Skip to content

fix: preserve OpenCode V1 hooks and support V2 - #982

Open
SaulMoro wants to merge 1 commit into
Tencent:mainfrom
SaulMoro:fix/opencode-v2-hooks
Open

SaulMoro wants to merge 1 commit into
Tencent:mainfrom
SaulMoro:fix/opencode-v2-hooks

Conversation

@SaulMoro

@SaulMoro SaulMoro commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

Built-in and enterprise OpenCode plugins
  default { id, server (V1), setup (V2) }
    → shared event/command dispatch
V2 shell OPENCODE_SESSION_ID
    → existing recall session attribution

Preserves OpenCode 1.18.23 and adds V2 compatibility, verified with 2.0.23. Refresh generated plugins with teamai hooks inject or teamai pull, then restart OpenCode.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature causing existing behavior to change)
  • Documentation only
  • Refactor / internal cleanup

Evidence

  • Before: V2 rejected both named-function generators: Plugin must export a default definition with an id and an effect or setup function. The original-module regression failed with an undefined default export; V2 prompt dispatch and native shell attribution also failed before implementation.
    After: Actual V1 1.18.23 and V2 2.0.23 hosts loaded the CLI-installed plugin in isolated HOME/XDG directories. Each session creation produced exactly one session-start with the host session id and canonical cwd, and exactly one enterprise shell-command marker. V2 plugin.list confirmed teamai.hooks and teamai.agent.start-proof active.

Test Plan

  • npx tsc --noEmit

  • npm run lint

  • npx vitest run — 8,028 passed, 20 skipped; final additional failure-path regressions passed in the focused run.

  • npx vitest run opencode-hooks session-id — generated original ESM, both entrypoints, event payloads/matchers, aliases, task links, cleanup, enterprise replacement/removal and nonfatal subprocess errors.

  • npm run build

  • TEAMAI_OPENCODE_V2_BIN=/Users/pw-smoro/.opencode/bin/opencode2 npm run test:e2e — full suite completed: 557 passed, 26 skipped, 6 failed. All six also fail at the pinned base: one self-mode-worktrees-808 untracked .teamai/last-fetch.json assertion and five stats-recall-dry-run assertions. Both actual OpenCode host tests pass in this full run.

    Baseline evidence: archived a8957a8 into excluded .scrath/baseline, built it, and ran npx vitest run --config vitest.e2e.config.ts src/__tests__/e2e/self-mode-worktrees-808.test.ts -t "lets a checkout pull and contribute after another checkout switched" (same failure), then npx vitest run --config vitest.e2e.config.ts src/__tests__/e2e/stats-recall-dry-run.test.ts (same five failures). No unrelated fixes added.

  • Real-host run: TEAMAI_OPENCODE_V2_BIN=/Users/pw-smoro/.opencode/bin/opencode2 npx vitest run --config vitest.e2e.config.ts opencode-hooks — 2 passed. The built CLI executes hooks inject; real hosts serve and create sessions; a capture executable verifies spawned dispatch argv/STDIN, while the enterprise command actually appends its marker.

Related Issues

Reported OpenCode V2 server-plugin error; no linked issue.

Notes for Reviewers

Whole branch reviewed against initial origin/main SHA a8957a8943a297b08fbc017b48d9b29c8bb98b98; parallel Standards/Spec review: 0 findings in each axis, no pending corrections. EN/CN usage docs and agent troubleshooting updated.

V2 smoke testing opts in through TEAMAI_OPENCODE_V2_BIN; default CI retains the pinned V1 binary. Capture verifies adapter delivery, not remote provider side effects. V2 supplies its native shell session variable because its shell hook has no session id.

Merge Danger

Door: two-way

Regenerate plugins after rolling back. No schema or data migration.

Blast Radius: OpenCode

Built-in/enterprise hooks and native shell attribution only; other tool adapters are unchanged.

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