@hcmai/cli 0.4.20 → 0.4.22

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
@@ -28,7 +28,7 @@ function exitWithError(err) {
28
28
  }
29
29
  function exitOk(stdout) {
30
30
  if (stdout) process.stdout.write(stdout + "\n");
31
- process.exit(0);
31
+ process.exitCode = 0;
32
32
  }
33
33
  var init_exit = __esm({
34
34
  "src/utils/exit.ts"() {
@@ -523,8 +523,8 @@ var init_TerminalRenderer = __esm({
523
523
  }
524
524
  }
525
525
  /** 来源行(仅子代理触发,agentPath ≥2 段时显示 `↑ 来自 a › b`,对齐 Web)。 */
526
- originLine(path13) {
527
- const segs = path13.split(".").filter(Boolean);
526
+ originLine(path14) {
527
+ const segs = path14.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(path13) {
1710
- const segs = (path13 ?? "").split(".").filter(Boolean);
1709
+ function originLine(path14) {
1710
+ const segs = (path14 ?? "").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
  }
@@ -1880,7 +1880,8 @@ async function runInkRepl(args) {
1880
1880
  );
1881
1881
  await waitUntilExit();
1882
1882
  await ws.close();
1883
- process.exit(0);
1883
+ process.exitCode = 0;
1884
+ return;
1884
1885
  } catch (e) {
1885
1886
  exitWithError(e);
1886
1887
  }
@@ -2292,15 +2293,15 @@ async function loginCommand(args) {
2292
2293
  gl.activeEnv = envName;
2293
2294
  await saveGlobalConfig(gl);
2294
2295
  }
2295
- exitOk(
2296
+ return exitOk(
2296
2297
  `\u2705 logged in (env=${envName}, identity=${idName}, scheme=${scheme}, ${describePrincipal(principal)}, scopes=${scopes.join(" ")})`
2297
2298
  );
2298
2299
  } catch (e) {
2299
2300
  const err = e;
2300
2301
  if (err.isAxiosError) {
2301
- const { fromAxiosError: fromAxiosError24 } = await import("@hcmai/sdk");
2302
+ const { fromAxiosError: fromAxiosError25 } = await import("@hcmai/sdk");
2302
2303
  exitWithError(
2303
- fromAxiosError24(
2304
+ fromAxiosError25(
2304
2305
  e,
2305
2306
  envName
2306
2307
  )
@@ -2319,8 +2320,7 @@ async function logoutCommand(args) {
2319
2320
  const envCfg = await loadEnv(envName).catch(() => null);
2320
2321
  const dflt = envCfg?.defaultIdentity;
2321
2322
  if (!dflt) {
2322
- exitOk("(no active identity to log out)");
2323
- return;
2323
+ return exitOk("(no active identity to log out)");
2324
2324
  }
2325
2325
  target = dflt;
2326
2326
  }
@@ -2329,9 +2329,9 @@ async function logoutCommand(args) {
2329
2329
  const revoked = await revokeOnServer(store, envName ?? idMeta.env);
2330
2330
  await store.clear();
2331
2331
  if (revoked) {
2332
- exitOk(`\u2705 logged out (identity: ${target})`);
2332
+ return exitOk(`\u2705 logged out (identity: ${target})`);
2333
2333
  } else {
2334
- exitOk(
2334
+ return exitOk(
2335
2335
  `\u26A0\uFE0F \u5DF2\u6E05\u9664\u672C\u5730\u51ED\u636E (identity: ${target})\uFF0C\u4F46\u670D\u52A1\u7AEF\u540A\u9500\u672A\u786E\u8BA4\u2014\u2014\u8BE5 token \u53EF\u80FD\u4ECD\u7136\u6709\u6548\u76F4\u81F3\u81EA\u7136\u8FC7\u671F\u3002\u82E5\u51ED\u636E\u53EF\u80FD\u5DF2\u6CC4\u6F0F\uFF0C\u8BF7\u6539\u5BC6\u4EE5\u540A\u9500\u5168\u90E8\u4F1A\u8BDD\u3002`
2336
2336
  );
2337
2337
  }
@@ -2405,8 +2405,7 @@ async function envList() {
2405
2405
  const envs = await listEnvs();
2406
2406
  const g = await loadGlobalConfig2();
2407
2407
  if (envs.length === 0) {
2408
- exitOk("(no envs; run `hcm env add <name> --endpoint <url>`)");
2409
- return;
2408
+ return exitOk("(no envs; run `hcm env add <name> --endpoint <url>`)");
2410
2409
  }
2411
2410
  const rows = await Promise.all(
2412
2411
  envs.map(async (name) => {
@@ -2421,7 +2420,7 @@ async function envList() {
2421
2420
  };
2422
2421
  })
2423
2422
  );
2424
- exitOk(formatTable(rows));
2423
+ return exitOk(formatTable(rows));
2425
2424
  } catch (e) {
2426
2425
  exitWithError(e);
2427
2426
  }
@@ -2431,12 +2430,11 @@ async function envCurrent() {
2431
2430
  const g = await loadGlobalConfig2();
2432
2431
  const cfg = await loadEnv2(g.activeEnv).catch(() => null);
2433
2432
  if (!cfg) {
2434
- exitOk("(no active env; run `hcm env add <name> --endpoint <url>`)");
2435
- return;
2433
+ return exitOk("(no active env; run `hcm env add <name> --endpoint <url>`)");
2436
2434
  }
2437
2435
  const idName = cfg.defaultIdentity ?? "(none)";
2438
2436
  const frontend = cfg.frontend ? ` frontend=${cfg.frontend}` : "";
2439
- exitOk(`\u2192 ${g.activeEnv} ${cfg.endpoint}${frontend} tenant=${cfg.tenantId ?? "1"} identity=${idName}`);
2437
+ return exitOk(`\u2192 ${g.activeEnv} ${cfg.endpoint}${frontend} tenant=${cfg.tenantId ?? "1"} identity=${idName}`);
2440
2438
  } catch (e) {
2441
2439
  exitWithError(e);
2442
2440
  }
@@ -2468,7 +2466,7 @@ async function envAdd(name, args) {
2468
2466
  g.activeEnv = name;
2469
2467
  await saveGlobalConfig2(g);
2470
2468
  }
2471
- exitOk(`\u2705 env '${name}' added. Run: hcm login --env ${name}`);
2469
+ return exitOk(`\u2705 env '${name}' added. Run: hcm login --env ${name}`);
2472
2470
  } catch (e) {
2473
2471
  exitWithError(e);
2474
2472
  }
@@ -2500,7 +2498,7 @@ async function envUse(name, args) {
2500
2498
  );
2501
2499
  }
2502
2500
  }
2503
- exitOk(`\u2705 active env: ${name}`);
2501
+ return exitOk(`\u2705 active env: ${name}`);
2504
2502
  } catch (e) {
2505
2503
  exitWithError(e);
2506
2504
  }
@@ -2510,8 +2508,7 @@ async function envRemove(name, args) {
2510
2508
  if (!args.force) {
2511
2509
  const ok = await promptConfirm(`remove env '${name}' and all its identities? [y/N] `);
2512
2510
  if (!ok) {
2513
- exitOk("aborted");
2514
- return;
2511
+ return exitOk("aborted");
2515
2512
  }
2516
2513
  }
2517
2514
  const ids = await listIdentities(name);
@@ -2537,7 +2534,7 @@ async function envRemove(name, args) {
2537
2534
  const removedCount = ids.length - failed2.length;
2538
2535
  const noun = (n) => n === 1 ? "identity" : "identities";
2539
2536
  const failPart = failed2.length > 0 ? `, ${failed2.length} ${noun(failed2.length)} failed: ${failed2.join(", ")}` : "";
2540
- exitOk(`\u2705 env '${name}' removed (${removedCount} ${noun(removedCount)} removed${failPart})`);
2537
+ return exitOk(`\u2705 env '${name}' removed (${removedCount} ${noun(removedCount)} removed${failPart})`);
2541
2538
  } catch (e) {
2542
2539
  exitWithError(e);
2543
2540
  }
@@ -2548,7 +2545,7 @@ async function envShow(args) {
2548
2545
  const target = args.name ?? g.activeEnv;
2549
2546
  const cfg = await loadEnv2(target);
2550
2547
  const ids = await listIdentities(target);
2551
- exitOk(
2548
+ return exitOk(
2552
2549
  toYaml({
2553
2550
  name: target,
2554
2551
  active: target === g.activeEnv,
@@ -2577,7 +2574,7 @@ async function envEdit(field, value, args) {
2577
2574
  }
2578
2575
  cfg[field] = value;
2579
2576
  await saveEnv2(name, cfg);
2580
- exitOk(`\u2705 ${name}.${field} = ${value}`);
2577
+ return exitOk(`\u2705 ${name}.${field} = ${value}`);
2581
2578
  } catch (e) {
2582
2579
  exitWithError(e);
2583
2580
  }
@@ -2620,7 +2617,7 @@ async function configSet(key2, value) {
2620
2617
  g.defaults = g.defaults ?? {};
2621
2618
  g.defaults[sub] = value;
2622
2619
  await saveGlobalConfig3(g);
2623
- exitOk(`\u2705 defaults.${sub} = ${value}`);
2620
+ return exitOk(`\u2705 defaults.${sub} = ${value}`);
2624
2621
  } catch (e) {
2625
2622
  exitWithError(e);
2626
2623
  }
@@ -2635,7 +2632,7 @@ async function configGet(key2) {
2635
2632
  }
2636
2633
  const sub = key2.slice("defaults.".length);
2637
2634
  const g = await loadGlobalConfig3();
2638
- exitOk(String(g.defaults?.[sub] ?? ""));
2635
+ return exitOk(String(g.defaults?.[sub] ?? ""));
2639
2636
  } catch (e) {
2640
2637
  exitWithError(e);
2641
2638
  }
@@ -2811,16 +2808,7 @@ async function actionCommand(spec, args) {
2811
2808
  }
2812
2809
  const result = await client3.action(model, action, input);
2813
2810
  const fmt = args.output ?? "json";
2814
- if (fmt !== "json" && result.taskId) {
2815
- process.stdout.write(
2816
- `\u23F3 task created: ${result.taskId} (use \`hcm task ${result.taskId}\` to follow up \u2014 coming Phase 1)
2817
- `
2818
- );
2819
- } else if (fmt !== "json") {
2820
- process.stdout.write("\u2705 action succeeded\n");
2821
- }
2822
- process.stdout.write(formatObject(result, { format: fmt }) + "\n");
2823
- process.exit(0);
2811
+ printActionResult(result, fmt);
2824
2812
  } catch (e) {
2825
2813
  const err = e;
2826
2814
  if (err?.isAxiosError) {
@@ -2829,6 +2817,18 @@ async function actionCommand(spec, args) {
2829
2817
  exitWithError(e);
2830
2818
  }
2831
2819
  }
2820
+ function printActionResult(result, fmt) {
2821
+ if (fmt !== "json" && result.taskId) {
2822
+ process.stdout.write(
2823
+ `\u23F3 task created: ${result.taskId} (use \`hcm task ${result.taskId}\` to follow up \u2014 coming Phase 1)
2824
+ `
2825
+ );
2826
+ } else if (fmt !== "json") {
2827
+ process.stdout.write("\u2705 action succeeded\n");
2828
+ }
2829
+ process.stdout.write(formatObject(result, { format: fmt }) + "\n");
2830
+ process.exitCode = 0;
2831
+ }
2832
2832
  function normalizeMethod(value) {
2833
2833
  const raw = (value ?? "POST").toUpperCase();
2834
2834
  if (raw === "GET" || raw === "POST" || raw === "PUT" || raw === "DELETE") return raw;
@@ -2877,7 +2877,8 @@ async function createCommand(model, args) {
2877
2877
  const fmt = args.output ?? "json";
2878
2878
  if (fmt !== "json") process.stdout.write("\u2705 created\n");
2879
2879
  process.stdout.write(formatObject2(res, { format: fmt }) + "\n");
2880
- process.exit(0);
2880
+ process.exitCode = 0;
2881
+ return;
2881
2882
  } catch (e) {
2882
2883
  const err = e;
2883
2884
  if (err?.isAxiosError) exitWithError(fromAxiosError3(err, args.profile));
@@ -2912,7 +2913,8 @@ async function updateCommand(model, args) {
2912
2913
  if (fmt !== "json") process.stdout.write(`\u2705 ${model}#${args.id} \u5DF2\u66F4\u65B0
2913
2914
  `);
2914
2915
  process.stdout.write(formatObject3(result, { format: fmt }) + "\n");
2915
- process.exit(0);
2916
+ process.exitCode = 0;
2917
+ return;
2916
2918
  } catch (e) {
2917
2919
  const err = e;
2918
2920
  if (err?.isAxiosError) exitWithError(fromAxiosError4(err, args.env));
@@ -2964,7 +2966,8 @@ async function settingGetCommand(domain, args) {
2964
2966
  } else {
2965
2967
  process.stdout.write(formatObject4(items, { format: fmt }) + "\n");
2966
2968
  }
2967
- process.exit(0);
2969
+ process.exitCode = 0;
2970
+ return;
2968
2971
  } catch (e) {
2969
2972
  fail(e, args);
2970
2973
  }
@@ -2989,7 +2992,8 @@ async function settingSetCommand(domain, args) {
2989
2992
  `);
2990
2993
  for (const i of items) process.stdout.write(` ${i.namespace}.${i.settingKey} = ${String(i.value)}
2991
2994
  `);
2992
- process.exit(0);
2995
+ process.exitCode = 0;
2996
+ return;
2993
2997
  }
2994
2998
  const c = await client(args);
2995
2999
  const result = await patchSettingDomain(c.raw(), domain, items);
@@ -2997,7 +3001,8 @@ async function settingSetCommand(domain, args) {
2997
3001
  if (fmt !== "json") process.stdout.write(`\u2705 ${domain} \u5DF2\u66F4\u65B0 ${items.length} \u9879
2998
3002
  `);
2999
3003
  process.stdout.write(formatObject4(result, { format: fmt }) + "\n");
3000
- process.exit(0);
3004
+ process.exitCode = 0;
3005
+ return;
3001
3006
  } catch (e) {
3002
3007
  fail(e, args);
3003
3008
  }
@@ -3018,7 +3023,8 @@ async function settingResetCommand(domain, namespace, key2, args) {
3018
3023
  if (fmt !== "json") process.stdout.write(`\u2705 ${namespace}.${key2} \u5DF2\u56DE\u843D\u5230\u9ED8\u8BA4\u503C
3019
3024
  `);
3020
3025
  process.stdout.write(formatObject4(result, { format: fmt }) + "\n");
3021
- process.exit(0);
3026
+ process.exitCode = 0;
3027
+ return;
3022
3028
  } catch (e) {
3023
3029
  fail(e, args);
3024
3030
  }
@@ -3064,7 +3070,8 @@ async function versionCommand(args) {
3064
3070
  process.stdout.write(
3065
3071
  formatObject5({ cli: CLI_VERSION, backend: info }, { format: fmt }) + "\n"
3066
3072
  );
3067
- process.exit(0);
3073
+ process.exitCode = 0;
3074
+ return;
3068
3075
  } catch (e) {
3069
3076
  const err = e;
3070
3077
  if (err?.isAxiosError) exitWithError(fromAxiosError6(err, args.env));
@@ -3114,7 +3121,8 @@ async function upgradeCommand(args) {
3114
3121
  } else if (latest === CLI_VERSION) {
3115
3122
  lines.push(`\u6700\u65B0\u7248\u672C\uFF1A${latest} \u2014\u2014 \u5DF2\u662F\u6700\u65B0\uFF0C\u65E0\u9700\u5347\u7EA7`);
3116
3123
  process.stdout.write(lines.join("\n") + "\n");
3117
- process.exit(0);
3124
+ process.exitCode = 0;
3125
+ return;
3118
3126
  } else {
3119
3127
  lines.push(`\u6700\u65B0\u7248\u672C\uFF1A${latest}`);
3120
3128
  }
@@ -3127,7 +3135,8 @@ async function upgradeCommand(args) {
3127
3135
  lines.push("");
3128
3136
  lines.push("\u5347\u7EA7\u540E\u7528 `hcm version` \u6838\u5BF9\uFF08\u5B83\u4F1A\u540C\u65F6\u62A5 CLI \u4E0E\u540E\u7AEF\u4E24\u4E2A\u7248\u672C\uFF09\u3002");
3129
3137
  process.stdout.write(lines.join("\n") + "\n");
3130
- process.exit(args.check && latest !== null && latest !== CLI_VERSION ? 1 : 0);
3138
+ process.exitCode = args.check && latest !== null && latest !== CLI_VERSION ? 1 : 0;
3139
+ return;
3131
3140
  }
3132
3141
 
3133
3142
  // src/commands/open.ts
@@ -3166,7 +3175,7 @@ function launchBrowser(url, platform = process.platform) {
3166
3175
  child.unref();
3167
3176
  }
3168
3177
  async function runOpen(target, args, deps) {
3169
- const path13 = normalizeTarget(target);
3178
+ const path14 = normalizeTarget(target);
3170
3179
  if (!deps.frontend?.trim()) {
3171
3180
  throw new CliError12({
3172
3181
  code: CliErrorCode11.INVALID_ARGUMENT,
@@ -3174,13 +3183,13 @@ async function runOpen(target, args, deps) {
3174
3183
  });
3175
3184
  }
3176
3185
  const { ticket, expiresIn } = await deps.mintTicket();
3177
- const url = buildBrowserLoginUrl(deps.frontend, ticket, path13);
3186
+ const url = buildBrowserLoginUrl(deps.frontend, ticket, path14);
3178
3187
  if (args.printUrl) {
3179
3188
  deps.write(`${url}
3180
3189
  `);
3181
3190
  } else {
3182
3191
  deps.launch(url);
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
3192
+ deps.write(`\u5DF2\u7528\u5F53\u524D\u8EAB\u4EFD\u6253\u5F00 ${path14}\uFF08\u7968\u636E ${expiresIn ?? 60}s \u5185\u6709\u6548\uFF0C\u53EA\u80FD\u7528\u4E00\u6B21\uFF09
3184
3193
  `);
3185
3194
  }
3186
3195
  return { url, expiresIn };
@@ -3226,7 +3235,8 @@ async function openCommand(target, args) {
3226
3235
  write: (line) => process.stdout.write(line)
3227
3236
  }
3228
3237
  );
3229
- process.exit(0);
3238
+ process.exitCode = 0;
3239
+ return;
3230
3240
  } catch (e) {
3231
3241
  exitWithError(e);
3232
3242
  }
@@ -3252,7 +3262,8 @@ async function deleteCommand(model, args) {
3252
3262
  const fmt = args.output ?? "json";
3253
3263
  if (fmt !== "json") process.stdout.write("\u2705 deleted\n");
3254
3264
  process.stdout.write(formatObject6(res, { format: fmt }) + "\n");
3255
- process.exit(0);
3265
+ process.exitCode = 0;
3266
+ return;
3256
3267
  } catch (e) {
3257
3268
  const err = e;
3258
3269
  if (err?.isAxiosError) exitWithError(fromAxiosError8(err, args.profile));
@@ -3272,8 +3283,8 @@ import {
3272
3283
  formatObject as formatObject7,
3273
3284
  fromAxiosError as fromAxiosError9
3274
3285
  } from "@hcmai/sdk";
3275
- function collectYmlFiles(path13) {
3276
- if (statSync(path13).isFile()) return [path13];
3286
+ function collectYmlFiles(path14) {
3287
+ if (statSync(path14).isFile()) return [path14];
3277
3288
  const out = [];
3278
3289
  const walk = (dir) => {
3279
3290
  for (const name of readdirSync(dir).sort()) {
@@ -3282,7 +3293,7 @@ function collectYmlFiles(path13) {
3282
3293
  else if (full.endsWith(".yml") || full.endsWith(".yaml")) out.push(full);
3283
3294
  }
3284
3295
  };
3285
- walk(path13);
3296
+ walk(path14);
3286
3297
  return out.sort();
3287
3298
  }
3288
3299
  var DRY_RUN_CLIENT = {
@@ -3290,9 +3301,9 @@ var DRY_RUN_CLIENT = {
3290
3301
  create: async () => ({ id: "" }),
3291
3302
  update: async () => ({})
3292
3303
  };
3293
- async function importCommand(path13, args) {
3304
+ async function importCommand(path14, args) {
3294
3305
  try {
3295
- const files = collectYmlFiles(path13);
3306
+ const files = collectYmlFiles(path14);
3296
3307
  const fixtures = files.map(
3297
3308
  (f) => parseFixture(readFileSync2(f, "utf8"), relative(process.cwd(), f))
3298
3309
  );
@@ -3311,7 +3322,8 @@ async function importCommand(path13, args) {
3311
3322
  `
3312
3323
  );
3313
3324
  process.stdout.write(formatObject7(result, { format: fmt }) + "\n");
3314
- process.exit(result.failed > 0 ? 3 : 0);
3325
+ process.exitCode = result.failed > 0 ? 3 : 0;
3326
+ return;
3315
3327
  } catch (e) {
3316
3328
  const err = e;
3317
3329
  if (err?.isAxiosError) exitWithError(fromAxiosError9(err, args.profile));
@@ -3334,10 +3346,12 @@ async function describeCommand(model, args) {
3334
3346
  const fmt = args.output ?? "table";
3335
3347
  if (fmt !== "table") {
3336
3348
  process.stdout.write(formatObject8(desc, { format: fmt }) + "\n");
3337
- process.exit(0);
3349
+ process.exitCode = 0;
3350
+ return;
3338
3351
  }
3339
3352
  process.stdout.write(formatDescriptionTable(desc, !!args.verbose) + "\n");
3340
- process.exit(0);
3353
+ process.exitCode = 0;
3354
+ return;
3341
3355
  } catch (e) {
3342
3356
  const err = e;
3343
3357
  if (err?.isAxiosError) {
@@ -3354,7 +3368,13 @@ function formatDescriptionTable(desc, verbose = false) {
3354
3368
  for (const f of desc.fields) {
3355
3369
  const req = f.required ? " required" : " ";
3356
3370
  const lbl = verbose ? ` ${f.label ?? ""} ${f.description ?? ""}` : ` ${f.label ?? ""}`;
3357
- lines.push(` ${f.name.padEnd(20)} ${f.type.padEnd(10)} ${req}${lbl}`);
3371
+ const type = f.i18n ? `${f.type} (i18n)` : f.type;
3372
+ lines.push(` ${f.name.padEnd(20)} ${type.padEnd(14)} ${req}${lbl}`);
3373
+ }
3374
+ if (desc.fields.some((f) => f.i18n)) {
3375
+ lines.push(
3376
+ ' \u2139\uFE0F (i18n) = \u591A\u8BED\u8A00\u5B57\u6BB5\uFF0C\u503C\u5F62\u5982 {zh_CN: "\u2026"}\uFF1B\u4E0D\u5E26 --i18n \u65F6\u4F20\u5B57\u7B26\u4E32\u53EA\u6539\u5F53\u524D\u8BED\u8A00\uFF0C\u5E26 --i18n \u5219\u6309 Map \u6574\u4EFD\u66FF\u6362'
3377
+ );
3358
3378
  }
3359
3379
  lines.push(`actions (${desc.actions.length}):`);
3360
3380
  for (const a of desc.actions) {
@@ -3639,7 +3659,8 @@ async function chatCommand(prompt, args) {
3639
3659
  });
3640
3660
  }
3641
3661
  await printConversationList(args);
3642
- process.exit(0);
3662
+ process.exitCode = 0;
3663
+ return;
3643
3664
  }
3644
3665
  const eventsConversationId = resolveEventsConversation(args);
3645
3666
  if (eventsConversationId) {
@@ -3650,7 +3671,8 @@ async function chatCommand(prompt, args) {
3650
3671
  });
3651
3672
  }
3652
3673
  await printConversationEvents(eventsConversationId, args);
3653
- process.exit(0);
3674
+ process.exitCode = 0;
3675
+ return;
3654
3676
  }
3655
3677
  let regenerateFromSeq;
3656
3678
  let regenerateFromLastAssistant = false;
@@ -3850,7 +3872,8 @@ async function chatCommand(prompt, args) {
3850
3872
  resolve4();
3851
3873
  }
3852
3874
  });
3853
- process.exit(0);
3875
+ process.exitCode = 0;
3876
+ return;
3854
3877
  }
3855
3878
  const { resolveInteraction: resolveInteraction2 } = await Promise.resolve().then(() => (init_control_prompt(), control_prompt_exports));
3856
3879
  const { readLineFromStdin: readLineFromStdin2 } = await Promise.resolve().then(() => (init_readline(), readline_exports));
@@ -3921,7 +3944,8 @@ async function chatCommand(prompt, args) {
3921
3944
  resolve4();
3922
3945
  }
3923
3946
  });
3924
- process.exit(result.status === "interrupted" ? 130 : 0);
3947
+ process.exitCode = result.status === "interrupted" ? 130 : 0;
3948
+ return;
3925
3949
  } catch (e) {
3926
3950
  process.removeListener("SIGINT", sigintHandler);
3927
3951
  await ws.close();
@@ -3981,7 +4005,8 @@ async function chatCommand(prompt, args) {
3981
4005
  )
3982
4006
  );
3983
4007
  }
3984
- process.exit(0);
4008
+ process.exitCode = 0;
4009
+ return;
3985
4010
  } catch (e) {
3986
4011
  exitWithError(e);
3987
4012
  }
@@ -3998,7 +4023,8 @@ async function downloadCommand(documentId, args) {
3998
4023
  const client3 = HcmClient12.fromAuthContext(ctx);
3999
4024
  const saved = await downloadDocument(client3.raw(), { documentId }, args.output);
4000
4025
  process.stdout.write(saved + "\n");
4001
- process.exit(0);
4026
+ process.exitCode = 0;
4027
+ return;
4002
4028
  } catch (e) {
4003
4029
  const status = e?.response?.status;
4004
4030
  if (status === 401 || status === 403) {
@@ -4350,10 +4376,12 @@ async function traceCommand(traceId, args) {
4350
4376
  const rows = await fetchLlmTrace(http, convId);
4351
4377
  const fmt = args.raw ? "json" : args.output;
4352
4378
  process.stdout.write(formatObject10(rows, { format: fmt }) + "\n");
4353
- process.exit(0);
4379
+ process.exitCode = 0;
4380
+ return;
4354
4381
  }
4355
4382
  printLlmTraceTree(await gatherLlmTraceTree(http, convId));
4356
- process.exit(0);
4383
+ process.exitCode = 0;
4384
+ return;
4357
4385
  }
4358
4386
  if (!traceId) {
4359
4387
  if (args.events || args.raw || args.span) {
@@ -4361,17 +4389,20 @@ async function traceCommand(traceId, args) {
4361
4389
  return;
4362
4390
  }
4363
4391
  await listRecentTraces(client3, parsePositiveInt2(args.limit, 10, "--limit"));
4364
- process.exit(0);
4392
+ process.exitCode = 0;
4393
+ return;
4365
4394
  }
4366
4395
  const resp = await http.get(`/api/trace/${traceId}`);
4367
4396
  const agg = resp.data ?? {};
4368
4397
  if (args.raw) {
4369
4398
  process.stdout.write(formatObject10(agg, { format: "json" }) + "\n");
4370
- process.exit(0);
4399
+ process.exitCode = 0;
4400
+ return;
4371
4401
  }
4372
4402
  if (args.output === "json" || args.output === "yaml") {
4373
4403
  process.stdout.write(formatObject10(agg, { format: args.output }) + "\n");
4374
- process.exit(0);
4404
+ process.exitCode = 0;
4405
+ return;
4375
4406
  }
4376
4407
  const spans = agg.sources?.tempo?.spans ?? [];
4377
4408
  if (args.span) {
@@ -4381,14 +4412,16 @@ async function traceCommand(traceId, args) {
4381
4412
  return;
4382
4413
  }
4383
4414
  process.stdout.write(formatObject10(spans[idx], { format: "yaml" }) + "\n");
4384
- process.exit(0);
4415
+ process.exitCode = 0;
4416
+ return;
4385
4417
  }
4386
4418
  if (args.events) {
4387
4419
  printTraceEvents(traceId, agg);
4388
4420
  } else {
4389
4421
  printTraceDetail(traceId, agg);
4390
4422
  }
4391
- process.exit(0);
4423
+ process.exitCode = 0;
4424
+ return;
4392
4425
  } catch (e) {
4393
4426
  const err = e;
4394
4427
  if (err?.isAxiosError) {
@@ -4417,7 +4450,8 @@ function emit(result, args, human) {
4417
4450
  const fmt = args.output ?? "json";
4418
4451
  if (fmt !== "json") process.stdout.write(human + "\n");
4419
4452
  process.stdout.write(formatObject11(result, { format: fmt }) + "\n");
4420
- process.exit(0);
4453
+ process.exitCode = 0;
4454
+ return;
4421
4455
  }
4422
4456
  function fail2(e, args) {
4423
4457
  const err = e;
@@ -4475,7 +4509,8 @@ function emit2(result, args, human) {
4475
4509
  const fmt = args.output ?? "json";
4476
4510
  if (fmt !== "json") process.stdout.write(human + "\n");
4477
4511
  process.stdout.write(formatObject12(result, { format: fmt }) + "\n");
4478
- process.exit(0);
4512
+ process.exitCode = 0;
4513
+ return;
4479
4514
  }
4480
4515
  function fail3(e, args) {
4481
4516
  const err = e;
@@ -4592,7 +4627,8 @@ async function uploadCommand(filePath, args) {
4592
4627
  );
4593
4628
  }
4594
4629
  process.stdout.write(formatObject13(meta2, { format: fmt }) + "\n");
4595
- process.exit(0);
4630
+ process.exitCode = 0;
4631
+ return;
4596
4632
  } catch (e) {
4597
4633
  const err = e;
4598
4634
  const status = err?.response?.status;
@@ -4616,13 +4652,23 @@ import {
4616
4652
  formatObject as formatObject14,
4617
4653
  fromAxiosError as fromAxiosError15,
4618
4654
  packDataPackage,
4619
- installDataPackageArtifact,
4655
+ installDataPackageArtifactAsync,
4656
+ waitForInstallRun,
4657
+ fetchInstallRun,
4658
+ isTerminalRunStatus,
4620
4659
  DEFAULT_ARTIFACT_CATEGORY
4621
4660
  } from "@hcmai/sdk";
4661
+ var DEFAULT_INSTALL_WAIT_SECONDS = 900;
4622
4662
  async function datapackagePackCommand(packageDir, args) {
4623
4663
  try {
4624
- const result = await packDataPackage(packageDir, args.out);
4625
4664
  const fmt = args.output ?? "json";
4665
+ const showProgress = fmt !== "json" && process.stderr.isTTY === true;
4666
+ const result = await packDataPackage(packageDir, args.out, {
4667
+ onFile: showProgress ? (rel, i, total) => {
4668
+ process.stderr.write(`\r\u{1F4E6} \u6253\u5305 ${i}/${total} ${truncateTail(rel, 60)}`.padEnd(90));
4669
+ if (i === total) process.stderr.write("\n");
4670
+ } : void 0
4671
+ });
4626
4672
  if (fmt !== "json") {
4627
4673
  process.stdout.write(
4628
4674
  `\u{1F4E6} ${result.name} v${result.version}\uFF08${result.entryCount} \u4E2A\u6587\u4EF6\uFF09\u2192 ${result.artifactPath}
@@ -4630,7 +4676,8 @@ async function datapackagePackCommand(packageDir, args) {
4630
4676
  );
4631
4677
  }
4632
4678
  process.stdout.write(formatObject14(result, { format: fmt }) + "\n");
4633
- process.exit(0);
4679
+ process.exitCode = 0;
4680
+ return;
4634
4681
  } catch (e) {
4635
4682
  exitWithError(e);
4636
4683
  }
@@ -4639,22 +4686,68 @@ async function datapackageInstallCommand(artifactPath, args) {
4639
4686
  try {
4640
4687
  const ctx = await getActiveAuthContextFromCli(args);
4641
4688
  const client3 = HcmClient17.fromAuthContext(ctx);
4642
- const { documentId, view } = await installDataPackageArtifact(client3, artifactPath, {
4689
+ const fmt = args.output ?? "json";
4690
+ const human = fmt !== "json";
4691
+ const accepted = await installDataPackageArtifactAsync(client3, artifactPath, {
4643
4692
  category: args.category ?? DEFAULT_ARTIFACT_CATEGORY
4644
4693
  });
4645
- const fmt = args.output ?? "json";
4646
- if (fmt !== "json") {
4694
+ if (human) {
4647
4695
  process.stdout.write(
4648
- `\u{1F4E5} ${view.code ?? "?"} v${view.version ?? "?"} \u2192 ${view.installStatus ?? "?"}\uFF08rowCount=${view.rowCount ?? 0}\uFF0CdocumentId=${documentId}\uFF09
4696
+ `\u{1F4E5} \u5DF2\u53D7\u7406 ${accepted.packageName ?? "?"} v${accepted.version ?? "?"}\uFF08runId=${accepted.runId}\uFF09
4649
4697
  `
4650
4698
  );
4651
- if (view.replayNotice) {
4652
- process.stdout.write(`\u26A0\uFE0F ${view.replayNotice}
4653
- `);
4699
+ }
4700
+ if (args.wait === false) {
4701
+ emit3({
4702
+ runId: accepted.runId,
4703
+ documentId: accepted.documentId,
4704
+ packageName: accepted.packageName,
4705
+ version: accepted.version,
4706
+ status: "ACCEPTED",
4707
+ next_step: `hcm datapackage status ${accepted.runId}`
4708
+ }, fmt);
4709
+ process.exitCode = 0;
4710
+ return;
4711
+ }
4712
+ const timeoutMs = Math.max(1, Number(args.timeout ?? DEFAULT_INSTALL_WAIT_SECONDS)) * 1e3;
4713
+ const showProgress = human && process.stderr.isTTY === true;
4714
+ const { run, timedOut } = await waitForInstallRun(client3, accepted.runId, {
4715
+ timeoutMs,
4716
+ onProgress: showProgress ? (r) => process.stderr.write(`\r${renderProgress(r)}`.padEnd(96)) : void 0
4717
+ });
4718
+ if (showProgress) process.stderr.write("\n");
4719
+ if (timedOut) {
4720
+ if (human) {
4721
+ process.stdout.write(
4722
+ `\u23F3 \u7B49\u5F85\u8D85\u8FC7 ${Math.round(timeoutMs / 1e3)}s\uFF0C\u88C5\u8F7D\u4ECD\u5728\u670D\u52A1\u7AEF\u7EE7\u7EED\u2014\u2014CLI \u9000\u51FA\u4E0D\u4F1A\u4E2D\u65AD\u5B83\u3002
4723
+ `
4724
+ );
4654
4725
  }
4726
+ emit3({
4727
+ runId: accepted.runId,
4728
+ status: run?.status ?? "RUNNING",
4729
+ phase: run?.phase,
4730
+ filesDone: run?.filesDone,
4731
+ filesTotal: run?.filesTotal,
4732
+ rowsDone: run?.rowsDone,
4733
+ timedOut: true,
4734
+ next_step: `hcm datapackage status ${accepted.runId}`
4735
+ }, fmt);
4736
+ process.exitCode = 0;
4737
+ return;
4738
+ }
4739
+ const failed2 = run?.status !== "SUCCESS";
4740
+ if (human) {
4741
+ process.stdout.write(
4742
+ `${failed2 ? "\u274C" : "\u2705"} ${run?.packageCode ?? accepted.packageName ?? "?"} v${run?.version ?? accepted.version ?? "?"} \u2192 ${run?.status ?? "?"}\uFF08rowCount=${run?.rowCount ?? 0}\uFF0C${Math.round((run?.durationMs ?? 0) / 1e3)}s\uFF09
4743
+ `
4744
+ );
4745
+ if (run?.errorMessage) process.stdout.write(` \u539F\u56E0\uFF1A${run.errorMessage}
4746
+ `);
4655
4747
  }
4656
- process.stdout.write(formatObject14(view, { format: fmt }) + "\n");
4657
- process.exit(0);
4748
+ emit3({ ...run ?? {}, runId: accepted.runId, documentId: accepted.documentId }, fmt);
4749
+ process.exitCode = failed2 ? 1 : 0;
4750
+ return;
4658
4751
  } catch (e) {
4659
4752
  const err = e;
4660
4753
  if (err?.code === "ENOENT") {
@@ -4666,6 +4759,51 @@ async function datapackageInstallCommand(artifactPath, args) {
4666
4759
  }
4667
4760
  }
4668
4761
  }
4762
+ async function datapackageStatusCommand(runId, args) {
4763
+ try {
4764
+ const ctx = await getActiveAuthContextFromCli(args);
4765
+ const client3 = HcmClient17.fromAuthContext(ctx);
4766
+ const run = await fetchInstallRun(client3, runId);
4767
+ const fmt = args.output ?? "json";
4768
+ if (!run) {
4769
+ if (fmt !== "json") {
4770
+ process.stdout.write(`\u23F3 \u6D41\u6C34 ${runId} \u8FD8\u6CA1\u51FA\u73B0\u2014\u2014\u521A\u53D7\u7406\u7684\u88C5\u8F7D\u4F1A\u6709\u51E0\u767E\u6BEB\u79D2\u7684\u7A7A\u7A97\u3002
4771
+ `);
4772
+ }
4773
+ emit3({ runId, status: "PENDING", next_step: `hcm datapackage status ${runId}` }, fmt);
4774
+ process.exitCode = 0;
4775
+ return;
4776
+ }
4777
+ if (fmt !== "json") {
4778
+ process.stdout.write(`${renderProgress(run)}
4779
+ `);
4780
+ if (run.errorMessage) process.stdout.write(` \u539F\u56E0\uFF1A${run.errorMessage}
4781
+ `);
4782
+ }
4783
+ emit3({ ...run, ...isTerminalRunStatus(run.status) ? {} : { next_step: `hcm datapackage status ${runId}` } }, fmt);
4784
+ process.exitCode = 0;
4785
+ return;
4786
+ } catch (e) {
4787
+ const err = e;
4788
+ if (err?.isAxiosError) exitWithError(fromAxiosError15(err, args.env));
4789
+ else exitWithError(e);
4790
+ }
4791
+ }
4792
+ function renderProgress(run) {
4793
+ if (!run) return "\u23F3 \u7B49\u5F85\u88C5\u8F7D\u6D41\u6C34\u51FA\u73B0\u2026";
4794
+ const phase = run.phase ?? run.status ?? "?";
4795
+ const files = run.filesTotal ? `${run.filesDone ?? 0}/${run.filesTotal} \u6587\u4EF6` : `${run.filesDone ?? 0} \u6587\u4EF6`;
4796
+ const rows = run.rowsTotal ? `${run.rowsDone ?? 0}/${run.rowsTotal} \u884C` : `${run.rowsDone ?? 0} \u884C`;
4797
+ const pct = run.rowsTotal ? ` ${Math.min(100, Math.round((run.rowsDone ?? 0) / run.rowsTotal * 100))}%` : "";
4798
+ const file = run.currentFile ? ` ${truncateTail(run.currentFile, 42)}` : "";
4799
+ return `\u23F3 ${phase}${pct} ${files} ${rows}${file}`;
4800
+ }
4801
+ function truncateTail(text, max) {
4802
+ return text.length <= max ? text : "\u2026" + text.slice(text.length - max + 1);
4803
+ }
4804
+ function emit3(payload, fmt) {
4805
+ process.stdout.write(formatObject14(payload, { format: fmt }) + "\n");
4806
+ }
4669
4807
 
4670
4808
  // src/commands/skills.ts
4671
4809
  init_exit();
@@ -5061,10 +5199,12 @@ async function resolveInstallLayout(args, cwd = process.cwd()) {
5061
5199
  const target = requested ?? await detectTarget(cwd) ?? "claude";
5062
5200
  if (target === "codex") {
5063
5201
  const root = args.global ? path4.join(os2.homedir(), ".codex") : cwd;
5202
+ const claudeFile = path4.join(root, "CLAUDE.md");
5064
5203
  return {
5065
5204
  target,
5066
5205
  baseDir: args.dir ? path4.resolve(args.dir) : path4.join(root, "hcm-skills"),
5067
- agentsFile: path4.join(root, "AGENTS.md")
5206
+ agentsFile: path4.join(root, "AGENTS.md"),
5207
+ companionAgentFiles: !args.global && await exists(claudeFile) ? [claudeFile] : []
5068
5208
  };
5069
5209
  }
5070
5210
  return {
@@ -5151,14 +5291,16 @@ async function skillsListCommand(keyword, args) {
5151
5291
  { format: fmt }
5152
5292
  ) + "\n"
5153
5293
  );
5154
- process.exit(0);
5294
+ process.exitCode = 0;
5295
+ return;
5155
5296
  }
5156
5297
  const shown = cats.flatMap((c) => c.skills);
5157
5298
  const total = (manifest2?.skillCount ?? 0) + catalog.cli.entries.size;
5158
5299
  if (shown.length === 0) {
5159
5300
  process.stdout.write(`\u6CA1\u6709\u5339\u914D\u7684\u6280\u80FD\uFF08\u8FD9\u4E00\u8D9F\u770B\u7684\u6765\u6E90\u5171 ${total} \u4E2A\uFF09
5160
5301
  `);
5161
- process.exit(0);
5302
+ process.exitCode = 0;
5303
+ return;
5162
5304
  }
5163
5305
  process.stdout.write(`${manifest2?.title ?? "HCM \u6280\u80FD"} \u2014 ${endpoint ?? `@hcmai/cli@${CLI_VERSION}`}
5164
5306
 
@@ -5193,7 +5335,8 @@ async function skillsListCommand(keyword, args) {
5193
5335
  `);
5194
5336
  process.stdout.write(` \u88C5\u4E00\u4E2A\uFF1Ahcm skills install <id>
5195
5337
  `);
5196
- process.exit(0);
5338
+ process.exitCode = 0;
5339
+ return;
5197
5340
  }
5198
5341
  for (const c of cats) {
5199
5342
  process.stdout.write(` ${c.name}
@@ -5209,7 +5352,8 @@ async function skillsListCommand(keyword, args) {
5209
5352
  `);
5210
5353
  process.stdout.write(` \u88C5\u4E00\u4E2A\uFF1Ahcm skills install <id>
5211
5354
  `);
5212
- process.exit(0);
5355
+ process.exitCode = 0;
5356
+ return;
5213
5357
  } catch (e) {
5214
5358
  fail4(e, args);
5215
5359
  }
@@ -5221,12 +5365,14 @@ async function listInstalledSkills(keyword, args) {
5221
5365
  if (!state || Object.keys(state.skills).length === 0) {
5222
5366
  if (fmt === "json" || fmt === "yaml") {
5223
5367
  process.stdout.write(formatObject16({ baseDir: layout.baseDir, target: layout.target, all: false, skills: [] }, { format: fmt }) + "\n");
5224
- process.exit(0);
5368
+ process.exitCode = 0;
5369
+ return;
5225
5370
  }
5226
5371
  process.stdout.write(`${path4.join(layout.baseDir, SKILLS_STATE_FILE)} \u4E0D\u5B58\u5728\u6216\u4E3A\u7A7A \u2014\u2014 \u8FD9\u4E2A\u76EE\u5F55\u4E0B\u8FD8\u6CA1\u7528\u672C CLI \u88C5\u8FC7\u6280\u80FD\u3002
5227
5372
  `);
5228
5373
  process.stdout.write(" \u88C5\u5168\u90E8\uFF1Ahcm skills install --all\n");
5229
- process.exit(0);
5374
+ process.exitCode = 0;
5375
+ return;
5230
5376
  }
5231
5377
  const rows = [];
5232
5378
  for (const [id, record] of Object.entries(state.skills).sort(([a], [b]) => a.localeCompare(b))) {
@@ -5267,7 +5413,8 @@ async function listInstalledSkills(keyword, args) {
5267
5413
  },
5268
5414
  skills: shown
5269
5415
  }, { format: fmt }) + "\n");
5270
- process.exit(0);
5416
+ process.exitCode = 0;
5417
+ return;
5271
5418
  }
5272
5419
  process.stdout.write(`\u5DF2\u5B89\u88C5\u7684\u6280\u80FD \u2014 ${layout.baseDir}\uFF08${layout.target}\uFF09
5273
5420
  `);
@@ -5275,7 +5422,8 @@ async function listInstalledSkills(keyword, args) {
5275
5422
  if (shown.length === 0) {
5276
5423
  process.stdout.write(` \u6CA1\u6709\u5339\u914D\u300C${keyword}\u300D\u7684\u6280\u80FD\uFF08\u5171\u88C5\u4E86 ${rows.length} \u4E2A\uFF09
5277
5424
  `);
5278
- process.exit(0);
5425
+ process.exitCode = 0;
5426
+ return;
5279
5427
  }
5280
5428
  for (const kind of ["chiron", "cli", "local"]) {
5281
5429
  const group = shown.filter((row) => row.sourceKind === kind);
@@ -5303,7 +5451,8 @@ async function listInstalledSkills(keyword, args) {
5303
5451
  ].filter(Boolean).map((t) => `\uFF0C${t}`).join("") + "\n");
5304
5452
  process.stdout.write(` \u5347\u7EA7\uFF1Ahcm skills update${state.all ? "" : "\uFF08\u60F3\u8DDF\u968F\u5168\u96C6\u52A0 --all\uFF09"}
5305
5453
  `);
5306
- process.exit(0);
5454
+ process.exitCode = 0;
5455
+ return;
5307
5456
  }
5308
5457
  async function skillsShowCommand(id, args) {
5309
5458
  try {
@@ -5312,7 +5461,8 @@ async function skillsShowCommand(id, args) {
5312
5461
  if (source !== "chiron" && listBundledSkills().some((s) => s.id === id)) {
5313
5462
  const document = await readBundledSkillDocument(id);
5314
5463
  process.stdout.write(document.markdown.endsWith("\n") ? document.markdown : document.markdown + "\n");
5315
- process.exit(0);
5464
+ process.exitCode = 0;
5465
+ return;
5316
5466
  }
5317
5467
  if (source === "cli") {
5318
5468
  throw invalid(`\u8FD9\u4E00\u7248 CLI \u6CA1\u6709\u81EA\u5E26 ${id} \u8FD9\u4E2A\u6280\u80FD\uFF08--source cli \u4E0D\u770B\u777F\u620E\u76EE\u5F55\uFF09`);
@@ -5320,7 +5470,8 @@ async function skillsShowCommand(id, args) {
5320
5470
  const { http, base } = await chironClient(args);
5321
5471
  const md = await fetchSkillMarkdown(http, id, base);
5322
5472
  process.stdout.write(md.endsWith("\n") ? md : md + "\n");
5323
- process.exit(0);
5473
+ process.exitCode = 0;
5474
+ return;
5324
5475
  } catch (e) {
5325
5476
  fail4(e, args);
5326
5477
  }
@@ -5449,10 +5600,11 @@ async function skillsInstallCommand(id, args) {
5449
5600
  target: layout.target,
5450
5601
  all
5451
5602
  });
5452
- const agents = layout.agentsFile ? await syncAgentsIndex(layout, manifest2) : void 0;
5603
+ const agentIndexes = layout.agentsFile ? await syncAgentIndexes(layout, manifest2) : [];
5604
+ const agents = agentIndexes[0]?.status;
5453
5605
  const fmt = args.output ?? "table";
5454
5606
  if (fmt === "json" || fmt === "yaml") {
5455
- process.stdout.write(formatObject16({ ...result, all, target_agent: layout.target, agentsFile: layout.agentsFile, agents, conflictCheck: conflictNote ? { checked: false, note: conflictNote } : { checked: true } }, { format: fmt }) + "\n");
5607
+ process.stdout.write(formatObject16({ ...result, all, target_agent: layout.target, agentsFile: layout.agentsFile, agents, agentIndexes, conflictCheck: conflictNote ? { checked: false, note: conflictNote } : { checked: true } }, { format: fmt }) + "\n");
5456
5608
  } else {
5457
5609
  const headline = all ? `\u2705 \u5168\u90E8 ${requestedIds.length} \u4E2A\u6280\u80FD \u2192 ${result.baseDir}` : `\u2705 ${id} \u2192 ${path4.join(result.baseDir, id, "SKILL.md")}`;
5458
5610
  process.stdout.write(`${headline}
@@ -5472,8 +5624,9 @@ async function skillsInstallCommand(id, args) {
5472
5624
  process.stdout.write(` \u53C2\u8003\u6587\u4EF6 ${referenceCount} \u4E2A\uFF08references/ \u4E0B\uFF09
5473
5625
  `);
5474
5626
  }
5475
- if (layout.agentsFile) {
5476
- process.stdout.write(` \u5DF2${agents === "created" ? "\u521B\u5EFA" : "\u66F4\u65B0"} ${layout.agentsFile} \u91CC\u7684\u6280\u80FD\u7D22\u5F15\uFF08Codex \u8BFB\u8FD9\u91CC\uFF09
5627
+ for (const index of agentIndexes) {
5628
+ const reader = path4.basename(index.file) === "CLAUDE.md" ? "Claude Code" : "Codex";
5629
+ process.stdout.write(` \u5DF2${index.status === "created" ? "\u521B\u5EFA" : "\u66F4\u65B0"} ${index.file} \u91CC\u7684\u6280\u80FD\u7D22\u5F15\uFF08${reader} \u8BFB\u8FD9\u91CC\uFF09
5477
5630
  `);
5478
5631
  }
5479
5632
  process.stdout.write(` \u6765\u6E90 ${endpoint ?? (args.from ? path4.resolve(args.from) : `@hcmai/cli@${CLI_VERSION}`)}
@@ -5482,7 +5635,8 @@ async function skillsInstallCommand(id, args) {
5482
5635
  `);
5483
5636
  process.stdout.write(all ? " \u5DF2\u8BB0\u4E3A\u300C\u8DDF\u968F\u5168\u96C6\u300D\uFF1A\u4EE5\u540E\u8DD1 hcm skills update\uFF0C\u4EA7\u54C1\u65B0\u589E\u7684\u6280\u80FD\u4F1A\u81EA\u52A8\u8865\u4E0A\n" : " \u4EA7\u54C1\u66F4\u65B0\u540E\u8DD1 hcm skills update \u5347\u7EA7\n");
5484
5637
  }
5485
- process.exit(0);
5638
+ process.exitCode = 0;
5639
+ return;
5486
5640
  } catch (e) {
5487
5641
  fail4(e, args);
5488
5642
  }
@@ -5530,28 +5684,33 @@ async function fetchSkillDocument(http, skill, endpoint, base) {
5530
5684
  references
5531
5685
  };
5532
5686
  }
5533
- async function syncAgentsIndex(layout, manifest2) {
5534
- if (!layout.agentsFile) return void 0;
5687
+ async function syncAgentIndexes(layout, manifest2) {
5688
+ if (!layout.agentsFile) return [];
5535
5689
  const state = await readSkillsState(layout.baseDir);
5536
- if (!state) return void 0;
5690
+ if (!state) return [];
5537
5691
  const catalog = /* @__PURE__ */ new Map();
5538
5692
  for (const category of manifest2?.categories ?? []) {
5539
5693
  for (const skill of category.skills ?? []) catalog.set(skill.id, skill);
5540
5694
  }
5541
- const agentsDir = path4.dirname(layout.agentsFile);
5542
- const entries = Object.keys(state.skills).sort().map((id) => {
5543
- const known = catalog.get(id);
5544
- const absolute = path4.join(layout.baseDir, id, "SKILL.md");
5545
- let relative2 = path4.relative(agentsDir, absolute);
5546
- if (!relative2.startsWith(".")) relative2 = `./${relative2}`;
5547
- return {
5548
- id,
5549
- title: known?.title ?? id,
5550
- description: known?.description ?? "",
5551
- relativePath: relative2.split(path4.sep).join("/")
5552
- };
5553
- });
5554
- return upsertAgentsBlock(layout.agentsFile, renderAgentsBlock(entries));
5695
+ const files = [layout.agentsFile, ...layout.companionAgentFiles ?? []];
5696
+ const results = [];
5697
+ for (const file of files) {
5698
+ const agentsDir = path4.dirname(file);
5699
+ const entries = Object.keys(state.skills).sort().map((id) => {
5700
+ const known = catalog.get(id);
5701
+ const absolute = path4.join(layout.baseDir, id, "SKILL.md");
5702
+ let relative2 = path4.relative(agentsDir, absolute);
5703
+ if (!relative2.startsWith(".")) relative2 = `./${relative2}`;
5704
+ return {
5705
+ id,
5706
+ title: known?.title ?? id,
5707
+ description: known?.description ?? "",
5708
+ relativePath: relative2.split(path4.sep).join("/")
5709
+ };
5710
+ });
5711
+ results.push({ file, status: await upsertAgentsBlock(file, renderAgentsBlock(entries)) });
5712
+ }
5713
+ return results;
5555
5714
  }
5556
5715
  async function resolveLocalSkillDocuments(sourceRoot, targetId) {
5557
5716
  assertSafeSkillId(targetId);
@@ -6012,8 +6171,8 @@ async function skillsUpdateCommand(args) {
6012
6171
  all,
6013
6172
  directIds: all ? new Set(plan.documents.map((document) => document.id)) : /* @__PURE__ */ new Set()
6014
6173
  });
6015
- if (layout.agentsFile) await syncAgentsIndex(layout, manifest2);
6016
6174
  }
6175
+ if (!args.check && layout.agentsFile) await syncAgentIndexes(layout, manifest2);
6017
6176
  const changed = plan.entries.filter((e) => e.status === "updated" || e.status === "added");
6018
6177
  const fmt = args.output ?? "table";
6019
6178
  if (fmt === "json" || fmt === "yaml") {
@@ -6032,7 +6191,8 @@ async function skillsUpdateCommand(args) {
6032
6191
  staleReferences: stale,
6033
6192
  entries: plan.entries
6034
6193
  }, { format: fmt }) + "\n");
6035
- process.exit(0);
6194
+ process.exitCode = 0;
6195
+ return;
6036
6196
  }
6037
6197
  process.stdout.write(`\u6280\u80FD\u5347\u7EA7 \u2014 ${source === "cli" ? `@hcmai/cli@${CLI_VERSION}\uFF08\u672A\u8FDE\u7F51\uFF09` : endpoint}
6038
6198
  `);
@@ -6086,7 +6246,8 @@ async function skillsUpdateCommand(args) {
6086
6246
  process.stdout.write(` ${[head, tail].filter(Boolean).join("\uFF1B")}
6087
6247
  `);
6088
6248
  }
6089
- process.exit(0);
6249
+ process.exitCode = 0;
6250
+ return;
6090
6251
  } catch (e) {
6091
6252
  fail4(e, args);
6092
6253
  }
@@ -6189,7 +6350,8 @@ async function tenantBootstrapCommand(args) {
6189
6350
  );
6190
6351
  }
6191
6352
  process.stdout.write(formatObject17(result, { format: fmt }) + "\n");
6192
- process.exit(0);
6353
+ process.exitCode = 0;
6354
+ return;
6193
6355
  } catch (e) {
6194
6356
  const err = e;
6195
6357
  if (err?.response?.status === 403) {
@@ -6251,24 +6413,26 @@ async function metaListCommand(args) {
6251
6413
  if (fmt !== "json") process.stdout.write(`\u{1F4C4} ${items.length} \u4EFD${total ? ` / \u5171 ${total}` : ""}
6252
6414
  `);
6253
6415
  process.stdout.write(formatObject18(items, { format: fmt }) + "\n");
6254
- process.exit(0);
6416
+ process.exitCode = 0;
6417
+ return;
6255
6418
  } catch (e) {
6256
6419
  fail5(e, args);
6257
6420
  }
6258
6421
  }
6259
- async function metaGetCommand(path13, args) {
6422
+ async function metaGetCommand(path14, args) {
6260
6423
  try {
6261
6424
  const c = await client2(args);
6262
- const content = await getTenantMeta(c.raw(), path13);
6425
+ const content = await getTenantMeta(c.raw(), path14);
6263
6426
  process.stdout.write(content.endsWith("\n") ? content : content + "\n");
6264
- process.exit(0);
6427
+ process.exitCode = 0;
6428
+ return;
6265
6429
  } catch (e) {
6266
6430
  fail5(e, args);
6267
6431
  }
6268
6432
  }
6269
6433
  var PROBEABLE_META_TYPES = /* @__PURE__ */ new Set(["model", "list", "info", "view", "filter", "page", "wiz", "impexp"]);
6270
- function parseMetaPath(path13) {
6271
- const base = path13.split(/[\\/]/).pop() ?? path13;
6434
+ function parseMetaPath(path14) {
6435
+ const base = path14.split(/[\\/]/).pop() ?? path14;
6272
6436
  if (!/\.(yml|yaml)$/i.test(base)) return {};
6273
6437
  const parts = base.replace(/\.(yml|yaml)$/i, "").split(".");
6274
6438
  return { model: parts[0] || void 0, kind: parts[1] ?? "model", state: parts[2] };
@@ -6285,10 +6449,10 @@ function unverifiableReason(e) {
6285
6449
  if (st == null) return `\u8BF7\u6C42\u6CA1\u53D1\u51FA\u53BB\u6216\u6CA1\u56DE\u6765\uFF08${err.code ?? err.message ?? "\u672A\u77E5"}\uFF09`;
6286
6450
  return void 0;
6287
6451
  }
6288
- async function verifyAfterWrite(c, path13) {
6289
- const { model, kind, state } = parseMetaPath(path13);
6452
+ async function verifyAfterWrite(c, path14) {
6453
+ const { model, kind, state } = parseMetaPath(path14);
6290
6454
  if (!model || !kind) {
6291
- return { status: "unverified", where: "(\u672A\u63A2)", why: `\u4ECE\u8DEF\u5F84 ${path13} \u8BA4\u4E0D\u51FA\u6A21\u578B\u540D/\u5C42\u540D` };
6455
+ return { status: "unverified", where: "(\u672A\u63A2)", why: `\u4ECE\u8DEF\u5F84 ${path14} \u8BA4\u4E0D\u51FA\u6A21\u578B\u540D/\u5C42\u540D` };
6292
6456
  }
6293
6457
  try {
6294
6458
  await clearMetaCache2(c.raw(), model, {});
@@ -6333,7 +6497,7 @@ async function verifyAfterWrite(c, path13) {
6333
6497
  }
6334
6498
  return { status: "ok" };
6335
6499
  }
6336
- async function metaSetCommand(path13, args) {
6500
+ async function metaSetCommand(path14, args) {
6337
6501
  try {
6338
6502
  if (!args.file) {
6339
6503
  throw new CliError19({
@@ -6349,9 +6513,9 @@ async function metaSetCommand(path13, args) {
6349
6513
  process.stdin.on("error", reject);
6350
6514
  }) : await fsp3.readFile(args.file, "utf8");
6351
6515
  if (!args.skipValidate) {
6352
- const result2 = validateMetaContent(path13, content);
6516
+ const result2 = validateMetaContent(path14, content);
6353
6517
  if (result2.issues.length > 0) {
6354
- process.stderr.write(`\u{1F50E} \u5199\u524D\u6821\u9A8C ${path13}\uFF08schema \u7C7B\u578B\uFF1A${result2.kind ?? "\u672A\u8BC6\u522B"}\uFF09
6518
+ process.stderr.write(`\u{1F50E} \u5199\u524D\u6821\u9A8C ${path14}\uFF08schema \u7C7B\u578B\uFF1A${result2.kind ?? "\u672A\u8BC6\u522B"}\uFF09
6355
6519
  `);
6356
6520
  process.stderr.write(formatMetaIssues(result2, " ") + "\n");
6357
6521
  }
@@ -6370,32 +6534,33 @@ async function metaSetCommand(path13, args) {
6370
6534
  if (dryFmt === "json" || dryFmt === "yaml") {
6371
6535
  process.stdout.write(
6372
6536
  formatObject18(
6373
- { dryRun: true, path: path13, bytes: Buffer.byteLength(content), content },
6537
+ { dryRun: true, path: path14, bytes: Buffer.byteLength(content), content },
6374
6538
  { format: dryFmt }
6375
6539
  ) + "\n"
6376
6540
  );
6377
6541
  } else {
6378
6542
  process.stdout.write(
6379
- `[dry-run] \u5C06\u5199\u5165 ${path13}\uFF08${Buffer.byteLength(content)} B\uFF09\u2014\u2014\u672A\u5B9E\u9645\u5199\u5165
6543
+ `[dry-run] \u5C06\u5199\u5165 ${path14}\uFF08${Buffer.byteLength(content)} B\uFF09\u2014\u2014\u672A\u5B9E\u9645\u5199\u5165
6380
6544
  ---
6381
6545
  ${content}
6382
6546
  `
6383
6547
  );
6384
6548
  }
6385
- process.exit(0);
6549
+ process.exitCode = 0;
6550
+ return;
6386
6551
  }
6387
6552
  const c = await client2(args);
6388
6553
  let backupFile;
6389
6554
  let backupState = "unknown";
6390
6555
  let backupWhy;
6391
6556
  try {
6392
- const prev = await getTenantMeta(c.raw(), path13);
6557
+ const prev = await getTenantMeta(c.raw(), path14);
6393
6558
  if (!prev || prev.trim() === "") {
6394
6559
  backupState = "absent";
6395
6560
  } else {
6396
6561
  backupFile = nodePath.join(
6397
6562
  os3.tmpdir(),
6398
- `hcm-meta-backup-${Date.now()}-${path13.replace(/[\\/]/g, "_")}`
6563
+ `hcm-meta-backup-${Date.now()}-${path14.replace(/[\\/]/g, "_")}`
6399
6564
  );
6400
6565
  await fsp3.writeFile(backupFile, prev, "utf8");
6401
6566
  backupState = "saved";
@@ -6410,22 +6575,22 @@ ${content}
6410
6575
  backupWhy = `HTTP ${st ?? "-"}${err.code ? ` ${err.code}` : ""}${err.message ? `\uFF1A${err.message}` : ""}`;
6411
6576
  }
6412
6577
  }
6413
- const result = await saveTenantMeta(c.raw(), path13, content);
6578
+ const result = await saveTenantMeta(c.raw(), path14, content);
6414
6579
  const fmt = args.output ?? "json";
6415
- if (fmt !== "json") process.stdout.write(`\u2705 \u5DF2\u5199\u5165 ${path13}
6580
+ if (fmt !== "json") process.stdout.write(`\u2705 \u5DF2\u5199\u5165 ${path14}
6416
6581
  `);
6417
6582
  const restoreHint = backupState === "saved" && backupFile ? ` \u65E7\u5185\u5BB9\u5DF2\u5B58\uFF1A${backupFile}
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)}
6583
+ \u653E\u56DE\u53BB\uFF1Ahcm meta set ${path14} --file ${backupFile}${connFlags(args)}
6584
+ ` : backupState === "absent" ? ` \u8FD9\u4E00\u5C42\u6B64\u524D\u6CA1\u6709\u8986\u76D6\uFF08\u5DF2\u8BC1\u5B9E\uFF09\uFF0C\u6062\u590D\u5373\u5220\u9664\uFF1Ahcm meta delete ${path14}${connFlags(args)}
6420
6585
  ` : ` \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
6421
- \u5148\u81EA\u5DF1\u8BFB\u4E00\u904D\u786E\u8BA4\uFF1Ahcm meta get ${path13}${connFlags(args)}
6586
+ \u5148\u81EA\u5DF1\u8BFB\u4E00\u904D\u786E\u8BA4\uFF1Ahcm meta get ${path14}${connFlags(args)}
6422
6587
  `;
6423
6588
  if (args.verify === false) {
6424
6589
  process.stderr.write(
6425
6590
  "\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
6426
6591
  );
6427
6592
  } else {
6428
- const outcome = await verifyAfterWrite(c, path13);
6593
+ const outcome = await verifyAfterWrite(c, path14);
6429
6594
  if (outcome.status === "broken") {
6430
6595
  const human = explainJacksonError(outcome.raw);
6431
6596
  process.stderr.write(
@@ -6451,33 +6616,35 @@ ${content}
6451
6616
  }
6452
6617
  }
6453
6618
  process.stdout.write(formatObject18(result, { format: fmt }) + "\n");
6454
- process.exit(0);
6619
+ process.exitCode = 0;
6620
+ return;
6455
6621
  } catch (e) {
6456
6622
  if (e.code === "ENOENT") exitWithError(new Error(`\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${args.file}`));
6457
6623
  fail5(e, args);
6458
6624
  }
6459
6625
  }
6460
- async function metaDeleteCommand(path13, args) {
6626
+ async function metaDeleteCommand(path14, args) {
6461
6627
  try {
6462
6628
  if (!args.yes) {
6463
- const ok = await promptConfirm(`\u5C06\u5220\u9664\u5143\u6570\u636E ${path13}\uFF0C\u6B64\u64CD\u4F5C\u4E0D\u53EF\u9006\u3002\u7EE7\u7EED\uFF1F`);
6629
+ const ok = await promptConfirm(`\u5C06\u5220\u9664\u5143\u6570\u636E ${path14}\uFF0C\u6B64\u64CD\u4F5C\u4E0D\u53EF\u9006\u3002\u7EE7\u7EED\uFF1F`);
6464
6630
  if (!ok) {
6465
6631
  process.stderr.write("\u5DF2\u53D6\u6D88\n");
6466
6632
  process.exit(1);
6467
6633
  }
6468
6634
  }
6469
6635
  const c = await client2(args);
6470
- const result = await deleteTenantMeta(c.raw(), path13);
6636
+ const result = await deleteTenantMeta(c.raw(), path14);
6471
6637
  const fmt = args.output ?? "json";
6472
- if (fmt !== "json") process.stdout.write(`\u{1F5D1}\uFE0F \u5DF2\u5220\u9664 ${path13}
6638
+ if (fmt !== "json") process.stdout.write(`\u{1F5D1}\uFE0F \u5DF2\u5220\u9664 ${path14}
6473
6639
  `);
6474
6640
  process.stdout.write(formatObject18(result, { format: fmt }) + "\n");
6475
- process.exit(0);
6641
+ process.exitCode = 0;
6642
+ return;
6476
6643
  } catch (e) {
6477
6644
  fail5(e, args);
6478
6645
  }
6479
6646
  }
6480
- async function metaValidateCommand(path13, args) {
6647
+ async function metaValidateCommand(path14, args) {
6481
6648
  try {
6482
6649
  if (!args.file) {
6483
6650
  throw new CliError19({
@@ -6492,13 +6659,13 @@ async function metaValidateCommand(path13, args) {
6492
6659
  process.stdin.on("end", () => resolve4(buf));
6493
6660
  process.stdin.on("error", reject);
6494
6661
  }) : await fsp3.readFile(args.file, "utf8");
6495
- const result = validateMetaContent(path13, content);
6662
+ const result = validateMetaContent(path14, content);
6496
6663
  const fmt = args.output ?? "table";
6497
6664
  if (fmt === "json" || fmt === "yaml") {
6498
6665
  process.stdout.write(
6499
6666
  formatObject18(
6500
6667
  {
6501
- path: path13,
6668
+ path: path14,
6502
6669
  kind: result.kind,
6503
6670
  schemaKnown: result.schemaKnown,
6504
6671
  schemaSourceCommit: META_SCHEMA_SOURCE_COMMIT,
@@ -6510,14 +6677,15 @@ async function metaValidateCommand(path13, args) {
6510
6677
  );
6511
6678
  } else {
6512
6679
  process.stdout.write(
6513
- `\u{1F50E} ${path13}\uFF08schema \u7C7B\u578B\uFF1A${result.kind ?? "\u672A\u8BC6\u522B"}\uFF0C\u6765\u6E90 ${META_SCHEMA_SOURCE_COMMIT.slice(0, 8)}\uFF09
6680
+ `\u{1F50E} ${path14}\uFF08schema \u7C7B\u578B\uFF1A${result.kind ?? "\u672A\u8BC6\u522B"}\uFF0C\u6765\u6E90 ${META_SCHEMA_SOURCE_COMMIT.slice(0, 8)}\uFF09
6514
6681
  `
6515
6682
  );
6516
6683
  process.stdout.write(
6517
6684
  result.issues.length === 0 ? " \u6CA1\u6709\u53D1\u73B0\u95EE\u9898\u3002\n" : formatMetaIssues(result, " ") + "\n"
6518
6685
  );
6519
6686
  }
6520
- process.exit(result.errors.length > 0 ? 1 : 0);
6687
+ process.exitCode = result.errors.length > 0 ? 1 : 0;
6688
+ return;
6521
6689
  } catch (e) {
6522
6690
  if (e.code === "ENOENT") exitWithError(new Error(`\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${args.file}`));
6523
6691
  fail5(e, args);
@@ -6613,7 +6781,8 @@ async function workspaceListCommand(args) {
6613
6781
  limit
6614
6782
  });
6615
6783
  writeWorkspaceListResult(result.rows, args.output ?? "table", result.total);
6616
- process.exit(0);
6784
+ process.exitCode = 0;
6785
+ return;
6617
6786
  } catch (e) {
6618
6787
  exitWorkspaceError(e, args.env ?? args.profile);
6619
6788
  }
@@ -6642,7 +6811,8 @@ async function workspaceActiveCommand(args) {
6642
6811
  rootDir
6643
6812
  };
6644
6813
  writeWorkspaceActiveResult(view, args.output ?? "table");
6645
- process.exit(0);
6814
+ process.exitCode = 0;
6815
+ return;
6646
6816
  } catch (e) {
6647
6817
  exitWorkspaceError(e, args.env ?? args.profile);
6648
6818
  }
@@ -6666,7 +6836,8 @@ async function workspaceBindCommand(workspaceKey, args) {
6666
6836
  await fs5.mkdir(rootDir, { recursive: true });
6667
6837
  await writeWorkspaceContext(rootDir, context);
6668
6838
  writeWorkspaceBindResult(context, rootDir, args.output ?? "table");
6669
- process.exit(0);
6839
+ process.exitCode = 0;
6840
+ return;
6670
6841
  } catch (e) {
6671
6842
  exitWorkspaceError(e, args.env ?? args.profile);
6672
6843
  }
@@ -6712,7 +6883,8 @@ async function workspaceCreateCommand(workspaceKey, args) {
6712
6883
  },
6713
6884
  args.output ?? "table"
6714
6885
  );
6715
- process.exit(0);
6886
+ process.exitCode = 0;
6887
+ return;
6716
6888
  } catch (e) {
6717
6889
  exitWorkspaceError(e, args.env ?? args.profile);
6718
6890
  }
@@ -6785,7 +6957,8 @@ async function workspacePullCommand(args) {
6785
6957
  },
6786
6958
  args.output ?? "table"
6787
6959
  );
6788
- process.exit(0);
6960
+ process.exitCode = 0;
6961
+ return;
6789
6962
  } catch (e) {
6790
6963
  exitWorkspaceError(e, args.env ?? args.profile);
6791
6964
  }
@@ -6826,7 +6999,8 @@ async function workspaceAddMiniCommand(appCode, args) {
6826
6999
  force: !!args.force
6827
7000
  });
6828
7001
  writeWorkspaceAddMiniResult(result, rootDir, args.output ?? "table");
6829
- process.exit(0);
7002
+ process.exitCode = 0;
7003
+ return;
6830
7004
  } catch (e) {
6831
7005
  exitWorkspaceError(e, args.env ?? args.profile);
6832
7006
  }
@@ -6870,7 +7044,8 @@ async function workspaceStatusCommand(args) {
6870
7044
  } else {
6871
7045
  process.stdout.write(formatRows5(rows, { format: "table" }) + "\n");
6872
7046
  }
6873
- process.exit(0);
7047
+ process.exitCode = 0;
7048
+ return;
6874
7049
  } catch (e) {
6875
7050
  exitWorkspaceError(e);
6876
7051
  }
@@ -6884,7 +7059,8 @@ async function workspaceValidateCommand(args) {
6884
7059
  miniApps.map(async (app) => ({ app, result: await validateMiniProject(app.dir) }))
6885
7060
  );
6886
7061
  writeWorkspaceValidateResult(results, args.output ?? "table");
6887
- process.exit(results.every((item) => item.result.valid) ? 0 : 1);
7062
+ process.exitCode = results.every((item) => item.result.valid) ? 0 : 1;
7063
+ return;
6888
7064
  } catch (e) {
6889
7065
  exitWorkspaceError(e);
6890
7066
  }
@@ -6941,9 +7117,8 @@ async function workspacePushCommand(args) {
6941
7117
  if (hint) process.stderr.write(`
6942
7118
  ${hint}
6943
7119
  `);
6944
- process.exit(
6945
- rawResult.conflicts.length || results.some((item) => item.result.conflicts.length) ? 3 : 0
6946
- );
7120
+ process.exitCode = rawResult.conflicts.length || results.some((item) => item.result.conflicts.length) ? 3 : 0;
7121
+ return;
6947
7122
  } catch (e) {
6948
7123
  exitWorkspaceError(e, args.env ?? args.profile);
6949
7124
  }
@@ -6973,7 +7148,8 @@ async function workspacePreviewCommand(args) {
6973
7148
  } else {
6974
7149
  process.stdout.write(formatRows5(rows, { format: "table" }) + "\n");
6975
7150
  }
6976
- process.exit(0);
7151
+ process.exitCode = 0;
7152
+ return;
6977
7153
  } catch (e) {
6978
7154
  exitWorkspaceError(e);
6979
7155
  }
@@ -7064,7 +7240,8 @@ async function workspaceVerifyCommand(args) {
7064
7240
  args.output ?? "table"
7065
7241
  );
7066
7242
  const rawOk = !!rawPlan && rawPlan.conflicts.length === 0;
7067
- process.exit(rawOk && reports.every((item) => item.report.ok) ? 0 : 1);
7243
+ process.exitCode = rawOk && reports.every((item) => item.report.ok) ? 0 : 1;
7244
+ return;
7068
7245
  } catch (e) {
7069
7246
  exitWorkspaceError(e, args.env ?? args.profile);
7070
7247
  }
@@ -7879,7 +8056,8 @@ async function workspaceActivateCommand(workspaceKey, args) {
7879
8056
  formatObject19({ workspaceKey: key2, activated: true }, { format: fmt }) + "\n"
7880
8057
  );
7881
8058
  }
7882
- process.exit(0);
8059
+ process.exitCode = 0;
8060
+ return;
7883
8061
  } catch (e) {
7884
8062
  exitWorkspaceError(e, args.env ?? args.profile);
7885
8063
  }
@@ -7887,7 +8065,13 @@ async function workspaceActivateCommand(workspaceKey, args) {
7887
8065
 
7888
8066
  // src/commands/identity.ts
7889
8067
  init_exit();
8068
+ import axios4 from "axios";
7890
8069
  import {
8070
+ AUTH_INFO_PATH,
8071
+ CliError as CliError20,
8072
+ CliErrorCode as CliErrorCode19,
8073
+ formatObject as formatObject20,
8074
+ fromAxiosError as fromAxiosError20,
7891
8075
  loadEnv as loadEnv8,
7892
8076
  saveEnv as saveEnv3,
7893
8077
  loadIdentity as loadIdentity4,
@@ -7895,17 +8079,60 @@ import {
7895
8079
  deleteIdentity as deleteIdentity2,
7896
8080
  loadGlobalConfig as loadGlobalConfig8,
7897
8081
  TokenStore as TokenStore3,
7898
- CliError as CliError20,
7899
- CliErrorCode as CliErrorCode19
8082
+ toPrincipal
7900
8083
  } from "@hcmai/sdk";
8084
+ var fetchAuthInfo = async (endpoint, accessToken) => {
8085
+ const response = await axios4.get(`${endpoint.replace(/\/$/, "")}${AUTH_INFO_PATH}`, {
8086
+ headers: { Authorization: `Bearer ${accessToken}` },
8087
+ timeout: 3e4
8088
+ });
8089
+ return response.data;
8090
+ };
8091
+ async function inspectIdentity(name, fetcher = fetchAuthInfo) {
8092
+ const meta2 = await loadIdentity4(name);
8093
+ const env2 = await loadEnv8(meta2.env);
8094
+ const accessToken = await TokenStore3.forIdentity(name).getStoredAccessToken();
8095
+ if (!accessToken) {
8096
+ throw new CliError20({
8097
+ code: CliErrorCode19.AUTH_FAILED,
8098
+ message: `identity '${name}' \u6CA1\u6709\u53EF\u8BFB\u53D6\u7684\u6301\u4E45\u5316 token`,
8099
+ context: { nextStep: `\u91CD\u65B0\u767B\u5F55\u8BE5\u8EAB\u4EFD\uFF1Ahcm login --env ${meta2.env} --name ${name}` }
8100
+ });
8101
+ }
8102
+ const raw = await fetcher(env2.endpoint, accessToken);
8103
+ const principal = toPrincipal(raw);
8104
+ const body = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
8105
+ const serverScopes = Array.isArray(body.scopes) ? body.scopes.map(String) : void 0;
8106
+ return {
8107
+ identity: name,
8108
+ env: meta2.env,
8109
+ endpoint: env2.endpoint,
8110
+ scheme: meta2.scheme,
8111
+ userId: principal?.userId ?? null,
8112
+ username: principal?.username ?? null,
8113
+ tenantId: principal?.tenantId ?? null,
8114
+ // null 明确表示服务端没回该字段;[] 才表示服务端确认角色为空。
8115
+ roles: principal?.roles ?? null,
8116
+ scopes: serverScopes ?? meta2.scopes,
8117
+ expiresAt: meta2.expiresAt ?? null,
8118
+ source: AUTH_INFO_PATH
8119
+ };
8120
+ }
8121
+ async function identityShow(name, args) {
8122
+ try {
8123
+ const details = await inspectIdentity(name);
8124
+ return exitOk(formatObject20(details, { format: args.output ?? "json" }));
8125
+ } catch (e) {
8126
+ exitWithError(axios4.isAxiosError(e) ? fromAxiosError20(e, name) : e);
8127
+ }
8128
+ }
7901
8129
  async function identityList(args) {
7902
8130
  try {
7903
8131
  const g = await loadGlobalConfig8();
7904
8132
  const filter = args.env === "all" ? void 0 : args.env ?? g.activeEnv;
7905
8133
  const names = await listIdentities2(filter);
7906
8134
  if (names.length === 0) {
7907
- exitOk("(no identities)");
7908
- return;
8135
+ return exitOk("(no identities)");
7909
8136
  }
7910
8137
  const lines = [];
7911
8138
  for (const n of names) {
@@ -7915,7 +8142,7 @@ async function identityList(args) {
7915
8142
  const expired = meta2.expiresAt && new Date(meta2.expiresAt) < /* @__PURE__ */ new Date() ? " (expired)" : "";
7916
8143
  lines.push(`${isDefault} ${n} scheme=${meta2.scheme} env=${meta2.env}${expired}`);
7917
8144
  }
7918
- exitOk(lines.join("\n"));
8145
+ return exitOk(lines.join("\n"));
7919
8146
  } catch (e) {
7920
8147
  exitWithError(e);
7921
8148
  }
@@ -7931,7 +8158,7 @@ async function identityUse(name) {
7931
8158
  });
7932
8159
  env2.defaultIdentity = name;
7933
8160
  await saveEnv3(meta2.env, env2);
7934
- exitOk(`\u2705 default identity for env '${meta2.env}': ${name}`);
8161
+ return exitOk(`\u2705 default identity for env '${meta2.env}': ${name}`);
7935
8162
  } catch (e) {
7936
8163
  exitWithError(e);
7937
8164
  }
@@ -7953,7 +8180,7 @@ async function identityRemove(name) {
7953
8180
  env2.defaultIdentity = void 0;
7954
8181
  await saveEnv3(meta2.env, env2);
7955
8182
  }
7956
- exitOk(`\u2705 identity '${name}' removed`);
8183
+ return exitOk(`\u2705 identity '${name}' removed`);
7957
8184
  } catch (e) {
7958
8185
  exitWithError(e);
7959
8186
  }
@@ -7966,7 +8193,7 @@ import { join as pathJoin } from "path";
7966
8193
  import {
7967
8194
  HcmClient as HcmClient20,
7968
8195
  classifyEffect,
7969
- formatObject as formatObject20
8196
+ formatObject as formatObject21
7970
8197
  } from "@hcmai/sdk";
7971
8198
 
7972
8199
  // src/commands/delivery.ts
@@ -8594,7 +8821,7 @@ function withProjectReadiness(assessment, projectRoot = ".") {
8594
8821
  deliveryMode,
8595
8822
  requirements: requirements2,
8596
8823
  modePolicy: assessment.modePolicy ? { ...assessment.modePolicy, controlled: "deny" } : assessment.modePolicy,
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>"
8824
+ 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 --approved-by '<\u9879\u76EE\u8D1F\u8D23\u4EBA>' --reason '<\u672C\u6B21\u5BF9\u8BDD\u6216\u4EFB\u52A1\u4E66\u4E2D\u7684\u660E\u786E\u6388\u6743\u4F9D\u636E>'\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>"
8598
8825
  };
8599
8826
  }
8600
8827
  if (projectInitialized || !assessment.guardedExecutionAvailable) {
@@ -8613,7 +8840,7 @@ function withProjectReadiness(assessment, projectRoot = ".") {
8613
8840
  async function deliveryAssessCommand(argv, args) {
8614
8841
  const assessment = await assessEffectiveDeliveryCommand(argv);
8615
8842
  const enriched = withProjectReadiness(assessment);
8616
- process.stdout.write(formatObject20(enriched, { format: args.output ?? "json" }) + "\n");
8843
+ process.stdout.write(formatObject21(enriched, { format: args.output ?? "json" }) + "\n");
8617
8844
  }
8618
8845
  async function resolveCoreAction(request) {
8619
8846
  try {
@@ -8722,10 +8949,10 @@ function flagValue2(argv, flag) {
8722
8949
 
8723
8950
  // src/commands/delivery-init.ts
8724
8951
  init_exit();
8725
- import { promises as fs7 } from "fs";
8726
- import path7 from "path";
8952
+ import { promises as fs8 } from "fs";
8953
+ import path8 from "path";
8727
8954
  import {
8728
- formatObject as formatObject21,
8955
+ formatObject as formatObject22,
8729
8956
  loadEnv as loadEnv9,
8730
8957
  loadGlobalConfig as loadGlobalConfig9,
8731
8958
  resolveActiveEnv as resolveActiveEnv5
@@ -8734,6 +8961,157 @@ import {
8734
8961
  // src/commands/delivery-project-scaffold.ts
8735
8962
  import { promises as fs6 } from "fs";
8736
8963
  import path6 from "path";
8964
+
8965
+ // src/commands/delivery-page-acceptance.ts
8966
+ function renderPageAcceptanceSh() {
8967
+ return [
8968
+ "#!/usr/bin/env bash",
8969
+ "set -euo pipefail",
8970
+ "",
8971
+ "usage() {",
8972
+ " cat >&2 <<'USAGE'",
8973
+ "\u7528\u6CD5\uFF1A",
8974
+ " ./page-acceptance.sh --env <\u73AF\u5883> [--as <\u8EAB\u4EFD>] --path </\u7AD9\u5185\u8DEF\u5F84> \\",
8975
+ " --expect-text <\u9875\u9762\u5FC5\u987B\u51FA\u73B0\u7684\u6587\u672C> [--expect-text <\u6587\u672C> ...] \\",
8976
+ " --out <\u8BC1\u636E/.../\u622A\u56FE.png> [--reject-text <\u4E0D\u5F97\u51FA\u73B0\u7684\u6587\u672C>] \\",
8977
+ " [--wait-ms 10000] [--size 1440x900]",
8978
+ "",
8979
+ "\u8BF4\u660E\uFF1A",
8980
+ " - \u8C03\u7528 hcm open \u94F8\u4E00\u6B21\u6027\u767B\u5F55\u7968\u636E\uFF0C\u5E76\u7ACB\u5373\u4EA4\u7ED9\u672C\u673A Chrome/Chromium\u3002",
8981
+ " - \u622A\u56FE\u53EA\u80FD\u5199\u5165\u9879\u76EE\u7684 \u8BC1\u636E/ \u76EE\u5F55\uFF1B\u5DF2\u6709\u6587\u4EF6\u4E0D\u4F1A\u88AB\u8986\u76D6\u3002",
8982
+ " - \u81F3\u5C11\u4E00\u4E2A --expect-text \u662F\u5FC5\u586B\u9879\uFF0C\u9632\u6B62\u628A\u767B\u5F55\u9875\u6216\u9519\u8BEF\u9875\u8BEF\u8BB0\u6210\u901A\u8FC7\u3002",
8983
+ " - \u6D4F\u89C8\u5668\u672A\u5728 PATH \u65F6\uFF0C\u7528 HCM_CHROME_BIN=/\u7EDD\u5BF9\u8DEF\u5F84 \u6307\u5B9A\u3002",
8984
+ "USAGE",
8985
+ "}",
8986
+ "",
8987
+ "fail() {",
8988
+ ` printf '\u9875\u9762\u9A8C\u6536\u5931\u8D25\uFF1A%s\\n' "$1" >&2`,
8989
+ ' exit "${2:-1}"',
8990
+ "}",
8991
+ "",
8992
+ "need_value() {",
8993
+ ' if (( $# < 2 )) || [[ -z "$2" ]]; then fail "$1 \u7F3A\u5C11\u503C" 2; fi',
8994
+ "}",
8995
+ "",
8996
+ 'environment=""',
8997
+ 'identity=""',
8998
+ 'page_path=""',
8999
+ 'output=""',
9000
+ 'wait_ms="10000"',
9001
+ 'size="1440x900"',
9002
+ "expected_texts=()",
9003
+ "rejected_texts=()",
9004
+ "",
9005
+ "while (( $# > 0 )); do",
9006
+ ' case "$1" in',
9007
+ ' --env) need_value "$@"; environment="$2"; shift 2 ;;',
9008
+ ' --as) need_value "$@"; identity="$2"; shift 2 ;;',
9009
+ ' --path) need_value "$@"; page_path="$2"; shift 2 ;;',
9010
+ ' --out) need_value "$@"; output="$2"; shift 2 ;;',
9011
+ ' --expect-text) need_value "$@"; expected_texts+=("$2"); shift 2 ;;',
9012
+ ' --reject-text) need_value "$@"; rejected_texts+=("$2"); shift 2 ;;',
9013
+ ' --wait-ms) need_value "$@"; wait_ms="$2"; shift 2 ;;',
9014
+ ' --size) need_value "$@"; size="$2"; shift 2 ;;',
9015
+ " -h|--help) usage; exit 0 ;;",
9016
+ ' *) fail "\u672A\u77E5\u53C2\u6570\uFF1A$1" 2 ;;',
9017
+ " esac",
9018
+ "done",
9019
+ "",
9020
+ '[[ -n "$environment" ]] || fail "\u5FC5\u987B\u663E\u5F0F\u4F20 --env" 2',
9021
+ '[[ -n "$page_path" ]] || fail "\u5FC5\u987B\u4F20 --path" 2',
9022
+ '[[ "$page_path" == /* ]] || fail "--path \u53EA\u63A5\u53D7\u4EE5 / \u5F00\u5934\u7684\u7AD9\u5185\u8DEF\u5F84" 2',
9023
+ '[[ -n "$output" ]] || fail "\u5FC5\u987B\u4F20 --out" 2',
9024
+ '[[ "$output" == *.png ]] || fail "--out \u5FC5\u987B\u4EE5 .png \u7ED3\u5C3E" 2',
9025
+ '(( ${#expected_texts[@]} > 0 )) || fail "\u81F3\u5C11\u4F20\u4E00\u4E2A --expect-text" 2',
9026
+ '[[ "$wait_ms" =~ ^[0-9]+$ ]] || fail "--wait-ms \u5FC5\u987B\u662F\u6574\u6570" 2',
9027
+ '(( wait_ms >= 0 && wait_ms <= 60000 )) || fail "--wait-ms \u5FC5\u987B\u5728 0..60000" 2',
9028
+ 'if [[ "$size" =~ ^([0-9]+)x([0-9]+)$ ]]; then',
9029
+ ' width="${BASH_REMATCH[1]}"',
9030
+ ' height="${BASH_REMATCH[2]}"',
9031
+ "else",
9032
+ ' fail "--size \u5FC5\u987B\u662F <\u5BBD>x<\u9AD8>\uFF0C\u4F8B\u5982 1440x900" 2',
9033
+ "fi",
9034
+ '(( width >= 320 && width <= 7680 && height >= 240 && height <= 7680 )) || fail "--size \u8D85\u51FA\u5141\u8BB8\u8303\u56F4\uFF08\u5BBD 320..7680\uFF0C\u9AD8 240..7680\uFF09" 2',
9035
+ "",
9036
+ 'project_root="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"',
9037
+ 'evidence_root="$project_root/\u8BC1\u636E"',
9038
+ '[[ -d "$evidence_root" && ! -L "$evidence_root" ]] || fail "\u9879\u76EE\u7684 \u8BC1\u636E/ \u5FC5\u987B\u662F\u666E\u901A\u76EE\u5F55\uFF0C\u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5"',
9039
+ `out_abs="$(node -e "const p=require('node:path'); const root=p.resolve(process.argv[1],'\u8BC1\u636E'); const out=p.resolve(process.argv[1],process.argv[2]); if(out!==root && !out.startsWith(root+p.sep)){process.stderr.write('--out \u5FC5\u987B\u4F4D\u4E8E\u9879\u76EE\u7684 \u8BC1\u636E/ \u76EE\u5F55\\n'); process.exit(2)} process.stdout.write(out)" "$project_root" "$output")" || exit $?`,
9040
+ '[[ ! -e "$out_abs" && ! -L "$out_abs" ]] || fail "\u622A\u56FE\u5DF2\u5B58\u5728\u6216\u662F\u7B26\u53F7\u94FE\u63A5\uFF0C\u62D2\u7EDD\u8986\u76D6\uFF1A$out_abs"',
9041
+ 'mkdir -p "$(dirname "$out_abs")"',
9042
+ 'canonical_root="$(cd "$evidence_root" && pwd -P)"',
9043
+ 'canonical_parent="$(cd "$(dirname "$out_abs")" && pwd -P)"',
9044
+ 'case "$canonical_parent/" in',
9045
+ ' "$canonical_root/"*) ;;',
9046
+ ' *) fail "--out \u7684\u7236\u76EE\u5F55\u7ECF\u7B26\u53F7\u94FE\u63A5\u9003\u51FA\u4E86 \u8BC1\u636E/\uFF1A$output" ;;',
9047
+ "esac",
9048
+ "",
9049
+ "find_browser() {",
9050
+ ' if [[ -n "${HCM_CHROME_BIN:-}" ]]; then',
9051
+ ' if [[ -x "$HCM_CHROME_BIN" ]]; then printf "%s" "$HCM_CHROME_BIN"; return 0; fi',
9052
+ ' if command -v "$HCM_CHROME_BIN" >/dev/null 2>&1; then command -v "$HCM_CHROME_BIN"; return 0; fi',
9053
+ " return 1",
9054
+ " fi",
9055
+ " local candidate",
9056
+ " for candidate in google-chrome-stable google-chrome chromium chromium-browser; do",
9057
+ ' if command -v "$candidate" >/dev/null 2>&1; then command -v "$candidate"; return 0; fi',
9058
+ " done",
9059
+ ' for candidate in "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" "/Applications/Chromium.app/Contents/MacOS/Chromium"; do',
9060
+ ' if [[ -x "$candidate" ]]; then printf "%s" "$candidate"; return 0; fi',
9061
+ " done",
9062
+ " return 1",
9063
+ "}",
9064
+ "",
9065
+ 'command -v hcm >/dev/null 2>&1 || fail "\u627E\u4E0D\u5230 hcm\uFF1B\u5148\u8FD0\u884C ./setup.sh"',
9066
+ 'browser="$(find_browser)" || fail "\u627E\u4E0D\u5230 Chrome/Chromium\uFF1B\u8BF7\u8BBE\u7F6E HCM_CHROME_BIN"',
9067
+ 'temp_dir="$(mktemp -d "${TMPDIR:-/tmp}/hcm-page-acceptance.XXXXXX")"',
9068
+ "cleanup() {",
9069
+ ' case "$temp_dir" in "${TMPDIR:-/tmp}"/hcm-page-acceptance.*) rm -rf -- "$temp_dir" ;; esac',
9070
+ "}",
9071
+ "trap cleanup EXIT",
9072
+ 'dom_file="$temp_dir/page.dom"',
9073
+ 'browser_log="$temp_dir/browser.log"',
9074
+ "",
9075
+ 'hcm_args=(open "$page_path" --env "$environment")',
9076
+ 'if [[ -n "$identity" ]]; then hcm_args+=(--as "$identity"); fi',
9077
+ "hcm_args+=(--print-url)",
9078
+ 'url="$(hcm "${hcm_args[@]}")" || fail "hcm open \u672A\u80FD\u94F8\u51FA\u9875\u9762\u7968\u636E"',
9079
+ `url="\${url//$'\\r'/}"`,
9080
+ '[[ "$url" == http://* || "$url" == https://* ]] || fail "hcm open \u6CA1\u6709\u8FD4\u56DE\u6709\u6548 URL"',
9081
+ "",
9082
+ "browser_args=(",
9083
+ " --headless=new",
9084
+ " --disable-gpu",
9085
+ " --disable-dev-shm-usage",
9086
+ " --hide-scrollbars",
9087
+ " --no-first-run",
9088
+ " --no-default-browser-check",
9089
+ ' "--window-size=$size"',
9090
+ ' "--virtual-time-budget=$wait_ms"',
9091
+ ' "--screenshot=$out_abs"',
9092
+ " --dump-dom",
9093
+ ")",
9094
+ 'if [[ "$(id -u)" == "0" ]]; then browser_args+=(--no-sandbox); fi',
9095
+ 'if ! "$browser" "${browser_args[@]}" "$url" >"$dom_file" 2>"$browser_log"; then',
9096
+ ' sed -E "s/(ticket=)[^&[:space:]]+/\\1<redacted>/g" "$browser_log" >&2 || true',
9097
+ ' fail "\u6D4F\u89C8\u5668\u622A\u56FE\u8FDB\u7A0B\u5931\u8D25"',
9098
+ "fi",
9099
+ '[[ -s "$out_abs" ]] || fail "\u6D4F\u89C8\u5668\u672A\u751F\u6210\u975E\u7A7A PNG\uFF1A$out_abs"',
9100
+ "",
9101
+ 'for text in "${expected_texts[@]}"; do',
9102
+ ' grep -Fq -- "$text" "$dom_file" || fail "\u9875\u9762\u672A\u51FA\u73B0\u671F\u671B\u6587\u672C\uFF1A$text\uFF08\u622A\u56FE\u5DF2\u4FDD\u7559\uFF09"',
9103
+ "done",
9104
+ 'for text in "${rejected_texts[@]}"; do',
9105
+ ' if grep -Fq -- "$text" "$dom_file"; then fail "\u9875\u9762\u51FA\u73B0\u62D2\u7EDD\u6587\u672C\uFF1A$text\uFF08\u622A\u56FE\u5DF2\u4FDD\u7559\uFF09"; fi',
9106
+ "done",
9107
+ "",
9108
+ 'browser_version="$("$browser" --version 2>/dev/null | head -n 1 || true)"',
9109
+ `node -e "const fs=require('node:fs'); const result={ok:true,screenshot:process.argv[1],bytes:fs.statSync(process.argv[1]).size,environment:process.argv[2],identity:process.argv[3]||null,path:process.argv[4],viewport:process.argv[5],waitMs:Number(process.argv[6]),browser:process.argv[7]}; process.stdout.write(JSON.stringify(result)+'\\n')" "$out_abs" "$environment" "$identity" "$page_path" "$size" "$wait_ms" "$browser_version"`,
9110
+ ""
9111
+ ].join("\n");
9112
+ }
9113
+
9114
+ // src/commands/delivery-project-scaffold.ts
8737
9115
  var AGENT_BEGIN = "<!-- hcm-delivery-project:begin -->";
8738
9116
  var AGENT_END = "<!-- hcm-delivery-project:end -->";
8739
9117
  var GITIGNORE_BEGIN = "# >>> hcm delivery local state >>>";
@@ -8776,8 +9154,11 @@ function renderAgentInstructions() {
8776
9154
  "- \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
9155
  "- \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
9156
  "- 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",
9157
+ "- R2 \u5199\u6388\u6743\u53EA\u8BA4\u53EF\u9879\u76EE\u8D1F\u8D23\u4EBA\u5728**\u672C\u6B21\u5BF9\u8BDD\u6216\u4EFB\u52A1\u4E66**\u91CC\u7684\u660E\u786E\u6279\u51C6\uFF1B\u5BA2\u6237\u53E3\u5934\u8981\u6C42\u6216\u7FA4\u6D88\u606F\u53EA\u662F\u4E1A\u52A1\u9700\u6C42\uFF0C\u4E0D\u662F\u6267\u884C\u6388\u6743\uFF0C\u4E0D\u80FD\u636E\u6B64\u5207\u5230 controlled \u6216\u6267\u884C\u3002",
9158
+ "- \u5199\u524D\u5FC5\u987B\u8BF4\u660E\u5BF9\u8C61\u3001\u8303\u56F4\u3001\u5F71\u54CD\u4E0E\u56DE\u9000\u5E76\u53D6\u5F97\u672C\u6B21\u660E\u786E\u786E\u8BA4\u3002\u975E\u4EA4\u4E92\u8FD0\u884C\u62FF\u4E0D\u5230\u786E\u8BA4\u65F6\uFF0C\u6700\u591A\u505A\u5230 `prepare`\uFF0C\u7ED3\u8BBA\u5FC5\u987B\u4E3A `BLOCKED` \u5E76\u9644\u8BA1\u5212\uFF1B\u4E0D\u5F97\u81EA\u884C `delivery mode --set controlled` \u6216 `execute`\u3002",
9159
+ "- `.hcm-delivery/project.yml` \u662F\u6BCF\u4EBA\u6BCF\u673A\u72B6\u6001\uFF0C\u4E0D\u63D0\u4EA4\uFF1B\u53EA\u6709 `\u73AF\u5883.yml` \u4E2D `controlled: true` \u4E14\u6EE1\u8DB3\u4E0A\u8FF0\u6388\u6743\u65F6\uFF0C\u624D\u80FD\u7528 `--approved-by` \u4E0E `--reason` \u7559\u4E0B\u6A21\u5F0F\u5207\u6362\u6536\u636E\uFF0C\u5B8C\u6210\u540E\u7ACB\u5373\u56DE\u5230 plan-only\u3002\u5BA1\u8BA1\u53C2\u6570\u4E0D\u80FD\u66FF\u4EE3\u771F\u5B9E\u6388\u6743\u3002",
8780
9160
  "- \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",
9161
+ "- \u9875\u9762\u9A8C\u6536\u7EDF\u4E00\u7528 `./page-acceptance.sh`\uFF1A\u663E\u5F0F\u4F20\u73AF\u5883\u3001\u8EAB\u4EFD\u3001\u7AD9\u5185\u8DEF\u5F84\u3001\u671F\u671B\u6587\u672C\u4E0E `\u8BC1\u636E/` \u4E0B\u7684 PNG \u8DEF\u5F84\uFF1B\u4E0D\u80FD\u53EA\u4EE5\u201C\u751F\u6210\u4E86\u622A\u56FE\u201D\u5224\u901A\u8FC7\u3002",
8781
9162
  "- \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
9163
  AGENT_END,
8783
9164
  ""
@@ -8983,6 +9364,15 @@ async function scaffoldDeliveryProject(root, options) {
8983
9364
  493
8984
9365
  );
8985
9366
  if (setupCreated) await fs6.chmod(setupFile, 493);
9367
+ const pageAcceptanceFile = path6.join(root, "page-acceptance.sh");
9368
+ const pageAcceptanceCreated = await writeIfAbsent(
9369
+ pageAcceptanceFile,
9370
+ renderPageAcceptanceSh(),
9371
+ result,
9372
+ "page-acceptance.sh",
9373
+ 493
9374
+ );
9375
+ if (pageAcceptanceCreated) await fs6.chmod(pageAcceptanceFile, 493);
8986
9376
  await mergeManagedFile(path6.join(root, "AGENTS.md"), mergeAgentInstructions, result, "AGENTS.md");
8987
9377
  await mergeManagedFile(path6.join(root, "CLAUDE.md"), mergeAgentInstructions, result, "CLAUDE.md");
8988
9378
  await mergeManagedFile(path6.join(root, ".gitignore"), mergeDeliveryGitignore, result, ".gitignore");
@@ -9050,6 +9440,103 @@ function upsertBlock(existing, begin, end, block) {
9050
9440
  `;
9051
9441
  }
9052
9442
 
9443
+ // src/commands/delivery-mode-approval.ts
9444
+ import { randomUUID } from "crypto";
9445
+ import { promises as fs7 } from "fs";
9446
+ import path7 from "path";
9447
+ function requireControlledModeApproval(mode, approvedBy, reason) {
9448
+ if (mode !== "controlled") return null;
9449
+ const approver = approvedBy?.trim() ?? "";
9450
+ const approvalReason = reason?.trim() ?? "";
9451
+ if (!approver || !approvalReason) {
9452
+ throw new Error(
9453
+ "\u5207\u6362\u5230 controlled \u5FC5\u987B\u540C\u65F6\u4F20 --approved-by <\u9879\u76EE\u8D1F\u8D23\u4EBA> \u4E0E --reason <\u672C\u6B21\u660E\u786E\u6388\u6743\u4F9D\u636E>\u3002\u6388\u6743\u5FC5\u987B\u6765\u81EA\u9879\u76EE\u8D1F\u8D23\u4EBA\u5728\u672C\u6B21\u5BF9\u8BDD\u6216\u4EFB\u52A1\u4E66\u4E2D\u7684\u660E\u786E\u6279\u51C6\uFF1B\u5BA2\u6237\u53E3\u5934\u6216\u7FA4\u6D88\u606F\u4E0D\u662F\u6267\u884C\u6388\u6743"
9454
+ );
9455
+ }
9456
+ return { approvedBy: approver, reason: approvalReason };
9457
+ }
9458
+ async function setDeliveryModeWithReceipt(input) {
9459
+ const approval = requireControlledModeApproval(input.mode, input.approvedBy, input.reason);
9460
+ const root = path7.resolve(input.project);
9461
+ const projectFile = path7.join(root, ".hcm-delivery", "project.yml");
9462
+ const content = await fs7.readFile(projectFile, "utf8").catch((cause) => {
9463
+ throw new Error(`\u9879\u76EE\u672A\u521D\u59CB\u5316\uFF1A\u627E\u4E0D\u5230 ${projectFile}
9464
+ \u4E0B\u4E00\u6B65\uFF1Ahcm delivery init`, {
9465
+ cause
9466
+ });
9467
+ });
9468
+ const update = setDeliveryModeForEnvironment(content, input.environment, input.mode);
9469
+ const changed = (input.now ?? (() => /* @__PURE__ */ new Date()))();
9470
+ if (Number.isNaN(changed.getTime())) throw new Error("\u5F53\u524D\u65F6\u95F4\u65E0\u6548");
9471
+ let receiptFile = null;
9472
+ if (approval) {
9473
+ const relativeDirectory = path7.join("evidence", "delivery-mode");
9474
+ await ensureReceiptDirectory(root);
9475
+ const safeTime = changed.toISOString().replace(/[:.]/g, "-");
9476
+ const id = (input.receiptId ?? randomUUID)();
9477
+ if (!/^[a-zA-Z0-9-]+$/.test(id)) throw new Error("\u6A21\u5F0F\u5207\u6362\u6536\u636E ID \u975E\u6CD5");
9478
+ receiptFile = path7.join(relativeDirectory, `${safeTime}-${id}.receipt.json`);
9479
+ }
9480
+ const receipt = {
9481
+ schemaVersion: 1,
9482
+ receiptType: "delivery-mode-change",
9483
+ changedAt: changed.toISOString(),
9484
+ project: root,
9485
+ projectFile,
9486
+ environment: input.environment,
9487
+ previous: update.previous,
9488
+ deliveryMode: input.mode,
9489
+ canExecuteR2: input.mode === "controlled",
9490
+ migratedLegacy: update.migratedLegacy,
9491
+ approvedBy: approval?.approvedBy ?? null,
9492
+ reason: approval?.reason ?? null,
9493
+ receiptFile
9494
+ };
9495
+ await fs7.writeFile(projectFile, update.content, "utf8");
9496
+ if (receiptFile) {
9497
+ try {
9498
+ await fs7.writeFile(path7.join(root, receiptFile), `${JSON.stringify(receipt, null, 2)}
9499
+ `, {
9500
+ encoding: "utf8",
9501
+ mode: 384,
9502
+ flag: "wx"
9503
+ });
9504
+ } catch (cause) {
9505
+ try {
9506
+ await fs7.writeFile(projectFile, content, "utf8");
9507
+ } catch (rollbackCause) {
9508
+ throw new Error(
9509
+ `\u6A21\u5F0F\u5207\u6362\u6536\u636E\u5199\u5165\u5931\u8D25\uFF0C\u4E14 project.yml \u56DE\u6EDA\u5931\u8D25\uFF1A${String(rollbackCause.message)}`,
9510
+ { cause }
9511
+ );
9512
+ }
9513
+ throw new Error("\u6A21\u5F0F\u5207\u6362\u6536\u636E\u5199\u5165\u5931\u8D25\uFF1Bproject.yml \u5DF2\u56DE\u6EDA\uFF0C\u4ECD\u4FDD\u6301\u539F\u6A21\u5F0F", { cause });
9514
+ }
9515
+ }
9516
+ return receipt;
9517
+ }
9518
+ async function ensureReceiptDirectory(root) {
9519
+ const evidenceDirectory = path7.join(root, "evidence");
9520
+ await ensurePlainDirectory(evidenceDirectory, false);
9521
+ await ensurePlainDirectory(path7.join(evidenceDirectory, "delivery-mode"), true);
9522
+ }
9523
+ async function ensurePlainDirectory(directory, privateDirectory) {
9524
+ let created = false;
9525
+ try {
9526
+ await fs7.mkdir(directory, { mode: privateDirectory ? 448 : 493 });
9527
+ created = true;
9528
+ } catch (cause) {
9529
+ if (cause.code !== "EEXIST") throw cause;
9530
+ }
9531
+ const stat = await fs7.lstat(directory);
9532
+ if (!stat.isDirectory() || stat.isSymbolicLink()) {
9533
+ throw new Error(`\u6A21\u5F0F\u5207\u6362\u6536\u636E\u8DEF\u5F84\u4E0D\u662F\u666E\u901A\u76EE\u5F55\uFF1A${directory}`);
9534
+ }
9535
+ if (privateDirectory || created) {
9536
+ await fs7.chmod(directory, privateDirectory ? 448 : 493);
9537
+ }
9538
+ }
9539
+
9053
9540
  // src/commands/delivery-init.ts
9054
9541
  function renderProjectYml(environment, mode) {
9055
9542
  return [
@@ -9076,13 +9563,14 @@ async function deliveryInitCommand(args) {
9076
9563
  \u8FD9\u4E24\u4E2A\u503C\u662F delivery prepare \u8BA4\u5F97\u7684\u5168\u90E8\uFF1B\u5199\u522B\u7684\u503C prepare \u4F1A\u62D2\u7EDD\u52A0\u8F7D\u3002`
9077
9564
  );
9078
9565
  }
9566
+ const approval = requireControlledModeApproval(mode, args.approvedBy, args.reason);
9079
9567
  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");
9568
+ const root = path8.resolve(args.project ?? ".");
9569
+ const dir = path8.join(root, ".hcm-delivery");
9570
+ const file = path8.join(dir, "project.yml");
9083
9571
  let existed = false;
9084
9572
  try {
9085
- await fs7.access(file);
9573
+ await fs8.access(file);
9086
9574
  existed = true;
9087
9575
  } catch {
9088
9576
  existed = false;
@@ -9094,8 +9582,8 @@ async function deliveryInitCommand(args) {
9094
9582
  \u786E\u8981\u91CD\u5199\uFF1Ahcm delivery init --force`
9095
9583
  );
9096
9584
  }
9097
- await fs7.mkdir(dir, { recursive: true });
9098
- await fs7.writeFile(file, renderProjectYml(environment, mode), "utf8");
9585
+ await fs8.mkdir(dir, { recursive: true });
9586
+ await fs8.writeFile(file, renderProjectYml(environment, "plan-only"), "utf8");
9099
9587
  const environmentConfig = await loadEnv9(environment).catch(() => null);
9100
9588
  const scaffold = await scaffoldDeliveryProject(root, {
9101
9589
  environment,
@@ -9103,6 +9591,13 @@ async function deliveryInitCommand(args) {
9103
9591
  initialMode: mode,
9104
9592
  cliVersion: CLI_VERSION
9105
9593
  });
9594
+ const modeReceipt = approval ? await setDeliveryModeWithReceipt({
9595
+ project: root,
9596
+ environment,
9597
+ mode,
9598
+ approvedBy: approval.approvedBy,
9599
+ reason: approval.reason
9600
+ }) : null;
9106
9601
  const result = {
9107
9602
  project: root,
9108
9603
  projectFile: file,
@@ -9110,10 +9605,12 @@ async function deliveryInitCommand(args) {
9110
9605
  deliveryMode: mode,
9111
9606
  overwritten: existed,
9112
9607
  scaffold,
9608
+ ...modeReceipt ? { modeReceipt } : {},
9113
9609
  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"
9114
9610
  };
9115
- process.stdout.write(formatObject21(result, { format: args.output ?? "json" }) + "\n");
9116
- process.exit(0);
9611
+ process.stdout.write(formatObject22(result, { format: args.output ?? "json" }) + "\n");
9612
+ process.exitCode = 0;
9613
+ return;
9117
9614
  } catch (e) {
9118
9615
  exitWithError(e);
9119
9616
  process.exit(1);
@@ -9121,12 +9618,12 @@ async function deliveryInitCommand(args) {
9121
9618
  }
9122
9619
  async function deliveryModeCommand(args) {
9123
9620
  try {
9124
- const environment = await resolveDeliveryEnvironment(args.env);
9125
- const root = path7.resolve(args.project ?? ".");
9126
- const file = path7.join(root, ".hcm-delivery", "project.yml");
9621
+ const environment = requireDeliveryModeEnvironment(args.env);
9622
+ const root = path8.resolve(args.project ?? ".");
9623
+ const file = path8.join(root, ".hcm-delivery", "project.yml");
9127
9624
  let content;
9128
9625
  try {
9129
- content = await fs7.readFile(file, "utf8");
9626
+ content = await fs8.readFile(file, "utf8");
9130
9627
  } catch {
9131
9628
  throw new Error(
9132
9629
  `\u9879\u76EE\u672A\u521D\u59CB\u5316\uFF1A\u627E\u4E0D\u5230 ${file}
@@ -9136,7 +9633,7 @@ async function deliveryModeCommand(args) {
9136
9633
  if (!args.set) {
9137
9634
  const current = deliveryModeForEnvironment(content, environment);
9138
9635
  process.stdout.write(
9139
- formatObject21(
9636
+ formatObject22(
9140
9637
  {
9141
9638
  project: root,
9142
9639
  projectFile: file,
@@ -9150,34 +9647,39 @@ async function deliveryModeCommand(args) {
9150
9647
  { format: args.output ?? "json" }
9151
9648
  ) + "\n"
9152
9649
  );
9153
- process.exit(0);
9650
+ process.exitCode = 0;
9651
+ return;
9154
9652
  }
9155
9653
  const next = args.set;
9156
9654
  if (!DELIVERY_MODES.includes(next)) {
9157
9655
  throw new Error(`--set \u53EA\u63A5\u53D7 ${DELIVERY_MODES.join(" | ")}\uFF0C\u6536\u5230 "${args.set}"`);
9158
9656
  }
9159
- const update = setDeliveryModeForEnvironment(content, environment, next);
9160
- await fs7.writeFile(file, update.content, "utf8");
9657
+ const receipt = await setDeliveryModeWithReceipt({
9658
+ project: root,
9659
+ environment,
9660
+ mode: next,
9661
+ approvedBy: args.approvedBy,
9662
+ reason: args.reason
9663
+ });
9161
9664
  process.stdout.write(
9162
- formatObject21(
9163
- {
9164
- project: root,
9165
- projectFile: file,
9166
- environment,
9167
- deliveryMode: next,
9168
- previous: update.previous,
9169
- canExecuteR2: next === "controlled",
9170
- migratedLegacy: update.migratedLegacy
9171
- },
9172
- { format: args.output ?? "json" }
9173
- ) + "\n"
9665
+ formatObject22(receipt, { format: args.output ?? "json" }) + "\n"
9174
9666
  );
9175
- process.exit(0);
9667
+ process.exitCode = 0;
9668
+ return;
9176
9669
  } catch (e) {
9177
9670
  exitWithError(e);
9178
9671
  process.exit(1);
9179
9672
  }
9180
9673
  }
9674
+ function requireDeliveryModeEnvironment(envFlag) {
9675
+ const environment = envFlag?.trim();
9676
+ if (!environment) {
9677
+ throw new Error(
9678
+ "hcm delivery mode \u5FC5\u987B\u663E\u5F0F\u4F20 --env <\u73AF\u5883\u522B\u540D>\uFF1B\u9879\u76EE\u4EA4\u4ED8\u6A21\u5F0F\u4E0D\u7EE7\u627F\u5168\u5C40 activeEnv\uFF0C\u907F\u514D\u67E5\u770B\u6216\u4FEE\u6539\u9519\u8BEF\u73AF\u5883"
9679
+ );
9680
+ }
9681
+ return environment;
9682
+ }
9181
9683
  async function resolveDeliveryEnvironment(envFlag) {
9182
9684
  const global = await loadGlobalConfig9();
9183
9685
  const environment = resolveActiveEnv5({ envFlag }, process.env, global);
@@ -9191,8 +9693,8 @@ init_exit();
9191
9693
  import {
9192
9694
  HcmClient as HcmClient21,
9193
9695
  fetchReconIdentity,
9194
- formatObject as formatObject22,
9195
- fromAxiosError as fromAxiosError20,
9696
+ formatObject as formatObject23,
9697
+ fromAxiosError as fromAxiosError21,
9196
9698
  httpProbe,
9197
9699
  runDoctor
9198
9700
  } from "@hcmai/sdk";
@@ -9217,11 +9719,12 @@ async function deliveryDoctorCommand(args) {
9217
9719
  const report = await runDoctor(probe, identity2);
9218
9720
  const fmt = args.output ?? "json";
9219
9721
  if (fmt !== "json") process.stdout.write(render2(report) + "\n");
9220
- process.stdout.write(formatObject22(report, { format: fmt }) + "\n");
9221
- process.exit(report.ok ? 0 : 1);
9722
+ process.stdout.write(formatObject23(report, { format: fmt }) + "\n");
9723
+ process.exitCode = report.ok ? 0 : 1;
9724
+ return;
9222
9725
  } catch (e) {
9223
9726
  const err = e;
9224
- if (err?.isAxiosError) exitWithError(fromAxiosError20(err, args.env));
9727
+ if (err?.isAxiosError) exitWithError(fromAxiosError21(err, args.env));
9225
9728
  exitWithError(e);
9226
9729
  process.exit(1);
9227
9730
  }
@@ -9235,8 +9738,8 @@ import {
9235
9738
  ReconLayout,
9236
9739
  ROUND_EXIT_CODES,
9237
9740
  computeReconSourceKey,
9238
- formatObject as formatObject23,
9239
- fromAxiosError as fromAxiosError21,
9741
+ formatObject as formatObject24,
9742
+ fromAxiosError as fromAxiosError22,
9240
9743
  httpProbe as httpProbe2,
9241
9744
  inspectRound,
9242
9745
  renderRound,
@@ -9255,10 +9758,10 @@ async function deliveryReconCommand(args) {
9255
9758
  onlyModel: args.model ?? null,
9256
9759
  identity: ctx.tenantId ? { requestedTenantId: ctx.tenantId } : null
9257
9760
  });
9258
- process.stdout.write(formatObject23(summary, { format: args.output ?? "json" }) + "\n");
9761
+ process.stdout.write(formatObject24(summary, { format: args.output ?? "json" }) + "\n");
9259
9762
  } catch (e) {
9260
9763
  const err = e;
9261
- if (err?.isAxiosError) exitWithError(fromAxiosError21(err, args.env));
9764
+ if (err?.isAxiosError) exitWithError(fromAxiosError22(err, args.env));
9262
9765
  exitWithError(e);
9263
9766
  process.exit(1);
9264
9767
  }
@@ -9269,13 +9772,14 @@ async function deliveryReconRoundCommand(args) {
9269
9772
  const result = inspectRound(args.dir ?? ".");
9270
9773
  const fmt = args.output ?? "json";
9271
9774
  if (fmt !== "json") process.stdout.write(renderRound(result));
9272
- process.stdout.write(formatObject23(result, { format: fmt }) + "\n");
9775
+ process.stdout.write(formatObject24(result, { format: fmt }) + "\n");
9273
9776
  code = ROUND_EXIT_CODES[result.state];
9274
9777
  } catch (e) {
9275
9778
  exitWithError(e);
9276
9779
  code = 1;
9277
9780
  }
9278
- process.exit(code);
9781
+ process.exitCode = code;
9782
+ return;
9279
9783
  }
9280
9784
 
9281
9785
  // src/commands/delivery-gate0.ts
@@ -9287,14 +9791,14 @@ import {
9287
9791
  GAP_REASONS,
9288
9792
  deriveAclass,
9289
9793
  exitCode as gate0ExitCode,
9290
- formatObject as formatObject24,
9794
+ formatObject as formatObject25,
9291
9795
  inspectRound as inspectRound2,
9292
9796
  loadProtocolFacts,
9293
9797
  scan
9294
9798
  } from "@hcmai/sdk";
9295
- import * as path8 from "path";
9799
+ import * as path9 from "path";
9296
9800
  function renderGate0(result, skillRoot) {
9297
- const where = skillRoot ? `\uFF08${path8.resolve(skillRoot)}\uFF09` : "";
9801
+ const where = skillRoot ? `\uFF08${path9.resolve(skillRoot)}\uFF09` : "";
9298
9802
  const lines = [
9299
9803
  `\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`
9300
9804
  ];
@@ -9332,7 +9836,7 @@ async function deliveryGate0Command(args) {
9332
9836
  const merged = { ...result, premise: premise5 };
9333
9837
  const fmt = args.output ?? "json";
9334
9838
  if (fmt !== "json") process.stdout.write(renderGate0(merged, skillRoot));
9335
- process.stdout.write(`${formatObject24(merged, { format: fmt })}
9839
+ process.stdout.write(`${formatObject25(merged, { format: fmt })}
9336
9840
  `);
9337
9841
  for (const problem of premise5) {
9338
9842
  process.stderr.write(`\u{1F534} \u524D\u63D0\u4E0D\u6210\u7ACB\uFF08${problem.reason}\uFF09\uFF1A${problem.message}
@@ -9343,7 +9847,8 @@ async function deliveryGate0Command(args) {
9343
9847
  exitWithError(e);
9344
9848
  code = 1;
9345
9849
  }
9346
- process.exit(code);
9850
+ process.exitCode = code;
9851
+ return;
9347
9852
  }
9348
9853
 
9349
9854
  // src/commands/delivery-seed.ts
@@ -9406,7 +9911,7 @@ import {
9406
9911
  writeRisk
9407
9912
  } from "@hcmai/sdk";
9408
9913
  import { existsSync as existsSync3 } from "fs";
9409
- import * as path9 from "path";
9914
+ import * as path10 from "path";
9410
9915
  function premise(message, hint = "") {
9411
9916
  process.stderr.write(message + (hint ? `
9412
9917
  \u2192 ${hint}` : "") + "\n");
@@ -9433,13 +9938,13 @@ async function runSeedPlan(args, client3) {
9433
9938
  const reconDir = candidates[0].reconDir;
9434
9939
  if (candidates.length > 1) {
9435
9940
  process.stderr.write(
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"
9941
+ `\u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u6709 ${candidates.length} \u4EFD\u57FA\u7EBF\uFF0C\u672C\u8F6E\u8BFB\u7684\u662F \`${path10.basename(reconDir)}\`\uFF1A` + candidates.slice(1).map((c) => `\`${path10.basename(c.reconDir)}\``).join("\u3001") + " \u672A\u88AB\u8BFB\u53D6 \u2014\u2014 \u4E0D\u540C sourceKey \u7684\u4EA7\u7269**\u4E0D\u53EF\u4E92\u6362**\u3002\n"
9437
9942
  );
9438
9943
  }
9439
9944
  const round = inspectRound3(reconDir);
9440
9945
  process.stderr.write(roundWarning(round));
9441
9946
  const baseline = {
9442
- path: `${path9.basename(path9.dirname(reconDir))}/${path9.basename(reconDir)}`,
9947
+ path: `${path10.basename(path10.dirname(reconDir))}/${path10.basename(reconDir)}`,
9443
9948
  roundId: round.roundId ?? null
9444
9949
  };
9445
9950
  let exemptions = null;
@@ -9701,7 +10206,7 @@ async function deliverySeedVerifyCommand(args) {
9701
10206
  // src/commands/delivery-seed-find.ts
9702
10207
  import { existsSync as existsSync4 } from "fs";
9703
10208
  import { readFileSync as readFileSync6 } from "fs";
9704
- import * as path10 from "path";
10209
+ import * as path11 from "path";
9705
10210
  import {
9706
10211
  INIT_EXIT_CODES as INIT_EXIT_CODES2,
9707
10212
  ValueHints,
@@ -9715,10 +10220,10 @@ import {
9715
10220
  valuesRoundCaveat
9716
10221
  } from "@hcmai/sdk";
9717
10222
  function provenance(chosenReconDir, others) {
9718
- let line = `> \u57FA\u7EBF\uFF1A\`${path10.basename(chosenReconDir)}\`
10223
+ let line = `> \u57FA\u7EBF\uFF1A\`${path11.basename(chosenReconDir)}\`
9719
10224
  `;
9720
10225
  if (others.length > 0) {
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";
10226
+ line += `> \u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u53E6\u6709 ${others.length} \u4EFD\u57FA\u7EBF\u672A\u88AB\u8BFB\u53D6\uFF1A` + others.map((o) => `\`${path11.basename(o)}\``).join("\u3001") + " \u2014\u2014 \u4E0D\u540C sourceKey \u7684\u4EA7\u7269**\u4E0D\u53EF\u4E92\u6362**\u3002\n";
9722
10227
  }
9723
10228
  return `${line}
9724
10229
  `;
@@ -10055,7 +10560,7 @@ import {
10055
10560
  runTriageRound
10056
10561
  } from "@hcmai/sdk";
10057
10562
  import { mkdirSync, readFileSync as readFileSync8, writeFileSync as writeFileSync2 } from "fs";
10058
- import * as path11 from "path";
10563
+ import * as path12 from "path";
10059
10564
  var DEFAULT_CAPABILITIES4 = "default";
10060
10565
  function premise4(message, hint) {
10061
10566
  process.stderr.write(`\u{1F534} \u524D\u63D0\u4E0D\u6210\u7ACB\uFF1A${message}
@@ -10091,8 +10596,8 @@ function renderProblems(rows) {
10091
10596
  `;
10092
10597
  }
10093
10598
  function writeTriageArtifact(outDir, body) {
10094
- const out = path11.join(outDir, "work", "triage.md");
10095
- mkdirSync(path11.dirname(out), { recursive: true });
10599
+ const out = path12.join(outDir, "work", "triage.md");
10600
+ mkdirSync(path12.dirname(out), { recursive: true });
10096
10601
  writeFileSync2(out, body, "utf8");
10097
10602
  return out;
10098
10603
  }
@@ -10126,15 +10631,16 @@ async function deliveryTriageCommand(args) {
10126
10631
  exitWithError(e);
10127
10632
  code = 1;
10128
10633
  }
10129
- process.exit(code);
10634
+ process.exitCode = code;
10635
+ return;
10130
10636
  }
10131
10637
 
10132
10638
  // src/commands/delivery-execution.ts
10133
10639
  import { createHash as createHash5, randomBytes as secureRandomBytes } from "crypto";
10134
10640
  import { spawn as spawn2 } from "child_process";
10135
- import { createReadStream, promises as fs8 } from "fs";
10136
- import path12 from "path";
10137
- import { CliError as CliError21, CliErrorCode as CliErrorCode20, formatObject as formatObject25 } from "@hcmai/sdk";
10641
+ import { createReadStream, promises as fs9 } from "fs";
10642
+ import path13 from "path";
10643
+ import { CliError as CliError21, CliErrorCode as CliErrorCode20, formatObject as formatObject26 } from "@hcmai/sdk";
10138
10644
  init_exit();
10139
10645
  var EXECUTION_CONTRACT_VERSION = "2026-09-03.controlled-v4";
10140
10646
  var DEFAULT_TTL_SECONDS = 15 * 60;
@@ -10176,11 +10682,11 @@ async function prepareDeliveryExecution(input) {
10176
10682
  };
10177
10683
  const planId = sha2565(canonicalJson(core)).slice(0, 24);
10178
10684
  const plan = { ...core, planId };
10179
- const plansDir = path12.join(project, ".hcm-delivery", "execution-plans");
10685
+ const plansDir = path13.join(project, ".hcm-delivery", "execution-plans");
10180
10686
  await safeManagedDirectory(project, ".hcm-delivery/execution-plans", plansDir);
10181
- const planFile = path12.join(plansDir, `${planId}.json`);
10687
+ const planFile = path13.join(plansDir, `${planId}.json`);
10182
10688
  try {
10183
- await fs8.writeFile(planFile, `${JSON.stringify(plan, null, 2)}
10689
+ await fs9.writeFile(planFile, `${JSON.stringify(plan, null, 2)}
10184
10690
  `, {
10185
10691
  encoding: "utf8",
10186
10692
  mode: 384,
@@ -10194,7 +10700,7 @@ async function prepareDeliveryExecution(input) {
10194
10700
  async function executeDeliveryPlan(input) {
10195
10701
  if (!PLAN_ID_PATTERN.test(input.planId)) throw invalid2("planId \u5FC5\u987B\u662F 24 \u4F4D\u5C0F\u5199\u5341\u516D\u8FDB\u5236");
10196
10702
  const project = await realProject(input.project);
10197
- const planFile = path12.join(project, ".hcm-delivery", "execution-plans", `${input.planId}.json`);
10703
+ const planFile = path13.join(project, ".hcm-delivery", "execution-plans", `${input.planId}.json`);
10198
10704
  const plan = await readPlan(project, planFile);
10199
10705
  if (plan.planId !== input.planId || computePlanId(plan) !== input.planId) {
10200
10706
  throw invalid2("\u6267\u884C\u8BA1\u5212\u5185\u5BB9\u4E0E planId \u6458\u8981\u4E0D\u4E00\u81F4");
@@ -10231,13 +10737,13 @@ async function executeDeliveryPlan(input) {
10231
10737
  await assertDocumentUnchanged(project, plan.documents.rollback, "\u56DE\u6EDA\u8BF4\u660E");
10232
10738
  await assertPayloadsUnchanged(project, plan.payloads);
10233
10739
  const evidenceDir = await bindEvidenceDirectory(project, plan.evidenceDir);
10234
- const receiptFile = path12.join(evidenceDir.absolute, `${plan.planId}.receipt.json`);
10740
+ const receiptFile = path13.join(evidenceDir.absolute, `${plan.planId}.receipt.json`);
10235
10741
  if (await pathExists(receiptFile)) throw invalid2(`\u6267\u884C\u6536\u636E\u5DF2\u5B58\u5728\uFF0C\u62D2\u7EDD\u518D\u6B21\u6267\u884C\uFF1A${plan.planId}`);
10236
- const claimsDir = path12.join(project, ".hcm-delivery", "execution-claims");
10742
+ const claimsDir = path13.join(project, ".hcm-delivery", "execution-claims");
10237
10743
  await safeManagedDirectory(project, ".hcm-delivery/execution-claims", claimsDir);
10238
- const claimFile = path12.join(claimsDir, `${plan.planId}.json`);
10744
+ const claimFile = path13.join(claimsDir, `${plan.planId}.json`);
10239
10745
  try {
10240
- await fs8.writeFile(
10746
+ await fs9.writeFile(
10241
10747
  claimFile,
10242
10748
  `${JSON.stringify({ schemaVersion: 1, planId: plan.planId, claimedAt: now.toISOString() }, null, 2)}
10243
10749
  `,
@@ -10294,7 +10800,7 @@ async function deliveryPrepareCommand(argv, args) {
10294
10800
  evidenceDir: args.evidenceDir,
10295
10801
  ...ttlSeconds === void 0 ? {} : { ttlSeconds }
10296
10802
  });
10297
- process.stdout.write(formatObject25(plan, { format: args.output ?? "json" }) + "\n");
10803
+ process.stdout.write(formatObject26(plan, { format: args.output ?? "json" }) + "\n");
10298
10804
  process.stderr.write(`
10299
10805
  \u4E0B\u4E00\u6B65\uFF08argv \u5FC5\u987B\u4E0E\u672C\u6B21\u5B8C\u5168\u4E00\u81F4\uFF09\uFF1A
10300
10806
  ${nextCommandHint(plan.planId, args.project, argv)}
@@ -10315,14 +10821,17 @@ async function deliveryExecuteCommand(planId, argv, args) {
10315
10821
  planId,
10316
10822
  argv
10317
10823
  });
10318
- process.stdout.write(formatObject25(receipt, { format: args.output ?? "json" }) + "\n");
10319
- process.exitCode = receipt.exitCode;
10824
+ writeDeliveryExecutionReceipt(receipt, args.output ?? "json");
10320
10825
  } catch (cause) {
10321
10826
  exitWithError(cause);
10322
10827
  }
10323
10828
  }
10829
+ function writeDeliveryExecutionReceipt(receipt, format = "json") {
10830
+ process.stderr.write(formatObject26(receipt, { format }) + "\n");
10831
+ process.exitCode = receipt.exitCode;
10832
+ }
10324
10833
  async function readProjectMode(project, environment) {
10325
- const file = path12.join(project, ".hcm-delivery", "project.yml");
10834
+ const file = path13.join(project, ".hcm-delivery", "project.yml");
10326
10835
  const content = await readSafeFile(project, file, "\u9879\u76EE\u914D\u7F6E");
10327
10836
  let mode;
10328
10837
  try {
@@ -10338,13 +10847,13 @@ async function readProjectMode(project, environment) {
10338
10847
  return mode;
10339
10848
  }
10340
10849
  var SKILLS_LOCK_CANDIDATES = [
10341
- path12.join("hcm-skills", ".hcm-skills.json"),
10342
- path12.join(".claude", "skills", ".hcm-skills.json")
10850
+ path13.join("hcm-skills", ".hcm-skills.json"),
10851
+ path13.join(".claude", "skills", ".hcm-skills.json")
10343
10852
  ];
10344
10853
  async function readSkillsLock(project) {
10345
10854
  const found = [];
10346
10855
  for (const candidate of SKILLS_LOCK_CANDIDATES) {
10347
- if (await pathExists(path12.join(project, candidate))) found.push(candidate);
10856
+ if (await pathExists(path13.join(project, candidate))) found.push(candidate);
10348
10857
  }
10349
10858
  if (found.length === 0) {
10350
10859
  throw invalid2(
@@ -10356,7 +10865,7 @@ async function readSkillsLock(project) {
10356
10865
  `\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`
10357
10866
  );
10358
10867
  }
10359
- const bytes = await readSafeFile(project, path12.join(project, found[0]), "\u6280\u80FD\u9501");
10868
+ const bytes = await readSafeFile(project, path13.join(project, found[0]), "\u6280\u80FD\u9501");
10360
10869
  try {
10361
10870
  JSON.parse(bytes.toString("utf8"));
10362
10871
  } catch (cause) {
@@ -10369,7 +10878,7 @@ async function bindDocument(project, reference, label) {
10369
10878
  if (!(relative2.startsWith("work/") || relative2.startsWith("decisions/"))) {
10370
10879
  throw invalid2(`${label}\u5FC5\u987B\u4F4D\u4E8E\u9879\u76EE work/ \u6216 decisions/ \u4E0B`);
10371
10880
  }
10372
- const file = path12.join(project, relative2);
10881
+ const file = path13.join(project, relative2);
10373
10882
  const bytes = await readSafeFile(project, file, label);
10374
10883
  return { path: relative2, sha256: sha2565(bytes) };
10375
10884
  }
@@ -10382,11 +10891,11 @@ async function bindEvidenceDirectory(project, reference) {
10382
10891
  if (!(relative2 === "evidence" || relative2.startsWith("evidence/"))) {
10383
10892
  throw invalid2("evidence \u76EE\u5F55\u5FC5\u987B\u4F4D\u4E8E\u9879\u76EE evidence/ \u4E0B");
10384
10893
  }
10385
- const absolute = path12.join(project, relative2);
10894
+ const absolute = path13.join(project, relative2);
10386
10895
  await assertNoSymlinkComponents(project, relative2);
10387
- const stat = await fs8.stat(absolute).catch(() => null);
10896
+ const stat = await fs9.stat(absolute).catch(() => null);
10388
10897
  if (stat === null) {
10389
- await fs8.mkdir(absolute, { recursive: true, mode: 448 }).catch((cause) => {
10898
+ await fs9.mkdir(absolute, { recursive: true, mode: 448 }).catch((cause) => {
10390
10899
  throw invalid2(
10391
10900
  `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`,
10392
10901
  cause
@@ -10566,7 +11075,7 @@ async function bindPayloadPath(project, reference, label) {
10566
11075
  const relative2 = safeRelative(reference, label);
10567
11076
  let stat;
10568
11077
  try {
10569
- stat = await fs8.stat(path12.join(project, relative2));
11078
+ stat = await fs9.stat(path13.join(project, relative2));
10570
11079
  } catch (cause) {
10571
11080
  throw invalid2(
10572
11081
  `${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`,
@@ -10577,10 +11086,10 @@ async function bindPayloadPath(project, reference, label) {
10577
11086
  }
10578
11087
  async function bindPayloadDirectory(project, reference, label) {
10579
11088
  const relative2 = reference === "." ? "." : safeRelative(reference, label);
10580
- const root = path12.join(project, relative2);
11089
+ const root = path13.join(project, relative2);
10581
11090
  let stat;
10582
11091
  try {
10583
- stat = await fs8.stat(root);
11092
+ stat = await fs9.stat(root);
10584
11093
  } catch {
10585
11094
  throw invalid2(`${label}\u4E0D\u5B58\u5728\uFF1A${relative2}`);
10586
11095
  }
@@ -10590,10 +11099,10 @@ async function bindPayloadDirectory(project, reference, label) {
10590
11099
  const skipToolingAtRoot = relative2 === ".";
10591
11100
  const entries = [];
10592
11101
  const walk = async (dir, prefix) => {
10593
- const items = await fs8.readdir(dir, { withFileTypes: true });
11102
+ const items = await fs9.readdir(dir, { withFileTypes: true });
10594
11103
  for (const item of [...items].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0)) {
10595
11104
  if (skipToolingAtRoot && prefix === "" && TOOLING_DIRS.includes(item.name)) continue;
10596
- const child = path12.join(dir, item.name);
11105
+ const child = path13.join(dir, item.name);
10597
11106
  const rel = prefix ? `${prefix}/${item.name}` : item.name;
10598
11107
  if (item.isSymbolicLink()) {
10599
11108
  throw invalid2(
@@ -10618,7 +11127,7 @@ ${sha2565(bytes)}`);
10618
11127
  }
10619
11128
  async function bindPayloadFile(project, reference, label) {
10620
11129
  const relative2 = safeRelative(reference, label);
10621
- const file = path12.join(project, relative2);
11130
+ const file = path13.join(project, relative2);
10622
11131
  const bytes = await readSafeFile(project, file, label);
10623
11132
  return { path: relative2, kind: "file", sha256: sha2565(bytes) };
10624
11133
  }
@@ -10681,29 +11190,29 @@ async function runCurrentCliCommand(argv, cwd, streams) {
10681
11190
  async function writeReceiptExclusive(target, receipt) {
10682
11191
  const temp = `${target}.${process.pid}.${Date.now()}.tmp`;
10683
11192
  try {
10684
- await fs8.writeFile(temp, `${JSON.stringify(receipt, null, 2)}
11193
+ await fs9.writeFile(temp, `${JSON.stringify(receipt, null, 2)}
10685
11194
  `, {
10686
11195
  encoding: "utf8",
10687
11196
  mode: 384,
10688
11197
  flag: "wx"
10689
11198
  });
10690
- await fs8.link(temp, target);
11199
+ await fs9.link(temp, target);
10691
11200
  } catch (cause) {
10692
- throw invalid2(`\u6267\u884C\u6536\u636E\u5199\u5165\u5931\u8D25\u6216\u5DF2\u5B58\u5728\uFF1A${path12.basename(target)}`, cause);
11201
+ throw invalid2(`\u6267\u884C\u6536\u636E\u5199\u5165\u5931\u8D25\u6216\u5DF2\u5B58\u5728\uFF1A${path13.basename(target)}`, cause);
10693
11202
  } finally {
10694
- await fs8.unlink(temp).catch(() => void 0);
11203
+ await fs9.unlink(temp).catch(() => void 0);
10695
11204
  }
10696
11205
  }
10697
11206
  async function safeManagedDirectory(project, relative2, absolute) {
10698
- await assertNoSymlinkComponents(project, path12.dirname(relative2));
10699
- const existing = await fs8.lstat(absolute).catch(() => void 0);
11207
+ await assertNoSymlinkComponents(project, path13.dirname(relative2));
11208
+ const existing = await fs9.lstat(absolute).catch(() => void 0);
10700
11209
  if (existing?.isSymbolicLink()) throw invalid2(`\u53D7\u7BA1\u76EE\u5F55\u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5\uFF1A${relative2}`);
10701
11210
  if (existing && !existing.isDirectory()) throw invalid2(`\u53D7\u7BA1\u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55\uFF1A${relative2}`);
10702
- if (!existing) await fs8.mkdir(absolute, { mode: 448 });
10703
- await fs8.chmod(absolute, 448);
11211
+ if (!existing) await fs9.mkdir(absolute, { mode: 448 });
11212
+ await fs9.chmod(absolute, 448);
10704
11213
  }
10705
11214
  async function pathExists(file) {
10706
- return fs8.lstat(file).then(
11215
+ return fs9.lstat(file).then(
10707
11216
  () => true,
10708
11217
  (cause) => {
10709
11218
  if (cause.code === "ENOENT") return false;
@@ -10712,47 +11221,47 @@ async function pathExists(file) {
10712
11221
  );
10713
11222
  }
10714
11223
  async function readSafeFile(project, file, label) {
10715
- const relative2 = path12.relative(project, file).split(path12.sep).join("/");
10716
- if (relative2.startsWith("../") || path12.isAbsolute(relative2))
11224
+ const relative2 = path13.relative(project, file).split(path13.sep).join("/");
11225
+ if (relative2.startsWith("../") || path13.isAbsolute(relative2))
10717
11226
  throw invalid2(`${label}\u8DEF\u5F84\u9003\u9038\u9879\u76EE`);
10718
11227
  await assertNoSymlinkComponents(project, relative2);
10719
11228
  let stat;
10720
11229
  try {
10721
- stat = await fs8.lstat(file);
11230
+ stat = await fs9.lstat(file);
10722
11231
  } catch (cause) {
10723
11232
  throw invalid2(`${label}\u4E0D\u53EF\u7528\uFF1A${relative2}`, cause);
10724
11233
  }
10725
11234
  if (stat.isSymbolicLink()) throw invalid2(`${label}\u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5\uFF1A${relative2}`);
10726
11235
  if (!stat.isFile()) throw invalid2(`${label}\u4E0D\u662F\u666E\u901A\u6587\u4EF6\uFF1A${relative2}`);
10727
- return fs8.readFile(file);
11236
+ return fs9.readFile(file);
10728
11237
  }
10729
11238
  async function assertNoSymlinkComponents(project, relative2) {
10730
11239
  const parts = relative2.split("/").filter(Boolean);
10731
11240
  let current = project;
10732
11241
  for (const part of parts) {
10733
- current = path12.join(current, part);
10734
- const stat = await fs8.lstat(current).catch(() => void 0);
11242
+ current = path13.join(current, part);
11243
+ const stat = await fs9.lstat(current).catch(() => void 0);
10735
11244
  if (stat?.isSymbolicLink()) throw invalid2(`\u8DEF\u5F84\u5305\u542B\u7B26\u53F7\u94FE\u63A5\uFF1A${relative2}`);
10736
11245
  if (!stat) break;
10737
11246
  }
10738
11247
  }
10739
11248
  async function realProject(requested) {
10740
- const absolute = path12.resolve(requested);
11249
+ const absolute = path13.resolve(requested);
10741
11250
  let project;
10742
11251
  try {
10743
- project = await fs8.realpath(absolute);
11252
+ project = await fs9.realpath(absolute);
10744
11253
  } catch (cause) {
10745
11254
  throw invalid2(`\u9879\u76EE\u76EE\u5F55\u4E0D\u53EF\u7528\uFF1A${absolute}`, cause);
10746
11255
  }
10747
- const stat = await fs8.stat(project);
11256
+ const stat = await fs9.stat(project);
10748
11257
  if (!stat.isDirectory()) throw invalid2(`\u9879\u76EE\u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55\uFF1A${absolute}`);
10749
11258
  return project;
10750
11259
  }
10751
11260
  function safeRelative(reference, label) {
10752
- if (!reference || path12.isAbsolute(reference) || /[\r\n\0]/.test(reference)) {
11261
+ if (!reference || path13.isAbsolute(reference) || /[\r\n\0]/.test(reference)) {
10753
11262
  throw invalid2(`${label}\u5FC5\u987B\u662F\u9879\u76EE\u5185\u76F8\u5BF9\u8DEF\u5F84`);
10754
11263
  }
10755
- const normalized = path12.normalize(reference).split(path12.sep).join("/");
11264
+ const normalized = path13.normalize(reference).split(path13.sep).join("/");
10756
11265
  if (normalized === ".." || normalized.startsWith("../") || normalized === ".") {
10757
11266
  throw invalid2(`${label}\u8DEF\u5F84\u9003\u9038\u9879\u76EE`);
10758
11267
  }
@@ -10819,8 +11328,8 @@ init_exit();
10819
11328
  import {
10820
11329
  HcmClient as HcmClient26,
10821
11330
  adminResetPassword,
10822
- formatObject as formatObject26,
10823
- fromAxiosError as fromAxiosError22,
11331
+ formatObject as formatObject27,
11332
+ fromAxiosError as fromAxiosError23,
10824
11333
  CliError as CliError22,
10825
11334
  CliErrorCode as CliErrorCode21
10826
11335
  } from "@hcmai/sdk";
@@ -10853,10 +11362,10 @@ async function userResetPasswordCommand(args) {
10853
11362
  const request = buildAdminResetPasswordRequest(args, password);
10854
11363
  const client3 = HcmClient26.fromAuthContext(await getActiveAuthContextFromCli(args));
10855
11364
  const result = await adminResetPassword(client3.raw(), request);
10856
- process.stdout.write(formatObject26(result, { format: args.output ?? "json" }) + "\n");
11365
+ process.stdout.write(formatObject27(result, { format: args.output ?? "json" }) + "\n");
10857
11366
  } catch (cause) {
10858
11367
  const err = cause;
10859
- if (err?.isAxiosError) exitWithError(fromAxiosError22(err, args.env));
11368
+ if (err?.isAxiosError) exitWithError(fromAxiosError23(err, args.env));
10860
11369
  exitWithError(cause);
10861
11370
  }
10862
11371
  }
@@ -10877,8 +11386,8 @@ init_exit();
10877
11386
  init_auth_guard();
10878
11387
  import {
10879
11388
  HcmClient as HcmClient27,
10880
- formatObject as formatObject27,
10881
- fromAxiosError as fromAxiosError23
11389
+ formatObject as formatObject28,
11390
+ fromAxiosError as fromAxiosError24
10882
11391
  } from "@hcmai/sdk";
10883
11392
  async function modelsCommand(keyword, args) {
10884
11393
  try {
@@ -10888,15 +11397,17 @@ async function modelsCommand(keyword, args) {
10888
11397
  const rows = (needle ? all.filter((m) => JSON.stringify(m).toLowerCase().includes(needle)) : all).sort((a, b) => key(a).localeCompare(key(b)));
10889
11398
  const fmt = args.output ?? "table";
10890
11399
  if (fmt !== "table") {
10891
- process.stdout.write(formatObject27({ total: rows.length, models: rows }, { format: fmt }) + "\n");
10892
- process.exit(0);
11400
+ process.stdout.write(formatObject28({ total: rows.length, models: rows }, { format: fmt }) + "\n");
11401
+ process.exitCode = 0;
11402
+ return;
10893
11403
  }
10894
11404
  if (rows.length === 0) {
10895
11405
  process.stdout.write(
10896
11406
  needle ? `\u6CA1\u6709\u5339\u914D "${keyword}" \u7684 Model\uFF08\u5171 ${all.length} \u4E2A\u53EF\u89C1\uFF09\u3002
10897
11407
  ` : "\u5F53\u524D\u8EAB\u4EFD\u5728\u8FD9\u4E2A\u73AF\u5883\u770B\u4E0D\u5230\u4EFB\u4F55 Model\u3002\n"
10898
11408
  );
10899
- process.exit(0);
11409
+ process.exitCode = 0;
11410
+ return;
10900
11411
  }
10901
11412
  const width = Math.max(...rows.map((m) => key(m).length), 8);
10902
11413
  process.stdout.write(`${"MODEL".padEnd(width)} TYPE
@@ -10909,10 +11420,11 @@ async function modelsCommand(keyword, args) {
10909
11420
  \u5171 ${rows.length} \u4E2A${needle ? `\uFF08\u5168\u90E8 ${all.length} \u4E2A\u4E2D\u5339\u914D\uFF09` : ""}\u3002
10910
11421
  `);
10911
11422
  process.stdout.write("\u4E0B\u4E00\u6B65\uFF1Ahcm describe <Model> \u770B\u5B57\u6BB5\u3001\u5173\u7CFB\u4E0E Action\u3002\n");
10912
- process.exit(0);
11423
+ process.exitCode = 0;
11424
+ return;
10913
11425
  } catch (e) {
10914
11426
  const err = e;
10915
- if (err?.isAxiosError) exitWithError(fromAxiosError23(err, args.profile));
11427
+ if (err?.isAxiosError) exitWithError(fromAxiosError24(err, args.profile));
10916
11428
  exitWithError(e);
10917
11429
  }
10918
11430
  }
@@ -10955,6 +11467,7 @@ env.command("show [name]").description("\u663E\u793A env \u8BE6\u60C5\uFF08\u542
10955
11467
  env.command("edit <field> <value>").description("\u7F16\u8F91 env \u5B57\u6BB5\uFF08endpoint / frontend / tenantId / defaultIdentity / defaultAgent\uFF09").option("--env <name>", "\u76EE\u6807 env \u540D\uFF08\u9ED8\u8BA4\u5F53\u524D activeEnv\uFF09").action((field, value, opts) => envEdit(field, value, opts));
10956
11468
  var identity = program.command("identity").description("\u7BA1\u7406 HCM \u8EAB\u4EFD\u51ED\u636E\uFF08env \u4E0B\u7684 identity\uFF09");
10957
11469
  identity.command("list").description("\u5217\u51FA identity\uFF08\u9ED8\u8BA4\u5217\u5F53\u524D env\uFF0C--env all \u5217\u5168\u90E8\uFF09").option("--env <name>", '\u8FC7\u6EE4 env\uFF1B\u4F20 "all" \u5217\u5168\u90E8', void 0).action((opts) => identityList(opts));
11470
+ identity.command("show <name>").description("\u5B9E\u65F6\u663E\u793A alias \u5BF9\u5E94\u7684\u670D\u52A1\u7AEF\u7528\u6237\u3001\u79DF\u6237\u4E0E\u89D2\u8272\uFF08\u4E0D\u8F93\u51FA token\uFF09").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((name, opts) => identityShow(name, opts));
10958
11471
  identity.command("use <name>").description("\u628A identity \u8BBE\u4E3A\u5176 env \u7684 default identity").action((name) => identityUse(name));
10959
11472
  identity.command("remove <name>").description("\u5220\u9664 identity\uFF08\u6E05 token + \u82E5\u662F env default \u5219\u6E05\u7A7A\uFF09").action((name) => identityRemove(name));
10960
11473
  var user = program.command("user").description("\u7BA1\u7406\u79DF\u6237\u7528\u6237\u7684\u4E13\u7528\u51ED\u636E\u6D41\u7A0B");
@@ -11024,8 +11537,8 @@ delivery.command("triage").description(
11024
11537
  "--recon <dir>",
11025
11538
  "\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"
11026
11539
  ).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));
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));
11540
+ delivery.command("init").description("\u751F\u6210\u5BA2\u6237\u9879\u76EE\u4ED3\u9AA8\u67B6\u3001\u73AF\u5883\u6E05\u5355\u3001\u6210\u5458 setup \u4E0E\u672C\u673A\u53D7\u63A7\u4EA4\u4ED8\u914D\u7F6E").option("--project <dir>", "HCM \u987E\u95EE\u9879\u76EE\u6839\u76EE\u5F55", ".").option("--env <name>", "\u521D\u59CB\u5316\u54EA\u4E2A\u73AF\u5883\uFF08\u9ED8\u8BA4 HCM_ENV / activeEnv\uFF09").option("--mode <mode>", "\u672C\u673A\u521D\u59CB\u4EA4\u4ED8\u6A21\u5F0F\uFF1Acontrolled | plan-only", "plan-only").option("--approved-by <person>", "\u5207\u5230 controlled \u65F6\u5FC5\u586B\uFF1A\u672C\u6B21\u660E\u786E\u6279\u51C6\u7684\u9879\u76EE\u8D1F\u8D23\u4EBA").option("--reason <text>", "\u5207\u5230 controlled \u65F6\u5FC5\u586B\uFF1A\u672C\u6B21\u5BF9\u8BDD\u6216\u4EFB\u52A1\u4E66\u4E2D\u7684\u6388\u6743\u4F9D\u636E").option("--force", "\u8986\u76D6\u5DF2\u5B58\u5728\u7684\u9879\u76EE\u914D\u7F6E").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((opts) => deliveryInitCommand(opts));
11541
+ delivery.command("mode").description("\u6309\u73AF\u5883\u770B/\u6539\u672C\u673A\u4EA4\u4ED8\u6A21\u5F0F\uFF1B\u4E0D\u5E26 --set \u53EA\u8BFB\uFF0C\u5E26 --set \u53EA\u6539\u76EE\u6807\u73AF\u5883").option("--project <dir>", "HCM \u987E\u95EE\u9879\u76EE\u6839\u76EE\u5F55", ".").requiredOption("--env <name>", "\u76EE\u6807\u73AF\u5883\uFF08\u5FC5\u586B\uFF1B\u4E0D\u7EE7\u627F\u5168\u5C40 activeEnv\uFF09").option("--set <mode>", "\u6539\u4E3A\uFF1Acontrolled | plan-only").option("--approved-by <person>", "\u5207\u5230 controlled \u65F6\u5FC5\u586B\uFF1A\u672C\u6B21\u660E\u786E\u6279\u51C6\u7684\u9879\u76EE\u8D1F\u8D23\u4EBA").option("--reason <text>", "\u5207\u5230 controlled \u65F6\u5FC5\u586B\uFF1A\u672C\u6B21\u5BF9\u8BDD\u6216\u4EFB\u52A1\u4E66\u4E2D\u7684\u6388\u6743\u4F9D\u636E").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((opts) => deliveryModeCommand(opts));
11029
11542
  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));
11030
11543
  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));
11031
11544
  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(
@@ -11092,7 +11605,8 @@ program.command("upload <file>").description("\u4E0A\u4F20\u672C\u5730\u6587\u4E
11092
11605
  ).action((file, opts) => uploadCommand(file, opts));
11093
11606
  var datapackage = program.command("datapackage").description("DataPackage \u5355\u6587\u4EF6\u5236\u54C1\uFF1Apack \u6253\u5305\uFF08\u7EAF\u672C\u5730\uFF09/ install \u4E0A\u4F20\u5B89\u88C5\uFF08\u670D\u52A1\u7AEF\u5B89\u88C5\u5668\uFF09");
11094
11607
  datapackage.command("pack <packageDir>").description("\u628A\u5305\u76EE\u5F55\uFF08\u542B package.yml\uFF09\u6253\u6210 .hcmpkg \u5355\u6587\u4EF6\u5236\u54C1\uFF0C\u4E0D\u8054\u7F51").option("-o, --out <path>", "\u4EA7\u7269\u8DEF\u5F84\uFF08\u7F3A\u7701 <name \u672B\u6BB5>-<version>.hcmpkg\uFF09").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((dir, opts) => datapackagePackCommand(dir, opts));
11095
- datapackage.command("install <artifact>").description("\u4E0A\u4F20 .hcmpkg \u5236\u54C1\u5E76\u7ECF\u670D\u52A1\u7AEF DataPackage.installFromDocument \u5B89\u88C5\uFF08admin.system\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("--category <name>", "\u5236\u54C1\u4E0A\u4F20\u7684\u5B58\u50A8\u5206\u7C7B\uFF08\u670D\u52A1\u7AEF\u6570\u636E\u975E\u679A\u4E3E\uFF09", "attachment").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((artifact, opts) => datapackageInstallCommand(artifact, opts));
11608
+ datapackage.command("install <artifact>").description("\u4E0A\u4F20 .hcmpkg \u5236\u54C1\u5E76\u7ECF\u670D\u52A1\u7AEF\u5F02\u6B65\u5B89\u88C5\u5668\u5B89\u88C5\uFF0C\u5B9E\u65F6\u663E\u793A\u8FDB\u5EA6\uFF08admin.system\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("--category <name>", "\u5236\u54C1\u4E0A\u4F20\u7684\u5B58\u50A8\u5206\u7C7B\uFF08\u670D\u52A1\u7AEF\u6570\u636E\u975E\u679A\u4E3E\uFF09", "attachment").option("--no-wait", "\u53EA\u53D7\u7406\u4E0D\u7B49\u5F85\uFF0C\u7ACB\u523B\u8FD4\u56DE runId").option("--timeout <sec>", "\u7B49\u5F85\u4E0A\u9650\uFF08\u79D2\uFF09\uFF1B\u7B49\u4E0D\u5230\u4E0D\u662F\u5931\u8D25\uFF0C\u88C5\u8F7D\u5728\u670D\u52A1\u7AEF\u7EE7\u7EED", "900").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((artifact, opts) => datapackageInstallCommand(artifact, opts));
11609
+ datapackage.command("status <runId>").description("\u67E5\u770B\u88C5\u8F7D\u6D41\u6C34\u8FDB\u5EA6/\u7EC8\u6001\uFF08\u914D\u5408 install --no-wait \u6216\u7B49\u5F85\u8D85\u65F6\u540E\u4F7F\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").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((runId, opts) => datapackageStatusCommand(runId, opts));
11096
11610
  var tenant = program.command("tenant").description("\u79DF\u6237\u5F00\u901A\u4E0E\u751F\u547D\u5468\u671F");
11097
11611
  tenant.command("bootstrap").description("\u5F00\u901A\u65B0\u79DF\u6237\uFF08\u5EFA\u79DF\u6237 + admin \u7528\u6237 + \u7ED3\u6784 reconcile\uFF09\u2014\u2014\u4E0D\u53EF\u9006\uFF0C\u9ED8\u8BA4\u8FC7\u786E\u8BA4\u95F8").requiredOption("--tenant-id <id>", "\u79DF\u6237 ID").requiredOption("--admin-username <user>", "\u7BA1\u7406\u5458\u7528\u6237\u540D").option("--admin-password <pwd>", "\u7BA1\u7406\u5458\u5BC6\u7801\uFF08\u4F1A\u6CC4\u6F0F\u5230 history/ps\uFF0C\u5EFA\u8BAE --admin-password-stdin\uFF09").option("--admin-password-stdin", "\u4ECE\u6807\u51C6\u8F93\u5165\u8BFB\u7BA1\u7406\u5458\u5BC6\u7801\uFF08\u63A8\u8350\uFF09").option("--tenant-name <name>", "\u79DF\u6237\u540D\u79F0\uFF08\u9ED8\u8BA4\u53D6 tenantId\uFF09").option("--bootstrap-key <key>", "bootstrap \u5BC6\u94A5\uFF08\u5EFA\u8BAE\u7528 HCM_BOOTSTRAP_KEY \u73AF\u5883\u53D8\u91CF\uFF09").option("--bootstrap-key-stdin", "\u4ECE\u6807\u51C6\u8F93\u5165\u8BFB bootstrap \u5BC6\u94A5").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("-y, --yes", "\u8DF3\u8FC7\u786E\u8BA4\uFF08CI \u7528\uFF09").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((opts) => tenantBootstrapCommand(opts));
11098
11612
  var meta = program.command("meta").description("\u79DF\u6237\u5143\u6570\u636E\u8BFB\u5199\uFF08\u9875\u9762/\u5B57\u6BB5/\u5217\u8868\u914D\u7F6E\uFF09");
@@ -11105,12 +11619,12 @@ var skills = program.command("skills").description("\u4EA4\u4ED8\u6280\u80FD\uFF
11105
11619
  skills.command("list [keyword]").description("\u5217\u51FA\u76EE\u6807\u73AF\u5883\u8FD9\u4E00\u7248\u7684\u4EA4\u4ED8\u6280\u80FD\uFF1B--installed \u6539\u770B\u672C\u5730\u88C5\u4E86\u54EA\u4E9B\uFF08\u4E0D\u8FDE\u7F51\uFF09").option("--installed", "\u53EA\u770B\u672C\u5730\u5DF2\u88C5\u7684\u6280\u80FD\uFF08\u8BFB .hcm-skills.json\uFF0C\u4E0D\u8FDE\u7F51\uFF09").option("--target <agent>", "\u914D\u5408 --installed\uFF1Aclaude | codex | auto", "auto").option("--global", "\u914D\u5408 --installed\uFF1A\u770B\u7528\u6237\u7EA7\u76EE\u5F55").option("--dir <path>", "\u914D\u5408 --installed\uFF1A\u770B\u6307\u5B9A\u76EE\u5F55").option("--category <key>", "\u53EA\u770B\u67D0\u4E2A\u5206\u7C7B").option("--stage <key>", "\u53EA\u770B\u67D0\u4E2A\u4EA4\u4ED8\u9636\u6BB5\uFF1Ahandover | baseline | configure | migrate | integrate | golive | operate").option("--by-stage", "\u6309\u4EA4\u4ED8\u751F\u547D\u5468\u671F\u5206\u7EC4\u5C55\u793A\uFF08\u9ED8\u8BA4\u6309\u529F\u80FD\u5206\u7C7B\uFF09").option("--source <kind>", "\u8FD9\u4E00\u8D9F\u770B\u54EA\u4E9B\u6765\u6E90\uFF1Acli\uFF08\u53EA\u770B\u81EA\u5E26\uFF0C\u4E0D\u8FDE\u7F51\uFF09| chiron | all", "all").option("--endpoint <url>", "\u6280\u80FD\u5E93\u5730\u5740\uFF08\u9ED8\u8BA4\u53D6 activeEnv \u7684 endpoint\uFF09").option("--env <name>", "\u4ECE\u8BE5 env \u89E3\u6790 endpoint").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((kw, opts) => skillsListCommand(kw, opts));
11106
11620
  skills.command("manifest").description("\u6253\u5370\u672C CLI \u7684\u547D\u4EE4\u9762\u4E0E\u81EA\u5E26\u6280\u80FD\u6E05\u5355\uFF08\u4E0D\u8FDE\u7F51\uFF0C\u4F9B\u5B88\u536B\u4E0E\u5916\u90E8\u5DE5\u5177\u6BD4\u5BF9\uFF09").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((opts) => skillsManifestCommand(program, opts));
11107
11621
  skills.command("show <id>").description("\u6253\u5370\u6280\u80FD\u539F\u6587\uFF08\u7BA1\u9053\u53CB\u597D\uFF09\uFF1B\u81EA\u5E26\u6280\u80FD\u76F4\u63A5\u8BFB\u672C\u5730\uFF0C\u4E0D\u8FDE\u7F51").option("--source <kind>", "\u8FD9\u4E00\u8D9F\u770B\u54EA\u4E9B\u6765\u6E90\uFF1Acli\uFF08\u53EA\u770B\u81EA\u5E26\uFF0C\u4E0D\u8FDE\u7F51\uFF09| chiron | all", "all").option("--endpoint <url>", "\u6280\u80FD\u5E93\u5730\u5740\uFF08\u9ED8\u8BA4\u53D6 activeEnv \u7684 endpoint\uFF09").option("--env <name>", "\u4ECE\u8BE5 env \u89E3\u6790 endpoint").action((id, opts) => skillsShowCommand(id, opts));
11108
- skills.command("install [id]").description("\u8FDE\u540C requires \u524D\u7F6E\u6280\u80FD\u4E0E\u53C2\u8003\u6587\u4EF6\u88C5\u5230 agent \u6280\u80FD\u76EE\u5F55\uFF1B--all \u88C5\u6574\u4E2A\u6280\u80FD\u5E93").option("--all", "\u88C5\u6574\u4E2A\u6280\u80FD\u5E93\uFF0C\u5E76\u8BB0\u4E3A\u300C\u8DDF\u968F\u5168\u96C6\u300D\uFF08\u5F80\u540E update \u4F1A\u81EA\u52A8\u8865\u4E0A\u4EA7\u54C1\u65B0\u589E\u7684\u6280\u80FD\uFF09").option("--target <agent>", "\u88C5\u7ED9\u54EA\u4E2A agent\uFF1Aclaude\uFF08.claude/skills/\uFF09| codex\uFF08hcm-skills/ + AGENTS.md\uFF09| auto", "auto").option("--global", "\u88C5\u5230\u7528\u6237\u7EA7\u76EE\u5F55\u800C\u975E\u5F53\u524D\u9879\u76EE").option("--dir <path>", "\u88C5\u5230\u6307\u5B9A\u76EE\u5F55").option("--from <dir>", "\u4ECE\u672C\u5730\u76EE\u5F55\u88C5\uFF08\u73B0\u573A\u6539\u8FC7\u7684\u7248\u672C\uFF09\uFF0C\u4E0D\u8D70\u7F51\u7EDC").option("--source <kind>", "\u8FD9\u4E00\u8D9F\u770B\u54EA\u4E9B\u6765\u6E90\uFF1Acli\uFF08\u53EA\u770B\u81EA\u5E26\uFF0C\u4E0D\u8FDE\u7F51\uFF09| chiron | all", "all").option("--force", "\u8986\u76D6\u5DF2\u5B58\u5728\u7684\u540C\u540D\u6280\u80FD").option("--endpoint <url>", "\u6280\u80FD\u5E93\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", "table").action((id, opts) => skillsInstallCommand(id, opts));
11622
+ skills.command("install [id]").description("\u8FDE\u540C requires \u524D\u7F6E\u6280\u80FD\u4E0E\u53C2\u8003\u6587\u4EF6\u88C5\u5230 agent \u6280\u80FD\u76EE\u5F55\uFF1B--all \u88C5\u6574\u4E2A\u6280\u80FD\u5E93").option("--all", "\u88C5\u6574\u4E2A\u6280\u80FD\u5E93\uFF0C\u5E76\u8BB0\u4E3A\u300C\u8DDF\u968F\u5168\u96C6\u300D\uFF08\u5F80\u540E update \u4F1A\u81EA\u52A8\u8865\u4E0A\u4EA7\u54C1\u65B0\u589E\u7684\u6280\u80FD\uFF09").option("--target <agent>", "\u88C5\u7ED9\u54EA\u4E2A agent\uFF1Aclaude\uFF08.claude/skills/\uFF09| codex\uFF08hcm-skills/ + Agent \u7D22\u5F15\uFF09| auto", "auto").option("--global", "\u88C5\u5230\u7528\u6237\u7EA7\u76EE\u5F55\u800C\u975E\u5F53\u524D\u9879\u76EE").option("--dir <path>", "\u88C5\u5230\u6307\u5B9A\u76EE\u5F55").option("--from <dir>", "\u4ECE\u672C\u5730\u76EE\u5F55\u88C5\uFF08\u73B0\u573A\u6539\u8FC7\u7684\u7248\u672C\uFF09\uFF0C\u4E0D\u8D70\u7F51\u7EDC").option("--source <kind>", "\u8FD9\u4E00\u8D9F\u770B\u54EA\u4E9B\u6765\u6E90\uFF1Acli\uFF08\u53EA\u770B\u81EA\u5E26\uFF0C\u4E0D\u8FDE\u7F51\uFF09| chiron | all", "all").option("--force", "\u8986\u76D6\u5DF2\u5B58\u5728\u7684\u540C\u540D\u6280\u80FD").option("--endpoint <url>", "\u6280\u80FD\u5E93\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", "table").action((id, opts) => skillsInstallCommand(id, opts));
11109
11623
  skills.command("update").description("\u628A\u88C5\u8FC7\u7684\u6280\u80FD\u5347\u5230\u76EE\u6807\u73AF\u5883\u8FD9\u4E00\u7248\uFF08\u4EA7\u54C1\u5347\u7EA7\u540E\u8DD1\u5B83\uFF09").option("--all", "\u8FDE\u4EA7\u54C1\u65B0\u589E\u7684\u6280\u80FD\u4E00\u8D77\u88C5\u4E0A\uFF0C\u5E76\u8BB0\u4E3A\u300C\u8DDF\u968F\u5168\u96C6\u300D").option("--check", "\u53EA\u770B\u4F1A\u53D8\u4EC0\u4E48\uFF0C\u4E0D\u5199\u76D8").option("--target <agent>", "claude | codex | auto\uFF08\u9ED8\u8BA4\u6309\u5DF2\u5B89\u88C5\u76EE\u5F55\u63A2\uFF09", "auto").option("--global", "\u5347\u7EA7\u7528\u6237\u7EA7\u76EE\u5F55\u91CC\u7684\u6280\u80FD").option("--dir <path>", "\u5347\u7EA7\u6307\u5B9A\u76EE\u5F55\u91CC\u7684\u6280\u80FD").option("--force", "\u8FDE\u672C\u5730\u6539\u8FC7\u7684\u6280\u80FD\u4E00\u8D77\u8986\u76D6\u6210\u4EA7\u54C1\u8FD9\u4E00\u7248").option("--source <kind>", "\u8FD9\u4E00\u8D9F\u770B\u54EA\u4E9B\u6765\u6E90\uFF1Acli\uFF08\u53EA\u770B\u81EA\u5E26\uFF0C\u4E0D\u8FDE\u7F51\uFF09| chiron | all", "all").option("--endpoint <url>", "\u6280\u80FD\u5E93\u5730\u5740\uFF08\u9ED8\u8BA4\u53D6\u5B89\u88C5\u65F6\u8BB0\u5F55\u7684\u5730\u5740\uFF09").option("--env <name>", "\u4ECE\u8BE5 env \u89E3\u6790 endpoint").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((opts) => skillsUpdateCommand(opts));
11110
11624
  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));
11111
11625
  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));
11112
11626
  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));
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));
11627
+ program.command("open [path]").description("\u7528\u5F53\u524D CLI \u8EAB\u4EFD\u6253\u5F00\u524D\u7AEF\u9875\u9762\uFF1A\u94F8\u4E00\u5F20 60s \u4E00\u6B21\u6027\u7968\u636E\u4EA4\u7ED9\u6D4F\u89C8\u5668\uFF0C\u4F1A\u8BDD token \u4E0D\u8FDB URL").option("--print-url", "\u53EA\u6253\u5370\u767B\u5F55 URL\uFF0C\u4E0D\u5F00\u6D4F\u89C8\u5668\uFF08\u7ED9 agent \u6D4F\u89C8\u5668 navigate \u7528\uFF09").option("--env <name>", "\u4E34\u65F6\u5207\u73AF\u5883\uFF08\u8986\u76D6 activeEnv\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD\uFF08\u8986\u76D6 env defaultIdentity\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--profile <name>", "[deprecated] \u7528 --env \u66FF\u4EE3").action((path14, opts) => openCommand(path14, opts));
11114
11628
  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");
11115
11629
  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));
11116
11630
  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));