Apply Patch Tool
Applies a unified diff (output of git diff) to local files. Mutation permission โ gateway prompts for approval before execution.
Usage
# Inside an agent conversation:
"Here's the diff to apply:
```diff
--- a/src/server.ts
+++ b/src/server.ts
@@ -10,7 +10,7 @@
export const PORT = 3000;
-export const HOST = '0.0.0.0';
+export const HOST = '127.0.0.1';
...
```
Apply with apply_patch and dry_run first."Parameters
patch(string, required) โ unified diff contentworkdir(string) โ working dir, defaultprocess.cwd()dry_run(boolean) โ preview only, don't write. Defaultfalse.
Output
{
"success": true,
"data": {
"dryRun": false,
"filesAffected": 1,
"applied": 1,
"wouldApply": 0,
"conflicts": 0,
"results": [
{ "file": "src/server.ts", "status": "APPLIED", "hunks": 1 }
]
}
}Conflict handling
If a context line doesn't match the current file content, the hunk is rejected with status: "CONFLICT". The file is not modified.
Approval flow
Marked permission: "mutation". By default the gateway prompts via Approvals before writing. Auto-allow rules can opt out per-agent.
Source
Implementation: packages/plugins/apply-patch/