fix: head/tail multi-file rewrite falls back to native command (#1362)#1371
Open
ousamabenyounes wants to merge 1 commit intortk-ai:developfrom
Open
fix: head/tail multi-file rewrite falls back to native command (#1362)#1371ousamabenyounes wants to merge 1 commit intortk-ai:developfrom
ousamabenyounes wants to merge 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`.
Collaborator
📊 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. |
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.
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.