Repository navigation
Studio Code: Reload the preview in the app when the agent finishes, instead of asking the agent to - #5171
Open
chubes4 wants to merge 8 commits into
Open
Studio Code: Reload the preview in the app when the agent finishes, instead of asking the agent to#5171chubes4 wants to merge 8 commits into
chubes4 wants to merge 8 commits into
Conversation
…nstead of asking the agent to The prompt told the agent to call refresh_browser after any change that alters what the site renders. Studio now reloads the preview itself at the end of a turn in which a file write, a WP-CLI or WordPress.com write, a theme scaffold, an import or a pull succeeded. The refresh_browser tool and its prompt rule go.
A turn changed the preview when something under the active site's wp-content (themes, plugins, uploads, the SQLite database) changed during it, whichever tool or command changed it.
chubes4
marked this pull request as ready for review
October 17, 2026 15:18
Collaborator
📊 Performance Test ResultsComparing add0bd4 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) |
WordPress writes to the database in the background: WP-Cron on the next request after an event falls due (every minute with WooCommerce), and the block editor's post locks and autosaves. Checked per turn, those writes reloaded the preview after nearly every turn on such sites. Checked per request, they cause at most one reload, when the agent finishes.
A turn's tool calls name the files they touch. At the end of a turn whose named file in the site's wp-content changed since the last reload, the preview reloads, so a build shows its theme and styles as they land. When the request ends, an asynchronous walk that stops at the first changed file catches what tool paths cannot show: wp commands, Bash and the database. The walk never blocks the CLI, and it only reloads if something changed since the last reload.
WordPress writes to its database in the background: WP-Cron on the next request after an event falls due, and the block editor's post locks and autosaves. When a request ends, the database now counts only if the request ran a command or a tool annotated as replacing data, the calls that can write it without naming a file. The reload event says whether a tool call changed the site or the request ended. The app leaves a preview showing wp-admin alone on the second kind, so an editor with unsaved changes is never reloaded under the person using it.
A reload after a tool's change recorded Date.now() as the last reload. File times can be later than the process clock, as on Windows, so the check when the request ended found the same file newer and reloaded again. The last reload is now the newest change it showed, when that is later than the clock.
The preview is a browser: it shows a page as it loaded, whoever changed the site. The app already knows when the agent finishes a request, so it reloads the preview then, in place and without opening a closed panel. wp-admin is left alone, where the person may have unsaved edits. This replaces the CLI's detection of site changes from tool paths and file times, and the preview.reload event, which nothing emits any more.
The app's session commands reload the preview on run.exited and run.interrupted, in place and without opening a closed panel, and leave wp-admin alone. The preview.reload event and the chatArtifactsEnabled prompt option have no users left.
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
How AI was used in this PR
Claude (via the Pi coding agent in a Roadie session) wrote the change and its tests and ran the checks below. Opened as a draft for human review.
Proposed Changes
When the Studio app is attached, the prompt told Studio Code: "After a change that alters what the site renders …, call refresh_browser so the in-app preview shows the result." Keeping the preview current was the agent's job, and depended on it remembering a mechanical step.
The preview is a browser (an Electron
<webview>with its own Refresh button). Like any browser, it shows a page as it loaded, whoever changed the site, whether the agent or someone runningwpby hand. Keeping it current belongs to the app, and the app already knows when the agent finishes: it receivesrun.exitedandrun.interruptedfor every request.refresh_browsertool, its prompt rule, thechatArtifactsEnabledprompt option that only existed for that rule, and thepreview.reloadevent, which nothing emits any more. The app keeps itsrefresh_browsericon and label so older sessions still display.Trade-offs:
refresh_browser, so mid-request refreshes look rarely used.Testing Instructions
npx vitest run apps/ui/src/hooks apps/cli/ai/tests/tools.test.ts apps/cli/ai/tests/system-prompt.test.ts. They check that the preview reloads when a run exits or is interrupted, not when it starts or for another session's run; that the reload keeps the current page and leaves a closed panel closed; and that wp-admin isn't reloaded.refresh_browsercall in the conversation. Open a post in the editor in the preview, ask a question, and check the editor isn't reloaded.Pre-merge Checklist