@cnbcool/cnb-cli 1.20.7 → 1.21.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.
- package/README.en.md +20 -0
- package/README.md +88 -0
- package/dist/index.js +303 -184
- package/package.json +4 -2
package/README.en.md
CHANGED
|
@@ -57,6 +57,26 @@ npm install skills -g
|
|
|
57
57
|
npx skills add https://cnb.cool/cnb/skills/cnb-skill.git --agent codebuddy -y --copy
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
+
## MCP Setup
|
|
61
|
+
|
|
62
|
+
Instead of installing skills and the cli locally, configure a single MCP server; the Agent logs in and runs cnb commands through MCP tools:
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
{
|
|
66
|
+
"mcpServers": {
|
|
67
|
+
"cnb": { "command": "npx", "args": ["-y", "@cnbcool/cnb-cli@latest", "mcp"] }
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The platform and repo are inferred from the `cwd` git remote (`cnb_run`, `cnb_status` and `cnb_login` all accept a `cwd` argument), so a workspace with a CNB remote needs no extra config. For other deployments (e.g. intranet) you can pin the platform by appending `"--host", "<platform host>"` to `args`.
|
|
73
|
+
|
|
74
|
+
The cli usage conventions ship inside the MCP instructions and tool descriptions, always matching the cli version. Tools:
|
|
75
|
+
|
|
76
|
+
- `cnb_run` — run a cnb command; arguments are passed as an array without a shell; pass `cwd` to infer the repo from a workspace
|
|
77
|
+
- `cnb_login` — OAuth2 device authorization, returns an auth link; the token is shared with `cnb login` in `~/.cnb/token`
|
|
78
|
+
- `cnb_status` / `cnb_logout` — check or clear the login
|
|
79
|
+
|
|
60
80
|
## Environment Variables
|
|
61
81
|
|
|
62
82
|
**Required**
|
package/README.md
CHANGED
|
@@ -57,6 +57,94 @@ npm install skills -g
|
|
|
57
57
|
npx skills add https://cnb.cool/cnb/skills/cnb-skill.git --agent codebuddy -y --copy
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
+
## MCP 接入
|
|
61
|
+
|
|
62
|
+
不想在本地装 skills 和 cli,可以只配一个 MCP server:Agent 通过 MCP 工具登录、执行任意 `cnb` 命令。
|
|
63
|
+
|
|
64
|
+
cli 的用法约定(常用命令、参数、输出约定)随包内置在 MCP 的 instructions 和工具描述里,与 cli 版本一致;平台和仓库按工作区自动推断,无需再手写。
|
|
65
|
+
|
|
66
|
+
### 配置
|
|
67
|
+
|
|
68
|
+
在各客户端的 MCP 配置里加一项(CodeBuddy 在 Settings → MCP,对应 `~/.codebuddy/mcp.json`;Claude Desktop 在 `claude_desktop_config.json`):
|
|
69
|
+
|
|
70
|
+
```json
|
|
71
|
+
{
|
|
72
|
+
"mcpServers": {
|
|
73
|
+
"cnb": {
|
|
74
|
+
"type": "stdio",
|
|
75
|
+
"command": "npx",
|
|
76
|
+
"args": ["-y", "@cnbcool/cnb-cli@latest", "mcp"]
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
- **版本**:`@latest` 每次启动拉最新发布版;需要固定大版本时改成 `@1`
|
|
83
|
+
- **内网 / 私有化部署**:在 `args` 末尾加 `"--host", "<平台域名>"`(如 `"cnb.woa.com"`)。工作区有 CNB 远端时可省略,由 git remote 推断
|
|
84
|
+
- **本地开发本仓库**:把启动命令换成本地的 node + `bin/cnb.js`,改动后需先 `npm run build`
|
|
85
|
+
|
|
86
|
+
```json
|
|
87
|
+
{
|
|
88
|
+
"mcpServers": {
|
|
89
|
+
"cnb": {
|
|
90
|
+
"type": "stdio",
|
|
91
|
+
"command": "/absolute/path/to/node",
|
|
92
|
+
"args": ["/absolute/path/to/cnb-skill/bin/cnb.js", "mcp"]
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 提供的工具
|
|
99
|
+
|
|
100
|
+
| 工具 | 作用 | 参数 |
|
|
101
|
+
| --- | --- | --- |
|
|
102
|
+
| `cnb_run` | 执行任意 `cnb` 命令,覆盖 Issues / PR / 仓库 / 构建 / 制品库等全部 OpenAPI 操作 | `args`:`cnb` 之后的参数数组;`cwd`:工作区绝对路径 |
|
|
103
|
+
| `cnb_status` | 查看登录状态,过期时自动用 refresh_token 刷新 | `cwd` |
|
|
104
|
+
| `cnb_login` | OAuth2 设备授权登录,返回授权链接,token 写入 `~/.cnb/token` | `cwd` |
|
|
105
|
+
| `cnb_logout` | 退出登录,删除本机对应平台的登录态 | `cwd` |
|
|
106
|
+
|
|
107
|
+
`cnb_run` 的 `args` 按数组原样传给 cli、不经过 shell:多行正文直接作为一个元素传入(如 `["issues","comment","--number","12","--body","第一行\n第二行"]`),无需引号或转义。`login`、`mcp` 两个子命令被拦截,登录请用 `cnb_login`。
|
|
108
|
+
|
|
109
|
+
### 自动推断
|
|
110
|
+
|
|
111
|
+
- **平台**:启动参数 `--host` → `cwd` 的 git remote → `CNB_API_ENDPOINT` → `cnb.cool`。推断出的平台同时决定 API 域名和读取哪份登录态
|
|
112
|
+
- **仓库**:未传 `--repo` 时按 `cwd` 的 git remote 推断(`https://`、`ssh://`、`git@host:org/repo.git` 都支持);跨仓库操作、或 `cwd` 不在 git 仓库里时才需显式传
|
|
113
|
+
- **优先级**:显式传入的 `--repo` 永远优先于推断值
|
|
114
|
+
|
|
115
|
+
### 典型流程
|
|
116
|
+
|
|
117
|
+
1. `cnb_status`(传 `cwd`)检查登录;未登录调 `cnb_login`,把返回的链接发给用户,用户授权后再查一次
|
|
118
|
+
2. 用 `cnb_run` 执行任务,无需每条命令都填仓库:
|
|
119
|
+
|
|
120
|
+
```json
|
|
121
|
+
{ "args": ["issues", "list-issues", "--state", "open", "--page-size", "5"], "cwd": "/path/to/repo" }
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
3. 遇到速查里没有的命令,先让 Agent 调 `["<module>","--help"]` 查参数
|
|
125
|
+
|
|
126
|
+
### 与 Skills 的关系
|
|
127
|
+
|
|
128
|
+
MCP 覆盖 cli 的全部命令能力,相当于「cnb-api skill + cli」,不需要再安装 skills。
|
|
129
|
+
|
|
130
|
+
但 `cnb-code-review`、`cnb-code-commit`、`cnb-pipeline` 等 skill 的价值在流程知识(评审标准、提交规范、`.cnb.yml` 语法),cli 里没有这部分。需要这些能力时,仍按上文安装对应 skills,或让 Agent 直接读取仓库里的 `SKILL.md`。
|
|
131
|
+
|
|
132
|
+
### 认证与安全
|
|
133
|
+
|
|
134
|
+
- token 存在 `~/.cnb/token`(权限 `600`),与 `cnb login` 共用一份,MCP 拿到的授权也写在这里
|
|
135
|
+
- `cnb_login` 走设备码流程,不接触密码;授权链接有效期约 10 分钟,期间在浏览器确认即可
|
|
136
|
+
- 客户端支持 URL elicitation 时会直接弹出授权链接,不支持的客户端返回链接文本
|
|
137
|
+
|
|
138
|
+
### 常见问题
|
|
139
|
+
|
|
140
|
+
| 现象 | 处理 |
|
|
141
|
+
| --- | --- |
|
|
142
|
+
| `cnb_status` 显示未登录 | 调 `cnb_login`,浏览器确认后再调 `cnb_status` |
|
|
143
|
+
| 报「不是 git 仓库,无法推断仓库」 | `cwd` 不在 git 仓库或没有 remote:显式传 `--repo 组织/仓库`,或把 `cwd` 指向工作区 |
|
|
144
|
+
| 命令打到了错误平台 | 检查 `cwd` 的 git remote;或在配置里加 `"--host", "<平台域名>"` 锁定 |
|
|
145
|
+
| 参数报 `unknown option` | cli 会提示正确写法(如 `--page-size`)并附完整帮助,照提示改即可 |
|
|
146
|
+
| 输出被截断 | 单次输出超过 100KB 会截断,去掉 `--verbose` 或改用分页查询 |
|
|
147
|
+
|
|
60
148
|
## 环境变量
|
|
61
149
|
|
|
62
150
|
**必填**
|