@d5render/cli 0.1.83 → 0.1.84
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 +23 -40
- package/package.json +1 -1
package/bin/d5cli
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { argv, env, platform } from "node:process";
|
|
3
|
-
import { execSync, spawn
|
|
3
|
+
import { execSync, spawn } from "node:child_process";
|
|
4
4
|
import { createHash } from "node:crypto";
|
|
5
5
|
import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { dirname, join } from "node:path";
|
|
@@ -8,7 +8,7 @@ import { fileURLToPath } from "node:url";
|
|
|
8
8
|
|
|
9
9
|
//#region package.json
|
|
10
10
|
var name$1 = "@d5render/cli";
|
|
11
|
-
var version = "0.1.
|
|
11
|
+
var version = "0.1.84";
|
|
12
12
|
|
|
13
13
|
//#endregion
|
|
14
14
|
//#region packages/env.ts
|
|
@@ -311,11 +311,10 @@ async function deploy() {
|
|
|
311
311
|
//#endregion
|
|
312
312
|
//#region review/copilot/index.ts
|
|
313
313
|
const bind = "copilot";
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
"
|
|
317
|
-
|
|
318
|
-
];
|
|
314
|
+
/** 单引号包裹并转义,用于 shell 内联,避免子进程 env 被改写 */
|
|
315
|
+
function shellEscape(val) {
|
|
316
|
+
return `'${val.replace(/'/g, "'\\''")}'`;
|
|
317
|
+
}
|
|
319
318
|
async function cli() {
|
|
320
319
|
await deploy();
|
|
321
320
|
const httpProxy = env.HTTP_PROXY || env.http_proxy || "";
|
|
@@ -323,50 +322,34 @@ async function cli() {
|
|
|
323
322
|
if (httpProxy) env.HTTP_PROXY = httpProxy;
|
|
324
323
|
if (httpsProxy) env.HTTPS_PROXY = httpsProxy;
|
|
325
324
|
console.log("@d5render/cli version:", VERSION);
|
|
326
|
-
const
|
|
327
|
-
if (childEnv) {
|
|
328
|
-
console.log("[env] child env keys count:", Object.keys(childEnv).length);
|
|
329
|
-
console.log("[env] child env token keys present:", TOKEN_KEYS.filter((k) => childEnv[k]).join(", ") || "(none)");
|
|
330
|
-
const check = spawnSync(process.execPath, ["-e", `
|
|
331
|
-
const ok = process.env.COPILOT_GITHUB_TOKEN ? 'OK' : 'MISSING';
|
|
332
|
-
console.log('[env] env injected:', ok);
|
|
333
|
-
const keys = ['COPILOT_GITHUB_TOKEN','GH_TOKEN','GITHUB_TOKEN'];
|
|
334
|
-
const lengths = keys.map(k => k + '=' + (process.env[k]?.length ?? 0)).join(', ');
|
|
335
|
-
console.log('[env] token lengths (7~8 may be literal [MASKED]):', lengths);
|
|
336
|
-
`.trim()], {
|
|
337
|
-
env: childEnv,
|
|
338
|
-
encoding: "utf8"
|
|
339
|
-
});
|
|
340
|
-
(check.stdout?.trim() || check.stderr?.trim() || "").split("\n").forEach((line) => console.log(line));
|
|
341
|
-
const parentLengths = TOKEN_KEYS.map((k) => `${k}=${env[k]?.length ?? 0}`).join(", ");
|
|
342
|
-
console.log("[env] parent process token lengths:", parentLengths);
|
|
343
|
-
try {
|
|
344
|
-
const whichOut = spawnSync(platform === "win32" ? "where copilot" : "which copilot", [], {
|
|
345
|
-
shell: true,
|
|
346
|
-
encoding: "utf8"
|
|
347
|
-
});
|
|
348
|
-
const pathOut = (whichOut.stdout?.trim() || whichOut.stderr?.trim() || "").split("\n")[0];
|
|
349
|
-
console.log("[env] copilot executable:", pathOut || "(not found)");
|
|
350
|
-
} catch {
|
|
351
|
-
console.log("[env] copilot executable: (resolve failed)");
|
|
352
|
-
}
|
|
353
|
-
} else console.log("[env] child env: inherits process.env (win32)");
|
|
354
|
-
const child = spawn(bind, [
|
|
325
|
+
const args = [
|
|
355
326
|
...tools,
|
|
356
327
|
"-p",
|
|
357
328
|
`"${common_review_prompt.replace(/"/g, "\\\"")}"`
|
|
358
|
-
]
|
|
329
|
+
];
|
|
330
|
+
const opts = {
|
|
359
331
|
cwd: env.CI_PROJECT_DIR,
|
|
360
332
|
stdio: [
|
|
361
333
|
"inherit",
|
|
362
334
|
"pipe",
|
|
363
335
|
"pipe"
|
|
364
|
-
]
|
|
365
|
-
|
|
336
|
+
]
|
|
337
|
+
};
|
|
338
|
+
let child;
|
|
339
|
+
if (platform === "win32") child = spawn(bind, args, {
|
|
340
|
+
...opts,
|
|
341
|
+
shell: true
|
|
366
342
|
});
|
|
343
|
+
else {
|
|
344
|
+
const token = env.COPILOT_GITHUB_TOKEN || env.GH_TOKEN || env.GITHUB_TOKEN || env.GITHUB_COPILOT_TOKEN;
|
|
345
|
+
child = spawn("sh", ["-c", `${token !== void 0 && token !== "" ? `export COPILOT_GITHUB_TOKEN=${shellEscape(token)} GH_TOKEN=${shellEscape(token)} GITHUB_TOKEN=${shellEscape(token)}; ` : ""}exec ${bind} ${args.map((a) => shellEscape(a)).join(" ")}`], {
|
|
346
|
+
...opts,
|
|
347
|
+
env
|
|
348
|
+
});
|
|
349
|
+
}
|
|
367
350
|
child.stdout.on("data", (chunk) => console.log(String(chunk)));
|
|
368
351
|
child.stderr.on("data", (chunk) => console.error(String(chunk)));
|
|
369
|
-
return new Promise((res, rej) => child.on("close", (code) => getCopilotUsage().then((
|
|
352
|
+
return new Promise((res, rej) => child.on("close", (code) => getCopilotUsage().then((r) => console.log("本次Token积累使用量:", r)).catch(() => {}).finally(() => {
|
|
370
353
|
if (code === 0) res();
|
|
371
354
|
else rej(/* @__PURE__ */ new Error(`${bind} exited with code ${code}`));
|
|
372
355
|
})));
|