@github/copilot-sdk 1.0.17-preview.3 → 1.0.17-preview.5

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.
@@ -37,6 +37,10 @@ export declare class SessionFsSqliteTransactionFailure extends Error {
37
37
  readonly errorClass: SessionFsSqliteTransactionErrorClass;
38
38
  constructor(message: string, errorClass?: SessionFsSqliteTransactionErrorClass);
39
39
  }
40
+ /** Throw from `writeFile` only when the provider changed the target before failing. */
41
+ export declare class SessionFsWriteFailure extends Error {
42
+ readonly writeChanged = true;
43
+ }
40
44
  /**
41
45
  * SQLite operations for the per-session database.
42
46
  * Implementers provide query execution and existence checking.
@@ -78,7 +82,11 @@ export interface SessionFsSqliteProvider {
78
82
  export interface SessionFsProvider {
79
83
  /** Reads the full content of a file. Throw if the file does not exist. */
80
84
  readFile(path: string): Promise<string>;
81
- /** Writes content to a file, creating parent directories if needed. */
85
+ /** Read exact file bytes. Required when capabilities.binary is enabled. */
86
+ readFileBytes?(path: string): Promise<Uint8Array>;
87
+ /** Write exact file bytes. Required when capabilities.binary is enabled. */
88
+ writeFileBytes?(path: string, content: Uint8Array, mode?: number): Promise<void>;
89
+ /** Writes content to a file, creating parent directories if needed. Throw {@link SessionFsWriteFailure} if a failed write changed the target. */
82
90
  writeFile(path: string, content: string, mode?: number): Promise<void>;
83
91
  /** Appends content to a file, creating parent directories if needed. */
84
92
  appendFile(path: string, content: string, mode?: number): Promise<void>;
@@ -1,3 +1,5 @@
1
+ const MAX_BINARY_BYTES = (64 * 1024 * 1024 - 1024) / 4 * 3;
2
+ const MAX_BINARY_CONTENT_LENGTH = Math.ceil(MAX_BINARY_BYTES / 3) * 4;
1
3
  class SessionFsSqliteTransactionFailure extends Error {
2
4
  /** Failure classification reported to the runtime. */
3
5
  errorClass;
@@ -7,6 +9,9 @@ class SessionFsSqliteTransactionFailure extends Error {
7
9
  this.errorClass = errorClass;
8
10
  }
9
11
  }
12
+ class SessionFsWriteFailure extends Error {
13
+ writeChanged = true;
14
+ }
10
15
  function normalizeSqliteParams(params) {
11
16
  if (!params) {
12
17
  return void 0;
@@ -29,10 +34,60 @@ function createSessionFsAdapter(provider) {
29
34
  return { content: "", error: toSessionFsError(err) };
30
35
  }
31
36
  },
37
+ readFileBytes: async ({ path }) => {
38
+ if (!provider.readFileBytes) {
39
+ return {
40
+ content: "",
41
+ error: { code: "UNKNOWN", message: "Binary reads are not supported" }
42
+ };
43
+ }
44
+ try {
45
+ const bytes = await provider.readFileBytes(path);
46
+ if (bytes.length > MAX_BINARY_BYTES) {
47
+ return {
48
+ content: "",
49
+ error: {
50
+ code: "UNKNOWN",
51
+ message: "sessionFs.readFileBytes content exceeds the binary read limit"
52
+ }
53
+ };
54
+ }
55
+ return {
56
+ content: Buffer.from(bytes).toString("base64")
57
+ };
58
+ } catch (err) {
59
+ return { content: "", error: toSessionFsError(err) };
60
+ }
61
+ },
32
62
  writeFile: async ({ path, content, mode }) => {
33
63
  try {
34
64
  await provider.writeFile(path, content, mode);
35
65
  return void 0;
66
+ } catch (err) {
67
+ const error = toSessionFsError(err);
68
+ return err instanceof SessionFsWriteFailure ? { ...error, writeChanged: true } : error;
69
+ }
70
+ },
71
+ writeFileBytes: async ({ path, content, mode }) => {
72
+ if (!provider.writeFileBytes) {
73
+ return { code: "UNKNOWN", message: "Binary writes are not supported" };
74
+ }
75
+ if (content.length > MAX_BINARY_CONTENT_LENGTH) {
76
+ return {
77
+ code: "UNKNOWN",
78
+ message: "sessionFs.writeFileBytes content exceeds the binary write limit"
79
+ };
80
+ }
81
+ const bytes = Buffer.from(content, "base64");
82
+ if (bytes.toString("base64") !== content || bytes.length > MAX_BINARY_BYTES) {
83
+ return {
84
+ code: "UNKNOWN",
85
+ message: "invalid sessionFs.writeFileBytes base64 content"
86
+ };
87
+ }
88
+ try {
89
+ await provider.writeFileBytes(path, bytes, mode);
90
+ return void 0;
36
91
  } catch (err) {
37
92
  return toSessionFsError(err);
38
93
  }
@@ -169,5 +224,6 @@ function toSqliteTransactionError(err) {
169
224
  }
170
225
  export {
171
226
  SessionFsSqliteTransactionFailure,
227
+ SessionFsWriteFailure,
172
228
  createSessionFsAdapter
173
229
  };
package/dist/types.d.ts CHANGED
@@ -48,6 +48,7 @@ export type { SessionFsSqliteProvider } from "./sessionFsProvider.js";
48
48
  export type { SessionFsSqliteStatement } from "./sessionFsProvider.js";
49
49
  export type { SessionFsSqliteTransactionErrorClass } from "./sessionFsProvider.js";
50
50
  export { SessionFsSqliteTransactionFailure } from "./sessionFsProvider.js";
51
+ export { SessionFsWriteFailure } from "./sessionFsProvider.js";
51
52
  export type { LlmInferenceHeaders } from "./generated/rpc.js";
52
53
  export type { PermissionDecisionContext, PermissionDecisionOutcome, PermissionDecisionSurface, PermissionResponseCapability, } from "./generated/rpc.js";
53
54
  export type { PermissionDecisionSource } from "./generated/session-events.js";
@@ -922,6 +923,8 @@ export interface SystemMessageReplaceConfig {
922
923
  /**
923
924
  * Customize mode: Override individual sections of the system prompt.
924
925
  * Keeps the SDK-managed prompt structure while allowing targeted modifications.
926
+ * The `last_instructions` section includes configured subagent-model guidance.
927
+ * Its overrides and transforms control that prose, not runtime model selection or tool availability.
925
928
  */
926
929
  export interface SystemMessageCustomizeConfig {
927
930
  mode: "customize";
@@ -1098,8 +1101,9 @@ export type AutoModeSwitchHandler = (request: AutoModeSwitchRequest, invocation:
1098
1101
  * Base interface for all hook inputs
1099
1102
  */
1100
1103
  export interface BaseHookInput {
1101
- /** The runtime session ID of the session that triggered the hook.
1102
- * For sub-agent hooks this differs from `invocation.sessionId`. */
1104
+ /** The runtime session ID associated with the hook. Child tool hooks use
1105
+ * the child session ID; sub-agent lifecycle hooks use the parent session ID,
1106
+ * matching `invocation.sessionId`. */
1103
1107
  sessionId: string;
1104
1108
  /** Time at which the hook event was emitted by the runtime. */
1105
1109
  timestamp: Date;
@@ -1366,6 +1370,54 @@ export interface AgentStopHookOutput {
1366
1370
  export type AgentStopHandler = (input: AgentStopHookInput, invocation: {
1367
1371
  sessionId: string;
1368
1372
  }) => Promise<AgentStopHookOutput | void> | AgentStopHookOutput | void;
1373
+ /**
1374
+ * Input for the hook fired before a sub-agent's first turn.
1375
+ *
1376
+ * The session metadata belongs to the parent session, not the child.
1377
+ */
1378
+ export interface SubagentStartHookInput extends BaseHookInput {
1379
+ transcriptPath: string;
1380
+ agentName: string;
1381
+ agentDisplayName?: string;
1382
+ agentDescription?: string;
1383
+ }
1384
+ /** Output for the sub-agent start hook. Context is prepended to the child's initial prompt. */
1385
+ export interface SubagentStartHookOutput {
1386
+ additionalContext?: string;
1387
+ }
1388
+ /** Handler for the sub-agent start hook. */
1389
+ export type SubagentStartHandler = (input: SubagentStartHookInput, invocation: {
1390
+ sessionId: string;
1391
+ }) => Promise<SubagentStartHookOutput | void> | SubagentStartHookOutput | void;
1392
+ /**
1393
+ * Input for the hook fired after a sub-agent completes a turn.
1394
+ *
1395
+ * The response is the child's last assistant message before any hook rewrite.
1396
+ */
1397
+ export interface SubagentStopHookInput extends SubagentStartHookInput {
1398
+ agentId?: string;
1399
+ agentType: string;
1400
+ stopReason: "end_turn";
1401
+ response: string;
1402
+ }
1403
+ /**
1404
+ * Output for the sub-agent stop hook. `"block"` with a nonempty `reason` continues
1405
+ * the child; otherwise `modifiedResponse` replaces the response reported to the parent.
1406
+ * When both are supplied, a valid block takes precedence over the rewrite.
1407
+ */
1408
+ export type SubagentStopHookOutput = {
1409
+ decision: "block";
1410
+ reason: string;
1411
+ modifiedResponse?: string;
1412
+ } | {
1413
+ decision?: "allow";
1414
+ reason?: never;
1415
+ modifiedResponse?: string;
1416
+ };
1417
+ /** Handler for the sub-agent stop hook. */
1418
+ export type SubagentStopHandler = (input: SubagentStopHookInput, invocation: {
1419
+ sessionId: string;
1420
+ }) => Promise<SubagentStopHookOutput | void> | SubagentStopHookOutput | void;
1369
1421
  /**
1370
1422
  * Configuration for session hooks
1371
1423
  */
@@ -1422,6 +1474,13 @@ export interface SessionHooks {
1422
1474
  * agent stop.
1423
1475
  */
1424
1476
  onAgentStop?: AgentStopHandler;
1477
+ /** Called before a sub-agent's first turn. Return context to prepend to its prompt. */
1478
+ onSubagentStart?: SubagentStartHandler;
1479
+ /**
1480
+ * Called after a sub-agent completes a turn. Return a block reason to
1481
+ * continue the child, or a replacement response to report to the parent.
1482
+ */
1483
+ onSubagentStop?: SubagentStopHandler;
1425
1484
  }
1426
1485
  /**
1427
1486
  * Base interface for MCP server configuration.
@@ -2894,6 +2953,12 @@ export interface SessionFsConfig {
2894
2953
  * @default false
2895
2954
  */
2896
2955
  sqlite?: boolean;
2956
+ /**
2957
+ * Whether this provider supports exact binary reads and writes through readFileBytes and writeFileBytes.
2958
+ * Required to view images stored only in the provider.
2959
+ * @default false
2960
+ */
2961
+ binary?: boolean;
2897
2962
  };
2898
2963
  }
2899
2964
  /**
package/dist/types.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { createSessionFsAdapter } from "./sessionFsProvider.js";
2
2
  import { SessionFsSqliteTransactionFailure } from "./sessionFsProvider.js";
3
+ import { SessionFsWriteFailure } from "./sessionFsProvider.js";
3
4
  import {
4
5
  CopilotRequestHandler,
5
6
  CopilotWebSocketHandler,
@@ -106,10 +107,10 @@ const SYSTEM_MESSAGE_SECTIONS = {
106
107
  tool_instructions: { description: "Per-tool usage instructions" },
107
108
  custom_instructions: { description: "Repository and organization custom instructions" },
108
109
  runtime_instructions: {
109
- description: "Runtime-provided context and instructions (e.g. system notifications, memories, workspace context, mode-specific instructions, content-exclusion policy)"
110
+ description: "Runtime-provided system-prompt context and instructions, such as system notifications, memories, workspace context, and content-exclusion policy. Mode-specific instructions can travel in transition messages instead."
110
111
  },
111
112
  last_instructions: {
112
- description: "End-of-prompt instructions: parallel tool calling, persistence, task completion"
113
+ description: "End-of-prompt instructions: parallel tool calling, persistence, task completion, and configured subagent-model guidance when the task tool is available"
113
114
  }
114
115
  };
115
116
  function isAttributedPermissionResult(result) {
@@ -149,6 +150,7 @@ export {
149
150
  RuntimeConnection,
150
151
  SYSTEM_MESSAGE_SECTIONS,
151
152
  SessionFsSqliteTransactionFailure,
153
+ SessionFsWriteFailure,
152
154
  approveAll,
153
155
  convertMcpCallToolResult,
154
156
  createAttributedPermissionResult,
@@ -122,10 +122,12 @@ hooks: {
122
122
  onSessionStart: async (input, invocation) => { ... },
123
123
  onSessionEnd: async (input, invocation) => { ... },
124
124
  onErrorOccurred: async (input, invocation) => { ... },
125
+ onSubagentStart: async (input, invocation) => { ... },
126
+ onSubagentStop: async (input, invocation) => { ... },
125
127
  }
126
128
  ```
127
129
 
128
- All hook inputs include `timestamp` (`Date`) and `workingDirectory`.
130
+ All hook inputs include `sessionId`, `timestamp` (`Date`) and `workingDirectory`.
129
131
  All handlers receive `invocation: { sessionId: string }` as the second argument.
130
132
  All handlers may return `void`/`undefined` (no-op) or an output object.
131
133
 
@@ -214,7 +216,32 @@ fire it.
214
216
  | `retryCount` | `number` | Max retries (when errorHandling is "retry") |
215
217
  | `userNotification` | `string` | Message shown to the user |
216
218
 
217
- ---
219
+ ### onSubagentStart
220
+
221
+ Fires before a sub-agent's first turn. The input's `sessionId` and the
222
+ invocation's `sessionId` identify the parent session, not the child.
223
+
224
+ **Input:** `{ sessionId: string, transcriptPath: string, agentName: string, agentDisplayName?: string, agentDescription?: string, timestamp, workingDirectory }`
225
+
226
+ **Output (optional):**
227
+ | Field | Type | Effect |
228
+ |-------|------|--------|
229
+ | `additionalContext` | `string` | Prepended to the child's initial prompt |
230
+
231
+ ### onSubagentStop
232
+
233
+ Fires after a sub-agent completes a turn. The input includes the child's last
234
+ assistant `response` and the parent's session metadata. `agentId` is available
235
+ when the task registry supplies one. This is distinct from `onAgentStop`, which
236
+ only runs for the top-level agent.
237
+
238
+ **Input:** `{ sessionId: string, transcriptPath: string, agentName: string, agentDisplayName?: string, agentDescription?: string, agentId?: string, agentType: string, stopReason: "end_turn", response: string, timestamp, workingDirectory }`
239
+
240
+ **Output (choose one, or return nothing):**
241
+ | Field | Type | Effect |
242
+ |-------|------|--------|
243
+ | `decision` and `reason` | `"block"` and `string` | Continue the child for another turn using `reason` |
244
+ | `modifiedResponse` | `string` | Replace the child's response reported to the parent |
218
245
 
219
246
  ## Session Object
220
247
 
package/package.json CHANGED
@@ -5,8 +5,8 @@
5
5
  "url": "https://github.com/github/copilot-agent-runtime.git",
6
6
  "directory": "src/sdk/nodejs"
7
7
  },
8
- "version": "1.0.17-preview.3",
9
- "copilotCliVersion": "1.0.92-3",
8
+ "version": "1.0.17-preview.5",
9
+ "copilotCliVersion": "1.0.92-5",
10
10
  "description": "TypeScript SDK for programmatic control of GitHub Copilot CLI via JSON-RPC",
11
11
  "main": "./dist/cjs/index.js",
12
12
  "types": "./dist/index.d.ts",
@@ -98,22 +98,23 @@
98
98
  },
99
99
  "files": [
100
100
  "dist/**/*",
101
+ "!dist/tsconfig.tsbuildinfo",
101
102
  "docs/**/*",
102
103
  "README.md"
103
104
  ],
104
105
  "copilotRuntime": {
105
- "sourceSha": "7a09ab7e985d69cf9f6d446d5c83ae897c7f7daa",
106
- "version": "1.0.92-3",
106
+ "sourceSha": "6d9037e403e4fac0cc65be349f6ab0d9c9351564",
107
+ "version": "1.0.92-5",
107
108
  "visibility": "public"
108
109
  },
109
110
  "optionalDependencies": {
110
- "@github/copilot-sdk-darwin-arm64": "1.0.17-preview.3",
111
- "@github/copilot-sdk-darwin-x64": "1.0.17-preview.3",
112
- "@github/copilot-sdk-linux-arm64": "1.0.17-preview.3",
113
- "@github/copilot-sdk-linux-x64": "1.0.17-preview.3",
114
- "@github/copilot-sdk-linuxmusl-arm64": "1.0.17-preview.3",
115
- "@github/copilot-sdk-linuxmusl-x64": "1.0.17-preview.3",
116
- "@github/copilot-sdk-win32-arm64": "1.0.17-preview.3",
117
- "@github/copilot-sdk-win32-x64": "1.0.17-preview.3"
111
+ "@github/copilot-sdk-darwin-arm64": "1.0.17-preview.5",
112
+ "@github/copilot-sdk-darwin-x64": "1.0.17-preview.5",
113
+ "@github/copilot-sdk-linux-arm64": "1.0.17-preview.5",
114
+ "@github/copilot-sdk-linux-x64": "1.0.17-preview.5",
115
+ "@github/copilot-sdk-linuxmusl-arm64": "1.0.17-preview.5",
116
+ "@github/copilot-sdk-linuxmusl-x64": "1.0.17-preview.5",
117
+ "@github/copilot-sdk-win32-arm64": "1.0.17-preview.5",
118
+ "@github/copilot-sdk-win32-x64": "1.0.17-preview.5"
118
119
  }
119
120
  }