Skip to content

fix: head/tail multi-file rewrite falls back to native command (#1362)#1371

Merged
aeppling merged 1 commit intortk-ai:developfrom
ousamabenyounes:fix/issue-1362
May 3, 2026
Merged

fix: head/tail multi-file rewrite falls back to native command (#1362)#1371
aeppling merged 1 commit intortk-ai:developfrom
ousamabenyounes:fix/issue-1362

Conversation

@ousamabenyounes
Copy link
Copy Markdown
Contributor

@ousamabenyounes ousamabenyounes commented Apr 17, 2026

Summary

Before: head -3 /tmp/a /tmp/b /tmp/c was rewritten to rtk read /tmp/a /tmp/b /tmp/c --max-lines 3, silently mis-handled and occasionally falling through to the system read builtin on macOS.
After: the same command is not rewritten; native head runs unchanged with correct multi-file banners.

Test plan

  • cargo fmt --all --check && cargo clippy --all-targets && cargo test — 1596 pass / 0 fail / 6 ignored (6 new tests added, no clippy warnings introduced in src/discover/registry.rs).
  • Manual: rtk rewrite "head -3 /tmp/a /tmp/b /tmp/c" now exits 1 (no rewrite); single-file form still rewrites to rtk read /tmp/a --max-lines 3 as before.
  • Regression: head -20 src/main.rs, tail -n 12 src/lib.rs, tail --lines=7 src/lib.rs, head --lines=50 src/lib.rs all still rewrite correctly.

Important: All PRs must target the develop branch (not master).
See CONTRIBUTING.md for details.


Vibe Coded by Ousama Ben Younes
Developed With Ora Studio (Claude Code)

…tk-ai#1362)

`head -N file1 file2 ...` was rewritten to
`rtk read file1 file2 ... --max-lines N`. The capture regex was greedy
(`(.+)$`), so every file argument was folded into a single string. `rtk
read` then silently mis-handled the shape and fell through to the system
`read` builtin (`/usr/bin/read`) which rejects paths starting with `/` as
"not a valid identifier".

Tighten each head/tail regex to a single non-whitespace file argument
(`\S+$`). When >1 file is provided the regex misses, `rewrite_line_range`
returns `None`, and the command falls through to the native `head` / `tail`
binary — which already handles multi-file input with the expected
`==> name <==` banners. Same class as the cat multi-file fix in rtk-ai#989.

Added six regression tests covering the `-N`, `--lines=N`, `-n N`, and
`--lines N` variants for both `head` and `tail`.
@pszymkowiak pszymkowiak added bug Something isn't working effort-small Quelques heures, 1 fichier filter-quality Filter produces incorrect/truncated signal labels Apr 17, 2026
@pszymkowiak
Copy link
Copy Markdown
Collaborator

[w] wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

Tightens head/tail regex patterns in the command rewrite registry to only match single-file arguments, so multi-file invocations fall back to the native head/tail binaries which correctly emit per-file banners. This fixes incorrect rewriting of commands like head -3 /tmp/a /tmp/b /tmp/c that previously produced broken rtk read invocations.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #1362


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

Copy link
Copy Markdown
Collaborator

@pszymkowiak pszymkowiak left a comment

Choose a reason for hiding this comment

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

Clean fix. Changing (.+)$ to (\S+)$ correctly restricts rewrites to single-file invocations — multi-file head/tail falls through to native with ==> name <== banners as expected. Six targeted tests cover all affected patterns. LGTM.

@aeppling
Copy link
Copy Markdown
Contributor

aeppling commented May 3, 2026

LGTM for temporary fix.

Follow up:

RTK should be able to handle multiple file rewrite correctly

@aeppling aeppling merged commit f75a10b into rtk-ai:develop May 3, 2026
12 checks passed
@aeppling aeppling mentioned this pull request May 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working effort-small Quelques heures, 1 fichier filter-quality Filter produces incorrect/truncated signal

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants