Skip to content

Commit 6225994

Browse files
author
Roo Code
committed
Rename 'write_to_file' tool to 'create_file' across codebase and fixed tests
1 parent e134e54 commit 6225994

File tree

17 files changed

+215
-215
lines changed

17 files changed

+215
-215
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 write_to_file commands that lead to truncated output
482+
- If diffs are enabled, automatically reject create_file commands that lead to truncated output
483483

484484
## [2.1.13]
485485

src/api/transform/o1-format.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ Description: Perform a regex search across files in a specified directory, provi
6767
</read_file>
6868
Description: Read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file, for example to analyze code, review text files, or extract information from configuration files. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string.
6969
70-
6. write_to_file:
71-
<write_to_file>
70+
6. create_file:
71+
<create_file>
7272
<path>File path here</path>
7373
<content>
7474
Your file content here
7575
</content>
76-
</write_to_file>
76+
</create_file>
7777
Description: Write content to a file at the specified path. If the file exists, it will be overwritten with the provided content. If the file doesn't exist, it will be created. Always provide the full intended content of the file, without any truncation. This tool will automatically create any directories needed to write the file.
7878
7979
7. ask_followup_question:
@@ -107,7 +107,7 @@ Example 2: Using multiple tools
107107
108108
Let's create two new configuration files for the web application: one for the frontend and one for the backend.
109109
110-
<write_to_file>
110+
<create_file>
111111
<path>./frontend-config.json</path>
112112
<content>
113113
{
@@ -125,9 +125,9 @@ Let's create two new configuration files for the web application: one for the fr
125125
"version": "1.0.0"
126126
}
127127
</content>
128-
</write_to_file>
128+
</create_file>
129129
130-
<write_to_file>
130+
<create_file>
131131
<path>./backend-config.yaml</path>
132132
<content>
133133
database:
@@ -154,7 +154,7 @@ externalServices:
154154
emailProvider: sendgrid
155155
storageProvider: aws-s3
156156
</content>
157-
</write_to_file>
157+
</create_file>
158158
159159
Example 3: Asking a follow-up question
160160
@@ -239,7 +239,7 @@ const toolNames = [
239239
"list_code_definition_names",
240240
"search_files",
241241
"read_file",
242-
"write_to_file",
242+
"create_file",
243243
"ask_followup_question",
244244
"attempt_completion",
245245
]
@@ -331,7 +331,7 @@ function validateToolInput(toolName: string, tool_input: Record<string, string>)
331331
return "path" in tool_input
332332
case "search_files":
333333
return "path" in tool_input && "regex" in tool_input
334-
case "write_to_file":
334+
case "create_file":
335335
return "path" in tool_input && "content" in tool_input
336336
case "ask_followup_question":
337337
return "question" in tool_input
@@ -349,10 +349,10 @@ function validateToolInput(toolName: string, tool_input: Record<string, string>)
349349
// <command>ls -la</command>
350350
// </execute_command>
351351

352-
// <write_to_file>
352+
// <create_file>
353353
// <path>./example.txt</path>
354354
// <content>Hello, World!</content>
355-
// </write_to_file>`;
355+
// </create_file>`;
356356
//
357357
// const { normalText, toolCalls } = parseAIResponse(aiResponse);
358358
// console.log(normalText);

src/core/Cline.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ export class Cline {
698698
text:
699699
`[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.${
700700
wasRecent
701-
? "\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."
701+
? "\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."
702702
: ""
703703
}` +
704704
(responseText
@@ -1102,7 +1102,7 @@ export class Cline {
11021102
return `[${block.name} for '${block.params.command}']`
11031103
case "read_file":
11041104
return `[${block.name} for '${block.params.path}']`
1105-
case "write_to_file":
1105+
case "create_file":
11061106
return `[${block.name} for '${block.params.path}']`
11071107
case "edit_file":
11081108
return `[${block.name} for '${block.params.path}']`
@@ -1267,7 +1267,7 @@ export class Cline {
12671267
}
12681268

12691269
switch (block.name) {
1270-
case "write_to_file": {
1270+
case "create_file": {
12711271
const relPath: string | undefined = block.params.path
12721272
let newContent: string | undefined = block.params.content
12731273
let predictedLineCount: number | undefined = parseInt(block.params.line_count ?? "0")
@@ -1332,20 +1332,20 @@ export class Cline {
13321332
} else {
13331333
if (!relPath) {
13341334
this.consecutiveMistakeCount++
1335-
pushToolResult(await this.sayAndCreateMissingParamError("write_to_file", "path"))
1335+
pushToolResult(await this.sayAndCreateMissingParamError("create_file", "path"))
13361336
await this.diffViewProvider.reset()
13371337
break
13381338
}
13391339
if (!newContent) {
13401340
this.consecutiveMistakeCount++
1341-
pushToolResult(await this.sayAndCreateMissingParamError("write_to_file", "content"))
1341+
pushToolResult(await this.sayAndCreateMissingParamError("create_file", "content"))
13421342
await this.diffViewProvider.reset()
13431343
break
13441344
}
13451345
if (!predictedLineCount) {
13461346
this.consecutiveMistakeCount++
13471347
pushToolResult(
1348-
await this.sayAndCreateMissingParamError("write_to_file", "line_count"),
1348+
await this.sayAndCreateMissingParamError("create_file", "line_count"),
13491349
)
13501350
await this.diffViewProvider.reset()
13511351
break
@@ -2194,7 +2194,7 @@ export class Cline {
21942194
formatResponse.toolResult(
21952195
`The browser action has been executed. The console logs and screenshot have been captured for your analysis.\n\nConsole logs:\n${
21962196
browserActionResult.logs || "(No new logs)"
2197-
}\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.)`,
2197+
}\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.)`,
21982198
browserActionResult.screenshot ? [browserActionResult.screenshot] : [],
21992199
),
22002200
)
@@ -2711,7 +2711,7 @@ export class Cline {
27112711

27122712
/*
27132713
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.
2714-
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.
2714+
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.
27152715
*/
27162716
this.presentAssistantMessageLocked = false // this needs to be placed here, if not then calling this.presentAssistantMessage below would fail (sometimes) since it's locked
27172717
// 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)
@@ -3261,7 +3261,7 @@ export class Cline {
32613261

32623262
// Add warning if not in code mode
32633263
if (
3264-
!isToolAllowedForMode("write_to_file", currentMode, customModes ?? [], {
3264+
!isToolAllowedForMode("create_file", currentMode, customModes ?? [], {
32653265
edit_file: this.diffEnabled,
32663266
}) &&
32673267
!isToolAllowedForMode("edit_file", currentMode, customModes ?? [], { edit_file: this.diffEnabled })

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

Lines changed: 3 additions & 3 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("write_to_file", "custom-mode", customModes)).toBe(true)
62+
expect(isToolAllowedForMode("create_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("write_to_file", codeMode, customModes)).toBe(false)
79+
expect(isToolAllowedForMode("create_file", codeMode, customModes)).toBe(false)
8080
})
8181

8282
it("respects tool requirements in custom modes", () => {
@@ -94,7 +94,7 @@ describe("mode-validator", () => {
9494
expect(isToolAllowedForMode("edit_file", "custom-mode", customModes, requirements)).toBe(false)
9595

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

src/core/assistant-message/index.ts

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

8282
export interface WriteToFileToolUse extends ToolUse {
83-
name: "write_to_file"
83+
name: "create_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 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.
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.
6565
const contentParamName: ToolParamName = "content"
66-
if (currentToolUse.name === "write_to_file" && accumulator.endsWith(`</${contentParamName}>`)) {
66+
if (currentToolUse.name === "create_file" && accumulator.endsWith(`</${contentParamName}>`)) {
6767
const toolContent = accumulator.slice(currentToolUseStartIndex)
6868
const contentStartTag = `<${contentParamName}>`
6969
const contentEndTag = `</${contentParamName}>`

0 commit comments

Comments
 (0)