Skip to content

Commit be71004

Browse files
gold-ak47claude
andcommitted
feat: add /treble:sync command and treble status CLI
/treble:sync plugin command: - Preflight: checks CLI installed, checks auth via treble status --json - Silent scan: analyzes Figma file structure, recommends frames - Smart selection: presents frames grouped by page with recommendations - Non-interactive sync: uses --frame/--page flags (never -i for agents) - Suggests /treble:plan as next step after sync treble status CLI command: - Validates token against Figma API - Shows auth state, project state, sync state - --json flag for machine-readable agent consumption Also fixes all pre-existing clippy warnings (div_ceil, identical blocks, saturating_sub, collapsible replace, useless format). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent aa29fc7 commit be71004

9 files changed

Lines changed: 372 additions & 59 deletions

File tree

.claude-plugin/ui/CLAUDE.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The only exception is `treble show`, which calls the Figma images API to render
1717

1818
| Command | What it does |
1919
|---------|-------------|
20+
| `/treble:sync` | Preflight checks + smart frame selection + sync to disk |
2021
| `/treble:plan` | Analyze Figma frames → write analysis.json + build-state.json |
2122
| `/treble:dev` | Build router — detects target stack, hands off to the right build command |
2223
| `/treble:dev-shadcn` | Build loop for React + shadcn/ui targets |
@@ -63,12 +64,12 @@ treble show "55:1234" # Render by node ID
6364
## Workflow
6465

6566
### React + shadcn/ui
66-
1. `treble sync`Pull Figma data to disk
67+
1. `/treble:sync`Preflight checks, smart frame selection, sync to disk
6768
2. `/treble:plan` — Analyze the screenshots + node trees, write analysis.json
6869
3. `/treble:dev``/treble:dev-shadcn` — Implement components in build order, reviewing each one
6970

7071
### WordPress
71-
1. `treble sync`Pull Figma data to disk
72+
1. `/treble:sync`Preflight checks, smart frame selection, sync to disk
7273
2. `/treble:plan` — Analyze (uses shadcn as reference catalog for primitive matching — the dev agent translates)
7374
3. `/treble:dev``/treble:dev-basecoat-wp` — Build pixel-perfect pages with hardcoded content
7475
4. `/treble:cms-wp` — Make pages editable (ACF fields, CPTs, nav menus, content migration)

.claude-plugin/ui/commands/sync.md

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
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+
```

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 17 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -39,75 +39,47 @@ The output is a real project — `npm run dev` works, components match the Figma
3939

4040
## Quick start
4141

42-
### 1. Install the CLI
43-
44-
```bash
45-
npm install -g @treble-app/cli
46-
```
47-
48-
Or run without installing:
49-
50-
```bash
51-
npx @treble-app/cli --help
52-
```
53-
54-
### 2. Install the Claude Code plugin
55-
56-
The CLI syncs your Figma data. The Claude Code plugin does the AI analysis and code generation. You need both.
42+
### 1. Install the Claude Code plugin
5743

5844
In [Claude Code](https://claude.ai/code):
5945

6046
```
61-
/install-plugin treble-app/treble-cli
47+
/install-plugin treble-app/cli
6248
```
6349

64-
### 3. Authenticate with Figma
50+
### 2. Install the CLI
6551

6652
```bash
67-
treble login --pat
53+
npm install -g @treble-app/cli
6854
```
6955

70-
This stores your token in `~/.treble/config.toml` (never in your project directory).
71-
72-
### 4. Initialize a project
56+
### 3. Authenticate with Figma
7357

7458
```bash
75-
mkdir my-site && cd my-site
76-
treble init "https://www.figma.com/design/abc123/My-Design"
59+
treble login --pat
7760
```
7861

79-
This creates `.treble/config.toml` with your Figma file key.
62+
### 4. Go
8063

81-
### 5. Sync your design
82-
83-
```bash
84-
treble sync
8564
```
86-
87-
Interactive mode — pick which frames to sync:
88-
89-
```bash
90-
treble sync -i
65+
/treble:sync # Checks CLI + auth, helps you pick frames, syncs to disk
66+
/treble:plan # Analyzes your design → component inventory + build order
67+
/treble:dev # Picks the right stack, scaffolds, builds every component
68+
/treble:cms # Wires up CMS (Sanity, Prismic, or WordPress)
9169
```
9270

93-
After syncing, your `.treble/figma/` directory contains everything: reference screenshots, full layer trees with visual properties, and section-level snapshots. Zero API calls from this point on.
94-
95-
### 6. Plan and build (in Claude Code)
96-
97-
```
98-
/treble:plan # Analyze → writes analysis.json + build-state.json
99-
/treble:dev # Classify → pick stack → scaffold → build all components
100-
/treble:cms # Wire up CMS (Sanity, Prismic, or WordPress)
101-
```
71+
That's it. `/treble:sync` handles initialization, frame selection, and preflight checks — it will tell you if anything is missing.
10272

10373
## CLI reference
10474

10575
```bash
10676
treble login --pat # Store Figma personal access token
10777
treble login # OAuth via treble.build (if available)
108-
treble init "FIGMA_URL_OR_KEY" # Initialize .treble/ in current directory
78+
treble status # Check auth + project state
79+
treble status --json # Machine-readable (for agents)
80+
treble init --figma "FIGMA_URL_OR_KEY" # Initialize .treble/ in current directory
10981
treble sync # Pull all Figma frames to disk
110-
treble sync -i # Interactive frame picker
82+
treble sync -i # Interactive frame picker (TUI)
11183
treble sync --frame "Contact" # Sync one frame by name
11284
treble sync --page "Homepage" # Sync all frames from one page
11385
treble sync --force # Re-sync even if already cached
@@ -127,6 +99,7 @@ These run inside Claude Code with the treble plugin installed:
12799

128100
| Command | What it does |
129101
|---------|-------------|
102+
| `/treble:sync` | Preflight checks, smart frame selection, sync Figma to disk |
130103
| `/treble:plan` | Analyze synced Figma data → component inventory, design tokens, build order |
131104
| `/treble:dev` | Classify design → pick stack → scaffold → build loop with visual review |
132105
| `/treble:cms` | Wire up CMS editability (Sanity, Prismic, or WordPress) |

src/commands/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ pub mod extract;
22
pub mod init;
33
pub mod login;
44
pub mod show;
5+
pub mod status;
56
pub mod sync;
67
pub mod tree;

0 commit comments

Comments
 (0)