@cnbcool/cnb-cli 1.0.7 → 1.0.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cnbcool/cnb-cli",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "CNB OpenAPI 命令行工具,基于 CNB 平台 Swagger 自动生成,支持 Issues、PR、Git、组织管理等全部 API 操作",
5
5
  "main": "skills/cnb-api/scripts/core/index.js",
6
6
  "bin": {
@@ -34,7 +34,7 @@
34
34
  "author": "",
35
35
  "license": "MIT",
36
36
  "devDependencies": {
37
- "@cnbcool/cnb-api-generate": "^1.2.3",
37
+ "@cnbcool/cnb-api-generate": "^1.2.4",
38
38
  "skills": "^1.4.4"
39
39
  }
40
40
  }
@@ -169,7 +169,6 @@ function formatParams(params) {
169
169
  if (params.help) formatted.help = true;
170
170
  if (params.short) formatted.short = true;
171
171
  if (params.verbose) formatted.verbose = true;
172
- if (params.summary) formatted.summary = true;
173
172
 
174
173
  // 旧格式兼容:--path / --query / --data 是 JSON 字符串
175
174
  if (typeof params.path === 'string') {
@@ -187,7 +186,7 @@ function formatParams(params) {
187
186
  if (paramDefs) {
188
187
  const pathDef = paramDefs.path || {};
189
188
  const queryDef = paramDefs.query || {};
190
- const reservedKeys = new Set(['module', 'tool', 'help', 'short', 'verbose', 'summary', 'path', 'query', 'data', 'h', 'v']);
189
+ const reservedKeys = new Set(['module', 'tool', 'help', 'short', 'verbose', 'path', 'query', 'data', 'h', 'v']);
191
190
  for (const [key, value] of Object.entries(params)) {
192
191
  if (reservedKeys.has(key)) continue;
193
192
  if (typeof value === 'boolean') continue;
@@ -262,8 +261,8 @@ function isStandardResponse(response) {
262
261
  /**
263
262
  * 格式化 CLI 输出
264
263
  * - verbose 模式:完整 JSON(含 trace、header 等全部字段)
265
- * - summary 模式:只输出核心摘要字段(需要 --summary 显式指定)
266
- * - 默认:精简 JSON(去掉 trace、header,保留完整 data)
264
+ * - 快捷命令默认:只输出核心摘要字段
265
+ * - 非快捷命令默认:精简 JSON(去掉 trace、header,保留完整 data)
267
266
  * @param response 原始响应
268
267
  * @param verbose 是否 verbose 模式
269
268
  * @param summary 是否 summary 模式
@@ -289,7 +288,7 @@ function formatOutput(response, verbose, summary, toolKey) {
289
288
  // 精简响应
290
289
  const compact = compactResponse(response);
291
290
 
292
- // --summary 模式:对特定 tool 应用摘要提取(仅成功响应)
291
+ // summary 模式:对特定 tool 应用摘要提取(仅成功响应)
293
292
  if (summary && compact.status >= 200 && compact.status < 300) {
294
293
  const summarized = (0, _shortcuts.summarizeResponse)(compact.data, toolKey);
295
294
  if (summarized !== null) {
@@ -342,7 +341,7 @@ ${lines.join('\n')}
342
341
  <tool> 工具名称 (如: list-issues, get-issue)
343
342
  --key value 路径或查询参数,CLI 自动识别归类
344
343
  --data 'JSON' 请求体参数,JSON 字符串
345
- --verbose 输出完整响应(含 trace、header
344
+ --verbose 输出完整原始响应(含 trace、header 等全部字段)
346
345
  --help 显示帮助文档
347
346
  --short 显示当前仓库的快捷命令
348
347
 
@@ -458,6 +457,9 @@ async function main() {
458
457
  }
459
458
  const data = await toolFunction(...toolsParam);
460
459
  const toolKey = `${formattedParams.module}/${formattedParams.tool}`;
461
- console.log(formatOutput(data, !!formattedParams.verbose, !!formattedParams.summary, toolKey));
460
+ // 快捷命令默认输出摘要,--verbose 时输出全部信息
461
+ const isVerbose = !!formattedParams.verbose;
462
+ const isSummary = shortcut ? !isVerbose : false;
463
+ console.log(formatOutput(data, isVerbose, isSummary, toolKey));
462
464
  }
463
465
  main();
@@ -161,7 +161,7 @@ function showShort() {
161
161
  ${list}
162
162
 
163
163
  提示: 以上命令自动使用环境变量 CNB_REPO_SLUG 和 CNB_ISSUE_IID,无需手动传 --path
164
- 添加 --summary 可只输出核心摘要字段
164
+ 默认只输出摘要信息,添加 --verbose 可输出全部信息
165
165
  `);
166
166
  } else if (ctx === 'pull_request') {
167
167
  const number = getPRNumber();
@@ -174,7 +174,7 @@ ${list}
174
174
  ${list}
175
175
 
176
176
  提示: 以上命令自动使用环境变量 CNB_REPO_SLUG 和 CNB_PULL_REQUEST_IID,无需手动传 --path
177
- 添加 --summary 可只输出核心摘要字段
177
+ 默认只输出摘要信息,添加 --verbose 可输出全部信息
178
178
  `);
179
179
  } else {
180
180
  // 未知上下文,两组都显示
@@ -195,7 +195,7 @@ ${prList}
195
195
  CNB_ISSUE_IID - Issue 编号 (Issue 事件)
196
196
  CNB_PULL_REQUEST_IID - PR 编号 (PR 事件)
197
197
 
198
- 添加 --summary 可只输出核心摘要字段
198
+ 默认只输出摘要信息,添加 --verbose 可输出全部信息
199
199
  `);
200
200
  }
201
201
  }
@@ -1,140 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = convertLink;
7
- /**
8
- * 把文本里的相对路径转换为绝对路径
9
- * 与 codebuddy/skills/cnb-text-relative-path-converter/scripts/convertLink.js 逻辑一致
10
- *
11
- * @param {String} text 待转换的文本
12
- * @param {String} repoSlug 仓库路径
13
- * @param {String} branchOrSha 可选,分支或SHA
14
- * @returns {String}
15
- */
16
- function convertLink(text, repoSlug, branchOrSha) {
17
- // 查询所有代码块的位置
18
- let codeBlockPositions = [];
19
- let index = 0;
20
- while (index !== -1) {
21
- const nextIndex = text.indexOf('```', index);
22
- if (nextIndex === -1) break;
23
- codeBlockPositions.push(nextIndex);
24
- index = nextIndex + 3; // 跳过已匹配的三个反引号
25
- }
26
- if (codeBlockPositions.length % 2 !== 0) {
27
- codeBlockPositions = codeBlockPositions.slice(0, codeBlockPositions.length - 1);
28
- }
29
-
30
- // 查询所有行内代码块的位置
31
- let inlineCodeBlockPositions = [];
32
- index = 0;
33
- while (index < text.length) {
34
- const nextIndex = text.indexOf('`', index);
35
- if (nextIndex === -1) break;
36
- // 检查是否是单独的反引号(不是代码块的一部分)
37
- if ((nextIndex === 0 || text.charAt(nextIndex - 1) !== '`') && (nextIndex === text.length - 1 || text.charAt(nextIndex + 1) !== '`')) {
38
- inlineCodeBlockPositions.push(nextIndex);
39
- }
40
- index = nextIndex + 1;
41
- }
42
- if (inlineCodeBlockPositions.length % 2 !== 0) {
43
- inlineCodeBlockPositions = inlineCodeBlockPositions.slice(0, inlineCodeBlockPositions.length - 1);
44
- }
45
-
46
- // 整理起始和结束位置
47
- const excludedRanges = [...codeBlockPositions, ...inlineCodeBlockPositions].reduce((result, item, index) => {
48
- if (index % 2 === 0) {
49
- return result.concat([[item]]);
50
- }
51
- result[result.length - 1].push(item);
52
- return result;
53
- }, []);
54
-
55
- // Helper function to check if an index is within excluded ranges
56
- const isInExcludedRange = index => {
57
- return excludedRanges.some(([start, end]) => index >= start && index < end);
58
- };
59
- let match;
60
-
61
- // Collect all replacements with their positions
62
- const replacements = [];
63
-
64
- // Match markdown links and images: [text](url) and ![alt](url)
65
- const markdownLinkRegex = /!?\[([^\]]+)\]\(([^)]+)\)/g;
66
- while ((match = markdownLinkRegex.exec(text)) !== null) {
67
- if (!isInExcludedRange(match.index)) {
68
- // Calculate URL position: match.index + length of "![" + match[1] + "]("
69
- const prefixLength = (match[0].startsWith('!') ? 1 : 0) + 1 + match[1].length + 2;
70
- const urlStart = match.index + prefixLength;
71
- const urlEnd = urlStart + match[2].length;
72
- const newUrl = normaliseLink(match[2], repoSlug, branchOrSha);
73
- if (newUrl !== match[2]) {
74
- replacements.push({
75
- start: urlStart,
76
- end: urlEnd,
77
- newUrl
78
- });
79
- }
80
- }
81
- }
82
-
83
- // Match HTML tags: <img src="..."> and <a href="...">
84
- const htmlTagRegex = /\s(src|href)=["']([^"']+)["']/gi;
85
- while ((match = htmlTagRegex.exec(text)) !== null) {
86
- if (!isInExcludedRange(match.index)) {
87
- const urlStart = match.index + match[0].indexOf(match[2]);
88
- const urlEnd = urlStart + match[2].length;
89
- const newUrl = normaliseLink(match[2], repoSlug, branchOrSha);
90
- if (newUrl !== match[2]) {
91
- replacements.push({
92
- start: urlStart,
93
- end: urlEnd,
94
- newUrl
95
- });
96
- }
97
- }
98
- }
99
-
100
- // Sort replacements by start position in descending order
101
- replacements.sort((a, b) => b.start - a.start);
102
-
103
- // Apply replacements from end to start to maintain correct indices
104
- let result = text;
105
- for (const {
106
- start,
107
- end,
108
- newUrl
109
- } of replacements) {
110
- result = result.substring(0, start) + newUrl + result.substring(end);
111
- }
112
- return result;
113
- }
114
-
115
- /**
116
- * 相对路径转换为绝对路径
117
- * 与 codebuddy/skills/text-path-converter/scripts/convertLink.js 逻辑一致
118
- *
119
- * @param {String} link 待转换的链接
120
- * @param {String} repoSlug 仓库路径
121
- * @param {String} branchOrSha 分支或SHA,默认为 HEAD
122
- * @returns {String}
123
- */
124
- function normaliseLink(link, repoSlug, branchOrSha = 'HEAD') {
125
- const baseURL = `${process.env.CNB_WEB_ENDPOINT}/${repoSlug}`;
126
- if (link.startsWith('/-/')) {
127
- return `${baseURL}${link}`;
128
- }
129
- if (link.indexOf('/-/') === -1 && (link.startsWith('../') || link.startsWith('./') || link.startsWith('/') && !link.startsWith('//'))) {
130
- let chunks = link.split('/');
131
- // 过滤掉空字符串和 . .. 这些无效路径
132
- chunks = chunks.filter(chunk => !!chunk && chunk !== '.' && chunk !== '..');
133
- if (chunks.length === 0) {
134
- return link;
135
- }
136
- chunks.unshift(branchOrSha);
137
- return `${baseURL}/-/git/raw/${chunks.join('/')}`;
138
- }
139
- return link;
140
- }
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
-
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
@@ -1,70 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = _default;
7
- var _core = _interopRequireDefault(require("../../core/core.js"));
8
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
- // @ts-nocheck
10
- /* tslint:disable */
11
- /* eslint-disable */
12
- /*
13
- * -------------------------------------------------------------------------
14
- * ## THIS FILE WAS GENERATED VIA CNB-API-GENERATE ##
15
- * ## ##
16
- * ## AUTHOR: bapelin ##
17
- * ## SOURCE: https://cnb.cool/cnb/frontend-science/cnb-api-generate ##
18
- * -------------------------------------------------------------------------
19
- * @Version 1.2.1
20
- * @Source /{repo}/-/build/ai/auto-pr
21
- */
22
-
23
- /**
24
- * @description Other reuqest params
25
- */
26
-
27
- /**
28
- * @description AiAutoPrRes Success Response Type
29
- */
30
-
31
- /**
32
- * @description AiAutoPrError Error Response Type
33
- */
34
-
35
- /**
36
- * @description 访问令牌调用此接口需包含以下权限。Required permissions for access token.
37
- * repo-code:rw
38
- * @tags AI
39
- * @name aiAutoPr
40
- * @summary 根据传入的需求内容和需求标题借助 AI 自动编码并提 PR。Automatically code and create a PR with AI based on the input requirement content and title.
41
- * @request post:/{repo}/-/build/ai/auto-pr
42
-
43
- ----------------------------------
44
- * @param {string} arg0
45
- * @param {DtoAiAutoPrReq} arg1
46
- * @param {RequestConfig} arg2 - Other reuqest params
47
- */
48
- async function _default(repo, request, {
49
- req,
50
- options,
51
- ...axiosConfig
52
- } = {}) {
53
- return await _core.default.request({
54
- ...axiosConfig,
55
- _next_req: req,
56
- options: options,
57
- url: `/${repo}/-/build/ai/auto-pr`,
58
- _apiTag: "/{repo}/-/build/ai/auto-pr",
59
- method: "post",
60
- data: request,
61
- _originParams: {
62
- method: "post",
63
- _apiTag: "/{repo}/-/build/ai/auto-pr",
64
- path: {
65
- repo
66
- },
67
- body: request
68
- }
69
- });
70
- }
@@ -1,75 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = _default;
7
- var _core = _interopRequireDefault(require("../../core/core.js"));
8
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
- // @ts-nocheck
10
- /* tslint:disable */
11
- /* eslint-disable */
12
- /*
13
- * -------------------------------------------------------------------------
14
- * ## THIS FILE WAS GENERATED VIA CNB-API-GENERATE ##
15
- * ## ##
16
- * ## AUTHOR: bapelin ##
17
- * ## SOURCE: https://cnb.woa.com/cnb/frontend-science/cnb-api-generate ##
18
- * -------------------------------------------------------------------------
19
- * @Version 2.2.0
20
- * @Source /{repo}/-/files/{filePath}
21
- */
22
-
23
- /**
24
- * @description getFiles request params
25
- */
26
-
27
- /**
28
- * @description Other reuqest params
29
- */
30
-
31
- /**
32
- * @description GetFilesRes Success Response Type
33
- */
34
-
35
- /**
36
- * @description GetFilesError Error Response Type
37
- */
38
-
39
- /**
40
- * @description 访问令牌调用此接口需包含以下权限。Required permissions for access token.
41
- * repo-contents:r
42
- * @tags Pulls,Issues
43
- * @name getFiles
44
- * @summary 获取 issue 文件或合并请求文件的请求,返回文件二进制内容。Request to retrieve file of issues and pull requests, returns binary content.
45
- * @request get:/{repo}/-/files/{filePath}
46
-
47
- ----------------------------------
48
- * @param {GetFilesParams} arg0 - getFiles request params
49
- * @param {RequestConfig} arg1 - Other reuqest params
50
- */
51
- async function _default({
52
- repo,
53
- filePath
54
- }, {
55
- req,
56
- options,
57
- ...axiosConfig
58
- } = {}) {
59
- return await _core.default.request({
60
- ...axiosConfig,
61
- _next_req: req,
62
- options: options,
63
- url: `/${repo}/-/files/${filePath}`,
64
- _apiTag: "/{repo}/-/files/{filePath}",
65
- method: "get",
66
- _originParams: {
67
- method: "get",
68
- _apiTag: "/{repo}/-/files/{filePath}",
69
- path: {
70
- repo,
71
- filePath
72
- }
73
- }
74
- });
75
- }
@@ -1,75 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = _default;
7
- var _core = _interopRequireDefault(require("../../core/core.js"));
8
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
- // @ts-nocheck
10
- /* tslint:disable */
11
- /* eslint-disable */
12
- /*
13
- * -------------------------------------------------------------------------
14
- * ## THIS FILE WAS GENERATED VIA CNB-API-GENERATE ##
15
- * ## ##
16
- * ## AUTHOR: bapelin ##
17
- * ## SOURCE: https://cnb.woa.com/cnb/frontend-science/cnb-api-generate ##
18
- * -------------------------------------------------------------------------
19
- * @Version 2.2.0
20
- * @Source /{repo}/-/imgs/{imgPath}
21
- */
22
-
23
- /**
24
- * @description getImgs request params
25
- */
26
-
27
- /**
28
- * @description Other reuqest params
29
- */
30
-
31
- /**
32
- * @description GetImgsRes Success Response Type
33
- */
34
-
35
- /**
36
- * @description GetImgsError Error Response Type
37
- */
38
-
39
- /**
40
- * @description 访问令牌调用此接口需包含以下权限。Required permissions for access token.
41
- * repo-contents:r
42
- * @tags Pulls,Issues
43
- * @name getImgs
44
- * @summary 获取 issue 图片或合并请求图片的请求,返回图片二进制内容。Request to retrieve image of issues and pull requests, returns binary content.
45
- * @request get:/{repo}/-/imgs/{imgPath}
46
-
47
- ----------------------------------
48
- * @param {GetImgsParams} arg0 - getImgs request params
49
- * @param {RequestConfig} arg1 - Other reuqest params
50
- */
51
- async function _default({
52
- repo,
53
- imgPath
54
- }, {
55
- req,
56
- options,
57
- ...axiosConfig
58
- } = {}) {
59
- return await _core.default.request({
60
- ...axiosConfig,
61
- _next_req: req,
62
- options: options,
63
- url: `/${repo}/-/imgs/${imgPath}`,
64
- _apiTag: "/{repo}/-/imgs/{imgPath}",
65
- method: "get",
66
- _originParams: {
67
- method: "get",
68
- _apiTag: "/{repo}/-/imgs/{imgPath}",
69
- path: {
70
- repo,
71
- imgPath
72
- }
73
- }
74
- });
75
- }