Repository navigation
Conversation
…tings through it Entire-Checkpoint: 0907cea0c707
Entire-Checkpoint: 0b64290310cc
…pply parity Entire-Checkpoint: ef3c94c1dc55
…nt/settings.json Entire-Checkpoint: 072f6425aa17
… refactor Entire-Checkpoint: 4bcca7169b83
Entire-Checkpoint: 8657303470fa
…has no fs side effect settings.ts -> templates.ts -> manifest.ts made every suite that stubs fs and imports settings.js throw at import time (CI build (22.x) red on worktree-isolation.test.ts). Memoize the read behind getPackageVersion() instead of running it at module scope. Entire-Checkpoint: 30050aeb21c1
…CUSTOMIZABLE_FILES symbol templates/memory/constitution.md ships to every project; keep it byte-identical to its memory/ twin. README's constitution section reworded the same way. Entire-Checkpoint: 2edb1476e042
…port a parity check The decisions block and the post-copy #814 report were fed by two different sources and both printed. The decisions line now carries the repair hint; what remains after the copy fires only when copyTemplates preserved a file the diff pass did not predict — the #722 divergence, which is worth a loud line. Test parser scoped to the decisions block so sync's other preserved: lines cannot leak into the parity set. Entire-Checkpoint: 377a23651d63
… decided policy value The gate mapped writeOpencodeMcpConfig to the .opencode/ prefix, so the exact merge rule describing the one file under that tree sequant merges was declared but never asserted — the same shape as the class this issue ends. Map the site to the exact path, declare it, and assert the policy VALUE for each decided destination; POLICIES.toContain passes for all three values and would let a silent re-classification ship. Entire-Checkpoint: fcf2dff887a6
… and the lazy version read Also records the apply-path diff cost at the call site: the pass only runs when force is set or the version marker mismatches, measured ~36 ms against 63 templates on a run that renders and writes the whole tree. Entire-Checkpoint: 0541015c854d
admarble
deleted the
feature/1090-fix-sync-init-update-one-ownership-rule-for-projec
branch
September 20, 2026 02:30
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
One declared ownership policy per destination, consulted by every writer.
ownershipPolicy(destinationPath)insrc/lib/templates.tsreturnssequant-owned | user-owned | mergeand is the only sourceinit,syncandupdateconsult.CUSTOMIZABLE_FILES/isCustomizableFileare gone.templateDestinationnow reads a declaredTEMPLATE_ROUTEStable instead of a chain of hardcoded prefix tests, so the diff-path and write-path routers whose drift caused fix(update/sync): sync reports 'up to date' on content drift; update overwrites in-place customizations (constitution) #708 and fix(sync): dry-run lists files apply never writes — the template walk maps templates/opencode/** to .claude/opencode/** (phantom drift nag in serve; update plants unrendered {{PHASE}} files) #1030 share one declaration.sync --dry-runprints the policy decision per file (overwrite/preserved/merged) andsyncapplies exactly that set — the update: --dry-run reports "0 modified" but apply rewrites every SKILL.md (dry-run vs apply divergence) #722 parity contract restated in policy terms.templates/.Pre-PR AC Verification
ownershipPolicy(), sole source for init/sync/update0(baseline 9).src/lib/templates.ts:239-395Tests 2 passed.src/lib/templates.test.ts:186-330.sequant/settings.jsondeclareduser-owned; init guard reads the policygrep -c ownershipPolicy src/lib/settings.ts→2;-t "1071"→Tests 14 passed.claude/settings.jsonsequant-owned,settings.local.jsonnamed; dry-run printsoverwritegrep settings.local.json→2; AC-5 parity case assertspreview.overwritecontains the pathoverwrite+mergednpx vitest run src/commands -t "1090"→Tests 4 passedownershipPolicynormalizes\→/; gate asserts itupdate --forcereports the same protected setnpx vitest run src/commands/update*.test.ts -t "1090"→Tests 2 passednpm run build && npm testgreennpm run build✅,npm run lint✅,npm test6522 passed / 3 failed, all three the knownSEQUANT_*env leak (#1086) — see the test plan.Test plan
npm run buildnpm run lint--max-warnings 0)npx vitest run src/lib/templates.test.tsnpx vitest run src/commands/sync.test.tsnpx vitest run src/commands/init.test.tsnpx vitest run src/commands/update.test.ts src/commands/update.integration.test.tsnpx vitest run src/lib/settings.*.test.ts src/lib/agents-md.test.ts src/commands/init.codex.integration.test.tsnpx vitest run src/commands/doctor.test.ts src/commands/ready.test.ts src/commands/run-preflight-exit.test.ts src/lib/workflow/ready-gate-run.test.ts src/commands/ready.phase-policy.test.tsnpm testnpx vitest run src/lib/worktree-isolation.test.ts src/commands/doctor.test.ts src/lib/workflow/log-rotation.test.ts src/lib/workflow/token-utils.test.tsEnd-to-end smoke (real filesystem, not mocks)
A scratch project was
init-ed from this branch, its constitution hand-edited and itsexecSKILL.md locally tweaked — the exact AC-5 fixture.sync --dry-runprinted:syncthen printed the identical block, and after it ran the constitution's sha1 was byte-identical (118e7688…before and after, hand-edit intact) while the skill's local tweak was gone. Under--forceboth files moved tooverwrite.Mutation verification (AC-2 gate test)
Both sides mutated from a committed, clean tree (
git status --short→ 0 lines), restored to clean after each.Mutation-verified: AC-2 — added
templates/stray-gate-probe.md, a file undertemplates/with no entry inTEMPLATE_ROUTES; src/lib/templates.test.ts > templates > ownership policy covers every destination sequant writes > ownership policy covers every bundled template (side a) failed; restored.Mutation-verified: AC-2 — removed the
.codex/config.tomlentry fromNON_TEMPLATE_DESTINATIONS; src/lib/templates.test.ts > templates > ownership policy covers every destination sequant writes > ownership policy covers every non-template destination (side b) failed; restored.Failure messages named the path in both cases:
undeclared template route(s) — add them to TEMPLATE_ROUTES in src/lib/templates.ts: templates/stray-gate-probe.mdinit.ts#writeCodexConfig writes .codex/config.toml, which is not in NON_TEMPLATE_DESTINATIONSThird probe — the recurrence path itself. Beyond the two the AC requires, a brand-new undeclared writer (
async function writeProbeArtifact()insync.ts, writing.project-owned-file) was added and side (b) failed withunregistered writeFile site(s) … sync.ts#writeProbeArtifact (line 174). That is the case that has reopened this class four times out of six, so it is the one worth knowing the gate catches. Restored to clean.Notes for review
.gitignoreis declaredmerge, notsequant-owned—initappends its.sequant/entries only when absent and never rewrites existing lines. It is not one of the six defects, but it is awriteFiletarget ininit.tsand therefore has to be declared.init.test.tsstubbed../lib/templates.jswith a bare factory, socreateDefaultSettingsreadingownershipPolicythrew; it now usesimportOriginaland deliberately leavesownershipPolicyreal — a stub would make the bug(init): init --agent <name> on an initialized repo overwrites .sequant/settings.json with defaults #1071 preservation cases assert against the stub rather than the declared table.sync.test.tsneededPROJECT_MCP_JSONon itsmcp-configmock and a default[]forcomputeTemplateChanges.--quiet, where neither the decision report nor the--forceannouncement is printed.copyTemplatesmock models the write path's own guard (ownershipPolicy(path) === "user-owned" && !overwriteCustomizable) and the applied set is derived from that, not from sync's printer.templateDestinationkeeps its.claude/<relpath>fallback for unrouted paths, so behaviour is unchanged for everything already shipping; the gate is what forces a new tree onto the table before it can reach a release.Second round — the five QA findings on this PR
1. Blocking: the import-time regression (CI
build (22.x)red) — fixedsettings.ts→templates.ts→manifest.ts, whose top level ranconst pkg = JSON.parse(findPackageJson()). Every suite that stubsfsand then importssettings.jsthrew at import. CI named it exactly:src/lib/worktree-isolation.test.ts > settings integration > isolateParallel defaults to false,Error: Could not find sequant package.json.Fixed at the root, not the symptom: the read is lazy and memoized behind
getPackageVersion(), and the two internalPACKAGE_VERSIONuses now call it. No module-levelfsside effect remains — the class that broke ESM import order in #734.Causally verified, not assumed. With only
manifest.tsreverted to the module-scope read, that exact test fails atsrc/lib/manifest.ts:34:24←src/lib/templates.ts:20:1; with the fix in place the four affected suites are 131 passed.2. Shipped docs named a deleted symbol — fixed
templates/memory/constitution.md:131(ships to every project), itsmemory/constitution.mdtwin andREADME.md:225all saidCUSTOMIZABLE_FILES. All three now name the policy (user-owned). The two constitution copies are byte-identical (diffclean). The remaining hits in the repo are historical by design: pastCHANGELOGentries describing the old mechanism,docs/internal/lab notes, a__tests__/fixtures/transcript, and one comment inupdate.test.tsthat explains what the characterization case maps from.3. Apply-path cost — evaluated, measured, not changed
The finding's premise does not hold in this tree: there is one
computeTemplateChangespass on the apply path (sync.ts), and the--forceannouncement already reuses its result rather than computing a second. The four call sites insync.tsare on mutually exclusive paths — the pre-flight helpercomputeContentDrift, the version fast path (returns), the dry-run path (returns), and the apply path.What is real is the remaining single pass on a non-
forceapply, whichmaindid not run. It cannot be removed without giving up AC-5's apply-side report, and printing after the copy instead would break the invariant the report exists for (#1030 I-2: the decision must be visible before the write). So I measured it rather than argue it:computeTemplateChangesover the 63 bundled templates: 35.8 ms, yielding 57 changes.forceis set or the version marker mismatches. A version-current plainsyncreturns at the report-only fast path above it, which runs its own diff and never gets there.So the added pass lands only on runs that then render and write the entire tree — ~36 ms against that. The analysis is recorded as a comment at the call site so the next reader does not re-derive it. Happy to reopen if the measurement is the part you disagree with.
4. Duplicate
preserved:output — fixed, and turned into a parity checkThe decision line now carries the
— runsync --forceto replacehint that #814's separate post-copy loop used to add, so a preserved file is announced exactly once. What remains after the copy is the check the decision block cannot make for itself: the decisions come from the diff pass,preservedCustomizablecomes from the write path that actually ran, so a file the writer preserved but the preview never predicted is precisely the #722 divergence — now reported loudly instead of printed as a silent duplicate.The AC-5 parity test's stdout parser is scoped to the
File ownership decisions:block rather than grepping whole stdout. That was not cosmetic: unscoped, it silently folded the #990preserved: AGENTS.mdline — printed outside the block — into the decision set, which is the failure mode the repo's gate-test rule warns about.Mutation-verified: AC-5 print-once — removed the
if (announced.has(file)) continue;guard insync.tsso the post-copy loop prints every preserved file again; src/commands/sync.test.ts > sync command > ownership decision parity between --dry-run and apply (#1090) > prints a policy decision per file and applies exactly that set (#1090 AC-5) failed (expected [ …(2) ] to have a length of 1 but got 2); restored.5. The
.opencode/opencode.jsonmergerule — now enforcedThe rule is real:
writeOpencodeMcpConfigreads the existing config, merges in onlymcp.sequant, and keeps every other entry. It was the gate that was weak — the write site was mapped to the.opencode/prefix, so side (b) asserted the tree'ssequant-ownedrule and never touched the exactmergerule. A declared policy nothing enforces is the class this issue exists to end, so:init.ts#writeOpencodeMcpConfignow maps to.opencode/opencode.json, and that exact path is declared inNON_TEMPLATE_DESTINATIONSalongside the prefix.constitution.md/settings.json/AGENTS.md→user-owned,.mcp.json/.opencode/opencode.json→merge,.claude/settings.json→sequant-owned). The existingPOLICIES.toContain(...)check passes for all three values, so it would have let a silent re-classification ship.Mutation-verified: AC-2 — flipped
.opencode/opencode.json's policy frommergetosequant-ownedinOWNERSHIP_RULES; src/lib/templates.test.ts > templates > ownership policy covers every destination sequant writes > ownership policy covers every non-template destination (side b) failed (.opencode/opencode.json is declared merge; changing it reopens the defect it closed: expected 'sequant-owned' to be 'merge'); restored.Full suite (AC-8)
npm test→ 6522 passed, 3 failed, 1 expected-fail, 3 skipped across 322 files.The three failures are
src/commands/__tests__/prompt-wait.test.ts,src/lib/workflow/batch-executor.test.tsand__tests__/integration/relay-hook.integration.test.ts— the knownSEQUANT_*environment leak (#1086) from running the suite inside asequant runphase. Verified as such rather than assumed: re-running exactly those three files withSEQUANT_ORCHESTRATOR/PHASE/ISSUE/WORKTREE/RELAY/ISOLATE_PARALLELstripped gives 3 files, 106 tests, all passed. None of the three touchestemplates.ts,sync.ts,init.ts,settings.tsormanifest.ts. CI does not set those variables.Still open, by the runner's own note
Side-(b) granularity — per-write-site destinations rather than per-enclosing-function, non-awaited
writeFile(, arrow-const writers — is deferred to a follow-up.merged: .mcp.jsonprints aftersyncSequantMcpPinhas already written on the apply path; noted as accepted.Closes #1090
🤖 Generated with Claude Code
Full suite — runner result (2026-09-19,
ef43f6fd)Run once in this worktree, foreground, from a shell with no
SEQUANT_*variables:Test Files 322 passed (322),Tests 6525 passed | 1 expected fail | 3 skipped, 348s, exit 0. The four fs-stubbing files that crashed at import on the first pass (doctor.test.ts,worktree-isolation.test.ts,token-utils.test.ts,log-rotation.test.ts) pass 131/131 after the lazygetPackageVersion().