@cloudbase/cli 2.8.0-beta.4 → 2.8.0-beta.5
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.
- package/.augment-guidelines +119 -0
- package/.clinerules/cloudbase-rules.mdc +119 -0
- package/.cursor/rules/cloudbase-rules.mdc +119 -0
- package/.mcp.json +11 -0
- package/CLAUDE.md +119 -0
- package/README.md +13 -1
- package/bin/cloudbase-mcp.js +24 -0
- package/bin/tcb.js +0 -2
- package/cloudbaserc.json +3 -0
- package/lib/commands/ai/index.js +172 -0
- package/lib/commands/cloudrun/base.js +2 -2
- package/lib/commands/index.js +1 -0
- package/lib/commands/utils.js +10 -4
- package/lib/utils/ai/banner.js +88 -0
- package/lib/utils/ai/config.js +254 -0
- package/lib/utils/ai/const.js +150 -0
- package/lib/utils/ai/ensureFiles.js +26 -0
- package/lib/utils/ai/envLocalManager.js +144 -0
- package/lib/utils/ai/router.js +1089 -0
- package/lib/utils/ai/setup.js +550 -0
- package/package.json +11 -3
- package/rules/cloudbase-platform.mdc +44 -0
- package/rules/database.mdc +25 -0
- package/rules/miniprogram-development.mdc +61 -0
- package/rules/ui-design.mdc +24 -0
- package/rules/web-development.mdc +44 -0
- package/rules/workflows.mdc +30 -0
- package/specs/ai-cli-bootstrap/QWEN.md +196 -0
- package/specs/ai-cli-bootstrap/design.md +185 -0
- package/specs/ai-cli-bootstrap/requirements.md +51 -0
- package/specs/ai-cli-bootstrap/tasks.md +70 -0
- package/specs/ai-cli-bootstrap/technical-docs.md +421 -0
- package/specs/mcp-global-bin/design.md +57 -0
- package/specs/mcp-global-bin/requirements.md +43 -0
- package/specs/mcp-global-bin/tasks.md +54 -0
- package/types/commands/ai/index.d.ts +23 -0
- package/types/commands/index.d.ts +1 -0
- package/types/commands/utils.d.ts +6 -0
- package/types/utils/ai/banner.d.ts +2 -0
- package/types/utils/ai/config.d.ts +79 -0
- package/types/utils/ai/const.d.ts +323 -0
- package/types/utils/ai/ensureFiles.d.ts +1 -0
- package/types/utils/ai/envLocalManager.d.ts +23 -0
- package/types/utils/ai/router.d.ts +45 -0
- package/types/utils/ai/setup.d.ts +23 -0
- package/types/utils/config.d.ts +1 -0
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
# AI 开发套件
|
|
2
|
+
|
|
3
|
+
AI 开发套件是云开发为用户提供的 AI 辅助开发能力,用户可以通过云开发提供的 CLI 工具快速启动和配置主流 AI 编程工具,如 Claude Code、OpenAI Codex、Gemini CLI 等。AI 开发套件内置云开发全栈能力,支持生成、部署和托管全栈 Web 应用与小程序、数据库和后端服务。
|
|
4
|
+
|
|
5
|
+
## 命令总览
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
tcb ai [options] -- [agent-args]
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 路径说明
|
|
12
|
+
|
|
13
|
+
* `options` 为 AI 开发套件的配置选项,如 `-a claude`、`-e my-env` 等。
|
|
14
|
+
* `agent-args` 为目标 AI CLI 工具的原生参数,通过 `--` 分隔符透传。
|
|
15
|
+
|
|
16
|
+
⚠️ 注意事项
|
|
17
|
+
|
|
18
|
+
* `--` 分隔符后的所有参数将原样传递给目标 AI CLI 工具,请确保参数格式正确。
|
|
19
|
+
* 首次使用需要运行 `tcb ai --setup` 进行配置。
|
|
20
|
+
* 确保已安装目标 AI CLI 工具,如 Claude Code、OpenAI CLI 等。
|
|
21
|
+
|
|
22
|
+
## 快速开始
|
|
23
|
+
|
|
24
|
+
### 1. 配置 AI 开发套件
|
|
25
|
+
|
|
26
|
+
首次使用需要配置 AI 开发套件:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# 启动配置向导
|
|
30
|
+
tcb ai --setup
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
配置向导将引导您:
|
|
34
|
+
- 选择默认的 AI 工具(Claude Code、OpenAI Codex、Gemini CLI)
|
|
35
|
+
- 配置 API 密钥和基础 URL
|
|
36
|
+
- 设置云开发环境 ID
|
|
37
|
+
- 选择模型和协议类型
|
|
38
|
+
|
|
39
|
+
### 2. 启动 AI 工具
|
|
40
|
+
|
|
41
|
+
配置完成后,可以直接启动 AI 工具:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
# 使用默认配置启动 Claude Code
|
|
45
|
+
tcb ai -a claude -- --continue
|
|
46
|
+
|
|
47
|
+
# 指定环境 ID 启动
|
|
48
|
+
tcb ai -a claude -e my-env -- --model=claude-3.5-sonnet
|
|
49
|
+
|
|
50
|
+
# 查看帮助信息
|
|
51
|
+
tcb ai -a claude -- --help
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## 核心功能
|
|
55
|
+
|
|
56
|
+
### 启动 AI 工具
|
|
57
|
+
|
|
58
|
+
您可以使用下面的命令启动配置好的 AI 工具:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
tcb ai -a <agent> [options] -- [agent-args]
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**参数说明:**
|
|
65
|
+
- `-a, --agent <name>`: 指定 AI 工具名称(claude/codex/gemini)
|
|
66
|
+
- `-e, --envId <id>`: 指定云开发环境 ID
|
|
67
|
+
- `--`: 参数分隔符,后面的参数将透传给 AI 工具
|
|
68
|
+
|
|
69
|
+
**使用示例:**
|
|
70
|
+
```bash
|
|
71
|
+
# 启动 Claude Code 并继续上次会话
|
|
72
|
+
tcb ai -a claude -- --continue
|
|
73
|
+
|
|
74
|
+
# 启动 OpenAI Codex 并指定模型
|
|
75
|
+
tcb ai -a codex -- --model=gpt-4
|
|
76
|
+
|
|
77
|
+
# 启动 Gemini CLI 并设置最大 token
|
|
78
|
+
tcb ai -a gemini -- --max-tokens=4096
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### 配置管理
|
|
82
|
+
|
|
83
|
+
#### 查看当前配置
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
tcb ai --config
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
显示当前配置信息,包括:
|
|
90
|
+
- 默认 AI 工具
|
|
91
|
+
- API 密钥状态
|
|
92
|
+
- 环境 ID 配置
|
|
93
|
+
- 模型和协议设置
|
|
94
|
+
|
|
95
|
+
#### 重置配置
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
tcb ai --reset
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
清除所有配置信息,恢复到初始状态。
|
|
102
|
+
|
|
103
|
+
#### 交互式配置
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
tcb ai --setup
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
启动交互式配置向导,引导您完成:
|
|
110
|
+
- AI 工具选择和配置
|
|
111
|
+
- API 密钥设置
|
|
112
|
+
- 云开发环境绑定
|
|
113
|
+
- 协议和模型选择
|
|
114
|
+
|
|
115
|
+
## 支持的 AI 工具
|
|
116
|
+
|
|
117
|
+
### Claude Code
|
|
118
|
+
|
|
119
|
+
Claude Code 是 Anthropic 推出的 AI 编程助手,支持自然语言编程和代码生成。
|
|
120
|
+
|
|
121
|
+
**安装命令:**
|
|
122
|
+
```bash
|
|
123
|
+
npm install -g @anthropic-ai/claude-code
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**配置要求:**
|
|
127
|
+
- API 密钥:`ANTHROPIC_API_KEY`
|
|
128
|
+
- 基础 URL:`https://api.anthropic.com`
|
|
129
|
+
- 支持模型:claude-3.5-sonnet, claude-3-opus 等
|
|
130
|
+
|
|
131
|
+
**使用示例:**
|
|
132
|
+
```bash
|
|
133
|
+
# 启动 Claude Code
|
|
134
|
+
tcb ai -a claude -- --continue
|
|
135
|
+
|
|
136
|
+
# 指定模型和参数
|
|
137
|
+
tcb ai -a claude -- --model=claude-3.5-sonnet --max-tokens=4096
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### OpenAI Codex
|
|
141
|
+
|
|
142
|
+
OpenAI Codex 是 OpenAI 的代码生成 AI,基于 GPT 模型优化。
|
|
143
|
+
|
|
144
|
+
**安装命令:**
|
|
145
|
+
```bash
|
|
146
|
+
npm install -g openai
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
**配置要求:**
|
|
150
|
+
- API 密钥:`OPENAI_API_KEY`
|
|
151
|
+
- 基础 URL:`https://api.openai.com`
|
|
152
|
+
- 支持模型:gpt-4, gpt-3.5-turbo 等
|
|
153
|
+
|
|
154
|
+
**使用示例:**
|
|
155
|
+
```bash
|
|
156
|
+
# 启动 OpenAI Codex
|
|
157
|
+
tcb ai -a codex -- --model=gpt-4
|
|
158
|
+
|
|
159
|
+
# 设置温度和最大 token
|
|
160
|
+
tcb ai -a codex -- --temperature=0.7 --max-tokens=2048
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Gemini CLI
|
|
164
|
+
|
|
165
|
+
Gemini CLI 是 Google 的 AI 编程工具,基于 Gemini 模型。
|
|
166
|
+
|
|
167
|
+
**安装命令:**
|
|
168
|
+
```bash
|
|
169
|
+
npm install -g @google/generative-ai
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
**配置要求:**
|
|
173
|
+
- API 密钥:`GOOGLE_API_KEY`
|
|
174
|
+
- 基础 URL:`https://generativelanguage.googleapis.com`
|
|
175
|
+
- 支持模型:gemini-2.0-flash, gemini-2.0-pro 等
|
|
176
|
+
|
|
177
|
+
**使用示例:**
|
|
178
|
+
```bash
|
|
179
|
+
# 启动 Gemini CLI
|
|
180
|
+
tcb ai -a gemini -- --model=gemini-2.0-pro
|
|
181
|
+
|
|
182
|
+
# 设置安全过滤
|
|
183
|
+
tcb ai -a gemini -- --safety-level=BLOCK_MEDIUM_AND_ABOVE
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## 协议适配
|
|
187
|
+
|
|
188
|
+
### Anthropic 协议
|
|
189
|
+
|
|
190
|
+
支持 Anthropic 协议的 AI 工具可以直接透传:
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
# Claude Code(原生支持)
|
|
194
|
+
tcb ai -a claude -- --continue
|
|
195
|
+
|
|
196
|
+
# Kimi(支持 Anthropic 协议)
|
|
197
|
+
tcb ai -a kimi -- --model=claude-3.5-sonnet
|
|
198
|
+
|
|
199
|
+
# K2(支持 Anthropic 协议)
|
|
200
|
+
tcb ai -a k2 -- --max-tokens=4096
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### OpenAI 协议
|
|
204
|
+
|
|
205
|
+
支持 OpenAI 协议的 AI 工具通过 claude-code-router 转发:
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
# 自动检测并安装 claude-code-router
|
|
209
|
+
tcb ai -a openai -- --model=gpt-4
|
|
210
|
+
|
|
211
|
+
# 自定义 OpenAI 兼容服务
|
|
212
|
+
tcb ai -a custom -- --base-url=https://api.example.com
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## 云开发集成
|
|
216
|
+
|
|
217
|
+
### 环境变量注入
|
|
218
|
+
|
|
219
|
+
AI 开发套件会自动注入云开发相关环境变量:
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
# 自动注入环境 ID
|
|
223
|
+
tcb ai -a claude -e my-env -- --continue
|
|
224
|
+
|
|
225
|
+
# 环境变量示例
|
|
226
|
+
CLOUDBASE_ENV_ID=my-env
|
|
227
|
+
CLOUDBASE_REGION=ap-shanghai
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### 模板下载
|
|
231
|
+
|
|
232
|
+
支持下载云开发项目模板:
|
|
233
|
+
|
|
234
|
+
```bash
|
|
235
|
+
# 下载 React + CloudBase 模板
|
|
236
|
+
tcb ai --template react
|
|
237
|
+
|
|
238
|
+
# 下载小程序模板
|
|
239
|
+
tcb ai --template miniprogram
|
|
240
|
+
|
|
241
|
+
# 下载 Vue + CloudBase 模板
|
|
242
|
+
tcb ai --template vue
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
**支持的模板类型:**
|
|
246
|
+
- `rules`: AI 编辑器配置模板
|
|
247
|
+
- `react`: React + CloudBase 全栈应用
|
|
248
|
+
- `vue`: Vue + CloudBase 全栈应用
|
|
249
|
+
- `miniprogram`: 微信小程序 + 云开发
|
|
250
|
+
- `uniapp`: UniApp + CloudBase 跨端应用
|
|
251
|
+
|
|
252
|
+
### 自动部署
|
|
253
|
+
|
|
254
|
+
AI 工具生成的代码可以直接部署到云开发:
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
# 生成并部署 React 应用
|
|
258
|
+
tcb ai -a claude -e my-env -- --prompt="创建一个 React 购物车应用"
|
|
259
|
+
|
|
260
|
+
# 部署到云函数
|
|
261
|
+
tcb ai -a claude -e my-env -- --prompt="创建一个用户注册云函数"
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## 高级配置
|
|
265
|
+
|
|
266
|
+
### 自定义 Provider
|
|
267
|
+
|
|
268
|
+
支持配置自定义 AI 服务提供商:
|
|
269
|
+
|
|
270
|
+
```json
|
|
271
|
+
{
|
|
272
|
+
"defaultAgent": "custom",
|
|
273
|
+
"agents": {
|
|
274
|
+
"custom": {
|
|
275
|
+
"command": "claude",
|
|
276
|
+
"apiKey": "sk-xxx",
|
|
277
|
+
"baseUrl": "https://api.custom-ai.com",
|
|
278
|
+
"model": "custom-model"
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### 多环境支持
|
|
285
|
+
|
|
286
|
+
支持配置多个云开发环境:
|
|
287
|
+
|
|
288
|
+
```bash
|
|
289
|
+
# 开发环境
|
|
290
|
+
tcb ai -a claude -e dev-env -- --continue
|
|
291
|
+
|
|
292
|
+
# 生产环境
|
|
293
|
+
tcb ai -a claude -e prod-env -- --continue
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
### 代理配置
|
|
297
|
+
|
|
298
|
+
支持通过代理访问 AI 服务:
|
|
299
|
+
|
|
300
|
+
```bash
|
|
301
|
+
# 设置代理
|
|
302
|
+
export HTTP_PROXY=http://127.0.0.1:7890
|
|
303
|
+
export HTTPS_PROXY=http://127.0.0.1:7890
|
|
304
|
+
|
|
305
|
+
# 启动 AI 工具
|
|
306
|
+
tcb ai -a claude -- --continue
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
## 故障排除
|
|
310
|
+
|
|
311
|
+
### 常见问题
|
|
312
|
+
|
|
313
|
+
#### 1. AI 工具未安装
|
|
314
|
+
|
|
315
|
+
**错误信息:** `⚠️ claude 工具未安装`
|
|
316
|
+
|
|
317
|
+
**解决方案:**
|
|
318
|
+
```bash
|
|
319
|
+
# 安装 Claude Code
|
|
320
|
+
npm install -g @anthropic-ai/claude-code
|
|
321
|
+
|
|
322
|
+
# 检查安装
|
|
323
|
+
claude doctor
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
#### 2. API 密钥无效
|
|
327
|
+
|
|
328
|
+
**错误信息:** `❌ API 密钥无效`
|
|
329
|
+
|
|
330
|
+
**解决方案:**
|
|
331
|
+
```bash
|
|
332
|
+
# 重新配置
|
|
333
|
+
tcb ai --setup
|
|
334
|
+
|
|
335
|
+
# 检查 API 密钥格式
|
|
336
|
+
# Claude: sk-ant-api03-xxx
|
|
337
|
+
# OpenAI: sk-xxx
|
|
338
|
+
# Google: AIzaSyCxxx
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
#### 3. 网络连接问题
|
|
342
|
+
|
|
343
|
+
**错误信息:** `❌ 网络连接失败`
|
|
344
|
+
|
|
345
|
+
**解决方案:**
|
|
346
|
+
```bash
|
|
347
|
+
# 检查网络连接
|
|
348
|
+
ping api.anthropic.com
|
|
349
|
+
|
|
350
|
+
# 配置代理
|
|
351
|
+
export HTTP_PROXY=http://127.0.0.1:7890
|
|
352
|
+
|
|
353
|
+
# 使用国内镜像(如果支持)
|
|
354
|
+
tcb ai -a claude -- --base-url=https://api.anthropic.cn
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
#### 4. 模板下载失败
|
|
358
|
+
|
|
359
|
+
**错误信息:** `❌ 模板下载失败`
|
|
360
|
+
|
|
361
|
+
**解决方案:**
|
|
362
|
+
```bash
|
|
363
|
+
# 检查网络连接
|
|
364
|
+
curl -I https://static.cloudbase.net
|
|
365
|
+
|
|
366
|
+
# 重新下载
|
|
367
|
+
tcb ai --template react --force
|
|
368
|
+
|
|
369
|
+
# 手动下载模板
|
|
370
|
+
wget https://static.cloudbase.net/cloudbase-examples/web-cloudbase-react-template.zip
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
### 调试模式
|
|
374
|
+
|
|
375
|
+
启用调试模式获取详细信息:
|
|
376
|
+
|
|
377
|
+
```bash
|
|
378
|
+
# 启用调试
|
|
379
|
+
DEBUG=* tcb ai -a claude -- --continue
|
|
380
|
+
|
|
381
|
+
# 查看详细日志
|
|
382
|
+
tcb ai -a claude -- --verbose --continue
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
## 最佳实践
|
|
386
|
+
|
|
387
|
+
### 1. 配置管理
|
|
388
|
+
|
|
389
|
+
- 使用 `tcb ai --setup` 进行初始配置
|
|
390
|
+
- 定期更新 API 密钥
|
|
391
|
+
- 为不同项目使用不同的环境 ID
|
|
392
|
+
|
|
393
|
+
### 2. 安全考虑
|
|
394
|
+
|
|
395
|
+
- 不要在代码中硬编码 API 密钥
|
|
396
|
+
- 使用环境变量存储敏感信息
|
|
397
|
+
- 定期轮换 API 密钥
|
|
398
|
+
|
|
399
|
+
### 3. 性能优化
|
|
400
|
+
|
|
401
|
+
- 选择合适的模型和参数
|
|
402
|
+
- 使用 `--continue` 保持会话连续性
|
|
403
|
+
- 合理设置 `max-tokens` 参数
|
|
404
|
+
|
|
405
|
+
### 4. 云开发集成
|
|
406
|
+
|
|
407
|
+
- 充分利用云开发的全栈能力
|
|
408
|
+
- 使用模板快速搭建项目
|
|
409
|
+
- 结合云函数和数据库构建完整应用
|
|
410
|
+
|
|
411
|
+
## 相关资源
|
|
412
|
+
|
|
413
|
+
- [CloudBase CLI 官方文档](https://docs.cloudbase.net/cli-v1/)
|
|
414
|
+
- [Claude Code 官方文档](https://docs.anthropic.com/en/docs/claude-code)
|
|
415
|
+
- [OpenAI API 文档](https://platform.openai.com/docs)
|
|
416
|
+
- [Google AI Studio](https://aistudio.google.com/)
|
|
417
|
+
- [云开发社区](https://cloudbase.net/community)
|
|
418
|
+
|
|
419
|
+
---
|
|
420
|
+
|
|
421
|
+
上一页[云存储](./storage) 下一页[静态网站托管](./hosting)
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# 技术方案设计
|
|
2
|
+
|
|
3
|
+
## 架构概述
|
|
4
|
+
|
|
5
|
+
本方案通过在 CLI 中暴露一个全局的 `cloudbase-mcp` bin 命令,直接调用内置的 `@cloudbase/cloudbase-mcp` 包,并修改模板下载逻辑,使所有 MCP 配置都指向这个全局命令,从而避免用户需要额外安装 MCP 包。
|
|
6
|
+
|
|
7
|
+
## 技术栈
|
|
8
|
+
|
|
9
|
+
- Node.js CLI 工具
|
|
10
|
+
- `@cloudbase/cloudbase-mcp` 内置依赖
|
|
11
|
+
- 文件系统操作 (fs-extra)
|
|
12
|
+
- 模板下载和解压
|
|
13
|
+
|
|
14
|
+
## 技术选型
|
|
15
|
+
|
|
16
|
+
### 1. Bin 文件创建
|
|
17
|
+
- 在 `bin/` 目录下创建 `cloudbase-mcp.js` 文件
|
|
18
|
+
- 在 `package.json` 的 `bin` 字段中注册 `cloudbase-mcp` 命令
|
|
19
|
+
- 直接调用内置的 `@cloudbase/cloudbase-mcp` 包
|
|
20
|
+
|
|
21
|
+
### 2. 模板配置生成
|
|
22
|
+
- 修改 `router.ts` 中的模板下载逻辑
|
|
23
|
+
- 根据 IDE 类型生成对应的 MCP 配置文件
|
|
24
|
+
- 所有配置都指向 `cloudbase-mcp` 命令
|
|
25
|
+
|
|
26
|
+
### 3. IDE 配置映射和格式支持
|
|
27
|
+
- 参考 CloudBase-AI-ToolKit 的 IDE 到文件映射关系
|
|
28
|
+
- 支持 Cursor、VSCode、Claude Code、OpenAI Codex、OpenCode、Aider 等多种 IDE
|
|
29
|
+
- 支持 JSON 和 TOML 两种配置文件格式
|
|
30
|
+
- 实现 TOML 解析和修改功能
|
|
31
|
+
|
|
32
|
+
## 数据库/接口设计
|
|
33
|
+
|
|
34
|
+
无需数据库设计,主要涉及文件系统操作和命令行接口。
|
|
35
|
+
|
|
36
|
+
## 测试策略
|
|
37
|
+
|
|
38
|
+
1. **单元测试**:测试 bin 文件是否正确调用内置包
|
|
39
|
+
2. **集成测试**:测试模板下载和配置生成功能
|
|
40
|
+
3. **端到端测试**:测试完整的 MCP 配置流程
|
|
41
|
+
|
|
42
|
+
## 安全性
|
|
43
|
+
|
|
44
|
+
- 确保 bin 文件有正确的执行权限
|
|
45
|
+
- 验证模板下载源的安全性
|
|
46
|
+
- 防止路径遍历攻击
|
|
47
|
+
|
|
48
|
+
## 实施计划
|
|
49
|
+
|
|
50
|
+
```mermaid
|
|
51
|
+
graph TD
|
|
52
|
+
A[创建 cloudbase-mcp.js bin 文件] --> B[在 package.json 中注册命令]
|
|
53
|
+
B --> C[修改 router.ts 模板下载逻辑]
|
|
54
|
+
C --> D[实现 IDE 配置映射]
|
|
55
|
+
D --> E[测试验证]
|
|
56
|
+
E --> F[文档更新]
|
|
57
|
+
```
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# 需求文档
|
|
2
|
+
|
|
3
|
+
## 介绍
|
|
4
|
+
|
|
5
|
+
当前下载的模板中的 MCP 配置使用 `npx npm-global-exec@latest @cloudbase/cloudbase-mcp@latest` 命令,这会导致用户需要安装 MCP,降低了成功率。CLI 已经内置了 `@cloudbase/cloudbase-mcp@latest` 依赖,需要在 CLI 中直接暴露一个额外的 bin 文件指向到这个依赖,然后修改下载模板的 MCP 配置都指向这个全局命令。
|
|
6
|
+
|
|
7
|
+
## 需求
|
|
8
|
+
|
|
9
|
+
### 需求 1 - 创建全局 MCP bin 命令
|
|
10
|
+
|
|
11
|
+
**用户故事:** 作为开发者,我希望 CLI 提供一个全局的 MCP 命令,这样我就不需要额外安装 MCP 包,提高配置成功率。
|
|
12
|
+
|
|
13
|
+
#### 验收标准
|
|
14
|
+
|
|
15
|
+
1. When CLI 安装后,the 系统 shall 提供一个全局的 `cloudbase-mcp` 命令
|
|
16
|
+
2. When 执行 `cloudbase-mcp` 命令时,the 系统 shall 直接调用内置的 `@cloudbase/cloudbase-mcp` 包
|
|
17
|
+
3. When 验证 MCP 配置时,the 配置文件中的命令 shall 指向 `cloudbase-mcp` 而不是 `npx npm-global-exec@latest @cloudbase/cloudbase-mcp@latest`
|
|
18
|
+
|
|
19
|
+
### 需求 2 - 自动修改模板 MCP 配置
|
|
20
|
+
|
|
21
|
+
**用户故事:** 作为开发者,我希望下载模板后系统自动修改 MCP 配置,将 npx 命令替换为 CLI 提供的全局命令,避免额外的依赖安装。
|
|
22
|
+
|
|
23
|
+
#### 验收标准
|
|
24
|
+
|
|
25
|
+
1. When 下载模板完成后,the 系统 shall 自动检测并修改所有 MCP 配置文件
|
|
26
|
+
2. When 发现 `.cursor/mcp.json` 等配置文件时,the 系统 shall 将 `npx npm-global-exec@latest @cloudbase/cloudbase-mcp@latest` 替换为 `cloudbase-mcp`
|
|
27
|
+
3. When 修改完成后,the 系统 shall 验证配置文件的正确性
|
|
28
|
+
4. When 用户使用模板时,the MCP 功能 shall 无需额外安装即可正常工作
|
|
29
|
+
|
|
30
|
+
### 需求 3 - 支持多种 IDE 配置和格式
|
|
31
|
+
|
|
32
|
+
**用户故事:** 作为开发者,我希望模板支持多种 IDE 的 MCP 配置,包括不同格式(JSON、TOML)和各种工具。
|
|
33
|
+
|
|
34
|
+
#### 验收标准
|
|
35
|
+
|
|
36
|
+
1. When 下载模板时,the 系统 shall 根据 IDE 类型生成对应的配置文件
|
|
37
|
+
2. When 配置 Cursor 时,the 系统 shall 生成 `.cursor/mcp.json` 和 `.cursor/rules/cloudbase-rules.mdc`
|
|
38
|
+
3. When 配置 VSCode 时,the 系统 shall 生成 `.vscode/mcp.json` 和 `.vscode/settings.json`
|
|
39
|
+
4. When 配置 Claude Code 时,the 系统 shall 生成 `CLAUDE.md` 和 `.mcp.json`
|
|
40
|
+
5. When 配置 OpenAI Codex 时,the 系统 shall 处理 `.codex/config.toml` 文件
|
|
41
|
+
6. When 配置 OpenCode 时,the 系统 shall 处理 `.opencode.json` 文件
|
|
42
|
+
7. When 配置 Aider 时,the 系统 shall 处理 `mcp.json` 文件
|
|
43
|
+
8. When 处理 TOML 格式时,the 系统 shall 正确解析和修改配置
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# 实施计划
|
|
2
|
+
|
|
3
|
+
- [x] 1. 创建 cloudbase-mcp bin 文件
|
|
4
|
+
- 在 `bin/` 目录下创建 `cloudbase-mcp.js` 文件
|
|
5
|
+
- 实现直接调用内置 `@cloudbase/cloudbase-mcp` 包的逻辑
|
|
6
|
+
- 确保文件有正确的执行权限
|
|
7
|
+
- _需求: 需求 1
|
|
8
|
+
|
|
9
|
+
- [x] 2. 在 package.json 中注册新命令
|
|
10
|
+
- 在 `bin` 字段中添加 `cloudbase-mcp` 命令映射
|
|
11
|
+
- 确保命令指向正确的 bin 文件
|
|
12
|
+
- _需求: 需求 1
|
|
13
|
+
|
|
14
|
+
- [x] 3. 实现 IDE 配置映射常量
|
|
15
|
+
- 在 `router.ts` 中添加 IDE 到文件的映射关系常量
|
|
16
|
+
- 参考 CloudBase-AI-ToolKit 的映射配置
|
|
17
|
+
- 支持 Cursor、VSCode、Claude Code 等多种 IDE
|
|
18
|
+
- _需求: 需求 3
|
|
19
|
+
|
|
20
|
+
- [x] 3.1. 扩展支持更多 IDE 和格式
|
|
21
|
+
- 添加 OpenAI Codex (.codex/config.toml) 支持
|
|
22
|
+
- 添加 OpenCode (.opencode.json) 支持
|
|
23
|
+
- 添加 Aider (mcp.json) 支持
|
|
24
|
+
- 实现 TOML 格式解析和修改功能
|
|
25
|
+
- _需求: 需求 3
|
|
26
|
+
|
|
27
|
+
- [x] 4. 修改模板下载后的处理逻辑
|
|
28
|
+
- 在 `downloadAndExtractTemplate` 方法中添加 MCP 配置修改逻辑
|
|
29
|
+
- 实现自动检测 MCP 配置文件的功能
|
|
30
|
+
- 实现将 npx 命令替换为 cloudbase-mcp 命令的功能
|
|
31
|
+
- _需求: 需求 2
|
|
32
|
+
|
|
33
|
+
- [x] 5. 实现 MCP 配置文件修改函数
|
|
34
|
+
- 创建 `modifyMCPConfigs` 函数
|
|
35
|
+
- 遍历所有 IDE 配置文件并修改命令
|
|
36
|
+
- 验证修改后的配置文件正确性
|
|
37
|
+
- _需求: 需求 2
|
|
38
|
+
|
|
39
|
+
- [x] 6. 添加配置验证功能
|
|
40
|
+
- 实现验证 MCP 配置文件格式的功能
|
|
41
|
+
- 确保修改后的配置仍然有效
|
|
42
|
+
- 添加错误处理和回滚机制
|
|
43
|
+
- _需求: 需求 2
|
|
44
|
+
|
|
45
|
+
- [x] 7. 测试验证
|
|
46
|
+
- 测试 cloudbase-mcp 命令是否正常工作
|
|
47
|
+
- 测试模板下载和配置修改功能
|
|
48
|
+
- 测试不同 IDE 配置文件的生成
|
|
49
|
+
- _需求: 需求 1, 需求 2, 需求 3
|
|
50
|
+
|
|
51
|
+
- [x] 8. 文档更新
|
|
52
|
+
- 更新 README.md 说明新的 cloudbase-mcp 命令
|
|
53
|
+
- 更新模板下载相关的文档
|
|
54
|
+
- _需求: 需求 1, 需求 2
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Command } from '../common';
|
|
2
|
+
import { ICommandContext } from '../../types';
|
|
3
|
+
import { Logger } from '../../utils/log';
|
|
4
|
+
export declare class AICommand extends Command {
|
|
5
|
+
get options(): {
|
|
6
|
+
cmd: string;
|
|
7
|
+
options: {
|
|
8
|
+
flags: string;
|
|
9
|
+
desc: string;
|
|
10
|
+
}[];
|
|
11
|
+
desc: string;
|
|
12
|
+
requiredEnvId: boolean;
|
|
13
|
+
withoutAuth: boolean;
|
|
14
|
+
allowUnknownOption: boolean;
|
|
15
|
+
};
|
|
16
|
+
execute(options: any, ctx: ICommandContext, log: Logger): Promise<void | {
|
|
17
|
+
defaultAgent: string;
|
|
18
|
+
}>;
|
|
19
|
+
private resetConfig;
|
|
20
|
+
private showConfig;
|
|
21
|
+
private parseArgs;
|
|
22
|
+
private getSubCommand;
|
|
23
|
+
}
|
|
@@ -15,6 +15,12 @@ export declare function fetchAccessToken(params: {
|
|
|
15
15
|
secretKey: string;
|
|
16
16
|
token?: string;
|
|
17
17
|
}): Promise<any>;
|
|
18
|
+
export declare function rawFetchAccessToken(params: {
|
|
19
|
+
envId: string;
|
|
20
|
+
secretId: string;
|
|
21
|
+
secretKey: string;
|
|
22
|
+
token?: string;
|
|
23
|
+
}): Promise<any>;
|
|
18
24
|
export declare function upsertCloudbaserc(projectPath: string, inputData: {
|
|
19
25
|
envId?: string;
|
|
20
26
|
[key: string]: any;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { ConfigParser } from '@cloudbase/toolbox';
|
|
2
|
+
import { CLAUDE, QWEN, CODEX, AIDER } from './const';
|
|
3
|
+
import z from 'zod/v3';
|
|
4
|
+
export declare const CONFIG_NOT_FOUND = "CONFIG_NOT_FOUND";
|
|
5
|
+
export declare function isValidAgent(agent: unknown): agent is keyof AIConfig['agents'];
|
|
6
|
+
export interface AIConfig {
|
|
7
|
+
defaultAgent: string;
|
|
8
|
+
agents: {
|
|
9
|
+
claude?: z.infer<(typeof CLAUDE)['configSchema']>;
|
|
10
|
+
qwen?: z.infer<(typeof QWEN)['configSchema']>;
|
|
11
|
+
codex?: z.infer<(typeof CODEX)['configSchema']>;
|
|
12
|
+
aider?: z.infer<(typeof AIDER)['configSchema']>;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export interface AgentConfig {
|
|
16
|
+
enabled: boolean;
|
|
17
|
+
command: string;
|
|
18
|
+
apiKey?: string;
|
|
19
|
+
baseUrl?: string;
|
|
20
|
+
model?: string;
|
|
21
|
+
maxTokens?: number;
|
|
22
|
+
}
|
|
23
|
+
export declare const TOOLKIT_CONFIGS: {
|
|
24
|
+
[x: string]: {
|
|
25
|
+
mcp: string;
|
|
26
|
+
rules: string;
|
|
27
|
+
config?: undefined;
|
|
28
|
+
} | {
|
|
29
|
+
config: string;
|
|
30
|
+
rules: string;
|
|
31
|
+
mcp?: undefined;
|
|
32
|
+
} | {
|
|
33
|
+
config: string;
|
|
34
|
+
mcp?: undefined;
|
|
35
|
+
rules?: undefined;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export declare function createConfigParser(): ConfigParser;
|
|
39
|
+
export declare class AIConfigManager {
|
|
40
|
+
private envLocalManager;
|
|
41
|
+
loadConfig(): Promise<AIConfig>;
|
|
42
|
+
isConfigured(): Promise<boolean>;
|
|
43
|
+
getAgentConfig(agent: string): Promise<AgentConfig | null>;
|
|
44
|
+
resetConfig(): Promise<void>;
|
|
45
|
+
checkToolkitConfig(agent: string): Promise<{
|
|
46
|
+
hasConfig: boolean;
|
|
47
|
+
hasMcp: boolean;
|
|
48
|
+
hasRules: boolean;
|
|
49
|
+
missingFiles: string[];
|
|
50
|
+
}>;
|
|
51
|
+
updateEnvId(envId: string): Promise<void>;
|
|
52
|
+
updateDefaultAgent(agent: string): Promise<void>;
|
|
53
|
+
updateClaudeConfig(type: 'custom' | 'cloudbase', config: {
|
|
54
|
+
baseUrl?: string;
|
|
55
|
+
apiKey?: string;
|
|
56
|
+
provider?: string;
|
|
57
|
+
model?: string;
|
|
58
|
+
transformer?: string;
|
|
59
|
+
}): Promise<void>;
|
|
60
|
+
updateQwenConfig(type: 'custom' | 'cloudbase', config: {
|
|
61
|
+
baseUrl?: string;
|
|
62
|
+
apiKey?: string;
|
|
63
|
+
provider?: string;
|
|
64
|
+
model?: string;
|
|
65
|
+
}): Promise<void>;
|
|
66
|
+
updateCodexConfig(type: 'custom' | 'cloudbase', config: {
|
|
67
|
+
baseUrl?: string;
|
|
68
|
+
apiKey?: string;
|
|
69
|
+
provider?: string;
|
|
70
|
+
model?: string;
|
|
71
|
+
}): Promise<void>;
|
|
72
|
+
updateAiderConfig(type: 'custom' | 'cloudbase', config: {
|
|
73
|
+
apiKey?: string;
|
|
74
|
+
baseUrl?: string;
|
|
75
|
+
model?: string;
|
|
76
|
+
provider?: string;
|
|
77
|
+
}): Promise<void>;
|
|
78
|
+
private updateConfig;
|
|
79
|
+
}
|