Skip to content

feat: content hashing with staleness detection and AI spec regen#91

Merged
corvid-agent merged 5 commits intomainfrom
feat/hash-cache-phase1
Mar 31, 2026
Merged

feat: content hashing with staleness detection and AI spec regen#91
corvid-agent merged 5 commits intomainfrom
feat/hash-cache-phase1

Conversation

@corvid-agent
Copy link
Copy Markdown
Collaborator

@corvid-agent corvid-agent commented Mar 31, 2026

Summary

Phase 1 — Content Hashing:

  • SHA-256 content hashing to skip re-validation of unchanged specs — hashes stored in .specsync/hashes.json (gitignored local state)
  • Tracks spec files, companion files (req/context/tasks), and source files from frontmatter files: list
  • --force flag bypasses cache; --strict always re-validates
  • Cache only persisted when validation has zero errors

Phase 2 — Staleness Detection & AI Regen:

  • ChangeKind enum (Spec, Requirements, Companion, Source) classifies what changed per spec instead of just whether anything changed
  • Requirements drift → yellow warnings in check output; interactive TTY prompt to re-validate
  • --fix + requirements changed → auto-regenerates specs via AI (regenerate_spec_with_ai)
  • --strict makes staleness warnings into errors
  • JSON/MCP output includes new "stale" array with {spec, reason, message} entries

Bug fix: Companion file detection now checks both plain names (requirements.md, context.md, tasks.md) and legacy prefixed names ({module}.req.md, etc.)

Closes #90

Test plan

  • 72/72 non-env-dependent tests pass (3 pre-existing AI provider failures unchanged)
  • cargo clippy — clean
  • cargo build — clean compilation
  • 6 new unit tests: change classification, companion discovery, cache updates with plain-named companions
  • Manual: specsync check on repo with changed requirements → staleness warnings
  • Manual: specsync check --fix with AI provider → spec regeneration
  • Manual: JSON output includes stale array

🤖 Generated with Claude Code

corvid-agent and others added 2 commits March 30, 2026 21:56
Add SHA-256 content hashing to skip re-validation of unchanged specs.
Hashes are stored in .specsync/hashes.json (gitignored local state).

- Hash spec files, companion files, and source files listed in frontmatter
- Skip validation when no backing files have changed
- --force flag to bypass cache and re-validate everything
- --strict always re-validates (warnings become errors, different semantics)
- Cache only saved when validation has no errors

Closes #90 (Phase 1)

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Copy link
Copy Markdown
Collaborator Author

@corvid-agent corvid-agent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the full diff. Looks good to merge.

What's good:

  • Inline SHA-256 avoids a new dependency while passing known test vectors (empty string, "hello"). Correct FIPS 180-4.
  • filter_unchanged correctly checks all three layers: spec file, companion files (.req/.context/.tasks), and frontmatter source files. A source code change properly invalidates its spec.
  • Cache only persists on zero errors — prevents caching invalid state.
  • --strict always re-validates (since warning→error semantics change pass/fail), and --force bypasses cache entirely. Both good escape hatches.
  • Coverage computed from ALL spec files, not just validated ones — correct.
  • 8 unit + 4 integration tests cover the key scenarios.

Minor notes (non-blocking):

  • extract_frontmatter_files won't handle inline YAML arrays (files: [a.ts, b.ts]) or quoted strings — fine since specsync uses - item list format, but worth a comment if the format ever expands.
  • The Vec<u8> buffer in Sha256::update works correctly with 8192-byte chunks but implicitly assumes reasonable chunk sizes.

LGTM — ready to merge. Phase 2 (prompt-to-regen on requirements drift) can build on this nicely.


🤖 Agent: CorvidAgent | Model: Opus 4.6

…regen (Phase 2)

Adds ChangeKind enum and classify_changes() to detect what specifically changed
(spec, requirements, companion, source) instead of just whether anything changed.
Reports staleness warnings in check output, supports interactive re-validation
prompting, auto-regenerates specs via AI when --fix is used with requirements
drift, and surfaces stale entries in JSON/MCP output. Fixes companion file
detection to check both plain names (requirements.md) and legacy prefixed names.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@corvid-agent corvid-agent changed the title feat: content hashing for smart change detection feat: content hashing with staleness detection and AI spec regen Mar 31, 2026
corvid-agent and others added 2 commits March 30, 2026 22:51
Cache keys now always use forward slashes regardless of OS, fixing
Windows test failures where backslash paths didn't match cache entries.
Also applies cargo fmt formatting fixes.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@corvid-agent corvid-agent merged commit 8d4cf46 into main Mar 31, 2026
9 checks passed
@corvid-agent corvid-agent deleted the feat/hash-cache-phase1 branch March 31, 2026 06:02
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.

Content hashing for smart change detection and regen prompting

1 participant