Skip to content

fix: handle tail rewrites with read tail-lines#412

Merged
pszymkowiak merged 2 commits intortk-ai:developfrom
gula00:fix/tail-rewrite-lines
Mar 11, 2026
Merged

fix: handle tail rewrites with read tail-lines#412
pszymkowiak merged 2 commits intortk-ai:developfrom
gula00:fix/tail-rewrite-lines

Conversation

@gula00
Copy link
Copy Markdown
Contributor

@gula00 gula00 commented Mar 8, 2026

Closes #407

Summary

This PR fixes the tail -N rewrite regression where:

  • rtk rewrite "tail -20 <file>" incorrectly produced rtk read -20 <file>
  • the rewritten command then failed because rtk read does not accept that flag format

What changed

  • Added tail-specific rewrite handling in src/discover/registry.rs:

    • tail -N <file> -> rtk read <file> --tail-lines N
    • tail -n N <file> -> rtk read <file> --tail-lines N
    • tail --lines=N <file> -> rtk read <file> --tail-lines N
    • tail --lines N <file> -> rtk read <file> --tail-lines N
  • Added --tail-lines support to rtk read in:

    • src/main.rs
    • src/read.rs
  • Made --tail-lines and --max-lines mutually exclusive

  • Kept unsupported tail forms (e.g. tail -c) as no-rewrite fallback for safety

Validation

  • Added unit tests for rewrite mappings and read tail behavior

  • Ran:

    • cargo fmt --all
    • cargo clippy --all-targets
    • cargo test --all

@pszymkowiak pszymkowiak changed the base branch from master to develop March 11, 2026 18:53
- apply_line_window() now preserves trailing newline when input has one
- Add test for tail --lines N (space form) rewrite
- Add test for tail_lines without trailing newline

Signed-off-by: Patrick <patrick@rtk-ai.com>
Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
@pszymkowiak
Copy link
Copy Markdown
Collaborator

Thanks for the contribution @gula00! Great work on the tail -N rewrite support.

I pushed two small fixes to your branch before merging:

  1. Trailing newline preservationapply_line_window() was using str::lines().join("\n") which drops the final \n. Now preserves it when the input has one.
  2. Missing test — Added coverage for tail --lines 7 file (space form without =), the TAIL_LINES_SPACE regex was untested.

All 718 tests pass. Merging into develop.

@pszymkowiak pszymkowiak merged commit a314927 into rtk-ai:develop Mar 11, 2026
1 of 3 checks passed
@gula00 gula00 deleted the fix/tail-rewrite-lines branch March 12, 2026 01:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tail -N fails when rewritten to rtk read

2 participants