@hcmai/cli 0.15.7 → 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) {
@@ -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
  }
@@ -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}`);
@@ -12323,11 +12359,11 @@ import { accessSync, constants, readdirSync as readdirSync3 } from "fs";
12323
12359
  import fs12 from "fs/promises";
12324
12360
  import os5 from "os";
12325
12361
  import path14 from "path";
12326
- import { CliError as CliError30, CliErrorCode as CliErrorCode29, formatObject as formatObject27, HcmClient as HcmClient23, loadEnv as loadEnv6 } from "@hcmai/sdk";
12362
+ import { CliError as CliError30, CliErrorCode as CliErrorCode30, formatObject as formatObject27, HcmClient as HcmClient23, loadEnv as loadEnv6 } from "@hcmai/sdk";
12327
12363
  import { createRequire } from "module";
12328
12364
 
12329
12365
  // src/commands/chiron-page-cdp.ts
12330
- import { CliError as CliError28, CliErrorCode as CliErrorCode27 } from "@hcmai/sdk";
12366
+ import { CliError as CliError28, CliErrorCode as CliErrorCode28 } from "@hcmai/sdk";
12331
12367
 
12332
12368
  // src/commands/chiron-page-shared.ts
12333
12369
  function redactTicket(text) {
@@ -12363,14 +12399,14 @@ function normalizeCdpEndpoint(raw) {
12363
12399
  try {
12364
12400
  url = new URL(candidate);
12365
12401
  } catch {
12366
- throw new CliError28({ code: CliErrorCode27.INVALID_ARGUMENT, message: `--cdp \u8981\u5199\u6210 http://\u4E3B\u673A:\u7AEF\u53E3\uFF08Chrome \u7684 --remote-debugging-port\uFF09\uFF0C\u6536\u5230\u7684\u662F ${text}` });
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}` });
12367
12403
  }
12368
12404
  const protocol = url.protocol === "wss:" ? "https:" : url.protocol === "ws:" ? "http:" : url.protocol;
12369
12405
  if (protocol !== "http:" && protocol !== "https:") {
12370
- throw new CliError28({ code: CliErrorCode27.INVALID_ARGUMENT, message: `--cdp \u53EA\u8BA4 http(s) \u6216 ws(s) \u7AEF\u70B9\uFF0C\u6536\u5230\u7684\u662F ${text}` });
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}` });
12371
12407
  }
12372
12408
  if (!url.port) {
12373
- throw new CliError28({ code: CliErrorCode27.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}` });
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}` });
12374
12410
  }
12375
12411
  return `${protocol}//${url.hostname}:${url.port}`;
12376
12412
  }
@@ -12468,7 +12504,7 @@ async function captureViaCdp(input, io) {
12468
12504
  const target = await io.fetchJson(`${input.endpoint}/json/new?about:blank`, "PUT");
12469
12505
  if (!target?.id || !target.webSocketDebuggerUrl) {
12470
12506
  throw new CliError28({
12471
- code: CliErrorCode27.SERVER_ERROR,
12507
+ code: CliErrorCode28.SERVER_ERROR,
12472
12508
  message: `${input.endpoint}/json/new \u6CA1\u6709\u7ED9\u51FA\u6807\u7B7E\u9875\uFF08id / webSocketDebuggerUrl \u7F3A\u5931\uFF09`,
12473
12509
  context: { nextStep: "\u786E\u8BA4 Chrome \u662F\u5E26 --remote-debugging-port \u8D77\u7684\uFF0C\u4E14 --cdp \u6307\u5230\u7684\u662F\u5B83" }
12474
12510
  });
@@ -12498,7 +12534,7 @@ async function captureViaCdp(input, io) {
12498
12534
  });
12499
12535
  if (r.exceptionDetails) {
12500
12536
  const why = r.exceptionDetails.exception?.description ?? r.exceptionDetails.text ?? "unknown";
12501
- throw new CliError28({ code: CliErrorCode27.INVALID_ARGUMENT, message: `--eval \u5728\u9875\u9762\u91CC\u629B\u4E86\u5F02\u5E38\uFF1A${redactTicket(why.split("\n")[0] ?? why)}` });
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)}` });
12502
12538
  }
12503
12539
  evalResult = r.result && "value" in r.result ? toPlainJson(r.result.value) : toPlainJson(r.result?.description);
12504
12540
  }
@@ -12509,7 +12545,7 @@ async function captureViaCdp(input, io) {
12509
12545
  const dom = typeof domReply.result?.value === "string" ? domReply.result.value : "";
12510
12546
  const shot = await session.send("Page.captureScreenshot", { format: "png" });
12511
12547
  if (!shot.data) {
12512
- throw new CliError28({ code: CliErrorCode27.SERVER_ERROR, message: "Page.captureScreenshot \u6CA1\u6709\u8FD4\u56DE\u56FE\u50CF\u6570\u636E" });
12548
+ throw new CliError28({ code: CliErrorCode28.SERVER_ERROR, message: "Page.captureScreenshot \u6CA1\u6709\u8FD4\u56DE\u56FE\u50CF\u6570\u636E" });
12513
12549
  }
12514
12550
  await io.writeFile(input.screenshot, Buffer.from(shot.data, "base64"));
12515
12551
  return { dom, browser, evalResult, navigated, minted };
@@ -12531,7 +12567,7 @@ var defaultCdpIo = {
12531
12567
  openSocket: (wsUrl) => new Promise((resolve3, reject) => {
12532
12568
  const Ctor = globalThis.WebSocket;
12533
12569
  if (!Ctor) {
12534
- reject(new CliError28({ code: CliErrorCode27.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" }));
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" }));
12535
12571
  return;
12536
12572
  }
12537
12573
  const ws = new Ctor(wsUrl);
@@ -12554,7 +12590,7 @@ var defaultCdpIo = {
12554
12590
 
12555
12591
  // src/commands/chiron-page-playwright.ts
12556
12592
  import path13 from "path";
12557
- import { CliError as CliError29, CliErrorCode as CliErrorCode28 } from "@hcmai/sdk";
12593
+ import { CliError as CliError29, CliErrorCode as CliErrorCode29 } from "@hcmai/sdk";
12558
12594
  function playwrightCacheRoot(probe) {
12559
12595
  const override = probe.env.PLAYWRIGHT_BROWSERS_PATH?.trim();
12560
12596
  if (override === "0" && probe.packageRoot) return path13.join(probe.packageRoot, ".local-browsers");
@@ -12598,7 +12634,7 @@ function discoverPlaywrightBrowser(probe) {
12598
12634
  if (explicit) {
12599
12635
  if (probe.executable(explicit)) return { executablePath: explicit, kind: "explicit", from: "HCM_PLAYWRIGHT_EXECUTABLE" };
12600
12636
  throw new CliError29({
12601
- code: CliErrorCode28.INVALID_ARGUMENT,
12637
+ code: CliErrorCode29.INVALID_ARGUMENT,
12602
12638
  message: `HCM_PLAYWRIGHT_EXECUTABLE \u6307\u7684\u6587\u4EF6\u4E0D\u53EF\u6267\u884C\uFF1A${explicit}`,
12603
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" }
12604
12640
  });
@@ -12641,7 +12677,7 @@ async function captureViaPlaywright(input) {
12641
12677
  }
12642
12678
  if (!browser) {
12643
12679
  throw new CliError29({
12644
- code: CliErrorCode28.SERVER_ERROR,
12680
+ code: CliErrorCode29.SERVER_ERROR,
12645
12681
  message: `Playwright \u8D77\u4E0D\u4E86\u6D4F\u89C8\u5668\uFF1A${failures.join("\uFF1B")}`,
12646
12682
  context: {
12647
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"
@@ -12661,7 +12697,7 @@ async function captureViaPlaywright(input) {
12661
12697
  evalResult = toPlainJson(await page.evaluate(wrapEvalBody(input.evalJs)));
12662
12698
  } catch (e) {
12663
12699
  const why = (e instanceof Error ? e.message : String(e)).split("\n")[0] ?? "";
12664
- throw new CliError29({ code: CliErrorCode28.INVALID_ARGUMENT, message: `--eval \u5728\u9875\u9762\u91CC\u629B\u4E86\u5F02\u5E38\uFF1A${redactTicket(why)}` });
12700
+ throw new CliError29({ code: CliErrorCode29.INVALID_ARGUMENT, message: `--eval \u5728\u9875\u9762\u91CC\u629B\u4E86\u5F02\u5E38\uFF1A${redactTicket(why)}` });
12665
12701
  }
12666
12702
  }
12667
12703
  const dom = await page.content();
@@ -12685,13 +12721,13 @@ function judgePageContent(input) {
12685
12721
  function parseViewport(size) {
12686
12722
  const m = /^(\d+)x(\d+)$/.exec(size.trim());
12687
12723
  if (!m) {
12688
- throw new CliError30({ code: CliErrorCode29.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}` });
12689
12725
  }
12690
12726
  const width = Number(m[1]);
12691
12727
  const height = Number(m[2]);
12692
12728
  if (width < VIEWPORT_MIN.width || width > VIEWPORT_MAX.width || height < VIEWPORT_MIN.height || height > VIEWPORT_MAX.height) {
12693
12729
  throw new CliError30({
12694
- code: CliErrorCode29.INVALID_ARGUMENT,
12730
+ code: CliErrorCode30.INVALID_ARGUMENT,
12695
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}`
12696
12732
  });
12697
12733
  }
@@ -12701,23 +12737,23 @@ function parseWaitMs(raw) {
12701
12737
  if (raw === void 0) return 1e4;
12702
12738
  const value = typeof raw === "number" ? raw : Number(raw);
12703
12739
  if (!Number.isInteger(value) || value < 0 || value > WAIT_MS_MAX) {
12704
- throw new CliError30({ code: CliErrorCode29.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}` });
12705
12741
  }
12706
12742
  return value;
12707
12743
  }
12708
12744
  function resolveEvidenceTarget(projectRoot, out) {
12709
12745
  if (!out?.trim()) {
12710
- throw new CliError30({ code: CliErrorCode29.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` });
12711
12747
  }
12712
12748
  if (!out.endsWith(".png")) {
12713
- throw new CliError30({ code: CliErrorCode29.INVALID_ARGUMENT, message: `--out \u8981\u4EE5 .png \u7ED3\u5C3E\uFF0C\u6536\u5230\u7684\u662F ${out}` });
12749
+ throw new CliError30({ code: CliErrorCode30.INVALID_ARGUMENT, message: `--out \u8981\u4EE5 .png \u7ED3\u5C3E\uFF0C\u6536\u5230\u7684\u662F ${out}` });
12714
12750
  }
12715
12751
  const root = path14.resolve(projectRoot);
12716
12752
  const evidenceRoot = path14.join(root, EVIDENCE_DIR);
12717
12753
  const absolute = path14.resolve(root, out);
12718
12754
  if (absolute !== evidenceRoot && !absolute.startsWith(evidenceRoot + path14.sep)) {
12719
12755
  throw new CliError30({
12720
- code: CliErrorCode29.INVALID_ARGUMENT,
12756
+ code: CliErrorCode30.INVALID_ARGUMENT,
12721
12757
  message: `--out \u8981\u843D\u5728\u9879\u76EE\u7684 ${EVIDENCE_DIR}/ \u4E0B\uFF08${evidenceRoot}\uFF09\uFF0C\u6536\u5230\u7684\u662F ${absolute}`
12722
12758
  });
12723
12759
  }
@@ -12766,7 +12802,7 @@ async function assertInsideEvidence(deps, evidenceRoot, absolute) {
12766
12802
  if (canonicalRoot === null || canonicalParent === null) return;
12767
12803
  if (canonicalParent !== canonicalRoot && !canonicalParent.startsWith(canonicalRoot + path14.sep)) {
12768
12804
  throw new CliError30({
12769
- code: CliErrorCode29.INVALID_ARGUMENT,
12805
+ code: CliErrorCode30.INVALID_ARGUMENT,
12770
12806
  message: `--out \u7684\u7236\u76EE\u5F55\u7ECF\u7B26\u53F7\u94FE\u63A5\u8DD1\u51FA\u4E86 ${EVIDENCE_DIR}/\uFF1A${canonicalParent}`
12771
12807
  });
12772
12808
  }
@@ -12776,7 +12812,7 @@ async function runChironPage(target, args, deps) {
12776
12812
  const expect = (args.expectText ?? []).filter((t) => t.trim().length > 0);
12777
12813
  if (expect.length === 0) {
12778
12814
  throw new CliError30({
12779
- code: CliErrorCode29.MISSING_FLAG,
12815
+ code: CliErrorCode30.MISSING_FLAG,
12780
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"
12781
12817
  });
12782
12818
  }
@@ -12787,7 +12823,7 @@ async function runChironPage(target, args, deps) {
12787
12823
  const { evidenceRoot, absolute } = resolveEvidenceTarget(root, args.out);
12788
12824
  if (await deps.present(absolute)) {
12789
12825
  throw new CliError30({
12790
- code: CliErrorCode29.INVALID_ARGUMENT,
12826
+ code: CliErrorCode30.INVALID_ARGUMENT,
12791
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`
12792
12828
  });
12793
12829
  }
@@ -12800,7 +12836,7 @@ async function runChironPage(target, args, deps) {
12800
12836
  const usePlaywright = !endpoint && !forceSpawn && (playwrightBrowser !== null || evalJs !== void 0);
12801
12837
  if (evalJs && !endpoint && !usePlaywright) {
12802
12838
  throw new CliError30({
12803
- code: CliErrorCode29.INVALID_ARGUMENT,
12839
+ code: CliErrorCode30.INVALID_ARGUMENT,
12804
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",
12805
12841
  context: { nextStep: "npx playwright install chromium-headless-shell\uFF0C\u6216\u5728\u6C99\u7BB1\u5916\u8D77 Chrome \u7528 --cdp \u8FDE" }
12806
12842
  });
@@ -12821,7 +12857,7 @@ async function runChironPage(target, args, deps) {
12821
12857
  if (e instanceof CliError30) throw new CliError30({ code: e.code, message: redactTicket(e.message), context: e.context });
12822
12858
  const where = endpoint ? `\u8FDE\u5230 ${endpoint} \u7684 Chrome` : "Playwright \u8D77\u7684\u6D4F\u89C8\u5668";
12823
12859
  throw new CliError30({
12824
- code: CliErrorCode29.SERVER_ERROR,
12860
+ code: CliErrorCode30.SERVER_ERROR,
12825
12861
  message: `${where}\u6CA1\u8DD1\u5B8C\uFF1A${redactTicket(e instanceof Error ? e.message : String(e))}`,
12826
12862
  context: {
12827
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"
@@ -12838,7 +12874,7 @@ async function runChironPage(target, args, deps) {
12838
12874
  const browser = deps.findBrowser();
12839
12875
  if (!browser) {
12840
12876
  throw new CliError30({
12841
- code: CliErrorCode29.INVALID_ARGUMENT,
12877
+ code: CliErrorCode30.INVALID_ARGUMENT,
12842
12878
  message: "\u672C\u673A\u627E\u4E0D\u5230 Playwright \u7684 Chromium\uFF0C\u4E5F\u627E\u4E0D\u5230 Chrome/Chromium\uFF0C\u622A\u4E0D\u4E86\u56FE\u3002",
12843
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" }
12844
12880
  });
@@ -12847,7 +12883,7 @@ async function runChironPage(target, args, deps) {
12847
12883
  const result = deps.capture({ browser, argv: chromeArgv({ viewport, waitMs, screenshot: absolute, url: minted.url, isRoot: process.getuid?.() === 0 }) });
12848
12884
  if (!result.ok) {
12849
12885
  throw new CliError30({
12850
- code: CliErrorCode29.SERVER_ERROR,
12886
+ code: CliErrorCode30.SERVER_ERROR,
12851
12887
  message: `\u6D4F\u89C8\u5668\u6CA1\u8DD1\u5B8C\uFF1A${redactTicket(result.stderr.trim().split("\n").slice(-1)[0] ?? "\u65E0\u8F93\u51FA")}`,
12852
12888
  context: { nextStep: spawnFailureNextStep(browser, result, deps.platform) }
12853
12889
  });
@@ -12857,7 +12893,7 @@ async function runChironPage(target, args, deps) {
12857
12893
  }
12858
12894
  const bytes = await deps.present(absolute) ? await deps.sizeOf(absolute) : 0;
12859
12895
  if (bytes === 0) {
12860
- throw new CliError30({ code: CliErrorCode29.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}` });
12861
12897
  }
12862
12898
  const verdict = judgePageContent({ dom, expect, reject });
12863
12899
  return {
@@ -12921,7 +12957,7 @@ var defaultChironPageDeps = {
12921
12957
  const frontend = ctx.frontend ?? envCfg.frontend;
12922
12958
  if (!frontend?.trim()) {
12923
12959
  throw new CliError30({
12924
- code: CliErrorCode29.INVALID_ARGUMENT,
12960
+ code: CliErrorCode30.INVALID_ARGUMENT,
12925
12961
  message: `env '${ctx.env}' \u6CA1\u914D\u524D\u7AEF\u5730\u5740\uFF0C\u5F00\u4E0D\u4E86\u9875\u9762\u3002`,
12926
12962
  context: { nextStep: `hcm env edit frontend <\u524D\u7AEF\u5730\u5740> --env ${ctx.env}` }
12927
12963
  });
@@ -14834,20 +14870,20 @@ import {
14834
14870
  formatObject as formatObject30,
14835
14871
  fromAxiosError as fromAxiosError23,
14836
14872
  CliError as CliError31,
14837
- CliErrorCode as CliErrorCode30
14873
+ CliErrorCode as CliErrorCode31
14838
14874
  } from "@hcmai/sdk";
14839
14875
  function buildAdminResetPasswordRequest(args, password) {
14840
14876
  const hasId = Boolean(args.id);
14841
14877
  const hasUsername = Boolean(args.username);
14842
14878
  if (hasId === hasUsername) {
14843
14879
  throw new CliError31({
14844
- code: CliErrorCode30.INVALID_ARGUMENT,
14880
+ code: CliErrorCode31.INVALID_ARGUMENT,
14845
14881
  message: "--id <uuid> \u4E0E --username <user> \u5FC5\u987B\u4E14\u53EA\u80FD\u63D0\u4F9B\u4E00\u4E2A"
14846
14882
  });
14847
14883
  }
14848
14884
  if (!password) {
14849
14885
  throw new CliError31({
14850
- code: CliErrorCode30.INVALID_ARGUMENT,
14886
+ code: CliErrorCode31.INVALID_ARGUMENT,
14851
14887
  message: "\u65B0\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A"
14852
14888
  });
14853
14889
  }
@@ -14877,7 +14913,7 @@ async function promptPasswordTwice() {
14877
14913
  const confirmation = await promptSecret("\u518D\u6B21\u8F93\u5165\u65B0\u5BC6\u7801: ");
14878
14914
  if (password !== confirmation) {
14879
14915
  throw new CliError31({
14880
- code: CliErrorCode30.INVALID_ARGUMENT,
14916
+ code: CliErrorCode31.INVALID_ARGUMENT,
14881
14917
  message: "\u4E24\u6B21\u8F93\u5165\u7684\u65B0\u5BC6\u7801\u4E0D\u4E00\u81F4"
14882
14918
  });
14883
14919
  }