Skip to content

Commit fae5a37

Browse files
committed
feat(read_file): enhance file reading capabilities with multi-file support and improved parameter handling
1 parent 7e76736 commit fae5a37

File tree

4 files changed

+206
-187
lines changed

4 files changed

+206
-187
lines changed

src/core/prompts/sections/tool-use.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ Tool use is formatted using XML-style tags. The tool name is enclosed in opening
1717
1818
For example:
1919
20-
<read_file>
21-
<path>src/main.js</path>
22-
</read_file>
20+
<new_task>
21+
<mode>code</mode>
22+
<message>Implement a new feature for the application.</message>
23+
</new_task>
2324
2425
Always adhere to this format for the tool use to ensure proper parsing and execution.`
2526
}

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

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,70 @@ import { ToolArgs } from "./types"
22

33
export function getReadFileDescription(args: ToolArgs): string {
44
return `## read_file
5-
Description: Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. The output includes line numbers prefixed to each line (e.g. "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code. By specifying start_line and end_line parameters, you can efficiently read specific portions of large files without loading the entire file into memory. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string.
5+
Description: Request to read the contents of one or more files. 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.
6+
67
Parameters:
7-
- path: (required) The path of the file to read (relative to the current workspace directory ${args.cwd})
8-
- start_line: (optional) The starting line number to read from (1-based). If not provided, it starts from the beginning of the file.
9-
- end_line: (optional) The ending line number to read to (1-based, inclusive). If not provided, it reads to the end of the file.
8+
- args (required): File read operations in the following format:
9+
:path: File path (relative to workspace directory ${args.cwd})
10+
:start_line: (optional) Starting line number (1-based)
11+
:end_line: (optional) Ending line number (1-based, inclusive)
12+
13+
Multiple files can be read in a single request by separating entries with "======+++======". Each entry follows the same format with its own path and optional line range.
14+
1015
Usage:
1116
<read_file>
12-
<path>File path here</path>
13-
<start_line>Starting line number (optional)</start_line>
14-
<end_line>Ending line number (optional)</end_line>
17+
<args>
18+
:path:path/to/file
19+
:start_line:1
20+
:end_line:100
21+
</args>
1522
</read_file>
1623
1724
Examples:
1825
19-
1. Reading an entire file:
26+
1. Reading a single file:
2027
<read_file>
21-
<path>frontend-config.json</path>
28+
<args>
29+
:path:src/app.ts
30+
:start_line:1
31+
:end_line:1000
32+
</args>
2233
</read_file>
2334
24-
2. Reading the first 1000 lines of a large log file:
35+
2. Reading specific lines from multiple files:
2536
<read_file>
26-
<path>logs/application.log</path>
27-
<end_line>1000</end_line>
37+
<args>
38+
:path:src/app.ts
39+
:start_line:1
40+
:end_line:1000
41+
======+++======
42+
:path:src/utils.ts
43+
:start_line:10
44+
:end_line:20
45+
</args>
2846
</read_file>
2947
30-
3. Reading lines 500-1000 of a CSV file:
48+
3. Reading an entire file (omitting line ranges):
3149
<read_file>
32-
<path>data/large-dataset.csv</path>
33-
<start_line>500</start_line>
34-
<end_line>1000</end_line>
50+
<args>
51+
:path:config.json
52+
</args>
3553
</read_file>
3654
37-
4. Reading a specific function in a source file:
55+
4. Reading multiple files with different ranges:
3856
<read_file>
39-
<path>src/app.ts</path>
40-
<start_line>46</start_line>
41-
<end_line>68</end_line>
57+
<args>
58+
:path:src/app.ts
59+
:start_line:1
60+
:end_line:50
61+
======+++======
62+
:path:src/utils.ts
63+
:start_line:100
64+
:end_line:150
65+
======+++======
66+
:path:package.json
67+
</args>
4268
</read_file>
4369
44-
Note: When both start_line and end_line are provided, this tool efficiently streams only the requested lines, making it suitable for processing large files like logs, CSV files, and other large datasets without memory issues.`
70+
Note: Line ranges enable efficient streaming of specific portions from large files like logs or datasets.`
4571
}

0 commit comments

Comments
 (0)