@muloka/figma-console-mcp 0.5.4 → 0.5.6

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 (109) hide show
  1. package/README.md +5 -4
  2. package/dist/apps/design-system-dashboard/mcp-app.html +26 -26
  3. package/dist/apps/token-browser/mcp-app.html +34 -34
  4. package/dist/core/http-request-guard.d.ts.map +1 -1
  5. package/dist/core/http-request-guard.js +12 -14
  6. package/dist/core/http-request-guard.js.map +1 -1
  7. package/dist/core/port-discovery.d.ts.map +1 -1
  8. package/dist/core/port-discovery.js +151 -52
  9. package/dist/core/port-discovery.js.map +1 -1
  10. package/dist/core/websocket-server.d.ts.map +1 -1
  11. package/dist/core/websocket-server.js +9 -1
  12. package/dist/core/websocket-server.js.map +1 -1
  13. package/dist/core/write-tools.d.ts +5 -1
  14. package/dist/core/write-tools.d.ts.map +1 -1
  15. package/dist/core/write-tools.js +113 -83
  16. package/dist/core/write-tools.js.map +1 -1
  17. package/dist/local.d.ts.map +1 -1
  18. package/dist/local.js +9 -2
  19. package/dist/local.js.map +1 -1
  20. package/figma-desktop-bridge/code.js +10 -2
  21. package/figma-desktop-bridge/ui.html +82 -8
  22. package/package.json +1 -1
  23. package/dist/cloudflare/apps/design-system-dashboard/scoring/accessibility.js +0 -277
  24. package/dist/cloudflare/apps/design-system-dashboard/scoring/component-metadata.js +0 -357
  25. package/dist/cloudflare/apps/design-system-dashboard/scoring/consistency.js +0 -341
  26. package/dist/cloudflare/apps/design-system-dashboard/scoring/coverage.js +0 -230
  27. package/dist/cloudflare/apps/design-system-dashboard/scoring/engine.js +0 -92
  28. package/dist/cloudflare/apps/design-system-dashboard/scoring/naming-semantics.js +0 -308
  29. package/dist/cloudflare/apps/design-system-dashboard/scoring/token-architecture.js +0 -349
  30. package/dist/cloudflare/apps/design-system-dashboard/scoring/types.js +0 -40
  31. package/dist/cloudflare/apps/design-system-dashboard/server.js +0 -159
  32. package/dist/cloudflare/apps/token-browser/server.js +0 -136
  33. package/dist/cloudflare/browser-manager.js +0 -157
  34. package/dist/cloudflare/core/accessibility-tools.js +0 -361
  35. package/dist/cloudflare/core/annotation-tools.js +0 -230
  36. package/dist/cloudflare/core/cloud-websocket-connector.js +0 -419
  37. package/dist/cloudflare/core/cloud-websocket-relay.js +0 -198
  38. package/dist/cloudflare/core/comment-tools.js +0 -292
  39. package/dist/cloudflare/core/config.js +0 -153
  40. package/dist/cloudflare/core/console-monitor.js +0 -427
  41. package/dist/cloudflare/core/deep-component-tools.js +0 -128
  42. package/dist/cloudflare/core/design-code-tools.js +0 -2793
  43. package/dist/cloudflare/core/design-system-manifest.js +0 -265
  44. package/dist/cloudflare/core/design-system-tools.js +0 -882
  45. package/dist/cloudflare/core/diagnose-tool.js +0 -100
  46. package/dist/cloudflare/core/diff/changelog-formatter.js +0 -275
  47. package/dist/cloudflare/core/diff/diff-engine.js +0 -334
  48. package/dist/cloudflare/core/diff/property-compare.js +0 -36
  49. package/dist/cloudflare/core/diff/version-cache.js +0 -74
  50. package/dist/cloudflare/core/enrichment/enrichment-service.js +0 -374
  51. package/dist/cloudflare/core/enrichment/index.js +0 -7
  52. package/dist/cloudflare/core/enrichment/relationship-mapper.js +0 -351
  53. package/dist/cloudflare/core/enrichment/style-resolver.js +0 -346
  54. package/dist/cloudflare/core/figjam-tools.js +0 -547
  55. package/dist/cloudflare/core/figma-api.js +0 -509
  56. package/dist/cloudflare/core/figma-connector.js +0 -7
  57. package/dist/cloudflare/core/figma-reconstruction-spec.js +0 -402
  58. package/dist/cloudflare/core/figma-style-extractor.js +0 -311
  59. package/dist/cloudflare/core/figma-tools.js +0 -3353
  60. package/dist/cloudflare/core/identity.js +0 -96
  61. package/dist/cloudflare/core/library-tools.js +0 -580
  62. package/dist/cloudflare/core/logger.js +0 -53
  63. package/dist/cloudflare/core/port-discovery.js +0 -935
  64. package/dist/cloudflare/core/resolve-package-root.js +0 -11
  65. package/dist/cloudflare/core/slides-tools.js +0 -714
  66. package/dist/cloudflare/core/slot-tools.js +0 -334
  67. package/dist/cloudflare/core/snippet-injector.js +0 -96
  68. package/dist/cloudflare/core/tokens/alias-resolver.js +0 -205
  69. package/dist/cloudflare/core/tokens/config.js +0 -294
  70. package/dist/cloudflare/core/tokens/dialect.js +0 -232
  71. package/dist/cloudflare/core/tokens/figma-converter.js +0 -323
  72. package/dist/cloudflare/core/tokens/formatters/css-vars.js +0 -338
  73. package/dist/cloudflare/core/tokens/formatters/dtcg.js +0 -376
  74. package/dist/cloudflare/core/tokens/formatters/index.js +0 -45
  75. package/dist/cloudflare/core/tokens/formatters/json.js +0 -205
  76. package/dist/cloudflare/core/tokens/formatters/less.js +0 -4
  77. package/dist/cloudflare/core/tokens/formatters/scss.js +0 -258
  78. package/dist/cloudflare/core/tokens/formatters/stubs.js +0 -13
  79. package/dist/cloudflare/core/tokens/formatters/style-dictionary-v3.js +0 -213
  80. package/dist/cloudflare/core/tokens/formatters/tailwind-v3.js +0 -237
  81. package/dist/cloudflare/core/tokens/formatters/tailwind-v4.js +0 -335
  82. package/dist/cloudflare/core/tokens/formatters/tokens-studio.js +0 -256
  83. package/dist/cloudflare/core/tokens/formatters/ts-module.js +0 -198
  84. package/dist/cloudflare/core/tokens/index.js +0 -16
  85. package/dist/cloudflare/core/tokens/parsers/css-vars.js +0 -4
  86. package/dist/cloudflare/core/tokens/parsers/dtcg.js +0 -280
  87. package/dist/cloudflare/core/tokens/parsers/index.js +0 -138
  88. package/dist/cloudflare/core/tokens/parsers/json.js +0 -7
  89. package/dist/cloudflare/core/tokens/parsers/scss.js +0 -4
  90. package/dist/cloudflare/core/tokens/parsers/stubs.js +0 -20
  91. package/dist/cloudflare/core/tokens/parsers/style-dictionary-v3.js +0 -4
  92. package/dist/cloudflare/core/tokens/parsers/tailwind-v3.js +0 -4
  93. package/dist/cloudflare/core/tokens/parsers/tailwind-v4.js +0 -4
  94. package/dist/cloudflare/core/tokens/parsers/tokens-studio.js +0 -4
  95. package/dist/cloudflare/core/tokens/schemas.js +0 -152
  96. package/dist/cloudflare/core/tokens/transforms/color.js +0 -12
  97. package/dist/cloudflare/core/tokens/transforms/index.js +0 -29
  98. package/dist/cloudflare/core/tokens/transforms/size.js +0 -7
  99. package/dist/cloudflare/core/tokens/types.js +0 -18
  100. package/dist/cloudflare/core/tokens-tools.js +0 -1788
  101. package/dist/cloudflare/core/types/design-code.js +0 -4
  102. package/dist/cloudflare/core/types/enriched.js +0 -5
  103. package/dist/cloudflare/core/types/index.js +0 -4
  104. package/dist/cloudflare/core/variable-resolver.js +0 -85
  105. package/dist/cloudflare/core/version-tools.js +0 -1199
  106. package/dist/cloudflare/core/websocket-connector.js +0 -436
  107. package/dist/cloudflare/core/websocket-server.js +0 -1009
  108. package/dist/cloudflare/core/write-tools.js +0 -2506
  109. package/dist/cloudflare/index.js +0 -3010
@@ -1,357 +0,0 @@
1
- /**
2
- * Component Metadata Scorer (weight: 0.20)
3
- *
4
- * Checks component quality and completeness within the design system.
5
- * Evaluates description presence, description quality, property completeness,
6
- * variant structure, and category organization.
7
- *
8
- * Scores against "scorable units" (component sets + standalone components)
9
- * rather than raw variant count to avoid inflated totals.
10
- */
11
- import { clamp, getSeverity } from "./types.js";
12
- /** Maximum examples to include in a finding. */
13
- const MAX_EXAMPLES = 5;
14
- /** Minimum description length to be considered "quality" documentation. */
15
- const MIN_QUALITY_DESC_LENGTH = 20;
16
- /**
17
- * Build a lookup structure for matching components to variant groups.
18
- * Collects component set node IDs for `containing_frame.containingComponentSet`
19
- * matching (primary REST API path) and name prefixes as fallback.
20
- */
21
- function buildComponentSetLookup(data) {
22
- const nodeIds = new Set();
23
- const namePrefixes = new Set();
24
- for (const cs of data.componentSets) {
25
- if (cs.node_id)
26
- nodeIds.add(cs.node_id);
27
- if (cs.name)
28
- namePrefixes.add(cs.name + "/");
29
- }
30
- return { nodeIds, namePrefixes };
31
- }
32
- /**
33
- * Check if a component belongs to a variant set.
34
- *
35
- * Detection order:
36
- * 1. Plugin API: `componentSetId` (set on ComponentNode by Figma plugin runtime)
37
- * 2. REST API: `containing_frame.containingComponentSet` (present on variants
38
- * returned by GET /v1/files/:key/components)
39
- * 3. File JSON: `component_set_id` (snake_case field on COMPONENT nodes in file tree)
40
- * 4. Name prefix: variant names starting with "SetName/" (some API formats)
41
- * 5. Frame node ID: containing_frame.nodeId matching a known component set node
42
- */
43
- function isComponentInSet(component, lookup) {
44
- // Plugin API: direct componentSetId
45
- if (component.componentSetId)
46
- return true;
47
- // REST API: containing_frame.containingComponentSet is set on variant components
48
- if (component.containing_frame?.containingComponentSet)
49
- return true;
50
- // File JSON: snake_case variant of componentSetId
51
- if (component.component_set_id)
52
- return true;
53
- // Name-based fallback: variant names may start with "SetName/"
54
- if (component.name) {
55
- for (const prefix of lookup.namePrefixes) {
56
- if (component.name.startsWith(prefix))
57
- return true;
58
- }
59
- }
60
- // Frame node ID fallback
61
- const frameNodeId = component.containing_frame?.nodeId;
62
- if (frameNodeId && lookup.nodeIds.has(frameNodeId))
63
- return true;
64
- return false;
65
- }
66
- /**
67
- * Classify components into standalone, variants, and component sets.
68
- * Scoring evaluates `scorableUnits` (standalone + componentSets)
69
- * instead of the raw component list which double-counts variants.
70
- */
71
- export function classifyComponents(data) {
72
- const lookup = buildComponentSetLookup(data);
73
- const standalone = [];
74
- const variants = [];
75
- for (const comp of data.components) {
76
- if (isComponentInSet(comp, lookup)) {
77
- variants.push(comp);
78
- }
79
- else {
80
- standalone.push(comp);
81
- }
82
- }
83
- return {
84
- standalone,
85
- variants,
86
- componentSets: data.componentSets,
87
- scorableUnits: [...standalone, ...data.componentSets],
88
- };
89
- }
90
- // ---------------------------------------------------------------------------
91
- // Scoring functions (operate on scorable units)
92
- // ---------------------------------------------------------------------------
93
- /**
94
- * Score description presence across scorable units.
95
- * Component sets and standalone components should have non-empty descriptions.
96
- */
97
- function scoreDescriptionPresence(classification) {
98
- const { scorableUnits } = classification;
99
- if (scorableUnits.length === 0) {
100
- return {
101
- id: "component-desc-presence",
102
- label: "Description presence",
103
- score: 100,
104
- severity: "info",
105
- tooltip: "Components and component sets should have descriptions. Descriptions appear in Figma's asset panel and help designers find the right component.",
106
- details: "No components to evaluate.",
107
- };
108
- }
109
- const withDesc = scorableUnits.filter((c) => c.description && c.description.trim().length > 0);
110
- const withoutDesc = scorableUnits.filter((c) => !c.description || c.description.trim().length === 0);
111
- const ratio = withDesc.length / scorableUnits.length;
112
- const score = clamp(ratio * 100);
113
- return {
114
- id: "component-desc-presence",
115
- label: "Description presence",
116
- score,
117
- severity: getSeverity(score),
118
- tooltip: "Components and component sets should have descriptions. Descriptions appear in Figma's asset panel and help designers find the right component.",
119
- details: `${withDesc.length} of ${scorableUnits.length} components have descriptions (${Math.round(ratio * 100)}%).`,
120
- examples: withoutDesc.length > 0
121
- ? withoutDesc.slice(0, MAX_EXAMPLES).map((c) => c.name)
122
- : undefined,
123
- locations: withoutDesc.length > 0
124
- ? withoutDesc.slice(0, MAX_EXAMPLES).map((c) => ({
125
- name: c.name,
126
- nodeId: c.node_id,
127
- type: "component",
128
- }))
129
- : undefined,
130
- };
131
- }
132
- /**
133
- * Score description quality.
134
- * Descriptions should be meaningful (>20 chars), not just the component name.
135
- */
136
- function scoreDescriptionQuality(classification) {
137
- const { scorableUnits } = classification;
138
- const withDesc = scorableUnits.filter((c) => c.description && c.description.trim().length > 0);
139
- if (withDesc.length === 0) {
140
- return {
141
- id: "component-desc-quality",
142
- label: "Description quality",
143
- score: 0,
144
- severity: scorableUnits.length === 0 ? "info" : "fail",
145
- tooltip: "Descriptions should be meaningful (20+ characters) and explain usage, not just repeat the name. Good descriptions reduce misuse.",
146
- details: scorableUnits.length === 0
147
- ? "No components to evaluate."
148
- : "No components have descriptions to evaluate quality.",
149
- };
150
- }
151
- const shortDescs = withDesc.filter((c) => c.description.trim().length < MIN_QUALITY_DESC_LENGTH);
152
- const qualityCount = withDesc.length - shortDescs.length;
153
- const ratio = qualityCount / withDesc.length;
154
- const score = clamp(ratio * 100);
155
- return {
156
- id: "component-desc-quality",
157
- label: "Description quality",
158
- score,
159
- severity: getSeverity(score),
160
- tooltip: "Descriptions should be meaningful (20+ characters) and explain usage, not just repeat the name. Good descriptions reduce misuse.",
161
- details: shortDescs.length > 0
162
- ? `${shortDescs.length} of ${withDesc.length} descriptions are too short (<${MIN_QUALITY_DESC_LENGTH} chars). Provide usage guidance, not just names.`
163
- : `All ${withDesc.length} descriptions provide meaningful documentation.`,
164
- examples: shortDescs.length > 0
165
- ? shortDescs.slice(0, MAX_EXAMPLES).map((c) => c.name)
166
- : undefined,
167
- };
168
- }
169
- /**
170
- * Score property completeness.
171
- * Standalone components should define properties for flexibility.
172
- * Component sets inherently have properties via their variants.
173
- */
174
- function scorePropertyCompleteness(classification) {
175
- const { standalone, componentSets, scorableUnits } = classification;
176
- if (scorableUnits.length === 0) {
177
- return {
178
- id: "component-property-completeness",
179
- label: "Property completeness",
180
- score: 100,
181
- severity: "info",
182
- tooltip: "Components should expose properties or use variant sets. Properties make components flexible and reduce the need for detaching instances.",
183
- details: "No components to evaluate.",
184
- };
185
- }
186
- // Component sets always count as having properties (they are variant groups)
187
- // For standalone, check if they have any property definitions
188
- const standaloneWithProps = standalone.filter((c) => c.componentPropertyDefinitions &&
189
- Object.keys(c.componentPropertyDefinitions).length > 0);
190
- const standaloneWithoutProps = standalone.filter((c) => !c.componentPropertyDefinitions ||
191
- Object.keys(c.componentPropertyDefinitions).length === 0);
192
- const withProperties = standaloneWithProps.length + componentSets.length;
193
- const ratio = withProperties / scorableUnits.length;
194
- const score = clamp(ratio * 100);
195
- return {
196
- id: "component-property-completeness",
197
- label: "Property completeness",
198
- score,
199
- severity: getSeverity(score),
200
- tooltip: "Components should expose properties or use variant sets. Properties make components flexible and reduce the need for detaching instances.",
201
- details: `${withProperties} of ${scorableUnits.length} components have defined properties or variants (${Math.round(ratio * 100)}%).`,
202
- examples: standaloneWithoutProps.length > 0
203
- ? standaloneWithoutProps.slice(0, MAX_EXAMPLES).map((c) => c.name)
204
- : undefined,
205
- locations: standaloneWithoutProps.length > 0
206
- ? standaloneWithoutProps.slice(0, MAX_EXAMPLES).map((c) => ({
207
- name: c.name,
208
- nodeId: c.node_id,
209
- type: "component",
210
- }))
211
- : undefined,
212
- };
213
- }
214
- /**
215
- * Score variant structure.
216
- * A higher ratio of component sets to total scorable units indicates
217
- * good use of variant organization.
218
- */
219
- function scoreVariantStructure(classification) {
220
- const { standalone, componentSets, scorableUnits } = classification;
221
- if (scorableUnits.length === 0) {
222
- return {
223
- id: "component-variant-structure",
224
- label: "Variant structure",
225
- score: 100,
226
- severity: "info",
227
- tooltip: "Related component variants should be organized into component sets. Sets make variant switching easy and reduce component sprawl.",
228
- details: "No components to evaluate.",
229
- };
230
- }
231
- const setCount = componentSets.length;
232
- const ratio = setCount / scorableUnits.length;
233
- const score = clamp(ratio * 100);
234
- return {
235
- id: "component-variant-structure",
236
- label: "Variant structure",
237
- score,
238
- severity: getSeverity(score),
239
- tooltip: "Related component variants should be organized into component sets. Sets make variant switching easy and reduce component sprawl.",
240
- details: setCount > 0
241
- ? `${setCount} of ${scorableUnits.length} components use variant sets (${Math.round(ratio * 100)}%). ${standalone.length} standalone component${standalone.length === 1 ? "" : "s"}.`
242
- : "No components use variant structures. Consider organizing components into sets with variants.",
243
- examples: standalone.length > 0 && setCount > 0
244
- ? standalone.slice(0, MAX_EXAMPLES).map((c) => `${c.name} (standalone)`)
245
- : undefined,
246
- };
247
- }
248
- /**
249
- * Score category organization.
250
- * Components should use path separators (/) for logical grouping.
251
- */
252
- function scoreCategoryOrganization(classification) {
253
- const { scorableUnits } = classification;
254
- if (scorableUnits.length === 0) {
255
- return {
256
- id: "component-category-org",
257
- label: "Category organization",
258
- score: 100,
259
- severity: "info",
260
- tooltip: 'Component names should use path separators (/) for grouping (e.g. Forms/Input). Organized naming improves asset panel navigation.',
261
- details: "No components to evaluate.",
262
- };
263
- }
264
- const withPath = scorableUnits.filter((c) => c.name?.includes("/"));
265
- const withoutPath = scorableUnits.filter((c) => !c.name?.includes("/"));
266
- const ratio = withPath.length / scorableUnits.length;
267
- const score = clamp(ratio * 100);
268
- return {
269
- id: "component-category-org",
270
- label: "Category organization",
271
- score,
272
- severity: getSeverity(score),
273
- tooltip: 'Component names should use path separators (/) for grouping (e.g. Forms/Input). Organized naming improves asset panel navigation.',
274
- details: withPath.length > 0
275
- ? `${withPath.length} of ${scorableUnits.length} components use path-based grouping (${Math.round(ratio * 100)}%).`
276
- : 'No components use path separators for grouping. Use "/" in names for organization (e.g., "Forms/Input").',
277
- examples: withoutPath.length > 0
278
- ? withoutPath.slice(0, MAX_EXAMPLES).map((c) => c.name)
279
- : undefined,
280
- locations: withoutPath.length > 0
281
- ? withoutPath.slice(0, MAX_EXAMPLES).map((c) => ({
282
- name: c.name,
283
- nodeId: c.node_id,
284
- type: "component",
285
- }))
286
- : undefined,
287
- };
288
- }
289
- /** Matches Figma auto-generated layer names like "Frame 347", "Group 12", "Rectangle 5". */
290
- const GENERIC_NAME_RE = /^(Frame|Group|Rectangle|Ellipse|Line|Polygon|Vector|Text|Image|Slice|Component|Instance|Section|Boolean\s*Group)\s*\d*$/i;
291
- /**
292
- * Score generic layer naming.
293
- * Published components should have intentional names, not auto-generated ones.
294
- */
295
- function scoreGenericNaming(classification) {
296
- const { scorableUnits } = classification;
297
- if (scorableUnits.length === 0) {
298
- return {
299
- id: "component-generic-naming",
300
- label: "Layer naming",
301
- score: 100,
302
- severity: "info",
303
- tooltip: "Published components should have intentional names. Auto-generated names like Frame 347 or Group 12 indicate layers that were never renamed.",
304
- details: "No components to evaluate.",
305
- };
306
- }
307
- const genericComps = scorableUnits.filter((c) => {
308
- const segments = (c.name || "").split("/").map((s) => s.trim());
309
- return segments.some((seg) => GENERIC_NAME_RE.test(seg));
310
- });
311
- const ratio = 1 - genericComps.length / scorableUnits.length;
312
- const score = clamp(ratio * 100);
313
- return {
314
- id: "component-generic-naming",
315
- label: "Layer naming",
316
- score,
317
- severity: getSeverity(score),
318
- tooltip: "Published components should have intentional names. Auto-generated names like Frame 347 or Group 12 indicate layers that were never renamed.",
319
- details: genericComps.length > 0
320
- ? `${genericComps.length} of ${scorableUnits.length} components have auto-generated layer names (e.g. Frame, Group, Rectangle).`
321
- : "All components have intentional names.",
322
- examples: genericComps.length > 0
323
- ? genericComps.slice(0, MAX_EXAMPLES).map((c) => c.name)
324
- : undefined,
325
- locations: genericComps.length > 0
326
- ? genericComps.slice(0, MAX_EXAMPLES).map((c) => ({
327
- name: c.name,
328
- nodeId: c.node_id,
329
- type: "component",
330
- }))
331
- : undefined,
332
- };
333
- }
334
- /**
335
- * Component Metadata category scorer.
336
- * Returns the average score across all component metadata checks.
337
- */
338
- export function scoreComponentMetadata(data) {
339
- const classification = classifyComponents(data);
340
- const findings = [
341
- scoreDescriptionPresence(classification),
342
- scoreDescriptionQuality(classification),
343
- scorePropertyCompleteness(classification),
344
- scoreVariantStructure(classification),
345
- scoreCategoryOrganization(classification),
346
- scoreGenericNaming(classification),
347
- ];
348
- const score = clamp(findings.reduce((sum, f) => sum + f.score, 0) / findings.length);
349
- return {
350
- id: "component-metadata",
351
- label: "Component Metadata",
352
- shortLabel: "Components",
353
- score,
354
- weight: 0.2,
355
- findings,
356
- };
357
- }