Skip to content

fix(discover): route rg to rtk rg, not rtk grep - #2505

Closed
multicam wants to merge 1 commit into
rtk-ai:developfrom
multicam:fix/rg-passthrough-not-grep
Closed

multicam wants to merge 1 commit into
rtk-ai:developfrom
multicam:fix/rg-passthrough-not-grep

Conversation

@multicam

Copy link
Copy Markdown

Problem

rg and grep share the rtk grep rule (pattern: r"^(rg|rtk rg)\s+"), so rtk rewrite downgrades rg … → rtk grep …. But rtk grep is a POSIX-grep passthrough: it is not recursive and rejects ripgrep-only flags (--hidden, --glob/-g, --type). The result:

  • rg --hidden foo → rtk grep --hidden foo → unrecognised option '--hidden'
  • rg foo (recursive intent) → rtk grep foo → reads stdin instead of recursing

In agent/LLM tooling this reliably gets mis-read as "rg isn't installed" (it is) and triggers retry loops.

Fix

When the matched prefix is rg, route to rtk rg (rtk's faithful ripgrep wrapper) instead of rtk grep, preserving every ripgrep flag and rg's recursive/gitignore semantics. A real grep is unaffected — only the rg prefix is rerouted. Per-segment, so rg foo | grep bar rewrites only the rg half.

rg --hidden -g '*.rs' foo   →  rtk rg --hidden -g '*.rs' foo   (was: rtk grep …)
grep -rn foo .              →  rtk grep -rn foo .              (unchanged)

Tests

+3 unit tests in discover::registry::tests:

  • test_rewrite_rg_pattern — rg→rtk rg
  • test_rewrite_rg_preserves_ripgrep_flags — --hidden/-g survive
  • test_rewrite_grep_still_maps_to_rtk_grep — real grep untouched

Sibling to #2453 (compound-find rewrite); independent change, applies cleanly on develop.

🤖 Generated with Claude Code

`rg` and `grep` shared the `rtk grep` rule, but `rtk grep` is a POSIX-grep
passthrough: not recursive, and it rejects ripgrep-only flags
(--hidden/--glob/--type/-g). Downgrading `rg …` → `rtk grep …` silently broke
ripgrep semantics (flags bomb; bare form reads stdin instead of recursing),
which agents mis-read as "rg isn't installed". rtk already ships a faithful
`rtk rg`, so route an `rg` invocation there — preserving every flag + recursion.
Real `grep` is unaffected. +3 tests.
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@KuSh

KuSh commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator

Thanks for tracking this down and for the clear before and after. develop already routes rg to rtk rg: #2641 (merged 2026-06-26) stopped substituting one search engine for the other, and the registry rule landed with it. On the current build rtk rewrite "rg --hidden -g '*.rs' foo" returns rtk rg --hidden -g '*.rs' foo while grep -rn foo . still returns rtk grep -rn foo ., and the registry tests cover the same routing your tests added. If you still see rg downgraded to rtk grep on the latest develop, please comment here or reopen.

@KuSh KuSh closed this Sep 6, 2026
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.

3 participants