@github/copilot-sdk 1.0.0-beta.1 → 1.0.0-beta.11

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.js CHANGED
@@ -1,4 +1,32 @@
1
1
  import { createSessionFsAdapter } from "./sessionFsProvider.js";
2
+ const RuntimeConnection = {
3
+ /**
4
+ * Spawn a runtime child process and communicate over its stdin/stdout.
5
+ * This is the default if no {@link CopilotClientOptions.connection} is set.
6
+ */
7
+ forStdio(opts = {}) {
8
+ return { kind: "stdio", path: opts.path, args: opts.args };
9
+ },
10
+ /**
11
+ * Spawn a runtime child process that listens on a TCP socket and connect to it.
12
+ */
13
+ forTcp(opts = {}) {
14
+ return {
15
+ kind: "tcp",
16
+ port: opts.port,
17
+ connectionToken: opts.connectionToken,
18
+ path: opts.path,
19
+ args: opts.args
20
+ };
21
+ },
22
+ /**
23
+ * Connect to an already-running runtime at the given URL. The SDK does not
24
+ * spawn a process in this mode.
25
+ */
26
+ forUri(url, opts = {}) {
27
+ return { kind: "uri", url, connectionToken: opts.connectionToken };
28
+ }
29
+ };
2
30
  function convertMcpCallToolResult(callResult) {
3
31
  const textParts = [];
4
32
  const binaryResults = [];
@@ -23,9 +51,10 @@ function convertMcpCallToolResult(callResult) {
23
51
  textParts.push(block.resource.text);
24
52
  }
25
53
  if (block.resource?.blob) {
54
+ const mimeType = block.resource.mimeType;
26
55
  binaryResults.push({
27
56
  data: block.resource.blob,
28
- mimeType: block.resource.mimeType ?? "application/octet-stream",
57
+ mimeType: typeof mimeType === "string" && mimeType ? mimeType : "application/octet-stream",
29
58
  type: "resource",
30
59
  description: block.resource.uri
31
60
  });
@@ -43,7 +72,7 @@ function convertMcpCallToolResult(callResult) {
43
72
  function defineTool(name, config) {
44
73
  return { name, ...config };
45
74
  }
46
- const SYSTEM_PROMPT_SECTIONS = {
75
+ const SYSTEM_MESSAGE_SECTIONS = {
47
76
  identity: { description: "Agent identity preamble and mode statement" },
48
77
  tone: { description: "Response style, conciseness rules, output formatting preferences" },
49
78
  tool_efficiency: { description: "Tool usage patterns, parallel calling, batching guidelines" },
@@ -53,6 +82,9 @@ const SYSTEM_PROMPT_SECTIONS = {
53
82
  safety: { description: "Environment limitations, prohibited actions, security policies" },
54
83
  tool_instructions: { description: "Per-tool usage instructions" },
55
84
  custom_instructions: { description: "Repository and organization custom instructions" },
85
+ runtime_instructions: {
86
+ description: "Runtime-provided context and instructions (e.g. system notifications, memories, workspace context, mode-specific instructions, content-exclusion policy)"
87
+ },
56
88
  last_instructions: {
57
89
  description: "End-of-prompt instructions: parallel tool calling, persistence, task completion"
58
90
  }
@@ -62,7 +94,8 @@ const defaultJoinSessionPermissionHandler = () => ({
62
94
  kind: "no-result"
63
95
  });
64
96
  export {
65
- SYSTEM_PROMPT_SECTIONS,
97
+ RuntimeConnection,
98
+ SYSTEM_MESSAGE_SECTIONS,
66
99
  approveAll,
67
100
  convertMcpCallToolResult,
68
101
  createSessionFsAdapter,
@@ -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 |
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
  };
@@ -408,7 +415,7 @@ session.on("assistant.message", (event) => {
408
415
  | Event Type | Description | Key Data Fields |
409
416
  | --------------------------- | ------------------------------------------------ | ------------------------------------------------------ |
410
417
  | `assistant.message` | Agent's final response | `content`, `messageId`, `toolRequests` |
411
- | `assistant.streaming_delta` | Token-by-token streaming (ephemeral) | `totalResponseSizeBytes` |
418
+ | `assistant.message_delta` | Message content chunks (ephemeral) | `deltaContent` |
412
419
  | `tool.execution_start` | A tool is about to run | `toolCallId`, `toolName`, `arguments` |
413
420
  | `tool.execution_complete` | A tool finished running | `toolCallId`, `toolName`, `success`, `result`, `error` |
414
421
  | `user.message` | User sent a message | `content`, `attachments`, `source` |
@@ -561,12 +568,12 @@ const session = await joinSession({
561
568
  onPermissionRequest: async (request) => {
562
569
  if (request.kind === "shell") {
563
570
  // request.fullCommandText has the shell command
564
- return { kind: "approved" };
571
+ return { kind: "approve-once" };
565
572
  }
566
573
  if (request.kind === "write") {
567
- return { kind: "approved" };
574
+ return { kind: "approve-once" };
568
575
  }
569
- return { kind: "denied-by-rules" };
576
+ return { kind: "reject" };
570
577
  },
571
578
  });
572
579
  ```
@@ -622,8 +629,11 @@ const session = await joinSession({
622
629
  onPreToolUse: async (input) => {
623
630
  if (input.toolName === "bash") {
624
631
  const cmd = String(input.toolArgs?.command || "");
625
- if (/rm\\s+-rf\\s+\\/ / i.test(cmd) || /Remove-Item\\s+.*-Recurse/i.test(cmd)) {
626
- return { permissionDecision: "deny" };
632
+ if (/rm\\s+-rf\\s+\//i.test(cmd) || /Remove-Item\\s+.*-Recurse/i.test(cmd)) {
633
+ return {
634
+ permissionDecision: "deny",
635
+ permissionDecisionReason: "Destructive commands are not allowed.",
636
+ };
627
637
  }
628
638
  }
629
639
  },
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.1",
7
+ "version": "1.0.0-beta.11",
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",
@@ -40,11 +40,11 @@
40
40
  "format:check": "prettier --check \"src/**/*.ts\" \"test/**/*.ts\" --ignore-path .prettierignore",
41
41
  "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
42
42
  "lint:fix": "eslint --fix \"src/**/*.ts\" \"test/**/*.ts\"",
43
- "typecheck": "tsc --noEmit",
43
+ "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
44
44
  "generate": "cd ../scripts/codegen && npm run generate",
45
45
  "update:protocol-version": "tsx scripts/update-protocol-version.ts",
46
46
  "prepublishOnly": "npm run build",
47
- "package": "npm run clean && npm run build && node scripts/set-version.js && npm pack && npm version 0.1.0 --no-git-tag-version --allow-same-version"
47
+ "package": "npm run clean && npm run build && node scripts/set-version.js && npm pack && npm version 0.0.0-dev --no-git-tag-version --allow-same-version"
48
48
  },
49
49
  "keywords": [
50
50
  "github",
@@ -56,7 +56,7 @@
56
56
  "author": "GitHub",
57
57
  "license": "MIT",
58
58
  "dependencies": {
59
- "@github/copilot": "^1.0.41-0",
59
+ "@github/copilot": "^1.0.57",
60
60
  "vscode-jsonrpc": "^8.2.1",
61
61
  "zod": "^4.3.6"
62
62
  },