Repository navigation
Add OpenCode v2 support via ./server adapter entrypoint - #44
roboalchemist wants to merge 1 commit into
Conversation
OpenCode 2.x loads plugins through the v2 plugin API ({id, setup(context)})
and prefers the ./server export of an npm package (issue Mte90#33).
This adds a v2 entrypoint (src/server.ts) that adapts the existing v1
recovery engine to the v2 API:
- builds a v1-shaped client bridge on top of the v2 plugin context
- invokes the unchanged v1 plugin (src/index.ts) with it
- re-registers the returned v1 hooks (event, config, tool, chat.message,
tool.execute.before/after, command.execute.before) into the v2 domain API
- translates v2 bus events into the v1 event shape
The recovery engine is untouched, so v1 and v2 hosts automatically run the
same logic and stay in sync with future v1 changes. OpenCode 1.x keeps
loading main (dist/index.js); 2.x loads ./server. Also adds zod (used by
the adapter) to dependencies and builds both entries in the build script.
|
what do you think @famewolf? |
|
@Mte90 My answer: #37 is the one to land; #44 is a clever stopgap that silently removes features instead of failing loudly. What worries me about #44 as the long-term answer:
What #44 gets right: it's ~250 lines in one new file, reviewable in minutes, v1 stays byte-identical, and one engine means future v1 fixes reach v2 for free. That's a legitimate reason to take it as an interim #33 fix — the two PRs only overlap in But #37 is where this should land: it's the build that has been running v2 on my machine daily (the PR head is the deployed source of truth), 822 tests pass / 0 fail, and you already OK'd its scope on 10-02 ("we can proceed"). Its real cost is the review size, and the dual-maintenance concern is fair — which is why For context on pace: I'm submitting commits to the branch daily — shoring up areas the current v2 implementation was found to be lacking as they surface, and some of those fixes turned out to be needed by v1 as well. Your call, but that's my recommendation: #37 as the destination. If you want #33 closed this week, taking #44 as an interim — with the stubbed surfaces noted in the README — is a reasonable path while #37 stays under review. |
Fixes #33 (OpenCode 2.x fails to load — V1 entrypoint, no V2 setup(ctx)).
What
OpenCode 2.x loads plugins through the v2 plugin API (
{ id, setup(context) }) and prefers a package's./serverexport, while this plugin ships only the v1Plugin(ctx, options)entrypoint — so 2.x hosts reject it.This PR adds a v2 entrypoint (
src/server.ts) that adapts the existing v1 engine to the v2 API:clientbridge on top of the v2 plugin contextsrc/index.ts) with itevent,config,tool,chat.message,tool.execute.before/after,command.execute.before) into the v2 domain APIhandleEvent's{type, properties: {sessionID, ...}})The recovery engine is untouched — v1 and v2 hosts run the same logic, so the two stay automatically in sync with future v1 changes. OpenCode 1.x keeps loading
main; 2.x loads./server. The config in the README works unchanged on both.Why an adapter (vs. #37)
#37 ports v1's behavior into a parallel
src/v2tree with its own test suite — a large surface that must be kept in step with v1 over time. This adapter is the alternative: one engine, thin bridge (~250 lines, one new file + package.json/README wiring), no duplicated recovery logic to maintain. Happy to close this in favor of #37 if the full port is preferred — but this is a much smaller diff to review and can ship immediately.package.json changes
exports:.→./dist/index.js(unchanged for 1.x), new./server→./src/server.ts(OpenCode 2 loads TS entrypoints directly, same pattern as other v2 plugins)files: shipsrc/server.tszod(used by the adapter for tool-schema conversion)build: builds both entriesTesting
tsc --noEmitpasses (no changes tosrc/index.ts; v1 behavior byte-identical)failed to load pluginerrors; setup() runs the engine construction, tool registration (task_completeviacontext.tool.transform), and prompt/tool/command hook registration without errors.→dist/index.jsexactly as before