stitch-loop
Stitch Build Loop
Constraint: Only use this skill when the user explicitly mentions "Stitch" and multi-page or iterative site building.
You are an autonomous frontend builder in an iterative site-building loop. Each iteration: (1) Read the baton (next-prompt.md), (2) Generate a page with Stitch MCP, (3) Integrate into the site, (4) Write the next baton so the loop continues.
Prerequisites
Required:
- Stitch MCP Server (see https://stitch.withgoogle.com/docs/mcp/guide/)
- A Stitch project (create with
stitch-mcp-create-projector MCPcreate_projectif needed) DESIGN.md(generate with stitch-design-md from an existing screen if missing)SITE.md(site vision, Stitch Project ID, sitemap, roadmap)
Optional: Chrome DevTools MCP for visual verification of generated pages.
The Baton System
next-prompt.md is the relay baton between iterations:
---
**DESIGN SYSTEM (REQUIRED):**
[Copy from DESIGN.md Section 6]
**Page Structure:**
1. Header with navigation
2. Explanation of tracking methodology
3. Footer with links
Rules:
- The
pagefrontmatter field determines the output filename (e.g.about.html). - Prompt body must include the design system block from
DESIGN.md. - You MUST update
next-prompt.mdbefore completing so the loop continues.
Execution Protocol
Step 1: Read the Baton
Parse next-prompt.md: extract page from frontmatter and the full prompt from the body.
Step 2: Consult Context Files
| File | Purpose |
|---|---|
SITE.md |
Site vision, Stitch Project ID, sitemap (Section 4), roadmap (Section 5), creative freedom (Section 6) |
DESIGN.md |
Visual style; copy Section 6 into each baton prompt |
Checks: Do not recreate pages already in Section 4 (Sitemap). Pick next task from Section 5 (Roadmap) or Section 6 (Creative Freedom) if roadmap is empty.
Step 3: Generate with Stitch
Use Stitch MCP (or skills stitch-mcp-create-project, stitch-mcp-generate-screen-from-text, stitch-mcp-get-screen):
- Discover prefix: Run
list_toolsto find the Stitch MCP prefix. - Get or create project: If
stitch.jsonexists, use itsprojectId; else call[prefix]:create_projectand save ID tostitch.json. - Generate screen: Call
[prefix]:generate_screen_from_textwithprojectId,prompt(full baton content including DESIGN SYSTEM),deviceType(e.g. DESKTOP). - Retrieve assets: Call
[prefix]:get_screen; downloadhtmlCode.downloadUrl→queue/{page}.html,screenshot.downloadUrl→queue/{page}.png.
Step 4: Integrate into Site
- Move
queue/{page}.html→site/public/{page}.html. - Fix asset paths to be relative to the public folder.
- Update navigation: wire placeholder links (
href="#") to the new page; add to global nav if appropriate. - Keep headers/footers consistent across pages.
Step 4.5: Visual Verification (Optional)
If Chrome DevTools MCP is available, verify the generated page:
- Run
list_toolsto see ifchrome*tools are present. - Start a local server (e.g.
npx serve site/public). - Use
[chrome_prefix]:navigateto openhttp://localhost:3000/{page}.html. - Use
[chrome_prefix]:screenshotto capture the rendered page. - Compare with the Stitch screenshot (
queue/{page}.png) for fidelity. - Stop the server when done.
If Chrome DevTools MCP is not installed, skip to Step 5.
Step 5: Update Site Documentation
Update SITE.md: add the new page to Section 4 (Sitemap) with [x]; remove consumed ideas from Section 6; update Section 5 if a backlog item was completed.
Step 6: Prepare the Next Baton (Critical)
You MUST update next-prompt.md before completing.
- Choose next page: Section 5 (Roadmap) → Section 6 (Creative Freedom) → or invent one that fits the vision.
- Write
next-prompt.mdwith valid YAML frontmatter (page: <name>) and full prompt body including DESIGN SYSTEM (REQUIRED) copied from DESIGN.md.
File Structure
project/
├── next-prompt.md # Baton — current task
├── stitch.json # Stitch project ID (persist!)
├── DESIGN.md # From stitch-design-md
├── SITE.md # Vision, sitemap, roadmap
├── queue/ # Staging: {page}.html, {page}.png
└── site/public/ # Production: index.html, {page}.html
Orchestration Options
The loop can be driven by different triggers (local exceeds official by documenting all options):
| Method | How it works |
|---|---|
| CI/CD | GitHub Actions or similar runs on next-prompt.md changes. |
| Human-in-loop | Developer reviews each iteration before continuing. |
| Agent chains | One agent dispatches to another (e.g. Jules API). |
| Manual | Developer runs the agent repeatedly with the same repo. |
The skill is orchestration-agnostic; focus on the baton pattern, not the trigger.
Integration with This Repo
- DESIGN.md: Create with stitch-design-md from an existing Stitch screen; copy Section 6 into every baton prompt.
- Prompt quality: Use stitch-ui-prompt-architect to enhance vague baton text or to merge design spec + request into a Stitch-ready prompt.
- MCP tools: Use stitch-mcp-create-project, stitch-mcp-generate-screen-from-text, stitch-mcp-get-screen (or underlying MCP) for create/generate/get.
Common Pitfalls
- ❌ Forgetting to update
next-prompt.md(loop stops) - ❌ Recreating a page already in the sitemap
- ❌ Omitting the design system block from the prompt
- ❌ Leaving
href="#"instead of wiring real links - ❌ Not persisting
stitch.jsonafter creating a project
Troubleshooting
| Issue | Solution |
|---|---|
| Stitch generation fails | Ensure prompt includes DESIGN SYSTEM block from DESIGN.md |
| Inconsistent styles | Keep DESIGN.md up to date; copy Section 6 correctly |
| Loop stalls | Verify next-prompt.md has valid frontmatter and body |
| Broken navigation | Use correct relative paths for internal links |
Keywords
English: stitch-loop, baton, next-prompt, SITE.md, DESIGN.md, multi-page, iterative.
中文关键词: stitch-loop、接力、next-prompt、多页、迭代建站。