moldui-sync — Apply Visual Edits to Source Code
This skill reads pending visual edit batches from .moldui/ in the current project and translates them into source code edits.
When to Invoke
- User runs
/moldui-sync
- User says "apply my moldui changes" / "sync my visual edits" / "apply canvas edits"
- User has made visual edits in their browser via
moldui and clicked Save
Steps
Check for pending batches
ls -1 .moldui/batch-*.json 2>/dev/null
If no batches found, tell the user: "No pending moldui edits found. Run npx moldui and make some visual changes first."
Read all pending batches in chronological order (sorted by timestamp in filename). Each batch is JSON with:
timestamp: when the batch was created
framework: detected framework (e.g. nextjs, vite, vue, static)
sourceHints: array of { file, confidence, reason } — likely source files
changes: array of change descriptors
prompt: pre-built prompt describing changes
For each batch, apply changes intelligently:
For style changes (type: style):
- Look at
element.classes to find the element in source
- If framework is Tailwind, update class names (e.g.
p-6 → p-8 when padding changes from 24px to 32px)
- If using CSS modules or scoped CSS, edit the stylesheet
- If inline styles, update them
- Use the
changes object: { padding: { from: "24px", to: "32px" } }
For text changes (type: text):
- Search for
oldText in source files (prefer files from sourceHints)
- Replace with
newText
- Preserve surrounding whitespace and quotes
For reorder changes (type: reorder):
- Find the parent container by
fromParent selector or class names
- Move the child element from
fromIndex to toIndex
- If
fromParent !== toParent, move the element to a different container
For swap changes (type: swap):
- The user held Alt while dragging to exchange two elements' positions
- Swap the source positions of
selector and swapSelector
- If in JSX: swap the two JSX elements in their source tree
- If in HTML: swap the two HTML elements
For clone changes (type: clone):
- Duplicate the element in source code at the specified position
Use sourceHints first — these are the most likely source files. Read them first, then grep if needed.
Edit files minimally — preserve existing code style, formatting, indentation.
After applying each batch, delete it:
rm .moldui/batch-{timestamp}.json
Report to the user:
- List files modified
- Summary of changes applied
- Any changes that couldn't be applied (and why)
Tailwind Class Mapping
When the framework uses Tailwind CSS, translate CSS values to Tailwind classes:
| CSS |
Tailwind |
padding: 24px |
p-6 |
padding: 32px |
p-8 |
margin: 16px |
m-4 |
gap: 16px |
gap-4 |
border-radius: 8px |
rounded-lg |
border-radius: 12px |
rounded-xl |
border-radius: 16px |
rounded-2xl |
font-size: 16px |
text-base |
font-size: 18px |
text-lg |
font-size: 24px |
text-2xl |
width: 100% |
w-full |
Base unit = 4px. So {N}px → {N/4} (e.g., 12px → 3).
Framework-Specific Tips
Next.js / React:
- JSX files at
app/*/page.tsx, pages/*/index.tsx, components/*.tsx
- Look for matching class strings or text content
Vue:
- SFC files:
<template>, <script>, <style>
- Edit classes in the template
Svelte:
.svelte files with <script>, HTML, and <style>
Django/Rails/Laravel:
- Template files with class="..." attributes
- For styles, find the corresponding CSS file
Static HTML:
- Edit the HTML directly
- For styles, edit the
<style> block or linked CSS
Example Interaction
User: /moldui-sync
Claude: Found 1 pending batch with 3 changes.
Reading batch-1713300000000.json...
Framework: nextjs + tailwind
Source hints: src/app/page.tsx (route match)
Applied changes:
✓ src/app/page.tsx — padding p-6 → p-8 on .card (3 instances)
✓ src/app/page.tsx — text "Welcome to My App" → "Ship Faster with AI" (h1)
✓ src/app/page.tsx — reordered grid children [0,1,2] → [2,0,1]
Deleted batch file.
Edge Cases
- Multiple matches for a class: Apply to all matches. If the change should be scoped, Claude should note this and ask.
- Source file not obvious: Grep across the project for the class/text. If still unclear, show the user the change and ask which file to edit.
- Text contains special regex chars: Escape them before searching.
- Reorder across different files: If an element is moved to a different parent and that parent lives in a different file, handle the cross-file case by editing both.
- Unknown framework: Fall back to grep-based file matching and editing raw HTML/CSS.
1---2name: moldui-sync3description: Apply pending visual edits from moldui to source code. Triggers: /moldui-sync, apply my moldui changes, sync visual edits, apply canvas edits4---56# moldui-sync — Apply Visual Edits to Source Code78This skill reads pending visual edit batches from `.moldui/` in the current project and translates them into source code edits.910## When to Invoke1112- User runs `/moldui-sync`13- User says "apply my moldui changes" / "sync my visual edits" / "apply canvas edits"14- User has made visual edits in their browser via `moldui` and clicked Save1516## Steps17181. **Check for pending batches**19 ```20 ls -1 .moldui/batch-*.json 2>/dev/null21 ```22 If no batches found, tell the user: "No pending moldui edits found. Run `npx moldui` and make some visual changes first."23242. **Read all pending batches** in chronological order (sorted by timestamp in filename). Each batch is JSON with:25 - `timestamp`: when the batch was created26 - `framework`: detected framework (e.g. nextjs, vite, vue, static)27 - `sourceHints`: array of `{ file, confidence, reason }` — likely source files28 - `changes`: array of change descriptors29 - `prompt`: pre-built prompt describing changes30313. **For each batch, apply changes intelligently:**3233 For **style changes** (type: `style`):34 - Look at `element.classes` to find the element in source35 - If framework is Tailwind, update class names (e.g. `p-6` → `p-8` when padding changes from 24px to 32px)36 - If using CSS modules or scoped CSS, edit the stylesheet37 - If inline styles, update them38 - Use the `changes` object: `{ padding: { from: "24px", to: "32px" } }`3940 For **text changes** (type: `text`):41 - Search for `oldText` in source files (prefer files from `sourceHints`)42 - Replace with `newText`43 - Preserve surrounding whitespace and quotes4445 For **reorder changes** (type: `reorder`):46 - Find the parent container by `fromParent` selector or class names47 - Move the child element from `fromIndex` to `toIndex`48 - If `fromParent !== toParent`, move the element to a different container4950 For **swap changes** (type: `swap`):51 - The user held Alt while dragging to exchange two elements' positions52 - Swap the source positions of `selector` and `swapSelector`53 - If in JSX: swap the two JSX elements in their source tree54 - If in HTML: swap the two HTML elements5556 For **clone changes** (type: `clone`):57 - Duplicate the element in source code at the specified position58594. **Use `sourceHints` first** — these are the most likely source files. Read them first, then grep if needed.60615. **Edit files minimally** — preserve existing code style, formatting, indentation.62636. **After applying each batch, delete it:**64 ```65 rm .moldui/batch-{timestamp}.json66 ```67687. **Report to the user:**69 - List files modified70 - Summary of changes applied71 - Any changes that couldn't be applied (and why)7273## Tailwind Class Mapping7475When the framework uses Tailwind CSS, translate CSS values to Tailwind classes:7677| CSS | Tailwind |78|------------------------|-----------------------|79| `padding: 24px` | `p-6` |80| `padding: 32px` | `p-8` |81| `margin: 16px` | `m-4` |82| `gap: 16px` | `gap-4` |83| `border-radius: 8px` | `rounded-lg` |84| `border-radius: 12px` | `rounded-xl` |85| `border-radius: 16px` | `rounded-2xl` |86| `font-size: 16px` | `text-base` |87| `font-size: 18px` | `text-lg` |88| `font-size: 24px` | `text-2xl` |89| `width: 100%` | `w-full` |9091Base unit = 4px. So `{N}px` → `{N/4}` (e.g., `12px` → `3`).9293## Framework-Specific Tips9495**Next.js / React:**96- JSX files at `app/*/page.tsx`, `pages/*/index.tsx`, `components/*.tsx`97- Look for matching class strings or text content9899**Vue:**100- SFC files: `<template>`, `<script>`, `<style>`101- Edit classes in the template102103**Svelte:**104- `.svelte` files with `<script>`, HTML, and `<style>`105106**Django/Rails/Laravel:**107- Template files with class="..." attributes108- For styles, find the corresponding CSS file109110**Static HTML:**111- Edit the HTML directly112- For styles, edit the `<style>` block or linked CSS113114## Example Interaction115116```117User: /moldui-sync118119Claude: Found 1 pending batch with 3 changes.120121Reading batch-1713300000000.json...122Framework: nextjs + tailwind123Source hints: src/app/page.tsx (route match)124125Applied changes:126✓ src/app/page.tsx — padding p-6 → p-8 on .card (3 instances)127✓ src/app/page.tsx — text "Welcome to My App" → "Ship Faster with AI" (h1)128✓ src/app/page.tsx — reordered grid children [0,1,2] → [2,0,1]129130Deleted batch file.131```132133## Edge Cases134135- **Multiple matches for a class**: Apply to all matches. If the change should be scoped, Claude should note this and ask.136- **Source file not obvious**: Grep across the project for the class/text. If still unclear, show the user the change and ask which file to edit.137- **Text contains special regex chars**: Escape them before searching.138- **Reorder across different files**: If an element is moved to a different parent and that parent lives in a different file, handle the cross-file case by editing both.139- **Unknown framework**: Fall back to grep-based file matching and editing raw HTML/CSS.