Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

Commit be69ef9

Browse files
Refactor: Remove line_count parameter from write_to_file tool (#9667)
1 parent c91a19f commit be69ef9

25 files changed

Lines changed: 61 additions & 275 deletions

src/core/assistant-message/NativeToolCallParser.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -394,16 +394,10 @@ export class NativeToolCallParser {
394394
break
395395

396396
case "write_to_file":
397-
if (partialArgs.path || partialArgs.content || partialArgs.line_count !== undefined) {
397+
if (partialArgs.path || partialArgs.content) {
398398
nativeArgs = {
399399
path: partialArgs.path,
400400
content: partialArgs.content,
401-
line_count:
402-
typeof partialArgs.line_count === "number"
403-
? partialArgs.line_count
404-
: partialArgs.line_count
405-
? parseInt(String(partialArgs.line_count), 10)
406-
: undefined,
407401
}
408402
}
409403
break
@@ -745,14 +739,10 @@ export class NativeToolCallParser {
745739
break
746740

747741
case "write_to_file":
748-
if (args.path !== undefined && args.content !== undefined && args.line_count !== undefined) {
742+
if (args.path !== undefined && args.content !== undefined) {
749743
nativeArgs = {
750744
path: args.path,
751745
content: args.content,
752-
line_count:
753-
typeof args.line_count === "number"
754-
? args.line_count
755-
: parseInt(String(args.line_count), 10),
756746
} as NativeArgsFor<TName>
757747
}
758748
break

src/core/assistant-message/__tests__/AssistantMessageParser.spec.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ describe("AssistantMessageParser (streaming)", () => {
179179
// This has XML-like content: </content>
180180
return true;
181181
}
182-
</content><line_count>5</line_count></write_to_file>`
182+
</content></write_to_file>`
183183

184184
const result = streamChunks(parser, message).filter((block) => !isEmptyTextContent(block))
185185

@@ -188,7 +188,6 @@ describe("AssistantMessageParser (streaming)", () => {
188188
expect(toolUse.type).toBe("tool_use")
189189
expect(toolUse.name).toBe("write_to_file")
190190
expect(toolUse.params.path).toBe("src/file.ts")
191-
expect(toolUse.params.line_count).toBe("5")
192191
expect(toolUse.params.content).toContain("function example()")
193192
expect(toolUse.params.content).toContain("// This has XML-like content: </content>")
194193
expect(toolUse.params.content).toContain("return true;")
@@ -263,7 +262,7 @@ describe("AssistantMessageParser (streaming)", () => {
263262
line 1
264263
line 2
265264
line 3
266-
</content><line_count>3</line_count></write_to_file>`
265+
</content></write_to_file>`
267266
const result = streamChunks(parser, message).filter((block) => !isEmptyTextContent(block))
268267

269268
expect(result).toHaveLength(1)
@@ -274,7 +273,6 @@ describe("AssistantMessageParser (streaming)", () => {
274273
expect(toolUse.params.content).toContain("line 1")
275274
expect(toolUse.params.content).toContain("line 2")
276275
expect(toolUse.params.content).toContain("line 3")
277-
expect(toolUse.params.line_count).toBe("3")
278276
expect(toolUse.partial).toBe(false)
279277
})
280278
it("should handle a complex message with multiple content types", () => {
@@ -287,7 +285,7 @@ describe("AssistantMessageParser (streaming)", () => {
287285
<write_to_file><path>src/index.ts</path><content>
288286
// Updated content
289287
console.log("Hello world");
290-
</content><line_count>2</line_count></write_to_file>
288+
</content></write_to_file>
291289
292290
Let's run the code:
293291

src/core/assistant-message/__tests__/parseAssistantMessage.spec.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ const isEmptyTextContent = (block: AssistantMessageContent) =>
168168
// This has XML-like content: </content>
169169
return true;
170170
}
171-
</content><line_count>5</line_count></write_to_file>`
171+
</content></write_to_file>`
172172

173173
const result = parser(message).filter((block) => !isEmptyTextContent(block))
174174

@@ -177,7 +177,6 @@ const isEmptyTextContent = (block: AssistantMessageContent) =>
177177
expect(toolUse.type).toBe("tool_use")
178178
expect(toolUse.name).toBe("write_to_file")
179179
expect(toolUse.params.path).toBe("src/file.ts")
180-
expect(toolUse.params.line_count).toBe("5")
181180
expect(toolUse.params.content).toContain("function example()")
182181
expect(toolUse.params.content).toContain("// This has XML-like content: </content>")
183182
expect(toolUse.params.content).toContain("return true;")
@@ -276,7 +275,7 @@ const isEmptyTextContent = (block: AssistantMessageContent) =>
276275
line 1
277276
line 2
278277
line 3
279-
</content><line_count>3</line_count></write_to_file>`
278+
</content></write_to_file>`
280279
const result = parser(message).filter((block) => !isEmptyTextContent(block))
281280

282281
expect(result).toHaveLength(1)
@@ -287,7 +286,6 @@ const isEmptyTextContent = (block: AssistantMessageContent) =>
287286
expect(toolUse.params.content).toContain("line 1")
288287
expect(toolUse.params.content).toContain("line 2")
289288
expect(toolUse.params.content).toContain("line 3")
290-
expect(toolUse.params.line_count).toBe("3")
291289
expect(toolUse.partial).toBe(false)
292290
})
293291

@@ -301,7 +299,7 @@ const isEmptyTextContent = (block: AssistantMessageContent) =>
301299
<write_to_file><path>src/index.ts</path><content>
302300
// Updated content
303301
console.log("Hello world");
304-
</content><line_count>2</line_count></write_to_file>
302+
</content></write_to_file>
305303
306304
Let's run the code:
307305

src/core/assistant-message/__tests__/parseAssistantMessageBenchmark.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,17 @@ const testCases = [
6262
},
6363
{
6464
name: "Message with a complex tool use (write_to_file)",
65-
input: "<write_to_file><path>src/file.ts</path><content>\nfunction example() {\n // This has XML-like content: </content>\n return true;\n}\n</content><line_count>5</line_count></write_to_file>",
65+
input: "<write_to_file><path>src/file.ts</path><content>\nfunction example() {\n // This has XML-like content: </content>\n return true;\n}\n</content></write_to_file>",
6666
},
6767
{
6868
name: "Message with multiple tool uses",
69-
input: "First file: <read_file><path>src/file1.ts</path></read_file>\nSecond file: <read_file><path>src/file2.ts</path></read_file>\nLet's write a new file: <write_to_file><path>src/file3.ts</path><content>\nexport function newFunction() {\n return 'Hello world';\n}\n</content><line_count>3</line_count></write_to_file>",
69+
input: "First file: <read_file><path>src/file1.ts</path></read_file>\nSecond file: <read_file><path>src/file2.ts</path></read_file>\nLet's write a new file: <write_to_file><path>src/file3.ts</path><content>\nexport function newFunction() {\n return 'Hello world';\n}\n</content></write_to_file>",
7070
},
7171
{
7272
name: "Large message with repeated tool uses",
7373
input: Array(50)
7474
.fill(
75-
'<read_file><path>src/file.ts</path></read_file>\n<write_to_file><path>output.ts</path><content>console.log("hello");</content><line_count>1</line_count></write_to_file>',
75+
'<read_file><path>src/file.ts</path></read_file>\n<write_to_file><path>output.ts</path><content>console.log("hello");</content></write_to_file>',
7676
)
7777
.join("\n"),
7878
},

src/core/prompts/__tests__/__snapshots__/add-custom-instructions/architect-mode-prompt.snap

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

src/core/prompts/__tests__/__snapshots__/add-custom-instructions/mcp-server-creation-disabled.snap

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

src/core/prompts/__tests__/__snapshots__/add-custom-instructions/mcp-server-creation-enabled.snap

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

src/core/prompts/__tests__/__snapshots__/add-custom-instructions/partial-reads-enabled.snap

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

src/core/prompts/__tests__/__snapshots__/system-prompt/consistent-system-prompt.snap

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

src/core/prompts/__tests__/__snapshots__/system-prompt/with-computer-use-support.snap

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

0 commit comments

Comments
 (0)