@d5render/cli 0.1.56 → 0.1.60
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/.skills/code-review/SKILL.md +34 -6
- package/bin/copilot.js +737 -740
- package/bin/d5cli +9 -113
- package/package.json +1 -2
- package/.github/instructions/code-review.instructions.md +0 -43
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";
|
|
@@ -52,9 +51,9 @@ function toEnv(key, defaultValue) {
|
|
|
52
51
|
}
|
|
53
52
|
function buildEnv() {
|
|
54
53
|
const envArg = argv.find((arg) => arg.startsWith("--customizenv="));
|
|
55
|
-
let envJson
|
|
56
|
-
if (envArg) envJson
|
|
57
|
-
return envJson
|
|
54
|
+
let envJson = {};
|
|
55
|
+
if (envArg) envJson = JSON.parse(envArg.replace("--customizenv=", ""));
|
|
56
|
+
return envJson;
|
|
58
57
|
}
|
|
59
58
|
|
|
60
59
|
//#endregion
|
|
@@ -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.
|
|
110
|
+
var version = "0.1.60";
|
|
112
111
|
|
|
113
112
|
//#endregion
|
|
114
113
|
//#region packages/gitlab/url.ts
|
|
@@ -221,14 +220,14 @@ async function deploy() {
|
|
|
221
220
|
async function need() {
|
|
222
221
|
if (!env.CI) return true;
|
|
223
222
|
const { CI_MERGE_REQUEST_IID, CI_COMMIT_SHA } = env;
|
|
224
|
-
const file
|
|
223
|
+
const file = join(TEMP, "CODEREVIEW");
|
|
225
224
|
if (CI_MERGE_REQUEST_IID) {
|
|
226
|
-
let appended = `${existsSync(file
|
|
225
|
+
let appended = `${existsSync(file) ? readFileSync(file, "utf8") : ""}\n${CI_MERGE_REQUEST_IID}`.split("\n");
|
|
227
226
|
const max = 1e4;
|
|
228
227
|
if (appended.length > max) appended = appended.slice(-max);
|
|
229
228
|
if (!existsSync(TEMP)) mkdirSync(TEMP, { recursive: true });
|
|
230
|
-
writeFileSync(file
|
|
231
|
-
console.log("merge pipeline, recorded IID:", CI_MERGE_REQUEST_IID, "to:", file
|
|
229
|
+
writeFileSync(file, appended.join("\n"), "utf8");
|
|
230
|
+
console.log("merge pipeline, recorded IID:", CI_MERGE_REQUEST_IID, "to:", file);
|
|
232
231
|
return true;
|
|
233
232
|
}
|
|
234
233
|
if (!CI_COMMIT_SHA) return true;
|
|
@@ -239,7 +238,7 @@ async function need() {
|
|
|
239
238
|
}).toString().match(/See merge request[\s\S]+!(\d+)/);
|
|
240
239
|
if (!match) return true;
|
|
241
240
|
const iid = match[1];
|
|
242
|
-
const yes = (existsSync(file
|
|
241
|
+
const yes = (existsSync(file) ? readFileSync(file, "utf8") : "").split("\n").includes(iid);
|
|
243
242
|
if (yes) {
|
|
244
243
|
console.warn(`Merge Request !${iid} has been AI reviewed before.`);
|
|
245
244
|
const mergeURL = visitPipeline(iid).url;
|
|
@@ -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.
|
|
7
|
+
"version": "0.1.60",
|
|
8
8
|
"devDependencies": {
|
|
9
9
|
"@modelcontextprotocol/sdk": "^1.25.1",
|
|
10
10
|
"@types/node": "^25.0.3",
|
|
@@ -18,7 +18,6 @@
|
|
|
18
18
|
"zod": "^4.3.5"
|
|
19
19
|
},
|
|
20
20
|
"files": [
|
|
21
|
-
".github/instructions/code-review.instructions.md",
|
|
22
21
|
".github/instructions/severity.instructions.md",
|
|
23
22
|
".skills/devops",
|
|
24
23
|
".skills/code-review",
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
applyTo: "**"
|
|
3
|
-
excludeAgent: ["code-review"]
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
1. **MUST** Take the file as the review target:
|
|
7
|
-
- The focus of this review is on the content involved in the diff but the evaluation dimensions need to be based on the file content.
|
|
8
|
-
- When the diff in the discrepancy report differs from the document content, the diff is only used as a line number reference.
|
|
9
|
-
- The actual content that needs to be reviewed should be **based on the document content**.
|
|
10
|
-
2. Establish context by **reading relevant files**, files that are **imported/used by** the diff files or are **structurally neighboring** them (e.g., related configuration or test files).
|
|
11
|
-
3. **Ensure the relationship diagram of the diff is complete:**
|
|
12
|
-
- After establishing the context, analyze the complete context of the difference code to ensure a relatively complete code relationship diagram can be built.
|
|
13
|
-
- If the content is incomplete, supplement the context and rebuild the relationship diagram.
|
|
14
|
-
4. Read the commit message as the basic understanding of the current change
|
|
15
|
-
5. Determine technology the repository belongs, draw upon your understanding of that technology, provide recommendations on cutting-edge technologies and best practices:
|
|
16
|
-
- **Consult the workspace introduction** yourself.
|
|
17
|
-
- Consult cutting-edge industry documentation yourself.
|
|
18
|
-
6. **Execute as many relevant commands as possible to enrich your context.**
|
|
19
|
-
7. **Prioritize Analysis Focus**:
|
|
20
|
-
- For all collected code, meticulously trace the logic to uncover functional bugs and correctness issues.
|
|
21
|
-
- Pay attention to the **correctness** of the analytical logic, the **efficiency** of the code, and its **long-term maintainability**.
|
|
22
|
-
- Concentrate your deepest analysis on the application code (non-test files).
|
|
23
|
-
- Actively consider edge cases, off-by-one errors, race conditions, and improper null/error handling.
|
|
24
|
-
- **focusing on major errors**, identify potential bugs, architectural impact, security vulnerabilities, performance bottlenecks, and clarity issues.
|
|
25
|
-
- focusing on last commit when the same functionality rolling commits occur.
|
|
26
|
-
8. **Maintain skepticism but verify carefully**:
|
|
27
|
-
- Gather as much context as possible for the code you suspect, raise questions only after **ensuring you have a sufficient understanding** of the business logic.
|
|
28
|
-
- If doubts persist even after establishing a complete context, lower the severity rating of the issue.
|
|
29
|
-
9. **Strictly** classify the severity according to the content of **file: [severity.instructions.md](./severity.instructions.md)**.
|
|
30
|
-
10. **Further summary report:**
|
|
31
|
-
- **Tone/Content:** **DO NOT** add comments that:
|
|
32
|
-
- Tell the user to "check," "confirm," "verify," or "ensure" something.
|
|
33
|
-
- Explain what the code change does or validate its purpose.
|
|
34
|
-
- Explain the code to the author (they are assumed to know their own code).
|
|
35
|
-
- Comment on missing trailing newlines or other purely stylistic issues that do not affect code execution or readability in a meaningful way.
|
|
36
|
-
- **Technical Detail:**
|
|
37
|
-
- Pay **meticulous attention to line numbers and indentation** in code suggestions; they **must** be correct and match the surrounding code.
|
|
38
|
-
- **NEVER** comment on license headers, copyright headers, or anything related to future dates/versions (e.g., "this date is in the future").
|
|
39
|
-
- **NEVER** comment on the presence or absence of comments in the code.
|
|
40
|
-
- **Formatting/Structure:**
|
|
41
|
-
- Keep the **change summary** concise (aim for a single sentence).
|
|
42
|
-
- Keep **comment bodies concise** and focused on a single issue.
|
|
43
|
-
- When similar issues occur frequently, please review the code to determine if it meets the change objectives.
|