feat(index): require --replace to overwrite a usable index

Merged
LE
9d ago
+614-32

Prevents vera index from accidentally overwriting an existing usable index unless --replace is passed.

Summary

  • Add --replace to vera index and refuse to overwrite an existing usable index by default, pointing users to vera update for incremental refreshes and --replace for full rebuilds.
  • Check replaceability in vera_core::indexing::usable_index_exists / ensure_replaceable before CLI provider setup (and again under IndexLock in pipeline.rs), recovering any pending .vera.old directory first during preflight so vera update and search prompts continue to work.
  • Keep rebuilds automatic without --replace for stray .vera/ directories, corrupt/missing metadata.db or Tantivy bm25/ state, interrupted updates (index_complete = "0"), old format versions, and retired character-cap chunking configs.
  • Preserve overwrite behavior for --dry-run, vera setup / vera setup --index, and internal callers (vera-mcp, vera-eval), and adjust failed API --replace checkpoint hints to suggest vera index --replace when a usable index still exists on disk.
  • Update docs/ and skills/vera/SKILL.md, and add unit and CLI integration tests.

Verification

  • cargo fmt --all -- --check
  • cargo clippy --locked --workspace --all-targets -- -D warnings
  • cargo test --locked --workspace (1,770 passed, 0 failed, 63 ignored)
  • RUSTDOCFLAGS="-D warnings" cargo doc --locked --workspace --no-deps
  • cargo deny --locked check, cargo machete, cargo audit

Devin Review


Summary by cubic

Makes vera index refuse to overwrite an existing usable index unless --replace is passed, so a working index is no longer destroyed by an accidental rebuild. Use vera update to refresh changed files, or vera index . --replace for a deliberate full rebuild.

Behavior

  • Refuses only when the existing index is complete, current-format, and healthy; stray .vera/ directories, corrupt or missing metadata.db / bm25/ state, interrupted updates, old format versions, and retired chunking configs still rebuild without --replace.
  • Leaves --dry-run, vera setup, and internal callers (vera-mcp, vera-eval) on their previous overwrite behavior.
  • Recovers a pending .vera.old directory during preflight before refusing, so vera update and search prompts continue to work.
  • Failed API builds now suggest vera index --replace in the resume hint when a usable index still exists on disk.
  • Updates docs/ and skills/vera/SKILL.md and adds unit and CLI integration tests.