官方 Google Stitch SDK 的 OpenClaw 封装,仅需 STITCH_API_KEY。提供从文本生成 UI 界面、精准编辑、分支变体以及导出 H... 的功能。
AI-powered UI design with Google Stitch — generate, iterate, export.
Required: Node.js 18+ and STITCH_API_KEY env var.
Get a key at: https://stitch.withgoogle.com → Profile → API Keys
Configure the key in your OpenClaw skill env settings or in the shell used to run the CLI.
bash
# Install dependencies (one-time, from skill root)
cd scripts && npm install
Install scope: this installs the Node dependency declared in scripts/package.json ( @google/stitch-sdk) plus its npm transitive dependencies.
Troubleshooting:
STITCH_API_KEY not set → ensure the env var is configured in OpenClaw skill settings or shellECONNRESET / timeouts → Stitch API calls take 1-5 min; the CLI retries automaticallyCorrupt names.json → run node scripts/stitch.mjs rebuild --project <id> to reconstruct from event logSTITCH_API_KEY onlyruns/, state/, latest-screen.jsonThe CLI is at scripts/stitch.mjs. All output is JSON on stdout.
bash
node scripts/stitch.mjs <command> [args] [--flags]
Use when user wants to design something from scratch.
Step 1 — Shape the prompt (see references/prompt-guide.md for keywords)
Transform the user's brief into a richer prompt:
Step 2 — Generate
bash
node scripts/stitch.mjs generate <project-id> "shaped prompt" --device desktop
Typical time: 1–5 minutes. The CLI downloads HTML + PNG automatically.
Step 3 — Preview
Show the hi-res screenshot: run show <alias> → display via MEDIA:<screenshotUrl> (see Image Delivery).
Step 4 — Iterate (edit or variants)
Use when user wants targeted changes to an existing screen.
bash
node scripts/stitch.mjs edit <screen-id> "change the header to blue, add a search bar"
# --project auto-detected from latest-screen.json
Focused edits work better than vague ones. Be specific: colors, layout, components.
Use when user wants to explore directions before committing.
bash
# 3 variants, exploring freely
node scripts/stitch.mjs variants <screen-id> "make it feel more premium" --count 3 --range explore
# More conservative: refine only
node scripts/stitch.mjs variants <screen-id> "tighten the spacing" --count 2 --range refine
# Target specific aspects
node scripts/stitch.mjs variants <screen-id> "new color direction" --aspects color_scheme,text_font
Creative ranges:
refine — small changes, stays close to originalexplore — moderate exploration (default)reimagine — radical redesignAspects (comma-separated): layout, color_scheme, images, text_font, text_content
Use when user wants to see existing designs and decide which to work on.
Step 1 — Get project overview
bash
node scripts/stitch.mjs info <project-id>
This returns all screen IDs + titles.
Step 2 — Export screenshots for each screen
bash
node scripts/stitch.mjs image <screen-id> --project <project-id>
Do this for each screen (or a selection). Each call saves a local thumbnail + result.json with the screenshotUrl.
Step 3 — Send images to user
For each screen: get the screenshotUrl from the image command's result.json, append =w780, and display via MEDIA:<url>.
Include screen ID + title as caption so user can reference them.
Step 4 — User picks a screen
User says "take screen 3" or "the dark one" → match to screen ID.
Step 5 — Continue with edit/variants
Use the picked screen ID for edit or variants workflows.
Download HTML + screenshot from an existing screen.
bash
node scripts/stitch.mjs export <screen-id> --project <project-id>
# or just HTML:
node scripts/stitch.mjs html <screen-id>
# or just screenshot:
node scripts/stitch.mjs image <screen-id>
Related screens of a concept need a shared hub screen as their visual basis. Generate is generative — layout, colors, spacing, and typography are all invented from scratch. Edit takes the source screen as the visual basis and changes only what you describe — navigation, typography, and color palette stay consistent.
generate vs edit — the key difference:
generate = brand-new screen. Everything is up for grabs.edit = visual continuation of the source screen. Only the described delta changes.edit from the hub, not fresh generateCore Rule: For multi-screen concepts, always define a hub screen first, then derive further screens via edit — never fresh generate.
During the concept phase, 3-4 consistent core screens are enough. Full screen coverage only after the concept is approved. Stitch excels at rapid exploration, not exhaustive elaboration.
A systematic loop for deciding when to keep editing in Stitch vs. when to note something for post-export fixing.
Step 1 — Run generate or edit
Step 2 — Analyze the screenshot (vision model)
Check against this list:
Step 3 — Categorize issues
CategoryExamplesStitch-fixableMissing section, wrong layout order, major color error, wrong navigation structurePost-Export FixExact pixel spacing, icon details, typography fine-tuning, persistent content hallucinations (avatars, labels)
Step 4 — Decide
The user decides which external tool to use for post-export fixes — Figma, Framer, code, or any other tool. Do not prescribe a tool.
Before generating anything, create a feature matrix: which features appear on which screen. Only start generating once the coverage is clear. This way every subsequent generate/edit call is a deliberate execution step, not a discovery — no surprises, no forgotten features. Keep this matrix short; a simple table or bullet list per screen is enough. Three focused screens you've thought through are worth more than ten screens you discover issues with during generation.
bash
# List all projects
node scripts/stitch.mjs projects
# Create a new project
node scripts/stitch.mjs create "App Name"
# Show project screens
node scripts/stitch.mjs info <project-id>
latest-screen.json (in skill root) tracks the last generated/edited screen.
edit, variants, html, image, export auto-detect project from latest-screen.json--project <id> when neededScreens get auto-generated IDs like bcde81e368e24edbabd6213d9dc17b3b. Use screen names to give them memorable aliases that persist across sessions.
bash
# Name during generation (recommended — naming in the flow)
node scripts/stitch.mjs generate <project-id> "prompt" --name concept-a
# Name during editing (alias follows the new screen)
node scripts/stitch.mjs edit <screen-id> "changes" --name concept-a --force
# Name an existing screen manually
node scripts/stitch.mjs name concept-a <screen-id> --project <id>
# Add a note
node scripts/stitch.mjs name concept-a <screen-id> --note "Karte als Fenster, Bottom Sheet"
bash
# Show screen details via alias or screen ID (fetches live data from Stitch API)
node scripts/stitch.mjs show concept-a
node scripts/stitch.mjs show bcde81e368e24edbabd6213d9dc17b3b
# Resolve alias to screen ID only
node scripts/stitch.mjs resolve concept-a
# List all named screens in a project
node scripts/stitch.mjs names
# List + verify against Stitch API (checks for deleted screens)
node scripts/stitch.mjs names --verify
bash
# Rename
node scripts/stitch.mjs rename concept-a map-startscreen
# Remove
node scripts/stitch.mjs unname old-concept
a-z, 0-9, hyphens. Case-insensitive.concept-a, home-v2, onboarding-flow, dark-variant-3--force to overwrite an existing aliasstate/projects/<projectId>/names.json (rebuildable snapshot)state/projects/<projectId>/events.jsonl (append-only, immutable)show will report it as broken; names --verify checks all at oncenames.json gets corrupted, run rebuild to reconstruct from the event log (pre-log aliases require a backup or manual re-naming)Every generate/edit/variants operation and every alias change is recorded as an append-only event.
bash
# Show all events for an alias (creates, edits, rebinds)
node scripts/stitch.mjs history concept-b
# Show a specific alias revision (Nth time it was bound to a screen)
node scripts/stitch.mjs history concept-b --rev 2
# Walk the edit/variant lineage DAG backwards from a screen
node scripts/stitch.mjs lineage concept-b
node scripts/stitch.mjs lineage abc123def456
# Rebuild names.json from event log (recovery)
node scripts/stitch.mjs rebuild --project <id>
Event types:
generate / edit / variants — screen operations (with parentScreenId, promptPreview, runDir)alias_set / alias_renamed / alias_removed — alias pointer changesvariantGroupId to group related screensWhen generating or editing screens for the user:
--name when the user has a clear concept name or purpose for the screenshow <alias> first--name <same-alias> --force to keep the alias pointing to the latest versionshow <alias|screenId>, extract screenshotUrl, display via MEDIA:<url> (see Image Delivery section)names at session start to see what screens already existEvery operation saves to runs/<YYYYMMDD-HHmmss>-<operation>-<slug>/:
FileContentscreen.htmlFull HTML/CSS/JS of the screenscreen.pngScreenshot (desktop/mobile)result.jsonMetadata (screenId, projectId, prompt, timestamps)variant-N.html/.pngFor variants commands
The skill uses a 3-layer local state model. The Stitch API is always the source of truth for screen content (HTML, screenshots).
LayerStoragePurposeArtifactsruns/<timestamp>/Immutable per-operation receipts: thumbnail, HTML, result.jsonEvent Logstate/projects/<id>/events.jsonlAppend-only chronological record of all operationsAlias Pointersstate/projects/<id>/names.jsonCurrent named references — rebuildable from event log
Key principles:
runs/ are artifacts (never mutated, never deleted)state/ is the mutable layer (names.json is a snapshot, events.jsonl is append-only)names.json can be rebuilt from events.jsonl via rebuild (complete for all alias changes recorded in the log; pre-log aliases are preserved from existing snapshot if available)screen.png) are low-res; always use screenshotUrl + =w780 for displaystate/ and runs/ are gitignored — they are local working state, not source codereferences/prompt-guide.md before your first generate/edit/variants call in a session. It contains critical prompting principles that determine output quality. For SDK details (methods, types, enums), see references/sdk-api.md.show <alias|screenId> → MEDIA:<screenshotUrl>. See "Image Delivery" section.generate defaults to --device desktop. --model uses SDK default (pro). Explicit: --count 3, --range explore. edit and variants inherit device from the source screen.latest-screen.json first. If it has a recent entry, use that projectId/screenId. Only ask if no state exists or the user explicitly switches context.The local screen.png in runs/ is only a low-res thumbnail (~168×512px). Full-resolution images come from the Stitch API via screenshotUrl.
The show command accepts an alias OR a raw screen ID and returns live API data with a hi-res screenshot URL ( =w780 suffix appended):
bash
# By alias
node scripts/stitch.mjs show concept-a
# By screen ID (no alias needed)
node scripts/stitch.mjs show bcde81e368e24edbabd6213d9dc17b3b
# → { "screenshotUrl": "https://lh3.googleusercontent.com/...=w780", ... }
After every generate/edit/variants:
show <alias> → extract screenshotUrl from JSON → MEDIA:<url>show <screenId> (accepts raw screen IDs too) → same flowscreenshotUrl from runs/<dir>/result.json, append =w780, display via MEDIA:<url>text
MEDIA:https://lh3.googleusercontent.com/...=w780
Google's lh3.googleusercontent.com URLs support size parameters:
=w780 — full mobile design width (default from show)=w1440 — full desktop design width=s2000 — max 2000px on longest sideStitch interprets hand-drawn sketches and wireframes well. The SDK has no image upload — but the workflow is:
info <project-id> → finds the screen by title in list_screensedit or variants on that screen to refine itpro (Gemini 3.1 Pro) and flash (Gemini 3.0 Flash). "Redesign/NanoBanana" from the Web UI = variants --range reimaginelist_screens newest; variants use delta-based recovery by comparing screen lists before and after the call)FlagCommandsValuesDefault--device``generate, edit, variants``desktop, mobile, tablet, agnostic``desktop for generate; inherited from source for edit/ variants``--model``generate, edit, variants``pro, flashSDK default (pro)--count``variants``1– 5``3``--range``variants``refine, explore, reimagine``explore``--aspects``variants``layout, color_scheme, images, text_font, text_contentall--projectallproject IDfrom latest-screen.json``--design-system``generate, edit, variantsdesign system name/slug—
Note on --design-system: Stitch supports native Design Systems ( create_design_system), but the SDK does not yet allow linking them to generate/edit calls. --design-system is a workaround that loads design-systems/<name>.md from this skill folder and appends that content to your prompt. It does not accept arbitrary file paths. Once the SDK supports design_system_id in generate/edit, this flag will become obsolete.