|
1 | | -# @ai-migration/framework |
2 | | - |
3 | | -通用AI辅助迁移框架 - 基于Vue迁移工具的成功实践抽象出的轻量级、可扩展的迁移框架。 |
4 | | - |
5 | | -## 🌟 特性 |
6 | | - |
7 | | -- **🤖 AI驱动**: 智能分析项目结构,自动生成迁移策略 |
8 | | -- **🔧 可扩展**: 插件化架构,支持自定义迁移规则和工具 |
9 | | -- **📊 上下文感知**: 全程跟踪迁移状态,支持断点续传 |
10 | | -- **🎯 多模态**: 支持规则引擎 + AI智能修复的混合模式 |
11 | | -- **🛡️ 安全可靠**: 自动备份、回滚机制、干运行模式 |
12 | | -- **⚡ 高性能**: 并行处理、增量分析、智能缓存 |
13 | | - |
14 | | -## 📦 安装 |
15 | | - |
16 | | -```bash |
17 | | -npm install @ai-migration/framework |
18 | | -``` |
19 | | - |
20 | | -### 全局安装CLI工具 |
21 | | - |
22 | | -```bash |
23 | | -npm install -g @ai-migration/framework |
24 | | -``` |
25 | | - |
26 | | -## 🚀 快速开始 |
27 | | - |
28 | | -### CLI使用 |
29 | | - |
30 | | -```bash |
31 | | -# Vue 2 到 Vue 3 迁移 |
32 | | -ai-migration migrate ./my-vue-project --preset vue2-to-vue3 |
33 | | - |
34 | | -# React 16 到 React 18 迁移 |
35 | | -ai-migration migrate ./my-react-project --preset react16-to-react18 |
36 | | - |
37 | | -# 项目分析 |
38 | | -ai-migration analyze ./my-project |
39 | | - |
40 | | -# 查看框架状态 |
41 | | -ai-migration status |
42 | | -``` |
43 | | - |
44 | | -### 编程接口 |
45 | | - |
46 | | -```typescript |
47 | | -import { |
48 | | - createMigrationOrchestrator, |
49 | | - createMigrationContext, |
50 | | - ConfigManager |
51 | | -} from '@ai-migration/framework'; |
52 | | - |
53 | | -async function migrateProject() { |
54 | | - // 创建迁移编排器 |
55 | | - const orchestrator = createMigrationOrchestrator({ |
56 | | - dryRun: false, |
57 | | - verbose: true |
58 | | - }); |
59 | | - |
60 | | - // 初始化迁移上下文 |
61 | | - const context = await orchestrator.initialize('./my-project'); |
62 | | - |
63 | | - // 执行迁移 |
64 | | - const result = await orchestrator.execute(); |
65 | | - |
66 | | - console.log('迁移完成:', result); |
67 | | -} |
68 | | -``` |
69 | | - |
70 | | -## 🏗️ 架构概览 |
71 | | - |
72 | | -``` |
73 | | -┌─────────────────────────────────────────────────────────────┐ |
74 | | -│ 应用层 (CLI/API) │ |
75 | | -├─────────────────────────────────────────────────────────────┤ |
76 | | -│ 迁移编排层 (策略规划+流程执行) │ |
77 | | -├─────────────────────────────────────────────────────────────┤ |
78 | | -│ AI代理层 (分析+修复+验证) │ |
79 | | -├─────────────────────────────────────────────────────────────┤ |
80 | | -│ 工具执行层 (可扩展工具系统) │ |
81 | | -├─────────────────────────────────────────────────────────────┤ |
82 | | -│ 上下文管理层 (状态+配置管理) │ |
83 | | -├─────────────────────────────────────────────────────────────┤ |
84 | | -│ 基础设施层 (文件系统+AI服务+日志) │ |
85 | | -└─────────────────────────────────────────────────────────────┘ |
86 | | -``` |
87 | | - |
88 | | -## 📋 支持的迁移类型 |
89 | | - |
90 | | -### Vue 2 → Vue 3 |
91 | | -- ✅ 依赖升级 (vue, vue-router, vuex) |
92 | | -- ✅ Composition API 迁移 |
93 | | -- ✅ 构建工具更新 (webpack → vite) |
94 | | -- ✅ 组件语法转换 |
95 | | - |
96 | | -### React 16 → React 18 |
97 | | -- ✅ 依赖升级 |
98 | | -- ✅ 并发特性迁移 |
99 | | -- ✅ 严格模式修复 |
100 | | -- ✅ Root API 更新 |
101 | | - |
102 | | -### Angular 12 → 15 |
103 | | -- ✅ ng update 自动升级 |
104 | | -- ✅ 独立组件迁移 |
105 | | -- ✅ 新特性采用 |
106 | | - |
107 | | -## 🔧 配置 |
108 | | - |
109 | | -### 环境变量 |
110 | | - |
111 | | -```bash |
112 | | -# AI服务配置 |
113 | | -export OPENAI_API_KEY="your-openai-key" |
114 | | -export DEEPSEEK_TOKEN="your-deepseek-token" |
115 | | -export GLM_API_KEY="your-glm-key" |
116 | | - |
117 | | -# 框架配置 |
118 | | -export AI_MIGRATION_DRY_RUN="false" |
119 | | -export AI_MIGRATION_VERBOSE="true" |
120 | | -export AI_MIGRATION_MAX_RETRIES="3" |
121 | | -``` |
122 | | - |
123 | | -### 配置文件 |
124 | | - |
125 | | -```bash |
126 | | -# 初始化配置文件 |
127 | | -ai-migration config --init |
128 | | - |
129 | | -# 查看当前配置 |
130 | | -ai-migration config --show |
131 | | - |
132 | | -# 验证配置 |
133 | | -ai-migration config --validate |
134 | | -``` |
135 | | - |
136 | | -配置文件示例 (`ai-migration.config.json`): |
137 | | - |
138 | | -```json |
139 | | -{ |
140 | | - "mode": "auto", |
141 | | - "dryRun": false, |
142 | | - "verbose": false, |
143 | | - "ai": { |
144 | | - "provider": "openai", |
145 | | - "model": "gpt-4", |
146 | | - "maxTokens": 4000, |
147 | | - "temperature": 0.1 |
148 | | - }, |
149 | | - "execution": { |
150 | | - "parallelism": { |
151 | | - "enabled": true, |
152 | | - "maxConcurrency": 4 |
153 | | - }, |
154 | | - "backup": { |
155 | | - "enabled": true, |
156 | | - "location": ".migration-backup" |
157 | | - } |
158 | | - } |
159 | | -} |
160 | | -``` |
161 | | - |
162 | | -## 🎯 API参考 |
163 | | - |
164 | | -### 核心类 |
165 | | - |
166 | | -#### MigrationContext |
167 | | -```typescript |
168 | | -import { MigrationContext } from '@ai-migration/framework'; |
169 | | - |
170 | | -const context = new MigrationContext('./project-path', { |
171 | | - mode: 'auto', |
172 | | - verbose: true |
173 | | -}); |
174 | | -``` |
175 | | - |
176 | | -#### ContextAwareComponent |
177 | | -```typescript |
178 | | -import { ContextAwareComponent } from '@ai-migration/framework'; |
179 | | - |
180 | | -class CustomComponent extends ContextAwareComponent { |
181 | | - async onExecute() { |
182 | | - // 自定义执行逻辑 |
183 | | - return { success: true }; |
184 | | - } |
185 | | -} |
186 | | -``` |
187 | | - |
188 | | -#### AIService |
189 | | -```typescript |
190 | | -import { AIService } from '@ai-migration/framework'; |
191 | | - |
192 | | -class CustomAIService extends AIService { |
193 | | - protected checkAvailability(): boolean { |
194 | | - return !!process.env.CUSTOM_AI_KEY; |
195 | | - } |
196 | | - |
197 | | - protected async performAICall(prompt: string): Promise<string> { |
198 | | - // 自定义AI调用逻辑 |
199 | | - return 'AI response'; |
200 | | - } |
201 | | -} |
202 | | -``` |
203 | | - |
204 | | -### 工具系统 |
205 | | - |
206 | | -#### ToolRegistry |
207 | | -```typescript |
208 | | -import { ToolRegistry } from '@ai-migration/framework'; |
209 | | - |
210 | | -const registry = new ToolRegistry(); |
211 | | - |
212 | | -registry.registerTool({ |
213 | | - name: 'custom_tool', |
214 | | - category: 'migration', |
215 | | - description: '自定义迁移工具', |
216 | | - parameters: { |
217 | | - type: 'object', |
218 | | - properties: { |
219 | | - input: { type: 'string', required: true } |
220 | | - }, |
221 | | - required: ['input'] |
222 | | - }, |
223 | | - executor: async (params) => { |
224 | | - return { result: `处理: ${params.input}` }; |
225 | | - } |
226 | | -}); |
227 | | -``` |
228 | | - |
229 | | -## 🔌 扩展开发 |
230 | | - |
231 | | -### 自定义AI代理 |
232 | | - |
233 | | -```typescript |
234 | | -import { BaseAIAgent } from '@ai-migration/framework'; |
235 | | - |
236 | | -class CustomAnalysisAgent extends BaseAIAgent { |
237 | | - async onExecute() { |
238 | | - const prompt = '分析项目结构...'; |
239 | | - const analysis = await this.analyzeWithAI(prompt); |
240 | | - return { analysis }; |
241 | | - } |
242 | | -} |
243 | | -``` |
244 | | - |
245 | | -### 自定义预设 |
246 | | - |
247 | | -```typescript |
248 | | -import { ConfigManager } from '@ai-migration/framework'; |
249 | | - |
250 | | -const configManager = new ConfigManager(); |
251 | | - |
252 | | -configManager.addPreset('custom-migration', { |
253 | | - name: 'Custom Migration', |
254 | | - description: '自定义迁移预设', |
255 | | - source: { framework: 'custom', version: '1.x' }, |
256 | | - target: { framework: 'custom', version: '2.x' }, |
257 | | - steps: [ |
258 | | - { |
259 | | - name: 'custom-step', |
260 | | - agent: 'CustomAgent', |
261 | | - order: 1, |
262 | | - required: true |
263 | | - } |
264 | | - ], |
265 | | - tools: ['custom-tool'] |
266 | | -}); |
267 | | -``` |
268 | | - |
269 | | -## 📊 监控和报告 |
270 | | - |
271 | | -### 事件监听 |
272 | | - |
273 | | -```typescript |
274 | | -orchestrator.on('phase:change', (data) => { |
275 | | - console.log(`阶段变更: ${data.phase}`); |
276 | | -}); |
277 | | - |
278 | | -orchestrator.on('progress:update', (progress) => { |
279 | | - console.log(`进度: ${progress}%`); |
280 | | -}); |
281 | | - |
282 | | -orchestrator.on('error:add', (data) => { |
283 | | - console.log(`错误: ${data.error.message}`); |
284 | | -}); |
285 | | -``` |
286 | | - |
287 | | -### 生成报告 |
288 | | - |
289 | | -迁移完成后会自动生成详细报告: |
290 | | -- JSON格式:机器可读的详细数据 |
291 | | -- 包含迁移统计、错误信息、性能指标 |
292 | | - |
293 | | -## 🛠️ 开发 |
294 | | - |
295 | | -### 构建 |
296 | | - |
297 | | -```bash |
298 | | -npm run build |
299 | | -``` |
300 | | - |
301 | | -### 测试 |
302 | | - |
303 | | -```bash |
304 | | -npm test |
305 | | -npm run test:watch |
306 | | -``` |
307 | | - |
308 | | -### 开发模式 |
309 | | - |
310 | | -```bash |
311 | | -npm run dev |
312 | | -``` |
313 | | - |
314 | | -## 📄 许可证 |
315 | | - |
316 | | -MIT License |
317 | | - |
318 | | -## 🤝 贡献 |
319 | | - |
320 | | -欢迎贡献代码、报告问题或提出改进建议! |
321 | | - |
322 | | -1. Fork 项目 |
323 | | -2. 创建特性分支 (`git checkout -b feature/amazing-feature`) |
324 | | -3. 提交更改 (`git commit -m 'Add amazing feature'`) |
325 | | -4. 推送到分支 (`git push origin feature/amazing-feature`) |
326 | | -5. 打开 Pull Request |
327 | | - |
328 | | -## 🙏 致谢 |
329 | | - |
330 | | -本框架基于Vue 2到Vue 3迁移工具的成功实践开发,感谢原项目的贡献者们。 |
331 | | - |
332 | | ---- |
333 | | - |
334 | | -**更多文档**: [GitHub Repository](https://github.com/unit-mesh/autodev-workbench/tree/master/packages/framework) |
335 | | -**问题反馈**: [GitHub Issues](https://github.com/unit-mesh/autodev-workbench/issues) |
336 | | -**社区讨论**: [Discussions](https://github.com/unit-mesh/autodev-workbench/discussions) |
| 1 | +# @autodev/migration |
0 commit comments