Repository navigation
feat(hooks): run project team hooks on OpenCode and OMP (#1492) - #1497
Conversation
|
Findings
Testing |
47562cd to
2c41218
Compare
|
Findings
All four earlier findings remain unresolved in the current diff. Testing |
SaulMoro
left a comment
There was a problem hiding this comment.
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.tsreads the team'shooks/hooks.yamldirectly instead of going throughresolveTeamHooks. On OpenCode and OMP, the controls indocs/guide/sharing.md:196-203stop working:TEAMAI_HOOKS_DISABLED=1still runs the hooks.- With
sharing.hooks.autoApply: false,pullsays the hooks are pending, but they run. - With
requireTeamScripts,pullreports 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
pulland no "Applying" listing. Claude's settings only get it after apullon that branch.
Please resolve the hooks the way the other tools do, so what runs here is what
pullapplied. -
[P1 blocking] On OpenCode 2.x, hook output never reaches the model. The plugin's V2
setuppath never registersexperimental.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 V2ctx.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" writesoff), every request after the stop still carriesRULESET(level=full), andPONYTAIL_STOPPEDshows 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 withBLOCKED_REASONis 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). teamContextin 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.
- A successful hook's stderr is dropped (
-
[P3 nit] Every bridged event now starts a second node process, about 80 ms each, even for teams with no
hooks.yaml.chat.messageandtool.execute.afterare 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.
2c41218 to
5cd6280
Compare
|
Findings
All four earlier findings remain unresolved in the current diff. Testing |
61469e7 to
5c816f5
Compare
|
Findings
Earlier Findings Testing |
@Walternater Thanks, this is a big step. We reran the earlier fixtures on
A successful hook's stderr now comes through, and Two things still block approval:
Build, |
|
@SaulMoro the three blocking findings are addressed on
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.
|
@Walternater Thanks. Our comment above, from just before yours, confirms those three are fixed on
|
5c816f5 to
16dcce2
Compare
|
@SaulMoro both remaining items are fixed on
CI is running on |
|
Findings
Earlier Findings Testing |
16dcce2 to
cc2731a
Compare
|
Findings
Earlier Findings Testing |
@Walternater Thanks. On
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, |
cc2731a to
b81e7a2
Compare
|
Both P2 findings are addressed on
CI is running on |
@Walternater Thanks. On The P1 from the comment above, posted just before your reply, still stands on this head, since the |
|
Findings
Earlier Findings Testing |
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.
b81e7a2 to
2651b27
Compare
|
CI on
|
|
Findings
Earlier Findings Testing |
@Walternater Thanks. On Two small items from the CI review are left. Both reproduce and both fit this PR, so they block approval:
Non-blocking: in self mode, Build, |
|
@SaulMoro the last self-mode P1 is addressed on |
|
Findings Earlier Findings Testing I only read the specified diff and trusted base review criteria; I did not run, build, or install PR code. |
|
@SaulMoro |
SaulMoro
left a comment
There was a problem hiding this comment.
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
TOOLSnow hasteamHooks: true, and both generated tool-support pages showopencode-plugin incl. team hooks. A timed-out hook's own stderr now follows the timeout line. A test covers each. - Self mode. On
2651b27c, afterinit --selfandpull, 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.f2c39b75doesn't touch that path. - Checks. On a merge of this head with main (after the oxlint change in #1414), lint,
tscand 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.
…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).
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.
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).
…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).
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.
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).
…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).
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.
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).
* 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.
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
…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.
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'shooks/hooks.yamlentries never run there: the adapterscontinuebefore the settings path and never receiveteamDefs, and the generated bridges callhook-dispatch …without--team-hooks(which only ran a Codex dispatcher). The README matrix'shooks ✓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.
reconcileHooksToAllToolsnow records the team hooks it applied for OpenCode and OMP — afterresolveTeamHooks' security gates — in~/.teamai/team-hook-bridges.json, keyed byuseror the shared project anchor.teamai hook-dispatch <event> --tool <tool> --team-hooksthen:cwd(project over user);TEAMAI_HOOKS_DISABLEDat 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 removeclears the record);projectRoot; its business repo is the project key, soinit --self+pullrecords the applied hooks there too (and a self-mode user config records them underuser);Bashmatching the host'sbash;exit 2as the blocking decision;hookSpecificOutput.additionalContextwhen 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 throughexperimental.chat.system.transform, V2 through thectx.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 inbefore_agent_starteach turn, appending their output tosystemPrompt. It awaits the Bun shell call (ShellOutput) and reads itsexitCode/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: trueinTOOLS, and the generated tool-support pages sayincl. team hooksfor 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).src/__tests__/team-hooks-dispatch.test.ts— 6 passed: applied-only hooks, event/tool filtering, stdout pass-through, exit 2 + stderr, case-insensitive matcher, JSONadditionalContext, a hook declared inhooks.yamlbut not applied runs nothing, and the kill switch stops an applied hook.opencode-hooks.test.ts— 62 passed, including the V2session.contextregistration receiving team output and the V1 transform running SessionStart per request.omp-hooks.test.ts— 30 passed, including team output inbefore_agent_start'ssystemPrompt.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 awaitableShellOutput(text()/exitCode/stderr).hooks-reconcile-scope.test.ts— including a self-mode case that asserts the bridge record is written forinit --self+pull.tool-support.test.ts— the regenerated English and Chinese pages match the updatedTOOLSdescriptor.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):(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.