@hcmai/cli 0.4.18 → 0.4.20

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
@@ -523,8 +523,8 @@ var init_TerminalRenderer = __esm({
523
523
  }
524
524
  }
525
525
  /** 来源行(仅子代理触发,agentPath ≥2 段时显示 `↑ 来自 a › b`,对齐 Web)。 */
526
- originLine(path12) {
527
- const segs = path12.split(".").filter(Boolean);
526
+ originLine(path13) {
527
+ const segs = path13.split(".").filter(Boolean);
528
528
  if (segs.length < 2) return "";
529
529
  const names = segs.map((k) => agentDisplayName(k));
530
530
  return chalk.gray(` \u2191 \u6765\u81EA ${names.join(" \u203A ")}`) + "\n";
@@ -1706,8 +1706,8 @@ function agentLabel(agentId) {
1706
1706
  if (/^[0-9a-f]{8}-[0-9a-f-]{27}$/i.test(agentId)) return `agent \u2026${agentId.slice(-4)}`;
1707
1707
  return agentDisplayName(agentId);
1708
1708
  }
1709
- function originLine(path12) {
1710
- const segs = (path12 ?? "").split(".").filter(Boolean);
1709
+ function originLine(path13) {
1710
+ const segs = (path13 ?? "").split(".").filter(Boolean);
1711
1711
  if (segs.length < 2) return null;
1712
1712
  return `\u6765\u81EA ${segs.map((k) => agentDisplayName(k)).join(" \u203A ")}`;
1713
1713
  }
@@ -2229,7 +2229,19 @@ async function loginCommand(args) {
2229
2229
  scopes = record.scopes;
2230
2230
  } else {
2231
2231
  username = args.username ?? await promptText("username: ");
2232
- const password = args.password ?? await promptSecret("password: ");
2232
+ if (args.passwordStdin && args.password) {
2233
+ throw new CliError2({
2234
+ code: CliErrorCode.INVALID_ARGUMENT,
2235
+ message: "--password \u4E0E --password-stdin \u53EA\u80FD\u4E8C\u9009\u4E00"
2236
+ });
2237
+ }
2238
+ if (args.password) {
2239
+ process.stderr.write("[hcm] WARNING: --password <p> \u4F1A\u6CC4\u6F0F\u5230 shell history / ps aux\u3002\u63A8\u8350 --password-stdin\u3002\n");
2240
+ }
2241
+ const password = args.passwordStdin ? await readStdin() : args.password ?? await promptSecret("password: ");
2242
+ if (args.passwordStdin && !password) {
2243
+ throw new CliError2({ code: CliErrorCode.INVALID_ARGUMENT, message: "--password-stdin \u8BFB\u5230\u7684\u5BC6\u7801\u4E3A\u7A7A" });
2244
+ }
2233
2245
  if (!username || !password) {
2234
2246
  throw new CliError2({
2235
2247
  code: CliErrorCode.MISSING_FLAG,
@@ -2644,6 +2656,7 @@ async function queryCommand(model, args) {
2644
2656
  const dsl = {};
2645
2657
  if (args.filter) dsl.filter = parseJsonOrThrow(args.filter, "--filter");
2646
2658
  if (args.sort) dsl.sort = parseJsonOrThrow(args.sort, "--sort");
2659
+ if (args.additions) dsl.additions = parseAdditionsOrThrow(args.additions);
2647
2660
  if (args.fields) dsl.fields = args.fields.split(",").map((s) => s.trim());
2648
2661
  if (args.keyword) dsl.keyword = args.keyword;
2649
2662
  if (args.limit) dsl.limit = Number(args.limit);
@@ -2652,13 +2665,7 @@ async function queryCommand(model, args) {
2652
2665
  const client3 = HcmClient.fromAuthContext(await getActiveAuthContextFromCli(args));
2653
2666
  const result = await client3.query(model, dsl);
2654
2667
  const fmt = args.output ?? "table";
2655
- const out = formatRows(result.rows, { format: fmt });
2656
- process.stdout.write(out + "\n");
2657
- if (fmt === "table" && result.total !== void 0) {
2658
- process.stdout.write(`Showing ${result.rows.length} of ${result.total} results.
2659
- `);
2660
- }
2661
- process.exit(0);
2668
+ printQueryResult(result, fmt);
2662
2669
  } catch (e) {
2663
2670
  const err = e;
2664
2671
  if (err?.isAxiosError) {
@@ -2667,6 +2674,25 @@ async function queryCommand(model, args) {
2667
2674
  exitWithError(e);
2668
2675
  }
2669
2676
  }
2677
+ function printQueryResult(result, fmt) {
2678
+ const out = formatRows(result.rows, { format: fmt });
2679
+ process.stdout.write(out + "\n");
2680
+ if (fmt === "table" && result.total !== void 0) {
2681
+ process.stdout.write(`Showing ${result.rows.length} of ${result.total} results.
2682
+ `);
2683
+ }
2684
+ process.exitCode = 0;
2685
+ }
2686
+ function parseAdditionsOrThrow(text) {
2687
+ const parsed = parseJsonOrThrow(text, "--additions");
2688
+ if (!Array.isArray(parsed) || parsed.some((item) => typeof item !== "object" || item === null || Array.isArray(item))) {
2689
+ throw new CliError6({
2690
+ code: CliErrorCode5.INVALID_ARGUMENT,
2691
+ message: `--additions \u5FC5\u987B\u662F JSON \u5BF9\u8C61\u6570\u7EC4\uFF0C\u4F8B\u5982 '[{"key":"employee","model":"Employee"}]'`
2692
+ });
2693
+ }
2694
+ return parsed;
2695
+ }
2670
2696
  function parseJsonOrThrow(text, flag) {
2671
2697
  try {
2672
2698
  return JSON.parse(text);
@@ -3140,7 +3166,7 @@ function launchBrowser(url, platform = process.platform) {
3140
3166
  child.unref();
3141
3167
  }
3142
3168
  async function runOpen(target, args, deps) {
3143
- const path12 = normalizeTarget(target);
3169
+ const path13 = normalizeTarget(target);
3144
3170
  if (!deps.frontend?.trim()) {
3145
3171
  throw new CliError12({
3146
3172
  code: CliErrorCode11.INVALID_ARGUMENT,
@@ -3148,13 +3174,13 @@ async function runOpen(target, args, deps) {
3148
3174
  });
3149
3175
  }
3150
3176
  const { ticket, expiresIn } = await deps.mintTicket();
3151
- const url = buildBrowserLoginUrl(deps.frontend, ticket, path12);
3177
+ const url = buildBrowserLoginUrl(deps.frontend, ticket, path13);
3152
3178
  if (args.printUrl) {
3153
3179
  deps.write(`${url}
3154
3180
  `);
3155
3181
  } else {
3156
3182
  deps.launch(url);
3157
- deps.write(`\u5DF2\u7528\u5F53\u524D\u8EAB\u4EFD\u6253\u5F00 ${path12}\uFF08\u7968\u636E ${expiresIn ?? 60}s \u5185\u6709\u6548\uFF0C\u53EA\u80FD\u7528\u4E00\u6B21\uFF09
3183
+ deps.write(`\u5DF2\u7528\u5F53\u524D\u8EAB\u4EFD\u6253\u5F00 ${path13}\uFF08\u7968\u636E ${expiresIn ?? 60}s \u5185\u6709\u6548\uFF0C\u53EA\u80FD\u7528\u4E00\u6B21\uFF09
3158
3184
  `);
3159
3185
  }
3160
3186
  return { url, expiresIn };
@@ -3246,8 +3272,8 @@ import {
3246
3272
  formatObject as formatObject7,
3247
3273
  fromAxiosError as fromAxiosError9
3248
3274
  } from "@hcmai/sdk";
3249
- function collectYmlFiles(path12) {
3250
- if (statSync(path12).isFile()) return [path12];
3275
+ function collectYmlFiles(path13) {
3276
+ if (statSync(path13).isFile()) return [path13];
3251
3277
  const out = [];
3252
3278
  const walk = (dir) => {
3253
3279
  for (const name of readdirSync(dir).sort()) {
@@ -3256,7 +3282,7 @@ function collectYmlFiles(path12) {
3256
3282
  else if (full.endsWith(".yml") || full.endsWith(".yaml")) out.push(full);
3257
3283
  }
3258
3284
  };
3259
- walk(path12);
3285
+ walk(path13);
3260
3286
  return out.sort();
3261
3287
  }
3262
3288
  var DRY_RUN_CLIENT = {
@@ -3264,9 +3290,9 @@ var DRY_RUN_CLIENT = {
3264
3290
  create: async () => ({ id: "" }),
3265
3291
  update: async () => ({})
3266
3292
  };
3267
- async function importCommand(path12, args) {
3293
+ async function importCommand(path13, args) {
3268
3294
  try {
3269
- const files = collectYmlFiles(path12);
3295
+ const files = collectYmlFiles(path13);
3270
3296
  const fixtures = files.map(
3271
3297
  (f) => parseFixture(readFileSync2(f, "utf8"), relative(process.cwd(), f))
3272
3298
  );
@@ -4503,8 +4529,8 @@ async function scriptManifestValidateCommand(args) {
4503
4529
  if (!args.file) {
4504
4530
  throw new Error("\u7F3A\u5C11 --file\n \u4E0B\u4E00\u6B65\uFF1Ahcm script manifest-validate --file ./manifest.yml");
4505
4531
  }
4506
- const yaml = readFileSync3(args.file, "utf8");
4507
- const result = await withClient2(args, (c) => validateScriptManifest(c.raw(), yaml));
4532
+ const yaml2 = readFileSync3(args.file, "utf8");
4533
+ const result = await withClient2(args, (c) => validateScriptManifest(c.raw(), yaml2));
4508
4534
  emit2(result, args, `\u{1F4CB} manifest \u6821\u9A8C\u5B8C\u6210\uFF1A${args.file}`);
4509
4535
  } catch (e) {
4510
4536
  fail3(e, args);
@@ -5499,7 +5525,7 @@ async function fetchSkillDocument(http, skill, endpoint, base) {
5499
5525
  return {
5500
5526
  id: skill.id,
5501
5527
  markdown: await fetchSkillMarkdown(http, skill.id, base),
5502
- source: `${endpoint}${base}/skills/${skill.id}.md`,
5528
+ source: `${endpoint}${base}/${skill.id}.md`,
5503
5529
  sourceKind: "chiron",
5504
5530
  references
5505
5531
  };
@@ -6230,10 +6256,10 @@ async function metaListCommand(args) {
6230
6256
  fail5(e, args);
6231
6257
  }
6232
6258
  }
6233
- async function metaGetCommand(path12, args) {
6259
+ async function metaGetCommand(path13, args) {
6234
6260
  try {
6235
6261
  const c = await client2(args);
6236
- const content = await getTenantMeta(c.raw(), path12);
6262
+ const content = await getTenantMeta(c.raw(), path13);
6237
6263
  process.stdout.write(content.endsWith("\n") ? content : content + "\n");
6238
6264
  process.exit(0);
6239
6265
  } catch (e) {
@@ -6241,8 +6267,8 @@ async function metaGetCommand(path12, args) {
6241
6267
  }
6242
6268
  }
6243
6269
  var PROBEABLE_META_TYPES = /* @__PURE__ */ new Set(["model", "list", "info", "view", "filter", "page", "wiz", "impexp"]);
6244
- function parseMetaPath(path12) {
6245
- const base = path12.split(/[\\/]/).pop() ?? path12;
6270
+ function parseMetaPath(path13) {
6271
+ const base = path13.split(/[\\/]/).pop() ?? path13;
6246
6272
  if (!/\.(yml|yaml)$/i.test(base)) return {};
6247
6273
  const parts = base.replace(/\.(yml|yaml)$/i, "").split(".");
6248
6274
  return { model: parts[0] || void 0, kind: parts[1] ?? "model", state: parts[2] };
@@ -6259,10 +6285,10 @@ function unverifiableReason(e) {
6259
6285
  if (st == null) return `\u8BF7\u6C42\u6CA1\u53D1\u51FA\u53BB\u6216\u6CA1\u56DE\u6765\uFF08${err.code ?? err.message ?? "\u672A\u77E5"}\uFF09`;
6260
6286
  return void 0;
6261
6287
  }
6262
- async function verifyAfterWrite(c, path12) {
6263
- const { model, kind, state } = parseMetaPath(path12);
6288
+ async function verifyAfterWrite(c, path13) {
6289
+ const { model, kind, state } = parseMetaPath(path13);
6264
6290
  if (!model || !kind) {
6265
- return { status: "unverified", where: "(\u672A\u63A2)", why: `\u4ECE\u8DEF\u5F84 ${path12} \u8BA4\u4E0D\u51FA\u6A21\u578B\u540D/\u5C42\u540D` };
6291
+ return { status: "unverified", where: "(\u672A\u63A2)", why: `\u4ECE\u8DEF\u5F84 ${path13} \u8BA4\u4E0D\u51FA\u6A21\u578B\u540D/\u5C42\u540D` };
6266
6292
  }
6267
6293
  try {
6268
6294
  await clearMetaCache2(c.raw(), model, {});
@@ -6307,7 +6333,7 @@ async function verifyAfterWrite(c, path12) {
6307
6333
  }
6308
6334
  return { status: "ok" };
6309
6335
  }
6310
- async function metaSetCommand(path12, args) {
6336
+ async function metaSetCommand(path13, args) {
6311
6337
  try {
6312
6338
  if (!args.file) {
6313
6339
  throw new CliError19({
@@ -6323,9 +6349,9 @@ async function metaSetCommand(path12, args) {
6323
6349
  process.stdin.on("error", reject);
6324
6350
  }) : await fsp3.readFile(args.file, "utf8");
6325
6351
  if (!args.skipValidate) {
6326
- const result2 = validateMetaContent(path12, content);
6352
+ const result2 = validateMetaContent(path13, content);
6327
6353
  if (result2.issues.length > 0) {
6328
- process.stderr.write(`\u{1F50E} \u5199\u524D\u6821\u9A8C ${path12}\uFF08schema \u7C7B\u578B\uFF1A${result2.kind ?? "\u672A\u8BC6\u522B"}\uFF09
6354
+ process.stderr.write(`\u{1F50E} \u5199\u524D\u6821\u9A8C ${path13}\uFF08schema \u7C7B\u578B\uFF1A${result2.kind ?? "\u672A\u8BC6\u522B"}\uFF09
6329
6355
  `);
6330
6356
  process.stderr.write(formatMetaIssues(result2, " ") + "\n");
6331
6357
  }
@@ -6344,13 +6370,13 @@ async function metaSetCommand(path12, args) {
6344
6370
  if (dryFmt === "json" || dryFmt === "yaml") {
6345
6371
  process.stdout.write(
6346
6372
  formatObject18(
6347
- { dryRun: true, path: path12, bytes: Buffer.byteLength(content), content },
6373
+ { dryRun: true, path: path13, bytes: Buffer.byteLength(content), content },
6348
6374
  { format: dryFmt }
6349
6375
  ) + "\n"
6350
6376
  );
6351
6377
  } else {
6352
6378
  process.stdout.write(
6353
- `[dry-run] \u5C06\u5199\u5165 ${path12}\uFF08${Buffer.byteLength(content)} B\uFF09\u2014\u2014\u672A\u5B9E\u9645\u5199\u5165
6379
+ `[dry-run] \u5C06\u5199\u5165 ${path13}\uFF08${Buffer.byteLength(content)} B\uFF09\u2014\u2014\u672A\u5B9E\u9645\u5199\u5165
6354
6380
  ---
6355
6381
  ${content}
6356
6382
  `
@@ -6363,13 +6389,13 @@ ${content}
6363
6389
  let backupState = "unknown";
6364
6390
  let backupWhy;
6365
6391
  try {
6366
- const prev = await getTenantMeta(c.raw(), path12);
6392
+ const prev = await getTenantMeta(c.raw(), path13);
6367
6393
  if (!prev || prev.trim() === "") {
6368
6394
  backupState = "absent";
6369
6395
  } else {
6370
6396
  backupFile = nodePath.join(
6371
6397
  os3.tmpdir(),
6372
- `hcm-meta-backup-${Date.now()}-${path12.replace(/[\\/]/g, "_")}`
6398
+ `hcm-meta-backup-${Date.now()}-${path13.replace(/[\\/]/g, "_")}`
6373
6399
  );
6374
6400
  await fsp3.writeFile(backupFile, prev, "utf8");
6375
6401
  backupState = "saved";
@@ -6384,22 +6410,22 @@ ${content}
6384
6410
  backupWhy = `HTTP ${st ?? "-"}${err.code ? ` ${err.code}` : ""}${err.message ? `\uFF1A${err.message}` : ""}`;
6385
6411
  }
6386
6412
  }
6387
- const result = await saveTenantMeta(c.raw(), path12, content);
6413
+ const result = await saveTenantMeta(c.raw(), path13, content);
6388
6414
  const fmt = args.output ?? "json";
6389
- if (fmt !== "json") process.stdout.write(`\u2705 \u5DF2\u5199\u5165 ${path12}
6415
+ if (fmt !== "json") process.stdout.write(`\u2705 \u5DF2\u5199\u5165 ${path13}
6390
6416
  `);
6391
6417
  const restoreHint = backupState === "saved" && backupFile ? ` \u65E7\u5185\u5BB9\u5DF2\u5B58\uFF1A${backupFile}
6392
- \u653E\u56DE\u53BB\uFF1Ahcm meta set ${path12} --file ${backupFile}${connFlags(args)}
6393
- ` : backupState === "absent" ? ` \u8FD9\u4E00\u5C42\u6B64\u524D\u6CA1\u6709\u8986\u76D6\uFF08\u5DF2\u8BC1\u5B9E\uFF09\uFF0C\u6062\u590D\u5373\u5220\u9664\uFF1Ahcm meta delete ${path12}${connFlags(args)}
6418
+ \u653E\u56DE\u53BB\uFF1Ahcm meta set ${path13} --file ${backupFile}${connFlags(args)}
6419
+ ` : backupState === "absent" ? ` \u8FD9\u4E00\u5C42\u6B64\u524D\u6CA1\u6709\u8986\u76D6\uFF08\u5DF2\u8BC1\u5B9E\uFF09\uFF0C\u6062\u590D\u5373\u5220\u9664\uFF1Ahcm meta delete ${path13}${connFlags(args)}
6394
6420
  ` : ` \u26A0\uFE0F \u65E7\u5185\u5BB9**\u6CA1\u5907\u4EFD\u6210**\uFF08${backupWhy ?? "\u539F\u56E0\u672A\u77E5"}\uFF09\u2014\u2014\u65E2\u4E0D\u77E5\u9053\u6B64\u524D\u6709\u6CA1\u6709\u8986\u76D6\uFF0C\u4E5F\u5C31\u7ED9\u4E0D\u51FA\u6062\u590D\u547D\u4EE4\u3002
6395
- \u5148\u81EA\u5DF1\u8BFB\u4E00\u904D\u786E\u8BA4\uFF1Ahcm meta get ${path12}${connFlags(args)}
6421
+ \u5148\u81EA\u5DF1\u8BFB\u4E00\u904D\u786E\u8BA4\uFF1Ahcm meta get ${path13}${connFlags(args)}
6396
6422
  `;
6397
6423
  if (args.verify === false) {
6398
6424
  process.stderr.write(
6399
6425
  "\u26A0\uFE0F --no-verify\uFF1A**\u6CA1\u6709**\u9A8C\u8FC7\u670D\u52A1\u7AEF\u8BFB\u4E0D\u8BFB\u5F97\u52A8\u8FD9\u4EFD meta\u3002\u300C\u5199\u5165\u6210\u529F\u300D\u53EA\u8BF4\u660E\u5B57\u8282\u6536\u4E0B\u4E86\u3002\n \u81EA\u5DF1\u8865\uFF1Ahcm cache clear-meta <Model> \u540E\u6253\u5F00\u9875\u9762\u770B\u4E00\u773C\u3002\n" + restoreHint
6400
6426
  );
6401
6427
  } else {
6402
- const outcome = await verifyAfterWrite(c, path12);
6428
+ const outcome = await verifyAfterWrite(c, path13);
6403
6429
  if (outcome.status === "broken") {
6404
6430
  const human = explainJacksonError(outcome.raw);
6405
6431
  process.stderr.write(
@@ -6431,19 +6457,19 @@ ${content}
6431
6457
  fail5(e, args);
6432
6458
  }
6433
6459
  }
6434
- async function metaDeleteCommand(path12, args) {
6460
+ async function metaDeleteCommand(path13, args) {
6435
6461
  try {
6436
6462
  if (!args.yes) {
6437
- const ok = await promptConfirm(`\u5C06\u5220\u9664\u5143\u6570\u636E ${path12}\uFF0C\u6B64\u64CD\u4F5C\u4E0D\u53EF\u9006\u3002\u7EE7\u7EED\uFF1F`);
6463
+ const ok = await promptConfirm(`\u5C06\u5220\u9664\u5143\u6570\u636E ${path13}\uFF0C\u6B64\u64CD\u4F5C\u4E0D\u53EF\u9006\u3002\u7EE7\u7EED\uFF1F`);
6438
6464
  if (!ok) {
6439
6465
  process.stderr.write("\u5DF2\u53D6\u6D88\n");
6440
6466
  process.exit(1);
6441
6467
  }
6442
6468
  }
6443
6469
  const c = await client2(args);
6444
- const result = await deleteTenantMeta(c.raw(), path12);
6470
+ const result = await deleteTenantMeta(c.raw(), path13);
6445
6471
  const fmt = args.output ?? "json";
6446
- if (fmt !== "json") process.stdout.write(`\u{1F5D1}\uFE0F \u5DF2\u5220\u9664 ${path12}
6472
+ if (fmt !== "json") process.stdout.write(`\u{1F5D1}\uFE0F \u5DF2\u5220\u9664 ${path13}
6447
6473
  `);
6448
6474
  process.stdout.write(formatObject18(result, { format: fmt }) + "\n");
6449
6475
  process.exit(0);
@@ -6451,7 +6477,7 @@ async function metaDeleteCommand(path12, args) {
6451
6477
  fail5(e, args);
6452
6478
  }
6453
6479
  }
6454
- async function metaValidateCommand(path12, args) {
6480
+ async function metaValidateCommand(path13, args) {
6455
6481
  try {
6456
6482
  if (!args.file) {
6457
6483
  throw new CliError19({
@@ -6466,13 +6492,13 @@ async function metaValidateCommand(path12, args) {
6466
6492
  process.stdin.on("end", () => resolve4(buf));
6467
6493
  process.stdin.on("error", reject);
6468
6494
  }) : await fsp3.readFile(args.file, "utf8");
6469
- const result = validateMetaContent(path12, content);
6495
+ const result = validateMetaContent(path13, content);
6470
6496
  const fmt = args.output ?? "table";
6471
6497
  if (fmt === "json" || fmt === "yaml") {
6472
6498
  process.stdout.write(
6473
6499
  formatObject18(
6474
6500
  {
6475
- path: path12,
6501
+ path: path13,
6476
6502
  kind: result.kind,
6477
6503
  schemaKnown: result.schemaKnown,
6478
6504
  schemaSourceCommit: META_SCHEMA_SOURCE_COMMIT,
@@ -6484,7 +6510,7 @@ async function metaValidateCommand(path12, args) {
6484
6510
  );
6485
6511
  } else {
6486
6512
  process.stdout.write(
6487
- `\u{1F50E} ${path12}\uFF08schema \u7C7B\u578B\uFF1A${result.kind ?? "\u672A\u8BC6\u522B"}\uFF0C\u6765\u6E90 ${META_SCHEMA_SOURCE_COMMIT.slice(0, 8)}\uFF09
6513
+ `\u{1F50E} ${path13}\uFF08schema \u7C7B\u578B\uFF1A${result.kind ?? "\u672A\u8BC6\u522B"}\uFF0C\u6765\u6E90 ${META_SCHEMA_SOURCE_COMMIT.slice(0, 8)}\uFF09
6488
6514
  `
6489
6515
  );
6490
6516
  process.stdout.write(
@@ -7939,6 +7965,7 @@ import { existsSync as existsSync2, readFileSync as readFileSync5 } from "fs";
7939
7965
  import { join as pathJoin } from "path";
7940
7966
  import {
7941
7967
  HcmClient as HcmClient20,
7968
+ classifyEffect,
7942
7969
  formatObject as formatObject20
7943
7970
  } from "@hcmai/sdk";
7944
7971
 
@@ -7962,6 +7989,11 @@ var GUARDED_EXECUTOR_REASON_CODES = /* @__PURE__ */ new Set([
7962
7989
  "setting-write",
7963
7990
  "credential-reset",
7964
7991
  "action-write",
7992
+ // 三态 effect 的 UNKNOWN / 未识别值都按最坏情况视作写操作,走与 WRITES
7993
+ // 完全相同的 prepare + execute 通道。分类函数已经返回 R2 guarded;这里漏登记
7994
+ // 会把 guardedExecutionAvailable 又翻回 false,造成 reason 与 modePolicy 自相矛盾。
7995
+ "action-effect-undetermined",
7996
+ "action-effect-unrecognized",
7965
7997
  "workspace-create",
7966
7998
  "workspace-activate",
7967
7999
  // 这两个的载荷是**任意文件 / 整棵目录**,此前刻意不收——绑不住就意味着
@@ -7987,7 +8019,11 @@ var GUARDED_EXECUTOR_REASON_CODES = /* @__PURE__ */ new Set([
7987
8019
  // 🔴 客户存量组织导入的整条链就卡在这一个上:2026-09-01 演示环境租户 15,
7988
8020
  // 531 条组织机构 dry-run 全绿(静态校验 0 失败),正式导入被
7989
8021
  // 「该 R2 命令不在首批受控执行器支持面」拦死,一个写请求都没发出去。
7990
- "import-write"
8022
+ "import-write",
8023
+ // 报表 / 套打模板回传要先 upload 拿 documentId,再挂到业务对象。文件路径是
8024
+ // 固定位置参数,prepare 会钉住项目内普通文件的摘要,execute 前重算后才单次执行。
8025
+ // 2026-09-02 弹性报表顾问仿真已证实这条交付链会在缺受控执行器时中断。
8026
+ "document-upload"
7991
8027
  ]);
7992
8028
  function normalizeAssessedArgv(inputArgv) {
7993
8029
  let rest = inputArgv;
@@ -8296,8 +8332,35 @@ function classifyAction(policy) {
8296
8332
  reason: "Core \u58F0\u660E\u8BE5 Action \u4E3A\u53EA\u8BFB\uFF0C\u4E0E Moirai \u7684\u53EA\u8BFB Action \u8DEF\u5F84\u4E00\u81F4\uFF0C\u53EF\u76F4\u63A5\u6267\u884C\u3002"
8297
8333
  };
8298
8334
  }
8335
+ if (policy.effect === "declared-unknown") {
8336
+ return {
8337
+ risk: "R2",
8338
+ execution: "guarded",
8339
+ effect: "undetermined",
8340
+ reasonCode: "action-effect-undetermined",
8341
+ reason: "\u4EA7\u54C1\u4FA7\u628A\u8FD9\u4E2A Action \u58F0\u660E\u6210 effect=UNKNOWN\uFF1A**\u6CA1\u4EBA\u5224\u8FC7**\u5B83\u5199\u4E0D\u5199\u5E93\u3002\u6309\u6700\u574F\u60C5\u51B5\u8D70\u53D7\u63A7\u6267\u884C\uFF08\u4E0E\u4F1A\u5199\u7684 Action \u540C\u4E00\u6761\u8DEF\u5F84\uFF09\uFF0C\u4F46\u5B83\u4E0D\u7B49\u4E8E\u300C\u786E\u8BA4\u4F1A\u5199\u300D\u3002next_step=\u53BB\u4EA7\u54C1\u4FA7\u7ED9\u8FD9\u4E2A @ClassAction/@ObjectAction \u628A effect \u5224\u6389\uFF08READ_ONLY / WRITES\uFF09\uFF0C\u800C\u4E0D\u662F\u5728 CLI \u8FD9\u8FB9\u653E\u5BBD\u3002"
8342
+ };
8343
+ }
8344
+ if (policy.effect === "unrecognized-effect") {
8345
+ return {
8346
+ risk: "R2",
8347
+ execution: "guarded",
8348
+ effect: "undetermined",
8349
+ reasonCode: "action-effect-unrecognized",
8350
+ reason: `Core \u9001\u6765\u7684 effect \u53D6\u503C ${describeEffectRaw(policy.effectRaw)} \u4E0D\u5728 READ_ONLY / WRITES / UNKNOWN \u4E09\u6001\u5185\uFF08\u62FC\u5199\u6F02\u79FB\uFF1F\u670D\u52A1\u7AEF\u6BD4\u672C CLI \u65B0\u3001\u591A\u4E86\u4E00\u6001\uFF1F\uFF09\u3002fail-closed\uFF1A\u6309 UNKNOWN \u5904\u7F6E\u8D70\u53D7\u63A7\u6267\u884C\uFF0C\u4E0D\u731C\u6210\u53EA\u8BFB\u3002next_step=\u62FF\u8FD9\u4E2A\u539F\u503C\u53BB\u5BF9\u4EA7\u54C1\u4FA7\u7684 ActionEffect \u5B9A\u4E49\uFF0C\u5FC5\u8981\u65F6\u5347\u7EA7 CLI\u3002`
8351
+ };
8352
+ }
8299
8353
  return guarded("tenant-write", "action-write");
8300
8354
  }
8355
+ function describeEffectRaw(raw) {
8356
+ if (raw === null) return "null";
8357
+ if (typeof raw === "string") return JSON.stringify(raw);
8358
+ try {
8359
+ return `${JSON.stringify(raw)}\uFF08${typeof raw}\uFF09`;
8360
+ } catch {
8361
+ return `<\u65E0\u6CD5\u5E8F\u5217\u5316\u7684 ${typeof raw}>`;
8362
+ }
8363
+ }
8301
8364
  function forbidden(reasonCode, reason) {
8302
8365
  return { risk: "R3", execution: "forbidden", effect: reasonCode, reasonCode, reason };
8303
8366
  }
@@ -8350,6 +8413,151 @@ function isPlainObject(value) {
8350
8413
  return typeof value === "object" && value !== null && !Array.isArray(value);
8351
8414
  }
8352
8415
 
8416
+ // src/commands/delivery-project-config.ts
8417
+ import yaml, { JSON_SCHEMA } from "js-yaml";
8418
+ var DELIVERY_MODES = ["plan-only", "controlled"];
8419
+ function isDeliveryMode(value) {
8420
+ return value === "plan-only" || value === "controlled";
8421
+ }
8422
+ function parseProjectDeliveryModes(content) {
8423
+ let loaded;
8424
+ try {
8425
+ loaded = yaml.load(content, { schema: JSON_SCHEMA });
8426
+ } catch (cause) {
8427
+ throw new Error(`project.yml \u4E0D\u662F\u5408\u6CD5 YAML\uFF1A${String(cause.message)}`);
8428
+ }
8429
+ if (!isRecord(loaded)) throw new Error("project.yml \u9876\u5C42\u5FC5\u987B\u662F\u5BF9\u8C61");
8430
+ const version = loaded.schemaVersion;
8431
+ const raw = loaded.deliveryMode;
8432
+ if (isDeliveryMode(raw)) {
8433
+ if (version !== void 0 && version !== 1) {
8434
+ throw new Error("project.yml \u7684\u6807\u91CF deliveryMode \u53EA\u5C5E\u4E8E schemaVersion 1");
8435
+ }
8436
+ return { kind: "legacy", mode: raw };
8437
+ }
8438
+ if (version !== 2) {
8439
+ throw new Error("project.yml \u7684\u5206\u73AF\u5883 deliveryMode \u5FC5\u987B\u58F0\u660E schemaVersion: 2");
8440
+ }
8441
+ if (raw !== null && raw !== void 0 && !isRecord(raw)) {
8442
+ throw new Error("project.yml \u7684 deliveryMode \u5FC5\u987B\u662F\u201C\u73AF\u5883\u522B\u540D \u2192 \u6A21\u5F0F\u201D\u7684\u6620\u5C04");
8443
+ }
8444
+ const modes = /* @__PURE__ */ Object.create(null);
8445
+ for (const [environment, mode] of Object.entries(raw ?? {})) {
8446
+ if (!environment.trim()) throw new Error("project.yml \u7684 deliveryMode \u542B\u7A7A\u73AF\u5883\u522B\u540D");
8447
+ if (!isDeliveryMode(mode)) {
8448
+ throw new Error(
8449
+ `project.yml \u4E2D\u73AF\u5883 ${JSON.stringify(environment)} \u7684 deliveryMode \u975E\u6CD5\uFF1A${String(mode)}`
8450
+ );
8451
+ }
8452
+ modes[environment] = mode;
8453
+ }
8454
+ return { kind: "per-environment", modes };
8455
+ }
8456
+ function deliveryModeForEnvironment(content, environment) {
8457
+ assertEnvironment(environment);
8458
+ const parsed = parseProjectDeliveryModes(content);
8459
+ return parsed.kind === "per-environment" ? parsed.modes[environment] ?? null : null;
8460
+ }
8461
+ function setDeliveryModeForEnvironment(content, environment, mode) {
8462
+ assertEnvironment(environment);
8463
+ const parsed = parseProjectDeliveryModes(content);
8464
+ const hadFinalNewline = content.endsWith("\n");
8465
+ const lines = content.split("\n");
8466
+ if (hadFinalNewline) lines.pop();
8467
+ if (parsed.kind === "legacy") {
8468
+ const scalarIndex = lines.findIndex(
8469
+ (line) => /^deliveryMode:\s*(?:"(?:plan-only|controlled)"|'(?:plan-only|controlled)'|(?:plan-only|controlled))\s*(?:#.*)?$/.test(line)
8470
+ );
8471
+ if (scalarIndex < 0) {
8472
+ throw new Error("project.yml \u7684\u65E7 deliveryMode \u4E0D\u662F\u53EF\u5B89\u5168\u8FC1\u79FB\u7684\u9876\u5C42\u6807\u91CF\u884C");
8473
+ }
8474
+ const inlineComment = lines[scalarIndex]?.match(/\s+(#.*)$/)?.[1];
8475
+ lines.splice(
8476
+ scalarIndex,
8477
+ 1,
8478
+ `deliveryMode:${inlineComment ? ` ${inlineComment}` : ""}`,
8479
+ renderModeEntry(environment, mode)
8480
+ );
8481
+ const versionIndex = lines.findIndex((line) => /^schemaVersion:\s*/.test(line));
8482
+ if (versionIndex >= 0) {
8483
+ const versionComment = lines[versionIndex]?.match(/\s+(#.*)$/)?.[1];
8484
+ lines[versionIndex] = `schemaVersion: 2${versionComment ? ` ${versionComment}` : ""}`;
8485
+ } else {
8486
+ lines.splice(scalarIndex, 0, "schemaVersion: 2");
8487
+ }
8488
+ return {
8489
+ content: finishLines(lines, hadFinalNewline),
8490
+ previous: parsed.mode,
8491
+ migratedLegacy: true
8492
+ };
8493
+ }
8494
+ const sectionStart = lines.findIndex((line) => /^deliveryMode:\s*(?:#.*)?$/.test(line));
8495
+ if (sectionStart < 0) {
8496
+ throw new Error("project.yml \u7F3A\u5C11\u53EF\u5B89\u5168\u66F4\u65B0\u7684\u9876\u5C42 deliveryMode \u6620\u5C04");
8497
+ }
8498
+ let sectionEnd = lines.length;
8499
+ for (let index = sectionStart + 1; index < lines.length; index += 1) {
8500
+ const line = lines[index] ?? "";
8501
+ if (line.trim() === "" || line.trimStart().startsWith("#")) continue;
8502
+ if (!/^\s/.test(line)) {
8503
+ sectionEnd = index;
8504
+ break;
8505
+ }
8506
+ }
8507
+ let lastEntry = sectionStart;
8508
+ let targetIndex = -1;
8509
+ for (let index = sectionStart + 1; index < sectionEnd; index += 1) {
8510
+ const line = lines[index] ?? "";
8511
+ if (!/^ {2}\S/.test(line) || /^ {4}/.test(line)) continue;
8512
+ const entry = parseDirectModeEntry(line);
8513
+ if (!entry) continue;
8514
+ lastEntry = index;
8515
+ if (entry.environment === environment) targetIndex = index;
8516
+ }
8517
+ const previous = parsed.modes[environment] ?? null;
8518
+ if (previous !== null && targetIndex < 0) {
8519
+ throw new Error(
8520
+ `project.yml \u4E2D ${JSON.stringify(environment)} \u4F7F\u7528\u4E86\u65E0\u6CD5\u5B89\u5168\u5C31\u5730\u6539\u5199\u7684 YAML \u5E03\u5C40`
8521
+ );
8522
+ }
8523
+ if (targetIndex >= 0) {
8524
+ const trailingComment = lines[targetIndex]?.match(
8525
+ /(?:"(?:plan-only|controlled)"|'(?:plan-only|controlled)'|(?:plan-only|controlled))\s+(#.*)$/
8526
+ )?.[1];
8527
+ lines[targetIndex] = `${renderModeEntry(environment, mode)}${trailingComment ? ` ${trailingComment}` : ""}`;
8528
+ } else {
8529
+ lines.splice(lastEntry + 1, 0, renderModeEntry(environment, mode));
8530
+ }
8531
+ return {
8532
+ content: finishLines(lines, hadFinalNewline),
8533
+ previous,
8534
+ migratedLegacy: false
8535
+ };
8536
+ }
8537
+ function parseDirectModeEntry(line) {
8538
+ try {
8539
+ const value = yaml.load(line.trim(), { schema: JSON_SCHEMA });
8540
+ if (!isRecord(value)) return null;
8541
+ const entries = Object.entries(value);
8542
+ if (entries.length !== 1 || !isDeliveryMode(entries[0]?.[1])) return null;
8543
+ return { environment: entries[0][0], mode: entries[0][1] };
8544
+ } catch {
8545
+ return null;
8546
+ }
8547
+ }
8548
+ function renderModeEntry(environment, mode) {
8549
+ return ` ${JSON.stringify(environment)}: ${mode}`;
8550
+ }
8551
+ function finishLines(lines, finalNewline) {
8552
+ return `${lines.join("\n")}${finalNewline ? "\n" : ""}`;
8553
+ }
8554
+ function assertEnvironment(environment) {
8555
+ if (!environment.trim()) throw new Error("\u73AF\u5883\u522B\u540D\u4E0D\u80FD\u4E3A\u7A7A");
8556
+ }
8557
+ function isRecord(value) {
8558
+ return value !== null && typeof value === "object" && !Array.isArray(value);
8559
+ }
8560
+
8353
8561
  // src/commands/delivery-action-policy.ts
8354
8562
  async function assessEffectiveDeliveryCommand(inputArgv, dependencies = {}) {
8355
8563
  const local = assessDeliveryCommand(inputArgv);
@@ -8361,25 +8569,32 @@ async function assessEffectiveDeliveryCommand(inputArgv, dependencies = {}) {
8361
8569
  const resolution = await (dependencies.resolveAction ?? resolveCoreAction)(request);
8362
8570
  return assessDeliveryCommand(inputArgv, { actionResolution: resolution });
8363
8571
  }
8364
- function readDeliveryMode(projectRoot = ".") {
8572
+ function readDeliveryMode(projectRoot = ".", environment) {
8365
8573
  const file = pathJoin(projectRoot, ".hcm-delivery", "project.yml");
8366
8574
  if (!existsSync2(file)) return null;
8367
- const match = readFileSync5(file, "utf8").match(
8368
- /^deliveryMode:\s*(?:"(plan-only|controlled)"|'(plan-only|controlled)'|(plan-only|controlled))\s*$/m
8369
- );
8370
- return match?.[1] ?? match?.[2] ?? match?.[3] ?? null;
8575
+ try {
8576
+ return deliveryModeForEnvironment(readFileSync5(file, "utf8"), environment);
8577
+ } catch {
8578
+ return null;
8579
+ }
8371
8580
  }
8372
8581
  function withProjectReadiness(assessment, projectRoot = ".") {
8373
8582
  const projectFile = pathJoin(projectRoot, ".hcm-delivery", "project.yml");
8374
8583
  const projectInitialized = existsSync2(projectFile);
8375
- const deliveryMode = readDeliveryMode(projectRoot);
8376
- if (projectInitialized && deliveryMode === "plan-only" && assessment.guardedExecutionAvailable) {
8584
+ const environment = assessment.environment?.envAlias;
8585
+ const deliveryMode = environment ? readDeliveryMode(projectRoot, environment) : null;
8586
+ if (projectInitialized && deliveryMode !== "controlled" && assessment.guardedExecutionAvailable) {
8587
+ const requirements2 = [...assessment.requirements ?? []];
8588
+ if (!requirements2.includes("environment-delivery-mode")) {
8589
+ requirements2.push("environment-delivery-mode");
8590
+ }
8377
8591
  return {
8378
8592
  ...assessment,
8379
8593
  projectInitialized,
8380
8594
  deliveryMode,
8595
+ requirements: requirements2,
8381
8596
  modePolicy: assessment.modePolicy ? { ...assessment.modePolicy, controlled: "deny" } : assessment.modePolicy,
8382
- projectNextStep: "\u672C\u9879\u76EE\u7684\u4EA4\u4ED8\u6A21\u5F0F\u662F plan-only\uFF0C\u53EA\u51FA\u8BA1\u5212\u4E0D\u6267\u884C\u3002\u8981\u771F\u6B63\u6267\u884C R2\uFF0C\u9700\u9879\u76EE\u8D1F\u8D23\u4EBA\u6388\u6743\u540E\u6539\u4E3A controlled\uFF08hcm delivery init --mode controlled --force \u4F1A\u8986\u76D6\u6574\u4EFD\u9879\u76EE\u914D\u7F6E\uFF0C\u8BF7\u786E\u8BA4\u540E\u518D\u6267\u884C\uFF09"
8597
+ projectNextStep: deliveryMode === "plan-only" ? `\u73AF\u5883 ${environment} \u7684\u4EA4\u4ED8\u6A21\u5F0F\u662F plan-only\uFF0C\u53EA\u51FA\u8BA1\u5212\u4E0D\u6267\u884C\u3002\u8981\u771F\u6B63\u6267\u884C R2\uFF0C\u9700\u9879\u76EE\u8D1F\u8D23\u4EBA\u6388\u6743\u540E\u53EA\u5207\u6362\u8FD9\u4E2A\u73AF\u5883\uFF08hcm delivery mode --env ${environment} --set controlled\uFF09` : environment ? `\u73AF\u5883 ${environment} \u5C1A\u672A\u767B\u8BB0\u5408\u6CD5\u4EA4\u4ED8\u6A21\u5F0F\uFF0C\u5DF2 fail-closed\u3002\u5148\u6267\u884C hcm delivery mode --env ${environment} --set plan-only` : "R2 \u547D\u4EE4\u5FC5\u987B\u5728\u88AB\u8BC4\u4F30\u7684 argv \u4E2D\u663E\u5F0F\u5305\u542B --env <\u73AF\u5883\u522B\u540D>"
8383
8598
  };
8384
8599
  }
8385
8600
  if (projectInitialized || !assessment.guardedExecutionAvailable) {
@@ -8408,7 +8623,7 @@ async function resolveCoreAction(request) {
8408
8623
  profile: request.profile
8409
8624
  });
8410
8625
  const description = await HcmClient20.fromAuthContext(auth).describe(request.model);
8411
- const named = description.actions.filter((action2) => action2.name === request.action);
8626
+ const named = description.actions.filter((action) => action.name === request.action);
8412
8627
  if (named.length === 0) {
8413
8628
  const degraded = description.effectiveActionsAvailable ? "" : `\u26A0\uFE0F \u672C\u6B21\u6BD4\u5BF9\u4E0D\u542B\u811A\u672C Action\u2014\u2014${description.effectiveActionsNote ?? "\u539F\u56E0\u672A\u77E5"}\u3002`;
8414
8629
  return failed(
@@ -8416,7 +8631,7 @@ async function resolveCoreAction(request) {
8416
8631
  `Core \u5143\u6570\u636E\u91CC\u6CA1\u6709 ${request.model}.${request.action} \u8FD9\u4E2A Action\u3002${degraded}next_step=\u7528 \`hcm describe ${request.model}\` \u770B\u5B83\u5217\u51FA\u7684 Action \u540D\uFF08\u811A\u672C Action \u4F1A\u6807 [script]\uFF09`
8417
8632
  );
8418
8633
  }
8419
- const matches = request.explicitShape ? named.filter((action2) => matchesRequest(action2, request)) : named;
8634
+ const matches = request.explicitShape ? named.filter((action) => matchesRequest(action, request)) : named;
8420
8635
  if (matches.length === 0) {
8421
8636
  const shapes = named.map((a) => `scope=${a.scope ?? "?"} method=${(a.httpMethod ?? "?").toUpperCase()}`).join("\uFF1B");
8422
8637
  return failed(
@@ -8430,22 +8645,7 @@ async function resolveCoreAction(request) {
8430
8645
  `${request.model}.${request.action} \u5728\u5143\u6570\u636E\u91CC\u6709\u591A\u79CD\u5F62\u6001\uFF0C\u65E0\u6CD5\u552F\u4E00\u5224\u5B9A\u3002next_step=\u7528 --scope \u4E0E --method \u6307\u660E\u8981\u8C03\u54EA\u4E00\u4E2A`
8431
8646
  );
8432
8647
  }
8433
- const action = matches[0];
8434
- if (typeof action.readOnly !== "boolean") {
8435
- return failed(
8436
- "action-readonly-unclassified",
8437
- "Core \u672A\u8FD4\u56DE Action \u7684 readOnly \u58F0\u660E\uFF0C\u6309\u5B89\u5168\u9ED8\u8BA4\u62D2\u7EDD\u6267\u884C\u3002"
8438
- );
8439
- }
8440
- return {
8441
- status: "resolved",
8442
- policy: {
8443
- scope: action.scope ?? request.scope,
8444
- httpMethod: (action.httpMethod ?? request.httpMethod).toUpperCase(),
8445
- readOnly: action.readOnly,
8446
- ...action.source ? { source: action.source } : {}
8447
- }
8448
- };
8648
+ return policyFromActionMeta(matches[0], request);
8449
8649
  } catch {
8450
8650
  return failed(
8451
8651
  "action-metadata-unavailable",
@@ -8453,6 +8653,32 @@ async function resolveCoreAction(request) {
8453
8653
  );
8454
8654
  }
8455
8655
  }
8656
+ function policyFromActionMeta(action, request) {
8657
+ const shape = {
8658
+ scope: action.scope ?? request.scope,
8659
+ httpMethod: (action.httpMethod ?? request.httpMethod).toUpperCase(),
8660
+ ...action.source ? { source: action.source } : {}
8661
+ };
8662
+ const effectClass = classifyEffect(action.effect);
8663
+ if (effectClass === "absent") {
8664
+ if (typeof action.readOnly !== "boolean") {
8665
+ return failed(
8666
+ "action-readonly-unclassified",
8667
+ "Core \u672A\u8FD4\u56DE Action \u7684 effect \u4E09\u6001\u58F0\u660E\uFF0C\u4E5F\u6CA1\u6709\u56DE\u843D\u7528\u7684 readOnly \u5E03\u5C14\uFF0C\u6309\u5B89\u5168\u9ED8\u8BA4\u62D2\u7EDD\u6267\u884C\u3002"
8668
+ );
8669
+ }
8670
+ return { status: "resolved", policy: { ...shape, readOnly: action.readOnly } };
8671
+ }
8672
+ return {
8673
+ status: "resolved",
8674
+ policy: {
8675
+ ...shape,
8676
+ effect: effectClass,
8677
+ ...effectClass === "unrecognized-effect" ? { effectRaw: action.effect } : {},
8678
+ readOnly: effectClass === "read-only"
8679
+ }
8680
+ };
8681
+ }
8456
8682
  function matchesRequest(action, request) {
8457
8683
  return action.name === request.action && action.httpMethod?.toUpperCase() === request.httpMethod && action.scope?.toLowerCase() === request.scope;
8458
8684
  }
@@ -8496,40 +8722,367 @@ function flagValue2(argv, flag) {
8496
8722
 
8497
8723
  // src/commands/delivery-init.ts
8498
8724
  init_exit();
8725
+ import { promises as fs7 } from "fs";
8726
+ import path7 from "path";
8727
+ import {
8728
+ formatObject as formatObject21,
8729
+ loadEnv as loadEnv9,
8730
+ loadGlobalConfig as loadGlobalConfig9,
8731
+ resolveActiveEnv as resolveActiveEnv5
8732
+ } from "@hcmai/sdk";
8733
+
8734
+ // src/commands/delivery-project-scaffold.ts
8499
8735
  import { promises as fs6 } from "fs";
8500
8736
  import path6 from "path";
8501
- import { formatObject as formatObject21 } from "@hcmai/sdk";
8502
- var MODES = ["plan-only", "controlled"];
8503
- var SCAFFOLD_DIRS = ["work", "decisions", "evidence"];
8504
- function renderProjectYml(mode) {
8737
+ var AGENT_BEGIN = "<!-- hcm-delivery-project:begin -->";
8738
+ var AGENT_END = "<!-- hcm-delivery-project:end -->";
8739
+ var GITIGNORE_BEGIN = "# >>> hcm delivery local state >>>";
8740
+ var GITIGNORE_END = "# <<< hcm delivery local state <<<";
8741
+ var DELIVERY_PROJECT_DIRECTORIES = [
8742
+ "work",
8743
+ "decisions",
8744
+ "evidence",
8745
+ "hcm-skills",
8746
+ "\u5BA2\u6237\u8D44\u6599",
8747
+ "\u9700\u6C42",
8748
+ "\u4EA4\u4ED8\u7269",
8749
+ "\u8BC1\u636E",
8750
+ "\u51B3\u7B56",
8751
+ "\u6848\u4F8B"
8752
+ ];
8753
+ function renderEnvironmentYml(environment, config2, initialMode) {
8754
+ const endpoint = config2?.endpoint ?? "REPLACE_ME";
8755
+ const frontend = config2?.frontend ?? endpoint;
8756
+ const tenant2 = config2?.tenantId ?? "1";
8757
+ return [
8758
+ "# \u5BA2\u6237\u9879\u76EE\u5171\u4EAB\u73AF\u5883\u6E05\u5355\uFF08\u4E0D\u653E\u8EAB\u4EFD\u6216\u51ED\u636E\uFF09",
8759
+ "# 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",
8760
+ "schemaVersion: 1",
8761
+ "environments:",
8762
+ ` - alias: ${JSON.stringify(environment)}`,
8763
+ ` endpoint: ${JSON.stringify(endpoint)}`,
8764
+ ` frontend: ${JSON.stringify(frontend)}`,
8765
+ ` tenant: ${JSON.stringify(tenant2)}`,
8766
+ ` controlled: ${initialMode === "controlled" ? "true" : "false"}`,
8767
+ ' owner: "TODO: \u9879\u76EE\u8D1F\u8D23\u4EBA"',
8768
+ ""
8769
+ ].join("\n");
8770
+ }
8771
+ function renderAgentInstructions() {
8772
+ return [
8773
+ AGENT_BEGIN,
8774
+ "# HCM \u987E\u95EE\u9879\u76EE\u8FB9\u754C",
8775
+ "",
8776
+ "- \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",
8777
+ "- \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",
8778
+ "- 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",
8779
+ "- `.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\u8D1F\u8D23\u4EBA\u6279\u51C6\u65F6\uFF0C\u624D\u80FD\u4E34\u65F6\u5207\u6362\u5BF9\u5E94\u73AF\u5883\uFF0C\u5B8C\u6210\u540E\u7ACB\u5373\u56DE\u5230 plan-only\u3002",
8780
+ "- \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",
8781
+ "- \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",
8782
+ AGENT_END,
8783
+ ""
8784
+ ].join("\n");
8785
+ }
8786
+ function renderSetupSh(cliVersion) {
8787
+ return [
8788
+ "#!/usr/bin/env bash",
8789
+ "set -euo pipefail",
8790
+ "",
8791
+ `expected_hcm_version=${JSON.stringify(cliVersion)}`,
8792
+ 'actual_hcm_version="$(hcm --version 2>/dev/null || true)"',
8793
+ 'if [[ "$actual_hcm_version" != "$expected_hcm_version" ]]; then',
8794
+ ` 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`,
8795
+ " exit 1",
8796
+ "fi",
8797
+ "",
8798
+ "node <<'HCM_PROJECT_SETUP'",
8799
+ "const fs = require('node:fs');",
8800
+ "const path = require('node:path');",
8801
+ "const { spawnSync } = require('node:child_process');",
8802
+ "",
8803
+ "const project = process.cwd();",
8804
+ "const environmentsFile = path.join(project, '\u73AF\u5883.yml');",
8805
+ "const projectFile = path.join(project, '.hcm-delivery', 'project.yml');",
8806
+ "const skillsLock = path.join(project, 'hcm-skills', '.hcm-skills.json');",
8807
+ "const source = fs.readFileSync(environmentsFile, 'utf8');",
8808
+ "const environments = parseEnvironments(source);",
8809
+ "if (environments.length === 0) throw new Error('\u73AF\u5883.yml \u81F3\u5C11\u8981\u6709\u4E00\u4E2A\u73AF\u5883');",
8810
+ "",
8811
+ "const missingEnvironments = new Set();",
8812
+ "for (const environment of environments) {",
8813
+ " const probe = spawnSync('hcm', ['env', 'show', environment.alias], { encoding: 'utf8' });",
8814
+ " if (probe.error) throw new Error(`\u65E0\u6CD5\u68C0\u67E5\u73AF\u5883 ${environment.alias}\uFF1A${probe.error.message}`);",
8815
+ " if (probe.status === 0) {",
8816
+ " const existing = parseExistingEnvironment(probe.stdout, environment.alias);",
8817
+ " assertEnvironmentMatches(environment, existing);",
8818
+ " 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`);",
8819
+ " continue;",
8820
+ " }",
8821
+ " if (/\\bENV_NOT_FOUND\\b/.test(probe.stderr)) {",
8822
+ " missingEnvironments.add(environment.alias);",
8823
+ " continue;",
8824
+ " }",
8825
+ " const detail = probe.stderr.trim() || `\u9000\u51FA\u7801 ${probe.status ?? 'unknown'}`;",
8826
+ " throw new Error(`\u65E0\u6CD5\u68C0\u67E5\u73AF\u5883 ${environment.alias}\uFF1A${detail}`);",
8827
+ "}",
8828
+ "",
8829
+ "let projectInitialized = fs.existsSync(projectFile);",
8830
+ "for (const environment of environments) {",
8831
+ " if (missingEnvironments.has(environment.alias)) {",
8832
+ " const add = ['env', 'add', environment.alias, '--endpoint', environment.endpoint];",
8833
+ " if (environment.frontend) add.push('--frontend', environment.frontend);",
8834
+ " if (environment.tenant) add.push('--tenant', environment.tenant);",
8835
+ " run(add);",
8836
+ " }",
8837
+ " if (!projectInitialized) {",
8838
+ " run(['delivery', 'init', '--project', project, '--env', environment.alias, '--mode', 'plan-only']);",
8839
+ " projectInitialized = true;",
8840
+ " } else {",
8841
+ " run(['delivery', 'mode', '--project', project, '--env', environment.alias, '--set', 'plan-only']);",
8842
+ " }",
8843
+ "}",
8844
+ "",
8845
+ "if (!fs.existsSync(skillsLock)) {",
8846
+ " run(['skills', 'install', '--all', '--target', 'codex', '--env', environments[0].alias]);",
8847
+ "} else {",
8848
+ " 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');",
8849
+ "}",
8850
+ '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");',
8851
+ "",
8852
+ "function run(args) {",
8853
+ " const result = spawnSync('hcm', args, { cwd: project, stdio: 'inherit' });",
8854
+ " if (result.error) throw new Error(`\u65E0\u6CD5\u6267\u884C hcm ${args.join(' ')}\uFF1A${result.error.message}`);",
8855
+ " if (result.status !== 0) process.exit(result.status ?? 1);",
8856
+ "}",
8857
+ "",
8858
+ "function parseEnvironments(text) {",
8859
+ " const result = [];",
8860
+ " let current = null;",
8861
+ " let inEnvironments = false;",
8862
+ " for (const [offset, rawLine] of text.split(/\\r?\\n/).entries()) {",
8863
+ " const lineNo = offset + 1;",
8864
+ ' if (!rawLine.trim() || rawLine.trimStart().startsWith("#")) continue;',
8865
+ " if (/^schemaVersion:\\s*1\\s*$/.test(rawLine)) continue;",
8866
+ " if (/^environments:\\s*$/.test(rawLine)) { inEnvironments = true; continue; }",
8867
+ " if (!inEnvironments) throw new Error(`\u73AF\u5883.yml \u7B2C ${lineNo} \u884C\u4E0D\u5C5E\u4E8E environments`);",
8868
+ " const first = rawLine.match(/^ {2}- alias:\\s*(.+)$/);",
8869
+ " if (first) {",
8870
+ " if (current) result.push(validateEnvironment(current, lineNo));",
8871
+ " current = { alias: scalar(first[1], lineNo) };",
8872
+ " continue;",
8873
+ " }",
8874
+ " const field = rawLine.match(/^ {4}(endpoint|frontend|tenant|controlled|owner):\\s*(.+)$/);",
8875
+ " if (!field || !current) throw new Error(`\u73AF\u5883.yml \u7B2C ${lineNo} \u884C\u4E0D\u7B26\u5408\u811A\u624B\u67B6\u683C\u5F0F`);",
8876
+ " current[field[1]] = scalar(field[2], lineNo);",
8877
+ " }",
8878
+ " if (current) result.push(validateEnvironment(current, text.split(/\\r?\\n/).length));",
8879
+ " return result;",
8880
+ "}",
8881
+ "",
8882
+ "function scalar(raw, lineNo) {",
8883
+ " const value = raw.trim();",
8884
+ ` if (value.startsWith('"')) {`,
8885
+ " try { return JSON.parse(value); } catch { throw new Error(`\u73AF\u5883.yml \u7B2C ${lineNo} \u884C\u7684\u53CC\u5F15\u53F7\u503C\u975E\u6CD5`); }",
8886
+ " }",
8887
+ ` if (value.startsWith("'") && value.endsWith("'")) return value.slice(1, -1).replace(/''/g, "'");`,
8888
+ ' const plain = value.replace(/\\s+#.*$/, "").trim();',
8889
+ ' if (plain === "true") return true;',
8890
+ ' if (plain === "false") return false;',
8891
+ " return plain;",
8892
+ "}",
8893
+ "",
8894
+ "function validateEnvironment(environment, lineNo) {",
8895
+ ' for (const key of ["alias", "endpoint"]) {',
8896
+ ' if (typeof environment[key] !== "string" || !environment[key].trim()) {',
8897
+ " throw new Error(`\u73AF\u5883.yml \u622A\u81F3\u7B2C ${lineNo} \u884C\u7F3A\u5C11 ${key}`);",
8898
+ " }",
8899
+ " }",
8900
+ ' if (environment.endpoint === "REPLACE_ME") {',
8901
+ " throw new Error(`\u73AF\u5883 ${environment.alias} \u7684 endpoint \u4ECD\u662F REPLACE_ME\uFF0C\u8BF7\u5148\u7F16\u8F91 \u73AF\u5883.yml`);",
8902
+ " }",
8903
+ " if (environment.controlled !== true && environment.controlled !== false) {",
8904
+ " throw new Error(`\u73AF\u5883 ${environment.alias} \u7684 controlled \u5FC5\u987B\u662F true \u6216 false`);",
8905
+ " }",
8906
+ ' for (const key of ["frontend", "tenant"]) {',
8907
+ ' if (environment[key] !== undefined && typeof environment[key] !== "string") {',
8908
+ " environment[key] = String(environment[key]);",
8909
+ " }",
8910
+ " }",
8911
+ " return environment;",
8912
+ "}",
8913
+ "",
8914
+ "function parseExistingEnvironment(text, alias) {",
8915
+ " const result = {};",
8916
+ " for (const [offset, rawLine] of text.split(/\\r?\\n/).entries()) {",
8917
+ ' if (!rawLine.trim() || rawLine.startsWith(" ") || rawLine.trimStart().startsWith("#")) continue;',
8918
+ " const field = rawLine.match(/^(endpoint|frontend|tenantId):\\s*(.+)$/);",
8919
+ " if (field) result[field[1]] = scalar(field[2], offset + 1);",
8920
+ " }",
8921
+ ' if (typeof result.endpoint !== "string" || !result.endpoint) {',
8922
+ " throw new Error(`hcm env show ${alias} \u672A\u8FD4\u56DE\u6709\u6548 endpoint\uFF0C\u62D2\u7EDD\u7EE7\u7EED`);",
8923
+ " }",
8924
+ " return result;",
8925
+ "}",
8926
+ "",
8927
+ "function assertEnvironmentMatches(expected, actual) {",
8928
+ " const fields = [",
8929
+ ' ["endpoint", expected.endpoint, actual.endpoint],',
8930
+ ' ["frontend", expected.frontend ?? "", actual.frontend ?? ""],',
8931
+ ' ["tenant", expected.tenant ?? "1", actual.tenantId ?? "1"],',
8932
+ " ];",
8933
+ " const mismatches = fields",
8934
+ " .filter(([, wanted, found]) => String(wanted) !== String(found))",
8935
+ " .map(([name, wanted, found]) => `${name}: \u9879\u76EE=${JSON.stringify(wanted)} \u672C\u673A=${JSON.stringify(found)}`);",
8936
+ " if (mismatches.length === 0) return;",
8937
+ " throw new Error(",
8938
+ ' `\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` +',
8939
+ ' "\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",',
8940
+ " );",
8941
+ "}",
8942
+ "HCM_PROJECT_SETUP",
8943
+ ""
8944
+ ].join("\n");
8945
+ }
8946
+ function mergeDeliveryGitignore(existing) {
8947
+ const block = [
8948
+ GITIGNORE_BEGIN,
8949
+ ".hcm-delivery/project.yml",
8950
+ ".hcm-delivery/execution-plans/",
8951
+ ".hcm-delivery/execution-claims/",
8952
+ GITIGNORE_END
8953
+ ].join("\n");
8954
+ return upsertBlock(existing, GITIGNORE_BEGIN, GITIGNORE_END, block);
8955
+ }
8956
+ function mergeAgentInstructions(existing) {
8957
+ return upsertBlock(
8958
+ existing,
8959
+ AGENT_BEGIN,
8960
+ AGENT_END,
8961
+ renderAgentInstructions().trimEnd()
8962
+ );
8963
+ }
8964
+ async function scaffoldDeliveryProject(root, options) {
8965
+ const result = { created: [], updated: [], preserved: [] };
8966
+ for (const directory of DELIVERY_PROJECT_DIRECTORIES) {
8967
+ const absolute = path6.join(root, directory);
8968
+ await ensureDirectory(absolute);
8969
+ await writeIfAbsent(path6.join(absolute, ".gitkeep"), "", result, `${directory}/.gitkeep`);
8970
+ }
8971
+ await writeIfAbsent(
8972
+ path6.join(root, "\u73AF\u5883.yml"),
8973
+ renderEnvironmentYml(options.environment, options.environmentConfig, options.initialMode),
8974
+ result,
8975
+ "\u73AF\u5883.yml"
8976
+ );
8977
+ const setupFile = path6.join(root, "setup.sh");
8978
+ const setupCreated = await writeIfAbsent(
8979
+ setupFile,
8980
+ renderSetupSh(options.cliVersion),
8981
+ result,
8982
+ "setup.sh",
8983
+ 493
8984
+ );
8985
+ if (setupCreated) await fs6.chmod(setupFile, 493);
8986
+ await mergeManagedFile(path6.join(root, "AGENTS.md"), mergeAgentInstructions, result, "AGENTS.md");
8987
+ await mergeManagedFile(path6.join(root, "CLAUDE.md"), mergeAgentInstructions, result, "CLAUDE.md");
8988
+ await mergeManagedFile(path6.join(root, ".gitignore"), mergeDeliveryGitignore, result, ".gitignore");
8989
+ return result;
8990
+ }
8991
+ async function mergeManagedFile(file, merge, result, relative2) {
8992
+ const existing = await readRegularFile(file);
8993
+ const next = merge(existing ?? "");
8994
+ if (existing === next) {
8995
+ result.preserved.push(relative2);
8996
+ return;
8997
+ }
8998
+ await fs6.writeFile(file, next, { encoding: "utf8", mode: 420 });
8999
+ (existing === null ? result.created : result.updated).push(relative2);
9000
+ }
9001
+ async function writeIfAbsent(file, content, result, relative2, mode = 420) {
9002
+ try {
9003
+ await fs6.writeFile(file, content, { encoding: "utf8", mode, flag: "wx" });
9004
+ result.created.push(relative2);
9005
+ return true;
9006
+ } catch (cause) {
9007
+ if (cause.code !== "EEXIST") throw cause;
9008
+ await assertRegularFile(file);
9009
+ result.preserved.push(relative2);
9010
+ return false;
9011
+ }
9012
+ }
9013
+ async function ensureDirectory(directory) {
9014
+ await fs6.mkdir(directory, { recursive: true });
9015
+ const stat = await fs6.lstat(directory);
9016
+ if (!stat.isDirectory() || stat.isSymbolicLink()) {
9017
+ throw new Error(`\u811A\u624B\u67B6\u8DEF\u5F84\u4E0D\u662F\u666E\u901A\u76EE\u5F55\uFF1A${directory}`);
9018
+ }
9019
+ }
9020
+ async function readRegularFile(file) {
9021
+ try {
9022
+ await assertRegularFile(file);
9023
+ return await fs6.readFile(file, "utf8");
9024
+ } catch (cause) {
9025
+ if (cause.code === "ENOENT") return null;
9026
+ throw cause;
9027
+ }
9028
+ }
9029
+ async function assertRegularFile(file) {
9030
+ const stat = await fs6.lstat(file);
9031
+ if (!stat.isFile() || stat.isSymbolicLink()) {
9032
+ throw new Error(`\u811A\u624B\u67B6\u8DEF\u5F84\u4E0D\u662F\u666E\u901A\u6587\u4EF6\uFF1A${file}`);
9033
+ }
9034
+ }
9035
+ function upsertBlock(existing, begin, end, block) {
9036
+ const start = existing.indexOf(begin);
9037
+ const finish = existing.indexOf(end);
9038
+ const markersAreMalformed = start < 0 !== finish < 0 || start >= 0 && (finish < start || existing.lastIndexOf(begin) !== start || existing.lastIndexOf(end) !== finish);
9039
+ if (markersAreMalformed) {
9040
+ throw new Error(`\u6258\u7BA1\u5757\u6807\u8BB0\u635F\u574F\u6216\u91CD\u590D\uFF0C\u62D2\u7EDD\u8986\u76D6\uFF1A${begin} \u2026 ${end}`);
9041
+ }
9042
+ let next;
9043
+ if (start >= 0 && finish >= start) {
9044
+ next = `${existing.slice(0, start)}${block}${existing.slice(finish + end.length)}`;
9045
+ } else {
9046
+ const prefix = existing.trimEnd();
9047
+ next = `${prefix}${prefix ? "\n\n" : ""}${block}`;
9048
+ }
9049
+ return `${next.trimEnd()}
9050
+ `;
9051
+ }
9052
+
9053
+ // src/commands/delivery-init.ts
9054
+ function renderProjectYml(environment, mode) {
8505
9055
  return [
8506
9056
  "# HCM \u987E\u95EE\u4EA4\u4ED8\u9879\u76EE\u914D\u7F6E\uFF08hcm delivery init \u751F\u6210\uFF09",
8507
9057
  "#",
8508
- "# deliveryMode \u51B3\u5B9A\u8FD9\u4E2A\u9879\u76EE\u5141\u8BB8\u8D70\u5230\u54EA\u4E00\u6B65\uFF1A",
9058
+ "# deliveryMode \u6309\u76EE\u6807\u73AF\u5883\u51B3\u5B9A\u672C\u673A\u5141\u8BB8\u8D70\u5230\u54EA\u4E00\u6B65\uFF1A",
8509
9059
  "# plan-only \u2014\u2014 \u53EA\u5141\u8BB8 assess / prepare \u51FA\u8BA1\u5212\uFF0Cexecute \u4E00\u5F8B\u62D2\u7EDD",
8510
9060
  "# controlled \u2014\u2014 \u5141\u8BB8 prepare + execute \u5355\u6B21\u53D7\u63A7\u6267\u884C\uFF08\u4ECD\u9700\u9010\u6B21\u6279\u51C6\uFF09",
8511
9061
  "#",
8512
9062
  "# \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",
8513
- "# \u6539\u8FD9\u4E00\u884C\u53EA\u6539\u300C\u672C\u9879\u76EE\u5141\u4E0D\u5141\u8BB8\u771F\u7684\u6267\u884C\u300D\uFF0C\u4E0D\u6539\u300C\u8FD9\u6761\u547D\u4EE4\u6709\u591A\u5371\u9669\u300D\u3002",
8514
- `deliveryMode: ${mode}`,
9063
+ "# \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",
9064
+ "schemaVersion: 2",
9065
+ "deliveryMode:",
9066
+ ` ${JSON.stringify(environment)}: ${mode}`,
8515
9067
  ""
8516
9068
  ].join("\n");
8517
9069
  }
8518
9070
  async function deliveryInitCommand(args) {
8519
9071
  try {
8520
- const mode = args.mode ?? "controlled";
8521
- if (!MODES.includes(mode)) {
9072
+ const mode = args.mode ?? "plan-only";
9073
+ if (!DELIVERY_MODES.includes(mode)) {
8522
9074
  throw new Error(
8523
- `--mode \u53EA\u63A5\u53D7 ${MODES.join(" | ")}\uFF0C\u6536\u5230 "${args.mode}"
9075
+ `--mode \u53EA\u63A5\u53D7 ${DELIVERY_MODES.join(" | ")}\uFF0C\u6536\u5230 "${args.mode}"
8524
9076
  \u8FD9\u4E24\u4E2A\u503C\u662F delivery prepare \u8BA4\u5F97\u7684\u5168\u90E8\uFF1B\u5199\u522B\u7684\u503C prepare \u4F1A\u62D2\u7EDD\u52A0\u8F7D\u3002`
8525
9077
  );
8526
9078
  }
8527
- const root = path6.resolve(args.project ?? ".");
8528
- const dir = path6.join(root, ".hcm-delivery");
8529
- const file = path6.join(dir, "project.yml");
9079
+ const environment = await resolveDeliveryEnvironment(args.env);
9080
+ const root = path7.resolve(args.project ?? ".");
9081
+ const dir = path7.join(root, ".hcm-delivery");
9082
+ const file = path7.join(dir, "project.yml");
8530
9083
  let existed = false;
8531
9084
  try {
8532
- await fs6.access(file);
9085
+ await fs7.access(file);
8533
9086
  existed = true;
8534
9087
  } catch {
8535
9088
  existed = false;
@@ -8541,20 +9094,22 @@ async function deliveryInitCommand(args) {
8541
9094
  \u786E\u8981\u91CD\u5199\uFF1Ahcm delivery init --force`
8542
9095
  );
8543
9096
  }
8544
- await fs6.mkdir(dir, { recursive: true });
8545
- await fs6.writeFile(file, renderProjectYml(mode), "utf8");
8546
- const created = [];
8547
- for (const sub of SCAFFOLD_DIRS) {
8548
- const p = path6.join(root, sub);
8549
- await fs6.mkdir(p, { recursive: true });
8550
- created.push(sub + "/");
8551
- }
9097
+ await fs7.mkdir(dir, { recursive: true });
9098
+ await fs7.writeFile(file, renderProjectYml(environment, mode), "utf8");
9099
+ const environmentConfig = await loadEnv9(environment).catch(() => null);
9100
+ const scaffold = await scaffoldDeliveryProject(root, {
9101
+ environment,
9102
+ environmentConfig,
9103
+ initialMode: mode,
9104
+ cliVersion: CLI_VERSION
9105
+ });
8552
9106
  const result = {
8553
9107
  project: root,
8554
9108
  projectFile: file,
9109
+ environment,
8555
9110
  deliveryMode: mode,
8556
9111
  overwritten: existed,
8557
- scaffold: created,
9112
+ scaffold,
8558
9113
  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"
8559
9114
  };
8560
9115
  process.stdout.write(formatObject21(result, { format: args.output ?? "json" }) + "\n");
@@ -8566,31 +9121,31 @@ async function deliveryInitCommand(args) {
8566
9121
  }
8567
9122
  async function deliveryModeCommand(args) {
8568
9123
  try {
8569
- const root = path6.resolve(args.project ?? ".");
8570
- const file = path6.join(root, ".hcm-delivery", "project.yml");
9124
+ const environment = await resolveDeliveryEnvironment(args.env);
9125
+ const root = path7.resolve(args.project ?? ".");
9126
+ const file = path7.join(root, ".hcm-delivery", "project.yml");
8571
9127
  let content;
8572
9128
  try {
8573
- content = await fs6.readFile(file, "utf8");
9129
+ content = await fs7.readFile(file, "utf8");
8574
9130
  } catch {
8575
9131
  throw new Error(
8576
9132
  `\u9879\u76EE\u672A\u521D\u59CB\u5316\uFF1A\u627E\u4E0D\u5230 ${file}
8577
9133
  \u4E0B\u4E00\u6B65\uFF1Ahcm delivery init`
8578
9134
  );
8579
9135
  }
8580
- const read = () => content.match(
8581
- /^deliveryMode:\s*(?:"(plan-only|controlled)"|'(plan-only|controlled)'|(plan-only|controlled))\s*$/m
8582
- );
8583
9136
  if (!args.set) {
8584
- const m2 = read();
8585
- const current = m2?.[1] ?? m2?.[2] ?? m2?.[3] ?? null;
9137
+ const current = deliveryModeForEnvironment(content, environment);
8586
9138
  process.stdout.write(
8587
9139
  formatObject21(
8588
9140
  {
8589
9141
  project: root,
8590
9142
  projectFile: file,
9143
+ environment,
8591
9144
  deliveryMode: current,
8592
9145
  canExecuteR2: current === "controlled",
8593
- ...current === "plan-only" ? { note: "plan-only \u53EA\u51FA\u8BA1\u5212\u4E0D\u6267\u884C\uFF1Bexecute \u4F1A\u62D2\u7EDD R2 \u8BA1\u5212" } : {}
9146
+ ...current === "plan-only" ? { note: "plan-only \u53EA\u51FA\u8BA1\u5212\u4E0D\u6267\u884C\uFF1Bexecute \u4F1A\u62D2\u7EDD R2 \u8BA1\u5212" } : current === null ? {
9147
+ 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`
9148
+ } : {}
8594
9149
  },
8595
9150
  { format: args.output ?? "json" }
8596
9151
  ) + "\n"
@@ -8598,27 +9153,21 @@ async function deliveryModeCommand(args) {
8598
9153
  process.exit(0);
8599
9154
  }
8600
9155
  const next = args.set;
8601
- if (!MODES.includes(next)) {
8602
- throw new Error(`--set \u53EA\u63A5\u53D7 ${MODES.join(" | ")}\uFF0C\u6536\u5230 "${args.set}"`);
9156
+ if (!DELIVERY_MODES.includes(next)) {
9157
+ throw new Error(`--set \u53EA\u63A5\u53D7 ${DELIVERY_MODES.join(" | ")}\uFF0C\u6536\u5230 "${args.set}"`);
8603
9158
  }
8604
- const m = read();
8605
- if (!m) {
8606
- throw new Error(
8607
- `${file} \u91CC\u6CA1\u6709\u5408\u6CD5\u7684 deliveryMode \u884C\uFF0C\u4E0D\u5C31\u5730\u6539\u5199\u4EE5\u514D\u7834\u574F\u914D\u7F6E
8608
- \u4E0B\u4E00\u6B65\uFF1A\u786E\u8BA4\u6587\u4EF6\u5185\u5BB9\uFF0C\u6216 hcm delivery init --force \u91CD\u65B0\u751F\u6210`
8609
- );
8610
- }
8611
- const before = m[1] ?? m[2] ?? m[3];
8612
- content = content.replace(m[0], `deliveryMode: ${next}`);
8613
- await fs6.writeFile(file, content, "utf8");
9159
+ const update = setDeliveryModeForEnvironment(content, environment, next);
9160
+ await fs7.writeFile(file, update.content, "utf8");
8614
9161
  process.stdout.write(
8615
9162
  formatObject21(
8616
9163
  {
8617
9164
  project: root,
8618
9165
  projectFile: file,
9166
+ environment,
8619
9167
  deliveryMode: next,
8620
- previous: before,
8621
- canExecuteR2: next === "controlled"
9168
+ previous: update.previous,
9169
+ canExecuteR2: next === "controlled",
9170
+ migratedLegacy: update.migratedLegacy
8622
9171
  },
8623
9172
  { format: args.output ?? "json" }
8624
9173
  ) + "\n"
@@ -8629,6 +9178,12 @@ async function deliveryModeCommand(args) {
8629
9178
  process.exit(1);
8630
9179
  }
8631
9180
  }
9181
+ async function resolveDeliveryEnvironment(envFlag) {
9182
+ const global = await loadGlobalConfig9();
9183
+ const environment = resolveActiveEnv5({ envFlag }, process.env, global);
9184
+ if (!environment.trim()) throw new Error("\u65E0\u6CD5\u89E3\u6790\u76EE\u6807\u73AF\u5883\uFF1B\u8BF7\u4F20 --env <\u73AF\u5883\u522B\u540D>");
9185
+ return environment;
9186
+ }
8632
9187
 
8633
9188
  // src/commands/delivery-doctor.ts
8634
9189
  init_auth_guard();
@@ -8737,9 +9292,9 @@ import {
8737
9292
  loadProtocolFacts,
8738
9293
  scan
8739
9294
  } from "@hcmai/sdk";
8740
- import * as path7 from "path";
9295
+ import * as path8 from "path";
8741
9296
  function renderGate0(result, skillRoot) {
8742
- const where = skillRoot ? `\uFF08${path7.resolve(skillRoot)}\uFF09` : "";
9297
+ const where = skillRoot ? `\uFF08${path8.resolve(skillRoot)}\uFF09` : "";
8743
9298
  const lines = [
8744
9299
  `\u626B\u63CF\u9762${where}\uFF1A${result.scanned.length} \u4E2A\u6587\u4EF6\uFF1B\u5224\u7EA2 ${result.red.length} \u6761\uFF1B\u7F3A\u53E3\u653E\u884C ${result.gaps.length} \u6761\u3002`
8745
9300
  ];
@@ -8851,7 +9406,7 @@ import {
8851
9406
  writeRisk
8852
9407
  } from "@hcmai/sdk";
8853
9408
  import { existsSync as existsSync3 } from "fs";
8854
- import * as path8 from "path";
9409
+ import * as path9 from "path";
8855
9410
  function premise(message, hint = "") {
8856
9411
  process.stderr.write(message + (hint ? `
8857
9412
  \u2192 ${hint}` : "") + "\n");
@@ -8878,13 +9433,13 @@ async function runSeedPlan(args, client3) {
8878
9433
  const reconDir = candidates[0].reconDir;
8879
9434
  if (candidates.length > 1) {
8880
9435
  process.stderr.write(
8881
- `\u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u6709 ${candidates.length} \u4EFD\u57FA\u7EBF\uFF0C\u672C\u8F6E\u8BFB\u7684\u662F \`${path8.basename(reconDir)}\`\uFF1A` + candidates.slice(1).map((c) => `\`${path8.basename(c.reconDir)}\``).join("\u3001") + " \u672A\u88AB\u8BFB\u53D6 \u2014\u2014 \u4E0D\u540C sourceKey \u7684\u4EA7\u7269**\u4E0D\u53EF\u4E92\u6362**\u3002\n"
9436
+ `\u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u6709 ${candidates.length} \u4EFD\u57FA\u7EBF\uFF0C\u672C\u8F6E\u8BFB\u7684\u662F \`${path9.basename(reconDir)}\`\uFF1A` + candidates.slice(1).map((c) => `\`${path9.basename(c.reconDir)}\``).join("\u3001") + " \u672A\u88AB\u8BFB\u53D6 \u2014\u2014 \u4E0D\u540C sourceKey \u7684\u4EA7\u7269**\u4E0D\u53EF\u4E92\u6362**\u3002\n"
8882
9437
  );
8883
9438
  }
8884
9439
  const round = inspectRound3(reconDir);
8885
9440
  process.stderr.write(roundWarning(round));
8886
9441
  const baseline = {
8887
- path: `${path8.basename(path8.dirname(reconDir))}/${path8.basename(reconDir)}`,
9442
+ path: `${path9.basename(path9.dirname(reconDir))}/${path9.basename(reconDir)}`,
8888
9443
  roundId: round.roundId ?? null
8889
9444
  };
8890
9445
  let exemptions = null;
@@ -9146,7 +9701,7 @@ async function deliverySeedVerifyCommand(args) {
9146
9701
  // src/commands/delivery-seed-find.ts
9147
9702
  import { existsSync as existsSync4 } from "fs";
9148
9703
  import { readFileSync as readFileSync6 } from "fs";
9149
- import * as path9 from "path";
9704
+ import * as path10 from "path";
9150
9705
  import {
9151
9706
  INIT_EXIT_CODES as INIT_EXIT_CODES2,
9152
9707
  ValueHints,
@@ -9160,10 +9715,10 @@ import {
9160
9715
  valuesRoundCaveat
9161
9716
  } from "@hcmai/sdk";
9162
9717
  function provenance(chosenReconDir, others) {
9163
- let line = `> \u57FA\u7EBF\uFF1A\`${path9.basename(chosenReconDir)}\`
9718
+ let line = `> \u57FA\u7EBF\uFF1A\`${path10.basename(chosenReconDir)}\`
9164
9719
  `;
9165
9720
  if (others.length > 0) {
9166
- line += `> \u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u53E6\u6709 ${others.length} \u4EFD\u57FA\u7EBF\u672A\u88AB\u8BFB\u53D6\uFF1A` + others.map((o) => `\`${path9.basename(o)}\``).join("\u3001") + " \u2014\u2014 \u4E0D\u540C sourceKey \u7684\u4EA7\u7269**\u4E0D\u53EF\u4E92\u6362**\u3002\n";
9721
+ line += `> \u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u53E6\u6709 ${others.length} \u4EFD\u57FA\u7EBF\u672A\u88AB\u8BFB\u53D6\uFF1A` + others.map((o) => `\`${path10.basename(o)}\``).join("\u3001") + " \u2014\u2014 \u4E0D\u540C sourceKey \u7684\u4EA7\u7269**\u4E0D\u53EF\u4E92\u6362**\u3002\n";
9167
9722
  }
9168
9723
  return `${line}
9169
9724
  `;
@@ -9500,7 +10055,7 @@ import {
9500
10055
  runTriageRound
9501
10056
  } from "@hcmai/sdk";
9502
10057
  import { mkdirSync, readFileSync as readFileSync8, writeFileSync as writeFileSync2 } from "fs";
9503
- import * as path10 from "path";
10058
+ import * as path11 from "path";
9504
10059
  var DEFAULT_CAPABILITIES4 = "default";
9505
10060
  function premise4(message, hint) {
9506
10061
  process.stderr.write(`\u{1F534} \u524D\u63D0\u4E0D\u6210\u7ACB\uFF1A${message}
@@ -9536,8 +10091,8 @@ function renderProblems(rows) {
9536
10091
  `;
9537
10092
  }
9538
10093
  function writeTriageArtifact(outDir, body) {
9539
- const out = path10.join(outDir, "work", "triage.md");
9540
- mkdirSync(path10.dirname(out), { recursive: true });
10094
+ const out = path11.join(outDir, "work", "triage.md");
10095
+ mkdirSync(path11.dirname(out), { recursive: true });
9541
10096
  writeFileSync2(out, body, "utf8");
9542
10097
  return out;
9543
10098
  }
@@ -9577,21 +10132,23 @@ async function deliveryTriageCommand(args) {
9577
10132
  // src/commands/delivery-execution.ts
9578
10133
  import { createHash as createHash5, randomBytes as secureRandomBytes } from "crypto";
9579
10134
  import { spawn as spawn2 } from "child_process";
9580
- import { createReadStream, promises as fs7 } from "fs";
9581
- import path11 from "path";
10135
+ import { createReadStream, promises as fs8 } from "fs";
10136
+ import path12 from "path";
9582
10137
  import { CliError as CliError21, CliErrorCode as CliErrorCode20, formatObject as formatObject25 } from "@hcmai/sdk";
9583
10138
  init_exit();
9584
- var EXECUTION_CONTRACT_VERSION = "2026-08-29.controlled-v3";
10139
+ var EXECUTION_CONTRACT_VERSION = "2026-09-03.controlled-v4";
9585
10140
  var DEFAULT_TTL_SECONDS = 15 * 60;
9586
10141
  var MIN_TTL_SECONDS = 60;
9587
10142
  var MAX_TTL_SECONDS = 60 * 60;
9588
10143
  var PLAN_ID_PATTERN = /^[a-f0-9]{24}$/;
9589
10144
  async function prepareDeliveryExecution(input) {
9590
10145
  const project = await realProject(input.project);
9591
- await readProjectMode(project);
9592
10146
  const argv = normalizeCommandArgv(input.argv);
9593
10147
  const assessment = await (input.assessCommand ?? assessEffectiveDeliveryCommand)(argv);
9594
10148
  assertGuardedAssessment(assessment, argv);
10149
+ const environment = assessment.environment.envAlias;
10150
+ if (!environment) throw invalid2("R2 argv \u5FC5\u987B\u663E\u5F0F\u5305\u542B --env \u73AF\u5883\u522B\u540D");
10151
+ await readProjectMode(project, environment);
9595
10152
  const ttlSeconds = input.ttlSeconds ?? DEFAULT_TTL_SECONDS;
9596
10153
  if (!Number.isInteger(ttlSeconds) || ttlSeconds < MIN_TTL_SECONDS || ttlSeconds > MAX_TTL_SECONDS) {
9597
10154
  throw invalid2(`--ttl-seconds \u5FC5\u987B\u662F ${MIN_TTL_SECONDS} \u5230 ${MAX_TTL_SECONDS} \u7684\u6574\u6570`);
@@ -9619,11 +10176,11 @@ async function prepareDeliveryExecution(input) {
9619
10176
  };
9620
10177
  const planId = sha2565(canonicalJson(core)).slice(0, 24);
9621
10178
  const plan = { ...core, planId };
9622
- const plansDir = path11.join(project, ".hcm-delivery", "execution-plans");
10179
+ const plansDir = path12.join(project, ".hcm-delivery", "execution-plans");
9623
10180
  await safeManagedDirectory(project, ".hcm-delivery/execution-plans", plansDir);
9624
- const planFile = path11.join(plansDir, `${planId}.json`);
10181
+ const planFile = path12.join(plansDir, `${planId}.json`);
9625
10182
  try {
9626
- await fs7.writeFile(planFile, `${JSON.stringify(plan, null, 2)}
10183
+ await fs8.writeFile(planFile, `${JSON.stringify(plan, null, 2)}
9627
10184
  `, {
9628
10185
  encoding: "utf8",
9629
10186
  mode: 384,
@@ -9637,14 +10194,16 @@ async function prepareDeliveryExecution(input) {
9637
10194
  async function executeDeliveryPlan(input) {
9638
10195
  if (!PLAN_ID_PATTERN.test(input.planId)) throw invalid2("planId \u5FC5\u987B\u662F 24 \u4F4D\u5C0F\u5199\u5341\u516D\u8FDB\u5236");
9639
10196
  const project = await realProject(input.project);
9640
- if (await readProjectMode(project) !== "controlled") {
9641
- throw invalid2("\u9879\u76EE\u4E0D\u662F controlled\uFF0C\u4E0D\u80FD\u6267\u884C R2 \u8BA1\u5212");
9642
- }
9643
- const planFile = path11.join(project, ".hcm-delivery", "execution-plans", `${input.planId}.json`);
10197
+ const planFile = path12.join(project, ".hcm-delivery", "execution-plans", `${input.planId}.json`);
9644
10198
  const plan = await readPlan(project, planFile);
9645
10199
  if (plan.planId !== input.planId || computePlanId(plan) !== input.planId) {
9646
10200
  throw invalid2("\u6267\u884C\u8BA1\u5212\u5185\u5BB9\u4E0E planId \u6458\u8981\u4E0D\u4E00\u81F4");
9647
10201
  }
10202
+ const environment = plan.assessment.environment.envAlias;
10203
+ if (!environment) throw invalid2("\u6267\u884C\u8BA1\u5212\u7F3A\u5C11\u76EE\u6807\u73AF\u5883");
10204
+ if (await readProjectMode(project, environment) !== "controlled") {
10205
+ throw invalid2(`\u73AF\u5883 ${environment} \u4E0D\u662F controlled\uFF0C\u4E0D\u80FD\u6267\u884C R2 \u8BA1\u5212`);
10206
+ }
9648
10207
  const now = (input.now ?? (() => /* @__PURE__ */ new Date()))();
9649
10208
  if (Number.isNaN(now.getTime())) throw invalid2("\u5F53\u524D\u65F6\u95F4\u65E0\u6548");
9650
10209
  const expiresAt = Date.parse(plan.expiresAt);
@@ -9672,13 +10231,13 @@ async function executeDeliveryPlan(input) {
9672
10231
  await assertDocumentUnchanged(project, plan.documents.rollback, "\u56DE\u6EDA\u8BF4\u660E");
9673
10232
  await assertPayloadsUnchanged(project, plan.payloads);
9674
10233
  const evidenceDir = await bindEvidenceDirectory(project, plan.evidenceDir);
9675
- const receiptFile = path11.join(evidenceDir.absolute, `${plan.planId}.receipt.json`);
10234
+ const receiptFile = path12.join(evidenceDir.absolute, `${plan.planId}.receipt.json`);
9676
10235
  if (await pathExists(receiptFile)) throw invalid2(`\u6267\u884C\u6536\u636E\u5DF2\u5B58\u5728\uFF0C\u62D2\u7EDD\u518D\u6B21\u6267\u884C\uFF1A${plan.planId}`);
9677
- const claimsDir = path11.join(project, ".hcm-delivery", "execution-claims");
10236
+ const claimsDir = path12.join(project, ".hcm-delivery", "execution-claims");
9678
10237
  await safeManagedDirectory(project, ".hcm-delivery/execution-claims", claimsDir);
9679
- const claimFile = path11.join(claimsDir, `${plan.planId}.json`);
10238
+ const claimFile = path12.join(claimsDir, `${plan.planId}.json`);
9680
10239
  try {
9681
- await fs7.writeFile(
10240
+ await fs8.writeFile(
9682
10241
  claimFile,
9683
10242
  `${JSON.stringify({ schemaVersion: 1, planId: plan.planId, claimedAt: now.toISOString() }, null, 2)}
9684
10243
  `,
@@ -9762,26 +10321,30 @@ async function deliveryExecuteCommand(planId, argv, args) {
9762
10321
  exitWithError(cause);
9763
10322
  }
9764
10323
  }
9765
- async function readProjectMode(project) {
9766
- const file = path11.join(project, ".hcm-delivery", "project.yml");
10324
+ async function readProjectMode(project, environment) {
10325
+ const file = path12.join(project, ".hcm-delivery", "project.yml");
9767
10326
  const content = await readSafeFile(project, file, "\u9879\u76EE\u914D\u7F6E");
9768
- const match = content.toString("utf8").match(
9769
- /^deliveryMode:\s*(?:"(plan-only|controlled)"|'(plan-only|controlled)'|(plan-only|controlled))\s*$/m
9770
- );
9771
- const mode = match?.[1] ?? match?.[2] ?? match?.[3];
9772
- if (mode !== "plan-only" && mode !== "controlled") {
9773
- throw invalid2("project.yml \u7F3A\u5C11\u5408\u6CD5 deliveryMode");
10327
+ let mode;
10328
+ try {
10329
+ mode = deliveryModeForEnvironment(content.toString("utf8"), environment);
10330
+ } catch (cause) {
10331
+ throw invalid2(`project.yml \u7684 deliveryMode \u914D\u7F6E\u65E0\u6548\uFF1A${String(cause.message)}`, cause);
10332
+ }
10333
+ if (!mode) {
10334
+ throw invalid2(
10335
+ `project.yml \u672A\u7ED9\u73AF\u5883 ${environment} \u914D\u7F6E deliveryMode\u3002next_step=hcm delivery mode --env ${environment} --set plan-only`
10336
+ );
9774
10337
  }
9775
10338
  return mode;
9776
10339
  }
9777
10340
  var SKILLS_LOCK_CANDIDATES = [
9778
- path11.join("hcm-skills", ".hcm-skills.json"),
9779
- path11.join(".claude", "skills", ".hcm-skills.json")
10341
+ path12.join("hcm-skills", ".hcm-skills.json"),
10342
+ path12.join(".claude", "skills", ".hcm-skills.json")
9780
10343
  ];
9781
10344
  async function readSkillsLock(project) {
9782
10345
  const found = [];
9783
10346
  for (const candidate of SKILLS_LOCK_CANDIDATES) {
9784
- if (await pathExists(path11.join(project, candidate))) found.push(candidate);
10347
+ if (await pathExists(path12.join(project, candidate))) found.push(candidate);
9785
10348
  }
9786
10349
  if (found.length === 0) {
9787
10350
  throw invalid2(
@@ -9793,7 +10356,7 @@ async function readSkillsLock(project) {
9793
10356
  `\u9879\u76EE\u91CC\u6709\u591A\u4EFD\u6280\u80FD\u9501\uFF08${found.join("\u3001")}\uFF09\uFF0C\u65E0\u6CD5\u552F\u4E00\u5224\u5B9A\u53D7\u63A7\u6267\u884C\u7ED1\u5B9A\u54EA\u4E00\u4EFD\u3002next_step=\u53EA\u4FDD\u7559\u5B9E\u9645\u5728\u7528\u7684\u90A3\u4E2A\u6280\u80FD\u76EE\u5F55`
9794
10357
  );
9795
10358
  }
9796
- const bytes = await readSafeFile(project, path11.join(project, found[0]), "\u6280\u80FD\u9501");
10359
+ const bytes = await readSafeFile(project, path12.join(project, found[0]), "\u6280\u80FD\u9501");
9797
10360
  try {
9798
10361
  JSON.parse(bytes.toString("utf8"));
9799
10362
  } catch (cause) {
@@ -9806,7 +10369,7 @@ async function bindDocument(project, reference, label) {
9806
10369
  if (!(relative2.startsWith("work/") || relative2.startsWith("decisions/"))) {
9807
10370
  throw invalid2(`${label}\u5FC5\u987B\u4F4D\u4E8E\u9879\u76EE work/ \u6216 decisions/ \u4E0B`);
9808
10371
  }
9809
- const file = path11.join(project, relative2);
10372
+ const file = path12.join(project, relative2);
9810
10373
  const bytes = await readSafeFile(project, file, label);
9811
10374
  return { path: relative2, sha256: sha2565(bytes) };
9812
10375
  }
@@ -9819,11 +10382,11 @@ async function bindEvidenceDirectory(project, reference) {
9819
10382
  if (!(relative2 === "evidence" || relative2.startsWith("evidence/"))) {
9820
10383
  throw invalid2("evidence \u76EE\u5F55\u5FC5\u987B\u4F4D\u4E8E\u9879\u76EE evidence/ \u4E0B");
9821
10384
  }
9822
- const absolute = path11.join(project, relative2);
10385
+ const absolute = path12.join(project, relative2);
9823
10386
  await assertNoSymlinkComponents(project, relative2);
9824
- const stat = await fs7.stat(absolute).catch(() => null);
10387
+ const stat = await fs8.stat(absolute).catch(() => null);
9825
10388
  if (stat === null) {
9826
- await fs7.mkdir(absolute, { recursive: true, mode: 448 }).catch((cause) => {
10389
+ await fs8.mkdir(absolute, { recursive: true, mode: 448 }).catch((cause) => {
9827
10390
  throw invalid2(
9828
10391
  `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`,
9829
10392
  cause
@@ -9904,6 +10467,18 @@ function validateSupportedCommandShape(reasonCode, argv) {
9904
10467
  }
9905
10468
  return;
9906
10469
  }
10470
+ if (reasonCode === "document-upload") {
10471
+ if (argv[0] !== "upload") {
10472
+ throw invalid2(`upload \u7684\u547D\u4EE4\u540D\u5FC5\u987B\u662F argv \u7684\u7B2C\u4E00\u4E2A token\uFF0C\u5B9E\u9645\u662F\uFF1A${argv[0] ?? "(\u7A7A)"}`);
10473
+ }
10474
+ const file = argv[1];
10475
+ if (!file || file.startsWith("-")) {
10476
+ throw invalid2(
10477
+ "upload \u7684\u6587\u4EF6\u8DEF\u5F84\u5FC5\u987B\u7D27\u8DDF\u5728 upload \u4E4B\u540E\uFF08hcm upload <\u6587\u4EF6> ...\uFF09\u3002next_step=\u628A\u6587\u4EF6\u8DEF\u5F84\u79FB\u5230\u547D\u4EE4\u540D\u540E\u9762\u7684\u7B2C\u4E00\u4E2A\u4F4D\u7F6E\u2014\u2014\u53D7\u63A7\u6267\u884C\u6309\u8FD9\u4E2A\u4F4D\u7F6E\u9489\u4F4F\u8F7D\u8377"
10478
+ );
10479
+ }
10480
+ return;
10481
+ }
9907
10482
  if (reasonCode === "record-create") {
9908
10483
  requireExactlyOnePayload(argv, "create");
9909
10484
  return;
@@ -9955,7 +10530,10 @@ var PAYLOAD_FILE_FLAGS = ["--data-file", "--params-file", "--file"];
9955
10530
  var PAYLOAD_DIR_FLAGS = ["--dir"];
9956
10531
  var IMPLICIT_DIR_COMMANDS = { "workspace push": "." };
9957
10532
  var TOOLING_DIRS = [".git", "node_modules", ".hcm-delivery", "evidence"];
9958
- var POSITIONAL_PAYLOAD_COMMANDS = { import: 1 };
10533
+ var POSITIONAL_PAYLOAD_COMMANDS = {
10534
+ import: { index: 1, kind: "file-or-directory", label: "import \u6570\u636E\u96C6\u8F7D\u8377" },
10535
+ upload: { index: 1, kind: "file", label: "upload \u6587\u4EF6\u8F7D\u8377" }
10536
+ };
9959
10537
  function normalizeCommandArgv(argv) {
9960
10538
  return normalizeAssessedArgv(argv);
9961
10539
  }
@@ -9977,7 +10555,10 @@ async function bindPayloadFiles(project, argv) {
9977
10555
  }
9978
10556
  const positional = POSITIONAL_PAYLOAD_COMMANDS[argv[0] ?? ""];
9979
10557
  if (positional !== void 0) {
9980
- bound.push(await bindPayloadPath(project, argv[positional] ?? "", `${argv[0]} \u6570\u636E\u96C6\u8F7D\u8377`));
10558
+ const reference = argv[positional.index] ?? "";
10559
+ bound.push(
10560
+ await (positional.kind === "file" ? bindPayloadFile(project, reference, positional.label) : bindPayloadPath(project, reference, positional.label))
10561
+ );
9981
10562
  }
9982
10563
  return bound;
9983
10564
  }
@@ -9985,7 +10566,7 @@ async function bindPayloadPath(project, reference, label) {
9985
10566
  const relative2 = safeRelative(reference, label);
9986
10567
  let stat;
9987
10568
  try {
9988
- stat = await fs7.stat(path11.join(project, relative2));
10569
+ stat = await fs8.stat(path12.join(project, relative2));
9989
10570
  } catch (cause) {
9990
10571
  throw invalid2(
9991
10572
  `${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`,
@@ -9996,10 +10577,10 @@ async function bindPayloadPath(project, reference, label) {
9996
10577
  }
9997
10578
  async function bindPayloadDirectory(project, reference, label) {
9998
10579
  const relative2 = reference === "." ? "." : safeRelative(reference, label);
9999
- const root = path11.join(project, relative2);
10580
+ const root = path12.join(project, relative2);
10000
10581
  let stat;
10001
10582
  try {
10002
- stat = await fs7.stat(root);
10583
+ stat = await fs8.stat(root);
10003
10584
  } catch {
10004
10585
  throw invalid2(`${label}\u4E0D\u5B58\u5728\uFF1A${relative2}`);
10005
10586
  }
@@ -10009,10 +10590,10 @@ async function bindPayloadDirectory(project, reference, label) {
10009
10590
  const skipToolingAtRoot = relative2 === ".";
10010
10591
  const entries = [];
10011
10592
  const walk = async (dir, prefix) => {
10012
- const items = await fs7.readdir(dir, { withFileTypes: true });
10593
+ const items = await fs8.readdir(dir, { withFileTypes: true });
10013
10594
  for (const item of [...items].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0)) {
10014
10595
  if (skipToolingAtRoot && prefix === "" && TOOLING_DIRS.includes(item.name)) continue;
10015
- const child = path11.join(dir, item.name);
10596
+ const child = path12.join(dir, item.name);
10016
10597
  const rel = prefix ? `${prefix}/${item.name}` : item.name;
10017
10598
  if (item.isSymbolicLink()) {
10018
10599
  throw invalid2(
@@ -10029,26 +10610,24 @@ ${sha2565(bytes)}`);
10029
10610
  }
10030
10611
  };
10031
10612
  await walk(root, "");
10032
- return { path: relative2, sha256: sha2565(Buffer.from(entries.join("\n"), "utf8")) };
10613
+ return {
10614
+ path: relative2,
10615
+ kind: "directory",
10616
+ sha256: sha2565(Buffer.from(entries.join("\n"), "utf8"))
10617
+ };
10033
10618
  }
10034
10619
  async function bindPayloadFile(project, reference, label) {
10035
10620
  const relative2 = safeRelative(reference, label);
10036
- const file = path11.join(project, relative2);
10621
+ const file = path12.join(project, relative2);
10037
10622
  const bytes = await readSafeFile(project, file, label);
10038
- return { path: relative2, sha256: sha2565(bytes) };
10623
+ return { path: relative2, kind: "file", sha256: sha2565(bytes) };
10039
10624
  }
10040
10625
  async function assertPayloadsUnchanged(project, payloads) {
10041
10626
  for (const payload of payloads) {
10042
- let isDirectory = false;
10043
- try {
10044
- isDirectory = (await fs7.stat(path11.join(project, payload.path))).isDirectory();
10045
- } catch {
10046
- isDirectory = false;
10047
- }
10048
- const current = isDirectory ? await bindPayloadDirectory(project, payload.path, `\u8F7D\u8377 ${payload.path}`) : await bindPayloadFile(project, payload.path, `\u8F7D\u8377 ${payload.path}`);
10627
+ const current = payload.kind === "directory" ? await bindPayloadDirectory(project, payload.path, `\u8F7D\u8377 ${payload.path}`) : await bindPayloadFile(project, payload.path, `\u8F7D\u8377 ${payload.path}`);
10049
10628
  if (current.sha256 !== payload.sha256) {
10050
10629
  throw invalid2(
10051
- `\u8F7D\u8377${isDirectory ? "\u76EE\u5F55" : "\u6587\u4EF6"} ${payload.path} \u7684\u5185\u5BB9\u5DF2\u53D8\u66F4\uFF0C\u8BF7\u91CD\u65B0 prepare`
10630
+ `\u8F7D\u8377${payload.kind === "directory" ? "\u76EE\u5F55" : "\u6587\u4EF6"} ${payload.path} \u7684\u5185\u5BB9\u5DF2\u53D8\u66F4\uFF0C\u8BF7\u91CD\u65B0 prepare`
10052
10631
  );
10053
10632
  }
10054
10633
  }
@@ -10102,29 +10681,29 @@ async function runCurrentCliCommand(argv, cwd, streams) {
10102
10681
  async function writeReceiptExclusive(target, receipt) {
10103
10682
  const temp = `${target}.${process.pid}.${Date.now()}.tmp`;
10104
10683
  try {
10105
- await fs7.writeFile(temp, `${JSON.stringify(receipt, null, 2)}
10684
+ await fs8.writeFile(temp, `${JSON.stringify(receipt, null, 2)}
10106
10685
  `, {
10107
10686
  encoding: "utf8",
10108
10687
  mode: 384,
10109
10688
  flag: "wx"
10110
10689
  });
10111
- await fs7.link(temp, target);
10690
+ await fs8.link(temp, target);
10112
10691
  } catch (cause) {
10113
- throw invalid2(`\u6267\u884C\u6536\u636E\u5199\u5165\u5931\u8D25\u6216\u5DF2\u5B58\u5728\uFF1A${path11.basename(target)}`, cause);
10692
+ throw invalid2(`\u6267\u884C\u6536\u636E\u5199\u5165\u5931\u8D25\u6216\u5DF2\u5B58\u5728\uFF1A${path12.basename(target)}`, cause);
10114
10693
  } finally {
10115
- await fs7.unlink(temp).catch(() => void 0);
10694
+ await fs8.unlink(temp).catch(() => void 0);
10116
10695
  }
10117
10696
  }
10118
10697
  async function safeManagedDirectory(project, relative2, absolute) {
10119
- await assertNoSymlinkComponents(project, path11.dirname(relative2));
10120
- const existing = await fs7.lstat(absolute).catch(() => void 0);
10698
+ await assertNoSymlinkComponents(project, path12.dirname(relative2));
10699
+ const existing = await fs8.lstat(absolute).catch(() => void 0);
10121
10700
  if (existing?.isSymbolicLink()) throw invalid2(`\u53D7\u7BA1\u76EE\u5F55\u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5\uFF1A${relative2}`);
10122
10701
  if (existing && !existing.isDirectory()) throw invalid2(`\u53D7\u7BA1\u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55\uFF1A${relative2}`);
10123
- if (!existing) await fs7.mkdir(absolute, { mode: 448 });
10124
- await fs7.chmod(absolute, 448);
10702
+ if (!existing) await fs8.mkdir(absolute, { mode: 448 });
10703
+ await fs8.chmod(absolute, 448);
10125
10704
  }
10126
10705
  async function pathExists(file) {
10127
- return fs7.lstat(file).then(
10706
+ return fs8.lstat(file).then(
10128
10707
  () => true,
10129
10708
  (cause) => {
10130
10709
  if (cause.code === "ENOENT") return false;
@@ -10133,65 +10712,68 @@ async function pathExists(file) {
10133
10712
  );
10134
10713
  }
10135
10714
  async function readSafeFile(project, file, label) {
10136
- const relative2 = path11.relative(project, file).split(path11.sep).join("/");
10137
- if (relative2.startsWith("../") || path11.isAbsolute(relative2))
10715
+ const relative2 = path12.relative(project, file).split(path12.sep).join("/");
10716
+ if (relative2.startsWith("../") || path12.isAbsolute(relative2))
10138
10717
  throw invalid2(`${label}\u8DEF\u5F84\u9003\u9038\u9879\u76EE`);
10139
10718
  await assertNoSymlinkComponents(project, relative2);
10140
10719
  let stat;
10141
10720
  try {
10142
- stat = await fs7.lstat(file);
10721
+ stat = await fs8.lstat(file);
10143
10722
  } catch (cause) {
10144
10723
  throw invalid2(`${label}\u4E0D\u53EF\u7528\uFF1A${relative2}`, cause);
10145
10724
  }
10146
10725
  if (stat.isSymbolicLink()) throw invalid2(`${label}\u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5\uFF1A${relative2}`);
10147
10726
  if (!stat.isFile()) throw invalid2(`${label}\u4E0D\u662F\u666E\u901A\u6587\u4EF6\uFF1A${relative2}`);
10148
- return fs7.readFile(file);
10727
+ return fs8.readFile(file);
10149
10728
  }
10150
10729
  async function assertNoSymlinkComponents(project, relative2) {
10151
10730
  const parts = relative2.split("/").filter(Boolean);
10152
10731
  let current = project;
10153
10732
  for (const part of parts) {
10154
- current = path11.join(current, part);
10155
- const stat = await fs7.lstat(current).catch(() => void 0);
10733
+ current = path12.join(current, part);
10734
+ const stat = await fs8.lstat(current).catch(() => void 0);
10156
10735
  if (stat?.isSymbolicLink()) throw invalid2(`\u8DEF\u5F84\u5305\u542B\u7B26\u53F7\u94FE\u63A5\uFF1A${relative2}`);
10157
10736
  if (!stat) break;
10158
10737
  }
10159
10738
  }
10160
10739
  async function realProject(requested) {
10161
- const absolute = path11.resolve(requested);
10740
+ const absolute = path12.resolve(requested);
10162
10741
  let project;
10163
10742
  try {
10164
- project = await fs7.realpath(absolute);
10743
+ project = await fs8.realpath(absolute);
10165
10744
  } catch (cause) {
10166
10745
  throw invalid2(`\u9879\u76EE\u76EE\u5F55\u4E0D\u53EF\u7528\uFF1A${absolute}`, cause);
10167
10746
  }
10168
- const stat = await fs7.stat(project);
10747
+ const stat = await fs8.stat(project);
10169
10748
  if (!stat.isDirectory()) throw invalid2(`\u9879\u76EE\u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55\uFF1A${absolute}`);
10170
10749
  return project;
10171
10750
  }
10172
10751
  function safeRelative(reference, label) {
10173
- if (!reference || path11.isAbsolute(reference) || /[\r\n\0]/.test(reference)) {
10752
+ if (!reference || path12.isAbsolute(reference) || /[\r\n\0]/.test(reference)) {
10174
10753
  throw invalid2(`${label}\u5FC5\u987B\u662F\u9879\u76EE\u5185\u76F8\u5BF9\u8DEF\u5F84`);
10175
10754
  }
10176
- const normalized = path11.normalize(reference).split(path11.sep).join("/");
10755
+ const normalized = path12.normalize(reference).split(path12.sep).join("/");
10177
10756
  if (normalized === ".." || normalized.startsWith("../") || normalized === ".") {
10178
10757
  throw invalid2(`${label}\u8DEF\u5F84\u9003\u9038\u9879\u76EE`);
10179
10758
  }
10180
10759
  return normalized.replace(/^\.\//, "");
10181
10760
  }
10182
10761
  function isRuntimeIdentity(value) {
10183
- if (!isRecord(value) || !isSha(value.executableSha256)) return false;
10762
+ if (!isRecord2(value) || !isSha(value.executableSha256)) return false;
10184
10763
  if (value.kind === "executable") return true;
10185
10764
  return value.kind === "node-entry" && isSha(value.entrySha256);
10186
10765
  }
10187
10766
  function isExecutionPlan(value) {
10188
- if (!isRecord(value)) return false;
10189
- return value.schemaVersion === 1 && value.contractVersion === EXECUTION_CONTRACT_VERSION && typeof value.planId === "string" && PLAN_ID_PATTERN.test(value.planId) && typeof value.createdAt === "string" && typeof value.expiresAt === "string" && isSha(value.nonceSha256) && isSha(value.skillsLockSha256) && isRuntimeIdentity(value.runtime) && isRecord(value.assessment) && isRecord(value.documents) && isBoundDocument(value.documents.change) && isBoundDocument(value.documents.rollback) && Array.isArray(value.payloads) && value.payloads.every(isBoundDocument) && typeof value.evidenceDir === "string";
10767
+ if (!isRecord2(value)) return false;
10768
+ return value.schemaVersion === 1 && value.contractVersion === EXECUTION_CONTRACT_VERSION && typeof value.planId === "string" && PLAN_ID_PATTERN.test(value.planId) && typeof value.createdAt === "string" && typeof value.expiresAt === "string" && isSha(value.nonceSha256) && isSha(value.skillsLockSha256) && isRuntimeIdentity(value.runtime) && isRecord2(value.assessment) && isRecord2(value.documents) && isBoundDocument(value.documents.change) && isBoundDocument(value.documents.rollback) && Array.isArray(value.payloads) && value.payloads.every(isBoundPayload) && typeof value.evidenceDir === "string";
10190
10769
  }
10191
10770
  function isBoundDocument(value) {
10192
- return isRecord(value) && typeof value.path === "string" && isSha(value.sha256);
10771
+ return isRecord2(value) && typeof value.path === "string" && isSha(value.sha256);
10193
10772
  }
10194
- function isRecord(value) {
10773
+ function isBoundPayload(value) {
10774
+ return isBoundDocument(value) && "kind" in value && (value.kind === "file" || value.kind === "directory");
10775
+ }
10776
+ function isRecord2(value) {
10195
10777
  return typeof value === "object" && value !== null && !Array.isArray(value);
10196
10778
  }
10197
10779
  function isSha(value) {
@@ -10204,7 +10786,7 @@ function parseTtl(value) {
10204
10786
  }
10205
10787
  function canonicalJson(value) {
10206
10788
  if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`;
10207
- if (isRecord(value)) {
10789
+ if (isRecord2(value)) {
10208
10790
  return `{${Object.keys(value).sort().map((key2) => `${JSON.stringify(key2)}:${canonicalJson(value[key2])}`).join(",")}}`;
10209
10791
  }
10210
10792
  return JSON.stringify(value) ?? "null";
@@ -10354,7 +10936,7 @@ var exitOnBrokenPipe = (err) => {
10354
10936
  process.stdout.on("error", exitOnBrokenPipe);
10355
10937
  process.stderr.on("error", exitOnBrokenPipe);
10356
10938
  program.name("hcm").description("HCM \u547D\u4EE4\u884C\u5DE5\u5177 \u2014 \u64CD\u4F5C HCM API\u3001\u4E0E Moirai \u6570\u5B57\u5458\u5DE5\u5BF9\u8BDD\u3001\u5F00\u53D1\u79DF\u6237\u5F00\u53D1\u7A7A\u95F4").version(CLI_VERSION);
10357
- program.command("login").description("\u767B\u5F55 HCM\uFF08\u914D\u5BF9\u7801 / \u7528\u6237\u540D\u5BC6\u7801 / client_credentials / PAT \u56DB\u79CD\u65B9\u5F0F\uFF09").argument("[endpoint]", "\u4ECE\u7CFB\u7EDF\u9875\u9762\u300C\u547D\u4EE4\u884C\u5DE5\u5177\u300D\u590D\u5236\u6765\u7684\u5730\u5740\uFF08\u914D\u5BF9\u7801\u65B9\u5F0F\uFF09").option("--code <code>", "\u914D\u5BF9\u7801\uFF0C\u5728\u7CFB\u7EDF\u9875\u9762\u7528\u6237\u83DC\u5355 \u2192\u300C\u547D\u4EE4\u884C\u5DE5\u5177\u300D\u751F\u6210").option("--env <name>", "\u73AF\u5883\u540D\uFF08\u9ED8\u8BA4 activeEnv\uFF09").option("--profile <name>", "[deprecated] \u7528 --env \u66FF\u4EE3").option("--name <id-name>", "\u81EA\u5B9A\u4E49 identity \u540D\uFF08\u9ED8\u8BA4\u6309 scheme \u63A8\u65AD\uFF09").option("--no-activate", "login \u5B8C\u4E0D\u5207\u5230\u8BE5\u73AF\u5883\u4E5F\u4E0D\u8BBE\u4E3A default identity").option("--endpoint <url>", "HCM \u540E\u7AEF\u5730\u5740\uFF0C\u4F8B\u5982 http://localhost:8080").option("--username <user>", "\u7528\u6237\u540D\uFF08\u5BC6\u7801\u767B\u5F55\u6A21\u5F0F\uFF09").option("--password <pwd>", "\u5BC6\u7801\uFF08\u5BC6\u7801\u767B\u5F55\u6A21\u5F0F\uFF09").option("--client-id <id>", "OAuth client_id\uFF08client_credentials \u6A21\u5F0F\uFF09").option("--client-secret <secret>", "OAuth client_secret\uFF08client_credentials \u6A21\u5F0F\uFF09").option("--pat <token>", "PAT \u4E2A\u4EBA\u8BBF\u95EE\u4EE4\u724C\uFF08\u6CE8\u610F\uFF1A\u4F1A\u6CC4\u6F0F\u5230 ps/history\uFF0C\u5EFA\u8BAE\u6539\u7528 --pat-stdin\uFF09").option("--pat-stdin", "\u4ECE\u6807\u51C6\u8F93\u5165\u8BFB\u53D6 PAT\uFF08\u63A8\u8350\uFF09").option("--new-password <pwd>", "\u9996\u767B\u5F3A\u5236\u6539\u5BC6\u65F6\u7684\u65B0\u53E3\u4EE4\uFF08\u4F1A\u6CC4\u6F0F\u5230 history/ps\uFF0C\u5EFA\u8BAE --new-password-stdin\uFF09").option("--new-password-stdin", "\u9996\u767B\u5F3A\u5236\u6539\u5BC6\u65F6\u4ECE\u6807\u51C6\u8F93\u5165\u8BFB\u65B0\u53E3\u4EE4\uFF08\u975E\u4EA4\u4E92\u573A\u666F\uFF09").option("--tenant <tenantId>", "\u79DF\u6237 ID\uFF08\u9ED8\u8BA4 1\uFF09").action((endpoint, opts) => loginCommand({ ...opts, endpointArg: endpoint }));
10939
+ program.command("login").description("\u767B\u5F55 HCM\uFF08\u914D\u5BF9\u7801 / \u7528\u6237\u540D\u5BC6\u7801 / client_credentials / PAT \u56DB\u79CD\u65B9\u5F0F\uFF09").argument("[endpoint]", "\u4ECE\u7CFB\u7EDF\u9875\u9762\u300C\u547D\u4EE4\u884C\u5DE5\u5177\u300D\u590D\u5236\u6765\u7684\u5730\u5740\uFF08\u914D\u5BF9\u7801\u65B9\u5F0F\uFF09").option("--code <code>", "\u914D\u5BF9\u7801\uFF0C\u5728\u7CFB\u7EDF\u9875\u9762\u7528\u6237\u83DC\u5355 \u2192\u300C\u547D\u4EE4\u884C\u5DE5\u5177\u300D\u751F\u6210").option("--env <name>", "\u73AF\u5883\u540D\uFF08\u9ED8\u8BA4 activeEnv\uFF09").option("--profile <name>", "[deprecated] \u7528 --env \u66FF\u4EE3").option("--name <id-name>", "\u81EA\u5B9A\u4E49 identity \u540D\uFF08\u9ED8\u8BA4\u6309 scheme \u63A8\u65AD\uFF09").option("--no-activate", "login \u5B8C\u4E0D\u5207\u5230\u8BE5\u73AF\u5883\u4E5F\u4E0D\u8BBE\u4E3A default identity").option("--endpoint <url>", "HCM \u540E\u7AEF\u5730\u5740\uFF0C\u4F8B\u5982 http://localhost:8080").option("--username <user>", "\u7528\u6237\u540D\uFF08\u5BC6\u7801\u767B\u5F55\u6A21\u5F0F\uFF09").option("--password <pwd>", "\u5BC6\u7801\uFF08\u5BC6\u7801\u767B\u5F55\u6A21\u5F0F\uFF1B\u4F1A\u6CC4\u6F0F\u5230 history/ps\uFF0CAgent/\u53D7\u63A7\u4EA4\u4ED8\u8BF7\u7528 --password-stdin\uFF09").option("--password-stdin", "\u4ECE\u6807\u51C6\u8F93\u5165\u8BFB\u5BC6\u7801\uFF08\u5BC6\u7801\u767B\u5F55\u6A21\u5F0F\uFF0C\u975E\u4EA4\u4E92/\u4E0D\u56DE\u663E\uFF09").option("--client-id <id>", "OAuth client_id\uFF08client_credentials \u6A21\u5F0F\uFF09").option("--client-secret <secret>", "OAuth client_secret\uFF08client_credentials \u6A21\u5F0F\uFF09").option("--pat <token>", "PAT \u4E2A\u4EBA\u8BBF\u95EE\u4EE4\u724C\uFF08\u6CE8\u610F\uFF1A\u4F1A\u6CC4\u6F0F\u5230 ps/history\uFF0C\u5EFA\u8BAE\u6539\u7528 --pat-stdin\uFF09").option("--pat-stdin", "\u4ECE\u6807\u51C6\u8F93\u5165\u8BFB\u53D6 PAT\uFF08\u63A8\u8350\uFF09").option("--new-password <pwd>", "\u9996\u767B\u5F3A\u5236\u6539\u5BC6\u65F6\u7684\u65B0\u53E3\u4EE4\uFF08\u4F1A\u6CC4\u6F0F\u5230 history/ps\uFF0C\u5EFA\u8BAE --new-password-stdin\uFF09").option("--new-password-stdin", "\u9996\u767B\u5F3A\u5236\u6539\u5BC6\u65F6\u4ECE\u6807\u51C6\u8F93\u5165\u8BFB\u65B0\u53E3\u4EE4\uFF08\u975E\u4EA4\u4E92\u573A\u666F\uFF09").option("--tenant <tenantId>", "\u79DF\u6237 ID\uFF08\u9ED8\u8BA4 1\uFF09").action((endpoint, opts) => loginCommand({ ...opts, endpointArg: endpoint }));
10358
10940
  program.command("logout").description("\u767B\u51FA HCM\uFF08\u6E05\u9664 identity \u7684 keychain token\uFF09").option("--identity <name>", "\u6307\u5B9A identity\uFF1B\u9ED8\u8BA4\u6E05\u5F53\u524D env \u7684 default identity").option("--env <name>", "\u6307\u5B9A env\uFF08\u5F71\u54CD default identity \u89E3\u6790\uFF09").action((opts) => logoutCommand(opts));
10359
10941
  var config = program.command("config").description("\u7BA1\u7406\u5168\u5C40 defaults\uFF08env/identity \u7528 `hcm env` / `hcm identity`\uFF09");
10360
10942
  config.command("list").description("[deprecated] \u7528 `hcm env list`").action(() => configListDeprecated());
@@ -10442,14 +11024,17 @@ delivery.command("triage").description(
10442
11024
  "--recon <dir>",
10443
11025
  "\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"
10444
11026
  ).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));
10445
- delivery.command("init").description("\u751F\u6210\u53D7\u63A7\u6267\u884C\u6240\u9700\u7684\u9879\u76EE\u9AA8\u67B6\uFF08.hcm-delivery/project.yml + work/ decisions/ evidence/\uFF09").option("--project <dir>", "HCM \u987E\u95EE\u9879\u76EE\u6839\u76EE\u5F55", ".").option("--mode <mode>", "\u4EA4\u4ED8\u6A21\u5F0F\uFF1Acontrolled | plan-only", "controlled").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));
10446
- delivery.command("mode").description("\u770B/\u6539\u672C\u9879\u76EE\u7684\u4EA4\u4ED8\u6A21\u5F0F\uFF1B\u4E0D\u5E26 --set \u53EA\u8BFB\uFF0C\u5E26 --set \u5C31\u5730\u6539\u90A3\u4E00\u884C\uFF08\u4E0D\u8986\u76D6\u6574\u4EFD\u914D\u7F6E\uFF09").option("--project <dir>", "HCM \u987E\u95EE\u9879\u76EE\u6839\u76EE\u5F55", ".").option("--set <mode>", "\u6539\u4E3A\uFF1Acontrolled | plan-only").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((opts) => deliveryModeCommand(opts));
11027
+ 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("--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));
11028
+ 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", ".").option("--env <name>", "\u76EE\u6807\u73AF\u5883\uFF08\u9ED8\u8BA4 HCM_ENV / activeEnv\uFF09").option("--set <mode>", "\u6539\u4E3A\uFF1Acontrolled | plan-only").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((opts) => deliveryModeCommand(opts));
10447
11029
  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));
10448
11030
  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));
10449
- program.command("query <Model>").description("\u67E5\u8BE2 Model \u5217\u8868\u6570\u636E\uFF08\u901A\u8FC7 ModelQueryDsl JSON \u8868\u8FBE\u8FC7\u6EE4/\u6392\u5E8F/\u5206\u9875\uFF09").option(
11031
+ program.command("query <Model>").description("\u67E5\u8BE2 Model \u5217\u8868\u6570\u636E\uFF08\u901A\u8FC7 ModelQueryDsl JSON \u8868\u8FBE\u8FC7\u6EE4/\u6392\u5E8F/\u5173\u8054/\u5206\u9875\uFF09").option(
10450
11032
  "--filter <JSON>",
10451
11033
  `\u8FC7\u6EE4 AST\uFF08ModelQueryDsl\uFF09\uFF1A\u53F6\u5B50 '{"field":"status","op":"eq","value":"ACTIVE"}'\uFF0C\u591A\u6761\u4EF6\u7528 '{"and":[\u53F6\u5B50,\u2026]}'\u3002\u26A0\uFE0F \u4E0D\u63A5\u53D7 {"\u5B57\u6BB5":"\u503C"} \u7B80\u5199\uFF0Cschema \u5C42\u4F1A\u62D2`
10452
- ).option("--sort <JSON>", `\u6392\u5E8F\u6761\u4EF6 JSON\uFF0C\u4F8B\u5982 '[{"field":"hireDate","direction":"desc"}]'`).option("--fields <list>", "\u8FD4\u56DE\u5B57\u6BB5\u5217\u8868\uFF08\u9017\u53F7\u5206\u9694\uFF09\uFF0C\u4F8B\u5982 name,code,email").option("--keyword <text>", "\u5168\u6587\u68C0\u7D22\u5173\u952E\u5B57").option("--limit <n>", "\u6BCF\u9875\u5927\u5C0F", "20").option("--offset <n>", "\u504F\u79FB\u91CF\uFF08\u6309 limit \u81EA\u52A8\u6362\u7B97 page\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", "table").action((m, opts) => queryCommand(m, opts));
11034
+ ).option("--sort <JSON>", `\u6392\u5E8F\u6761\u4EF6 JSON\uFF0C\u4F8B\u5982 '[{"field":"hireDate","direction":"desc"}]'`).option(
11035
+ "--additions <JSON>",
11036
+ `\u8DE8\u5173\u7CFB JOIN \u7684\u5BF9\u8C61\u6570\u7EC4 JSON\uFF0C\u4F8B\u5982 '[{"key":"employee","model":"Employee"}]'`
11037
+ ).option("--fields <list>", "\u8FD4\u56DE\u5B57\u6BB5\u5217\u8868\uFF08\u9017\u53F7\u5206\u9694\uFF09\uFF0C\u4F8B\u5982 name,code,email").option("--keyword <text>", "\u5168\u6587\u68C0\u7D22\u5173\u952E\u5B57").option("--limit <n>", "\u6BCF\u9875\u5927\u5C0F", "20").option("--offset <n>", "\u504F\u79FB\u91CF\uFF08\u6309 limit \u81EA\u52A8\u6362\u7B97 page\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", "table").action((m, opts) => queryCommand(m, opts));
10453
11038
  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("--scope <scope>", "\u5F3A\u5236 Action scope\uFF1Aclass | object\uFF08\u9ED8\u8BA4\uFF1A\u6709 --id \u4E3A object\uFF0C\u5426\u5219 class\uFF09").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));
10454
11039
  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("--i18n", "\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").action((m, opts) => createCommand(m, opts));
10455
11040
  program.command("delete <Model>").description("\u5220\u9664\u4E00\u6761 Model \u8BB0\u5F55\uFF08\u8D70\u540E\u7AEF\u5B8C\u6574\u6821\u9A8C\uFF1B\u90E8\u5206 Model \u4F1A\u6267\u884C\u4E1A\u52A1\u64A4\u9500\uFF09").option("--id <id>", "\u76EE\u6807\u5B9E\u4F53 ID\uFF08\u5FC5\u586B\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((m, opts) => deleteCommand(m, opts));
@@ -10525,7 +11110,7 @@ skills.command("update").description("\u628A\u88C5\u8FC7\u7684\u6280\u80FD\u5347
10525
11110
  program.command("update <Model>").description("\u66F4\u65B0\u4E00\u6761 Model \u8BB0\u5F55\uFF08\u8D70\u540E\u7AEF\u5B8C\u6574\u6821\u9A8C\uFF09\u3002\u5347\u7EA7 CLI \u8BF7\u7528 `hcm upgrade`").requiredOption("--id <id>", "\u8BB0\u5F55 ID").option("--data <JSON>", `\u8981\u66F4\u65B0\u7684\u5B57\u6BB5 JSON\uFF0C\u4F8B\u5982 '{"name":"\u65B0\u540D\u79F0"}'`).option("--data-file <path>", "\u4ECE UTF-8 JSON \u6587\u4EF6\u8BFB\u53D6\u66F4\u65B0\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("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").option("--i18n", "\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").action((model, opts) => updateCommand(model, opts));
10526
11111
  program.command("version").description("\u67E5 CLI \u4E0E\u540E\u7AEF\u4E24\u4E2A\u7248\u672C\uFF08commit / tag / \u6784\u5EFA\u65F6\u95F4\uFF09\u2014\u2014\u514D\u8BA4\u8BC1\uFF0C\u65E0\u9700\u5148 login").option("--endpoint <url>", "\u540E\u7AEF\u5730\u5740\uFF08\u9ED8\u8BA4\u53D6 activeEnv \u7684 endpoint\uFF09").option("--env <name>", "\u4ECE\u8BE5 env \u89E3\u6790 endpoint").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((opts) => versionCommand(opts));
10527
11112
  program.command("upgrade").alias("self-update").description("\u5347\u7EA7 CLI \u81EA\u5DF1\uFF08\u6CE8\u610F\uFF1A`hcm update` \u662F\u66F4\u65B0\u4E1A\u52A1\u8BB0\u5F55\uFF0C\u4E0D\u662F\u5347\u7EA7\uFF09").option("--check", "\u53EA\u68C0\u67E5\uFF1B\u6709\u65B0\u7248\u672C\u65F6\u4EE5\u9000\u51FA\u7801 1 \u7ED3\u675F\uFF0C\u4FBF\u4E8E\u811A\u672C\u5224\u65AD").action((opts) => upgradeCommand(opts));
10528
- program.command("open [path]").description("\u7528\u5F53\u524D CLI \u8EAB\u4EFD\u6253\u5F00\u524D\u7AEF\u9875\u9762\uFF1A\u94F8\u4E00\u5F20 60s \u4E00\u6B21\u6027\u7968\u636E\u4EA4\u7ED9\u6D4F\u89C8\u5668\uFF0C\u4F1A\u8BDD token \u4E0D\u8FDB URL").option("--print-url", "\u53EA\u6253\u5370\u767B\u5F55 URL\uFF0C\u4E0D\u5F00\u6D4F\u89C8\u5668\uFF08\u7ED9 agent \u6D4F\u89C8\u5668 navigate \u7528\uFF09").option("--env <name>", "\u4E34\u65F6\u5207\u73AF\u5883\uFF08\u8986\u76D6 activeEnv\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD\uFF08\u8986\u76D6 env defaultIdentity\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--profile <name>", "[deprecated] \u7528 --env \u66FF\u4EE3").action((path12, opts) => openCommand(path12, opts));
11113
+ program.command("open [path]").description("\u7528\u5F53\u524D CLI \u8EAB\u4EFD\u6253\u5F00\u524D\u7AEF\u9875\u9762\uFF1A\u94F8\u4E00\u5F20 60s \u4E00\u6B21\u6027\u7968\u636E\u4EA4\u7ED9\u6D4F\u89C8\u5668\uFF0C\u4F1A\u8BDD token \u4E0D\u8FDB URL").option("--print-url", "\u53EA\u6253\u5370\u767B\u5F55 URL\uFF0C\u4E0D\u5F00\u6D4F\u89C8\u5668\uFF08\u7ED9 agent \u6D4F\u89C8\u5668 navigate \u7528\uFF09").option("--env <name>", "\u4E34\u65F6\u5207\u73AF\u5883\uFF08\u8986\u76D6 activeEnv\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD\uFF08\u8986\u76D6 env defaultIdentity\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--profile <name>", "[deprecated] \u7528 --env \u66FF\u4EE3").action((path13, opts) => openCommand(path13, opts));
10529
11114
  var setting = program.command("setting").description("\u79DF\u6237\u7CFB\u7EDF\u53C2\u6570\uFF08\u767B\u5F55\u7B56\u7565 / \u5BC6\u7801\u7B56\u7565 / \u529F\u80FD\u5F00\u5173 / \u96C6\u6210\u53C2\u6570\uFF09");
10530
11115
  setting.command("get <domain>").description("\u8BFB\u67D0\u57DF\u53C2\u6570\uFF08\u5B9A\u4E49 + \u79DF\u6237\u8986\u76D6\u503C\u5408\u5E76\uFF0C\u7F3A\u5931\u56DE\u843D\u9ED8\u8BA4\u503C\uFF09").option("--env <name>", "\u4E34\u65F6\u5207\u73AF\u5883\uFF08\u8986\u76D6 activeEnv\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((d, opts) => settingGetCommand(d, opts));
10531
11116
  setting.command("set <domain>").description("\u6539\u53C2\u6570\uFF0C\u53EF\u91CD\u590D --set\uFF1B\u8D70\u53D7\u63A7\u6821\u9A8C\u8DEF\u5F84\u800C\u975E\u6807\u51C6 CRUD").option("--set <assignment...>", "namespace.key=value\uFF0C\u4F8B\u5982 security.password.passwordPolicy=complex").option("--dry-run", "\u53EA\u663E\u793A\u5C06\u5199\u5165\u4EC0\u4E48\uFF0C\u4E0D\u5B9E\u9645\u5199\u5165").option("--env <name>", "\u4E34\u65F6\u5207\u73AF\u5883\uFF08\u8986\u76D6 activeEnv\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((d, opts) => settingSetCommand(d, opts));