-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: force preview for protected files regardless of background editing #6723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -517,8 +517,10 @@ ${errorDetails ? `\nTechnical details:\n${errorDetails}\n` : ""} | |||||
| EXPERIMENT_IDS.PREVENT_FOCUS_DISRUPTION, | ||||||
| ) | ||||||
|
|
||||||
| // For batch operations, we've already gotten approval | ||||||
| // Check if file is write-protected | ||||||
| const isWriteProtected = cline.rooProtectedController?.isWriteProtected(relPath) || false | ||||||
|
|
||||||
| // For batch operations, we've already gotten approval | ||||||
| const sharedMessageProps: ClineSayTool = { | ||||||
| tool: "appliedDiff", | ||||||
| path: getReadablePath(cline.cwd, relPath), | ||||||
|
|
@@ -549,8 +551,8 @@ ${errorDetails ? `\nTechnical details:\n${errorDetails}\n` : ""} | |||||
| // Set up diff view | ||||||
| cline.diffViewProvider.editType = "modify" | ||||||
|
|
||||||
| // Show diff view if focus disruption prevention is disabled | ||||||
| if (!isPreventFocusDisruptionEnabled) { | ||||||
| // Show diff view if focus disruption prevention is disabled OR if file is protected | ||||||
| if (!isPreventFocusDisruptionEnabled || isWriteProtected) { | ||||||
| await cline.diffViewProvider.open(relPath) | ||||||
| await cline.diffViewProvider.update(originalContent!, true) | ||||||
| cline.diffViewProvider.scrollToFirstDiff() | ||||||
|
|
@@ -560,21 +562,20 @@ ${errorDetails ? `\nTechnical details:\n${errorDetails}\n` : ""} | |||||
| } | ||||||
|
|
||||||
| // Ask for approval (same for both flows) | ||||||
| const isWriteProtected = cline.rooProtectedController?.isWriteProtected(relPath) || false | ||||||
| didApprove = await askApproval("tool", operationMessage, toolProgressStatus, isWriteProtected) | ||||||
|
|
||||||
| if (!didApprove) { | ||||||
| // Revert changes if diff view was shown | ||||||
| if (!isPreventFocusDisruptionEnabled) { | ||||||
| if (!isPreventFocusDisruptionEnabled || isWriteProtected) { | ||||||
| await cline.diffViewProvider.revertChanges() | ||||||
| } | ||||||
| results.push(`Changes to ${relPath} were not approved by user`) | ||||||
| continue | ||||||
| } | ||||||
|
|
||||||
| // Save the changes | ||||||
| if (isPreventFocusDisruptionEnabled) { | ||||||
| // Direct file write without diff view or opening the file | ||||||
| if (isPreventFocusDisruptionEnabled && !isWriteProtected) { | ||||||
| // Direct file write without diff view or opening the file (only for non-protected files) | ||||||
| await cline.diffViewProvider.saveDirectly( | ||||||
| relPath, | ||||||
| originalContent!, | ||||||
|
|
@@ -588,8 +589,12 @@ ${errorDetails ? `\nTechnical details:\n${errorDetails}\n` : ""} | |||||
| } | ||||||
| } else { | ||||||
| // Batch operations - already approved above | ||||||
| if (isPreventFocusDisruptionEnabled) { | ||||||
| // Direct file write without diff view or opening the file | ||||||
| // Check if any files in the batch are protected | ||||||
| const hasProtectedFiles = operationsToApprove.some( | ||||||
| (op) => cline.rooProtectedController?.isWriteProtected(op.path) || false, | ||||||
| ) | ||||||
| if (isPreventFocusDisruptionEnabled && !hasProtectedFiles) { | ||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this intentional? The condition for checking protected files in batch operations uses a different pattern than the other tools. Consider refactoring to match the pattern used elsewhere for consistency:
Suggested change
|
||||||
| // Direct file write without diff view or opening the file (only if no protected files) | ||||||
| cline.diffViewProvider.editType = "modify" | ||||||
| cline.diffViewProvider.originalContent = await fs.readFile(absolutePath, "utf-8") | ||||||
| await cline.diffViewProvider.saveDirectly( | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -171,8 +171,9 @@ export async function writeToFileTool( | |
| EXPERIMENT_IDS.PREVENT_FOCUS_DISRUPTION, | ||
| ) | ||
|
|
||
| if (isPreventFocusDisruptionEnabled) { | ||
| // Direct file write without diff view | ||
| // For protected files, always show diff view regardless of background editing setting | ||
| if (isPreventFocusDisruptionEnabled && !isWriteProtected) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment 'only for non-protected files' appears multiple times across the codebase. Could we improve readability by extracting this logic into a well-named variable like |
||
| // Direct file write without diff view (only for non-protected files) | ||
| // Check for code omissions before proceeding | ||
| if (detectCodeOmission(cline.diffViewProvider.originalContent || "", newContent, predictedLineCount)) { | ||
| if (cline.diffStrategy) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test suite is quite comprehensive! However, it might benefit from being split into smaller, more focused describe blocks. For example, you could have separate blocks for 'direct save behavior', 'diff view behavior', and 'protection flag handling'. Also, consider adding a test case for when
rooProtectedControlleris undefined/null to ensure the fallback tofalseworks correctly.