@hcmai/cli 0.4.21 → 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"() {
@@ -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,7 +2293,7 @@ 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) {
@@ -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
  }
@@ -2880,7 +2877,8 @@ async function createCommand(model, args) {
2880
2877
  const fmt = args.output ?? "json";
2881
2878
  if (fmt !== "json") process.stdout.write("\u2705 created\n");
2882
2879
  process.stdout.write(formatObject2(res, { format: fmt }) + "\n");
2883
- process.exit(0);
2880
+ process.exitCode = 0;
2881
+ return;
2884
2882
  } catch (e) {
2885
2883
  const err = e;
2886
2884
  if (err?.isAxiosError) exitWithError(fromAxiosError3(err, args.profile));
@@ -2915,7 +2913,8 @@ async function updateCommand(model, args) {
2915
2913
  if (fmt !== "json") process.stdout.write(`\u2705 ${model}#${args.id} \u5DF2\u66F4\u65B0
2916
2914
  `);
2917
2915
  process.stdout.write(formatObject3(result, { format: fmt }) + "\n");
2918
- process.exit(0);
2916
+ process.exitCode = 0;
2917
+ return;
2919
2918
  } catch (e) {
2920
2919
  const err = e;
2921
2920
  if (err?.isAxiosError) exitWithError(fromAxiosError4(err, args.env));
@@ -2967,7 +2966,8 @@ async function settingGetCommand(domain, args) {
2967
2966
  } else {
2968
2967
  process.stdout.write(formatObject4(items, { format: fmt }) + "\n");
2969
2968
  }
2970
- process.exit(0);
2969
+ process.exitCode = 0;
2970
+ return;
2971
2971
  } catch (e) {
2972
2972
  fail(e, args);
2973
2973
  }
@@ -2992,7 +2992,8 @@ async function settingSetCommand(domain, args) {
2992
2992
  `);
2993
2993
  for (const i of items) process.stdout.write(` ${i.namespace}.${i.settingKey} = ${String(i.value)}
2994
2994
  `);
2995
- process.exit(0);
2995
+ process.exitCode = 0;
2996
+ return;
2996
2997
  }
2997
2998
  const c = await client(args);
2998
2999
  const result = await patchSettingDomain(c.raw(), domain, items);
@@ -3000,7 +3001,8 @@ async function settingSetCommand(domain, args) {
3000
3001
  if (fmt !== "json") process.stdout.write(`\u2705 ${domain} \u5DF2\u66F4\u65B0 ${items.length} \u9879
3001
3002
  `);
3002
3003
  process.stdout.write(formatObject4(result, { format: fmt }) + "\n");
3003
- process.exit(0);
3004
+ process.exitCode = 0;
3005
+ return;
3004
3006
  } catch (e) {
3005
3007
  fail(e, args);
3006
3008
  }
@@ -3021,7 +3023,8 @@ async function settingResetCommand(domain, namespace, key2, args) {
3021
3023
  if (fmt !== "json") process.stdout.write(`\u2705 ${namespace}.${key2} \u5DF2\u56DE\u843D\u5230\u9ED8\u8BA4\u503C
3022
3024
  `);
3023
3025
  process.stdout.write(formatObject4(result, { format: fmt }) + "\n");
3024
- process.exit(0);
3026
+ process.exitCode = 0;
3027
+ return;
3025
3028
  } catch (e) {
3026
3029
  fail(e, args);
3027
3030
  }
@@ -3067,7 +3070,8 @@ async function versionCommand(args) {
3067
3070
  process.stdout.write(
3068
3071
  formatObject5({ cli: CLI_VERSION, backend: info }, { format: fmt }) + "\n"
3069
3072
  );
3070
- process.exit(0);
3073
+ process.exitCode = 0;
3074
+ return;
3071
3075
  } catch (e) {
3072
3076
  const err = e;
3073
3077
  if (err?.isAxiosError) exitWithError(fromAxiosError6(err, args.env));
@@ -3117,7 +3121,8 @@ async function upgradeCommand(args) {
3117
3121
  } else if (latest === CLI_VERSION) {
3118
3122
  lines.push(`\u6700\u65B0\u7248\u672C\uFF1A${latest} \u2014\u2014 \u5DF2\u662F\u6700\u65B0\uFF0C\u65E0\u9700\u5347\u7EA7`);
3119
3123
  process.stdout.write(lines.join("\n") + "\n");
3120
- process.exit(0);
3124
+ process.exitCode = 0;
3125
+ return;
3121
3126
  } else {
3122
3127
  lines.push(`\u6700\u65B0\u7248\u672C\uFF1A${latest}`);
3123
3128
  }
@@ -3130,7 +3135,8 @@ async function upgradeCommand(args) {
3130
3135
  lines.push("");
3131
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");
3132
3137
  process.stdout.write(lines.join("\n") + "\n");
3133
- 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;
3134
3140
  }
3135
3141
 
3136
3142
  // src/commands/open.ts
@@ -3229,7 +3235,8 @@ async function openCommand(target, args) {
3229
3235
  write: (line) => process.stdout.write(line)
3230
3236
  }
3231
3237
  );
3232
- process.exit(0);
3238
+ process.exitCode = 0;
3239
+ return;
3233
3240
  } catch (e) {
3234
3241
  exitWithError(e);
3235
3242
  }
@@ -3255,7 +3262,8 @@ async function deleteCommand(model, args) {
3255
3262
  const fmt = args.output ?? "json";
3256
3263
  if (fmt !== "json") process.stdout.write("\u2705 deleted\n");
3257
3264
  process.stdout.write(formatObject6(res, { format: fmt }) + "\n");
3258
- process.exit(0);
3265
+ process.exitCode = 0;
3266
+ return;
3259
3267
  } catch (e) {
3260
3268
  const err = e;
3261
3269
  if (err?.isAxiosError) exitWithError(fromAxiosError8(err, args.profile));
@@ -3314,7 +3322,8 @@ async function importCommand(path14, args) {
3314
3322
  `
3315
3323
  );
3316
3324
  process.stdout.write(formatObject7(result, { format: fmt }) + "\n");
3317
- process.exit(result.failed > 0 ? 3 : 0);
3325
+ process.exitCode = result.failed > 0 ? 3 : 0;
3326
+ return;
3318
3327
  } catch (e) {
3319
3328
  const err = e;
3320
3329
  if (err?.isAxiosError) exitWithError(fromAxiosError9(err, args.profile));
@@ -3337,10 +3346,12 @@ async function describeCommand(model, args) {
3337
3346
  const fmt = args.output ?? "table";
3338
3347
  if (fmt !== "table") {
3339
3348
  process.stdout.write(formatObject8(desc, { format: fmt }) + "\n");
3340
- process.exit(0);
3349
+ process.exitCode = 0;
3350
+ return;
3341
3351
  }
3342
3352
  process.stdout.write(formatDescriptionTable(desc, !!args.verbose) + "\n");
3343
- process.exit(0);
3353
+ process.exitCode = 0;
3354
+ return;
3344
3355
  } catch (e) {
3345
3356
  const err = e;
3346
3357
  if (err?.isAxiosError) {
@@ -3357,7 +3368,13 @@ function formatDescriptionTable(desc, verbose = false) {
3357
3368
  for (const f of desc.fields) {
3358
3369
  const req = f.required ? " required" : " ";
3359
3370
  const lbl = verbose ? ` ${f.label ?? ""} ${f.description ?? ""}` : ` ${f.label ?? ""}`;
3360
- 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
+ );
3361
3378
  }
3362
3379
  lines.push(`actions (${desc.actions.length}):`);
3363
3380
  for (const a of desc.actions) {
@@ -3642,7 +3659,8 @@ async function chatCommand(prompt, args) {
3642
3659
  });
3643
3660
  }
3644
3661
  await printConversationList(args);
3645
- process.exit(0);
3662
+ process.exitCode = 0;
3663
+ return;
3646
3664
  }
3647
3665
  const eventsConversationId = resolveEventsConversation(args);
3648
3666
  if (eventsConversationId) {
@@ -3653,7 +3671,8 @@ async function chatCommand(prompt, args) {
3653
3671
  });
3654
3672
  }
3655
3673
  await printConversationEvents(eventsConversationId, args);
3656
- process.exit(0);
3674
+ process.exitCode = 0;
3675
+ return;
3657
3676
  }
3658
3677
  let regenerateFromSeq;
3659
3678
  let regenerateFromLastAssistant = false;
@@ -3853,7 +3872,8 @@ async function chatCommand(prompt, args) {
3853
3872
  resolve4();
3854
3873
  }
3855
3874
  });
3856
- process.exit(0);
3875
+ process.exitCode = 0;
3876
+ return;
3857
3877
  }
3858
3878
  const { resolveInteraction: resolveInteraction2 } = await Promise.resolve().then(() => (init_control_prompt(), control_prompt_exports));
3859
3879
  const { readLineFromStdin: readLineFromStdin2 } = await Promise.resolve().then(() => (init_readline(), readline_exports));
@@ -3924,7 +3944,8 @@ async function chatCommand(prompt, args) {
3924
3944
  resolve4();
3925
3945
  }
3926
3946
  });
3927
- process.exit(result.status === "interrupted" ? 130 : 0);
3947
+ process.exitCode = result.status === "interrupted" ? 130 : 0;
3948
+ return;
3928
3949
  } catch (e) {
3929
3950
  process.removeListener("SIGINT", sigintHandler);
3930
3951
  await ws.close();
@@ -3984,7 +4005,8 @@ async function chatCommand(prompt, args) {
3984
4005
  )
3985
4006
  );
3986
4007
  }
3987
- process.exit(0);
4008
+ process.exitCode = 0;
4009
+ return;
3988
4010
  } catch (e) {
3989
4011
  exitWithError(e);
3990
4012
  }
@@ -4001,7 +4023,8 @@ async function downloadCommand(documentId, args) {
4001
4023
  const client3 = HcmClient12.fromAuthContext(ctx);
4002
4024
  const saved = await downloadDocument(client3.raw(), { documentId }, args.output);
4003
4025
  process.stdout.write(saved + "\n");
4004
- process.exit(0);
4026
+ process.exitCode = 0;
4027
+ return;
4005
4028
  } catch (e) {
4006
4029
  const status = e?.response?.status;
4007
4030
  if (status === 401 || status === 403) {
@@ -4353,10 +4376,12 @@ async function traceCommand(traceId, args) {
4353
4376
  const rows = await fetchLlmTrace(http, convId);
4354
4377
  const fmt = args.raw ? "json" : args.output;
4355
4378
  process.stdout.write(formatObject10(rows, { format: fmt }) + "\n");
4356
- process.exit(0);
4379
+ process.exitCode = 0;
4380
+ return;
4357
4381
  }
4358
4382
  printLlmTraceTree(await gatherLlmTraceTree(http, convId));
4359
- process.exit(0);
4383
+ process.exitCode = 0;
4384
+ return;
4360
4385
  }
4361
4386
  if (!traceId) {
4362
4387
  if (args.events || args.raw || args.span) {
@@ -4364,17 +4389,20 @@ async function traceCommand(traceId, args) {
4364
4389
  return;
4365
4390
  }
4366
4391
  await listRecentTraces(client3, parsePositiveInt2(args.limit, 10, "--limit"));
4367
- process.exit(0);
4392
+ process.exitCode = 0;
4393
+ return;
4368
4394
  }
4369
4395
  const resp = await http.get(`/api/trace/${traceId}`);
4370
4396
  const agg = resp.data ?? {};
4371
4397
  if (args.raw) {
4372
4398
  process.stdout.write(formatObject10(agg, { format: "json" }) + "\n");
4373
- process.exit(0);
4399
+ process.exitCode = 0;
4400
+ return;
4374
4401
  }
4375
4402
  if (args.output === "json" || args.output === "yaml") {
4376
4403
  process.stdout.write(formatObject10(agg, { format: args.output }) + "\n");
4377
- process.exit(0);
4404
+ process.exitCode = 0;
4405
+ return;
4378
4406
  }
4379
4407
  const spans = agg.sources?.tempo?.spans ?? [];
4380
4408
  if (args.span) {
@@ -4384,14 +4412,16 @@ async function traceCommand(traceId, args) {
4384
4412
  return;
4385
4413
  }
4386
4414
  process.stdout.write(formatObject10(spans[idx], { format: "yaml" }) + "\n");
4387
- process.exit(0);
4415
+ process.exitCode = 0;
4416
+ return;
4388
4417
  }
4389
4418
  if (args.events) {
4390
4419
  printTraceEvents(traceId, agg);
4391
4420
  } else {
4392
4421
  printTraceDetail(traceId, agg);
4393
4422
  }
4394
- process.exit(0);
4423
+ process.exitCode = 0;
4424
+ return;
4395
4425
  } catch (e) {
4396
4426
  const err = e;
4397
4427
  if (err?.isAxiosError) {
@@ -4420,7 +4450,8 @@ function emit(result, args, human) {
4420
4450
  const fmt = args.output ?? "json";
4421
4451
  if (fmt !== "json") process.stdout.write(human + "\n");
4422
4452
  process.stdout.write(formatObject11(result, { format: fmt }) + "\n");
4423
- process.exit(0);
4453
+ process.exitCode = 0;
4454
+ return;
4424
4455
  }
4425
4456
  function fail2(e, args) {
4426
4457
  const err = e;
@@ -4478,7 +4509,8 @@ function emit2(result, args, human) {
4478
4509
  const fmt = args.output ?? "json";
4479
4510
  if (fmt !== "json") process.stdout.write(human + "\n");
4480
4511
  process.stdout.write(formatObject12(result, { format: fmt }) + "\n");
4481
- process.exit(0);
4512
+ process.exitCode = 0;
4513
+ return;
4482
4514
  }
4483
4515
  function fail3(e, args) {
4484
4516
  const err = e;
@@ -4595,7 +4627,8 @@ async function uploadCommand(filePath, args) {
4595
4627
  );
4596
4628
  }
4597
4629
  process.stdout.write(formatObject13(meta2, { format: fmt }) + "\n");
4598
- process.exit(0);
4630
+ process.exitCode = 0;
4631
+ return;
4599
4632
  } catch (e) {
4600
4633
  const err = e;
4601
4634
  const status = err?.response?.status;
@@ -4619,13 +4652,23 @@ import {
4619
4652
  formatObject as formatObject14,
4620
4653
  fromAxiosError as fromAxiosError15,
4621
4654
  packDataPackage,
4622
- installDataPackageArtifact,
4655
+ installDataPackageArtifactAsync,
4656
+ waitForInstallRun,
4657
+ fetchInstallRun,
4658
+ isTerminalRunStatus,
4623
4659
  DEFAULT_ARTIFACT_CATEGORY
4624
4660
  } from "@hcmai/sdk";
4661
+ var DEFAULT_INSTALL_WAIT_SECONDS = 900;
4625
4662
  async function datapackagePackCommand(packageDir, args) {
4626
4663
  try {
4627
- const result = await packDataPackage(packageDir, args.out);
4628
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
+ });
4629
4672
  if (fmt !== "json") {
4630
4673
  process.stdout.write(
4631
4674
  `\u{1F4E6} ${result.name} v${result.version}\uFF08${result.entryCount} \u4E2A\u6587\u4EF6\uFF09\u2192 ${result.artifactPath}
@@ -4633,7 +4676,8 @@ async function datapackagePackCommand(packageDir, args) {
4633
4676
  );
4634
4677
  }
4635
4678
  process.stdout.write(formatObject14(result, { format: fmt }) + "\n");
4636
- process.exit(0);
4679
+ process.exitCode = 0;
4680
+ return;
4637
4681
  } catch (e) {
4638
4682
  exitWithError(e);
4639
4683
  }
@@ -4642,22 +4686,68 @@ async function datapackageInstallCommand(artifactPath, args) {
4642
4686
  try {
4643
4687
  const ctx = await getActiveAuthContextFromCli(args);
4644
4688
  const client3 = HcmClient17.fromAuthContext(ctx);
4645
- 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, {
4646
4692
  category: args.category ?? DEFAULT_ARTIFACT_CATEGORY
4647
4693
  });
4648
- const fmt = args.output ?? "json";
4649
- if (fmt !== "json") {
4694
+ if (human) {
4650
4695
  process.stdout.write(
4651
- `\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
4652
4697
  `
4653
4698
  );
4654
- if (view.replayNotice) {
4655
- process.stdout.write(`\u26A0\uFE0F ${view.replayNotice}
4656
- `);
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
+ );
4657
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;
4658
4738
  }
4659
- process.stdout.write(formatObject14(view, { format: fmt }) + "\n");
4660
- process.exit(0);
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
+ `);
4747
+ }
4748
+ emit3({ ...run ?? {}, runId: accepted.runId, documentId: accepted.documentId }, fmt);
4749
+ process.exitCode = failed2 ? 1 : 0;
4750
+ return;
4661
4751
  } catch (e) {
4662
4752
  const err = e;
4663
4753
  if (err?.code === "ENOENT") {
@@ -4669,6 +4759,51 @@ async function datapackageInstallCommand(artifactPath, args) {
4669
4759
  }
4670
4760
  }
4671
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
+ }
4672
4807
 
4673
4808
  // src/commands/skills.ts
4674
4809
  init_exit();
@@ -5156,14 +5291,16 @@ async function skillsListCommand(keyword, args) {
5156
5291
  { format: fmt }
5157
5292
  ) + "\n"
5158
5293
  );
5159
- process.exit(0);
5294
+ process.exitCode = 0;
5295
+ return;
5160
5296
  }
5161
5297
  const shown = cats.flatMap((c) => c.skills);
5162
5298
  const total = (manifest2?.skillCount ?? 0) + catalog.cli.entries.size;
5163
5299
  if (shown.length === 0) {
5164
5300
  process.stdout.write(`\u6CA1\u6709\u5339\u914D\u7684\u6280\u80FD\uFF08\u8FD9\u4E00\u8D9F\u770B\u7684\u6765\u6E90\u5171 ${total} \u4E2A\uFF09
5165
5301
  `);
5166
- process.exit(0);
5302
+ process.exitCode = 0;
5303
+ return;
5167
5304
  }
5168
5305
  process.stdout.write(`${manifest2?.title ?? "HCM \u6280\u80FD"} \u2014 ${endpoint ?? `@hcmai/cli@${CLI_VERSION}`}
5169
5306
 
@@ -5198,7 +5335,8 @@ async function skillsListCommand(keyword, args) {
5198
5335
  `);
5199
5336
  process.stdout.write(` \u88C5\u4E00\u4E2A\uFF1Ahcm skills install <id>
5200
5337
  `);
5201
- process.exit(0);
5338
+ process.exitCode = 0;
5339
+ return;
5202
5340
  }
5203
5341
  for (const c of cats) {
5204
5342
  process.stdout.write(` ${c.name}
@@ -5214,7 +5352,8 @@ async function skillsListCommand(keyword, args) {
5214
5352
  `);
5215
5353
  process.stdout.write(` \u88C5\u4E00\u4E2A\uFF1Ahcm skills install <id>
5216
5354
  `);
5217
- process.exit(0);
5355
+ process.exitCode = 0;
5356
+ return;
5218
5357
  } catch (e) {
5219
5358
  fail4(e, args);
5220
5359
  }
@@ -5226,12 +5365,14 @@ async function listInstalledSkills(keyword, args) {
5226
5365
  if (!state || Object.keys(state.skills).length === 0) {
5227
5366
  if (fmt === "json" || fmt === "yaml") {
5228
5367
  process.stdout.write(formatObject16({ baseDir: layout.baseDir, target: layout.target, all: false, skills: [] }, { format: fmt }) + "\n");
5229
- process.exit(0);
5368
+ process.exitCode = 0;
5369
+ return;
5230
5370
  }
5231
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
5232
5372
  `);
5233
5373
  process.stdout.write(" \u88C5\u5168\u90E8\uFF1Ahcm skills install --all\n");
5234
- process.exit(0);
5374
+ process.exitCode = 0;
5375
+ return;
5235
5376
  }
5236
5377
  const rows = [];
5237
5378
  for (const [id, record] of Object.entries(state.skills).sort(([a], [b]) => a.localeCompare(b))) {
@@ -5272,7 +5413,8 @@ async function listInstalledSkills(keyword, args) {
5272
5413
  },
5273
5414
  skills: shown
5274
5415
  }, { format: fmt }) + "\n");
5275
- process.exit(0);
5416
+ process.exitCode = 0;
5417
+ return;
5276
5418
  }
5277
5419
  process.stdout.write(`\u5DF2\u5B89\u88C5\u7684\u6280\u80FD \u2014 ${layout.baseDir}\uFF08${layout.target}\uFF09
5278
5420
  `);
@@ -5280,7 +5422,8 @@ async function listInstalledSkills(keyword, args) {
5280
5422
  if (shown.length === 0) {
5281
5423
  process.stdout.write(` \u6CA1\u6709\u5339\u914D\u300C${keyword}\u300D\u7684\u6280\u80FD\uFF08\u5171\u88C5\u4E86 ${rows.length} \u4E2A\uFF09
5282
5424
  `);
5283
- process.exit(0);
5425
+ process.exitCode = 0;
5426
+ return;
5284
5427
  }
5285
5428
  for (const kind of ["chiron", "cli", "local"]) {
5286
5429
  const group = shown.filter((row) => row.sourceKind === kind);
@@ -5308,7 +5451,8 @@ async function listInstalledSkills(keyword, args) {
5308
5451
  ].filter(Boolean).map((t) => `\uFF0C${t}`).join("") + "\n");
5309
5452
  process.stdout.write(` \u5347\u7EA7\uFF1Ahcm skills update${state.all ? "" : "\uFF08\u60F3\u8DDF\u968F\u5168\u96C6\u52A0 --all\uFF09"}
5310
5453
  `);
5311
- process.exit(0);
5454
+ process.exitCode = 0;
5455
+ return;
5312
5456
  }
5313
5457
  async function skillsShowCommand(id, args) {
5314
5458
  try {
@@ -5317,7 +5461,8 @@ async function skillsShowCommand(id, args) {
5317
5461
  if (source !== "chiron" && listBundledSkills().some((s) => s.id === id)) {
5318
5462
  const document = await readBundledSkillDocument(id);
5319
5463
  process.stdout.write(document.markdown.endsWith("\n") ? document.markdown : document.markdown + "\n");
5320
- process.exit(0);
5464
+ process.exitCode = 0;
5465
+ return;
5321
5466
  }
5322
5467
  if (source === "cli") {
5323
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`);
@@ -5325,7 +5470,8 @@ async function skillsShowCommand(id, args) {
5325
5470
  const { http, base } = await chironClient(args);
5326
5471
  const md = await fetchSkillMarkdown(http, id, base);
5327
5472
  process.stdout.write(md.endsWith("\n") ? md : md + "\n");
5328
- process.exit(0);
5473
+ process.exitCode = 0;
5474
+ return;
5329
5475
  } catch (e) {
5330
5476
  fail4(e, args);
5331
5477
  }
@@ -5489,7 +5635,8 @@ async function skillsInstallCommand(id, args) {
5489
5635
  `);
5490
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");
5491
5637
  }
5492
- process.exit(0);
5638
+ process.exitCode = 0;
5639
+ return;
5493
5640
  } catch (e) {
5494
5641
  fail4(e, args);
5495
5642
  }
@@ -6044,7 +6191,8 @@ async function skillsUpdateCommand(args) {
6044
6191
  staleReferences: stale,
6045
6192
  entries: plan.entries
6046
6193
  }, { format: fmt }) + "\n");
6047
- process.exit(0);
6194
+ process.exitCode = 0;
6195
+ return;
6048
6196
  }
6049
6197
  process.stdout.write(`\u6280\u80FD\u5347\u7EA7 \u2014 ${source === "cli" ? `@hcmai/cli@${CLI_VERSION}\uFF08\u672A\u8FDE\u7F51\uFF09` : endpoint}
6050
6198
  `);
@@ -6098,7 +6246,8 @@ async function skillsUpdateCommand(args) {
6098
6246
  process.stdout.write(` ${[head, tail].filter(Boolean).join("\uFF1B")}
6099
6247
  `);
6100
6248
  }
6101
- process.exit(0);
6249
+ process.exitCode = 0;
6250
+ return;
6102
6251
  } catch (e) {
6103
6252
  fail4(e, args);
6104
6253
  }
@@ -6201,7 +6350,8 @@ async function tenantBootstrapCommand(args) {
6201
6350
  );
6202
6351
  }
6203
6352
  process.stdout.write(formatObject17(result, { format: fmt }) + "\n");
6204
- process.exit(0);
6353
+ process.exitCode = 0;
6354
+ return;
6205
6355
  } catch (e) {
6206
6356
  const err = e;
6207
6357
  if (err?.response?.status === 403) {
@@ -6263,7 +6413,8 @@ async function metaListCommand(args) {
6263
6413
  if (fmt !== "json") process.stdout.write(`\u{1F4C4} ${items.length} \u4EFD${total ? ` / \u5171 ${total}` : ""}
6264
6414
  `);
6265
6415
  process.stdout.write(formatObject18(items, { format: fmt }) + "\n");
6266
- process.exit(0);
6416
+ process.exitCode = 0;
6417
+ return;
6267
6418
  } catch (e) {
6268
6419
  fail5(e, args);
6269
6420
  }
@@ -6273,7 +6424,8 @@ async function metaGetCommand(path14, args) {
6273
6424
  const c = await client2(args);
6274
6425
  const content = await getTenantMeta(c.raw(), path14);
6275
6426
  process.stdout.write(content.endsWith("\n") ? content : content + "\n");
6276
- process.exit(0);
6427
+ process.exitCode = 0;
6428
+ return;
6277
6429
  } catch (e) {
6278
6430
  fail5(e, args);
6279
6431
  }
@@ -6394,7 +6546,8 @@ ${content}
6394
6546
  `
6395
6547
  );
6396
6548
  }
6397
- process.exit(0);
6549
+ process.exitCode = 0;
6550
+ return;
6398
6551
  }
6399
6552
  const c = await client2(args);
6400
6553
  let backupFile;
@@ -6463,7 +6616,8 @@ ${content}
6463
6616
  }
6464
6617
  }
6465
6618
  process.stdout.write(formatObject18(result, { format: fmt }) + "\n");
6466
- process.exit(0);
6619
+ process.exitCode = 0;
6620
+ return;
6467
6621
  } catch (e) {
6468
6622
  if (e.code === "ENOENT") exitWithError(new Error(`\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${args.file}`));
6469
6623
  fail5(e, args);
@@ -6484,7 +6638,8 @@ async function metaDeleteCommand(path14, args) {
6484
6638
  if (fmt !== "json") process.stdout.write(`\u{1F5D1}\uFE0F \u5DF2\u5220\u9664 ${path14}
6485
6639
  `);
6486
6640
  process.stdout.write(formatObject18(result, { format: fmt }) + "\n");
6487
- process.exit(0);
6641
+ process.exitCode = 0;
6642
+ return;
6488
6643
  } catch (e) {
6489
6644
  fail5(e, args);
6490
6645
  }
@@ -6529,7 +6684,8 @@ async function metaValidateCommand(path14, args) {
6529
6684
  result.issues.length === 0 ? " \u6CA1\u6709\u53D1\u73B0\u95EE\u9898\u3002\n" : formatMetaIssues(result, " ") + "\n"
6530
6685
  );
6531
6686
  }
6532
- process.exit(result.errors.length > 0 ? 1 : 0);
6687
+ process.exitCode = result.errors.length > 0 ? 1 : 0;
6688
+ return;
6533
6689
  } catch (e) {
6534
6690
  if (e.code === "ENOENT") exitWithError(new Error(`\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${args.file}`));
6535
6691
  fail5(e, args);
@@ -6625,7 +6781,8 @@ async function workspaceListCommand(args) {
6625
6781
  limit
6626
6782
  });
6627
6783
  writeWorkspaceListResult(result.rows, args.output ?? "table", result.total);
6628
- process.exit(0);
6784
+ process.exitCode = 0;
6785
+ return;
6629
6786
  } catch (e) {
6630
6787
  exitWorkspaceError(e, args.env ?? args.profile);
6631
6788
  }
@@ -6654,7 +6811,8 @@ async function workspaceActiveCommand(args) {
6654
6811
  rootDir
6655
6812
  };
6656
6813
  writeWorkspaceActiveResult(view, args.output ?? "table");
6657
- process.exit(0);
6814
+ process.exitCode = 0;
6815
+ return;
6658
6816
  } catch (e) {
6659
6817
  exitWorkspaceError(e, args.env ?? args.profile);
6660
6818
  }
@@ -6678,7 +6836,8 @@ async function workspaceBindCommand(workspaceKey, args) {
6678
6836
  await fs5.mkdir(rootDir, { recursive: true });
6679
6837
  await writeWorkspaceContext(rootDir, context);
6680
6838
  writeWorkspaceBindResult(context, rootDir, args.output ?? "table");
6681
- process.exit(0);
6839
+ process.exitCode = 0;
6840
+ return;
6682
6841
  } catch (e) {
6683
6842
  exitWorkspaceError(e, args.env ?? args.profile);
6684
6843
  }
@@ -6724,7 +6883,8 @@ async function workspaceCreateCommand(workspaceKey, args) {
6724
6883
  },
6725
6884
  args.output ?? "table"
6726
6885
  );
6727
- process.exit(0);
6886
+ process.exitCode = 0;
6887
+ return;
6728
6888
  } catch (e) {
6729
6889
  exitWorkspaceError(e, args.env ?? args.profile);
6730
6890
  }
@@ -6797,7 +6957,8 @@ async function workspacePullCommand(args) {
6797
6957
  },
6798
6958
  args.output ?? "table"
6799
6959
  );
6800
- process.exit(0);
6960
+ process.exitCode = 0;
6961
+ return;
6801
6962
  } catch (e) {
6802
6963
  exitWorkspaceError(e, args.env ?? args.profile);
6803
6964
  }
@@ -6838,7 +6999,8 @@ async function workspaceAddMiniCommand(appCode, args) {
6838
6999
  force: !!args.force
6839
7000
  });
6840
7001
  writeWorkspaceAddMiniResult(result, rootDir, args.output ?? "table");
6841
- process.exit(0);
7002
+ process.exitCode = 0;
7003
+ return;
6842
7004
  } catch (e) {
6843
7005
  exitWorkspaceError(e, args.env ?? args.profile);
6844
7006
  }
@@ -6882,7 +7044,8 @@ async function workspaceStatusCommand(args) {
6882
7044
  } else {
6883
7045
  process.stdout.write(formatRows5(rows, { format: "table" }) + "\n");
6884
7046
  }
6885
- process.exit(0);
7047
+ process.exitCode = 0;
7048
+ return;
6886
7049
  } catch (e) {
6887
7050
  exitWorkspaceError(e);
6888
7051
  }
@@ -6896,7 +7059,8 @@ async function workspaceValidateCommand(args) {
6896
7059
  miniApps.map(async (app) => ({ app, result: await validateMiniProject(app.dir) }))
6897
7060
  );
6898
7061
  writeWorkspaceValidateResult(results, args.output ?? "table");
6899
- process.exit(results.every((item) => item.result.valid) ? 0 : 1);
7062
+ process.exitCode = results.every((item) => item.result.valid) ? 0 : 1;
7063
+ return;
6900
7064
  } catch (e) {
6901
7065
  exitWorkspaceError(e);
6902
7066
  }
@@ -6953,9 +7117,8 @@ async function workspacePushCommand(args) {
6953
7117
  if (hint) process.stderr.write(`
6954
7118
  ${hint}
6955
7119
  `);
6956
- process.exit(
6957
- rawResult.conflicts.length || results.some((item) => item.result.conflicts.length) ? 3 : 0
6958
- );
7120
+ process.exitCode = rawResult.conflicts.length || results.some((item) => item.result.conflicts.length) ? 3 : 0;
7121
+ return;
6959
7122
  } catch (e) {
6960
7123
  exitWorkspaceError(e, args.env ?? args.profile);
6961
7124
  }
@@ -6985,7 +7148,8 @@ async function workspacePreviewCommand(args) {
6985
7148
  } else {
6986
7149
  process.stdout.write(formatRows5(rows, { format: "table" }) + "\n");
6987
7150
  }
6988
- process.exit(0);
7151
+ process.exitCode = 0;
7152
+ return;
6989
7153
  } catch (e) {
6990
7154
  exitWorkspaceError(e);
6991
7155
  }
@@ -7076,7 +7240,8 @@ async function workspaceVerifyCommand(args) {
7076
7240
  args.output ?? "table"
7077
7241
  );
7078
7242
  const rawOk = !!rawPlan && rawPlan.conflicts.length === 0;
7079
- 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;
7080
7245
  } catch (e) {
7081
7246
  exitWorkspaceError(e, args.env ?? args.profile);
7082
7247
  }
@@ -7891,7 +8056,8 @@ async function workspaceActivateCommand(workspaceKey, args) {
7891
8056
  formatObject19({ workspaceKey: key2, activated: true }, { format: fmt }) + "\n"
7892
8057
  );
7893
8058
  }
7894
- process.exit(0);
8059
+ process.exitCode = 0;
8060
+ return;
7895
8061
  } catch (e) {
7896
8062
  exitWorkspaceError(e, args.env ?? args.profile);
7897
8063
  }
@@ -7955,7 +8121,7 @@ async function inspectIdentity(name, fetcher = fetchAuthInfo) {
7955
8121
  async function identityShow(name, args) {
7956
8122
  try {
7957
8123
  const details = await inspectIdentity(name);
7958
- exitOk(formatObject20(details, { format: args.output ?? "json" }));
8124
+ return exitOk(formatObject20(details, { format: args.output ?? "json" }));
7959
8125
  } catch (e) {
7960
8126
  exitWithError(axios4.isAxiosError(e) ? fromAxiosError20(e, name) : e);
7961
8127
  }
@@ -7966,8 +8132,7 @@ async function identityList(args) {
7966
8132
  const filter = args.env === "all" ? void 0 : args.env ?? g.activeEnv;
7967
8133
  const names = await listIdentities2(filter);
7968
8134
  if (names.length === 0) {
7969
- exitOk("(no identities)");
7970
- return;
8135
+ return exitOk("(no identities)");
7971
8136
  }
7972
8137
  const lines = [];
7973
8138
  for (const n of names) {
@@ -7977,7 +8142,7 @@ async function identityList(args) {
7977
8142
  const expired = meta2.expiresAt && new Date(meta2.expiresAt) < /* @__PURE__ */ new Date() ? " (expired)" : "";
7978
8143
  lines.push(`${isDefault} ${n} scheme=${meta2.scheme} env=${meta2.env}${expired}`);
7979
8144
  }
7980
- exitOk(lines.join("\n"));
8145
+ return exitOk(lines.join("\n"));
7981
8146
  } catch (e) {
7982
8147
  exitWithError(e);
7983
8148
  }
@@ -7993,7 +8158,7 @@ async function identityUse(name) {
7993
8158
  });
7994
8159
  env2.defaultIdentity = name;
7995
8160
  await saveEnv3(meta2.env, env2);
7996
- exitOk(`\u2705 default identity for env '${meta2.env}': ${name}`);
8161
+ return exitOk(`\u2705 default identity for env '${meta2.env}': ${name}`);
7997
8162
  } catch (e) {
7998
8163
  exitWithError(e);
7999
8164
  }
@@ -8015,7 +8180,7 @@ async function identityRemove(name) {
8015
8180
  env2.defaultIdentity = void 0;
8016
8181
  await saveEnv3(meta2.env, env2);
8017
8182
  }
8018
- exitOk(`\u2705 identity '${name}' removed`);
8183
+ return exitOk(`\u2705 identity '${name}' removed`);
8019
8184
  } catch (e) {
8020
8185
  exitWithError(e);
8021
8186
  }
@@ -9444,7 +9609,8 @@ async function deliveryInitCommand(args) {
9444
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"
9445
9610
  };
9446
9611
  process.stdout.write(formatObject22(result, { format: args.output ?? "json" }) + "\n");
9447
- process.exit(0);
9612
+ process.exitCode = 0;
9613
+ return;
9448
9614
  } catch (e) {
9449
9615
  exitWithError(e);
9450
9616
  process.exit(1);
@@ -9481,7 +9647,8 @@ async function deliveryModeCommand(args) {
9481
9647
  { format: args.output ?? "json" }
9482
9648
  ) + "\n"
9483
9649
  );
9484
- process.exit(0);
9650
+ process.exitCode = 0;
9651
+ return;
9485
9652
  }
9486
9653
  const next = args.set;
9487
9654
  if (!DELIVERY_MODES.includes(next)) {
@@ -9497,7 +9664,8 @@ async function deliveryModeCommand(args) {
9497
9664
  process.stdout.write(
9498
9665
  formatObject22(receipt, { format: args.output ?? "json" }) + "\n"
9499
9666
  );
9500
- process.exit(0);
9667
+ process.exitCode = 0;
9668
+ return;
9501
9669
  } catch (e) {
9502
9670
  exitWithError(e);
9503
9671
  process.exit(1);
@@ -9552,7 +9720,8 @@ async function deliveryDoctorCommand(args) {
9552
9720
  const fmt = args.output ?? "json";
9553
9721
  if (fmt !== "json") process.stdout.write(render2(report) + "\n");
9554
9722
  process.stdout.write(formatObject23(report, { format: fmt }) + "\n");
9555
- process.exit(report.ok ? 0 : 1);
9723
+ process.exitCode = report.ok ? 0 : 1;
9724
+ return;
9556
9725
  } catch (e) {
9557
9726
  const err = e;
9558
9727
  if (err?.isAxiosError) exitWithError(fromAxiosError21(err, args.env));
@@ -9609,7 +9778,8 @@ async function deliveryReconRoundCommand(args) {
9609
9778
  exitWithError(e);
9610
9779
  code = 1;
9611
9780
  }
9612
- process.exit(code);
9781
+ process.exitCode = code;
9782
+ return;
9613
9783
  }
9614
9784
 
9615
9785
  // src/commands/delivery-gate0.ts
@@ -9677,7 +9847,8 @@ async function deliveryGate0Command(args) {
9677
9847
  exitWithError(e);
9678
9848
  code = 1;
9679
9849
  }
9680
- process.exit(code);
9850
+ process.exitCode = code;
9851
+ return;
9681
9852
  }
9682
9853
 
9683
9854
  // src/commands/delivery-seed.ts
@@ -10460,7 +10631,8 @@ async function deliveryTriageCommand(args) {
10460
10631
  exitWithError(e);
10461
10632
  code = 1;
10462
10633
  }
10463
- process.exit(code);
10634
+ process.exitCode = code;
10635
+ return;
10464
10636
  }
10465
10637
 
10466
10638
  // src/commands/delivery-execution.ts
@@ -10649,12 +10821,15 @@ async function deliveryExecuteCommand(planId, argv, args) {
10649
10821
  planId,
10650
10822
  argv
10651
10823
  });
10652
- process.stdout.write(formatObject26(receipt, { format: args.output ?? "json" }) + "\n");
10653
- process.exitCode = receipt.exitCode;
10824
+ writeDeliveryExecutionReceipt(receipt, args.output ?? "json");
10654
10825
  } catch (cause) {
10655
10826
  exitWithError(cause);
10656
10827
  }
10657
10828
  }
10829
+ function writeDeliveryExecutionReceipt(receipt, format = "json") {
10830
+ process.stderr.write(formatObject26(receipt, { format }) + "\n");
10831
+ process.exitCode = receipt.exitCode;
10832
+ }
10658
10833
  async function readProjectMode(project, environment) {
10659
10834
  const file = path13.join(project, ".hcm-delivery", "project.yml");
10660
10835
  const content = await readSafeFile(project, file, "\u9879\u76EE\u914D\u7F6E");
@@ -11223,14 +11398,16 @@ async function modelsCommand(keyword, args) {
11223
11398
  const fmt = args.output ?? "table";
11224
11399
  if (fmt !== "table") {
11225
11400
  process.stdout.write(formatObject28({ total: rows.length, models: rows }, { format: fmt }) + "\n");
11226
- process.exit(0);
11401
+ process.exitCode = 0;
11402
+ return;
11227
11403
  }
11228
11404
  if (rows.length === 0) {
11229
11405
  process.stdout.write(
11230
11406
  needle ? `\u6CA1\u6709\u5339\u914D "${keyword}" \u7684 Model\uFF08\u5171 ${all.length} \u4E2A\u53EF\u89C1\uFF09\u3002
11231
11407
  ` : "\u5F53\u524D\u8EAB\u4EFD\u5728\u8FD9\u4E2A\u73AF\u5883\u770B\u4E0D\u5230\u4EFB\u4F55 Model\u3002\n"
11232
11408
  );
11233
- process.exit(0);
11409
+ process.exitCode = 0;
11410
+ return;
11234
11411
  }
11235
11412
  const width = Math.max(...rows.map((m) => key(m).length), 8);
11236
11413
  process.stdout.write(`${"MODEL".padEnd(width)} TYPE
@@ -11243,7 +11420,8 @@ async function modelsCommand(keyword, args) {
11243
11420
  \u5171 ${rows.length} \u4E2A${needle ? `\uFF08\u5168\u90E8 ${all.length} \u4E2A\u4E2D\u5339\u914D\uFF09` : ""}\u3002
11244
11421
  `);
11245
11422
  process.stdout.write("\u4E0B\u4E00\u6B65\uFF1Ahcm describe <Model> \u770B\u5B57\u6BB5\u3001\u5173\u7CFB\u4E0E Action\u3002\n");
11246
- process.exit(0);
11423
+ process.exitCode = 0;
11424
+ return;
11247
11425
  } catch (e) {
11248
11426
  const err = e;
11249
11427
  if (err?.isAxiosError) exitWithError(fromAxiosError24(err, args.profile));
@@ -11427,7 +11605,8 @@ program.command("upload <file>").description("\u4E0A\u4F20\u672C\u5730\u6587\u4E
11427
11605
  ).action((file, opts) => uploadCommand(file, opts));
11428
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");
11429
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));
11430
- 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));
11431
11610
  var tenant = program.command("tenant").description("\u79DF\u6237\u5F00\u901A\u4E0E\u751F\u547D\u5468\u671F");
11432
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));
11433
11612
  var meta = program.command("meta").description("\u79DF\u6237\u5143\u6570\u636E\u8BFB\u5199\uFF08\u9875\u9762/\u5B57\u6BB5/\u5217\u8868\u914D\u7F6E\uFF09");