Skip to content

feat(vscode): add HTTP+SSE client, SSE parser, and service discovery - #67571

Open
yash-alla wants to merge 1 commit into
anomalyco:devfrom
yash-alla:vscode-client
Open

yash-alla wants to merge 1 commit into
anomalyco:devfrom
yash-alla:vscode-client

Conversation

@yash-alla

@yash-alla yash-alla commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Issue for this PR

Part of #11176

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds the standalone OpenCode V2 HTTP+SSE client layer for the VS Code extension (sdks/vscode):

  • src/types.ts: TypeScript definitions for OpenCode V2 sessions, messages, events, models, permissions, and forms.
  • src/sse.ts: SseParser and parseOpenCodeEvent for chunked Server-Sent Events.
  • src/serviceDiscovery.ts: Discovers local service.json registrations, validates PIDs, spawns the background service in auto mode, and builds Basic Auth headers.
  • src/client.ts: OpenCodeClient for session, model, agent, permission, form, diff, and SSE event endpoints.

How did you verify your code works?

Ran bun run check-types, eslint, and bun test test/sse.test.ts test/serviceDiscovery.test.ts test/client.integration.test.ts in sdks/vscode/ (8 pass, 0 fail against a real http.createServer with Basic Auth and workspace directory headers).

Screenshots / recordings

N/A (no UI changes in this PR).

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Related: #11176

@github-actions github-actions Bot added contributor needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The client works against a real v2 server. I started opencode serve --service from source and pointed the new code at its registration file. Discovery found the server, the session, agent, model, command, form, permission and diff calls I tried all returned the expected data, and the event stream parsed 21 events. The 8 new tests pass with bun test test/ and node --test. Type-check, lint and esbuild pass.

Public API: unchanged. These are internal modules of the extension, nothing imports them yet, and they add no commands or settings.

Concerns:

  1. This reimplements @opencode/client. That package already provides local-service discovery and startup (@opencode/client/service: discover, ensure, headers), a generated typed HTTP client for every route used here, and the SSE event stream. The hand-written types.ts (~450 lines) and client.ts copy those generated types and request shapes, and they will drift from the server. The copy of discovery and startup also leaves out what ensure handles: version compatibility, several windows starting a server at the same time, recovering a server that has stopped responding, terminal handoff on restart, and registration file names per release channel. Please build the extension on @opencode/client instead of a parallel copy (see inline comments).
  2. The new tests are never run by the package. compile-tests (tsc -p .) now compiles only src/, and vscode-test runs mocha tests from out/test, while these tests use node:test. Nothing references tsconfig.test.json. Please wire up a test script that actually runs them, and trim client.integration.test.ts (211 lines) to the core cases once the client comes from the shared package.
  3. Nothing uses this code yet. extension.ts doesn't import it and esbuild doesn't bundle it, so it is dead code until a follow-up PR. The settings it reads (opencode.serverMode, serverUrl, serverPassword, binaryPath, autoStartServer and others) are not declared in package.json. It would help to land the client together with the smallest piece that uses it, and to link a design issue as suggested on #67569.

Related: #11176

readonly spawnService?: (binaryPath: string) => void;
}

export function defaultRegistrationFile(env: NodeJS.ProcessEnv = process.env): string {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This copies fallback(), headers() and the discover/ensure logic from @opencode/client/service, but it only handles service.json. The CLI names the registration file by release channel. For example, a server built from source writes service-local.json, and other channels write service-<channel>.json, so discovery misses those servers. Using Service.discover / Service.ensure from @opencode/client/service would keep the extension in sync with the CLI's discovery logic.

};
}

export function spawnBackgroundService(binaryPath: string): void {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problems with this spawn and poll loop:

  • Two VS Code windows activating at the same time each spawn their own serve --service.
  • There is no version check, so the extension connects to whatever server is registered.
  • A server that has stopped responding is never replaced.
  • A missing binary (ENOENT) is swallowed, so the user waits the full 15s before a generic timeout.

Service.ensure in @opencode/client already handles all of these. Please use it rather than a second implementation.

Comment thread sdks/vscode/src/client.ts
readonly description?: string;
}

export class OpenCodeClient {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class hand-copies routes, request bodies and response shapes that @opencode/client already generates from the server's API definition, e.g. session.prompt, session.list and the /api/event stream. Hand-written routes and types will silently drift as the API changes. With OpenCode.make({ baseUrl, headers: Service.headers(endpoint) }) you get the same calls with typed inputs and outputs, and sse.ts and most of types.ts would no longer be needed.

Comment thread sdks/vscode/tsconfig.json
// "noUnusedParameters": true, /* Report errors on unused parameters. */
}
},
"include": ["src/**/*.ts"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With include limited to src/**/*.ts, the existing compile-tests script (tsc -p . --outDir out) never compiles test/. Nothing references tsconfig.test.json. vscode-test also expects mocha tests in out/test, while these use node:test. As it stands, no script runs these tests. Please add a test script that does, e.g. bun test test/.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant