Skip to content

Commit a2b06a7

Browse files
committed
Respect the setting to always read the full file
1 parent 2eba534 commit a2b06a7

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed

.changeset/tough-coats-hear.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"roo-cline": patch
3+
---
4+
5+
Respect the setting to always read the full file

src/core/__tests__/read-file-maxReadFileLine.test.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ describe("read_file tool with maxReadFileLine setting", () => {
186186

187187
return toolResult
188188
}
189-
190189
describe("when maxReadFileLine is negative", () => {
191190
it("should read the entire file using extractTextFromFile", async () => {
192191
// Setup - use default mockInputContent
@@ -201,6 +200,43 @@ describe("read_file tool with maxReadFileLine setting", () => {
201200
expect(mockedParseSourceCodeDefinitionsForFile).not.toHaveBeenCalled()
202201
expect(result).toBe(expectedFullFileXml)
203202
})
203+
204+
it("should ignore range parameters and read entire file when maxReadFileLine is -1", async () => {
205+
// Setup - use default mockInputContent
206+
mockInputContent = fileContent
207+
208+
// Execute with range parameters
209+
const result = await executeReadFileTool(
210+
{
211+
start_line: "2",
212+
end_line: "4",
213+
},
214+
{ maxReadFileLine: -1 },
215+
)
216+
217+
// Verify that extractTextFromFile is still used (not readLines)
218+
expect(mockedExtractTextFromFile).toHaveBeenCalledWith(absoluteFilePath)
219+
expect(mockedReadLines).not.toHaveBeenCalled()
220+
expect(mockedParseSourceCodeDefinitionsForFile).not.toHaveBeenCalled()
221+
expect(result).toBe(expectedFullFileXml)
222+
})
223+
224+
it("should not show line snippet in approval message when maxReadFileLine is -1", async () => {
225+
// This test verifies the line snippet behavior for the approval message
226+
// Setup - use default mockInputContent
227+
mockInputContent = fileContent
228+
229+
// Execute - we'll reuse executeReadFileTool to run the tool
230+
await executeReadFileTool({}, { maxReadFileLine: -1 })
231+
232+
// Verify the empty line snippet for full read was passed to the approval message
233+
// Look at the parameters passed to the 'ask' method in the approval message
234+
const askCall = mockCline.ask.mock.calls[0]
235+
const completeMessage = JSON.parse(askCall[1])
236+
237+
// Verify the reason (lineSnippet) is empty or undefined for full read
238+
expect(completeMessage.reason).toBeFalsy()
239+
})
204240
})
205241

206242
describe("when maxReadFileLine is 0", () => {

src/core/tools/readFileTool.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,16 @@ export async function readFileTool(
5151
return
5252
}
5353

54+
const { maxReadFileLine = 500 } = (await cline.providerRef.deref()?.getState()) ?? {}
55+
const isFullRead = maxReadFileLine === -1
56+
5457
// Check if we're doing a line range read
5558
let isRangeRead = false
5659
let startLine: number | undefined = undefined
5760
let endLine: number | undefined = undefined
5861

59-
// Check if we have either range parameter
60-
if (startLineStr || endLineStr) {
62+
// Check if we have either range parameter and we're not doing a full read
63+
if (!isFullRead && (startLineStr || endLineStr)) {
6164
isRangeRead = true
6265
}
6366

@@ -98,11 +101,11 @@ export async function readFileTool(
98101
return
99102
}
100103

101-
const { maxReadFileLine = 500 } = (await cline.providerRef.deref()?.getState()) ?? {}
102-
103104
// Create line snippet description for approval message
104105
let lineSnippet = ""
105-
if (startLine !== undefined && endLine !== undefined) {
106+
if (isFullRead) {
107+
// No snippet for full read
108+
} else if (startLine !== undefined && endLine !== undefined) {
106109
lineSnippet = t("tools:readFile.linesRange", { start: startLine + 1, end: endLine + 1 })
107110
} else if (startLine !== undefined) {
108111
lineSnippet = t("tools:readFile.linesFromToEnd", { start: startLine + 1 })

0 commit comments

Comments
 (0)