mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 04:11:10 -05:00
Detect code omission and show warning with troubleshooting link
This commit is contained in:
@@ -41,6 +41,7 @@ import { formatResponse } from "./prompts/responses"
|
|||||||
import { addCustomInstructions, SYSTEM_PROMPT } from "./prompts/system"
|
import { addCustomInstructions, SYSTEM_PROMPT } from "./prompts/system"
|
||||||
import { truncateHalfConversation } from "./sliding-window"
|
import { truncateHalfConversation } from "./sliding-window"
|
||||||
import { ClineProvider, GlobalFileNames } from "./webview/ClineProvider"
|
import { ClineProvider, GlobalFileNames } from "./webview/ClineProvider"
|
||||||
|
import { showOmissionWarning } from "../integrations/editor/detect-omission"
|
||||||
|
|
||||||
const cwd =
|
const cwd =
|
||||||
vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0) ?? path.join(os.homedir(), "Desktop") // may or may not exist but fs checking existence would immediately ask for permission which would be bad UX, need to come up with a better solution
|
vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0) ?? path.join(os.homedir(), "Desktop") // may or may not exist but fs checking existence would immediately ask for permission which would be bad UX, need to come up with a better solution
|
||||||
@@ -1075,6 +1076,8 @@ export class Cline {
|
|||||||
await delay(300) // wait for diff view to update
|
await delay(300) // wait for diff view to update
|
||||||
this.diffViewProvider.scrollToFirstDiff()
|
this.diffViewProvider.scrollToFirstDiff()
|
||||||
|
|
||||||
|
showOmissionWarning(newContent)
|
||||||
|
|
||||||
const completeMessage = JSON.stringify({
|
const completeMessage = JSON.stringify({
|
||||||
...sharedMessageProps,
|
...sharedMessageProps,
|
||||||
content: fileExists ? undefined : newContent,
|
content: fileExists ? undefined : newContent,
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ Usage:
|
|||||||
Description: Request to 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. This tool will automatically create any directories needed to write the file.
|
Description: Request to 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. This tool will automatically create any directories needed to write the file.
|
||||||
Parameters:
|
Parameters:
|
||||||
- path: (required) The path of the file to write to (relative to the current working directory ${cwd.toPosix()})
|
- path: (required) The path of the file to write to (relative to the current working directory ${cwd.toPosix()})
|
||||||
- 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. IT IS STRICTLY FORBIDDEN TO OMIT CODE WITH \`// implementation remains unchanged\` OR ANY OTHER SUCH PLACEHOLDER.
|
- 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.
|
||||||
Usage:
|
Usage:
|
||||||
<write_to_file>
|
<write_to_file>
|
||||||
<path>File path here</path>
|
<path>File path here</path>
|
||||||
|
|||||||
52
src/integrations/editor/detect-omission.ts
Normal file
52
src/integrations/editor/detect-omission.ts
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import * as vscode from "vscode"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detects potential AI-generated code omissions in the given file content.
|
||||||
|
* @param fileContent The content of the file to check.
|
||||||
|
* @returns True if a potential omission is detected, false otherwise.
|
||||||
|
*/
|
||||||
|
function detectCodeOmission(fileContent: string): boolean {
|
||||||
|
const lines = fileContent.split("\n")
|
||||||
|
const omissionKeywords = ["remain", "remains", "unchanged", "rest", "existing", "previous", "..."]
|
||||||
|
|
||||||
|
const commentPatterns = [
|
||||||
|
/^\s*\/\//, // Single-line comment for most languages
|
||||||
|
/^\s*#/, // Single-line comment for Python, Ruby, etc.
|
||||||
|
/^\s*{\s*\/\*/, // JSX comment opening
|
||||||
|
/^\s*<!--/, // HTML comment opening
|
||||||
|
]
|
||||||
|
|
||||||
|
for (const line of lines) {
|
||||||
|
if (commentPatterns.some((pattern) => pattern.test(line))) {
|
||||||
|
const words = line.toLowerCase().split(/\s+/)
|
||||||
|
if (omissionKeywords.some((keyword) => words.includes(keyword))) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows a warning in VSCode if a potential code omission is detected.
|
||||||
|
* @param fileContent The content of the file to check.
|
||||||
|
*/
|
||||||
|
export function showOmissionWarning(fileContent: string): void {
|
||||||
|
if (detectCodeOmission(fileContent)) {
|
||||||
|
vscode.window
|
||||||
|
.showWarningMessage(
|
||||||
|
"Potential code truncation detected. This happens when the AI reaches its max output limit.",
|
||||||
|
"Follow this guide to fix the issue"
|
||||||
|
)
|
||||||
|
.then((selection) => {
|
||||||
|
if (selection === "Follow this guide to fix the issue") {
|
||||||
|
vscode.env.openExternal(
|
||||||
|
vscode.Uri.parse(
|
||||||
|
"https://github.com/cline/cline/wiki/Troubleshooting-%E2%80%90-Cline-Deleting-Code-with-%22Rest-of-Code-Here%22-Comments"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user