Repository navigation
Conversation
|
|
a437345 to
bc216fc
Compare
`rg` and `grep` were both rewritten to `rtk grep`, which always ran ripgrep as its backend. That collapsed the two tools' identities and broke whichever one didn't match the backend: ripgrep-only flags (`--glob`, `-g`, `-P`, `--files`) failed because the command fell through to system grep, while grep commands silently misbehaved under rg (e.g. `-r` is recursive in grep but `--replace` in rg, so `grep -rn foo` rewrote every match). Preserve the invoked tool's identity from the rewrite onward, so each command runs its own backend with its own semantics and there is never any crossover: - rewrite: `grep ...` -> `rtk grep`, `rg ...` -> `rtk rg` (split the single rule). - `rtk rg` (new subcommand): faithful ripgrep passthrough — all args forwarded verbatim, so rg-only flags work in any order — with RTK's by-file filtering (and raw streaming for info/list flags like `--files`). - `rtk grep`: now runs system grep (grep semantics: BRE, grep flags, `-r`), parsing grep's `file:line:content` output; `-t/--file-type` maps to grep `--include`. - shared `emit_filtered` takes a per-backend line parser (rg NUL form vs grep colon form). Fixes rtk-ai#2167. Also addresses rtk-ai#2060, rtk-ai#1651. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
bc216fc to
20eedd1
Compare
|
This pull request has been automatically marked as stale due to 90 days of inactivity. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. Your contribution is very much appreciated — we're sorry we haven't been able to review it yet. |
|
Thanks for digging into this. PR #2641 (merged 2026-06-26, commit eafadce) made rtk grep run grep and rtk rg run ripgrep by replacing src/cmds/system/grep_cmd.rs with src/cmds/system/search.rs and an engine parameter, which is the separation this PR was after; on the current develop binary |
Summary
rgandgrepwere both rewritten tortk grep, which always ran ripgrep as its backend. That collapsed the two tools into one and broke whichever didn't match the backend:--glob,-g,-P,--files) failed — the command fell through to system grep, which rejects them (rtk grep calls system grep instead of ripgrep — breaks -g/--glob flags #2167, rg --files is rewritten to rtk grep --files #2060, rtk fails to handle --pcre2 flag when agent tries to use rg #1651);-ris recursive in grep but--replacein rg, sogrep -rn foorewrote every match toninstead of searching.This PR preserves the invoked tool's identity from the rewrite onward, so each command runs its own backend with its own semantics — no crossover in either direction.
Design
grep …rtk grep-r)rg …rtk rg--glob/-g/-P/--files, any order)^(rg\|grep)rule intogrep → rtk grepandrg → rtk rg.rtk rg(new subcommand): faithful ripgrep passthrough — all args forwarded verbatim (flattrailing_var_arg, so leading flags never break clap) — with RTK's by-file filtering; info/list flags (--files,--json, …) stream raw.rtk grep: now runs system grep, parsing grep'sfile:line:contentoutput;-t/--file-typemaps to grep--include. Keeps its documented-l/-m/-t/--context-onlyinterface.emit_filteredtakes a per-backend line parser (rg NUL formfile\0line:contentvs grep colon form).Why not "route everything through one backend"
The first iterations of this PR tried that (route rg-style fallbacks to rg). Review found it corrupts the other tool because grep and rg share short flags with conflicting meanings — most dangerously
grep -rn foo→ rg--replace=n→ every match rewritten. There is no safe way to run one tool's syntax through the other; the only correct fix is to keep them separate.Test plan
cargo fmt --check && cargo clippy --all-targets && cargo test— 1985 passed, 7 ignored, clippy clean, fmt cleanrg→rtk rg,grep→rtk grep),parse_grep_line,grep_type_glob,is_raw_passthrough_flagNotes
rtk grepnow runs system grep rather than ripgrep — a deliberate behavior change so grep semantics are respected (loses rg's speed/gitignore-awareness forgrepcommands; that's grep being grep).rtk rgis the path for ripgrep.