# Design Spec Extraction (`--design-spec`) Imports a pre-structured design specification file and converts it to our `brand/design-system.md` format. Highest-fidelity input mode — skips both the style picker (Sub-step 3) AND spec-writing (Sub-step 4). ## Supported formats | Format | Detection marker | Parser | |---|---|---| | Our own `/design-system` output | `# ... — Design System` heading | Direct copy (~0 cost) | | Tokens Studio JSON-in-markdown | `$type` / `$value` keys in JSON blocks | Schema-aware flatten | | Style Dictionary `.json` | Top-level `color` / `spacing` / `typography` with `value` keys | Schema-validated parser | | Storybook MDX | `.mdx` extension + `Meta` import or frontmatter | Frontmatter + table extraction | | Figma Make / V0 / Lovable output | Known markers: `/* Generated by */` comments, specific heading patterns | Per-tool parser | | Claude Design output | `## Design Tokens` or `## Color Palette` + `## Typography Scale` headings | Known-format parser | | Generic markdown with tables | Palette/typography/component tables (pipe-delimited) | Deterministic table extraction | ## Pipeline ``` 1. Read file (200 KB cap; .md / .mdx / .json accepted) 2. Auto-detect format via markers (table above) 3. Route to format-specific parser 4. Emit ## Design Direction block with provenance line 5. SKIP Sub-step 3 (style picker) AND Sub-step 4 (write spec) 6. Jump to Sub-step 5 (gallery render) ``` ## Format-specific parsing ### Our own format (direct copy) Look for: `# — Design System` + `Generated:` line + `## Palette` table. Action: Copy verbatim to `brand/design-system.md`. Add provenance: `source: (native design-system format)`. ### Tokens Studio JSON Structure: ```json { "color": { "primary": { "$type": "color", "$value": "#0078D4" }, "background": { "$type": "color", "$value": "#FFFFFF" } }, "typography": { "heading": { "$type": "typography", "$value": { "fontFamily": "Inter", "fontSize": "24px", "fontWeight": "600" } } } } ``` Parser: Schema-aware recursive flatten. Handle nested groups (`color.brand.primary.default`). Strip `$` prefix from type/value keys. ### Style Dictionary JSON Structure: ```json { "color": { "primary": { "value": "#0078D4" }, "background": { "value": "#FFFFFF" } } } ``` Parser: Simpler — `value` key at leaf nodes. Validate against Style Dictionary schema. ### Storybook MDX Look for: `.mdx` extension, `import { Meta } from '@storybook/blocks'` or YAML frontmatter. Parser: Extract frontmatter tokens + scan for markdown tables with color/typography/spacing data. Strip React component blocks (not useful for token extraction). ### Claude Design output Look for: `## Design Tokens` or `## Color Palette` + `## Typography Scale` as section headers. Parser: Known heading structure → deterministic table extraction from each section. ### Generic markdown Fallback for unrecognized formats. Look for pipe-delimited tables containing: - Color values (hex `#RRGGBB`, rgb(), hsl()) - Font specifications (family, size, weight) - Spacing values (px, rem) Parser: Deterministic table regex extraction. Sonnet assist ONLY if tables are ambiguous (e.g., no clear column headers). ## Output Emits a complete `## Design Direction` block: ```markdown ## Design Direction source: () ## Palette | Token | Hex | Usage | ... ## Typography | Role | Family | Size | Weight | Line | Tracking | ... ## Components (if extractable from source) ## Negatives (if source includes constraints / forbidden patterns) ``` ## Failure modes | Condition | Action | |---|---| | File missing | STOP | | Format unrecognized + no token tables | Fall back to `--brand-doc` Sonnet path with warning | | Tokens Studio deeply nested `$type`/`$value` | Schema-aware flatten | | Storybook MDX has React component blocks | Strip components, keep token tables | | Figma Make output has placeholder hex (`#TBD`) | STOP — ask user to fill in | | Spec contradicts itself (two different `palette.primary`) | Surface conflict, ask user | | Non-color tokens we can't map (motion curves, elevation) | Capture in Negatives as "preserve from source" | ## Cost ~0-2k tokens (mostly deterministic; Sonnet only for unrecognized markdown structure).