diff --git a/src/core/tools/__tests__/insertContentTool.test.ts b/src/core/tools/__tests__/insertContentTool.test.ts index c9c48ba5b0..7f0832a8ea 100644 --- a/src/core/tools/__tests__/insertContentTool.test.ts +++ b/src/core/tools/__tests__/insertContentTool.test.ts @@ -48,28 +48,6 @@ jest.mock("../../ignore/RooIgnoreController", () => ({ }, })) -// Mock insertGroups from diff/insert-groups -jest.mock("../../diff/insert-groups", () => ({ - insertGroups: jest.fn().mockImplementation((lines, groups) => { - let newLines = [...lines] - for (const group of groups) { - const { index, elements } = group - if (index === -1 || index >= newLines.length) { - // Append to end - newLines.push(...elements) - } else if (index < 0) { - // Insert at beginning (index -1 for line 0, but insertGroups expects 0 for beginning) - // This mock simplifies, assuming index -1 is always append. - // For line 1, index is 0. - newLines.splice(0, 0, ...elements) - } else { - newLines.splice(index, 0, ...elements) - } - } - return newLines - }), -})) - describe("insertContentTool", () => { const testFilePath = "test/file.txt" const absoluteFilePath = "/test/file.txt" @@ -77,7 +55,6 @@ describe("insertContentTool", () => { const mockedFileExistsAtPath = fileExistsAtPath as jest.MockedFunction const mockedFsReadFile = fs.readFile as jest.MockedFunction const mockedPathResolve = path.resolve as jest.MockedFunction - const mockedInsertGroups = require("../../diff/insert-groups").insertGroups as jest.MockedFunction let mockCline: any let mockAskApproval: jest.Mock diff --git a/src/core/tools/insertContentTool.ts b/src/core/tools/insertContentTool.ts index 704d2bcb54..b76769fcf0 100644 --- a/src/core/tools/insertContentTool.ts +++ b/src/core/tools/insertContentTool.ts @@ -116,11 +116,22 @@ export async function insertContentTool( await delay(200) } - const diff = formatResponse.createPrettyPatch(relPath, fileContent, updatedContent) + // For consistency with writeToFileTool, handle new files differently + let diff: string | undefined + let approvalContent: string | undefined - if (fileExists && !diff) { - pushToolResult(`No changes needed for '${relPath}'`) - return + if (fileExists) { + // For existing files, generate diff and check for changes + diff = formatResponse.createPrettyPatch(relPath, fileContent, updatedContent) + if (!diff) { + pushToolResult(`No changes needed for '${relPath}'`) + return + } + approvalContent = undefined + } else { + // For new files, skip diff generation and provide full content + diff = undefined + approvalContent = updatedContent } await cline.diffViewProvider.update(updatedContent, true) @@ -128,6 +139,7 @@ export async function insertContentTool( const completeMessage = JSON.stringify({ ...sharedMessageProps, diff, + content: approvalContent, lineNumber: lineNumber, isProtected: isWriteProtected, } satisfies ClineSayTool)