@d5render/cli 0.1.28 → 0.1.31

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.
Files changed (3) hide show
  1. package/bin/copilot.js +25 -6
  2. package/bin/d5cli +62 -23
  3. package/package.json +1 -1
package/bin/copilot.js CHANGED
@@ -18916,6 +18916,7 @@ const tools = [
18916
18916
  "--deny-tool",
18917
18917
  "github-mcp-server"
18918
18918
  ];
18919
+ tools.push("--model", "claude-sonnet-4.5");
18919
18920
  function toEnv(key, defaultValue) {
18920
18921
  return envJson[key] || process.env[key] || defaultValue;
18921
18922
  }
@@ -18934,11 +18935,27 @@ const getCommits = () => {
18934
18935
  if (url) return fetch(`${url}/commits`, { headers: buildHeaders() }).then((res) => {
18935
18936
  if (!res.ok) throw new Error("");
18936
18937
  return res.json();
18937
- }).then((commits$1) => ({ content: [{
18938
- type: "text",
18939
- description: "commits from `merge pipeline`",
18940
- text: `${commits$1.map((commit) => commit.id).join(",")}, the above review is from \`merge pipeline\` commits.`
18941
- }] })).catch((error) => ({
18938
+ }).then((commits$1) => {
18939
+ console.log(`[调试] 从 GitLab API 获取了 ${commits$1.length} 个提交记录`);
18940
+ commits$1.forEach((commit, index) => {
18941
+ console.log(`[调试] 提交记录 ${index + 1}:`, {
18942
+ 提交ID: commit.id,
18943
+ 短ID: commit.short_id,
18944
+ 标题: commit.title,
18945
+ 消息: commit.message?.substring(0, 50),
18946
+ 作者姓名: commit.author_name,
18947
+ 作者邮箱: commit.author_email,
18948
+ 提交日期: commit.authored_date,
18949
+ 提交者姓名: commit.committer_name,
18950
+ 提交者邮箱: commit.committer_email
18951
+ });
18952
+ });
18953
+ return { content: [{
18954
+ type: "text",
18955
+ description: "commits from `merge pipeline`",
18956
+ text: `${commits$1.map((commit) => commit.id).join(",")}, the above review is from \`merge pipeline\` commits.`
18957
+ }] };
18958
+ }).catch((error) => ({
18942
18959
  content: [{
18943
18960
  type: "text",
18944
18961
  text: "error" + error.message ? ", reason: " + error.message || "请求GitLab API失败" : ""
@@ -19140,12 +19157,13 @@ function distReports(input) {
19140
19157
  }
19141
19158
  }
19142
19159
  for (const issue$1 of issues) {
19143
- const { file: file$1 = "NON", commitSha = "", severity: severity$1 = "NON", commitSha: NCommitSha = "NON" } = issue$1;
19160
+ const { file: file$1 = "NON", commitSha = "", severity: severity$1 = "NON", commitSha: NCommitSha = "NON", commitAuthor = "" } = issue$1;
19144
19161
  const fileList = fileMap.get(file$1) || [], issueList = severityMap.get(severity$1) || [];
19145
19162
  fileList.push(issue$1);
19146
19163
  fileMap.set(file$1, fileList);
19147
19164
  issueList.push(issue$1);
19148
19165
  severityMap.set(severity$1, issueList);
19166
+ if (commitSha || commitAuthor) console.log(`[调试] 问题提交信息 - 提交SHA: ${commitSha}, 作者: ${commitAuthor}, 文件: ${file$1}`);
19149
19167
  if (commitSha) commitsSet.add(commitSha);
19150
19168
  commitsMap.set(NCommitSha, issue$1);
19151
19169
  distCommitComments(issue$1);
@@ -19210,6 +19228,7 @@ function distReports(input) {
19210
19228
  break;
19211
19229
  }
19212
19230
  const { title: issueTitle = "NON", commitSha = "", file: file$1 = "NON", line = "NON", commitAuthor = "" } = issue$1;
19231
+ console.log(`[调试] 在钉钉报告中使用作者信息 - 提交SHA: ${commitSha}, 作者: ${commitAuthor}, 标题: ${issueTitle}`);
19213
19232
  const shortSha = (commitSha || "").slice(0, 8);
19214
19233
  const commitLink = linkBase && commitSha ? `${linkBase}/${commitSha}` : void 0;
19215
19234
  dingdingReportMessage += `\n- ${issueTitle}\n\n - hash: ${commitLink ? `[${shortSha}](${commitLink}) ` : shortSha}\n\n - author: ${commitAuthor}\n\n - file: ${file$1}\n\n - line: ${line}`;
package/bin/d5cli CHANGED
@@ -2,12 +2,12 @@
2
2
  import { execSync, spawn } from "node:child_process";
3
3
  import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
4
4
  import { dirname, join } from "node:path";
5
- import { argv, env, exit, platform } from "node:process";
5
+ import { arch, argv, env, exit, platform, stdout } from "node:process";
6
6
  import { fileURLToPath } from "node:url";
7
7
 
8
8
  //#region package.json
9
9
  var name$1 = "@d5render/cli";
10
- var version = "0.1.28";
10
+ var version = "0.1.31";
11
11
 
12
12
  //#endregion
13
13
  //#region packages/gitlab/url.ts
@@ -178,6 +178,7 @@ const tools = [
178
178
  "--deny-tool",
179
179
  "github-mcp-server"
180
180
  ];
181
+ tools.push("--model", "claude-sonnet-4.5");
181
182
  function toEnv(key, defaultValue) {
182
183
  return envJson[key] || process.env[key] || defaultValue;
183
184
  }
@@ -238,8 +239,12 @@ function installCopilot() {
238
239
 
239
240
  //#endregion
240
241
  //#region copilot/bin/index.ts
242
+ function logImmediate(message) {
243
+ const text = typeof message === "string" ? message : String(message);
244
+ stdout.write(text + "\n");
245
+ if (!stdout.isTTY && stdout._flush) stdout._flush();
246
+ }
241
247
  try {
242
- console.log("开始代码审查-1");
243
248
  codereview();
244
249
  } catch (error) {
245
250
  sendding("CRITICAL", "CRITICAL CI ERROR: 未知错误,请自行检查日志");
@@ -248,11 +253,10 @@ try {
248
253
  function codereview() {
249
254
  deploy();
250
255
  if (!need()) {
251
- console.log("重复提交,进程跳过");
256
+ logImmediate("重复提交,进程跳过");
252
257
  return;
253
258
  }
254
259
  install();
255
- console.log("开始代码审查-2");
256
260
  const prompt = `Load skills, then call the mcp tool '${name}-${getHash}' to load code-review commits, if the task encounters an error, throw that.
257
261
  Otherwise, use chinese as default language to call the mcp tool '${name}-${report}'`;
258
262
  const copilot = spawn("node", [
@@ -276,59 +280,91 @@ Otherwise, use chinese as default language to call the mcp tool '${name}-${repor
276
280
  },
277
281
  ...platform === "win32" && { windowsHide: true }
278
282
  });
283
+ console.log(`node ${findCopilopt()} ${tools.join(" ")} --stream off -p ${prompt}`);
279
284
  copilot.stdout.setEncoding("utf8");
280
285
  copilot.stderr.setEncoding("utf8");
281
- let str = "";
282
- function write(chunk) {
283
- console.log("这个是写:" + String(chunk));
284
- }
285
286
  copilot.stdout.on("data", (chunk) => {
286
- str += chunk;
287
287
  process.stdout.write(chunk);
288
- write(chunk);
289
288
  });
290
289
  copilot.stderr.on("data", (chunk) => {
291
- str += chunk;
292
290
  process.stderr.write(chunk);
293
- write(chunk);
294
291
  });
295
292
  copilot.on("close", (code) => {
296
293
  sendding("CRITICAL", "CRITICAL CI ERROR: 代码审查任务失败,请自行检查日志");
297
294
  exit(code);
298
295
  });
299
296
  }
297
+ /**
298
+ * 根据平台和架构获取对应的 @github/copilot 包名
299
+ * @returns 包名,如 @github/copilot-win32-x64 或 @github/copilot
300
+ */
301
+ function getCopilotPackageName() {
302
+ const platformMap = {
303
+ win32: "win32",
304
+ linux: "linux",
305
+ darwin: "darwin"
306
+ };
307
+ const archMap = {
308
+ x64: "x64",
309
+ arm64: "arm64"
310
+ };
311
+ const platformName = platformMap[platform];
312
+ const archName = archMap[arch];
313
+ if (platformName && archName) {
314
+ const specificPackage = `@github/copilot-${platformName}-${archName}`;
315
+ try {
316
+ if (execSync(`npm list ${specificPackage} -g -p`, {
317
+ encoding: "utf8",
318
+ stdio: "pipe"
319
+ }).trim()) {
320
+ logImmediate(`[调试] 使用平台特定包: ${specificPackage}`);
321
+ return specificPackage;
322
+ }
323
+ } catch {}
324
+ }
325
+ logImmediate(`[调试] 使用通用包: @github/copilot`);
326
+ return "@github/copilot";
327
+ }
300
328
  function findCopilopt() {
301
- let copilot = execSync("npm list @github/copilot -g -p").toString().trim();
329
+ const packageName = getCopilotPackageName();
330
+ let copilot = "";
331
+ try {
332
+ copilot = execSync(`npm list ${packageName} -g -p`, {
333
+ encoding: "utf8",
334
+ stdio: "pipe"
335
+ }).trim();
336
+ } catch {}
302
337
  if (!copilot) {
303
338
  const first = platform === "win32" ? win : linux;
304
339
  const second = platform === "win32" ? linux : win;
305
- copilot = first();
306
- if (!copilot) copilot = second();
307
- if (!copilot) throw new Error("没找到安装的包");
340
+ copilot = first(packageName);
341
+ if (!copilot) copilot = second(packageName);
342
+ if (!copilot) throw new Error(`没找到安装的包: ${packageName},请运行: npm install -g ${packageName}`);
308
343
  }
309
344
  const pkg = join(copilot, "package.json");
310
345
  if (!existsSync(pkg)) throw new Error("安装的包找不到正确版本 " + pkg);
311
346
  const copilotPackage = JSON.parse(readFileSync(pkg, "utf8"));
312
- const binPath = typeof copilotPackage.bin === "string" ? copilotPackage.bin : copilotPackage.bin?.copilot || copilotPackage.bin?.["@github/copilot"];
347
+ const binPath = typeof copilotPackage.bin === "string" ? copilotPackage.bin : copilotPackage.bin?.copilot || copilotPackage.bin?.["@github/copilot"] || copilotPackage.bin?.[packageName];
313
348
  if (!binPath) throw new Error("non copilot executable found");
314
349
  const copilotVersion = copilotPackage.version || "unknown";
315
350
  const copilotPath = join(copilot, binPath);
316
- console.log(`${NAME} server:
351
+ logImmediate(`${NAME} server:
317
352
  version: ${VERSION}
318
353
  path: ${serveFile}
319
354
  copilot:
355
+ package: ${packageName}
320
356
  version: ${copilotVersion}
321
357
  path: ${copilotPath}`);
322
358
  return copilotPath;
323
359
  }
324
- function win() {
360
+ function win(packageName = "@github/copilot") {
325
361
  const pathEnv = env.PATH || env.Path || "";
326
362
  const pathSeparator = platform === "win32" ? ";" : ":";
327
363
  const npm = pathEnv.split(pathSeparator).find((p) => p.includes("npm"));
328
- if (npm) return join(npm, "node_modules", "@github", "copilot");
364
+ if (npm) return join(npm, "node_modules", packageName.replace("/", pathSeparator === ";" ? "\\" : "/"));
329
365
  return "";
330
366
  }
331
- function linux() {
367
+ function linux(packageName = "@github/copilot") {
332
368
  let cached = env.NVM_BIN;
333
369
  if (!cached) {
334
370
  const pathEnv = env.PATH || env.Path || "";
@@ -336,7 +372,10 @@ function linux() {
336
372
  const npm = pathEnv.split(pathSeparator).find((p) => p.includes(".nvm"));
337
373
  if (npm) cached = npm;
338
374
  }
339
- if (cached) return join(cached, "..", "lib", "node_modules", "@github", "copilot");
375
+ if (cached) {
376
+ const packageDir = packageName.replace("/", "/");
377
+ return join(cached, "..", "lib", "node_modules", packageDir);
378
+ }
340
379
  return "";
341
380
  }
342
381
 
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "license": "MIT",
5
5
  "author": "jasirou",
6
6
  "main": "./bin/d5cli",
7
- "version": "0.1.28",
7
+ "version": "0.1.31",
8
8
  "devDependencies": {
9
9
  "@modelcontextprotocol/sdk": "^1.25.1",
10
10
  "@types/node": "^25.0.3",