@noemuch/bridge-ds 2.3.0 → 2.5.0

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 (31) hide show
  1. package/.claude-plugin/plugin.json +31 -0
  2. package/.cursor-plugin/plugin.json +26 -0
  3. package/.mcp.json +12 -0
  4. package/CHANGELOG.md +66 -0
  5. package/CLAUDE.md +84 -0
  6. package/README.md +7 -3
  7. package/lib/cli.js +107 -134
  8. package/lib/mcp-setup.js +32 -28
  9. package/lib/scaffold.js +6 -3
  10. package/package.json +10 -3
  11. package/skills/design-workflow/SKILL.md +70 -17
  12. package/skills/design-workflow/references/actions/design.md +63 -12
  13. package/skills/design-workflow/references/actions/done.md +21 -3
  14. package/skills/design-workflow/references/actions/learn.md +147 -0
  15. package/skills/design-workflow/references/actions/quick.md +78 -0
  16. package/skills/design-workflow/references/actions/review.md +14 -3
  17. package/skills/design-workflow/references/actions/spec.md +24 -0
  18. package/skills/design-workflow/references/actions/sync.md +176 -0
  19. package/skills/design-workflow/references/figma-api-rules.md +63 -0
  20. package/skills/design-workflow/references/knowledge-base/README.md +18 -1
  21. package/skills/design-workflow/references/knowledge-base/schemas/assets.md +6 -0
  22. package/skills/design-workflow/references/knowledge-base/schemas/components.md +6 -0
  23. package/skills/design-workflow/references/knowledge-base/schemas/learnings.md +250 -0
  24. package/skills/design-workflow/references/knowledge-base/schemas/text-styles.md +6 -0
  25. package/skills/design-workflow/references/knowledge-base/schemas/validation.md +6 -0
  26. package/skills/design-workflow/references/knowledge-base/schemas/variables.md +6 -0
  27. package/skills/design-workflow/references/onboarding.md +51 -9
  28. package/skills/design-workflow/references/quality-gates.md +51 -2
  29. package/skills/design-workflow/references/templates/screen-template.md +12 -0
  30. package/skills/design-workflow/references/templates/spec-template.md +12 -0
  31. package/skills/design-workflow/references/transport-adapter.md +210 -0
@@ -34,13 +34,31 @@ STEP 6 Done (archive + retro)
34
34
 
35
35
  **Trigger**: any design-related request (spec, design, new component, new screen, setup, etc.)
36
36
 
37
- ### 0a. Check figma-console-mcp
37
+ ### 0a. Check Figma MCP Transport
38
38
 
39
- | Check | How to verify | Block message if fail |
40
- |-------|--------------|----------------------|
41
- | figma-console-mcp available | Call `figma_get_status()` should return connection info | "figma-console-mcp is not configured. Run: `claude mcp add figma-console -s user -e FIGMA_ACCESS_TOKEN=figd_YOUR_TOKEN -- npx -y figma-console-mcp@latest`" |
42
- | Connected to Figma | `figma_get_status()` returns `setup.valid: true` | "Figma Desktop is not connected. Open your Figma file → Plugins → Development → Run the Desktop Bridge plugin." |
43
- | DS libraries enabled | Ask user to confirm | "Make sure your DS libraries are enabled in the target Figma file (Assets panel → Team → Enable). Confirm when done." |
39
+ Detect which transport is available (see `references/transport-adapter.md` Section A):
40
+
41
+ 1. **Check console transport:** Is `figma_execute` available? Try `figma_get_status()`.
42
+ 2. **Check official transport:** Is `use_figma` available? Try `whoami()`.
43
+
44
+ | Result | Action |
45
+ |--------|--------|
46
+ | Console available | Use console transport. Verify: `figma_get_status()` returns `setup.valid: true` |
47
+ | Official only | Use official transport. Verify: `whoami()` succeeds, then test `use_figma` call |
48
+ | Both available | Use console (preferred — more capable, no response limits) |
49
+ | Neither available | **Block.** Show setup instructions for both options (see transport-adapter.md Section A) |
50
+
51
+ **Post-detection checks:**
52
+
53
+ | Check | Console | Official | Block message if fail |
54
+ |-------|---------|----------|-----------------------|
55
+ | Transport connected | `figma_get_status()` → `setup.valid: true` | `whoami()` succeeds + test `use_figma` call | Console: "Figma Desktop is not connected. Open: Plugins → Development → Desktop Bridge." / Official: "Figma MCP not authenticated. Check your Figma MCP configuration." |
56
+ | DS libraries enabled | Ask user to confirm | Ask user to confirm | "Make sure your DS libraries are enabled in the target Figma file (Assets panel → Team → Enable). Confirm when done." |
57
+
58
+ Report the active transport:
59
+ ```
60
+ Transport: {console | official} ✓
61
+ ```
44
62
 
45
63
  **Note:** Setup check can be deferred to just before STEP 4 (design) if the user only wants to write a spec first. But it MUST pass before any Figma generation.
46
64
 
@@ -56,17 +74,41 @@ What do you want to design? (component or screen)
56
74
 
57
75
  **If knowledge base is empty → build it:**
58
76
 
77
+ #### Knowledge Base Directory Selection
78
+
79
+ Determine where to create the knowledge base:
80
+ - If `./.claude/skills/design-workflow/references/knowledge-base/` already exists (npm scaffold mode) → use that path
81
+ - Otherwise (plugin mode or fresh project) → create and use `./bridge-ds/knowledge-base/`
82
+
83
+ Create these subdirectories in the chosen KB root:
84
+ - `registries/`
85
+ - `guides/tokens/`
86
+ - `guides/components/`
87
+ - `guides/patterns/`
88
+ - `guides/assets/`
89
+ - `ui-references/screenshots/`
90
+
59
91
  #### KB Generation Flow
60
92
 
61
93
  1. **Ask the user for the DS library file key/URL** (the Figma file containing their design system)
62
94
 
63
95
  2. **Extract raw data via MCP tools:**
96
+
97
+ **Console transport:**
64
98
  ```
65
99
  figma_get_design_system_kit({ file_key: "...", format: "full" })
66
100
  figma_get_variables({ file_key: "..." })
67
101
  figma_get_styles({ file_key: "..." })
68
102
  ```
69
103
 
104
+ **Official transport** (no `figma_get_design_system_kit`): Use the composite strategy from `references/transport-adapter.md` Section D:
105
+ ```
106
+ get_variable_defs({ fileKey: "..." })
107
+ search_design_system({ query: "*", includeComponents: true })
108
+ search_design_system({ query: "*", includeStyles: true })
109
+ ```
110
+ Supplement with `use_figma` extraction scripts from the schemas as needed.
111
+
70
112
  3. **Write registries** (raw JSON, deterministic):
71
113
 
72
114
  **CRITICAL: Read the schema for each registry BEFORE writing it:**
@@ -278,7 +320,7 @@ Now we can design the screen with real DS components.
278
320
  **Prerequisites (ALL must pass):**
279
321
  - [ ] Spec validated (STEP 2 passed)
280
322
  - [ ] New components created if needed (STEP 3 passed)
281
- - [ ] figma-console-mcp connected (STEP 0 check)
323
+ - [ ] Figma MCP transport connected (STEP 0 check)
282
324
  - [ ] DS libraries enabled
283
325
 
284
326
  **If any prerequisite fails → block with specific message from Block Messages Reference.**
@@ -344,8 +386,8 @@ Ready for the next design!
344
386
 
345
387
  | Situation | Message |
346
388
  |-----------|---------|
347
- | No MCP server | "figma-console-mcp is not configured. Run: `claude mcp add figma-console -s user -e FIGMA_ACCESS_TOKEN=figd_YOUR_TOKEN -- npx -y figma-console-mcp@latest`" |
348
- | Not connected | "Figma Desktop is not connected. Open: Plugins → Development → Desktop Bridge." |
389
+ | No MCP transport | "No Figma MCP transport detected. See `references/transport-adapter.md` Section A for setup instructions (console or official)." |
390
+ | Not connected | Console: "Figma Desktop is not connected. Open: Plugins → Development → Desktop Bridge." / Official: "Figma MCP not authenticated. Check your configuration." |
349
391
  | Libraries not enabled | "Enable your DS libraries in the target Figma file: Assets → Team → Enable." |
350
392
  | No knowledge base | "Knowledge base not built yet. Run: `setup`" |
351
393
  | No active spec | "No active spec. Let's create one: component or screen?" |
@@ -6,8 +6,8 @@
6
6
 
7
7
  | Gate | Blocking | Check |
8
8
  |------|----------|-------|
9
- | figma-console-mcp available | Yes (before design) | `figma_get_status()` returns valid connection |
10
- | Connected to Figma Desktop | Yes (before design) | Status has `setup.valid: true` |
9
+ | Figma MCP transport available | Yes (before design) | Console: `figma_get_status()` returns valid connection / Official: `whoami()` succeeds (see transport-adapter.md Section F) |
10
+ | Connected to Figma | Yes (before design) | Console: `setup.valid: true` / Official: `whoami()` + test `use_figma` call |
11
11
  | DS libraries enabled | Yes (before design) | User confirmation |
12
12
  | Knowledge base exists | Yes (before spec) | `registries/` has JSON files |
13
13
  | Registry schemas followed | Yes | All registry files match schemas in `schemas/` — every entry has `key` field |
@@ -121,6 +121,33 @@
121
121
 
122
122
  ---
123
123
 
124
+ ## Phase: learn (after design corrections)
125
+
126
+ | Gate | Blocking | Check |
127
+ |------|----------|-------|
128
+ | Active spec exists | Yes | `specs/active/{name}-spec.md` present |
129
+ | Snapshot exists | Yes | `specs/active/{name}-snapshot.json` present |
130
+ | Figma MCP transport available | Yes | Console: `figma_get_status()` / Official: `whoami()` (see transport-adapter.md) |
131
+ | Root node still exists | Yes | Plugin API execution can find the node from snapshot meta |
132
+ | Changes classified | Yes | Every change classified as LEARNING or FLAG |
133
+ | Learnings have valid tokens | Yes | Every LEARNING references a token from `registries/variables.json` |
134
+ | Flags surfaced to user | Yes | All FLAG items reported before saving |
135
+
136
+ ---
137
+
138
+ ## Phase: sync (DS incremental update)
139
+
140
+ | Gate | Blocking | Check |
141
+ |------|----------|-------|
142
+ | Knowledge base exists | Yes | `registries/` has JSON files |
143
+ | Figma MCP transport available | Yes | Console: `figma_get_status()` / Official: `whoami()` (see transport-adapter.md) |
144
+ | Diff computed before apply | Yes | Report shown to user before any registry modification |
145
+ | Breaking changes confirmed | Yes (if removals) | User explicitly approves deletion of removed items |
146
+ | Registry validation after update | Yes | Sample import test passes (3-5 keys per registry) |
147
+ | Guides patched for removals | Yes (if removals) | No guide references deleted components/tokens |
148
+
149
+ ---
150
+
124
151
  ## Skip Policy
125
152
 
126
153
  - **Non-skippable (NEVER):** spec creation, spec validation, new components check, pattern matching, visual fidelity review, DS component reuse audit (Rule 18), pre-script element audit, registry loading
@@ -129,3 +156,25 @@
129
156
  1. Warn user about quality impact
130
157
  2. Log the skip reason
131
158
  3. Flag in review as advisory issue
159
+
160
+ ---
161
+
162
+ ## Phase: Quick Mode
163
+
164
+ Quick mode relaxes some gates while keeping critical ones:
165
+
166
+ ### Relaxed (non-blocking in quick mode)
167
+ - Pattern matching: best-effort, not blocking
168
+ - Spec creation and validation: skipped entirely
169
+ - New components check: skipped (use what exists in registries)
170
+ - Formal review: skipped (user can run separately)
171
+ - Acceptance criteria: none (no spec)
172
+
173
+ ### Still enforced (BLOCKING even in quick mode)
174
+ - Pre-script element audit (Rule 18) — every element must be in registries
175
+ - Zero hardcoded hex colors — all colors via setBoundVariableForPaint
176
+ - Atomic generation — 4-6 scripts with screenshots between
177
+ - DS component reuse — NEVER recreate existing components as raw frames
178
+ - Registry loading — must load and cross-reference before generating
179
+ - Canvas positioning — 80px+ gaps, no stacking at (0,0)
180
+ - Script structure — follow figma-api-rules.md (Rule 17 / Rule 23)
@@ -128,6 +128,18 @@
128
128
 
129
129
  ---
130
130
 
131
+ ## Known Preferences
132
+
133
+ > Learnings from previous designs that apply to this screen.
134
+ > Populated automatically from `knowledge-base/learnings.json` during spec writing.
135
+ > If none apply, write "None — no applicable learnings."
136
+
137
+ | Rule | Scope | Signals |
138
+ |------|-------|---------|
139
+ | `{rule}` | {global / contextual} | {n} |
140
+
141
+ ---
142
+
131
143
  ## Responsive Rules
132
144
 
133
145
  | Breakpoint | Layout change |
@@ -124,6 +124,18 @@ interface {Composed}Props {
124
124
 
125
125
  ---
126
126
 
127
+ ## Known Preferences
128
+
129
+ > Learnings from previous designs that apply to this component.
130
+ > Populated automatically from `knowledge-base/learnings.json` during spec writing.
131
+ > If none apply, write "None — no applicable learnings."
132
+
133
+ | Rule | Scope | Signals |
134
+ |------|-------|---------|
135
+ | `{rule}` | {global / contextual} | {n} |
136
+
137
+ ---
138
+
127
139
  ## Component Properties (Figma)
128
140
 
129
141
  > Define ALL configurable properties for the Figma component.
@@ -0,0 +1,210 @@
1
+ # Transport Adapter — Dual MCP Transport Support
2
+
3
+ > **Single source of truth for transport detection, tool mapping, and script adaptation.**
4
+ > All other reference files point here instead of duplicating transport logic.
5
+
6
+ ---
7
+
8
+ ## A. Transport Detection
9
+
10
+ Before any Figma operation, determine which transport is active:
11
+
12
+ 1. **Check for console transport:** Is `figma_execute` available?
13
+ 2. **Check for official transport:** Is `use_figma` available?
14
+
15
+ | Result | Transport | Action |
16
+ |--------|-----------|--------|
17
+ | `figma_execute` available | **Console** (preferred) | Use console tool names throughout |
18
+ | `use_figma` available (no console) | **Official** | Use official tool names, apply adaptation rules below |
19
+ | Both available | **Console** (preferred) | Console is more capable, no response limits |
20
+ | Neither available | **Blocked** | Show setup instructions for both options (see below) |
21
+
22
+ **Block message when neither is available:**
23
+ ```
24
+ No Figma MCP transport detected. Configure one of these:
25
+
26
+ Option A — figma-console-mcp (recommended, full Plugin API access):
27
+ claude mcp add figma-console -s user -e FIGMA_ACCESS_TOKEN=figd_YOUR_TOKEN -- npx -y figma-console-mcp@latest
28
+
29
+ Option B — Official Figma MCP (cloud-based, cross-library search):
30
+ Configure via Claude settings or Figma's MCP integration.
31
+ ```
32
+
33
+ ---
34
+
35
+ ## B. Tool Mapping Table
36
+
37
+ | Bridge Operation | Console (preferred) | Official Figma MCP | Notes |
38
+ |---|---|---|---|
39
+ | Execute Plugin API code | `figma_execute` | `use_figma` | Different wrapper format (see Section C) |
40
+ | Take screenshot | `figma_take_screenshot` | `get_screenshot` | Official requires `nodeId` + `fileKey` |
41
+ | Full DS extraction | `figma_get_design_system_kit` | Composite strategy (see Section D) | |
42
+ | Get variables | `figma_get_variables` | `get_variable_defs` | |
43
+ | Get styles | `figma_get_styles` | `search_design_system` (includeStyles) | |
44
+ | Connection check | `figma_get_status` | `whoami` + test `use_figma` call | See Section F |
45
+ | Search components | `figma_search_components` | `search_design_system` (includeComponents) | Official searches cross-library |
46
+ | Get component | `figma_get_component` | `get_design_context` or `get_metadata` | |
47
+
48
+ ---
49
+
50
+ ## C. Script Adaptation Rules
51
+
52
+ ### Console transport (figma_execute)
53
+
54
+ IIFE wrapper is **mandatory**. The `return` before the IIFE is required.
55
+
56
+ ```javascript
57
+ // Console: figma_execute({ code: "..." })
58
+ return (async function() {
59
+ await figma.loadFontAsync({ family: "Inter", style: "Regular" });
60
+ // ... Plugin API code ...
61
+ return { success: true };
62
+ })();
63
+ ```
64
+
65
+ ### Official transport (use_figma)
66
+
67
+ Top-level `await` — **no IIFE wrapper**. Requires `fileKey` and `description` parameters.
68
+
69
+ ```javascript
70
+ // Official: use_figma({ fileKey: "...", description: "...", code: "..." })
71
+ await figma.loadFontAsync({ family: "Inter", style: "Regular" });
72
+ // ... Plugin API code ...
73
+ return { success: true };
74
+ ```
75
+
76
+ ### Key differences
77
+
78
+ | Aspect | Console | Official |
79
+ |--------|---------|----------|
80
+ | Wrapper | `return (async function() { ... })();` | Top-level `await`, no IIFE |
81
+ | Parameters | `{ code }` | `{ fileKey, description, code }` |
82
+ | `figma.notify()` | Allowed | **Forbidden** (no UI access) |
83
+ | `getPluginData()` | Allowed | **Forbidden** (use `getSharedPluginData()`) |
84
+ | Response size | Unlimited | **20KB limit** — chunk large extractions |
85
+ | Document access | Current file via plugin | Specified file via `fileKey` |
86
+
87
+ ### Transformation example
88
+
89
+ **Same script in both formats:**
90
+
91
+ Console:
92
+ ```javascript
93
+ return (async function() {
94
+ await figma.loadFontAsync({ family: "Inter", style: "Regular" });
95
+ var frame = figma.createFrame();
96
+ frame.name = "Test";
97
+ frame.resize(400, 300);
98
+ figma.currentPage.appendChild(frame);
99
+ return { id: frame.id, name: frame.name };
100
+ })();
101
+ ```
102
+
103
+ Official:
104
+ ```javascript
105
+ await figma.loadFontAsync({ family: "Inter", style: "Regular" });
106
+ var frame = figma.createFrame();
107
+ frame.name = "Test";
108
+ frame.resize(400, 300);
109
+ figma.currentPage.appendChild(frame);
110
+ return { id: frame.id, name: frame.name };
111
+ ```
112
+
113
+ Called as: `use_figma({ fileKey: "YOUR_FILE_KEY", description: "Create a test frame", code: "..." })`
114
+
115
+ ---
116
+
117
+ ## D. DS Extraction Composite Strategy
118
+
119
+ When `figma_get_design_system_kit` is unavailable (official transport), extract DS data using multiple tools:
120
+
121
+ ### 1. Variables
122
+
123
+ ```
124
+ get_variable_defs({ fileKey }) → collection/variable structure
125
+ ```
126
+
127
+ If `get_variable_defs` does not return keys suitable for `importVariableByKeyAsync`, supplement with a `use_figma` extraction script (same script as in `schemas/variables.md`, without the IIFE wrapper).
128
+
129
+ ### 2. Components
130
+
131
+ ```
132
+ search_design_system({ query: "*", includeComponents: true }) → component list
133
+ ```
134
+
135
+ Run broad queries per category (e.g., "Button", "Input", "Card") to cover the DS. For detailed component properties, use `use_figma` with the extraction script from `schemas/components.md` (without IIFE wrapper).
136
+
137
+ ### 3. Styles
138
+
139
+ ```
140
+ search_design_system({ query: "*", includeStyles: true }) → text/color/effect styles
141
+ ```
142
+
143
+ If keys are not returned, supplement with a `use_figma` extraction script (from `schemas/text-styles.md`, without IIFE wrapper).
144
+
145
+ ### 4. Assembly
146
+
147
+ Assemble extracted data into the same registry JSON format defined in the schemas. The output registries must be identical regardless of which transport was used for extraction.
148
+
149
+ ---
150
+
151
+ ## E. Screenshot Adaptation
152
+
153
+ ### Console
154
+
155
+ ```
156
+ figma_take_screenshot({ node_id: "123:456" })
157
+ ```
158
+
159
+ `node_id` is optional — omitting it captures the current viewport.
160
+
161
+ ### Official
162
+
163
+ ```
164
+ get_screenshot({ nodeId: "123:456", fileKey: "abc123" })
165
+ ```
166
+
167
+ Both `nodeId` and `fileKey` are **required**. Track these values throughout the workflow:
168
+ - `fileKey`: obtained when the user provides the Figma file URL
169
+ - `nodeId`: returned by script execution (root frame ID from generation steps)
170
+
171
+ ---
172
+
173
+ ## F. Connection Check Adaptation
174
+
175
+ ### Console
176
+
177
+ ```
178
+ figma_get_status() → { setup: { valid: true }, ... }
179
+ ```
180
+
181
+ Success: `setup.valid === true` means Figma Desktop is connected.
182
+
183
+ ### Official
184
+
185
+ ```
186
+ whoami() → { name: "...", email: "..." }
187
+ ```
188
+
189
+ Success means the user is authenticated. Then test actual file access:
190
+ ```
191
+ use_figma({ fileKey: "...", description: "Connection test", code: "return { page: figma.currentPage.name };" })
192
+ ```
193
+
194
+ If both succeed, the official transport is operational.
195
+
196
+ ---
197
+
198
+ ## G. Official Transport Bonus Capabilities
199
+
200
+ These tools are only available on the official transport and provide additional functionality:
201
+
202
+ | Tool | Capability |
203
+ |------|------------|
204
+ | `search_design_system` | **Cross-library search** — finds components/styles across all team libraries, not just the current file |
205
+ | `get_code_connect_map` | Retrieve Code Connect mappings between Figma components and code |
206
+ | `add_code_connect_map` | Create Code Connect mappings |
207
+ | `create_design_system_rules` | Export design system rules |
208
+ | `generate_figma_design` | Capture a web page into Figma (web-to-Figma) |
209
+ | `get_design_context` | Rich component context with code hints |
210
+ | `get_metadata` | File-level metadata and structure |