figma-to-code-agent 0.5.0 → 0.7.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 (193) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/README.md +69 -55
  3. package/README.zh-CN.md +173 -0
  4. package/dist/agent/ConversationContext.d.ts +91 -0
  5. package/dist/agent/ConversationContext.d.ts.map +1 -0
  6. package/dist/agent/ConversationContext.js +271 -0
  7. package/dist/agent/ConversationContext.js.map +1 -0
  8. package/dist/agent/DecisionEngine.d.ts +77 -0
  9. package/dist/agent/DecisionEngine.d.ts.map +1 -0
  10. package/dist/agent/DecisionEngine.js +414 -0
  11. package/dist/agent/DecisionEngine.js.map +1 -0
  12. package/dist/agent/ExecutionOrchestrator.d.ts +55 -0
  13. package/dist/agent/ExecutionOrchestrator.d.ts.map +1 -0
  14. package/dist/agent/ExecutionOrchestrator.js +360 -0
  15. package/dist/agent/ExecutionOrchestrator.js.map +1 -0
  16. package/dist/agent/IntentUnderstandingEngine.d.ts +43 -0
  17. package/dist/agent/IntentUnderstandingEngine.d.ts.map +1 -0
  18. package/dist/agent/IntentUnderstandingEngine.js +261 -0
  19. package/dist/agent/IntentUnderstandingEngine.js.map +1 -0
  20. package/dist/agent/index.d.ts +9 -0
  21. package/dist/agent/index.d.ts.map +1 -0
  22. package/dist/agent/index.js +30 -0
  23. package/dist/agent/index.js.map +1 -0
  24. package/dist/agent/types.d.ts +111 -0
  25. package/dist/agent/types.d.ts.map +1 -0
  26. package/dist/agent/types.js +6 -0
  27. package/dist/agent/types.js.map +1 -0
  28. package/dist/cli/InteractiveCLI.d.ts +109 -0
  29. package/dist/cli/InteractiveCLI.d.ts.map +1 -0
  30. package/dist/cli/InteractiveCLI.js +534 -0
  31. package/dist/cli/InteractiveCLI.js.map +1 -0
  32. package/dist/cli/ProgressDisplay.d.ts +117 -0
  33. package/dist/cli/ProgressDisplay.d.ts.map +1 -0
  34. package/dist/cli/ProgressDisplay.js +370 -0
  35. package/dist/cli/ProgressDisplay.js.map +1 -0
  36. package/dist/cli/index.d.ts +6 -0
  37. package/dist/cli/index.d.ts.map +1 -0
  38. package/dist/cli/index.js +22 -0
  39. package/dist/cli/index.js.map +1 -0
  40. package/dist/consistency/DesignConsistencyChecker.d.ts +125 -0
  41. package/dist/consistency/DesignConsistencyChecker.d.ts.map +1 -0
  42. package/dist/consistency/DesignConsistencyChecker.js +448 -0
  43. package/dist/consistency/DesignConsistencyChecker.js.map +1 -0
  44. package/dist/consistency/index.d.ts +5 -0
  45. package/dist/consistency/index.d.ts.map +1 -0
  46. package/dist/consistency/index.js +21 -0
  47. package/dist/consistency/index.js.map +1 -0
  48. package/dist/context/CodeStyleMatcher.d.ts +124 -0
  49. package/dist/context/CodeStyleMatcher.d.ts.map +1 -0
  50. package/dist/context/CodeStyleMatcher.js +558 -0
  51. package/dist/context/CodeStyleMatcher.js.map +1 -0
  52. package/dist/context/IncrementalUpdater.d.ts +97 -0
  53. package/dist/context/IncrementalUpdater.d.ts.map +1 -0
  54. package/dist/context/IncrementalUpdater.js +431 -0
  55. package/dist/context/IncrementalUpdater.js.map +1 -0
  56. package/dist/context/index.d.ts +6 -0
  57. package/dist/context/index.d.ts.map +1 -0
  58. package/dist/context/index.js +22 -0
  59. package/dist/context/index.js.map +1 -0
  60. package/dist/feedback/FeedbackLoop.d.ts +125 -0
  61. package/dist/feedback/FeedbackLoop.d.ts.map +1 -0
  62. package/dist/feedback/FeedbackLoop.js +353 -0
  63. package/dist/feedback/FeedbackLoop.js.map +1 -0
  64. package/dist/feedback/index.d.ts +5 -0
  65. package/dist/feedback/index.d.ts.map +1 -0
  66. package/dist/feedback/index.js +21 -0
  67. package/dist/feedback/index.js.map +1 -0
  68. package/dist/mcp/FigmaMCPIntegration.d.ts +72 -0
  69. package/dist/mcp/FigmaMCPIntegration.d.ts.map +1 -0
  70. package/dist/mcp/FigmaMCPIntegration.js +173 -0
  71. package/dist/mcp/FigmaMCPIntegration.js.map +1 -0
  72. package/dist/mcp/MCPServiceManager.d.ts +109 -0
  73. package/dist/mcp/MCPServiceManager.d.ts.map +1 -0
  74. package/dist/mcp/MCPServiceManager.js +237 -0
  75. package/dist/mcp/MCPServiceManager.js.map +1 -0
  76. package/dist/mcp/MCPToolAdapter.d.ts +73 -0
  77. package/dist/mcp/MCPToolAdapter.d.ts.map +1 -0
  78. package/dist/mcp/MCPToolAdapter.js +249 -0
  79. package/dist/mcp/MCPToolAdapter.js.map +1 -0
  80. package/dist/mcp/index.d.ts +7 -0
  81. package/dist/mcp/index.d.ts.map +1 -0
  82. package/dist/mcp/index.js +23 -0
  83. package/dist/mcp/index.js.map +1 -0
  84. package/dist/mcp-server/MCPServer.d.ts +125 -0
  85. package/dist/mcp-server/MCPServer.d.ts.map +1 -0
  86. package/dist/mcp-server/MCPServer.js +449 -0
  87. package/dist/mcp-server/MCPServer.js.map +1 -0
  88. package/dist/mcp-server/index.d.ts +5 -0
  89. package/dist/mcp-server/index.d.ts.map +1 -0
  90. package/dist/mcp-server/index.js +21 -0
  91. package/dist/mcp-server/index.js.map +1 -0
  92. package/dist/monitoring/ExecutionSummary.d.ts +160 -0
  93. package/dist/monitoring/ExecutionSummary.d.ts.map +1 -0
  94. package/dist/monitoring/ExecutionSummary.js +345 -0
  95. package/dist/monitoring/ExecutionSummary.js.map +1 -0
  96. package/dist/monitoring/Logger.d.ts +139 -0
  97. package/dist/monitoring/Logger.d.ts.map +1 -0
  98. package/dist/monitoring/Logger.js +406 -0
  99. package/dist/monitoring/Logger.js.map +1 -0
  100. package/dist/monitoring/index.d.ts +6 -0
  101. package/dist/monitoring/index.d.ts.map +1 -0
  102. package/dist/monitoring/index.js +22 -0
  103. package/dist/monitoring/index.js.map +1 -0
  104. package/dist/performance/LLMCache.d.ts +133 -0
  105. package/dist/performance/LLMCache.d.ts.map +1 -0
  106. package/dist/performance/LLMCache.js +358 -0
  107. package/dist/performance/LLMCache.js.map +1 -0
  108. package/dist/performance/ParallelProcessor.d.ts +89 -0
  109. package/dist/performance/ParallelProcessor.d.ts.map +1 -0
  110. package/dist/performance/ParallelProcessor.js +253 -0
  111. package/dist/performance/ParallelProcessor.js.map +1 -0
  112. package/dist/performance/TokenMonitor.d.ts +166 -0
  113. package/dist/performance/TokenMonitor.d.ts.map +1 -0
  114. package/dist/performance/TokenMonitor.js +315 -0
  115. package/dist/performance/TokenMonitor.js.map +1 -0
  116. package/dist/performance/index.d.ts +7 -0
  117. package/dist/performance/index.d.ts.map +1 -0
  118. package/dist/performance/index.js +23 -0
  119. package/dist/performance/index.js.map +1 -0
  120. package/dist/prototype/InteractivePrototypeGenerator.d.ts +175 -0
  121. package/dist/prototype/InteractivePrototypeGenerator.d.ts.map +1 -0
  122. package/dist/prototype/InteractivePrototypeGenerator.js +624 -0
  123. package/dist/prototype/InteractivePrototypeGenerator.js.map +1 -0
  124. package/dist/prototype/index.d.ts +5 -0
  125. package/dist/prototype/index.d.ts.map +1 -0
  126. package/dist/prototype/index.js +21 -0
  127. package/dist/prototype/index.js.map +1 -0
  128. package/dist/skill/SkillConfig.d.ts +66 -0
  129. package/dist/skill/SkillConfig.d.ts.map +1 -0
  130. package/dist/skill/SkillConfig.js +233 -0
  131. package/dist/skill/SkillConfig.js.map +1 -0
  132. package/dist/skill/SkillInterface.d.ts +102 -0
  133. package/dist/skill/SkillInterface.d.ts.map +1 -0
  134. package/dist/skill/SkillInterface.js +425 -0
  135. package/dist/skill/SkillInterface.js.map +1 -0
  136. package/dist/skill/index.d.ts +7 -0
  137. package/dist/skill/index.d.ts.map +1 -0
  138. package/dist/skill/index.js +23 -0
  139. package/dist/skill/index.js.map +1 -0
  140. package/dist/skill/types.d.ts +103 -0
  141. package/dist/skill/types.d.ts.map +1 -0
  142. package/dist/skill/types.js +6 -0
  143. package/dist/skill/types.js.map +1 -0
  144. package/dist/templates/TemplateManager.d.ts +147 -0
  145. package/dist/templates/TemplateManager.d.ts.map +1 -0
  146. package/dist/templates/TemplateManager.js +418 -0
  147. package/dist/templates/TemplateManager.js.map +1 -0
  148. package/dist/templates/index.d.ts +6 -0
  149. package/dist/templates/index.d.ts.map +1 -0
  150. package/dist/templates/index.js +10 -0
  151. package/dist/templates/index.js.map +1 -0
  152. package/dist/tools/CodeGenerationTool.d.ts +32 -0
  153. package/dist/tools/CodeGenerationTool.d.ts.map +1 -0
  154. package/dist/tools/CodeGenerationTool.js +63 -0
  155. package/dist/tools/CodeGenerationTool.js.map +1 -0
  156. package/dist/tools/FigmaExtractionTool.d.ts +45 -0
  157. package/dist/tools/FigmaExtractionTool.d.ts.map +1 -0
  158. package/dist/tools/FigmaExtractionTool.js +105 -0
  159. package/dist/tools/FigmaExtractionTool.js.map +1 -0
  160. package/dist/tools/ProjectAnalysisTool.d.ts +104 -0
  161. package/dist/tools/ProjectAnalysisTool.d.ts.map +1 -0
  162. package/dist/tools/ProjectAnalysisTool.js +428 -0
  163. package/dist/tools/ProjectAnalysisTool.js.map +1 -0
  164. package/dist/tools/ToolRegistry.d.ts +59 -0
  165. package/dist/tools/ToolRegistry.d.ts.map +1 -0
  166. package/dist/tools/ToolRegistry.js +162 -0
  167. package/dist/tools/ToolRegistry.js.map +1 -0
  168. package/dist/tools/TransformationTool.d.ts +30 -0
  169. package/dist/tools/TransformationTool.d.ts.map +1 -0
  170. package/dist/tools/TransformationTool.js +50 -0
  171. package/dist/tools/TransformationTool.js.map +1 -0
  172. package/dist/tools/index.d.ts +10 -0
  173. package/dist/tools/index.d.ts.map +1 -0
  174. package/dist/tools/index.js +32 -0
  175. package/dist/tools/index.js.map +1 -0
  176. package/dist/tools/types.d.ts +74 -0
  177. package/dist/tools/types.d.ts.map +1 -0
  178. package/dist/tools/types.js +6 -0
  179. package/dist/tools/types.js.map +1 -0
  180. package/dist/transformation/transformers/LayoutOptimizer.d.ts +8 -0
  181. package/dist/transformation/transformers/LayoutOptimizer.d.ts.map +1 -1
  182. package/dist/transformation/transformers/LayoutOptimizer.js +157 -15
  183. package/dist/transformation/transformers/LayoutOptimizer.js.map +1 -1
  184. package/dist/version/VersionManager.d.ts +128 -0
  185. package/dist/version/VersionManager.d.ts.map +1 -0
  186. package/dist/version/VersionManager.js +400 -0
  187. package/dist/version/VersionManager.js.map +1 -0
  188. package/dist/version/index.d.ts +5 -0
  189. package/dist/version/index.d.ts.map +1 -0
  190. package/dist/version/index.js +21 -0
  191. package/dist/version/index.js.map +1 -0
  192. package/package.json +3 -1
  193. package/QUICKSTART.md +0 -168
package/CHANGELOG.md CHANGED
@@ -1,5 +1,49 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.7.0] - 2026-02-27
4
+
5
+ ### Added
6
+ - MCP (Model Context Protocol) server implementation for integration with Claude Desktop and Kiro IDE
7
+ - Kiro Skill interface for seamless design-to-code workflow in Kiro IDE
8
+ - Design consistency checker for analyzing design token consistency
9
+ - Interactive prototype generator with state management
10
+ - Custom template system for code generation
11
+ - Comprehensive property-based tests for agent components (ConversationContext, DecisionEngine, ExecutionOrchestrator, IntentUnderstandingEngine)
12
+ - Property-based tests for ToolRegistry
13
+ - End-to-end agent workflow tests
14
+ - Cross-delivery consistency integration tests
15
+ - Agent architecture with conversation context, intent understanding, decision engine, and execution orchestrator
16
+
17
+ ### Changed
18
+ - Updated README with bilingual support (English and Chinese)
19
+ - Refined documentation structure and removed redundant content
20
+ - Fixed broken documentation links
21
+ - Improved CLI guide with comprehensive examples and troubleshooting
22
+
23
+ ### Documentation
24
+ - Added MCP Service Configuration Guide (docs/MCP_GUIDE.md)
25
+ - Added Kiro Skill Usage Guide (docs/KIRO_SKILL_GUIDE.md)
26
+ - Added CLI Usage Guide (docs/CLI_GUIDE.md)
27
+ - Created README.zh-CN.md for Chinese documentation
28
+ - Updated QUICKSTART.md with clearer instructions
29
+
30
+ ### Tests
31
+ - Total test count: 222 tests (all passing)
32
+ - Added 7 new test files for agent components and integrations
33
+ - Updated jest.config.js to handle uuid module transformation
34
+
35
+ ## [0.6.0] - 2026-02-13
36
+
37
+ ### Added
38
+ - Property tests for Property 3 (component identification completeness) and Property 4 (image asset extraction)
39
+ - Real Figma data end-to-end tests: 29 tests covering 4 real design files (MIUI12 Navigation, Homepage, Shopping Cart, Product Page)
40
+ - Cross-design pipeline consistency tests (React vs Vue, css-modules vs css)
41
+ - Full document processing test for large Figma canvas
42
+
43
+ ### Improved
44
+ - Property test coverage now spans Properties 1-4, 5-44 (complete)
45
+ - Total test count: 309 tests across 42 test suites
46
+
3
47
  ## [0.5.0] - 2026-02-13
4
48
 
5
49
  ### Added
package/README.md CHANGED
@@ -3,10 +3,33 @@
3
3
  Convert Figma designs to production-ready React/Vue components. Supports CSS Modules, Tailwind, and plain CSS.
4
4
 
5
5
  > 📖 New here? Check the [Quick Start Guide](QUICKSTART.md) for step-by-step setup.
6
+ >
7
+ > English | [中文](README.zh-CN.md)
8
+
9
+ ## Usage
10
+
11
+ ### 1. CLI Tool
12
+ For local development and CI/CD integration.
13
+
14
+ ```bash
15
+ npx figma-to-code-agent --token YOUR_TOKEN --file FILE_KEY --framework react --output ./output
16
+ ```
17
+
18
+ [Full CLI Guide →](docs/CLI_GUIDE.md)
19
+
20
+ ### 2. MCP Service
21
+ Integrate with Claude Desktop or Kiro IDE, generate code through AI conversations.
22
+
23
+ [MCP Configuration Guide →](docs/MCP_GUIDE.md)
24
+
25
+ ### 3. Kiro Skill
26
+ Use as a Skill in Kiro IDE for seamless design-to-code workflow.
27
+
28
+ [Kiro Skill Guide →](docs/KIRO_SKILL_GUIDE.md)
6
29
 
7
30
  ## Examples
8
31
 
9
- ### Example 1 — MIUI12 官网 (全局导航)
32
+ ### Example 1 — MIUI12 Website (Global Navigation)
10
33
 
11
34
  | Original Design | React | Vue |
12
35
  |:-:|:-:|:-:|
@@ -34,23 +57,33 @@ Convert Figma designs to production-ready React/Vue components. Supports CSS Mod
34
57
 
35
58
  - 🎨 Extract designs from Figma API with caching and rate-limit handling
36
59
  - ⚛️ Generate React (.jsx/.tsx) and Vue (.vue) components
37
- - 🎭 CSS Modules, Tailwind, or plain CSS
38
- - 📐 Absolute positioning with responsive scaling (auto-fits viewport)
39
- - 🖼️ Image export at 2x resolution, vector icon auto-detection and PNG export
40
- - 🔤 Full typography support (font family, size, weight, line-height, letter-spacing, color)
41
- - 👁️ Figma layer filtering (hidden layers, mask shapes)
60
+ - 🎭 Support CSS Modules, Tailwind CSS, and plain CSS
61
+ - 📐 Responsive layout with viewport adaptation
62
+ - 🖼️ 2x resolution image export, auto-detect vector icons
63
+ - 🎯 Design token extraction (CSS variables, SCSS, JSON, JS)
64
+ - Accessibility enhancements (ARIA roles, alt text)
65
+ - ⚡ Performance optimization (lazy loading, code splitting, style deduplication)
42
66
  - 🤖 Optional AI enhancements (semantic naming, component splitting, code optimization)
67
+ - 🔌 MCP server (integrate with Claude Desktop / Kiro IDE)
68
+ - 🎯 Kiro Skill (use as a skill in Kiro IDE)
69
+ - 📊 Design consistency checker
70
+ - 🎮 Interactive prototype generator
43
71
 
44
72
  ## Install
45
73
 
74
+ ### Global Installation
46
75
  ```bash
47
76
  npm install -g figma-to-code-agent
48
77
  ```
49
78
 
50
- Or use directly with npx (no install needed):
79
+ ### Local Installation
80
+ ```bash
81
+ npm install figma-to-code-agent
82
+ ```
51
83
 
84
+ ### Use with npx (no installation required)
52
85
  ```bash
53
- npx figma-to-code-agent --token YOUR_FIGMA_TOKEN --file FILE_KEY --node NODE_ID --output ./output
86
+ npx figma-to-code-agent --token YOUR_TOKEN --file FILE_KEY --output ./output
54
87
  ```
55
88
 
56
89
  ## Quick Start
@@ -64,78 +97,60 @@ npx figma-to-code-agent \
64
97
  --framework react \
65
98
  --output ./output
66
99
 
67
- # Generate and preview in browser
100
+ # Generate and preview
68
101
  npx figma-to-code-agent \
69
102
  --token YOUR_FIGMA_TOKEN \
70
103
  --file FILE_KEY \
71
- --node NODE_ID \
72
104
  --framework react \
73
105
  --output ./output \
74
106
  --preview
75
107
  ```
76
108
 
109
+ For more usage options, see the [Quick Start Guide](docs/QUICKSTART.md).
110
+
77
111
  ## How It Works
78
112
 
79
- 1. Fetches the Figma file data via API (with local caching)
80
- 2. Parses the design tree into an intermediate AST
81
- 3. Filters invisible layers, mask shapes, and transparent fills
82
- 4. Detects vector-only containers and exports them as PNG icons
83
- 5. Downloads images at 2x resolution
84
- 6. Generates framework-specific components with CSS Modules
85
- 7. Wraps output in a responsive scale container (no horizontal scrollbar)
113
+ 1. **Extract**: Fetch design data via Figma API (with caching)
114
+ 2. **Parse**: Parse design tree into intermediate AST
115
+ 3. **Transform**: Apply transformation pipeline (flatten, extract components, optimize, semantic naming)
116
+ 4. **Generate**: Generate framework-specific component code
117
+ 5. **Optimize**: Style deduplication, responsive handling, accessibility enhancements
118
+
119
+ For detailed architecture, see [Architecture Documentation](spec/ARCHITECTURE.md).
86
120
 
87
121
  ## CLI Options
88
122
 
89
123
  | Option | Description | Default |
90
124
  |--------|-------------|---------|
91
- | `--token <token>` | Figma API token (or `FIGMA_TOKEN` env) | — |
125
+ | `--token <token>` | Figma API token | — |
92
126
  | `--file <key>` | Figma file key | — |
93
- | `--node <id>` | Target node ID (e.g. `1502-102`) | root |
127
+ | `--node <id>` | Target node ID | root |
94
128
  | `--framework` | `react` or `vue` | `react` |
95
129
  | `--style` | `css-modules`, `tailwind`, or `css` | `css-modules` |
96
- | `--typescript` | Enable TypeScript output | `false` |
130
+ | `--typescript` | Enable TypeScript | `false` |
97
131
  | `--output <dir>` | Output directory | `./output` |
98
132
  | `--preview` | Preview in browser after generation | — |
133
+ | `--mcp` | Start MCP server mode | — |
99
134
 
100
- ### AI Options (optional)
135
+ ### AI Options
101
136
 
102
137
  | Option | Description |
103
138
  |--------|-------------|
104
139
  | `--llm-provider` | `bedrock`, `openai`, or `anthropic` |
105
140
  | `--llm-model` | Model name |
106
- | `--ai-naming` | AI-powered semantic component naming |
107
- | `--ai-splitting` | AI-powered component splitting |
141
+ | `--ai-naming` | AI-powered semantic naming |
108
142
  | `--ai-optimization` | AI-powered code optimization |
109
143
 
110
- ## Programmatic API
111
-
112
- ```typescript
113
- import { FigmaToCodeAgent } from 'figma-to-code-agent'
144
+ For complete options, see [CLI Usage Guide](docs/CLI_GUIDE.md).
114
145
 
115
- const agent = new FigmaToCodeAgent({
116
- figmaToken: 'your-token',
117
- fileKey: 'your-file-key',
118
- framework: 'react',
119
- styleMode: 'css-modules',
120
- typescript: false,
121
- outputDir: './output',
122
- })
146
+ ## Documentation
123
147
 
124
- const files = await agent.convert()
125
- ```
126
-
127
- ## Project Structure
128
-
129
- ```
130
- src/
131
- ├── extraction/ # Figma API client, MCP protocol, caching
132
- ├── transformation/ # AST parsing, layout optimization, transformers
133
- │ └── transformers/ # Component extraction, semantic naming, etc.
134
- ├── generation/ # React and Vue code generators
135
- ├── llm/ # LLM providers (Bedrock, OpenAI)
136
- ├── validation/ # Visual validation
137
- └── cli.ts # CLI entry point
138
- ```
148
+ - 📖 [Quick Start](QUICKSTART.md) - Get started in 5 minutes
149
+ - 🖥️ [CLI Guide](docs/CLI_GUIDE.md) - Complete CLI reference
150
+ - 🔌 [MCP Guide](docs/MCP_GUIDE.md) - Integrate with Claude/Kiro
151
+ - 🎯 [Kiro Skill Guide](docs/KIRO_SKILL_GUIDE.md) - Use in Kiro IDE
152
+ - 🏗️ [Architecture](spec/ARCHITECTURE.md) - System architecture
153
+ - 🎨 [Examples](assets/) - Real conversion examples
139
154
 
140
155
  ## Development
141
156
 
@@ -144,16 +159,15 @@ git clone https://github.com/lewiscutey/figma-to-code-agent.git
144
159
  cd figma-to-code-agent
145
160
  npm install
146
161
  npm run build # Compile TypeScript
147
- npm test # Run all tests (129 tests)
148
- npm run lint # ESLint
149
- npm run format # Prettier
162
+ npm test # Run tests (222 tests)
163
+ npm run lint # Lint code
150
164
  ```
151
165
 
152
166
  ## Requirements
153
167
 
154
168
  - Node.js 18+
155
- - npm
169
+ - Figma access token ([Get token](https://www.figma.com/developers/api#access-tokens))
156
170
 
157
171
  ## License
158
172
 
159
- MIT
173
+ MIT License - See [LICENSE](LICENSE) file for details
@@ -0,0 +1,173 @@
1
+ # Figma-to-Code Agent
2
+
3
+ 将 Figma 设计转换为生产就绪的 React/Vue 组件。支持 CSS Modules、Tailwind 和纯 CSS。
4
+
5
+ > 📖 新手入门?查看 [快速入门指南](QUICKSTART.md) 获取详细步骤。
6
+ >
7
+ > [English](README.md) | 中文
8
+
9
+ ## 使用方式
10
+
11
+ ### 1. 命令行工具(CLI)
12
+ 适合本地开发和 CI/CD 集成。
13
+
14
+ ```bash
15
+ npx figma-to-code-agent --token YOUR_TOKEN --file FILE_KEY --framework react --output ./output
16
+ ```
17
+
18
+ [完整 CLI 指南 →](docs/CLI_GUIDE.md)
19
+
20
+ ### 2. MCP 服务
21
+ 集成到 Claude Desktop 或 Kiro IDE,通过 AI 对话生成代码。
22
+
23
+ [MCP 配置指南 →](docs/MCP_GUIDE.md)
24
+
25
+ ### 3. Kiro Skill
26
+ 在 Kiro IDE 中作为 Skill 使用,提供无缝的设计到代码工作流。
27
+
28
+ [Kiro Skill 指南 →](docs/KIRO_SKILL_GUIDE.md)
29
+
30
+ ## 示例展示
31
+
32
+ ### 示例 1 — MIUI12 官网(全局导航)
33
+
34
+ | 原始设计 | React | Vue |
35
+ |:-:|:-:|:-:|
36
+ | ![Original](assets/example1/全局导航-黑.png) | ![React](assets/example1/generate/Figma%20to%20Code%20-%20React%20Test%20-%20%5Blocalhost%5D.png) | ![Vue](assets/example1/generate/Figma%20to%20Code%20-%20Vue%20Test%20-%20%5Blocalhost%5D.png) |
37
+
38
+ ### 示例 2 — 主页(World Peas)
39
+
40
+ | 原始设计 | React | Vue |
41
+ |:-:|:-:|:-:|
42
+ | ![Original](assets/example2/20260211-185255.png) | ![React](assets/example2/generate/Figma%20to%20Code%20-%20React%20Test%20-%20%5Blocalhost%5D.png) | ![Vue](assets/example2/generate/Figma%20to%20Code%20-%20Vue%20Test%20-%20%5Blocalhost%5D.png) |
43
+
44
+ ### 示例 3 — 购物车
45
+
46
+ | 原始设计 | React | Vue |
47
+ |:-:|:-:|:-:|
48
+ | ![Original](assets/example3/20260212-095453.png) | ![React](assets/example3/generate/Figma%20to%20Code%20-%20React%20Test%20-%20%5Blocalhost%5D.png) | ![Vue](assets/example3/generate/Figma%20to%20Code%20-%20Vue%20Test%20-%20%5Blocalhost%5D.png) |
49
+
50
+ ### 示例 4 — 产品页面
51
+
52
+ | 原始设计 | React | Vue |
53
+ |:-:|:-:|:-:|
54
+ | ![Original](assets/example4/20260212-095459.png) | ![React](assets/example4/generate/Figma%20to%20Code%20-%20React%20Test%20-%20%5Blocalhost%5D.png) | ![Vue](assets/example4/generate/Figma%20to%20Code%20-%20Vue%20Test%20-%20%5Blocalhost%5D.png) |
55
+
56
+ ## 功能特性
57
+
58
+ - 🎨 从 Figma API 提取设计,支持缓存和速率限制处理
59
+ - ⚛️ 生成 React (.jsx/.tsx) 和 Vue (.vue) 组件
60
+ - 🎭 支持 CSS Modules、Tailwind CSS 和纯 CSS
61
+ - 📐 响应式布局,自适应视口
62
+ - 🖼️ 2x 分辨率图片导出,自动检测矢量图标
63
+ - 🎯 设计令牌提取(CSS 变量、SCSS、JSON、JS)
64
+ - ♿ 无障碍增强(ARIA 角色、alt 文本)
65
+ - ⚡ 性能优化(懒加载、代码分割、样式去重)
66
+ - 🤖 可选 AI 增强(语义命名、组件拆分、代码优化)
67
+ - 🔌 MCP 服务器(集成到 Claude Desktop / Kiro IDE)
68
+ - 🎯 Kiro Skill(在 Kiro IDE 中作为技能使用)
69
+ - 📊 设计一致性检查器
70
+ - 🎮 交互原型生成器
71
+
72
+ ## 安装
73
+
74
+ ### 全局安装
75
+ ```bash
76
+ npm install -g figma-to-code-agent
77
+ ```
78
+
79
+ ### 本地安装
80
+ ```bash
81
+ npm install figma-to-code-agent
82
+ ```
83
+
84
+ ### 使用 npx(无需安装)
85
+ ```bash
86
+ npx figma-to-code-agent --token YOUR_TOKEN --file FILE_KEY --output ./output
87
+ ```
88
+
89
+ ## 快速开始
90
+
91
+ ```bash
92
+ # 生成 React 组件
93
+ npx figma-to-code-agent \
94
+ --token YOUR_FIGMA_TOKEN \
95
+ --file FILE_KEY \
96
+ --node NODE_ID \
97
+ --framework react \
98
+ --output ./output
99
+
100
+ # 生成并预览
101
+ npx figma-to-code-agent \
102
+ --token YOUR_FIGMA_TOKEN \
103
+ --file FILE_KEY \
104
+ --framework react \
105
+ --output ./output \
106
+ --preview
107
+ ```
108
+
109
+ 更多使用方式请查看 [快速入门指南](QUICKSTART.md)。
110
+
111
+ ## 工作原理
112
+
113
+ 1. **提取**:通过 Figma API 获取设计数据(支持缓存)
114
+ 2. **解析**:将设计树解析为中间 AST
115
+ 3. **转换**:应用转换管道(扁平化、组件提取、优化、语义命名)
116
+ 4. **生成**:生成框架特定的组件代码
117
+ 5. **优化**:样式去重、响应式处理、无障碍增强
118
+
119
+ 详细架构请参考 [系统架构文档](spec/ARCHITECTURE.md)。
120
+
121
+ ## CLI 选项
122
+
123
+ | 选项 | 描述 | 默认值 |
124
+ |--------|-------------|---------|
125
+ | `--token <token>` | Figma API 令牌 | — |
126
+ | `--file <key>` | Figma 文件 Key | — |
127
+ | `--node <id>` | 目标节点 ID | root |
128
+ | `--framework` | `react` 或 `vue` | `react` |
129
+ | `--style` | `css-modules`、`tailwind` 或 `css` | `css-modules` |
130
+ | `--typescript` | 启用 TypeScript | `false` |
131
+ | `--output <dir>` | 输出目录 | `./output` |
132
+ | `--preview` | 生成后在浏览器中预览 | — |
133
+ | `--mcp` | 启动 MCP 服务器模式 | — |
134
+
135
+ ### AI 选项
136
+
137
+ | 选项 | 描述 |
138
+ |--------|-------------|
139
+ | `--llm-provider` | `bedrock`、`openai` 或 `anthropic` |
140
+ | `--llm-model` | 模型名称 |
141
+ | `--ai-naming` | AI 驱动的语义命名 |
142
+ | `--ai-optimization` | AI 驱动的代码优化 |
143
+
144
+ 完整选项请参考 [CLI 使用指南](docs/CLI_GUIDE.md)。
145
+
146
+ ## 文档
147
+
148
+ - 📖 [快速入门](docs/QUICKSTART.md) - 5 分钟快速上手
149
+ - 🖥️ [CLI 指南](docs/CLI_GUIDE.md) - 命令行完整参考
150
+ - 🔌 [MCP 指南](docs/MCP_GUIDE.md) - 集成到 Claude/Kiro
151
+ - 🎯 [Kiro Skill 指南](docs/KIRO_SKILL_GUIDE.md) - Kiro IDE 使用
152
+ - 🏗️ [系统架构](spec/ARCHITECTURE.md) - 架构设计
153
+ - 🎨 [示例项目](assets/) - 真实转换示例
154
+
155
+ ## 开发
156
+
157
+ ```bash
158
+ git clone https://github.com/lewiscutey/figma-to-code-agent.git
159
+ cd figma-to-code-agent
160
+ npm install
161
+ npm run build # 编译 TypeScript
162
+ npm test # 运行测试(222 个测试)
163
+ npm run lint # 代码检查
164
+ ```
165
+
166
+ ## 系统要求
167
+
168
+ - Node.js 18+
169
+ - Figma 访问令牌([获取令牌](https://www.figma.com/developers/api#access-tokens))
170
+
171
+ ## 许可证
172
+
173
+ MIT License - 详见 [LICENSE](LICENSE) 文件
@@ -0,0 +1,91 @@
1
+ import type { ConversationContext as IConversationContext, Message, Intent, TaskState, UserPreferences, Artifact } from './types';
2
+ /**
3
+ * 对话上下文管理器
4
+ * 维护用户意图、历史交互和任务状态
5
+ */
6
+ export declare class ConversationContextManager {
7
+ private context;
8
+ private persistencePath?;
9
+ constructor(sessionId?: string, persistencePath?: string);
10
+ /**
11
+ * 创建新的对话上下文
12
+ */
13
+ private createNewContext;
14
+ /**
15
+ * 获取当前上下文
16
+ */
17
+ getContext(): IConversationContext;
18
+ /**
19
+ * 添加消息到历史记录
20
+ */
21
+ addMessage(role: Message['role'], content: string, metadata?: Record<string, any>): void;
22
+ /**
23
+ * 设置用户意图
24
+ */
25
+ setIntent(intent: Intent): void;
26
+ /**
27
+ * 获取用户意图
28
+ */
29
+ getIntent(): Intent | null;
30
+ /**
31
+ * 更新任务状态
32
+ */
33
+ updateTaskState(updates: Partial<TaskState>): void;
34
+ /**
35
+ * 获取任务状态
36
+ */
37
+ getTaskState(): TaskState;
38
+ /**
39
+ * 创建检查点
40
+ */
41
+ createCheckpoint(data: any): string;
42
+ /**
43
+ * 从检查点恢复
44
+ */
45
+ restoreFromCheckpoint(checkpointId: string): boolean;
46
+ /**
47
+ * 更新用户偏好
48
+ */
49
+ updateUserPreferences(preferences: Partial<UserPreferences>): void;
50
+ /**
51
+ * 获取用户偏好
52
+ */
53
+ getUserPreferences(): UserPreferences;
54
+ /**
55
+ * 添加生成的产物
56
+ */
57
+ addArtifact(artifact: Omit<Artifact, 'id' | 'timestamp'>): string;
58
+ /**
59
+ * 获取所有产物
60
+ */
61
+ getArtifacts(): Artifact[];
62
+ /**
63
+ * 获取特定版本的产物
64
+ */
65
+ getArtifactsByVersion(version: number): Artifact[];
66
+ /**
67
+ * 获取历史消息
68
+ */
69
+ getHistory(): Message[];
70
+ /**
71
+ * 清空历史记录(保留用户偏好)
72
+ */
73
+ clearHistory(): void;
74
+ /**
75
+ * 持久化上下文到文件
76
+ */
77
+ private persist;
78
+ /**
79
+ * 从文件加载上下文
80
+ */
81
+ private loadFromFile;
82
+ /**
83
+ * 导出上下文为 JSON
84
+ */
85
+ export(): string;
86
+ /**
87
+ * 从 JSON 导入上下文
88
+ */
89
+ import(json: string): boolean;
90
+ }
91
+ //# sourceMappingURL=ConversationContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConversationContext.d.ts","sourceRoot":"","sources":["../../src/agent/ConversationContext.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,mBAAmB,IAAI,oBAAoB,EAC3C,OAAO,EACP,MAAM,EACN,SAAS,EACT,eAAe,EACf,QAAQ,EAET,MAAM,SAAS,CAAC;AAEjB;;;GAGG;AACH,qBAAa,0BAA0B;IACrC,OAAO,CAAC,OAAO,CAAuB;IACtC,OAAO,CAAC,eAAe,CAAC,CAAS;gBAErB,SAAS,CAAC,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM;IAYxD;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAoBxB;;OAEG;IACH,UAAU,IAAI,oBAAoB;IAIlC;;OAEG;IACH,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IAWxF;;OAEG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK/B;;OAEG;IACH,SAAS,IAAI,MAAM,GAAG,IAAI;IAI1B;;OAEG;IACH,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,IAAI;IAQlD;;OAEG;IACH,YAAY,IAAI,SAAS;IAIzB;;OAEG;IACH,gBAAgB,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM;IAYnC;;OAEG;IACH,qBAAqB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO;IAiBpD;;OAEG;IACH,qBAAqB,CAAC,WAAW,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,IAAI;IAQlE;;OAEG;IACH,kBAAkB,IAAI,eAAe;IAIrC;;OAEG;IACH,WAAW,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,GAAG,WAAW,CAAC,GAAG,MAAM;IAWjE;;OAEG;IACH,YAAY,IAAI,QAAQ,EAAE;IAI1B;;OAEG;IACH,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ,EAAE;IAIlD;;OAEG;IACH,UAAU,IAAI,OAAO,EAAE;IAIvB;;OAEG;IACH,YAAY,IAAI,IAAI;IAYpB;;OAEG;IACH,OAAO,CAAC,OAAO;IAgBf;;OAEG;IACH,OAAO,CAAC,YAAY;IAUpB;;OAEG;IACH,MAAM,IAAI,MAAM;IAIhB;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;CAW9B"}