@hcmai/cli 0.15.6 → 0.15.8

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/dist/index.js CHANGED
@@ -142,7 +142,7 @@ import {
142
142
  } from "@hcmai/sdk";
143
143
  async function ensureActiveAuth(args) {
144
144
  const g = await loadGlobalConfig();
145
- const resolved = await resolveEnvContext({ envFlag: args.envFlag, fallbackEnv: args.fallbackEnv }, process.env, g);
145
+ const resolved = await resolveEnvContext({ envFlag: args.envFlag, fallbackEnv: args.fallbackEnv, cwd: args.cwd }, process.env, g);
146
146
  if (resolved.project && (process.env.HCM_PAT || process.env.HCM_ACCESS_TOKEN)) throw new CliError2({
147
147
  code: CliErrorCode.INVALID_ARGUMENT,
148
148
  message: "\u9879\u76EE\u73AF\u5883\u4E0D\u63A5\u53D7 HCM_PAT / HCM_ACCESS_TOKEN \u8986\u76D6\u5DF2\u9009\u62E9\u8EAB\u4EFD\u7684\u51ED\u636E\uFF1B\u672A\u53D1\u9001\u4E1A\u52A1\u8BF7\u6C42\u3002",
@@ -326,7 +326,7 @@ async function getActiveAuthContextFromCli(args, opts) {
326
326
  );
327
327
  envFlag = args.profile;
328
328
  }
329
- const ctx = await ensureActiveAuth({ envFlag, asFlag: args.as, fallbackEnv: opts?.fallbackEnv, allowDanger: args.allowDanger });
329
+ const ctx = await ensureActiveAuth({ envFlag, asFlag: args.as, fallbackEnv: opts?.fallbackEnv, cwd: opts?.cwd, allowDanger: args.allowDanger });
330
330
  return ctx;
331
331
  }
332
332
  async function deadlockHint(envName) {
@@ -769,8 +769,8 @@ var init_TerminalRenderer = __esm({
769
769
  }
770
770
  }
771
771
  /** 来源行(仅子代理触发,agentPath ≥2 段时显示 `↑ 来自 a › b`,对齐 Web)。 */
772
- originLine(path18) {
773
- const segs = path18.split(".").filter(Boolean);
772
+ originLine(path19) {
773
+ const segs = path19.split(".").filter(Boolean);
774
774
  if (segs.length < 2) return "";
775
775
  const names = segs.map((k) => agentDisplayName(k));
776
776
  return chalk.gray(` \u2191 \u6765\u81EA ${names.join(" \u203A ")}`) + "\n";
@@ -1952,8 +1952,8 @@ function agentLabel(agentId) {
1952
1952
  if (/^[0-9a-f]{8}-[0-9a-f-]{27}$/i.test(agentId)) return `agent \u2026${agentId.slice(-4)}`;
1953
1953
  return agentDisplayName(agentId);
1954
1954
  }
1955
- function originLine(path18) {
1956
- const segs = (path18 ?? "").split(".").filter(Boolean);
1955
+ function originLine(path19) {
1956
+ const segs = (path19 ?? "").split(".").filter(Boolean);
1957
1957
  if (segs.length < 2) return null;
1958
1958
  return `\u6765\u81EA ${segs.map((k) => agentDisplayName(k)).join(" \u203A ")}`;
1959
1959
  }
@@ -2376,7 +2376,7 @@ function launchBrowser(url, platform = process.platform, onFailure) {
2376
2376
  child.unref();
2377
2377
  }
2378
2378
  async function runOpen(target, args, deps) {
2379
- const path18 = normalizeTarget(target);
2379
+ const path19 = normalizeTarget(target);
2380
2380
  if (!deps.frontend?.trim()) {
2381
2381
  throw new CliError3({
2382
2382
  code: CliErrorCode2.INVALID_ARGUMENT,
@@ -2384,13 +2384,13 @@ async function runOpen(target, args, deps) {
2384
2384
  });
2385
2385
  }
2386
2386
  const { ticket, expiresIn } = await deps.mintTicket();
2387
- const url = buildBrowserLoginUrl(deps.frontend, ticket, path18);
2387
+ const url = buildBrowserLoginUrl(deps.frontend, ticket, path19);
2388
2388
  if (args.printUrl) {
2389
2389
  deps.write(`${url}
2390
2390
  `);
2391
2391
  } else {
2392
2392
  deps.launch(url);
2393
- deps.write(`\u5DF2\u7528\u5F53\u524D\u8EAB\u4EFD\u6253\u5F00 ${path18}\uFF08\u7968\u636E ${expiresIn ?? 60}s \u5185\u6709\u6548\uFF0C\u53EA\u80FD\u7528\u4E00\u6B21\uFF09
2393
+ deps.write(`\u5DF2\u7528\u5F53\u524D\u8EAB\u4EFD\u6253\u5F00 ${path19}\uFF08\u7968\u636E ${expiresIn ?? 60}s \u5185\u6709\u6548\uFF0C\u53EA\u80FD\u7528\u4E00\u6B21\uFF09
2394
2394
  `);
2395
2395
  }
2396
2396
  return { url, expiresIn };
@@ -3413,7 +3413,7 @@ function renderEnvListing(listing) {
3413
3413
  const out = [];
3414
3414
  const effectiveRow = rows2.find((r) => r.name === effective);
3415
3415
  out.push(
3416
- effective ? `\u2192 \u8FD9\u4E2A\u76EE\u5F55\u7528 ${effective}\uFF08\u6765\u81EA ${source === "env.yaml" ? `${file} \u7684 default` : source}\uFF09${effectiveRow?.slot ? `\uFF0C\u51ED\u636E\u53D6\u672C\u673A\u69FD ${effectiveRow.slot}` : "\uFF0C\u4F46\u5B83\u8FD8\u6CA1\u5728\u672C\u673A\u767B\u5F55\u8FC7"}` : `\u2192 \u8FD9\u4E2A\u76EE\u5F55\u6709 ${file}\uFF0C\u4F46\u751F\u6548\u7684\u662F\u672C\u673A\u69FD ${listing.activeEnv}\uFF08${source ?? "activeEnv"} \u6307\u7684\u540D\u5B57\u4E0D\u5728 ${file} \u91CC\uFF09`
3416
+ listing.resolutionError ? `\u2192 \u73AF\u5883\u9009\u62E9\u5931\u8D25\uFF1A${listing.resolutionError}` : effective ? `\u2192 \u8FD9\u4E2A\u76EE\u5F55\u7528 ${effective}\uFF08\u6765\u81EA ${source === "env.yaml" ? `${file} \u7684 default` : source}\uFF09${effectiveRow?.slot ? `\uFF0C\u51ED\u636E\u53D6\u672C\u673A\u69FD ${effectiveRow.slot}` : "\uFF0C\u4F46\u5B83\u8FD8\u6CA1\u5728\u672C\u673A\u767B\u5F55\u8FC7"}` : `\u2192 \u8FD9\u4E2A\u76EE\u5F55\u6709 ${file}\uFF0C\u4F46\u751F\u6548\u7684\u662F\u672C\u673A\u69FD ${listing.effectiveSlot ?? listing.activeEnv}\uFF08\u6765\u81EA ${source ?? "activeEnv"}\uFF1B\u5730\u5740\u6216\u79DF\u6237\u4E0D\u5339\u914D\u9879\u76EE\u58F0\u660E\uFF09`
3417
3417
  );
3418
3418
  out.push("");
3419
3419
  out.push(`\u9879\u76EE\u73AF\u5883\uFF08${file}\uFF09`);
@@ -3465,15 +3465,35 @@ async function collectEnvListing(args = {}) {
3465
3465
  const listing = { slots, activeEnv: g.activeEnv };
3466
3466
  const discovered = await discoverProjectEnv2();
3467
3467
  if (!discovered) return listing;
3468
- const selected = await resolveProjectEnvironment2({}, process.env);
3468
+ let selected = await resolveProjectEnvironment2({}, process.env);
3469
+ let resolved;
3470
+ if (!selected) {
3471
+ try {
3472
+ resolved = await resolveEnvContext3({}, process.env, g);
3473
+ } catch (e) {
3474
+ if (!(e instanceof CliError6) || e.code !== CliErrorCode5.ENV_NOT_FOUND && e.code !== CliErrorCode5.INVALID_ARGUMENT) throw e;
3475
+ listing.resolutionError = e.message;
3476
+ }
3477
+ }
3478
+ if (resolved) {
3479
+ selected = resolved.project ?? null;
3480
+ listing.effectiveSlot = resolved.name;
3481
+ }
3469
3482
  const rows2 = await Promise.all(
3470
3483
  Object.entries(discovered.config.environments).map(async ([name, env2]) => {
3471
3484
  const found = await findEnvByEndpoint2(env2.endpoint, env2.tenant, { strictTenant: true, activeEnv: g.activeEnv });
3472
- return { name, endpoint: env2.endpoint, tenant: env2.tenant, danger: env2.danger === true, slot: found?.name ?? null };
3485
+ return {
3486
+ name,
3487
+ endpoint: env2.endpoint,
3488
+ tenant: env2.tenant,
3489
+ danger: env2.danger === true,
3490
+ slot: resolved?.project?.name === name ? resolved.name : found?.name ?? null
3491
+ };
3473
3492
  })
3474
3493
  );
3475
3494
  if (!args.all) {
3476
3495
  const relevant = new Set(rows2.map((r) => r.slot).filter((n) => n !== null));
3496
+ if (resolved) relevant.add(resolved.name);
3477
3497
  const kept = slots.filter((s) => relevant.has(s.name));
3478
3498
  listing.hiddenSlots = slots.length - kept.length;
3479
3499
  listing.slots = kept;
@@ -3483,7 +3503,7 @@ async function collectEnvListing(args = {}) {
3483
3503
  file: relative2.startsWith(".") ? relative2 : `./${relative2}`,
3484
3504
  rows: rows2,
3485
3505
  effective: selected?.name ?? null,
3486
- source: selected?.source ?? null
3506
+ source: selected?.source ?? resolved?.source ?? null
3487
3507
  };
3488
3508
  return listing;
3489
3509
  }
@@ -4468,8 +4488,8 @@ import {
4468
4488
  formatObject as formatObject7,
4469
4489
  fromAxiosError as fromAxiosError9
4470
4490
  } from "@hcmai/sdk";
4471
- function collectYmlFiles(path18) {
4472
- if (statSync(path18).isFile()) return [path18];
4491
+ function collectYmlFiles(path19) {
4492
+ if (statSync(path19).isFile()) return [path19];
4473
4493
  const out = [];
4474
4494
  const walk = (dir) => {
4475
4495
  for (const name of readdirSync(dir).sort()) {
@@ -4478,7 +4498,7 @@ function collectYmlFiles(path18) {
4478
4498
  else if (full.endsWith(".yml") || full.endsWith(".yaml")) out.push(full);
4479
4499
  }
4480
4500
  };
4481
- walk(path18);
4501
+ walk(path19);
4482
4502
  return out.sort();
4483
4503
  }
4484
4504
  var DRY_RUN_CLIENT = {
@@ -4486,9 +4506,9 @@ var DRY_RUN_CLIENT = {
4486
4506
  create: async () => ({ id: "" }),
4487
4507
  update: async () => ({})
4488
4508
  };
4489
- async function importCommand(path18, args) {
4509
+ async function importCommand(path19, args) {
4490
4510
  try {
4491
- const files = collectYmlFiles(path18);
4511
+ const files = collectYmlFiles(path19);
4492
4512
  const fixtures = files.map(
4493
4513
  (f) => parseFixture(readFileSync2(f, "utf8"), relative(process.cwd(), f))
4494
4514
  );
@@ -8780,10 +8800,10 @@ async function metaListCommand(args) {
8780
8800
  fail7(e, args, "read");
8781
8801
  }
8782
8802
  }
8783
- async function metaGetCommand(path18, args) {
8803
+ async function metaGetCommand(path19, args) {
8784
8804
  try {
8785
8805
  const c = await client2(args);
8786
- const content = await getTenantMeta(c.raw(), path18);
8806
+ const content = await getTenantMeta(c.raw(), path19);
8787
8807
  process.stdout.write(content.endsWith("\n") ? content : content + "\n");
8788
8808
  process.exitCode = 0;
8789
8809
  return;
@@ -8792,8 +8812,8 @@ async function metaGetCommand(path18, args) {
8792
8812
  }
8793
8813
  }
8794
8814
  var PROBEABLE_META_TYPES = /* @__PURE__ */ new Set(["model", "list", "info", "view", "filter", "page", "wiz", "impexp"]);
8795
- function parseMetaPath(path18) {
8796
- const base = path18.split(/[\\/]/).pop() ?? path18;
8815
+ function parseMetaPath(path19) {
8816
+ const base = path19.split(/[\\/]/).pop() ?? path19;
8797
8817
  if (!/\.(yml|yaml)$/i.test(base)) return {};
8798
8818
  const parts = base.replace(/\.(yml|yaml)$/i, "").split(".");
8799
8819
  return { model: parts[0] || void 0, kind: parts[1] ?? "model", state: parts[2] };
@@ -8810,10 +8830,10 @@ function unverifiableReason(e) {
8810
8830
  if (st == null) return `\u8BF7\u6C42\u6CA1\u53D1\u51FA\u53BB\u6216\u6CA1\u56DE\u6765\uFF08${err.code ?? err.message ?? "\u672A\u77E5"}\uFF09`;
8811
8831
  return void 0;
8812
8832
  }
8813
- async function verifyAfterWrite(c, path18) {
8814
- const { model, kind, state } = parseMetaPath(path18);
8833
+ async function verifyAfterWrite(c, path19) {
8834
+ const { model, kind, state } = parseMetaPath(path19);
8815
8835
  if (!model || !kind) {
8816
- return { status: "unverified", where: "(\u672A\u63A2)", why: `\u4ECE\u8DEF\u5F84 ${path18} \u8BA4\u4E0D\u51FA\u6A21\u578B\u540D/\u5C42\u540D` };
8836
+ return { status: "unverified", where: "(\u672A\u63A2)", why: `\u4ECE\u8DEF\u5F84 ${path19} \u8BA4\u4E0D\u51FA\u6A21\u578B\u540D/\u5C42\u540D` };
8817
8837
  }
8818
8838
  try {
8819
8839
  await clearMetaCache2(c.raw(), model, {});
@@ -8858,7 +8878,7 @@ async function verifyAfterWrite(c, path18) {
8858
8878
  }
8859
8879
  return { status: "ok" };
8860
8880
  }
8861
- async function metaSetCommand(path18, args) {
8881
+ async function metaSetCommand(path19, args) {
8862
8882
  try {
8863
8883
  if (!args.file) {
8864
8884
  throw new CliError22({
@@ -8874,9 +8894,9 @@ async function metaSetCommand(path18, args) {
8874
8894
  process.stdin.on("error", reject);
8875
8895
  }) : await fsp3.readFile(args.file, "utf8");
8876
8896
  if (!args.skipValidate) {
8877
- const result2 = validateMetaContent(path18, content);
8897
+ const result2 = validateMetaContent(path19, content);
8878
8898
  if (result2.issues.length > 0) {
8879
- process.stderr.write(`\u{1F50E} \u5199\u524D\u6821\u9A8C ${path18}\uFF08schema \u7C7B\u578B\uFF1A${result2.kind ?? "\u672A\u8BC6\u522B"}\uFF09
8899
+ process.stderr.write(`\u{1F50E} \u5199\u524D\u6821\u9A8C ${path19}\uFF08schema \u7C7B\u578B\uFF1A${result2.kind ?? "\u672A\u8BC6\u522B"}\uFF09
8880
8900
  `);
8881
8901
  process.stderr.write(formatMetaIssues(result2, " ") + "\n");
8882
8902
  }
@@ -8895,13 +8915,13 @@ async function metaSetCommand(path18, args) {
8895
8915
  if (dryFmt === "json" || dryFmt === "yaml") {
8896
8916
  process.stdout.write(
8897
8917
  formatObject20(
8898
- { dryRun: true, path: path18, bytes: Buffer.byteLength(content), content },
8918
+ { dryRun: true, path: path19, bytes: Buffer.byteLength(content), content },
8899
8919
  { format: dryFmt }
8900
8920
  ) + "\n"
8901
8921
  );
8902
8922
  } else {
8903
8923
  process.stdout.write(
8904
- `[dry-run] \u5C06\u5199\u5165 ${path18}\uFF08${Buffer.byteLength(content)} B\uFF09\u2014\u2014\u672A\u5B9E\u9645\u5199\u5165
8924
+ `[dry-run] \u5C06\u5199\u5165 ${path19}\uFF08${Buffer.byteLength(content)} B\uFF09\u2014\u2014\u672A\u5B9E\u9645\u5199\u5165
8905
8925
  ---
8906
8926
  ${content}
8907
8927
  `
@@ -8915,13 +8935,13 @@ ${content}
8915
8935
  let backupState = "unknown";
8916
8936
  let backupWhy;
8917
8937
  try {
8918
- const prev = await getTenantMeta(c.raw(), path18);
8938
+ const prev = await getTenantMeta(c.raw(), path19);
8919
8939
  if (!prev || prev.trim() === "") {
8920
8940
  backupState = "absent";
8921
8941
  } else {
8922
8942
  backupFile = nodePath.join(
8923
8943
  os4.tmpdir(),
8924
- `hcm-meta-backup-${Date.now()}-${path18.replace(/[\\/]/g, "_")}`
8944
+ `hcm-meta-backup-${Date.now()}-${path19.replace(/[\\/]/g, "_")}`
8925
8945
  );
8926
8946
  await fsp3.writeFile(backupFile, prev, "utf8");
8927
8947
  backupState = "saved";
@@ -8936,22 +8956,22 @@ ${content}
8936
8956
  backupWhy = `HTTP ${st ?? "-"}${err.code ? ` ${err.code}` : ""}${err.message ? `\uFF1A${err.message}` : ""}`;
8937
8957
  }
8938
8958
  }
8939
- const result = await saveTenantMeta(c.raw(), path18, content);
8959
+ const result = await saveTenantMeta(c.raw(), path19, content);
8940
8960
  const fmt = args.output ?? "json";
8941
- if (fmt !== "json") process.stdout.write(`\u2705 \u5DF2\u5199\u5165 ${path18}
8961
+ if (fmt !== "json") process.stdout.write(`\u2705 \u5DF2\u5199\u5165 ${path19}
8942
8962
  `);
8943
8963
  const restoreHint = backupState === "saved" && backupFile ? ` \u65E7\u5185\u5BB9\u5DF2\u5B58\uFF1A${backupFile}
8944
- \u653E\u56DE\u53BB\uFF1Ahcm meta set ${path18} --file ${backupFile}${connFlags(args)}
8945
- ` : backupState === "absent" ? ` \u8FD9\u4E00\u5C42\u6B64\u524D\u6CA1\u6709\u8986\u76D6\uFF08\u5DF2\u8BC1\u5B9E\uFF09\uFF0C\u6062\u590D\u5373\u5220\u9664\uFF1Ahcm meta delete ${path18}${connFlags(args)}
8964
+ \u653E\u56DE\u53BB\uFF1Ahcm meta set ${path19} --file ${backupFile}${connFlags(args)}
8965
+ ` : backupState === "absent" ? ` \u8FD9\u4E00\u5C42\u6B64\u524D\u6CA1\u6709\u8986\u76D6\uFF08\u5DF2\u8BC1\u5B9E\uFF09\uFF0C\u6062\u590D\u5373\u5220\u9664\uFF1Ahcm meta delete ${path19}${connFlags(args)}
8946
8966
  ` : ` \u26A0\uFE0F \u65E7\u5185\u5BB9**\u6CA1\u5907\u4EFD\u6210**\uFF08${backupWhy ?? "\u539F\u56E0\u672A\u77E5"}\uFF09\u2014\u2014\u65E2\u4E0D\u77E5\u9053\u6B64\u524D\u6709\u6CA1\u6709\u8986\u76D6\uFF0C\u4E5F\u5C31\u7ED9\u4E0D\u51FA\u6062\u590D\u547D\u4EE4\u3002
8947
- \u5148\u81EA\u5DF1\u8BFB\u4E00\u904D\u786E\u8BA4\uFF1Ahcm meta get ${path18}${connFlags(args)}
8967
+ \u5148\u81EA\u5DF1\u8BFB\u4E00\u904D\u786E\u8BA4\uFF1Ahcm meta get ${path19}${connFlags(args)}
8948
8968
  `;
8949
8969
  if (args.verify === false) {
8950
8970
  process.stderr.write(
8951
8971
  "\u26A0\uFE0F --no-verify\uFF1A**\u6CA1\u6709**\u9A8C\u8FC7\u670D\u52A1\u7AEF\u8BFB\u4E0D\u8BFB\u5F97\u52A8\u8FD9\u4EFD meta\u3002\u300C\u5199\u5165\u6210\u529F\u300D\u53EA\u8BF4\u660E\u5B57\u8282\u6536\u4E0B\u4E86\u3002\n \u81EA\u5DF1\u8865\uFF1Ahcm cache clear-meta <Model> \u540E\u6253\u5F00\u9875\u9762\u770B\u4E00\u773C\u3002\n" + restoreHint
8952
8972
  );
8953
8973
  } else {
8954
- const outcome = await verifyAfterWrite(c, path18);
8974
+ const outcome = await verifyAfterWrite(c, path19);
8955
8975
  if (outcome.status === "broken") {
8956
8976
  const human = explainJacksonError(outcome.raw);
8957
8977
  process.stderr.write(
@@ -8985,19 +9005,19 @@ ${content}
8985
9005
  fail7(e, args);
8986
9006
  }
8987
9007
  }
8988
- async function metaDeleteCommand(path18, args) {
9008
+ async function metaDeleteCommand(path19, args) {
8989
9009
  try {
8990
9010
  if (!args.yes) {
8991
- const ok = await promptConfirm(`\u5C06\u5220\u9664\u5143\u6570\u636E ${path18}\uFF0C\u6B64\u64CD\u4F5C\u4E0D\u53EF\u9006\u3002\u7EE7\u7EED\uFF1F`);
9011
+ const ok = await promptConfirm(`\u5C06\u5220\u9664\u5143\u6570\u636E ${path19}\uFF0C\u6B64\u64CD\u4F5C\u4E0D\u53EF\u9006\u3002\u7EE7\u7EED\uFF1F`);
8992
9012
  if (!ok) {
8993
9013
  process.stderr.write("\u5DF2\u53D6\u6D88\n");
8994
9014
  process.exit(1);
8995
9015
  }
8996
9016
  }
8997
9017
  const c = await client2(args);
8998
- const result = await deleteTenantMeta(c.raw(), path18);
9018
+ const result = await deleteTenantMeta(c.raw(), path19);
8999
9019
  const fmt = args.output ?? "json";
9000
- if (fmt !== "json") process.stdout.write(`\u{1F5D1}\uFE0F \u5DF2\u5220\u9664 ${path18}
9020
+ if (fmt !== "json") process.stdout.write(`\u{1F5D1}\uFE0F \u5DF2\u5220\u9664 ${path19}
9001
9021
  `);
9002
9022
  process.stdout.write(formatObject20(result, { format: fmt }) + "\n");
9003
9023
  process.exitCode = 0;
@@ -9006,7 +9026,7 @@ async function metaDeleteCommand(path18, args) {
9006
9026
  fail7(e, args);
9007
9027
  }
9008
9028
  }
9009
- async function metaValidateCommand(path18, args) {
9029
+ async function metaValidateCommand(path19, args) {
9010
9030
  try {
9011
9031
  if (!args.file) {
9012
9032
  throw new CliError22({
@@ -9021,13 +9041,13 @@ async function metaValidateCommand(path18, args) {
9021
9041
  process.stdin.on("end", () => resolve3(buf));
9022
9042
  process.stdin.on("error", reject);
9023
9043
  }) : await fsp3.readFile(args.file, "utf8");
9024
- const result = validateMetaContent(path18, content);
9044
+ const result = validateMetaContent(path19, content);
9025
9045
  const fmt = args.output ?? "table";
9026
9046
  if (fmt === "json" || fmt === "yaml") {
9027
9047
  process.stdout.write(
9028
9048
  formatObject20(
9029
9049
  {
9030
- path: path18,
9050
+ path: path19,
9031
9051
  kind: result.kind,
9032
9052
  schemaKnown: result.schemaKnown,
9033
9053
  schemaSourceCommit: META_SCHEMA_SOURCE_COMMIT,
@@ -9039,7 +9059,7 @@ async function metaValidateCommand(path18, args) {
9039
9059
  );
9040
9060
  } else {
9041
9061
  process.stdout.write(
9042
- `\u{1F50E} ${path18}\uFF08schema \u7C7B\u578B\uFF1A${result.kind ?? "\u672A\u8BC6\u522B"}\uFF0C\u6765\u6E90 ${META_SCHEMA_SOURCE_COMMIT.slice(0, 8)}\uFF09
9062
+ `\u{1F50E} ${path19}\uFF08schema \u7C7B\u578B\uFF1A${result.kind ?? "\u672A\u8BC6\u522B"}\uFF0C\u6765\u6E90 ${META_SCHEMA_SOURCE_COMMIT.slice(0, 8)}\uFF09
9043
9063
  `
9044
9064
  );
9045
9065
  process.stdout.write(
@@ -11900,6 +11920,9 @@ import path11 from "path";
11900
11920
  import {
11901
11921
  HcmClient as HcmClient22,
11902
11922
  CliError as CliError26,
11923
+ CliErrorCode as CliErrorCode26,
11924
+ loadGlobalConfig as loadGlobalConfig11,
11925
+ resolveEnvContext as resolveEnvContext8,
11903
11926
  fetchReconIdentity as fetchReconIdentity2,
11904
11927
  formatObject as formatObject25,
11905
11928
  httpProbe as httpProbe2,
@@ -11908,8 +11931,8 @@ import {
11908
11931
  runDoctor
11909
11932
  } from "@hcmai/sdk";
11910
11933
  var defaultDeps2 = {
11911
- anchors: async (envName, tenant2, as) => {
11912
- const ctx = await getActiveAuthContextFromCli({ env: envName, as });
11934
+ anchors: async (envName, tenant2, as, project) => {
11935
+ const ctx = await getActiveAuthContextFromCli({ env: envName, as }, { cwd: project });
11913
11936
  const client3 = HcmClient22.fromAuthContext(ctx);
11914
11937
  const probe = httpProbe2(client3.raw(), "default");
11915
11938
  const identity2 = await fetchReconIdentity2(probe, tenant2);
@@ -11943,17 +11966,28 @@ async function runChironDoctor(args, deps = defaultDeps2) {
11943
11966
  return finish(report);
11944
11967
  }
11945
11968
  const names = Object.keys(file.environments);
11969
+ let selectedName = args.env;
11970
+ let explicitSlot;
11946
11971
  if (args.env !== void 0 && !Object.hasOwn(file.environments, args.env)) {
11947
- report.lines.push({
11948
- item: "\u767B\u5F55",
11949
- verdict: "fail",
11950
- detail: `${ENV_FILE} \u91CC\u6CA1\u6709\u73AF\u5883 '${args.env}'\uFF1B\u672C\u9879\u76EE\u6709\uFF1A${names.join(", ")}`,
11951
- nextStep: `\u53BB\u6389 --env \u6838\u5168\u90E8\uFF0C\u6216\u6362\u6210\u4E0A\u9762\u5217\u51FA\u7684\u540D\u5B57`
11952
- });
11953
- return finish(report);
11972
+ try {
11973
+ explicitSlot = await resolveEnvContext8({ envFlag: args.env, cwd: root }, process.env, await loadGlobalConfig11());
11974
+ if (!explicitSlot.project) throw new CliError26({
11975
+ code: CliErrorCode26.INVALID_ARGUMENT,
11976
+ message: `\u672C\u673A\u69FD '${args.env}' \u7684\u5730\u5740\u6216\u79DF\u6237\u4E0D\u5339\u914D\u672C\u9879\u76EE\uFF1B\u672C\u9879\u76EE\u6709\uFF1A${names.join(", ")}`
11977
+ });
11978
+ selectedName = explicitSlot.project.name;
11979
+ } catch (e) {
11980
+ report.lines.push({
11981
+ item: "\u767B\u5F55",
11982
+ verdict: "fail",
11983
+ detail: e.message,
11984
+ nextStep: `\u53BB\u6389 --env \u6838\u5168\u90E8\uFF0C\u6216\u7528 --env <\u9879\u76EE\u73AF\u5883\u540D> \u9009\u62E9\uFF1A${names.join(", ")}`
11985
+ });
11986
+ return finish(report);
11987
+ }
11954
11988
  }
11955
- const targets = args.env !== void 0 ? [args.env] : names;
11956
- const env2 = file.environments[file.default] ?? file.environments[targets[0]];
11989
+ const targets = selectedName !== void 0 ? [selectedName] : names;
11990
+ const env2 = file.environments[selectedName ?? file.default];
11957
11991
  report.env = env2;
11958
11992
  report.environments = names;
11959
11993
  report.defaultEnv = file.default;
@@ -11963,16 +11997,16 @@ async function runChironDoctor(args, deps = defaultDeps2) {
11963
11997
  const selected = isDefault || args.env !== void 0;
11964
11998
  const severity = () => selected ? "fail" : "warn";
11965
11999
  const label = `${name}${isDefault ? "\uFF08default\uFF09" : ""}${env3.danger ? " \xB7 danger" : ""}`;
11966
- const found = await findEnvByEndpoint3(env3.endpoint, env3.tenant);
11967
- const loginCmd = names.length > 1 ? `hcm login --env ${name}` : `hcm login ${env3.endpoint}`;
12000
+ const found = explicitSlot ?? await findEnvByEndpoint3(env3.endpoint, env3.tenant);
12001
+ const loginCmd = args.env !== void 0 ? `hcm login --env ${args.env}` : isDefault && process.env.HCM_ENV === void 0 && process.env.HCM_PROFILE === void 0 ? "hcm login" : `hcm login --env ${name}`;
11968
12002
  if (!found) {
11969
12003
  report.lines.push({ item: "\u767B\u5F55", verdict: severity(), detail: `${label} \xB7 \u672C\u673A\u6CA1\u6709\u767B\u5F55\u8FC7 ${env3.endpoint}`, nextStep: loginCmd });
11970
12004
  continue;
11971
12005
  }
11972
12006
  if (selected) report.envName = found.name;
11973
12007
  try {
11974
- const targetEnv = name;
11975
- const { report: anchors, tokenTenant: tokenTenant2 } = await deps.anchors(targetEnv, env3.tenant, args.as);
12008
+ const targetEnv = explicitSlot?.name ?? name;
12009
+ const { report: anchors, tokenTenant: tokenTenant2 } = await deps.anchors(targetEnv, env3.tenant, args.as, root);
11976
12010
  if (selected) report.anchors = anchors;
11977
12011
  (report.environmentAnchors ??= {})[name] = anchors;
11978
12012
  const tenantMismatch = tokenTenant2 && tokenTenant2 !== env3.tenant;
@@ -11996,6 +12030,8 @@ async function runChironDoctor(args, deps = defaultDeps2) {
11996
12030
  report.lines.push({ item: "\u767B\u5F55", verdict: severity(), detail: `${label} \xB7 \u672C\u673A\u69FD ${found.name} \xB7 ${env3.endpoint}\uFF1A${msg}`, nextStep: loginCmd });
11997
12031
  }
11998
12032
  }
12033
+ const skillsEnv = args.env ?? (process.env.HCM_ENV !== void 0 || process.env.HCM_PROFILE !== void 0 ? file.default : void 0);
12034
+ const skillsEnvOption = skillsEnv === void 0 ? "" : `--env ${skillsEnv}`;
11999
12035
  const skillsLine = async () => {
12000
12036
  const state = await readSkillsState(skillsSyncDir(root));
12001
12037
  if (!state) {
@@ -12005,22 +12041,22 @@ async function runChironDoctor(args, deps = defaultDeps2) {
12005
12041
  item: "\u6280\u80FD",
12006
12042
  verdict: "warn",
12007
12043
  detail: `${Object.keys(legacy.skills).length} \u4E2A\uFF0C\u4F46\u8FD8\u662F 0.14.0 \u4E4B\u524D\u7684\u6241\u5E73\u5E03\u5C40\uFF08\u6E05\u5355\u5728 ${SKILLS_DIR}/\uFF0C\u4EA7\u54C1\u90A3\u4E00\u534A\u5E94\u8BE5\u5728 ${SKILLS_DIR}/${SKILLS_SYNC_SUBDIR}/\uFF09`,
12008
- nextStep: "hcm chiron skills sync \u5C31\u5730\u5206\u6210\u4E24\u534A\uFF08\u5E42\u7B49\uFF0C\u4E0D\u4F1A\u91CD\u88C5\uFF09"
12044
+ nextStep: `hcm chiron skills sync ${skillsEnvOption} \u5C31\u5730\u5206\u6210\u4E24\u534A\uFF08\u5E42\u7B49\uFF0C\u4E0D\u4F1A\u91CD\u88C5\uFF09`
12009
12045
  };
12010
12046
  }
12011
12047
  return {
12012
12048
  item: "\u6280\u80FD",
12013
12049
  verdict: "fail",
12014
12050
  detail: `${SKILLS_DIR}/${SKILLS_SYNC_SUBDIR}/ \u91CC\u6CA1\u6709\u5B89\u88C5\u6E05\u5355`,
12015
- nextStep: "hcm chiron skills sync"
12051
+ nextStep: `hcm chiron skills sync ${skillsEnvOption}`.trimEnd()
12016
12052
  };
12017
12053
  }
12018
12054
  const count = Object.keys(state.skills).length;
12019
12055
  if (state.endpoint && normalizeOrigin3(state.endpoint) !== env2.endpoint) {
12020
- return { item: "\u6280\u80FD", verdict: "fail", detail: `${count} \u4E2A\uFF0C\u4F46\u88C5\u81EA ${state.endpoint}\uFF0C\u4E0D\u662F\u9879\u76EE\u73AF\u5883 ${env2.endpoint}`, nextStep: "hcm chiron skills sync \u91CD\u88C5\uFF08\u5B83\u4F1A\u6309\u9879\u76EE\u73AF\u5883\u91CD\u65B0\u5BF9\u8D26\uFF09" };
12056
+ return { item: "\u6280\u80FD", verdict: "fail", detail: `${count} \u4E2A\uFF0C\u4F46\u88C5\u81EA ${state.endpoint}\uFF0C\u4E0D\u662F\u9879\u76EE\u73AF\u5883 ${env2.endpoint}`, nextStep: `hcm chiron skills sync ${skillsEnvOption} \u91CD\u88C5\uFF08\u5B83\u4F1A\u6309\u9879\u76EE\u73AF\u5883\u91CD\u65B0\u5BF9\u8D26\uFF09` };
12021
12057
  }
12022
12058
  if (state.target !== "codex") {
12023
- return { item: "\u6280\u80FD", verdict: "warn", detail: `${count} \u4E2A\uFF0C\u5E03\u5C40\u662F ${state.target}\uFF08Codex \u8981\u8BFB AGENTS.md \u7D22\u5F15\uFF09`, nextStep: "hcm chiron skills sync --target codex" };
12059
+ return { item: "\u6280\u80FD", verdict: "warn", detail: `${count} \u4E2A\uFF0C\u5E03\u5C40\u662F ${state.target}\uFF08Codex \u8981\u8BFB AGENTS.md \u7D22\u5F15\uFF09`, nextStep: `hcm chiron skills sync ${skillsEnvOption} --target codex` };
12024
12060
  }
12025
12061
  return { item: "\u6280\u80FD", verdict: "ok", detail: `${count} \u4E2A\uFF0C\u6765\u81EA ${state.endpoint ?? "\u672C\u5730"}${state.all ? "\uFF0C\u8DDF\u968F\u5168\u96C6" : ""}` };
12026
12062
  };
@@ -12046,7 +12082,7 @@ function finish(report) {
12046
12082
  }
12047
12083
  function renderChironDoctor(report) {
12048
12084
  const mark = { ok: "\u2705", warn: "\u26A0\uFE0F", fail: "\u274C" };
12049
- const out = [];
12085
+ const out = [`\u9879\u76EE\u76EE\u5F55\uFF1A${report.project}\uFF08\u4E0B\u4E00\u6B65\u547D\u4EE4\u5728\u6B64\u76EE\u5F55\u6267\u884C\uFF09`];
12050
12086
  for (const l of report.lines) {
12051
12087
  out.push(`${mark[l.verdict]} ${l.item.padEnd(3, "\u3000")} ${l.detail}`);
12052
12088
  if (l.nextStep && l.verdict !== "ok") out.push(` \u2192 ${l.nextStep}`);
@@ -12082,7 +12118,7 @@ import yaml from "js-yaml";
12082
12118
  import {
12083
12119
  AUTH_INFO_PATH as AUTH_INFO_PATH2,
12084
12120
  CliError as CliError27,
12085
- CliErrorCode as CliErrorCode26,
12121
+ CliErrorCode as CliErrorCode27,
12086
12122
  discoverProjectEnv as discoverProjectEnv6,
12087
12123
  ENV_FILE as ENV_FILE2,
12088
12124
  findEnvByEndpoint as findEnvByEndpoint5,
@@ -12105,7 +12141,7 @@ function summarizeReasons(reasons) {
12105
12141
  return reasons.length === 1 ? reasons[0] : `${reasons[0]} \u7B49 ${reasons.length} \u6761\uFF08--output json \u770B\u5168\u90E8\uFF09`;
12106
12142
  }
12107
12143
  function invalid2(message, nextStep) {
12108
- throw new CliError27({ code: CliErrorCode26.INVALID_ARGUMENT, message, context: { nextStep } });
12144
+ throw new CliError27({ code: CliErrorCode27.INVALID_ARGUMENT, message, context: { nextStep } });
12109
12145
  }
12110
12146
  function required(value, label) {
12111
12147
  if (!value?.trim()) invalid2(`${label} \u4E0D\u80FD\u4E3A\u7A7A\uFF1B\u914D\u7F6E\u672A\u5199\u5165\u3002`, `\u8BF7\u63D0\u4F9B\u975E\u7A7A\u7684 ${label}`);
@@ -12319,10 +12355,360 @@ async function chironEnvCommand(action, args) {
12319
12355
  init_auth_guard();
12320
12356
  init_exit();
12321
12357
  import { spawnSync } from "child_process";
12322
- import { accessSync, constants } from "fs";
12358
+ import { accessSync, constants, readdirSync as readdirSync3 } from "fs";
12323
12359
  import fs12 from "fs/promises";
12360
+ import os5 from "os";
12361
+ import path14 from "path";
12362
+ import { CliError as CliError30, CliErrorCode as CliErrorCode30, formatObject as formatObject27, HcmClient as HcmClient23, loadEnv as loadEnv6 } from "@hcmai/sdk";
12363
+ import { createRequire } from "module";
12364
+
12365
+ // src/commands/chiron-page-cdp.ts
12366
+ import { CliError as CliError28, CliErrorCode as CliErrorCode28 } from "@hcmai/sdk";
12367
+
12368
+ // src/commands/chiron-page-shared.ts
12369
+ function redactTicket(text) {
12370
+ return text.replace(/(ticket=)[^&\s"']+/g, "$1<redacted>");
12371
+ }
12372
+ function toPlainJson(value) {
12373
+ if (value === void 0) return void 0;
12374
+ const seen = /* @__PURE__ */ new WeakSet();
12375
+ const text = JSON.stringify(value, (_k, v) => {
12376
+ if (typeof v === "bigint") return v.toString();
12377
+ if (v && typeof v === "object") {
12378
+ if (seen.has(v)) return "[Circular]";
12379
+ seen.add(v);
12380
+ }
12381
+ return v;
12382
+ });
12383
+ if (text === void 0) return void 0;
12384
+ return JSON.parse(redactTicket(text));
12385
+ }
12386
+ function wrapEvalBody(body) {
12387
+ return `(async () => {
12388
+ ${body}
12389
+ })()`;
12390
+ }
12391
+
12392
+ // src/commands/chiron-page-cdp.ts
12393
+ function normalizeCdpEndpoint(raw) {
12394
+ const text = raw?.trim();
12395
+ if (!text) return null;
12396
+ let candidate = text;
12397
+ if (!/^[a-z]+:\/\//i.test(candidate)) candidate = `http://${candidate}`;
12398
+ let url;
12399
+ try {
12400
+ url = new URL(candidate);
12401
+ } catch {
12402
+ throw new CliError28({ code: CliErrorCode28.INVALID_ARGUMENT, message: `--cdp \u8981\u5199\u6210 http://\u4E3B\u673A:\u7AEF\u53E3\uFF08Chrome \u7684 --remote-debugging-port\uFF09\uFF0C\u6536\u5230\u7684\u662F ${text}` });
12403
+ }
12404
+ const protocol = url.protocol === "wss:" ? "https:" : url.protocol === "ws:" ? "http:" : url.protocol;
12405
+ if (protocol !== "http:" && protocol !== "https:") {
12406
+ throw new CliError28({ code: CliErrorCode28.INVALID_ARGUMENT, message: `--cdp \u53EA\u8BA4 http(s) \u6216 ws(s) \u7AEF\u70B9\uFF0C\u6536\u5230\u7684\u662F ${text}` });
12407
+ }
12408
+ if (!url.port) {
12409
+ throw new CliError28({ code: CliErrorCode28.INVALID_ARGUMENT, message: `--cdp \u8981\u5E26\u7AEF\u53E3\uFF08Chrome \u542F\u52A8\u65F6 --remote-debugging-port=<\u7AEF\u53E3> \u7684\u90A3\u4E2A\uFF09\uFF0C\u6536\u5230\u7684\u662F ${text}` });
12410
+ }
12411
+ return `${protocol}//${url.hostname}:${url.port}`;
12412
+ }
12413
+ var CdpSession = class {
12414
+ constructor(socket) {
12415
+ this.socket = socket;
12416
+ socket.addEventListener("message", (ev) => this.onMessage(typeof ev.data === "string" ? ev.data : String(ev.data)));
12417
+ socket.addEventListener("close", () => this.failAll(new Error("CDP socket \u5DF2\u5173\u95ED")));
12418
+ socket.addEventListener("error", (ev) => this.failAll(new Error(`CDP socket \u51FA\u9519\uFF1A${describe(ev)}`)));
12419
+ }
12420
+ socket;
12421
+ nextId = 1;
12422
+ pending = /* @__PURE__ */ new Map();
12423
+ listeners = /* @__PURE__ */ new Map();
12424
+ closed = false;
12425
+ send(method, params = {}) {
12426
+ if (this.closed) return Promise.reject(new Error(`CDP socket \u5DF2\u5173\u95ED\uFF0C\u53D1\u4E0D\u4E86 ${method}`));
12427
+ const id = this.nextId++;
12428
+ return new Promise((resolve3, reject) => {
12429
+ this.pending.set(id, { resolve: resolve3, reject, method });
12430
+ this.socket.send(JSON.stringify({ id, method, params }));
12431
+ });
12432
+ }
12433
+ on(event, listener) {
12434
+ const list = this.listeners.get(event) ?? [];
12435
+ list.push(listener);
12436
+ this.listeners.set(event, list);
12437
+ return () => {
12438
+ const cur = this.listeners.get(event) ?? [];
12439
+ const i = cur.indexOf(listener);
12440
+ if (i >= 0) cur.splice(i, 1);
12441
+ };
12442
+ }
12443
+ /** 事件监听器数(测试用:确认 waitFor 结束后不留监听器)。 */
12444
+ listenerCount(event) {
12445
+ return (this.listeners.get(event) ?? []).length;
12446
+ }
12447
+ /** 等一个事件,超时就 reject——「等 load 事件」不能无限等。无论哪种结束都摘掉监听器。 */
12448
+ waitFor(event, timeoutMs) {
12449
+ return new Promise((resolve3, reject) => {
12450
+ const off = this.on(event, (params) => {
12451
+ clearTimeout(timer);
12452
+ off();
12453
+ resolve3(params);
12454
+ });
12455
+ const timer = setTimeout(() => {
12456
+ off();
12457
+ reject(new Error(`\u7B49 ${event} \u8D85\u8FC7 ${timeoutMs}ms`));
12458
+ }, timeoutMs);
12459
+ });
12460
+ }
12461
+ close() {
12462
+ this.closed = true;
12463
+ try {
12464
+ this.socket.close();
12465
+ } catch {
12466
+ }
12467
+ this.failAll(new Error("CDP socket \u5DF2\u5173\u95ED"));
12468
+ }
12469
+ onMessage(raw) {
12470
+ let msg;
12471
+ try {
12472
+ msg = JSON.parse(raw);
12473
+ } catch {
12474
+ return;
12475
+ }
12476
+ if (typeof msg.id === "number") {
12477
+ const p = this.pending.get(msg.id);
12478
+ if (!p) return;
12479
+ this.pending.delete(msg.id);
12480
+ if (msg.error) p.reject(new Error(`${p.method} \u88AB Chrome \u62D2\u7EDD\uFF1A${msg.error.message ?? JSON.stringify(msg.error)}`));
12481
+ else p.resolve(msg.result);
12482
+ return;
12483
+ }
12484
+ if (msg.method) {
12485
+ for (const l of [...this.listeners.get(msg.method) ?? []]) l(msg.params);
12486
+ }
12487
+ }
12488
+ failAll(err) {
12489
+ for (const [id, p] of this.pending) {
12490
+ this.pending.delete(id);
12491
+ p.reject(err);
12492
+ }
12493
+ }
12494
+ };
12495
+ function describe(ev) {
12496
+ if (ev && typeof ev === "object" && "message" in ev) return String(ev.message);
12497
+ return String(ev);
12498
+ }
12499
+ var LOAD_WAIT_MS = 15e3;
12500
+ var CDP_IO_TIMEOUT_MS = 1e4;
12501
+ async function captureViaCdp(input, io) {
12502
+ const version = await io.fetchJson(`${input.endpoint}/json/version`, "GET");
12503
+ const browser = version?.Browser ? String(version.Browser) : `attached ${input.endpoint}`;
12504
+ const target = await io.fetchJson(`${input.endpoint}/json/new?about:blank`, "PUT");
12505
+ if (!target?.id || !target.webSocketDebuggerUrl) {
12506
+ throw new CliError28({
12507
+ code: CliErrorCode28.SERVER_ERROR,
12508
+ message: `${input.endpoint}/json/new \u6CA1\u6709\u7ED9\u51FA\u6807\u7B7E\u9875\uFF08id / webSocketDebuggerUrl \u7F3A\u5931\uFF09`,
12509
+ context: { nextStep: "\u786E\u8BA4 Chrome \u662F\u5E26 --remote-debugging-port \u8D77\u7684\uFF0C\u4E14 --cdp \u6307\u5230\u7684\u662F\u5B83" }
12510
+ });
12511
+ }
12512
+ let session = null;
12513
+ try {
12514
+ session = new CdpSession(await io.openSocket(target.webSocketDebuggerUrl));
12515
+ await session.send("Emulation.setDeviceMetricsOverride", {
12516
+ width: input.viewport.width,
12517
+ height: input.viewport.height,
12518
+ deviceScaleFactor: 1,
12519
+ mobile: false
12520
+ });
12521
+ await session.send("Page.enable");
12522
+ await session.send("Runtime.enable");
12523
+ const minted = await input.mintUrl();
12524
+ const loaded = session.waitFor("Page.loadEventFired", LOAD_WAIT_MS).then(() => true, () => false);
12525
+ await session.send("Page.navigate", { url: minted.url });
12526
+ const navigated = await loaded;
12527
+ if (input.waitMs > 0) await io.sleep(input.waitMs);
12528
+ let evalResult;
12529
+ if (input.evalJs?.trim()) {
12530
+ const r = await session.send("Runtime.evaluate", {
12531
+ expression: wrapEvalBody(input.evalJs),
12532
+ awaitPromise: true,
12533
+ returnByValue: true
12534
+ });
12535
+ if (r.exceptionDetails) {
12536
+ const why = r.exceptionDetails.exception?.description ?? r.exceptionDetails.text ?? "unknown";
12537
+ throw new CliError28({ code: CliErrorCode28.INVALID_ARGUMENT, message: `--eval \u5728\u9875\u9762\u91CC\u629B\u4E86\u5F02\u5E38\uFF1A${redactTicket(why.split("\n")[0] ?? why)}` });
12538
+ }
12539
+ evalResult = r.result && "value" in r.result ? toPlainJson(r.result.value) : toPlainJson(r.result?.description);
12540
+ }
12541
+ const domReply = await session.send("Runtime.evaluate", {
12542
+ expression: "document.documentElement.outerHTML",
12543
+ returnByValue: true
12544
+ });
12545
+ const dom = typeof domReply.result?.value === "string" ? domReply.result.value : "";
12546
+ const shot = await session.send("Page.captureScreenshot", { format: "png" });
12547
+ if (!shot.data) {
12548
+ throw new CliError28({ code: CliErrorCode28.SERVER_ERROR, message: "Page.captureScreenshot \u6CA1\u6709\u8FD4\u56DE\u56FE\u50CF\u6570\u636E" });
12549
+ }
12550
+ await io.writeFile(input.screenshot, Buffer.from(shot.data, "base64"));
12551
+ return { dom, browser, evalResult, navigated, minted };
12552
+ } finally {
12553
+ session?.close();
12554
+ try {
12555
+ await io.fetchJson(`${input.endpoint}/json/close/${target.id}`, "GET");
12556
+ } catch {
12557
+ }
12558
+ }
12559
+ }
12560
+ var defaultCdpIo = {
12561
+ fetchJson: async (url, method) => {
12562
+ const res = await fetch(url, { method, signal: AbortSignal.timeout(CDP_IO_TIMEOUT_MS) });
12563
+ if (!res.ok) throw new Error(`${method} ${url} \u2192 HTTP ${res.status}`);
12564
+ const text = await res.text();
12565
+ return text ? JSON.parse(text) : null;
12566
+ },
12567
+ openSocket: (wsUrl) => new Promise((resolve3, reject) => {
12568
+ const Ctor = globalThis.WebSocket;
12569
+ if (!Ctor) {
12570
+ reject(new CliError28({ code: CliErrorCode28.SERVER_ERROR, message: "\u8FD9\u4E2A Node \u6CA1\u6709\u5168\u5C40 WebSocket\uFF08\u9700\u8981 Node \u2265 22.4\uFF1B22.0\u201322.3 \u8981\u52A0 --experimental-websocket\uFF09" }));
12571
+ return;
12572
+ }
12573
+ const ws = new Ctor(wsUrl);
12574
+ const timer = setTimeout(() => reject(new Error(`\u8FDE ${wsUrl} \u8D85\u8FC7 ${CDP_IO_TIMEOUT_MS}ms \u6CA1\u63E1\u4E0A\u624B`)), CDP_IO_TIMEOUT_MS);
12575
+ ws.addEventListener("open", () => {
12576
+ clearTimeout(timer);
12577
+ resolve3(ws);
12578
+ });
12579
+ ws.addEventListener("error", (ev) => {
12580
+ clearTimeout(timer);
12581
+ reject(new Error(`\u8FDE\u4E0D\u4E0A ${wsUrl}\uFF1A${describe(ev)}`));
12582
+ });
12583
+ }),
12584
+ writeFile: async (file, bytes) => {
12585
+ const fs14 = await import("fs/promises");
12586
+ await fs14.writeFile(file, bytes);
12587
+ },
12588
+ sleep: (ms) => new Promise((r) => setTimeout(r, ms))
12589
+ };
12590
+
12591
+ // src/commands/chiron-page-playwright.ts
12324
12592
  import path13 from "path";
12325
- import { CliError as CliError28, CliErrorCode as CliErrorCode27, formatObject as formatObject27, HcmClient as HcmClient23, loadEnv as loadEnv6 } from "@hcmai/sdk";
12593
+ import { CliError as CliError29, CliErrorCode as CliErrorCode29 } from "@hcmai/sdk";
12594
+ function playwrightCacheRoot(probe) {
12595
+ const override = probe.env.PLAYWRIGHT_BROWSERS_PATH?.trim();
12596
+ if (override === "0" && probe.packageRoot) return path13.join(probe.packageRoot, ".local-browsers");
12597
+ if (override && override !== "0") return path13.resolve(override);
12598
+ if (probe.platform === "darwin") return path13.join(probe.homedir(), "Library", "Caches", "ms-playwright");
12599
+ if (probe.platform === "win32") {
12600
+ return path13.join(probe.env.LOCALAPPDATA?.trim() || path13.join(probe.homedir(), "AppData", "Local"), "ms-playwright");
12601
+ }
12602
+ return path13.join(probe.env.XDG_CACHE_HOME?.trim() || path13.join(probe.homedir(), ".cache"), "ms-playwright");
12603
+ }
12604
+ function playwrightPlatformTag(probe) {
12605
+ const arm = probe.arch === "arm64";
12606
+ if (probe.platform === "darwin") return arm ? "mac-arm64" : "mac-x64";
12607
+ if (probe.platform === "win32") return "win64";
12608
+ return arm ? "linux-arm64" : "linux64";
12609
+ }
12610
+ function revisionOf(entry, prefix) {
12611
+ if (!entry.startsWith(prefix)) return null;
12612
+ const rev = Number(entry.slice(prefix.length));
12613
+ return Number.isInteger(rev) ? rev : null;
12614
+ }
12615
+ function candidateBinaries(probe, kind) {
12616
+ const tag = playwrightPlatformTag(probe);
12617
+ if (kind === "headless-shell") {
12618
+ return [path13.join(`chrome-headless-shell-${tag}`, probe.platform === "win32" ? "chrome-headless-shell.exe" : "chrome-headless-shell")];
12619
+ }
12620
+ if (probe.platform === "darwin") {
12621
+ return [
12622
+ // Playwright ≥ 1.49:Chrome for Testing 的 .app
12623
+ path13.join(`chrome-${tag}`, "Google Chrome for Testing.app", "Contents", "MacOS", "Google Chrome for Testing"),
12624
+ // ≤ 1.48:Chromium.app,目录名不分架构
12625
+ path13.join("chrome-mac", "Chromium.app", "Contents", "MacOS", "Chromium"),
12626
+ path13.join(`chrome-${tag}`, "Chromium.app", "Contents", "MacOS", "Chromium")
12627
+ ];
12628
+ }
12629
+ if (probe.platform === "win32") return [path13.join("chrome-win64", "chrome.exe"), path13.join("chrome-win", "chrome.exe")];
12630
+ return [path13.join(`chrome-${tag}`, "chrome"), path13.join("chrome-linux", "chrome")];
12631
+ }
12632
+ function discoverPlaywrightBrowser(probe) {
12633
+ const explicit = probe.env.HCM_PLAYWRIGHT_EXECUTABLE?.trim();
12634
+ if (explicit) {
12635
+ if (probe.executable(explicit)) return { executablePath: explicit, kind: "explicit", from: "HCM_PLAYWRIGHT_EXECUTABLE" };
12636
+ throw new CliError29({
12637
+ code: CliErrorCode29.INVALID_ARGUMENT,
12638
+ message: `HCM_PLAYWRIGHT_EXECUTABLE \u6307\u7684\u6587\u4EF6\u4E0D\u53EF\u6267\u884C\uFF1A${explicit}`,
12639
+ context: { nextStep: "\u6307\u5230 Playwright \u88C5\u7684 chrome-headless-shell / chrome \u4E8C\u8FDB\u5236\uFF0C\u6216\u53BB\u6389\u8FD9\u4E2A\u53D8\u91CF\u8BA9 CLI \u81EA\u5DF1\u627E" }
12640
+ });
12641
+ }
12642
+ const root = playwrightCacheRoot(probe);
12643
+ const entries = probe.readdir(root);
12644
+ const pick2 = (prefix, kind) => {
12645
+ const revisions = entries.map((e) => ({ e, rev: revisionOf(e, prefix) })).filter((x) => x.rev !== null).sort((a, b) => b.rev - a.rev);
12646
+ for (const { e } of revisions) {
12647
+ for (const rel of candidateBinaries(probe, kind)) {
12648
+ const candidate = path13.join(root, e, rel);
12649
+ if (probe.executable(candidate)) return { executablePath: candidate, kind, from: path13.join(root, e) };
12650
+ }
12651
+ }
12652
+ return null;
12653
+ };
12654
+ return pick2("chromium_headless_shell-", "headless-shell") ?? pick2("chromium-", "chromium");
12655
+ }
12656
+ var PW_LOAD_WAIT_MS = 15e3;
12657
+ async function loadPlaywright() {
12658
+ return import("playwright-core");
12659
+ }
12660
+ async function captureViaPlaywright(input) {
12661
+ const pw = await loadPlaywright();
12662
+ const attempts = [];
12663
+ if (input.browser) attempts.push({ label: `${input.browser.kind} @ ${input.browser.from}`, options: { headless: true, executablePath: input.browser.executablePath } });
12664
+ attempts.push({ label: "playwright default", options: { headless: true } });
12665
+ attempts.push({ label: "channel=chrome", options: { headless: true, channel: "chrome" } });
12666
+ const failures = [];
12667
+ let browser = null;
12668
+ let used = "";
12669
+ for (const a of attempts) {
12670
+ try {
12671
+ browser = await pw.chromium.launch({ ...a.options, args: ["--disable-gpu", "--disable-dev-shm-usage", "--hide-scrollbars"] });
12672
+ used = a.label;
12673
+ break;
12674
+ } catch (e) {
12675
+ failures.push(`${a.label}: ${(e instanceof Error ? e.message : String(e)).split("\n")[0]}`);
12676
+ }
12677
+ }
12678
+ if (!browser) {
12679
+ throw new CliError29({
12680
+ code: CliErrorCode29.SERVER_ERROR,
12681
+ message: `Playwright \u8D77\u4E0D\u4E86\u6D4F\u89C8\u5668\uFF1A${failures.join("\uFF1B")}`,
12682
+ context: {
12683
+ nextStep: "\u88C5\u4E00\u4EFD Playwright \u7684 Chromium\uFF1Anpx playwright install chromium-headless-shell\uFF08\u6216 chromium\uFF09\uFF1B\u5DF2\u7ECF\u88C5\u4E86\u4F46\u4E0D\u5728\u7F3A\u7701\u7F13\u5B58\u76EE\u5F55\u5C31 export PLAYWRIGHT_BROWSERS_PATH=<\u76EE\u5F55> \u6216 HCM_PLAYWRIGHT_EXECUTABLE=<\u4E8C\u8FDB\u5236>\uFF1B\u6C99\u7BB1\u8FDE headless shell \u90FD\u8D77\u4E0D\u4E86\u65F6\uFF0C\u5728\u6C99\u7BB1\u5916\u8D77 Chrome \u5E76\u7528 --cdp \u8FDE"
12684
+ }
12685
+ });
12686
+ }
12687
+ const browserLabel = `${browser.version()} via playwright (${used})`;
12688
+ try {
12689
+ const context = await browser.newContext({ viewport: input.viewport, deviceScaleFactor: 1 });
12690
+ const page = await context.newPage();
12691
+ const minted = await input.mintUrl();
12692
+ const navigated = await page.goto(minted.url, { waitUntil: "load", timeout: PW_LOAD_WAIT_MS }).then(() => true, () => false);
12693
+ if (input.waitMs > 0) await page.waitForTimeout(input.waitMs);
12694
+ let evalResult;
12695
+ if (input.evalJs?.trim()) {
12696
+ try {
12697
+ evalResult = toPlainJson(await page.evaluate(wrapEvalBody(input.evalJs)));
12698
+ } catch (e) {
12699
+ const why = (e instanceof Error ? e.message : String(e)).split("\n")[0] ?? "";
12700
+ throw new CliError29({ code: CliErrorCode29.INVALID_ARGUMENT, message: `--eval \u5728\u9875\u9762\u91CC\u629B\u4E86\u5F02\u5E38\uFF1A${redactTicket(why)}` });
12701
+ }
12702
+ }
12703
+ const dom = await page.content();
12704
+ await page.screenshot({ path: input.screenshot, fullPage: false });
12705
+ return { dom, browser: browserLabel, evalResult, navigated, minted };
12706
+ } finally {
12707
+ await browser.close().catch(() => void 0);
12708
+ }
12709
+ }
12710
+
12711
+ // src/commands/chiron-page.ts
12326
12712
  var EVIDENCE_DIR = "evidence";
12327
12713
  var WAIT_MS_MAX = 6e4;
12328
12714
  var VIEWPORT_MIN = { width: 320, height: 240 };
@@ -12335,13 +12721,13 @@ function judgePageContent(input) {
12335
12721
  function parseViewport(size) {
12336
12722
  const m = /^(\d+)x(\d+)$/.exec(size.trim());
12337
12723
  if (!m) {
12338
- throw new CliError28({ code: CliErrorCode27.INVALID_ARGUMENT, message: `--size \u8981\u5199\u6210 <\u5BBD>x<\u9AD8>\uFF0C\u4F8B\u5982 1440x900\uFF0C\u6536\u5230\u7684\u662F ${size}` });
12724
+ throw new CliError30({ code: CliErrorCode30.INVALID_ARGUMENT, message: `--size \u8981\u5199\u6210 <\u5BBD>x<\u9AD8>\uFF0C\u4F8B\u5982 1440x900\uFF0C\u6536\u5230\u7684\u662F ${size}` });
12339
12725
  }
12340
12726
  const width = Number(m[1]);
12341
12727
  const height = Number(m[2]);
12342
12728
  if (width < VIEWPORT_MIN.width || width > VIEWPORT_MAX.width || height < VIEWPORT_MIN.height || height > VIEWPORT_MAX.height) {
12343
- throw new CliError28({
12344
- code: CliErrorCode27.INVALID_ARGUMENT,
12729
+ throw new CliError30({
12730
+ code: CliErrorCode30.INVALID_ARGUMENT,
12345
12731
  message: `--size \u8D85\u51FA\u8303\u56F4\uFF1A\u5BBD ${VIEWPORT_MIN.width}..${VIEWPORT_MAX.width}\u3001\u9AD8 ${VIEWPORT_MIN.height}..${VIEWPORT_MAX.height}\uFF0C\u6536\u5230\u7684\u662F ${size}`
12346
12732
  });
12347
12733
  }
@@ -12351,23 +12737,23 @@ function parseWaitMs(raw) {
12351
12737
  if (raw === void 0) return 1e4;
12352
12738
  const value = typeof raw === "number" ? raw : Number(raw);
12353
12739
  if (!Number.isInteger(value) || value < 0 || value > WAIT_MS_MAX) {
12354
- throw new CliError28({ code: CliErrorCode27.INVALID_ARGUMENT, message: `--wait-ms \u8981\u662F 0..${WAIT_MS_MAX} \u7684\u6574\u6570\uFF0C\u6536\u5230\u7684\u662F ${raw}` });
12740
+ throw new CliError30({ code: CliErrorCode30.INVALID_ARGUMENT, message: `--wait-ms \u8981\u662F 0..${WAIT_MS_MAX} \u7684\u6574\u6570\uFF0C\u6536\u5230\u7684\u662F ${raw}` });
12355
12741
  }
12356
12742
  return value;
12357
12743
  }
12358
12744
  function resolveEvidenceTarget(projectRoot, out) {
12359
12745
  if (!out?.trim()) {
12360
- throw new CliError28({ code: CliErrorCode27.MISSING_FLAG, message: `\u8981\u4F20 --out <${EVIDENCE_DIR}/\u2026/\u622A\u56FE.png>\uFF1A\u622A\u56FE\u843D\u5728\u54EA\u513F\u5FC5\u987B\u662F\u4F60\u5B9A\u7684\uFF0C\u4E0D\u7531\u547D\u4EE4\u731C` });
12746
+ throw new CliError30({ code: CliErrorCode30.MISSING_FLAG, message: `\u8981\u4F20 --out <${EVIDENCE_DIR}/\u2026/\u622A\u56FE.png>\uFF1A\u622A\u56FE\u843D\u5728\u54EA\u513F\u5FC5\u987B\u662F\u4F60\u5B9A\u7684\uFF0C\u4E0D\u7531\u547D\u4EE4\u731C` });
12361
12747
  }
12362
12748
  if (!out.endsWith(".png")) {
12363
- throw new CliError28({ code: CliErrorCode27.INVALID_ARGUMENT, message: `--out \u8981\u4EE5 .png \u7ED3\u5C3E\uFF0C\u6536\u5230\u7684\u662F ${out}` });
12364
- }
12365
- const root = path13.resolve(projectRoot);
12366
- const evidenceRoot = path13.join(root, EVIDENCE_DIR);
12367
- const absolute = path13.resolve(root, out);
12368
- if (absolute !== evidenceRoot && !absolute.startsWith(evidenceRoot + path13.sep)) {
12369
- throw new CliError28({
12370
- code: CliErrorCode27.INVALID_ARGUMENT,
12749
+ throw new CliError30({ code: CliErrorCode30.INVALID_ARGUMENT, message: `--out \u8981\u4EE5 .png \u7ED3\u5C3E\uFF0C\u6536\u5230\u7684\u662F ${out}` });
12750
+ }
12751
+ const root = path14.resolve(projectRoot);
12752
+ const evidenceRoot = path14.join(root, EVIDENCE_DIR);
12753
+ const absolute = path14.resolve(root, out);
12754
+ if (absolute !== evidenceRoot && !absolute.startsWith(evidenceRoot + path14.sep)) {
12755
+ throw new CliError30({
12756
+ code: CliErrorCode30.INVALID_ARGUMENT,
12371
12757
  message: `--out \u8981\u843D\u5728\u9879\u76EE\u7684 ${EVIDENCE_DIR}/ \u4E0B\uFF08${evidenceRoot}\uFF09\uFF0C\u6536\u5230\u7684\u662F ${absolute}`
12372
12758
  });
12373
12759
  }
@@ -12412,11 +12798,11 @@ function findChrome(probe, override) {
12412
12798
  }
12413
12799
  async function assertInsideEvidence(deps, evidenceRoot, absolute) {
12414
12800
  const canonicalRoot = await deps.realpath(evidenceRoot);
12415
- const canonicalParent = await deps.realpath(path13.dirname(absolute));
12801
+ const canonicalParent = await deps.realpath(path14.dirname(absolute));
12416
12802
  if (canonicalRoot === null || canonicalParent === null) return;
12417
- if (canonicalParent !== canonicalRoot && !canonicalParent.startsWith(canonicalRoot + path13.sep)) {
12418
- throw new CliError28({
12419
- code: CliErrorCode27.INVALID_ARGUMENT,
12803
+ if (canonicalParent !== canonicalRoot && !canonicalParent.startsWith(canonicalRoot + path14.sep)) {
12804
+ throw new CliError30({
12805
+ code: CliErrorCode30.INVALID_ARGUMENT,
12420
12806
  message: `--out \u7684\u7236\u76EE\u5F55\u7ECF\u7B26\u53F7\u94FE\u63A5\u8DD1\u51FA\u4E86 ${EVIDENCE_DIR}/\uFF1A${canonicalParent}`
12421
12807
  });
12422
12808
  }
@@ -12425,46 +12811,91 @@ async function runChironPage(target, args, deps) {
12425
12811
  const sitePath = normalizeTarget(target);
12426
12812
  const expect = (args.expectText ?? []).filter((t) => t.trim().length > 0);
12427
12813
  if (expect.length === 0) {
12428
- throw new CliError28({
12429
- code: CliErrorCode27.MISSING_FLAG,
12814
+ throw new CliError30({
12815
+ code: CliErrorCode30.MISSING_FLAG,
12430
12816
  message: "\u81F3\u5C11\u8981\u4F20\u4E00\u6761 --expect-text\uFF08\u9875\u9762\u4E0A\u5FC5\u987B\u51FA\u73B0\u7684\u6587\u672C\uFF09\u3002\u53EA\u5224\u300C\u622A\u51FA\u56FE\u4E86\u300D\u4E0D\u7B97\u9A8C\u6536\uFF1A\u767B\u5F55\u9875\u3001\u62A5\u9519\u9875\u3001\u767D\u5C4F\u90FD\u80FD\u622A\u51FA\u56FE\u3002"
12431
12817
  });
12432
12818
  }
12433
12819
  const reject = (args.rejectText ?? []).filter((t) => t.trim().length > 0);
12434
12820
  const viewport = parseViewport(args.size ?? "1440x900");
12435
12821
  const waitMs = parseWaitMs(args.waitMs);
12436
- const root = path13.resolve(args.project ?? ".");
12822
+ const root = path14.resolve(args.project ?? ".");
12437
12823
  const { evidenceRoot, absolute } = resolveEvidenceTarget(root, args.out);
12438
12824
  if (await deps.present(absolute)) {
12439
- throw new CliError28({
12440
- code: CliErrorCode27.INVALID_ARGUMENT,
12825
+ throw new CliError30({
12826
+ code: CliErrorCode30.INVALID_ARGUMENT,
12441
12827
  message: `\u622A\u56FE\u5DF2\u5B58\u5728\uFF0C\u4E0D\u8986\u76D6\uFF1A${absolute}\u3002\u6362\u4E2A --out\uFF0C\u6216\u5148\u628A\u65E7\u8BC1\u636E\u632A\u8D70\u3002`
12442
12828
  });
12443
12829
  }
12444
- await deps.ensureDir(path13.dirname(absolute));
12830
+ await deps.ensureDir(path14.dirname(absolute));
12445
12831
  await assertInsideEvidence(deps, evidenceRoot, absolute);
12446
- const browser = deps.findBrowser();
12447
- if (!browser) {
12448
- throw new CliError28({
12449
- code: CliErrorCode27.INVALID_ARGUMENT,
12450
- message: "\u672C\u673A\u627E\u4E0D\u5230 Chrome/Chromium\uFF0C\u622A\u4E0D\u4E86\u56FE\u3002",
12451
- context: { nextStep: "\u88C5\u4E00\u4E2A Chrome\uFF0C\u6216\u7528 HCM_CHROME_BIN=/\u7EDD\u5BF9\u8DEF\u5F84 \u6307\u5230\u5DF2\u6709\u7684\u90A3\u4E2A" }
12832
+ const endpoint = normalizeCdpEndpoint(args.cdp ?? deps.env.HCM_CHROME_CDP);
12833
+ const evalJs = args.eval?.trim() ? args.eval : void 0;
12834
+ const forceSpawn = (deps.env.HCM_CHIRON_PAGE_DRIVER ?? "").trim() === "spawn";
12835
+ const playwrightBrowser = endpoint || forceSpawn ? null : deps.findPlaywrightBrowser();
12836
+ const usePlaywright = !endpoint && !forceSpawn && (playwrightBrowser !== null || evalJs !== void 0);
12837
+ if (evalJs && !endpoint && !usePlaywright) {
12838
+ throw new CliError30({
12839
+ code: CliErrorCode30.INVALID_ARGUMENT,
12840
+ message: "--eval \u9700\u8981 Playwright \u6216 --cdp\uFF1A\u8001\u7684 spawn \u8DEF\u5F84\u53EA\u4F1A --dump-dom\uFF0C\u585E\u4E0D\u8FDB\u811A\u672C\u3002",
12841
+ context: { nextStep: "npx playwright install chromium-headless-shell\uFF0C\u6216\u5728\u6C99\u7BB1\u5916\u8D77 Chrome \u7528 --cdp \u8FDE" }
12452
12842
  });
12453
12843
  }
12454
- const minted = await deps.mintUrl({ path: sitePath, args });
12455
- const result = deps.capture({ browser, argv: chromeArgv({ viewport, waitMs, screenshot: absolute, url: minted.url, isRoot: process.getuid?.() === 0 }) });
12456
- if (!result.ok) {
12457
- throw new CliError28({
12458
- code: CliErrorCode27.SERVER_ERROR,
12459
- message: `\u6D4F\u89C8\u5668\u6CA1\u8DD1\u5B8C\uFF1A${result.stderr.trim().split("\n").slice(-1)[0] ?? "\u65E0\u8F93\u51FA"}`,
12460
- context: { nextStep: `\u624B\u5DE5\u6838\u4E00\u773C\uFF1A${browser} --headless=new --screenshot \u8DD1\u5F97\u8D77\u6765\u5417` }
12461
- });
12844
+ let dom;
12845
+ let browserLabel;
12846
+ let evalResult;
12847
+ let navigated;
12848
+ let minted;
12849
+ let mode;
12850
+ const mint = () => deps.mintUrl({ path: sitePath, args });
12851
+ if (endpoint || usePlaywright) {
12852
+ mode = endpoint ? "attach" : "playwright";
12853
+ let captured;
12854
+ try {
12855
+ captured = endpoint ? await deps.captureAttached({ endpoint, viewport, waitMs, evalJs, screenshot: absolute, mintUrl: mint }) : await deps.capturePlaywright({ viewport, waitMs, evalJs, screenshot: absolute, browser: playwrightBrowser, mintUrl: mint });
12856
+ } catch (e) {
12857
+ if (e instanceof CliError30) throw new CliError30({ code: e.code, message: redactTicket(e.message), context: e.context });
12858
+ const where = endpoint ? `\u8FDE\u5230 ${endpoint} \u7684 Chrome` : "Playwright \u8D77\u7684\u6D4F\u89C8\u5668";
12859
+ throw new CliError30({
12860
+ code: CliErrorCode30.SERVER_ERROR,
12861
+ message: `${where}\u6CA1\u8DD1\u5B8C\uFF1A${redactTicket(e instanceof Error ? e.message : String(e))}`,
12862
+ context: {
12863
+ nextStep: endpoint ? `\u6838\u4E00\u773C ${endpoint}/json/version \u80FD\u4E0D\u80FD\u6253\u5F00\uFF1BChrome \u8981\u5E26 --remote-debugging-port \u8D77\uFF0C\u4E14\u6C99\u7BB1\u653E\u884C\u4E86\u8FD9\u4E2A\u7AEF\u53E3` : "npx playwright install chromium-headless-shell \u540E\u91CD\u8DD1\uFF1B\u6216 HCM_CHIRON_PAGE_DRIVER=spawn \u8D70\u8001\u8DEF\u5F84\u5BF9\u7167"
12864
+ }
12865
+ });
12866
+ }
12867
+ dom = captured.dom;
12868
+ browserLabel = captured.browser;
12869
+ evalResult = captured.evalResult;
12870
+ navigated = captured.navigated;
12871
+ minted = captured.minted;
12872
+ } else {
12873
+ mode = "spawn";
12874
+ const browser = deps.findBrowser();
12875
+ if (!browser) {
12876
+ throw new CliError30({
12877
+ code: CliErrorCode30.INVALID_ARGUMENT,
12878
+ message: "\u672C\u673A\u627E\u4E0D\u5230 Playwright \u7684 Chromium\uFF0C\u4E5F\u627E\u4E0D\u5230 Chrome/Chromium\uFF0C\u622A\u4E0D\u4E86\u56FE\u3002",
12879
+ context: { nextStep: "npx playwright install chromium-headless-shell\uFF08\u6C99\u7BB1\u91CC\u4E5F\u80FD\u8DD1\uFF09\uFF1B\u6216\u88C5\u4E00\u4E2A Chrome / HCM_CHROME_BIN=/\u7EDD\u5BF9\u8DEF\u5F84\uFF1B\u6216\u5728\u6C99\u7BB1\u5916\u8D77 Chrome \u7528 --cdp \u8FDE" }
12880
+ });
12881
+ }
12882
+ minted = await mint();
12883
+ const result = deps.capture({ browser, argv: chromeArgv({ viewport, waitMs, screenshot: absolute, url: minted.url, isRoot: process.getuid?.() === 0 }) });
12884
+ if (!result.ok) {
12885
+ throw new CliError30({
12886
+ code: CliErrorCode30.SERVER_ERROR,
12887
+ message: `\u6D4F\u89C8\u5668\u6CA1\u8DD1\u5B8C\uFF1A${redactTicket(result.stderr.trim().split("\n").slice(-1)[0] ?? "\u65E0\u8F93\u51FA")}`,
12888
+ context: { nextStep: spawnFailureNextStep(browser, result, deps.platform) }
12889
+ });
12890
+ }
12891
+ dom = result.dom;
12892
+ browserLabel = deps.browserVersion(browser);
12462
12893
  }
12463
12894
  const bytes = await deps.present(absolute) ? await deps.sizeOf(absolute) : 0;
12464
12895
  if (bytes === 0) {
12465
- throw new CliError28({ code: CliErrorCode27.SERVER_ERROR, message: `\u6D4F\u89C8\u5668\u6CA1\u5199\u51FA\u975E\u7A7A PNG\uFF1A${absolute}` });
12896
+ throw new CliError30({ code: CliErrorCode30.SERVER_ERROR, message: `\u6D4F\u89C8\u5668\u6CA1\u5199\u51FA\u975E\u7A7A PNG\uFF1A${absolute}` });
12466
12897
  }
12467
- const verdict = judgePageContent({ dom: result.dom, expect, reject });
12898
+ const verdict = judgePageContent({ dom, expect, reject });
12468
12899
  return {
12469
12900
  ok: verdict.ok,
12470
12901
  path: sitePath,
@@ -12474,25 +12905,50 @@ async function runChironPage(target, args, deps) {
12474
12905
  identity: minted.identity,
12475
12906
  viewport: `${viewport.width}x${viewport.height}`,
12476
12907
  waitMs,
12477
- browser: deps.browserVersion(browser),
12908
+ browser: browserLabel,
12909
+ mode,
12910
+ ...endpoint ? { attach: endpoint } : {},
12911
+ ...evalResult !== void 0 ? { evalResult } : {},
12912
+ ...navigated !== void 0 ? { navigated } : {},
12478
12913
  expected: expect,
12479
12914
  rejected: reject,
12480
12915
  missing: verdict.missing,
12481
12916
  forbidden: verdict.forbidden
12482
12917
  };
12483
12918
  }
12919
+ function spawnFailureNextStep(browser, result, platform) {
12920
+ const sandboxed = result.signal === "SIGABRT" || /SIGABRT|abort trap|Trace\/BPT trap|sandbox/i.test(result.stderr);
12921
+ if (sandboxed) {
12922
+ return `Chrome \u5728\u8FD9\u4E2A\u8FDB\u7A0B\u91CC\u8D77\u4E0D\u6765\uFF08${result.signal ?? "\u88AB\u4FE1\u53F7\u7EC8\u6B62"}\uFF09\u2014\u2014\u6C99\u7BB1\u91CC\u5E38\u89C1\u3002\u6539\u8D70 attach\uFF1A\u5728\u6C99\u7BB1\u5916\u8D77 "${browser}" --headless=new --remote-debugging-port=9222 --user-data-dir=<\u4E34\u65F6\u76EE\u5F55>\uFF0C\u518D\u7ED9\u672C\u547D\u4EE4\u52A0 --cdp http://127.0.0.1:9222\uFF08\u6216 export HCM_CHROME_CDP=\u2026\uFF09` + (platform === "darwin" ? "\uFF1BmacOS \u7684 Seatbelt \u5C31\u662F\u8FD9\u79CD\u60C5\u51B5" : "");
12923
+ }
12924
+ return `\u624B\u5DE5\u6838\u4E00\u773C\uFF1A${browser} --headless=new --screenshot \u8DD1\u5F97\u8D77\u6765\u5417\uFF1B\u8D77\u4E0D\u6765\u5C31\u5728\u6C99\u7BB1\u5916\u8D77\u597D Chrome \u7528 --cdp \u8FDE`;
12925
+ }
12484
12926
  function renderChironPage(receipt) {
12485
12927
  const out = [];
12486
12928
  out.push(`${receipt.ok ? "\u2705" : "\u274C"} ${receipt.path} \xB7 ${receipt.environment}${receipt.identity ? ` \xB7 ${receipt.identity}` : ""}`);
12487
- out.push(` \u622A\u56FE ${receipt.screenshot}\uFF08${receipt.bytes} \u5B57\u8282\uFF0C${receipt.viewport}\uFF0C\u7B49 ${receipt.waitMs}ms\uFF09`);
12929
+ out.push(` \u622A\u56FE ${receipt.screenshot}\uFF08${receipt.bytes} \u5B57\u8282\uFF0C${receipt.viewport}\uFF0C\u7B49 ${receipt.waitMs}ms\uFF0C${receipt.mode === "attach" ? `\u8FDE\u7684 ${receipt.attach}` : receipt.mode}\uFF09`);
12930
+ out.push(` \u6D4F\u89C8\u5668 ${receipt.browser}`);
12931
+ if (receipt.navigated === false) out.push(" \u26A0\uFE0F \u5BFC\u822A\u6CA1\u8D70\u5230 load \u4E8B\u4EF6\uFF08\u8FDE\u63A5\u88AB\u62D2 / \u8BC1\u4E66 / \u7968\u636E\u9875\u8DF3\u8F6C\u5931\u8D25\uFF09\u2014\u2014\u4E0B\u9762\u7684\u5224\u636E\u662F\u5BF9\u9519\u8BEF\u9875\u6216\u7A7A\u58F3\u5224\u7684");
12932
+ if (receipt.evalResult !== void 0) out.push(` --eval \u8FD4\u56DE ${typeof receipt.evalResult === "string" ? receipt.evalResult : safeStringify(receipt.evalResult)}`);
12488
12933
  out.push(` \u6838\u8FC7 ${receipt.expected.map((t) => `\u300C${t}\u300D`).join("\u3001")}${receipt.rejected.length ? ` \xB7 \u4E0D\u8BB8\u51FA\u73B0 ${receipt.rejected.map((t) => `\u300C${t}\u300D`).join("\u3001")}` : ""}`);
12489
12934
  for (const t of receipt.missing) out.push(` \u274C \u9875\u9762\u4E0A\u6CA1\u6709\u300C${t}\u300D`);
12490
12935
  for (const t of receipt.forbidden) out.push(` \u274C \u9875\u9762\u4E0A\u51FA\u73B0\u4E86\u4E0D\u8BE5\u6709\u7684\u300C${t}\u300D`);
12491
12936
  if (!receipt.ok) out.push(" \u622A\u56FE\u4FDD\u7559\u7740\uFF0C\u6253\u5F00\u770B\u4E00\u773C\u662F\u767B\u5F55\u9875\u3001\u62A5\u9519\u9875\uFF0C\u8FD8\u662F\u9875\u9762\u771F\u7684\u5C11\u4E86\u4E1C\u897F\u3002");
12492
12937
  return out.join("\n");
12493
12938
  }
12494
- function redactTicket(text) {
12495
- return text.replace(/(ticket=)[^&\s"']+/g, "$1<redacted>");
12939
+ function safeStringify(value) {
12940
+ try {
12941
+ return JSON.stringify(value);
12942
+ } catch {
12943
+ return String(value);
12944
+ }
12945
+ }
12946
+ function playwrightPackageRoot() {
12947
+ try {
12948
+ return path14.dirname(createRequire(import.meta.url).resolve("playwright-core/package.json"));
12949
+ } catch {
12950
+ return void 0;
12951
+ }
12496
12952
  }
12497
12953
  var defaultChironPageDeps = {
12498
12954
  mintUrl: async ({ path: sitePath, args }) => {
@@ -12500,8 +12956,8 @@ var defaultChironPageDeps = {
12500
12956
  const envCfg = await loadEnv6(ctx.env);
12501
12957
  const frontend = ctx.frontend ?? envCfg.frontend;
12502
12958
  if (!frontend?.trim()) {
12503
- throw new CliError28({
12504
- code: CliErrorCode27.INVALID_ARGUMENT,
12959
+ throw new CliError30({
12960
+ code: CliErrorCode30.INVALID_ARGUMENT,
12505
12961
  message: `env '${ctx.env}' \u6CA1\u914D\u524D\u7AEF\u5730\u5740\uFF0C\u5F00\u4E0D\u4E86\u9875\u9762\u3002`,
12506
12962
  context: { nextStep: `hcm env edit frontend <\u524D\u7AEF\u5730\u5740> --env ${ctx.env}` }
12507
12963
  });
@@ -12530,8 +12986,34 @@ var defaultChironPageDeps = {
12530
12986
  ),
12531
12987
  capture: ({ browser, argv }) => {
12532
12988
  const r = spawnSync(browser, argv, { encoding: "utf8", maxBuffer: 1 << 26, timeout: 3e5 });
12533
- return { ok: r.status === 0, dom: r.stdout ?? "", stderr: redactTicket(r.stderr ?? "") };
12989
+ return { ok: r.status === 0, dom: r.stdout ?? "", stderr: redactTicket(r.stderr ?? ""), signal: r.signal ?? null };
12534
12990
  },
12991
+ captureAttached: (input) => captureViaCdp(input, defaultCdpIo),
12992
+ env: process.env,
12993
+ findPlaywrightBrowser: () => discoverPlaywrightBrowser({
12994
+ platform: process.platform,
12995
+ arch: process.arch,
12996
+ env: process.env,
12997
+ packageRoot: playwrightPackageRoot(),
12998
+ homedir: () => os5.homedir(),
12999
+ readdir: (dir) => {
13000
+ try {
13001
+ return readdirSync3(dir);
13002
+ } catch {
13003
+ return [];
13004
+ }
13005
+ },
13006
+ executable: (file) => {
13007
+ try {
13008
+ accessSync(file, constants.X_OK);
13009
+ return true;
13010
+ } catch {
13011
+ return false;
13012
+ }
13013
+ }
13014
+ }),
13015
+ capturePlaywright: (input) => captureViaPlaywright(input),
13016
+ platform: process.platform,
12535
13017
  browserVersion: (browser) => (spawnSync(browser, ["--version"], { encoding: "utf8" }).stdout ?? "").trim().split("\n")[0] ?? "",
12536
13018
  ensureDir: (dir) => fs12.mkdir(dir, { recursive: true }).then(() => void 0),
12537
13019
  present: (file) => fs12.lstat(file).then(() => true).catch(() => false),
@@ -12555,7 +13037,7 @@ init_exit();
12555
13037
  import { spawnSync as spawnSync2 } from "child_process";
12556
13038
  import { randomUUID } from "crypto";
12557
13039
  import { promises as fs13 } from "fs";
12558
- import path14 from "path";
13040
+ import path15 from "path";
12559
13041
  import yaml2 from "js-yaml";
12560
13042
  import { formatObject as formatObject28 } from "@hcmai/sdk";
12561
13043
 
@@ -13445,7 +13927,7 @@ async function runCase(spec, root, opts = {}, deps = defaultDeps3) {
13445
13927
  continue;
13446
13928
  }
13447
13929
  if (c.file) {
13448
- const file = path14.resolve(root, fill(c.file));
13930
+ const file = path15.resolve(root, fill(c.file));
13449
13931
  const want = c.expect ?? {};
13450
13932
  const bad = [];
13451
13933
  if (want.xlsx_header || want.xlsx_min_rows !== void 0) {
@@ -13467,7 +13949,7 @@ async function runCase(spec, root, opts = {}, deps = defaultDeps3) {
13467
13949
  results.push(bad.length ? { name: c.name, verdict: "fail", detail: bad.join("\uFF1B") } : { name: c.name, verdict: "pass", detail: "" });
13468
13950
  continue;
13469
13951
  }
13470
- const out = path14.join(
13952
+ const out = path15.join(
13471
13953
  "evidence",
13472
13954
  "test",
13473
13955
  opts.evidenceRunId ?? "current",
@@ -13489,11 +13971,11 @@ async function runCase(spec, root, opts = {}, deps = defaultDeps3) {
13489
13971
  }
13490
13972
  async function loadCases(target) {
13491
13973
  const stat = await fs13.stat(target);
13492
- const files = stat.isDirectory() ? (await fs13.readdir(target)).filter((f) => /\.ya?ml$/.test(f)).sort().map((f) => path14.join(target, f)) : [target];
13974
+ const files = stat.isDirectory() ? (await fs13.readdir(target)).filter((f) => /\.ya?ml$/.test(f)).sort().map((f) => path15.join(target, f)) : [target];
13493
13975
  const out = [];
13494
13976
  for (const f of files) {
13495
13977
  const spec = yaml2.load(await fs13.readFile(f, "utf8"));
13496
- assertUsableSpec(spec, path14.basename(f));
13978
+ assertUsableSpec(spec, path15.basename(f));
13497
13979
  out.push({ file: f, spec });
13498
13980
  }
13499
13981
  if (out.length === 0) throw new Error(`${target} \u4E0B\u6CA1\u6709\u7528\u4F8B\uFF08*.yml\uFF09`);
@@ -13501,8 +13983,8 @@ async function loadCases(target) {
13501
13983
  }
13502
13984
  async function chironTestCommand(target, args, deps) {
13503
13985
  try {
13504
- const root = path14.resolve(args.project ?? ".");
13505
- const where = path14.resolve(root, target ?? "tests");
13986
+ const root = path15.resolve(args.project ?? ".");
13987
+ const where = path15.resolve(root, target ?? "tests");
13506
13988
  const cases = await loadCases(where);
13507
13989
  const report = [];
13508
13990
  let failed2 = 0;
@@ -13514,7 +13996,7 @@ async function chironTestCommand(target, args, deps) {
13514
13996
  deps
13515
13997
  );
13516
13998
  failed2 += results.filter((r) => r.verdict === "fail").length;
13517
- report.push({ case: spec.name, file: path14.relative(root, file), results });
13999
+ report.push({ case: spec.name, file: path15.relative(root, file), results });
13518
14000
  }
13519
14001
  const fmt = args.output ?? "table";
13520
14002
  if (fmt === "json" || fmt === "yaml") {
@@ -13655,7 +14137,7 @@ import {
13655
14137
  writeRisk
13656
14138
  } from "@hcmai/sdk";
13657
14139
  import { existsSync as existsSync3 } from "fs";
13658
- import * as path15 from "path";
14140
+ import * as path16 from "path";
13659
14141
  function premise(message, hint = "") {
13660
14142
  process.stderr.write(message + (hint ? `
13661
14143
  \u2192 ${hint}` : "") + "\n");
@@ -13682,13 +14164,13 @@ async function runSeedPlan(args, client3) {
13682
14164
  const reconDir = candidates[0].reconDir;
13683
14165
  if (candidates.length > 1) {
13684
14166
  process.stderr.write(
13685
- `\u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u6709 ${candidates.length} \u4EFD\u57FA\u7EBF\uFF0C\u672C\u8F6E\u8BFB\u7684\u662F \`${path15.basename(reconDir)}\`\uFF1A` + candidates.slice(1).map((c) => `\`${path15.basename(c.reconDir)}\``).join("\u3001") + " \u672A\u88AB\u8BFB\u53D6 \u2014\u2014 \u4E0D\u540C sourceKey \u7684\u4EA7\u7269**\u4E0D\u53EF\u4E92\u6362**\u3002\n"
14167
+ `\u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u6709 ${candidates.length} \u4EFD\u57FA\u7EBF\uFF0C\u672C\u8F6E\u8BFB\u7684\u662F \`${path16.basename(reconDir)}\`\uFF1A` + candidates.slice(1).map((c) => `\`${path16.basename(c.reconDir)}\``).join("\u3001") + " \u672A\u88AB\u8BFB\u53D6 \u2014\u2014 \u4E0D\u540C sourceKey \u7684\u4EA7\u7269**\u4E0D\u53EF\u4E92\u6362**\u3002\n"
13686
14168
  );
13687
14169
  }
13688
14170
  const round = inspectRound2(reconDir);
13689
14171
  process.stderr.write(roundWarning(round));
13690
14172
  const baseline = {
13691
- path: `${path15.basename(path15.dirname(reconDir))}/${path15.basename(reconDir)}`,
14173
+ path: `${path16.basename(path16.dirname(reconDir))}/${path16.basename(reconDir)}`,
13692
14174
  roundId: round.roundId ?? null
13693
14175
  };
13694
14176
  let exemptions = null;
@@ -13950,7 +14432,7 @@ async function deliverySeedVerifyCommand(args) {
13950
14432
  // src/commands/delivery-seed-find.ts
13951
14433
  import { existsSync as existsSync4 } from "fs";
13952
14434
  import { readFileSync as readFileSync8 } from "fs";
13953
- import * as path16 from "path";
14435
+ import * as path17 from "path";
13954
14436
  import {
13955
14437
  INIT_EXIT_CODES as INIT_EXIT_CODES2,
13956
14438
  ValueHints,
@@ -13964,10 +14446,10 @@ import {
13964
14446
  valuesRoundCaveat
13965
14447
  } from "@hcmai/sdk";
13966
14448
  function provenance(chosenReconDir, others) {
13967
- let line = `> \u57FA\u7EBF\uFF1A\`${path16.basename(chosenReconDir)}\`
14449
+ let line = `> \u57FA\u7EBF\uFF1A\`${path17.basename(chosenReconDir)}\`
13968
14450
  `;
13969
14451
  if (others.length > 0) {
13970
- line += `> \u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u53E6\u6709 ${others.length} \u4EFD\u57FA\u7EBF\u672A\u88AB\u8BFB\u53D6\uFF1A` + others.map((o) => `\`${path16.basename(o)}\``).join("\u3001") + " \u2014\u2014 \u4E0D\u540C sourceKey \u7684\u4EA7\u7269**\u4E0D\u53EF\u4E92\u6362**\u3002\n";
14452
+ line += `> \u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u53E6\u6709 ${others.length} \u4EFD\u57FA\u7EBF\u672A\u88AB\u8BFB\u53D6\uFF1A` + others.map((o) => `\`${path17.basename(o)}\``).join("\u3001") + " \u2014\u2014 \u4E0D\u540C sourceKey \u7684\u4EA7\u7269**\u4E0D\u53EF\u4E92\u6362**\u3002\n";
13971
14453
  }
13972
14454
  return `${line}
13973
14455
  `;
@@ -14304,7 +14786,7 @@ import {
14304
14786
  runTriageRound
14305
14787
  } from "@hcmai/sdk";
14306
14788
  import { mkdirSync as mkdirSync2, readFileSync as readFileSync10, writeFileSync as writeFileSync3 } from "fs";
14307
- import * as path17 from "path";
14789
+ import * as path18 from "path";
14308
14790
  var DEFAULT_CAPABILITIES3 = "default";
14309
14791
  function premise4(message, hint) {
14310
14792
  process.stderr.write(`\u{1F534} \u524D\u63D0\u4E0D\u6210\u7ACB\uFF1A${message}
@@ -14340,8 +14822,8 @@ function renderProblems(rows2) {
14340
14822
  `;
14341
14823
  }
14342
14824
  function writeTriageArtifact(outDir, body) {
14343
- const out = path17.join(outDir, "work", "triage.md");
14344
- mkdirSync2(path17.dirname(out), { recursive: true });
14825
+ const out = path18.join(outDir, "work", "triage.md");
14826
+ mkdirSync2(path18.dirname(out), { recursive: true });
14345
14827
  writeFileSync3(out, body, "utf8");
14346
14828
  return out;
14347
14829
  }
@@ -14387,21 +14869,21 @@ import {
14387
14869
  adminResetPassword,
14388
14870
  formatObject as formatObject30,
14389
14871
  fromAxiosError as fromAxiosError23,
14390
- CliError as CliError29,
14391
- CliErrorCode as CliErrorCode28
14872
+ CliError as CliError31,
14873
+ CliErrorCode as CliErrorCode31
14392
14874
  } from "@hcmai/sdk";
14393
14875
  function buildAdminResetPasswordRequest(args, password) {
14394
14876
  const hasId = Boolean(args.id);
14395
14877
  const hasUsername = Boolean(args.username);
14396
14878
  if (hasId === hasUsername) {
14397
- throw new CliError29({
14398
- code: CliErrorCode28.INVALID_ARGUMENT,
14879
+ throw new CliError31({
14880
+ code: CliErrorCode31.INVALID_ARGUMENT,
14399
14881
  message: "--id <uuid> \u4E0E --username <user> \u5FC5\u987B\u4E14\u53EA\u80FD\u63D0\u4F9B\u4E00\u4E2A"
14400
14882
  });
14401
14883
  }
14402
14884
  if (!password) {
14403
- throw new CliError29({
14404
- code: CliErrorCode28.INVALID_ARGUMENT,
14885
+ throw new CliError31({
14886
+ code: CliErrorCode31.INVALID_ARGUMENT,
14405
14887
  message: "\u65B0\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A"
14406
14888
  });
14407
14889
  }
@@ -14430,8 +14912,8 @@ async function promptPasswordTwice() {
14430
14912
  const password = await promptSecret("\u65B0\u5BC6\u7801: ");
14431
14913
  const confirmation = await promptSecret("\u518D\u6B21\u8F93\u5165\u65B0\u5BC6\u7801: ");
14432
14914
  if (password !== confirmation) {
14433
- throw new CliError29({
14434
- code: CliErrorCode28.INVALID_ARGUMENT,
14915
+ throw new CliError31({
14916
+ code: CliErrorCode31.INVALID_ARGUMENT,
14435
14917
  message: "\u4E24\u6B21\u8F93\u5165\u7684\u65B0\u5BC6\u7801\u4E0D\u4E00\u81F4"
14436
14918
  });
14437
14919
  }
@@ -14562,7 +15044,7 @@ var chiron = program.command("chiron").description(
14562
15044
  );
14563
15045
  chiron.command("init").description("\u5EFA\u987E\u95EE\u9879\u76EE\u4ED3\uFF1A\u5199 env.yaml\u3001\u5EFA\u76EE\u5F55\u3001\u5199 AGENTS/CLAUDE \u8FB9\u754C\u5757\u3002\u7EAF\u672C\u5730\uFF0C\u65AD\u7F51\u4E5F\u80FD\u5EFA\uFF1B\u91CD\u8DD1\u5B89\u5168").option("--project <dir>", "\u9879\u76EE\u6839\u76EE\u5F55", ".").option("--env <name>", "\u7ED1\u5230\u672C\u673A\u54EA\u4E2A\u73AF\u5883\uFF08\u6216\u5DF2\u6709 env.yaml \u91CC\u7684\u73AF\u5883\u540D\uFF09").option("--endpoint <url>", "\u5B8C\u5168\u663E\u5F0F\u5730\u58F0\u660E\u540E\u7AEF\u5730\u5740\uFF08\u4E0D\u9700\u8981\u5148\u767B\u5F55\uFF0C\u4E5F\u4E0D\u53D1\u4EFB\u4F55\u8BF7\u6C42\uFF09").option("--frontend <url>", "\u524D\u7AEF\u5730\u5740\uFF08\u914D\u5408 --endpoint\uFF1B\u9ED8\u8BA4\u4E0E\u540E\u7AEF\u540C\u5740\uFF09").option("--tenant <id>", "\u79DF\u6237\u53F7\uFF08\u914D\u5408 --endpoint\uFF1B\u9ED8\u8BA4 1\uFF09").option("--with-skills", "\u987A\u624B\u628A\u6280\u80FD\u4E5F\u88C5\u4E0A\uFF08\u9ED8\u8BA4\u4E0D\u88C5\uFF0C\u7528 hcm chiron skills sync\uFF09").option("--yes", "\u975E\u4EA4\u4E92\u5730\u786E\u8BA4\u300C\u5C31\u7528\u672C\u673A\u5F53\u524D\u6D3B\u52A8\u73AF\u5883\u300D").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((opts) => chironInitCommand(opts));
14564
15046
  chiron.command("test").description("\u6309\u7528\u4F8B\u8DD1\u4E00\u904D\u5E76\u628A\u95EE\u9898\u627E\u51FA\u6765\uFF1A\u7528\u4F8B\u5728\u9879\u76EE\u4ED3 tests/\uFF0C\u5224\u636E\u5FC5\u987B\u770B\u5185\u5BB9\uFF08\u53EA\u5224\u9000\u51FA\u7801\u7684\u7528\u4F8B\u4F1A\u88AB\u62D2\u7EDD\u52A0\u8F7D\uFF09").argument("[target]", "\u7528\u4F8B\u6587\u4EF6\u6216\u76EE\u5F55\uFF08\u9ED8\u8BA4 tests/\uFF09").option("--project <dir>", "\u9879\u76EE\u6839\u76EE\u5F55", ".").option("--env <name>", "\u76EE\u6807\u73AF\u5883\uFF1B\u7528\u4F8B\u91CC\u6CA1\u5199 --env \u65F6\u8865\u4E0A").option("--as <identity>", "\u8EAB\u4EFD\uFF1B\u7528\u4F8B\u91CC\u6CA1\u5199 --as \u65F6\u8865\u4E0A").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((target, opts) => chironTestCommand(target, opts));
14565
- chiron.command("page").description("\u6253\u5F00\u9875\u9762\u622A\u56FE\u5E76\u5BF9\u7740\u9875\u9762\u5185\u5BB9\u5224\u4E00\u6B21\uFF1A\u81F3\u5C11\u8981\u7ED9\u4E00\u6761 --expect-text\uFF0C\u53EA\u622A\u56FE\u4E0D\u7B97\u9A8C\u6536").argument("<\u8DEF\u5F84>", "\u7AD9\u5185\u8DEF\u5F84\uFF0C\u5982 /dashboard/xxx").requiredOption("--out <file>", "\u622A\u56FE\u843D\u70B9\uFF0C\u5FC5\u987B\u5728\u9879\u76EE\u7684 evidence/ \u4E0B\u4E14\u4EE5 .png \u7ED3\u5C3E").option("--expect-text <text...>", "\u9875\u9762\u4E0A\u5FC5\u987B\u51FA\u73B0\u7684\u6587\u672C\uFF08\u81F3\u5C11\u4E00\u6761\uFF09").option("--reject-text <text...>", "\u9875\u9762\u4E0A\u4E0D\u5F97\u51FA\u73B0\u7684\u6587\u672C").option("--project <dir>", "\u9879\u76EE\u6839\u76EE\u5F55", ".").option("--env <name>", "\u9879\u76EE\u73AF\u5883\u540D\u6216\u672C\u673A\u69FD\u540D").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD").option("--wait-ms <ms>", "\u9875\u9762\u6E32\u67D3\u9884\u7B97\u6BEB\u79D2\u6570", "10000").option("--size <WxH>", "\u89C6\u53E3\u5C3A\u5BF8", "1440x900").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((target, opts) => chironPageCommand(target, opts));
15047
+ chiron.command("page").description("\u6253\u5F00\u9875\u9762\u622A\u56FE\u5E76\u5BF9\u7740\u9875\u9762\u5185\u5BB9\u5224\u4E00\u6B21\uFF1A\u81F3\u5C11\u8981\u7ED9\u4E00\u6761 --expect-text\uFF0C\u53EA\u622A\u56FE\u4E0D\u7B97\u9A8C\u6536").argument("<\u8DEF\u5F84>", "\u7AD9\u5185\u8DEF\u5F84\uFF0C\u5982 /dashboard/xxx").requiredOption("--out <file>", "\u622A\u56FE\u843D\u70B9\uFF0C\u5FC5\u987B\u5728\u9879\u76EE\u7684 evidence/ \u4E0B\u4E14\u4EE5 .png \u7ED3\u5C3E").option("--expect-text <text...>", "\u9875\u9762\u4E0A\u5FC5\u987B\u51FA\u73B0\u7684\u6587\u672C\uFF08\u81F3\u5C11\u4E00\u6761\uFF09").option("--reject-text <text...>", "\u9875\u9762\u4E0A\u4E0D\u5F97\u51FA\u73B0\u7684\u6587\u672C").option("--project <dir>", "\u9879\u76EE\u6839\u76EE\u5F55", ".").option("--env <name>", "\u9879\u76EE\u73AF\u5883\u540D\u6216\u672C\u673A\u69FD\u540D").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD").option("--wait-ms <ms>", "\u9875\u9762\u6E32\u67D3\u9884\u7B97\u6BEB\u79D2\u6570", "10000").option("--size <WxH>", "\u89C6\u53E3\u5C3A\u5BF8", "1440x900").option("--cdp <endpoint>", "\u4E0D\u81EA\u5DF1\u8D77 Chrome\uFF0C\u8FDE\u5230\u5DF2\u5728\u8DD1\u7684 Chrome\uFF08--remote-debugging-port\uFF09\uFF1A\u6C99\u7BB1\u91CC\u8D77\u4E0D\u4E86 Chrome \u65F6\u7528\uFF1B\u4E5F\u8BFB HCM_CHROME_CDP").option("--eval <js>", "\u622A\u56FE\u524D\u5728\u9875\u9762\u91CC\u8DD1\u7684 JS\uFF08\u51FD\u6570\u4F53\uFF0C\u53EF await\uFF0C\u8FD4\u56DE\u503C\u8FDB\u56DE\u6267\uFF09\uFF1A\u70B9\u6309\u94AE\u3001\u586B\u8868\u3001\u8FFD\u95EE\u90FD\u9760\u5B83\uFF1B\u9700\u8981 Playwright \u6216 --cdp").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((target, opts) => chironPageCommand(target, opts));
14566
15048
  chiron.command("doctor").description(
14567
15049
  "\u6838\u5BF9\uFF1A\u672C\u673A\u767B\u5F55\u662F\u5426\u5BF9\u7740 env.yaml \u7684\u73AF\u5883\uFF08\u542B\u4E94\u6761\u951A\u70B9\u4E0E\u5BF9\u8BDD\u63E1\u624B\uFF09/ \u6280\u80FD\u88C5\u6CA1\u88C5 / \u6848\u4F8B\u5E93\u8BFB\u4E0D\u8BFB\u5F97\u5230 / Jira \u80FD\u4E0D\u80FD\u63D0\u5355"
14568
15050
  ).option("--project <dir>", "\u9879\u76EE\u6839\u76EE\u5F55", ".").option("--env <name>", "\u8986\u76D6\u8981\u6838\u7684\u73AF\u5883\u522B\u540D\uFF08\u9ED8\u8BA4\u53D6 env.yaml\uFF1B\u591A\u73AF\u5883\u9879\u76EE\u7528\u5B83\u6328\u4E2A\u63A2\uFF09").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD\u63A2\u951A\u70B9").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((opts) => chironDoctorCommand(opts));
@@ -14765,7 +15247,7 @@ program.command("update <Model>").description("\u66F4\u65B0\u4E00\u6761 Model \u
14765
15247
  ).action((model, opts) => updateCommand(model, opts));
14766
15248
  program.command("version").description("\u67E5 CLI \u4E0E\u540E\u7AEF\u4E24\u4E2A\u7248\u672C\uFF08commit / tag / \u6784\u5EFA\u65F6\u95F4\uFF09\u2014\u2014\u514D\u8BA4\u8BC1\uFF0C\u65E0\u9700\u5148 login").option("--endpoint <url>", "\u540E\u7AEF\u5730\u5740\uFF08\u9ED8\u8BA4\u53D6\u9879\u76EE\u73AF\u5883\u6216 activeEnv \u7684 endpoint\uFF09").option("--env <name>", "\u4ECE\u8BE5 env \u89E3\u6790 endpoint").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((opts) => versionCommand(opts));
14767
15249
  program.command("upgrade").alias("self-update").description("\u5347\u7EA7 CLI \u81EA\u5DF1\uFF08\u6CE8\u610F\uFF1A`hcm update` \u662F\u66F4\u65B0\u4E1A\u52A1\u8BB0\u5F55\uFF0C\u4E0D\u662F\u5347\u7EA7\uFF09").option("--check", "\u53EA\u68C0\u67E5\uFF1B\u6709\u65B0\u7248\u672C\u65F6\u4EE5\u9000\u51FA\u7801 1 \u7ED3\u675F\uFF0C\u4FBF\u4E8E\u811A\u672C\u5224\u65AD").action((opts) => upgradeCommand(opts));
14768
- program.command("open [path]").description("\u7528\u5F53\u524D CLI \u8EAB\u4EFD\u6253\u5F00\u524D\u7AEF\u9875\u9762\uFF1A\u94F8\u4E00\u5F20 60s \u4E00\u6B21\u6027\u7968\u636E\u4EA4\u7ED9\u6D4F\u89C8\u5668\uFF0C\u4F1A\u8BDD token \u4E0D\u8FDB URL").option("--print-url", "\u53EA\u6253\u5370\u767B\u5F55 URL\uFF0C\u4E0D\u5F00\u6D4F\u89C8\u5668\uFF08\u7ED9 agent \u6D4F\u89C8\u5668 navigate \u7528\uFF09").option("--env <name>", "\u672C\u6B21\u4F7F\u7528\u7684\u9879\u76EE\u73AF\u5883\u540D\u6216\u672C\u673A\u69FD\u540D").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD\uFF08\u8986\u76D6 env defaultIdentity\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--profile <name>", "[deprecated] \u7528 --env \u66FF\u4EE3").action((path18, opts) => openCommand(path18, opts));
15250
+ program.command("open [path]").description("\u7528\u5F53\u524D CLI \u8EAB\u4EFD\u6253\u5F00\u524D\u7AEF\u9875\u9762\uFF1A\u94F8\u4E00\u5F20 60s \u4E00\u6B21\u6027\u7968\u636E\u4EA4\u7ED9\u6D4F\u89C8\u5668\uFF0C\u4F1A\u8BDD token \u4E0D\u8FDB URL").option("--print-url", "\u53EA\u6253\u5370\u767B\u5F55 URL\uFF0C\u4E0D\u5F00\u6D4F\u89C8\u5668\uFF08\u7ED9 agent \u6D4F\u89C8\u5668 navigate \u7528\uFF09").option("--env <name>", "\u672C\u6B21\u4F7F\u7528\u7684\u9879\u76EE\u73AF\u5883\u540D\u6216\u672C\u673A\u69FD\u540D").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD\uFF08\u8986\u76D6 env defaultIdentity\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--profile <name>", "[deprecated] \u7528 --env \u66FF\u4EE3").action((path19, opts) => openCommand(path19, opts));
14769
15251
  var setting = program.command("setting").description("\u79DF\u6237\u7CFB\u7EDF\u53C2\u6570\uFF08\u767B\u5F55\u7B56\u7565 / \u5BC6\u7801\u7B56\u7565 / \u529F\u80FD\u5F00\u5173 / \u96C6\u6210\u53C2\u6570\uFF09");
14770
15252
  setting.command("get <domain>").description("\u8BFB\u67D0\u57DF\u53C2\u6570\uFF08\u5B9A\u4E49 + \u79DF\u6237\u8986\u76D6\u503C\u5408\u5E76\uFF0C\u7F3A\u5931\u56DE\u843D\u9ED8\u8BA4\u503C\uFF09").option("--env <name>", "\u672C\u6B21\u4F7F\u7528\u7684\u9879\u76EE\u73AF\u5883\u540D\u6216\u672C\u673A\u69FD\u540D").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((d, opts) => settingGetCommand(d, opts));
14771
15253
  setting.command("set <domain>").description("\u6539\u53C2\u6570\uFF0C\u53EF\u91CD\u590D --set\uFF1B\u8D70\u53D7\u63A7\u6821\u9A8C\u8DEF\u5F84\u800C\u975E\u6807\u51C6 CRUD").option(