You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
read reports a phantom last line and an inflated total for any file ending in a newline #764
finishLine is the handler for a partial last line — one with no trailing
newline. For a file that ends in a newline, consume has already flushed every
line and left state.line empty, so finishLine still runs: it increments the
line counter and pushes an empty string.
So a two-line file is reported as three lines, and the tool prints a numbered
empty line for it. On 3e94875c:
<file>
00001| a
00002| b
00003|
(End of file - total 3 lines)
</file>
Three consequences, all visible to the model:
(End of file - total N lines) is one too high.
A phantom 00003| line is printed.
lastReadLine = offset + raw.length feeds the "Use 'offset' parameter to read
beyond line N" hint, so paging is off by one too: reading a three-line file
with offset: 2 returns 00003| threeand a phantom 00004|.
Almost every source file ends in a newline, so this fires on essentially every
read. A file with no trailing newline is unaffected, which is why the existing
cases did not catch it.
Steps to reproduce
Write a file that ends in a newline, e.g. printf 'a\nb\n' > two.txt.
Ask the agent to read it.
Read the tool output: a third, empty line is printed and the total says 3.
The two focused regressions in test/tool/read.test.ts fail on 3e94875c and
pass with the fix.
How did you install OpenScience?
From source (bun dev).
OpenScience version
Source commit 3e94875c.
Provider and model
Not applicable; the defect is in how the file is rendered, before any model call.
Operating system
Not OS-specific; reproduced in the Bun test harness.
Activity