CLI agent: add scaffold_theme tool#3348
Merged
Merged
Conversation
Adds a scaffold_theme tool that drops a minimal block-theme baseline (style.css with WP header + UX fixes, theme.json with appearanceTools, useRootPaddingAwareAlignments and a sane palette/spacing/typography scale, functions.php that enqueues style.css on the frontend and as editor styles, default templates and parts, empty assets/fonts and patterns dirs) and activates the theme by default. When the site is not running or activation fails, the scaffold still succeeds and the result reports the manual activation command. Templates use a plain <main> wrapper with an inner constrained group (or constrained wp:post-content for page/single) so align:"full" sections in user content reliably reach viewport width. System-prompt updates: scaffold_theme appears in the available tools list, the theme-build workflow recommends calling it first, the "never scaffold a whole theme" rule carves out the scaffold call, the duplicated frontend/editor enqueue rules collapse into one general rule, and the style.css skeleton-first guidance now branches to Edit (not Write) when the scaffolded file is already on disk. Tool label and detail also registered in the shared tools.ts registry so the CLI UI shows "Scaffold theme (<name>)". Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Collaborator
📊 Performance Test ResultsComparing a59ced6 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) |
Adds a minimal front-page.html to the scaffold (header part, plain <main>, unconstrained wp:post-content, footer part) so one-page builds have a purpose-built home canvas with no constrained-layout interference. System prompt updates: - Step 3 now points homepage layouts at templates/front-page.html and reserves templates/page.html for interior pages. - The "Page content" cadence rule splits into a Homepage bullet (Edit front-page.html directly, replace the post-content reference with section anchors, fill via Edits) and an Interior-page bullet (existing empty-page + tmp file + wp_cli eval workflow). Skipping the DB-page round trip for the homepage saves several turns per session. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
scaffold_theme tool result now includes: - the absolute theme directory at the top so the agent doesn't need a follow-up site_info call to construct Edit file_paths; - a one-line content description per file (style.css, theme.json, functions.php, every template, both parts) so the agent can plan targeted Edits without Reading first. System prompt: the Homepage workflow rule was buried under "Long files: skeleton first" — a section about file *length*, which doesn't cue the agent on homepage authoring. Move that guidance into step 3 of the build workflow (right after the scaffold_theme call) so the agent sees the front-page.html path before reaching the wp_cli "configure WordPress" step. The Homepage bullet under "Long files" is removed; the interior-page bullet stays put. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
Author
|
This is producing more complete themes and sites. |
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
wp-content/themes/<slug>/directory each session.How AI was used in this PR
Iteratively designed and implemented with Claude/Codex. The final shape is intentionally narrow: provide a block-theme scaffold that removes repetitive setup work without imposing design defaults on the generated site.
Proposed Changes
Adds a
scaffold_themetool to the CLI agent so the agent does not have to regenerate the same block-theme boilerplate at the start of every site-building session.Tool —
apps/cli/ai/tools/scaffold-theme.tsnameOrPath,name, optionalslugderived fromnameif omitted, optionalactivatedefaulting totrue.wp-content/themes/<slug>/:style.css— WordPress theme header only.theme.json— schema, version 3, andsettings.appearanceTools: trueonly.functions.php— versioned frontendstyle.cssenqueue plusadd_editor_style( 'style.css' ).templates/—index.html,single.html,page.html,archive.html,404.html.parts/—header.html,footer.html.assets/fonts/,patterns/— empty directories.wp theme activate <slug>by default. If the site is not running or WP-CLI fails, the scaffold still succeeds and reports the manual activation command.wp-content/themes/<slug>directory.Scaffold theme (<theme name>)via the shared label/detail registry intools/common/ai/tools.ts.System prompt —
apps/cli/ai/system-prompt.tsscaffold_themefirst, then fill the scaffold with normalWrite/Editcadence.style.csscadence rule tells the agent to append tokens and section anchors below the scaffolded theme header instead of overwriting it.Tests —
apps/cli/ai/tests/tools.test.tsReal-fs scaffolding into a temp directory; covers tool registration, full file creation, explicit slug override,
activate: false, default activation when site is running, activation skipped when site is not running, activation skipped on WP-CLI non-zero exit, theme-already-exists guard, missingwp-content/themesguard, invalid slug, and empty name.Testing Instructions
npm installthennpm run cli:build.scaffold_themecall rendered asScaffold theme (<name>)in the CLI UI.style.css,theme.json,functions.php, all five templates, and both parts are present underwp-content/themes/<slug>/../node_modules/.bin/eslint --fix apps/cli/ai/system-prompt.ts apps/cli/ai/tools/scaffold-theme.ts apps/cli/ai/tests/tools.test.tsnpm run typechecknpm test -- apps/cli/ai/tests/tools.test.tsnpm run cli:buildPre-merge Checklist
🤖 Generated with Codex