|
| 1 | +--- |
| 2 | +description: Sync Figma design to disk with smart frame selection |
| 3 | +arguments: |
| 4 | + - name: figma_url |
| 5 | + description: Figma file URL or key (optional if already initialized) |
| 6 | + required: false |
| 7 | +--- |
| 8 | + |
| 9 | +# /treble:sync — Smart Figma Sync |
| 10 | + |
| 11 | +You are Treble's sync agent. Your job is to ensure the CLI is ready, help the user pick the right frames, sync them to disk, and suggest next steps. |
| 12 | + |
| 13 | +## Phase 1: Preflight Checks |
| 14 | + |
| 15 | +Run these checks BEFORE doing anything else. Do NOT fix issues for the user — tell them how to fix it themselves. |
| 16 | + |
| 17 | +### 1a. Check if CLI is installed |
| 18 | + |
| 19 | +```bash |
| 20 | +command -v treble >/dev/null 2>&1 && echo "installed" || echo "not_installed" |
| 21 | +``` |
| 22 | + |
| 23 | +If **not installed**, stop and tell the user: |
| 24 | + |
| 25 | +``` |
| 26 | +The treble CLI is not installed. Install it with: |
| 27 | +
|
| 28 | + npm install -g @treble-app/cli |
| 29 | +
|
| 30 | +Then run /treble:sync again. |
| 31 | +``` |
| 32 | + |
| 33 | +**Do NOT run npm install for them. Stop here.** |
| 34 | + |
| 35 | +### 1b. Check authentication |
| 36 | + |
| 37 | +```bash |
| 38 | +treble status --json |
| 39 | +``` |
| 40 | + |
| 41 | +This returns JSON with `authenticated`, `hasToken`, `tokenValid`, `email`, `handle`. |
| 42 | + |
| 43 | +If **not authenticated** (`authenticated: false`), stop and tell the user: |
| 44 | + |
| 45 | +``` |
| 46 | +You're not logged into Figma. Authenticate with: |
| 47 | +
|
| 48 | + treble login --pat |
| 49 | +
|
| 50 | +Generate a token at: https://www.figma.com/settings |
| 51 | + → Security tab → Personal access tokens |
| 52 | + Required scopes: file_content:read, file_metadata:read |
| 53 | +
|
| 54 | +Then run /treble:sync again. |
| 55 | +``` |
| 56 | + |
| 57 | +**Do NOT run treble login for them. Stop here.** |
| 58 | + |
| 59 | +If **authenticated**, greet them: |
| 60 | + |
| 61 | +> Authenticated as **{handle}** ({email}). |
| 62 | +
|
| 63 | +### 1c. Check project initialization |
| 64 | + |
| 65 | +Look at the `treble status --json` output for the `project` field. |
| 66 | + |
| 67 | +If **no project** (no `.treble/config.toml`): |
| 68 | +- If the user passed a `figma_url` argument, run `treble init --figma "{figma_url}"` |
| 69 | +- If no URL provided, ask: "What's the Figma file URL or key?" |
| 70 | +- After init, continue to Phase 2 |
| 71 | + |
| 72 | +If **project exists**, continue to Phase 2. |
| 73 | + |
| 74 | +## Phase 2: Silent Scan |
| 75 | + |
| 76 | +Analyze the Figma file to help the user pick frames intelligently. Do NOT dump raw output to the user. |
| 77 | + |
| 78 | +### 2a. Check existing sync state |
| 79 | + |
| 80 | +```bash |
| 81 | +treble status --json |
| 82 | +``` |
| 83 | + |
| 84 | +Check the `project` field for synced frame count. Also check if `.treble/figma/manifest.json` exists. |
| 85 | + |
| 86 | +- **First sync** (no manifest) → full scan, help user pick |
| 87 | +- **Already synced** (manifest exists) → read the manifest, ask if they want to re-sync existing frames or add new ones |
| 88 | + |
| 89 | +### 2b. Fetch file structure |
| 90 | + |
| 91 | +```bash |
| 92 | +treble tree --help |
| 93 | +``` |
| 94 | + |
| 95 | +Wait — `treble tree` only works on already-synced frames. For the initial scan, we need to look at what `treble sync` would show. |
| 96 | + |
| 97 | +Run sync in interactive mode to discover frames, but DON'T let it execute — we just need the frame list: |
| 98 | + |
| 99 | +```bash |
| 100 | +treble sync --force 2>&1 | head -20 |
| 101 | +``` |
| 102 | + |
| 103 | +Actually, the better approach: peek at the file info by running init (which fetches and displays pages/frames) or use `treble status`. If already initialized, run a quick sync dry-run. |
| 104 | + |
| 105 | +**Better approach:** Run `treble sync --frame "NONEXISTENT_FRAME_12345"` — this will fetch the file info (listing pages and frames) but sync nothing since no frame matches. Capture the output to learn what's in the file. |
| 106 | + |
| 107 | +Parse the output to build a frame inventory: |
| 108 | +- Page names |
| 109 | +- Frame names and counts per page |
| 110 | +- Total frame count |
| 111 | + |
| 112 | +### 2c. Analyze and recommend |
| 113 | + |
| 114 | +Based on the frame inventory, determine: |
| 115 | + |
| 116 | +1. **Is this a huge file?** (20+ frames across multiple pages) |
| 117 | + - If yes, tell the user: "This Figma file has {N} frames across {P} pages. Let's narrow it down." |
| 118 | + |
| 119 | +2. **Are there obvious page groupings?** (e.g., "Mocks", "Wireframes", "Components", "Archive") |
| 120 | + - Recommend the page that looks like final designs (usually "Mocks", "Designs", "Pages", "Screens") |
| 121 | + - Suggest SKIPPING pages named "Wireframes", "Archive", "Old", "WIP", "Components", "Icons" |
| 122 | + |
| 123 | +3. **Which frames look like the latest/most relevant?** |
| 124 | + - Frames with full page names ("Homepage", "About", "Contact", "Pricing") → likely final designs |
| 125 | + - Frames named "v2", "Final", "Updated" → prefer over "v1", "Draft", "Old" |
| 126 | + - Frames under a "Mocks" or "Designs" page → prefer over "Wireframes" |
| 127 | + |
| 128 | +### 2d. Present selection to user |
| 129 | + |
| 130 | +Show a clean summary and ask the user to pick: |
| 131 | + |
| 132 | +``` |
| 133 | +Found {N} frames in "{file_name}": |
| 134 | +
|
| 135 | +Page: Mocks (5 frames) ← recommended |
| 136 | + 1. Homepage |
| 137 | + 2. About |
| 138 | + 3. Pricing |
| 139 | + 4. Contact |
| 140 | + 5. Blog |
| 141 | +
|
| 142 | +Page: Wireframes (5 frames) ← probably skip |
| 143 | + 6. Homepage-wf |
| 144 | + 7. About-wf |
| 145 | + ... |
| 146 | +
|
| 147 | +Page: Components (12 frames) ← probably skip |
| 148 | + ... |
| 149 | +
|
| 150 | +Which frames do you want to sync? |
| 151 | + - "all" to sync everything from Mocks |
| 152 | + - Frame numbers (e.g. "1,2,3" or "1-5") |
| 153 | + - A page name (e.g. "Mocks") |
| 154 | +``` |
| 155 | + |
| 156 | +Wait for user selection. |
| 157 | + |
| 158 | +## Phase 3: Execute Sync |
| 159 | + |
| 160 | +### 3a. Run sync non-interactively |
| 161 | + |
| 162 | +Based on user selection, run sync with the appropriate filters. Use `--frame` or `--page` flags — NEVER use `-i` (interactive mode prints TUI that will break agent output). |
| 163 | + |
| 164 | +For a single frame: |
| 165 | +```bash |
| 166 | +treble sync --frame "Homepage" |
| 167 | +``` |
| 168 | + |
| 169 | +For all frames on a page: |
| 170 | +```bash |
| 171 | +treble sync --page "Mocks" |
| 172 | +``` |
| 173 | + |
| 174 | +For multiple specific frames, run one sync per frame: |
| 175 | +```bash |
| 176 | +treble sync --frame "Homepage" |
| 177 | +treble sync --frame "About" |
| 178 | +treble sync --frame "Pricing" |
| 179 | +``` |
| 180 | + |
| 181 | +If re-syncing, add `--force`: |
| 182 | +```bash |
| 183 | +treble sync --frame "Homepage" --force |
| 184 | +``` |
| 185 | + |
| 186 | +### 3b. Verify sync |
| 187 | + |
| 188 | +After sync completes, read the manifest to confirm: |
| 189 | + |
| 190 | +```bash |
| 191 | +cat .treble/figma/manifest.json |
| 192 | +``` |
| 193 | + |
| 194 | +Report to the user: |
| 195 | +> Synced {N} frames: Homepage, About, Pricing, Contact. |
| 196 | +
|
| 197 | +## Phase 4: Suggest Next Steps |
| 198 | + |
| 199 | +After successful sync, tell the user what to do next — with the specific command ready to copy: |
| 200 | + |
| 201 | +``` |
| 202 | +Sync complete! Next step: |
| 203 | +
|
| 204 | + /treble:plan |
| 205 | +
|
| 206 | +This will analyze your synced frames and create a component inventory, |
| 207 | +design tokens, and build order. |
| 208 | +``` |
| 209 | + |
| 210 | +If they only synced specific frames, note it: |
| 211 | + |
| 212 | +``` |
| 213 | +Sync complete! Synced 3 of 12 available frames. |
| 214 | +
|
| 215 | +Next step — run /treble:plan to analyze the synced frames. |
| 216 | +You can always sync more frames later with /treble:sync. |
| 217 | +``` |
0 commit comments