C0::Diff
C0DIFF parser and applier for atomic multi-file edits.
Format: [FS]<filepath>[GS]<literal>[US]<old>[SUB]<new>[US]<literal>
- FS starts a new file block
- GS starts a new pattern section within a file
- US separates pattern units (anchor text ↔ replacement regions)
- SUB separates old text from new text within a replacement
- DLE escapes literal control codes
TODO: Consider a "replace-all within bounded scope" mode. Two unique sentinel anchors would define a region, and all occurrences within that region would be replaced. Candidate codes: SO/SI (0x0E/0x0F) — "Shift Out/In" to switch into replace-all mode: [GS]<start anchor>[SO]<old>[SUB]<new>[SI]<end anchor> Open questions:
- Is this too liberal? Should there be a max replacement count?
- Or is it better to generate one section per occurrence at a higher tool level, keeping the format strictly exact-match?
- Could also be useful for batch renames (variable/method renaming within a function scope).
Class methods
Apply a C0DIFF buffer to a hash of file contents. Returns the modified file contents. Raises on validation failure. All files are validated before any modifications (atomic semantics).
apply_files(diff_buf : Bytes, base_dir : String = ".") : Nil
Apply a C0DIFF buffer to files on disk. Validates all files before writing any (atomic semantics).