Repository navigation
Conversation
Studio Code sessions now load the user's pi extensions from ~/.studio/agent/extensions, the way pi loads ~/.pi/agent/extensions. An extension can add tools, register providers, and extend the system prompt on each turn through pi's own API. The agent directory moves off the sites root, which stays an untrusted project, so project extensions do not load. An extension that fails to load is reported and skipped.
c0ef756 to
391d677
Compare
📊 Performance Test ResultsComparing 391d677 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) |
|
Why do we want to do that? We're using pi as a framework and I'm not sure we should allow pi extensions. |
|
I am picturing that Studio should have the freedom and extensibility of WordPress itself. This was a first step towards enabling users to bring their own model or provider to Studio. It would also let users add their own tools and extend the system prompt. However it wouldn't actually enable BYO because our providers list is still closed. So it's more of a primitive capability than anything else. I set it back to draft, as I think it's premature compared to some of the other changes that need to be made. |
Related issues
How AI was used in this PR
Claude (via the Pi coding agent in a Roadie session) traced how Studio Code configures pi's resource loader, made the change, wrote the tests, and ran the checks below. I reviewed the diff.
Proposed Changes
Studio Code runs on pi but turns its extension system off (
noExtensions: truesince #3360), so the only way to change the agent's tools, providers or prompt is to change Studio. This turns it on.~/.studio/agent/extensions, the same way pi loads~/.pi/agent/extensions. An extension uses pi's API as is:pi.registerTool()adds a tool. Studio now enables extension tools next to its own; before, the session's tool allowlist only named Studio's.pi.on( 'before_agent_start' )extends the system prompt on each turn.pi.registerProvider()registers a provider. Picking an extension's model in Studio is a follow-up.getAgentDirectory()(~/.studio/agent) inwell-known-paths. pi's agent directory was the sites root (~/Studio), which is the wrong home forextensions/. The sites root stays the session's working directory and stays untrusted, so project-level extensions (~/Studio/.pi/extensions) do not load.console.warnand skipped, and the turn runs without it.Extension tools are the user's own code, run with the user's permissions, as in pi. Studio's guards (payload limits, core-file refusal) stay on Studio's own Write, Edit and Bash; they do not wrap extension tools.
Testing Instructions
npx vitest run apps/cli/ai packages/common/lib: 925 passed, 1 skipped. New tests:before_agent_starthandler, and its tool is enabled next to Studio's;Live, through the WordPress.com AI proxy, with a temporary config directory holding
agent/extensions/motto.js. The extension registers astudio_mottotool and appends a section to the prompt that says to use it for the team motto. The prompt was "What is our team motto?":studio_mottoand quoted "code is poetry, ship it kumquat-7." (23.9k tokens)Pre-merge Checklist