@d5render/cli 0.1.38 → 0.1.40

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 (2) hide show
  1. package/bin/d5cli +86 -142
  2. package/package.json +1 -1
package/bin/d5cli CHANGED
@@ -2,16 +2,11 @@
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 { arch, argv, env, exit, platform, stdout } from "node:process";
5
+ import { argv, env, exit, platform } from "node:process";
6
6
  import { fileURLToPath } from "node:url";
7
7
 
8
- //#region package.json
9
- var name$1 = "@d5render/cli";
10
- var version = "0.1.38";
11
-
12
- //#endregion
13
8
  //#region copilot/server/config.ts
14
- const name = "d5_mcp_review_builtin";
9
+ const name$1 = "d5_mcp_review_builtin";
15
10
  const report = "report";
16
11
  const getHash = "hash";
17
12
  const file = "bin/copilot.js";
@@ -39,7 +34,7 @@ const envUsed = {
39
34
  };
40
35
  const tools = [
41
36
  "--additional-mcp-config",
42
- JSON.stringify({ mcpServers: { [name]: {
37
+ JSON.stringify({ mcpServers: { [name$1]: {
43
38
  type: "local",
44
39
  command: "node",
45
40
  args: [serveFile, `--customizenv=${JSON.stringify(envUsed)}`],
@@ -63,6 +58,59 @@ function buildEnv() {
63
58
  return envJson$1;
64
59
  }
65
60
 
61
+ //#endregion
62
+ //#region copilot/bin/install.ts
63
+ function install() {
64
+ if (!env.CI) return;
65
+ console.log("install copilot...");
66
+ let success = false;
67
+ let local = "";
68
+ try {
69
+ local = execSync("npm list @github/copilot -g --depth=0 --json").toString();
70
+ } catch {
71
+ local = "{}";
72
+ }
73
+ try {
74
+ const localInfo = JSON.parse(local);
75
+ const localVersion = localInfo.dependencies ? localInfo.dependencies?.["@github/copilot"]?.version : void 0;
76
+ if (!localVersion) {
77
+ installCopilot();
78
+ success = true;
79
+ console.log("install copilot success");
80
+ return;
81
+ }
82
+ if (localVersion !== execSync("npm view @github/copilot version --registry=https://registry.npmmirror.com").toString().trim()) {
83
+ execSync("npm uninstall -g @github/copilot --force");
84
+ installCopilot();
85
+ success = true;
86
+ console.log("update copilot success");
87
+ } else {
88
+ success = true;
89
+ console.log("copilot exists and is up-to-date");
90
+ }
91
+ } catch (error) {
92
+ console.error(error);
93
+ }
94
+ if (!success) try {
95
+ console.warn("try to reinstall copilot...");
96
+ installCopilot();
97
+ success = true;
98
+ } catch (error) {
99
+ console.error(error);
100
+ }
101
+ if (success) return;
102
+ console.warn("try to reinstall copilot...");
103
+ installCopilot();
104
+ }
105
+ function installCopilot() {
106
+ execSync("npm install -g @github/copilot --registry=https://registry.npmmirror.com", { stdio: "inherit" });
107
+ }
108
+
109
+ //#endregion
110
+ //#region package.json
111
+ var name = "@d5render/cli";
112
+ var version = "0.1.40";
113
+
66
114
  //#endregion
67
115
  //#region packages/gitlab/url.ts
68
116
  function buildHeaders() {
@@ -120,7 +168,7 @@ async function sendding(title, text) {
120
168
 
121
169
  //#endregion
122
170
  //#region copilot/bin/utils.ts
123
- const NAME = name$1.replaceAll("/", "_");
171
+ const NAME = name.replaceAll("/", "_");
124
172
  const VERSION = version;
125
173
  const HOME = env.USERPROFILE ?? env.HOME ?? env.HOMEPATH;
126
174
  if (!HOME) throw new Error("cannot find `USERPROFILE` directory");
@@ -197,61 +245,8 @@ async function need() {
197
245
  return !yes;
198
246
  }
199
247
 
200
- //#endregion
201
- //#region copilot/bin/install.ts
202
- function install() {
203
- if (!env.CI) return;
204
- console.log("install copilot...");
205
- let success = false;
206
- let local = "";
207
- try {
208
- local = execSync("npm list @github/copilot -g --depth=0 --json").toString();
209
- } catch {
210
- local = "{}";
211
- }
212
- try {
213
- const localInfo = JSON.parse(local);
214
- const localVersion = localInfo.dependencies ? localInfo.dependencies?.["@github/copilot"]?.version : void 0;
215
- if (!localVersion) {
216
- installCopilot();
217
- success = true;
218
- console.log("install copilot success");
219
- return;
220
- }
221
- if (localVersion !== execSync("npm view @github/copilot version --registry=https://registry.npmmirror.com").toString().trim()) {
222
- execSync("npm uninstall -g @github/copilot --force");
223
- installCopilot();
224
- success = true;
225
- console.log("update copilot success");
226
- } else {
227
- success = true;
228
- console.log("copilot exists and is up-to-date");
229
- }
230
- } catch (error) {
231
- console.error(error);
232
- }
233
- if (!success) try {
234
- console.warn("try to reinstall copilot...");
235
- installCopilot();
236
- success = true;
237
- } catch (error) {
238
- console.error(error);
239
- }
240
- if (success) return;
241
- console.warn("try to reinstall copilot...");
242
- installCopilot();
243
- }
244
- function installCopilot() {
245
- execSync("npm install -g @github/copilot --registry=https://registry.npmmirror.com", { stdio: "inherit" });
246
- }
247
-
248
248
  //#endregion
249
249
  //#region copilot/bin/index.ts
250
- function logImmediate(message) {
251
- const text = typeof message === "string" ? message : String(message);
252
- stdout.write(text + "\n");
253
- if (!stdout.isTTY && stdout._flush) stdout._flush();
254
- }
255
250
  try {
256
251
  codereview();
257
252
  } catch (error) {
@@ -265,8 +260,8 @@ async function codereview() {
265
260
  return;
266
261
  }
267
262
  install();
268
- const prompt = `Load skills, then call the mcp tool '${name}-${getHash}' to load code-review commits, if the task encounters an error, throw that.
269
- Otherwise, use chinese as default language to call the mcp tool '${name}-${report}'`;
263
+ const prompt = `Load skills, then call the mcp tool '${name$1}-${getHash}' to load code-review commits, if the task encounters an error, throw that.
264
+ Otherwise, use chinese as default language to call the mcp tool '${name$1}-${report}'`;
270
265
  const copilot = spawn("node", [
271
266
  findCopilopt(),
272
267
  ...tools,
@@ -281,23 +276,10 @@ Otherwise, use chinese as default language to call the mcp tool '${name}-${repor
281
276
  "pipe",
282
277
  "pipe"
283
278
  ],
284
- env: {
285
- ...env,
286
- NODE_NO_WARNINGS: "1",
287
- PYTHONUNBUFFERED: "1"
288
- },
289
279
  ...platform === "win32" && { windowsHide: true }
290
280
  });
291
- console.log("执行命令:");
292
- console.log(`node ${findCopilopt()} ${tools.join(" ")} --stream off -p ${prompt}`);
293
- copilot.stdout.setEncoding("utf8");
294
- copilot.stderr.setEncoding("utf8");
295
- copilot.stdout.on("data", (chunk) => {
296
- process.stdout.write(chunk);
297
- });
298
- copilot.stderr.on("data", (chunk) => {
299
- process.stderr.write(chunk);
300
- });
281
+ copilot.stdout.on("data", (chunk) => console.log("Stdout:" + String(chunk)));
282
+ copilot.stderr.on("data", (chunk) => console.error("Stderr:" + String(chunk)));
301
283
  copilot.on("close", (code) => {
302
284
  if (!code) dingding("CRITICAL", "CI ERROR: 代码审查任务失败,请自行检查日志");
303
285
  exit(code);
@@ -305,74 +287,37 @@ Otherwise, use chinese as default language to call the mcp tool '${name}-${repor
305
287
  }
306
288
  /**
307
289
  * 根据操作系统和架构获取对应的 copilot 包名
308
- * @returns 平台特定的包名数组,按优先级排序
309
290
  */
310
- function getCopilotPackageNames() {
311
- const packages = [];
312
- console.log("platform:", platform);
313
- console.log("arch:", arch);
314
- if (platform === "win32" && arch === "x64") packages.push("@github/copilot-win32-x64");
315
- else if (platform === "linux" && arch === "x64") packages.push("@github/copilot-linux-x64");
316
- else if (platform === "linux" && arch === "arm64") packages.push("@github/copilot-linux-arm64");
317
- else if (platform === "darwin" && arch === "arm64") packages.push("@github/copilot-darwin-arm64");
318
- packages.push("@github/copilot");
319
- console.log("packages:", packages);
320
- return packages;
291
+ function getCopilotPackageName() {
292
+ return "@github/copilot";
321
293
  }
322
294
  function findCopilopt() {
323
- const packageNames = getCopilotPackageNames();
295
+ const platformPackage = getCopilotPackageName();
324
296
  let copilot = "";
325
- let foundPackageName = "";
326
- for (const packageName of packageNames) try {
327
- copilot = execSync(`npm list ${packageName} -g -p`).toString().trim();
328
- if (copilot) {
329
- foundPackageName = packageName;
330
- break;
331
- }
332
- } catch {}
297
+ try {
298
+ copilot = execSync(`npm list ${platformPackage} -g -p`).toString().trim();
299
+ } catch {
300
+ try {
301
+ copilot = execSync("npm list @github/copilot -g -p").toString().trim();
302
+ } catch {}
303
+ }
333
304
  if (!copilot) {
334
305
  const first = platform === "win32" ? win : linux;
335
306
  const second = platform === "win32" ? linux : win;
336
- const result = first();
337
- if (result) {
338
- copilot = result;
339
- const pathParts = copilot.split(/[/\\]/);
340
- const nodeModulesIndex = pathParts.indexOf("node_modules");
341
- if (nodeModulesIndex !== -1 && pathParts[nodeModulesIndex + 1]) foundPackageName = pathParts[nodeModulesIndex + 1] === "@github" ? `${pathParts[nodeModulesIndex + 1]}/${pathParts[nodeModulesIndex + 2]}` : pathParts[nodeModulesIndex + 1];
342
- } else {
343
- copilot = second();
344
- if (copilot) {
345
- const pathParts = copilot.split(/[/\\]/);
346
- const nodeModulesIndex = pathParts.indexOf("node_modules");
347
- if (nodeModulesIndex !== -1 && pathParts[nodeModulesIndex + 1]) foundPackageName = pathParts[nodeModulesIndex + 1] === "@github" ? `${pathParts[nodeModulesIndex + 1]}/${pathParts[nodeModulesIndex + 2]}` : pathParts[nodeModulesIndex + 1];
348
- }
349
- }
307
+ copilot = first();
308
+ if (!copilot) copilot = second();
350
309
  if (!copilot) throw new Error("没找到安装的包");
351
310
  }
352
311
  const pkg = join(copilot, "package.json");
353
312
  if (!existsSync(pkg)) throw new Error("安装的包找不到正确版本 " + pkg);
354
313
  const copilotPackage = JSON.parse(readFileSync(pkg, "utf8"));
355
- let binPath;
356
- if (typeof copilotPackage.bin === "string") binPath = copilotPackage.bin;
357
- else if (copilotPackage.bin) {
358
- const possibleKeys = foundPackageName ? [
359
- foundPackageName,
360
- "copilot",
361
- "@github/copilot"
362
- ] : [
363
- "copilot",
364
- "@github/copilot",
365
- ...packageNames
366
- ];
367
- for (const key of possibleKeys) if (copilotPackage.bin[key]) {
368
- binPath = copilotPackage.bin[key];
369
- break;
370
- }
371
- }
314
+ const binPath = typeof copilotPackage.bin === "string" ? copilotPackage.bin : copilotPackage.bin?.copilot || copilotPackage.bin?.[platformPackage] || copilotPackage.bin?.["@github/copilot"];
315
+ console.log("binPath:", binPath);
316
+ console.log("copilotPackage:", copilotPackage);
372
317
  if (!binPath) throw new Error("non copilot executable found");
373
318
  const copilotVersion = copilotPackage.version || "unknown";
374
319
  const copilotPath = join(copilot, binPath);
375
- logImmediate(`${NAME} server:
320
+ console.log(`${NAME} server:
376
321
  version: ${VERSION}
377
322
  path: ${serveFile}
378
323
  copilot:
@@ -385,11 +330,10 @@ function win() {
385
330
  const pathSeparator = platform === "win32" ? ";" : ":";
386
331
  const npm = pathEnv.split(pathSeparator).find((p) => p.includes("npm"));
387
332
  if (!npm) return "";
388
- const packageNames = getCopilotPackageNames();
389
- for (const packageName of packageNames) {
390
- const packagePath = join(npm, "node_modules", ...packageName.split("/"));
391
- if (existsSync(join(packagePath, "package.json"))) return packagePath;
392
- }
333
+ const packagePath = join(npm, "node_modules", ...getCopilotPackageName().split("/"));
334
+ if (existsSync(join(packagePath, "package.json"))) return packagePath;
335
+ const fallbackPath = join(npm, "node_modules", "@github", "copilot");
336
+ if (existsSync(join(fallbackPath, "package.json"))) return fallbackPath;
393
337
  return "";
394
338
  }
395
339
  function linux() {
@@ -401,11 +345,11 @@ function linux() {
401
345
  if (npm) cached = npm;
402
346
  }
403
347
  if (!cached) return "";
404
- const packageNames = getCopilotPackageNames();
405
- for (const packageName of packageNames) {
406
- const packagePath = join(cached, "..", "lib", "node_modules", ...packageName.split("/"));
407
- if (existsSync(join(packagePath, "package.json"))) return packagePath;
408
- }
348
+ const platformPackage = getCopilotPackageName();
349
+ const packagePath = join(cached, "..", "lib", "node_modules", ...platformPackage.split("/"));
350
+ if (existsSync(join(packagePath, "package.json"))) return packagePath;
351
+ const fallbackPath = join(cached, "..", "lib", "node_modules", "@github", "copilot");
352
+ if (existsSync(join(fallbackPath, "package.json"))) return fallbackPath;
409
353
  return "";
410
354
  }
411
355
 
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.38",
7
+ "version": "0.1.40",
8
8
  "devDependencies": {
9
9
  "@modelcontextprotocol/sdk": "^1.25.1",
10
10
  "@types/node": "^25.0.3",