@agi-cli/sdk 0.1.80 → 0.1.81
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.ts +3 -1
- package/src/core/src/tools/builtin/patch.txt +36 -6
- package/src/prompts/src/providers/anthropic.txt +17 -2
- package/src/prompts/src/providers/default.txt +17 -2
- package/src/prompts/src/providers/google.txt +17 -2
- package/src/prompts/src/providers/openai.txt +17 -2
package/package.json
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
- Returns a compact patch artifact summarizing the change
|
|
5
5
|
|
|
6
6
|
Usage tips:
|
|
7
|
-
-
|
|
7
|
+
- Use for creating NEW files
|
|
8
|
+
- Use when replacing >70% of a file's content (almost complete rewrite)
|
|
8
9
|
- NEVER use for partial/targeted edits - use apply_patch or edit instead
|
|
9
10
|
- Using write for partial edits wastes output tokens and risks hallucinating unchanged parts
|
|
10
11
|
- Prefer idempotent writes by providing the full intended content when you do use write
|
|
@@ -351,7 +351,9 @@ function parseEnvelopedPatch(patch: string): ParsedPatchOperation[] {
|
|
|
351
351
|
} else if (prefix === ' ') {
|
|
352
352
|
currentHunk.lines.push({ kind: 'context', content: line.slice(1) });
|
|
353
353
|
} else {
|
|
354
|
-
|
|
354
|
+
// Auto-correct: treat lines without prefix as context (with implicit space)
|
|
355
|
+
// This makes the parser more forgiving for AI-generated patches
|
|
356
|
+
currentHunk.lines.push({ kind: 'context', content: line });
|
|
355
357
|
}
|
|
356
358
|
}
|
|
357
359
|
|
|
@@ -60,7 +60,7 @@ All patches must be wrapped in markers and use explicit file directives:
|
|
|
60
60
|
```
|
|
61
61
|
*** Begin Patch
|
|
62
62
|
*** Update File: src/app.ts
|
|
63
|
-
@@ function main()
|
|
63
|
+
@@ function main()
|
|
64
64
|
function main() {
|
|
65
65
|
- console.log("old");
|
|
66
66
|
+ console.log("new");
|
|
@@ -68,9 +68,33 @@ All patches must be wrapped in markers and use explicit file directives:
|
|
|
68
68
|
*** End Patch
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
-
**IMPORTANT**:
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
**IMPORTANT**:
|
|
72
|
+
- The `@@` line is an OPTIONAL hint to help locate the change - it's a comment, not parsed as context
|
|
73
|
+
- REQUIRED: Actual context lines (starting with space ` `) that match the file exactly
|
|
74
|
+
- The context lines with space prefix are what the tool uses to find the location
|
|
75
|
+
- The `@@` line just helps humans/AI understand what section you're editing
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
### Update multiple locations in the same file:
|
|
79
|
+
```
|
|
80
|
+
*** Begin Patch
|
|
81
|
+
*** Update File: src/app.ts
|
|
82
|
+
@@ first section - near line 10
|
|
83
|
+
function init() {
|
|
84
|
+
- const port = 3000;
|
|
85
|
+
+ const port = 8080;
|
|
86
|
+
return port;
|
|
87
|
+
}
|
|
88
|
+
@@ second section - near line 25
|
|
89
|
+
function start() {
|
|
90
|
+
- console.log("Starting...");
|
|
91
|
+
+ console.log("Server starting...");
|
|
92
|
+
init();
|
|
93
|
+
}
|
|
94
|
+
*** End Patch
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**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
98
|
|
|
75
99
|
### Delete a file:
|
|
76
100
|
```
|
|
@@ -96,11 +120,17 @@ The actual context lines (with leading space) come AFTER the `@@` line.
|
|
|
96
120
|
- Lines starting with `+` are added
|
|
97
121
|
- Lines starting with `-` are removed
|
|
98
122
|
- Lines starting with ` ` (space) are context (kept unchanged)
|
|
99
|
-
- Lines starting with `@@`
|
|
123
|
+
- Lines starting with `@@` are optional hints/comments (not parsed as context)
|
|
100
124
|
|
|
101
125
|
## Common Errors
|
|
102
126
|
|
|
103
|
-
**"Failed to find expected lines"**: The file content doesn't match your patch.
|
|
127
|
+
**"Failed to find expected lines"**: The file content doesn't match your patch. Common causes:
|
|
128
|
+
- Missing context lines (lines with space prefix)
|
|
129
|
+
- Using `@@` line as context instead of real context lines
|
|
130
|
+
- The file content has changed since you read it
|
|
131
|
+
- Whitespace/indentation mismatch
|
|
132
|
+
|
|
133
|
+
**Solution**: Always read the file immediately before patching and include actual context lines with space prefix.
|
|
104
134
|
|
|
105
135
|
## Important Notes
|
|
106
136
|
|
|
@@ -87,9 +87,23 @@ When making changes to files, first understand the file's code conventions. Mimi
|
|
|
87
87
|
- Primary choice for targeted file edits - avoids rewriting entire files
|
|
88
88
|
- Only requires the specific lines you want to change
|
|
89
89
|
- Format: `*** Begin Patch` ... `*** Update File: path` ... `-old` / `+new` ... `*** End Patch`
|
|
90
|
+
- For multiple changes in one file: use multiple `@@` headers to separate non-consecutive hunks
|
|
91
|
+
- MUST include context lines (space prefix) - the `@@` line is just an optional hint
|
|
90
92
|
- Workflow: 1) Read file, 2) Create patch based on what you just read, 3) Apply patch
|
|
91
93
|
- The `-` lines in your patch MUST match exactly what's in the file character-for-character
|
|
92
94
|
- If patch fails, it means the file content doesn't match - read it again and retry
|
|
95
|
+
- **Best for**: Small, surgical edits to code files (< 50 line changes per file)
|
|
96
|
+
- **Struggles with**: Large restructures (> 50 lines), major section reorganizations
|
|
97
|
+
|
|
98
|
+
**Patch Format Reminder**:
|
|
99
|
+
```
|
|
100
|
+
*** Update File: path
|
|
101
|
+
@@ optional hint ← Optional comment/hint (not parsed)
|
|
102
|
+
actual line from file ← Context (space prefix) - REQUIRED
|
|
103
|
+
-line to remove ← Remove this line
|
|
104
|
+
+line to add ← Add this line
|
|
105
|
+
more context ← More context (space prefix)
|
|
106
|
+
```
|
|
93
107
|
|
|
94
108
|
**Using the `edit` Tool** (Alternative):
|
|
95
109
|
- Specify the file path and a list of operations
|
|
@@ -99,13 +113,14 @@ When making changes to files, first understand the file's code conventions. Mimi
|
|
|
99
113
|
- When making multiple changes to a file, use ONE `edit` call with multiple ops
|
|
100
114
|
|
|
101
115
|
**Using the `write` Tool** (Last Resort):
|
|
102
|
-
-
|
|
116
|
+
- Use for creating NEW files
|
|
117
|
+
- Use when replacing >70% of a file's content (almost complete rewrite)
|
|
103
118
|
- NEVER use for targeted edits - it rewrites the entire file
|
|
104
119
|
- Wastes output tokens and risks hallucinating unchanged parts
|
|
105
120
|
|
|
106
121
|
**Never**:
|
|
107
122
|
- 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
|
|
123
|
+
- Make multiple separate `edit` or `apply_patch` calls for the same file (use multiple hunks with @@ headers or multiple ops instead)
|
|
109
124
|
- Assume file content remains unchanged between operations
|
|
110
125
|
- Use `bash` with `sed`/`awk` for programmatic file editing (use `edit` instead)
|
|
111
126
|
|
|
@@ -51,9 +51,23 @@ You have access to a rich set of specialized tools optimized for coding tasks:
|
|
|
51
51
|
- Primary choice for targeted file edits - avoids rewriting entire files
|
|
52
52
|
- Only requires the specific lines you want to change
|
|
53
53
|
- Format: `*** Begin Patch` ... `*** Update File: path` ... `-old` / `+new` ... `*** End Patch`
|
|
54
|
+
- For multiple changes in one file: use multiple `@@` headers to separate non-consecutive hunks
|
|
55
|
+
- MUST include context lines (space prefix) - the `@@` line is just an optional hint
|
|
54
56
|
- Workflow: 1) Read file, 2) Create patch based on what you just read, 3) Apply patch
|
|
55
57
|
- The `-` lines in your patch MUST match exactly what's in the file character-for-character
|
|
56
58
|
- If patch fails, it means the file content doesn't match - read it again and retry
|
|
59
|
+
- **Best for**: Small, surgical edits to code files (< 50 line changes per file)
|
|
60
|
+
- **Struggles with**: Large restructures (> 50 lines), major section reorganizations
|
|
61
|
+
|
|
62
|
+
**Patch Format Reminder**:
|
|
63
|
+
```
|
|
64
|
+
*** Update File: path
|
|
65
|
+
@@ optional hint ← Optional comment/hint (not parsed)
|
|
66
|
+
actual line from file ← Context (space prefix) - REQUIRED
|
|
67
|
+
-line to remove ← Remove this line
|
|
68
|
+
+line to add ← Add this line
|
|
69
|
+
more context ← More context (space prefix)
|
|
70
|
+
```
|
|
57
71
|
|
|
58
72
|
**Using the `edit` Tool** (Alternative):
|
|
59
73
|
- Specify the file path and a list of operations
|
|
@@ -63,13 +77,14 @@ You have access to a rich set of specialized tools optimized for coding tasks:
|
|
|
63
77
|
- When making multiple changes to a file, use ONE `edit` call with multiple ops
|
|
64
78
|
|
|
65
79
|
**Using the `write` Tool** (Last Resort):
|
|
66
|
-
-
|
|
80
|
+
- Use for creating NEW files
|
|
81
|
+
- Use when replacing >70% of a file's content (almost complete rewrite)
|
|
67
82
|
- NEVER use for targeted edits - it rewrites the entire file
|
|
68
83
|
- Wastes output tokens and risks hallucinating unchanged parts
|
|
69
84
|
|
|
70
85
|
**Never**:
|
|
71
86
|
- 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
|
|
87
|
+
- Make multiple separate `edit` or `apply_patch` calls for the same file (use multiple hunks with @@ headers or multiple ops instead)
|
|
73
88
|
- Assume file content remains unchanged between operations
|
|
74
89
|
- Use `bash` with `sed`/`awk` for programmatic file editing (use `edit` instead)
|
|
75
90
|
|
|
@@ -33,9 +33,23 @@ call with multiple ops. Each separate `edit` operation re-reads the file fresh.
|
|
|
33
33
|
- Primary choice for targeted file edits - avoids rewriting entire files
|
|
34
34
|
- Only requires the specific lines you want to change
|
|
35
35
|
- Format: `*** Begin Patch` ... `*** Update File: path` ... `-old` / `+new` ... `*** End Patch`
|
|
36
|
+
- For multiple changes in one file: use multiple `@@` headers to separate non-consecutive hunks
|
|
37
|
+
- MUST include context lines (space prefix) - the `@@` line is just an optional hint
|
|
36
38
|
- Workflow: 1) Read file, 2) Create patch based on what you just read, 3) Apply patch
|
|
37
39
|
- The `-` lines in your patch MUST match exactly what's in the file character-for-character
|
|
38
40
|
- If patch fails, it means the file content doesn't match - read it again and retry
|
|
41
|
+
- **Best for**: Small, surgical edits to code files (< 50 line changes per file)
|
|
42
|
+
- **Struggles with**: Large restructures (> 50 lines), major section reorganizations
|
|
43
|
+
|
|
44
|
+
**Patch Format Reminder**:
|
|
45
|
+
```
|
|
46
|
+
*** Update File: path
|
|
47
|
+
@@ optional hint ← Optional comment/hint (not parsed)
|
|
48
|
+
actual line from file ← Context (space prefix) - REQUIRED
|
|
49
|
+
-line to remove ← Remove this line
|
|
50
|
+
+line to add ← Add this line
|
|
51
|
+
more context ← More context (space prefix)
|
|
52
|
+
```
|
|
39
53
|
|
|
40
54
|
**Using the `edit` Tool** (Alternative):
|
|
41
55
|
- Specify the file path and a list of operations
|
|
@@ -45,13 +59,14 @@ call with multiple ops. Each separate `edit` operation re-reads the file fresh.
|
|
|
45
59
|
- When making multiple changes to a file, use ONE `edit` call with multiple ops
|
|
46
60
|
|
|
47
61
|
**Using the `write` Tool** (Last Resort):
|
|
48
|
-
-
|
|
62
|
+
- Use for creating NEW files
|
|
63
|
+
- Use when replacing >70% of a file's content (almost complete rewrite)
|
|
49
64
|
- NEVER use for targeted edits - it rewrites the entire file
|
|
50
65
|
- Wastes output tokens and risks hallucinating unchanged parts
|
|
51
66
|
|
|
52
67
|
**Never**:
|
|
53
68
|
- 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
|
|
69
|
+
- Make multiple separate `edit` or `apply_patch` calls for the same file (use multiple hunks with @@ headers or multiple ops instead)
|
|
55
70
|
- Assume file content remains unchanged between operations
|
|
56
71
|
- Use `bash` with `sed`/`awk` for programmatic file editing (use `edit` instead)
|
|
57
72
|
|
|
@@ -77,9 +77,23 @@ Your toolset includes specialized file editing and search tools. Follow these gu
|
|
|
77
77
|
- Primary choice for targeted file edits - avoids rewriting entire files
|
|
78
78
|
- Only requires the specific lines you want to change
|
|
79
79
|
- Format: `*** Begin Patch` ... `*** Update File: path` ... `-old` / `+new` ... `*** End Patch`
|
|
80
|
+
- For multiple changes in one file: use multiple `@@` headers to separate non-consecutive hunks
|
|
81
|
+
- MUST include context lines (space prefix) - the `@@` line is just an optional hint
|
|
80
82
|
- Workflow: 1) Read file, 2) Create patch based on what you just read, 3) Apply patch
|
|
81
83
|
- The `-` lines in your patch MUST match exactly what's in the file character-for-character
|
|
82
84
|
- If patch fails, it means the file content doesn't match - read it again and retry
|
|
85
|
+
- **Best for**: Small, surgical edits to code files (< 50 line changes per file)
|
|
86
|
+
- **Struggles with**: Large restructures (> 50 lines), major section reorganizations
|
|
87
|
+
|
|
88
|
+
**Patch Format Reminder**:
|
|
89
|
+
```
|
|
90
|
+
*** Update File: path
|
|
91
|
+
@@ optional hint ← Optional comment/hint (not parsed)
|
|
92
|
+
actual line from file ← Context (space prefix) - REQUIRED
|
|
93
|
+
-line to remove ← Remove this line
|
|
94
|
+
+line to add ← Add this line
|
|
95
|
+
more context ← More context (space prefix)
|
|
96
|
+
```
|
|
83
97
|
|
|
84
98
|
**Using the `edit` Tool** (Alternative):
|
|
85
99
|
- Specify the file path and a list of operations
|
|
@@ -89,13 +103,14 @@ Your toolset includes specialized file editing and search tools. Follow these gu
|
|
|
89
103
|
- When making multiple changes to a file, use ONE `edit` call with multiple ops
|
|
90
104
|
|
|
91
105
|
**Using the `write` Tool** (Last Resort):
|
|
92
|
-
-
|
|
106
|
+
- Use for creating NEW files
|
|
107
|
+
- Use when replacing >70% of a file's content (almost complete rewrite)
|
|
93
108
|
- NEVER use for targeted edits - it rewrites the entire file
|
|
94
109
|
- Wastes output tokens and risks hallucinating unchanged parts
|
|
95
110
|
|
|
96
111
|
**Never**:
|
|
97
112
|
- 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
|
|
113
|
+
- Make multiple separate `edit` or `apply_patch` calls for the same file (use multiple hunks with @@ headers or multiple ops instead)
|
|
99
114
|
- Assume file content remains unchanged between operations
|
|
100
115
|
- Use `bash` with `sed`/`awk` for programmatic file editing (use `edit` instead)
|
|
101
116
|
|