Skip to content

feat(discover): expand subcommand coverage and strip verbose flags#549

Open
bz00qa wants to merge 2 commits intortk-ai:developfrom
bz00qa:feat/compound-command-rewriting
Open

feat(discover): expand subcommand coverage and strip verbose flags#549
bz00qa wants to merge 2 commits intortk-ai:developfrom
bz00qa:feat/compound-command-rewriting

Conversation

@bz00qa
Copy link
Copy Markdown

@bz00qa bz00qa commented Mar 12, 2026

Summary

  • Fix ENV_PREFIX regex to handle quoted values with spaces (e.g., PATH="/c/Program Files/nodejs:$PATH" npm run build)
  • Add PURE_ASSIGNMENT detection to ignore bare variable assignments like FOO=bar that aren't commands
  • Strip leading operators (&&, ||, ;) in classify_command to handle shell parsing artifacts
  • Strip verbose flags (-v, --verbose, --debug) from rewritten commands to reduce token-heavy output, with a denylist for commands where -v means something else (e.g., grep -v = invert match)
  • Expand git pattern from 12 to 51 subcommands with -C flag support (git -C /dir status)
  • Expand cargo pattern from 6 to 13 subcommands (tree, doc, bench, clean, update, publish, add, remove)
  • Expand pnpm pattern with --filter/-F/-r flag support and 21 subcommands
  • Expand npm pattern from 2 to 25 subcommands (test, install, ci, build, etc.)
  • Expand go pattern from 3 to 14 subcommands (mod, tool, run, fmt, generate, etc.)
  • Add subcmd_status: Passthrough entries for non-filtered subcommands across all expanded commands
  • Expand IGNORED_PREFIXES with Windows commands, Python scripts, version checks, Unix utilities, custom executables
  • Expand IGNORED_EXACT with env, printenv, whoami, hostname, date, id, uname
  • 40+ new tests covering all changes

Motivation

The discover registry and hook rewrite system are critical for RTK adoption — they determine which commands get rewritten and which get ignored. The current patterns miss many common subcommands (e.g., git checkout, npm install, go mod tidy, pnpm --filter), causing false negatives in rtk discover reports and missed rewrite opportunities in hooks.

The ENV_PREFIX regex also breaks on quoted values with spaces (common on Windows with PATH="/c/Program Files/..." patterns), and bare variable assignments like PATH=... (without a following command) were incorrectly classified as unsupported commands.

Test plan

  • All 182 registry tests pass (cargo test discover::registry::tests)
  • All 921 tests pass (918 + 3 rewrite_cmd), except 1 pre-existing Windows CRLF issue in binlog
  • cargo fmt --all && cargo clippy --all-targets clean (no new warnings)
  • New tests cover: quoted env prefix, pure assignments, leading operators, git -C flag, pnpm --filter/-F/-r, npm 25 subcmds, go mod/tool/doc, verbose flag stripping, grep -v denylist, expanded ignored commands
  • Manual verification of rtk discover output with expanded patterns

🤖 Generated with Claude Code

@bz00qa
Copy link
Copy Markdown
Author

bz00qa commented Mar 12, 2026

real results from "rtk discover --all" report before vs. after:
unhandled commands: ~2800 --> <100
est. tokens saveable: over +20%

…ip verbose flags

Improve the discover registry's command parsing robustness:

- Fix ENV_PREFIX regex to handle quoted values with spaces (e.g., PATH="/c/Program Files/nodejs:$PATH")
- Add PURE_ASSIGNMENT detection to ignore bare variable assignments
- Strip leading operators (&&, ||, ;) from classify_command input
- Add strip_verbose_flags() to remove -v/--verbose/--debug from rewritten commands (with denylist for grep -v)
- Expand git pattern to 51 subcommands with -C flag support
- Expand cargo pattern to 13 subcommands (tree, doc, bench, clean, update, publish, add, remove)
- Expand pnpm pattern with --filter/-F/-r support and 21 subcommands
- Expand npm pattern to 25 subcommands (test, install, ci, build, etc.)
- Expand go pattern to 14 subcommands (mod, tool, run, fmt, generate, etc.)
- Add subcmd_status Passthrough entries for non-filtered subcommands
- Expand IGNORED_PREFIXES with Windows commands, Python scripts, version checks, Unix utilities
- Expand IGNORED_EXACT with env, printenv, whoami, hostname, date, id, uname
- Add 40+ new tests covering all changes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: bz00qa <bz00qa.hub@gmail.com>
@bz00qa bz00qa force-pushed the feat/compound-command-rewriting branch from 8d052c2 to 1b88f0b Compare March 13, 2026 16:32
@bz00qa bz00qa changed the base branch from master to develop March 13, 2026 16:32
Signed-off-by: bZ00qa <167500396+bz00qa@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@bz00qa bz00qa changed the title feat: enhance command parsing and expand subcommand recognition feat(discover): expand subcommand coverage and strip verbose flags Mar 13, 2026
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@aeppling
Copy link
Copy Markdown
Contributor

Hey

We are cleaning up the codebase and improving the project structure for better onboarding. As part of this effort, PR #826 reorganizes src/ from a flat layout into subfolders.

No logic changes — only file moves and import path updates.

What you need to do

Rebase your branch on develop when receiving this comment:

git fetch origin && git rebase origin/develop

Git detects renames automatically. If you get import conflicts, update the paths:

use crate::git;        // now: use crate::cmds::git::git;
use crate::tracking;   // now: use crate::core::tracking;
use crate::config;     // now: use crate::core::config;
use crate::init;       // now: use crate::hooks::init;
use crate::gain;       // now: use crate::analytics::gain;

Need help rebasing? Tag @aeppling

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.

4 participants