Skip to content

Commit

Permalink
Supports updating multiple locations of a file in one call of the app…
Browse files Browse the repository at this point in the history
…ly_diff tool
  • Loading branch information
axb committed Feb 27, 2025
1 parent 931af8f commit b2d4caa
Show file tree
Hide file tree
Showing 3 changed files with 264 additions and 176 deletions.
39 changes: 32 additions & 7 deletions src/core/Cline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1555,17 +1555,36 @@ export class Cline {
success: false,
error: "No diff strategy available",
}
let partResults = ""

if (!diffResult.success) {
this.consecutiveMistakeCount++
const currentCount =
(this.consecutiveMistakeCountForApplyDiff.get(relPath) || 0) + 1
this.consecutiveMistakeCountForApplyDiff.set(relPath, currentCount)
const errorDetails = diffResult.details
? JSON.stringify(diffResult.details, null, 2)
: ""
const formattedError = `Unable to apply diff to file: ${absolutePath}\n\n<error_details>\n${
diffResult.error
}${errorDetails ? `\n\nDetails:\n${errorDetails}` : ""}\n</error_details>`
let formattedError = ""
if (diffResult.failParts && diffResult.failParts.length > 0) {
for (const failPart of diffResult.failParts) {
if (failPart.success) {
continue
}
const errorDetails = failPart.details
? JSON.stringify(failPart.details, null, 2)
: ""
formattedError = `<error_details>\n${
failPart.error
}${errorDetails ? `\n\nDetails:\n${errorDetails}` : ""}\n</error_details>`
partResults += formattedError
}
} else {
const errorDetails = diffResult.details
? JSON.stringify(diffResult.details, null, 2)
: ""
formattedError = `Unable to apply diff to file: ${absolutePath}\n\n<error_details>\n${
diffResult.error
}${errorDetails ? `\n\nDetails:\n${errorDetails}` : ""}\n</error_details>`
}

if (currentCount >= 2) {
await this.say("error", formattedError)
}
Expand Down Expand Up @@ -1595,6 +1614,10 @@ export class Cline {
const { newProblemsMessage, userEdits, finalContent } =
await this.diffViewProvider.saveChanges()
this.didEditFile = true // used to determine if we should wait for busy terminal to update before sending api request
let partFailHint = ""
if (diffResult.failParts && diffResult.failParts.length > 0) {
partFailHint = `Unable to apply all diff parts to file: ${absolutePath}, use <read_file> tool to check newest file version and re-apply diffs\n`
}
if (userEdits) {
await this.say(
"user_feedback_diff",
Expand All @@ -1606,6 +1629,7 @@ export class Cline {
)
pushToolResult(
`The user made the following updates to your content:\n\n${userEdits}\n\n` +
partFailHint +
`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, including line numbers:\n\n` +
`<final_file_content path="${relPath.toPosix()}">\n${addLineNumbers(
finalContent || "",
Expand All @@ -1618,7 +1642,8 @@ export class Cline {
)
} else {
pushToolResult(
`Changes successfully applied to ${relPath.toPosix()}:\n\n${newProblemsMessage}`,
`Changes successfully applied to ${relPath.toPosix()}:\n\n${newProblemsMessage}\n` +
partFailHint,
)
}
await this.diffViewProvider.reset()
Expand Down
Loading

0 comments on commit b2d4caa

Please sign in to comment.