Skip to content

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

Merged
jeff-r2026 merged 2 commits into
Tencent:mainfrom
SaulMoro:fix/opencode-v2-hooks
Oct 7, 2026
Merged

jeff-r2026 merged 2 commits 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
Enterprise hook command
    → sh -c (POSIX) | cmd.exe /d /s /c (win32), as the Pi adapter
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

Rebased onto origin/main 3f11504 (after #971, #974, #986) without conflicts; checks below were rerun on the rebased head.

  • npm run build
  • npx tsc --noEmit
  • npm run lint
  • npx vitest run — 8,103 passed, 20 skipped.
  • npx vitest run opencode-hooks session-id — generated original ESM, both entrypoints, event payloads/matchers, aliases, task links, cleanup, enterprise replacement/removal, the cmd.exe spawn on win32 (failed before the fix) and nonfatal subprocess errors.
  • Real-host run (pre-rebase, on a8957a8): 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.
  • Full npm run test:e2e (pre-rebase): 557 passed, 26 skipped, 6 failed, all six also failing at the then-base a8957a8. Five were stats-recall-dry-run; after rebasing onto fix(dry-run): allow stats and recall previews after #970 #986 that file passes (7/7). The remaining one, self-mode-worktrees-808 (untracked .teamai/last-fetch.json assertion), is unrelated and was not rerun. The full e2e suite was not rerun after the rebase.

Related Issues

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

Notes for Reviewers

Branch reviewed against a8957a8 (parallel Standards/Spec review: 0 findings in each axis). The commits merged since (#971, #974, #986) touch dry-run, recall scoping and roles, not OpenCode hooks or session-id; they share only docs/usage-guide*.md, and those hunks merged cleanly. 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. Enterprise hooks previously ran through Bun's $`sh -c …`, which also needed sh on PATH; spawning directly now picks the platform shell (Codex review finding). The Windows path is unit-tested only, not run on a Windows host.

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.

@jeff-r2026 jeff-r2026 self-assigned this Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown

No findings.

The PR description includes a representative built-CLI, real OpenCode V1/V2 host verification, satisfying the required end-to-end testing record for runtime changes. I did not run or build PR code, as requested.

@SaulMoro
SaulMoro force-pushed the fix/opencode-v2-hooks branch from 6abb9bc to ff96bcc Compare October 6, 2026 15:36
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
  • [P1 blocking] Preserve Windows execution for enterprise hooks — src/opencode-hooks.ts:350 unconditionally launches sh -c. On a standard Windows OpenCode installation without a POSIX shell, every server-pushed hook fails with ENOENT; the error is swallowed, so the hook silently never runs. Use cmd.exe /d /s /c on win32, as the Pi adapter does, or retain OpenCode’s cross-platform shell abstraction.

The PR description includes a representative built-CLI real-host verification for V1 and V2, satisfying the required end-to-end testing record.

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown

No findings.

The earlier Windows issue is resolved: enterprise hooks now use cmd.exe /d /s /c on win32 in src/opencode-hooks.ts:350.

The PR description includes representative built-CLI, real OpenCode V1 and V2 host verification, satisfying the required end-to-end testing record for runtime changes. I did not run or build PR code, as requested.

@jeff-r2026
jeff-r2026 merged commit f6666ce into Tencent:main Oct 7, 2026
13 checks passed
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.

2 participants