Repository navigation
Conversation
… it in the prompt
1 task
… a broker in the agent process
The broker saved about a second per call, but its socket and client script are more than the agent needs. Faster CLI startup is tracked in #5169.
1 task done
chubes4
added a commit
that referenced
this pull request
Oct 21, 2026
## Related issues - Related to #5166, which runs WP-CLI as `studio wp` from the agent's shell, so `studio` startup time adds to every WP-CLI call. ## How AI was used in this PR Claude (via the Pi coding agent in a Roadie session) profiled `studio` startup, traced the import chain, wrote the change and the test, and took the timings below. I reviewed the diff and the numbers. ## Proposed Changes Every `studio` command loaded the whole agent runtime before running. The CLI entry imports each command module up front, and `commands/mcp.ts` imported the MCP server at its top, which brings every agent tool and the Pi agent with them (highlight.js, typebox, undici, …). `studio --version` loaded 3,765 modules, and about 4,000 in the shipped 1.24.0 app. - `studio mcp` now loads the MCP server inside the command, the same way `studio ai` already loads its runtime. - A test imports everything the CLI entry imports statically and checks the agent runtime stays unloaded. It reads the imports from `index.ts`, so a command added later is covered too. It fails on trunk. - Vitest gets the `@studio/local` alias the build already has. Without it, no test could load `commands/ui.ts`. ## Testing Instructions - `npx vitest run apps/cli/tests/startup-imports.test.ts` passes; with the `commands/mcp.ts` change reverted, it fails. - `npx vitest run --project cli`: 1,158 pass. - From a built CLI (`cd apps/cli && npx vite build --config ./vite.config.dev.ts`), same machine, 5 runs each: | Command | Trunk | This branch | |---|---|---| | `node dist/cli/main.mjs --version` | 1.8 s, 3,765 modules | 0.7 s, 1,132 modules | | `node dist/cli/main.mjs wp --path=<site> option get siteurl` | 1.29–1.57 s (median 1.40) | 0.93–1.15 s (median 1.00) | - `studio mcp` still starts the MCP server: after `initialize`, `tools/list` returns its 30 tools. ## Pre-merge Checklist - [x] Have you checked for TypeScript, React or other console errors?
Contributor
Author
|
Closing to focus on #5146 as the larger architectural proof. |
chubes4
added a commit
that referenced
this pull request
Oct 24, 2026
`wp` in Studio Code's Bash is Studio's WP-CLI for the site the command runs in (the PATH shim from #5166), so the rule that refused `wp` in the shell, added because a bare `wp` reached the system binary, has nothing left to guard. The wp_cli tool leaves Studio Code; `studio mcp` keeps it for clients without a shell. The checks that only wp_cli had leave with it, as the shell already runs without them: the irreversible WP-CLI and other-site confirmations (Studio's own tools keep theirs), and the refusal of post content from a file with open validation problems. Block markup is still validated as it is written, and a shell call waits for that validation and reports it, as wp_cli did. The preview reloads after a successful shell call.
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
wpin Bash instead of making it workHow AI was used in this PR
Claude (via the Pi coding agent in a Roadie session) traced why the prompt forbids
wpin Bash, wrote the change and its tests, and ran the checks and agent runs below. Opened as a draft for human review.Proposed Changes
The prompt told Studio Code: "Never run
wpcommands via Bash — always use the wp_cli tool instead." That rule dates from when sites ran in PHP-WASM and a systemwpran on a different PHP (#2632, #2970). Sites now run on native PHP, andstudio wpruns the samerunWpCliCommandaswp_cli. So Studio Code now runs WP-CLI the normal way, aswpin its shell:wpin the agent's shell is Studio's WP-CLI. The Bash tool'sspawnHookputs a directory first onPATHholding a one-linewpscript:exec node <studio cli> wp "$@". Sowpruns on Studio's bundled PHP at the site's version, with the SQLite mu-plugins and Reprint runtimes, and gets the shell's stdin, environment and exit code. A systemwp, where one is installed at all, has none of these.studiocommand start faster.studio wpfinds the site from any directory inside it, the way WP-CLI does. Before, it needed the exact site root. This also helps people using the CLI directly.wp_clitool (shellRunsStudioWp). With both available, the agent kept picking the tool. The MCP server keepswp_clifor external agents.wp_cli's checks:–porcelain) moves intostudio wp, so it applies to every route.$(cat file)post-content check stays withwp_cli, the only place it applies: in a real shell,$(cat file)is simply correct.wp plugin list,wp eval-file …) instead of naming a Studio tool. Studio Code runs them as written. External agents get one line saying to run a skill'swpcommands withwp_cliorstudio wp, the same convention as theSTUDIO.mdinstalled into site folders.TAXONOMIST_*environment variables foreval-file, whichwp_clicannot do. They are now single shell commands (TAXONOMIST_OUTPUT=… wp eval-file …), matching the usage lines in the scripts themselves.wpvia Bash" rule is gone, with nothing replacing it. Oncewp_cliis gone, the agent reaches forwpin its shell without any hint. An earlier version stated the fact in the Bash tool's description; runs without that sentence passed just the same, so it was dropped.wp_cli:studio mcpdocuments Claude Desktop as a target. It has no shell on the user's machine, sowp_cliis its only way to run WP-CLI.Testing Instructions
npx vitest run apps/cli/ai/tests/studio-wp-shim.test.ts apps/cli/lib/cli-config/tests/sites.test.ts apps/cli/lib/tests/wp-cli-options.test.ts apps/cli/ai/tests/tools.test.tswpthrough/bin/shthe way the Bash tool does, with a stand-in for PHP. They check that the arguments, stdin, an inline environment variable (TAXONOMIST_MODE=apply wp …) and the exit code all reach it.cd ~/Studio/<site>/wp-content/plugins && wp option get siteurl && wp cli version. It prints the site URL and Studio's bundled WP-CLI (2.12.0 here), not a systemwp.wp option get siteurl, median of 7, on a heavily loaded machine, so compare the rows rather than the absolute numbers):wp_clitool, in-processwpin Bash, throughstudio wpOn a quieter run,
studio wptook 1.55 s against 0.63 s for PHP and WP-CLI alone.cd <site> && wp …in Bash. The same 4 runs, repeated without any mention ofwpin the Bash tool description, also passed 4 of 4.Pre-merge Checklist