Skip to content

feat: support opencode v2 (dual V1+V2) - #4

Closed
bacluc-agent wants to merge 4 commits into
mainfrom
issue-390-migrate-opencode-v2
Closed

bacluc-agent wants to merge 4 commits into
mainfrom
issue-390-migrate-opencode-v2

Conversation

@bacluc-agent

@bacluc-agent bacluc-agent commented Oct 14, 2026 •

Copy link
Copy Markdown
Owner

Fixes https://github.com/bacluc-agent/agent-todo/issues/390

Management summary

Adds opencode V2 support while keeping V1 working. src/server.ts now exports the documented V2 Plugin.define({ id, setup }) shape with the existing V1 server plugin spread in, so one module serves both. src/v2.ts registers the command via ctx.command.transform, subscribes to execution events, and re-prompts on failure. isUsageLimitError understands both the V1 ({name,data:{...}}) and V2 ({type,message,status?,response?.body}) error shapes.

Fix: trigger on session.execution.*, not session.idle

Commit ef68d6b subscribed to session.status/session.idle. Those V2 events are never published (SessionEvent.Idle and SessionStatusEvent.Status have no publish sites), so the check was dead code. Commit 48c2ecd subscribes to session.execution.succeeded/.failed/.interrupted — the events packages/core/src/session/execution.ts emits:

  • succeeded → run the command; re-prompt on non-zero exit until maxRetries.
  • failed → skip when event.data.error is a usage-limit error, else run the check.
  • interrupted → skip shutdown (session torn down); run for user, superseded, inactivity.

Usage limits now come from the structured session.execution.failed error payload; the V2 message-scan helper is removed.

Commit cd2a127 uses the singular config keys command/plugin that opencode v2.0.29 honours. The dev opencode.json declares plugin; the README V2 examples use plugin and command (the earlier plural keys were ignored).

The dev opencode.json does not declare command.completion-check-command: activation order is pre → 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

  • No V2 type adaptation needed: ctx.command.transform/editor.add, ctx.event.subscribe({ signal }), ctx.session.prompt({ sessionID, text }), ctx.location.directory, ctx.options all typecheck against @opencode/plugin@2.0.29.
  • @opencode/plugin@2.0.29 added to dependencies next to @opencode-ai/plugin@1.18.33; package-lock.json regenerated.
  • The V1 factory and V1 sessionHitUsageLimit are unchanged.
  • In v2.0.29 the config keys are singular (plugin, command); plural forms are ignored. The dev config therefore carries no command block (adding one would shadow the plugin's own command registration).

Test evidence

Additional test run on the PR head cd2a127 (branch issue-390-migrate-opencode-v2), success:

Action runs

Run What happened Result
https://github.com/bacluc-agent/opencode-completion-check-command/actions/runs/38645603820 manual ci.yaml on ef68d6b (110 tests) success
https://github.com/bacluc-agent/opencode-completion-check-command/actions/runs/38647726089 manual ci.yaml on 48c2ecd (112 tests) success
https://github.com/bacluc-agent/opencode-completion-check-command/actions/runs/38648775966 manual ci.yaml on cd2a127 (PR head, 112 tests) success

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.

renovate Bot and others added 4 commits October 14, 2026 17:28
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.
@bacluc-agent

Copy link
Copy Markdown
Owner Author

Superseded: this repo is owned by BacLuc, so the pull request belongs on upstream, not the fork. Opened BacLuc#99 against upstream main with head bacluc-agent:issue-390-migrate-opencode-v2 (matching the repo convention, e.g. upstream PRs BacLuc#78/BacLuc#82). Closing this fork-targeted PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant