Context
borg edits with write_file / edit_file / edit_lines (internal/tools/fs.go), one file per call. For a change that spans several files, that's several round-trips. A single apply_patch tool that applies a unified diff across files would cut steps (and steps dominate token cost — each step re-sends the whole conversation).
The task
Add an apply_patch tool that takes a unified diff and applies it, respecting the trust boundary (internal/tools/boundary.go) for every touched path. It's a mutating tool, so it goes through the same permission gate.
Notes
- Reuse
guardPath for each target — an apply_patch must not be a way around the trusted-root scoping.
- Report a clear failure (which hunk, which file) when a patch doesn't apply, so the model can recover.
Acceptance
- A multi-file diff applies in one call; out-of-root paths are refused.
- Malformed/partial patches fail with an actionable message, no partial corruption.
- Tests. Coverage ≥90%.
Context
borg edits with
write_file/edit_file/edit_lines(internal/tools/fs.go), one file per call. For a change that spans several files, that's several round-trips. A singleapply_patchtool that applies a unified diff across files would cut steps (and steps dominate token cost — each step re-sends the whole conversation).The task
Add an
apply_patchtool that takes a unified diff and applies it, respecting the trust boundary (internal/tools/boundary.go) for every touched path. It's a mutating tool, so it goes through the same permission gate.Notes
guardPathfor each target — anapply_patchmust not be a way around the trusted-root scoping.Acceptance