Skip to content

Commit 955660c

Browse files
committed
Prompt updates
1 parent 538fedb commit 955660c

File tree

1 file changed

+54
-17
lines changed

1 file changed

+54
-17
lines changed

src/core/prompts/system.ts

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,60 @@ ${diffEnabled ? `
7171
## apply_diff
7272
Description: Apply a diff to a file at the specified path. The diff should be in unified format ('diff -U0') and can be used to apply changes to a file. This tool is useful when you need to make specific modifications to a file based on a set of changes provided in a diff.
7373
74-
- Make sure you include the first 2 lines with the file paths.
75-
- Don't include timestamps with the file paths.
76-
- Start each hunk of changes with a '@@ ... @@' line. Don't include line numbers like 'diff -U0' does. The user's patch tool doesn't need them.
77-
- The user's patch tool needs CORRECT patches that apply cleanly against the current contents of the file!
78-
- Think carefully and make sure you include and mark all lines that need to be removed or changed as '-' lines.
79-
- Make sure you mark all new or modified lines with '+'.
80-
- Don't leave out any lines or the diff patch won't apply correctly.
81-
- Indentation matters in the diffs!
82-
- Start a new hunk for each section of the file that needs changes.
83-
- Only output hunks that specify changes with '+' or '-' lines.
84-
- Skip any hunks that are entirely unchanging ' ' lines.
85-
- Output hunks in whatever order makes the most sense.
86-
- Hunks don't need to be in any particular order.
87-
- When editing a function, method, loop, etc use a hunk to replace the *entire* code block.
88-
- Delete the entire existing version with '-' lines and then add a new, updated version with '+' lines.
89-
- This will help you generate correct code and correct diffs.
90-
- To move code within a file, use 2 hunks: 1 to delete it from its current location, 1 to insert it in the new location.
74+
Diff Format Requirements:
75+
76+
1. Header (REQUIRED):
77+
\`\`\`
78+
--- path/to/original/file
79+
+++ path/to/modified/file
80+
\`\`\`
81+
- Must include both lines exactly as shown
82+
- Use actual file paths
83+
- NO timestamps after paths
84+
85+
2. Hunks:
86+
\`\`\`
87+
@@ -lineStart,lineCount +lineStart,lineCount @@
88+
-removed line
89+
+added line
90+
\`\`\`
91+
- Each hunk starts with @@ showing line numbers for changes
92+
- Format: @@ -originalStart,originalCount +newStart,newCount @@
93+
- Use - for removed/changed lines
94+
- Use + for new/modified lines
95+
- Indentation must match exactly
96+
97+
Complete Example:
98+
\`\`\`
99+
--- src/utils/helper.ts
100+
+++ src/utils/helper.ts
101+
@@ -10,3 +10,4 @@
102+
-function oldFunction(x: number): number {
103+
- return x + 1;
104+
-}
105+
+function newFunction(x: number): number {
106+
+ const result = x + 2;
107+
+ return result;
108+
+}
109+
\`\`\`
110+
111+
Common Pitfalls:
112+
1. Missing or incorrect header lines
113+
2. Incorrect line numbers in @@ lines
114+
3. Wrong indentation in changed lines
115+
4. Incomplete context (missing lines that need changing)
116+
5. Not marking all modified lines with - and +
117+
118+
Best Practices:
119+
1. Replace entire code blocks:
120+
- Remove complete old version with - lines
121+
- Add complete new version with + lines
122+
- Include correct line numbers
123+
2. Moving code requires two hunks:
124+
- First hunk: Remove from old location
125+
- Second hunk: Add to new location
126+
3. One hunk per logical change
127+
4. Verify line numbers match the file
91128
92129
Parameters:
93130
- path: (required) The path of the file to apply the diff to (relative to the current working directory ${cwd.toPosix()})

0 commit comments

Comments
 (0)