Skip to content

feat: support OpenCode V2 with @opencode-ai/plugin@beta - #1

Open
pascalandr wants to merge 4 commits into
openchamber:mainfrom
pascalandr:feat/v2-compat
Open

feat: support OpenCode V2 with @opencode-ai/plugin@beta#1
pascalandr wants to merge 4 commits into
openchamber:mainfrom
pascalandr:feat/v2-compat

Conversation

@pascalandr

@pascalandr pascalandr commented Aug 23, 2026

Copy link
Copy Markdown

Summary

Adds OpenCode V2 support through the package's ./server entrypoint while preserving the existing V1 root export.

The V2 dependency now follows the published @opencode-ai/plugin@beta dist-tag rather than hardcoding a prerelease. The npm and Bun locks were regenerated from that tag.

Implementation

  • Default-exports Plugin.define({ id: "opencode.provider.cursor", setup }) from ./server for V2.
  • Starts and reuses the existing Bun HTTP proxy, updates its live model list, and stops it during plugin cleanup.
  • Registers the Cursor provider with @opencode-ai/ai/providers/openai-compatible and the process-local proxy settings.baseURL.
  • Discovers the authenticated account's Cursor models, publishes exact model/variant selection headers, retains cursor/default auto-routing, and reloads the catalog after login, refresh, and startup discovery.
  • Registers Cursor PKCE browser OAuth through ctx.integration.transform; callbacks return V2 OAuth credentials for host-owned persistence rather than writing auth.json.
  • Rewrites Cursor requests to /v1/chat/completions through ctx.session.hook("http.request"), strips the host credential before localhost dispatch, and preserves the selected Cursor model/variant header.
  • Keeps V1 imports on a stable-tag npm alias because the V2 beta package no longer exposes the legacy compatibility subpath.
  • Resolves packaged HTTP/2 bridge files with 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 ./server export. 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 build
  • npx tsc -p tsconfig.json --noEmit
  • npm test (focused V2 coverage plus the complete existing proxy smoke suite)
  • npm pack, isolated install, and Node imports of both @openchamber/opencode-cursor and @openchamber/opencode-cursor/server
  • Real isolated opencode2 server 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 listener

The 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.

- 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.
@pascalandr pascalandr changed the title feat: OpenCode V2 compatibility docs: clarify OpenCode V2 support status Aug 23, 2026
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.
@pascalandr pascalandr changed the title docs: clarify OpenCode V2 support status feat: OpenCode V2 compatibility Aug 23, 2026
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.
@pascalandr pascalandr changed the title feat: OpenCode V2 compatibility feat: support OpenCode V2 with @opencode-ai/plugin@beta Aug 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant