@d5render/cli 0.1.56 → 0.1.57

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 +1 -105
  2. package/package.json +1 -1
package/bin/d5cli CHANGED
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
  import { execSync, spawn } from "node:child_process";
3
- import { createConnection } from "node:net";
4
3
  import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
5
4
  import { dirname, join } from "node:path";
6
5
  import { argv, env, platform } from "node:process";
@@ -108,7 +107,7 @@ function installCopilot() {
108
107
  //#endregion
109
108
  //#region package.json
110
109
  var name = "@d5render/cli";
111
- var version = "0.1.56";
110
+ var version = "0.1.57";
112
111
 
113
112
  //#endregion
114
113
  //#region packages/gitlab/url.ts
@@ -273,7 +272,6 @@ async function codereview() {
273
272
  Otherwise, use chinese as default language to call the mcp tool '${name$1}-${report}'`;
274
273
  const httpProxy = process.env.HTTP_PROXY || process.env.http_proxy || "";
275
274
  const httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy || "";
276
- await logProxyStatus(httpProxy, httpsProxy);
277
275
  const copilot = spawn("node", [
278
276
  findCopilopt(),
279
277
  ...tools,
@@ -301,108 +299,6 @@ Otherwise, use chinese as default language to call the mcp tool '${name$1}-${rep
301
299
  copilot.on("close", (code) => res());
302
300
  });
303
301
  }
304
- /** 代理排查:环境变量 + 检测代理是否在运行、子进程是否会走代理 */
305
- async function logProxyStatus(httpProxy, httpsProxy) {
306
- const tag = "[proxy]";
307
- console.log(`${tag} -------- 代理排查 --------`);
308
- const proxyKeys = Object.keys(process.env).filter((k) => /proxy/i.test(k));
309
- if (proxyKeys.length > 0) console.log(`${tag} 当前进程里含 proxy 的环境变量名: ${proxyKeys.join(", ")}`);
310
- else console.log(`${tag} 当前进程里没有任何含 proxy 的环境变量(GitLab 未传入或未生效)`);
311
- console.log(`${tag} 当前进程 env: HTTP_PROXY = ${process.env.HTTP_PROXY ?? "(未设置)"}, http_proxy = ${process.env.http_proxy ?? "(未设置)"}`);
312
- console.log(`${tag} 当前进程 env: HTTPS_PROXY = ${process.env.HTTPS_PROXY ?? "(未设置)"}, https_proxy = ${process.env.https_proxy ?? "(未设置)"}`);
313
- console.log(`${tag} 传给子进程: HTTP_PROXY = ${httpProxy || "(空)"}, HTTPS_PROXY = ${httpsProxy || "(空)"}`);
314
- const proxyUrl = httpsProxy || httpProxy;
315
- if (!proxyUrl) {
316
- console.log(`${tag} 结论: 未设置代理,子进程将直连外网,不会经代理`);
317
- await logGitHubReachable(tag, false);
318
- console.log(`${tag} ------------------------`);
319
- return;
320
- }
321
- let host;
322
- let port;
323
- try {
324
- const u = new URL(proxyUrl);
325
- host = u.hostname || "127.0.0.1";
326
- port = u.port ? parseInt(u.port, 10) : 7890;
327
- } catch {
328
- console.log(`${tag} 结论: 代理 URL 解析失败,子进程可能无法正确使用代理: ${proxyUrl}`);
329
- console.log(`${tag} ------------------------`);
330
- return;
331
- }
332
- const reachable = await checkPortReachable(host, port);
333
- if (reachable) {
334
- console.log(`${tag} 代理检测: ${host}:${port} 可连接,代理服务应在运行`);
335
- logPortListener(port, tag);
336
- } else {
337
- console.log(`${tag} 代理检测: ${host}:${port} 无法连接,可能代理未启动或地址/端口错误`);
338
- logPortListener(port, tag);
339
- }
340
- await logGitHubReachable(tag, !!proxyUrl);
341
- if (reachable) console.log(`${tag} 结论: 子进程已继承代理环境变量,请求应能通过代理发出`);
342
- else console.log(`${tag} 结论: 子进程虽有代理变量,但代理不可达,请求可能失败或直连`);
343
- console.log(`${tag} ------------------------`);
344
- }
345
- function checkPortReachable(host, port, timeoutMs = 3e3) {
346
- return new Promise((resolve) => {
347
- const socket = createConnection(port, host, () => {
348
- socket.destroy();
349
- resolve(true);
350
- });
351
- socket.setTimeout(timeoutMs);
352
- socket.on("timeout", () => {
353
- socket.destroy();
354
- resolve(false);
355
- });
356
- socket.on("error", () => resolve(false));
357
- });
358
- }
359
- /** 打印指定端口上的监听进程(如 7890 上是 mihomo) */
360
- function logPortListener(port, tag) {
361
- try {
362
- if (platform === "win32") {
363
- const out = execSync(`netstat -ano | findstr :${port}`, {
364
- encoding: "utf8",
365
- maxBuffer: 65536
366
- });
367
- console.log(`${tag} 端口 ${port} 监听情况 (netstat):\n${out.trim().split("\n").slice(0, 10).join("\n")}`);
368
- return;
369
- }
370
- const lsof = execSync(`lsof -i :${port} 2>/dev/null`, {
371
- encoding: "utf8",
372
- maxBuffer: 65536
373
- }).trim();
374
- if (lsof) {
375
- console.log(`${tag} 端口 ${port} 监听进程 (lsof):\n${lsof}`);
376
- return;
377
- }
378
- } catch {}
379
- try {
380
- const ss = execSync(`ss -tlnp 2>/dev/null | grep :${port}`, {
381
- encoding: "utf8",
382
- maxBuffer: 65536
383
- }).trim();
384
- if (ss) console.log(`${tag} 端口 ${port} 监听进程 (ss):\n${ss}`);
385
- else console.log(`${tag} 端口 ${port}: 无法获取监听进程 (无 lsof/ss 或无权限)`);
386
- } catch {
387
- console.log(`${tag} 端口 ${port}: 无法获取监听进程 (无 lsof/ss 或无权限)`);
388
- }
389
- }
390
- /** 检测 GitHub 是否可访问(Node 内置 fetch 不走代理,此处为直连可达性) */
391
- async function logGitHubReachable(tag, proxySet) {
392
- const url = "https://api.github.com";
393
- const note = proxySet ? " (当前进程已设代理,但 Node fetch 不经过代理,此处为直连)" : " (直连)";
394
- try {
395
- const ac = new AbortController();
396
- const t = setTimeout(() => ac.abort(), 1e4);
397
- const res = await fetch(url, { signal: ac.signal });
398
- clearTimeout(t);
399
- const ok = res.ok || res.status === 403;
400
- console.log(`${tag} GitHub 连通性${note}: ${ok ? "可调通" : "异常"} status=${res.status}`);
401
- } catch (e) {
402
- const msg = e instanceof Error ? e.message : String(e);
403
- console.log(`${tag} GitHub 连通性${note}: 调不通 - ${msg}`);
404
- }
405
- }
406
302
  function findCopilopt() {
407
303
  let copilot = "";
408
304
  try {
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.56",
7
+ "version": "0.1.57",
8
8
  "devDependencies": {
9
9
  "@modelcontextprotocol/sdk": "^1.25.1",
10
10
  "@types/node": "^25.0.3",