fix: head/tail multi-file rewrite falls back to native command (#1362)#1371
fix: head/tail multi-file rewrite falls back to native command (#1362)#1371aeppling merged 1 commit intortk-ai:developfrom
Conversation
…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`.
📊 Automated PR Analysis
SummaryTightens 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 Review Checklist
Linked issues: #1362 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
pszymkowiak
left a comment
There was a problem hiding this comment.
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.
|
LGTM for temporary fix. Follow up: RTK should be able to handle multiple file rewrite correctly |
Summary
head/tailregexes insrc/discover/registry.rsso that each one only matches a single file argument (\S+$instead of(.+)$).rewrite_line_rangenow returnsNoneand the shell runs the nativehead/tailbinary, which already emits the==> name <==banners thatrtk read --max-linescannot reproduce.rtk read file1 file2 ... --max-lines N#1362 — same class as thecatmulti-file fallback in Cat multiple files result in an error #989.Before:
head -3 /tmp/a /tmp/b /tmp/cwas rewritten tortk read /tmp/a /tmp/b /tmp/c --max-lines 3, silently mis-handled and occasionally falling through to the systemreadbuiltin on macOS.After: the same command is not rewritten; native
headruns 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 insrc/discover/registry.rs).rtk rewrite "head -3 /tmp/a /tmp/b /tmp/c"now exits 1 (no rewrite); single-file form still rewrites tortk read /tmp/a --max-lines 3as before.head -20 src/main.rs,tail -n 12 src/lib.rs,tail --lines=7 src/lib.rs,head --lines=50 src/lib.rsall still rewrite correctly.Vibe Coded by Ousama Ben Younes
Developed With Ora Studio (Claude Code)