Skip to content

Add OpenCode 2 plugin entrypoint (dual V1+V2 export) - #6

Open
vitaly74 wants to merge 1 commit into
doomsday616:mainfrom
vitaly74:v2-plugin-compat
Open

vitaly74 wants to merge 1 commit into
doomsday616:mainfrom
vitaly74:v2-plugin-compat

Conversation

@vitaly74

Copy link
Copy Markdown

OpenCode 2 rejects the V1 function export (Plugin must export a default definition with an id...), so the plugin never loads there. Verified on 2.0.14: opencode plugin list shows the entry with no id, and the server log repeats the LoadError.

This keeps one default export that both loaders accept:

  • V2 half: { id: 'opencode-github-sync', setup } — registers the opencode_sync tool via ctx.tool.transform (JSON Schema input, { content } result), subscribes to session.idle via ctx.event.subscribe for the optional idle push, and runs the startup pull. No dependency on @opencode/plugin; the context shape is structural.
  • V1 half: unchanged server() hook map (event + tool), kept as a named OpencodeGithubSync export.
  • prunePluginCache now reads the V2 plugins key (string and { package } specs) with fallback to the legacy plugin key.
  • Install docs use plugins in both READMEs.

Verification: npm run check green (lint + typecheck + 104 tests, including new tests/plugin.test.ts covering both halves, idle push, and both config keys). Local V2 live-load confirmed: loading plugin .../dist/plugin with no LoadError and the entry listed with id opencode-github-sync.

V2 rejects the V1 function export, so the default export now carries
{id, setup} for OpenCode 2 plus server() for OpenCode 1. setup registers
the opencode_sync tool via ctx.tool.transform and subscribes to
session.idle via ctx.event.subscribe, mirroring the V1 behavior.

Also teach prunePluginCache the V2 plugins key (string and {package}
specs) while keeping the legacy plugin key, and update the install
docs. Covers both halves and the new pruning paths with tests/plugin.test.ts.
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