Skip to content
Draft
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
10 changes: 6 additions & 4 deletions src/core/tools/ReadFileTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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., <line_range>1-${Math.min(500, totalLines)}</line_range>)`
updateFileResult(relPath, {
xmlContent: `<file><path>${relPath}</path>\n<list_code_definition_names>${defResult}</list_code_definition_names>\n<notice>${notice}</notice>\n</file>`,
nativeContent: `File: ${relPath}\nCode Definitions:\n${defResult}\n\nNote: ${notice}`,
Expand Down Expand Up @@ -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., <line_range>${nextLine}-${Math.min(nextLine + 499, totalLines)}</line_range>)`
xmlInfo += `<notice>${notice}</notice>\n`
nativeInfo += `\nNote: ${notice}`

Expand Down Expand Up @@ -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., <line_range>${nextLine}-${Math.min(nextLine + 499, totalLines)}</line_range>)`
const lineRangeAttr = result.lineCount > 0 ? ` lines="1-${result.lineCount}"` : ""
xmlInfo =
result.lineCount > 0
Expand Down
6 changes: 3 additions & 3 deletions src/core/tools/__tests__/readFileTool.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ describe("read_file tool with maxReadFileLine setting", () => {
expect(result).toContain(`<list_code_definition_names>`)

// Verify XML structure
expect(result).toContain("<notice>Showing only 0 of 5 total lines")
expect(result).toContain("<notice>Showing code definitions only (0 of 5 total lines)")
expect(result).toContain("</notice>")
expect(result).toContain("<list_code_definition_names>")
expect(result).toContain(sourceCodeDef.trim())
Expand All @@ -450,7 +450,7 @@ describe("read_file tool with maxReadFileLine setting", () => {
expect(result).toContain(`<file><path>${testFilePath}</path>`)
expect(result).toContain(`<content lines="1-3">`)
expect(result).toContain(`<list_code_definition_names>`)
expect(result).toContain("<notice>Showing only 3 of 5 total lines")
expect(result).toContain("<notice>File truncated at line 3 of 5 total lines")
})

it("should truncate code definitions when file exceeds maxReadFileLine", async () => {
Expand Down Expand Up @@ -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("<notice>Showing only 30 of 100 total lines")
expect(result).toContain("<notice>File truncated at line 30 of 100 total lines")
})

it("should handle truncation when all definitions are beyond the line limit", async () => {
Expand Down
Loading