@github/copilot-sdk 1.0.0-beta.7 → 1.0.0-beta.9

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/dist/types.d.ts CHANGED
@@ -7,6 +7,7 @@ import type { SessionEvent as GeneratedSessionEvent } from "./generated/session-
7
7
  import type { CopilotSession } from "./session.js";
8
8
  import type { RemoteSessionMode } from "./generated/rpc.js";
9
9
  import type { OpenCanvasInstance } from "./generated/rpc.js";
10
+ import type { ToolSet } from "./toolSet.js";
10
11
  export type { RemoteSessionMode } from "./generated/rpc.js";
11
12
  export type SessionEvent = GeneratedSessionEvent;
12
13
  export type { SessionFsProvider } from "./sessionFsProvider.js";
@@ -128,12 +129,38 @@ export declare const RuntimeConnection: {
128
129
  connectionToken?: string;
129
130
  }) => UriRuntimeConnection;
130
131
  };
132
+ /**
133
+ * Controls SDK defaults for ambient features.
134
+ *
135
+ * - `"copilot-cli"` (default): Defaults equivalent to Copilot CLI. Useful when
136
+ * building a coding agent that shares sessions with Copilot CLI. Do not use
137
+ * this mode for server-based multi-user applications — the default coding
138
+ * agent has tools and capabilities that operate across sessions and can
139
+ * access the host OS environment.
140
+ * - `"empty"`: Disables optional features by default. The app must explicitly
141
+ * opt into anything it needs. Required for any scenario where CLI-like
142
+ * ambient behavior is unsafe (e.g. multi-user servers).
143
+ */
144
+ export type CopilotClientMode = "empty" | "copilot-cli";
131
145
  export interface CopilotClientOptions {
132
146
  /**
133
147
  * How to connect to the Copilot runtime. When omitted, defaults to
134
148
  * {@link RuntimeConnection.forStdio} with the bundled runtime.
135
149
  */
136
150
  connection?: RuntimeConnection;
151
+ /**
152
+ * Selects the SDK defaulting strategy. See {@link CopilotClientMode}.
153
+ *
154
+ * When set to `"empty"`, the SDK validates that the app has supplied the
155
+ * required configuration ({@link CopilotClientOptions.baseDirectory} or
156
+ * {@link CopilotClientOptions.sessionFs}, plus
157
+ * {@link SessionConfigBase.availableTools} on each session) and translates
158
+ * session creation requests into runtime options that flip tool filter
159
+ * precedence to deny-wins so exclusions are expressible.
160
+ *
161
+ * @default "copilot-cli"
162
+ */
163
+ mode?: CopilotClientMode;
137
164
  /**
138
165
  * Working directory for the runtime process.
139
166
  * If not set, inherits the current process's working directory.
@@ -849,6 +876,47 @@ export interface PostToolUseHookOutput {
849
876
  export type PostToolUseHandler = (input: PostToolUseHookInput, invocation: {
850
877
  sessionId: string;
851
878
  }) => Promise<PostToolUseHookOutput | void> | PostToolUseHookOutput | void;
879
+ /**
880
+ * Input for post-tool-use-failure hook.
881
+ *
882
+ * Dispatched after a tool execution whose `resultType` is `"failure"`.
883
+ * The input differs from {@link PostToolUseHookInput}: the host CLI does not
884
+ * forward the full `ToolResultObject` to failure hooks — only `error`, the
885
+ * stringified failure message extracted from the tool's result, is provided.
886
+ */
887
+ export interface PostToolUseFailureHookInput extends BaseHookInput {
888
+ toolName: string;
889
+ toolArgs: unknown;
890
+ /**
891
+ * Failure message from the tool's result (the `error` field of the
892
+ * underlying `ToolResultObject`, falling back to its text/log fields).
893
+ */
894
+ error: string;
895
+ }
896
+ /**
897
+ * Output for post-tool-use-failure hook.
898
+ *
899
+ * Only `additionalContext` is consumed by the host CLI — it is appended as
900
+ * hidden guidance to the model alongside the failed tool result. Other fields
901
+ * such as `modifiedResult` or `suppressOutput` are not honored for failure
902
+ * hooks (see {@link PostToolUseHookOutput} for the success-only hook).
903
+ */
904
+ export interface PostToolUseFailureHookOutput {
905
+ additionalContext?: string;
906
+ }
907
+ /**
908
+ * Handler for post-tool-use-failure hook.
909
+ *
910
+ * Fires after a tool execution whose result was `"failure"`. `onPostToolUse`
911
+ * only fires for successful results, so register this handler to observe or
912
+ * react to failed tool outcomes.
913
+ *
914
+ * Note: `"rejected"`, `"denied"`, and `"timeout"` results do not currently
915
+ * trigger this hook either — only `"failure"` does.
916
+ */
917
+ export type PostToolUseFailureHandler = (input: PostToolUseFailureHookInput, invocation: {
918
+ sessionId: string;
919
+ }) => Promise<PostToolUseFailureHookOutput | void> | PostToolUseFailureHookOutput | void;
852
920
  /**
853
921
  * Input for user-prompt-submitted hook
854
922
  */
@@ -947,9 +1015,20 @@ export interface SessionHooks {
947
1015
  */
948
1016
  onPreMcpToolCall?: PreMcpToolCallHandler;
949
1017
  /**
950
- * Called after a tool is executed
1018
+ * Called after a tool is executed with a successful result.
1019
+ *
1020
+ * For failed tool executions, register {@link onPostToolUseFailure} instead;
1021
+ * this handler does not fire for non-success results.
951
1022
  */
952
1023
  onPostToolUse?: PostToolUseHandler;
1024
+ /**
1025
+ * Called after a tool execution whose result was `"failure"`.
1026
+ *
1027
+ * Register this handler alongside {@link onPostToolUse} to observe failed
1028
+ * tool calls — `onPostToolUse` only fires for successful results, so
1029
+ * without this hook failed tool calls are invisible to extensions.
1030
+ */
1031
+ onPostToolUseFailure?: PostToolUseFailureHandler;
953
1032
  /**
954
1033
  * Called when the user submits a prompt
955
1034
  */
@@ -1207,14 +1286,25 @@ export interface SessionConfigBase {
1207
1286
  systemMessage?: SystemMessageConfig;
1208
1287
  /**
1209
1288
  * List of tool names to allow. When specified, only these tools will be available.
1210
- * Takes precedence over excludedTools.
1289
+ *
1290
+ * Supports source-qualified filter patterns (`builtin:*`, `builtin:<name>`,
1291
+ * `mcp:*`, `mcp:<name>`, `custom:*`, `custom:<name>`) as well as the bare
1292
+ * name form (exact match across any source). Build this list with
1293
+ * {@link ToolSet} for type safety and readable intent.
1294
+ *
1295
+ * Composes with {@link excludedTools}: a tool is enabled when it matches
1296
+ * `availableTools` (or `availableTools` is unset) AND it does not match
1297
+ * `excludedTools`. This lets you express "everything matching X except Y".
1211
1298
  */
1212
- availableTools?: string[];
1299
+ availableTools?: string[] | ToolSet;
1213
1300
  /**
1214
- * List of tool names to disable. All other tools remain available.
1215
- * Ignored if availableTools is specified.
1301
+ * List of tool names to disable. Supports the same pattern syntax as
1302
+ * {@link availableTools}.
1303
+ *
1304
+ * Always takes precedence over {@link availableTools}: a tool listed here
1305
+ * is disabled even if it also matches `availableTools`.
1216
1306
  */
1217
- excludedTools?: string[];
1307
+ excludedTools?: string[] | ToolSet;
1218
1308
  /**
1219
1309
  * Custom provider configuration (BYOK - Bring Your Own Key).
1220
1310
  * When specified, uses the provided API endpoint instead of the Copilot API.
@@ -1229,6 +1319,39 @@ export interface SessionConfigBase {
1229
1319
  * This is independent of the OpenTelemetry configuration in {@link CopilotClientOptions.telemetry}.
1230
1320
  */
1231
1321
  enableSessionTelemetry?: boolean;
1322
+ /**
1323
+ * When true, the runtime skips loading custom-instruction sources
1324
+ * (e.g. `.github/copilot-instructions.md`, `AGENTS.md`, `CLAUDE.md`).
1325
+ *
1326
+ * Defaults to `false` (custom instructions are loaded). Under
1327
+ * {@link CopilotClientOptions.mode} = `"empty"`, defaults to `true`; apps
1328
+ * can pass `false` here to opt back in.
1329
+ */
1330
+ skipCustomInstructions?: boolean;
1331
+ /**
1332
+ * When true, custom agents default to local-only execution and are not
1333
+ * dispatched to remote workers.
1334
+ *
1335
+ * Defaults to `false`. Under {@link CopilotClientOptions.mode} = `"empty"`,
1336
+ * defaults to `true`; apps can pass `false` here to opt back in.
1337
+ */
1338
+ customAgentsLocalOnly?: boolean;
1339
+ /**
1340
+ * When true, the runtime instructs the agent to include a `Co-authored-by`
1341
+ * trailer in commit messages it composes.
1342
+ *
1343
+ * Defaults to `true`. Under {@link CopilotClientOptions.mode} = `"empty"`,
1344
+ * defaults to `false`; apps can pass `true` here to opt back in.
1345
+ */
1346
+ coauthorEnabled?: boolean;
1347
+ /**
1348
+ * When true, the `manage_schedule` tool is exposed to the agent.
1349
+ *
1350
+ * Defaults to whatever the runtime exposes (typically gated to staff
1351
+ * users). Under {@link CopilotClientOptions.mode} = `"empty"`, defaults to
1352
+ * `false`; apps can pass `true` here to opt back in.
1353
+ */
1354
+ manageScheduleEnabled?: boolean;
1232
1355
  /**
1233
1356
  * Optional handler for permission requests from the server.
1234
1357
  * When omitted, permission requests are surfaced as events and left pending for
@@ -1514,6 +1637,11 @@ export interface MessageOptions {
1514
1637
  * - "immediate": Send immediately
1515
1638
  */
1516
1639
  mode?: "enqueue" | "immediate";
1640
+ /**
1641
+ * The UI mode the agent was in when this message was sent (for example "plan" or "autopilot").
1642
+ * Defaults to the session's current mode when unset.
1643
+ */
1644
+ agentMode?: "interactive" | "plan" | "autopilot" | "shell";
1517
1645
  /**
1518
1646
  * Custom HTTP headers to include in outbound model requests for this turn.
1519
1647
  */
@@ -118,19 +118,20 @@ hooks: {
118
118
  onUserPromptSubmitted: async (input, invocation) => { ... },
119
119
  onPreToolUse: async (input, invocation) => { ... },
120
120
  onPostToolUse: async (input, invocation) => { ... },
121
+ onPostToolUseFailure: async (input, invocation) => { ... },
121
122
  onSessionStart: async (input, invocation) => { ... },
122
123
  onSessionEnd: async (input, invocation) => { ... },
123
124
  onErrorOccurred: async (input, invocation) => { ... },
124
125
  }
125
126
  ```
126
127
 
127
- All hook inputs include `timestamp` (unix ms) and `cwd` (working directory).
128
+ All hook inputs include `timestamp` (`Date`) and `workingDirectory`.
128
129
  All handlers receive `invocation: { sessionId: string }` as the second argument.
129
130
  All handlers may return `void`/`undefined` (no-op) or an output object.
130
131
 
131
132
  ### onUserPromptSubmitted
132
133
 
133
- **Input:** `{ prompt: string, timestamp, cwd }`
134
+ **Input:** `{ prompt: string, timestamp, workingDirectory }`
134
135
 
135
136
  **Output (all fields optional):**
136
137
  | Field | Type | Effect |
@@ -140,7 +141,7 @@ All handlers may return `void`/`undefined` (no-op) or an output object.
140
141
 
141
142
  ### onPreToolUse
142
143
 
143
- **Input:** `{ toolName: string, toolArgs: unknown, timestamp, cwd }`
144
+ **Input:** `{ toolName: string, toolArgs: unknown, timestamp, workingDirectory }`
144
145
 
145
146
  **Output (all fields optional):**
146
147
  | Field | Type | Effect |
@@ -152,7 +153,10 @@ All handlers may return `void`/`undefined` (no-op) or an output object.
152
153
 
153
154
  ### onPostToolUse
154
155
 
155
- **Input:** `{ toolName: string, toolArgs: unknown, toolResult: ToolResultObject, timestamp, cwd }`
156
+ **Input:** `{ toolName: string, toolArgs: unknown, toolResult: ToolResultObject, timestamp, workingDirectory }`
157
+
158
+ Fires only when the tool returned a successful result. To observe non-success
159
+ outcomes, register `onPostToolUseFailure` as well.
156
160
 
157
161
  **Output (all fields optional):**
158
162
  | Field | Type | Effect |
@@ -160,9 +164,29 @@ All handlers may return `void`/`undefined` (no-op) or an output object.
160
164
  | `modifiedResult` | `ToolResultObject` | Replaces the tool result |
161
165
  | `additionalContext` | `string` | Injected into the conversation |
162
166
 
167
+ ### onPostToolUseFailure
168
+
169
+ **Input:** `{ toolName: string, toolArgs: unknown, error: string, timestamp, workingDirectory }`
170
+
171
+ Fires after a tool execution whose result was `"failure"`. `onPostToolUse`
172
+ does **not** fire for these outcomes, so register this handler to observe or
173
+ react to them — useful for telemetry, replay buffers, fault-injection tests,
174
+ or pairing pre/post tool tracking that would otherwise leak when the tool
175
+ fails. Note the input shape differs from `onPostToolUse`: only `error` (the
176
+ stringified failure message) is provided, not the full `toolResult`.
177
+
178
+ **Output (all fields optional):**
179
+ | Field | Type | Effect |
180
+ |-------|------|--------|
181
+ | `additionalContext` | `string` | Appended as hidden guidance the model sees alongside the failed tool result |
182
+
183
+ Note: only `"failure"` results trigger this hook. Other non-success
184
+ `resultType` values (`"rejected"`, `"denied"`, `"timeout"`) do not currently
185
+ fire it.
186
+
163
187
  ### onSessionStart
164
188
 
165
- **Input:** `{ source: "startup" \| "resume" \| "new", initialPrompt?: string, timestamp, cwd }`
189
+ **Input:** `{ source: "startup" \| "resume" \| "new", initialPrompt?: string, timestamp, workingDirectory }`
166
190
 
167
191
  **Output (all fields optional):**
168
192
  | Field | Type | Effect |
@@ -171,7 +195,7 @@ All handlers may return `void`/`undefined` (no-op) or an output object.
171
195
 
172
196
  ### onSessionEnd
173
197
 
174
- **Input:** `{ reason: "complete" \| "error" \| "abort" \| "timeout" \| "user_exit", finalMessage?: string, error?: string, timestamp, cwd }`
198
+ **Input:** `{ reason: "complete" \| "error" \| "abort" \| "timeout" \| "user_exit", finalMessage?: string, error?: string, timestamp, workingDirectory }`
175
199
 
176
200
  **Output (all fields optional):**
177
201
  | Field | Type | Effect |
@@ -181,7 +205,7 @@ All handlers may return `void`/`undefined` (no-op) or an output object.
181
205
 
182
206
  ### onErrorOccurred
183
207
 
184
- **Input:** `{ error: string, errorContext: "model_call" \| "tool_execution" \| "system" \| "user_input", recoverable: boolean, timestamp, cwd }`
208
+ **Input:** `{ error: string, errorContext: "model_call" \| "tool_execution" \| "system" \| "user_input", recoverable: boolean, timestamp, workingDirectory }`
185
209
 
186
210
  **Output (all fields optional):**
187
211
  | Field | Type | Effect |
package/docs/examples.md CHANGED
@@ -152,16 +152,17 @@ Hooks intercept and modify behavior at key lifecycle points. Register them in th
152
152
 
153
153
  ### Available Hooks
154
154
 
155
- | Hook | Fires When | Can Modify |
156
- | ----------------------- | ------------------------- | ------------------------------------------- |
157
- | `onUserPromptSubmitted` | User sends a message | The prompt text, add context |
158
- | `onPreToolUse` | Before a tool executes | Tool args, permission decision, add context |
159
- | `onPostToolUse` | After a tool executes | Tool result, add context |
160
- | `onSessionStart` | Session starts or resumes | Add context, modify config |
161
- | `onSessionEnd` | Session ends | Cleanup actions, summary |
162
- | `onErrorOccurred` | An error occurs | Error handling strategy (retry/skip/abort) |
163
-
164
- All hook inputs include `timestamp` (unix ms) and `cwd` (working directory).
155
+ | Hook | Fires When | Can Modify |
156
+ | ----------------------- | ---------------------------------------- | ------------------------------------------- |
157
+ | `onUserPromptSubmitted` | User sends a message | The prompt text, add context |
158
+ | `onPreToolUse` | Before a tool executes | Tool args, permission decision, add context |
159
+ | `onPostToolUse` | After a tool executes successfully | Tool result, add context |
160
+ | `onPostToolUseFailure` | After a tool execution returns a failure | Add hidden guidance to the model |
161
+ | `onSessionStart` | Session starts or resumes | Add context, modify config |
162
+ | `onSessionEnd` | Session ends | Cleanup actions, summary |
163
+ | `onErrorOccurred` | An error occurs | Error handling strategy (retry/skip/abort) |
164
+
165
+ All hook inputs include `timestamp` (`Date`) and `workingDirectory`.
165
166
 
166
167
  ### Modifying the user's message
167
168
 
@@ -267,12 +268,18 @@ hooks: {
267
268
  }
268
269
  ```
269
270
 
270
- ### Augmenting tool results with extra context
271
+ ### Reacting when a tool fails
272
+
273
+ `onPostToolUse` only fires for successful tool executions. To observe or react
274
+ to failures, register `onPostToolUseFailure`. The input includes
275
+ `input.error` (the stringified failure message); only `additionalContext` on
276
+ the return value is consumed by the runtime, and it is appended as hidden
277
+ guidance alongside the failed tool result.
271
278
 
272
279
  ```js
273
280
  hooks: {
274
- onPostToolUse: async (input) => {
275
- if (input.toolName === "bash" && input.toolResult?.resultType === "failure") {
281
+ onPostToolUseFailure: async (input) => {
282
+ if (input.toolName === "bash") {
276
283
  return {
277
284
  additionalContext: "The command failed. Try a different approach.",
278
285
  };
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "type": "git",
5
5
  "url": "https://github.com/github/copilot-sdk.git"
6
6
  },
7
- "version": "1.0.0-beta.7",
7
+ "version": "1.0.0-beta.9",
8
8
  "description": "TypeScript SDK for programmatic control of GitHub Copilot CLI via JSON-RPC",
9
9
  "main": "./dist/cjs/index.js",
10
10
  "types": "./dist/index.d.ts",
@@ -56,7 +56,7 @@
56
56
  "author": "GitHub",
57
57
  "license": "MIT",
58
58
  "dependencies": {
59
- "@github/copilot": "^1.0.53-2",
59
+ "@github/copilot": "^1.0.55-5",
60
60
  "vscode-jsonrpc": "^8.2.1",
61
61
  "zod": "^4.3.6"
62
62
  },