@calibrate-ds/cli 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +555 -0
  2. package/package.json +5 -5
package/README.md ADDED
@@ -0,0 +1,555 @@
1
+ # Calibrate
2
+
3
+ **Calibrate is a local-first design system compiler for design engineers.** It reads your design tool, builds a normalized model of your design system, and uses it to scaffold typed components, design tokens, MDX documentation, and AI implementation prompts — all from the terminal.
4
+
5
+ No cloud sync. No proprietary lock-in. Your design system lives in git.
6
+
7
+ ---
8
+
9
+ ## What it does
10
+
11
+ ```
12
+ Figma → ptb scan → ptb generate-components → typed React shells
13
+ → ptb generate-tokens → CSS custom properties
14
+ → ptb document component → MDX docs + Storybook stories
15
+ → ptb implement component → AI-written component code
16
+ → ptb status → staleness tracking in CI
17
+ ```
18
+
19
+ When your designer updates a component in Figma, `ptb scan` picks up the change, `ptb diff` shows what changed, and `ptb status` tells you which implementations are now stale. The whole team stays in sync through a committed `ptb.lock` file — no external service required.
20
+
21
+ ---
22
+
23
+ ## Install
24
+
25
+ **Requirements:** Node.js ≥ 20
26
+
27
+ ### If you don't have Node 20+ yet
28
+
29
+ The easiest way is [nvm](https://github.com/nvm-sh/nvm):
30
+
31
+ ```bash
32
+ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
33
+ source ~/.zshrc # or ~/.bashrc if you use bash
34
+ nvm install 22
35
+ ```
36
+
37
+ ### Install the CLI
38
+
39
+ ```bash
40
+ npm install -g @calibrate-ds/cli
41
+ source ~/.zshrc # reload PATH so the ptb command is found
42
+ ptb --version # should print 0.1.1
43
+ ```
44
+
45
+ Or run without installing:
46
+
47
+ ```bash
48
+ npx @calibrate-ds/cli init
49
+ ```
50
+
51
+ > **Already have Node 20+?** Just run `npm install -g @calibrate-ds/cli`. If `ptb` is not found after install, run `source ~/.zshrc` (or open a new terminal tab) to reload your PATH.
52
+
53
+ ---
54
+
55
+ ## Quickstart
56
+
57
+ ### 1. Initialize
58
+
59
+ ```bash
60
+ cd your-project
61
+ ptb init
62
+ ```
63
+
64
+ PTB detects whether your repo is fresh or existing:
65
+ - **Fresh repo** — scaffolds `packages/ui/` with framework-specific `package.json`, `tsconfig.json`, and component/token directories
66
+ - **Existing repo** — writes `ptb.config.json` and `.gitignore` entries only, leaves your code untouched
67
+
68
+ You will be asked to choose:
69
+ - Framework (React, Vue, Svelte, React Native)
70
+ - Solo or team project
71
+ - Figma plan (Organization/Enterprise for direct API, or Pro/Starter for the Calibrate plugin)
72
+ - Documentation tool (Storybook, Docusaurus, or plain MDX)
73
+
74
+ ### 2. Set your Figma token
75
+
76
+ ```bash
77
+ export FIGMA_ACCESS_TOKEN=your_token_here
78
+ ```
79
+
80
+ Generate a token at **Figma → Account Settings → Security → Generate New Token**. PTB never stores the token — `ptb.config.json` only stores the env var name.
81
+
82
+ ### 3. Scan your Figma file
83
+
84
+ ```bash
85
+ ptb scan
86
+ ```
87
+
88
+ Fetches your Figma file, normalizes it into a `DesignSystemModel`, saves it to `.ptb/latest.json`, and exports component context files to `.ptb/context/`.
89
+
90
+ Find your file key in the Figma URL: `figma.com/design/<FILE_KEY>/...`
91
+
92
+ ### 4. Generate components and tokens
93
+
94
+ ```bash
95
+ ptb generate-components # typed React shells in packages/ui/src/components/
96
+ ptb generate-tokens # CSS custom properties in packages/ui/src/tokens/
97
+ ```
98
+
99
+ ### 5. Document components
100
+
101
+ ```bash
102
+ ptb document component . # generates MDX + Storybook stories for all components
103
+ ```
104
+
105
+ ### 6. Implement with AI
106
+
107
+ ```bash
108
+ ptb ai setup # configure Claude or OpenAI once
109
+ ptb implement component Button
110
+ ```
111
+
112
+ ### 7. Track freshness
113
+
114
+ ```bash
115
+ ptb status # shows which components are stale vs implemented
116
+ ptb stamp component Button # mark Button as implemented against the current design
117
+ ```
118
+
119
+ ---
120
+
121
+ ## Figma workflows
122
+
123
+ PTB supports two workflows depending on your Figma plan.
124
+
125
+ ### Direct Fetch (Organization / Enterprise)
126
+
127
+ PTB reads tokens directly from the Figma API. No plugin required.
128
+
129
+ ```bash
130
+ ptb flow direct # step-by-step checklist
131
+ ```
132
+
133
+ ### Plugin Export (Pro / Starter / Free)
134
+
135
+ Use the **Calibrate** Figma plugin to export variables and tokens, then import them into PTB.
136
+
137
+ ```bash
138
+ # 1. In Figma: run Calibrate → Export
139
+ # 2. Place the export file in your project named as imported-tokens.json
140
+ # 3. Place it in the .ptb root folder. (If you don't see .ptb folder while exporting, press Cmd+Shift+. to show hidden files)
141
+ ptb scan
142
+ ptb generate-tokens
143
+ ptb generate-components
144
+ ```
145
+
146
+ ---
147
+
148
+ ## Configuration
149
+
150
+ `ptb init` creates `ptb.config.json` at your project root. All fields:
151
+
152
+ ```json
153
+ {
154
+ "designTool": {
155
+ "provider": "figma",
156
+ "fileKey": "YOUR_FIGMA_FILE_KEY",
157
+ "accessTokenEnv": "FIGMA_ACCESS_TOKEN"
158
+ },
159
+ "project": {
160
+ "rootDir": "."
161
+ },
162
+ "output": {
163
+ "componentsDir": "packages/ui/src/components",
164
+ "tokensDir": "packages/ui/src/tokens",
165
+ "metadataDir": ".ptb"
166
+ },
167
+ "framework": {
168
+ "name": "react",
169
+ "typescript": true,
170
+ "styling": "css-modules"
171
+ },
172
+ "generation": {
173
+ "stories": true,
174
+ "tests": false,
175
+ "types": true,
176
+ "indexFiles": true,
177
+ "cssFiles": true
178
+ },
179
+ "naming": {
180
+ "componentCase": "PascalCase",
181
+ "folderCase": "kebab-case",
182
+ "tokenCase": "camelCase"
183
+ },
184
+ "classification": {
185
+ "treatComponentSetsAsCanonical": true,
186
+ "treatStandaloneComponentsAsCanonical": true,
187
+ "treatNestedInstancesAsReferences": true
188
+ },
189
+ "docs": {
190
+ "tool": "storybook",
191
+ "format": "both"
192
+ },
193
+ "ai": {
194
+ "active": "claude",
195
+ "providers": {
196
+ "claude": {
197
+ "model": "claude-sonnet-4-6",
198
+ "accessTokenEnv": "ANTHROPIC_API_KEY"
199
+ }
200
+ }
201
+ }
202
+ }
203
+ ```
204
+
205
+ **`designTool.accessTokenEnv`** stores the name of the env var, never the token itself. PTB validates that this value is `SCREAMING_SNAKE_CASE` on startup.
206
+
207
+ ---
208
+
209
+ ## AI setup
210
+
211
+ ```bash
212
+ ptb ai setup # interactive: choose provider, set env var name, pick model
213
+ ptb ai list # show all configured providers
214
+ ptb ai use claude # switch active provider
215
+ ptb ai model # change model for active provider
216
+ ```
217
+
218
+ Supported providers: **Claude** (Anthropic), **OpenAI**. Local models via OpenAI-compatible `baseUrl` are also supported.
219
+
220
+ PTB uses fuzzy matching during `ptb ai setup` — if you mistype a provider name (e.g. `opneai`), it suggests the closest known provider before proceeding.
221
+
222
+ ```bash
223
+ # Claude
224
+ export ANTHROPIC_API_KEY=sk-ant-...
225
+ ptb ai setup # choose "claude"
226
+
227
+ # OpenAI
228
+ export OPENAI_API_KEY=sk-...
229
+ ptb ai setup # choose "openai"
230
+ ```
231
+
232
+ ---
233
+
234
+ ## Implementing components with AI
235
+
236
+ `ptb implement component <name>` sends a rich context package to your configured AI provider and writes the component files. **The quality of the output depends entirely on the model you use.**
237
+
238
+ ### Recommended models
239
+
240
+ For best results use a top-tier coding model:
241
+
242
+ | Provider | Recommended model |
243
+ |---|---|
244
+ | Anthropic | `claude-opus-4-7` or `claude-sonnet-4-6` |
245
+ | OpenAI | `gpt-4o` or `o3` |
246
+
247
+ Weaker models (GPT-3.5, smaller Ollama models) will produce code that compiles but misses design intent — wrong spacing, ignored variants, missing accessibility attributes.
248
+
249
+ ```bash
250
+ ptb ai setup # set your provider and model
251
+ ptb ai model # change model at any time
252
+ ```
253
+
254
+ ### Alternative: use any AI IDE with PTB context files
255
+
256
+ `ptb implement` is useful for batch generation. For interactive development, you can skip it entirely and use PTB's context files directly in any AI IDE — Claude Code, Cursor, Copilot, or any other.
257
+
258
+ PTB already extracts and normalizes everything from Figma into structured JSON. Your AI IDE doesn't need a live Figma connection — the context files have everything: variant axes, token bindings, state contracts, layout, render trees, and interaction contracts.
259
+
260
+ **Workflow:**
261
+ 1. Run `ptb export context` after each scan
262
+ 2. Run `ptb document system` to generate `AI.md` at your package root — most AI IDEs pick this up automatically
263
+ 3. Use `ptb prompt component <name>` to get a structured prompt for a specific component
264
+ 4. Open your AI IDE and point it at `.ptb/context/<component>.json` or paste the prompt
265
+ 5. Let the AI write the component — it has full design intent without needing Figma access
266
+
267
+ This gives you more control, lets you iterate interactively, and works with whatever AI IDE you already use.
268
+
269
+ ---
270
+
271
+ ## Team workflow
272
+
273
+ PTB tracks design-to-implementation freshness through a committed `ptb.lock` file. No server required.
274
+
275
+ ### Setup
276
+
277
+ ```bash
278
+ ptb init # scaffolds project, registers you as lead, creates ptb.lock
279
+ ptb join # teammates register themselves (they join as members)
280
+ git add ptb.lock ptb-team.json
281
+ ```
282
+
283
+ ### Roles
284
+
285
+ Every team member has a role: **lead** or **member**.
286
+
287
+ - The person who runs `ptb init` is automatically the **lead**.
288
+ - The first person to run `ptb join` on a fresh roster also becomes a **lead** automatically — this prevents the deadlock where the only member can't promote themselves (only leads can change roles).
289
+ - All subsequent `ptb join` calls give the **member** role.
290
+ - Leads can assign components to anyone, reassign, and stamp any component.
291
+ - Members can only self-assign and stamp components assigned to them.
292
+ - The last lead cannot be demoted — PTB blocks the operation until another lead is promoted first.
293
+
294
+ ```bash
295
+ ptb team # show roster with roles
296
+ ptb team role @alice lead # promote alice to lead (leads only)
297
+ ptb team role @bob member # demote to member (leads only, can't remove last lead)
298
+ ```
299
+
300
+ ### Assigning work
301
+
302
+ ```bash
303
+ ptb assign Button # self-assign Button to yourself
304
+ ptb assign Button @alice # assign to alice (leads only)
305
+ ptb assign . @alice # assign all unimplemented to alice (leads only)
306
+ ptb assign Button --clear # unassign (members can only clear their own)
307
+ ptb status --team # view workload by assignee
308
+ ptb status --mine # view only your assignments
309
+ ```
310
+
311
+ ### Stamping implementations
312
+
313
+ When a developer finishes implementing a component against the current design:
314
+
315
+ ```bash
316
+ ptb stamp component Button
317
+ ptb stamp component Button -m "implemented with new focus ring per design v2"
318
+ ```
319
+
320
+ Members can only stamp components assigned to them. Leads can stamp anything.
321
+
322
+ This writes the current `designHash` into `ptb.lock` as `stampedHash`. When `ptb status` sees they match, the component is **ready**. When Figma changes and PTB re-scans, `designHash` updates but `stampedHash` stays — making the component **stale**.
323
+
324
+ ### Viewing history
325
+
326
+ ```bash
327
+ ptb log # show design changes and stamps from git history
328
+ ptb diff # show unstamped design changes since last scan
329
+ ```
330
+
331
+ ---
332
+
333
+ ## CI integration
334
+
335
+ ```bash
336
+ ptb ci setup # leads only
337
+ ```
338
+
339
+ Generates `.github/workflows/ptb.yml` — a GitHub Actions workflow that runs `ptb status --fail-on-stale` on every push and PR. Blocks merges when components are stale.
340
+
341
+ ```bash
342
+ git add .github/workflows/ptb.yml
343
+ git commit -m "ci: add PTB design freshness check"
344
+ ```
345
+
346
+ For CI to work without a Figma token, commit your context files after each scan:
347
+
348
+ ```bash
349
+ ptb export context
350
+ git add .ptb/context/ ptb.lock
351
+ git commit -m "chore: update design system context"
352
+ ```
353
+
354
+ ---
355
+
356
+ ## Documentation
357
+
358
+ ### Component docs
359
+
360
+ ```bash
361
+ ptb document component Button # single component
362
+ ptb document component . # all components
363
+ ptb document component Button --force # overwrite existing
364
+ ptb document component Button --no-ai # skip AI prose, deterministic tables only
365
+ ```
366
+
367
+ On first run, PTB asks two one-time questions and saves the answers to `ptb.config.json` — they won't be asked again:
368
+ - **Documentation tool**: Storybook, Docusaurus, or plain MDX
369
+ - **Format** (Storybook only): MDX doc only, Stories only, or Both
370
+
371
+ Override the format per-run with `--format mdx|stories|both`.
372
+
373
+ For Storybook, PTB detects whether Storybook is installed (monorepo-aware — correctly handles hoisted `node_modules`) and offers to run the setup steps for you. After `storybook init`, PTB automatically removes Storybook's example `src/stories/` scaffold so it doesn't pollute your component directory.
374
+
375
+ ### System documentation
376
+
377
+ ```bash
378
+ ptb document system
379
+ ```
380
+
381
+ Generates two files at your component library root:
382
+
383
+ - **`AI.md`** — design system intent map for AI coding assistants (Claude Code, Cursor, Copilot)
384
+ - **`components.md`** — human-readable component inventory with import paths and descriptions
385
+
386
+ ---
387
+
388
+ ## Context and prompts
389
+
390
+ ```bash
391
+ ptb export context # export all component context to .ptb/context/
392
+ ptb context component Button # display rich context in terminal
393
+ ptb context component Button --json # machine-readable JSON
394
+ ptb prompt component Button # print AI implementation prompt
395
+ ptb prompt component . --format json # write all prompts to .ptb/prompts/
396
+ ```
397
+
398
+ Context files in `.ptb/context/` are designed to be committed and read by AI tools. They contain the full component model: variant axes, token bindings, state contracts, layout, render tree, and interaction contracts.
399
+
400
+ ---
401
+
402
+ ## Health checks
403
+
404
+ ```bash
405
+ ptb doctor # system check: config, token, snapshot age, component health
406
+ ptb doctor component Button # deep audit: 10-point score for one component
407
+ ptb doctor component . # scorecard table for all components
408
+ ptb doctor tokens # token resolution coverage
409
+ ptb doctor context Button # AI context quality score
410
+ ```
411
+
412
+ The doctor checks whether your Figma components have the data PTB needs to generate high-quality code: Auto Layout, token bindings, variant axes, state contracts, render trees, and descriptions.
413
+
414
+ A low doctor score means your generated code will be less accurate. Fix the issues in Figma, re-scan, and the score improves.
415
+
416
+ ---
417
+
418
+ ## Getting help
419
+
420
+ ```bash
421
+ ptb --help # full command list
422
+ ptb <command> --help # flags and options for one command
423
+ ptb guide # list all topic guides
424
+ ptb guide <topic> # focused reference for a feature area
425
+ ```
426
+
427
+ Available topics: `setup` · `context` · `implement` · `document` · `status` · `team` · `ai` · `doctor` · `ci`
428
+
429
+ ---
430
+
431
+ ## Command reference
432
+
433
+ ### Setup & scanning
434
+
435
+ | Command | What it does |
436
+ |---|---|
437
+ | `ptb init` | Initialize PTB, scaffold fresh repos, write config |
438
+ | `ptb scan` | Fetch Figma file, save snapshot, export context |
439
+ | `ptb generate-components [name]` | Scaffold typed component shells |
440
+ | `ptb generate-tokens` | Scaffold CSS token files |
441
+ | `ptb import-tokens <path>` | Import a Calibrate token export |
442
+
443
+ ### Context & prompts
444
+
445
+ | Command | What it does |
446
+ |---|---|
447
+ | `ptb export context` | Export component context files for AI tools |
448
+ | `ptb context component <name>` | Display rich component context |
449
+ | `ptb prompt component <name>` | Print AI implementation prompt |
450
+
451
+ ### AI implementation
452
+
453
+ | Command | What it does |
454
+ |---|---|
455
+ | `ptb implement component <name>` | AI-generate component implementation |
456
+ | `ptb plan` | Show which files are affected by the latest diff |
457
+ | `ptb apply` | Regenerate only the files affected by design changes |
458
+ | `ptb prune` | Remove stale component folders no longer in Figma |
459
+
460
+ ### Documentation
461
+
462
+ | Command | What it does |
463
+ |---|---|
464
+ | `ptb document component <name>` | Generate MDX docs and Storybook stories |
465
+ | `ptb document system` | Generate AI.md and components.md |
466
+
467
+ ### Status & tracking
468
+
469
+ | Command | What it does |
470
+ |---|---|
471
+ | `ptb status` | Check implementation freshness |
472
+ | `ptb diff` | Show unstamped design changes since last scan |
473
+ | `ptb log` | Show design change and stamp history |
474
+ | `ptb stamp component <name>` | Mark a component as implemented |
475
+ | `ptb assign <name> [person]` | Assign a component to a developer |
476
+
477
+ ### Team
478
+
479
+ | Command | What it does |
480
+ |---|---|
481
+ | `ptb join` | Register yourself in the team roster |
482
+ | `ptb team` | Show team roster and workload |
483
+ | `ptb team role <handle> <role>` | Promote or demote a team member (leads only) |
484
+
485
+ ### AI providers
486
+
487
+ | Command | What it does |
488
+ |---|---|
489
+ | `ptb ai setup` | Configure AI provider |
490
+ | `ptb ai list` | List saved providers and active one |
491
+ | `ptb ai use <provider>` | Switch active provider |
492
+ | `ptb ai model [id]` | Change model for active provider |
493
+
494
+ ### Health & CI
495
+
496
+ | Command | What it does |
497
+ |---|---|
498
+ | `ptb doctor` | System and component health audit |
499
+ | `ptb ci setup` | Generate GitHub Actions freshness workflow (leads only) |
500
+ | `ptb remove` | Remove all PTB config and metadata from this project (leads only) |
501
+
502
+ ### Help & onboarding
503
+
504
+ | Command | What it does |
505
+ |---|---|
506
+ | `ptb guide [topic]` | Focused workflow reference per feature area |
507
+ | `ptb learn` | Interactive onboarding walkthrough |
508
+ | `ptb flow direct` | Checklist for direct Figma API workflow |
509
+ | `ptb flow plugin` | Checklist for Calibrate plugin workflow |
510
+
511
+ ---
512
+
513
+ ## What gets committed to git
514
+
515
+ ```
516
+ ptb.config.json # your PTB configuration
517
+ ptb.lock # design hash tracking — commit this
518
+ ptb-team.json # team roster — commit this
519
+ .ptb/context/ # component context files — commit after ptb export context
520
+ .ptb/manifest.json # generated file tracking — commit this
521
+ .github/workflows/ # CI workflow — commit this
522
+ ```
523
+
524
+ ```
525
+ .ptb/latest.json # gitignored — large Figma snapshot
526
+ .ptb/history/ # gitignored — snapshot history
527
+ *.ptb-meta.json # gitignored — inline metadata
528
+ ```
529
+
530
+ `ptb init` writes the correct `.gitignore` entries automatically. If you have an old project with `.ptb/` blanket-ignored, running `ptb export context` will migrate it.
531
+
532
+ ---
533
+
534
+ ## Supported frameworks
535
+
536
+ | Framework | Scan & Track | Generate Components | Storybook |
537
+ |---|---|---|---|
538
+ | React | ✓ | ✓ | ✓ |
539
+ | Vue 3 | ✓ | coming soon | ✓ (Vite) |
540
+ | Svelte | ✓ | coming soon | ✓ (Vite) |
541
+ | React Native | ✓ | coming soon | — |
542
+
543
+ All frameworks support the full governance workflow (scan, diff, status, stamp, assign, CI) and documentation generation. Code generation is React-first for v1.
544
+
545
+ ---
546
+
547
+ ## Contributing
548
+
549
+ See [PTB.md](./PTB.md) for architecture, type definitions, the generator interface, and internal conventions.
550
+
551
+ ```bash
552
+ pnpm install
553
+ pnpm build
554
+ node apps/cli/dist/index.js --help
555
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@calibrate-ds/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -22,10 +22,10 @@
22
22
  "commander": "^14.0.3",
23
23
  "openai": "^6.34.0",
24
24
  "zod": "^4.3.6",
25
- "@calibrate-ds/core": "0.1.0",
26
- "@calibrate-ds/figma-client": "0.1.0",
27
- "@calibrate-ds/shared-types": "0.1.0",
28
- "@calibrate-ds/generator-react": "0.1.0"
25
+ "@calibrate-ds/figma-client": "0.1.2",
26
+ "@calibrate-ds/core": "0.1.2",
27
+ "@calibrate-ds/shared-types": "0.1.2",
28
+ "@calibrate-ds/generator-react": "0.1.2"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/node": "^22.13.5",