Skip to content

Commit 720fb58

Browse files
committed
fix(read_file): enhance description to include partial reads support
1 parent 118afad commit 720fb58

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

src/core/prompts/tools/read-file.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { ToolArgs } from "./types"
22

33
export function getReadFileDescription(args: ToolArgs): string {
4-
const maxConcurrentReads = args.settings?.maxConcurrentFileReads ?? 15;
5-
const isMultipleReadsEnabled = maxConcurrentReads > 1;
6-
4+
const maxConcurrentReads = args.settings?.maxConcurrentFileReads ?? 15
5+
const isMultipleReadsEnabled = maxConcurrentReads > 1
6+
77
return `## read_file
8-
Description: Request to read the contents of ${isMultipleReadsEnabled ? "one or more files" : "a file"}. The tool outputs line-numbered content (e.g. "1 | const x = 1") for easy reference when creating diffs or discussing code. Use line ranges to efficiently read specific portions of large files. Supports text extraction from PDF and DOCX files, but may not handle other binary files properly.
8+
Description: Request to read the contents of ${isMultipleReadsEnabled ? "one or more files" : "a file"}. The tool outputs line-numbered content (e.g. "1 | const x = 1") for easy reference when creating diffs or discussing code.${args.partialReadsEnabled ? " Use line ranges to efficiently read specific portions of large files." : ""} Supports text extraction from PDF and DOCX files, but may not handle other binary files properly.
99
1010
${isMultipleReadsEnabled ? `**IMPORTANT: You can read a maximum of ${maxConcurrentReads} files in a single request.** If you need to read more files, use multiple sequential read_file requests.` : "**IMPORTANT: Multiple file reads are currently disabled. You can only read one file at a time.**"}
1111
@@ -27,7 +27,7 @@ Usage:
2727
2828
Examples:
2929
30-
1. Reading a single file with one line range:
30+
1. Reading a single file${args.partialReadsEnabled ? " with one line range" : ""}:
3131
<read_file>
3232
<args>
3333
<file>
@@ -37,20 +37,28 @@ Examples:
3737
</args>
3838
</read_file>
3939
40-
${isMultipleReadsEnabled ? `2. Reading multiple files with different line ranges (within the ${maxConcurrentReads}-file limit):` : ""}${isMultipleReadsEnabled ? `
40+
${isMultipleReadsEnabled ? `2. Reading multiple files${args.partialReadsEnabled ? " with different line ranges" : ""} (within the ${maxConcurrentReads}-file limit):` : ""}${
41+
isMultipleReadsEnabled
42+
? `
4143
<read_file>
4244
<args>
4345
<file>
4446
<path>src/app.ts</path>
45-
${args.partialReadsEnabled ? `<line_range>1-50</line_range>
46-
<line_range>100-150</line_range>` : ""}
47+
${
48+
args.partialReadsEnabled
49+
? `<line_range>1-50</line_range>
50+
<line_range>100-150</line_range>`
51+
: ""
52+
}
4753
</file>
4854
<file>
4955
<path>src/utils.ts</path>
5056
${args.partialReadsEnabled ? `<line_range>10-20</line_range>` : ""}
5157
</file>
5258
</args>
53-
</read_file>` : ""}
59+
</read_file>`
60+
: ""
61+
}
5462
5563
${isMultipleReadsEnabled ? "3. " : "2. "}Reading an entire file (omitting line ranges):
5664
<read_file>
@@ -64,10 +72,14 @@ ${isMultipleReadsEnabled ? "3. " : "2. "}Reading an entire file (omitting line r
6472
IMPORTANT: You MUST use this Efficient Reading Strategy:
6573
- ${isMultipleReadsEnabled ? `You MUST read all related files and implementations together in a single operation (up to ${maxConcurrentReads} files at once)` : "You MUST read files one at a time, as multiple file reads are currently disabled"}
6674
- You MUST obtain all necessary context before proceeding with changes
67-
${args.partialReadsEnabled ? `- You MUST use line ranges to read specific portions of large files, rather than reading entire files when not needed
75+
${
76+
args.partialReadsEnabled
77+
? `- You MUST use line ranges to read specific portions of large files, rather than reading entire files when not needed
6878
- You MUST combine adjacent line ranges (<10 lines apart)
6979
- You MUST use multiple ranges for content separated by >10 lines
7080
- You MUST include sufficient line context for planned modifications while keeping ranges minimal
71-
` : ""}
81+
`
82+
: ""
83+
}
7284
${isMultipleReadsEnabled ? `- When you need to read more than ${maxConcurrentReads} files, prioritize the most critical files first, then use subsequent read_file requests for additional files` : ""}`
7385
}

0 commit comments

Comments
 (0)