Simplify file read ranges

This commit is contained in:
Ollie Agent 2026-08-18 08:15:18 +02:00
parent d90bd77fa0
commit 9bd9539b6a
2 changed files with 2 additions and 15 deletions

View File

@ -1,6 +1,6 @@
{
"description": "Read a file with line numbers. Prefer segments over full reads.",
"prompt": "## file_read\n\nRead a file with line numbers. Prefer segments over full reads.\n\n**Args**: `path` (required), `start`, `end`, or `head`\n\n- `start`/`end`: 1-indexed line numbers, inclusive. Use integers. Max segment: 2000 lines.\n- No start/end: reads up to 500 lines from line 1.\n- `head`: read first N lines (alternative to start/end).\n\n```\nfile_read(path=\"<ABSOLUTE_PATH_FROM_PWD>\")\nfile_read(path=\"<ABSOLUTE_PATH_FROM_PWD>\", start=100, end=200)\nfile_read(path=\"<ABSOLUTE_PATH_FROM_PWD>\", head=50)\n```\n\n- Use `start`/`end` as integers even though they represent line numbers.\n- Use `head` as an integer alternative to `start`/`end`.\n\n**Constraints**: Absolute paths only.",
"prompt": "## file_read\n\nRead a file with line numbers. Prefer segments over full reads.\n\n**Args**: `path` (required), optional `start` and `end` line numbers\n\n- `start`/`end`: 1-indexed line numbers, inclusive. Use integers. Max segment: 2000 lines.\n- No `start`/`end`: reads up to 500 lines from line 1.\n\n```\nfile_read(path=\"<ABSOLUTE_PATH_FROM_PWD>\")\nfile_read(path=\"<ABSOLUTE_PATH_FROM_PWD>\", start=100, end=200)\n```\n\n- Use `start`/`end` as integers even though they represent line numbers.\n\n**Constraints**: Absolute paths only.",
"args": {
"type": "object",
"required": [
@ -18,10 +18,6 @@
"end": {
"type": "integer",
"description": "1-indexed end line, inclusive (max 2000 line segment). Use an integer."
},
"head": {
"type": "integer",
"description": "Read first N lines (alternative to start/end). Use an integer."
}
}
},

View File

@ -122,21 +122,12 @@ func Read(m map[string]any) (string, error) {
if start < 1 {
start = 1
}
hp, e := Int(m, "head", nil)
if e != nil {
return "", e
}
ep, e := Int(m, "end", nil)
if e != nil {
return "", e
}
end := start + MaxLines - 1
if hp != nil {
if *hp < 0 {
return "", fmt.Errorf("argument %q must be non-negative", "head")
}
end = start + *hp - 1
} else if ep != nil {
if ep != nil {
end = *ep
if end > start+MaxSegment-1 {
end = start + MaxSegment - 1