@sarjallab09/figma-intelligence 1.0.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 (286) hide show
  1. package/LICENSE +26 -0
  2. package/README.md +327 -0
  3. package/bin/cli.js +859 -0
  4. package/design-bridge/.env.example +5 -0
  5. package/design-bridge/bridge.js +196 -0
  6. package/design-bridge/lib/assets.js +367 -0
  7. package/design-bridge/lib/prompt.js +85 -0
  8. package/design-bridge/lib/server.js +66 -0
  9. package/design-bridge/lib/stitch.js +37 -0
  10. package/design-bridge/lib/tokens.js +82 -0
  11. package/design-bridge/package-lock.json +579 -0
  12. package/design-bridge/package.json +19 -0
  13. package/figma-bridge-plugin/README.md +97 -0
  14. package/figma-bridge-plugin/anthropic-chat-runner.js +192 -0
  15. package/figma-bridge-plugin/bridge-relay.js +2363 -0
  16. package/figma-bridge-plugin/chat-runner.js +459 -0
  17. package/figma-bridge-plugin/code.js +1528 -0
  18. package/figma-bridge-plugin/codex-runner.js +505 -0
  19. package/figma-bridge-plugin/component-schemas.js +110 -0
  20. package/figma-bridge-plugin/content-context.js +869 -0
  21. package/figma-bridge-plugin/create-button.js +216 -0
  22. package/figma-bridge-plugin/gemini-cli-runner.js +291 -0
  23. package/figma-bridge-plugin/gemini-runner.js +187 -0
  24. package/figma-bridge-plugin/html-to-figma.js +927 -0
  25. package/figma-bridge-plugin/knowledge-hub/.gitkeep +0 -0
  26. package/figma-bridge-plugin/knowledge-hub/uspec-references/anatomy-spec.md +159 -0
  27. package/figma-bridge-plugin/knowledge-hub/uspec-references/api-spec.md +162 -0
  28. package/figma-bridge-plugin/knowledge-hub/uspec-references/color-spec.md +148 -0
  29. package/figma-bridge-plugin/knowledge-hub/uspec-references/full-spec-template.md +314 -0
  30. package/figma-bridge-plugin/knowledge-hub/uspec-references/property-spec.md +175 -0
  31. package/figma-bridge-plugin/knowledge-hub/uspec-references/screen-reader-spec.md +180 -0
  32. package/figma-bridge-plugin/knowledge-hub/uspec-references/structure-spec.md +165 -0
  33. package/figma-bridge-plugin/manifest.json +21 -0
  34. package/figma-bridge-plugin/package-lock.json +1936 -0
  35. package/figma-bridge-plugin/package.json +20 -0
  36. package/figma-bridge-plugin/perplexity-runner.js +188 -0
  37. package/figma-bridge-plugin/references/SKILL.md +178 -0
  38. package/figma-bridge-plugin/references/anatomy-spec.md +159 -0
  39. package/figma-bridge-plugin/references/api-spec.md +162 -0
  40. package/figma-bridge-plugin/references/color-spec.md +148 -0
  41. package/figma-bridge-plugin/references/full-spec-template.md +314 -0
  42. package/figma-bridge-plugin/references/property-spec.md +175 -0
  43. package/figma-bridge-plugin/references/screen-reader-spec.md +180 -0
  44. package/figma-bridge-plugin/references/structure-spec.md +165 -0
  45. package/figma-bridge-plugin/shared-prompt-config.js +604 -0
  46. package/figma-bridge-plugin/spec-helpers/build-table.js +269 -0
  47. package/figma-bridge-plugin/spec-helpers/classify-elements.js +189 -0
  48. package/figma-bridge-plugin/spec-helpers/index.js +35 -0
  49. package/figma-bridge-plugin/spec-helpers/parse-figma-link.js +49 -0
  50. package/figma-bridge-plugin/spec-helpers/position-markers.js +158 -0
  51. package/figma-bridge-plugin/stitch-auth.js +322 -0
  52. package/figma-bridge-plugin/stitch-runner.js +1427 -0
  53. package/figma-bridge-plugin/token-resolver.js +107 -0
  54. package/figma-bridge-plugin/ui.html +4467 -0
  55. package/figma-intelligence-layer/.env.example +39 -0
  56. package/figma-intelligence-layer/docs/local-image-generation.md +60 -0
  57. package/figma-intelligence-layer/examples/comfyui-workflow-template.example.json +101 -0
  58. package/figma-intelligence-layer/jest.config.js +14 -0
  59. package/figma-intelligence-layer/mcp-config.json +19 -0
  60. package/figma-intelligence-layer/package-lock.json +5892 -0
  61. package/figma-intelligence-layer/package.json +48 -0
  62. package/figma-intelligence-layer/scripts/setup-comfyui-local.sh +67 -0
  63. package/figma-intelligence-layer/scripts/start-comfyui.sh +33 -0
  64. package/figma-intelligence-layer/src/index.ts +2233 -0
  65. package/figma-intelligence-layer/src/shared/auto-layout-validator.ts +404 -0
  66. package/figma-intelligence-layer/src/shared/cache.ts +187 -0
  67. package/figma-intelligence-layer/src/shared/color-operations.ts +533 -0
  68. package/figma-intelligence-layer/src/shared/color-utils.ts +138 -0
  69. package/figma-intelligence-layer/src/shared/component-script-builder.ts +413 -0
  70. package/figma-intelligence-layer/src/shared/component-templates.ts +2767 -0
  71. package/figma-intelligence-layer/src/shared/concept-taxonomy.ts +694 -0
  72. package/figma-intelligence-layer/src/shared/decision-log.ts +128 -0
  73. package/figma-intelligence-layer/src/shared/design-system-context.ts +568 -0
  74. package/figma-intelligence-layer/src/shared/design-system-intelligence.ts +131 -0
  75. package/figma-intelligence-layer/src/shared/design-system-matcher.ts +184 -0
  76. package/figma-intelligence-layer/src/shared/design-system-normalizers.ts +196 -0
  77. package/figma-intelligence-layer/src/shared/design-system-tokens.ts +295 -0
  78. package/figma-intelligence-layer/src/shared/dtcg-validator.ts +530 -0
  79. package/figma-intelligence-layer/src/shared/enrichment-pipeline.ts +671 -0
  80. package/figma-intelligence-layer/src/shared/figma-bridge.ts +1408 -0
  81. package/figma-intelligence-layer/src/shared/font-config.ts +126 -0
  82. package/figma-intelligence-layer/src/shared/icon-catalog.ts +360 -0
  83. package/figma-intelligence-layer/src/shared/icon-fetch.ts +80 -0
  84. package/figma-intelligence-layer/src/shared/prototype-script-builder.ts +162 -0
  85. package/figma-intelligence-layer/src/shared/response-compression.ts +440 -0
  86. package/figma-intelligence-layer/src/shared/semantic-token-catalog.ts +324 -0
  87. package/figma-intelligence-layer/src/shared/token-binder.ts +505 -0
  88. package/figma-intelligence-layer/src/shared/token-math.ts +427 -0
  89. package/figma-intelligence-layer/src/shared/token-naming.ts +468 -0
  90. package/figma-intelligence-layer/src/shared/token-utils.ts +420 -0
  91. package/figma-intelligence-layer/src/shared/types.ts +346 -0
  92. package/figma-intelligence-layer/src/shared/typography-presets.ts +94 -0
  93. package/figma-intelligence-layer/src/shared/unsplash.ts +165 -0
  94. package/figma-intelligence-layer/src/shared/vision-client.ts +607 -0
  95. package/figma-intelligence-layer/src/shared/vision-provider-anthropic.ts +334 -0
  96. package/figma-intelligence-layer/src/shared/vision-provider-openai.ts +446 -0
  97. package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/a11y-annotate-handler.ts +782 -0
  98. package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/a11y-annotate-renderer.ts +496 -0
  99. package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/a11y-annotation-kit.ts +230 -0
  100. package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/colorblind-sim.ts +66 -0
  101. package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/index.ts +810 -0
  102. package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/keyboard-sr-order-analyzer.ts +1191 -0
  103. package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/keyboard-sr-order-figma-page.ts +1346 -0
  104. package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/keyboard-sr-order-handler.ts +148 -0
  105. package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/vpat-figma-page.ts +499 -0
  106. package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/vpat-report.ts +910 -0
  107. package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/wcag-checker.ts +989 -0
  108. package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/wcag-criteria.ts +1160 -0
  109. package/figma-intelligence-layer/src/tools/phase1-vision/design-from-ref/index.ts +424 -0
  110. package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/component-recognizer.ts +38 -0
  111. package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/ds-matcher.ts +111 -0
  112. package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/font-matcher.ts +114 -0
  113. package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/icon-resolver.ts +103 -0
  114. package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/index.ts +1060 -0
  115. package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/layout-segmenter.ts +18 -0
  116. package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/token-inferencer.ts +39 -0
  117. package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/vision-pipeline.ts +58 -0
  118. package/figma-intelligence-layer/src/tools/phase1-vision/sketch-to-design/index.ts +298 -0
  119. package/figma-intelligence-layer/src/tools/phase1-vision/visual-audit/index.ts +197 -0
  120. package/figma-intelligence-layer/src/tools/phase2-accuracy/component-audit/index.ts +494 -0
  121. package/figma-intelligence-layer/src/tools/phase2-accuracy/intent-translator/index.ts +356 -0
  122. package/figma-intelligence-layer/src/tools/phase2-accuracy/layout-intelligence/container-patterns.ts +123 -0
  123. package/figma-intelligence-layer/src/tools/phase2-accuracy/layout-intelligence/index.ts +663 -0
  124. package/figma-intelligence-layer/src/tools/phase2-accuracy/lint-rules/built-in-rules.yaml +56 -0
  125. package/figma-intelligence-layer/src/tools/phase2-accuracy/lint-rules/index.ts +614 -0
  126. package/figma-intelligence-layer/src/tools/phase2-accuracy/lint-rules/rule-engine.ts +113 -0
  127. package/figma-intelligence-layer/src/tools/phase2-accuracy/theme-generator/color-theory.ts +178 -0
  128. package/figma-intelligence-layer/src/tools/phase2-accuracy/theme-generator/index.ts +470 -0
  129. package/figma-intelligence-layer/src/tools/phase2-accuracy/variant-expander/index.ts +429 -0
  130. package/figma-intelligence-layer/src/tools/phase2-accuracy/variant-expander/token-override-maps.ts +226 -0
  131. package/figma-intelligence-layer/src/tools/phase3-generation/ai-image-insert/index.ts +535 -0
  132. package/figma-intelligence-layer/src/tools/phase3-generation/component-archaeologist/index.ts +660 -0
  133. package/figma-intelligence-layer/src/tools/phase3-generation/component-archaeologist/pattern-fingerprints.ts +209 -0
  134. package/figma-intelligence-layer/src/tools/phase3-generation/composition-builder/index.ts +540 -0
  135. package/figma-intelligence-layer/src/tools/phase3-generation/figma-animated-build.ts +391 -0
  136. package/figma-intelligence-layer/src/tools/phase3-generation/page-architect/index.ts +2019 -0
  137. package/figma-intelligence-layer/src/tools/phase3-generation/page-architect/screen-templates.ts +131 -0
  138. package/figma-intelligence-layer/src/tools/phase3-generation/prototype-map/index.ts +381 -0
  139. package/figma-intelligence-layer/src/tools/phase3-generation/prototype-wire/index.ts +565 -0
  140. package/figma-intelligence-layer/src/tools/phase3-generation/swarm-build/index.ts +764 -0
  141. package/figma-intelligence-layer/src/tools/phase3-generation/system-drift/index.ts +535 -0
  142. package/figma-intelligence-layer/src/tools/phase3-generation/unsplash-search/index.ts +84 -0
  143. package/figma-intelligence-layer/src/tools/phase3-generation/url-to-frame/index.ts +401 -0
  144. package/figma-intelligence-layer/src/tools/phase4-sync/animation-specifier/code-generators/css-animations.ts +68 -0
  145. package/figma-intelligence-layer/src/tools/phase4-sync/animation-specifier/code-generators/framer-motion.ts +78 -0
  146. package/figma-intelligence-layer/src/tools/phase4-sync/animation-specifier/code-generators/swift-animations.ts +93 -0
  147. package/figma-intelligence-layer/src/tools/phase4-sync/animation-specifier/index.ts +596 -0
  148. package/figma-intelligence-layer/src/tools/phase4-sync/ci-check/index.ts +462 -0
  149. package/figma-intelligence-layer/src/tools/phase4-sync/export-tokens/index.ts +1470 -0
  150. package/figma-intelligence-layer/src/tools/phase4-sync/generate-component-code/index.ts +829 -0
  151. package/figma-intelligence-layer/src/tools/phase4-sync/handoff-spec/index.ts +702 -0
  152. package/figma-intelligence-layer/src/tools/phase4-sync/icon-library-sync/index.ts +483 -0
  153. package/figma-intelligence-layer/src/tools/phase4-sync/sync-from-code/index.ts +501 -0
  154. package/figma-intelligence-layer/src/tools/phase4-sync/sync-from-code/storybook-parser.ts +106 -0
  155. package/figma-intelligence-layer/src/tools/phase4-sync/watch-docs/index.ts +676 -0
  156. package/figma-intelligence-layer/src/tools/phase4-sync/webhook-listener/index.ts +560 -0
  157. package/figma-intelligence-layer/src/tools/phase5-governance/apg-doc/index.ts +1043 -0
  158. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/component-detection.ts +620 -0
  159. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/anatomy.ts +331 -0
  160. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/color-tokens.ts +77 -0
  161. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/properties.ts +54 -0
  162. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/snapshot.ts +287 -0
  163. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/spacing.ts +71 -0
  164. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/states.ts +43 -0
  165. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/typography.ts +71 -0
  166. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/index.ts +221 -0
  167. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/_default.ts +166 -0
  168. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/accordion.ts +232 -0
  169. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/alert.ts +234 -0
  170. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/avatar-group.ts +270 -0
  171. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/avatar.ts +249 -0
  172. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/badge.ts +231 -0
  173. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/banner.ts +293 -0
  174. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/breadcrumb.ts +240 -0
  175. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/button.ts +243 -0
  176. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/calendar.ts +307 -0
  177. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/card.ts +143 -0
  178. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/checkbox.ts +227 -0
  179. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/chip.ts +233 -0
  180. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/combobox.ts +282 -0
  181. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/datepicker.ts +276 -0
  182. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/divider.ts +223 -0
  183. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/drawer.ts +255 -0
  184. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/dropdown-menu.ts +289 -0
  185. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/empty-state.ts +261 -0
  186. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/file-uploader.ts +290 -0
  187. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/form.ts +265 -0
  188. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/grid.ts +238 -0
  189. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/icon.ts +255 -0
  190. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/index.ts +128 -0
  191. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/inline-edit.ts +286 -0
  192. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/inline-message.ts +255 -0
  193. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/input.ts +330 -0
  194. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/link.ts +247 -0
  195. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/list.ts +250 -0
  196. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/menu.ts +247 -0
  197. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/modal.ts +144 -0
  198. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/navbar.ts +264 -0
  199. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/navigation.ts +251 -0
  200. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/number-input.ts +261 -0
  201. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/pagination.ts +248 -0
  202. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/popover.ts +270 -0
  203. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/progress.ts +251 -0
  204. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/radio.ts +142 -0
  205. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/range-slider.ts +282 -0
  206. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/rating.ts +250 -0
  207. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/search.ts +258 -0
  208. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/segmented-control.ts +265 -0
  209. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/select.ts +319 -0
  210. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/skeleton.ts +256 -0
  211. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/slider.ts +232 -0
  212. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/spinner.ts +239 -0
  213. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/status-dot.ts +252 -0
  214. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/stepper.ts +270 -0
  215. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/table.ts +244 -0
  216. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/tabs.ts +143 -0
  217. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/tag.ts +243 -0
  218. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/textarea.ts +259 -0
  219. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/time-picker.ts +293 -0
  220. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/toast.ts +144 -0
  221. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/toggle.ts +289 -0
  222. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/toolbar.ts +267 -0
  223. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/tooltip.ts +232 -0
  224. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/treeview.ts +257 -0
  225. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/typography.ts +319 -0
  226. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/legacy-compat.ts +121 -0
  227. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/renderers/anatomy-diagram.ts +430 -0
  228. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/renderers/figma-page.ts +312 -0
  229. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/renderers/json.ts +129 -0
  230. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/renderers/markdown.ts +78 -0
  231. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/renderers/visual-doc.ts +2333 -0
  232. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/accessibility.ts +100 -0
  233. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/anatomy.ts +32 -0
  234. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/color-tokens.ts +59 -0
  235. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/content-guidance.ts +18 -0
  236. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/design-tokens.ts +53 -0
  237. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/interaction-rules.ts +19 -0
  238. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/overview.ts +91 -0
  239. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/properties-api.ts +71 -0
  240. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/qa-criteria.ts +19 -0
  241. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/related-components.ts +110 -0
  242. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/responsive.ts +19 -0
  243. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/size-specs.ts +67 -0
  244. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/spacing-structure.ts +58 -0
  245. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/state-specs.ts +79 -0
  246. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/states.ts +50 -0
  247. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/type-hierarchy.ts +33 -0
  248. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/typography.ts +55 -0
  249. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/usage-guidelines.ts +73 -0
  250. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/variants.ts +81 -0
  251. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/types.ts +409 -0
  252. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec-sheet/index.ts +198 -0
  253. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec-sheet/renderer.ts +701 -0
  254. package/figma-intelligence-layer/src/tools/phase5-governance/component-spec-sheet/types.ts +88 -0
  255. package/figma-intelligence-layer/src/tools/phase5-governance/decision-log/index.ts +135 -0
  256. package/figma-intelligence-layer/src/tools/phase5-governance/design-decision-log/index.ts +491 -0
  257. package/figma-intelligence-layer/src/tools/phase5-governance/ds-primitives/index.ts +416 -0
  258. package/figma-intelligence-layer/src/tools/phase5-governance/ds-scaffolder/index.ts +722 -0
  259. package/figma-intelligence-layer/src/tools/phase5-governance/ds-variables/index.ts +449 -0
  260. package/figma-intelligence-layer/src/tools/phase5-governance/health-report/index.ts +393 -0
  261. package/figma-intelligence-layer/src/tools/phase5-governance/taxonomy-docs/index.ts +406 -0
  262. package/figma-intelligence-layer/src/tools/phase5-governance/taxonomy-docs/renderers/figma-page.ts +292 -0
  263. package/figma-intelligence-layer/src/tools/phase5-governance/taxonomy-docs/renderers/json.ts +24 -0
  264. package/figma-intelligence-layer/src/tools/phase5-governance/taxonomy-docs/renderers/markdown.ts +172 -0
  265. package/figma-intelligence-layer/src/tools/phase5-governance/taxonomy-docs/renderers/naming-guide.ts +409 -0
  266. package/figma-intelligence-layer/src/tools/phase5-governance/token-analytics/index.ts +594 -0
  267. package/figma-intelligence-layer/src/tools/phase5-governance/token-docs/index.ts +710 -0
  268. package/figma-intelligence-layer/src/tools/phase5-governance/token-migrate/index.ts +458 -0
  269. package/figma-intelligence-layer/src/tools/phase5-governance/token-naming/index.ts +134 -0
  270. package/figma-intelligence-layer/tests/apg-doc.test.ts +101 -0
  271. package/figma-intelligence-layer/tests/design-system-context.test.ts +152 -0
  272. package/figma-intelligence-layer/tests/design-system-matcher.test.ts +144 -0
  273. package/figma-intelligence-layer/tests/figma-bridge.test.ts +83 -0
  274. package/figma-intelligence-layer/tests/generate-image-and-insert.test.ts +56 -0
  275. package/figma-intelligence-layer/tests/screen-cloner-regression.test.ts +69 -0
  276. package/figma-intelligence-layer/tests/smoke.test.ts +174 -0
  277. package/figma-intelligence-layer/tests/spec-generator.test.ts +127 -0
  278. package/figma-intelligence-layer/tests/token-migrate.test.ts +21 -0
  279. package/figma-intelligence-layer/tests/token-naming.test.ts +30 -0
  280. package/figma-intelligence-layer/tsconfig.json +19 -0
  281. package/package.json +35 -0
  282. package/scripts/clean-existing-chunks.js +179 -0
  283. package/scripts/connect-ai-tool.js +490 -0
  284. package/scripts/convert-hub-pdfs.js +425 -0
  285. package/scripts/figma-mcp-status.js +349 -0
  286. package/scripts/register-codex-mcp.js +96 -0
@@ -0,0 +1,24 @@
1
+ /**
2
+ * JSON renderer for taxonomy documentation.
3
+ * Returns structured data for tooling integration.
4
+ */
5
+
6
+ import { GRAMMAR } from "../../../../shared/concept-taxonomy.js";
7
+ import type { ConceptCoverage, TaxonomyDocsJsonOutput, TokenValueSnapshot } from "../index.js";
8
+
9
+ export function renderJson(
10
+ coverage: ConceptCoverage[],
11
+ snapshots: Record<string, TokenValueSnapshot>,
12
+ totalExpected: number,
13
+ totalFound: number,
14
+ ): TaxonomyDocsJsonOutput {
15
+ return {
16
+ generatedAt: new Date().toISOString(),
17
+ grammar: GRAMMAR,
18
+ concepts: coverage,
19
+ totalExpected,
20
+ totalFound,
21
+ totalMissing: totalExpected - totalFound,
22
+ tokenValues: snapshots,
23
+ };
24
+ }
@@ -0,0 +1,172 @@
1
+ /**
2
+ * Markdown renderer for taxonomy documentation.
3
+ * Generates exportable markdown with concept table, naming grammar,
4
+ * per-concept token anatomy, and coverage report.
5
+ */
6
+
7
+ import { GRAMMAR } from "../../../../shared/concept-taxonomy.js";
8
+ import type { ConceptCoverage, TokenValueSnapshot } from "../index.js";
9
+
10
+ interface MarkdownOptions {
11
+ includeTokenAnatomy: boolean;
12
+ showCoverage: boolean;
13
+ }
14
+
15
+ function formatColorValue(value: unknown): string {
16
+ if (typeof value === "string") return value;
17
+ if (value && typeof value === "object" && "r" in value) {
18
+ const c = value as { r: number; g: number; b: number; a?: number };
19
+ const r = Math.round(c.r * 255);
20
+ const g = Math.round(c.g * 255);
21
+ const b = Math.round(c.b * 255);
22
+ return `#${r.toString(16).padStart(2, "0")}${g.toString(16).padStart(2, "0")}${b.toString(16).padStart(2, "0")}`.toUpperCase();
23
+ }
24
+ return String(value ?? "—");
25
+ }
26
+
27
+ function statusEmoji(status: ConceptCoverage["status"]): string {
28
+ if (status === "full") return "✅";
29
+ if (status === "partial") return "🟡";
30
+ return "❌";
31
+ }
32
+
33
+ export function renderMarkdown(
34
+ coverage: ConceptCoverage[],
35
+ snapshots: Record<string, TokenValueSnapshot>,
36
+ options: MarkdownOptions,
37
+ ): string {
38
+ const lines: string[] = [];
39
+ const now = new Date().toISOString().split("T")[0];
40
+
41
+ // ── Header ──
42
+ lines.push("# Token Taxonomy Documentation");
43
+ lines.push("");
44
+ lines.push(`> Generated ${now} from live Figma variables. Re-run \`figma_taxonomy_docs\` to refresh.`);
45
+ lines.push("");
46
+
47
+ // ── Naming Grammar ──
48
+ lines.push("## Naming Grammar");
49
+ lines.push("");
50
+ lines.push("### Semantic Token Pattern");
51
+ lines.push("```");
52
+ lines.push(GRAMMAR.pattern);
53
+ lines.push("```");
54
+ lines.push("");
55
+ lines.push("### Component Alias Pattern");
56
+ lines.push("```");
57
+ lines.push(GRAMMAR.componentPattern);
58
+ lines.push("```");
59
+ lines.push("");
60
+ lines.push("| Segment | Description | Examples |");
61
+ lines.push("|---------|-------------|----------|");
62
+ lines.push(`| category | ${GRAMMAR.categories.join(", ")} | color, radius, space |`);
63
+ lines.push(`| concept | UI concept from taxonomy | actions, surface, field |`);
64
+ lines.push(`| variant | Optional variant | primary, secondary, sm, lg |`);
65
+ lines.push(`| property | ${GRAMMAR.properties.slice(0, 6).join(", ")}... | background, text, border |`);
66
+ lines.push(`| state | ${GRAMMAR.states.slice(0, 8).join(", ")}... | default, hover, disabled |`);
67
+ lines.push("");
68
+
69
+ // ── Coverage Summary ──
70
+ if (options.showCoverage) {
71
+ const full = coverage.filter((c) => c.status === "full").length;
72
+ const partial = coverage.filter((c) => c.status === "partial").length;
73
+ const missing = coverage.filter((c) => c.status === "missing").length;
74
+
75
+ lines.push("## Coverage Summary");
76
+ lines.push("");
77
+ lines.push(`| Status | Count |`);
78
+ lines.push(`|--------|-------|`);
79
+ lines.push(`| ✅ Full | ${full} |`);
80
+ lines.push(`| 🟡 Partial | ${partial} |`);
81
+ lines.push(`| ❌ Missing | ${missing} |`);
82
+ lines.push("");
83
+ }
84
+
85
+ // ── Concept Overview Table ──
86
+ lines.push("## Concept Taxonomy");
87
+ lines.push("");
88
+ lines.push("| Concept | Purpose | Typical Forms | States | Variants | Coverage |");
89
+ lines.push("|---------|---------|---------------|--------|----------|----------|");
90
+
91
+ for (const c of coverage) {
92
+ const forms = c.typicalForms.slice(0, 4).join(", ") + (c.typicalForms.length > 4 ? "..." : "");
93
+ const states = c.validStates.slice(0, 4).join(", ") + (c.validStates.length > 4 ? "..." : "");
94
+ const variants = c.validVariants.length > 0
95
+ ? c.validVariants.slice(0, 3).join(", ") + (c.validVariants.length > 3 ? "..." : "")
96
+ : "—";
97
+ const cov = options.showCoverage ? `${statusEmoji(c.status)} ${c.foundTokens.length}/${c.expectedTokens.length}` : "";
98
+ lines.push(`| **${c.conceptName}** | ${c.purpose} | ${forms} | ${states} | ${variants} | ${cov} |`);
99
+ }
100
+ lines.push("");
101
+
102
+ // ── Per-Concept Token Anatomy ──
103
+ if (options.includeTokenAnatomy) {
104
+ lines.push("## Token Anatomy by Concept");
105
+ lines.push("");
106
+
107
+ for (const c of coverage) {
108
+ if (c.expectedTokens.length === 0) continue;
109
+
110
+ lines.push(`### ${c.conceptName}`);
111
+ lines.push("");
112
+ lines.push(`> ${c.purpose}`);
113
+ lines.push("");
114
+
115
+ if (c.typicalForms.length > 0) {
116
+ lines.push(`**Components:** ${c.typicalForms.join(", ")}`);
117
+ lines.push("");
118
+ }
119
+
120
+ lines.push("| Token Path | Status | File Token | Value |");
121
+ lines.push("|------------|--------|------------|-------|");
122
+
123
+ for (const token of c.expectedTokens) {
124
+ const found = c.foundTokens.includes(token);
125
+ const fileToken = c.matchedFileTokens[token];
126
+ const status = found ? "✅" : "❌ missing";
127
+ const fileCol = fileToken ? `\`${fileToken}\`` : (found ? "exact" : "—");
128
+
129
+ let value = "—";
130
+ // Try the file token name first for snapshot lookup, then fall back to expected path
131
+ const snapKey = fileToken ?? token;
132
+ const snap = snapshots[snapKey] ?? snapshots[token];
133
+ if (snap?.values) {
134
+ const firstValue = Object.values(snap.values)[0];
135
+ if (firstValue !== undefined && firstValue !== null) {
136
+ value = snap.type === "COLOR" ? formatColorValue(firstValue) : String(firstValue);
137
+ }
138
+ }
139
+
140
+ lines.push(`| \`${token}\` | ${status} | ${fileCol} | ${value} |`);
141
+ }
142
+
143
+ lines.push("");
144
+
145
+ // States and variants
146
+ if (c.validStates.length > 0) {
147
+ lines.push(`**Valid states:** ${c.validStates.join(", ")}`);
148
+ }
149
+ if (c.validVariants.length > 0) {
150
+ lines.push(`**Valid variants:** ${c.validVariants.join(", ")}`);
151
+ }
152
+ lines.push("");
153
+ }
154
+ }
155
+
156
+ // ── Missing Tokens Summary ──
157
+ if (options.showCoverage) {
158
+ const allMissing = coverage.flatMap((c) => c.missingTokens.map((t) => ({ concept: c.conceptName, token: t })));
159
+ if (allMissing.length > 0) {
160
+ lines.push("## Missing Tokens");
161
+ lines.push("");
162
+ lines.push("| Concept | Missing Token |");
163
+ lines.push("|---------|---------------|");
164
+ for (const { concept, token } of allMissing) {
165
+ lines.push(`| ${concept} | \`${token}\` |`);
166
+ }
167
+ lines.push("");
168
+ }
169
+ }
170
+
171
+ return lines.join("\n");
172
+ }
@@ -0,0 +1,409 @@
1
+ /**
2
+ * Naming Guide renderer for taxonomy documentation.
3
+ * Generates a human-readable reference document that teaches contributors
4
+ * how to name tokens from scratch — grammar rules, allowed values per segment,
5
+ * worked examples per concept, and common mistakes to avoid.
6
+ */
7
+
8
+ import {
9
+ GRAMMAR,
10
+ CONCEPT_TAXONOMY,
11
+ generateTokenName,
12
+ type ConceptDefinition,
13
+ } from "../../../../shared/concept-taxonomy.js";
14
+ import type { ConceptCoverage } from "../index.js";
15
+
16
+ // ─── Helpers ────────────────────────────────────────────────────────────────
17
+
18
+ /** Pick representative examples for a concept across its variants and states. */
19
+ function buildWorkedExamples(concept: ConceptDefinition): string[] {
20
+ const examples: string[] = [];
21
+ const conceptSlug = concept.id === "action" ? "actions" : concept.id;
22
+
23
+ // 1. Basic default token
24
+ const firstRole = concept.tokenRoles.find((r) => r.required);
25
+ if (firstRole) {
26
+ examples.push(
27
+ generateTokenName(firstRole.category, conceptSlug, firstRole.property, undefined, "default"),
28
+ );
29
+ }
30
+
31
+ // 2. With a variant (pick first non-default variant)
32
+ const variant = concept.validVariants.find((v) => v !== "default");
33
+ if (variant && firstRole) {
34
+ examples.push(
35
+ generateTokenName(firstRole.category, conceptSlug, firstRole.property, variant, "default"),
36
+ );
37
+ }
38
+
39
+ // 3. With a non-default state
40
+ const state = concept.validStates.find((s) => s !== "default");
41
+ if (state && firstRole) {
42
+ examples.push(
43
+ generateTokenName(firstRole.category, conceptSlug, firstRole.property, undefined, state),
44
+ );
45
+ }
46
+
47
+ // 4. Different property (secondary role)
48
+ const secondRole = concept.tokenRoles.find(
49
+ (r) => r !== firstRole && r.required,
50
+ );
51
+ if (secondRole) {
52
+ examples.push(
53
+ generateTokenName(secondRole.category, conceptSlug, secondRole.property, undefined, "default"),
54
+ );
55
+ }
56
+
57
+ return examples;
58
+ }
59
+
60
+ /** Build a "wrong → right" pair for common mistakes. */
61
+ function buildMistakeExamples(concept: ConceptDefinition): Array<{ wrong: string; right: string; reason: string }> {
62
+ const mistakes: Array<{ wrong: string; right: string; reason: string }> = [];
63
+ const slug = concept.id === "action" ? "actions" : concept.id;
64
+ const firstRole = concept.tokenRoles.find((r) => r.required);
65
+ if (!firstRole) return mistakes;
66
+
67
+ // Mistake: uppercase
68
+ mistakes.push({
69
+ wrong: `${firstRole.category}/${slug.charAt(0).toUpperCase() + slug.slice(1)}/${firstRole.property}/default`,
70
+ right: `${firstRole.category}/${slug}/${firstRole.property}/default`,
71
+ reason: "All segments must be lowercase",
72
+ });
73
+
74
+ // Mistake: using dots or dashes as separators
75
+ mistakes.push({
76
+ wrong: `${firstRole.category}.${slug}.${firstRole.property}.default`,
77
+ right: `${firstRole.category}/${slug}/${firstRole.property}/default`,
78
+ reason: `Use \`/\` as the separator, not \`.\` or \`-\``,
79
+ });
80
+
81
+ // Mistake: skipping category
82
+ if (concept.validVariants.length > 0) {
83
+ const v = concept.validVariants[0];
84
+ mistakes.push({
85
+ wrong: `${slug}/${v}/${firstRole.property}/default`,
86
+ right: `${firstRole.category}/${slug}/${v}/${firstRole.property}/default`,
87
+ reason: "Token names must start with a category segment",
88
+ });
89
+ }
90
+
91
+ // Mistake: invalid state
92
+ mistakes.push({
93
+ wrong: `${firstRole.category}/${slug}/${firstRole.property}/highlighted`,
94
+ right: `${firstRole.category}/${slug}/${firstRole.property}/hover`,
95
+ reason: `"highlighted" is not a valid state — use one of: ${concept.validStates.join(", ")}`,
96
+ });
97
+
98
+ return mistakes;
99
+ }
100
+
101
+ // ─── Main Renderer ──────────────────────────────────────────────────────────
102
+
103
+ export function renderNamingGuide(coverage: ConceptCoverage[]): string {
104
+ const lines: string[] = [];
105
+ const now = new Date().toISOString().split("T")[0];
106
+
107
+ // ── Title ──
108
+ lines.push("# Token Naming Convention Reference");
109
+ lines.push("");
110
+ lines.push(`> A practical guide for designers and developers to name semantic tokens correctly.`);
111
+ lines.push(`> Generated ${now}. Re-run \`figma_taxonomy_docs\` with \`outputFormat: "naming-guide"\` to refresh.`);
112
+ lines.push("");
113
+ lines.push("---");
114
+ lines.push("");
115
+
116
+ // ── 1. Grammar Rules ──
117
+ lines.push("## 1. Grammar Rules");
118
+ lines.push("");
119
+ lines.push("Every semantic token follows a strict slash-delimited grammar. There are two patterns:");
120
+ lines.push("");
121
+ lines.push("### Semantic Token");
122
+ lines.push("```");
123
+ lines.push(GRAMMAR.pattern);
124
+ lines.push("```");
125
+ lines.push("");
126
+ lines.push("### Component Alias Token");
127
+ lines.push("```");
128
+ lines.push(GRAMMAR.componentPattern);
129
+ lines.push("```");
130
+ lines.push("");
131
+ lines.push("**Rules:**");
132
+ lines.push("- All segments are **lowercase**, **kebab-case** where multi-word");
133
+ lines.push("- The separator is always `/` (forward slash)");
134
+ lines.push("- Segments in `[brackets]` are optional — omit them entirely, don't leave blanks");
135
+ lines.push("- A `semantic` prefix between category and concept is used in file organization (e.g. `color/semantic/actions/...`)");
136
+ lines.push("");
137
+ lines.push("---");
138
+ lines.push("");
139
+
140
+ // ── 2. Allowed Values ──
141
+ lines.push("## 2. Allowed Values per Segment");
142
+ lines.push("");
143
+
144
+ // Categories
145
+ lines.push("### Categories");
146
+ lines.push("");
147
+ lines.push("| Category | When to use |");
148
+ lines.push("|----------|-------------|");
149
+ lines.push("| `color` | Fill, text, icon, border, and ring colors |");
150
+ lines.push("| `radius` | Corner rounding |");
151
+ lines.push("| `space` | Padding (inset) and gap between elements |");
152
+ lines.push("| `shadow` | Box shadow / elevation |");
153
+ lines.push("| `border` | Border shorthand (color + width combined) |");
154
+ lines.push("| `border-width` | Stroke thickness only |");
155
+ lines.push("| `opacity` | Transparency levels |");
156
+ lines.push("| `typography` | Font size, weight, line-height, letter-spacing |");
157
+ lines.push("| `motion` | Duration and easing curves |");
158
+ lines.push("| `z-index` | Stacking order |");
159
+ lines.push("| `icon-size` | Icon dimensions |");
160
+ lines.push("");
161
+
162
+ // Properties
163
+ lines.push("### Properties");
164
+ lines.push("");
165
+ lines.push("| Property | Typical categories | Meaning |");
166
+ lines.push("|----------|--------------------|---------|");
167
+ lines.push("| `background` / `bg` | color | Fill color |");
168
+ lines.push("| `text` | color | Text / label color |");
169
+ lines.push("| `icon` | color | Icon foreground color |");
170
+ lines.push("| `border` | color, border | Border / stroke color |");
171
+ lines.push("| `ring` | color | Focus ring color |");
172
+ lines.push("| `shadow` | shadow | Box shadow value |");
173
+ lines.push("| `inset` | space | Inner padding |");
174
+ lines.push("| `gap` | space | Spacing between children |");
175
+ lines.push("| `corner-radius` | radius | Border radius |");
176
+ lines.push("| `font-size` | typography | Type scale |");
177
+ lines.push("| `font-weight` | typography | Weight (regular, bold, etc.) |");
178
+ lines.push("| `line-height` | typography | Leading |");
179
+ lines.push("| `letter-spacing` | typography | Tracking |");
180
+ lines.push("| `duration` | motion | Animation / transition time |");
181
+ lines.push("| `easing` | motion | Timing function |");
182
+ lines.push("| `foreground` | color | General foreground (icons, illustrations) |");
183
+ lines.push("| `indicator` | color | Active/progress indicator |");
184
+ lines.push("| `backdrop` | opacity | Overlay backdrop opacity |");
185
+ lines.push("");
186
+
187
+ // States
188
+ lines.push("### States");
189
+ lines.push("");
190
+ lines.push("| State | Meaning |");
191
+ lines.push("|-------|---------|");
192
+ lines.push("| `default` | Resting / idle state |");
193
+ lines.push("| `hover` | Pointer over the element |");
194
+ lines.push("| `active` / `pressed` | During click or tap |");
195
+ lines.push("| `focus` | Keyboard or programmatic focus |");
196
+ lines.push("| `disabled` | Non-interactive |");
197
+ lines.push("| `selected` | Chosen item in a group |");
198
+ lines.push("| `checked` | Toggle / checkbox is on |");
199
+ lines.push("| `indeterminate` | Partially checked |");
200
+ lines.push("| `on` / `off` | Binary switch state |");
201
+ lines.push("| `error` | Validation failure |");
202
+ lines.push("| `success` | Validation pass or positive feedback |");
203
+ lines.push("| `warning` | Caution state |");
204
+ lines.push("| `loading` | In-progress / skeleton |");
205
+ lines.push("| `visited` | Previously followed link |");
206
+ lines.push("");
207
+
208
+ // Concepts
209
+ lines.push("### Concepts");
210
+ lines.push("");
211
+ lines.push("| Concept | Purpose | Example components |");
212
+ lines.push("|---------|---------|-------------------|");
213
+ for (const concept of CONCEPT_TAXONOMY) {
214
+ const forms = concept.typicalForms.slice(0, 4).join(", ") || "—";
215
+ lines.push(`| \`${concept.id}\` | ${concept.purpose.split("—")[0].trim()} | ${forms} |`);
216
+ }
217
+ lines.push("");
218
+ lines.push("---");
219
+ lines.push("");
220
+
221
+ // ── 3. Worked Examples by Concept ──
222
+ lines.push("## 3. Worked Examples by Concept");
223
+ lines.push("");
224
+
225
+ // Group concepts by category for readability
226
+ const conceptGroups: Record<string, ConceptDefinition[]> = {
227
+ "Interactive": CONCEPT_TAXONOMY.filter((c) => ["action", "field", "selection"].includes(c.id)),
228
+ "Containers": CONCEPT_TAXONOMY.filter((c) => ["surface", "float", "modal"].includes(c.id)),
229
+ "Feedback": CONCEPT_TAXONOMY.filter((c) => ["feedback", "progress", "status"].includes(c.id)),
230
+ "Navigation": CONCEPT_TAXONOMY.filter((c) => ["navigation", "chip", "badge"].includes(c.id)),
231
+ "Content": CONCEPT_TAXONOMY.filter((c) => ["text", "icon", "data-display", "profile"].includes(c.id)),
232
+ "Overlay & System": CONCEPT_TAXONOMY.filter((c) => ["tooltip", "focus", "elevation", "layout", "motion", "skeleton", "toggles", "utility", "decorative"].includes(c.id)),
233
+ };
234
+
235
+ for (const [groupName, concepts] of Object.entries(conceptGroups)) {
236
+ lines.push(`### ${groupName}`);
237
+ lines.push("");
238
+
239
+ for (const concept of concepts) {
240
+ const examples = buildWorkedExamples(concept);
241
+ if (examples.length === 0) continue;
242
+
243
+ lines.push(`#### \`${concept.id}\``);
244
+ lines.push("");
245
+
246
+ // States and variants available
247
+ if (concept.validVariants.length > 0) {
248
+ lines.push(`- **Variants:** ${concept.validVariants.join(", ")}`);
249
+ }
250
+ if (concept.validStates.length > 0) {
251
+ lines.push(`- **States:** ${concept.validStates.join(", ")}`);
252
+ }
253
+ lines.push("");
254
+
255
+ lines.push("```");
256
+ for (const ex of examples) {
257
+ lines.push(ex);
258
+ }
259
+ lines.push("```");
260
+ lines.push("");
261
+ }
262
+ }
263
+
264
+ lines.push("---");
265
+ lines.push("");
266
+
267
+ // ── 4. Component Alias Examples ──
268
+ lines.push("## 4. Component Alias Tokens");
269
+ lines.push("");
270
+ lines.push("Component aliases map a specific component to an underlying semantic token.");
271
+ lines.push("They follow the component pattern:");
272
+ lines.push("");
273
+ lines.push("```");
274
+ lines.push(GRAMMAR.componentPattern);
275
+ lines.push("```");
276
+ lines.push("");
277
+ lines.push("**Examples:**");
278
+ lines.push("");
279
+ lines.push("```");
280
+ lines.push("component/button/color/background/default → resolves to color/semantic/actions/primary/bg/default");
281
+ lines.push("component/button/icon-slot/color/icon/default → resolves to color/semantic/icon/on-color");
282
+ lines.push("component/button/primary/color/background/hover → resolves to color/semantic/actions/primary/bg/hover");
283
+ lines.push("component/button/radius/corner-radius/default → resolves to radius/semantic/control/default");
284
+ lines.push("component/input/color/border/focus → resolves to color/semantic/border/focus");
285
+ lines.push("component/card/shadow/shadow/default → resolves to elevation/semantic/shadow/md");
286
+ lines.push("```");
287
+ lines.push("");
288
+ lines.push("**Rules for component aliases:**");
289
+ lines.push("- Always start with `component/`");
290
+ lines.push("- Use the component name in lowercase (e.g. `button`, `input`, `card`)");
291
+ lines.push("- Optional `<part>` for sub-elements (e.g. `icon-slot`, `label`, `thumb`)");
292
+ lines.push("- The rest follows the same `<category>/<property>[/<state>]` structure");
293
+ lines.push("- Every component alias should resolve to a semantic token — never to a primitive");
294
+ lines.push("");
295
+ lines.push("---");
296
+ lines.push("");
297
+
298
+ // ── 5. Common Mistakes ──
299
+ lines.push("## 5. Common Mistakes");
300
+ lines.push("");
301
+
302
+ // Pick a few representative concepts for mistake examples
303
+ const mistakeConcepts = ["action", "field", "surface"];
304
+ const allMistakes: Array<{ concept: string; wrong: string; right: string; reason: string }> = [];
305
+
306
+ for (const id of mistakeConcepts) {
307
+ const concept = CONCEPT_TAXONOMY.find((c) => c.id === id);
308
+ if (!concept) continue;
309
+ const mistakes = buildMistakeExamples(concept);
310
+ for (const m of mistakes) {
311
+ allMistakes.push({ concept: id, ...m });
312
+ }
313
+ }
314
+
315
+ // Deduplicate by reason
316
+ const seenReasons = new Set<string>();
317
+ const uniqueMistakes = allMistakes.filter((m) => {
318
+ if (seenReasons.has(m.reason)) return false;
319
+ seenReasons.add(m.reason);
320
+ return true;
321
+ });
322
+
323
+ lines.push("| # | Wrong | Right | Why |");
324
+ lines.push("|---|-------|-------|-----|");
325
+ uniqueMistakes.forEach((m, i) => {
326
+ lines.push(`| ${i + 1} | \`${m.wrong}\` | \`${m.right}\` | ${m.reason} |`);
327
+ });
328
+ lines.push("");
329
+ lines.push("**Additional pitfalls:**");
330
+ lines.push("- Do not use a primitive token directly in a component — always alias through a semantic token");
331
+ lines.push("- Do not invent new states — use only the states listed in this guide for each concept");
332
+ lines.push("- Do not combine variant and state in one segment (e.g. `primary-hover`) — they are separate segments");
333
+ lines.push("- Do not add sizing (sm/md/lg) as a variant for color tokens — sizing belongs in `space` or `typography` categories");
334
+ lines.push("");
335
+ lines.push("---");
336
+ lines.push("");
337
+
338
+ // ── 6. Your File's Token Coverage ──
339
+ lines.push("## 6. Your File's Token Coverage");
340
+ lines.push("");
341
+
342
+ // Detect if the file uses a different convention
343
+ const totalExpected = coverage.reduce((sum, c) => sum + c.expectedTokens.length, 0);
344
+ const totalFound = coverage.reduce((sum, c) => sum + c.foundTokens.length, 0);
345
+ const totalFuzzy = coverage.reduce((sum, c) => sum + Object.keys(c.matchedFileTokens).length, 0);
346
+
347
+ if (totalFuzzy > 0) {
348
+ lines.push(`> Your file uses a different naming convention than the grammar above. ${totalFuzzy} token(s) were matched by semantic role rather than exact name.`);
349
+ lines.push("");
350
+ }
351
+
352
+ lines.push(`**Coverage:** ${totalFound} / ${totalExpected} token roles covered`);
353
+ lines.push("");
354
+
355
+ // Show per-concept coverage with matched file tokens
356
+ for (const c of coverage) {
357
+ if (c.expectedTokens.length === 0) continue;
358
+
359
+ const icon = c.status === "full" ? "✅" : c.status === "partial" ? "🟡" : "❌";
360
+ lines.push(`### ${icon} ${c.conceptName} (${c.foundTokens.length}/${c.expectedTokens.length})`);
361
+ lines.push("");
362
+
363
+ if (c.expectedTokens.length > 0) {
364
+ lines.push("| Role (expected path) | Status | Your file token |");
365
+ lines.push("|----------------------|--------|-----------------|");
366
+
367
+ for (const token of c.expectedTokens) {
368
+ const found = c.foundTokens.includes(token);
369
+ const fileToken = c.matchedFileTokens[token];
370
+ const status = found ? "✅" : "❌";
371
+ const fileCol = fileToken ? `\`${fileToken}\`` : (found ? "exact match" : "—");
372
+ lines.push(`| \`${token}\` | ${status} | ${fileCol} |`);
373
+ }
374
+ lines.push("");
375
+ }
376
+ }
377
+
378
+ lines.push("---");
379
+ lines.push("");
380
+
381
+ // ── 7. Quick Decision Tree ──
382
+ lines.push("## 7. Quick Decision Tree");
383
+ lines.push("");
384
+ lines.push("Use this flowchart when naming a new token:");
385
+ lines.push("");
386
+ lines.push("```");
387
+ lines.push("1. What TYPE of value is it?");
388
+ lines.push(" → color, radius, space, shadow, etc. → that's your CATEGORY");
389
+ lines.push("");
390
+ lines.push("2. What UI CONCEPT does it serve?");
391
+ lines.push(" → button = action, input = field, card = surface → that's your CONCEPT");
392
+ lines.push("");
393
+ lines.push("3. Is there a visual VARIANT?");
394
+ lines.push(" → primary, secondary, ghost, outlined → add as VARIANT segment");
395
+ lines.push(" → no variant → skip this segment");
396
+ lines.push("");
397
+ lines.push("4. What PART of the component?");
398
+ lines.push(" → background, text, icon, border, ring → that's your PROPERTY");
399
+ lines.push("");
400
+ lines.push("5. What interaction STATE?");
401
+ lines.push(" → default, hover, focus, disabled → add as STATE segment");
402
+ lines.push(" → resting / no specific state → use 'default' or omit");
403
+ lines.push("```");
404
+ lines.push("");
405
+ lines.push("**Result:** `<category>/<concept>[/<variant>]/<property>[/<state>]`");
406
+ lines.push("");
407
+
408
+ return lines.join("\n");
409
+ }