Repository navigation
Description
Summary
Every plugin CLI command (bb git, bb workflows, bb browser-automation, and other plugin commands) loads, evaluates and registers all 20 core command groups, and adds the JSON shape help, before the CLI asks the server for plugin commands. The plugin proxy then runs the command and calls process.exit, so none of that work is used. On this machine it costs about 120 ms of CPU and 40 to 60 ms of wall time on each plugin command. Agents call plugin commands in loops (for example one bb browser-automation call for each page action), so the cost adds up.
Versions and environment
- bb from source at origin/main fb045a0.
- Linux (CachyOS, kernel 7.3.4), Node v26.13.1.
- CLI built with
pnpm exec turbo run build --filter=@bb/cli(split bundle, as shipped).
Steps to reproduce
- Build the CLI:
pnpm exec turbo run build --filter=@bb/cli. - Start a fixture server on 127.0.0.1 that answers
GET /api/v1/plugins/contributionswith one plugin commandfixture inspectand answersPOST /api/v1/plugins/fixture-plugin/cliwith{"exitCode":0,"stdout":"ran\n","stderr":""}. - Run
BB_CLI_REEXEC=1 BB_SERVER_URL=<fixture url> node apps/cli/dist/index.js fixture inspect x30 times and record wall time and user+sys CPU time. - Record the modules that the run loads with a Node resolve hook (the method of
apps/cli/src/__tests__/startup-graph.test.ts).
Expected vs actual
Expected: a plugin command loads no core command group, because the plugin proxy handles it and exits.
Actual: the run loads all 20 core group chunks (browser-*.js, status-*.js, settings-*.js, ... voice-*.js) and json-shapes-*.js.
Timings for bb fixture inspect x, 30 runs each, two rounds:
| Measure | Round 1 | Round 2 |
|---|---|---|
| Wall time, median | 206.5 ms | 228.3 ms |
| CPU user+sys, median | 321 ms | 304 ms |
For comparison, bb --version takes 32.5 ms wall time.
Evidence
main()loads the groups, registers them and runsaddJsonShapeHelp()first, and callstryPluginCommandProxyonly after that:Lines 207 to 259 in fb045a0
async function main(): Promise<void> { const firstArg = process.argv[2]; const groups = selectCommandGroups(firstArg); if (groups.length === 0) { await parseProgram(null); return; } const [contextEnv, ...registrars] = await Promise.all([ import("./context-env.js"), ...groups.map((group) => group.load()), ]); const deps = createCommandGroupDeps(contextEnv); program.addHelpText("after", () => { const context = deps.getContext(); const project = context.projectId ?? "<unset>"; const thread = context.threadId ?? "<unset>"; return ` Current context: BB_PROJECT_ID: ${project} BB_THREAD_ID: ${thread} BB_SERVER_URL: ${context.serverUrl} Quick start: bb status bb project list bb thread show <id> bb thread spawn --project <id> --provider codex --prompt "..." `; }); for (const register of registrars) { register(program, deps); } await addJsonShapeHelp(); const candidate = pluginProxyCandidate(firstArg, KNOWN_COMMAND_NAMES); if (candidate !== null) { const { TOP_LEVEL_SOFT_ALIASES } = await import("./command-resolution.js"); const aliasTarget = TOP_LEVEL_SOFT_ALIASES[candidate]; await tryPluginCommandProxy( candidate, deps.getUrl, aliasTarget !== undefined, ); if (aliasTarget !== undefined) process.argv[2] = aliasTarget; } await rejectHelpForUnknownSubcommand(deps.getUrl); await parseProgram(deps.getUrl); } selectCommandGroupsreturns allCORE_COMMAND_GROUPSwhen the first argument is not a core command name, which is always true for a plugin command:bb/apps/cli/src/command-groups.ts
Lines 135 to 141 in fb045a0
export function selectCommandGroups( firstArg: string | undefined, ): readonly CommandGroup[] { if (firstArg === "--version" || firstArg === "-V") return []; const match = CORE_COMMAND_GROUPS.find((entry) => entry.name === firstArg); return match === undefined ? CORE_COMMAND_GROUPS : [match]; } tryPluginCommandProxyreads onlyprocess.argv, the server URL and the server response. It callsprocess.exitwhen a plugin owns the command:Lines 48 to 112 in fb045a0
async function tryPluginCommandProxy( candidate: string, getUrl: () => string, isSoftAlias: boolean, ): Promise<void> { const proxy = await import("./plugin-cli-proxy.js"); const result = await proxy.fetchPluginCliContributions(getUrl()); if (result.outcome === "unreachable") { if (isSoftAlias) return; const message = proxy.describeUnreachableServer( getUrl(), result.cause, result.lastTimeoutMs, result.attempts, ); console.error(message); const { isJsonInvocation, writeCliErrorEnvelope } = await import("./cli-error-output.js"); writeCliErrorEnvelope( { code: "server_unreachable", hint: null, message }, isJsonInvocation(process.argv), ); process.exit(1); } if (result.outcome === "invalid") return; const match = proxy.findPluginCliCommand(result.contributions, candidate); if (match === undefined) { const disabledId = await proxy.findDisabledPluginForCommand( getUrl(), candidate, ); if (disabledId !== null) { console.error( `bb ${candidate} is provided by the "${disabledId}" plugin, which is disabled — ` + `run \`bb plugin enable ${disabledId}\` or enable it in Plugins.`, ); process.exit(1); } return; } const argv = process.argv.slice(3); const command = match.commands.find((entry) => entry.name === argv[0]); if ( command !== undefined && match.rendersHelp !== true && argv.slice(1).some((arg) => arg === "--help" || arg === "-h") ) { console.log(command.usage); process.exit(0); } const exitCode = await proxy.runPluginCliCommand( getUrl(), match.pluginId, argv, ); if (exitCode !== 0) { await logCliError({ code: "plugin_command_failed", command: proxy.pluginCommandLabel(match, argv), exitCode, token: null, }); } process.exit(exitCode); } - Cause of the order: before perf: load bb command groups on demand and split the CLI bundle (C1) #2349,
tryPluginCommandProxybuilt the set of known command names fromprogram.commands, so it had to run after registration. perf: load bb command groups on demand and split the CLI bundle (C1) #2349 moved the names to the staticCORE_COMMAND_GROUPStable (KNOWN_COMMAND_NAMES), but kept the old order.
Timing method: a Node script ran the built CLI 30 times for each case and took the median of process.hrtime around execFile. CPU time came from the bash time builtin (TIMEFORMAT='%U %S'). The machine had other load, so the numbers vary between rounds.
What you ruled out
- The proxy does not depend on the registered program: it passes its own command label to the error log, and it does not call commander.
- Core commands (
bb thread --help) already load only their own group, so they are not affected. bb --versionloads no group and is not affected.
AGENT GENERATED
Activity
bb-slop-cop commentedon Nov 25, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilotcli, plusperf.confirmed-repro.fb045a0466each load all 20 core groups and JSON-shape help for a successful plugin command. The startup probe fails its zero-core-import assertion in both; all 8 existing startup tests pass. Exact timing savings were not measured.Run plugin CLI commands before loading core command groups (get-bb#8175)