Skip to content

fix(#708): content-truth for update/sync; protect in-place customizations - #710

Merged
admarble merged 2 commits into
mainfrom
feature/708-fix-update-sync-sync-reports-up-to-date-on-content
Jun 3, 2026
Merged

admarble merged 2 commits into
mainfrom
feature/708-fix-update-sync-sync-reports-up-to-date-on-content

Conversation

@admarble

@admarble admarble commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes two correctness bugs in the update/sync flow (#708), both stemming from incomplete/divergent template content-comparison:

  • sync false "up to date": it decided status purely from the version marker, so real content drift on the automation-recommended path was reported as a success no-op. It now verifies actual content on a version match and reports drift instead.
  • update overwrote in-place customizations: it compared installed files against the raw (unrendered) template, so an unmodified constitution.md always read as modified, and a user-edited constitution was silently overwritten on the default Apply updates? (Y) prompt.

Root cause fixed by extracting a single source of truth in src/lib/templates.ts — buildTemplateVariables + computeTemplateChanges, now also used by copyTemplates so the write path and the diff path can't drift again.

Key decisions (from /spec)

  • sync is report-only on the equal-version drift path (no auto-apply) so the fast path can't silently clobber an in-place-customized constitution.
  • --force includes local-override files in the apply set (matches AC-4 wording).
  • Customizable allow-list = constitution.md only for now (CUSTOMIZABLE_FILES).

Pre-PR AC Verification

AC Description Status Evidence
AC-1 sync reports drift (not "up to date") when content differs at equal version ✅ sync.ts version-equal branch; sync.test.ts "reports drift…"
AC-2 "already up to date" only when content is identical ✅ sync.ts; sync.test.ts "skips sync when versions match and content is identical"
AC-3 Render tokens before equality check; unmodified constitution reads unchanged ✅ computeTemplateChanges renders via buildTemplateVariables; templates.test.ts AC-3
AC-4 In-place-diverged customizable file → local-override (skip default, --force overwrites) ✅ isCustomizableFile + classification; templates.test.ts AC-4, update.integration.test.ts --force
AC-5 Default Y path never overwrites a customized constitution ✅ update.integration.test.ts "does not overwrite … on the default (Y) path"

Test plan

  • npm run build — passes
  • npm run lint — passes (0 warnings)
  • npx vitest run on sync.test.ts, templates.test.ts, update.integration.test.ts — 32 passed
  • Regression check: init.test.ts, stacks.test.ts, project-name.test.ts, agents-md.test.ts — 192 passed (verifies copyTemplates refactor)

Follow-up (out of scope, per /spec)

checkAndWarnSkillsOutdated / areSkillsOutdated (sync.ts) are also version-only and will under-report content drift to other commands' pre-flight warnings — same root cause. Recommend a separate issue rather than expanding this PR (changing pre-flight warning behavior is outside these ACs).

Closes #708

🤖 Generated with Claude Code

…ions

sync reported "up to date" purely from the version marker, hiding real
content drift on the automation-recommended path. update compared installed
files against the raw (unrendered) template, so an unmodified constitution
always read as "modified" and an in-place-customized constitution was
overwritten on the default Y prompt — silent data loss.

Extract a single source of truth in src/lib/templates.ts
(buildTemplateVariables + computeTemplateChanges, shared with copyTemplates):
- render template tokens before diffing (AC-3)
- classify in-place-diverged customizable files (constitution) as
  local-override: skip-by-default, --force overwrites (AC-4, AC-5)
- sync verifies actual content on version match and reports drift instead
  of a false no-op (AC-1, AC-2)

Add SEQUANT_TEMPLATES_DIR override to getTemplatesDir for hermetic tests.

Entire-Checkpoint: 95e7fd3f430e
…ble-file match

QA second-look gaps:
- sync's drift path returned exit 0 (and was silent under --quiet), so the
  CI/automation path #708 is about could still treat a drifted tree as
  success. Set process.exitCode=1 on drift — fires even under --quiet, since
  the exit code is the machine signal the suppressible message is not. The
  preAction auto-sync hook only runs on version mismatch (copy path), so it
  never hits this branch.
- isCustomizableFile/computeTemplateChanges matched forward-slash paths only;
  on Windows listTemplateFiles yields backslashes, so the constitution
  protection would silently fail and revert to overwrite-on-default. Normalize
  separators before the allow-list and .local/ checks.
- Tests: assert exit code on drift (incl. --quiet), separator normalization,
  and reset process.exitCode in afterEach so it can't leak.

Entire-Checkpoint: 73d0d8a9f37d
@admarble
admarble merged commit f52d6fe into main Jun 3, 2026
4 checks passed
admarble added a commit that referenced this pull request Jun 4, 2026
#717)

* fix(#713): make pre-flight skill check content-aware, not version-only

areSkillsOutdated/checkAndWarnSkillsOutdated (used by the preAction hook in
bin/cli.ts before most commands) compared only the .sequant-version marker, so a
tree at the matching version with drifted bundled content (the #708 scenario)
reported outdated:false — no warning, drift invisible to every other command.

- areSkillsOutdated now returns a contentDrift count: on a version match it runs
  the same computeTemplateChanges diff sync uses (#708/#710 source of truth),
  counting new+modified and excluding local-override/unchanged so customized
  files (#711) don't warn on every command. Version mismatch skips the diff
  (already stale → copy path) to keep the per-command pre-flight cheap (AC-5).
- checkAndWarnSkillsOutdated warns on content drift; warn-only — never copies,
  never sets process.exitCode. Accepts a pre-computed status to avoid a double
  scan on the hook hot path.
- preAction hook: version mismatch → auto-sync (copy) as before; version match +
  drift → warn only. Auto-sync stays gated on version bumps so in-place
  customizations aren't clobbered (AC-3).
- Docs (plugin-updates.md) + CHANGELOG document the decision; unit tests cover
  contentDrift detection, exclusions, fast-path skip, and warn-only/exit-0.

Closes #713

Entire-Checkpoint: d954cbdb7aec

* fix(#713): point content-drift pre-flight warning at the commands that fix it

The pre-flight content-drift warning recommended bare 'sequant sync', but at a
matching version sync is report-only (reports drift and exits non-zero, does not
copy). Point users at the commands that actually resolve in-place drift —
'sync --force' or 'update' — mirroring syncCommand's own drift message and
satisfying AC-2's 'consistent with sync's own drift message'. Drop the 'skill'
qualifier since computeTemplateChanges covers all bundled templates, not just
skills.

Entire-Checkpoint: 38bd202180af

* fix(#713): cache the pre-flight drift scan + skip it on `update`

Address the two QA gaps on the content-drift pre-flight:

1. Performance (AC-5): the full read+render+diff template scan (~15ms) ran on
   every command for up-to-date installs, since the existing gate only skipped
   on a version *mismatch* (the common case is a match). Add an opt-in stat-only
   fingerprint cache: a SHA-1 over the package version plus the mtime/absence of
   each bundled template, its installed counterpart, any `.claude/.local/`
   override, and the config/manifest. On a fingerprint match the cached drift
   count is returned without scanning (~4ms vs ~15ms, measured ~5x faster). A
   per-file hash (not max-mtime) ensures editing an older file still invalidates,
   so a real drift is never missed; `sync`/`update` rewrites bump mtimes so the
   cache self-invalidates. Opt-in via `areSkillsOutdated({ cache: true })` from
   the hot preAction path only — `doctor`/`sync` stay uncached for fresh truth.
   Degrades gracefully: any fingerprint/cache error falls back to a fresh scan.

2. UX: exclude `update` from the preAction pre-flight (alongside `init`/`sync`).
   `update` is itself the command that resolves drift, so the warn-only
   "run sync/update" message was a circular nag right before it ran.

Adds 4 cache tests (hit/miss/default-uncached/graceful-fallback) and updates the
plugin-updates doc + CHANGELOG. Build + lint + 57 sync/doctor tests green.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(update/sync): sync reports 'up to date' on content drift; update overwrites in-place customizations (constitution)

1 participant