fix(bash): attribute wrapped commands to the real tool, not the wrapper#658
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #657.
Problem
extractBashCommandsinsrc/bash-utils.tstakes 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:sudo apt updatesudoaptnpx vitest --runnpxvitestrtk git pushrtkgitAny 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 existingVAR=valueenv-assignment skip, so mixed forms likesudo NODE_ENV=prod node server.jsresolve correctly.Guards that keep it safe (no new garbage keys, no regressions):
sudoalone stayssudo).nice -n 10 gitstaysnice, since we can't know the flag's arity).npx "@angular/cli"staysnpx, nevercli").One function, so every provider parser benefits.
Tests
Added cases in
tests/bash-commands.test.tscovering 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.