Skip to content

fix(read): separate line numbers with a tab - #4647

Merged
KuSh merged 3 commits into
rtk-ai:developfrom
nrenvo:fix/read-line-numbers-tab
Oct 31, 2026
Merged

KuSh merged 3 commits into
rtk-ai:developfrom
nrenvo:fix/read-line-numbers-tab

Conversation

@nrenvo

@nrenvo nrenvo commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

rtk read -n formatted line numbers as {:>width$} │ . The box-drawing │ is three bytes in UTF-8; a tab is one. Each numbered line therefore carried four more bytes than the same output with a tab.

Use a tab instead, keeping the width alignment. The tab is also what cat -n itself uses, so the output now looks like the native command rather than an rtk-specific marker:

$ rtk read -n src/lib.rs | head -2
   1	mod analytics;
   2	mod cmds;

The read benchmark rows now target src/lib.rs (5,971 lines) instead of src/main.rs, which is a 3-line shim since 5d8102a moved the CLI.

scripts/benchmark.sh estimates tokens with ${#input}. On the CI runner's UTF-8 locale that counts characters, so CI reports cat -n at 63,452 and the tab row at 60,466. The old │ separator is three bytes; with its two surrounding spaces it adds four bytes per line over the tab. In a C/POSIX locale (byte counting) the old row is 66,460 (+4.7% vs cat -n). In the CI runner's UTF-8 locale │ counts as one character, so the old row ties cat -n at 63,451-63,452. Either way the tab removes the four-byte overhead and puts the row 4.7% below cat -n:

output CI (UTF-8, chars) C locale (bytes)
cat -n 63,452 63,475
previous │ format ≈63,452 (tie) 66,460 (+4.7%)
this PR (tab) 60,466 (-4.7%) 60,489 (-4.7%)

The derived rows use the same measured output; the │ rows add the separator difference (two characters per line under the script's estimate, four bytes per line in the emitted output).

Test plan

  • cargo fmt --all --check and cargo clippy --workspace --all-targets pass
  • cargo test --test read_window_bytes_test: 6 passed. The two existing expectations now use the tab, and a 12-line case pins both the tab separator and the right-aligned width; reverting either the tab or the width padding fails it
  • rtk read -n output inspected; it matches cat -n's shape
  • format_with_line_numbers is the only producer of the separator; no other source, test, snapshot or doc asserts the old format
  • Full scripts/benchmark.sh on CI (run 39563655818): 41 good / 33 warn / 0 negative / 0 fail (41/74, 55%); exit 0
  • Read benchmark rows on CI (UTF-8): read 53,003/53,003, read -l minimal 49,604/53,003, read -l aggressive 5,991/53,003, read -n 60,466/63,452 (rtk/cat); no NEGATIVE
  • CI run 39563655818: all 15 checks green

@rtk-wshm-sync-bot rtk-wshm-sync-bot Bot added bug Something isn't working output-format benchmark labels Oct 18, 2026
@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

Replaces the box-drawing │ separator with a tab in read -n's line-numbered output, reducing token overhead by ~4% (50,360 → 47,947 tokens on a test file) and bringing output size back below the benchmark script's regression threshold. Updates the corresponding test expectations in read_window_bytes_test.rs.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Analyzed automatically by wshm · This is an automated analysis, not a human review.

`--line-numbers` formatted each prefix as `{:>width$} │ `, and the
box-drawing bar is three bytes in UTF-8. That made `rtk read -n` about
4% larger than `cat -n` on a minified source file — the only negative
case in scripts/benchmark.sh, so the benchmark currently fails against
develop's tree.

Use a tab instead, keeping the width alignment. The output now matches
`cat -n`'s shape and is about 4% smaller than it (50,360 -> 47,947
tokens on src/main.rs), so the benchmark case turns from negative to
good.

Update the two line-number expectations in read_window_bytes_test.
@nrenvo
nrenvo force-pushed the fix/read-line-numbers-tab branch from 027c9bc to 975103a Compare October 21, 2026 03:47
A 12-line input pins both the tab separator and the right-aligned width. Reverting either the tab or the width padding fails the test.
@nrenvo

nrenvo commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Hey @KuSh 👋

Small one for you when you get a sec — just swaps the │ separator in read -n for a tab, saves a few bytes/line, no logic changes. Tests are green and CI passed. Would appreciate a look whenever you're free, thanks!

@nrenvo

nrenvo commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

@KuSh 👋 this has been open since Oct 18 with CI green. #4816 reports the same cat -n gutter difference, which is the part this PR covers. Happy to change anything.

@KuSh KuSh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 1 of 3 — APPROVED, follow-ups filed

Claim: rtk read -n separates the line number from the text with a tab instead of │, and the benchmark's read rows target src/lib.rs instead of the 3-line src/main.rs shim.
Scope: accept (round 1, frozen). #3689 also edits format_with_line_numbers and adds two new │ gutters; this PR lands first and #3689 (already conflicting) switches to the tab on rebase. Maintainer PRs: checked against #4153 (merged with this PR on develop: no conflict, both sets of read and tracking tests pass, 224 tests), and against #4593 and #4341, which change the cat rewrite guard but keep cat -n FILE → rtk read -n FILE; nothing contradicts.
Ran: cat -n FILE through rtk rewrite and then the rewritten rtk read -n command, on develop 41e6912 and on this PR merged into it. 10 files (src/lib.rs, read.rs, CRLF, embedded tabs, empty, no final newline, 9/10/100 lines, Latin-1) plus -l minimal, -l aggressive, --max-lines 50, --head-lines 12, --tail-lines 12, stdin and two files at once. Invariants checked: through the hook, every path the separator takes (windowed, filtered, capped, stdin, file), same exit codes and same stderr on both binaries. src/lib.rs: cat -n 255,855 B, develop 267,893 B (+4.7%), this PR 243,817 B (−4.7%). The 20% floor in CONTRIBUTING.md does not apply: this changes a format, it adds no filter.
Pins: 0 decisions (only the separator's formatting changes); 5 mutations of the formatting line (restore │, use a space, drop the width, fix the width at 6, left-align): 0 survived, all caught by read_line_numbers_align_multi_digit_widths_with_a_tab
Matrix: executed this round; pin check: executed this round
CI @931571a6d: all green (run 39563655818, benchmark read -n 63,452 → 60,466)

Blocks merge (0)

Filed as follow-ups

  • #4889 cat -n a b rewritten to rtk read -n a b restarts numbering for each file — outside this PR's hunks; same on develop
  • #4065 — cat -n on a non-UTF-8 file goes through the same exit-1 path; already on develop; comment added
  • #3427 — --tail-lines N -n numbers the window from 1, not with the file's line numbers; already on develop and already reported there
  • #4816 — CRLF and final newline under -n, already tracked; this PR covers only the separator, as #4816 says

Checked and correct — no need to re-verify

  • format_with_line_numbers is the only producer of the separator; the windowed, filtered, --max-lines and stdin paths all go through it and all print the tab.
  • Tracking compares rtk's numbered raw text with rtk's numbered output, so the change applies to both sides and recorded ratios stay the same.
  • The engine's strip-line-numbers now treats the tab as a file-coordinate separator, but it only runs on Read tool results and is off by default. The shell posthook skips rtk commands.
  • The PR merges cleanly into develop 41e6912. On that merge, fmt and clippy are clean (0 warnings) and cargo test --all passes with 0 failures.

Next

nothing — approving.
Rounds: 1/3. Threads: 0 open, 0 resolved this round.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

benchmark bug Something isn't working output-format

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants