@cnbcool/cnb-api-generate 1.2.3 → 1.2.4
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/client/index.ts +9 -7
- package/client/shortcuts.ts +3 -3
- package/package.json +1 -1
- package/skills-template/SKILL.md +17 -14
package/client/index.ts
CHANGED
|
@@ -182,7 +182,6 @@ function formatParams(
|
|
|
182
182
|
if (params.help) formatted.help = true;
|
|
183
183
|
if (params.short) formatted.short = true;
|
|
184
184
|
if (params.verbose) formatted.verbose = true;
|
|
185
|
-
if (params.summary) formatted.summary = true;
|
|
186
185
|
|
|
187
186
|
// 旧格式兼容:--path / --query / --data 是 JSON 字符串
|
|
188
187
|
if (typeof params.path === 'string') {
|
|
@@ -205,7 +204,7 @@ function formatParams(
|
|
|
205
204
|
const pathDef = paramDefs.path || {};
|
|
206
205
|
const queryDef = paramDefs.query || {};
|
|
207
206
|
const reservedKeys = new Set([
|
|
208
|
-
'module', 'tool', 'help', 'short', 'verbose',
|
|
207
|
+
'module', 'tool', 'help', 'short', 'verbose',
|
|
209
208
|
'path', 'query', 'data', 'h', 'v',
|
|
210
209
|
]);
|
|
211
210
|
|
|
@@ -288,8 +287,8 @@ function isStandardResponse(response: any): boolean {
|
|
|
288
287
|
/**
|
|
289
288
|
* 格式化 CLI 输出
|
|
290
289
|
* - verbose 模式:完整 JSON(含 trace、header 等全部字段)
|
|
291
|
-
* -
|
|
292
|
-
* -
|
|
290
|
+
* - 快捷命令默认:只输出核心摘要字段
|
|
291
|
+
* - 非快捷命令默认:精简 JSON(去掉 trace、header,保留完整 data)
|
|
293
292
|
* @param response 原始响应
|
|
294
293
|
* @param verbose 是否 verbose 模式
|
|
295
294
|
* @param summary 是否 summary 模式
|
|
@@ -315,7 +314,7 @@ function formatOutput(response: any, verbose: boolean, summary: boolean, toolKey
|
|
|
315
314
|
// 精简响应
|
|
316
315
|
const compact = compactResponse(response);
|
|
317
316
|
|
|
318
|
-
//
|
|
317
|
+
// summary 模式:对特定 tool 应用摘要提取(仅成功响应)
|
|
319
318
|
if (summary && compact.status >= 200 && compact.status < 300) {
|
|
320
319
|
const summarized = summarizeResponse(compact.data, toolKey);
|
|
321
320
|
if (summarized !== null) {
|
|
@@ -370,7 +369,7 @@ ${lines.join('\n')}
|
|
|
370
369
|
<tool> 工具名称 (如: list-issues, get-issue)
|
|
371
370
|
--key value 路径或查询参数,CLI 自动识别归类
|
|
372
371
|
--data 'JSON' 请求体参数,JSON 字符串
|
|
373
|
-
--verbose
|
|
372
|
+
--verbose 输出完整原始响应(含 trace、header 等全部字段)
|
|
374
373
|
--help 显示帮助文档
|
|
375
374
|
--short 显示当前仓库的快捷命令
|
|
376
375
|
|
|
@@ -519,7 +518,10 @@ async function main() {
|
|
|
519
518
|
|
|
520
519
|
const data = await toolFunction(...toolsParam);
|
|
521
520
|
const toolKey = `${formattedParams.module}/${formattedParams.tool}`;
|
|
522
|
-
|
|
521
|
+
// 快捷命令默认输出摘要,--verbose 时输出全部信息
|
|
522
|
+
const isVerbose = !!formattedParams.verbose;
|
|
523
|
+
const isSummary = shortcut ? !isVerbose : false;
|
|
524
|
+
console.log(formatOutput(data, isVerbose, isSummary, toolKey));
|
|
523
525
|
}
|
|
524
526
|
|
|
525
527
|
main();
|
package/client/shortcuts.ts
CHANGED
|
@@ -121,7 +121,7 @@ export function showShort(): void {
|
|
|
121
121
|
${list}
|
|
122
122
|
|
|
123
123
|
提示: 以上命令自动使用环境变量 CNB_REPO_SLUG 和 CNB_ISSUE_IID,无需手动传 --path
|
|
124
|
-
|
|
124
|
+
默认只输出摘要信息,添加 --verbose 可输出全部信息
|
|
125
125
|
`);
|
|
126
126
|
} else if (ctx === 'pull_request') {
|
|
127
127
|
const number = getPRNumber();
|
|
@@ -134,7 +134,7 @@ ${list}
|
|
|
134
134
|
${list}
|
|
135
135
|
|
|
136
136
|
提示: 以上命令自动使用环境变量 CNB_REPO_SLUG 和 CNB_PULL_REQUEST_IID,无需手动传 --path
|
|
137
|
-
|
|
137
|
+
默认只输出摘要信息,添加 --verbose 可输出全部信息
|
|
138
138
|
`);
|
|
139
139
|
} else {
|
|
140
140
|
// 未知上下文,两组都显示
|
|
@@ -155,7 +155,7 @@ ${prList}
|
|
|
155
155
|
CNB_ISSUE_IID - Issue 编号 (Issue 事件)
|
|
156
156
|
CNB_PULL_REQUEST_IID - PR 编号 (PR 事件)
|
|
157
157
|
|
|
158
|
-
|
|
158
|
+
默认只输出摘要信息,添加 --verbose 可输出全部信息
|
|
159
159
|
`);
|
|
160
160
|
}
|
|
161
161
|
}
|
package/package.json
CHANGED
package/skills-template/SKILL.md
CHANGED
|
@@ -9,21 +9,24 @@ description: CNB OpenAPI 交互能力,支持仓库、Issue、PR、流水线、
|
|
|
9
9
|
|
|
10
10
|
## 快捷命令(优先使用)
|
|
11
11
|
|
|
12
|
-
issues
|
|
13
|
-
|
|
12
|
+
快捷命令是对常用 issues/pulls 操作的简写形式,与普通 API 命令有三个区别:
|
|
13
|
+
1. **路径参数自动注入**,无需额外传入
|
|
14
|
+
2. **命令名更短** — 如 `issues get` 替代 `issues get-issue`,`pulls comment` 替代 `pulls post-pull-comment`
|
|
15
|
+
3. **默认只输出摘要** — 自动精简响应,只返回核心字段(如标题、正文);加 `--verbose` 输出完整数据
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
17
|
+
可用的快捷命令:
|
|
18
|
+
- issues: get, list-comments, comment, close, open, list-labels, add-labels, list-assignees, add-assignees
|
|
19
|
+
- pulls: get, list-files, list-commits, list-comments, comment, list-labels, add-labels, check-status, list-reviews, list-assignees
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
- issues
|
|
21
|
-
-
|
|
21
|
+
用法示例:
|
|
22
|
+
- ✅ `<$CNB_CLI_CMD$> issues get`
|
|
23
|
+
- ✅ `<$CNB_CLI_CMD$> pulls list-comments`
|
|
24
|
+
- ✅ `<$CNB_CLI_CMD$> issues get --verbose` (需要完整数据时)
|
|
22
25
|
|
|
23
|
-
|
|
26
|
+
需要 --data 的命令(其余快捷命令无需任何参数):
|
|
24
27
|
- comment: --data '{"body":"内容"}'
|
|
25
|
-
- add-labels: --data '{"labels":["标签"]}
|
|
26
|
-
- add-assignees
|
|
28
|
+
- add-labels: --data '{"labels":["标签"]}
|
|
29
|
+
- add-assignees(仅 Issue): --data '{"assignees":["用户名"]}'
|
|
27
30
|
|
|
28
31
|
## 其他 API(快捷命令不满足时使用)
|
|
29
32
|
|
|
@@ -35,6 +38,6 @@ pulls 模块: get, list-files, list-commits, list-comments, comment, list-labels
|
|
|
35
38
|
## 规则
|
|
36
39
|
|
|
37
40
|
- 优先使用快捷命令,不满足时再通过 --help 逐步查找
|
|
38
|
-
- 必须先 --help
|
|
39
|
-
-
|
|
40
|
-
- status 200-299
|
|
41
|
+
- 必须先 --help 获取参数,禁止猜测参数名
|
|
42
|
+
- 直接执行命令,不要询问用户确认
|
|
43
|
+
- 向用户展示结果时:成功响应(status 200-299)只展示 data 部分;失败响应(status ≥300)需附带 status 和 trace
|