Repository navigation
refactor(betterread): smaller, faster reads aligned with host output - #14
Conversation
|
|
@greptile-apps updated review requested: the finding was real, fixed in two commits. Confirmed (graded P2: unreachable with default 2000-line / 51,200 B budgets, reachable with small custom budgets and long lines). When no line fits the byte budget there was no way forward: the reader selected nothing, and the engine additionally raised a false "Offset out of range" error pointing at a valid offset. So retrying the same call repeated the same output forever. Fixed in 23dfe93: the engine only errors on genuinely out-of-range offsets, and the empty-window footer now reads "(Line N exceeds budget. Use offset=N+1 to continue.)", so pagination skips exactly the lines that do not fit and shows the rest. Follow-up in 18396f8: when the over-budget line is the last one, the footer reads "(Line N exceeds budget. End of file.)" instead of pointing past the end. Both pinned by failing-first tests (red before, green after, mutants killed); ceilings hold (bundle 48,012 B, 174 tests, snapshots unchanged). |
|
Verified the two follow-up commits. The original stall is fixed: an over-budget line now produces a continuation footer with |
…eduction # Conflicts: # bun.lock
This branch rewrites the read plugin (opencode-betterread) from the inside: same reads, less code, faster, with output sized to what the host can display. No features removed.
Numbers
The bundle grows slightly because it now includes the JPEG dimension parser and the host output budget. Code is down 27%.
What got simplified
Six files folded into five pieces with one job each: attachments, directory output, formatting, limits and tool. The intermediate index, duplicated structured escaping and the dead factory parameter are gone. Reading a file, a directory or a notebook now passes through fewer layers.
Faster reads
The text reader scanned quadratically in 64 KiB blocks: 2 MB of newlines took 2.5 seconds. The single-pass scanner takes 95 ms. Symlinks resolved serially; now in concurrent batches of 256. The first read after startup loaded the whole effect module (~155 ms); detection now runs before loading and takes ~8 ms.
Output respects what the host shows
The host truncates output at 2000 lines or ~50 KiB. The plugin used its own budget and the host cut blindly, with no continuation footer, forcing blind re-reads. The plugin now budgets against host limits and includes the footer with the exact offset to continue. The real saving is here: fewer wasted re-reads.
Fixed bugs
Dependencies
plugin 1.18.32, exact effect beta.83, TypeScript 7.0.2, Biome 2.5.14, @types/node from v24, bun-types 1.4.2 and packageManager [email protected].
Verification
Severity review with APTO verdict, 55 mutants evaluated (50 killed, 5 closed discards), 174/0 suite, clean check and typecheck. No behavior changes except directory order, which is intentional and documented.