claude-code-workflow 6.0.4 → 6.1.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 (120) hide show
  1. package/.claude/agents/action-planning-agent.md +1 -1
  2. package/.claude/agents/cli-execution-agent.md +269 -269
  3. package/.claude/agents/cli-explore-agent.md +182 -182
  4. package/.claude/agents/context-search-agent.md +582 -582
  5. package/.claude/agents/memory-bridge.md +93 -93
  6. package/.claude/commands/cli/cli-init.md +1 -1
  7. package/.claude/commands/memory/docs-full-cli.md +471 -471
  8. package/.claude/commands/memory/docs-related-cli.md +386 -386
  9. package/.claude/commands/memory/docs.md +615 -615
  10. package/.claude/commands/memory/load.md +1 -1
  11. package/.claude/commands/memory/update-full.md +332 -332
  12. package/.claude/commands/memory/update-related.md +5 -5
  13. package/.claude/commands/workflow/init.md +1 -1
  14. package/.claude/commands/workflow/lite-fix.md +621 -621
  15. package/.claude/commands/workflow/lite-plan.md +592 -592
  16. package/.claude/commands/workflow/tools/context-gather.md +434 -434
  17. package/.claude/commands/workflow/ui-design/generate.md +504 -504
  18. package/.claude/commands/workflow/ui-design/import-from-code.md +537 -537
  19. package/.claude/scripts/classify-folders.sh +4 -0
  20. package/.claude/scripts/convert_tokens_to_css.sh +4 -0
  21. package/.claude/scripts/detect_changed_modules.sh +5 -1
  22. package/.claude/scripts/discover-design-files.sh +87 -83
  23. package/.claude/scripts/generate_module_docs.sh +717 -713
  24. package/.claude/scripts/get_modules_by_depth.sh +5 -1
  25. package/.claude/scripts/ui-generate-preview.sh +4 -0
  26. package/.claude/scripts/ui-instantiate-prototypes.sh +4 -0
  27. package/.claude/scripts/update_module_claude.sh +4 -0
  28. package/.claude/skills/command-guide/index/all-commands.json +1 -12
  29. package/.claude/skills/command-guide/index/by-category.json +1 -12
  30. package/.claude/skills/command-guide/index/by-use-case.json +1 -12
  31. package/.claude/skills/command-guide/index/essential-commands.json +1 -12
  32. package/.claude/skills/command-guide/reference/agents/action-planning-agent.md +127 -71
  33. package/.claude/skills/command-guide/reference/agents/cli-execution-agent.md +269 -269
  34. package/.claude/skills/command-guide/reference/agents/cli-explore-agent.md +182 -182
  35. package/.claude/skills/command-guide/reference/agents/conceptual-planning-agent.md +18 -38
  36. package/.claude/skills/command-guide/reference/agents/context-search-agent.md +582 -577
  37. package/.claude/skills/command-guide/reference/agents/memory-bridge.md +93 -93
  38. package/.claude/skills/command-guide/reference/commands/cli/cli-init.md +1 -1
  39. package/.claude/skills/command-guide/reference/commands/memory/docs-full-cli.md +471 -471
  40. package/.claude/skills/command-guide/reference/commands/memory/docs-related-cli.md +386 -386
  41. package/.claude/skills/command-guide/reference/commands/memory/docs.md +615 -610
  42. package/.claude/skills/command-guide/reference/commands/memory/load.md +1 -1
  43. package/.claude/skills/command-guide/reference/commands/memory/update-full.md +332 -332
  44. package/.claude/skills/command-guide/reference/commands/memory/update-related.md +5 -5
  45. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/artifacts.md +299 -451
  46. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/auto-parallel.md +14 -37
  47. package/.claude/skills/command-guide/reference/commands/workflow/brainstorm/synthesis.md +252 -350
  48. package/.claude/skills/command-guide/reference/commands/workflow/init.md +2 -2
  49. package/.claude/skills/command-guide/reference/commands/workflow/lite-execute.md +52 -0
  50. package/.claude/skills/command-guide/reference/commands/workflow/lite-fix.md +621 -602
  51. package/.claude/skills/command-guide/reference/commands/workflow/lite-plan.md +46 -36
  52. package/.claude/skills/command-guide/reference/commands/workflow/review-fix.md +18 -58
  53. package/.claude/skills/command-guide/reference/commands/workflow/review-module-cycle.md +22 -52
  54. package/.claude/skills/command-guide/reference/commands/workflow/review-session-cycle.md +19 -48
  55. package/.claude/skills/command-guide/reference/commands/workflow/session/start.md +25 -5
  56. package/.claude/skills/command-guide/reference/commands/workflow/tdd-plan.md +1 -1
  57. package/.claude/skills/command-guide/reference/commands/workflow/test-fix-gen.md +7 -7
  58. package/.claude/skills/command-guide/reference/commands/workflow/tools/context-gather.md +434 -434
  59. package/.claude/skills/command-guide/reference/commands/workflow/tools/task-generate-agent.md +151 -11
  60. package/.claude/skills/command-guide/reference/commands/workflow/tools/task-generate-tdd.md +4 -4
  61. package/.claude/skills/command-guide/reference/commands/workflow/tools/test-task-generate.md +1 -1
  62. package/.claude/skills/command-guide/reference/commands/workflow/ui-design/generate.md +504 -504
  63. package/.claude/skills/command-guide/reference/commands/workflow/ui-design/import-from-code.md +537 -537
  64. package/.claude/workflows/context-search-strategy.md +77 -77
  65. package/.claude/workflows/tool-strategy.md +90 -71
  66. package/.claude/workflows/workflow-architecture.md +1 -1
  67. package/ccw/package.json +6 -6
  68. package/ccw/src/cli.js +16 -0
  69. package/ccw/src/commands/stop.js +101 -0
  70. package/ccw/src/commands/tool.js +181 -0
  71. package/ccw/src/core/dashboard-generator.js +18 -3
  72. package/ccw/src/core/lite-scanner.js +35 -11
  73. package/ccw/src/core/server.js +583 -17
  74. package/ccw/src/templates/dashboard-css/01-base.css +161 -0
  75. package/ccw/src/templates/dashboard-css/02-session.css +726 -0
  76. package/ccw/src/templates/dashboard-css/03-tasks.css +512 -0
  77. package/ccw/src/templates/dashboard-css/04-lite-tasks.css +843 -0
  78. package/ccw/src/templates/dashboard-css/05-context.css +2206 -0
  79. package/ccw/src/templates/dashboard-css/06-cards.css +1570 -0
  80. package/ccw/src/templates/dashboard-css/07-managers.css +936 -0
  81. package/ccw/src/templates/dashboard-css/08-review.css +1266 -0
  82. package/ccw/src/templates/dashboard-css/09-explorer.css +1397 -0
  83. package/ccw/src/templates/dashboard-js/components/global-notifications.js +219 -0
  84. package/ccw/src/templates/dashboard-js/components/hook-manager.js +10 -0
  85. package/ccw/src/templates/dashboard-js/components/mcp-manager.js +24 -2
  86. package/ccw/src/templates/dashboard-js/components/navigation.js +11 -5
  87. package/ccw/src/templates/dashboard-js/components/tabs-context.js +20 -20
  88. package/ccw/src/templates/dashboard-js/components/tabs-other.js +11 -11
  89. package/ccw/src/templates/dashboard-js/components/theme.js +29 -1
  90. package/ccw/src/templates/dashboard-js/main.js +4 -0
  91. package/ccw/src/templates/dashboard-js/state.js +5 -0
  92. package/ccw/src/templates/dashboard-js/views/explorer.js +852 -0
  93. package/ccw/src/templates/dashboard-js/views/home.js +13 -9
  94. package/ccw/src/templates/dashboard-js/views/hook-manager.js +8 -5
  95. package/ccw/src/templates/dashboard-js/views/lite-tasks.js +21 -16
  96. package/ccw/src/templates/dashboard-js/views/mcp-manager.js +148 -8
  97. package/ccw/src/templates/dashboard-js/views/project-overview.js +15 -11
  98. package/ccw/src/templates/dashboard-js/views/review-session.js +3 -3
  99. package/ccw/src/templates/dashboard-js/views/session-detail.js +38 -28
  100. package/ccw/src/templates/dashboard.html +129 -28
  101. package/ccw/src/tools/classify-folders.js +204 -0
  102. package/ccw/src/tools/convert-tokens-to-css.js +250 -0
  103. package/ccw/src/tools/detect-changed-modules.js +288 -0
  104. package/ccw/src/tools/discover-design-files.js +134 -0
  105. package/ccw/src/tools/edit-file.js +266 -0
  106. package/ccw/src/tools/generate-module-docs.js +416 -0
  107. package/ccw/src/tools/get-modules-by-depth.js +308 -0
  108. package/ccw/src/tools/index.js +176 -0
  109. package/ccw/src/tools/ui-generate-preview.js +327 -0
  110. package/ccw/src/tools/ui-instantiate-prototypes.js +301 -0
  111. package/ccw/src/tools/update-module-claude.js +380 -0
  112. package/ccw/src/utils/browser-launcher.js +15 -4
  113. package/package.json +1 -1
  114. package/.claude/skills/command-guide/reference/commands/workflow/status.md +0 -352
  115. package/ccw/src/core/server.js.bak +0 -385
  116. package/ccw/src/core/server_original.bak +0 -385
  117. package/ccw/src/templates/dashboard.css +0 -8114
  118. package/ccw/src/templates/dashboard_tailwind.html +0 -42
  119. package/ccw/src/templates/dashboard_test.html +0 -37
  120. package/ccw/src/templates/tailwind-base.css +0 -212
@@ -1,537 +1,537 @@
1
- ---
2
- name: workflow:ui-design:import-from-code
3
- description: Import design system from code files (CSS/JS/HTML/SCSS) with automatic file discovery and parallel agent analysis
4
- argument-hint: "[--design-id <id>] [--session <id>] [--source <path>]"
5
- allowed-tools: Read,Write,Bash,Glob,Grep,Task,TodoWrite
6
- auto-continue: true
7
- ---
8
-
9
- # UI Design: Import from Code
10
-
11
- ## Overview
12
-
13
- Extract design system tokens from source code files (CSS/SCSS/JS/TS/HTML) using parallel agent analysis. Each agent can reference any file type for cross-source token extraction, and directly generates completeness reports with findings and gaps.
14
-
15
- **Key Characteristics**:
16
- - Executes parallel agent analysis (3 agents: Style, Animation, Layout)
17
- - Each agent can read ALL file types (CSS/SCSS/JS/TS/HTML) for cross-reference
18
- - Direct completeness reporting without synthesis phase
19
- - Graceful failure handling with detailed missing content analysis
20
- - Returns concrete analysis results with recommendations
21
-
22
- ## Core Functionality
23
-
24
- - **File Discovery**: Auto-discover or target specific CSS/SCSS/JS/HTML files
25
- - **Parallel Analysis**: 3 agents extract tokens simultaneously with cross-file-type support
26
- - **Completeness Reporting**: Each agent reports found tokens, missing content, and recommendations
27
- - **Cross-Source Extraction**: Agents can reference any file type (e.g., Style agent can read JS theme configs)
28
-
29
- ## Usage
30
-
31
- ### Command Syntax
32
-
33
- ```bash
34
- /workflow:ui-design:import-from-code [FLAGS]
35
-
36
- # Flags
37
- --design-id <id> Design run ID to import into (must exist)
38
- --session <id> Session ID (uses latest design run in session)
39
- --source <path> Source code directory to analyze (required)
40
- ```
41
-
42
- **Note**: All file discovery is automatic. The command will scan the source directory and find all relevant style files (CSS, SCSS, JS, HTML) automatically.
43
-
44
- ## Execution Process
45
-
46
- ```
47
- Input Parsing:
48
- ├─ Parse flags: --design-id, --session, --source
49
- └─ Decision (base path resolution):
50
- ├─ --design-id provided → Exact match by design ID
51
- ├─ --session provided → Latest design run in session
52
- └─ Neither → ERROR: Must provide --design-id or --session
53
-
54
- Phase 0: Setup & File Discovery
55
- ├─ Step 1: Resolve base path
56
- ├─ Step 2: Initialize directories
57
- └─ Step 3: Discover files using script
58
-
59
- Phase 1: Parallel Agent Analysis (3 agents)
60
- ├─ Style Agent → design-tokens.json + code_snippets
61
- ├─ Animation Agent → animation-tokens.json + code_snippets
62
- └─ Layout Agent → layout-templates.json + code_snippets
63
- ```
64
-
65
- ### Step 1: Setup & File Discovery
66
-
67
- **Purpose**: Initialize session, discover and categorize code files
68
-
69
- **Operations**:
70
-
71
- ```bash
72
- # 1. Determine base path with priority: --design-id > --session > error
73
- if [ -n "$DESIGN_ID" ]; then
74
- # Exact match by design ID
75
- relative_path=$(find .workflow -name "${DESIGN_ID}" -type d -print -quit)
76
- if [ -z "$relative_path" ]; then
77
- echo "ERROR: Design run not found: $DESIGN_ID"
78
- echo "HINT: Run '/workflow:ui-design:list' to see available design runs"
79
- exit 1
80
- fi
81
- elif [ -n "$SESSION_ID" ]; then
82
- # Latest in session
83
- relative_path=$(find .workflow/active/WFS-$SESSION_ID -name "design-run-*" -type d -printf "%T@ %p\n" 2>/dev/null | sort -nr | head -1 | cut -d' ' -f2)
84
- if [ -z "$relative_path" ]; then
85
- echo "ERROR: No design run found in session: $SESSION_ID"
86
- echo "HINT: Create a design run first or provide --design-id"
87
- exit 1
88
- fi
89
- else
90
- echo "ERROR: Must provide --design-id or --session parameter"
91
- exit 1
92
- fi
93
-
94
- base_path=$(cd "$relative_path" && pwd)
95
- design_id=$(basename "$base_path")
96
-
97
- # 2. Initialize directories
98
- source="${source:-.}"
99
- intermediates_dir="${base_path}/.intermediates/import-analysis"
100
- mkdir -p "$intermediates_dir"
101
-
102
- echo "[Phase 0] File Discovery Started"
103
- echo " Design ID: $design_id"
104
- echo " Source: $source"
105
- echo " Output: $base_path"
106
-
107
- # 3. Discover files using script
108
- discovery_file="${intermediates_dir}/discovered-files.json"
109
- ~/.claude/scripts/discover-design-files.sh "$source" "$discovery_file"
110
-
111
- echo " Output: $discovery_file"
112
- ```
113
-
114
- <!-- TodoWrite: Initialize todo list -->
115
-
116
- **TodoWrite**:
117
- ```json
118
- [
119
- {"content": "Phase 0: 发现和分类代码文件", "status": "in_progress", "activeForm": "发现代码文件"},
120
- {"content": "Phase 1.1: Style Agent - 提取视觉token及代码片段 (design-tokens.json + code_snippets)", "status": "pending", "activeForm": "提取视觉token"},
121
- {"content": "Phase 1.2: Animation Agent - 提取动画token及代码片段 (animation-tokens.json + code_snippets)", "status": "pending", "activeForm": "提取动画token"},
122
- {"content": "Phase 1.3: Layout Agent - 提取布局模式及代码片段 (layout-templates.json + code_snippets)", "status": "pending", "activeForm": "提取布局模式"}
123
- ]
124
- ```
125
-
126
- **File Discovery Behavior**:
127
-
128
- - **Automatic discovery**: Intelligently scans source directory for all style-related files
129
- - **Supported file types**: CSS, SCSS, JavaScript, TypeScript, HTML
130
- - **Smart filtering**: Finds theme-related JS/TS files (e.g., tailwind.config.js, theme.js, styled-components)
131
- - **Exclusions**: Automatically excludes `node_modules/`, `dist/`, `.git/`, and build directories
132
- - **Output**: Single JSON file `discovered-files.json` in `.intermediates/import-analysis/`
133
- - Structure: `{ "css": [...], "js": [...], "html": [...], "counts": {...}, "discovery_time": "..." }`
134
- - Generated via bash commands using `find` + JSON formatting
135
-
136
- <!-- TodoWrite: Update Phase 0 → completed, Phase 1.1-1.3 → in_progress (all 3 agents in parallel) -->
137
-
138
- ---
139
-
140
- ### Step 2: Parallel Agent Analysis
141
-
142
- **Purpose**: Three agents analyze all file types in parallel, each producing completeness-report.json
143
-
144
- **Operations**:
145
- - **Style Agent**: Extracts visual tokens (colors, typography, spacing) from ALL files (CSS/SCSS/JS/HTML)
146
- - **Animation Agent**: Extracts animations/transitions from ALL files
147
- - **Layout Agent**: Extracts layout patterns/component structures from ALL files
148
-
149
- **Validation**:
150
- - Each agent can reference any file type (not restricted to single type)
151
- - Direct output: Each agent generates completeness-report.json with findings + missing content
152
- - No synthesis needed: Agents produce final output directly
153
-
154
- ```bash
155
- echo "[Phase 1] Starting parallel agent analysis (3 agents)"
156
- ```
157
-
158
- #### Style Agent Task (design-tokens.json, style-guide.md)
159
-
160
- **Agent Task**:
161
-
162
- ```javascript
163
- Task(subagent_type="ui-design-agent",
164
- prompt="[STYLE_TOKENS_EXTRACTION]
165
- Extract visual design tokens from code files using code import extraction pattern.
166
-
167
- MODE: style-extraction | SOURCE: ${source} | BASE_PATH: ${base_path}
168
-
169
- ## Input Files
170
-
171
- **Discovered Files**: ${intermediates_dir}/discovered-files.json
172
- $(cat \"${intermediates_dir}/discovered-files.json\" 2>/dev/null | grep -E '(count|files)' | head -30)
173
-
174
- ## Code Import Extraction Strategy
175
-
176
- **Step 0: Fast Conflict Detection** (Use Bash/Grep for quick global scan)
177
- - Quick scan: \`rg --color=never -n "^\\s*--primary:|^\\s*--secondary:|^\\s*--accent:" --type css ${source}\` to find core color definitions with line numbers
178
- - Semantic search: \`rg --color=never -B3 -A1 "^\\s*--primary:" --type css ${source}\` to capture surrounding context and comments
179
- - Core token scan: Search for --primary, --secondary, --accent, --background patterns to detect all theme-critical definitions
180
- - Pattern: rg → Extract values → Compare → If different → Read full context with comments → Record conflict
181
- - Alternative (if many files): Execute CLI analysis for comprehensive report:
182
- \`\`\`bash
183
- cd ${source} && gemini -p \"
184
- PURPOSE: Detect color token conflicts across all CSS/SCSS/JS files
185
- TASK: • Scan all files for color definitions • Identify conflicting values • Extract semantic comments
186
- MODE: analysis
187
- CONTEXT: @**/*.css @**/*.scss @**/*.js @**/*.ts
188
- EXPECTED: JSON report listing conflicts with file:line, values, semantic context
189
- RULES: Focus on core tokens | Report ALL variants | analysis=READ-ONLY
190
- \"
191
- \`\`\`
192
-
193
- **Step 1: Load file list**
194
- - Read(${intermediates_dir}/discovered-files.json)
195
- - Extract: file_types.css.files, file_types.js.files, file_types.html.files
196
-
197
- **Step 2: Cross-source token extraction**
198
- - CSS/SCSS: Colors, typography, spacing, shadows, borders
199
- - JavaScript/TypeScript: Theme configs (Tailwind, styled-components, CSS-in-JS)
200
- - HTML: Inline styles, usage patterns
201
-
202
- **Step 3: Validation and Conflict Detection**
203
- - Report missing tokens WITHOUT inference (mark as "missing" in _metadata.completeness)
204
- - Detect and report inconsistent values across files (list ALL variants with file:line sources)
205
- - Report missing categories WITHOUT auto-filling (document gaps for manual review)
206
- - CRITICAL: Verify core tokens (primary, secondary, accent) against semantic comments in source code
207
-
208
- ## Output Files
209
-
210
- **Target Directory**: ${base_path}/style-extraction/style-1/
211
-
212
- **Files to Generate**:
213
- 1. **design-tokens.json**
214
- - Follow [DESIGN_SYSTEM_GENERATION_TASK] standard token structure
215
- - Add \"_metadata.extraction_source\": \"code_import\"
216
- - Add \"_metadata.files_analyzed\": {css, js, html file lists}
217
- - Add \"_metadata.completeness\": {status, missing_categories, recommendations}
218
- - Add \"_metadata.conflicts\": Array of conflicting definitions (MANDATORY if conflicts exist)
219
- - Add \"_metadata.code_snippets\": Map of code snippets (see below)
220
- - Add \"_metadata.usage_recommendations\": Usage patterns from code (see below)
221
- - Include \"source\" field for each token (e.g., \"file.css:23\")
222
-
223
- **Code Snippet Recording**:
224
- - For each extracted token, record the actual code snippet in `_metadata.code_snippets`
225
- - Structure:
226
- ```json
227
- \"code_snippets\": {
228
- \"file.css:23\": {
229
- \"lines\": \"23-27\",
230
- \"snippet\": \":root {\\n --color-primary: oklch(0.5555 0.15 270);\\n /* Primary brand color */\\n --color-primary-hover: oklch(0.6 0.15 270);\\n}\",
231
- \"context\": \"css-variable\"
232
- }
233
- }
234
- ```
235
- - Context types: \"css-variable\" | \"css-class\" | \"js-object\" | \"js-theme-config\" | \"inline-style\"
236
- - Record complete code blocks with all dependencies and relevant comments
237
- - Typical ranges: Simple declarations (1-5 lines), Utility classes (5-15 lines), Complete configs (15-50 lines)
238
- - Preserve original formatting and indentation
239
-
240
- **Conflict Detection and Reporting**:
241
- - When the same token is defined differently across multiple files, record in `_metadata.conflicts`
242
- - Follow Agent schema for conflicts array structure (see ui-design-agent.md)
243
- - Each conflict MUST include: token_name, category, all definitions with context, selected_value, selection_reason
244
- - Selection priority:
245
- 1. Definitions with semantic comments explaining intent (/* Blue theme */, /* Primary brand color */)
246
- 2. Definitions that align with overall color scheme described in comments
247
- 3. When in doubt, report ALL variants and flag for manual review in completeness.recommendations
248
-
249
- **Usage Recommendations Generation**:
250
- - Analyze code usage patterns to extract `_metadata.usage_recommendations` (see ui-design-agent.md schema)
251
- - **Typography recommendations**:
252
- * `common_sizes`: Identify most frequent font size usage (e.g., \"body_text\": \"base (1rem)\")
253
- * `common_combinations`: Extract heading+body pairings from actual usage (e.g., h1 with p tags)
254
- - **Spacing recommendations**:
255
- * `size_guide`: Categorize spacing values into tight/normal/loose based on frequency
256
- * `common_patterns`: Extract frequent padding/margin combinations from components
257
- - Analysis method: Scan code for class/style usage frequency, extract patterns from component implementations
258
- - Optional: If insufficient usage data, mark fields as empty arrays/objects with note in completeness.recommendations
259
-
260
- ## Code Import Specific Requirements
261
- - ✅ Read discovered-files.json FIRST to get file paths
262
- - ✅ Track extraction source for each token (file:line)
263
- - ✅ Record complete code snippets in _metadata.code_snippets (complete blocks with dependencies/comments)
264
- - ✅ Include completeness assessment in _metadata
265
- - ✅ Report inconsistent values with ALL source locations in _metadata.conflicts (DO NOT auto-normalize or choose)
266
- - ✅ CRITICAL: Verify core theme tokens (primary, secondary, accent) match source code semantic intent
267
- - ✅ When conflicts exist, prefer definitions with semantic comments explaining intent
268
- - ❌ NO inference, NO smart filling, NO automatic conflict resolution
269
- - ❌ NO external research or web searches (code-only extraction)
270
- ")
271
- ```
272
-
273
- #### Animation Agent Task (animation-tokens.json, animation-guide.md)
274
-
275
- **Agent Task**:
276
-
277
- ```javascript
278
- Task(subagent_type="ui-design-agent",
279
- prompt="[ANIMATION_TOKEN_GENERATION_TASK]
280
- Extract animation tokens from code files using code import extraction pattern.
281
-
282
- MODE: animation-extraction | SOURCE: ${source} | BASE_PATH: ${base_path}
283
-
284
- ## Input Files
285
-
286
- **Discovered Files**: ${intermediates_dir}/discovered-files.json
287
- $(cat \"${intermediates_dir}/discovered-files.json\" 2>/dev/null | grep -E '(count|files)' | head -30)
288
-
289
- ## Code Import Extraction Strategy
290
-
291
- **Step 0: Fast Animation Discovery** (Use Bash/Grep for quick pattern detection)
292
- - Quick scan: \`rg --color=never -n "@keyframes|animation:|transition:" --type css ${source}\` to find animation definitions with line numbers
293
- - Framework detection: \`rg --color=never "framer-motion|gsap|@react-spring|react-spring" --type js --type ts ${source}\` to detect animation frameworks
294
- - Pattern categorization: \`rg --color=never -B2 -A5 "@keyframes" --type css ${source}\` to extract keyframe animations with context
295
- - Pattern: rg → Identify animation types → Map framework usage → Prioritize extraction targets
296
- - Alternative (if complex framework mix): Execute CLI analysis for comprehensive report:
297
- \`\`\`bash
298
- cd ${source} && gemini -p \"
299
- PURPOSE: Detect animation frameworks and patterns
300
- TASK: • Identify frameworks • Map animation patterns • Categorize by complexity
301
- MODE: analysis
302
- CONTEXT: @**/*.css @**/*.scss @**/*.js @**/*.ts
303
- EXPECTED: JSON report listing frameworks, animation types, file locations
304
- RULES: Focus on framework consistency | Map all animations | analysis=READ-ONLY
305
- \"
306
- \`\`\`
307
-
308
- **Step 1: Load file list**
309
- - Read(${intermediates_dir}/discovered-files.json)
310
- - Extract: file_types.css.files, file_types.js.files, file_types.html.files
311
-
312
- **Step 2: Cross-source animation extraction**
313
- - CSS/SCSS: @keyframes, transitions, animation properties
314
- - JavaScript/TypeScript: Animation frameworks (Framer Motion, GSAP), CSS-in-JS
315
- - HTML: Inline styles, data-animation attributes
316
-
317
- **Step 3: Framework detection & normalization**
318
- - Detect animation frameworks used (css-animations | framer-motion | gsap | none)
319
- - Normalize into semantic token system
320
- - Cross-reference CSS animations with JS configs
321
-
322
- ## Output Files
323
-
324
- **Target Directory**: ${base_path}/animation-extraction/
325
-
326
- **Files to Generate**:
327
- 1. **animation-tokens.json**
328
- - Follow [ANIMATION_TOKEN_GENERATION_TASK] standard structure
329
- - Add \"_metadata.framework_detected\"
330
- - Add \"_metadata.files_analyzed\"
331
- - Add \"_metadata.completeness\"
332
- - Add \"_metadata.code_snippets\": Map of code snippets (same format as Style Agent)
333
- - Include \"source\" field for each token
334
-
335
- **Code Snippet Recording**:
336
- - Record actual animation/transition code in `_metadata.code_snippets`
337
- - Context types: \"css-keyframes\" | \"css-transition\" | \"js-animation\" | \"framer-motion\" | \"gsap\"
338
- - Record complete blocks: @keyframes animations (10-30 lines), transition configs (5-15 lines), JS animation objects (15-50 lines)
339
- - Include all animation steps, timing functions, and related comments
340
- - Preserve original formatting and framework-specific syntax
341
-
342
- ## Code Import Specific Requirements
343
- - ✅ Read discovered-files.json FIRST to get file paths
344
- - ✅ Detect animation framework if present
345
- - ✅ Track extraction source for each token (file:line)
346
- - ✅ Record complete code snippets in _metadata.code_snippets (complete animation blocks with all steps/timing)
347
- - ✅ Normalize framework-specific syntax into standard tokens
348
- - ❌ NO external research or web searches (code-only extraction)
349
- ")
350
- ```
351
-
352
- #### Layout Agent Task (layout-templates.json, layout-guide.md)
353
-
354
- **Agent Task**:
355
-
356
- ```javascript
357
- Task(subagent_type="ui-design-agent",
358
- prompt="[LAYOUT_TEMPLATE_GENERATION_TASK]
359
- Extract layout patterns from code files using code import extraction pattern.
360
-
361
- MODE: layout-extraction | SOURCE: ${source} | BASE_PATH: ${base_path}
362
-
363
- ## Input Files
364
-
365
- **Discovered Files**: ${intermediates_dir}/discovered-files.json
366
- $(cat \"${intermediates_dir}/discovered-files.json\" 2>/dev/null | grep -E '(count|files)' | head -30)
367
-
368
- ## Code Import Extraction Strategy
369
-
370
- **Step 0: Fast Component Discovery** (Use Bash/Grep for quick component scan)
371
- - Layout pattern scan: \`rg --color=never -n "display:\\s*(grid|flex)|grid-template" --type css ${source}\` to find layout systems
372
- - Component class scan: \`rg --color=never "class.*=.*\\"[^\"]*\\b(btn|button|card|input|modal|dialog|dropdown)" --type html --type js --type ts ${source}\` to identify UI components
373
- - Universal component heuristic: Components appearing in 3+ files = universal, <3 files = specialized
374
- - Pattern: rg → Count occurrences → Classify by frequency → Prioritize universal components
375
- - Alternative (if large codebase): Execute CLI analysis for comprehensive categorization:
376
- \`\`\`bash
377
- cd ${source} && gemini -p \"
378
- PURPOSE: Classify components as universal vs specialized
379
- TASK: • Identify UI components • Classify reusability • Map layout systems
380
- MODE: analysis
381
- CONTEXT: @**/*.css @**/*.scss @**/*.js @**/*.ts @**/*.html
382
- EXPECTED: JSON report categorizing components, layout patterns, naming conventions
383
- RULES: Focus on component reusability | Identify layout systems | analysis=READ-ONLY
384
- \"
385
- \`\`\`
386
-
387
- **Step 1: Load file list**
388
- - Read(${intermediates_dir}/discovered-files.json)
389
- - Extract: file_types.css.files, file_types.js.files, file_types.html.files
390
-
391
- **Step 2: Cross-source layout extraction**
392
- - CSS/SCSS: Grid systems, flexbox utilities, layout classes, media queries
393
- - JavaScript/TypeScript: Layout components (React/Vue), grid configs
394
- - HTML: Semantic structure, component hierarchies
395
-
396
- **Component Classification** (MUST annotate in extraction):
397
- - **Universal Components**: Reusable multi-component templates (buttons, inputs, cards, modals, etc.)
398
- - **Specialized Components**: Module-specific components from code (feature-specific layouts, custom widgets, domain components)
399
-
400
- **Step 3: System identification**
401
- - Detect naming convention (BEM | SMACSS | utility-first | css-modules)
402
- - Identify layout system (12-column | flexbox | css-grid | custom)
403
- - Extract responsive strategy and breakpoints
404
-
405
- ## Output Files
406
-
407
- **Target Directory**: ${base_path}/layout-extraction/
408
-
409
- **Files to Generate**:
410
-
411
- 1. **layout-templates.json**
412
- - Follow [LAYOUT_TEMPLATE_GENERATION_TASK] standard structure
413
- - Add \"extraction_metadata\" section:
414
- * extraction_source: \"code_import\"
415
- * naming_convention: detected convention
416
- * layout_system: {type, confidence, source_files}
417
- * responsive: {breakpoints, mobile_first, source}
418
- * completeness: {status, missing_items, recommendations}
419
- * code_snippets: Map of code snippets (same format as Style Agent)
420
- - For each component in \"layout_templates\":
421
- * Include \"source\" field (file:line)
422
- * **Include \"component_type\" field: \"universal\" | \"specialized\"**
423
- * dom_structure with semantic HTML5
424
- * css_layout_rules using var() placeholders
425
- * Add \"description\" field explaining component purpose and classification rationale
426
- * **Add \"usage_guide\" field for universal components** (see ui-design-agent.md schema):
427
- - common_sizes: Extract size variants (small/medium/large) from code
428
- - variant_recommendations: Document when to use each variant (primary/secondary/etc)
429
- - usage_context: List typical usage scenarios from actual implementation
430
- - accessibility_tips: Extract ARIA patterns and a11y notes from code
431
-
432
- **Code Snippet Recording**:
433
- - Record actual layout/component code in `extraction_metadata.code_snippets`
434
- - Context types: \"css-grid\" | \"css-flexbox\" | \"css-utility\" | \"html-structure\" | \"react-component\"
435
- - Record complete blocks: Utility classes (5-15 lines), HTML structures (10-30 lines), React components (20-100 lines)
436
- - For components: include HTML structure + associated CSS rules + component logic
437
- - Preserve original formatting and framework-specific syntax
438
-
439
- ## Code Import Specific Requirements
440
- - ✅ Read discovered-files.json FIRST to get file paths
441
- - ✅ Detect and document naming conventions
442
- - ✅ Identify layout system with confidence level
443
- - ✅ Extract component variants and states from usage patterns
444
- - ✅ **Classify each component as \"universal\" or \"specialized\"** based on:
445
- * Universal: Reusable across multiple features (buttons, inputs, cards, modals)
446
- * Specialized: Feature-specific or domain-specific (checkout form, dashboard widget)
447
- - ✅ Record complete code snippets in extraction_metadata.code_snippets (complete components/structures)
448
- - ✅ **Document classification rationale** in component description
449
- - ✅ **Generate usage_guide for universal components** (REQUIRED):
450
- * Analyze code to extract size variants (scan for size-related classes/props)
451
- * Document variant usage from code comments and implementation patterns
452
- * List usage contexts from component instances in codebase
453
- * Extract accessibility patterns from ARIA attributes and a11y comments
454
- * If insufficient data, populate with minimal valid structure and note in completeness
455
- - ❌ NO external research or web searches (code-only extraction)
456
- ")
457
- ```
458
-
459
- **Wait for All Agents**:
460
-
461
- ```bash
462
- # Note: Agents run in parallel and write separate completeness reports
463
- # Each agent generates its own completeness-report.json directly
464
- # No synthesis phase needed
465
- echo "[Phase 1] Parallel agent analysis complete"
466
- ```
467
-
468
- <!-- TodoWrite: Update Phase 1.1-1.3 → completed (all 3 agents complete together) -->
469
-
470
- ---
471
-
472
- ## Output Files
473
-
474
- ### Generated Files
475
-
476
- **Location**: `${base_path}/`
477
-
478
- **Directory Structure**:
479
- ```
480
- ${base_path}/
481
- ├── style-extraction/
482
- │ └── style-1/
483
- │ └── design-tokens.json # Production-ready design tokens with code snippets
484
- ├── animation-extraction/
485
- │ └── animation-tokens.json # Animation/transition tokens with code snippets
486
- ├── layout-extraction/
487
- │ └── layout-templates.json # Layout patterns with code snippets
488
- └── .intermediates/
489
- └── import-analysis/
490
- └── discovered-files.json # All discovered files (JSON format)
491
- ```
492
-
493
- **Files**:
494
- 1. **style-extraction/style-1/design-tokens.json**
495
- - Production-ready design tokens
496
- - Categories: colors, typography, spacing, opacity, border_radius, shadows, breakpoints
497
- - Metadata: extraction_source, files_analyzed, completeness assessment, **code_snippets**
498
- - **Code snippets**: Complete code blocks from source files (CSS variables, theme configs, inline styles)
499
-
500
- 2. **animation-extraction/animation-tokens.json**
501
- - Animation tokens: duration, easing, transitions, keyframes, interactions
502
- - Framework detection: css-animations, framer-motion, gsap, etc.
503
- - Metadata: extraction_source, completeness assessment, **code_snippets**
504
- - **Code snippets**: Complete animation blocks (@keyframes, transition configs, JS animations)
505
-
506
- 3. **layout-extraction/layout-templates.json**
507
- - Layout templates for each discovered component
508
- - Extraction metadata: naming_convention, layout_system, responsive strategy, **code_snippets**
509
- - Component patterns with DOM structure and CSS rules
510
- - **Code snippets**: Complete component/structure code (HTML, CSS utilities, React components)
511
-
512
- **Intermediate Files**: `.intermediates/import-analysis/`
513
- - `discovered-files.json` - All discovered files in JSON format with counts and metadata
514
-
515
- ---
516
-
517
- ## Error Handling
518
-
519
- ### Common Errors
520
-
521
- | Error | Cause | Resolution |
522
- |-------|-------|------------|
523
- | No files discovered | Wrong --source path or no style files in directory | Verify --source parameter points to correct directory with style files |
524
- | Agent reports "failed" status | No tokens found in any file | Review file content, check if files contain design tokens |
525
- | Empty completeness reports | Files exist but contain no extractable tokens | Manually verify token definitions in source files |
526
- | Missing file type | File extensions not recognized | Check that files use standard extensions (.css, .scss, .js, .ts, .html) |
527
-
528
- ---
529
-
530
- ## Best Practices
531
-
532
- 1. **Point to the right directory**: Use `--source` to specify the directory containing your style files (e.g., `./src`, `./app`, `./styles`)
533
- 2. **Let automatic discovery work**: The command will find all relevant files - no need to specify patterns
534
- 3. **Specify target design run**: Use `--design-id` for existing design run or `--session` to use session's latest design run (one of these is required)
535
- 4. **Cross-reference agent reports**: Compare all three completeness reports (style, animation, layout) to identify gaps
536
- 5. **Review missing content**: Check `_metadata.completeness` field in reports for actionable improvements
537
- 6. **Verify file discovery**: Check `${base_path}/.intermediates/import-analysis/discovered-files.json` if agents report no data
1
+ ---
2
+ name: workflow:ui-design:import-from-code
3
+ description: Import design system from code files (CSS/JS/HTML/SCSS) with automatic file discovery and parallel agent analysis
4
+ argument-hint: "[--design-id <id>] [--session <id>] [--source <path>]"
5
+ allowed-tools: Read,Write,Bash,Glob,Grep,Task,TodoWrite
6
+ auto-continue: true
7
+ ---
8
+
9
+ # UI Design: Import from Code
10
+
11
+ ## Overview
12
+
13
+ Extract design system tokens from source code files (CSS/SCSS/JS/TS/HTML) using parallel agent analysis. Each agent can reference any file type for cross-source token extraction, and directly generates completeness reports with findings and gaps.
14
+
15
+ **Key Characteristics**:
16
+ - Executes parallel agent analysis (3 agents: Style, Animation, Layout)
17
+ - Each agent can read ALL file types (CSS/SCSS/JS/TS/HTML) for cross-reference
18
+ - Direct completeness reporting without synthesis phase
19
+ - Graceful failure handling with detailed missing content analysis
20
+ - Returns concrete analysis results with recommendations
21
+
22
+ ## Core Functionality
23
+
24
+ - **File Discovery**: Auto-discover or target specific CSS/SCSS/JS/HTML files
25
+ - **Parallel Analysis**: 3 agents extract tokens simultaneously with cross-file-type support
26
+ - **Completeness Reporting**: Each agent reports found tokens, missing content, and recommendations
27
+ - **Cross-Source Extraction**: Agents can reference any file type (e.g., Style agent can read JS theme configs)
28
+
29
+ ## Usage
30
+
31
+ ### Command Syntax
32
+
33
+ ```bash
34
+ /workflow:ui-design:import-from-code [FLAGS]
35
+
36
+ # Flags
37
+ --design-id <id> Design run ID to import into (must exist)
38
+ --session <id> Session ID (uses latest design run in session)
39
+ --source <path> Source code directory to analyze (required)
40
+ ```
41
+
42
+ **Note**: All file discovery is automatic. The command will scan the source directory and find all relevant style files (CSS, SCSS, JS, HTML) automatically.
43
+
44
+ ## Execution Process
45
+
46
+ ```
47
+ Input Parsing:
48
+ ├─ Parse flags: --design-id, --session, --source
49
+ └─ Decision (base path resolution):
50
+ ├─ --design-id provided → Exact match by design ID
51
+ ├─ --session provided → Latest design run in session
52
+ └─ Neither → ERROR: Must provide --design-id or --session
53
+
54
+ Phase 0: Setup & File Discovery
55
+ ├─ Step 1: Resolve base path
56
+ ├─ Step 2: Initialize directories
57
+ └─ Step 3: Discover files using script
58
+
59
+ Phase 1: Parallel Agent Analysis (3 agents)
60
+ ├─ Style Agent → design-tokens.json + code_snippets
61
+ ├─ Animation Agent → animation-tokens.json + code_snippets
62
+ └─ Layout Agent → layout-templates.json + code_snippets
63
+ ```
64
+
65
+ ### Step 1: Setup & File Discovery
66
+
67
+ **Purpose**: Initialize session, discover and categorize code files
68
+
69
+ **Operations**:
70
+
71
+ ```bash
72
+ # 1. Determine base path with priority: --design-id > --session > error
73
+ if [ -n "$DESIGN_ID" ]; then
74
+ # Exact match by design ID
75
+ relative_path=$(find .workflow -name "${DESIGN_ID}" -type d -print -quit)
76
+ if [ -z "$relative_path" ]; then
77
+ echo "ERROR: Design run not found: $DESIGN_ID"
78
+ echo "HINT: Run '/workflow:ui-design:list' to see available design runs"
79
+ exit 1
80
+ fi
81
+ elif [ -n "$SESSION_ID" ]; then
82
+ # Latest in session
83
+ relative_path=$(find .workflow/active/WFS-$SESSION_ID -name "design-run-*" -type d -printf "%T@ %p\n" 2>/dev/null | sort -nr | head -1 | cut -d' ' -f2)
84
+ if [ -z "$relative_path" ]; then
85
+ echo "ERROR: No design run found in session: $SESSION_ID"
86
+ echo "HINT: Create a design run first or provide --design-id"
87
+ exit 1
88
+ fi
89
+ else
90
+ echo "ERROR: Must provide --design-id or --session parameter"
91
+ exit 1
92
+ fi
93
+
94
+ base_path=$(cd "$relative_path" && pwd)
95
+ design_id=$(basename "$base_path")
96
+
97
+ # 2. Initialize directories
98
+ source="${source:-.}"
99
+ intermediates_dir="${base_path}/.intermediates/import-analysis"
100
+ mkdir -p "$intermediates_dir"
101
+
102
+ echo "[Phase 0] File Discovery Started"
103
+ echo " Design ID: $design_id"
104
+ echo " Source: $source"
105
+ echo " Output: $base_path"
106
+
107
+ # 3. Discover files using script
108
+ discovery_file="${intermediates_dir}/discovered-files.json"
109
+ ccw tool exec discover_design_files '{"sourceDir":"'"$source"'","outputPath":"'"$discovery_file"'"}'
110
+
111
+ echo " Output: $discovery_file"
112
+ ```
113
+
114
+ <!-- TodoWrite: Initialize todo list -->
115
+
116
+ **TodoWrite**:
117
+ ```json
118
+ [
119
+ {"content": "Phase 0: 发现和分类代码文件", "status": "in_progress", "activeForm": "发现代码文件"},
120
+ {"content": "Phase 1.1: Style Agent - 提取视觉token及代码片段 (design-tokens.json + code_snippets)", "status": "pending", "activeForm": "提取视觉token"},
121
+ {"content": "Phase 1.2: Animation Agent - 提取动画token及代码片段 (animation-tokens.json + code_snippets)", "status": "pending", "activeForm": "提取动画token"},
122
+ {"content": "Phase 1.3: Layout Agent - 提取布局模式及代码片段 (layout-templates.json + code_snippets)", "status": "pending", "activeForm": "提取布局模式"}
123
+ ]
124
+ ```
125
+
126
+ **File Discovery Behavior**:
127
+
128
+ - **Automatic discovery**: Intelligently scans source directory for all style-related files
129
+ - **Supported file types**: CSS, SCSS, JavaScript, TypeScript, HTML
130
+ - **Smart filtering**: Finds theme-related JS/TS files (e.g., tailwind.config.js, theme.js, styled-components)
131
+ - **Exclusions**: Automatically excludes `node_modules/`, `dist/`, `.git/`, and build directories
132
+ - **Output**: Single JSON file `discovered-files.json` in `.intermediates/import-analysis/`
133
+ - Structure: `{ "css": [...], "js": [...], "html": [...], "counts": {...}, "discovery_time": "..." }`
134
+ - Generated via bash commands using `find` + JSON formatting
135
+
136
+ <!-- TodoWrite: Update Phase 0 → completed, Phase 1.1-1.3 → in_progress (all 3 agents in parallel) -->
137
+
138
+ ---
139
+
140
+ ### Step 2: Parallel Agent Analysis
141
+
142
+ **Purpose**: Three agents analyze all file types in parallel, each producing completeness-report.json
143
+
144
+ **Operations**:
145
+ - **Style Agent**: Extracts visual tokens (colors, typography, spacing) from ALL files (CSS/SCSS/JS/HTML)
146
+ - **Animation Agent**: Extracts animations/transitions from ALL files
147
+ - **Layout Agent**: Extracts layout patterns/component structures from ALL files
148
+
149
+ **Validation**:
150
+ - Each agent can reference any file type (not restricted to single type)
151
+ - Direct output: Each agent generates completeness-report.json with findings + missing content
152
+ - No synthesis needed: Agents produce final output directly
153
+
154
+ ```bash
155
+ echo "[Phase 1] Starting parallel agent analysis (3 agents)"
156
+ ```
157
+
158
+ #### Style Agent Task (design-tokens.json, style-guide.md)
159
+
160
+ **Agent Task**:
161
+
162
+ ```javascript
163
+ Task(subagent_type="ui-design-agent",
164
+ prompt="[STYLE_TOKENS_EXTRACTION]
165
+ Extract visual design tokens from code files using code import extraction pattern.
166
+
167
+ MODE: style-extraction | SOURCE: ${source} | BASE_PATH: ${base_path}
168
+
169
+ ## Input Files
170
+
171
+ **Discovered Files**: ${intermediates_dir}/discovered-files.json
172
+ $(cat \"${intermediates_dir}/discovered-files.json\" 2>/dev/null | grep -E '(count|files)' | head -30)
173
+
174
+ ## Code Import Extraction Strategy
175
+
176
+ **Step 0: Fast Conflict Detection** (Use Bash/Grep for quick global scan)
177
+ - Quick scan: \`rg --color=never -n "^\\s*--primary:|^\\s*--secondary:|^\\s*--accent:" --type css ${source}\` to find core color definitions with line numbers
178
+ - Semantic search: \`rg --color=never -B3 -A1 "^\\s*--primary:" --type css ${source}\` to capture surrounding context and comments
179
+ - Core token scan: Search for --primary, --secondary, --accent, --background patterns to detect all theme-critical definitions
180
+ - Pattern: rg → Extract values → Compare → If different → Read full context with comments → Record conflict
181
+ - Alternative (if many files): Execute CLI analysis for comprehensive report:
182
+ \`\`\`bash
183
+ cd ${source} && gemini -p \"
184
+ PURPOSE: Detect color token conflicts across all CSS/SCSS/JS files
185
+ TASK: • Scan all files for color definitions • Identify conflicting values • Extract semantic comments
186
+ MODE: analysis
187
+ CONTEXT: @**/*.css @**/*.scss @**/*.js @**/*.ts
188
+ EXPECTED: JSON report listing conflicts with file:line, values, semantic context
189
+ RULES: Focus on core tokens | Report ALL variants | analysis=READ-ONLY
190
+ \"
191
+ \`\`\`
192
+
193
+ **Step 1: Load file list**
194
+ - Read(${intermediates_dir}/discovered-files.json)
195
+ - Extract: file_types.css.files, file_types.js.files, file_types.html.files
196
+
197
+ **Step 2: Cross-source token extraction**
198
+ - CSS/SCSS: Colors, typography, spacing, shadows, borders
199
+ - JavaScript/TypeScript: Theme configs (Tailwind, styled-components, CSS-in-JS)
200
+ - HTML: Inline styles, usage patterns
201
+
202
+ **Step 3: Validation and Conflict Detection**
203
+ - Report missing tokens WITHOUT inference (mark as "missing" in _metadata.completeness)
204
+ - Detect and report inconsistent values across files (list ALL variants with file:line sources)
205
+ - Report missing categories WITHOUT auto-filling (document gaps for manual review)
206
+ - CRITICAL: Verify core tokens (primary, secondary, accent) against semantic comments in source code
207
+
208
+ ## Output Files
209
+
210
+ **Target Directory**: ${base_path}/style-extraction/style-1/
211
+
212
+ **Files to Generate**:
213
+ 1. **design-tokens.json**
214
+ - Follow [DESIGN_SYSTEM_GENERATION_TASK] standard token structure
215
+ - Add \"_metadata.extraction_source\": \"code_import\"
216
+ - Add \"_metadata.files_analyzed\": {css, js, html file lists}
217
+ - Add \"_metadata.completeness\": {status, missing_categories, recommendations}
218
+ - Add \"_metadata.conflicts\": Array of conflicting definitions (MANDATORY if conflicts exist)
219
+ - Add \"_metadata.code_snippets\": Map of code snippets (see below)
220
+ - Add \"_metadata.usage_recommendations\": Usage patterns from code (see below)
221
+ - Include \"source\" field for each token (e.g., \"file.css:23\")
222
+
223
+ **Code Snippet Recording**:
224
+ - For each extracted token, record the actual code snippet in `_metadata.code_snippets`
225
+ - Structure:
226
+ ```json
227
+ \"code_snippets\": {
228
+ \"file.css:23\": {
229
+ \"lines\": \"23-27\",
230
+ \"snippet\": \":root {\\n --color-primary: oklch(0.5555 0.15 270);\\n /* Primary brand color */\\n --color-primary-hover: oklch(0.6 0.15 270);\\n}\",
231
+ \"context\": \"css-variable\"
232
+ }
233
+ }
234
+ ```
235
+ - Context types: \"css-variable\" | \"css-class\" | \"js-object\" | \"js-theme-config\" | \"inline-style\"
236
+ - Record complete code blocks with all dependencies and relevant comments
237
+ - Typical ranges: Simple declarations (1-5 lines), Utility classes (5-15 lines), Complete configs (15-50 lines)
238
+ - Preserve original formatting and indentation
239
+
240
+ **Conflict Detection and Reporting**:
241
+ - When the same token is defined differently across multiple files, record in `_metadata.conflicts`
242
+ - Follow Agent schema for conflicts array structure (see ui-design-agent.md)
243
+ - Each conflict MUST include: token_name, category, all definitions with context, selected_value, selection_reason
244
+ - Selection priority:
245
+ 1. Definitions with semantic comments explaining intent (/* Blue theme */, /* Primary brand color */)
246
+ 2. Definitions that align with overall color scheme described in comments
247
+ 3. When in doubt, report ALL variants and flag for manual review in completeness.recommendations
248
+
249
+ **Usage Recommendations Generation**:
250
+ - Analyze code usage patterns to extract `_metadata.usage_recommendations` (see ui-design-agent.md schema)
251
+ - **Typography recommendations**:
252
+ * `common_sizes`: Identify most frequent font size usage (e.g., \"body_text\": \"base (1rem)\")
253
+ * `common_combinations`: Extract heading+body pairings from actual usage (e.g., h1 with p tags)
254
+ - **Spacing recommendations**:
255
+ * `size_guide`: Categorize spacing values into tight/normal/loose based on frequency
256
+ * `common_patterns`: Extract frequent padding/margin combinations from components
257
+ - Analysis method: Scan code for class/style usage frequency, extract patterns from component implementations
258
+ - Optional: If insufficient usage data, mark fields as empty arrays/objects with note in completeness.recommendations
259
+
260
+ ## Code Import Specific Requirements
261
+ - ✅ Read discovered-files.json FIRST to get file paths
262
+ - ✅ Track extraction source for each token (file:line)
263
+ - ✅ Record complete code snippets in _metadata.code_snippets (complete blocks with dependencies/comments)
264
+ - ✅ Include completeness assessment in _metadata
265
+ - ✅ Report inconsistent values with ALL source locations in _metadata.conflicts (DO NOT auto-normalize or choose)
266
+ - ✅ CRITICAL: Verify core theme tokens (primary, secondary, accent) match source code semantic intent
267
+ - ✅ When conflicts exist, prefer definitions with semantic comments explaining intent
268
+ - ❌ NO inference, NO smart filling, NO automatic conflict resolution
269
+ - ❌ NO external research or web searches (code-only extraction)
270
+ ")
271
+ ```
272
+
273
+ #### Animation Agent Task (animation-tokens.json, animation-guide.md)
274
+
275
+ **Agent Task**:
276
+
277
+ ```javascript
278
+ Task(subagent_type="ui-design-agent",
279
+ prompt="[ANIMATION_TOKEN_GENERATION_TASK]
280
+ Extract animation tokens from code files using code import extraction pattern.
281
+
282
+ MODE: animation-extraction | SOURCE: ${source} | BASE_PATH: ${base_path}
283
+
284
+ ## Input Files
285
+
286
+ **Discovered Files**: ${intermediates_dir}/discovered-files.json
287
+ $(cat \"${intermediates_dir}/discovered-files.json\" 2>/dev/null | grep -E '(count|files)' | head -30)
288
+
289
+ ## Code Import Extraction Strategy
290
+
291
+ **Step 0: Fast Animation Discovery** (Use Bash/Grep for quick pattern detection)
292
+ - Quick scan: \`rg --color=never -n "@keyframes|animation:|transition:" --type css ${source}\` to find animation definitions with line numbers
293
+ - Framework detection: \`rg --color=never "framer-motion|gsap|@react-spring|react-spring" --type js --type ts ${source}\` to detect animation frameworks
294
+ - Pattern categorization: \`rg --color=never -B2 -A5 "@keyframes" --type css ${source}\` to extract keyframe animations with context
295
+ - Pattern: rg → Identify animation types → Map framework usage → Prioritize extraction targets
296
+ - Alternative (if complex framework mix): Execute CLI analysis for comprehensive report:
297
+ \`\`\`bash
298
+ cd ${source} && gemini -p \"
299
+ PURPOSE: Detect animation frameworks and patterns
300
+ TASK: • Identify frameworks • Map animation patterns • Categorize by complexity
301
+ MODE: analysis
302
+ CONTEXT: @**/*.css @**/*.scss @**/*.js @**/*.ts
303
+ EXPECTED: JSON report listing frameworks, animation types, file locations
304
+ RULES: Focus on framework consistency | Map all animations | analysis=READ-ONLY
305
+ \"
306
+ \`\`\`
307
+
308
+ **Step 1: Load file list**
309
+ - Read(${intermediates_dir}/discovered-files.json)
310
+ - Extract: file_types.css.files, file_types.js.files, file_types.html.files
311
+
312
+ **Step 2: Cross-source animation extraction**
313
+ - CSS/SCSS: @keyframes, transitions, animation properties
314
+ - JavaScript/TypeScript: Animation frameworks (Framer Motion, GSAP), CSS-in-JS
315
+ - HTML: Inline styles, data-animation attributes
316
+
317
+ **Step 3: Framework detection & normalization**
318
+ - Detect animation frameworks used (css-animations | framer-motion | gsap | none)
319
+ - Normalize into semantic token system
320
+ - Cross-reference CSS animations with JS configs
321
+
322
+ ## Output Files
323
+
324
+ **Target Directory**: ${base_path}/animation-extraction/
325
+
326
+ **Files to Generate**:
327
+ 1. **animation-tokens.json**
328
+ - Follow [ANIMATION_TOKEN_GENERATION_TASK] standard structure
329
+ - Add \"_metadata.framework_detected\"
330
+ - Add \"_metadata.files_analyzed\"
331
+ - Add \"_metadata.completeness\"
332
+ - Add \"_metadata.code_snippets\": Map of code snippets (same format as Style Agent)
333
+ - Include \"source\" field for each token
334
+
335
+ **Code Snippet Recording**:
336
+ - Record actual animation/transition code in `_metadata.code_snippets`
337
+ - Context types: \"css-keyframes\" | \"css-transition\" | \"js-animation\" | \"framer-motion\" | \"gsap\"
338
+ - Record complete blocks: @keyframes animations (10-30 lines), transition configs (5-15 lines), JS animation objects (15-50 lines)
339
+ - Include all animation steps, timing functions, and related comments
340
+ - Preserve original formatting and framework-specific syntax
341
+
342
+ ## Code Import Specific Requirements
343
+ - ✅ Read discovered-files.json FIRST to get file paths
344
+ - ✅ Detect animation framework if present
345
+ - ✅ Track extraction source for each token (file:line)
346
+ - ✅ Record complete code snippets in _metadata.code_snippets (complete animation blocks with all steps/timing)
347
+ - ✅ Normalize framework-specific syntax into standard tokens
348
+ - ❌ NO external research or web searches (code-only extraction)
349
+ ")
350
+ ```
351
+
352
+ #### Layout Agent Task (layout-templates.json, layout-guide.md)
353
+
354
+ **Agent Task**:
355
+
356
+ ```javascript
357
+ Task(subagent_type="ui-design-agent",
358
+ prompt="[LAYOUT_TEMPLATE_GENERATION_TASK]
359
+ Extract layout patterns from code files using code import extraction pattern.
360
+
361
+ MODE: layout-extraction | SOURCE: ${source} | BASE_PATH: ${base_path}
362
+
363
+ ## Input Files
364
+
365
+ **Discovered Files**: ${intermediates_dir}/discovered-files.json
366
+ $(cat \"${intermediates_dir}/discovered-files.json\" 2>/dev/null | grep -E '(count|files)' | head -30)
367
+
368
+ ## Code Import Extraction Strategy
369
+
370
+ **Step 0: Fast Component Discovery** (Use Bash/Grep for quick component scan)
371
+ - Layout pattern scan: \`rg --color=never -n "display:\\s*(grid|flex)|grid-template" --type css ${source}\` to find layout systems
372
+ - Component class scan: \`rg --color=never "class.*=.*\\"[^\"]*\\b(btn|button|card|input|modal|dialog|dropdown)" --type html --type js --type ts ${source}\` to identify UI components
373
+ - Universal component heuristic: Components appearing in 3+ files = universal, <3 files = specialized
374
+ - Pattern: rg → Count occurrences → Classify by frequency → Prioritize universal components
375
+ - Alternative (if large codebase): Execute CLI analysis for comprehensive categorization:
376
+ \`\`\`bash
377
+ cd ${source} && gemini -p \"
378
+ PURPOSE: Classify components as universal vs specialized
379
+ TASK: • Identify UI components • Classify reusability • Map layout systems
380
+ MODE: analysis
381
+ CONTEXT: @**/*.css @**/*.scss @**/*.js @**/*.ts @**/*.html
382
+ EXPECTED: JSON report categorizing components, layout patterns, naming conventions
383
+ RULES: Focus on component reusability | Identify layout systems | analysis=READ-ONLY
384
+ \"
385
+ \`\`\`
386
+
387
+ **Step 1: Load file list**
388
+ - Read(${intermediates_dir}/discovered-files.json)
389
+ - Extract: file_types.css.files, file_types.js.files, file_types.html.files
390
+
391
+ **Step 2: Cross-source layout extraction**
392
+ - CSS/SCSS: Grid systems, flexbox utilities, layout classes, media queries
393
+ - JavaScript/TypeScript: Layout components (React/Vue), grid configs
394
+ - HTML: Semantic structure, component hierarchies
395
+
396
+ **Component Classification** (MUST annotate in extraction):
397
+ - **Universal Components**: Reusable multi-component templates (buttons, inputs, cards, modals, etc.)
398
+ - **Specialized Components**: Module-specific components from code (feature-specific layouts, custom widgets, domain components)
399
+
400
+ **Step 3: System identification**
401
+ - Detect naming convention (BEM | SMACSS | utility-first | css-modules)
402
+ - Identify layout system (12-column | flexbox | css-grid | custom)
403
+ - Extract responsive strategy and breakpoints
404
+
405
+ ## Output Files
406
+
407
+ **Target Directory**: ${base_path}/layout-extraction/
408
+
409
+ **Files to Generate**:
410
+
411
+ 1. **layout-templates.json**
412
+ - Follow [LAYOUT_TEMPLATE_GENERATION_TASK] standard structure
413
+ - Add \"extraction_metadata\" section:
414
+ * extraction_source: \"code_import\"
415
+ * naming_convention: detected convention
416
+ * layout_system: {type, confidence, source_files}
417
+ * responsive: {breakpoints, mobile_first, source}
418
+ * completeness: {status, missing_items, recommendations}
419
+ * code_snippets: Map of code snippets (same format as Style Agent)
420
+ - For each component in \"layout_templates\":
421
+ * Include \"source\" field (file:line)
422
+ * **Include \"component_type\" field: \"universal\" | \"specialized\"**
423
+ * dom_structure with semantic HTML5
424
+ * css_layout_rules using var() placeholders
425
+ * Add \"description\" field explaining component purpose and classification rationale
426
+ * **Add \"usage_guide\" field for universal components** (see ui-design-agent.md schema):
427
+ - common_sizes: Extract size variants (small/medium/large) from code
428
+ - variant_recommendations: Document when to use each variant (primary/secondary/etc)
429
+ - usage_context: List typical usage scenarios from actual implementation
430
+ - accessibility_tips: Extract ARIA patterns and a11y notes from code
431
+
432
+ **Code Snippet Recording**:
433
+ - Record actual layout/component code in `extraction_metadata.code_snippets`
434
+ - Context types: \"css-grid\" | \"css-flexbox\" | \"css-utility\" | \"html-structure\" | \"react-component\"
435
+ - Record complete blocks: Utility classes (5-15 lines), HTML structures (10-30 lines), React components (20-100 lines)
436
+ - For components: include HTML structure + associated CSS rules + component logic
437
+ - Preserve original formatting and framework-specific syntax
438
+
439
+ ## Code Import Specific Requirements
440
+ - ✅ Read discovered-files.json FIRST to get file paths
441
+ - ✅ Detect and document naming conventions
442
+ - ✅ Identify layout system with confidence level
443
+ - ✅ Extract component variants and states from usage patterns
444
+ - ✅ **Classify each component as \"universal\" or \"specialized\"** based on:
445
+ * Universal: Reusable across multiple features (buttons, inputs, cards, modals)
446
+ * Specialized: Feature-specific or domain-specific (checkout form, dashboard widget)
447
+ - ✅ Record complete code snippets in extraction_metadata.code_snippets (complete components/structures)
448
+ - ✅ **Document classification rationale** in component description
449
+ - ✅ **Generate usage_guide for universal components** (REQUIRED):
450
+ * Analyze code to extract size variants (scan for size-related classes/props)
451
+ * Document variant usage from code comments and implementation patterns
452
+ * List usage contexts from component instances in codebase
453
+ * Extract accessibility patterns from ARIA attributes and a11y comments
454
+ * If insufficient data, populate with minimal valid structure and note in completeness
455
+ - ❌ NO external research or web searches (code-only extraction)
456
+ ")
457
+ ```
458
+
459
+ **Wait for All Agents**:
460
+
461
+ ```bash
462
+ # Note: Agents run in parallel and write separate completeness reports
463
+ # Each agent generates its own completeness-report.json directly
464
+ # No synthesis phase needed
465
+ echo "[Phase 1] Parallel agent analysis complete"
466
+ ```
467
+
468
+ <!-- TodoWrite: Update Phase 1.1-1.3 → completed (all 3 agents complete together) -->
469
+
470
+ ---
471
+
472
+ ## Output Files
473
+
474
+ ### Generated Files
475
+
476
+ **Location**: `${base_path}/`
477
+
478
+ **Directory Structure**:
479
+ ```
480
+ ${base_path}/
481
+ ├── style-extraction/
482
+ │ └── style-1/
483
+ │ └── design-tokens.json # Production-ready design tokens with code snippets
484
+ ├── animation-extraction/
485
+ │ └── animation-tokens.json # Animation/transition tokens with code snippets
486
+ ├── layout-extraction/
487
+ │ └── layout-templates.json # Layout patterns with code snippets
488
+ └── .intermediates/
489
+ └── import-analysis/
490
+ └── discovered-files.json # All discovered files (JSON format)
491
+ ```
492
+
493
+ **Files**:
494
+ 1. **style-extraction/style-1/design-tokens.json**
495
+ - Production-ready design tokens
496
+ - Categories: colors, typography, spacing, opacity, border_radius, shadows, breakpoints
497
+ - Metadata: extraction_source, files_analyzed, completeness assessment, **code_snippets**
498
+ - **Code snippets**: Complete code blocks from source files (CSS variables, theme configs, inline styles)
499
+
500
+ 2. **animation-extraction/animation-tokens.json**
501
+ - Animation tokens: duration, easing, transitions, keyframes, interactions
502
+ - Framework detection: css-animations, framer-motion, gsap, etc.
503
+ - Metadata: extraction_source, completeness assessment, **code_snippets**
504
+ - **Code snippets**: Complete animation blocks (@keyframes, transition configs, JS animations)
505
+
506
+ 3. **layout-extraction/layout-templates.json**
507
+ - Layout templates for each discovered component
508
+ - Extraction metadata: naming_convention, layout_system, responsive strategy, **code_snippets**
509
+ - Component patterns with DOM structure and CSS rules
510
+ - **Code snippets**: Complete component/structure code (HTML, CSS utilities, React components)
511
+
512
+ **Intermediate Files**: `.intermediates/import-analysis/`
513
+ - `discovered-files.json` - All discovered files in JSON format with counts and metadata
514
+
515
+ ---
516
+
517
+ ## Error Handling
518
+
519
+ ### Common Errors
520
+
521
+ | Error | Cause | Resolution |
522
+ |-------|-------|------------|
523
+ | No files discovered | Wrong --source path or no style files in directory | Verify --source parameter points to correct directory with style files |
524
+ | Agent reports "failed" status | No tokens found in any file | Review file content, check if files contain design tokens |
525
+ | Empty completeness reports | Files exist but contain no extractable tokens | Manually verify token definitions in source files |
526
+ | Missing file type | File extensions not recognized | Check that files use standard extensions (.css, .scss, .js, .ts, .html) |
527
+
528
+ ---
529
+
530
+ ## Best Practices
531
+
532
+ 1. **Point to the right directory**: Use `--source` to specify the directory containing your style files (e.g., `./src`, `./app`, `./styles`)
533
+ 2. **Let automatic discovery work**: The command will find all relevant files - no need to specify patterns
534
+ 3. **Specify target design run**: Use `--design-id` for existing design run or `--session` to use session's latest design run (one of these is required)
535
+ 4. **Cross-reference agent reports**: Compare all three completeness reports (style, animation, layout) to identify gaps
536
+ 5. **Review missing content**: Check `_metadata.completeness` field in reports for actionable improvements
537
+ 6. **Verify file discovery**: Check `${base_path}/.intermediates/import-analysis/discovered-files.json` if agents report no data