Skip to content

feat(tools): windowed file_read via offset/limit line range (#74) - #78

Merged
jamiesun merged 1 commit into
mainfrom
feat/i74-windowed-read
Jun 18, 2026
Merged

feat(tools): windowed file_read via offset/limit line range (#74)#78
jamiesun merged 1 commit into
mainfrom
feat/i74-windowed-read

Conversation

@jamiesun

Copy link
Copy Markdown
Collaborator

What & why

Closes #74. Adds windowed file_read so 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:

grep → hit at line 420   →   file_read {"path":"…","offset":400,"limit":60}

Changes

  • tools/file.zigreadLineRange()LineWindow {text, total_lines, start_line, end_line}. 1-based offset, optional limit (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.zigFileReadArgs 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 byte-for-byte unchanged. Windowed observation reports 第 X-Y 行 / 共 Z 行, or an explicit out-of-range note. Updated the file_read action description.

Behavior

Input Result
{"path":"f"} whole file (unchanged), clipped at 8000 bytes
{"path":"f","offset":400,"limit":60} lines 400–459, labeled 第 400-459 行 / 共 N 行
{"path":"f","offset":99999} offset … 超出文件总行数 N

Tests

  • 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).

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>
@jamiesun
jamiesun merged commit 16cb52c into main Jun 18, 2026
2 checks passed
@jamiesun
jamiesun deleted the feat/i74-windowed-read branch June 18, 2026 07:10
@jamiesun jamiesun mentioned this pull request Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[tools] file_read 无行范围/偏移,大文件只能整读后截断(无分页,够不到尾部)

1 participant