Skip to content

fix(upkeep): the home folder is not a repository — never refresh its wiring (#829) - #860

Draft
hr1juldey wants to merge 1 commit into
trailhq:mainfrom
hr1juldey:fix/829-home-guard-upkeep
Draft

hr1juldey wants to merge 1 commit into
trailhq:mainfrom
hr1juldey:fix/829-home-guard-upkeep

Conversation

@hr1juldey

@hr1juldey hr1juldey commented Nov 18, 2026 •

Copy link
Copy Markdown

Fixes #829.

Root cause

wiredHostIds(~) reads ~/.claude/helpers/*.cjs — user-scope agent wiring — as if it were repository wiring. On a version change, reconcileWiring(~) then finds hosts "wired", runs the full rewrite path against the home folder, and clearOldLayout deletes the user-scope helpers and skills while disableGraftServerIn disables the graft MCP server in projects[~] — with trail mode registering no replacement. It repeats on every version change.

Fix

reconcileWiring now refuses the home folder before reading or writing anything — the same homeFolderRefusal the explicit trail init command already gives (runInitCommand), applied to the automatic path that fired without the person choosing anything. Since rewriteWiring (and therefore runInit, clearOldLayout, and disableGraftServerIn) is only reachable through reconcileWiring on the upkeep path, this one guard closes the whole chain.

The guard is positional: only ~ itself is refused. A real repository under the same home refreshes exactly as before.

Tests (RED→GREEN, adversarial)

  • a fake home carrying only user-scope wiring (.claude/helpers/graft-hooks.cjs): reconcile returns null, the rewrite spy never fires, the helper file survives;
  • a home stamped by an older version: still refused on upgrade — the guard is positional, not stamp-based (the stamp-as-intent path cannot resurrect the wipe);
  • a real repository under the same home: still refreshes, rewrite actually ran — proving the guard does not over-refuse.
  • Full suite: fail-6 (the six pre-existing main failures), 4551 tests.

…wiring (trailhq#829)

User-scope agent wiring (~/.claude/helpers/*.cjs, ~/.claude/skills, the
graft MCP entry in ~/.claude.json) made the home folder look like a
wired repository: wiredHostIds(~) reads ~/.claude/helpers, so a
version-change upkeep ran a full wiring refresh against ~ —
clearOldLayout deleted the user-scope helpers and skills, and
disableGraftServerIn disabled the graft MCP server with nothing
registered in its place, on every version change.

reconcileWiring now gives the home folder the same refusal "trail
init" already gives it (homeFolderRefusal), before anything is read or
written: no stamp replay, no rewrite, no deletion. The guard is
positional — only ~ itself is refused; a real repository under the
same home refreshes exactly as before. The explicit-init path was
already guarded in runInitCommand; this closes the automatic path,
which is the one that fired without the person choosing anything.
@hr1juldey
hr1juldey force-pushed the fix/829-home-guard-upkeep branch from b07ecb6 to 0c7c67e Compare November 18, 2026 18:22
github-actions Bot added a commit that referenced this pull request Nov 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🌱 graft blast radius

1 area changed → 3 areas can be affected. 3 dependent symbols, depth 2.
Tests: 1 area updated its tests.
Tag: @anirudhkumar-nanonets — 4 of 4 areas · @shhdwi — 4 of 4 areas

flowchart TB
  A0(("Claude Hooks<br/>1 symbol"))
  A1(("Upkeep Execution<br/>1 symbol"))
  A2(("MCP Server<br/>1 symbol"))
  classDef reached fill:#D9EDF3,stroke:#3AA7C9,stroke-width:1.5px,color:#0E313C;
  class A0,A1,A2 reached;
Loading
Can be affected Symbols Nearest hop Reached from
Claude Hooks 1 src/claude/hooks.ts:L537-L627 main — calls, depth 2 Wiring Reconciliation
Upkeep Execution 1 src/upkeep-run.ts:L85-L102 runUpkeep — calls, depth 1 Wiring Reconciliation
MCP Server 1 src/mcp/server.ts:L101-L256 startMcpServer — calls, depth 2 Wiring Reconciliation
Who knows this code — 2 people across 4 areas
Area Who knows it
Wiring Reconciliation · changed @anirudhkumar-nanonets — 6 commits, last 1mo ago · @shhdwi — 3 commits, last 23d ago
Claude Hooks · affected @anirudhkumar-nanonets — 23 commits, last 10d ago · @shhdwi — 14 commits, last 22d ago
Upkeep Execution · affected @anirudhkumar-nanonets — 6 commits, last 1mo ago · @shhdwi — 3 commits, last 23d ago
MCP Server · affected @anirudhkumar-nanonets — 7 commits, last 22d ago · @shhdwi — 5 commits, last 22d ago

Ownership is git history over each area's own files, weighted towards recent work (120-day half-life). Merge commits and bots are dropped, and you are dropped from your own PR. A name with no @ has no GitHub handle in its commit email — tag them by hand, or add a .mailmap entry. A suggestion from history, not a CODEOWNERS rule.

All 3 dependent symbols, grouped by area

Claude Hooks — 1 symbol in 1 file

  • src/claude/hooks.ts:L537-L627 — main (calls, depth 2)

Upkeep Execution — 1 symbol in 1 file

  • src/upkeep-run.ts:L85-L102 — runUpkeep (calls, depth 1)
    92: const refreshed = reconcileWiring(repo, current, { rewrite: rewriteWiring, toTrail: (r) => shouldMoveToTrail(r) });

MCP Server — 1 symbol in 1 file

  • src/mcp/server.ts:L101-L256 — startMcpServer (calls, depth 2)
Test signal per changed area — 1 ✓

Reached = a node under a test path has a resolved edge into the changed symbol. It undercounts anything called indirectly — through a CLI, a spawned process or a dynamic import — so read a low ratio as “look here”, never as a coverage gate.

  • ✓ Wiring Reconciliation — 1 of 1 reached · 1 test file changed here: test/upkeep.test.ts
4 test suites also reference this code

4 symbols, kept out of the diagram and the table so they cannot crowd out the areas a reviewer has to look at.

  • test/graft-to-trail.test.ts
  • test/hosts-trail.test.ts
  • test/init-agents-auto.test.ts
  • test/trail-init-upgrade.test.ts

graft blast · origin/main...HEAD · depth 2 · 2 changed files

Open the interactive graph → — click an area to see its dependent symbols at file:line.

This branch has not been deployed

No deployments
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.

Trail upkeep treats home as a repo and removes global Claude wiring on upgrade

1 participant