feat: support OpenCode V2 with @opencode-ai/plugin@beta - #1
Open
pascalandr wants to merge 4 commits into
Open
Conversation
- Declare optional peerDependencies for both V1 (@opencode-ai/plugin ^1.15.7) and V2 (@opencode-ai/client 0.0.0-beta-17595 Promise API) so the plugin resolves in either runtime. - Document that the ephemeral HTTP/2 bridge to api2.cursor.sh now runs inside the single shared global daemon (V2) with no per-workspace Bun, private DB or port — same local OpenAI-compatible proxy, same transport. - Note CodeNomad V2 embedded providers already include Cursor quota; external Cursor OAuth via this plugin remains supported side-by-side.
Remove the optional peer dependencies and daemon compatibility claims because the package still exports the OpenCode V1 hook factory and requires Bun at runtime. Adding the V2 client package cannot adapt that implementation to the V2 plugin contract. Document the supported V1 plugin version and explicitly note that V2 requires a future API port. Verified with npm run build and the full Bun smoke suite.
Add a native V2 server plugin that registers the Cursor provider, live account model catalog, PKCE integration flow, and request hook routing through the existing local proxy. OpenCode owns OAuth credentials while login and refresh trigger best-effort catalog reloads, including Cursor's default auto-routing alias and exact variant selection headers. Preserve the V1 root entrypoint through the beta package's /v1 compatibility export, publish ./server for V2 discovery, and pin the matching beta plugin runtime with all transitive provider dependencies. Use import.meta.url for packaged bridge paths so both entrypoints import correctly outside Bun's source runtime. Cover catalog transforms, OAuth registration, request rewriting, variant propagation, and proxy cleanup with a focused mocked V2 test. Validated TypeScript build, the complete existing smoke suite, and isolated imports from the packed tarball.
Follow the @opencode-ai/plugin beta dist-tag so the V2 server entrypoint is installed against the currently published plugin contract instead of a hardcoded prerelease. Keep the V1 root export working through a stable-tag npm alias now that the beta package no longer exposes its former V1 compatibility subpath. Regenerate both npm and Bun locks and extend the V2 OAuth test to cover token refresh and catalog reload behavior. Validated with the TypeScript build and no-emit typecheck, the full Bun smoke suite, isolated tarball imports for both entrypoints, and a real opencode2 plugin/catalog/OAuth/proxy lifecycle smoke.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds OpenCode V2 support through the package's
./serverentrypoint while preserving the existing V1 root export.The V2 dependency now follows the published
@opencode-ai/plugin@betadist-tag rather than hardcoding a prerelease. The npm and Bun locks were regenerated from that tag.Implementation
Plugin.define({ id: "opencode.provider.cursor", setup })from./serverfor V2.@opencode-ai/ai/providers/openai-compatibleand the process-local proxysettings.baseURL.cursor/defaultauto-routing, and reloads the catalog after login, refresh, and startup discovery.ctx.integration.transform; callbacks return V2 OAuth credentials for host-owned persistence rather than writingauth.json./v1/chat/completionsthroughctx.session.hook("http.request"), strips the host credential before localhost dispatch, and preserves the selected Cursor model/variant header.import.meta.url, allowing normal Node and Bun imports from an installed tarball.V2 configuration
{ "$schema": "https://opencode.ai/config.json", "plugins": ["@openchamber/opencode-cursor"], "providers": { "cursor": { "name": "Cursor" } } }OpenCode V2 selects the package's
./serverexport. OpenCode V1 continues to use the root export.Discovery fallback
Live account discovery remains the source of truth. If Cursor discovery is temporarily unavailable, the plugin keeps the authorization bootstrap model or the last discovered in-memory catalog until the next login or token refresh; it does not advertise a fabricated static model list.
Validation
npm run buildnpx tsc -p tsconfig.json --noEmitnpm test(focused V2 coverage plus the complete existing proxy smoke suite)npm pack, isolated install, and Node imports of both@openchamber/opencode-cursorand@openchamber/opencode-cursor/serveropencode2server smoke against the current beta: plugin ID loaded, Cursor provider/bootstrap catalog present, OAuth attempt started and cancelled, proxy catalog served, and disabling the plugin closed the proxy listenerThe deterministic V2 test covers OAuth authorization and refresh, provider/model transforms, exact variant request rewriting, authorization stripping, and cleanup. The smoke did not complete a real Cursor browser login or send an authenticated Cursor model request, so live account discovery and upstream inference remain credential-dependent validation.