@alphalawyer/alpha-classic-cli 0.1.2 → 0.1.3

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/README.md CHANGED
@@ -5,7 +5,7 @@ Alpha Classic CLI 是为 **Alpha 律所管理系统** 开发的 AI-friendly CLI
5
5
  - CLI 命令能访问 Web 应用 API
6
6
  - Codex 能通过 Skill 理解该怎么调用 CLI
7
7
  - 登录、诊断、业务查询形成最小闭环
8
- - 环境在构建时固化,运行时不能切换,避免误连 dev/prod
8
+ - 默认环境是 `prod`,也可以通过 `env use` 在预设环境间切换
9
9
 
10
10
  ## 安装依赖
11
11
 
@@ -16,10 +16,10 @@ npm install
16
16
  ## 构建
17
17
 
18
18
  ```bash
19
- npm run build:dev
19
+ npm run build
20
20
  ```
21
21
 
22
- 构建脚本会把环境写入产物:
22
+ 默认构建生产环境产物;本地调试也保留按环境构建的脚本:
23
23
 
24
24
  ```bash
25
25
  npm run build:local
@@ -41,10 +41,10 @@ npm run release:patch
41
41
  - `release:patch`:先确认 npm 登录用户,再完成发布前检查、自动升级补丁版本、重新生产构建并发布到公开 npm 仓库。
42
42
  - 如果 npm 要求 OTP,命令后追加参数即可,例如 `npm run release:patch -- --otp=123456`。
43
43
 
44
- 当前 dev 环境:
44
+ 默认 prod 环境:
45
45
 
46
46
  ```text
47
- baseUrl/apiBaseUrl: https://dev.alphalawyer.cn
47
+ baseUrl/apiBaseUrl: https://alphalawyer.cn
48
48
  current user API: GET /im/v1/users/me
49
49
  auth header: token: <token>
50
50
  device header: deviceType: ai
@@ -56,7 +56,10 @@ device header: deviceType: ai
56
56
 
57
57
  ```bash
58
58
  alpha-classic-cli version
59
+ alpha-classic-cli env list
59
60
  alpha-classic-cli env current
61
+ alpha-classic-cli env use test
62
+ alpha-classic-cli env use prod
60
63
  alpha-classic-cli login
61
64
  alpha-classic-cli doctor
62
65
  alpha-classic-cli matter search --keyword 合同 --limit 10
@@ -68,7 +71,7 @@ alpha-classic-cli appro initiators --keyword 张三
68
71
  alpha-classic-cli appro detail --id <审批ID>
69
72
  ```
70
73
 
71
- `env use` 已移除。只保留 `env list` 和 `env current`;切换环境必须重新构建对应环境版本。
74
+ `env use <local|dev|test|prod>` 会写入本地配置并清空旧登录态,切换后需要重新执行 `alpha-classic-cli login`。
72
75
 
73
76
  源码调试时也可以使用:
74
77
 
@@ -221,5 +224,5 @@ alpha-classic-cli capabilities
221
224
  - 默认输出 JSON envelope,方便 AI 解析。
222
225
  - 只支持查询,不执行写操作。
223
226
  - 不在终端输出 token。
224
- - 不接受运行时 baseUrl/apiBaseUrl 参数。
227
+ - 运行时只允许切换内置环境预设,不接受任意 baseUrl/apiBaseUrl 参数。
225
228
  - Skill 负责告诉 AI 什么时候用哪个命令。
@@ -10,7 +10,7 @@
10
10
  - 使用前先运行 `alpha-classic-cli doctor`。
11
11
  - 未登录时提示用户运行 `alpha-classic-cli login`。
12
12
  - Agent 异步登录使用 `alpha-classic-cli login --no-wait --json`,把 `data.verification_url` 原样交给用户;用户确认后运行 `alpha-classic-cli login --device-code <device_code>`。
13
- - 环境由 CLI 构建时固化,运行时不能切换;如环境不对,提示用户重新构建对应环境版本。
13
+ - 默认环境是 `prod`;如环境不对,使用 `alpha-classic-cli env use <local|dev|test|prod>` 切换,并在切换后重新登录。
14
14
 
15
15
  ## 输出处理
16
16
 
@@ -107,7 +107,7 @@ alpha-classic-cli appro detail --id <approId> --comments 10
107
107
 
108
108
  - 除非用户明确要求做 CLI 开发工作,否则只使用查询 / 读取命令。
109
109
  - 不要输出 token 或 refreshToken。
110
- - 不要使用 `env use`;这个命令已经移除,只保留 `env list` 和 `env current`,环境在构建时已经锁定。
110
+ - 默认环境是 `prod`;需要切换时使用 `alpha-classic-cli env use <local|dev|test|prod>`,切换后重新登录。
111
111
  - 优先使用 `matter`,`project` 只是别名。
112
112
  - 在项目详情页里,任务表用 `matter task`。
113
113
  - 最终回答默认隐藏内部 ID,包括 `项目ID`、`审批ID`、`任务ID`、`流程任务ID`、`节点ID`、`字段ID`、`文件ID`、`评论ID`、`动态ID`;这些只留给后续 CLI 调用。`项目编号`、`审批编号` 这类业务编号可以展示。
package/dist/index.js CHANGED
@@ -19,7 +19,7 @@ function normalizeBaseUrl(value) {
19
19
  }
20
20
 
21
21
  // src/config/environments.ts
22
- var DEFAULT_ENVIRONMENT_NAME = "dev";
22
+ var DEFAULT_ENVIRONMENT_NAME = "prod";
23
23
  var PRESETS = {
24
24
  local: {
25
25
  label: "Local development",
@@ -68,6 +68,16 @@ function getEnvironmentPresetOrThrow(name) {
68
68
  function getDefaultEnvironmentPreset() {
69
69
  return getEnvironmentPresetOrThrow(BUILD_ENVIRONMENT_NAME);
70
70
  }
71
+ async function getCurrentEnvironmentPreset(configReader) {
72
+ const config = await configReader.getConfig();
73
+ const configuredEnvironment = getEnvironmentPreset(config.environment);
74
+ const fallbackEnvironment = getDefaultEnvironmentPreset();
75
+ const environment = configuredEnvironment ?? fallbackEnvironment;
76
+ return {
77
+ ...environment,
78
+ source: configuredEnvironment ? "config" : "default"
79
+ };
80
+ }
71
81
  function normalizePreset(name, preset) {
72
82
  return {
73
83
  name,
@@ -368,6 +378,7 @@ async function createLoginDeviceAuthorization(options, sessionStore) {
368
378
  client: CLIENT_NAME,
369
379
  deviceName: buildDeviceName()
370
380
  });
381
+ const normalizedAuth = normalizeDeviceAuthorizationUrls(auth, context.baseUrl);
371
382
  await sessionStore.saveConfig({
372
383
  environment: context.environment.name,
373
384
  baseUrl: context.baseUrl,
@@ -378,7 +389,7 @@ async function createLoginDeviceAuthorization(options, sessionStore) {
378
389
  baseUrl: context.baseUrl,
379
390
  apiBaseUrl: context.apiBaseUrl,
380
391
  timeoutMs: context.timeoutMs,
381
- auth
392
+ auth: normalizedAuth
382
393
  };
383
394
  }
384
395
  async function pollLoginDeviceAuthorization(options, sessionStore, deviceCode) {
@@ -439,7 +450,7 @@ async function runTokenLogin(options, sessionStore) {
439
450
  if (!options.token) {
440
451
  throw new Error("Missing token.");
441
452
  }
442
- const environment = getDefaultEnvironmentPreset();
453
+ const environment = await getCurrentEnvironmentPreset(sessionStore);
443
454
  const currentUser = await verifyToken(environment.apiBaseUrl, options.token);
444
455
  const currentUserData = getCurrentUserData(currentUser);
445
456
  const userId = options.userId ?? currentUserData?.accid ?? currentUserData?.id ?? currentUserData?.user_id;
@@ -468,9 +479,9 @@ async function runTokenLogin(options, sessionStore) {
468
479
  }
469
480
  async function resolveLoginContext(options, sessionStore) {
470
481
  const config = await sessionStore.getConfig();
471
- const environment = getDefaultEnvironmentPreset();
472
- const baseUrl = normalizeBaseUrl(config.baseUrl ?? environment.baseUrl);
473
- const apiBaseUrl = normalizeBaseUrl(config.apiBaseUrl ?? environment.apiBaseUrl);
482
+ const environment = await getCurrentEnvironmentPreset(sessionStore);
483
+ const baseUrl = normalizeBaseUrl(environment.baseUrl);
484
+ const apiBaseUrl = normalizeBaseUrl(environment.apiBaseUrl);
474
485
  const timeoutMs = options.timeoutMs ?? config.timeoutMs ?? DEFAULT_LOGIN_TIMEOUT_MS;
475
486
  const apiClient = options.apiClient ?? new ApiClient({
476
487
  sessionStore,
@@ -573,6 +584,27 @@ ${qrcode}
573
584
  }
574
585
  emitProgress(reporter, `login: open ${auth.verificationUriComplete}`);
575
586
  }
587
+ function normalizeDeviceAuthorizationUrls(auth, baseUrl) {
588
+ return {
589
+ ...auth,
590
+ ...auth.verificationUri ? { verificationUri: replaceUrlOrigin(auth.verificationUri, baseUrl) } : {},
591
+ verificationUriComplete: replaceUrlOrigin(auth.verificationUriComplete, baseUrl)
592
+ };
593
+ }
594
+ function replaceUrlOrigin(value, baseUrl) {
595
+ if (!value.trim()) {
596
+ return value;
597
+ }
598
+ try {
599
+ const currentUrl = new URL(value);
600
+ const targetUrl = new URL(baseUrl);
601
+ currentUrl.protocol = targetUrl.protocol;
602
+ currentUrl.host = targetUrl.host;
603
+ return currentUrl.toString();
604
+ } catch {
605
+ return new URL(value.startsWith("/") ? value : `/${value}`, baseUrl).toString();
606
+ }
607
+ }
576
608
  function emitProgress(reporter, message) {
577
609
  reporter?.(`[${(/* @__PURE__ */ new Date()).toLocaleTimeString("zh-CN", { hour12: false })}] ${message}`);
578
610
  }
@@ -643,7 +675,7 @@ function printError(type, message, options) {
643
675
  // src/commands/api.ts
644
676
  async function runApiCommand(method, apiPath, options, sessionStore) {
645
677
  const config = await sessionStore.getConfig();
646
- const environment = getDefaultEnvironmentPreset();
678
+ const environment = await getCurrentEnvironmentPreset(sessionStore);
647
679
  const client = new ApiClient({
648
680
  sessionStore,
649
681
  apiBaseUrl: environment.apiBaseUrl,
@@ -694,7 +726,7 @@ async function runApproList(options, sessionStore) {
694
726
  const approTypes = parseNumberList(options.approType);
695
727
  const status = parseApproStatus(options.status);
696
728
  const config = await sessionStore.getConfig();
697
- const environment = getDefaultEnvironmentPreset();
729
+ const environment = await getCurrentEnvironmentPreset(sessionStore);
698
730
  const client = new ApiClient({
699
731
  sessionStore,
700
732
  apiBaseUrl: environment.apiBaseUrl,
@@ -747,7 +779,7 @@ async function runApproList(options, sessionStore) {
747
779
  async function runApproInitiators(options, sessionStore) {
748
780
  const limit = clampLimit(options.limit ?? 50);
749
781
  const config = await sessionStore.getConfig();
750
- const environment = getDefaultEnvironmentPreset();
782
+ const environment = await getCurrentEnvironmentPreset(sessionStore);
751
783
  const client = new ApiClient({
752
784
  sessionStore,
753
785
  apiBaseUrl: environment.apiBaseUrl,
@@ -775,7 +807,7 @@ async function runApproDetail(options, sessionStore) {
775
807
  throw new Error("Missing appro id. Use: alpha-classic-cli appro detail --id <approId>");
776
808
  }
777
809
  const config = await sessionStore.getConfig();
778
- const environment = getDefaultEnvironmentPreset();
810
+ const environment = await getCurrentEnvironmentPreset(sessionStore);
779
811
  const client = new ApiClient({
780
812
  sessionStore,
781
813
  apiBaseUrl: environment.apiBaseUrl,
@@ -1975,8 +2007,8 @@ function clampCommentLimit(limit) {
1975
2007
  }
1976
2008
 
1977
2009
  // src/commands/capabilities.ts
1978
- function runCapabilities(version) {
1979
- const environment = getDefaultEnvironmentPreset();
2010
+ async function runCapabilities(version, sessionStore) {
2011
+ const environment = await getCurrentEnvironmentPreset(sessionStore);
1980
2012
  printSuccess({
1981
2013
  "\u5DE5\u5177": {
1982
2014
  "\u540D\u79F0": "alpha-classic-cli",
@@ -1988,8 +2020,9 @@ function runCapabilities(version) {
1988
2020
  "\u5F53\u524D\u73AF\u5883": environment.name,
1989
2021
  "baseUrl": environment.baseUrl,
1990
2022
  "apiBaseUrl": environment.apiBaseUrl,
1991
- "\u662F\u5426\u6784\u5EFA\u65F6\u9501\u5B9A": true,
1992
- "\u5207\u6362\u65B9\u5F0F": "\u91CD\u65B0\u6784\u5EFA\u5BF9\u5E94\u73AF\u5883\u7248\u672C\uFF0C\u4F8B\u5982 npm run build:dev"
2023
+ "\u662F\u5426\u53EF\u8FD0\u884C\u65F6\u5207\u6362": true,
2024
+ "\u73AF\u5883\u6765\u6E90": environment.source,
2025
+ "\u5207\u6362\u65B9\u5F0F": "alpha-classic-cli env use <local|dev|test|prod>"
1993
2026
  },
1994
2027
  "\u8BA4\u8BC1": {
1995
2028
  "\u68C0\u67E5\u767B\u5F55": "alpha-classic-cli doctor",
@@ -2016,7 +2049,7 @@ function runCapabilities(version) {
2016
2049
  "\u5378\u8F7D Claude Code": "alpha-classic-cli uninstall --agent claude",
2017
2050
  "\u5378\u8F7D Alpha-claw": "alpha-classic-cli uninstall --agent alphaclaw",
2018
2051
  "\u5378\u8F7D\u5168\u90E8": "alpha-classic-cli uninstall --agent all",
2019
- "\u8BF4\u660E": "\u7528\u6237\u81EA\u884C\u9009\u62E9\u5B89\u88C5\u76EE\u6807\uFF1BAlpha-claw \u4F1A\u6309 CLI \u6784\u5EFA\u73AF\u5883\u5B89\u88C5\u5230\u5BF9\u5E94 .openclaw-<env>alphaclaw \u5DE5\u4F5C\u533A\u3002"
2052
+ "\u8BF4\u660E": "\u7528\u6237\u81EA\u884C\u9009\u62E9\u5B89\u88C5\u76EE\u6807\uFF1BAlpha-claw \u4F1A\u6309\u5F53\u524D CLI \u73AF\u5883\u5B89\u88C5\u5230\u5BF9\u5E94 .openclaw-<env>alphaclaw \u5DE5\u4F5C\u533A\u3002"
2020
2053
  },
2021
2054
  "\u8F93\u51FA\u534F\u8BAE": {
2022
2055
  "\u6210\u529F": { "ok": true, "data": "\u4E1A\u52A1\u6570\u636E" },
@@ -2300,7 +2333,7 @@ function runCapabilities(version) {
2300
2333
  "\u4E0D\u8981\u8F93\u51FA token\u3002",
2301
2334
  "\u4E0D\u8981\u81EA\u884C\u62FC\u63A5\u540E\u7AEF\u63A5\u53E3\uFF0C\u9664\u975E\u7528\u6237\u660E\u786E\u8981\u6C42\u4F7F\u7528 api \u8C03\u8BD5\u547D\u4EE4\u3002",
2302
2335
  "\u4F18\u5148\u4F7F\u7528 capabilities \u4E2D\u58F0\u660E\u7684\u7A33\u5B9A\u4E1A\u52A1\u547D\u4EE4\u3002",
2303
- "\u73AF\u5883\u8FD0\u884C\u65F6\u4E0D\u53EF\u5207\u6362\uFF0C\u907F\u514D\u8BEF\u8FDE dev/prod\u3002"
2336
+ "\u9700\u8981\u5207\u6362\u73AF\u5883\u65F6\u4F7F\u7528 alpha-classic-cli env use\uFF0C\u5E76\u5728\u5207\u6362\u540E\u91CD\u65B0\u767B\u5F55\u3002"
2304
2337
  ]
2305
2338
  });
2306
2339
  }
@@ -2356,11 +2389,10 @@ function resolveClaudeGuidePath(homeDir = os2.homedir()) {
2356
2389
  function resolveClaudeMemoryPath(homeDir = os2.homedir()) {
2357
2390
  return path2.join(homeDir, ".claude", "CLAUDE.md");
2358
2391
  }
2359
- function resolveAlphaClawSkillPath(homeDir = os2.homedir()) {
2360
- const environment = getDefaultEnvironmentPreset();
2392
+ function resolveAlphaClawSkillPath(homeDir = os2.homedir(), environmentName = DEFAULT_ENVIRONMENT_NAME) {
2361
2393
  return path2.join(
2362
2394
  homeDir,
2363
- `.openclaw-${environment.name}alphaclaw`,
2395
+ `.openclaw-${environmentName}alphaclaw`,
2364
2396
  "workspace",
2365
2397
  "skills",
2366
2398
  SKILL_NAME
@@ -2409,8 +2441,8 @@ async function uninstallAgentGuides(options) {
2409
2441
  result.claudeMemoryUpdated = claudeResult.claudeMemoryUpdated;
2410
2442
  }
2411
2443
  if (agent === "alphaclaw" || agent === "all") {
2412
- await fs2.rm(resolveAlphaClawSkillPath(options?.homeDir), { recursive: true, force: true });
2413
- result.alphaClawSkillPath = resolveAlphaClawSkillPath(options?.homeDir);
2444
+ await fs2.rm(resolveAlphaClawSkillPath(options?.homeDir, options?.environmentName), { recursive: true, force: true });
2445
+ result.alphaClawSkillPath = resolveAlphaClawSkillPath(options?.homeDir, options?.environmentName);
2414
2446
  result.alphaClawSkillInstalled = false;
2415
2447
  }
2416
2448
  return result;
@@ -2425,7 +2457,7 @@ async function installCodexSkill(options) {
2425
2457
  };
2426
2458
  }
2427
2459
  async function installAlphaClawSkill(options) {
2428
- const skillPath = resolveAlphaClawSkillPath(options?.homeDir);
2460
+ const skillPath = resolveAlphaClawSkillPath(options?.homeDir, options?.environmentName);
2429
2461
  await fs2.rm(skillPath, { recursive: true, force: true });
2430
2462
  await copyDirectory(SKILL_TEMPLATE_ROOT, skillPath);
2431
2463
  return {
@@ -2482,7 +2514,7 @@ async function inspectInstallState(options) {
2482
2514
  } catch {
2483
2515
  claudeGuideInstalled = false;
2484
2516
  }
2485
- const alphaClawSkillPath = resolveAlphaClawSkillPath(options?.homeDir);
2517
+ const alphaClawSkillPath = resolveAlphaClawSkillPath(options?.homeDir, options?.environmentName);
2486
2518
  let alphaClawSkillInstalled = false;
2487
2519
  try {
2488
2520
  await fs2.access(path2.join(alphaClawSkillPath, "SKILL.md"));
@@ -2549,8 +2581,10 @@ async function removeClaudeImport(memoryPath) {
2549
2581
  async function runDoctor(sessionStore) {
2550
2582
  const config = await sessionStore.getConfig();
2551
2583
  let session = await sessionStore.getSession();
2552
- const environment = getDefaultEnvironmentPreset();
2553
- const installState = await inspectInstallState();
2584
+ const environment = await getCurrentEnvironmentPreset(sessionStore);
2585
+ const installState = await inspectInstallState({
2586
+ environmentName: environment.name
2587
+ });
2554
2588
  let apiCheck = {
2555
2589
  ok: false,
2556
2590
  message: "\u672A\u767B\u5F55\u3002\u8BF7\u6267\u884C\uFF1Aalpha-classic-cli login"
@@ -2584,8 +2618,8 @@ async function runDoctor(sessionStore) {
2584
2618
  environment: environment.name,
2585
2619
  baseUrl: environment.baseUrl,
2586
2620
  apiBaseUrl: environment.apiBaseUrl,
2587
- locked: true,
2588
- source: "build",
2621
+ locked: false,
2622
+ source: environment.source,
2589
2623
  configPath: sessionStore.configPath
2590
2624
  },
2591
2625
  session: session ? {
@@ -2633,30 +2667,52 @@ function getCurrentUserData2(response) {
2633
2667
  }
2634
2668
 
2635
2669
  // src/commands/env.ts
2636
- async function runEnvCommand(action, _name, _sessionStore) {
2670
+ async function runEnvCommand(action, name, sessionStore) {
2637
2671
  const normalizedAction = action?.trim().toLowerCase() ?? "current";
2638
2672
  if (normalizedAction === "list") {
2673
+ const currentEnvironment = await getCurrentEnvironmentPreset(sessionStore);
2639
2674
  printSuccess(listEnvironmentPresets(), {
2640
- count: listEnvironmentPresets().length
2675
+ count: listEnvironmentPresets().length,
2676
+ current: currentEnvironment.name
2641
2677
  });
2642
2678
  return;
2643
2679
  }
2644
2680
  if (normalizedAction === "current") {
2645
- const fallback = getDefaultEnvironmentPreset();
2681
+ const currentEnvironment = await getCurrentEnvironmentPreset(sessionStore);
2646
2682
  printSuccess({
2647
- environment: fallback.name,
2648
- label: fallback.label,
2649
- baseUrl: fallback.baseUrl,
2650
- apiBaseUrl: fallback.apiBaseUrl,
2651
- locked: true,
2652
- source: "build"
2683
+ environment: currentEnvironment.name,
2684
+ label: currentEnvironment.label,
2685
+ baseUrl: currentEnvironment.baseUrl,
2686
+ apiBaseUrl: currentEnvironment.apiBaseUrl,
2687
+ locked: false,
2688
+ source: currentEnvironment.source,
2689
+ configPath: sessionStore.configPath
2653
2690
  });
2654
2691
  return;
2655
2692
  }
2656
2693
  if (normalizedAction === "use") {
2657
- throw new Error(
2658
- "env use has been removed. This CLI only exposes env list and env current."
2659
- );
2694
+ if (!name?.trim()) {
2695
+ throw new Error("Missing environment name. Use: alpha-classic-cli env use <local|dev|test|prod>");
2696
+ }
2697
+ const nextEnvironment = getEnvironmentPresetOrThrow(name);
2698
+ await sessionStore.saveConfig({
2699
+ environment: nextEnvironment.name,
2700
+ baseUrl: nextEnvironment.baseUrl,
2701
+ apiBaseUrl: nextEnvironment.apiBaseUrl
2702
+ });
2703
+ await sessionStore.clearAuthState();
2704
+ printSuccess({
2705
+ environment: nextEnvironment.name,
2706
+ label: nextEnvironment.label,
2707
+ baseUrl: nextEnvironment.baseUrl,
2708
+ apiBaseUrl: nextEnvironment.apiBaseUrl,
2709
+ locked: false,
2710
+ source: "config",
2711
+ session: "cleared",
2712
+ hint: "\u73AF\u5883\u5DF2\u5207\u6362\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C alpha-classic-cli login\u3002",
2713
+ configPath: sessionStore.configPath
2714
+ });
2715
+ return;
2660
2716
  }
2661
2717
  throw new Error(`Unknown env action: ${normalizedAction}`);
2662
2718
  }
@@ -2664,7 +2720,7 @@ async function runEnvCommand(action, _name, _sessionStore) {
2664
2720
  // src/commands/matter.ts
2665
2721
  async function runMatterSearch(options, sessionStore) {
2666
2722
  const config = await sessionStore.getConfig();
2667
- const environment = getDefaultEnvironmentPreset();
2723
+ const environment = await getCurrentEnvironmentPreset(sessionStore);
2668
2724
  const client = new ApiClient({
2669
2725
  sessionStore,
2670
2726
  apiBaseUrl: environment.apiBaseUrl,
@@ -2715,7 +2771,7 @@ async function runMatterDetail(options, sessionStore) {
2715
2771
  throw new Error("Missing matter id. Use: alpha-classic-cli matter detail --id <matterId>");
2716
2772
  }
2717
2773
  const config = await sessionStore.getConfig();
2718
- const environment = getDefaultEnvironmentPreset();
2774
+ const environment = await getCurrentEnvironmentPreset(sessionStore);
2719
2775
  const client = new ApiClient({
2720
2776
  sessionStore,
2721
2777
  apiBaseUrl: environment.apiBaseUrl,
@@ -2746,7 +2802,7 @@ async function runMatterTaskList(options, sessionStore) {
2746
2802
  throw new Error("Missing matter id. Use: alpha-classic-cli matter task --id <matterId>");
2747
2803
  }
2748
2804
  const config = await sessionStore.getConfig();
2749
- const environment = getDefaultEnvironmentPreset();
2805
+ const environment = await getCurrentEnvironmentPreset(sessionStore);
2750
2806
  const client = new ApiClient({
2751
2807
  sessionStore,
2752
2808
  apiBaseUrl: environment.apiBaseUrl,
@@ -2798,7 +2854,7 @@ async function runMatterTaskDetail(options, sessionStore) {
2798
2854
  throw new Error("Missing task id. Use: alpha-classic-cli matter task-detail --id <taskId>");
2799
2855
  }
2800
2856
  const config = await sessionStore.getConfig();
2801
- const environment = getDefaultEnvironmentPreset();
2857
+ const environment = await getCurrentEnvironmentPreset(sessionStore);
2802
2858
  const client = new ApiClient({
2803
2859
  sessionStore,
2804
2860
  apiBaseUrl: environment.apiBaseUrl,
@@ -3820,8 +3876,8 @@ function dateFromTimestamp2(timestamp) {
3820
3876
  }
3821
3877
 
3822
3878
  // src/commands/version.ts
3823
- function runVersion(info) {
3824
- const environment = getDefaultEnvironmentPreset();
3879
+ async function runVersion(info, sessionStore) {
3880
+ const environment = await getCurrentEnvironmentPreset(sessionStore);
3825
3881
  printSuccess({
3826
3882
  "\u540D\u79F0": info.name,
3827
3883
  "\u7248\u672C": info.version,
@@ -3829,7 +3885,8 @@ function runVersion(info) {
3829
3885
  "\u73AF\u5883": environment.name,
3830
3886
  "baseUrl": environment.baseUrl,
3831
3887
  "apiBaseUrl": environment.apiBaseUrl,
3832
- "\u73AF\u5883\u662F\u5426\u6784\u5EFA\u65F6\u9501\u5B9A": true
3888
+ "\u73AF\u5883\u662F\u5426\u53EF\u8FD0\u884C\u65F6\u5207\u6362": true,
3889
+ "\u73AF\u5883\u6765\u6E90": environment.source
3833
3890
  });
3834
3891
  }
3835
3892
 
@@ -3914,22 +3971,33 @@ async function main() {
3914
3971
  program.name("alpha-classic-cli").description("Alpha Classic AI-friendly CLI for Alpha web app").version(packageJson.version ?? "0.0.0");
3915
3972
  program.command("install").description("Install agent guides for Codex, Claude Code, Alpha-claw, or all supported agents").option("--agent <agent>", "Agent target: codex, claude, alphaclaw, all", "codex").action(async (options) => {
3916
3973
  const agent = parseAgentInstallTarget(options.agent);
3917
- const result = await installAgentGuides({ agent });
3974
+ const environment = await getCurrentEnvironmentPreset(sessionStore);
3975
+ const result = await installAgentGuides({
3976
+ agent,
3977
+ environmentName: environment.name
3978
+ });
3918
3979
  printSuccess(result);
3919
3980
  });
3920
3981
  program.command("uninstall").description("Uninstall agent guides for Codex, Claude Code, Alpha-claw, or all supported agents").option("--agent <agent>", "Agent target: codex, claude, alphaclaw, all", "codex").action(async (options) => {
3921
3982
  const agent = parseAgentInstallTarget(options.agent);
3922
- const result = await uninstallAgentGuides({ agent });
3983
+ const environment = await getCurrentEnvironmentPreset(sessionStore);
3984
+ const result = await uninstallAgentGuides({
3985
+ agent,
3986
+ environmentName: environment.name
3987
+ });
3923
3988
  printSuccess(result);
3924
3989
  });
3925
- program.command("capabilities").description("Print machine-readable CLI capabilities for agents").action(() => {
3926
- runCapabilities(packageJson.version ?? "0.0.0");
3990
+ program.command("capabilities").description("Print machine-readable CLI capabilities for agents").action(async () => {
3991
+ await runCapabilities(packageJson.version ?? "0.0.0", sessionStore);
3927
3992
  });
3928
- program.command("version").description("Print machine-readable CLI version").action(() => {
3929
- runVersion({
3930
- name: packageJson.name ?? "alpha-classic-cli",
3931
- version: packageJson.version ?? "0.0.0"
3932
- });
3993
+ program.command("version").description("Print machine-readable CLI version").action(async () => {
3994
+ await runVersion(
3995
+ {
3996
+ name: packageJson.name ?? "alpha-classic-cli",
3997
+ version: packageJson.version ?? "0.0.0"
3998
+ },
3999
+ sessionStore
4000
+ );
3933
4001
  });
3934
4002
  program.command("login").description("Start Alpha CLI device authorization login").option("--token <token>", "Debug fallback token").option("--user-id <id>", "Current user id").option("--office-id <id>", "Current office id").option("--name <name>", "Current user name").option("--no-wait", "Create device authorization and print JSON only").option("--json", "Print final result as JSON envelope").option("--device-code <deviceCode>", "Poll an existing device code").option("--timeout-ms <ms>", "Device authorization wait timeout", parseInteger).option("--no-open-browser", "Do not open browser when token is missing").action(
3935
4003
  async (options) => {
@@ -3992,7 +4060,7 @@ async function main() {
3992
4060
  program.command("doctor").description("Inspect config, session, skill install, and API health").action(async () => {
3993
4061
  await runDoctor(sessionStore);
3994
4062
  });
3995
- program.command("env").description("Inspect the build-time environment").argument("[action]", "Action: list, current").argument("[name]", "Environment name for list/current only").action(async (action, name) => {
4063
+ program.command("env").description("Inspect or switch the current environment").argument("[action]", "Action: list, current, use").argument("[name]", "Environment name for env use: local, dev, test, prod").action(async (action, name) => {
3996
4064
  await runEnvCommand(action, name, sessionStore);
3997
4065
  });
3998
4066
  program.command("api").description("Call a raw API endpoint").argument("<method>", "HTTP method").argument("<path>", "API path").option("--params <json>", "Query params JSON object").option("--data <json>", "Request body JSON").action(