#4315·rtk

Pick the filter from the final command and run the command as typed: one mechanism for path-prefixed, runner-prefixed and aliased invocations

Author: KuShCreated Sep 28, 2026Updated Sep 28, 2026
Labelsenhancementpriority:higharea:cli

The problem, in one mechanism

Two decisions are made in two places and can disagree:

  1. The rewriter maps a spelling to rtk <tool>. To get there it strips whatever precedes the tool: a path (.venv/bin/pytest), a package runner (npx, pnpm exec, uv pip, python -m), or an alias (gradle, ./mvnw).
  2. The handler then chooses what to execute by its own rule: resolved_command("<tool>") on PATH (pytest, ruff, eslint via rtk lint), a wrapper preference (gradlew_cmd prefers ./gradlew, mvn_cmd prefers ./mvnw), a package manager it detects itself (playwright, prisma), or a fallback chain (rtk pip runs uv only when pip is absent).

When the two disagree the caller's command runs a program they did not name, with no trace in the output. When the rewriter declines instead, the binary is right and the filter is lost. Both halves are today's behaviour, and each instance has been filed as a separate bug.

Measured on develop @45b0b4c3 (rtk rewrite "<spelling>")

Prefix stripped, handler re-resolves (binary can change):

Spelling Rewritten to Handler runs Filed as
npx eslint ., pnpm exec eslint . rtk lint . eslint from PATH #3846
pnpm exec biome ci . rtk lint ci . ESLint, with ci as the linter name #2906, #3117
npx vitest run, pnpm exec vitest run, pnpm dlx vitest run, npm exec vitest run rtk vitest vitest by its own resolution
npx tsc, npx prettier, npx playwright, npx prisma rtk <tool> … tool by its own resolution
python -m pytest -q rtk pytest -q pytest from PATH if present, else python -m pytest
uv pip list rtk pip list pip when pip is on PATH this issue
uv pip list, dead pip on PATH rtk pip list pip, fails with ENOENT (exit 1) #4054
pip3 list rtk pip list pip, not pip3
gradle build rtk gradlew build ./gradlew when present #3413, #2374
./mvnw test rtk mvn test ./mvnw when present, else mvn
npm run lint, pnpm lint rtk lint ESLint by default #2879, #3846 comments

Not rewritten (binary right, filter lost):

/usr/bin/git status, .venv/bin/pytest -q, ./node_modules/.bin/vitest run, ./node_modules/.bin/eslint . (#1053); yarn exec eslint ., yarn eslint .; uvx ruff check ., poetry run pytest (#2969), pipx run ruff check ., hatch run pytest, pdm run pytest; python3 -m pip list, python -m ruff check .; pnpm typecheck (#2809); docker compose exec app pytest. #1205 and #294 ask for several of these to be rewritten; without the mechanism below they would move to the first table.

Runner kept, rtk inserted after it or the runner handler takes over:

Spelling Rewritten to What happens
uv run pytest -q uv run rtk pytest -q works because uv run prepends the venv to PATH before rtk pytest re-resolves pytest
uv run -- pytest -q rtk uv run -- pytest -q uv_cmd runs uv as typed and applies the pytest filter itself
npm exec -- eslint . rtk npm exec -- eslint . exec is in npm_cmd's passthrough list: binary right, no filter
bunx vitest run, bun x vitest run rtk bunx vitest run bun_cmd runs bunx as typed; the inner tool gets a filter only where main.rs special-cases it (tsc, eslint)
env FOO=1 pytest, nice pytest, timeout 30 pytest … rtk pytest wrapper kept, tool re-resolved from PATH (fine for these wrappers)

The third group is the shape that is right, implemented per handler: lint_cmd::named_runner, the runner: Option<&str> parameter of tsc_cmd::run and lint_cmd::run, uv_cmd's uv run branch, and the main.rs arms that route rtk npx eslint / rtk bunx tsc. Each new runner or tool pair needs another arm.

Direction

One pipeline instead of per-handler arms:

  1. Find the final command. Walk past env assignments, wrappers (env, nice, timeout), package runners (npx, npm exec, pnpm exec/dlx, yarn [exec], bunx/bun x, uv run/uvx, poetry run, pipx run, hatch run, pdm run, python -m), and a path or wrapper spelling of the tool (.venv/bin/pytest, ./gradlew, ./mvnw). What remains is the tool and its arguments.
  2. Pick the filter from that tool. The registry lookup keys on the final command, not on the spelling.
  3. Run the command as typed. The argv rtk spawns is the caller's, prefix included: the binary at that path, the tool under that runner, the wrapper the caller chose. The filter is applied to its output. Where the caller named no prefix, today's resolution rules apply unchanged. Fallbacks that only exist to guess a stripped prefix back go away with it: pip_cmd runs uv pip when pip is absent because the rewriter dropped the uv of uv pip; once the named runner reaches the handler, a bare pip with no pip on PATH fails as it does without rtk.

The CLI shape that carries the original argv from the rewriter to the process (a flag, an env var like the RTK_BIN of #3590/#3592, or a rtk <runner> … form that every runner handler understands) is open. The invariant is not: the program that runs is the one the caller named, and the filter is the one for the tool they ran.

Acceptance

For every spelling in the three tables, with a stub of the tool placed first on PATH that records its argv and a second copy at the named path or under the named runner:

  • the copy that runs is the one the caller named (the stub on PATH is never hit for a path- or runner-prefixed spelling);
  • the output is filtered by the final tool's filter, and the exit code is the child's;
  • the "not rewritten" group gains a filter without changing which binary runs.

A differential test over the spellings above (rewriter output → argv spawned, compared to the raw command's argv) pins it and is the regression gate for new runners.

Absorbs

#1053 (path prefixes; #3590 and #3592 are the path half of step 3), #3846, #2906, #3117, #3413, #2374, #2809, #1205, #2969, #294, the uv run / pnpm exec items of #1711, the uv pip case above and #4054. Each keeps its own repro; the fix lands once.