More flexibility for LLMs not being great at this

This commit is contained in:
Matt Rubens
2024-12-19 02:12:20 -05:00
parent ef9c468f17
commit 5d930981a4
4 changed files with 105 additions and 162 deletions

View File

@@ -1041,6 +1041,7 @@ export class Cline {
case "write_to_file": {
const relPath: string | undefined = block.params.path
let newContent: string | undefined = block.params.content
let predictedLineCount: number | undefined = parseInt(block.params.line_count ?? "0")
if (!relPath || !newContent) {
// checking for newContent ensure relPath is complete
// wait so we can determine if it's a new file or editing an existing file
@@ -1109,6 +1110,12 @@ export class Cline {
await this.diffViewProvider.reset()
break
}
if (!predictedLineCount) {
this.consecutiveMistakeCount++
pushToolResult(await this.sayAndCreateMissingParamError("write_to_file", "line_count"))
await this.diffViewProvider.reset()
break
}
this.consecutiveMistakeCount = 0
// if isEditingFile false, that means we have the full contents of the file already.
@@ -1125,12 +1132,11 @@ export class Cline {
this.diffViewProvider.scrollToFirstDiff()
// Check for code omissions before proceeding
const predictedLineCount = parseInt(block.params.line_count ?? "0")
if (detectCodeOmission(this.diffViewProvider.originalContent || "", newContent, predictedLineCount)) {
if (this.diffStrategy) {
await this.diffViewProvider.revertChanges()
pushToolResult(formatResponse.toolError(
`Content appears to be truncated (file has ${newContent.split("\n").length} lines but was predicted to have ${predictedLineCount} lines). 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.`
`Content appears to be truncated (file has ${newContent.split("\n").length} 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.`
))
break
} else {

View File

@@ -62,15 +62,15 @@ Usage:
Description: Request to write full 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. This tool will automatically create any directories needed to write the file.
Parameters:
- path: (required) The path of the file to write to (relative to the current working directory ${cwd.toPosix()})
- line_count: (required) The number of lines in the content. This is used to determine if the user needs to provide more content to complete the file.
- content: (required) The content to write to the file. ALWAYS provide the COMPLETE intended content of the file, without any truncation or omissions. You MUST include ALL parts of the file, even if they haven't been modified. Do NOT include the line numbers in the content though, just the actual content of the file.
- line_count: (required) The number of lines in the file. Make sure to compute this based on the actual content of the file, not the number of lines in the content you're providing.
Usage:
<write_to_file>
<line_count>total number of lines in the content, including empty lines</line_count>
<path>File path here</path>
<content>
Your file content here
</content>
<line_count>total number of lines in the file, including empty lines</line_count>
</write_to_file>
${diffStrategy ? diffStrategy.getToolDescription(cwd.toPosix()) : ""}
@@ -209,7 +209,6 @@ Your final result description here
## Example 2: Requesting to write to a file
<write_to_file>
<line_count>14</line_count>
<path>frontend-config.json</path>
<content>
{
@@ -227,6 +226,7 @@ Your final result description here
"version": "1.0.0"
}
</content>
<line_count>14</line_count>
</write_to_file>
## Example 3: Requesting to use an MCP tool