Skip to content

fix(kiro): use standalone V3 session-start hooks - #1341

Merged
SaulMoro merged 8 commits into
Tencent:mainfrom
nateEc:fix/1221-kiro-standalone-hooks
Oct 26, 2026
Merged

SaulMoro merged 8 commits into
Tencent:mainfrom
nateEc:fix/1221-kiro-standalone-hooks

Conversation

@nateEc

@nateEc nateEc commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Kiro's default agent never ran the session-start dispatcher because synchronization was embedded in custom agents. Install a standalone Kiro V3 user hook and connect injection, listing, doctor, removal and uninstall. Migrate managed legacy agentSpawn entries out of active and kept agent copies to avoid duplicate dispatch.

Compatibility: intentionally requires Kiro V3 standalone hooks and drops Kiro 2.x embedded-hook support, as agreed in review. Member-authored hooks and agent content are preserved.

Review follow-up:

Rebase and retain both troubleshooting sections. Update the obsolete type comment to describe standalone V3 session hooks and legacy agentSpawn migration. Preserve the previously reviewed cleanup of legacy entries in active and kept agent copies.

Validation at 17b3bb45, based on fc8a229e:

  • npx tsc --noEmit, npm run lint, npm run build, git diff --check: passed.
  • npx vitest run src/__tests__/kiro-hooks.test.ts src/__tests__/hooks.test.ts src/__tests__/hooks-cmd.test.ts src/__tests__/agent-format.test.ts src/__tests__/uninstall.test.ts: 406 passed.
  • After build, npx vitest run --config vitest.e2e.config.ts src/__tests__/e2e/kiro-standalone-hooks.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.

Merge with main at f70ce259, head 1c61f6a7:

  • Merged origin/main into the branch to clear the skill-data/core/references/troubleshooting.md conflict with fix(pi): deliver user context to active override files #1340. Both sections are kept, with the Pi section from main followed by the Kiro section. The rest of the diff against main is unchanged.
  • npx tsc --noEmit, npm run lint, npm run build, git diff --check: passed.
  • npx vitest run src/__tests__/kiro-hooks.test.ts src/__tests__/kiro.test.ts src/__tests__/hooks.test.ts src/__tests__/hooks-cmd.test.ts src/__tests__/agent-format.test.ts src/__tests__/uninstall.test.ts: 416 passed. npx vitest run: 575 files passed, 1 skipped, 16425 tests passed.
  • npm run test:e2e -- src/__tests__/e2e/kiro-standalone-hooks.test.ts: 1 passed.
  • Real-CLI run with the built dist/index.js in a throwaway HOME and a local bare team remote, user scope, enabledAgents: [kiro], with a member-edited ~/.kiro/agents/reviewer.json that still carries the legacy agentSpawn dispatch plus a personal echo personal entry:
$ teamai pull --force
exit=0
$ cat ~/.kiro/agents/reviewer.json
{ "name": "reviewer", "prompt": "Member-edited prompt",
  "hooks": { "agentSpawn": [ { "command": "echo personal" } ] } }
$ cat ~/.kiro/hooks/teamai.json
{ "version": "v1", "hooks": [ { "name": "teamai-session-start", "trigger": "SessionStart", "enabled": true,
    "action": { "type": "command", "command": "bash -lc \"teamai hook-dispatch session-start --tool kiro 2>/dev/null\" || true" },
    "timeout": 30 } ] }
$ teamai hooks list
kiro  installed  ~/.kiro/hooks/teamai.json
$ teamai doctor --json   (Kiro check)
[{"name":"teamai hooks in Kiro standalone hook file (requires Kiro CLI V3)","ok":true}]
$ teamai hooks remove
✔ Hooks removed from all AI tool settings
exit=0
teamai.json exists after remove: no
$ teamai hooks inject   (after writing a personal ~/.kiro/hooks/teamai.json)
⚠ Failed to reconcile Kiro hooks: <home>/.kiro/hooks/teamai.json is not owned by teamai; move it aside before injecting hooks.
exit=1

User-scope custom agents directory, head e16c9925:

  • legacyAgentDirs read the user scope through readConfigFrom, which only loads project partitions, so a user-scope toolPaths.kiro.agents directory was never searched. It now loads the user config with loadLocalConfig. New unit case in kiro-hooks.test.ts fails on 1c61f6a7 and passes here.
  • Merged origin/main again after fix(doctor): report blocked skill directories and preserve them on uninstall #1335; troubleshooting.md keeps the blocked-skills section, then the Kiro section.
  • npx tsc --noEmit, npm run lint, npm run build: passed. Kiro and hooks unit files pass. npm run test:e2e -- src/__tests__/e2e/kiro-standalone-hooks.test.ts src/__tests__/e2e/blocked-skills-directory.test.ts: 3 passed.
  • Real CLI, user scope, team toolPaths.kiro.agents: work/project/.kiro/agents, agent carrying the legacy dispatch plus echo personal, then teamai hooks inject:
# 1c61f6a7
{"agentSpawn":[{"command":"bash -lc \"teamai hook-dispatch session-start --tool kiro 2>/dev/null\" || true"},{"command":"echo personal"}]}
# e16c9925
{"agentSpawn":[{"command":"echo personal"}]}
~/.kiro/hooks/teamai.json written in both

No tests were deleted.

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

@github-actions

Copy link
Copy Markdown

No findings I’m confident are real in the specified diff.

The PR description documents sufficient testing, including a representative built-CLI E2E run covering installation, listing, doctor, removal, reinjection, and user uninstall. Missing live Kiro and additional platform/provider coverage is explicitly disclosed and is not blocking.

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

@SaulMoro

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

@jeff-r2026 This needs your decision. The PR checks "Breaking compatibility change": session-start for Kiro moves from the agentSpawn hook inside teamai-rendered agents to a standalone ~/.kiro/hooks/teamai.json, which only Kiro CLI V3 loads, so Kiro 2.x users lose their only session-start path. Our review is below for when you decide.

@nateEc We built this head and its merge-base 83f6d1db. On this head, the standalone file is installed, listed, checked by doctor, removed, re-injected and uninstalled. Base never writes it. kiro-standalone-hooks e2e and the Kiro unit tests (54/54) pass here and fail on base, and tsc and lint pass.

  • [P1 blocking] A member-edited Kiro agent keeps the old hook. Pull keeps an agent the member changed ("Kept …/.kiro/agents/reviewer.json: you changed it …"), so its agentSpawn entry with teamai hook-dispatch session-start --tool kiro stays, and pull also writes ~/.kiro/hooks/teamai.json. Going by Kiro's migration docs, V3 runs both, which is the duplicate dispatch this PR sets out to remove. We reproduced the files with the real CLI but couldn't run Kiro itself. Removing teamai's agentSpawn entry from kept agents, or skipping the standalone hook while one remains, with a test for the kept-agent state, would close it.
  • [P2 non-blocking] On Kiro 2.x, the new doctor check reports ok although 2.x doesn't load the file. Doctor could name the V3 requirement.
  • [P2 non-blocking] teamai hooks inject prints "Hooks injected" after the Kiro write is refused. Pull reports the same failure correctly.
  • [P3 nit] The reference and troubleshooting docs cover the same thing twice. The body's combined-snapshot paragraph can't be checked against this diff. troubleshooting.md conflicts with main at the end of the file, which needs a rebase.

CI review: it reported no findings. We disagree because of the kept-agent case above, which it did not run.

@SaulMoro
SaulMoro requested a review from jeff-r2026 October 23, 2026 14:55
@jeff-r2026

Copy link
Copy Markdown
Collaborator

Decision: we accept dropping Kiro 2.x session-start support. Moving to the standalone ~/.kiro/hooks/teamai.json that Kiro CLI V3 loads is fine. @nateEc please address SaulMoro's remaining [P1 blocking] (a member-edited Kiro agent keeps teamai's old agentSpawn entry, so V3 would dispatch session-start twice) and rebase onto current main; the doctor check could mention the V3 requirement (P2). Once that is clean we will merge.

@nateEc
nateEc force-pushed the fix/1221-kiro-standalone-hooks branch from 7fde26a to bdb0fa3 Compare October 24, 2026 17:31
@nateEc

nateEc commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the review follow-up at bdb0fa34f1fab7d402038cc2de869a048f9af058 on current main.

  • Implemented the accepted V3 migration decision. Before enabling the standalone hook, injection removes only the exact legacy TeamAI agentSpawn command from existing user/current-project Kiro agents, including edited copies; personal prompts, hooks and other fields remain.
  • Doctor's check names the Kiro CLI V3 requirement. hooks inject exits 1 rather than printing success when a managed adapter write is refused.
  • New kept-agent unit regression was red before the fix. Kiro/hook-command unit files: 53 passed. Real built-CLI lifecycle/migration E2E: 1 passed, including personal hook preservation and refusal of a foreign standalone file. Build, type checking and lint passed.
  • Kiro itself and Windows were unavailable. Kiro 2.x remains intentionally unsupported, as approved by jeff-r2026.

The PR description contains the updated verification record. Ready for another review.

@github-actions

Copy link
Copy Markdown
  • [P2 non-blocking] Migration misses other project installs — src/kiro-hooks.ts:41: With legacy Kiro agents in projects A and B, injection in A removes embedded hooks only from A and HOME, then enables the user-wide SessionStart hook. B’s agents retain their embedded dispatcher and therefore dispatch twice when selected. Account for other existing installs, or prevent duplicate dispatch while their legacy hooks remain.

The PR description documents sufficient testing, including a representative built-CLI lifecycle/migration E2E run. Disclosed unavailable platform/provider coverage is not blocking.

The earlier pass reported no findings, so none require resolution. Review was read-only; I did not run, build, or install PR code.

@nateEc

nateEc commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the review follow-up at a8baae5692a9e431aa5b9d2d87c2b54c1a8259e4 on current main.

  • Implemented the accepted V3 migration decision. Before enabling the standalone hook, injection removes only the exact legacy TeamAI agentSpawn command from existing user and registered-project Kiro agents (including linked worktrees and configured agent locations), including edited copies; personal prompts, hooks and other fields remain.

  • Doctor's check names the Kiro CLI V3 requirement. hooks inject exits 1 rather than printing success when a managed adapter write is refused.

  • New kept-agent unit regression was red before the fix. Kiro/hook-command unit files: 54 passed. Real built-CLI lifecycle/migration E2E: 1 passed, including personal hook preservation and refusal of a foreign standalone file. Build, type checking and lint passed.

  • Kiro itself and Windows were unavailable. Kiro 2.x remains intentionally unsupported, as approved by jeff-r2026.

  • Follow-up review: a new two-project regression failed before registry discovery was added. The final real-CLI run verifies a registered project B is migrated while installing the shared hook from another scope, without creating or healing its configuration.

The PR description contains the updated verification record. Ready for another review.

@github-actions

Copy link
Copy Markdown

No new findings I’m confident are real in the specified diff.

  • Resolved: The earlier cross-project migration finding is addressed by discovering registered projects, linked worktrees, and configured agent locations before enabling the shared hook. New regression coverage includes project B.
  • Testing: The PR description documents sufficient testing, including a representative built-CLI lifecycle/migration E2E run. Disclosed unavailable live Kiro, Windows, and additional provider coverage is not blocking.

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

@nateEc

nateEc commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the review follow-up at 911d827e6afa73191b692a52fbb788eb27793a7a on current main.

  • Implemented the accepted V3 migration decision. Before enabling the standalone hook, injection removes only the exact legacy TeamAI agentSpawn command from existing user and registered-project Kiro agents (including linked worktrees and configured agent locations), including edited copies; personal prompts, hooks and other fields remain.

  • Doctor's check names the Kiro CLI V3 requirement. hooks inject exits 1 rather than printing success when a managed adapter write is refused.

  • New kept-agent unit regression was red before the fix. Kiro/hook-command unit files: 54 passed. Real built-CLI lifecycle/migration E2E: 1 passed, including personal hook preservation and refusal of a foreign standalone file. Build, type checking and lint passed.

  • Kiro itself and Windows were unavailable. Kiro 2.x remains intentionally unsupported, as approved by jeff-r2026.

  • Follow-up review: a new two-project regression failed before registry discovery was added. The final real-CLI run verifies a registered project B is migrated while installing the shared hook from another scope, without creating or healing its configuration.

  • CI follow-up: Ubuntu Node 20 passed 15,252 tests but failed an unrelated session-sync-pull temporary Git object-directory cleanup with ENOTEMPTY. The complete 27-test file passes locally. The Actions retry API is not permitted for this account, so a code-free CI commit retriggers verification; no Kiro behavior or test assertion was changed.

The PR description contains the updated verification record. Ready for another review.

@github-actions

Copy link
Copy Markdown

No new findings I’m confident are real in the specified diff.

  • Resolved: The earlier cross-project migration finding is addressed by discovering registered projects, linked worktrees, and configured agent locations before enabling the shared hook. Regression coverage includes project B.
  • Testing: The PR description documents sufficient testing, including a representative real built-CLI lifecycle/migration E2E run. Disclosed unavailable live Kiro, Windows, and additional provider coverage is not blocking.

Review was read-only and limited to the specified diff; I did not run, build, or install PR code.

@nateEc
nateEc force-pushed the fix/1221-kiro-standalone-hooks branch from 911d827 to 144af8a Compare October 24, 2026 18:06
@nateEc

nateEc commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the review follow-up at 144af8a4df9d0e25d6233f1d56a0b9329ad06f43 on current main.

  • Implemented the accepted V3 migration decision. Before enabling the standalone hook, injection removes only the exact legacy TeamAI agentSpawn command from existing user and registered-project Kiro agents (including linked worktrees and configured agent locations), including edited copies; personal prompts, hooks and other fields remain.

  • Doctor's check names the Kiro CLI V3 requirement. hooks inject exits 1 rather than printing success when a managed adapter write is refused.

  • New kept-agent unit regression was red before the fix. Kiro/hook-command unit files: 54 passed. Real built-CLI lifecycle/migration E2E: 1 passed, including personal hook preservation and refusal of a foreign standalone file. Build, type checking and lint passed.

  • Kiro itself and Windows were unavailable. Kiro 2.x remains intentionally unsupported, as approved by jeff-r2026.

  • Follow-up review: a new two-project regression failed before registry discovery was added. The final real-CLI run verifies a registered project B is migrated while installing the shared hook from another scope, without creating or healing its configuration.

  • CI follow-up: Ubuntu Node 20 passed 15,252 tests but failed an unrelated session-sync-pull temporary Git object-directory cleanup with ENOTEMPTY. The complete 27-test file passes locally. The Actions retry API is not permitted for this account. A code-free retry commit was attempted; the later main rebase carries the current CI rerun. No Kiro behavior or test assertion was changed.

  • Rebased again onto main a26f74d after fix(hooks): launch OpenCode through the installed Node entry #1336 merged; retained both sides of the documentation conflict. Final rebase verification: 54 focused unit tests, 1 built-CLI E2E case, build, types and lint passed.

The PR description contains the updated verification record. Ready for another review.

@github-actions

Copy link
Copy Markdown

No new findings I’m confident are real in the specified diff.

  • Resolved: The earlier cross-project migration finding is addressed by discovering registered projects, linked worktrees, and configured agent locations before enabling the shared hook. Regression coverage includes project B.
  • Testing: The PR description documents sufficient testing, including a representative built-CLI lifecycle/migration E2E run. Disclosed unavailable live Kiro, Windows, and additional provider coverage is not blocking.

Review was read-only and limited to the specified diff; I did not run, build, or install PR code.

@SaulMoro

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

@jeff-r2026 @nateEc Re-checked at 144af8a against the decision above. The code is ready. The only thing blocking is the rebase.

  • The kept-agent duplicate is fixed. With the built CLI, a member-edited Kiro agent on 7fde26a kept teamai's old agentSpawn entry next to the standalone hook, so session-start dispatched twice. On this head the entry is migrated out and it dispatches once. The Kiro e2e fails on the base and passes here.
  • The doctor check now says it requires Kiro CLI V3, and hooks inject exits 1 when the write is refused instead of printing success.
  • Build, tsc, lint and the Kiro tests pass. A trial merge with current main builds and passes them too.

[P1 blocking] It conflicts with main (5dc075f) in docs/guide/reference.md, docs/guide/zh-CN/reference.md and skill-data/core/references/troubleshooting.md. The code merges cleanly. The troubleshooting conflict is the same append-at-end conflict the other open PRs have, and keeping both sections resolves it.

  • [P2 non-blocking] The comment at src/types.ts:505-508 still says Kiro hooks are embedded as agentSpawn with no standalone surface.
  • [P3 nit] The migration matches the legacy command exactly while rendering matches by substring, so a Windows-rendered command might be missed (not reproduced). It rewrites the member's agent file with a plain writeFile. The body still carries the superseded 83f6d1d numbers and dates its follow-up 2026-10-25.

The CI review reports no new findings. We agree there is no code P1, but it did not see the conflict or the types.ts comment. All CI jobs pass, and the earlier session-sync-pull flake is green.

- Install the Kiro CLI V3 standalone SessionStart hook for every agent, including the default agent, without requiring any team agent.
- Integrate the owned artifact into injection, listing, doctor, explicit removal and scope-aware uninstall while preserving personal hook files.
- Remove only the legacy managed agentSpawn entry from rendered agents to avoid duplicate dispatch; document the V3 lifecycle requirement in both languages.
- Verify 54 adapter/rendering/list tests, a built-CLI pull/list/doctor/remove/inject/uninstall scenario, type checking and lint; live Kiro is unavailable locally.

BREAKING CHANGE: Kiro lifecycle hooks now require Kiro CLI V3; upgrade before relying on automatic session-start synchronization.
- 安装 V3 独立 hook 前,从用户及当前项目 agent 中移除精确匹配的旧 TeamAI agentSpawn 命令,保留成员提示词、个人 hooks 和其他字段。
- hooks inject 在写入被拒绝时返回失败,doctor 的检查名称明确标注 Kiro CLI V3 要求,并同步中英文迁移说明。
- 新单测在修复前复现重复入口;53 个相关单测、真实 CLI 生命周期与拒绝写入用例,以及构建、类型检查和 lint 通过。
- 启用用户全局 hook 前扫描已注册项目及关联 worktree,同时通过统一定位接口覆盖配置过的 agent 目录。
- 配置发现保持只读,不触发自愈;仅删除精确匹配的旧 TeamAI 命令,保留其他项目的成员内容和个人 hooks。
- 两项目回归在修复前失败;54 个相关单测和跨项目真实 CLI 生命周期用例通过,构建、类型检查和 lint 通过。
- Ubuntu Node 20 在 session-sync-pull 测试清理临时 Git objects 目录时出现 ENOTEMPTY,其余 15252 项测试通过。
- 本地完整复查该测试文件的 27 项用例全部通过;本提交不修改产品代码,重新触发 CI 验证偶发清理失败。
- GitHub Actions 重跑接口因权限不足拒绝请求,因此通过分支提交触发同一验证流程。
- 将配置注释改为独立 V3 会话启动文件,说明旧 agentSpawn 入口仅用于迁移。
- 406 项定向单测及独立 Kiro hook CLI 场景通过,类型、lint 与构建通过。
@nateEc
nateEc force-pushed the fix/1221-kiro-standalone-hooks branch from 144af8a to 17b3bb4 Compare October 26, 2026 04:38
@github-actions

Copy link
Copy Markdown

No new findings I’m confident are real in the specified diff.

  • Resolved: The earlier cross-project migration finding is addressed by discovering registered projects, linked worktrees, and configured agent locations before enabling the shared hook. Regression coverage includes project B.
  • Testing: The PR description documents sufficient testing, including a representative built-CLI lifecycle/migration E2E run. Disclosed unavailable live Kiro, Windows, and additional provider coverage is not blocking.

Review was read-only and limited to the specified diff and trusted base criteria; I 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. Rebase and retain both troubleshooting sections. Update the obsolete type comment to describe standalone V3 session hooks and legacy agentSpawn migration. Preserve the previously reviewed cleanup of legacy entries in active and kept agent copies.

Verification: 406 focused unit tests passed; types, lint and build passed. Post-build real-CLI kiro-standalone-hooks: 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: 17b3bb45.

@SaulMoro

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

@jeff-r2026 @nateEc Re-checked at 17b3bb4 against the decision above. Everything is in place. The kept-agent duplicate is fixed, and the Kiro e2e with the real CLI passes. The doctor check names the V3 requirement, and hooks inject exits 1 on a refused write. Since 144af8a the only content change is the types.ts comment. Build, tsc, lint, the related unit files (3181 tests) and the Kiro e2e pass, and CI is green at this head.

It conflicts with main again in skill-data/core/references/troubleshooting.md after today's merges (#1340, #1337). Please rebase once more; we will merge as soon as CI is green on the rebased head.

Two nits for a later Kiro change: migration matches the legacy command exactly (src/kiro-hooks.ts:83-84) while rendering matches by substring (src/resources/agent-format.ts:220-221); and pull turns a Kiro injection failure into a warning and exits 0 (src/hooks.ts:3018-3021), where hooks inject exits 1.

@github-actions

Copy link
Copy Markdown

No new findings I’m confident are real in the specified diff.

  • Resolved: The earlier cross-project migration finding is addressed by scanning registered projects, linked worktrees, and configured agent locations before enabling the shared hook. Regression coverage includes project B.
  • Testing: The PR description documents sufficient testing, including a representative real-CLI E2E run after building. Disclosed unavailable live applications, Windows, and additional provider coverage is not blocking.

Review was read-only and limited to the specified diff and trusted base criteria. I did not run, build, or install PR code.

…ectory

legacyAgentDirs read every scope through readConfigFrom, which only loads
project partitions, so a user-scope toolPaths.kiro.agents directory was never
searched and its agents kept the old agentSpawn dispatcher next to the new
standalone hook. Load the user config with loadLocalConfig.
# Conflicts:
#	skill-data/core/references/troubleshooting.md
@github-actions

Copy link
Copy Markdown

No new findings I’m confident are real in the specified diff.

  • Resolved: The earlier cross-project migration finding is addressed by scanning registered projects, linked worktrees, and configured agent directories before enabling the shared hook. Regression coverage includes project B and user-scope custom agent paths.
  • Testing: The PR description documents sufficient testing, including representative built-CLI E2E and migration runs. Disclosed unavailable live applications, Windows, and additional provider coverage is not blocking.

Review was read-only and limited to the specified diff and trusted base criteria. I 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.

Thanks @nateEc. I merged main twice to clear the troubleshooting.md conflicts (keeping every section), and fixed one gap: legacyAgentDirs read the user scope through readConfigFrom, which only loads project partitions, so a user-scope custom toolPaths.kiro.agents directory kept the old agentSpawn dispatcher next to the new hook. It now loads the user config with loadLocalConfig, with a unit case and a real-CLI run in the description. CI is green at e16c992.

@SaulMoro
SaulMoro merged commit 4cb2b3c into Tencent:main Oct 26, 2026
18 checks passed
hz89Dev pushed a commit to hz89Dev/teamai-cli that referenced this pull request Oct 27, 2026
…encent#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.
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
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