Repository navigation
Support OpenCode V1 and V2 from one plugin export - #9016
SwarmStorm wants to merge 2 commits into
Conversation
V2 calls setup() from Plugin.define. V1 (1.18.29+) keeps calling server() and the TUI tui() function. The existing V1 pipeline stays in place and is projected onto V2 domains.
|
All contributors have signed the CLA. Thank you! ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
The dual export loaded, but V2 messages, events, and session calls did not match the V1 pipeline. Translate those shapes, fill the client facade, and keep todos, parents, toasts, compaction, the sidebar, and the CLI working on V2.
|
Follow-up on this branch: the first patch made one export load on OpenCode 1 and 2. Using it against OpenCode 2.0.16 showed the V1 pipeline still receiving V2 shapes. This commit translates chat messages and events into the V1 info/parts and properties shapes, and fills the client methods the tools call: agents, providers, models, skills, config, and session create, prompt, list, status, children, and todos. Parent links are stored by the adapter because V2 create has no parentID. Todos and toasts are stored by the adapter because OpenCode 2 has no todo API and the server context has no toast. Manual compaction asks to continue once on the next idle; automatic compaction does not send a second prompt. The TUI claims the sidebar slot, the CLI uses the V2 session API when the server is V2, and an OpenChamber extension publishes toasts and incomplete todos. On an isolated OpenCode 2.0.16 server, the plugin loaded, a prompt completed, and session_list returned a session that existed before the plugin loaded. The log had none of the previous failures: v2 hook failed, app.agents is not a function, or client has no equivalent. |
|
What is the set of things to do, for making v1 tools to become v2 compatible? Cus a lot of other OpenCode context management tools need migration |
Fork-Patch: v2-support
Fork-Patch: v2-support
|
I update this to latest dev here: It works well with opencode v2. |
|
Thanks for this work @SwarmStorm. A heads-up on direction: we're consolidating OpenCode V2 support on one additive dual-host shape (a separate This PR explores the same single-export, dual-host direction, so you'd be very welcome to review the slices or co-author one. Where your work is reused, it will be credited in the changelog. I'm leaving this PR open for now; once the first slice lands we'll compare what this covers and close it with a pointer if it's fully covered. |
|
Bug report + fix for this branch's V2 hook bridge: SwarmStorm#1.
The PR maps each view back to the message it came from ( |
Fork-Patch: v2-support
fork-sync rebuilt main on the head of upstream PR code-yeongyu#9016 while it was open, which pinned the fork to the upstream commit that PR was based on. It now rebuilds on upstream dev; the PR's commits carry the Fork-Patch trailer and travel as patches. The sync also runs the prompt-route and Bun runtime audits. Upstream workflows added since the previous base are dropped, as the sync itself does. Fork-Patch: v2-support
|
The adapter as written removes user-registered namespaced MCP tools matching V1 false rules (including The proposed guard uses native Since the V2 adapter is not on |
|
@SwarmStorm I checked your head I prepared a rebased copy in my fork, preserving your two commits, authorship and messages. Cherry-picks, in order: Verification: export/V2-host/V2-CLI tests 16 pass, 0 fail, and root typecheck passes. The additional TUI/state/SQLite group has two Windows I know the additive dual-host slices in #9389 are the intended direction. Please use the branch/cherry-picks if useful; happy to help adapt the rebase to those slices or keep the #10237 registry follow-up separate. |
Fork-Patch: v2-support
fork-sync rebuilt main on the head of upstream PR code-yeongyu#9016 while it was open, which pinned the fork to the upstream commit that PR was based on. It now rebuilds on upstream dev; the PR's commits carry the Fork-Patch trailer and travel as patches. The sync also runs the prompt-route and Bun runtime audits. Upstream workflows added since the previous base are dropped, as the sync itself does. Fork-Patch: v2-support
Fork-Patch: v2-support
fork-sync rebuilt main on the head of upstream PR code-yeongyu#9016 while it was open, which pinned the fork to the upstream commit that PR was based on. It now rebuilds on upstream dev; the PR's commits carry the Fork-Patch trailer and travel as patches. The sync also runs the prompt-route and Bun runtime audits. Upstream workflows added since the previous base are dropped, as the sync itself does. Fork-Patch: v2-support
Fork-Patch: v2-support
fork-sync rebuilt main on the head of upstream PR code-yeongyu#9016 while it was open, which pinned the fork to the upstream commit that PR was based on. It now rebuilds on upstream dev; the PR's commits carry the Fork-Patch trailer and travel as patches. The sync also runs the prompt-route and Bun runtime audits. Upstream workflows added since the previous base are dropped, as the sync itself does. Fork-Patch: v2-support
Fork-Patch: v2-support
fork-sync rebuilt main on the head of upstream PR code-yeongyu#9016 while it was open, which pinned the fork to the upstream commit that PR was based on. It now rebuilds on upstream dev; the PR's commits carry the Fork-Patch trailer and travel as patches. The sync also runs the prompt-route and Bun runtime audits. Upstream workflows added since the previous base are dropped, as the sync itself does. Fork-Patch: v2-support
Fork-Patch: v2-support
fork-sync rebuilt main on the head of upstream PR code-yeongyu#9016 while it was open, which pinned the fork to the upstream commit that PR was based on. It now rebuilds on upstream dev; the PR's commits carry the Fork-Patch trailer and travel as patches. The sync also runs the prompt-route and Bun runtime audits. Upstream workflows added since the previous base are dropped, as the sync itself does. Fork-Patch: v2-support
Fork-Patch: v2-support
fork-sync rebuilt main on the head of upstream PR code-yeongyu#9016 while it was open, which pinned the fork to the upstream commit that PR was based on. It now rebuilds on upstream dev; the PR's commits carry the Fork-Patch trailer and travel as patches. The sync also runs the prompt-route and Bun runtime audits. Upstream workflows added since the previous base are dropped, as the sync itself does. Fork-Patch: v2-support
Fork-Patch: v2-support
fork-sync rebuilt main on the head of upstream PR code-yeongyu#9016 while it was open, which pinned the fork to the upstream commit that PR was based on. It now rebuilds on upstream dev; the PR's commits carry the Fork-Patch trailer and travel as patches. The sync also runs the prompt-route and Bun runtime audits. Upstream workflows added since the previous base are dropped, as the sync itself does. Fork-Patch: v2-support


Summary
setupfromPlugin.definein@opencode/plugin. This package still exported the V1{ id, server }shape, so V2 hosts rejected it withMissing key at ["default"]["setup"].setup(). OpenCode 1.18.29 and newer keep callingserver(), and the TUI entry keepstui().setupruns the existing V1 pipeline, then projects that config onto V2 tools, commands, MCP, skills, and providers. Agents are written as markdown, because the V2 agent editor can update and remove agents but cannot add one.Changes
Plugin.define({ id, setup })and keepserveron the same object. TUI entry does the same and keepstui.packages/omo-opencode/src/v2/is the host. A context facade feeds the V1 startup path. A hook bridge forwards V2 events into the existing handlers. A projection step registers tools, commands, MCP, skills, and providers, and writes agent markdown under the OpenCode agents directory.index.jsre-exports the built plugin so a configured plugin directory loads on OpenCode 2.0.16. That release drops a configured path that points at a file.@opencode/plugin2.0.16 is a dependency of the root package andpackages/omo-opencode. The index and TUI bundles treat it as external.QA & Evidence
bun teston the export-shape test, the V2 host tests, and the TUI tests, thenbun run --cwd packages/omo-opencode typecheck. Separately, OpenCode 2.0.16run --standalone --format jsonin a temporaryHOMEandXDG_*sandbox, with this package configured as a local plugin directory. The session used agentoh-my-openagent/Sisyphus - ultraworkerand was asked to callsession_listonce.Observed result: 10 pass, 0 fail, 35 expect() calls. Typecheck exited 0. The server log recorded
loading pluginwith entrypointindex.jsand did not record a missing-setuperror. MCP servers connected:lsp(9 tools),context7(2),websearch(1),grep_app(1). The tool result containedNo sessions found.Agent markdown was written for theoh-my-openagentagents, including Sisyphus and oracle.Artifact:
.omo/evidence/20260927-opencode-v2-load/unit.txtandload.txt(local only, not in the diff).Why sufficient: The unit tests pin the dual export, and the OpenCode 2.0.16 process shows the package loading, an OMO agent being selected, and
session_listrunning.Risks & Residuals
experimental.compaction.autocontinuehas no V2 hook. It stays off, and startup logs that.bun testandbun run test:codexwere not re-run. Those trees are outside this diff. Accepted.Automated Checks
bun run --cwd packages/omo-opencode typecheck bun test packages/omo-opencode/src/index.export-shape.test.ts packages/omo-opencode/src/v2/host.test.ts packages/omo-opencode/src/tui.test.tsRelated Issues
Fixes #8485
Summary by cubic
Makes the
oh-my-openagentplugin load in both OpenCode V1 and V2 from a single export. OpenCode V2 hosts rejected the previous{ id, server }export shape with a missingsetuperror; the default export now also carriesPlugin.define({ id, setup })so V2 callssetup()while V1 keeps callingserver()andtui().packages/omo-opencode/src/v2/host that runs the existing V1 pipeline through a context facade, translates V2 messages and events into V1 shapes, and projects tools, commands, MCP, skills, and providers into V2.runcommand can drive V2 through its client API.@opencode/plugin2.0.16 as a dependency of the rootpackage.jsonandpackages/omo-opencode, a rootindex.jsthat re-exports the built plugin, and anopenchamber/host with v2 SDK native-skills support.experimental.compaction.autocontinuehook; those calls are logged and the setting stays off.Fixes #8485.
Written for commit 502a4f0. Summary will update on new commits.