Skip to content

fix(companion): refresh Claude links in linked worktrees and after sync - #228

Merged
TornquistK merged 2 commits into
mainfrom
workset/refresh-claude-links-in-linked-worktrees
Dec 2, 2026
Merged

TornquistK merged 2 commits into
mainfrom
workset/refresh-claude-links-in-linked-worktrees

Conversation

@TornquistK

@TornquistK TornquistK commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A skill added to the companion reached only the Registered Checkout. Linked worktrees kept their old .claude/skills, and mate companion sync refreshed no links at all.

 refreshWorkingClaudeLinks(companion)
   for entry in registry
-    reconcile(entry.path)
+    for checkout in liveCheckouts(entry's clone)   # main worktree first, each once
+      skip if checkout's projection names another companion
+      skip unless checkout's own wrap state has claude
+      reconcileSkillLinks(checkout, { keepExistingFolder: true })
+      reconcileCommandLinks(checkout)
+      report { ...entry, path: checkout }
 reconcileWorkingRepoClaudeSkillLinks(checkout, …, options)
-  placed = enabled && !servedByMainWorktree
+  placed = enabled && ((keepExistingFolder && .claude/skills is a directory) || !servedByMainWorktree)

The wrap pass passes no option, so session prepare still withdraws a Mate-only folder. A missing folder is never created: a session may be running there. A clone linked to two companions ("Keep both") keeps each checkout's links with the companion its projection names.

 runCompanionSyncCommand
   syncCompanionGit
   settleLinked
+  refreshClaudeLinks          # completed syncs only; readCompanionConfig; reports written + failed; warns, never fails

reportLinkRefresh moved to companion/link-refresh-report.ts; sync filters out current results before reporting. commands.mdx documents both commands.

Evidence

  • Before: 4 of the new tests in refresh-working-claude-links.test.ts failed
    (fail) a worktree's Mate-only skills folder gets an added skill and stays
    (fail) the operator's own skill stays beside the added link
    (fail) a worktree gets an added command
    (fail) each worktree of a bare clone gets its own links
    
    After: all pass, plus the regression guards; each guard fails when its fix is broken by hand
    (pass) a worktree without a skills folder gets none while the main worktree links the skill
    (pass) the companion's first skill reaches the main worktree, not a worktree without a folder   # red when worktrees run before main
    (pass) a worktree linked to another companion is left to it                                     # red without the projection skip
    (pass) an unwrapped worktree and a locked one whose folder is away are left alone
    
  • sync.test.ts adds:
    (pass) after a sync that brought changes, reporting each Checkout it wrote
    (pass) after a sync with nothing left to merge
    (pass) says nothing about links that are already current
    (pass) warns about a Checkout it could not refresh and exits zero
    (pass) warns and exits zero when the refresh cannot start                                       # red when the catch rethrows
    
    and the conflict, not-Git and policy-refusal tests now assert no refresh.
  • Real app (verify-mate, acme fixture with a bare upstream): a teammate pushes skill acme-team, then mate companion sync
    before (fce802a5):  mate: synchronized …/acme-companion (updated).            # acme-app and acme-wt lack acme-team
    after:              mate: synchronized …/acme-companion (updated).
                        mate: refreshed Claude skill and command links in …/acme-app.
                        mate: refreshed Claude skill and command links in …/acme-wt.
                        # both link acme-team; acme-wt-noskills still has no .claude/skills; exit 0
    
    A second sync with nothing to merge prints no link lines. After deleting acme-wt's link, a no-change sync restores it.
  • packages/mate-core: bun run test 7020 pass / 0 fail; typecheck and format clean; lint shows only an existing warning in src/runtime/skill-prefix.ts. apps/docs: bun run check 0 errors.
  • Not exercised: mate companion update in the real app (refuses on a prerelease build); a failed refresh, an incomplete sync, command links, an operator's own skill and the other-companion skip are covered by unit tests only.
  • Finish: a5b412f

Merge Danger

Door: two-way

Only symlinks under .claude/skills and .claude/commands are written; the next update or wrap reconciles them again.

Blast Radius: local

mate companion update and mate companion sync now touch every wrapped linked worktree of a linked clone, not only the Registered Checkout. Operator-owned skills are never removed. A checkout served by another companion is left alone.

mate companion update now reconciles Claude skill and command links in every wrapped Checkout of each linked clone, main worktree first, keeping a linked worktree's existing .claude/skills folder current. mate companion sync runs the same refresh after every completed synchronization and reports only written and failed Checkouts.
…efresh

A clone can be linked to two companions ("Keep both"), so the refresh now
skips a checkout whose projection names another companion. Sync loads its
config through readCompanionConfig and filters current results itself;
the skills folder check reuses isDirectory and runs before the costlier
served-by-main check; keepFolder is now keepExistingFolder.

Tests pin the main-worktree-first order and a sync whose refresh cannot
start.
@TornquistK
TornquistK merged commit 8bffd33 into main Dec 2, 2026
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