Repository navigation
Conversation
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
There was a problem hiding this comment.
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:
- 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-writtentypes.ts(~450 lines) andclient.tscopy those generated types and request shapes, and they will drift from the server. The copy of discovery and startup also leaves out whatensurehandles: 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/clientinstead of a parallel copy (see inline comments). - The new tests are never run by the package.
compile-tests(tsc -p .) now compiles onlysrc/, andvscode-testruns mocha tests fromout/test, while these tests usenode:test. Nothing referencestsconfig.test.json. Please wire up a test script that actually runs them, and trimclient.integration.test.ts(211 lines) to the core cases once the client comes from the shared package. - Nothing uses this code yet.
extension.tsdoesn'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,autoStartServerand others) are not declared inpackage.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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
| readonly description?: string; | ||
| } | ||
|
|
||
| export class OpenCodeClient { |
There was a problem hiding this comment.
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.
| // "noUnusedParameters": true, /* Report errors on unused parameters. */ | ||
| } | ||
| }, | ||
| "include": ["src/**/*.ts"] |
There was a problem hiding this comment.
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/.
Issue for this PR
Part of #11176
Type of change
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:SseParserandparseOpenCodeEventfor chunked Server-Sent Events.src/serviceDiscovery.ts: Discovers localservice.jsonregistrations, validates PIDs, spawns the background service inautomode, and builds Basic Auth headers.src/client.ts:OpenCodeClientfor session, model, agent, permission, form, diff, and SSE event endpoints.How did you verify your code works?
Ran
bun run check-types,eslint, andbun test test/sse.test.ts test/serviceDiscovery.test.ts test/client.integration.test.tsinsdks/vscode/(8 pass, 0 fail against a realhttp.createServerwith Basic Auth and workspace directory headers).Screenshots / recordings
N/A (no UI changes in this PR).
Checklist
Added by the opencode bot (AI-generated).
Related: #11176