Skip to content

New tool: apply_patch (multi-file unified-diff edits in one call) #20

Description

@stefanthearchitect

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%.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions