# Hash-edit agent guide
Anchored patches are parsed, prepared against snapshots, and committed through the tool filesystem policy.
## Where to look
| Patch envelope and syntax | `input.rs`, `parser.rs`, `tokenizer.rs`, `model.rs` |
| Line and block operations | `apply.rs`, `block.rs`, `normalize.rs` |
| Stale tags and retained snapshots | `recovery.rs`, `snapshots.rs` |
| Preparation, locking, commit, metadata | `tool.rs` |
| Diagnostic text | `format.rs` |
## Local contracts
- Address all operations against the original tagged snapshot, not line numbers shifted by earlier operations. Preserve overlap/range validation and block-selection rules.
- Prepare and validate sections before commit. Do not describe a multi-file patch as an all-or-nothing filesystem transaction: later commit failures can leave earlier sections written.
- Preserve per-file statuses and changed-path reporting, including committed-but-undurable writes and moves whose destination was written but source retained.
- Stale-tag recovery is intentional. Keep recovery tied to the existing snapshot/remapping checks and emit recovery warnings/metadata; do not add silent fuzzy matching.
- Restore original file shape, including BOM and line-ending handling, through `tool.rs` rather than writing normalized snapshot text directly.
- Keep mutation and cross-process locks, path checks, and atomic-write error handling on every write/move/remove route.
- Recovery snapshots and diagnostic context must remain bounded. Syntax or recovery-marker changes also require matching schema/prompt coverage in the parent tool layer.
Use existing module tests and `../tests/edit_write.rs` for multi-operation addressing, stale recovery, and write-failure regressions.