Repository navigation
Conversation
3 tasks done
This branch has not been deployed
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.
Human Overview
Description
The file tools treat a trailing newline as the start of a new empty line. For the canonical POSIX file
"alpha\nbeta\n"(2 lines,wc -l= 2),readreturns a phantom third line thatoffset=3can select, the footer saysof 3, andwritereportsWrote 3 lines. An empty file reads as one numbered line but writes as 0 lines, andread(limit=0)returns a misleading "offset None is past the end" message. Coding agents rely on these line numbers, so the phantom line sends them to a location that does not exist.Related Issues
None — small bug fix, no prior issue (duplicate search clean).
Documentation PR
Not needed — tool output is corrected, no API change.
Type of Change
Bug fix
Testing
Added five Python tests and five mirrored TypeScript tests: trailing-newline file has exactly two numbered lines with no phantom/footer;
offset=3reports[File has 2 lines; offset 3 is past the end.];write("alpha\nbeta\n")reportsWrote 2 lines; empty file is 0 lines consistently ([File is empty.]/Wrote 0 lines);limit=0raisesValueError("limit must be at least 1.").Red on
3bd98e6with the final tests: 5 failed inharness-py/tests/tools/test_file_tools.py, no collection errors. Green with the fix: Python 21 passed and TypeScript 21 passed (both file-tool suites).hatch run prepareAdditional Details
Extended context
str.split("\n")yields a final empty element for content ending in\n; that element is a terminator, not a line. Both SDKs now use one shared helper per language for bothreadandwrite, so the counts cannot drift.\rhandling is unchanged (splitting remains on\nonly). The Python harness package was installed from source in a dedicated venv using the CI command (pip install -e '.[dev]'); the committed tests ran against the real package. TypeScript tests ran vianpx vitest run test/tools/file-tools.test.ts.Checklist
By submitting this pull request, I confirm that I can use, modify, copy, and redistribute this contribution, under the terms of your choice.