diff --git a/src/core/__tests__/read-file-maxReadFileLine.test.ts b/src/core/__tests__/read-file-maxReadFileLine.test.ts index 619ae3a605..c3bf80a043 100644 --- a/src/core/__tests__/read-file-maxReadFileLine.test.ts +++ b/src/core/__tests__/read-file-maxReadFileLine.test.ts @@ -48,6 +48,7 @@ describe("read_file tool with maxReadFileLine setting", () => { const fileContent = "Line 1\nLine 2\nLine 3\nLine 4\nLine 5" const numberedFileContent = "1 | Line 1\n2 | Line 2\n3 | Line 3\n4 | Line 4\n5 | Line 5" const sourceCodeDef = "\n\n# file.txt\n1--5 | Content" + const expectedFullFileXml = `\n ${testFilePath}\n \n${numberedFileContent}\n \n` // Mocked functions with correct types const mockedCountFileLines = countFileLines as jest.MockedFunction @@ -147,7 +148,7 @@ describe("read_file tool with maxReadFileLine setting", () => { expect(mockedExtractTextFromFile).toHaveBeenCalledWith(absoluteFilePath) expect(mockedReadLines).not.toHaveBeenCalled() expect(mockedParseSourceCodeDefinitionsForFile).not.toHaveBeenCalled() - expect(result).toBe(numberedFileContent) + expect(result).toBe(expectedFullFileXml) }) }) @@ -207,7 +208,7 @@ describe("read_file tool with maxReadFileLine setting", () => { // Verify expect(mockedExtractTextFromFile).toHaveBeenCalledWith(absoluteFilePath) - expect(result).toBe(numberedFileContent) + expect(result).toBe(expectedFullFileXml) }) it("should read with extractTextFromFile when file has few lines", async () => { @@ -221,7 +222,7 @@ describe("read_file tool with maxReadFileLine setting", () => { // Verify expect(mockedExtractTextFromFile).toHaveBeenCalledWith(absoluteFilePath) expect(mockedReadLines).not.toHaveBeenCalled() - expect(result).toBe(numberedFileContent) + expect(result).toBe(expectedFullFileXml) }) }) @@ -237,7 +238,7 @@ describe("read_file tool with maxReadFileLine setting", () => { // Verify expect(mockedExtractTextFromFile).toHaveBeenCalledWith(absoluteFilePath) expect(mockedReadLines).not.toHaveBeenCalled() - expect(result).toBe(numberedFileContent) + expect(result).toBe(expectedFullFileXml) }) }) diff --git a/src/core/diff/strategies/multi-search-replace.ts b/src/core/diff/strategies/multi-search-replace.ts index 78622c8f03..0f756896cc 100644 --- a/src/core/diff/strategies/multi-search-replace.ts +++ b/src/core/diff/strategies/multi-search-replace.ts @@ -480,7 +480,7 @@ Only use a single line of '=======' between search and replacement content, beca diffResults.push({ success: false, - error: `No sufficiently similar match found${lineRange} (${Math.floor(bestMatchScore * 100)}% similar, needs ${Math.floor(this.fuzzyThreshold * 100)}%)\n\nDebug Info:\n- Similarity Score: ${Math.floor(bestMatchScore * 100)}%\n- Required Threshold: ${Math.floor(this.fuzzyThreshold * 100)}%\n- Search Range: ${startLine && endLine ? `lines ${startLine}-${endLine}` : "start to end"}\n- Tip: Use read_file to get the latest content of the file before attempting the diff again, as the file content may have changed\n\nSearch Content:\n${searchChunk}${bestMatchSection}${originalContentSection}`, + error: `No sufficiently similar match found${lineRange} (${Math.floor(bestMatchScore * 100)}% similar, needs ${Math.floor(this.fuzzyThreshold * 100)}%)\n\nDebug Info:\n- Similarity Score: ${Math.floor(bestMatchScore * 100)}%\n- Required Threshold: ${Math.floor(this.fuzzyThreshold * 100)}%\n- Search Range: ${startLine && endLine ? `lines ${startLine}-${endLine}` : "start to end"}\n- Tip: Use the read_file tool to get the latest content of the file before attempting to use the apply_diff tool again, as the file content may have changed\n\nSearch Content:\n${searchChunk}${bestMatchSection}${originalContentSection}`, }) continue } diff --git a/src/core/tools/readFileTool.ts b/src/core/tools/readFileTool.ts index 8cbe89e570..0632a0a86f 100644 --- a/src/core/tools/readFileTool.ts +++ b/src/core/tools/readFileTool.ts @@ -171,7 +171,9 @@ export async function readFileTool( content += `\n\n[Showing only ${maxReadFileLine} of ${totalLines} total lines. Use start_line and end_line if you need to read more]${sourceCodeDef}` } - pushToolResult(content) + // Format the result into the required XML structure + const xmlResult = `\n ${relPath}\n \n${content}\n \n` + pushToolResult(xmlResult) } } catch (error) { await handleError("reading file", error)