Files
hermes-agent/tests
Teknium 6f62aff7f2 fix(tools): read_file line accounting — count unterminated final lines, drop the phantom trailing line
Two long-standing, mutually-masking defects in read_file's line accounting,
present on all three read paths (compound shell probe, sequential probes,
native):

1. total_lines came from `wc -l`, which counts newline bytes: a file whose
   final line has no trailing newline was undercounted by one. For an
   N*limit+1-line file read in pages, the last page was never offered
   (truncated=False) and the past-EOF guard refused `offset=total` reads of
   the real final line.

2. _add_line_numbers() split on '\n' without dropping the single terminating
   newline, so every well-formed newline-terminated file rendered a phantom
   `N+1|` empty gutter line that does not exist in the file (models routinely
   tried to patch/reference it). Exactly one terminator is dropped, so a
   genuinely selected trailing blank line keeps its number (`cat -n`
   semantics).

Both fixes land at the shared choke point (_assemble_read_result /
_add_line_numbers) so the compound, sequential, and native paths agree.
Existing tests that froze the buggy rendering as expected output are updated
to the corrected contract.

Salvages community PRs #106888 (@nikkoxgonzales) and #49453
(@MaxFreedomPollard); same bug class independently reported/fixed in
 #3907/#3908, #3927, #20814, #22945, #42929, #55696, #91306.
Cross-validated against anomalyco/opencode#47420's read-page serialization
fix (their trailing-blank-line class; hermes' page path is already
blank-line-safe once the terminator handling is right — verified live).
2026-09-12 20:52:49 -07:00
..
…
…