Skip to content

fix(muse): follow the recorded home for hook settings - #1370

Closed
nateEc wants to merge 2 commits into
Tencent:mainfrom
nateEc:fix/1221-muse-relocated-hooks
Closed

nateEc wants to merge 2 commits into
Tencent:mainfrom
nateEc:fix/1221-muse-relocated-hooks

Conversation

@nateEc

@nateEc nateEc commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Muse reads user hooks from its XDG configuration home, but TeamAI still installed them under ~/.config/muse. A recorded home without XDG_CONFIG_HOME in the hook process had the same failure.

Resolve native user hook paths through toolHome('muse') for injection, HTTP hooks, listing, instruction-channel readiness and uninstall. Preserve self/project and custom paths, personal entries and old-home files. A missing moved home cannot be recreated through the old-home/project installation fallback. Model switching is handled separately in #1366; this PR does not close the umbrella issue.

Review follow-up:

Narrow the moved-user-home guard to restore ZCode self hooks. Remove the obsolete default-home model note after #1366, while preserving legacy MCP ownership through a separate compatibility flag. Old-home TeamAI hook entries are intentionally retained because other scopes may still use them; remove those entries after confirming no other installation uses that home.

Validation on this branch, rebased onto fc8a229e:

  • npx tsc --noEmit, npm run lint, npm run build, git diff --check: passed.
  • npx vitest run src/__tests__/muse-relocated-hooks.test.ts src/__tests__/uninstall.test.ts src/__tests__/local-agent.test.ts src/__tests__/mcp-locate-targets.test.ts src/__tests__/instruction-targets.test.ts src/__tests__/tools-channels.test.ts: 839 passed.
  • After build, npx vitest run --config vitest.e2e.config.ts src/__tests__/e2e/muse-relocated-hooks.test.ts src/__tests__/e2e/zcode-self-hooks.test.ts: 2 passed, using the real CLI and isolated local Git/HOME fixtures.

Local host: macOS, Node 22.22.1, Apple Git 2.50.1. Native Windows, live vendor applications and additional provider combinations were not run locally and are left to CI. This record replaces the earlier combined-snapshot validation paragraphs.

Refs #1221; this PR addresses only its stated independent defect.

@github-actions

Copy link
Copy Markdown

No findings in the specified diff.

The PR description documents sufficient testing, including a passing built-CLI e2e run covering inject, list, doctor, uninstall, and preservation of personal settings and the old-home file. Additional provider/agent coverage is not required.

Review was read-only; I did not run, build, or install anything from the PR.

@SaulMoro SaulMoro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This was generated by AI during triage.

@nateEc The Muse move works with the built CLI. Hooks land in the recorded or XDG_CONFIG_HOME home, uninstall removes them there and keeps personal entries, and tsc and lint pass; a build of current main still writes ~/.config/muse. One thing blocks, and the PR now conflicts with main.

[P1 blocking] ZCode hooks are no longer installed. On this head, teamai init . --agent zcode --force in a git project writes no hook entries to ~/.zcode/cli/config.json; a build of main writes five. The new installedRoot guard at src/hooks.ts:3271 treats any hook root not under the project as moved, and ZCode's hook root is always $HOME. Reverting that line restores the five entries. e2e/zcode-self-hooks.test.ts passes on main and fails here, and it is the failure in E2E shard 3/3. #1371 adds the same guard; a version limited to the moved user home is in the review there.

  • [P2 non-blocking] After an upgrade, teamai's hook entries in ~/.config/muse/settings.json stay through inject and uninstall, which main removes. Muse does not read that file while the variable is set, but the entries are teamai's own and fire again if the member unsets it. Either withdraw them or say in the body that they are kept.
  • [P2 non-blocking] Since #1366 merged, the reference.md sentence about models switch settings staying at the default home is wrong, it is where the rebase conflicts, and settingsAtDefault: true for Muse is stale too. skill-data/core/references/troubleshooting.md:338 still says Muse hooks live in ~/.config/muse.
  • [P2 non-blocking] This PR and #1371 add the same per-tool branch in hookSettingsPath and the same guard. One helper driven by the tool's recorded home would serve both, and is the piece #1221's B4 will replace.
  • [P3 nit] A commit subject is in Chinese; the ZCode rationale comment next to the guard was deleted; hooks inject prints success when the moved home does not exist.

The CI review reports no findings. We agree that extra providers and agents are not required, and disagree with "no findings": it read only the diff and did not see the red E2E shard. CI: E2E shard 3/3 and its aggregate fail on zcode-self-hooks; the rest pass, and the GitHub-provider job is skipped by the fork policy.

- 通过统一 hook 路径解析,让 Muse 内置与 HTTP hooks 使用 XDG 或机器记录的主目录,项目自身与自定义路径保持原有语义。
- 将列表、卸载与指令投递检查接到相同路径;移动目录缺失时不再因旧目录或项目目录存在而重建它,保留旧副本及个人设置。
- 补充目录迁移、记录优先级、个人 hook 保留、HTTP 安装卸载和 readiness 回归;修复前目录用例及 readiness 用例分别失败。
- 362 个定向单测、143 个 HTTP 单测、220 个卸载相关单测通过;构建、类型检查、lint 以及真实 CLI 注入、列表、doctor、卸载验证通过。
- 独立标记旧版 MCP 默认目录,移除已过期的模型目录提示。
- 收窄迁移目录的安装检查,保留 ZCode 自模式行为并更新故障排查。
- 839 项定向单测和 Muse、ZCode 两个真实 CLI 场景通过,类型、lint 与构建通过。
@nateEc
nateEc force-pushed the fix/1221-muse-relocated-hooks branch from fa9f45a to 26550fc Compare October 26, 2026 04:38
@github-actions

Copy link
Copy Markdown

No findings in the specified diff. The earlier review also reported no findings, so none require a resolution update.

The PR description documents sufficient testing, including a passing built-CLI e2e run covering inject, list, doctor, uninstall, and preservation of personal settings and the old-home file. Additional provider/agent coverage is not required.

Review was read-only; I did not run, build, or install anything from the PR.

@nateEc

nateEc commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Updated and rebased onto main fc8a229e. Narrow the moved-user-home guard to restore ZCode self hooks. Remove the obsolete default-home model note after #1366, while preserving legacy MCP ownership through a separate compatibility flag. Old-home TeamAI hook entries are intentionally retained because other scopes may still use them; remove those entries after confirming no other installation uses that home.

Verification: 839 focused unit tests passed; types, lint and build passed. Post-build real-CLI muse-relocated-hooks, zcode-self-hooks: 2 passed. Native Windows and live vendor/provider combinations remain CI coverage. The PR body now describes this branch's current verification rather than an older combined snapshot.

Updated head: 26550fcb.

@SaulMoro

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

@nateEc Re-checked at 26550fc. The ZCode blocker is fixed: init --agent zcode --force writes the five hook entries again, and zcode-self-hooks passes. The stale docs and the settingsAtDefault flag are fixed too. Build, tsc, lint, the PR's e2e files and the related e2e files (11 files, 71 tests) pass. One blocker remains. It is the same one we raised on #1369.

  • [P1 blocking] uninstall --agent muse --force leaves teamai's hook entries in the default Muse home once XDG_CONFIG_HOME has moved it. On main, Muse is settingsAtDefault, so teamai's hooks live in ~/.config/muse/settings.json and uninstall removes them there. On this head, with the XDG home recorded and the entries an earlier release wrote still in the default home, uninstall exits 0 and clears the XDG file. The default home keeps its 10 teamai hook lines. A shell without the variable then runs teamai's hooks again after an uninstall. The reply says other scopes may still use them, but those entries carry teamai's marker and are the copy main removes. Please remove the teamai-marked entries from the default home on uninstall and hooks remove, and keep leaving the member's own entries alone. This is the same rule as fix(pi): follow the recorded home for hook extensions #1368 and fix(opencode): follow the recorded configuration home for plugins #1369.
  • [P2 non-blocking] doctor no longer sees those entries. With the setup above, doctor --json reports every Muse check ok and prints no Muse note. The removed settingsAtDefault notes were the only signal. Once uninstall removes the entries, a doctor note is only needed if you keep any of them.
  • [P2 non-blocking] src/hooks.ts here is byte-identical to fix(codebuddy): follow the recorded home for hooks #1371's, and the two PRs conflict in five files. Whichever lands second should rebase onto the first and share the per-tool hookSettingsPath branch.
  • [P3 nit] hooks inject prints "Hooks injected into all AI tool settings" when the moved Muse home is missing and nothing was written. The ZCode "CLI reads hooks only from HOME" comment in src/types.ts is gone. The rationale is worth keeping.

CI: E2E shard 3/3 failed in deleted-worktree-scope-810 with ENOTEMPTY while removing the test home during teardown. That file is outside this diff and passes locally on this head. I've re-run the job. The CI review reports no findings. It ran before the red shard and doesn't cover the uninstall case above.

SaulMoro added a commit that referenced this pull request Oct 26, 2026
…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]>
@SaulMoro

Copy link
Copy Markdown
Collaborator

Closing in favor of #1405, which locates every tool's hooks from its descriptor and fixes the moved Pi, OpenCode, Muse and CodeBuddy homes together. Your end-to-end test fails on main and passes on #1405 unchanged, so I carried it into that PR with you as co-author. Thanks for tracking this down.

@SaulMoro SaulMoro closed this Oct 26, 2026
hz89Dev pushed a commit to hz89Dev/teamai-cli that referenced this pull request Oct 27, 2026
…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 Tencent#1368, Tencent#1369, Tencent#1370 and Tencent#1371,
which this branch replaces.

Co-authored-by: Nathan Shan <[email protected]>
jeff-r2026 pushed a commit that referenced this pull request Oct 27, 2026
…ollow a moved home (#1221) (#1405)

* feat(tools): state every tool's hook channel in the descriptor (#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 (#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 (#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 (#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 (#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 (#1221)

* fix(hooks): clear the default-home copy first, so one team-hook record 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.

* refactor(hooks): key HOME-hook ownership on the descriptor's self channel, 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.

* fix(hooks): pull removes the OpenCode plugin an earlier release left 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.

* fix(hooks): an agent hook leaves no copy in a moved tool's default home (#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 (#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 (#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 (#1221)

* fix(models): models switch writes into the Claude and Codex roots teamai init recorded (#1221)

* fix(hooks): hooks remove exits 1 when it leaves hooks behind, as uninstall does (#1221)

* fix(hooks): write settings and agent hooks only through a channel the tool reads (#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 #1368, #1369, #1370 and #1371,
which this branch replaces.

Co-authored-by: Nathan Shan <[email protected]>

* feat(tools): state Kiro's standalone hook file as its hook channel (#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.

---------

Co-authored-by: Nathan Shan <[email protected]>
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.

3 participants