Repository navigation
Description
Observed
When a project has sequant installed in node_modules at an older version and a newer sequant runs sync, scripts/dev/*.sh never settles. resolveScriptsSymlinkTarget (src/lib/templates.ts) prefers <project>/node_modules/sequant/templates/scripts (#991), so sync rebuilds each symlink pointing at the installed copy. But sync --dry-run and the version-current drift check (sync.ts:821, version-preflight.ts:145) compare that file with the running CLI's bundled template. The dry-run predicts an overwrite that the apply never makes, and every later sync exits 1 with Version current, but 1 file(s) differ from bundled content.
It stayed hidden because templates/scripts/*.sh hadn't changed since 2.16.0. The first PR to change one (#1145, PR #1156) turns the required canary check red. From now on, every change to a script template is blocked from merging until this is fixed.
Repro (run 2026-09-25)
mkdir p && cd p && git init -q && echo '{"name":"p","version":"1.0.0"}' > package.json
npm install [email protected] && node_modules/.bin/sequant init --yes --skip-setup
node <PR-with-a-changed-templates/scripts/new-feature.sh>/dist/bin/cli.js sync
readlink scripts/dev/new-feature.sh # ../../node_modules/sequant/templates/scripts/new-feature.sh (the 2.16 copy)
cmp "$(readlink -f scripts/dev/new-feature.sh)" <PR>/templates/scripts/new-feature.sh # differ
Canary on PR #1156 at f2f9dbf: npx vitest run --project canary → 2 failed | 2 passed (dry-run equals apply predicts scripts/dev/new-feature.sh, and customizations survive… fails on the drift exit 1). The same happens with #1122's branch merged in, so this is not #1122.
Fix direction
Owner decision (2026-09-25): option 1. Keep the #991 targeting (node_modules first). Fix the dry-run and the drift check so they compare a scripts/dev symlink against resolveScriptsSymlinkTarget(), not the running bundle. Options 2 and 3 are rejected: don't change which target sync links to, and don't change only the canary.
Options considered:
- The drift check and the dry-run treat a
scripts/devsymlink that already points atresolveScriptsSymlinkTarget()as current, and compare against that target, not the running bundle. This keeps the fix(templates): scripts/dev symlinks target whichever sequant package ran the command — npx-cache targets get evicted, npm-link targets are machine-specific #991 design. synctargets the running CLI's templates whenever its version differs from the one innode_modules. This partly reverses fix(templates): scripts/dev symlinks target whichever sequant package ran the command — npx-cache targets get evicted, npm-link targets are machine-specific #991.- Change only the canary, so it installs the PR tarball into
node_modulesbeforesync. This hides a real user-facing loop, so it's not recommended alone.
- Tier: judgment
- AC-1: after the repro above, a second
syncexits 0 with nodiffer from bundled contentline — Verify:npx vitest run --project canaryon a branch that changestemplates/scripts/new-feature.sh→ 4 passed - AC-3:
resolveScriptsSymlinkTargetstill prefers<project>/node_modules/sequant/templates/scriptswhen it exists (the fix(templates): scripts/dev symlinks target whichever sequant package ran the command — npx-cache targets get evicted, npm-link targets are machine-specific #991 behaviour is unchanged) — Verify:readlink scripts/dev/new-feature.shafter the repro still points intonode_modules/sequant; asserted in a named test - AC-2:
sync --dry-runlistsscripts/dev/<name>.shonly when the apply changes it — Verify: the canarydry-run equals applycase passes on the same branch
Found by the graph 2026-09-w3 run (docs/internal/graph-2026-09-w3/issue-graph.md). Blocks #1145.
Activity
docs(#1159): graph w3 — #1145 blocked by #1159 not #1122; #1160 filed
admarble commentedon Sep 25, 2026
Runner context (graph 2026-09-w3,
docs/internal/graph-2026-09-w3/issue-graph.md, PR #1154) — these rules apply to the spec, exec AND qa phases:npm test. Verify each AC with its own verify command and run only the named test files. The runner runs the full suite once per PR, serially — three phase agents share this machine and a full-suite call inside a phase can hit the 30-minute no-progress wall.timeout; neverrun_in_background.<!-- SEQUANT_MUTATION: {...} -->marker needsfailedTestto start with the test file path (src/.../x.test.ts > describe > case), or /qa §6i floors it to AC_NOT_MET.[Unreleased]line.admarble commentedon Sep 25, 2026
Runner note on verifying AC-1/AC-2. This branch doesn't change
templates/scripts/new-feature.shitself, so on its own the canary is green before and after. To exercise the bug, mergeorigin/feature/1145-bug-worktree-new-feature-sh-and-sequant-run-derive(PR #1156) into a scratch worktree on top of this branch, build, and runnpx vitest run --project canary. Onmain+ #1156 alone that gives 2 failed | 2 passed, and with this fix it should give 4 passed. Record the result in the PR body. Better still, also add a permanent unit/integration case: a project whosenode_modules/sequant/templates/scripts/x.shdiffers from the bundled one;synctwice; the second exits 0 and the dry-run predicts nothing forscripts/dev/x.sh.admarble commentedon Sep 25, 2026
Complexity: Standard (3 ACs, 1 directory —
src/lib+src/lib/templates.test.ts)AC Quality Check
lintAcceptanceCriteria: 3/3 passed, 0 flagged. All three parse cleanly on one line each.One gap worth fixing at exec time: all three ACs use
Verify:, not the houseEvidence:field, soextractAcceptanceCriteriaresolvesverificationMethod: "manual"for every one of them andAC.evidenceis unset. The verify commands are concrete, so this is cosmetic for a human, but it means no AC declares a test as its evidence — see derived AC-4.Scope Assessment
Non-Goals: not present as a section, but the issue states them as rejected options: don't change which target
synclinks to (option 2), don't change only the canary (option 3). Treat those as binding.src/lib/)Verdict: ✅ SCOPE_OK
Root cause — one site, not two
The issue names
sync.ts:821andversion-preflight.ts:145. Both are message sites; neither compares anything. Every symptom funnels through a single function:computeTemplateChanges(src/lib/templates.ts:614) walks the running CLI's bundled templates, mapstemplates/scripts/x.sh→scripts/dev/x.shviaTEMPLATE_ROUTES(templates.ts:527), thenreadFile(localPath)— which follows the symlink intonode_modules/sequant/templates/scripts/x.sh(the older copy) — and compares it togetTemplateContent(templatePath)from the running bundle. The apply path never writes that file:copyTemplates(templates.ts:1093) relinks it toresolveScriptsSymlinkTarget().scriptsDir, which is the node_modules dir. So the diff reportsmodifiedforever.Four consumers read that count —
sync's version-current fast path (sync.ts:419, setsexitCode = 1),sync --dry-run(sync.ts:476, theModified files:andoverwrite:lines),checkAndWarnSkillsOutdated(sync.ts:756, every command's pre-flight) andgetSkillsInstallStatus(version-preflight.ts:145,serve+sequant://install). One edit fixes all four.previewScriptsSymlinkTargets(templates.ts:929) is already correct — it readsresolveScriptsSymlinkTargetand needs no edit.In the canary (
__tests__/canary/downstream.integration.test.ts)snapshot()stores a symlink aslink:<target>, so the apply leaves the entry identical:predictedcontainsscripts/dev/new-feature.sh,changeddoes not (dry-run equals applyfails), and the secondsyncexits 1 (customizations survive…fails). The fixture installs the previous minor intonode_modulesfor real, so it is the repro.Acceptance Criteria
AC-1: a second
syncexits 0 with nodiffer from bundled contentlineVerification: Integration Test (canary)
Scenario: Given the canary fixture (previous minor in
node_modules) on a branch that changestemplates/scripts/new-feature.sh→ Whennpx vitest run --project canary→ Then 4 passed (today: 2 failed | 2 passed)Assumptions: the canary needs the npm registry +
npm pack; #1156's branch must be merged into a scratch worktree to change a script template.AC-2:
sync --dry-runlistsscripts/dev/<name>.shonly when the apply changes itVerification: Integration Test (canary
dry-run equals apply)Scenario: Given the same fixture → When
sync --dry-runthensync→ Then the non-preserved predicted set equals the set of files whose snapshot entry changed.Assumptions: satisfied by the same edit as AC-1 — both read
computeTemplateChanges.AC-3:
resolveScriptsSymlinkTargetstill prefersnode_modules/sequant/templates/scriptsVerification: Unit Test + manual
readlinkScenario: Given
node_modules/sequant/templates/scriptsexists → Whensync→ Thenreadlink scripts/dev/new-feature.shstill resolves intonode_modules/sequant.Assumptions:
resolveScriptsSymlinkTargetandcopyTemplatesare not edited at all. The existing test attemplates.test.ts:1140already asserts the resolver; the new assertion is that the link on disk is unchanged after the fix.AC-4 (derived): a permanent test reproduces the skew without the registry
Verification: Unit Test
Scenario: Given a temp cwd with
SEQUANT_TEMPLATES_DIRpointing at a bundledscripts/x.shof content A andnode_modules/sequant/templates/scripts/x.shof content B → WhencopyTemplates()thencomputeTemplateChanges("generic")→ Thenscripts/dev/x.shisunchangedand the link points intonode_modules/sequant.Assumptions: use real
process.chdir+SEQUANT_TEMPLATES_DIR, the pattern already in thecomputeTemplateChangesdescribe (templates.test.ts:560). Never spyprocess.cwd— it leaks across forks (#870).AC-5 (derived): a
scripts/devsymlink pointing anywhere else is still reported as driftVerification: Unit Test
Scenario: Given
scripts/dev/x.sh→…/_npx/deadbeef/…/scripts/x.shwhileresolveScriptsSymlinkTarget()resolves tonode_modules/sequant/…→ WhencomputeTemplateChanges("generic")→ Thenscripts/dev/x.shismodified(the apply relinks it).Assumptions: this is the guard against the cheap wrong fix. Blanket-skipping
scripts/dev/in the diff passes AC-1, AC-2 and AC-3 while silently killing stale-link detection — the #1053 npx-cache shape.Implementation Plan
Phase 1: one comparison site
src/lib/templates.ts,computeTemplateChanges: hoistconst scriptsTarget = resolveScriptsSymlinkTarget(getTemplatesDir())above the loop (one call per diff, not per file).localPathstarting withscripts/dev/, resolveexpectedSource = join(scriptsTarget.scriptsDir, basename(localPath))and branch:new;unchangediff its resolved target isexpectedSource, elsemodified(AC-5);--no-symlinks/ copy mode) → compare its bytes againstexpectedSource's bytes, notgetTemplateContent(templatePath).copyDircopies fromsymlinkTarget.scriptsDirin that mode too, so the same rule is correct for both.processTemplateon thescripts/dev/branch — neithersymlinkDirnorcopyDirrenders scripts, so rendering them at diff time is a latent false positive the moment a script template contains a{{TOKEN}}.resolveScriptsSymlinkTarget,copyTemplates,previewScriptsSymlinkTargets,sync.tsorversion-preflight.ts(AC-3, and options 2/3 are rejected).Phase 2: durable tests (AC-4, AC-5)
computeTemplateChangesdescribe insrc/lib/templates.test.ts(unit project, 5s default — keep them filesystem-only, no subprocess): skew-converges, stale-link-still-modified, copy-mode-compares-target.<!-- SEQUANT_MUTATION: {...} -->in the PR body withfailedTeststarting at the file path (src/lib/templates.test.ts > … > …), or /qa §6i floors the AC. Start from a cleangit status --short.Phase 3: canary proof (AC-1, AC-2)
origin/feature/1145-bug-worktree-new-feature-sh-and-sequant-run-derive,npm run build, then a single foregroundtimeout 1500 npx vitest run --project canary. Never background it (Nested phase claude that hangs after its turn is killed at ~106s, taking down the parent sequant run #856 kills the group at ~106s). Record before (2 failed | 2 passed onmain+ fix(#1145): new-feature.sh derives the branch name with the slugify() rule #1156) and after (4 passed) in the PR body.[Unreleased]line.Design Review
computeTemplateChanges, beside the.local/twin check that already special-casesscripts/dev/paths (templates.ts:672). The diff is the single source of truth fix(update/sync): sync reports 'up to date' on content drift; update overwrites in-place customizations (constitution) #708/fix(#708): content-truth for update/sync; protect in-place customizations #710/fix(sync/init/update): one ownership rule for project files — the clobbering class fixed file-by-file in #708/#814/#990/#1042/#1071/#1078 #1090 built; putting the rule anywhere else re-splits the preview from the apply.scripts/dev/branch read the same source the writer reads. Rejected: ascripts/dev/skip-list in the diff (breaks AC-5 / fix(sync): copy-mode sync leaves existing machine-specific scripts/dev symlinks in place, and doctor's hint loops back to sync #1053); declaringscripts/devuser-owned(turns drift intopreserved, which is a different and wrong verb for a sequant-owned tree).previewScriptsSymlinkTargetsalready resolves the same target for the same destination — this brings the content diff onto the resolver the preview has used since fix(sync): never rewrite a user-owned AGENTS.md or write a machine-specific scripts/dev symlink (absorbs #991) #990.--no-symlinksproject with skewednode_moduleshits the identical loop and the canary does not cover it.Conflict Risk Analysis
No in-flight worktree touches
src/lib/templates.ts(#1141 → test files, #1153 →.github/workflows/, #1145 →templates/scripts/new-feature.sh). OnlyCHANGELOG.mdis shared — one[Unreleased]line each, a routine squash conflict. The existingfeature/1159-…worktree sits at104f324e(main with #1122 merged), so #1122 is already in the base.Dependency (outbound): this blocks #1145 / PR #1156 — the canary stays red there until this lands.
Open Questions
--no-symlinksprojects keep the permanentN file(s) differloop with no test covering it, and the next report reads as a regression of this fix.processTemplateon thescripts/dev/branch (step 3)? — Recommendation: yes. Impact if wrong: none today (no script template contains a token); it prevents a future token in a.shfrom re-opening this exact loop.Feature Quality Planning
All standard checks pass. Notable items:
computeTemplateChangesfeedssync,update,doctor,serve's install status and the per-command pre-flight. The change must be inert whenresolveScriptsSymlinkTarget().scriptsDiris the bundled dir — the sequant repo itself has nonode_modules/sequant, so localsyncbehaviour must not move.computeDriftFingerprint/.claude/.sequant/drift cache (sync.ts:156) stats inputs. Confirm the fingerprint covers the symlink target, or a cached count can outlive a relink on thecache: truepre-flight path.readlinkon a project-relative path only.Derived ACs
Recommended Workflow
Phases: exec → qa
Quality Loop: disabled
Reasoning: SCOPE_OK, one function edited, five ACs.
testgenis skipped —buglabel only, and the two test ACs are specific enough that stubs would be churn (/testgenleaves stubs behind). No UI, no security surface, so notestorsecurity-reviewphase. Per the runner note: qa verifies each AC with its own named test files, never the fullnpm test.Label Review
Current:
bugRecommended:
bug(unchanged)Reason: one-function fix with a clear repro; no
complex/refactor/breakingsignal.Quality Loop: won't auto-enable — SCOPE_OK.
admarble commentedon Sep 25, 2026
QA Verdict: AC_NOT_MET
AC coverage: 0/6 met
Gaps:
updatenon-convergence regression above — blocking.classifyScriptsDevChange's closing comment ("A regular file here … is a real write:symlinkDirunlinks it and putsexpectedLinkin its place") is only true underforce.symlinkDir:972-982skips a regular file without it. It happens to be correct for every current consumer becausesync.ts:632hardcodesforce: true, but the comment states an unconditional invariant the callee does not provide — exactly the "comments state intent, not effect" trap, and the coupling is undocumented at thesymlinkDirend.modifiedwith nodifffield, soupdate --dry-run(update.ts:271) prints the path with no diff body for these entries. Minor, and arguably right (there is no content diff to show), but it is an asymmetry with the copy arm.Suggestions:
SCRIPTS_TEMPLATE_PREFIX = "templates/scripts/"duplicates theTEMPLATE_ROUTESentry attemplates.ts:536-540. The JSDoc points at the route, but nothing fails if the two drift. Deriving the prefix from the route entry would make drift impossible.forcecoupling atsymlinkDir's definition, so a future change to its skip-without-force branch surfaces the dependency.fix(#1159): update leaves symlink-mode scripts/dev to sync; stops the…
test(#1159): re-pin the writer matrix — update leaves link-route scri…
admarble commentedon Sep 25, 2026
Runner, after QA round 1: I fixed QA's
updatenon-convergence finding myself inc8c3732aandb3777a63; details in the PR #1161 body under Runner fixes. Checks: fullnpm run build && npm test→ 338 files and 8399 tests passed. Canary on a scratch merge of this branch with #1156 → 4 passed. Real[email protected]probe:updateandsyncboth converge on the second run. qa phase: don't run the full suite; the runner already has.admarble commentedon Sep 25, 2026
Runner, qa phase: the last qa run hit the 30-minute no-progress wall and returned no verdict. For this run: don't run
npm testornpm run build(the runner ran both atb3777a63: 8399 passed, and CI at that SHA showstest,canaryandtypechecksuccess). Don't repeat the real-npm installprobe either (the runner's result is in the PR body). Verify with the named test files only (src/lib/templates.test.ts,src/commands/update.integration.test.ts,src/lib/__tests__/writer-state-matrix.test.ts) and keep every command under ~5 minutes.admarble commentedon Sep 25, 2026
QA Verdict: AC_MET_BUT_NOT_A_PLUS
Gaps:
Suggestions:
SCRIPTS_TEMPLATE_PREFIX = "templates/scripts/"(templates.ts:625) duplicates theTEMPLATE_ROUTESentry attemplates.ts:541-545. The JSDoc points at the route, but nothing fails if the two drift. Deriving the prefix from the route entry would make drift impossible.forcecoupling atsymlinkDir's own definition so a future change to its skip-without-force branch surfaces thesync.ts-side dependency.fix(#1159): update names pending scripts/dev links instead of a silen…
fix(#1159): diff scripts/dev against the install target, not the runn…
docs(#1153): graph 2026-09-w3 plan for #1145, #1153, #1122 and #1141 (#…