Skip to content

Commit cf90414

Browse files
committed
feat: improve LLM understanding of implicit file change rejections
- Add new response format for implicit rejection with feedback - Update askApproval logic to detect implicit rejections (messageResponse with feedback on file change tools) - Add system prompt rule clarifying file change feedback handling - Add tests for the new implicit rejection response format Fixes #7480
1 parent 548d3b4 commit cf90414

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed

src/core/assistant-message/presentAssistantMessage.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,27 @@ export async function presentAssistantMessage(cline: Task) {
285285
)
286286

287287
if (response !== "yesButtonClicked") {
288-
// Handle both messageResponse and noButtonClicked with text.
289-
if (text) {
288+
// Check if this is a file change tool and user provided feedback via messageResponse
289+
const isFileChangeTool = [
290+
"write_to_file",
291+
"apply_diff",
292+
"insert_content",
293+
"search_and_replace",
294+
].includes(block.name)
295+
const isImplicitRejection = response === "messageResponse" && text && isFileChangeTool
296+
297+
if (isImplicitRejection) {
298+
// User provided feedback without explicitly accepting - treat as implicit rejection with improvement request
299+
await cline.say("user_feedback", text, images)
300+
pushToolResult(
301+
formatResponse.toolResult(formatResponse.toolImplicitlyRejectedWithFeedback(text), images),
302+
)
303+
} else if (text) {
304+
// Explicit rejection with feedback
290305
await cline.say("user_feedback", text, images)
291306
pushToolResult(formatResponse.toolResult(formatResponse.toolDeniedWithFeedback(text), images))
292307
} else {
308+
// Explicit rejection without feedback
293309
pushToolResult(formatResponse.toolDenied())
294310
}
295311
cline.didRejectTool = true
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { describe, it, expect } from "vitest"
2+
import { formatResponse } from "../responses"
3+
4+
describe("formatResponse - Implicit Rejection", () => {
5+
it("should format implicit rejection message correctly", () => {
6+
const feedback = "Please add error handling to this code"
7+
const result = formatResponse.toolImplicitlyRejectedWithFeedback(feedback)
8+
9+
expect(result).toContain("implicitly rejected")
10+
expect(result).toContain("NOT applied")
11+
expect(result).toContain(feedback)
12+
expect(result).toContain("Do not attempt to revert")
13+
expect(result).toContain("read the current file content")
14+
expect(result).toContain("create a new proposal")
15+
})
16+
17+
it("should differentiate from explicit rejection message", () => {
18+
const feedback = "This doesn't look right"
19+
const implicitResult = formatResponse.toolImplicitlyRejectedWithFeedback(feedback)
20+
const explicitResult = formatResponse.toolDeniedWithFeedback(feedback)
21+
22+
expect(implicitResult).not.toBe(explicitResult)
23+
expect(implicitResult).toContain("implicitly rejected")
24+
expect(explicitResult).not.toContain("implicitly rejected")
25+
})
26+
27+
it("should differentiate from approval with feedback message", () => {
28+
const feedback = "Looks good, thanks!"
29+
const implicitResult = formatResponse.toolImplicitlyRejectedWithFeedback(feedback)
30+
const approvalResult = formatResponse.toolApprovedWithFeedback(feedback)
31+
32+
expect(implicitResult).not.toBe(approvalResult)
33+
expect(implicitResult).toContain("rejected")
34+
expect(approvalResult).toContain("approved")
35+
})
36+
})

src/core/prompts/responses.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ export const formatResponse = {
1313
toolApprovedWithFeedback: (feedback?: string) =>
1414
`The user approved this operation and provided the following context:\n<feedback>\n${feedback}\n</feedback>`,
1515

16+
toolImplicitlyRejectedWithFeedback: (feedback?: string) =>
17+
`The user implicitly rejected the current file change proposal by providing improvement feedback instead of explicitly accepting it. The proposed change was NOT applied. The user wants you to create a NEW, improved proposal based on their feedback:\n<feedback>\n${feedback}\n</feedback>\n\nIMPORTANT: The previous file change proposal was rejected. Do not attempt to revert any changes. Instead, read the current file content and create a new proposal incorporating the user's feedback.`,
18+
1619
toolError: (error?: string) => `The tool execution failed with the following error:\n<error>\n${error}\n</error>`,
1720

1821
rooIgnoreError: (path: string) =>

src/core/prompts/sections/rules.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ RULES
6969
- All file paths must be relative to this directory. However, commands may change directories in terminals, so respect working directory specified by the response to <execute_command>.
7070
- You cannot \`cd\` into a different directory to complete a task. You are stuck operating from '${cwd.toPosix()}', so be sure to pass in the correct 'path' parameter when using tools that require a path.
7171
- Do not use the ~ character or $HOME to refer to the home directory.
72+
- **CRITICAL: File Change Feedback Handling** - When you propose a file change (using write_to_file, apply_diff, insert_content, or search_and_replace) and the user provides feedback without explicitly accepting it, this means they have IMPLICITLY REJECTED your current proposal. In this case:
73+
* The proposed change was NOT applied to the file
74+
* You should NOT attempt to "revert" anything (there's nothing to revert since the change wasn't applied)
75+
* You MUST read the current file content again to understand its actual state
76+
* You should create a NEW proposal that incorporates the user's feedback
77+
* The user's feedback is meant to guide you toward a better solution, not to trigger a revert operation
7278
- Before using the execute_command tool, you must first think about the SYSTEM INFORMATION context provided to understand the user's environment and tailor your commands to ensure they are compatible with their system. You must also consider if the command you need to run should be executed in a specific directory outside of the current working directory '${cwd.toPosix()}', and if so prepend with \`cd\`'ing into that directory && then executing the command (as one command since you are stuck operating from '${cwd.toPosix()}'). For example, if you needed to run \`npm install\` in a project outside of '${cwd.toPosix()}', you would need to prepend with a \`cd\` i.e. pseudocode for this would be \`cd (path to project) && (command, in this case npm install)\`.
7379
${codebaseSearchRule}- When using the search_files tool${isCodebaseSearchAvailable ? " (after codebase_search)" : ""}, craft your regex patterns carefully to balance specificity and flexibility. Based on the user's task you may use it to find code patterns, TODO comments, function definitions, or any text-based information across the project. The results include context, so analyze the surrounding code to better understand the matches. Leverage the search_files tool in combination with other tools for more comprehensive analysis. For example, use it to find specific code patterns, then use read_file to examine the full context of interesting matches before using ${diffStrategy ? "apply_diff or write_to_file" : "write_to_file"} to make informed changes.
7480
- When creating a new project (such as an app, website, or any software project), organize all new files within a dedicated project directory unless the user specifies otherwise. Use appropriate file paths when writing files, as the write_to_file tool will automatically create any necessary directories. Structure the project logically, adhering to best practices for the specific type of project being created. Unless otherwise specified, new projects should be easily run without additional setup, for example most projects can be built in HTML, CSS, and JavaScript - which you can open in a browser.

0 commit comments

Comments
 (0)