Skip to content

feat!: port to the OpenCode V2 plugin API - #25

Open
dldkhy wants to merge 1 commit into
renjfk:mainfrom
dldkhy:feat/opencode-v2
Open

dldkhy wants to merge 1 commit into
renjfk:mainfrom
dldkhy:feat/opencode-v2

Conversation

@dldkhy

@dldkhy dldkhy commented Oct 12, 2026

Copy link
Copy Markdown

Summary

Ports the plugin to the OpenCode V2 CLI plugin API. V2 rejects V1 plugin modules with Invalid V2 TUI plugin module (see #24), so ctrl+r, the /stt-* commands, and TTS all disappear on V2.

This is a breaking change: after this PR the plugin requires OpenCode V2 (opencode-v2 2.0.x) and no longer runs on OpenCode V1. Happy to add a dual V1/V2 entrypoint if you prefer to keep V1 working while users migrate.

Why the old implementation cannot load on V2

V2's loader requires the default export to carry a non-empty id and a setup function (opencode-v2 2.0.27 source: packages/tui/src/plugin/context.tsx). The V1 shape — export default { id, tui(api, options) } with api.kv, api.command.register, api.ui.DialogSelect, api.event.on — is rejected outright. V1 plugin code does not run on V2; the API must be ported (migration guide).

Changes

  • Entrypoint: Plugin.define({ id, setup(context) }) from @opencode/plugin/tui (index.js + lib/plugin.js).
  • Added a root tui.js. V2 resolves the TUI entry of a local path plugin by looking for a tui file (tui.ts/tui.tsx/tui.js); package exports only apply to package-name targets. Without it opencode plugin list silently reports the plugin as unsupported.
  • Commands/keybinds: context.keymap.layer(...) with stable IDs (opencode-voice.record, ...) and slash names unchanged (/stt-record, ...).
  • State: api.kv → context.storage (lib/kv.js adapter).
  • Dialogs: api.ui.DialogSelect → promise-based context.ui.dialog.select.
  • Events: api.event.on → context.data.on; question.asked → form.created (V2 forms).
  • Messages: api.state.session.messages / client.session.message → context.data.session.message.
  • STT delivery: client.tui.appendPrompt does not exist on V2 and the composer is not exposed to plugins yet (#51209, #51392), so transcriptions are sent with client.session.prompt:
    • submitOnStop: true → send immediately (unchanged UX).
    • submitOnStop: false (default) → prefilled edit dialog, Enter sends, Esc cancels.
  • Keybind defaults: ctrl+r record (unchanged), ctrl+y cancel, <leader>v speak, <leader>o TTS toggle; /stt-submit and /tts-stop remain command-only to avoid shadowing built-ins (<leader>r = redo, <leader>s = status, escape = interrupt). All overridable via plugin options.
  • Logging now goes to OPENCODE_VOICE_LOG (the V1 client.app.log API no longer exists); README updated for cli.json.

Testing

  • npm run check (oxlint + oxfmt) clean.
  • npm test — all green, including new V2 port tests (test/v2-smoke.test.js): definition shape, all ten commands, storage wiring, and the TTS session.status → session.idle path. The module-shape check skips when @opencode/plugin/tui is not installed (CI), every other test runs everywhere.
  • Manually verified on opencode-v2 2.0.27: opencode plugin list discovers the local plugin and the TUI loads it (13 plugins, no reconciliation errors); ctrl+r records/transcribes/submits; TTS speaks on idle.

Refs #24.

V2 rewrites the plugin API and rejects V1 modules with "Invalid V2 TUI
plugin module", which disabled every command after upgrading.

- Entrypoint: Plugin.define({ id, setup }) via lib/plugin.js; index.js and
  the new root tui.js cover package and local-path loading
- Commands/keybinds via context.keymap.layer, keeping slash names
- api.kv -> context.storage (lib/kv.js), DialogSelect -> ui.dialog.select
- Events/state: context.data.on, context.data.session.message
- STT delivery: client.session.prompt with submitOnStop and an edit dialog
  fallback (the V2 composer is not exposed to plugins yet)
- question.asked -> form.created; logging via OPENCODE_VOICE_LOG

BREAKING CHANGE: requires OpenCode V2 (opencode-v2 2.0.x). V1 is no longer
supported.

Refs renjfk#24
@crixue

crixue commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Hi @renjfk This is a important upgrade for this plugin while opencode version upgrade. So would u take some time to review and merge it?

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.

2 participants