Repository navigation
feat(tools): read_file v2 with a hash header, ranges, outline, and info (T3) - #35
Merged
Merged
Conversation
…fo (T3)
read_file's result now opens with `read <path> L<a>-<b>[,<c>-<d>]/<total>
h:<hash>` and numbers every line (`<n>\t<text>`, one gutter width per
call), so edit anchors and re-reads line up and a pruned stub keeps the
hash. New arguments: `ranges` (up to eight, merged and ascending,
separated by `--`), `mode=outline` (items from the per-language tables
that search already uses, nested by indentation, <= 400 rows),
`mode=info` (size, lines, hash, utf8, eol, perms, binary/mime), and
`if_changed_since=h:<hash>`, which answers `read <path> unchanged
h:<hash> lines=<n>` and still records the file for the staleness guard.
Bounds: 32 KiB model-facing default with the walk stopping on a whole
row and naming the resume offset instead of a head/tail cut; 2000-byte
line clip; the 4 MiB scan cap is unchanged. Typed failures:
invalid_ranges, invalid_offset, invalid_limit, invalid_if_changed_since,
range_out_of_bounds{last_line}, not_a_file, not_text, path_not_found,
path_escapes_workspace, outline_unsupported. Images answer info plus
hint=image_unsupported_by_model until T11.
TUI reads the row metric from the header (`L1-40 of 120 lines`,
`unchanged`, `3 items`, `info`) and hides it in the expanded body.
Prompt teaches the hash, ranges, and outline.
A 32 KiB String per read showed as +4% on tool_dispatch. Pinned A/B, 10 pairs: base 43.7 µs → cand 41.4 µs median.
cap_std::fs::PermissionsExt is cfg(unix); Windows reports ro/rw.
lg2m
force-pushed
the
feat/tool-layer-t3-read-file
branch
from
September 14, 2026 16:53
7f2b242 to
181ae4f
Compare
This was referenced Sep 14, 2026
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.
T3:
read_filev2 — hash header, ranges, outline, info,if_changed_sinceSpec: docs/plans/tool-layer.md § D2 (
read_file), task T3 Linear: ENG-773 Follows: #32 (T2)What changed
User-visible
read_fileresult opens withread <path> L<a>-<b>[,<c>-<d>]/<total> h:<hash>and numbers each line (<n>\t<text>, one gutter width per call). The header is what a pruned stub keeps, so the model retains the hash after the body is dropped.ranges: ["12", "40-80", "400-"]— up to eight windows in one call, merged when they overlap or touch, ascending, separated by--.offset/limitremains the one-range form; passing both isinvalid_ranges.if_changed_since: "h:<12 hex>"— when the file is unchanged the whole answer isread <path> unchanged h:<hash> lines=<n>and the file is still recorded for the staleness guard. A re-read before an edit now costs one line.mode: "outline"—L<line> <kind> <name>nested by indentation (≤ 400 rows) from the same per-language tablessearch mode=definitionuses (Rust, TS/JS, Python, Go, Zig, C/C++, Markdown headings).outline_unsupportedfor other languages.mode: "info"—size= lines= h: utf8= eol=lf|crlf|none perms= binary=[ mime=]on one line, for any file including binaries, whichlines/outlinerefuse withnot_text.truncated=bytes, and the marker namesoffset=<next>. Replaces the head/tail cut for reads (the shared bounding still backstops at 128 KiB).…+Nandclipped=counts them.png jpg gif webp) answerinfoplushint=image_unsupported_by_modelfrom every mode until T11.invalid_ranges,invalid_offset,invalid_limit,invalid_if_changed_since,range_out_of_bounds(withlast_line=),not_a_file,not_text,path_not_found,path_escapes_workspace,outline_unsupported.Read a.rs L1-40 of 120 lines,… · truncated,unchanged,3 items,info); the header is hidden in the expanded body. Prompt teaches the hash, ranges, and outline.Design
tools/read.rsrewritten around oneload()(contained path → metadata → read to the 4 MiB cap → hash) and three renderers. Rows are pushed whole-or-not-at-all against an escaped-byte budget so no partial last line ever reaches the model.lang.rsgainsLanguage::outline()— named-group tables compiled once per process (OnceLock), run multi-line over the whole buffer, with a small statement-keyword filter (if/for/return…) for the C function form and an indented-constfilter for TS/Zig locals. Thedefinitiontables are unchanged.Header::token()added for bare header tokens (L1-40/120,h:…,unchanged) alongsidefield().tool_dispatch). The body is now sized to the file.How verified
cargo test --workspace: 1346 passed / 0 failed; fmt andclippy -D warningsclean.rangesmerge/align/open-end/out-of-bounds plus nine typed failures;if_changed_sinceunchanged-then-changed with recording asserted both ways; outline/info/CRLF/binary/image; byte-budget stop with whole rows and the resume offset; TUI header metrics for all shapes. One test rewritten (read_file_stops_at_its_byte_budget_and_names_the_resume_offsetreplaces the head/tail assertion). Runtime/session assertions updated for the header.Measurements
tool_dispatchA/B (pinned core, 10 pairs, median)e441b17Evidence:
target/qq-perf/t3-2026-09-14/(untracked).Docs
docs/design/tools.md: § Built-In Tools updated; § Reading Files (new).docs/plans/progress/tool-layer.md: T2 shipped, T3 in review + receipt.Compatibility
read_fileoutput gains a header line and a line-number gutter. Oldoffset/limitcalls keep working. Persisted transcripts replay as-is; the TUI falls back to counting body lines for headerless results.if_changed_sincecompares the 12-hex short hash the header shows;rangesaccept an open end ("400-"); per-tool ceiling remains the shared 128 KiB.Follow-ups
h:as an optionaledit_fileprecondition. T11 replaces the image hint with an image block. T12's@ranges reuseparse_ranges.