You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
refactor(sync): fold computeDriftFingerprint's templates→.claude mapping into templateDestination; document the retired-file limitation #1045
Tier: mechanical Found by: QA on #1030 (PR #1042), 2026-09-11 Blocked by:#1030
Why
src/commands/sync.ts (computeDriftFingerprint, ~:130) builds the .claude/<relpath> install path for its stat-only cache key with its own string replacement, independently of templateDestination in src/lib/templates.ts — the function that now owns the templates→.claude mapping and its exclusions (templates/opencode/** → not a copy target, #1030). Harmless today (the cache key only needs to be stable), but it is the same root-cause pattern #1030 fixed: the next exclusion or relocation added to templateDestination silently diverges from the fingerprint.
QA also noted a limitation worth documenting rather than silently carrying: a template file that is retired from the bundle leaves its installed copy in place and invisible to drift detection (the walk is template-driven).
Scope
may touch: src/commands/sync.ts (computeDriftFingerprint), src/lib/templates.ts (export or reuse templateDestination), src/commands/sync.test.ts, docs/reference/ (one paragraph on retired files).
not in scope: any behaviour change to what sync/update write.
Acceptance criteria
AC-1: computeDriftFingerprint derives install paths via templateDestination (or a shared helper) and has no private templates/ → .claude/ replacement — Verify: grep -c 'replace("templates/", ".claude/")' src/commands/sync.ts → 0 (runner amendment 2026-09-11: the original grep also matched an unrelated prefix-strip replace("templates/", "") that is not a mapping); npx vitest run src/commands/sync.test.ts -t "fingerprint" → green, including a case where an excluded template (templates/opencode/**) contributes nothing to the key.
AC-2: the retired-file limitation is documented in one sentence where sync drift detection is described — Verify: grep -rc "retired" docs/reference/*.md ≥ 1.
AC-3: suite green — Verify: npm run build && npm test.
Runner context — launch (2026-09-11). Base: main at ac9afc3 (wave 1 + wave 2 merged). Stop-at-PR: open the PR, do not merge. Gate tests need Mutation-verified: records in the PR body with failedTest as <test file path> > <test name>. Foreground only: run every check in the foreground with a timeout (timeout 600 npm test 2>&1 | tail -80), once — the pre-tool hook blocks Monitor and run_in_background under the orchestrator and nothing will wake you; the phase ends when your turn ends. Commit a WIP within 5 minutes and every ~10 minutes; every phase has a hard 30-minute wall. CHANGELOG.md[Unreleased]: one bullet under the matching existing ### heading.
All 3 AC pass the linter — each has a concrete Verify: clause (grep or command), no vague/unmeasurable/open-ended language, no title/body tension.
Scope Assessment
Non-Goals: Informal — the issue's ## Scope section has a not in scope: bullet ("any behaviour change to what sync/update write") rather than a dedicated ## Non-Goals heading. Sufficient for this size of change; no warning raised.
Metric
Value
Status
Feature count
1
✅
AC items
3
✅
Directory spread
3 (src/commands, src/lib, docs/reference)
✅
Verdict: ✅ SCOPE_OK (skipped as trivial by the assessor: 3 AC, single feature)
Dependencies
Blocked by:#1030 — merged (main is at ac9afc34, the squash of PR #1042 that shipped #1030's templateDestination exclusion). Unblocked, safe to start.
In-flight overlap: worktree feature/1044-... is active in parallel but touches src/lib/workflow/pr-status.ts / state-cleanup.ts only — confirmed via git diff --name-only origin/main...HEAD, no overlap with this issue's files.
Acceptance Criteria
AC-1: computeDriftFingerprint derives install paths via templateDestination, no private templates/→.claude/ replace
Verification: Unit Test Scenario: Given the template tree includes an excluded path (templates/opencode/**) → When computeDriftFingerprint builds its cache-key lines → Then it resolves each install path via the exported templateDestination (not a private .replace("templates/", ".claude/")), and excluded templates contribute zero t:/l:/o: lines to the key (matching the skip computeTemplateChanges already does at templates.ts:356-359). Assumptions:templateDestination stays exported from src/lib/templates.ts (it is, templates.ts:323). sync.test.ts's vi.mock("../lib/templates.js", ...) spreads ...actual, so the real templateDestination runs in tests rather than a stub — no new mock wiring needed for the happy path, only for asserting the excluded-path case.
AC-2: Retired-file limitation documented in one sentence
Verification: Manual Test (doc content), gated by an automated grep Scenario: Given docs/reference/cheat-sheet.md's sync/drift-check description (the "Automation" callout under "When to use which", ~line 43) → When a reader reads it → Then one sentence states that a template file retired from the bundle leaves its previously-installed copy in place, invisible to sync's drift check (the walk is template-driven, not install-driven). Assumptions: cheat-sheet.md is the right home — it's the only doc that currently describes the sync/drift-check use case at all (no dedicated sync.md exists). If a more specific doc is added later this sentence should move with it.
AC-3: Suite green
Verification: Integration Test (build + full suite) Scenario: Given the full repo after the above changes → When npm run build && npm test runs → Then it exits 0. Assumptions: none beyond the current green baseline on main.
Implementation Plan
Phase 1: Fold the mapping into templateDestination
In src/commands/sync.ts, import templateDestination from ../lib/templates.js.
Replace the private mapping at sync.ts:130 (normalized.replace("templates/", ".claude/")) with a call to templateDestination(normalized). When it returns null (excluded: templates/opencode/**, templates/relay/**, templates/mcp.json), continue the loop for that template — don't emit t:/l:/o: lines for it, mirroring computeTemplateChanges's own skip at templates.ts:356-359.
Leave sync.ts:134 (normalized.replace("templates/", ""), used only to build the on-disk template path via join(templatesDir, ...)) untouched — it's unrelated to the install-path mapping and isn't a duplicate of templateDestination. Confirmed by repo-wide grep: sync.ts:130 is the only stray reimplementation of the templates→.claude mapping outside templates.ts itself.
templateDestination can also return a scripts/dev/... path (for templates/scripts/**) which has no .local override concept — guard the existing overridePath = localPath.replace(".claude/", ".claude/.local/") line with localPath.startsWith(".claude/") before computing/checking it, else skip the o: line for that entry.
Phase 2: Tests
Extend the fingerprint describe block in src/commands/sync.test.ts: assert that an excluded template (e.g. templates/opencode/foo.json) contributes nothing to the fingerprint — its mtime changing must not flip the cache result, and getFileStats should not be called for its .claude/-mapped ghost path.
Regression-check the existing 4 fingerprint tests still pass unchanged (they use .claude/skills/... paths, unaffected by the fix).
grep -n 'replace("templates/"' src/commands/sync.ts → should show only the unrelated on-disk-path strip (step 3), not the install-path mapping.
Phase 3: Docs
Add the one-sentence retired-file caveat to docs/reference/cheat-sheet.md.
Phase 4: Verify
npm run build && npm test.
Design Review
Where does this logic belong? Install-path derivation belongs entirely in templates.ts (templateDestination already owns it and its exclusions); sync.ts should be a consumer, not a second source of truth.
Simplest correct approach? Call the existing exported function and skip on null, matching the skip pattern computeTemplateChanges already uses. No new abstraction, no signature changes.
What existing pattern does this follow? The null-skip idiom at templates.ts:356-359.
What would a senior reviewer challenge? "Why does the fingerprint walk excluded/customizable files at all instead of filtering listTemplateFiles itself?" — Because the fingerprint's job is cheap cache-invalidation (path+mtime hashing), not content diffing; walking everything and skipping at the mapping step keeps it consistent with the real write path (computeTemplateChanges) without touching the shared walker other callers rely on.
Feature Quality Planning
All standard checks pass. Notable items:
Cache format is unchanged (still a sha1 hex string) — a stale on-disk drift cache from before this fix mismatches once, forcing one extra rescan, then self-heals. No migration needed.
No new derived ACs.
Open Questions
Should the retired-file caveat get more than one sentence (e.g. its own "Known limitations" subsection)? — Recommendation: one sentence, per AC-2's literal ask. Impact if wrong: cheap to expand into a subsection in a follow-up docs pass if a reviewer wants more.
Recommended Workflow
Phases: exec → qa Quality Loop: disabled Reasoning: Single-file mechanical refactor (per the issue's own Tier: mechanical) of already-tested code — sync.test.ts already has a dedicated fingerprint describe block to extend directly, so testgen stubs would add process overhead without value. Not UI, not security-sensitive, scope is SCOPE_OK/trivial, so no quality loop.
Label Review
Current: enhancement Recommended: no change Reason: Scope is SCOPE_OK and correctly labeled already; no UI/security/complexity signal to add. Quality Loop: Won't auto-enable — scope trivial, single-file fix.
AC-1: computeDriftFingerprint derives install paths via templateDestination, no private templates/→.claude/ replace — Unit Test
AC-2: Retired-file limitation documented in one sentence — Manual/doc, grep-gated
AC-3: Suite green — Integration (build+test)
Implementation: Replace sync.ts:130's private templates/→.claude/ mapping with a call to the already-exported templateDestination (templates.ts:323), skipping (continue) when it returns null for excluded templates (opencode/, relay/, mcp.json) — mirrors the skip computeTemplateChanges already does. Guard the .local override-path check with localPath.startsWith(".claude/") since templateDestination can also return non-.claude/ paths (scripts/dev/...). Leave sync.ts:134 (on-disk template path strip) alone — it's not a duplicate of the mapping. Add a fingerprint test proving an excluded template contributes nothing to the cache key. Add one sentence to docs/reference/cheat-sheet.md on the retired-file blind spot.
Key decisions: No testgen (existing test file covers this function already); no quality loop (trivial scope); docs sentence goes in cheat-sheet.md (only doc describing sync/drift-check today).
Open questions: Whether the retired-file caveat deserves more than one sentence — recommend keeping it to one per AC-2, expandable later if wanted.
AC-1's grep proxy is over-broad relative to its own requirement clause, so the AC's verbatim verify command reads as a failure even though the requirement is met
The two behavior branches introduced beyond the opencode case, including the one that fixes the latent scripts/dev cache-staleness bug, ship untested
Suggestions:
Add one fingerprint case asserting a templates/scripts/x.sh template contributes l:scripts/dev/x.sh and no o: line.
Activity
admarble commentedon Sep 11, 2026
Runner context — launch (2026-09-11). Base:
mainat ac9afc3 (wave 1 + wave 2 merged). Stop-at-PR: open the PR, do not merge. Gate tests needMutation-verified:records in the PR body withfailedTestas<test file path> > <test name>. Foreground only: run every check in the foreground with a timeout (timeout 600 npm test 2>&1 | tail -80), once — the pre-tool hook blocksMonitorandrun_in_backgroundunder the orchestrator and nothing will wake you; the phase ends when your turn ends. Commit a WIP within 5 minutes and every ~10 minutes; every phase has a hard 30-minute wall.CHANGELOG.md[Unreleased]: one bullet under the matching existing###heading.templateDestinationinsrc/lib/templates.tsowns the mapping and itstemplates/opencode/**exclusion; reuse it, do not re-implement. fix(state): reconcile marks an open issue merged when any squash commit title mentions (#N) — isIssueMergedIntoMain's commit-mention fallback confuses PR and issue numbers #1044 runs in parallel onsrc/lib/workflow/pr-status.ts/state-cleanup.ts— no overlap.admarble commentedon Sep 11, 2026
Complexity: Standard (3 ACs, 3 directories)
AC Quality Check
All 3 AC pass the linter — each has a concrete
Verify:clause (grep or command), no vague/unmeasurable/open-ended language, no title/body tension.Scope Assessment
Non-Goals: Informal — the issue's
## Scopesection has anot in scope:bullet ("any behaviour change to what sync/update write") rather than a dedicated## Non-Goalsheading. Sufficient for this size of change; no warning raised.src/commands,src/lib,docs/reference)Verdict: ✅ SCOPE_OK (skipped as trivial by the assessor: 3 AC, single feature)
Dependencies
Blocked by: #1030 — merged (main is at
ac9afc34, the squash of PR #1042 that shipped #1030'stemplateDestinationexclusion). Unblocked, safe to start.In-flight overlap: worktree
feature/1044-...is active in parallel but touchessrc/lib/workflow/pr-status.ts/state-cleanup.tsonly — confirmed viagit diff --name-only origin/main...HEAD, no overlap with this issue's files.Acceptance Criteria
AC-1:
computeDriftFingerprintderives install paths viatemplateDestination, no privatetemplates/→.claude/replaceVerification: Unit Test
Scenario: Given the template tree includes an excluded path (
templates/opencode/**) → WhencomputeDriftFingerprintbuilds its cache-key lines → Then it resolves each install path via the exportedtemplateDestination(not a private.replace("templates/", ".claude/")), and excluded templates contribute zerot:/l:/o:lines to the key (matching the skipcomputeTemplateChangesalready does attemplates.ts:356-359).Assumptions:
templateDestinationstays exported fromsrc/lib/templates.ts(it is,templates.ts:323).sync.test.ts'svi.mock("../lib/templates.js", ...)spreads...actual, so the realtemplateDestinationruns in tests rather than a stub — no new mock wiring needed for the happy path, only for asserting the excluded-path case.AC-2: Retired-file limitation documented in one sentence
Verification: Manual Test (doc content), gated by an automated grep
Scenario: Given
docs/reference/cheat-sheet.md's sync/drift-check description (the "Automation" callout under "When to use which", ~line 43) → When a reader reads it → Then one sentence states that a template file retired from the bundle leaves its previously-installed copy in place, invisible tosync's drift check (the walk is template-driven, not install-driven).Assumptions: cheat-sheet.md is the right home — it's the only doc that currently describes the sync/drift-check use case at all (no dedicated
sync.mdexists). If a more specific doc is added later this sentence should move with it.AC-3: Suite green
Verification: Integration Test (build + full suite)
Scenario: Given the full repo after the above changes → When
npm run build && npm testruns → Then it exits 0.Assumptions: none beyond the current green baseline on
main.Implementation Plan
Phase 1: Fold the mapping into
templateDestinationsrc/commands/sync.ts, importtemplateDestinationfrom../lib/templates.js.sync.ts:130(normalized.replace("templates/", ".claude/")) with a call totemplateDestination(normalized). When it returnsnull(excluded:templates/opencode/**,templates/relay/**,templates/mcp.json),continuethe loop for that template — don't emitt:/l:/o:lines for it, mirroringcomputeTemplateChanges's own skip attemplates.ts:356-359.sync.ts:134(normalized.replace("templates/", ""), used only to build the on-disk template path viajoin(templatesDir, ...)) untouched — it's unrelated to the install-path mapping and isn't a duplicate oftemplateDestination. Confirmed by repo-wide grep:sync.ts:130is the only stray reimplementation of the templates→.claudemapping outsidetemplates.tsitself.templateDestinationcan also return ascripts/dev/...path (fortemplates/scripts/**) which has no.localoverride concept — guard the existingoverridePath = localPath.replace(".claude/", ".claude/.local/")line withlocalPath.startsWith(".claude/")before computing/checking it, else skip theo:line for that entry.Phase 2: Tests
fingerprintdescribe block insrc/commands/sync.test.ts: assert that an excluded template (e.g.templates/opencode/foo.json) contributes nothing to the fingerprint — its mtime changing must not flip the cache result, andgetFileStatsshould not be called for its.claude/-mapped ghost path..claude/skills/...paths, unaffected by the fix).grep -n 'replace("templates/"' src/commands/sync.ts→ should show only the unrelated on-disk-path strip (step 3), not the install-path mapping.Phase 3: Docs
docs/reference/cheat-sheet.md.Phase 4: Verify
npm run build && npm test.Design Review
templates.ts(templateDestinationalready owns it and its exclusions);sync.tsshould be a consumer, not a second source of truth.null, matching the skip patterncomputeTemplateChangesalready uses. No new abstraction, no signature changes.templates.ts:356-359.listTemplateFilesitself?" — Because the fingerprint's job is cheap cache-invalidation (path+mtime hashing), not content diffing; walking everything and skipping at the mapping step keeps it consistent with the real write path (computeTemplateChanges) without touching the shared walker other callers rely on.Feature Quality Planning
All standard checks pass. Notable items:
Open Questions
Recommended Workflow
Phases: exec → qa
Quality Loop: disabled
Reasoning: Single-file mechanical refactor (per the issue's own
Tier: mechanical) of already-tested code —sync.test.tsalready has a dedicatedfingerprintdescribe block to extend directly, so testgen stubs would add process overhead without value. Not UI, not security-sensitive, scope is SCOPE_OK/trivial, so no quality loop.Label Review
Current: enhancement
Recommended: no change
Reason: Scope is SCOPE_OK and correctly labeled already; no UI/security/complexity signal to add.
Quality Loop: Won't auto-enable — scope trivial, single-file fix.
--- DRAFT GITHUB ISSUE COMMENT (PLAN) ---
Plan for #1045
computeDriftFingerprintderives install paths viatemplateDestination, no privatetemplates/→.claude/replace — Unit TestImplementation: Replace
sync.ts:130's privatetemplates/→.claude/mapping with a call to the already-exportedtemplateDestination(templates.ts:323), skipping (continue) when it returnsnullfor excluded templates (opencode/,relay/,mcp.json) — mirrors the skipcomputeTemplateChangesalready does. Guard the.localoverride-path check withlocalPath.startsWith(".claude/")sincetemplateDestinationcan also return non-.claude/paths (scripts/dev/...). Leavesync.ts:134(on-disk template path strip) alone — it's not a duplicate of the mapping. Add a fingerprint test proving an excluded template contributes nothing to the cache key. Add one sentence todocs/reference/cheat-sheet.mdon the retired-file blind spot.Key decisions: No testgen (existing test file covers this function already); no quality loop (trivial scope); docs sentence goes in
cheat-sheet.md(only doc describing sync/drift-check today).Open questions: Whether the retired-file caveat deserves more than one sentence — recommend keeping it to one per AC-2, expandable later if wanted.
Recommended workflow: exec → qa (quality loop disabled).
refactor(sync): fold computeDriftFingerprint's templates path mapping…
admarble commentedon Sep 11, 2026
QA Verdict: AC_MET_BUT_NOT_A_PLUS
AC coverage: 3/9 met
Gaps:
Suggestions:
templates/scripts/x.shtemplate contributesl:scripts/dev/x.shand noo:line.test(#1045): a scripts template contributes one install-path line and…
refactor(sync): fold computeDriftFingerprint's templates→.claude mapp…