Repository navigation
Studio CLI: Load @inquirer/prompts when a prompt is shown - #5316
Merged
Merged
Conversation
Every studio command loaded every prompt type, each with its own copy of @inquirer/core, before running.
Collaborator
📊 Performance Test ResultsComparing 806db48 vs trunk app-size
site-editor
site-startup
Results are median values from multiple test runs. Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff) |
1 task done
Contributor
|
Given the perf impact, this feels worth shipping. |
1 task done
chubes4
added a commit
that referenced
this pull request
Oct 27, 2026
## Related issues - Follows #5235, #5313 and #5316, which kept the MCP server, the `date-fns` root and `@inquirer/prompts` off CLI startup. ## How AI was used in this PR Claude (via the Pi coding agent in a Roadie session) profiled CLI startup, wrote the change and the test, and measured the before/after timings. I reviewed the diff and the measurements. ## Proposed Changes `apps/cli/index.ts` statically imported every top-level command module, and each module held the command's whole implementation. So every `studio` invocation loaded the implementation of every command before running one, including the export, import, push and pull code and its archive, upload and certificate libraries: 1,375 dependency files from 109 packages for `studio --version`. Each top-level command now has a `.command` module that defines the command (name, description, options) and loads the implementation with `await import()` in its handler, the pattern `wp` and `_events` already use. The implementation modules keep their paths and their `runCommand` exports, so their other callers are unchanged; each one's former handler body is now its exported `commandHandler`. - `studio list`, `start`, `stop`, `create` and `wp` load 520 dependency files at startup instead of 1,375. - Help output, unknown-command errors and option validation are byte-identical to trunk. - A `CommandArgs< typeof builder >` type keeps each handler typed from its command's options. Local timings on macOS (median of 8 alternating runs, Node 24): | Command | trunk | this PR | | --- | --- | --- | | `studio --version` | 0.40 s | 0.21 s | | `studio list` | 0.39 s | 0.23 s | | `studio status` | 0.42 s | 0.24 s | | `studio wp option get blogname` | 0.67 s | 0.48 s | | `studio stop` / `start` (already in that state) | 0.44 s | 0.26 s | The saving is a fixed cost per CLI process, so it applies to every command the desktop app and Studio Code run through the CLI. ## Testing Instructions - `npx vitest run --project cli apps/cli/tests/startup-imports.test.ts`: loading what `index.ts` imports statically must not load any command implementation. Making a `.command` module import its implementation statically fails it. - Build the CLI and compare `studio --help`, `studio create --help` and `studio foo` with trunk's output. - Time `studio list` or `studio wp option get blogname` against trunk. ## Pre-merge Checklist - [x] Have you checked for TypeScript, React or other console errors?
chubes4
added a commit
that referenced
this pull request
Oct 28, 2026
…ce-agent Conflicts: - apps/cli/index.ts, apps/cli/tests/startup-imports.test.ts: trunk's .command modules (#5495) load each command's implementation when it runs, which the spike's lazy top-level registration (2c7f7a8) did for `studio wp`; took trunk's. - apps/cli/ai/providers.ts: the spike's custom endpoint imports, with trunk's lazy prompts from cli/lib/prompts (#5316). - apps/cli/ai/slash-commands.ts: the spike's async getModels(), trunk's comment. - apps/cli/ai/tools/ask-user-question.ts: trunk removed the appended "Other" choice and added skipping (#5474); the description says so, positively. - apps/ui/.../site-actions-menu/index.tsx: trunk's Email item (#5359), the spike's Global Styles query.
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.
Related issues
date-fnsroot off thestudiostartup path. The Studio app runs the CLI for nearly everything, so startup time adds to each of those calls.How AI was used in this PR
Claude (via the Pi coding agent in a Roadie session) traced the modules loaded at startup, wrote the change and the test, and took the timings below. I reviewed the diff and the numbers.
Proposed Changes
Nine command and migration modules import
@inquirer/promptsat their top, and the CLI entry imports them all, so everystudiocommand loaded every prompt type before running. Each prompt package carries its own copy of@inquirer/core: about 260 modules, for prompts that most commands never show, and none when the app runs the CLI.cli/lib/prompts.tswraps the five prompts the CLI uses (confirm,input,password,select,search) and loads@inquirer/promptswhen one is shown. The wrappers keep the original signatures, including theValuetype ofselectandsearch.cli/lib/promptsinstead. Existing tests that mock@inquirer/promptswork unchanged.date-fnsroot,@inquirer/prompts) and reports which ones a command loads. It fails on trunk with[ '@inquirer/prompts' ].Testing Instructions
npx vitest run apps/cli/tests/startup-imports.test.tspasses; on trunk it fails.npx tsc --noEmit -p apps/cli/tsconfig.jsonis clean.input,confirmandselectwrappers took typed answers (text,y, arrow down + Enter) and returned{"a":"chubes","b":true,"c":2}.dist/cli(vite.config.dev.ts) against trunk at Clear the graceful-stop timer so site stop returns as soon as the site is down #5476, interleaved:studio --versionstudio --version, 30 runsThe saving is about 30 ms per command on this machine. CI's Performance Test Results show
siteStartupflat; 30 ms is below that metric's run-to-run noise.Pre-merge Checklist