@hcmai/cli 0.4.25 → 0.4.26

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
@@ -66,6 +66,15 @@ async function ensureActiveAuth(args) {
66
66
  envName
67
67
  );
68
68
  let idMeta = await loadIdentity3(identityName);
69
+ if (idMeta.env !== envName) {
70
+ throw new CliError5({
71
+ code: CliErrorCode4.IDENTITY_NOT_IN_ENV,
72
+ message: `identity '${identityName}' \u5C5E\u4E8E env '${idMeta.env}'\uFF0C\u4E0D\u662F\u5F53\u524D\u7684 '${envName}'\u3002\u7EE7\u7EED\u6267\u884C\u4F1A\u62FF\u7740 '${envName}' \u7684\u5730\u5740\u914D '${idMeta.env}' \u7684\u51ED\u636E\u53D1\u8BF7\u6C42\u3002`,
73
+ context: {
74
+ nextStep: `hcm identity list --env ${envName} \u770B\u8FD9\u4E2A\u73AF\u5883\u6709\u54EA\u4E9B\u8EAB\u4EFD\uFF1B\u6216 hcm login --env ${envName} \u91CD\u767B`
75
+ }
76
+ });
77
+ }
69
78
  const slid = await ensureSessionFresh({
70
79
  endpoint: envCfg.endpoint,
71
80
  identity: identityName,
@@ -1972,7 +1981,6 @@ import {
1972
1981
  loginPairing,
1973
1982
  loginPat,
1974
1983
  loginPassword,
1975
- inferEnvName,
1976
1984
  toOrigin,
1977
1985
  changePassword,
1978
1986
  detectPasswordChangeChallenge,
@@ -1980,8 +1988,12 @@ import {
1980
1988
  saveEnv,
1981
1989
  saveIdentity,
1982
1990
  loadIdentity,
1991
+ listIdentities,
1992
+ deleteIdentity,
1983
1993
  loadGlobalConfig,
1984
1994
  saveGlobalConfig,
1995
+ TEMP_ENV_NAME,
1996
+ isTempEnv,
1985
1997
  TokenStore,
1986
1998
  isServerSlidingSession,
1987
1999
  CliError as CliError2,
@@ -2134,6 +2146,50 @@ async function migrateProfileTokenToIdentity(envName, identityName) {
2134
2146
  throw err;
2135
2147
  }
2136
2148
  }
2149
+ async function discardTempEnvSessions() {
2150
+ const ids = await listIdentities(TEMP_ENV_NAME).catch(() => []);
2151
+ for (const id of ids) {
2152
+ const store = TokenStore.forIdentity(id);
2153
+ const meta2 = await store.readMeta().catch(() => null);
2154
+ const hadServerSession = meta2 != null && isServerSlidingSession(meta2.scheme) && Boolean(meta2.accessTokenRef);
2155
+ const revoked = await revokeOnServer(store, TEMP_ENV_NAME).catch(() => false);
2156
+ if (hadServerSession && !revoked) {
2157
+ process.stderr.write(
2158
+ `[hcm] event=temp_session_revoke_unconfirmed identity=${id} hint="\u4E0A\u4E00\u6761\u4E34\u65F6\u4F1A\u8BDD\u53EF\u80FD\u4ECD\u7136\u6709\u6548\u76F4\u81F3\u81EA\u7136\u8FC7\u671F"
2159
+ `
2160
+ );
2161
+ }
2162
+ await store.clear().catch(() => void 0);
2163
+ await deleteIdentity(id).catch(() => void 0);
2164
+ }
2165
+ }
2166
+ function assertPairingAddressBelongsToEnv(envName, cfg, pairingOrigin) {
2167
+ const originOf = (u) => {
2168
+ if (!u) return null;
2169
+ try {
2170
+ return new URL(u).origin;
2171
+ } catch {
2172
+ return null;
2173
+ }
2174
+ };
2175
+ const endpointOrigin = originOf(cfg.endpoint);
2176
+ const frontendOrigin = originOf(cfg.frontend);
2177
+ if (pairingOrigin === endpointOrigin || pairingOrigin === frontendOrigin) return;
2178
+ if (frontendOrigin) {
2179
+ throw new CliError2({
2180
+ code: CliErrorCode.INVALID_ARGUMENT,
2181
+ message: `env '${envName}' \u7684\u5730\u5740\u662F ${endpointOrigin} / ${frontendOrigin}\uFF0C\u4E0E\u4F60\u7C98\u8D34\u7684 ${pairingOrigin} \u90FD\u4E0D\u5339\u914D\u3002\u914D\u5BF9\u7801\u662F\u4E00\u6B21\u6027\u51ED\u636E\uFF0C\u4E0D\u80FD\u53D1\u5230\u4E00\u53F0\u8FD9\u4E2A env \u4E0D\u8BA4\u8BC6\u7684\u670D\u52A1\u5668\u4E0A\u3002`,
2182
+ context: {
2183
+ nextStep: `\u53BB\u6389 --env ${envName}\uFF08\u672C\u6B21\u4F1A\u843D\u5230\u4E34\u65F6\u73AF\u5883\uFF09\uFF0C\u6216\u6362\u6210\u5730\u5740\u5339\u914D\u7684\u90A3\u4E2A env`
2184
+ }
2185
+ });
2186
+ }
2187
+ process.stderr.write(
2188
+ `[hcm] \u914D\u5BF9\u7801\u5C06\u53D1\u5F80 ${endpointOrigin}\uFF08env '${envName}' \u7684 endpoint\uFF09\uFF0C\u800C\u4F60\u7C98\u8D34\u7684\u662F ${pairingOrigin}\u3002\u8BE5 env \u6CA1\u6709\u8BB0 frontend\uFF0C\u65E0\u6CD5\u6838\u5BF9\u4E24\u8005\u662F\u5426\u540C\u6E90\u3002
2189
+ [hcm] \u5982\u679C\u8FD9\u4E0D\u662F\u4F60\u8981\u7684\uFF0C\u73B0\u5728 Ctrl-C\uFF1B\u6838\u5BF9\u65E0\u8BEF\u53EF\u4EE5 hcm env edit frontend ${pairingOrigin} \u8BB0\u4E0B\u6765\uFF0C\u4EE5\u540E\u5C31\u80FD\u81EA\u52A8\u6838\u5BF9\u3002
2190
+ `
2191
+ );
2192
+ }
2137
2193
  async function loginCommand(args) {
2138
2194
  if (args.profile && args.env) {
2139
2195
  process.stderr.write(
@@ -2147,18 +2203,20 @@ async function loginCommand(args) {
2147
2203
  }
2148
2204
  const g = await loadGlobalConfig();
2149
2205
  const pairingOrigin = args.code ? toOrigin(args.endpointArg ?? args.endpoint ?? "") : null;
2150
- const envName = args.env ?? (pairingOrigin ? inferEnvName(pairingOrigin) : g.activeEnv);
2206
+ const envName = args.env ?? (pairingOrigin ? TEMP_ENV_NAME : g.activeEnv);
2207
+ const usingTempEnv = Boolean(pairingOrigin) && isTempEnv(envName);
2208
+ const previousActiveEnv = g.activeEnv;
2151
2209
  try {
2152
2210
  let envCfg = await loadEnv(envName).catch(() => null);
2153
- if (pairingOrigin && !envCfg) {
2154
- envCfg = { endpoint: pairingOrigin };
2211
+ let tempEnvPending = false;
2212
+ if (pairingOrigin && usingTempEnv) {
2213
+ envCfg = { endpoint: pairingOrigin, frontend: pairingOrigin };
2214
+ tempEnvPending = true;
2215
+ } else if (pairingOrigin && !envCfg) {
2216
+ envCfg = { endpoint: pairingOrigin, frontend: pairingOrigin };
2155
2217
  await saveEnv(envName, envCfg);
2156
- }
2157
- if (pairingOrigin && envCfg && envCfg.endpoint !== pairingOrigin) {
2158
- throw new CliError2({
2159
- code: CliErrorCode.INVALID_ARGUMENT,
2160
- message: `env '${envName}' \u5DF2\u5B58\u5728\u4E14\u6307\u5411 ${envCfg.endpoint}\uFF0C\u4E0E\u672C\u6B21\u7684 ${pairingOrigin} \u4E0D\u540C\u3002\u7528 --env <name> \u663E\u5F0F\u6307\u5B9A\u4E00\u4E2A\u65B0\u540D\u5B57\u3002`
2161
- });
2218
+ } else if (pairingOrigin && envCfg) {
2219
+ assertPairingAddressBelongsToEnv(envName, envCfg, pairingOrigin);
2162
2220
  }
2163
2221
  if (!envCfg) {
2164
2222
  const endpoint2 = args.endpoint ?? await promptText("endpoint: ");
@@ -2194,6 +2252,10 @@ async function loginCommand(args) {
2194
2252
  profile: envName,
2195
2253
  httpClient: http
2196
2254
  });
2255
+ if (tempEnvPending) {
2256
+ await discardTempEnvSessions();
2257
+ await saveEnv(envName, envCfg);
2258
+ }
2197
2259
  scheme = "pairing";
2198
2260
  scopes = record.scopes;
2199
2261
  principal = p;
@@ -2277,17 +2339,24 @@ async function loginCommand(args) {
2277
2339
  ttlSeconds: newMeta?.ttlSeconds
2278
2340
  };
2279
2341
  await saveIdentity(idName, identityMeta);
2280
- if (principal?.tenantId && String(principal.tenantId) !== String(tenantId)) {
2281
- if (args.tenant) {
2342
+ if (principal?.tenantId) {
2343
+ const actualTenant = String(principal.tenantId);
2344
+ const askedTenant = args.tenant ? String(args.tenant) : void 0;
2345
+ const recordedTenant = envCfg.tenantId ? String(envCfg.tenantId) : void 0;
2346
+ if (askedTenant && askedTenant !== actualTenant) {
2282
2347
  process.stderr.write(
2283
- `[hcm] WARNING: \u8BF7\u6C42\u7684\u79DF\u6237\u662F ${tenantId}\uFF0C\u4F46 token \u5B9E\u9645\u5F52\u5C5E\u79DF\u6237 ${principal.tenantId}\u3002\u540E\u7EED\u547D\u4EE4\u6309 ${principal.tenantId} \u6267\u884C\u3002
2348
+ `[hcm] WARNING: \u8BF7\u6C42\u7684\u79DF\u6237\u662F ${askedTenant}\uFF0C\u4F46 token \u5B9E\u9645\u5F52\u5C5E\u79DF\u6237 ${actualTenant}\u3002\u540E\u7EED\u547D\u4EE4\u6309 ${actualTenant} \u6267\u884C\u3002
2284
2349
  `
2285
2350
  );
2286
- } else {
2287
- envCfg.tenantId = String(principal.tenantId);
2351
+ } else if (recordedTenant !== actualTenant) {
2352
+ envCfg.tenantId = actualTenant;
2288
2353
  await saveEnv(envName, envCfg);
2289
- process.stderr.write(`[hcm] env ${envName} \u7684\u79DF\u6237\u5DF2\u8BB0\u4E3A ${principal.tenantId}\uFF08token \u5F52\u5C5E\uFF09\u3002
2290
- `);
2354
+ if (recordedTenant !== void 0) {
2355
+ process.stderr.write(
2356
+ `[hcm] env ${envName} \u7684\u79DF\u6237\u5DF2\u4ECE ${recordedTenant} \u6539\u8BB0\u4E3A ${actualTenant}\uFF08token \u5F52\u5C5E\uFF09\u3002
2357
+ `
2358
+ );
2359
+ }
2291
2360
  }
2292
2361
  }
2293
2362
  const shouldActivate = args.activate !== false;
@@ -2300,9 +2369,16 @@ async function loginCommand(args) {
2300
2369
  gl.activeEnv = envName;
2301
2370
  await saveGlobalConfig(gl);
2302
2371
  }
2303
- return exitOk(
2304
- `\u2705 logged in (env=${envName}, identity=${idName}, scheme=${scheme}, ${describePrincipal(principal)}, scopes=${scopes.join(" ")})`
2305
- );
2372
+ const envLabel = usingTempEnv ? "\u4E34\u65F6\u73AF\u5883(\u672A\u4FDD\u5B58)" : envName;
2373
+ const head = `\u2705 logged in (env=${envLabel}, identity=${idName}, scheme=${scheme}, ${describePrincipal(principal)}, scopes=${scopes.join(" ")})`;
2374
+ if (!usingTempEnv) return exitOk(head);
2375
+ const lines = [head, "", " \u8FD9\u662F\u4E34\u65F6\u73AF\u5883\uFF1A\u4E0B\u6B21 login --code \u4F1A\u76F4\u63A5\u8986\u76D6\u5B83\u3002"];
2376
+ const previousEnvExists = !isTempEnv(previousActiveEnv) && previousActiveEnv !== envName && await loadEnv(previousActiveEnv).catch(() => null) !== null;
2377
+ if (shouldActivate && previousEnvExists) {
2378
+ lines.push(` \u539F\u6765\u7684 activeEnv \u662F '${previousActiveEnv}'\uFF0C\u56DE\u53BB\u7528: hcm env use ${previousActiveEnv}`);
2379
+ }
2380
+ lines.push(" \u60F3\u7559\u7740\u5B83: hcm env save <name>");
2381
+ return exitOk(lines.join("\n"));
2306
2382
  } catch (e) {
2307
2383
  const err = e;
2308
2384
  if (err.isAxiosError) {
@@ -2350,7 +2426,7 @@ async function revokeOnServer(store, envName) {
2350
2426
  try {
2351
2427
  const meta2 = await store.readMeta();
2352
2428
  if (!meta2 || !isServerSlidingSession(meta2.scheme)) return false;
2353
- const token = await store.getAccessToken();
2429
+ const token = await store.getStoredAccessToken();
2354
2430
  if (!token) return false;
2355
2431
  const envCfg = await loadEnv(envName).catch(() => null);
2356
2432
  if (!envCfg?.endpoint) return false;
@@ -2367,6 +2443,7 @@ async function revokeOnServer(store, envName) {
2367
2443
 
2368
2444
  // src/commands/config.ts
2369
2445
  import {
2446
+ CREDENTIAL_STORE_MODES,
2370
2447
  loadGlobalConfig as loadGlobalConfig3,
2371
2448
  saveGlobalConfig as saveGlobalConfig3,
2372
2449
  CliError as CliError4,
@@ -2384,8 +2461,13 @@ import {
2384
2461
  loadGlobalConfig as loadGlobalConfig2,
2385
2462
  saveGlobalConfig as saveGlobalConfig2,
2386
2463
  loadIdentity as loadIdentity2,
2387
- listIdentities,
2388
- deleteIdentity,
2464
+ saveIdentity as saveIdentity2,
2465
+ listIdentities as listIdentities2,
2466
+ deleteIdentity as deleteIdentity2,
2467
+ renameIdentity,
2468
+ assertNotReservedEnvName,
2469
+ TEMP_ENV_NAME as TEMP_ENV_NAME2,
2470
+ isTempEnv as isTempEnv2,
2389
2471
  TokenStore as TokenStore2,
2390
2472
  CliError as CliError3,
2391
2473
  CliErrorCode as CliErrorCode2,
@@ -2419,7 +2501,9 @@ async function envList() {
2419
2501
  const cfg = await loadEnv2(name);
2420
2502
  return {
2421
2503
  active: name === g.activeEnv ? "*" : " ",
2422
- name,
2504
+ // 临时槽位在列表里如实标出来:它不是使用者起的名字,也随时会被下一次
2505
+ // `login --code` 覆盖 —— 显示成一个普通 env 名会让人以为它是自己建的。
2506
+ name: isTempEnv2(name) ? `${name} (\u4E34\u65F6\xB7\u672A\u4FDD\u5B58)` : name,
2423
2507
  endpoint: cfg.endpoint,
2424
2508
  frontend: cfg.frontend ?? "(none)",
2425
2509
  tenant: cfg.tenantId ?? "1",
@@ -2441,13 +2525,17 @@ async function envCurrent() {
2441
2525
  }
2442
2526
  const idName = cfg.defaultIdentity ?? "(none)";
2443
2527
  const frontend = cfg.frontend ? ` frontend=${cfg.frontend}` : "";
2444
- return exitOk(`\u2192 ${g.activeEnv} ${cfg.endpoint}${frontend} tenant=${cfg.tenantId ?? "1"} identity=${idName}`);
2528
+ const head = `\u2192 ${g.activeEnv} ${cfg.endpoint}${frontend} tenant=${cfg.tenantId ?? "1"} identity=${idName}`;
2529
+ if (!isTempEnv2(g.activeEnv)) return exitOk(head);
2530
+ return exitOk(`${head}
2531
+ \u4E34\u65F6\u73AF\u5883\xB7\u672A\u4FDD\u5B58\uFF08\u4E0B\u6B21 login --code \u4F1A\u8986\u76D6\uFF09\u3002\u7559\u7740\u5B83: hcm env save <name>`);
2445
2532
  } catch (e) {
2446
2533
  exitWithError(e);
2447
2534
  }
2448
2535
  }
2449
2536
  async function envAdd(name, args) {
2450
2537
  try {
2538
+ assertNotReservedEnvName(name);
2451
2539
  if (!args.endpoint) {
2452
2540
  throw new CliError3({
2453
2541
  code: CliErrorCode2.ENV_ENDPOINT_REQUIRED,
@@ -2518,12 +2606,12 @@ async function envRemove(name, args) {
2518
2606
  return exitOk("aborted");
2519
2607
  }
2520
2608
  }
2521
- const ids = await listIdentities(name);
2609
+ const ids = await listIdentities2(name);
2522
2610
  const failed2 = [];
2523
2611
  for (const id of ids) {
2524
2612
  try {
2525
2613
  await TokenStore2.forIdentity(id).clear();
2526
- await deleteIdentity(id);
2614
+ await deleteIdentity2(id);
2527
2615
  } catch (err) {
2528
2616
  failed2.push(id);
2529
2617
  process.stderr.write(
@@ -2551,7 +2639,7 @@ async function envShow(args) {
2551
2639
  const g = await loadGlobalConfig2();
2552
2640
  const target = args.name ?? g.activeEnv;
2553
2641
  const cfg = await loadEnv2(target);
2554
- const ids = await listIdentities(target);
2642
+ const ids = await listIdentities2(target);
2555
2643
  return exitOk(
2556
2644
  toYaml({
2557
2645
  name: target,
@@ -2586,6 +2674,84 @@ async function envEdit(field, value, args) {
2586
2674
  exitWithError(e);
2587
2675
  }
2588
2676
  }
2677
+ async function findEquivalentEnvs(cfg, exclude) {
2678
+ const origin = (u) => {
2679
+ if (!u) return "";
2680
+ try {
2681
+ return new URL(u).origin;
2682
+ } catch {
2683
+ return "";
2684
+ }
2685
+ };
2686
+ const mine = new Set([origin(cfg.endpoint), origin(cfg.frontend)].filter(Boolean));
2687
+ const hits = [];
2688
+ for (const name of await listEnvs()) {
2689
+ if (name === exclude || isTempEnv2(name)) continue;
2690
+ const other = await loadEnv2(name).catch(() => null);
2691
+ if (!other) continue;
2692
+ const theirs = [origin(other.endpoint), origin(other.frontend)].filter(Boolean);
2693
+ const sameAddress = theirs.some((o) => mine.has(o));
2694
+ const tenantOf2 = (v) => String(v ?? "1");
2695
+ const sameTenant = tenantOf2(other.tenantId) === tenantOf2(cfg.tenantId);
2696
+ if (sameAddress && sameTenant) hits.push(name);
2697
+ }
2698
+ return hits;
2699
+ }
2700
+ async function envSave(name, args) {
2701
+ try {
2702
+ assertNotReservedEnvName(name);
2703
+ const g = await loadGlobalConfig2();
2704
+ if (!isTempEnv2(g.activeEnv)) {
2705
+ throw new CliError3({
2706
+ code: CliErrorCode2.INVALID_ARGUMENT,
2707
+ message: `\u5F53\u524D\u4E0D\u662F\u4E34\u65F6\u73AF\u5883\uFF08activeEnv='${g.activeEnv}'\uFF09\uFF0C\u6CA1\u6709\u8981\u4FDD\u5B58\u7684\u4E1C\u897F\u3002`,
2708
+ context: {
2709
+ nextStep: `\u4E34\u65F6\u73AF\u5883\u7531 'hcm login <url> --code <\u7801>' \u4EA7\u751F\uFF1B\u5DF2\u5177\u540D\u7684 env \u6539\u914D\u7F6E\u7528 'hcm env edit'`
2710
+ }
2711
+ });
2712
+ }
2713
+ const cfg = await loadEnv2(TEMP_ENV_NAME2);
2714
+ const existing = await loadEnv2(name).catch(() => null);
2715
+ if (existing && !args.force) {
2716
+ throw new CliError3({
2717
+ code: CliErrorCode2.ENV_ALREADY_EXISTS,
2718
+ message: `env '${name}' \u5DF2\u5B58\u5728\uFF08\u6307\u5411 ${existing.endpoint}\uFF09\u3002`,
2719
+ context: { nextStep: `\u6362\u4E2A\u540D\u5B57\uFF0C\u6216\u7528 --force \u8986\u76D6\u5B83\u7684\u914D\u7F6E` }
2720
+ });
2721
+ }
2722
+ const twins = await findEquivalentEnvs(cfg, name);
2723
+ if (twins.length > 0) {
2724
+ process.stderr.write(
2725
+ `[hcm] \u6CE8\u610F\uFF1A\u76F8\u540C\u5730\u5740\u4E0E\u79DF\u6237\u7684 env \u5DF2\u7ECF\u6709\u4E86\uFF1A${twins.join(", ")}\u3002\u5982\u679C\u662F\u540C\u4E00\u4E2A\u73AF\u5883\uFF0C\u8003\u8651\u76F4\u63A5\u7528\u5B83\u4EEC\uFF0C\u907F\u514D\u518D\u6512\u4E00\u4EFD\u91CD\u590D\u914D\u7F6E\u3002
2726
+ `
2727
+ );
2728
+ }
2729
+ await saveEnv2(name, cfg);
2730
+ const ids = await listIdentities2(TEMP_ENV_NAME2);
2731
+ const renamed = [];
2732
+ for (const id of ids) {
2733
+ const next = id.endsWith(`@${TEMP_ENV_NAME2}`) ? `${id.slice(0, -`@${TEMP_ENV_NAME2}`.length)}@${name}` : id;
2734
+ await renameIdentity(id, next);
2735
+ const meta2 = await loadIdentity2(next);
2736
+ await saveIdentity2(next, { ...meta2, env: name });
2737
+ renamed.push(next);
2738
+ if (cfg.defaultIdentity === id) {
2739
+ cfg.defaultIdentity = next;
2740
+ await saveEnv2(name, cfg);
2741
+ }
2742
+ }
2743
+ g.activeEnv = name;
2744
+ await saveGlobalConfig2(g);
2745
+ await deleteEnv(TEMP_ENV_NAME2);
2746
+ const noun = renamed.length === 1 ? "identity" : "identities";
2747
+ const detail = renamed.length > 0 ? `\uFF1A${renamed.join(", ")}` : "";
2748
+ return exitOk(
2749
+ `\u2705 \u5DF2\u4FDD\u5B58\u4E3A env '${name}'\uFF08${renamed.length} ${noun} \u968F\u4E4B\u8FC1\u79FB${detail}\uFF09\uFF0C\u5E76\u8BBE\u4E3A\u5F53\u524D env\u3002`
2750
+ );
2751
+ } catch (e) {
2752
+ exitWithError(e);
2753
+ }
2754
+ }
2589
2755
 
2590
2756
  // src/commands/config.ts
2591
2757
  init_exit();
@@ -2603,6 +2769,19 @@ async function configShowDeprecated() {
2603
2769
  warnDeprecated("hcm config show", "hcm env current");
2604
2770
  await envCurrent();
2605
2771
  }
2772
+ function assertKnownDefault(sub, value) {
2773
+ const allowed = {
2774
+ credentialStore: CREDENTIAL_STORE_MODES,
2775
+ output: ["table", "json", "yaml"]
2776
+ };
2777
+ const options = allowed[sub];
2778
+ if (!options || options.includes(value)) return;
2779
+ throw new CliError4({
2780
+ code: CliErrorCode3.INVALID_ARGUMENT,
2781
+ message: `defaults.${sub} \u4E0D\u63A5\u53D7 '${value}'\u3002\u53EF\u9009\u503C\uFF1A${options.join(" / ")}`,
2782
+ context: sub === "credentialStore" ? { nextStep: `\u6CA1\u6709 keychain \u8FD9\u4E00\u6863\uFF1Aauto \u5C31\u662F\u300C\u4F18\u5148\u94A5\u5319\u4E32\u3001\u5199\u4E0D\u8FDB\u843D 0600 \u6587\u4EF6\u300D` } : void 0
2783
+ });
2784
+ }
2606
2785
  async function configSetProfileDeprecated(name) {
2607
2786
  warnDeprecated("hcm config set-profile", "hcm env use");
2608
2787
  await envUse(name, { ping: false });
@@ -2620,6 +2799,7 @@ async function configSet(key2, value) {
2620
2799
  });
2621
2800
  }
2622
2801
  const sub = key2.slice("defaults.".length);
2802
+ assertKnownDefault(sub, value);
2623
2803
  const g = await loadGlobalConfig3();
2624
2804
  g.defaults = g.defaults ?? {};
2625
2805
  g.defaults[sub] = value;
@@ -8082,8 +8262,8 @@ import {
8082
8262
  loadEnv as loadEnv8,
8083
8263
  saveEnv as saveEnv3,
8084
8264
  loadIdentity as loadIdentity4,
8085
- listIdentities as listIdentities2,
8086
- deleteIdentity as deleteIdentity2,
8265
+ listIdentities as listIdentities3,
8266
+ deleteIdentity as deleteIdentity3,
8087
8267
  loadGlobalConfig as loadGlobalConfig8,
8088
8268
  TokenStore as TokenStore3,
8089
8269
  toPrincipal
@@ -8137,7 +8317,7 @@ async function identityList(args) {
8137
8317
  try {
8138
8318
  const g = await loadGlobalConfig8();
8139
8319
  const filter = args.env === "all" ? void 0 : args.env ?? g.activeEnv;
8140
- const names = await listIdentities2(filter);
8320
+ const names = await listIdentities3(filter);
8141
8321
  if (names.length === 0) {
8142
8322
  return exitOk("(no identities)");
8143
8323
  }
@@ -8181,7 +8361,7 @@ async function identityRemove(name) {
8181
8361
  `
8182
8362
  );
8183
8363
  }
8184
- await deleteIdentity2(name);
8364
+ await deleteIdentity3(name);
8185
8365
  const env2 = await loadEnv8(meta2.env).catch(() => null);
8186
8366
  if (env2?.defaultIdentity === name) {
8187
8367
  env2.defaultIdentity = void 0;
@@ -9750,7 +9930,8 @@ import {
9750
9930
  fetchReconIdentity as fetchReconIdentity2,
9751
9931
  formatObject as formatObject24,
9752
9932
  httpProbe as httpProbe2,
9753
- listIdentities as listIdentities3,
9933
+ isTempEnv as isTempEnv3,
9934
+ listIdentities as listIdentities4,
9754
9935
  loadEnv as loadEnv11,
9755
9936
  loadGlobalConfig as loadGlobalConfig10
9756
9937
  } from "@hcmai/sdk";
@@ -10028,7 +10209,7 @@ async function resolveLoggedInEnv() {
10028
10209
  message: `\u5F53\u524D\u73AF\u5883 '${name}' \u6CA1\u6709 endpoint\u3002\u5148\u6267\u884C\uFF1A${loginHint}`
10029
10210
  });
10030
10211
  }
10031
- const identities = await listIdentities3(name).catch(() => []);
10212
+ const identities = await listIdentities4(name).catch(() => []);
10032
10213
  if (identities.length === 0) {
10033
10214
  throw new CliError21({
10034
10215
  code: CliErrorCode20.IDENTITY_NOT_FOUND,
@@ -10088,6 +10269,13 @@ async function scaffoldChironProject(root, env2, envName) {
10088
10269
  async function runChironInit(args, deps = defaultChironInitDeps) {
10089
10270
  const root = path10.resolve(args.project ?? ".");
10090
10271
  const { name, env: env2, identity: identity2 } = await resolveLoggedInEnv();
10272
+ if (isTempEnv3(name)) {
10273
+ throw new CliError21({
10274
+ code: CliErrorCode20.INVALID_ARGUMENT,
10275
+ message: `\u5F53\u524D\u662F\u4E34\u65F6\u73AF\u5883\uFF08${env2.endpoint}\uFF09\uFF0C\u8FD8\u6CA1\u6709\u540D\u5B57\u3002\u9879\u76EE\u8981\u7ED1\u4E00\u4E2A\u7A33\u5B9A\u7684 env\uFF0C\u5426\u5219\u4E0B\u4E00\u6B21 hcm login --code \u8986\u76D6\u5B83\u4E4B\u540E\uFF0C\u9879\u76EE\u4ED3\u8BB0\u7684\u73AF\u5883\u5C31\u5BF9\u4E0D\u4E0A\u4E86\u3002`,
10276
+ context: { nextStep: `\u5148\u7ED9\u5B83\u8D77\u4E2A\u540D\u5B57\uFF1Ahcm env save <name>\uFF0C\u7136\u540E\u91CD\u8DD1 hcm chiron init` }
10277
+ });
10278
+ }
10091
10279
  const say = (line) => process.stderr.write(`[chiron init] ${line}
10092
10280
  `);
10093
10281
  const actual = await deps.tokenTenant(name, env2.tenant);
@@ -12020,6 +12208,7 @@ env.command("list").description("\u5217\u51FA\u5168\u90E8 env").action(() => env
12020
12208
  env.command("current").description("\u663E\u793A\u5F53\u524D\u6FC0\u6D3B\u7684 env").action(() => envCurrent());
12021
12209
  env.command("add <name>").description("\u65B0\u589E env").option("--endpoint <url>", "HCM \u540E\u7AEF URL\uFF08\u5FC5\u586B\uFF09").option("--tenant <id>", "\u9ED8\u8BA4 tenant id", "1").option("--frontend <url>", "\u5BF9\u5E94\u524D\u7AEF URL\uFF0C\u4F8B\u5982 http://127.0.0.1:5176").option("--force", "\u8986\u76D6\u5DF2\u5B58\u5728\u7684\u540C\u540D env").action((name, opts) => envAdd(name, opts));
12022
12210
  env.command("use <name>").description("\u5207\u5230\u6307\u5B9A env").option("--no-ping", "\u8DF3\u8FC7 endpoint \u5065\u5EB7\u68C0\u67E5").action((name, opts) => envUse(name, opts));
12211
+ env.command("save <name>").description("\u628A\u5F53\u524D\u4E34\u65F6\u73AF\u5883\uFF08login --code \u4EA7\u751F\u7684\uFF09\u5B58\u6210\u5177\u540D env").option("--force", "\u76EE\u6807 env \u5DF2\u5B58\u5728\u65F6\u8986\u76D6\u5B83\u7684\u914D\u7F6E").action((name, opts) => envSave(name, opts));
12023
12212
  env.command("remove <name>").description("\u5220\u9664 env\uFF08\u7EA7\u8054\u6E05\u9664\u8BE5 env \u7684\u5168\u90E8 identity \u548C token\uFF09").option("--force", "\u8DF3\u8FC7\u786E\u8BA4\u63D0\u793A").action((name, opts) => envRemove(name, opts));
12024
12213
  env.command("show [name]").description("\u663E\u793A env \u8BE6\u60C5\uFF08\u542B\u8BE5 env \u4E0B\u7684 identity \u5217\u8868\uFF09").action((name) => envShow({ name }));
12025
12214
  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));