@d5render/cli 0.1.37 → 0.1.39

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 -108
  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 { arch, 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.37";
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.39";
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(String(chunk)));
282
+ copilot.stderr.on("data", (chunk) => console.error(String(chunk)));
301
283
  copilot.on("close", (code) => {
302
284
  if (!code) dingding("CRITICAL", "CI ERROR: 代码审查任务失败,请自行检查日志");
303
285
  exit(code);
@@ -305,27 +287,24 @@ 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
+ if (platform === "win32" && arch === "x64") return "@github/copilot-win32-x64";
293
+ else if (platform === "linux" && arch === "x64") return "@github/copilot-linux-x64";
294
+ else if (platform === "linux" && arch === "arm64") return "@github/copilot-linux-arm64";
295
+ else if (platform === "darwin" && arch === "arm64") return "@github/copilot-darwin-arm64";
296
+ return "@github/copilot";
321
297
  }
322
298
  function findCopilopt() {
323
- const packageNames = getCopilotPackageNames();
299
+ const platformPackage = getCopilotPackageName();
324
300
  let copilot = "";
325
- for (const packageName of packageNames) try {
326
- copilot = execSync(`npm list ${packageName} -g -p`).toString().trim();
327
- if (copilot) break;
328
- } catch {}
301
+ try {
302
+ copilot = execSync(`npm list ${platformPackage} -g -p`).toString().trim();
303
+ } catch {
304
+ try {
305
+ copilot = execSync("npm list @github/copilot -g -p").toString().trim();
306
+ } catch {}
307
+ }
329
308
  if (!copilot) {
330
309
  const first = platform === "win32" ? win : linux;
331
310
  const second = platform === "win32" ? linux : win;
@@ -336,11 +315,11 @@ function findCopilopt() {
336
315
  const pkg = join(copilot, "package.json");
337
316
  if (!existsSync(pkg)) throw new Error("安装的包找不到正确版本 " + pkg);
338
317
  const copilotPackage = JSON.parse(readFileSync(pkg, "utf8"));
339
- const binPath = typeof copilotPackage.bin === "string" ? copilotPackage.bin : copilotPackage.bin?.copilot || copilotPackage.bin?.["@github/copilot"];
318
+ const binPath = typeof copilotPackage.bin === "string" ? copilotPackage.bin : copilotPackage.bin?.copilot || copilotPackage.bin?.[platformPackage] || copilotPackage.bin?.["@github/copilot"];
340
319
  if (!binPath) throw new Error("non copilot executable found");
341
320
  const copilotVersion = copilotPackage.version || "unknown";
342
321
  const copilotPath = join(copilot, binPath);
343
- logImmediate(`${NAME} server:
322
+ console.log(`${NAME} server:
344
323
  version: ${VERSION}
345
324
  path: ${serveFile}
346
325
  copilot:
@@ -353,11 +332,10 @@ function win() {
353
332
  const pathSeparator = platform === "win32" ? ";" : ":";
354
333
  const npm = pathEnv.split(pathSeparator).find((p) => p.includes("npm"));
355
334
  if (!npm) return "";
356
- const packageNames = getCopilotPackageNames();
357
- for (const packageName of packageNames) {
358
- const packagePath = join(npm, "node_modules", ...packageName.split("/"));
359
- if (existsSync(join(packagePath, "package.json"))) return packagePath;
360
- }
335
+ const packagePath = join(npm, "node_modules", ...getCopilotPackageName().split("/"));
336
+ if (existsSync(join(packagePath, "package.json"))) return packagePath;
337
+ const fallbackPath = join(npm, "node_modules", "@github", "copilot");
338
+ if (existsSync(join(fallbackPath, "package.json"))) return fallbackPath;
361
339
  return "";
362
340
  }
363
341
  function linux() {
@@ -369,11 +347,11 @@ function linux() {
369
347
  if (npm) cached = npm;
370
348
  }
371
349
  if (!cached) return "";
372
- const packageNames = getCopilotPackageNames();
373
- for (const packageName of packageNames) {
374
- const packagePath = join(cached, "..", "lib", "node_modules", ...packageName.split("/"));
375
- if (existsSync(join(packagePath, "package.json"))) return packagePath;
376
- }
350
+ const platformPackage = getCopilotPackageName();
351
+ const packagePath = join(cached, "..", "lib", "node_modules", ...platformPackage.split("/"));
352
+ if (existsSync(join(packagePath, "package.json"))) return packagePath;
353
+ const fallbackPath = join(cached, "..", "lib", "node_modules", "@github", "copilot");
354
+ if (existsSync(join(fallbackPath, "package.json"))) return fallbackPath;
377
355
  return "";
378
356
  }
379
357
 
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.37",
7
+ "version": "0.1.39",
8
8
  "devDependencies": {
9
9
  "@modelcontextprotocol/sdk": "^1.25.1",
10
10
  "@types/node": "^25.0.3",