You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/tools/builtin.rs
+15-19Lines changed: 15 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -138,7 +138,7 @@ impl Tool for ReadFileTool {
138
138
}
139
139
140
140
fndescription(&self) -> &str{
141
-
"Read the contents of a local file. Provide the absolute or relative path to the file. You can optionally read specific lines by specifying start_line and end_line (1-indexed, inclusive) capped at a maximum of 100 lines per call."
141
+
"Read the contents of a local file. Provide the absolute or relative path to the file. You can read specific lines by specifying start_line and end_line (1-indexed, inclusive) capped at a maximum of 100 lines per call, so you can call this tool multiple times to read a file with more than 100 lines when needed."
142
142
}
143
143
144
144
fnparameters(&self) -> Value{
@@ -151,14 +151,14 @@ impl Tool for ReadFileTool {
151
151
},
152
152
"start_line":{
153
153
"type":"integer",
154
-
"description":"Optional starting line number (1-indexed, inclusive)"
154
+
"description":"Starting line number (1-indexed, inclusive)"
155
155
},
156
156
"end_line":{
157
157
"type":"integer",
158
-
"description":"Optional ending line number (1-indexed, inclusive)"
158
+
"description":"Ending line number (1-indexed, inclusive)"
159
159
}
160
160
},
161
-
"required":["path"]
161
+
"required":["path","start_line","end_line"]
162
162
})
163
163
}
164
164
@@ -170,22 +170,19 @@ impl Tool for ReadFileTool {
170
170
171
171
let actual_path = resolve_path(path_str,&self.workspace_dir,self.restrict_to_workspace)?;
172
172
173
-
let start_line = args.get("start_line").and_then(|v| v.as_u64());
174
-
let end_line = args.get("end_line").and_then(|v| v.as_u64());
173
+
let start_line = args
174
+
.get("start_line")
175
+
.and_then(|v| v.as_u64())
176
+
.ok_or("Missing 'start_line' argument")?;
177
+
let end_line = args
178
+
.get("end_line")
179
+
.and_then(|v| v.as_u64())
180
+
.ok_or("Missing 'end_line' argument")?;
175
181
176
182
let content = fs::read_to_string(&actual_path).map_err(|e| e.to_string())?;
177
183
178
-
if start_line.is_none() && end_line.is_none(){
179
-
// No lines specified, check total lines
180
-
let total_lines = content.lines().count();
181
-
if total_lines > 100{
182
-
returnErr(format!("File is too large ({} lines). Please specify start_line and end_line to read a maximum of 100 lines at a time.", total_lines));
183
-
}
184
-
returnOk(content);
185
-
}
186
-
187
-
let start = start_line.unwrap_or(1).max(1)asusize;
188
-
let end = end_line.unwrap_or(start asu64 + 99)asusize;
184
+
let start = start_line.max(1)asusize;
185
+
let end = end_line asusize;
189
186
190
187
if end < start {
191
188
returnErr("end_line must be greater than or equal to start_line".to_string());
@@ -201,8 +198,7 @@ impl Tool for ReadFileTool {
201
198
202
199
let snippet:Vec<String> = lines[actual_start - 1..actual_end]
203
200
.iter()
204
-
.enumerate()
205
-
.map(|(i, l)| format!("{:4}: {}", actual_start + i, l))
0 commit comments