Repository navigation
fix(read): keep true file line numbers under --tail-lines -n - #12
Merged
Merged
Conversation
`rtk read <file> --tail-lines N -n` renumbered the surviving tail window from 1, so a model reading the output was told the last N lines were lines 1..N when they are really the final N lines of the file. That mislabels the line references the model reasons over (the output-mangling class). apply_line_window now returns the 1-based original position of the first emitted line (total - tail + 1 for a tail window, 1 otherwise), and format_with_line_numbers renders the gutter from that offset. Gutter width is sized for the largest number actually printed so high offsets stay aligned. max-lines/smart_truncate keeps a non-contiguous top selection, so it stays 1-based. Adds regression + edge-case tests (tail offset, width, empty, tail=0, tail>len).
|
👋 Thanks for the PR! It looks like this targets Please update the base branch:
See CONTRIBUTING.md for details. |
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.
Problem
rtk read <file> --tail-lines N -nrenumbered the surviving tail window starting from1. A model reading the output was told the last N lines of the file were lines1..N, when they are actually the final N lines. Example (5-line file):This is the output-mangling class (same family as the grep #6 / wc #8 / tree #9 / find #10 fixes): a filter corrupts the information the model reasons over — here, the line references it would cite.
Fix
apply_line_windownow returns(windowed_text, start_offset)wherestart_offsetis the 1-based original position of the first emitted line (total - tail + 1for a tail window,1otherwise).format_with_line_numbersrenders the gutter from that offset; gutter width is sized for the largest number actually printed so a high offset (e.g. lines 9–10) stays aligned.--max-lines/smart_truncatekeeps a non-contiguous selection starting at line 1, so it correctly stays 1-based (already signals omissions via the[N more lines]marker).After:
Tests
Adds a RED-on-revert regression (
test_format_line_numbers_with_tail_offset— fails with1 │ l4if the offset wiring is reverted) plus edge cases: width across a digit boundary, empty content (no panic), tail=0, tail>len, and the no-window / max-lines offset invariants.Verification
cargo fmt --checkcleancargo clippy --all-targets -- -D unsafe_codecleancargo test --allgreen (1752 + 12 pass)cargo build --release+ manual E2E confirm the corrected gutter