@d5render/cli 0.1.54 → 0.1.56
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/bin/d5cli +109 -3
- package/package.json +1 -1
package/bin/d5cli
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { execSync, spawn } from "node:child_process";
|
|
3
|
+
import { createConnection } from "node:net";
|
|
3
4
|
import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
4
5
|
import { dirname, join } from "node:path";
|
|
5
6
|
import { argv, env, platform } from "node:process";
|
|
@@ -107,7 +108,7 @@ function installCopilot() {
|
|
|
107
108
|
//#endregion
|
|
108
109
|
//#region package.json
|
|
109
110
|
var name = "@d5render/cli";
|
|
110
|
-
var version = "0.1.
|
|
111
|
+
var version = "0.1.56";
|
|
111
112
|
|
|
112
113
|
//#endregion
|
|
113
114
|
//#region packages/gitlab/url.ts
|
|
@@ -270,6 +271,9 @@ async function codereview() {
|
|
|
270
271
|
install();
|
|
271
272
|
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.
|
|
272
273
|
Otherwise, use chinese as default language to call the mcp tool '${name$1}-${report}'`;
|
|
274
|
+
const httpProxy = process.env.HTTP_PROXY || process.env.http_proxy || "";
|
|
275
|
+
const httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy || "";
|
|
276
|
+
await logProxyStatus(httpProxy, httpsProxy);
|
|
273
277
|
const copilot = spawn("node", [
|
|
274
278
|
findCopilopt(),
|
|
275
279
|
...tools,
|
|
@@ -287,8 +291,8 @@ Otherwise, use chinese as default language to call the mcp tool '${name$1}-${rep
|
|
|
287
291
|
...platform === "win32" && { windowsHide: true },
|
|
288
292
|
env: {
|
|
289
293
|
...process.env,
|
|
290
|
-
HTTP_PROXY:
|
|
291
|
-
HTTPS_PROXY:
|
|
294
|
+
HTTP_PROXY: httpProxy,
|
|
295
|
+
HTTPS_PROXY: httpsProxy
|
|
292
296
|
}
|
|
293
297
|
});
|
|
294
298
|
copilot.stdout.on("data", (chunk) => console.log(String(chunk)));
|
|
@@ -297,6 +301,108 @@ Otherwise, use chinese as default language to call the mcp tool '${name$1}-${rep
|
|
|
297
301
|
copilot.on("close", (code) => res());
|
|
298
302
|
});
|
|
299
303
|
}
|
|
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
|
+
}
|
|
300
406
|
function findCopilopt() {
|
|
301
407
|
let copilot = "";
|
|
302
408
|
try {
|