Parent: #3202
Problem
Workspace tools have finite inputs, but several materialize very large files or aggregate unbounded record counts before applying output limits:
- structural-analysis dependencies/references/exports modes scan all files, accumulate all records, and duplicate the aggregate during JSON formatting; their
truncated status is not accurate;
- AST grep accumulates all matches before applying
maxResults;
- AST read-file reads and parses an explicitly selected file without the regular
read_file pre-read size gate;
- edit/patch/insert/delete paths can read complete large target files and create additional copies for diff/backup.
This is a workspace-finite aggregation/file-boundary problem, not a streaming subprocess problem.
Architecture
Reuse only the shared validated budget and truncation metadata contracts established by #3200. Do not force record aggregation or whole-file semantics through the head/tail stream collector.
Extend the existing packages/tools file-size gate used by read_file/read_line_range instead of creating a second gate. Keep record-count and traversal-stop policies in structural/AST tool modules.
Acceptance criteria
- structural-analysis modes enforce file/record/result budgets while traversing and report accurate partial-result metadata;
- AST grep stops accumulating when
maxResults is satisfied rather than collecting everything and slicing afterward;
- aggregate serialization avoids unnecessary full-result duplication;
- AST read-file and write/edit/patch helpers reuse a shared pre-read stat/size policy before parsing or copying oversized files;
- regular
read_file, read_line_range, and read_many_files behavior remains compatible and their existing acquisition bounds are preserved;
- partial workspace analyses are clearly identified as partial.
Behavioral tests
Use Bun and bun:test with real fixture trees/files:
- structural dependencies/references/exports beyond record and file budgets;
- AST grep with far more matches than requested;
- exact-limit and one-byte-over files for AST read and modification paths;
- abort during a large traversal;
- aggregate output that proves bounded collection without mock-only call-count assertions.
Non-goals
- No AST parser/language redesign.
- No generic streaming result protocol.
- Do not modify the shared head/tail collector for record aggregation.
- No separate file-size utility when the existing gate can be extended.
Parent: #3202
Problem
Workspace tools have finite inputs, but several materialize very large files or aggregate unbounded record counts before applying output limits:
truncatedstatus is not accurate;maxResults;read_filepre-read size gate;This is a workspace-finite aggregation/file-boundary problem, not a streaming subprocess problem.
Architecture
Reuse only the shared validated budget and truncation metadata contracts established by #3200. Do not force record aggregation or whole-file semantics through the head/tail stream collector.
Extend the existing
packages/toolsfile-size gate used byread_file/read_line_rangeinstead of creating a second gate. Keep record-count and traversal-stop policies in structural/AST tool modules.Acceptance criteria
maxResultsis satisfied rather than collecting everything and slicing afterward;read_file,read_line_range, andread_many_filesbehavior remains compatible and their existing acquisition bounds are preserved;Behavioral tests
Use Bun and
bun:testwith real fixture trees/files:Non-goals