Skip to content

Commit e36d2e3

Browse files
authored
Merge pull request #1150 from RooVetGit/revert_tool_changes
Revert "Merge pull request #1125 from hannesrudolph/change_order_appl…
2 parents 645d069 + 08aa911 commit e36d2e3

File tree

24 files changed

+269
-274
lines changed

24 files changed

+269
-274
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ Join us at https://www.reddit.com/r/RooCode to share your custom modes and be pa
479479
## [2.1.14]
480480

481481
- Fix bug where diffs were not being applied correctly and try Aider's [unified diff prompt](https://github.com/Aider-AI/aider/blob/3995accd0ca71cea90ef76d516837f8c2731b9fe/aider/coders/udiff_prompts.py#L75-L105)
482-
- If diffs are enabled, automatically reject create_file commands that lead to truncated output
482+
- If diffs are enabled, automatically reject write_to_file commands that lead to truncated output
483483

484484
## [2.1.13]
485485

src/core/Cline.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ export class Cline {
733733
text:
734734
`[TASK RESUMPTION] This task was interrupted ${agoText}. It may or may not be complete, so please reassess the task context. Be aware that the project state may have changed since then. The current working directory is now '${cwd.toPosix()}'. If the task has not been completed, retry the last step before interruption and proceed with completing the task.\n\nNote: If you previously attempted a tool use that the user did not provide a result for, you should assume the tool use was not successful and assess whether you should retry. If the last tool was a browser_action, the browser has been closed and you must launch a new browser if needed.${
735735
wasRecent
736-
? "\n\nIMPORTANT: If the last tool use was a create_file that was interrupted, the file was reverted back to its original state before the interrupted edit, and you do NOT need to re-read the file as you already have its up-to-date contents."
736+
? "\n\nIMPORTANT: If the last tool use was a write_to_file that was interrupted, the file was reverted back to its original state before the interrupted edit, and you do NOT need to re-read the file as you already have its up-to-date contents."
737737
: ""
738738
}` +
739739
(responseText
@@ -1141,9 +1141,9 @@ export class Cline {
11411141
return `[${block.name} for '${block.params.command}']`
11421142
case "read_file":
11431143
return `[${block.name} for '${block.params.path}']`
1144-
case "create_file":
1144+
case "write_to_file":
11451145
return `[${block.name} for '${block.params.path}']`
1146-
case "edit_file":
1146+
case "apply_diff":
11471147
return `[${block.name} for '${block.params.path}']`
11481148
case "search_files":
11491149
return `[${block.name} for '${block.params.regex}'${
@@ -1295,7 +1295,7 @@ export class Cline {
12951295
mode ?? defaultModeSlug,
12961296
customModes ?? [],
12971297
{
1298-
edit_file: this.diffEnabled,
1298+
apply_diff: this.diffEnabled,
12991299
},
13001300
block.params,
13011301
)
@@ -1306,7 +1306,7 @@ export class Cline {
13061306
}
13071307

13081308
switch (block.name) {
1309-
case "create_file": {
1309+
case "write_to_file": {
13101310
const relPath: string | undefined = block.params.path
13111311
let newContent: string | undefined = block.params.content
13121312
let predictedLineCount: number | undefined = parseInt(block.params.line_count ?? "0")
@@ -1371,20 +1371,20 @@ export class Cline {
13711371
} else {
13721372
if (!relPath) {
13731373
this.consecutiveMistakeCount++
1374-
pushToolResult(await this.sayAndCreateMissingParamError("create_file", "path"))
1374+
pushToolResult(await this.sayAndCreateMissingParamError("write_to_file", "path"))
13751375
await this.diffViewProvider.reset()
13761376
break
13771377
}
13781378
if (!newContent) {
13791379
this.consecutiveMistakeCount++
1380-
pushToolResult(await this.sayAndCreateMissingParamError("create_file", "content"))
1380+
pushToolResult(await this.sayAndCreateMissingParamError("write_to_file", "content"))
13811381
await this.diffViewProvider.reset()
13821382
break
13831383
}
13841384
if (!predictedLineCount) {
13851385
this.consecutiveMistakeCount++
13861386
pushToolResult(
1387-
await this.sayAndCreateMissingParamError("create_file", "line_count"),
1387+
await this.sayAndCreateMissingParamError("write_to_file", "line_count"),
13881388
)
13891389
await this.diffViewProvider.reset()
13901390
break
@@ -1421,7 +1421,7 @@ export class Cline {
14211421
formatResponse.toolError(
14221422
`Content appears to be truncated (file has ${
14231423
newContent.split("\n").length
1424-
} 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.`,
1424+
} 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.`,
14251425
),
14261426
)
14271427
break
@@ -1497,7 +1497,7 @@ export class Cline {
14971497
break
14981498
}
14991499
}
1500-
case "edit_file": {
1500+
case "apply_diff": {
15011501
const relPath: string | undefined = block.params.path
15021502
const diffContent: string | undefined = block.params.diff
15031503

@@ -1515,12 +1515,12 @@ export class Cline {
15151515
} else {
15161516
if (!relPath) {
15171517
this.consecutiveMistakeCount++
1518-
pushToolResult(await this.sayAndCreateMissingParamError("edit_file", "path"))
1518+
pushToolResult(await this.sayAndCreateMissingParamError("apply_diff", "path"))
15191519
break
15201520
}
15211521
if (!diffContent) {
15221522
this.consecutiveMistakeCount++
1523-
pushToolResult(await this.sayAndCreateMissingParamError("edit_file", "diff"))
1523+
pushToolResult(await this.sayAndCreateMissingParamError("apply_diff", "diff"))
15241524
break
15251525
}
15261526

@@ -2233,7 +2233,7 @@ export class Cline {
22332233
formatResponse.toolResult(
22342234
`The browser action has been executed. The console logs and screenshot have been captured for your analysis.\n\nConsole logs:\n${
22352235
browserActionResult.logs || "(No new logs)"
2236-
}\n\n(REMEMBER: if you need to proceed to using non-\`browser_action\` tools or launch a new browser, you MUST first close this browser. For example, if after analyzing the logs and screenshot you need to edit a file, you must first close the browser before you can use the create_file tool.)`,
2236+
}\n\n(REMEMBER: if you need to proceed to using non-\`browser_action\` tools or launch a new browser, you MUST first close this browser. For example, if after analyzing the logs and screenshot you need to edit a file, you must first close the browser before you can use the write_to_file tool.)`,
22372237
browserActionResult.screenshot ? [browserActionResult.screenshot] : [],
22382238
),
22392239
)
@@ -2750,7 +2750,7 @@ export class Cline {
27502750

27512751
/*
27522752
Seeing out of bounds is fine, it means that the next too call is being built up and ready to add to assistantMessageContent to present.
2753-
When you see the UI inactive during this, it means that a tool is breaking without presenting any UI. For example the create_file tool was breaking when relpath was undefined, and for invalid relpath it never presented UI.
2753+
When you see the UI inactive during this, it means that a tool is breaking without presenting any UI. For example the write_to_file tool was breaking when relpath was undefined, and for invalid relpath it never presented UI.
27542754
*/
27552755
this.presentAssistantMessageLocked = false // this needs to be placed here, if not then calling this.presentAssistantMessage below would fail (sometimes) since it's locked
27562756
// NOTE: when tool is rejected, iterator stream is interrupted and it waits for userMessageContentReady to be true. Future calls to present will skip execution since didRejectTool and iterate until contentIndex is set to message length and it sets userMessageContentReady to true itself (instead of preemptively doing it in iterator)
@@ -3300,10 +3300,10 @@ export class Cline {
33003300

33013301
// Add warning if not in code mode
33023302
if (
3303-
!isToolAllowedForMode("create_file", currentMode, customModes ?? [], {
3304-
edit_file: this.diffEnabled,
3303+
!isToolAllowedForMode("write_to_file", currentMode, customModes ?? [], {
3304+
apply_diff: this.diffEnabled,
33053305
}) &&
3306-
!isToolAllowedForMode("edit_file", currentMode, customModes ?? [], { edit_file: this.diffEnabled })
3306+
!isToolAllowedForMode("apply_diff", currentMode, customModes ?? [], { apply_diff: this.diffEnabled })
33073307
) {
33083308
const currentModeName = getModeBySlug(currentMode, customModes)?.name ?? currentMode
33093309
const defaultModeName = getModeBySlug(defaultModeSlug, customModes)?.name ?? defaultModeSlug

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe("mode-validator", () => {
5959
]
6060
// Should allow tools from read and edit groups
6161
expect(isToolAllowedForMode("read_file", "custom-mode", customModes)).toBe(true)
62-
expect(isToolAllowedForMode("create_file", "custom-mode", customModes)).toBe(true)
62+
expect(isToolAllowedForMode("write_to_file", "custom-mode", customModes)).toBe(true)
6363
// Should not allow tools from other groups
6464
expect(isToolAllowedForMode("execute_command", "custom-mode", customModes)).toBe(false)
6565
})
@@ -76,7 +76,7 @@ describe("mode-validator", () => {
7676
// Should allow tools from read group
7777
expect(isToolAllowedForMode("read_file", codeMode, customModes)).toBe(true)
7878
// Should not allow tools from other groups
79-
expect(isToolAllowedForMode("create_file", codeMode, customModes)).toBe(false)
79+
expect(isToolAllowedForMode("write_to_file", codeMode, customModes)).toBe(false)
8080
})
8181

8282
it("respects tool requirements in custom modes", () => {
@@ -88,39 +88,39 @@ describe("mode-validator", () => {
8888
groups: ["edit"] as const,
8989
},
9090
]
91-
const requirements = { edit_file: false }
91+
const requirements = { apply_diff: false }
9292

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

9696
// Should allow other edit tools
97-
expect(isToolAllowedForMode("create_file", "custom-mode", customModes, requirements)).toBe(true)
97+
expect(isToolAllowedForMode("write_to_file", "custom-mode", customModes, requirements)).toBe(true)
9898
})
9999
})
100100

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

106-
const enabledRequirements = { edit_file: true }
107-
expect(isToolAllowedForMode("edit_file", codeMode, [], enabledRequirements)).toBe(true)
106+
const enabledRequirements = { apply_diff: true }
107+
expect(isToolAllowedForMode("apply_diff", 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("edit_file", codeMode, [], requirements)).toBe(true)
112+
expect(isToolAllowedForMode("apply_diff", codeMode, [], requirements)).toBe(true)
113113
})
114114

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

120120
it("prioritizes requirements over mode configuration", () => {
121-
const requirements = { edit_file: false }
121+
const requirements = { apply_diff: false }
122122
// Even in code mode which allows all tools, disabled requirement should take precedence
123-
expect(isToolAllowedForMode("edit_file", codeMode, [], requirements)).toBe(false)
123+
expect(isToolAllowedForMode("apply_diff", 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 = { edit_file: false }
141-
expect(() => validateToolUse("edit_file", codeMode, [], requirements)).toThrow(
142-
'Tool "edit_file" is not allowed in code mode.',
140+
const requirements = { apply_diff: false }
141+
expect(() => validateToolUse("apply_diff", codeMode, [], requirements)).toThrow(
142+
'Tool "apply_diff" is not allowed in code mode.',
143143
)
144144
})
145145

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

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

src/core/assistant-message/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export interface TextContent {
1111
export const toolUseNames = [
1212
"execute_command",
1313
"read_file",
14-
"create_file",
15-
"edit_file",
14+
"write_to_file",
15+
"apply_diff",
1616
"insert_content",
1717
"search_and_replace",
1818
"search_files",
@@ -80,7 +80,7 @@ export interface ReadFileToolUse extends ToolUse {
8080
}
8181

8282
export interface WriteToFileToolUse extends ToolUse {
83-
name: "create_file"
83+
name: "write_to_file"
8484
params: Partial<Pick<Record<ToolParamName, string>, "path" | "content" | "line_count">>
8585
}
8686

src/core/assistant-message/parse-assistant-message.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ export function parseAssistantMessage(assistantMessage: string) {
6161

6262
// there's no current param, and not starting a new param
6363

64-
// special case for create_file where file contents could contain the closing tag, in which case the param would have closed and we end up with the rest of the file contents here. To work around this, we get the string between the starting content tag and the LAST content tag.
64+
// special case for write_to_file where file contents could contain the closing tag, in which case the param would have closed and we end up with the rest of the file contents here. To work around this, we get the string between the starting content tag and the LAST content tag.
6565
const contentParamName: ToolParamName = "content"
66-
if (currentToolUse.name === "create_file" && accumulator.endsWith(`</${contentParamName}>`)) {
66+
if (currentToolUse.name === "write_to_file" && accumulator.endsWith(`</${contentParamName}>`)) {
6767
const toolContent = accumulator.slice(currentToolUseStartIndex)
6868
const contentStartTag = `<${contentParamName}>`
6969
const contentEndTag = `</${contentParamName}>`

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("edit_file Tool - Generate Precise Code Changes")
32+
expect(description).toContain("apply_diff 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("<edit_file>")
1548-
expect(description).toContain("</edit_file>")
1547+
expect(description).toContain("<apply_diff>")
1548+
expect(description).toContain("</apply_diff>")
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("edit_file")
15+
expect(description).toContain("apply_diff")
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 `# edit_file Tool - Generate Precise Code Changes
111+
return `# apply_diff 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-
<edit_file>
171+
<apply_diff>
172172
<path>path/to/file.ext</path>
173173
<diff>
174174
Your diff here
175175
</diff>
176-
</edit_file>`
176+
</apply_diff>`
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 `## edit_file
43+
return `## apply_diff
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-
<edit_file>
94+
<apply_diff>
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-
</edit_file>`
101+
</apply_diff>`
102102
}
103103

104104
async applyDiff(

0 commit comments

Comments
 (0)