stitch-loop
npx machina-cli add skill gabelul/stitch-kit/stitch-loop --openclawStitch 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, (2) Generate a page with Stitch MCP, (3) Integrate into the site, (4) Write the next baton so the loop continues.
Prerequisites
- Stitch MCP Server (see
stitch-setupskill or https://stitch.withgoogle.com/docs/mcp/guide/) DESIGN.md— generate withstitch-design-systemfrom an existing screen (required for consistency)SITE.md— site vision, Stitch project ID, sitemap, roadmap (create if missing)
The baton system
next-prompt.md is the relay baton between iterations. It tells the loop what page to build next.
Baton format
---
page: about
---
**DESIGN SYSTEM (REQUIRED):**
[Paste DESIGN.md Section 6 here verbatim]
**Page request:**
About page with company mission, team section (3 people), and timeline.
Rules:
pagefrontmatter → output filename (about.html)- The body must include the design system block from
DESIGN.mdSection 6 - You must update
next-prompt.mdat the end of every iteration — the loop stops if this is missing
Execution protocol
Step 1 — Read the baton
Parse next-prompt.md:
- Extract
pagefrom YAML frontmatter - Extract the full prompt body (including the design system block)
Step 2 — Consult context files
| File | What to look for |
|---|---|
SITE.md | Stitch project ID (Section 2), sitemap (Section 3), roadmap / next pages (Section 4), creative freedom (Section 5) |
DESIGN.md | Section 6 — copy this into every prompt, not just the current one |
Check: Do not rebuild pages already in SITE.md sitemap. Do not deviate from the visual language in DESIGN.md.
Step 3 — Generate with Stitch
- Run
list_tools→ find Stitch MCP prefix - If
stitch.jsonexists, use storedprojectId— do not create a new project - If no
stitch.json, callcreate_project→ save numeric ID tostitch.json - Call
generate_screen_from_text:projectId: numeric ID (noprojects/prefix)prompt: full baton content including DESIGN SYSTEM blockdeviceType: match what's inSITE.mdorDESIGN.md
- Call
get_screenwith numeric projectId + screenId - Download HTML:
bash scripts/fetch-stitch.sh "[htmlCode.downloadUrl]" "queue/[page].html" - Download screenshot: save to
queue/[page].png
Step 4 — Integrate into site
- Move
queue/[page].html→site/public/[page].html - Fix asset paths (make relative to
site/public/) - Wire navigation: replace
href="#"placeholders with real paths to existing pages - Ensure the header/footer matches other pages in the site
Step 4.5 — Visual verification (if Chrome DevTools MCP available)
If chrome* tools are in list_tools:
- Start local server:
npx serve site/public -p 3000 - Navigate to
http://localhost:3000/[page].html - Take screenshot, compare against
queue/[page].png - Stop server
Step 5 — Update SITE.md
- Add
[x] [page].htmlto the sitemap - Remove consumed ideas from creative freedom section
- Update roadmap if a backlog item was completed
Step 6 — Write the next baton (CRITICAL)
You must update next-prompt.md before completing — the loop stalls if you skip this.
- Pick next page from: sitemap → roadmap → creative freedom → or invent one that fits
- Write
next-prompt.mdwith:- Valid YAML frontmatter (
page: <next-page-name>) **DESIGN SYSTEM (REQUIRED):**block copied verbatim fromDESIGN.mdSection 6- Clear page description
- Valid YAML frontmatter (
File structure
project/
├── next-prompt.md ← Baton (current task; updated each iteration)
├── stitch.json ← Stitch project ID (persist between loops!)
├── DESIGN.md ← From stitch-design-system
├── SITE.md ← Vision, sitemap, roadmap
├── queue/ ← Staging: [page].html, [page].png
└── site/
└── public/ ← Production: index.html, about.html, etc.
SITE.md template
# Site Vision
[One paragraph describing the site's purpose, audience, and overall feeling]
## Stitch Project
- **Project ID (numeric):** [ID from stitch-mcp-create-project]
## Sitemap
- [ ] index.html — Home
- [ ] about.html — About
- [ ] contact.html — Contact
## Roadmap
1. index.html — main landing page
2. about.html — company/team info
3. contact.html — contact form
## Creative freedom
Additional pages or sections not yet planned...
Common pitfalls
- ❌ Forgetting to update
next-prompt.md(loop stops) - ❌ Rebuilding a page already in SITE.md sitemap
- ❌ Omitting
DESIGN.mdSection 6 from the prompt (causes visual drift) - ❌ Using
projects/IDformat instead of numeric ingenerate_screen_from_text - ❌ Leaving
href="#"instead of wiring real page links - ❌ Not persisting
stitch.json(creates new project every iteration)
Troubleshooting
| Issue | Fix |
|---|---|
| Inconsistent visual styles across pages | Keep DESIGN.md updated; always copy Section 6 into baton |
| Loop stalls at next iteration | Check next-prompt.md has valid frontmatter and non-empty body |
| Stitch generation fails | Ensure baton includes DESIGN SYSTEM block and a specific page request |
| Broken navigation | Use relative paths for internal links; check site/public/ structure |
References
scripts/fetch-stitch.sh— Reliable GCS HTML downloaderstitch-design-system— Generate DESIGN.md from an existing screenstitch-ui-prompt-architect— Enhance vague baton text into structured promptsdocs/prd-to-stitch-workflow.md— PRD-driven multi-screen workflow
Source
git clone https://github.com/gabelul/stitch-kit/blob/main/skills/stitch-loop/SKILL.mdView on GitHub Overview
Stitch-loop automates multi-page site creation by iteratively reading the baton from next-prompt.md, generating the next page with Stitch MCP, integrating it into the site, and updating the baton to continue. It relies on a shared DESIGN.md (Section 6) and SITE.md for project IDs and sitemap to maintain a consistent visual language across pages.
How This Skill Works
In each iteration, Stitch-loop reads next-prompt.md to determine the target page, then uses Stitch MCP to generate the page from the baton content (including the required Design System block). The generated HTML is integrated into site/public, asset paths are fixed, and navigation is wired. Finally, next-prompt.md is updated with the next page to continue the loop, ensuring design consistency via DESIGN.md and the site plan in SITE.md.
When to Use It
- When building a multi-page site with a consistent design language driven by a central DESIGN.md.
- When you need automated, page-by-page expansion guided by sitemap or roadmap in SITE.md.
- When you want to enforce visual consistency across pages using Stitch MCP and the design system.
- When the workflow uses a baton (next-prompt.md) to control which page to render next.
- When you have a functioning Stitch MCP server and the required toolchain (stitch*, Bash).
Quick Start
- Step 1: Ensure prerequisites are in place (Stitch MCP server reachable, DESIGN.md Section 6 present, SITE.md with projectId and sitemap).
- Step 2: Create the initial next-prompt.md baton containing the frontmatter page and the DESIGN.md Section 6 block to request the first page.
- Step 3: Run the Stitch loop to generate the page, integrate it into site/public, and update next-prompt.md for the next page.
Best Practices
- Always copy DESIGN.md Section 6 into every baton body verbatim to preserve design fidelity.
- Validate the target page against SITE.md sitemap before generating to avoid duplicates.
- Update next-prompt.md after every iteration to prevent loop stalls.
- Match the deviceType in the prompt to SITE.md or DESIGN.md to ensure responsive output.
- After integration, verify header/footer consistency, navigation links, and asset paths.
Example Use Cases
- Build a 5-page product site (about, features, pricing, team, contact) where the Team section lists 3 people and a company timeline.
- Rebuild a corporate site iteratively, expanding sections while keeping a unified design language via DESIGN.md.
- Launch a marketing microsite by progressively adding pages (hero, services, case studies, about) using the baton-driven loop.
- Migrate an existing blog into a Stitch-driven flow, generating styled post pages that follow the global design system.
- Create an internal dashboard with multi-page views (Overview, Timeline, Team) that maintain consistent visuals and navigation.