@@ -12,6 +12,7 @@ import { fileExistsAtPath } from "../../utils/fs"
1212import { insertGroups } from "../diff/insert-groups"
1313import { DEFAULT_WRITE_DELAY_MS } from "@roo-code/types"
1414import { EXPERIMENT_IDS , experiments } from "../../shared/experiments"
15+ import { convertNewFileToUnifiedDiff , computeDiffStats , sanitizeUnifiedDiff } from "../diff/stats"
1516
1617export async function insertContentTool (
1718 cline : Task ,
@@ -101,7 +102,7 @@ export async function insertContentTool(
101102 cline . diffViewProvider . originalContent = fileContent
102103 const lines = fileExists ? fileContent . split ( "\n" ) : [ ]
103104
104- const updatedContent = insertGroups ( lines , [
105+ let updatedContent = insertGroups ( lines , [
105106 {
106107 index : lineNumber - 1 ,
107108 elements : content . split ( "\n" ) ,
@@ -118,31 +119,31 @@ export async function insertContentTool(
118119 EXPERIMENT_IDS . PREVENT_FOCUS_DISRUPTION ,
119120 )
120121
121- // For consistency with writeToFileTool, handle new files differently
122- let diff : string | undefined
123- let approvalContent : string | undefined
124-
122+ // Build unified diff for display (normalize EOLs only for diff generation)
123+ let unified : string
125124 if ( fileExists ) {
126- // For existing files, generate diff and check for changes
127- diff = formatResponse . createPrettyPatch ( relPath , fileContent , updatedContent )
128- if ( ! diff ) {
125+ const oldForDiff = fileContent . replace ( / \r \n / g, "\n" )
126+ const newForDiff = updatedContent . replace ( / \r \n / g, "\n" )
127+ unified = formatResponse . createPrettyPatch ( relPath , oldForDiff , newForDiff )
128+ if ( ! unified ) {
129129 pushToolResult ( `No changes needed for '${ relPath } '` )
130130 return
131131 }
132- approvalContent = undefined
133132 } else {
134- // For new files, skip diff generation and provide full content
135- diff = undefined
136- approvalContent = updatedContent
133+ const newForDiff = updatedContent . replace ( / \r \n / g, "\n" )
134+ unified = convertNewFileToUnifiedDiff ( newForDiff , relPath )
137135 }
136+ unified = sanitizeUnifiedDiff ( unified )
137+ const diffStats = computeDiffStats ( unified ) || undefined
138138
139139 // Prepare the approval message (same for both flows)
140140 const completeMessage = JSON . stringify ( {
141141 ...sharedMessageProps ,
142- diff,
143- content : approvalContent ,
142+ // Send unified diff as content for render-only webview
143+ content : unified ,
144144 lineNumber : lineNumber ,
145145 isProtected : isWriteProtected ,
146+ diffStats,
146147 } satisfies ClineSayTool )
147148
148149 // Show diff view if focus disruption prevention is disabled
0 commit comments