Repository navigation
Description
Summary
22 rules in src/discover/rules.rs end in a bare subcommand alternation with no trailing word boundary, so any command whose second word merely starts with a listed subcommand is rewritten. git branchless status becomes rtk git branchless status, and git-branchless is a real, widely used tool.
This was found while reviewing #3676, which fixes exactly this bug for the pnpm rule by appending (\s|$). 23 rules had the defect on develop; that PR fixes one, leaving 22.
Reproduction
Against the develop binary (79b96a4):
$ rtk rewrite "git branchless" → rtk git branchless
$ rtk rewrite "git statuses" → rtk git statuses
$ rtk rewrite "git logger" → rtk git logger
$ rtk rewrite "git showcase" → rtk git showcase
$ rtk rewrite "cargo installer" → rtk cargo installer
$ rtk rewrite "cargo builder" → rtk cargo builder
$ rtk rewrite "gh prs" → rtk gh prs
$ rtk rewrite "gh issues" → rtk gh issues
$ rtk rewrite "glab mrs" → rtk glab mrs
$ rtk rewrite "docker psql" → rtk docker psql
$ rtk rewrite "kubectl getall" → rtk kubectl getall
$ rtk rewrite "oc status-check" → rtk oc status-check
$ rtk rewrite "ruff checker" → rtk ruff checker
$ rtk rewrite "go vetting" → rtk go vetting
$ rtk rewrite "terraform planner" → rtk terraform planner
$ rtk rewrite "pio runner" → rtk pio runner
Every one of these should be left untouched.
git branchless is the one with real-world bite today: it is an installed third-party subcommand, and the hook silently redirects it into rtk git, which has no idea what branchless is.
Affected rules
All 22 end in an alternation group with nothing anchoring its right edge:
git|yadm, gh, glab, cargo, prettier, next build, playwright, prisma, docker, kubectl, oc, ruff, sqlfluff lint, pip|uv pip, go, sbt, rake|rails test, pio run, quarto render, shopify theme, terraform plan, trunk build
(pnpm was the 23rd and is fixed by #3676.)
Rules that already do this correctly — ^ls(\s|$), ^tree(\s|$), ^wc(\s|$), ^mypy(\s|$), ^pytest(\s|$), the gradlew rule, and the several \b-terminated ones — show the intended shape.
Suggested fix
Append (\s|$) (or \b) to each affected pattern, then close the class with a table-wide test asserting every rule's pattern is boundary-terminated, so a new rule can't reintroduce it:
#[test]
fn every_rule_pattern_is_boundary_terminated() {
for (i, rule) in RULES.iter().enumerate() { /* … */ }
}A test that simply appends a junk suffix to each rule's own sample command and asserts no rewrite would catch all 22 at once.
Note on blast radius
pnpm 12 adds clean and purge built-ins that delete node_modules. None are matched by a rule today, but the combination of destructive built-ins and unanchored alternations is worth closing before it matters.
Related
- feat(discover): route pnpm's bare script forms #3676 — fixes the
pnpmarm and is where this was found - Root cause: rewrite_command() lacks early command-shape validation (fixes #2792, #2821, #2892) #2902 — same family (over-eager rewriting) but a different mechanism: unsupported predicate shapes in
find/fdrather than the alternation boundary. Both would need fixing independently.
Activity
rtk-wshm-sync-bot commentedon Sep 12, 2026
🔍 Automated Triage
bughighSummary
22 rules in src/discover/rules.rs lack a trailing word-boundary on their subcommand alternation, causing false-positive rewrites (e.g.
git branchless→rtk git branchless); fix by appending(\s|$)to each pattern and add a table-wide boundary test.📁 Relevant files
src/discover/rules.rsTriaged automatically by wshm · This is an automated analysis, not a human review.
tsugumi42 commentedon Sep 18, 2026
Two instances of the
pip|uv piprule, from a 0.45.0 install on Windows/MSYS:uv pip listlooks worth more than a cosmetic fix. Herepip listanduv pip listresolve to different interpreters (uv's managed environment vsthe active venv), so the rewrite doesn't return a shorter version of what was
asked — it answers a different question, silently. By the Transparency rule in
CONTRIBUTING,
rtk pip listis not "a valid, useful subset" ofuv pip list.One note on workarounds, since it affects how these get fixed:
[hooks] exclude_commandsonly matches the outermost command. Addinguvtheredoes suppress
uv pip list/uv sync/uv add/uv lock/uv venv/uvx ...(verified), butuv run pyteststill becomesuv run rtk pytest.That specific case is already tracked in #1205 (v0.43.0 regression, silently
collects 0 tests), so I'm not re-filing it — the point is just that the
config-level opt-out can't reach wrapped commands.
fix(discover): split words the way bash does, and pin the rule table (#…
fix(discover): split words the way bash does, and pin the rule table (#…
fix(discover): split words the way bash does, and pin the rule table (#…
fix(discover): split words the way bash does, and pin the rule table (#…