Skip to content

Commit e134e54

Browse files
author
Roo Code
committed
Rename 'apply_diff' tool to 'edit_file' across codebase
1 parent 24d5280 commit e134e54

File tree

21 files changed

+74
-74
lines changed

21 files changed

+74
-74
lines changed

src/core/Cline.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ export class Cline {
11041104
return `[${block.name} for '${block.params.path}']`
11051105
case "write_to_file":
11061106
return `[${block.name} for '${block.params.path}']`
1107-
case "apply_diff":
1107+
case "edit_file":
11081108
return `[${block.name} for '${block.params.path}']`
11091109
case "search_files":
11101110
return `[${block.name} for '${block.params.regex}'${
@@ -1256,7 +1256,7 @@ export class Cline {
12561256
mode ?? defaultModeSlug,
12571257
customModes ?? [],
12581258
{
1259-
apply_diff: this.diffEnabled,
1259+
edit_file: this.diffEnabled,
12601260
},
12611261
block.params,
12621262
)
@@ -1382,7 +1382,7 @@ export class Cline {
13821382
formatResponse.toolError(
13831383
`Content appears to be truncated (file has ${
13841384
newContent.split("\n").length
1385-
} lines but was predicted to have ${predictedLineCount} lines), and found comments indicating omitted code (e.g., '// rest of code unchanged', '/* previous code */'). Please provide the complete file content without any omissions if possible, or otherwise use the 'apply_diff' tool to apply the diff to the original file.`,
1385+
} lines but was predicted to have ${predictedLineCount} lines), and found comments indicating omitted code (e.g., '// rest of code unchanged', '/* previous code */'). Please provide the complete file content without any omissions if possible, or otherwise use the 'edit_file' tool to apply the diff to the original file.`,
13861386
),
13871387
)
13881388
break
@@ -1458,7 +1458,7 @@ export class Cline {
14581458
break
14591459
}
14601460
}
1461-
case "apply_diff": {
1461+
case "edit_file": {
14621462
const relPath: string | undefined = block.params.path
14631463
const diffContent: string | undefined = block.params.diff
14641464

@@ -1476,12 +1476,12 @@ export class Cline {
14761476
} else {
14771477
if (!relPath) {
14781478
this.consecutiveMistakeCount++
1479-
pushToolResult(await this.sayAndCreateMissingParamError("apply_diff", "path"))
1479+
pushToolResult(await this.sayAndCreateMissingParamError("edit_file", "path"))
14801480
break
14811481
}
14821482
if (!diffContent) {
14831483
this.consecutiveMistakeCount++
1484-
pushToolResult(await this.sayAndCreateMissingParamError("apply_diff", "diff"))
1484+
pushToolResult(await this.sayAndCreateMissingParamError("edit_file", "diff"))
14851485
break
14861486
}
14871487

@@ -3262,9 +3262,9 @@ export class Cline {
32623262
// Add warning if not in code mode
32633263
if (
32643264
!isToolAllowedForMode("write_to_file", currentMode, customModes ?? [], {
3265-
apply_diff: this.diffEnabled,
3265+
edit_file: this.diffEnabled,
32663266
}) &&
3267-
!isToolAllowedForMode("apply_diff", currentMode, customModes ?? [], { apply_diff: this.diffEnabled })
3267+
!isToolAllowedForMode("edit_file", currentMode, customModes ?? [], { edit_file: this.diffEnabled })
32683268
) {
32693269
const currentModeName = getModeBySlug(currentMode, customModes)?.name ?? currentMode
32703270
const defaultModeName = getModeBySlug(defaultModeSlug, customModes)?.name ?? defaultModeSlug

src/core/__tests__/mode-validator.test.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ describe("mode-validator", () => {
8888
groups: ["edit"] as const,
8989
},
9090
]
91-
const requirements = { apply_diff: false }
91+
const requirements = { edit_file: false }
9292

9393
// Should respect disabled requirement even if tool group is allowed
94-
expect(isToolAllowedForMode("apply_diff", "custom-mode", customModes, requirements)).toBe(false)
94+
expect(isToolAllowedForMode("edit_file", "custom-mode", customModes, requirements)).toBe(false)
9595

9696
// Should allow other edit tools
9797
expect(isToolAllowedForMode("write_to_file", "custom-mode", customModes, requirements)).toBe(true)
@@ -100,27 +100,27 @@ describe("mode-validator", () => {
100100

101101
describe("tool requirements", () => {
102102
it("respects tool requirements when provided", () => {
103-
const requirements = { apply_diff: false }
104-
expect(isToolAllowedForMode("apply_diff", codeMode, [], requirements)).toBe(false)
103+
const requirements = { edit_file: false }
104+
expect(isToolAllowedForMode("edit_file", codeMode, [], requirements)).toBe(false)
105105

106-
const enabledRequirements = { apply_diff: true }
107-
expect(isToolAllowedForMode("apply_diff", codeMode, [], enabledRequirements)).toBe(true)
106+
const enabledRequirements = { edit_file: true }
107+
expect(isToolAllowedForMode("edit_file", codeMode, [], enabledRequirements)).toBe(true)
108108
})
109109

110110
it("allows tools when their requirements are not specified", () => {
111111
const requirements = { some_other_tool: true }
112-
expect(isToolAllowedForMode("apply_diff", codeMode, [], requirements)).toBe(true)
112+
expect(isToolAllowedForMode("edit_file", codeMode, [], requirements)).toBe(true)
113113
})
114114

115115
it("handles undefined and empty requirements", () => {
116-
expect(isToolAllowedForMode("apply_diff", codeMode, [], undefined)).toBe(true)
117-
expect(isToolAllowedForMode("apply_diff", codeMode, [], {})).toBe(true)
116+
expect(isToolAllowedForMode("edit_file", codeMode, [], undefined)).toBe(true)
117+
expect(isToolAllowedForMode("edit_file", codeMode, [], {})).toBe(true)
118118
})
119119

120120
it("prioritizes requirements over mode configuration", () => {
121-
const requirements = { apply_diff: false }
121+
const requirements = { edit_file: false }
122122
// Even in code mode which allows all tools, disabled requirement should take precedence
123-
expect(isToolAllowedForMode("apply_diff", codeMode, [], requirements)).toBe(false)
123+
expect(isToolAllowedForMode("edit_file", codeMode, [], requirements)).toBe(false)
124124
})
125125
})
126126
})
@@ -137,19 +137,19 @@ describe("mode-validator", () => {
137137
})
138138

139139
it("throws error when tool requirement is not met", () => {
140-
const requirements = { apply_diff: false }
141-
expect(() => validateToolUse("apply_diff", codeMode, [], requirements)).toThrow(
142-
'Tool "apply_diff" is not allowed in code mode.',
140+
const requirements = { edit_file: false }
141+
expect(() => validateToolUse("edit_file", codeMode, [], requirements)).toThrow(
142+
'Tool "edit_file" is not allowed in code mode.',
143143
)
144144
})
145145

146146
it("does not throw when tool requirement is met", () => {
147-
const requirements = { apply_diff: true }
148-
expect(() => validateToolUse("apply_diff", codeMode, [], requirements)).not.toThrow()
147+
const requirements = { edit_file: true }
148+
expect(() => validateToolUse("edit_file", codeMode, [], requirements)).not.toThrow()
149149
})
150150

151151
it("handles undefined requirements gracefully", () => {
152-
expect(() => validateToolUse("apply_diff", codeMode, [], undefined)).not.toThrow()
152+
expect(() => validateToolUse("edit_file", codeMode, [], undefined)).not.toThrow()
153153
})
154154
})
155155
})

src/core/assistant-message/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const toolUseNames = [
1212
"execute_command",
1313
"read_file",
1414
"write_to_file",
15-
"apply_diff",
15+
"edit_file",
1616
"insert_content",
1717
"search_and_replace",
1818
"search_files",

src/core/diff/strategies/__tests__/new-unified.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe("main", () => {
2929
const cwd = "/test/path"
3030
const description = strategy.getToolDescription({ cwd })
3131

32-
expect(description).toContain("apply_diff Tool - Generate Precise Code Changes")
32+
expect(description).toContain("edit_file Tool - Generate Precise Code Changes")
3333
expect(description).toContain(cwd)
3434
expect(description).toContain("Step-by-Step Instructions")
3535
expect(description).toContain("Requirements")

src/core/diff/strategies/__tests__/search-replace.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,8 +1544,8 @@ function two() {
15441544
expect(description).toContain("<<<<<<< SEARCH")
15451545
expect(description).toContain("=======")
15461546
expect(description).toContain(">>>>>>> REPLACE")
1547-
expect(description).toContain("<apply_diff>")
1548-
expect(description).toContain("</apply_diff>")
1547+
expect(description).toContain("<edit_file>")
1548+
expect(description).toContain("</edit_file>")
15491549
})
15501550

15511551
it("should document start_line and end_line parameters", async () => {

src/core/diff/strategies/__tests__/unified.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe("UnifiedDiffStrategy", () => {
1212
const cwd = "/test/path"
1313
const description = strategy.getToolDescription({ cwd })
1414

15-
expect(description).toContain("apply_diff")
15+
expect(description).toContain("edit_file")
1616
expect(description).toContain(cwd)
1717
expect(description).toContain("Parameters:")
1818
expect(description).toContain("Format Requirements:")

src/core/diff/strategies/new-unified/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export class NewUnifiedDiffStrategy implements DiffStrategy {
108108
}
109109

110110
getToolDescription(args: { cwd: string; toolOptions?: { [key: string]: string } }): string {
111-
return `# apply_diff Tool - Generate Precise Code Changes
111+
return `# edit_file Tool - Generate Precise Code Changes
112112
113113
Generate a unified diff that can be cleanly applied to modify code files.
114114
@@ -168,12 +168,12 @@ Parameters:
168168
- diff: (required) Unified diff content in unified format to apply to the file.
169169
170170
Usage:
171-
<apply_diff>
171+
<edit_file>
172172
<path>path/to/file.ext</path>
173173
<diff>
174174
Your diff here
175175
</diff>
176-
</apply_diff>`
176+
</edit_file>`
177177
}
178178

179179
// Helper function to split a hunk into smaller hunks based on contiguous changes

src/core/diff/strategies/search-replace.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class SearchReplaceDiffStrategy implements DiffStrategy {
4040
}
4141

4242
getToolDescription(args: { cwd: string; toolOptions?: { [key: string]: string } }): string {
43-
return `## apply_diff
43+
return `## edit_file
4444
Description: Request to replace existing code using a search and replace block.
4545
This tool allows for precise, surgical replaces to files by specifying exactly what content to search for and what to replace it with.
4646
The tool will maintain proper indentation and formatting while making changes.
@@ -91,14 +91,14 @@ def calculate_total(items):
9191
\`\`\`
9292
9393
Usage:
94-
<apply_diff>
94+
<edit_file>
9595
<path>File path here</path>
9696
<diff>
9797
Your search/replace content here
9898
</diff>
9999
<start_line>1</start_line>
100100
<end_line>5</end_line>
101-
</apply_diff>`
101+
</edit_file>`
102102
}
103103

104104
async applyDiff(

src/core/diff/strategies/unified.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { DiffStrategy, DiffResult } from "../types"
33

44
export class UnifiedDiffStrategy implements DiffStrategy {
55
getToolDescription(args: { cwd: string; toolOptions?: { [key: string]: string } }): string {
6-
return `## apply_diff
6+
return `## edit_file
77
Description: Apply a unified diff to a file at the specified path. This tool is useful when you need to make specific modifications to a file based on a set of changes provided in unified diff format (diff -U3).
88
99
Parameters:
@@ -100,12 +100,12 @@ Best Practices:
100100
4. Verify line numbers match the line numbers you have in the file
101101
102102
Usage:
103-
<apply_diff>
103+
<edit_file>
104104
<path>File path here</path>
105105
<diff>
106106
Your diff here
107107
</diff>
108-
</apply_diff>`
108+
</edit_file>`
109109
}
110110

111111
async applyDiff(originalContent: string, diffContent: string): Promise<DiffResult> {

src/core/prompts/__tests__/__snapshots__/system.test.ts.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2580,7 +2580,7 @@ Example: Requesting to write to frontend-config.json
25802580
<line_count>14</line_count>
25812581
</write_to_file>
25822582
2583-
## apply_diff
2583+
## edit_file
25842584
Description: Request to replace existing code using a search and replace block.
25852585
This tool allows for precise, surgical replaces to files by specifying exactly what content to search for and what to replace it with.
25862586
The tool will maintain proper indentation and formatting while making changes.
@@ -2631,14 +2631,14 @@ def calculate_total(items):
26312631
\`\`\`
26322632
26332633
Usage:
2634-
<apply_diff>
2634+
<edit_file>
26352635
<path>File path here</path>
26362636
<diff>
26372637
Your search/replace content here
26382638
</diff>
26392639
<start_line>1</start_line>
26402640
<end_line>5</end_line>
2641-
</apply_diff>
2641+
</edit_file>
26422642
26432643
## execute_command
26442644
Description: Request to execute a CLI command on the system. Use this when you need to perform system operations or run specific commands to accomplish any step in the user's task. You must tailor your command to the user's system and provide a clear explanation of what the command does. For command chaining, use the appropriate chaining syntax for the user's shell. Prefer to execute complex CLI commands over creating executable scripts, as they are more flexible and easier to run. Commands will be executed in the current working directory: /test/path
@@ -2758,7 +2758,7 @@ CAPABILITIES
27582758
- When the user initially gives you a task, a recursive list of all filepaths in the current working directory ('/test/path') will be included in environment_details. This provides an overview of the project's file structure, offering key insights into the project from directory/file names (how developers conceptualize and organize their code) and file extensions (the language used). This can also guide decision-making on which files to explore further. If you need to further explore directories such as outside the current working directory, you can use the list_files tool. If you pass 'true' for the recursive parameter, it will list files recursively. Otherwise, it will list files at the top level, which is better suited for generic directories where you don't necessarily need the nested structure, like the Desktop.
27592759
- You can use search_files to perform regex searches across files in a specified directory, outputting context-rich results that include surrounding lines. This is particularly useful for understanding code patterns, finding specific implementations, or identifying areas that need refactoring.
27602760
- You can use the list_code_definition_names tool to get an overview of source code definitions for all files at the top level of a specified directory. This can be particularly useful when you need to understand the broader context and relationships between certain parts of the code. You may need to call this tool multiple times to understand various parts of the codebase related to the task.
2761-
- For example, when asked to make edits or improvements you might analyze the file structure in the initial environment_details to get an overview of the project, then use list_code_definition_names to get further insight using source code definitions for files located in relevant directories, then read_file to examine the contents of relevant files, analyze the code and suggest improvements or make necessary edits, then use the write_to_file or apply_diff tool to apply the changes. If you refactored code that could affect other parts of the codebase, you could use search_files to ensure you update other files as needed.
2761+
- For example, when asked to make edits or improvements you might analyze the file structure in the initial environment_details to get an overview of the project, then use list_code_definition_names to get further insight using source code definitions for files located in relevant directories, then read_file to examine the contents of relevant files, analyze the code and suggest improvements or make necessary edits, then use the write_to_file or edit_file tool to apply the changes. If you refactored code that could affect other parts of the codebase, you could use search_files to ensure you update other files as needed.
27622762
- You can use the execute_command tool to run commands on the user's computer whenever you feel it can help accomplish the user's task. When you need to execute a CLI command, you must provide a clear explanation of what the command does. Prefer to execute complex CLI commands over creating executable scripts, since they are more flexible and easier to run. Interactive and long-running commands are allowed, since the commands are run in the user's VSCode terminal. The user may keep commands running in the background and you will be kept updated on their status along the way. Each command you execute is run in a new terminal instance.
27632763
27642764
====
@@ -2777,7 +2777,7 @@ RULES
27772777
- Before using the execute_command tool, you must first think about the SYSTEM INFORMATION context provided to understand the user's environment and tailor your commands to ensure they are compatible with their system. You must also consider if the command you need to run should be executed in a specific directory outside of the current working directory '/test/path', and if so prepend with \`cd\`'ing into that directory && then executing the command (as one command since you are stuck operating from '/test/path'). For example, if you needed to run \`npm install\` in a project outside of '/test/path', you would need to prepend with a \`cd\` i.e. pseudocode for this would be \`cd (path to project) && (command, in this case npm install)\`.
27782778
- When using the search_files tool, craft your regex patterns carefully to balance specificity and flexibility. Based on the user's task you may use it to find code patterns, TODO comments, function definitions, or any text-based information across the project. The results include context, so analyze the surrounding code to better understand the matches. Leverage the search_files tool in combination with other tools for more comprehensive analysis. For example, use it to find specific code patterns, then use read_file to examine the full context of interesting matches before using write_to_file to make informed changes.
27792779
- When creating a new project (such as an app, website, or any software project), organize all new files within a dedicated project directory unless the user specifies otherwise. Use appropriate file paths when writing files, as the write_to_file tool will automatically create any necessary directories. Structure the project logically, adhering to best practices for the specific type of project being created. Unless otherwise specified, new projects should be easily run without additional setup, for example most projects can be built in HTML, CSS, and JavaScript - which you can open in a browser.
2780-
- For editing files, you have access to these tools: write_to_file (for creating new files or complete file rewrites), apply_diff (for replacing lines in existing files).
2780+
- For editing files, you have access to these tools: write_to_file (for creating new files or complete file rewrites), edit_file (for replacing lines in existing files).
27812781
- When using the write_to_file tool to modify a file, use the tool directly with the desired content. You do not need to display the content before using the tool. ALWAYS provide the COMPLETE file content in your response. This is NON-NEGOTIABLE. Partial updates or placeholders like '// rest of code unchanged' are STRICTLY FORBIDDEN. You MUST include ALL parts of the file, even if they haven't been modified. Failure to do so will result in incomplete or broken code, severely impacting the user's project.
27822782
- You should always prefer using other editing tools over write_to_file when making changes to existing files since write_to_file is much slower and cannot handle large files.
27832783
- Some modes have restrictions on which files they can edit. If you attempt to edit a restricted file, the operation will be rejected with a FileRestrictionError that will specify which file patterns are allowed for the current mode.

0 commit comments

Comments
 (0)