Migrate Copilot CLI integration #3529
Conversation
There was a problem hiding this comment.
Pull request overview
Migrates the Copilot CLI VS Code integration into this extension by introducing an in-proc MCP-over-HTTP server, VS Code-facing MCP tools (diff/diagnostics/selection/notifications), and supporting commands + lockfile plumbing so the external CLI can discover/connect.
Changes:
- Add MCP tool implementations (open/close diff, get selection/diagnostics/VS Code info, show notification) plus push notifications for selection/diagnostics changes.
- Introduce in-proc HTTP server over unix socket / named pipe, plus lockfile creation/cleanup for discovery.
- Add VS Code commands/keybindings/menu contributions for “Add File Reference” and diff accept/reject UI.
Reviewed changes
Copilot reviewed 35 out of 36 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| src/extension/agents/copilotcli/vscode-node/tools/utils.ts | Adds helper for MCP text results. |
| src/extension/agents/copilotcli/vscode-node/tools/showNotification.ts | MCP tool to display VS Code notifications. |
| src/extension/agents/copilotcli/vscode-node/tools/push/selectionChanged.ts | Push notification broadcaster for editor selection changes. |
| src/extension/agents/copilotcli/vscode-node/tools/push/diagnosticsChanged.ts | Push notification broadcaster for diagnostics changes. |
| src/extension/agents/copilotcli/vscode-node/tools/push/index.ts | Re-exports push notification registration helpers. |
| src/extension/agents/copilotcli/vscode-node/tools/openDiff.ts | MCP tool to open and manage a VS Code diff UI. |
| src/extension/agents/copilotcli/vscode-node/tools/closeDiff.ts | MCP tool to close/reject an active diff by tab name. |
| src/extension/agents/copilotcli/vscode-node/tools/getVscodeInfo.ts | MCP tool exposing VS Code environment metadata. |
| src/extension/agents/copilotcli/vscode-node/tools/getSelection.ts | MCP tool + cache for current/latest selection info. |
| src/extension/agents/copilotcli/vscode-node/tools/getDiagnostics.ts | MCP tool returning VS Code diagnostics. |
| src/extension/agents/copilotcli/vscode-node/tools/index.ts | Central registration for all Copilot CLI MCP tools. |
| src/extension/agents/copilotcli/vscode-node/readonlyContentProvider.ts | Virtual readonly document provider for diff URIs. |
| src/extension/agents/copilotcli/vscode-node/diffState.ts | Tracks active diffs and context key state for UI. |
| src/extension/agents/copilotcli/vscode-node/inProcHttpServer.ts | Implements local MCP HTTP server over socket/pipe with auth nonce. |
| src/extension/agents/copilotcli/vscode-node/cliHelpers.ts | Determines state/lockfile directory for CLI integration. |
| src/extension/agents/copilotcli/vscode-node/lockFile.ts | Creates/updates/removes lockfiles and cleans stale ones. |
| src/extension/agents/copilotcli/vscode-node/commands/addFileReference.ts | VS Code command to push a file (and optional selection) reference to the CLI. |
| src/extension/agents/copilotcli/vscode-node/commands/diffCommands.ts | Adds accept/reject commands wired to active diff state. |
| src/extension/agents/copilotcli/vscode-node/commands/index.ts | Re-exports command registration + constants. |
| src/extension/agents/copilotcli/vscode-node/contribution.ts | Wires everything together via extension contribution + DI logger. |
| src/extension/agents/copilotcli/vscode-node/test/testHelpers.ts | Shared unit test helpers/mocks for MCP server + VS Code objects. |
| src/extension/agents/copilotcli/vscode-node/test/showNotification.spec.ts | Unit tests for show_notification tool. |
| src/extension/agents/copilotcli/vscode-node/test/getVscodeInfo.spec.ts | Unit tests for get_vscode_info tool. |
| src/extension/agents/copilotcli/vscode-node/test/getSelection.spec.ts | Unit tests for selection info + get_selection tool. |
| src/extension/agents/copilotcli/vscode-node/test/getDiagnostics.spec.ts | Unit tests for get_diagnostics tool. |
| src/extension/agents/copilotcli/vscode-node/test/selectionChanged.spec.ts | Unit tests for selection_changed push notifications. |
| src/extension/agents/copilotcli/vscode-node/test/diagnosticsChanged.spec.ts | Unit tests for diagnostics_changed push notifications. |
| src/extension/agents/copilotcli/vscode-node/test/readonlyContentProvider.spec.ts | Unit tests for readonly content provider. |
| src/extension/agents/copilotcli/vscode-node/test/openDiff.spec.ts | Unit tests for open_diff tool behavior. |
| src/extension/agents/copilotcli/vscode-node/test/closeDiff.spec.ts | Unit tests for close_diff tool behavior. |
| src/extension/agents/copilotcli/vscode-node/test/diffState.spec.ts | Unit tests for diff state tracking. |
| src/extension/agents/copilotcli/vscode-node/test/diffCommands.spec.ts | Unit tests for accept/reject commands. |
| src/extension/agents/copilotcli/vscode-node/test/addFileReference.spec.ts | Unit tests for add file reference command. |
| src/extension/agents/copilotcli/vscode-node/test/lockFile.spec.ts | Unit tests for lockfile lifecycle and stale cleanup. |
| package.json | Adds commands/menus/keybinding and new dependencies (express, MCP SDK, express types). |
| package-lock.json | Locks transitive deps for express + MCP SDK additions. |
src/extension/agents/copilotcli/vscode-node/tools/push/selectionChanged.ts
Outdated
Show resolved
Hide resolved
src/extension/agents/copilotcli/vscode-node/tools/push/diagnosticsChanged.ts
Outdated
Show resolved
Hide resolved
src/extension/agents/copilotcli/vscode-node/tools/showNotification.ts
Outdated
Show resolved
Hide resolved
src/extension/agents/copilotcli/vscode-node/test/closeDiff.spec.ts
Outdated
Show resolved
Hide resolved
src/extension/agents/copilotcli/vscode-node/readonlyContentProvider.ts
Outdated
Show resolved
Hide resolved
…debug information
… and update result parsing
| const schema = { | ||
| tab_name: z.string().describe('The tab name of the diff to close (must match the tab_name used when opening the diff)'), | ||
| }; | ||
| server.tool( |
There was a problem hiding this comment.
This is marked as deprecated.
Do we still want to use this and not an alternative?
src/extension/agents/copilotcli/vscode-node/tools/push/selectionChanged.ts
Outdated
Show resolved
Hide resolved
src/extension/agents/copilotcli/vscode-node/commands/addFileReference.ts
Outdated
Show resolved
Hide resolved
| * Cleans up stale lockfiles where the associated process is no longer running. | ||
| * Returns the number of lockfiles cleaned up. | ||
| */ | ||
| export function cleanupStaleLockFiles(logger: ILogger): number { |
There was a problem hiding this comment.
This would block loading the extension until all of this I/O has completed.
We try to avoid sync I/O.
Can we try to do this another way, I haven't read the code to figure out what we're doing here.
| } | ||
| } | ||
|
|
||
| export async function createLockFile(serverUri: vscode.Uri, headers: Record<string, string>, logger: ILogger): Promise<LockFileHandle> { |
There was a problem hiding this comment.
Again 3 sync I/O operations, i guess this cannot be avoided hence the design.
But would like to double check whether using async code works or not, if we can do it async, then please do
as this can block other extensions as well as block the chat extension, yes its small, but we try to avoid any sync I/O.
…nge notifications
…CopilotCLIContrib
Started out as copy and paste job to move code over from https://github.com/github/vscode-copilot-cli
Then I converted our code over to your DI patterns.
Followed conventions in CONTRIBUTING.md as best I could :)