Skip to content

fix: complete pre-clap intercepts — meta flags + grep flag fallbacks - #99

Merged
thehoff merged 2 commits into
developfrom
fix/clap-intercept-96-97
May 20, 2026
Merged

thehoff merged 2 commits into
developfrom
fix/clap-intercept-96-97

Conversation

@thehoff

@thehoff thehoff commented May 20, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #96. Closes #97. Completes the pre-clap intercept coverage so more invocations stop falling through to raw exec / parse_failures.

#96 — META_PASSTHROUGH_BINS gap

pytest --version recorded −75% over 90 calls. These wrappers use clap trailing_var_arg, so --version wasn't rejected — it was captured and run through the filter handler, mangling output. Added pytest, ruff, mypy, rake, rubocop, rspec, pip to the meta-flag intercept.

#97 — residual grep clap fallbacks

After #88 (recursive/context flags), grep still clap-failed on -E, -H, -l, bundles. Now: -E stripped (rg is extended-regex by default — genuine no-op), -H routed to passthrough (rg honours --with-filename), -l routed to passthrough, -o already handled.

Security — CRITICAL caught in review

The meta-flag passthrough initially used a bare resolved_command, bypassing the per-tool env hardening (issues #36/#37/#38 — RUBYOPT/PYTHONPATH/DOCKER_CONFIG/KUBECONFIG/AWS_CONFIG_FILE/...). A secure_meta_command dispatcher now routes every meta-passthrough binary to its tool-specific secure_*_command builder:

Binaries Builder
cargo secure_cargo_command
pnpm, npm, npx, prisma secure_node_command
go secure_go_command
pytest, ruff, mypy, pip secure_python_command
rake, rubocop, rspec secure_ruby_command
docker / kubectl / aws / psql / gh / glab / gt their respective secure_*_command

This also retroactively hardens the existing cargo/npm/go meta entries from #90.

Test plan

  • cargo test --workspace — 2272 pass, 0 fail
  • All 42 hardening tests pass (runtime / cloud / gh_glab_gt / node / cargo)
  • 31 grep-preprocess tests; 3 new secure_meta_dispatch tests
  • Smoke: pytest --version, rake --version, pip --version, grep -E/-H/-rnE/-l — no clap errors
  • Codex review — one CRITICAL (hardening-bypass) + one IMPORTANT (-H regression) found and fixed; 4 pre-existing tests that codified the -H bug corrected

🤖 Generated with Claude Code

thehoff and others added 2 commits May 20, 2026 15:15
Issue #96 — META_PASSTHROUGH_BINS gap
Add the Python/Ruby subcommand-style wrappers (pytest, ruff, mypy, rake,
rubocop, rspec, pip) to META_PASSTHROUGH_BINS. All seven are real clap
subcommands using trailing_var_arg, so `--version` was captured into args
and run through the filter handler, which mangled version output
(production DB recorded `pytest --version` at -75% savings over 90 calls).
Routing them to clean passthrough fixes this. The regression test
test_meta_passthrough_covers_all_subcommand_only_wrappers is extended to
match.

To preserve the issue #36 runtime-env hardening that the per-tool filter
handlers apply, run_simple_passthrough now builds its command via the new
secure_meta_command dispatcher instead of a bare resolved_command. Without
this the meta-flag path re-exposed RUBYOPT/PYTHONPATH/NODE_OPTIONS
injection (caught by tests/runtime_hardening.rs::rake_rubyopt_is_not_executed).

Issue #97 — residual grep clap fallbacks
After #88 (which handled -r/-R/--recursive/-A/-B/-C), grep still
clap-failed on other standard flags. Classification:
  - -E (extended regex): no-op for rg (extended by default) -> STRIP,
    generalised the recursive-strip pass via GREP_STRIPPABLE_SHORTS.
  - -H (with-filename): cosmetic for rg -> STRIP.
  - -rnE / -HnE bundles: r/E/H peeled from the bundle, -n survives -> STRIP.
  - -o (only-matching): ALREADY handled — listed in grep_format_flag_present
    SHORT_LETTERS, routes to passthrough.
  - -l (files-with-matches): clap claims -l for --max-len (a usize), so
    bare `grep -l <pattern>` failed parsing. grep_format_flag_present now
    routes bare/bundled/trailing -l to rg, but leaves `-l <numeric>` for
    clap as --max-len.
Routed flags still pass through run_grep_format_passthrough +
check_forbidden_rg_args (issue #32).

Tests: extended grep_format_flag_tests, grep_preprocess_tests, and
meta_flag_tests. All 2269 workspace tests pass.

Closes #96.
Closes #97.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…ning

Codex review of #96/#97: secure_meta_command sent docker/kubectl/gh/
glab/aws/psql/gt to the generic universal-strip fallback, bypassing
their tool-specific secure_*_command builders (issue #36/#37/#38 env
hardening). Silent regression on the meta-flag path. Add explicit
dispatch arms for every binary with a dedicated builder.

Also: stop stripping grep -H unconditionally (dropped filename output).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@thehoff
thehoff merged commit 540fa02 into develop May 20, 2026
4 checks passed
@thehoff
thehoff deleted the fix/clap-intercept-96-97 branch May 20, 2026 05:32
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.

grep: residual clap fallbacks for -E/-H/-l and other unhandled flags cli: META_PASSTHROUGH_BINS missing pytest/ruff/mypy/rake/rubocop/rspec/pip

1 participant