feat(tools): windowed file_read via offset/limit line range (#74) - #78
Merged
Conversation
Add line-range reads to file_read so the agent can page through large
files instead of reading the whole file and getting blunt-truncated at
8000 bytes — directly cutting tokens and letting it reach content past
the cap (previously unreachable). Pairs with grep's line numbers:
grep hits line 420 -> file_read {path, offset:400, limit:60}.
- tools/file.zig: readLineRange() returns a LineWindow {text, total_lines,
start_line, end_line}. 1-based offset, optional limit (null = to EOF),
editor line convention (trailing newline doesn't add an empty line),
clamps offset/limit, empty-file and out-of-range yield an empty window.
Still bounded by the 1 MiB whole-file read limit (this saves tokens fed
to the model, not file I/O).
- agent.zig: FileReadArgs gains optional offset/limit. A shared
fileReadObservation() helper is used by both execTool and the parallel
worker (execReadTool), so windowed reads also work inside `parallel`.
Whole-file path (no offset/limit) is unchanged. The observation now
reports "第 X-Y 行 / 共 Z 行" for windowed reads, or an explicit
out-of-range note. Updated the file_read action description.
- Tests: readLineRange (window/clamp/out-of-range/no-trailing-newline/
empty) and fileReadObservation (whole vs windowed vs out-of-range).
Closes #74.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Closes #74. Adds windowed
file_readso the agent can page through large files instead of reading the whole file and getting blunt-truncated at 8000 bytes. This cuts tokens and makes content past the cap reachable (previously impossible). It pairs naturally with grep's line numbers:Changes
tools/file.zig—readLineRange()→LineWindow {text, total_lines, start_line, end_line}. 1-basedoffset, optionallimit(null = to EOF), editor line convention (trailing newline ≠ extra blank line), clamps offset/limit, empty-file & out-of-range return an empty window. Still bounded by the existing 1 MiB whole-file read limit — this saves tokens fed to the model, not file I/O.agent.zig—FileReadArgsgains optionaloffset/limit. A sharedfileReadObservation()helper is used by bothexecTooland the parallel worker (execReadTool), so windowed reads also work insideparallel. Whole-file path (no offset/limit) is byte-for-byte unchanged. Windowed observation reports第 X-Y 行 / 共 Z 行, or an explicit out-of-range note. Updated thefile_readaction description.Behavior
{"path":"f"}{"path":"f","offset":400,"limit":60}第 400-459 行 / 共 N 行{"path":"f","offset":99999}offset … 超出文件总行数 NTests
readLineRange: mid window, read-to-EOF, limit past EOF clamps, out-of-range, no-trailing-newline, empty file.fileReadObservation: whole vs windowed vs out-of-range.Verification
zig build✅ ·zig build test✅ (all green). First of the token-efficiency group (#70–#77).