Generate a screen from a description using the configured generator (Stitch or Claude Code).
Guardrails (MUST follow)
Before sending any prompt to Stitch:
- Verify prompt is under 5000 characters
- Verify prompt targets ONE screen only (not multiple pages)
- For refinements: verify ONE change only (not compound changes)
- Reject vague requests ("make it better", "improve it") — ask for specifics
- Check quota before generating: read
.guardrc.jsonto see current usage - DESIGN.md is required — step 1 blocks generation if missing
- Flag generic terms ("modern", "clean", "professional") and suggest specific UI/UX vocabulary replacements (e.g., "asymmetric hero layout", "bento grid", "sticky nav with CTA")
Instructions
-
Generator selection (MUST run before generating):
- Read
.guardrc.jsonand check thegeneratorfield. - IF
generatoris already set (value is"stitch"or"claude"):- Use it. Tell the user: "Using [Stitch MCP / Claude Code] as your configured generator."
- Do NOT ask again.
- IF
generatoris NOT set (field missing or.guardrc.jsondoes not exist):-
Present the options to the user:
"Which generator would you like to use for this project?
- Claude Code (recommended) -- Generates HTML locally. Anti-slop rules from
.claude/rules/are enforced during generation. Best for design-system compliance. - Google Stitch -- Generates via Stitch MCP. More creative/varied layouts, but anti-slop rules do NOT apply during generation (the critic catches issues after).
Which do you prefer? (Default: Claude Code)"
- Claude Code (recommended) -- Generates HTML locally. Anti-slop rules from
-
If the user picks Claude Code (or does not express a preference): set
generatorto"claude". -
If the user picks Stitch: set
generatorto"stitch". -
Save the choice to
.guardrc.jsonby updating thegeneratorfield (create file with defaults if it does not exist). -
Tell the user: "Saved generator preference to .guardrc.json. You can change it anytime by editing the file or telling me to switch."
-
- Read
-
Read DESIGN.md (REQUIRED):
- Read DESIGN.md from the project root.
- IF DESIGN.md does NOT exist: STOP. Do NOT create one inline. Do NOT proceed with generation.
- Tell the user: "No DESIGN.md found. A design system is required before generating screens. Run
/dg-designto create one (or/dg-discoverfirst if this is for a real business)." - Do NOT offer to create DESIGN.md within this skill. The user MUST use
/dg-designwhich has context isolation and discover checks.
- Tell the user: "No DESIGN.md found. A design system is required before generating screens. Run
- IF DESIGN.md exists: use it as context for visual consistency. Extract colors, fonts, spacing, and component patterns.
-
Guide the user through building a good prompt using the zoom-out-zoom-in framework:
Zoom out (context ~30%):
- Product name and what it does
- Target user/audience
- Overall aesthetic direction
Zoom in (specifics ~70%):
- Page type (landing page, dashboard, pricing, about, contact, etc.)
- Goal of this screen
- Each section with specific descriptions
- UI patterns: "bento grid", "sticky header", "card layout"
- Specific numbers: "3 pricing tiers", "4 testimonials"
-
Build the prompt following this structure:
A [adjective] [page type] for "[Product Name]," a [product description]. Designed for [target user]. [Visual tone]. Include these sections: 1. [Section with brief description] 2. [Section with brief description] ... -
Generate the screen:
- IF generator is
stitch:- Model selection: Before generating, read
packages/cli/src/research/known-state.jsonto check available models. Use ONLY non-deprecated models:- GEMINI_3_FLASH (350/month quota) — default for fast iteration and standard screens
- GEMINI_3_1_PRO (200/month quota) — use for high-quality hero pages or when the user explicitly requests best quality
- Do NOT use GEMINI_3_PRO or GEMINI_2_5_FLASH — these are deprecated and may produce inferior results or fail
- Call
mcp__stitch__generate_screen_from_textwith the prompt, the selected model, and the Stitch project ID from.guardrc.json.
- Model selection: Before generating, read
- IF generator is
claude: Generate a complete, single-file HTML page directly. Follow these constraints:- Apply ALL rules from
.claude/rules/anti-slop-design.md - Apply ALL rules from
.claude/rules/design-system-adherence.md - Apply ALL rules from
.claude/rules/content-authenticity.md - Follow DESIGN.md for all color, typography, spacing, and component decisions
- Use the zoom-out-zoom-in prompt structure from step 3 as the page specification
- Output a complete HTML file with embedded CSS (no external dependencies except Google Fonts)
- Run the self-check from
.claude/rules/post-generation-evaluation.mdbefore presenting
- Apply ALL rules from
- IF generator is
-
After generation, retrieve the screen code and save the HTML to
screens/[screen-name].html. -
Post-generation quality gate: After saving the HTML, run the
dg-criticagent to check quality:- The critic runs static lint + 5 quick pattern checks (identical cards, gradient text, button hierarchy, palette compliance, content truth).
- If the critic returns FAIL: show the issues, attempt one automatic fix pass using the critic's suggestions as a refinement prompt, then re-lint. If still failing, present both versions to the user with the issues noted.
- If the critic returns WARN: show the warnings but proceed to preview.
- If the critic returns PASS: proceed to preview.
- The anti-slop rules in
.claude/rules/prevent issues in Claude-generated HTML, but Stitch output is NOT influenced by rules — the critic catches what rules cannot.
-
Preview the screen after saving:
- Call
mcp__stitch__get_screen_imagewith the project ID and screen ID to get a base64 PNG. - Display the image inline so the user can see the result immediately.
- Call
-
For refinements, use this structure (one change at a time):
On the [specific section] of [screen name], [specific change]: - [Detail 1] - [Detail 2] -
Multi-screen requests — SEQUENTIAL ONLY: When the user asks to generate multiple screens (e.g., "create a landing page, about page, and pricing page"), generate them ONE AT A TIME. Follow this sequence for each screen:
- Build the prompt for screen N
- Generate screen N (Stitch or Claude)
- Save to
screens/ - Run the critic on screen N
- Fix any issues the critic flags
- Wait for the full cycle to complete before starting screen N+1
NEVER send multiple generation requests in parallel — this causes cascading timeouts on Stitch and wastes quota when screens fail. If Stitch is already timing out on one request, sending more will make it worse.
For subsequent screens, prefix prompts with: "Following the same design language as the homepage..."
-
For variants, offer to call
mcp__stitch__generate_variantsto produce 2-3 alternative designs the user can compare before committing to one direction. -
For inline edits to an existing screen, use
mcp__stitch__edit_screensinstead of regenerating from scratch. -
Next step: Based on the critic verdict, provide context-aware guidance:
- If PASS: "Screen passes quality gate. Preview with
/dg-preview, deep-evaluate with/dg-evaluate, or generate another screen." - If WARN: "Screen has minor issues. Run
/dg-evaluatefor detailed analysis, or refine with/dg-generatetargeting the flagged issues." - If FAIL: "Screen needs work. Use the suggested refinement prompt above, or run
/dg-evaluatefor a full breakdown." - Always show quota status: "Quota: Flash {used}/{limit}, Pro {used}/{limit}"
- If PASS: "Screen passes quality gate. Preview with
Error Handling
Stitch Timeout Recovery
IF a Stitch MCP call (mcp__stitch__generate_screen_from_text) times out, hangs, or returns an error:
- Do NOT silently switch to Claude Code generation. The user chose Stitch and must be informed.
- Auto-check if the screen completed server-side: Stitch often completes generation even when the MCP response times out. Immediately call
mcp__stitch__list_screensto check if the screen was created despite the timeout.- IF the screen IS found: download it via
mcp__stitch__get_screenandget_screen_code, save toscreens/, and tell the user: "Stitch timed out but the screen completed server-side. Downloaded to screens/[name].html." Proceed to the critic step as normal. - IF the screen is NOT found: continue to step 3.
- IF the screen IS found: download it via
- Tell the user exactly what happened: "Stitch MCP timed out while generating [screen name] and the screen was not completed server-side."
- Offer options (do NOT pick one silently):
- "Would you like me to generate this screen locally with Claude Code instead? (Anti-slop rules will be enforced during generation.)"
- "Or run
/dg-synclater to check again if it appears."
- Generate locally with Claude Code ONLY if the user explicitly agrees.
- NEVER:
- Retry the Stitch call (the timeout suggests a server-side issue)
- Send parallel requests to Stitch
- Generate locally without asking
- Pretend the timeout didn't happen
Claude Code Generation Errors
IF generating locally with Claude Code and the output is incomplete or malformed:
- Tell the user what went wrong.
- Offer to retry generation.
- Do NOT switch to Stitch as a fallback.
Reference: See docs/prompting-guide.md for examples and strategies.


