Skip to content

Support new blank or child themes in Studio Code - #4209

Merged
sejas merged 7 commits into
trunkfrom
stu-2017-support-blank-child-themes
Jul 17, 2026
Merged

Support new blank or child themes in Studio Code#4209
sejas merged 7 commits into
trunkfrom
stu-2017-support-blank-child-themes

Conversation

@sejas

@sejas sejas commented Jul 15, 2026

Copy link
Copy Markdown
Member

Related issues

When asked to customize a site running an installed theme (e.g. Ollie), Studio Code edited the theme's files directly. Any later theme update would silently wipe every customization — the exact failure reported in STU-2017.

How AI was used in this PR

AI assisted with implementation, code review, and simplification passes; all changes were verified with unit tests, typecheck, and lint.

Proposed Changes

  • Studio Code now defaults to creating a child theme when customizing an installed third-party theme: scaffold_theme accepts a parentTheme slug and scaffolds a minimal block child theme (inherits the parent's templates, parts, patterns, theme.json settings, and styles) and activates it. Customizations survive parent theme updates.
  • The child scaffold defensively enqueues the parent's style.css (Theme Handbook pattern), so parents that enqueue via get_stylesheet_uri() keep their styling when the child is active.
  • The agent's instructions now forbid editing installed third-party theme files by default. Themes Studio Code itself created remain directly editable. If the user explicitly asks to edit an installed theme's files, the agent warns once about the update-wipe risk and then complies.
  • Guardrails reject invalid setups with actionable errors: parent not installed, grandchild themes (points to the real parent slug), parent equal to the child slug.

Testing Instructions

Child theme check:

  • Run npm run cli:build && node apps/cli/dist/cli/main.mjs code
  • Install Ollie or any other theme from the themes directory.
  • Ask the agent to customize existing theme
  • Expect a scaffold_theme call with parentTheme: 'ollie', all edits under the new child theme directory, and wp-content/themes/ollie/ untouched.
  • Then ask it to edit the Ollie theme files directly — expect a single warning about updates overwriting changes before it complies.
  • Test the new eval: npm run eval -- --filter-pattern "child theme"

Keep working with themes built from scratch:

  • Run npm run cli:build && node apps/cli/dist/cli/main.mjs code
  • Select a site where you built the theme from scratch
  • Ask the agent to modify the theme
  • Confirm it keeps working as usual and it doesn't create a child theme
  • Test the new eval: npm run eval -- --filter-pattern "single-page site"
Child Existing theme
622715576-41bf41c9-521d-4532-bfb0-3cd159e31c57 622715596-c6ef1224-9d65-4a6a-b585-c574956b52f7
Prompt: Create a new site about the odyssey using the Ollie theme image (3) Prompt: Create a new site about Prince of Egypt image (4)

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
…e never edited directly

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sejas sejas self-assigned this Jul 15, 2026
@sejas
sejas marked this pull request as ready for review July 16, 2026 13:40
@wpmobilebot

wpmobilebot commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing 39fe6a5 vs trunk

app-size

Metric trunk 39fe6a5 Diff Change
App Size (Mac) 1353.03 MB 1353.03 MB 0.01 MB ⚪ 0.0%

site-editor

Metric trunk 39fe6a5 Diff Change
load 1110 ms 1029 ms 81 ms 🟢 -7.3%

site-startup

Metric trunk 39fe6a5 Diff Change
siteCreation 6992 ms 7002 ms +10 ms ⚪ 0.0%
siteStartup 2350 ms 2350 ms 0 ms ⚪ 0.0%

Results are median values from multiple test runs.

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

Comment thread apps/cli/ai/tools/scaffold-theme.ts
@youknowriad

Copy link
Copy Markdown
Contributor

Do you think we can write an eval that actually breaks in trunk but passes in this branch?

sejas and others added 2 commits July 16, 2026 16:17
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sejas

sejas commented Jul 16, 2026

Copy link
Copy Markdown
Member Author

Do you think we can write an eval that actually breaks in trunk but passes in this branch?

Yes! I added an eval to test a blank theme and another to test the child theme behaviors:

3e47f82

Comment thread scripts/eval/README.md Outdated
- **single-page-build-turn-cadence** — Agent builds a simple one-page site. Asserts (a) every individual turn stays under 60s (wall-clock between successive assistant messages) and (b) no `wp_cli` call uses `--post_content-file=` (which silently fails inside PHP-WASM).
- **jetpack-catchall-slideshow** — Agent reaches for Jetpack on a slideshow request. Asserts the generated page content uses a `jetpack/*` block (i.e. the catch-all rule fired instead of the agent falling back to raw HTML).
- **differentiate-preview-vs-remote** — Regression for STU-1775. Seeds one connected WordPress.com remote site and one preview site for a local site, then asserts the `site_connected_remote_sites` and `preview_list` tools tag their output with a `type` discriminator (`wpcom-remote` / `preview`) and that the agent's prose keeps the two categories distinct (preview sites are never described as connected WordPress.com remote sites).
- **blank-theme-for-new-site** — Default new-site flow ("create a new site about the history of Wapuu", no theme named). Asserts the agent scaffolds a fresh blank theme — `scaffold_theme` called without `parentTheme` and succeeding.

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 wonder if we can move the assertions of this eval to one of the previous ones to keep the evals a bit more fast/contained.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Great suggestion! I added it to "single-page site build keeps every turn under 60s" 87b15ce

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Comment thread apps/cli/ai/tests/system-prompt.test.ts Outdated
expect( prompt ).toContain( 'Personal or Premium cannot install plugins' );
} );

it( 'guards installed third-party theme edits behind child themes', () => {

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.

That feels like a useless unit test.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed! Removed it. c7dcebb

We still have other similar unit tests that were added in other PRs.

sejas and others added 2 commits July 17, 2026 10:48
@sejas
sejas enabled auto-merge (squash) July 17, 2026 09:53
@sejas
sejas merged commit c57bbe9 into trunk Jul 17, 2026
15 checks passed
@sejas
sejas deleted the stu-2017-support-blank-child-themes branch July 17, 2026 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants