Skip to content

fix(bash): attribute wrapped commands to the real tool, not the wrapper#658

Merged
iamtoruk merged 1 commit into
mainfrom
fix/bash-wrapper-prefixes
Jul 10, 2026
Merged

fix(bash): attribute wrapped commands to the real tool, not the wrapper#658
iamtoruk merged 1 commit into
mainfrom
fix/bash-wrapper-prefixes

Conversation

@iamtoruk

Copy link
Copy Markdown
Member

Closes #657.

Problem

extractBashCommands in src/bash-utils.ts takes the first token of a shell command as the tool name. When an agent wraps its commands in a prefix, that first token is the wrapper, not the real tool:

Agent ran Recorded (before) Real tool
sudo apt update sudo apt
npx vitest --run npx vitest
rtk git push rtk git

Any agent that prefixes its shell calls collapses its whole bash breakdown into one bucket, and the optimize detectors lose the tool they key on. Reported on v0.9.15 by an agent config that prefixes with rtk.

Change

Add a small set of known wrappers (sudo, doas, npx, bunx, time, nice, nohup, stdbuf, rtk) and skip past them to the delegated command. The skip is interleaved with the existing VAR=value env-assignment skip, so mixed forms like sudo NODE_ENV=prod node server.js resolve correctly.

Guards that keep it safe (no new garbage keys, no regressions):

  • A wrapper with no following command is kept as-is (sudo alone stays sudo).
  • A wrapper followed by a flag is kept (nice -n 10 git stays nice, since we can't know the flag's arity).
  • A wrapper followed by a quoted token is kept (npx "@angular/cli" stays npx, never cli").

One function, so every provider parser benefits.

Tests

Added cases in tests/bash-commands.test.ts covering wrapper skip, nested wrappers, env+wrapper interleave, chained wrappers, standalone wrapper, flag guard, and quote guard. Full suite green (3086 tests).

Credit to @athoune (Mathieu Lecarme) for the report and the proposed approach.

extractBashCommands recorded the wrapper (sudo, npx, rtk, and friends)
instead of the command it delegates to, so any agent that prefixes its
shell calls collapsed its whole bash breakdown into one meaningless
bucket and the optimize detectors lost the actual tool.

Skip a known set of command wrappers when a real command follows, and
interleave that skip with the existing VAR=value env-assignment skip so
forms like 'sudo NODE_ENV=prod node x' resolve to the real tool. A
wrapper followed by a flag or a quoted token is kept as-is so we never
emit a garbage key.

Closes #657
@iamtoruk iamtoruk merged commit c6f2073 into main Jul 10, 2026
3 checks passed
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.

Bash command wrappers / prefixes (sudo, npx, rtk, …) are misclassified

1 participant