Skip to content

Add refresh_browser tool so the agent can reload the site preview - #4027

Merged
bcotrim merged 1 commit into
trunkfrom
explore-stu-1904
Jul 2, 2026
Merged

Add refresh_browser tool so the agent can reload the site preview#4027
bcotrim merged 1 commit into
trunkfrom
explore-stu-1904

Conversation

@bcotrim

@bcotrim bcotrim commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Related issues

How AI was used in this PR

Built with Claude Code: explored the agent tool + site-preview architecture, implemented the tool and event wiring, and wrote the unit tests. I reviewed every change myself and validated the behavior manually in the app. No CSS/color changes, so there is nothing to review in dark mode.

Proposed Changes

The Studio agent had no way to refresh the in-app site preview after making changes, so it fell back to stopping and starting the whole site just to force a fresh webview mount — slow, disruptive, and impossible when the site was already running (the preview would simply stay stale). This adds a refresh_browser tool that reloads the preview in place via a dedicated preview.reload event, and steers the agent through its system prompt to use it after user-visible changes instead of restarting the site. Users now see their agent-made changes reflected immediately, without a server restart.

Testing Instructions

  1. Start Studio, open the agentic UI, and select a running local site with the preview panel open.
  2. Ask the agent to change something visible without navigating, e.g. Run wp-cli option update blogname "Reloaded-1" on this site. The preview still shows the old title.
  3. Ask the agent to refresh the browser preview. It should call refresh_browser (shown as "Refresh preview") and the header should update in place — with no site stop/start.
  4. Automated: npm test -- apps/cli/ai/tests/tools.test.ts and npm test -- apps/ui/src/hooks/use-session-commands.test.tsx.

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
@bcotrim bcotrim self-assigned this Jul 1, 2026
@bcotrim
bcotrim requested review from a team and shaunandrews July 1, 2026 12:40
@wpmobilebot

Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing 4b3b907 vs trunk

app-size

Metric trunk 4b3b907 Diff Change
App Size (Mac) 1316.83 MB 1316.83 MB +0.00 MB ⚪ 0.0%

site-editor

Metric trunk 4b3b907 Diff Change
load 738 ms 1115 ms +377 ms 🔴 51.1%

site-startup

Metric trunk 4b3b907 Diff Change
siteCreation 6534 ms 6500 ms 34 ms ⚪ 0.0%
siteStartup 1853 ms 1858 ms +5 ms ⚪ 0.0%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff)


export const refreshBrowserTool = defineTool(
'refresh_browser',
'Reloads the site preview browser in the Studio app so the user sees your latest changes. Call this after a change that alters what the site renders (content, options/settings, theme, plugins, activation). It reloads in place — never stop/start the site (site_stop/site_start) just to refresh the preview.',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this is a much better experience than having to reload things manually which I was doing before

@katinthehatsite katinthehatsite left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good 👍 I asked to make some visual changes like adjusting colors and I noticed that the preview refreshed by itself once the agent was done without me having to do it manully. I think this is a much better experience.

@bcotrim
bcotrim merged commit 7be5da1 into trunk Jul 2, 2026
14 checks passed
@bcotrim
bcotrim deleted the explore-stu-1904 branch July 2, 2026 18:11
@gcsecsey gcsecsey mentioned this pull request Jul 7, 2026
1 task
gcsecsey added a commit that referenced this pull request Jul 7, 2026
## Related issues

- N/A

## How AI was used in this PR

Claude cross-checked the auto-generated 1.14.0 changelog against the
merged PRs, classifying them as user-facing or internal, and drafting
the 1.14.0 wording. I reviewed the changes before raising the PR.

## Proposed Changes

- Replace the generated `1.14.0` release-note block with a shorter,
user-facing summary.
- Grouped the Studio Code changes and folded the shipped dependency
bumps into a single "Updated multiple dependencies" line.
- Omitted changes not yet visible to users:	
	- the `studio ui` browser surface and `refresh_browser` preview tool
	- both part of the not-yet-released agentic UI (#3953, #4027)
- internal-only PRs (CI/test infra and CI dependency bumps, the Studio
apps design doc, release tooling, and internal state/vendor cleanups)
- For the Windows E2E PR (#4082), surfaced only the user-facing part:
native-PHP sites failing to load on Windows when the profile path uses
an 8.3 short name.

## Testing Instructions

- Read the `1.14.0` section of `RELEASE-NOTES.txt`
- Confirm the groupings and wording read well and are accurate
- Cross-check against the merged-PR list for anything important that
should be surfaced or reworded

## Pre-merge Checklist

- [ ] Have you checked for TypeScript, React or other console errors?

---------

Co-authored-by: Fredrik Rombach Ekelund <fredrik@f26d.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants