Skip to main content

Module reparse

Module reparse 

Source
Expand description

Incremental file reparse — used by mati reparse, edit-hook, and the MCP server socket handler.

Steps:

  1. Read file from disk. Missing → add FileDeleted staleness signal, return.
  2. Detect language, construct WalkedFile, run parse_file().
  3. Parse failure → log warning, return Ok (graceful degradation P9).
  4. Fetch existing file:<path> record.
  5. No record → create Layer 0 stub, persist, return.
  6. Deserialize record.payload as FileRecord, compare structural fields.
  7. Nothing changed → return early (no write).
  8. Merge new analysis, preserve: purpose, gotcha_keys, decision_keys, change_frequency, last_author, is_hotspot.
  9. Apply staleness + cascade to linked gotchas (M-12-C).
  10. Write back.

Not recomputed here: Co-change cluster index. Clusters depend on CoChanges edges which only change when mati init re-mines git history after new commits. Incremental file edits do not affect cluster membership.

Functions§

compute_diff
Compute the structural diff between an old FileRecord and new analysis.
reparse_impl
Re-parse a single file and update its store record in place.
reparse_staged
Compute the reparse result without persisting. Returns the key and updated Record to write, or None if no write is needed (file missing, parse failure, or no structural changes).