Skip to content

fix(hooks): unify hook-injection scope so project-scope init installs the SessionStart hook - #370

Merged
jeff-r2026 merged 3 commits into
mainfrom
pr-fix-project-hook-home
Sep 1, 2026
Merged

jeff-r2026 merged 3 commits into
mainfrom
pr-fix-project-hook-home

Conversation

@jeff-r2026

Copy link
Copy Markdown
Collaborator

Problem

Opening Claude Code in a project-scope install did not auto-pull team skills, and teamai doctor reported two checks failing even right after a successful teamai init:

✖ teamai hooks in claude settings
✖ Env variables injected in shell profile

Root cause

Hook injection had two divergent code paths that had drifted:

On a fresh project-scope init, <projectRoot>/.claude does not exist yet. The reconcileHooksToAllTools "only inject into installed tools" gate (if (!await pathExists(toolRoot)) continue) therefore skipped every tool, so the SessionStart hook was never written anywhere. That hook is what triggers the background teamai pull on each session start — with no hook, skills never auto-sync, and the env variables (a downstream effect of pull) never get injected either.

doctor compounded the confusion: it also resolved to <projectRoot> via resolveBaseDir, so it checked <projectRoot>/.claude for hooks that (when they do exist, e.g. after a manual hooks inject) actually live in ~/.claude — always reporting them missing.

Fix

Introduce a single source of truth, resolveHookScope(localConfig) in src/types.ts, returning the (baseDir, manifestPath) pair every injection path must share, and route init/pull (hooks.ts), the hooks command (hooks-cmd.ts), and doctor (doctor.ts) through it:

This aligns the implementation to the already-documented HOME behavior (see docs/usage-guide.md: settings.json hooks "live in HOME and gate on the cwd handed to hook-dispatch"). No doc changes needed — grepped to confirm nothing describes the old <projectRoot> behavior.

Test Plan

All executed and passing on this branch (rebased onto Tencent/teamai-cli@main):

  • npx tsc --noEmit — clean
  • npm run build — success
  • npx vitest run — 2408 passed (175 files)
  • hooks-reconcile-scope + doctor unit tests — 15 passed. Rewrote the scope test to stub HOME to a sandbox and assert project-scope injection lands in HOME; added a self-mode regression locking injection to projectRoot.
  • Real CLI end-to-end (built dist, project-scope config, <projectRoot>/.claude absent to reproduce the bug):
    • teamai hooks inject → ✔ Updated teamai hooks in <HOME>/.claude/settings.json; the file contains the SessionStart hook-dispatch session-start entry + the team hook; <projectRoot>/.claude is not created.
    • teamai doctor → ✔ teamai hooks in claude settings (previously ✖).

Notes

… the SessionStart hook

Project-scope `teamai init`/`pull`/`bootstrap` resolved the hook base dir
via resolveBaseDir → <projectRoot>, but on a fresh init <projectRoot>/.claude
does not exist yet, so the "only inject into installed tools" gate skipped
every tool. Result: no SessionStart hook was written anywhere, so opening
Claude never triggered the background `teamai pull` and skills never
auto-synced. `teamai doctor` then checked <projectRoot>/.claude too and
always reported the hooks missing.

Meanwhile the `hooks inject` command already wrote to HOME (#264). The two
paths had drifted.

Introduce `resolveHookScope(localConfig)` in types.ts as the single source
of truth for the (baseDir, manifestPath) pair, and route init/pull
(hooks.ts), the hooks command (hooks-cmd.ts), and doctor (doctor.ts)
through it:
- non-self project scope → HOME (~/.claude always exists, the dispatch
  runtime resolves the active project by cwd) — matches #264
- self single-repo mode → projectRoot (hooks committed to main travel on
  clone and self-heal)
- user scope → HOME

Tests: rewrite hooks-reconcile-scope to stub HOME to a sandbox and assert
project-scope injection lands in HOME; add a self-mode regression that
locks injection to projectRoot. Verified end-to-end with the real CLI:
project-scope `hooks inject` writes the SessionStart hook to
~/.claude/settings.json (not <projectRoot>/.claude) and `doctor` now passes.
@jeff-r2026

Copy link
Copy Markdown
Collaborator Author

Reviewed this at depth. The resolveHookScope abstraction is the right call — my concerns are that the unification is incomplete (three hook-writing paths still bypass it) and that redirecting project scope to HOME has scope-isolation consequences the PR doesn't address. Grouping by whether I think it should block the merge.

Blocking

1. teamai uninstall can no longer find the hooks this PR writes.
buildRemovalPlan still resolves via resolveBaseDir(localConfig) (src/uninstall.ts:345) and getManagedHooksPath(localConfig.scope, projectRoot) (src/uninstall.ts:378), so in a non-self project scope it scans <projectRoot>/.claude/settings.json while injection now targets ~/.claude/settings.json. uninstall --force reports success and leaves the SessionStart hook live forever; once the binary is gone it fails on every session start. Note baseDir there is also used for skills/rules/agents, which correctly stay at projectRoot — so the fix is a separate hook base dir via resolveHookScope, not swapping baseDir.

2. No migration for existing <projectRoot>/.claude/settings.json entries.
Every project-scope user who ran the old init/pull already has hooks at <projectRoot>. The new HOME target never touches that file, so after upgrading both copies are live: Claude Code merges user + project settings, and every session start fires teamai hook-dispatch session-start twice (two concurrent background pulls), plus every team hook twice. hooksRemove already carries an explicit legacy-cleanup block for exactly this state (src/hooks-cmd.ts:160-163) — the inject path needs the equivalent sweep.

Worth doing in this PR (cheap)

3. doctor change is untested. The doctor regression leads the problem statement, but detectProjectConfig is mocked to null (src/__tests__/doctor.test.ts:8) and mockLocalConfig has no scope field (:45), so resolveHookScope always takes the getUserHome() branch. Reverting src/doctor.ts:92 to resolveBaseDir leaves the suite green. One project-scope assertion (and a self-mode one) would lock both branches, mirroring what the new hooks-reconcile-scope test does for injection.

4. Docs now describe the old behavior. docs/usage-guide.md:303 still states "User env, hooks, MCP definitions, sources, reporting, and writes remain isolated in project mode" — with project team hooks landing in ~/.claude/settings.json that isolation no longer holds. CLAUDE.md requires docs to move with behavior changes, and both language versions need it.

5. resolveHookScopeTargets is now a dead abstraction. It wraps a single value in an array, and HookScopeTarget (src/hooks-cmd.ts:19-22) restates the type resolveHookScope already declares. Three call sites still loop/map over a guaranteed one-element array (:79, :104, :154). Destructuring directly drops ~15 lines and makes the single-target invariant obvious — which is the point of the PR.

Real, but fine to track separately

6. Project team hooks now execute machine-wide, and collide across projects. Team hooks from hooks/hooks.yaml are injected verbatim (not routed through the cwd-gated hook-dispatch), so a project's npm run lint Stop hook now runs in every session on the machine. Worse, all project scopes share one settings file and one manifest (~/.teamai/managed-hooks.json), and isManaged() (src/hooks.ts:281) strips any [teamai:hook: entry regardless of who wrote it — so a session in project B deletes project A's team hooks, and vice versa.

In fairness this isn't introduced here: #264 already pointed hooks inject at HOME. This PR promotes it from a rarely-run command to the init/pull main path, so it goes from theoretical to everyday. The real fix (cwd-gating team hooks, or namespacing the manifest per project) is out of scope — worth its own issue.

7. autoMigrateHooksIfNeeded still bypasses resolveHookScope (src/pull.ts:1208). It detects the legacy format by reading ~/.claude/settings.json (:1184) but re-injects into resolveBaseDir → <projectRoot>. The two targets are now different files, so the guard at :1191 never becomes true: the migration re-fires on every pull, never fixes HOME, and re-creates the <projectRoot> copy this PR is removing. Pre-existing, but it undercuts the "single source of truth" claim.

8. OpenCode's stale project-plugin cleanup is now dead code. reconcileOpencodePlugin deletes <projectRoot>/.opencode/plugin/teamai-hooks.ts only when path.resolve(baseDir) !== path.resolve(home) (src/hooks.ts:767). Project scope was the only caller passing a non-HOME baseDir; it now passes HOME, so a leftover project copy survives and OpenCode dispatches every event twice — exactly what docs/usage-guide.md:986 says is prevented.

9. hooks remove in self mode: duplicate work, wrong target. The legacy block fires for any scope === 'project', but resolveHookScope now returns (projectRoot, project manifest) for self mode — identical to the primary target, so it runs twice — while HOME, where the pre-PR hooks inject put self-mode hooks, is never swept. Gate it on the target actually differing from resolveHookScope(...).baseDir.

10. The installed-tool gate is now keyed on HOME while resources still deploy to projectRoot. A project carrying <projectRoot>/.cursor/ on a machine without ~/.cursor gets skills and rules but no hooks anywhere — the mirror image of the bug being fixed. Same on a machine with no ~/.claude at all, where the comment's premise that it "always exists" doesn't hold.

11. resolveHookScope throws for self mode without projectRoot. It falls through to resolveBaseDir + getManagedHooksPath, both of which throw when scope === 'project' and projectRoot is absent (it's optional in LocalConfigSchema). The old hooks-cmd code returned HOME for every project scope without touching it, so hooks inject/list/remove — and doctor via src/doctor.ts:92 — now abort on a config that previously degraded gracefully. Minor, but doctor crashing on a broken config is the wrong failure mode.


Verified locally on this branch: npx tsc --noEmit clean, and hooks-reconcile-scope / hooks-cmd / doctor / pull-scope-isolation are 35/35 green — none of the above is caught by existing tests. Also worth noting hooks-team-e2e.test.ts is excluded from the default vitest run and only covers user scope, so it won't catch these either.

…, tests

Follows up the resolveHookScope unification with the paths that still
bypassed it and the cheap review items.

- uninstall (#1, blocking): buildRemovalPlan discovers hooks at the
  resolveHookScope target (HOME + user manifest for a non-self project
  scope) instead of <projectRoot>, so uninstall no longer leaves the
  SessionStart hook live in HOME forever; a legacy <projectRoot> copy is
  swept too, each hookFile tagged with its own manifest.
- inject legacy sweep (#2, blocking): reconcileTeamHooksForConfig
  (init/pull/bootstrap) and hooks inject now clear the legacy
  <projectRoot> copy after writing HOME, so an upgraded project does not
  fire hook-dispatch twice.
- doctor tests (#3): lock the project-scope→HOME and self→projectRoot
  branches of resolveHookScope.
- docs (#4): usage-guide.md/.zh-CN note hooks are no longer isolated in
  project mode (injected into HOME; self mode keeps them in the repo).
- dead abstraction (#5): drop resolveHookScopeTargets/HookScopeTarget;
  hooks-cmd destructures resolveHookScope directly.
- autoMigrateHooksIfNeeded (#7): reinject via resolveHookScope so the
  HOME old-format guard converges instead of re-firing every pull.
- hooks remove self mode (#9): gate the legacy sweep to a project-owned
  <projectRoot> (resolveLegacyProjectHookScope), never HOME (shared with
  user scope) and never a redundant re-run on the primary target.
- resolveHookScope robustness (#11): self mode missing projectRoot now
  degrades to HOME instead of throwing, so doctor never crashes.

Architectural findings (#6 machine-wide team hooks + cross-project
manifest collision, #8 OpenCode stale project cleanup, #10 gate/resource
base-dir split) are tracked separately.
@jeff-r2026

Copy link
Copy Markdown
Collaborator Author

Thanks for the deep review — this was exactly the right set of gaps. Addressed in 55bb863. Grouping by your own categories.

Blocking — fixed

1. uninstall now targets where hooks are actually injected. buildRemovalPlan discovers hooks via resolveHookScope (HOME + user manifest for a non-self project scope) rather than resolveBaseDir → <projectRoot>, so the SessionStart hook is no longer left live in HOME forever. As you noted, baseDir stays at projectRoot for skills/rules/agents — only the hook base dir moved. It also sweeps a legacy <projectRoot> copy in the same pass; each hookFile now carries its own manifestPath so team hooks are stripped correctly at both locations. Locked by a new uninstall.test.ts regression (asserts removal targets HOME, not <projectRoot>).

2. Migration sweep on the inject path. reconcileTeamHooksForConfig (init/pull/bootstrap) and hooks inject now clear the legacy <projectRoot> copy after writing HOME, mirroring the hooksRemove legacy block. Verified end-to-end: with a stale <projectRoot>/.claude/settings.json present, a re-run prints ✔ Removed teamai hooks in <projectRoot>/.claude/settings.json and leaves only HOME's copy — no more double hook-dispatch.

Worth doing in this PR — done

3. doctor change is now tested. Two cases in doctor.test.ts set scope: 'project' (+ a self-mode variant with repo.kind: 'self') and stub the hooks into HOME vs <projectRoot> respectively, asserting the teamai hooks in claude settings check passes only because doctor looks at the right location. Reverting doctor.ts to resolveBaseDir now fails the suite.

4. Docs updated. docs/usage-guide.md:303 / .zh-CN.md:301 and the FAQ (:1176 / :1171) no longer claim hooks stay isolated in project mode — they now state a non-self project scope injects hooks into HOME (dispatch gates on cwd), and self mode keeps them in the business repo. Both languages.

5. Dead abstraction removed. resolveHookScopeTargets and HookScopeTarget are gone; hooks-cmd destructures resolveHookScope directly at all three call sites.

Tracked separately (cheap ones fixed here anyway)

7. autoMigrateHooksIfNeeded now reinjects via resolveHookScope, so the HOME old-format guard converges instead of re-firing every pull and re-creating the <projectRoot> copy.

9. hooks remove self mode. The legacy sweep is now gated through resolveLegacyProjectHookScope, which returns a target only for a non-self project scope (a project-owned <projectRoot>). Self mode no longer double-runs on its primary target. Note I deliberately do not sweep HOME for self mode: HOME is shared with any user-scope install and its user manifest, so a blind removeAll there would clobber genuine user-scope hooks — that cross-scope collision is #6's territory. New self-mode test asserts a single removal.

11. resolveHookScope robustness. Self mode missing projectRoot now degrades to HOME instead of throwing, so doctor (and hooks list/inject/remove) never abort on a partially-broken config.

6, 8, 10 — architectural, filed as #373. Machine-wide team-hook execution + cross-project manifest collision (needs cwd-gating or per-project manifest namespacing), OpenCode's now-dead project-plugin cleanup (needs projectRoot threaded into reconcileOpencodePlugin), and the installed-tool gate being keyed on HOME while resources deploy to projectRoot. Agreed these predate this PR / need their own design.

Full suite: 2412 passed (175 files). tsc clean. Real-CLI E2E in a sandbox HOME confirmed inject→HOME (no <projectRoot> copy), legacy sweep, doctor ✔, and project-scope uninstall --force clearing the HOME hook.

@jeff-r2026 jeff-r2026 self-assigned this Sep 1, 2026
The #370 review follow-up introduced a <projectRoot> legacy sweep via
reconcileHooksToAllTools(removeAll). Two tools do not honour its baseDir,
so for a non-self project scope the sweep undid the primary pass:

- Hermes reconciles through removeHermesHooks(), which takes no base dir
  at all, and OpenCode through an adapter whose removeAll branch always
  targets HOME. Injecting installed ~/.config/opencode/plugin/teamai-hooks.ts
  and $HERMES_HOME/hooks/teamai-status-report.sh; the sweep then deleted
  both. Every init/pull/hooks inject repeated the install-then-delete, so
  those two tools ended up with no teamai hooks at all.
- resolveLegacyProjectHookScope did not check projectRoot against HOME, so
  `teamai init .` run in ~ (dotfiles repo) made the "legacy" location and
  the live target the same file — the sweep stripped every hook just
  written, reproducing the very bug #370 fixes.

Fixes:
- Add `settingsOnly` to reconcileHooksToAllTools, skipping the two global
  adapters, and extract the shared sweepLegacyProjectHooks() used by
  init/pull/bootstrap, `hooks inject` and `hooks remove`. It removes the
  project-scope OpenCode plugin directly, so the stale <projectRoot> copy
  is still cleaned without touching the HOME one.
- resolveLegacyProjectHookScope returns null when projectRoot resolves to
  HOME, making the "never returns HOME" invariant callers rely on hold.
- Drop filterAgents from the sweep: cleanup of a legacy location must be
  unconditional, or a tool disabled today strands the copy it wrote while
  it was enabled.

Tests: 4 disk-level cases in hooks-reconcile-scope (HOME OpenCode/Hermes
survive, legacy project plugin still removed, filtered-out tool still
swept, projectRoot===HOME not wiped) — all 4 fail without this change; 5
resolveLegacyProjectHookScope unit cases in types.test; hooks-cmd updated
for the extracted helper.

Verified: tsc clean, 2421 tests pass, and a real CLI run against a
sandbox HOME + project-scope config with pre-seeded legacy state —
inject keeps HOME's claude/cursor/opencode/hermes hooks, clears
<projectRoot>/.claude and <projectRoot>/.opencode, doctor reports both
checks green, a second inject is idempotent, projectRoot===HOME keeps its
SessionStart hook, and `hooks remove` clears everything including Hermes
and OpenCode.
@jeff-r2026
jeff-r2026 merged commit e9ba926 into main Sep 1, 2026
7 checks passed
@jeff-r2026
jeff-r2026 deleted the pr-fix-project-hook-home branch September 1, 2026 07:22
SaulMoro added a commit to SaulMoro/teamai-cli that referenced this pull request Oct 7, 2026
…the working tree (Tencent#993)

getManagedHooksPath built <root>/.teamai/managed-hooks.json in project
scope, so the Copilot hook index showed up untracked in every git project
and self mode committed it with git add -A. It now resolves per checkout to
<dataHome>/workspaces/<id>/managed-hooks.json, beside managed-mcp.json.
legacyManagedHooksPath names the old file for the pre-Tencent#370 Codex import,
the legacy hook sweep and uninstall. migrateLegacyManagedHooks moves its
Copilot records (all records in self mode) before hooks are reconciled,
removed or uninstalled, and deletes it once empty and untracked; doctor
names a tracked one with the git rm --cached command.

teamai.lock moves to the data home too (packageLockDir): an older
.teamai/teamai.lock is moved on the next install or session-start read,
doctor reads it where it is, and a .teamai/.gitignore holding only
teamai.lock is removed outside self mode. Self mode's .teamai/.gitignore
lists managed-hooks.json, also through its migration.
jeff-r2026 pushed a commit that referenced this pull request Oct 9, 2026
* fix(opencode): add team rules and instructions to V2 sessions through the plugin

OpenCode V2 parses `instructions` and ignores it, so a V2 session got none
of the team rules or the culture, claudemd and recall blocks. The teamai
plugin's V2 setup now registers the session context and compaction hooks
and adds the user instruction file and rules, then the nearest project's
.opencode/teamai-context.md and .opencode/rules/**/*.md, sorted by path.
V1 delivery through `instructions` is unchanged. (#993)

* fix(opencode): write the user instruction file beside the Claude fallback for V2

OpenCode V1 reads ~/.claude/CLAUDE.md while ~/.config/opencode/AGENTS.md
does not exist, so teamai wrote no OpenCode user file there. V2 reads
neither that fallback nor `instructions`. Pull and HTTP prompts now
write ~/.config/opencode/teamai-context.md for teamai's plugin in that
case too, and still list it nowhere, so V1 gets no duplicate. (#993)

* fix(init): set up only the --agent tools in single-repo init (#993)

init . wrote .teamai/teamai.yaml (mode: self) before it read the existing
project config. With the marker on disk and no config yet, that read ran the
clone-time self-heal, which enabled every tool found in HOME, injected their
hooks into the repo and saved them; init then merged --agent into that.

Read the config once, before the marker is written, and use that snapshot for
inheriting user scope, the enabledAgents union, the tool-roots carry-over and
the mode-switch settlement.

* fix(coauthor): keep the project-scope co-author setting out of shared settings (#993)

In project scope only claude writes attribution, to the member-local
.claude/settings.local.json; the rest of the Claude settings family is
user-scope only, like Codex and Cursor. The next pull removes an
attribution an earlier release wrote to a shared project settings file
when it is exactly teamai's value and the co-author record lists the
file, deleting only that member's text.

* docs(coauthor): note a pre-fix shared value stays while no co-author choice exists (#993)

* fix(doctor): check OpenCode V2 delivery from the teamai plugin

doctor reported the team rules and instructions active on OpenCode V2
because `instructions` listed them, but V2 ignores that key. doctor now
reads the major version from `opencode --version` (missing or unparsable
counts as V1) and, on V2, checks that teamai's plugin in HOME is the one
this build writes, since its context hook is what delivers them. V1
checks are unchanged. The usage guide describes V2 delivery. (#993)

* fix(pull): probe live checkouts from recorded roots, not the worktree list (#993)

A pull in a linked worktree of a --separate-git-dir repo or a submodule
dropped the main checkout's delivery record and workspaces/<id>/, because
git worktree list names the git directory there instead of the main
checkout. Its next pull then overwrote edited rules without a word.

Records and workspace directories now store their checkout root; a full
pull keeps one while that root still has a .git, names the same git common
dir, and (records) gives the same checkoutKey, so a re-created worktree
still starts fresh (#807). Entries without a root (older CLI) are kept.
listWorktrees reads --porcelain -z, skipping bare, prunable and common-dir
entries, and returns [] when -z is unsupported instead of splitting lines.

* fix(init): skip the clone-time self-heal for init in a single-repo clone (#993)

A fresh clone whose committed .teamai/teamai.yaml says mode: self ran the
self-heal in the preAction queue check and again in initSelfRepo's config
read. Either one enabled every tool found in HOME before --agent could
choose. init now loads with selfHeal: false in both places; every other
command still self-heals.

* fix(sync): adopt config entries that equal a team render, keep the member's (#993)

An MCP server or a team hook entry teamai has no record of is teamai's
only when it equals teamai's render of a team server or hook, today or at
any revision in the team repo's history (one hook only). It is then
adopted and handled as recorded. Any other one is the member's: kept and
named by pull and doctor; a member's same-name MCP server means the team
server is not written to that file. `pull --force` no longer overwrites
a member's server (`teamai mcp inject --force` still does).

This removes the second copy of each team hook a lost hook manifest
caused in .claude/settings.local.json and .codex/hooks.json.

* docs(sync): describe ownership of unrecorded MCP servers and hook entries (#993)

* test(init): cover init . in a single-repo clone with no --agent and no terminal (#993)

With the clone self-heal skipped for init, a fresh clone has no config when
init runs. Pin that it takes the non-interactive default (the tools found in
HOME) instead of prompting or stopping at "already initialized".

* test(hooks): cover hook ownership beside the co-author setting in settings.local.json (#993)

* fix(pull): prune a workspace directory without a root only when the worktree list names every checkout (#993)

contribute, recall, viz, the MCP writers and the local agent create a
checkout's workspaces/<id>/ before its first full pull writes root, so a
removed worktree that never ran a full pull kept its directory forever
(self-mode-worktrees-808). Such a directory now goes when git worktree list
-z names every checkout (no non-bare entry is the common dir) and none has
its id, as git prints it or realpath'd. It is kept with --separate-git-dir,
in a submodule, on git < 2.36, and when it holds local-agent/.

* fix(mcp): create a missing .git/info/ before excluding a resolved MCP config (#993)

A repository created with an empty template has no .git/info/. The
writability check ran `access(W_OK)` on that directory, got ENOENT, and
reported it as "not writable", so every team MCP server holding a
resolved value was withheld.

Check the exclude file when it exists, otherwise its closest existing
directory, and let the write create info/. Report "not writable" only
for EACCES, EPERM and EROFS, and name the exclude file in the reason and
the fix. Applies to pull, doctor, `mcp list` and local-agent installs,
which share ensureExcludedFromGit.

* fix(mcp): write CodeBuddy's user MCP servers to the file CodeBuddy reads (#993)

CodeBuddy reads only the first user MCP file that exists of
~/.codebuddy/.mcp.json, ~/.codebuddy/mcp.json and ~/.codebuddy.json, and
teamai always wrote the second, so team servers and the member's own hid
each other. In user scope teamai now writes to that first existing file and
creates ~/.codebuddy/.mcp.json only when none exists. Each CodeBuddy record
in managed-mcp.json names its file; a pull moves teamai's own entries out of
a file CodeBuddy no longer reads, uninstall and `teamai mcp remove` follow
the record, and doctor and `teamai mcp list` name a shadowed file.

* fix(local-agent): install CodeBuddy's user MCP servers in the file CodeBuddy reads (#993)

An HTTP-backed team's install_mcp now writes CodeBuddy's user servers to the first existing file of CodeBuddy's lookup order, as a pull does, and records that file. A reinstall moves a server an earlier install left in a file CodeBuddy no longer reads; uninstall_mcp removes it from the recorded file.

* fix(migrate): move the team clone's last-fetch stamp out of a superseded install (#993)

A linked worktree whose old git-mode install another checkout superseded
by switching to single-repo mode keeps the team knowledge in .teamai/ and
moves only SUPERSEDED_ENTRIES to .teamai.bak. #964 added last-fetch.json
beside the clone, which that list did not name, so it stayed in .teamai/
as an untracked file. The 808 fixture now writes the stamp a #964 release
leaves, so the case fails without the fix whatever teamai the developer
has installed.

* fix(hooks): keep the managed-hooks index and the package lock out of the working tree (#993)

getManagedHooksPath built <root>/.teamai/managed-hooks.json in project
scope, so the Copilot hook index showed up untracked in every git project
and self mode committed it with git add -A. It now resolves per checkout to
<dataHome>/workspaces/<id>/managed-hooks.json, beside managed-mcp.json.
legacyManagedHooksPath names the old file for the pre-#370 Codex import,
the legacy hook sweep and uninstall. migrateLegacyManagedHooks moves its
Copilot records (all records in self mode) before hooks are reconciled,
removed or uninstalled, and deletes it once empty and untracked; doctor
names a tracked one with the git rm --cached command.

teamai.lock moves to the data home too (packageLockDir): an older
.teamai/teamai.lock is moved on the next install or session-start read,
doctor reads it where it is, and a .teamai/.gitignore holding only
teamai.lock is removed outside self mode. Self mode's .teamai/.gitignore
lists managed-hooks.json, also through its migration.

* fix(pull): keep a rule or agent file teamai cannot prove its own (#993)

A rule or agent destination that exists with no delivery record is
teamai's only when its bytes equal teamai's render of that resource at
some revision of the team repo's history (git blob ids, through ticket
04's matchesHistory). Otherwise it is the member's: pull neither writes
nor deletes it, names it, and doctor lists it. This covers a checkout
whose record key changed (a restore or copy gives .git a new inode), a
role switch after that, and a member's own file with a team name.

- DeliveryTarget.origin carries the proof; judgeCopy gains a 'member'
  verdict; isTeamaiCopy and describeMembersFile are the shared seam.
- The rules stale sweep and the tombstone cleanup prove an unrecorded
  copy before deleting it.
- A kept copy is worded as an edit when another checkout record lists
  its path (a record lost to a new key); no record is carried over.
- A pull that keeps a member's file does not count as synced, so a
  plain pull delivers the team version once the file is gone.

* fix(mcp): leave an older teamai's ~/.codebuddy/mcp.json that hides ~/.codebuddy.json (#993)

Earlier releases always created ~/.codebuddy/mcp.json, so a member's servers in ~/.codebuddy.json stayed hidden. When that file holds only teamai's servers (recorded, or equal to a team render) and a later file of CodeBuddy's lookup order exists, a pull moves the servers there, deletes the file and says so once. A file that also holds a member's server or any other key stays chosen.

* fix(remove): judge rule copies by record and team history in teamai remove (#993)

teamai remove's rules refresh ran without the checkout's ledger, so it
wrote over a member's own file at a team rule's path, and its explicit
sweep deleted a member's own file named after the removed rule. It now
opens the ledger, passes it to the refresh and names what it kept, and
deletes a copy of the removed rule only when it is on record or its
bytes are a version from the team history (the author's root copy keeps
its placement record as proof). Docs say a personal rule the team never
had is kept, and that a pull keeping a member's file syncs in full until
it is gone.

* fix(pull): keep a skill or doc teamai cannot prove its own (#993)

A skill directory with no delivery record is teamai's only when every file
in it is today's team file or a version of it from the team repo's history
(SKILL.md also as pull repairs its frontmatter); one file of the member's
makes the whole directory theirs. A file in the docs mirror at a team doc's
path is teamai's only when it is a version of that doc. Anything else is
kept and named, not written over or removed by the tombstone cleanup, and
doctor lists it. isTeamaiSkillCopy is the ledger-free decision ticket 05
reuses.

* docs(skill): keep the ownership sentence clear of the command check (#993)

* fix(rules): delete a legacy .md in .cursor/rules only when it is teamai's (#993)

Pull's stale sweep and pullItem deleted every .md in a .mdc tool's rules
directory, and uninstall every one with a team rule's name, as a copy of
the layout before .mdc. A member's own notes.md there went with them,
though the usage guide promised it stays. Each now deletes one only when
the checkout record lists it, it is a team version from the history
verbatim, or it has a built-in rule's name (isLegacyLayoutCopy); any
other is kept silently, since Cursor never reads it. teamai remove
already applies the proof since 02b.

* fix(coauthor): move a pre-fix attribution to settings.local.json when no choice exists (#993)

With no co-author choice (the team dropped sharing.coAuthor and the
member has none), the reconcile returned before settling shared project
files, so an attribution an earlier teamai wrote to a tracked
.claude/settings.json stayed there for git add -A to commit. The next
pull now moves it to .claude/settings.local.json under the same guards
(teamai's exact value, the record lists the file with "strip", only
that key is edited), so the member's trailer is unchanged and the
tracked file is clean. A value the member already set in
settings.local.json is kept. Other Claude-family tools' shared files
have no member-local counterpart and wait for a choice. A failed
settle now keeps its record so the next pull retries.

* fix(git): list sibling worktrees on git before 2.36 (#993)

listWorktrees read only `git worktree list --porcelain -z`, so on git
without -z it returned [] to every caller. A pull or uninstall then judged
the shared .git/info/exclude line from the current checkout alone and
dropped /.mcp.json while a sibling worktree's .mcp.json still held a
resolved value (#882/#886).

Fall back to the newline-split list when -z fails. Liveness is unchanged:
completeWorktreeList stays -z only and returns null there.

* fix(mcp): report an exclude directory teamai cannot create as not writable, not as a held lock (#993)

acquireLock returns false when it cannot create the lock's directory, so
updateFileLocked waited out 25 attempts and reported "another teamai
command held <file> past the wait". With .git/info a regular file, MCP
exclusion blamed a lock nobody held.

updateFileLocked now creates the file's directory before taking the
lock. EEXIST and ENOTDIR (a path on the way is not a directory) and
EACCES, EPERM and EROFS throw a NotWritableError naming the file and the
closest existing path above it, without waiting. ensureExcludedFromGit
reports it as "<exclude> is not writable, as <path> is not a directory"
and withholds the server as before. acquireLock's boolean contract is
unchanged for its other callers.

The e2e fixtures now use fresh paths per call, so a retried case
rebuilds them instead of failing on the first try's.

* docs(mcp): say an unrecorded entry under a name the team dropped is not adopted (#993)

MCP ownership adopts an unrecorded entry only under a server name the
team defines today, so a copy of a since-deleted team server stays as it
is. Say so in the usage guide's ownership paragraph, in both languages.

* fix(agents): prove an agent copy an older CLI rendered teamai's (#993)

The agent ownership proof accepted a team version verbatim or rendered as
pull renders it today, with today's aliases. Every member upgrading from
0.26.0 or earlier has no delivery record, and 0.26.0 rendered agents
differently: the spec's model as written (no aliases), and before #830
Qoder, Qoder CN, ZCode and OMP took Claude's tool_extras and tclaude and
tcodex only their base tool's. Such a copy read as the member's: never
updated, named on every pull, and every pull a full sync. agentOrigin now
also accepts the unresolved render and the pre-#830 extras render.

* fix(pull): keep a member's file when the team deletes the doc at its path (#993)

The docs mirror prune deleted every local file the team repo no longer has.
At a path the team once had a doc, it now deletes the file only when it is
a version of that doc from the team history; any other is kept and named,
and doctor no longer lists it as stale. A local-only file at a path the
team never had is pruned as before.

* test(e2e): isolate HOME and the teamai binary for fixture git

The git hooks teamai installs run `PATH="$HOME/.teamai/bin:$PATH" teamai
hook-dispatch ...`. E2E fixtures ran git with the real HOME and PATH, so a
fixture merge or checkout ran the developer's installed teamai against the
real ~/.teamai (it rewrote ~/.teamai/bin/teamai and left fixture projects
in ~/.teamai/projects). CI has no teamai, so local runs diverged from CI.

A new e2e setup file gives each test file a sandboxed HOME (with a git
identity), unsets XDG_CONFIG_HOME so XDG paths follow HOME, sets
GIT_CONFIG_NOSYSTEM=1, and puts a `teamai` on PATH that runs the dist under
test; all are restored afterwards.

The remote suite in e2e.test.ts now clones the fixture team repo into the
sandbox itself instead of relying on CI preparing the real ~/.teamai. The
#808 single-repo case merges with the member's HOME, as a member's hook
would run.

* fix(pull): retry a resource a member's file held back even at the same revision (#993)

A pull that keeps a member's file did not advance the revision, so the
next pull would sync in full and deliver once the file was gone. When
the checkout was already at that revision (pull --force, or the first
pull after an older CLI's), the next pull still took the fast path and
the team version never arrived, though the message says a pull brings
it. Such a pull now resets the checkout record's revision (the shared
revision in user scope), as a forced full sync does.

* fix(doctor): report a .git/info that is a regular file as not writable on a dry run (#993)

Doctor checks MCP exclusion with a dry run, which never reaches
updateFileLocked and reads the unreadable exclude file as empty, so with
.git/info a regular file it reported "not injected" and pointed at
`teamai pull`. ensureExcludedFromGit's writability check now fails when
the closest existing path above the exclude file is not a directory, so
doctor's `MCP servers delivered to <tool>` gives the same not-writable
reason and fix as pull.

* fix(skills): deliver Codex skills into .agents/skills only over teamai's copy (#993)

Codex reads the shared .agents/skills, which other tools and the member
write to as well. The destination resolver took any existing copy there as
teamai's and wrote the team skill over it, silently at init. It now takes
an ownership predicate: pull asks judgeCopy against the checkout's record,
doctor the team history alone, and teamai remove and uninstall
isTeamaiSkillCopy. A copy that is not teamai's is left alone; the team
skill goes to .codex/skills/<name>, and every full pull names the conflict.
remove and uninstall delete only teamai's copy, in project and user scope.
Source skills and the built-in stub keep the old rule for now.

* test(doctor): give the older-copy fixtures a team history (#993)

Two doctor-delivery-cli cases wrote a stale agent and Cursor rule copy by
hand, with no delivery record and no team history: since #993 such a copy
is the member's, so doctor reported it as "not teamai's". Each now commits
the older version to the team repo first, so the copy is teamai's older
render, as the case means. The Cursor case restores the team rule and its
copy in a finally block, so a failure no longer breaks the cases after it.

* fix(skills): delete only teamai's skill directories on remove, uninstall and pull (#993)

teamai remove, uninstall, and pull's sweep of namespace-nested copies of an
excluded skill deleted any directory at a team skill's name, including a
member's own skill that pull keeps as not teamai's.

remove and uninstall now delete a skill directory only when a file under it
is on the checkout's record, or isTeamaiSkillCopy proves it (what pull writes
today from the team source, or a team version by the history), and name each
one they leave. remove judges before deleting the team source, so the local
agent's history-less resource cache still removes its own installs. uninstall
keeps trusting built-in names and names the local agent's manifest lists.
The nested sweep deletes a copy only when removedCopyChanged says it is
teamai's and unchanged.

* test(uninstall): drop the commitTeamRepo import the merge duplicated (#993)

* fix(source): deliver source skills where team skills go (#993)

Source skills resolve through the team-skill seam: the agent-exclusion
check, skillTargetForTool (Hermes home, OpenClaw workspace, Copilot home),
then Codex's shared-destination rule with a real ownership proof against
the source repo. Destinations outside the project are recorded as absolute
paths inside the tool's home and shared per source across projects. An
unrecorded existing copy that is no version of the source skill is the
member's and is kept. Copies earlier releases left in the project's
.hermes/skills and .openclaw/skills are reclaimed when unchanged, kept and
named otherwise.

* test(source): changed legacy source copies survive uninstall, remove and withdrawal (#993)

* test(pull): pin delivery of an agent held at the team revision once its alias resolves (#993)

A pull --force that holds an agent for its model leaves the checkout record at the team revision, so the next pull takes the fast path. The fast path's agent redeploy (#830) already writes the resolved model there, and a copy held before delivery is written as missing; no code change is needed. The test fails when that redeploy is disabled.

* fix(uninstall): delete only teamai's rule and agent copies on uninstall, remove agents and pull (#993)

uninstall and `teamai remove agents` deleted every rule or agent file at a
team name, and pull deleted the namespaced copy beside the author's root copy
on tools that do not flatten rules. Each now goes only on the checkout's
record or a team version by the history; built-in names stay deletable, and a
member's file is kept and named.

* fix(packages): leave a tracked .teamai/teamai.lock in place and name it in doctor (#993)

Moving a lock git tracks left a deletion in git status. A tracked (or
unknown) lock is now copied to the data home instead, and doctor names it
with git rm --cached, as it does the tracked hook index.

* fix(docs): keep a local doc when the team history cannot be read (#993)

The docs prune deleted a file the team no longer has when git could not
read the team history. Without proof the file is the member's, as
everywhere else.

* test(skills): cover an unrecorded older team copy in .agents/skills updated in place for Codex (#993)

* ci(e2e): drop the steps that prepared the real HOME the e2e sandbox replaces (#993)

The e2e setup file gives every test file a sandbox HOME with its own git
identity, and e2e.test.ts clones the fixture repo into it, so the git
identity, teamai config and fixture cleanup steps act on a HOME nothing
reads.

* docs(ci): describe the e2e HOME sandbox in the local e2e setup (#993)

* refactor(sync): build every not-teamai's line from one reason (#993)

* test(agents): prove the removed and superseded copies teamai's by the team history (#993)

* test(pull): give the docs prune fixtures a team history (#993)

* fix(source): name the source's version, not a team version, for a member's skill at a source skill's path (#993)

* refactor(local-agent): resolve a record's MCP file through recordedFileOf (#993)

* fix(coauthor): report a recorded settings file that is not JSON as unreadable, naming it (#993)

* test(mcp): wait for the session start's background pass before the git-info fixture cleans up (#993)

hook-dispatch leaves a detached --bg-only pass running in the sandbox HOME
after the foreground hook exits; it was still writing when afterAll removed
the sandbox, so CI failed the suite with ENOTEMPTY.

* test(opencode): keep the V1 hooks e2e off the npm registry (#993)

With any plugin configured, OpenCode's first request for a directory waits
for it to npm-install @opencode-ai/plugin into its config dir. On CI that
fetch outlasted the 5 s session request. teamai's plugins import nothing
from it, so the fixture records it as installed, and a failed session
request now carries the server log.

* fix(sync): name a kept copy of a removed resource as the member's or as an edit (#993)

judgeRemoval replaces removedCopyChanged with three outcomes: remove,
edited (changed since teamai delivered it, or on another checkout's
record), and notTeamais (no record, no team version). Pull's tombstone
cleanup and the rules sweep now say a member's own file is not teamai's
instead of claiming the member changed a teamai copy.

* fix(agents): delete a stale same-stem agent sibling only when it is teamai's (#993)

removeStaleAgentSiblings deleted every same-stem file with another
extension beside a rendered agent, a member's own included. It now goes
through judgeRemoval with the agent's origin and the checkout record, and
names a sibling it keeps. Built-in agents keep sweeping their own names.

* test(agents): record the stale Kiro .md sibling as teamai's in the fixture (#993)

* fix(docs): keep a member's entry whose type conflicts with a team doc (#993)

The mirror replaced a local directory at a team doc file's path, or a
local file at a team docs directory's path, and deleted the backup with
its staging directory. membersDocs now treats such an entry as the
member's unless the team history proves it teamai's (a file where the
team now has a directory, or a directory whose every file is a team
version), and copyDocs leaves a kept entry in place. A link is still
replaced without touching its target.

* test(skills): expect the not-teamai's line for a member's copy of a removed skill (#993)

* fix(docs): keep a member's link at a team doc's path, without following it (#993)

membersDocs skipped links, so the mirror still moved a member's link
aside and deleted it with the staging directory (rest of the Codex P1).
A link at a doc's path, or at an ancestor of one, is now the member's
unless the team has the same link there: it is kept, named and never
followed, and the docs under it are not delivered.

* ci: re-run checks after an unrelated recall-attribution flake (#993)

Node 22 on macOS failed on 9309e201 with one unhandled rejection from
src/__tests__/recall-attribution.test.ts (a votes-lock write outliving the
test's temp HOME); every test passed and #995 does not touch that code.
The fork cannot re-run jobs, so this empty commit re-triggers CI.

* ci: re-run the Codex PR review, cancelled at its time limit (#993)

* fix(mcp): save the manifest when an adoption records a server it did not rewrite (#993)

An unrecorded server equal to today's team render was adopted into the
in-memory records, but with no file write the manifest was not saved, so
a later team removal or uninstall found nothing owned and left the server
installed. The reconcile now saves the manifest whenever this run changed it.

* fix(mcp): preview a no-op MCP adoption on --dry-run, and cover uninstall (#993)

A dry run now says it would record an unrecorded server that already holds
the team's render, in .mcp.json-style files and in Codex config, and still
writes nothing. The real-CLI cases add the dry run before the adoption and
an adoption followed by teamai uninstall; both failed before b62e503b.
Hook adoption needs no change: reconcileHooks saves its records whenever
they differ from the previous ones, whether or not it wrote a file.

* fix(docs): keep a member's directory where the team removed a doc file (#993)

When the team deleted a doc file the member had replaced with a directory,
the prune walked into that directory and deleted its files, which match no
team version. A directory at a path where the team history had a doc file,
holding anything that is not a team version, is now kept whole and named.

* fix(mcp): remove an unrecorded copy of a server the team deleted (#993)

With a lost manifest, a server an older release installed stayed for good
once the team deleted it: only today's names were judged, and with no team
server and nothing owned the reconcile returned early. Pull and uninstall
now also remove an unrecorded entry, in .mcp.json-style files and Codex
config, that equals a render of that server from the team history. A
member's entry under that name stays. The early return now also requires a
team history with no MCP server.

* perf(sync): read the team's MCP history once per pull, in one git call (#993)

historicalContents read each historical blob with its own git process
(about 370 ms for 60 versions); it now reads them all with one
git cat-file --batch (about 30 ms). The MCP reconcile reads that history
once per run for every target, and only when a target file holds an
unrecorded entry; with no team server, nothing recorded and no server in
any target file it returns without reading it. A dry run names an
unrecorded copy of a server the team deleted that a pull would remove.

* fix(docs): keep a member's link where the team deleted a doc (#993)

The prune unlinked any link at a removed team doc's path. A link there is
now removed only when it is a version of that doc from the team history
(git stores a link as a blob of its target); a link of the member's stays,
and is never followed. A link at a path the team never had is pruned as
before.

* fix(coauthor): keep the record of a shared settings file that does not parse (#993)

A pull that could not read a recorded shared settings file dropped its
record, so once the member repaired the file no later pull removed the old
attribution value. The record now stays until the file can be read.

* fix(docs): keep any non-file entry of the member's where the team deleted a doc (#993)

A link at a removed team doc's path goes only when it is a version of that
doc from the team history; any other entry that is not a regular file stays
and is named. Adds the real-CLI case for a member's link replacing a doc.

* fix(sync): never adopt or write through a link at a delivered file's path (#993)

isTeamaiCopy and the copy judgement followed links: a link at a rule or
agent path whose target held an older team version was taken as teamai's,
and the next pull wrote through it into the member's file. A link in place
of a delivered file is now the member's (kept, named), a link there is
never removed as teamai's copy, and a skill directory holding a link is not
teamai's copy, since copying over it would write through it.

* fix(docs): keep a member's directory of links where the team deleted a doc file, and do not call it stale (#993)

A directory that replaced a former team doc file and held only links read
as teamai's (links are not listed), so the prune removed it. Such a
directory is now the member's whenever it holds a link. doctor also stops
listing files inside a directory pull keeps whole as stale docs.

* fix(hooks): recognize unrecorded team hooks in every format, on pull and uninstall (#993)

Pull recovered a team hook entry whose record was lost only in Claude and
Codex files. In Cursor, Copilot and ZCode files the old entry stayed as the
member's and the new one was added beside it, so both ran. Each entry is now
compared with the team's hooks rendered the way that format's reconciler
writes them; one equal to exactly one hook is replaced or removed as teamai's.

Uninstall did not judge unrecorded entries at all, so with the records lost
it left custom team hooks installed, and missed a main-checkout Codex file
holding only team hooks. It now judges every hook file against the team's
hook history, gated to the project as pull renders them in a non-self
project scope, and removes the entries equal to exactly one team hook.

* fix(sync): treat any non-regular entry in a skill or docs directory as the member's (#993)

A directory is teamai's copy only when every entry is a regular file that
is a team version; a link or any other non-regular entry anywhere below it
makes it the member's. Adds real-CLI cases for a skill directory holding a
link and a docs directory of links where the team deleted a doc file.

* fix(sync): keep a member's link at any delivered path (#993)

A link at a delivered skill directory, rule or agent file, docs entry or
source skill destination is the member's: teamai never creates links, so
it is never adopted, replaced, written through or deleted, on pull,
remove and uninstall alike. Pull and doctor name it: "Kept <path>: it is a
link of yours, so teamai does not replace it. Remove the link to receive
<name> from the team."

This deliberately changes earlier behavior: source and team skills used to
replace a leaf link in place of a skill directory with a copy, and the
Codex duplicate cleanup deleted a configured leaf link. The source tests
that asserted those now expect the link kept.

* fix(agents): prove a tombstoned agent copy teamai's in a team-defined tool too (#993)

For a tool teamai renders no agents for, the tombstone cleanup had no
proof to check and removed any file with the removed agent's name. It now
removes it only when it is a team agent's own bytes from the history; a
member's file of that name stays.

* fix(rules): never read through, write through or delete a member's link at a rule path (#993)

The cleanup and rerender paths judged a rule copy by reading the file a
link points at, so a link whose target held a team render was rewritten
through or deleted: the "Already synced" rerender, the legacy rules
directories (pull and uninstall), the reserved teamai-context name, the
unselected-rule sweep, the moved nested copy, the flat OMP and Kiro
copies, the older .md layout, and teamai remove rules. Each now treats a
link as the member's and leaves it. The empty-directory sweep no longer
deletes a directory whose only entries are links.

* fix(agents): keep a member's link where an agent was delivered, on pull and teamai remove (#993)

The inactive-namespace cleanup judged a copy by the file a link points at, and teamai remove agents deleted the author's root copy by its placement record alone. A link at either path is now the member's and stays.

* fix(skills): keep a skill directory that holds a member's link, on pull, remove and uninstall (#993)

A recorded skill whose file the member replaced with a link to the same
bytes read as unchanged, so pull copied over the link and remove,
uninstall and the tombstone and inactive-namespace sweeps deleted the
directory with every link in it. A skill directory holding a link is now
the member's on pull, named by the link, and kept by every sweep.
teamai remove skills also judges a link at a built-in skill's name
before the name.

* fix(sync): keep an unrecorded file teamai cannot read where a removed resource was delivered (#993)

judgeRemoval counted a file it could not read as absent and removed it. Without its bytes nothing proves it teamai's, so it is now kept as the member's.

* fix(docs): never read through or delete inside a member's link in a deactivated docs namespace (#993)

Withdrawing a namespace's docs read each copy through any link on its path and deleted what matched the team file. A namespace directory the member linked to a folder of their own lost its files, and a linked doc was deleted. A path through a link is now left alone.

* fix(source): keep a source skill copy that holds a member's link, on pull and source remove (#993)

A recorded destination was the source's whole, so pull copied over a link the member put inside it and source remove deleted the directory with it. Such a copy is now the member's: pull names the link and source remove keeps the directory on record.

* fix(local-agent): keep a member's link where the local agent installs a skill or rule (#993)

The local agent installs through pullItem with no delivery record, which skipped every ownership check: a rule was written through a link and a skill directory link was replaced. A link at the path, or inside the skill directory, is now kept and named.

* fix(sync): deliver team and source skills without the links in them (#993)

Copying a skill recreated each link in its source as a link in the
member's tool directory, which then read as the member's own, and let a
skill plant a link to any target. Delivery now skips a link in a team or
source skill, without following it, and names each one once:
"Skipped <link> in <skill>: teamai does not deliver links."

* fix(docs): keep a member's link in the docs mirror at a path the team never had (#993)

This deliberately changes the mirror prune: it used to unlink any link at
a path the team repo's history never had, as a local leftover. teamai
never creates a link there, so such a link is the member's: pull now
keeps it and names it, and doctor no longer reports it as a stale doc.
A link matching a team link once at a removed doc's path is still pruned.
The docs and doctor tests that expected the unlink now expect it kept.

* docs(designs): state that teamai never follows, replaces or deletes a member's link (#993)

* fix(uninstall): remove only teamai's docs from the docs mirror, and keep the member's (#993)

Uninstall deleted the whole docs directory, so a file pull had kept as
the member's, a directory or a link of theirs went with it. It now
removes a file or link only when it is a version of that doc from the
team repo's history, names everything else, and removes a directory only
once it is empty. While the history cannot be read, the mirror stays
whole. A mirror inside the data home that keeps something survives the
removal of that home with it.

* fix(mcp): write a linked MCP config through its link, and keep its target out of git (#993)

A member's MCP config can be a symlink into a dotfiles repository. The
atomic writes replaced the link with a regular file. They now write at the
file the link points to, rollbacks included, and a linked CodeBuddy
~/.codebuddy/mcp.json is kept rather than deleted.

A resolved value then lands in the link's target, so the git checks judge
that file in its own repository: a target that repository tracks gets no
value, and an untracked one is listed in that repository's info/exclude,
which pull and uninstall now find to take the line out again.

* fix(docs): name a kept link at a removed doc's path as before, and only a never-team path's link as such (#993)

Goes with keeping a member's link at a path the team never had: a link at a removed doc's path keeps the line that says the team removed it.

* test(skills): expect pull to name the member's link inside a skill directory (#993)

* fix(opencode): keep a member's linked opencode.json and openclaw.json as links (#993)

The OpenCode instructions writer and the OpenClaw hook entry writer
replaced a symlinked config with a regular file, and uninstall deleted a
linked .opencode/opencode.json left holding only its $schema. Both now
write at the link's target, and a link is never deleted.

* fix(rules): never delete a linked CLAUDE.md or AGENTS.md when its teamai section goes (#993)

Removing teamai's section from an instruction file teamai created deleted
the file once nothing else was left, a member's link to it included. A
link stays; its target is emptied instead.

* fix(skills): push no links to the team repo, and name why remove and uninstall keep a skill directory (#993)

A push copied a link inside the member's skill into the team repo, so every
member then received a skill teamai will not deliver; push now skips each
link and names it. remove and uninstall now say a kept skill directory is a
link of the member's, or holds one, instead of claiming it has no delivery
record.

* fix(source): keep reading a record into a removed OpenClaw workspace, and never another repository's history (#993)

A source record of a copy in an OpenClaw workspace outside ~/.openclaw was
rejected once that workspace was gone, so every pull and source remove of
that source failed. The configured workspace now counts as a tool home even
when its directory is missing. A source cache without its own .git no
longer lets git read an enclosing repository's history (a dotfiles HOME):
only today's source proves a copy then.

* fix(source): leave a copy in a tool home that moved, instead of rejecting the record (#993)

Configuring OpenClaw to another workspace made the record of a copy in the
old one invalid, so every pull and source remove of that source failed.
The record now notes the tool home of each absolute destination; one whose
home moved is dropped from the record and its copy left as it is, while an
absolute path the record cannot account for is still rejected.

* fix(docs): keep the member's hidden files on uninstall, and match a link only to a team link (#993)

uninstall did not count hidden entries in the docs mirror as kept, so with
nothing else kept it deleted the data home around them. They are now named
and keep the mirror. A link in the mirror is now teamai's only when the
team history had a link with that target there, not a file holding the
same text (the history now carries each version's git mode).

* fix(skills): keep a delivered skill directory that holds a file the member added (#993)

A skill directory with any file on record was taken as teamai's whole, so
remove, uninstall and the tombstone cleanup deleted a file the member had
added beside teamai's. A recorded directory now goes only when every file in
it is on record or a team version; otherwise it is kept whole and named.
Source skill removal applies the same rule against the source's files and
history.

* fix(skills): remove and uninstall take only teamai's files from a skill directory (#993)

When a delivered skill directory holds a file the member added, remove and
uninstall now delete only the files on record or matching a team version,
name each file they keep, and leave the directory while anything is left in
it. uninstall plans the exact files, so its dry run shows them.

* fix(source): keep a member's file at the path of a link the source skill has (#993)

Delivery never copies a link from a source skill, but removal counted any
history at that path as the source's, the link included, so a regular file
the member put there was deleted with the skill. Only a regular file the
source has, or had, is the source's now.

* fix(mcp): find teamai's CodeBuddy servers in every user MCP file, and treat a linked lookup path as its target (#993)

A server an earlier teamai left in a CodeBuddy user MCP file that CodeBuddy no longer reads stayed there once its record was lost: pull and uninstall looked only at the file CodeBuddy reads, and returned early when that file was empty. They now also look at the other lookup files that exist and remove an unrecorded entry equal to a current or historical team render; a member's entry stays.

Lookup files are compared by real path. With ~/.codebuddy/.mcp.json a symlink to ~/.codebuddy/mcp.json, a pull recorded the server at the link and then removed it from its target, the same file. With ~/.codebuddy.json a symlink to ~/.codebuddy/mcp.json, the upgrade move emptied and deleted the file the link points to.

* fix(sync): prove a CONTRIBUTORS file like any other, and a file only by a file the team had (#993)

A skill's CONTRIBUTORS file counted as teamai's by its name alone, so remove
and uninstall deleted the member's own one, and it never made a directory
the member's. It now needs the same proof as any file. A link in the team
history no longer proves a regular file holding the same bytes, and a
version that changed only its mode is kept as its own version.

* fix(skills): keep a delivered skill when the team or the source adds a file where the member has one (#993)

A file the member added to a recorded team or source skill was overwritten
once the team, or the source, delivered a file at that path. Pull now keeps
such a copy whole and names it, as an edited one, unless the file is a
version from the history. A source removal keeps a copy holding a file of
the member's only when the source's own files prove the copy came from it:
a copy from a replaced repository, or one an in-repo alias placed, is left
to the record, as before.

* fix(docs): keep a file of the member's at a path the team never had (#993)

The docs mirror pruned any local file at a path the team history never
had, so a member's own notes there were deleted on the next pull. Having
no team version is no proof that teamai put a file there: the prune now
removes only teamai's copies of docs the team removed, and leaves the
member's own files without a word. doctor stops calling them stale, and
the usage guide no longer says local drafts are removed. Earlier tests that
expected such files pruned now use team docs the team removed.

* docs(designs): the docs mirror prunes only teamai's copies of removed docs (#993)

* fix(rules): remove a rule copy that holds what pull writes today (#993)

`remove rules` deleted a tool's copy only on the checkout's record or the
team history. A checkout without history and without a record, such as a
resource cache, left teamai's own copy behind. The copy that holds today's
render of the team rule, or the rule verbatim, is now teamai's too, read
before the team file goes, as `remove skills` already does.

* fix(source): keep a source skill copy holding the member's file, on record (#993)

A copy pull kept whole because the source added a file where the member
had one was left off `installedSkills`, so `source remove` forgot it and
dropped the manifest. It stays on record now. Removal then tells the
source's files from the member's by their bytes, not their path, and a
file at a path the skill never had keeps the directory even when no file
of the source is left in it.

* test(local-agent): uninstall_rule removes the installed copy and keeps the member's (#993)

* fix(mcp): tell another tool's server by the file's real path (#993)

An entry another tool's record claims in the same file is left to that
tool. The file was compared by name, so a tool whose MCP path links to
another's file adopted that tool's server once its own record was lost,
and a later removal for it would take the server from the shared file.
It is compared by real path now, as the rest of MCP reconciliation does.

* fix(source): keep a source skill copy whose every file the member edited (#993)

Removal kept a copy holding an edited file only when another file still
matched the source. A copy whose every file the member edited, such as a
single SKILL.md, was deleted by `source remove` or by a pull after the
source withdrew the skill. When the source history has the skill, a file
that matches no source version keeps the copy.

* fix(ownership): keep a member's entry of the other type at a delivered path (#993)

A file where a team skill directory goes, or a directory where a rule or
agent file goes, was not judged the member's. Delivery over it failed, yet
the pull could record the team revision as synced, so once the member
removed the entry a plain pull delivered nothing until the team changed or
the member ran `pull --force`. Such an entry is now kept and named, and the
next pull after it is gone delivers the team version.

* fix(skills): keep a member's file when removing a skill with a built-in's name (#993)

`teamai remove skills <name>` deleted the whole directory when the name is
one the CLI once shipped (such as team-wiki-codebase), so a file the member
added beside it was lost. It now removes the files the team history proves
teamai's and the files a release packaged there, as uninstall does, and keeps
and names a directory left holding anything else.

* fix(skills): keep a delivered skill when the team adds a file where the member has a directory (#993)

When the team added a file to a delivered skill at a path where the member
had a directory, or a directory where the member had a file, the copy failed
inside pull and the pull still advanced to the team revision, leaving the
skill stale. Such an entry is the member's now: the skill is kept whole and
named, as when the team adds a file where the member has one.

* fix(local-agent): tell CodeBuddy's user MCP file by its real path (#993)

With `~/.codebuddy/.mcp.json` linked to `mcp.json`, a record an older agent
wrote without a file resolved to `mcp.json`, while the install target was
`.mcp.json`. The record was dropped as another file's, so reinstalling the
same server failed as "not managed by teamai". Records are matched to the
target by real path now, as MCP reconciliation does.

* fix(skills): deliver a skill around a member's entry of the other type, and retry failed copies (#993)

A member's directory where the team adds a file to a delivered skill, or a
file where it adds a directory, is the member's: it is kept and named, the
files it covers stay undelivered, and the rest of the skill is delivered.
The pull is not counted as synced, so the next one is a full sync that
delivers those files once the entry is gone.

A skill, rule or agent copy that fails with an error no longer counts as
synced either: the revision stays, and the next pull retries it.

* fix(source): keep a source skill copy when the source adds a directory where the member has a file (#993)

A file of the member's where the source now has a directory was missed by
the collision check, so the copy failed on the conflict instead of keeping
the member's copy. An entry of the other type at a source path, or at one of
its parents, is the member's now, also when the source cache has no history.

* fix(uninstall): keep OpenCode's user plugin on a project uninstall (#993)

The plugin in the user's OpenCode config now also carries the team rules and
instructions for V2, for every project and the user scope. A project-scope
uninstall removed it, which ended delivery for every other project. It keeps
it now and names it, as it does for the other global adapters; a user-scope
uninstall still removes it, and so does `teamai hooks remove`.

* fix(skills): keep a skill directory holding a git repository of the member's (#993)

The ownership check reads a skill directory's files the way delivery lists
them, which skips `.git`. A recorded skill whose files matched was then
deleted whole by `teamai remove`, `uninstall` or a source removal, taking a
repository the member made in it, with its local commits. A directory holding
a `.git` is never deleted whole now; only teamai's files in it go.

* fix(local-agent): keep a CodeBuddy server copy the member edited when moving it (#993)

When CodeBuddy's preferred user MCP file changed, reinstalling a server
moved it there and deleted the copy in the old file without checking it.
A copy the member edited since teamai installed it is kept now, and named.

* fix(local-agent): keep a CodeBuddy server's record until its move is written (#993)

Moving a server to the user MCP file CodeBuddy now reads recorded it in the
new file before writing it there. When that write failed, the record pointed
at the new file while the server stayed in the old one, so uninstall left it
installed. The old file's record is existing ownership now: it stays until the
new file is written, as for a server already recorded in the target file.

* fix(uninstall): record a project's OpenCode exclusion when its plugins are kept (#993)

A project-scope `uninstall --agent opencode` keeps the user plugin
directory, so with only a server-pushed agent-hook plugin there the plan was
empty: it said "Nothing to uninstall" and never excluded OpenCode, whose
global hooks stayed active for the project. OpenCode now takes the
exclusion-only path, like the other tools with global channels, and the kept
agent-hook plugins are named with the other retained adapters.

* fix(docs): keep a member's doc that has the bytes of a team doc that is a link (#993)

A regular file of the member's at the path of a team doc that is a link was
taken for teamai's copy when its bytes matched the link's target, and the
mirror replaced it with the link. Equal bytes now prove a copy only of a team
file; such a doc is the member's unless the team history has that file.

* fix(mcp): judge each CodeBuddy lookup file with the tools that write it (#993)

Cleaning CodeBuddy's other user MCP files reused the ownership check built for
the file it reads, which knew of no other tool writing there. With
`~/.codebuddy/mcp.json` linked to Claude's `~/.claude.json`, Claude's copy of a
team server matched CodeBuddy's render and was deleted through the link. Each
file is now judged with the records of every tool whose MCP file it is.

* fix(docs): judge a deactivated namespace's doc by its type as well as its bytes (#993)

When a docs namespace stops being active here, its copies that are teamai's
are removed. A member's regular file whose bytes equal the target of a team
doc that is a link was taken for teamai's, through the link and through a
history check that also matched link versions, and deleted. A file is
teamai's only as a team file now, today's or one from the history, as on
every other docs path that deletes or replaces (prune, copy, uninstall).

* fix(mcp): count another tool's servers in a shared file even when it is not detected (#993)

Whose entries a config file holds was judged only with the tools detected on
this run. With `~/.codebuddy/mcp.json` linked to Claude's `~/.claude.json` and
Claude no longer installed, a CodeBuddy pull took Claude's identically rendered
server for its own and deleted it through the link, leaving Claude's record
stale. Every tool that maps a file counts now, detected or not: detection
decides where teamai writes, never what it may delete. Doctor judges the same way.

* fix(mcp): restore a file two tools write through linked paths once, to its first state (#993)

Configs written during an MCP sync are restored when ownership cannot be
saved. Snapshots were keyed by path, so a file two tools reach through
linked paths got one per path and the later one, taken after the first
tool's write, was restored last: the server stayed without its record. One
snapshot per real file now, taken before its first write.

* fix(coauthor): leave a settings file that does not parse as it is (#993)

Project scope writes the co-author setting to `.claude/settings.local.json`,
the member's own file. One that did not parse was read as empty, so a pull
replaced the whole file with teamai's `attribution` block and the member's
settings were lost. A Claude or Cursor file that is not a JSON object is now
left untouched and reported as skipped, and the setting is written on the
first pull after the member repairs it.

* fix(hooks): leave a hook settings file that does not parse as it is (#993)

Every hook writer read its settings file as empty when it did not parse, so
a pull or a session-start pass while the member was mid-edit of, say, their
HOME `~/.claude/settings.json` replaced the whole file with teamai's hooks.
The Claude, Cursor, Copilot, Codex and ZCode writers, and the agent-hook
install and removal, now leave such a file byte-identical and say which file
and why; nothing is recorded, and the first pull after the repair writes it.

* fix(docs): never walk a docs mirror that is a link of the member's (#993)

When `sharing.docs.localDir` itself was a link to a personal directory,
uninstall walked it and deleted the files behind it that matched a team doc
from the history, outside the mirror. A mirror root that is a link is now the
member's on every path: pull copies, prunes and withdraws nothing through it
and names it, doctor reports it, and uninstall leaves it and what it points at.

* fix(uninstall): keep the record of hooks a settings file that does not parse still holds (#993)

Uninstall left out a hook settings file that did not parse, then deleted the
data directory holding the record of its hooks; once the member repaired the
file, teamai's hooks ran there with no record left to remove them by. Such a
file is now tried, named and left as it is, and the data directory stays, so
uninstall run again after the repair removes them. `source remove-http` and
uninstall keep the record of an HTTP agent hook they could not remove, and the
local agent's directory with it, instead of clearing the whole manifest.

Pull also names a docs mirror that is a link before counting or previewing
its files, so it never walks it, on a dry run either.

* fix(uninstall): report an uninstall that left hooks in place as incomplete (#993)

When a hook settings file could not be cleaned, uninstall kept the data
directory but still said "teamai uninstalled" and exited 0, and a targeted
uninstall of the last tool did not record the tool as excluded, so the hook
left in place could sync its resources back. Hooks left in place now make the
uninstall incomplete, as an OpenCode entry it could not remove does: exit code
1, the files named, and the tool excluded. The message for a settings file that
does not parse no longer points at `teamai pull`.

* fix(uninstall): stop hooks an incomplete uninstall left in place from syncing back (#993)

A full uninstall that could not remove a tool's hooks kept the data directory
with every tool still enabled, so the hook left in place ran a session-start
pull that restored what had just been removed. Each tool whose hooks remain is
now excluded, and the session-start pull of an excluded tool's hook does
nothing, as its instruction and HTTP handlers already did, until the uninstall
is run again after the repair.

* fix(local-agent): keep removed HTTP sources disabled (#993)

* fix(local-agent): serialize HTTP sync and source removal (#993)

* docs(http): describe skipped concurrent hook syncs (#993)

* fix(uninstall): remove the HTTP source under its lock before teardown (#993)

A full user-scope uninstall removed agent hooks, plugins and ~/.teamai
without the local-agent lock, so a hook sync paused after loading its
config could reinstall resources once uninstall reported success.
Uninstall now runs the remove-http shutdown first: it waits up to 30
seconds for the lock, disables the source before teardown, and exits 1
without removing anything when the lock cannot be taken.

* fix(local-agent): let a server-pushed uninstall hold its sync's lock (#993)

A sync holds the HTTP source lock while it runs an uninstall_teamai
command, so the uninstall it spawns waited for that lock until the hook's
15-second budget killed the sync, unacknowledged and with teamai still
installed. The sync now passes its pid to the command; a child whose
parent holds the lock runs under it without acquiring or releasing it.

* docs: point the kept-edit links in sharing at member-guide's Auto-sync

The Auto-sync section moved to member-guide in the docs reorganization,
so the in-page anchors #993 added no longer resolve.
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
* fix(opencode): add team rules and instructions to V2 sessions through the plugin

OpenCode V2 parses `instructions` and ignores it, so a V2 session got none
of the team rules or the culture, claudemd and recall blocks. The teamai
plugin's V2 setup now registers the session context and compaction hooks
and adds the user instruction file and rules, then the nearest project's
.opencode/teamai-context.md and .opencode/rules/**/*.md, sorted by path.
V1 delivery through `instructions` is unchanged. (#993)

* fix(opencode): write the user instruction file beside the Claude fallback for V2

OpenCode V1 reads ~/.claude/CLAUDE.md while ~/.config/opencode/AGENTS.md
does not exist, so teamai wrote no OpenCode user file there. V2 reads
neither that fallback nor `instructions`. Pull and HTTP prompts now
write ~/.config/opencode/teamai-context.md for teamai's plugin in that
case too, and still list it nowhere, so V1 gets no duplicate. (#993)

* fix(init): set up only the --agent tools in single-repo init (#993)

init . wrote .teamai/teamai.yaml (mode: self) before it read the existing
project config. With the marker on disk and no config yet, that read ran the
clone-time self-heal, which enabled every tool found in HOME, injected their
hooks into the repo and saved them; init then merged --agent into that.

Read the config once, before the marker is written, and use that snapshot for
inheriting user scope, the enabledAgents union, the tool-roots carry-over and
the mode-switch settlement.

* fix(coauthor): keep the project-scope co-author setting out of shared settings (#993)

In project scope only claude writes attribution, to the member-local
.claude/settings.local.json; the rest of the Claude settings family is
user-scope only, like Codex and Cursor. The next pull removes an
attribution an earlier release wrote to a shared project settings file
when it is exactly teamai's value and the co-author record lists the
file, deleting only that member's text.

* docs(coauthor): note a pre-fix shared value stays while no co-author choice exists (#993)

* fix(doctor): check OpenCode V2 delivery from the teamai plugin

doctor reported the team rules and instructions active on OpenCode V2
because `instructions` listed them, but V2 ignores that key. doctor now
reads the major version from `opencode --version` (missing or unparsable
counts as V1) and, on V2, checks that teamai's plugin in HOME is the one
this build writes, since its context hook is what delivers them. V1
checks are unchanged. The usage guide describes V2 delivery. (#993)

* fix(pull): probe live checkouts from recorded roots, not the worktree list (#993)

A pull in a linked worktree of a --separate-git-dir repo or a submodule
dropped the main checkout's delivery record and workspaces/<id>/, because
git worktree list names the git directory there instead of the main
checkout. Its next pull then overwrote edited rules without a word.

Records and workspace directories now store their checkout root; a full
pull keeps one while that root still has a .git, names the same git common
dir, and (records) gives the same checkoutKey, so a re-created worktree
still starts fresh (#807). Entries without a root (older CLI) are kept.
listWorktrees reads --porcelain -z, skipping bare, prunable and common-dir
entries, and returns [] when -z is unsupported instead of splitting lines.

* fix(init): skip the clone-time self-heal for init in a single-repo clone (#993)

A fresh clone whose committed .teamai/teamai.yaml says mode: self ran the
self-heal in the preAction queue check and again in initSelfRepo's config
read. Either one enabled every tool found in HOME before --agent could
choose. init now loads with selfHeal: false in both places; every other
command still self-heals.

* fix(sync): adopt config entries that equal a team render, keep the member's (#993)

An MCP server or a team hook entry teamai has no record of is teamai's
only when it equals teamai's render of a team server or hook, today or at
any revision in the team repo's history (one hook only). It is then
adopted and handled as recorded. Any other one is the member's: kept and
named by pull and doctor; a member's same-name MCP server means the team
server is not written to that file. `pull --force` no longer overwrites
a member's server (`teamai mcp inject --force` still does).

This removes the second copy of each team hook a lost hook manifest
caused in .claude/settings.local.json and .codex/hooks.json.

* docs(sync): describe ownership of unrecorded MCP servers and hook entries (#993)

* test(init): cover init . in a single-repo clone with no --agent and no terminal (#993)

With the clone self-heal skipped for init, a fresh clone has no config when
init runs. Pin that it takes the non-interactive default (the tools found in
HOME) instead of prompting or stopping at "already initialized".

* test(hooks): cover hook ownership beside the co-author setting in settings.local.json (#993)

* fix(pull): prune a workspace directory without a root only when the worktree list names every checkout (#993)

contribute, recall, viz, the MCP writers and the local agent create a
checkout's workspaces/<id>/ before its first full pull writes root, so a
removed worktree that never ran a full pull kept its directory forever
(self-mode-worktrees-808). Such a directory now goes when git worktree list
-z names every checkout (no non-bare entry is the common dir) and none has
its id, as git prints it or realpath'd. It is kept with --separate-git-dir,
in a submodule, on git < 2.36, and when it holds local-agent/.

* fix(mcp): create a missing .git/info/ before excluding a resolved MCP config (#993)

A repository created with an empty template has no .git/info/. The
writability check ran `access(W_OK)` on that directory, got ENOENT, and
reported it as "not writable", so every team MCP server holding a
resolved value was withheld.

Check the exclude file when it exists, otherwise its closest existing
directory, and let the write create info/. Report "not writable" only
for EACCES, EPERM and EROFS, and name the exclude file in the reason and
the fix. Applies to pull, doctor, `mcp list` and local-agent installs,
which share ensureExcludedFromGit.

* fix(mcp): write CodeBuddy's user MCP servers to the file CodeBuddy reads (#993)

CodeBuddy reads only the first user MCP file that exists of
~/.codebuddy/.mcp.json, ~/.codebuddy/mcp.json and ~/.codebuddy.json, and
teamai always wrote the second, so team servers and the member's own hid
each other. In user scope teamai now writes to that first existing file and
creates ~/.codebuddy/.mcp.json only when none exists. Each CodeBuddy record
in managed-mcp.json names its file; a pull moves teamai's own entries out of
a file CodeBuddy no longer reads, uninstall and `teamai mcp remove` follow
the record, and doctor and `teamai mcp list` name a shadowed file.

* fix(local-agent): install CodeBuddy's user MCP servers in the file CodeBuddy reads (#993)

An HTTP-backed team's install_mcp now writes CodeBuddy's user servers to the first existing file of CodeBuddy's lookup order, as a pull does, and records that file. A reinstall moves a server an earlier install left in a file CodeBuddy no longer reads; uninstall_mcp removes it from the recorded file.

* fix(migrate): move the team clone's last-fetch stamp out of a superseded install (#993)

A linked worktree whose old git-mode install another checkout superseded
by switching to single-repo mode keeps the team knowledge in .teamai/ and
moves only SUPERSEDED_ENTRIES to .teamai.bak. #964 added last-fetch.json
beside the clone, which that list did not name, so it stayed in .teamai/
as an untracked file. The 808 fixture now writes the stamp a #964 release
leaves, so the case fails without the fix whatever teamai the developer
has installed.

* fix(hooks): keep the managed-hooks index and the package lock out of the working tree (#993)

getManagedHooksPath built <root>/.teamai/managed-hooks.json in project
scope, so the Copilot hook index showed up untracked in every git project
and self mode committed it with git add -A. It now resolves per checkout to
<dataHome>/workspaces/<id>/managed-hooks.json, beside managed-mcp.json.
legacyManagedHooksPath names the old file for the pre-#370 Codex import,
the legacy hook sweep and uninstall. migrateLegacyManagedHooks moves its
Copilot records (all records in self mode) before hooks are reconciled,
removed or uninstalled, and deletes it once empty and untracked; doctor
names a tracked one with the git rm --cached command.

teamai.lock moves to the data home too (packageLockDir): an older
.teamai/teamai.lock is moved on the next install or session-start read,
doctor reads it where it is, and a .teamai/.gitignore holding only
teamai.lock is removed outside self mode. Self mode's .teamai/.gitignore
lists managed-hooks.json, also through its migration.

* fix(pull): keep a rule or agent file teamai cannot prove its own (#993)

A rule or agent destination that exists with no delivery record is
teamai's only when its bytes equal teamai's render of that resource at
some revision of the team repo's history (git blob ids, through ticket
04's matchesHistory). Otherwise it is the member's: pull neither writes
nor deletes it, names it, and doctor lists it. This covers a checkout
whose record key changed (a restore or copy gives .git a new inode), a
role switch after that, and a member's own file with a team name.

- DeliveryTarget.origin carries the proof; judgeCopy gains a 'member'
  verdict; isTeamaiCopy and describeMembersFile are the shared seam.
- The rules stale sweep and the tombstone cleanup prove an unrecorded
  copy before deleting it.
- A kept copy is worded as an edit when another checkout record lists
  its path (a record lost to a new key); no record is carried over.
- A pull that keeps a member's file does not count as synced, so a
  plain pull delivers the team version once the file is gone.

* fix(mcp): leave an older teamai's ~/.codebuddy/mcp.json that hides ~/.codebuddy.json (#993)

Earlier releases always created ~/.codebuddy/mcp.json, so a member's servers in ~/.codebuddy.json stayed hidden. When that file holds only teamai's servers (recorded, or equal to a team render) and a later file of CodeBuddy's lookup order exists, a pull moves the servers there, deletes the file and says so once. A file that also holds a member's server or any other key stays chosen.

* fix(remove): judge rule copies by record and team history in teamai remove (#993)

teamai remove's rules refresh ran without the checkout's ledger, so it
wrote over a member's own file at a team rule's path, and its explicit
sweep deleted a member's own file named after the removed rule. It now
opens the ledger, passes it to the refresh and names what it kept, and
deletes a copy of the removed rule only when it is on record or its
bytes are a version from the team history (the author's root copy keeps
its placement record as proof). Docs say a personal rule the team never
had is kept, and that a pull keeping a member's file syncs in full until
it is gone.

* fix(pull): keep a skill or doc teamai cannot prove its own (#993)

A skill directory with no delivery record is teamai's only when every file
in it is today's team file or a version of it from the team repo's history
(SKILL.md also as pull repairs its frontmatter); one file of the member's
makes the whole directory theirs. A file in the docs mirror at a team doc's
path is teamai's only when it is a version of that doc. Anything else is
kept and named, not written over or removed by the tombstone cleanup, and
doctor lists it. isTeamaiSkillCopy is the ledger-free decision ticket 05
reuses.

* docs(skill): keep the ownership sentence clear of the command check (#993)

* fix(rules): delete a legacy .md in .cursor/rules only when it is teamai's (#993)

Pull's stale sweep and pullItem deleted every .md in a .mdc tool's rules
directory, and uninstall every one with a team rule's name, as a copy of
the layout before .mdc. A member's own notes.md there went with them,
though the usage guide promised it stays. Each now deletes one only when
the checkout record lists it, it is a team version from the history
verbatim, or it has a built-in rule's name (isLegacyLayoutCopy); any
other is kept silently, since Cursor never reads it. teamai remove
already applies the proof since 02b.

* fix(coauthor): move a pre-fix attribution to settings.local.json when no choice exists (#993)

With no co-author choice (the team dropped sharing.coAuthor and the
member has none), the reconcile returned before settling shared project
files, so an attribution an earlier teamai wrote to a tracked
.claude/settings.json stayed there for git add -A to commit. The next
pull now moves it to .claude/settings.local.json under the same guards
(teamai's exact value, the record lists the file with "strip", only
that key is edited), so the member's trailer is unchanged and the
tracked file is clean. A value the member already set in
settings.local.json is kept. Other Claude-family tools' shared files
have no member-local counterpart and wait for a choice. A failed
settle now keeps its record so the next pull retries.

* fix(git): list sibling worktrees on git before 2.36 (#993)

listWorktrees read only `git worktree list --porcelain -z`, so on git
without -z it returned [] to every caller. A pull or uninstall then judged
the shared .git/info/exclude line from the current checkout alone and
dropped /.mcp.json while a sibling worktree's .mcp.json still held a
resolved value (#882/#886).

Fall back to the newline-split list when -z fails. Liveness is unchanged:
completeWorktreeList stays -z only and returns null there.

* fix(mcp): report an exclude directory teamai cannot create as not writable, not as a held lock (#993)

acquireLock returns false when it cannot create the lock's directory, so
updateFileLocked waited out 25 attempts and reported "another teamai
command held <file> past the wait". With .git/info a regular file, MCP
exclusion blamed a lock nobody held.

updateFileLocked now creates the file's directory before taking the
lock. EEXIST and ENOTDIR (a path on the way is not a directory) and
EACCES, EPERM and EROFS throw a NotWritableError naming the file and the
closest existing path above it, without waiting. ensureExcludedFromGit
reports it as "<exclude> is not writable, as <path> is not a directory"
and withholds the server as before. acquireLock's boolean contract is
unchanged for its other callers.

The e2e fixtures now use fresh paths per call, so a retried case
rebuilds them instead of failing on the first try's.

* docs(mcp): say an unrecorded entry under a name the team dropped is not adopted (#993)

MCP ownership adopts an unrecorded entry only under a server name the
team defines today, so a copy of a since-deleted team server stays as it
is. Say so in the usage guide's ownership paragraph, in both languages.

* fix(agents): prove an agent copy an older CLI rendered teamai's (#993)

The agent ownership proof accepted a team version verbatim or rendered as
pull renders it today, with today's aliases. Every member upgrading from
0.26.0 or earlier has no delivery record, and 0.26.0 rendered agents
differently: the spec's model as written (no aliases), and before #830
Qoder, Qoder CN, ZCode and OMP took Claude's tool_extras and tclaude and
tcodex only their base tool's. Such a copy read as the member's: never
updated, named on every pull, and every pull a full sync. agentOrigin now
also accepts the unresolved render and the pre-#830 extras render.

* fix(pull): keep a member's file when the team deletes the doc at its path (#993)

The docs mirror prune deleted every local file the team repo no longer has.
At a path the team once had a doc, it now deletes the file only when it is
a version of that doc from the team history; any other is kept and named,
and doctor no longer lists it as stale. A local-only file at a path the
team never had is pruned as before.

* test(e2e): isolate HOME and the teamai binary for fixture git

The git hooks teamai installs run `PATH="$HOME/.teamai/bin:$PATH" teamai
hook-dispatch ...`. E2E fixtures ran git with the real HOME and PATH, so a
fixture merge or checkout ran the developer's installed teamai against the
real ~/.teamai (it rewrote ~/.teamai/bin/teamai and left fixture projects
in ~/.teamai/projects). CI has no teamai, so local runs diverged from CI.

A new e2e setup file gives each test file a sandboxed HOME (with a git
identity), unsets XDG_CONFIG_HOME so XDG paths follow HOME, sets
GIT_CONFIG_NOSYSTEM=1, and puts a `teamai` on PATH that runs the dist under
test; all are restored afterwards.

The remote suite in e2e.test.ts now clones the fixture team repo into the
sandbox itself instead of relying on CI preparing the real ~/.teamai. The
#808 single-repo case merges with the member's HOME, as a member's hook
would run.

* fix(pull): retry a resource a member's file held back even at the same revision (#993)

A pull that keeps a member's file did not advance the revision, so the
next pull would sync in full and deliver once the file was gone. When
the checkout was already at that revision (pull --force, or the first
pull after an older CLI's), the next pull still took the fast path and
the team version never arrived, though the message says a pull brings
it. Such a pull now resets the checkout record's revision (the shared
revision in user scope), as a forced full sync does.

* fix(doctor): report a .git/info that is a regular file as not writable on a dry run (#993)

Doctor checks MCP exclusion with a dry run, which never reaches
updateFileLocked and reads the unreadable exclude file as empty, so with
.git/info a regular file it reported "not injected" and pointed at
`teamai pull`. ensureExcludedFromGit's writability check now fails when
the closest existing path above the exclude file is not a directory, so
doctor's `MCP servers delivered to <tool>` gives the same not-writable
reason and fix as pull.

* fix(skills): deliver Codex skills into .agents/skills only over teamai's copy (#993)

Codex reads the shared .agents/skills, which other tools and the member
write to as well. The destination resolver took any existing copy there as
teamai's and wrote the team skill over it, silently at init. It now takes
an ownership predicate: pull asks judgeCopy against the checkout's record,
doctor the team history alone, and teamai remove and uninstall
isTeamaiSkillCopy. A copy that is not teamai's is left alone; the team
skill goes to .codex/skills/<name>, and every full pull names the conflict.
remove and uninstall delete only teamai's copy, in project and user scope.
Source skills and the built-in stub keep the old rule for now.

* test(doctor): give the older-copy fixtures a team history (#993)

Two doctor-delivery-cli cases wrote a stale agent and Cursor rule copy by
hand, with no delivery record and no team history: since #993 such a copy
is the member's, so doctor reported it as "not teamai's". Each now commits
the older version to the team repo first, so the copy is teamai's older
render, as the case means. The Cursor case restores the team rule and its
copy in a finally block, so a failure no longer breaks the cases after it.

* fix(skills): delete only teamai's skill directories on remove, uninstall and pull (#993)

teamai remove, uninstall, and pull's sweep of namespace-nested copies of an
excluded skill deleted any directory at a team skill's name, including a
member's own skill that pull keeps as not teamai's.

remove and uninstall now delete a skill directory only when a file under it
is on the checkout's record, or isTeamaiSkillCopy proves it (what pull writes
today from the team source, or a team version by the history), and name each
one they leave. remove judges before deleting the team source, so the local
agent's history-less resource cache still removes its own installs. uninstall
keeps trusting built-in names and names the local agent's manifest lists.
The nested sweep deletes a copy only when removedCopyChanged says it is
teamai's and unchanged.

* test(uninstall): drop the commitTeamRepo import the merge duplicated (#993)

* fix(source): deliver source skills where team skills go (#993)

Source skills resolve through the team-skill seam: the agent-exclusion
check, skillTargetForTool (Hermes home, OpenClaw workspace, Copilot home),
then Codex's shared-destination rule with a real ownership proof against
the source repo. Destinations outside the project are recorded as absolute
paths inside the tool's home and shared per source across projects. An
unrecorded existing copy that is no version of the source skill is the
member's and is kept. Copies earlier releases left in the project's
.hermes/skills and .openclaw/skills are reclaimed when unchanged, kept and
named otherwise.

* test(source): changed legacy source copies survive uninstall, remove and withdrawal (#993)

* test(pull): pin delivery of an agent held at the team revision once its alias resolves (#993)

A pull --force that holds an agent for its model leaves the checkout record at the team revision, so the next pull takes the fast path. The fast path's agent redeploy (#830) already writes the resolved model there, and a copy held before delivery is written as missing; no code change is needed. The test fails when that redeploy is disabled.

* fix(uninstall): delete only teamai's rule and agent copies on uninstall, remove agents and pull (#993)

uninstall and `teamai remove agents` deleted every rule or agent file at a
team name, and pull deleted the namespaced copy beside the author's root copy
on tools that do not flatten rules. Each now goes only on the checkout's
record or a team version by the history; built-in names stay deletable, and a
member's file is kept and named.

* fix(packages): leave a tracked .teamai/teamai.lock in place and name it in doctor (#993)

Moving a lock git tracks left a deletion in git status. A tracked (or
unknown) lock is now copied to the data home instead, and doctor names it
with git rm --cached, as it does the tracked hook index.

* fix(docs): keep a local doc when the team history cannot be read (#993)

The docs prune deleted a file the team no longer has when git could not
read the team history. Without proof the file is the member's, as
everywhere else.

* test(skills): cover an unrecorded older team copy in .agents/skills updated in place for Codex (#993)

* ci(e2e): drop the steps that prepared the real HOME the e2e sandbox replaces (#993)

The e2e setup file gives every test file a sandbox HOME with its own git
identity, and e2e.test.ts clones the fixture repo into it, so the git
identity, teamai config and fixture cleanup steps act on a HOME nothing
reads.

* docs(ci): describe the e2e HOME sandbox in the local e2e setup (#993)

* refactor(sync): build every not-teamai's line from one reason (#993)

* test(agents): prove the removed and superseded copies teamai's by the team history (#993)

* test(pull): give the docs prune fixtures a team history (#993)

* fix(source): name the source's version, not a team version, for a member's skill at a source skill's path (#993)

* refactor(local-agent): resolve a record's MCP file through recordedFileOf (#993)

* fix(coauthor): report a recorded settings file that is not JSON as unreadable, naming it (#993)

* test(mcp): wait for the session start's background pass before the git-info fixture cleans up (#993)

hook-dispatch leaves a detached --bg-only pass running in the sandbox HOME
after the foreground hook exits; it was still writing when afterAll removed
the sandbox, so CI failed the suite with ENOTEMPTY.

* test(opencode): keep the V1 hooks e2e off the npm registry (#993)

With any plugin configured, OpenCode's first request for a directory waits
for it to npm-install @opencode-ai/plugin into its config dir. On CI that
fetch outlasted the 5 s session request. teamai's plugins import nothing
from it, so the fixture records it as installed, and a failed session
request now carries the server log.

* fix(sync): name a kept copy of a removed resource as the member's or as an edit (#993)

judgeRemoval replaces removedCopyChanged with three outcomes: remove,
edited (changed since teamai delivered it, or on another checkout's
record), and notTeamais (no record, no team version). Pull's tombstone
cleanup and the rules sweep now say a member's own file is not teamai's
instead of claiming the member changed a teamai copy.

* fix(agents): delete a stale same-stem agent sibling only when it is teamai's (#993)

removeStaleAgentSiblings deleted every same-stem file with another
extension beside a rendered agent, a member's own included. It now goes
through judgeRemoval with the agent's origin and the checkout record, and
names a sibling it keeps. Built-in agents keep sweeping their own names.

* test(agents): record the stale Kiro .md sibling as teamai's in the fixture (#993)

* fix(docs): keep a member's entry whose type conflicts with a team doc (#993)

The mirror replaced a local directory at a team doc file's path, or a
local file at a team docs directory's path, and deleted the backup with
its staging directory. membersDocs now treats such an entry as the
member's unless the team history proves it teamai's (a file where the
team now has a directory, or a directory whose every file is a team
version), and copyDocs leaves a kept entry in place. A link is still
replaced without touching its target.

* test(skills): expect the not-teamai's line for a member's copy of a removed skill (#993)

* fix(docs): keep a member's link at a team doc's path, without following it (#993)

membersDocs skipped links, so the mirror still moved a member's link
aside and deleted it with the staging directory (rest of the Codex P1).
A link at a doc's path, or at an ancestor of one, is now the member's
unless the team has the same link there: it is kept, named and never
followed, and the docs under it are not delivered.

* ci: re-run checks after an unrelated recall-attribution flake (#993)

Node 22 on macOS failed on 9309e201 with one unhandled rejection from
src/__tests__/recall-attribution.test.ts (a votes-lock write outliving the
test's temp HOME); every test passed and #995 does not touch that code.
The fork cannot re-run jobs, so this empty commit re-triggers CI.

* ci: re-run the Codex PR review, cancelled at its time limit (#993)

* fix(mcp): save the manifest when an adoption records a server it did not rewrite (#993)

An unrecorded server equal to today's team render was adopted into the
in-memory records, but with no file write the manifest was not saved, so
a later team removal or uninstall found nothing owned and left the server
installed. The reconcile now saves the manifest whenever this run changed it.

* fix(mcp): preview a no-op MCP adoption on --dry-run, and cover uninstall (#993)

A dry run now says it would record an unrecorded server that already holds
the team's render, in .mcp.json-style files and in Codex config, and still
writes nothing. The real-CLI cases add the dry run before the adoption and
an adoption followed by teamai uninstall; both failed before b62e503b.
Hook adoption needs no change: reconcileHooks saves its records whenever
they differ from the previous ones, whether or not it wrote a file.

* fix(docs): keep a member's directory where the team removed a doc file (#993)

When the team deleted a doc file the member had replaced with a directory,
the prune walked into that directory and deleted its files, which match no
team version. A directory at a path where the team history had a doc file,
holding anything that is not a team version, is now kept whole and named.

* fix(mcp): remove an unrecorded copy of a server the team deleted (#993)

With a lost manifest, a server an older release installed stayed for good
once the team deleted it: only today's names were judged, and with no team
server and nothing owned the reconcile returned early. Pull and uninstall
now also remove an unrecorded entry, in .mcp.json-style files and Codex
config, that equals a render of that server from the team history. A
member's entry under that name stays. The early return now also requires a
team history with no MCP server.

* perf(sync): read the team's MCP history once per pull, in one git call (#993)

historicalContents read each historical blob with its own git process
(about 370 ms for 60 versions); it now reads them all with one
git cat-file --batch (about 30 ms). The MCP reconcile reads that history
once per run for every target, and only when a target file holds an
unrecorded entry; with no team server, nothing recorded and no server in
any target file it returns without reading it. A dry run names an
unrecorded copy of a server the team deleted that a pull would remove.

* fix(docs): keep a member's link where the team deleted a doc (#993)

The prune unlinked any link at a removed team doc's path. A link there is
now removed only when it is a version of that doc from the team history
(git stores a link as a blob of its target); a link of the member's stays,
and is never followed. A link at a path the team never had is pruned as
before.

* fix(coauthor): keep the record of a shared settings file that does not parse (#993)

A pull that could not read a recorded shared settings file dropped its
record, so once the member repaired the file no later pull removed the old
attribution value. The record now stays until the file can be read.

* fix(docs): keep any non-file entry of the member's where the team deleted a doc (#993)

A link at a removed team doc's path goes only when it is a version of that
doc from the team history; any other entry that is not a regular file stays
and is named. Adds the real-CLI case for a member's link replacing a doc.

* fix(sync): never adopt or write through a link at a delivered file's path (#993)

isTeamaiCopy and the copy judgement followed links: a link at a rule or
agent path whose target held an older team version was taken as teamai's,
and the next pull wrote through it into the member's file. A link in place
of a delivered file is now the member's (kept, named), a link there is
never removed as teamai's copy, and a skill directory holding a link is not
teamai's copy, since copying over it would write through it.

* fix(docs): keep a member's directory of links where the team deleted a doc file, and do not call it stale (#993)

A directory that replaced a former team doc file and held only links read
as teamai's (links are not listed), so the prune removed it. Such a
directory is now the member's whenever it holds a link. doctor also stops
listing files inside a directory pull keeps whole as stale docs.

* fix(hooks): recognize unrecorded team hooks in every format, on pull and uninstall (#993)

Pull recovered a team hook entry whose record was lost only in Claude and
Codex files. In Cursor, Copilot and ZCode files the old entry stayed as the
member's and the new one was added beside it, so both ran. Each entry is now
compared with the team's hooks rendered the way that format's reconciler
writes them; one equal to exactly one hook is replaced or removed as teamai's.

Uninstall did not judge unrecorded entries at all, so with the records lost
it left custom team hooks installed, and missed a main-checkout Codex file
holding only team hooks. It now judges every hook file against the team's
hook history, gated to the project as pull renders them in a non-self
project scope, and removes the entries equal to exactly one team hook.

* fix(sync): treat any non-regular entry in a skill or docs directory as the member's (#993)

A directory is teamai's copy only when every entry is a regular file that
is a team version; a link or any other non-regular entry anywhere below it
makes it the member's. Adds real-CLI cases for a skill directory holding a
link and a docs directory of links where the team deleted a doc file.

* fix(sync): keep a member's link at any delivered path (#993)

A link at a delivered skill directory, rule or agent file, docs entry or
source skill destination is the member's: teamai never creates links, so
it is never adopted, replaced, written through or deleted, on pull,
remove and uninstall alike. Pull and doctor name it: "Kept <path>: it is a
link of yours, so teamai does not replace it. Remove the link to receive
<name> from the team."

This deliberately changes earlier behavior: source and team skills used to
replace a leaf link in place of a skill directory with a copy, and the
Codex duplicate cleanup deleted a configured leaf link. The source tests
that asserted those now expect the link kept.

* fix(agents): prove a tombstoned agent copy teamai's in a team-defined tool too (#993)

For a tool teamai renders no agents for, the tombstone cleanup had no
proof to check and removed any file with the removed agent's name. It now
removes it only when it is a team agent's own bytes from the history; a
member's file of that name stays.

* fix(rules): never read through, write through or delete a member's link at a rule path (#993)

The cleanup and rerender paths judged a rule copy by reading the file a
link points at, so a link whose target held a team render was rewritten
through or deleted: the "Already synced" rerender, the legacy rules
directories (pull and uninstall), the reserved teamai-context name, the
unselected-rule sweep, the moved nested copy, the flat OMP and Kiro
copies, the older .md layout, and teamai remove rules. Each now treats a
link as the member's and leaves it. The empty-directory sweep no longer
deletes a directory whose only entries are links.

* fix(agents): keep a member's link where an agent was delivered, on pull and teamai remove (#993)

The inactive-namespace cleanup judged a copy by the file a link points at, and teamai remove agents deleted the author's root copy by its placement record alone. A link at either path is now the member's and stays.

* fix(skills): keep a skill directory that holds a member's link, on pull, remove and uninstall (#993)

A recorded skill whose file the member replaced with a link to the same
bytes read as unchanged, so pull copied over the link and remove,
uninstall and the tombstone and inactive-namespace sweeps deleted the
directory with every link in it. A skill directory holding a link is now
the member's on pull, named by the link, and kept by every sweep.
teamai remove skills also judges a link at a built-in skill's name
before the name.

* fix(sync): keep an unrecorded file teamai cannot read where a removed resource was delivered (#993)

judgeRemoval counted a file it could not read as absent and removed it. Without its bytes nothing proves it teamai's, so it is now kept as the member's.

* fix(docs): never read through or delete inside a member's link in a deactivated docs namespace (#993)

Withdrawing a namespace's docs read each copy through any link on its path and deleted what matched the team file. A namespace directory the member linked to a folder of their own lost its files, and a linked doc was deleted. A path through a link is now left alone.

* fix(source): keep a source skill copy that holds a member's link, on pull and source remove (#993)

A recorded destination was the source's whole, so pull copied over a link the member put inside it and source remove deleted the directory with it. Such a copy is now the member's: pull names the link and source remove keeps the directory on record.

* fix(local-agent): keep a member's link where the local agent installs a skill or rule (#993)

The local agent installs through pullItem with no delivery record, which skipped every ownership check: a rule was written through a link and a skill directory link was replaced. A link at the path, or inside the skill directory, is now kept and named.

* fix(sync): deliver team and source skills without the links in them (#993)

Copying a skill recreated each link in its source as a link in the
member's tool directory, which then read as the member's own, and let a
skill plant a link to any target. Delivery now skips a link in a team or
source skill, without following it, and names each one once:
"Skipped <link> in <skill>: teamai does not deliver links."

* fix(docs): keep a member's link in the docs mirror at a path the team never had (#993)

This deliberately changes the mirror prune: it used to unlink any link at
a path the team repo's history never had, as a local leftover. teamai
never creates a link there, so such a link is the member's: pull now
keeps it and names it, and doctor no longer reports it as a stale doc.
A link matching a team link once at a removed doc's path is still pruned.
The docs and doctor tests that expected the unlink now expect it kept.

* docs(designs): state that teamai never follows, replaces or deletes a member's link (#993)

* fix(uninstall): remove only teamai's docs from the docs mirror, and keep the member's (#993)

Uninstall deleted the whole docs directory, so a file pull had kept as
the member's, a directory or a link of theirs went with it. It now
removes a file or link only when it is a version of that doc from the
team repo's history, names everything else, and removes a directory only
once it is empty. While the history cannot be read, the mirror stays
whole. A mirror inside the data home that keeps something survives the
removal of that home with it.

* fix(mcp): write a linked MCP config through its link, and keep its target out of git (#993)

A member's MCP config can be a symlink into a dotfiles repository. The
atomic writes replaced the link with a regular file. They now write at the
file the link points to, rollbacks included, and a linked CodeBuddy
~/.codebuddy/mcp.json is kept rather than deleted.

A resolved value then lands in the link's target, so the git checks judge
that file in its own repository: a target that repository tracks gets no
value, and an untracked one is listed in that repository's info/exclude,
which pull and uninstall now find to take the line out again.

* fix(docs): name a kept link at a removed doc's path as before, and only a never-team path's link as such (#993)

Goes with keeping a member's link at a path the team never had: a link at a removed doc's path keeps the line that says the team removed it.

* test(skills): expect pull to name the member's link inside a skill directory (#993)

* fix(opencode): keep a member's linked opencode.json and openclaw.json as links (#993)

The OpenCode instructions writer and the OpenClaw hook entry writer
replaced a symlinked config with a regular file, and uninstall deleted a
linked .opencode/opencode.json left holding only its $schema. Both now
write at the link's target, and a link is never deleted.

* fix(rules): never delete a linked CLAUDE.md or AGENTS.md when its teamai section goes (#993)

Removing teamai's section from an instruction file teamai created deleted
the file once nothing else was left, a member's link to it included. A
link stays; its target is emptied instead.

* fix(skills): push no links to the team repo, and name why remove and uninstall keep a skill directory (#993)

A push copied a link inside the member's skill into the team repo, so every
member then received a skill teamai will not deliver; push now skips each
link and names it. remove and uninstall now say a kept skill directory is a
link of the member's, or holds one, instead of claiming it has no delivery
record.

* fix(source): keep reading a record into a removed OpenClaw workspace, and never another repository's history (#993)

A source record of a copy in an OpenClaw workspace outside ~/.openclaw was
rejected once that workspace was gone, so every pull and source remove of
that source failed. The configured workspace now counts as a tool home even
when its directory is missing. A source cache without its own .git no
longer lets git read an enclosing repository's history (a dotfiles HOME):
only today's source proves a copy then.

* fix(source): leave a copy in a tool home that moved, instead of rejecting the record (#993)

Configuring OpenClaw to another workspace made the record of a copy in the
old one invalid, so every pull and source remove of that source failed.
The record now notes the tool home of each absolute destination; one whose
home moved is dropped from the record and its copy left as it is, while an
absolute path the record cannot account for is still rejected.

* fix(docs): keep the member's hidden files on uninstall, and match a link only to a team link (#993)

uninstall did not count hidden entries in the docs mirror as kept, so with
nothing else kept it deleted the data home around them. They are now named
and keep the mirror. A link in the mirror is now teamai's only when the
team history had a link with that target there, not a file holding the
same text (the history now carries each version's git mode).

* fix(skills): keep a delivered skill directory that holds a file the member added (#993)

A skill directory with any file on record was taken as teamai's whole, so
remove, uninstall and the tombstone cleanup deleted a file the member had
added beside teamai's. A recorded directory now goes only when every file in
it is on record or a team version; otherwise it is kept whole and named.
Source skill removal applies the same rule against the source's files and
history.

* fix(skills): remove and uninstall take only teamai's files from a skill directory (#993)

When a delivered skill directory holds a file the member added, remove and
uninstall now delete only the files on record or matching a team version,
name each file they keep, and leave the directory while anything is left in
it. uninstall plans the exact files, so its dry run shows them.

* fix(source): keep a member's file at the path of a link the source skill has (#993)

Delivery never copies a link from a source skill, but removal counted any
history at that path as the source's, the link included, so a regular file
the member put there was deleted with the skill. Only a regular file the
source has, or had, is the source's now.

* fix(mcp): find teamai's CodeBuddy servers in every user MCP file, and treat a linked lookup path as its target (#993)

A server an earlier teamai left in a CodeBuddy user MCP file that CodeBuddy no longer reads stayed there once its record was lost: pull and uninstall looked only at the file CodeBuddy reads, and returned early when that file was empty. They now also look at the other lookup files that exist and remove an unrecorded entry equal to a current or historical team render; a member's entry stays.

Lookup files are compared by real path. With ~/.codebuddy/.mcp.json a symlink to ~/.codebuddy/mcp.json, a pull recorded the server at the link and then removed it from its target, the same file. With ~/.codebuddy.json a symlink to ~/.codebuddy/mcp.json, the upgrade move emptied and deleted the file the link points to.

* fix(sync): prove a CONTRIBUTORS file like any other, and a file only by a file the team had (#993)

A skill's CONTRIBUTORS file counted as teamai's by its name alone, so remove
and uninstall deleted the member's own one, and it never made a directory
the member's. It now needs the same proof as any file. A link in the team
history no longer proves a regular file holding the same bytes, and a
version that changed only its mode is kept as its own version.

* fix(skills): keep a delivered skill when the team or the source adds a file where the member has one (#993)

A file the member added to a recorded team or source skill was overwritten
once the team, or the source, delivered a file at that path. Pull now keeps
such a copy whole and names it, as an edited one, unless the file is a
version from the history. A source removal keeps a copy holding a file of
the member's only when the source's own files prove the copy came from it:
a copy from a replaced repository, or one an in-repo alias placed, is left
to the record, as before.

* fix(docs): keep a file of the member's at a path the team never had (#993)

The docs mirror pruned any local file at a path the team history never
had, so a member's own notes there were deleted on the next pull. Having
no team version is no proof that teamai put a file there: the prune now
removes only teamai's copies of docs the team removed, and leaves the
member's own files without a word. doctor stops calling them stale, and
the usage guide no longer says local drafts are removed. Earlier tests that
expected such files pruned now use team docs the team removed.

* docs(designs): the docs mirror prunes only teamai's copies of removed docs (#993)

* fix(rules): remove a rule copy that holds what pull writes today (#993)

`remove rules` deleted a tool's copy only on the checkout's record or the
team history. A checkout without history and without a record, such as a
resource cache, left teamai's own copy behind. The copy that holds today's
render of the team rule, or the rule verbatim, is now teamai's too, read
before the team file goes, as `remove skills` already does.

* fix(source): keep a source skill copy holding the member's file, on record (#993)

A copy pull kept whole because the source added a file where the member
had one was left off `installedSkills`, so `source remove` forgot it and
dropped the manifest. It stays on record now. Removal then tells the
source's files from the member's by their bytes, not their path, and a
file at a path the skill never had keeps the directory even when no file
of the source is left in it.

* test(local-agent): uninstall_rule removes the installed copy and keeps the member's (#993)

* fix(mcp): tell another tool's server by the file's real path (#993)

An entry another tool's record claims in the same file is left to that
tool. The file was compared by name, so a tool whose MCP path links to
another's file adopted that tool's server once its own record was lost,
and a later removal for it would take the server from the shared file.
It is compared by real path now, as the rest of MCP reconciliation does.

* fix(source): keep a source skill copy whose every file the member edited (#993)

Removal kept a copy holding an edited file only when another file still
matched the source. A copy whose every file the member edited, such as a
single SKILL.md, was deleted by `source remove` or by a pull after the
source withdrew the skill. When the source history has the skill, a file
that matches no source version keeps the copy.

* fix(ownership): keep a member's entry of the other type at a delivered path (#993)

A file where a team skill directory goes, or a directory where a rule or
agent file goes, was not judged the member's. Delivery over it failed, yet
the pull could record the team revision as synced, so once the member
removed the entry a plain pull delivered nothing until the team changed or
the member ran `pull --force`. Such an entry is now kept and named, and the
next pull after it is gone delivers the team version.

* fix(skills): keep a member's file when removing a skill with a built-in's name (#993)

`teamai remove skills <name>` deleted the whole directory when the name is
one the CLI once shipped (such as team-wiki-codebase), so a file the member
added beside it was lost. It now removes the files the team history proves
teamai's and the files a release packaged there, as uninstall does, and keeps
and names a directory left holding anything else.

* fix(skills): keep a delivered skill when the team adds a file where the member has a directory (#993)

When the team added a file to a delivered skill at a path where the member
had a directory, or a directory where the member had a file, the copy failed
inside pull and the pull still advanced to the team revision, leaving the
skill stale. Such an entry is the member's now: the skill is kept whole and
named, as when the team adds a file where the member has one.

* fix(local-agent): tell CodeBuddy's user MCP file by its real path (#993)

With `~/.codebuddy/.mcp.json` linked to `mcp.json`, a record an older agent
wrote without a file resolved to `mcp.json`, while the install target was
`.mcp.json`. The record was dropped as another file's, so reinstalling the
same server failed as "not managed by teamai". Records are matched to the
target by real path now, as MCP reconciliation does.

* fix(skills): deliver a skill around a member's entry of the other type, and retry failed copies (#993)

A member's directory where the team adds a file to a delivered skill, or a
file where it adds a directory, is the member's: it is kept and named, the
files it covers stay undelivered, and the rest of the skill is delivered.
The pull is not counted as synced, so the next one is a full sync that
delivers those files once the entry is gone.

A skill, rule or agent copy that fails with an error no longer counts as
synced either: the revision stays, and the next pull retries it.

* fix(source): keep a source skill copy when the source adds a directory where the member has a file (#993)

A file of the member's where the source now has a directory was missed by
the collision check, so the copy failed on the conflict instead of keeping
the member's copy. An entry of the other type at a source path, or at one of
its parents, is the member's now, also when the source cache has no history.

* fix(uninstall): keep OpenCode's user plugin on a project uninstall (#993)

The plugin in the user's OpenCode config now also carries the team rules and
instructions for V2, for every project and the user scope. A project-scope
uninstall removed it, which ended delivery for every other project. It keeps
it now and names it, as it does for the other global adapters; a user-scope
uninstall still removes it, and so does `teamai hooks remove`.

* fix(skills): keep a skill directory holding a git repository of the member's (#993)

The ownership check reads a skill directory's files the way delivery lists
them, which skips `.git`. A recorded skill whose files matched was then
deleted whole by `teamai remove`, `uninstall` or a source removal, taking a
repository the member made in it, with its local commits. A directory holding
a `.git` is never deleted whole now; only teamai's files in it go.

* fix(local-agent): keep a CodeBuddy server copy the member edited when moving it (#993)

When CodeBuddy's preferred user MCP file changed, reinstalling a server
moved it there and deleted the copy in the old file without checking it.
A copy the member edited since teamai installed it is kept now, and named.

* fix(local-agent): keep a CodeBuddy server's record until its move is written (#993)

Moving a server to the user MCP file CodeBuddy now reads recorded it in the
new file before writing it there. When that write failed, the record pointed
at the new file while the server stayed in the old one, so uninstall left it
installed. The old file's record is existing ownership now: it stays until the
new file is written, as for a server already recorded in the target file.

* fix(uninstall): record a project's OpenCode exclusion when its plugins are kept (#993)

A project-scope `uninstall --agent opencode` keeps the user plugin
directory, so with only a server-pushed agent-hook plugin there the plan was
empty: it said "Nothing to uninstall" and never excluded OpenCode, whose
global hooks stayed active for the project. OpenCode now takes the
exclusion-only path, like the other tools with global channels, and the kept
agent-hook plugins are named with the other retained adapters.

* fix(docs): keep a member's doc that has the bytes of a team doc that is a link (#993)

A regular file of the member's at the path of a team doc that is a link was
taken for teamai's copy when its bytes matched the link's target, and the
mirror replaced it with the link. Equal bytes now prove a copy only of a team
file; such a doc is the member's unless the team history has that file.

* fix(mcp): judge each CodeBuddy lookup file with the tools that write it (#993)

Cleaning CodeBuddy's other user MCP files reused the ownership check built for
the file it reads, which knew of no other tool writing there. With
`~/.codebuddy/mcp.json` linked to Claude's `~/.claude.json`, Claude's copy of a
team server matched CodeBuddy's render and was deleted through the link. Each
file is now judged with the records of every tool whose MCP file it is.

* fix(docs): judge a deactivated namespace's doc by its type as well as its bytes (#993)

When a docs namespace stops being active here, its copies that are teamai's
are removed. A member's regular file whose bytes equal the target of a team
doc that is a link was taken for teamai's, through the link and through a
history check that also matched link versions, and deleted. A file is
teamai's only as a team file now, today's or one from the history, as on
every other docs path that deletes or replaces (prune, copy, uninstall).

* fix(mcp): count another tool's servers in a shared file even when it is not detected (#993)

Whose entries a config file holds was judged only with the tools detected on
this run. With `~/.codebuddy/mcp.json` linked to Claude's `~/.claude.json` and
Claude no longer installed, a CodeBuddy pull took Claude's identically rendered
server for its own and deleted it through the link, leaving Claude's record
stale. Every tool that maps a file counts now, detected or not: detection
decides where teamai writes, never what it may delete. Doctor judges the same way.

* fix(mcp): restore a file two tools write through linked paths once, to its first state (#993)

Configs written during an MCP sync are restored when ownership cannot be
saved. Snapshots were keyed by path, so a file two tools reach through
linked paths got one per path and the later one, taken after the first
tool's write, was restored last: the server stayed without its record. One
snapshot per real file now, taken before its first write.

* fix(coauthor): leave a settings file that does not parse as it is (#993)

Project scope writes the co-author setting to `.claude/settings.local.json`,
the member's own file. One that did not parse was read as empty, so a pull
replaced the whole file with teamai's `attribution` block and the member's
settings were lost. A Claude or Cursor file that is not a JSON object is now
left untouched and reported as skipped, and the setting is written on the
first pull after the member repairs it.

* fix(hooks): leave a hook settings file that does not parse as it is (#993)

Every hook writer read its settings file as empty when it did not parse, so
a pull or a session-start pass while the member was mid-edit of, say, their
HOME `~/.claude/settings.json` replaced the whole file with teamai's hooks.
The Claude, Cursor, Copilot, Codex and ZCode writers, and the agent-hook
install and removal, now leave such a file byte-identical and say which file
and why; nothing is recorded, and the first pull after the repair writes it.

* fix(docs): never walk a docs mirror that is a link of the member's (#993)

When `sharing.docs.localDir` itself was a link to a personal directory,
uninstall walked it and deleted the files behind it that matched a team doc
from the history, outside the mirror. A mirror root that is a link is now the
member's on every path: pull copies, prunes and withdraws nothing through it
and names it, doctor reports it, and uninstall leaves it and what it points at.

* fix(uninstall): keep the record of hooks a settings file that does not parse still holds (#993)

Uninstall left out a hook settings file that did not parse, then deleted the
data directory holding the record of its hooks; once the member repaired the
file, teamai's hooks ran there with no record left to remove them by. Such a
file is now tried, named and left as it is, and the data directory stays, so
uninstall run again after the repair removes them. `source remove-http` and
uninstall keep the record of an HTTP agent hook they could not remove, and the
local agent's directory with it, instead of clearing the whole manifest.

Pull also names a docs mirror that is a link before counting or previewing
its files, so it never walks it, on a dry run either.

* fix(uninstall): report an uninstall that left hooks in place as incomplete (#993)

When a hook settings file could not be cleaned, uninstall kept the data
directory but still said "teamai uninstalled" and exited 0, and a targeted
uninstall of the last tool did not record the tool as excluded, so the hook
left in place could sync its resources back. Hooks left in place now make the
uninstall incomplete, as an OpenCode entry it could not remove does: exit code
1, the files named, and the tool excluded. The message for a settings file that
does not parse no longer points at `teamai pull`.

* fix(uninstall): stop hooks an incomplete uninstall left in place from syncing back (#993)

A full uninstall that could not remove a tool's hooks kept the data directory
with every tool still enabled, so the hook left in place ran a session-start
pull that restored what had just been removed. Each tool whose hooks remain is
now excluded, and the session-start pull of an excluded tool's hook does
nothing, as its instruction and HTTP handlers already did, until the uninstall
is run again after the repair.

* fix(local-agent): keep removed HTTP sources disabled (#993)

* fix(local-agent): serialize HTTP sync and source removal (#993)

* docs(http): describe skipped concurrent hook syncs (#993)

* fix(uninstall): remove the HTTP source under its lock before teardown (#993)

A full user-scope uninstall removed agent hooks, plugins and ~/.teamai
without the local-agent lock, so a hook sync paused after loading its
config could reinstall resources once uninstall reported success.
Uninstall now runs the remove-http shutdown first: it waits up to 30
seconds for the lock, disables the source before teardown, and exits 1
without removing anything when the lock cannot be taken.

* fix(local-agent): let a server-pushed uninstall hold its sync's lock (#993)

A sync holds the HTTP source lock while it runs an uninstall_teamai
command, so the uninstall it spawns waited for that lock until the hook's
15-second budget killed the sync, unacknowledged and with teamai still
installed. The sync now passes its pid to the command; a child whose
parent holds the lock runs under it without acquiring or releasing it.

* docs: point the kept-edit links in sharing at member-guide's Auto-sync

The Auto-sync section moved to member-guide in the docs reorganization,
so the in-page anchors #993 added no longer resolve.
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
… the SessionStart hook (Tencent#370)

* fix(hooks): unify hook-injection scope so project-scope init installs the SessionStart hook

Project-scope `teamai init`/`pull`/`bootstrap` resolved the hook base dir
via resolveBaseDir → <projectRoot>, but on a fresh init <projectRoot>/.claude
does not exist yet, so the "only inject into installed tools" gate skipped
every tool. Result: no SessionStart hook was written anywhere, so opening
Claude never triggered the background `teamai pull` and skills never
auto-synced. `teamai doctor` then checked <projectRoot>/.claude too and
always reported the hooks missing.

Meanwhile the `hooks inject` command already wrote to HOME (Tencent#264). The two
paths had drifted.

Introduce `resolveHookScope(localConfig)` in types.ts as the single source
of truth for the (baseDir, manifestPath) pair, and route init/pull
(hooks.ts), the hooks command (hooks-cmd.ts), and doctor (doctor.ts)
through it:
- non-self project scope → HOME (~/.claude always exists, the dispatch
  runtime resolves the active project by cwd) — matches Tencent#264
- self single-repo mode → projectRoot (hooks committed to main travel on
  clone and self-heal)
- user scope → HOME

Tests: rewrite hooks-reconcile-scope to stub HOME to a sandbox and assert
project-scope injection lands in HOME; add a self-mode regression that
locks injection to projectRoot. Verified end-to-end with the real CLI:
project-scope `hooks inject` writes the SessionStart hook to
~/.claude/settings.json (not <projectRoot>/.claude) and `doctor` now passes.

* fix(hooks): address Tencent#370 review — unify uninstall/migrate scope, docs, tests

Follows up the resolveHookScope unification with the paths that still
bypassed it and the cheap review items.

- uninstall (#1, blocking): buildRemovalPlan discovers hooks at the
  resolveHookScope target (HOME + user manifest for a non-self project
  scope) instead of <projectRoot>, so uninstall no longer leaves the
  SessionStart hook live in HOME forever; a legacy <projectRoot> copy is
  swept too, each hookFile tagged with its own manifest.
- inject legacy sweep (#2, blocking): reconcileTeamHooksForConfig
  (init/pull/bootstrap) and hooks inject now clear the legacy
  <projectRoot> copy after writing HOME, so an upgraded project does not
  fire hook-dispatch twice.
- doctor tests (#3): lock the project-scope→HOME and self→projectRoot
  branches of resolveHookScope.
- docs (#4): usage-guide.md/.zh-CN note hooks are no longer isolated in
  project mode (injected into HOME; self mode keeps them in the repo).
- dead abstraction (#5): drop resolveHookScopeTargets/HookScopeTarget;
  hooks-cmd destructures resolveHookScope directly.
- autoMigrateHooksIfNeeded (#7): reinject via resolveHookScope so the
  HOME old-format guard converges instead of re-firing every pull.
- hooks remove self mode (#9): gate the legacy sweep to a project-owned
  <projectRoot> (resolveLegacyProjectHookScope), never HOME (shared with
  user scope) and never a redundant re-run on the primary target.
- resolveHookScope robustness (#11): self mode missing projectRoot now
  degrades to HOME instead of throwing, so doctor never crashes.

Architectural findings (#6 machine-wide team hooks + cross-project
manifest collision, #8 OpenCode stale project cleanup, #10 gate/resource
base-dir split) are tracked separately.

* fix(hooks): stop the legacy sweep from deleting the hooks it just wrote

The Tencent#370 review follow-up introduced a <projectRoot> legacy sweep via
reconcileHooksToAllTools(removeAll). Two tools do not honour its baseDir,
so for a non-self project scope the sweep undid the primary pass:

- Hermes reconciles through removeHermesHooks(), which takes no base dir
  at all, and OpenCode through an adapter whose removeAll branch always
  targets HOME. Injecting installed ~/.config/opencode/plugin/teamai-hooks.ts
  and $HERMES_HOME/hooks/teamai-status-report.sh; the sweep then deleted
  both. Every init/pull/hooks inject repeated the install-then-delete, so
  those two tools ended up with no teamai hooks at all.
- resolveLegacyProjectHookScope did not check projectRoot against HOME, so
  `teamai init .` run in ~ (dotfiles repo) made the "legacy" location and
  the live target the same file — the sweep stripped every hook just
  written, reproducing the very bug Tencent#370 fixes.

Fixes:
- Add `settingsOnly` to reconcileHooksToAllTools, skipping the two global
  adapters, and extract the shared sweepLegacyProjectHooks() used by
  init/pull/bootstrap, `hooks inject` and `hooks remove`. It removes the
  project-scope OpenCode plugin directly, so the stale <projectRoot> copy
  is still cleaned without touching the HOME one.
- resolveLegacyProjectHookScope returns null when projectRoot resolves to
  HOME, making the "never returns HOME" invariant callers rely on hold.
- Drop filterAgents from the sweep: cleanup of a legacy location must be
  unconditional, or a tool disabled today strands the copy it wrote while
  it was enabled.

Tests: 4 disk-level cases in hooks-reconcile-scope (HOME OpenCode/Hermes
survive, legacy project plugin still removed, filtered-out tool still
swept, projectRoot===HOME not wiped) — all 4 fail without this change; 5
resolveLegacyProjectHookScope unit cases in types.test; hooks-cmd updated
for the extracted helper.

Verified: tsc clean, 2421 tests pass, and a real CLI run against a
sandbox HOME + project-scope config with pre-seeded legacy state —
inject keeps HOME's claude/cursor/opencode/hermes hooks, clears
<projectRoot>/.claude and <projectRoot>/.opencode, doctor reports both
checks green, a second inject is idempotent, projectRoot===HOME keeps its
SessionStart hook, and `hooks remove` clears everything including Hermes
and OpenCode.
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.

1 participant