fix(opencode): support OpenCode 2.x via native tools and commands - #1213
fix(opencode): support OpenCode 2.x via native tools and commands#1213SHJordan wants to merge 3 commits into
Conversation
|
🔍 OpenCodeReview found 4 issue(s) in this PR.
|
The single-file plugin (open-code-review.ts) cannot load on OpenCode 2.x:
the 2.x loader requires a default-exported { id, effect | setup } and has
no custom-tool registration API. It also fails on 1.x for most users
because nothing installs the @opencode-ai/plugin dependency the file
imports.
Ship the same ocr_review / ocr_health features as 2.x-native custom
tools plus /ocr-review /ocr-health commands, and document the
@opencode-ai/plugin dependency step for both versions.
34330a3 to
fe7ccb1
Compare
|
Update: addressed the review findings. Fixed — missing output cap in Not applied — Duplication (maintainability/medium x2) — kept self-contained deliberately. Each file under Also fixed the commit author email so the commits link to @SHJordan for the CLA check. |
Replace the tools/+commands/ split with the documented dual plugin form:
default-export { ...Plugin.define({ id, setup }), server }. V2 registers
ocr_review/ocr_health via ctx.tool.transform and /ocr-review//ocr-health
via ctx.command.transform, reusing the same OCR logic as V1. Add
@opencode/plugin beta devDependency and a test for the default export.
|
Revision pushed: replaced the separate |
|
Approach looks right — I checked the V2 docs' "Support V1" section, and V2 reading Blocking
Not keen to defer
Smaller notes (dropped period in the V2 command template, redundant |
|
Smaller notes, none blocking.
|
…ests
- Import @opencode/plugin as types only and export a plain dual object,
so OpenCode 1.x never needs the V2 beta package at runtime (verified
in the built output: only node:*, @opencode-ai/plugin imports remain).
- V2 numeric inputs now require positive integers
({ type: integer, minimum: 1 }), matching the V1 zod schema.
- V2 commands keep the V1 sentence break, skip user-defined names like
the V1 ??= guards, and resolveSessionCwd falls back to the plugin
location when the session lookup fails.
- README: single download block, corrected 30-minute tool timeout,
deduped project section.
- Track package-lock.json (drop the local ignore) so npm ci works.
- Move the V2 stub harness into the test suite (+6 tests, 29 passing).
- Verified live on OpenCode 1.18.30 sandbox: plugin loads with no
errors, single init across sessions, both commands registered once.
|
@Qiyuanqiii @lizhengfeng101 revision pushed addressing everything — walkthrough: Qiyuanqiii (blocking): V1 hard dependency on the V2 package — fixed structurally, not just docs. The V2 API is now Numeric schemas (both): fixed + tested. V2 numerics are now Attachments in V2 commands: kept text-only deliberately, matching the V1 $ARGUMENTS templates; spreading attachments would break 15-min README line: fixed to the effective 30-minute tool default. Lockfile: committed ( AGENTS.md disclosure: added to the PR body (tools used included). 1.x verified live (1.18.30 sandbox): plugin loads clean, exactly one init across sessions, both commands registered once — so no double registration from Harness in test/: done (+6 V2 tests, 29/29 green), covering registration, schema shape, command-collision skip, session-cwd resolution + fallback, and template rendering. Small notes, all applied: sentence break + no double space on empty prompt (tested), |
|
@SHJordan Nice fix. One thing worth confirming: |
The
opencode/README (curl open-code-review.ts into plugins/)is broken in two independent ways:
Missing dependency. The
.tsfile imports@opencode-ai/plugin, but nothing tells users to add that dependencyto their config directory. The server log shows:
failed to load plugin ... Cause([Die(ResolveMessage: Cannot find package '@opencode-ai/plugin' ...)])(referr_ae92f004).V1-only API. The file exports a V1 plugin function, but OpenCode
2.x requires a default-exported
{ id, effect | setup }definition.Server log:
Plugin must export a default definition with an id and an effect or setup function(refserr_01716a41,err_daa504f5).Changes
open-code-review.ts: dual entrypoint perhttps://opencode.ai/v2/docs/build/plugins#support-v1 —
export default { id, setup, server }.V2
setupregistersocr_review/ocr_healthviactx.tool.transformand/ocr-review//ocr-healthviactx.command.transform, reusing the exact V1 OCR logic(arg validation,
ocr review --audience agent --format json,30-min overall timeout, 10 MiB output cap, process-group cleanup).
The V2 API is imported as types only, so OpenCode 1.x never needs
the
@opencode/pluginpackage at runtime (verified in the builtoutput). V2 tool cwd resolves from the session location with
fallback to the plugin location; V2 has no abort signal, so
cancellation there relies on the overall timeout (documented).
V2 numeric inputs require positive integers like V1, and V2
commands skip user-defined names like the V1
??=guards.package.json(+ trackedpackage-lock.json, ~300 locked packages):add
@opencode/pluginbeta devDependency for typechecking the V2code; lockfile committed so
npm ciworks.test/open-code-review.test.mjs: default-export shape test plus aV2 stub-context harness (+6 tests).
README.md: single download block with per-version dependencyinstructions, corrected 30-minute tool timeout.
Verification (OpenCode
v0.0.0-beta-19425+1.18.30,ocr v1.11.8)npm run check: typecheck + 29/29 tests pass; clean-roomnpm ci+ check also green.failed to load pluginentries; V2 harness registers both tools/commands andocr_review {preview: true}returned liveocroutput throughsession-derived cwd.
exactly one init across sessions (no double registration from
default.server+ named export), both commands registered once.ocr llm testpasses, so the health flow has working credentialsbehind it (full
ocr_healthexecute not run here to avoid LLM spend).Suggested test plan for maintainers
~/.config/opencode, follow README 1.x steps, checkocr_review/ocr_healthappear and/ocr-healthsucceeds.AI/LLM disclosure (per AGENTS.md)
This PR was prepared with AI assistance (OpenCode coding agent).
Every line was reviewed by the author, and all behavior claims above
were functionally verified as described (live loads on both versions,
29/29 tests, real
ocrruns for preview paths). No AI attributiontrailers in commits.