@cloudbase/cli 2.9.2 → 2.9.3

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.
@@ -0,0 +1,60 @@
1
+ # 需求文档
2
+
3
+ ## 介绍
4
+
5
+ 当前 `tcb ai` 命令在下载模板时会自动修改 MCP 配置文件,将 `npx npm-global-exec@latest @cloudbase/cloudbase-mcp@latest` 命令替换为 `cloudbase-mcp`,但 `tcb pull` 命令没有实现这个功能。这导致用户使用 `tcb pull` 下载的模板中的 MCP 配置仍然使用 npx 命令,需要额外安装依赖,降低了配置成功率。
6
+
7
+ ## 需求
8
+
9
+ ### 需求 1 - tcb pull 命令集成 MCP 配置修改
10
+
11
+ **用户故事:** 作为开发者,我希望使用 `tcb pull` 命令下载模板后,系统能够自动修改 MCP 配置文件,将 npx 命令替换为 CLI 提供的全局命令,避免额外的依赖安装。
12
+
13
+ #### 验收标准
14
+
15
+ 1. When 使用 `tcb pull` 命令下载模板完成后,the 系统 shall 自动检测并修改所有 MCP 配置文件
16
+ 2. When 发现 `.cursor/mcp.json` 等配置文件时,the 系统 shall 将 `npx npm-global-exec@latest @cloudbase/cloudbase-mcp@latest` 替换为 `cloudbase-mcp`
17
+ 3. When 修改完成后,the 系统 shall 验证配置文件的正确性
18
+ 4. When 用户使用 `tcb pull` 下载的模板时,the MCP 功能 shall 无需额外安装即可正常工作
19
+
20
+ ### 需求 2 - 保持与 tcb ai 命令的一致性
21
+
22
+ **用户故事:** 作为开发者,我希望 `tcb pull` 和 `tcb ai` 命令在模板下载和 MCP 配置修改方面保持一致的行为,避免混淆。
23
+
24
+ #### 验收标准
25
+
26
+ 1. When 使用 `tcb pull` 下载模板时,the MCP 配置修改逻辑 shall 与 `tcb ai` 命令完全一致
27
+ 2. When 支持相同的 IDE 配置文件格式时,the 系统 shall 使用相同的修改规则
28
+ 3. When 处理 JSON 和 TOML 格式时,the 系统 shall 使用相同的转换逻辑
29
+ 4. When 出现错误时,the 系统 shall 提供相同的错误处理和日志记录
30
+
31
+ ### 需求 3 - 支持所有内置模板和 Git 仓库
32
+
33
+ **用户故事:** 作为开发者,我希望无论从内置模板还是 Git 仓库下载内容,`tcb pull` 命令都能正确处理 MCP 配置。
34
+
35
+ #### 验收标准
36
+
37
+ 1. When 下载内置模板(miniprogram、react、vue、uniapp、rules)时,the 系统 shall 自动修改 MCP 配置
38
+ 2. When 从 Git 仓库下载模板时,the 系统 shall 自动修改 MCP 配置
39
+ 3. When 从 Git 子目录下载内容时,the 系统 shall 自动修改 MCP 配置
40
+ 4. When 支持多种 IDE 配置时,the 系统 shall 处理所有相关的配置文件
41
+
42
+ ### 需求 4 - 向后兼容性
43
+
44
+ **用户故事:** 作为开发者,我希望新功能不会影响现有的 `tcb pull` 命令功能,保持向后兼容。
45
+
46
+ #### 验收标准
47
+
48
+ 1. When 现有 `tcb pull` 命令功能使用时,the 系统 shall 保持原有行为不变
49
+ 2. When 新增 MCP 配置修改功能时,the 系统 shall 不影响模板下载的核心流程
50
+ 3. When 出现 MCP 配置修改失败时,the 系统 shall 不影响模板下载的成功完成
51
+ 4. When 用户可以选择跳过 MCP 配置修改时,the 系统 shall 提供相应的选项
52
+
53
+ ## 技术约束
54
+
55
+ - 必须复用 `tcb ai` 命令中已有的 MCP 配置修改逻辑
56
+ - 必须支持 JSON 和 TOML 两种配置文件格式
57
+ - 必须支持所有已定义的 IDE 配置文件映射
58
+ - 必须保持与现有代码架构的一致性
59
+
60
+
@@ -0,0 +1,125 @@
1
+ # 实施计划
2
+
3
+ ## 阶段一:代码重构和提取
4
+
5
+ - [x] 1. 提取 MCP 配置修改逻辑
6
+ - 从 `src/utils/ai/router.ts` 中提取 `modifyMCPConfigs` 相关方法
7
+ - 创建独立的 `MCPConfigModifier` 工具类
8
+ - 提取 IDE 配置文件映射常量
9
+ - 提取配置文件格式推断逻辑
10
+ - _需求: 需求 1, 需求 2
11
+
12
+ - [x] 2. 创建 MCPConfigModifier 类
13
+ - 实现 `modifyMCPConfigs` 主方法
14
+ - 实现 `modifyMCPJsonFile` 方法
15
+ - 实现 `modifyMCPTomlFile` 方法
16
+ - 实现 `objectToToml` 辅助方法
17
+ - 添加完整的错误处理和日志记录
18
+ - _需求: 需求 1, 需求 2
19
+
20
+ - [x] 3. 提取共享常量和类型
21
+ - 将 `IDE_FILE_MAPPINGS` 常量移动到共享位置
22
+ - 将 `IdeFileDescriptor` 接口移动到共享位置
23
+ - 将 `inferConfigFormat` 函数移动到共享位置
24
+ - 确保类型定义的一致性
25
+ - _需求: 需求 2
26
+
27
+ ## 阶段二:TemplateManager 集成
28
+
29
+ - [x] 4. 修改 TemplateManager 类
30
+ - 在 `TemplateManager` 构造函数中初始化 `MCPConfigModifier`
31
+ - 在 `copyFromTempToTarget` 方法完成后调用 MCP 配置修改
32
+ - 添加错误处理,确保 MCP 配置修改失败不影响模板下载
33
+ - 添加相应的日志记录
34
+ - _需求: 需求 1, 需求 4
35
+
36
+ - [x] 5. 集成点优化
37
+ - 确保 MCP 配置修改在正确的时机执行
38
+ - 优化执行顺序,避免重复文件操作
39
+ - 添加性能监控和日志记录
40
+ - 支持可选的 MCP 配置修改跳过
41
+ - _需求: 需求 1, 需求 4
42
+
43
+ ## 阶段三:测试和验证
44
+
45
+ - [x] 6. 单元测试编写
46
+ - 为 `MCPConfigModifier` 类编写单元测试
47
+ - 测试 JSON 配置文件修改逻辑
48
+ - 测试 TOML 配置文件修改逻辑
49
+ - 测试错误处理机制
50
+ - 测试边界情况
51
+ - _需求: 需求 1, 需求 2
52
+
53
+ - [x] 7. 集成测试编写
54
+ - 测试 `tcb pull` 命令的完整流程
55
+ - 测试内置模板的 MCP 配置修改
56
+ - 测试 Git 仓库的 MCP 配置修改
57
+ - 测试 Git 子目录的 MCP 配置修改
58
+ - 测试与现有功能的兼容性
59
+ - _需求: 需求 1, 需求 3
60
+
61
+ - [x] 8. 端到端测试
62
+ - 测试完整的模板下载和配置修改流程
63
+ - 测试不同 IDE 配置文件的生成和修改
64
+ - 测试错误场景的处理和恢复
65
+ - 测试性能影响和资源使用
66
+ - _需求: 需求 1, 需求 2, 需求 3
67
+
68
+ ## 阶段四:文档和优化
69
+
70
+ - [ ] 9. 文档更新
71
+ - 更新 `docs/template-pull.md` 文档
72
+ - 添加 MCP 配置修改功能的说明
73
+ - 更新命令使用示例
74
+ - 添加故障排除指南
75
+ - _需求: 需求 1, 需求 2
76
+
77
+ - [ ] 10. 代码优化
78
+ - 优化文件遍历和修改逻辑
79
+ - 减少重复的文件系统操作
80
+ - 优化内存使用和性能
81
+ - 添加配置选项和开关
82
+ - _需求: 需求 4
83
+
84
+ ## 阶段五:发布和部署
85
+
86
+ - [ ] 11. 代码审查
87
+ - 确保代码质量和一致性
88
+ - 验证与现有架构的兼容性
89
+ - 检查安全性和性能影响
90
+ - 确保测试覆盖率
91
+ - _需求: 所有需求
92
+
93
+ - [ ] 12. 发布准备
94
+ - 更新版本号和变更日志
95
+ - 准备发布说明
96
+ - 验证所有功能正常工作
97
+ - 准备回滚计划
98
+ - _需求: 所有需求
99
+
100
+ ## 验收标准检查
101
+
102
+ ### 需求 1 - tcb pull 命令集成 MCP 配置修改
103
+ - [x] When 使用 `tcb pull` 命令下载模板完成后,the 系统 shall 自动检测并修改所有 MCP 配置文件
104
+ - [x] When 发现 `.cursor/mcp.json` 等配置文件时,the 系统 shall 将 `npx npm-global-exec@latest @cloudbase/cloudbase-mcp@latest` 替换为 `cloudbase-mcp`
105
+ - [x] When 修改完成后,the 系统 shall 验证配置文件的正确性
106
+ - [x] When 用户使用 `tcb pull` 下载的模板时,the MCP 功能 shall 无需额外安装即可正常工作
107
+
108
+ ### 需求 2 - 保持与 tcb ai 命令的一致性
109
+ - [x] When 使用 `tcb pull` 下载模板时,the MCP 配置修改逻辑 shall 与 `tcb ai` 命令完全一致
110
+ - [x] When 支持相同的 IDE 配置文件格式时,the 系统 shall 使用相同的修改规则
111
+ - [x] When 处理 JSON 和 TOML 格式时,the 系统 shall 使用相同的转换逻辑
112
+ - [x] When 出现错误时,the 系统 shall 提供相同的错误处理和日志记录
113
+
114
+ ### 需求 3 - 支持所有内置模板和 Git 仓库
115
+ - [x] When 下载内置模板(miniprogram、react、vue、uniapp、rules)时,the 系统 shall 自动修改 MCP 配置
116
+ - [x] When 从 Git 仓库下载模板时,the 系统 shall 自动修改 MCP 配置
117
+ - [x] When 从 Git 子目录下载内容时,the 系统 shall 自动修改 MCP 配置
118
+ - [x] When 支持多种 IDE 配置时,the 系统 shall 处理所有相关的配置文件
119
+
120
+ ### 需求 4 - 向后兼容性
121
+ - [x] When 现有 `tcb pull` 命令功能使用时,the 系统 shall 保持原有行为不变
122
+ - [x] When 新增 MCP 配置修改功能时,the 系统 shall 不影响模板下载的核心流程
123
+ - [x] When 出现 MCP 配置修改失败时,the 系统 shall 不影响模板下载的成功完成
124
+ - [x] When 用户可以选择跳过 MCP 配置修改时,the 系统 shall 提供相应的选项
125
+
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env node
2
+
3
+ const path = require('path');
4
+ const fs = require('fs-extra');
5
+
6
+ // 模拟 Logger
7
+ const mockLogger = {
8
+ info: (...args) => console.log('ℹ️', ...args),
9
+ warn: (...args) => console.log('⚠️', ...args),
10
+ error: (...args) => console.log('❌', ...args),
11
+ debug: (...args) => console.log('🔍', ...args),
12
+ log: (...args) => console.log(...args)
13
+ };
14
+
15
+ async function testMCPIntegration() {
16
+ console.log('🧪 测试 MCP 配置修改功能...\n');
17
+
18
+ try {
19
+ // 动态导入 MCPConfigModifier
20
+ const { MCPConfigModifier } = await import('./lib/utils/mcp-config-modifier.js');
21
+
22
+ const mcpConfigModifier = new MCPConfigModifier();
23
+ const testDir = path.join(__dirname, 'test-demo');
24
+
25
+ console.log(`📁 测试目录: ${testDir}`);
26
+
27
+ // 检查测试文件是否存在
28
+ const files = [
29
+ '.cursor/mcp.json',
30
+ '.vscode/mcp.json',
31
+ '.codex/config.toml'
32
+ ];
33
+
34
+ console.log('\n📋 测试前的文件内容:');
35
+ for (const file of files) {
36
+ const filePath = path.join(testDir, file);
37
+ if (await fs.pathExists(filePath)) {
38
+ const content = await fs.readFile(filePath, 'utf-8');
39
+ console.log(`\n${file}:`);
40
+ console.log(content);
41
+ }
42
+ }
43
+
44
+ // 执行 MCP 配置修改
45
+ console.log('\n🔧 执行 MCP 配置修改...');
46
+ await mcpConfigModifier.modifyMCPConfigs(testDir, mockLogger);
47
+
48
+ // 检查修改后的文件
49
+ console.log('\n📋 测试后的文件内容:');
50
+ for (const file of files) {
51
+ const filePath = path.join(testDir, file);
52
+ if (await fs.pathExists(filePath)) {
53
+ const content = await fs.readFile(filePath, 'utf-8');
54
+ console.log(`\n${file}:`);
55
+ console.log(content);
56
+ }
57
+ }
58
+
59
+ console.log('\n✅ MCP 配置修改测试完成!');
60
+
61
+ } catch (error) {
62
+ console.error('❌ 测试失败:', error);
63
+ process.exit(1);
64
+ }
65
+ }
66
+
67
+ // 运行测试
68
+ testMCPIntegration();
@@ -27,6 +27,10 @@ export declare const TOOLKIT_CONFIGS: {
27
27
  mcp: string;
28
28
  rules: string;
29
29
  config?: undefined;
30
+ } | {
31
+ config: string;
32
+ mcp: string;
33
+ rules: string;
30
34
  } | {
31
35
  config: string;
32
36
  mcp?: undefined;
@@ -230,6 +230,25 @@ export declare const AGENTS: readonly [{
230
230
  model?: string;
231
231
  provider?: string;
232
232
  }>]>;
233
+ }, {
234
+ name: string;
235
+ value: string;
236
+ configSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
237
+ type: z.ZodLiteral<"none">;
238
+ }, "strip", z.ZodTypeAny, {
239
+ type?: "none";
240
+ }, {
241
+ type?: "none";
242
+ }>, z.ZodObject<{
243
+ type: z.ZodLiteral<"custom">;
244
+ apiKey: z.ZodOptional<z.ZodString>;
245
+ }, "strip", z.ZodTypeAny, {
246
+ type?: "custom";
247
+ apiKey?: string;
248
+ }, {
249
+ type?: "custom";
250
+ apiKey?: string;
251
+ }>]>;
233
252
  }, {
234
253
  name: string;
235
254
  value: string;
@@ -345,25 +364,6 @@ export declare const AGENTS: readonly [{
345
364
  }, {
346
365
  type?: "none";
347
366
  }>;
348
- }, {
349
- name: string;
350
- value: string;
351
- configSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
352
- type: z.ZodLiteral<"none">;
353
- }, "strip", z.ZodTypeAny, {
354
- type?: "none";
355
- }, {
356
- type?: "none";
357
- }>, z.ZodObject<{
358
- type: z.ZodLiteral<"custom">;
359
- apiKey: z.ZodOptional<z.ZodString>;
360
- }, "strip", z.ZodTypeAny, {
361
- type?: "custom";
362
- apiKey?: string;
363
- }, {
364
- type?: "custom";
365
- apiKey?: string;
366
- }>]>;
367
367
  }, {
368
368
  name: string;
369
369
  value: string;
@@ -0,0 +1,7 @@
1
+ import { Logger } from './log';
2
+ export declare class MCPConfigModifier {
3
+ modifyMCPConfigs(extractDir: string, log: Logger): Promise<void>;
4
+ private modifyMCPJsonFile;
5
+ private modifyMCPTomlFile;
6
+ private objectToToml;
7
+ }
@@ -5,6 +5,7 @@ interface PullOptions {
5
5
  }
6
6
  export declare class TemplateManager {
7
7
  private git;
8
+ private mcpConfigModifier;
8
9
  constructor();
9
10
  pullTemplate(source: string, options: PullOptions, log: Logger): Promise<void>;
10
11
  private isBuiltinTemplate;