Skip to content

pnpm run bb:dev -- <cmd> <positional> --<flag> fails: pnpm forwards a literal -- that Commander treats as end-of-options #2998

Closed

Description

@technicalpickles

Summary

pnpm run bb:dev -- <command> <positional> --<flag> fails for any CLI command that takes a positional argument followed by a flag, with error: too many arguments. The root cause is not bb's own argument parsing: pnpm 9.15.0 forwards the -- separator itself as a literal argument to the underlying script, and Commander.js treats that literal -- as "end of options," so the trailing flag gets parsed as an extra positional instead of an option.

Versions and environment

  • bb from source at commit 99c0ad71841ff6ff2d42b3f7864b6dba0b0f7337 (main)
  • pnpm 9.15.0 (packageManager pin in package.json), Node v22.19.0
  • macOS 25.5.0 (Darwin), arm64
  • No provider/agent involved; pure CLI dev-workflow bug

Steps to reproduce

  1. pnpm run --silent bb:dev -- machine show <id> --json
  2. Observe: error: too many arguments for 'show'. Expected 1 argument but got 2.

Also fails reordered (pnpm run --silent bb:dev -- machine show --json <id>) with the same error, and fails for other commands with the same positional-then-flag shape (machine join-code --json, machine remove <id> --yes).

Does not reproduce when the same args are handed to the compiled CLI directly, bypassing pnpm's -- forwarding:

node apps/cli/dist/index.js machine show <id> --json

That runs fine (only fails later, on "machine not found," for an unrelated reason: I used a fake id).

Minimal isolation, no bb code involved at all:

// package.json
"scripts": { "debug:argv": "node -e 'console.error(process.argv.slice(2))'" }
$ pnpm run --silent debug:argv -- foo bar
[ '--', 'foo', 'bar' ]

$ npm run debug:argv -- foo bar
[ 'foo', 'bar' ]

pnpm includes the literal -- token in argv passed to the script; npm strips it. bb's packages/scripts/src/commands/run-cli.ts forwards process.argv.slice(2) straight through to the spawned CLI process (resolveCliExecution, lines 17-33), so that leading -- lands as a real CLI argument: node apps/cli/dist/index.js -- machine show <id> --json. Commander then treats everything after that -- as literal positionals, so --json becomes a second positional for the show <id-or-name> command (defined here), which only accepts one.

Confirmed directly:

$ node apps/cli/dist/index.js -- machine show <id> --json
error: too many arguments for 'show'. Expected 1 argument but got 2.

$ node apps/cli/dist/index.js machine show <id> --json
Error: Machine '<id>' was not found. Available machines: ...

Expected vs actual

Actual: any pnpm run bb:dev -- <command> <positional> --<flag> invocation fails at the parser with error: too many arguments for '<command>'. Expected N but got N+1, before bb's own command logic ever runs.

Expected: pnpm run bb:dev -- machine show <id> --json behaves the same as calling the compiled CLI directly with those same logical arguments.

Evidence

  • package.json script: "bb:dev", line 48.
  • run-cli.ts forwarding site: resolveCliExecution, lines 17-33.
  • Measured by direct comparison of pnpm run vs npm run argv forwarding for the same script and args (above); the discrepancy is 100% reproducible across repeated runs.

What you ruled out

  • Not a bug in bb's Commander command definitions: calling the compiled CLI directly with identical logical arguments (no -- prefix) works correctly.
  • Not fixed by reordering the flag before the positional; both orders fail identically once the stray -- is present.
  • Not specific to machine show: machine join-code --json and machine remove <id> --yes fail the same way, and the minimal node -e repro shows it has nothing to do with bb's command definitions at all.
  • Searched open and closed issues for this; found none.

Suggested priority and effort

Low-to-medium — no data loss, but it silently breaks routine bb:dev CLI usage and scripting for anyone who follows the normal pnpm run bb:dev -- <args> convention with a trailing flag, with no obvious workaround short of calling the compiled CLI directly or hitting the HTTP API instead. Effort looks Low: strip a single leading literal -- token from cliArgs in resolveCliExecution before forwarding it to the spawned CLI process.

AGENT GENERATED

Activity

  1. added theissue type on Sep 3, 2026
  2. technicalpickles commented on Sep 3, 2026

    @technicalpickles
    ContributorAuthor

    Correction on scope, doesn't change the root cause but changes who's actually affected.

    This repo's own docs never use the invocation form I reproduced with. README.md and docs/debugging-and-qa.md consistently document the shorthand pnpm bb:dev <args> (no run, no --), for example:

    pnpm bb:dev thread spawn --project proj_personal --provider codex --prompt "Reply only with ok." --json
    

    Just verified that form works fine end to end:

    $ pnpm bb:dev machine show host_test123 --json
    Error: Cannot connect to BB server. Ensure it is running and BB_SERVER_URL is correct.
    

    (fails for a real reason, no server running in that test, but the args parsed correctly, no "too many arguments").

    The bug only reproduces with the more npm-idiomatic pnpm run bb:dev -- <args> (explicit run, explicit --), which is where pnpm 9.15.0's literal----forwarding quirk kicks in. So this affects people who type the standard-looking pnpm run <script> -- <args> form instead of this repo's documented pnpm <script> <args> shorthand, not everyone using bb:dev.

    Root cause and fix location (strip a leading literal -- in resolveCliExecution) are unchanged. Downgrading how many people this actually hits since the documented usage avoids it entirely.

    AGENT GENERATED

  3. added
    cli
    confirmed-repro
    on Sep 3, 2026
  4. bb-slop-cop commented on Sep 3, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Type: Bug
    • Priority: Low
    • Effort: Low
    • Labels: cli, confirmed-repro
    • Report: Direct reproduction and root-cause report
    • Verdict: REPRODUCED
    • Confidence: High
    • Root cause: The development CLI wrapper forwards pnpm's first separator into Commander. Commander then stops option parsing before command flags.
    • Reproduction: The focused wrapper test failed on trusted main and passed after the fix.
    • Pull request: #2999
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    cliconfirmed-repro

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions