@d5render/cli 0.1.83 → 0.1.85

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 +56 -39
  2. package/package.json +1 -1
package/bin/d5cli CHANGED
@@ -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.83";
11
+ var version = "0.1.85";
12
12
 
13
13
  //#endregion
14
14
  //#region packages/env.ts
@@ -311,11 +311,40 @@ async function deploy() {
311
311
  //#endregion
312
312
  //#region review/copilot/index.ts
313
313
  const bind = "copilot";
314
- const TOKEN_KEYS = [
315
- "COPILOT_GITHUB_TOKEN",
316
- "GH_TOKEN",
317
- "GITHUB_TOKEN"
318
- ];
314
+ const verifyPrompt = "Reply with OK only, no other text.";
315
+ /** 单引号包裹并转义,用于 shell 内联,避免子进程 env 被改写 */
316
+ function shellEscape(val) {
317
+ return `'${val.replace(/'/g, "'\\''")}'`;
318
+ }
319
+ /** 最简 copilot 调用(仅 -p),用于验证登录/env 是否可用 */
320
+ function runVerifySync() {
321
+ const verifyArgs = ["-p", verifyPrompt];
322
+ const opts = {
323
+ cwd: env.CI_PROJECT_DIR,
324
+ encoding: "utf8"
325
+ };
326
+ if (platform === "win32") {
327
+ const r = spawnSync(bind, verifyArgs, {
328
+ ...opts,
329
+ shell: true
330
+ });
331
+ return {
332
+ code: r.status ?? -1,
333
+ out: r.stdout?.toString() ?? "",
334
+ err: r.stderr?.toString() ?? ""
335
+ };
336
+ }
337
+ const token = env.COPILOT_GITHUB_TOKEN || env.GH_TOKEN || env.GITHUB_TOKEN || env.GITHUB_COPILOT_TOKEN;
338
+ const r = spawnSync("sh", ["-c", `${token !== void 0 && token !== "" ? `export COPILOT_GITHUB_TOKEN=${shellEscape(token)} GH_TOKEN=${shellEscape(token)} GITHUB_TOKEN=${shellEscape(token)}; ` : ""}exec ${bind} ${verifyArgs.map((a) => shellEscape(a)).join(" ")}`], {
339
+ ...opts,
340
+ env
341
+ });
342
+ return {
343
+ code: r.status ?? -1,
344
+ out: r.stdout?.toString() ?? "",
345
+ err: r.stderr?.toString() ?? ""
346
+ };
347
+ }
319
348
  async function cli() {
320
349
  await deploy();
321
350
  const httpProxy = env.HTTP_PROXY || env.http_proxy || "";
@@ -323,50 +352,38 @@ async function cli() {
323
352
  if (httpProxy) env.HTTP_PROXY = httpProxy;
324
353
  if (httpsProxy) env.HTTPS_PROXY = httpsProxy;
325
354
  console.log("@d5render/cli version:", VERSION);
326
- const childEnv = platform === "win32" ? void 0 : env;
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, [
355
+ const verify = runVerifySync();
356
+ console.log("copilot verify:", verify.code === 0 ? "OK" : `failed (code ${verify.code})`);
357
+ if (verify.out) console.log(verify.out.trim());
358
+ if (verify.err) console.error(verify.err.trim());
359
+ const args = [
355
360
  ...tools,
356
361
  "-p",
357
362
  `"${common_review_prompt.replace(/"/g, "\\\"")}"`
358
- ], {
363
+ ];
364
+ const opts = {
359
365
  cwd: env.CI_PROJECT_DIR,
360
366
  stdio: [
361
367
  "inherit",
362
368
  "pipe",
363
369
  "pipe"
364
- ],
365
- ...platform === "win32" ? { shell: true } : { env: childEnv }
370
+ ]
371
+ };
372
+ let child;
373
+ if (platform === "win32") child = spawn(bind, args, {
374
+ ...opts,
375
+ shell: true
366
376
  });
377
+ else {
378
+ const token = env.COPILOT_GITHUB_TOKEN || env.GH_TOKEN || env.GITHUB_TOKEN || env.GITHUB_COPILOT_TOKEN;
379
+ 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(" ")}`], {
380
+ ...opts,
381
+ env
382
+ });
383
+ }
367
384
  child.stdout.on("data", (chunk) => console.log(String(chunk)));
368
385
  child.stderr.on("data", (chunk) => console.error(String(chunk)));
369
- return new Promise((res, rej) => child.on("close", (code) => getCopilotUsage().then((res) => console.log("本次Token积累使用量:", res)).catch(() => {}).finally(() => {
386
+ return new Promise((res, rej) => child.on("close", (code) => getCopilotUsage().then((r) => console.log("本次Token积累使用量:", r)).catch(() => {}).finally(() => {
370
387
  if (code === 0) res();
371
388
  else rej(/* @__PURE__ */ new Error(`${bind} exited with code ${code}`));
372
389
  })));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d5render/cli",
3
- "version": "0.1.83",
3
+ "version": "0.1.85",
4
4
  "license": "MIT",
5
5
  "author": "jasirou",
6
6
  "bin": {