Skip to content

feat(hooks): locate each tool's hooks from the descriptor, so hooks follow a moved home (#1221) - #1405

Merged
jeff-r2026 merged 18 commits into
mainfrom
saulmoro/1221-hooks-locate
Oct 27, 2026
Merged

jeff-r2026 merged 18 commits into
mainfrom
saulmoro/1221-hooks-locate

Conversation

@SaulMoro

@SaulMoro SaulMoro commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

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.

 TOOLS[tool].hooks
+  user: settings { format, reads } | adapter { adapter, evidence } | 'none' | 'unknown'
+  self: settings { format, reads } | 'user' | 'none' | 'unknown'

 locate(tool, 'hooks', install)
+  settings: own = the settings entry, format, reads
+  adapter:  own = the adapter directory
+  retired:  the default-home copy, when the home moved

 writers
-  hookSettingsPath (types.ts), resolvePiExtensionsDir, resolveOmpExtensionsDir,
-  resolveDshHooksDir, '~/.config/opencode/plugin' joins
+  hookSettingsFile, hookAdapterDir (locate.ts, on toolHome)
-  detectFormat, CURSOR_TOOLS, CODEX_FORMAT_TOOLS, ZCODE_TOOLS (hooks.ts)
+  hookFormatOf (tools.ts)

The channel is required on every descriptor. Removing it, or giving an adapter tool a project channel, fails tsc (tools.type-test.ts). HooksChannels.self replaces 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:

Home moved by Before After
CODEBUDDY_CONFIG_DIR=/x ~/.codebuddy/settings.json /x/settings.json
XDG_CONFIG_HOME=/x, OPENCODE_CONFIG_DIR ~/.config/opencode/plugin /x/opencode/plugin, or $OPENCODE_CONFIG_DIR/plugin
XDG_CONFIG_HOME=/x (Muse) ~/.config/muse/settings.json /x/muse/settings.json
PI_CODING_AGENT_DIR=/x ~/.pi/agent/extensions /x/extensions

Earlier releases wrote these four tools' hooks under the default home. The tool does not read that copy.

Command Default-home copy
pull, hooks inject removed, before the moved copy is written. OpenCode 1.x loads the default config dir's plugins beside OPENCODE_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 it
hooks remove removed, so no hook fires once the member unsets the variable
uninstall removed, with the moved copy (locate's retired)

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:

  • The lookup for MCP servers an earlier release wrote to the default home stays (defaultHomeLeftovers).
  • ZCode keeps its hooks in HOME in self mode (e2e/zcode-self-hooks.test.ts).
  • uninstall and hooks remove clear the default-home hooks.
  • Their end-to-end tests come over as they are (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:

Area Before After
models switch / restore Claude and Codex settings came from CLAUDE_CONFIG_DIR / CODEX_HOME only. A shell without the variable switched ~/.claude/settings.json even when teamai init recorded ~/.claude-work The shell's variable, else the scope's recorded toolRoots (the config pull passes, else resolveMemberToolRoots), 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 from
hooks remove exit Printed success and exited 0 when a file could not be written or parsed, including the legacy project sweep Exits 1 and names the tools left, as uninstall does
Hook channel gating JoyCode, Kiro, Trae and Trae CN read no settings hooks, but a team toolPaths settings entry still got Claude-format hooks. install_hook_rule accepted Copilot, ZCode, OMP, dsh, JoyCode, Kiro and Trae, then wrote a format they do not read No settings hooks are written for a tool whose channel names none, and removal still cleans what an earlier release wrote. isAgentHookSupportedTool decides from the channel through two exhaustive tables, so a new format or adapter fails tsc until decided. uninstall_hook_rule acts on the tool the hook was installed for, whatever tool runs it
Kiro hooks #1341 writes ~/.kiro/hooks/teamai.json, which Kiro CLI V3 loads for every agent, but the descriptor said Kiro takes no hooks TOOLS.kiro.hooks names the file as the kiro-hooks adapter, and kiroHookFile takes its directory from locate, as the Pi, OMP and OpenCode adapters do

Evidence

  • Before: e2e/moved-home-hooks-1221.test.ts against the F build (a443f10), real CLI: with CODEBUDDY_CONFIG_DIR and XDG_CONFIG_HOME set, teamai hooks inject fails at expect(hasTeamaiHooks(movedSettings)).toBe(true) (line 52): the hooks went to ~/.codebuddy/settings.json.
    After: npm run test:e2e at ce25ac1, real CLI:

    ✓ moved-home-hooks-1221.test.ts (11 tests)
      ✓ injects into the moved homes, and uninstall also clears the default-home copies an earlier release wrote
      ✓ hooks remove also clears the default-home copies, which the tool reads again once the variable is unset
      ✓ hooks inject leaves one OpenCode plugin, so OpenCode 1.x does not fire every event twice
      ✓ hooks inject moves the Pi extension out of the default home
      ✓ hooks inject keeps the OpenCode plugin when the default config dir is a link to OPENCODE_CONFIG_DIR
      ✓ uninstall --force clears a Muse team hook from both homes with one record
      ✓ hooks remove clears a Muse team hook from both homes with one record
      ✓ uninstall --force keeps the record while the default-home copy fails, so a retry clears it
      ✓ hooks remove keeps the record while the default-home copy fails, so a retry clears it
      ✓ a pull after the team changes a hook leaves no unowned copy of the old one in the default home
      ✓ a pull leaves the moved hooks as they are while the default-home copy does not parse, so a retry still names the old hook
    ✓ zcode-self-hooks.test.ts (1 test)
    ✓ opencode-hooks.test.ts: real OpenCode 2.1.2 loads the CLI-generated plugin and dispatches session start once
    
  • locate-hooks.test.ts runs 469 matrix cells over every tool: default, env, recorded and workspace homes, self scope (Qoder's cwdOnly read 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 remove clear a Muse team hook from both homes for an HTTP-backed team (real CLI): before the records fix, the default-home copy kept echo company-check (moved-home-hooks-1221.test.ts:110).

  • hooks inject with OPENCODE_CONFIG_DIR and an earlier ~/.config/opencode/plugin/teamai-hooks.ts leaves one plugin (real CLI), and so does Pi's extension with PI_CODING_AGENT_DIR; both failed before the fix.

  • A Muse team hook changed after the move, then hooks inject and hooks 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 switch with toolRoots.claude: ~/.claude-work recorded and no CLAUDE_CONFIG_DIR in the shell (real CLI, sandbox HOME):

    $ teamai models switch local:fixture --agent claude
    switched      claude switched to local:fixture
    recorded root settings: { "env": { "KEEP": "yes", "ANTHROPIC_BASE_URL": "https://example.test", ... } }
    default ~/.claude/settings.json exists: no
    $ teamai models restore --agent claude
    restored      claude model settings restored
    recorded root settings after restore: { "env": { "KEEP": "yes" } }
    

    Before, the switch wrote ~/.claude/settings.json. model-switch.test.ts also covers a switch an earlier release recorded under the default root: it is skipped with both paths named, and restore from a shell with CLAUDE_CONFIG_DIR=~/.claude undoes it.

  • hooks remove exits 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.ts writes no settings hooks for a tool whose channel names none and still removes what an earlier release left there. local-agent.test.ts uninstalls a CodeBuddy agent hook from an OMP session.

  • locate-hooks.test.ts resolves Kiro's hooks to ~/.kiro/hooks, and e2e/kiro-standalone-hooks.test.ts (from fix(kiro): use standalone V3 session-start hooks #1341, real CLI) passes with kiroHookFile going through locate.

  • At 1a2daea: npx tsc --noEmit, npm run lint and npm run build pass, and npx vitest run passes 17191 tests in 579 files (21 skipped). npm run test:e2e over the hook, model and session files (12 files, with installed-launcher-readiness from 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 pull after 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.

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Code Erosion Report

Informational — never blocks the merge. scb-check==0.2.0 SlopCodeBench metrics; method & caveats in docs/dev/ci-code-erosion.md.

Metric Value Human band Agent band Reading
Verbosity* 0.053 0.15 0.33 human
Erosion 0.706 0.31 0.68 agent
Cognitive erosion 0.874 – – –

Scanned 480 files / 106709 SLOC · high-CC functions 839/9478

* On TypeScript, verbosity is partial and the bands are Python-calibrated.

Rule hits (TS verbosity layer)

Standalone ast-grep, separate from the number above.

Rule Hits
unnecessary-else-after-return 64
empty-catch-block 5
self-assignment 1

70 distinct lines flagged across src/.

@github-actions

Copy link
Copy Markdown
  • [P1 blocking] Preserve retired Muse hook ownership across updates — src/hooks.ts:2657: For an HTTP-backed Muse team, install hook command A before upgrading, move XDG_CONFIG_HOME, then change the hook to command B and run hooks inject. Reconciliation replaces A’s manifest record with B’s while leaving A in the default-home settings. Subsequent hooks remove or uninstall cannot identify A: Muse hooks have no marker, and HTTP teams have no history. A remains and runs again when the default home becomes active. Preserve retired-copy ownership separately before replacing active records.

The PR description documents sufficient real-CLI verification at 14f900d55; no testing-record finding. I only read the diff and did not run, build, or install PR code.

@SaulMoro

Copy link
Copy Markdown
Collaborator Author

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: a pull after the team changes a hook leaves no unowned copy of the old one in the default home failed before and passes now.

@SaulMoro SaulMoro assigned jeff-r2026 and unassigned jeff-r2026 Oct 26, 2026
@github-actions

Copy link
Copy Markdown
  • [P1 blocking] Stop reconciliation when retired Muse cleanup fails — src/hooks.ts:2919: For an HTTP-backed Muse team, install command A, move XDG_CONFIG_HOME, leave the default settings temporarily invalid, change the hook to B, and run hooks inject. This catch only warns, so the moved-file pass replaces A’s manifest record with B’s. After repairing the default settings, hooks remove or uninstall cannot identify A: Muse has no marker and HTTP teams have no history. Skip moved-file reconciliation when retired cleanup fails, preserving ownership for retry.

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 b03008b77; no testing-record finding. I only read the specified diff and did not run, build, or install PR code.

@SaulMoro

Copy link
Copy Markdown
Collaborator Author

Fixed in ce25ac1. A default-home copy that cannot be cleaned now stops that tool's pass. The pull warns Failed to reconcile hooks for muse: ..., the moved copy and its records stay as they were, and a retry after the file is fixed removes the old hook from both copies. Covered by the e2e test "a pull leaves the moved hooks as they are while the default-home copy does not parse, so a retry still names the old hook". It failed on b03008b and passes now.

@SaulMoro SaulMoro assigned jeff-r2026 and unassigned jeff-r2026 Oct 26, 2026
@github-actions

Copy link
Copy Markdown

No new findings in the specified diff.

  • Both earlier Muse ownership findings are resolved: retired hooks are cleaned before replacing records, and cleanup failure prevents moved-file reconciliation so ownership remains available for retry.
  • The PR description documents sufficient representative real-CLI verification at ce25ac184; no testing-record finding.

I only read the specified diff. I did not run, build, or install PR code.

@SaulMoro
SaulMoro force-pushed the saulmoro/1221-hooks-locate branch from ce25ac1 to cc2b9a7 Compare October 26, 2026 06:44
@github-actions

Copy link
Copy Markdown

No new findings in the specified diff.

  • Both earlier Muse ownership findings are resolved: retired hooks are cleaned before records are replaced, and cleanup failure prevents moved-file reconciliation, preserving ownership for retry.
  • The PR description documents sufficient representative real-CLI verification at ce25ac184; no testing-record finding. The older verification commit is not blocking under the review rules.

I only read the specified diff. I did not run, build, or install PR code.

@SaulMoro
SaulMoro force-pushed the saulmoro/1221-hooks-locate branch from cc2b9a7 to dd28a11 Compare October 26, 2026 08:13
@SaulMoro SaulMoro assigned jeff-r2026 and unassigned jeff-r2026 Oct 26, 2026
@github-actions

Copy link
Copy Markdown

No new findings in the specified diff.

  • Both earlier Muse ownership findings are resolved: retired hooks are cleaned before records are replaced, and cleanup failure prevents moved-file reconciliation, preserving ownership for retry.
  • The PR description documents sufficient representative real-CLI verification. The older verification commits are not blocking under the review rules.

I only read the specified diff. I did not run, build, or install PR code.

@SaulMoro
SaulMoro force-pushed the saulmoro/1221-hooks-locate branch from dd28a11 to c9bbc31 Compare October 26, 2026 08:37
@github-actions

Copy link
Copy Markdown

No new findings in the specified diff.

  • Both earlier Muse ownership findings are resolved: retired hooks are cleaned before records are replaced, and cleanup failure prevents moved-file reconciliation, preserving ownership for retry.
  • The PR description documents sufficient representative real-CLI verification. Older verification commits are not blocking under the trusted review rules.

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

@SaulMoro
SaulMoro force-pushed the saulmoro/1221-hooks-locate branch from c9bbc31 to d1d58f0 Compare October 26, 2026 10:38
@github-actions

Copy link
Copy Markdown

No new findings in the specified diff.

  • Both earlier Muse ownership findings are resolved: retired hooks are cleaned before records are replaced, and cleanup failure prevents moved-file reconciliation, preserving ownership for retry.
  • The PR description documents sufficient representative real-CLI verification. Older verification commits are not blocking under the trusted review rules.

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

@SaulMoro
SaulMoro force-pushed the saulmoro/1221-hooks-locate branch from d1d58f0 to cc3e973 Compare October 26, 2026 11:33
@SaulMoro
SaulMoro force-pushed the saulmoro/1221-hooks-locate branch from 3baa04a to a2904fe Compare October 27, 2026 00:11
@github-actions

Copy link
Copy Markdown

No new findings in the specified diff.

  • Both earlier Muse ownership findings are resolved: retired hooks are cleaned before records are replaced, and cleanup failure prevents moved-file reconciliation, preserving ownership for retry.
  • The PR description documents sufficient representative real-CLI verification. Older verification commits are not blocking under the trusted review rules.

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

Base automatically changed from saulmoro/1221-session-stores to main October 27, 2026 02:52
@jeff-r2026
jeff-r2026 force-pushed the saulmoro/1221-hooks-locate branch from a2904fe to c168d34 Compare October 27, 2026 02:52
@SaulMoro
SaulMoro force-pushed the saulmoro/1221-hooks-locate branch from c168d34 to cd0f3b3 Compare October 27, 2026 02:56
SaulMoro and others added 18 commits October 27, 2026 03:57
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.
…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]>
…1221)

#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.
@github-actions

Copy link
Copy Markdown

No new findings in the specified diff.

  • Both earlier Muse ownership findings are resolved: retired hooks are cleaned before records are replaced, and cleanup failure prevents moved-file reconciliation, preserving ownership for retry.
  • The PR description documents sufficient representative real-CLI verification. Older verification commits are not blocking under the trusted review rules.

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

@SaulMoro
SaulMoro force-pushed the saulmoro/1221-hooks-locate branch from cd0f3b3 to 93e54f8 Compare October 27, 2026 02:58
@github-actions

Copy link
Copy Markdown

No new findings in the specified diff.

  • Both earlier Muse ownership findings are resolved: retired hooks are cleaned before records are replaced, and cleanup failure prevents moved-file reconciliation, preserving ownership for retry.
  • The PR description documents sufficient representative real-CLI verification. Older verification commits are not blocking under the trusted review rules.

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

@jeff-r2026 jeff-r2026 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.

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.

@jeff-r2026
jeff-r2026 merged commit 8ee3ca5 into main Oct 27, 2026
18 checks passed
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants