Skip to content

Add OpenCode 2 beta adapter - #6

Open
shanebishop1 wants to merge 15 commits into
mainfrom
feat/opencode-v2
Open

Add OpenCode 2 beta adapter#6
shanebishop1 wants to merge 15 commits into
mainfrom
feat/opencode-v2

Conversation

@shanebishop1

@shanebishop1 shanebishop1 commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Adds an isolated OpenCode 2 beta package while keeping the existing V1 package and release line unchanged.

What changed

  • Added opencode-command-hooks-v2@0.1.0-beta.0, pinned to @opencode-ai/plugin@0.0.0-next-15853.
  • Added the V2 Promise adapter for tool before/after hooks, synthetic injection, event dedupe, and cleanup.
  • Mapped compatibility and durable execution lifecycle events to the existing session.start and session.idle hooks.
  • Normalized V2 subagent/agent events to the existing task/subagent_type config contract.
  • Refactored shared execution behind host injection/toast ports and passed project directories explicitly through config discovery, agent loading, and shell execution. V1 remains on its existing SDK adapter.
  • Added a one-time diagnostic for unsupported V2 server-plugin toasts and uses resume: false for synthetic messages to avoid unsolicited turns.
  • Added unit, regression, package, and real-host E2E coverage, plus separate V1/V2 build outputs.
  • Added PR CI and a V2 release workflow. Both run the packed package against the pinned OpenCode 2 host.
  • Updated the README and impact report with compatibility, rollout, and rollback details.

Why

OpenCode 2 does not load V1 plugin exports and runs as a long-lived multi-location service. A separate package avoids breaking V1 users, while the shared host-neutral core prevents the adapters from drifting. Resolving each session through the V2 client provides the correct project directory instead of relying on process cwd.

Real-host verification

The E2E installs the packed V2 package and @opencode-ai/cli@0.0.0-next-15853 into a temporary project, starts a private server on an OS-selected port, and polls until plugin activation completes. Temporary HOME/XDG paths and explicit test credentials keep it separate from the normal opencode installation and service. The test passes and confirms opencode-command-hooks.v2 completes setup in the real host.

Verification

  • npm run lint
  • npm run typecheck
  • bun test: 143 passed
  • OPENCODE2_E2E=1 bun test tests/e2e.v2.test.ts: passed twice consecutively
  • bun run build:all
  • V1 and V2 npm pack --dry-run: passed
  • Workflow YAML parsing: passed

OpenCode 2 remains beta. Server plugins still cannot display TUI toasts, and exact CLI/plugin version pins remain required.

Issue #5: active subagent waits

  • Added opt-in excludeSubagentWait support for session.idle hooks in both adapters.
  • V1 tracks task calls; V2 normalizes native subagent calls to the same lifecycle.
  • Only opted-in hooks are suppressed, and they resume after all active calls complete.
  • Session deletion clears stale tracking state.
  • The earlier sessionScope approach was fully reverted because it did not address active subagents.

Verification: npm run lint, npm run typecheck, npx --yes bun@1.3.9 test --timeout 20000 (142 passed, 3 gated skips), V1 TypeScript build, and V2 bundle build.

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