Skip to content

fix(pi): follow the recorded home for hook extensions - #1368

Closed
nateEc wants to merge 3 commits into
Tencent:mainfrom
nateEc:fix/1221-pi-relocated-extensions
Closed

nateEc wants to merge 3 commits into
Tencent:mainfrom
nateEc:fix/1221-pi-relocated-extensions

Conversation

@nateEc

@nateEc nateEc commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Pi's skill/MCP/model paths followed PI_CODING_AGENT_DIR and the recorded tool home, but its extensions stayed under ~/.pi/agent/extensions. Pi therefore never loaded TeamAI hooks from a relocated agent directory.

Use the existing tool-home resolver for the single extension directory. Built-in and HTTP-source extensions, listing, readiness checks and removal now agree on that directory. Remove the obsolete descriptor/doctor note that Pi still writes settings into its default home. Existing copies in another agent directory are kept because they can still serve another profile; personal files in both homes stay intact. Update the bilingual reference.

Review follow-up:

Correct the stale doctor-note assertion and preserve legacy default-home MCP lookup through a separate compatibility flag. Bilingual guidance explains how to retire the old TeamAI extension after no other scope/session 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__/pi-hooks.test.ts src/__tests__/mcp-locate-targets.test.ts src/__tests__/uninstall.test.ts src/__tests__/tools-channels.test.ts: 458 passed.
  • After build, npx vitest run --config vitest.e2e.config.ts src/__tests__/e2e/pi-relocated-extensions.test.ts: 1 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.

@nateEc

nateEc commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

Updated the tools-channels descriptor contract to remove Pi from the list of tools still writing hooks/settings under their default home; its functional moved-home regressions remain intact. Ran the complete Windows test selection locally on macOS: 29 files, 2,908 passed and one existing platform-specific skip. Type checking and lint passed. This is a local selection run, not a claim of native Windows execution; the new CI run checks that host.

@github-actions

Copy link
Copy Markdown

No findings confidently identified in the specified PR diff.

The PR description documents sufficient testing: a post-build real-CLI run covers relocated-home installation, listing/removal without the environment variable, and preservation of a personal extension. Native Windows and live Pi validation are explicitly disclosed as not run; neither is blocking under the review rules.

Reviewed only the diff; did not run, build, or install PR code.

@SaulMoro SaulMoro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This was generated by AI during triage.

@nateEc The hook move works with the built CLI. The extension lands in the recorded or PI_CODING_AGENT_DIR home, and hooks list, doctor, a pull with a stale variable and hooks remove all use that home; a build of main (f3cd042) still writes ~/.pi/agent. It uses the existing toolHome and adds no new resolver. Combined with #1365 (now merged), the tree merges cleanly and pi-hooks (31/31) and both Pi e2e files pass. One thing blocks.

[P1 blocking] The Lint & Test jobs are red because of this PR. All six fail on mcp-locate-targets.test.ts (doctor notes cwd-only MCP and settings that still stay at the default home) with expected [] to include 'pi takes MCP servers from …'. The PR removes Pi from settingsAtDefault and the test still expects the Pi note; it passes on main. If dropping the note is intended, flip that assertion to .not.toContain and rename the case.

  • [P2 non-blocking] settingsAtDefault('pi') also drives the lookup in src/mcp-reconcile.ts:607 for MCP servers an earlier release wrote to the default home (used as the ownership-record fallback at src/mcp-reconcile.ts:483). Pi loses that fallback and the body does not say so. Not reproduced here; #1369 makes the same change for OpenCode and there it does break uninstall. A separate flag for "hooks follow the moved home" would leave this reader alone.
  • [P2 non-blocking] After an upgrade, hooks remove prints ✔ Hooks removed from all AI tool settings while ~/.pi/agent/extensions/teamai-hooks.ts from the earlier release stays; main removes it. Keeping the old copy is stated in the body, but the message should name the leftover path, or the body should tell upgraders to delete it.
  • [P2 non-blocking] The settingsAtDefault comment in src/tools.ts:27-30 still lists Pi's extension among the files written under the default home.
  • [P3 nit] Two commit subjects are in Chinese. The squash title is English.

#1369, #1370 and #1371 conflict with this PR in the same reference.md paragraph, and #1369 and #1371 also in tools-channels.test.ts.

The CI review reports no findings. We agree the testing record covers the hook behavior and that the Windows and live-Pi gaps do not block, but disagree with "no findings": it read only the diff and did not see the red jobs. CI: the six Lint & Test jobs fail as above, so Build is skipped; the GitHub-provider job is skipped by the fork policy.

- 使用现有工具主目录规则定位 Pi 扩展,使内置 hook、HTTP hook、列表、就绪检查及删除操作遵循已记录目录和 PI_CODING_AGENT_DIR。
- 保留旧目录和目标目录的个人文件,仅删除当前目录中的受管扩展;同步工具描述及中英文参考,移除已过时的默认目录警告。
- 环境和已记录目录的两个回归在修改前失败;89 项相关单测、真实 CLI 安装及无环境变量时列出和删除用例、构建、类型检查和 lint 通过。
- 将 Pi 从仍在默认目录写入 hooks 与设置的工具列表中移除,与已经跟随记录目录的实现和 doctor 契约一致。
- 本机完整 Windows 测试集合 2908 项通过,1 项原有平台用例跳过;类型检查和 lint 通过。
- 将旧版 MCP 默认目录查找与当前 hooks 路径标记分开。
- 更新已迁移目录的诊断断言,补充中英文旧扩展清理说明。
- 458 项定向单测及迁移扩展 CLI 场景通过,类型、lint 与构建通过。
@nateEc
nateEc force-pushed the fix/1221-pi-relocated-extensions branch from 6b2bc7c to 3c710c0 Compare October 26, 2026 04:38
@github-actions

Copy link
Copy Markdown

No findings confidently identified in the specified PR diff.

The PR description documents sufficient testing: a post-build real-CLI run covers relocated-home installation, listing/removal without the environment variable, and preservation of a personal extension. Native Windows and live Pi validation are disclosed as not run; neither is blocking under the review rules.

The earlier review reported no findings, so none require resolution.

Reviewed only the diff; did not run, build, or install PR code.

@nateEc

nateEc commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Updated and rebased onto main fc8a229e. Correct the stale doctor-note assertion and preserve legacy default-home MCP lookup through a separate compatibility flag. Bilingual guidance explains how to retire the old TeamAI extension after no other scope/session uses that home.

Verification: 458 focused unit tests passed; types, lint and build passed. Post-build real-CLI pi-relocated-extensions: 1 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: 3c710c04.

@SaulMoro

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

@nateEc Re-checked at 3c710c0. Lint & Test is green, the tools.ts comment is fixed, and the Pi MCP fallback to the default home is kept through legacyDefaultHome. With the built CLI and PI_CODING_AGENT_DIR set, hooks list and doctor read the moved home, and uninstall --agent pi reports the moved extension. The merge with current main type-checks and passes the related tests. Two things are left before we can approve, both inside this PR's scope:

  • hooks remove leaves teamai's old extension running. After an upgrade pull with PI_CODING_AGENT_DIR set, hooks remove prints ✔ Hooks removed from all AI tool settings, but ~/.pi/agent/extensions/teamai-hooks.ts (the pre-upgrade, teamai-marked copy) is still there. Any shell without the variable keeps loading it, running hooks from frozen code. The docs now tell users to delete it by hand, but "removed from all AI tool settings" is what the command promises. Please have hooks remove also remove the teamai-marked copy in the default home, and leave unmarked files alone. That is the same rule as for OpenCode's plugin in fix(opencode): follow the recorded configuration home for plugins #1369, where main already removes it on uninstall. If you keep it on purpose for another profile, the success line should at least name the leftover path.
  • The Pi user-rules sentence is stale after fix(pi): deliver user context to active override files #1340. Both reference.md files say Pi reads /x/AGENTS.md. Since fix(pi): deliver user context to active override files #1340, Pi reads AGENTS.override.md first when it exists. The paragraph is one this PR already edits.

Nits: no test covers Pi's legacyDefaultHome case. Three commit subjects are in Chinese; a squash merge lets the PR title stand instead.

The CI review reports no blocking findings. Its line saying the earlier review had none is not right: our review at 6b2bc7c requested changes. CI is green on this head.

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