Skip to content

Commit 4299450

Browse files
committed
tweak apply_patch tool description
1 parent 3515b4f commit 4299450

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

packages/opencode/src/tool/apply_patch.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ import { assertExternalDirectory } from "./external-directory"
1212
import { trimDiff } from "./edit"
1313
import { LSP } from "../lsp"
1414
import { Filesystem } from "../util/filesystem"
15+
import DESCRIPTION from "./apply_patch.txt"
1516

1617
const PatchParams = z.object({
1718
patchText: z.string().describe("The full patch text that describes all changes to be made"),
1819
})
1920

2021
export const ApplyPatchTool = Tool.define("apply_patch", {
21-
description: "Use the `apply_patch` tool to edit files. This is a FREEFORM tool, so do not wrap the patch in JSON.",
22+
description: DESCRIPTION,
2223
parameters: PatchParams,
2324
async execute(params, ctx) {
2425
if (!params.patchText) {
Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,33 @@
1-
Use the `apply_patch` tool to edit files. This is a FREEFORM tool, so do not wrap the patch in JSON.
1+
Use the `apply_patch` tool to edit files. This is a FREEFORM tool, so do not wrap the patch in JSON. Your patch language is a stripped‑down, file‑oriented diff format designed to be easy to parse and safe to apply. You can think of it as a high‑level envelope:
2+
3+
*** Begin Patch
4+
[ one or more file sections ]
5+
*** End Patch
6+
7+
Within that envelope, you get a sequence of file operations.
8+
You MUST include a header to specify the action you are taking.
9+
Each operation starts with one of three headers:
10+
11+
*** Add File: <path> - create a new file. Every following line is a + line (the initial contents).
12+
*** Delete File: <path> - remove an existing file. Nothing follows.
13+
*** Update File: <path> - patch an existing file in place (optionally with a rename).
14+
15+
Example patch:
16+
17+
```
18+
*** Begin Patch
19+
*** Add File: hello.txt
20+
+Hello world
21+
*** Update File: src/app.py
22+
*** Move to: src/main.py
23+
@@ def greet():
24+
-print("Hi")
25+
+print("Hello, world!")
26+
*** Delete File: obsolete.txt
27+
*** End Patch
28+
```
29+
30+
It is important to remember:
31+
32+
- You must include a header with your intended action (Add/Delete/Update)
33+
- You must prefix new lines with `+` even when creating a new file

0 commit comments

Comments
 (0)