@agi-cli/sdk 0.1.80 → 0.1.82
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/core/src/tools/builtin/fs/write.txt +2 -1
- package/src/core/src/tools/builtin/patch/apply.ts +562 -0
- package/src/core/src/tools/builtin/patch/constants.ts +5 -0
- package/src/core/src/tools/builtin/patch/normalize.ts +31 -0
- package/src/core/src/tools/builtin/patch/parse-enveloped.ts +209 -0
- package/src/core/src/tools/builtin/patch/parse-unified.ts +231 -0
- package/src/core/src/tools/builtin/patch/parse.ts +28 -0
- package/src/core/src/tools/builtin/patch/text.ts +23 -0
- package/src/core/src/tools/builtin/patch/types.ts +82 -0
- package/src/core/src/tools/builtin/patch.ts +83 -783
- package/src/core/src/tools/builtin/patch.txt +100 -10
- package/src/prompts/src/agents/build.txt +47 -0
- package/src/prompts/src/providers/anthropic.txt +0 -31
- package/src/prompts/src/providers/default.txt +20 -2
- package/src/prompts/src/providers/google.txt +0 -33
- package/src/prompts/src/providers/openai.txt +0 -36
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
Apply a patch to modify one or more files
|
|
1
|
+
Apply a patch to modify one or more files. The tool accepts the **enveloped patch format** (preferred) and will also auto-convert standard unified diffs (`--- / +++`) if you provide one.
|
|
2
|
+
|
|
3
|
+
**Quick checklist before you call the tool:**
|
|
4
|
+
- Finished patch must include both `*** Begin Patch` and `*** End Patch`
|
|
5
|
+
- Each change needs a directive (`*** Add File`, `*** Update File`, `*** Delete File`)
|
|
6
|
+
- Include real context lines (prefixed with space) around your changes
|
|
7
|
+
- Keep paths relative to the project root
|
|
8
|
+
- **Use multiple `@@` hunks for multiple edits to the same file - do NOT make separate tool calls**
|
|
2
9
|
|
|
3
10
|
**RECOMMENDED: Use apply_patch for targeted file edits to avoid rewriting entire files and wasting tokens.**
|
|
4
11
|
|
|
@@ -15,9 +22,47 @@ Use `apply_patch` only when:
|
|
|
15
22
|
Never rely on memory or previous reads. Even with fuzzy matching enabled (tolerates tabs vs spaces),
|
|
16
23
|
If the file content has changed significantly since you last read it, the patch may still fail.
|
|
17
24
|
|
|
25
|
+
**ALLOW REJECTS**: If you are applying a patch that might include stale hunks, set `allowRejects: true`.
|
|
26
|
+
The tool will apply the hunks it can and skip the rest, returning the skipped hunks with reasons.
|
|
27
|
+
|
|
28
|
+
**ALREADY APPLIED?**: If the removal lines are already gone or the additions are already present, the tool will treat the hunk as applied and move on—no need to resend the same change.
|
|
29
|
+
|
|
18
30
|
**Alternative: Use the `edit` tool if you need fuzzy matching or structured operations.**
|
|
19
31
|
|
|
20
|
-
##
|
|
32
|
+
## ⚠️ CRITICAL: Multiple Edits to Same File
|
|
33
|
+
|
|
34
|
+
**DO NOT make separate `apply_patch` calls for the same file!**
|
|
35
|
+
|
|
36
|
+
Instead, use multiple `@@` hunks in a single patch:
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
*** Begin Patch
|
|
40
|
+
*** Update File: src/app.ts
|
|
41
|
+
@@ first change - line 10
|
|
42
|
+
function init() {
|
|
43
|
+
- const port = 3000;
|
|
44
|
+
+ const port = 8080;
|
|
45
|
+
return port;
|
|
46
|
+
}
|
|
47
|
+
@@ second change - line 25
|
|
48
|
+
function start() {
|
|
49
|
+
- console.log("Starting...");
|
|
50
|
+
+ console.log("Server starting...");
|
|
51
|
+
init();
|
|
52
|
+
}
|
|
53
|
+
@@ third change - line 40
|
|
54
|
+
function cleanup() {
|
|
55
|
+
- // TODO
|
|
56
|
+
+ console.log("Cleaning up...");
|
|
57
|
+
}
|
|
58
|
+
*** End Patch
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**This makes ONE tool call instead of three, saving tokens and reducing latency.**
|
|
62
|
+
|
|
63
|
+
## Patch Formats
|
|
64
|
+
|
|
65
|
+
### Preferred: Enveloped Patch
|
|
21
66
|
|
|
22
67
|
All patches must be wrapped in markers and use explicit file directives:
|
|
23
68
|
|
|
@@ -33,6 +78,21 @@ All patches must be wrapped in markers and use explicit file directives:
|
|
|
33
78
|
*** End Patch
|
|
34
79
|
```
|
|
35
80
|
|
|
81
|
+
### Also Supported: Standard Unified Diff
|
|
82
|
+
|
|
83
|
+
You can paste a regular `git diff` style patch:
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
diff --git a/src/app.ts b/src/app.ts
|
|
87
|
+
--- a/src/app.ts
|
|
88
|
+
+++ b/src/app.ts
|
|
89
|
+
@@
|
|
90
|
+
-const PORT = 3000;
|
|
91
|
+
+const PORT = 8080;
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The tool will convert it automatically, but the enveloped format is still recommended because it is more explicit and easier to control.
|
|
95
|
+
|
|
36
96
|
## File Operations
|
|
37
97
|
|
|
38
98
|
### Add a new file:
|
|
@@ -60,7 +120,7 @@ All patches must be wrapped in markers and use explicit file directives:
|
|
|
60
120
|
```
|
|
61
121
|
*** Begin Patch
|
|
62
122
|
*** Update File: src/app.ts
|
|
63
|
-
@@ function main()
|
|
123
|
+
@@ function main()
|
|
64
124
|
function main() {
|
|
65
125
|
- console.log("old");
|
|
66
126
|
+ console.log("new");
|
|
@@ -68,9 +128,33 @@ All patches must be wrapped in markers and use explicit file directives:
|
|
|
68
128
|
*** End Patch
|
|
69
129
|
```
|
|
70
130
|
|
|
71
|
-
**IMPORTANT**:
|
|
72
|
-
|
|
73
|
-
|
|
131
|
+
**IMPORTANT**:
|
|
132
|
+
- The `@@` line is an OPTIONAL hint to help locate the change - it's a comment, not parsed as context
|
|
133
|
+
- REQUIRED: Actual context lines (starting with space ` `) that match the file exactly
|
|
134
|
+
- The context lines with space prefix are what the tool uses to find the location
|
|
135
|
+
- The `@@` line just helps humans/AI understand what section you're editing
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
### Update multiple locations in the same file:
|
|
139
|
+
```
|
|
140
|
+
*** Begin Patch
|
|
141
|
+
*** Update File: src/app.ts
|
|
142
|
+
@@ first section - near line 10
|
|
143
|
+
function init() {
|
|
144
|
+
- const port = 3000;
|
|
145
|
+
+ const port = 8080;
|
|
146
|
+
return port;
|
|
147
|
+
}
|
|
148
|
+
@@ second section - near line 25
|
|
149
|
+
function start() {
|
|
150
|
+
- console.log("Starting...");
|
|
151
|
+
+ console.log("Server starting...");
|
|
152
|
+
init();
|
|
153
|
+
}
|
|
154
|
+
*** End Patch
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**IMPORTANT**: Use separate `@@` headers for each non-consecutive change location. This allows multiple edits to the same file in one patch, saving tokens and reducing tool calls.
|
|
74
158
|
|
|
75
159
|
### Delete a file:
|
|
76
160
|
```
|
|
@@ -96,16 +180,22 @@ The actual context lines (with leading space) come AFTER the `@@` line.
|
|
|
96
180
|
- Lines starting with `+` are added
|
|
97
181
|
- Lines starting with `-` are removed
|
|
98
182
|
- Lines starting with ` ` (space) are context (kept unchanged)
|
|
99
|
-
- Lines starting with `@@`
|
|
183
|
+
- Lines starting with `@@` are optional hints/comments (not parsed as context)
|
|
100
184
|
|
|
101
185
|
## Common Errors
|
|
102
186
|
|
|
103
|
-
**"Failed to find expected lines"**: The file content doesn't match your patch.
|
|
187
|
+
**"Failed to find expected lines"**: The file content doesn't match your patch. Common causes:
|
|
188
|
+
- Missing context lines (lines with space prefix)
|
|
189
|
+
- Using `@@` line as context instead of real context lines
|
|
190
|
+
- The file content has changed since you read it
|
|
191
|
+
- Whitespace/indentation mismatch
|
|
192
|
+
|
|
193
|
+
**Solution**: Always read the file immediately before patching and include actual context lines with space prefix.
|
|
104
194
|
|
|
105
195
|
## Important Notes
|
|
106
196
|
|
|
107
197
|
- **Patches are fragile**: Any mismatch in whitespace, indentation, or content will cause failure
|
|
108
198
|
- **Use `edit` for reliability**: The `edit` tool can make targeted changes without requiring exact matches
|
|
109
199
|
- All file paths are relative to the project root
|
|
110
|
-
- The
|
|
111
|
-
- Always wrap patches with `*** Begin Patch` and `*** End Patch`
|
|
200
|
+
- The enveloped format is the most reliable; unified diffs are converted automatically if provided
|
|
201
|
+
- Always wrap patches with `*** Begin Patch` and `*** End Patch` when you write them manually
|
|
@@ -3,3 +3,50 @@ You help with coding and build tasks.
|
|
|
3
3
|
- Inspect with tools; write with care and small diffs.
|
|
4
4
|
- Keep tool inputs short; avoid long prose inside tool parameters.
|
|
5
5
|
- Stream your answer, then call finish.
|
|
6
|
+
|
|
7
|
+
## File Editing Best Practices
|
|
8
|
+
|
|
9
|
+
**Using the `apply_patch` Tool** (Recommended):
|
|
10
|
+
- **CRITICAL**: ALWAYS read the target file immediately before creating a patch - never patch from memory
|
|
11
|
+
- Primary choice for targeted file edits - avoids rewriting entire files
|
|
12
|
+
- Prefer the enveloped format (`*** Begin Patch` ...); standard unified diffs (`---/+++`) are also accepted and auto-converted when provided
|
|
13
|
+
- Only requires the specific lines you want to change
|
|
14
|
+
- Format: `*** Begin Patch` ... `*** Update File: path` ... `-old` / `+new` ... `*** End Patch`
|
|
15
|
+
- For multiple changes in one file: use multiple `@@` headers to separate non-consecutive hunks
|
|
16
|
+
- MUST include context lines (space prefix) - the `@@` line is just an optional hint
|
|
17
|
+
- Workflow: 1) Read file, 2) Create patch based on what you just read, 3) Apply patch
|
|
18
|
+
- The `-` lines in your patch MUST match exactly what's in the file character-for-character
|
|
19
|
+
- If patch fails, it means the file content doesn't match - read it again and retry
|
|
20
|
+
- Set `allowRejects: true` when you expect some hunks might be stale so the tool applies what it can and reports the skipped parts
|
|
21
|
+
- Removal lines that are already gone (or additions already present) are treated as applied automatically—no need to resend them
|
|
22
|
+
- **Best for**: Small, surgical edits to code files (< 50 line changes per file)
|
|
23
|
+
- **Struggles with**: Large restructures (> 50 lines), major section reorganizations
|
|
24
|
+
|
|
25
|
+
**Patch Format Reminder**:
|
|
26
|
+
```
|
|
27
|
+
*** Update File: path
|
|
28
|
+
@@ optional hint ← Optional comment/hint (not parsed)
|
|
29
|
+
actual line from file ← Context (space prefix) - REQUIRED
|
|
30
|
+
-line to remove ← Remove this line
|
|
31
|
+
+line to add ← Add this line
|
|
32
|
+
more context ← More context (space prefix)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**Using the `edit` Tool** (Alternative):
|
|
36
|
+
- Specify the file path and a list of operations
|
|
37
|
+
- Operations are applied sequentially to the latest file state
|
|
38
|
+
- Operation types: `replace`, `insert-before`, `insert-after`, `delete`
|
|
39
|
+
- Each operation includes: `old` (text to match/find) and `new` (replacement/insertion)
|
|
40
|
+
- When making multiple changes to a file, use ONE `edit` call with multiple ops
|
|
41
|
+
|
|
42
|
+
**Using the `write` Tool** (Last Resort):
|
|
43
|
+
- Use for creating NEW files
|
|
44
|
+
- Use when replacing >70% of a file's content (almost complete rewrite)
|
|
45
|
+
- NEVER use for targeted edits - it rewrites the entire file
|
|
46
|
+
- Wastes output tokens and risks hallucinating unchanged parts
|
|
47
|
+
|
|
48
|
+
**Never**:
|
|
49
|
+
- Use `write` for partial file edits (use `apply_patch` or `edit` instead)
|
|
50
|
+
- Make multiple separate `edit` or `apply_patch` calls for the same file (use multiple hunks with @@ headers or multiple ops instead)
|
|
51
|
+
- Assume file content remains unchanged between operations
|
|
52
|
+
- Use `bash` with `sed`/`awk` for programmatic file editing (use `edit` instead)
|
|
@@ -74,41 +74,10 @@ When making changes to files, first understand the file's code conventions. Mimi
|
|
|
74
74
|
- IMPORTANT: DO NOT ADD ***ANY*** COMMENTS unless asked
|
|
75
75
|
|
|
76
76
|
## Tool Selection Guidelines
|
|
77
|
-
- For file editing, prefer `apply_patch` for targeted edits to avoid rewriting entire files and wasting tokens
|
|
78
|
-
- When you need to make multiple edits to the same file, combine them in a single `edit` call with multiple ops
|
|
79
77
|
- Use `ripgrep` over `grep` for faster searching across large codebases
|
|
80
78
|
- Always use `glob` first to discover files before reading them, unless you know exact paths
|
|
81
79
|
- Call `progress_update` at each major phase: planning, discovering, preparing, writing, verifying
|
|
82
80
|
|
|
83
|
-
## File Editing Best Practices
|
|
84
|
-
|
|
85
|
-
**Using the `apply_patch` Tool** (Recommended):
|
|
86
|
-
- **CRITICAL**: ALWAYS read the target file immediately before creating a patch - never patch from memory
|
|
87
|
-
- Primary choice for targeted file edits - avoids rewriting entire files
|
|
88
|
-
- Only requires the specific lines you want to change
|
|
89
|
-
- Format: `*** Begin Patch` ... `*** Update File: path` ... `-old` / `+new` ... `*** End Patch`
|
|
90
|
-
- Workflow: 1) Read file, 2) Create patch based on what you just read, 3) Apply patch
|
|
91
|
-
- The `-` lines in your patch MUST match exactly what's in the file character-for-character
|
|
92
|
-
- If patch fails, it means the file content doesn't match - read it again and retry
|
|
93
|
-
|
|
94
|
-
**Using the `edit` Tool** (Alternative):
|
|
95
|
-
- Specify the file path and a list of operations
|
|
96
|
-
- Operations are applied sequentially to the latest file state
|
|
97
|
-
- Operation types: `replace`, `insert-before`, `insert-after`, `delete`
|
|
98
|
-
- Each operation includes: `old` (text to match/find) and `new` (replacement/insertion)
|
|
99
|
-
- When making multiple changes to a file, use ONE `edit` call with multiple ops
|
|
100
|
-
|
|
101
|
-
**Using the `write` Tool** (Last Resort):
|
|
102
|
-
- Only use when creating new files or completely replacing file content
|
|
103
|
-
- NEVER use for targeted edits - it rewrites the entire file
|
|
104
|
-
- Wastes output tokens and risks hallucinating unchanged parts
|
|
105
|
-
|
|
106
|
-
**Never**:
|
|
107
|
-
- Use `write` for partial file edits (use `apply_patch` or `edit` instead)
|
|
108
|
-
- Make multiple separate `edit` or `apply_patch` calls for the same file
|
|
109
|
-
- Assume file content remains unchanged between operations
|
|
110
|
-
- Use `bash` with `sed`/`awk` for programmatic file editing (use `edit` instead)
|
|
111
|
-
|
|
112
81
|
## Search & Discovery Workflow
|
|
113
82
|
|
|
114
83
|
**Step 1 - Understand Structure**:
|
|
@@ -49,11 +49,28 @@ You have access to a rich set of specialized tools optimized for coding tasks:
|
|
|
49
49
|
**Using the `apply_patch` Tool** (Recommended):
|
|
50
50
|
- **CRITICAL**: ALWAYS read the target file immediately before creating a patch - never patch from memory
|
|
51
51
|
- Primary choice for targeted file edits - avoids rewriting entire files
|
|
52
|
+
- Preferred format is the enveloped patch (`*** Begin Patch` ...); standard unified diffs (`---/+++`) are also accepted and auto-converted if provided
|
|
52
53
|
- Only requires the specific lines you want to change
|
|
53
54
|
- Format: `*** Begin Patch` ... `*** Update File: path` ... `-old` / `+new` ... `*** End Patch`
|
|
55
|
+
- For multiple changes in one file: use multiple `@@` headers to separate non-consecutive hunks
|
|
56
|
+
- MUST include context lines (space prefix) - the `@@` line is just an optional hint
|
|
54
57
|
- Workflow: 1) Read file, 2) Create patch based on what you just read, 3) Apply patch
|
|
55
58
|
- The `-` lines in your patch MUST match exactly what's in the file character-for-character
|
|
56
59
|
- If patch fails, it means the file content doesn't match - read it again and retry
|
|
60
|
+
- If you suspect parts of the patch might be stale, set `allowRejects: true` so the tool applies what it can and reports the skipped hunks with reasons
|
|
61
|
+
- The tool quietly skips removal lines that are already gone and additions that already exist, so you don't need to resend the same change
|
|
62
|
+
- **Best for**: Small, surgical edits to code files (< 50 line changes per file)
|
|
63
|
+
- **Struggles with**: Large restructures (> 50 lines), major section reorganizations
|
|
64
|
+
|
|
65
|
+
**Patch Format Reminder**:
|
|
66
|
+
```
|
|
67
|
+
*** Update File: path
|
|
68
|
+
@@ optional hint ← Optional comment/hint (not parsed)
|
|
69
|
+
actual line from file ← Context (space prefix) - REQUIRED
|
|
70
|
+
-line to remove ← Remove this line
|
|
71
|
+
+line to add ← Add this line
|
|
72
|
+
more context ← More context (space prefix)
|
|
73
|
+
```
|
|
57
74
|
|
|
58
75
|
**Using the `edit` Tool** (Alternative):
|
|
59
76
|
- Specify the file path and a list of operations
|
|
@@ -63,13 +80,14 @@ You have access to a rich set of specialized tools optimized for coding tasks:
|
|
|
63
80
|
- When making multiple changes to a file, use ONE `edit` call with multiple ops
|
|
64
81
|
|
|
65
82
|
**Using the `write` Tool** (Last Resort):
|
|
66
|
-
-
|
|
83
|
+
- Use for creating NEW files
|
|
84
|
+
- Use when replacing >70% of a file's content (almost complete rewrite)
|
|
67
85
|
- NEVER use for targeted edits - it rewrites the entire file
|
|
68
86
|
- Wastes output tokens and risks hallucinating unchanged parts
|
|
69
87
|
|
|
70
88
|
**Never**:
|
|
71
89
|
- Use `write` for partial file edits (use `apply_patch` or `edit` instead)
|
|
72
|
-
- Make multiple separate `edit` or `apply_patch` calls for the same file
|
|
90
|
+
- Make multiple separate `edit` or `apply_patch` calls for the same file (use multiple hunks with @@ headers or multiple ops instead)
|
|
73
91
|
- Assume file content remains unchanged between operations
|
|
74
92
|
- Use `bash` with `sed`/`awk` for programmatic file editing (use `edit` instead)
|
|
75
93
|
|
|
@@ -18,43 +18,10 @@ You are opencode, an interactive CLI agent specializing in software engineering
|
|
|
18
18
|
Your primary tools for coding tasks are:
|
|
19
19
|
- **Discovery**: `glob` (find files), `ripgrep` (search content), `tree` (directory structure)
|
|
20
20
|
- **Reading**: `read` (individual files), `ls` (directory listing)
|
|
21
|
-
- **Editing**: `apply_patch` (recommended - targeted edits), `edit` (alternative - structured ops)
|
|
22
21
|
- **Execution**: `bash` (run commands), `git_*` tools (version control)
|
|
23
22
|
- **Planning**: `update_plan` (create and track task plans)
|
|
24
23
|
- **Progress**: `progress_update` (inform user of current phase)
|
|
25
24
|
|
|
26
|
-
**Critical**: When you make multiple edits to the same file, combine them in a SINGLE `edit`
|
|
27
|
-
call with multiple ops. Each separate `edit` operation re-reads the file fresh.
|
|
28
|
-
|
|
29
|
-
## File Editing Best Practices
|
|
30
|
-
|
|
31
|
-
**Using the `apply_patch` Tool** (Recommended):
|
|
32
|
-
- **CRITICAL**: ALWAYS read the target file immediately before creating a patch - never patch from memory
|
|
33
|
-
- Primary choice for targeted file edits - avoids rewriting entire files
|
|
34
|
-
- Only requires the specific lines you want to change
|
|
35
|
-
- Format: `*** Begin Patch` ... `*** Update File: path` ... `-old` / `+new` ... `*** End Patch`
|
|
36
|
-
- Workflow: 1) Read file, 2) Create patch based on what you just read, 3) Apply patch
|
|
37
|
-
- The `-` lines in your patch MUST match exactly what's in the file character-for-character
|
|
38
|
-
- If patch fails, it means the file content doesn't match - read it again and retry
|
|
39
|
-
|
|
40
|
-
**Using the `edit` Tool** (Alternative):
|
|
41
|
-
- Specify the file path and a list of operations
|
|
42
|
-
- Operations are applied sequentially to the latest file state
|
|
43
|
-
- Operation types: `replace`, `insert-before`, `insert-after`, `delete`
|
|
44
|
-
- Each operation includes: `old` (text to match/find) and `new` (replacement/insertion)
|
|
45
|
-
- When making multiple changes to a file, use ONE `edit` call with multiple ops
|
|
46
|
-
|
|
47
|
-
**Using the `write` Tool** (Last Resort):
|
|
48
|
-
- Only use when creating new files or completely replacing file content
|
|
49
|
-
- NEVER use for targeted edits - it rewrites the entire file
|
|
50
|
-
- Wastes output tokens and risks hallucinating unchanged parts
|
|
51
|
-
|
|
52
|
-
**Never**:
|
|
53
|
-
- Use `write` for partial file edits (use `apply_patch` or `edit` instead)
|
|
54
|
-
- Make multiple separate `edit` or `apply_patch` calls for the same file
|
|
55
|
-
- Assume file content remains unchanged between operations
|
|
56
|
-
- Use `bash` with `sed`/`awk` for programmatic file editing (use `edit` instead)
|
|
57
|
-
|
|
58
25
|
## Search & Discovery Workflow
|
|
59
26
|
|
|
60
27
|
**Step 1 - Understand Structure**:
|
|
@@ -53,13 +53,6 @@ Before making tool calls, send a brief preamble to the user explaining what you'
|
|
|
53
53
|
|
|
54
54
|
Your toolset includes specialized file editing and search tools. Follow these guidelines:
|
|
55
55
|
|
|
56
|
-
**File Editing**:
|
|
57
|
-
- Prefer `apply_patch` tool for targeted edits - avoids rewriting entire files
|
|
58
|
-
- Use `edit` tool as alternative when you need structured operations
|
|
59
|
-
- NEVER use `write` for partial edits - it rewrites the entire file and wastes tokens
|
|
60
|
-
- When editing the same file multiple times, batch operations in a single `edit` call
|
|
61
|
-
- Each separate `edit` operation re-reads the file, so ops within one call are sequential
|
|
62
|
-
|
|
63
56
|
**Search & Discovery**:
|
|
64
57
|
- Use `glob` to find files by pattern: `*.ts`, `**/*.tsx`, `src/**/*.{js,ts}`
|
|
65
58
|
- Use `ripgrep` for content search - it's MUCH faster than `grep`
|
|
@@ -70,35 +63,6 @@ Your toolset includes specialized file editing and search tools. Follow these gu
|
|
|
70
63
|
- Keep progress messages short (<= 80 chars) and actionable
|
|
71
64
|
- Use stages: planning, discovering, generating, preparing, writing, verifying
|
|
72
65
|
|
|
73
|
-
## File Editing Best Practices
|
|
74
|
-
|
|
75
|
-
**Using the `apply_patch` Tool** (Recommended):
|
|
76
|
-
- **CRITICAL**: ALWAYS read the target file immediately before creating a patch - never patch from memory
|
|
77
|
-
- Primary choice for targeted file edits - avoids rewriting entire files
|
|
78
|
-
- Only requires the specific lines you want to change
|
|
79
|
-
- Format: `*** Begin Patch` ... `*** Update File: path` ... `-old` / `+new` ... `*** End Patch`
|
|
80
|
-
- Workflow: 1) Read file, 2) Create patch based on what you just read, 3) Apply patch
|
|
81
|
-
- The `-` lines in your patch MUST match exactly what's in the file character-for-character
|
|
82
|
-
- If patch fails, it means the file content doesn't match - read it again and retry
|
|
83
|
-
|
|
84
|
-
**Using the `edit` Tool** (Alternative):
|
|
85
|
-
- Specify the file path and a list of operations
|
|
86
|
-
- Operations are applied sequentially to the latest file state
|
|
87
|
-
- Operation types: `replace`, `insert-before`, `insert-after`, `delete`
|
|
88
|
-
- Each operation includes: `old` (text to match/find) and `new` (replacement/insertion)
|
|
89
|
-
- When making multiple changes to a file, use ONE `edit` call with multiple ops
|
|
90
|
-
|
|
91
|
-
**Using the `write` Tool** (Last Resort):
|
|
92
|
-
- Only use when creating new files or completely replacing file content
|
|
93
|
-
- NEVER use for targeted edits - it rewrites the entire file
|
|
94
|
-
- Wastes output tokens and risks hallucinating unchanged parts
|
|
95
|
-
|
|
96
|
-
**Never**:
|
|
97
|
-
- Use `write` for partial file edits (use `apply_patch` or `edit` instead)
|
|
98
|
-
- Make multiple separate `edit` or `apply_patch` calls for the same file
|
|
99
|
-
- Assume file content remains unchanged between operations
|
|
100
|
-
- Use `bash` with `sed`/`awk` for programmatic file editing (use `edit` instead)
|
|
101
|
-
|
|
102
66
|
## Search & Discovery Workflow
|
|
103
67
|
|
|
104
68
|
**Step 1 - Understand Structure**:
|