Skip to content

fix(sync): areSkillsOutdated/checkAndWarnSkillsOutdated pre-flight is version-only — misses content drift (sibling of #708) #713

Closed

Description

@admarble

Summary

Follow-up from #708 (PR #710). The content-truth fix corrected sync's own up-to-date decision, but the sibling pre-flight warning path other commands rely on is still version-only and will under-report real content drift — the same root cause as #708's Bug 1, just on a different surface.

Where

src/commands/sync.ts:

54  export async function areSkillsOutdated(): Promise<{ outdated; currentVersion; packageVersion }>
63    outdated: currentVersion !== packageVersion,   // <-- version marker only

199 export async function checkAndWarnSkillsOutdated(): Promise<boolean>
200   const { outdated, currentVersion, packageVersion } = await areSkillsOutdated();

checkAndWarnSkillsOutdated is invoked from the preAction hook in bin/cli.ts (runs before most commands) and gates both the "Skills are outdated" warning and the auto-sync trigger. Because areSkillsOutdated compares only the .sequant-version marker against the package version, a tree at the matching version but with drifted content (exactly the #708 scenario) reports outdated: false — so:

  • No "skills outdated" warning is shown to the user before running other commands.
  • The auto-sync hook does not fire (it's gated on outdated && currentVersion !== null).

i.e. the drift that sequant sync now correctly flags is still invisible to every other command's pre-flight path.

Why it was deferred

#708 was explicitly scoped to the update/sync commands' own correctness. The /spec review for #708 flagged this sibling and recommended a separate issue rather than widening that PR. This is that issue.

Acceptance criteria

  • areSkillsOutdated (or a content-aware variant) reflects content drift, not just the version marker — a tree at the matching version but with drifted bundled content is reported as needing attention.
  • The preAction pre-flight in bin/cli.ts warns on content drift at a matching version (consistent with sync's own drift message), instead of staying silent.
  • Decide and document auto-sync behavior on content-only drift: either trigger the (non-destructive) drift report or leave auto-sync to version bumps only — but the warning must surface either way.
  • Reuse computeTemplateChanges (already the source of truth in src/lib/templates.ts) rather than reintroducing a parallel comparison — avoid re-creating the divergence that caused fix(update/sync): sync reports 'up to date' on content drift; update overwrites in-place customizations (constitution) #708.
  • Performance: the pre-flight runs before most commands; ensure content comparison is cheap enough (or gated/cached) not to add noticeable latency to every invocation.

Suggested approach

Have checkAndWarnSkillsOutdated (and/or areSkillsOutdated) call computeTemplateChanges to detect new/modified drift in addition to the version marker. Consider a fast-path: keep the version-marker check as a cheap hint, only run the content diff when versions match (mirrors sync's own structure post-#708), and weigh whether the pre-flight should run the diff on every command or only emit a lighter signal.

Out of scope

Activity

  1. added
    bug
    cli
    on Jun 3, 2026
  2. admarble commented on Jun 4, 2026

    @admarble
    ContributorAuthor

    → PROCEED — Make areSkillsOutdated/checkAndWarnSkillsOutdated pre-flight content-aware (not version-only)

    Workflow: spec → exec → qa (-Q)

    Clear ACs (5). Reuse computeTemplateChanges (per AC) rather than a parallel comparison; mind the per-command pre-flight latency. Touches bin/cli.ts (preAction hook) — coordinate with #709 (also edits bin/cli.ts).

  3. admarble commented on Jun 4, 2026

    @admarble
    ContributorAuthor

    📋 Plan Review (/spec)

    Complexity: Standard — 5 ACs, 2 dirs (src/commands/, bin/) + docs. Scope: ✅ OK.

    ⚠️ Dependency / stacking (read first)

    computeTemplateChanges / buildTemplateVariables (AC-4's "source of truth") were added by #708 / PR #710 (f52d6fe), which is NOT on main — only on the feature branches. So #713 is stacked on #710:

    Acceptance Criteria + verification

    Implementation plan

    1. sync.ts — extend areSkillsOutdated() → { outdated, currentVersion, packageVersion, contentDrift }. Keep currentVersion !== packageVersion as fast-path; only on a version match, load manifest/config.tokens and run computeTemplateChanges, counting new+modified. Mirror syncCommand's post-fix(update/sync): sync reports 'up to date' on content drift; update overwrites in-place customizations (constitution) #708 drift block. Update checkAndWarnSkillsOutdated (currently unused) to surface content drift.
    2. bin/cli.ts preAction — branch: version mismatch → keep syncCommand({quiet:true}) (copy); version match + drift>0 → warn only. Add AC-3 decision as a code comment.
    3. Docs + tests — note in plugin-updates.md; unit on areSkillsOutdated (match→drift true/false, mismatch→skips diff), integration on hook (warns + exit 0 on drift; auto-syncs on version mismatch). Extend src/commands/sync.test.ts.

    Quality flags / derived ACs

    Open questions

    1. fix(#708): content-truth for update/sync; protect in-place customizations #710 merge order — land fix(#708): content-truth for update/sync; protect in-place customizations #710 first then rebase fix(sync): areSkillsOutdated/checkAndWarnSkillsOutdated pre-flight is version-only — misses content drift (sibling of #708) #713 onto main (rec). If wrong: fix(sync): areSkillsOutdated/checkAndWarnSkillsOutdated pre-flight is version-only — misses content drift (sibling of #708) #713 won't compile vs bare main.
    2. Throttle the warning once per session? — rec: no throttle for v1 (matches existing "outdated" warning).

    Recommended workflow

    exec → qa, quality loop enabled (matches /assess). No testgen (bug fix, targeted tests in /exec); no test (no UI). Pre-req: confirm #710 stack/merge order before /exec.

  4. added
    planned
    on Jun 4, 2026
  5. admarble commented on Jun 4, 2026

    @admarble
    ContributorAuthor

    ✅ Implementation Complete (/exec)

    PR: #717 (base main)

    Pre-PR AC Verification

    AC Source Description Status Evidence
    AC-1 Original areSkillsOutdated content-aware ✅ Implemented src/commands/sync.ts — adds contentDrift via computeTemplateChanges on version match; counts new+modified, excludes local-override/unchanged
    AC-2 Original preAction warns on content drift at matching version ✅ Implemented bin/cli.ts hook — warn-only branch; checkAndWarnSkillsOutdated never sets process.exitCode
    AC-3 Original Decide + document auto-sync on content-only drift ✅ Implemented Decision: auto-sync (copy) gated on version bumps only; content drift → warn. Documented in docs/internal/plugin-updates.md + hook comment
    AC-4 Original Reuse computeTemplateChanges ✅ Implemented No parallel diff loop; calls the #708/#710 source of truth
    AC-5 Original Performance ✅ Implemented Diff gated behind version match (mismatch skips it); hook reuses computed status → single scan per command

    Files changed

    • src/commands/sync.ts — SkillsOutdatedStatus interface, content-aware areSkillsOutdated, content-drift warn branch in checkAndWarnSkillsOutdated (+ optional pre-computed status param)
    • bin/cli.ts — preAction hook: version mismatch → copy; version match + drift → warn only
    • src/commands/sync.test.ts — unit tests for drift detection, exclusions, fast-path skip, diff-failure tolerance, warn-only/exit-0
    • docs/internal/plugin-updates.md — "Pre-flight Skill Drift Check" section (AC-3 decision + perf)
    • CHANGELOG.md — [Unreleased] entry

    Checks

    Check Result
    npm run build ✅ Pass
    npm run lint ✅ Pass (0 warnings)
    npm test (sync, doctor, cli.integration) ✅ 65 pass

    Quality Plan Alignment

    Quality Dimension Items Addressed Notes
    Drift exclusions (local-override/unchanged) ✅ High-priority derived AC — customized constitution (#711) won't warn on every command
    No process.exitCode change in pre-flight ✅ High-priority — content-drift warning never fails the user's command
    Performance (gated scan) ✅ /qa to sanity-check; mtime-cache deferrable per spec

    Coverage note

    bin/cli.ts preAction hook is thin glue over the two unit-tested helpers (areSkillsOutdated, checkAndWarnSkillsOutdated); a subprocess hook test would risk mutating the repo's own .claude, so decision logic is covered at the helper level. The warn-only/exit-0 contract (AC-2) is asserted directly on checkAndWarnSkillsOutdated.

    Coordination

  6. added a commit that references this issue on Jun 4, 2026
  7. admarble commented on Jun 4, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #713

    AC Coverage

    AC Source Description Status Notes
    AC-1 Original areSkillsOutdated reflects content drift, not just version marker MET On a version match, runs computeTemplateChanges and counts new+modified into contentDrift; a matching-version tree with drifted content now reports drift. Unit-tested (reports contentDrift on a version match…).
    AC-2 Original preAction warns on content drift at matching version (consistent with sync's drift message) MET Hook warns (warn-only) via checkAndWarnSkillsOutdated; never sets process.exitCode, command exits normally. Fixed during QA: remediation now points at sync --force/update to match syncCommand's own drift message (bare sync is report-only).
    AC-3 Original Decide + document auto-sync behavior on content-only drift MET Decision: auto-sync (copy) gated on version bumps only; content drift → warn-only. Documented in docs/internal/plugin-updates.md ("Pre-flight Skill Drift Check") + hook comment.
    AC-4 Original Reuse computeTemplateChanges (no parallel comparison) MET Single source of truth from #708/#710; no re-implemented diff loop.
    AC-5 Original Pre-flight content comparison cheap enough MET Gated behind version match (mismatch skips the diff); measured ~22.5ms against the 48-template corpus. Hook reuses the computed status → single scan per command. mtime-cache remains a documented follow-up.

    Coverage: 5/5 AC items fully met (0 derived ACs)


    CI Status

    Check State Impact
    build (22.x) SUCCESS (2m22s) ✅ MET
    typecheck SUCCESS ✅ MET
    validate-plugin SUCCESS ✅ MET
    validate-skills SUCCESS ✅ MET

    CI Summary: 4 passed, 0 pending, 0 failed · mergeable=MERGEABLE, state CLEAN


    Quality Metrics

    Metric Value Status
    Type issues (any) 0 OK
    Deleted tests 0 OK
    Files changed 5 OK
    Lines added/deleted +~310 / -~18 OK (mostly tests + docs)
    Local build / lint / tests pass / pass / 65 pass OK

    Code Review

    Strengths:

    • Correct behavior parity: version-mismatch → auto-sync (copy) unchanged; currentVersion === null (manual-managed installs) stays silent as before; new branch only fires on version-match + drift.
    • contentDrift excludes local-override/unchanged, so customized files (constitution, bug(customization): .claude/.local/skills (and likely hooks) never load — documented override layer is non-functional #711) don't warn on every command — verified by unit test.
    • try/catch around the diff guarantees the pre-flight can't break the actual command (returns contentDrift: 0 on failure) — unit-tested.
    • Optional pre-computed status param avoids a double template scan on the hook hot path (AC-5).
    • Clean types (no any/casts); named SkillsOutdatedStatus interface; doctor.ts's .outdated consumer is unaffected by the additive field.

    Issues (found + fixed during QA):

    • Misleading remediation (AC-2 "consistent" qualifier): the warning recommended bare sequant sync, but at a matching version sync is report-only and won't copy — it would have sent users on a two-hop. Fixed to sync --force/update, matching syncCommand's own message. Test + docs updated (commit 8e4b10f).

    Suggestions (non-blocking, optional follow-ups):

    • doctor.ts now pays the ~22ms scan via areSkillsOutdated() but ignores contentDrift — could surface drift in doctor output as a follow-up, or read a lighter signal there.
    • mtime-cache for the per-command scan (already noted as deferrable in the spec) if profiling later shows it matters for tight automation loops.

    Test Coverage Analysis

    Changed File Tier Has Tests?
    src/commands/sync.ts Standard ✅ sync.test.ts (contentDrift detection, exclusions, fast-path skip, diff-failure tolerance, warn-only/exit-0)
    bin/cli.ts (preAction hook) Standard ⚠️ Indirect — thin glue over the two unit-tested helpers; covered by cli.integration + helper units

    Coverage: Core logic fully unit-tested. Hook wiring intentionally not subprocess-tested (would risk mutating the repo's own .claude); decision logic asserted at the helper level.


    Risk Assessment

    • Likely failure mode: A real install at a matching version pays a computeTemplateChanges scan on every command (~22ms here); only noticeable in tight automation loops — gated and spec-acknowledged, mtime-cache deferred.
    • Not tested: The preAction hook end-to-end (decision branches verified via helper unit tests instead).
    • Sibling sites considered: Cross-file — doctor.ts is the only other areSkillsOutdated consumer; it reads .outdated only and is unaffected. No other version-only pre-flight siblings.
    • Sibling-line audit: Intra-file — syncCommand's own drift block was the reference; the QA fix aligned the helper's remediation message to it. syncCommand's report-only behavior left intentionally unchanged (Non-Goal: re-litigating fix(update/sync): sync reports 'up to date' on content drift; update overwrites in-place customizations (constitution) #708).

    Adversarial Re-Read

    Findings: No remaining gaps. Walked the diff against: (1) the issue scenario (matching-version + drifted content → now reported) — covered by unit test; no verbatim code-block fixtures in the issue body to execute; (2) exec evidence is post-fix validation (local build/lint/65 tests + measured perf), not a bug repro; (3) process state clean — fix committed (8e4b10f) and pushed, branch MERGEABLE/CLEAN, 1 commit behind main (#714 merge, within threshold); (4) sibling sites cited above (cross-file doctor.ts, intra-file syncCommand); (5) Non-Goals respected — syncCommand's report-only decision and #709's TTY/--yes ergonomics untouched. The one issue surfaced (misleading remediation) was fixed in-PR.

    Status: Clean


    Verdict: READY_FOR_MERGE

    All 5 ACs MET, CI fully green, PR CLEAN. The one real finding (AC-2 remediation message pointed at the report-only sync instead of sync --force/update) was fixed during QA in commit 8e4b10f, with test and docs aligned. Code quality is A+: correct behavior parity, drift exclusions protect customizations, pre-flight is failure-isolated, and the per-command cost is gated and measured.

    Documentation

    Next Steps

    1. Merge PR fix(#713): make pre-flight skill check content-aware, not version-only #717 (after fix(#708): content-truth for update/sync; protect in-place customizations #710 — already on main).
    2. Coordinate with fix(update): no non-interactive path — crashes without a TTY, add --yes #709 (PR fix(#709): non-interactive update path — add --yes, replace ExitPromptError crash #715) which also edits bin/cli.ts near preAction — merge, don't rebase.
  8. added
    ready-for-review
    on Jun 4, 2026
  9. admarble commented on Jun 4, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #713 (PR #717)

    Verdict: AC_MET_BUT_NOT_A_PLUS — all 5 ACs met, CI green, build clean, 19 new/updated tests passing. Two small, optional polish items keep it just shy of A+.

    AC Coverage

    AC Description Status Notes
    AC-1 areSkillsOutdated reflects content drift, not just version marker MET Adds contentDrift count from computeTemplateChanges, counting new+modified and excluding local-override/unchanged (so #711 customizations don't warn). Tested.
    AC-2 preAction warns on content drift at a matching version MET bin/cli.ts hook calls checkAndWarnSkillsOutdated(status) when contentDrift > 0; warn-only, never sets process.exitCode. Tested.
    AC-3 Decide + document auto-sync behavior on content-only drift MET Decision: auto-sync (copy) gated on version bumps only; content drift is warn-only. Documented in docs/internal/plugin-updates.md, CHANGELOG, and inline comments.
    AC-4 Reuse computeTemplateChanges (single source of truth) MET Uses the same call + filter as syncCommand; no parallel comparison reintroduced.
    AC-5 Performance: pre-flight comparison cheap enough / gated MET (with note) Content diff gated behind a version match (skipped on mismatch). See note below.

    Coverage: 5/5 met.

    CI Status (PR #717)

    Check State
    build (22.x) ✅ pass
    typecheck ✅ pass
    validate-plugin ✅ pass
    validate-skills ✅ pass

    Quality Metrics

    Metric Value
    Files changed 5 (sync.ts, sync.test.ts, bin/cli.ts, CHANGELOG.md, docs)
    Lines +307 / -16
    any casts added 0
    Deleted tests 0
    Build (tsc) ✅ clean
    sync.test.ts + doctor.test.ts ✅ 53 passed

    Code Review

    Strengths

    Issues / polish (non-blocking)

    1. update is not in the hook's skip-list (only init/sync are). On a drifted tree, running sequant update — the remediation command — first prints "…N file(s) differ… Run: sync --force (or update)" and then updates. Mildly circular/noisy. Suggest adding update to the skip set (one line: if (cmd === "init" || cmd === "sync" || cmd === "update") return;).
    2. AC-5 gate doesn't cover the common case. The diff is skipped only on a version mismatch, but an up-to-date install is a version match — so the full ~48-file template scan runs on every command except init/sync (and doctor pays it too). The PR is honest about this and defers an mtime cache. Cost is small (~48 files) and dwarfed by the git/gh work most commands do, so MET — but worth filing the mtime-cache follow-up rather than leaving it only in prose.

    Suggestion (optional): doctor calls areSkillsOutdated but still only reports the version marker — it could now surface contentDrift too, giving users a content-aware health check. Out of scope for this issue.

    Self-Evaluation

    • Verified working: Yes — built (tsc clean), ran the suite (53 passing incl. 19 new), traced the preAction wiring and the computeTemplateChanges reuse end-to-end, and confirmed callers (doctor.ts) remain backward-compatible with the widened return type.
    • Test efficacy: High — tests assert the exact AC behaviors (drift count, exclusion, fast-path, warn-only exitCode), not just "passes".
    • Likely failure mode: Per-command latency from the template scan on large/slow filesystems for up-to-date installs (acknowledged; mtime cache deferred).
    • Verdict confidence: High.

    Verdict: AC_MET_BUT_NOT_A_PLUS

    All five ACs are met with high-quality, well-tested, well-documented code and green CI — this is essentially mergeable. It lands at AC_MET_BUT_NOT_A_PLUS only for the two optional polish items above (skip update in the pre-flight to avoid the circular warning; file the mtime-cache follow-up). Both are cheap; addressing #1 would make it A+.

    Documentation

    Next Steps

    1. (Recommended) Add update to the preAction skip-list to avoid the circular "run update" warning during sequant update.
    2. (Optional) File the mtime-based cache as a follow-up issue so AC-5's deferral is tracked, not just documented.
    3. Otherwise ready to merge — /docs 713 if feature docs are desired (internal docs already updated).
  10. added
    needs-improvement
    on Jun 4, 2026
  11. added a commit that references this issue on Jun 4, 2026
  12. admarble commented on Jun 4, 2026

    @admarble
    ContributorAuthor

    Gap fixes pushed (follow-up to QA)

    Both QA polish items are now fixed in PR #717 (commit 70bdeb6), taking this to A+:

    1. UX gap — update triggered the circular pre-flight warning.
    The preAction hook now excludes update alongside init/sync (bin/cli.ts). update is itself the command that resolves drift, so the warn-only "run sync/update" message was a nag right before it ran.

    2. AC-5 performance — full scan ran on every command for up-to-date installs.
    The existing gate only skipped on a version mismatch, but the common case is a match — so the ~15ms read+render+diff template scan ran on every command. Replaced the prose "mtime cache is a follow-up" note with an actual opt-in stat-only fingerprint cache:

    • SHA-1 over the package version + the mtime (or absence) of every 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. Measured on a real install: 22.8ms → 4.1ms (~5× faster); correctly rescans (15.2ms) when a fingerprinted file's mtime changes.
    • Per-file hash, not max-mtime — editing an older file (whose new mtime may still trail another file's) still changes the fingerprint, so a real drift is never missed. sync/update rewrites bump mtimes, so the cache self-invalidates — no explicit cache-clearing.
    • 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, write failures are swallowed.

    Verification: tsc clean, eslint --max-warnings 0 clean, 23 sync tests (4 new cache tests: hit / mtime-miss / default-uncached / graceful-fallback) + 34 doctor tests green. Docs (docs/internal/plugin-updates.md) + CHANGELOG updated.

    Note: PR #717's branch had been rebased server-side (head 8e4b10f) to exclude the already-merged #714 content; this commit was replayed onto that real head as a clean fast-forward (8e4b10f..70bdeb6), so no #707/#714 content was re-introduced.

    Updated verdict: READY_FOR_MERGE (pending CI green on 70bdeb6).

  13. added a commit that references this issue on Jun 4, 2026
  14. added a commit that references this issue on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugclineeds-improvementplannedready-for-review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions