Repository navigation
Run plugin CLI commands before loading core command groups - #8175
Merged
Merged
Conversation
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.
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.
Human comments
What was wrong
main()inapps/cli/src/index.tsloaded, evaluated and registered all 20 core command groups and ranaddJsonShapeHelp()before it calledtryPluginCommandProxy. For a plugin command (bb git,bb workflows,bb browser-automation),selectCommandGroupsreturns 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 fromprogram.commands, so it had to run after registration. #2349 moved the names to the staticCORE_COMMAND_GROUPStable but kept the order. I confirmed the cost with a resolve-hook trace of the built CLI (all 20 group chunks andjson-shapesload forbb fixture inspect x) and with timings before I changed anything.What changed
apps/cli/src/index.ts:main()loadscontext-envand 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 onlyprocess.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 rewritesprocess.argv[2]).startup-graph.test.tsasserts that a plugin command from the split bundle loads no core group chunk and nojson-shapeschunk.cli-entry-errors.e2e.test.tspins the error and suggestion for an unknown top-level name that no plugin owns (bb thraed listgivesDid you mean: bb thread?). The existing soft alias tests (bb host list --json,bb hosts --helpwith 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
startup-graph.test.ts("uses registered plugin help from the split artifact") against the unfixedindex.ts: fails, 20 core group chunks loaded (browser-*.jsthroughvoice-*.js). With the fix: passes.bb fixture inspect x(plugin)bb fixture inspect x(plugin)bb thread --help(core)bb --versionThe core command and
--versionrows 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/clihas nolinttask.oxfmt --checkon the changed files passes.Fixes #8174