Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/core/__tests__/read-file-maxReadFileLine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `<file>\n <path>${testFilePath}</path>\n <content>\n${numberedFileContent}\n </content>\n</file>`

// Mocked functions with correct types
const mockedCountFileLines = countFileLines as jest.MockedFunction<typeof countFileLines>
Expand Down Expand Up @@ -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)
})
})

Expand Down Expand Up @@ -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 () => {
Expand All @@ -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)
})
})

Expand All @@ -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)
})
})

Expand Down
2 changes: 1 addition & 1 deletion src/core/diff/strategies/multi-search-replace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion src/core/tools/readFileTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `<file>\n <path>${relPath}</path>\n <content>\n${content}\n </content>\n</file>`
pushToolResult(xmlResult)
}
} catch (error) {
await handleError("reading file", error)
Expand Down