Skip to content

Commit 9c3c090

Browse files
committed
Add managed permission settings to session startup
Regenerate RPC and session-event mirrors from @github/copilot 1.0.79-5 and serialize permissions-only managed settings on create and resume across all six SDKs. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: c85d8afb-8b62-4636-9408-7a3ba6a82931
1 parent 4e95dee commit 9c3c090

71 files changed

Lines changed: 3313 additions & 247 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎dotnet/src/Client.cs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ private CopilotSession InitializeSession(
785785
session.RegisterTools(config.Tools ?? []);
786786
session.RegisterPermissionHandler(
787787
config.OnPermissionRequest,
788-
config.EnableManagedSettings is true);
788+
config.EnableManagedSettings is true || config.ManagedSettings is not null);
789789
session.RegisterMcpAuthHandler(config.OnMcpAuthRequest);
790790
session.RegisterCommands(config.Commands);
791791
session.RegisterElicitationHandler(config.OnElicitationRequest);
@@ -1204,6 +1204,7 @@ public async Task<CopilotSession> CreateSessionAsync(SessionConfig config, Cance
12041204
ToolFilterPrecedence: toolFilter.ToolFilterPrecedence,
12051205
ExpAssignments: config.ExpAssignments,
12061206
EnableManagedSettings: config.EnableManagedSettings,
1207+
ManagedSettings: config.ManagedSettings,
12071208
GitHubMcpToolConfig: config.GitHubMcpToolConfig,
12081209
EnableGitHubTelemetryForwarding: _options.OnGitHubTelemetry != null ? true : null,
12091210
AdditionalDirectories: config.AdditionalDirectories);
@@ -1424,6 +1425,7 @@ public async Task<CopilotSession> ResumeSessionAsync(string sessionId, ResumeSes
14241425
ToolFilterPrecedence: toolFilter.ToolFilterPrecedence,
14251426
ExpAssignments: config.ExpAssignments,
14261427
EnableManagedSettings: config.EnableManagedSettings,
1428+
ManagedSettings: config.ManagedSettings,
14271429
GitHubMcpToolConfig: config.GitHubMcpToolConfig,
14281430
EnableGitHubTelemetryForwarding: _options.OnGitHubTelemetry != null ? true : null,
14291431
AdditionalDirectories: config.AdditionalDirectories);
@@ -2781,6 +2783,7 @@ internal record CreateSessionRequest(
27812783
OptionsUpdateToolFilterPrecedence? ToolFilterPrecedence = null,
27822784
[property: JsonPropertyName("expAssignments")] CopilotExpAssignmentResponse? ExpAssignments = null,
27832785
[property: JsonPropertyName("enableManagedSettings")] bool? EnableManagedSettings = null,
2786+
[property: JsonPropertyName("managedSettings")] ManagedSettings? ManagedSettings = null,
27842787
bool? EnableGitHubTelemetryForwarding = null,
27852788
[property: JsonPropertyName("githubMcpToolConfig")] GitHubMcpToolConfig? GitHubMcpToolConfig = null,
27862789
IList<string>? AdditionalDirectories = null);
@@ -2895,6 +2898,7 @@ internal record ResumeSessionRequest(
28952898
OptionsUpdateToolFilterPrecedence? ToolFilterPrecedence = null,
28962899
[property: JsonPropertyName("expAssignments")] CopilotExpAssignmentResponse? ExpAssignments = null,
28972900
[property: JsonPropertyName("enableManagedSettings")] bool? EnableManagedSettings = null,
2901+
[property: JsonPropertyName("managedSettings")] ManagedSettings? ManagedSettings = null,
28982902
bool? EnableGitHubTelemetryForwarding = null,
28992903
[property: JsonPropertyName("githubMcpToolConfig")] GitHubMcpToolConfig? GitHubMcpToolConfig = null,
29002904
IList<string>? AdditionalDirectories = null);

‎dotnet/src/Generated/Rpc.cs‎

Lines changed: 420 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dotnet/src/Generated/SessionEvents.cs‎

Lines changed: 25 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dotnet/src/Types.cs‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3044,6 +3044,30 @@ public sealed class GitHubMcpToolConfig
30443044
public bool? DisableFormDeferral { get; set; }
30453045
}
30463046

3047+
/// <summary>Enterprise permission policy injected by an SDK host at session startup.</summary>
3048+
public sealed class ManagedSettingsPermissions
3049+
{
3050+
/// <summary>When set to <c>"disable"</c>, prevents bypass permission modes.</summary>
3051+
[JsonPropertyName("disableBypassPermissionsMode")]
3052+
public string? DisableBypassPermissionsMode { get; set; }
3053+
3054+
/// <summary>Permission rules that block matching operations.</summary>
3055+
public IList<string>? Deny { get; set; }
3056+
3057+
/// <summary>Permission rules that require explicit approval.</summary>
3058+
public IList<string>? Ask { get; set; }
3059+
3060+
/// <summary>Permission rules that allow matching operations.</summary>
3061+
public IList<string>? Allow { get; set; }
3062+
}
3063+
3064+
/// <summary>Permissions-only managed settings injected by an SDK host.</summary>
3065+
public sealed class ManagedSettings
3066+
{
3067+
/// <summary>Gets or sets the managed permission policy.</summary>
3068+
public ManagedSettingsPermissions? Permissions { get; set; }
3069+
}
3070+
30473071
/// <summary>
30483072
/// Shared configuration properties for creating or resuming a Copilot session.
30493073
/// Use <see cref="SessionConfig"/> when creating a new session, or
@@ -3136,6 +3160,7 @@ protected SessionConfigBase(SessionConfigBase? other)
31363160
RemoteSession = other.RemoteSession;
31373161
ExpAssignments = other.ExpAssignments;
31383162
EnableManagedSettings = other.EnableManagedSettings;
3163+
ManagedSettings = other.ManagedSettings;
31393164
#pragma warning disable GHCP001
31403165
Canvases = other.Canvases is not null ? [.. other.Canvases] : null;
31413166
RequestCanvasRenderer = other.RequestCanvasRenderer;
@@ -3601,6 +3626,13 @@ protected SessionConfigBase(SessionConfigBase? other)
36013626
/// </summary>
36023627
public bool? EnableManagedSettings { get; set; }
36033628

3629+
/// <summary>
3630+
/// Gets or sets permissions-only managed settings injected at session
3631+
/// create or resume. This is independent of <see cref="EnableManagedSettings"/>
3632+
/// and must be re-supplied on resume because it is not persisted.
3633+
/// </summary>
3634+
public ManagedSettings? ManagedSettings { get; set; }
3635+
36043636
#pragma warning disable GHCP001
36053637
/// <summary>
36063638
/// Canvas declarations advertised by this connection. The runtime forwards

‎dotnet/test/Unit/ClientSessionLifetimeTests.cs‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,46 @@ public async Task Generated_Session_Rpc_Throws_When_Session_Disposed()
480480
await Assert.ThrowsAsync<ObjectDisposedException>(() => session.Rpc.Model.GetCurrentAsync());
481481
}
482482

483+
[Fact]
484+
public async Task Create_And_Resume_Serialize_ManagedSettings()
485+
{
486+
await using var server = await FakeCopilotServer.StartAsync();
487+
await using var client = new CopilotClient(new CopilotClientOptions { Connection = RuntimeConnection.ForUri(server.Url) });
488+
await client.StartAsync();
489+
var settings = new ManagedSettings
490+
{
491+
Permissions = new ManagedSettingsPermissions
492+
{
493+
DisableBypassPermissionsMode = "disable",
494+
Deny = ["shell(rm*)"],
495+
Ask = [],
496+
Allow = []
497+
}
498+
};
499+
500+
await using var created = await client.CreateSessionAsync(new SessionConfig
501+
{
502+
ManagedSettings = settings,
503+
OnPermissionRequest = PermissionHandler.ApproveAll
504+
});
505+
await using var resumed = await client.ResumeSessionAsync("session-managed", new ResumeSessionConfig
506+
{
507+
ManagedSettings = settings,
508+
OnPermissionRequest = PermissionHandler.ApproveAll,
509+
OnEvent = _ => { }
510+
});
511+
512+
foreach (var method in new[] { "session.create", "session.resume" })
513+
{
514+
var request = Assert.Single(server.Requests, request => request.Method == method);
515+
Assert.False(request.Params.TryGetProperty("enableManagedSettings", out _));
516+
var permissions = request.Params.GetProperty("managedSettings").GetProperty("permissions");
517+
Assert.Equal("disable", permissions.GetProperty("disableBypassPermissionsMode").GetString());
518+
Assert.Empty(permissions.GetProperty("ask").EnumerateArray());
519+
Assert.Empty(permissions.GetProperty("allow").EnumerateArray());
520+
}
521+
}
522+
483523
[MethodImpl(MethodImplOptions.NoInlining)]
484524
private static async Task<WeakReference<CopilotSession>> CreateDroppedSessionAsync(CopilotClient client)
485525
{

‎go/client.go‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,10 @@ func extractTransformCallbacks(config *SystemMessageConfig) (*SystemMessageConfi
750750
return wireConfig, callbacks
751751
}
752752

753+
func hasManagedSettings(enableManagedSettings *bool, managedSettings *rpc.SessionManagedSettings) bool {
754+
return (enableManagedSettings != nil && *enableManagedSettings) || managedSettings != nil
755+
}
756+
753757
func (c *Client) CreateSession(ctx context.Context, config *SessionConfig) (*Session, error) {
754758
if config == nil {
755759
config = &SessionConfig{}
@@ -833,6 +837,7 @@ func (c *Client) CreateSession(ctx context.Context, config *SessionConfig) (*Ses
833837
req.ExtensionInfo = config.ExtensionInfo
834838
req.ExpAssignments = config.ExpAssignments
835839
req.EnableManagedSettings = config.EnableManagedSettings
840+
req.ManagedSettings = config.ManagedSettings
836841

837842
if len(config.Commands) > 0 {
838843
cmds := make([]wireCommand, 0, len(config.Commands))
@@ -917,7 +922,7 @@ func (c *Client) CreateSession(ctx context.Context, config *SessionConfig) (*Ses
917922
sessionID,
918923
c.client,
919924
"",
920-
config.EnableManagedSettings != nil && *config.EnableManagedSettings,
925+
hasManagedSettings(config.EnableManagedSettings, config.ManagedSettings),
921926
)
922927

923928
s.registerTools(config.Tools)
@@ -1215,6 +1220,7 @@ func (c *Client) ResumeSessionWithOptions(ctx context.Context, sessionID string,
12151220
req.ExtensionInfo = config.ExtensionInfo
12161221
req.ExpAssignments = config.ExpAssignments
12171222
req.EnableManagedSettings = config.EnableManagedSettings
1223+
req.ManagedSettings = config.ManagedSettings
12181224
if config.OnPermissionRequest != nil {
12191225
req.RequestPermission = Bool(true)
12201226
}
@@ -1250,7 +1256,7 @@ func (c *Client) ResumeSessionWithOptions(ctx context.Context, sessionID string,
12501256
sessionID,
12511257
c.client,
12521258
"",
1253-
config.EnableManagedSettings != nil && *config.EnableManagedSettings,
1259+
hasManagedSettings(config.EnableManagedSettings, config.ManagedSettings),
12541260
)
12551261

12561262
session.registerTools(config.Tools)

0 commit comments

Comments
 (0)