Files
rtk-ai__rtk/tests/grep_context_test.rs
Adrien Eppling 0adfae6cf6 fix(grep): correctly handle all flag shapes and never exceed raw output
The grep argument-parsing rework routed many flag shapes through the
grouping reparse, which silently dropped any line it could not parse and
returned a success exit. Common invocations produced wrong or empty
output -- and grep-only syntax like `--include` failed outright -- which
pushed agents back to unfiltered `rtk proxy grep`.

Every valid grep invocation now produces correct output:

- Context (`-A`/`-B`/`-C`) is grouped and compressed instead of dropped;
  the header counts matches only and context lines are shown.
- Output the reparse cannot represent (`-N`, `-I`, `--color`, `-p`,
  `--heading`, binary-file notices, ...) is passed through verbatim
  instead of reported as a false "0 matches".
- Format/shape flags (`-c`, `-l`, `-o`, `-Z`, `--column`, `-b`,
  `--vimgrep`, `--null-data`) pass through cleanly with no NUL leak.
- grep-only syntax (`--include`, `--exclude`, ...) works: ripgrep is the
  fast path and rtk falls back to system grep when ripgrep rejects a flag.
- rtk grep never emits more than plain grep: if grouping is not smaller
  than `file:line:content`, the raw form is shown.

Resolves #2543.
2026-06-23 13:16:27 +02:00

3.0 KiB