Expand description
apply_patch: apply a structured multi-file patch atomically.
The patch format is the V4A flavour popularised by Anthropic and used by OpenAI’s Codex CLI: no line numbers, context lines locate the change in the file. This is materially more robust than unified diff for LLM-authored edits — models reliably mis-count line numbers, but they reliably preserve a few lines of context.
*** Begin Patch
*** Update File: src/foo.rs
@@ optional anchor
context line (unchanged, must match the file exactly)
-line to remove (must match the file exactly)
+line to add
context line
*** Add File: new/file.rs
+line one
+line two
*** Delete File: doomed/file.rs
*** End PatchReliability strategy:
- Strict matching. Context+remove lines must match the live file exactly. No fuzzy matching.
- Single-match. If a hunk’s pattern appears 0 or >1 times in the
file, the patch is rejected (the model can add an
@@ anchorfor disambiguation or include more context). - Atomic. All hunks are applied in memory first; only after every file’s final state is computed do we touch the disk. A failure in hunk N rolls the whole patch back; nothing on disk changes.
- Sandboxed. Every path goes through
resolve_within. - Useful errors. The tool returns structured diagnostics (which file, which hunk, what was being matched) so the model can self-correct.