Skip to content

feat(hooks): run project team hooks on OpenCode and OMP (#1492) - #1497

Merged
SaulMoro merged 2 commits into
Tencent:mainfrom
Walternater:feat/1492-team-hooks-opencode-omp
Oct 28, 2026
Merged

SaulMoro merged 2 commits into
Tencent:mainfrom
Walternater:feat/1492-team-hooks-opencode-omp

Conversation

@Walternater

@Walternater Walternater commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

teamai installs its own built-in bridge for OpenCode (~/.config/opencode/plugin/teamai-hooks.ts) and OMP (~/.omp/agent/extensions/teamai-hooks.ts), but a team's hooks/hooks.yaml entries never run there: the adapters continue before the settings path and never receive teamDefs, and the generated bridges call hook-dispatch … without --team-hooks (which only ran a Codex dispatcher). The README matrix's hooks ✓ covers the built-in channel only, so a team cannot tell why its hook-driven behaviour is missing on those two hosts.

Fix

An applied-hooks record, then a live dispatcher. The bridges are user-wide and are not a hook list, so "what pull applied" needs somewhere to live. reconcileHooksToAllTools now records the team hooks it applied for OpenCode and OMP — after resolveTeamHooks' security gates — in ~/.teamai/team-hook-bridges.json, keyed by user or the shared project anchor. teamai hook-dispatch <event> --tool <tool> --team-hooks then:

  • resolves the project from the payload's cwd (project over user);
  • runs only the hooks recorded for that scope/project — so TEAMAI_HOOKS_DISABLED at run time, sharing.hooks.autoApply, requireTeamScripts, a held/failed resolution, or a hook that exists only on an unpulled branch all behave as they do for the settings-based tools (hooks remove clears the record);
  • self mode has no partition projectRoot; its business repo is the project key, so init --self + pull records the applied hooks there too (and a self-mode user config records them under user);
  • matches event, matcher and the record's per-tool filtering, with Bash matching the host's bash;
  • passes stdin through, runs in the payload's cwd with each hook's timeout, and keeps exit 2 as the blocking decision;
  • stdout carries the context: a hook's hookSpecificOutput.additionalContext when it follows Claude's JSON contract, plain text otherwise. stderr is forwarded for any non-empty diagnostic, independent of the dispatcher's own exit status — a hook exiting 1, or a timeout, keeps dispatcher exit 0 but its reason still reaches the host log.

OpenCode bridge. Calls the dispatcher on chat.message, tool.execute.after, session.idle, and runs the SessionStart hooks again for every request — V1 through experimental.chat.system.transform, V2 through the ctx.session.hook('context') registration (merged into the existing context hook so both contexts share one registration). Running them per request is what lets a prompt hook's level change reach the next turn. A prompt hook's output is kept for one turn and pruned after use; there is no per-session cache. OpenCode has no subagent-start event, so team context reaches main sessions only.

OMP extension. Calls the dispatcher on tool_result, session_stop, and runs SessionStart + the prompt hook in before_agent_start each turn, appending their output to systemPrompt. It awaits the Bun shell call (ShellOutput) and reads its exitCode/stderr, so a team hook that blocks or fails is visible. OMP has no subagent-start event either.

Pi stays built-in only, as its adapter documents and the issue scopes. The OpenCode and OMP hook adapters now carry teamHooks: true in TOOLS, and the generated tool-support pages say incl. team hooks for them. One node process per bridged event remains (about 80 ms); combining it with the built-in dispatch is left for a follow-up.

Testing

  • npx tsc --noEmit, npm run lint (oxlint, changed files).
  • New src/__tests__/team-hooks-dispatch.test.ts — 6 passed: applied-only hooks, event/tool filtering, stdout pass-through, exit 2 + stderr, case-insensitive matcher, JSON additionalContext, a hook declared in hooks.yaml but not applied runs nothing, and the kill switch stops an applied hook.
  • opencode-hooks.test.ts — 62 passed, including the V2 session.context registration receiving team output and the V1 transform running SessionStart per request.
  • omp-hooks.test.ts — 30 passed, including team output in before_agent_start's systemPrompt.
  • omp-installed-launcher.test.ts — the installed-CLI launcher path still reaches the context callback with the team dispatcher added; its shim now models Bun's awaitable ShellOutput (text()/exitCode/stderr).
  • hooks-reconcile-scope.test.ts — including a self-mode case that asserts the bridge record is written for init --self + pull.
  • tool-support.test.ts — the regenerated English and Chinese pages match the updated TOOLS descriptor.
  • Related suites (hooks-reconcile-scope, hooks-team, hooks-golden, hook-dispatch): 205 passed.

Real CLI, after npm run build, fresh HOME, a user-scope team with three hooks (OpenCode gets all three; OMP only the SessionStart one):

$ teamai hooks inject
inject exit=0
$ cat ~/.teamai/team-hook-bridges.json
{"omp":{"user":[{"id":"session-context","event":"SessionStart",...}]},
 "opencode":{"user":[{"id":"session-context",...},{"id":"prompt-context",...},{"id":"block",...}]}}

$ teamai hook-dispatch session-start --tool opencode --team-hooks
TEAM_SESSION_CONTEXT        exit=0
$ teamai hook-dispatch prompt-submit --tool opencode --team-hooks    # a hook exits 2
BLOCKED_REASON              exit=2
$ TEAMAI_HOOKS_DISABLED=1 teamai hook-dispatch session-start --tool opencode --team-hooks
                            exit=0
$ teamai hook-dispatch prompt-submit --tool omp --team-hooks         # opencode-only hook
                            exit=0
$ teamai hooks remove
$ cat ~/.teamai/team-hook-bridges.json
{}
$ teamai hook-dispatch session-start --tool opencode --team-hooks
                            exit=0

(Each dispatcher run fed {"cwd": …, "prompt": …} on stdin.)

Not run here: a live OpenCode/OMP session — OMP is not installed on this machine, and the host-side context injection rests on the generated bridge and the unit tests above (V1 and V2 stubs, installed-CLI launcher). Deferred to the reviewer/CI.

Fixes #1492.

@github-actions

Copy link
Copy Markdown

Findings

  • [P2 non-blocking] src/team-hooks-dispatch.ts:137 — Successful hooks lose all stderr: printf diagnostic >&2; exit 0 returns an empty diagnostic stream. Forward stderr regardless of exit status so the CLI preserves the promised diagnostic channel.
  • [P2 non-blocking] src/omp-hooks.ts:188 — .quiet().nothrow().text() discards the exit status and stderr. A hook writing a blocking reason to stderr and exiting 2 is therefore silent in OMP, contrary to the description’s claim that both bridges log it. OpenCode also suppresses diagnostics for failures other than exit 2 (src/opencode-hooks.ts:191). Capture and report dispatcher stderr in both adapters.
  • [P2 non-blocking] src/opencode-hooks.ts:146 — teamContext retains every session’s SessionStart output indefinitely; there is no deletion when a session is deleted. A long-lived OpenCode server accumulates closed sessions and their context. Remove the corresponding entry on session deletion.
  • [P2 non-blocking] src/index.ts:1230 — This adds team-hook support for OpenCode and OMP without updating their TOOLS entries in src/tools.ts. The trusted Code Review Rules explicitly require descriptor updates when a tool’s supported behavior changes.

Testing
The description includes representative real-CLI runs after npm run build, satisfying the required verification record. Live-host coverage is explicitly deferred; that is not blocking. No earlier findings were supplied. I did not run, build, or install PR code.

@Walternater
Walternater force-pushed the feat/1492-team-hooks-opencode-omp branch from 47562cd to 2c41218 Compare October 28, 2026 05:19
@github-actions

Copy link
Copy Markdown

Findings

  • [P2 non-blocking] src/team-hooks-dispatch.ts:137 — Successful hooks still lose stderr: printf diagnostic >&2; exit 0 produces no diagnostics. Forward stderr regardless of exit status.
  • [P2 non-blocking] src/omp-hooks.ts:188 — .quiet().nothrow().text() still discards stderr and exit status, making an exit-2 blocking reason silent. OpenCode likewise logs diagnostics only for exit 2 (src/opencode-hooks.ts:191), hiding other failures. Capture and report dispatcher stderr in both bridges.
  • [P2 non-blocking] src/opencode-hooks.ts:146 — teamContext retains SessionStart output after sessions are deleted. A long-lived server accumulates closed-session context; delete the corresponding entry on session.deleted.
  • [P2 non-blocking] src/index.ts:1230 — OpenCode and OMP gain team-hook support without updating src/tools.ts. The Code Review Rules require updating a tool’s TOOLS entry when its supported behavior changes.

All four earlier findings remain unresolved in the current diff.

Testing
The description documents representative real-CLI runs after npm run build, satisfying the required record. Deferred live-host coverage is not blocking. I only read the specified diff; I did not run, build, or install PR code.

@SaulMoro SaulMoro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was generated by AI during triage.

@Walternater Thanks. The dispatcher itself works with the built CLI. Events, matchers (case-insensitive) and tools: filter correctly, so a claude-only hook stays off OpenCode and OMP. A timeout kills the child, a workspace-scope project gate holds, Codex dispatch is unchanged, and the bridge files differ from main only by the new dispatch code. A few things block it.

  • [P1 blocking] The live dispatcher skips the team-hook security gates. src/team-hooks-dispatch.ts reads the team's hooks/hooks.yaml directly instead of going through resolveTeamHooks. On OpenCode and OMP, the controls in docs/guide/sharing.md:196-203 stop working:

    • TEAMAI_HOOKS_DISABLED=1 still runs the hooks.
    • With sharing.hooks.autoApply: false, pull says the hooks are pending, but they run.
    • With requireTeamScripts, pull reports all 8 hooks skipped, but they all run.
    • In self mode, a hook that exists only on a checked-out branch runs straight away, with no pull and no "Applying" listing. Claude's settings only get it after a pull on that branch.

    Please resolve the hooks the way the other tools do, so what runs here is what pull applied.

  • [P1 blocking] On OpenCode 2.x, hook output never reaches the model. The plugin's V2 setup path never registers experimental.chat.system.transform. In a V2 stub host loading the generated plugin, the hooks run but the context it passes stays []. OpenCode's current release is v2.2.0, and #1492 names the V2 ctx.session.hook('context') channel.

  • [P1 blocking] The issue's acceptance case fails on both hosts. SessionStart output is captured once and re-sent on every request, and a prompt hook's output lasts one request. With a ponytail-shaped team (SessionStart prints RULESET(level=<file>), a prompt hook on "stop ponytail" writes off), every request after the stop still carries RULESET(level=full), and PONYTAIL_STOPPED shows in one request only. #1492 asks that "stop ponytail" remove it and that the next turn reflect a level change.

  • [P2 non-blocking, but needed before approval] Hook failures leave no trace. OMP's .quiet().nothrow().text() (src/omp-hooks.ts:188) drops the exit status and stderr. A hook exiting 2 with BLOCKED_REASON is silent there, and the extension still returns the session context for that prompt. OpenCode logs only exit 2, so an exit-1 hook leaves no trace on either host. #1492 item 5 asks for any other non-zero to be logged, and the body says both bridges log exit-2 stderr.

  • [P2 non-blocking]

    • A successful hook's stderr is dropped (src/team-hooks-dispatch.ts:137).
    • teamContext in the OpenCode bridge is never pruned, so a long-lived server keeps one entry per session.
    • #1492 asks to document which subagent events get the context. Nothing maps or documents it yet.
  • [P3 nit] Every bridged event now starts a second node process, about 80 ms each, even for teams with no hooks.yaml. chat.message and tool.execute.after are awaited, so it lands on every tool call.

At 47562cdc CI Lint & Test failed on ubuntu (opencode-hooks.test.ts:491, omp-installed-launcher.test.ts:32). 2c412185 updates both tests, and CI is still running on it. On the CI review's TOOLS point: src/tools.ts and the tool-support page have no team-hooks cell, and the OpenCode/OMP hooks cells describe where teamai writes, which doesn't change here. Nothing is needed there.

This conflicts with #1494 in src/index.ts (the --team-hooks branch). The resolution keeps #1494's CodeBuddy branch next to this PR's OpenCode/OMP branch, and whichever lands second rebases.

Not run here: a live OpenCode or OMP session. The V2 and acceptance findings come from stub hosts that load the generated plugin and extension with the real CLI, plus the upstream OpenCode source.

@SaulMoro
SaulMoro self-requested a review October 28, 2026 05:22
@Walternater
Walternater force-pushed the feat/1492-team-hooks-opencode-omp branch from 2c41218 to 5cd6280 Compare October 28, 2026 05:23
@github-actions

Copy link
Copy Markdown

Findings

  • [P2 non-blocking] src/team-hooks-dispatch.ts:137 — Successful hooks still lose stderr: printf diagnostic >&2; exit 0 returns no diagnostics. Forward stderr regardless of exit status.
  • [P2 non-blocking] src/omp-hooks.ts:188 — .quiet().nothrow().text() still discards stderr and exit status, silencing an exit-2 blocking reason. OpenCode also hides diagnostics for other failures (src/opencode-hooks.ts:191). Report dispatcher stderr in both bridges.
  • [P2 non-blocking] src/opencode-hooks.ts:146 — teamContext retains SessionStart output after session deletion, accumulating closed-session context in a long-lived server. Delete the entry on session.deleted.
  • [P2 non-blocking] src/index.ts:1230 — OpenCode and OMP gain team-hook support without corresponding updates to TOOLS in src/tools.ts, contrary to the Code Review Rules requiring descriptor updates when supported behavior changes.

All four earlier findings remain unresolved in the current diff.

Testing
The description documents representative real-CLI runs after npm run build, satisfying the required verification record. Deferred live-host coverage is not blocking. I only read the specified diff; I did not run, build, or install PR code.

@Walternater
Walternater force-pushed the feat/1492-team-hooks-opencode-omp branch 2 times, most recently from 61469e7 to 5c816f5 Compare October 28, 2026 05:55
@github-actions

Copy link
Copy Markdown

Findings

  • [P2 non-blocking] src/omp-hooks.ts:190 — result is a Bun ShellPromise, not the resolved shell output. Calling .text() does not expose exitCode or stderr on that promise, so these reads fall back to 0 and ""; an exit-2 blocking reason remains silent. Await the shell result and read its output fields. The updated mock incorrectly attaches those fields to the promise.
  • [P2 non-blocking] src/opencode-hooks.ts:178 — Diagnostics still disappear for non-blocking failures. For example, printf failure >&2; exit 1 produces dispatcher stderr but exit code 0 (src/team-hooks-dispatch.ts:145), so reportTeam suppresses it. Timeouts are likewise hidden; OMP has the same exit-status guard. Report nonempty dispatcher stderr independently of exit status.
  • [P2 non-blocking] src/index.ts:1230 — OpenCode and OMP gain team-hook support without updating their entries in src/tools.ts. This remains contrary to the Code Review Rules requiring descriptor updates when a tool’s supported behavior changes.

Earlier Findings
The dispatcher’s successful-hook stderr loss is resolved. The indefinite SessionStart cache is also resolved: SessionStart now runs per request instead of being retained per session. Bridge diagnostics remain partially unresolved as detailed above; the missing TOOLS update remains unresolved.

Testing
The description includes representative real-CLI verification after npm run build, satisfying the required record. Deferred live-host coverage is not blocking. I only read the specified diff and trusted base criteria; I did not run, build, or install PR code.

@SaulMoro

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

@Walternater Thanks, this is a big step. We reran the earlier fixtures on 5c816f56, and our three blocking items are fixed:

  • The security gates hold. TEAMAI_HOOKS_DISABLED, autoApply: false, requireTeamScripts, and a hook that exists only on an unpulled branch all stop the hook on OpenCode and OMP.
  • OpenCode 2.x now receives the hook output, in a V2 stub host loading the generated plugin.
  • The stop-ponytail case passes on the OpenCode 1.x and 2.x stubs. On OMP it's confirmed by code and a real-Bun run.

A successful hook's stderr now comes through, and teamContext is pruned. The rebase keeps #1494's CodeBuddy branch exactly as merged.

Two things still block approval:

  • [P1 blocking] In self mode, OpenCode and OMP never run team hooks. After init --self, a hook committed on main and a pull, pull prints Applying 1 team hook(s) and Claude's settings.local.json gets the hook. But ~/.teamai/team-hook-bridges.json is never written, and dispatch returns nothing on both hosts. hooks inject doesn't fix it. reconcileTeamHooksForConfig sets teamHookProjectRoot only outside self mode, so recordAppliedTeamHooks gets no project root and returns early. Passing opts.teamHookProjectRoot ?? opts.installedBaseDir should cover it.
  • [P2 non-blocking, but needed before approval] A failing hook still leaves no trace.
    • On OMP the extension reads exitCode and stderr from Bun's shell promise rather than from its result. Loaded under real Bun 1.4.0, a hook that exits 2 (BLOCKED_REASON) or exits 1 logs nothing. The updated test shim puts those fields on the promise, which real Bun doesn't, so the tests pass anyway. The body's claim that OMP failures are now visible doesn't hold yet.
    • On OpenCode the dispatcher returns 0 for an exit-1 hook or a timeout, and the bridge logs only a non-zero code. Exit 2 logs BLOCKED_REASON, but an exit-1 hook is silent.
  • [P2 non-blocking]
  • [P3 nit]
    • A stale comment in omp-hooks.ts.
    • On OpenCode 1.x the title request may take the prompt hook's one-turn output. That's inferred from upstream source, not a live host.
    • Hook output that is bare JSON, like 42, is dropped.

Build, tsc, lint, this PR's tests (99) and the related hook suites pass. No live OpenCode or OMP session was run here. When we wrote this, CI was still running the macOS jobs, ubuntu Node 20 and two E2E shards.

@Walternater

Copy link
Copy Markdown
Collaborator Author

@SaulMoro the three blocking findings are addressed on 5c816f56; CI is fully green.

  1. Security gates — reconcile now records the hooks it applied in ~/.teamai/team-hook-bridges.json after resolveTeamHooks (TEAMAI_HOOKS_DISABLED, sharing.hooks.autoApply, requireTeamScripts, held/failed resolution, the namespace set), keyed by user or the shared project anchor. --team-hooks runs only that record for the payload's project, so a hook on an unpulled branch, a held-back hook and a non-whitelisted hook do not run; the kill switch is also checked at dispatch time; hooks remove clears the record ({}, dispatch runs nothing). Verified with the built CLI (record → session/prompt → TEAMAI_HOOKS_DISABLED=1 → hooks remove).
  2. OpenCode V2 context — the team context is part of the existing ctx.session.hook('context') registration (one registration, both contexts), so event.system receives it on V2; a V2 stub test pins it. V1 keeps experimental.chat.system.transform.
  3. Acceptance case — SessionStart hooks now run per request (V1 transform / V2 context hook; OMP before_agent_start), so a prompt hook's level change reaches the next turn and "stop ponytail" removes it. A prompt hook's output is kept for one turn and pruned after use; the per-session map is gone.

From the P2s: OMP now reads the Bun shell result's exit code and stderr (a blocking/failing hook is visible), OpenCode logs any non-zero stderr, and the dispatcher forwards stderr from successful hooks too. Neither host exposes a subagent-start event; that is documented in the bridges and the body. The second node process per event remains (P3), noted in the body as a follow-up.

Fixes #1492 is in the body. Could you take another look?

@SaulMoro

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

@Walternater Thanks. Our comment above, from just before yours, confirms those three are fixed on 5c816f56. Two items in it are still open:

  • Self mode. After init --self, a hook committed on main and a pull, ~/.teamai/team-hook-bridges.json is never written, so --team-hooks returns nothing on OpenCode and OMP while Claude gets the hook. reconcileTeamHooksForConfig passes no teamHookProjectRoot in self mode, and recordAppliedTeamHooks returns early without it.
  • OMP failures. In src/omp-hooks.ts:190-193 the shell call isn't awaited, so result is Bun's ShellPromise, and result.exitCode / result.stderr are undefined there. Loaded under real Bun 1.4.0, a hook that exits 2 with BLOCKED_REASON, and one that exits 1, both log nothing. const result = await $\...`.quiet().nothrow();gives theShellOutputwithexitCodeandstderr`. The test shim sets those fields on the promise itself, which is why the tests pass.

@Walternater
Walternater force-pushed the feat/1492-team-hooks-opencode-omp branch from 5c816f5 to 16dcce2 Compare October 28, 2026 06:43
@Walternater

Copy link
Copy Markdown
Collaborator Author

@SaulMoro both remaining items are fixed on 16dcce25:

  • Self mode. reconcileTeamHooksForConfig now passes the business repo as teamHookProjectRoot when isSelfMode, so recordAppliedTeamHooks writes the project record (keyed by the shared anchor, same key the dispatcher resolves). A self-mode user config records under user. Added a hooks-reconcile-scope case: a self config + reconcileTeamHooksForConfig writes the bridge index for both opencode and omp.
  • OMP failures. The shell call is awaited (const result = await $\…`.quiet().nothrow()), so resultis Bun'sShellOutputandexitCode/stderrare read from it; a hook exiting 2 logsBLOCKED_REASONand one exiting 1 logs its stderr. The test shims now model the awaitableShellOutput(withtext(), exitCode, stderr`) instead of attaching those fields to the promise, including the installed-launcher shim.

CI is running on 16dcce25; the related unit files (dispatcher, OpenCode, OMP, installed launcher, reconcile) are 187 passed locally.

@github-actions

Copy link
Copy Markdown

Findings

  • [P2 non-blocking] src/opencode-hooks.ts:178, src/omp-hooks.ts:194 — Both bridges still suppress diagnostics when the dispatcher exits 0. A hook running printf failure >&2; exit 1 produces dispatcher stderr but dispatcher exit 0, so its failure is silent; timeouts are likewise hidden. Report nonempty stderr independently of exit status.
  • [P2 non-blocking] src/index.ts:1255 — OpenCode and OMP gain team-hook support without updating their TOOLS entries in src/tools.ts. The trusted Code Review Rules require descriptor updates when a tool’s supported behavior changes.

Earlier Findings
The Bun ShellPromise issue, successful-hook stderr loss in the dispatcher, and indefinite SessionStart cache are resolved. The remaining diagnostics and descriptor findings persist.

Testing
The description documents representative real-CLI verification after npm run build, satisfying the required record. Deferred live-host coverage is not blocking. I only read the specified diff and trusted base criteria; I did not run, build, or install PR code.

@Walternater
Walternater force-pushed the feat/1492-team-hooks-opencode-omp branch from 16dcce2 to cc2731a Compare October 28, 2026 06:46
@github-actions

Copy link
Copy Markdown

Findings

  • [P2 non-blocking] src/opencode-hooks.ts:178, src/omp-hooks.ts:194 — Both bridges still suppress stderr when the dispatcher exits 0. A hook running printf failure >&2; exit 1 produces dispatcher stderr but dispatcher exit 0, so its diagnostic disappears; timeouts are likewise hidden. Report nonempty stderr independently of exit status.
  • [P2 non-blocking] src/index.ts:1255 — OpenCode and OMP gain team-hook support without updating their TOOLS entries in src/tools.ts. The trusted Code Review Rules require descriptor updates when a tool’s supported behavior changes.

Earlier Findings
The Bun ShellPromise issue, dispatcher’s successful-hook stderr loss, and indefinite SessionStart cache are resolved. The two findings above remain unresolved.

Testing
The description documents representative real-CLI verification after npm run build, satisfying the required record. Deferred live-host coverage is not blocking. I only read the specified diff; I did not run, build, or install PR code.

@SaulMoro

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

@Walternater Thanks. On cc2731aa, self mode now records the applied hooks and dispatches them on OpenCode and OMP, and under real Bun 1.4.0 OMP logs an exit-2 hook's BLOCKED_REASON. Two things still block approval:

  • [P1 blocking] In self mode the new project root also gates the hooks written into tracked files. teamHookProjectRoot is read by gating (scopedTeamDefs), the records, held-hook regating and the Claude/ZCode removal rules, so setting it to the business root in self mode changes more than the OpenCode/OMP record. With the built CLI on main and on this head (init --self, a hook committed on main, pull), .codebuddy/settings.json and .cursor/hooks.json change from printf MAIN_HOOK_RAN to if [ "$PWD" = '<abs path>/proj' ] || case "$PWD" in '<abs path>/proj'/*) … then (printf MAIN_HOOK_RAN); fi. Both files are tracked in self mode, so a teammate's clone at another path, or a moved checkout, runs nothing. Claude's settings.local.json, ZCode and Codex are identical to main. Keeping teamHookProjectRoot as on main and keying only the record with opts.teamHookProjectRoot ?? opts.installedBaseDir would avoid it. hooksRemove (src/hooks-cmd.ts:315) and uninstall (src/uninstall.ts:990) still pass no root in self mode either, so they leave the record behind. A live host isn't affected, since the plugin and extension are removed.
  • [P2 non-blocking, but needed before approval] An exit-1 hook or a timeout still leaves no trace. The dispatcher returns 0 for an exit-1 hook, and both bridges log only a non-zero code. So a hook that exits 1 logs nothing on OMP (real Bun) or on the OpenCode V1 plugin. Exit 2 logs on both. [feat] Run custom team hooks (hooks/hooks.yaml) on OpenCode and OMP #1492 item 5 asks for any other non-zero to be logged.

The earlier P2/P3 notes are unchanged: SessionStart per request is undocumented, the subagent subset is undocumented, a stale OMP comment, and two inferred edge cases. Build, tsc, lint and this PR's 5 test files (187 tests) pass. CI Lint & Test and the E2E shards were still running when we checked.

@Walternater
Walternater force-pushed the feat/1492-team-hooks-opencode-omp branch from cc2731a to b81e7a2 Compare October 28, 2026 06:56
@Walternater

Copy link
Copy Markdown
Collaborator Author

Both P2 findings are addressed on b81e7a27:

  • stderr independent of exit status. The dispatcher reports a failing or timed-out hook on its own stderr while keeping exit 0 unless the hook blocks with 2. Both bridges now log any non-empty stderr regardless of the dispatcher's exit code, so printf failure >&2; exit 1 and timeouts are visible on OpenCode and OMP.
  • TOOLS descriptor. The HookAdapter shape gains teamHooks?: true; the OpenCode and OMP hook entries set it, and the generated tool-support pages now render opencode-plugin incl. team hooks / omp-extension incl. team hooks (both languages regenerated with npx vitest run tool-support -u).

CI is running on b81e7a27.

@SaulMoro

SaulMoro commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

@Walternater Thanks. On b81e7a27 the exit-1 and timeout item is resolved. runLiveTeamHooksDispatcher writes a hook's stderr, or the timeout line, whatever the exit code, and both bridges now log any non-empty stderr. The teamHooks flag on the OpenCode and OMP entries in TOOLS reads well in the generated pages.

The P1 from the comment above, posted just before your reply, still stands on this head, since the teamHookProjectRoot code is unchanged between cc2731aa and b81e7a27. In self mode the CodeBuddy and Cursor hook files that get committed carry an absolute-path $PWD gate. Keying only the record with opts.teamHookProjectRoot ?? opts.installedBaseDir, and leaving the gate root as on main, would fix it. The same comment notes that hooks remove and uninstall leave the self-mode record behind. That's the last item before approval.

@github-actions

Copy link
Copy Markdown

Findings

  • [P2 non-blocking] src/team-hooks-dispatch.ts:141 — Timed-out hooks still lose their own stderr. With timeout: 1, printf reason >&2; sleep 10 reports only the generated timeout message, discarding reason. Append captured stderr independently of the timeout diagnostic.
  • [P2 non-blocking] src/hooks.ts:3284 — OpenCode gains team-hook support without a corresponding TOOLS entry update. Only OMP receives teamHooks: true, so OpenCode’s generated support documentation also remains unchanged. Update OpenCode’s descriptor as required by the trusted Code Review Rules.

Earlier Findings
Successful-hook stderr forwarding, Bun shell-result handling, the indefinite SessionStart cache, and both bridges’ exit-status diagnostic guards are resolved. The descriptor finding is resolved for OMP but remains for OpenCode.

Testing
The description records representative real-CLI verification after npm run build, satisfying the testing requirement. Deferred live-host coverage is not blocking. I only read the specified diff and trusted base criteria; I did not run, build, or install PR code.

Their built-in bridges are user-wide and were generated without the team's
hooks, so a team's hooks/hooks.yaml entries never ran there.

Add a live team-hook dispatcher: `hook-dispatch <event> --tool <tool>
--team-hooks` resolves the project from the payload's cwd, reads that
project's team hooks, and runs the ones matching event, matcher and tool.
Stdout carries their context, stderr their diagnostics, and exit 2 keeps its
blocking meaning. No new store: the team repo is read at hook time.

The OpenCode plugin and OMP extension call it and inject the output into the
host context: OpenCode through experimental.chat.system.transform (its event
hooks cannot inject), OMP through before_agent_start's systemPrompt, with the
SessionStart output kept for the session and a prompt hook's output once.
Pi stays built-in only, as documented.
@Walternater
Walternater force-pushed the feat/1492-team-hooks-opencode-omp branch from b81e7a2 to 2651b27 Compare October 28, 2026 08:02
@Walternater

Copy link
Copy Markdown
Collaborator Author

CI on b81e7a27 failed the same codex-trust case on every Lint job: passing teamHookProjectRoot for self mode also gated the settings-based tools' hooks in self mode. Fixed on 2651b27c:

  • teamHookProjectRoot keeps its previous shape (non-self project scope only), so settings hooks are unchanged.
  • A new teamHookBridgeRoot carries self mode's business repo for the OpenCode/OMP record only; the dispatcher reads the same project key.

codex-trust + hooks-reconcile-scope (170 tests) and the bridge/dispatcher/tool-support files (101 tests) pass locally. CI is running on 2651b27c.

@github-actions

Copy link
Copy Markdown

Findings

  • [P2 non-blocking] src/team-hooks-dispatch.ts:141 — Timed-out hooks still lose their captured stderr. With timeout: 1, printf reason >&2; sleep 10 reports only the generated timeout message, discarding reason. Append captured stderr independently of the timeout diagnostic.
  • [P2 non-blocking] src/hooks.ts:3284 — OpenCode gains team-hook support without updating its TOOLS entry. Only OMP receives teamHooks: true, leaving OpenCode’s generated support documentation unchanged. Update OpenCode’s descriptor as required by the trusted Code Review Rules.

Earlier Findings
Successful-hook stderr forwarding, Bun shell-result handling, the indefinite SessionStart cache, and both bridges’ diagnostic guards are resolved. The descriptor finding is resolved for OMP, but not OpenCode.

Testing
The description records representative real-CLI verification after npm run build, satisfying the testing requirement. Explicitly deferred live-host coverage is not blocking. I only read the specified diff and trusted base criteria; I did not run, build, or install PR code.

@SaulMoro

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

@Walternater Thanks. On 2651b27c the self-mode P1 is fixed. After init --self and pull, these files match main byte for byte: .codebuddy/settings.json, .cursor/hooks.json, Claude's settings.local.json, ZCode's config and Codex's team hooks. The OpenCode and OMP records are still keyed to the business repo, so both run the hook, and OMP's extension under real Bun 1.4.0 adds MAIN_HOOK_RAN to the system prompt. teamHookProjectRoot has the same readers and writers as on main, and teamHookBridgeRoot is read only by the two record calls.

Two small items from the CI review are left. Both reproduce and both fit this PR, so they block approval:

  • OpenCode's hook adapter in TOOLS still has no teamHooks: true (src/tools.ts:1150). Only OMP got it, so the generated docs/guide/tool-support.md still shows plain opencode-plugin for OpenCode. Adding the flag and regenerating with npx vitest run tool-support -u fixes it. Our last comment wrongly said both entries had it, sorry about that.
  • A timed-out hook's own stderr is dropped (src/team-hooks-dispatch.ts:141). A hook with timeout: 1 running printf OWN_REASON_BEFORE_HANG >&2; sleep 10 gives only teamai: team hook slow timed out after 1s. Writing the timeout line and then run.stderr, instead of the if/else if, keeps both.

Non-blocking: in self mode, hooks remove still leaves the record in team-hook-bridges.json, because hooksRemove (src/hooks-cmd.ts:347) passes no teamHookBridgeRoot. Passing it as reconcileTeamHooksForConfig does would clear it, and uninstall (src/uninstall.ts:990) is the same. The plugin and extension are removed, so no live host runs the hook. The earlier doc and comment notes are unchanged.

Build, tsc, lint and the 7 related unit test files (271 tests) pass. CI Lint & Test and E2E were still running when we checked.

@Walternater

Copy link
Copy Markdown
Collaborator Author

@SaulMoro the last self-mode P1 is addressed on 2651b27c: teamHookProjectRoot keeps its previous non-self scope, while teamHookBridgeRoot keys only the OpenCode/OMP applied-hook record. This avoids absolute-path gates in tracked CodeBuddy/Cursor files. Could you take another look? CI is currently running on this head.

@github-actions

Copy link
Copy Markdown

Findings
No confident, actionable findings in the current diff.

Earlier Findings
All earlier findings are resolved: timeout and successful-hook stderr are preserved, both bridges report diagnostics independently of exit status, OMP awaits the shell result, SessionStart context is no longer cached indefinitely, and both TOOLS entries and generated support pages are updated.

Testing
The description records representative real-CLI verification after npm run build, satisfying the requirement. Explicitly deferred live OpenCode/OMP coverage is not blocking.

I only read the specified diff and trusted base review criteria; I did not run, build, or install PR code.

@Walternater

Copy link
Copy Markdown
Collaborator Author

@SaulMoro f2c39b75 also resolves the two remaining automated-review items: timeout diagnostics now preserve hook stderr, and OpenCode has the teamHooks descriptor with regenerated support pages. The latest Codex review reports no actionable findings and all earlier findings resolved. CI is running; could you re-review the self-mode P1 fix when you have a chance?

@SaulMoro SaulMoro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was generated by AI during triage.

@Walternater Thanks, approving f2c39b75.

  • What's left from the last round is fixed. OpenCode's hook adapter in TOOLS now has teamHooks: true, and both generated tool-support pages show opencode-plugin incl. team hooks. A timed-out hook's own stderr now follows the timeout line. A test covers each.
  • Self mode. On 2651b27c, after init --self and pull, the CodeBuddy, Cursor, Claude, ZCode and Codex hook files matched main byte for byte. OpenCode and OMP still ran the hook, and OMP under real Bun 1.4.0 added it to the system prompt. f2c39b75 doesn't touch that path.
  • Checks. On a merge of this head with main (after the oxlint change in #1414), lint, tsc and the 5 related unit test files (189 tests) pass. CI is green at this head.

The CI review reported no findings and called the earlier ones resolved. We agree.

Left for later, not blocking: in self mode, hooks remove and uninstall leave the OpenCode/OMP record in team-hook-bridges.json, since hooksRemove and uninstall pass no teamHookBridgeRoot. The plugin and extension are removed, so no host runs the hook.

@SaulMoro
SaulMoro merged commit 3a583cd into Tencent:main Oct 28, 2026
18 checks passed
@Walternater
Walternater deleted the feat/1492-team-hooks-opencode-omp branch October 28, 2026 09:01
SaulMoro added a commit to SaulMoro/teamai-cli that referenced this pull request Oct 28, 2026
…eeps stderr

Why: Tencent#1497's dispatcher stopped the team's applied hooks under
TEAMAI_HOOKS_DISABLED at run time and kept a timed-out hook's own stderr
after the timeout line. The bridge does both now, before OpenCode and OMP
move onto it. The local agent's hooks are not the team's and keep running.

Proof: both tests seen red, then npx vitest run bridged-team-hooks (33).
SaulMoro added a commit to SaulMoro/teamai-cli that referenced this pull request Oct 28, 2026
Why: Tencent#1497 gave OpenCode and OMP a second way to run team hooks, an index
of what pull applied and a live dispatcher, beside the bridged file the
other four adapter tools run. One way now serves all six: pull writes
~/.teamai/team-hooks/<tool>.json through the same reconcile, records and
project gates as a settings file, and the runner reads it. The index and
the dispatcher go; nothing released wrote the index.

Kept from Tencent#1497, now on the bridge: OpenCode, OMP and Pi build the system
prompt for each request, so SessionStart runs at the session's start for
the first request and again before each later one, and a prompt hook's
change (ponytail's level, Tencent#1492) shows on the next turn; a
hook's stderr reaches the host's console; self mode delivers to the
business repo and nowhere else. HookAdapter.teamHooks goes: every hook
adapter runs the team's hooks now.

Proof: Tencent#1497's behaviours as tests on the bridge (per-turn SessionStart
for OpenCode, OMP and Pi; stderr on each host's console; self mode in and
outside the project); the per-turn and stderr ones seen red, the self-mode
one passed on the bridge as it came; npx vitest run hooks omp
opencode pi- team tools tool-support readme bridged uninstall local-agent
kiro hermes openclaw commands-reference (2280 pass); tsc and lint clean;
npm run test:e2e -- src/__tests__/e2e/opencode-hooks.test.ts against real
OpenCode 1.18.23 runs the team's SessionStart hook.
SaulMoro added a commit to SaulMoro/teamai-cli that referenced this pull request Oct 28, 2026
Why: the runner passed stderr on only for a hook that failed or timed out.
A UserPromptSubmit hook that refuses with exit 2 cannot block the prompt
on a bridged host, so its reason was lost; Tencent#1497 showed every hook's
stderr. Each hook's stderr now goes to the host, except a PreToolUse
block's, which already arrives once as the block's reason.

Proof: three tests seen red (a successful hook's note, Stop's and
UserPromptSubmit's exit 2 reasons), then npx vitest run
bridged-team-hooks kiro hermes omp opencode pi- local-agent (660 pass).
SaulMoro added a commit to SaulMoro/teamai-cli that referenced this pull request Oct 28, 2026
…eeps stderr

Why: Tencent#1497's dispatcher stopped the team's applied hooks under
TEAMAI_HOOKS_DISABLED at run time and kept a timed-out hook's own stderr
after the timeout line. The bridge does both now, before OpenCode and OMP
move onto it. The local agent's hooks are not the team's and keep running.

Proof: both tests seen red, then npx vitest run bridged-team-hooks (33).
SaulMoro added a commit to SaulMoro/teamai-cli that referenced this pull request Oct 28, 2026
Why: Tencent#1497 gave OpenCode and OMP a second way to run team hooks, an index
of what pull applied and a live dispatcher, beside the bridged file the
other four adapter tools run. One way now serves all six: pull writes
~/.teamai/team-hooks/<tool>.json through the same reconcile, records and
project gates as a settings file, and the runner reads it. The index and
the dispatcher go; nothing released wrote the index.

Kept from Tencent#1497, now on the bridge: OpenCode, OMP and Pi build the system
prompt for each request, so SessionStart runs at the session's start for
the first request and again before each later one, and a prompt hook's
change (ponytail's level, Tencent#1492) shows on the next turn; a
hook's stderr reaches the host's console; self mode delivers to the
business repo and nowhere else. HookAdapter.teamHooks goes: every hook
adapter runs the team's hooks now.

Proof: Tencent#1497's behaviours as tests on the bridge (per-turn SessionStart
for OpenCode, OMP and Pi; stderr on each host's console; self mode in and
outside the project); the per-turn and stderr ones seen red, the self-mode
one passed on the bridge as it came; npx vitest run hooks omp
opencode pi- team tools tool-support readme bridged uninstall local-agent
kiro hermes openclaw commands-reference (2280 pass); tsc and lint clean;
npm run test:e2e -- src/__tests__/e2e/opencode-hooks.test.ts against real
OpenCode 1.18.23 runs the team's SessionStart hook.
SaulMoro added a commit to SaulMoro/teamai-cli that referenced this pull request Oct 28, 2026
Why: the runner passed stderr on only for a hook that failed or timed out.
A UserPromptSubmit hook that refuses with exit 2 cannot block the prompt
on a bridged host, so its reason was lost; Tencent#1497 showed every hook's
stderr. Each hook's stderr now goes to the host, except a PreToolUse
block's, which already arrives once as the block's reason.

Proof: three tests seen red (a successful hook's note, Stop's and
UserPromptSubmit's exit 2 reasons), then npx vitest run
bridged-team-hooks kiro hermes omp opencode pi- local-agent (660 pass).
SaulMoro added a commit to SaulMoro/teamai-cli that referenced this pull request Oct 28, 2026
…eeps stderr

Why: Tencent#1497's dispatcher stopped the team's applied hooks under
TEAMAI_HOOKS_DISABLED at run time and kept a timed-out hook's own stderr
after the timeout line. The bridge does both now, before OpenCode and OMP
move onto it. The local agent's hooks are not the team's and keep running.

Proof: both tests seen red, then npx vitest run bridged-team-hooks (33).
SaulMoro added a commit to SaulMoro/teamai-cli that referenced this pull request Oct 28, 2026
Why: Tencent#1497 gave OpenCode and OMP a second way to run team hooks, an index
of what pull applied and a live dispatcher, beside the bridged file the
other four adapter tools run. One way now serves all six: pull writes
~/.teamai/team-hooks/<tool>.json through the same reconcile, records and
project gates as a settings file, and the runner reads it. The index and
the dispatcher go; nothing released wrote the index.

Kept from Tencent#1497, now on the bridge: OpenCode, OMP and Pi build the system
prompt for each request, so SessionStart runs at the session's start for
the first request and again before each later one, and a prompt hook's
change (ponytail's level, Tencent#1492) shows on the next turn; a
hook's stderr reaches the host's console; self mode delivers to the
business repo and nowhere else. HookAdapter.teamHooks goes: every hook
adapter runs the team's hooks now.

Proof: Tencent#1497's behaviours as tests on the bridge (per-turn SessionStart
for OpenCode, OMP and Pi; stderr on each host's console; self mode in and
outside the project); the per-turn and stderr ones seen red, the self-mode
one passed on the bridge as it came; npx vitest run hooks omp
opencode pi- team tools tool-support readme bridged uninstall local-agent
kiro hermes openclaw commands-reference (2280 pass); tsc and lint clean;
npm run test:e2e -- src/__tests__/e2e/opencode-hooks.test.ts against real
OpenCode 1.18.23 runs the team's SessionStart hook.
SaulMoro added a commit to SaulMoro/teamai-cli that referenced this pull request Oct 28, 2026
Why: the runner passed stderr on only for a hook that failed or timed out.
A UserPromptSubmit hook that refuses with exit 2 cannot block the prompt
on a bridged host, so its reason was lost; Tencent#1497 showed every hook's
stderr. Each hook's stderr now goes to the host, except a PreToolUse
block's, which already arrives once as the block's reason.

Proof: three tests seen red (a successful hook's note, Stop's and
UserPromptSubmit's exit 2 reasons), then npx vitest run
bridged-team-hooks kiro hermes omp opencode pi- local-agent (660 pass).
jeff-r2026 pushed a commit that referenced this pull request Oct 29, 2026
* feat(hooks): run team hooks for tools whose hosts cannot read a hook file

OpenCode, OMP, Pi, Kiro, Hermes and OpenClaw got teamai's built-in bridge
but never the team's hooks/hooks.yaml entries: their adapters were
reconciled without the team defs. Each now gets a Claude-shaped file of its
own (~/.teamai/team-hooks/<tool>.json), written by the same reconcile,
records and project gates as a settings file, and a shared runner
(hook-dispatch <Event> --tool <tool> --team-hooks) that runs it as Claude
Code would and answers in the shape the host reads.

The runner that spawns one hook command now lives in hook-command.ts and is
shared with the Codex dispatcher and CodeBuddy's Windows gate.

Proved by bridged-team-hooks.test.ts (pull writes the file, the runner
blocks a force push and leaves a plain push) and the hook, adapter,
uninstall and doctor suites.

* feat(hooks): hook-dispatch --team-hooks runs a bridged tool's team hooks

The bridge of OpenCode, OMP, Pi, Kiro, Hermes or OpenClaw calls
hook-dispatch <Event> --tool <tool> --team-hooks with the host payload;
the command prints the runner's reply and exits with its code.

Proved with the built CLI: an OMP bash call to rm -rf gets
{"block":"No rm -rf here: use the clean script"}, ls gets nothing.

* feat(omp): the OMP extension runs the team's hooks

A PreToolUse team hook blocks the tool call it refuses (tool_call), what a
SessionStart or UserPromptSubmit hook prints joins the system prompt, and the
PostToolUse and Stop hooks run with the event's payload. The extension starts
no teamai process for an event the team has no hook on, and gives up after
25 s, below OMP's 30 s limit past which it blocks the tool call.

Proved in omp-hooks.test.ts with the generated extension on a fake host.

* feat(pi): the Pi extension runs the team's hooks

Pi was told it supports built-in lifecycle hooks only and skipped every team
hook. Its extension now runs them through the shared bridge: a PreToolUse
hook blocks the call on tool_call (which fires before the tool, unlike
tool_execution_start), SessionStart and UserPromptSubmit context joins the
run's system prompt, and PostToolUse and Stop hooks run with their payload.

Proved in pi-hooks.test.ts with the generated extension on a fake host.

* feat(opencode): the OpenCode plugin runs the team's hooks

On V1 and V2, a PreToolUse team hook that refuses fails the tool call from
tool.execute.before (OpenCode hands the model the error), SessionStart and
UserPromptSubmit context joins the system prompt (V1's system transform,
V2's context hook, which waits for the session's SessionStart run), and
PostToolUse and Stop hooks run with their payload. The plugin's header no
longer claims OpenCode cannot take a hook's output.

Proved in opencode-hooks.test.ts with the generated plugin on fake V1 and V2
hosts.

* feat(kiro): Kiro runs the team's hooks through teamai's bridge

Kiro loads every file in ~/.kiro/hooks, so the team's hooks get their own,
teamai-team.json, beside teamai.json (which hasKiroHooks compares byte for
byte): one entry per event the team has hooks on, bounded by the longest of
their timeouts, that runs them through hook-dispatch --team-hooks. The
bridge matches each hook's matcher against Kiro's tool names and answers as
Kiro reads a hook: exit 2 with the reason on stderr blocks, stdout is context.

Proved in kiro-hooks.test.ts: pull writes the entries, and removes the file
once the team has no hooks.

* feat(hermes): Hermes runs the team's hooks through teamai's bridge

Hermes runs a hook command without a shell, matches Hermes tool names, sends
its own payload and ignores plain stdout, so the team's commands cannot go
into config.yaml as they are. Each Hermes event the team has hooks on gets
one approved entry instead, '~/.hermes/hooks/teamai-team-hooks.sh <Event>',
whose command stays the same across upgrades so its approval does: the
bridge rewrites the payload to Claude's shape (TERMINAL_CWD, the prompt),
runs the hooks through a shell, and answers in Hermes's JSON. SessionStart
runs on the first turn's pre_llm_call, since Hermes ignores what an
on_session_start hook prints.

Proved in hermes-hooks.test.ts and bridged-team-hooks.test.ts.

* feat(openclaw): a plugin runs the team's hooks in OpenClaw

OpenClaw's internal hooks (HOOK.md + handler.ts) cannot block a tool call
or add context to a prompt, so the team's hooks run from a standalone
plugin instead: ~/.openclaw/teamai/teamai-team-hooks.mjs, which teamai adds
to plugins.load.paths and enables (with conversation access, to read the
prompt) while the team has hooks for OpenClaw. before_tool_call blocks
with the PreToolUse reason, before_prompt_build prepends what SessionStart
(first prompt of a session) and UserPromptSubmit hooks print, and
after_tool_call and agent_end run PostToolUse and Stop. The handlers ask
for OpenClaw's longest timeout, since a slow before_tool_call fails closed
at 15s by default. A plugin allowlist, deny list, switched-off plugins or a
disabled entry stay as the member set them, with a warning naming the fix.

Proved in openclaw-hooks.test.ts: the plugin openclaw.json points at,
loaded as the gateway loads it, blocks and adds context through a stub
CLI; pull's reconcile installs it and removeAll takes it out.

* fix(agent-hooks): adapter tools run backend-pushed hooks through the bridge

A hook the HTTP local agent pushes for an adapter tool used to become a
generated file per hook, and none of them ran it as Claude Code would:
OpenClaw's handler inherited stdin, discarded the output and was not
awaited; Hermes got the raw command, without a shell or tool-name mapping,
on events whose output it ignores; Pi's PreToolUse ran on
tool_execution_start, which cannot block, with an exact lowercase matcher;
OpenCode refused PreToolUse and ignored the output. OMP and Kiro refused
agent hooks.

The hook now goes into the tool's bridged team-hook file, beside the
team's, under its [teamai:agent-hook:<slug>] marker, so the bridge runs
it: it blocks, matches Claude tool names and adds context in all six
tools. Kiro, Hermes and OpenClaw rewire their per-event entries after the
change. The per-hook generators are deleted; their removal functions stay,
so an uninstall still cleans what an earlier release generated.

The OpenCode e2e now proves a team hook end to end: real OpenCode 1.18.23
loads the generated plugin, and its SessionStart runs the hook from
hooks/hooks.yaml through the real CLI.

Proved in local-agent.test.ts (install, block, uninstall for each of the
six tools), the adapter suites, and npm run test:e2e --
src/__tests__/e2e/opencode-hooks.test.ts (V1 passed, V2 skipped: no
binary here).

* test(hooks): a pull keeps an agent hook in the bridged file

The bridged file holds the team's hooks and the HTTP local agent's; pull
reconciles only the team's records, so both keep blocking.

Proved in bridged-team-hooks.test.ts.

* feat(hooks): hooks list says which tools run each team hook

A team hook reaches only the tools with a hook on its event: Cursor's and
Copilot's files have no entry for some Claude events, and the bridges run
five. Nothing said so, so a PreToolUse hook looked delivered in Cursor.
Each team hook now lists the enabled tools that run it and the ones with
no hook on its event, from runsTeamHookOn, which reads the same channel and
event maps the writers use.

Proved in hooks-cmd.test.ts.

* docs(hooks): team hook examples, and where each one runs

The sharing guide now shows four team hooks a team can copy (refuse a
force push, keep shipped migrations unchanged, announce a release freeze,
format what the agent wrote), what each event can do, the hooks list view,
and the limits of the tools whose hooks run through teamai. The
troubleshooting reference explains runs in / not in. The README hooks
column is tied to TOOLS: a tick means teamai's hooks and the team's both.

Proved by running the examples, copied from sharing.md, through the built
CLI in a sandboxed HOME (hooks inject, hooks list, hook-dispatch
--team-hooks): the force push and the migration edit are blocked with the
documented reasons, the plain push and the other edit are not, and
SessionStart returns the freeze notice. readme-matrix.test.ts passes.

* fix(uninstall): remove the team hooks teamai runs for a tool

uninstall --agent <tool> left ~/.teamai/team-hooks/<tool>.json and
OpenClaw's team-hook plugin behind. They are now in the removal plan of
the tool whose adapter they serve, kept like that adapter on a project
uninstall, and kept for projects still set up when ~/.teamai goes, as the
Codex team-hook index is. The Hermes plan names the team-hook script.

Proved in uninstall.test.ts (red with the removal taken out).

* refactor(hooks): one function runs an event's bridged team hooks

runBridgedTeamHooks ran each event's hooks inline, and decisionOf read the
JSON decision inline; each now has its own function. Tests cover the
cases that had none: a JSON block without a reason, exit 2 with nothing on
stderr, a failing hook's stderr, a payload that is not JSON, Hermes's
prompt as a list of parts, and every OpenClaw plugin policy that keeps the
plugin from loading.

Proved in bridged-team-hooks.test.ts and openclaw-hooks.test.ts.

* test(hooks): pin what the team hook runner decides in edge cases

Why: mutation testing left decisions of runBridgedTeamHooks unpinned:
matcher "*" and none, the default hook id, a failing hook that prints a
deny, JSON with no decision, Hermes with no extra, and empty entries.

Proof: npx vitest run src/__tests__/bridged-team-hooks.test.ts (25 pass).

* fix(hooks): a new hook adapter fails to compile until its bridge is wired

Why: isBridgedToolInstalled ended in default false and the rewire was an
if-chain on tool names, so a seventh bridged tool would get no team-hook
file and no host entries, silently. Both now switch on the adapter id with
a never check. Pi's override warning said Pi runs built-in hooks only,
which this branch made untrue.

Proof: npx tsc --noEmit; npx vitest run hooks pi-hooks kiro hermes
openclaw local-agent (1630 pass).

* fix(hooks): a malformed team-hook file says so instead of crashing

Why: an entry with hooks: {} made the runner throw, and hook-dispatch
exits 0 on a throw, so every hook of the event was skipped with no word,
a PreToolUse block included. The file is now parsed with a zod schema at
the read; a file that does not parse runs nothing and the host gets one
line naming it and the fix. Reading the file once also lets the Hermes
first turn reuse merge instead of a second copy of it.

Proof: test seen red (TypeError: flatMap is not a function), then
npx vitest run bridged-team-hooks kiro hermes openclaw local-agent
hooks-cmd (481 pass); tsc and lint clean.

* fix(agent-hooks): a sync moves agent hooks earlier releases wrote to the bridge

Why: the fixes for OpenClaw's handler, Hermes's raw command and Pi's
non-blocking PreToolUse only reached a hook the server installed again,
and it sends no install for a hook already in place. Each sync now moves
a recorded hook for a bridged tool that its bridged file lacks: it removes
the old copy and writes it beside the team's hooks.

Proof: test seen red (the old Pi extension stayed), then npx vitest run
local-agent hooks uninstall (1869 pass); tsc clean.

* refactor(openclaw): each plugin message is one searchable literal

Why: the load and unload warnings were stitched from ternary fragments, so
the text a member sees could not be found in the source. The two new
uninstall warnings no longer cast the caught value.

Proof: npx vitest run openclaw (50 pass); tsc clean.

* fix(hooks): prompt hooks get the member's prompt, and time to run

Why: Pi and OMP fire before_agent_start for a run an extension starts,
with no prompt, so UserPromptSubmit hooks ran on nothing. OpenClaw's
prompt can hold rebuilt history, where currentUserMessage is the request.
Hermes's first turn runs SessionStart then UserPromptSubmit in one entry
but got the longer timeout, not their sum. OMP ran the team's prompt
hooks after the built-in dispatch, so both could pass its 30 s limit.

Proof: each case seen red, then npx vitest run pi-hooks omp-hooks
openclaw-hooks hermes (151 pass); tsc and lint clean.

* docs(hooks): Kiro's team-hook file, the bridge's data file, Claude's extra

Why: the reference did not name ~/.kiro/hooks/teamai-team.json, the data
layout did not record ~/.teamai/team-hooks/, and the sharing table read as
if exit 2 did nothing on UserPromptSubmit in Claude Code too.

Proof: removeKiroHooks removes both Kiro files (src/kiro-hooks.ts), hooks
remove and uninstall call it.

* docs(tools): agent hook cells name the evidence behind them

Why: the six bridged tools' agent hook cells said teamai's code only, but
each host's hook contract was read from its source (Kiro: its docs), and
OpenCode 1.18.23 ran a team hook through the bridge.

Proof: npx vitest run tool-support -u, then tool-support readme locate
(4221 pass).

* fix(uninstall): a project uninstall takes its team hooks out of the bridged file

Why: a project install gates its team hooks for a bridged tool in the
machine-wide ~/.teamai/team-hooks/<tool>.json. A project uninstall kept
the whole file, so after uninstall --agent omp the project's hooks still
ran there. The file now takes the ZCode path: the project's gated team
hooks go, the other projects' and the agent hooks stay.

Proof: test seen red (the force push was still blocked), then
npx vitest run uninstall hooks (1567 pass); tsc clean.

* fix(kiro): a team hook's matcher selects Kiro CLI V3's tool IDs

Why: the Kiro mapping knew only the 2.x and IDE names, so matcher: Bash
blocked execute_bash but let V3's shell through with the same input.
Kiro's hooks migration guide lists shell, read and write as the V3 IDs.

Proof: test seen red for shell, read, fs_read and write, then
npx vitest run bridged-team-hooks kiro (46 pass).

* fix(agent-hooks): removing one rewires only the team-hook entries

Why: installing or removing an agent hook for Kiro, Hermes or OpenClaw
reran the whole adapter injector. An uninstall removes teamai's Kiro
hooks before the agent hooks, so it wrote ~/.kiro/hooks/teamai.json
back. Each of the three now reconciles only its team-hook entries.

Proof: test seen red (teamai.json was back), then npx vitest run
uninstall local-agent hooks kiro hermes openclaw (1925 pass); tsc, lint.

* fix(hooks): the kill switch stops applied team hooks, and a timeout keeps stderr

Why: #1497's dispatcher stopped the team's applied hooks under
TEAMAI_HOOKS_DISABLED at run time and kept a timed-out hook's own stderr
after the timeout line. The bridge does both now, before OpenCode and OMP
move onto it. The local agent's hooks are not the team's and keep running.

Proof: both tests seen red, then npx vitest run bridged-team-hooks (33).

* refactor(hooks): OpenCode and OMP run team hooks from the bridged file

Why: #1497 gave OpenCode and OMP a second way to run team hooks, an index
of what pull applied and a live dispatcher, beside the bridged file the
other four adapter tools run. One way now serves all six: pull writes
~/.teamai/team-hooks/<tool>.json through the same reconcile, records and
project gates as a settings file, and the runner reads it. The index and
the dispatcher go; nothing released wrote the index.

Kept from #1497, now on the bridge: OpenCode, OMP and Pi build the system
prompt for each request, so SessionStart runs at the session's start for
the first request and again before each later one, and a prompt hook's
change (ponytail's level, #1492) shows on the next turn; a
hook's stderr reaches the host's console; self mode delivers to the
business repo and nowhere else. HookAdapter.teamHooks goes: every hook
adapter runs the team's hooks now.

Proof: #1497's behaviours as tests on the bridge (per-turn SessionStart
for OpenCode, OMP and Pi; stderr on each host's console; self mode in and
outside the project); the per-turn and stderr ones seen red, the self-mode
one passed on the bridge as it came; npx vitest run hooks omp
opencode pi- team tools tool-support readme bridged uninstall local-agent
kiro hermes openclaw commands-reference (2280 pass); tsc and lint clean;
npm run test:e2e -- src/__tests__/e2e/opencode-hooks.test.ts against real
OpenCode 1.18.23 runs the team's SessionStart hook.

* fix(hooks): a team hook's stderr reaches the host whatever its exit

Why: the runner passed stderr on only for a hook that failed or timed out.
A UserPromptSubmit hook that refuses with exit 2 cannot block the prompt
on a bridged host, so its reason was lost; #1497 showed every hook's
stderr. Each hook's stderr now goes to the host, except a PreToolUse
block's, which already arrives once as the block's reason.

Proof: three tests seen red (a successful hook's note, Stop's and
UserPromptSubmit's exit 2 reasons), then npx vitest run
bridged-team-hooks kiro hermes omp opencode pi- local-agent (660 pass).

* test(hermes): expect the Windows quoting Hermes needs for the team-hook script

Why: the Windows CI job failed. The test expected POSIX single quotes, but
the team-hook entry reuses reportCommand, which double-quotes the script
path on Windows because Hermes tokenizes the command itself.

What: the expectation follows the same per-platform rule.

Proof: npx vitest run src/__tests__/hermes-hooks.test.ts (11 passed);
npx tsc --noEmit clean.

* test(opencode): compare the V2 plugin with the one built for the machine's HOME

Why: the fork-safe E2E shard failed. The generated plugin now names the
team-hook file under ~/.teamai, and the test built its expected copy
under the test process's HOME instead of the sandbox machine's.

What: the expected plugin is built with HOME set to the machine's home.

Proof: npx vitest run --config vitest.e2e.config.ts
src/__tests__/e2e/opencode-versions-915.test.ts -t 'rewrites a plugin
from an older build' failed before (TEAM_HOOKS_FILE path differs) and
passes after.

* fix(openclaw): a team hook's stderr reaches OpenClaw's console

Why: the OpenClaw team-hook plugin spawned hook-dispatch with stderr
ignored, so a failing formatter or a timeout notice never showed, while
OpenCode, OMP and Pi forward it. A plugin whose own timeout fires before
the child closes also printed the same stderr twice on Pi and OpenCode.

What: the OpenClaw plugin pipes the dispatcher's stderr to console.error,
as the Pi and OpenCode ones do. All three clear what they printed, so a
second finish prints nothing.

Proof: the new openclaw-hooks test (a Stop hook's stderr reaches
console.error) failed with 0 calls before and passes after;
npx vitest run on the openclaw, pi and opencode hook tests passes.

* fix(hooks): every hook's stderr shows, on Hermes too

Why: two gaps in forwarding a team hook's stderr. When two PreToolUse
hooks blocked, the runner dropped the stderr of every exit-2 hook while
only the first one's reason reached the host, so the other hook's
message was lost. Hermes logs a shell hook's stderr only at DEBUG when
the hook exits 0, which every bridged reply did, so a failing
PostToolUse formatter was invisible at normal verbosity.

What: the runner holds back stderr only for the run whose block it
returns. A Hermes reply that carries stderr exits 1: Hermes then logs
it as a warning and still parses the decision JSON on stdout, and exit 1
blocks nothing. Other hosts keep exit 0. Kiro also shows stderr only for
a nonzero exit, but a nonzero exit there drops stdout and, in the IDE,
blocks the call, so Kiro is left as it is.

Proof: two new bridged-team-hooks tests (two blocking hooks; Hermes
exit 1 with stderr) failed before and pass after. Hermes's evaluator
(agent/shell_hooks.py _evaluate_result, v2026.9.24) warns with stderr
for a nonzero non-2 exit and then parses stdout.
Walternater added a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
A team's hooks/hooks.yaml entries now run on OpenCode and OMP. pull records the team hooks it applied for each project, after the usual security gates, and the OpenCode plugin and the OMP extension run them through hook-dispatch --team-hooks for the project the session is in, in project and self mode. A hook's stderr, a blocking exit 2 and a timeout are reported on both hosts. The TOOLS entries and the generated tool-support pages mark both adapters as running team hooks.

Closes Tencent#1492
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
…ent#1515)

* feat(hooks): run team hooks for tools whose hosts cannot read a hook file

OpenCode, OMP, Pi, Kiro, Hermes and OpenClaw got teamai's built-in bridge
but never the team's hooks/hooks.yaml entries: their adapters were
reconciled without the team defs. Each now gets a Claude-shaped file of its
own (~/.teamai/team-hooks/<tool>.json), written by the same reconcile,
records and project gates as a settings file, and a shared runner
(hook-dispatch <Event> --tool <tool> --team-hooks) that runs it as Claude
Code would and answers in the shape the host reads.

The runner that spawns one hook command now lives in hook-command.ts and is
shared with the Codex dispatcher and CodeBuddy's Windows gate.

Proved by bridged-team-hooks.test.ts (pull writes the file, the runner
blocks a force push and leaves a plain push) and the hook, adapter,
uninstall and doctor suites.

* feat(hooks): hook-dispatch --team-hooks runs a bridged tool's team hooks

The bridge of OpenCode, OMP, Pi, Kiro, Hermes or OpenClaw calls
hook-dispatch <Event> --tool <tool> --team-hooks with the host payload;
the command prints the runner's reply and exits with its code.

Proved with the built CLI: an OMP bash call to rm -rf gets
{"block":"No rm -rf here: use the clean script"}, ls gets nothing.

* feat(omp): the OMP extension runs the team's hooks

A PreToolUse team hook blocks the tool call it refuses (tool_call), what a
SessionStart or UserPromptSubmit hook prints joins the system prompt, and the
PostToolUse and Stop hooks run with the event's payload. The extension starts
no teamai process for an event the team has no hook on, and gives up after
25 s, below OMP's 30 s limit past which it blocks the tool call.

Proved in omp-hooks.test.ts with the generated extension on a fake host.

* feat(pi): the Pi extension runs the team's hooks

Pi was told it supports built-in lifecycle hooks only and skipped every team
hook. Its extension now runs them through the shared bridge: a PreToolUse
hook blocks the call on tool_call (which fires before the tool, unlike
tool_execution_start), SessionStart and UserPromptSubmit context joins the
run's system prompt, and PostToolUse and Stop hooks run with their payload.

Proved in pi-hooks.test.ts with the generated extension on a fake host.

* feat(opencode): the OpenCode plugin runs the team's hooks

On V1 and V2, a PreToolUse team hook that refuses fails the tool call from
tool.execute.before (OpenCode hands the model the error), SessionStart and
UserPromptSubmit context joins the system prompt (V1's system transform,
V2's context hook, which waits for the session's SessionStart run), and
PostToolUse and Stop hooks run with their payload. The plugin's header no
longer claims OpenCode cannot take a hook's output.

Proved in opencode-hooks.test.ts with the generated plugin on fake V1 and V2
hosts.

* feat(kiro): Kiro runs the team's hooks through teamai's bridge

Kiro loads every file in ~/.kiro/hooks, so the team's hooks get their own,
teamai-team.json, beside teamai.json (which hasKiroHooks compares byte for
byte): one entry per event the team has hooks on, bounded by the longest of
their timeouts, that runs them through hook-dispatch --team-hooks. The
bridge matches each hook's matcher against Kiro's tool names and answers as
Kiro reads a hook: exit 2 with the reason on stderr blocks, stdout is context.

Proved in kiro-hooks.test.ts: pull writes the entries, and removes the file
once the team has no hooks.

* feat(hermes): Hermes runs the team's hooks through teamai's bridge

Hermes runs a hook command without a shell, matches Hermes tool names, sends
its own payload and ignores plain stdout, so the team's commands cannot go
into config.yaml as they are. Each Hermes event the team has hooks on gets
one approved entry instead, '~/.hermes/hooks/teamai-team-hooks.sh <Event>',
whose command stays the same across upgrades so its approval does: the
bridge rewrites the payload to Claude's shape (TERMINAL_CWD, the prompt),
runs the hooks through a shell, and answers in Hermes's JSON. SessionStart
runs on the first turn's pre_llm_call, since Hermes ignores what an
on_session_start hook prints.

Proved in hermes-hooks.test.ts and bridged-team-hooks.test.ts.

* feat(openclaw): a plugin runs the team's hooks in OpenClaw

OpenClaw's internal hooks (HOOK.md + handler.ts) cannot block a tool call
or add context to a prompt, so the team's hooks run from a standalone
plugin instead: ~/.openclaw/teamai/teamai-team-hooks.mjs, which teamai adds
to plugins.load.paths and enables (with conversation access, to read the
prompt) while the team has hooks for OpenClaw. before_tool_call blocks
with the PreToolUse reason, before_prompt_build prepends what SessionStart
(first prompt of a session) and UserPromptSubmit hooks print, and
after_tool_call and agent_end run PostToolUse and Stop. The handlers ask
for OpenClaw's longest timeout, since a slow before_tool_call fails closed
at 15s by default. A plugin allowlist, deny list, switched-off plugins or a
disabled entry stay as the member set them, with a warning naming the fix.

Proved in openclaw-hooks.test.ts: the plugin openclaw.json points at,
loaded as the gateway loads it, blocks and adds context through a stub
CLI; pull's reconcile installs it and removeAll takes it out.

* fix(agent-hooks): adapter tools run backend-pushed hooks through the bridge

A hook the HTTP local agent pushes for an adapter tool used to become a
generated file per hook, and none of them ran it as Claude Code would:
OpenClaw's handler inherited stdin, discarded the output and was not
awaited; Hermes got the raw command, without a shell or tool-name mapping,
on events whose output it ignores; Pi's PreToolUse ran on
tool_execution_start, which cannot block, with an exact lowercase matcher;
OpenCode refused PreToolUse and ignored the output. OMP and Kiro refused
agent hooks.

The hook now goes into the tool's bridged team-hook file, beside the
team's, under its [teamai:agent-hook:<slug>] marker, so the bridge runs
it: it blocks, matches Claude tool names and adds context in all six
tools. Kiro, Hermes and OpenClaw rewire their per-event entries after the
change. The per-hook generators are deleted; their removal functions stay,
so an uninstall still cleans what an earlier release generated.

The OpenCode e2e now proves a team hook end to end: real OpenCode 1.18.23
loads the generated plugin, and its SessionStart runs the hook from
hooks/hooks.yaml through the real CLI.

Proved in local-agent.test.ts (install, block, uninstall for each of the
six tools), the adapter suites, and npm run test:e2e --
src/__tests__/e2e/opencode-hooks.test.ts (V1 passed, V2 skipped: no
binary here).

* test(hooks): a pull keeps an agent hook in the bridged file

The bridged file holds the team's hooks and the HTTP local agent's; pull
reconciles only the team's records, so both keep blocking.

Proved in bridged-team-hooks.test.ts.

* feat(hooks): hooks list says which tools run each team hook

A team hook reaches only the tools with a hook on its event: Cursor's and
Copilot's files have no entry for some Claude events, and the bridges run
five. Nothing said so, so a PreToolUse hook looked delivered in Cursor.
Each team hook now lists the enabled tools that run it and the ones with
no hook on its event, from runsTeamHookOn, which reads the same channel and
event maps the writers use.

Proved in hooks-cmd.test.ts.

* docs(hooks): team hook examples, and where each one runs

The sharing guide now shows four team hooks a team can copy (refuse a
force push, keep shipped migrations unchanged, announce a release freeze,
format what the agent wrote), what each event can do, the hooks list view,
and the limits of the tools whose hooks run through teamai. The
troubleshooting reference explains runs in / not in. The README hooks
column is tied to TOOLS: a tick means teamai's hooks and the team's both.

Proved by running the examples, copied from sharing.md, through the built
CLI in a sandboxed HOME (hooks inject, hooks list, hook-dispatch
--team-hooks): the force push and the migration edit are blocked with the
documented reasons, the plain push and the other edit are not, and
SessionStart returns the freeze notice. readme-matrix.test.ts passes.

* fix(uninstall): remove the team hooks teamai runs for a tool

uninstall --agent <tool> left ~/.teamai/team-hooks/<tool>.json and
OpenClaw's team-hook plugin behind. They are now in the removal plan of
the tool whose adapter they serve, kept like that adapter on a project
uninstall, and kept for projects still set up when ~/.teamai goes, as the
Codex team-hook index is. The Hermes plan names the team-hook script.

Proved in uninstall.test.ts (red with the removal taken out).

* refactor(hooks): one function runs an event's bridged team hooks

runBridgedTeamHooks ran each event's hooks inline, and decisionOf read the
JSON decision inline; each now has its own function. Tests cover the
cases that had none: a JSON block without a reason, exit 2 with nothing on
stderr, a failing hook's stderr, a payload that is not JSON, Hermes's
prompt as a list of parts, and every OpenClaw plugin policy that keeps the
plugin from loading.

Proved in bridged-team-hooks.test.ts and openclaw-hooks.test.ts.

* test(hooks): pin what the team hook runner decides in edge cases

Why: mutation testing left decisions of runBridgedTeamHooks unpinned:
matcher "*" and none, the default hook id, a failing hook that prints a
deny, JSON with no decision, Hermes with no extra, and empty entries.

Proof: npx vitest run src/__tests__/bridged-team-hooks.test.ts (25 pass).

* fix(hooks): a new hook adapter fails to compile until its bridge is wired

Why: isBridgedToolInstalled ended in default false and the rewire was an
if-chain on tool names, so a seventh bridged tool would get no team-hook
file and no host entries, silently. Both now switch on the adapter id with
a never check. Pi's override warning said Pi runs built-in hooks only,
which this branch made untrue.

Proof: npx tsc --noEmit; npx vitest run hooks pi-hooks kiro hermes
openclaw local-agent (1630 pass).

* fix(hooks): a malformed team-hook file says so instead of crashing

Why: an entry with hooks: {} made the runner throw, and hook-dispatch
exits 0 on a throw, so every hook of the event was skipped with no word,
a PreToolUse block included. The file is now parsed with a zod schema at
the read; a file that does not parse runs nothing and the host gets one
line naming it and the fix. Reading the file once also lets the Hermes
first turn reuse merge instead of a second copy of it.

Proof: test seen red (TypeError: flatMap is not a function), then
npx vitest run bridged-team-hooks kiro hermes openclaw local-agent
hooks-cmd (481 pass); tsc and lint clean.

* fix(agent-hooks): a sync moves agent hooks earlier releases wrote to the bridge

Why: the fixes for OpenClaw's handler, Hermes's raw command and Pi's
non-blocking PreToolUse only reached a hook the server installed again,
and it sends no install for a hook already in place. Each sync now moves
a recorded hook for a bridged tool that its bridged file lacks: it removes
the old copy and writes it beside the team's hooks.

Proof: test seen red (the old Pi extension stayed), then npx vitest run
local-agent hooks uninstall (1869 pass); tsc clean.

* refactor(openclaw): each plugin message is one searchable literal

Why: the load and unload warnings were stitched from ternary fragments, so
the text a member sees could not be found in the source. The two new
uninstall warnings no longer cast the caught value.

Proof: npx vitest run openclaw (50 pass); tsc clean.

* fix(hooks): prompt hooks get the member's prompt, and time to run

Why: Pi and OMP fire before_agent_start for a run an extension starts,
with no prompt, so UserPromptSubmit hooks ran on nothing. OpenClaw's
prompt can hold rebuilt history, where currentUserMessage is the request.
Hermes's first turn runs SessionStart then UserPromptSubmit in one entry
but got the longer timeout, not their sum. OMP ran the team's prompt
hooks after the built-in dispatch, so both could pass its 30 s limit.

Proof: each case seen red, then npx vitest run pi-hooks omp-hooks
openclaw-hooks hermes (151 pass); tsc and lint clean.

* docs(hooks): Kiro's team-hook file, the bridge's data file, Claude's extra

Why: the reference did not name ~/.kiro/hooks/teamai-team.json, the data
layout did not record ~/.teamai/team-hooks/, and the sharing table read as
if exit 2 did nothing on UserPromptSubmit in Claude Code too.

Proof: removeKiroHooks removes both Kiro files (src/kiro-hooks.ts), hooks
remove and uninstall call it.

* docs(tools): agent hook cells name the evidence behind them

Why: the six bridged tools' agent hook cells said teamai's code only, but
each host's hook contract was read from its source (Kiro: its docs), and
OpenCode 1.18.23 ran a team hook through the bridge.

Proof: npx vitest run tool-support -u, then tool-support readme locate
(4221 pass).

* fix(uninstall): a project uninstall takes its team hooks out of the bridged file

Why: a project install gates its team hooks for a bridged tool in the
machine-wide ~/.teamai/team-hooks/<tool>.json. A project uninstall kept
the whole file, so after uninstall --agent omp the project's hooks still
ran there. The file now takes the ZCode path: the project's gated team
hooks go, the other projects' and the agent hooks stay.

Proof: test seen red (the force push was still blocked), then
npx vitest run uninstall hooks (1567 pass); tsc clean.

* fix(kiro): a team hook's matcher selects Kiro CLI V3's tool IDs

Why: the Kiro mapping knew only the 2.x and IDE names, so matcher: Bash
blocked execute_bash but let V3's shell through with the same input.
Kiro's hooks migration guide lists shell, read and write as the V3 IDs.

Proof: test seen red for shell, read, fs_read and write, then
npx vitest run bridged-team-hooks kiro (46 pass).

* fix(agent-hooks): removing one rewires only the team-hook entries

Why: installing or removing an agent hook for Kiro, Hermes or OpenClaw
reran the whole adapter injector. An uninstall removes teamai's Kiro
hooks before the agent hooks, so it wrote ~/.kiro/hooks/teamai.json
back. Each of the three now reconciles only its team-hook entries.

Proof: test seen red (teamai.json was back), then npx vitest run
uninstall local-agent hooks kiro hermes openclaw (1925 pass); tsc, lint.

* fix(hooks): the kill switch stops applied team hooks, and a timeout keeps stderr

Why: Tencent#1497's dispatcher stopped the team's applied hooks under
TEAMAI_HOOKS_DISABLED at run time and kept a timed-out hook's own stderr
after the timeout line. The bridge does both now, before OpenCode and OMP
move onto it. The local agent's hooks are not the team's and keep running.

Proof: both tests seen red, then npx vitest run bridged-team-hooks (33).

* refactor(hooks): OpenCode and OMP run team hooks from the bridged file

Why: Tencent#1497 gave OpenCode and OMP a second way to run team hooks, an index
of what pull applied and a live dispatcher, beside the bridged file the
other four adapter tools run. One way now serves all six: pull writes
~/.teamai/team-hooks/<tool>.json through the same reconcile, records and
project gates as a settings file, and the runner reads it. The index and
the dispatcher go; nothing released wrote the index.

Kept from Tencent#1497, now on the bridge: OpenCode, OMP and Pi build the system
prompt for each request, so SessionStart runs at the session's start for
the first request and again before each later one, and a prompt hook's
change (ponytail's level, Tencent#1492) shows on the next turn; a
hook's stderr reaches the host's console; self mode delivers to the
business repo and nowhere else. HookAdapter.teamHooks goes: every hook
adapter runs the team's hooks now.

Proof: Tencent#1497's behaviours as tests on the bridge (per-turn SessionStart
for OpenCode, OMP and Pi; stderr on each host's console; self mode in and
outside the project); the per-turn and stderr ones seen red, the self-mode
one passed on the bridge as it came; npx vitest run hooks omp
opencode pi- team tools tool-support readme bridged uninstall local-agent
kiro hermes openclaw commands-reference (2280 pass); tsc and lint clean;
npm run test:e2e -- src/__tests__/e2e/opencode-hooks.test.ts against real
OpenCode 1.18.23 runs the team's SessionStart hook.

* fix(hooks): a team hook's stderr reaches the host whatever its exit

Why: the runner passed stderr on only for a hook that failed or timed out.
A UserPromptSubmit hook that refuses with exit 2 cannot block the prompt
on a bridged host, so its reason was lost; Tencent#1497 showed every hook's
stderr. Each hook's stderr now goes to the host, except a PreToolUse
block's, which already arrives once as the block's reason.

Proof: three tests seen red (a successful hook's note, Stop's and
UserPromptSubmit's exit 2 reasons), then npx vitest run
bridged-team-hooks kiro hermes omp opencode pi- local-agent (660 pass).

* test(hermes): expect the Windows quoting Hermes needs for the team-hook script

Why: the Windows CI job failed. The test expected POSIX single quotes, but
the team-hook entry reuses reportCommand, which double-quotes the script
path on Windows because Hermes tokenizes the command itself.

What: the expectation follows the same per-platform rule.

Proof: npx vitest run src/__tests__/hermes-hooks.test.ts (11 passed);
npx tsc --noEmit clean.

* test(opencode): compare the V2 plugin with the one built for the machine's HOME

Why: the fork-safe E2E shard failed. The generated plugin now names the
team-hook file under ~/.teamai, and the test built its expected copy
under the test process's HOME instead of the sandbox machine's.

What: the expected plugin is built with HOME set to the machine's home.

Proof: npx vitest run --config vitest.e2e.config.ts
src/__tests__/e2e/opencode-versions-915.test.ts -t 'rewrites a plugin
from an older build' failed before (TEAM_HOOKS_FILE path differs) and
passes after.

* fix(openclaw): a team hook's stderr reaches OpenClaw's console

Why: the OpenClaw team-hook plugin spawned hook-dispatch with stderr
ignored, so a failing formatter or a timeout notice never showed, while
OpenCode, OMP and Pi forward it. A plugin whose own timeout fires before
the child closes also printed the same stderr twice on Pi and OpenCode.

What: the OpenClaw plugin pipes the dispatcher's stderr to console.error,
as the Pi and OpenCode ones do. All three clear what they printed, so a
second finish prints nothing.

Proof: the new openclaw-hooks test (a Stop hook's stderr reaches
console.error) failed with 0 calls before and passes after;
npx vitest run on the openclaw, pi and opencode hook tests passes.

* fix(hooks): every hook's stderr shows, on Hermes too

Why: two gaps in forwarding a team hook's stderr. When two PreToolUse
hooks blocked, the runner dropped the stderr of every exit-2 hook while
only the first one's reason reached the host, so the other hook's
message was lost. Hermes logs a shell hook's stderr only at DEBUG when
the hook exits 0, which every bridged reply did, so a failing
PostToolUse formatter was invisible at normal verbosity.

What: the runner holds back stderr only for the run whose block it
returns. A Hermes reply that carries stderr exits 1: Hermes then logs
it as a warning and still parses the decision JSON on stdout, and exit 1
blocks nothing. Other hosts keep exit 0. Kiro also shows stderr only for
a nonzero exit, but a nonzero exit there drops stdout and, in the IDE,
blocks the call, so Kiro is left as it is.

Proof: two new bridged-team-hooks tests (two blocking hooks; Hermes
exit 1 with stderr) failed before and pass after. Hermes's evaluator
(agent/shell_hooks.py _evaluate_result, v2026.9.24) warns with stderr
for a nonzero non-2 exit and then parses stdout.
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.

[feat] Run custom team hooks (hooks/hooks.yaml) on OpenCode and OMP

3 participants