@github/copilot-sdk 0.2.2 → 0.3.0-preview.0
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/cjs/client.js +39 -4
- package/dist/cjs/extension.js +2 -4
- package/dist/cjs/generated/rpc.js +24 -5
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/session.js +2 -1
- package/dist/cjs/sessionFsProvider.js +121 -0
- package/dist/cjs/types.js +51 -0
- package/dist/client.d.ts +1 -0
- package/dist/client.js +39 -4
- package/dist/extension.d.ts +1 -1
- package/dist/extension.js +3 -3
- package/dist/generated/rpc.d.ts +1214 -1027
- package/dist/generated/rpc.js +24 -5
- package/dist/generated/session-events.d.ts +3490 -2894
- package/dist/index.d.ts +2 -2
- package/dist/index.js +9 -1
- package/dist/session.js +2 -1
- package/dist/sessionFsProvider.d.ts +44 -0
- package/dist/sessionFsProvider.js +97 -0
- package/dist/types.d.ts +96 -13
- package/dist/types.js +48 -0
- package/docs/agent-author.md +22 -14
- package/docs/examples.md +35 -31
- package/package.json +2 -2
package/docs/examples.md
CHANGED
|
@@ -10,14 +10,19 @@ Every extension starts with the same boilerplate:
|
|
|
10
10
|
import { joinSession } from "@github/copilot-sdk/extension";
|
|
11
11
|
|
|
12
12
|
const session = await joinSession({
|
|
13
|
-
hooks: {
|
|
14
|
-
|
|
13
|
+
hooks: {
|
|
14
|
+
/* ... */
|
|
15
|
+
},
|
|
16
|
+
tools: [
|
|
17
|
+
/* ... */
|
|
18
|
+
],
|
|
15
19
|
});
|
|
16
20
|
```
|
|
17
21
|
|
|
18
22
|
`joinSession` returns a `CopilotSession` object you can use to send messages and subscribe to events.
|
|
19
23
|
|
|
20
24
|
> **Platform notes (Windows vs macOS/Linux):**
|
|
25
|
+
>
|
|
21
26
|
> - Use `process.platform === "win32"` to detect Windows at runtime.
|
|
22
27
|
> - Clipboard: `pbcopy` on macOS, `clip` on Windows.
|
|
23
28
|
> - Use `exec()` instead of `execFile()` for `.cmd` scripts like `code`, `npx`, `npm` on Windows.
|
|
@@ -71,7 +76,7 @@ tools: [
|
|
|
71
76
|
return `Processed: ${args.input}`;
|
|
72
77
|
},
|
|
73
78
|
},
|
|
74
|
-
]
|
|
79
|
+
];
|
|
75
80
|
```
|
|
76
81
|
|
|
77
82
|
### Tool that invokes an external shell command
|
|
@@ -136,7 +141,7 @@ handler: async (args, invocation) => {
|
|
|
136
141
|
// invocation.toolCallId — unique ID for this tool call
|
|
137
142
|
// invocation.toolName — name of the tool being called
|
|
138
143
|
return "done";
|
|
139
|
-
}
|
|
144
|
+
};
|
|
140
145
|
```
|
|
141
146
|
|
|
142
147
|
---
|
|
@@ -147,14 +152,14 @@ Hooks intercept and modify behavior at key lifecycle points. Register them in th
|
|
|
147
152
|
|
|
148
153
|
### Available Hooks
|
|
149
154
|
|
|
150
|
-
| Hook
|
|
151
|
-
|
|
152
|
-
| `onUserPromptSubmitted` | User sends a message
|
|
153
|
-
| `onPreToolUse`
|
|
154
|
-
| `onPostToolUse`
|
|
155
|
-
| `onSessionStart`
|
|
156
|
-
| `onSessionEnd`
|
|
157
|
-
| `onErrorOccurred`
|
|
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) |
|
|
158
163
|
|
|
159
164
|
All hook inputs include `timestamp` (unix ms) and `cwd` (working directory).
|
|
160
165
|
|
|
@@ -400,18 +405,18 @@ session.on("assistant.message", (event) => {
|
|
|
400
405
|
|
|
401
406
|
### Top 10 Most Useful Event Types
|
|
402
407
|
|
|
403
|
-
| Event Type
|
|
404
|
-
|
|
405
|
-
| `assistant.message`
|
|
406
|
-
| `assistant.streaming_delta` | Token-by-token streaming (ephemeral)
|
|
407
|
-
| `tool.execution_start`
|
|
408
|
-
| `tool.execution_complete`
|
|
409
|
-
| `user.message`
|
|
410
|
-
| `session.idle`
|
|
411
|
-
| `session.error`
|
|
412
|
-
| `permission.requested`
|
|
413
|
-
| `session.shutdown`
|
|
414
|
-
| `assistant.turn_start`
|
|
408
|
+
| Event Type | Description | Key Data Fields |
|
|
409
|
+
| --------------------------- | ------------------------------------------------ | ------------------------------------------------------ |
|
|
410
|
+
| `assistant.message` | Agent's final response | `content`, `messageId`, `toolRequests` |
|
|
411
|
+
| `assistant.streaming_delta` | Token-by-token streaming (ephemeral) | `totalResponseSizeBytes` |
|
|
412
|
+
| `tool.execution_start` | A tool is about to run | `toolCallId`, `toolName`, `arguments` |
|
|
413
|
+
| `tool.execution_complete` | A tool finished running | `toolCallId`, `toolName`, `success`, `result`, `error` |
|
|
414
|
+
| `user.message` | User sent a message | `content`, `attachments`, `source` |
|
|
415
|
+
| `session.idle` | Session finished processing a turn | `backgroundTasks` |
|
|
416
|
+
| `session.error` | An error occurred | `errorType`, `message`, `stack` |
|
|
417
|
+
| `permission.requested` | Agent needs permission (shell, file write, etc.) | `requestId`, `permissionRequest.kind` |
|
|
418
|
+
| `session.shutdown` | Session is ending | `shutdownType`, `totalPremiumRequests`, `codeChanges` |
|
|
419
|
+
| `assistant.turn_start` | Agent begins a new thinking/response cycle | `turnId` |
|
|
415
420
|
|
|
416
421
|
### Example: Detecting when the plan file is created or edited
|
|
417
422
|
|
|
@@ -435,8 +440,10 @@ if (workspace) {
|
|
|
435
440
|
|
|
436
441
|
// Track agent edits to suppress false triggers
|
|
437
442
|
session.on("tool.execution_start", (event) => {
|
|
438
|
-
if (
|
|
439
|
-
|
|
443
|
+
if (
|
|
444
|
+
(event.data.toolName === "edit" || event.data.toolName === "create") &&
|
|
445
|
+
String(event.data.arguments?.path || "").endsWith("plan.md")
|
|
446
|
+
) {
|
|
440
447
|
agentEdits.add(event.data.toolCallId);
|
|
441
448
|
recentAgentPaths.add(planPath);
|
|
442
449
|
}
|
|
@@ -539,9 +546,7 @@ const response = await session.sendAndWait({ prompt: "What is 2 + 2?" });
|
|
|
539
546
|
```js
|
|
540
547
|
await session.send({
|
|
541
548
|
prompt: "Review this file",
|
|
542
|
-
attachments: [
|
|
543
|
-
{ type: "file", path: "./src/index.ts" },
|
|
544
|
-
],
|
|
549
|
+
attachments: [{ type: "file", path: "./src/index.ts" }],
|
|
545
550
|
});
|
|
546
551
|
```
|
|
547
552
|
|
|
@@ -617,7 +622,7 @@ const session = await joinSession({
|
|
|
617
622
|
onPreToolUse: async (input) => {
|
|
618
623
|
if (input.toolName === "bash") {
|
|
619
624
|
const cmd = String(input.toolArgs?.command || "");
|
|
620
|
-
if (/rm\\s+-rf\\s
|
|
625
|
+
if (/rm\\s+-rf\\s+\\/ / i.test(cmd) || /Remove-Item\\s+.*-Recurse/i.test(cmd)) {
|
|
621
626
|
return { permissionDecision: "deny" };
|
|
622
627
|
}
|
|
623
628
|
}
|
|
@@ -665,4 +670,3 @@ session.on("tool.execution_complete", (event) => {
|
|
|
665
670
|
// event.data.success, event.data.toolName, event.data.result
|
|
666
671
|
});
|
|
667
672
|
```
|
|
668
|
-
|
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": "0.
|
|
7
|
+
"version": "0.3.0-preview.0",
|
|
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.
|
|
59
|
+
"@github/copilot": "^1.0.35-0",
|
|
60
60
|
"vscode-jsonrpc": "^8.2.1",
|
|
61
61
|
"zod": "^4.3.6"
|
|
62
62
|
},
|