Skip to content

Run plugin CLI commands before loading core command groups - #8175

Merged
ymichael merged 1 commit into
get-bb:mainfrom
lanjak:perf-cli-plugin-command-startup
Nov 25, 2026
Merged

ymichael merged 1 commit into
get-bb:mainfrom
lanjak:perf-cli-plugin-command-startup

Conversation

@lanjak

@lanjak lanjak commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Human comments

What was wrong

main() in apps/cli/src/index.ts loaded, evaluated and registered all 20 core command groups and ran addJsonShapeHelp() before it called tryPluginCommandProxy. For a plugin command (bb git, bb workflows, bb browser-automation), selectCommandGroups returns every group because the first argument is not a core name, and the proxy then runs the command and exits. So every plugin command paid for code it never used: about 120 ms of CPU and 40 to 60 ms of wall time on this machine. The order is left from before #2349: at that time the proxy read the known command names from program.commands, so it had to run after registration. #2349 moved the names to the static CORE_COMMAND_GROUPS table but kept the order. I confirmed the cost with a resolve-hook trace of the built CLI (all 20 group chunks and json-shapes load for bb fixture inspect x) and with timings before I changed anything.

What changed

  • apps/cli/src/index.ts: main() loads context-env and runs the plugin proxy first, then loads and registers the selected command groups. The proxy block moved; no code was added. When no plugin owns the name, the proxy returns and the CLI continues on the same path as before with the same groups, so the new order can cost nothing extra and cannot change the output of a core command, an unknown command or a soft alias. The proxy reads only process.argv, the server URL and the server response, and registration reads nothing the proxy writes (the group list is chosen from the first argument before the soft alias rewrites process.argv[2]).
  • Tests: startup-graph.test.ts asserts that a plugin command from the split bundle loads no core group chunk and no json-shapes chunk. cli-entry-errors.e2e.test.ts pins the error and suggestion for an unknown top-level name that no plugin owns (bb thraed list gives Did you mean: bb thread?). The existing soft alias tests (bb host list --json, bb hosts --help with the server down) and plugin help tests did not change and still pass.

No wire, CLI or protocol changes.

Not done: the soft alias path still loads all groups, as before. Loading only the alias target would be a separate change in behavior with a small gain, because soft aliases are rare compared to plugin commands.

How you verified

  • New assertion in startup-graph.test.ts ("uses registered plugin help from the split artifact") against the unfixed index.ts: fails, 20 core group chunks loaded (browser-*.js through voice-*.js). With the fix: passes.
  • New e2e test for the unknown command passes before and after the change (it guards the fallback path).
  • Timings of the built CLI against a local fixture server, 30 runs per case, two rounds each (median):
Command Measure Before After
bb fixture inspect x (plugin) wall time 206.5 / 228.3 ms 165.2 / 169.9 ms
bb fixture inspect x (plugin) CPU user+sys 321 / 304 ms 193 / 185 ms
bb thread --help (core) wall time 127.5 / 135.7 ms 133.9 / 123.6 ms
bb --version wall time 32.5 / 32.9 ms 32.3 / 58.9 ms (noise)

The core command and --version rows show no change outside the noise of a shared machine.

  • pnpm exec turbo run typecheck test lint lint:type-aware --continue --filter=@bb/cli: all tasks pass (81 test files, 1438 tests). @bb/cli has no lint task. oxfmt --check on the changed files passes.

Fixes #8174

AGENT GENERATED

The bb entry point loaded and registered all 20 core command groups and
added the JSON shape help before it asked the server for plugin
commands. A plugin command exits inside the proxy, so this work was
never used. The order came from before get-bb#2349, when the proxy read the
known command names from the registered program. The names now come
from CORE_COMMAND_GROUPS, so the proxy can run first.
@ymichael
ymichael merged commit 9b67e8d into get-bb:main Nov 25, 2026
26 checks passed
@lanjak
lanjak deleted the perf-cli-plugin-command-startup branch November 25, 2026 22:58
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.

Plugin CLI commands load every core command group before they run

2 participants