Skip to content

Commit 72c5c71

Browse files
committed
Improvements to apply_diff
1 parent c78216a commit 72c5c71

File tree

5 files changed

+53
-9
lines changed

5 files changed

+53
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Roo Cline Changelog
22

3+
## [2.1.14]
4+
5+
- Fix bug where diffs were not being applied correctly and try Aider's unified diff prompt
6+
37
## [2.1.13]
48

59
- Fix https://github.com/RooVetGit/Roo-Cline/issues/50 where sound effects were not respecting settings

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "Roo Cline",
44
"description": "A fork of Cline, an autonomous coding agent, with some added experimental configuration and automation features.",
55
"publisher": "RooVeterinaryInc",
6-
"version": "2.1.13",
6+
"version": "2.1.14",
77
"icon": "assets/icons/rocket.png",
88
"galleryBanner": {
99
"color": "#617A91",

src/core/Cline.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,11 +1231,32 @@ export class Cline {
12311231
break
12321232
}
12331233

1234-
await fs.writeFile(absolutePath, newContent)
1235-
await vscode.window.showTextDocument(vscode.Uri.file(absolutePath), { preview: false })
1234+
const { newProblemsMessage, userEdits, finalContent } =
1235+
await this.diffViewProvider.saveChanges()
1236+
this.didEditFile = true // used to determine if we should wait for busy terminal to update before sending api request
1237+
if (userEdits) {
1238+
await this.say(
1239+
"user_feedback_diff",
1240+
JSON.stringify({
1241+
tool: fileExists ? "editedExistingFile" : "newFileCreated",
1242+
path: getReadablePath(cwd, relPath),
1243+
diff: userEdits,
1244+
} satisfies ClineSayTool),
1245+
)
1246+
pushToolResult(
1247+
`The user made the following updates to your content:\n\n${userEdits}\n\n` +
1248+
`The updated content, which includes both your original modifications and the user's edits, has been successfully saved to ${relPath.toPosix()}. Here is the full, updated content of the file:\n\n` +
1249+
`<final_file_content path="${relPath.toPosix()}">\n${finalContent}\n</final_file_content>\n\n` +
1250+
`Please note:\n` +
1251+
`1. You do not need to re-write the file with these changes, as they have already been applied.\n` +
1252+
`2. Proceed with the task using this updated file content as the new baseline.\n` +
1253+
`3. If the user's edits have addressed part of the task or changed the requirements, adjust your approach accordingly.` +
1254+
`${newProblemsMessage}`,
1255+
)
1256+
} else {
1257+
pushToolResult(`Changes successfully applied to ${relPath.toPosix()}:\n\n${newProblemsMessage}`)
1258+
}
12361259
await this.diffViewProvider.reset()
1237-
1238-
pushToolResult(`Changes successfully applied to ${relPath.toPosix()}:\n\n${diffRepresentation}`)
12391260
break
12401261
}
12411262
} catch (error) {

src/core/prompts/system.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,29 @@ Your file content here
6969
7070
${diffEnabled ? `
7171
## apply_diff
72-
Description: Apply a diff to a file at the specified path. The diff should be in unified format (diff -u) 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.
72+
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.
73+
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.
91+
7392
Parameters:
7493
- path: (required) The path of the file to apply the diff to (relative to the current working directory ${cwd.toPosix()})
75-
- diff: (required) The diff in unified format (diff -u) to apply to the file.
94+
- diff: (required) The diff in unified format (diff -U0) to apply to the file.
7695
Usage:
7796
<apply_diff>
7897
<path>File path here</path>

0 commit comments

Comments
 (0)