feat(v2): add an OpenCode v2 adapter for micode
micode 0.11.0 is a v1 plugin: it exports a named OpenCodeConfigPlugin, returns a v1 hooks object, and mutates the host config directly. v2 requires a default Plugin.define({id, setup}) and exposes no config mutation, so no released version loads on v2 — upstream main is still pinned to the v1 plugin package.
v2-adapter/ is a shim that runs the published plugin unchanged and translates its v1 API surface into v2: agents via ctx.agent.transform, commands and tools via their editors, MCP via ctx.mcp.transform, permissions via a ctx.permission evaluate hook, and the v1 hooks onto ctx.session.hook / ctx.tool.hook / ctx.event.subscribe.
Two v2 gaps shape the design:
-
SessionDomain is a Pick that omits compact and remove, so a plugin cannot request a compaction. micode's Auto-Compact is disarmed by withholding the token counts it triggers on — session.usage.updated carries cumulative session usage, which is not what its per-request ratio expects — and summarize() rejects rather than parking the hook in a two-minute wait. OpenCode's own compaction.auto does the compacting.
-
ctx.session.prompt admits and returns a receipt in v2, where v1 returned the reply synchronously. The client shim waits and re-reads context so spawn_agent and octto's probe agents still receive a reply.
Verified on 2.0.21: no load errors, 26 agents, 4 commands, 41 tools, the context7 MCP server and 6 bridged hooks all present in the live registries, and subagent spawning works end to end with a live model.
npm test runs the real upstream plugin against a stand-in host in both directions: 11 assertions, no server required.
What
Brief description of the change.
Why
What problem does this solve? Link to related issue if applicable.
Checklist
- Tests added or updated
-
bun run checkpasses - Documentation updated (if public API changed)
- CHANGELOG.md updated (if user-facing change)
Summary by cubic
Adds v2-adapter/, a shim that runs the published micode 0.11.0 plugin on OpenCode v2 despite its v1 plugin API, and fixes the bugs that fix exposed.
v2-adapter
- Translates the v1 API surface onto v2 transforms and hooks: agents via
ctx.agent.transform, commands and tools via their editors, MCP viactx.mcp.transform, permissions via actx.permissionhook, and v1 hooks ontoctx.session.hook/ctx.tool.hook/ctx.event.subscribe. - Works around two v2 gaps: no
session.compact/remove(Auto-Compact disarmed by withholding the token counts it triggers on), andctx.session.promptreturning a receipt instead of a reply (client shim waits and re-reads context). - Addresses review findings: re-throws micode's
ConstraintViolationError, resubscribes the event bridge with backoff, seeds agent permissions fromconfig.permissionplussubagent(per-agent denies layer over the base), boundssession.waitwith a 5-minute race, parses features withjsonc-parser, queues log writes on a timer, and readssession.deleted's id from both the 2.0.21 and fallback shapes. - Loads the repo's local
dist/build over the published bundle, so prompt fixes actually reach running agents;local-build.test.jsasserts the resolution order and that the loaded bundle teaches the array-form call.npm testruns the real upstream plugin against a stand-in host (16 assertions, no server).
Related fixes
- Aligns executor, planner, and project-initializer prompts with
spawn_agent's single{ agents: [...] }array schema; batched spawns previously failed validation and spawned nothing. The contract test pins prompts to the schema, verifies one call overlaps all agents concurrently, and asserts every element is complete. - Fixes
mindmodellookup: a manifest-less.mindmodel/no longer loads as null, and matching is now symmetric over a file's path, description, and headings instead of only the description. - Excludes
v2-adapterfrom the root biome/eslint configs (makingbun run checkgreen) and syncs the biome schema URL with the installed CLI.