@adversity/coding-tool-x 2.2.0 → 2.4.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 (34) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/README.md +12 -14
  3. package/dist/web/assets/index-Bu1oPcKu.js +4009 -0
  4. package/dist/web/assets/index-XSok7-mN.css +41 -0
  5. package/dist/web/index.html +2 -2
  6. package/package.json +5 -4
  7. package/src/config/default.js +1 -1
  8. package/src/index.js +2 -2
  9. package/src/server/api/agents.js +188 -0
  10. package/src/server/api/commands.js +261 -0
  11. package/src/server/api/config-export.js +122 -0
  12. package/src/server/api/config-templates.js +26 -5
  13. package/src/server/api/health-check.js +1 -89
  14. package/src/server/api/permissions.js +370 -0
  15. package/src/server/api/rules.js +188 -0
  16. package/src/server/api/skills.js +66 -14
  17. package/src/server/api/workspaces.js +30 -55
  18. package/src/server/index.js +7 -11
  19. package/src/server/services/agents-service.js +179 -1
  20. package/src/server/services/commands-service.js +231 -47
  21. package/src/server/services/config-export-service.js +209 -0
  22. package/src/server/services/config-templates-service.js +481 -107
  23. package/src/server/services/format-converter.js +506 -0
  24. package/src/server/services/health-check.js +1 -315
  25. package/src/server/services/permission-templates-service.js +339 -0
  26. package/src/server/services/repo-scanner-base.js +678 -0
  27. package/src/server/services/rules-service.js +179 -1
  28. package/src/server/services/skill-service.js +114 -61
  29. package/src/server/services/workspace-service.js +52 -1
  30. package/dist/web/assets/index-D1AYlFLZ.js +0 -3220
  31. package/dist/web/assets/index-aL3cKxSK.css +0 -41
  32. package/docs/CHANGELOG.md +0 -582
  33. package/docs/DIRECTORY_MIGRATION.md +0 -112
  34. package/docs/PROJECT_STRUCTURE.md +0 -396
@@ -20,125 +20,436 @@ const skillService = new SkillService();
20
20
  const TEMPLATES_FILE = path.join(PATHS.config, 'config-templates.json');
21
21
 
22
22
  // 内置配置模板
23
+ // aiConfigs 结构: { claude: { enabled, content }, codex: { enabled, content }, gemini: { enabled, content } }
23
24
  const BUILTIN_TEMPLATES = [
24
25
  {
25
- id: 'default',
26
- name: '默认配置',
27
- description: '标准的开发环境配置',
28
- claudeMd: {
29
- enabled: true,
30
- content: `# 项目配置
26
+ id: 'full-stack',
27
+ name: '全栈开发',
28
+ description: '前后端全栈开发配置,包含代码编辑、文档查询、版本控制等常用工具',
29
+ // 兼容旧字段
30
+ claudeMd: { enabled: false, content: '' },
31
+ // 新的多 AI 配置
32
+ aiConfigs: {
33
+ claude: {
34
+ enabled: true,
35
+ content: `# 全栈开发项目配置
36
+
37
+ 你是一位经验丰富的全栈开发工程师,专注于高质量代码交付。
31
38
 
32
- 这是一个标准的开发项目。
39
+ ## 核心原则
40
+
41
+ - **KISS**: 保持简单,避免过度设计
42
+ - **YAGNI**: 只实现当前需求,不做假设性扩展
43
+ - **向后兼容**: 修改 API 或数据结构时确保兼容性
44
+ - **安全优先**: 防范 XSS、SQL 注入、CSRF 等常见漏洞
33
45
 
34
46
  ## 代码规范
35
- - 保持代码简洁
36
- - 遵循项目现有风格
37
- - 添加必要的注释
47
+
48
+ - 遵循项目既有风格和模式
49
+ - 函数保持单一职责,控制在 50 行以内
50
+ - 变量命名清晰准确,避免缩写
51
+ - 只在必要时添加注释,代码应自解释
52
+
53
+ ## MCP 工具使用规范
54
+
55
+ ### Serena(代码编辑 - 首选)
56
+ - **适用场景**: 所有代码修改、符号重命名、跨文件重构
57
+ - **使用方式**: 先用 \`find_symbol\` 定位,再用 \`replace_symbol_body\` 或 \`insert_*\` 修改
58
+ - **注意**: 优先符号级精确编辑,避免大段盲改
59
+
60
+ ### Context7(文档查询 - 首选)
61
+ - **适用场景**: 查询框架/库的官方文档、API 用法、配置说明
62
+ - **使用方式**: 先 \`resolve-library-id\`,再 \`get-library-docs\`
63
+ - **注意**: 用明确的 topic 关键词收敛查询范围
64
+
65
+ ### GitHub MCP
66
+ - **适用场景**: PR 操作、Issue 管理、代码搜索、仓库信息查询
67
+ - **使用方式**: 直接调用对应的 GitHub API
68
+ - **注意**: 不要用于本地文件操作
69
+
70
+ ### Fetch MCP
71
+ - **适用场景**: 抓取网页内容、博客、技术文档
72
+ - **使用方式**: 控制 \`max_length\`,必要时用 \`start_index\` 分段
73
+ - **注意**: 只抓取必要内容,避免敏感信息
74
+
75
+ ### Memory MCP
76
+ - **适用场景**: 持久化用户偏好、项目约定、长期上下文
77
+ - **使用方式**: 原子化记录,一个事实一条 observation
78
+ - **注意**: 仅在用户明确提供且有长期价值时写入
79
+
80
+ ## 工作流程
81
+
82
+ 1. **理解需求**: 复述任务,识别潜在风险
83
+ 2. **收集上下文**: 使用 Serena 符号检索理解代码结构
84
+ 3. **制定计划**: 拆分为可回滚的小步骤
85
+ 4. **执行修改**: 使用 Serena 进行精确编辑
86
+ 5. **验证结果**: 运行测试或给出验证命令
38
87
  `
39
- },
40
- skills: [],
41
- rules: [],
42
- commands: [],
43
- agents: [],
44
- mcpServers: [],
45
- isBuiltin: true
46
- },
47
- {
48
- id: 'full-stack',
49
- name: '全栈开发',
50
- description: '前后端全栈开发配置,包含常用的开发工具和规则',
51
- claudeMd: {
52
- enabled: true,
53
- content: `# 全栈开发项目
54
-
55
- 你是一个经验丰富的全栈开发工程师。
56
-
57
- ## 技术栈关注
58
- - **前端**: React/Vue, TypeScript, 组件化开发
59
- - **后端**: Node.js/Python, RESTful API, 数据库设计
60
- - **DevOps**: Git, CI/CD, Docker
61
-
62
- ## 开发原则
63
- - KISS: Keep It Simple, Stupid
64
- - DRY: Don't Repeat Yourself
65
- - YAGNI: You Aren't Gonna Need It
66
- - 安全优先:防止 XSS、SQL 注入等常见漏洞
67
-
68
- ## 代码风格
69
- - 使用 TypeScript 时启用严格模式
88
+ },
89
+ codex: {
90
+ enabled: true,
91
+ content: `# Full-Stack Development Configuration
92
+
93
+ You are an experienced full-stack developer focused on delivering high-quality code.
94
+
95
+ ## Core Principles
96
+
97
+ - **KISS**: Keep it simple, avoid over-engineering
98
+ - **YAGNI**: Only implement current requirements
99
+ - **Security First**: Prevent XSS, SQL injection, CSRF vulnerabilities
100
+ - **Backward Compatibility**: Ensure API/data structure changes are compatible
101
+
102
+ ## Code Standards
103
+
104
+ - Follow existing project patterns and styles
105
+ - Keep functions under 50 lines with single responsibility
106
+ - Use clear, descriptive variable names
107
+ - Add comments only when necessary
108
+
109
+ ## Workflow
110
+
111
+ 1. Understand the requirement and identify risks
112
+ 2. Explore codebase to understand structure
113
+ 3. Plan changes in small, reversible steps
114
+ 4. Implement with minimal diff
115
+ 5. Verify with tests or provide verification commands
116
+ `
117
+ },
118
+ gemini: {
119
+ enabled: true,
120
+ content: `# 全栈开发项目配置
121
+
122
+ 你是一位经验丰富的全栈开发工程师。
123
+
124
+ ## 核心原则
125
+
126
+ - 保持简单 (KISS),避免过度设计
127
+ - 只实现当前需求 (YAGNI)
128
+ - 安全优先,防范常见漏洞
129
+ - 确保向后兼容性
130
+
131
+ ## 代码规范
132
+
133
+ - 遵循项目既有风格
70
134
  - 函数保持单一职责
71
- - 添加适当的错误处理
135
+ - 变量命名清晰准确
136
+ - 必要时添加注释
137
+
138
+ ## 工作流程
139
+
140
+ 1. 理解需求,识别风险
141
+ 2. 探索代码库结构
142
+ 3. 制定可回滚的计划
143
+ 4. 执行最小化修改
144
+ 5. 验证结果
72
145
  `
146
+ }
73
147
  },
74
148
  skills: [],
75
149
  rules: [],
76
150
  commands: [],
77
151
  agents: [],
78
- mcpServers: ['github', 'fetch'],
152
+ mcpServers: ['github', 'context7', 'fetch', 'memory'],
79
153
  isBuiltin: true
80
154
  },
81
155
  {
82
- id: 'data-science',
83
- name: '数据科学',
84
- description: '数据分析和机器学习项目配置',
85
- claudeMd: {
86
- enabled: true,
87
- content: `# 数据科学项目
156
+ id: 'architecture',
157
+ name: '方案设计',
158
+ description: '专注于技术方案设计、架构评审、系统设计,适合需求分析和技术决策场景',
159
+ claudeMd: { enabled: false, content: '' },
160
+ aiConfigs: {
161
+ claude: {
162
+ enabled: true,
163
+ content: `# 技术方案设计配置
164
+
165
+ 你是一位资深技术架构师,专注于系统设计和技术方案制定。
166
+
167
+ ## 核心职责
168
+
169
+ - 分析需求,识别技术挑战和风险点
170
+ - 设计可扩展、可维护的系统架构
171
+ - 评估技术选型的利弊权衡
172
+ - 制定清晰的实施路径和里程碑
173
+
174
+ ## 设计原则
175
+
176
+ - **单一职责**: 每个模块只负责一件事
177
+ - **开闭原则**: 对扩展开放,对修改关闭
178
+ - **依赖倒置**: 依赖抽象而非具体实现
179
+ - **最小知识**: 模块间保持松耦合
180
+
181
+ ## MCP 工具使用规范
182
+
183
+ ### Serena(代码探索 - 首选)
184
+ - **适用场景**: 理解现有代码架构、分析模块依赖关系
185
+ - **使用方式**: 用 \`get_symbols_overview\` 了解文件结构,\`find_referencing_symbols\` 分析依赖
186
+ - **注意**: 方案设计阶段主要用于读取和分析,不直接修改代码
187
+
188
+ ### Context7(技术文档 - 首选)
189
+ - **适用场景**: 查询框架最佳实践、设计模式、架构指南
190
+ - **使用方式**: 查询具体技术的官方架构文档
191
+ - **注意**: 关注架构级别的文档而非 API 细节
192
+
193
+ ### Fetch MCP
194
+ - **适用场景**: 获取技术博客、架构案例、行业最佳实践
195
+ - **使用方式**: 抓取相关技术文章作为参考
196
+ - **注意**: 验证信息来源的权威性
197
+
198
+ ### Memory MCP
199
+ - **适用场景**: 记录架构决策 (ADR)、技术约定、设计原则
200
+ - **使用方式**: 以结构化方式记录重要决策及其理由
201
+ - **注意**: 架构决策应包含背景、方案、理由、后果
202
+
203
+ ## 方案输出格式
204
+
205
+ ### 1. 背景与目标
206
+ - 业务背景和驱动因素
207
+ - 要解决的核心问题
208
+ - 预期达成的目标
209
+
210
+ ### 2. 现状分析
211
+ - 现有系统架构
212
+ - 当前痛点和瓶颈
213
+ - 技术债务评估
214
+
215
+ ### 3. 方案设计
216
+ - 整体架构设计
217
+ - 核心模块划分
218
+ - 关键流程设计
219
+ - 数据模型设计
220
+
221
+ ### 4. 技术选型
222
+ - 候选方案对比
223
+ - 选型理由
224
+ - 潜在风险
225
+
226
+ ### 5. 实施计划
227
+ - 分阶段里程碑
228
+ - 依赖关系
229
+ - 风险缓解措施
230
+
231
+ ### 6. 附录
232
+ - 术语表
233
+ - 参考资料
234
+ - 相关 ADR
235
+ `
236
+ },
237
+ codex: {
238
+ enabled: true,
239
+ content: `# Architecture Design Configuration
88
240
 
89
- 你是一个数据科学专家,擅长数据分析和机器学习。
241
+ You are a senior technical architect focused on system design and technical planning.
90
242
 
91
- ## 工作流程
92
- 1. **数据探索**: 理解数据结构、分布、缺失值
93
- 2. **数据清洗**: 处理异常值、填充缺失、特征工程
94
- 3. **建模**: 选择合适的算法,调优参数
95
- 4. **评估**: 使用适当的指标评估模型性能
96
- 5. **可视化**: 清晰展示分析结果
97
-
98
- ## 常用库
99
- - pandas, numpy: 数据处理
100
- - scikit-learn: 机器学习
101
- - matplotlib, seaborn: 可视化
102
- - jupyter: 交互式开发
103
-
104
- ## 最佳实践
105
- - 始终验证数据质量
106
- - 避免数据泄露
107
- - 记录实验过程和参数
108
- - 可复现的分析流程
243
+ ## Core Responsibilities
244
+
245
+ - Analyze requirements and identify technical challenges
246
+ - Design scalable, maintainable system architectures
247
+ - Evaluate technology trade-offs
248
+ - Define clear implementation roadmaps
249
+
250
+ ## Design Principles
251
+
252
+ - **Single Responsibility**: Each module handles one thing
253
+ - **Open-Closed**: Open for extension, closed for modification
254
+ - **Dependency Inversion**: Depend on abstractions
255
+ - **Least Knowledge**: Keep modules loosely coupled
256
+
257
+ ## Output Format
258
+
259
+ 1. **Background & Goals**: Business context, problems to solve
260
+ 2. **Current State Analysis**: Existing architecture, pain points
261
+ 3. **Solution Design**: Architecture, modules, flows, data models
262
+ 4. **Technology Selection**: Options comparison, rationale
263
+ 5. **Implementation Plan**: Milestones, dependencies, risks
264
+ `
265
+ },
266
+ gemini: {
267
+ enabled: true,
268
+ content: `# 技术方案设计配置
269
+
270
+ 你是一位资深技术架构师,专注于系统设计。
271
+
272
+ ## 核心职责
273
+
274
+ - 分析需求,识别技术挑战
275
+ - 设计可扩展的系统架构
276
+ - 评估技术选型利弊
277
+ - 制定实施路径
278
+
279
+ ## 设计原则
280
+
281
+ - 单一职责
282
+ - 开闭原则
283
+ - 依赖倒置
284
+ - 松耦合
285
+
286
+ ## 输出格式
287
+
288
+ 1. 背景与目标
289
+ 2. 现状分析
290
+ 3. 方案设计
291
+ 4. 技术选型
292
+ 5. 实施计划
109
293
  `
294
+ }
110
295
  },
111
296
  skills: [],
112
297
  rules: [],
113
298
  commands: [],
114
299
  agents: [],
115
- mcpServers: ['fetch'],
300
+ mcpServers: ['context7', 'fetch', 'memory'],
116
301
  isBuiltin: true
117
302
  },
118
303
  {
119
304
  id: 'code-review',
120
305
  name: '代码审查',
121
- description: '专注于代码审查和质量改进',
122
- claudeMd: {
123
- enabled: true,
124
- content: `# 代码审查专家
306
+ description: '专注于代码审查、质量评估、安全检查,适合 PR Review 和代码质量改进',
307
+ claudeMd: { enabled: false, content: '' },
308
+ aiConfigs: {
309
+ claude: {
310
+ enabled: true,
311
+ content: `# 代码审查配置
125
312
 
126
- 你是一个专业的代码审查专家。
313
+ 你是一位专业的代码审查专家,专注于代码质量和最佳实践。
127
314
 
128
315
  ## 审查维度
129
- - **可读性**: 命名、注释、代码组织
130
- - **性能**: 算法复杂度、资源使用
131
- - **安全**: 常见漏洞、输入验证
132
- - **可维护性**: 模块化、耦合度
133
- - **测试**: 测试覆盖、边界情况
134
-
135
- ## 审查流程
136
- 1. 理解代码意图和上下文
137
- 2. 检查代码逻辑和实现
138
- 3. 识别潜在问题
139
- 4. 提供具体改进建议
140
- 5. 给出示例代码(如需要)
316
+
317
+ ### 1. 正确性
318
+ - 逻辑是否正确
319
+ - 边界条件处理
320
+ - 错误处理完整性
321
+
322
+ ### 2. 可读性
323
+ - 命名是否清晰准确
324
+ - 代码结构是否清晰
325
+ - 注释是否必要且准确
326
+
327
+ ### 3. 可维护性
328
+ - 函数长度和复杂度
329
+ - 模块化程度
330
+ - 代码重复情况
331
+
332
+ ### 4. 性能
333
+ - 算法复杂度
334
+ - 资源使用效率
335
+ - 潜在的性能瓶颈
336
+
337
+ ### 5. 安全性
338
+ - 输入验证
339
+ - 敏感数据处理
340
+ - 常见漏洞检查(XSS、SQL 注入、CSRF 等)
341
+
342
+ ### 6. 测试
343
+ - 测试覆盖率
344
+ - 边界情况测试
345
+ - 测试质量
346
+
347
+ ## MCP 工具使用规范
348
+
349
+ ### Serena(代码分析 - 首选)
350
+ - **适用场景**: 理解代码结构、追踪依赖关系、分析影响范围
351
+ - **使用方式**:
352
+ - \`find_symbol\` 定位具体实现
353
+ - \`find_referencing_symbols\` 分析影响范围
354
+ - \`get_symbols_overview\` 了解模块结构
355
+ - **注意**: 审查时主要用于分析,建议修改时再进行编辑
356
+
357
+ ### GitHub MCP
358
+ - **适用场景**: 获取 PR 信息、查看文件变更、提交审查意见
359
+ - **使用方式**:
360
+ - \`get_pull_request\` 获取 PR 详情
361
+ - \`get_pull_request_files\` 查看变更文件
362
+ - \`create_pull_request_review\` 提交审查
363
+ - **注意**: 确保审查意见具体、可执行
364
+
365
+ ### Context7(最佳实践 - 参考)
366
+ - **适用场景**: 查询语言/框架的最佳实践、代码规范
367
+ - **使用方式**: 查询具体技术的编码规范文档
368
+ - **注意**: 用于支撑审查意见,而非替代审查
369
+
370
+ ## 审查输出格式
371
+
372
+ ### 总体评价
373
+ - 整体代码质量评分(1-5)
374
+ - 主要优点
375
+ - 需要改进的地方
376
+
377
+ ### 具体问题
378
+ 对每个问题:
379
+ - **位置**: 文件路径:行号
380
+ - **级别**: 🔴 必须修复 / 🟡 建议修复 / 🟢 可选优化
381
+ - **问题**: 具体描述
382
+ - **建议**: 改进方案
383
+ - **示例**: 示例代码(如需要)
384
+
385
+ ### 审查结论
386
+ - ✅ 批准:可以合并
387
+ - 🔄 需要修改:修复问题后重新审查
388
+ - ❌ 拒绝:需要重大重构
389
+ `
390
+ },
391
+ codex: {
392
+ enabled: true,
393
+ content: `# Code Review Configuration
394
+
395
+ You are a professional code reviewer focused on code quality and best practices.
396
+
397
+ ## Review Dimensions
398
+
399
+ 1. **Correctness**: Logic, edge cases, error handling
400
+ 2. **Readability**: Naming, structure, necessary comments
401
+ 3. **Maintainability**: Function length, modularity, duplication
402
+ 4. **Performance**: Algorithm complexity, resource usage
403
+ 5. **Security**: Input validation, sensitive data, vulnerabilities
404
+ 6. **Testing**: Coverage, edge cases, test quality
405
+
406
+ ## Output Format
407
+
408
+ ### Overall Assessment
409
+ - Quality score (1-5)
410
+ - Main strengths
411
+ - Areas for improvement
412
+
413
+ ### Specific Issues
414
+ For each issue:
415
+ - **Location**: file:line
416
+ - **Severity**: 🔴 Must fix / 🟡 Should fix / 🟢 Optional
417
+ - **Issue**: Description
418
+ - **Suggestion**: How to fix
419
+ - **Example**: Code example if needed
420
+
421
+ ### Conclusion
422
+ - ✅ Approve / 🔄 Request changes / ❌ Reject
141
423
  `
424
+ },
425
+ gemini: {
426
+ enabled: true,
427
+ content: `# 代码审查配置
428
+
429
+ 你是一位专业的代码审查专家。
430
+
431
+ ## 审查维度
432
+
433
+ 1. **正确性**: 逻辑、边界、错误处理
434
+ 2. **可读性**: 命名、结构、注释
435
+ 3. **可维护性**: 函数长度、模块化、重复
436
+ 4. **性能**: 算法复杂度、资源使用
437
+ 5. **安全性**: 输入验证、漏洞检查
438
+ 6. **测试**: 覆盖率、边界测试
439
+
440
+ ## 输出格式
441
+
442
+ ### 总体评价
443
+ - 质量评分(1-5)
444
+ - 优点和改进点
445
+
446
+ ### 具体问题
447
+ - 位置、级别、问题、建议
448
+
449
+ ### 结论
450
+ - ✅ 批准 / 🔄 需修改 / ❌ 拒绝
451
+ `
452
+ }
142
453
  },
143
454
  skills: [],
144
455
  rules: [],
@@ -150,10 +461,12 @@ const BUILTIN_TEMPLATES = [
150
461
  {
151
462
  id: 'minimal',
152
463
  name: '最小配置',
153
- description: '不使用任何额外配置的纯净环境',
154
- claudeMd: {
155
- enabled: false,
156
- content: ''
464
+ description: '纯净环境,不添加任何额外配置,适合已有完善配置的项目',
465
+ claudeMd: { enabled: false, content: '' },
466
+ aiConfigs: {
467
+ claude: { enabled: false, content: '' },
468
+ codex: { enabled: false, content: '' },
469
+ gemini: { enabled: false, content: '' }
157
470
  },
158
471
  skills: [],
159
472
  rules: [],
@@ -488,8 +801,11 @@ function generateRuleContent(rule) {
488
801
  * 应用模板到项目目录(完整应用,写入实际文件)
489
802
  * @param {string} targetDir - 目标项目目录
490
803
  * @param {string} templateId - 模板 ID
804
+ * @param {object} options - 可选配置
805
+ * @param {string|string[]} options.aiConfigTypes - 选择的 AI 配置类型数组: ['claude', 'codex', 'gemini']
806
+ * @param {string} options.aiConfigType - (兼容旧版) 单个 AI 配置类型
491
807
  */
492
- function applyTemplateToProject(targetDir, templateId) {
808
+ function applyTemplateToProject(targetDir, templateId, options = {}) {
493
809
  const template = getTemplateById(templateId);
494
810
  if (!template) {
495
811
  throw new Error('模板不存在');
@@ -498,7 +814,7 @@ function applyTemplateToProject(targetDir, templateId) {
498
814
  ensureDir(targetDir);
499
815
 
500
816
  const results = {
501
- claudeMd: { applied: false, path: null },
817
+ aiConfigs: [], // 改为数组存储多个 AI 配置结果
502
818
  skills: { applied: template.skills?.length || 0, items: template.skills?.map(s => s.directory || s.name) || [] },
503
819
  agents: { applied: 0, files: [] },
504
820
  commands: { applied: 0, files: [] },
@@ -506,11 +822,38 @@ function applyTemplateToProject(targetDir, templateId) {
506
822
  mcpServers: { applied: 0 }
507
823
  };
508
824
 
509
- // 1. 写入 CLAUDE.md
510
- if (template.claudeMd?.enabled && template.claudeMd?.content) {
511
- const claudeMdPath = path.join(targetDir, 'CLAUDE.md');
512
- fs.writeFileSync(claudeMdPath, template.claudeMd.content, 'utf-8');
513
- results.claudeMd = { applied: true, path: 'CLAUDE.md' };
825
+ // 1. 写入 AI 配置文件(支持多 AI 类型选择)
826
+ // 兼容旧版单值参数
827
+ let aiConfigTypes = options.aiConfigTypes;
828
+ if (!aiConfigTypes) {
829
+ aiConfigTypes = options.aiConfigType ? [options.aiConfigType] : ['claude'];
830
+ }
831
+ if (!Array.isArray(aiConfigTypes)) {
832
+ aiConfigTypes = [aiConfigTypes];
833
+ }
834
+
835
+ const aiConfigMap = {
836
+ claude: { fileName: 'CLAUDE.md', name: 'Claude' },
837
+ codex: { fileName: 'AGENTS.md', name: 'Codex' },
838
+ gemini: { fileName: 'GEMINI.md', name: 'Gemini' }
839
+ };
840
+
841
+ // 遍历所有选中的 AI 配置类型
842
+ for (const aiConfigType of aiConfigTypes) {
843
+ let aiConfig = null;
844
+ if (template.aiConfigs && template.aiConfigs[aiConfigType]) {
845
+ aiConfig = template.aiConfigs[aiConfigType];
846
+ } else if (aiConfigType === 'claude' && template.claudeMd) {
847
+ // 兼容旧的 claudeMd 字段
848
+ aiConfig = template.claudeMd;
849
+ }
850
+
851
+ if (aiConfig?.enabled && aiConfig?.content) {
852
+ const configInfo = aiConfigMap[aiConfigType];
853
+ const configPath = path.join(targetDir, configInfo.fileName);
854
+ fs.writeFileSync(configPath, aiConfig.content, 'utf-8');
855
+ results.aiConfigs.push({ applied: true, path: configInfo.fileName, type: configInfo.name, key: aiConfigType });
856
+ }
514
857
  }
515
858
 
516
859
  // 2. 写入 Agents
@@ -600,6 +943,8 @@ function applyTemplateToProject(targetDir, templateId) {
600
943
  templateId: template.id,
601
944
  templateName: template.name,
602
945
  appliedAt: new Date().toISOString(),
946
+ aiConfigTypes: aiConfigTypes,
947
+ aiConfigPaths: results.aiConfigs.map(c => c.path),
603
948
  skills: template.skills?.map(s => s.directory || s.name) || [],
604
949
  agents: template.agents?.map(a => a.fileName || a.name) || [],
605
950
  commands: template.commands?.map(c => c.name) || [],
@@ -620,8 +965,11 @@ function applyTemplateToProject(targetDir, templateId) {
620
965
  * 预览模板应用效果
621
966
  * @param {string} targetDir - 目标项目目录
622
967
  * @param {string} templateId - 模板 ID
968
+ * @param {object} options - 可选配置
969
+ * @param {string|string[]} options.aiConfigTypes - 选择的 AI 配置类型数组: ['claude', 'codex', 'gemini']
970
+ * @param {string} options.aiConfigType - (兼容旧版) 单个 AI 配置类型
623
971
  */
624
- function previewTemplateApplication(targetDir, templateId) {
972
+ function previewTemplateApplication(targetDir, templateId, options = {}) {
625
973
  const template = getTemplateById(templateId);
626
974
  if (!template) {
627
975
  throw new Error('模板不存在');
@@ -631,7 +979,7 @@ function previewTemplateApplication(targetDir, templateId) {
631
979
  willCreate: [],
632
980
  willOverwrite: [],
633
981
  summary: {
634
- claudeMd: false,
982
+ aiConfigs: [], // 改为数组
635
983
  skills: 0,
636
984
  agents: 0,
637
985
  commands: 0,
@@ -640,15 +988,41 @@ function previewTemplateApplication(targetDir, templateId) {
640
988
  }
641
989
  };
642
990
 
643
- // 检查 CLAUDE.md
644
- if (template.claudeMd?.enabled && template.claudeMd?.content) {
645
- const claudeMdPath = path.join(targetDir, 'CLAUDE.md');
646
- if (fs.existsSync(claudeMdPath)) {
647
- preview.willOverwrite.push('CLAUDE.md');
648
- } else {
649
- preview.willCreate.push('CLAUDE.md');
991
+ // 检查 AI 配置文件(支持多选)
992
+ // 兼容旧版单值参数
993
+ let aiConfigTypes = options.aiConfigTypes;
994
+ if (!aiConfigTypes) {
995
+ aiConfigTypes = options.aiConfigType ? [options.aiConfigType] : ['claude'];
996
+ }
997
+ if (!Array.isArray(aiConfigTypes)) {
998
+ aiConfigTypes = [aiConfigTypes];
999
+ }
1000
+
1001
+ const aiConfigMap = {
1002
+ claude: { fileName: 'CLAUDE.md', name: 'Claude' },
1003
+ codex: { fileName: 'AGENTS.md', name: 'Codex' },
1004
+ gemini: { fileName: 'GEMINI.md', name: 'Gemini' }
1005
+ };
1006
+
1007
+ // 遍历所有选中的 AI 配置类型
1008
+ for (const aiConfigType of aiConfigTypes) {
1009
+ let aiConfig = null;
1010
+ if (template.aiConfigs && template.aiConfigs[aiConfigType]) {
1011
+ aiConfig = template.aiConfigs[aiConfigType];
1012
+ } else if (aiConfigType === 'claude' && template.claudeMd) {
1013
+ aiConfig = template.claudeMd;
1014
+ }
1015
+
1016
+ if (aiConfig?.enabled && aiConfig?.content) {
1017
+ const configInfo = aiConfigMap[aiConfigType];
1018
+ const configPath = path.join(targetDir, configInfo.fileName);
1019
+ if (fs.existsSync(configPath)) {
1020
+ preview.willOverwrite.push(configInfo.fileName);
1021
+ } else {
1022
+ preview.willCreate.push(configInfo.fileName);
1023
+ }
1024
+ preview.summary.aiConfigs.push({ type: aiConfigType, fileName: configInfo.fileName, name: configInfo.name });
650
1025
  }
651
- preview.summary.claudeMd = true;
652
1026
  }
653
1027
 
654
1028
  // Skills 摘要