--- name: layout-extract description: Extract structural layout information from reference images, URLs, or text prompts usage: /workflow:ui-design:layout-extract [--base-path ] [--session ] [--images ""] [--urls ""] [--prompt ""] [--targets ""] [--mode ] [--variants ] [--device-type ] examples: - /workflow:ui-design:layout-extract --urls "home:https://linear.app" --mode imitate --targets "home" - /workflow:ui-design:layout-extract --images "refs/*.png" --mode explore --variants 3 --targets "dashboard" - /workflow:ui-design:layout-extract --prompt "Two-column blog with sticky sidebar" --mode explore --variants 2 --targets "blog-post" - /workflow:ui-design:layout-extract --session WFS-auth --urls "login:https://clerk.dev" --device-type mobile --targets "login" allowed-tools: TodoWrite(*), Read(*), Write(*), Glob(*), Bash(*), Task(ui-design-agent), mcp__exa__web_search_exa(*) --- # Layout Extraction Command ## Overview Extract structural layout information from reference images, URLs, or text prompts using AI analysis. This command separates the "scaffolding" (HTML structure and CSS layout) from the "paint" (visual tokens handled by `style-extract`). **Strategy**: AI-Driven Structural Analysis - **Agent-Powered**: Uses `ui-design-agent` for deep structural analysis - **Dual-Mode**: - `imitate`: High-fidelity replication of single layout structure - `explore`: Multiple structurally distinct layout variations - **Single Output**: `layout-templates.json` with DOM structure, component hierarchy, and CSS layout rules - **Device-Aware**: Optimized for specific device types (desktop, mobile, tablet, responsive) - **Token-Based**: CSS uses `var()` placeholders for spacing and breakpoints ## Phase 0: Setup & Input Validation ### Step 1: Detect Input, Mode & Targets ```bash # Detect input source # Priority: --urls + --images → hybrid | --urls → url | --images → image | --prompt → text # Determine extraction mode extraction_mode = --mode OR "imitate" # "imitate" or "explore" # Set variants count based on mode IF extraction_mode == "imitate": variants_count = 1 # Force single variant (ignore --variants) ELSE IF extraction_mode == "explore": variants_count = --variants OR 3 # Default to 3 VALIDATE: 1 <= variants_count <= 5 # Resolve targets # Priority: --targets → prompt analysis → default ["page"] targets = --targets OR extract_from_prompt(--prompt) OR ["page"] # Resolve device type device_type = --device-type OR "responsive" # desktop|mobile|tablet|responsive # Determine base path bash(find .workflow -type d -name "design-*" | head -1) # Auto-detect # OR use --base-path / --session parameters ``` ### Step 2: Load Inputs & Create Directories ```bash # For image mode bash(ls {images_pattern}) # Expand glob pattern Read({image_path}) # Load each image # For URL mode # Parse URL list format: "target:url,target:url" # Validate URLs are accessible # For text mode # Validate --prompt is non-empty # Create output directory bash(mkdir -p {base_path}/layout-extraction) ``` ### Step 3: Memory Check (Skip if Already Done) ```bash # Check if layouts already extracted bash(test -f {base_path}/layout-extraction/layout-templates.json && echo "exists") ``` **If exists**: Skip to completion message **Output**: `input_mode`, `base_path`, `extraction_mode`, `variants_count`, `targets[]`, `device_type`, loaded inputs ## Phase 1: Layout Research (Explore Mode Only) ### Step 1: Check Extraction Mode ```bash # extraction_mode == "imitate" → skip this phase # extraction_mode == "explore" → execute this phase ``` **If imitate mode**: Skip to Phase 2 ### Step 2: Gather Layout Inspiration (Explore Mode) ```bash bash(mkdir -p {base_path}/layout-extraction/_inspirations) # For each target: Research via MCP # mcp__exa__web_search_exa(query="{target} layout patterns {device_type}", numResults=5) # Write inspiration file Write({base_path}/layout-extraction/_inspirations/{target}-layout-ideas.txt, inspiration_content) ``` **Output**: Inspiration text files for each target (explore mode only) ## Phase 2: Layout Analysis & Synthesis (Agent) **Executor**: `Task(ui-design-agent)` ### Step 1: Launch Agent Task ```javascript Task(ui-design-agent): ` [LAYOUT_EXTRACTION_TASK] Analyze references and extract structural layout templates. Focus ONLY on structure and layout. DO NOT concern with visual style (colors, fonts, etc.). REFERENCES: - Input: {reference_material} // Images, URLs, or prompt - Mode: {extraction_mode} // 'imitate' or 'explore' - Targets: {targets} // List of page/component names - Variants per Target: {variants_count} - Device Type: {device_type} ${exploration_mode ? "- Layout Inspiration: Read('" + base_path + "/layout-extraction/_inspirations/{target}-layout-ideas.txt')" : ""} ## Analysis & Generation For EACH target in {targets}: For EACH variant (1 to {variants_count}): 1. **Analyze Structure**: Deconstruct reference to understand layout, hierarchy, responsiveness 2. **Define Philosophy**: Short description (e.g., "Asymmetrical grid with overlapping content areas") 3. **Generate DOM Structure**: JSON object representing semantic HTML5 structure - Semantic tags:
,