@github/copilot-sdk 1.0.9-preview.1 → 1.0.9-preview.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -36,7 +36,7 @@ import { CopilotClient, approveAll } from "@github/copilot-sdk";
36
36
  const client = new CopilotClient();
37
37
  await client.start();
38
38
 
39
- // Create a session (onPermissionRequest is optional; approveAll allows every tool)
39
+ // approveAll is only valid when managed settings are disabled.
40
40
  const session = await client.createSession({
41
41
  model: "gpt-5",
42
42
  onPermissionRequest: approveAll,
@@ -135,8 +135,9 @@ Create a new conversation session.
135
135
  - `tools?: Tool[]` - Custom tools exposed to the CLI. Tools without `handler` are declaration-only and must be resolved via pending tool-call RPCs.
136
136
  - `systemMessage?: SystemMessageConfig` - System message customization (see below)
137
137
  - `infiniteSessions?: InfiniteSessionConfig` - Configure automatic context compaction (see below)
138
+ - `enableSessionStore?: boolean` - Enables the cross-session store for search and retrieval across sessions. When unset in `"copilot-cli"` mode, the runtime default applies (enabled). In `"empty"` mode, defaults to disabled.
138
139
  - `provider?: ProviderConfig` - Custom API provider configuration (BYOK - Bring Your Own Key). See [Custom Providers](#custom-providers) section.
139
- - `onPermissionRequest?: PermissionHandler` - Optional handler called before each tool execution to approve or deny it. When omitted, permission requests are emitted as events and left pending for manual resolution. Use `approveAll` to allow everything, or provide a custom function for fine-grained control. See [Permission Handling](#permission-handling) section.
140
+ - `onPermissionRequest?: PermissionHandler` - Optional handler called before each tool execution to approve or deny it. When omitted, permission requests are emitted as events and left pending for manual resolution. `approveAll` approves requests when managed settings are disabled and throws when `enableManagedSettings` is true. Custom handlers can inspect `managedApprovalRequired` for human-facing confirmation logic. See [Permission Handling](#permission-handling) section.
140
141
  - `onUserInputRequest?: UserInputHandler` - Handler for user input requests from the agent. Enables the `ask_user` tool. See [User Input Requests](#user-input-requests) section.
141
142
  - `onElicitationRequest?: ElicitationHandler` - Handler for elicitation requests dispatched by the server. Enables this client to present form-based UI dialogs on behalf of the agent or other session participants. See [Elicitation Requests](#elicitation-requests) section.
142
143
  - `hooks?: SessionHooks` - Hook handlers for session lifecycle events. See [Session Hooks](#session-hooks) section.
@@ -861,7 +862,7 @@ An `onPermissionRequest` handler is optional when you create or resume a session
861
862
 
862
863
  ### Approve All (simplest)
863
864
 
864
- Use the built-in `approveAll` helper to allow every tool call without any checks:
865
+ Use the built-in `approveAll` helper when managed settings are disabled:
865
866
 
866
867
  ```typescript
867
868
  import { CopilotClient, approveAll } from "@github/copilot-sdk";
@@ -872,9 +873,11 @@ const session = await client.createSession({
872
873
  });
873
874
  ```
874
875
 
876
+ When `enableManagedSettings` is true for the session, `approveAll` throws. Use a custom handler for managed sessions; request-level `managedApprovalRequired` remains available for human-facing confirmation logic.
877
+
875
878
  ### Custom Permission Handler
876
879
 
877
- Provide your own function to inspect each request and apply custom logic:
880
+ Provide your own function to inspect each request and apply custom logic. Check `managedApprovalRequired` before any automatic approval:
878
881
 
879
882
  ```typescript
880
883
  import type { PermissionRequest, PermissionRequestResult } from "@github/copilot-sdk";
@@ -882,6 +885,11 @@ import type { PermissionRequest, PermissionRequestResult } from "@github/copilot
882
885
  const session = await client.createSession({
883
886
  model: "gpt-5",
884
887
  onPermissionRequest: (request: PermissionRequest, invocation): PermissionRequestResult => {
888
+ if ("managedApprovalRequired" in request && request.managedApprovalRequired === true) {
889
+ // Leave the request pending for the host's human-facing confirmation flow.
890
+ return { kind: "no-result" };
891
+ }
892
+
885
893
  // request.kind — what type of operation is being requested:
886
894
  // "shell" — executing a shell command
887
895
  // "write" — writing or editing a file
@@ -919,7 +927,7 @@ The handler must return one of the `PermissionDecision` shapes (or `{ kind: "no-
919
927
  | `"approve-permanently"` | Allow this request and persist the approval across sessions (currently used for URL domains) | `domain` (URL domain to approve) |
920
928
  | `"reject"` | Deny the request | `feedback?` (optional string surfaced to the agent) |
921
929
  | `"user-not-available"` | Deny the request because no user is available to confirm it | — |
922
- | `"no-result"` | Leave the request unanswered (only valid with protocol v1; rejected by protocol v2 servers) | — |
930
+ | `"no-result"` | Suppress this SDK client's response so another connected client can answer the pending request | — |
923
931
 
924
932
  ### Resuming Sessions
925
933
 
@@ -520,9 +520,6 @@ class CopilotClient {
520
520
  }
521
521
  setupClientGlobalHandlers() {
522
522
  const handlers = {};
523
- handlers.hooks = {
524
- invoke: async (params) => await this.handleHooksInvoke(params)
525
- };
526
523
  if (this.requestHandler) {
527
524
  handlers.llmInference = (0, import_copilotRequestHandler.createCopilotRequestAdapter)(this.requestHandler, () => {
528
525
  if (!this.connection) {
@@ -917,11 +914,16 @@ class CopilotClient {
917
914
  enableHostGitOperations: false,
918
915
  enableSessionStore: false,
919
916
  enableSkills: false,
920
- memory: { enabled: false }
917
+ memory: { enabled: false },
918
+ customAgentsLocalOnly: true
921
919
  };
922
920
  }
923
921
  return {};
924
922
  }
923
+ /** Mode-specific default for enableExperimentalMode. */
924
+ experimentalModeForMode(supplied) {
925
+ return this.options.mode === "empty" ? supplied ?? false : supplied;
926
+ }
925
927
  /**
926
928
  * Returns the systemMessage config to use, adjusted for the current mode.
927
929
  * In empty mode we ensure the environment_context section is removed
@@ -1002,7 +1004,9 @@ class CopilotClient {
1002
1004
  if (!this.connection) {
1003
1005
  await this.start();
1004
1006
  }
1005
- config = { ...this.configDefaultsForMode(), ...config };
1007
+ const modeDefaults = this.configDefaultsForMode();
1008
+ config = { ...modeDefaults, ...config };
1009
+ config.customAgentsLocalOnly ??= modeDefaults.customAgentsLocalOnly;
1006
1010
  config.systemMessage = this.getSystemMessageConfigForMode(config.systemMessage);
1007
1011
  const callerSessionId = config.sessionId;
1008
1012
  const useServerGeneratedId = config.cloud != null && callerSessionId == null;
@@ -1021,7 +1025,10 @@ class CopilotClient {
1021
1025
  this.connection,
1022
1026
  void 0,
1023
1027
  this.onGetTraceContext,
1024
- { mcpAuthHandler: config.onMcpAuthRequest }
1028
+ {
1029
+ mcpAuthHandler: config.onMcpAuthRequest,
1030
+ managedSettingsEnabled: config.enableManagedSettings
1031
+ }
1025
1032
  );
1026
1033
  s.registerTools(config.tools);
1027
1034
  s.registerCanvases(config.canvases);
@@ -1070,6 +1077,7 @@ class CopilotClient {
1070
1077
  clientName: config.clientName,
1071
1078
  reasoningEffort: config.reasoningEffort,
1072
1079
  reasoningSummary: config.reasoningSummary,
1080
+ isExperimentalMode: this.experimentalModeForMode(config.enableExperimentalMode),
1073
1081
  contextTier: config.contextTier,
1074
1082
  tools: config.tools?.map((tool) => ({
1075
1083
  name: tool.name,
@@ -1109,10 +1117,12 @@ class CopilotClient {
1109
1117
  requestUserInput: !!config.onUserInputRequest,
1110
1118
  requestElicitation: !!config.onElicitationRequest,
1111
1119
  ...config.enableMcpApps ? { requestMcpApps: true } : {},
1120
+ ...config.githubMcpToolConfig != null ? { githubMcpToolConfig: config.githubMcpToolConfig } : {},
1112
1121
  requestExitPlanMode: !!config.onExitPlanModeRequest,
1113
1122
  requestAutoModeSwitch: !!config.onAutoModeSwitchRequest,
1114
1123
  hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
1115
1124
  workingDirectory: config.workingDirectory,
1125
+ additionalDirectories: config.additionalDirectories,
1116
1126
  streaming: config.streaming,
1117
1127
  includeSubAgentStreamingEvents: config.includeSubAgentStreamingEvents ?? true,
1118
1128
  ...this.onGitHubTelemetry != null ? { enableGitHubTelemetryForwarding: true } : {},
@@ -1120,6 +1130,7 @@ class CopilotClient {
1120
1130
  mcpOAuthTokenStorage: config.mcpOAuthTokenStorage,
1121
1131
  envValueMode: "direct",
1122
1132
  customAgents: toWireCustomAgents(config.customAgents),
1133
+ customAgentsLocalOnly: config.customAgentsLocalOnly,
1123
1134
  defaultAgent: config.defaultAgent,
1124
1135
  agent: config.agent,
1125
1136
  configDir: config.configDirectory,
@@ -1218,7 +1229,10 @@ class CopilotClient {
1218
1229
  this.connection,
1219
1230
  void 0,
1220
1231
  this.onGetTraceContext,
1221
- { mcpAuthHandler: config.onMcpAuthRequest }
1232
+ {
1233
+ mcpAuthHandler: config.onMcpAuthRequest,
1234
+ managedSettingsEnabled: config.enableManagedSettings
1235
+ }
1222
1236
  );
1223
1237
  session.registerTools(config.tools);
1224
1238
  session.registerCanvases(config.canvases);
@@ -1248,7 +1262,9 @@ class CopilotClient {
1248
1262
  if (config.hooks) {
1249
1263
  session.registerHooks(config.hooks);
1250
1264
  }
1251
- config = { ...this.configDefaultsForMode(), ...config };
1265
+ const modeDefaults = this.configDefaultsForMode();
1266
+ config = { ...modeDefaults, ...config };
1267
+ config.customAgentsLocalOnly ??= modeDefaults.customAgentsLocalOnly;
1252
1268
  config.systemMessage = this.getSystemMessageConfigForMode(config.systemMessage);
1253
1269
  const { wirePayload: wireSystemMessage, transformCallbacks } = extractTransformCallbacks(
1254
1270
  config.systemMessage
@@ -1270,6 +1286,7 @@ class CopilotClient {
1270
1286
  model: config.model,
1271
1287
  reasoningEffort: config.reasoningEffort,
1272
1288
  reasoningSummary: config.reasoningSummary,
1289
+ isExperimentalMode: this.experimentalModeForMode(config.enableExperimentalMode),
1273
1290
  contextTier: config.contextTier,
1274
1291
  systemMessage: wireSystemMessage,
1275
1292
  availableTools: toolFilterOptions.availableTools,
@@ -1310,10 +1327,12 @@ class CopilotClient {
1310
1327
  requestUserInput: !!config.onUserInputRequest,
1311
1328
  requestElicitation: !!config.onElicitationRequest,
1312
1329
  ...config.enableMcpApps ? { requestMcpApps: true } : {},
1330
+ ...config.githubMcpToolConfig != null ? { githubMcpToolConfig: config.githubMcpToolConfig } : {},
1313
1331
  requestExitPlanMode: !!config.onExitPlanModeRequest,
1314
1332
  requestAutoModeSwitch: !!config.onAutoModeSwitchRequest,
1315
1333
  hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
1316
1334
  workingDirectory: config.workingDirectory,
1335
+ additionalDirectories: config.additionalDirectories,
1317
1336
  configDir: config.configDirectory,
1318
1337
  enableConfigDiscovery: config.enableConfigDiscovery,
1319
1338
  skipEmbeddingRetrieval: config.skipEmbeddingRetrieval,
@@ -1331,6 +1350,7 @@ class CopilotClient {
1331
1350
  mcpOAuthTokenStorage: config.mcpOAuthTokenStorage,
1332
1351
  envValueMode: "direct",
1333
1352
  customAgents: toWireCustomAgents(config.customAgents),
1353
+ customAgentsLocalOnly: config.customAgentsLocalOnly,
1334
1354
  defaultAgent: config.defaultAgent,
1335
1355
  agent: config.agent,
1336
1356
  skillDirectories: config.skillDirectories,
@@ -2088,6 +2108,12 @@ stderr: ${stderrOutput}`
2088
2108
  return session.clientSessionApis;
2089
2109
  });
2090
2110
  (0, import_rpc.registerClientGlobalApiHandlers)(this.connection, this.clientGlobalHandlers);
2111
+ this.connection.onRequest(
2112
+ "hooks.invoke",
2113
+ async (params) => {
2114
+ return await this.handleHooksInvoke(params);
2115
+ }
2116
+ );
2091
2117
  this.connection.onClose(() => {
2092
2118
  this.state = "disconnected";
2093
2119
  });
@@ -171,6 +171,27 @@ function createServerRpc(connection) {
171
171
  discover: async (params) => connection.sendRequest("mcp.discover", params)
172
172
  },
173
173
  /** @experimental */
174
+ extensions: {
175
+ /**
176
+ * Discovers user and enabled installed-plugin extensions from persisted Copilot home state, including enablement preferences. Launch-scoped additional plugins are not included.
177
+ *
178
+ * @returns Extensions discovered from persisted Copilot home state and their effective loading mode. Launch-scoped additional plugins are not included.
179
+ */
180
+ discover: async () => connection.sendRequest("extensions.discover", {}),
181
+ /**
182
+ * Persistently enables extension IDs for future sessions. Active sessions are unchanged; use session.extensions.enable to update them.
183
+ *
184
+ * @param params Source-qualified extension identifiers to persistently enable for future sessions.
185
+ */
186
+ enable: async (params) => connection.sendRequest("extensions.enable", params),
187
+ /**
188
+ * Persistently disables extension IDs for future sessions. Active sessions are unchanged; use session.extensions.disable to update them.
189
+ *
190
+ * @param params Source-qualified extension identifiers to persistently disable for future sessions.
191
+ */
192
+ disable: async (params) => connection.sendRequest("extensions.disable", params)
193
+ },
194
+ /** @experimental */
174
195
  plugins: {
175
196
  /**
176
197
  * Lists plugins installed in user/global state.
@@ -1165,6 +1186,12 @@ function createSessionRpc(connection, sessionId) {
1165
1186
  * @returns Agents available to the session.
1166
1187
  */
1167
1188
  list: async (params) => connection.sendRequest("session.agent.list", { sessionId, ...params }),
1189
+ /**
1190
+ * Sets an in-memory authored prompt override for an available agent. For built-in agents, this replaces only the static base prompt while preserving runtime-owned dynamic prompt composition and behavior. The special `general-purpose` agent is not overrideable. Overrides are not persisted; resumed and forked sessions start without them, so the host must re-apply them.
1191
+ *
1192
+ * @param params An in-memory authored prompt override for an available agent.
1193
+ */
1194
+ setPrompt: async (params) => connection.sendRequest("session.agent.setPrompt", { sessionId, ...params }),
1168
1195
  /**
1169
1196
  * Gets the currently selected custom agent for the session.
1170
1197
  *
@@ -1406,6 +1433,12 @@ function createSessionRpc(connection, sessionId) {
1406
1433
  * @returns Indicates whether the pending MCP OAuth response was accepted.
1407
1434
  */
1408
1435
  handlePendingRequest: async (params) => connection.sendRequest("session.mcp.oauth.handlePendingRequest", { sessionId, ...params }),
1436
+ /**
1437
+ * Notifies the session that MCP OAuth authentication succeeded and updated credentials were persisted, so cached tool definitions can be refreshed.
1438
+ *
1439
+ * @param params Identifies the MCP server whose persisted OAuth credentials were updated.
1440
+ */
1441
+ authenticationStateChanged: async (params) => connection.sendRequest("session.mcp.oauth.authenticationStateChanged", { sessionId, ...params }),
1409
1442
  /**
1410
1443
  * Starts OAuth authentication for a remote MCP server.
1411
1444
  *
@@ -2129,7 +2162,15 @@ function createSessionRpc(connection, sessionId) {
2129
2162
  *
2130
2163
  * @returns Markdown summary of the conversation context (empty when not available).
2131
2164
  */
2132
- summarizeForHandoff: async () => connection.sendRequest("session.history.summarizeForHandoff", { sessionId })
2165
+ summarizeForHandoff: async () => connection.sendRequest("session.history.summarizeForHandoff", { sessionId }),
2166
+ /**
2167
+ * Clears the session's conversation history, keeping only system and developer messages, and seeds the fresh context window with a first user message. Must be called from inside a tool handler: the clear has to drop the results of the tool calls its wipe orphans, and it rejects when no tool call is in flight.
2168
+ *
2169
+ * @param params Parameters for clearing the conversation and seeding the window that replaces it.
2170
+ *
2171
+ * @returns What a successful clear removed. A clear that could not be applied rejects instead of reporting a count.
2172
+ */
2173
+ clearContext: async (params) => connection.sendRequest("session.history.clearContext", { sessionId, ...params })
2133
2174
  },
2134
2175
  /** @experimental */
2135
2176
  queue: {
@@ -2207,7 +2248,7 @@ function createSessionRpc(connection, sessionId) {
2207
2248
  /** @experimental */
2208
2249
  eventLog: {
2209
2250
  /**
2210
- * Reads a batch of session events from a cursor, optionally waiting for new events.
2251
+ * Reads a batch of session events from a cursor, optionally waiting for new events. Supports tail-first reads via `direction: backward`.
2211
2252
  *
2212
2253
  * @param params Cursor, batch size, and optional long-poll/filter parameters for reading session events.
2213
2254
  *
@@ -2582,11 +2623,6 @@ function registerClientSessionApiHandlers(connection, getHandlers) {
2582
2623
  });
2583
2624
  }
2584
2625
  function registerClientGlobalApiHandlers(connection, handlers) {
2585
- connection.onRequest("hooks.invoke", async (params) => {
2586
- const handler = handlers.hooks;
2587
- if (!handler) throw new Error("No hooks client-global handler registered");
2588
- return handler.invoke(params);
2589
- });
2590
2626
  connection.onRequest("llmInference.httpRequestStart", async (params) => {
2591
2627
  const handler = handlers.llmInference;
2592
2628
  if (!handler) throw new Error("No llmInference client-global handler registered");
@@ -224,6 +224,7 @@ class CopilotSession {
224
224
  this._workspacePath = _workspacePath;
225
225
  this.traceContextProvider = traceContextProvider;
226
226
  this.mcpAuthHandler = options?.mcpAuthHandler;
227
+ this.managedSettingsEnabled = options?.managedSettingsEnabled === true;
227
228
  }
228
229
  sessionId;
229
230
  connection;
@@ -246,6 +247,7 @@ class CopilotSession {
246
247
  transformCallbacks;
247
248
  _rpc = null;
248
249
  traceContextProvider;
250
+ managedSettingsEnabled;
249
251
  _capabilities = {};
250
252
  openCanvasInstances = [];
251
253
  disconnected = false;
@@ -272,7 +274,7 @@ class CopilotSession {
272
274
  limits: options?.limits
273
275
  }
274
276
  });
275
- return toPublicFactoryRunResult(envelope);
277
+ return this.settleFactoryRun(envelope);
276
278
  }),
277
279
  resume: (async (runId, options) => {
278
280
  let response;
@@ -290,7 +292,7 @@ class CopilotSession {
290
292
  }
291
293
  throw error;
292
294
  }
293
- return toPublicFactoryRunResult(response.run);
295
+ return this.settleFactoryRun(response.run);
294
296
  }),
295
297
  getRun: async (runId) => toPublicFactoryRunResult(await this.rpc.factory.getRun({ runId })),
296
298
  waitForRun: (runId, options) => this.waitForFactoryRun(runId, options?.signal),
@@ -299,6 +301,19 @@ class CopilotSession {
299
301
  getRunProgress: (runId, options = {}) => this.rpc.factory.getRunProgress({ runId, ...options }),
300
302
  cancel: async (runId) => toPublicFactoryRunResult(await this.rpc.factory.cancel({ runId }))
301
303
  };
304
+ /**
305
+ * Resolve a start/resume envelope into the terminal envelope callers expect.
306
+ *
307
+ * The CLI may answer `session.factory.run` and `session.factory.resume`
308
+ * before the run settles, so a non-terminal envelope is followed by a wait
309
+ * on the run's terminal state.
310
+ */
311
+ settleFactoryRun(envelope) {
312
+ if ((0, import_factory.isFactoryRunTerminal)(envelope.status)) {
313
+ return Promise.resolve(toPublicFactoryRunResult(envelope));
314
+ }
315
+ return this.waitForFactoryRun(envelope.runId);
316
+ }
302
317
  /**
303
318
  * Resolve when a factory run reaches a terminal status.
304
319
  *
@@ -704,7 +719,8 @@ class CopilotSession {
704
719
  async _executePermissionAndRespond(requestId, permissionRequest) {
705
720
  try {
706
721
  const result = await this.permissionHandler(permissionRequest, {
707
- sessionId: this.sessionId
722
+ sessionId: this.sessionId,
723
+ managedSettingsEnabled: this.managedSettingsEnabled
708
724
  });
709
725
  if (result.kind === "no-result") {
710
726
  return;
@@ -713,10 +729,15 @@ class CopilotSession {
713
729
  return;
714
730
  }
715
731
  await this.rpc.permissions.handlePendingPermissionRequest({ requestId, result });
716
- } catch (_error) {
732
+ } catch (error) {
717
733
  if (this.disconnected) {
718
734
  return;
719
735
  }
736
+ console.error("Permission handler or response delivery failed", {
737
+ sessionId: this.sessionId,
738
+ requestId,
739
+ error
740
+ });
720
741
  try {
721
742
  await this.rpc.permissions.handlePendingPermissionRequest({
722
743
  requestId,
package/dist/cjs/types.js CHANGED
@@ -141,7 +141,18 @@ const SYSTEM_MESSAGE_SECTIONS = {
141
141
  description: "End-of-prompt instructions: parallel tool calling, persistence, task completion"
142
142
  }
143
143
  };
144
- const approveAll = () => ({ kind: "approve-once" });
144
+ const approveAll = (request, invocation) => {
145
+ if (invocation.managedSettingsEnabled) {
146
+ throw new Error("approveAll cannot be used when managed settings are enabled");
147
+ }
148
+ if ("managedApprovalRequired" in request) {
149
+ const managedApprovalRequired = request.managedApprovalRequired;
150
+ if (managedApprovalRequired !== void 0 && managedApprovalRequired !== false) {
151
+ return { kind: "no-result" };
152
+ }
153
+ }
154
+ return { kind: "approve-once" };
155
+ };
145
156
  const defaultJoinSessionPermissionHandler = () => ({
146
157
  kind: "no-result"
147
158
  });
package/dist/client.d.ts CHANGED
@@ -180,6 +180,8 @@ export declare class CopilotClient {
180
180
  forceStop(): Promise<void>;
181
181
  /** Mode-specific defaults spread under the caller's config (app values win). */
182
182
  private configDefaultsForMode;
183
+ /** Mode-specific default for enableExperimentalMode. */
184
+ private experimentalModeForMode;
183
185
  /**
184
186
  * Returns the systemMessage config to use, adjusted for the current mode.
185
187
  * In empty mode we ensure the environment_context section is removed
package/dist/client.js CHANGED
@@ -497,9 +497,6 @@ class CopilotClient {
497
497
  }
498
498
  setupClientGlobalHandlers() {
499
499
  const handlers = {};
500
- handlers.hooks = {
501
- invoke: async (params) => await this.handleHooksInvoke(params)
502
- };
503
500
  if (this.requestHandler) {
504
501
  handlers.llmInference = createCopilotRequestAdapter(this.requestHandler, () => {
505
502
  if (!this.connection) {
@@ -894,11 +891,16 @@ class CopilotClient {
894
891
  enableHostGitOperations: false,
895
892
  enableSessionStore: false,
896
893
  enableSkills: false,
897
- memory: { enabled: false }
894
+ memory: { enabled: false },
895
+ customAgentsLocalOnly: true
898
896
  };
899
897
  }
900
898
  return {};
901
899
  }
900
+ /** Mode-specific default for enableExperimentalMode. */
901
+ experimentalModeForMode(supplied) {
902
+ return this.options.mode === "empty" ? supplied ?? false : supplied;
903
+ }
902
904
  /**
903
905
  * Returns the systemMessage config to use, adjusted for the current mode.
904
906
  * In empty mode we ensure the environment_context section is removed
@@ -979,7 +981,9 @@ class CopilotClient {
979
981
  if (!this.connection) {
980
982
  await this.start();
981
983
  }
982
- config = { ...this.configDefaultsForMode(), ...config };
984
+ const modeDefaults = this.configDefaultsForMode();
985
+ config = { ...modeDefaults, ...config };
986
+ config.customAgentsLocalOnly ??= modeDefaults.customAgentsLocalOnly;
983
987
  config.systemMessage = this.getSystemMessageConfigForMode(config.systemMessage);
984
988
  const callerSessionId = config.sessionId;
985
989
  const useServerGeneratedId = config.cloud != null && callerSessionId == null;
@@ -998,7 +1002,10 @@ class CopilotClient {
998
1002
  this.connection,
999
1003
  void 0,
1000
1004
  this.onGetTraceContext,
1001
- { mcpAuthHandler: config.onMcpAuthRequest }
1005
+ {
1006
+ mcpAuthHandler: config.onMcpAuthRequest,
1007
+ managedSettingsEnabled: config.enableManagedSettings
1008
+ }
1002
1009
  );
1003
1010
  s.registerTools(config.tools);
1004
1011
  s.registerCanvases(config.canvases);
@@ -1047,6 +1054,7 @@ class CopilotClient {
1047
1054
  clientName: config.clientName,
1048
1055
  reasoningEffort: config.reasoningEffort,
1049
1056
  reasoningSummary: config.reasoningSummary,
1057
+ isExperimentalMode: this.experimentalModeForMode(config.enableExperimentalMode),
1050
1058
  contextTier: config.contextTier,
1051
1059
  tools: config.tools?.map((tool) => ({
1052
1060
  name: tool.name,
@@ -1086,10 +1094,12 @@ class CopilotClient {
1086
1094
  requestUserInput: !!config.onUserInputRequest,
1087
1095
  requestElicitation: !!config.onElicitationRequest,
1088
1096
  ...config.enableMcpApps ? { requestMcpApps: true } : {},
1097
+ ...config.githubMcpToolConfig != null ? { githubMcpToolConfig: config.githubMcpToolConfig } : {},
1089
1098
  requestExitPlanMode: !!config.onExitPlanModeRequest,
1090
1099
  requestAutoModeSwitch: !!config.onAutoModeSwitchRequest,
1091
1100
  hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
1092
1101
  workingDirectory: config.workingDirectory,
1102
+ additionalDirectories: config.additionalDirectories,
1093
1103
  streaming: config.streaming,
1094
1104
  includeSubAgentStreamingEvents: config.includeSubAgentStreamingEvents ?? true,
1095
1105
  ...this.onGitHubTelemetry != null ? { enableGitHubTelemetryForwarding: true } : {},
@@ -1097,6 +1107,7 @@ class CopilotClient {
1097
1107
  mcpOAuthTokenStorage: config.mcpOAuthTokenStorage,
1098
1108
  envValueMode: "direct",
1099
1109
  customAgents: toWireCustomAgents(config.customAgents),
1110
+ customAgentsLocalOnly: config.customAgentsLocalOnly,
1100
1111
  defaultAgent: config.defaultAgent,
1101
1112
  agent: config.agent,
1102
1113
  configDir: config.configDirectory,
@@ -1195,7 +1206,10 @@ class CopilotClient {
1195
1206
  this.connection,
1196
1207
  void 0,
1197
1208
  this.onGetTraceContext,
1198
- { mcpAuthHandler: config.onMcpAuthRequest }
1209
+ {
1210
+ mcpAuthHandler: config.onMcpAuthRequest,
1211
+ managedSettingsEnabled: config.enableManagedSettings
1212
+ }
1199
1213
  );
1200
1214
  session.registerTools(config.tools);
1201
1215
  session.registerCanvases(config.canvases);
@@ -1225,7 +1239,9 @@ class CopilotClient {
1225
1239
  if (config.hooks) {
1226
1240
  session.registerHooks(config.hooks);
1227
1241
  }
1228
- config = { ...this.configDefaultsForMode(), ...config };
1242
+ const modeDefaults = this.configDefaultsForMode();
1243
+ config = { ...modeDefaults, ...config };
1244
+ config.customAgentsLocalOnly ??= modeDefaults.customAgentsLocalOnly;
1229
1245
  config.systemMessage = this.getSystemMessageConfigForMode(config.systemMessage);
1230
1246
  const { wirePayload: wireSystemMessage, transformCallbacks } = extractTransformCallbacks(
1231
1247
  config.systemMessage
@@ -1247,6 +1263,7 @@ class CopilotClient {
1247
1263
  model: config.model,
1248
1264
  reasoningEffort: config.reasoningEffort,
1249
1265
  reasoningSummary: config.reasoningSummary,
1266
+ isExperimentalMode: this.experimentalModeForMode(config.enableExperimentalMode),
1250
1267
  contextTier: config.contextTier,
1251
1268
  systemMessage: wireSystemMessage,
1252
1269
  availableTools: toolFilterOptions.availableTools,
@@ -1287,10 +1304,12 @@ class CopilotClient {
1287
1304
  requestUserInput: !!config.onUserInputRequest,
1288
1305
  requestElicitation: !!config.onElicitationRequest,
1289
1306
  ...config.enableMcpApps ? { requestMcpApps: true } : {},
1307
+ ...config.githubMcpToolConfig != null ? { githubMcpToolConfig: config.githubMcpToolConfig } : {},
1290
1308
  requestExitPlanMode: !!config.onExitPlanModeRequest,
1291
1309
  requestAutoModeSwitch: !!config.onAutoModeSwitchRequest,
1292
1310
  hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
1293
1311
  workingDirectory: config.workingDirectory,
1312
+ additionalDirectories: config.additionalDirectories,
1294
1313
  configDir: config.configDirectory,
1295
1314
  enableConfigDiscovery: config.enableConfigDiscovery,
1296
1315
  skipEmbeddingRetrieval: config.skipEmbeddingRetrieval,
@@ -1308,6 +1327,7 @@ class CopilotClient {
1308
1327
  mcpOAuthTokenStorage: config.mcpOAuthTokenStorage,
1309
1328
  envValueMode: "direct",
1310
1329
  customAgents: toWireCustomAgents(config.customAgents),
1330
+ customAgentsLocalOnly: config.customAgentsLocalOnly,
1311
1331
  defaultAgent: config.defaultAgent,
1312
1332
  agent: config.agent,
1313
1333
  skillDirectories: config.skillDirectories,
@@ -2065,6 +2085,12 @@ stderr: ${stderrOutput}`
2065
2085
  return session.clientSessionApis;
2066
2086
  });
2067
2087
  registerClientGlobalApiHandlers(this.connection, this.clientGlobalHandlers);
2088
+ this.connection.onRequest(
2089
+ "hooks.invoke",
2090
+ async (params) => {
2091
+ return await this.handleHooksInvoke(params);
2092
+ }
2093
+ );
2068
2094
  this.connection.onClose(() => {
2069
2095
  this.state = "disconnected";
2070
2096
  });