Skip to content

feat(aiagents): detect package install in compound shell commands#89

Open
raysubham wants to merge 1 commit into
step-security:mainfrom
raysubham:feat/npm-detect-compound-commands
Open

feat(aiagents): detect package install in compound shell commands#89
raysubham wants to merge 1 commit into
step-security:mainfrom
raysubham:feat/npm-detect-compound-commands

Conversation

@raysubham
Copy link
Copy Markdown
Contributor

Summary

  • The npm enricher classified shell commands by their first token only, so compound commands such as cd /repo && pnpm install && pnpm run build were never flagged as a package install step (the first token is cd).
  • Detect now splits the command on unquoted shell separators (&&, ||, ;, |, &, newline) into segments, classifies each segment independently with the existing per-segment logic, and returns the strongest detection (install > uninstall > publish > audit > exec > other). Quotes and backslash escapes are respected so operators inside string literals do not cause false splits.
  • Per-segment classification preserves the existing nested-fetcher behaviour for npx/bunx/pnpm dlx — only the outer fetcher in a segment is emitted, no double-emission of the inner install.

Notes

  • ShellEnrichment.WorkingDirectory and the cwd passed to enrichment continue to record the shell's origin directory, not any effective directory after a cd segment. That is intentional and out of scope here; lockfile / registry / npm-config evidence is still resolved against the origin cwd.

Test plan

  • go test ./internal/aiagents/enrich/npm/... (existing single-segment cases plus new compound-command coverage).
  • go build ./...
  • gofmt -l internal/aiagents/enrich/npm/ clean.
  • Reviewer to spot-check classification on real Cursor/Claude shell invocations that chain cd and pnpm install.

The npm enricher classified a command by its first token only, so compound
shells like `cd /repo && pnpm install && pnpm run build` were missed
because `cd` is not a package manager.

Split the command on unquoted shell separators (`&&`, `||`, `;`, `|`, `&`,
newline) into segments, classify each, and pick the strongest detection
(install > uninstall > publish > audit > exec > other). Quotes and
backslash escapes are respected so operators inside string literals do
not cause false splits.
@raysubham raysubham changed the title feat(aiagents/enrich): detect package install in compound shell commands feat(aiagents): detect package install in compound shell commands May 20, 2026
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.

1 participant