From 5bf4eec3d8ae163fcda9b5c225abd87c54bdbf9b Mon Sep 17 00:00:00 2001 From: Roo Code Date: Sun, 21 Dec 2025 16:28:23 +0000 Subject: [PATCH 1/2] feat: improve context budget truncation notice with total lines and continuation example When files are truncated due to context budget limits, the truncation notice now includes: - Total number of lines in the file - The next line number to continue from - A concrete example of the line_range syntax This helps models understand why they received fewer lines than expected and how to continue reading. Addresses Issue #10239 --- src/core/tools/ReadFileTool.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/tools/ReadFileTool.ts b/src/core/tools/ReadFileTool.ts index 58f3cc495e1..b4ee651a6dd 100644 --- a/src/core/tools/ReadFileTool.ts +++ b/src/core/tools/ReadFileTool.ts @@ -547,8 +547,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 From 6e9486964ef3afcb637461aa0b9255f8b3edc816 Mon Sep 17 00:00:00 2001 From: Roo Code Date: Sun, 21 Dec 2025 16:40:06 +0000 Subject: [PATCH 2/2] fix: update remaining truncation notices with concrete line_range examples --- src/core/tools/ReadFileTool.ts | 5 +++-- src/core/tools/__tests__/readFileTool.spec.ts | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/core/tools/ReadFileTool.ts b/src/core/tools/ReadFileTool.ts index b4ee651a6dd..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}` 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 () => {