Skip to content

feat: add OpenCode 2 (V2) plugin entrypoint - #16

Closed
Majidalee1 wants to merge 2 commits into
brent-weatherall:mainfrom
Majidalee1:pr2-feat/v2-entrypoint
Closed

feat: add OpenCode 2 (V2) plugin entrypoint#16
Majidalee1 wants to merge 2 commits into
brent-weatherall:mainfrom
Majidalee1:pr2-feat/v2-entrypoint

Conversation

@Majidalee1

@Majidalee1 Majidalee1 commented Aug 7, 2026

Copy link
Copy Markdown

Summary

Adds a native OpenCode 2 (V2) plugin entrypoint so the Command Code provider works on the opencode2 CLI.

Stacked PRs: this is PR 2 of 3. Please review/merge #15 (refactor: shared model utilities) first — this branch is based on it. It targets main here because the intermediate branch lives on a fork and cannot be used as a base ref in this repo; the diff is scoped to just the V2 entrypoint.

Problem

OpenCode 2 loads plugins from a module's default export as { id, setup } and requires provider/model registration through the catalog transform API. The existing plugin.ts default export is a factory returning { config, auth } (the legacy V1 contract), which fails to load in V2:

SchemaError: Expected object, got async function commandcodePlugin()

The provider core itself (index.ts, src/model.ts) already implements the AI SDK LanguageModelV3 interface, so it is usable in V2 via the aisdk: package contract — it only needs a V2 plugin to register the provider and models.

Changes

  • v2.ts (new): V2 plugin default export ({ id, setup }) that registers the commandcode provider (aisdk:commandcode-go-opencode-provider, default baseURL) and all models from models.json via ctx.catalog.transform.
  • package.json: expose ./v2 export; include v2.ts in published files; bump to 0.5.0.
  • tsconfig.json: include v2.ts.
  • tests/unit/v2.test.ts (new): verifies provider registration, settings override behavior, and that every model from models.json is registered with the correct shape.

Usage

{
  "plugins": ["commandcode-go-opencode-provider/v2"]
}

No provider block or hand-written model list is required.

Verification

  • bun run typecheck passes
  • bun test tests/unit/ passes (90 tests, 0 failures)
  • Loaded the actual v2.ts into a running opencode2 instance and confirmed the provider plus all 21 models register (checked via /api/provider and /api/model)

Introduce src/models.ts so the V1 plugin and the upcoming V2 entrypoint
share one source of truth for loading models.json and converting entries
into their runtime-specific shapes.

- loadModels(): reads models.json once, typed as ModelEntry[]
- toConfigKey(): stable short key derivation (preserves prior behavior)
- toV1ModelConfig(): legacy { config } hook model shape
- toV2ModelDraft()/toV2ModelMap(): OpenCode V2 catalog model drafts

plugin.ts now delegates to the shared module; behavior is unchanged
and covered by tests.
OpenCode 2 loads plugins from a module's default export as
{ id, setup }, and requires provider/model registration through the
catalog transform API. The legacy plugin.ts factory (V1 only) fails to
load in V2 with a SchemaError.

Add a new ./v2 entrypoint that exports { id, setup } and registers the
commandcode provider plus all models from models.json via
ctx.catalog.transform. Users can now opt in with:

  plugins: ["commandcode-go-opencode-provider/v2"]

No provider block or hand-written model list is needed.

- v2.ts: V2 plugin default export ({ id, setup })
- package.json: expose ./v2, include v2.ts in files, bump to 0.5.0
- tsconfig.json: include v2.ts
- tests/unit/v2.test.ts: coverage for provider/model registration
@Majidalee1

Copy link
Copy Markdown
Author

Closing this PR. PR #15 now has all the changes from #15, #16, and #17. GitHub does not allow a fork branch as a PR base in the upstream repo. This made a real 3-PR stack impossible without push access to this repo. See #15 for the combined change: #15

@Majidalee1 Majidalee1 closed this Aug 7, 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