Skip to content

feat: passthrough fallback when Clap parse fails + review fixes#200

Merged
pszymkowiak merged 8 commits intortk-ai:masterfrom
guillaumedeslandes:feat/passthrough-fallback
Mar 4, 2026
Merged

feat: passthrough fallback when Clap parse fails + review fixes#200
pszymkowiak merged 8 commits intortk-ai:masterfrom
guillaumedeslandes:feat/passthrough-fallback

Conversation

@guillaumedeslandes
Copy link
Contributor

@guillaumedeslandes guillaumedeslandes commented Feb 18, 2026

Summary

  • Graceful fallback: when Clap can't parse a command (e.g. git -C /path status), RTK executes the raw command instead of erroring out
  • Guard RTK meta-commands (gain, discover, learn, init, config, proxy, hook-audit, cc-economics) from falling through to raw $PATH execution — bad flags like rtk gain --badtypo show the Clap error directly
  • Fix timer placement so fallback commands capture actual execution time in rtk gain --history (was showing ~0ms)
  • Add 90-day retention cleanup to record_parse_failure() (parse_failures table was never cleaned up)
  • Strip ANSI codes from Clap errors before storing in SQLite
  • Fix smoke test: cargo test assertion now matches RTK's filtered output, fix undefined skipskip_test calls

Test plan

  • 425 unit tests pass (cargo test)
  • 90/90 smoke tests pass, 0 failed (bash scripts/test-all.sh)
  • rtk gain --badtypo shows Clap error (not "command not found")
  • rtk git -C /path status falls back to raw git -C /path status
  • rtk --help and rtk --version still work normally

Fixes #204, #228, #229

🤖 Generated with Claude Code

@pszymkowiak
Copy link
Collaborator

Tested locally — solid approach, needs rebase + 2 fixes before merge.

Testing results:

  • 387/387 unit tests pass
  • 82/83 smoke tests pass (1 fail due to branch being behind master)
  • Manual testing confirms fallback works correctly for git -C, git --no-pager, grep -E
  • Normal RTK-filtered commands (git status, git log, --help, --version) unaffected

Must fix:

  1. Rebase on master — branch is 2 commits behind (missing v0.22.0/0.22.1), cargo test count mismatch
  2. Guard RTK meta-commands from fallback — rtk gain --badtypo currently tries to execute a gain binary from $PATH before showing the Clap error. Add a check for known RTK-only subcommands
    (gain, discover, learn, init, config, proxy, hook-audit, cc-economics) and show the Clap error directly for those.

Nice to have (non-blocking):

  • Timer starts after command completes — all fallback commands show ~0ms in rtk gain --history. Move TimedExecution::start() before the .status() call.
  • parse_failures table never gets cleaned up (only record() calls cleanup_old(), not record_parse_failure())
  • Strip ANSI codes from Clap error before storing in SQLite (utils::strip_ansi already exists)

This will fix #204, #228, #229 and any future unknown-flag issues globally. Great work!

@guillaumedeslandes guillaumedeslandes changed the title feat: passthrough fallback when Clap parse fails feat: passthrough fallback when Clap parse fails + review fixes Feb 23, 2026
@guillaumedeslandes
Copy link
Contributor Author

Tested locally — solid approach, needs rebase + 2 fixes before merge.

Testing results:

  • 387/387 unit tests pass
  • 82/83 smoke tests pass (1 fail due to branch being behind master)
  • Manual testing confirms fallback works correctly for git -C, git --no-pager, grep -E
  • Normal RTK-filtered commands (git status, git log, --help, --version) unaffected

Must fix:

  1. Rebase on master — branch is 2 commits behind (missing v0.22.0/0.22.1), cargo test count mismatch
  2. Guard RTK meta-commands from fallback — rtk gain --badtypo currently tries to execute a gain binary from $PATH before showing the Clap error. Add a check for known RTK-only subcommands
    (gain, discover, learn, init, config, proxy, hook-audit, cc-economics) and show the Clap error directly for those.

Nice to have (non-blocking):

  • Timer starts after command completes — all fallback commands show ~0ms in rtk gain --history. Move TimedExecution::start() before the .status() call.
  • parse_failures table never gets cleaned up (only record() calls cleanup_old(), not record_parse_failure())
  • Strip ANSI codes from Clap error before storing in SQLite (utils::strip_ansi already exists)

This will fix #204, #228, #229 and any future unknown-flag issues globally. Great work!

@pszymkowiak Rebased and implemented requested changes.
Please note that I had to modify scripts/test-all.sh in last commit.

heAdz0r added a commit to heAdz0r/rtk that referenced this pull request Feb 28, 2026
…tk-ai#217, rtk-ai#196, rtk-ai#248, rtk-ai#211, rtk-ai#200, rtk-ai#192, rtk-ai#268)

Wave 1 (critical bugs):
- fix(registry): fi/done moved to IGNORED_EXACT — find no longer shadowed (rtk-ai#246)
- fix(playwright): f64 duration, specs[] structure, --reporter=json after subcmd (rtk-ai#193)
- fix(gh): should_passthrough_gh_view for --json/--jq/--template/--web in view_pr/issue/run (rtk-ai#217+196)

Wave 2 (reliability):
- fix(git): is_blob_show_arg — blob show passthrough without trailing-newline trim (rtk-ai#248)
- fix(find): parse_find_args with native -name/-type/-maxdepth/-iname support (rtk-ai#211)
- fix(main): graceful Clap fallback + parse_failures SQLite table + rtk gain --failures (rtk-ai#200)

Wave 3 (UX):
- feat(git): global options -C/-c/--git-dir/--work-tree/--no-pager/--no-optional-locks/--bare/--literal-pathspecs (rtk-ai#192)
- feat(proxy): streaming output via spawn()+threads instead of buffered output() (rtk-ai#268)

Tests: 1091 → 1117 (+26), 0 regressions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@pszymkowiak
Copy link
Collaborator

Please rebase on master before we can merge — there are conflicts in src/main.rs and src/tracking.rs.

guillaumedeslandes and others added 7 commits March 1, 2026 12:45
When RTK cannot parse a command (e.g. `rtk git -C /path status`),
instead of exiting with error code 2, it now falls back to running
the raw command directly. This keeps developer workflows unbroken.

- Replace Cli::parse() with try_parse() + run_fallback()
- Add parse_failures SQLite table for failure analytics
- Add `rtk gain --failures` / `-F` to view failure log
- Fallback preserves stdin/stdout/stderr via Stdio::inherit()
- --help and --version still work normally

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When Clap fails to parse a meta-command like `rtk gain --badtypo`,
show the Clap error directly instead of trying to execute `gain`
as a binary from $PATH. Adds RTK_META_COMMANDS constant listing
gain, discover, learn, init, config, proxy, hook-audit, cc-economics.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
TimedExecution::start() was called after the command finished,
so all fallback commands showed ~0ms in rtk gain --history.
Now the timer captures actual command runtime.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The parse_failures table was never cleaned up because only record()
called cleanup_old(). Now parse failures also trigger 90-day retention
cleanup.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Clap errors may contain terminal color codes. Strip them with
utils::strip_ansi() before storing in the parse_failures table
to avoid garbled output and wasted space.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- cargo test check now matches RTK's filtered output format ("passed")
  in addition to raw "test result:" and "FAILURES"
- Fix undefined `skip` calls to use existing `skip_test` function
  with proper (name, reason) arguments

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@guillaumedeslandes guillaumedeslandes force-pushed the feat/passthrough-fallback branch from c9816a5 to a888f02 Compare March 1, 2026 11:46
Upstream v0.23.0 release bumped Cargo.toml version and added mypy_cmd
module. Update docs to match for CI validation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@guillaumedeslandes
Copy link
Contributor Author

Please rebase on master before we can merge — there are conflicts in src/main.rs and src/tracking.rs.

@pszymkowiak Done.

@pszymkowiak
Copy link
Collaborator

Hi, this PR has conflicts with master in src/main.rs and src/tracking.rs. Could you rebase on current master? Thanks!

@pszymkowiak
Copy link
Collaborator

Tested locally — all good.

All review items addressed (must-fix and nice-to-have). LGTM, ready to merge.

@pszymkowiak pszymkowiak merged commit 772b501 into rtk-ai:master Mar 4, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

find and grep commands fail (unexpected argument '-n' found)

2 participants