Repository navigation
Description
Summary
Dogfooding a manual sequant update in a downstream project surfaced two correctness bugs in the update/sync flow. Both lead a user to a wrong outcome on the default path: either silently miss real drift, or silently overwrite a file they customized in place.
Scope note: the headless/TTY ergonomics of update (crashes without a TTY, no --yes) are out of scope here — these two are the correctness bugs. Filing them together because they share one theme: the manual update flow can't be trusted to do the right thing by default.
Bug 1 — sync reports "up to date" while real content drift exists
sequant sync decides up-to-date status purely from the version marker:
src/commands/sync.ts:106
if (!force && skillsVersion === packageVersion) {
console.log(chalk.green("✔ Skills are already up to date!"));
Version equality ≠ content equality. On a tree where update (which diffs content) found 5 modified + 1 new file, sync printed ✔ Skills are already up to date! and exited a no-op — same 2.6.1 marker on both sides.
This matters because sync is the non-interactive / automation-recommended path (it even prints "Plugin users get auto-updates without running sync manually"). The path we point CI and scripts at is the one that declares success while leaving drift in place. The only escape is sync --force, which is undiscoverable from the "up to date" message.
Acceptance criteria
- When the version marker matches but bundled template content differs from installed content,
syncdoes not claim "up to date" — it reports the drift (e.g.version current, but N files differ — run \update` or `sync --force``) and/or applies it. - Truthful no-op:
synconly prints "already up to date" when content is actually identical.
Bug 2 — In-place customizations (e.g. constitution.md) are classified modified and overwritten on the default Y
Override protection only fires when a separate .claude/.local/<file> exists:
src/commands/update.ts:151-159
// Check if there's a local override
const localOverridePath = localPath.replace(".claude/", ".claude/.local/");
const hasLocalOverride = await fileExists(localOverridePath);
if (hasLocalOverride) {
changes.push({ path: localPath, status: "local-override" });
} else {
... status: "modified"
}
The constitution is the one file explicitly meant to be edited in place per project. A user who customizes it (custom principles/patterns) — without creating a parallel .claude/.local/ file they have no reason to know about — gets it listed under Modified, with Local overrides: 0, and the default Apply updates? (Y/n) overwrites their content. That's silent data loss of intentional customization.
Compounding it, the diff compares against the raw template:
src/commands/update.ts:148
if (localContent === templateContent) { ... unchanged }
But {{PROJECT_NAME}} is only substituted at write time (update.ts:242). So constitution.md shows as modified for every initialized project even with zero user edits (installed # matcha-maps Constitution vs template # {{PROJECT_NAME}} Constitution). This trains users to hit Y on a "modified" constitution as routine — exactly when it might contain real edits.
Repro
sequant initin a project; edit.claude/memory/constitution.mdin place (add a custom principle).sequant update.- Observe constitution under Modified, Local overrides: 0; default
Yreverts custom content to template (+ name substitution).
Acceptance criteria
- In-place divergence of a customizable/templated file (constitution at minimum) is detected as a protected local override — skipped by default, only overwritten with
--force. - Template-vs-installed comparison renders
{{PROJECT_NAME}}(and other tokens) before diffing, so an unmodified constitution reads asunchanged, notmodified. - No silent loss of in-place customizations on the default (non-
--force) path.
Evidence (observed this session)
sequant sync→✔ Skills are already up to date!whilesequant update --dry-runon the same tree reportedNew files: 1 / Modified: 5 / Local overrides: 0.updateModified list included.claude/memory/constitution.md, shown as# matcha-maps Constitution→# {{PROJECT_NAME}} Constitution. Had to restore from git after applying.
Suggested approach
sync: fall back to (or always use) content comparison; treat version marker as a fast-path hint, not the source of truth.update: (a) render template tokens before thelocalContent === templateContentcheck; (b) treat a customizable file diverging in place aslocal-override(skip-by-default), notmodified.
Activity
admarble commentedon Jun 3, 2026
Plan Review vs Acceptance Criteria — #708
Complexity: Standard (5 ACs, 2 directories:
src/commands,src/lib)AC Quality Check
ACs are written as plain
- [ ]checkboxes without explicitAC-N:IDs, so the parser extracted 0 — I've assigned IDs below for traceability. Minor recommendation: add**AC-1:**-style IDs so/execand/qacan track them. One open-ended phrase to pin down:syncshould mutate files on the version-equal path. See Open Questions (recommend report-only).Scope Assessment
Non-Goals: Present and explicit — headless/TTY ergonomics of
update(no-TTY crash, missing--yes) are out of scope. ✅src/commands,src/lib)Verdict: ✅ SCOPE_OK — two bugs, one shared root cause; cohesive.
Acceptance Criteria
AC-1:
syncreports drift instead of false "up to date" when content differs at equal versionVerification: Unit Test (mocked fs, mirrors existing
sync.test.ts)Scenario: Given installed version == package version but ≥1 template renders to different installed content → When
syncCommand()runs without--force→ Then it does not print "already up to date"; it printsversion current, but N file(s) differ — run \update` or `sync --force`` and exits a no-op.AC-2: Truthful no-op — "already up to date" only when content is identical
Verification: Unit Test
Scenario: Given version equal AND every template renders identical to installed content → When
syncCommand()runs → Then it prints "already up to date" and skips copy.AC-3: Render template tokens before the equality check
Verification: Unit Test
Scenario: Given an unmodified installed
constitution.md(# matcha-maps Constitution, expandedSTACK_NOTES) → WhenupdateCommand()computes changes → Then it renders{{PROJECT_NAME}}/{{STACK_NOTES}}(using the same variable set ascopyTemplates:getProjectName()+getStackNotes()) before comparing, and classifies the fileunchanged, notmodified.AC-4: In-place divergence of a customizable file →
local-override(skip-by-default,--forceoverwrites)Verification: Unit Test
Scenario: Given a user-edited
constitution.mdthat diverges after token rendering, with no parallel.claude/.local/file → WhenupdateCommand()runs → Then it is classifiedlocal-override(notmodified), excluded from the default apply set; only--forceincludes it in the apply set.AC-5: No silent loss of in-place customizations on the default path
Verification: Integration Test (real fs in a temp project)
Scenario: Given a customized
constitution.md→ WhenupdateCommand({})runs and the defaultApply updates? (Y)is accepted → Thenconstitution.mdis not overwritten (only--forceoverwrites it).Implementation Plan
Phase 1: Extract a single source of truth for template variables + change detection (
src/lib)buildTemplateVariables(stack, tokens, opts?)insrc/lib/templates.tsreturning exactly whatcopyTemplateswrites with:stackConfig.variables,tokens,PROJECT_NAME(fromgetProjectName()),STACK,STACK_NOTES(fromgetStackNotes()/getMultiStackNotes()). RefactorcopyTemplates(templates.ts:244) to call it so the three call sites can't drift again.computeTemplateChanges(stack, tokens, opts)insrc/libthat iterateslistTemplateFiles(), renders each viaprocessTemplate(raw, vars)before comparing to installed content, and classifiesnew | unchanged | modified | local-override. This is the corrected version ofupdate.ts:133-175.CUSTOMIZABLE_FILESallow-list (.claude/memory/constitution.md) +isCustomizableFile(path). IncomputeTemplateChanges, a file that diverges in place AND is customizable (and has no.localoverride) →local-override.Phase 2: Fix
update(src/commands/update.ts) — AC-3, AC-4, AC-5computeTemplateChanges. Build the apply set as[...new, ...modified]by default and[...new, ...modified, ...localOverrides]only when--force.--dry-runview.Phase 3: Fix
sync(src/commands/sync.ts) — AC-1, AC-2!force && skillsVersion === packageVersionbranch (sync.ts:106), callcomputeTemplateChanges; if anynew/modifiedexist, print the drift message and return (report-only, non-destructive); else print "already up to date".Design Review
src/lib/templates.ts(or a smallsrc/lib/template-diff.ts) — both commands are thin consumers; the comparison + variable rules are library concerns. The bug exists because the rules were duplicated/incomplete inupdateand absent insync.computeTemplateChanges+buildTemplateVariables. Rejected: patchingupdate.tsandsync.tsindependently — re-creates the drift that caused this.copyTemplates's variable assembly (templates.ts:244-250) — we are unifying to that exact set, not inventing one.--forceonupdatenow clobber genuine.local/overrides too?" — yes, by the AC's "only overwritten with--force" wording. Flag in Open Questions. Also: keepsyncreport-only so the equal-version fast path never silently overwrites an in-place-customized constitution (ties Bug 1 and Bug 2 together).Feature Quality Planning
All standard checks pass. Notable items:
checkAndWarnSkillsOutdated(sync.ts:168) →areSkillsOutdatedis also version-only and will under-report content drift to other commands' pre-flight warnings. Same root cause; recommend a follow-up issue rather than expanding this PR.update.ts:242currently usescwdbasename forPROJECT_NAMEand omitsSTACK_NOTESentirely — both must move tobuildTemplateVariablesor AC-3 only partially fixes the "always modified" symptom.Open Questions
syncapply or only report on the equal-version drift path (AC-1 "and/or")? — Recommendation: report-only. Auto-applying would reintroduce constitution data-loss (Bug 2) on the "safe" fast path. Impact if wrong: minor message-vs-mutation change, cheap to revisit.--forceoverwriting genuine.claude/.local/overrides? — Recommendation: under--force, includelocal-overridein the apply set (matches AC-4 wording). Impact: a forced update also refreshes parallel.localfiles; acceptable since--force= "take the template".constitution.mdonly for now; expand later if other in-place-edited templates appear.Recommended Workflow
Phases: spec → testgen → exec → qa
Quality Loop: enabled
Reasoning: ACs are Unit/Integration-verifiable (testgen stubs first). Data-loss-class correctness bug → enable the quality loop despite SCOPE_OK. No UI → no
testphase.Label Review
Current:
bug,cliRecommended:
bug,cli(+plannedon this comment)Reason: Accurate as-is; no UI/security/breaking surface.
Quality Loop: Manually enabled (data-loss risk), not auto-enabled (scope is green).
--- DRAFT GITHUB ISSUE COMMENT (PLAN) ---
Plan (spec): Both bugs share one root cause — divergent/incomplete template content-comparison. Fix by extracting a single
buildTemplateVariables+computeTemplateChangesinsrc/lib(matchingcopyTemplates), then makingupdateandsyncthin consumers.syncreports drift (not "up to date") when content differs at equal version — Unit{{PROJECT_NAME}}/{{STACK_NOTES}}(same vars ascopyTemplates) before the equality check; unmodified constitution readsunchanged— Unitlocal-override(skip by default,--forceoverwrites) — UnitYpath never overwrites a customized constitution — IntegrationKey decisions:
syncis report-only on the equal-version path (no auto-apply) so the fast path can't silently clobber an in-place-customized constitution.--forceincludeslocal-overridefiles in the apply set.Open questions: (1)
syncreport-only vs apply → recommend report-only; (2)--forceoverwriting.local/overrides → recommend yes; (3) customizable allow-list = constitution only for now.Follow-up (sibling):
checkAndWarnSkillsOutdated/areSkillsOutdated(sync.ts:168) is also version-only — same root cause, recommend a separate issue.Workflow: spec → testgen → exec → qa, quality loop on (data-loss-class bug).
admarble commentedon Jun 3, 2026
Implementation Update (exec) — PR #710
Both bugs share one root cause (incomplete/divergent template content-comparison), fixed by extracting a single source of truth in
src/lib/templates.ts:buildTemplateVariables+computeTemplateChanges, now also used bycopyTemplatesso the write and diff paths can't drift again.AC Coverage
syncreports drift instead of false "up to date" at equal version{{PROJECT_NAME}}/{{STACK_NOTES}}(same vars ascopyTemplates) before equality checklocal-override(skip default,--forceoverwrites)Ypath never overwrites a customized constitutionKey files changed
src/lib/templates.ts—buildTemplateVariables,computeTemplateChanges,CUSTOMIZABLE_FILES/isCustomizableFile,SEQUANT_TEMPLATES_DIRoverride;copyTemplatesrefactored to share variables.src/commands/update.ts— replace inline diff loop withcomputeTemplateChanges; default apply set excludeslocal-override,--forceincludes it; writes pre-rendered content.src/commands/sync.ts— version-equal branch now content-verifies and reports drift (report-only).templates.test.ts,sync.test.ts, newupdate.integration.test.ts.Quality Plan Alignment
.local/skip + customizable allow-list preserve in-place editscopyTemplatesconsumerssyncreport-only (non-destructive fast path)Derived ACs: None in spec comment.
Checks
npm run build✅ ·npm run lint✅ (0 warnings) · targeted vitest: 32 passed; regression set: 192 passed.Open questions resolved (per /spec recommendations)
syncequal-version path → report-only (no auto-apply).--force→ includeslocal-overridefiles in apply set.constitution.mdonly for now.Follow-up (out of scope)
checkAndWarnSkillsOutdated/areSkillsOutdatedare also version-only (same root cause) — recommend a separate issue rather than expanding this PR.admarble commentedon Jun 3, 2026
QA Review for Issue #708 — PR #710
AC Coverage
syncreports drift instead of false "up to date" at equal versionVersion current, but N file(s) differ — run \update` or `sync --force`` (verbatim match to AC); report-only, no mutation. Unit test confirms.drifted.length === 0(new+modified). Unit test "skips sync when versions match and content is identical".{{PROJECT_NAME}}/{{STACK_NOTES}}(same vars ascopyTemplates) before equality checkbuildTemplateVariablesis now the single source shared bycopyTemplates+computeTemplateChanges; tokens rendered before diff. Hermetic test: unmodified constitution →unchanged.local-override(skip default,--forceoverwrites)CUSTOMIZABLE_FILES/isCustomizableFileallow-list; default apply set excludes overrides,--forceincludes them. Hermetic test confirms classification.Ypath never overwrites a customized constitutionupdateCommand({})leaves custom content intact;{force:true}overwrites.Coverage: 5/5 AC items fully met. Derived ACs: None in spec.
CI Status
CI Summary: 4 passed, 0 pending, 0 failed.
Quality Metrics
any)Test Coverage Analysis
src/lib/templates.tstemplates.test.ts(AC-3/AC-4 hermetic)src/commands/sync.tssync.test.ts(AC-1/AC-2)src/commands/update.tsupdate.integration.test.ts(AC-5 real-fs)Coverage: 3/3 changed source files have tests. Targeted suite: 32 passed.
npm run build: ✅. No critical paths untested.Code Review
Strengths:
buildTemplateVariablesis now the only place template variables are assembled, consumed by both the write path (copyTemplates) and the diff path (computeTemplateChanges) — eliminating the duplicate/incomplete variable logic that caused the bug.syncfast path is report-only (non-destructive), correctly avoiding reintroducing Bug 2 on the "safe" path.listTemplateFileswalk is wrapped in try/catch, so the new fs I/O onsync's version-equal fast path cannot crash on a missing templates dir (falls back to "up to date").Issues: None blocking.
Suggestions (non-blocking):
updatepath, protected local overrides are communicated only via theLocal overrides: Nsummary count, not listed by name (per-file listing appears only under--force). Minor discoverability nit.constitution.mdusesSTACK_NOTES, and it's in the customizable allow-list, so the fact thatupdate/syncdon't threadadditionalStacksis benign (no false "modified" elsewhere, no data loss). No action needed.Test Quality Review
--forcepaths.SEQUANT_TEMPLATES_DIR.Call-Site Review
New exported functions:
buildTemplateVariables,computeTemplateChanges,isCustomizableFile(+CUSTOMIZABLE_FILES,TemplateChange).computeTemplateChanges!force && version match), update.ts:121buildTemplateVariablescopyTemplates,computeTemplateChanges)isCustomizableFilecomputeTemplateChanges)All call sites match AC constraints. No dead exports.
Execution Evidence
vitest run sync.test update.integration.test templates.testnpm run buildscripts/not modified → standalone/verifynot required. The real-fs integration test exercisesupdateCommandend-to-end against the actual data-loss path. Evidence status: Complete.CHANGELOG Verification
Self-Evaluation
STACK_NOTESwhileupdate/syncstill don't threadadditionalStacks→ that file would read asmodifiedfor multi-stack projects. Not a current bug (only constitution uses it, and it's protected).Verdict: READY_FOR_MERGE
All 5 ACs MET (AC-1 message is a verbatim match), CI green (4/4), no
any/deleted tests, root-cause fix with strong unit + real-fs integration coverage. The two non-blocking suggestions above are optional polish.Recommended follow-up (out of scope, per /spec):
checkAndWarnSkillsOutdated/areSkillsOutdated(sync.ts:194) are still version-only and will under-report content drift in other commands' pre-flight warnings — same root cause. File as a separate issue.Documentation
Next Steps
areSkillsOutdatedcontent-truth follow-up.fix(#708): exit non-zero on sync drift; normalize paths for customiza…
admarble commentedon Jun 3, 2026
QA Gap Fixes (commit
b01823a)Second-look adversarial review surfaced gaps where the ACs were literally met but the issue's intent wasn't fully addressed. Fixed:
1.
syncautomation path could still pass silently on drift.The drift branch returned exit 0, and under
--quietprinted nothing — so CI/scripts (the path Bug 1 is explicitly about) could still treat a drifted tree as success. Now setsprocess.exitCode = 1on drift, which fires even under--quiet(the exit code is the machine signal the suppressible message is not). Still report-only / non-destructive. ThepreActionauto-sync hook only runs on version mismatch (copy path), so it never hits this branch and is unaffected.2. Constitution protection was POSIX-only (Windows data-loss risk).
isCustomizableFile/computeTemplateChangesmatched forward-slash paths, butlistTemplateFilesbuilds paths with the OS separator — on Windows the allow-list match would miss and the constitution would revert tomodified→ overwritten on the defaultY, reintroducing the AC-4/AC-5 data loss. Now normalizes separators before the allow-list and.local/checks.3. Test coverage for the above.
sync: assert exit code 1 on drift, plus a--quietdrift case (suppressed message, still exit 1).templates: separator-normalization case forisCustomizableFile.afterEachresetsprocess.exitCodeso it can't leak across tests/into vitest.Verification:
npm run build✅ ·npm run lint✅ (0 warnings) · full unit suite 2759 passed (1 expected-fail, 2 skipped) · targeted suite 34 passed · CI 4/4 green.Verdict unchanged: READY_FOR_MERGE.
fix(#708): content-truth for update/sync; protect in-place customizat…
fix(#713): make pre-flight skill check content-aware, not version-only (
fix: align template diff destinations with the copyTemplates write path
fix(#708): content-truth for update/sync; protect in-place customizat…
fix(#708): exit non-zero on sync drift; normalize paths for customiza…
fix(#1030): the version-current fast path reports a stale opencode sh…
fix(sync): exclude templates/opencode from the generic diff/copy engi…