Repository navigation
feat: support opencode v2 (dual V1+V2) - #4
Closed
bacluc-agent wants to merge 4 commits into
Closed
bacluc-agent wants to merge 4 commits into
bacluc-agent wants to merge 4 commits into
Conversation
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
opencode V2 core publishes session.execution.succeeded|failed|interrupted at the end of a turn (packages/core/src/session/execution.ts). session.idle and session.status are only defined in @opencode/schema and are never published at runtime, so triggering on them made the v2 completion check dead code. - Run the check on session.execution.succeeded, .failed and .interrupted, skipping interrupted with reason "shutdown". - Detect the usage limit from session.execution.failed's structured error instead of re-reading the session context. - Drop the redundant user-facing commands.completion-check-command from the dev opencode.json: config commands are registered after external plugins and would override the plugin's own command, losing the command capture. - Document the v2 command override limitation in the README. Tests updated to cover the new trigger and the shutdown/usage-limit cases.
Owner
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes https://github.com/bacluc-agent/agent-todo/issues/390
Management summary
Adds opencode V2 support while keeping V1 working.
src/server.tsnow exports the documented V2Plugin.define({ id, setup })shape with the existing V1serverplugin spread in, so one module serves both.src/v2.tsregisters the command viactx.command.transform, subscribes to execution events, and re-prompts on failure.isUsageLimitErrorunderstands both the V1 ({name,data:{...}}) and V2 ({type,message,status?,response?.body}) error shapes.Fix: trigger on
session.execution.*, notsession.idleCommit
ef68d6bsubscribed tosession.status/session.idle. Those V2 events are never published (SessionEvent.IdleandSessionStatusEvent.Statushave no publish sites), so the check was dead code. Commit48c2ecdsubscribes tosession.execution.succeeded/.failed/.interrupted— the eventspackages/core/src/session/execution.tsemits:succeeded→ run the command; re-prompt on non-zero exit untilmaxRetries.failed→ skip whenevent.data.erroris a usage-limit error, else run the check.interrupted→ skipshutdown(session torn down); run foruser,superseded,inactivity.Usage limits now come from the structured
session.execution.failederror payload; the V2 message-scan helper is removed.Commit
cd2a127uses the singular config keyscommand/pluginthat opencode v2.0.29 honours. The devopencode.jsondeclaresplugin; the README V2 examples usepluginandcommand(the earlier plural keys were ignored).The dev
opencode.jsondoes not declarecommand.completion-check-command: activation order ispre → config packages → post, so a config entry of the same name replaces the plugin's own command and loses the capture that feeds the check. The README documents this.Assumptions
ctx.command.transform/editor.add,ctx.event.subscribe({ signal }),ctx.session.prompt({ sessionID, text }),ctx.location.directory,ctx.optionsall typecheck against@opencode/plugin@2.0.29.@opencode/plugin@2.0.29added todependenciesnext to@opencode-ai/plugin@1.18.33;package-lock.jsonregenerated.sessionHitUsageLimitare unchanged.plugin,command); plural forms are ignored. The dev config therefore carries nocommandblock (adding one would shadow the plugin's own command registration).Test evidence
Additional test run on the PR head
cd2a127(branchissue-390-migrate-opencode-v2), success:src/*.ts,tests/*): https://github.com/bacluc-agent/opencode-completion-check-command/actions/runs/38648775966/job/116142128600#step:5tests/v2.test.ts,tests/plugin.test.ts; 112 passed): https://github.com/bacluc-agent/opencode-completion-check-command/actions/runs/38648775966/job/116142128600#step:6opencode.json,README.md): https://github.com/bacluc-agent/opencode-completion-check-command/actions/runs/38648775966/job/116142128600#step:7Action runs
ci.yamlonef68d6b(110 tests)ci.yamlon48c2ecd(112 tests)ci.yamloncd2a127(PR head, 112 tests)No action run exercises the original wrong-event bug: no opencode V2 server runs here, so the trigger change is covered by
tests/v2.test.ts.