apps/ui: auto-refresh site preview as the agent edits#3235
Merged
youknowriad merged 2 commits intotrunkfrom Apr 24, 2026
Merged
apps/ui: auto-refresh site preview as the agent edits#3235youknowriad merged 2 commits intotrunkfrom
youknowriad merged 2 commits intotrunkfrom
Conversation
Adds two MCP tools (preview_navigate, preview_reload) the agent calls after editing a page, template, or theme so the Studio site-preview iframe updates in sync with the work. Commands flow from the CLI child process through the existing ai-agent-event IPC stream to the renderer, where SitePreview subscribes (scoped by sessionId) and remounts the iframe. Tools are gated on a forked-by-desktop signal so plain CLI runs neither see nor mention preview-steering tools. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Collaborator
📊 Performance Test ResultsComparing dc458ab 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) |
Array.prototype.includes narrows on the element type, which fails against the broader studioToolDefinitions union. Switch to a Set of tool names so the filter doesn't depend on the narrower subtype. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
Authored with Claude Code. The model drove the implementation end-to-end (architecture discussion → MCP tool design → renderer wiring → tests). I reviewed and steered at each step — asked for a detailed architecture of the most-reliable option, had it gate the tools for standalone CLI after I noticed the noisy tool-call messages, and flagged follow-ups rather than bundling them. Verification (typecheck, lint, 110 unit tests) was run locally.
Proposed Changes
apps/cli/ai/tools.ts):preview_navigate(path)andpreview_reload()— the agent calls these as a side effect of its editing loop. HandlersemitEvent({ type: 'preview.command', ... })and return synchronously.preview.commandvariant toJsonEvent(tools/common/ai/json-events.ts). Events ride the existing CLI→main→rendererai-agent-eventchannel — no new IPC surface.apps/ui/src/components/site-preview/index.tsx):SitePreviewnow takes asessionId, subscribes toconnector.onAgentEvent, filters for matchingpreview.commands, and drives the iframe viacurrentPath+ areloadNonce. The nonce is baked into the iframekeyso reloads force a remount — more reliable thaniframe.contentWindow.location.reload()across self-signed certs / custom-domain boundaries.apps/ui/src/components/session-view/index.tsx): passessessionIdtoSitePreview.apps/cli/ai/agent.ts,apps/cli/ai/tools.ts,apps/cli/ai/system-prompt.ts):enablePreviewSteeringis derived fromtypeof process.send === 'function'(the same signalemitEventuses to pick IPC vs stdout). When the CLI runs standalone — not forked by the desktop app — the preview tools are filtered out of the MCP server and omitted from the system prompt, so the model never sees them and the terminal transcript doesn't show noisy "Reload preview" / "Navigate preview" entries.tools/common/ai/tools.ts): so the desktop transcript rendersNavigate preview /about/nicely.preview_reloadafter editing theme/CSS/homepage andpreview_navigateafter editing a specific page/post/template.apps/cli/ai/tests/tools.test.tscovering navigate normalization, empty-path fallback, reload emission, and the gating behavior (with and withoutenablePreviewSteering).What isn't here yet
turn.completed. If the agent forgets to call the tools, nothing updates the preview. Intentionally left as a follow-up — want to see how good model compliance is on the system-prompt guidance first before layering a belt-and-suspenders reload inrun-manager.Testing Instructions
Pre-merge Checklist