@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/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
- tools: [ /* ... */ ],
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 | Fires When | Can Modify |
151
- |------|-----------|------------|
152
- | `onUserPromptSubmitted` | User sends a message | The prompt text, add context |
153
- | `onPreToolUse` | Before a tool executes | Tool args, permission decision, add context |
154
- | `onPostToolUse` | After a tool executes | Tool result, add context |
155
- | `onSessionStart` | Session starts or resumes | Add context, modify config |
156
- | `onSessionEnd` | Session ends | Cleanup actions, summary |
157
- | `onErrorOccurred` | An error occurs | Error handling strategy (retry/skip/abort) |
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 | Description | Key Data Fields |
404
- |-----------|-------------|-----------------|
405
- | `assistant.message` | Agent's final response | `content`, `messageId`, `toolRequests` |
406
- | `assistant.streaming_delta` | Token-by-token streaming (ephemeral) | `totalResponseSizeBytes` |
407
- | `tool.execution_start` | A tool is about to run | `toolCallId`, `toolName`, `arguments` |
408
- | `tool.execution_complete` | A tool finished running | `toolCallId`, `toolName`, `success`, `result`, `error` |
409
- | `user.message` | User sent a message | `content`, `attachments`, `source` |
410
- | `session.idle` | Session finished processing a turn | `backgroundTasks` |
411
- | `session.error` | An error occurred | `errorType`, `message`, `stack` |
412
- | `permission.requested` | Agent needs permission (shell, file write, etc.) | `requestId`, `permissionRequest.kind` |
413
- | `session.shutdown` | Session is ending | `shutdownType`, `totalPremiumRequests`, `codeChanges` |
414
- | `assistant.turn_start` | Agent begins a new thinking/response cycle | `turnId` |
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 ((event.data.toolName === "edit" || event.data.toolName === "create")
439
- && String(event.data.arguments?.path || "").endsWith("plan.md")) {
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+\\//i.test(cmd) || /Remove-Item\\s+.*-Recurse/i.test(cmd)) {
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.2.2",
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.21",
59
+ "@github/copilot": "^1.0.35-0",
60
60
  "vscode-jsonrpc": "^8.2.1",
61
61
  "zod": "^4.3.6"
62
62
  },