Skip to content

feat(cli): WordPress site generator for Studio Code (theme + companion plugin)#3666

Draft
draganescu wants to merge 2 commits into
trunkfrom
feat/wordpress-site-generator
Draft

feat(cli): WordPress site generator for Studio Code (theme + companion plugin)#3666
draganescu wants to merge 2 commits into
trunkfrom
feat/wordpress-site-generator

Conversation

@draganescu
Copy link
Copy Markdown

Summary

Adds an end-to-end WordPress site generator to the studio ai / studio code agent. From a description, it produces a complete site: a pure-presentation block theme plus a companion plugin (custom post types, REST routes, build-less plain-JS blocks), seeds content into the live database, and fills AI imagery — all driven by the user's existing WordPress.com authentication.

Adapted from the Telex generation pipeline, repackaged natively for this harness (Pi Agent Core tools + SKILL.md skills + the WPCom AI proxy that's already wired in providers.ts).

Draft: opening for early review. See "Build/verify" below — this needs a npm install + cli:build to validate the full typecheck/build in a complete environment.

What it adds

Tools (registered in apps/cli/ai/tools/index.ts):

  • generate_design_previews — N distinct first-fold HTML directions for the user to pick from
  • generate_theme — parallel per-file generation of a pure-presentation theme (theme.json, style.css, templates, parts), activates it, returns a manifest
  • generate_companion_plugin — CPTs / taxonomies / post meta / REST routes / build-less plain-JS blocks (no @wordpress/scripts)
  • seed_content — generates page + CPT content and publishes it into the live DB
  • generate_image — fills AI_IMAGE: placeholders via the WPCom AI proxy

Skills (apps/cli/ai/skills/): the orchestrator site-generator (/site-generator slash command) plus knowledge skills theme-architecture, companion-plugin, layout-patterns, wp-best-practices, data-persistence, and bundled generator prompt fragments.

Generation core (apps/cli/ai/generation/): a non-streaming parallel Anthropic client that reuses the wpcom provider env, transient-error retry/backoff, robust JSON extraction, the manifest schema, AI_IMAGE handling, and WP-CLI helpers.

Design

Two packages, not one bloated theme: the theme is presentation only; behaviour lives in a companion plugin that survives a theme switch. Content is seeded into the live DB, not baked into the theme. Custom blocks are build-less plain JS (matching the harness's existing no-build approach).

Notable correctness fixes (found during live testing)

  • Large content truncation: wp post create/update --post_content=<large> is truncated crossing the daemon IPC bus (25KB → 16 bytes). seed_content now writes content to a host file the WP filesystem reads (wp post create/update <file>), since <site>/wp-content is the live WP FS.
  • Empty CPT collections: entries are generated with their meta fields from the companion plugin's declared post types.
  • AI images: use the authorized OpenAI images route (gpt-image-1 under the studio-assistant feature slug). Telex's Imagen slug returns 403 for Studio accounts. Placeholders are stripped (not left broken) when not logged into WordPress.com.

Tests

apps/cli/ai/tests/wsg-generation.test.ts — 22 unit tests for the pure helpers (manifest parsing, fence/JSON extraction, transient-error classification, path containment, aspect mapping, AI_IMAGE parsing/stripping). ESLint clean.

Build / verify

npm install      # complete deps (typebox, @mariozechner/* — required to typecheck/build)
npm run cli:build
node apps/cli/dist/cli/main.mjs ai   # then: /login (WordPress.com), /site-generator

🤖 Generated with Claude Code

…tion for studio ai

Adds an end-to-end WordPress site generator to the `studio ai`/`studio code`
agent: generation tools plus knowledge/runbook skills that produce a
pure-presentation block theme and a companion plugin (CPTs, REST routes,
build-less plain-JS blocks), seed content into the live DB, and fill AI imagery.

Tools (registered in tools/index.ts): generate_design_previews, generate_theme
(parallel per-file generation), generate_companion_plugin, seed_content,
generate_image. Orchestrated by the `site-generator` skill (/site-generator
slash command) alongside theme-architecture, companion-plugin, layout-patterns,
wp-best-practices, and data-persistence knowledge skills + bundled generator
prompt fragments adapted from Telex.

Generation core (apps/cli/ai/generation/): non-streaming parallel Anthropic
client reusing the wpcom provider env, transient-error retry/backoff, robust
JSON extraction, manifest schema, AI_IMAGE handling, path/WP-CLI helpers.

Key correctness fixes from live testing:
- seed_content writes large post content to a host file the WP filesystem reads
  (wp post create/update <file>) instead of a giant --post_content arg that the
  daemon IPC bus truncates (25KB -> 16 bytes).
- CPT entries generated with their meta fields from the companion plugin's post
  types, so collections actually populate.
- AI images use the authorized OpenAI images route (gpt-image-1 under the
  studio-assistant feature slug); Telex's Imagen slug is 403 for Studio
  accounts. Placeholders are stripped when not logged into WordPress.com.

Adds unit tests (apps/cli/ai/tests/wsg-generation.test.ts, 22 passing).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@draganescu
Copy link
Copy Markdown
Author

This for now is a one size exploration which tries to settle the best shape of porting some of the Telex learnings on site generation into agent friendly skills and tools.

Images don't generate because of the auth system on WPCOM for certain ai proxies which is not tied to user auth. The agent using the orchestrator command is still significantly slower than the Telex PHP orchestrator.

Finally, an area this exploration shed light on is that we need to have a wp build system bundled somehow so we don't npm install for every theme fresh. Right now the draft instructs generation as vanilla JS for blocks to avoid building.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant