@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.
- package/LICENSE +26 -0
- package/README.md +327 -0
- package/bin/cli.js +859 -0
- package/design-bridge/.env.example +5 -0
- package/design-bridge/bridge.js +196 -0
- package/design-bridge/lib/assets.js +367 -0
- package/design-bridge/lib/prompt.js +85 -0
- package/design-bridge/lib/server.js +66 -0
- package/design-bridge/lib/stitch.js +37 -0
- package/design-bridge/lib/tokens.js +82 -0
- package/design-bridge/package-lock.json +579 -0
- package/design-bridge/package.json +19 -0
- package/figma-bridge-plugin/README.md +97 -0
- package/figma-bridge-plugin/anthropic-chat-runner.js +192 -0
- package/figma-bridge-plugin/bridge-relay.js +2363 -0
- package/figma-bridge-plugin/chat-runner.js +459 -0
- package/figma-bridge-plugin/code.js +1528 -0
- package/figma-bridge-plugin/codex-runner.js +505 -0
- package/figma-bridge-plugin/component-schemas.js +110 -0
- package/figma-bridge-plugin/content-context.js +869 -0
- package/figma-bridge-plugin/create-button.js +216 -0
- package/figma-bridge-plugin/gemini-cli-runner.js +291 -0
- package/figma-bridge-plugin/gemini-runner.js +187 -0
- package/figma-bridge-plugin/html-to-figma.js +927 -0
- package/figma-bridge-plugin/knowledge-hub/.gitkeep +0 -0
- package/figma-bridge-plugin/knowledge-hub/uspec-references/anatomy-spec.md +159 -0
- package/figma-bridge-plugin/knowledge-hub/uspec-references/api-spec.md +162 -0
- package/figma-bridge-plugin/knowledge-hub/uspec-references/color-spec.md +148 -0
- package/figma-bridge-plugin/knowledge-hub/uspec-references/full-spec-template.md +314 -0
- package/figma-bridge-plugin/knowledge-hub/uspec-references/property-spec.md +175 -0
- package/figma-bridge-plugin/knowledge-hub/uspec-references/screen-reader-spec.md +180 -0
- package/figma-bridge-plugin/knowledge-hub/uspec-references/structure-spec.md +165 -0
- package/figma-bridge-plugin/manifest.json +21 -0
- package/figma-bridge-plugin/package-lock.json +1936 -0
- package/figma-bridge-plugin/package.json +20 -0
- package/figma-bridge-plugin/perplexity-runner.js +188 -0
- package/figma-bridge-plugin/references/SKILL.md +178 -0
- package/figma-bridge-plugin/references/anatomy-spec.md +159 -0
- package/figma-bridge-plugin/references/api-spec.md +162 -0
- package/figma-bridge-plugin/references/color-spec.md +148 -0
- package/figma-bridge-plugin/references/full-spec-template.md +314 -0
- package/figma-bridge-plugin/references/property-spec.md +175 -0
- package/figma-bridge-plugin/references/screen-reader-spec.md +180 -0
- package/figma-bridge-plugin/references/structure-spec.md +165 -0
- package/figma-bridge-plugin/shared-prompt-config.js +604 -0
- package/figma-bridge-plugin/spec-helpers/build-table.js +269 -0
- package/figma-bridge-plugin/spec-helpers/classify-elements.js +189 -0
- package/figma-bridge-plugin/spec-helpers/index.js +35 -0
- package/figma-bridge-plugin/spec-helpers/parse-figma-link.js +49 -0
- package/figma-bridge-plugin/spec-helpers/position-markers.js +158 -0
- package/figma-bridge-plugin/stitch-auth.js +322 -0
- package/figma-bridge-plugin/stitch-runner.js +1427 -0
- package/figma-bridge-plugin/token-resolver.js +107 -0
- package/figma-bridge-plugin/ui.html +4467 -0
- package/figma-intelligence-layer/.env.example +39 -0
- package/figma-intelligence-layer/docs/local-image-generation.md +60 -0
- package/figma-intelligence-layer/examples/comfyui-workflow-template.example.json +101 -0
- package/figma-intelligence-layer/jest.config.js +14 -0
- package/figma-intelligence-layer/mcp-config.json +19 -0
- package/figma-intelligence-layer/package-lock.json +5892 -0
- package/figma-intelligence-layer/package.json +48 -0
- package/figma-intelligence-layer/scripts/setup-comfyui-local.sh +67 -0
- package/figma-intelligence-layer/scripts/start-comfyui.sh +33 -0
- package/figma-intelligence-layer/src/index.ts +2233 -0
- package/figma-intelligence-layer/src/shared/auto-layout-validator.ts +404 -0
- package/figma-intelligence-layer/src/shared/cache.ts +187 -0
- package/figma-intelligence-layer/src/shared/color-operations.ts +533 -0
- package/figma-intelligence-layer/src/shared/color-utils.ts +138 -0
- package/figma-intelligence-layer/src/shared/component-script-builder.ts +413 -0
- package/figma-intelligence-layer/src/shared/component-templates.ts +2767 -0
- package/figma-intelligence-layer/src/shared/concept-taxonomy.ts +694 -0
- package/figma-intelligence-layer/src/shared/decision-log.ts +128 -0
- package/figma-intelligence-layer/src/shared/design-system-context.ts +568 -0
- package/figma-intelligence-layer/src/shared/design-system-intelligence.ts +131 -0
- package/figma-intelligence-layer/src/shared/design-system-matcher.ts +184 -0
- package/figma-intelligence-layer/src/shared/design-system-normalizers.ts +196 -0
- package/figma-intelligence-layer/src/shared/design-system-tokens.ts +295 -0
- package/figma-intelligence-layer/src/shared/dtcg-validator.ts +530 -0
- package/figma-intelligence-layer/src/shared/enrichment-pipeline.ts +671 -0
- package/figma-intelligence-layer/src/shared/figma-bridge.ts +1408 -0
- package/figma-intelligence-layer/src/shared/font-config.ts +126 -0
- package/figma-intelligence-layer/src/shared/icon-catalog.ts +360 -0
- package/figma-intelligence-layer/src/shared/icon-fetch.ts +80 -0
- package/figma-intelligence-layer/src/shared/prototype-script-builder.ts +162 -0
- package/figma-intelligence-layer/src/shared/response-compression.ts +440 -0
- package/figma-intelligence-layer/src/shared/semantic-token-catalog.ts +324 -0
- package/figma-intelligence-layer/src/shared/token-binder.ts +505 -0
- package/figma-intelligence-layer/src/shared/token-math.ts +427 -0
- package/figma-intelligence-layer/src/shared/token-naming.ts +468 -0
- package/figma-intelligence-layer/src/shared/token-utils.ts +420 -0
- package/figma-intelligence-layer/src/shared/types.ts +346 -0
- package/figma-intelligence-layer/src/shared/typography-presets.ts +94 -0
- package/figma-intelligence-layer/src/shared/unsplash.ts +165 -0
- package/figma-intelligence-layer/src/shared/vision-client.ts +607 -0
- package/figma-intelligence-layer/src/shared/vision-provider-anthropic.ts +334 -0
- package/figma-intelligence-layer/src/shared/vision-provider-openai.ts +446 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/a11y-annotate-handler.ts +782 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/a11y-annotate-renderer.ts +496 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/a11y-annotation-kit.ts +230 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/colorblind-sim.ts +66 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/index.ts +810 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/keyboard-sr-order-analyzer.ts +1191 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/keyboard-sr-order-figma-page.ts +1346 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/keyboard-sr-order-handler.ts +148 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/vpat-figma-page.ts +499 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/vpat-report.ts +910 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/wcag-checker.ts +989 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/a11y-audit/wcag-criteria.ts +1160 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/design-from-ref/index.ts +424 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/component-recognizer.ts +38 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/ds-matcher.ts +111 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/font-matcher.ts +114 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/icon-resolver.ts +103 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/index.ts +1060 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/layout-segmenter.ts +18 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/token-inferencer.ts +39 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/screen-cloner/vision-pipeline.ts +58 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/sketch-to-design/index.ts +298 -0
- package/figma-intelligence-layer/src/tools/phase1-vision/visual-audit/index.ts +197 -0
- package/figma-intelligence-layer/src/tools/phase2-accuracy/component-audit/index.ts +494 -0
- package/figma-intelligence-layer/src/tools/phase2-accuracy/intent-translator/index.ts +356 -0
- package/figma-intelligence-layer/src/tools/phase2-accuracy/layout-intelligence/container-patterns.ts +123 -0
- package/figma-intelligence-layer/src/tools/phase2-accuracy/layout-intelligence/index.ts +663 -0
- package/figma-intelligence-layer/src/tools/phase2-accuracy/lint-rules/built-in-rules.yaml +56 -0
- package/figma-intelligence-layer/src/tools/phase2-accuracy/lint-rules/index.ts +614 -0
- package/figma-intelligence-layer/src/tools/phase2-accuracy/lint-rules/rule-engine.ts +113 -0
- package/figma-intelligence-layer/src/tools/phase2-accuracy/theme-generator/color-theory.ts +178 -0
- package/figma-intelligence-layer/src/tools/phase2-accuracy/theme-generator/index.ts +470 -0
- package/figma-intelligence-layer/src/tools/phase2-accuracy/variant-expander/index.ts +429 -0
- package/figma-intelligence-layer/src/tools/phase2-accuracy/variant-expander/token-override-maps.ts +226 -0
- package/figma-intelligence-layer/src/tools/phase3-generation/ai-image-insert/index.ts +535 -0
- package/figma-intelligence-layer/src/tools/phase3-generation/component-archaeologist/index.ts +660 -0
- package/figma-intelligence-layer/src/tools/phase3-generation/component-archaeologist/pattern-fingerprints.ts +209 -0
- package/figma-intelligence-layer/src/tools/phase3-generation/composition-builder/index.ts +540 -0
- package/figma-intelligence-layer/src/tools/phase3-generation/figma-animated-build.ts +391 -0
- package/figma-intelligence-layer/src/tools/phase3-generation/page-architect/index.ts +2019 -0
- package/figma-intelligence-layer/src/tools/phase3-generation/page-architect/screen-templates.ts +131 -0
- package/figma-intelligence-layer/src/tools/phase3-generation/prototype-map/index.ts +381 -0
- package/figma-intelligence-layer/src/tools/phase3-generation/prototype-wire/index.ts +565 -0
- package/figma-intelligence-layer/src/tools/phase3-generation/swarm-build/index.ts +764 -0
- package/figma-intelligence-layer/src/tools/phase3-generation/system-drift/index.ts +535 -0
- package/figma-intelligence-layer/src/tools/phase3-generation/unsplash-search/index.ts +84 -0
- package/figma-intelligence-layer/src/tools/phase3-generation/url-to-frame/index.ts +401 -0
- package/figma-intelligence-layer/src/tools/phase4-sync/animation-specifier/code-generators/css-animations.ts +68 -0
- package/figma-intelligence-layer/src/tools/phase4-sync/animation-specifier/code-generators/framer-motion.ts +78 -0
- package/figma-intelligence-layer/src/tools/phase4-sync/animation-specifier/code-generators/swift-animations.ts +93 -0
- package/figma-intelligence-layer/src/tools/phase4-sync/animation-specifier/index.ts +596 -0
- package/figma-intelligence-layer/src/tools/phase4-sync/ci-check/index.ts +462 -0
- package/figma-intelligence-layer/src/tools/phase4-sync/export-tokens/index.ts +1470 -0
- package/figma-intelligence-layer/src/tools/phase4-sync/generate-component-code/index.ts +829 -0
- package/figma-intelligence-layer/src/tools/phase4-sync/handoff-spec/index.ts +702 -0
- package/figma-intelligence-layer/src/tools/phase4-sync/icon-library-sync/index.ts +483 -0
- package/figma-intelligence-layer/src/tools/phase4-sync/sync-from-code/index.ts +501 -0
- package/figma-intelligence-layer/src/tools/phase4-sync/sync-from-code/storybook-parser.ts +106 -0
- package/figma-intelligence-layer/src/tools/phase4-sync/watch-docs/index.ts +676 -0
- package/figma-intelligence-layer/src/tools/phase4-sync/webhook-listener/index.ts +560 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/apg-doc/index.ts +1043 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/component-detection.ts +620 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/anatomy.ts +331 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/color-tokens.ts +77 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/properties.ts +54 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/snapshot.ts +287 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/spacing.ts +71 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/states.ts +43 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/extractors/typography.ts +71 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/index.ts +221 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/_default.ts +166 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/accordion.ts +232 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/alert.ts +234 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/avatar-group.ts +270 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/avatar.ts +249 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/badge.ts +231 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/banner.ts +293 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/breadcrumb.ts +240 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/button.ts +243 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/calendar.ts +307 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/card.ts +143 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/checkbox.ts +227 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/chip.ts +233 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/combobox.ts +282 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/datepicker.ts +276 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/divider.ts +223 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/drawer.ts +255 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/dropdown-menu.ts +289 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/empty-state.ts +261 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/file-uploader.ts +290 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/form.ts +265 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/grid.ts +238 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/icon.ts +255 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/index.ts +128 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/inline-edit.ts +286 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/inline-message.ts +255 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/input.ts +330 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/link.ts +247 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/list.ts +250 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/menu.ts +247 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/modal.ts +144 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/navbar.ts +264 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/navigation.ts +251 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/number-input.ts +261 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/pagination.ts +248 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/popover.ts +270 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/progress.ts +251 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/radio.ts +142 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/range-slider.ts +282 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/rating.ts +250 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/search.ts +258 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/segmented-control.ts +265 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/select.ts +319 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/skeleton.ts +256 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/slider.ts +232 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/spinner.ts +239 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/status-dot.ts +252 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/stepper.ts +270 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/table.ts +244 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/tabs.ts +143 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/tag.ts +243 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/textarea.ts +259 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/time-picker.ts +293 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/toast.ts +144 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/toggle.ts +289 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/toolbar.ts +267 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/tooltip.ts +232 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/treeview.ts +257 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/knowledge/typography.ts +319 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/legacy-compat.ts +121 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/renderers/anatomy-diagram.ts +430 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/renderers/figma-page.ts +312 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/renderers/json.ts +129 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/renderers/markdown.ts +78 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/renderers/visual-doc.ts +2333 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/accessibility.ts +100 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/anatomy.ts +32 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/color-tokens.ts +59 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/content-guidance.ts +18 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/design-tokens.ts +53 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/interaction-rules.ts +19 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/overview.ts +91 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/properties-api.ts +71 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/qa-criteria.ts +19 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/related-components.ts +110 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/responsive.ts +19 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/size-specs.ts +67 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/spacing-structure.ts +58 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/state-specs.ts +79 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/states.ts +50 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/type-hierarchy.ts +33 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/typography.ts +55 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/usage-guidelines.ts +73 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/sections/variants.ts +81 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec/types.ts +409 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec-sheet/index.ts +198 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec-sheet/renderer.ts +701 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/component-spec-sheet/types.ts +88 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/decision-log/index.ts +135 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/design-decision-log/index.ts +491 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/ds-primitives/index.ts +416 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/ds-scaffolder/index.ts +722 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/ds-variables/index.ts +449 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/health-report/index.ts +393 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/taxonomy-docs/index.ts +406 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/taxonomy-docs/renderers/figma-page.ts +292 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/taxonomy-docs/renderers/json.ts +24 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/taxonomy-docs/renderers/markdown.ts +172 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/taxonomy-docs/renderers/naming-guide.ts +409 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/token-analytics/index.ts +594 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/token-docs/index.ts +710 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/token-migrate/index.ts +458 -0
- package/figma-intelligence-layer/src/tools/phase5-governance/token-naming/index.ts +134 -0
- package/figma-intelligence-layer/tests/apg-doc.test.ts +101 -0
- package/figma-intelligence-layer/tests/design-system-context.test.ts +152 -0
- package/figma-intelligence-layer/tests/design-system-matcher.test.ts +144 -0
- package/figma-intelligence-layer/tests/figma-bridge.test.ts +83 -0
- package/figma-intelligence-layer/tests/generate-image-and-insert.test.ts +56 -0
- package/figma-intelligence-layer/tests/screen-cloner-regression.test.ts +69 -0
- package/figma-intelligence-layer/tests/smoke.test.ts +174 -0
- package/figma-intelligence-layer/tests/spec-generator.test.ts +127 -0
- package/figma-intelligence-layer/tests/token-migrate.test.ts +21 -0
- package/figma-intelligence-layer/tests/token-naming.test.ts +30 -0
- package/figma-intelligence-layer/tsconfig.json +19 -0
- package/package.json +35 -0
- package/scripts/clean-existing-chunks.js +179 -0
- package/scripts/connect-ai-tool.js +490 -0
- package/scripts/convert-hub-pdfs.js +425 -0
- package/scripts/figma-mcp-status.js +349 -0
- package/scripts/register-codex-mcp.js +96 -0
|
@@ -0,0 +1,535 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
2
|
+
// System Drift
|
|
3
|
+
// Compares design-token variables from a canonical Figma file against one or
|
|
4
|
+
// more target files using the Figma REST API. Calculates a drift score per
|
|
5
|
+
// file, categorises each deviation, and formats the results as a detailed
|
|
6
|
+
// report, inline Figma annotation JSON, or a PR-comment markdown block.
|
|
7
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
8
|
+
|
|
9
|
+
import { DriftReport, TokenDrift } from "../../../shared/types.js";
|
|
10
|
+
import { decisionLog } from "../../../shared/decision-log.js";
|
|
11
|
+
|
|
12
|
+
// ─── Public types ─────────────────────────────────────────────────────────────
|
|
13
|
+
|
|
14
|
+
export interface SystemDriftArgs {
|
|
15
|
+
canonicalFileKey: string;
|
|
16
|
+
targetFileKeys: string[];
|
|
17
|
+
tokenTypes?: string[];
|
|
18
|
+
threshold?: number;
|
|
19
|
+
outputFormat: "report" | "annotations" | "pr-comment";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface DriftSummary {
|
|
23
|
+
filesChecked: number;
|
|
24
|
+
healthyFiles: number;
|
|
25
|
+
warningFiles: number;
|
|
26
|
+
criticalFiles: number;
|
|
27
|
+
totalTokensCompared: number;
|
|
28
|
+
totalDriftingTokens: number;
|
|
29
|
+
overallDriftScore: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface SystemDriftResult {
|
|
33
|
+
reports: DriftReport[];
|
|
34
|
+
summary: DriftSummary;
|
|
35
|
+
formattedOutput: string;
|
|
36
|
+
logEntryId: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// ─── Figma REST API types ──────────────────────────────────────────────────────
|
|
40
|
+
|
|
41
|
+
interface FigmaVariableColor {
|
|
42
|
+
r: number;
|
|
43
|
+
g: number;
|
|
44
|
+
b: number;
|
|
45
|
+
a: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface FigmaVariableAlias {
|
|
49
|
+
type: "VARIABLE_ALIAS";
|
|
50
|
+
id: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
type FigmaVariableValue =
|
|
54
|
+
| number
|
|
55
|
+
| string
|
|
56
|
+
| boolean
|
|
57
|
+
| FigmaVariableColor
|
|
58
|
+
| FigmaVariableAlias;
|
|
59
|
+
|
|
60
|
+
interface FigmaVariable {
|
|
61
|
+
id: string;
|
|
62
|
+
name: string;
|
|
63
|
+
resolvedType: string;
|
|
64
|
+
valuesByMode: Record<string, FigmaVariableValue>;
|
|
65
|
+
description?: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface FigmaVariableCollection {
|
|
69
|
+
id: string;
|
|
70
|
+
name: string;
|
|
71
|
+
modes: Array<{ modeId: string; name: string }>;
|
|
72
|
+
variableIds: string[];
|
|
73
|
+
defaultModeId: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
interface FigmaVariablesResponse {
|
|
77
|
+
meta: {
|
|
78
|
+
variables: Record<string, FigmaVariable>;
|
|
79
|
+
variableCollections: Record<string, FigmaVariableCollection>;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// ─── Flat token map ───────────────────────────────────────────────────────────
|
|
84
|
+
|
|
85
|
+
interface FlatToken {
|
|
86
|
+
name: string;
|
|
87
|
+
type: string;
|
|
88
|
+
value: string;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// ─── REST API fetch ───────────────────────────────────────────────────────────
|
|
92
|
+
|
|
93
|
+
function normalizeVariableValue(value: FigmaVariableValue): string {
|
|
94
|
+
if (typeof value === "number") {
|
|
95
|
+
return String(Math.round(value * 1000) / 1000);
|
|
96
|
+
}
|
|
97
|
+
if (typeof value === "string") return value;
|
|
98
|
+
if (typeof value === "boolean") return String(value);
|
|
99
|
+
if (typeof value === "object" && value !== null) {
|
|
100
|
+
if ("r" in value && "g" in value && "b" in value) {
|
|
101
|
+
const r = Math.round((value as FigmaVariableColor).r * 255);
|
|
102
|
+
const g = Math.round((value as FigmaVariableColor).g * 255);
|
|
103
|
+
const b = Math.round((value as FigmaVariableColor).b * 255);
|
|
104
|
+
return `#${r.toString(16).padStart(2, "0")}${g.toString(16).padStart(2, "0")}${b.toString(16).padStart(2, "0")}`;
|
|
105
|
+
}
|
|
106
|
+
if ("type" in value && (value as FigmaVariableAlias).type === "VARIABLE_ALIAS") {
|
|
107
|
+
return `alias:${(value as FigmaVariableAlias).id}`;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return JSON.stringify(value);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async function fetchFileVariables(fileKey: string): Promise<FlatToken[]> {
|
|
114
|
+
const token = process.env.FIGMA_ACCESS_TOKEN;
|
|
115
|
+
if (!token) {
|
|
116
|
+
throw new Error("systemDrift: FIGMA_ACCESS_TOKEN environment variable is not set.");
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const response = await fetch(
|
|
120
|
+
`https://api.figma.com/v1/files/${fileKey}/variables/local`,
|
|
121
|
+
{ headers: { "X-Figma-Token": token } }
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
if (!response.ok) {
|
|
125
|
+
const body = await response.text().catch(() => "");
|
|
126
|
+
throw new Error(
|
|
127
|
+
`systemDrift: Figma API error for file "${fileKey}" — HTTP ${response.status}: ${body.slice(0, 200)}`
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const data = (await response.json()) as FigmaVariablesResponse;
|
|
132
|
+
const { variables, variableCollections } = data.meta;
|
|
133
|
+
const flatTokens: FlatToken[] = [];
|
|
134
|
+
|
|
135
|
+
for (const variable of Object.values(variables ?? {})) {
|
|
136
|
+
// Resolve which collection owns this variable to get the default mode
|
|
137
|
+
let defaultModeId: string | undefined;
|
|
138
|
+
for (const col of Object.values(variableCollections ?? {})) {
|
|
139
|
+
if (col.variableIds.includes(variable.id)) {
|
|
140
|
+
defaultModeId = col.defaultModeId;
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const rawValue =
|
|
146
|
+
defaultModeId && variable.valuesByMode[defaultModeId] !== undefined
|
|
147
|
+
? variable.valuesByMode[defaultModeId]
|
|
148
|
+
: Object.values(variable.valuesByMode)[0];
|
|
149
|
+
|
|
150
|
+
flatTokens.push({
|
|
151
|
+
name: variable.name,
|
|
152
|
+
type: variable.resolvedType,
|
|
153
|
+
value: rawValue !== undefined ? normalizeVariableValue(rawValue) : "null",
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return flatTokens;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// ─── Drift detection ──────────────────────────────────────────────────────────
|
|
161
|
+
|
|
162
|
+
function hexDistance(a: string, b: string): number {
|
|
163
|
+
const clean = (s: string) => s.replace(/^#/, "").toLowerCase().padEnd(6, "0");
|
|
164
|
+
const ca = clean(a);
|
|
165
|
+
const cb = clean(b);
|
|
166
|
+
let diff = 0;
|
|
167
|
+
for (let i = 0; i < Math.max(ca.length, cb.length); i++) {
|
|
168
|
+
if ((ca[i] ?? "") !== (cb[i] ?? "")) diff++;
|
|
169
|
+
}
|
|
170
|
+
return diff;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function isHexColor(value: string): boolean {
|
|
174
|
+
return /^#[0-9a-fA-F]{3,8}$/.test(value);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function computeInstanceCount(tokenName: string): number {
|
|
178
|
+
// Heuristic: deeply nested token names imply fewer cross-file usages
|
|
179
|
+
const depth = (tokenName.match(/\//g) ?? []).length;
|
|
180
|
+
return Math.max(1, Math.round(30 / (depth + 1)));
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function compareTokenSets(
|
|
184
|
+
canonicalTokens: FlatToken[],
|
|
185
|
+
targetTokens: FlatToken[],
|
|
186
|
+
tokenTypeFilter: string[] | undefined
|
|
187
|
+
): TokenDrift[] {
|
|
188
|
+
const violations: TokenDrift[] = [];
|
|
189
|
+
|
|
190
|
+
const shouldInclude = (type: string): boolean => {
|
|
191
|
+
if (!tokenTypeFilter || tokenTypeFilter.length === 0) return true;
|
|
192
|
+
return tokenTypeFilter.some((tf) =>
|
|
193
|
+
type.toLowerCase().includes(tf.toLowerCase())
|
|
194
|
+
);
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
const canonicalMap = new Map(canonicalTokens.map((t) => [t.name, t]));
|
|
198
|
+
const targetMap = new Map(targetTokens.map((t) => [t.name, t]));
|
|
199
|
+
|
|
200
|
+
// Check canonical tokens against target
|
|
201
|
+
for (const [name, canonical] of canonicalMap) {
|
|
202
|
+
if (!shouldInclude(canonical.type)) continue;
|
|
203
|
+
|
|
204
|
+
const target = targetMap.get(name);
|
|
205
|
+
if (!target) {
|
|
206
|
+
violations.push({
|
|
207
|
+
tokenName: name,
|
|
208
|
+
canonicalValue: canonical.value,
|
|
209
|
+
targetValue: "MISSING",
|
|
210
|
+
driftType: "missing",
|
|
211
|
+
severity: "warning",
|
|
212
|
+
instancesAffected: computeInstanceCount(name),
|
|
213
|
+
});
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (canonical.value === target.value) continue;
|
|
218
|
+
|
|
219
|
+
// Hex typo: one character differs
|
|
220
|
+
if (isHexColor(canonical.value) && isHexColor(target.value)) {
|
|
221
|
+
const dist = hexDistance(canonical.value, target.value);
|
|
222
|
+
if (dist === 1) {
|
|
223
|
+
violations.push({
|
|
224
|
+
tokenName: name,
|
|
225
|
+
canonicalValue: canonical.value,
|
|
226
|
+
targetValue: target.value,
|
|
227
|
+
driftType: "typo",
|
|
228
|
+
severity: "warning",
|
|
229
|
+
instancesAffected: computeInstanceCount(name),
|
|
230
|
+
});
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Different value, same name → override
|
|
236
|
+
violations.push({
|
|
237
|
+
tokenName: name,
|
|
238
|
+
canonicalValue: canonical.value,
|
|
239
|
+
targetValue: target.value,
|
|
240
|
+
driftType: "override",
|
|
241
|
+
severity: "critical",
|
|
242
|
+
instancesAffected: computeInstanceCount(name),
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Check target tokens not present in canonical → extra
|
|
247
|
+
for (const [name, target] of targetMap) {
|
|
248
|
+
if (!shouldInclude(target.type)) continue;
|
|
249
|
+
if (!canonicalMap.has(name)) {
|
|
250
|
+
violations.push({
|
|
251
|
+
tokenName: name,
|
|
252
|
+
canonicalValue: "NOT_IN_CANONICAL",
|
|
253
|
+
targetValue: target.value,
|
|
254
|
+
driftType: "extra",
|
|
255
|
+
severity: "warning",
|
|
256
|
+
instancesAffected: computeInstanceCount(name),
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return violations;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// ─── Score classification ─────────────────────────────────────────────────────
|
|
265
|
+
|
|
266
|
+
type DriftCategory = "healthy" | "warning" | "critical";
|
|
267
|
+
|
|
268
|
+
function classifyScore(driftScore: number, threshold: number): DriftCategory {
|
|
269
|
+
const warningThreshold = Math.min(15, threshold);
|
|
270
|
+
if (driftScore <= Math.min(5, threshold * 0.33)) return "healthy";
|
|
271
|
+
if (driftScore <= warningThreshold) return "warning";
|
|
272
|
+
return "critical";
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// ─── Output formatters ────────────────────────────────────────────────────────
|
|
276
|
+
|
|
277
|
+
function formatAsReport(reports: DriftReport[], summary: DriftSummary, threshold: number): string {
|
|
278
|
+
const lines: string[] = [];
|
|
279
|
+
lines.push("# Design System Drift Report");
|
|
280
|
+
lines.push(`Generated: ${new Date().toISOString()}`);
|
|
281
|
+
lines.push("");
|
|
282
|
+
lines.push("## Summary");
|
|
283
|
+
lines.push(`- Files checked: ${summary.filesChecked}`);
|
|
284
|
+
lines.push(
|
|
285
|
+
`- Status: ${summary.healthyFiles} healthy / ${summary.warningFiles} warning / ${summary.criticalFiles} critical`
|
|
286
|
+
);
|
|
287
|
+
lines.push(`- Total tokens compared: ${summary.totalTokensCompared}`);
|
|
288
|
+
lines.push(`- Total drifting tokens: ${summary.totalDriftingTokens}`);
|
|
289
|
+
lines.push(`- Overall drift score: ${summary.overallDriftScore.toFixed(1)}%`);
|
|
290
|
+
lines.push(`- Alert threshold: ${threshold}%`);
|
|
291
|
+
lines.push("");
|
|
292
|
+
|
|
293
|
+
for (const report of reports) {
|
|
294
|
+
const cat = classifyScore(report.driftScore, threshold);
|
|
295
|
+
const statusLabel =
|
|
296
|
+
cat === "healthy" ? "[HEALTHY]" : cat === "warning" ? "[WARNING]" : "[CRITICAL]";
|
|
297
|
+
|
|
298
|
+
lines.push(`## ${statusLabel} ${report.targetFileKey}`);
|
|
299
|
+
lines.push(
|
|
300
|
+
`Drift score: **${report.driftScore.toFixed(1)}%** (${report.driftingTokens}/${report.totalTokens} tokens)`
|
|
301
|
+
);
|
|
302
|
+
lines.push("");
|
|
303
|
+
|
|
304
|
+
if (report.violations.length === 0) {
|
|
305
|
+
lines.push("No violations found.");
|
|
306
|
+
} else {
|
|
307
|
+
lines.push("| Token | Canonical | Target | Type | Severity | Instances |");
|
|
308
|
+
lines.push("|-------|-----------|--------|------|----------|-----------|");
|
|
309
|
+
for (const v of report.violations.slice(0, 30)) {
|
|
310
|
+
lines.push(
|
|
311
|
+
`| ${v.tokenName} | \`${v.canonicalValue}\` | \`${v.targetValue}\` | ${v.driftType} | ${v.severity} | ${v.instancesAffected} |`
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
if (report.violations.length > 30) {
|
|
315
|
+
lines.push(`\n...and ${report.violations.length - 30} more violations`);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
lines.push("");
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
return lines.join("\n");
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function formatAsPrComment(reports: DriftReport[], summary: DriftSummary): string {
|
|
325
|
+
const overallStatus =
|
|
326
|
+
summary.criticalFiles > 0 ? "CRITICAL" : summary.warningFiles > 0 ? "WARNING" : "HEALTHY";
|
|
327
|
+
|
|
328
|
+
const statusBadge =
|
|
329
|
+
overallStatus === "CRITICAL"
|
|
330
|
+
? "[CRITICAL]"
|
|
331
|
+
: overallStatus === "WARNING"
|
|
332
|
+
? "[WARNING]"
|
|
333
|
+
: "[HEALTHY]";
|
|
334
|
+
|
|
335
|
+
const lines: string[] = [];
|
|
336
|
+
lines.push(`## Design System Drift Check ${statusBadge}`);
|
|
337
|
+
lines.push("");
|
|
338
|
+
lines.push(
|
|
339
|
+
`Compared **${summary.filesChecked}** file(s) against the canonical design system.`
|
|
340
|
+
);
|
|
341
|
+
lines.push(
|
|
342
|
+
`Overall drift: **${summary.overallDriftScore.toFixed(1)}%** (${summary.totalDriftingTokens} of ${summary.totalTokensCompared} tokens)`
|
|
343
|
+
);
|
|
344
|
+
lines.push("");
|
|
345
|
+
lines.push("| File | Drift | Status |");
|
|
346
|
+
lines.push("|------|-------|--------|");
|
|
347
|
+
for (const r of reports) {
|
|
348
|
+
const cat = r.driftScore < 5 ? "HEALTHY" : r.driftScore < 15 ? "WARNING" : "CRITICAL";
|
|
349
|
+
lines.push(`| \`${r.targetFileKey}\` | ${r.driftScore.toFixed(1)}% | ${cat} |`);
|
|
350
|
+
}
|
|
351
|
+
lines.push("");
|
|
352
|
+
|
|
353
|
+
const criticalViolations = reports
|
|
354
|
+
.flatMap((r) => r.violations.filter((v) => v.severity === "critical"))
|
|
355
|
+
.slice(0, 10);
|
|
356
|
+
|
|
357
|
+
if (criticalViolations.length > 0) {
|
|
358
|
+
lines.push("### Critical violations requiring attention");
|
|
359
|
+
for (const v of criticalViolations) {
|
|
360
|
+
lines.push(
|
|
361
|
+
`- **${v.tokenName}**: canonical \`${v.canonicalValue}\` vs target \`${v.targetValue}\` — affects ~${v.instancesAffected} instance(s)`
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
lines.push("");
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const warnings = reports
|
|
368
|
+
.flatMap((r) => r.violations.filter((v) => v.severity === "warning"))
|
|
369
|
+
.slice(0, 8);
|
|
370
|
+
|
|
371
|
+
if (warnings.length > 0) {
|
|
372
|
+
lines.push("<details><summary>Warnings</summary>");
|
|
373
|
+
lines.push("");
|
|
374
|
+
for (const v of warnings) {
|
|
375
|
+
lines.push(
|
|
376
|
+
`- \`${v.tokenName}\` (${v.driftType}): \`${v.canonicalValue}\` → \`${v.targetValue}\``
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
lines.push("</details>");
|
|
380
|
+
lines.push("");
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
if (overallStatus === "HEALTHY") {
|
|
384
|
+
lines.push("All tokens are within acceptable drift thresholds. No action required.");
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
return lines.join("\n");
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function formatAsAnnotations(reports: DriftReport[]): string {
|
|
391
|
+
const annotations = reports.flatMap((report) =>
|
|
392
|
+
report.violations
|
|
393
|
+
.filter((v) => v.severity === "critical")
|
|
394
|
+
.map((v) => ({
|
|
395
|
+
fileKey: report.targetFileKey,
|
|
396
|
+
tokenName: v.tokenName,
|
|
397
|
+
message: `[DRIFT] ${v.tokenName}: expected "${v.canonicalValue}" but found "${v.targetValue}" (${v.driftType}, ~${v.instancesAffected} instance(s))`,
|
|
398
|
+
severity: v.severity,
|
|
399
|
+
driftType: v.driftType,
|
|
400
|
+
instancesAffected: v.instancesAffected,
|
|
401
|
+
}))
|
|
402
|
+
);
|
|
403
|
+
|
|
404
|
+
return JSON.stringify({ annotations }, null, 2);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// ─── Main handler ─────────────────────────────────────────────────────────────
|
|
408
|
+
|
|
409
|
+
export async function systemDriftHandler(
|
|
410
|
+
args: SystemDriftArgs
|
|
411
|
+
): Promise<SystemDriftResult> {
|
|
412
|
+
const {
|
|
413
|
+
canonicalFileKey,
|
|
414
|
+
targetFileKeys,
|
|
415
|
+
tokenTypes,
|
|
416
|
+
threshold = 15,
|
|
417
|
+
outputFormat,
|
|
418
|
+
} = args;
|
|
419
|
+
|
|
420
|
+
if (!canonicalFileKey) throw new Error("systemDrift: `canonicalFileKey` is required.");
|
|
421
|
+
if (!targetFileKeys || targetFileKeys.length === 0) {
|
|
422
|
+
throw new Error("systemDrift: `targetFileKeys` must be a non-empty array.");
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// 1. Fetch canonical tokens
|
|
426
|
+
const canonicalTokens = await fetchFileVariables(canonicalFileKey);
|
|
427
|
+
|
|
428
|
+
if (canonicalTokens.length === 0) {
|
|
429
|
+
throw new Error(
|
|
430
|
+
`systemDrift: No variables found in canonical file "${canonicalFileKey}". Ensure the file has local variables and the access token has read permission.`
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// 2. Compare each target file
|
|
435
|
+
const reports: DriftReport[] = [];
|
|
436
|
+
|
|
437
|
+
for (const targetFileKey of targetFileKeys) {
|
|
438
|
+
let targetTokens: FlatToken[];
|
|
439
|
+
try {
|
|
440
|
+
targetTokens = await fetchFileVariables(targetFileKey);
|
|
441
|
+
} catch (err) {
|
|
442
|
+
console.error(
|
|
443
|
+
`systemDrift: Skipping "${targetFileKey}" — ${err instanceof Error ? err.message : String(err)}`
|
|
444
|
+
);
|
|
445
|
+
continue;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
const violations = compareTokenSets(canonicalTokens, targetTokens, tokenTypes);
|
|
449
|
+
|
|
450
|
+
// Count only tokens that match the type filter for the denominator
|
|
451
|
+
const relevantCanonical = tokenTypes && tokenTypes.length > 0
|
|
452
|
+
? canonicalTokens.filter((t) =>
|
|
453
|
+
tokenTypes.some((tf) => t.type.toLowerCase().includes(tf.toLowerCase()))
|
|
454
|
+
)
|
|
455
|
+
: canonicalTokens;
|
|
456
|
+
|
|
457
|
+
const totalTokens = relevantCanonical.length;
|
|
458
|
+
const driftingTokens = violations.filter((v) => v.driftType !== "extra").length;
|
|
459
|
+
const driftScore = totalTokens > 0 ? (driftingTokens / totalTokens) * 100 : 0;
|
|
460
|
+
|
|
461
|
+
reports.push({
|
|
462
|
+
canonicalFileKey,
|
|
463
|
+
targetFileKey,
|
|
464
|
+
totalTokens,
|
|
465
|
+
driftingTokens,
|
|
466
|
+
driftScore: Math.round(driftScore * 10) / 10,
|
|
467
|
+
violations,
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// 3. Build summary
|
|
472
|
+
const healthyFiles = reports.filter(
|
|
473
|
+
(r) => classifyScore(r.driftScore, threshold) === "healthy"
|
|
474
|
+
).length;
|
|
475
|
+
const warningFiles = reports.filter(
|
|
476
|
+
(r) => classifyScore(r.driftScore, threshold) === "warning"
|
|
477
|
+
).length;
|
|
478
|
+
const criticalFiles = reports.filter(
|
|
479
|
+
(r) => classifyScore(r.driftScore, threshold) === "critical"
|
|
480
|
+
).length;
|
|
481
|
+
const totalTokensCompared = reports.reduce((s, r) => s + r.totalTokens, 0);
|
|
482
|
+
const totalDriftingTokens = reports.reduce((s, r) => s + r.driftingTokens, 0);
|
|
483
|
+
const overallDriftScore =
|
|
484
|
+
totalTokensCompared > 0 ? (totalDriftingTokens / totalTokensCompared) * 100 : 0;
|
|
485
|
+
|
|
486
|
+
const summary: DriftSummary = {
|
|
487
|
+
filesChecked: reports.length,
|
|
488
|
+
healthyFiles,
|
|
489
|
+
warningFiles,
|
|
490
|
+
criticalFiles,
|
|
491
|
+
totalTokensCompared,
|
|
492
|
+
totalDriftingTokens,
|
|
493
|
+
overallDriftScore: Math.round(overallDriftScore * 10) / 10,
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
// 4. Format output
|
|
497
|
+
let formattedOutput: string;
|
|
498
|
+
switch (outputFormat) {
|
|
499
|
+
case "report":
|
|
500
|
+
formattedOutput = formatAsReport(reports, summary, threshold);
|
|
501
|
+
break;
|
|
502
|
+
case "pr-comment":
|
|
503
|
+
formattedOutput = formatAsPrComment(reports, summary);
|
|
504
|
+
break;
|
|
505
|
+
case "annotations":
|
|
506
|
+
formattedOutput = formatAsAnnotations(reports);
|
|
507
|
+
break;
|
|
508
|
+
default:
|
|
509
|
+
formattedOutput = formatAsReport(reports, summary, threshold);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// 5. Log the decision
|
|
513
|
+
const logEntry = await decisionLog.log({
|
|
514
|
+
tool: "system-drift",
|
|
515
|
+
nodeIds: [],
|
|
516
|
+
rationale: `Drift analysis: canonical="${canonicalFileKey}", targets=${targetFileKeys.join(", ")}. Files checked: ${reports.length}. Overall drift: ${summary.overallDriftScore.toFixed(1)}%. Healthy: ${healthyFiles}, Warning: ${warningFiles}, Critical: ${criticalFiles}. Output: ${outputFormat}.`,
|
|
517
|
+
tokens: [],
|
|
518
|
+
reversible: false,
|
|
519
|
+
metadata: {
|
|
520
|
+
canonicalFileKey,
|
|
521
|
+
targetFileKeys,
|
|
522
|
+
tokenTypes,
|
|
523
|
+
threshold,
|
|
524
|
+
outputFormat,
|
|
525
|
+
summary,
|
|
526
|
+
},
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
return {
|
|
530
|
+
reports,
|
|
531
|
+
summary,
|
|
532
|
+
formattedOutput,
|
|
533
|
+
logEntryId: logEntry.id,
|
|
534
|
+
};
|
|
535
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { decisionLog } from "../../../shared/decision-log.js";
|
|
2
|
+
import {
|
|
3
|
+
searchUnsplashPhotos,
|
|
4
|
+
trackUnsplashDownload,
|
|
5
|
+
UnsplashContentFilter,
|
|
6
|
+
UnsplashOrientation,
|
|
7
|
+
UnsplashPhotoResult,
|
|
8
|
+
} from "../../../shared/unsplash.js";
|
|
9
|
+
|
|
10
|
+
export interface FigmaUnsplashSearchArgs {
|
|
11
|
+
query: string;
|
|
12
|
+
count?: number;
|
|
13
|
+
page?: number;
|
|
14
|
+
orientation?: UnsplashOrientation;
|
|
15
|
+
contentFilter?: UnsplashContentFilter;
|
|
16
|
+
color?: string;
|
|
17
|
+
trackDownloads?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface FigmaUnsplashSearchResult {
|
|
21
|
+
query: string;
|
|
22
|
+
count: number;
|
|
23
|
+
page: number;
|
|
24
|
+
total: number;
|
|
25
|
+
totalPages: number;
|
|
26
|
+
results: UnsplashPhotoResult[];
|
|
27
|
+
logEntryId: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function figmaUnsplashSearchHandler(
|
|
31
|
+
args: FigmaUnsplashSearchArgs
|
|
32
|
+
): Promise<FigmaUnsplashSearchResult> {
|
|
33
|
+
const {
|
|
34
|
+
query,
|
|
35
|
+
count = 4,
|
|
36
|
+
page = 1,
|
|
37
|
+
orientation,
|
|
38
|
+
contentFilter = "high",
|
|
39
|
+
color,
|
|
40
|
+
trackDownloads = false,
|
|
41
|
+
} = args;
|
|
42
|
+
|
|
43
|
+
const search = await searchUnsplashPhotos({
|
|
44
|
+
query,
|
|
45
|
+
page,
|
|
46
|
+
perPage: count,
|
|
47
|
+
orientation,
|
|
48
|
+
contentFilter,
|
|
49
|
+
color,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
if (trackDownloads) {
|
|
53
|
+
for (const photo of search.results) {
|
|
54
|
+
await trackUnsplashDownload(photo.links.downloadLocation);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const logEntry = await decisionLog.log({
|
|
59
|
+
tool: "figma_unsplash_search",
|
|
60
|
+
nodeIds: [],
|
|
61
|
+
rationale: `Searched Unsplash for "${query}" and returned ${search.results.length} image candidates for Figma generation.`,
|
|
62
|
+
reversible: false,
|
|
63
|
+
metadata: {
|
|
64
|
+
query,
|
|
65
|
+
count,
|
|
66
|
+
page,
|
|
67
|
+
orientation,
|
|
68
|
+
contentFilter,
|
|
69
|
+
color,
|
|
70
|
+
trackDownloads,
|
|
71
|
+
total: search.total,
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
query,
|
|
77
|
+
count: search.results.length,
|
|
78
|
+
page,
|
|
79
|
+
total: search.total,
|
|
80
|
+
totalPages: search.totalPages,
|
|
81
|
+
results: search.results,
|
|
82
|
+
logEntryId: logEntry.id,
|
|
83
|
+
};
|
|
84
|
+
}
|