@hcmai/cli 0.17.0 → 0.19.0

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
@@ -11,8 +11,8 @@ var __export = (target, all) => {
11
11
 
12
12
  // src/utils/impersonation-lifecycle.ts
13
13
  import { hasPendingImpersonationSessions, releasePendingImpersonationSessions } from "@hcmai/sdk";
14
- function deferExitForImpersonation(code) {
15
- if (hasPendingImpersonationSessions()) throw new HandledExit(code);
14
+ function deferExitForImpersonation(code2) {
15
+ if (hasPendingImpersonationSessions()) throw new HandledExit(code2);
16
16
  }
17
17
  function cleanup() {
18
18
  cleaning ??= (async () => {
@@ -28,10 +28,10 @@ function cleanup() {
28
28
  });
29
29
  return cleaning;
30
30
  }
31
- function prepareImpersonationExit(code, brokenStderr = false) {
31
+ function prepareImpersonationExit(code2, brokenStderr = false) {
32
32
  stderrBroken ||= brokenStderr;
33
33
  terminating ??= (async () => {
34
- process.exitCode = code || process.exitCode || 0;
34
+ process.exitCode = code2 || process.exitCode || 0;
35
35
  const errors = await cleanup();
36
36
  await new Promise((resolve3) => {
37
37
  let remaining = 2;
@@ -280,19 +280,19 @@ async function ensureAsAuth(env2, endpoint, configuredTenant, target, expectedTe
280
280
  });
281
281
  }
282
282
  if (!local) {
283
- const matches2 = [];
283
+ const matches3 = [];
284
284
  for (const name of await listIdentities(env2)) {
285
285
  const meta2 = await loadIdentity(name);
286
- if (meta2.username === target) matches2.push({ name, meta: meta2 });
286
+ if (meta2.username === target) matches3.push({ name, meta: meta2 });
287
287
  }
288
- if (matches2.length > 1) {
288
+ if (matches3.length > 1) {
289
289
  throw new CliError2({
290
290
  code: CliErrorCode.INVALID_ARGUMENT,
291
- message: `\u7528\u6237\u540D '${target}' \u5339\u914D\u591A\u4E2A\u672C\u673A\u8EAB\u4EFD\uFF1A${matches2.map((m) => m.name).join(", ")}`,
291
+ message: `\u7528\u6237\u540D '${target}' \u5339\u914D\u591A\u4E2A\u672C\u673A\u8EAB\u4EFD\uFF1A${matches3.map((m) => m.name).join(", ")}`,
292
292
  context: { nextStep: "\u7528 --as <\u5B8C\u6574\u672C\u673A\u8EAB\u4EFD\u540D> \u7CBE\u786E\u6307\u5B9A" }
293
293
  });
294
294
  }
295
- local = matches2[0];
295
+ local = matches3[0];
296
296
  }
297
297
  const targetUsername = local ? local.meta.username ?? (local.name.endsWith(`@${env2}`) ? local.name.slice(0, -env2.length - 1) : void 0) : target;
298
298
  if (!targetUsername) {
@@ -612,8 +612,8 @@ var init_TerminalRenderer = __esm({
612
612
  const rendered = marked.parse(src).replace(/\n+$/, "");
613
613
  if (!rendered) return;
614
614
  this.ensureLineStart();
615
- const indented = this.depth > 0 ? this.indent() + rendered.replace(/\n/g, "\n" + this.indent()) : rendered;
616
- this.write(indented + "\n\n");
615
+ const indented2 = this.depth > 0 ? this.indent() + rendered.replace(/\n/g, "\n" + this.indent()) : rendered;
616
+ this.write(indented2 + "\n\n");
617
617
  }
618
618
  /** 渲染收口累积正文(终态/块级边界时调)。markdown 关时正文已直写,仅校正行首。 */
619
619
  flushChatBuffer() {
@@ -728,8 +728,8 @@ var init_TerminalRenderer = __esm({
728
728
  if (totalTokens) {
729
729
  const inTok = stats?.inputTokens ?? 0;
730
730
  const outTok = stats?.outputTokens ?? 0;
731
- const split = inTok > 0 || outTok > 0 ? ` (\u2191${inTok}/\u2193${outTok})` : "";
732
- segs.push(`${totalTokens} tok${split}`);
731
+ const split2 = inTok > 0 || outTok > 0 ? ` (\u2191${inTok}/\u2193${outTok})` : "";
732
+ segs.push(`${totalTokens} tok${split2}`);
733
733
  }
734
734
  if (stats?.toolCount) segs.push(`${stats.toolCount} \u5DE5\u5177`);
735
735
  if (stats?.delegationCount) segs.push(`${stats.delegationCount} \u59D4\u6D3E`);
@@ -986,8 +986,8 @@ var init_StreamPresenter = __esm({
986
986
  this.renderer.delegationEnd(parentToolUseId, totalDurMs, d.toolCount, d.failCount, success, nextSteps);
987
987
  this.renderer.startSpinner("\u601D\u8003\u4E2D\u2026");
988
988
  },
989
- onTerminal: (_stopReason, tokens) => {
990
- this.totalTokens = tokens || this.totalTokens;
989
+ onTerminal: (_stopReason, tokens2) => {
990
+ this.totalTokens = tokens2 || this.totalTokens;
991
991
  this.pendingTools.clear();
992
992
  for (const [k, d] of this.delgMeta) {
993
993
  if (!d.paused) this.delgMeta.delete(k);
@@ -1117,10 +1117,10 @@ var init_StreamPresenter = __esm({
1117
1117
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1118
1118
  async toError(ev) {
1119
1119
  const fromConn = await this.opts.serverError?.() ?? null;
1120
- const code = ev.payload?.errorCode ?? ev.payload?.code ?? fromConn?.code;
1120
+ const code2 = ev.payload?.errorCode ?? ev.payload?.code ?? fromConn?.code;
1121
1121
  const message = ev.payload?.message ?? fromConn?.message;
1122
1122
  const err = new Error(message ?? "stream failed");
1123
- err.code = code ?? CliErrorCode16.STREAM_FAILED_NO_SERVER_CODE;
1123
+ err.code = code2 ?? CliErrorCode16.STREAM_FAILED_NO_SERVER_CODE;
1124
1124
  err.traceId = ev.traceId;
1125
1125
  return err;
1126
1126
  }
@@ -1405,8 +1405,8 @@ function BlockView({ block: b }) {
1405
1405
  case "done": {
1406
1406
  const segs = [`${b.durMs}ms`];
1407
1407
  if (b.totalTokens) {
1408
- const split = b.inputTokens || b.outputTokens ? ` (\u2191${b.inputTokens ?? 0}/\u2193${b.outputTokens ?? 0})` : "";
1409
- segs.push(`${b.totalTokens} tok${split}`);
1408
+ const split2 = b.inputTokens || b.outputTokens ? ` (\u2191${b.inputTokens ?? 0}/\u2193${b.outputTokens ?? 0})` : "";
1409
+ segs.push(`${b.totalTokens} tok${split2}`);
1410
1410
  }
1411
1411
  if (b.toolCount) segs.push(`${b.toolCount} \u5DE5\u5177`);
1412
1412
  if (b.delegationCount) segs.push(`${b.delegationCount} \u59D4\u6D3E`);
@@ -1444,7 +1444,7 @@ import { useEffect, useRef, useState } from "react";
1444
1444
  import { Box as Box2, Text as Text2, useInput } from "ink";
1445
1445
  import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
1446
1446
  function MultilineInput(props) {
1447
- const { value, onChange, onSubmit, placeholder = "", prompt = "\u203A ", onHistoryUp, onHistoryDown, onEscapeClear, captureKey } = props;
1447
+ const { value, onChange, onSubmit, placeholder: placeholder2 = "", prompt = "\u203A ", onHistoryUp, onHistoryDown, onEscapeClear, captureKey } = props;
1448
1448
  const [cursor, setCursor] = useState(value.length);
1449
1449
  const selfEdit = useRef(false);
1450
1450
  useEffect(() => {
@@ -1518,8 +1518,8 @@ function MultilineInput(props) {
1518
1518
  if (!value) {
1519
1519
  return /* @__PURE__ */ jsxs2(Box2, { children: [
1520
1520
  /* @__PURE__ */ jsx2(Text2, { color: "cyan", children: prompt }),
1521
- /* @__PURE__ */ jsx2(Text2, { inverse: true, children: placeholder.charAt(0) || " " }),
1522
- /* @__PURE__ */ jsx2(Text2, { dimColor: true, children: placeholder.slice(1) })
1521
+ /* @__PURE__ */ jsx2(Text2, { inverse: true, children: placeholder2.charAt(0) || " " }),
1522
+ /* @__PURE__ */ jsx2(Text2, { dimColor: true, children: placeholder2.slice(1) })
1523
1523
  ] });
1524
1524
  }
1525
1525
  const lines = value.split("\n");
@@ -2404,8 +2404,8 @@ function launchBrowser(url, platform = process.platform, onFailure) {
2404
2404
  child.on("error", () => {
2405
2405
  onFailure?.();
2406
2406
  });
2407
- child.once("exit", (code) => {
2408
- if (code !== null && code !== 0) onFailure?.();
2407
+ child.once("exit", (code2) => {
2408
+ if (code2 !== null && code2 !== 0) onFailure?.();
2409
2409
  });
2410
2410
  child.unref();
2411
2411
  }
@@ -2496,20 +2496,20 @@ function validateCliLoginEnvironment(endpoint, frontend) {
2496
2496
  }
2497
2497
  function cancellation() {
2498
2498
  const controller = new AbortController();
2499
- let code;
2499
+ let code2;
2500
2500
  const onInt = () => {
2501
- code = 130;
2501
+ code2 = 130;
2502
2502
  controller.abort();
2503
2503
  };
2504
2504
  const onTerm = () => {
2505
- code = 143;
2505
+ code2 = 143;
2506
2506
  controller.abort();
2507
2507
  };
2508
2508
  process.on("SIGINT", onInt);
2509
2509
  process.on("SIGTERM", onTerm);
2510
2510
  return {
2511
2511
  controller,
2512
- error: (error) => code === void 0 ? error : new HandledExit(code),
2512
+ error: (error) => code2 === void 0 ? error : new HandledExit(code2),
2513
2513
  dispose: () => {
2514
2514
  process.removeListener("SIGINT", onInt);
2515
2515
  process.removeListener("SIGTERM", onTerm);
@@ -2643,10 +2643,10 @@ async function beginBrowserLogin(input) {
2643
2643
  }
2644
2644
  const keys = [...url.searchParams.keys()];
2645
2645
  const returnedState = url.searchParams.get("state") ?? "";
2646
- const code = url.searchParams.get("code");
2646
+ const code2 = url.searchParams.get("code");
2647
2647
  const denied = url.searchParams.get("error");
2648
2648
  const validState = Buffer.byteLength(returnedState) === Buffer.byteLength(state) && timingSafeEqual(Buffer.from(returnedState), Buffer.from(state));
2649
- if (!validState || keys.length !== 2 || new Set(keys).size !== keys.length || keys.some((key2) => !["state", "code", "error"].includes(key2)) || !code && denied !== "access_denied" || code !== null && denied !== null) {
2649
+ if (!validState || keys.length !== 2 || new Set(keys).size !== keys.length || keys.some((key2) => !["state", "code", "error"].includes(key2)) || !code2 && denied !== "access_denied" || code2 !== null && denied !== null) {
2650
2650
  reply(response, 400, "\u56DE\u8C03\u6821\u9A8C\u5931\u8D25\uFF0C\u8BF7\u7EE7\u7EED\u539F\u6388\u6743\u6D41\u7A0B");
2651
2651
  return;
2652
2652
  }
@@ -2669,7 +2669,7 @@ async function beginBrowserLogin(input) {
2669
2669
  pendingResponse = response;
2670
2670
  void exchangeBrowserAuthorization({
2671
2671
  ...input,
2672
- authorizationCode: code,
2672
+ authorizationCode: code2,
2673
2673
  codeVerifier: verifier,
2674
2674
  redirectUri,
2675
2675
  deadline,
@@ -6006,14 +6006,14 @@ function describeLlmTraceEmpty(convId, envelope) {
6006
6006
  return lines;
6007
6007
  }
6008
6008
  const facts = [];
6009
- const code = asText(envelope.code);
6009
+ const code2 = asText(envelope.code);
6010
6010
  const reason = envelopeReason(envelope);
6011
6011
  const nextStep = asText(envelope.nextStep);
6012
6012
  const tenantId = asText(asRecord2(envelope.scope)?.tenantId);
6013
6013
  const visible = asRecord2(envelope.conversation)?.visible;
6014
6014
  const retention = asText(asRecord2(envelope.capture)?.retention);
6015
6015
  const writerLine = writerCountsLine(envelope);
6016
- if (code) lines.push(`code: ${code}`);
6016
+ if (code2) lines.push(`code: ${code2}`);
6017
6017
  if (reason) lines.push(`reason: ${unfold(reason)}`);
6018
6018
  if (tenantId) facts.push(`tenant ${tenantId}`);
6019
6019
  if (typeof visible === "boolean") facts.push(`conversation: ${visible ? "visible" : "not visible"}`);
@@ -11943,8 +11943,8 @@ function parseVerifyResult(raw) {
11943
11943
  context: { nextStep: "pass = \u539F\u6545\u969C\u5728\u76EE\u6807\u73AF\u5883\u4E0D\u518D\u51FA\u73B0\uFF1Bfail = \u4ECD\u7136\u590D\u73B0\u6216\u9A8C\u51FA\u6CA1\u901A\u8FC7\u7684\uFF1Bpartial = \u53EA\u9A8C\u4E86\u4E00\u90E8\u5206\u3001\u9A8C\u8FC7\u7684\u90FD\u901A\u8FC7\uFF08\u4E0D\u5173\u5355\uFF09\u3002" }
11944
11944
  });
11945
11945
  }
11946
- function verifyFailure(reasonCode, code, written, message, nextStep, extra = {}, cause) {
11947
- return new CliError26({ code, message: `${message}${WRITTEN_TAG[written]}`, context: { reasonCode, written, nextStep, ...extra }, cause });
11946
+ function verifyFailure(reasonCode, code2, written, message, nextStep, extra = {}, cause) {
11947
+ return new CliError26({ code: code2, message: `${message}${WRITTEN_TAG[written]}`, context: { reasonCode, written, nextStep, ...extra }, cause });
11948
11948
  }
11949
11949
  function who(u) {
11950
11950
  if (!u) return "\uFF08\u5355\u4E0A\u6CA1\u6709\uFF09";
@@ -12476,19 +12476,19 @@ async function gapVerifyCommand(ref, args, deps = defaultDeps) {
12476
12476
  init_auth_guard();
12477
12477
  import { promises as fs12 } from "fs";
12478
12478
  import path14 from "path";
12479
- import axios7 from "axios";
12479
+ import axios9 from "axios";
12480
12480
  import {
12481
- CliError as CliError30,
12482
- CliErrorCode as CliErrorCode31,
12481
+ CliError as CliError31,
12482
+ CliErrorCode as CliErrorCode32,
12483
12483
  formatObject as formatObject28,
12484
12484
  httpProbe as httpProbe2,
12485
- loadGlobalConfig as loadGlobalConfig11,
12485
+ loadGlobalConfig as loadGlobalConfig12,
12486
12486
  loadIdentity as loadIdentity5,
12487
12487
  parseEnvYaml as parseEnvYaml3,
12488
12488
  releasePendingImpersonationSessions as releasePendingImpersonationSessions2,
12489
12489
  resolveActiveIdentity as resolveActiveIdentity2,
12490
- resolveEnvContext as resolveEnvContext8,
12491
- printResolvedEnvironment as printResolvedEnvironment8,
12490
+ resolveEnvContext as resolveEnvContext9,
12491
+ printResolvedEnvironment as printResolvedEnvironment9,
12492
12492
  conversationWebSocketEndpoint as conversationWebSocketEndpoint4,
12493
12493
  probeConversationHandshake
12494
12494
  } from "@hcmai/sdk";
@@ -13920,11 +13920,11 @@ function judgmentRefFor(checkId) {
13920
13920
  function pass(summary, extra = {}) {
13921
13921
  return { level: "PASS", summary, ...extra };
13922
13922
  }
13923
- function found(code, summary, extra = {}) {
13924
- return { level: "FOUND", code, summary: summary ?? code, ...extra };
13923
+ function found(code2, summary, extra = {}) {
13924
+ return { level: "FOUND", code: code2, summary: summary ?? code2, ...extra };
13925
13925
  }
13926
- function unknown(code, summary, extra = {}) {
13927
- return { level: "UNDETERMINED", code, summary: summary ?? code, reason: "SOURCE_UNAVAILABLE", ...extra };
13926
+ function unknown(code2, summary, extra = {}) {
13927
+ return { level: "UNDETERMINED", code: code2, summary: summary ?? code2, reason: "SOURCE_UNAVAILABLE", ...extra };
13928
13928
  }
13929
13929
  function safeError(error) {
13930
13930
  const message = error instanceof Error ? `${error.name}: ${error.message}` : String(error);
@@ -14094,8 +14094,8 @@ var boundary = async (ctx) => {
14094
14094
  var method = async (ctx) => {
14095
14095
  const status = await ctx.services.inspectMethod(ctx.root);
14096
14096
  if (status.verdict === "ok") return pass(status.detail);
14097
- const code = status.detail.startsWith("\u672A\u5B89\u88C5") ? "METHOD_NOT_INSTALLED" : status.detail.startsWith("\u672C\u673A\u526F\u672C") ? "METHOD_COPY_MISMATCH" : status.detail.startsWith("\u7248\u672C\u843D\u540E") ? "METHOD_OUTDATED" : "METHOD_UNCHECKED";
14098
- return (code === "METHOD_UNCHECKED" ? unknown : found)(code, status.detail, { note: status.nextStep });
14097
+ const code2 = status.detail.startsWith("\u672A\u5B89\u88C5") ? "METHOD_NOT_INSTALLED" : status.detail.startsWith("\u672C\u673A\u526F\u672C") ? "METHOD_COPY_MISMATCH" : status.detail.startsWith("\u7248\u672C\u843D\u540E") ? "METHOD_OUTDATED" : "METHOD_UNCHECKED";
14098
+ return (code2 === "METHOD_UNCHECKED" ? unknown : found)(code2, status.detail, { note: status.nextStep });
14099
14099
  };
14100
14100
  function caseFailureAdvice(reason, timedOut) {
14101
14101
  if (timedOut || /ECONN\w*|ENOTFOUND|EAI_AGAIN|ETIMEDOUT|fetch failed|socket|TLS/i.test(reason ?? "")) return "\u67E5\u7F51\u7EDC\u6216\u4EE3\u7406\u540E\u91CD\u8DD1";
@@ -14117,9 +14117,9 @@ var cases = async (ctx) => {
14117
14117
  var jira = async (ctx) => {
14118
14118
  const status = await ctx.services.inspectJira({ httpTimeoutMs: 8e3 });
14119
14119
  if (status.ok) return pass(`${status.who || "\u5DF2\u8FDE\u63A5"}\uFF0CJira \u9879\u76EE\u53EF\u89C1\uFF08\u53EA\u8BFB\u63A2\u6D3B\uFF09`);
14120
- const code = status.code ?? (status.tokenReadError ? "JIRA_TOKEN_UNREADABLE" : "JIRA_UNREACHABLE");
14121
- const undetermined = ["JIRA_SERVER_ERROR", "JIRA_UNREACHABLE", "JIRA_TOKEN_UNREADABLE"].includes(code);
14122
- return (undetermined ? unknown : found)(code, void 0, {
14120
+ const code2 = status.code ?? (status.tokenReadError ? "JIRA_TOKEN_UNREADABLE" : "JIRA_UNREACHABLE");
14121
+ const undetermined = ["JIRA_SERVER_ERROR", "JIRA_UNREACHABLE", "JIRA_TOKEN_UNREADABLE"].includes(code2);
14122
+ return (undetermined ? unknown : found)(code2, void 0, {
14123
14123
  note: [status.reason, status.nextStep, !status.code ? "\u672A\u80FD\u5224\u522B\u5931\u8D25\u7C7B\u578B" : void 0].filter(Boolean).join("\uFF1B")
14124
14124
  });
14125
14125
  };
@@ -14127,8 +14127,301 @@ var localChecks = { project, credential, version, installed, fresh, boundary, me
14127
14127
 
14128
14128
  // src/commands/doctor/connect-checks.ts
14129
14129
  init_auth_guard();
14130
- import axios6 from "axios";
14130
+ import axios7 from "axios";
14131
14131
  import { CliError as CliError29, probeDoctorEndpoint, probeDoctorLayer, layerDetail, toPrincipal as toPrincipal3 } from "@hcmai/sdk";
14132
+
14133
+ // src/commands/doctor/server-report.ts
14134
+ import axios6 from "axios";
14135
+ import { classifyStatus } from "@hcmai/sdk";
14136
+ var fullScope = { stage: null, only: [], skip: [], active: false };
14137
+ function serverCatalogKnown(catalog, report) {
14138
+ return !!catalog && !!report && catalog.catalogRevision != null && report.catalogRevision != null;
14139
+ }
14140
+ function catalogChanged(catalog, report) {
14141
+ return serverCatalogKnown(catalog, report) && catalog.catalogRevision !== report.catalogRevision;
14142
+ }
14143
+ function expectedServerIds(catalog, report, requested = fullScope) {
14144
+ const disabled = new Set(report.scope?.policyDisabled?.map((row) => row.id));
14145
+ return new Set(catalog.checks.filter((row) => !disabled.has(row.id) && (!requested.stage || Array.isArray(row.stages) && row.stages.some((s) => s.toLowerCase() === requested.stage?.toLowerCase())) && (!requested.only.length || requested.only.some((t) => row.id.startsWith(t))) && !requested.skip.some((t) => row.id.startsWith(t))).map((row) => row.id));
14146
+ }
14147
+ var object = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
14148
+ function parseCatalog(body) {
14149
+ if (!object(body) || !Array.isArray(body.checks) || !Array.isArray(body.reservedCodes) || !(typeof body.catalogRevision === "string" || body.catalogRevision === null) || !object(body.tenantCatalog)) return void 0;
14150
+ if (!body.checks.every((c2) => object(c2) && typeof c2.id === "string")) return void 0;
14151
+ return body;
14152
+ }
14153
+ var requestServerReport = async (endpoint, token, timeoutMs, budgetMs, signal, scope = fullScope) => {
14154
+ const options = {
14155
+ baseURL: endpoint,
14156
+ timeout: timeoutMs,
14157
+ signal,
14158
+ maxRedirects: 0,
14159
+ validateStatus: () => true,
14160
+ headers: { Accept: "application/json", ...token ? { Authorization: `Bearer ${token}` } : {} }
14161
+ };
14162
+ const range = {
14163
+ ...scope.stage ? { stage: scope.stage } : {},
14164
+ ...scope.only.length ? { only: scope.only.join(",") } : {},
14165
+ ...scope.skip.length ? { skip: scope.skip.join(",") } : {}
14166
+ };
14167
+ const res = scope.active ? await axios6.post("/api/system/health/report", { active: true, budgetMs, ...range }, options) : await axios6.get("/api/system/health/report", { ...options, params: { budgetMs, ...range } });
14168
+ return {
14169
+ status: res.status,
14170
+ body: res.data,
14171
+ error: classifyStatus(res.status),
14172
+ headers: Object.fromEntries(Object.entries(res.headers).map(([k, v]) => [k.toLowerCase(), String(v)]))
14173
+ };
14174
+ };
14175
+ function httpNote(out) {
14176
+ return `HTTP ${out.status < 0 ? "\u672A\u53D6\u5F97\u54CD\u5E94" : out.status}${out.headers["x-trace-id"] ? ` \xB7 traceId=${out.headers["x-trace-id"]}` : ""}`;
14177
+ }
14178
+ function throttleNote(out) {
14179
+ const error = object(out.body) && object(out.body.error) ? out.body.error : void 0;
14180
+ const details = object(error?.details) ? error.details : void 0;
14181
+ const retryAfter = out.headers["retry-after"] || details?.retryAfter;
14182
+ return `${httpNote(out)} \xB7 ${retryAfter !== void 0 && retryAfter !== null ? `retryAfter=${retryAfter}` : "\u670D\u52A1\u7AEF\u672A\u63D0\u4F9B retryAfter"}${typeof error?.next_step === "string" ? `\uFF1B${error.next_step}` : ""}`;
14183
+ }
14184
+ function reportEnvelopeError(body, platformOps = false) {
14185
+ if (!object(body)) return "\u6B63\u6587\u5FC5\u987B\u662F\u5BF9\u8C61";
14186
+ if (body.schemaVersion === void 0 || body.schemaVersion === null) return "\u7F3A\u5C11 schemaVersion";
14187
+ if (body.schemaVersion !== 1) return `schemaVersion=${String(body.schemaVersion)} \u4E0D\u53D7\u652F\u6301\uFF1B\u5347\u7EA7 CLI`;
14188
+ for (const field of ["results", "scopeIds"]) if (!Array.isArray(body[field])) return `${field} \u5FC5\u987B\u662F\u6570\u7EC4`;
14189
+ for (const field of ["totalCount", "returnedCount"]) if (!Number.isInteger(body[field])) return `${field} \u5FC5\u987B\u662F\u6574\u6570`;
14190
+ for (const [i, row] of body.results.entries()) {
14191
+ if (!object(row) || typeof row.checkId !== "string") return `results[${i}].checkId \u5FC5\u987B\u662F\u5B57\u7B26\u4E32`;
14192
+ if (!["platform", "tenant"].includes(String(row.layer))) return `results[${i}].layer \u5FC5\u987B\u662F platform / tenant`;
14193
+ }
14194
+ if (platformOps && (!Array.isArray(body.checks) || !body.checks.every((row) => object(row) && typeof row.id === "string")))
14195
+ return "checks \u5FC5\u987B\u662F\u5E26\u5B57\u7B26\u4E32 id \u7684\u5BF9\u8C61\u6570\u7EC4";
14196
+ if (body.scope !== void 0 && !object(body.scope)) return "scope \u5FC5\u987B\u662F\u5BF9\u8C61";
14197
+ const disabled = object(body.scope) ? body.scope.policyDisabled : void 0;
14198
+ if (disabled !== void 0 && !Array.isArray(disabled)) return "scope.policyDisabled \u5FC5\u987B\u662F\u6570\u7EC4";
14199
+ for (const [i, row] of (disabled ?? []).entries())
14200
+ if (!object(row) || typeof row.id !== "string" || typeof row.cause !== "string") return `scope.policyDisabled[${i}] \u987B\u542B\u5B57\u7B26\u4E32 id \u4E0E cause`;
14201
+ return void 0;
14202
+ }
14203
+ function failedReport(out, env2, as) {
14204
+ const note = httpNote(out);
14205
+ if (out.status === 429) return unknown("REPORT_THROTTLED", "\u670D\u52A1\u7AEF\u4F53\u68C0\u63A5\u53E3\u8BF7\u6C42\u88AB\u9650\u6D41", { note: throttleNote(out) });
14206
+ if ([401, 403].includes(out.status)) return unknown("REPORT_UNAUTHORIZED", "\u670D\u52A1\u7AEF\u4F53\u68C0\u63A5\u53E3\u8BF7\u6C42\u6743\u9650\u4E0D\u8DB3", {
14207
+ reason: "PERMISSION_DENIED",
14208
+ note: `${note}${as ? `\uFF1B${env2.proxied ? "\u4F7F\u7528\u4EE3\u7406 token" : "\u4F7F\u7528\u672C\u673A token"}` : ""}`,
14209
+ nextStep: codeStep("REPORT_UNAUTHORIZED", env2.name)
14210
+ });
14211
+ if (out.status >= 500 || out.error === "network") return unknown("REPORT_UNAVAILABLE", "\u670D\u52A1\u7AEF\u4F53\u68C0\u62A5\u544A\u6682\u4E0D\u53EF\u7528\uFF1B\u7A0D\u540E\u91CD\u8BD5", { note });
14212
+ if (out.status !== 200) return unknown("REPORT_MALFORMED", "\u670D\u52A1\u7AEF\u4F53\u68C0\u63A5\u53E3\u8FD4\u56DE\u975E\u9884\u671F\u72B6\u6001", {
14213
+ reason: "EVALUATOR_ERROR",
14214
+ note: `${note}\uFF1B${(typeof out.body === "string" ? out.body : JSON.stringify(out.body) ?? "").slice(0, 200)}`
14215
+ });
14216
+ const invalid3 = reportEnvelopeError(out.body);
14217
+ if (invalid3) return unknown("REPORT_MALFORMED", "\u670D\u52A1\u7AEF\u4F53\u68C0\u62A5\u544A\u4FE1\u5C01\u4E0D\u5408\u6CD5", { reason: "EVALUATOR_ERROR", note: `${note}\uFF1B${invalid3}` });
14218
+ return void 0;
14219
+ }
14220
+ function placeholderRows(ctx, env2, observation, duration = 0) {
14221
+ env2.report.server.verdict = null;
14222
+ return SERVER_PLACEHOLDERS.filter((d) => !ctx.scope || ctx.scope.serverLayers.has(d.layer)).map((descriptor2) => makeResult(
14223
+ descriptor2,
14224
+ observation,
14225
+ env2.name,
14226
+ true,
14227
+ ctx.requestedAt,
14228
+ duration,
14229
+ codeStep(observation.code ?? "REPORT_UNAVAILABLE", env2.name)
14230
+ ));
14231
+ }
14232
+ function verdictViolation(row) {
14233
+ const v = row.verdict, c2 = v?.coverage;
14234
+ if (v === void 0 || v === null) return "verdict \u7F3A\u5931";
14235
+ if (typeof v !== "object" || Array.isArray(v)) return "verdict \u4E0D\u662F\u5BF9\u8C61";
14236
+ if (!["PASS", "FOUND", "UNDETERMINED", "NOT_RUN", "NOT_APPLICABLE"].includes(v.level)) return `level=${String(v.level)} \u4E0D\u5728\u4E94\u6863`;
14237
+ if (v.level === "FOUND" && !["CRITICAL", "WARN"].includes(v.grade ?? "")) return "FOUND \u7F3A grade \u6216 grade \u4E0D\u662F CRITICAL / WARN";
14238
+ if (["UNDETERMINED", "NOT_RUN"].includes(v.level) && (typeof v.reason !== "string" || !v.reason.trim())) return `${v.level} \u7F3A reason`;
14239
+ if (v.level === "PASS" && (!c2 || c2.expected == null || c2.evaluated + (c2.notApplicable ?? 0) !== c2.expected || c2.missing + c2.failed !== 0 || !(c2.evaluated > 0 || c2.expected === 0))) return "PASS \u6CA1\u6570\u6EE1";
14240
+ if (v.level === "NOT_APPLICABLE" && !!c2 && c2.missing + c2.failed > 0) return "NOT_APPLICABLE \u5E26\u7F3A\u53E3";
14241
+ return void 0;
14242
+ }
14243
+ function reconcileReport(ctx, env2, report, requested, platformOps) {
14244
+ const known = !platformOps && serverCatalogKnown(env2.catalog, report), changed = !platformOps && catalogChanged(env2.catalog, report);
14245
+ const expected = known && !changed ? expectedServerIds(env2.catalog, report, requested) : new Set(platformOps ? report.scopeIds.filter((id) => id.startsWith("platform.")) : report.scopeIds);
14246
+ const scope = new Set(report.scopeIds), rows2 = [];
14247
+ const issues = /* @__PURE__ */ new Map();
14248
+ const layerFor = (id) => {
14249
+ if (platformOps) return "platform";
14250
+ const layer2 = known ? env2.catalog?.checks.find((c2) => c2.id === id)?.spec?.layer : void 0;
14251
+ return layer2 === "platform" || layer2 === "tenant" ? layer2 : String(id).startsWith("platform.") ? "platform" : "tenant";
14252
+ };
14253
+ const issue = (layer2, note) => issues.set(layer2, [...issues.get(layer2) ?? [], note]);
14254
+ const both2 = (note) => {
14255
+ issue("platform", note);
14256
+ issue("tenant", note);
14257
+ };
14258
+ if (platformOps) {
14259
+ for (const id of report.scopeIds) if (!id.startsWith("platform.")) issue("platform", `${id}\uFF1A\u8FD0\u7EF4\u62A5\u544A\u8303\u56F4\u4E0D\u662F platform`);
14260
+ }
14261
+ const synthesize = (id, code2, note) => {
14262
+ env2.report.server.verdict = null;
14263
+ const catalogRow = known ? env2.catalog?.checks.find((c2) => c2.id === id) : void 0;
14264
+ return makeResult({
14265
+ id,
14266
+ name: catalogRow?.name ?? id,
14267
+ layer: layerFor(id),
14268
+ requirement: catalogRow?.requirement === "OPTIONAL" ? "OPTIONAL" : "REQUIRED",
14269
+ dependsOn: [],
14270
+ owner: "RND"
14271
+ }, unknown(code2, code2 === "REPORT_ITEM_MISSING" ? "\u670D\u52A1\u7AEF\u62A5\u544A\u91CC\u6CA1\u6709\u8FD9\u4E00\u9879\uFF08CLI \u8865\u9879\uFF09" : "\u670D\u52A1\u7AEF\u68C0\u67E5\u7ED3\u8BBA\u4E0D\u5408\u6CD5\uFF08CLI \u6539\u5199\uFF09", {
14272
+ reason: code2 === "REPORT_ITEM_MISSING" ? "SOURCE_UNAVAILABLE" : "EVALUATOR_ERROR",
14273
+ note
14274
+ }), env2.name, true, ctx.requestedAt, 0, codeStep(code2, env2.name));
14275
+ };
14276
+ const rewrite = (row, originals, why) => {
14277
+ const replacement = synthesize(row.checkId, "SERVER_VERDICT_INVALID", `CLI \u6539\u5199\uFF08${why}\uFF09\uFF1B\u539F\u59CB code\uFF1A${originals.map((r) => r.code ?? "\u65E0").join("\uFF1B")}\uFF1B\u539F\u59CB verdict\uFF1A${originals.map((r) => r.verdict === void 0 ? "\u7F3A\u5931" : JSON.stringify(r.verdict)).join("\uFF1B")}`);
14278
+ return { ...row, env: env2.name, verdict: { ...replacement.verdict }, code: replacement.code, summary: replacement.summary, nextStep: replacement.nextStep };
14279
+ };
14280
+ if (!changed) {
14281
+ if (known) {
14282
+ for (const disabled of report.scope?.policyDisabled ?? []) {
14283
+ if (env2.catalog.checks.find((c2) => c2.id === disabled.id)?.requirement !== "OPTIONAL") issue(layerFor(disabled.id), `${disabled.id}\uFF1ApolicyDisabled \u4E0D\u662F\u76EE\u5F55\u9009\u68C0`);
14284
+ if (scope.has(disabled.id)) issue(layerFor(disabled.id), `${disabled.id}\uFF1ApolicyDisabled \u4E0E scopeIds \u76F8\u4EA4`);
14285
+ }
14286
+ for (const id of /* @__PURE__ */ new Set([...expected, ...scope]))
14287
+ if (expected.has(id) !== scope.has(id)) issue(layerFor(id), `${id}\uFF1AscopeIds \u4E0E\u671F\u671B\u96C6\u5408 E \u4E0D\u4E00\u81F4`);
14288
+ }
14289
+ if (known) {
14290
+ const echo = report.scope;
14291
+ const sameTokens = (a, b) => Array.isArray(a) && a.length === b.length && [...a].sort().every((v, i) => v === [...b].sort()[i]);
14292
+ if ((typeof echo?.stage === "string" ? echo.stage.toLowerCase() : echo?.stage) !== (requested.stage?.toLowerCase() ?? null)) both2("scope.stage \u56DE\u663E\u4E0E\u8BF7\u6C42\u4E0D\u7B26");
14293
+ for (const key2 of ["only", "skip"]) if (!sameTokens(echo?.[key2], requested[key2])) both2(`scope.${key2} \u56DE\u663E\u4E0E\u8BF7\u6C42\u4E0D\u7B26`);
14294
+ if (echo?.active !== requested.active) both2("scope.active \u56DE\u663E\u4E0E\u8BF7\u6C42\u4E0D\u7B26");
14295
+ }
14296
+ if (report.returnedCount !== report.results.length || report.totalCount !== report.scopeIds.length)
14297
+ both2(`\u8BA1\u6570\u4E0D\u7B26\uFF1AreturnedCount=${report.returnedCount}\uFF0Cresults.length=${report.results.length}\uFF1BtotalCount=${report.totalCount}\uFF0CscopeIds.length=${report.scopeIds.length}`);
14298
+ }
14299
+ const groups = /* @__PURE__ */ new Map();
14300
+ for (const row of report.results) groups.set(row.checkId, [...groups.get(row.checkId) ?? [], row]);
14301
+ for (const [id, group] of groups) {
14302
+ const row = group[0];
14303
+ if (platformOps && row.layer !== "platform") {
14304
+ issue("platform", `${id}\uFF1A\u8FD0\u7EF4\u62A5\u544A\u7ED3\u679C\u5C42\u4E0D\u662F platform`);
14305
+ continue;
14306
+ }
14307
+ if (!changed && !scope.has(id)) {
14308
+ issue(row.layer, `${id}\uFF1A\u7ED3\u679C\u8D8A\u51FA\u672C\u6B21\u8303\u56F4`);
14309
+ continue;
14310
+ }
14311
+ const why = group.length > 1 ? `\u540C\u4E00 id \u51FA\u73B0 ${group.length} \u6761` : verdictViolation(row);
14312
+ rows2.push(why ? rewrite(row, group, why) : { ...row, env: env2.name });
14313
+ }
14314
+ if (!changed) {
14315
+ for (const id of expected) if (!rows2.some((row) => row.checkId === id))
14316
+ rows2.push(synthesize(id, "REPORT_ITEM_MISSING", "CLI \u8865\u9879\uFF1A\u670D\u52A1\u7AEF\u62A5\u544A\u91CC\u6CA1\u6709\u8FD9\u4E00\u9879"));
14317
+ }
14318
+ const selected = (layer2) => (layer2 === "platform" || layer2 === "tenant") && (platformOps ? layer2 === "platform" : !ctx.scope || ctx.scope.serverLayers.has(layer2));
14319
+ const marks = /* @__PURE__ */ new Map();
14320
+ for (const [layer2, notes] of issues) {
14321
+ const home = selected(layer2) ? layer2 : platformOps ? "platform" : SERVER_PLACEHOLDERS.map((d) => d.layer).find(selected);
14322
+ marks.set(home, [...marks.get(home) ?? [], ...notes.map((note) => home === layer2 ? note : `${String(layer2)} \u5C42\uFF08\u4E0D\u5728\u672C\u6B21\u8303\u56F4\uFF09\uFF1A${note}`)]);
14323
+ }
14324
+ for (const [layer2, notes] of marks) {
14325
+ env2.report.server.verdict = null;
14326
+ const observation = unknown("REPORT_MALFORMED", "\u670D\u52A1\u7AEF\u4F53\u68C0\u62A5\u544A\u5BF9\u8D26\u4E0D\u7B26\uFF08CLI \u6807\u8BB0\uFF09", { reason: "EVALUATOR_ERROR", note: notes.join("\uFF1B") });
14327
+ rows2.push(...platformOps ? [makeResult(
14328
+ platformOps.placeholder,
14329
+ observation,
14330
+ env2.name,
14331
+ true,
14332
+ ctx.requestedAt,
14333
+ 0,
14334
+ codeStep("REPORT_MALFORMED", env2.name)
14335
+ )] : placeholderRows(ctx, env2, observation).filter((r) => r.layer === layer2));
14336
+ }
14337
+ return rows2;
14338
+ }
14339
+ async function fetchServerReport(ctx, env2, dependencies, deadline, requested = fullScope) {
14340
+ const [identity3, health] = dependencies;
14341
+ const missing = SERVER_PLACEHOLDERS[0].dependsOn.filter((_, i) => dependencies[i]?.verdict.level !== "PASS");
14342
+ const prerequisites = (note) => placeholderRows(ctx, env2, {
14343
+ level: "NOT_RUN",
14344
+ code: "PREREQUISITE_NOT_MET",
14345
+ reason: "PREREQUISITE_NOT_MET",
14346
+ summary: "\u670D\u52A1\u7AEF\u4F53\u68C0\u62A5\u544A\u672A\u6267\u884C\uFF1A\u524D\u7F6E\u68C0\u67E5\u672A\u901A\u8FC7",
14347
+ note
14348
+ });
14349
+ if (identity3?.verdict.level !== "PASS" || !health || health.verdict.level === "NOT_RUN") return prerequisites(missing.join(", "));
14350
+ if (health.code === "BACKEND_UNSUPPORTED") return placeholderRows(ctx, env2, {
14351
+ level: "NOT_RUN",
14352
+ code: health.code,
14353
+ reason: "CAPABILITY_UNSUPPORTED",
14354
+ summary: "\u540E\u7AEF\u4E0D\u652F\u6301\u4F53\u68C0\u62A5\u544A",
14355
+ note: `${health.verdict.note ?? ""}\uFF1B${env2.report.backend.commit ? `\u540E\u7AEF commit ${env2.report.backend.commit}` : "commit \u672A\u77E5"}`
14356
+ });
14357
+ if (health.verdict.level !== "PASS") {
14358
+ if (["HEALTH_API_ROUTE_MISSING", "REPORT_THROTTLED", "REPORT_UNAUTHORIZED", "REPORT_UNAVAILABLE", "REPORT_MALFORMED"].includes(health.code ?? ""))
14359
+ return placeholderRows(ctx, env2, unknown(health.code, health.summary, {
14360
+ reason: health.code === "REPORT_UNAUTHORIZED" ? "PERMISSION_DENIED" : health.code === "REPORT_MALFORMED" ? "EVALUATOR_ERROR" : "SOURCE_UNAVAILABLE",
14361
+ note: health.verdict.note
14362
+ }));
14363
+ return prerequisites(`connect.health-api\uFF1A${health.code ?? health.verdict.level}`);
14364
+ }
14365
+ const remaining = deadline - Date.now();
14366
+ if (remaining < 3e3) return placeholderRows(ctx, env2, unknown("BUDGET_EXHAUSTED", "\u9884\u7B97\u8017\u5C3D\uFF0C\u672A\u542F\u52A8\uFF1B\u7A0D\u540E\u91CD\u8DD1", { note: "\u9884\u7B97\u8017\u5C3D\uFF0C\u672A\u542F\u52A8" }));
14367
+ const timeoutMs = Math.min(25e3, remaining), budgetMs = Math.min(15e3, timeoutMs - 2e3), started = Date.now();
14368
+ const controller = new AbortController();
14369
+ let timer;
14370
+ try {
14371
+ const expired = new Promise((_, reject) => {
14372
+ timer = setTimeout(() => {
14373
+ controller.abort();
14374
+ reject(new Error("\u5DF2\u505C\u6B62\u7B49\u5F85"));
14375
+ }, timeoutMs);
14376
+ });
14377
+ const request = ctx.scope ? ctx.services.reportRequest(env2.config.endpoint, env2.token, timeoutMs, budgetMs, controller.signal, requested) : ctx.services.reportRequest(env2.config.endpoint, env2.token, timeoutMs, budgetMs, controller.signal);
14378
+ const out = await Promise.race([request, expired]);
14379
+ const error = object(out.body) && object(out.body.error) ? out.body.error : void 0;
14380
+ const details = object(error?.details) ? error.details : void 0;
14381
+ if (out.status === 400 && error?.code === "HEALTH_REPORT_INVALID_PARAM" && Array.isArray(details?.policyDisabled) && details.policyDisabled.length > 0 && details.policyDisabled.every((row) => object(row) && typeof row.id === "string" && typeof row.by === "string" && typeof row.at === "string" && typeof row.cause === "string")) {
14382
+ env2.serverReport = {
14383
+ schemaVersion: 1,
14384
+ results: [],
14385
+ scopeIds: [],
14386
+ totalCount: 0,
14387
+ returnedCount: 0,
14388
+ catalogRevision: env2.catalog?.catalogRevision,
14389
+ scope: { ...requested, policyDisabled: details.policyDisabled },
14390
+ recoveryCommand: typeof error.next_step === "string" ? error.next_step : void 0
14391
+ };
14392
+ env2.report.server.verdict = null;
14393
+ return [];
14394
+ }
14395
+ const failure2 = failedReport(out, env2, ctx.as);
14396
+ if (failure2) return placeholderRows(ctx, env2, failure2, Date.now() - started);
14397
+ const report = out.body;
14398
+ env2.serverReport = report;
14399
+ Object.assign(env2.report.server, {
14400
+ deploymentTenancy: report.deploymentTenancy ?? null,
14401
+ instance: report.instance ?? null,
14402
+ verdict: report.verdict ?? null,
14403
+ catalogRevision: report.catalogRevision ?? null
14404
+ });
14405
+ if (catalogChanged(env2.catalog, report)) {
14406
+ try {
14407
+ const refreshed = await ctx.services.probe(env2.config.endpoint, env2.token, controller.signal).get("/api/system/health/checks");
14408
+ const catalog = refreshed.status === 200 ? parseCatalog(refreshed.body) : void 0;
14409
+ if (catalog && catalog.catalogRevision === report.catalogRevision) env2.catalog = catalog;
14410
+ } catch {
14411
+ }
14412
+ }
14413
+ return reconcileReport(ctx, env2, report, requested);
14414
+ } catch (error) {
14415
+ const stopped = controller.signal.aborted || axios6.isAxiosError(error) && ["ECONNABORTED", "ETIMEDOUT"].includes(error.code ?? "");
14416
+ return placeholderRows(ctx, env2, unknown("REPORT_UNAVAILABLE", "\u670D\u52A1\u7AEF\u4F53\u68C0\u62A5\u544A\u6682\u4E0D\u53EF\u7528\uFF1B\u7A0D\u540E\u91CD\u8BD5", {
14417
+ note: `HTTP \u672A\u53D6\u5F97\u54CD\u5E94\uFF1B${stopped ? "\u5DF2\u505C\u6B62\u7B49\u5F85" : safeError(error)}`
14418
+ }), Date.now() - started);
14419
+ } finally {
14420
+ clearTimeout(timer);
14421
+ }
14422
+ }
14423
+
14424
+ // src/commands/doctor/connect-checks.ts
14132
14425
  var obj = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
14133
14426
  var json = (o) => o.body !== null && o.body !== void 0;
14134
14427
  var probe = (ctx, env2, execution, authenticated = true) => ctx.services.probe(env2.config.endpoint, authenticated ? env2.token : void 0, execution.signal);
@@ -14141,8 +14434,8 @@ var connectivity = async (ctx, env2, execution) => {
14141
14434
  };
14142
14435
  return pass("\u540E\u7AEF\u7248\u672C\u7AEF\u70B9\u53EF\u8FBE\uFF08\u514D\u8BA4\u8BC1\uFF09");
14143
14436
  }
14144
- const code = out.error === "network" ? "BACKEND_UNREACHABLE" : out.error === "server-error" ? "BACKEND_SERVER_ERROR" : out.error === "not-found" ? "BACKEND_NOT_FOUND" : ["unauthorized", "forbidden"].includes(out.error) ? "BACKEND_REJECTED" : out.status >= 200 && out.status < 300 && !json(out) && !/json/i.test(out.headers["content-type"] ?? "") ? "BACKEND_NOT_JSON" : "BACKEND_BAD_RESPONSE";
14145
- return found(code, void 0, { note: `HTTP ${out.status < 0 ? "\u672A\u53D6\u5F97\u54CD\u5E94" : out.status}` });
14437
+ const code2 = out.error === "network" ? "BACKEND_UNREACHABLE" : out.error === "server-error" ? "BACKEND_SERVER_ERROR" : out.error === "not-found" ? "BACKEND_NOT_FOUND" : ["unauthorized", "forbidden"].includes(out.error) ? "BACKEND_REJECTED" : out.status >= 200 && out.status < 300 && !json(out) && !/json/i.test(out.headers["content-type"] ?? "") ? "BACKEND_NOT_JSON" : "BACKEND_BAD_RESPONSE";
14438
+ return found(code2, void 0, { note: `HTTP ${out.status < 0 ? "\u672A\u53D6\u5F97\u54CD\u5E94" : out.status}` });
14146
14439
  };
14147
14440
  function identityOutcome(out, env2, username) {
14148
14441
  if (out.status === 401) return found("TOKEN_REJECTED", void 0, { note: "\u53EF\u80FD\u539F\u56E0\uFF1A\u8FC7\u671F / \u88AB\u540A\u9500 / \u8D85\u51FA\u79DF\u6237\u5E76\u53D1\u4F1A\u8BDD\u4E0A\u9650\uFF08\u82E5\u8BE5\u79DF\u6237\u914D\u7F6E\u4E86\uFF09" });
@@ -14173,6 +14466,7 @@ var identity = async (ctx, env2, execution) => {
14173
14466
  );
14174
14467
  e.close = auth.closeEphemeralSession;
14175
14468
  e.token = auth.ephemeralAccessToken;
14469
+ e.proxied = !!auth.impersonation;
14176
14470
  const out2 = auth.verifiedPrincipal ? { status: 200, body: auth.verifiedPrincipal, headers: {}, error: "ok" } : await probeDoctorEndpoint(probe(ctx, e, execution), "identity");
14177
14471
  const observation = identityOutcome(out2, e, auth.verifiedPrincipal?.username);
14178
14472
  if (auth.impersonation) observation.note = `\u7ECF ${auth.impersonation.actorIdentity} \u4EE3\u7406\u6838\u9A8C`;
@@ -14187,13 +14481,13 @@ var identity = async (ctx, env2, execution) => {
14187
14481
  const actorCode = actorStep === "meta" || actorStep === "env" ? "IDENTITY_META_INVALID" : actorStep === "resolve" && errorCode === "IDENTITY_NOT_FOUND" ? "IDENTITY_NOT_LOGGED_IN" : "IDENTITY_UNVERIFIED";
14188
14482
  return (actorCode === "IDENTITY_UNVERIFIED" ? unknown : found)(actorCode, void 0, { note: `\u64CD\u4F5C\u8005\u8EAB\u4EFD\u4E0D\u53EF\u7528\uFF0C\u672A\u53D1\u8D77\u4EE3\u7406\uFF1A${safeError(error)}` });
14189
14483
  }
14190
- const status = axios6.isAxiosError(error) ? error.response?.status : void 0;
14191
- const envelope = status === 404 && axios6.isAxiosError(error) && error.config?.url?.endsWith("/impersonation/start") ? error.response?.data?.error : void 0;
14484
+ const status = axios7.isAxiosError(error) ? error.response?.status : void 0;
14485
+ const envelope = status === 404 && axios7.isAxiosError(error) && error.config?.url?.endsWith("/impersonation/start") ? error.response?.data?.error : void 0;
14192
14486
  const targetMissing = envelope?.code === "NOT_FOUND";
14193
14487
  const targetAdvice = envelope?.details === "\u76EE\u6807\u7528\u6237\u4E0D\u5B58\u5728" ? "\u670D\u52A1\u7AEF\uFF1A\u76EE\u6807\u7528\u6237\u4E0D\u5B58\u5728\uFF1B\u6838\u5BF9\u5F53\u524D\u79DF\u6237\u4E0E\u76EE\u6807\u7528\u6237 UUID" : "\u670D\u52A1\u7AEF\u56DE 404 NOT_FOUND\uFF0C\u672A\u6307\u660E\u76EE\u6807\u7528\u6237\u4E0D\u5B58\u5728\uFF08\u4E5F\u53EF\u80FD\u662F\u540E\u7AEF\u6CA1\u6709\u4EE3\u7406\u63A5\u53E3\uFF09\uFF1B\u6838\u5BF9\u5F53\u524D\u79DF\u6237\u4E0E\u76EE\u6807\u7528\u6237 UUID\uFF0C\u5E76\u6838\u540E\u7AEF\u7248\u672C";
14194
- const code = status === 403 || targetMissing || errorCode && ["SCOPE_FORBIDDEN", "IDENTITY_NOT_FOUND", "INVALID_ARGUMENT", "IDENTITY_NOT_IN_ENV", "IDENTITY_META_INCOMPLETE"].includes(errorCode) ? "AS_PROXY_DENIED" : errorCode === "AUTH_FAILED" ? "IDENTITY_NOT_LOGGED_IN" : status === 401 ? "TOKEN_REJECTED" : "IDENTITY_UNVERIFIED";
14488
+ const code2 = status === 403 || targetMissing || errorCode && ["SCOPE_FORBIDDEN", "IDENTITY_NOT_FOUND", "INVALID_ARGUMENT", "IDENTITY_NOT_IN_ENV", "IDENTITY_META_INCOMPLETE"].includes(errorCode) ? "AS_PROXY_DENIED" : errorCode === "AUTH_FAILED" ? "IDENTITY_NOT_LOGGED_IN" : status === 401 ? "TOKEN_REJECTED" : "IDENTITY_UNVERIFIED";
14195
14489
  const note = detail?.issuance === "unconfirmed" ? "\u4EE3\u7406\u7B7E\u53D1\u8BF7\u6C42\u88AB\u4E2D\u6B62\uFF1B\u670D\u52A1\u7AEF\u53EF\u80FD\u5DF2\u7B7E\u53D1\uFF0C\u5BA2\u6237\u7AEF\u62FF\u4E0D\u5230\u4F1A\u8BDD\uFF0C\u670D\u52A1\u7AEF\u6309\u6709\u6548\u671F\u81EA\u7136\u8FC7\u671F" : detail?.cleanup === "unconfirmed" ? "\u4EE3\u7406\u4F1A\u8BDD\u6536\u5C3E\u5931\u8D25\uFF0C\u670D\u52A1\u7AEF\u6309\u6709\u6548\u671F\u81EA\u7136\u8FC7\u671F" : safeError(error);
14196
- return (code === "IDENTITY_UNVERIFIED" ? unknown : found)(code, void 0, {
14490
+ return (code2 === "IDENTITY_UNVERIFIED" ? unknown : found)(code2, void 0, {
14197
14491
  note: `${note}${typeof detail?.nextStep === "string" ? `\uFF1B${detail.nextStep}` : targetMissing ? `\uFF1B${targetAdvice}` : ""}`
14198
14492
  });
14199
14493
  }
@@ -14224,23 +14518,25 @@ var websocket = async (ctx, env2) => {
14224
14518
  }
14225
14519
  };
14226
14520
  function classifyHealthApi(out) {
14227
- const note = `HTTP ${out.status}${out.headers["x-trace-id"] ? ` \xB7 traceId=${out.headers["x-trace-id"]}` : ""}`;
14228
- if (out.status === 429) return unknown("REPORT_THROTTLED", void 0, { note: `${note} \xB7 retryAfter=${out.headers["retry-after"] ?? "\u672A\u63D0\u4F9B"}` });
14521
+ const note = httpNote(out);
14522
+ if (out.status === 429) return unknown("REPORT_THROTTLED", void 0, { note: throttleNote(out) });
14229
14523
  if ([401, 403].includes(out.status)) return unknown("REPORT_UNAUTHORIZED", void 0, { reason: "PERMISSION_DENIED", note });
14230
- if (out.status >= 500 || out.error === "network") return unknown("REPORT_UNAVAILABLE", void 0, { note });
14524
+ if (out.status >= 500) return unknown("REPORT_UNAVAILABLE", "\u670D\u52A1\u7AEF\u4F53\u68C0\u76EE\u5F55\u6682\u4E0D\u53EF\u7528\uFF1B\u7A0D\u540E\u91CD\u8BD5\uFF0C\u82E5\u540E\u7AEF\u65E9\u4E8E #2318 \u5219\u5148\u5347\u7EA7\u540E\u7AEF", { note });
14525
+ if (out.error === "network") return unknown("REPORT_UNAVAILABLE", "\u670D\u52A1\u7AEF\u4F53\u68C0\u76EE\u5F55\u6682\u4E0D\u53EF\u7528\uFF1B\u7A0D\u540E\u91CD\u8BD5", { note });
14231
14526
  if (out.status === 404) {
14232
14527
  const envelope = obj(out.body) && obj(out.body.error) && out.body.error.code === "NOT_FOUND" && typeof out.body.error.message === "string";
14233
14528
  if (out.headers["x-trace-id"] && envelope) return found("BACKEND_UNSUPPORTED", void 0, { note });
14234
14529
  return found("HEALTH_API_ROUTE_MISSING", void 0, { evidence: "INFERRED", note: `${note}\uFF1B\u7F3A\u540E\u7AEF traceId \u6216 HCM \u4FE1\u5C01\uFF1B\u4EE3\u7406\u4E5F\u53EF\u80FD\u5265\u6389\u54CD\u5E94\u5934` });
14235
14530
  }
14236
- if (out.status === 200 && json(out)) return pass("\u540E\u7AEF\u652F\u6301\u4F53\u68C0 API");
14531
+ if (out.status === 200 && parseCatalog(out.body)) return pass("\u540E\u7AEF\u652F\u6301\u4F53\u68C0 API");
14237
14532
  if (out.status === 200 && /text\/html/i.test(out.headers["content-type"] ?? ""))
14238
14533
  return found("HEALTH_API_ROUTE_MISSING", void 0, { evidence: "INFERRED", note: `${note}\uFF1B\u6536\u5230 HTML\uFF0C\u63A8\u65AD\u8DEF\u7531\u843D\u5230\u524D\u7AEF SPA` });
14239
- return unknown("REPORT_MALFORMED", void 0, { reason: "EVALUATOR_ERROR", note });
14534
+ return unknown("REPORT_MALFORMED", void 0, { reason: "EVALUATOR_ERROR", note: `${note}\uFF1B\u76EE\u5F55\u987B\u542B checks\u3001reservedCodes \u6570\u7EC4\uFF08checks \u6BCF\u9879\u662F\u5E26\u5B57\u7B26\u4E32 id \u7684\u5BF9\u8C61\uFF09\u3001catalogRevision \u5B57\u7B26\u4E32\u6216 null\u3001tenantCatalog \u5BF9\u8C61` });
14240
14535
  }
14241
14536
  var healthApi = async (ctx, env2, execution) => {
14242
14537
  const out = await probeDoctorEndpoint(probe(ctx, env2, execution), "health-api");
14243
14538
  const result = classifyHealthApi(out);
14539
+ if (result.level === "PASS") env2.catalog = parseCatalog(out.body);
14244
14540
  env2.report.server.supported = result.level === "PASS" ? true : result.code === "BACKEND_UNSUPPORTED" ? false : null;
14245
14541
  return result;
14246
14542
  };
@@ -14312,13 +14608,18 @@ var CODE_TABLE = {
14312
14608
  EXPOSURE_UNCHECKED: c("\u672A\u80FD\u6838\u5B9E\u533F\u540D\u5065\u5EB7\u7AEF\u70B9\uFF1B\u68C0\u67E5\u5165\u53E3\u4E0E\u670D\u52A1", "WARN", "CUSTOMER_OPS"),
14313
14609
  BACKEND_UNSUPPORTED: c("\u540E\u7AEF\u6CA1\u6709\u4F53\u68C0\u8DEF\u7531\uFF1B\u5347\u7EA7\u540E\u7AEF"),
14314
14610
  HEALTH_API_ROUTE_MISSING: c("\u63A8\u65AD\u4F53\u68C0\u8DEF\u7531\u672A\u5230\u540E\u7AEF\uFF1B\u68C0\u67E5\u53CD\u4EE3\u653E\u884C\u4E0E\u54CD\u5E94\u5934"),
14315
- REPORT_THROTTLED: c("\u4F53\u68C0\u76EE\u5F55\u8BF7\u6C42\u88AB\u9650\u6D41\uFF1B\u6309 retryAfter \u7A0D\u540E\u91CD\u8BD5"),
14316
- REPORT_UNAUTHORIZED: c("\u4F53\u68C0\u76EE\u5F55\u8BF7\u6C42\u6743\u9650\u4E0D\u8DB3", "WARN", "FDE", login),
14317
- REPORT_UNAVAILABLE: c("\u4F53\u68C0\u76EE\u5F55\u6682\u4E0D\u53EF\u7528\uFF1B\u7A0D\u540E\u91CD\u8BD5\uFF0C\u82E5\u540E\u7AEF\u65E9\u4E8E #2318 \u5219\u5148\u5347\u7EA7\u540E\u7AEF"),
14318
- REPORT_MALFORMED: c("\u4F53\u68C0\u76EE\u5F55\u54CD\u5E94\u65E0\u6CD5\u89E3\u6790\uFF1B\u8054\u7CFB\u7814\u53D1\u6838\u5BF9\u534F\u8BAE", "WARN", "RND")
14611
+ REPORT_THROTTLED: c("\u670D\u52A1\u7AEF\u4F53\u68C0\u63A5\u53E3\u8BF7\u6C42\u88AB\u9650\u6D41\uFF1B\u6309 retryAfter \u7A0D\u540E\u91CD\u8BD5"),
14612
+ REPORT_UNAUTHORIZED: c("\u670D\u52A1\u7AEF\u4F53\u68C0\u63A5\u53E3\u8BF7\u6C42\u6743\u9650\u4E0D\u8DB3", "WARN", "FDE", login),
14613
+ HEALTH_OPS_KEY_INVALID: c("\u8FD0\u7EF4\u53EA\u8BFB\u5BC6\u94A5\u88AB\u62D2\uFF1A\u6CA1\u5E26\u3001\u4E0D\u5339\u914D\uFF0C\u6216\u670D\u52A1\u7AEF\u6CA1\u914D / \u5DF2\u505C\u7528", "WARN", "RND"),
14614
+ HEALTH_OPS_KEY_LOCKED: c("\u8BE5\u6765\u6E90\u8FD0\u7EF4\u5BC6\u94A5\u8FDE\u9519\u88AB\u9501\uFF1B\u6309 retryAfter \u7B49\u5F85\u540E\u7528\u6B63\u786E\u5BC6\u94A5\u91CD\u8BD5", "WARN", "RND"),
14615
+ REPORT_UNAVAILABLE: c("\u670D\u52A1\u7AEF\u4F53\u68C0\u63A5\u53E3\u6682\u4E0D\u53EF\u7528\uFF1B\u7A0D\u540E\u91CD\u8BD5"),
14616
+ REPORT_MALFORMED: c("\u670D\u52A1\u7AEF\u4F53\u68C0\u63A5\u53E3\u54CD\u5E94\u65E0\u6CD5\u89E3\u6790\uFF1B\u8054\u7CFB\u7814\u53D1\u6838\u5BF9\u534F\u8BAE", "WARN", "RND"),
14617
+ REPORT_ITEM_MISSING: c("\u670D\u52A1\u7AEF\u62A5\u544A\u91CC\u6CA1\u6709\u8FD9\u4E00\u9879", "WARN", "RND"),
14618
+ SERVER_VERDICT_INVALID: c("\u670D\u52A1\u7AEF\u68C0\u67E5\u7ED3\u8BBA\u4E0D\u5408\u6CD5\uFF1B\u8054\u7CFB\u7814\u53D1\u6838\u5BF9\u534F\u8BAE", "WARN", "RND"),
14619
+ BUDGET_EXHAUSTED: c("\u9884\u7B97\u8017\u5C3D\uFF0C\u672A\u542F\u52A8\uFF1B\u7A0D\u540E\u91CD\u8DD1")
14319
14620
  };
14320
- function codeStep(code, env2) {
14321
- const row = CODE_TABLE[code];
14621
+ function codeStep(code2, env2) {
14622
+ const row = CODE_TABLE[code2];
14322
14623
  return { owner: row?.owner ?? "FDE", ...row?.command ? { command: row.command(env2) } : {} };
14323
14624
  }
14324
14625
  var allStages = ["handover", "baseline", "configure", "migrate", "integrate", "golive", "operate"];
@@ -14356,33 +14657,73 @@ var CHECKS = [
14356
14657
  descriptor("connect.health-api", "\u4F53\u68C0 API", ["connect.connectivity", "connect.identity"], ["BACKEND_UNSUPPORTED", "HEALTH_API_ROUTE_MISSING", "REPORT_THROTTLED", "REPORT_UNAUTHORIZED", "REPORT_UNAVAILABLE", "REPORT_MALFORMED"], 1e4, connectChecks.healthApi),
14357
14658
  descriptor("connect.exposure", "\u533F\u540D\u66B4\u9732", ["connect.connectivity"], ["ACTUATOR_DETAILS_EXPOSED", "EXPOSURE_UNCHECKED"], 1e4, connectChecks.exposure, false, "CUSTOMER_OPS")
14358
14659
  ];
14660
+ var SERVER_PLACEHOLDERS = ["platform", "tenant"].map((layer2) => ({
14661
+ id: `${layer2}.server-report`,
14662
+ name: layer2 === "platform" ? "\u5E73\u53F0\u4F53\u68C0\u62A5\u544A" : "\u79DF\u6237\u4F53\u68C0\u62A5\u544A",
14663
+ layer: layer2,
14664
+ requirement: "REQUIRED",
14665
+ owner: "FDE",
14666
+ dependsOn: ["connect.identity", "connect.health-api"],
14667
+ codes: [
14668
+ "BACKEND_UNSUPPORTED",
14669
+ "HEALTH_API_ROUTE_MISSING",
14670
+ "REPORT_THROTTLED",
14671
+ "REPORT_UNAUTHORIZED",
14672
+ "REPORT_UNAVAILABLE",
14673
+ "REPORT_MALFORMED",
14674
+ "REPORT_ITEM_MISSING",
14675
+ "SERVER_VERDICT_INVALID",
14676
+ "BUDGET_EXHAUSTED"
14677
+ ]
14678
+ }));
14359
14679
  async function executeChecks(ctx, options = {}) {
14360
14680
  const deadline = Date.now() + (options.budgetMs ?? 45e3);
14361
14681
  const checks = options.checks ?? CHECKS;
14362
- const jobs = checks.flatMap((d) => d.layer === "connect" || d.id === "local.credential" ? ctx.environments.length ? ctx.environments.map((env2) => ({ d, env: env2 })) : d.id === "local.credential" ? [{ d, env: void 0 }] : [] : [{ d, env: void 0 }]);
14682
+ const jobs = checks.flatMap((d) => d.layer === "connect" || d.id === "local.credential" ? ctx.environments.length ? ctx.environments.map((env2) => ({ d, env: env2 })) : d.id === "local.credential" ? [{ d, env: void 0 }] : [] : [{ d, env: void 0 }]).filter(({ d, env: env2 }) => {
14683
+ if (options.onlyTarget && env2 && !env2.report.target) return false;
14684
+ if (!ctx.scope) return true;
14685
+ const selected = (!ctx.scope.stage || d.stages.includes(ctx.scope.stage)) && (!ctx.scope.only.length || ctx.scope.only.some((t) => d.id.startsWith(t))) && !ctx.scope.skip.some((t) => d.id.startsWith(t));
14686
+ return selected || !!env2?.report.target && ctx.scope.addedPrerequisites.includes(d.id);
14687
+ });
14363
14688
  const pending = /* @__PURE__ */ new Map();
14364
14689
  const key2 = (id, env2) => `${id}:${id === "local.project.env" ? "" : env2?.name ?? ""}`;
14690
+ for (const row of options.precomputed ?? []) pending.set(`${row.checkId}:${row.checkId === "local.project.env" ? "" : row.env ?? ""}`, Promise.resolve(row));
14365
14691
  for (const { d, env: env2 } of jobs) {
14692
+ if (pending.has(key2(d.id, env2))) continue;
14366
14693
  const job = (async () => {
14367
14694
  const dependencies = await Promise.all(d.dependsOn.map((id) => pending.get(key2(id, env2))));
14368
- const failed2 = dependencies.filter((r) => r?.verdict.level !== "PASS").map((r, i) => r?.checkId ?? d.dependsOn[i]);
14695
+ const failed2 = d.dependsOn.filter((_, i) => dependencies[i]?.verdict.level !== "PASS");
14369
14696
  const finish = (o, duration = 0) => {
14370
- const code = o.code && CODE_TABLE[o.code];
14697
+ const code2 = o.code && CODE_TABLE[o.code];
14371
14698
  return makeResult(
14372
14699
  d,
14373
14700
  {
14374
14701
  ...o,
14375
- grade: o.grade ?? (code ? code.grade : void 0),
14376
- summary: o.summary === o.code && code ? code.summary : o.summary
14702
+ grade: o.grade ?? (code2 ? code2.grade : void 0),
14703
+ summary: o.summary === o.code && code2 ? code2.summary : o.summary
14377
14704
  },
14378
14705
  env2?.name ?? null,
14379
14706
  !env2 || env2.report.target,
14380
14707
  ctx.requestedAt,
14381
14708
  duration,
14382
- o.code && code ? codeStep(o.code, env2?.name ?? ctx.targetEnv ?? "default") : { owner: d.owner }
14709
+ o.code && code2 ? codeStep(o.code, env2?.name ?? ctx.targetEnv ?? "default") : { owner: d.owner }
14383
14710
  );
14384
14711
  };
14385
- if (failed2.length) return finish({ level: "NOT_RUN", code: "PREREQUISITE_NOT_MET", summary: "\u524D\u7F6E\u68C0\u67E5\u672A\u901A\u8FC7", note: failed2.join(", "), reason: "PREREQUISITE_NOT_MET" });
14712
+ if (failed2.length) {
14713
+ const missing = failed2.filter((id) => !pending.has(key2(id, env2)));
14714
+ const observation = {
14715
+ level: "NOT_RUN",
14716
+ code: "PREREQUISITE_NOT_MET",
14717
+ summary: missing.length ? "\u524D\u7F6E\u9879\u4E0D\u5728\u672C\u6B21\u8303\u56F4\u5185" : "\u524D\u7F6E\u68C0\u67E5\u672A\u901A\u8FC7",
14718
+ note: failed2.map((id) => missing.includes(id) ? `\u524D\u7F6E\u9879 ${id} \u4E0D\u5728\u672C\u6B21\u8303\u56F4\u5185` : id).join(", "),
14719
+ reason: "PREREQUISITE_NOT_MET"
14720
+ };
14721
+ if (missing.length) observation.nextStep = {
14722
+ owner: d.owner,
14723
+ command: `hcm chiron doctor --env ${quote(env2?.name ?? ctx.targetEnv ?? "<env>")}${ctx.as ? ` --as ${quote(ctx.as)}` : ""} --only ${[d.id, ...missing].join(",")}`
14724
+ };
14725
+ return finish(observation);
14726
+ }
14386
14727
  if (Date.now() >= deadline) return finish(unknown("BUDGET_EXHAUSTED", "\u9884\u7B97\u8017\u5C3D\uFF0C\u672A\u542F\u52A8", { note: "\u9884\u7B97\u8017\u5C3D\uFF0C\u672A\u542F\u52A8" }));
14387
14728
  const start = Date.now();
14388
14729
  const controller = new AbortController();
@@ -14421,40 +14762,120 @@ async function executeChecks(ctx, options = {}) {
14421
14762
  })();
14422
14763
  pending.set(key2(d.id, env2), job);
14423
14764
  }
14424
- return Promise.all(pending.values());
14765
+ const target = ctx.environments.find((env2) => env2.report.target);
14766
+ const serverTask = target && options.fetchReport !== false && (!ctx.scope || ctx.scope.serverLayers.size > 0) ? Promise.all(SERVER_PLACEHOLDERS[0].dependsOn.map((id) => pending.get(key2(id, target)))).then((dependencies) => fetchServerReport(ctx, target, dependencies, deadline, ctx.scope ? { stage: ctx.scope.stage, only: ctx.scope.forwardedOnly, skip: ctx.scope.forwardedSkip, active: ctx.scope.active } : void 0)) : Promise.resolve([]);
14767
+ const [localAndConnect, server] = await Promise.all([Promise.all(jobs.map(({ d, env: env2 }) => pending.get(key2(d.id, env2)))), serverTask]);
14768
+ return [...localAndConnect, ...server];
14425
14769
  }
14426
14770
 
14427
14771
  // src/commands/doctor/report.ts
14772
+ var isOptIn = (r) => r.verdict?.level === "NOT_RUN" && r.verdict.reason === "OPT_IN_REQUIRED";
14428
14773
  function conclude(results, ctx) {
14429
- const blocked = results.some((r) => r.verdict.level === "FOUND" && r.verdict.grade === "CRITICAL");
14430
- const risks = results.some((r) => r.verdict.level === "FOUND" || r.verdict.level === "UNDETERMINED" || r.verdict.level === "NOT_RUN" && r.verdict.reason !== "OPT_IN_REQUIRED");
14774
+ const blocked = results.some((r) => r.verdict?.level === "FOUND" && r.verdict.grade === "CRITICAL");
14775
+ const risks = results.some((r) => r.verdict?.level === "FOUND" || r.verdict?.level === "UNDETERMINED" || r.verdict?.level === "NOT_RUN" && !isOptIn(r));
14431
14776
  const verdict = blocked ? "BLOCKED" : risks || ctx.total === null || ctx.total <= 0 ? "READY_WITH_RISKS" : "READY";
14432
14777
  return { verdict, exitCode: verdict === "BLOCKED" || ctx.failOn === "risks" && verdict === "READY_WITH_RISKS" ? 3 : 0 };
14433
14778
  }
14779
+ var reportCatalogs = /* @__PURE__ */ new WeakMap();
14434
14780
  function assembleReport(input) {
14435
14781
  const counts = { PASS: 0, FOUND: 0, UNDETERMINED: 0, NOT_RUN: 0, NOT_APPLICABLE: 0 };
14436
14782
  const foundByGrade = { CRITICAL: 0, WARN: 0 };
14437
14783
  for (const result of input.results) {
14438
- counts[result.verdict.level]++;
14439
- if (result.verdict.level === "FOUND") foundByGrade[result.verdict.grade]++;
14784
+ const level = result.verdict?.level;
14785
+ if (level && Object.hasOwn(counts, level)) counts[level]++;
14786
+ const grade = result.verdict?.grade;
14787
+ if (level === "FOUND" && (grade === "CRITICAL" || grade === "WARN")) foundByGrade[grade]++;
14788
+ }
14789
+ const targetResults = input.results.filter((r) => r.env === null || r.env === input.targetEnv);
14790
+ if (input.platformOps) {
14791
+ const known2 = !!input.serverReport && input.serverReport.catalogRevision != null;
14792
+ const expected2 = new Set(input.serverReport?.scopeIds ?? []);
14793
+ const checked2 = targetResults.filter((r) => ["PASS", "FOUND", "NOT_APPLICABLE"].includes(r.verdict?.level) && (r.layer === "connect" || expected2.has(r.checkId))).length;
14794
+ const total2 = known2 ? targetResults.filter((r) => r.layer === "connect").length + expected2.size : null;
14795
+ const incomplete2 = /* @__PURE__ */ new Set([
14796
+ "platform-ops-view",
14797
+ ...!known2 ? ["server-catalog-unknown"] : [],
14798
+ ...input.scope?.only.length ? ["only"] : [],
14799
+ ...(input.scope?.skip ?? []).map((t) => `skip:${t}`),
14800
+ ...known2 && expected2.size === 0 ? ["empty-layer:platform"] : [],
14801
+ ...(input.serverReport?.scope?.incompleteBecause ?? []).filter((t) => t !== "only" && !t.startsWith("skip:") && !t.startsWith("empty-layer:"))
14802
+ ]);
14803
+ return {
14804
+ schemaVersion: 2,
14805
+ verdict: conclude(input.results, { total: total2, failOn: input.failOn }).verdict,
14806
+ counts,
14807
+ foundByGrade,
14808
+ coverage: { checked: checked2, total: total2 },
14809
+ scope: {
14810
+ stage: null,
14811
+ only: input.scope?.only ?? [],
14812
+ skip: input.scope?.skip ?? [],
14813
+ active: false,
14814
+ serverCatalogKnown: known2,
14815
+ addedPrerequisites: input.scope?.addedPrerequisites ?? [],
14816
+ policyDisabled: [],
14817
+ incompleteBecause: [...incomplete2],
14818
+ complete: false
14819
+ },
14820
+ cli: { version: input.cliVersion },
14821
+ project: null,
14822
+ targetEnv: input.targetEnv,
14823
+ generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
14824
+ durationMs: Date.now() - input.startedAt,
14825
+ environments: input.environments,
14826
+ results: input.results
14827
+ };
14440
14828
  }
14441
- const checked = input.results.filter((r) => (r.env === null || r.env === input.targetEnv) && ["PASS", "FOUND", "NOT_APPLICABLE"].includes(r.verdict.level)).length;
14442
- return {
14829
+ const requested = input.scope ? {
14830
+ stage: input.scope.stage,
14831
+ only: input.scope.forwardedOnly,
14832
+ skip: input.scope.forwardedSkip,
14833
+ active: input.scope.active
14834
+ } : { stage: null, only: [], skip: [], active: false };
14835
+ const serverInScope = !input.scope || input.scope.serverLayers.size > 0;
14836
+ const serverRelevant = !input.scope || input.scope.serverRelevant;
14837
+ const known = serverInScope ? serverCatalogKnown(input.catalog, input.serverReport) : serverRelevant && !!input.catalog && input.catalog.catalogRevision !== null;
14838
+ const changed = catalogChanged(input.catalog, input.serverReport);
14839
+ const expected = known && !changed && input.serverReport ? expectedServerIds(input.catalog, input.serverReport, requested) : void 0;
14840
+ const coverageServerIds = changed ? new Set(input.serverReport.scopeIds) : expected;
14841
+ const checked = targetResults.filter((r) => ["PASS", "FOUND", "NOT_APPLICABLE"].includes(r.verdict?.level) && (r.layer === "local" || r.layer === "connect" || !coverageServerIds || coverageServerIds.has(r.checkId))).length;
14842
+ const localConnectTotal = targetResults.filter((r) => r.layer === "local" || r.layer === "connect").length;
14843
+ const total = !serverInScope ? localConnectTotal : known ? localConnectTotal + (coverageServerIds?.size ?? 0) : null;
14844
+ const incomplete = new Set(serverRelevant && !known ? ["server-catalog-unknown"] : []);
14845
+ if (input.scope?.only.length) incomplete.add("only");
14846
+ for (const token of input.scope?.skip ?? []) incomplete.add(`skip:${token}`);
14847
+ if (changed) incomplete.add("catalog-changed");
14848
+ const explicitlyExcluded = (layer2) => {
14849
+ const prefix = `${layer2}.`;
14850
+ return !!input.scope && (input.scope.only.length > 0 && !input.scope.only.some((t) => prefix.startsWith(t) || t.startsWith(prefix)) || input.scope.skip.some((t) => prefix.startsWith(t)));
14851
+ };
14852
+ for (const layer2 of ["local", "connect"]) {
14853
+ if (!targetResults.some((r) => r.layer === layer2) && !explicitlyExcluded(layer2) && (layer2 === "connect" ? !input.environments.length : CHECKS.some((d) => d.layer === layer2))) incomplete.add(`empty-layer:${layer2}`);
14854
+ }
14855
+ for (const token of input.serverReport?.scope?.incompleteBecause ?? [])
14856
+ if (token !== "only" && !token.startsWith("skip:") && !token.startsWith("empty-layer:")) incomplete.add(token);
14857
+ if (known && !changed) for (const layer2 of ["platform", "tenant"]) {
14858
+ if (explicitlyExcluded(layer2)) continue;
14859
+ if (layer2 === "tenant" && input.catalog.tenantCatalog.available === false) continue;
14860
+ const stage = input.scope?.stage;
14861
+ if (!input.catalog.checks.some((c2) => c2.spec?.layer === layer2 && (!stage || Array.isArray(c2.stages) && c2.stages.some((s) => s.toLowerCase() === stage)))) incomplete.add(`empty-layer:${layer2}`);
14862
+ }
14863
+ const report = {
14443
14864
  schemaVersion: 2,
14444
- verdict: conclude(input.results, { total: null, failOn: input.failOn }).verdict,
14865
+ verdict: conclude(input.results, { total, failOn: input.failOn }).verdict,
14445
14866
  counts,
14446
14867
  foundByGrade,
14447
- coverage: { checked, total: null },
14868
+ coverage: { checked, total },
14448
14869
  scope: {
14449
- stage: null,
14450
- only: [],
14451
- skip: [],
14452
- active: false,
14453
- serverCatalogKnown: false,
14454
- addedPrerequisites: [],
14455
- policyDisabled: [],
14456
- incompleteBecause: ["server-catalog-unknown", ...input.environments.length ? [] : ["empty-layer:connect"]],
14457
- complete: false
14870
+ stage: input.scope?.stage ?? null,
14871
+ only: input.scope?.only ?? [],
14872
+ skip: input.scope?.skip ?? [],
14873
+ active: input.scope?.active ?? false,
14874
+ serverCatalogKnown: serverRelevant ? known : null,
14875
+ addedPrerequisites: input.scope?.addedPrerequisites ?? [],
14876
+ policyDisabled: input.serverReport?.scope?.policyDisabled ?? [],
14877
+ incompleteBecause: [...incomplete],
14878
+ complete: incomplete.size === 0
14458
14879
  },
14459
14880
  cli: { version: input.cliVersion },
14460
14881
  project: input.project,
@@ -14464,63 +14885,756 @@ function assembleReport(input) {
14464
14885
  environments: input.environments,
14465
14886
  results: input.results
14466
14887
  };
14888
+ if (input.catalog) reportCatalogs.set(report, input.catalog);
14889
+ return report;
14467
14890
  }
14468
14891
  function firstActions(results) {
14469
14892
  const layers = ["local", "connect", "platform", "tenant"];
14470
- return results.filter((r) => r.verdict.level !== "PASS" && r.verdict.level !== "NOT_APPLICABLE" && r.code !== "PREREQUISITE_NOT_MET").sort((a, b) => Number(b.verdict.level === "FOUND" && b.verdict.grade === "CRITICAL") - Number(a.verdict.level === "FOUND" && a.verdict.grade === "CRITICAL") || layers.indexOf(a.layer) - layers.indexOf(b.layer));
14893
+ return results.filter((r) => r.verdict?.level !== "PASS" && r.verdict?.level !== "NOT_APPLICABLE" && r.code !== "PREREQUISITE_NOT_MET" && r.code !== "PLATFORM_OPS_ONLY" && !isOptIn(r)).sort((a, b) => Number(b.verdict?.level === "FOUND" && b.verdict.grade === "CRITICAL") - Number(a.verdict?.level === "FOUND" && a.verdict.grade === "CRITICAL") || layers.indexOf(a.layer) - layers.indexOf(b.layer));
14471
14894
  }
14472
14895
 
14473
14896
  // src/commands/doctor/render.ts
14897
+ var indented = (text, prefix = " ") => String(text).split(/\r?\n/).map((line) => `${prefix}${line}`).join("\n");
14898
+ var reportRecoveryCommands = /* @__PURE__ */ new WeakMap();
14899
+ function policyDescription(row, catalog) {
14900
+ const name = (id) => catalog?.checks.find((c2) => c2.id === id)?.name ?? id;
14901
+ return `${name(row.id)}\uFF08${row.cause.startsWith("PREREQUISITE_DISABLED:") ? `\u968F ${name(row.cause.slice("PREREQUISITE_DISABLED:".length))} \u5173\u95ED\uFF0C` : "\u79DF\u6237\u7B56\u7565\uFF0C"}${row.by} \u4E8E ${row.at} \u5173\u95ED\uFF09`;
14902
+ }
14903
+ function recovery(row, rows2, catalog, recoveryCommand) {
14904
+ let root = row;
14905
+ const visited = /* @__PURE__ */ new Set();
14906
+ while (root.cause.startsWith("PREREQUISITE_DISABLED:") && !visited.has(root.id)) {
14907
+ visited.add(root.id);
14908
+ const parent = rows2.find((r) => r.id === root.cause.slice("PREREQUISITE_DISABLED:".length));
14909
+ if (!parent) break;
14910
+ root = parent;
14911
+ }
14912
+ const id = catalog?.checks.find((c2) => c2.id === root.id)?.definitionId;
14913
+ return recoveryCommand ? `\u6062\u590D\uFF1A${recoveryCommand}` : id ? `\u6062\u590D\uFF1Ahcm action HealthCheckDefinition.resetToDefault --id ${quote(id)}` : "\u6062\u590D\uFF1A\u5148 hcm query HealthCheckDefinition \u53D6\u5F97\u5B9A\u4E49 id";
14914
+ }
14915
+ function renderPolicyDisabled(rows2, catalog, recoveryCommand) {
14916
+ return ["policyDisabled \xB7 \u9009\u68C0\u672A\u542F\u7528\uFF1A", ...rows2.flatMap((row) => [
14917
+ indented(`${policyDescription(row, catalog)} \xB7 cause=${row.cause}`),
14918
+ indented(recovery(row, rows2, catalog, recoveryCommand))
14919
+ ])].join("\n");
14920
+ }
14474
14921
  function renderChironDoctor(report) {
14475
14922
  const target = report.environments.find((env2) => env2.target);
14476
14923
  const version2 = target?.backend.version;
14477
14924
  const backend = !version2 || version2 === "unknown" ? "\u540E\u7AEF\u7248\u672C\u672A\u77E5" : `\u540E\u7AEF ${version2}`;
14925
+ const platformOps = report.scope.incompleteBecause.includes("platform-ops-view");
14478
14926
  const out = [
14479
- `\u777F\u620E\u4F53\u68C0 \xB7 \u9879\u76EE ${report.project} \xB7 \u76EE\u6807 ${report.targetEnv ?? "\u672A\u89E3\u6790"} \xB7 CLI ${report.cli.version} \xB7 ${backend}${target?.backend.commit ? `\uFF08commit ${target.backend.commit.slice(0, 7)}\uFF09` : ""}`,
14927
+ `\u777F\u620E\u4F53\u68C0 \xB7 \u9879\u76EE ${report.project} \xB7 \u76EE\u6807 ${report.targetEnv ?? "\u672A\u89E3\u6790"}${report.scope.stage ? ` \xB7 \u9636\u6BB5 ${report.scope.stage}` : ""} \xB7 CLI ${report.cli.version} \xB7 ${backend}${target?.backend.commit ? `\uFF08commit ${target.backend.commit.slice(0, 7)}\uFF09` : ""}`,
14480
14928
  "\u4E0B\u4E00\u6B65\u547D\u4EE4\u5728\u9879\u76EE\u76EE\u5F55\u6267\u884C\u3002"
14481
14929
  ];
14482
- const groups = [
14930
+ if (platformOps) {
14931
+ out[0] = `\u777F\u620E\u4F53\u68C0 \xB7 \u8FD0\u7EF4\u89C6\u56FE \xB7 \u76EE\u6807 ${report.targetEnv ?? "\u672A\u89E3\u6790"} \xB7 CLI ${report.cli.version} \xB7 ${backend}${target?.backend.commit ? `\uFF08commit ${target.backend.commit.slice(0, 7)}\uFF09` : ""}`;
14932
+ out.pop();
14933
+ }
14934
+ const groups = platformOps ? [
14935
+ ["\u8FDE\u63A5", report.results.filter((r) => r.layer === "connect")],
14936
+ [
14937
+ `\u5E73\u53F0\u5E95\u5EA7 \xB7 ${target?.server.instance ? `\u5E94\u7B54\u5B9E\u4F8B ${String(target.server.instance.id ?? "\u672A\u77E5")} \xB7 ${String(target.server.instance.runtimeRole ?? "\u8FD0\u884C\u89D2\u8272\u672A\u77E5")}` : "\u672A\u53D6\u5230\u62A5\u544A"}`,
14938
+ report.results.filter((r) => r.layer === "platform"),
14939
+ "platform"
14940
+ ]
14941
+ ] : [
14483
14942
  ["\u672C\u673A\u5DE5\u4F4D", report.results.filter((r) => r.layer === "local")],
14484
14943
  ...report.environments.map((env2) => [`\u8FDE\u63A5\u4E0E\u8EAB\u4EFD \xB7 ${env2.name}${env2.target ? "\uFF08\u76EE\u6807\uFF09" : ""}`, report.results.filter((r) => r.layer === "connect" && r.env === env2.name)])
14485
14944
  ];
14486
- for (const [label, rows2] of groups) {
14945
+ if (target && !platformOps) groups.push(
14946
+ [`\u5E73\u53F0\u5E95\u5EA7 \xB7 ${target.name}${target.server.deploymentTenancy === "shared" ? "\uFF08\u5171\u4EAB\u5B9E\u4F8B\uFF1A\u5E73\u53F0\u5C42\u53EA\u5BF9\u5E73\u53F0\u8FD0\u7EF4\u5F00\u653E\uFF09" : ""}`, report.results.filter((r) => r.layer === "platform" && r.env === target.name), "platform"],
14947
+ [`\u79DF\u6237\u5C31\u7EEA \xB7 \u79DF\u6237 ${target.tenant}`, report.results.filter((r) => r.layer === "tenant" && r.env === target.name), "tenant"]
14948
+ );
14949
+ for (const [label, rows2, serverLayer] of groups) {
14487
14950
  out.push("", label);
14951
+ if (!rows2.length && serverLayer && report.scope.incompleteBecause.includes(`empty-layer:${serverLayer}`)) {
14952
+ const knownLayer = reportCatalogs.get(report)?.checks.some((item) => item.spec?.layer === serverLayer);
14953
+ out.push(` \u2205 ${knownLayer && report.scope.stage ? `\u672C\u5C42\u5728\u9636\u6BB5 ${report.scope.stage} \u6CA1\u6709\u68C0\u67E5` : "\u672C\u5C42\u5728\u670D\u52A1\u7AEF\u76EE\u5F55\u91CC\u6CA1\u6709\u68C0\u67E5"}\uFF08empty-layer:${serverLayer}\uFF09`);
14954
+ }
14488
14955
  const folded = /* @__PURE__ */ new Set();
14489
14956
  for (const row of rows2) {
14490
- if (row.code === "PREREQUISITE_NOT_MET") {
14491
- const key2 = `${row.env}:${row.verdict.note}`;
14957
+ const v = row.verdict;
14958
+ if (row.code === "PREREQUISITE_NOT_MET" || row.code === "PLATFORM_OPS_ONLY") {
14959
+ const key2 = row.code === "PLATFORM_OPS_ONLY" ? row.code : `${row.env}:${v.note}`;
14492
14960
  if (folded.has(key2)) continue;
14493
14961
  folded.add(key2);
14494
- const matching = rows2.filter((r) => r.code === row.code && r.env === row.env && r.verdict.note === row.verdict.note);
14495
- out.push(` \xB7 ${matching.map((r) => r.name).join("\u3001")}\uFF1A\u524D\u7F6E\u672A\u901A\u8FC7\uFF08${row.verdict.note}\uFF09`);
14496
- continue;
14962
+ const matching = rows2.filter((r) => r.code === row.code && (row.code === "PLATFORM_OPS_ONLY" || r.env === row.env && r.verdict.note === v.note));
14963
+ if (row.code === "PREREQUISITE_NOT_MET") {
14964
+ const outside = row.summary === "\u524D\u7F6E\u9879\u4E0D\u5728\u672C\u6B21\u8303\u56F4\u5185";
14965
+ out.push(indented(`${matching.map((r) => r.name).join("\u3001")}\uFF1A${outside ? "\u524D\u7F6E\u9879\u4E0D\u5728\u672C\u6B21\u8303\u56F4\u5185" : "\u524D\u7F6E\u672A\u901A\u8FC7"}\uFF08${v.note}\uFF09`, " \xB7 "));
14966
+ if (outside) {
14967
+ for (const item of matching) if (item.nextStep?.command)
14968
+ out.push(indented(`\u2192 ${item.nextStep.command} [${item.nextStep.owner}]`));
14969
+ }
14970
+ continue;
14971
+ }
14972
+ out.push(indented(`\u5168\u90E8 ${matching.length} \u9879 \u672A\u6267\u884C\uFF1A${row.summary}`, " ? "));
14973
+ } else {
14974
+ const mark = v?.level === "FOUND" ? v.grade === "CRITICAL" ? "\u2717" : "!" : { PASS: "\u2713", UNDETERMINED: "?", NOT_RUN: "\xB7", NOT_APPLICABLE: "\u2205" }[v?.level] ?? "?";
14975
+ out.push(` ${mark} ${row.name}${row.requirement === "OPTIONAL" ? "\uFF08\u9009\u68C0\uFF09" : ""}${row.layer === "local" && row.env ? ` \xB7 ${row.env}` : ""} ${String(row.summary).replace(/\r?\n/g, "\n ")}`);
14497
14976
  }
14498
- const v = row.verdict;
14499
- const mark = v.level === "FOUND" ? v.grade === "CRITICAL" ? "\u2717" : "!" : { PASS: "\u2713", UNDETERMINED: "?", NOT_RUN: "\xB7", NOT_APPLICABLE: "\u2205" }[v.level];
14500
- out.push(` ${mark} ${row.name}${row.requirement === "OPTIONAL" ? "\uFF08\u9009\u68C0\uFF09" : ""}${row.layer === "local" && row.env ? ` \xB7 ${row.env}` : ""} ${row.summary}`);
14501
- if (v.note) out.push(` ${v.note}`);
14502
- if (v.level !== "PASS" && row.nextStep) out.push(` \u2192 ${row.nextStep.command ?? "\u6309\u672C\u9879\u8BF4\u660E\u5904\u7406\u540E\u91CD\u8DD1 hcm chiron doctor"} [${row.nextStep.owner}]`);
14503
- }
14504
- }
14505
- out.push(
14506
- "",
14507
- "\u5E73\u53F0\u3001\u79DF\u6237\uFF1A\u672C\u7248 CLI \u5C1A\u672A\u53D6\u670D\u52A1\u7AEF\u4F53\u68C0\u62A5\u544A\uFF0C\u8FD9\u4E24\u5C42\u4E0D\u5728\u672C\u6B21\u8303\u56F4\u3002",
14508
- `\u7ED3\u8BBA\uFF1A${report.verdict.replaceAll("_", " ")} \xB7 ${report.foundByGrade.CRITICAL} \u963B\u65AD \xB7 ${report.foundByGrade.WARN} \u98CE\u9669 \xB7 ${report.counts.UNDETERMINED + report.counts.NOT_RUN} \u672A\u5224 \xB7 \u5DF2\u6838 ${report.coverage.checked}/?\uFF08\u670D\u52A1\u7AEF\u68C0\u67E5\u6570\u672A\u77E5\uFF09`
14509
- );
14977
+ if (v?.note) out.push(indented(v.note));
14978
+ if (v?.level !== "PASS" && row.nextStep && (v?.level !== "NOT_APPLICABLE" || row.nextStep.command)) out.push(indented(`\u2192 ${row.nextStep.command ?? `\u6309\u672C\u9879\u8BF4\u660E\u5904\u7406\u540E\u91CD\u8DD1 hcm chiron doctor${platformOps ? " --platform-ops" : ""}`} [${row.nextStep.owner}]`));
14979
+ }
14980
+ }
14981
+ const active = report.results.filter(isOptIn).length;
14982
+ const coverage = (report.coverage.total === null ? `${report.coverage.checked}/?\uFF08\u670D\u52A1\u7AEF\u68C0\u67E5\u6570\u672A\u77E5\uFF09` : `${report.coverage.checked}/${report.coverage.total}`) + (active ? `\uFF08${active} \u9879\u9700 --active\uFF09` : "");
14983
+ out.push("", `\u7ED3\u8BBA\uFF1A${report.verdict.replaceAll("_", " ")} \xB7 ${report.foundByGrade.CRITICAL} \u963B\u65AD \xB7 ${report.foundByGrade.WARN} \u98CE\u9669 \xB7 ${report.counts.UNDETERMINED + report.counts.NOT_RUN - active} \u672A\u5224 \xB7 \u5DF2\u6838 ${coverage}`);
14984
+ const policyCatalog = reportCatalogs.get(report), disabled = report.scope.policyDisabled;
14985
+ if (disabled.length) out.push(`\u9009\u68C0\u672A\u542F\u7528\uFF1A${disabled.map((r) => policyDescription(r, policyCatalog)).join("\uFF1B")}`);
14986
+ for (const row of disabled.filter((r) => report.scope.only.includes(r.id)))
14987
+ out.push(`\u8BE5\u9879\u5DF2\u6309\u79DF\u6237\u7B56\u7565\u5173\u95ED\uFF1A${policyCatalog?.checks.find((c2) => c2.id === row.id)?.name ?? row.id}\uFF1B${recovery(row, disabled, policyCatalog, reportRecoveryCommands.get(report))}`);
14988
+ if (report.scope.incompleteBecause.includes("catalog-changed")) out.push("\u6838\u9A8C\u671F\u95F4\u68C0\u67E5\u76EE\u5F55\u53D1\u751F\u53D8\u5316\uFF0C\u7A0D\u540E\u91CD\u8DD1");
14510
14989
  const actions = firstActions(report.results);
14511
14990
  if (actions.length) out.push(`\u5148\u5904\u7406\uFF1A${actions.map((r) => `${r.checkId}${r.env ? `\uFF08${r.env}\uFF09` : ""}`).join("\u3001")}`);
14991
+ if (platformOps) {
14992
+ const note = target?.server?.note;
14993
+ if (note) out.push(note);
14994
+ out.push("\u672C\u62A5\u544A\u4EC5\u4EE3\u8868\u5E94\u7B54\u5B9E\u4F8B");
14995
+ }
14512
14996
  return out.join("\n");
14513
14997
  }
14514
14998
 
14999
+ // src/commands/doctor/platform-ops.ts
15000
+ import { createHash as createHash8 } from "crypto";
15001
+ import axios8 from "axios";
15002
+ import {
15003
+ classifyStatus as classifyStatus2,
15004
+ CliError as CliError30,
15005
+ CliErrorCode as CliErrorCode31,
15006
+ loadGlobalConfig as loadGlobalConfig11,
15007
+ printResolvedEnvironment as printResolvedEnvironment8,
15008
+ resolveEnvContext as resolveEnvContext8
15009
+ } from "@hcmai/sdk";
15010
+ var OPS_PATH = "/api/system/health/ops/report";
15011
+ var connectivity2 = CHECKS.find((row) => row.id === "connect.connectivity");
15012
+ var api = {
15013
+ ...CHECKS.find((row) => row.id === "connect.health-api"),
15014
+ dependsOn: ["connect.connectivity"],
15015
+ timeoutMs: 26e3,
15016
+ codes: [
15017
+ "BACKEND_UNSUPPORTED",
15018
+ "HEALTH_API_ROUTE_MISSING",
15019
+ "REPORT_UNAVAILABLE",
15020
+ "REPORT_MALFORMED",
15021
+ "BUDGET_EXHAUSTED"
15022
+ ],
15023
+ run: async (ctx, env2, execution) => {
15024
+ const remaining = (ctx.opsDeadline ?? Date.now()) - Date.now();
15025
+ if (remaining < 3e3) return unknown("BUDGET_EXHAUSTED", "\u9884\u7B97\u8017\u5C3D\uFF0C\u672A\u542F\u52A8", { note: "\u9884\u7B97\u8017\u5C3D\uFF0C\u672A\u542F\u52A8" });
15026
+ const timeoutMs = Math.min(25e3, remaining);
15027
+ let out;
15028
+ try {
15029
+ out = await ctx.services.opsReportRequest(
15030
+ env2.config.endpoint,
15031
+ ctx.opsKey,
15032
+ timeoutMs,
15033
+ Math.min(15e3, timeoutMs - 2e3),
15034
+ execution.signal,
15035
+ { only: ctx.scope?.forwardedOnly ?? [], skip: ctx.scope?.forwardedSkip ?? [] }
15036
+ );
15037
+ } catch (error) {
15038
+ const stopped = execution.signal.aborted || axios8.isAxiosError(error) && ["ECONNABORTED", "ETIMEDOUT"].includes(error.code ?? "") || ["ECONNABORTED", "ETIMEDOUT"].includes(String(error.code));
15039
+ return unknown(
15040
+ "REPORT_UNAVAILABLE",
15041
+ "\u670D\u52A1\u7AEF\u4F53\u68C0\u63A5\u53E3\u6682\u4E0D\u53EF\u7528\uFF1B\u7A0D\u540E\u91CD\u8BD5",
15042
+ { note: `HTTP \u672A\u53D6\u5F97\u54CD\u5E94\uFF1B${stopped ? "\u5DF2\u505C\u6B62\u7B49\u5F85" : safeError(error)}` }
15043
+ );
15044
+ }
15045
+ env2.opsOutcome = out;
15046
+ return classifyOpsApi(out, env2.config.endpoint, ctx.opsKey);
15047
+ }
15048
+ };
15049
+ var placeholder = {
15050
+ id: "platform.server-report",
15051
+ name: "\u5E73\u53F0\u4F53\u68C0\u62A5\u544A",
15052
+ layer: "platform",
15053
+ requirement: "REQUIRED",
15054
+ owner: "RND",
15055
+ dependsOn: ["connect.connectivity", "connect.health-api"],
15056
+ codes: [
15057
+ "BACKEND_UNSUPPORTED",
15058
+ "HEALTH_API_ROUTE_MISSING",
15059
+ "HEALTH_OPS_KEY_INVALID",
15060
+ "HEALTH_OPS_KEY_LOCKED",
15061
+ "REPORT_THROTTLED",
15062
+ "REPORT_UNAVAILABLE",
15063
+ "REPORT_MALFORMED",
15064
+ "REPORT_ITEM_MISSING",
15065
+ "SERVER_VERDICT_INVALID",
15066
+ "BUDGET_EXHAUSTED"
15067
+ ]
15068
+ };
15069
+ var OPS_DESCRIPTORS = [connectivity2, api, placeholder];
15070
+ var requestOpsReport = async (endpoint, key2, timeoutMs, budgetMs, signal, scope) => {
15071
+ const res = await axios8.get(OPS_PATH, {
15072
+ baseURL: endpoint,
15073
+ timeout: timeoutMs,
15074
+ signal,
15075
+ maxRedirects: 0,
15076
+ validateStatus: () => true,
15077
+ headers: { Accept: "application/json", "X-Platform-Ops-Key": key2 },
15078
+ params: {
15079
+ budgetMs,
15080
+ ...scope.only.length ? { only: scope.only.join(",") } : {},
15081
+ ...scope.skip.length ? { skip: scope.skip.join(",") } : {}
15082
+ }
15083
+ });
15084
+ return {
15085
+ status: res.status,
15086
+ body: res.data,
15087
+ error: classifyStatus2(res.status),
15088
+ headers: Object.fromEntries(Object.entries(res.headers).map(([name, value]) => [name.toLowerCase(), String(value)]))
15089
+ };
15090
+ };
15091
+ function opsKeyFingerprint(key2) {
15092
+ return key2 ? createHash8("sha256").update(key2, "utf8").digest("hex").slice(0, 16) : "none";
15093
+ }
15094
+ async function readPlatformOpsKey(args, io = {
15095
+ env: process.env.HCM_PLATFORM_OPS_KEY,
15096
+ isTTY: !!process.stdin.isTTY,
15097
+ readStdin,
15098
+ prompt: () => promptSecret("\u8FD0\u7EF4\u53EA\u8BFB\u5BC6\u94A5: ", process.stderr),
15099
+ stderr: (text) => process.stderr.write(text)
15100
+ }) {
15101
+ let source, key2;
15102
+ const fromEnv = io.env?.trim();
15103
+ if (fromEnv) {
15104
+ source = "env";
15105
+ key2 = fromEnv;
15106
+ } else if (args.platformOpsKeyStdin) {
15107
+ source = "stdin";
15108
+ key2 = await io.readStdin();
15109
+ } else if (io.isTTY) {
15110
+ source = "tty";
15111
+ key2 = await io.prompt();
15112
+ } else throw new CliError30({
15113
+ code: CliErrorCode31.INVALID_ARGUMENT,
15114
+ message: "\u7F3A\u5C11\u8FD0\u7EF4\u5BC6\u94A5\uFF1A\u8BBE\u7F6E HCM_PLATFORM_OPS_KEY\u3001\u4F7F\u7528 --platform-ops-key-stdin\uFF0C\u6216\u5728 TTY \u4EA4\u4E92\u8F93\u5165"
15115
+ });
15116
+ key2 = key2.trim();
15117
+ if (!key2) throw new CliError30({ code: CliErrorCode31.INVALID_ARGUMENT, message: "\u8FD0\u7EF4\u5BC6\u94A5\u4E3A\u7A7A" });
15118
+ io.stderr(`\u8FD0\u7EF4\u5BC6\u94A5\u6765\u6E90\uFF1A${source} \xB7 \u6307\u7EB9 ${opsKeyFingerprint(key2)}
15119
+ `);
15120
+ return { key: key2, source };
15121
+ }
15122
+ var split = (value) => (Array.isArray(value) ? value : value ? [value] : []).flatMap((item) => item.split(",")).map((item) => item.trim()).filter(Boolean);
15123
+ function scopeFor(args) {
15124
+ const only = split(args.only), skip = split(args.skip);
15125
+ for (const token of [...only, ...skip]) if (!("platform.".startsWith(token) || token.startsWith("platform.")))
15126
+ throw new CliError30({
15127
+ code: CliErrorCode31.INVALID_ARGUMENT,
15128
+ message: `\u8FD0\u7EF4\u89C6\u56FE\u53EA\u770B\u5E73\u53F0\u5C42\uFF1A--only / --skip \u53EA\u63A5\u53D7 platform \u524D\u7F00\uFF0C\u6536\u5230 ${token}`
15129
+ });
15130
+ if (skip.some((token) => "platform.".startsWith(token))) throw new CliError30({
15131
+ code: CliErrorCode31.INVALID_ARGUMENT,
15132
+ message: "\u6392\u9664\u4E86\u5E73\u53F0\u5C42\uFF0C\u8FD0\u7EF4\u89C6\u56FE\u6CA1\u6709\u53EF\u770B\u7684\u68C0\u67E5"
15133
+ });
15134
+ return {
15135
+ stage: null,
15136
+ only,
15137
+ skip,
15138
+ active: false,
15139
+ forwardedOnly: only,
15140
+ forwardedSkip: skip,
15141
+ serverIds: /* @__PURE__ */ new Set(),
15142
+ serverLayers: /* @__PURE__ */ new Set(["platform"]),
15143
+ serverRelevant: true,
15144
+ addedPrerequisites: only.length ? ["connect.connectivity", "connect.health-api"] : []
15145
+ };
15146
+ }
15147
+ function redact(text, key2) {
15148
+ const raw = typeof text === "string" ? text : JSON.stringify(text) ?? "";
15149
+ return raw.replaceAll(key2, "[redacted]").replace(/hcm\s+login/gi, "[login advice omitted]");
15150
+ }
15151
+ function classifyOpsApi(out, endpoint, key2) {
15152
+ const note = httpNote(out), error = object(out.body) && object(out.body.error) ? out.body.error : void 0;
15153
+ const wireCode = error?.code;
15154
+ if (out.status === 200) {
15155
+ if (object(out.body) || Array.isArray(out.body)) return pass("\u540E\u7AEF\u652F\u6301\u8FD0\u7EF4\u4F53\u68C0 API");
15156
+ if (/json/i.test(out.headers["content-type"] ?? "")) {
15157
+ if (typeof out.body === "string") {
15158
+ try {
15159
+ JSON.parse(out.body);
15160
+ } catch {
15161
+ return unknown(
15162
+ "REPORT_MALFORMED",
15163
+ "\u8FD0\u7EF4\u4F53\u68C0\u63A5\u53E3 JSON \u89E3\u6790\u5931\u8D25",
15164
+ { reason: "EVALUATOR_ERROR", note: `${note}\uFF1B${redact(out.body, key2).slice(0, 200)}` }
15165
+ );
15166
+ }
15167
+ }
15168
+ return pass("\u540E\u7AEF\u652F\u6301\u8FD0\u7EF4\u4F53\u68C0 API");
15169
+ }
15170
+ return found(
15171
+ "HEALTH_API_ROUTE_MISSING",
15172
+ void 0,
15173
+ { evidence: "INFERRED", note: `${note}\uFF1B\u6536\u5230\u975E JSON\uFF0C\u63A8\u65AD\u8DEF\u7531\u843D\u5230\u53CD\u4EE3\u6216\u524D\u7AEF SPA` }
15174
+ );
15175
+ }
15176
+ if (out.status === 403 && wireCode === "HEALTH_OPS_KEY_INVALID") return pass("\u8FD0\u7EF4\u4F53\u68C0 API \u5DF2\u5E94\u7B54");
15177
+ if (out.status === 429 && ["HEALTH_OPS_KEY_LOCKED", "HEALTH_REPORT_THROTTLED"].includes(String(wireCode)))
15178
+ return pass("\u8FD0\u7EF4\u4F53\u68C0 API \u5DF2\u5E94\u7B54");
15179
+ if (out.status === 401 && !out.headers["x-trace-id"]) return found(
15180
+ "HEALTH_API_ROUTE_MISSING",
15181
+ void 0,
15182
+ { evidence: "INFERRED", note: `${note}\uFF1B\u7F3A\u540E\u7AEF traceId\uFF0C\u63A8\u65AD\u7F51\u5173\u62E6\u622A\uFF1B\u4EE3\u7406\u4E5F\u53EF\u80FD\u5265\u6389\u54CD\u5E94\u5934` }
15183
+ );
15184
+ const requestPath = new URL(`${endpoint.replace(/\/+$/, "")}${OPS_PATH}`).pathname;
15185
+ if (out.status === 401 && out.headers["x-trace-id"] && object(out.body) && out.body.code === 401 && [requestPath, OPS_PATH].includes(String(out.body.path))) return found("BACKEND_UNSUPPORTED", void 0, { note });
15186
+ if (out.status === 404) {
15187
+ if (out.headers["x-trace-id"] && error && typeof error.code === "string" && typeof error.message === "string")
15188
+ return found("BACKEND_UNSUPPORTED", void 0, { note });
15189
+ if (!out.headers["x-trace-id"]) return found(
15190
+ "HEALTH_API_ROUTE_MISSING",
15191
+ void 0,
15192
+ { evidence: "INFERRED", note: `${note}\uFF1B\u7F3A\u540E\u7AEF traceId\uFF0C\u63A8\u65AD\u8DEF\u7531\u672A\u5230\u540E\u7AEF\uFF1B\u4EE3\u7406\u4E5F\u53EF\u80FD\u5265\u6389\u54CD\u5E94\u5934` }
15193
+ );
15194
+ }
15195
+ if (out.status >= 500 || out.error === "network") return unknown("REPORT_UNAVAILABLE", void 0, { note });
15196
+ return unknown(
15197
+ "REPORT_MALFORMED",
15198
+ "\u8FD0\u7EF4\u4F53\u68C0\u63A5\u53E3\u8FD4\u56DE\u975E\u9884\u671F\u72B6\u6001",
15199
+ { reason: "EVALUATOR_ERROR", note: `${note}\uFF1B${redact(out.body, key2).slice(0, 200)}` }
15200
+ );
15201
+ }
15202
+ function opsPlaceholder(ctx, env2, observation) {
15203
+ const row = CODE_TABLE[observation.code ?? ""];
15204
+ return makeResult(
15205
+ placeholder,
15206
+ {
15207
+ ...observation,
15208
+ grade: observation.grade ?? row?.grade,
15209
+ summary: observation.summary === observation.code && row ? row.summary : observation.summary
15210
+ },
15211
+ env2.name,
15212
+ true,
15213
+ ctx.requestedAt,
15214
+ 0,
15215
+ observation.code ? codeStep(observation.code, env2.name) : { owner: "RND" }
15216
+ );
15217
+ }
15218
+ function failure(ctx, env2, health, key2) {
15219
+ const out = env2.opsOutcome, code2 = health.code;
15220
+ if (!out) {
15221
+ if (code2 === "BUDGET_EXHAUSTED") return opsPlaceholder(ctx, env2, unknown("BUDGET_EXHAUSTED", "\u9884\u7B97\u8017\u5C3D\uFF0C\u672A\u542F\u52A8", { note: "\u9884\u7B97\u8017\u5C3D\uFF0C\u672A\u542F\u52A8" }));
15222
+ if (code2 === "REPORT_UNAVAILABLE") return opsPlaceholder(
15223
+ ctx,
15224
+ env2,
15225
+ unknown("REPORT_UNAVAILABLE", void 0, { note: health.verdict.note })
15226
+ );
15227
+ return opsPlaceholder(ctx, env2, {
15228
+ level: "NOT_RUN",
15229
+ code: "PREREQUISITE_NOT_MET",
15230
+ reason: "PREREQUISITE_NOT_MET",
15231
+ summary: "\u8FD0\u7EF4\u62A5\u544A\u672A\u6267\u884C\uFF1A\u524D\u7F6E\u68C0\u67E5\u672A\u901A\u8FC7",
15232
+ note: code2 ?? health.verdict.level
15233
+ });
15234
+ }
15235
+ const error = object(out.body) && object(out.body.error) ? out.body.error : void 0;
15236
+ const detail = object(error?.details) ? error.details : void 0;
15237
+ const next = typeof error?.next_step === "string" ? `\uFF1B${redact(error.next_step, key2)}` : "";
15238
+ const keyNote = `${httpNote(out)} \xB7 \u6307\u7EB9 ${opsKeyFingerprint(key2)}`;
15239
+ if (out.status === 403 && error?.code === "HEALTH_OPS_KEY_INVALID") return opsPlaceholder(
15240
+ ctx,
15241
+ env2,
15242
+ unknown("HEALTH_OPS_KEY_INVALID", void 0, { reason: "PERMISSION_DENIED", note: keyNote + next })
15243
+ );
15244
+ if (out.status === 429 && error?.code === "HEALTH_OPS_KEY_LOCKED") {
15245
+ const retry = out.headers["retry-after"] || detail?.retryAfter;
15246
+ return opsPlaceholder(ctx, env2, unknown(
15247
+ "HEALTH_OPS_KEY_LOCKED",
15248
+ void 0,
15249
+ { note: `${keyNote} \xB7 ${retry == null ? "\u670D\u52A1\u7AEF\u672A\u63D0\u4F9B retryAfter" : `retryAfter=${String(retry)}`}${next}` }
15250
+ ));
15251
+ }
15252
+ if (out.status === 429 && error?.code === "HEALTH_REPORT_THROTTLED") return opsPlaceholder(
15253
+ ctx,
15254
+ env2,
15255
+ unknown("REPORT_THROTTLED", void 0, { note: redact(throttleNote(out), key2) })
15256
+ );
15257
+ if (code2 === "BACKEND_UNSUPPORTED") return opsPlaceholder(
15258
+ ctx,
15259
+ env2,
15260
+ {
15261
+ level: "NOT_RUN",
15262
+ code: code2,
15263
+ reason: "CAPABILITY_UNSUPPORTED",
15264
+ summary: "\u540E\u7AEF\u4E0D\u652F\u6301\u8FD0\u7EF4\u4F53\u68C0\u62A5\u544A",
15265
+ note: `${health.verdict.note ?? ""}\uFF1B${env2.report.backend.commit ? `\u540E\u7AEF commit ${env2.report.backend.commit}` : "commit \u672A\u77E5"}`
15266
+ }
15267
+ );
15268
+ if (code2 === "HEALTH_API_ROUTE_MISSING") return opsPlaceholder(
15269
+ ctx,
15270
+ env2,
15271
+ unknown(code2, void 0, { note: health.verdict.note })
15272
+ );
15273
+ if (code2 === "REPORT_UNAVAILABLE") return opsPlaceholder(
15274
+ ctx,
15275
+ env2,
15276
+ unknown(code2, void 0, { note: health.verdict.note })
15277
+ );
15278
+ return opsPlaceholder(ctx, env2, unknown(
15279
+ "REPORT_MALFORMED",
15280
+ void 0,
15281
+ { reason: "EVALUATOR_ERROR", note: health.verdict.note ?? `${httpNote(out)}\uFF1B${redact(out.body, key2).slice(0, 200)}` }
15282
+ ));
15283
+ }
15284
+ var ENV_HINT = "hcm env list \u67E5\u770B\u53EF\u9009\u73AF\u5883\uFF1Bhcm env add <\u540D> --endpoint <url> \u767B\u8BB0";
15285
+ function resolverMessage(error) {
15286
+ if (error instanceof CliError30 && error.code === CliErrorCode31.NO_ACTIVE_ENV) return "\u672A\u9009\u5B9A\u73AF\u5883\uFF1A\u7528 --env <\u540D> \u6307\u5B9A";
15287
+ return (error instanceof Error ? error.message : safeError(error)).replace(/\s*(&&\s*)?hcm\s+login\b[^;;\n]*/gi, "");
15288
+ }
15289
+ async function runPlatformOps(args, services, readKey = readPlatformOpsKey, onReport) {
15290
+ const scope = scopeFor(args);
15291
+ let resolved;
15292
+ try {
15293
+ resolved = await resolveEnvContext8({ envFlag: args.env }, process.env, await loadGlobalConfig11());
15294
+ } catch (error2) {
15295
+ throw new CliError30({ code: CliErrorCode31.INVALID_ARGUMENT, message: `${resolverMessage(error2)}\uFF1B${ENV_HINT}` });
15296
+ }
15297
+ if (!resolved.config.endpoint) throw new CliError30({
15298
+ code: CliErrorCode31.INVALID_ARGUMENT,
15299
+ message: `\u672A\u89E3\u6790\u5230 endpoint\uFF1B${ENV_HINT}`
15300
+ });
15301
+ printResolvedEnvironment8(resolved);
15302
+ const { key: key2 } = await readKey(args);
15303
+ const startedAt = Date.now();
15304
+ const name = resolved.project?.name ?? resolved.name;
15305
+ const env2 = {
15306
+ name,
15307
+ config: { endpoint: resolved.config.endpoint },
15308
+ credential: async () => {
15309
+ throw new Error("\u8FD0\u7EF4\u89C6\u56FE\u4E0D\u5F97\u8BFB\u53D6\u8EAB\u4EFD");
15310
+ },
15311
+ report: {
15312
+ name,
15313
+ endpoint: resolved.config.endpoint,
15314
+ tenant: null,
15315
+ target: true,
15316
+ backend: { version: null, commit: null },
15317
+ server: {
15318
+ supported: null,
15319
+ deploymentTenancy: null,
15320
+ instance: null,
15321
+ verdict: null,
15322
+ catalogRevision: null
15323
+ }
15324
+ }
15325
+ };
15326
+ const ctx = {
15327
+ root: "",
15328
+ requestedAt: new Date(startedAt).toISOString(),
15329
+ cliVersion: CLI_VERSION,
15330
+ projectObservation: pass("\u8FD0\u7EF4\u73AF\u5883\u5DF2\u89E3\u6790"),
15331
+ targetEnv: name,
15332
+ environments: [env2],
15333
+ services,
15334
+ scope,
15335
+ opsKey: key2,
15336
+ opsDeadline: startedAt + 45e3
15337
+ };
15338
+ const results = await executeChecks(ctx, { checks: [connectivity2, api], fetchReport: false });
15339
+ const health = results.find((row) => row.checkId === "connect.health-api");
15340
+ const out = env2.opsOutcome;
15341
+ const error = out && object(out.body) && object(out.body.error) ? out.body.error : void 0;
15342
+ if (out?.status === 400 && error?.code === "HEALTH_REPORT_INVALID_PARAM") throw new CliError30({
15343
+ code: CliErrorCode31.INVALID_ARGUMENT,
15344
+ message: `${typeof error.message === "string" ? redact(error.message, key2) : "\u8FD0\u7EF4\u68C0\u67E5\u8303\u56F4\u65E0\u6548"}${scope.only.length || scope.skip.length ? "\uFF1B\u53BB\u6389 --only / --skip \u91CD\u8DD1 hcm chiron doctor --platform-ops \u53EF\u770B\u5230\u5168\u90E8\u5E73\u53F0\u68C0\u67E5" : ""}`
15345
+ });
15346
+ env2.report.server.supported = health.verdict.level === "PASS" ? true : health.code === "BACKEND_UNSUPPORTED" ? false : null;
15347
+ if (out?.status === 200 && health.verdict.level === "PASS") {
15348
+ const invalid3 = reportEnvelopeError(out.body, true);
15349
+ if (invalid3) results.push(opsPlaceholder(ctx, env2, unknown(
15350
+ "REPORT_MALFORMED",
15351
+ "\u670D\u52A1\u7AEF\u8FD0\u7EF4\u62A5\u544A\u4FE1\u5C01\u4E0D\u5408\u6CD5",
15352
+ { reason: "EVALUATOR_ERROR", note: `${httpNote(out)}\uFF1B${invalid3}` }
15353
+ )));
15354
+ else {
15355
+ const report = out.body;
15356
+ env2.serverReport = report;
15357
+ onReport?.(report);
15358
+ Object.assign(env2.report.server, {
15359
+ deploymentTenancy: report.deploymentTenancy ?? null,
15360
+ instance: report.instance ?? null,
15361
+ catalogRevision: report.catalogRevision ?? null,
15362
+ verdict: report.verdict ?? null,
15363
+ note: report.note
15364
+ });
15365
+ results.push(...reconcileReport(ctx, env2, report, {
15366
+ stage: null,
15367
+ only: scope.forwardedOnly,
15368
+ skip: scope.forwardedSkip,
15369
+ active: false
15370
+ }, { placeholder }));
15371
+ }
15372
+ } else results.push(failure(ctx, env2, health, key2));
15373
+ return assembleReport({
15374
+ results,
15375
+ environments: [env2.report],
15376
+ project: null,
15377
+ targetEnv: name,
15378
+ cliVersion: CLI_VERSION,
15379
+ startedAt,
15380
+ failOn: args.failOn ?? "blocked",
15381
+ scope,
15382
+ serverReport: env2.serverReport,
15383
+ platformOps: true
15384
+ });
15385
+ }
15386
+
15387
+ // src/commands/doctor/catalog.ts
15388
+ var localCriterion = {
15389
+ "local.project.env": "env.yaml \u5B58\u5728\u3001\u53EF\u89E3\u6790\uFF0C\u76EE\u6807\u73AF\u5883\u80FD\u89E3\u6790\u5230\u9879\u76EE\u73AF\u5883",
15390
+ "local.credential": "\u6BCF\u4E2A\u9879\u76EE\u73AF\u5883\u6709\u5339\u914D endpoint \u4E0E\u79DF\u6237\u7684\u672C\u673A\u51ED\u636E\u69FD",
15391
+ "local.cli.version": "\u4E0E npm \u6700\u65B0 CLI \u7248\u672C\u6BD4\u8F83",
15392
+ "local.skills.installed": "\u4E24\u79CD\u5E03\u5C40\u7684\u6280\u80FD\u5E76\u96C6\u3001\u9501\u6587\u4EF6\u4E0E\u76EE\u6807\u73AF\u5883\u4E00\u81F4",
15393
+ "local.skills.fresh": "\u672C\u673A\u6280\u80FD\u4E0E\u76EE\u6807\u73AF\u5883\u7684\u4EA7\u54C1\u6280\u80FD\u76EE\u5F55\u5BF9\u8D26",
15394
+ "local.boundary": "\u9879\u76EE\u8FB9\u754C\u5757\u5B58\u5728\uFF0C\u4E14\u4E0D\u662F CLI fallback \u526F\u672C",
15395
+ "local.method": "\u5B9E\u65BD\u65B9\u6CD5\u5305\u5DF2\u5B89\u88C5\u3001\u7248\u672C\u4E0E\u672C\u673A\u526F\u672C\u4E00\u81F4",
15396
+ "local.cases": "\u6848\u4F8B\u5E93\u7D22\u5F15\u53EF\u8BFB\u53D6\uFF0C\u8FDC\u7AEF\u4E0E\u7F13\u5B58\u6765\u6E90\u53EF\u8FA8",
15397
+ "local.jira": "Jira \u4EE4\u724C\u3001\u672C\u4EBA\u8EAB\u4EFD\u53CA\u9879\u76EE\u53EF\u89C1\u6027\u9010\u9879\u6838\u9A8C",
15398
+ "connect.connectivity": "\u514D\u8BA4\u8BC1\u8BFB\u53D6\u540E\u7AEF\u7248\u672C\u7AEF\u70B9\uFF0C\u786E\u8BA4\u540E\u7AEF\u53EF\u8FBE",
15399
+ "connect.identity": "\u670D\u52A1\u7AEF\u786E\u8BA4 token \u4E3B\u4F53\u53CA\u79DF\u6237\u4E0E\u9879\u76EE\u58F0\u660E\u4E00\u81F4",
15400
+ "connect.config-admin": "\u79DF\u6237 meta \u6E05\u5355\u53EF\u8BFB\uFF0C\u96F6\u6761\u4E5F\u6709\u6548",
15401
+ "connect.layer": "\u80FD\u5224\u51FA\u5F53\u524D workspace \u5C42",
15402
+ "connect.websocket": "\u5BF9\u8BDD WebSocket \u63E1\u624B\u8FD4\u56DE HTTP 101",
15403
+ "connect.health-api": "\u670D\u52A1\u7AEF\u4F53\u68C0\u76EE\u5F55\u53EF\u8BFB\u4E14\u54CD\u5E94\u5F62\u72B6\u5408\u6CD5",
15404
+ "connect.exposure": "\u533F\u540D\u5065\u5EB7\u7AEF\u70B9\u4E0D\u66B4\u9732\u7EC4\u4EF6\u8BE6\u60C5"
15405
+ };
15406
+ var critical = /* @__PURE__ */ new Set([
15407
+ "local.project.env",
15408
+ "local.credential",
15409
+ "local.skills.installed",
15410
+ "connect.connectivity",
15411
+ "connect.identity",
15412
+ "connect.config-admin"
15413
+ ]);
15414
+ var special = /* @__PURE__ */ new Set([
15415
+ "NEED_SYSTEM_ADMIN",
15416
+ "NEED_CONFIG_ADMIN",
15417
+ "OPT_IN_REQUIRED",
15418
+ "PLATFORM_OPS_ONLY",
15419
+ "DEFINITION_MISSING",
15420
+ "INVALID_DEFINITION",
15421
+ "DEFINITIONS_UNAVAILABLE"
15422
+ ]);
15423
+ var object2 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
15424
+ var codeRows = (value) => Array.isArray(value) ? value.filter(object2) : [];
15425
+ var code = (row) => String(row.code ?? "");
15426
+ function listCatalog(ctx, reason) {
15427
+ const catalog = ctx.environments.find((e) => e.report.target)?.catalog;
15428
+ const checks = [
15429
+ ...CHECKS.map((d) => ({ id: d.id, layer: d.layer, name: d.name, requirement: d.requirement, stages: d.stages, source: "cli" })),
15430
+ ...(catalog?.checks ?? []).map((d) => ({
15431
+ id: d.id,
15432
+ layer: d.spec?.layer,
15433
+ name: d.name,
15434
+ requirement: d.requirement,
15435
+ stages: Array.isArray(d.stages) ? d.stages : [],
15436
+ source: "server"
15437
+ }))
15438
+ ];
15439
+ return {
15440
+ checks,
15441
+ placeholders: SERVER_PLACEHOLDERS.map((d) => ({
15442
+ id: d.id,
15443
+ layer: d.layer,
15444
+ note: "\u670D\u52A1\u7AEF\u62A5\u544A\u7F3A\u5E2D\u6216\u5F02\u5E38\u65F6\u4EE3\u8868\u8BE5\u5C42\u8BF7\u6C42\u8303\u56F4\u7684\u5360\u4F4D\u884C\uFF1B\u4E0D\u662F\u53EF\u7B5B\u9009\u7684\u68C0\u67E5"
15445
+ })),
15446
+ server: reason ? { known: false, reason, catalogRevision: null } : { known: true, catalogRevision: catalog?.catalogRevision ?? null }
15447
+ };
15448
+ }
15449
+ function explainCatalog(ctx, id, reason) {
15450
+ const env2 = ctx.targetEnv ?? "<env>";
15451
+ const local = CHECKS.find((d) => d.id === id);
15452
+ if (local) return {
15453
+ id,
15454
+ layer: local.layer,
15455
+ name: local.name,
15456
+ source: "cli",
15457
+ criterion: localCriterion[id],
15458
+ requirement: local.requirement,
15459
+ stages: local.stages,
15460
+ grade: critical.has(id) ? "CRITICAL" : "WARN",
15461
+ dependsOn: local.dependsOn,
15462
+ coverageForm: local.coverageForm,
15463
+ coverageDomain: local.coverageDomain,
15464
+ timeoutMs: local.timeoutMs,
15465
+ codes: local.codes.map((key2) => {
15466
+ const row2 = CODE_TABLE[key2];
15467
+ return {
15468
+ code: key2,
15469
+ summaryTemplate: row2?.summary ?? key2,
15470
+ nextStep: row2?.command?.(env2) ?? null,
15471
+ owner: row2?.owner ?? local.owner
15472
+ };
15473
+ }),
15474
+ skill: null
15475
+ };
15476
+ const placeholder2 = SERVER_PLACEHOLDERS.find((d) => d.id === id);
15477
+ if (placeholder2) return {
15478
+ id,
15479
+ layer: placeholder2.layer,
15480
+ name: placeholder2.name,
15481
+ source: "cli",
15482
+ note: "\u5360\u4F4D\u884C\uFF1A\u670D\u52A1\u7AEF\u62A5\u544A\u7F3A\u5E2D\u6216\u5F02\u5E38\u65F6\u4EE3\u8868\u8BE5\u5C42\u8BF7\u6C42\u8303\u56F4\uFF0C\u4E0D\u662F\u670D\u52A1\u7AEF\u76EE\u5F55\u91CC\u7684\u53EF\u7B5B\u9009\u68C0\u67E5",
15483
+ requirement: placeholder2.requirement,
15484
+ dependsOn: placeholder2.dependsOn,
15485
+ codes: placeholder2.codes.map((key2) => ({
15486
+ code: key2,
15487
+ summaryTemplate: CODE_TABLE[key2]?.summary ?? key2,
15488
+ nextStep: CODE_TABLE[key2]?.command?.(env2) ?? null,
15489
+ owner: CODE_TABLE[key2]?.owner ?? placeholder2.owner
15490
+ }))
15491
+ };
15492
+ if (!id.startsWith("platform.") && !id.startsWith("tenant.")) throw new Error(`\u68C0\u67E5 id ${id} \u4E0D\u5B58\u5728\uFF1B\u53EF\u9009 id \u524D\u7F00\uFF1Alocal.\u3001connect.\u3001platform.\u3001tenant.`);
15493
+ if (reason) throw new Error(`\u670D\u52A1\u7AEF\u76EE\u5F55\u672A\u53D6\u5230\uFF0C\u65E0\u6CD5\u8BF4\u660E ${id}\uFF1A${reason}`);
15494
+ const catalog = ctx.environments.find((e) => e.report.target)?.catalog;
15495
+ const row = catalog?.checks.find((d) => d.id === id);
15496
+ if (!row) throw new Error(`\u68C0\u67E5 id ${id} \u4E0D\u5B58\u5728\uFF1B\u53EF\u9009 id \u524D\u7F00\uFF1Alocal.\u3001connect.\u3001platform.\u3001tenant.`);
15497
+ const spec = object2(row.spec) ? row.spec : {};
15498
+ const reserved = codeRows(catalog?.reservedCodes).filter((item) => {
15499
+ const key2 = code(item);
15500
+ return !special.has(key2) || key2 === "OPT_IN_REQUIRED" && spec.active === true || key2 === "PLATFORM_OPS_ONLY" && spec.layer === "platform" || key2 === "DEFINITION_MISSING" && spec.layer === "tenant" || key2 === "INVALID_DEFINITION" && spec.layer === "tenant" || key2 === "DEFINITIONS_UNAVAILABLE" && spec.layer === "tenant" || key2 === "NEED_SYSTEM_ADMIN" && spec.requiredPermission === "SYSTEM_ADMIN" || key2 === "NEED_CONFIG_ADMIN" && spec.requiredPermission === "CONFIG_ADMIN";
15501
+ });
15502
+ return {
15503
+ id,
15504
+ layer: spec.layer,
15505
+ name: row.name,
15506
+ source: "server",
15507
+ criterion: row.description,
15508
+ requirement: row.requirement,
15509
+ stages: row.stages,
15510
+ grade: row.grade,
15511
+ ...row.gradeByStage !== void 0 ? { gradeByStage: row.gradeByStage } : {},
15512
+ dependsOn: row.dependsOn,
15513
+ ruleType: row.ruleType,
15514
+ evaluatorKey: row.evaluatorKey,
15515
+ ruleDsl: row.ruleDsl,
15516
+ coverageForm: spec.coverageForm,
15517
+ coverageDomain: spec.coverageDomain,
15518
+ queryMode: spec.queryMode,
15519
+ requiredPermission: spec.requiredPermission,
15520
+ timeout: spec.timeout,
15521
+ paramSchema: spec.paramSchema,
15522
+ enabled: row.enabled,
15523
+ policySource: row.policySource,
15524
+ definitionId: row.definitionId,
15525
+ by: row.by,
15526
+ at: row.at,
15527
+ codes: codeRows(spec.codes),
15528
+ reservedCodes: reserved,
15529
+ ...row.skill ? { skill: row.skill } : {}
15530
+ };
15531
+ }
15532
+ var opsCriteria = {
15533
+ "connect.connectivity": "\u514D\u8BA4\u8BC1\u8BFB\u53D6\u540E\u7AEF\u7248\u672C\u7AEF\u70B9\uFF0C\u786E\u8BA4\u540E\u7AEF\u53EF\u8FBE",
15534
+ "connect.health-api": "\u7528\u53EA\u8BFB\u8FD0\u7EF4\u5BC6\u94A5\u8BF7\u6C42\u8FD0\u7EF4\u4F53\u68C0\u62A5\u544A\uFF0C\u786E\u8BA4\u8FD0\u7EF4\u7AEF\u70B9\u53EF\u5E94\u7B54",
15535
+ "platform.server-report": "\u8FD0\u7EF4\u62A5\u544A\u7F3A\u5E2D\u6216\u5F02\u5E38\u65F6\u4EE3\u8868\u5E73\u53F0\u5C42\u8BF7\u6C42\u8303\u56F4\uFF1B\u4E0D\u662F\u53EF\u7B5B\u9009\u7684\u68C0\u67E5"
15536
+ };
15537
+ var opsReservedNote = "\u6587\u6848\u4E0E owner \u4EE5\u670D\u52A1\u7AEF\u4E3A\u51C6\uFF1B\u8FD0\u7EF4\u62A5\u544A\u4E0D\u4E0B\u53D1\u4FDD\u7559\u7801\u8868\uFF0C\u6301\u79DF\u6237\u8EAB\u4EFD\u53EF\u7528 `hcm chiron doctor --explain <id>` \u770B\u5B8C\u6574\u7801\u8868";
15538
+ function explainOpsCatalog(id, report) {
15539
+ const local = OPS_DESCRIPTORS.find((row2) => row2.id === id);
15540
+ if (local) return {
15541
+ id,
15542
+ layer: local.layer,
15543
+ name: local.name,
15544
+ source: "cli",
15545
+ criterion: opsCriteria[id],
15546
+ requirement: local.requirement,
15547
+ stages: "stages" in local ? local.stages : [],
15548
+ grade: id === "connect.connectivity" ? "CRITICAL" : "WARN",
15549
+ dependsOn: local.dependsOn,
15550
+ coverageForm: "coverageForm" in local ? local.coverageForm : void 0,
15551
+ coverageDomain: "coverageDomain" in local ? local.coverageDomain : void 0,
15552
+ timeoutMs: "timeoutMs" in local ? local.timeoutMs : void 0,
15553
+ codes: local.codes.map((key2) => ({
15554
+ code: key2,
15555
+ summaryTemplate: CODE_TABLE[key2]?.summary ?? key2,
15556
+ nextStep: CODE_TABLE[key2]?.command?.("<env>") ?? null,
15557
+ owner: CODE_TABLE[key2]?.owner ?? local.owner
15558
+ })),
15559
+ reservedCodes: RESERVED_CODES.map((code2) => ({ code: code2 })),
15560
+ reservedCodesNote: opsReservedNote,
15561
+ skill: null
15562
+ };
15563
+ const checks = report?.checks ?? [];
15564
+ const row = checks.find((item) => item.id === id);
15565
+ if (!row) throw new Error(`\u68C0\u67E5 id ${id} \u4E0D\u5728\u8FD0\u7EF4\u62A5\u544A\u91CC\uFF1B\u62A5\u544A\u4E2D\u7684 id\uFF1A${checks.map((item) => item.id).join("\u3001") || "\u65E0"}`);
15566
+ const spec = object2(row.spec) ? row.spec : {};
15567
+ return {
15568
+ id,
15569
+ layer: spec.layer,
15570
+ name: row.name,
15571
+ source: "server",
15572
+ criterion: row.description,
15573
+ requirement: row.requirement,
15574
+ stages: row.stages,
15575
+ grade: row.grade,
15576
+ ...row.gradeByStage !== void 0 ? { gradeByStage: row.gradeByStage } : {},
15577
+ dependsOn: row.dependsOn,
15578
+ ruleType: row.ruleType,
15579
+ evaluatorKey: row.evaluatorKey,
15580
+ ruleDsl: row.ruleDsl,
15581
+ coverageForm: spec.coverageForm,
15582
+ coverageDomain: spec.coverageDomain,
15583
+ queryMode: spec.queryMode,
15584
+ requiredPermission: spec.requiredPermission,
15585
+ timeout: spec.timeout,
15586
+ paramSchema: spec.paramSchema,
15587
+ enabled: row.enabled,
15588
+ policySource: row.policySource,
15589
+ definitionId: row.definitionId,
15590
+ by: row.by,
15591
+ at: row.at,
15592
+ codes: codeRows(spec.codes),
15593
+ reservedCodes: RESERVED_CODES.map((code2) => ({ code: code2 })),
15594
+ reservedCodesNote: opsReservedNote,
15595
+ ...row.skill ? { skill: row.skill } : {}
15596
+ };
15597
+ }
15598
+ function renderCatalogList(data) {
15599
+ const lines = [
15600
+ "\u68C0\u67E5 id \xB7 \u5C42 \xB7 \u540D\u79F0 \xB7 \u5FC5\u68C0/\u9009\u68C0 \xB7 \u9636\u6BB5",
15601
+ ...data.checks.map((d) => `${d.id} \xB7 ${d.layer} \xB7 ${d.name} \xB7 ${d.requirement === "OPTIONAL" ? "\u9009\u68C0" : "\u5FC5\u68C0"} \xB7 ${d.stages.join(", ")}`),
15602
+ "\u5360\u4F4D\u884C\uFF1A",
15603
+ ...data.placeholders.map((d) => `${d.id} \xB7 ${d.layer} \xB7 ${d.note}`)
15604
+ ];
15605
+ if (!data.server.known) lines.push(`\u670D\u52A1\u7AEF\u76EE\u5F55\u672A\u53D6\u5230\uFF1A${data.server.reason}`);
15606
+ return lines.join("\n");
15607
+ }
15608
+ function renderCatalogExplanation(item) {
15609
+ const row = item;
15610
+ const lines = [
15611
+ `${row.id} \xB7 ${row.name} \xB7 ${row.layer}`,
15612
+ `\u5224\u636E\uFF1A${row.criterion ?? row.note ?? "\u65E0"}`,
15613
+ `\u9636\u6BB5\uFF1A${Array.isArray(row.stages) ? row.stages.join(", ") : "\u65E0"}`,
15614
+ `grade\uFF1A${row.grade ?? "\u65E0"}`,
15615
+ `gradeByStage\uFF1A${row.gradeByStage ? JSON.stringify(row.gradeByStage) : "\u65E0"}`,
15616
+ `\u4F9D\u8D56\uFF1A${Array.isArray(row.dependsOn) && row.dependsOn.length ? row.dependsOn.join(", ") : "\u65E0"}`,
15617
+ `\u5B9A\u4E49\u57DF\uFF1A${row.coverageDomain ?? "\u65E0"}`,
15618
+ `\u6280\u80FD\uFF1A${row.skill ?? "\u65E0"}`,
15619
+ "\u7801\u8868\uFF1A"
15620
+ ];
15621
+ for (const item2 of [...codeRows(row.codes), ...codeRows(row.reservedCodes)])
15622
+ lines.push(` ${code(item2)} \xB7 ${item2.summaryTemplate ?? "\u65E0"} \xB7 \u4E0B\u4E00\u6B65\uFF1A${item2.nextStep ?? "\u65E0"} \xB7 owner\uFF1A${item2.owner ?? "\u65E0"}`);
15623
+ if (row.reservedCodesNote) lines.push(String(row.reservedCodesNote));
15624
+ return lines.join("\n");
15625
+ }
15626
+
14515
15627
  // src/commands/chiron-doctor.ts
14516
15628
  var defaultServices = {
15629
+ reportRequest: requestServerReport,
15630
+ opsReportRequest: requestOpsReport,
14517
15631
  inspectCases: inspectCaseLibrary,
14518
15632
  inspectJira,
14519
15633
  inspectMethod: inspectMethodForDoctor,
14520
15634
  latestVersion: fetchLatestVersion,
14521
15635
  skillsFresh: inspectSkillsFresh,
14522
15636
  asAuth: (...args) => ensureAsAuth(...args),
14523
- probe: (endpoint, token, signal) => httpProbe2(axios7.create({
15637
+ probe: (endpoint, token, signal) => httpProbe2(axios9.create({
14524
15638
  baseURL: endpoint,
14525
15639
  timeout: 5e3,
14526
15640
  maxRedirects: 0,
@@ -14531,17 +15645,69 @@ var defaultServices = {
14531
15645
  };
14532
15646
  function validate(args) {
14533
15647
  for (const [key2, value, choices] of [["output", args.output, ["table", "json", "yaml"]], ["fail-on", args.failOn, ["blocked", "risks"]]])
14534
- if (value !== void 0 && !choices.includes(value)) throw new CliError30({
14535
- code: CliErrorCode31.INVALID_ARGUMENT,
15648
+ if (value !== void 0 && !choices.includes(value)) throw new CliError31({
15649
+ code: CliErrorCode32.INVALID_ARGUMENT,
14536
15650
  message: `--${key2} \u53EA\u63A5\u53D7 ${choices.join(" / ")}\uFF0C\u6536\u5230 ${value}`
14537
15651
  });
15652
+ const stages = ["handover", "baseline", "configure", "migrate", "integrate", "golive", "operate"];
15653
+ if (args.stage !== void 0 && !stages.includes(args.stage.toLowerCase())) throw new CliError31({
15654
+ code: CliErrorCode32.INVALID_ARGUMENT,
15655
+ message: `--stage \u53EA\u63A5\u53D7 ${stages.join(" / ")}\uFF0C\u6536\u5230 ${args.stage}`
15656
+ });
15657
+ if (args.platformOpsKeyStdin && !args.platformOps) invalidScope("--platform-ops-key-stdin \u53EA\u80FD\u4E0E --platform-ops \u540C\u7528");
15658
+ if (args.platformOps) {
15659
+ for (const [flag, present] of [
15660
+ ["--active", args.active],
15661
+ ["--stage", args.stage !== void 0],
15662
+ ["--as", args.as !== void 0],
15663
+ ["--project", args.project !== void 0]
15664
+ ])
15665
+ if (present) invalidScope(`${flag} \u4E0E --platform-ops \u4E0D\u80FD\u540C\u7528\uFF1A\u8FD0\u7EF4\u89C6\u56FE\u53EA\u6709\u5E73\u53F0\u5C42\u88AB\u52A8\u68C0\u67E5\uFF0C\u6CA1\u6709\u9636\u6BB5\u4E0E\u8EAB\u4EFD\u4E4B\u5206`);
15666
+ if (args.list) invalidScope("--list \u4E0E --platform-ops \u4E0D\u80FD\u540C\u7528\uFF1A\u8FD0\u7EF4\u89C6\u56FE\u7684\u76EE\u5F55\u5C31\u662F\u62A5\u544A\u672C\u8EAB\uFF0C\u76F4\u63A5\u8DD1\u5373\u53EF");
15667
+ }
15668
+ if (args.list && args.explain) invalidScope("--list \u4E0E --explain \u4E0D\u80FD\u540C\u7528");
15669
+ if ((args.list || args.explain) && (args.stage !== void 0 || tokens(args.only).length || tokens(args.skip).length || args.active || args.failOn !== void 0)) invalidScope("--list / --explain \u4E0D\u80FD\u4E0E --stage / --only / --skip / --active / --fail-on \u540C\u7528");
15670
+ }
15671
+ var tokens = (value) => (Array.isArray(value) ? value : value ? [value] : []).flatMap((item) => item.split(",")).map((item) => item.trim()).filter(Boolean);
15672
+ var matches = (id, only, skip) => (!only.length || only.some((t) => id.startsWith(t))) && !skip.some((t) => id.startsWith(t));
15673
+ var serverCandidate = (t) => ["platform.", "tenant."].some((prefix) => prefix.startsWith(t) || t.startsWith(prefix));
15674
+ function invalidScope(message) {
15675
+ throw new CliError31({ code: CliErrorCode32.INVALID_ARGUMENT, message });
15676
+ }
15677
+ function scopeFor2(args, catalog) {
15678
+ const only = tokens(args.only), skip = tokens(args.skip), stage = args.stage?.toLowerCase() ?? null;
15679
+ const serverChecks = catalog?.checks ?? [];
15680
+ const valid = (t) => CHECKS.some((d) => d.id.startsWith(t)) || serverChecks.some((d) => d.id.startsWith(t)) || catalog?.tenantCatalog.available === false && (t.startsWith("tenant.") || "tenant.".startsWith(t)) || !catalog && serverCandidate(t);
15681
+ for (const t of [...only, ...skip]) if (!valid(t)) invalidScope(`\u8303\u56F4\u524D\u7F00 ${t} \u4E0D\u5B58\u5728\uFF1B\u53EF\u9009\u524D\u7F00\uFF1Alocal.\u3001connect.\u3001platform.\u3001tenant.`);
15682
+ const forwarded = (items) => items.filter((t) => serverChecks.some((d) => d.id.startsWith(t)) || catalog?.tenantCatalog.available === false && (t.startsWith("tenant.") || "tenant.".startsWith(t)) || !catalog && serverCandidate(t));
15683
+ const forwardedOnly = forwarded(only), forwardedSkip = forwarded(skip);
15684
+ const serverIds = new Set(serverChecks.filter((d) => (!stage || Array.isArray(d.stages) && d.stages.some((s) => s.toLowerCase() === stage)) && matches(d.id, only, skip)).map((d) => d.id));
15685
+ const serverLayers = /* @__PURE__ */ new Set();
15686
+ for (const layer2 of ["platform", "tenant"]) {
15687
+ const root = `${layer2}.`;
15688
+ const possible = (!only.length || only.some((t) => root.startsWith(t) || t.startsWith(root))) && !skip.some((t) => root.startsWith(t));
15689
+ if (possible && (!catalog || serverChecks.some((d) => serverIds.has(d.id) && d.spec?.layer === layer2) || layer2 === "tenant" && catalog.tenantCatalog.available === false)) serverLayers.add(layer2);
15690
+ }
15691
+ const serverRelevant = (!only.length || only.some(serverCandidate)) && !["platform.", "tenant."].every((root) => skip.some((t) => root.startsWith(t)));
15692
+ return {
15693
+ stage,
15694
+ only,
15695
+ skip,
15696
+ active: !!args.active,
15697
+ forwardedOnly,
15698
+ forwardedSkip,
15699
+ serverIds,
15700
+ serverLayers,
15701
+ serverRelevant,
15702
+ addedPrerequisites: []
15703
+ };
14538
15704
  }
14539
15705
  async function readCredential(envFlag, root, as) {
14540
15706
  let resolved;
14541
15707
  try {
14542
- resolved = await resolveEnvContext8({ envFlag, cwd: root }, process.env, await loadGlobalConfig11());
15708
+ resolved = await resolveEnvContext9({ envFlag, cwd: root }, process.env, await loadGlobalConfig12());
14543
15709
  } catch (error) {
14544
- if (error instanceof CliError30 && error.code === CliErrorCode31.ENV_NOT_FOUND) return { resolved: null };
15710
+ if (error instanceof CliError31 && error.code === CliErrorCode32.ENV_NOT_FOUND) return { resolved: null };
14545
15711
  throw error;
14546
15712
  }
14547
15713
  if (as) return { resolved };
@@ -14550,14 +15716,14 @@ async function readCredential(envFlag, root, as) {
14550
15716
  try {
14551
15717
  identity3 = await resolveActiveIdentity2({}, process.env, resolved.name);
14552
15718
  } catch (error) {
14553
- if (error instanceof CliError30 && error.code === CliErrorCode31.IDENTITY_NOT_FOUND) return { resolved, error: found("IDENTITY_NOT_LOGGED_IN") };
15719
+ if (error instanceof CliError31 && error.code === CliErrorCode32.IDENTITY_NOT_FOUND) return { resolved, error: found("IDENTITY_NOT_LOGGED_IN") };
14554
15720
  throw error;
14555
15721
  }
14556
15722
  let meta2;
14557
15723
  try {
14558
15724
  meta2 = await loadIdentity5(identity3);
14559
15725
  } catch (error) {
14560
- if (error instanceof CliError30 && error.code === CliErrorCode31.IDENTITY_NOT_FOUND) return { resolved, identity: identity3, error: found("IDENTITY_META_INVALID", `\u8EAB\u4EFD ${identity3} \u7684\u5143\u6570\u636E\u4E0D\u5B58\u5728\uFF1B\u91CD\u65B0\u767B\u5F55\u4FEE\u590D`) };
15726
+ if (error instanceof CliError31 && error.code === CliErrorCode32.IDENTITY_NOT_FOUND) return { resolved, identity: identity3, error: found("IDENTITY_META_INVALID", `\u8EAB\u4EFD ${identity3} \u7684\u5143\u6570\u636E\u4E0D\u5B58\u5728\uFF1B\u91CD\u65B0\u767B\u5F55\u4FEE\u590D`) };
14561
15727
  throw error;
14562
15728
  }
14563
15729
  if (!meta2.env || meta2.env !== resolved.name) return {
@@ -14567,11 +15733,10 @@ async function readCredential(envFlag, root, as) {
14567
15733
  error: found("IDENTITY_META_INVALID", `\u8EAB\u4EFD ${identity3} \u7684 env ${meta2.env ?? "\u7F3A\u5931"} \u4E0E\u672C\u673A\u69FD ${resolved.name} \u4E0D\u7B26\uFF1B\u91CD\u65B0\u767B\u5F55\u4FEE\u590D`)
14568
15734
  };
14569
15735
  const token = await readStoredIdentityToken(identity3);
14570
- printResolvedEnvironment8(resolved, identity3, resolved.project?.environment.tenant);
15736
+ printResolvedEnvironment9(resolved, identity3, resolved.project?.environment.tenant);
14571
15737
  return { resolved, identity: identity3, meta: meta2, token };
14572
15738
  }
14573
- async function runChironDoctor(args, deps = {}) {
14574
- validate(args);
15739
+ async function prepareContext(args, deps) {
14575
15740
  const startedAt = Date.now(), root = path14.resolve(args.project ?? ".");
14576
15741
  let file;
14577
15742
  let projectObservation = found("ENV_FILE_MISSING", void 0, { evidence: "ABSENT" });
@@ -14590,7 +15755,7 @@ async function runChironDoctor(args, deps = {}) {
14590
15755
  let explicitSlot;
14591
15756
  if (file && args.env && !Object.hasOwn(file.environments, args.env)) {
14592
15757
  try {
14593
- const resolved = await resolveEnvContext8({ envFlag: args.env, cwd: root }, process.env, await loadGlobalConfig11());
15758
+ const resolved = await resolveEnvContext9({ envFlag: args.env, cwd: root }, process.env, await loadGlobalConfig12());
14594
15759
  if (!resolved.project) throw new Error("\u672C\u673A\u69FD\u4E0D\u5C5E\u4E8E\u5F53\u524D\u9879\u76EE");
14595
15760
  targetEnv = resolved.project.name;
14596
15761
  explicitSlot = resolved.name;
@@ -14625,29 +15790,141 @@ async function runChironDoctor(args, deps = {}) {
14625
15790
  }
14626
15791
  };
14627
15792
  });
14628
- const results = await executeChecks(ctx);
14629
- await Promise.all(ctx.environments.map(async (env2) => {
14630
- if (!env2.close) return;
14631
- try {
14632
- await env2.close();
14633
- } catch (error) {
14634
- const identity3 = results.find((r) => r.checkId === "connect.identity" && r.env === env2.name);
14635
- if (identity3) identity3.verdict.note = `${identity3.verdict.note ? `${identity3.verdict.note}\uFF1B` : ""}\u4EE3\u7406\u4F1A\u8BDD\u6536\u5C3E\u672A\u786E\u8BA4\uFF1A${safeError(error)}\uFF1B\u670D\u52A1\u7AEF\u6309\u6709\u6548\u671F\u81EA\u7136\u8FC7\u671F`;
14636
- }
14637
- }));
14638
- if (ctx.environments.some((env2) => env2.close)) await releasePendingImpersonationSessions2();
14639
- return assembleReport({
15793
+ return { ctx, file, projectObservation, startedAt, root };
15794
+ }
15795
+ async function runChironDoctor(args, deps = {}) {
15796
+ validate(args);
15797
+ for (const t of [...tokens(args.only), ...tokens(args.skip)])
15798
+ if (!CHECKS.some((d) => d.id.startsWith(t)) && !serverCandidate(t)) invalidScope(`\u8303\u56F4\u524D\u7F00 ${t} \u4E0D\u5B58\u5728\uFF1B\u53EF\u9009\u524D\u7F00\uFF1Alocal.\u3001connect.\u3001platform.\u3001tenant.`);
15799
+ const { ctx, file, projectObservation, startedAt, root } = await prepareContext(args, deps);
15800
+ let results = [];
15801
+ try {
15802
+ const mayNeedServer = (!tokens(args.only).length || tokens(args.only).some(serverCandidate)) && !["platform.", "tenant."].every((prefix) => tokens(args.skip).some((t) => prefix.startsWith(t)));
15803
+ const preflight = mayNeedServer && ctx.environments.some((e) => e.report.target) ? await executeChecks(ctx, {
15804
+ checks: CHECKS.filter((d) => ["connect.connectivity", "connect.identity", "connect.health-api"].includes(d.id)),
15805
+ fetchReport: false,
15806
+ onlyTarget: true,
15807
+ budgetMs: Math.max(0, 45e3 - (Date.now() - startedAt))
15808
+ }) : [];
15809
+ const targetBefore = ctx.environments.find((e) => e.report.target);
15810
+ const scope2 = scopeFor2(args, targetBefore?.catalog);
15811
+ const selectedLocal = CHECKS.filter((d) => d.layer === "local" && (!scope2.stage || d.stages.includes(scope2.stage)) && matches(d.id, scope2.only, scope2.skip));
15812
+ const selectedConnect = targetBefore ? CHECKS.filter((d) => d.layer === "connect" && (!scope2.stage || d.stages.includes(scope2.stage)) && matches(d.id, scope2.only, scope2.skip)) : [];
15813
+ if (!selectedLocal.length && !selectedConnect.length && !scope2.serverLayers.size) invalidScope(
15814
+ `${!file ? `\u9879\u76EE\u73AF\u5883\u672A\u89E3\u6790\uFF1A${projectObservation.note ?? projectObservation.code ?? "env.yaml \u8BFB\u4E0D\u5230"}\uFF1B\u53BB\u6389 --only \u91CD\u8DD1\u53EF\u770B\u5230 local.project.env \u7684\u7ED3\u8BBA\uFF1B` : ""}\u8FD9\u4E2A\u8303\u56F4\u5185\u6CA1\u6709\u4EFB\u4F55\u68C0\u67E5`
15815
+ );
15816
+ if (scope2.serverLayers.size) scope2.addedPrerequisites = ["connect.connectivity", "connect.identity", "connect.health-api"].filter((id) => !selectedConnect.some((d) => d.id === id));
15817
+ ctx.scope = scope2;
15818
+ const reused = /* @__PURE__ */ new Set([...selectedConnect.map((d) => d.id), ...scope2.addedPrerequisites]);
15819
+ results = await executeChecks(ctx, {
15820
+ precomputed: preflight.filter((row) => reused.has(row.checkId)),
15821
+ budgetMs: Math.max(0, 45e3 - (Date.now() - startedAt))
15822
+ });
15823
+ } finally {
15824
+ await Promise.all(ctx.environments.map(async (env2) => {
15825
+ if (!env2.close) return;
15826
+ try {
15827
+ await env2.close();
15828
+ } catch (error) {
15829
+ const identity3 = results.find((r) => r.checkId === "connect.identity" && r.env === env2.name);
15830
+ if (identity3) identity3.verdict.note = `${identity3.verdict.note ? `${identity3.verdict.note}\uFF1B` : ""}\u4EE3\u7406\u4F1A\u8BDD\u6536\u5C3E\u672A\u786E\u8BA4\uFF1A${safeError(error)}\uFF1B\u670D\u52A1\u7AEF\u6309\u6709\u6548\u671F\u81EA\u7136\u8FC7\u671F`;
15831
+ }
15832
+ }));
15833
+ if (ctx.environments.some((env2) => env2.close)) await releasePendingImpersonationSessions2();
15834
+ }
15835
+ const scope = ctx.scope;
15836
+ const target = ctx.environments.find((env2) => env2.report.target);
15837
+ if (target?.serverReport?.scope?.policyDisabled?.length) process.stderr.write(renderPolicyDisabled(
15838
+ target.serverReport.scope.policyDisabled,
15839
+ target.catalog,
15840
+ target.serverReport.recoveryCommand
15841
+ ) + "\n");
15842
+ const report = assembleReport({
14640
15843
  results,
15844
+ serverReport: target?.serverReport,
15845
+ catalog: target?.catalog,
14641
15846
  environments: ctx.environments.map((e) => e.report),
14642
- targetEnv,
15847
+ targetEnv: ctx.targetEnv,
14643
15848
  project: root,
14644
15849
  cliVersion: CLI_VERSION,
14645
15850
  startedAt,
14646
- failOn: args.failOn ?? "blocked"
15851
+ failOn: args.failOn ?? "blocked",
15852
+ scope
14647
15853
  });
15854
+ if (target?.serverReport?.recoveryCommand) reportRecoveryCommands.set(report, target.serverReport.recoveryCommand);
15855
+ return report;
15856
+ }
15857
+ async function runChironCatalog(args, deps) {
15858
+ const { ctx } = await prepareContext(args, deps);
15859
+ const target = ctx.environments.find((e) => e.report.target);
15860
+ let preflight = [];
15861
+ try {
15862
+ if (target) preflight = await executeChecks(ctx, {
15863
+ checks: CHECKS.filter((d) => ["connect.connectivity", "connect.identity", "connect.health-api"].includes(d.id)),
15864
+ fetchReport: false,
15865
+ onlyTarget: true
15866
+ });
15867
+ } finally {
15868
+ await Promise.all(ctx.environments.map(async (env2) => {
15869
+ if (env2.close) {
15870
+ try {
15871
+ await env2.close();
15872
+ } catch (error) {
15873
+ process.stderr.write(`\u4EE3\u7406\u4F1A\u8BDD\u6536\u5C3E\u672A\u786E\u8BA4\uFF1A${safeError(error)}
15874
+ `);
15875
+ }
15876
+ }
15877
+ }));
15878
+ if (ctx.environments.some((env2) => env2.close)) await releasePendingImpersonationSessions2();
15879
+ }
15880
+ const blocker = ["connect.connectivity", "connect.identity", "connect.health-api"].map((id) => preflight.find((r) => r.checkId === id && r.env === target?.name)).find((r) => r && r.verdict.level !== "PASS");
15881
+ const project2 = ctx.projectObservation, step2 = project2.code ? codeStep(project2.code, ctx.targetEnv ?? "<env>").command : void 0;
15882
+ const detail = [project2.summary !== project2.code ? project2.summary : void 0, project2.note].filter(Boolean).join("\uFF1B");
15883
+ const reason = !target ? `\u76EE\u6807\u73AF\u5883\u672A\u89E3\u6790\uFF1A${project2.code ?? "env.yaml \u8BFB\u4E0D\u5230"}${project2.code && CODE_TABLE[project2.code] ? ` \xB7 ${CODE_TABLE[project2.code].summary}` : ""}${detail ? `\uFF08${detail}\uFF09` : ""}${step2 ? `\uFF1B\u4E0B\u4E00\u6B65\uFF1A${step2}` : ""}` : blocker ? `${blocker.checkId}\uFF1A${blocker.code ?? blocker.verdict.level} \xB7 ${blocker.summary}${blocker.verdict.note ? `\uFF08${blocker.verdict.note}\uFF09` : ""}\uFF1B\u76EE\u6807 ${target.name} \xB7 ${target.config.endpoint}${blocker.nextStep?.command ? `\uFF1B\u4E0B\u4E00\u6B65\uFF1A${blocker.nextStep.command}` : ""}` : !target.catalog ? "\u4F53\u68C0\u76EE\u5F55\u5C1A\u672A\u53D6\u5F97" : target.catalog.catalogRevision === null || target.catalog.tenantCatalog.available === false ? "\u670D\u52A1\u7AEF\u76EE\u5F55\u7248\u672C\u672A\u77E5\uFF0C\u79DF\u6237\u68C0\u67E5\u5B9A\u4E49\u672A\u53D6\u5230" : void 0;
15884
+ return args.list ? listCatalog(ctx, reason) : explainCatalog(ctx, args.explain, reason);
14648
15885
  }
14649
15886
  async function chironDoctorCommand(args, deps) {
14650
15887
  try {
15888
+ validate(args);
15889
+ if (args.platformOps) {
15890
+ if (args.explain) {
15891
+ let descriptorReport;
15892
+ const local = ["connect.connectivity", "connect.health-api", "platform.server-report"].includes(args.explain);
15893
+ if (!local) {
15894
+ const report3 = await runPlatformOps(args, { ...defaultServices, ...deps }, void 0, (value) => {
15895
+ descriptorReport = value;
15896
+ });
15897
+ if (!descriptorReport) {
15898
+ for (const id of ["connect.connectivity", "connect.health-api", "platform.server-report"]) {
15899
+ const row = report3.results.find((item) => item.checkId === id);
15900
+ if (row && (id !== "connect.connectivity" || row.verdict.level !== "PASS")) process.stderr.write(`${id}: ${row.verdict.level} \xB7 code=${row.code ?? "\u65E0"} \xB7 ${String(row.summary ?? "")} \xB7 note=${row.verdict.note ?? "\u65E0"}
15901
+ `);
15902
+ }
15903
+ throw new Error(`\u8FD0\u7EF4\u62A5\u544A\u672A\u53D6\u5230\uFF0C\u65E0\u6CD5\u8BF4\u660E ${args.explain}\uFF1B\u5148\u6392\u9664\u4E0A\u9762\u7684\u9519\u8BEF\u518D\u8BD5`);
15904
+ }
15905
+ }
15906
+ const data = explainOpsCatalog(args.explain, descriptorReport);
15907
+ process.stdout.write((args.output === "json" || args.output === "yaml" ? formatObject28(data, { format: args.output }) : renderCatalogExplanation(data)) + "\n");
15908
+ process.exitCode = 0;
15909
+ return;
15910
+ }
15911
+ const report2 = await runPlatformOps(args, { ...defaultServices, ...deps });
15912
+ process.stdout.write((args.output === "json" || args.output === "yaml" ? formatObject28(report2, { format: args.output }) : renderChironDoctor(report2)) + "\n");
15913
+ process.exitCode = conclude(report2.results, { total: report2.coverage.total, failOn: args.failOn ?? "blocked" }).exitCode;
15914
+ return;
15915
+ }
15916
+ if (args.list || args.explain) {
15917
+ validate(args);
15918
+ const data = await runChironCatalog(args, deps ?? {});
15919
+ if (args.list) {
15920
+ const listing = data;
15921
+ if (!listing.server.known) process.stderr.write(`\u670D\u52A1\u7AEF\u76EE\u5F55\u672A\u53D6\u5230\uFF1A${listing.server.reason}
15922
+ `);
15923
+ }
15924
+ process.stdout.write((args.output === "json" || args.output === "yaml" ? formatObject28(data, { format: args.output }) : args.list ? renderCatalogList(data) : renderCatalogExplanation(data)) + "\n");
15925
+ process.exitCode = 0;
15926
+ return;
15927
+ }
14651
15928
  const report = await runChironDoctor(args, deps);
14652
15929
  process.stdout.write((args.output === "json" || args.output === "yaml" ? formatObject28(report, { format: args.output }) : renderChironDoctor(report)) + "\n");
14653
15930
  process.exitCode = conclude(report.results, { total: report.coverage.total, failOn: args.failOn ?? "blocked" }).exitCode;
@@ -14666,11 +15943,11 @@ import { accessSync, constants, readdirSync as readdirSync3 } from "fs";
14666
15943
  import fs13 from "fs/promises";
14667
15944
  import os6 from "os";
14668
15945
  import path16 from "path";
14669
- import { CliError as CliError33, CliErrorCode as CliErrorCode34, formatObject as formatObject29, HcmClient as HcmClient24, loadEnv as loadEnv6 } from "@hcmai/sdk";
15946
+ import { CliError as CliError34, CliErrorCode as CliErrorCode35, formatObject as formatObject29, HcmClient as HcmClient24, loadEnv as loadEnv6 } from "@hcmai/sdk";
14670
15947
  import { createRequire } from "module";
14671
15948
 
14672
15949
  // src/commands/chiron-page-cdp.ts
14673
- import { CliError as CliError31, CliErrorCode as CliErrorCode32 } from "@hcmai/sdk";
15950
+ import { CliError as CliError32, CliErrorCode as CliErrorCode33 } from "@hcmai/sdk";
14674
15951
 
14675
15952
  // src/commands/chiron-page-shared.ts
14676
15953
  function redactTicket(text) {
@@ -14706,14 +15983,14 @@ function normalizeCdpEndpoint(raw) {
14706
15983
  try {
14707
15984
  url = new URL(candidate);
14708
15985
  } catch {
14709
- throw new CliError31({ code: CliErrorCode32.INVALID_ARGUMENT, message: `--cdp \u8981\u5199\u6210 http://\u4E3B\u673A:\u7AEF\u53E3\uFF08Chrome \u7684 --remote-debugging-port\uFF09\uFF0C\u6536\u5230\u7684\u662F ${text}` });
15986
+ throw new CliError32({ code: CliErrorCode33.INVALID_ARGUMENT, message: `--cdp \u8981\u5199\u6210 http://\u4E3B\u673A:\u7AEF\u53E3\uFF08Chrome \u7684 --remote-debugging-port\uFF09\uFF0C\u6536\u5230\u7684\u662F ${text}` });
14710
15987
  }
14711
15988
  const protocol = url.protocol === "wss:" ? "https:" : url.protocol === "ws:" ? "http:" : url.protocol;
14712
15989
  if (protocol !== "http:" && protocol !== "https:") {
14713
- throw new CliError31({ code: CliErrorCode32.INVALID_ARGUMENT, message: `--cdp \u53EA\u8BA4 http(s) \u6216 ws(s) \u7AEF\u70B9\uFF0C\u6536\u5230\u7684\u662F ${text}` });
15990
+ throw new CliError32({ code: CliErrorCode33.INVALID_ARGUMENT, message: `--cdp \u53EA\u8BA4 http(s) \u6216 ws(s) \u7AEF\u70B9\uFF0C\u6536\u5230\u7684\u662F ${text}` });
14714
15991
  }
14715
15992
  if (!url.port) {
14716
- throw new CliError31({ code: CliErrorCode32.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}` });
15993
+ throw new CliError32({ code: CliErrorCode33.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}` });
14717
15994
  }
14718
15995
  return `${protocol}//${url.hostname}:${url.port}`;
14719
15996
  }
@@ -14810,8 +16087,8 @@ async function captureViaCdp(input, io) {
14810
16087
  const browser = version2?.Browser ? String(version2.Browser) : `attached ${input.endpoint}`;
14811
16088
  const target = await io.fetchJson(`${input.endpoint}/json/new?about:blank`, "PUT");
14812
16089
  if (!target?.id || !target.webSocketDebuggerUrl) {
14813
- throw new CliError31({
14814
- code: CliErrorCode32.SERVER_ERROR,
16090
+ throw new CliError32({
16091
+ code: CliErrorCode33.SERVER_ERROR,
14815
16092
  message: `${input.endpoint}/json/new \u6CA1\u6709\u7ED9\u51FA\u6807\u7B7E\u9875\uFF08id / webSocketDebuggerUrl \u7F3A\u5931\uFF09`,
14816
16093
  context: { nextStep: "\u786E\u8BA4 Chrome \u662F\u5E26 --remote-debugging-port \u8D77\u7684\uFF0C\u4E14 --cdp \u6307\u5230\u7684\u662F\u5B83" }
14817
16094
  });
@@ -14841,7 +16118,7 @@ async function captureViaCdp(input, io) {
14841
16118
  });
14842
16119
  if (r.exceptionDetails) {
14843
16120
  const why = r.exceptionDetails.exception?.description ?? r.exceptionDetails.text ?? "unknown";
14844
- throw new CliError31({ code: CliErrorCode32.INVALID_ARGUMENT, message: `--eval \u5728\u9875\u9762\u91CC\u629B\u4E86\u5F02\u5E38\uFF1A${redactTicket(why.split("\n")[0] ?? why)}` });
16121
+ throw new CliError32({ code: CliErrorCode33.INVALID_ARGUMENT, message: `--eval \u5728\u9875\u9762\u91CC\u629B\u4E86\u5F02\u5E38\uFF1A${redactTicket(why.split("\n")[0] ?? why)}` });
14845
16122
  }
14846
16123
  evalResult = r.result && "value" in r.result ? toPlainJson(r.result.value) : toPlainJson(r.result?.description);
14847
16124
  }
@@ -14852,7 +16129,7 @@ async function captureViaCdp(input, io) {
14852
16129
  const dom = typeof domReply.result?.value === "string" ? domReply.result.value : "";
14853
16130
  const shot = await session.send("Page.captureScreenshot", { format: "png" });
14854
16131
  if (!shot.data) {
14855
- throw new CliError31({ code: CliErrorCode32.SERVER_ERROR, message: "Page.captureScreenshot \u6CA1\u6709\u8FD4\u56DE\u56FE\u50CF\u6570\u636E" });
16132
+ throw new CliError32({ code: CliErrorCode33.SERVER_ERROR, message: "Page.captureScreenshot \u6CA1\u6709\u8FD4\u56DE\u56FE\u50CF\u6570\u636E" });
14856
16133
  }
14857
16134
  await io.writeFile(input.screenshot, Buffer.from(shot.data, "base64"));
14858
16135
  return { dom, browser, evalResult, navigated, minted };
@@ -14874,7 +16151,7 @@ var defaultCdpIo = {
14874
16151
  openSocket: (wsUrl) => new Promise((resolve3, reject) => {
14875
16152
  const Ctor = globalThis.WebSocket;
14876
16153
  if (!Ctor) {
14877
- reject(new CliError31({ code: CliErrorCode32.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" }));
16154
+ reject(new CliError32({ code: CliErrorCode33.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" }));
14878
16155
  return;
14879
16156
  }
14880
16157
  const ws = new Ctor(wsUrl);
@@ -14897,7 +16174,7 @@ var defaultCdpIo = {
14897
16174
 
14898
16175
  // src/commands/chiron-page-playwright.ts
14899
16176
  import path15 from "path";
14900
- import { CliError as CliError32, CliErrorCode as CliErrorCode33 } from "@hcmai/sdk";
16177
+ import { CliError as CliError33, CliErrorCode as CliErrorCode34 } from "@hcmai/sdk";
14901
16178
  function playwrightCacheRoot(probe2) {
14902
16179
  const override = probe2.env.PLAYWRIGHT_BROWSERS_PATH?.trim();
14903
16180
  if (override === "0" && probe2.packageRoot) return path15.join(probe2.packageRoot, ".local-browsers");
@@ -14940,8 +16217,8 @@ function discoverPlaywrightBrowser(probe2) {
14940
16217
  const explicit = probe2.env.HCM_PLAYWRIGHT_EXECUTABLE?.trim();
14941
16218
  if (explicit) {
14942
16219
  if (probe2.executable(explicit)) return { executablePath: explicit, kind: "explicit", from: "HCM_PLAYWRIGHT_EXECUTABLE" };
14943
- throw new CliError32({
14944
- code: CliErrorCode33.INVALID_ARGUMENT,
16220
+ throw new CliError33({
16221
+ code: CliErrorCode34.INVALID_ARGUMENT,
14945
16222
  message: `HCM_PLAYWRIGHT_EXECUTABLE \u6307\u7684\u6587\u4EF6\u4E0D\u53EF\u6267\u884C\uFF1A${explicit}`,
14946
16223
  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" }
14947
16224
  });
@@ -14983,8 +16260,8 @@ async function captureViaPlaywright(input) {
14983
16260
  }
14984
16261
  }
14985
16262
  if (!browser) {
14986
- throw new CliError32({
14987
- code: CliErrorCode33.SERVER_ERROR,
16263
+ throw new CliError33({
16264
+ code: CliErrorCode34.SERVER_ERROR,
14988
16265
  message: `Playwright \u8D77\u4E0D\u4E86\u6D4F\u89C8\u5668\uFF1A${failures.join("\uFF1B")}`,
14989
16266
  context: {
14990
16267
  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"
@@ -15004,7 +16281,7 @@ async function captureViaPlaywright(input) {
15004
16281
  evalResult = toPlainJson(await page.evaluate(wrapEvalBody(input.evalJs)));
15005
16282
  } catch (e) {
15006
16283
  const why = (e instanceof Error ? e.message : String(e)).split("\n")[0] ?? "";
15007
- throw new CliError32({ code: CliErrorCode33.INVALID_ARGUMENT, message: `--eval \u5728\u9875\u9762\u91CC\u629B\u4E86\u5F02\u5E38\uFF1A${redactTicket(why)}` });
16284
+ throw new CliError33({ code: CliErrorCode34.INVALID_ARGUMENT, message: `--eval \u5728\u9875\u9762\u91CC\u629B\u4E86\u5F02\u5E38\uFF1A${redactTicket(why)}` });
15008
16285
  }
15009
16286
  }
15010
16287
  const dom = await page.content();
@@ -15028,13 +16305,13 @@ function judgePageContent(input) {
15028
16305
  function parseViewport(size) {
15029
16306
  const m = /^(\d+)x(\d+)$/.exec(size.trim());
15030
16307
  if (!m) {
15031
- throw new CliError33({ code: CliErrorCode34.INVALID_ARGUMENT, message: `--size \u8981\u5199\u6210 <\u5BBD>x<\u9AD8>\uFF0C\u4F8B\u5982 1440x900\uFF0C\u6536\u5230\u7684\u662F ${size}` });
16308
+ throw new CliError34({ code: CliErrorCode35.INVALID_ARGUMENT, message: `--size \u8981\u5199\u6210 <\u5BBD>x<\u9AD8>\uFF0C\u4F8B\u5982 1440x900\uFF0C\u6536\u5230\u7684\u662F ${size}` });
15032
16309
  }
15033
16310
  const width = Number(m[1]);
15034
16311
  const height = Number(m[2]);
15035
16312
  if (width < VIEWPORT_MIN.width || width > VIEWPORT_MAX.width || height < VIEWPORT_MIN.height || height > VIEWPORT_MAX.height) {
15036
- throw new CliError33({
15037
- code: CliErrorCode34.INVALID_ARGUMENT,
16313
+ throw new CliError34({
16314
+ code: CliErrorCode35.INVALID_ARGUMENT,
15038
16315
  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}`
15039
16316
  });
15040
16317
  }
@@ -15044,23 +16321,23 @@ function parseWaitMs(raw) {
15044
16321
  if (raw === void 0) return 1e4;
15045
16322
  const value = typeof raw === "number" ? raw : Number(raw);
15046
16323
  if (!Number.isInteger(value) || value < 0 || value > WAIT_MS_MAX) {
15047
- throw new CliError33({ code: CliErrorCode34.INVALID_ARGUMENT, message: `--wait-ms \u8981\u662F 0..${WAIT_MS_MAX} \u7684\u6574\u6570\uFF0C\u6536\u5230\u7684\u662F ${raw}` });
16324
+ throw new CliError34({ code: CliErrorCode35.INVALID_ARGUMENT, message: `--wait-ms \u8981\u662F 0..${WAIT_MS_MAX} \u7684\u6574\u6570\uFF0C\u6536\u5230\u7684\u662F ${raw}` });
15048
16325
  }
15049
16326
  return value;
15050
16327
  }
15051
16328
  function resolveEvidenceTarget(projectRoot, out) {
15052
16329
  if (!out?.trim()) {
15053
- throw new CliError33({ code: CliErrorCode34.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` });
16330
+ throw new CliError34({ code: CliErrorCode35.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` });
15054
16331
  }
15055
16332
  if (!out.endsWith(".png")) {
15056
- throw new CliError33({ code: CliErrorCode34.INVALID_ARGUMENT, message: `--out \u8981\u4EE5 .png \u7ED3\u5C3E\uFF0C\u6536\u5230\u7684\u662F ${out}` });
16333
+ throw new CliError34({ code: CliErrorCode35.INVALID_ARGUMENT, message: `--out \u8981\u4EE5 .png \u7ED3\u5C3E\uFF0C\u6536\u5230\u7684\u662F ${out}` });
15057
16334
  }
15058
16335
  const root = path16.resolve(projectRoot);
15059
16336
  const evidenceRoot = path16.join(root, EVIDENCE_DIR);
15060
16337
  const absolute = path16.resolve(root, out);
15061
16338
  if (absolute !== evidenceRoot && !absolute.startsWith(evidenceRoot + path16.sep)) {
15062
- throw new CliError33({
15063
- code: CliErrorCode34.INVALID_ARGUMENT,
16339
+ throw new CliError34({
16340
+ code: CliErrorCode35.INVALID_ARGUMENT,
15064
16341
  message: `--out \u8981\u843D\u5728\u9879\u76EE\u7684 ${EVIDENCE_DIR}/ \u4E0B\uFF08${evidenceRoot}\uFF09\uFF0C\u6536\u5230\u7684\u662F ${absolute}`
15065
16342
  });
15066
16343
  }
@@ -15108,8 +16385,8 @@ async function assertInsideEvidence(deps, evidenceRoot, absolute) {
15108
16385
  const canonicalParent = await deps.realpath(path16.dirname(absolute));
15109
16386
  if (canonicalRoot === null || canonicalParent === null) return;
15110
16387
  if (canonicalParent !== canonicalRoot && !canonicalParent.startsWith(canonicalRoot + path16.sep)) {
15111
- throw new CliError33({
15112
- code: CliErrorCode34.INVALID_ARGUMENT,
16388
+ throw new CliError34({
16389
+ code: CliErrorCode35.INVALID_ARGUMENT,
15113
16390
  message: `--out \u7684\u7236\u76EE\u5F55\u7ECF\u7B26\u53F7\u94FE\u63A5\u8DD1\u51FA\u4E86 ${EVIDENCE_DIR}/\uFF1A${canonicalParent}`
15114
16391
  });
15115
16392
  }
@@ -15118,8 +16395,8 @@ async function runChironPage(target, args, deps) {
15118
16395
  const sitePath = normalizeTarget(target);
15119
16396
  const expect = (args.expectText ?? []).filter((t) => t.trim().length > 0);
15120
16397
  if (expect.length === 0) {
15121
- throw new CliError33({
15122
- code: CliErrorCode34.MISSING_FLAG,
16398
+ throw new CliError34({
16399
+ code: CliErrorCode35.MISSING_FLAG,
15123
16400
  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"
15124
16401
  });
15125
16402
  }
@@ -15129,8 +16406,8 @@ async function runChironPage(target, args, deps) {
15129
16406
  const root = path16.resolve(args.project ?? ".");
15130
16407
  const { evidenceRoot, absolute } = resolveEvidenceTarget(root, args.out);
15131
16408
  if (await deps.present(absolute)) {
15132
- throw new CliError33({
15133
- code: CliErrorCode34.INVALID_ARGUMENT,
16409
+ throw new CliError34({
16410
+ code: CliErrorCode35.INVALID_ARGUMENT,
15134
16411
  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`
15135
16412
  });
15136
16413
  }
@@ -15142,8 +16419,8 @@ async function runChironPage(target, args, deps) {
15142
16419
  const playwrightBrowser = endpoint || forceSpawn ? null : deps.findPlaywrightBrowser();
15143
16420
  const usePlaywright = !endpoint && !forceSpawn && (playwrightBrowser !== null || evalJs !== void 0);
15144
16421
  if (evalJs && !endpoint && !usePlaywright) {
15145
- throw new CliError33({
15146
- code: CliErrorCode34.INVALID_ARGUMENT,
16422
+ throw new CliError34({
16423
+ code: CliErrorCode35.INVALID_ARGUMENT,
15147
16424
  message: "--eval \u9700\u8981 Playwright \u6216 --cdp\uFF1A\u8001\u7684 spawn \u8DEF\u5F84\u53EA\u4F1A --dump-dom\uFF0C\u585E\u4E0D\u8FDB\u811A\u672C\u3002",
15148
16425
  context: { nextStep: "npx playwright install chromium-headless-shell\uFF0C\u6216\u5728\u6C99\u7BB1\u5916\u8D77 Chrome \u7528 --cdp \u8FDE" }
15149
16426
  });
@@ -15161,10 +16438,10 @@ async function runChironPage(target, args, deps) {
15161
16438
  try {
15162
16439
  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 });
15163
16440
  } catch (e) {
15164
- if (e instanceof CliError33) throw new CliError33({ code: e.code, message: redactTicket(e.message), context: e.context });
16441
+ if (e instanceof CliError34) throw new CliError34({ code: e.code, message: redactTicket(e.message), context: e.context });
15165
16442
  const where = endpoint ? `\u8FDE\u5230 ${endpoint} \u7684 Chrome` : "Playwright \u8D77\u7684\u6D4F\u89C8\u5668";
15166
- throw new CliError33({
15167
- code: CliErrorCode34.SERVER_ERROR,
16443
+ throw new CliError34({
16444
+ code: CliErrorCode35.SERVER_ERROR,
15168
16445
  message: `${where}\u6CA1\u8DD1\u5B8C\uFF1A${redactTicket(e instanceof Error ? e.message : String(e))}`,
15169
16446
  context: {
15170
16447
  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"
@@ -15180,8 +16457,8 @@ async function runChironPage(target, args, deps) {
15180
16457
  mode = "spawn";
15181
16458
  const browser = deps.findBrowser();
15182
16459
  if (!browser) {
15183
- throw new CliError33({
15184
- code: CliErrorCode34.INVALID_ARGUMENT,
16460
+ throw new CliError34({
16461
+ code: CliErrorCode35.INVALID_ARGUMENT,
15185
16462
  message: "\u672C\u673A\u627E\u4E0D\u5230 Playwright \u7684 Chromium\uFF0C\u4E5F\u627E\u4E0D\u5230 Chrome/Chromium\uFF0C\u622A\u4E0D\u4E86\u56FE\u3002",
15186
16463
  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" }
15187
16464
  });
@@ -15189,8 +16466,8 @@ async function runChironPage(target, args, deps) {
15189
16466
  minted = await mint();
15190
16467
  const result = deps.capture({ browser, argv: chromeArgv({ viewport, waitMs, screenshot: absolute, url: minted.url, isRoot: process.getuid?.() === 0 }) });
15191
16468
  if (!result.ok) {
15192
- throw new CliError33({
15193
- code: CliErrorCode34.SERVER_ERROR,
16469
+ throw new CliError34({
16470
+ code: CliErrorCode35.SERVER_ERROR,
15194
16471
  message: `\u6D4F\u89C8\u5668\u6CA1\u8DD1\u5B8C\uFF1A${redactTicket(result.stderr.trim().split("\n").slice(-1)[0] ?? "\u65E0\u8F93\u51FA")}`,
15195
16472
  context: { nextStep: spawnFailureNextStep(browser, result, deps.platform) }
15196
16473
  });
@@ -15200,7 +16477,7 @@ async function runChironPage(target, args, deps) {
15200
16477
  }
15201
16478
  const bytes = await deps.present(absolute) ? await deps.sizeOf(absolute) : 0;
15202
16479
  if (bytes === 0) {
15203
- throw new CliError33({ code: CliErrorCode34.SERVER_ERROR, message: `\u6D4F\u89C8\u5668\u6CA1\u5199\u51FA\u975E\u7A7A PNG\uFF1A${absolute}` });
16480
+ throw new CliError34({ code: CliErrorCode35.SERVER_ERROR, message: `\u6D4F\u89C8\u5668\u6CA1\u5199\u51FA\u975E\u7A7A PNG\uFF1A${absolute}` });
15204
16481
  }
15205
16482
  const verdict = judgePageContent({ dom, expect, reject });
15206
16483
  return {
@@ -15263,8 +16540,8 @@ var defaultChironPageDeps = {
15263
16540
  const envCfg = await loadEnv6(ctx.env);
15264
16541
  const frontend = ctx.frontend ?? envCfg.frontend;
15265
16542
  if (!frontend?.trim()) {
15266
- throw new CliError33({
15267
- code: CliErrorCode34.INVALID_ARGUMENT,
16543
+ throw new CliError34({
16544
+ code: CliErrorCode35.INVALID_ARGUMENT,
15268
16545
  message: `env '${ctx.env}' \u6CA1\u914D\u524D\u7AEF\u5730\u5740\uFF0C\u5F00\u4E0D\u4E86\u9875\u9762\u3002`,
15269
16546
  context: { nextStep: `hcm env edit frontend <\u524D\u7AEF\u5730\u5740> --env ${ctx.env}` }
15270
16547
  });
@@ -15353,7 +16630,7 @@ init_auth_guard();
15353
16630
  import { HcmClient as HcmClient25, classifyEffect } from "@hcmai/sdk";
15354
16631
 
15355
16632
  // src/commands/delivery.ts
15356
- import { createHash as createHash8 } from "crypto";
16633
+ import { createHash as createHash9 } from "crypto";
15357
16634
  import { LEDGER_ONLY_FLAG } from "@hcmai/sdk";
15358
16635
  var APPROVAL_BYPASS_FLAGS = /* @__PURE__ */ new Set(["-y", "--yes", "--force", "--auto-approve"]);
15359
16636
  var CREDENTIAL_FLAGS = /* @__PURE__ */ new Set([
@@ -15540,7 +16817,19 @@ function classify(argv, actionResolution) {
15540
16817
  return forbidden("removed-command", "`hcm mini` \u5DF2\u79FB\u9664\uFF0C\u6539\u7528 `hcm workspace`\u3002");
15541
16818
  }
15542
16819
  if (name === "chiron") {
15543
- if (subcommand === "doctor") return direct("R1", "remote-read", "chiron-doctor");
16820
+ if (subcommand === "doctor") return hasFlag(argv, "--active") ? {
16821
+ risk: "R2",
16822
+ execution: "guarded",
16823
+ effect: "external-probe-accounted",
16824
+ reasonCode: "chiron-doctor-active",
16825
+ reason: "\u4E3B\u52A8\u63A2\u6D4B\u771F\u8C03\u7B2C\u4E09\u65B9\u5E76\u8BB0\u8D26\uFF0C\u4E0D\u5199\u4E1A\u52A1\u6570\u636E\uFF1B\u6309\u9879\u76EE\u7684\u5199\u6388\u6743\u7EAA\u5F8B\u6267\u884C\u3002"
16826
+ } : hasFlag(argv, "--platform-ops") ? {
16827
+ risk: "R1",
16828
+ execution: "direct",
16829
+ effect: "remote-read",
16830
+ reasonCode: "chiron-doctor-platform-ops",
16831
+ reason: "\u53EA\u8BFB\u8FD0\u7EF4\u5BC6\u94A5\u8BFB\u5E73\u53F0\u5C42\uFF0C\u4E0D\u5199\u4EFB\u4F55\u4E1C\u897F\u3002"
16832
+ } : direct("R1", "remote-read", "chiron-doctor");
15544
16833
  if (subcommand === "init") return direct("R1", "managed-local-write", "chiron-project-scaffold");
15545
16834
  if (subcommand === "test") return direct("R1", "remote-read", "chiron-regression-test");
15546
16835
  if (subcommand === "env") {
@@ -15893,7 +17182,7 @@ function valuesAfterFlag(argv, flag) {
15893
17182
  return values;
15894
17183
  }
15895
17184
  function sha2564(value) {
15896
- return createHash8("sha256").update(value).digest("hex");
17185
+ return createHash9("sha256").update(value).digest("hex");
15897
17186
  }
15898
17187
  function isPlainObject(value) {
15899
17188
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -15926,21 +17215,21 @@ async function resolveCoreAction(request) {
15926
17215
  `Core \u5143\u6570\u636E\u91CC\u6CA1\u6709 ${request.model}.${request.action} \u8FD9\u4E2A Action\u3002${degraded}next_step=\u7528 \`hcm describe ${request.model}\` \u770B\u5B83\u5217\u51FA\u7684 Action \u540D\uFF08\u811A\u672C Action \u4F1A\u6807 [script]\uFF09`
15927
17216
  );
15928
17217
  }
15929
- const matches2 = request.explicitShape ? named.filter((action) => matchesRequest(action, request)) : named;
15930
- if (matches2.length === 0) {
17218
+ const matches3 = request.explicitShape ? named.filter((action) => matchesRequest(action, request)) : named;
17219
+ if (matches3.length === 0) {
15931
17220
  const shapes = named.map((a) => `scope=${a.scope ?? "?"} method=${(a.httpMethod ?? "?").toUpperCase()}`).join("\uFF1B");
15932
17221
  return failed(
15933
17222
  "action-shape-mismatch",
15934
17223
  `${request.model}.${request.action} \u5B58\u5728\uFF0C\u4F46\u5F62\u6001\u5BF9\u4E0D\u4E0A\uFF1A\u4F60\u7ED9\u7684\u662F scope=${request.scope} method=${request.httpMethod}\uFF0C\u5143\u6570\u636E\u91CC\u662F ${shapes}\u3002next_step=\u53BB\u6389 --scope/--method \u8BA9 CLI \u6309\u5143\u6570\u636E\u81EA\u52A8\u5224\u5B9A\uFF0C\u6216\u6539\u6210\u4E0A\u9762\u7684\u5F62\u6001`
15935
17224
  );
15936
17225
  }
15937
- if (matches2.length > 1) {
17226
+ if (matches3.length > 1) {
15938
17227
  return failed(
15939
17228
  "action-metadata-ambiguous",
15940
17229
  `${request.model}.${request.action} \u5728\u5143\u6570\u636E\u91CC\u6709\u591A\u79CD\u5F62\u6001\uFF0C\u65E0\u6CD5\u552F\u4E00\u5224\u5B9A\u3002next_step=\u7528 --scope \u4E0E --method \u6307\u660E\u8981\u8C03\u54EA\u4E00\u4E2A`
15941
17230
  );
15942
17231
  }
15943
- return policyFromActionMeta(matches2[0], request);
17232
+ return policyFromActionMeta(matches3[0], request);
15944
17233
  } catch {
15945
17234
  return failed(
15946
17235
  "action-metadata-unavailable",
@@ -16165,9 +17454,9 @@ function parseJsonLoose(stdout) {
16165
17454
  return void 0;
16166
17455
  }
16167
17456
  function pick(value, expr) {
16168
- const tokens = [...expr.replace(/^\$/, "").matchAll(/\[(\d+)\]|([^.[\]]+)/g)];
17457
+ const tokens2 = [...expr.replace(/^\$/, "").matchAll(/\[(\d+)\]|([^.[\]]+)/g)];
16169
17458
  let cur = value;
16170
- for (const t of tokens) {
17459
+ for (const t of tokens2) {
16171
17460
  if (cur === null || cur === void 0) return void 0;
16172
17461
  if (t[1] !== void 0) {
16173
17462
  if (!Array.isArray(cur)) return void 0;
@@ -16179,7 +17468,7 @@ function pick(value, expr) {
16179
17468
  }
16180
17469
  return cur;
16181
17470
  }
16182
- function matches(actual, rule) {
17471
+ function matches2(actual, rule) {
16183
17472
  const r = rule.trim();
16184
17473
  if (r === "\u975E\u7A7A" || r === "nonempty") return actual !== void 0 && actual !== null && String(actual) !== "" && !(Array.isArray(actual) && actual.length === 0);
16185
17474
  const m = /^(>=|<=|>|<|!=|=)\s*(.*)$/.exec(r);
@@ -16270,7 +17559,7 @@ async function runCase(spec, root, opts = {}, deps = defaultDeps2) {
16270
17559
  for (const [expr, rawRule] of Object.entries(want.json)) {
16271
17560
  const rule = fill(rawRule);
16272
17561
  const actual = pick(parsed, expr);
16273
- if (!matches(actual, rule)) bad.push(`${expr} \u5B9E\u9645 ${JSON.stringify(actual)}\uFF0C\u671F\u671B ${rule}`);
17562
+ if (!matches2(actual, rule)) bad.push(`${expr} \u5B9E\u9645 ${JSON.stringify(actual)}\uFF0C\u671F\u671B ${rule}`);
16274
17563
  }
16275
17564
  }
16276
17565
  }
@@ -16421,18 +17710,18 @@ async function deliveryReconCommand(args) {
16421
17710
  }
16422
17711
  }
16423
17712
  async function deliveryReconRoundCommand(args) {
16424
- let code;
17713
+ let code2;
16425
17714
  try {
16426
17715
  const result = inspectRound(args.dir ?? ".");
16427
17716
  const fmt = args.output ?? "json";
16428
17717
  if (fmt !== "json") process.stdout.write(renderRound(result));
16429
17718
  process.stdout.write(formatObject31(result, { format: fmt }) + "\n");
16430
- code = ROUND_EXIT_CODES[result.state];
17719
+ code2 = ROUND_EXIT_CODES[result.state];
16431
17720
  } catch (e) {
16432
17721
  exitWithError(e);
16433
- code = 1;
17722
+ code2 = 1;
16434
17723
  }
16435
- process.exitCode = code;
17724
+ process.exitCode = code2;
16436
17725
  return;
16437
17726
  }
16438
17727
 
@@ -16908,7 +18197,7 @@ import {
16908
18197
  VERIFY_CRASHED,
16909
18198
  VERIFY_WORDS,
16910
18199
  WorkLayout,
16911
- classifyStatus,
18200
+ classifyStatus as classifyStatus3,
16912
18201
  runActiveVerify,
16913
18202
  runMetaChange,
16914
18203
  seedWorkDir as seedWorkDir2
@@ -16916,9 +18205,9 @@ import {
16916
18205
  var VERIFY_NOT_ASKED = "verify-not-asked";
16917
18206
  var VERIFY_NOT_REACHED = "verify-not-reached";
16918
18207
  var VERIFY_ACTIVE_FLAG = "--verify-active";
16919
- function metaVerifyWords(code) {
16920
- const word = VERIFY_WORDS[code] ?? CODE_WORDS[code];
16921
- if (word === void 0) throw new Error(`\u6CA1\u6709\u7ED9 ${code} \u914D\u8FC7\u8BDD\uFF1A\u8FD9\u4E2A\u53D6\u503C\u54EA\u5F20\u5224\u8BCD\u8868\u91CC\u90FD\u67E5\u4E0D\u5230`);
18208
+ function metaVerifyWords(code2) {
18209
+ const word = VERIFY_WORDS[code2] ?? CODE_WORDS[code2];
18210
+ if (word === void 0) throw new Error(`\u6CA1\u6709\u7ED9 ${code2} \u914D\u8FC7\u8BDD\uFF1A\u8FD9\u4E2A\u53D6\u503C\u54EA\u5F20\u5224\u8BCD\u8868\u91CC\u90FD\u67E5\u4E0D\u5230`);
16922
18211
  return word;
16923
18212
  }
16924
18213
  function metaRc(change, verify, verifyCode) {
@@ -17093,7 +18382,7 @@ function metaClient(client3, ctx) {
17093
18382
  return {
17094
18383
  status: res.status,
17095
18384
  body: res.data,
17096
- error: classifyStatus(res.status),
18385
+ error: classifyStatus3(res.status),
17097
18386
  headers: lowerCaseHeaders2(res.headers)
17098
18387
  };
17099
18388
  } catch (e) {
@@ -17104,7 +18393,7 @@ function metaClient(client3, ctx) {
17104
18393
  body: res?.data ?? null,
17105
18394
  // 🔴 `-1` **不是** HTTP 状态:网络层没走通与「服务端答了个 4xx」在处置上相反 ——
17106
18395
  // 改动轴正是靠这一格把「确认没写」与「不知道写没写」分开。
17107
- error: status === -1 ? "network" : classifyStatus(status),
18396
+ error: status === -1 ? "network" : classifyStatus3(status),
17108
18397
  headers: lowerCaseHeaders2(res?.headers)
17109
18398
  };
17110
18399
  }
@@ -17209,14 +18498,14 @@ async function runTriage(args) {
17209
18498
  return 0;
17210
18499
  }
17211
18500
  async function deliveryTriageCommand(args) {
17212
- let code;
18501
+ let code2;
17213
18502
  try {
17214
- code = await runTriage(args);
18503
+ code2 = await runTriage(args);
17215
18504
  } catch (e) {
17216
18505
  exitWithError(e);
17217
- code = 1;
18506
+ code2 = 1;
17218
18507
  }
17219
- process.exitCode = code;
18508
+ process.exitCode = code2;
17220
18509
  return;
17221
18510
  }
17222
18511
 
@@ -17228,21 +18517,21 @@ import {
17228
18517
  adminResetPassword,
17229
18518
  formatObject as formatObject32,
17230
18519
  fromAxiosError as fromAxiosError23,
17231
- CliError as CliError34,
17232
- CliErrorCode as CliErrorCode35
18520
+ CliError as CliError35,
18521
+ CliErrorCode as CliErrorCode36
17233
18522
  } from "@hcmai/sdk";
17234
18523
  function buildAdminResetPasswordRequest(args, password) {
17235
18524
  const hasId = Boolean(args.id);
17236
18525
  const hasUsername = Boolean(args.username);
17237
18526
  if (hasId === hasUsername) {
17238
- throw new CliError34({
17239
- code: CliErrorCode35.INVALID_ARGUMENT,
18527
+ throw new CliError35({
18528
+ code: CliErrorCode36.INVALID_ARGUMENT,
17240
18529
  message: "--id <uuid> \u4E0E --username <user> \u5FC5\u987B\u4E14\u53EA\u80FD\u63D0\u4F9B\u4E00\u4E2A"
17241
18530
  });
17242
18531
  }
17243
18532
  if (!password) {
17244
- throw new CliError34({
17245
- code: CliErrorCode35.INVALID_ARGUMENT,
18533
+ throw new CliError35({
18534
+ code: CliErrorCode36.INVALID_ARGUMENT,
17246
18535
  message: "\u65B0\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A"
17247
18536
  });
17248
18537
  }
@@ -17271,8 +18560,8 @@ async function promptPasswordTwice() {
17271
18560
  const password = await promptSecret("\u65B0\u5BC6\u7801: ");
17272
18561
  const confirmation = await promptSecret("\u518D\u6B21\u8F93\u5165\u65B0\u5BC6\u7801: ");
17273
18562
  if (password !== confirmation) {
17274
- throw new CliError34({
17275
- code: CliErrorCode35.INVALID_ARGUMENT,
18563
+ throw new CliError35({
18564
+ code: CliErrorCode36.INVALID_ARGUMENT,
17276
18565
  message: "\u4E24\u6B21\u8F93\u5165\u7684\u65B0\u5BC6\u7801\u4E0D\u4E00\u81F4"
17277
18566
  });
17278
18567
  }
@@ -17406,7 +18695,7 @@ chiron.command("test").description("\u6309\u7528\u4F8B\u8DD1\u4E00\u904D\u5E76\u
17406
18695
  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));
17407
18696
  chiron.command("doctor").description(
17408
18697
  "\u4F53\u68C0\u672C\u673A 9 \u9879\u4E0E\u6BCF\u73AF\u5883\u8FDE\u63A5 7 \u9879\uFF1B\u7ED3\u8BBA READY / READY_WITH_RISKS / BLOCKED"
17409
- ).option("--project <dir>", "\u9879\u76EE\u6839\u76EE\u5F55", ".").option("--env <name>", "\u9009\u5B9A\u76EE\u6807\u73AF\u5883\uFF08\u9ED8\u8BA4 env.yaml default\uFF09\uFF1B\u5176\u4F59\u73AF\u5883\u4ECD\u68C0\u67E5\uFF0C\u5931\u8D25\u8BB0\u98CE\u9669").option("--as <identity>", "\u4EE5\u6307\u5B9A\u8EAB\u4EFD\u4F53\u68C0\uFF08\u6CBF\u7528\u4E1A\u52A1\u547D\u4EE4\u7684\u4EE3\u7406\u56DE\u843D\uFF09").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").option("--fail-on <level>", "\u975E\u96F6\u9000\u51FA\u9608\u503C\uFF1Ablocked | risks", "blocked").action((opts) => chironDoctorCommand(opts));
18698
+ ).option("--project <dir>", "\u9879\u76EE\u6839\u76EE\u5F55\uFF08\u9ED8\u8BA4\u5F53\u524D\u76EE\u5F55\uFF09").option("--env <name>", "\u9009\u5B9A\u76EE\u6807\u73AF\u5883\uFF08\u9ED8\u8BA4 env.yaml default\uFF09\uFF1B\u5176\u4F59\u73AF\u5883\u4ECD\u68C0\u67E5\uFF0C\u5931\u8D25\u8BB0\u98CE\u9669").option("--as <identity>", "\u4EE5\u6307\u5B9A\u8EAB\u4EFD\u4F53\u68C0\uFF08\u6CBF\u7528\u4E1A\u52A1\u547D\u4EE4\u7684\u4EE3\u7406\u56DE\u843D\uFF09").option("--stage <stage>", "\u9636\u6BB5\uFF1Ahandover | baseline | configure | migrate | integrate | golive | operate").option("--only <prefix>", "\u53EA\u68C0\u67E5\u8FD9\u4E9B id \u6216\u524D\u7F00\uFF0C\u9017\u53F7\u5206\u9694\uFF1B\u53EF\u91CD\u590D", (value, previous) => [...previous, value], []).option("--skip <prefix>", "\u6392\u9664\u8FD9\u4E9B id \u6216\u524D\u7F00\uFF0C\u9017\u53F7\u5206\u9694\uFF1B\u53EF\u91CD\u590D", (value, previous) => [...previous, value], []).option("--active", "\u5141\u8BB8\u4E3B\u52A8\u63A2\u6D4B\u7B2C\u4E09\u65B9\u5E76\u8BB0\u8D26").option("--platform-ops", "\u53EA\u7528\u8FD0\u7EF4\u53EA\u8BFB\u5BC6\u94A5\u68C0\u67E5\u5E94\u7B54\u5B9E\u4F8B\u7684\u5E73\u53F0\u5C42").option("--platform-ops-key-stdin", "\u4ECE stdin \u8BFB\u53D6\u8FD0\u7EF4\u53EA\u8BFB\u5BC6\u94A5").option("--list", "\u5217\u51FA\u672C\u673A\u4E0E\u670D\u52A1\u7AEF\u7684\u68C0\u67E5\u76EE\u5F55").option("--explain <id>", "\u8BF4\u660E\u6307\u5B9A\u68C0\u67E5\u7684\u5224\u636E\u3001\u4F9D\u8D56\u548C\u7801\u8868").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").option("--fail-on <level>", "\u975E\u96F6\u9000\u51FA\u9608\u503C\uFF1Ablocked | risks\uFF08\u9ED8\u8BA4 blocked\uFF09").action((opts) => chironDoctorCommand(opts));
17410
18699
  var chironSkills = chiron.command("skills").description("\u8FD9\u4E2A\u9879\u76EE\u4ED3\u7684\u6280\u80FD\uFF1A\u8DDF\u76EE\u6807\u73AF\u5883\u5BF9\u9F50");
17411
18700
  chironSkills.command("sync").description("\u8BA9\u8FD9\u4E2A\u4ED3\u7684\u6280\u80FD\u8DDF\u76EE\u6807\u73AF\u5883\u5BF9\u9F50\uFF1A\u7B2C\u4E00\u6B21\u5C31\u88C5\u9F50\uFF0C\u4E4B\u540E\u6309\u4EA7\u54C1\u5F53\u524D\u5168\u96C6\u5BF9\u8D26\u3002\u5E42\u7B49\uFF0C\u4EA7\u54C1\u5347\u7EA7\u540E\u8DD1\u5B83").option("--only <id...>", "\u53EA\u8981\u8FD9\u51E0\u4E2A\u6280\u80FD\uFF08\u8FDE\u540C requires \u524D\u7F6E\uFF09\uFF0C\u4E0D\u8BA2\u9605\u5168\u96C6\uFF1B\u8BAD\u7EC3\u573A blind \u6863\u7528").option("--check", "\u53EA\u770B\u4F1A\u53D8\u4EC0\u4E48\uFF0C\u4E0D\u5199\u76D8").option("--target <agent>", "claude\uFF08.claude/skills/\uFF09| codex\uFF08hcm-skills/ + Agent \u7D22\u5F15\uFF09| auto", "auto").option("--global", "\u540C\u6B65\u7528\u6237\u7EA7\u76EE\u5F55\u800C\u975E\u5F53\u524D\u9879\u76EE").option("--dir <path>", "\u540C\u6B65\u6307\u5B9A\u76EE\u5F55").option("--from <dir>", "\u4ECE\u672C\u5730\u76EE\u5F55\u53D6\uFF08\u73B0\u573A\u6539\u8FC7\u7684\u7248\u672C\uFF09\uFF0C\u4E0D\u8D70\u7F51\u7EDC").option("--force", "\u8FDE\u672C\u5730\u6539\u8FC7\u7684\u6280\u80FD\u4E00\u8D77\u8986\u76D6\u6210\u4EA7\u54C1\u8FD9\u4E00\u7248").option("--prune-max <n>", `\u4E00\u8D9F\u6700\u591A\u6E05\u51E0\u4EFD\u4E0A\u6E38\u4E0D\u518D\u53D1\u7684\u6280\u80FD\uFF0C\u8D85\u4E86\u6574\u6279\u62D2\u7EDD\uFF1B0 = \u4E00\u4EFD\u90FD\u522B\u6E05\uFF08\u7F3A\u7701 ${PRUNE_DEFAULT_MAX}\uFF09`).option("--source <kind>", "\u8FD9\u4E00\u8D9F\u770B\u54EA\u4E9B\u6765\u6E90\uFF1Acli\uFF08\u53EA\u770B\u81EA\u5E26\uFF0C\u4E0D\u8FDE\u7F51\uFF09| chiron | all", "all").option("--endpoint <url>", "\u6280\u80FD\u5E93\u5730\u5740\uFF08\u9ED8\u8BA4\u53D6\u9879\u76EE\u73AF\u5883\u6216\u5B89\u88C5\u65F6\u8BB0\u5F55\u7684\u5730\u5740\uFF09").option("--env <name>", "\u4ECE\u8BE5 env \u89E3\u6790 endpoint").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((opts) => skillsSyncCommand(opts));
17412
18701
  chironSkills.command("path <id>").description("\u6253\u5370\u8FD9\u4E2A id \u5728\u672C\u9879\u76EE\u5B9E\u9645\u751F\u6548\u90A3\u4E00\u4EFD\u7684\u8DEF\u5F84\uFF08local/ \u906E\u853D sync/\uFF09\uFF0C\u4F9B\u6280\u80FD\u6B63\u6587\u5F15\u7528\uFF0C\u514D\u5F97\u6B63\u6587\u5199\u6B7B\u76EE\u5F55\u5C42\u6570").option("--refs", "\u8981 references/ \u7684\u843D\u70B9\uFF0C\u4E0D\u662F SKILL.md").option("--target <agent>", "claude | codex | auto", "auto").option("--global", "\u770B\u7528\u6237\u7EA7\u76EE\u5F55").option("--dir <path>", "\u770B\u6307\u5B9A\u76EE\u5F55").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((id, opts) => skillsPathCommand(id, opts));