Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/core/prompts/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,39 @@ Otherwise, if you have not completed the task and do not need additional informa
missingToolParameterError: (paramName: string) =>
`Missing value for required parameter '${paramName}'. Please retry with complete response.\n\n${toolUseInstructionsReminder}`,

lineCountTruncationError: (actualLineCount: number, isNewFile: boolean, diffStrategyEnabled: boolean = false) => {
const truncationMessage = `Note: Your response may have been truncated because it exceeded your output limit. You wrote ${actualLineCount} lines of content, but the line_count parameter was either missing or not included in your response.`

const newFileGuidance =
`This appears to be a new file.\n` +
`${truncationMessage}\n\n` +
`RECOMMENDED APPROACH:\n` +
`1. Try again with the line_count parameter in your response if you forgot to include it\n` +
`2. Or break your content into smaller chunks - first use write_to_file with the initial chunk\n` +
`3. Then use insert_content to append additional chunks\n`

let existingFileApproaches = [
`1. Try again with the line_count parameter in your response if you forgot to include it`,
]

if (diffStrategyEnabled) {
existingFileApproaches.push(`2. Or try using apply_diff instead of write_to_file for targeted changes`)
}

existingFileApproaches.push(
`${diffStrategyEnabled ? "3" : "2"}. Or use search_and_replace for specific text replacements`,
`${diffStrategyEnabled ? "4" : "3"}. Or use insert_content to add specific content at particular lines`,
)

const existingFileGuidance =
`This appears to be content for an existing file.\n` +
`${truncationMessage}\n\n` +
`RECOMMENDED APPROACH:\n` +
`${existingFileApproaches.join("\n")}\n`

return `${isNewFile ? newFileGuidance : existingFileGuidance}\n${toolUseInstructionsReminder}`
},

invalidMcpToolArgumentError: (serverName: string, toolName: string) =>
`Invalid JSON argument used with ${serverName} for ${toolName}. Please retry with a properly formatted JSON argument.`,

Expand Down
24 changes: 23 additions & 1 deletion src/core/tools/writeToFileTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,29 @@ export async function writeToFileTool(
if (!predictedLineCount) {
cline.consecutiveMistakeCount++
cline.recordToolError("write_to_file")
pushToolResult(await cline.sayAndCreateMissingParamError("write_to_file", "line_count"))

// Calculate the actual number of lines in the content
const actualLineCount = newContent.split("\n").length

// Check if this is a new file or existing file
const isNewFile = !fileExists

// Check if diffStrategy is enabled
const diffStrategyEnabled = !!cline.diffStrategy

// Use more specific error message for line_count that provides guidance based on the situation
await cline.say(
"error",
`Roo tried to use write_to_file${
relPath ? ` for '${relPath.toPosix()}'` : ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message builds a string using relPath.toPosix(). Ensure that relPath is not a plain string but an object with a toPosix() method, or use a helper function (like getReadablePath) consistently to convert the path to POSIX format.

Suggested change
relPath ? ` for '${relPath.toPosix()}'` : ""
relPath ? ` for '${getReadablePath(cline.cwd, relPath)}'` : ""

This comment was generated because it violated a code review rule: mrule_fYE6mUdYYxZL58YF.

} but the required parameter 'line_count' was missing or truncated after ${actualLineCount} lines of content were written. Retrying...`,
)

pushToolResult(
formatResponse.toolError(
formatResponse.lineCountTruncationError(actualLineCount, isNewFile, diffStrategyEnabled),
),
)
await cline.diffViewProvider.revertChanges()
return
}
Expand Down