Repository navigation
fix(#1122): writers replace a symlink and skip a directory at a template destination - #1157
Merged
admarble merged 4 commits intoSep 25, 2026
Conversation
Entire-Checkpoint: e3388ad901b1
Entire-Checkpoint: d0263fefa401
…ate destination writeFile now unlinks an existing symlink before writing, so init/sync/update no longer overwrite what a link points at (#1053 class, all destinations). Every writer skips a directory at a destination with a named message instead of aborting on EISDIR/EEXIST; computeTemplateChanges reports it as directory-collision so both dry-runs preview it. Re-pins the writer-state matrix and empties KNOWN_DEFECTS. Entire-Checkpoint: d9eef630c0aa
Entire-Checkpoint: ab0ea390843e
admarble
deleted the
feature/1122-fix-writers-update-init-sync-write-through-an-exis
branch
September 25, 2026 12:31
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two writer defects the #1097 writer-state matrix pinned, both at template destinations:
fs.writeFilefollows a symlink, soinit,syncandupdate— with and without--force— left an existing link in place and overwrote what it pointed at: an npx cache, a sibling checkout, a file outside the project entirely. fix(sync): copy-mode sync leaves existing machine-specific scripts/dev symlinks in place, and doctor's hint loops back to sync #1053 fixed one writer (copyDir); the rule now lives insrc/lib/fs.ts:writeFile, which unlinks a symlink before writing, so no call site can reintroduce the class. 24 pinnedWcells atsequant-owneddestinations go toT, plus 8 more atuser-ownedones (constitution,.sequant/settings.json,AGENTS.md) that the invariant never counted.fileExistsusesaccess, which answers true for a directory, so every guard built on it fell into areadFile/writeFilethat threw a rawEISDIR— orEEXISTfromcreateSymlinkon the link route — and abandoned the run partway.computeTemplateChangeshit it first, sosync --dry-runandupdate --dry-runcrashed before printing anything. Each writer now skips the destination and names it:<path> is a directory; move it aside. 32 pinnedXcells go to=.KNOWN_DEFECTSin the matrix is now empty — these were its last two entries.Design notes
fs.writeFileand not a helper at the two call sites. The 24 cells span two unrelated writers (copyTemplates' direct.claude/settings.jsonwrite, outsidecopyDir;update's bare-writeFileapplySet loop), and the class already recurred once after fix(sync): copy-mode sync leaves existing machine-specific scripts/dev symlinks in place, and doctor's hint loops back to sync #1053 fixed it locally. A local fix leaves.sequant/settings.json,AGENTS.mdand the constitution still writing through links. All 36writeFilecall sites inherit the rule; a regular file is still overwritten in place, so nothing changes where no link exists.dry.threw === nullmatchesapply.threw === null, andclassifyreturnsXwhenever a writer threw with a directory before and after — so throwing keeps all 32 cells atXanddirectory-crashes-writercould not be removed. Follows fix(init): --yes init replaces a user-modified AGENTS.md and an unparseable .mcp.json that sync would preserve #1123's precedent (createProjectMcpJsonreturns without writing and reports the file untouched), which is why.mcp.json'sdirectoryrow already read= = = = = =.overwrite:would promise a write that never happens — andprintedDecisionwould read it asoand break theDECISIONSrows.copyDirkeeps its own pre-unlink.writeFilenow guarantees the same thing, but that branch is what stopskeepExistingFilesfrom treating a link as "an existing file" and leaving it in place (the fix(sync): copy-mode sync leaves existing machine-specific scripts/dev symlinks in place, and doctor's hint loops back to sync #1053initcase).violations()now returns only non-zero counts. The old initializer had to name every key in advance, and the one key it missed (user-owned-not-preserved-without-force) incrementedundefinedintoNaNinstead of failing legibly. Required anyway: withKNOWN_DEFECTSempty, a zero-valued key would not match{}.Out of scope
.mcp.jsonwrites throughfs.writeFileSyncdirectly (mcp-config.ts:243,356,471), so itsMcells at symlink states remain write-throughs. It is amergedestination, outside AC-1's literal scope, and no invariant counts it — follow-up issue rather than widening this PR.Pre-PR AC Verification
src/lib/fs.ts:64unlinks before writing;symlink-written-through-at-sequant-ownedremoved fromKNOWN_DEFECTS(writer-state-matrix.test.ts:456);settings/skill/scriptsCopysymlink rows →T,scriptsLink→L L L L T T.classifyreturnsV(notT) if the old target changed, so "target stays byte-identical" is asserted, not assumed.<path> is a directory; move it aside, no partial write, both dry-runs report instead of throwingdirectoryCollisionMessage(src/lib/fs.ts:94) is the single source; guards incomputeTemplateChanges,copyDir,symlinkDir, the direct.claude/settings.jsonwrite,updateGitignoreandcreateDefaultSettings.directory-crashes-writerremoved fromKNOWN_DEFECTS; all 9directoryrows →= = = = = =withDECISIONSunchanged at- - - -.describe("#1122: foreign symlink at .claude/settings.json")— 4 named cases (sync,sync --force,update,update --force) asserting the outside file's bytes survive and the destination ends a regular file with template content.npm run build✅,npm run lint✅ (0 errors, 0 warnings), full suite ✅ — 337 test files, 8393 passed, 1 expected fail, 3 skipped, 0 failures (table under Test results). CItest+canaryboth SUCCESS on this head.SEQUANT_MUTATIONmarker for AC-3,failedTeststarting with the test file pathvalidthroughparseMutationMarkers.Mutation verification
Mutation-verified: AC-1 — restored the bare
fsWriteFileinsrc/lib/fs.ts:writeFile; 32 grid cells failed; restored.Mutation-verified: AC-2 — deleted the
isDirectorydirectory-collision guard incomputeTemplateChanges; thedirectorycells forsettings,skill,constitution,scriptsCopyandscriptsLinkfailed; restored.Mutation-verified: AC-3 — restored the bare
fsWriteFileinsrc/lib/fs.ts:writeFile; all 4 named foreign-symlink cases failed on the foreign file's bytes; restored.Test results
npx vitest run src/lib/__tests__/writer-state-matrix.test.ts— 649 passed (645 grid/decision cells + 4 new named cases), first run, no grid cell re-derived after observation.npm run build✅ ·npm run lint✅ (0 errors, 0 warnings)npm test(full suite, run as 3 foreground shards to stay under the 600s tool cap —npx vitest run --project unit --project integration --shard=N/3):No red tests inside or outside the diff, so there is no "pre-existing failure" claim to settle against base.
CI on this head:
test✅,canary✅,typecheck✅,validate-skills✅,validate-plugin✅,node-floor-guard✅,structural✅,tautology-advisory✅.Test coverage
src/lib/fs.tssrc/lib/fs.test.ts— 10 new cases forwriteFile/isDirectory/directoryCollisionMessagesrc/lib/templates.tswriter-state-matrix.test.ts(all 6 writers × 7 states),src/lib/templates.test.tssrc/commands/sync.tswriter-state-matrix.test.ts,src/commands/sync.test.tssrc/commands/update.tswriter-state-matrix.test.ts,src/commands/update.test.tssrc/commands/init.tswriter-state-matrix.test.ts,src/commands/init.test.tssrc/lib/settings.tswriter-state-matrix.test.ts(sequantSettingsrows)docs/troubleshooting.mdgains an entry under Update Issues for the new skip message, since it is a user-facing string with a prescribed action.src/commands/init.test.tsandsrc/commands/sync.test.tsnow spread the realfs.jsthroughimportOriginalinstead of listing four exports, so an export added tofs.tslater cannot silently break every case in those files (it broke 52 of them here).Closes #1122
(#1124 was folded into #1122 and is already closed; its
directory-crashes-writercells are the 32 fixed here.)🤖 Generated with Claude Code