Skip to content

Fix AI screenshot local site resolution#3307

Open
chubes4 wants to merge 3 commits intotrunkfrom
fix-ai-screenshot-local-site
Open

Fix AI screenshot local site resolution#3307
chubes4 wants to merge 3 commits intotrunkfrom
fix-ai-screenshot-local-site

Conversation

@chubes4
Copy link
Copy Markdown
Contributor

@chubes4 chubes4 commented Apr 30, 2026

Summary

  • Allow both take_screenshot and share_screenshot to target local Studio sites with the same nameOrPath contract used by the rest of the local-site AI tool surface.
  • Add a small resolveScreenshotUrl() helper consumed by both tools.
  • Preserve existing absolute url screenshot behavior; emit a clean error when neither url nor nameOrPath is provided.

Why

The local Studio AI prompt tells agents to use take_screenshot after building a local site, but the tool originally only accepted url. Neighboring local-site tools such as wp_cli and validate_blocks accept nameOrPath, so agents can naturally call take_screenshot with nameOrPath + path and hit MCP schema validation before the screenshot handler runs.

share_screenshot (added by #3272) has the same URL-resolution gap: agents that know a local Studio site by name must already know its public URL to share a screenshot of it. Per the standing "fix upstream first, never paper over" rule, fixing one tool but not the other would calcify the workaround pattern. Both tools now share the same resolver and the same fallback behavior — pass url, or pass nameOrPath (+ optional path), or get a clean error.

Closes #3306.

What changed since the original draft

  • Extended resolveScreenshotUrl() to share_screenshot in addition to take_screenshot. Both tools now accept the same { url?, nameOrPath?, path? } shape and call the same resolver.
  • Slimmed the test diff to a single regression test that proves nameOrPath resolves correctly. The previous draft had four behavior tests plus a mock helper; the regression we need to guard against is specifically "agent passed nameOrPath, screenshot resolved against the local site." Types and existing trunk tests cover gating and tool-list shape; explicit-URL / path-composition / missing-input error cases can land in follow-up coverage if needed.

Tests

  • npx vitest run apps/cli/ai/tests/tools.test.ts — 22 passed
  • npx eslint apps/cli/ai/tools.ts apps/cli/ai/tests/tools.test.ts — clean
  • npm run typecheck --workspace apps/cli — clean

AI assistance

  • AI assistance: Yes
  • Tool(s): OpenCode (GPT-5.5) for the original draft; Claude Code (Sonnet 4.5) for the share_screenshot extension and test slimming.
  • Used for: OpenCode isolated the tool-contract mismatch, drafted the small fix, and added focused tests. Claude Code extended the resolver to share_screenshot, slimmed the test diff, and updated this description under Chris's direction. Chris reviewed both passes.

@wpmobilebot
Copy link
Copy Markdown
Collaborator

wpmobilebot commented Apr 30, 2026

📊 Performance Test Results

Comparing 175ffc2 vs trunk

app-size

Metric trunk 175ffc2 Diff Change
App Size (Mac) 1557.92 MB 1511.28 MB 46.65 MB 🟢 -3.0%

site-editor

Metric trunk 175ffc2 Diff Change
load 1514 ms 1478 ms 36 ms ⚪ 0.0%

site-startup

Metric trunk 175ffc2 Diff Change
siteCreation 8099 ms 8095 ms 4 ms ⚪ 0.0%
siteStartup 4946 ms 4949 ms +3 ms ⚪ 0.0%

Results are median values from multiple test runs.

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

chubes4 added 2 commits May 1, 2026 07:56
…cal-site

# Conflicts:
#	apps/cli/ai/tools.ts
After PR #3272 (CLI: send screenshots from studio code to Telegram
remote sessions, merged 2026-05-01) the codebase has two screenshot
tools that capture a URL: take_screenshot for agent-internal visual
reasoning, and share_screenshot for fire-and-forget delivery to the
user. This branch's resolveScreenshotUrl helper was originally only
applied to take_screenshot, but share_screenshot has the same
URL-resolution gap: agents that know a local Studio site by name
must already know its public URL to share a screenshot of it.

Apply the same nameOrPath/path schema and resolveScreenshotUrl call
to share_screenshot. Both tools now accept the same shape, both
errors out cleanly when neither url nor nameOrPath is provided.

Slim the test diff to a single regression test. The original branch
added four behavior tests plus a mockScreenshotBrowser helper, but
the regression we're guarding against is specifically 'agent passed
nameOrPath, screenshot resolved correctly'. The other cases (explicit
URL, path composition, error path) are nice-to-haves and can land in
follow-up coverage if needed; types and existing trunk tests cover
the gating and tool-list shape.

## AI assistance
- **AI assistance:** Yes
- **Tool(s):** Claude Code (Sonnet 4.5)
- **Used for:** Drafted the share_screenshot extension and slimmed
  the test diff under Chris's direction. Chris reviewed the scope
  trade-off (extend to both tools vs leave share_screenshot for
  later) and chose the unconditional both-tools fix per the
  fix-upstream-first rule.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Studio MCP take_screenshot should accept local site nameOrPath

2 participants