@hcmai/cli 0.4.31 → 0.6.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
@@ -121,9 +121,9 @@ __export(attachment_args_exports, {
121
121
  extractInlineFilePaths: () => extractInlineFilePaths,
122
122
  isBareFilePath: () => isBareFilePath
123
123
  });
124
- import * as fs2 from "fs";
124
+ import * as fs3 from "fs";
125
125
  import * as os from "os";
126
- import * as path from "path";
126
+ import * as path2 from "path";
127
127
  function extractAtFileTokens(text) {
128
128
  const paths = [];
129
129
  const re = /@(?:"([^"]+)"|'([^']+)'|(\S+))/g;
@@ -159,11 +159,11 @@ function isBareFilePath(text) {
159
159
  return isExistingFile(abs) ? abs : null;
160
160
  }
161
161
  function expandHome(p) {
162
- return p.startsWith("~") ? path.join(os.homedir(), p.slice(1)) : path.resolve(p);
162
+ return p.startsWith("~") ? path2.join(os.homedir(), p.slice(1)) : path2.resolve(p);
163
163
  }
164
164
  function isExistingFile(p) {
165
165
  try {
166
- return fs2.statSync(p).isFile();
166
+ return fs3.statSync(p).isFile();
167
167
  } catch {
168
168
  return false;
169
169
  }
@@ -1312,7 +1312,7 @@ var init_types = __esm({
1312
1312
 
1313
1313
  // src/repl/App.tsx
1314
1314
  import { useCallback, useEffect as useEffect2, useMemo, useRef as useRef2, useState as useState2 } from "react";
1315
- import * as fs3 from "fs/promises";
1315
+ import * as fs4 from "fs/promises";
1316
1316
  import { Box as Box3, Static, Text as Text3, useApp, useInput as useInput2 } from "ink";
1317
1317
  import TextInput from "ink-text-input";
1318
1318
  import SelectInput from "ink-select-input";
@@ -1359,7 +1359,7 @@ function ReplApp(props) {
1359
1359
  const histIdxRef = useRef2(-1);
1360
1360
  const draftRef = useRef2("");
1361
1361
  useEffect2(() => {
1362
- void fs3.readFile(replHistoryFile(props.env), "utf-8").then((c) => {
1362
+ void fs4.readFile(replHistoryFile(props.env), "utf-8").then((c) => {
1363
1363
  historyRef.current = c.split("\n").filter(Boolean);
1364
1364
  }).catch(() => {
1365
1365
  });
@@ -1546,7 +1546,7 @@ function ReplApp(props) {
1546
1546
  }
1547
1547
  historyRef.current.push(line);
1548
1548
  histIdxRef.current = -1;
1549
- void fs3.appendFile(replHistoryFile(props.env), line.replace(/\n/g, " ") + "\n").catch(() => {
1549
+ void fs4.appendFile(replHistoryFile(props.env), line.replace(/\n/g, " ") + "\n").catch(() => {
1550
1550
  });
1551
1551
  void (async () => {
1552
1552
  const at = extractAtFileTokens(line);
@@ -2100,21 +2100,21 @@ async function loginPasswordWithFirstLoginChange(input, args) {
2100
2100
  return loginPassword({ ...input, password: next });
2101
2101
  }
2102
2102
  }
2103
- function inferIdentityName(scheme, env2, extra) {
2104
- if (scheme === "password" && extra.username) return `${extra.username}@${env2}`;
2103
+ function inferIdentityName(scheme, env3, extra) {
2104
+ if (scheme === "password" && extra.username) return `${extra.username}@${env3}`;
2105
2105
  if (scheme === "client_credentials" && extra.clientId) {
2106
- return `${extra.clientId.slice(0, 6)}@${env2}`;
2106
+ return `${extra.clientId.slice(0, 6)}@${env3}`;
2107
2107
  }
2108
- if (scheme === "pairing" && extra.username) return `${extra.username}@${env2}`;
2108
+ if (scheme === "pairing" && extra.username) return `${extra.username}@${env3}`;
2109
2109
  if (scheme === "pat") {
2110
- const name = `pat-${Math.random().toString(36).slice(2, 6)}@${env2}`;
2110
+ const name = `pat-${Math.random().toString(36).slice(2, 6)}@${env3}`;
2111
2111
  process.stderr.write(
2112
2112
  `[hcm] event=pat_identity_auto_named name=${name} hint="pass --name <id> for a stable identity name across re-logins"
2113
2113
  `
2114
2114
  );
2115
2115
  return name;
2116
2116
  }
2117
- return `default@${env2}`;
2117
+ return `default@${env3}`;
2118
2118
  }
2119
2119
  async function migrateProfileTokenToIdentity(envName, identityName) {
2120
2120
  const oldStore = new TokenStore(envName);
@@ -2382,9 +2382,9 @@ async function loginCommand(args) {
2382
2382
  } catch (e) {
2383
2383
  const err = e;
2384
2384
  if (err.isAxiosError) {
2385
- const { fromAxiosError: fromAxiosError25 } = await import("@hcmai/sdk");
2385
+ const { fromAxiosError: fromAxiosError24 } = await import("@hcmai/sdk");
2386
2386
  exitWithError(
2387
- fromAxiosError25(
2387
+ fromAxiosError24(
2388
2388
  e,
2389
2389
  envName
2390
2390
  )
@@ -2895,8 +2895,8 @@ import {
2895
2895
  HcmClient as HcmClient2,
2896
2896
  formatObject,
2897
2897
  fromAxiosError as fromAxiosError2,
2898
- CliError as CliError8,
2899
- CliErrorCode as CliErrorCode7
2898
+ CliError as CliError9,
2899
+ CliErrorCode as CliErrorCode8
2900
2900
  } from "@hcmai/sdk";
2901
2901
 
2902
2902
  // src/utils/json-input.ts
@@ -2951,19 +2951,106 @@ async function readJsonObjectInput(options) {
2951
2951
  return parsed;
2952
2952
  }
2953
2953
 
2954
+ // src/artifact.ts
2955
+ import { createHash } from "crypto";
2956
+ import { CliError as CliError8, CliErrorCode as CliErrorCode7 } from "@hcmai/sdk";
2957
+ import { promises as fs2 } from "fs";
2958
+ import path from "path";
2959
+ var MAX_ARTIFACT_BYTES = 10 * 1024 * 1024;
2960
+ var ARTIFACT_ENCODING_BASE64 = "base64";
2961
+ var SHA256_HEX = /^[0-9a-f]{64}$/;
2962
+ var isStr = (v) => typeof v === "string";
2963
+ function parseArtifactEnvelope(data) {
2964
+ if (data === null || typeof data !== "object" || Array.isArray(data)) {
2965
+ return { ok: false, reason: "\u54CD\u5E94\u4F53\u4E0D\u662F\u5BF9\u8C61" };
2966
+ }
2967
+ const o = data;
2968
+ const missing = ["fileName", "mediaType", "encoding", "content", "sizeBytes", "sha256", "capabilityVersion", "language"].filter(
2969
+ (k) => !(k in o)
2970
+ );
2971
+ if (missing.length) return { ok: false, reason: `\u4E0D\u662F\u6807\u51C6\u5236\u54C1\u4FE1\u5C01\uFF0C\u7F3A\u5B57\u6BB5\uFF1A${missing.join(", ")}` };
2972
+ if (!isStr(o.fileName) || !o.fileName.trim()) return { ok: false, reason: "fileName \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32" };
2973
+ if (!isStr(o.mediaType) || !o.mediaType.trim()) return { ok: false, reason: "mediaType \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32" };
2974
+ if (o.encoding !== ARTIFACT_ENCODING_BASE64) {
2975
+ return { ok: false, reason: `encoding \u53EA\u652F\u6301 ${ARTIFACT_ENCODING_BASE64}\uFF0C\u6536\u5230 ${JSON.stringify(o.encoding)}` };
2976
+ }
2977
+ if (!isStr(o.content)) return { ok: false, reason: "content \u5FC5\u987B\u662F\u5B57\u7B26\u4E32" };
2978
+ if (typeof o.sizeBytes !== "number" || !Number.isInteger(o.sizeBytes) || o.sizeBytes < 0) {
2979
+ return { ok: false, reason: `sizeBytes \u5FC5\u987B\u662F\u975E\u8D1F\u6574\u6570\uFF0C\u6536\u5230 ${JSON.stringify(o.sizeBytes)}` };
2980
+ }
2981
+ if (!isStr(o.sha256) || !SHA256_HEX.test(o.sha256)) return { ok: false, reason: "sha256 \u5FC5\u987B\u662F 64 \u4F4D\u5C0F\u5199 hex" };
2982
+ if (!isStr(o.capabilityVersion)) return { ok: false, reason: "capabilityVersion \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\uFF08\u65E0\u7248\u672C\u65F6\u4E3A\u7A7A\u4E32\uFF0C\u4E0D\u662F null\uFF09" };
2983
+ if (!isStr(o.language) || !o.language.trim()) {
2984
+ return { ok: false, reason: "language \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\uFF08\u5236\u54C1\u8868\u5934\u968F\u8BED\u8A00\u53D8\uFF0C\u5FC5\u987B\u81EA\u9648\uFF09" };
2985
+ }
2986
+ return { ok: true, artifact: o };
2987
+ }
2988
+ var fail = (message, nextStep) => new CliError8({ code: CliErrorCode7.INVALID_ARGUMENT, message, context: { nextStep } });
2989
+ async function writeArtifact(artifact, target, opts = {}) {
2990
+ const abs = path.resolve(target);
2991
+ const stat = await fs2.lstat(abs).catch(() => null);
2992
+ if (stat) {
2993
+ if (stat.isSymbolicLink()) {
2994
+ throw fail(`\u76EE\u6807\u662F\u7B26\u53F7\u94FE\u63A5\uFF0C\u62D2\u7EDD\u5199\u5165\uFF1A${abs}`, "\u6362\u4E00\u4E2A\u771F\u5B9E\u8DEF\u5F84\u3002\u8DDF\u7740\u7B26\u53F7\u94FE\u63A5\u5199\u4F1A\u843D\u5230\u94FE\u63A5\u6307\u5411\u7684\u5730\u65B9\uFF0C\u90A3\u4E0D\u662F\u4F60\u5728\u547D\u4EE4\u884C\u91CC\u6307\u5B9A\u7684\u4F4D\u7F6E\u3002");
2995
+ }
2996
+ if (stat.isDirectory()) {
2997
+ throw fail(`\u76EE\u6807\u662F\u76EE\u5F55\uFF0C\u4E0D\u662F\u6587\u4EF6\uFF1A${abs}`, "--artifact-output \u8981\u7ED9**\u6587\u4EF6**\u8DEF\u5F84\uFF08\u670D\u52A1\u7AEF\u7ED9\u7684 fileName \u4E0D\u4F1A\u88AB\u62FC\u8FDB\u53BB\uFF0C\u90A3\u6837\u4F1A\u5E26\u6765\u8DEF\u5F84\u7A7F\u8D8A\uFF09\u3002");
2998
+ }
2999
+ if (!opts.force) {
3000
+ throw fail(`\u76EE\u6807\u5DF2\u5B58\u5728\uFF1A${abs}`, "\u6362\u4E2A\u8DEF\u5F84\uFF0C\u6216\u663E\u5F0F\u52A0 --artifact-force \u8986\u76D6\u3002\u9ED8\u8BA4\u4E0D\u8986\u76D6\uFF0C\u514D\u5F97\u628A\u4E0A\u4E00\u8F6E\u7684\u8BC1\u636E\u6084\u6084\u6362\u6389\u3002");
3001
+ }
3002
+ }
3003
+ let bytes;
3004
+ try {
3005
+ bytes = Buffer.from(artifact.content, "base64");
3006
+ } catch {
3007
+ throw fail("content \u4E0D\u662F\u5408\u6CD5 base64", "\u8FD9\u4E0D\u662F\u4E00\u4EFD\u53EF\u7528\u7684\u5236\u54C1\uFF0C\u68C0\u67E5\u670D\u52A1\u7AEF\u54CD\u5E94\uFF1B\u4E0D\u8981\u624B\u5DE5\u6539\u9020\u5B83\u3002");
3008
+ }
3009
+ if (bytes.byteLength > MAX_ARTIFACT_BYTES) {
3010
+ throw fail(`\u5236\u54C1 ${bytes.byteLength} \u5B57\u8282\uFF0C\u8D85\u8FC7\u4E0A\u9650 ${MAX_ARTIFACT_BYTES}`, "\u8FD9\u4E00\u6863\u53EA\u8D70\u4E0D\u843D\u5E93\u7684\u5C0F\u5236\u54C1\uFF1B\u66F4\u5927\u7684\u4EA7\u7269\u8BF7\u8D70\u4F1A\u5EFA Document \u7684\u90A3\u6761\u5165\u53E3\u3002");
3011
+ }
3012
+ if (bytes.byteLength !== artifact.sizeBytes) {
3013
+ throw fail(`\u5B57\u8282\u6570\u5BF9\u4E0D\u4E0A\uFF1A\u4FE1\u5C01\u8BF4 ${artifact.sizeBytes}\uFF0C\u89E3\u7801\u51FA ${bytes.byteLength}`, "\u54CD\u5E94\u5728\u4F20\u8F93\u4E2D\u88AB\u6539\u8FC7\u6216\u670D\u52A1\u7AEF\u7B97\u9519\u4E86\u3002\u4E0D\u8981\u843D\u76D8\u2014\u2014\u843D\u4E0B\u53BB\u7684\u4F1A\u662F\u4E00\u4EFD\u770B\u7740\u6B63\u5E38\u7684\u574F\u6587\u4EF6\u3002");
3014
+ }
3015
+ const digest = createHash("sha256").update(bytes).digest("hex");
3016
+ if (digest !== artifact.sha256) {
3017
+ throw fail(`SHA-256 \u5BF9\u4E0D\u4E0A\uFF1A\u4FE1\u5C01\u8BF4 ${artifact.sha256}\uFF0C\u5B9E\u9645 ${digest}`, "\u540C\u4E0A\uFF1A\u5185\u5BB9\u4E0E\u6458\u8981\u4E0D\u4E00\u81F4\uFF0C\u8FD9\u4EFD\u5236\u54C1\u4E0D\u53EF\u4FE1\uFF0C\u4E0D\u843D\u76D8\u3002");
3018
+ }
3019
+ const dir = path.dirname(abs);
3020
+ await fs2.mkdir(dir, { recursive: true });
3021
+ const tmp = path.join(dir, `.tmp-artifact-${process.pid}-${Date.now()}`);
3022
+ try {
3023
+ await fs2.writeFile(tmp, bytes, { mode: 384, flag: "wx" });
3024
+ await fs2.rename(tmp, abs);
3025
+ } catch (e) {
3026
+ await fs2.rm(tmp, { force: true }).catch(() => {
3027
+ });
3028
+ throw fail(`\u5199\u5165\u5931\u8D25\uFF1A${e.message}`, "\u68C0\u67E5\u76EE\u5F55\u6743\u9650\u4E0E\u78C1\u76D8\u7A7A\u95F4\u3002\u4E34\u65F6\u6587\u4EF6\u5DF2\u6E05\u6389\uFF0C\u76EE\u6807\u8DEF\u5F84\u4E0A\u4E0D\u4F1A\u7559\u4E0B\u534A\u4EFD\u6587\u4EF6\u3002");
3029
+ }
3030
+ return {
3031
+ path: abs,
3032
+ sizeBytes: artifact.sizeBytes,
3033
+ sha256: artifact.sha256,
3034
+ fileName: artifact.fileName,
3035
+ mediaType: artifact.mediaType,
3036
+ capabilityVersion: artifact.capabilityVersion,
3037
+ language: artifact.language
3038
+ };
3039
+ }
3040
+
2954
3041
  // src/commands/action.ts
2955
3042
  async function actionCommand(spec, args) {
2956
3043
  try {
2957
3044
  const [model, action] = spec.split(".");
2958
3045
  if (!model || !action) {
2959
- throw new CliError8({
2960
- code: CliErrorCode7.INVALID_ARGUMENT,
3046
+ throw new CliError9({
3047
+ code: CliErrorCode8.INVALID_ARGUMENT,
2961
3048
  message: "expected <Model>.<Action> (e.g. Employee.regularize)"
2962
3049
  });
2963
3050
  }
2964
3051
  if (args.id && args.ids) {
2965
- throw new CliError8({
2966
- code: CliErrorCode7.INVALID_ARGUMENT,
3052
+ throw new CliError9({
3053
+ code: CliErrorCode8.INVALID_ARGUMENT,
2967
3054
  message: "--id and --ids are mutually exclusive"
2968
3055
  });
2969
3056
  }
@@ -2995,6 +3082,10 @@ async function actionCommand(spec, args) {
2995
3082
  }
2996
3083
  const result = await client3.action(model, action, input);
2997
3084
  const fmt = args.output ?? "json";
3085
+ if (args.artifactOutput) {
3086
+ await emitArtifact(result, args.artifactOutput, { force: args.artifactForce }, fmt);
3087
+ return;
3088
+ }
2998
3089
  printActionResult(result, fmt);
2999
3090
  } catch (e) {
3000
3091
  const err = e;
@@ -3004,6 +3095,29 @@ async function actionCommand(spec, args) {
3004
3095
  exitWithError(e);
3005
3096
  }
3006
3097
  }
3098
+ async function emitArtifact(result, target, opts, fmt) {
3099
+ const parsed = parseArtifactEnvelope(result?.data ?? result);
3100
+ if (!parsed.ok) {
3101
+ throw new CliError9({
3102
+ code: CliErrorCode8.INVALID_ARGUMENT,
3103
+ message: `--artifact-output \u53EA\u63A5\u53D7\u6807\u51C6\u53EA\u8BFB\u5236\u54C1\u54CD\u5E94\uFF1A${parsed.reason}`,
3104
+ context: {
3105
+ nextStep: "\u786E\u8BA4\u8FD9\u4E2A Action \u5728\u76EE\u6807 Core \u4E0A\u8FD4\u56DE ActionArtifact\uFF08fileName / mediaType / encoding / content / sizeBytes / sha256 / capabilityVersion / language \u516B\u4E2A\u952E\uFF09\u3002\u82E5\u76EE\u6807 Core \u8F83\u65E7\u3001\u8FD8\u6CA1\u6709\u8FD9\u6761\u53EA\u8BFB\u5165\u53E3\uFF0C\u8BF7\u5347\u7EA7 Core\u2014\u2014\u4E0D\u8981\u6539\u7528\u4F1A\u521B\u5EFA Document \u7684\u5199\u5165\u53E3\u6765\u7ED5\u8FC7\u3002"
3106
+ }
3107
+ });
3108
+ }
3109
+ const written = await writeArtifact(parsed.artifact, target, opts);
3110
+ if (fmt === "json" || fmt === "yaml") {
3111
+ process.stdout.write(formatObject({ artifact: written }, { format: fmt }) + "\n");
3112
+ } else {
3113
+ process.stdout.write(
3114
+ `\u2705 \u5236\u54C1\u5DF2\u843D\u76D8\uFF1A${written.path}
3115
+ ${written.sizeBytes} \u5B57\u8282 \xB7 sha256 ${written.sha256.slice(0, 12)}\u2026 \xB7 ${written.mediaType} \xB7 \u8BED\u8A00 ${written.language}
3116
+ `
3117
+ );
3118
+ }
3119
+ process.exitCode = 0;
3120
+ }
3007
3121
  function printActionResult(result, fmt) {
3008
3122
  if (fmt !== "json" && result.taskId) {
3009
3123
  process.stdout.write(
@@ -3019,16 +3133,16 @@ function printActionResult(result, fmt) {
3019
3133
  function normalizeMethod(value) {
3020
3134
  const raw = (value ?? "POST").toUpperCase();
3021
3135
  if (raw === "GET" || raw === "POST" || raw === "PUT" || raw === "DELETE") return raw;
3022
- throw new CliError8({
3023
- code: CliErrorCode7.INVALID_ARGUMENT,
3136
+ throw new CliError9({
3137
+ code: CliErrorCode8.INVALID_ARGUMENT,
3024
3138
  message: `--method \u53D6\u503C GET | POST | PUT | DELETE\uFF0C\u6536\u5230 "${value}"`
3025
3139
  });
3026
3140
  }
3027
3141
  function normalizeScope(value) {
3028
3142
  if (value === void 0) return void 0;
3029
3143
  if (value === "class" || value === "object") return value;
3030
- throw new CliError8({
3031
- code: CliErrorCode7.INVALID_ARGUMENT,
3144
+ throw new CliError9({
3145
+ code: CliErrorCode8.INVALID_ARGUMENT,
3032
3146
  message: `--scope \u53D6\u503C class | object\uFF0C\u6536\u5230 "${value}"`
3033
3147
  });
3034
3148
  }
@@ -3080,13 +3194,13 @@ import {
3080
3194
  HcmClient as HcmClient4,
3081
3195
  formatObject as formatObject3,
3082
3196
  fromAxiosError as fromAxiosError4,
3083
- CliError as CliError9,
3084
- CliErrorCode as CliErrorCode8
3197
+ CliError as CliError10,
3198
+ CliErrorCode as CliErrorCode9
3085
3199
  } from "@hcmai/sdk";
3086
3200
  async function updateCommand(model, args) {
3087
3201
  try {
3088
3202
  if (!args.id) {
3089
- throw new CliError9({ code: CliErrorCode8.MISSING_FLAG, message: "--id <id> \u5FC5\u586B" });
3203
+ throw new CliError10({ code: CliErrorCode9.MISSING_FLAG, message: "--id <id> \u5FC5\u586B" });
3090
3204
  }
3091
3205
  const data = await readJsonObjectInput({
3092
3206
  inline: args.data,
@@ -3119,15 +3233,15 @@ import {
3119
3233
  patchSettingDomain,
3120
3234
  resetSettingItem,
3121
3235
  parseSettingAssignment,
3122
- CliError as CliError10,
3123
- CliErrorCode as CliErrorCode9
3236
+ CliError as CliError11,
3237
+ CliErrorCode as CliErrorCode10
3124
3238
  } from "@hcmai/sdk";
3125
3239
  init_exit();
3126
3240
  init_auth_guard();
3127
3241
  async function client(args) {
3128
3242
  return HcmClient5.fromAuthContext(await getActiveAuthContextFromCli(args));
3129
3243
  }
3130
- function fail(e, args) {
3244
+ function fail2(e, args) {
3131
3245
  const err = e;
3132
3246
  if (err?.response?.status === 404) {
3133
3247
  exitWithError(new Error("\u6CA1\u6709\u8FD9\u4E2A\u53C2\u6570\u57DF \u2014\u2014 \u7528 `hcm setting get <\u57DF>` \u770B\u73B0\u6709\u57DF\uFF0C\u5E38\u89C1\u6709 security / feature / integration"));
@@ -3156,15 +3270,15 @@ async function settingGetCommand(domain, args) {
3156
3270
  process.exitCode = 0;
3157
3271
  return;
3158
3272
  } catch (e) {
3159
- fail(e, args);
3273
+ fail2(e, args);
3160
3274
  }
3161
3275
  }
3162
3276
  async function settingSetCommand(domain, args) {
3163
3277
  try {
3164
3278
  const raw = args.set ?? [];
3165
3279
  if (raw.length === 0) {
3166
- throw new CliError10({
3167
- code: CliErrorCode9.MISSING_FLAG,
3280
+ throw new CliError11({
3281
+ code: CliErrorCode10.MISSING_FLAG,
3168
3282
  message: "\u81F3\u5C11\u8981\u4E00\u4E2A --set namespace.key=value\uFF0C\u4F8B\u5982 --set security.password.passwordPolicy=complex"
3169
3283
  });
3170
3284
  }
@@ -3172,7 +3286,7 @@ async function settingSetCommand(domain, args) {
3172
3286
  try {
3173
3287
  items = raw.map(parseSettingAssignment);
3174
3288
  } catch (e) {
3175
- throw new CliError10({ code: CliErrorCode9.INVALID_ARGUMENT, message: e.message });
3289
+ throw new CliError11({ code: CliErrorCode10.INVALID_ARGUMENT, message: e.message });
3176
3290
  }
3177
3291
  if (args.dryRun) {
3178
3292
  process.stdout.write(`[dry-run] \u5C06\u5728\u57DF ${domain} \u5199\u5165 ${items.length} \u9879\uFF0C\u672A\u5B9E\u9645\u5199\u5165\uFF1A
@@ -3191,7 +3305,7 @@ async function settingSetCommand(domain, args) {
3191
3305
  process.exitCode = 0;
3192
3306
  return;
3193
3307
  } catch (e) {
3194
- fail(e, args);
3308
+ fail2(e, args);
3195
3309
  }
3196
3310
  }
3197
3311
  async function settingResetCommand(domain, namespace, key2, args) {
@@ -3213,7 +3327,7 @@ async function settingResetCommand(domain, namespace, key2, args) {
3213
3327
  process.exitCode = 0;
3214
3328
  return;
3215
3329
  } catch (e) {
3216
- fail(e, args);
3330
+ fail2(e, args);
3217
3331
  }
3218
3332
  }
3219
3333
 
@@ -3226,22 +3340,22 @@ import {
3226
3340
  loadEnv as loadEnv4,
3227
3341
  loadGlobalConfig as loadGlobalConfig5,
3228
3342
  resolveActiveEnv as resolveActiveEnv2,
3229
- CliError as CliError11,
3230
- CliErrorCode as CliErrorCode10
3343
+ CliError as CliError12,
3344
+ CliErrorCode as CliErrorCode11
3231
3345
  } from "@hcmai/sdk";
3232
3346
  async function versionCommand(args) {
3233
3347
  try {
3234
3348
  let endpoint = args.endpoint;
3235
3349
  if (!endpoint) {
3236
3350
  const g = await loadGlobalConfig5();
3237
- const env2 = await loadEnv4(resolveActiveEnv2({ envFlag: args.env }, process.env, g)).catch(() => null);
3238
- if (!env2?.endpoint) {
3239
- throw new CliError11({
3240
- code: CliErrorCode10.MISSING_FLAG,
3351
+ const env3 = await loadEnv4(resolveActiveEnv2({ envFlag: args.env }, process.env, g)).catch(() => null);
3352
+ if (!env3?.endpoint) {
3353
+ throw new CliError12({
3354
+ code: CliErrorCode11.MISSING_FLAG,
3241
3355
  message: "\u672A\u89E3\u6790\u5230 endpoint \u2014\u2014 \u4F20 --endpoint <url>\uFF0C\u6216\u5148 `hcm env add <name> --endpoint <url>`"
3242
3356
  });
3243
3357
  }
3244
- endpoint = env2.endpoint;
3358
+ endpoint = env3.endpoint;
3245
3359
  }
3246
3360
  const http = createHttpClient({
3247
3361
  endpoint: endpoint.replace(/\/+$/, ""),
@@ -3330,15 +3444,15 @@ async function upgradeCommand(args) {
3330
3444
  init_auth_guard();
3331
3445
  init_exit();
3332
3446
  import { spawn } from "child_process";
3333
- import { CliError as CliError12, CliErrorCode as CliErrorCode11, fromAxiosError as fromAxiosError7, HcmClient as HcmClient6, loadEnv as loadEnv5 } from "@hcmai/sdk";
3447
+ import { CliError as CliError13, CliErrorCode as CliErrorCode12, fromAxiosError as fromAxiosError7, HcmClient as HcmClient6, loadEnv as loadEnv5 } from "@hcmai/sdk";
3334
3448
  var BROWSER_TICKET_PATH = "/api/auth/browser-ticket";
3335
3449
  var SSO_CALLBACK_PATH = "/sso/callback";
3336
3450
  function normalizeTarget(target) {
3337
3451
  const raw = (target ?? "").trim();
3338
3452
  if (!raw) return "/";
3339
3453
  if (/^[a-z][a-z0-9+.-]*:\/\//i.test(raw)) {
3340
- throw new CliError12({
3341
- code: CliErrorCode11.INVALID_ARGUMENT,
3454
+ throw new CliError13({
3455
+ code: CliErrorCode12.INVALID_ARGUMENT,
3342
3456
  message: `\u53EA\u6536\u7AD9\u5185\u8DEF\u5F84\uFF08\u5982 /dashboard/<id>\uFF09\uFF0C\u4E0D\u6536\u5B8C\u6574 URL\uFF1A${raw}`
3343
3457
  });
3344
3458
  }
@@ -3364,8 +3478,8 @@ function launchBrowser(url, platform = process.platform) {
3364
3478
  async function runOpen(target, args, deps) {
3365
3479
  const path19 = normalizeTarget(target);
3366
3480
  if (!deps.frontend?.trim()) {
3367
- throw new CliError12({
3368
- code: CliErrorCode11.INVALID_ARGUMENT,
3481
+ throw new CliError13({
3482
+ code: CliErrorCode12.INVALID_ARGUMENT,
3369
3483
  message: `env '${args.envName}' \u6CA1\u914D\u524D\u7AEF\u5730\u5740\uFF0C\u5F00\u4E0D\u4E86\u9875\u9762\u3002\u5148\u8DD1\uFF1Ahcm env edit frontend <\u524D\u7AEF\u5730\u5740> --env ${args.envName}`
3370
3484
  });
3371
3485
  }
@@ -3399,8 +3513,8 @@ async function openCommand(target, args) {
3399
3513
  } catch (e) {
3400
3514
  const err = e;
3401
3515
  if (err?.isAxiosError && err.response?.status === 404) {
3402
- throw new CliError12({
3403
- code: CliErrorCode11.INVALID_ARGUMENT,
3516
+ throw new CliError13({
3517
+ code: CliErrorCode12.INVALID_ARGUMENT,
3404
3518
  message: `\u540E\u7AEF\u6CA1\u6709 ${BROWSER_TICKET_PATH}\uFF08\u9700\u8981\u542B\u6D4F\u89C8\u5668\u4F1A\u8BDD\u7968\u636E\u7684\u540E\u7AEF\u7248\u672C\uFF09\uFF0C\u5347\u7EA7\u540E\u7AEF\u540E\u518D\u8BD5\u3002\u672C\u547D\u4EE4\u4E0D\u4F1A\u628A\u4F1A\u8BDD token \u62FC\u8FDB URL \u515C\u5E95\u3002`
3405
3519
  });
3406
3520
  }
@@ -3408,8 +3522,8 @@ async function openCommand(target, args) {
3408
3522
  throw e;
3409
3523
  }
3410
3524
  if (typeof data.ticket !== "string" || !data.ticket) {
3411
- throw new CliError12({
3412
- code: CliErrorCode11.INVALID_ARGUMENT,
3525
+ throw new CliError13({
3526
+ code: CliErrorCode12.INVALID_ARGUMENT,
3413
3527
  message: "\u94F8\u7968\u54CD\u5E94\u91CC\u6CA1\u6709 ticket \u2014\u2014 \u540E\u7AEF\u7248\u672C\u4E0E\u672C CLI \u7684\u5951\u7EA6\u5BF9\u4E0D\u4E0A"
3414
3528
  });
3415
3529
  }
@@ -3436,13 +3550,13 @@ import {
3436
3550
  HcmClient as HcmClient7,
3437
3551
  formatObject as formatObject6,
3438
3552
  fromAxiosError as fromAxiosError8,
3439
- CliError as CliError13,
3440
- CliErrorCode as CliErrorCode12
3553
+ CliError as CliError14,
3554
+ CliErrorCode as CliErrorCode13
3441
3555
  } from "@hcmai/sdk";
3442
3556
  async function deleteCommand(model, args) {
3443
3557
  try {
3444
3558
  if (!args.id) {
3445
- throw new CliError13({ code: CliErrorCode12.MISSING_FLAG, message: "--id <id> \u5FC5\u586B" });
3559
+ throw new CliError14({ code: CliErrorCode13.MISSING_FLAG, message: "--id <id> \u5FC5\u586B" });
3446
3560
  }
3447
3561
  const client3 = HcmClient7.fromAuthContext(await getActiveAuthContextFromCli(args));
3448
3562
  const res = await client3.remove(model, args.id);
@@ -3601,8 +3715,8 @@ import {
3601
3715
  fetchConversationTimelineStrict,
3602
3716
  fetchRecentConversations,
3603
3717
  findLastAssistantSeq,
3604
- CliError as CliError14,
3605
- CliErrorCode as CliErrorCode13,
3718
+ CliError as CliError15,
3719
+ CliErrorCode as CliErrorCode14,
3606
3720
  parseInteractionRequest as parseInteractionRequest2,
3607
3721
  parseInteractionResolved as parseInteractionResolved2,
3608
3722
  buildConfirm as buildConfirm2,
@@ -3612,51 +3726,51 @@ import {
3612
3726
  buildSteer
3613
3727
  } from "@hcmai/sdk";
3614
3728
  import chalk2 from "chalk";
3615
- import * as fs4 from "fs/promises";
3729
+ import * as fs5 from "fs/promises";
3616
3730
  function parseInjectOn(s) {
3617
- const fail6 = (detail) => {
3618
- throw new CliError14({
3619
- code: CliErrorCode13.INVALID_ARGUMENT,
3731
+ const fail7 = (detail) => {
3732
+ throw new CliError15({
3733
+ code: CliErrorCode14.INVALID_ARGUMENT,
3620
3734
  message: `--inject-on \u683C\u5F0F <eventType>:<action>[:<arg>]\uFF0Caction \u2208 {interrupt, steer}\uFF08steer \u5FC5\u987B\u5E26 content\uFF09\uFF1B${detail}\uFF0C\u6536\u5230 "${s}"`
3621
3735
  });
3622
3736
  };
3623
3737
  const firstColon = s.indexOf(":");
3624
- if (firstColon < 0) return fail6("\u7F3A\u5C11 action \u6BB5");
3738
+ if (firstColon < 0) return fail7("\u7F3A\u5C11 action \u6BB5");
3625
3739
  const eventType = s.slice(0, firstColon);
3626
3740
  const rest = s.slice(firstColon + 1);
3627
3741
  const secondColon = rest.indexOf(":");
3628
3742
  const action = secondColon < 0 ? rest : rest.slice(0, secondColon);
3629
3743
  const arg = secondColon < 0 ? void 0 : rest.slice(secondColon + 1);
3630
- if (!eventType) return fail6("eventType \u6BB5\u4E3A\u7A7A");
3744
+ if (!eventType) return fail7("eventType \u6BB5\u4E3A\u7A7A");
3631
3745
  if (action === "interrupt") {
3632
- if (arg !== void 0) return fail6("interrupt \u4E0D\u63A5\u53D7 arg");
3746
+ if (arg !== void 0) return fail7("interrupt \u4E0D\u63A5\u53D7 arg");
3633
3747
  return { eventType, action: "interrupt" };
3634
3748
  }
3635
3749
  if (action === "steer") {
3636
- if (arg === void 0 || arg === "") return fail6("steer \u5FC5\u987B\u5E26 content\uFF08arg\uFF09");
3750
+ if (arg === void 0 || arg === "") return fail7("steer \u5FC5\u987B\u5E26 content\uFF08arg\uFF09");
3637
3751
  return { eventType, action: "steer", arg };
3638
3752
  }
3639
- return fail6(`\u672A\u77E5 action "${action}"`);
3753
+ return fail7(`\u672A\u77E5 action "${action}"`);
3640
3754
  }
3641
3755
  function parseOnConfirm(s) {
3642
3756
  if (s === "approve") return { decision: "approve" };
3643
3757
  if (s === "reject") return { decision: "reject" };
3644
3758
  if (s.startsWith("reject:")) return { decision: "reject", reason: s.slice("reject:".length) };
3645
- throw new CliError14({
3646
- code: CliErrorCode13.INVALID_ARGUMENT,
3759
+ throw new CliError15({
3760
+ code: CliErrorCode14.INVALID_ARGUMENT,
3647
3761
  message: `--on-confirm \u53D6\u503C approve | reject | reject:<reason>\uFF0C\u6536\u5230 "${s}"`
3648
3762
  });
3649
3763
  }
3650
3764
  function resolveResumeConversation(args) {
3651
3765
  if (args.resume && args.conversation) {
3652
- throw new CliError14({
3653
- code: CliErrorCode13.INVALID_ARGUMENT,
3766
+ throw new CliError15({
3767
+ code: CliErrorCode14.INVALID_ARGUMENT,
3654
3768
  message: "--resume \u548C --conversation \u4E0D\u80FD\u540C\u65F6\u4F7F\u7528\uFF1B\u65B0\u547D\u4EE4\u8BF7\u7528 --resume <conversationId>"
3655
3769
  });
3656
3770
  }
3657
3771
  if (args.resume === "NEW") {
3658
- throw new CliError14({
3659
- code: CliErrorCode13.INVALID_ARGUMENT,
3772
+ throw new CliError15({
3773
+ code: CliErrorCode14.INVALID_ARGUMENT,
3660
3774
  message: "--resume \u9700\u8981\u65E2\u5B58 conversationId\uFF1B\u65B0\u4F1A\u8BDD\u8BF7\u76F4\u63A5\u7701\u7565 --resume"
3661
3775
  });
3662
3776
  }
@@ -3667,8 +3781,8 @@ function resolveResumeConversation(args) {
3667
3781
  function parsePositiveInt(value, fallback, flag) {
3668
3782
  const n = Number(value ?? fallback);
3669
3783
  if (!Number.isInteger(n) || n <= 0) {
3670
- throw new CliError14({
3671
- code: CliErrorCode13.INVALID_ARGUMENT,
3784
+ throw new CliError15({
3785
+ code: CliErrorCode14.INVALID_ARGUMENT,
3672
3786
  message: `${flag} \u9700\u8981\u6B63\u6574\u6570\uFF0C\u6536\u5230 "${value}"`
3673
3787
  });
3674
3788
  }
@@ -3691,21 +3805,21 @@ function resolveEventsConversation(args) {
3691
3805
  const resumeConversationId = resolveResumeConversation(args);
3692
3806
  const eventConversationId = typeof args.events === "string" ? args.events.trim() : void 0;
3693
3807
  if (eventConversationId === "NEW") {
3694
- throw new CliError14({
3695
- code: CliErrorCode13.INVALID_ARGUMENT,
3808
+ throw new CliError15({
3809
+ code: CliErrorCode14.INVALID_ARGUMENT,
3696
3810
  message: "--events \u9700\u8981\u65E2\u5B58 conversationId\uFF1B\u65B0\u4F1A\u8BDD\u6CA1\u6709\u53EF\u67E5\u8BE2\u7684\u4E8B\u4EF6\u6D41"
3697
3811
  });
3698
3812
  }
3699
3813
  if (eventConversationId && resumeConversationId && eventConversationId !== resumeConversationId) {
3700
- throw new CliError14({
3701
- code: CliErrorCode13.INVALID_ARGUMENT,
3814
+ throw new CliError15({
3815
+ code: CliErrorCode14.INVALID_ARGUMENT,
3702
3816
  message: "--events <conversationId> \u4E0E --resume/--conversation \u6307\u5411\u4E0D\u540C\u4F1A\u8BDD\uFF1B\u8BF7\u53EA\u4FDD\u7559\u4E00\u4E2A id"
3703
3817
  });
3704
3818
  }
3705
3819
  const id = eventConversationId || resumeConversationId;
3706
3820
  if (!id) {
3707
- throw new CliError14({
3708
- code: CliErrorCode13.INVALID_ARGUMENT,
3821
+ throw new CliError15({
3822
+ code: CliErrorCode14.INVALID_ARGUMENT,
3709
3823
  message: "\u67E5\u8BE2\u4E8B\u4EF6\u6D41\u8BF7\u4F20 `hcm chat --events <conversationId>`\uFF0C\u6216 `hcm chat --resume <conversationId> --events`"
3710
3824
  });
3711
3825
  }
@@ -3809,8 +3923,8 @@ async function printConversationEvents(conversationId, args) {
3809
3923
  }
3810
3924
  async function printConversationList(args) {
3811
3925
  if (args.events || args.resume || args.conversation || args.regenerateFrom || args.promptFile) {
3812
- throw new CliError14({
3813
- code: CliErrorCode13.INVALID_ARGUMENT,
3926
+ throw new CliError15({
3927
+ code: CliErrorCode14.INVALID_ARGUMENT,
3814
3928
  message: "--list \u53EA\u7528\u4E8E\u5217\u4F1A\u8BDD\uFF1B\u4E0D\u8981\u540C\u65F6\u4F20 --events/--resume/--conversation/--regenerate-from/--prompt-file"
3815
3929
  });
3816
3930
  }
@@ -3840,8 +3954,8 @@ async function chatCommand(prompt, args) {
3840
3954
  try {
3841
3955
  if (args.list) {
3842
3956
  if (prompt) {
3843
- throw new CliError14({
3844
- code: CliErrorCode13.INVALID_ARGUMENT,
3957
+ throw new CliError15({
3958
+ code: CliErrorCode14.INVALID_ARGUMENT,
3845
3959
  message: "--list \u4E0D\u63A5\u53D7 prompt\uFF1B\u7528 `hcm chat --list` \u67E5\u770B\u6700\u8FD1\u4F1A\u8BDD"
3846
3960
  });
3847
3961
  }
@@ -3852,8 +3966,8 @@ async function chatCommand(prompt, args) {
3852
3966
  const eventsConversationId = resolveEventsConversation(args);
3853
3967
  if (eventsConversationId) {
3854
3968
  if (prompt || args.promptFile || args.regenerateFrom || args.attach?.length) {
3855
- throw new CliError14({
3856
- code: CliErrorCode13.INVALID_ARGUMENT,
3969
+ throw new CliError15({
3970
+ code: CliErrorCode14.INVALID_ARGUMENT,
3857
3971
  message: "--events \u662F\u53EA\u8BFB\u67E5\u8BE2\uFF1B\u4E0D\u8981\u540C\u65F6\u4F20 prompt/--prompt-file/--regenerate-from/--attach"
3858
3972
  });
3859
3973
  }
@@ -3871,15 +3985,15 @@ async function chatCommand(prompt, args) {
3871
3985
  } else {
3872
3986
  regenerateFromSeq = Number(args.regenerateFrom);
3873
3987
  if (!Number.isInteger(regenerateFromSeq) || regenerateFromSeq <= 0) {
3874
- throw new CliError14({
3875
- code: CliErrorCode13.INVALID_ARGUMENT,
3988
+ throw new CliError15({
3989
+ code: CliErrorCode14.INVALID_ARGUMENT,
3876
3990
  message: `--regenerate-from \u9700\u8981\u6B63\u6574\u6570 journal seq \u6216 last-assistant\uFF0C\u6536\u5230 "${args.regenerateFrom}"`
3877
3991
  });
3878
3992
  }
3879
3993
  }
3880
3994
  if (!requestedConversationId) {
3881
- throw new CliError14({
3882
- code: CliErrorCode13.INVALID_ARGUMENT,
3995
+ throw new CliError15({
3996
+ code: CliErrorCode14.INVALID_ARGUMENT,
3883
3997
  message: "--regenerate-from \u5FC5\u987B\u914D\u5408 --resume <\u65E2\u5B58\u4F1A\u8BDD id>\uFF08\u91CD\u8DD1\u65E2\u5B58\u6BB5\uFF0C\u65E0\u65B0 prompt\uFF09"
3884
3998
  });
3885
3999
  }
@@ -3890,11 +4004,11 @@ async function chatCommand(prompt, args) {
3890
4004
  return runInkRepl2(args);
3891
4005
  }
3892
4006
  if (args.promptFile) {
3893
- prompt = await fs4.readFile(args.promptFile, "utf-8");
4007
+ prompt = await fs5.readFile(args.promptFile, "utf-8");
3894
4008
  }
3895
4009
  if (prompt === void 0 || !prompt && !regenerateMode) {
3896
- throw new CliError14({
3897
- code: CliErrorCode13.INVALID_ARGUMENT,
4010
+ throw new CliError15({
4011
+ code: CliErrorCode14.INVALID_ARGUMENT,
3898
4012
  message: "prompt is required (positional or --prompt-file)"
3899
4013
  });
3900
4014
  }
@@ -3915,8 +4029,8 @@ async function chatCommand(prompt, args) {
3915
4029
  const items = await fetchConversationTimeline2(client3.raw(), resumeConversationId);
3916
4030
  const lastSeq = findLastAssistantSeq(items);
3917
4031
  if (lastSeq == null) {
3918
- throw new CliError14({
3919
- code: CliErrorCode13.BUSINESS_RULE_VIOLATION,
4032
+ throw new CliError15({
4033
+ code: CliErrorCode14.BUSINESS_RULE_VIOLATION,
3920
4034
  message: `--regenerate-from last-assistant \u627E\u4E0D\u5230\u53EF\u91CD\u8DD1\u7684 chat-text seq: conversation=${resumeConversationId}`
3921
4035
  });
3922
4036
  }
@@ -4136,8 +4250,8 @@ async function chatCommand(prompt, args) {
4136
4250
  } catch (e) {
4137
4251
  process.removeListener("SIGINT", sigintHandler);
4138
4252
  await ws.close();
4139
- throw new CliError14({
4140
- code: e.code ?? CliErrorCode13.BUSINESS_RULE_VIOLATION,
4253
+ throw new CliError15({
4254
+ code: e.code ?? CliErrorCode14.BUSINESS_RULE_VIOLATION,
4141
4255
  message: e.message,
4142
4256
  traceId: e.traceId ?? void 0
4143
4257
  });
@@ -4640,7 +4754,7 @@ function emit(result, args, human) {
4640
4754
  process.exitCode = 0;
4641
4755
  return;
4642
4756
  }
4643
- function fail2(e, args) {
4757
+ function fail3(e, args) {
4644
4758
  const err = e;
4645
4759
  if (err?.isAxiosError) exitWithError(fromAxiosError12(err, args.env));
4646
4760
  exitWithError(e);
@@ -4651,7 +4765,7 @@ async function cacheStatsCommand(model, args) {
4651
4765
  const stats = await withClient(args, (c) => getCacheStats(c.raw(), model));
4652
4766
  emit(stats, args, `\u{1F4CA} ${model} \u7F13\u5B58\u7EDF\u8BA1`);
4653
4767
  } catch (e) {
4654
- fail2(e, args);
4768
+ fail3(e, args);
4655
4769
  }
4656
4770
  }
4657
4771
  async function cacheClearCommand(model, args) {
@@ -4659,7 +4773,7 @@ async function cacheClearCommand(model, args) {
4659
4773
  const result = await withClient(args, (c) => clearModelCache(c.raw(), model, args.id));
4660
4774
  emit(result, args, args.id ? `\u{1F9F9} \u5DF2\u6E05 ${model}#${args.id} \u7F13\u5B58` : `\u{1F9F9} \u5DF2\u6E05 ${model} \u5168\u90E8\u5B9E\u4F53\u7F13\u5B58`);
4661
4775
  } catch (e) {
4662
- fail2(e, args);
4776
+ fail3(e, args);
4663
4777
  }
4664
4778
  }
4665
4779
  async function cacheClearMetaCommand(model, args) {
@@ -4671,7 +4785,7 @@ async function cacheClearMetaCommand(model, args) {
4671
4785
  const scope = args.type ? `${args.type}${args.state ? `.${args.state}` : ""}` : "\u5168\u90E8";
4672
4786
  emit(result, args, `\u{1F9F9} \u5DF2\u6E05 ${model} \u5143\u6570\u636E\u7F13\u5B58\uFF08${scope}\uFF09`);
4673
4787
  } catch (e) {
4674
- fail2(e, args);
4788
+ fail3(e, args);
4675
4789
  }
4676
4790
  }
4677
4791
 
@@ -4699,7 +4813,7 @@ function emit2(result, args, human) {
4699
4813
  process.exitCode = 0;
4700
4814
  return;
4701
4815
  }
4702
- function fail3(e, args) {
4816
+ function fail4(e, args) {
4703
4817
  const err = e;
4704
4818
  if (err?.isAxiosError) exitWithError(fromAxiosError13(err, args.env));
4705
4819
  exitWithError(e);
@@ -4743,7 +4857,7 @@ async function scriptDryRunCommand(args) {
4743
4857
  const intents = Array.isArray(result?.writeIntents) ? result.writeIntents.length : 0;
4744
4858
  emit2(result, args, `\u{1F9EA} dry-run \u5B8C\u6210\uFF1A${args.scriptKey}\uFF08\u62E6\u4E0B ${intents} \u4E2A\u5199\u610F\u56FE\uFF09`);
4745
4859
  } catch (e) {
4746
- fail3(e, args);
4860
+ fail4(e, args);
4747
4861
  }
4748
4862
  }
4749
4863
  async function scriptManifestValidateCommand(args) {
@@ -4755,7 +4869,7 @@ async function scriptManifestValidateCommand(args) {
4755
4869
  const result = await withClient2(args, (c) => validateScriptManifest(c.raw(), yaml3));
4756
4870
  emit2(result, args, `\u{1F4CB} manifest \u6821\u9A8C\u5B8C\u6210\uFF1A${args.file}`);
4757
4871
  } catch (e) {
4758
- fail3(e, args);
4872
+ fail4(e, args);
4759
4873
  }
4760
4874
  }
4761
4875
  async function scriptLogsCommand(args) {
@@ -4775,7 +4889,7 @@ async function scriptLogsCommand(args) {
4775
4889
  );
4776
4890
  emit2(page, args, "\u{1F4DC} \u811A\u672C\u6267\u884C\u65E5\u5FD7");
4777
4891
  } catch (e) {
4778
- fail3(e, args);
4892
+ fail4(e, args);
4779
4893
  }
4780
4894
  }
4781
4895
  async function scriptTaskCommand(taskId, args) {
@@ -4783,7 +4897,7 @@ async function scriptTaskCommand(taskId, args) {
4783
4897
  const task = await withClient2(args, (c) => getScriptTask(c.raw(), taskId));
4784
4898
  emit2(task, args, `\u2699\uFE0F \u4EFB\u52A1 ${taskId}\uFF1A${task?.status ?? "\u672A\u77E5"}\uFF08\u7B2C ${task?.attempts ?? "?"}/${task?.maxAttempts ?? "?"} \u6B21\uFF09`);
4785
4899
  } catch (e) {
4786
- fail3(e, args);
4900
+ fail4(e, args);
4787
4901
  }
4788
4902
  }
4789
4903
 
@@ -4996,8 +5110,8 @@ function emit3(payload, fmt) {
4996
5110
  init_exit();
4997
5111
  import { promises as fsp2 } from "fs";
4998
5112
  import os2 from "os";
4999
- import path4 from "path";
5000
- import { createHash as createHash2 } from "crypto";
5113
+ import path5 from "path";
5114
+ import { createHash as createHash3 } from "crypto";
5001
5115
  import {
5002
5116
  createHttpClient as createHttpClient2,
5003
5117
  fetchSkillCatalog,
@@ -5018,12 +5132,12 @@ import {
5018
5132
  loadEnv as loadEnv6,
5019
5133
  loadGlobalConfig as loadGlobalConfig6,
5020
5134
  resolveActiveEnv as resolveActiveEnv3,
5021
- CliError as CliError17,
5022
- CliErrorCode as CliErrorCode16
5135
+ CliError as CliError18,
5136
+ CliErrorCode as CliErrorCode17
5023
5137
  } from "@hcmai/sdk";
5024
5138
 
5025
5139
  // src/commands/skills-catalog.ts
5026
- import { flattenSkills, CliError as CliError15, CliErrorCode as CliErrorCode14 } from "@hcmai/sdk";
5140
+ import { flattenSkills, CliError as CliError16, CliErrorCode as CliErrorCode15 } from "@hcmai/sdk";
5027
5141
  var CLI_CATEGORY_KEY = "cli-operations";
5028
5142
  var CLI_CATEGORY_NAME = "CLI \u64CD\u4F5C";
5029
5143
  function chironEntry(skill) {
@@ -5066,8 +5180,8 @@ var SOURCE_FILTERS = ["cli", "chiron", "all"];
5066
5180
  function parseSourceFilter(raw) {
5067
5181
  if (raw === void 0) return "all";
5068
5182
  if (SOURCE_FILTERS.includes(raw)) return raw;
5069
- throw new CliError15({
5070
- code: CliErrorCode14.INVALID_ARGUMENT,
5183
+ throw new CliError16({
5184
+ code: CliErrorCode15.INVALID_ARGUMENT,
5071
5185
  message: `--source \u53EA\u8BA4 ${SOURCE_FILTERS.join(" / ")}\uFF0C\u6536\u5230 "${raw}"\u3002\uFF08\`local\` \u4E0D\u662F\u53D6\u503C\uFF1A\u6CA1\u6709\u54EA\u4E00\u8D9F\u4F1A\u53BB\u300C\u626B local \u6765\u6E90\u300D\uFF0Cinstall --from \u88C5\u7684\u90A3\u4E9B\u5728\u4EFB\u4F55 --source \u4E0B\u90FD\u5355\u5217\u3001\u90FD\u4E0D\u53C2\u4E0E\u5347\u7EA7\u3002\uFF09`
5072
5186
  });
5073
5187
  }
@@ -5137,13 +5251,13 @@ function checkCrossSourceRequires(catalog) {
5137
5251
 
5138
5252
  // src/commands/skills-bundled.ts
5139
5253
  import { promises as fsp } from "fs";
5140
- import * as path3 from "path";
5141
- import { CliError as CliError16, CliErrorCode as CliErrorCode15, assertSafeReferencePath, parseSkillRequirements } from "@hcmai/sdk";
5254
+ import * as path4 from "path";
5255
+ import { CliError as CliError17, CliErrorCode as CliErrorCode16, assertSafeReferencePath, parseSkillRequirements } from "@hcmai/sdk";
5142
5256
 
5143
5257
  // src/commands/skills-manifest.ts
5144
5258
  import { readFileSync as readFileSync4, readdirSync as readdirSync2, statSync as statSync3, existsSync } from "fs";
5145
- import { createHash } from "crypto";
5146
- import * as path2 from "path";
5259
+ import { createHash as createHash2 } from "crypto";
5260
+ import * as path3 from "path";
5147
5261
  import { fileURLToPath } from "url";
5148
5262
  import { formatObject as formatObject15, parseSkillFrontmatter } from "@hcmai/sdk";
5149
5263
  function collectCommandSurface(root) {
@@ -5160,16 +5274,16 @@ function collectCommandSurface(root) {
5160
5274
  return out.sort((a, b) => a.path.localeCompare(b.path));
5161
5275
  }
5162
5276
  function bundledSkillsDir() {
5163
- const here = path2.dirname(fileURLToPath(import.meta.url));
5164
- return path2.join(here, "skills");
5277
+ const here = path3.dirname(fileURLToPath(import.meta.url));
5278
+ return path3.join(here, "skills");
5165
5279
  }
5166
5280
  function sha256(buf) {
5167
- return createHash("sha256").update(buf).digest("hex");
5281
+ return createHash2("sha256").update(buf).digest("hex");
5168
5282
  }
5169
5283
  function listFiles(dir, rel = "") {
5170
5284
  const out = [];
5171
5285
  for (const name of readdirSync2(dir)) {
5172
- const p = path2.join(dir, name);
5286
+ const p = path3.join(dir, name);
5173
5287
  const r = rel ? `${rel}/${name}` : name;
5174
5288
  if (statSync3(p).isDirectory()) out.push(...listFiles(p, r));
5175
5289
  else out.push(r);
@@ -5180,17 +5294,17 @@ function collectBundledSkills(dir = bundledSkillsDir()) {
5180
5294
  if (!existsSync(dir)) return [];
5181
5295
  const out = [];
5182
5296
  for (const id of readdirSync2(dir).sort()) {
5183
- const skillDir = path2.join(dir, id);
5297
+ const skillDir = path3.join(dir, id);
5184
5298
  if (!statSync3(skillDir).isDirectory()) continue;
5185
5299
  const files = listFiles(skillDir).sort();
5186
5300
  if (!files.includes("SKILL.md")) continue;
5187
5301
  let bytes = 0;
5188
5302
  const fileRows = files.map((rel) => {
5189
- const buf = readFileSync4(path2.join(skillDir, rel));
5303
+ const buf = readFileSync4(path3.join(skillDir, rel));
5190
5304
  bytes += buf.byteLength;
5191
5305
  return { path: rel, bytes: buf.byteLength, sha256: sha256(buf) };
5192
5306
  });
5193
- const body = readFileSync4(path2.join(skillDir, "SKILL.md"), "utf8");
5307
+ const body = readFileSync4(path3.join(skillDir, "SKILL.md"), "utf8");
5194
5308
  const fm = parseSkillFrontmatter(body, id);
5195
5309
  out.push({
5196
5310
  id,
@@ -5230,14 +5344,14 @@ function listBundledSkills(dir = bundledSkillsDir()) {
5230
5344
  return collectBundledSkills(dir);
5231
5345
  }
5232
5346
  function unreachable(id, detail) {
5233
- return new CliError16({
5234
- code: CliErrorCode15.SKILL_SOURCE_UNREACHABLE,
5347
+ return new CliError17({
5348
+ code: CliErrorCode16.SKILL_SOURCE_UNREACHABLE,
5235
5349
  message: `\u88C5\u5728\u8FD9\u4EFD CLI \u91CC\u7684\u6280\u80FD\u8D44\u6E90\u8BFB\u4E0D\u5230\uFF08${detail}\uFF09\uFF0C\u91CD\u88C5 @hcmai/cli\u3002
5236
5350
  \u6280\u80FD id\uFF1A${id}\uFF1B\u627E\u7684\u4F4D\u7F6E\uFF1A${bundledSkillsDir()}`
5237
5351
  });
5238
5352
  }
5239
5353
  async function readBundledReferences(skillDir) {
5240
- const root = path3.join(skillDir, "references");
5354
+ const root = path4.join(skillDir, "references");
5241
5355
  const out = [];
5242
5356
  const walk = async (dir, prefix) => {
5243
5357
  let items;
@@ -5250,22 +5364,22 @@ async function readBundledReferences(skillDir) {
5250
5364
  for (const item of items.sort((a, b) => a.name.localeCompare(b.name))) {
5251
5365
  const relative2 = prefix ? `${prefix}/${item.name}` : item.name;
5252
5366
  if (item.isDirectory()) {
5253
- await walk(path3.join(dir, item.name), relative2);
5367
+ await walk(path4.join(dir, item.name), relative2);
5254
5368
  continue;
5255
5369
  }
5256
5370
  if (!item.isFile()) continue;
5257
5371
  assertSafeReferencePath(relative2);
5258
- out.push({ path: relative2, content: await fsp.readFile(path3.join(dir, item.name), "utf8") });
5372
+ out.push({ path: relative2, content: await fsp.readFile(path4.join(dir, item.name), "utf8") });
5259
5373
  }
5260
5374
  };
5261
5375
  await walk(root, "");
5262
5376
  return out;
5263
5377
  }
5264
5378
  async function readBundledSkillDocument(id, dir = bundledSkillsDir()) {
5265
- const skillDir = path3.join(dir, id);
5379
+ const skillDir = path4.join(dir, id);
5266
5380
  let markdown;
5267
5381
  try {
5268
- markdown = await fsp.readFile(path3.join(skillDir, "SKILL.md"), "utf8");
5382
+ markdown = await fsp.readFile(path4.join(skillDir, "SKILL.md"), "utf8");
5269
5383
  } catch (cause) {
5270
5384
  if (cause?.code === "ENOENT") throw unreachable(id, "SKILL.md \u4E0D\u5B58\u5728");
5271
5385
  throw cause;
@@ -5288,8 +5402,8 @@ async function resolveBundledClosure(targetId, dir = bundledSkillsDir()) {
5288
5402
  const visit = async (id) => {
5289
5403
  if (state.get(id) === "done") return;
5290
5404
  if (state.get(id) === "visiting") {
5291
- throw new CliError16({
5292
- code: CliErrorCode15.INVALID_ARGUMENT,
5405
+ throw new CliError17({
5406
+ code: CliErrorCode16.INVALID_ARGUMENT,
5293
5407
  message: `\u81EA\u5E26\u6280\u80FD\u4F9D\u8D56\u6210\u73AF\uFF1A${[...stack, id].join(" \u2192 ")}`
5294
5408
  });
5295
5409
  }
@@ -5323,20 +5437,20 @@ function migrateSkillsState(state) {
5323
5437
  return { ...state, skills: skills2 };
5324
5438
  }
5325
5439
  function sha2562(text) {
5326
- return createHash2("sha256").update(text, "utf8").digest("hex");
5440
+ return createHash3("sha256").update(text, "utf8").digest("hex");
5327
5441
  }
5328
5442
  async function resolveEndpoint(args) {
5329
5443
  if (args.endpoint) return args.endpoint.replace(/\/+$/, "");
5330
5444
  const g = await loadGlobalConfig6();
5331
5445
  const envName = resolveActiveEnv3({ envFlag: args.env }, process.env, g);
5332
- const env2 = await loadEnv6(envName).catch(() => null);
5333
- if (!env2?.endpoint) {
5334
- throw new CliError17({
5335
- code: CliErrorCode16.MISSING_FLAG,
5446
+ const env3 = await loadEnv6(envName).catch(() => null);
5447
+ if (!env3?.endpoint) {
5448
+ throw new CliError18({
5449
+ code: CliErrorCode17.MISSING_FLAG,
5336
5450
  message: "\u672A\u89E3\u6790\u5230 endpoint \u2014\u2014 \u4F20 --endpoint <url>\uFF0C\u6216\u5148 `hcm env add <name> --endpoint <url>`\u3002\uFF08\u6280\u80FD\u5E93\u514D\u8BA4\u8BC1\uFF0C\u4E0D\u9700\u8981\u5148 login\uFF09"
5337
5451
  });
5338
5452
  }
5339
- return env2.endpoint.replace(/\/+$/, "");
5453
+ return env3.endpoint.replace(/\/+$/, "");
5340
5454
  }
5341
5455
  function normalizeEndpoint(endpoint) {
5342
5456
  return endpoint.replace(/\/+$/, "");
@@ -5351,8 +5465,8 @@ function decideTrackedEndpoint(options) {
5351
5465
  }
5352
5466
  if (!recorded) {
5353
5467
  if (!current) {
5354
- throw new CliError17({
5355
- code: CliErrorCode16.MISSING_FLAG,
5468
+ throw new CliError18({
5469
+ code: CliErrorCode17.MISSING_FLAG,
5356
5470
  message: "\u672A\u89E3\u6790\u5230 endpoint \u2014\u2014 \u4F20 --endpoint <url>\uFF0C\u6216\u5148 `hcm env add <name> --endpoint <url>`\u3002\uFF08\u6280\u80FD\u5E93\u514D\u8BA4\u8BC1\uFF0C\u4E0D\u9700\u8981\u5148 login\uFF09"
5357
5471
  });
5358
5472
  }
@@ -5376,27 +5490,27 @@ async function exists(target) {
5376
5490
  }
5377
5491
  }
5378
5492
  async function detectTarget(cwd) {
5379
- if (await exists(path4.join(cwd, ".claude"))) return "claude";
5380
- if (await exists(path4.join(cwd, "AGENTS.md"))) return "codex";
5381
- if (await exists(path4.join(cwd, ".codex"))) return "codex";
5493
+ if (await exists(path5.join(cwd, ".claude"))) return "claude";
5494
+ if (await exists(path5.join(cwd, "AGENTS.md"))) return "codex";
5495
+ if (await exists(path5.join(cwd, ".codex"))) return "codex";
5382
5496
  return void 0;
5383
5497
  }
5384
5498
  async function resolveInstallLayout(args, cwd = process.cwd()) {
5385
5499
  const requested = args.target && args.target !== "auto" ? args.target : void 0;
5386
5500
  const target = requested ?? await detectTarget(cwd) ?? "claude";
5387
5501
  if (target === "codex") {
5388
- const root = args.global ? path4.join(os2.homedir(), ".codex") : cwd;
5389
- const claudeFile = path4.join(root, "CLAUDE.md");
5502
+ const root = args.global ? path5.join(os2.homedir(), ".codex") : cwd;
5503
+ const claudeFile = path5.join(root, "CLAUDE.md");
5390
5504
  return {
5391
5505
  target,
5392
- baseDir: args.dir ? path4.resolve(args.dir) : path4.join(root, "hcm-skills"),
5393
- agentsFile: path4.join(root, "AGENTS.md"),
5506
+ baseDir: args.dir ? path5.resolve(args.dir) : path5.join(root, "hcm-skills"),
5507
+ agentsFile: path5.join(root, "AGENTS.md"),
5394
5508
  companionAgentFiles: !args.global && await exists(claudeFile) ? [claudeFile] : []
5395
5509
  };
5396
5510
  }
5397
5511
  return {
5398
5512
  target,
5399
- baseDir: args.dir ? path4.resolve(args.dir) : args.global ? path4.join(os2.homedir(), ".claude", "skills") : path4.join(cwd, ".claude", "skills")
5513
+ baseDir: args.dir ? path5.resolve(args.dir) : args.global ? path5.join(os2.homedir(), ".claude", "skills") : path5.join(cwd, ".claude", "skills")
5400
5514
  };
5401
5515
  }
5402
5516
  async function chironClient(args) {
@@ -5409,7 +5523,7 @@ async function chironClient(args) {
5409
5523
  });
5410
5524
  return { http, endpoint, base: await resolveChironBase(http) };
5411
5525
  }
5412
- function fail4(e, args) {
5526
+ function fail5(e, args) {
5413
5527
  const err = e;
5414
5528
  if (err?.response?.status === 404) {
5415
5529
  exitWithError(new Error("\u8BE5\u73AF\u5883\u6CA1\u6709\u8FD9\u4E2A\u6280\u80FD \u2014\u2014 \u8DD1 `hcm skills list` \u770B\u76EE\u5F55\uFF08\u6280\u80FD\u968F\u4EA7\u54C1\u7248\u672C\u8D70\uFF09"));
@@ -5433,8 +5547,8 @@ async function skillsListCommand(keyword, args) {
5433
5547
  const catalog = buildUnifiedCatalog({ source, chironManifest: manifest2, bundled, cliVersion: CLI_VERSION });
5434
5548
  const conflicts = detectIdConflicts(catalog);
5435
5549
  if (conflicts.ids.length > 0) {
5436
- throw new CliError17({
5437
- code: CliErrorCode16.SKILL_ID_CONFLICT,
5550
+ throw new CliError18({
5551
+ code: CliErrorCode17.SKILL_ID_CONFLICT,
5438
5552
  message: conflictMessage(conflicts.ids, endpoint ?? "(\u672A\u77E5\u73AF\u5883)")
5439
5553
  });
5440
5554
  }
@@ -5542,7 +5656,7 @@ async function skillsListCommand(keyword, args) {
5542
5656
  process.exitCode = 0;
5543
5657
  return;
5544
5658
  } catch (e) {
5545
- fail4(e, args);
5659
+ fail5(e, args);
5546
5660
  }
5547
5661
  }
5548
5662
  async function listInstalledSkills(keyword, args) {
@@ -5555,7 +5669,7 @@ async function listInstalledSkills(keyword, args) {
5555
5669
  process.exitCode = 0;
5556
5670
  return;
5557
5671
  }
5558
- process.stdout.write(`${path4.join(layout.baseDir, SKILLS_STATE_FILE)} \u4E0D\u5B58\u5728\u6216\u4E3A\u7A7A \u2014\u2014 \u8FD9\u4E2A\u76EE\u5F55\u4E0B\u8FD8\u6CA1\u7528\u672C CLI \u88C5\u8FC7\u6280\u80FD\u3002
5672
+ process.stdout.write(`${path5.join(layout.baseDir, SKILLS_STATE_FILE)} \u4E0D\u5B58\u5728\u6216\u4E3A\u7A7A \u2014\u2014 \u8FD9\u4E2A\u76EE\u5F55\u4E0B\u8FD8\u6CA1\u7528\u672C CLI \u88C5\u8FC7\u6280\u80FD\u3002
5559
5673
  `);
5560
5674
  process.stdout.write(" \u88C5\u5168\u90E8\uFF1Ahcm skills install --all\n");
5561
5675
  process.exitCode = 0;
@@ -5660,7 +5774,7 @@ async function skillsShowCommand(id, args) {
5660
5774
  process.exitCode = 0;
5661
5775
  return;
5662
5776
  } catch (e) {
5663
- fail4(e, args);
5777
+ fail5(e, args);
5664
5778
  }
5665
5779
  }
5666
5780
  async function skillsInstallCommand(id, args) {
@@ -5677,7 +5791,7 @@ async function skillsInstallCommand(id, args) {
5677
5791
  let manifest2;
5678
5792
  let conflictNote;
5679
5793
  if (args.from) {
5680
- const root = path4.resolve(args.from);
5794
+ const root = path5.resolve(args.from);
5681
5795
  requestedIds = all ? await listLocalSkillIds(root) : [id];
5682
5796
  const seen = /* @__PURE__ */ new Set();
5683
5797
  documents = [];
@@ -5707,8 +5821,8 @@ async function skillsInstallCommand(id, args) {
5707
5821
  const catalog = buildUnifiedCatalog({ source, chironManifest: manifest2, bundled, cliVersion: CLI_VERSION });
5708
5822
  const conflicts = detectIdConflicts(catalog);
5709
5823
  if (conflicts.ids.length > 0) {
5710
- throw new CliError17({
5711
- code: CliErrorCode16.SKILL_ID_CONFLICT,
5824
+ throw new CliError18({
5825
+ code: CliErrorCode17.SKILL_ID_CONFLICT,
5712
5826
  message: conflictMessage(conflicts.ids, endpoint ?? "(\u672A\u77E5\u73AF\u5883)")
5713
5827
  });
5714
5828
  }
@@ -5793,7 +5907,7 @@ async function skillsInstallCommand(id, args) {
5793
5907
  if (fmt === "json" || fmt === "yaml") {
5794
5908
  process.stdout.write(formatObject16({ ...result, all, target_agent: layout.target, agentsFile: layout.agentsFile, agents, agentIndexes, conflictCheck: conflictNote ? { checked: false, note: conflictNote } : { checked: true } }, { format: fmt }) + "\n");
5795
5909
  } else {
5796
- const headline = all ? `\u2705 \u5168\u90E8 ${requestedIds.length} \u4E2A\u6280\u80FD \u2192 ${result.baseDir}` : `\u2705 ${id} \u2192 ${path4.join(result.baseDir, id, "SKILL.md")}`;
5910
+ const headline = all ? `\u2705 \u5168\u90E8 ${requestedIds.length} \u4E2A\u6280\u80FD \u2192 ${result.baseDir}` : `\u2705 ${id} \u2192 ${path5.join(result.baseDir, id, "SKILL.md")}`;
5797
5911
  process.stdout.write(`${headline}
5798
5912
  `);
5799
5913
  if (result.installed.length > 0) {
@@ -5812,11 +5926,11 @@ async function skillsInstallCommand(id, args) {
5812
5926
  `);
5813
5927
  }
5814
5928
  for (const index of agentIndexes) {
5815
- const reader = path4.basename(index.file) === "CLAUDE.md" ? "Claude Code" : "Codex";
5929
+ const reader = path5.basename(index.file) === "CLAUDE.md" ? "Claude Code" : "Codex";
5816
5930
  process.stdout.write(` \u5DF2${index.status === "created" ? "\u521B\u5EFA" : "\u66F4\u65B0"} ${index.file} \u91CC\u7684\u6280\u80FD\u7D22\u5F15\uFF08${reader} \u8BFB\u8FD9\u91CC\uFF09
5817
5931
  `);
5818
5932
  }
5819
- process.stdout.write(` \u6765\u6E90 ${endpoint ?? (args.from ? path4.resolve(args.from) : `@hcmai/cli@${CLI_VERSION}`)}
5933
+ process.stdout.write(` \u6765\u6E90 ${endpoint ?? (args.from ? path5.resolve(args.from) : `@hcmai/cli@${CLI_VERSION}`)}
5820
5934
  `);
5821
5935
  if (conflictNote) process.stdout.write(` \u26A0\uFE0F ${conflictNote}
5822
5936
  `);
@@ -5825,7 +5939,7 @@ async function skillsInstallCommand(id, args) {
5825
5939
  process.exitCode = 0;
5826
5940
  return;
5827
5941
  } catch (e) {
5828
- fail4(e, args);
5942
+ fail5(e, args);
5829
5943
  }
5830
5944
  }
5831
5945
  var FETCH_CONCURRENCY = 6;
@@ -5852,7 +5966,7 @@ async function listLocalSkillIds(root) {
5852
5966
  const ids = [];
5853
5967
  for (const entry of entries) {
5854
5968
  if (!entry.isDirectory()) continue;
5855
- if (await exists(path4.join(root, entry.name, "SKILL.md"))) ids.push(entry.name);
5969
+ if (await exists(path5.join(root, entry.name, "SKILL.md"))) ids.push(entry.name);
5856
5970
  }
5857
5971
  if (ids.length === 0) throw invalid(`\u672C\u5730\u76EE\u5F55\u91CC\u6CA1\u6709\u4EFB\u4F55 <id>/SKILL.md\uFF1A${root}`);
5858
5972
  return ids.sort();
@@ -5882,17 +5996,17 @@ async function syncAgentIndexes(layout, manifest2) {
5882
5996
  const files = [layout.agentsFile, ...layout.companionAgentFiles ?? []];
5883
5997
  const results = [];
5884
5998
  for (const file of files) {
5885
- const agentsDir = path4.dirname(file);
5999
+ const agentsDir = path5.dirname(file);
5886
6000
  const entries = Object.keys(state.skills).sort().map((id) => {
5887
6001
  const known = catalog.get(id);
5888
- const absolute = path4.join(layout.baseDir, id, "SKILL.md");
5889
- let relative2 = path4.relative(agentsDir, absolute);
6002
+ const absolute = path5.join(layout.baseDir, id, "SKILL.md");
6003
+ let relative2 = path5.relative(agentsDir, absolute);
5890
6004
  if (!relative2.startsWith(".")) relative2 = `./${relative2}`;
5891
6005
  return {
5892
6006
  id,
5893
6007
  title: known?.title ?? id,
5894
6008
  description: known?.description ?? "",
5895
- relativePath: relative2.split(path4.sep).join("/")
6009
+ relativePath: relative2.split(path5.sep).join("/")
5896
6010
  };
5897
6011
  });
5898
6012
  results.push({ file, status: await upsertAgentsBlock(file, renderAgentsBlock(entries)) });
@@ -5912,13 +6026,13 @@ async function resolveLocalSkillDocuments(sourceRoot, targetId) {
5912
6026
  throw invalid(`\u6280\u80FD\u4F9D\u8D56\u5B58\u5728\u73AF: ${[...pathStack.slice(Math.max(0, start)), id].join(" -> ")}`);
5913
6027
  }
5914
6028
  assertSafeSkillId(id);
5915
- const local = path4.join(sourceRoot, id, "SKILL.md");
6029
+ const local = path5.join(sourceRoot, id, "SKILL.md");
5916
6030
  let markdown;
5917
6031
  try {
5918
6032
  markdown = await fsp2.readFile(local, "utf8");
5919
6033
  } catch (cause) {
5920
6034
  if (cause?.code === "ENOENT") {
5921
- throw invalid(requiredBy ? `\u672C\u5730\u6280\u80FD ${requiredBy} \u4F9D\u8D56\u4E0D\u5B58\u5728: ${id}\uFF08${local}\uFF09` : `\u672C\u5730\u76EE\u5F55\u91CC\u6CA1\u6709 ${id}/SKILL.md\uFF1A${path4.join(sourceRoot, id)}`);
6035
+ throw invalid(requiredBy ? `\u672C\u5730\u6280\u80FD ${requiredBy} \u4F9D\u8D56\u4E0D\u5B58\u5728: ${id}\uFF08${local}\uFF09` : `\u672C\u5730\u76EE\u5F55\u91CC\u6CA1\u6709 ${id}/SKILL.md\uFF1A${path5.join(sourceRoot, id)}`);
5922
6036
  }
5923
6037
  throw cause;
5924
6038
  }
@@ -5930,7 +6044,7 @@ async function resolveLocalSkillDocuments(sourceRoot, targetId) {
5930
6044
  markdown,
5931
6045
  source: local,
5932
6046
  sourceKind: "local",
5933
- references: await readLocalReferences(path4.join(sourceRoot, id))
6047
+ references: await readLocalReferences(path5.join(sourceRoot, id))
5934
6048
  };
5935
6049
  for (const required of parseSkillRequirements2(markdown, id)) {
5936
6050
  await visit(required, id);
@@ -5944,7 +6058,7 @@ async function resolveLocalSkillDocuments(sourceRoot, targetId) {
5944
6058
  }
5945
6059
  async function readSkillsState(baseDir) {
5946
6060
  try {
5947
- const raw = await fsp2.readFile(path4.join(baseDir, SKILLS_STATE_FILE), "utf8");
6061
+ const raw = await fsp2.readFile(path5.join(baseDir, SKILLS_STATE_FILE), "utf8");
5948
6062
  const parsed = JSON.parse(raw);
5949
6063
  if (!parsed || typeof parsed !== "object" || !parsed.skills) return void 0;
5950
6064
  return migrateSkillsState(parsed);
@@ -5954,7 +6068,7 @@ async function readSkillsState(baseDir) {
5954
6068
  }
5955
6069
  async function writeSkillsState(baseDir, state) {
5956
6070
  await fsp2.mkdir(baseDir, { recursive: true });
5957
- const file = path4.join(baseDir, SKILLS_STATE_FILE);
6071
+ const file = path5.join(baseDir, SKILLS_STATE_FILE);
5958
6072
  const temp = `${file}.${process.pid}.tmp`;
5959
6073
  await fsp2.writeFile(temp, JSON.stringify(state, null, 2) + "\n", "utf8");
5960
6074
  await fsp2.rename(temp, file);
@@ -5983,7 +6097,7 @@ async function upsertAgentsBlock(agentsFile, block) {
5983
6097
  existing = await fsp2.readFile(agentsFile, "utf8");
5984
6098
  } catch (cause) {
5985
6099
  if (cause?.code !== "ENOENT") throw cause;
5986
- await fsp2.mkdir(path4.dirname(agentsFile), { recursive: true });
6100
+ await fsp2.mkdir(path5.dirname(agentsFile), { recursive: true });
5987
6101
  await fsp2.writeFile(agentsFile, block + "\n", "utf8");
5988
6102
  return "created";
5989
6103
  }
@@ -6009,7 +6123,7 @@ async function installSkillDocuments(documents, requestedIds, baseDir, force, me
6009
6123
  if (!document.markdown.trim()) throw invalid(`\u6280\u80FD ${document.id} \u5185\u5BB9\u4E3A\u7A7A`);
6010
6124
  return {
6011
6125
  ...document,
6012
- target: path4.join(baseDir, document.id, "SKILL.md"),
6126
+ target: path5.join(baseDir, document.id, "SKILL.md"),
6013
6127
  bytes: Buffer.byteLength(document.markdown)
6014
6128
  };
6015
6129
  });
@@ -6060,7 +6174,7 @@ async function sameOnDisk(baseDir, candidate) {
6060
6174
  return true;
6061
6175
  }
6062
6176
  async function readLocalReferences(skillDir) {
6063
- const root = path4.join(skillDir, "references");
6177
+ const root = path5.join(skillDir, "references");
6064
6178
  const out = [];
6065
6179
  const walk = async (dir, prefix) => {
6066
6180
  let items;
@@ -6073,12 +6187,12 @@ async function readLocalReferences(skillDir) {
6073
6187
  for (const item of items.sort((a, b) => a.name.localeCompare(b.name))) {
6074
6188
  const relative2 = prefix ? `${prefix}/${item.name}` : item.name;
6075
6189
  if (item.isDirectory()) {
6076
- await walk(path4.join(dir, item.name), relative2);
6190
+ await walk(path5.join(dir, item.name), relative2);
6077
6191
  continue;
6078
6192
  }
6079
6193
  if (!item.isFile()) continue;
6080
6194
  assertSafeReferencePath2(relative2);
6081
- out.push({ path: relative2, content: await fsp2.readFile(path4.join(dir, item.name), "utf8") });
6195
+ out.push({ path: relative2, content: await fsp2.readFile(path5.join(dir, item.name), "utf8") });
6082
6196
  }
6083
6197
  };
6084
6198
  await walk(root, "");
@@ -6109,15 +6223,15 @@ async function writeSkillDocuments(documents, baseDir, removals = []) {
6109
6223
  const removed = [];
6110
6224
  try {
6111
6225
  for (const document of documents) {
6112
- const target = path4.join(baseDir, document.id, "SKILL.md");
6113
- await fsp2.mkdir(path4.dirname(target), { recursive: true });
6114
- const temp = path4.join(path4.dirname(target), `.SKILL.md.${process.pid}.${Date.now()}.tmp`);
6226
+ const target = path5.join(baseDir, document.id, "SKILL.md");
6227
+ await fsp2.mkdir(path5.dirname(target), { recursive: true });
6228
+ const temp = path5.join(path5.dirname(target), `.SKILL.md.${process.pid}.${Date.now()}.tmp`);
6115
6229
  await fsp2.writeFile(temp, document.markdown, "utf8");
6116
6230
  staged.push({ temp, target });
6117
6231
  for (const reference of document.references ?? []) {
6118
6232
  assertSafeReferencePath2(reference.path);
6119
- const referenceTarget = path4.join(baseDir, document.id, "references", reference.path);
6120
- await fsp2.mkdir(path4.dirname(referenceTarget), { recursive: true });
6233
+ const referenceTarget = path5.join(baseDir, document.id, "references", reference.path);
6234
+ await fsp2.mkdir(path5.dirname(referenceTarget), { recursive: true });
6121
6235
  const referenceTemp = `${referenceTarget}.${process.pid}.${Date.now()}.tmp`;
6122
6236
  await fsp2.writeFile(referenceTemp, reference.content, "utf8");
6123
6237
  staged.push({ temp: referenceTemp, target: referenceTarget });
@@ -6125,7 +6239,7 @@ async function writeSkillDocuments(documents, baseDir, removals = []) {
6125
6239
  }
6126
6240
  for (const stale of removals) {
6127
6241
  assertSafeReferencePath2(stale.path);
6128
- const original = path4.join(baseDir, stale.id, "references", stale.path);
6242
+ const original = path5.join(baseDir, stale.id, "references", stale.path);
6129
6243
  const parked = `${original}.${process.pid}.${Date.now()}.removed`;
6130
6244
  await fsp2.rename(original, parked);
6131
6245
  removed.push({ parked, original });
@@ -6171,11 +6285,11 @@ async function recordInstalled(baseDir, documents, meta2) {
6171
6285
  return state;
6172
6286
  }
6173
6287
  function invalid(message) {
6174
- return new CliError17({ code: CliErrorCode16.INVALID_ARGUMENT, message });
6288
+ return new CliError18({ code: CliErrorCode17.INVALID_ARGUMENT, message });
6175
6289
  }
6176
6290
  async function readInstalled(baseDir, id) {
6177
6291
  try {
6178
- return await fsp2.readFile(path4.join(baseDir, id, "SKILL.md"), "utf8");
6292
+ return await fsp2.readFile(path5.join(baseDir, id, "SKILL.md"), "utf8");
6179
6293
  } catch (cause) {
6180
6294
  if (cause?.code === "ENOENT") return void 0;
6181
6295
  throw cause;
@@ -6183,7 +6297,7 @@ async function readInstalled(baseDir, id) {
6183
6297
  }
6184
6298
  async function readInstalledReference(baseDir, id, relative2) {
6185
6299
  try {
6186
- return await fsp2.readFile(path4.join(baseDir, id, "references", relative2), "utf8");
6300
+ return await fsp2.readFile(path5.join(baseDir, id, "references", relative2), "utf8");
6187
6301
  } catch (cause) {
6188
6302
  if (cause?.code === "ENOENT") return void 0;
6189
6303
  throw cause;
@@ -6315,9 +6429,9 @@ async function skillsUpdateCommand(args) {
6315
6429
  const layout = await resolveInstallLayout(args);
6316
6430
  const state = await readSkillsState(layout.baseDir);
6317
6431
  if (!state || Object.keys(state.skills).length === 0) {
6318
- throw new CliError17({
6319
- code: CliErrorCode16.INVALID_ARGUMENT,
6320
- message: `${path4.join(layout.baseDir, SKILLS_STATE_FILE)} \u4E0D\u5B58\u5728\u6216\u4E3A\u7A7A \u2014\u2014 \u8FD9\u4E2A\u76EE\u5F55\u4E0B\u8FD8\u6CA1\u6709\u7528\u672C CLI \u88C5\u8FC7\u6280\u80FD\u3002\u5148 \`hcm skills install <id>\`\uFF1B\u5982\u679C\u6280\u80FD\u662F\u624B\u5DE5\u62F7\u8FDB\u6765\u7684\uFF0C\u91CD\u88C5\u4E00\u6B21\u5373\u53EF\u63A5\u7BA1\u5347\u7EA7\u3002`
6432
+ throw new CliError18({
6433
+ code: CliErrorCode17.INVALID_ARGUMENT,
6434
+ message: `${path5.join(layout.baseDir, SKILLS_STATE_FILE)} \u4E0D\u5B58\u5728\u6216\u4E3A\u7A7A \u2014\u2014 \u8FD9\u4E2A\u76EE\u5F55\u4E0B\u8FD8\u6CA1\u6709\u7528\u672C CLI \u88C5\u8FC7\u6280\u80FD\u3002\u5148 \`hcm skills install <id>\`\uFF1B\u5982\u679C\u6280\u80FD\u662F\u624B\u5DE5\u62F7\u8FDB\u6765\u7684\uFF0C\u91CD\u88C5\u4E00\u6B21\u5373\u53EF\u63A5\u7BA1\u5347\u7EA7\u3002`
6321
6435
  });
6322
6436
  }
6323
6437
  const source = parseSourceFilter(args.source);
@@ -6436,7 +6550,7 @@ async function skillsUpdateCommand(args) {
6436
6550
  process.exitCode = 0;
6437
6551
  return;
6438
6552
  } catch (e) {
6439
- fail4(e, args);
6553
+ fail5(e, args);
6440
6554
  }
6441
6555
  }
6442
6556
 
@@ -6449,8 +6563,8 @@ import {
6449
6563
  loadEnv as loadEnv7,
6450
6564
  loadGlobalConfig as loadGlobalConfig7,
6451
6565
  resolveActiveEnv as resolveActiveEnv4,
6452
- CliError as CliError18,
6453
- CliErrorCode as CliErrorCode17
6566
+ CliError as CliError19,
6567
+ CliErrorCode as CliErrorCode18
6454
6568
  } from "@hcmai/sdk";
6455
6569
  init_exit();
6456
6570
  async function resolveBootstrapKey(args, stdinTaken) {
@@ -6458,8 +6572,8 @@ async function resolveBootstrapKey(args, stdinTaken) {
6458
6572
  if (fromEnv) return fromEnv;
6459
6573
  if (args.bootstrapKeyStdin) {
6460
6574
  if (stdinTaken) {
6461
- throw new CliError18({
6462
- code: CliErrorCode17.INVALID_ARGUMENT,
6575
+ throw new CliError19({
6576
+ code: CliErrorCode18.INVALID_ARGUMENT,
6463
6577
  message: "--bootstrap-key-stdin \u4E0E --admin-password-stdin \u4E0D\u80FD\u540C\u65F6\u7528\uFF08stdin \u53EA\u6709\u4E00\u8DEF\uFF09\uFF1B\u628A\u5176\u4E2D\u4E00\u4E2A\u6539\u8D70 HCM_BOOTSTRAP_KEY \u73AF\u5883\u53D8\u91CF\u6216\u4EA4\u4E92\u8F93\u5165"
6464
6578
  });
6465
6579
  }
@@ -6487,20 +6601,20 @@ async function resolveEndpoint2(args) {
6487
6601
  if (args.endpoint) return args.endpoint;
6488
6602
  const g = await loadGlobalConfig7();
6489
6603
  const envName = resolveActiveEnv4({ envFlag: args.env }, process.env, g);
6490
- const env2 = await loadEnv7(envName).catch(() => null);
6491
- if (!env2?.endpoint) {
6492
- throw new CliError18({
6493
- code: CliErrorCode17.MISSING_FLAG,
6604
+ const env3 = await loadEnv7(envName).catch(() => null);
6605
+ if (!env3?.endpoint) {
6606
+ throw new CliError19({
6607
+ code: CliErrorCode18.MISSING_FLAG,
6494
6608
  message: "\u672A\u89E3\u6790\u5230 endpoint \u2014\u2014 \u4F20 --endpoint <url>\uFF0C\u6216\u5148 `hcm env add <name> --endpoint <url>`"
6495
6609
  });
6496
6610
  }
6497
- return env2.endpoint;
6611
+ return env3.endpoint;
6498
6612
  }
6499
6613
  async function tenantBootstrapCommand(args) {
6500
6614
  try {
6501
6615
  if (!args.tenantId || !args.adminUsername) {
6502
- throw new CliError18({
6503
- code: CliErrorCode17.MISSING_FLAG,
6616
+ throw new CliError19({
6617
+ code: CliErrorCode18.MISSING_FLAG,
6504
6618
  message: "--tenant-id \u4E0E --admin-username \u5FC5\u586B"
6505
6619
  });
6506
6620
  }
@@ -6568,15 +6682,15 @@ import {
6568
6682
  formatMetaIssues,
6569
6683
  explainJacksonError,
6570
6684
  META_SCHEMA_SOURCE_COMMIT,
6571
- CliError as CliError19,
6572
- CliErrorCode as CliErrorCode18
6685
+ CliError as CliError20,
6686
+ CliErrorCode as CliErrorCode19
6573
6687
  } from "@hcmai/sdk";
6574
6688
  init_exit();
6575
6689
  init_auth_guard();
6576
6690
  async function client2(args) {
6577
6691
  return HcmClient18.fromAuthContext(await getActiveAuthContextFromCli(args));
6578
6692
  }
6579
- function fail5(e, args) {
6693
+ function fail6(e, args) {
6580
6694
  const err = e;
6581
6695
  if (err?.response?.status === 403) {
6582
6696
  exitWithError(
@@ -6603,7 +6717,7 @@ async function metaListCommand(args) {
6603
6717
  process.exitCode = 0;
6604
6718
  return;
6605
6719
  } catch (e) {
6606
- fail5(e, args);
6720
+ fail6(e, args);
6607
6721
  }
6608
6722
  }
6609
6723
  async function metaGetCommand(path19, args) {
@@ -6614,7 +6728,7 @@ async function metaGetCommand(path19, args) {
6614
6728
  process.exitCode = 0;
6615
6729
  return;
6616
6730
  } catch (e) {
6617
- fail5(e, args);
6731
+ fail6(e, args);
6618
6732
  }
6619
6733
  }
6620
6734
  var PROBEABLE_META_TYPES = /* @__PURE__ */ new Set(["model", "list", "info", "view", "filter", "page", "wiz", "impexp"]);
@@ -6687,8 +6801,8 @@ async function verifyAfterWrite(c, path19) {
6687
6801
  async function metaSetCommand(path19, args) {
6688
6802
  try {
6689
6803
  if (!args.file) {
6690
- throw new CliError19({
6691
- code: CliErrorCode18.MISSING_FLAG,
6804
+ throw new CliError20({
6805
+ code: CliErrorCode19.MISSING_FLAG,
6692
6806
  message: "--file <path> \u5FC5\u586B\uFF08\u4ECE\u6587\u4EF6\u8BFB\u53D6 meta \u539F\u6587\uFF1B\u7528 - \u8868\u793A stdin\uFF09"
6693
6807
  });
6694
6808
  }
@@ -6807,7 +6921,7 @@ ${content}
6807
6921
  return;
6808
6922
  } catch (e) {
6809
6923
  if (e.code === "ENOENT") exitWithError(new Error(`\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${args.file}`));
6810
- fail5(e, args);
6924
+ fail6(e, args);
6811
6925
  }
6812
6926
  }
6813
6927
  async function metaDeleteCommand(path19, args) {
@@ -6828,14 +6942,14 @@ async function metaDeleteCommand(path19, args) {
6828
6942
  process.exitCode = 0;
6829
6943
  return;
6830
6944
  } catch (e) {
6831
- fail5(e, args);
6945
+ fail6(e, args);
6832
6946
  }
6833
6947
  }
6834
6948
  async function metaValidateCommand(path19, args) {
6835
6949
  try {
6836
6950
  if (!args.file) {
6837
- throw new CliError19({
6838
- code: CliErrorCode18.MISSING_FLAG,
6951
+ throw new CliError20({
6952
+ code: CliErrorCode19.MISSING_FLAG,
6839
6953
  message: "--file <path> \u5FC5\u586B\uFF08\u8981\u9A8C\u7684\u90A3\u4EFD\u539F\u6587\uFF1B\u7528 - \u8868\u793A stdin\uFF09"
6840
6954
  });
6841
6955
  }
@@ -6875,7 +6989,7 @@ async function metaValidateCommand(path19, args) {
6875
6989
  return;
6876
6990
  } catch (e) {
6877
6991
  if (e.code === "ENOENT") exitWithError(new Error(`\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${args.file}`));
6878
- fail5(e, args);
6992
+ fail6(e, args);
6879
6993
  }
6880
6994
  }
6881
6995
 
@@ -6883,8 +6997,8 @@ async function metaValidateCommand(path19, args) {
6883
6997
  init_exit();
6884
6998
  init_auth_guard();
6885
6999
  import * as crypto from "crypto";
6886
- import * as fs5 from "fs/promises";
6887
- import * as path5 from "path";
7000
+ import * as fs6 from "fs/promises";
7001
+ import * as path6 from "path";
6888
7002
  import {
6889
7003
  buildMiniPreviewTargets,
6890
7004
  buildMiniVerifyAgentReport,
@@ -7024,7 +7138,7 @@ async function workspaceBindCommand(workspaceKey, args) {
7024
7138
  tenantId: args.tenant ?? client3?.tenantId,
7025
7139
  endpoint: args.endpoint ?? client3?.endpoint
7026
7140
  });
7027
- await fs5.mkdir(rootDir, { recursive: true });
7141
+ await fs6.mkdir(rootDir, { recursive: true });
7028
7142
  await writeWorkspaceContext(rootDir, context);
7029
7143
  writeWorkspaceBindResult(context, rootDir, args.output ?? "table");
7030
7144
  process.exitCode = 0;
@@ -7061,7 +7175,7 @@ async function workspaceCreateCommand(workspaceKey, args) {
7061
7175
  tenantId: client3.tenantId,
7062
7176
  endpoint: client3.endpoint
7063
7177
  });
7064
- await fs5.mkdir(rootDir, { recursive: true });
7178
+ await fs6.mkdir(rootDir, { recursive: true });
7065
7179
  await writeWorkspaceContext(rootDir, context);
7066
7180
  writeWorkspaceCreateResult(
7067
7181
  {
@@ -7099,7 +7213,7 @@ async function workspacePullCommand(args) {
7099
7213
  tenantId: client3.tenantId ?? existing?.tenantId,
7100
7214
  endpoint: client3.endpoint ?? existing?.endpoint
7101
7215
  });
7102
- await fs5.mkdir(rootDir, { recursive: true });
7216
+ await fs6.mkdir(rootDir, { recursive: true });
7103
7217
  await writeWorkspaceContext(rootDir, context);
7104
7218
  const files = await listWorkspaceFiles(client3.raw(), workspaceKey, { pageSize: 5e3 });
7105
7219
  const miniApps = detectRemoteMiniApps(files.data);
@@ -7109,7 +7223,7 @@ async function workspacePullCommand(args) {
7109
7223
  http: client3.raw(),
7110
7224
  appCode,
7111
7225
  workspaceKey,
7112
- targetDir: path5.join(rootDir, MINI_APPS_DIR, appCode),
7226
+ targetDir: path6.join(rootDir, MINI_APPS_DIR, appCode),
7113
7227
  tenantId: client3.tenantId,
7114
7228
  endpoint: client3.endpoint,
7115
7229
  profile: args.profile ?? client3.profile,
@@ -7124,7 +7238,7 @@ async function workspacePullCommand(args) {
7124
7238
  const rawRemoteByLocalPath = /* @__PURE__ */ new Map();
7125
7239
  for (const file of rawFiles) {
7126
7240
  const content = await loadWorkspaceFileContent(client3.raw(), file.id);
7127
- const target = path5.join(rootDir, content.relativePath);
7241
+ const target = path6.join(rootDir, content.relativePath);
7128
7242
  await writeTextFile(target, content.content, !!args.force);
7129
7243
  pulledRawFiles.push(content.relativePath);
7130
7244
  rawRemoteByLocalPath.set(content.relativePath, file);
@@ -7175,7 +7289,7 @@ async function workspaceAddMiniCommand(appCode, args) {
7175
7289
  const result = await initMiniAppProject({
7176
7290
  appCode,
7177
7291
  workspaceKey: context.workspaceKey,
7178
- targetDir: path5.join(rootDir, MINI_APPS_DIR, appCode),
7292
+ targetDir: path6.join(rootDir, MINI_APPS_DIR, appCode),
7179
7293
  name: args.name,
7180
7294
  defaultSurface: parseSurface(args.surface),
7181
7295
  templateKind,
@@ -7201,10 +7315,10 @@ async function workspaceRmCommand(relativePath, args) {
7201
7315
  const rootDir = resolveRootDir(args.dir);
7202
7316
  const context = await requireWorkspaceContext(rootDir);
7203
7317
  const normalized = normalizeWorkspaceRmPath(relativePath);
7204
- const absolutePath = path5.join(rootDir, ...normalized.split("/"));
7318
+ const absolutePath = path6.join(rootDir, ...normalized.split("/"));
7205
7319
  let stat;
7206
7320
  try {
7207
- stat = await fs5.lstat(absolutePath);
7321
+ stat = await fs6.lstat(absolutePath);
7208
7322
  } catch (e) {
7209
7323
  if (e.code !== "ENOENT") throw e;
7210
7324
  stat = null;
@@ -7260,7 +7374,7 @@ async function workspaceRmCommand(relativePath, args) {
7260
7374
  }
7261
7375
  throw new Error(`workspace file not found locally or in the workspace: ${normalized}`);
7262
7376
  }
7263
- await fs5.unlink(absolutePath);
7377
+ await fs6.unlink(absolutePath);
7264
7378
  const result = {
7265
7379
  workspaceKey: context.workspaceKey,
7266
7380
  file: normalized,
@@ -7534,7 +7648,7 @@ function removedMiniCommand() {
7534
7648
  );
7535
7649
  }
7536
7650
  function resolveRootDir(dir) {
7537
- return path5.resolve(dir ?? ".");
7651
+ return path6.resolve(dir ?? ".");
7538
7652
  }
7539
7653
  function buildWorkspaceContext(args) {
7540
7654
  return {
@@ -7550,7 +7664,7 @@ function buildWorkspaceContext(args) {
7550
7664
  async function readWorkspaceContext(rootDir) {
7551
7665
  try {
7552
7666
  const parsed = JSON.parse(
7553
- await fs5.readFile(path5.join(rootDir, WORKSPACE_CONTEXT_FILE), "utf-8")
7667
+ await fs6.readFile(path6.join(rootDir, WORKSPACE_CONTEXT_FILE), "utf-8")
7554
7668
  );
7555
7669
  if (parsed.kind !== WORKSPACE_CONTEXT_KIND || parsed.version !== WORKSPACE_CONTEXT_VERSION) {
7556
7670
  throw new Error(`${WORKSPACE_CONTEXT_FILE} is not an HCM workspace context`);
@@ -7579,26 +7693,26 @@ async function requireWorkspaceContext(rootDir) {
7579
7693
  return context;
7580
7694
  }
7581
7695
  async function writeWorkspaceContext(rootDir, context) {
7582
- await fs5.writeFile(
7583
- path5.join(rootDir, WORKSPACE_CONTEXT_FILE),
7696
+ await fs6.writeFile(
7697
+ path6.join(rootDir, WORKSPACE_CONTEXT_FILE),
7584
7698
  JSON.stringify(context, null, 2) + "\n"
7585
7699
  );
7586
7700
  }
7587
7701
  async function writeTextFile(file, content, force) {
7588
7702
  try {
7589
- await fs5.access(file);
7703
+ await fs6.access(file);
7590
7704
  if (!force) throw new Error(`${file} already exists; use --force to overwrite`);
7591
7705
  } catch (e) {
7592
7706
  if (e.code !== "ENOENT") throw e;
7593
7707
  }
7594
- await fs5.mkdir(path5.dirname(file), { recursive: true });
7595
- await fs5.writeFile(file, content);
7708
+ await fs6.mkdir(path6.dirname(file), { recursive: true });
7709
+ await fs6.writeFile(file, content);
7596
7710
  }
7597
7711
  async function readWorkspaceRawManifest(rootDir, context) {
7598
7712
  try {
7599
7713
  const parsed = JSON.parse(
7600
- await fs5.readFile(
7601
- path5.join(rootDir, WORKSPACE_STATE_DIR, WORKSPACE_PULL_MANIFEST_FILE),
7714
+ await fs6.readFile(
7715
+ path6.join(rootDir, WORKSPACE_STATE_DIR, WORKSPACE_PULL_MANIFEST_FILE),
7602
7716
  "utf-8"
7603
7717
  )
7604
7718
  );
@@ -7620,8 +7734,8 @@ async function readWorkspaceRawManifest(rootDir, context) {
7620
7734
  }
7621
7735
  }
7622
7736
  async function writeWorkspaceRawState(rootDir, context, files, remoteByLocalPath) {
7623
- const stateDir = path5.join(rootDir, WORKSPACE_STATE_DIR);
7624
- await fs5.mkdir(stateDir, { recursive: true });
7737
+ const stateDir = path6.join(rootDir, WORKSPACE_STATE_DIR);
7738
+ await fs6.mkdir(stateDir, { recursive: true });
7625
7739
  const snapshots = files.map(
7626
7740
  (file) => ({
7627
7741
  localPath: file.localPath,
@@ -7632,8 +7746,8 @@ async function writeWorkspaceRawState(rootDir, context, files, remoteByLocalPath
7632
7746
  lastModified: remoteByLocalPath.get(file.localPath)?.lastModified
7633
7747
  })
7634
7748
  );
7635
- await fs5.writeFile(
7636
- path5.join(stateDir, WORKSPACE_PULL_MANIFEST_FILE),
7749
+ await fs6.writeFile(
7750
+ path6.join(stateDir, WORKSPACE_PULL_MANIFEST_FILE),
7637
7751
  JSON.stringify(
7638
7752
  {
7639
7753
  version: WORKSPACE_CONTEXT_VERSION,
@@ -7649,10 +7763,10 @@ async function writeWorkspaceRawState(rootDir, context, files, remoteByLocalPath
7649
7763
  );
7650
7764
  }
7651
7765
  async function writeWorkspaceRawManifest(rootDir, manifest2) {
7652
- const stateDir = path5.join(rootDir, WORKSPACE_STATE_DIR);
7653
- await fs5.mkdir(stateDir, { recursive: true });
7654
- await fs5.writeFile(
7655
- path5.join(stateDir, WORKSPACE_PULL_MANIFEST_FILE),
7766
+ const stateDir = path6.join(rootDir, WORKSPACE_STATE_DIR);
7767
+ await fs6.mkdir(stateDir, { recursive: true });
7768
+ await fs6.writeFile(
7769
+ path6.join(stateDir, WORKSPACE_PULL_MANIFEST_FILE),
7656
7770
  JSON.stringify(manifest2, null, 2) + "\n",
7657
7771
  "utf8"
7658
7772
  );
@@ -7664,10 +7778,10 @@ async function readWorkspaceRawLocalFiles(rootDir) {
7664
7778
  return files;
7665
7779
  }
7666
7780
  async function walkWorkspaceRawFiles(rootDir, relativeDir, files) {
7667
- const absoluteDir = path5.join(rootDir, relativeDir);
7781
+ const absoluteDir = path6.join(rootDir, relativeDir);
7668
7782
  let entries;
7669
7783
  try {
7670
- entries = await fs5.readdir(absoluteDir, { withFileTypes: true });
7784
+ entries = await fs6.readdir(absoluteDir, { withFileTypes: true });
7671
7785
  } catch (e) {
7672
7786
  if (e.code === "ENOENT") return;
7673
7787
  throw e;
@@ -7675,14 +7789,14 @@ async function walkWorkspaceRawFiles(rootDir, relativeDir, files) {
7675
7789
  for (const entry of entries) {
7676
7790
  if (entry.isDirectory() && RAW_WORKSPACE_EXCLUDED_DIRS.has(entry.name)) continue;
7677
7791
  if (entry.isFile() && RAW_WORKSPACE_EXCLUDED_FILES.has(entry.name)) continue;
7678
- const localPath = normalizeRelativePath(path5.posix.join(toPosix(relativeDir), entry.name));
7679
- const absolutePath = path5.join(rootDir, localPath);
7792
+ const localPath = normalizeRelativePath(path6.posix.join(toPosix(relativeDir), entry.name));
7793
+ const absolutePath = path6.join(rootDir, localPath);
7680
7794
  if (entry.isDirectory()) {
7681
7795
  await walkWorkspaceRawFiles(rootDir, localPath, files);
7682
7796
  continue;
7683
7797
  }
7684
7798
  if (!entry.isFile()) continue;
7685
- const content = await fs5.readFile(absolutePath, "utf-8");
7799
+ const content = await fs6.readFile(absolutePath, "utf-8");
7686
7800
  files.push({
7687
7801
  localPath,
7688
7802
  absolutePath,
@@ -7864,15 +7978,15 @@ function workspaceRawConflict(entry, reason) {
7864
7978
  };
7865
7979
  }
7866
7980
  async function discoverMiniApps(rootDir) {
7867
- const appsRoot = path5.join(rootDir, MINI_APPS_DIR);
7981
+ const appsRoot = path6.join(rootDir, MINI_APPS_DIR);
7868
7982
  let entries;
7869
7983
  try {
7870
- entries = await fs5.readdir(appsRoot, { withFileTypes: true });
7984
+ entries = await fs6.readdir(appsRoot, { withFileTypes: true });
7871
7985
  } catch (e) {
7872
7986
  if (e.code === "ENOENT") return [];
7873
7987
  throw e;
7874
7988
  }
7875
- return entries.filter((entry) => entry.isDirectory()).map((entry) => ({ appCode: entry.name, dir: path5.join(appsRoot, entry.name) })).sort((a, b) => a.appCode.localeCompare(b.appCode));
7989
+ return entries.filter((entry) => entry.isDirectory()).map((entry) => ({ appCode: entry.name, dir: path6.join(appsRoot, entry.name) })).sort((a, b) => a.appCode.localeCompare(b.appCode));
7876
7990
  }
7877
7991
  function detectRemoteMiniApps(files) {
7878
7992
  const appCodes = /* @__PURE__ */ new Set();
@@ -8015,7 +8129,7 @@ function normalizeWorkspaceKey(value) {
8015
8129
  return key2;
8016
8130
  }
8017
8131
  function normalizeWorkspaceRmPath(value) {
8018
- if (path5.isAbsolute(value) || /^[A-Za-z]:[\\/]/.test(value)) {
8132
+ if (path6.isAbsolute(value) || /^[A-Za-z]:[\\/]/.test(value)) {
8019
8133
  throw new Error("workspace rm path must be relative to the bound workspace");
8020
8134
  }
8021
8135
  const normalized = normalizeRelativePath(value);
@@ -8037,7 +8151,7 @@ function normalizeRelativePath(value) {
8037
8151
  return normalized;
8038
8152
  }
8039
8153
  function toPosix(value) {
8040
- return value.split(path5.sep).join("/");
8154
+ return value.split(path6.sep).join("/");
8041
8155
  }
8042
8156
  function sha2563(content) {
8043
8157
  return crypto.createHash("sha256").update(content, "utf-8").digest("hex");
@@ -8428,8 +8542,8 @@ init_exit();
8428
8542
  import axios4 from "axios";
8429
8543
  import {
8430
8544
  AUTH_INFO_PATH,
8431
- CliError as CliError20,
8432
- CliErrorCode as CliErrorCode19,
8545
+ CliError as CliError21,
8546
+ CliErrorCode as CliErrorCode20,
8433
8547
  formatObject as formatObject20,
8434
8548
  fromAxiosError as fromAxiosError20,
8435
8549
  loadEnv as loadEnv8,
@@ -8450,23 +8564,23 @@ var fetchAuthInfo = async (endpoint, accessToken) => {
8450
8564
  };
8451
8565
  async function inspectIdentity(name, fetcher = fetchAuthInfo) {
8452
8566
  const meta2 = await loadIdentity4(name);
8453
- const env2 = await loadEnv8(meta2.env);
8567
+ const env3 = await loadEnv8(meta2.env);
8454
8568
  const accessToken = await TokenStore3.forIdentity(name).getStoredAccessToken();
8455
8569
  if (!accessToken) {
8456
- throw new CliError20({
8457
- code: CliErrorCode19.AUTH_FAILED,
8570
+ throw new CliError21({
8571
+ code: CliErrorCode20.AUTH_FAILED,
8458
8572
  message: `identity '${name}' \u6CA1\u6709\u53EF\u8BFB\u53D6\u7684\u6301\u4E45\u5316 token`,
8459
8573
  context: { nextStep: `\u91CD\u65B0\u767B\u5F55\u8BE5\u8EAB\u4EFD\uFF1Ahcm login --env ${meta2.env} --name ${name}` }
8460
8574
  });
8461
8575
  }
8462
- const raw = await fetcher(env2.endpoint, accessToken);
8576
+ const raw = await fetcher(env3.endpoint, accessToken);
8463
8577
  const principal = toPrincipal(raw);
8464
8578
  const body = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
8465
8579
  const serverScopes = Array.isArray(body.scopes) ? body.scopes.map(String) : void 0;
8466
8580
  return {
8467
8581
  identity: name,
8468
8582
  env: meta2.env,
8469
- endpoint: env2.endpoint,
8583
+ endpoint: env3.endpoint,
8470
8584
  scheme: meta2.scheme,
8471
8585
  userId: principal?.userId ?? null,
8472
8586
  username: principal?.username ?? null,
@@ -8497,8 +8611,8 @@ async function identityList(args) {
8497
8611
  const lines = [];
8498
8612
  for (const n of names) {
8499
8613
  const meta2 = await loadIdentity4(n);
8500
- const env2 = await loadEnv8(meta2.env).catch(() => null);
8501
- const isDefault = env2?.defaultIdentity === n ? "*" : " ";
8614
+ const env3 = await loadEnv8(meta2.env).catch(() => null);
8615
+ const isDefault = env3?.defaultIdentity === n ? "*" : " ";
8502
8616
  const expired = meta2.expiresAt && new Date(meta2.expiresAt) < /* @__PURE__ */ new Date() ? " (expired)" : "";
8503
8617
  lines.push(`${isDefault} ${n} scheme=${meta2.scheme} env=${meta2.env}${expired}`);
8504
8618
  }
@@ -8510,14 +8624,14 @@ async function identityList(args) {
8510
8624
  async function identityUse(name) {
8511
8625
  try {
8512
8626
  const meta2 = await loadIdentity4(name);
8513
- const env2 = await loadEnv8(meta2.env).catch(() => {
8514
- throw new CliError20({
8515
- code: CliErrorCode19.IDENTITY_NOT_IN_ENV,
8627
+ const env3 = await loadEnv8(meta2.env).catch(() => {
8628
+ throw new CliError21({
8629
+ code: CliErrorCode20.IDENTITY_NOT_IN_ENV,
8516
8630
  message: `identity '${name}' references env '${meta2.env}' which no longer exists. Re-create the env, or remove this orphan: hcm identity remove ${name}`
8517
8631
  });
8518
8632
  });
8519
- env2.defaultIdentity = name;
8520
- await saveEnv3(meta2.env, env2);
8633
+ env3.defaultIdentity = name;
8634
+ await saveEnv3(meta2.env, env3);
8521
8635
  return exitOk(`\u2705 default identity for env '${meta2.env}': ${name}`);
8522
8636
  } catch (e) {
8523
8637
  exitWithError(e);
@@ -8535,10 +8649,10 @@ async function identityRemove(name) {
8535
8649
  );
8536
8650
  }
8537
8651
  await deleteIdentity3(name);
8538
- const env2 = await loadEnv8(meta2.env).catch(() => null);
8539
- if (env2?.defaultIdentity === name) {
8540
- env2.defaultIdentity = void 0;
8541
- await saveEnv3(meta2.env, env2);
8652
+ const env3 = await loadEnv8(meta2.env).catch(() => null);
8653
+ if (env3?.defaultIdentity === name) {
8654
+ env3.defaultIdentity = void 0;
8655
+ await saveEnv3(meta2.env, env3);
8542
8656
  }
8543
8657
  return exitOk(`\u2705 identity '${name}' removed`);
8544
8658
  } catch (e) {
@@ -8557,7 +8671,7 @@ import {
8557
8671
  } from "@hcmai/sdk";
8558
8672
 
8559
8673
  // src/commands/delivery.ts
8560
- import { createHash as createHash4 } from "crypto";
8674
+ import { createHash as createHash5 } from "crypto";
8561
8675
  var APPROVAL_BYPASS_FLAGS = /* @__PURE__ */ new Set(["-y", "--yes", "--force", "--auto-approve"]);
8562
8676
  var CREDENTIAL_FLAGS = /* @__PURE__ */ new Set([
8563
8677
  "--password",
@@ -9035,7 +9149,7 @@ function valuesAfterFlag(argv, flag) {
9035
9149
  return values;
9036
9150
  }
9037
9151
  function sha2564(value) {
9038
- return createHash4("sha256").update(value).digest("hex");
9152
+ return createHash5("sha256").update(value).digest("hex");
9039
9153
  }
9040
9154
  function isPlainObject(value) {
9041
9155
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -9235,7 +9349,7 @@ function withProjectReadiness(assessment, projectRoot = ".") {
9235
9349
  projectInitialized,
9236
9350
  requirements,
9237
9351
  modePolicy: assessment.modePolicy ? { ...assessment.modePolicy, controlled: "deny" } : assessment.modePolicy,
9238
- projectNextStep: `\u672C\u9879\u76EE\u5C1A\u672A\u521D\u59CB\u5316\uFF08\u7F3A ${projectFile}\uFF09\uFF1B\u5148\u8DD1 hcm delivery init`
9352
+ projectNextStep: `\u672C\u9879\u76EE\u5C1A\u672A\u521D\u59CB\u5316\uFF08\u7F3A ${projectFile}\uFF09\uFF1B\u5148\u8DD1 hcm chiron init`
9239
9353
  };
9240
9354
  }
9241
9355
  async function deliveryAssessCommand(argv, args) {
@@ -9352,21 +9466,209 @@ function flagValue2(argv, flag) {
9352
9466
  init_exit();
9353
9467
  import { promises as fs8 } from "fs";
9354
9468
  import path8 from "path";
9355
- import {
9356
- formatObject as formatObject22,
9357
- loadEnv as loadEnv9,
9358
- loadGlobalConfig as loadGlobalConfig9,
9359
- resolveActiveEnv as resolveActiveEnv5
9360
- } from "@hcmai/sdk";
9469
+ import { formatObject as formatObject22 } from "@hcmai/sdk";
9361
9470
 
9362
- // src/commands/delivery-project-scaffold.ts
9363
- import { promises as fs6 } from "fs";
9364
- import path6 from "path";
9471
+ // src/commands/delivery-mode-approval.ts
9472
+ import { randomUUID } from "crypto";
9473
+ import { promises as fs7 } from "fs";
9474
+ import path7 from "path";
9475
+ function requireControlledModeApproval(mode, approvedBy, reason) {
9476
+ if (mode !== "controlled") return null;
9477
+ const approver = approvedBy?.trim() ?? "";
9478
+ const approvalReason = reason?.trim() ?? "";
9479
+ if (!approver || !approvalReason) {
9480
+ throw new Error(
9481
+ "\u5207\u6362\u5230 controlled \u5FC5\u987B\u540C\u65F6\u4F20 --approved-by <\u9879\u76EE\u8D1F\u8D23\u4EBA> \u4E0E --reason <\u672C\u6B21\u660E\u786E\u6388\u6743\u4F9D\u636E>\u3002\u6388\u6743\u5FC5\u987B\u6765\u81EA\u9879\u76EE\u8D1F\u8D23\u4EBA\u5728\u672C\u6B21\u5BF9\u8BDD\u6216\u4EFB\u52A1\u4E66\u4E2D\u7684\u660E\u786E\u6279\u51C6\uFF1B\u5BA2\u6237\u53E3\u5934\u6216\u7FA4\u6D88\u606F\u4E0D\u662F\u6267\u884C\u6388\u6743"
9482
+ );
9483
+ }
9484
+ return { approvedBy: approver, reason: approvalReason };
9485
+ }
9486
+ async function setDeliveryModeWithReceipt(input) {
9487
+ const approval = requireControlledModeApproval(input.mode, input.approvedBy, input.reason);
9488
+ const root = path7.resolve(input.project);
9489
+ const projectFile = path7.join(root, ".hcm-delivery", "project.yml");
9490
+ const content = await fs7.readFile(projectFile, "utf8").catch((cause) => {
9491
+ throw new Error(`\u9879\u76EE\u672A\u521D\u59CB\u5316\uFF1A\u627E\u4E0D\u5230 ${projectFile}
9492
+ \u4E0B\u4E00\u6B65\uFF1Ahcm chiron init`, {
9493
+ cause
9494
+ });
9495
+ });
9496
+ const update = setDeliveryModeForEnvironment(content, input.environment, input.mode);
9497
+ const changed = (input.now ?? (() => /* @__PURE__ */ new Date()))();
9498
+ if (Number.isNaN(changed.getTime())) throw new Error("\u5F53\u524D\u65F6\u95F4\u65E0\u6548");
9499
+ let receiptFile = null;
9500
+ if (approval) {
9501
+ const relativeDirectory = path7.join("evidence", "delivery-mode");
9502
+ await ensureReceiptDirectory(root);
9503
+ const safeTime = changed.toISOString().replace(/[:.]/g, "-");
9504
+ const id = (input.receiptId ?? randomUUID)();
9505
+ if (!/^[a-zA-Z0-9-]+$/.test(id)) throw new Error("\u6A21\u5F0F\u5207\u6362\u6536\u636E ID \u975E\u6CD5");
9506
+ receiptFile = path7.join(relativeDirectory, `${safeTime}-${id}.receipt.json`);
9507
+ }
9508
+ const receipt = {
9509
+ schemaVersion: 1,
9510
+ receiptType: "delivery-mode-change",
9511
+ changedAt: changed.toISOString(),
9512
+ project: root,
9513
+ projectFile,
9514
+ environment: input.environment,
9515
+ previous: update.previous,
9516
+ deliveryMode: input.mode,
9517
+ canExecuteR2: input.mode === "controlled",
9518
+ migratedLegacy: update.migratedLegacy,
9519
+ approvedBy: approval?.approvedBy ?? null,
9520
+ reason: approval?.reason ?? null,
9521
+ receiptFile
9522
+ };
9523
+ await fs7.writeFile(projectFile, update.content, "utf8");
9524
+ if (receiptFile) {
9525
+ try {
9526
+ await fs7.writeFile(path7.join(root, receiptFile), `${JSON.stringify(receipt, null, 2)}
9527
+ `, {
9528
+ encoding: "utf8",
9529
+ mode: 384,
9530
+ flag: "wx"
9531
+ });
9532
+ } catch (cause) {
9533
+ try {
9534
+ await fs7.writeFile(projectFile, content, "utf8");
9535
+ } catch (rollbackCause) {
9536
+ throw new Error(
9537
+ `\u6A21\u5F0F\u5207\u6362\u6536\u636E\u5199\u5165\u5931\u8D25\uFF0C\u4E14 project.yml \u56DE\u6EDA\u5931\u8D25\uFF1A${String(rollbackCause.message)}`,
9538
+ { cause }
9539
+ );
9540
+ }
9541
+ throw new Error("\u6A21\u5F0F\u5207\u6362\u6536\u636E\u5199\u5165\u5931\u8D25\uFF1Bproject.yml \u5DF2\u56DE\u6EDA\uFF0C\u4ECD\u4FDD\u6301\u539F\u6A21\u5F0F", { cause });
9542
+ }
9543
+ }
9544
+ return receipt;
9545
+ }
9546
+ async function ensureReceiptDirectory(root) {
9547
+ const evidenceDirectory = path7.join(root, "evidence");
9548
+ await ensurePlainDirectory(evidenceDirectory, false);
9549
+ await ensurePlainDirectory(path7.join(evidenceDirectory, "delivery-mode"), true);
9550
+ }
9551
+ async function ensurePlainDirectory(directory, privateDirectory) {
9552
+ let created = false;
9553
+ try {
9554
+ await fs7.mkdir(directory, { mode: privateDirectory ? 448 : 493 });
9555
+ created = true;
9556
+ } catch (cause) {
9557
+ if (cause.code !== "EEXIST") throw cause;
9558
+ }
9559
+ const stat = await fs7.lstat(directory);
9560
+ if (!stat.isDirectory() || stat.isSymbolicLink()) {
9561
+ throw new Error(`\u6A21\u5F0F\u5207\u6362\u6536\u636E\u8DEF\u5F84\u4E0D\u662F\u666E\u901A\u76EE\u5F55\uFF1A${directory}`);
9562
+ }
9563
+ if (privateDirectory || created) {
9564
+ await fs7.chmod(directory, privateDirectory ? 448 : 493);
9565
+ }
9566
+ }
9365
9567
 
9366
- // src/commands/delivery-page-acceptance.ts
9367
- function renderPageAcceptanceSh(evidenceDir = "\u8BC1\u636E") {
9368
- const ev = evidenceDir;
9369
- return [
9568
+ // src/commands/delivery-init.ts
9569
+ function renderProjectYml(environment, mode) {
9570
+ return [
9571
+ "# HCM \u987E\u95EE\u4EA4\u4ED8\u9879\u76EE\u914D\u7F6E\uFF08hcm delivery init \u751F\u6210\uFF09",
9572
+ "#",
9573
+ "# deliveryMode \u6309\u76EE\u6807\u73AF\u5883\u51B3\u5B9A\u672C\u673A\u5141\u8BB8\u8D70\u5230\u54EA\u4E00\u6B65\uFF1A",
9574
+ "# plan-only \u2014\u2014 \u53EA\u5141\u8BB8 assess / prepare \u51FA\u8BA1\u5212\uFF0Cexecute \u4E00\u5F8B\u62D2\u7EDD",
9575
+ "# controlled \u2014\u2014 \u5141\u8BB8 prepare + execute \u5355\u6B21\u53D7\u63A7\u6267\u884C\uFF08\u4ECD\u9700\u9010\u6B21\u6279\u51C6\uFF09",
9576
+ "#",
9577
+ "# \u{1F534} \u5B83\u4E0D\u653E\u5BBD\u4EFB\u4F55\u98CE\u9669\u5224\u7EA7\uFF1AR3 \u5728\u4E24\u79CD\u6A21\u5F0F\u4E0B\u90FD\u62D2\u7EDD\uFF0CR2 \u4ECD\u8981\u8BA1\u5212\u3001\u56DE\u6EDA\u8BF4\u660E\u4E0E\u6536\u636E\u3002",
9578
+ "# \u6539\u4E00\u4E2A\u73AF\u5883\u53EA\u5F71\u54CD\u8BE5\u73AF\u5883\uFF1B\u672A\u767B\u8BB0\u7684\u73AF\u5883 fail-closed\uFF0C\u4E0D\u7EE7\u627F\u5176\u5B83\u73AF\u5883\u7684 controlled\u3002",
9579
+ "schemaVersion: 2",
9580
+ "deliveryMode:",
9581
+ ` ${JSON.stringify(environment)}: ${mode}`,
9582
+ ""
9583
+ ].join("\n");
9584
+ }
9585
+ async function deliveryModeCommand(args) {
9586
+ try {
9587
+ const environment = requireDeliveryModeEnvironment(args.env);
9588
+ const root = path8.resolve(args.project ?? ".");
9589
+ const file = path8.join(root, ".hcm-delivery", "project.yml");
9590
+ let content;
9591
+ try {
9592
+ content = await fs8.readFile(file, "utf8");
9593
+ } catch {
9594
+ throw new Error(
9595
+ `\u9879\u76EE\u672A\u521D\u59CB\u5316\uFF1A\u627E\u4E0D\u5230 ${file}
9596
+ \u4E0B\u4E00\u6B65\uFF1Ahcm delivery init`
9597
+ );
9598
+ }
9599
+ if (!args.set) {
9600
+ const current = deliveryModeForEnvironment(content, environment);
9601
+ process.stdout.write(
9602
+ formatObject22(
9603
+ {
9604
+ project: root,
9605
+ projectFile: file,
9606
+ environment,
9607
+ deliveryMode: current,
9608
+ canExecuteR2: current === "controlled",
9609
+ ...current === "plan-only" ? { note: "plan-only \u53EA\u51FA\u8BA1\u5212\u4E0D\u6267\u884C\uFF1Bexecute \u4F1A\u62D2\u7EDD R2 \u8BA1\u5212" } : current === null ? {
9610
+ note: `\u73AF\u5883 ${environment} \u5C1A\u672A\u767B\u8BB0\u4EA4\u4ED8\u6A21\u5F0F\uFF1Bfail-closed\u3002\u5148\u6267\u884C hcm delivery mode --env ${environment} --set plan-only`
9611
+ } : {}
9612
+ },
9613
+ { format: args.output ?? "json" }
9614
+ ) + "\n"
9615
+ );
9616
+ process.exitCode = 0;
9617
+ return;
9618
+ }
9619
+ const next = args.set;
9620
+ if (!DELIVERY_MODES.includes(next)) {
9621
+ throw new Error(`--set \u53EA\u63A5\u53D7 ${DELIVERY_MODES.join(" | ")}\uFF0C\u6536\u5230 "${args.set}"`);
9622
+ }
9623
+ const receipt = await setDeliveryModeWithReceipt({
9624
+ project: root,
9625
+ environment,
9626
+ mode: next,
9627
+ approvedBy: args.approvedBy,
9628
+ reason: args.reason
9629
+ });
9630
+ process.stdout.write(
9631
+ formatObject22(receipt, { format: args.output ?? "json" }) + "\n"
9632
+ );
9633
+ process.exitCode = 0;
9634
+ return;
9635
+ } catch (e) {
9636
+ exitWithError(e);
9637
+ process.exit(1);
9638
+ }
9639
+ }
9640
+ function requireDeliveryModeEnvironment(envFlag) {
9641
+ const environment = envFlag?.trim();
9642
+ if (!environment) {
9643
+ throw new Error(
9644
+ "hcm delivery mode \u5FC5\u987B\u663E\u5F0F\u4F20 --env <\u73AF\u5883\u522B\u540D>\uFF1B\u9879\u76EE\u4EA4\u4ED8\u6A21\u5F0F\u4E0D\u7EE7\u627F\u5168\u5C40 activeEnv\uFF0C\u907F\u514D\u67E5\u770B\u6216\u4FEE\u6539\u9519\u8BEF\u73AF\u5883"
9645
+ );
9646
+ }
9647
+ return environment;
9648
+ }
9649
+
9650
+ // src/commands/chiron-init.ts
9651
+ init_auth_guard();
9652
+ init_exit();
9653
+ import { promises as fs12 } from "fs";
9654
+ import path11 from "path";
9655
+ import {
9656
+ CliError as CliError22,
9657
+ CliErrorCode as CliErrorCode21,
9658
+ HcmClient as HcmClient21,
9659
+ fetchReconIdentity,
9660
+ formatObject as formatObject23,
9661
+ httpProbe,
9662
+ isTempEnv as isTempEnv3,
9663
+ listIdentities as listIdentities5,
9664
+ loadEnv as loadEnv10,
9665
+ loadGlobalConfig as loadGlobalConfig10
9666
+ } from "@hcmai/sdk";
9667
+
9668
+ // src/commands/delivery-page-acceptance.ts
9669
+ function renderPageAcceptanceSh(evidenceDir = "\u8BC1\u636E") {
9670
+ const ev = evidenceDir;
9671
+ return [
9370
9672
  "#!/usr/bin/env bash",
9371
9673
  "set -euo pipefail",
9372
9674
  "",
@@ -9514,218 +9816,11 @@ function renderPageAcceptanceSh(evidenceDir = "\u8BC1\u636E") {
9514
9816
  }
9515
9817
 
9516
9818
  // src/commands/delivery-project-scaffold.ts
9819
+ import { promises as fs9 } from "fs";
9517
9820
  var AGENT_BEGIN = "<!-- hcm-delivery-project:begin -->";
9518
9821
  var AGENT_END = "<!-- hcm-delivery-project:end -->";
9519
9822
  var GITIGNORE_BEGIN = "# >>> hcm delivery local state >>>";
9520
9823
  var GITIGNORE_END = "# <<< hcm delivery local state <<<";
9521
- var DELIVERY_PROJECT_DIRECTORIES = [
9522
- "work",
9523
- "decisions",
9524
- "evidence",
9525
- "hcm-skills",
9526
- "\u5BA2\u6237\u8D44\u6599",
9527
- "\u9700\u6C42",
9528
- "\u4EA4\u4ED8\u7269",
9529
- "\u8BC1\u636E",
9530
- "\u51B3\u7B56",
9531
- "\u6848\u4F8B"
9532
- ];
9533
- function renderEnvironmentYml(environment, config2, initialMode) {
9534
- const endpoint = config2?.endpoint ?? "REPLACE_ME";
9535
- const frontend = config2?.frontend ?? endpoint;
9536
- const tenant2 = config2?.tenantId ?? "1";
9537
- return [
9538
- "# \u5BA2\u6237\u9879\u76EE\u5171\u4EAB\u73AF\u5883\u6E05\u5355\uFF08\u4E0D\u653E\u8EAB\u4EFD\u6216\u51ED\u636E\uFF09",
9539
- "# owner \u4E0E controlled \u7531\u9879\u76EE\u8D1F\u8D23\u4EBA\u8BC4\u5BA1\uFF1B\u4E2A\u4EBA\u673A\u5668\u4E0A\u7684\u5B9E\u9645\u6A21\u5F0F\u5728 .hcm-delivery/project.yml\u3002",
9540
- "schemaVersion: 1",
9541
- "environments:",
9542
- ` - alias: ${JSON.stringify(environment)}`,
9543
- ` endpoint: ${JSON.stringify(endpoint)}`,
9544
- ` frontend: ${JSON.stringify(frontend)}`,
9545
- ` tenant: ${JSON.stringify(tenant2)}`,
9546
- ` controlled: ${initialMode === "controlled" ? "true" : "false"}`,
9547
- ' owner: "TODO: \u9879\u76EE\u8D1F\u8D23\u4EBA"',
9548
- ""
9549
- ].join("\n");
9550
- }
9551
- function renderAgentInstructions() {
9552
- return [
9553
- AGENT_BEGIN,
9554
- "# HCM \u987E\u95EE\u9879\u76EE\u8FB9\u754C",
9555
- "",
9556
- "- \u53EA\u4F7F\u7528\u672C\u9879\u76EE\u5185\u7684\u777F\u620E\u6280\u80FD\u4E0E\u5DF2\u53D1\u5E03\u7684 `hcm` CLI\uFF1B\u4E0D\u8BFB\u53D6\u4EA7\u54C1\u6E90\u7801\uFF0C\u4E0D\u76F4\u8FDE\u6570\u636E\u5E93\uFF0C\u4E0D\u7528 `curl` \u7ED5\u8FC7 CLI\u3002",
9557
- "- \u6BCF\u6B21\u5F00\u5DE5\u5148\u53EA\u8BFB\u6838\u5BF9 CLI \u7248\u672C\u3001\u76EE\u6807\u73AF\u5883\u3001\u8EAB\u4EFD\u3001\u6280\u80FD\u9501\u4E0E `hcm delivery doctor`\uFF1B\u73AF\u5883\u4E8B\u5B9E\u5FC5\u987B\u73B0\u67E5\uFF0C\u4E0D\u51ED\u8BB0\u5FC6\u586B\u5199\u3002",
9558
- "- R2 \u5199\u64CD\u4F5C\u5FC5\u987B\u4F9D\u6B21\u7ECF\u8FC7 `hcm delivery assess`\u3001`prepare`\u3001`execute`\uFF0C\u88AB\u6267\u884C argv \u5FC5\u987B\u663E\u5F0F\u5E26 `--env` \u4E0E `--as`\u3002",
9559
- "- R2 \u5199\u6388\u6743\u53EA\u8BA4\u53EF\u9879\u76EE\u8D1F\u8D23\u4EBA\u5728**\u672C\u6B21\u5BF9\u8BDD\u6216\u4EFB\u52A1\u4E66**\u91CC\u7684\u660E\u786E\u6279\u51C6\uFF1B\u5BA2\u6237\u53E3\u5934\u8981\u6C42\u6216\u7FA4\u6D88\u606F\u53EA\u662F\u4E1A\u52A1\u9700\u6C42\uFF0C\u4E0D\u662F\u6267\u884C\u6388\u6743\uFF0C\u4E0D\u80FD\u636E\u6B64\u5207\u5230 controlled \u6216\u6267\u884C\u3002",
9560
- "- \u5199\u524D\u5FC5\u987B\u8BF4\u660E\u5BF9\u8C61\u3001\u8303\u56F4\u3001\u5F71\u54CD\u4E0E\u56DE\u9000\u5E76\u53D6\u5F97\u672C\u6B21\u660E\u786E\u786E\u8BA4\u3002\u975E\u4EA4\u4E92\u8FD0\u884C\u62FF\u4E0D\u5230\u786E\u8BA4\u65F6\uFF0C\u6700\u591A\u505A\u5230 `prepare`\uFF0C\u7ED3\u8BBA\u5FC5\u987B\u4E3A `BLOCKED` \u5E76\u9644\u8BA1\u5212\uFF1B\u4E0D\u5F97\u81EA\u884C `delivery mode --set controlled` \u6216 `execute`\u3002",
9561
- "- `.hcm-delivery/project.yml` \u662F\u6BCF\u4EBA\u6BCF\u673A\u72B6\u6001\uFF0C\u4E0D\u63D0\u4EA4\uFF1B\u53EA\u6709 `\u73AF\u5883.yml` \u4E2D `controlled: true` \u4E14\u6EE1\u8DB3\u4E0A\u8FF0\u6388\u6743\u65F6\uFF0C\u624D\u80FD\u7528 `--approved-by` \u4E0E `--reason` \u7559\u4E0B\u6A21\u5F0F\u5207\u6362\u6536\u636E\uFF0C\u5B8C\u6210\u540E\u7ACB\u5373\u56DE\u5230 plan-only\u3002\u5BA1\u8BA1\u53C2\u6570\u4E0D\u80FD\u66FF\u4EE3\u771F\u5B9E\u6388\u6743\u3002",
9562
- "- \u53D8\u66F4/\u56DE\u6EDA\u8BF4\u660E\u653E CLI \u56FA\u5B9A\u7684 `work/` \u6216 `decisions/`\uFF0C\u6536\u636E\u653E `evidence/`\uFF1B\u5BA2\u6237\u5171\u4EAB\u6750\u6599\u5206\u522B\u5F52\u6863\u5230\u4E2D\u6587\u4E1A\u52A1\u76EE\u5F55\u3002",
9563
- "- \u9875\u9762\u9A8C\u6536\u7EDF\u4E00\u7528 `./page-acceptance.sh`\uFF1A\u663E\u5F0F\u4F20\u73AF\u5883\u3001\u8EAB\u4EFD\u3001\u7AD9\u5185\u8DEF\u5F84\u3001\u671F\u671B\u6587\u672C\u4E0E `\u8BC1\u636E/` \u4E0B\u7684 PNG \u8DEF\u5F84\uFF1B\u4E0D\u80FD\u53EA\u4EE5\u201C\u751F\u6210\u4E86\u622A\u56FE\u201D\u5224\u901A\u8FC7\u3002",
9564
- "- \u4EFB\u4F55\u51ED\u636E\u3001\u914D\u5BF9\u7801\u3001\u4EE4\u724C\u3001\u5BA2\u6237\u5BC6\u7801\u90FD\u4E0D\u5F97\u5199\u5165\u4ED3\u5E93\u3001\u547D\u4EE4\u53C2\u6570\u6216\u4EA4\u4ED8\u6587\u6863\u3002",
9565
- AGENT_END,
9566
- ""
9567
- ].join("\n");
9568
- }
9569
- function renderSetupSh(cliVersion) {
9570
- return [
9571
- "#!/usr/bin/env bash",
9572
- "set -euo pipefail",
9573
- "",
9574
- `expected_hcm_version=${JSON.stringify(cliVersion)}`,
9575
- 'actual_hcm_version="$(hcm --version 2>/dev/null || true)"',
9576
- 'if [[ "$actual_hcm_version" != "$expected_hcm_version" ]]; then',
9577
- ` printf '\u9700\u8981 hcm %s\uFF0C\u5F53\u524D\u662F %s\u3002\u5148\u6267\u884C\uFF1Anpm install --global @hcmai/cli@%s\\n' "$expected_hcm_version" "\${actual_hcm_version:-\u672A\u5B89\u88C5}" "$expected_hcm_version" >&2`,
9578
- " exit 1",
9579
- "fi",
9580
- "",
9581
- "node <<'HCM_PROJECT_SETUP'",
9582
- "const fs = require('node:fs');",
9583
- "const path = require('node:path');",
9584
- "const { spawnSync } = require('node:child_process');",
9585
- "",
9586
- "const project = process.cwd();",
9587
- "const environmentsFile = path.join(project, '\u73AF\u5883.yml');",
9588
- "const projectFile = path.join(project, '.hcm-delivery', 'project.yml');",
9589
- "const skillsLock = path.join(project, 'hcm-skills', '.hcm-skills.json');",
9590
- "const source = fs.readFileSync(environmentsFile, 'utf8');",
9591
- "const environments = parseEnvironments(source);",
9592
- "if (environments.length === 0) throw new Error('\u73AF\u5883.yml \u81F3\u5C11\u8981\u6709\u4E00\u4E2A\u73AF\u5883');",
9593
- "",
9594
- "const missingEnvironments = new Set();",
9595
- "for (const environment of environments) {",
9596
- " const probe = spawnSync('hcm', ['env', 'show', environment.alias], { encoding: 'utf8' });",
9597
- " if (probe.error) throw new Error(`\u65E0\u6CD5\u68C0\u67E5\u73AF\u5883 ${environment.alias}\uFF1A${probe.error.message}`);",
9598
- " if (probe.status === 0) {",
9599
- " const existing = parseExistingEnvironment(probe.stdout, environment.alias);",
9600
- " assertEnvironmentMatches(environment, existing);",
9601
- " process.stdout.write(`[setup] env ${environment.alias} \u5DF2\u5B58\u5728\u4E14\u4E0E \u73AF\u5883.yml \u4E00\u81F4\uFF0C\u4FDD\u7559\u672C\u673A\u8EAB\u4EFD\\n`);",
9602
- " continue;",
9603
- " }",
9604
- " if (/\\bENV_NOT_FOUND\\b/.test(probe.stderr)) {",
9605
- " missingEnvironments.add(environment.alias);",
9606
- " continue;",
9607
- " }",
9608
- " const detail = probe.stderr.trim() || `\u9000\u51FA\u7801 ${probe.status ?? 'unknown'}`;",
9609
- " throw new Error(`\u65E0\u6CD5\u68C0\u67E5\u73AF\u5883 ${environment.alias}\uFF1A${detail}`);",
9610
- "}",
9611
- "",
9612
- "let projectInitialized = fs.existsSync(projectFile);",
9613
- "for (const environment of environments) {",
9614
- " if (missingEnvironments.has(environment.alias)) {",
9615
- " const add = ['env', 'add', environment.alias, '--endpoint', environment.endpoint];",
9616
- " if (environment.frontend) add.push('--frontend', environment.frontend);",
9617
- " if (environment.tenant) add.push('--tenant', environment.tenant);",
9618
- " run(add);",
9619
- " }",
9620
- " if (!projectInitialized) {",
9621
- " run(['delivery', 'init', '--project', project, '--env', environment.alias, '--mode', 'plan-only']);",
9622
- " projectInitialized = true;",
9623
- " } else {",
9624
- " run(['delivery', 'mode', '--project', project, '--env', environment.alias, '--set', 'plan-only']);",
9625
- " }",
9626
- "}",
9627
- "",
9628
- "if (!fs.existsSync(skillsLock)) {",
9629
- " run(['skills', 'install', '--all', '--target', 'codex', '--env', environments[0].alias]);",
9630
- "} else {",
9631
- " process.stdout.write('[setup] \u5DF2\u6709 hcm-skills \u9501\uFF0C\u6309\u4ED3\u5E93\u7248\u672C\u4F7F\u7528\uFF1B\u5347\u7EA7\u6280\u80FD\u8BF7\u53E6\u8D70 PR\\n');",
9632
- "}",
9633
- 'process.stdout.write("[setup] \u5B8C\u6210\u3002\u4E0B\u4E00\u6B65\uFF1A\u9010\u4E2A\u6267\u884C hcm login --env <alias> --code <\u914D\u5BF9\u7801> --name <\u4F60\u7684\u540D\u5B57>-<alias>\\n");',
9634
- "",
9635
- "function run(args) {",
9636
- " const result = spawnSync('hcm', args, { cwd: project, stdio: 'inherit' });",
9637
- " if (result.error) throw new Error(`\u65E0\u6CD5\u6267\u884C hcm ${args.join(' ')}\uFF1A${result.error.message}`);",
9638
- " if (result.status !== 0) process.exit(result.status ?? 1);",
9639
- "}",
9640
- "",
9641
- "function parseEnvironments(text) {",
9642
- " const result = [];",
9643
- " let current = null;",
9644
- " let inEnvironments = false;",
9645
- " for (const [offset, rawLine] of text.split(/\\r?\\n/).entries()) {",
9646
- " const lineNo = offset + 1;",
9647
- ' if (!rawLine.trim() || rawLine.trimStart().startsWith("#")) continue;',
9648
- " if (/^schemaVersion:\\s*1\\s*$/.test(rawLine)) continue;",
9649
- " if (/^environments:\\s*$/.test(rawLine)) { inEnvironments = true; continue; }",
9650
- " if (!inEnvironments) throw new Error(`\u73AF\u5883.yml \u7B2C ${lineNo} \u884C\u4E0D\u5C5E\u4E8E environments`);",
9651
- " const first = rawLine.match(/^ {2}- alias:\\s*(.+)$/);",
9652
- " if (first) {",
9653
- " if (current) result.push(validateEnvironment(current, lineNo));",
9654
- " current = { alias: scalar(first[1], lineNo) };",
9655
- " continue;",
9656
- " }",
9657
- " const field = rawLine.match(/^ {4}(endpoint|frontend|tenant|controlled|owner):\\s*(.+)$/);",
9658
- " if (!field || !current) throw new Error(`\u73AF\u5883.yml \u7B2C ${lineNo} \u884C\u4E0D\u7B26\u5408\u811A\u624B\u67B6\u683C\u5F0F`);",
9659
- " current[field[1]] = scalar(field[2], lineNo);",
9660
- " }",
9661
- " if (current) result.push(validateEnvironment(current, text.split(/\\r?\\n/).length));",
9662
- " return result;",
9663
- "}",
9664
- "",
9665
- "function scalar(raw, lineNo) {",
9666
- " const value = raw.trim();",
9667
- ` if (value.startsWith('"')) {`,
9668
- " try { return JSON.parse(value); } catch { throw new Error(`\u73AF\u5883.yml \u7B2C ${lineNo} \u884C\u7684\u53CC\u5F15\u53F7\u503C\u975E\u6CD5`); }",
9669
- " }",
9670
- ` if (value.startsWith("'") && value.endsWith("'")) return value.slice(1, -1).replace(/''/g, "'");`,
9671
- ' const plain = value.replace(/\\s+#.*$/, "").trim();',
9672
- ' if (plain === "true") return true;',
9673
- ' if (plain === "false") return false;',
9674
- " return plain;",
9675
- "}",
9676
- "",
9677
- "function validateEnvironment(environment, lineNo) {",
9678
- ' for (const key of ["alias", "endpoint"]) {',
9679
- ' if (typeof environment[key] !== "string" || !environment[key].trim()) {',
9680
- " throw new Error(`\u73AF\u5883.yml \u622A\u81F3\u7B2C ${lineNo} \u884C\u7F3A\u5C11 ${key}`);",
9681
- " }",
9682
- " }",
9683
- ' if (environment.endpoint === "REPLACE_ME") {',
9684
- " throw new Error(`\u73AF\u5883 ${environment.alias} \u7684 endpoint \u4ECD\u662F REPLACE_ME\uFF0C\u8BF7\u5148\u7F16\u8F91 \u73AF\u5883.yml`);",
9685
- " }",
9686
- " if (environment.controlled !== true && environment.controlled !== false) {",
9687
- " throw new Error(`\u73AF\u5883 ${environment.alias} \u7684 controlled \u5FC5\u987B\u662F true \u6216 false`);",
9688
- " }",
9689
- ' for (const key of ["frontend", "tenant"]) {',
9690
- ' if (environment[key] !== undefined && typeof environment[key] !== "string") {',
9691
- " environment[key] = String(environment[key]);",
9692
- " }",
9693
- " }",
9694
- " return environment;",
9695
- "}",
9696
- "",
9697
- "function parseExistingEnvironment(text, alias) {",
9698
- " const result = {};",
9699
- " for (const [offset, rawLine] of text.split(/\\r?\\n/).entries()) {",
9700
- ' if (!rawLine.trim() || rawLine.startsWith(" ") || rawLine.trimStart().startsWith("#")) continue;',
9701
- " const field = rawLine.match(/^(endpoint|frontend|tenantId):\\s*(.+)$/);",
9702
- " if (field) result[field[1]] = scalar(field[2], offset + 1);",
9703
- " }",
9704
- ' if (typeof result.endpoint !== "string" || !result.endpoint) {',
9705
- " throw new Error(`hcm env show ${alias} \u672A\u8FD4\u56DE\u6709\u6548 endpoint\uFF0C\u62D2\u7EDD\u7EE7\u7EED`);",
9706
- " }",
9707
- " return result;",
9708
- "}",
9709
- "",
9710
- "function assertEnvironmentMatches(expected, actual) {",
9711
- " const fields = [",
9712
- ' ["endpoint", expected.endpoint, actual.endpoint],',
9713
- ' ["frontend", expected.frontend ?? "", actual.frontend ?? ""],',
9714
- ' ["tenant", expected.tenant ?? "1", actual.tenantId ?? "1"],',
9715
- " ];",
9716
- " const mismatches = fields",
9717
- " .filter(([, wanted, found]) => String(wanted) !== String(found))",
9718
- " .map(([name, wanted, found]) => `${name}: \u9879\u76EE=${JSON.stringify(wanted)} \u672C\u673A=${JSON.stringify(found)}`);",
9719
- " if (mismatches.length === 0) return;",
9720
- " throw new Error(",
9721
- ' `\u73AF\u5883 ${expected.alias} \u5DF2\u5B58\u5728\uFF0C\u4F46\u672C\u673A\u914D\u7F6E\u4E0E \u73AF\u5883.yml \u4E0D\u4E00\u81F4\uFF1A${mismatches.join("\uFF1B")}\u3002` +',
9722
- ' "\u4E3A\u4FDD\u62A4\u672C\u673A\u5DF2\u6709\u8EAB\u4EFD\uFF0Csetup.sh \u4E0D\u4F1A\u7528 --force \u8986\u76D6\uFF1B\u8BF7\u6838\u5BF9\u540E\u663E\u5F0F\u4FEE\u6B63\u672C\u673A\u73AF\u5883\u6216 \u73AF\u5883.yml\u3002",',
9723
- " );",
9724
- "}",
9725
- "HCM_PROJECT_SETUP",
9726
- ""
9727
- ].join("\n");
9728
- }
9729
9824
  function mergeDeliveryGitignore(existing) {
9730
9825
  const block = [
9731
9826
  GITIGNORE_BEGIN,
@@ -9736,50 +9831,6 @@ function mergeDeliveryGitignore(existing) {
9736
9831
  ].join("\n");
9737
9832
  return upsertBlock(existing, GITIGNORE_BEGIN, GITIGNORE_END, block);
9738
9833
  }
9739
- function mergeAgentInstructions(existing) {
9740
- return upsertBlock(
9741
- existing,
9742
- AGENT_BEGIN,
9743
- AGENT_END,
9744
- renderAgentInstructions().trimEnd()
9745
- );
9746
- }
9747
- async function scaffoldDeliveryProject(root, options) {
9748
- const result = { created: [], updated: [], preserved: [] };
9749
- for (const directory of DELIVERY_PROJECT_DIRECTORIES) {
9750
- const absolute = path6.join(root, directory);
9751
- await ensureDirectory(absolute);
9752
- await writeIfAbsent(path6.join(absolute, ".gitkeep"), "", result, `${directory}/.gitkeep`);
9753
- }
9754
- await writeIfAbsent(
9755
- path6.join(root, "\u73AF\u5883.yml"),
9756
- renderEnvironmentYml(options.environment, options.environmentConfig, options.initialMode),
9757
- result,
9758
- "\u73AF\u5883.yml"
9759
- );
9760
- const setupFile = path6.join(root, "setup.sh");
9761
- const setupCreated = await writeIfAbsent(
9762
- setupFile,
9763
- renderSetupSh(options.cliVersion),
9764
- result,
9765
- "setup.sh",
9766
- 493
9767
- );
9768
- if (setupCreated) await fs6.chmod(setupFile, 493);
9769
- const pageAcceptanceFile = path6.join(root, "page-acceptance.sh");
9770
- const pageAcceptanceCreated = await writeIfAbsent(
9771
- pageAcceptanceFile,
9772
- renderPageAcceptanceSh(),
9773
- result,
9774
- "page-acceptance.sh",
9775
- 493
9776
- );
9777
- if (pageAcceptanceCreated) await fs6.chmod(pageAcceptanceFile, 493);
9778
- await mergeManagedFile(path6.join(root, "AGENTS.md"), mergeAgentInstructions, result, "AGENTS.md");
9779
- await mergeManagedFile(path6.join(root, "CLAUDE.md"), mergeAgentInstructions, result, "CLAUDE.md");
9780
- await mergeManagedFile(path6.join(root, ".gitignore"), mergeDeliveryGitignore, result, ".gitignore");
9781
- return result;
9782
- }
9783
9834
  async function mergeManagedFile(file, merge, result, relative2) {
9784
9835
  const existing = await readRegularFile(file);
9785
9836
  const next = merge(existing ?? "");
@@ -9787,12 +9838,12 @@ async function mergeManagedFile(file, merge, result, relative2) {
9787
9838
  result.preserved.push(relative2);
9788
9839
  return;
9789
9840
  }
9790
- await fs6.writeFile(file, next, { encoding: "utf8", mode: 420 });
9841
+ await fs9.writeFile(file, next, { encoding: "utf8", mode: 420 });
9791
9842
  (existing === null ? result.created : result.updated).push(relative2);
9792
9843
  }
9793
9844
  async function writeIfAbsent(file, content, result, relative2, mode = 420) {
9794
9845
  try {
9795
- await fs6.writeFile(file, content, { encoding: "utf8", mode, flag: "wx" });
9846
+ await fs9.writeFile(file, content, { encoding: "utf8", mode, flag: "wx" });
9796
9847
  result.created.push(relative2);
9797
9848
  return true;
9798
9849
  } catch (cause) {
@@ -9803,8 +9854,8 @@ async function writeIfAbsent(file, content, result, relative2, mode = 420) {
9803
9854
  }
9804
9855
  }
9805
9856
  async function ensureDirectory(directory) {
9806
- await fs6.mkdir(directory, { recursive: true });
9807
- const stat = await fs6.lstat(directory);
9857
+ await fs9.mkdir(directory, { recursive: true });
9858
+ const stat = await fs9.lstat(directory);
9808
9859
  if (!stat.isDirectory() || stat.isSymbolicLink()) {
9809
9860
  throw new Error(`\u811A\u624B\u67B6\u8DEF\u5F84\u4E0D\u662F\u666E\u901A\u76EE\u5F55\uFF1A${directory}`);
9810
9861
  }
@@ -9812,14 +9863,14 @@ async function ensureDirectory(directory) {
9812
9863
  async function readRegularFile(file) {
9813
9864
  try {
9814
9865
  await assertRegularFile(file);
9815
- return await fs6.readFile(file, "utf8");
9866
+ return await fs9.readFile(file, "utf8");
9816
9867
  } catch (cause) {
9817
9868
  if (cause.code === "ENOENT") return null;
9818
9869
  throw cause;
9819
9870
  }
9820
9871
  }
9821
9872
  async function assertRegularFile(file) {
9822
- const stat = await fs6.lstat(file);
9873
+ const stat = await fs9.lstat(file);
9823
9874
  if (!stat.isFile() || stat.isSymbolicLink()) {
9824
9875
  throw new Error(`\u811A\u624B\u67B6\u8DEF\u5F84\u4E0D\u662F\u666E\u901A\u6587\u4EF6\uFF1A${file}`);
9825
9876
  }
@@ -9842,336 +9893,42 @@ function upsertBlock(existing, begin, end, block) {
9842
9893
  `;
9843
9894
  }
9844
9895
 
9845
- // src/commands/delivery-mode-approval.ts
9846
- import { randomUUID } from "crypto";
9847
- import { promises as fs7 } from "fs";
9848
- import path7 from "path";
9849
- function requireControlledModeApproval(mode, approvedBy, reason) {
9850
- if (mode !== "controlled") return null;
9851
- const approver = approvedBy?.trim() ?? "";
9852
- const approvalReason = reason?.trim() ?? "";
9853
- if (!approver || !approvalReason) {
9854
- throw new Error(
9855
- "\u5207\u6362\u5230 controlled \u5FC5\u987B\u540C\u65F6\u4F20 --approved-by <\u9879\u76EE\u8D1F\u8D23\u4EBA> \u4E0E --reason <\u672C\u6B21\u660E\u786E\u6388\u6743\u4F9D\u636E>\u3002\u6388\u6743\u5FC5\u987B\u6765\u81EA\u9879\u76EE\u8D1F\u8D23\u4EBA\u5728\u672C\u6B21\u5BF9\u8BDD\u6216\u4EFB\u52A1\u4E66\u4E2D\u7684\u660E\u786E\u6279\u51C6\uFF1B\u5BA2\u6237\u53E3\u5934\u6216\u7FA4\u6D88\u606F\u4E0D\u662F\u6267\u884C\u6388\u6743"
9856
- );
9857
- }
9858
- return { approvedBy: approver, reason: approvalReason };
9859
- }
9860
- async function setDeliveryModeWithReceipt(input) {
9861
- const approval = requireControlledModeApproval(input.mode, input.approvedBy, input.reason);
9862
- const root = path7.resolve(input.project);
9863
- const projectFile = path7.join(root, ".hcm-delivery", "project.yml");
9864
- const content = await fs7.readFile(projectFile, "utf8").catch((cause) => {
9865
- throw new Error(`\u9879\u76EE\u672A\u521D\u59CB\u5316\uFF1A\u627E\u4E0D\u5230 ${projectFile}
9866
- \u4E0B\u4E00\u6B65\uFF1Ahcm delivery init`, {
9867
- cause
9868
- });
9869
- });
9870
- const update = setDeliveryModeForEnvironment(content, input.environment, input.mode);
9871
- const changed = (input.now ?? (() => /* @__PURE__ */ new Date()))();
9872
- if (Number.isNaN(changed.getTime())) throw new Error("\u5F53\u524D\u65F6\u95F4\u65E0\u6548");
9873
- let receiptFile = null;
9874
- if (approval) {
9875
- const relativeDirectory = path7.join("evidence", "delivery-mode");
9876
- await ensureReceiptDirectory(root);
9877
- const safeTime = changed.toISOString().replace(/[:.]/g, "-");
9878
- const id = (input.receiptId ?? randomUUID)();
9879
- if (!/^[a-zA-Z0-9-]+$/.test(id)) throw new Error("\u6A21\u5F0F\u5207\u6362\u6536\u636E ID \u975E\u6CD5");
9880
- receiptFile = path7.join(relativeDirectory, `${safeTime}-${id}.receipt.json`);
9881
- }
9882
- const receipt = {
9883
- schemaVersion: 1,
9884
- receiptType: "delivery-mode-change",
9885
- changedAt: changed.toISOString(),
9886
- project: root,
9887
- projectFile,
9888
- environment: input.environment,
9889
- previous: update.previous,
9890
- deliveryMode: input.mode,
9891
- canExecuteR2: input.mode === "controlled",
9892
- migratedLegacy: update.migratedLegacy,
9893
- approvedBy: approval?.approvedBy ?? null,
9894
- reason: approval?.reason ?? null,
9895
- receiptFile
9896
- };
9897
- await fs7.writeFile(projectFile, update.content, "utf8");
9898
- if (receiptFile) {
9899
- try {
9900
- await fs7.writeFile(path7.join(root, receiptFile), `${JSON.stringify(receipt, null, 2)}
9901
- `, {
9902
- encoding: "utf8",
9903
- mode: 384,
9904
- flag: "wx"
9905
- });
9906
- } catch (cause) {
9907
- try {
9908
- await fs7.writeFile(projectFile, content, "utf8");
9909
- } catch (rollbackCause) {
9910
- throw new Error(
9911
- `\u6A21\u5F0F\u5207\u6362\u6536\u636E\u5199\u5165\u5931\u8D25\uFF0C\u4E14 project.yml \u56DE\u6EDA\u5931\u8D25\uFF1A${String(rollbackCause.message)}`,
9912
- { cause }
9913
- );
9914
- }
9915
- throw new Error("\u6A21\u5F0F\u5207\u6362\u6536\u636E\u5199\u5165\u5931\u8D25\uFF1Bproject.yml \u5DF2\u56DE\u6EDA\uFF0C\u4ECD\u4FDD\u6301\u539F\u6A21\u5F0F", { cause });
9916
- }
9917
- }
9918
- return receipt;
9919
- }
9920
- async function ensureReceiptDirectory(root) {
9921
- const evidenceDirectory = path7.join(root, "evidence");
9922
- await ensurePlainDirectory(evidenceDirectory, false);
9923
- await ensurePlainDirectory(path7.join(evidenceDirectory, "delivery-mode"), true);
9924
- }
9925
- async function ensurePlainDirectory(directory, privateDirectory) {
9926
- let created = false;
9927
- try {
9928
- await fs7.mkdir(directory, { mode: privateDirectory ? 448 : 493 });
9929
- created = true;
9930
- } catch (cause) {
9931
- if (cause.code !== "EEXIST") throw cause;
9932
- }
9933
- const stat = await fs7.lstat(directory);
9934
- if (!stat.isDirectory() || stat.isSymbolicLink()) {
9935
- throw new Error(`\u6A21\u5F0F\u5207\u6362\u6536\u636E\u8DEF\u5F84\u4E0D\u662F\u666E\u901A\u76EE\u5F55\uFF1A${directory}`);
9936
- }
9937
- if (privateDirectory || created) {
9938
- await fs7.chmod(directory, privateDirectory ? 448 : 493);
9939
- }
9940
- }
9941
-
9942
- // src/commands/delivery-init.ts
9943
- function renderProjectYml(environment, mode) {
9944
- return [
9945
- "# HCM \u987E\u95EE\u4EA4\u4ED8\u9879\u76EE\u914D\u7F6E\uFF08hcm delivery init \u751F\u6210\uFF09",
9946
- "#",
9947
- "# deliveryMode \u6309\u76EE\u6807\u73AF\u5883\u51B3\u5B9A\u672C\u673A\u5141\u8BB8\u8D70\u5230\u54EA\u4E00\u6B65\uFF1A",
9948
- "# plan-only \u2014\u2014 \u53EA\u5141\u8BB8 assess / prepare \u51FA\u8BA1\u5212\uFF0Cexecute \u4E00\u5F8B\u62D2\u7EDD",
9949
- "# controlled \u2014\u2014 \u5141\u8BB8 prepare + execute \u5355\u6B21\u53D7\u63A7\u6267\u884C\uFF08\u4ECD\u9700\u9010\u6B21\u6279\u51C6\uFF09",
9950
- "#",
9951
- "# \u{1F534} \u5B83\u4E0D\u653E\u5BBD\u4EFB\u4F55\u98CE\u9669\u5224\u7EA7\uFF1AR3 \u5728\u4E24\u79CD\u6A21\u5F0F\u4E0B\u90FD\u62D2\u7EDD\uFF0CR2 \u4ECD\u8981\u8BA1\u5212\u3001\u56DE\u6EDA\u8BF4\u660E\u4E0E\u6536\u636E\u3002",
9952
- "# \u6539\u4E00\u4E2A\u73AF\u5883\u53EA\u5F71\u54CD\u8BE5\u73AF\u5883\uFF1B\u672A\u767B\u8BB0\u7684\u73AF\u5883 fail-closed\uFF0C\u4E0D\u7EE7\u627F\u5176\u5B83\u73AF\u5883\u7684 controlled\u3002",
9953
- "schemaVersion: 2",
9954
- "deliveryMode:",
9955
- ` ${JSON.stringify(environment)}: ${mode}`,
9956
- ""
9957
- ].join("\n");
9958
- }
9959
- async function deliveryInitCommand(args) {
9960
- try {
9961
- const mode = args.mode ?? "plan-only";
9962
- if (!DELIVERY_MODES.includes(mode)) {
9963
- throw new Error(
9964
- `--mode \u53EA\u63A5\u53D7 ${DELIVERY_MODES.join(" | ")}\uFF0C\u6536\u5230 "${args.mode}"
9965
- \u8FD9\u4E24\u4E2A\u503C\u662F delivery prepare \u8BA4\u5F97\u7684\u5168\u90E8\uFF1B\u5199\u522B\u7684\u503C prepare \u4F1A\u62D2\u7EDD\u52A0\u8F7D\u3002`
9966
- );
9967
- }
9968
- const approval = requireControlledModeApproval(mode, args.approvedBy, args.reason);
9969
- const environment = await resolveDeliveryEnvironment(args.env);
9970
- const root = path8.resolve(args.project ?? ".");
9971
- const dir = path8.join(root, ".hcm-delivery");
9972
- const file = path8.join(dir, "project.yml");
9973
- let existed = false;
9974
- try {
9975
- await fs8.access(file);
9976
- existed = true;
9977
- } catch {
9978
- existed = false;
9979
- }
9980
- if (existed && !args.force) {
9981
- throw new Error(
9982
- `\u9879\u76EE\u914D\u7F6E\u5DF2\u5B58\u5728\uFF1A${file}
9983
- \u4E0D\u8986\u76D6\u5DF2\u6709\u914D\u7F6E\u2014\u2014\u5B83\u51B3\u5B9A\u672C\u9879\u76EE\u5141\u4E0D\u5141\u8BB8\u771F\u7684\u6267\u884C\u3002
9984
- \u786E\u8981\u91CD\u5199\uFF1Ahcm delivery init --force`
9985
- );
9986
- }
9987
- await fs8.mkdir(dir, { recursive: true });
9988
- await fs8.writeFile(file, renderProjectYml(environment, "plan-only"), "utf8");
9989
- const environmentConfig = await loadEnv9(environment).catch(() => null);
9990
- const scaffold = await scaffoldDeliveryProject(root, {
9991
- environment,
9992
- environmentConfig,
9993
- initialMode: mode,
9994
- cliVersion: CLI_VERSION
9995
- });
9996
- const modeReceipt = approval ? await setDeliveryModeWithReceipt({
9997
- project: root,
9998
- environment,
9999
- mode,
10000
- approvedBy: approval.approvedBy,
10001
- reason: approval.reason
10002
- }) : null;
10003
- const result = {
10004
- project: root,
10005
- projectFile: file,
10006
- environment,
10007
- deliveryMode: mode,
10008
- overwritten: existed,
10009
- scaffold,
10010
- ...modeReceipt ? { modeReceipt } : {},
10011
- nextStep: mode === "controlled" ? "hcm delivery assess <\u547D\u4EE4>\uFF1BR2 \u518D hcm delivery prepare --change-ref \u2026 --rollback-ref \u2026 --evidence-dir \u2026" : "hcm delivery assess <\u547D\u4EE4>\uFF1B\u672C\u9879\u76EE\u4E3A plan-only\uFF0Cexecute \u4F1A\u88AB\u62D2\u7EDD"
10012
- };
10013
- process.stdout.write(formatObject22(result, { format: args.output ?? "json" }) + "\n");
10014
- process.exitCode = 0;
10015
- return;
10016
- } catch (e) {
10017
- exitWithError(e);
10018
- process.exit(1);
10019
- }
10020
- }
10021
- async function deliveryModeCommand(args) {
10022
- try {
10023
- const environment = requireDeliveryModeEnvironment(args.env);
10024
- const root = path8.resolve(args.project ?? ".");
10025
- const file = path8.join(root, ".hcm-delivery", "project.yml");
10026
- let content;
10027
- try {
10028
- content = await fs8.readFile(file, "utf8");
10029
- } catch {
10030
- throw new Error(
10031
- `\u9879\u76EE\u672A\u521D\u59CB\u5316\uFF1A\u627E\u4E0D\u5230 ${file}
10032
- \u4E0B\u4E00\u6B65\uFF1Ahcm delivery init`
10033
- );
10034
- }
10035
- if (!args.set) {
10036
- const current = deliveryModeForEnvironment(content, environment);
10037
- process.stdout.write(
10038
- formatObject22(
10039
- {
10040
- project: root,
10041
- projectFile: file,
10042
- environment,
10043
- deliveryMode: current,
10044
- canExecuteR2: current === "controlled",
10045
- ...current === "plan-only" ? { note: "plan-only \u53EA\u51FA\u8BA1\u5212\u4E0D\u6267\u884C\uFF1Bexecute \u4F1A\u62D2\u7EDD R2 \u8BA1\u5212" } : current === null ? {
10046
- note: `\u73AF\u5883 ${environment} \u5C1A\u672A\u767B\u8BB0\u4EA4\u4ED8\u6A21\u5F0F\uFF1Bfail-closed\u3002\u5148\u6267\u884C hcm delivery mode --env ${environment} --set plan-only`
10047
- } : {}
10048
- },
10049
- { format: args.output ?? "json" }
10050
- ) + "\n"
10051
- );
10052
- process.exitCode = 0;
10053
- return;
10054
- }
10055
- const next = args.set;
10056
- if (!DELIVERY_MODES.includes(next)) {
10057
- throw new Error(`--set \u53EA\u63A5\u53D7 ${DELIVERY_MODES.join(" | ")}\uFF0C\u6536\u5230 "${args.set}"`);
10058
- }
10059
- const receipt = await setDeliveryModeWithReceipt({
10060
- project: root,
10061
- environment,
10062
- mode: next,
10063
- approvedBy: args.approvedBy,
10064
- reason: args.reason
10065
- });
10066
- process.stdout.write(
10067
- formatObject22(receipt, { format: args.output ?? "json" }) + "\n"
10068
- );
10069
- process.exitCode = 0;
10070
- return;
10071
- } catch (e) {
10072
- exitWithError(e);
10073
- process.exit(1);
10074
- }
10075
- }
10076
- function requireDeliveryModeEnvironment(envFlag) {
10077
- const environment = envFlag?.trim();
10078
- if (!environment) {
10079
- throw new Error(
10080
- "hcm delivery mode \u5FC5\u987B\u663E\u5F0F\u4F20 --env <\u73AF\u5883\u522B\u540D>\uFF1B\u9879\u76EE\u4EA4\u4ED8\u6A21\u5F0F\u4E0D\u7EE7\u627F\u5168\u5C40 activeEnv\uFF0C\u907F\u514D\u67E5\u770B\u6216\u4FEE\u6539\u9519\u8BEF\u73AF\u5883"
10081
- );
10082
- }
10083
- return environment;
10084
- }
10085
- async function resolveDeliveryEnvironment(envFlag) {
10086
- const global = await loadGlobalConfig9();
10087
- const environment = resolveActiveEnv5({ envFlag }, process.env, global);
10088
- if (!environment.trim()) throw new Error("\u65E0\u6CD5\u89E3\u6790\u76EE\u6807\u73AF\u5883\uFF1B\u8BF7\u4F20 --env <\u73AF\u5883\u522B\u540D>");
10089
- return environment;
10090
- }
10091
-
10092
- // src/commands/delivery-doctor.ts
10093
- init_auth_guard();
10094
- init_exit();
10095
- import {
10096
- HcmClient as HcmClient21,
10097
- fetchReconIdentity,
10098
- formatObject as formatObject23,
10099
- fromAxiosError as fromAxiosError21,
10100
- httpProbe,
10101
- runDoctor
10102
- } from "@hcmai/sdk";
10103
- var DEFAULT_CAPABILITIES = "default";
10104
- function render2(report) {
10105
- const lines = [];
10106
- for (const c of report.checks) {
10107
- lines.push(`${c.ok ? "\u2705" : "\u274C"} ${c.anchor.padEnd(13)} ${c.detail}`);
10108
- }
10109
- lines.push("");
10110
- lines.push(
10111
- report.ok ? "\u56DB\u6761\u951A\u70B9\u5168\u7EFF\uFF1A\u53EF\u4EE5\u5F00\u59CB recon\u3002" : "\u6709\u951A\u70B9\u6CA1\u8FC7\u2014\u2014\u5148\u6309\u4E0A\u9762\u5404\u6761\u7684\u4E0B\u4E00\u6B65\u5904\u7406\uFF0C\u4E0D\u8981\u5728\u8FD9\u4E2A\u72B6\u6001\u4E0A\u722C\u57FA\u7EBF\u3002"
10112
- );
10113
- return lines.join("\n");
10114
- }
10115
- async function deliveryDoctorCommand(args) {
10116
- try {
10117
- const ctx = await getActiveAuthContextFromCli(args);
10118
- const client3 = HcmClient21.fromAuthContext(ctx);
10119
- const probe2 = httpProbe(client3.raw(), args.capabilities ?? DEFAULT_CAPABILITIES);
10120
- const identity2 = await fetchReconIdentity(probe2, ctx.tenantId);
10121
- const report = await runDoctor(probe2, identity2);
10122
- const fmt = args.output ?? "json";
10123
- if (fmt !== "json") process.stdout.write(render2(report) + "\n");
10124
- process.stdout.write(formatObject23(report, { format: fmt }) + "\n");
10125
- process.exitCode = report.ok ? 0 : 1;
10126
- return;
10127
- } catch (e) {
10128
- const err = e;
10129
- if (err?.isAxiosError) exitWithError(fromAxiosError21(err, args.env));
10130
- exitWithError(e);
10131
- process.exit(1);
10132
- }
10133
- }
10134
-
10135
- // src/commands/chiron-init.ts
10136
- init_auth_guard();
10137
- init_exit();
10138
- import { promises as fs11 } from "fs";
10139
- import path11 from "path";
10140
- import {
10141
- CliError as CliError21,
10142
- CliErrorCode as CliErrorCode20,
10143
- HcmClient as HcmClient22,
10144
- fetchReconIdentity as fetchReconIdentity2,
10145
- formatObject as formatObject24,
10146
- httpProbe as httpProbe2,
10147
- isTempEnv as isTempEnv3,
10148
- listIdentities as listIdentities5,
10149
- loadEnv as loadEnv11,
10150
- loadGlobalConfig as loadGlobalConfig11
10151
- } from "@hcmai/sdk";
10152
-
10153
9896
  // src/commands/chiron-project.ts
10154
- import { promises as fs10 } from "fs";
9897
+ import { promises as fs11 } from "fs";
10155
9898
  import os5 from "os";
10156
9899
  import path10 from "path";
10157
9900
  import { spawnSync } from "child_process";
10158
- import { hcmConfigDir, listEnvs as listEnvs3, listIdentities as listIdentities4, loadEnv as loadEnv10, loadGlobalConfig as loadGlobalConfig10 } from "@hcmai/sdk";
9901
+ import { hcmConfigDir, listEnvs as listEnvs3, listIdentities as listIdentities4, loadEnv as loadEnv9, loadGlobalConfig as loadGlobalConfig9 } from "@hcmai/sdk";
10159
9902
 
10160
9903
  // src/jira/client.ts
10161
9904
  import { execFileSync } from "child_process";
10162
- import { promises as fs9 } from "fs";
9905
+ import { promises as fs10 } from "fs";
10163
9906
  import os4 from "os";
10164
9907
  import path9 from "path";
10165
- var JIRA_BASE = (process.env.JIRA_BASE || "https://jira.hcmcloud.cn").replace(/\/+$/, "");
10166
- var JIRA_PROJECT = process.env.JIRA_PROJECT || "HCMNX";
10167
- var JIRA_KEYCHAIN = process.env.JIRA_KEYCHAIN_SERVICE || "jira-hcmcloud";
9908
+
9909
+ // src/internal-endpoints.ts
9910
+ var env = (key2, fallback) => {
9911
+ const v = process.env[key2];
9912
+ return v && v.trim() ? v.trim() : fallback;
9913
+ };
9914
+ var trimSlash = (u) => u.replace(/\/+$/, "");
9915
+ var JIRA_BASE = trimSlash(env("JIRA_BASE", "https://jira.hcmcloud.cn"));
9916
+ var JIRA_PROJECT = env("JIRA_PROJECT", "HCMNX");
9917
+ var JIRA_KEYCHAIN = env("JIRA_KEYCHAIN_SERVICE", "jira-hcmcloud");
9918
+ var CNB_ORIGIN = trimSlash(env("HCM_CNB_ORIGIN", "https://cnb.cool"));
9919
+ var CASES_REPO_SLUG = env("HCM_CASES_REPO", "hcm/chiron-cases");
9920
+ var CASES_REPO_URL = `${CNB_ORIGIN}/${CASES_REPO_SLUG}.git`;
9921
+ var repoIssueUrl = (repo, number) => `${CNB_ORIGIN}/${repo}/-/issues/${number}`;
9922
+ var CNB_FAVICON_URL = `${CNB_ORIGIN}/favicon.ico`;
9923
+
9924
+ // src/jira/client.ts
10168
9925
  var JIRA_TOKEN_FILE = () => process.env.JIRA_TOKEN_FILE || path9.join(os4.homedir(), ".config", "hcm", "jira-token");
10169
9926
  async function jiraTokenSource() {
10170
9927
  if (process.env.JIRA_TOKEN?.trim()) return { token: process.env.JIRA_TOKEN.trim(), from: "\u73AF\u5883\u53D8\u91CF JIRA_TOKEN" };
10171
9928
  const file = JIRA_TOKEN_FILE();
10172
9929
  try {
10173
- const stat = await fs9.stat(file);
10174
- const value = (await fs9.readFile(file, "utf8")).trim();
9930
+ const stat = await fs10.stat(file);
9931
+ const value = (await fs10.readFile(file, "utf8")).trim();
10175
9932
  if (value) {
10176
9933
  if (stat.mode & 63) process.stderr.write(`[jira] \u8B66\u544A\uFF1A${file} \u5BF9\u5176\u4ED6\u7528\u6237\u53EF\u8BFB\uFF08chmod 600 \u6536\u7D27\uFF09
10177
9934
  `);
@@ -10328,7 +10085,7 @@ var JiraClient = class {
10328
10085
  body: {
10329
10086
  globalId: url,
10330
10087
  relationship,
10331
- object: { url, title, icon: { url16x16: "https://cnb.cool/favicon.ico", title: "cnb" } }
10088
+ object: { url, title, icon: { url16x16: CNB_FAVICON_URL, title: "cnb" } }
10332
10089
  }
10333
10090
  });
10334
10091
  }
@@ -10352,7 +10109,6 @@ async function createJiraClient(opts = {}) {
10352
10109
  // src/commands/chiron-project.ts
10353
10110
  var ENV_FILE = "env.yaml";
10354
10111
  var SKILLS_DIR = "hcm-skills";
10355
- var CASES_REPO_URL = "https://cnb.cool/hcm/chiron-cases.git";
10356
10112
  var CASES_MCP_NAME = "chiron-cases";
10357
10113
  var CHIRON_PROJECT_DIRECTORIES = [
10358
10114
  "work",
@@ -10364,13 +10120,13 @@ var CHIRON_PROJECT_DIRECTORIES = [
10364
10120
  "gaps",
10365
10121
  "customer-docs"
10366
10122
  ];
10367
- function renderEnvYaml(env2) {
10123
+ function renderEnvYaml(env3) {
10368
10124
  return [
10369
10125
  "# \u9879\u76EE\u73AF\u5883\uFF08hcm chiron init \u751F\u6210\uFF0C\u968F\u4ED3\u5E93\u63D0\u4EA4\uFF1B\u4E0D\u653E\u8EAB\u4EFD\u3001\u4E0D\u653E\u51ED\u636E\uFF09",
10370
10126
  "# \u767B\u5F55\uFF1Ahcm login <endpoint> --code <\u914D\u5BF9\u7801> \u6838\u5BF9\uFF1Ahcm chiron doctor",
10371
- `endpoint: ${JSON.stringify(env2.endpoint)}`,
10372
- `frontend: ${JSON.stringify(env2.frontend)}`,
10373
- `tenant: ${JSON.stringify(env2.tenant)}`,
10127
+ `endpoint: ${JSON.stringify(env3.endpoint)}`,
10128
+ `frontend: ${JSON.stringify(env3.frontend)}`,
10129
+ `tenant: ${JSON.stringify(env3.tenant)}`,
10374
10130
  ""
10375
10131
  ].join("\n");
10376
10132
  }
@@ -10415,12 +10171,12 @@ async function findEnvByEndpoint(endpoint, tenant2) {
10415
10171
  const wanted = normalizeOrigin(endpoint);
10416
10172
  const matches2 = [];
10417
10173
  for (const name of await listEnvs3().catch(() => [])) {
10418
- const config2 = await loadEnv10(name).catch(() => null);
10174
+ const config2 = await loadEnv9(name).catch(() => null);
10419
10175
  if (!config2 || normalizeOrigin(config2.endpoint) !== wanted) continue;
10420
10176
  matches2.push({ name, config: config2, hasIdentity: (await listIdentities4(name).catch(() => [])).length > 0 });
10421
10177
  }
10422
10178
  if (matches2.length === 0) return null;
10423
- const active = (await loadGlobalConfig10().catch(() => null))?.activeEnv;
10179
+ const active = (await loadGlobalConfig9().catch(() => null))?.activeEnv;
10424
10180
  const usable = matches2.filter((m) => m.hasIdentity);
10425
10181
  const pick2 = usable.find((m) => m.name === active) ?? (tenant2 ? usable.find((m) => (m.config.tenantId ?? "1") === tenant2) : void 0) ?? usable[0] ?? matches2.find((m) => m.name === active) ?? matches2[0];
10426
10182
  return { name: pick2.name, config: pick2.config };
@@ -10455,7 +10211,7 @@ function codexConfigFile() {
10455
10211
  }
10456
10212
  function renderCodexMcpSection(repo, envName, binPath = process.env.PATH ?? "") {
10457
10213
  const server = path10.join(repo, "mcp", "server.mjs");
10458
- const env2 = [
10214
+ const env3 = [
10459
10215
  `CASES_REPO = ${JSON.stringify(repo)}`,
10460
10216
  `HCM_ENV = ${JSON.stringify(envName)}`,
10461
10217
  ...binPath ? [`PATH = ${JSON.stringify(binPath)}`] : []
@@ -10464,7 +10220,7 @@ function renderCodexMcpSection(repo, envName, binPath = process.env.PATH ?? "")
10464
10220
  `[mcp_servers.${CASES_MCP_NAME}]`,
10465
10221
  'command = "node"',
10466
10222
  `args = [${JSON.stringify(server)}]`,
10467
- `env = { ${env2} }`,
10223
+ `env = { ${env3} }`,
10468
10224
  ""
10469
10225
  ].join("\n");
10470
10226
  }
@@ -10523,7 +10279,7 @@ async function ensureCaseLibrary(envName, deps = defaultCaseLibraryDeps, paths =
10523
10279
  status.step = pull.status === 0 ? "updated" : "present";
10524
10280
  if (pull.status !== 0) status.reason = `\u66F4\u65B0\u5931\u8D25\uFF0C\u6CBF\u7528\u672C\u5730\u7248\u672C\uFF1A${firstLine(pull.stderr, pull.error)}`;
10525
10281
  } else {
10526
- await fs10.mkdir(path10.dirname(repo), { recursive: true });
10282
+ await fs11.mkdir(path10.dirname(repo), { recursive: true });
10527
10283
  const clone = deps.git(["clone", "--depth", "1", "--quiet", CASES_REPO_URL, repo]);
10528
10284
  if (clone.status !== 0) {
10529
10285
  status.step = "clone-failed";
@@ -10547,10 +10303,10 @@ async function ensureCaseLibrary(envName, deps = defaultCaseLibraryDeps, paths =
10547
10303
  }
10548
10304
  }
10549
10305
  status.serverInstalled = true;
10550
- await fs10.mkdir(path10.dirname(codexConfig), { recursive: true });
10551
- const existing = await fs10.readFile(codexConfig, "utf8").catch(() => "");
10306
+ await fs11.mkdir(path10.dirname(codexConfig), { recursive: true });
10307
+ const existing = await fs11.readFile(codexConfig, "utf8").catch(() => "");
10552
10308
  const next = mergeCodexMcpConfig(existing, renderCodexMcpSection(repo, envName));
10553
- if (next !== existing) await fs10.writeFile(codexConfig, next, "utf8");
10309
+ if (next !== existing) await fs11.writeFile(codexConfig, next, "utf8");
10554
10310
  status.codexWired = true;
10555
10311
  status.ok = true;
10556
10312
  return status;
@@ -10560,7 +10316,7 @@ async function inspectCaseLibrary(paths = {}) {
10560
10316
  const codexConfig = paths.codexConfig ?? codexConfigFile();
10561
10317
  const cloned = await exists2(path10.join(repo, ".git"));
10562
10318
  const serverInstalled = cloned && await exists2(path10.join(repo, "mcp", "server.mjs")) && await exists2(path10.join(repo, "mcp", "node_modules", "@modelcontextprotocol"));
10563
- const codexWired = codexConfigHasCases(await fs10.readFile(codexConfig, "utf8").catch(() => ""));
10319
+ const codexWired = codexConfigHasCases(await fs11.readFile(codexConfig, "utf8").catch(() => ""));
10564
10320
  return { repo, cloned, serverInstalled, codexWired };
10565
10321
  }
10566
10322
  function firstLine(stderr, error) {
@@ -10602,7 +10358,7 @@ async function inspectJira() {
10602
10358
  }
10603
10359
  async function exists2(file) {
10604
10360
  try {
10605
- await fs10.access(file);
10361
+ await fs11.access(file);
10606
10362
  return true;
10607
10363
  } catch {
10608
10364
  return false;
@@ -10612,8 +10368,8 @@ async function exists2(file) {
10612
10368
  // src/commands/chiron-init.ts
10613
10369
  async function probeTokenTenant(envName, requested) {
10614
10370
  const ctx = await getActiveAuthContextFromCli({ env: envName });
10615
- const client3 = HcmClient22.fromAuthContext(ctx);
10616
- const identity2 = await fetchReconIdentity2(httpProbe2(client3.raw(), "default"), requested);
10371
+ const client3 = HcmClient21.fromAuthContext(ctx);
10372
+ const identity2 = await fetchReconIdentity(httpProbe(client3.raw(), "default"), requested);
10617
10373
  return identity2?.tenantId ? String(identity2.tenantId) : void 0;
10618
10374
  }
10619
10375
  var defaultChironInitDeps = {
@@ -10639,56 +10395,56 @@ var defaultChironInitDeps = {
10639
10395
  caseLibrary: (envName) => ensureCaseLibrary(envName)
10640
10396
  };
10641
10397
  async function resolveLoggedInEnv() {
10642
- const g = await loadGlobalConfig11();
10398
+ const g = await loadGlobalConfig10();
10643
10399
  const name = g.activeEnv;
10644
10400
  const loginHint = "hcm login https://<\u4F60\u7684 HCM \u5730\u5740> --code <\u914D\u5BF9\u7801>";
10645
10401
  if (!name) {
10646
- throw new CliError21({
10647
- code: CliErrorCode20.ENV_NOT_FOUND,
10402
+ throw new CliError22({
10403
+ code: CliErrorCode21.ENV_NOT_FOUND,
10648
10404
  message: `\u8FD8\u6CA1\u767B\u5F55\u4EFB\u4F55\u73AF\u5883\u3002\u5148\u6267\u884C\uFF1A${loginHint}`
10649
10405
  });
10650
10406
  }
10651
- const config2 = await loadEnv11(name).catch(() => null);
10407
+ const config2 = await loadEnv10(name).catch(() => null);
10652
10408
  if (!config2?.endpoint) {
10653
- throw new CliError21({
10654
- code: CliErrorCode20.ENV_NOT_FOUND,
10409
+ throw new CliError22({
10410
+ code: CliErrorCode21.ENV_NOT_FOUND,
10655
10411
  message: `\u5F53\u524D\u73AF\u5883 '${name}' \u6CA1\u6709 endpoint\u3002\u5148\u6267\u884C\uFF1A${loginHint}`
10656
10412
  });
10657
10413
  }
10658
10414
  const identities = await listIdentities5(name).catch(() => []);
10659
10415
  if (identities.length === 0) {
10660
- throw new CliError21({
10661
- code: CliErrorCode20.IDENTITY_NOT_FOUND,
10416
+ throw new CliError22({
10417
+ code: CliErrorCode21.IDENTITY_NOT_FOUND,
10662
10418
  message: `\u73AF\u5883 '${name}'\uFF08${config2.endpoint}\uFF09\u8FD8\u6CA1\u6709\u767B\u5F55\u8EAB\u4EFD\u3002\u5148\u6267\u884C\uFF1Ahcm login ${config2.endpoint} --code <\u914D\u5BF9\u7801>`
10663
10419
  });
10664
10420
  }
10665
10421
  const identity2 = config2.defaultIdentity && identities.includes(config2.defaultIdentity) ? config2.defaultIdentity : identities[0];
10666
10422
  return { name, env: projectEnvFromConfig(config2), identity: identity2 };
10667
10423
  }
10668
- async function scaffoldChironProject(root, env2, envName) {
10424
+ async function scaffoldChironProject(root, env3, envName) {
10669
10425
  const result = { created: [], updated: [], preserved: [] };
10670
10426
  const envFile = path11.join(root, ENV_FILE);
10671
- const existing = await fs11.readFile(envFile, "utf8").catch(() => null);
10427
+ const existing = await fs12.readFile(envFile, "utf8").catch(() => null);
10672
10428
  if (existing !== null) {
10673
10429
  const recorded = parseEnvYaml(existing);
10674
- if (recorded.endpoint !== env2.endpoint) {
10675
- throw new CliError21({
10676
- code: CliErrorCode20.INVALID_ARGUMENT,
10677
- message: `${ENV_FILE} \u6307\u5411 ${recorded.endpoint}\uFF0C\u800C\u4F60\u5F53\u524D\u767B\u5F55\u7684\u662F ${env2.endpoint}\uFF08env '${envName}'\uFF09\u3002
10430
+ if (recorded.endpoint !== env3.endpoint) {
10431
+ throw new CliError22({
10432
+ code: CliErrorCode21.INVALID_ARGUMENT,
10433
+ message: `${ENV_FILE} \u6307\u5411 ${recorded.endpoint}\uFF0C\u800C\u4F60\u5F53\u524D\u767B\u5F55\u7684\u662F ${env3.endpoint}\uFF08env '${envName}'\uFF09\u3002
10678
10434
  \u8981\u7528\u8FD9\u4E2A\u9879\u76EE\u7684\u73AF\u5883\uFF1Ahcm login ${recorded.endpoint} --code <\u914D\u5BF9\u7801>\uFF0C\u518D\u91CD\u8DD1 hcm chiron init
10679
10435
  \u8981\u628A\u9879\u76EE\u6539\u5230\u4F60\u767B\u5F55\u7684\u73AF\u5883\uFF1A\u5220\u6389 ${ENV_FILE} \u540E\u91CD\u8DD1\uFF08\u8FD9\u4F1A\u5F71\u54CD\u6240\u6709\u534F\u4F5C\u8005\uFF0C\u5148\u8DDF\u8D1F\u8D23\u4EBA\u786E\u8BA4\uFF09`
10680
10436
  });
10681
10437
  }
10682
- if (recorded.tenant !== env2.tenant) {
10683
- throw new CliError21({
10684
- code: CliErrorCode20.INVALID_ARGUMENT,
10685
- message: `${ENV_FILE} \u662F\u79DF\u6237 ${recorded.tenant}\uFF0C\u800C\u4F60\u767B\u5F55\u7684\u8EAB\u4EFD\u5C5E\u4E8E\u79DF\u6237 ${env2.tenant}\u3002
10686
- \u7528\u9879\u76EE\u79DF\u6237\u7684\u914D\u5BF9\u7801\u91CD\u65B0\u767B\u5F55\uFF1Ahcm login ${env2.endpoint} --code <\u914D\u5BF9\u7801>\uFF0C\u518D\u91CD\u8DD1 hcm chiron init`
10438
+ if (recorded.tenant !== env3.tenant) {
10439
+ throw new CliError22({
10440
+ code: CliErrorCode21.INVALID_ARGUMENT,
10441
+ message: `${ENV_FILE} \u662F\u79DF\u6237 ${recorded.tenant}\uFF0C\u800C\u4F60\u767B\u5F55\u7684\u8EAB\u4EFD\u5C5E\u4E8E\u79DF\u6237 ${env3.tenant}\u3002
10442
+ \u7528\u9879\u76EE\u79DF\u6237\u7684\u914D\u5BF9\u7801\u91CD\u65B0\u767B\u5F55\uFF1Ahcm login ${env3.endpoint} --code <\u914D\u5BF9\u7801>\uFF0C\u518D\u91CD\u8DD1 hcm chiron init`
10687
10443
  });
10688
10444
  }
10689
10445
  result.preserved.push(ENV_FILE);
10690
10446
  } else {
10691
- await fs11.writeFile(envFile, renderEnvYaml(env2), { encoding: "utf8", mode: 420, flag: "wx" });
10447
+ await fs12.writeFile(envFile, renderEnvYaml(env3), { encoding: "utf8", mode: 420, flag: "wx" });
10692
10448
  result.created.push(ENV_FILE);
10693
10449
  }
10694
10450
  for (const directory of CHIRON_PROJECT_DIRECTORIES) {
@@ -10706,7 +10462,7 @@ async function scaffoldChironProject(root, env2, envName) {
10706
10462
  );
10707
10463
  const pageAcceptanceFile = path11.join(root, "page-acceptance.sh");
10708
10464
  const created = await writeIfAbsent(pageAcceptanceFile, renderPageAcceptanceSh("evidence"), result, "page-acceptance.sh", 493);
10709
- if (created) await fs11.chmod(pageAcceptanceFile, 493);
10465
+ if (created) await fs12.chmod(pageAcceptanceFile, 493);
10710
10466
  await mergeManagedFile(path11.join(root, "AGENTS.md"), mergeChironAgentInstructions, result, "AGENTS.md");
10711
10467
  await mergeManagedFile(path11.join(root, "CLAUDE.md"), mergeChironAgentInstructions, result, "CLAUDE.md");
10712
10468
  await mergeManagedFile(path11.join(root, ".gitignore"), mergeDeliveryGitignore, result, ".gitignore");
@@ -10714,23 +10470,23 @@ async function scaffoldChironProject(root, env2, envName) {
10714
10470
  }
10715
10471
  async function runChironInit(args, deps = defaultChironInitDeps) {
10716
10472
  const root = path11.resolve(args.project ?? ".");
10717
- const { name, env: env2, identity: identity2 } = await resolveLoggedInEnv();
10473
+ const { name, env: env3, identity: identity2 } = await resolveLoggedInEnv();
10718
10474
  if (isTempEnv3(name)) {
10719
- throw new CliError21({
10720
- code: CliErrorCode20.INVALID_ARGUMENT,
10721
- message: `\u5F53\u524D\u662F\u4E34\u65F6\u73AF\u5883\uFF08${env2.endpoint}\uFF09\uFF0C\u8FD8\u6CA1\u6709\u540D\u5B57\u3002\u9879\u76EE\u8981\u7ED1\u4E00\u4E2A\u7A33\u5B9A\u7684 env\uFF0C\u5426\u5219\u4E0B\u4E00\u6B21 hcm login --code \u8986\u76D6\u5B83\u4E4B\u540E\uFF0C\u9879\u76EE\u4ED3\u8BB0\u7684\u73AF\u5883\u5C31\u5BF9\u4E0D\u4E0A\u4E86\u3002`,
10475
+ throw new CliError22({
10476
+ code: CliErrorCode21.INVALID_ARGUMENT,
10477
+ message: `\u5F53\u524D\u662F\u4E34\u65F6\u73AF\u5883\uFF08${env3.endpoint}\uFF09\uFF0C\u8FD8\u6CA1\u6709\u540D\u5B57\u3002\u9879\u76EE\u8981\u7ED1\u4E00\u4E2A\u7A33\u5B9A\u7684 env\uFF0C\u5426\u5219\u4E0B\u4E00\u6B21 hcm login --code \u8986\u76D6\u5B83\u4E4B\u540E\uFF0C\u9879\u76EE\u4ED3\u8BB0\u7684\u73AF\u5883\u5C31\u5BF9\u4E0D\u4E0A\u4E86\u3002`,
10722
10478
  context: { nextStep: `\u5148\u7ED9\u5B83\u8D77\u4E2A\u540D\u5B57\uFF1Ahcm env save <name>\uFF0C\u7136\u540E\u91CD\u8DD1 hcm chiron init` }
10723
10479
  });
10724
10480
  }
10725
10481
  const say = (line) => process.stderr.write(`[chiron init] ${line}
10726
10482
  `);
10727
- const actual = await deps.tokenTenant(name, env2.tenant);
10728
- if (actual && actual !== env2.tenant) {
10729
- say(`env ${name} \u8BB0\u7684\u79DF\u6237\u662F ${env2.tenant}\uFF0C\u4F46\u4F60\u7684\u767B\u5F55\u8EAB\u4EFD\u5C5E\u4E8E\u79DF\u6237 ${actual}\uFF0C\u6309 ${actual} \u5199 ${ENV_FILE}`);
10730
- env2.tenant = actual;
10483
+ const actual = await deps.tokenTenant(name, env3.tenant);
10484
+ if (actual && actual !== env3.tenant) {
10485
+ say(`env ${name} \u8BB0\u7684\u79DF\u6237\u662F ${env3.tenant}\uFF0C\u4F46\u4F60\u7684\u767B\u5F55\u8EAB\u4EFD\u5C5E\u4E8E\u79DF\u6237 ${actual}\uFF0C\u6309 ${actual} \u5199 ${ENV_FILE}`);
10486
+ env3.tenant = actual;
10731
10487
  }
10732
- say(`\u73AF\u5883 ${name} \xB7 ${env2.endpoint} \xB7 \u79DF\u6237 ${env2.tenant} \xB7 \u8EAB\u4EFD ${identity2}`);
10733
- const scaffold = await scaffoldChironProject(root, env2, name);
10488
+ say(`\u73AF\u5883 ${name} \xB7 ${env3.endpoint} \xB7 \u79DF\u6237 ${env3.tenant} \xB7 \u8EAB\u4EFD ${identity2}`);
10489
+ const scaffold = await scaffoldChironProject(root, env3, name);
10734
10490
  say(`\u9AA8\u67B6\uFF1A\u65B0\u5EFA ${scaffold.created.length} \xB7 \u66F4\u65B0 ${scaffold.updated.length} \xB7 \u4FDD\u7559 ${scaffold.preserved.length}`);
10735
10491
  let skills2 = "skipped";
10736
10492
  if (!args.skipSkills) {
@@ -10748,9 +10504,9 @@ async function runChironInit(args, deps = defaultChironInitDeps) {
10748
10504
  return {
10749
10505
  project: root,
10750
10506
  env: name,
10751
- endpoint: env2.endpoint,
10752
- frontend: env2.frontend,
10753
- tenant: env2.tenant,
10507
+ endpoint: env3.endpoint,
10508
+ frontend: env3.frontend,
10509
+ tenant: env3.tenant,
10754
10510
  identity: identity2,
10755
10511
  scaffold,
10756
10512
  skills: skills2,
@@ -10763,7 +10519,7 @@ async function chironInitCommand(args, deps) {
10763
10519
  const result = await runChironInit(args, deps);
10764
10520
  const fmt = args.output ?? "table";
10765
10521
  if (fmt === "json" || fmt === "yaml") {
10766
- process.stdout.write(formatObject24(result, { format: fmt }) + "\n");
10522
+ process.stdout.write(formatObject23(result, { format: fmt }) + "\n");
10767
10523
  } else {
10768
10524
  process.stdout.write(
10769
10525
  [
@@ -10784,23 +10540,23 @@ async function chironInitCommand(args, deps) {
10784
10540
  // src/commands/chiron-doctor.ts
10785
10541
  init_auth_guard();
10786
10542
  init_exit();
10787
- import { promises as fs12 } from "fs";
10543
+ import { promises as fs13 } from "fs";
10788
10544
  import path12 from "path";
10789
10545
  import {
10790
- HcmClient as HcmClient23,
10791
- CliError as CliError22,
10792
- fetchReconIdentity as fetchReconIdentity3,
10793
- formatObject as formatObject25,
10794
- httpProbe as httpProbe3,
10795
- runDoctor as runDoctor2
10546
+ HcmClient as HcmClient22,
10547
+ CliError as CliError23,
10548
+ fetchReconIdentity as fetchReconIdentity2,
10549
+ formatObject as formatObject24,
10550
+ httpProbe as httpProbe2,
10551
+ runDoctor
10796
10552
  } from "@hcmai/sdk";
10797
10553
  var defaultDeps = {
10798
- anchors: async (envName, tenant2) => {
10799
- const ctx = await getActiveAuthContextFromCli({ env: envName });
10800
- const client3 = HcmClient23.fromAuthContext(ctx);
10801
- const probe2 = httpProbe3(client3.raw(), "default");
10802
- const identity2 = await fetchReconIdentity3(probe2, tenant2);
10803
- return { report: await runDoctor2(probe2, identity2), tokenTenant: identity2?.tenantId ? String(identity2.tenantId) : void 0 };
10554
+ anchors: async (envName, tenant2, as) => {
10555
+ const ctx = await getActiveAuthContextFromCli({ env: envName, as });
10556
+ const client3 = HcmClient22.fromAuthContext(ctx);
10557
+ const probe2 = httpProbe2(client3.raw(), "default");
10558
+ const identity2 = await fetchReconIdentity2(probe2, tenant2);
10559
+ return { report: await runDoctor(probe2, identity2), tokenTenant: identity2?.tenantId ? String(identity2.tenantId) : void 0 };
10804
10560
  },
10805
10561
  fixSkills: (root, envName) => defaultChironInitDeps.installSkills(root, envName),
10806
10562
  fixCases: async (envName) => {
@@ -10812,7 +10568,7 @@ var defaultDeps = {
10812
10568
  async function runChironDoctor(args, deps = defaultDeps) {
10813
10569
  const root = path12.resolve(args.project ?? ".");
10814
10570
  const report = { ok: false, project: root, env: null, envName: null, lines: [] };
10815
- const envText = await fs12.readFile(path12.join(root, ENV_FILE), "utf8").catch(() => null);
10571
+ const envText = await fs13.readFile(path12.join(root, ENV_FILE), "utf8").catch(() => null);
10816
10572
  if (envText === null) {
10817
10573
  report.lines.push({
10818
10574
  item: "\u767B\u5F55",
@@ -10822,31 +10578,32 @@ async function runChironDoctor(args, deps = defaultDeps) {
10822
10578
  });
10823
10579
  return finish(report);
10824
10580
  }
10825
- let env2;
10581
+ let env3;
10826
10582
  try {
10827
- env2 = parseEnvYaml(envText);
10583
+ env3 = parseEnvYaml(envText);
10828
10584
  } catch (e) {
10829
10585
  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}` });
10830
10586
  return finish(report);
10831
10587
  }
10832
- report.env = env2;
10833
- const found = await findEnvByEndpoint(env2.endpoint, env2.tenant);
10834
- const loginCmd = `hcm login ${env2.endpoint} --code <\u914D\u5BF9\u7801>`;
10588
+ report.env = env3;
10589
+ const found = await findEnvByEndpoint(env3.endpoint, env3.tenant);
10590
+ const loginCmd = `hcm login ${env3.endpoint} --code <\u914D\u5BF9\u7801>`;
10835
10591
  if (!found) {
10836
- report.lines.push({ item: "\u767B\u5F55", verdict: "fail", detail: `\u672C\u673A\u6CA1\u6709\u767B\u5F55\u8FC7 ${env2.endpoint}`, nextStep: loginCmd });
10592
+ report.lines.push({ item: "\u767B\u5F55", verdict: "fail", detail: `\u672C\u673A\u6CA1\u6709\u767B\u5F55\u8FC7 ${env3.endpoint}`, nextStep: loginCmd });
10837
10593
  } else {
10838
10594
  report.envName = found.name;
10839
10595
  try {
10840
- const { report: anchors, tokenTenant } = await deps.anchors(found.name, env2.tenant);
10596
+ const targetEnv = args.env ?? found.name;
10597
+ const { report: anchors, tokenTenant } = await deps.anchors(targetEnv, env3.tenant, args.as);
10841
10598
  report.anchors = anchors;
10842
- const tenantMismatch = tokenTenant && tokenTenant !== env2.tenant;
10599
+ const tenantMismatch = tokenTenant && tokenTenant !== env3.tenant;
10843
10600
  const bad = anchors.checks.filter((c) => !c.ok && !(tenantMismatch && c.anchor === "identity"));
10844
10601
  if (bad.length === 0 && !tenantMismatch) {
10845
10602
  const who = found.config.defaultIdentity ? ` \xB7 ${found.config.defaultIdentity}` : "";
10846
- report.lines.push({ item: "\u767B\u5F55", verdict: "ok", detail: `${found.name} \xB7 ${env2.endpoint} \xB7 \u79DF\u6237 ${env2.tenant}${who}` });
10603
+ report.lines.push({ item: "\u767B\u5F55", verdict: "ok", detail: `${found.name} \xB7 ${env3.endpoint} \xB7 \u79DF\u6237 ${env3.tenant}${who}` });
10847
10604
  } else {
10848
- const parts = [`${found.name} \xB7 ${env2.endpoint}`];
10849
- if (tenantMismatch) parts.push(`\u4F60\u7684\u767B\u5F55\u8EAB\u4EFD\u5C5E\u4E8E\u79DF\u6237 ${tokenTenant}\uFF0C\u9879\u76EE\u662F\u79DF\u6237 ${env2.tenant}`);
10605
+ const parts = [`${found.name} \xB7 ${env3.endpoint}`];
10606
+ if (tenantMismatch) parts.push(`\u4F60\u7684\u767B\u5F55\u8EAB\u4EFD\u5C5E\u4E8E\u79DF\u6237 ${tokenTenant}\uFF0C\u9879\u76EE\u662F\u79DF\u6237 ${env3.tenant}`);
10850
10607
  if (bad.length) parts.push(`\u951A\u70B9\u672A\u8FC7\uFF1A${bad.map((c) => `${c.anchor}\uFF08${c.detail}\uFF09`).join("\u3001")}`);
10851
10608
  report.lines.push({
10852
10609
  item: "\u767B\u5F55",
@@ -10856,16 +10613,16 @@ async function runChironDoctor(args, deps = defaultDeps) {
10856
10613
  });
10857
10614
  }
10858
10615
  } catch (e) {
10859
- const msg = e instanceof CliError22 ? e.message : e.message;
10860
- report.lines.push({ item: "\u767B\u5F55", verdict: "fail", detail: `${found.name} \xB7 ${env2.endpoint}\uFF1A${msg}`, nextStep: loginCmd });
10616
+ const msg = e instanceof CliError23 ? e.message : e.message;
10617
+ report.lines.push({ item: "\u767B\u5F55", verdict: "fail", detail: `${found.name} \xB7 ${env3.endpoint}\uFF1A${msg}`, nextStep: loginCmd });
10861
10618
  }
10862
10619
  }
10863
10620
  const skillsLine = async () => {
10864
10621
  const state = await readSkillsState(path12.join(root, SKILLS_DIR));
10865
10622
  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" };
10866
10623
  const count = Object.keys(state.skills).length;
10867
- if (state.endpoint && normalizeOrigin(state.endpoint) !== env2.endpoint) {
10868
- 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" };
10624
+ if (state.endpoint && normalizeOrigin(state.endpoint) !== env3.endpoint) {
10625
+ return { item: "\u6280\u80FD", verdict: "fail", detail: `${count} \u4E2A\uFF0C\u4F46\u88C5\u81EA ${state.endpoint}\uFF0C\u4E0D\u662F\u9879\u76EE\u73AF\u5883 ${env3.endpoint}`, nextStep: "hcm chiron doctor --fix \u91CD\u88C5" };
10869
10626
  }
10870
10627
  if (state.target !== "codex") {
10871
10628
  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" };
@@ -10916,7 +10673,7 @@ async function chironDoctorCommand(args, deps) {
10916
10673
  try {
10917
10674
  const report = await runChironDoctor(args, deps);
10918
10675
  const fmt = args.output ?? "table";
10919
- if (fmt === "json" || fmt === "yaml") process.stdout.write(formatObject25(report, { format: fmt }) + "\n");
10676
+ if (fmt === "json" || fmt === "yaml") process.stdout.write(formatObject24(report, { format: fmt }) + "\n");
10920
10677
  else process.stdout.write(renderChironDoctor(report) + "\n");
10921
10678
  process.exitCode = report.ok ? 0 : 1;
10922
10679
  } catch (e) {
@@ -10927,10 +10684,10 @@ async function chironDoctorCommand(args, deps) {
10927
10684
  // src/commands/chiron-test.ts
10928
10685
  init_exit();
10929
10686
  import { spawnSync as spawnSync2 } from "child_process";
10930
- import { promises as fs13 } from "fs";
10687
+ import { promises as fs14 } from "fs";
10931
10688
  import path13 from "path";
10932
10689
  import yaml2 from "js-yaml";
10933
- import { formatObject as formatObject26 } from "@hcmai/sdk";
10690
+ import { formatObject as formatObject25 } from "@hcmai/sdk";
10934
10691
 
10935
10692
  // src/commands/xlsx-peek.ts
10936
10693
  import { readFileSync as readFileSync6 } from "fs";
@@ -11129,7 +10886,7 @@ var defaultDeps2 = {
11129
10886
  return { status: r.status, stdout: r.stdout ?? "", stderr: r.stderr ?? "" };
11130
10887
  },
11131
10888
  readXlsx: (file) => xlsxRows(file),
11132
- readText: (file) => fs13.readFile(file, "utf8")
10889
+ readText: (file) => fs14.readFile(file, "utf8")
11133
10890
  };
11134
10891
  async function runCase(spec, root, opts = {}, deps = defaultDeps2) {
11135
10892
  const results = [];
@@ -11214,11 +10971,11 @@ async function runCase(spec, root, opts = {}, deps = defaultDeps2) {
11214
10971
  return results;
11215
10972
  }
11216
10973
  async function loadCases(target) {
11217
- const stat = await fs13.stat(target);
11218
- const files = stat.isDirectory() ? (await fs13.readdir(target)).filter((f) => /\.ya?ml$/.test(f)).sort().map((f) => path13.join(target, f)) : [target];
10974
+ const stat = await fs14.stat(target);
10975
+ const files = stat.isDirectory() ? (await fs14.readdir(target)).filter((f) => /\.ya?ml$/.test(f)).sort().map((f) => path13.join(target, f)) : [target];
11219
10976
  const out = [];
11220
10977
  for (const f of files) {
11221
- const spec = yaml2.load(await fs13.readFile(f, "utf8"));
10978
+ const spec = yaml2.load(await fs14.readFile(f, "utf8"));
11222
10979
  assertUsableSpec(spec, path13.basename(f));
11223
10980
  out.push({ file: f, spec });
11224
10981
  }
@@ -11239,7 +10996,7 @@ async function chironTestCommand(target, args, deps) {
11239
10996
  }
11240
10997
  const fmt = args.output ?? "table";
11241
10998
  if (fmt === "json" || fmt === "yaml") {
11242
- process.stdout.write(formatObject26({ ok: failed2 === 0, failed: failed2, cases: report }, { format: fmt }) + "\n");
10999
+ process.stdout.write(formatObject25({ ok: failed2 === 0, failed: failed2, cases: report }, { format: fmt }) + "\n");
11243
11000
  } else {
11244
11001
  for (const c of report) {
11245
11002
  process.stdout.write(`
@@ -11268,10 +11025,10 @@ ${failed2} \u6761\u6CA1\u8FC7\u2014\u2014\u4E0A\u9762\u6BCF\u6761\u90FD\u5199\u4
11268
11025
  import { readFileSync as readFileSync7 } from "fs";
11269
11026
  import {
11270
11027
  createHttpClient as createHttpClient4,
11271
- formatObject as formatObject27,
11272
- loadEnv as loadEnv12,
11273
- loadGlobalConfig as loadGlobalConfig12,
11274
- resolveActiveEnv as resolveActiveEnv6
11028
+ formatObject as formatObject26,
11029
+ loadEnv as loadEnv11,
11030
+ loadGlobalConfig as loadGlobalConfig11,
11031
+ resolveActiveEnv as resolveActiveEnv5
11275
11032
  } from "@hcmai/sdk";
11276
11033
  init_exit();
11277
11034
 
@@ -11287,7 +11044,6 @@ function linkedRepoRefs(text) {
11287
11044
  }
11288
11045
  return [...out.values()];
11289
11046
  }
11290
- var repoIssueUrl = (repo, number) => `https://cnb.cool/${repo}/-/issues/${number}`;
11291
11047
  function parseCnbIssueOutput(raw) {
11292
11048
  const fields = {};
11293
11049
  let status;
@@ -11373,7 +11129,7 @@ function searchRepoIssues(cnb, repo, keyword, state) {
11373
11129
  return [];
11374
11130
  }
11375
11131
  }
11376
- function parseRef(raw, project, casesSlug = "hcm/chiron-cases") {
11132
+ function parseRef(raw, project, casesSlug = CASES_REPO_SLUG) {
11377
11133
  const r = String(raw ?? "").trim();
11378
11134
  let m = r.match(/^(?:hcm\/)?(?:hcm_nx_)?(core|cli|cloud)#(\d+)$/i);
11379
11135
  if (m) return { kind: "repo", repo: `hcm/hcm_nx_${m[1].toLowerCase()}`, number: m[2] };
@@ -11619,7 +11375,7 @@ async function gapSearch({ client: client3, cnb }, keywords, { includeClosed = t
11619
11375
  const seen = /* @__PURE__ */ new Set();
11620
11376
  return { rows: rows.filter((r) => seen.has(r.id) ? false : (seen.add(r.id), true)), jiraError };
11621
11377
  }
11622
- async function gapStatus({ client: client3, cnb }, ref, casesSlug = "hcm/chiron-cases") {
11378
+ async function gapStatus({ client: client3, cnb }, ref, casesSlug = CASES_REPO_SLUG) {
11623
11379
  const parsed = parseRef(ref, client3.project, casesSlug);
11624
11380
  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`);
11625
11381
  if (parsed.kind === "repo") {
@@ -11657,18 +11413,23 @@ var GAP_PREFIX = "\u7F3A\u53E3\uFF1A";
11657
11413
  var PENDING_STATUS = "\u65B0\u589E";
11658
11414
  var SYNC_MARKER = "\u4EE3\u7801\u5E93\u5DF2\u5173\u95ED\uFF1A";
11659
11415
  var bodyText = (issue, comments, remote = []) => [issue.fields.description ?? "", ...comments.map((c) => c.body ?? ""), ...remote.map((l) => l.object?.url ?? "")].join("\n");
11416
+ var remoteText = (remote) => remote.map((l) => `${l.object?.url ?? ""} ${l.object?.title ?? ""}`).join("\n");
11417
+ var refKeys = (text) => linkedRepoRefs(text).map((l) => `${l.repo}#${l.number}`);
11660
11418
  async function listOpen(client3, { all = false } = {}) {
11661
11419
  const every = await client3.search(`project = ${client3.project} AND resolution = Unresolved ORDER BY created DESC`, { max: 100 });
11662
11420
  const picked = all ? every : every.filter((i) => i.fields.status?.name === PENDING_STATUS);
11421
+ const linked = await Promise.all(picked.map((i) => client3.remoteLinks(i.key).then((r) => refKeys(remoteText(r)))));
11663
11422
  return {
11664
11423
  unresolved: every.length,
11665
- rows: picked.map((i) => ({
11424
+ rows: picked.map((i, n) => ({
11666
11425
  key: i.key,
11667
11426
  status: i.fields.status?.name ?? "?",
11668
11427
  priority: i.fields.priority?.name,
11669
11428
  summary: i.fields.summary ?? "",
11670
11429
  url: client3.browseUrl(i.key),
11671
11430
  reporter: i.fields.reporter?.displayName,
11431
+ assignee: i.fields.assignee?.displayName,
11432
+ linkedRefs: linked[n] ?? [],
11672
11433
  created: String(i.fields.created ?? "").slice(0, 10),
11673
11434
  fromAgent: (i.fields.summary ?? "").startsWith(GAP_PREFIX)
11674
11435
  }))
@@ -11678,7 +11439,11 @@ async function showIssue({ client: client3, cnb }, key2) {
11678
11439
  const issue = await client3.issue(key2);
11679
11440
  const comments = await client3.comments(key2);
11680
11441
  const remoteLinks = await client3.remoteLinks(key2);
11681
- const links = linkedRepoRefs(bodyText(issue, comments, remoteLinks)).map((l) => cnbIssueState(cnb, l.repo, l.number));
11442
+ const inRemote = new Set(refKeys(remoteText(remoteLinks)));
11443
+ const links = linkedRepoRefs(bodyText(issue, comments, remoteLinks)).map((l) => ({
11444
+ ...cnbIssueState(cnb, l.repo, l.number),
11445
+ source: inRemote.has(`${l.repo}#${l.number}`) ? "remote" : "comment"
11446
+ }));
11682
11447
  const transitions = await client3.transitions(key2);
11683
11448
  return { issue, comments, remoteLinks, links, transitions };
11684
11449
  }
@@ -11699,8 +11464,24 @@ async function moveIssue(client3, key2, target, comment) {
11699
11464
  async function toIssue({ client: client3, cnb }, key2, { repo = "hcm/hcm_nx_core", force = false, priority = "P2" } = {}) {
11700
11465
  const issue = await client3.issue(key2);
11701
11466
  const comments = await client3.comments(key2);
11702
- const existing = linkedRepoRefs(bodyText(issue, comments, await client3.remoteLinks(key2)));
11703
- if (existing.length && !force) return { key: key2, existing: existing.map((e) => `${e.repo}#${e.number}`) };
11467
+ const remote = await client3.remoteLinks(key2);
11468
+ const existing = linkedRepoRefs(bodyText(issue, comments, remote));
11469
+ if (existing.length && !force) {
11470
+ const remoteText2 = remote.map((l) => `${l.object?.url ?? ""} ${l.object?.title ?? ""}`).join("\n");
11471
+ const linked = [];
11472
+ const alreadyLinked = [];
11473
+ for (const e of existing) {
11474
+ const ref = `${e.repo}#${e.number}`;
11475
+ const url2 = repoIssueUrl(e.repo, e.number);
11476
+ if (remoteText2.includes(url2) || remoteText2.includes(ref)) {
11477
+ alreadyLinked.push(ref);
11478
+ continue;
11479
+ }
11480
+ await client3.addRemoteLink(key2, url2, `${ref} ${issue.fields.summary ?? ""}`.slice(0, 250));
11481
+ linked.push(ref);
11482
+ }
11483
+ return { key: key2, existing: existing.map((e) => `${e.repo}#${e.number}`), linked, alreadyLinked };
11484
+ }
11704
11485
  const title = `${issue.fields.summary ?? ""}\uFF08Jira ${key2}\uFF09`;
11705
11486
  const body = [
11706
11487
  `> \u6765\u81EA Jira ${key2}\uFF1A${client3.browseUrl(key2)}`,
@@ -11789,15 +11570,18 @@ async function auditIssues(client3) {
11789
11570
  const rows = (await client3.search(`project = ${client3.project} AND resolution = Unresolved ORDER BY created DESC`, { max: 100 })).filter(
11790
11571
  (i) => (i.fields.summary ?? "").startsWith(GAP_PREFIX)
11791
11572
  );
11573
+ const audited = [];
11792
11574
  const bad = [];
11793
11575
  for (const i of rows) {
11794
11576
  const status = i.fields.status?.name ?? "?";
11795
11577
  if (status === PENDING_STATUS) continue;
11578
+ audited.push(i.key);
11796
11579
  const remote = await client3.remoteLinks(i.key);
11797
- const text = bodyText(await client3.issue(i.key), await client3.comments(i.key), remote);
11798
- if (!remote.length && !linkedRepoRefs(text).length) bad.push({ key: i.key, status, url: client3.browseUrl(i.key) });
11580
+ if (refKeys(remoteText(remote)).length) continue;
11581
+ const refs = refKeys(bodyText(await client3.issue(i.key), await client3.comments(i.key), remote));
11582
+ bad.push({ key: i.key, status, url: client3.browseUrl(i.key), kind: refs.length ? "comment-only" : "missing", refs });
11799
11583
  }
11800
- return { checked: rows.length, bad };
11584
+ return { checked: rows.length, audited, bad };
11801
11585
  }
11802
11586
  async function probe(client3) {
11803
11587
  const [info, me, project] = await Promise.all([client3.serverInfo(), client3.myself(), client3.projectInfo()]);
@@ -11822,7 +11606,7 @@ async function triageDeps(deps) {
11822
11606
  return { client: await deps.client(), cnb: deps.cnb };
11823
11607
  }
11824
11608
  function emit4(fmt, data, text) {
11825
- if (fmt === "json" || fmt === "yaml") process.stdout.write(formatObject27(data, { format: fmt }) + "\n");
11609
+ if (fmt === "json" || fmt === "yaml") process.stdout.write(formatObject26(data, { format: fmt }) + "\n");
11826
11610
  else process.stdout.write(text() + "\n");
11827
11611
  }
11828
11612
  function readBody(opts, positional) {
@@ -11860,8 +11644,10 @@ async function jiraOpenCommand(args, deps = defaultDeps3) {
11860
11644
  const r = await listOpen(await deps.client(), { all: !!args.all });
11861
11645
  emit4(args.output, r, () => {
11862
11646
  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`;
11863
- return r.rows.map((i) => `${i.key} [${i.status}${i.priority ? " " + i.priority : ""}]${i.fromAgent ? "" : " \uFF08\u975E agent \u63D0\u5355\uFF09"} ${i.summary}
11864
- ${i.url} \u62A5\u544A\u4EBA ${i.reporter ?? "?"} ${i.created}`).join("\n");
11647
+ return r.rows.map(
11648
+ (i) => `${i.key} [${i.status}${i.priority ? " " + i.priority : ""}]${i.fromAgent ? "" : " \uFF08\u975E agent \u63D0\u5355\uFF09"} ${i.summary}
11649
+ ${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}`
11650
+ ).join("\n");
11865
11651
  });
11866
11652
  });
11867
11653
  }
@@ -11879,7 +11665,8 @@ async function jiraShowCommand(key2, args, deps = defaultDeps3) {
11879
11665
  i.fields.description || "\uFF08\u7A7A\uFF09"
11880
11666
  ];
11881
11667
  for (const c of r.comments) out.push("", `--- \u8BC4\u8BBA ${c.author?.displayName ?? "?"} ${String(c.created ?? "").slice(0, 10)} ---`, c.body ?? "");
11882
- for (const l of r.links) out.push("", `\u5173\u8054\u4EE3\u7801\u5E93 ${describeIssueState(l)}`);
11668
+ for (const l of r.links)
11669
+ 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` : ""}`);
11883
11670
  out.push("", `\u53EF\u7528\u6D41\u8F6C\uFF1A${r.transitions.map((t) => `${t.name}\u2192${t.to?.name}`).join(" / ") || "\uFF08\u65E0\uFF09"}`);
11884
11671
  return out.join("\n");
11885
11672
  });
@@ -11909,7 +11696,12 @@ async function jiraToIssueCommand(key2, args, deps = defaultDeps3) {
11909
11696
  await run(async () => {
11910
11697
  const r = await toIssue(await triageDeps(deps), key2, { repo: args.repo, force: !!args.force });
11911
11698
  emit4(args.output, r, () => {
11912
- if ("existing" in r) return `${r.key} \u5DF2\u5173\u8054 ${r.existing.join("\u3001")}\uFF0C\u4E0D\u91CD\u590D\u5EFA\u3002\u8981\u518D\u5EFA\u52A0 --force`;
11699
+ if ("existing" in r) {
11700
+ const parts = [`${r.key} \u5DF2\u5173\u8054 ${r.existing.join("\u3001")}\uFF0C\u4E0D\u91CD\u590D\u5EFA\u3002\u8981\u518D\u5EFA\u52A0 --force`];
11701
+ 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`);
11702
+ else if (r.alreadyLinked.length) parts.push("\u8FDC\u7A0B\u94FE\u63A5\u5DF2\u9F50\uFF0C\u65E0\u9700\u8865\u6302");
11703
+ return parts.join("\n");
11704
+ }
11913
11705
  const moved = r.moved ? `\uFF0C\u5DF2\u63A8\u8FDB\u5230 ${r.moved}` : r.moveError ? `\uFF0C\u4F46\u6CA1\u80FD\u63A8\u8FDB\u72B6\u6001\uFF1A${r.moveError}` : "";
11914
11706
  return `${r.key} \u2192 ${r.repo}#${r.number} ${r.url}${moved}`;
11915
11707
  });
@@ -11960,8 +11752,17 @@ async function jiraAuditCommand(args, deps = defaultDeps3) {
11960
11752
  const r = await auditIssues(await deps.client());
11961
11753
  emit4(args.output, r, () => {
11962
11754
  if (!r.checked) return "\u9879\u76EE\u91CC\u6CA1\u6709\u672A\u89E3\u51B3\u7684\u7F3A\u53E3\u5355\u3002";
11963
- const lines = r.bad.map((b) => `\u26A0\uFE0F ${b.key} [${b.status}] \u6CA1\u6709\u4EE3\u7801\u5E93\u6761\u76EE\uFF1A${b.url}`);
11964
- lines.push(r.bad.length ? `${r.bad.length} \u6761\u72B6\u6001\u5DF2\u63A8\u8FDB\u5374\u6CA1\u767B\u8BB0\uFF0C\u5148\u8865 to-issue\u3002` : "\u4E00\u81F4\uFF1A\u5DF2\u53D7\u7406\u7684\u5355\u90FD\u6302\u7740\u4EE3\u7801\u5E93\u6761\u76EE\u3002");
11755
+ 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`];
11756
+ for (const b of r.bad) {
11757
+ lines.push(
11758
+ 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(" / ")}
11759
+ ${b.url}
11760
+ \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}
11761
+ \u5148\u5206\u8BCA\uFF1Ahcm jira to-issue ${b.key} --repo hcm/hcm_nx_core`
11762
+ );
11763
+ }
11764
+ if (!r.audited.length) lines.push("\u6CA1\u6709\u5DF2\u53D7\u7406\u7684\u5355\uFF0C\u672C\u8F6E\u4EC0\u4E48\u90FD\u6CA1\u6838\u5230\u3002");
11765
+ 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");
11965
11766
  return lines.join("\n");
11966
11767
  });
11967
11768
  if (r.bad.length) process.exitCode = 1;
@@ -11987,11 +11788,11 @@ async function jiraStatusCommand(ref, args, deps = defaultDeps3) {
11987
11788
  emit4(args.output, r, () => [...r.lines, `\u4E0B\u4E00\u6B65\uFF1A${r.nextStep}`].join("\n"));
11988
11789
  });
11989
11790
  }
11990
- async function fingerprintText(env2) {
11791
+ async function fingerprintText(env3) {
11991
11792
  try {
11992
- const g = await loadGlobalConfig12();
11993
- const name = resolveActiveEnv6({ envFlag: env2 }, process.env, g);
11994
- const cfg = await loadEnv12(name);
11793
+ const g = await loadGlobalConfig11();
11794
+ const name = resolveActiveEnv5({ envFlag: env3 }, process.env, g);
11795
+ const cfg = await loadEnv11(name);
11995
11796
  if (!cfg?.endpoint) return `\u672A\u53D6\u5230\u6307\u7EB9\uFF08env=${name}\uFF1A\u6CA1\u6709 endpoint\uFF09`;
11996
11797
  const http = createHttpClient4({ endpoint: cfg.endpoint.replace(/\/+$/, ""), getAccessToken: async () => null, onRefresh: async () => {
11997
11798
  } });
@@ -12000,7 +11801,7 @@ async function fingerprintText(env2) {
12000
11801
  const commit = info.commit ?? info.gitCommit ?? info.version ?? "?";
12001
11802
  return `backend ${String(commit).slice(0, 12)} \xB7 CLI ${CLI_VERSION} \xB7 env ${name}`;
12002
11803
  } catch (e) {
12003
- return `\u672A\u53D6\u5230\u6307\u7EB9\uFF08env=${env2 ?? "\u672A\u8BBE"}\uFF1B${String(e.message ?? e).split("\n")[0]?.slice(0, 120)}\uFF09`;
11804
+ return `\u672A\u53D6\u5230\u6307\u7EB9\uFF08env=${env3 ?? "\u672A\u8BBE"}\uFF1B${String(e.message ?? e).split("\n")[0]?.slice(0, 120)}\uFF09`;
12004
11805
  }
12005
11806
  }
12006
11807
  async function jiraSubmitCommand(args, deps = defaultDeps3) {
@@ -12025,23 +11826,23 @@ ${r.url}
12025
11826
  init_auth_guard();
12026
11827
  init_exit();
12027
11828
  import {
12028
- HcmClient as HcmClient24,
11829
+ HcmClient as HcmClient23,
12029
11830
  ReconLayout,
12030
11831
  ROUND_EXIT_CODES,
12031
11832
  computeReconSourceKey,
12032
- formatObject as formatObject28,
12033
- fromAxiosError as fromAxiosError22,
12034
- httpProbe as httpProbe4,
11833
+ formatObject as formatObject27,
11834
+ fromAxiosError as fromAxiosError21,
11835
+ httpProbe as httpProbe3,
12035
11836
  inspectRound,
12036
11837
  renderRound,
12037
11838
  runRecon
12038
11839
  } from "@hcmai/sdk";
12039
- var DEFAULT_CAPABILITIES2 = "default";
11840
+ var DEFAULT_CAPABILITIES = "default";
12040
11841
  async function deliveryReconCommand(args) {
12041
11842
  try {
12042
11843
  const ctx = await getActiveAuthContextFromCli(args);
12043
- const client3 = HcmClient24.fromAuthContext(ctx);
12044
- const probe2 = httpProbe4(client3.raw(), args.capabilities ?? DEFAULT_CAPABILITIES2);
11844
+ const client3 = HcmClient23.fromAuthContext(ctx);
11845
+ const probe2 = httpProbe3(client3.raw(), args.capabilities ?? DEFAULT_CAPABILITIES);
12045
11846
  const sourceKey = await computeReconSourceKey(probe2);
12046
11847
  const layout = new ReconLayout(args.out ?? ".", ctx.tenantId, sourceKey);
12047
11848
  const summary = await runRecon(probe2, layout, {
@@ -12049,10 +11850,10 @@ async function deliveryReconCommand(args) {
12049
11850
  onlyModel: args.model ?? null,
12050
11851
  identity: ctx.tenantId ? { requestedTenantId: ctx.tenantId } : null
12051
11852
  });
12052
- process.stdout.write(formatObject28(summary, { format: args.output ?? "json" }) + "\n");
11853
+ process.stdout.write(formatObject27(summary, { format: args.output ?? "json" }) + "\n");
12053
11854
  } catch (e) {
12054
11855
  const err = e;
12055
- if (err?.isAxiosError) exitWithError(fromAxiosError22(err, args.env));
11856
+ if (err?.isAxiosError) exitWithError(fromAxiosError21(err, args.env));
12056
11857
  exitWithError(e);
12057
11858
  process.exit(1);
12058
11859
  }
@@ -12063,7 +11864,7 @@ async function deliveryReconRoundCommand(args) {
12063
11864
  const result = inspectRound(args.dir ?? ".");
12064
11865
  const fmt = args.output ?? "json";
12065
11866
  if (fmt !== "json") process.stdout.write(renderRound(result));
12066
- process.stdout.write(formatObject28(result, { format: fmt }) + "\n");
11867
+ process.stdout.write(formatObject27(result, { format: fmt }) + "\n");
12067
11868
  code = ROUND_EXIT_CODES[result.state];
12068
11869
  } catch (e) {
12069
11870
  exitWithError(e);
@@ -12082,7 +11883,7 @@ import {
12082
11883
  GAP_REASONS,
12083
11884
  deriveAclass,
12084
11885
  exitCode as gate0ExitCode,
12085
- formatObject as formatObject29,
11886
+ formatObject as formatObject28,
12086
11887
  inspectRound as inspectRound2,
12087
11888
  loadProtocolFacts,
12088
11889
  scan
@@ -12127,7 +11928,7 @@ async function deliveryGate0Command(args) {
12127
11928
  const merged = { ...result, premise: premise5 };
12128
11929
  const fmt = args.output ?? "json";
12129
11930
  if (fmt !== "json") process.stdout.write(renderGate0(merged, skillRoot));
12130
- process.stdout.write(`${formatObject29(merged, { format: fmt })}
11931
+ process.stdout.write(`${formatObject28(merged, { format: fmt })}
12131
11932
  `);
12132
11933
  for (const problem of premise5) {
12133
11934
  process.stderr.write(`\u{1F534} \u524D\u63D0\u4E0D\u6210\u7ACB\uFF08${problem.reason}\uFF09\uFF1A${problem.message}
@@ -12152,8 +11953,8 @@ import {
12152
11953
  DRY_RUN_TAIL,
12153
11954
  DriftDetected,
12154
11955
  FORCE_STALE_FLAG,
12155
- HcmClient as HcmClient25,
12156
- fetchReconIdentity as fetchReconIdentity4,
11956
+ HcmClient as HcmClient24,
11957
+ fetchReconIdentity as fetchReconIdentity3,
12157
11958
  INIT_EXIT_CODES,
12158
11959
  JOURNAL_STOP_KINDS,
12159
11960
  JOURNAL_STOP_UNKNOWN,
@@ -12223,7 +12024,7 @@ async function runSeedPlan(args, client3) {
12223
12024
  if (candidates.length === 0) {
12224
12025
  return premise(
12225
12026
  `\u672A\u627E\u5230\u5200 2 \u7684\u57FA\u7EBF\uFF1A${base}/*/index/fields.jsonl`,
12226
- "`plan` \u7684\u98CE\u9669\u6E05\u5355\u8981\u8BFB recon \u4EA7\u7269\u91CC\u7684 `mapping/` \u4E0E `valuedomain/`\u3002\u5148\u8DD1\u4E00\u6B21 `hcm delivery recon`\u3002"
12027
+ "`plan` \u7684\u98CE\u9669\u6E05\u5355\u8981\u8BFB recon \u4EA7\u7269\u91CC\u7684 `mapping/` \u4E0E `valuedomain/`\u3002\u5148\u8DD1\u4E00\u6B21 `hcm chiron recon`\u3002"
12227
12028
  );
12228
12029
  }
12229
12030
  const reconDir = candidates[0].reconDir;
@@ -12292,7 +12093,7 @@ async function authOrSignpost(args, cmd) {
12292
12093
  }
12293
12094
  async function deliverySeedPlanCommand(args) {
12294
12095
  const ctx = await authOrSignpost(args, "plan");
12295
- const client3 = HcmClient25.fromAuthContext(ctx);
12096
+ const client3 = HcmClient24.fromAuthContext(ctx);
12296
12097
  process.exitCode = await runSeedPlan(args, seedClient(client3, ctx));
12297
12098
  }
12298
12099
  function seedClient(client3, ctx) {
@@ -12321,14 +12122,14 @@ function seedClient(client3, ctx) {
12321
12122
  };
12322
12123
  return {
12323
12124
  tenantId: ctx.tenantId,
12324
- capabilities: DEFAULT_CAPABILITIES3,
12125
+ capabilities: DEFAULT_CAPABILITIES2,
12325
12126
  get: (p, params) => wrap(() => raw.get(p, { params })),
12326
12127
  post: (p, body) => wrap(() => raw.post(p, body))
12327
12128
  };
12328
12129
  }
12329
12130
  async function seedVerifyClient(client3, ctx) {
12330
12131
  const base = seedClient(client3, ctx);
12331
- const identity2 = await fetchReconIdentity4(base, String(ctx.tenantId ?? ""));
12132
+ const identity2 = await fetchReconIdentity3(base, String(ctx.tenantId ?? ""));
12332
12133
  return { ...base, identity: identity2 };
12333
12134
  }
12334
12135
  function lowerCaseHeaders(headers) {
@@ -12339,7 +12140,7 @@ function lowerCaseHeaders(headers) {
12339
12140
  }
12340
12141
  return out;
12341
12142
  }
12342
- var DEFAULT_CAPABILITIES3 = "default";
12143
+ var DEFAULT_CAPABILITIES2 = "default";
12343
12144
  async function runSeedApply(args, client3) {
12344
12145
  const out = args.out ?? ".";
12345
12146
  const tenant2 = tenantOf(client3);
@@ -12466,7 +12267,7 @@ async function runSeedApply(args, client3) {
12466
12267
  }
12467
12268
  async function deliverySeedApplyCommand(args) {
12468
12269
  const ctx = await authOrSignpost(args, "apply");
12469
- const client3 = HcmClient25.fromAuthContext(ctx);
12270
+ const client3 = HcmClient24.fromAuthContext(ctx);
12470
12271
  process.exitCode = await runSeedApply(args, seedClient(client3, ctx));
12471
12272
  }
12472
12273
  async function runSeedVerify(args, client3) {
@@ -12490,7 +12291,7 @@ async function deliverySeedVerifyCommand(args) {
12490
12291
  return;
12491
12292
  }
12492
12293
  const ctx = await authOrSignpost(args, "verify");
12493
- const client3 = HcmClient25.fromAuthContext(ctx);
12294
+ const client3 = HcmClient24.fromAuthContext(ctx);
12494
12295
  process.exitCode = await runSeedVerify(args, await seedVerifyClient(client3, ctx));
12495
12296
  }
12496
12297
 
@@ -12531,7 +12332,7 @@ function pickBaseline(args) {
12531
12332
  return {
12532
12333
  rc: premise2(
12533
12334
  "\u6CA1\u7ED9 `--tenant`\u3002",
12534
- "\u672C\u547D\u4EE4\u96F6\u7F51\u7EDC\uFF08\u4E0D\u767B\u5F55\u3001\u4E00\u53D1\u8BF7\u6C42\u90FD\u4E0D\u53D1\uFF09\uFF0C\u6240\u4EE5\u5B83\u65E0\u6CD5\u4ECE\u767B\u5F55\u6001\u77E5\u9053\u4F60\u5728\u54EA\u4E2A\u79DF\u6237\u3002\u7ED9\u7684\u503C\u8981\u4E0E\u5F53\u521D\u8DD1 `hcm delivery recon` \u65F6\u90A3\u4E2A\u79DF\u6237\u4E00\u81F4\u3002"
12335
+ "\u672C\u547D\u4EE4\u96F6\u7F51\u7EDC\uFF08\u4E0D\u767B\u5F55\u3001\u4E00\u53D1\u8BF7\u6C42\u90FD\u4E0D\u53D1\uFF09\uFF0C\u6240\u4EE5\u5B83\u65E0\u6CD5\u4ECE\u767B\u5F55\u6001\u77E5\u9053\u4F60\u5728\u54EA\u4E2A\u79DF\u6237\u3002\u7ED9\u7684\u503C\u8981\u4E0E\u5F53\u521D\u8DD1 `hcm chiron recon` \u65F6\u90A3\u4E2A\u79DF\u6237\u4E00\u81F4\u3002"
12535
12336
  )
12536
12337
  };
12537
12338
  }
@@ -12540,7 +12341,7 @@ function pickBaseline(args) {
12540
12341
  return {
12541
12342
  rc: premise2(
12542
12343
  `\u672A\u627E\u5230\u7D22\u5F15\uFF1A${base}/*/index/fields.jsonl`,
12543
- "\u672C\u547D\u4EE4\u53EA\u8BFB `hcm delivery recon` \u843D\u76D8\u7684\u5B57\u6BB5\u76EE\u5F55\u3002\u5148\u8DD1\u4E00\u6B21 `hcm delivery recon`\uFF0C\u6216\u7528 `--out <\u76EE\u5F55>` \u6307\u5230\u4EA7\u7269\u6839\u3002"
12344
+ "\u672C\u547D\u4EE4\u53EA\u8BFB `hcm chiron recon` \u843D\u76D8\u7684\u5B57\u6BB5\u76EE\u5F55\u3002\u5148\u8DD1\u4E00\u6B21 `hcm chiron recon`\uFF0C\u6216\u7528 `--out <\u76EE\u5F55>` \u6307\u5230\u4EA7\u7269\u6839\u3002"
12544
12345
  )
12545
12346
  };
12546
12347
  }
@@ -12605,7 +12406,7 @@ import {
12605
12406
  CHANGE_STATES,
12606
12407
  CHANGE_UNKNOWN,
12607
12408
  CODE_WORDS,
12608
- HcmClient as HcmClient26,
12409
+ HcmClient as HcmClient25,
12609
12410
  INIT_EXIT_CODES as INIT_EXIT_CODES3,
12610
12411
  META_WRITE_STEPS,
12611
12412
  META_VERIFY_STEPS,
@@ -12721,7 +12522,7 @@ function metaText(a) {
12721
12522
  }
12722
12523
  lines.push("[\u5DF2\u77E5\u4E0D\u8986\u76D6 \xB7 \u672C\u547D\u4EE4]");
12723
12524
  lines.push(
12724
- " \xB7 **\u9664\u8865\u507F\u53F0\u8D26\u90A3\u4E00\u4EFD\uFF0C\u672C\u547D\u4EE4\u4E0D\u843D\u76D8**\uFF1A\u4EA7\u51FA\u7269\u5C31\u662F\u5C4F\u5E55\u4E0A\u8FD9\u4E00\u9875\uFF1B\u8981\u7559\u4E00\u4EFD\u5B58\u6863\uFF0C\u81EA\u5DF1\u91CD\u5B9A\u5411\u4E00\u6B21 \u2014\u2014 `hcm delivery meta \u2026 > \u5143\u6570\u636E\u6539\u52A8-<\u65E5\u671F>.txt 2>&1`\u3002"
12525
+ " \xB7 **\u9664\u8865\u507F\u53F0\u8D26\u90A3\u4E00\u4EFD\uFF0C\u672C\u547D\u4EE4\u4E0D\u843D\u76D8**\uFF1A\u4EA7\u51FA\u7269\u5C31\u662F\u5C4F\u5E55\u4E0A\u8FD9\u4E00\u9875\uFF1B\u8981\u7559\u4E00\u4EFD\u5B58\u6863\uFF0C\u81EA\u5DF1\u91CD\u5B9A\u5411\u4E00\u6B21 \u2014\u2014 `hcm chiron meta \u2026 > \u5143\u6570\u636E\u6539\u52A8-<\u65E5\u671F>.txt 2>&1`\u3002"
12725
12526
  );
12726
12527
  lines.push(
12727
12528
  " \u{1F534} \u522B\u63A5\u7BA1\u9053\u5B58\u6863\uFF08`| tee \u6587\u4EF6`\uFF09\uFF1A\u90A3\u4E4B\u540E\u62FF\u5230\u7684\u9000\u51FA\u7801\u662F tee \u7684\uFF0C**\u6052\u4E3A 0**\uFF0C\u8FD9\u4E00\u8D9F\u5224\u6210\u4EC0\u4E48\u5C31\u4E22\u4E86\u3002"
@@ -12833,7 +12634,7 @@ function lowerCaseHeaders2(headers) {
12833
12634
  }
12834
12635
  async function deliveryMetaCommand(args) {
12835
12636
  const ctx = await getActiveAuthContextFromCli(args);
12836
- const client3 = HcmClient26.fromAuthContext(ctx);
12637
+ const client3 = HcmClient25.fromAuthContext(ctx);
12837
12638
  process.exitCode = await runDeliveryMeta(
12838
12639
  { ...args, tenant: args.tenant ?? String(ctx.tenantId ?? "") },
12839
12640
  metaClient(client3, ctx)
@@ -12845,14 +12646,14 @@ init_auth_guard();
12845
12646
  init_exit();
12846
12647
  import {
12847
12648
  computeReconSourceKey as computeReconSourceKey2,
12848
- HcmClient as HcmClient27,
12849
- httpProbe as httpProbe5,
12649
+ HcmClient as HcmClient26,
12650
+ httpProbe as httpProbe4,
12850
12651
  ReconLayout as ReconLayout2,
12851
12652
  runTriageRound
12852
12653
  } from "@hcmai/sdk";
12853
12654
  import { mkdirSync, readFileSync as readFileSync10, writeFileSync as writeFileSync2 } from "fs";
12854
12655
  import * as path17 from "path";
12855
- var DEFAULT_CAPABILITIES4 = "default";
12656
+ var DEFAULT_CAPABILITIES3 = "default";
12856
12657
  function premise4(message, hint) {
12857
12658
  process.stderr.write(`\u{1F534} \u524D\u63D0\u4E0D\u6210\u7ACB\uFF1A${message}
12858
12659
  `);
@@ -12901,8 +12702,8 @@ async function runTriage(args) {
12901
12702
  return premise4(e instanceof Error ? e.message : String(e), REQUESTS_SHAPE);
12902
12703
  }
12903
12704
  const ctx = await getActiveAuthContextFromCli(args);
12904
- const client3 = HcmClient27.fromAuthContext(ctx);
12905
- const probe2 = httpProbe5(client3.raw(), args.capabilities ?? DEFAULT_CAPABILITIES4);
12705
+ const client3 = HcmClient26.fromAuthContext(ctx);
12706
+ const probe2 = httpProbe4(client3.raw(), args.capabilities ?? DEFAULT_CAPABILITIES3);
12906
12707
  const artifactsDir = args.recon ?? new ReconLayout2(args.out ?? ".", ctx.tenantId, await computeReconSourceKey2(probe2)).dir;
12907
12708
  const result = await runTriageRound(probe2, artifactsDir, entriesIn);
12908
12709
  if (result.body === null) {
@@ -12927,11 +12728,11 @@ async function deliveryTriageCommand(args) {
12927
12728
  }
12928
12729
 
12929
12730
  // src/commands/delivery-execution.ts
12930
- import { createHash as createHash5, randomBytes as secureRandomBytes } from "crypto";
12731
+ import { createHash as createHash6, randomBytes as secureRandomBytes } from "crypto";
12931
12732
  import { spawn as spawn2 } from "child_process";
12932
- import { createReadStream, promises as fs14 } from "fs";
12733
+ import { createReadStream, promises as fs15 } from "fs";
12933
12734
  import path18 from "path";
12934
- import { CliError as CliError23, CliErrorCode as CliErrorCode21, formatObject as formatObject30 } from "@hcmai/sdk";
12735
+ import { CliError as CliError24, CliErrorCode as CliErrorCode22, formatObject as formatObject29 } from "@hcmai/sdk";
12935
12736
  init_exit();
12936
12737
  var EXECUTION_CONTRACT_VERSION = "2026-09-03.controlled-v4";
12937
12738
  var DEFAULT_TTL_SECONDS = 15 * 60;
@@ -12977,7 +12778,7 @@ async function prepareDeliveryExecution(input) {
12977
12778
  await safeManagedDirectory(project, ".hcm-delivery/execution-plans", plansDir);
12978
12779
  const planFile = path18.join(plansDir, `${planId}.json`);
12979
12780
  try {
12980
- await fs14.writeFile(planFile, `${JSON.stringify(plan, null, 2)}
12781
+ await fs15.writeFile(planFile, `${JSON.stringify(plan, null, 2)}
12981
12782
  `, {
12982
12783
  encoding: "utf8",
12983
12784
  mode: 384,
@@ -13034,7 +12835,7 @@ async function executeDeliveryPlan(input) {
13034
12835
  await safeManagedDirectory(project, ".hcm-delivery/execution-claims", claimsDir);
13035
12836
  const claimFile = path18.join(claimsDir, `${plan.planId}.json`);
13036
12837
  try {
13037
- await fs14.writeFile(
12838
+ await fs15.writeFile(
13038
12839
  claimFile,
13039
12840
  `${JSON.stringify({ schemaVersion: 1, planId: plan.planId, claimedAt: now.toISOString() }, null, 2)}
13040
12841
  `,
@@ -13043,8 +12844,8 @@ async function executeDeliveryPlan(input) {
13043
12844
  } catch (cause) {
13044
12845
  throw invalid2(`\u6267\u884C\u8BA1\u5212\u5DF2\u6D88\u8D39\uFF0C\u62D2\u7EDD\u91CD\u590D\u6267\u884C\uFF1A${plan.planId}`, cause);
13045
12846
  }
13046
- const stdoutHash = createHash5("sha256");
13047
- const stderrHash = createHash5("sha256");
12847
+ const stdoutHash = createHash6("sha256");
12848
+ const stderrHash = createHash6("sha256");
13048
12849
  const run2 = input.runCommand ?? runCurrentCliCommand;
13049
12850
  let exitCode;
13050
12851
  try {
@@ -13091,7 +12892,7 @@ async function deliveryPrepareCommand(argv, args) {
13091
12892
  evidenceDir: args.evidenceDir,
13092
12893
  ...ttlSeconds === void 0 ? {} : { ttlSeconds }
13093
12894
  });
13094
- process.stdout.write(formatObject30(plan, { format: args.output ?? "json" }) + "\n");
12895
+ process.stdout.write(formatObject29(plan, { format: args.output ?? "json" }) + "\n");
13095
12896
  process.stderr.write(
13096
12897
  `
13097
12898
  \u4E0B\u4E00\u6B65\uFF08argv \u5FC5\u987B\u4E0E\u672C\u6B21\u5B8C\u5168\u4E00\u81F4\uFF09\uFF1A
@@ -13120,7 +12921,7 @@ async function deliveryExecuteCommand(planId, argv, args) {
13120
12921
  }
13121
12922
  }
13122
12923
  function writeDeliveryExecutionReceipt(receipt, format = "json") {
13123
- process.stderr.write(formatObject30(receipt, { format }) + "\n");
12924
+ process.stderr.write(formatObject29(receipt, { format }) + "\n");
13124
12925
  process.exitCode = receipt.exitCode;
13125
12926
  }
13126
12927
  async function readProjectMode(project, environment) {
@@ -13189,9 +12990,9 @@ async function bindEvidenceDirectory(project, reference) {
13189
12990
  }
13190
12991
  const absolute = path18.join(project, relative2);
13191
12992
  await assertNoSymlinkComponents(project, relative2);
13192
- const stat = await fs14.stat(absolute).catch(() => null);
12993
+ const stat = await fs15.stat(absolute).catch(() => null);
13193
12994
  if (stat === null) {
13194
- await fs14.mkdir(absolute, { recursive: true, mode: 448 }).catch((cause) => {
12995
+ await fs15.mkdir(absolute, { recursive: true, mode: 448 }).catch((cause) => {
13195
12996
  throw invalid2(
13196
12997
  `evidence \u76EE\u5F55\u5EFA\u4E0D\u51FA\u6765\uFF1A${relative2}\u3002next_step=\u68C0\u67E5\u4E0A\u7EA7\u76EE\u5F55\u6743\u9650\uFF0C\u6216\u6362\u4E00\u4E2A evidence/ \u4E0B\u7684\u8DEF\u5F84`,
13197
12998
  cause
@@ -13374,7 +13175,7 @@ async function bindPayloadPath(project, reference, label) {
13374
13175
  const relative2 = safeRelative(reference, label);
13375
13176
  let stat;
13376
13177
  try {
13377
- stat = await fs14.stat(path18.join(project, relative2));
13178
+ stat = await fs15.stat(path18.join(project, relative2));
13378
13179
  } catch (cause) {
13379
13180
  throw invalid2(
13380
13181
  `${label}\u4E0D\u5B58\u5728\uFF1A${relative2}\u3002next_step=\u628A\u6570\u636E\u96C6\u653E\u8FDB\u9879\u76EE\u76EE\u5F55\u5185\uFF0C\u5E76\u7528\u9879\u76EE\u5185\u76F8\u5BF9\u8DEF\u5F84\u5F15\u7528\uFF08\u53D7\u63A7\u6267\u884C\u53EA\u9489\u5F97\u4F4F\u9879\u76EE\u5185\u7684\u8F7D\u8377\uFF09`,
@@ -13388,7 +13189,7 @@ async function bindPayloadDirectory(project, reference, label) {
13388
13189
  const root = path18.join(project, relative2);
13389
13190
  let stat;
13390
13191
  try {
13391
- stat = await fs14.stat(root);
13192
+ stat = await fs15.stat(root);
13392
13193
  } catch {
13393
13194
  throw invalid2(`${label}\u4E0D\u5B58\u5728\uFF1A${relative2}`);
13394
13195
  }
@@ -13398,7 +13199,7 @@ async function bindPayloadDirectory(project, reference, label) {
13398
13199
  const skipToolingAtRoot = relative2 === ".";
13399
13200
  const entries = [];
13400
13201
  const walk = async (dir, prefix) => {
13401
- const items = await fs14.readdir(dir, { withFileTypes: true });
13202
+ const items = await fs15.readdir(dir, { withFileTypes: true });
13402
13203
  for (const item of [...items].sort(
13403
13204
  (a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0
13404
13205
  )) {
@@ -13491,29 +13292,29 @@ async function runCurrentCliCommand(argv, cwd, streams) {
13491
13292
  async function writeReceiptExclusive(target, receipt) {
13492
13293
  const temp = `${target}.${process.pid}.${Date.now()}.tmp`;
13493
13294
  try {
13494
- await fs14.writeFile(temp, `${JSON.stringify(receipt, null, 2)}
13295
+ await fs15.writeFile(temp, `${JSON.stringify(receipt, null, 2)}
13495
13296
  `, {
13496
13297
  encoding: "utf8",
13497
13298
  mode: 384,
13498
13299
  flag: "wx"
13499
13300
  });
13500
- await fs14.link(temp, target);
13301
+ await fs15.link(temp, target);
13501
13302
  } catch (cause) {
13502
13303
  throw invalid2(`\u6267\u884C\u6536\u636E\u5199\u5165\u5931\u8D25\u6216\u5DF2\u5B58\u5728\uFF1A${path18.basename(target)}`, cause);
13503
13304
  } finally {
13504
- await fs14.unlink(temp).catch(() => void 0);
13305
+ await fs15.unlink(temp).catch(() => void 0);
13505
13306
  }
13506
13307
  }
13507
13308
  async function safeManagedDirectory(project, relative2, absolute) {
13508
13309
  await assertNoSymlinkComponents(project, path18.dirname(relative2));
13509
- const existing = await fs14.lstat(absolute).catch(() => void 0);
13310
+ const existing = await fs15.lstat(absolute).catch(() => void 0);
13510
13311
  if (existing?.isSymbolicLink()) throw invalid2(`\u53D7\u7BA1\u76EE\u5F55\u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5\uFF1A${relative2}`);
13511
13312
  if (existing && !existing.isDirectory()) throw invalid2(`\u53D7\u7BA1\u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55\uFF1A${relative2}`);
13512
- if (!existing) await fs14.mkdir(absolute, { mode: 448 });
13513
- await fs14.chmod(absolute, 448);
13313
+ if (!existing) await fs15.mkdir(absolute, { mode: 448 });
13314
+ await fs15.chmod(absolute, 448);
13514
13315
  }
13515
13316
  async function pathExists(file) {
13516
- return fs14.lstat(file).then(
13317
+ return fs15.lstat(file).then(
13517
13318
  () => true,
13518
13319
  (cause) => {
13519
13320
  if (cause.code === "ENOENT") return false;
@@ -13528,20 +13329,20 @@ async function readSafeFile(project, file, label) {
13528
13329
  await assertNoSymlinkComponents(project, relative2);
13529
13330
  let stat;
13530
13331
  try {
13531
- stat = await fs14.lstat(file);
13332
+ stat = await fs15.lstat(file);
13532
13333
  } catch (cause) {
13533
13334
  throw invalid2(`${label}\u4E0D\u53EF\u7528\uFF1A${relative2}`, cause);
13534
13335
  }
13535
13336
  if (stat.isSymbolicLink()) throw invalid2(`${label}\u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5\uFF1A${relative2}`);
13536
13337
  if (!stat.isFile()) throw invalid2(`${label}\u4E0D\u662F\u666E\u901A\u6587\u4EF6\uFF1A${relative2}`);
13537
- return fs14.readFile(file);
13338
+ return fs15.readFile(file);
13538
13339
  }
13539
13340
  async function assertNoSymlinkComponents(project, relative2) {
13540
13341
  const parts = relative2.split("/").filter(Boolean);
13541
13342
  let current = project;
13542
13343
  for (const part of parts) {
13543
13344
  current = path18.join(current, part);
13544
- const stat = await fs14.lstat(current).catch(() => void 0);
13345
+ const stat = await fs15.lstat(current).catch(() => void 0);
13545
13346
  if (stat?.isSymbolicLink()) throw invalid2(`\u8DEF\u5F84\u5305\u542B\u7B26\u53F7\u94FE\u63A5\uFF1A${relative2}`);
13546
13347
  if (!stat) break;
13547
13348
  }
@@ -13550,11 +13351,11 @@ async function realProject(requested) {
13550
13351
  const absolute = path18.resolve(requested);
13551
13352
  let project;
13552
13353
  try {
13553
- project = await fs14.realpath(absolute);
13354
+ project = await fs15.realpath(absolute);
13554
13355
  } catch (cause) {
13555
13356
  throw invalid2(`\u9879\u76EE\u76EE\u5F55\u4E0D\u53EF\u7528\uFF1A${absolute}`, cause);
13556
13357
  }
13557
- const stat = await fs14.stat(project);
13358
+ const stat = await fs15.stat(project);
13558
13359
  if (!stat.isDirectory()) throw invalid2(`\u9879\u76EE\u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55\uFF1A${absolute}`);
13559
13360
  return project;
13560
13361
  }
@@ -13602,10 +13403,10 @@ function canonicalJson(value) {
13602
13403
  return JSON.stringify(value) ?? "null";
13603
13404
  }
13604
13405
  function sha2565(value) {
13605
- return createHash5("sha256").update(value).digest("hex");
13406
+ return createHash6("sha256").update(value).digest("hex");
13606
13407
  }
13607
13408
  async function sha256File(file) {
13608
- const hash = createHash5("sha256");
13409
+ const hash = createHash6("sha256");
13609
13410
  await new Promise((resolve4, reject) => {
13610
13411
  const stream = createReadStream(file);
13611
13412
  stream.on("data", (chunk) => hash.update(chunk));
@@ -13615,7 +13416,7 @@ async function sha256File(file) {
13615
13416
  return hash.digest("hex");
13616
13417
  }
13617
13418
  function invalid2(message, cause) {
13618
- return new CliError23({ code: CliErrorCode21.INVALID_ARGUMENT, message, cause });
13419
+ return new CliError24({ code: CliErrorCode22.INVALID_ARGUMENT, message, cause });
13619
13420
  }
13620
13421
  function nextCommandHint(planId, project, argv) {
13621
13422
  const quoted = argv.map((a) => /[\s"'$`\\]/.test(a) ? `'${a.replace(/'/g, `'\\''`)}'` : a);
@@ -13627,25 +13428,25 @@ function nextCommandHint(planId, project, argv) {
13627
13428
  init_auth_guard();
13628
13429
  init_exit();
13629
13430
  import {
13630
- HcmClient as HcmClient28,
13431
+ HcmClient as HcmClient27,
13631
13432
  adminResetPassword,
13632
- formatObject as formatObject31,
13633
- fromAxiosError as fromAxiosError23,
13634
- CliError as CliError24,
13635
- CliErrorCode as CliErrorCode22
13433
+ formatObject as formatObject30,
13434
+ fromAxiosError as fromAxiosError22,
13435
+ CliError as CliError25,
13436
+ CliErrorCode as CliErrorCode23
13636
13437
  } from "@hcmai/sdk";
13637
13438
  function buildAdminResetPasswordRequest(args, password) {
13638
13439
  const hasId = Boolean(args.id);
13639
13440
  const hasUsername = Boolean(args.username);
13640
13441
  if (hasId === hasUsername) {
13641
- throw new CliError24({
13642
- code: CliErrorCode22.INVALID_ARGUMENT,
13442
+ throw new CliError25({
13443
+ code: CliErrorCode23.INVALID_ARGUMENT,
13643
13444
  message: "--id <uuid> \u4E0E --username <user> \u5FC5\u987B\u4E14\u53EA\u80FD\u63D0\u4F9B\u4E00\u4E2A"
13644
13445
  });
13645
13446
  }
13646
13447
  if (!password) {
13647
- throw new CliError24({
13648
- code: CliErrorCode22.INVALID_ARGUMENT,
13448
+ throw new CliError25({
13449
+ code: CliErrorCode23.INVALID_ARGUMENT,
13649
13450
  message: "\u65B0\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A"
13650
13451
  });
13651
13452
  }
@@ -13661,12 +13462,12 @@ async function userResetPasswordCommand(args) {
13661
13462
  try {
13662
13463
  const password = args.passwordStdin ? await readSecretFromStdin() : await promptPasswordTwice();
13663
13464
  const request = buildAdminResetPasswordRequest(args, password);
13664
- const client3 = HcmClient28.fromAuthContext(await getActiveAuthContextFromCli(args));
13465
+ const client3 = HcmClient27.fromAuthContext(await getActiveAuthContextFromCli(args));
13665
13466
  const result = await adminResetPassword(client3.raw(), request);
13666
- process.stdout.write(formatObject31(result, { format: args.output ?? "json" }) + "\n");
13467
+ process.stdout.write(formatObject30(result, { format: args.output ?? "json" }) + "\n");
13667
13468
  } catch (cause) {
13668
13469
  const err = cause;
13669
- if (err?.isAxiosError) exitWithError(fromAxiosError23(err, args.env));
13470
+ if (err?.isAxiosError) exitWithError(fromAxiosError22(err, args.env));
13670
13471
  exitWithError(cause);
13671
13472
  }
13672
13473
  }
@@ -13674,8 +13475,8 @@ async function promptPasswordTwice() {
13674
13475
  const password = await promptSecret("\u65B0\u5BC6\u7801: ");
13675
13476
  const confirmation = await promptSecret("\u518D\u6B21\u8F93\u5165\u65B0\u5BC6\u7801: ");
13676
13477
  if (password !== confirmation) {
13677
- throw new CliError24({
13678
- code: CliErrorCode22.INVALID_ARGUMENT,
13478
+ throw new CliError25({
13479
+ code: CliErrorCode23.INVALID_ARGUMENT,
13679
13480
  message: "\u4E24\u6B21\u8F93\u5165\u7684\u65B0\u5BC6\u7801\u4E0D\u4E00\u81F4"
13680
13481
  });
13681
13482
  }
@@ -13686,19 +13487,19 @@ async function promptPasswordTwice() {
13686
13487
  init_exit();
13687
13488
  init_auth_guard();
13688
13489
  import {
13689
- HcmClient as HcmClient29,
13690
- formatObject as formatObject32,
13691
- fromAxiosError as fromAxiosError24
13490
+ HcmClient as HcmClient28,
13491
+ formatObject as formatObject31,
13492
+ fromAxiosError as fromAxiosError23
13692
13493
  } from "@hcmai/sdk";
13693
13494
  async function modelsCommand(keyword, args) {
13694
13495
  try {
13695
- const client3 = HcmClient29.fromAuthContext(await getActiveAuthContextFromCli(args));
13496
+ const client3 = HcmClient28.fromAuthContext(await getActiveAuthContextFromCli(args));
13696
13497
  const all = await client3.listModels();
13697
13498
  const needle = keyword?.trim().toLowerCase();
13698
13499
  const rows = (needle ? all.filter((m) => JSON.stringify(m).toLowerCase().includes(needle)) : all).sort((a, b) => key(a).localeCompare(key(b)));
13699
13500
  const fmt = args.output ?? "table";
13700
13501
  if (fmt !== "table") {
13701
- process.stdout.write(formatObject32({ total: rows.length, models: rows }, { format: fmt }) + "\n");
13502
+ process.stdout.write(formatObject31({ total: rows.length, models: rows }, { format: fmt }) + "\n");
13702
13503
  process.exitCode = 0;
13703
13504
  return;
13704
13505
  }
@@ -13725,7 +13526,7 @@ async function modelsCommand(keyword, args) {
13725
13526
  return;
13726
13527
  } catch (e) {
13727
13528
  const err = e;
13728
- if (err?.isAxiosError) exitWithError(fromAxiosError24(err, args.profile));
13529
+ if (err?.isAxiosError) exitWithError(fromAxiosError23(err, args.profile));
13729
13530
  exitWithError(e);
13730
13531
  }
13731
13532
  }
@@ -13767,15 +13568,15 @@ config.command("set-profile <name>").description("[deprecated] \u7528 `hcm env u
13767
13568
  config.command("delete <name>").description("[deprecated] \u7528 `hcm env remove --force`").action((n) => configDeleteDeprecated(n));
13768
13569
  config.command("set <key> <value>").description("\u8BBE\u7F6E\u5168\u5C40 defaults\uFF0C\u4F8B\u5982 `defaults.output json`").action((k, v) => configSet(k, v));
13769
13570
  config.command("get <key>").description("\u8BFB\u53D6\u5168\u5C40 defaults").action((k) => configGet(k));
13770
- var env = program.command("env").description("\u7BA1\u7406 HCM \u73AF\u5883\uFF08\u591A\u540E\u7AEF\u8FDE\u63A5\u914D\u7F6E\uFF09");
13771
- env.command("list").description("\u5217\u51FA\u5168\u90E8 env").action(() => envList());
13772
- env.command("current").description("\u663E\u793A\u5F53\u524D\u6FC0\u6D3B\u7684 env").action(() => envCurrent());
13773
- env.command("add <name>").description("\u65B0\u589E env").option("--endpoint <url>", "HCM \u540E\u7AEF URL\uFF08\u5FC5\u586B\uFF09").option("--tenant <id>", "\u9ED8\u8BA4 tenant id", "1").option("--frontend <url>", "\u5BF9\u5E94\u524D\u7AEF URL\uFF0C\u4F8B\u5982 http://127.0.0.1:5176").option("--force", "\u8986\u76D6\u5DF2\u5B58\u5728\u7684\u540C\u540D env").action((name, opts) => envAdd(name, opts));
13774
- env.command("use <name>").description("\u5207\u5230\u6307\u5B9A env").option("--no-ping", "\u8DF3\u8FC7 endpoint \u5065\u5EB7\u68C0\u67E5").action((name, opts) => envUse(name, opts));
13775
- env.command("save <name>").description("\u628A\u5F53\u524D\u4E34\u65F6\u73AF\u5883\uFF08login --code \u4EA7\u751F\u7684\uFF09\u5B58\u6210\u5177\u540D env").option("--force", "\u76EE\u6807 env \u5DF2\u5B58\u5728\u65F6\u8986\u76D6\u5B83\u7684\u914D\u7F6E").action((name, opts) => envSave(name, opts));
13776
- env.command("remove <name>").description("\u5220\u9664 env\uFF08\u7EA7\u8054\u6E05\u9664\u8BE5 env \u7684\u5168\u90E8 identity \u548C token\uFF09").option("--force", "\u8DF3\u8FC7\u786E\u8BA4\u63D0\u793A").action((name, opts) => envRemove(name, opts));
13777
- env.command("show [name]").description("\u663E\u793A env \u8BE6\u60C5\uFF08\u542B\u8BE5 env \u4E0B\u7684 identity \u5217\u8868\uFF09").action((name) => envShow({ name }));
13778
- env.command("edit <field> <value>").description("\u7F16\u8F91 env \u5B57\u6BB5\uFF08endpoint / frontend / tenantId / defaultIdentity / defaultAgent\uFF09").option("--env <name>", "\u76EE\u6807 env \u540D\uFF08\u9ED8\u8BA4\u5F53\u524D activeEnv\uFF09").action((field, value, opts) => envEdit(field, value, opts));
13571
+ var env2 = program.command("env").description("\u7BA1\u7406 HCM \u73AF\u5883\uFF08\u591A\u540E\u7AEF\u8FDE\u63A5\u914D\u7F6E\uFF09");
13572
+ env2.command("list").description("\u5217\u51FA\u5168\u90E8 env").action(() => envList());
13573
+ env2.command("current").description("\u663E\u793A\u5F53\u524D\u6FC0\u6D3B\u7684 env").action(() => envCurrent());
13574
+ env2.command("add <name>").description("\u65B0\u589E env").option("--endpoint <url>", "HCM \u540E\u7AEF URL\uFF08\u5FC5\u586B\uFF09").option("--tenant <id>", "\u9ED8\u8BA4 tenant id", "1").option("--frontend <url>", "\u5BF9\u5E94\u524D\u7AEF URL\uFF0C\u4F8B\u5982 http://127.0.0.1:5176").option("--force", "\u8986\u76D6\u5DF2\u5B58\u5728\u7684\u540C\u540D env").action((name, opts) => envAdd(name, opts));
13575
+ env2.command("use <name>").description("\u5207\u5230\u6307\u5B9A env").option("--no-ping", "\u8DF3\u8FC7 endpoint \u5065\u5EB7\u68C0\u67E5").action((name, opts) => envUse(name, opts));
13576
+ env2.command("save <name>").description("\u628A\u5F53\u524D\u4E34\u65F6\u73AF\u5883\uFF08login --code \u4EA7\u751F\u7684\uFF09\u5B58\u6210\u5177\u540D env").option("--force", "\u76EE\u6807 env \u5DF2\u5B58\u5728\u65F6\u8986\u76D6\u5B83\u7684\u914D\u7F6E").action((name, opts) => envSave(name, opts));
13577
+ env2.command("remove <name>").description("\u5220\u9664 env\uFF08\u7EA7\u8054\u6E05\u9664\u8BE5 env \u7684\u5168\u90E8 identity \u548C token\uFF09").option("--force", "\u8DF3\u8FC7\u786E\u8BA4\u63D0\u793A").action((name, opts) => envRemove(name, opts));
13578
+ env2.command("show [name]").description("\u663E\u793A env \u8BE6\u60C5\uFF08\u542B\u8BE5 env \u4E0B\u7684 identity \u5217\u8868\uFF09").action((name) => envShow({ name }));
13579
+ env2.command("edit <field> <value>").description("\u7F16\u8F91 env \u5B57\u6BB5\uFF08endpoint / frontend / tenantId / defaultIdentity / defaultAgent\uFF09").option("--env <name>", "\u76EE\u6807 env \u540D\uFF08\u9ED8\u8BA4\u5F53\u524D activeEnv\uFF09").action((field, value, opts) => envEdit(field, value, opts));
13779
13580
  var identity = program.command("identity").description("\u7BA1\u7406 HCM \u8EAB\u4EFD\u51ED\u636E\uFF08env \u4E0B\u7684 identity\uFF09");
13780
13581
  identity.command("list").description("\u5217\u51FA identity\uFF08\u9ED8\u8BA4\u5217\u5F53\u524D env\uFF0C--env all \u5217\u5168\u90E8\uFF09").option("--env <name>", '\u8FC7\u6EE4 env\uFF1B\u4F20 "all" \u5217\u5168\u90E8', void 0).action((opts) => identityList(opts));
13781
13582
  identity.command("show <name>").description("\u5B9E\u65F6\u663E\u793A alias \u5BF9\u5E94\u7684\u670D\u52A1\u7AEF\u7528\u6237\u3001\u79DF\u6237\u4E0E\u89D2\u8272\uFF08\u4E0D\u8F93\u51FA token\uFF09").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((name, opts) => identityShow(name, opts));
@@ -13783,14 +13584,16 @@ identity.command("use <name>").description("\u628A identity \u8BBE\u4E3A\u5176 e
13783
13584
  identity.command("remove <name>").description("\u5220\u9664 identity\uFF08\u6E05 token + \u82E5\u662F env default \u5219\u6E05\u7A7A\uFF09").action((name) => identityRemove(name));
13784
13585
  var user = program.command("user").description("\u7BA1\u7406\u79DF\u6237\u7528\u6237\u7684\u4E13\u7528\u51ED\u636E\u6D41\u7A0B");
13785
13586
  user.command("reset-password").description("\u7531 admin.system \u5B89\u5168\u91CD\u7F6E\u7528\u6237\u5BC6\u7801\uFF0C\u5E76\u4F7F\u65E2\u6709\u4F1A\u8BDD\u5931\u6548").option("--id <uuid>", "\u76EE\u6807\u7528\u6237 ID\uFF08\u4E0E --username \u4E8C\u9009\u4E00\uFF09").option("--username <user>", "\u76EE\u6807\u7528\u6237\u540D\uFF08\u4E0E --id \u4E8C\u9009\u4E00\uFF09").option("--password-stdin", "\u4ECE\u6807\u51C6\u8F93\u5165\u8BFB\u53D6\u65B0\u5BC6\u7801\uFF08Agent/\u53D7\u63A7\u4EA4\u4ED8\u5FC5\u987B\u4F7F\u7528\uFF09").option("--no-force-change", "\u4E0B\u6B21\u767B\u5F55\u4E0D\u5F3A\u5236\u6539\u5BC6\uFF08\u4EC5\u9650\u5DF2\u6279\u51C6\u7684\u9694\u79BB\u6D4B\u8BD5\u73AF\u5883\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\u5FC5\u987B\u5177\u5907 admin.system\uFF09").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((opts) => userResetPasswordCommand(opts));
13786
- var chiron = program.command("chiron").description("\u777F\u620E\u987E\u95EE\u9879\u76EE\uFF1Ainit \u4E00\u6761\u547D\u4EE4\u521D\u59CB\u5316\u9879\u76EE\u4ED3\uFF0Cdoctor \u56DB\u884C\u6838\u5BF9\u80FD\u4E0D\u80FD\u5F00\u5DE5");
13587
+ var chiron = program.command("chiron").description(
13588
+ "\u777F\u620E\uFF1A\u5B9E\u65BD\u751F\u547D\u5468\u671F\u7684\u4E00\u6761\u547D\u4EE4\u6811\u2014\u2014\u8FDB\u573A init / \u5F00\u5DE5\u81EA\u68C0 doctor / \u6478\u5E95 recon / \u5224\u9700\u6C42 triage / \u704C\u6570 seed / \u6539\u914D\u7F6E meta / \u56DE\u5F52 test"
13589
+ );
13787
13590
  chiron.command("init").description(
13788
13591
  "\u521D\u59CB\u5316\u987E\u95EE\u9879\u76EE\u4ED3\uFF1A\u5199 env.yaml\uFF08\u7528\u521A hcm login \u7684\u73AF\u5883\uFF09\u3001\u5EFA\u76EE\u5F55\u3001\u88C5\u5168\u90E8\u6280\u80FD\u3001\u63A5\u6848\u4F8B\u5E93\uFF1B\u91CD\u8DD1\u5B89\u5168"
13789
13592
  ).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));
13790
13593
  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));
13791
13594
  chiron.command("doctor").description(
13792
13595
  "\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"
13793
- ).option("--project <dir>", "\u9879\u76EE\u6839\u76EE\u5F55", ".").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));
13596
+ ).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));
13794
13597
  var OUTPUT_OPT = ["--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table"];
13795
13598
  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-*");
13796
13599
  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));
@@ -13807,17 +13610,18 @@ jira.command("audit").description("\u4E00\u81F4\u6027\uFF1A\u72B6\u6001\u5DF2\u7
13807
13610
  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));
13808
13611
  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));
13809
13612
  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));
13810
- var delivery = program.command("delivery").description("\u987E\u95EE\u4EA4\u4ED8\uFF1A\u73B0\u573A\u63A2\u6D3B\u3001\u98CE\u9669\u8BC4\u4F30\u4E0E\u4E00\u6B21\u6027\u53D7\u63A7\u6267\u884C\u5408\u540C");
13613
+ var delivery = program.command("delivery").description(
13614
+ "\u53D7\u63A7\u5199\u5165\uFF08\u6A2A\u5207\uFF0C\u4E0D\u5C5E\u4E8E\u67D0\u4E2A\u4EA4\u4ED8\u9636\u6BB5\uFF09\uFF1A\u5224\u98CE\u9669 assess \u2192 \u7ED1\u4E00\u6B21\u6027\u8BA1\u5212 prepare \u2192 \u9010\u6B21\u6279\u51C6 execute\uFF1Bmode \u770B/\u6539\u672C\u673A\u5199\u7B56\u7565"
13615
+ );
13811
13616
  delivery.command("assess").description("\u8BC4\u4F30\u4E00\u6B21 HCM CLI argv\uFF1BAction \u98CE\u63A7\u58F0\u660E\u8BFB\u53D6\u81EA\u76EE\u6807 Core\uFF0C\u7528 -- \u5206\u9694\u88AB\u8BC4\u4F30\u547D\u4EE4").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").allowUnknownOption(true).argument("<command...>", "\u88AB\u8BC4\u4F30\u7684 HCM \u5B50\u547D\u4EE4\u4E0E\u53C2\u6570\uFF0C\u4E0D\u5305\u542B hcm \u672C\u8EAB").action((command, opts) => deliveryAssessCommand(command, opts));
13812
- delivery.command("doctor").description("\u56DB\u6761\u951A\u70B9\u63A2\u6D3B\uFF1A\u8FDE\u901A / \u6211\u662F\u8C01 / configAdmin / \u7AD9\u5728\u54EA\u4E00\u5C42").option("--env <name>", "\u76EE\u6807\u73AF\u5883\u522B\u540D").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD").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) => deliveryDoctorCommand(opts));
13813
- var recon = delivery.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));
13617
+ 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));
13814
13618
  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(
13815
13619
  (opts, cmd) => deliveryReconRoundCommand({
13816
13620
  ...opts,
13817
13621
  output: cmd.parent?.opts()?.output
13818
13622
  })
13819
13623
  );
13820
- var seed = delivery.command("seed").description(
13624
+ var seed = chiron.command("seed").description(
13821
13625
  "\u628A\u987E\u95EE\u624B\u4E0A\u7684**\u5BA2\u6237\u8868**\u53D8\u6210\u4EA7\u54C1\u91CC\u7684\u884C\u3002\u26A0\uFE0F \u4E0E\u9876\u5C42 `hcm import <path>` \u4E0D\u662F\u4E00\u56DE\u4E8B\uFF1A\u90A3\u4E00\u6761\u5403 DataPackage YAML\uFF08fixture \u6CE8\u5165\u5668\uFF09\uFF0C\u8FD9\u4E00\u65CF\u5403\u5BA2\u6237\u7684 Excel"
13822
13626
  );
13823
13627
  seed.command("find").argument("<term>", "\u8981\u627E\u7684\u8BCD\uFF1A\u5B57\u6BB5\u540D / \u4E2D\u6587\u540D\u79F0 / \u4E1A\u52A1\u8BDD\u672F\uFF08\u540C\u4E49\u8BCD\u3001\u63CF\u8FF0\u3001\u679A\u4E3E\u6807\u7B7E\u90FD\u641C\uFF09").description(
@@ -13843,7 +13647,7 @@ seed.command("verify").description(
13843
13647
  "\u53EA\u51FA\u53F0\u8D26\u90A3\u4E00\u5C42\uFF08\u96F6\u7F51\u7EDC\uFF0C\u4E00\u53D1\u8BF7\u6C42\u90FD\u4E0D\u53D1\uFF09\u3002\u26A0\uFE0F **\u5E93\u91CC\u73B0\u5728\u600E\u4E48\u6837\uFF0C\u90A3\u4E00\u8D9F\u4E00\u4E2A\u5B57\u90FD\u6CA1\u95EE** \u2014\u2014 \u522B\u62FF\u5B83\u5F53\u9A8C\u6536\u901A\u8FC7",
13844
13648
  false
13845
13649
  ).action((opts) => deliverySeedVerifyCommand(opts));
13846
- delivery.command("meta").description(
13650
+ chiron.command("meta").description(
13847
13651
  `\u6539\u4E00\u4EFD\u79DF\u6237 meta\uFF08\u5199 \u2192 \u6E05\u7F13\u5B58 \u2192 \u5B9A\u5411\u91CD\u722C \u2192 diff \u70B9\u540D\u5B57\u6BB5\uFF09\uFF0C\u5168\u7A0B\u5E26\u8865\u507F\u53F0\u8D26\u3002\u52A0 \`${VERIFY_ACTIVE_FLAG}\` \u518D\u7AD9\u5230 active \u5C42\u770B\u4E00\u773C**\u771F\u5B9E\u7528\u6237**\u770B\u5F97\u89C1\u4EC0\u4E48`
13848
13652
  ).option("--env <name>", "\u76EE\u6807\u73AF\u5883\u522B\u540D").option("--profile <name>", "\u8EAB\u4EFD\u6863\u6848").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD").requiredOption(
13849
13653
  "--layer <layer>",
@@ -13865,7 +13669,7 @@ delivery.command("gate0").description("\u96F6\u7F51\u7EDC\uFF1A\u626B\u4E00\u4EF
13865
13669
  "--mapping <file>",
13866
13670
  "\u987E\u95EE\u624B\u5199\u7684\u6620\u5C04\u5DE5\u4EF6\uFF08naturalKey \u8FD9\u4E00\u7C7B\u7684\u552F\u4E00\u6765\u6E90\uFF09\uFF1B\u4E0D\u7ED9 \u21D2 \u90A3\u4E00\u7C7B\u6052\u7EFF \u21D2 rc=2"
13867
13671
  ).option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((opts) => deliveryGate0Command(opts));
13868
- delivery.command("triage").description(
13672
+ chiron.command("triage").description(
13869
13673
  "\u9700\u6C42\u5206\u8BCA\uFF1A\u4E03\u7C7B\u627F\u8F7D\u7269\u7531\u672C\u547D\u4EE4\u73B0\u63A2\u73B0\u586B\uFF08\u987E\u95EE\u8DF3\u4E0D\u4E86\u6B65\uFF09\uFF0C\u7ED3\u8BBA\u4E0E\u8BC1\u636E\u7531\u4F60\u7ED9\uFF0C\u5B83\u53EA\u5224\u4E24\u8005\u6253\u4E0D\u6253\u67B6"
13870
13674
  ).requiredOption(
13871
13675
  "--requests <file>",
@@ -13874,7 +13678,6 @@ delivery.command("triage").description(
13874
13678
  "--recon <dir>",
13875
13679
  "\u57FA\u7EBF\u4EA7\u7269\u76EE\u5F55\uFF08<out>/recon/<\u79DF\u6237\u6BB5>/<\u6765\u6E90\u6BB5>\uFF09\uFF1B\u4E0D\u7ED9\u5219\u6309\u722C\u53D6\u8EAB\u4EFD\u73B0\u7B97\u4E00\u4EFD"
13876
13680
  ).option("--out <dir>", "\u4EA7\u7269\u6839\uFF08\u5199 work/triage.md\uFF09", ".").option("--capabilities <caps>", "\u672C\u6B21\u63A2\u6D4B\u58F0\u660E\u7684 capability \u4E32", "default").action((opts) => deliveryTriageCommand(opts));
13877
- delivery.command("init").description("\u751F\u6210\u5BA2\u6237\u9879\u76EE\u4ED3\u9AA8\u67B6\u3001\u73AF\u5883\u6E05\u5355\u3001\u6210\u5458 setup \u4E0E\u672C\u673A\u53D7\u63A7\u4EA4\u4ED8\u914D\u7F6E").option("--project <dir>", "HCM \u987E\u95EE\u9879\u76EE\u6839\u76EE\u5F55", ".").option("--env <name>", "\u521D\u59CB\u5316\u54EA\u4E2A\u73AF\u5883\uFF08\u9ED8\u8BA4 HCM_ENV / activeEnv\uFF09").option("--mode <mode>", "\u672C\u673A\u521D\u59CB\u4EA4\u4ED8\u6A21\u5F0F\uFF1Acontrolled | plan-only", "plan-only").option("--approved-by <person>", "\u5207\u5230 controlled \u65F6\u5FC5\u586B\uFF1A\u672C\u6B21\u660E\u786E\u6279\u51C6\u7684\u9879\u76EE\u8D1F\u8D23\u4EBA").option("--reason <text>", "\u5207\u5230 controlled \u65F6\u5FC5\u586B\uFF1A\u672C\u6B21\u5BF9\u8BDD\u6216\u4EFB\u52A1\u4E66\u4E2D\u7684\u6388\u6743\u4F9D\u636E").option("--force", "\u8986\u76D6\u5DF2\u5B58\u5728\u7684\u9879\u76EE\u914D\u7F6E").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((opts) => deliveryInitCommand(opts));
13878
13681
  delivery.command("mode").description("\u6309\u73AF\u5883\u770B/\u6539\u672C\u673A\u4EA4\u4ED8\u6A21\u5F0F\uFF1B\u4E0D\u5E26 --set \u53EA\u8BFB\uFF0C\u5E26 --set \u53EA\u6539\u76EE\u6807\u73AF\u5883").option("--project <dir>", "HCM \u987E\u95EE\u9879\u76EE\u6839\u76EE\u5F55", ".").requiredOption("--env <name>", "\u76EE\u6807\u73AF\u5883\uFF08\u5FC5\u586B\uFF1B\u4E0D\u7EE7\u627F\u5168\u5C40 activeEnv\uFF09").option("--set <mode>", "\u6539\u4E3A\uFF1Acontrolled | plan-only").option("--approved-by <person>", "\u5207\u5230 controlled \u65F6\u5FC5\u586B\uFF1A\u672C\u6B21\u660E\u786E\u6279\u51C6\u7684\u9879\u76EE\u8D1F\u8D23\u4EBA").option("--reason <text>", "\u5207\u5230 controlled \u65F6\u5FC5\u586B\uFF1A\u672C\u6B21\u5BF9\u8BDD\u6216\u4EFB\u52A1\u4E66\u4E2D\u7684\u6388\u6743\u4F9D\u636E").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((opts) => deliveryModeCommand(opts));
13879
13682
  delivery.command("prepare").description("\u628A\u53D7\u652F\u6301\u7684 R2 argv \u4E0E\u9501\u3001\u8FD0\u884C\u65F6\u548C\u53D8\u66F4/\u56DE\u6EDA\u8BF4\u660E\u7ED1\u5B9A\u4E3A\u77ED\u65F6\u6267\u884C\u8BA1\u5212").requiredOption("--change-ref <file>", "\u9879\u76EE work/ \u6216 decisions/ \u4E0B\u7684\u53D8\u66F4\u8BF4\u660E").requiredOption("--rollback-ref <file>", "\u9879\u76EE work/ \u6216 decisions/ \u4E0B\u7684\u56DE\u6EDA\u8BF4\u660E").requiredOption("--evidence-dir <dir>", "\u9879\u76EE evidence/ \u4E0B\u7684\u6536\u636E\u76EE\u5F55").option("--project <dir>", "HCM \u987E\u95EE\u9879\u76EE\u6839\u76EE\u5F55", ".").option("--ttl-seconds <n>", "\u6709\u6548\u671F\u79D2\u6570\uFF0860-3600\uFF09", "900").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").allowUnknownOption(true).argument("<command...>", "\u88AB\u7ED1\u5B9A\u7684 R2 HCM \u5B50\u547D\u4EE4\u4E0E\u53C2\u6570\uFF0C\u4E0D\u5305\u542B hcm \u672C\u8EAB").action((command, opts) => deliveryPrepareCommand(command, opts));
13880
13683
  delivery.command("execute <planId>").description("\u9010\u6B21\u6279\u51C6\u540E\u6D88\u8D39\u77ED\u65F6\u8BA1\u5212\uFF0C\u5E76\u6267\u884C\u4E00\u6B21\u4E0E\u8BA1\u5212\u5B8C\u5168\u76F8\u540C\u7684 R2 argv").option("--project <dir>", "HCM \u987E\u95EE\u9879\u76EE\u6839\u76EE\u5F55", ".").option("--output <fmt>", "\u6536\u636E\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").allowUnknownOption(true).argument("[command...]", "\u4E0E prepare \u5B8C\u5168\u76F8\u540C\u7684 R2 HCM \u5B50\u547D\u4EE4\u4E0E\u53C2\u6570").action((planId, command, opts) => deliveryExecuteCommand(planId, command, opts));
@@ -13888,7 +13691,10 @@ program.command("query <Model>").description("\u67E5\u8BE2 Model \u5217\u8868\u6
13888
13691
  program.command("action <Model.Action>").description("\u8C03\u7528 Model \u4E0A\u7684 Action\uFF08\u4E1A\u52A1\u65B9\u6CD5\uFF09\uFF0C\u4F8B\u5982 Employee.regularize").option("--id <id>", "\u76EE\u6807\u5B9E\u4F53 ID\uFF08object Action \u5FC5\u586B\uFF09").option("--ids <csv>", "\u6279\u91CF ID\uFF08\u9017\u53F7\u5206\u9694\uFF0Cbulk Action \u7528\uFF09").option("--method <method>", "HTTP \u65B9\u6CD5\uFF1AGET | POST | PUT | DELETE\uFF08\u9ED8\u8BA4\u6309 Core \u5143\u6570\u636E\u81EA\u52A8\u5224\u5B9A\uFF09").option(
13889
13692
  "--scope <scope>",
13890
13693
  "\u5F3A\u5236 Action scope\uFF1Aclass | object\uFF08\u9ED8\u8BA4\uFF1A\u6709 --id \u4E3A object\uFF0C\u5426\u5219 class\uFF09"
13891
- ).option("--params <JSON>", `Action \u5165\u53C2 JSON\uFF0C\u4F8B\u5982 '{"effectDate":"2026-06-01"}'`).option("--params-file <path>", "\u4ECE UTF-8 JSON \u6587\u4EF6\u8BFB\u53D6 Action \u5165\u53C2\uFF08\u4E0E --params \u4E92\u65A5\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").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((spec, opts) => actionCommand(spec, opts));
13694
+ ).option("--params <JSON>", `Action \u5165\u53C2 JSON\uFF0C\u4F8B\u5982 '{"effectDate":"2026-06-01"}'`).option("--params-file <path>", "\u4ECE UTF-8 JSON \u6587\u4EF6\u8BFB\u53D6 Action \u5165\u53C2\uFF08\u4E0E --params \u4E92\u65A5\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").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").option(
13695
+ "--artifact-output <path>",
13696
+ "\u628A\u6807\u51C6\u53EA\u8BFB\u5236\u54C1\uFF08Core ActionArtifact\uFF09\u843D\u5230\u8FD9\u4E2A**\u6587\u4EF6**\u8DEF\u5F84\uFF1B\u53EA\u8BA4\u516C\u5171\u5951\u7EA6\u4FE1\u5C01\uFF0C\u4E0D\u731C\u5B57\u6BB5\uFF0C\u4E5F\u4E0D\u6539\u53D8\u98CE\u9669\u5224\u6863"
13697
+ ).option("--artifact-force", "\u76EE\u6807\u5DF2\u5B58\u5728\u65F6\u624D\u9700\u8981\u5B83\u2014\u2014\u9ED8\u8BA4\u62D2\u7EDD\u8986\u76D6\uFF0C\u514D\u5F97\u628A\u4E0A\u4E00\u8F6E\u7684\u8BC1\u636E\u6084\u6084\u6362\u6389").action((spec, opts) => actionCommand(spec, opts));
13892
13698
  program.command("create <Model>").description("\u521B\u5EFA\u4E00\u6761 Model \u8BB0\u5F55\uFF08\u8D70\u540E\u7AEF\u5B8C\u6574\u6821\u9A8C\uFF09").option("--data <JSON>", `\u8BB0\u5F55\u5B57\u6BB5 JSON\uFF0C\u4F8B\u5982 '{"code":"ORG_SALES","name":"\u9500\u552E\u90E8"}'`).option("--data-file <path>", "\u4ECE UTF-8 JSON \u6587\u4EF6\u8BFB\u53D6\u8BB0\u5F55\u5B57\u6BB5\uFF08\u4E0E --data \u4E92\u65A5\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").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").option(
13893
13699
  "--i18n",
13894
13700
  "\u591A\u8BED\u8A00\u5B57\u6BB5\u6309 Map \u5B8C\u6574\u66FF\u6362\uFF08\u952E\u7528 zh-CN / en-US \u8FDE\u5B57\u7B26\u5F62\uFF09\uFF1B\u4E0D\u4F20\u5219\u6309\u5B57\u7B26\u4E32\u53EA\u6539\u5F53\u524D\u8BED\u8A00"