diff --git a/src/core/tools/ReadFileTool.ts b/src/core/tools/ReadFileTool.ts index 58f3cc495e1..0093e89e08d 100644 --- a/src/core/tools/ReadFileTool.ts +++ b/src/core/tools/ReadFileTool.ts @@ -458,7 +458,7 @@ export class ReadFileTool extends BaseTool<"read_file"> { task.rooIgnoreController, ) if (defResult) { - const notice = `Showing only ${maxReadFileLine} of ${totalLines} total lines. Use line_range if you need to read more lines` + const notice = `Showing code definitions only (0 of ${totalLines} total lines). To read file content, use the read_file tool with line_range (e.g., 1-${Math.min(500, totalLines)})` updateFileResult(relPath, { xmlContent: `${relPath}\n${defResult}\n${notice}\n`, nativeContent: `File: ${relPath}\nCode Definitions:\n${defResult}\n\nNote: ${notice}`, @@ -493,7 +493,8 @@ export class ReadFileTool extends BaseTool<"read_file"> { nativeInfo += `\nCode Definitions:\n${truncatedDefs}\n` } - const notice = `Showing only ${maxReadFileLine} of ${totalLines} total lines. Use line_range if you need to read more lines` + const nextLine = maxReadFileLine + 1 + const notice = `File truncated at line ${maxReadFileLine} of ${totalLines} total lines. To continue reading, use the read_file tool again with line_range starting at line ${nextLine} (e.g., ${nextLine}-${Math.min(nextLine + 499, totalLines)})` xmlInfo += `${notice}\n` nativeInfo += `\nNote: ${notice}` @@ -547,8 +548,9 @@ export class ReadFileTool extends BaseTool<"read_file"> { content = addLineNumbers(result.content) if (!result.complete) { - // File was truncated - const notice = `File truncated: showing ${result.lineCount} lines (${result.tokenCount} tokens) due to context budget. Use line_range to read specific sections.` + // File was truncated due to context budget + const nextLine = result.lineCount + 1 + const notice = `File truncated at line ${result.lineCount} of ${totalLines} total lines due to context budget (${result.tokenCount} tokens used). To continue reading, use the read_file tool again with line_range starting at line ${nextLine} (e.g., ${nextLine}-${Math.min(nextLine + 499, totalLines)})` const lineRangeAttr = result.lineCount > 0 ? ` lines="1-${result.lineCount}"` : "" xmlInfo = result.lineCount > 0 diff --git a/src/core/tools/__tests__/readFileTool.spec.ts b/src/core/tools/__tests__/readFileTool.spec.ts index d22c163636f..08b0edc7ade 100644 --- a/src/core/tools/__tests__/readFileTool.spec.ts +++ b/src/core/tools/__tests__/readFileTool.spec.ts @@ -423,7 +423,7 @@ describe("read_file tool with maxReadFileLine setting", () => { expect(result).toContain(``) // Verify XML structure - expect(result).toContain("Showing only 0 of 5 total lines") + expect(result).toContain("Showing code definitions only (0 of 5 total lines)") expect(result).toContain("") expect(result).toContain("") expect(result).toContain(sourceCodeDef.trim()) @@ -450,7 +450,7 @@ describe("read_file tool with maxReadFileLine setting", () => { expect(result).toContain(`${testFilePath}`) expect(result).toContain(``) expect(result).toContain(``) - expect(result).toContain("Showing only 3 of 5 total lines") + expect(result).toContain("File truncated at line 3 of 5 total lines") }) it("should truncate code definitions when file exceeds maxReadFileLine", async () => { @@ -481,7 +481,7 @@ describe("read_file tool with maxReadFileLine setting", () => { expect(result).not.toContain("50--60 | function bar()") expect(result).not.toContain("80--90 | function baz()") - expect(result).toContain("Showing only 30 of 100 total lines") + expect(result).toContain("File truncated at line 30 of 100 total lines") }) it("should handle truncation when all definitions are beyond the line limit", async () => {