Skip to content

Commit 5ea1198

Browse files
author
Eric Wheeler
committed
feat: only require apply_diff for files >25 lines
Add line count check to writeToFileTool to only require apply_diff for files that are more than 25 lines long. This allows write_to_file to work on small existing files while still protecting larger files that need more careful modification. Signed-off-by: Eric Wheeler <[email protected]>
1 parent 02e3dce commit 5ea1198

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/core/tools/writeToFileTool.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from "path"
22
import delay from "delay"
33
import * as vscode from "vscode"
4+
import { countFileLines } from "../../integrations/misc/line-counter"
45

56
import { Cline } from "../Cline"
67
import { ClineSayTool } from "../../shared/ExtensionMessage"
@@ -70,12 +71,18 @@ export async function writeToFileTool(
7071
const isOutsideWorkspace = isPathOutsideWorkspace(fullPath)
7172

7273
if (fileExists) {
73-
pushToolResult(
74-
formatResponse.toolError(
75-
`File '${relPath}' already exists, write_to_file failed: You must use the 'apply_diff' tool to change an existing file.`,
76-
),
77-
)
78-
return
74+
// Count the lines in the file
75+
const absolutePath = path.resolve(cline.cwd, relPath)
76+
const lineCount = await countFileLines(absolutePath)
77+
// Only show error if file has more than 25 lines
78+
if (lineCount > 25) {
79+
pushToolResult(
80+
formatResponse.toolError(
81+
`File '${relPath}' already exists and is >25 lines long, write_to_file failed: You must use the '<apply_diff>' or '<search_and_replace>' tool to change an existing file.`,
82+
),
83+
)
84+
return
85+
}
7986
}
8087

8188
const sharedMessageProps: ClineSayTool = {

0 commit comments

Comments
 (0)