fix(grep): correctly handle all flag shapes and never exceed raw output#2550
Conversation
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.
|
Nice — the Repro + a 0.42.2 confirmation, in case useful: #2543 (comment) 🤖 Generated with Claude Code |
|
Thanks @alexisLefebvre , good catch. Added a regression test for the exact #2543 shape in 3a59d23: |
Summary
Make rtk grep produce correct output for every valid grep invocation and never cost more tokens than plain grep.
The #2333 arg-parsing rework routed many flag shapes through the grouping reparse, which silently dropped unparseable lines and returned success, producing wrong/empty results (and grep failed on --include) that pushed agents to unfiltered rtk proxy grep.
Related
Test plan