Skip to content

ux(grep): pre-clap intercept routes documented format flags through rg - #16

Merged
thehoff merged 1 commit into
developfrom
fix/grep-format-flags-passthrough
May 18, 2026
Merged

thehoff merged 1 commit into
developfrom
fix/grep-format-flags-passthrough

Conversation

@thehoff

@thehoff thehoff commented May 18, 2026 •

Copy link
Copy Markdown
Owner

Summary

Empirical: tracking DB had 518 parse_failures, dominated by grep -c / grep -ci / grep -cE. The docs say -c, -L, -o, -Z and the long forms should run raw, but the implementation let clap reject them first; the fallback succeeded but stderr was polluted and the parse_failures table grew unboundedly.

Fix: pre-clap intercept at the top of run_cli(). When args[0] is grep and any documented format flag is present, route directly to a dedicated passthrough that bypasses clap and the parse_failure log entirely. Routes through rg (system grep fallback) so mixed invocations like grep -c --glob '*.rs' pat keep working — rg natively supports both the format flags AND the rtk-extra options the rg-backed grep path accepts.

Short letters (c/L/o/Z) match anywhere in a single-- bundle (-c, -ci, -cE, -iLn). Long forms (--count, --files-with-matches, --files-without-match, --only-matching, --null) match exactly. Numeric tokens (-5) are ignored.

-l is intentionally excluded — this app's clap claims -l for --max-len. Users wanting standard grep -l should use --files-with-matches or contextcrawler proxy grep -l ....

Reviewed by Codex

  • P2: bare GNU grep broke mixed invocations with rtk-extras → fixed by routing through rg

Test plan

  • cargo test --bin contextcrawler — 1999 passed, 0 failed (+11 new)
  • Unit tests cover: every short letter (c/L/o/Z), bundled short forms, all long forms, -l carve-out, normal -rn non-matching, numeric tokens, empty args, unrelated --include=

Closes #13

…rough (#13)

Empirical finding: the tracking DB had 518 parse_failures, dominated by
`grep -c`, `grep -ci`, `grep -cE` invocations. CONTEXTCRAWLER.md documents
that `-c, -L, -o, -Z` and the long-form equivalents should run raw, but the
implementation let clap reject them with `error: unexpected argument '-c'`
first; the fallback path then succeeded but stderr was polluted and the
parse_failures table grew unboundedly.

Fix: add a pre-clap intercept at the top of `run_cli()`. When args[0] is
`grep` and any of the documented format flags is present, route directly to
a dedicated passthrough that runs raw grep without invoking clap or
recording a parse_failure. Short letters (c/L/o/Z) match anywhere in a
single-`-` bundle (`-c`, `-ci`, `-cE`, `-iLn`); long forms must match
exactly. Numeric tokens like `-5` are ignored.

`-l` is intentionally excluded — this app's clap claims `-l` for
--max-len. Users wanting standard grep `-l` (list matching files) should
use `--files-with-matches` or `contextcrawler proxy grep -l ...`.

Tests: 11 new unit tests covering each short letter, bundled short forms,
all long forms, the `-l` carve-out, normal `-rn` non-matching, numeric
tokens, empty args, and unrelated `--include=`. All 1853 binary tests
pass.

Closes #13
@thehoff
thehoff force-pushed the fix/grep-format-flags-passthrough branch from b69fa0a to 87ba25c Compare May 18, 2026 05:35
@thehoff
thehoff merged commit e34e5b3 into develop May 18, 2026
3 checks passed
@thehoff
thehoff deleted the fix/grep-format-flags-passthrough branch May 18, 2026 05:36
noogalabs pushed a commit to noogalabs/contextcrawler that referenced this pull request Jun 4, 2026
… branding-lint extension

**Version bump 0.39.0 → 0.1.7.** The upstream rebase pulled in rtk's
`0.39.0` version; restoring the downstream `0.1.x` numbering line per
the maintainer's call. `.release-please-manifest.json` updated to
match. Last downstream tag was `v0.1.6` (2026-05-15); this is the
next in the sequence.

**release-please-config.json `package-name: "rtk"` → "contextcrawler".**
Caught by manual audit during release prep. Same regression-family as
thehoff#19 / thehoff#20 / thehoff#22: a rebrand gap the prior branding-lint (src/-scoped)
didn't catch because release-please-config.json lives at repo root.
Without this fix, release-please would have produced `rtk-vX.Y.Z`
tags and release-PR titles.

**Cargo.toml `extended-description` rebrand.** Line 77 still read
"rtk filters and compresses..." — same upstream-leak family. Fixed.

**Extended `tests/branding_lint.rs`** with a third test —
`branding_lint_config_files_pin_canonical_package_name` — that:
- Parses Cargo.toml and asserts `[package].name == "contextcrawler"`
- Parses release-please-config.json and asserts
  `packages["."]["package-name"] == "contextcrawler"`

This closes the gap that let release-please-config.json silently drift
to `"rtk"` post-rebase. Any future rebase that re-introduces an
upstream package-name fails `cargo test --test branding_lint` with an
explicit error pointing at issues thehoff#19/thehoff#20/thehoff#22 history.

**CHANGELOG.md** entry for v0.1.7 added, summarizing all PRs merged
today (thehoff#10 thehoff#15 thehoff#16 thehoff#21 thehoff#24 thehoff#25 thehoff#30) plus the deferred follow-ups
(thehoff#26 thehoff#27 thehoff#28 thehoff#29).

Tests: 2027 bin + 3 branding-lint (1 new) + 1 harness = all pass.
Verified: `contextcrawler --version` now prints `contextcrawler 0.1.7`.

Refs thehoff#19 thehoff#20 thehoff#22 thehoff#29
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.

ux(grep): -c/-l/-L/-o/-Z format flags error-then-fallback; should silently passthrough

1 participant