@hcmai/cli 0.7.1 → 0.9.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
@@ -532,8 +532,8 @@ var init_TerminalRenderer = __esm({
532
532
  }
533
533
  }
534
534
  /** 来源行(仅子代理触发,agentPath ≥2 段时显示 `↑ 来自 a › b`,对齐 Web)。 */
535
- originLine(path14) {
536
- const segs = path14.split(".").filter(Boolean);
535
+ originLine(path15) {
536
+ const segs = path15.split(".").filter(Boolean);
537
537
  if (segs.length < 2) return "";
538
538
  const names = segs.map((k) => agentDisplayName(k));
539
539
  return chalk.gray(` \u2191 \u6765\u81EA ${names.join(" \u203A ")}`) + "\n";
@@ -1715,8 +1715,8 @@ function agentLabel(agentId) {
1715
1715
  if (/^[0-9a-f]{8}-[0-9a-f-]{27}$/i.test(agentId)) return `agent \u2026${agentId.slice(-4)}`;
1716
1716
  return agentDisplayName(agentId);
1717
1717
  }
1718
- function originLine(path14) {
1719
- const segs = (path14 ?? "").split(".").filter(Boolean);
1718
+ function originLine(path15) {
1719
+ const segs = (path15 ?? "").split(".").filter(Boolean);
1720
1720
  if (segs.length < 2) return null;
1721
1721
  return `\u6765\u81EA ${segs.map((k) => agentDisplayName(k)).join(" \u203A ")}`;
1722
1722
  }
@@ -3474,7 +3474,7 @@ function launchBrowser(url, platform = process.platform) {
3474
3474
  child.unref();
3475
3475
  }
3476
3476
  async function runOpen(target, args, deps) {
3477
- const path14 = normalizeTarget(target);
3477
+ const path15 = normalizeTarget(target);
3478
3478
  if (!deps.frontend?.trim()) {
3479
3479
  throw new CliError13({
3480
3480
  code: CliErrorCode12.INVALID_ARGUMENT,
@@ -3482,13 +3482,13 @@ async function runOpen(target, args, deps) {
3482
3482
  });
3483
3483
  }
3484
3484
  const { ticket, expiresIn } = await deps.mintTicket();
3485
- const url = buildBrowserLoginUrl(deps.frontend, ticket, path14);
3485
+ const url = buildBrowserLoginUrl(deps.frontend, ticket, path15);
3486
3486
  if (args.printUrl) {
3487
3487
  deps.write(`${url}
3488
3488
  `);
3489
3489
  } else {
3490
3490
  deps.launch(url);
3491
- deps.write(`\u5DF2\u7528\u5F53\u524D\u8EAB\u4EFD\u6253\u5F00 ${path14}\uFF08\u7968\u636E ${expiresIn ?? 60}s \u5185\u6709\u6548\uFF0C\u53EA\u80FD\u7528\u4E00\u6B21\uFF09
3491
+ deps.write(`\u5DF2\u7528\u5F53\u524D\u8EAB\u4EFD\u6253\u5F00 ${path15}\uFF08\u7968\u636E ${expiresIn ?? 60}s \u5185\u6709\u6548\uFF0C\u53EA\u80FD\u7528\u4E00\u6B21\uFF09
3492
3492
  `);
3493
3493
  }
3494
3494
  return { url, expiresIn };
@@ -3582,8 +3582,8 @@ import {
3582
3582
  formatObject as formatObject7,
3583
3583
  fromAxiosError as fromAxiosError9
3584
3584
  } from "@hcmai/sdk";
3585
- function collectYmlFiles(path14) {
3586
- if (statSync(path14).isFile()) return [path14];
3585
+ function collectYmlFiles(path15) {
3586
+ if (statSync(path15).isFile()) return [path15];
3587
3587
  const out = [];
3588
3588
  const walk = (dir) => {
3589
3589
  for (const name of readdirSync(dir).sort()) {
@@ -3592,7 +3592,7 @@ function collectYmlFiles(path14) {
3592
3592
  else if (full.endsWith(".yml") || full.endsWith(".yaml")) out.push(full);
3593
3593
  }
3594
3594
  };
3595
- walk(path14);
3595
+ walk(path15);
3596
3596
  return out.sort();
3597
3597
  }
3598
3598
  var DRY_RUN_CLIENT = {
@@ -3600,9 +3600,9 @@ var DRY_RUN_CLIENT = {
3600
3600
  create: async () => ({ id: "" }),
3601
3601
  update: async () => ({})
3602
3602
  };
3603
- async function importCommand(path14, args) {
3603
+ async function importCommand(path15, args) {
3604
3604
  try {
3605
- const files = collectYmlFiles(path14);
3605
+ const files = collectYmlFiles(path15);
3606
3606
  const fixtures = files.map(
3607
3607
  (f) => parseFixture(readFileSync2(f, "utf8"), relative(process.cwd(), f))
3608
3608
  );
@@ -3726,29 +3726,29 @@ import {
3726
3726
  import chalk2 from "chalk";
3727
3727
  import * as fs5 from "fs/promises";
3728
3728
  function parseInjectOn(s) {
3729
- const fail7 = (detail) => {
3729
+ const fail8 = (detail) => {
3730
3730
  throw new CliError15({
3731
3731
  code: CliErrorCode14.INVALID_ARGUMENT,
3732
3732
  message: `--inject-on \u683C\u5F0F <eventType>:<action>[:<arg>]\uFF0Caction \u2208 {interrupt, steer}\uFF08steer \u5FC5\u987B\u5E26 content\uFF09\uFF1B${detail}\uFF0C\u6536\u5230 "${s}"`
3733
3733
  });
3734
3734
  };
3735
3735
  const firstColon = s.indexOf(":");
3736
- if (firstColon < 0) return fail7("\u7F3A\u5C11 action \u6BB5");
3736
+ if (firstColon < 0) return fail8("\u7F3A\u5C11 action \u6BB5");
3737
3737
  const eventType = s.slice(0, firstColon);
3738
3738
  const rest = s.slice(firstColon + 1);
3739
3739
  const secondColon = rest.indexOf(":");
3740
3740
  const action = secondColon < 0 ? rest : rest.slice(0, secondColon);
3741
3741
  const arg = secondColon < 0 ? void 0 : rest.slice(secondColon + 1);
3742
- if (!eventType) return fail7("eventType \u6BB5\u4E3A\u7A7A");
3742
+ if (!eventType) return fail8("eventType \u6BB5\u4E3A\u7A7A");
3743
3743
  if (action === "interrupt") {
3744
- if (arg !== void 0) return fail7("interrupt \u4E0D\u63A5\u53D7 arg");
3744
+ if (arg !== void 0) return fail8("interrupt \u4E0D\u63A5\u53D7 arg");
3745
3745
  return { eventType, action: "interrupt" };
3746
3746
  }
3747
3747
  if (action === "steer") {
3748
- if (arg === void 0 || arg === "") return fail7("steer \u5FC5\u987B\u5E26 content\uFF08arg\uFF09");
3748
+ if (arg === void 0 || arg === "") return fail8("steer \u5FC5\u987B\u5E26 content\uFF08arg\uFF09");
3749
3749
  return { eventType, action: "steer", arg };
3750
3750
  }
3751
- return fail7(`\u672A\u77E5 action "${action}"`);
3751
+ return fail8(`\u672A\u77E5 action "${action}"`);
3752
3752
  }
3753
3753
  function parseOnConfirm(s) {
3754
3754
  if (s === "approve") return { decision: "approve" };
@@ -5010,7 +5010,7 @@ async function datapackageInstallCommand(artifactPath, args) {
5010
5010
  }
5011
5011
  const timeoutMs = Math.max(1, Number(args.timeout ?? DEFAULT_INSTALL_WAIT_SECONDS)) * 1e3;
5012
5012
  const showProgress = human && process.stderr.isTTY === true;
5013
- const { run: run2, timedOut } = await waitForInstallRun(client3, accepted.runId, {
5013
+ const { run: run3, timedOut } = await waitForInstallRun(client3, accepted.runId, {
5014
5014
  timeoutMs,
5015
5015
  onProgress: showProgress ? (r) => process.stderr.write(`\r${renderProgress(r)}`.padEnd(96)) : void 0
5016
5016
  });
@@ -5024,27 +5024,27 @@ async function datapackageInstallCommand(artifactPath, args) {
5024
5024
  }
5025
5025
  emit3({
5026
5026
  runId: accepted.runId,
5027
- status: run2?.status ?? "RUNNING",
5028
- phase: run2?.phase,
5029
- filesDone: run2?.filesDone,
5030
- filesTotal: run2?.filesTotal,
5031
- rowsDone: run2?.rowsDone,
5027
+ status: run3?.status ?? "RUNNING",
5028
+ phase: run3?.phase,
5029
+ filesDone: run3?.filesDone,
5030
+ filesTotal: run3?.filesTotal,
5031
+ rowsDone: run3?.rowsDone,
5032
5032
  timedOut: true,
5033
5033
  next_step: `hcm datapackage status ${accepted.runId}`
5034
5034
  }, fmt);
5035
5035
  process.exitCode = 0;
5036
5036
  return;
5037
5037
  }
5038
- const failed2 = run2?.status !== "SUCCESS";
5038
+ const failed2 = run3?.status !== "SUCCESS";
5039
5039
  if (human) {
5040
5040
  process.stdout.write(
5041
- `${failed2 ? "\u274C" : "\u2705"} ${run2?.packageCode ?? accepted.packageName ?? "?"} v${run2?.version ?? accepted.version ?? "?"} \u2192 ${run2?.status ?? "?"}\uFF08rowCount=${run2?.rowCount ?? 0}\uFF0C${Math.round((run2?.durationMs ?? 0) / 1e3)}s\uFF09
5041
+ `${failed2 ? "\u274C" : "\u2705"} ${run3?.packageCode ?? accepted.packageName ?? "?"} v${run3?.version ?? accepted.version ?? "?"} \u2192 ${run3?.status ?? "?"}\uFF08rowCount=${run3?.rowCount ?? 0}\uFF0C${Math.round((run3?.durationMs ?? 0) / 1e3)}s\uFF09
5042
5042
  `
5043
5043
  );
5044
- if (run2?.errorMessage) process.stdout.write(` \u539F\u56E0\uFF1A${run2.errorMessage}
5044
+ if (run3?.errorMessage) process.stdout.write(` \u539F\u56E0\uFF1A${run3.errorMessage}
5045
5045
  `);
5046
5046
  }
5047
- emit3({ ...run2 ?? {}, runId: accepted.runId, documentId: accepted.documentId }, fmt);
5047
+ emit3({ ...run3 ?? {}, runId: accepted.runId, documentId: accepted.documentId }, fmt);
5048
5048
  process.exitCode = failed2 ? 1 : 0;
5049
5049
  return;
5050
5050
  } catch (e) {
@@ -5062,9 +5062,9 @@ async function datapackageStatusCommand(runId, args) {
5062
5062
  try {
5063
5063
  const ctx = await getActiveAuthContextFromCli(args);
5064
5064
  const client3 = HcmClient17.fromAuthContext(ctx);
5065
- const run2 = await fetchInstallRun(client3, runId);
5065
+ const run3 = await fetchInstallRun(client3, runId);
5066
5066
  const fmt = args.output ?? "json";
5067
- if (!run2) {
5067
+ if (!run3) {
5068
5068
  if (fmt !== "json") {
5069
5069
  process.stdout.write(`\u23F3 \u6D41\u6C34 ${runId} \u8FD8\u6CA1\u51FA\u73B0\u2014\u2014\u521A\u53D7\u7406\u7684\u88C5\u8F7D\u4F1A\u6709\u51E0\u767E\u6BEB\u79D2\u7684\u7A7A\u7A97\u3002
5070
5070
  `);
@@ -5074,12 +5074,12 @@ async function datapackageStatusCommand(runId, args) {
5074
5074
  return;
5075
5075
  }
5076
5076
  if (fmt !== "json") {
5077
- process.stdout.write(`${renderProgress(run2)}
5077
+ process.stdout.write(`${renderProgress(run3)}
5078
5078
  `);
5079
- if (run2.errorMessage) process.stdout.write(` \u539F\u56E0\uFF1A${run2.errorMessage}
5079
+ if (run3.errorMessage) process.stdout.write(` \u539F\u56E0\uFF1A${run3.errorMessage}
5080
5080
  `);
5081
5081
  }
5082
- emit3({ ...run2, ...isTerminalRunStatus(run2.status) ? {} : { next_step: `hcm datapackage status ${runId}` } }, fmt);
5082
+ emit3({ ...run3, ...isTerminalRunStatus(run3.status) ? {} : { next_step: `hcm datapackage status ${runId}` } }, fmt);
5083
5083
  process.exitCode = 0;
5084
5084
  return;
5085
5085
  } catch (e) {
@@ -5088,13 +5088,13 @@ async function datapackageStatusCommand(runId, args) {
5088
5088
  else exitWithError(e);
5089
5089
  }
5090
5090
  }
5091
- function renderProgress(run2) {
5092
- if (!run2) return "\u23F3 \u7B49\u5F85\u88C5\u8F7D\u6D41\u6C34\u51FA\u73B0\u2026";
5093
- const phase = run2.phase ?? run2.status ?? "?";
5094
- const files = run2.filesTotal ? `${run2.filesDone ?? 0}/${run2.filesTotal} \u6587\u4EF6` : `${run2.filesDone ?? 0} \u6587\u4EF6`;
5095
- const rows = run2.rowsTotal ? `${run2.rowsDone ?? 0}/${run2.rowsTotal} \u884C` : `${run2.rowsDone ?? 0} \u884C`;
5096
- const pct = run2.rowsTotal ? ` ${Math.min(100, Math.round((run2.rowsDone ?? 0) / run2.rowsTotal * 100))}%` : "";
5097
- const file = run2.currentFile ? ` ${truncateTail(run2.currentFile, 42)}` : "";
5091
+ function renderProgress(run3) {
5092
+ if (!run3) return "\u23F3 \u7B49\u5F85\u88C5\u8F7D\u6D41\u6C34\u51FA\u73B0\u2026";
5093
+ const phase = run3.phase ?? run3.status ?? "?";
5094
+ const files = run3.filesTotal ? `${run3.filesDone ?? 0}/${run3.filesTotal} \u6587\u4EF6` : `${run3.filesDone ?? 0} \u6587\u4EF6`;
5095
+ const rows = run3.rowsTotal ? `${run3.rowsDone ?? 0}/${run3.rowsTotal} \u884C` : `${run3.rowsDone ?? 0} \u884C`;
5096
+ const pct = run3.rowsTotal ? ` ${Math.min(100, Math.round((run3.rowsDone ?? 0) / run3.rowsTotal * 100))}%` : "";
5097
+ const file = run3.currentFile ? ` ${truncateTail(run3.currentFile, 42)}` : "";
5098
5098
  return `\u23F3 ${phase}${pct} ${files} ${rows}${file}`;
5099
5099
  }
5100
5100
  function truncateTail(text, max) {
@@ -6718,10 +6718,10 @@ async function metaListCommand(args) {
6718
6718
  fail6(e, args);
6719
6719
  }
6720
6720
  }
6721
- async function metaGetCommand(path14, args) {
6721
+ async function metaGetCommand(path15, args) {
6722
6722
  try {
6723
6723
  const c = await client2(args);
6724
- const content = await getTenantMeta(c.raw(), path14);
6724
+ const content = await getTenantMeta(c.raw(), path15);
6725
6725
  process.stdout.write(content.endsWith("\n") ? content : content + "\n");
6726
6726
  process.exitCode = 0;
6727
6727
  return;
@@ -6730,8 +6730,8 @@ async function metaGetCommand(path14, args) {
6730
6730
  }
6731
6731
  }
6732
6732
  var PROBEABLE_META_TYPES = /* @__PURE__ */ new Set(["model", "list", "info", "view", "filter", "page", "wiz", "impexp"]);
6733
- function parseMetaPath(path14) {
6734
- const base = path14.split(/[\\/]/).pop() ?? path14;
6733
+ function parseMetaPath(path15) {
6734
+ const base = path15.split(/[\\/]/).pop() ?? path15;
6735
6735
  if (!/\.(yml|yaml)$/i.test(base)) return {};
6736
6736
  const parts = base.replace(/\.(yml|yaml)$/i, "").split(".");
6737
6737
  return { model: parts[0] || void 0, kind: parts[1] ?? "model", state: parts[2] };
@@ -6748,10 +6748,10 @@ function unverifiableReason(e) {
6748
6748
  if (st == null) return `\u8BF7\u6C42\u6CA1\u53D1\u51FA\u53BB\u6216\u6CA1\u56DE\u6765\uFF08${err.code ?? err.message ?? "\u672A\u77E5"}\uFF09`;
6749
6749
  return void 0;
6750
6750
  }
6751
- async function verifyAfterWrite(c, path14) {
6752
- const { model, kind, state } = parseMetaPath(path14);
6751
+ async function verifyAfterWrite(c, path15) {
6752
+ const { model, kind, state } = parseMetaPath(path15);
6753
6753
  if (!model || !kind) {
6754
- return { status: "unverified", where: "(\u672A\u63A2)", why: `\u4ECE\u8DEF\u5F84 ${path14} \u8BA4\u4E0D\u51FA\u6A21\u578B\u540D/\u5C42\u540D` };
6754
+ return { status: "unverified", where: "(\u672A\u63A2)", why: `\u4ECE\u8DEF\u5F84 ${path15} \u8BA4\u4E0D\u51FA\u6A21\u578B\u540D/\u5C42\u540D` };
6755
6755
  }
6756
6756
  try {
6757
6757
  await clearMetaCache2(c.raw(), model, {});
@@ -6782,21 +6782,21 @@ async function verifyAfterWrite(c, path14) {
6782
6782
  run: () => c.raw().get(`/api/models/${model}`, { params: { state: state ?? "default", size: 1 } })
6783
6783
  });
6784
6784
  }
6785
- for (const probe2 of probes) {
6785
+ for (const probe of probes) {
6786
6786
  try {
6787
- await probe2.run();
6787
+ await probe.run();
6788
6788
  } catch (e) {
6789
6789
  const why = unverifiableReason(e);
6790
- if (why) return { status: "unverified", where: probe2.where, why };
6790
+ if (why) return { status: "unverified", where: probe.where, why };
6791
6791
  const err = e;
6792
6792
  const body = err.response?.data;
6793
6793
  const raw = typeof body === "string" ? body : JSON.stringify(body ?? err.message ?? String(e));
6794
- return { status: "broken", where: probe2.where, raw };
6794
+ return { status: "broken", where: probe.where, raw };
6795
6795
  }
6796
6796
  }
6797
6797
  return { status: "ok" };
6798
6798
  }
6799
- async function metaSetCommand(path14, args) {
6799
+ async function metaSetCommand(path15, args) {
6800
6800
  try {
6801
6801
  if (!args.file) {
6802
6802
  throw new CliError20({
@@ -6812,9 +6812,9 @@ async function metaSetCommand(path14, args) {
6812
6812
  process.stdin.on("error", reject);
6813
6813
  }) : await fsp3.readFile(args.file, "utf8");
6814
6814
  if (!args.skipValidate) {
6815
- const result2 = validateMetaContent(path14, content);
6815
+ const result2 = validateMetaContent(path15, content);
6816
6816
  if (result2.issues.length > 0) {
6817
- process.stderr.write(`\u{1F50E} \u5199\u524D\u6821\u9A8C ${path14}\uFF08schema \u7C7B\u578B\uFF1A${result2.kind ?? "\u672A\u8BC6\u522B"}\uFF09
6817
+ process.stderr.write(`\u{1F50E} \u5199\u524D\u6821\u9A8C ${path15}\uFF08schema \u7C7B\u578B\uFF1A${result2.kind ?? "\u672A\u8BC6\u522B"}\uFF09
6818
6818
  `);
6819
6819
  process.stderr.write(formatMetaIssues(result2, " ") + "\n");
6820
6820
  }
@@ -6833,13 +6833,13 @@ async function metaSetCommand(path14, args) {
6833
6833
  if (dryFmt === "json" || dryFmt === "yaml") {
6834
6834
  process.stdout.write(
6835
6835
  formatObject18(
6836
- { dryRun: true, path: path14, bytes: Buffer.byteLength(content), content },
6836
+ { dryRun: true, path: path15, bytes: Buffer.byteLength(content), content },
6837
6837
  { format: dryFmt }
6838
6838
  ) + "\n"
6839
6839
  );
6840
6840
  } else {
6841
6841
  process.stdout.write(
6842
- `[dry-run] \u5C06\u5199\u5165 ${path14}\uFF08${Buffer.byteLength(content)} B\uFF09\u2014\u2014\u672A\u5B9E\u9645\u5199\u5165
6842
+ `[dry-run] \u5C06\u5199\u5165 ${path15}\uFF08${Buffer.byteLength(content)} B\uFF09\u2014\u2014\u672A\u5B9E\u9645\u5199\u5165
6843
6843
  ---
6844
6844
  ${content}
6845
6845
  `
@@ -6853,13 +6853,13 @@ ${content}
6853
6853
  let backupState = "unknown";
6854
6854
  let backupWhy;
6855
6855
  try {
6856
- const prev = await getTenantMeta(c.raw(), path14);
6856
+ const prev = await getTenantMeta(c.raw(), path15);
6857
6857
  if (!prev || prev.trim() === "") {
6858
6858
  backupState = "absent";
6859
6859
  } else {
6860
6860
  backupFile = nodePath.join(
6861
6861
  os3.tmpdir(),
6862
- `hcm-meta-backup-${Date.now()}-${path14.replace(/[\\/]/g, "_")}`
6862
+ `hcm-meta-backup-${Date.now()}-${path15.replace(/[\\/]/g, "_")}`
6863
6863
  );
6864
6864
  await fsp3.writeFile(backupFile, prev, "utf8");
6865
6865
  backupState = "saved";
@@ -6874,22 +6874,22 @@ ${content}
6874
6874
  backupWhy = `HTTP ${st ?? "-"}${err.code ? ` ${err.code}` : ""}${err.message ? `\uFF1A${err.message}` : ""}`;
6875
6875
  }
6876
6876
  }
6877
- const result = await saveTenantMeta(c.raw(), path14, content);
6877
+ const result = await saveTenantMeta(c.raw(), path15, content);
6878
6878
  const fmt = args.output ?? "json";
6879
- if (fmt !== "json") process.stdout.write(`\u2705 \u5DF2\u5199\u5165 ${path14}
6879
+ if (fmt !== "json") process.stdout.write(`\u2705 \u5DF2\u5199\u5165 ${path15}
6880
6880
  `);
6881
6881
  const restoreHint = backupState === "saved" && backupFile ? ` \u65E7\u5185\u5BB9\u5DF2\u5B58\uFF1A${backupFile}
6882
- \u653E\u56DE\u53BB\uFF1Ahcm meta set ${path14} --file ${backupFile}${connFlags(args)}
6883
- ` : backupState === "absent" ? ` \u8FD9\u4E00\u5C42\u6B64\u524D\u6CA1\u6709\u8986\u76D6\uFF08\u5DF2\u8BC1\u5B9E\uFF09\uFF0C\u6062\u590D\u5373\u5220\u9664\uFF1Ahcm meta delete ${path14}${connFlags(args)}
6882
+ \u653E\u56DE\u53BB\uFF1Ahcm meta set ${path15} --file ${backupFile}${connFlags(args)}
6883
+ ` : backupState === "absent" ? ` \u8FD9\u4E00\u5C42\u6B64\u524D\u6CA1\u6709\u8986\u76D6\uFF08\u5DF2\u8BC1\u5B9E\uFF09\uFF0C\u6062\u590D\u5373\u5220\u9664\uFF1Ahcm meta delete ${path15}${connFlags(args)}
6884
6884
  ` : ` \u26A0\uFE0F \u65E7\u5185\u5BB9**\u6CA1\u5907\u4EFD\u6210**\uFF08${backupWhy ?? "\u539F\u56E0\u672A\u77E5"}\uFF09\u2014\u2014\u65E2\u4E0D\u77E5\u9053\u6B64\u524D\u6709\u6CA1\u6709\u8986\u76D6\uFF0C\u4E5F\u5C31\u7ED9\u4E0D\u51FA\u6062\u590D\u547D\u4EE4\u3002
6885
- \u5148\u81EA\u5DF1\u8BFB\u4E00\u904D\u786E\u8BA4\uFF1Ahcm meta get ${path14}${connFlags(args)}
6885
+ \u5148\u81EA\u5DF1\u8BFB\u4E00\u904D\u786E\u8BA4\uFF1Ahcm meta get ${path15}${connFlags(args)}
6886
6886
  `;
6887
6887
  if (args.verify === false) {
6888
6888
  process.stderr.write(
6889
6889
  "\u26A0\uFE0F --no-verify\uFF1A**\u6CA1\u6709**\u9A8C\u8FC7\u670D\u52A1\u7AEF\u8BFB\u4E0D\u8BFB\u5F97\u52A8\u8FD9\u4EFD meta\u3002\u300C\u5199\u5165\u6210\u529F\u300D\u53EA\u8BF4\u660E\u5B57\u8282\u6536\u4E0B\u4E86\u3002\n \u81EA\u5DF1\u8865\uFF1Ahcm cache clear-meta <Model> \u540E\u6253\u5F00\u9875\u9762\u770B\u4E00\u773C\u3002\n" + restoreHint
6890
6890
  );
6891
6891
  } else {
6892
- const outcome = await verifyAfterWrite(c, path14);
6892
+ const outcome = await verifyAfterWrite(c, path15);
6893
6893
  if (outcome.status === "broken") {
6894
6894
  const human = explainJacksonError(outcome.raw);
6895
6895
  process.stderr.write(
@@ -6922,19 +6922,19 @@ ${content}
6922
6922
  fail6(e, args);
6923
6923
  }
6924
6924
  }
6925
- async function metaDeleteCommand(path14, args) {
6925
+ async function metaDeleteCommand(path15, args) {
6926
6926
  try {
6927
6927
  if (!args.yes) {
6928
- const ok = await promptConfirm(`\u5C06\u5220\u9664\u5143\u6570\u636E ${path14}\uFF0C\u6B64\u64CD\u4F5C\u4E0D\u53EF\u9006\u3002\u7EE7\u7EED\uFF1F`);
6928
+ const ok = await promptConfirm(`\u5C06\u5220\u9664\u5143\u6570\u636E ${path15}\uFF0C\u6B64\u64CD\u4F5C\u4E0D\u53EF\u9006\u3002\u7EE7\u7EED\uFF1F`);
6929
6929
  if (!ok) {
6930
6930
  process.stderr.write("\u5DF2\u53D6\u6D88\n");
6931
6931
  process.exit(1);
6932
6932
  }
6933
6933
  }
6934
6934
  const c = await client2(args);
6935
- const result = await deleteTenantMeta(c.raw(), path14);
6935
+ const result = await deleteTenantMeta(c.raw(), path15);
6936
6936
  const fmt = args.output ?? "json";
6937
- if (fmt !== "json") process.stdout.write(`\u{1F5D1}\uFE0F \u5DF2\u5220\u9664 ${path14}
6937
+ if (fmt !== "json") process.stdout.write(`\u{1F5D1}\uFE0F \u5DF2\u5220\u9664 ${path15}
6938
6938
  `);
6939
6939
  process.stdout.write(formatObject18(result, { format: fmt }) + "\n");
6940
6940
  process.exitCode = 0;
@@ -6943,7 +6943,7 @@ async function metaDeleteCommand(path14, args) {
6943
6943
  fail6(e, args);
6944
6944
  }
6945
6945
  }
6946
- async function metaValidateCommand(path14, args) {
6946
+ async function metaValidateCommand(path15, args) {
6947
6947
  try {
6948
6948
  if (!args.file) {
6949
6949
  throw new CliError20({
@@ -6958,13 +6958,13 @@ async function metaValidateCommand(path14, args) {
6958
6958
  process.stdin.on("end", () => resolve3(buf));
6959
6959
  process.stdin.on("error", reject);
6960
6960
  }) : await fsp3.readFile(args.file, "utf8");
6961
- const result = validateMetaContent(path14, content);
6961
+ const result = validateMetaContent(path15, content);
6962
6962
  const fmt = args.output ?? "table";
6963
6963
  if (fmt === "json" || fmt === "yaml") {
6964
6964
  process.stdout.write(
6965
6965
  formatObject18(
6966
6966
  {
6967
- path: path14,
6967
+ path: path15,
6968
6968
  kind: result.kind,
6969
6969
  schemaKnown: result.schemaKnown,
6970
6970
  schemaSourceCommit: META_SCHEMA_SOURCE_COMMIT,
@@ -6976,7 +6976,7 @@ async function metaValidateCommand(path14, args) {
6976
6976
  );
6977
6977
  } else {
6978
6978
  process.stdout.write(
6979
- `\u{1F50E} ${path14}\uFF08schema \u7C7B\u578B\uFF1A${result.kind ?? "\u672A\u8BC6\u522B"}\uFF0C\u6765\u6E90 ${META_SCHEMA_SOURCE_COMMIT.slice(0, 8)}\uFF09
6979
+ `\u{1F50E} ${path15}\uFF08schema \u7C7B\u578B\uFF1A${result.kind ?? "\u672A\u8BC6\u522B"}\uFF0C\u6765\u6E90 ${META_SCHEMA_SOURCE_COMMIT.slice(0, 8)}\uFF09
6980
6980
  `
6981
6981
  );
6982
6982
  process.stdout.write(
@@ -9000,73 +9000,15 @@ function mergeChironAgentInstructions(existing) {
9000
9000
  function caseLibraryDir() {
9001
9001
  return path7.join(hcmConfigDir(), CASES_MCP_NAME);
9002
9002
  }
9003
- function codexConfigFile() {
9004
- return path7.join(process.env.HOME ?? os4.homedir(), ".codex", "config.toml");
9005
- }
9006
- function renderCodexMcpSection(repo, envName, binPath = process.env.PATH ?? "") {
9007
- const server = path7.join(repo, "mcp", "server.mjs");
9008
- const env2 = [
9009
- `CASES_REPO = ${JSON.stringify(repo)}`,
9010
- `HCM_ENV = ${JSON.stringify(envName)}`,
9011
- ...binPath ? [`PATH = ${JSON.stringify(binPath)}`] : []
9012
- ].join(", ");
9013
- return [
9014
- `[mcp_servers.${CASES_MCP_NAME}]`,
9015
- 'command = "node"',
9016
- `args = [${JSON.stringify(server)}]`,
9017
- `env = { ${env2} }`,
9018
- ""
9019
- ].join("\n");
9020
- }
9021
- function mergeCodexMcpConfig(existing, section) {
9022
- const lines = existing.split(/\r?\n/);
9023
- const isOurs = (line) => new RegExp(`^\\[mcp_servers\\.${CASES_MCP_NAME}(\\.|\\])`).test(line.trim());
9024
- const isHeader = (line) => /^\s*\[/.test(line);
9025
- let start = -1;
9026
- let end = -1;
9027
- for (let i = 0; i < lines.length; i++) {
9028
- const line = lines[i] ?? "";
9029
- if (start < 0 && isOurs(line)) {
9030
- start = i;
9031
- continue;
9032
- }
9033
- if (start >= 0 && isHeader(line) && !isOurs(line)) {
9034
- end = i;
9035
- break;
9036
- }
9037
- }
9038
- const block = section.trimEnd();
9039
- if (start < 0) {
9040
- const prefix = existing.trimEnd();
9041
- return `${prefix}${prefix ? "\n\n" : ""}${block}
9042
- `;
9043
- }
9044
- const tail = lines.slice(end < 0 ? lines.length : end);
9045
- const head = lines.slice(0, start);
9046
- return `${[...head, block, "", ...tail].join("\n").replace(/\n{3,}/g, "\n\n").trimEnd()}
9047
- `;
9048
- }
9049
- function codexConfigHasCases(text) {
9050
- return new RegExp(`^\\[mcp_servers\\.${CASES_MCP_NAME}\\]`, "m").test(text);
9051
- }
9052
9003
  var defaultCaseLibraryDeps = {
9053
9004
  git: (args, cwd) => {
9054
9005
  const r = spawnSync("git", args, { cwd, encoding: "utf8", timeout: 12e4, env: { ...process.env, GIT_TERMINAL_PROMPT: "0" } });
9055
9006
  return { status: r.status, stderr: r.stderr ?? "", error: r.error };
9056
- },
9057
- npmInstall: (cwd) => {
9058
- const r = spawnSync("npm", ["install", "--omit=dev", "--no-audit", "--no-fund", "--loglevel=error"], {
9059
- cwd,
9060
- encoding: "utf8",
9061
- timeout: 3e5
9062
- });
9063
- return { status: r.status, stderr: r.stderr ?? "", error: r.error };
9064
9007
  }
9065
9008
  };
9066
- async function ensureCaseLibrary(envName, deps = defaultCaseLibraryDeps, paths = {}) {
9009
+ async function ensureCaseLibrary(deps = defaultCaseLibraryDeps, paths = {}) {
9067
9010
  const repo = paths.repo ?? caseLibraryDir();
9068
- const codexConfig = paths.codexConfig ?? codexConfigFile();
9069
- const status = { ok: false, repo, step: "present", serverInstalled: false, codexWired: false };
9011
+ const status = { ok: false, repo, step: "present" };
9070
9012
  const hasGit = await exists2(path7.join(repo, ".git"));
9071
9013
  if (hasGit) {
9072
9014
  const pull = deps.git(["pull", "--ff-only", "--quiet"], repo);
@@ -9082,36 +9024,14 @@ async function ensureCaseLibrary(envName, deps = defaultCaseLibraryDeps, paths =
9082
9024
  }
9083
9025
  status.step = "cloned";
9084
9026
  }
9085
- const mcpDir = path7.join(repo, "mcp");
9086
- if (!await exists2(path7.join(mcpDir, "server.mjs"))) {
9087
- status.step = "install-failed";
9088
- status.reason = `\u6848\u4F8B\u5E93\u91CC\u6CA1\u6709 mcp/server.mjs\uFF1A${mcpDir}`;
9089
- return status;
9090
- }
9091
- if (!await exists2(path7.join(mcpDir, "node_modules", "@modelcontextprotocol"))) {
9092
- const install = deps.npmInstall(mcpDir);
9093
- if (install.status !== 0) {
9094
- status.step = "install-failed";
9095
- status.reason = `npm install \u5931\u8D25\uFF1A${firstLine(install.stderr, install.error)}`;
9096
- return status;
9097
- }
9098
- }
9099
- status.serverInstalled = true;
9100
- await fs8.mkdir(path7.dirname(codexConfig), { recursive: true });
9101
- const existing = await fs8.readFile(codexConfig, "utf8").catch(() => "");
9102
- const next = mergeCodexMcpConfig(existing, renderCodexMcpSection(repo, envName));
9103
- if (next !== existing) await fs8.writeFile(codexConfig, next, "utf8");
9104
- status.codexWired = true;
9105
9027
  status.ok = true;
9106
9028
  return status;
9107
9029
  }
9108
9030
  async function inspectCaseLibrary(paths = {}) {
9109
9031
  const repo = paths.repo ?? caseLibraryDir();
9110
- const codexConfig = paths.codexConfig ?? codexConfigFile();
9111
9032
  const cloned = await exists2(path7.join(repo, ".git"));
9112
- const serverInstalled = cloned && await exists2(path7.join(repo, "mcp", "server.mjs")) && await exists2(path7.join(repo, "mcp", "node_modules", "@modelcontextprotocol"));
9113
- const codexWired = codexConfigHasCases(await fs8.readFile(codexConfig, "utf8").catch(() => ""));
9114
- return { repo, cloned, serverInstalled, codexWired };
9033
+ const indexed = cloned && await exists2(path7.join(repo, "index", "index.json"));
9034
+ return { repo, cloned, indexed };
9115
9035
  }
9116
9036
  function firstLine(stderr, error) {
9117
9037
  if (error) return error.message;
@@ -9186,7 +9106,7 @@ var defaultChironInitDeps = {
9186
9106
  throw new Error("\u6280\u80FD\u6CA1\u88C5\u4E0A\uFF08\u4E0A\u9762\u662F skills install \u7684\u8F93\u51FA\uFF09\uFF1B\u4FEE\u597D\u540E\u91CD\u8DD1 hcm chiron init");
9187
9107
  }
9188
9108
  },
9189
- caseLibrary: (envName) => ensureCaseLibrary(envName)
9109
+ caseLibrary: () => ensureCaseLibrary()
9190
9110
  };
9191
9111
  async function resolveLoggedInEnv() {
9192
9112
  const g = await loadGlobalConfig10();
@@ -9282,7 +9202,7 @@ async function runChironInit(args, deps = defaultChironInitDeps) {
9282
9202
  let cases = { ok: false, step: "skipped" };
9283
9203
  if (!args.skipCases) {
9284
9204
  say("\u63A5\u6848\u4F8B\u5E93\uFF08chiron-cases MCP\uFF09\u2026");
9285
- cases = await deps.caseLibrary(name);
9205
+ cases = await deps.caseLibrary();
9286
9206
  if (cases.ok) say(`\u6848\u4F8B\u5E93\u5DF2\u63A5\u5165 Codex\uFF1A${cases.repo}`);
9287
9207
  else say(`\u6848\u4F8B\u5E93\u672A\u63A5\u5165\uFF08\u4E0D\u5F71\u54CD\u5F00\u5DE5\uFF0C\u7528\u5230\u65F6\u4F1A\u63D0\u793A\u6743\u9650\u4E0D\u8DB3\uFF09\uFF1A${cases.reason ?? cases.step}`);
9288
9208
  }
@@ -9322,1905 +9242,1652 @@ async function chironInitCommand(args, deps) {
9322
9242
  }
9323
9243
  }
9324
9244
 
9325
- // src/commands/chiron-doctor.ts
9326
- init_auth_guard();
9327
- init_exit();
9328
- import { promises as fs10 } from "fs";
9329
- import path9 from "path";
9245
+ // src/commands/gap.ts
9246
+ import { readFileSync as readFileSync5 } from "fs";
9330
9247
  import {
9331
- HcmClient as HcmClient21,
9332
- CliError as CliError23,
9333
- fetchReconIdentity as fetchReconIdentity2,
9248
+ createHttpClient as createHttpClient4,
9334
9249
  formatObject as formatObject22,
9335
- httpProbe as httpProbe2,
9336
- runDoctor
9250
+ loadEnv as loadEnv11,
9251
+ loadGlobalConfig as loadGlobalConfig11,
9252
+ resolveActiveEnv as resolveActiveEnv5
9337
9253
  } from "@hcmai/sdk";
9338
- var defaultDeps = {
9339
- anchors: async (envName, tenant2, as) => {
9340
- const ctx = await getActiveAuthContextFromCli({ env: envName, as });
9341
- const client3 = HcmClient21.fromAuthContext(ctx);
9342
- const probe2 = httpProbe2(client3.raw(), "default");
9343
- const identity2 = await fetchReconIdentity2(probe2, tenant2);
9344
- return { report: await runDoctor(probe2, identity2), tokenTenant: identity2?.tenantId ? String(identity2.tenantId) : void 0 };
9345
- },
9346
- fixSkills: (root, envName) => defaultChironInitDeps.installSkills(root, envName),
9347
- fixCases: async (envName) => {
9348
- await ensureCaseLibrary(envName);
9349
- },
9350
- inspectCases: () => inspectCaseLibrary(),
9351
- inspectJira: () => inspectJira()
9352
- };
9353
- async function runChironDoctor(args, deps = defaultDeps) {
9354
- const root = path9.resolve(args.project ?? ".");
9355
- const report = { ok: false, project: root, env: null, envName: null, lines: [] };
9356
- const envText = await fs10.readFile(path9.join(root, ENV_FILE), "utf8").catch(() => null);
9357
- if (envText === null) {
9358
- report.lines.push({
9359
- item: "\u767B\u5F55",
9360
- verdict: "fail",
9361
- detail: `\u8FD9\u4E2A\u76EE\u5F55\u91CC\u6CA1\u6709 ${ENV_FILE}\uFF0C\u4E0D\u662F\u777F\u620E\u9879\u76EE\u4ED3\uFF08\u6216\u8FD8\u6CA1\u521D\u59CB\u5316\uFF09`,
9362
- nextStep: "\u65B0\u4ED3\uFF1Ahcm login <\u5730\u5740> --code <\u914D\u5BF9\u7801> \u540E hcm chiron init\uFF1B\u5DF2\u6709\u4ED3\uFF1A\u786E\u8BA4 clone \u7684\u662F\u5BF9\u7684\u4ED3\u3001\u7AD9\u5728\u4ED3\u6839\u76EE\u5F55"
9363
- });
9364
- return finish(report);
9365
- }
9366
- let env2;
9367
- try {
9368
- env2 = parseEnvYaml(envText);
9369
- } catch (e) {
9370
- report.lines.push({ item: "\u767B\u5F55", verdict: "fail", detail: e.message, nextStep: `\u6309 hcm chiron init \u751F\u6210\u7684\u4E09\u884C\u5F62\u6001\u4FEE ${ENV_FILE}` });
9371
- return finish(report);
9372
- }
9373
- report.env = env2;
9374
- const found = await findEnvByEndpoint(env2.endpoint, env2.tenant);
9375
- const loginCmd = `hcm login ${env2.endpoint} --code <\u914D\u5BF9\u7801>`;
9376
- if (!found) {
9377
- report.lines.push({ item: "\u767B\u5F55", verdict: "fail", detail: `\u672C\u673A\u6CA1\u6709\u767B\u5F55\u8FC7 ${env2.endpoint}`, nextStep: loginCmd });
9378
- } else {
9379
- report.envName = found.name;
9380
- try {
9381
- const targetEnv = args.env ?? found.name;
9382
- const { report: anchors, tokenTenant } = await deps.anchors(targetEnv, env2.tenant, args.as);
9383
- report.anchors = anchors;
9384
- const tenantMismatch = tokenTenant && tokenTenant !== env2.tenant;
9385
- const bad = anchors.checks.filter((c) => !c.ok && !(tenantMismatch && c.anchor === "identity"));
9386
- if (bad.length === 0 && !tenantMismatch) {
9387
- const who = found.config.defaultIdentity ? ` \xB7 ${found.config.defaultIdentity}` : "";
9388
- report.lines.push({ item: "\u767B\u5F55", verdict: "ok", detail: `${found.name} \xB7 ${env2.endpoint} \xB7 \u79DF\u6237 ${env2.tenant}${who}` });
9389
- } else {
9390
- const parts = [`${found.name} \xB7 ${env2.endpoint}`];
9391
- if (tenantMismatch) parts.push(`\u4F60\u7684\u767B\u5F55\u8EAB\u4EFD\u5C5E\u4E8E\u79DF\u6237 ${tokenTenant}\uFF0C\u9879\u76EE\u662F\u79DF\u6237 ${env2.tenant}`);
9392
- if (bad.length) parts.push(`\u951A\u70B9\u672A\u8FC7\uFF1A${bad.map((c) => `${c.anchor}\uFF08${c.detail}\uFF09`).join("\u3001")}`);
9393
- report.lines.push({
9394
- item: "\u767B\u5F55",
9395
- verdict: "fail",
9396
- detail: parts.join("\uFF1B"),
9397
- nextStep: tenantMismatch ? `${loginCmd}\uFF08\u7528\u9879\u76EE\u79DF\u6237\u7684\u914D\u5BF9\u7801\uFF09` : "\u6309\u4E0A\u9762\u951A\u70B9\u7684\u63D0\u793A\u5904\u7406\uFF1B\u8EAB\u4EFD\u8FC7\u671F\u5C31\u91CD\u65B0 " + loginCmd
9398
- });
9399
- }
9400
- } catch (e) {
9401
- const msg = e instanceof CliError23 ? e.message : e.message;
9402
- report.lines.push({ item: "\u767B\u5F55", verdict: "fail", detail: `${found.name} \xB7 ${env2.endpoint}\uFF1A${msg}`, nextStep: loginCmd });
9403
- }
9404
- }
9405
- const skillsLine = async () => {
9406
- const state = await readSkillsState(path9.join(root, SKILLS_DIR));
9407
- if (!state) return { item: "\u6280\u80FD", verdict: "fail", detail: `${SKILLS_DIR}/ \u91CC\u6CA1\u6709\u5B89\u88C5\u6E05\u5355`, nextStep: "hcm chiron doctor --fix\uFF08\u6216 hcm chiron init\uFF09" };
9408
- const count = Object.keys(state.skills).length;
9409
- if (state.endpoint && normalizeOrigin(state.endpoint) !== env2.endpoint) {
9410
- return { item: "\u6280\u80FD", verdict: "fail", detail: `${count} \u4E2A\uFF0C\u4F46\u88C5\u81EA ${state.endpoint}\uFF0C\u4E0D\u662F\u9879\u76EE\u73AF\u5883 ${env2.endpoint}`, nextStep: "hcm chiron doctor --fix \u91CD\u88C5" };
9411
- }
9412
- if (state.target !== "codex") {
9413
- return { item: "\u6280\u80FD", verdict: "warn", detail: `${count} \u4E2A\uFF0C\u5E03\u5C40\u662F ${state.target}\uFF08Codex \u8981\u8BFB AGENTS.md \u7D22\u5F15\uFF09`, nextStep: "hcm skills install --all --target codex" };
9414
- }
9415
- return { item: "\u6280\u80FD", verdict: "ok", detail: `${count} \u4E2A\uFF0C\u6765\u81EA ${state.endpoint ?? "\u672C\u5730"}${state.all ? "\uFF0C\u8DDF\u968F\u5168\u96C6" : ""}` };
9416
- };
9417
- let skills2 = await skillsLine();
9418
- if (skills2.verdict === "fail" && args.fix && report.envName) {
9419
- await deps.fixSkills(root, report.envName);
9420
- skills2 = await skillsLine();
9421
- }
9422
- report.lines.push(skills2);
9423
- const casesLine = async () => {
9424
- const c = await deps.inspectCases();
9425
- if (!c.cloned) return { item: "\u6848\u4F8B\u5E93", verdict: "warn", detail: `\u672A clone\uFF08${c.repo}\uFF09`, nextStep: "hcm chiron doctor --fix\uFF1B\u6CA1\u6709 cnb \u6743\u9650\u5C31\u5148\u8DF3\u8FC7\uFF0C\u63D0\u4EA4\u6848\u4F8B/\u7F3A\u53E3\u65F6\u4F1A\u63D0\u793A" };
9426
- if (!c.serverInstalled) return { item: "\u6848\u4F8B\u5E93", verdict: "warn", detail: "MCP \u4F9D\u8D56\u6CA1\u88C5", nextStep: "hcm chiron doctor --fix" };
9427
- if (!c.codexWired) return { item: "\u6848\u4F8B\u5E93", verdict: "warn", detail: "Codex \u6CA1\u63A5\u7EBF\uFF08~/.codex/config.toml \u7F3A [mcp_servers.chiron-cases]\uFF09", nextStep: "hcm chiron doctor --fix" };
9428
- return { item: "\u6848\u4F8B\u5E93", verdict: "ok", detail: `\u5DF2\u63A5\u5165 Codex\uFF08${c.repo}\uFF09` };
9429
- };
9430
- let cases = await casesLine();
9431
- if (cases.verdict !== "ok" && args.fix && report.envName) {
9432
- await deps.fixCases(report.envName);
9433
- cases = await casesLine();
9254
+ init_exit();
9255
+ import { createJiraClient } from "@hcmai/sdk";
9256
+
9257
+ // src/jira/gaps.ts
9258
+ import { CASES_REPO_SLUG, repoIssueUrl } from "@hcmai/sdk";
9259
+ import { linkedRepoRefs, parseRef } from "@hcmai/sdk";
9260
+ var MIN_LEN = [
9261
+ ["title", 8],
9262
+ ["phenomenon", 20],
9263
+ ["repro", 10],
9264
+ ["expected", 10],
9265
+ ["alternative", 5],
9266
+ ["q_mechanism", 10],
9267
+ ["q_history", 10],
9268
+ ["q_skill", 10]
9269
+ ];
9270
+ function validateGapInput(x) {
9271
+ if (!x || typeof x !== "object") throw new Error("\u7F3A\u53E3\u8F7D\u8377\u5FC5\u987B\u662F\u4E00\u4E2A JSON \u5BF9\u8C61");
9272
+ const g = x;
9273
+ const problems = [];
9274
+ for (const [k, min] of MIN_LEN) {
9275
+ const v = g[k];
9276
+ if (typeof v !== "string" || v.trim().length < min) problems.push(`${k} \u81F3\u5C11 ${min} \u4E2A\u5B57`);
9434
9277
  }
9435
- report.lines.push(cases);
9436
- const jira2 = await deps.inspectJira();
9437
- report.lines.push(
9438
- jira2.ok ? { item: "Jira", verdict: "ok", detail: `${jira2.who || "\u5DF2\u8FDE\u63A5"} \xB7 \u770B\u5F97\u5230 ${JIRA_PROJECT2}\uFF08\u4EE4\u724C\u6765\u81EA ${jira2.from}\uFF09` } : { item: "Jira", verdict: "warn", detail: jira2.reason ?? "\u4E0D\u53EF\u7528", nextStep: "\u73B0\u5728\u4E0D\u914D\u4E5F\u80FD\u4EA4\u4ED8\uFF1B\u649E\u5230\u300C\u4EA7\u54C1\u505A\u4E0D\u5230\u300D\u8981\u63D0\u5355\u65F6\u5FC5\u987B\u5148\u914D\u597D" }
9439
- );
9440
- return finish(report);
9278
+ if (typeof g.title === "string" && g.title.length > 80) problems.push("title \u4E0D\u8D85\u8FC7 80 \u4E2A\u5B57");
9279
+ if (!["\u963B\u65AD", "\u6709\u66FF\u4EE3\u6CD5", "\u63AA\u8F9E\u7EA7"].includes(String(g.severity))) problems.push("severity \u53EA\u80FD\u662F \u963B\u65AD / \u6709\u66FF\u4EE3\u6CD5 / \u63AA\u8F9E\u7EA7");
9280
+ if (!["\u7F3A\u9677", "\u7F3A\u80FD\u529B"].includes(String(g.kind))) problems.push("kind \u53EA\u80FD\u662F \u7F3A\u9677\uFF08\u6545\u969C\uFF09/ \u7F3A\u80FD\u529B\uFF08\u9700\u6C42\uFF09");
9281
+ if (g.module !== void 0 && !["HCM-Core", "HCM-Cloud", "\u4EA7\u54C1\u652F\u6301"].includes(String(g.module))) problems.push("module \u53EA\u80FD\u662F HCM-Core / HCM-Cloud / \u4EA7\u54C1\u652F\u6301");
9282
+ if (problems.length) throw new Error(`\u7F3A\u53E3\u8F7D\u8377\u4E0D\u5408\u683C\uFF0C\u6CA1\u6709\u63D0\uFF1A
9283
+ ${problems.join("\n ")}`);
9284
+ return g;
9441
9285
  }
9442
- function finish(report) {
9443
- report.ok = report.lines.every((l) => l.verdict !== "fail");
9444
- return report;
9286
+ var gapKeyTag = (g) => `\u3014${[g.model, g.action, g.error_code].filter(Boolean).join("\xB7") || "-"}\u3015`;
9287
+ var gapSummary = (g) => `\u7F3A\u53E3\uFF1A${g.title} ${gapKeyTag(g)}`;
9288
+ function renderGapDescription(g, fingerprintText2) {
9289
+ return [
9290
+ "h2. \u73B0\u8C61",
9291
+ g.phenomenon,
9292
+ "",
9293
+ "h2. \u590D\u73B0",
9294
+ "{code}",
9295
+ g.repro,
9296
+ "{code}",
9297
+ "",
9298
+ "h2. \u671F\u671B",
9299
+ g.expected,
9300
+ "",
9301
+ "h2. \u73AF\u5883\u6307\u7EB9",
9302
+ fingerprintText2,
9303
+ "",
9304
+ "h2. \u66FF\u4EE3\u6CD5",
9305
+ g.alternative,
9306
+ "",
9307
+ "h2. \u4E25\u91CD\u5EA6",
9308
+ `${g.severity}\uFF08\u987E\u95EE\u4FA7\u5224\u5B9A\uFF1A\u963B\u65AD=\u4EA4\u4ED8\u505C\u4E0B / \u6709\u66FF\u4EE3\u6CD5=\u80FD\u7ED5 / \u63AA\u8F9E\u7EA7=\u8F93\u51FA\u5DF2\u7ED9\u8DEF\u6807\uFF09`,
9309
+ "",
9310
+ "h2. \u4E09\u95EE\u81EA\u7B54",
9311
+ `# \u673A\u5236\u8FB9\u754C\uFF1A${g.q_mechanism}`,
9312
+ `# \u5386\u53F2\uFF1A${g.q_history}`,
9313
+ `# \u6280\u80FD\u6709\u6CA1\u6709\u6559\u9519\uFF1A${g.q_skill}`,
9314
+ "",
9315
+ "h2. \u5173\u952E\u8BCD",
9316
+ [g.error_code, g.model, g.action].filter(Boolean).join(" \xB7 ") || "\uFF08\u65E0\uFF09",
9317
+ "",
9318
+ "_\u7531\u987E\u95EE agent \u7ECF `hcm chiron gap submit` \u63D0\u4EA4\u3002\u5206\u8BCA\u4E09\u53BB\u5411\uFF1A\u8F6C\u4EA7\u54C1\u4ED3 issue \u5E76\u56DE\u94FE / \u6539\u6280\u80FD\u5E76\u56DE\u590D / \u5408\u5E76\u8BA1\u6570\u3002\u5904\u7406\u529E\u6CD5\u89C1\u4EA7\u54C1\u4ED3\u6280\u80FD jira-triage\u3002_"
9319
+ ].join("\n");
9445
9320
  }
9446
- function renderChironDoctor(report) {
9447
- const mark = { ok: "\u2705", warn: "\u26A0\uFE0F", fail: "\u274C" };
9448
- const out = [];
9449
- for (const l of report.lines) {
9450
- out.push(`${mark[l.verdict]} ${l.item.padEnd(3, "\u3000")} ${l.detail}`);
9451
- if (l.nextStep && l.verdict !== "ok") out.push(` \u2192 ${l.nextStep}`);
9321
+ function findDuplicateGap(open, summary, keyTag) {
9322
+ const bigrams = (t) => {
9323
+ const x = (t || "").replace(/〔.*?〕/g, "").replace(/[\s,。::、()()「」]/g, "");
9324
+ const out = /* @__PURE__ */ new Set();
9325
+ for (let i = 0; i + 1 < x.length; i++) out.add(x.slice(i, i + 2));
9326
+ return out;
9327
+ };
9328
+ const sim = (a, b) => {
9329
+ const A = bigrams(a);
9330
+ const B = bigrams(b);
9331
+ if (!A.size || !B.size) return 0;
9332
+ let n = 0;
9333
+ for (const s of A) if (B.has(s)) n++;
9334
+ return n / Math.min(A.size, B.size);
9335
+ };
9336
+ for (const i of open) {
9337
+ const t = i.fields.summary ?? "";
9338
+ if (keyTag !== "\u3014-\u3015" && t.includes(keyTag)) return i;
9339
+ if (sim(t, summary) >= 0.6) return i;
9452
9340
  }
9453
- out.push("");
9454
- out.push(report.ok ? "\u53EF\u4EE5\u5F00\u5DE5\uFF1A\u5728\u8FD9\u4E2A\u76EE\u5F55\u91CC\u542F\u52A8 codex\u3002" : "\u5148\u6309 \u2192 \u5904\u7406\u7EA2\u9879\uFF0C\u518D\u8DD1\u4E00\u6B21 hcm chiron doctor\u3002");
9455
- return out.join("\n");
9341
+ return null;
9456
9342
  }
9457
- async function chironDoctorCommand(args, deps) {
9458
- try {
9459
- const report = await runChironDoctor(args, deps);
9460
- const fmt = args.output ?? "table";
9461
- if (fmt === "json" || fmt === "yaml") process.stdout.write(formatObject22(report, { format: fmt }) + "\n");
9462
- else process.stdout.write(renderChironDoctor(report) + "\n");
9463
- process.exitCode = report.ok ? 0 : 1;
9464
- } catch (e) {
9465
- exitWithError(e);
9343
+ var KIND_TO_TYPE = { \u7F3A\u9677: ["\u6545\u969C", "Bug", "\u7F3A\u9677"], \u7F3A\u80FD\u529B: ["\u9700\u6C42", "Story", "New Feature"] };
9344
+ var KIND_TO_CATEGORY = { \u7F3A\u9677: "\u7A0B\u5E8FBug", \u7F3A\u80FD\u529B: "\u9700\u6C42" };
9345
+ var SEVERITY_TO_PRIORITY = {
9346
+ \u963B\u65AD: ["\u7D27\u6025", "Highest", "High", "\u9AD8"],
9347
+ \u6709\u66FF\u4EE3\u6CD5: ["Medium", "\u4E2D", "\u4E00\u822C", "High"],
9348
+ \u63AA\u8F9E\u7EA7: ["Low", "\u4F4E", "Lowest"]
9349
+ };
9350
+ var MODULE_DEFAULT_CHILD = { "HCM-Core": "\u57FA\u7840\u8BBE\u7F6E", "HCM-Cloud": "\u5F00\u53D1\u5E73\u53F0", \u4EA7\u54C1\u652F\u6301: "\u4EA7\u54C1\u652F\u6301" };
9351
+ function buildGapFields(g, ctx) {
9352
+ const wanted = KIND_TO_TYPE[g.kind] ?? [];
9353
+ const type = ctx.issuetypeOverride && ctx.types.find((t) => t.name === ctx.issuetypeOverride) || wanted.map((n) => ctx.types.find((t) => t.name === n)).find(Boolean);
9354
+ if (!type) {
9355
+ throw new Error(`\u9879\u76EE ${ctx.project} \u91CC\u6CA1\u6709\u300C${wanted.join(" / ")}\u300D\u8FD9\u7C7B issuetype\uFF0C\u5B9E\u9645\u6709\uFF1A${ctx.types.map((t) => t.name).join(" / ")}`);
9466
9356
  }
9467
- }
9468
-
9469
- // src/commands/chiron-test.ts
9470
- init_exit();
9471
- import { spawnSync as spawnSync2 } from "child_process";
9472
- import { promises as fs11 } from "fs";
9473
- import path10 from "path";
9474
- import yaml from "js-yaml";
9475
- import { formatObject as formatObject23 } from "@hcmai/sdk";
9476
-
9477
- // src/commands/delivery-action-policy.ts
9478
- init_auth_guard();
9479
- import { HcmClient as HcmClient22, classifyEffect } from "@hcmai/sdk";
9480
-
9481
- // src/commands/delivery.ts
9482
- import { createHash as createHash5 } from "crypto";
9483
- var APPROVAL_BYPASS_FLAGS = /* @__PURE__ */ new Set(["-y", "--yes", "--force", "--auto-approve"]);
9484
- var CREDENTIAL_FLAGS = /* @__PURE__ */ new Set([
9485
- "--password",
9486
- "--password-stdin",
9487
- "--client-secret",
9488
- "--pat",
9489
- "--pat-stdin",
9490
- "--new-password",
9491
- "--new-password-stdin"
9492
- ]);
9493
- var PAYLOAD_FLAGS = ["--data", "--params"];
9494
- var GUARDED_EXECUTOR_REASON_CODES = /* @__PURE__ */ new Set([
9495
- "record-create",
9496
- "record-update",
9497
- "cache-mutation",
9498
- "setting-write",
9499
- "credential-reset",
9500
- "action-write",
9501
- // 三态 effect 的 UNKNOWN / 未识别值都按最坏情况视作写操作,走与 WRITES
9502
- // 完全相同的 prepare + execute 通道。分类函数已经返回 R2 guarded;这里漏登记
9503
- // 会把 guardedExecutionAvailable 又翻回 false,造成 reason 与 modePolicy 自相矛盾。
9504
- "action-effect-undetermined",
9505
- "action-effect-unrecognized",
9506
- "workspace-create",
9507
- "workspace-activate",
9508
- "workspace-deactivate",
9509
- // bind / add mini / rm 都是受控本地工作区变更;rm 暂存删除,push 再执行远端 DELETE。
9510
- "workspace-local-change",
9511
- // 这两个的载荷是**任意文件 / 整棵目录**,此前刻意不收——绑不住就意味着
9512
- // 「批准时看到的内容」与「执行时实际读到的内容」可以不同。
9513
- //
9514
- // 现在绑得住了:PAYLOAD_FILE_FLAGS 收了 --file,PAYLOAD_DIR_FLAGS 收了 --dir
9515
- // (workspace push 不传 --dir 时按其 option 默认值 '.' 隐式绑定),
9516
- // 目录按「路径 + 内容、排序稳定」整树摘要,assertPayloadsUnchanged 执行前逐一重算比对。
9517
- //
9518
- // 🔴 二次开发的整条链就卡在这两个上:2026-09-01 轨道 A 第四轮验收,
9519
- // 受控执行第一次跑通了 workspace create,却在 meta set / workspace push 上
9520
- // 被「该 R2 命令不在首批受控执行器支持面」拦死,远端只多了一个空 workspace。
9521
- "metadata-write",
9522
- "workspace-push",
9523
- // 载荷是**位置参数**(`hcm import <路径>`),既不走 --file 也不走 --dir,
9524
- // 所以上一刀把文件与目录开关收进来时它仍留在外面(0.4.9 CHANGELOG 逐字记了这一条)。
9525
- //
9526
- // 现在收得住了:POSITIONAL_PAYLOAD_COMMANDS 把 argv[1] 这个固定位置钉成载荷,
9527
- // 目录走整树摘要、单文件走文件摘要,execute 前重算比对(与 --dir 同一套 bind/assert)。
9528
- // 位置定死而不是「扫第一个非 flag 参数」,是因为 shape 校验与载荷绑定必须对
9529
- // 「哪个 token 是载荷」看法一致——两处各自解析就能绑 A 执行 B。
9530
- //
9531
- // 🔴 客户存量组织导入的整条链就卡在这一个上:2026-09-01 演示环境租户 15,
9532
- // 531 条组织机构 dry-run 全绿(静态校验 0 失败),正式导入被
9533
- // 「该 R2 命令不在首批受控执行器支持面」拦死,一个写请求都没发出去。
9534
- "import-write",
9535
- // 报表 / 套打模板回传要先 upload 拿 documentId,再挂到业务对象。文件路径是
9536
- // 固定位置参数,prepare 会钉住项目内普通文件的摘要,execute 前重算后才单次执行。
9537
- // 2026-09-02 弹性报表顾问仿真已证实这条交付链会在缺受控执行器时中断。
9538
- "document-upload"
9539
- ]);
9540
- function normalizeAssessedArgv(inputArgv) {
9541
- let rest = inputArgv;
9542
- const dropSeparators = () => {
9543
- let start = 0;
9544
- while (rest[start] === "--") start += 1;
9545
- rest = start > 0 ? rest.slice(start) : rest;
9357
+ const module = g.module ?? "HCM-Core";
9358
+ const keyTag = gapKeyTag(g);
9359
+ const byName = {
9360
+ \u6982\u8981: gapSummary(g),
9361
+ \u63CF\u8FF0: renderGapDescription(g, ctx.fingerprintText),
9362
+ \u95EE\u9898\u7C7B\u522B: KIND_TO_CATEGORY[g.kind],
9363
+ \u95EE\u9898\u6A21\u5757: module,
9364
+ \u4F18\u5148\u7EA7: SEVERITY_TO_PRIORITY[g.severity],
9365
+ \u62A5\u544A\u4EBA: ctx.me,
9366
+ \u7ECF\u529E\u4EBA: ctx.assignee,
9367
+ Bug\u53D1\u73B0\u4EBA: "\u987E\u95EE",
9368
+ Bug\u91CD\u73B0\u64CD\u4F5C\u6B65\u9AA4: g.repro,
9369
+ Bug\u9519\u8BEF\u53F7: g.error_code || "\u65E0\u9519\u8BEF\u7801\uFF08\u73B0\u8C61\u89C1\u63CF\u8FF0\uFF09"
9546
9370
  };
9547
- dropSeparators();
9548
- if (PACKAGE_RUNNERS.has(rest[0] ?? "") && isCliLauncher(rest[1])) {
9549
- rest = rest.slice(2);
9550
- } else if (isCliLauncher(rest[0])) {
9551
- rest = rest.slice(1);
9552
- }
9553
- dropSeparators();
9554
- return rest === inputArgv ? [...inputArgv] : rest;
9555
- }
9556
- var PACKAGE_RUNNERS = /* @__PURE__ */ new Set(["npx", "bunx", "pnpx"]);
9557
- function isCliLauncher(token) {
9558
- if (!token || token.startsWith("-")) return false;
9559
- if (token === "@hcmai/cli") return true;
9560
- const base = token.split(/[\\/]/).pop() ?? token;
9561
- return base === "hcm" || base === "hcm.js" || base === "hcmai";
9562
- }
9563
- function assessDeliveryCommand(inputArgv, options = {}) {
9564
- const argv = normalizeAssessedArgv(inputArgv);
9565
- const commandSha256 = sha2564(JSON.stringify(argv));
9566
- const name = argv[0] ?? "";
9567
- const subcommand = argv[1] && !argv[1].startsWith("-") ? argv[1] : void 0;
9568
- const envAlias = flagValue(argv, "--env");
9569
- const identityAlias = flagValue(argv, "--as");
9570
- const sensitiveFlags = [
9571
- ...new Set([...PAYLOAD_FLAGS, ...CREDENTIAL_FLAGS].filter((flag) => hasFlag(argv, flag)))
9572
- ];
9573
- const target = summarizeTarget(argv, options.actionResolution);
9574
- let classification = classify(argv, options.actionResolution);
9575
- const invalidPayload = payloadError(argv);
9576
- if (invalidPayload) {
9577
- classification = forbidden("invalid-input", "JSON payload \u65E0\u6548\uFF0C\u4E0D\u80FD\u8FDB\u5165\u4EFB\u4F55\u6267\u884C\u8DEF\u5F84\u3002");
9578
- }
9579
- const requirements = [];
9580
- const guardedExecutionAvailable = classification.risk === "R2" && GUARDED_EXECUTOR_REASON_CODES.has(classification.reasonCode);
9581
- if (classification.risk === "R2") {
9582
- if (!envAlias) requirements.push("explicit-env");
9583
- if (!identityAlias) requirements.push("explicit-identity");
9584
- if (guardedExecutionAvailable) {
9585
- requirements.push("change-plan", "rollback-plan", "human-approval", "single-use-plan");
9586
- } else {
9587
- requirements.push("guarded-executor");
9371
+ const fields = { project: { key: ctx.project }, issuetype: { id: type.id } };
9372
+ const unfilled = [];
9373
+ const values = (f) => (f.allowedValues ?? []).map((v) => v.value ?? v.name).join("|");
9374
+ for (const f of type.fields ?? []) {
9375
+ if (["project", "issuetype"].includes(f.fieldId)) continue;
9376
+ const want = byName[f.name];
9377
+ if (want === void 0) {
9378
+ if (f.required) unfilled.push(`${f.name}(${f.fieldId})${f.allowedValues ? `=[${values(f)}]` : ""}`);
9379
+ continue;
9588
9380
  }
9589
- } else if (classification.risk === "R3") {
9590
- requirements.push("governance-escalation");
9591
- }
9592
- const allowed = classification.risk === "R0" || classification.risk === "R1";
9593
- return {
9594
- schemaVersion: 1,
9595
- contractVersion: "2026-08-29",
9596
- assessmentId: sha2564(`2026-08-29
9597
- ${commandSha256}`).slice(0, 24),
9598
- commandSha256,
9599
- command: { name: name || "(empty)", ...subcommand ? { subcommand } : {} },
9600
- ...classification,
9601
- guardedExecutionAvailable,
9602
- environment: {
9603
- ...envAlias ? { envAlias } : {},
9604
- ...identityAlias ? { identityAlias } : {}
9605
- },
9606
- target,
9607
- requirements,
9608
- evidenceRequirements: evidenceFor(classification.risk),
9609
- sensitiveFlags,
9610
- modePolicy: {
9611
- planOnly: allowed ? "allow" : "deny",
9612
- controlled: allowed || guardedExecutionAvailable ? "allow" : "deny"
9381
+ if (f.schema?.type === "option-with-child") {
9382
+ const parent = (f.allowedValues ?? []).find((v) => (v.value ?? v.name) === want);
9383
+ if (!parent) {
9384
+ if (f.required) unfilled.push(`${f.name}(${f.fieldId}) \u60F3\u586B\u300C${String(want)}\u300D\u4F46\u53EF\u9009\u503C\u53EA\u6709 [${values(f)}]`);
9385
+ continue;
9386
+ }
9387
+ const childName = g.module_detail || MODULE_DEFAULT_CHILD[module];
9388
+ const child = (parent.children ?? []).find((c) => (c.value ?? c.name) === childName);
9389
+ if (!child && (parent.children ?? []).length) {
9390
+ unfilled.push(`${f.name}(${f.fieldId}) \u7684\u4E8C\u7EA7\u9879\u300C${childName}\u300D\u4E0D\u5728 [${(parent.children ?? []).map((c) => c.value ?? c.name).join("|")}] \u91CC`);
9391
+ continue;
9392
+ }
9393
+ fields[f.fieldId] = { id: parent.id, ...child ? { child: { id: child.id } } : {} };
9394
+ continue;
9613
9395
  }
9614
- };
9615
- }
9616
- function classify(argv, actionResolution) {
9617
- const name = argv[0] ?? "";
9618
- const subcommand = argv[1] ?? "";
9619
- if (name.startsWith("-")) {
9620
- return forbidden(
9621
- "malformed-argv",
9622
- `\u88AB\u8BC4\u4F30\u7684\u547D\u4EE4\u540D\u89E3\u6790\u6210\u4E86 ${name} \u2014\u2014 \u90A3\u662F\u4E00\u4E2A\u9009\u9879\uFF0C\u4E0D\u662F\u547D\u4EE4\u3002next_step=\u4ECE\u547D\u4EE4\u540D\u5F00\u5934\u5199\u6574\u6761\u547D\u4EE4\uFF0C\u628A ${name} \u632A\u5230\u547D\u4EE4\u540D\u540E\u9762\uFF0C\u4F8B\u5982 \`hcm meta set <Model> --env <env>\``
9623
- );
9624
- }
9625
- if (argv.some((arg) => APPROVAL_BYPASS_FLAGS.has(flagName(arg)))) {
9626
- return forbidden("approval-bypass", "\u547D\u4EE4\u5305\u542B\u8DF3\u8FC7\u786E\u8BA4\u7684\u65D7\u6807\uFF0C\u987E\u95EE\u4EA4\u4ED8\u9762\u4E0D\u6267\u884C\u3002");
9627
- }
9628
- if (name === "user" && subcommand === "reset-password") {
9629
- const nonStdinCredential = argv.some((arg) => {
9630
- const flag = flagName(arg);
9631
- return CREDENTIAL_FLAGS.has(flag) && flag !== "--password-stdin";
9632
- });
9633
- if (nonStdinCredential || !argv.includes("--password-stdin")) {
9634
- return forbidden(
9635
- "credential-governance",
9636
- "\u7528\u6237\u5BC6\u7801\u91CD\u7F6E\u53EA\u80FD\u901A\u8FC7 --password-stdin \u8FDB\u5165\u53D7\u63A7\u51ED\u636E\u6D41\u7A0B\u3002"
9637
- );
9396
+ if (f.allowedValues) {
9397
+ const candidates = Array.isArray(want) ? want : [want];
9398
+ const hit = candidates.map((c) => f.allowedValues.find((v) => (v.name ?? v.value) === c)).find(Boolean);
9399
+ if (!hit) {
9400
+ if (f.required) unfilled.push(`${f.name}(${f.fieldId}) \u60F3\u586B\u300C${candidates.join("/")}\u300D\u4F46\u53EF\u9009\u503C\u53EA\u6709 [${values(f)}]`);
9401
+ continue;
9402
+ }
9403
+ fields[f.fieldId] = hit.id ? { id: hit.id } : { name: hit.name ?? hit.value };
9404
+ } else if (f.schema?.type === "user") {
9405
+ if (!want) {
9406
+ if (f.required) unfilled.push(`${f.name}(${f.fieldId}) \u53D6\u4E0D\u5230\u7528\u6237\u540D`);
9407
+ continue;
9408
+ }
9409
+ fields[f.fieldId] = { name: Array.isArray(want) ? want[0] : want };
9410
+ } else {
9411
+ fields[f.fieldId] = Array.isArray(want) ? want[0] : want;
9638
9412
  }
9639
- return guarded("credential-write", "credential-reset");
9640
9413
  }
9641
- if (argv.some((arg) => CREDENTIAL_FLAGS.has(flagName(arg)))) {
9642
- return forbidden("credential-governance", "\u547D\u4EE4\u643A\u5E26\u8EAB\u4EFD\u51ED\u636E\u53C2\u6570\uFF0C\u5FC5\u987B\u8F6C\u4EA4\u8EAB\u4EFD\u6CBB\u7406\u6D41\u7A0B\u3002");
9414
+ if ((type.fields ?? []).some((f) => f.fieldId === "labels")) {
9415
+ const sev = { \u963B\u65AD: "blocking", \u6709\u66FF\u4EE3\u6CD5: "workaround", \u63AA\u8F9E\u7EA7: "wording" }[g.severity];
9416
+ fields.labels = ["chiron-gap", `severity-${sev}`];
9643
9417
  }
9644
- if (name === "version") return direct("R0", "product-discovery", "product-discovery");
9645
- if (name === "open") return direct("R1", "remote-read", "browser-session-open");
9646
- if (name === "models") return direct("R0", "product-discovery", "model-discovery");
9647
- if (name === "config") {
9648
- if (["list", "show", "get"].includes(subcommand))
9649
- return direct("R0", "local-discovery", "config-read");
9650
- return forbidden(
9651
- "identity-governance",
9652
- "\u4FEE\u6539\u672C\u673A\u5168\u5C40\u914D\u7F6E\u4F1A\u6539\u53D8\u540E\u7EED\u6240\u6709\u547D\u4EE4\u7684\u73AF\u5883\u4E0E\u8EAB\u4EFD\uFF0C\u5C5E\u6CBB\u7406\u64CD\u4F5C\u3002"
9418
+ if (unfilled.length) {
9419
+ throw new Error(
9420
+ `\u8FD9\u53F0 Jira \u7684\u300C${type.name}\u300D\u6709\u6211\u586B\u4E0D\u4E0A\u7684\u5FC5\u586B\u5B57\u6BB5\uFF0C\u6CA1\u6709\u5EFA\u5355\uFF08\u4E0D\u66FF\u4F60\u731C\uFF09\uFF1A
9421
+ ${unfilled.join("\n ")}
9422
+ next_step=\u8BA9 Jira \u7BA1\u7406\u5458\u628A\u8FD9\u4E9B\u5B57\u6BB5\u6539\u6210\u975E\u5FC5\u586B\uFF0C\u6216\u544A\u8BC9\u6211\u8BE5\u586B\u4EC0\u4E48\u3001\u6211\u52A0\u8FDB\u6620\u5C04\u3002\u53F0\u8D26\u5DF2\u7ECF\u5728\u9879\u76EE\u4ED3\u91CC\uFF0C\u4E0D\u4F1A\u4E22\u3002`
9653
9423
  );
9654
9424
  }
9655
- if (name === "upgrade" || name === "self-update") {
9656
- return direct("R1", "managed-local-write", "cli-self-upgrade");
9657
- }
9658
- if (name === "datapackage") {
9659
- if (subcommand === "pack") return direct("R1", "local-validation", "datapackage-pack");
9660
- if (subcommand === "status") return direct("R1", "remote-read", "datapackage-status");
9661
- if (subcommand === "install") return guarded("tenant-data-write", "datapackage-install");
9662
- return forbidden("unknown-command", "\u672A\u77E5 datapackage \u5B50\u547D\u4EE4\u6309\u6700\u9AD8\u98CE\u9669\u5173\u95ED\u3002");
9663
- }
9664
- if (name === "mini") {
9665
- return forbidden("removed-command", "`hcm mini` \u5DF2\u79FB\u9664\uFF0C\u6539\u7528 `hcm workspace`\u3002");
9666
- }
9667
- if (name === "chiron") {
9668
- if (subcommand === "doctor") return direct("R0", "local-discovery", "chiron-doctor");
9669
- if (subcommand === "init") return direct("R1", "managed-local-write", "chiron-project-scaffold");
9670
- if (subcommand === "test") return direct("R1", "remote-read", "chiron-regression-test");
9671
- return forbidden("unknown-command", "\u672A\u77E5 chiron \u5B50\u547D\u4EE4\u6309\u6700\u9AD8\u98CE\u9669\u5173\u95ED\u3002");
9672
- }
9673
- if (name === "jira") {
9674
- if (["probe", "open", "show", "audit", "search", "status"].includes(subcommand)) {
9675
- return direct("R1", "remote-read", "jira-read");
9676
- }
9677
- if (["comment", "assign", "move", "to-issue", "sync", "verify-pass", "verify-fail", "submit"].includes(subcommand)) {
9678
- return direct("R1", "external-tracker-write", "jira-tracker-write");
9679
- }
9680
- return forbidden("unknown-command", "\u672A\u77E5 jira \u5B50\u547D\u4EE4\u6309\u6700\u9AD8\u98CE\u9669\u5173\u95ED\u3002");
9425
+ return { fields, type, keyTag, summary: gapSummary(g), module: `${module}/${g.module_detail || MODULE_DEFAULT_CHILD[module]}` };
9426
+ }
9427
+ async function gapSubmit({ client: client3 }, g, { fingerprintText: fingerprintText2, issuetypeOverride, assigneeOverride }) {
9428
+ const summary = gapSummary(g);
9429
+ const keyTag = gapKeyTag(g);
9430
+ const open = await client3.search(`project = ${client3.project} AND resolution = Unresolved ORDER BY created DESC`, { max: 100 });
9431
+ const dup = findDuplicateGap(open, summary, keyTag);
9432
+ if (dup) {
9433
+ const body = `\u53C8\u4E00\u4E2A\u73B0\u573A\uFF08${fingerprintText2}\uFF09
9434
+
9435
+ **\u73B0\u8C61**\uFF1A${g.phenomenon}
9436
+
9437
+ **\u590D\u73B0**\uFF1A
9438
+ {code}
9439
+ ${g.repro}
9440
+ {code}
9441
+
9442
+ **\u66FF\u4EE3\u6CD5**\uFF1A${g.alternative}
9443
+ \u4E25\u91CD\u5EA6\uFF1A${g.severity}`;
9444
+ await client3.addComment(dup.key, body);
9445
+ return { outcome: "appended", key: dup.key, url: client3.browseUrl(dup.key), summary: dup.fields.summary ?? "", alternative: g.alternative };
9681
9446
  }
9682
- if (name === "skills") {
9683
- if (subcommand === "list" || subcommand === "show") {
9684
- return direct("R0", "product-discovery", "skill-discovery");
9447
+ const [types, me, project] = await Promise.all([client3.createMeta(), client3.myself(), client3.projectInfo()]);
9448
+ const built = buildGapFields(g, {
9449
+ types,
9450
+ me: me.name ?? me.key ?? "",
9451
+ assignee: assigneeOverride || project.lead?.name || project.lead?.key,
9452
+ project: client3.project,
9453
+ fingerprintText: fingerprintText2,
9454
+ issuetypeOverride
9455
+ });
9456
+ const created = await client3.createIssue(built.fields);
9457
+ return { outcome: "created", key: created.key, url: client3.browseUrl(created.key), summary: built.summary, type: built.type.name, module: built.module, alternative: g.alternative };
9458
+ }
9459
+ async function gapSearch({ client: client3 }, keywords, { includeClosed = true } = {}) {
9460
+ const rows = [];
9461
+ let jiraError;
9462
+ try {
9463
+ for (const kw of keywords) {
9464
+ const safe = kw.replace(/["\\]/g, " ").trim();
9465
+ const jql = `project = ${client3.project} AND text ~ "${safe}"${includeClosed ? "" : " AND resolution = Unresolved"} ORDER BY updated DESC`;
9466
+ for (const i of await client3.search(jql, { max: 15 })) {
9467
+ rows.push({ where: "Jira", id: i.key, title: i.fields.summary ?? "", state: i.fields.status?.name, resolution: i.fields.resolution?.name, url: client3.browseUrl(i.key) });
9468
+ }
9685
9469
  }
9686
- if (subcommand === "sync" || subcommand === "install") {
9687
- return direct("R1", "managed-local-write", "skill-managed-write");
9470
+ if (!rows.length) {
9471
+ const open = await client3.search(`project = ${client3.project} AND resolution = Unresolved ORDER BY created DESC`, { max: 100 });
9472
+ for (const i of open) {
9473
+ if (keywords.some((k) => (i.fields.summary ?? "").includes(k))) {
9474
+ rows.push({ where: "Jira", id: i.key, title: i.fields.summary ?? "", state: i.fields.status?.name, url: client3.browseUrl(i.key) });
9475
+ }
9476
+ }
9688
9477
  }
9689
- return forbidden("unknown-command", "\u672A\u77E5 skills \u5B50\u547D\u4EE4\u6309\u6700\u9AD8\u98CE\u9669\u5173\u95ED\u3002");
9478
+ } catch (e) {
9479
+ jiraError = e.message;
9690
9480
  }
9691
- if (name === "env") {
9692
- if (subcommand === "list" || subcommand === "current" || subcommand === "show") {
9693
- return direct("R0", "local-discovery", "environment-read");
9694
- }
9695
- return forbidden("identity-governance", "\u73AF\u5883\u65B0\u589E\u3001\u5207\u6362\u3001\u7F16\u8F91\u6216\u5220\u9664\u5C5E\u4E8E\u6CBB\u7406\u64CD\u4F5C\u3002");
9481
+ const seen = /* @__PURE__ */ new Set();
9482
+ return { rows: rows.filter((r) => seen.has(r.id) ? false : (seen.add(r.id), true)), jiraError };
9483
+ }
9484
+ async function gapStatus({ client: client3 }, ref, casesSlug = CASES_REPO_SLUG) {
9485
+ const parsed = parseRef(ref, client3.project, casesSlug);
9486
+ if (!parsed) throw new Error(`\u770B\u4E0D\u61C2 ${ref}\uFF1A\u7ED9 Jira \u5355\u53F7\uFF08HCMNX-12\uFF09`);
9487
+ if (parsed.kind === "repo") {
9488
+ throw new Error(
9489
+ `${parsed.repo}#${parsed.number} \u662F\u4EA7\u54C1\u4ED3\u7F16\u53F7\uFF0C\u987E\u95EE\u4FA7\u67E5\u4E0D\u5230\u5B83\u7684\u72B6\u6001\uFF08\u6CA1\u6709\u90A3\u4E2A\u4ED3\u7684\u8BFB\u6743\u9650\uFF09\u3002next_step=\u7528 Jira \u5355\u53F7\u67E5\uFF08HCMNX-12\uFF09\u3002\u4EA7\u54C1\u4FA7\u7684\u8FDB\u5C55\u4F1A\u56DE\u5199\u5230 Jira \u5355\u4E0A\uFF0C\u90A3\u662F\u4EA7\u54C1\u5BF9\u5916\u7684\u7EDF\u4E00\u9762\u3002`
9490
+ );
9696
9491
  }
9697
- if (name === "identity") {
9698
- if (subcommand === "list") return direct("R0", "local-discovery", "identity-read");
9699
- return forbidden("identity-governance", "\u8EAB\u4EFD\u5207\u6362\u6216\u5220\u9664\u5C5E\u4E8E\u6CBB\u7406\u64CD\u4F5C\u3002");
9492
+ const issue = await client3.issue(parsed.key);
9493
+ const cs = await client3.comments(parsed.key);
9494
+ const status = issue.fields.status?.name;
9495
+ const resolution = issue.fields.resolution?.name;
9496
+ const lines = [`Jira ${issue.key} [${status}${resolution ? "\xB7" + resolution : ""}${issue.fields.priority ? " " + issue.fields.priority.name : ""}] ${issue.fields.summary ?? ""}`, ` ${client3.browseUrl(issue.key)}`];
9497
+ const keyComments = cs.filter((c) => /分诊|已转|已修|合入|不做|重复|改技能|产品侧|代码库已关闭/.test(c.body ?? ""));
9498
+ const last = (keyComments.length ? keyComments : cs).at(-1);
9499
+ if (last) lines.push(` \u6700\u65B0\u5904\u7406\uFF08${String(last.created ?? "").slice(0, 10)} ${last.author?.displayName ?? "?"}\uFF09\uFF1A${(last.body ?? "").split("\n").find((l) => l.trim()) ?? ""}`.slice(0, 400));
9500
+ else lines.push(" \u8FD8\u6CA1\u6709\u4EBA\u5904\u7406\uFF08\u4EA7\u54C1\u4FA7\u6BCF\u5468\u6E05\u4E00\u6B21\uFF1B\u963B\u65AD\u7EA7\u8BF7\u5728\u9879\u76EE\u7FA4\u91CC\u70B9\u540D\u8D1F\u8D23\u4EBA\uFF09");
9501
+ const remote = (await client3.remoteLinks(parsed.key)).map((l) => l.object?.url ?? "").join("\n");
9502
+ const links = linkedRepoRefs(`${remote}
9503
+ ${issue.fields.description ?? ""}
9504
+ ${cs.map((c) => c.body ?? "").join("\n")}`).map((l) => ({
9505
+ ...l,
9506
+ url: repoIssueUrl(l.repo, l.number)
9507
+ }));
9508
+ for (const p of links) lines.push(`\u5DF2\u767B\u8BB0\u4EE3\u7801\u5E93\u6761\u76EE ${p.repo}#${p.number}`, ` ${p.url}`);
9509
+ let nextStep;
9510
+ if (resolution) nextStep = "Jira \u8FD9\u5355\u5DF2\u89E3\u51B3\u3002\u76EE\u6807\u73AF\u5883\u90E8\u7F72\u5230\u542B\u4FEE\u590D\u7684\u7248\u672C\u540E\uFF08`hcm version` \u7684 commit \u4F1A\u53D8\uFF09\uFF0C\u8DD1 `hcm skills update`\uFF0C\u518D\u6309\u6280\u80FD\u590D\u9A8C\u4E00\u6B21\u3002";
9511
+ else if (status === "\u5DF2\u4FEE\u590D") nextStep = "\u4FEE\u590D\u5DF2\u5408\u5165\u3001\u8FD8\u6CA1\u53D1\u5230\u4F60\u7684\u73AF\u5883\u3002\u7EE7\u7EED\u7528\u66FF\u4EE3\u6CD5\uFF0C\u53D1\u5E03\u540E\u590D\u9A8C\u3002";
9512
+ else if (links.length) nextStep = "\u5DF2\u5206\u8BCA\u3001\u4EE3\u7801\u5E93\u5DF2\u767B\u8BB0\uFF0C\u8FD8\u5728\u505A\u3002\u7EE7\u7EED\u7528\u66FF\u4EE3\u6CD5\uFF1B\u60F3\u8981\u6392\u671F\u5C31\u5728 Jira \u8FD9\u5355\u4E0B\u7559\u8A00\u3002";
9513
+ else nextStep = `\u7B49\u5206\u8BCA\u3002\u5148\u6309\u66FF\u4EE3\u6CD5\u7EE7\u7EED\u4EA4\u4ED8\uFF0C\u62A5\u544A\u5199 BLOCKED \xB7 \u5DF2\u63D0 ${issue.key}\u3002`;
9514
+ return { ref, lines, nextStep, jira: { key: issue.key, status, resolution, url: client3.browseUrl(issue.key) }, links };
9515
+ }
9516
+
9517
+ // src/commands/gap.ts
9518
+ var defaultDeps = { client: () => createJiraClient() };
9519
+ async function gapDeps(deps) {
9520
+ return { client: await deps.client() };
9521
+ }
9522
+ function emit4(fmt, data, text) {
9523
+ if (fmt === "json" || fmt === "yaml") process.stdout.write(formatObject22(data, { format: fmt }) + "\n");
9524
+ else process.stdout.write(text() + "\n");
9525
+ }
9526
+ async function run(fn) {
9527
+ try {
9528
+ await fn();
9529
+ } catch (e) {
9530
+ exitWithError(e);
9700
9531
  }
9701
- if (name === "query" || name === "describe" || name === "trace") {
9702
- return direct("R1", "remote-read", "business-read");
9532
+ }
9533
+ async function gapSearchCommand(keywords, args, deps = defaultDeps) {
9534
+ await run(async () => {
9535
+ if (!keywords.length) throw new Error("\u7ED9\u81F3\u5C11\u4E00\u4E2A\u5173\u952E\u8BCD\uFF1A\u9519\u8BEF\u7801 / Model / Action / \u4E00\u53E5\u73B0\u8C61");
9536
+ const r = await gapSearch(await gapDeps(deps), keywords, { includeClosed: args.includeClosed !== false });
9537
+ emit4(args.output, r, () => {
9538
+ const head = r.jiraError ? `\u26A0\uFE0F Jira \u6CA1\u67E5\u6210\uFF08${r.jiraError}\uFF09\uFF0C\u4E0B\u9762\u53EA\u6709\u4EA7\u54C1\u4ED3\u7684\u7ED3\u679C\uFF0C\u4E0D\u4EE3\u8868 Jira \u91CC\u6CA1\u6709\u3002
9539
+ ` : "";
9540
+ if (!r.rows.length) return `${head}Jira \u4E0E\u4EA7\u54C1\u4ED3\u90FD\u6CA1\u6709\u76F8\u5173\u8BB0\u5F55\u3002\u53EF\u4EE5 submit\uFF0C\u4F46\u5148\u628A\u4E09\u95EE\u7B54\u5B8C\u3002`;
9541
+ return `${head}\u547D\u4E2D ${r.rows.length} \u6761\uFF08\u540C\u4E00\u7F3A\u53E3\u5DF2\u6709\u7F16\u53F7\u5C31\u5728\u90A3\u6761\u4E0B\u8FFD\u52A0\u73B0\u573A\uFF0C\u4E0D\u65B0\u5F00\uFF09\uFF1A
9542
+ ${r.rows.map((i) => `${i.where} ${i.id} [${i.state}${i.resolution ? "\xB7" + i.resolution : ""}] ${i.title}
9543
+ ${i.url}`).join("\n")}`;
9544
+ });
9545
+ });
9546
+ }
9547
+ async function gapStatusCommand(ref, args, deps = defaultDeps) {
9548
+ await run(async () => {
9549
+ const r = await gapStatus(await gapDeps(deps), ref);
9550
+ emit4(args.output, r, () => [...r.lines, `\u4E0B\u4E00\u6B65\uFF1A${r.nextStep}`].join("\n"));
9551
+ });
9552
+ }
9553
+ async function fingerprintText(env2) {
9554
+ try {
9555
+ const g = await loadGlobalConfig11();
9556
+ const name = resolveActiveEnv5({ envFlag: env2 }, process.env, g);
9557
+ const cfg = await loadEnv11(name);
9558
+ if (!cfg?.endpoint) return `\u672A\u53D6\u5230\u6307\u7EB9\uFF08env=${name}\uFF1A\u6CA1\u6709 endpoint\uFF09`;
9559
+ const http = createHttpClient4({ endpoint: cfg.endpoint.replace(/\/+$/, ""), getAccessToken: async () => null, onRefresh: async () => {
9560
+ } });
9561
+ const resp = await http.get("/api/version/backend");
9562
+ const info = resp.data?.data ?? resp.data ?? {};
9563
+ const commit = info.commit ?? info.gitCommit ?? info.version ?? "?";
9564
+ return `backend ${String(commit).slice(0, 12)} \xB7 CLI ${CLI_VERSION} \xB7 env ${name}`;
9565
+ } catch (e) {
9566
+ return `\u672A\u53D6\u5230\u6307\u7EB9\uFF08env=${env2 ?? "\u672A\u8BBE"}\uFF1B${String(e.message ?? e).split("\n")[0]?.slice(0, 120)}\uFF09`;
9703
9567
  }
9704
- if (name === "cache") {
9705
- if (subcommand === "stats") return direct("R1", "remote-read", "cache-read");
9706
- if (subcommand === "clear" || subcommand === "clear-meta") {
9707
- return guarded("operational-write", "cache-mutation");
9708
- }
9568
+ }
9569
+ async function gapSubmitCommand(args, deps = defaultDeps) {
9570
+ await run(async () => {
9571
+ const raw = args.file ? readFileSync5(args.file, "utf8") : process.stdin.isTTY ? "" : readFileSync5(0, "utf8");
9572
+ if (!raw.trim()) throw new Error("\u7F3A\u53E3\u8F7D\u8377\uFF1A--file <gap.json> \u6216\u4ECE\u6807\u51C6\u8F93\u5165\u5582 JSON");
9573
+ const gap2 = validateGapInput(JSON.parse(raw));
9574
+ const fp = args.fingerprint ?? await fingerprintText(args.env);
9575
+ const r = await gapSubmit(await gapDeps(deps), gap2, { fingerprintText: fp, issuetypeOverride: args.issuetype, assigneeOverride: args.assignee });
9576
+ emit4(
9577
+ args.output,
9578
+ r,
9579
+ () => r.outcome === "appended" ? `Jira \u91CC\u5DF2\u6709\u540C\u4E00\u7F3A\u53E3 ${r.key}\u300C${r.summary}\u300D\uFF0C\u5DF2\u8FFD\u52A0\u300C\u53C8\u4E00\u4E2A\u73B0\u573A\u300D\u8BC4\u8BBA\uFF0C\u6CA1\u6709\u65B0\u5F00\u3002
9580
+ ${r.url}
9581
+ \u7ED9\u987E\u95EE\u7684\u8BDD\uFF1A\u8FD9\u4E2A\u95EE\u9898\u5DF2\u7ECF\u5728\u4EA7\u54C1\u90A3\u8FB9\u6392\u7740\uFF0C\u7F16\u53F7 ${r.key}\uFF1B\u5148\u7528\u66FF\u4EE3\u6CD5\u300C${r.alternative}\u300D\u7EE7\u7EED\uFF0C\u5206\u8BCA\u7ED3\u8BBA\u4F1A\u56DE\u5230\u90A3\u5355\u91CC\u3002` : `\u5DF2\u63D0 ${r.key}\uFF08${r.type} \xB7 ${r.module}\uFF09\uFF1A${r.url}
9582
+ \u7ED9\u987E\u95EE\u7684\u8BDD\uFF1A\u7F3A\u53E3\u5DF2\u63D0\uFF0C\u7F16\u53F7 ${r.key}\uFF1B\u5148\u7528\u66FF\u4EE3\u6CD5\u300C${r.alternative}\u300D\u7EE7\u7EED\uFF0C\u4EA7\u54C1\u5206\u8BCA\u540E\u4F1A\u5728\u90A3\u5355\u91CC\u56DE\u590D\u3002\u62A5\u544A\u91CC\u5199\u300CBLOCKED \xB7 \u5DF2\u63D0 ${r.key} \xB7 \u66FF\u4EE3\u6CD5\uFF1A${r.alternative}\u300D\u3002`
9583
+ );
9584
+ });
9585
+ }
9586
+
9587
+ // src/commands/chiron-case.ts
9588
+ init_exit();
9589
+ import { execFileSync } from "child_process";
9590
+ import { existsSync as existsSync2, readFileSync as readFileSync6, cpSync, writeFileSync as writeFileSync2, mkdirSync } from "fs";
9591
+ import os5 from "os";
9592
+ import path9 from "path";
9593
+ import { CASES_REPO_SLUG as CASES_REPO_SLUG2, CNB_ORIGIN, CliError as CliError23, CliErrorCode as CliErrorCode22, formatObject as formatObject23 } from "@hcmai/sdk";
9594
+ var casesRepoDir = () => process.env.HCM_CASES_DIR?.trim() || path9.join(os5.homedir(), "Projects", "chiron-cases");
9595
+ var fail7 = (message, nextStep) => new CliError23({ code: CliErrorCode22.INVALID_ARGUMENT, message, context: { nextStep } });
9596
+ var run2 = (cmd, args, opts = {}) => execFileSync(cmd, args, { encoding: "utf8", maxBuffer: 1 << 26, ...opts });
9597
+ function loadIndex(dir = casesRepoDir()) {
9598
+ const file = path9.join(dir, "index", "index.json");
9599
+ if (!existsSync2(file)) {
9600
+ throw fail7(
9601
+ `\u6848\u4F8B\u5E93\u7D22\u5F15\u4E0D\u5728\uFF1A${file}`,
9602
+ `\u5148 clone \u6848\u4F8B\u5E93\uFF08\`hcm chiron doctor --fix\` \u4F1A\u505A\uFF09\uFF0C\u6216\u7528 HCM_CASES_DIR \u6307\u5230\u5DF2\u6709\u7684 clone\u3002\u6CA1\u6709 cnb \u6743\u9650\u5C31\u8DF3\u8FC7\u6848\u4F8B\u5E93\u8FD9\u4E00\u683C\u3002`
9603
+ );
9709
9604
  }
9710
- if (name === "meta") {
9711
- if (subcommand === "list" || subcommand === "get") {
9712
- return direct("R1", "remote-read", "metadata-read");
9713
- }
9714
- if (subcommand === "set" && hasFlag(argv, "--dry-run")) {
9715
- return direct("R1", "local-validation", "metadata-dry-run");
9716
- }
9717
- if (subcommand === "set") return guarded("tenant-config-write", "metadata-write");
9718
- if (subcommand === "delete") return forbidden("destructive", "\u5143\u6570\u636E\u5220\u9664\u4E0D\u53EF\u7531\u987E\u95EE\u63D2\u4EF6\u6267\u884C\u3002");
9605
+ return JSON.parse(readFileSync6(file, "utf8"));
9606
+ }
9607
+ function backendFingerprint(env2) {
9608
+ if (!env2) return { reason: "\u6CA1\u7ED9 --env\uFF0C\u6CA1\u6CD5\u73B0\u67E5\u6307\u7EB9" };
9609
+ try {
9610
+ const raw = run2(process.execPath, [process.argv[1], "version", "--env", env2, "--output", "json"]);
9611
+ const j = JSON.parse(raw.slice(raw.indexOf("{")));
9612
+ const backend = j.backend?.commit ?? j.commit ?? j.server?.commit;
9613
+ if (!backend) return { reason: "\u540E\u7AEF\u56DE\u6267\u91CC\u6CA1\u6709 commit \u5B57\u6BB5" };
9614
+ return { backend: String(backend), cli: String(j.cli?.version ?? j.cliVersion ?? "") };
9615
+ } catch (e) {
9616
+ return { reason: String(e.message).split("\n")[0]?.slice(0, 120) };
9719
9617
  }
9720
- if (name === "setting") {
9721
- if (subcommand === "get") return direct("R1", "remote-read", "setting-read");
9722
- if (subcommand === "set" && hasFlag(argv, "--dry-run")) {
9723
- return direct("R1", "local-validation", "setting-dry-run");
9724
- }
9725
- if (subcommand === "set" || subcommand === "reset") {
9726
- return guarded("tenant-config-write", "setting-write");
9727
- }
9618
+ }
9619
+ function matchTag(c, fp) {
9620
+ if (!fp.backend) return `\u672A\u6BD4\u5BF9\uFF08${fp.reason ?? "\u6CA1\u6709\u6307\u7EB9"}\uFF09`;
9621
+ const be = String(c.fingerprint?.backend_commit ?? "");
9622
+ if (!be) return "\u6848\u4F8B\u6CA1\u8BB0\u540E\u7AEF\u6307\u7EB9";
9623
+ const a = be.slice(0, 12);
9624
+ const b = fp.backend.slice(0, 12);
9625
+ return a === b ? "\u5339\u914D" : `\u4E0D\u5339\u914D\uFF08\u6848\u4F8B ${a} / \u5F53\u524D ${b}\uFF09`;
9626
+ }
9627
+ function emit5(args, data, text) {
9628
+ if (args.output === "json" || args.output === "yaml") {
9629
+ process.stdout.write(formatObject23(data, { format: args.output }) + "\n");
9630
+ } else {
9631
+ process.stdout.write(text() + "\n");
9728
9632
  }
9729
- if (name === "workspace") {
9730
- if (subcommand === "push" && hasFlag(argv, "--dry-run")) {
9731
- return direct("R1", "remote-read", "workspace-push-dry-run");
9732
- }
9733
- if (["list", "active", "status", "validate", "verify", "preview"].includes(subcommand)) {
9734
- return direct("R1", "remote-read", "workspace-read");
9735
- }
9736
- if (subcommand === "pull") {
9737
- return direct("R1", "managed-local-write", "workspace-pull");
9738
- }
9739
- if (subcommand === "bind" || subcommand === "add" && argv[2] === "mini") {
9740
- return guarded("managed-local-write", "workspace-local-change");
9741
- }
9742
- if (subcommand === "rm") return guarded("managed-local-write", "workspace-local-change");
9743
- if (subcommand === "create") return guarded("tenant-write", "workspace-create");
9744
- if (subcommand === "activate") return guarded("tenant-write", "workspace-activate");
9745
- if (subcommand === "deactivate") return guarded("tenant-write", "workspace-deactivate");
9746
- if (subcommand === "push") return guarded("tenant-write", "workspace-push");
9747
- if (["deploy", "release", "promote", "publish"].includes(subcommand)) {
9748
- return forbidden("publish", "\u90E8\u7F72\u5230 active \u5C5E\u4E8E R3\uFF0C\u987B\u8D70\u53D1\u5E03\u4E0E\u5BA1\u6279\u94FE\u8DEF\u3002");
9749
- }
9633
+ }
9634
+ async function guard(fn) {
9635
+ try {
9636
+ await fn();
9637
+ } catch (e) {
9638
+ exitWithError(e);
9750
9639
  }
9751
- if (name === "script") {
9752
- if (["dry-run", "manifest-validate", "logs", "task"].includes(subcommand)) {
9753
- return direct("R1", "remote-read", "script-" + subcommand);
9640
+ }
9641
+ async function caseSearchCommand(query, args) {
9642
+ await guard(async () => {
9643
+ const idx = loadIndex();
9644
+ const fp = backendFingerprint(args.env);
9645
+ let raw;
9646
+ try {
9647
+ raw = run2("cnb", [
9648
+ "knowledge-base",
9649
+ "query-knowledge-base-get",
9650
+ "--repo",
9651
+ CASES_REPO_SLUG2,
9652
+ "--query",
9653
+ query,
9654
+ "--top-k",
9655
+ String(args.topK ?? 5),
9656
+ "--verbose"
9657
+ ]);
9658
+ } catch (e) {
9659
+ throw fail7(
9660
+ `\u6848\u4F8B\u5E93\u68C0\u7D22\u6CA1\u8DD1\u6210\uFF1A${String(e.message).split("\n")[0]}`,
9661
+ "\u68C0\u7D22\u8D70 cnb \u7684\u77E5\u8BC6\u5E93\u63A5\u53E3\uFF0C\u9700\u8981 cnb \u5DF2\u767B\u5F55\u4E14\u6709\u6848\u4F8B\u5E93\u6743\u9650\u3002\u6CA1\u6709\u5C31\u5148\u8DF3\u8FC7\u6848\u4F8B\u5E93\uFF0C\u76F4\u63A5\u6309\u6280\u80FD\u505A\uFF1B\u522B\u628A\u300C\u67E5\u4E0D\u5230\u300D\u5F53\u6210\u300C\u6CA1\u6709\u5148\u4F8B\u300D\u3002"
9662
+ );
9754
9663
  }
9755
- }
9756
- if (name === "import") {
9757
- if (hasFlag(argv, "--dry-run")) {
9758
- return direct("R1", "local-validation", "import-dry-run");
9664
+ const json = JSON.parse(raw.slice(raw.indexOf("{")));
9665
+ const seen = /* @__PURE__ */ new Map();
9666
+ for (const h of json.data ?? []) {
9667
+ const p = h.metadata?.path ?? "";
9668
+ const m = /^cases\/[^/]+\/([^/]+)\//.exec(p);
9669
+ if (!m) continue;
9670
+ const id = m[1];
9671
+ if (seen.has(id)) continue;
9672
+ const c = idx.cases.find((x) => x.id === id);
9673
+ seen.set(id, {
9674
+ id,
9675
+ score: h.score,
9676
+ file: p.split("/").pop(),
9677
+ status: c?.status,
9678
+ tier: c?.tier,
9679
+ skills: c?.skills,
9680
+ customer_ask: c?.customer_ask,
9681
+ match: c ? matchTag(c, fp) : "\u7D22\u5F15\u91CC\u6CA1\u6709\uFF08\u672C\u673A clone \u53EF\u80FD\u65E7\u4E86\uFF0Cgit pull \u4E00\u6B21\uFF09"
9682
+ });
9759
9683
  }
9760
- return guarded("bulk-tenant-write", "import-write");
9761
- }
9762
- if (name === "create" || name === "update") {
9763
- return guarded("tenant-write", name === "create" ? "record-create" : "record-update");
9764
- }
9765
- if (name === "upload") return guarded("tenant-write", "document-upload");
9766
- if (name === "download") return direct("R1", "managed-local-write", "document-download");
9767
- if (name === "action") {
9768
- if (actionResolution?.status === "resolved") {
9769
- return classifyAction(actionResolution.policy);
9684
+ const rows = [...seen.values()];
9685
+ emit5(
9686
+ args,
9687
+ { query, rows },
9688
+ () => rows.length ? rows.map((r) => `${r.id} [${r.status ?? "?"}\xB7${r.match}] ${r.customer_ask ?? ""}
9689
+ \u6280\u80FD\uFF1A${(r.skills ?? []).join(" / ") || "\uFF08\u672A\u767B\u8BB0\uFF09"}`).join("\n") : `\u6CA1\u6709\u547D\u4E2D\u300C${query}\u300D\u7684\u6848\u4F8B\u3002\u5148\u6309\u6280\u80FD\u505A\uFF0C\u8DD1\u901A\u4E86\u7528 \`hcm chiron case submit\` \u4E0A\u884C\u4E00\u6761\u3002`
9690
+ );
9691
+ });
9692
+ }
9693
+ async function caseShowCommand(id, args) {
9694
+ await guard(async () => {
9695
+ const idx = loadIndex();
9696
+ const c = idx.cases.find((x) => x.id === id);
9697
+ if (!c?.path) {
9698
+ throw fail7(
9699
+ `\u7D22\u5F15\u91CC\u6CA1\u6709\u6848\u4F8B ${id}`,
9700
+ `\u5148 \`hcm chiron case search <\u5173\u952E\u8BCD>\` \u62FF\u51C6\u786E\u7684 id\uFF1B\u672C\u673A clone \u65E7\u4E86\u5C31\u5728 ${casesRepoDir()} \u91CC git pull \u4E00\u6B21\u3002`
9701
+ );
9770
9702
  }
9771
- if (actionResolution?.status === "failed") {
9772
- return forbidden(actionResolution.reasonCode, actionResolution.reason);
9703
+ const dir = path9.join(casesRepoDir(), c.path);
9704
+ const files = args.file ? [args.file] : ["\u95EE\u9898.md", "\u65B9\u6848.md"];
9705
+ const parts = files.map((f) => {
9706
+ const p = path9.join(dir, f);
9707
+ return existsSync2(p) ? `# ${f}
9708
+
9709
+ ${readFileSync6(p, "utf8")}` : `# ${f}
9710
+
9711
+ \uFF08\u8FD9\u4E2A\u6848\u4F8B\u6CA1\u6709\u8FD9\u4EFD\u6587\u4EF6\uFF09`;
9712
+ });
9713
+ const meta2 = readFileSync6(path9.join(dir, "case.yml"), "utf8");
9714
+ emit5(args, { id, caseYml: meta2, files: parts }, () => `case.yml:
9715
+ ${meta2}
9716
+
9717
+ ${parts.join("\n\n---\n\n")}`);
9718
+ });
9719
+ }
9720
+ async function caseMatchCommand(args) {
9721
+ await guard(async () => {
9722
+ const idx = loadIndex();
9723
+ const fp = backendFingerprint(args.env);
9724
+ const rows = idx.cases.filter((c) => c.status === "approved").map((c) => ({ id: c.id, match: matchTag(c, fp), skills: c.skills, customer_ask: c.customer_ask }));
9725
+ emit5(args, { fingerprint: fp, rows }, () => {
9726
+ const head = fp.backend ? `\u5F53\u524D\u540E\u7AEF ${fp.backend.slice(0, 12)}\uFF08env ${args.env}\uFF09` : `\u26A0\uFE0F \u6CA1\u53D6\u5230\u5F53\u524D\u6307\u7EB9\uFF08${fp.reason}\uFF09\u2014\u2014\u4E0B\u9762\u6BCF\u4E00\u6761\u90FD\u6807\u7740\u300C\u672A\u6BD4\u5BF9\u300D\uFF0C\u522B\u628A\u5B83\u8BFB\u6210\u300C\u90FD\u80FD\u7167\u505A\u300D`;
9727
+ return [head, ...rows.map((r) => `${r.match === "\u5339\u914D" ? "\u2705" : "\xB7 "} ${r.id} [${r.match}] ${r.customer_ask ?? ""}`)].join("\n");
9728
+ });
9729
+ });
9730
+ }
9731
+ async function caseSubmitCommand(dir, args) {
9732
+ await guard(async () => {
9733
+ const repo = casesRepoDir();
9734
+ const src = path9.resolve(dir);
9735
+ if (!existsSync2(path9.join(src, "case.yml"))) {
9736
+ throw fail7(`${src} \u91CC\u6CA1\u6709 case.yml`, "\u6307\u5230\u9879\u76EE\u4ED3\u7684\u6848\u4F8B\u76EE\u5F55\uFF08\u5982 cases/CASE-20260902-xxx\uFF09\uFF0C\u90A3\u91CC\u5E94\u5F53\u6709 case.yml\u3002");
9737
+ }
9738
+ loadIndex(repo);
9739
+ const yamlText = readFileSync6(path9.join(src, "case.yml"), "utf8");
9740
+ const id = /^\s*(?:id|case_id):\s*(\S+)/m.exec(yamlText)?.[1];
9741
+ if (!id) throw fail7("case.yml \u91CC\u6CA1\u6709 id", "case.yml \u9876\u5C42\u8981\u6709 `id: CASE-YYYYMMDD-xxx`\u3002");
9742
+ run2("git", ["-C", repo, "checkout", "-q", "main"]);
9743
+ run2("git", ["-C", repo, "pull", "-q", "--ff-only", "origin", "main"]);
9744
+ const branch = `case/${id}-submit`;
9745
+ run2("git", ["-C", repo, "checkout", "-q", "-B", branch]);
9746
+ const dst = path9.join(repo, "cases", args.category, id);
9747
+ cpSync(src, dst, { recursive: true, filter: (p) => !p.includes("node_modules") });
9748
+ mkdirSync(path9.join(dst, "evidence"), { recursive: true });
9749
+ let doc = readFileSync6(path9.join(dst, "case.yml"), "utf8");
9750
+ doc = /^\s*tier:/m.test(doc) ? doc.replace(/^\s*tier:.*$/m, "tier: public") : `tier: public
9751
+ ${doc}`;
9752
+ doc = /^\s*category:/m.test(doc) ? doc.replace(/^\s*category:.*$/m, `category: ${args.category}`) : `category: ${args.category}
9753
+ ${doc}`;
9754
+ doc = /^\s*origin:/m.test(doc) ? doc.replace(/^\s*origin:.*$/m, `origin: ${args.origin}`) : `origin: ${args.origin}
9755
+ ${doc}`;
9756
+ if (!/^\s*status:/m.test(doc)) doc = `status: approved
9757
+ ${doc}`;
9758
+ writeFileSync2(path9.join(dst, "case.yml"), doc);
9759
+ run2("python3", ["scripts/render-readme.py", dst], { cwd: repo });
9760
+ let lint;
9761
+ try {
9762
+ lint = run2("python3", ["scripts/lint-case.py"], { cwd: repo });
9763
+ } catch (e) {
9764
+ throw fail7(
9765
+ `\u6848\u4F8B lint \u6CA1\u8FC7\uFF0CPR \u6CA1\u5F00\uFF1A
9766
+ ${e.stdout ?? e.message}`,
9767
+ "\u7167 lint \u7684\u63D0\u793A\u8865\u9F50 case.yml \u4E0E\u6B63\u6587\uFF0C\u518D\u8DD1\u4E00\u6B21\u3002\u6848\u4F8B\u8FD8\u5728\u9879\u76EE\u4ED3\u91CC\uFF0C\u6CA1\u4E22\u3002"
9768
+ );
9773
9769
  }
9774
- return forbidden(
9775
- "action-effect-unclassified",
9776
- "\u5C1A\u672A\u8BFB\u53D6 Core Action \u98CE\u63A7\u58F0\u660E\uFF0C\u4E0D\u80FD\u6309\u540D\u79F0\u731C\u6D4B\u540E\u653E\u884C\u3002"
9770
+ run2("python3", ["scripts/build-index.py"], { cwd: repo });
9771
+ run2("git", ["-C", repo, "add", "-A"]);
9772
+ run2("git", ["-C", repo, "-c", "user.name=hcm-cli", "-c", "user.email=chiron@local", "commit", "-q", "-m", `case: ${id}\uFF08\u9879\u76EE\u6848\u4F8B\u4E0A\u884C\uFF09`]);
9773
+ run2("git", ["-C", repo, "push", "-q", "-f", "-u", "origin", branch]);
9774
+ const pr = run2("cnb", [
9775
+ "pulls",
9776
+ "post-pull",
9777
+ "--repo",
9778
+ CASES_REPO_SLUG2,
9779
+ "--base",
9780
+ "main",
9781
+ "--head",
9782
+ branch,
9783
+ "--title",
9784
+ `case: ${id}\uFF08\u9879\u76EE\u6848\u4F8B\u4E0A\u884C\uFF09`,
9785
+ "--body",
9786
+ `\u6765\u6E90\uFF1A${args.origin}
9787
+
9788
+ \u7531 \`hcm chiron case submit\` \u63D0\u4EA4\uFF0Clint \u5DF2\u8FC7\u3002`
9789
+ ]);
9790
+ const num = /number: "?(\d+)/.exec(pr)?.[1];
9791
+ emit5(
9792
+ args,
9793
+ { id, pr: num, lint: lint.trim() },
9794
+ () => `\u5DF2\u5F00 PR #${num ?? "?"}\uFF1A${CNB_ORIGIN}/${CASES_REPO_SLUG2}/-/pulls/${num ?? ""}
9795
+ ${lint.trim()}`
9777
9796
  );
9778
- }
9779
- if (name === "delete" || name === "meta" && subcommand === "delete") {
9780
- return forbidden("destructive", "\u5220\u9664\u64CD\u4F5C\u4E0D\u8FDB\u5165\u987E\u95EE\u63D2\u4EF6\u6267\u884C\u9762\u3002");
9781
- }
9782
- if (name === "tenant") {
9783
- return forbidden("tenant-governance", "\u79DF\u6237\u5F00\u901A\u6216\u6CBB\u7406\u5FC5\u987B\u5347\u7EA7\u6CBB\u7406\u4EBA\u5458\u3002");
9784
- }
9785
- if (name === "login" || name === "logout") {
9786
- return forbidden("identity-governance", "\u767B\u5F55\u4E0E\u767B\u51FA\u5C5E\u4E8E\u8EAB\u4EFD\u6CBB\u7406\u64CD\u4F5C\u3002");
9787
- }
9788
- if (name === "chat") {
9789
- return forbidden("agent-autonomy", "\u987E\u95EE\u63D2\u4EF6\u4E0D\u901A\u8FC7\u5D4C\u5957\u6570\u5B57\u5458\u5DE5\u5BF9\u8BDD\u6269\u5927\u81EA\u6CBB\u6267\u884C\u9762\u3002");
9790
- }
9791
- return forbidden(
9792
- "unknown-command",
9793
- `\u672A\u77E5\u547D\u4EE4\u6309\u6700\u9AD8\u98CE\u9669\u5173\u95ED\uFF1A\u89E3\u6790\u5230\u7684\u547D\u4EE4\u662F ${name || "(\u7A7A)"}` + (subcommand ? ` ${subcommand}` : "") + "\u3002next_step=\u7528 `hcm --help` \u6838\u5BF9\u547D\u4EE4\u540D\uFF1B\u82E5\u4F60\u786E\u4FE1\u8FD9\u6761\u547D\u4EE4\u5B58\u5728\uFF0C\u5148\u8DD1 `hcm upgrade` \u770B CLI \u662F\u4E0D\u662F\u65E7\u7248\uFF08\u98CE\u63A7\u8868\u968F CLI \u53D1\u5E03\u66F4\u65B0\uFF09"
9794
- );
9797
+ });
9795
9798
  }
9796
- function summarizeTarget(argv, actionResolution) {
9797
- const name = argv[0] ?? "";
9798
- const subcommand = argv[1] ?? "";
9799
- const target = {};
9800
- if (["query", "describe", "create", "update", "delete"].includes(name) && subcommand) {
9801
- target.model = subcommand;
9802
- }
9803
- if (name === "action" && subcommand) {
9804
- target.action = subcommand;
9805
- if (actionResolution?.status === "resolved") {
9806
- target.actionPolicy = { ...actionResolution.policy };
9807
- }
9808
- }
9809
- if (name === "skills" && argv[2] && !argv[2].startsWith("-")) target.skill = argv[2];
9810
- if (name === "meta" && argv[2] && !argv[2].startsWith("-")) target.path = argv[2];
9811
- if (name === "cache" && argv[2] && !argv[2].startsWith("-")) {
9812
- target.cacheOperation = subcommand;
9813
- target.model = argv[2];
9814
- }
9815
- if (name === "setting" && argv[2] && !argv[2].startsWith("-")) {
9816
- target.domain = argv[2];
9817
- const settingKeys = valuesAfterFlag(argv, "--set").map((assignment) => assignment.split("=", 1)[0]).filter((key2) => Boolean(key2)).sort();
9818
- if (settingKeys.length > 0) target.settingKeys = settingKeys;
9799
+
9800
+ // src/commands/chiron-doctor.ts
9801
+ init_auth_guard();
9802
+ init_exit();
9803
+ import { promises as fs10 } from "fs";
9804
+ import path10 from "path";
9805
+ import {
9806
+ HcmClient as HcmClient21,
9807
+ CliError as CliError24,
9808
+ fetchReconIdentity as fetchReconIdentity2,
9809
+ formatObject as formatObject24,
9810
+ httpProbe as httpProbe2,
9811
+ runDoctor
9812
+ } from "@hcmai/sdk";
9813
+ var defaultDeps2 = {
9814
+ anchors: async (envName, tenant2, as) => {
9815
+ const ctx = await getActiveAuthContextFromCli({ env: envName, as });
9816
+ const client3 = HcmClient21.fromAuthContext(ctx);
9817
+ const probe = httpProbe2(client3.raw(), "default");
9818
+ const identity2 = await fetchReconIdentity2(probe, tenant2);
9819
+ return { report: await runDoctor(probe, identity2), tokenTenant: identity2?.tenantId ? String(identity2.tenantId) : void 0 };
9820
+ },
9821
+ fixSkills: (root, envName) => defaultChironInitDeps.installSkills(root, envName),
9822
+ fixCases: async () => {
9823
+ await ensureCaseLibrary();
9824
+ },
9825
+ inspectCases: () => inspectCaseLibrary(),
9826
+ inspectJira: () => inspectJira()
9827
+ };
9828
+ async function runChironDoctor(args, deps = defaultDeps2) {
9829
+ const root = path10.resolve(args.project ?? ".");
9830
+ const report = { ok: false, project: root, env: null, envName: null, lines: [] };
9831
+ const envText = await fs10.readFile(path10.join(root, ENV_FILE), "utf8").catch(() => null);
9832
+ if (envText === null) {
9833
+ report.lines.push({
9834
+ item: "\u767B\u5F55",
9835
+ verdict: "fail",
9836
+ detail: `\u8FD9\u4E2A\u76EE\u5F55\u91CC\u6CA1\u6709 ${ENV_FILE}\uFF0C\u4E0D\u662F\u777F\u620E\u9879\u76EE\u4ED3\uFF08\u6216\u8FD8\u6CA1\u521D\u59CB\u5316\uFF09`,
9837
+ nextStep: "\u65B0\u4ED3\uFF1Ahcm login <\u5730\u5740> --code <\u914D\u5BF9\u7801> \u540E hcm chiron init\uFF1B\u5DF2\u6709\u4ED3\uFF1A\u786E\u8BA4 clone \u7684\u662F\u5BF9\u7684\u4ED3\u3001\u7AD9\u5728\u4ED3\u6839\u76EE\u5F55"
9838
+ });
9839
+ return finish(report);
9819
9840
  }
9820
- const id = flagValue(argv, "--id");
9821
- if (name === "user" && subcommand === "reset-password") {
9822
- if (id) target.userIdSha256 = sha2564(id);
9823
- const username = flagValue(argv, "--username");
9824
- if (username) target.usernameSha256 = sha2564(username);
9825
- target.forceChangeOnNextLogin = !hasFlag(argv, "--no-force-change");
9826
- } else if (id) {
9827
- target.recordIdSha256 = sha2564(id);
9841
+ let env2;
9842
+ try {
9843
+ env2 = parseEnvYaml(envText);
9844
+ } catch (e) {
9845
+ report.lines.push({ item: "\u767B\u5F55", verdict: "fail", detail: e.message, nextStep: `\u6309 hcm chiron init \u751F\u6210\u7684\u4E09\u884C\u5F62\u6001\u4FEE ${ENV_FILE}` });
9846
+ return finish(report);
9828
9847
  }
9829
- for (const flag of PAYLOAD_FLAGS) {
9830
- const raw = flagValue(argv, flag);
9831
- if (!raw) continue;
9832
- target.payloadSha256 = sha2564(raw);
9848
+ report.env = env2;
9849
+ const found = await findEnvByEndpoint(env2.endpoint, env2.tenant);
9850
+ const loginCmd = `hcm login ${env2.endpoint} --code <\u914D\u5BF9\u7801>`;
9851
+ if (!found) {
9852
+ report.lines.push({ item: "\u767B\u5F55", verdict: "fail", detail: `\u672C\u673A\u6CA1\u6709\u767B\u5F55\u8FC7 ${env2.endpoint}`, nextStep: loginCmd });
9853
+ } else {
9854
+ report.envName = found.name;
9833
9855
  try {
9834
- const parsed = JSON.parse(raw);
9835
- if (isPlainObject(parsed)) target.fieldNames = Object.keys(parsed).sort();
9836
- } catch {
9856
+ const targetEnv = args.env ?? found.name;
9857
+ const { report: anchors, tokenTenant } = await deps.anchors(targetEnv, env2.tenant, args.as);
9858
+ report.anchors = anchors;
9859
+ const tenantMismatch = tokenTenant && tokenTenant !== env2.tenant;
9860
+ const bad = anchors.checks.filter((c) => !c.ok && !(tenantMismatch && c.anchor === "identity"));
9861
+ if (bad.length === 0 && !tenantMismatch) {
9862
+ const who = found.config.defaultIdentity ? ` \xB7 ${found.config.defaultIdentity}` : "";
9863
+ report.lines.push({ item: "\u767B\u5F55", verdict: "ok", detail: `${found.name} \xB7 ${env2.endpoint} \xB7 \u79DF\u6237 ${env2.tenant}${who}` });
9864
+ } else {
9865
+ const parts = [`${found.name} \xB7 ${env2.endpoint}`];
9866
+ if (tenantMismatch) parts.push(`\u4F60\u7684\u767B\u5F55\u8EAB\u4EFD\u5C5E\u4E8E\u79DF\u6237 ${tokenTenant}\uFF0C\u9879\u76EE\u662F\u79DF\u6237 ${env2.tenant}`);
9867
+ if (bad.length) parts.push(`\u951A\u70B9\u672A\u8FC7\uFF1A${bad.map((c) => `${c.anchor}\uFF08${c.detail}\uFF09`).join("\u3001")}`);
9868
+ report.lines.push({
9869
+ item: "\u767B\u5F55",
9870
+ verdict: "fail",
9871
+ detail: parts.join("\uFF1B"),
9872
+ nextStep: tenantMismatch ? `${loginCmd}\uFF08\u7528\u9879\u76EE\u79DF\u6237\u7684\u914D\u5BF9\u7801\uFF09` : "\u6309\u4E0A\u9762\u951A\u70B9\u7684\u63D0\u793A\u5904\u7406\uFF1B\u8EAB\u4EFD\u8FC7\u671F\u5C31\u91CD\u65B0 " + loginCmd
9873
+ });
9874
+ }
9875
+ } catch (e) {
9876
+ const msg = e instanceof CliError24 ? e.message : e.message;
9877
+ report.lines.push({ item: "\u767B\u5F55", verdict: "fail", detail: `${found.name} \xB7 ${env2.endpoint}\uFF1A${msg}`, nextStep: loginCmd });
9878
+ }
9879
+ }
9880
+ const skillsLine = async () => {
9881
+ const state = await readSkillsState(path10.join(root, SKILLS_DIR));
9882
+ if (!state) return { item: "\u6280\u80FD", verdict: "fail", detail: `${SKILLS_DIR}/ \u91CC\u6CA1\u6709\u5B89\u88C5\u6E05\u5355`, nextStep: "hcm chiron doctor --fix\uFF08\u6216 hcm chiron init\uFF09" };
9883
+ const count = Object.keys(state.skills).length;
9884
+ if (state.endpoint && normalizeOrigin(state.endpoint) !== env2.endpoint) {
9885
+ return { item: "\u6280\u80FD", verdict: "fail", detail: `${count} \u4E2A\uFF0C\u4F46\u88C5\u81EA ${state.endpoint}\uFF0C\u4E0D\u662F\u9879\u76EE\u73AF\u5883 ${env2.endpoint}`, nextStep: "hcm chiron doctor --fix \u91CD\u88C5" };
9886
+ }
9887
+ if (state.target !== "codex") {
9888
+ return { item: "\u6280\u80FD", verdict: "warn", detail: `${count} \u4E2A\uFF0C\u5E03\u5C40\u662F ${state.target}\uFF08Codex \u8981\u8BFB AGENTS.md \u7D22\u5F15\uFF09`, nextStep: "hcm skills install --all --target codex" };
9837
9889
  }
9890
+ return { item: "\u6280\u80FD", verdict: "ok", detail: `${count} \u4E2A\uFF0C\u6765\u81EA ${state.endpoint ?? "\u672C\u5730"}${state.all ? "\uFF0C\u8DDF\u968F\u5168\u96C6" : ""}` };
9891
+ };
9892
+ let skills2 = await skillsLine();
9893
+ if (skills2.verdict === "fail" && args.fix && report.envName) {
9894
+ await deps.fixSkills(root, report.envName);
9895
+ skills2 = await skillsLine();
9838
9896
  }
9839
- return target;
9897
+ report.lines.push(skills2);
9898
+ const casesLine = async () => {
9899
+ const c = await deps.inspectCases();
9900
+ if (!c.cloned) return { item: "\u6848\u4F8B\u5E93", verdict: "warn", detail: `\u672A clone\uFF08${c.repo}\uFF09`, nextStep: "hcm chiron doctor --fix\uFF1B\u6CA1\u6709 cnb \u6743\u9650\u5C31\u5148\u8DF3\u8FC7\uFF0C\u63D0\u4EA4\u6848\u4F8B/\u7F3A\u53E3\u65F6\u4F1A\u63D0\u793A" };
9901
+ if (!c.indexed) return { item: "\u6848\u4F8B\u5E93", verdict: "warn", detail: `clone \u4E86\u4F46\u6CA1\u6709\u7D22\u5F15\uFF08${c.repo}/index/index.json\uFF09`, nextStep: `\u5230 ${c.repo} \u91CC git pull \u4E00\u6B21\uFF1B\u4ECD\u7136\u6CA1\u6709\u5C31\u662F clone \u534A\u622A\u4E86\uFF0C\u5220\u6389\u91CD\u6765\u3002` };
9902
+ return { item: "\u6848\u4F8B\u5E93", verdict: "ok", detail: `\u5DF2\u63A5\u5165 Codex\uFF08${c.repo}\uFF09` };
9903
+ };
9904
+ let cases = await casesLine();
9905
+ if (cases.verdict !== "ok" && args.fix && report.envName) {
9906
+ await deps.fixCases();
9907
+ cases = await casesLine();
9908
+ }
9909
+ report.lines.push(cases);
9910
+ const jira = await deps.inspectJira();
9911
+ report.lines.push(
9912
+ jira.ok ? { item: "Jira", verdict: "ok", detail: `${jira.who || "\u5DF2\u8FDE\u63A5"} \xB7 \u770B\u5F97\u5230 ${JIRA_PROJECT2}\uFF08\u4EE4\u724C\u6765\u81EA ${jira.from}\uFF09` } : { item: "Jira", verdict: "warn", detail: jira.reason ?? "\u4E0D\u53EF\u7528", nextStep: "\u73B0\u5728\u4E0D\u914D\u4E5F\u80FD\u4EA4\u4ED8\uFF1B\u649E\u5230\u300C\u4EA7\u54C1\u505A\u4E0D\u5230\u300D\u8981\u63D0\u5355\u65F6\u5FC5\u987B\u5148\u914D\u597D" }
9913
+ );
9914
+ return finish(report);
9840
9915
  }
9841
- function payloadError(argv) {
9842
- for (const flag of PAYLOAD_FLAGS) {
9843
- const raw = flagValue(argv, flag);
9844
- if (raw === void 0) continue;
9845
- try {
9846
- const parsed = JSON.parse(raw);
9847
- if (!isPlainObject(parsed)) return true;
9848
- } catch {
9849
- return true;
9850
- }
9916
+ function finish(report) {
9917
+ report.ok = report.lines.every((l) => l.verdict !== "fail");
9918
+ return report;
9919
+ }
9920
+ function renderChironDoctor(report) {
9921
+ const mark = { ok: "\u2705", warn: "\u26A0\uFE0F", fail: "\u274C" };
9922
+ const out = [];
9923
+ for (const l of report.lines) {
9924
+ out.push(`${mark[l.verdict]} ${l.item.padEnd(3, "\u3000")} ${l.detail}`);
9925
+ if (l.nextStep && l.verdict !== "ok") out.push(` \u2192 ${l.nextStep}`);
9851
9926
  }
9852
- return false;
9927
+ out.push("");
9928
+ out.push(report.ok ? "\u53EF\u4EE5\u5F00\u5DE5\uFF1A\u5728\u8FD9\u4E2A\u76EE\u5F55\u91CC\u542F\u52A8 codex\u3002" : "\u5148\u6309 \u2192 \u5904\u7406\u7EA2\u9879\uFF0C\u518D\u8DD1\u4E00\u6B21 hcm chiron doctor\u3002");
9929
+ return out.join("\n");
9853
9930
  }
9854
- function direct(risk, effect, reasonCode) {
9855
- return {
9856
- risk,
9857
- execution: "direct",
9858
- effect,
9859
- reasonCode,
9860
- reason: risk === "R0" ? "\u7EAF\u53D1\u73B0\u64CD\u4F5C\uFF0C\u53EF\u76F4\u63A5\u6267\u884C\u3002" : "\u53EA\u8BFB\u6216\u53D7\u7BA1\u672C\u5730\u64CD\u4F5C\uFF0C\u53EF\u76F4\u63A5\u6267\u884C\u5E76\u4FDD\u7559\u7ED3\u679C\u3002"
9931
+ async function chironDoctorCommand(args, deps) {
9932
+ try {
9933
+ const report = await runChironDoctor(args, deps);
9934
+ const fmt = args.output ?? "table";
9935
+ if (fmt === "json" || fmt === "yaml") process.stdout.write(formatObject24(report, { format: fmt }) + "\n");
9936
+ else process.stdout.write(renderChironDoctor(report) + "\n");
9937
+ process.exitCode = report.ok ? 0 : 1;
9938
+ } catch (e) {
9939
+ exitWithError(e);
9940
+ }
9941
+ }
9942
+
9943
+ // src/commands/chiron-test.ts
9944
+ init_exit();
9945
+ import { spawnSync as spawnSync2 } from "child_process";
9946
+ import { promises as fs11 } from "fs";
9947
+ import path11 from "path";
9948
+ import yaml from "js-yaml";
9949
+ import { formatObject as formatObject25 } from "@hcmai/sdk";
9950
+
9951
+ // src/commands/delivery-action-policy.ts
9952
+ init_auth_guard();
9953
+ import { HcmClient as HcmClient22, classifyEffect } from "@hcmai/sdk";
9954
+
9955
+ // src/commands/delivery.ts
9956
+ import { createHash as createHash5 } from "crypto";
9957
+ var APPROVAL_BYPASS_FLAGS = /* @__PURE__ */ new Set(["-y", "--yes", "--force", "--auto-approve"]);
9958
+ var CREDENTIAL_FLAGS = /* @__PURE__ */ new Set([
9959
+ "--password",
9960
+ "--password-stdin",
9961
+ "--client-secret",
9962
+ "--pat",
9963
+ "--pat-stdin",
9964
+ "--new-password",
9965
+ "--new-password-stdin"
9966
+ ]);
9967
+ var PAYLOAD_FLAGS = ["--data", "--params"];
9968
+ var GUARDED_EXECUTOR_REASON_CODES = /* @__PURE__ */ new Set([
9969
+ "record-create",
9970
+ "record-update",
9971
+ "cache-mutation",
9972
+ "setting-write",
9973
+ "credential-reset",
9974
+ "action-write",
9975
+ // 三态 effect 的 UNKNOWN / 未识别值都按最坏情况视作写操作,走与 WRITES
9976
+ // 完全相同的 prepare + execute 通道。分类函数已经返回 R2 guarded;这里漏登记
9977
+ // 会把 guardedExecutionAvailable 又翻回 false,造成 reason 与 modePolicy 自相矛盾。
9978
+ "action-effect-undetermined",
9979
+ "action-effect-unrecognized",
9980
+ "workspace-create",
9981
+ "workspace-activate",
9982
+ "workspace-deactivate",
9983
+ // bind / add mini / rm 都是受控本地工作区变更;rm 暂存删除,push 再执行远端 DELETE。
9984
+ "workspace-local-change",
9985
+ // 这两个的载荷是**任意文件 / 整棵目录**,此前刻意不收——绑不住就意味着
9986
+ // 「批准时看到的内容」与「执行时实际读到的内容」可以不同。
9987
+ //
9988
+ // 现在绑得住了:PAYLOAD_FILE_FLAGS 收了 --file,PAYLOAD_DIR_FLAGS 收了 --dir
9989
+ // (workspace push 不传 --dir 时按其 option 默认值 '.' 隐式绑定),
9990
+ // 目录按「路径 + 内容、排序稳定」整树摘要,assertPayloadsUnchanged 执行前逐一重算比对。
9991
+ //
9992
+ // 🔴 二次开发的整条链就卡在这两个上:2026-09-01 轨道 A 第四轮验收,
9993
+ // 受控执行第一次跑通了 workspace create,却在 meta set / workspace push 上
9994
+ // 被「该 R2 命令不在首批受控执行器支持面」拦死,远端只多了一个空 workspace。
9995
+ "metadata-write",
9996
+ "workspace-push",
9997
+ // 载荷是**位置参数**(`hcm import <路径>`),既不走 --file 也不走 --dir,
9998
+ // 所以上一刀把文件与目录开关收进来时它仍留在外面(0.4.9 CHANGELOG 逐字记了这一条)。
9999
+ //
10000
+ // 现在收得住了:POSITIONAL_PAYLOAD_COMMANDS 把 argv[1] 这个固定位置钉成载荷,
10001
+ // 目录走整树摘要、单文件走文件摘要,execute 前重算比对(与 --dir 同一套 bind/assert)。
10002
+ // 位置定死而不是「扫第一个非 flag 参数」,是因为 shape 校验与载荷绑定必须对
10003
+ // 「哪个 token 是载荷」看法一致——两处各自解析就能绑 A 执行 B。
10004
+ //
10005
+ // 🔴 客户存量组织导入的整条链就卡在这一个上:2026-09-01 演示环境租户 15,
10006
+ // 531 条组织机构 dry-run 全绿(静态校验 0 失败),正式导入被
10007
+ // 「该 R2 命令不在首批受控执行器支持面」拦死,一个写请求都没发出去。
10008
+ "import-write",
10009
+ // 报表 / 套打模板回传要先 upload 拿 documentId,再挂到业务对象。文件路径是
10010
+ // 固定位置参数,prepare 会钉住项目内普通文件的摘要,execute 前重算后才单次执行。
10011
+ // 2026-09-02 弹性报表顾问仿真已证实这条交付链会在缺受控执行器时中断。
10012
+ "document-upload"
10013
+ ]);
10014
+ function normalizeAssessedArgv(inputArgv) {
10015
+ let rest = inputArgv;
10016
+ const dropSeparators = () => {
10017
+ let start = 0;
10018
+ while (rest[start] === "--") start += 1;
10019
+ rest = start > 0 ? rest.slice(start) : rest;
9861
10020
  };
10021
+ dropSeparators();
10022
+ if (PACKAGE_RUNNERS.has(rest[0] ?? "") && isCliLauncher(rest[1])) {
10023
+ rest = rest.slice(2);
10024
+ } else if (isCliLauncher(rest[0])) {
10025
+ rest = rest.slice(1);
10026
+ }
10027
+ dropSeparators();
10028
+ return rest === inputArgv ? [...inputArgv] : rest;
9862
10029
  }
9863
- function guarded(effect, reasonCode) {
10030
+ var PACKAGE_RUNNERS = /* @__PURE__ */ new Set(["npx", "bunx", "pnpx"]);
10031
+ function isCliLauncher(token) {
10032
+ if (!token || token.startsWith("-")) return false;
10033
+ if (token === "@hcmai/cli") return true;
10034
+ const base = token.split(/[\\/]/).pop() ?? token;
10035
+ return base === "hcm" || base === "hcm.js" || base === "hcmai";
10036
+ }
10037
+ function assessDeliveryCommand(inputArgv, options = {}) {
10038
+ const argv = normalizeAssessedArgv(inputArgv);
10039
+ const commandSha256 = sha2564(JSON.stringify(argv));
10040
+ const name = argv[0] ?? "";
10041
+ const subcommand = argv[1] && !argv[1].startsWith("-") ? argv[1] : void 0;
10042
+ const envAlias = flagValue(argv, "--env");
10043
+ const identityAlias = flagValue(argv, "--as");
10044
+ const sensitiveFlags = [
10045
+ ...new Set([...PAYLOAD_FLAGS, ...CREDENTIAL_FLAGS].filter((flag) => hasFlag(argv, flag)))
10046
+ ];
10047
+ const target = summarizeTarget(argv, options.actionResolution);
10048
+ let classification = classify(argv, options.actionResolution);
10049
+ const invalidPayload = payloadError(argv);
10050
+ if (invalidPayload) {
10051
+ classification = forbidden("invalid-input", "JSON payload \u65E0\u6548\uFF0C\u4E0D\u80FD\u8FDB\u5165\u4EFB\u4F55\u6267\u884C\u8DEF\u5F84\u3002");
10052
+ }
10053
+ const requirements = [];
10054
+ const guardedExecutionAvailable = classification.risk === "R2" && GUARDED_EXECUTOR_REASON_CODES.has(classification.reasonCode);
10055
+ if (classification.risk === "R2") {
10056
+ if (!envAlias) requirements.push("explicit-env");
10057
+ if (!identityAlias) requirements.push("explicit-identity");
10058
+ if (guardedExecutionAvailable) {
10059
+ requirements.push("change-plan", "rollback-plan", "human-approval", "single-use-plan");
10060
+ } else {
10061
+ requirements.push("guarded-executor");
10062
+ }
10063
+ } else if (classification.risk === "R3") {
10064
+ requirements.push("governance-escalation");
10065
+ }
10066
+ const allowed = classification.risk === "R0" || classification.risk === "R1";
9864
10067
  return {
9865
- risk: "R2",
9866
- execution: "guarded",
9867
- effect,
9868
- reasonCode,
9869
- // 🔴 这一句是 R2 档的**主文案**,15 个调用方共用它,顾问跑任何写命令都读到它。
9870
- // 0.7.0 之前它写的是「只允许在 controlled 项目中通过 delivery prepare +
9871
- // delivery execute 单次受控执行」——那三个概念随受控执行三步一起删了,
9872
- // 于是它变成一条指向不存在的路的下一步。既然 CLI 不再自建执行闸,
9873
- // 真正的下一步就是「这条命令不从这里跑」,而不是「换个 CLI 姿势跑」。
9874
- reason: "\u8FD9\u6761\u547D\u4EE4\u4F1A\u5199\u6570\u636E\uFF0C\u672C\u901A\u9053\u53EA\u8DD1\u53EA\u8BFB\uFF0C\u6240\u4EE5\u6CA1\u6709\u6267\u884C\u3002next_step=\u8981\u843D\u8FD9\u4E2A\u5199\uFF0C\u6309\u9879\u76EE\u7684\u5199\u6388\u6743\u7EAA\u5F8B\u5728\u73AF\u5883\u91CC\u505A\u6389\uFF08\u8BF4\u660E\u5BF9\u8C61\u3001\u8303\u56F4\u3001\u5F71\u54CD\u4E0E\u56DE\u9000\u5E76\u53D6\u5F97\u672C\u6B21\u786E\u8BA4\uFF09\uFF0C\u518D\u7528\u53EA\u8BFB\u547D\u4EE4\u65AD\u8A00\u5B83\u843D\u5E93\u7684\u6837\u5B50\uFF1B\u5982\u679C\u4F60\u8BA4\u4E3A\u5B83\u5176\u5B9E\u4E0D\u5199\u5E93\uFF0C\u53BB\u4EA7\u54C1\u4FA7\u628A effect \u5224\u6210 READ_ONLY\u3002"
10068
+ schemaVersion: 1,
10069
+ contractVersion: "2026-08-29",
10070
+ assessmentId: sha2564(`2026-08-29
10071
+ ${commandSha256}`).slice(0, 24),
10072
+ commandSha256,
10073
+ command: { name: name || "(empty)", ...subcommand ? { subcommand } : {} },
10074
+ ...classification,
10075
+ guardedExecutionAvailable,
10076
+ environment: {
10077
+ ...envAlias ? { envAlias } : {},
10078
+ ...identityAlias ? { identityAlias } : {}
10079
+ },
10080
+ target,
10081
+ requirements,
10082
+ evidenceRequirements: evidenceFor(classification.risk),
10083
+ sensitiveFlags,
10084
+ modePolicy: {
10085
+ planOnly: allowed ? "allow" : "deny",
10086
+ controlled: allowed || guardedExecutionAvailable ? "allow" : "deny"
10087
+ }
9875
10088
  };
9876
10089
  }
9877
- function classifyAction(policy) {
9878
- if (policy.readOnly) {
9879
- return {
9880
- risk: "R1",
9881
- execution: "direct",
9882
- effect: "remote-read",
9883
- reasonCode: "action-read-only",
9884
- reason: "Core \u58F0\u660E\u8BE5 Action \u4E3A\u53EA\u8BFB\uFF0C\u4E0E Moirai \u7684\u53EA\u8BFB Action \u8DEF\u5F84\u4E00\u81F4\uFF0C\u53EF\u76F4\u63A5\u6267\u884C\u3002"
9885
- };
10090
+ function classify(argv, actionResolution) {
10091
+ const name = argv[0] ?? "";
10092
+ const subcommand = argv[1] ?? "";
10093
+ if (name.startsWith("-")) {
10094
+ return forbidden(
10095
+ "malformed-argv",
10096
+ `\u88AB\u8BC4\u4F30\u7684\u547D\u4EE4\u540D\u89E3\u6790\u6210\u4E86 ${name} \u2014\u2014 \u90A3\u662F\u4E00\u4E2A\u9009\u9879\uFF0C\u4E0D\u662F\u547D\u4EE4\u3002next_step=\u4ECE\u547D\u4EE4\u540D\u5F00\u5934\u5199\u6574\u6761\u547D\u4EE4\uFF0C\u628A ${name} \u632A\u5230\u547D\u4EE4\u540D\u540E\u9762\uFF0C\u4F8B\u5982 \`hcm meta set <Model> --env <env>\``
10097
+ );
9886
10098
  }
9887
- if (policy.effect === "declared-unknown") {
9888
- return {
9889
- risk: "R2",
9890
- execution: "guarded",
9891
- effect: "undetermined",
9892
- reasonCode: "action-effect-undetermined",
9893
- reason: "\u4EA7\u54C1\u4FA7\u628A\u8FD9\u4E2A Action \u58F0\u660E\u6210 effect=UNKNOWN\uFF1A**\u6CA1\u4EBA\u5224\u8FC7**\u5B83\u5199\u4E0D\u5199\u5E93\u3002\u6309\u6700\u574F\u60C5\u51B5\u8D70\u53D7\u63A7\u6267\u884C\uFF08\u4E0E\u4F1A\u5199\u7684 Action \u540C\u4E00\u6761\u8DEF\u5F84\uFF09\uFF0C\u4F46\u5B83\u4E0D\u7B49\u4E8E\u300C\u786E\u8BA4\u4F1A\u5199\u300D\u3002next_step=\u53BB\u4EA7\u54C1\u4FA7\u7ED9\u8FD9\u4E2A @ClassAction/@ObjectAction \u628A effect \u5224\u6389\uFF08READ_ONLY / WRITES\uFF09\uFF0C\u800C\u4E0D\u662F\u5728 CLI \u8FD9\u8FB9\u653E\u5BBD\u3002"
9894
- };
10099
+ if (argv.some((arg) => APPROVAL_BYPASS_FLAGS.has(flagName(arg)))) {
10100
+ return forbidden("approval-bypass", "\u547D\u4EE4\u5305\u542B\u8DF3\u8FC7\u786E\u8BA4\u7684\u65D7\u6807\uFF0C\u987E\u95EE\u4EA4\u4ED8\u9762\u4E0D\u6267\u884C\u3002");
9895
10101
  }
9896
- if (policy.effect === "unrecognized-effect") {
9897
- return {
9898
- risk: "R2",
9899
- execution: "guarded",
9900
- effect: "undetermined",
9901
- reasonCode: "action-effect-unrecognized",
9902
- reason: `Core \u9001\u6765\u7684 effect \u53D6\u503C ${describeEffectRaw(policy.effectRaw)} \u4E0D\u5728 READ_ONLY / WRITES / UNKNOWN \u4E09\u6001\u5185\uFF08\u62FC\u5199\u6F02\u79FB\uFF1F\u670D\u52A1\u7AEF\u6BD4\u672C CLI \u65B0\u3001\u591A\u4E86\u4E00\u6001\uFF1F\uFF09\u3002fail-closed\uFF1A\u6309 UNKNOWN \u5904\u7F6E\u8D70\u53D7\u63A7\u6267\u884C\uFF0C\u4E0D\u731C\u6210\u53EA\u8BFB\u3002next_step=\u62FF\u8FD9\u4E2A\u539F\u503C\u53BB\u5BF9\u4EA7\u54C1\u4FA7\u7684 ActionEffect \u5B9A\u4E49\uFF0C\u5FC5\u8981\u65F6\u5347\u7EA7 CLI\u3002`
9903
- };
10102
+ if (name === "user" && subcommand === "reset-password") {
10103
+ const nonStdinCredential = argv.some((arg) => {
10104
+ const flag = flagName(arg);
10105
+ return CREDENTIAL_FLAGS.has(flag) && flag !== "--password-stdin";
10106
+ });
10107
+ if (nonStdinCredential || !argv.includes("--password-stdin")) {
10108
+ return forbidden(
10109
+ "credential-governance",
10110
+ "\u7528\u6237\u5BC6\u7801\u91CD\u7F6E\u53EA\u80FD\u901A\u8FC7 --password-stdin \u8FDB\u5165\u53D7\u63A7\u51ED\u636E\u6D41\u7A0B\u3002"
10111
+ );
10112
+ }
10113
+ return guarded("credential-write", "credential-reset");
9904
10114
  }
9905
- return guarded("tenant-write", "action-write");
9906
- }
9907
- function describeEffectRaw(raw) {
9908
- if (raw === null) return "null";
9909
- if (typeof raw === "string") return JSON.stringify(raw);
9910
- try {
9911
- return `${JSON.stringify(raw)}\uFF08${typeof raw}\uFF09`;
9912
- } catch {
9913
- return `<\u65E0\u6CD5\u5E8F\u5217\u5316\u7684 ${typeof raw}>`;
10115
+ if (argv.some((arg) => CREDENTIAL_FLAGS.has(flagName(arg)))) {
10116
+ return forbidden("credential-governance", "\u547D\u4EE4\u643A\u5E26\u8EAB\u4EFD\u51ED\u636E\u53C2\u6570\uFF0C\u5FC5\u987B\u8F6C\u4EA4\u8EAB\u4EFD\u6CBB\u7406\u6D41\u7A0B\u3002");
9914
10117
  }
9915
- }
9916
- function forbidden(reasonCode, reason) {
9917
- return { risk: "R3", execution: "forbidden", effect: reasonCode, reasonCode, reason };
9918
- }
9919
- function evidenceFor(risk) {
9920
- if (risk === "R0") return ["command-digest", "discovery-result"];
9921
- if (risk === "R1") return ["command-digest", "target-aliases", "result-summary"];
9922
- if (risk === "R2") {
9923
- return [
9924
- "command-digest",
9925
- "explicit-target-aliases",
9926
- "pre-state-or-dry-run",
9927
- "rollback-plan",
9928
- "execution-receipt",
9929
- "post-verification"
9930
- ];
10118
+ if (name === "version") return direct("R0", "product-discovery", "product-discovery");
10119
+ if (name === "open") return direct("R1", "remote-read", "browser-session-open");
10120
+ if (name === "models") return direct("R0", "product-discovery", "model-discovery");
10121
+ if (name === "config") {
10122
+ if (["list", "show", "get"].includes(subcommand))
10123
+ return direct("R0", "local-discovery", "config-read");
10124
+ return forbidden(
10125
+ "identity-governance",
10126
+ "\u4FEE\u6539\u672C\u673A\u5168\u5C40\u914D\u7F6E\u4F1A\u6539\u53D8\u540E\u7EED\u6240\u6709\u547D\u4EE4\u7684\u73AF\u5883\u4E0E\u8EAB\u4EFD\uFF0C\u5C5E\u6CBB\u7406\u64CD\u4F5C\u3002"
10127
+ );
9931
10128
  }
9932
- return ["governance-decision"];
9933
- }
9934
- function flagValue(argv, flag) {
9935
- for (let index = 0; index < argv.length; index += 1) {
9936
- const arg = argv[index];
9937
- if (arg === void 0) continue;
9938
- if (arg === flag) return argv[index + 1];
9939
- if (arg.startsWith(`${flag}=`)) return arg.slice(flag.length + 1);
10129
+ if (name === "upgrade" || name === "self-update") {
10130
+ return direct("R1", "managed-local-write", "cli-self-upgrade");
9940
10131
  }
9941
- return void 0;
9942
- }
9943
- function hasFlag(argv, flag) {
9944
- return argv.some((arg) => arg === flag || arg.startsWith(`${flag}=`));
9945
- }
9946
- function flagName(arg) {
9947
- const equals = arg.indexOf("=");
9948
- return equals < 0 ? arg : arg.slice(0, equals);
9949
- }
9950
- function valuesAfterFlag(argv, flag) {
9951
- const index = argv.indexOf(flag);
9952
- if (index < 0) return [];
9953
- const values = [];
9954
- for (let cursor = index + 1; cursor < argv.length; cursor += 1) {
9955
- const value = argv[cursor];
9956
- if (value === void 0 || value.startsWith("-")) break;
9957
- values.push(value);
10132
+ if (name === "datapackage") {
10133
+ if (subcommand === "pack") return direct("R1", "local-validation", "datapackage-pack");
10134
+ if (subcommand === "status") return direct("R1", "remote-read", "datapackage-status");
10135
+ if (subcommand === "install") return guarded("tenant-data-write", "datapackage-install");
10136
+ return forbidden("unknown-command", "\u672A\u77E5 datapackage \u5B50\u547D\u4EE4\u6309\u6700\u9AD8\u98CE\u9669\u5173\u95ED\u3002");
9958
10137
  }
9959
- return values;
9960
- }
9961
- function sha2564(value) {
9962
- return createHash5("sha256").update(value).digest("hex");
9963
- }
9964
- function isPlainObject(value) {
9965
- return typeof value === "object" && value !== null && !Array.isArray(value);
9966
- }
9967
-
9968
- // src/commands/delivery-action-policy.ts
9969
- async function assessEffectiveDeliveryCommand(inputArgv, dependencies = {}) {
9970
- const local = assessDeliveryCommand(inputArgv);
9971
- if (local.reasonCode !== "action-effect-unclassified") return local;
9972
- const request = parseActionRequest(inputArgv);
9973
- if ("status" in request) {
9974
- return assessDeliveryCommand(inputArgv, { actionResolution: request });
10138
+ if (name === "mini") {
10139
+ return forbidden("removed-command", "`hcm mini` \u5DF2\u79FB\u9664\uFF0C\u6539\u7528 `hcm workspace`\u3002");
9975
10140
  }
9976
- const resolution = await (dependencies.resolveAction ?? resolveCoreAction)(request);
9977
- return assessDeliveryCommand(inputArgv, { actionResolution: resolution });
9978
- }
9979
- async function resolveCoreAction(request) {
9980
- try {
9981
- const auth = await getActiveAuthContextFromCli({
9982
- env: request.env,
9983
- as: request.identity,
9984
- profile: request.profile
9985
- });
9986
- const description = await HcmClient22.fromAuthContext(auth).describe(request.model);
9987
- const named = description.actions.filter((action) => action.name === request.action);
9988
- if (named.length === 0) {
9989
- const degraded = description.effectiveActionsAvailable ? "" : `\u26A0\uFE0F \u672C\u6B21\u6BD4\u5BF9\u4E0D\u542B\u811A\u672C Action\u2014\u2014${description.effectiveActionsNote ?? "\u539F\u56E0\u672A\u77E5"}\u3002`;
9990
- return failed(
9991
- "action-metadata-not-found",
9992
- `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`
9993
- );
10141
+ if (name === "chiron") {
10142
+ if (subcommand === "doctor") return direct("R0", "local-discovery", "chiron-doctor");
10143
+ if (subcommand === "init") return direct("R1", "managed-local-write", "chiron-project-scaffold");
10144
+ if (subcommand === "test") return direct("R1", "remote-read", "chiron-regression-test");
10145
+ if (subcommand === "gap") {
10146
+ const third = argv[2] ?? "";
10147
+ if (["search", "status"].includes(third)) return direct("R1", "remote-read", "gap-read");
10148
+ if (third === "submit") return direct("R1", "external-tracker-write", "gap-submit");
10149
+ return forbidden("unknown-command", "\u672A\u77E5 chiron gap \u5B50\u547D\u4EE4\u6309\u6700\u9AD8\u98CE\u9669\u5173\u95ED\u3002");
9994
10150
  }
9995
- const matches2 = request.explicitShape ? named.filter((action) => matchesRequest(action, request)) : named;
9996
- if (matches2.length === 0) {
9997
- const shapes = named.map((a) => `scope=${a.scope ?? "?"} method=${(a.httpMethod ?? "?").toUpperCase()}`).join("\uFF1B");
9998
- return failed(
9999
- "action-shape-mismatch",
10000
- `${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`
10001
- );
10151
+ return forbidden("unknown-command", "\u672A\u77E5 chiron \u5B50\u547D\u4EE4\u6309\u6700\u9AD8\u98CE\u9669\u5173\u95ED\u3002");
10152
+ }
10153
+ if (name === "skills") {
10154
+ if (subcommand === "list" || subcommand === "show") {
10155
+ return direct("R0", "product-discovery", "skill-discovery");
10002
10156
  }
10003
- if (matches2.length > 1) {
10004
- return failed(
10005
- "action-metadata-ambiguous",
10006
- `${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`
10007
- );
10157
+ if (subcommand === "sync" || subcommand === "install") {
10158
+ return direct("R1", "managed-local-write", "skill-managed-write");
10008
10159
  }
10009
- return policyFromActionMeta(matches2[0], request);
10010
- } catch {
10011
- return failed(
10012
- "action-metadata-unavailable",
10013
- "\u65E0\u6CD5\u8BFB\u53D6 Core Action \u5143\u6570\u636E\uFF0C\u6309\u5B89\u5168\u9ED8\u8BA4\u62D2\u7EDD\u6267\u884C\u3002"
10014
- );
10160
+ return forbidden("unknown-command", "\u672A\u77E5 skills \u5B50\u547D\u4EE4\u6309\u6700\u9AD8\u98CE\u9669\u5173\u95ED\u3002");
10015
10161
  }
10016
- }
10017
- function policyFromActionMeta(action, request) {
10018
- const shape = {
10019
- scope: action.scope ?? request.scope,
10020
- httpMethod: (action.httpMethod ?? request.httpMethod).toUpperCase(),
10021
- ...action.source ? { source: action.source } : {}
10022
- };
10023
- const effectClass = classifyEffect(action.effect);
10024
- if (effectClass === "absent") {
10025
- if (typeof action.readOnly !== "boolean") {
10026
- return failed(
10027
- "action-readonly-unclassified",
10028
- "Core \u672A\u8FD4\u56DE Action \u7684 effect \u4E09\u6001\u58F0\u660E\uFF0C\u4E5F\u6CA1\u6709\u56DE\u843D\u7528\u7684 readOnly \u5E03\u5C14\uFF0C\u6309\u5B89\u5168\u9ED8\u8BA4\u62D2\u7EDD\u6267\u884C\u3002"
10029
- );
10162
+ if (name === "env") {
10163
+ if (subcommand === "list" || subcommand === "current" || subcommand === "show") {
10164
+ return direct("R0", "local-discovery", "environment-read");
10030
10165
  }
10031
- return { status: "resolved", policy: { ...shape, readOnly: action.readOnly } };
10166
+ return forbidden("identity-governance", "\u73AF\u5883\u65B0\u589E\u3001\u5207\u6362\u3001\u7F16\u8F91\u6216\u5220\u9664\u5C5E\u4E8E\u6CBB\u7406\u64CD\u4F5C\u3002");
10032
10167
  }
10033
- return {
10034
- status: "resolved",
10035
- policy: {
10036
- ...shape,
10037
- effect: effectClass,
10038
- ...effectClass === "unrecognized-effect" ? { effectRaw: action.effect } : {},
10039
- readOnly: effectClass === "read-only"
10168
+ if (name === "identity") {
10169
+ if (subcommand === "list") return direct("R0", "local-discovery", "identity-read");
10170
+ return forbidden("identity-governance", "\u8EAB\u4EFD\u5207\u6362\u6216\u5220\u9664\u5C5E\u4E8E\u6CBB\u7406\u64CD\u4F5C\u3002");
10171
+ }
10172
+ if (name === "query" || name === "describe" || name === "trace") {
10173
+ return direct("R1", "remote-read", "business-read");
10174
+ }
10175
+ if (name === "cache") {
10176
+ if (subcommand === "stats") return direct("R1", "remote-read", "cache-read");
10177
+ if (subcommand === "clear" || subcommand === "clear-meta") {
10178
+ return guarded("operational-write", "cache-mutation");
10040
10179
  }
10041
- };
10042
- }
10043
- function matchesRequest(action, request) {
10044
- return action.name === request.action && action.httpMethod?.toUpperCase() === request.httpMethod && action.scope?.toLowerCase() === request.scope;
10045
- }
10046
- function parseActionRequest(inputArgv) {
10047
- const argv = normalizeAssessedArgv(inputArgv);
10048
- const spec = argv[1] ?? "";
10049
- const separator = spec.indexOf(".");
10050
- if (separator <= 0 || separator === spec.length - 1) {
10051
- return failed("invalid-action-spec", "Action \u5FC5\u987B\u4F7F\u7528 <Model>.<Action> \u683C\u5F0F\u3002");
10052
10180
  }
10053
- const explicitMethod = flagValue2(argv, "--method");
10054
- const httpMethod = (explicitMethod ?? "POST").toUpperCase();
10055
- if (!["GET", "POST", "PUT", "DELETE"].includes(httpMethod)) {
10056
- return failed("invalid-action-method", "Action method \u5FC5\u987B\u662F GET\u3001POST\u3001PUT \u6216 DELETE\u3002");
10181
+ if (name === "meta") {
10182
+ if (subcommand === "list" || subcommand === "get") {
10183
+ return direct("R1", "remote-read", "metadata-read");
10184
+ }
10185
+ if (subcommand === "set" && hasFlag(argv, "--dry-run")) {
10186
+ return direct("R1", "local-validation", "metadata-dry-run");
10187
+ }
10188
+ if (subcommand === "set") return guarded("tenant-config-write", "metadata-write");
10189
+ if (subcommand === "delete") return forbidden("destructive", "\u5143\u6570\u636E\u5220\u9664\u4E0D\u53EF\u7531\u987E\u95EE\u63D2\u4EF6\u6267\u884C\u3002");
10057
10190
  }
10058
- const explicitScope = flagValue2(argv, "--scope");
10059
- const scope = explicitScope ?? (flagValue2(argv, "--id") ? "object" : "class");
10060
- if (scope !== "class" && scope !== "object") {
10061
- return failed("invalid-action-scope", "Action scope \u5FC5\u987B\u662F class \u6216 object\u3002");
10191
+ if (name === "setting") {
10192
+ if (subcommand === "get") return direct("R1", "remote-read", "setting-read");
10193
+ if (subcommand === "set" && hasFlag(argv, "--dry-run")) {
10194
+ return direct("R1", "local-validation", "setting-dry-run");
10195
+ }
10196
+ if (subcommand === "set" || subcommand === "reset") {
10197
+ return guarded("tenant-config-write", "setting-write");
10198
+ }
10062
10199
  }
10063
- return {
10064
- model: spec.slice(0, separator),
10065
- action: spec.slice(separator + 1),
10066
- httpMethod,
10067
- scope,
10068
- ...explicitMethod !== void 0 || explicitScope !== void 0 ? { explicitShape: true } : {},
10069
- env: flagValue2(argv, "--env"),
10070
- identity: flagValue2(argv, "--as"),
10071
- profile: flagValue2(argv, "--profile")
10072
- };
10073
- }
10074
- function failed(reasonCode, reason) {
10075
- return { status: "failed", reasonCode, reason };
10076
- }
10077
- function flagValue2(argv, flag) {
10078
- const equals = argv.find((arg) => arg.startsWith(`${flag}=`));
10079
- if (equals) return equals.slice(flag.length + 1);
10080
- const index = argv.indexOf(flag);
10081
- return index >= 0 ? argv[index + 1] : void 0;
10082
- }
10083
-
10084
- // src/commands/xlsx-peek.ts
10085
- import { readFileSync as readFileSync5 } from "fs";
10086
- import { inflateRawSync } from "zlib";
10087
- function readZip(buf, want) {
10088
- let eocd = -1;
10089
- for (let i = buf.length - 22; i >= 0 && i > buf.length - 66e3; i--) {
10090
- if (buf.readUInt32LE(i) === 101010256) {
10091
- eocd = i;
10092
- break;
10200
+ if (name === "workspace") {
10201
+ if (subcommand === "push" && hasFlag(argv, "--dry-run")) {
10202
+ return direct("R1", "remote-read", "workspace-push-dry-run");
10203
+ }
10204
+ if (["list", "active", "status", "validate", "verify", "preview"].includes(subcommand)) {
10205
+ return direct("R1", "remote-read", "workspace-read");
10206
+ }
10207
+ if (subcommand === "pull") {
10208
+ return direct("R1", "managed-local-write", "workspace-pull");
10209
+ }
10210
+ if (subcommand === "bind" || subcommand === "add" && argv[2] === "mini") {
10211
+ return guarded("managed-local-write", "workspace-local-change");
10093
10212
  }
10094
- }
10095
- if (eocd < 0) throw new Error("\u4E0D\u662F\u6709\u6548\u7684 zip/xlsx\uFF08\u627E\u4E0D\u5230\u4E2D\u592E\u76EE\u5F55\uFF09");
10096
- const count = buf.readUInt16LE(eocd + 10);
10097
- let p = buf.readUInt32LE(eocd + 16);
10098
- const out = [];
10099
- for (let n = 0; n < count; n++) {
10100
- if (buf.readUInt32LE(p) !== 33639248) break;
10101
- const method = buf.readUInt16LE(p + 10);
10102
- const compressedSize = buf.readUInt32LE(p + 20);
10103
- const nameLen = buf.readUInt16LE(p + 28);
10104
- const extraLen = buf.readUInt16LE(p + 30);
10105
- const commentLen = buf.readUInt16LE(p + 32);
10106
- const localOffset = buf.readUInt32LE(p + 42);
10107
- const name = buf.subarray(p + 46, p + 46 + nameLen).toString("utf8");
10108
- if (want(name)) {
10109
- const lnameLen = buf.readUInt16LE(localOffset + 26);
10110
- const lextraLen = buf.readUInt16LE(localOffset + 28);
10111
- const start = localOffset + 30 + lnameLen + lextraLen;
10112
- const raw = buf.subarray(start, start + compressedSize);
10113
- if (method === 0) out.push({ name, data: Buffer.from(raw) });
10114
- else if (method === 8) out.push({ name, data: inflateRawSync(raw) });
10115
- else throw new Error(`xlsx \u91CC\u7684 ${name} \u7528\u4E86\u4E0D\u652F\u6301\u7684\u538B\u7F29\u65B9\u5F0F ${method}`);
10213
+ if (subcommand === "rm") return guarded("managed-local-write", "workspace-local-change");
10214
+ if (subcommand === "create") return guarded("tenant-write", "workspace-create");
10215
+ if (subcommand === "activate") return guarded("tenant-write", "workspace-activate");
10216
+ if (subcommand === "deactivate") return guarded("tenant-write", "workspace-deactivate");
10217
+ if (subcommand === "push") return guarded("tenant-write", "workspace-push");
10218
+ if (["deploy", "release", "promote", "publish"].includes(subcommand)) {
10219
+ return forbidden("publish", "\u90E8\u7F72\u5230 active \u5C5E\u4E8E R3\uFF0C\u987B\u8D70\u53D1\u5E03\u4E0E\u5BA1\u6279\u94FE\u8DEF\u3002");
10116
10220
  }
10117
- p += 46 + nameLen + extraLen + commentLen;
10118
10221
  }
10119
- return out;
10120
- }
10121
- var decode = (s) => s.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&amp;/g, "&");
10122
- function xlsxRows(file, maxRows = 50) {
10123
- const buf = readFileSync5(file);
10124
- const [sheet] = readZip(buf, (n) => n === "xl/worksheets/sheet1.xml");
10125
- if (!sheet) throw new Error(`${file} \u91CC\u6CA1\u6709 xl/worksheets/sheet1.xml\uFF0C\u53EF\u80FD\u4E0D\u662F xlsx`);
10126
- const [shared] = readZip(buf, (n) => n === "xl/sharedStrings.xml");
10127
- const sharedStrings = [];
10128
- if (shared) {
10129
- for (const si of shared.data.toString("utf8").split("<si>").slice(1)) {
10130
- sharedStrings.push(decode([...si.matchAll(/<t[^>]*>([\s\S]*?)<\/t>/g)].map((m) => m[1] ?? "").join("")));
10222
+ if (name === "script") {
10223
+ if (["dry-run", "manifest-validate", "logs", "task"].includes(subcommand)) {
10224
+ return direct("R1", "remote-read", "script-" + subcommand);
10131
10225
  }
10132
10226
  }
10133
- const xml = sheet.data.toString("utf8");
10134
- const rows = [];
10135
- for (const rowXml of xml.split("<row").slice(1)) {
10136
- if (rows.length >= maxRows) break;
10137
- const cells = [];
10138
- for (const m of rowXml.matchAll(/<c\b([^>]*)>([\s\S]*?)<\/c>/g)) {
10139
- const attrs = m[1] ?? "";
10140
- const body = m[2] ?? "";
10141
- const v = /<v>([\s\S]*?)<\/v>/.exec(body)?.[1] ?? "";
10142
- const inline = [...body.matchAll(/<t[^>]*>([\s\S]*?)<\/t>/g)].map((x) => x[1] ?? "").join("");
10143
- if (/t="s"/.test(attrs)) cells.push(sharedStrings[Number(v)] ?? "");
10144
- else if (inline) cells.push(decode(inline));
10145
- else cells.push(decode(v));
10227
+ if (name === "import") {
10228
+ if (hasFlag(argv, "--dry-run")) {
10229
+ return direct("R1", "local-validation", "import-dry-run");
10146
10230
  }
10147
- rows.push(cells);
10231
+ return guarded("bulk-tenant-write", "import-write");
10148
10232
  }
10149
- return rows;
10150
- }
10151
-
10152
- // src/commands/chiron-test.ts
10153
- var CONTENT_KEYS = ["stdout_contains", "json", "xlsx_header", "xlsx_min_rows", "text_contains"];
10154
- var hasContentAssertion = (c) => (c.page ? (c.expect_text?.length ?? 0) > 0 : false) || CONTENT_KEYS.some((k) => c.expect?.[k] !== void 0);
10155
- function assertUsableSpec(spec, where) {
10156
- if (!spec?.name || !Array.isArray(spec.checks) || spec.checks.length === 0) {
10157
- throw new Error(`${where}: \u7528\u4F8B\u8981\u6709 name \u4E0E\u81F3\u5C11\u4E00\u6761 checks`);
10233
+ if (name === "create" || name === "update") {
10234
+ return guarded("tenant-write", name === "create" ? "record-create" : "record-update");
10158
10235
  }
10159
- spec.checks.forEach((c, i) => {
10160
- const at = `${where} \u7B2C ${i + 1} \u6761\u300C${c.name ?? "\u672A\u547D\u540D"}\u300D`;
10161
- if (!c.name) throw new Error(`${at}: \u7F3A name`);
10162
- const kinds = [c.run, c.file, c.page].filter(Boolean).length;
10163
- if (kinds !== 1) throw new Error(`${at}: run / file / page \u5FC5\u987B\u4E14\u53EA\u80FD\u6709\u4E00\u4E2A`);
10164
- if (c.run) {
10165
- if (!/^hcm\s/.test(c.run.trim())) {
10166
- throw new Error(`${at}: run \u53EA\u80FD\u8DD1 hcm \u5B50\u547D\u4EE4\uFF08\u4E0D\u63A5\u53D7\u4EFB\u610F shell\uFF1B\u8981\u7ED5\u8FC7 CLI \u7684\u4E8B\u672C\u6765\u5C31\u4E0D\u8BE5\u505A\uFF09`);
10167
- }
10168
- tokenize(c.run);
10236
+ if (name === "upload") return guarded("tenant-write", "document-upload");
10237
+ if (name === "download") return direct("R1", "managed-local-write", "document-download");
10238
+ if (name === "action") {
10239
+ if (actionResolution?.status === "resolved") {
10240
+ return classifyAction(actionResolution.policy);
10169
10241
  }
10170
- if (c.page && !c.expect_text?.length) throw new Error(`${at}: \u9875\u9762\u5224\u636E\u81F3\u5C11\u8981\u4E00\u4E2A expect_text\u2014\u2014\u622A\u56FE\u5B58\u5728\u4E0D\u7B49\u4E8E\u9875\u9762\u5BF9`);
10171
- if (c.file && !hasContentAssertion(c)) throw new Error(`${at}: \u8BFB\u6587\u4EF6\u5374\u6CA1\u6709\u5185\u5BB9\u5224\u636E\uFF08${CONTENT_KEYS.join(" / ")}\uFF09\u2014\u2014\u6587\u4EF6\u5B58\u5728\u4E0D\u7B49\u4E8E\u5185\u5BB9\u5BF9`);
10172
- });
10173
- if (!spec.checks.some(hasContentAssertion)) {
10174
- throw new Error(
10175
- `${where}: \u6574\u4EFD\u7528\u4F8B\u6CA1\u6709\u4EFB\u4F55\u5185\u5BB9\u5224\u636E\uFF08${CONTENT_KEYS.join(" / ")} / expect_text\uFF09\uFF0C\u53EA\u8DD1\u4E0D\u770B\u7B49\u4E8E\u6CA1\u6D4B\u3002`
10242
+ if (actionResolution?.status === "failed") {
10243
+ return forbidden(actionResolution.reasonCode, actionResolution.reason);
10244
+ }
10245
+ return forbidden(
10246
+ "action-effect-unclassified",
10247
+ "\u5C1A\u672A\u8BFB\u53D6 Core Action \u98CE\u63A7\u58F0\u660E\uFF0C\u4E0D\u80FD\u6309\u540D\u79F0\u731C\u6D4B\u540E\u653E\u884C\u3002"
10176
10248
  );
10177
10249
  }
10250
+ if (name === "delete" || name === "meta" && subcommand === "delete") {
10251
+ return forbidden("destructive", "\u5220\u9664\u64CD\u4F5C\u4E0D\u8FDB\u5165\u987E\u95EE\u63D2\u4EF6\u6267\u884C\u9762\u3002");
10252
+ }
10253
+ if (name === "tenant") {
10254
+ return forbidden("tenant-governance", "\u79DF\u6237\u5F00\u901A\u6216\u6CBB\u7406\u5FC5\u987B\u5347\u7EA7\u6CBB\u7406\u4EBA\u5458\u3002");
10255
+ }
10256
+ if (name === "login" || name === "logout") {
10257
+ return forbidden("identity-governance", "\u767B\u5F55\u4E0E\u767B\u51FA\u5C5E\u4E8E\u8EAB\u4EFD\u6CBB\u7406\u64CD\u4F5C\u3002");
10258
+ }
10259
+ if (name === "chat") {
10260
+ return forbidden("agent-autonomy", "\u987E\u95EE\u63D2\u4EF6\u4E0D\u901A\u8FC7\u5D4C\u5957\u6570\u5B57\u5458\u5DE5\u5BF9\u8BDD\u6269\u5927\u81EA\u6CBB\u6267\u884C\u9762\u3002");
10261
+ }
10262
+ return forbidden(
10263
+ "unknown-command",
10264
+ `\u672A\u77E5\u547D\u4EE4\u6309\u6700\u9AD8\u98CE\u9669\u5173\u95ED\uFF1A\u89E3\u6790\u5230\u7684\u547D\u4EE4\u662F ${name || "(\u7A7A)"}` + (subcommand ? ` ${subcommand}` : "") + "\u3002next_step=\u7528 `hcm --help` \u6838\u5BF9\u547D\u4EE4\u540D\uFF1B\u82E5\u4F60\u786E\u4FE1\u8FD9\u6761\u547D\u4EE4\u5B58\u5728\uFF0C\u5148\u8DD1 `hcm upgrade` \u770B CLI \u662F\u4E0D\u662F\u65E7\u7248\uFF08\u98CE\u63A7\u8868\u968F CLI \u53D1\u5E03\u66F4\u65B0\uFF09"
10265
+ );
10178
10266
  }
10179
- function tokenize(line) {
10180
- const out = [];
10181
- let cur = "";
10182
- let quote = null;
10183
- let started = false;
10184
- for (let i = 0; i < line.length; i++) {
10185
- const ch = line[i];
10186
- if (quote) {
10187
- if (ch === quote) quote = null;
10188
- else if (ch === "\\" && quote === '"' && i + 1 < line.length) {
10189
- cur += line[++i];
10190
- } else cur += ch;
10191
- continue;
10192
- }
10193
- if (ch === '"' || ch === "'") {
10194
- quote = ch;
10195
- started = true;
10196
- continue;
10267
+ function summarizeTarget(argv, actionResolution) {
10268
+ const name = argv[0] ?? "";
10269
+ const subcommand = argv[1] ?? "";
10270
+ const target = {};
10271
+ if (["query", "describe", "create", "update", "delete"].includes(name) && subcommand) {
10272
+ target.model = subcommand;
10273
+ }
10274
+ if (name === "action" && subcommand) {
10275
+ target.action = subcommand;
10276
+ if (actionResolution?.status === "resolved") {
10277
+ target.actionPolicy = { ...actionResolution.policy };
10197
10278
  }
10198
- if (ch === "\\" && i + 1 < line.length) {
10199
- cur += line[++i];
10200
- started = true;
10201
- continue;
10279
+ }
10280
+ if (name === "skills" && argv[2] && !argv[2].startsWith("-")) target.skill = argv[2];
10281
+ if (name === "meta" && argv[2] && !argv[2].startsWith("-")) target.path = argv[2];
10282
+ if (name === "cache" && argv[2] && !argv[2].startsWith("-")) {
10283
+ target.cacheOperation = subcommand;
10284
+ target.model = argv[2];
10285
+ }
10286
+ if (name === "setting" && argv[2] && !argv[2].startsWith("-")) {
10287
+ target.domain = argv[2];
10288
+ const settingKeys = valuesAfterFlag(argv, "--set").map((assignment) => assignment.split("=", 1)[0]).filter((key2) => Boolean(key2)).sort();
10289
+ if (settingKeys.length > 0) target.settingKeys = settingKeys;
10290
+ }
10291
+ const id = flagValue(argv, "--id");
10292
+ if (name === "user" && subcommand === "reset-password") {
10293
+ if (id) target.userIdSha256 = sha2564(id);
10294
+ const username = flagValue(argv, "--username");
10295
+ if (username) target.usernameSha256 = sha2564(username);
10296
+ target.forceChangeOnNextLogin = !hasFlag(argv, "--no-force-change");
10297
+ } else if (id) {
10298
+ target.recordIdSha256 = sha2564(id);
10299
+ }
10300
+ for (const flag of PAYLOAD_FLAGS) {
10301
+ const raw = flagValue(argv, flag);
10302
+ if (!raw) continue;
10303
+ target.payloadSha256 = sha2564(raw);
10304
+ try {
10305
+ const parsed = JSON.parse(raw);
10306
+ if (isPlainObject(parsed)) target.fieldNames = Object.keys(parsed).sort();
10307
+ } catch {
10202
10308
  }
10203
- if (/\s/.test(ch)) {
10204
- if (started || cur) {
10205
- out.push(cur);
10206
- cur = "";
10207
- started = false;
10208
- }
10209
- continue;
10309
+ }
10310
+ return target;
10311
+ }
10312
+ function payloadError(argv) {
10313
+ for (const flag of PAYLOAD_FLAGS) {
10314
+ const raw = flagValue(argv, flag);
10315
+ if (raw === void 0) continue;
10316
+ try {
10317
+ const parsed = JSON.parse(raw);
10318
+ if (!isPlainObject(parsed)) return true;
10319
+ } catch {
10320
+ return true;
10210
10321
  }
10211
- cur += ch;
10212
- started = true;
10213
10322
  }
10214
- if (quote) throw new Error(`\u547D\u4EE4\u91CC\u7684\u5F15\u53F7\u6CA1\u95ED\u5408\uFF1A${line}`);
10215
- if (started || cur) out.push(cur);
10216
- return out;
10323
+ return false;
10324
+ }
10325
+ function direct(risk, effect, reasonCode) {
10326
+ return {
10327
+ risk,
10328
+ execution: "direct",
10329
+ effect,
10330
+ reasonCode,
10331
+ reason: risk === "R0" ? "\u7EAF\u53D1\u73B0\u64CD\u4F5C\uFF0C\u53EF\u76F4\u63A5\u6267\u884C\u3002" : "\u53EA\u8BFB\u6216\u53D7\u7BA1\u672C\u5730\u64CD\u4F5C\uFF0C\u53EF\u76F4\u63A5\u6267\u884C\u5E76\u4FDD\u7559\u7ED3\u679C\u3002"
10332
+ };
10333
+ }
10334
+ function guarded(effect, reasonCode) {
10335
+ return {
10336
+ risk: "R2",
10337
+ execution: "guarded",
10338
+ effect,
10339
+ reasonCode,
10340
+ // 🔴 这一句是 R2 档的**主文案**,15 个调用方共用它,顾问跑任何写命令都读到它。
10341
+ // 0.7.0 之前它写的是「只允许在 controlled 项目中通过 delivery prepare +
10342
+ // delivery execute 单次受控执行」——那三个概念随受控执行三步一起删了,
10343
+ // 于是它变成一条指向不存在的路的下一步。既然 CLI 不再自建执行闸,
10344
+ // 真正的下一步就是「这条命令不从这里跑」,而不是「换个 CLI 姿势跑」。
10345
+ reason: "\u8FD9\u6761\u547D\u4EE4\u4F1A\u5199\u6570\u636E\uFF0C\u672C\u901A\u9053\u53EA\u8DD1\u53EA\u8BFB\uFF0C\u6240\u4EE5\u6CA1\u6709\u6267\u884C\u3002next_step=\u8981\u843D\u8FD9\u4E2A\u5199\uFF0C\u6309\u9879\u76EE\u7684\u5199\u6388\u6743\u7EAA\u5F8B\u5728\u73AF\u5883\u91CC\u505A\u6389\uFF08\u8BF4\u660E\u5BF9\u8C61\u3001\u8303\u56F4\u3001\u5F71\u54CD\u4E0E\u56DE\u9000\u5E76\u53D6\u5F97\u672C\u6B21\u786E\u8BA4\uFF09\uFF0C\u518D\u7528\u53EA\u8BFB\u547D\u4EE4\u65AD\u8A00\u5B83\u843D\u5E93\u7684\u6837\u5B50\uFF1B\u5982\u679C\u4F60\u8BA4\u4E3A\u5B83\u5176\u5B9E\u4E0D\u5199\u5E93\uFF0C\u53BB\u4EA7\u54C1\u4FA7\u628A effect \u5224\u6210 READ_ONLY\u3002"
10346
+ };
10347
+ }
10348
+ function classifyAction(policy) {
10349
+ if (policy.readOnly) {
10350
+ return {
10351
+ risk: "R1",
10352
+ execution: "direct",
10353
+ effect: "remote-read",
10354
+ reasonCode: "action-read-only",
10355
+ reason: "Core \u58F0\u660E\u8BE5 Action \u4E3A\u53EA\u8BFB\uFF0C\u4E0E Moirai \u7684\u53EA\u8BFB Action \u8DEF\u5F84\u4E00\u81F4\uFF0C\u53EF\u76F4\u63A5\u6267\u884C\u3002"
10356
+ };
10357
+ }
10358
+ if (policy.effect === "declared-unknown") {
10359
+ return {
10360
+ risk: "R2",
10361
+ execution: "guarded",
10362
+ effect: "undetermined",
10363
+ reasonCode: "action-effect-undetermined",
10364
+ reason: "\u4EA7\u54C1\u4FA7\u628A\u8FD9\u4E2A Action \u58F0\u660E\u6210 effect=UNKNOWN\uFF1A**\u6CA1\u4EBA\u5224\u8FC7**\u5B83\u5199\u4E0D\u5199\u5E93\u3002\u6309\u6700\u574F\u60C5\u51B5\u8D70\u53D7\u63A7\u6267\u884C\uFF08\u4E0E\u4F1A\u5199\u7684 Action \u540C\u4E00\u6761\u8DEF\u5F84\uFF09\uFF0C\u4F46\u5B83\u4E0D\u7B49\u4E8E\u300C\u786E\u8BA4\u4F1A\u5199\u300D\u3002next_step=\u53BB\u4EA7\u54C1\u4FA7\u7ED9\u8FD9\u4E2A @ClassAction/@ObjectAction \u628A effect \u5224\u6389\uFF08READ_ONLY / WRITES\uFF09\uFF0C\u800C\u4E0D\u662F\u5728 CLI \u8FD9\u8FB9\u653E\u5BBD\u3002"
10365
+ };
10366
+ }
10367
+ if (policy.effect === "unrecognized-effect") {
10368
+ return {
10369
+ risk: "R2",
10370
+ execution: "guarded",
10371
+ effect: "undetermined",
10372
+ reasonCode: "action-effect-unrecognized",
10373
+ reason: `Core \u9001\u6765\u7684 effect \u53D6\u503C ${describeEffectRaw(policy.effectRaw)} \u4E0D\u5728 READ_ONLY / WRITES / UNKNOWN \u4E09\u6001\u5185\uFF08\u62FC\u5199\u6F02\u79FB\uFF1F\u670D\u52A1\u7AEF\u6BD4\u672C CLI \u65B0\u3001\u591A\u4E86\u4E00\u6001\uFF1F\uFF09\u3002fail-closed\uFF1A\u6309 UNKNOWN \u5904\u7F6E\u8D70\u53D7\u63A7\u6267\u884C\uFF0C\u4E0D\u731C\u6210\u53EA\u8BFB\u3002next_step=\u62FF\u8FD9\u4E2A\u539F\u503C\u53BB\u5BF9\u4EA7\u54C1\u4FA7\u7684 ActionEffect \u5B9A\u4E49\uFF0C\u5FC5\u8981\u65F6\u5347\u7EA7 CLI\u3002`
10374
+ };
10375
+ }
10376
+ return guarded("tenant-write", "action-write");
10217
10377
  }
10218
- function parseJsonLoose(stdout) {
10219
- const candidates = [];
10220
- const oa = stdout.indexOf("{"), ob = stdout.lastIndexOf("}");
10221
- const aa = stdout.indexOf("["), ab = stdout.lastIndexOf("]");
10222
- if (aa >= 0 && ab > aa) candidates.push([aa, ab]);
10223
- if (oa >= 0 && ob > oa) candidates.push([oa, ob]);
10224
- candidates.sort((x, y) => x[0] - y[0]);
10225
- for (const [a, b] of candidates) {
10226
- try {
10227
- return JSON.parse(stdout.slice(a, b + 1));
10228
- } catch {
10229
- }
10378
+ function describeEffectRaw(raw) {
10379
+ if (raw === null) return "null";
10380
+ if (typeof raw === "string") return JSON.stringify(raw);
10381
+ try {
10382
+ return `${JSON.stringify(raw)}\uFF08${typeof raw}\uFF09`;
10383
+ } catch {
10384
+ return `<\u65E0\u6CD5\u5E8F\u5217\u5316\u7684 ${typeof raw}>`;
10230
10385
  }
10231
- return void 0;
10232
10386
  }
10233
- function pick(value, expr) {
10234
- const tokens = [...expr.replace(/^\$/, "").matchAll(/\[(\d+)\]|([^.[\]]+)/g)];
10235
- let cur = value;
10236
- for (const t of tokens) {
10237
- if (cur === null || cur === void 0) return void 0;
10238
- if (t[1] !== void 0) {
10239
- if (!Array.isArray(cur)) return void 0;
10240
- cur = cur[Number(t[1])];
10241
- } else {
10242
- if (typeof cur !== "object") return void 0;
10243
- cur = cur[t[2]];
10244
- }
10387
+ function forbidden(reasonCode, reason) {
10388
+ return { risk: "R3", execution: "forbidden", effect: reasonCode, reasonCode, reason };
10389
+ }
10390
+ function evidenceFor(risk) {
10391
+ if (risk === "R0") return ["command-digest", "discovery-result"];
10392
+ if (risk === "R1") return ["command-digest", "target-aliases", "result-summary"];
10393
+ if (risk === "R2") {
10394
+ return [
10395
+ "command-digest",
10396
+ "explicit-target-aliases",
10397
+ "pre-state-or-dry-run",
10398
+ "rollback-plan",
10399
+ "execution-receipt",
10400
+ "post-verification"
10401
+ ];
10245
10402
  }
10246
- return cur;
10403
+ return ["governance-decision"];
10247
10404
  }
10248
- function matches(actual, rule) {
10249
- const r = rule.trim();
10250
- if (r === "\u975E\u7A7A" || r === "nonempty") return actual !== void 0 && actual !== null && String(actual) !== "" && !(Array.isArray(actual) && actual.length === 0);
10251
- const m = /^(>=|<=|>|<|!=|=)\s*(.*)$/.exec(r);
10252
- if (!m) return String(actual) === r;
10253
- const [, op, want] = m;
10254
- const n = Number(want), a = Array.isArray(actual) ? actual.length : Number(actual);
10255
- switch (op) {
10256
- case ">":
10257
- return Number.isFinite(a) && a > n;
10258
- case "<":
10259
- return Number.isFinite(a) && a < n;
10260
- case ">=":
10261
- return Number.isFinite(a) && a >= n;
10262
- case "<=":
10263
- return Number.isFinite(a) && a <= n;
10264
- case "!=":
10265
- return String(actual) !== want;
10266
- default:
10267
- return String(actual) === want;
10405
+ function flagValue(argv, flag) {
10406
+ for (let index = 0; index < argv.length; index += 1) {
10407
+ const arg = argv[index];
10408
+ if (arg === void 0) continue;
10409
+ if (arg === flag) return argv[index + 1];
10410
+ if (arg.startsWith(`${flag}=`)) return arg.slice(flag.length + 1);
10268
10411
  }
10412
+ return void 0;
10269
10413
  }
10270
- var defaultDeps2 = {
10271
- assess: (argv) => assessEffectiveDeliveryCommand(argv),
10272
- hcm: (argv, cwd) => {
10273
- const r = spawnSync2("hcm", argv, { cwd, encoding: "utf8", maxBuffer: 1 << 26, timeout: 6e5 });
10274
- return { status: r.status, stdout: r.stdout ?? "", stderr: r.stderr ?? "" };
10275
- },
10276
- pageAcceptance: (root, argv) => {
10277
- const r = spawnSync2("./page-acceptance.sh", argv, { cwd: root, encoding: "utf8", maxBuffer: 1 << 24, timeout: 3e5 });
10278
- return { status: r.status, stdout: r.stdout ?? "", stderr: r.stderr ?? "" };
10279
- },
10280
- readXlsx: (file) => xlsxRows(file),
10281
- readText: (file) => fs11.readFile(file, "utf8")
10282
- };
10283
- async function runCase(spec, root, opts = {}, deps = defaultDeps2) {
10284
- const results = [];
10285
- const vars = {};
10286
- const fill = (text) => text.replace(/\$\{(\w+)\}/g, (_, k) => {
10287
- if (vars[k] === void 0) throw new Error(`\u7528\u5230\u4E86 ${"$"}{${k}} \u4F46\u524D\u9762\u6CA1\u6709\u54EA\u4E00\u6B65\u6355\u83B7\u5B83`);
10288
- return vars[k];
10289
- });
10290
- for (const c of spec.checks) {
10291
- try {
10292
- if (c.run) {
10293
- const argv2 = tokenize(fill(c.run)).slice(1);
10294
- const verdict = await deps.assess(argv2);
10295
- if (verdict.execution !== "direct") {
10296
- results.push({
10297
- name: c.name,
10298
- verdict: "fail",
10299
- // 🔴 `verdict.reason` 里已经带着分档理由与 `next_step=`(见 delivery.ts 的
10300
- // action-effect-undetermined / action-effect-unrecognized 两支)。此前这里
10301
- // 把它整个丢掉、自己编了一句「走 delivery assess → prepare → execute」,
10302
- // 而那三条命令已于 0.7.0 删除 —— 顾问撞到写命令,拿到的是一条不存在的路。
10303
- // 手上有的就要打出来,不要自己编第二句。
10304
- detail: `\u8FD9\u6761\u547D\u4EE4\u6309\u4EA4\u4ED8\u98CE\u63A7\u662F ${verdict.risk} / ${verdict.execution}\uFF08${verdict.reasonCode}\uFF09\uFF0C\u6CA1\u6709\u8DD1\u3002${verdict.reason} \u7528\u4F8B\u53EA\u8DD1\u53EA\u8BFB\uFF1A\u8981\u65AD\u8A00\u5199\u64CD\u4F5C\u7684\u7ED3\u679C\uFF0C\u5148\u5728\u73AF\u5883\u91CC\u628A\u5B83\u505A\u6389\uFF0C\u518D\u7528\u53EA\u8BFB\u547D\u4EE4\u65AD\u8A00\u843D\u5E93\u7684\u6837\u5B50\u3002`
10305
- });
10306
- continue;
10307
- }
10308
- if (opts.env && !argv2.includes("--env")) argv2.push("--env", opts.env);
10309
- const as2 = c.as ?? opts.as;
10310
- if (as2 && !argv2.includes("--as")) argv2.push("--as", as2);
10311
- const r2 = deps.hcm(argv2, root);
10312
- const want = c.expect ?? {};
10313
- const bad = [];
10314
- if (want.exit !== void 0 && r2.status !== want.exit) bad.push(`\u9000\u51FA\u7801 ${r2.status} \u2260 ${want.exit}`);
10315
- for (const t of want.stdout_contains ?? []) if (!r2.stdout.includes(t)) bad.push(`\u8F93\u51FA\u91CC\u6CA1\u6709\u300C${t}\u300D`);
10316
- for (const t of want.stdout_not_contains ?? []) if (r2.stdout.includes(t)) bad.push(`\u8F93\u51FA\u91CC\u51FA\u73B0\u4E86\u4E0D\u8BE5\u6709\u7684\u300C${t}\u300D`);
10317
- if (want.json) {
10318
- const parsed = parseJsonLoose(r2.stdout);
10319
- if (parsed === void 0) bad.push("\u8F93\u51FA\u4E0D\u662F JSON\uFF0C\u65E0\u6CD5\u6309 json \u5224\u636E\u6BD4\u5BF9");
10320
- if (parsed !== void 0) {
10321
- for (const [expr, rule] of Object.entries(want.json)) {
10322
- const actual = pick(parsed, expr);
10323
- if (!matches(actual, rule)) bad.push(`${expr} \u5B9E\u9645 ${JSON.stringify(actual)}\uFF0C\u671F\u671B ${rule}`);
10324
- }
10325
- }
10326
- }
10327
- if (c.capture && bad.length === 0) {
10328
- const parsed = parseJsonLoose(r2.stdout);
10329
- for (const [name, expr] of Object.entries(c.capture)) {
10330
- const v = pick(parsed, expr);
10331
- if (v === void 0 || v === null || String(v) === "") bad.push(`\u8981\u6355\u83B7\u7684 ${name}\uFF08${expr}\uFF09\u5728\u8F93\u51FA\u91CC\u53D6\u4E0D\u5230`);
10332
- else vars[name] = String(v);
10333
- }
10334
- }
10335
- results.push(bad.length ? { name: c.name, verdict: "fail", detail: `${bad.join("\uFF1B")}${r2.stderr.trim() ? `\uFF5Cstderr: ${r2.stderr.trim().split("\n")[0]}` : ""}` } : { name: c.name, verdict: hasContentAssertion(c) ? "pass" : "step", detail: c.capture ? `\u6355\u83B7 ${Object.keys(c.capture).join("\u3001")}` : "" });
10336
- continue;
10337
- }
10338
- if (c.file) {
10339
- const file = path10.resolve(root, fill(c.file));
10340
- const want = c.expect ?? {};
10341
- const bad = [];
10342
- if (want.xlsx_header || want.xlsx_min_rows !== void 0) {
10343
- const rows = deps.readXlsx(file);
10344
- const header = (rows[0] ?? []).map((x) => String(x).trim());
10345
- for (const h of want.xlsx_header ?? []) if (!header.includes(h)) bad.push(`\u8868\u5934\u91CC\u6CA1\u6709\u300C${h}\u300D\uFF0C\u5B9E\u9645\u662F [${header.slice(0, 8).join(", ")}]`);
10346
- if (want.xlsx_min_rows !== void 0 && rows.length - 1 < want.xlsx_min_rows) bad.push(`\u6570\u636E\u884C ${Math.max(rows.length - 1, 0)} \u5C11\u4E8E ${want.xlsx_min_rows}`);
10347
- }
10348
- if (want.text_contains) {
10349
- const text = await deps.readText(file);
10350
- for (const t of want.text_contains) if (!text.includes(t)) bad.push(`\u6587\u4EF6\u91CC\u6CA1\u6709\u300C${t}\u300D`);
10351
- }
10352
- results.push(bad.length ? { name: c.name, verdict: "fail", detail: bad.join("\uFF1B") } : { name: c.name, verdict: "pass", detail: "" });
10353
- continue;
10354
- }
10355
- const out = path10.join("evidence", "test", `${spec.name}-${c.name}`.replace(/[^\w一-龥-]+/g, "_") + ".png");
10356
- const argv = ["--path", fill(c.page), "--out", out];
10357
- if (opts.env) argv.push("--env", opts.env);
10358
- const as = c.as ?? opts.as;
10359
- if (as) argv.push("--as", as);
10360
- for (const t of c.expect_text ?? []) argv.push("--expect-text", t);
10361
- for (const t of c.reject_text ?? []) argv.push("--reject-text", t);
10362
- const r = deps.pageAcceptance(root, argv);
10363
- results.push(r.status === 0 ? { name: c.name, verdict: "pass", detail: out } : { name: c.name, verdict: "fail", detail: (r.stderr || r.stdout).trim().split("\n").slice(-1)[0] ?? `\u9000\u51FA\u7801 ${r.status}` });
10364
- } catch (e) {
10365
- results.push({ name: c.name, verdict: "fail", detail: e.message });
10366
- }
10414
+ function hasFlag(argv, flag) {
10415
+ return argv.some((arg) => arg === flag || arg.startsWith(`${flag}=`));
10416
+ }
10417
+ function flagName(arg) {
10418
+ const equals = arg.indexOf("=");
10419
+ return equals < 0 ? arg : arg.slice(0, equals);
10420
+ }
10421
+ function valuesAfterFlag(argv, flag) {
10422
+ const index = argv.indexOf(flag);
10423
+ if (index < 0) return [];
10424
+ const values = [];
10425
+ for (let cursor = index + 1; cursor < argv.length; cursor += 1) {
10426
+ const value = argv[cursor];
10427
+ if (value === void 0 || value.startsWith("-")) break;
10428
+ values.push(value);
10367
10429
  }
10368
- return results;
10430
+ return values;
10369
10431
  }
10370
- async function loadCases(target) {
10371
- const stat = await fs11.stat(target);
10372
- const files = stat.isDirectory() ? (await fs11.readdir(target)).filter((f) => /\.ya?ml$/.test(f)).sort().map((f) => path10.join(target, f)) : [target];
10373
- const out = [];
10374
- for (const f of files) {
10375
- const spec = yaml.load(await fs11.readFile(f, "utf8"));
10376
- assertUsableSpec(spec, path10.basename(f));
10377
- out.push({ file: f, spec });
10432
+ function sha2564(value) {
10433
+ return createHash5("sha256").update(value).digest("hex");
10434
+ }
10435
+ function isPlainObject(value) {
10436
+ return typeof value === "object" && value !== null && !Array.isArray(value);
10437
+ }
10438
+
10439
+ // src/commands/delivery-action-policy.ts
10440
+ async function assessEffectiveDeliveryCommand(inputArgv, dependencies = {}) {
10441
+ const local = assessDeliveryCommand(inputArgv);
10442
+ if (local.reasonCode !== "action-effect-unclassified") return local;
10443
+ const request = parseActionRequest(inputArgv);
10444
+ if ("status" in request) {
10445
+ return assessDeliveryCommand(inputArgv, { actionResolution: request });
10378
10446
  }
10379
- if (out.length === 0) throw new Error(`${target} \u4E0B\u6CA1\u6709\u7528\u4F8B\uFF08*.yml\uFF09`);
10380
- return out;
10447
+ const resolution = await (dependencies.resolveAction ?? resolveCoreAction)(request);
10448
+ return assessDeliveryCommand(inputArgv, { actionResolution: resolution });
10381
10449
  }
10382
- async function chironTestCommand(target, args, deps) {
10450
+ async function resolveCoreAction(request) {
10383
10451
  try {
10384
- const root = path10.resolve(args.project ?? ".");
10385
- const where = path10.resolve(root, target ?? "tests");
10386
- const cases = await loadCases(where);
10387
- const report = [];
10388
- let failed2 = 0;
10389
- for (const { file, spec } of cases) {
10390
- const results = await runCase(spec, root, { env: args.env, as: args.as }, deps);
10391
- failed2 += results.filter((r) => r.verdict === "fail").length;
10392
- report.push({ case: spec.name, file: path10.relative(root, file), results });
10452
+ const auth = await getActiveAuthContextFromCli({
10453
+ env: request.env,
10454
+ as: request.identity,
10455
+ profile: request.profile
10456
+ });
10457
+ const description = await HcmClient22.fromAuthContext(auth).describe(request.model);
10458
+ const named = description.actions.filter((action) => action.name === request.action);
10459
+ if (named.length === 0) {
10460
+ const degraded = description.effectiveActionsAvailable ? "" : `\u26A0\uFE0F \u672C\u6B21\u6BD4\u5BF9\u4E0D\u542B\u811A\u672C Action\u2014\u2014${description.effectiveActionsNote ?? "\u539F\u56E0\u672A\u77E5"}\u3002`;
10461
+ return failed(
10462
+ "action-metadata-not-found",
10463
+ `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`
10464
+ );
10393
10465
  }
10394
- const fmt = args.output ?? "table";
10395
- if (fmt === "json" || fmt === "yaml") {
10396
- process.stdout.write(formatObject23({ ok: failed2 === 0, failed: failed2, cases: report }, { format: fmt }) + "\n");
10397
- } else {
10398
- for (const c of report) {
10399
- process.stdout.write(`
10400
- ${c.case}\uFF08${c.file}\uFF09
10401
- `);
10402
- for (const r of c.results) {
10403
- const mark = r.verdict === "pass" ? "\u2705" : r.verdict === "step" ? "\xB7" : r.verdict === "warn" ? "\u26A0\uFE0F" : "\u274C";
10404
- process.stdout.write(` ${mark} ${r.name}${r.detail ? ` ${r.detail}` : ""}
10405
- `);
10406
- }
10407
- }
10408
- const verified = report.reduce((n, c) => n + c.results.filter((r) => r.verdict === "pass").length, 0);
10409
- process.stdout.write(failed2 === 0 ? `
10410
- \u5168\u90E8\u901A\u8FC7\uFF08\u771F\u5224\u8FC7\u5185\u5BB9\u7684 ${verified} \u6761\uFF1B\u5E26 \xB7 \u7684\u662F\u6B65\u9AA4\uFF0C\u4E0D\u7B97\u9A8C\u8BC1\uFF09\u3002
10411
- ` : `
10412
- ${failed2} \u6761\u6CA1\u8FC7\u2014\u2014\u4E0A\u9762\u6BCF\u6761\u90FD\u5199\u4E86\u5B9E\u9645\u503C\u4E0E\u671F\u671B\uFF0C\u7167\u7740\u67E5\u3002
10413
- `);
10466
+ const matches2 = request.explicitShape ? named.filter((action) => matchesRequest(action, request)) : named;
10467
+ if (matches2.length === 0) {
10468
+ const shapes = named.map((a) => `scope=${a.scope ?? "?"} method=${(a.httpMethod ?? "?").toUpperCase()}`).join("\uFF1B");
10469
+ return failed(
10470
+ "action-shape-mismatch",
10471
+ `${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`
10472
+ );
10414
10473
  }
10415
- process.exitCode = failed2 === 0 ? 0 : 1;
10416
- } catch (e) {
10417
- exitWithError(e);
10474
+ if (matches2.length > 1) {
10475
+ return failed(
10476
+ "action-metadata-ambiguous",
10477
+ `${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`
10478
+ );
10479
+ }
10480
+ return policyFromActionMeta(matches2[0], request);
10481
+ } catch {
10482
+ return failed(
10483
+ "action-metadata-unavailable",
10484
+ "\u65E0\u6CD5\u8BFB\u53D6 Core Action \u5143\u6570\u636E\uFF0C\u6309\u5B89\u5168\u9ED8\u8BA4\u62D2\u7EDD\u6267\u884C\u3002"
10485
+ );
10418
10486
  }
10419
10487
  }
10420
-
10421
- // src/commands/jira.ts
10422
- import { readFileSync as readFileSync6 } from "fs";
10423
- import {
10424
- createHttpClient as createHttpClient4,
10425
- formatObject as formatObject24,
10426
- loadEnv as loadEnv11,
10427
- loadGlobalConfig as loadGlobalConfig11,
10428
- resolveActiveEnv as resolveActiveEnv5
10429
- } from "@hcmai/sdk";
10430
- init_exit();
10431
- import { createJiraClient } from "@hcmai/sdk";
10432
-
10433
- // src/jira/refs.ts
10434
- import { execFileSync } from "child_process";
10435
- import { CASES_REPO_SLUG, repoIssueUrl } from "@hcmai/sdk";
10436
- var defaultCnb = (args) => execFileSync("cnb", args, { encoding: "utf8", maxBuffer: 1 << 26, stdio: ["ignore", "pipe", "pipe"] });
10437
- var PRODUCT_REPOS = ["hcm/hcm_nx_core", "hcm/hcm_nx_cli", "hcm/hcm_nx_cloud"];
10438
- var REF_RE = /hcm\/(hcm_nx_(?:core|cli|cloud))(?:#|\/-\/issues\/)(\d+)/g;
10439
- function linkedRepoRefs(text) {
10440
- const out = /* @__PURE__ */ new Map();
10441
- for (const m of String(text ?? "").matchAll(REF_RE)) {
10442
- out.set(`hcm/${m[1]}#${m[2]}`, { repo: `hcm/${m[1]}`, number: m[2] });
10443
- }
10444
- return [...out.values()];
10445
- }
10446
- function parseCnbIssueOutput(raw) {
10447
- const fields = {};
10448
- let status;
10449
- for (const line of raw.split("\n")) {
10450
- const head = line.match(/^status:\s*(\d+)\s*$/);
10451
- if (head && status === void 0) {
10452
- status = Number(head[1]);
10453
- continue;
10488
+ function policyFromActionMeta(action, request) {
10489
+ const shape = {
10490
+ scope: action.scope ?? request.scope,
10491
+ httpMethod: (action.httpMethod ?? request.httpMethod).toUpperCase(),
10492
+ ...action.source ? { source: action.source } : {}
10493
+ };
10494
+ const effectClass = classifyEffect(action.effect);
10495
+ if (effectClass === "absent") {
10496
+ if (typeof action.readOnly !== "boolean") {
10497
+ return failed(
10498
+ "action-readonly-unclassified",
10499
+ "Core \u672A\u8FD4\u56DE Action \u7684 effect \u4E09\u6001\u58F0\u660E\uFF0C\u4E5F\u6CA1\u6709\u56DE\u843D\u7528\u7684 readOnly \u5E03\u5C14\uFF0C\u6309\u5B89\u5168\u9ED8\u8BA4\u62D2\u7EDD\u6267\u884C\u3002"
10500
+ );
10454
10501
  }
10455
- const m = line.match(/^\s+(number|title|state|state_reason|priority|url|htmlUrl|created_at|updated_at|closed_at):\s*(.*)$/);
10456
- if (!m) continue;
10457
- const key2 = m[1];
10458
- if (fields[key2] !== void 0) continue;
10459
- fields[key2] = m[2].trim().replace(/^"|"$/g, "");
10502
+ return { status: "resolved", policy: { ...shape, readOnly: action.readOnly } };
10460
10503
  }
10461
- return { status, fields };
10504
+ return {
10505
+ status: "resolved",
10506
+ policy: {
10507
+ ...shape,
10508
+ effect: effectClass,
10509
+ ...effectClass === "unrecognized-effect" ? { effectRaw: action.effect } : {},
10510
+ readOnly: effectClass === "read-only"
10511
+ }
10512
+ };
10462
10513
  }
10463
- function cnbIssueState(cnb, repo, number) {
10464
- let raw;
10465
- try {
10466
- raw = cnb(["issues", "get-issue", "--repo", repo, "--number", String(number)]);
10467
- } catch (e) {
10468
- return { kind: "unreadable", repo, number, reason: firstLine2(e.message) };
10514
+ function matchesRequest(action, request) {
10515
+ return action.name === request.action && action.httpMethod?.toUpperCase() === request.httpMethod && action.scope?.toLowerCase() === request.scope;
10516
+ }
10517
+ function parseActionRequest(inputArgv) {
10518
+ const argv = normalizeAssessedArgv(inputArgv);
10519
+ const spec = argv[1] ?? "";
10520
+ const separator = spec.indexOf(".");
10521
+ if (separator <= 0 || separator === spec.length - 1) {
10522
+ return failed("invalid-action-spec", "Action \u5FC5\u987B\u4F7F\u7528 <Model>.<Action> \u683C\u5F0F\u3002");
10523
+ }
10524
+ const explicitMethod = flagValue2(argv, "--method");
10525
+ const httpMethod = (explicitMethod ?? "POST").toUpperCase();
10526
+ if (!["GET", "POST", "PUT", "DELETE"].includes(httpMethod)) {
10527
+ return failed("invalid-action-method", "Action method \u5FC5\u987B\u662F GET\u3001POST\u3001PUT \u6216 DELETE\u3002");
10469
10528
  }
10470
- const { status, fields } = parseCnbIssueOutput(raw);
10471
- if (status === 404) return { kind: "not-issue", repo, number };
10472
- if (status !== void 0 && status !== 200) {
10473
- return { kind: "unreadable", repo, number, reason: `cnb \u8FD4\u56DE ${status}` };
10529
+ const explicitScope = flagValue2(argv, "--scope");
10530
+ const scope = explicitScope ?? (flagValue2(argv, "--id") ? "object" : "class");
10531
+ if (scope !== "class" && scope !== "object") {
10532
+ return failed("invalid-action-scope", "Action scope \u5FC5\u987B\u662F class \u6216 object\u3002");
10474
10533
  }
10475
- if (!fields.state) return { kind: "unreadable", repo, number, reason: "cnb \u8F93\u51FA\u91CC\u6CA1\u6709 state \u5B57\u6BB5" };
10476
10534
  return {
10477
- kind: "issue",
10478
- repo,
10479
- number,
10480
- state: fields.state,
10481
- reason: fields.state_reason || void 0,
10482
- title: fields.title ?? "",
10483
- priority: fields.priority || void 0,
10484
- url: repoIssueUrl(repo, number)
10535
+ model: spec.slice(0, separator),
10536
+ action: spec.slice(separator + 1),
10537
+ httpMethod,
10538
+ scope,
10539
+ ...explicitMethod !== void 0 || explicitScope !== void 0 ? { explicitShape: true } : {},
10540
+ env: flagValue2(argv, "--env"),
10541
+ identity: flagValue2(argv, "--as"),
10542
+ profile: flagValue2(argv, "--profile")
10485
10543
  };
10486
10544
  }
10487
- var describeIssueState = (s) => {
10488
- if (s.kind === "issue") return `${s.repo}#${s.number} [${s.state}${s.reason ? "\xB7" + s.reason : ""}] ${s.title}`;
10489
- if (s.kind === "not-issue") return `${s.repo}#${s.number} \uFF08\u4E0D\u662F issue\uFF0C\u53EF\u80FD\u662F PR \u53F7\uFF1B\u4E0D\u8BA1\u5165\uFF09`;
10490
- return `${s.repo}#${s.number} \uFF08\u8BFB\u4E0D\u5230\uFF1A${s.reason}\uFF09`;
10491
- };
10492
- function parseCnbIssueList(raw, repo) {
10545
+ function failed(reasonCode, reason) {
10546
+ return { status: "failed", reasonCode, reason };
10547
+ }
10548
+ function flagValue2(argv, flag) {
10549
+ const equals = argv.find((arg) => arg.startsWith(`${flag}=`));
10550
+ if (equals) return equals.slice(flag.length + 1);
10551
+ const index = argv.indexOf(flag);
10552
+ return index >= 0 ? argv[index + 1] : void 0;
10553
+ }
10554
+
10555
+ // src/commands/xlsx-peek.ts
10556
+ import { readFileSync as readFileSync7 } from "fs";
10557
+ import { inflateRawSync } from "zlib";
10558
+ function readZip(buf, want) {
10559
+ let eocd = -1;
10560
+ for (let i = buf.length - 22; i >= 0 && i > buf.length - 66e3; i--) {
10561
+ if (buf.readUInt32LE(i) === 101010256) {
10562
+ eocd = i;
10563
+ break;
10564
+ }
10565
+ }
10566
+ if (eocd < 0) throw new Error("\u4E0D\u662F\u6709\u6548\u7684 zip/xlsx\uFF08\u627E\u4E0D\u5230\u4E2D\u592E\u76EE\u5F55\uFF09");
10567
+ const count = buf.readUInt16LE(eocd + 10);
10568
+ let p = buf.readUInt32LE(eocd + 16);
10493
10569
  const out = [];
10494
- let cur = null;
10495
- for (const line of raw.split("\n")) {
10496
- const m = line.match(/^\s*-?\s*(number|title|state|state_reason|priority):\s*(.*)$/);
10497
- if (!m) continue;
10498
- const key2 = m[1];
10499
- const value = m[2].trim().replace(/^"|"$/g, "");
10500
- if (key2 === "number") {
10501
- if (cur?.number) out.push(finishRow(cur, repo));
10502
- cur = { number: value };
10503
- continue;
10570
+ for (let n = 0; n < count; n++) {
10571
+ if (buf.readUInt32LE(p) !== 33639248) break;
10572
+ const method = buf.readUInt16LE(p + 10);
10573
+ const compressedSize = buf.readUInt32LE(p + 20);
10574
+ const nameLen = buf.readUInt16LE(p + 28);
10575
+ const extraLen = buf.readUInt16LE(p + 30);
10576
+ const commentLen = buf.readUInt16LE(p + 32);
10577
+ const localOffset = buf.readUInt32LE(p + 42);
10578
+ const name = buf.subarray(p + 46, p + 46 + nameLen).toString("utf8");
10579
+ if (want(name)) {
10580
+ const lnameLen = buf.readUInt16LE(localOffset + 26);
10581
+ const lextraLen = buf.readUInt16LE(localOffset + 28);
10582
+ const start = localOffset + 30 + lnameLen + lextraLen;
10583
+ const raw = buf.subarray(start, start + compressedSize);
10584
+ if (method === 0) out.push({ name, data: Buffer.from(raw) });
10585
+ else if (method === 8) out.push({ name, data: inflateRawSync(raw) });
10586
+ else throw new Error(`xlsx \u91CC\u7684 ${name} \u7528\u4E86\u4E0D\u652F\u6301\u7684\u538B\u7F29\u65B9\u5F0F ${method}`);
10504
10587
  }
10505
- if (cur && cur[key2] === void 0) cur[key2] = value;
10588
+ p += 46 + nameLen + extraLen + commentLen;
10506
10589
  }
10507
- if (cur?.number) out.push(finishRow(cur, repo));
10508
10590
  return out;
10509
10591
  }
10510
- function finishRow(p, repo) {
10511
- return {
10512
- repo,
10513
- number: p.number,
10514
- title: p.title ?? "",
10515
- state: p.state ?? "",
10516
- state_reason: p.state_reason,
10517
- priority: p.priority,
10518
- url: repoIssueUrl(repo, p.number)
10519
- };
10520
- }
10521
- function searchRepoIssues(cnb, repo, keyword, state) {
10522
- try {
10523
- return parseCnbIssueList(
10524
- cnb(["issues", "list-issues", "--repo", repo, "--keyword", keyword, "--state", state, "--page-size", "20"]),
10525
- repo
10526
- );
10527
- } catch {
10528
- return [];
10592
+ var decode = (s) => s.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&amp;/g, "&");
10593
+ function xlsxRows(file, maxRows = 50) {
10594
+ const buf = readFileSync7(file);
10595
+ const [sheet] = readZip(buf, (n) => n === "xl/worksheets/sheet1.xml");
10596
+ if (!sheet) throw new Error(`${file} \u91CC\u6CA1\u6709 xl/worksheets/sheet1.xml\uFF0C\u53EF\u80FD\u4E0D\u662F xlsx`);
10597
+ const [shared] = readZip(buf, (n) => n === "xl/sharedStrings.xml");
10598
+ const sharedStrings = [];
10599
+ if (shared) {
10600
+ for (const si of shared.data.toString("utf8").split("<si>").slice(1)) {
10601
+ sharedStrings.push(decode([...si.matchAll(/<t[^>]*>([\s\S]*?)<\/t>/g)].map((m) => m[1] ?? "").join("")));
10602
+ }
10529
10603
  }
10604
+ const xml = sheet.data.toString("utf8");
10605
+ const rows = [];
10606
+ for (const rowXml of xml.split("<row").slice(1)) {
10607
+ if (rows.length >= maxRows) break;
10608
+ const cells = [];
10609
+ for (const m of rowXml.matchAll(/<c\b([^>]*)>([\s\S]*?)<\/c>/g)) {
10610
+ const attrs = m[1] ?? "";
10611
+ const body = m[2] ?? "";
10612
+ const v = /<v>([\s\S]*?)<\/v>/.exec(body)?.[1] ?? "";
10613
+ const inline = [...body.matchAll(/<t[^>]*>([\s\S]*?)<\/t>/g)].map((x) => x[1] ?? "").join("");
10614
+ if (/t="s"/.test(attrs)) cells.push(sharedStrings[Number(v)] ?? "");
10615
+ else if (inline) cells.push(decode(inline));
10616
+ else cells.push(decode(v));
10617
+ }
10618
+ rows.push(cells);
10619
+ }
10620
+ return rows;
10530
10621
  }
10531
- function parseRef(raw, project, casesSlug = CASES_REPO_SLUG) {
10532
- const r = String(raw ?? "").trim();
10533
- let m = r.match(/^(?:hcm\/)?(?:hcm_nx_)?(core|cli|cloud)#(\d+)$/i);
10534
- if (m) return { kind: "repo", repo: `hcm/hcm_nx_${m[1].toLowerCase()}`, number: m[2] };
10535
- m = r.match(/^(?:chiron-)?cases#(\d+)$/i);
10536
- if (m) return { kind: "repo", repo: casesSlug, number: m[1] };
10537
- m = r.match(/^([A-Z][A-Z0-9_]+)-(\d+)$/i);
10538
- if (m) return { kind: "jira", key: `${m[1].toUpperCase()}-${m[2]}` };
10539
- m = r.match(/^(\d+)$/);
10540
- if (m) return { kind: "jira", key: `${project}-${m[1]}` };
10541
- return null;
10542
- }
10543
- var firstLine2 = (s) => String(s ?? "").split("\n").find((l) => l.trim())?.trim() ?? "";
10544
10622
 
10545
- // src/jira/gaps.ts
10546
- import { CASES_REPO_SLUG as CASES_REPO_SLUG2 } from "@hcmai/sdk";
10547
- var MIN_LEN = [
10548
- ["title", 8],
10549
- ["phenomenon", 20],
10550
- ["repro", 10],
10551
- ["expected", 10],
10552
- ["alternative", 5],
10553
- ["q_mechanism", 10],
10554
- ["q_history", 10],
10555
- ["q_skill", 10]
10556
- ];
10557
- function validateGapInput(x) {
10558
- if (!x || typeof x !== "object") throw new Error("\u7F3A\u53E3\u8F7D\u8377\u5FC5\u987B\u662F\u4E00\u4E2A JSON \u5BF9\u8C61");
10559
- const g = x;
10560
- const problems = [];
10561
- for (const [k, min] of MIN_LEN) {
10562
- const v = g[k];
10563
- if (typeof v !== "string" || v.trim().length < min) problems.push(`${k} \u81F3\u5C11 ${min} \u4E2A\u5B57`);
10623
+ // src/commands/chiron-test.ts
10624
+ var CONTENT_KEYS = ["stdout_contains", "json", "xlsx_header", "xlsx_min_rows", "text_contains"];
10625
+ var hasContentAssertion = (c) => (c.page ? (c.expect_text?.length ?? 0) > 0 : false) || CONTENT_KEYS.some((k) => c.expect?.[k] !== void 0);
10626
+ function assertUsableSpec(spec, where) {
10627
+ if (!spec?.name || !Array.isArray(spec.checks) || spec.checks.length === 0) {
10628
+ throw new Error(`${where}: \u7528\u4F8B\u8981\u6709 name \u4E0E\u81F3\u5C11\u4E00\u6761 checks`);
10564
10629
  }
10565
- if (typeof g.title === "string" && g.title.length > 80) problems.push("title \u4E0D\u8D85\u8FC7 80 \u4E2A\u5B57");
10566
- if (!["\u963B\u65AD", "\u6709\u66FF\u4EE3\u6CD5", "\u63AA\u8F9E\u7EA7"].includes(String(g.severity))) problems.push("severity \u53EA\u80FD\u662F \u963B\u65AD / \u6709\u66FF\u4EE3\u6CD5 / \u63AA\u8F9E\u7EA7");
10567
- if (!["\u7F3A\u9677", "\u7F3A\u80FD\u529B"].includes(String(g.kind))) problems.push("kind \u53EA\u80FD\u662F \u7F3A\u9677\uFF08\u6545\u969C\uFF09/ \u7F3A\u80FD\u529B\uFF08\u9700\u6C42\uFF09");
10568
- if (g.module !== void 0 && !["HCM-Core", "HCM-Cloud", "\u4EA7\u54C1\u652F\u6301"].includes(String(g.module))) problems.push("module \u53EA\u80FD\u662F HCM-Core / HCM-Cloud / \u4EA7\u54C1\u652F\u6301");
10569
- if (problems.length) throw new Error(`\u7F3A\u53E3\u8F7D\u8377\u4E0D\u5408\u683C\uFF0C\u6CA1\u6709\u63D0\uFF1A
10570
- ${problems.join("\n ")}`);
10571
- return g;
10572
- }
10573
- var gapKeyTag = (g) => `\u3014${[g.model, g.action, g.error_code].filter(Boolean).join("\xB7") || "-"}\u3015`;
10574
- var gapSummary = (g) => `\u7F3A\u53E3\uFF1A${g.title} ${gapKeyTag(g)}`;
10575
- function renderGapDescription(g, fingerprintText2) {
10576
- return [
10577
- "h2. \u73B0\u8C61",
10578
- g.phenomenon,
10579
- "",
10580
- "h2. \u590D\u73B0",
10581
- "{code}",
10582
- g.repro,
10583
- "{code}",
10584
- "",
10585
- "h2. \u671F\u671B",
10586
- g.expected,
10587
- "",
10588
- "h2. \u73AF\u5883\u6307\u7EB9",
10589
- fingerprintText2,
10590
- "",
10591
- "h2. \u66FF\u4EE3\u6CD5",
10592
- g.alternative,
10593
- "",
10594
- "h2. \u4E25\u91CD\u5EA6",
10595
- `${g.severity}\uFF08\u987E\u95EE\u4FA7\u5224\u5B9A\uFF1A\u963B\u65AD=\u4EA4\u4ED8\u505C\u4E0B / \u6709\u66FF\u4EE3\u6CD5=\u80FD\u7ED5 / \u63AA\u8F9E\u7EA7=\u8F93\u51FA\u5DF2\u7ED9\u8DEF\u6807\uFF09`,
10596
- "",
10597
- "h2. \u4E09\u95EE\u81EA\u7B54",
10598
- `# \u673A\u5236\u8FB9\u754C\uFF1A${g.q_mechanism}`,
10599
- `# \u5386\u53F2\uFF1A${g.q_history}`,
10600
- `# \u6280\u80FD\u6709\u6CA1\u6709\u6559\u9519\uFF1A${g.q_skill}`,
10601
- "",
10602
- "h2. \u5173\u952E\u8BCD",
10603
- [g.error_code, g.model, g.action].filter(Boolean).join(" \xB7 ") || "\uFF08\u65E0\uFF09",
10604
- "",
10605
- "_\u7531\u987E\u95EE agent \u7ECF `hcm jira submit` \u63D0\u4EA4\u3002\u5206\u8BCA\u4E09\u53BB\u5411\uFF1A\u8F6C\u4EA7\u54C1\u4ED3 issue \u5E76\u56DE\u94FE / \u6539\u6280\u80FD\u5E76\u56DE\u590D / \u5408\u5E76\u8BA1\u6570\u3002\u5904\u7406\u529E\u6CD5\u89C1\u4EA7\u54C1\u4ED3\u6280\u80FD jira-triage\u3002_"
10606
- ].join("\n");
10607
- }
10608
- function findDuplicateGap(open, summary, keyTag) {
10609
- const bigrams = (t) => {
10610
- const x = (t || "").replace(/〔.*?〕/g, "").replace(/[\s,。::、()()「」]/g, "");
10611
- const out = /* @__PURE__ */ new Set();
10612
- for (let i = 0; i + 1 < x.length; i++) out.add(x.slice(i, i + 2));
10613
- return out;
10614
- };
10615
- const sim = (a, b) => {
10616
- const A = bigrams(a);
10617
- const B = bigrams(b);
10618
- if (!A.size || !B.size) return 0;
10619
- let n = 0;
10620
- for (const s of A) if (B.has(s)) n++;
10621
- return n / Math.min(A.size, B.size);
10622
- };
10623
- for (const i of open) {
10624
- const t = i.fields.summary ?? "";
10625
- if (keyTag !== "\u3014-\u3015" && t.includes(keyTag)) return i;
10626
- if (sim(t, summary) >= 0.6) return i;
10630
+ spec.checks.forEach((c, i) => {
10631
+ const at = `${where} \u7B2C ${i + 1} \u6761\u300C${c.name ?? "\u672A\u547D\u540D"}\u300D`;
10632
+ if (!c.name) throw new Error(`${at}: \u7F3A name`);
10633
+ const kinds = [c.run, c.file, c.page].filter(Boolean).length;
10634
+ if (kinds !== 1) throw new Error(`${at}: run / file / page \u5FC5\u987B\u4E14\u53EA\u80FD\u6709\u4E00\u4E2A`);
10635
+ if (c.run) {
10636
+ if (!/^hcm\s/.test(c.run.trim())) {
10637
+ throw new Error(`${at}: run \u53EA\u80FD\u8DD1 hcm \u5B50\u547D\u4EE4\uFF08\u4E0D\u63A5\u53D7\u4EFB\u610F shell\uFF1B\u8981\u7ED5\u8FC7 CLI \u7684\u4E8B\u672C\u6765\u5C31\u4E0D\u8BE5\u505A\uFF09`);
10638
+ }
10639
+ tokenize(c.run);
10640
+ }
10641
+ if (c.page && !c.expect_text?.length) throw new Error(`${at}: \u9875\u9762\u5224\u636E\u81F3\u5C11\u8981\u4E00\u4E2A expect_text\u2014\u2014\u622A\u56FE\u5B58\u5728\u4E0D\u7B49\u4E8E\u9875\u9762\u5BF9`);
10642
+ if (c.file && !hasContentAssertion(c)) throw new Error(`${at}: \u8BFB\u6587\u4EF6\u5374\u6CA1\u6709\u5185\u5BB9\u5224\u636E\uFF08${CONTENT_KEYS.join(" / ")}\uFF09\u2014\u2014\u6587\u4EF6\u5B58\u5728\u4E0D\u7B49\u4E8E\u5185\u5BB9\u5BF9`);
10643
+ });
10644
+ if (!spec.checks.some(hasContentAssertion)) {
10645
+ throw new Error(
10646
+ `${where}: \u6574\u4EFD\u7528\u4F8B\u6CA1\u6709\u4EFB\u4F55\u5185\u5BB9\u5224\u636E\uFF08${CONTENT_KEYS.join(" / ")} / expect_text\uFF09\uFF0C\u53EA\u8DD1\u4E0D\u770B\u7B49\u4E8E\u6CA1\u6D4B\u3002`
10647
+ );
10627
10648
  }
10628
- return null;
10629
10649
  }
10630
- var KIND_TO_TYPE = { \u7F3A\u9677: ["\u6545\u969C", "Bug", "\u7F3A\u9677"], \u7F3A\u80FD\u529B: ["\u9700\u6C42", "Story", "New Feature"] };
10631
- var KIND_TO_CATEGORY = { \u7F3A\u9677: "\u7A0B\u5E8FBug", \u7F3A\u80FD\u529B: "\u9700\u6C42" };
10632
- var SEVERITY_TO_PRIORITY = {
10633
- \u963B\u65AD: ["\u7D27\u6025", "Highest", "High", "\u9AD8"],
10634
- \u6709\u66FF\u4EE3\u6CD5: ["Medium", "\u4E2D", "\u4E00\u822C", "High"],
10635
- \u63AA\u8F9E\u7EA7: ["Low", "\u4F4E", "Lowest"]
10636
- };
10637
- var MODULE_DEFAULT_CHILD = { "HCM-Core": "\u57FA\u7840\u8BBE\u7F6E", "HCM-Cloud": "\u5F00\u53D1\u5E73\u53F0", \u4EA7\u54C1\u652F\u6301: "\u4EA7\u54C1\u652F\u6301" };
10638
- function buildGapFields(g, ctx) {
10639
- const wanted = KIND_TO_TYPE[g.kind] ?? [];
10640
- const type = ctx.issuetypeOverride && ctx.types.find((t) => t.name === ctx.issuetypeOverride) || wanted.map((n) => ctx.types.find((t) => t.name === n)).find(Boolean);
10641
- if (!type) {
10642
- throw new Error(`\u9879\u76EE ${ctx.project} \u91CC\u6CA1\u6709\u300C${wanted.join(" / ")}\u300D\u8FD9\u7C7B issuetype\uFF0C\u5B9E\u9645\u6709\uFF1A${ctx.types.map((t) => t.name).join(" / ")}`);
10643
- }
10644
- const module = g.module ?? "HCM-Core";
10645
- const keyTag = gapKeyTag(g);
10646
- const byName = {
10647
- \u6982\u8981: gapSummary(g),
10648
- \u63CF\u8FF0: renderGapDescription(g, ctx.fingerprintText),
10649
- \u95EE\u9898\u7C7B\u522B: KIND_TO_CATEGORY[g.kind],
10650
- \u95EE\u9898\u6A21\u5757: module,
10651
- \u4F18\u5148\u7EA7: SEVERITY_TO_PRIORITY[g.severity],
10652
- \u62A5\u544A\u4EBA: ctx.me,
10653
- \u7ECF\u529E\u4EBA: ctx.assignee,
10654
- Bug\u53D1\u73B0\u4EBA: "\u987E\u95EE",
10655
- Bug\u91CD\u73B0\u64CD\u4F5C\u6B65\u9AA4: g.repro,
10656
- Bug\u9519\u8BEF\u53F7: g.error_code || "\u65E0\u9519\u8BEF\u7801\uFF08\u73B0\u8C61\u89C1\u63CF\u8FF0\uFF09"
10657
- };
10658
- const fields = { project: { key: ctx.project }, issuetype: { id: type.id } };
10659
- const unfilled = [];
10660
- const values = (f) => (f.allowedValues ?? []).map((v) => v.value ?? v.name).join("|");
10661
- for (const f of type.fields ?? []) {
10662
- if (["project", "issuetype"].includes(f.fieldId)) continue;
10663
- const want = byName[f.name];
10664
- if (want === void 0) {
10665
- if (f.required) unfilled.push(`${f.name}(${f.fieldId})${f.allowedValues ? `=[${values(f)}]` : ""}`);
10650
+ function tokenize(line) {
10651
+ const out = [];
10652
+ let cur = "";
10653
+ let quote = null;
10654
+ let started = false;
10655
+ for (let i = 0; i < line.length; i++) {
10656
+ const ch = line[i];
10657
+ if (quote) {
10658
+ if (ch === quote) quote = null;
10659
+ else if (ch === "\\" && quote === '"' && i + 1 < line.length) {
10660
+ cur += line[++i];
10661
+ } else cur += ch;
10666
10662
  continue;
10667
10663
  }
10668
- if (f.schema?.type === "option-with-child") {
10669
- const parent = (f.allowedValues ?? []).find((v) => (v.value ?? v.name) === want);
10670
- if (!parent) {
10671
- if (f.required) unfilled.push(`${f.name}(${f.fieldId}) \u60F3\u586B\u300C${String(want)}\u300D\u4F46\u53EF\u9009\u503C\u53EA\u6709 [${values(f)}]`);
10672
- continue;
10673
- }
10674
- const childName = g.module_detail || MODULE_DEFAULT_CHILD[module];
10675
- const child = (parent.children ?? []).find((c) => (c.value ?? c.name) === childName);
10676
- if (!child && (parent.children ?? []).length) {
10677
- unfilled.push(`${f.name}(${f.fieldId}) \u7684\u4E8C\u7EA7\u9879\u300C${childName}\u300D\u4E0D\u5728 [${(parent.children ?? []).map((c) => c.value ?? c.name).join("|")}] \u91CC`);
10678
- continue;
10679
- }
10680
- fields[f.fieldId] = { id: parent.id, ...child ? { child: { id: child.id } } : {} };
10664
+ if (ch === '"' || ch === "'") {
10665
+ quote = ch;
10666
+ started = true;
10681
10667
  continue;
10682
10668
  }
10683
- if (f.allowedValues) {
10684
- const candidates = Array.isArray(want) ? want : [want];
10685
- const hit = candidates.map((c) => f.allowedValues.find((v) => (v.name ?? v.value) === c)).find(Boolean);
10686
- if (!hit) {
10687
- if (f.required) unfilled.push(`${f.name}(${f.fieldId}) \u60F3\u586B\u300C${candidates.join("/")}\u300D\u4F46\u53EF\u9009\u503C\u53EA\u6709 [${values(f)}]`);
10688
- continue;
10689
- }
10690
- fields[f.fieldId] = hit.id ? { id: hit.id } : { name: hit.name ?? hit.value };
10691
- } else if (f.schema?.type === "user") {
10692
- if (!want) {
10693
- if (f.required) unfilled.push(`${f.name}(${f.fieldId}) \u53D6\u4E0D\u5230\u7528\u6237\u540D`);
10694
- continue;
10669
+ if (ch === "\\" && i + 1 < line.length) {
10670
+ cur += line[++i];
10671
+ started = true;
10672
+ continue;
10673
+ }
10674
+ if (/\s/.test(ch)) {
10675
+ if (started || cur) {
10676
+ out.push(cur);
10677
+ cur = "";
10678
+ started = false;
10695
10679
  }
10696
- fields[f.fieldId] = { name: Array.isArray(want) ? want[0] : want };
10697
- } else {
10698
- fields[f.fieldId] = Array.isArray(want) ? want[0] : want;
10680
+ continue;
10699
10681
  }
10682
+ cur += ch;
10683
+ started = true;
10700
10684
  }
10701
- if ((type.fields ?? []).some((f) => f.fieldId === "labels")) {
10702
- const sev = { \u963B\u65AD: "blocking", \u6709\u66FF\u4EE3\u6CD5: "workaround", \u63AA\u8F9E\u7EA7: "wording" }[g.severity];
10703
- fields.labels = ["chiron-gap", `severity-${sev}`];
10685
+ if (quote) throw new Error(`\u547D\u4EE4\u91CC\u7684\u5F15\u53F7\u6CA1\u95ED\u5408\uFF1A${line}`);
10686
+ if (started || cur) out.push(cur);
10687
+ return out;
10688
+ }
10689
+ function parseJsonLoose(stdout) {
10690
+ const candidates = [];
10691
+ const oa = stdout.indexOf("{"), ob = stdout.lastIndexOf("}");
10692
+ const aa = stdout.indexOf("["), ab = stdout.lastIndexOf("]");
10693
+ if (aa >= 0 && ab > aa) candidates.push([aa, ab]);
10694
+ if (oa >= 0 && ob > oa) candidates.push([oa, ob]);
10695
+ candidates.sort((x, y) => x[0] - y[0]);
10696
+ for (const [a, b] of candidates) {
10697
+ try {
10698
+ return JSON.parse(stdout.slice(a, b + 1));
10699
+ } catch {
10700
+ }
10704
10701
  }
10705
- if (unfilled.length) {
10706
- throw new Error(
10707
- `\u8FD9\u53F0 Jira \u7684\u300C${type.name}\u300D\u6709\u6211\u586B\u4E0D\u4E0A\u7684\u5FC5\u586B\u5B57\u6BB5\uFF0C\u6CA1\u6709\u5EFA\u5355\uFF08\u4E0D\u66FF\u4F60\u731C\uFF09\uFF1A
10708
- ${unfilled.join("\n ")}
10709
- next_step=\u8BA9 Jira \u7BA1\u7406\u5458\u628A\u8FD9\u4E9B\u5B57\u6BB5\u6539\u6210\u975E\u5FC5\u586B\uFF0C\u6216\u544A\u8BC9\u6211\u8BE5\u586B\u4EC0\u4E48\u3001\u6211\u52A0\u8FDB\u6620\u5C04\u3002\u53F0\u8D26\u5DF2\u7ECF\u5728\u9879\u76EE\u4ED3\u91CC\uFF0C\u4E0D\u4F1A\u4E22\u3002`
10710
- );
10702
+ return void 0;
10703
+ }
10704
+ function pick(value, expr) {
10705
+ const tokens = [...expr.replace(/^\$/, "").matchAll(/\[(\d+)\]|([^.[\]]+)/g)];
10706
+ let cur = value;
10707
+ for (const t of tokens) {
10708
+ if (cur === null || cur === void 0) return void 0;
10709
+ if (t[1] !== void 0) {
10710
+ if (!Array.isArray(cur)) return void 0;
10711
+ cur = cur[Number(t[1])];
10712
+ } else {
10713
+ if (typeof cur !== "object") return void 0;
10714
+ cur = cur[t[2]];
10715
+ }
10711
10716
  }
10712
- return { fields, type, keyTag, summary: gapSummary(g), module: `${module}/${g.module_detail || MODULE_DEFAULT_CHILD[module]}` };
10717
+ return cur;
10713
10718
  }
10714
- async function gapSubmit({ client: client3 }, g, { fingerprintText: fingerprintText2, issuetypeOverride, assigneeOverride }) {
10715
- const summary = gapSummary(g);
10716
- const keyTag = gapKeyTag(g);
10717
- const open = await client3.search(`project = ${client3.project} AND resolution = Unresolved ORDER BY created DESC`, { max: 100 });
10718
- const dup = findDuplicateGap(open, summary, keyTag);
10719
- if (dup) {
10720
- const body = `\u53C8\u4E00\u4E2A\u73B0\u573A\uFF08${fingerprintText2}\uFF09
10721
-
10722
- **\u73B0\u8C61**\uFF1A${g.phenomenon}
10723
-
10724
- **\u590D\u73B0**\uFF1A
10725
- {code}
10726
- ${g.repro}
10727
- {code}
10728
-
10729
- **\u66FF\u4EE3\u6CD5**\uFF1A${g.alternative}
10730
- \u4E25\u91CD\u5EA6\uFF1A${g.severity}`;
10731
- await client3.addComment(dup.key, body);
10732
- return { outcome: "appended", key: dup.key, url: client3.browseUrl(dup.key), summary: dup.fields.summary ?? "", alternative: g.alternative };
10719
+ function matches(actual, rule) {
10720
+ const r = rule.trim();
10721
+ if (r === "\u975E\u7A7A" || r === "nonempty") return actual !== void 0 && actual !== null && String(actual) !== "" && !(Array.isArray(actual) && actual.length === 0);
10722
+ const m = /^(>=|<=|>|<|!=|=)\s*(.*)$/.exec(r);
10723
+ if (!m) return String(actual) === r;
10724
+ const [, op, want] = m;
10725
+ const n = Number(want), a = Array.isArray(actual) ? actual.length : Number(actual);
10726
+ switch (op) {
10727
+ case ">":
10728
+ return Number.isFinite(a) && a > n;
10729
+ case "<":
10730
+ return Number.isFinite(a) && a < n;
10731
+ case ">=":
10732
+ return Number.isFinite(a) && a >= n;
10733
+ case "<=":
10734
+ return Number.isFinite(a) && a <= n;
10735
+ case "!=":
10736
+ return String(actual) !== want;
10737
+ default:
10738
+ return String(actual) === want;
10733
10739
  }
10734
- const [types, me, project] = await Promise.all([client3.createMeta(), client3.myself(), client3.projectInfo()]);
10735
- const built = buildGapFields(g, {
10736
- types,
10737
- me: me.name ?? me.key ?? "",
10738
- assignee: assigneeOverride || project.lead?.name || project.lead?.key,
10739
- project: client3.project,
10740
- fingerprintText: fingerprintText2,
10741
- issuetypeOverride
10742
- });
10743
- const created = await client3.createIssue(built.fields);
10744
- return { outcome: "created", key: created.key, url: client3.browseUrl(created.key), summary: built.summary, type: built.type.name, module: built.module, alternative: g.alternative };
10745
10740
  }
10746
- async function gapSearch({ client: client3, cnb }, keywords, { includeClosed = true } = {}) {
10747
- const rows = [];
10748
- let jiraError;
10749
- try {
10750
- for (const kw of keywords) {
10751
- const safe = kw.replace(/["\\]/g, " ").trim();
10752
- const jql = `project = ${client3.project} AND text ~ "${safe}"${includeClosed ? "" : " AND resolution = Unresolved"} ORDER BY updated DESC`;
10753
- for (const i of await client3.search(jql, { max: 15 })) {
10754
- rows.push({ where: "Jira", id: i.key, title: i.fields.summary ?? "", state: i.fields.status?.name, resolution: i.fields.resolution?.name, url: client3.browseUrl(i.key) });
10755
- }
10756
- }
10757
- if (!rows.length) {
10758
- const open = await client3.search(`project = ${client3.project} AND resolution = Unresolved ORDER BY created DESC`, { max: 100 });
10759
- for (const i of open) {
10760
- if (keywords.some((k) => (i.fields.summary ?? "").includes(k))) {
10761
- rows.push({ where: "Jira", id: i.key, title: i.fields.summary ?? "", state: i.fields.status?.name, url: client3.browseUrl(i.key) });
10741
+ var defaultDeps3 = {
10742
+ assess: (argv) => assessEffectiveDeliveryCommand(argv),
10743
+ hcm: (argv, cwd) => {
10744
+ const r = spawnSync2("hcm", argv, { cwd, encoding: "utf8", maxBuffer: 1 << 26, timeout: 6e5 });
10745
+ return { status: r.status, stdout: r.stdout ?? "", stderr: r.stderr ?? "" };
10746
+ },
10747
+ pageAcceptance: (root, argv) => {
10748
+ const r = spawnSync2("./page-acceptance.sh", argv, { cwd: root, encoding: "utf8", maxBuffer: 1 << 24, timeout: 3e5 });
10749
+ return { status: r.status, stdout: r.stdout ?? "", stderr: r.stderr ?? "" };
10750
+ },
10751
+ readXlsx: (file) => xlsxRows(file),
10752
+ readText: (file) => fs11.readFile(file, "utf8")
10753
+ };
10754
+ async function runCase(spec, root, opts = {}, deps = defaultDeps3) {
10755
+ const results = [];
10756
+ const vars = {};
10757
+ const fill = (text) => text.replace(/\$\{(\w+)\}/g, (_, k) => {
10758
+ if (vars[k] === void 0) throw new Error(`\u7528\u5230\u4E86 ${"$"}{${k}} \u4F46\u524D\u9762\u6CA1\u6709\u54EA\u4E00\u6B65\u6355\u83B7\u5B83`);
10759
+ return vars[k];
10760
+ });
10761
+ for (const c of spec.checks) {
10762
+ try {
10763
+ if (c.run) {
10764
+ const argv2 = tokenize(fill(c.run)).slice(1);
10765
+ const verdict = await deps.assess(argv2);
10766
+ if (verdict.execution !== "direct") {
10767
+ results.push({
10768
+ name: c.name,
10769
+ verdict: "fail",
10770
+ // 🔴 `verdict.reason` 里已经带着分档理由与 `next_step=`(见 delivery.ts 的
10771
+ // action-effect-undetermined / action-effect-unrecognized 两支)。此前这里
10772
+ // 把它整个丢掉、自己编了一句「走 delivery assess → prepare → execute」,
10773
+ // 而那三条命令已于 0.7.0 删除 —— 顾问撞到写命令,拿到的是一条不存在的路。
10774
+ // 手上有的就要打出来,不要自己编第二句。
10775
+ detail: `\u8FD9\u6761\u547D\u4EE4\u6309\u4EA4\u4ED8\u98CE\u63A7\u662F ${verdict.risk} / ${verdict.execution}\uFF08${verdict.reasonCode}\uFF09\uFF0C\u6CA1\u6709\u8DD1\u3002${verdict.reason} \u7528\u4F8B\u53EA\u8DD1\u53EA\u8BFB\uFF1A\u8981\u65AD\u8A00\u5199\u64CD\u4F5C\u7684\u7ED3\u679C\uFF0C\u5148\u5728\u73AF\u5883\u91CC\u628A\u5B83\u505A\u6389\uFF0C\u518D\u7528\u53EA\u8BFB\u547D\u4EE4\u65AD\u8A00\u843D\u5E93\u7684\u6837\u5B50\u3002`
10776
+ });
10777
+ continue;
10778
+ }
10779
+ if (opts.env && !argv2.includes("--env")) argv2.push("--env", opts.env);
10780
+ const as2 = c.as ?? opts.as;
10781
+ if (as2 && !argv2.includes("--as")) argv2.push("--as", as2);
10782
+ const r2 = deps.hcm(argv2, root);
10783
+ const want = c.expect ?? {};
10784
+ const bad = [];
10785
+ if (want.exit !== void 0 && r2.status !== want.exit) bad.push(`\u9000\u51FA\u7801 ${r2.status} \u2260 ${want.exit}`);
10786
+ for (const t of want.stdout_contains ?? []) if (!r2.stdout.includes(t)) bad.push(`\u8F93\u51FA\u91CC\u6CA1\u6709\u300C${t}\u300D`);
10787
+ for (const t of want.stdout_not_contains ?? []) if (r2.stdout.includes(t)) bad.push(`\u8F93\u51FA\u91CC\u51FA\u73B0\u4E86\u4E0D\u8BE5\u6709\u7684\u300C${t}\u300D`);
10788
+ if (want.json) {
10789
+ const parsed = parseJsonLoose(r2.stdout);
10790
+ if (parsed === void 0) bad.push("\u8F93\u51FA\u4E0D\u662F JSON\uFF0C\u65E0\u6CD5\u6309 json \u5224\u636E\u6BD4\u5BF9");
10791
+ if (parsed !== void 0) {
10792
+ for (const [expr, rule] of Object.entries(want.json)) {
10793
+ const actual = pick(parsed, expr);
10794
+ if (!matches(actual, rule)) bad.push(`${expr} \u5B9E\u9645 ${JSON.stringify(actual)}\uFF0C\u671F\u671B ${rule}`);
10795
+ }
10796
+ }
10762
10797
  }
10798
+ if (c.capture && bad.length === 0) {
10799
+ const parsed = parseJsonLoose(r2.stdout);
10800
+ for (const [name, expr] of Object.entries(c.capture)) {
10801
+ const v = pick(parsed, expr);
10802
+ if (v === void 0 || v === null || String(v) === "") bad.push(`\u8981\u6355\u83B7\u7684 ${name}\uFF08${expr}\uFF09\u5728\u8F93\u51FA\u91CC\u53D6\u4E0D\u5230`);
10803
+ else vars[name] = String(v);
10804
+ }
10805
+ }
10806
+ results.push(bad.length ? { name: c.name, verdict: "fail", detail: `${bad.join("\uFF1B")}${r2.stderr.trim() ? `\uFF5Cstderr: ${r2.stderr.trim().split("\n")[0]}` : ""}` } : { name: c.name, verdict: hasContentAssertion(c) ? "pass" : "step", detail: c.capture ? `\u6355\u83B7 ${Object.keys(c.capture).join("\u3001")}` : "" });
10807
+ continue;
10763
10808
  }
10764
- }
10765
- } catch (e) {
10766
- jiraError = e.message;
10767
- }
10768
- for (const kw of keywords) {
10769
- for (const st of includeClosed ? ["open", "closed"] : ["open"]) {
10770
- for (const repo of PRODUCT_REPOS) {
10771
- for (const i of searchRepoIssues(cnb, repo, kw, st)) rows.push({ where: "\u4EA7\u54C1\u4ED3", id: `${i.repo}#${i.number}`, title: i.title, state: i.state, url: i.url });
10772
- }
10773
- }
10774
- }
10775
- const seen = /* @__PURE__ */ new Set();
10776
- return { rows: rows.filter((r) => seen.has(r.id) ? false : (seen.add(r.id), true)), jiraError };
10777
- }
10778
- async function gapStatus({ client: client3, cnb }, ref, casesSlug = CASES_REPO_SLUG2) {
10779
- const parsed = parseRef(ref, client3.project, casesSlug);
10780
- if (!parsed) throw new Error(`\u770B\u4E0D\u61C2 ${ref}\uFF1A\u7ED9 Jira \u5355\u53F7\uFF08HCMNX-12\uFF09\u3001\u4EA7\u54C1\u4ED3\u5F15\u7528\uFF08core#2198\uFF09\u6216\u5386\u53F2\u961F\u5217\u6761\u76EE\uFF08cases#26\uFF09`);
10781
- if (parsed.kind === "repo") {
10782
- const s = cnbIssueState(cnb, parsed.repo, parsed.number);
10783
- if (s.kind !== "issue") throw new Error(`${parsed.repo}#${parsed.number} \u8BFB\u4E0D\u5230\uFF08\u7F16\u53F7\u4E0D\u5BF9\u3001\u662F PR \u53F7\uFF0C\u6216\u4F60\u6CA1\u6709\u8FD9\u4E2A\u4ED3\u7684\u6743\u9650\uFF09`);
10784
- const where = parsed.repo === casesSlug ? "\u5386\u53F2\u961F\u5217" : "\u4EA7\u54C1\u4ED3";
10785
- const nextStep2 = s.state === "closed" ? "\u8FD9\u6761\u5DF2\u5173\u3002\u76EE\u6807\u73AF\u5883\u90E8\u7F72\u5230\u542B\u4FEE\u590D\u7684\u7248\u672C\u540E `hcm skills update`\uFF0C\u518D\u6309\u6280\u80FD\u590D\u9A8C\u4E00\u6B21\u3002" : "\u8FD8\u5F00\u7740\u3002\u5148\u6309\u66FF\u4EE3\u6CD5\u7EE7\u7EED\u4EA4\u4ED8\uFF1B\u8981\u6392\u671F\u5C31\u5728\u90A3\u6761\u4E0B\u9762\u7559\u8A00\u3002";
10786
- return { ref, lines: [`${where} ${s.repo}#${s.number} [${s.state}${s.reason ? "\xB7" + s.reason : ""}${s.priority ? " " + s.priority : ""}] ${s.title}`, ` ${s.url}`], nextStep: nextStep2, repo: s, links: [] };
10787
- }
10788
- const issue = await client3.issue(parsed.key);
10789
- const cs = await client3.comments(parsed.key);
10790
- const status = issue.fields.status?.name;
10791
- const resolution = issue.fields.resolution?.name;
10792
- const lines = [`Jira ${issue.key} [${status}${resolution ? "\xB7" + resolution : ""}${issue.fields.priority ? " " + issue.fields.priority.name : ""}] ${issue.fields.summary ?? ""}`, ` ${client3.browseUrl(issue.key)}`];
10793
- const keyComments = cs.filter((c) => /分诊|已转|已修|合入|不做|重复|改技能|产品侧|代码库已关闭/.test(c.body ?? ""));
10794
- const last = (keyComments.length ? keyComments : cs).at(-1);
10795
- if (last) lines.push(` \u6700\u65B0\u5904\u7406\uFF08${String(last.created ?? "").slice(0, 10)} ${last.author?.displayName ?? "?"}\uFF09\uFF1A${(last.body ?? "").split("\n").find((l) => l.trim()) ?? ""}`.slice(0, 400));
10796
- else lines.push(" \u8FD8\u6CA1\u6709\u4EBA\u5904\u7406\uFF08\u4EA7\u54C1\u4FA7\u6BCF\u5468\u6E05\u4E00\u6B21\uFF1B\u963B\u65AD\u7EA7\u8BF7\u5728\u9879\u76EE\u7FA4\u91CC\u70B9\u540D\u8D1F\u8D23\u4EBA\uFF09");
10797
- const remote = (await client3.remoteLinks(parsed.key)).map((l) => l.object?.url ?? "").join("\n");
10798
- const links = linkedRepoRefs(`${remote}
10799
- ${issue.fields.description ?? ""}
10800
- ${cs.map((c) => c.body ?? "").join("\n")}`).map((l) => cnbIssueState(cnb, l.repo, l.number));
10801
- const issues = links.filter((l) => l.kind === "issue");
10802
- for (const p of issues) lines.push(`\u4EA7\u54C1\u4ED3 ${p.repo}#${p.number} [${p.state}${p.reason ? "\xB7" + p.reason : ""}${p.priority ? " " + p.priority : ""}] ${p.title}`, ` ${p.url}`);
10803
- let nextStep;
10804
- if (resolution) nextStep = "Jira \u8FD9\u5355\u5DF2\u89E3\u51B3\u3002\u76EE\u6807\u73AF\u5883\u90E8\u7F72\u5230\u542B\u4FEE\u590D\u7684\u7248\u672C\u540E\uFF08`hcm version` \u7684 commit \u4F1A\u53D8\uFF09\uFF0C\u8DD1 `hcm skills update`\uFF0C\u518D\u6309\u6280\u80FD\u590D\u9A8C\u4E00\u6B21\u3002";
10805
- else if (issues.length && issues.every((s) => s.state === "closed")) nextStep = "\u4EA7\u54C1\u4ED3\u90A3\u6761\u5DF2\u5173\u3001Jira \u8FD8\u6CA1\u5173\uFF0C\u591A\u534A\u5728\u7B49\u53D1\u5E03\u3002\u7EE7\u7EED\u7528\u66FF\u4EE3\u6CD5\uFF0C\u53D1\u5E03\u540E\u590D\u9A8C\u3002";
10806
- else if (issues.length) nextStep = "\u4EA7\u54C1\u4ED3\u5DF2\u7ACB\u9879\u3001\u8FD8\u6CA1\u5173\u3002\u7EE7\u7EED\u7528\u66FF\u4EE3\u6CD5\uFF1B\u60F3\u8981\u6392\u671F\u5C31\u5728 Jira \u8FD9\u5355\u4E0B\u7559\u8A00\u3002";
10807
- else nextStep = `\u7B49\u5206\u8BCA\u3002\u5148\u6309\u66FF\u4EE3\u6CD5\u7EE7\u7EED\u4EA4\u4ED8\uFF0C\u62A5\u544A\u5199 BLOCKED \xB7 \u5DF2\u63D0 ${issue.key}\u3002`;
10808
- return { ref, lines, nextStep, jira: { key: issue.key, status, resolution, url: client3.browseUrl(issue.key) }, links };
10809
- }
10810
-
10811
- // src/jira/triage.ts
10812
- var GAP_PREFIX = "\u7F3A\u53E3\uFF1A";
10813
- var PENDING_STATUS = "\u65B0\u589E";
10814
- var SYNC_MARKER = "\u4EE3\u7801\u5E93\u5DF2\u5173\u95ED\uFF1A";
10815
- var bodyText = (issue, comments, remote = []) => [issue.fields.description ?? "", ...comments.map((c) => c.body ?? ""), ...remote.map((l) => l.object?.url ?? "")].join("\n");
10816
- var remoteText = (remote) => remote.map((l) => `${l.object?.url ?? ""} ${l.object?.title ?? ""}`).join("\n");
10817
- var refKeys = (text) => linkedRepoRefs(text).map((l) => `${l.repo}#${l.number}`);
10818
- async function listOpen(client3, { all = false } = {}) {
10819
- const every = await client3.search(`project = ${client3.project} AND resolution = Unresolved ORDER BY created DESC`, { max: 100 });
10820
- const picked = all ? every : every.filter((i) => i.fields.status?.name === PENDING_STATUS);
10821
- const linked = await Promise.all(picked.map((i) => client3.remoteLinks(i.key).then((r) => refKeys(remoteText(r)))));
10822
- return {
10823
- unresolved: every.length,
10824
- rows: picked.map((i, n) => ({
10825
- key: i.key,
10826
- status: i.fields.status?.name ?? "?",
10827
- priority: i.fields.priority?.name,
10828
- summary: i.fields.summary ?? "",
10829
- url: client3.browseUrl(i.key),
10830
- reporter: i.fields.reporter?.displayName,
10831
- assignee: i.fields.assignee?.displayName,
10832
- linkedRefs: linked[n] ?? [],
10833
- created: String(i.fields.created ?? "").slice(0, 10),
10834
- fromAgent: (i.fields.summary ?? "").startsWith(GAP_PREFIX)
10835
- }))
10836
- };
10837
- }
10838
- async function showIssue({ client: client3, cnb }, key2) {
10839
- const issue = await client3.issue(key2);
10840
- const comments = await client3.comments(key2);
10841
- const remoteLinks = await client3.remoteLinks(key2);
10842
- const inRemote = new Set(refKeys(remoteText(remoteLinks)));
10843
- const links = linkedRepoRefs(bodyText(issue, comments, remoteLinks)).map((l) => ({
10844
- ...cnbIssueState(cnb, l.repo, l.number),
10845
- source: inRemote.has(`${l.repo}#${l.number}`) ? "remote" : "comment"
10846
- }));
10847
- const transitions = await client3.transitions(key2);
10848
- return { issue, comments, remoteLinks, links, transitions };
10849
- }
10850
- async function commentIssue(client3, key2, body) {
10851
- await client3.addComment(key2, body);
10852
- return { key: key2, url: client3.browseUrl(key2) };
10853
- }
10854
- async function assignIssue(client3, key2, who) {
10855
- const name = who === "me" || !who ? (await client3.myself()).name ?? "" : who;
10856
- if (!name) throw new Error("\u53D6\u4E0D\u5230\u5F53\u524D\u7528\u6237\u540D\uFF0C\u65E0\u6CD5\u63A5\u624B");
10857
- await client3.assign(key2, name);
10858
- return { key: key2, who: name, transitions: await client3.transitions(key2) };
10859
- }
10860
- async function moveIssue(client3, key2, target, comment) {
10861
- const transition = await client3.transition(key2, target, comment);
10862
- return { key: key2, transition };
10863
- }
10864
- async function toIssue({ client: client3, cnb }, key2, { repo = "hcm/hcm_nx_core", force = false, priority = "P2" } = {}) {
10865
- const issue = await client3.issue(key2);
10866
- const comments = await client3.comments(key2);
10867
- const remote = await client3.remoteLinks(key2);
10868
- const existing = linkedRepoRefs(bodyText(issue, comments, remote));
10869
- if (existing.length && !force) {
10870
- const remoteText2 = remote.map((l) => `${l.object?.url ?? ""} ${l.object?.title ?? ""}`).join("\n");
10871
- const linked = [];
10872
- const alreadyLinked = [];
10873
- for (const e of existing) {
10874
- const ref = `${e.repo}#${e.number}`;
10875
- const url2 = repoIssueUrl(e.repo, e.number);
10876
- if (remoteText2.includes(url2) || remoteText2.includes(ref)) {
10877
- alreadyLinked.push(ref);
10809
+ if (c.file) {
10810
+ const file = path11.resolve(root, fill(c.file));
10811
+ const want = c.expect ?? {};
10812
+ const bad = [];
10813
+ if (want.xlsx_header || want.xlsx_min_rows !== void 0) {
10814
+ const rows = deps.readXlsx(file);
10815
+ const header = (rows[0] ?? []).map((x) => String(x).trim());
10816
+ for (const h of want.xlsx_header ?? []) if (!header.includes(h)) bad.push(`\u8868\u5934\u91CC\u6CA1\u6709\u300C${h}\u300D\uFF0C\u5B9E\u9645\u662F [${header.slice(0, 8).join(", ")}]`);
10817
+ if (want.xlsx_min_rows !== void 0 && rows.length - 1 < want.xlsx_min_rows) bad.push(`\u6570\u636E\u884C ${Math.max(rows.length - 1, 0)} \u5C11\u4E8E ${want.xlsx_min_rows}`);
10818
+ }
10819
+ if (want.text_contains) {
10820
+ const text = await deps.readText(file);
10821
+ for (const t of want.text_contains) if (!text.includes(t)) bad.push(`\u6587\u4EF6\u91CC\u6CA1\u6709\u300C${t}\u300D`);
10822
+ }
10823
+ results.push(bad.length ? { name: c.name, verdict: "fail", detail: bad.join("\uFF1B") } : { name: c.name, verdict: "pass", detail: "" });
10878
10824
  continue;
10879
10825
  }
10880
- await client3.addRemoteLink(key2, url2, `${ref} ${issue.fields.summary ?? ""}`.slice(0, 250));
10881
- linked.push(ref);
10826
+ const out = path11.join("evidence", "test", `${spec.name}-${c.name}`.replace(/[^\w一-龥-]+/g, "_") + ".png");
10827
+ const argv = ["--path", fill(c.page), "--out", out];
10828
+ if (opts.env) argv.push("--env", opts.env);
10829
+ const as = c.as ?? opts.as;
10830
+ if (as) argv.push("--as", as);
10831
+ for (const t of c.expect_text ?? []) argv.push("--expect-text", t);
10832
+ for (const t of c.reject_text ?? []) argv.push("--reject-text", t);
10833
+ const r = deps.pageAcceptance(root, argv);
10834
+ results.push(r.status === 0 ? { name: c.name, verdict: "pass", detail: out } : { name: c.name, verdict: "fail", detail: (r.stderr || r.stdout).trim().split("\n").slice(-1)[0] ?? `\u9000\u51FA\u7801 ${r.status}` });
10835
+ } catch (e) {
10836
+ results.push({ name: c.name, verdict: "fail", detail: e.message });
10882
10837
  }
10883
- return { key: key2, existing: existing.map((e) => `${e.repo}#${e.number}`), linked, alreadyLinked };
10884
- }
10885
- const title = `${issue.fields.summary ?? ""}\uFF08Jira ${key2}\uFF09`;
10886
- const body = [
10887
- `> \u6765\u81EA Jira ${key2}\uFF1A${client3.browseUrl(key2)}`,
10888
- `> \u62A5\u544A\u4EBA\uFF1A${issue.fields.reporter?.displayName ?? "?"} \u4F18\u5148\u7EA7\uFF1A${issue.fields.priority?.name ?? "-"}`,
10889
- "",
10890
- issue.fields.description || "\uFF08Jira \u6B63\u6587\u4E3A\u7A7A\uFF09"
10891
- ].join("\n");
10892
- const raw = cnb(["issues", "create-issue", "--repo", repo, "--title", title, "--body", body, "--priority", priority]);
10893
- const number = raw.match(/number:\s*"?(\d+)/)?.[1];
10894
- if (!number) throw new Error(`\u4EA7\u54C1\u4ED3 issue \u5EFA\u5931\u8D25\uFF0Ccnb \u539F\u6837\u8F93\u51FA\uFF1A
10895
- ${raw.slice(0, 500)}`);
10896
- const url = repoIssueUrl(repo, number);
10897
- await client3.addRemoteLink(key2, url, `${repo}#${number} ${issue.fields.summary ?? ""}`.slice(0, 250));
10898
- await client3.addComment(key2, `\u5DF2\u5728\u4EE3\u7801\u5E93\u767B\u8BB0\uFF1A${repo}#${number}
10899
- ${url}
10900
- \u4FEE\u590D\u5408\u5165\u540E\u56DE\u5199\u672C\u5355\u4E3A\u300C\u5DF2\u4FEE\u590D\u300D\uFF0C\u76EE\u6807\u73AF\u5883\u53D1\u5E03\u4E14\u987E\u95EE\u590D\u9A8C\u901A\u8FC7\u540E\u624D\u5173\u95ED\u3002`);
10901
- const me = (await client3.myself()).name;
10902
- if (me && issue.fields.assignee?.name !== me) await client3.assign(key2, me);
10903
- const out = { key: key2, repo, number, url };
10904
- try {
10905
- const hit = await client3.transition(key2, "\u6253\u5F00\u95EE\u9898");
10906
- out.moved = hit.to?.name;
10907
- } catch (e) {
10908
- out.moveError = e.message;
10909
10838
  }
10910
- return out;
10839
+ return results;
10911
10840
  }
10912
- async function syncIssue({ client: client3, cnb }, key2, { dryRun = false } = {}) {
10913
- const issue = await client3.issue(key2);
10914
- const comments = await client3.comments(key2);
10915
- const refs = linkedRepoRefs(bodyText(issue, comments, await client3.remoteLinks(key2)));
10916
- const links = refs.map((l) => cnbIssueState(cnb, l.repo, l.number));
10917
- const issues = links.filter((l) => l.kind === "issue");
10918
- if (!refs.length || !issues.length) return { key: key2, outcome: "no-links", links };
10919
- if (links.some((l) => l.kind === "unreadable")) return { key: key2, outcome: "blocked-unreadable", links };
10920
- const allClosed = issues.every((l) => l.state === "closed");
10921
- if (!allClosed) return { key: key2, outcome: "not-closed", links };
10922
- const already = comments.some((c) => (c.body ?? "").includes(SYNC_MARKER) || (c.body ?? "").includes("\u4EA7\u54C1\u4FA7\u5DF2\u5173\u95ED"));
10923
- if (already) return { key: key2, outcome: "already-written", links };
10924
- if (dryRun) return { key: key2, outcome: "dry-run-would-write", links };
10925
- const summary = issues.map(describeIssueState).join("\u3001");
10926
- await client3.addComment(
10927
- key2,
10928
- `${SYNC_MARKER}${summary}\u3002\u4FEE\u590D\u53EA\u662F\u8FDB\u4E86 main\u2014\u2014\u76EE\u6807\u73AF\u5883\u90E8\u7F72\u5230\u542B\u4FEE\u590D\u7684\u7248\u672C\u540E\uFF0C\u7531\u987E\u95EE\u590D\u9A8C\u901A\u8FC7\u624D\u5173\u672C\u5355\uFF08verify-pass\uFF09\uFF1B\u590D\u9A8C\u4E0D\u8FC7\u8D70 verify-fail \u9000\u56DE\u3002`
10929
- );
10930
- const out = { key: key2, outcome: "written", links };
10931
- try {
10932
- const hit = await client3.transition(key2, "\u5904\u7406\u5B8C\u6210");
10933
- out.moved = hit.to?.name;
10934
- } catch (e) {
10935
- out.moveError = e.message;
10841
+ async function loadCases(target) {
10842
+ const stat = await fs11.stat(target);
10843
+ const files = stat.isDirectory() ? (await fs11.readdir(target)).filter((f) => /\.ya?ml$/.test(f)).sort().map((f) => path11.join(target, f)) : [target];
10844
+ const out = [];
10845
+ for (const f of files) {
10846
+ const spec = yaml.load(await fs11.readFile(f, "utf8"));
10847
+ assertUsableSpec(spec, path11.basename(f));
10848
+ out.push({ file: f, spec });
10936
10849
  }
10850
+ if (out.length === 0) throw new Error(`${target} \u4E0B\u6CA1\u6709\u7528\u4F8B\uFF08*.yml\uFF09`);
10937
10851
  return out;
10938
10852
  }
10939
- async function verifyPass(client3, key2, note = "\u987E\u95EE\u5728\u76EE\u6807\u73AF\u5883\u590D\u9A8C\u901A\u8FC7\u3002") {
10940
- await client3.addComment(key2, `\u987E\u95EE\u590D\u9A8C\u901A\u8FC7\uFF1A${note}`);
10941
- const hit = await client3.transition(key2, "\u786E\u8BA4\u5173\u95ED");
10942
- return { key: key2, to: hit.to?.name, url: client3.browseUrl(key2) };
10943
- }
10944
- async function verifyFail({ client: client3, cnb }, key2, note) {
10945
- await client3.addComment(key2, `\u987E\u95EE\u590D\u9A8C\u672A\u901A\u8FC7\uFF0C\u9000\u56DE\uFF1A
10946
- ${note}`);
10947
- const out = { key: key2, reopened: [], failed: [] };
10853
+ async function chironTestCommand(target, args, deps) {
10948
10854
  try {
10949
- out.moved = (await client3.transition(key2, "\u672A\u89E3\u51B3")).to?.name;
10950
- } catch (e) {
10951
- out.moveError = e.message;
10952
- }
10953
- const issue = await client3.issue(key2);
10954
- const comments = await client3.comments(key2);
10955
- for (const l of linkedRepoRefs(bodyText(issue, comments, await client3.remoteLinks(key2)))) {
10956
- const state = cnbIssueState(cnb, l.repo, l.number);
10957
- if (state.kind !== "issue") continue;
10958
- try {
10959
- cnb(["issues", "update-issue", "--repo", l.repo, "--number", l.number, "--state", "open", "--state-reason", "reopened"]);
10960
- cnb(["issues", "post-issue-comment", "--repo", l.repo, "--number", l.number, "--body", `\u987E\u95EE\u590D\u9A8C\u672A\u901A\u8FC7\uFF0C\u91CD\u5F00\uFF08Jira ${key2}\uFF09\uFF1A
10961
- ${note}`]);
10962
- out.reopened.push(`${l.repo}#${l.number}`);
10963
- } catch {
10964
- out.failed.push(`${l.repo}#${l.number}`);
10855
+ const root = path11.resolve(args.project ?? ".");
10856
+ const where = path11.resolve(root, target ?? "tests");
10857
+ const cases = await loadCases(where);
10858
+ const report = [];
10859
+ let failed2 = 0;
10860
+ for (const { file, spec } of cases) {
10861
+ const results = await runCase(spec, root, { env: args.env, as: args.as }, deps);
10862
+ failed2 += results.filter((r) => r.verdict === "fail").length;
10863
+ report.push({ case: spec.name, file: path11.relative(root, file), results });
10965
10864
  }
10966
- }
10967
- return out;
10968
- }
10969
- async function auditIssues(client3) {
10970
- const rows = (await client3.search(`project = ${client3.project} AND resolution = Unresolved ORDER BY created DESC`, { max: 100 })).filter(
10971
- (i) => (i.fields.summary ?? "").startsWith(GAP_PREFIX)
10972
- );
10973
- const audited = [];
10974
- const bad = [];
10975
- for (const i of rows) {
10976
- const status = i.fields.status?.name ?? "?";
10977
- if (status === PENDING_STATUS) continue;
10978
- audited.push(i.key);
10979
- const remote = await client3.remoteLinks(i.key);
10980
- if (refKeys(remoteText(remote)).length) continue;
10981
- const refs = refKeys(bodyText(await client3.issue(i.key), await client3.comments(i.key), remote));
10982
- bad.push({ key: i.key, status, url: client3.browseUrl(i.key), kind: refs.length ? "comment-only" : "missing", refs });
10983
- }
10984
- return { checked: rows.length, audited, bad };
10985
- }
10986
- async function probe(client3) {
10987
- const [info, me, project] = await Promise.all([client3.serverInfo(), client3.myself(), client3.projectInfo()]);
10988
- const types = (await client3.createMeta()).map((t) => ({
10989
- id: t.id,
10990
- name: t.name,
10991
- required: (t.fields ?? []).filter((f) => f.required && !["project", "issuetype"].includes(f.fieldId)).map((f) => `${f.name}(${f.fieldId})${f.allowedValues ? `=[${f.allowedValues.slice(0, 8).map((v) => v.name ?? v.value).join("|")}]` : ""}`)
10992
- }));
10993
- const flows = (await client3.projectStatuses()).map((t) => ({ name: t.name, statuses: (t.statuses ?? []).map((s) => s.name ?? "") }));
10994
- return {
10995
- server: `Jira ${info.version ?? "?"} (${info.deploymentType ?? "?"}) @ ${client3.base}`,
10996
- me: `${me.displayName ?? "?"} <${me.emailAddress ?? me.name ?? ""}> key=${me.key ?? me.name ?? ""}`,
10997
- project: `${project.key ?? client3.project} ${project.name ?? ""} lead=${project.lead?.displayName ?? "?"}`,
10998
- types,
10999
- flows
11000
- };
11001
- }
11002
-
11003
- // src/commands/jira.ts
11004
- var defaultDeps3 = { client: () => createJiraClient(), cnb: defaultCnb };
11005
- async function triageDeps(deps) {
11006
- return { client: await deps.client(), cnb: deps.cnb };
11007
- }
11008
- function emit4(fmt, data, text) {
11009
- if (fmt === "json" || fmt === "yaml") process.stdout.write(formatObject24(data, { format: fmt }) + "\n");
11010
- else process.stdout.write(text() + "\n");
11011
- }
11012
- function readBody(opts, positional) {
11013
- if (opts.file) return readFileSync6(opts.file, "utf8");
11014
- if (opts.body) return opts.body;
11015
- if (positional && positional.trim()) return positional;
11016
- if (process.stdin.isTTY) throw new Error("\u7F3A\u6B63\u6587\uFF1A-f <\u6587\u4EF6> / --body <\u6587\u672C> / \u4F4D\u7F6E\u53C2\u6570\uFF0C\u6216\u4ECE\u6807\u51C6\u8F93\u5165\u5582");
11017
- return readFileSync6(0, "utf8");
11018
- }
11019
- async function run(fn) {
11020
- try {
11021
- await fn();
11022
- } catch (e) {
11023
- exitWithError(e);
11024
- }
11025
- }
11026
- async function jiraProbeCommand(args, deps = defaultDeps3) {
11027
- await run(async () => {
11028
- const r = await probe(await deps.client());
11029
- emit4(
11030
- args.output,
11031
- r,
11032
- () => [
11033
- r.server,
11034
- `\u6211\u662F\uFF1A${r.me}`,
11035
- `\u9879\u76EE\uFF1A${r.project}`,
11036
- ...r.types.map((t) => `issuetype ${t.name}(${t.id}) \u5FC5\u586B\uFF1A${t.required.join(" \xB7 ") || "\uFF08\u65E0\uFF09"}`),
11037
- ...r.flows.map((f) => `\u72B6\u6001\u6D41 ${f.name}\uFF1A${f.statuses.join(" \u2192 ")}`)
11038
- ].join("\n")
11039
- );
11040
- });
11041
- }
11042
- async function jiraOpenCommand(args, deps = defaultDeps3) {
11043
- await run(async () => {
11044
- const r = await listOpen(await deps.client(), { all: !!args.all });
11045
- emit4(args.output, r, () => {
11046
- if (!r.rows.length) return args.all ? "\u9879\u76EE\u91CC\u6CA1\u6709\u672A\u89E3\u51B3\u7684\u5355\u3002" : `\u6CA1\u6709\u5F85\u5206\u8BCA\uFF08\u72B6\u6001\u300C\u65B0\u589E\u300D\uFF09\u7684\u5355\uFF1B\u9879\u76EE\u91CC\u672A\u89E3\u51B3\u7684\u5171 ${r.unresolved} \u6761\uFF0C\u770B\u5168\u90E8\u52A0 --all\u3002`;
11047
- return r.rows.map(
11048
- (i) => `${i.key} [${i.status}${i.priority ? " " + i.priority : ""}]${i.fromAgent ? "" : " \uFF08\u975E agent \u63D0\u5355\uFF09"} ${i.summary}
11049
- ${i.url} \u62A5\u544A\u4EBA ${i.reporter ?? "?"} \u7ECF\u529E\u4EBA ${i.assignee ?? "\u672A\u63A5\u624B"} \u6761\u76EE ${i.linkedRefs.join(" / ") || "\u94FE\u63A5\u680F\u672A\u6302"} ${i.created}`
11050
- ).join("\n");
11051
- });
11052
- });
11053
- }
11054
- async function jiraShowCommand(key2, args, deps = defaultDeps3) {
11055
- await run(async () => {
11056
- const d = await triageDeps(deps);
11057
- const r = await showIssue(d, key2);
11058
- const i = r.issue;
11059
- emit4(args.output, r, () => {
11060
- const out = [
11061
- `${i.key} [${i.fields.status?.name}${i.fields.resolution ? "\xB7" + i.fields.resolution.name : ""}${i.fields.priority ? " " + i.fields.priority.name : ""}] ${i.fields.summary ?? ""}`,
11062
- `${d.client.browseUrl(i.key)} \u62A5\u544A\u4EBA ${i.fields.reporter?.displayName ?? "?"} \u7ECF\u529E\u4EBA ${i.fields.assignee?.displayName ?? "-"} \u6807\u7B7E ${(i.fields.labels ?? []).join(",") || "-"}`,
11063
- "",
11064
- "--- \u6B63\u6587 ---",
11065
- i.fields.description || "\uFF08\u7A7A\uFF09"
11066
- ];
11067
- for (const c of r.comments) out.push("", `--- \u8BC4\u8BBA ${c.author?.displayName ?? "?"} ${String(c.created ?? "").slice(0, 10)} ---`, c.body ?? "");
11068
- for (const l of r.links)
11069
- out.push("", `\u5173\u8054\u4EE3\u7801\u5E93 ${describeIssueState(l)}${l.source === "comment" ? ` \uFF08\u4EC5\u89C1\u4E8E\u8BC4\u8BBA\uFF0C\u300C\u94FE\u63A5\u300D\u680F\u672A\u6302\uFF1Bhcm jira to-issue ${i.key} \u53EF\u8865\u6302\uFF09` : ""}`);
11070
- out.push("", `\u53EF\u7528\u6D41\u8F6C\uFF1A${r.transitions.map((t) => `${t.name}\u2192${t.to?.name}`).join(" / ") || "\uFF08\u65E0\uFF09"}`);
11071
- return out.join("\n");
11072
- });
11073
- });
11074
- }
11075
- async function jiraCommentCommand(key2, text, args, deps = defaultDeps3) {
11076
- await run(async () => {
11077
- const body = readBody(args, text);
11078
- const r = await commentIssue(await deps.client(), key2, body);
11079
- emit4(args.output, r, () => `\u5DF2\u56DE\u590D ${r.key}\uFF1A${r.url}`);
11080
- });
11081
- }
11082
- async function jiraAssignCommand(key2, who, args, deps = defaultDeps3) {
11083
- await run(async () => {
11084
- const r = await assignIssue(await deps.client(), key2, who);
11085
- emit4(args.output, r, () => `${r.key} \u5DF2\u6539\u6D3E\u7ED9 ${r.who}\u3002\u73B0\u5728\u53EF\u505A\u7684\u6D41\u8F6C\uFF1A${r.transitions.map((x) => `${x.name}\u2192${x.to?.name}`).join(" / ") || "\uFF08\u65E0\uFF09"}`);
11086
- });
11087
- }
11088
- async function jiraMoveCommand(key2, target, args, deps = defaultDeps3) {
11089
- await run(async () => {
11090
- const comment = args.file || args.body ? readBody(args) : void 0;
11091
- const r = await moveIssue(await deps.client(), key2, target, comment);
11092
- emit4(args.output, r, () => `${r.key} \u5DF2\u6D41\u8F6C\uFF1A${r.transition.name} \u2192 ${r.transition.to?.name}`);
11093
- });
11094
- }
11095
- async function jiraToIssueCommand(key2, args, deps = defaultDeps3) {
11096
- await run(async () => {
11097
- const r = await toIssue(await triageDeps(deps), key2, { repo: args.repo, force: !!args.force });
11098
- emit4(args.output, r, () => {
11099
- if ("existing" in r) {
11100
- const parts = [`${r.key} \u5DF2\u5173\u8054 ${r.existing.join("\u3001")}\uFF0C\u4E0D\u91CD\u590D\u5EFA\u3002\u8981\u518D\u5EFA\u52A0 --force`];
11101
- if (r.linked.length) parts.push(`\u5DF2\u8865\u6302\u8FDC\u7A0B\u94FE\u63A5\uFF1A${r.linked.join("\u3001")}\uFF08\u539F\u5148\u53EA\u5199\u5728\u6B63\u6587/\u8BC4\u8BBA\u91CC\uFF0CJira\u300C\u94FE\u63A5\u300D\u680F\u770B\u4E0D\u5230\uFF09`);
11102
- else if (r.alreadyLinked.length) parts.push("\u8FDC\u7A0B\u94FE\u63A5\u5DF2\u9F50\uFF0C\u65E0\u9700\u8865\u6302");
11103
- return parts.join("\n");
11104
- }
11105
- const moved = r.moved ? `\uFF0C\u5DF2\u63A8\u8FDB\u5230 ${r.moved}` : r.moveError ? `\uFF0C\u4F46\u6CA1\u80FD\u63A8\u8FDB\u72B6\u6001\uFF1A${r.moveError}` : "";
11106
- return `${r.key} \u2192 ${r.repo}#${r.number} ${r.url}${moved}`;
11107
- });
11108
- });
11109
- }
11110
- async function jiraSyncCommand(key2, args, deps = defaultDeps3) {
11111
- await run(async () => {
11112
- const r = await syncIssue(await triageDeps(deps), key2, { dryRun: !!args.dryRun });
11113
- emit4(args.output, r, () => {
11114
- const links = r.links.map(describeIssueState).join("\u3001") || "\uFF08\u65E0\uFF09";
11115
- switch (r.outcome) {
11116
- case "written":
11117
- return `${r.key} \u5DF2\u56DE\u5199\uFF1A${links}${r.moved ? ` \u5E76\u63A8\u8FDB\u5230 ${r.moved}` : r.moveError ? `\uFF08\u72B6\u6001\u6CA1\u63A8\u52A8\uFF1A${r.moveError}\uFF09` : ""}`;
11118
- case "dry-run-would-write":
11119
- return `${r.key} \u4EE3\u7801\u5E93\u6761\u76EE\u5DF2\u5168\u5173\uFF0C\u5B9E\u8DD1\u4F1A\u56DE\u5199\u5E76\u63A8\u300C\u5904\u7406\u5B8C\u6210\u300D\uFF1A${links}`;
11120
- case "already-written":
11121
- return `${r.key} \u5DF2\u56DE\u5199\u8FC7\uFF0C\u8DF3\u8FC7\uFF1A${links}`;
11122
- case "not-closed":
11123
- return `${r.key} \u4EA7\u54C1\u4ED3\u8FD8\u6CA1\u5173\uFF1A${links}`;
11124
- case "blocked-unreadable":
11125
- return `${r.key} \u6709\u8BFB\u4E0D\u5230\u7684\u4EE3\u7801\u5E93\u6761\u76EE\uFF0C\u4E0D\u6562\u5224\u5DF2\u5173\uFF08fail-closed\uFF09\uFF1A${links}`;
11126
- default:
11127
- return `${r.key} \u6CA1\u6709\u5173\u8054\u7684\u4EA7\u54C1\u4ED3 issue\uFF08PR \u53F7\u4E0D\u7B97\uFF09\uFF0C\u5148 to-issue\uFF1A${links}`;
11128
- }
11129
- });
11130
- if (r.outcome === "blocked-unreadable") process.exitCode = 1;
11131
- });
11132
- }
11133
- async function jiraVerifyPassCommand(key2, note, args, deps = defaultDeps3) {
11134
- await run(async () => {
11135
- const text = args.file || args.body || note && note.trim() ? readBody(args, note) : "\u987E\u95EE\u5728\u76EE\u6807\u73AF\u5883\u590D\u9A8C\u901A\u8FC7\u3002";
11136
- const r = await verifyPass(await deps.client(), key2, text);
11137
- emit4(args.output, r, () => `${r.key} \u5DF2\u5173\u95ED\uFF08${r.to ?? "?"}\uFF09\uFF1A${r.url}`);
11138
- });
11139
- }
11140
- async function jiraVerifyFailCommand(key2, note, args, deps = defaultDeps3) {
11141
- await run(async () => {
11142
- const r = await verifyFail(await triageDeps(deps), key2, readBody(args, note));
11143
- emit4(args.output, r, () => {
11144
- const moved = r.moved ? `\u5DF2\u9000\u56DE\u5230 ${r.moved}` : `\u72B6\u6001\u6CA1\u9000\u56DE\uFF08${r.moveError ?? "?"}\uFF09`;
11145
- const failed2 = r.failed.length ? `\uFF1B\u91CD\u5F00\u5931\u8D25\uFF1A${r.failed.join("\u3001")}` : "";
11146
- return `${r.key} ${moved}\uFF1B\u5DF2\u91CD\u5F00 ${r.reopened.join("\u3001") || "\uFF08\u6CA1\u6709\u53EF\u91CD\u5F00\u7684\u4EE3\u7801\u5E93\u6761\u76EE\uFF09"}${failed2}`;
11147
- });
11148
- });
11149
- }
11150
- async function jiraAuditCommand(args, deps = defaultDeps3) {
11151
- await run(async () => {
11152
- const r = await auditIssues(await deps.client());
11153
- emit4(args.output, r, () => {
11154
- if (!r.checked) return "\u9879\u76EE\u91CC\u6CA1\u6709\u672A\u89E3\u51B3\u7684\u7F3A\u53E3\u5355\u3002";
11155
- const lines = [`\u672C\u8F6E\u6838\u8FC7 ${r.audited.length} \u6761\u5DF2\u53D7\u7406\u7684\u5355\uFF08\u672A\u89E3\u51B3\u5171 ${r.checked} \u6761\uFF0C\u300C\u65B0\u589E\u300D\u7684\u4E0D\u7B97\uFF09\u3002`];
11156
- for (const b of r.bad) {
11157
- lines.push(
11158
- b.kind === "comment-only" ? `\u26A0\uFE0F ${b.key} [${b.status}] \u6761\u76EE\u53EA\u5199\u5728\u8BC4\u8BBA\u91CC\u3001\u300C\u94FE\u63A5\u300D\u680F\u662F\u7A7A\u7684\uFF1A${b.refs.join(" / ")}
11159
- ${b.url}
11160
- \u8865\u6302\uFF1Ahcm jira to-issue ${b.key}` : `\u26A0\uFE0F ${b.key} [${b.status}] \u6CA1\u6709\u4EFB\u4F55\u4EE3\u7801\u5E93\u6761\u76EE\uFF1A${b.url}
11161
- \u5148\u5206\u8BCA\uFF1Ahcm jira to-issue ${b.key} --repo hcm/hcm_nx_core`
11162
- );
10865
+ const fmt = args.output ?? "table";
10866
+ if (fmt === "json" || fmt === "yaml") {
10867
+ process.stdout.write(formatObject25({ ok: failed2 === 0, failed: failed2, cases: report }, { format: fmt }) + "\n");
10868
+ } else {
10869
+ for (const c of report) {
10870
+ process.stdout.write(`
10871
+ ${c.case}\uFF08${c.file}\uFF09
10872
+ `);
10873
+ for (const r of c.results) {
10874
+ const mark = r.verdict === "pass" ? "\u2705" : r.verdict === "step" ? "\xB7" : r.verdict === "warn" ? "\u26A0\uFE0F" : "\u274C";
10875
+ process.stdout.write(` ${mark} ${r.name}${r.detail ? ` ${r.detail}` : ""}
10876
+ `);
10877
+ }
11163
10878
  }
11164
- if (!r.audited.length) lines.push("\u6CA1\u6709\u5DF2\u53D7\u7406\u7684\u5355\uFF0C\u672C\u8F6E\u4EC0\u4E48\u90FD\u6CA1\u6838\u5230\u3002");
11165
- else if (!r.bad.length) lines.push("\u4E00\u81F4\uFF1A\u5DF2\u53D7\u7406\u7684\u5355\u90FD\u628A\u4EE3\u7801\u5E93\u6761\u76EE\u6302\u5728\u300C\u94FE\u63A5\u300D\u680F\u91CC\u3002");
11166
- return lines.join("\n");
11167
- });
11168
- if (r.bad.length) process.exitCode = 1;
11169
- });
11170
- }
11171
- async function jiraSearchCommand(keywords, args, deps = defaultDeps3) {
11172
- await run(async () => {
11173
- if (!keywords.length) throw new Error("\u7ED9\u81F3\u5C11\u4E00\u4E2A\u5173\u952E\u8BCD\uFF1A\u9519\u8BEF\u7801 / Model / Action / \u4E00\u53E5\u73B0\u8C61");
11174
- const r = await gapSearch(await triageDeps(deps), keywords, { includeClosed: args.includeClosed !== false });
11175
- emit4(args.output, r, () => {
11176
- const head = r.jiraError ? `\u26A0\uFE0F Jira \u6CA1\u67E5\u6210\uFF08${r.jiraError}\uFF09\uFF0C\u4E0B\u9762\u53EA\u6709\u4EA7\u54C1\u4ED3\u7684\u7ED3\u679C\uFF0C\u4E0D\u4EE3\u8868 Jira \u91CC\u6CA1\u6709\u3002
11177
- ` : "";
11178
- if (!r.rows.length) return `${head}Jira \u4E0E\u4EA7\u54C1\u4ED3\u90FD\u6CA1\u6709\u76F8\u5173\u8BB0\u5F55\u3002\u53EF\u4EE5 submit\uFF0C\u4F46\u5148\u628A\u4E09\u95EE\u7B54\u5B8C\u3002`;
11179
- return `${head}\u547D\u4E2D ${r.rows.length} \u6761\uFF08\u540C\u4E00\u7F3A\u53E3\u5DF2\u6709\u7F16\u53F7\u5C31\u5728\u90A3\u6761\u4E0B\u8FFD\u52A0\u73B0\u573A\uFF0C\u4E0D\u65B0\u5F00\uFF09\uFF1A
11180
- ${r.rows.map((i) => `${i.where} ${i.id} [${i.state}${i.resolution ? "\xB7" + i.resolution : ""}] ${i.title}
11181
- ${i.url}`).join("\n")}`;
11182
- });
11183
- });
11184
- }
11185
- async function jiraStatusCommand(ref, args, deps = defaultDeps3) {
11186
- await run(async () => {
11187
- const r = await gapStatus(await triageDeps(deps), ref);
11188
- emit4(args.output, r, () => [...r.lines, `\u4E0B\u4E00\u6B65\uFF1A${r.nextStep}`].join("\n"));
11189
- });
11190
- }
11191
- async function fingerprintText(env2) {
11192
- try {
11193
- const g = await loadGlobalConfig11();
11194
- const name = resolveActiveEnv5({ envFlag: env2 }, process.env, g);
11195
- const cfg = await loadEnv11(name);
11196
- if (!cfg?.endpoint) return `\u672A\u53D6\u5230\u6307\u7EB9\uFF08env=${name}\uFF1A\u6CA1\u6709 endpoint\uFF09`;
11197
- const http = createHttpClient4({ endpoint: cfg.endpoint.replace(/\/+$/, ""), getAccessToken: async () => null, onRefresh: async () => {
11198
- } });
11199
- const resp = await http.get("/api/version/backend");
11200
- const info = resp.data?.data ?? resp.data ?? {};
11201
- const commit = info.commit ?? info.gitCommit ?? info.version ?? "?";
11202
- return `backend ${String(commit).slice(0, 12)} \xB7 CLI ${CLI_VERSION} \xB7 env ${name}`;
10879
+ const verified = report.reduce((n, c) => n + c.results.filter((r) => r.verdict === "pass").length, 0);
10880
+ process.stdout.write(failed2 === 0 ? `
10881
+ \u5168\u90E8\u901A\u8FC7\uFF08\u771F\u5224\u8FC7\u5185\u5BB9\u7684 ${verified} \u6761\uFF1B\u5E26 \xB7 \u7684\u662F\u6B65\u9AA4\uFF0C\u4E0D\u7B97\u9A8C\u8BC1\uFF09\u3002
10882
+ ` : `
10883
+ ${failed2} \u6761\u6CA1\u8FC7\u2014\u2014\u4E0A\u9762\u6BCF\u6761\u90FD\u5199\u4E86\u5B9E\u9645\u503C\u4E0E\u671F\u671B\uFF0C\u7167\u7740\u67E5\u3002
10884
+ `);
10885
+ }
10886
+ process.exitCode = failed2 === 0 ? 0 : 1;
11203
10887
  } catch (e) {
11204
- return `\u672A\u53D6\u5230\u6307\u7EB9\uFF08env=${env2 ?? "\u672A\u8BBE"}\uFF1B${String(e.message ?? e).split("\n")[0]?.slice(0, 120)}\uFF09`;
10888
+ exitWithError(e);
11205
10889
  }
11206
10890
  }
11207
- async function jiraSubmitCommand(args, deps = defaultDeps3) {
11208
- await run(async () => {
11209
- const raw = args.file ? readFileSync6(args.file, "utf8") : process.stdin.isTTY ? "" : readFileSync6(0, "utf8");
11210
- if (!raw.trim()) throw new Error("\u7F3A\u53E3\u8F7D\u8377\uFF1A--file <gap.json> \u6216\u4ECE\u6807\u51C6\u8F93\u5165\u5582 JSON");
11211
- const gap = validateGapInput(JSON.parse(raw));
11212
- const fp = args.fingerprint ?? await fingerprintText(args.env);
11213
- const r = await gapSubmit(await triageDeps(deps), gap, { fingerprintText: fp, issuetypeOverride: args.issuetype, assigneeOverride: args.assignee });
11214
- emit4(
11215
- args.output,
11216
- r,
11217
- () => r.outcome === "appended" ? `Jira \u91CC\u5DF2\u6709\u540C\u4E00\u7F3A\u53E3 ${r.key}\u300C${r.summary}\u300D\uFF0C\u5DF2\u8FFD\u52A0\u300C\u53C8\u4E00\u4E2A\u73B0\u573A\u300D\u8BC4\u8BBA\uFF0C\u6CA1\u6709\u65B0\u5F00\u3002
11218
- ${r.url}
11219
- \u7ED9\u987E\u95EE\u7684\u8BDD\uFF1A\u8FD9\u4E2A\u95EE\u9898\u5DF2\u7ECF\u5728\u4EA7\u54C1\u90A3\u8FB9\u6392\u7740\uFF0C\u7F16\u53F7 ${r.key}\uFF1B\u5148\u7528\u66FF\u4EE3\u6CD5\u300C${r.alternative}\u300D\u7EE7\u7EED\uFF0C\u5206\u8BCA\u7ED3\u8BBA\u4F1A\u56DE\u5230\u90A3\u5355\u91CC\u3002` : `\u5DF2\u63D0 ${r.key}\uFF08${r.type} \xB7 ${r.module}\uFF09\uFF1A${r.url}
11220
- \u7ED9\u987E\u95EE\u7684\u8BDD\uFF1A\u7F3A\u53E3\u5DF2\u63D0\uFF0C\u7F16\u53F7 ${r.key}\uFF1B\u5148\u7528\u66FF\u4EE3\u6CD5\u300C${r.alternative}\u300D\u7EE7\u7EED\uFF0C\u4EA7\u54C1\u5206\u8BCA\u540E\u4F1A\u5728\u90A3\u5355\u91CC\u56DE\u590D\u3002\u62A5\u544A\u91CC\u5199\u300CBLOCKED \xB7 \u5DF2\u63D0 ${r.key} \xB7 \u66FF\u4EE3\u6CD5\uFF1A${r.alternative}\u300D\u3002`
11221
- );
11222
- });
11223
- }
11224
10891
 
11225
10892
  // src/commands/delivery-recon.ts
11226
10893
  init_auth_guard();
@@ -11230,7 +10897,7 @@ import {
11230
10897
  ReconLayout,
11231
10898
  ROUND_EXIT_CODES,
11232
10899
  computeReconSourceKey,
11233
- formatObject as formatObject25,
10900
+ formatObject as formatObject26,
11234
10901
  fromAxiosError as fromAxiosError21,
11235
10902
  httpProbe as httpProbe3,
11236
10903
  inspectRound,
@@ -11242,15 +10909,15 @@ async function deliveryReconCommand(args) {
11242
10909
  try {
11243
10910
  const ctx = await getActiveAuthContextFromCli(args);
11244
10911
  const client3 = HcmClient23.fromAuthContext(ctx);
11245
- const probe2 = httpProbe3(client3.raw(), args.capabilities ?? DEFAULT_CAPABILITIES);
11246
- const sourceKey = await computeReconSourceKey(probe2);
10912
+ const probe = httpProbe3(client3.raw(), args.capabilities ?? DEFAULT_CAPABILITIES);
10913
+ const sourceKey = await computeReconSourceKey(probe);
11247
10914
  const layout = new ReconLayout(args.out ?? ".", ctx.tenantId, sourceKey);
11248
- const summary = await runRecon(probe2, layout, {
10915
+ const summary = await runRecon(probe, layout, {
11249
10916
  state: args.state ?? "",
11250
10917
  onlyModel: args.model ?? null,
11251
10918
  identity: ctx.tenantId ? { requestedTenantId: ctx.tenantId } : null
11252
10919
  });
11253
- process.stdout.write(formatObject25(summary, { format: args.output ?? "json" }) + "\n");
10920
+ process.stdout.write(formatObject26(summary, { format: args.output ?? "json" }) + "\n");
11254
10921
  } catch (e) {
11255
10922
  const err = e;
11256
10923
  if (err?.isAxiosError) exitWithError(fromAxiosError21(err, args.env));
@@ -11264,7 +10931,7 @@ async function deliveryReconRoundCommand(args) {
11264
10931
  const result = inspectRound(args.dir ?? ".");
11265
10932
  const fmt = args.output ?? "json";
11266
10933
  if (fmt !== "json") process.stdout.write(renderRound(result));
11267
- process.stdout.write(formatObject25(result, { format: fmt }) + "\n");
10934
+ process.stdout.write(formatObject26(result, { format: fmt }) + "\n");
11268
10935
  code = ROUND_EXIT_CODES[result.state];
11269
10936
  } catch (e) {
11270
10937
  exitWithError(e);
@@ -11333,8 +11000,8 @@ import {
11333
11000
  writeImportPlan,
11334
11001
  writeRisk
11335
11002
  } from "@hcmai/sdk";
11336
- import { existsSync as existsSync2 } from "fs";
11337
- import * as path11 from "path";
11003
+ import { existsSync as existsSync3 } from "fs";
11004
+ import * as path12 from "path";
11338
11005
  function premise(message, hint = "") {
11339
11006
  process.stderr.write(message + (hint ? `
11340
11007
  \u2192 ${hint}` : "") + "\n");
@@ -11345,7 +11012,7 @@ async function runSeedPlan(args, client3) {
11345
11012
  const tenant2 = tenantOf(client3);
11346
11013
  const work = seedWorkDir({ out, tenant: tenant2, work: args.work ?? null, mapping: args.mapping ?? null });
11347
11014
  const mappingPath = seedMappingPath({ out, tenant: tenant2, mapping: args.mapping ?? null }, work);
11348
- if (!existsSync2(mappingPath)) {
11015
+ if (!existsSync3(mappingPath)) {
11349
11016
  return premise(
11350
11017
  `\u8BFB\u4E0D\u5230\u5BFC\u5165\u6620\u5C04\u5DE5\u4EF6\uFF1A${mappingPath}`,
11351
11018
  "\u5DE5\u4EF6\u662F\u987E\u95EE\u81EA\u5DF1\u5199\u7684\uFF08\u5951\u7EA6\u89C1 README \u7684 `work/mapping.json` \u4E00\u8282\uFF09\u3002\u5199\u5728\u522B\u5904\u5C31\u7528 `--mapping <\u8DEF\u5F84>` \u6307\u8FC7\u53BB\uFF0C\u6216\u7528 `--work <\u76EE\u5F55>` \u6362 work \u76EE\u5F55\u3002"
@@ -11361,13 +11028,13 @@ async function runSeedPlan(args, client3) {
11361
11028
  const reconDir = candidates[0].reconDir;
11362
11029
  if (candidates.length > 1) {
11363
11030
  process.stderr.write(
11364
- `\u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u6709 ${candidates.length} \u4EFD\u57FA\u7EBF\uFF0C\u672C\u8F6E\u8BFB\u7684\u662F \`${path11.basename(reconDir)}\`\uFF1A` + candidates.slice(1).map((c) => `\`${path11.basename(c.reconDir)}\``).join("\u3001") + " \u672A\u88AB\u8BFB\u53D6 \u2014\u2014 \u4E0D\u540C sourceKey \u7684\u4EA7\u7269**\u4E0D\u53EF\u4E92\u6362**\u3002\n"
11031
+ `\u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u6709 ${candidates.length} \u4EFD\u57FA\u7EBF\uFF0C\u672C\u8F6E\u8BFB\u7684\u662F \`${path12.basename(reconDir)}\`\uFF1A` + candidates.slice(1).map((c) => `\`${path12.basename(c.reconDir)}\``).join("\u3001") + " \u672A\u88AB\u8BFB\u53D6 \u2014\u2014 \u4E0D\u540C sourceKey \u7684\u4EA7\u7269**\u4E0D\u53EF\u4E92\u6362**\u3002\n"
11365
11032
  );
11366
11033
  }
11367
11034
  const round = inspectRound2(reconDir);
11368
11035
  process.stderr.write(roundWarning(round));
11369
11036
  const baseline = {
11370
- path: `${path11.basename(path11.dirname(reconDir))}/${path11.basename(reconDir)}`,
11037
+ path: `${path12.basename(path12.dirname(reconDir))}/${path12.basename(reconDir)}`,
11371
11038
  roundId: round.roundId ?? null
11372
11039
  };
11373
11040
  let exemptions = null;
@@ -11627,9 +11294,9 @@ async function deliverySeedVerifyCommand(args) {
11627
11294
  }
11628
11295
 
11629
11296
  // src/commands/delivery-seed-find.ts
11630
- import { existsSync as existsSync3 } from "fs";
11631
- import { readFileSync as readFileSync7 } from "fs";
11632
- import * as path12 from "path";
11297
+ import { existsSync as existsSync4 } from "fs";
11298
+ import { readFileSync as readFileSync8 } from "fs";
11299
+ import * as path13 from "path";
11633
11300
  import {
11634
11301
  INIT_EXIT_CODES as INIT_EXIT_CODES2,
11635
11302
  ValueHints,
@@ -11643,10 +11310,10 @@ import {
11643
11310
  valuesRoundCaveat
11644
11311
  } from "@hcmai/sdk";
11645
11312
  function provenance(chosenReconDir, others) {
11646
- let line = `> \u57FA\u7EBF\uFF1A\`${path12.basename(chosenReconDir)}\`
11313
+ let line = `> \u57FA\u7EBF\uFF1A\`${path13.basename(chosenReconDir)}\`
11647
11314
  `;
11648
11315
  if (others.length > 0) {
11649
- line += `> \u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u53E6\u6709 ${others.length} \u4EFD\u57FA\u7EBF\u672A\u88AB\u8BFB\u53D6\uFF1A` + others.map((o) => `\`${path12.basename(o)}\``).join("\u3001") + " \u2014\u2014 \u4E0D\u540C sourceKey \u7684\u4EA7\u7269**\u4E0D\u53EF\u4E92\u6362**\u3002\n";
11316
+ line += `> \u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u53E6\u6709 ${others.length} \u4EFD\u57FA\u7EBF\u672A\u88AB\u8BFB\u53D6\uFF1A` + others.map((o) => `\`${path13.basename(o)}\``).join("\u3001") + " \u2014\u2014 \u4E0D\u540C sourceKey \u7684\u4EA7\u7269**\u4E0D\u53EF\u4E92\u6362**\u3002\n";
11650
11317
  }
11651
11318
  return `${line}
11652
11319
  `;
@@ -11688,10 +11355,10 @@ function runSeedFind(args) {
11688
11355
  const chosen = { reconDir: picked.reconDir, indexFile: picked.indexFile };
11689
11356
  const prefix = picked.prefix;
11690
11357
  process.stdout.write(prefix);
11691
- if (!existsSync3(chosen.indexFile)) {
11358
+ if (!existsSync4(chosen.indexFile)) {
11692
11359
  return premise2(`\u7D22\u5F15\u6587\u4EF6\u5728\u9009\u4E2D\u4E4B\u540E\u6D88\u5931\u4E86\uFF1A${chosen.indexFile}`);
11693
11360
  }
11694
- const { rows, problems } = loadRows(readFileSync7(chosen.indexFile, "utf-8"));
11361
+ const { rows, problems } = loadRows(readFileSync8(chosen.indexFile, "utf-8"));
11695
11362
  process.stdout.write(
11696
11363
  renderFind(find(rows, args.term), args.term, rows.length, {
11697
11364
  prefixBytes: Buffer.byteLength(prefix, "utf-8"),
@@ -11731,7 +11398,7 @@ function deliverySeedValuesCommand(model, args) {
11731
11398
 
11732
11399
  // src/commands/delivery-meta.ts
11733
11400
  init_auth_guard();
11734
- import { readFileSync as readFileSync8 } from "fs";
11401
+ import { readFileSync as readFileSync9 } from "fs";
11735
11402
  import {
11736
11403
  BINDING_WORDS,
11737
11404
  CHANGE_STATES,
@@ -11879,7 +11546,7 @@ function premise3(what, hint) {
11879
11546
  async function runDeliveryMeta(args, client3) {
11880
11547
  let content;
11881
11548
  try {
11882
- content = readFileSync8(args.contentFile, "utf-8");
11549
+ content = readFileSync9(args.contentFile, "utf-8");
11883
11550
  } catch (e) {
11884
11551
  return premise3(
11885
11552
  `\u8981\u5199\u8FDB\u53BB\u7684\u6B63\u6587\u8BFB\u4E0D\u51FA\u6765\uFF1A${e.message}`,
@@ -11982,8 +11649,8 @@ import {
11982
11649
  ReconLayout as ReconLayout2,
11983
11650
  runTriageRound
11984
11651
  } from "@hcmai/sdk";
11985
- import { mkdirSync, readFileSync as readFileSync9, writeFileSync as writeFileSync2 } from "fs";
11986
- import * as path13 from "path";
11652
+ import { mkdirSync as mkdirSync2, readFileSync as readFileSync10, writeFileSync as writeFileSync3 } from "fs";
11653
+ import * as path14 from "path";
11987
11654
  var DEFAULT_CAPABILITIES3 = "default";
11988
11655
  function premise4(message, hint) {
11989
11656
  process.stderr.write(`\u{1F534} \u524D\u63D0\u4E0D\u6210\u7ACB\uFF1A${message}
@@ -11996,7 +11663,7 @@ var REQUESTS_SHAPE = "`--requests` \u6536\u7684\u662F\u4E00\u4E2A JSON \u6570\u7
11996
11663
  function readRequests(file) {
11997
11664
  let raw;
11998
11665
  try {
11999
- raw = JSON.parse(readFileSync9(file, "utf8"));
11666
+ raw = JSON.parse(readFileSync10(file, "utf8"));
12000
11667
  } catch (e) {
12001
11668
  throw new Error(`\u9700\u6C42\u6E05\u5355\u8BFB\u4E0D\u51FA\u6765\uFF08${file}\uFF09\uFF1A${e instanceof Error ? e.message : String(e)}`);
12002
11669
  }
@@ -12019,9 +11686,9 @@ function renderProblems(rows) {
12019
11686
  `;
12020
11687
  }
12021
11688
  function writeTriageArtifact(outDir, body) {
12022
- const out = path13.join(outDir, "work", "triage.md");
12023
- mkdirSync(path13.dirname(out), { recursive: true });
12024
- writeFileSync2(out, body, "utf8");
11689
+ const out = path14.join(outDir, "work", "triage.md");
11690
+ mkdirSync2(path14.dirname(out), { recursive: true });
11691
+ writeFileSync3(out, body, "utf8");
12025
11692
  return out;
12026
11693
  }
12027
11694
  async function runTriage(args) {
@@ -12034,9 +11701,9 @@ async function runTriage(args) {
12034
11701
  }
12035
11702
  const ctx = await getActiveAuthContextFromCli(args);
12036
11703
  const client3 = HcmClient26.fromAuthContext(ctx);
12037
- const probe2 = httpProbe4(client3.raw(), args.capabilities ?? DEFAULT_CAPABILITIES3);
12038
- const artifactsDir = args.recon ?? new ReconLayout2(args.out ?? ".", ctx.tenantId, await computeReconSourceKey2(probe2)).dir;
12039
- const result = await runTriageRound(probe2, artifactsDir, entriesIn);
11704
+ const probe = httpProbe4(client3.raw(), args.capabilities ?? DEFAULT_CAPABILITIES3);
11705
+ const artifactsDir = args.recon ?? new ReconLayout2(args.out ?? ".", ctx.tenantId, await computeReconSourceKey2(probe)).dir;
11706
+ const result = await runTriageRound(probe, artifactsDir, entriesIn);
12040
11707
  if (result.body === null) {
12041
11708
  process.stdout.write(renderProblems(result.problems));
12042
11709
  return 1;
@@ -12064,23 +11731,23 @@ init_exit();
12064
11731
  import {
12065
11732
  HcmClient as HcmClient27,
12066
11733
  adminResetPassword,
12067
- formatObject as formatObject26,
11734
+ formatObject as formatObject27,
12068
11735
  fromAxiosError as fromAxiosError22,
12069
- CliError as CliError24,
12070
- CliErrorCode as CliErrorCode22
11736
+ CliError as CliError25,
11737
+ CliErrorCode as CliErrorCode23
12071
11738
  } from "@hcmai/sdk";
12072
11739
  function buildAdminResetPasswordRequest(args, password) {
12073
11740
  const hasId = Boolean(args.id);
12074
11741
  const hasUsername = Boolean(args.username);
12075
11742
  if (hasId === hasUsername) {
12076
- throw new CliError24({
12077
- code: CliErrorCode22.INVALID_ARGUMENT,
11743
+ throw new CliError25({
11744
+ code: CliErrorCode23.INVALID_ARGUMENT,
12078
11745
  message: "--id <uuid> \u4E0E --username <user> \u5FC5\u987B\u4E14\u53EA\u80FD\u63D0\u4F9B\u4E00\u4E2A"
12079
11746
  });
12080
11747
  }
12081
11748
  if (!password) {
12082
- throw new CliError24({
12083
- code: CliErrorCode22.INVALID_ARGUMENT,
11749
+ throw new CliError25({
11750
+ code: CliErrorCode23.INVALID_ARGUMENT,
12084
11751
  message: "\u65B0\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A"
12085
11752
  });
12086
11753
  }
@@ -12098,7 +11765,7 @@ async function userResetPasswordCommand(args) {
12098
11765
  const request = buildAdminResetPasswordRequest(args, password);
12099
11766
  const client3 = HcmClient27.fromAuthContext(await getActiveAuthContextFromCli(args));
12100
11767
  const result = await adminResetPassword(client3.raw(), request);
12101
- process.stdout.write(formatObject26(result, { format: args.output ?? "json" }) + "\n");
11768
+ process.stdout.write(formatObject27(result, { format: args.output ?? "json" }) + "\n");
12102
11769
  } catch (cause) {
12103
11770
  const err = cause;
12104
11771
  if (err?.isAxiosError) exitWithError(fromAxiosError22(err, args.env));
@@ -12109,8 +11776,8 @@ async function promptPasswordTwice() {
12109
11776
  const password = await promptSecret("\u65B0\u5BC6\u7801: ");
12110
11777
  const confirmation = await promptSecret("\u518D\u6B21\u8F93\u5165\u65B0\u5BC6\u7801: ");
12111
11778
  if (password !== confirmation) {
12112
- throw new CliError24({
12113
- code: CliErrorCode22.INVALID_ARGUMENT,
11779
+ throw new CliError25({
11780
+ code: CliErrorCode23.INVALID_ARGUMENT,
12114
11781
  message: "\u4E24\u6B21\u8F93\u5165\u7684\u65B0\u5BC6\u7801\u4E0D\u4E00\u81F4"
12115
11782
  });
12116
11783
  }
@@ -12122,7 +11789,7 @@ init_exit();
12122
11789
  init_auth_guard();
12123
11790
  import {
12124
11791
  HcmClient as HcmClient28,
12125
- formatObject as formatObject27,
11792
+ formatObject as formatObject28,
12126
11793
  fromAxiosError as fromAxiosError23
12127
11794
  } from "@hcmai/sdk";
12128
11795
  async function modelsCommand(keyword, args) {
@@ -12133,7 +11800,7 @@ async function modelsCommand(keyword, args) {
12133
11800
  const rows = (needle ? all.filter((m) => JSON.stringify(m).toLowerCase().includes(needle)) : all).sort((a, b) => key(a).localeCompare(key(b)));
12134
11801
  const fmt = args.output ?? "table";
12135
11802
  if (fmt !== "table") {
12136
- process.stdout.write(formatObject27({ total: rows.length, models: rows }, { format: fmt }) + "\n");
11803
+ process.stdout.write(formatObject28({ total: rows.length, models: rows }, { format: fmt }) + "\n");
12137
11804
  process.exitCode = 0;
12138
11805
  return;
12139
11806
  }
@@ -12226,24 +11893,18 @@ chiron.command("init").description(
12226
11893
  ).option("--project <dir>", "\u9879\u76EE\u6839\u76EE\u5F55", ".").option("--skip-skills", "\u4E0D\u88C5\u6280\u80FD\uFF08\u79BB\u7EBF/\u6D4B\u8BD5\uFF09").option("--skip-cases", "\u4E0D\u63A5\u6848\u4F8B\u5E93").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((opts) => chironInitCommand(opts));
12227
11894
  chiron.command("test").description("\u6309\u7528\u4F8B\u8DD1\u4E00\u904D\u5E76\u628A\u95EE\u9898\u627E\u51FA\u6765\uFF1A\u7528\u4F8B\u5728\u9879\u76EE\u4ED3 tests/\uFF0C\u5224\u636E\u5FC5\u987B\u770B\u5185\u5BB9\uFF08\u53EA\u5224\u9000\u51FA\u7801\u7684\u7528\u4F8B\u4F1A\u88AB\u62D2\u7EDD\u52A0\u8F7D\uFF09").argument("[target]", "\u7528\u4F8B\u6587\u4EF6\u6216\u76EE\u5F55\uFF08\u9ED8\u8BA4 tests/\uFF09").option("--project <dir>", "\u9879\u76EE\u6839\u76EE\u5F55", ".").option("--env <name>", "\u76EE\u6807\u73AF\u5883\uFF1B\u7528\u4F8B\u91CC\u6CA1\u5199 --env \u65F6\u8865\u4E0A").option("--as <identity>", "\u8EAB\u4EFD\uFF1B\u7528\u4F8B\u91CC\u6CA1\u5199 --as \u65F6\u8865\u4E0A").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((target, opts) => chironTestCommand(target, opts));
12228
11895
  chiron.command("doctor").description(
12229
- "\u6838\u5BF9\uFF1A\u672C\u673A\u767B\u5F55\u662F\u5426\u5BF9\u7740 env.yaml \u7684\u73AF\u5883\uFF08\u542B\u56DB\u6761\u951A\u70B9\uFF09/ \u6280\u80FD\u88C5\u6CA1\u88C5 / \u6848\u4F8B\u5E93\u63A5\u6CA1\u63A5 / Jira \u80FD\u4E0D\u80FD\u63D0\u5355"
11896
+ "\u6838\u5BF9\uFF1A\u672C\u673A\u767B\u5F55\u662F\u5426\u5BF9\u7740 env.yaml \u7684\u73AF\u5883\uFF08\u542B\u56DB\u6761\u951A\u70B9\uFF09/ \u6280\u80FD\u88C5\u6CA1\u88C5 / \u6848\u4F8B\u5E93 clone \u4E86\u6CA1 / Jira \u80FD\u4E0D\u80FD\u63D0\u5355"
12230
11897
  ).option("--project <dir>", "\u9879\u76EE\u6839\u76EE\u5F55", ".").option("--env <name>", "\u8986\u76D6\u8981\u6838\u7684\u73AF\u5883\u522B\u540D\uFF08\u9ED8\u8BA4\u53D6 env.yaml\uFF1B\u591A\u73AF\u5883\u9879\u76EE\u7528\u5B83\u6328\u4E2A\u63A2\uFF09").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD\u63A2\u951A\u70B9").option("--fix", "\u80FD\u81EA\u52A8\u8865\u7684\u8865\u4E0A\uFF08\u6280\u80FD / \u6848\u4F8B\u5E93\uFF09\u540E\u518D\u6838\u4E00\u904D").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((opts) => chironDoctorCommand(opts));
12231
11898
  var OUTPUT_OPT = ["--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table"];
12232
- var jira = program.command("jira").description("\u777F\u620E\u7F3A\u53E3\u5728 Jira\uFF08HCMNX\uFF09\u4E0A\u7684\u51FA\u53E3\uFF1A\u987E\u95EE\u4FA7 search / status / submit\uFF1B\u4EA7\u54C1\u4FA7 open / show / to-issue / sync / verify-*");
12233
- jira.command("probe").description("\u6211\u662F\u8C01 / Jira \u7248\u672C / \u9879\u76EE / issuetype \u4E0E\u5FC5\u586B\u5B57\u6BB5 / \u72B6\u6001\u6D41\uFF1B\u7B2C\u4E00\u6B21\u5148\u8DD1\u5B83").option(...OUTPUT_OPT).action((opts) => jiraProbeCommand(opts));
12234
- jira.command("open").description("\u5F85\u5206\u8BCA\u7684\u5355\uFF08\u72B6\u6001\u300C\u65B0\u589E\u300D\uFF09\uFF1B--all \u770B\u9879\u76EE\u91CC\u5168\u90E8\u672A\u89E3\u51B3\u7684").option("--all", "\u5168\u90E8\u672A\u89E3\u51B3\u7684\u5355\uFF0C\u4E0D\u53EA\u5F85\u5206\u8BCA").option(...OUTPUT_OPT).action((opts) => jiraOpenCommand(opts));
12235
- jira.command("show").description("\u6B63\u6587 + \u8BC4\u8BBA + \u5173\u8054\u4EE3\u7801\u5E93\u6761\u76EE\u7684\u72B6\u6001 + \u53EF\u7528\u6D41\u8F6C").argument("<key>", "Jira \u5355\u53F7\uFF0C\u5982 HCMNX-12").option(...OUTPUT_OPT).action((key2, opts) => jiraShowCommand(key2, opts));
12236
- jira.command("comment").description("\u56DE\u590D\uFF08\u5206\u8BCA\u7ED3\u8BBA\u8D70\u8FD9\u6761\uFF09\uFF1A-f \u6587\u4EF6 / --body \u6587\u672C / \u4F4D\u7F6E\u53C2\u6570 / \u6807\u51C6\u8F93\u5165").argument("<key>", "Jira \u5355\u53F7").argument("[text]", "\u6B63\u6587").option("-f, --file <path>", "\u6B63\u6587\u6587\u4EF6").option("--body <text>", "\u6B63\u6587").option(...OUTPUT_OPT).action((key2, text, opts) => jiraCommentCommand(key2, text, opts));
12237
- jira.command("assign").description("\u63A5\u624B\uFF1A\u6539\u7ECF\u529E\u4EBA\uFF08\u9ED8\u8BA4 me\uFF09").argument("<key>", "Jira \u5355\u53F7").argument("[who]", "\u7528\u6237\u540D\u6216 me", "me").option(...OUTPUT_OPT).action((key2, who, opts) => jiraAssignCommand(key2, who, opts));
12238
- jira.command("move").description("\u6D41\u8F6C\uFF1A\u76EE\u6807\u72B6\u6001\u540D\u6216\u6D41\u8F6C\u540D\uFF08\u5982 \u63D0\u4EA4\u534F\u8C03 / \u4E0D\u7528\u5904\u7406\u4E86\uFF09\uFF1B\u53EF\u9644\u8BC4\u8BBA").argument("<key>", "Jira \u5355\u53F7").argument("<target>", "\u72B6\u6001\u6216\u6D41\u8F6C\u540D").option("-f, --file <path>", "\u9644\u5E26\u8BC4\u8BBA\u7684\u6587\u4EF6").option("--body <text>", "\u9644\u5E26\u8BC4\u8BBA").option(...OUTPUT_OPT).action((key2, target, opts) => jiraMoveCommand(key2, target, opts));
12239
- jira.command("to-issue").description("\u5206\u8BCA\u4E3A\u771F\u7F3A\u53E3\uFF1A\u8F6C\u4EA7\u54C1\u4ED3 issue \u5E76\u53CC\u5411\u56DE\u94FE\uFF08\u5EFA\u6761\u76EE \u2192 \u6302\u94FE\u63A5 \u2192 \u63A5\u624B \u2192 \u63A8 OPEN\uFF09").argument("<key>", "Jira \u5355\u53F7").option("--repo <slug>", "\u4EA7\u54C1\u4ED3", "hcm/hcm_nx_core").option("--force", "\u5DF2\u5173\u8054\u8FC7\u4E5F\u518D\u5EFA\u4E00\u6761").option(...OUTPUT_OPT).action((key2, opts) => jiraToIssueCommand(key2, opts));
12240
- jira.command("sync").description("\u4EE3\u7801\u5E93\u6761\u76EE\u5168\u5173 \u2192 \u56DE\u5199 Jira \u5E76\u63A8\u300C\u5DF2\u4FEE\u590D\u300D\uFF08PR \u53F7\u4E0D\u7B97\u6761\u76EE\uFF1B\u8BFB\u4E0D\u5230\u7684\u6309\u672A\u5173\u5904\u7406\uFF09").argument("<key>", "Jira \u5355\u53F7").option("--dry-run", "\u53EA\u5224\u65AD\u4E0D\u5199").option(...OUTPUT_OPT).action((key2, opts) => jiraSyncCommand(key2, opts));
12241
- jira.command("verify-pass").description("\u987E\u95EE\u5728\u76EE\u6807\u73AF\u5883\u590D\u9A8C\u901A\u8FC7 \u2192 CLOSE").argument("<key>", "Jira \u5355\u53F7").argument("[note]", "\u8BF4\u660E").option("-f, --file <path>", "\u8BF4\u660E\u6587\u4EF6").option("--body <text>", "\u8BF4\u660E").option(...OUTPUT_OPT).action((key2, note, opts) => jiraVerifyPassCommand(key2, note, opts));
12242
- jira.command("verify-fail").description("\u590D\u9A8C\u4E0D\u901A\u8FC7 \u2192 \u9000\u56DE OPEN\uFF0C\u5E76\u91CD\u5F00\u4EE3\u7801\u5E93 issue").argument("<key>", "Jira \u5355\u53F7").argument("[note]", "\u4E0D\u901A\u8FC7\u7684\u8BF4\u660E").option("-f, --file <path>", "\u8BF4\u660E\u6587\u4EF6").option("--body <text>", "\u8BF4\u660E").option(...OUTPUT_OPT).action((key2, note, opts) => jiraVerifyFailCommand(key2, note, opts));
12243
- jira.command("audit").description("\u4E00\u81F4\u6027\uFF1A\u72B6\u6001\u5DF2\u79BB\u5F00\u300C\u65B0\u589E\u300D\u7684\u7F3A\u53E3\u5355\u5FC5\u987B\u6302\u7740\u4EE3\u7801\u5E93\u6761\u76EE").option(...OUTPUT_OPT).action((opts) => jiraAuditCommand(opts));
12244
- jira.command("search").description("\u987E\u95EE\u4FA7\u67E5\u91CD\uFF1A\u6309\u9519\u8BEF\u7801 / Model / Action / \u4E00\u53E5\u73B0\u8C61\u67E5 Jira \u4E0E\u4EA7\u54C1\u4ED3\uFF0C\u5E26\u56DE\u7F16\u53F7\u4E0E\u72B6\u6001").argument("<keywords...>", "\u5173\u952E\u8BCD\uFF0C\u6BCF\u4E2A\u5355\u72EC\u67E5\u4E00\u6B21").option("--no-include-closed", "\u53EA\u67E5\u672A\u89E3\u51B3\u7684").option(...OUTPUT_OPT).action((keywords, opts) => jiraSearchCommand(keywords, opts));
12245
- jira.command("status").description("\u987E\u95EE\u4FA7\u67E5\u8FDB\u5EA6\uFF1A\u8BA4 HCMNX-12 / 12 / core#2198 / cases#26").argument("<ref>", "Jira \u5355\u53F7\u6216\u4EE3\u7801\u5E93\u5F15\u7528").option(...OUTPUT_OPT).action((ref, opts) => jiraStatusCommand(ref, opts));
12246
- jira.command("submit").description("\u987E\u95EE\u4FA7\u63D0\u7F3A\u53E3\uFF1A\u5148\u67E5\u91CD\uFF08\u540C\u4E00\u7F3A\u53E3\u8FFD\u52A0\u300C\u53C8\u4E00\u4E2A\u73B0\u573A\u300D\uFF09\uFF0C\u5426\u5219\u6309 HCMNX \u5FC5\u586B\u683C\u65B0\u5F00\uFF1B\u8F7D\u8377 JSON \u8D70 --file \u6216\u6807\u51C6\u8F93\u5165").option("--file <path>", "\u7F3A\u53E3\u8F7D\u8377 JSON\uFF08title/phenomenon/repro/expected/alternative/q_*/severity/kind/module\u2026\uFF09").option("--env <name>", "\u53D6\u73AF\u5883\u6307\u7EB9\u7528\u7684\u73AF\u5883\u522B\u540D\uFF08\u7F3A\u7701 activeEnv\uFF09").option("--fingerprint <text>", "\u76F4\u63A5\u7ED9\u6307\u7EB9\u6587\u672C\uFF08\u8BAD\u7EC3\u573A\u4ECE \u573A.yml \u53D6\u65F6\u7528\uFF09\uFF0C\u4E0D\u518D\u73B0\u67E5").option("--issuetype <name>", "\u8986\u76D6 issuetype\uFF08\u7F3A\u7701\u6309 kind \u9009 \u6545\u969C / \u9700\u6C42\uFF09").option("--assignee <user>", "\u8986\u76D6\u7ECF\u529E\u4EBA\uFF08\u7F3A\u7701\u9879\u76EE\u8D1F\u8D23\u4EBA\uFF09").option(...OUTPUT_OPT).action((opts) => jiraSubmitCommand(opts));
11899
+ var gap = chiron.command("gap").description("\u7F3A\u53E3\uFF1A\u649E\u5230\u300C\u4EA7\u54C1\u505A\u4E0D\u5230\u300D\u65F6\u7684\u7EDF\u4E00\u51FA\u53E3\uFF0C\u8FDB Jira\uFF08HCMNX\uFF09\u2014\u2014\u67E5\u91CD search / \u67E5\u8FDB\u5EA6 status / \u63D0\u7F3A\u53E3 submit");
11900
+ gap.command("search").description("\u67E5\u91CD\uFF1A\u6309\u9519\u8BEF\u7801 / Model / Action / \u4E00\u53E5\u73B0\u8C61\u67E5 Jira\uFF0C\u5E26\u56DE\u7F16\u53F7\u4E0E\u72B6\u6001").argument("<keywords...>", "\u5173\u952E\u8BCD\uFF0C\u6BCF\u4E2A\u5355\u72EC\u67E5\u4E00\u6B21").option("--no-include-closed", "\u53EA\u67E5\u672A\u89E3\u51B3\u7684").option(...OUTPUT_OPT).action((keywords, opts) => gapSearchCommand(keywords, opts));
11901
+ gap.command("status").description("\u67E5\u8FDB\u5EA6\uFF1A\u7ED9 Jira \u5355\u53F7\uFF08HCMNX-12 \u6216\u88F8\u6570\u5B57 12\uFF09").argument("<ref>", "Jira \u5355\u53F7").option(...OUTPUT_OPT).action((ref, opts) => gapStatusCommand(ref, opts));
11902
+ gap.command("submit").description("\u63D0\u7F3A\u53E3\uFF1A\u5148\u67E5\u91CD\uFF08\u540C\u4E00\u7F3A\u53E3\u8FFD\u52A0\u300C\u53C8\u4E00\u4E2A\u73B0\u573A\u300D\uFF09\uFF0C\u5426\u5219\u6309 HCMNX \u5FC5\u586B\u683C\u65B0\u5F00\uFF1B\u8F7D\u8377 JSON \u8D70 --file \u6216\u6807\u51C6\u8F93\u5165").option("--file <path>", "\u7F3A\u53E3\u8F7D\u8377 JSON\uFF08title/phenomenon/repro/expected/alternative/q_*/severity/kind/module\u2026\uFF09").option("--env <name>", "\u53D6\u73AF\u5883\u6307\u7EB9\u7528\u7684\u73AF\u5883\u522B\u540D\uFF08\u7F3A\u7701 activeEnv\uFF09").option("--fingerprint <text>", "\u76F4\u63A5\u7ED9\u6307\u7EB9\u6587\u672C\uFF08\u8BAD\u7EC3\u573A\u4ECE \u573A.yml \u53D6\u65F6\u7528\uFF09\uFF0C\u4E0D\u518D\u73B0\u67E5").option("--issuetype <name>", "\u8986\u76D6 issuetype\uFF08\u7F3A\u7701\u6309 kind \u9009 \u6545\u969C / \u9700\u6C42\uFF09").option("--assignee <user>", "\u8986\u76D6\u7ECF\u529E\u4EBA\uFF08\u7F3A\u7701\u9879\u76EE\u8D1F\u8D23\u4EBA\uFF09").option(...OUTPUT_OPT).action((opts) => gapSubmitCommand(opts));
11903
+ var kase = chiron.command("case").description("\u516C\u5171\u6848\u4F8B\u5E93\uFF1A\u67E5 search / \u770B show / \u5BF9\u6307\u7EB9 match / \u9879\u76EE\u6848\u4F8B\u4E0A\u884C submit");
11904
+ kase.command("search").description("\u6309\u5BA2\u6237\u539F\u8BDD / \u9519\u8BEF\u7801 / Model / \u6280\u80FD\u627E\u516C\u5171\u6848\u4F8B\uFF0C\u5E76\u6309\u5F53\u524D\u73AF\u5883\u6307\u7EB9\u6807\u5339\u914D").argument("<query>", "\u4E00\u53E5\u8BDD\u6216\u5173\u952E\u8BCD").option("--top-k <n>", "\u53D6\u524D\u51E0\u6761\uFF081-10\uFF09", "5").option("--env <name>", "\u7528\u54EA\u4E2A\u73AF\u5883\u7684\u540E\u7AEF\u6307\u7EB9\u6BD4\u5BF9\uFF08\u4E0D\u7ED9\u5C31\u6807\u300C\u672A\u6BD4\u5BF9\u300D\uFF0C\u4E0D\u5047\u88C5\u5339\u914D\uFF09").option(...OUTPUT_OPT).action((query, opts) => caseSearchCommand(query, { ...opts, topK: Number(opts.topK) }));
11905
+ kase.command("show").description("\u8BFB\u4E00\u4E2A\u6848\u4F8B\u7684\u6B63\u6587\uFF08\u9ED8\u8BA4 \u95EE\u9898.md + \u65B9\u6848.md\uFF09").argument("<id>", "\u6848\u4F8B id\uFF0C\u5982 CASE-20260828-xxx").option("--file <name>", "\u53EA\u770B\u67D0\u4E00\u4EFD\u6587\u4EF6").option(...OUTPUT_OPT).action((id, opts) => caseShowCommand(id, opts));
11906
+ kase.command("match").description("\u5217\u51FA\u5F53\u524D\u73AF\u5883\u6307\u7EB9\u4E0B\u53EF\u7167\u505A\u7684\u516C\u5171\u6848\u4F8B\uFF08status=approved\uFF09").option("--env <name>", "\u7528\u54EA\u4E2A\u73AF\u5883\u7684\u540E\u7AEF\u6307\u7EB9\u6BD4\u5BF9").option(...OUTPUT_OPT).action((opts) => caseMatchCommand(opts));
11907
+ kase.command("submit").description("\u628A\u9879\u76EE\u6848\u4F8B\u8131\u654F\u4E0A\u884C\u4E3A\u516C\u5171\u6848\u4F8B\uFF1A\u590D\u5236\u8FDB\u672C\u673A clone \u2192 tier=public \u2192 lint \u2192 \u5F00 PR").argument("<dir>", "\u9879\u76EE\u4ED3\u91CC\u7684\u6848\u4F8B\u76EE\u5F55\uFF0C\u5982 cases/CASE-20260902-xxx").requiredOption("--category <name>", "\u516C\u5171\u6848\u4F8B\u7684\u5206\u7C7B\u76EE\u5F55").requiredOption("--origin <text>", "\u6765\u6E90\u8BF4\u660E\uFF0C\u5982\u300C\u9879\u76EE\u4ED3 acme-hr cases/\u2026\u300D").option(...OUTPUT_OPT).action((dir, opts) => caseSubmitCommand(dir, opts));
12247
11908
  var recon = chiron.command("recon").description("\u722C\u4E00\u4EFD\u53EF\u5E26\u8D70\u7684\u57FA\u7EBF\uFF1A\u6A21\u578B / \u5B57\u6BB5 / \u53EA\u8BFB\u95F8 / \u4F9D\u8D56\u56FE / \u7801\u8868 / \u53EF\u5199\u6027\u753B\u50CF").option("--env <name>", "\u76EE\u6807\u73AF\u5883\u522B\u540D").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD").option("--out <dir>", "\u4EA7\u7269\u6839\u76EE\u5F55\uFF08\u4EA7\u7269\u843D\u5728 <out>/recon/<\u79DF\u6237\u6BB5>/<\u6765\u6E90\u6BB5>\uFF09", ".").option("--state <s>", "\u53EA\u8BFB\u95F8\u7684 state\uFF08\u4EA7\u54C1\u91CC state \u4E0D\u53EF\u679A\u4E3E\uFF0C\u95F8\u7684\u8986\u76D6\u9762\u6C38\u8FDC\u662F state-scoped\uFF09").option("--model <key>", "\u5B9A\u5411\u91CD\u722C\uFF1A\u53EA\u91CD\u722C\u8FD9\u4E00\u4E2A\u6A21\u578B\uFF0C\u5176\u4F59\u6CBF\u7528\u4E0A\u4E00\u8F6E\u4EA7\u7269").option("--capabilities <s>", "\u722C\u53D6\u65F6\u58F0\u660E\u7684 capability \u4E32\uFF08\u4F1A\u968F\u56DB\u5143\u7EC4\u7559\u6863\uFF09").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((opts) => deliveryReconCommand(opts));
12248
11909
  recon.command("round").description("\u96F6\u7F51\u7EDC\uFF1A\u8BFB\u4E00\u4EFD\u5DF2\u843D\u76D8\u7684\u57FA\u7EBF\uFF0C\u5224\u65AD\u5B83\u662F\u4E0D\u662F\u4E00\u8F6E\u5B8C\u6574\u8DD1\u51FA\u6765\u7684\uFF08complete/mixed/unknown\uFF09").option("--dir <dir>", "\u4EA7\u7269\u76EE\u5F55\uFF08<out>/recon/<\u79DF\u6237\u6BB5>/<\u6765\u6E90\u6BB5>\uFF09", ".").action(
12249
11910
  (opts, cmd) => deliveryReconRoundCommand({
@@ -12427,7 +12088,7 @@ program.command("update <Model>").description("\u66F4\u65B0\u4E00\u6761 Model \u
12427
12088
  ).action((model, opts) => updateCommand(model, opts));
12428
12089
  program.command("version").description("\u67E5 CLI \u4E0E\u540E\u7AEF\u4E24\u4E2A\u7248\u672C\uFF08commit / tag / \u6784\u5EFA\u65F6\u95F4\uFF09\u2014\u2014\u514D\u8BA4\u8BC1\uFF0C\u65E0\u9700\u5148 login").option("--endpoint <url>", "\u540E\u7AEF\u5730\u5740\uFF08\u9ED8\u8BA4\u53D6 activeEnv \u7684 endpoint\uFF09").option("--env <name>", "\u4ECE\u8BE5 env \u89E3\u6790 endpoint").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((opts) => versionCommand(opts));
12429
12090
  program.command("upgrade").alias("self-update").description("\u5347\u7EA7 CLI \u81EA\u5DF1\uFF08\u6CE8\u610F\uFF1A`hcm update` \u662F\u66F4\u65B0\u4E1A\u52A1\u8BB0\u5F55\uFF0C\u4E0D\u662F\u5347\u7EA7\uFF09").option("--check", "\u53EA\u68C0\u67E5\uFF1B\u6709\u65B0\u7248\u672C\u65F6\u4EE5\u9000\u51FA\u7801 1 \u7ED3\u675F\uFF0C\u4FBF\u4E8E\u811A\u672C\u5224\u65AD").action((opts) => upgradeCommand(opts));
12430
- program.command("open [path]").description("\u7528\u5F53\u524D CLI \u8EAB\u4EFD\u6253\u5F00\u524D\u7AEF\u9875\u9762\uFF1A\u94F8\u4E00\u5F20 60s \u4E00\u6B21\u6027\u7968\u636E\u4EA4\u7ED9\u6D4F\u89C8\u5668\uFF0C\u4F1A\u8BDD token \u4E0D\u8FDB URL").option("--print-url", "\u53EA\u6253\u5370\u767B\u5F55 URL\uFF0C\u4E0D\u5F00\u6D4F\u89C8\u5668\uFF08\u7ED9 agent \u6D4F\u89C8\u5668 navigate \u7528\uFF09").option("--env <name>", "\u4E34\u65F6\u5207\u73AF\u5883\uFF08\u8986\u76D6 activeEnv\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD\uFF08\u8986\u76D6 env defaultIdentity\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--profile <name>", "[deprecated] \u7528 --env \u66FF\u4EE3").action((path14, opts) => openCommand(path14, opts));
12091
+ program.command("open [path]").description("\u7528\u5F53\u524D CLI \u8EAB\u4EFD\u6253\u5F00\u524D\u7AEF\u9875\u9762\uFF1A\u94F8\u4E00\u5F20 60s \u4E00\u6B21\u6027\u7968\u636E\u4EA4\u7ED9\u6D4F\u89C8\u5668\uFF0C\u4F1A\u8BDD token \u4E0D\u8FDB URL").option("--print-url", "\u53EA\u6253\u5370\u767B\u5F55 URL\uFF0C\u4E0D\u5F00\u6D4F\u89C8\u5668\uFF08\u7ED9 agent \u6D4F\u89C8\u5668 navigate \u7528\uFF09").option("--env <name>", "\u4E34\u65F6\u5207\u73AF\u5883\uFF08\u8986\u76D6 activeEnv\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD\uFF08\u8986\u76D6 env defaultIdentity\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--profile <name>", "[deprecated] \u7528 --env \u66FF\u4EE3").action((path15, opts) => openCommand(path15, opts));
12431
12092
  var setting = program.command("setting").description("\u79DF\u6237\u7CFB\u7EDF\u53C2\u6570\uFF08\u767B\u5F55\u7B56\u7565 / \u5BC6\u7801\u7B56\u7565 / \u529F\u80FD\u5F00\u5173 / \u96C6\u6210\u53C2\u6570\uFF09");
12432
12093
  setting.command("get <domain>").description("\u8BFB\u67D0\u57DF\u53C2\u6570\uFF08\u5B9A\u4E49 + \u79DF\u6237\u8986\u76D6\u503C\u5408\u5E76\uFF0C\u7F3A\u5931\u56DE\u843D\u9ED8\u8BA4\u503C\uFF09").option("--env <name>", "\u4E34\u65F6\u5207\u73AF\u5883\uFF08\u8986\u76D6 activeEnv\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((d, opts) => settingGetCommand(d, opts));
12433
12094
  setting.command("set <domain>").description("\u6539\u53C2\u6570\uFF0C\u53EF\u91CD\u590D --set\uFF1B\u8D70\u53D7\u63A7\u6821\u9A8C\u8DEF\u5F84\u800C\u975E\u6807\u51C6 CRUD").option(