| name | apply-patch |
| description | Apply a unified diff to the workspace. Use when: the user provides a patch, you generated a diff and want to apply it, or you're integrating an upstream change. NOT for: small surgical edits to a known file (use file-ops write_file). |
| metadata | {"all_agents":{"emoji":"🩹","requires":{"bins":["patch"]}}} |
Apply Patch
Use the run_command infra capability to invoke GNU patch -p1.
Workflow
- Save the diff with
write_file { path: "patches/change.diff", content: "..." }.
- Apply:
run_command { command: "patch -p1 < patches/change.diff" }.
- On failure (non-zero return), inspect
.rej files via glob_files { pattern: "*.rej" }.
Rules
- Always
read_file the target paths first to confirm context lines match.
- Never feed a diff that mixes binary changes —
patch won't apply them.
- After success, run the project's tests via
run_command if available.