Repository navigation
feat(hooks): locate each tool's hooks from the descriptor, so hooks follow a moved home (#1221) - #1405
Conversation
Code Erosion ReportInformational — never blocks the merge.
Scanned 480 files / 106709 SLOC · high-CC functions 839/9478 * On TypeScript, Rule hits (TS verbosity layer)Standalone
70 distinct lines flagged across |
The PR description documents sufficient real-CLI verification at |
|
Fixed in b03008b. Pull now clears the default-home copy before it writes the moved one, judged by the records the moved pass then replaces. So a changed team hook no longer leaves the old one there unowned. This covers CodeBuddy and Muse settings and Pi's extension, as it already did OpenCode's plugin. A default home linked to the moved one is left alone. Real-CLI e2e: |
The earlier successful-migration scenario is resolved by cleaning the default copy before replacing its records; the failure path above remains. The PR description documents sufficient real-CLI verification at |
|
Fixed in ce25ac1. A default-home copy that cannot be cleaned now stops that tool's pass. The pull warns |
|
No new findings in the specified diff.
I only read the specified diff. I did not run, build, or install PR code. |
ce25ac1 to
cc2b9a7
Compare
|
No new findings in the specified diff.
I only read the specified diff. I did not run, build, or install PR code. |
cc2b9a7 to
dd28a11
Compare
|
No new findings in the specified diff.
I only read the specified diff. I did not run, build, or install PR code. |
dd28a11 to
c9bbc31
Compare
|
No new findings in the specified diff.
I only read the diff and trusted base review criteria. I did not run, build, or install PR code. |
c9bbc31 to
d1d58f0
Compare
|
No new findings in the specified diff.
I only read the specified diff and trusted base review criteria. I did not run, build, or install PR code. |
d1d58f0 to
cc3e973
Compare
3baa04a to
a2904fe
Compare
|
No new findings in the specified diff.
I only read the specified diff and base review criteria. I did not run, build, or install PR code. |
a2904fe to
c168d34
Compare
c168d34 to
cd0f3b3
Compare
Each built-in tool now names, for the user scope and for self mode, how teamai installs its hooks: entries in a settings file with the shape of its hook list, a file of teamai's own its adapter writes (OpenCode's plugin, Pi's and OMP's extension, Hermes, OpenClaw, dsh), 'none' or 'unknown'. Leaving it out fails tsc (tools.type-test.ts). hooks.ts takes each tool's hook shape from the descriptor (hookFormatOf) instead of its own tool sets; a test pins it to the table it replaced.
locate(tool, 'hooks') answers with the hook list of the tool's hook file, in its shape, or the directory its adapter writes teamai's file into. A workspace takes the user hooks; self mode takes the project's, except for a tool that reads its user hooks there too (ZCode's CLI, every adapter). A user hook file follows the tool's moved home, and the default home's is retired for the four tools whose earlier releases wrote there. hookSettingsFile and hookAdapterDir give the writers the same answer. No writer uses them yet. The matrix states every tool in the user scope, a workspace and self mode, with the moved homes.
…hem (#1221) Hook writers took a fixed default-home path, so a tool whose home moved (CODEBUDDY_CONFIG_DIR, CODEX_HOME, OPENCODE_CONFIG_DIR, XDG_CONFIG_HOME, PI_CODING_AGENT_DIR) got hooks in a file it never reads. Settings writers now take the file from hookSettingsFile, and the Pi, OMP, OpenCode and dsh adapters take their directory from hookAdapterDir; both sit beside locate's hooks resolver and share its toolHome. Uninstall checks the moved file and the default-home copy earlier releases wrote, and the OpenCode and Pi adapter dirs locate retires. Pull leaves the default-home copy in place, as it does for skills; the tool does not read it.
…home (#1221) Hooks now follow a moved home, so nothing teamai writes for Pi, CodeBuddy, OpenCode or Muse stays under the default one, and doctor's "still writes some of its other files under" notes were wrong. The descriptor flag behind them is renamed to defaultHomeLeftovers: it now only says where earlier releases left hooks and MCP servers, which uninstall and MCP ownership still look for.
…r release wrote (#1221) A tool reads its default home again once the member unsets the variable that moved it, so the hooks an earlier release left there would fire after `hooks remove`. It now sweeps the places locate retires: the settings file, with the team's hook history to find team entries whose records went with the moved copy, and the OpenCode plugin and Pi extension directories. The e2e test runs the real CLI with CODEBUDDY_CONFIG_DIR and XDG_CONFIG_HOME set: hooks inject writes the moved homes, and uninstall and hooks remove clear both copies.
…d covers both copies (#1221) A Muse team hook carries no marker, so only its manifest record names it, and an HTTP-backed team has no hook history to fall back on. Cleaning the moved file first consumed that record and left the team hook in the default-home copy. That copy now goes first with keepRecords, and the moved file's pass consumes the records.
…nnel, not on ZCode (#1221) A project install of a tool that keeps its user hooks reads them from HOME, so it owns only its gated team hooks there. reconcileHooksToAllTools and uninstall's HOME target named ZCode for this; they now read hooks.self === 'user', as hookSettingsFile already does.
…in the default home (#1221) OpenCode 1.x loads the default config dir's plugins beside OPENCODE_CONFIG_DIR's and dedupes them by file URL, so the copy an earlier release wrote there and the moved one both ran, firing every event twice. Pull already deletes a project-scope copy for the same reason.
…me (#1221) Withdrawing an OpenCode or Pi agent hook removed only the moved copy, so the one an earlier release wrote under the default home ran again once the home stopped moving. Removal now clears both. Writing an OpenCode agent hook also removes the earlier copy, which OpenCode 1.x loads beside the moved one.
…same or fails (#1221) A default home linked to the moved one is the same directory, so pull no longer deletes the plugin it just wrote through the link. And when the default-home copy cannot be cleaned, the moved copy's pass leaves the records, so a retry after repairing the file still finds the team hook.
… tool's default home (#1221) The default-home copy was left as it was, so once the team changed a hook, the moved file's pass replaced its record and the old Muse team hook stayed in that copy with nothing to name it for removal. Pull now clears the copy first, judged by the records the moved pass then replaces, for CodeBuddy and Muse settings and Pi's extension as already for OpenCode's plugin. A copy that is the moved file through a link is left alone.
…me copy cannot be cleaned (#1221)
…mai init recorded (#1221)
…use and CodeBuddy Each test records a moved home, then runs pull or hooks inject, hooks list and hooks remove through the built CLI with the variable unset, so the recorded home alone decides where the hooks go. The OpenCode case also checks that the plugin reads the user context from the moved home. All four fail on main and pass here. They come from #1368, #1369, #1370 and #1371, which this branch replaces. Co-authored-by: Nathan Shan <[email protected]>
|
No new findings in the specified diff.
I only read the specified diff and trusted base review criteria. I did not run, build, or install PR code. |
cd0f3b3 to
93e54f8
Compare
|
No new findings in the specified diff.
I only read the specified diff and base review criteria. I did not run, build, or install PR code. |
jeff-r2026
left a comment
There was a problem hiding this comment.
Reviewed with an independent agent pass plus local verification, merged with #1406 onto main 43b1bbc: tsc, lint, build pass; the 19 changed unit test files 1446/1446; related E2E 17 passed (1 skipped: OpenCode binary not installed). Real CLI upgrade path: hooks written to the default CodeBuddy home by main, then hooks inject with CODEBUDDY_CONFIG_DIR moves them (default copy cleared, member's own hooks and settings kept), re-inject is idempotent, hooks remove clears both and exits 0. Earlier Codex Muse ownership findings confirmed fixed in code. Non-blocking notes: a model switch made under an older release into ~/.claude while toolRoots.claude is recorded makes uninstall stop with 'model restoration is incomplete' — worth a release note.
…ollow a moved home (Tencent#1221) (Tencent#1405) * feat(tools): state every tool's hook channel in the descriptor (Tencent#1221) Each built-in tool now names, for the user scope and for self mode, how teamai installs its hooks: entries in a settings file with the shape of its hook list, a file of teamai's own its adapter writes (OpenCode's plugin, Pi's and OMP's extension, Hermes, OpenClaw, dsh), 'none' or 'unknown'. Leaving it out fails tsc (tools.type-test.ts). hooks.ts takes each tool's hook shape from the descriptor (hookFormatOf) instead of its own tool sets; a test pins it to the table it replaced. * feat(locate): locate each tool's hooks from the descriptor (Tencent#1221) locate(tool, 'hooks') answers with the hook list of the tool's hook file, in its shape, or the directory its adapter writes teamai's file into. A workspace takes the user hooks; self mode takes the project's, except for a tool that reads its user hooks there too (ZCode's CLI, every adapter). A user hook file follows the tool's moved home, and the default home's is retired for the four tools whose earlier releases wrote there. hookSettingsFile and hookAdapterDir give the writers the same answer. No writer uses them yet. The matrix states every tool in the user scope, a workspace and self mode, with the moved homes. * fix(hooks): write and remove hooks where locate says the tool reads them (Tencent#1221) Hook writers took a fixed default-home path, so a tool whose home moved (CODEBUDDY_CONFIG_DIR, CODEX_HOME, OPENCODE_CONFIG_DIR, XDG_CONFIG_HOME, PI_CODING_AGENT_DIR) got hooks in a file it never reads. Settings writers now take the file from hookSettingsFile, and the Pi, OMP, OpenCode and dsh adapters take their directory from hookAdapterDir; both sit beside locate's hooks resolver and share its toolHome. Uninstall checks the moved file and the default-home copy earlier releases wrote, and the OpenCode and Pi adapter dirs locate retires. Pull leaves the default-home copy in place, as it does for skills; the tool does not read it. * fix(doctor): drop the note that teamai writes under a tool's default home (Tencent#1221) Hooks now follow a moved home, so nothing teamai writes for Pi, CodeBuddy, OpenCode or Muse stays under the default one, and doctor's "still writes some of its other files under" notes were wrong. The descriptor flag behind them is renamed to defaultHomeLeftovers: it now only says where earlier releases left hooks and MCP servers, which uninstall and MCP ownership still look for. * fix(hooks): hooks remove also clears the default-home hooks an earlier release wrote (Tencent#1221) A tool reads its default home again once the member unsets the variable that moved it, so the hooks an earlier release left there would fire after `hooks remove`. It now sweeps the places locate retires: the settings file, with the team's hook history to find team entries whose records went with the moved copy, and the OpenCode plugin and Pi extension directories. The e2e test runs the real CLI with CODEBUDDY_CONFIG_DIR and XDG_CONFIG_HOME set: hooks inject writes the moved homes, and uninstall and hooks remove clear both copies. * docs: hooks follow a moved OpenCode, Muse, Pi and CodeBuddy home (Tencent#1221) * fix(hooks): clear the default-home copy first, so one team-hook record covers both copies (Tencent#1221) A Muse team hook carries no marker, so only its manifest record names it, and an HTTP-backed team has no hook history to fall back on. Cleaning the moved file first consumed that record and left the team hook in the default-home copy. That copy now goes first with keepRecords, and the moved file's pass consumes the records. * refactor(hooks): key HOME-hook ownership on the descriptor's self channel, not on ZCode (Tencent#1221) A project install of a tool that keeps its user hooks reads them from HOME, so it owns only its gated team hooks there. reconcileHooksToAllTools and uninstall's HOME target named ZCode for this; they now read hooks.self === 'user', as hookSettingsFile already does. * fix(hooks): pull removes the OpenCode plugin an earlier release left in the default home (Tencent#1221) OpenCode 1.x loads the default config dir's plugins beside OPENCODE_CONFIG_DIR's and dedupes them by file URL, so the copy an earlier release wrote there and the moved one both ran, firing every event twice. Pull already deletes a project-scope copy for the same reason. * fix(hooks): an agent hook leaves no copy in a moved tool's default home (Tencent#1221) Withdrawing an OpenCode or Pi agent hook removed only the moved copy, so the one an earlier release wrote under the default home ran again once the home stopped moving. Removal now clears both. Writing an OpenCode agent hook also removes the earlier copy, which OpenCode 1.x loads beside the moved one. * fix(hooks): keep a moved tool's hooks and records when a copy is the same or fails (Tencent#1221) A default home linked to the moved one is the same directory, so pull no longer deletes the plugin it just wrote through the link. And when the default-home copy cannot be cleaned, the moved copy's pass leaves the records, so a retry after repairing the file still finds the team hook. * fix(hooks): pull removes the hooks an earlier release left in a moved tool's default home (Tencent#1221) The default-home copy was left as it was, so once the team changed a hook, the moved file's pass replaced its record and the old Muse team hook stayed in that copy with nothing to name it for removal. Pull now clears the copy first, judged by the records the moved pass then replaces, for CodeBuddy and Muse settings and Pi's extension as already for OpenCode's plugin. A copy that is the moved file through a link is left alone. * fix(hooks): keep a moved tool's hooks and records when its default-home copy cannot be cleaned (Tencent#1221) * fix(models): models switch writes into the Claude and Codex roots teamai init recorded (Tencent#1221) * fix(hooks): hooks remove exits 1 when it leaves hooks behind, as uninstall does (Tencent#1221) * fix(hooks): write settings and agent hooks only through a channel the tool reads (Tencent#1221) * test(hooks): cover recorded tool homes end to end for Pi, OpenCode, Muse and CodeBuddy Each test records a moved home, then runs pull or hooks inject, hooks list and hooks remove through the built CLI with the variable unset, so the recorded home alone decides where the hooks go. The OpenCode case also checks that the plugin reads the user context from the moved home. All four fail on main and pass here. They come from Tencent#1368, Tencent#1369, Tencent#1370 and Tencent#1371, which this branch replaces. Co-authored-by: Nathan Shan <[email protected]> * feat(tools): state Kiro's standalone hook file as its hook channel (Tencent#1221) Tencent#1341 moved Kiro's session-start hook to ~/.kiro/hooks/teamai.json, which Kiro CLI V3 loads for every agent. The descriptor still said Kiro takes no hooks. It now names the file as a hook adapter, and kiroHookFile takes its directory from locate, as the other adapters do. --------- Co-authored-by: Nathan Shan <[email protected]>
Summary
This PR is step B4 of #1221. It builds on #1404 (step F), which has merged. Each tool's hook channel is part of its descriptor, and every hook writer takes its file or directory from
locate, so hooks follow a moved home.The channel is required on every descriptor. Removing it, or giving an adapter tool a project channel, fails
tsc(tools.type-test.ts).HooksChannels.selfreplaces the ZCode special case, in the paths and in who owns the HOME file in a project install. ZCode, and every adapter tool, take their user hooks in self mode too.Hooks now land where the tool reads them:
CODEBUDDY_CONFIG_DIR=/x~/.codebuddy/settings.json/x/settings.jsonXDG_CONFIG_HOME=/x,OPENCODE_CONFIG_DIR~/.config/opencode/plugin/x/opencode/plugin, or$OPENCODE_CONFIG_DIR/pluginXDG_CONFIG_HOME=/x(Muse)~/.config/muse/settings.json/x/muse/settings.jsonPI_CODING_AGENT_DIR=/x~/.pi/agent/extensions/x/extensionsEarlier releases wrote these four tools' hooks under the default home. The tool does not read that copy.
pull,hooks injectOPENCODE_CONFIG_DIR's and dedupes them by file URL only, so both copies would fire. And once the team changes a hook, the moved copy's pass replaces its record, which would leave the old team hook in the default copy with nothing to name ithooks removeuninstalllocate'sretired)All three clean the default-home copy first and leave the manifest records for the moved copy's pass. If the default-home copy fails, the moved copy's pass leaves them too, so a retry after the member repairs the file still removes the team hook. A default home linked to the moved one is the same directory, and nothing is removed through the link. A Muse team hook (Codex format) carries no marker, and an HTTP-backed team has no hook history, so the records are the only thing that names it in either copy. An OpenCode or Pi agent hook the local agent withdraws goes from both homes.
Doctor dropped its "teamai still writes some of its other files under " notes, because nothing stays there now. The descriptor flag behind them is renamed
defaultHomeLeftovers. It now only names where earlier releases left hooks and MCP servers, which uninstall and MCP ownership still look for.This supersedes #1368, #1369, #1370 and #1371. They fixed the same moved homes one tool at a time. Their review findings are covered here:
defaultHomeLeftovers).e2e/zcode-self-hooks.test.ts).uninstallandhooks removeclear the default-home hooks.e2e/{pi-relocated-extensions,opencode-relocated-hooks,muse-relocated-hooks,codebuddy-relocated-hooks}.test.ts). Each records a moved home and runs the CLI with the variable unset, and the OpenCode one also reads the user context from the moved home. All four fail on main and pass here.This PR also closes three #1221 follow-ups that touch the same writers, and states the hook file #1341 gave Kiro:
models switch/restoreCLAUDE_CONFIG_DIR/CODEX_HOMEonly. A shell without the variable switched~/.claude/settings.jsoneven whenteamai initrecorded~/.claude-worktoolRoots(the configpullpasses, elseresolveMemberToolRoots), else the default. Resolved once per operation. A switch recorded for another file is skipped with a message that names both files and the shell to restore fromhooks removeexituninstalldoestoolPathssettings entry still got Claude-format hooks.install_hook_ruleaccepted Copilot, ZCode, OMP, dsh, JoyCode, Kiro and Trae, then wrote a format they do not readisAgentHookSupportedTooldecides from the channel through two exhaustive tables, so a new format or adapter failstscuntil decided.uninstall_hook_ruleacts on the tool the hook was installed for, whatever tool runs it~/.kiro/hooks/teamai.json, which Kiro CLI V3 loads for every agent, but the descriptor said Kiro takes no hooksTOOLS.kiro.hooksnames the file as thekiro-hooksadapter, andkiroHookFiletakes its directory from locate, as the Pi, OMP and OpenCode adapters doEvidence
Before:
e2e/moved-home-hooks-1221.test.tsagainst the F build (a443f10), real CLI: withCODEBUDDY_CONFIG_DIRandXDG_CONFIG_HOMEset,teamai hooks injectfails atexpect(hasTeamaiHooks(movedSettings)).toBe(true)(line 52): the hooks went to~/.codebuddy/settings.json.After:
npm run test:e2eat ce25ac1, real CLI:locate-hooks.test.tsruns 469 matrix cells over every tool: default, env, recorded and workspace homes, self scope (Qoder'scwdOnlyread is reported as unread from a project subdirectory), and the retired default-home entry. A seeded wrong row failed 10 cells.Unit uninstall tests for CodeBuddy settings, the OpenCode plugin and the Pi extension under a moved home. All three failed with the retired directories dropped from discovery.
uninstall --force/hooks removeclear a Muse team hook from both homes for an HTTP-backed team (real CLI): before the records fix, the default-home copy keptecho company-check(moved-home-hooks-1221.test.ts:110).hooks injectwithOPENCODE_CONFIG_DIRand an earlier~/.config/opencode/plugin/teamai-hooks.tsleaves one plugin (real CLI), and so does Pi's extension withPI_CODING_AGENT_DIR; both failed before the fix.A Muse team hook changed after the move, then
hooks injectandhooks remove, leaves neither copy holding the old hook (real CLI); before the fix the default copy kept it. When that default copy does not parse, the pull warns and leaves the moved copy and its records for the retry; before that fix the retry left the old hook behind. Agent-hook unit tests for OpenCode and Pi failed with the fix reverted.models switchwithtoolRoots.claude: ~/.claude-workrecorded and noCLAUDE_CONFIG_DIRin the shell (real CLI, sandbox HOME):Before, the switch wrote
~/.claude/settings.json.model-switch.test.tsalso covers a switch an earlier release recorded under the default root: it is skipped with both paths named, andrestorefrom a shell withCLAUDE_CONFIG_DIR=~/.claudeundoes it.hooks removeexits 1 without the success line when the moved copy's default-home file fails (moved-home-hooks-1221.test.ts, real CLI) or the legacy project sweep leaves hooks (hooks-cmd.test.ts).hooks.test.tswrites no settings hooks for a tool whose channel names none and still removes what an earlier release left there.local-agent.test.tsuninstalls a CodeBuddy agent hook from an OMP session.locate-hooks.test.tsresolves Kiro's hooks to~/.kiro/hooks, ande2e/kiro-standalone-hooks.test.ts(from fix(kiro): use standalone V3 session-start hooks #1341, real CLI) passes withkiroHookFilegoing through locate.At 1a2daea:
npx tsc --noEmit,npm run lintandnpm run buildpass, andnpx vitest runpasses 17191 tests in 579 files (21 skipped).npm run test:e2eover the hook, model and session files (12 files, withinstalled-launcher-readinessfrom fix(doctor): accept live hook launchers from another CLI installation #1409) passes 86 tests, including the real OpenCode run against 1.x (the dev dependency) and 2.1.2 (TEAMAI_OPENCODE_V2_BIN).Merge Danger
Door: two-way
Reverting puts the writers back on the default home. The moved-home files this release wrote would stay until the member removes them.
Blast Radius: hooks
On the first
pullafter the upgrade, a member with a moved CodeBuddy, OpenCode, Muse or Pi home gets the hooks the tool reads. If that member had copied the default-home settings into the moved home by hand, teamai's entries are added beside theirs. Members with no moved home see no path change.