@epoch-agent/cli 1.1.0 → 2.0.0

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
@@ -14,7 +14,7 @@ CLI 入口。装了它才有 `epoch` 这个可执行文件。
14
14
  [docs/CLI.md](../../docs/CLI.md)**,这里不重复一遍——两处抄同一份清单必然漂。
15
15
 
16
16
  ```bash
17
- epoch model # 首次使用:交互式选 provider + 模型,key 写进 ~/.epoch/.env
17
+ epoch model # 首次使用:交互式添加一条模型(「我的模型」),key 进系统钥匙串
18
18
  epoch doctor # 装不上 / 跑不起来时第一个跑这个
19
19
  ```
20
20
 
@@ -56,35 +56,29 @@ epoch doctor # 装不上 / 跑不起来时第一个跑这个
56
56
  `applyRunFlags`。**加新 flag 时挂进那一个函数。**
57
57
 
58
58
  这条规矩是修出来的(前因见
59
- [方案 28 验收记录第七章](../../docs/verify/VERIFY_RECORD-28-headless-protocol.md)):`--provider` 的值校验原来住在 `runOnce`
59
+ [方案 28 验收记录第七章](../../docs/verify/VERIFY_RECORD-28-headless-protocol.md)):`--model` 的值校验原来住在 `runOnce`
60
60
  里、排在分流后面,而打错一个带值的 flag 必然让位置参数为空 —— 于是
61
- `epoch -p "跑一下测试"` 这类手滑永远走不到校验,一律表现为**静默进 TUI**,
61
+ `epoch -m "跑一下测试"` 这类手滑永远走不到校验,一律表现为**静默进 TUI**,
62
62
  一个字都不说。
63
63
 
64
- 九个走环境变量的(其余全局选项是解析成 `BuildRuntimeOptions` 的字段传下去的):
64
+ 七个走环境变量的(其余全局选项是解析成 `BuildRuntimeOptions` 的字段传下去的):
65
65
 
66
66
  | 选项 | 环境变量 | 值 |
67
67
  | ------------------ | ---------------------- | ------------------------------------ |
68
68
  | `--settings` | `EPOCH_SETTINGS` | 绝对路径 |
69
69
  | `--add-dir` | `EPOCH_ADD_DIR` | 绝对路径,按 `path.delimiter` 连起来 |
70
70
  | `--agent` | `EPOCH_AGENT` | 角色名原样 |
71
- | `-m/--model` | `EPOCH_MODEL` | 模型 id |
72
- | `--fallback-model` | `EPOCH_FALLBACK_MODEL` | 模型 id |
73
- | `-p/--provider` | `EPOCH_PROVIDER` | 收窄过的 provider 名 |
74
- | `--base-url` | `EPOCH_BASE_URL` | http(s) 地址 |
71
+ | `-m/--model` | `EPOCH_MODEL` | `@<id>`(「我的模型」里的一条) |
72
+ | `--fallback-model` | `EPOCH_FALLBACK_MODEL` | `@<id>` |
75
73
  | `--permission` | `EPOCH_PERMISSION` | 收窄过的权限级别 |
76
74
  | `-c` / `-r` | `EPOCH_RESUME` | 选中的会话 id |
77
75
 
78
- 后四行里有两个的语义**比「覆盖一格」重**(2026-09-29):
76
+ ⚠️ **2.0.0 删掉了 `-p/--provider` 和 `EPOCH_PROVIDER`**(老写法的入口:模型只认
77
+ 「我的模型」条目,每一条自带走哪家)。设了那个变量今天会被忽略并报一条诊断。
79
78
 
80
- - `EPOCH_PROVIDER` 是**真钉住** —— 引擎在本家 provider 没 key 时会把 type 换成
81
- `.env` 里配了 key 的那一家(`applySecretsFromEnv` 第 2 步),显式覆盖现在排在
82
- 它之后,所以 `-p openai-compatible` 不会被一把 `DEEPSEEK_API_KEY` 推翻;
83
- - `EPOCH_BASE_URL` 是**统一端点**:设了它 ⇒ 地址换成它,**且 type 强制落到
84
- `openai-compatible`**(收 `baseUrl` 的只有 `openai` / `openai-compatible` 和
85
- 四家国产,其余各家只换地址会静默打回上游官网)。两个都设时以它为准。
86
- 判据全文与复现在 [CONFIGURATION](../../docs/CONFIGURATION.md) 和
87
- [core 的用例](../core/__tests__/config-endpoint-override.test.ts)。
79
+ ⚠️ **`--base-url` / `EPOCH_BASE_URL` 2026-10-15 删了**:端点是「我的模型」条目自己的属性
80
+ (`hostPreset.models[].baseUrl`,或者用户在设置页给那一条填的地址),引擎不再有进程级的
81
+ 「统一端点」。设着那个变量的机器会收到一条诊断。
88
82
 
89
83
  因为无参进 TUI 那条路**不经过 `runOnce`**——TUI 起的是另一个进程,选项对象过不去,
90
84
  只有环境变量带得过去。路径一律转**绝对**:子进程的 cwd 不保证一样。
@@ -93,7 +87,7 @@ epoch doctor # 装不上 / 跑不起来时第一个跑这个
93
87
  只有 `EPOCH_RESUME` 要显式塞,因为它是**算出来的**(`-c` 要查库、`-r` 不带值
94
88
  要弹选择器)。加新 flag 时按这条分。
95
89
 
96
- 取值是**开放集合**的那三个(`-m` / `--fallback-model` / `--base-url`)没有可选值
90
+ 取值是**开放集合**的那两个(`-m` / `--fallback-model`,收 `@<id>`)没有可选值
97
91
  清单可以对,所以判**字形**:模型 id 得是 ASCII 可见字符,base URL 得能被
98
92
  `new URL()` 解析且是 http(s)。卡得松是刻意的 —— 误伤一个合法模型名的代价是
99
93
  「那个模型压根用不了」,比放过一句话严重得多。
@@ -25,11 +25,10 @@ function readOrEmpty(path) {
25
25
  return "";
26
26
  }
27
27
  }
28
-
29
28
  export {
29
+ exportSecretsToEnv,
30
30
  parseEnvText,
31
- setEnvVarText,
31
+ setEnvVarText as setEnvVar,
32
32
  writeEnvFile,
33
- exportSecretsToEnv,
34
- writeProviderSecret
33
+ writeProviderSecret as writeProviderKey
35
34
  };
package/dist/index.js CHANGED
@@ -1,7 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import {
3
- writeProviderSecret
4
- } from "./chunk-4SOT24BS.js";
5
2
  // src/index.ts
6
3
  import { Command } from "commander";
7
4
  import { t as t39 } from "@epoch-agent/infra";
@@ -38,7 +35,8 @@ function isCancellation(err2) {
38
35
  var EXPECTED_FAILURES = {
39
36
  ManagedPolicyError: EXIT_CODES.MANAGED_POLICY,
40
37
  AgentRoleError: EXIT_CODES.FAILURE,
41
- SettingsFileError: EXIT_CODES.FAILURE
38
+ SettingsFileError: EXIT_CODES.FAILURE,
39
+ ModelEntryError: EXIT_CODES.FAILURE
42
40
  };
43
41
  function expectedFailureExitCode(err2) {
44
42
  if (!(err2 instanceof Error)) return void 0;
@@ -346,7 +344,7 @@ import {
346
344
  import { t as t4 } from "@epoch-agent/infra";
347
345
  // src/paths.ts
348
346
  import { existsSync, mkdirSync } from "fs";
349
- import { hasProviderCredentials } from "@epoch-agent/core";
347
+ import { hasUsableModel as coreHasUsableModel, hasProviderCredentials } from "@epoch-agent/core";
350
348
  import { configPath, envPath, resolveHomeDir } from "@epoch-agent/infra";
351
349
  var EPOCH_HOME = resolveHomeDir();
352
350
  var CONFIG_PATH = configPath(EPOCH_HOME);
@@ -357,6 +355,9 @@ function ensureEpochHome() {
357
355
  function hasCredentials() {
358
356
  return hasProviderCredentials(EPOCH_HOME);
359
357
  }
358
+ function hasUsableModel() {
359
+ return coreHasUsableModel(EPOCH_HOME);
360
+ }
360
361
  // src/commands/compliance.ts
361
362
  var log2 = (msg) => process.stdout.write(msg + "\n");
362
363
  function buildEngine() {
@@ -452,11 +453,10 @@ import { existsSync as existsSync2, readFileSync } from "fs";
452
453
  import { maskApiKey, t as t5 } from "@epoch-agent/infra";
453
454
  import {
454
455
  API_KEY_ENV_VARS,
456
+ isEntrySecretName,
455
457
  isPermissionLevel,
456
- isProviderType,
457
458
  parseModelRef,
458
459
  PERMISSION_LEVELS,
459
- PROVIDER_TYPES,
460
460
  SHELL_KINDS
461
461
  } from "@epoch-agent/protocol";
462
462
  // src/files/config-yaml.ts
@@ -525,7 +525,6 @@ function knownKeys() {
525
525
  ([section, fields]) => Object.keys(fields).map((field) => `${section}.${field}`)
526
526
  );
527
527
  return [
528
- "provider",
529
528
  "model",
530
529
  "models.utility",
531
530
  "fallback.model",
@@ -554,10 +553,7 @@ function registerConfigCommand(program2) {
554
553
  });
555
554
  cmd.command("path").description(t5("cli.config.path")).action(() => log3(CONFIG_PATH));
556
555
  cmd.command("get").description(t5("cli.config.get")).argument("<key>", t5("cli.config.keys")).action((key) => {
557
- const value = readKey(
558
- readConfigYaml(CONFIG_PATH),
559
- key === "provider" ? "provider.type" : key
560
- );
556
+ const value = readKey(readConfigYaml(CONFIG_PATH), key);
561
557
  if (value === void 0) throw new CliError(t5("cli.config.unset_key", { key }));
562
558
  log3(value);
563
559
  });
@@ -604,7 +600,7 @@ async function printSecretStatus(store) {
604
600
  detail: store.detail
605
601
  })}`
606
602
  );
607
- const names = (await store.list()).filter((n) => API_KEY_ENV_VARS.includes(n));
603
+ const names = (await store.list()).filter(isModelSecret);
608
604
  if (names.length === 0) {
609
605
  log3(t5("cli.config.secret_empty"));
610
606
  return;
@@ -631,8 +627,12 @@ async function exportSecrets(store) {
631
627
  return;
632
628
  }
633
629
  ensureEpochHome();
634
- const { exportSecretsToEnv } = await import("./env-file-ERS45V7K.js");
635
- const written = await exportSecretsToEnv(store, ENV_PATH, API_KEY_ENV_VARS);
630
+ const { exportSecretsToEnv } = await import("./env-file-UWCPUY3C.js");
631
+ const written = await exportSecretsToEnv(
632
+ store,
633
+ ENV_PATH,
634
+ (await store.list()).filter(isModelSecret)
635
+ );
636
636
  if (written.length === 0) {
637
637
  log3(t5("cli.config.export_nothing"));
638
638
  return;
@@ -642,17 +642,9 @@ async function exportSecrets(store) {
642
642
  }
643
643
  function applySet(yaml, key, value) {
644
644
  switch (key) {
645
- case "provider":
646
- if (!isProviderType(value)) {
647
- throw new CliError(
648
- t5("cli.config.unknown_provider", { value }),
649
- 1,
650
- t5("cli.config.supported", { list: PROVIDER_TYPES.join(", ") })
651
- );
652
- }
653
- return yaml.replace(/^(\s*)type:.*$/m, `$1type: ${value}`);
654
645
  case "model":
655
- return setScalar(yaml, "model", value);
646
+ assertEntryRef(key, value);
647
+ return setScalar(yaml, "model", quoteEntryRef(value));
656
648
  case "permission":
657
649
  if (!isPermissionLevel(value)) {
658
650
  throw new CliError(
@@ -674,11 +666,9 @@ function applySet(yaml, key, value) {
674
666
  }
675
667
  case "models.utility":
676
668
  case "fallback.model": {
677
- if (!parseModelRef(value)) {
678
- throw new CliError(t5("cli.config.utility_empty"), 1, t5("cli.config.utility_hint"));
679
- }
669
+ assertEntryRef(key, value);
680
670
  const [section, field] = key.split(".");
681
- return setSectionField(yaml, section, field, value);
671
+ return setSectionField(yaml, section, field, quoteEntryRef(value));
682
672
  }
683
673
  default: {
684
674
  const scalar = SCALAR_FIELDS[key];
@@ -714,6 +704,20 @@ function splitSection(key) {
714
704
  const dot = key.indexOf(".");
715
705
  return dot < 0 ? [key, void 0] : [key.slice(0, dot), key.slice(dot + 1)];
716
706
  }
707
+ function assertEntryRef(key, value) {
708
+ if (parseModelRef(value)) return;
709
+ throw new CliError(
710
+ t5("cli.config.model_ref_invalid", { key, value }),
711
+ 1,
712
+ t5("cli.config.model_ref_hint")
713
+ );
714
+ }
715
+ function quoteEntryRef(value) {
716
+ return `'${value.trim()}'`;
717
+ }
718
+ function isModelSecret(name) {
719
+ return isEntrySecretName(name) || API_KEY_ENV_VARS.includes(name);
720
+ }
717
721
  // src/commands/mcp.ts
718
722
  import { t as t6, uiDateLocale } from "@epoch-agent/infra";
719
723
  import {
@@ -816,14 +820,14 @@ function guardAsync(fn) {
816
820
  }
817
821
  // src/commands/model.ts
818
822
  import { input, password, select } from "@inquirer/prompts";
819
- import { isNonInteractive, readProviderKeyEnv } from "@epoch-agent/core";
823
+ import { isNonInteractive, loadConfig as loadConfig2 } from "@epoch-agent/core";
820
824
  import { t as t7 } from "@epoch-agent/infra";
821
825
  import {
822
- apiKeyEnvVar,
826
+ entryDisplayName,
823
827
  PROVIDER_INFOS,
824
- PROVIDER_TYPES as PROVIDER_TYPES2
828
+ PROVIDER_TYPES
825
829
  } from "@epoch-agent/protocol";
826
- import { providerLabel } from "@epoch-agent/runtime";
830
+ import { buildModelEntriesControl, providerLabel } from "@epoch-agent/runtime";
827
831
  var log5 = (msg) => process.stdout.write(msg + "\n");
828
832
  var CUSTOM = "__custom__";
829
833
  function registerModelCommand(program2) {
@@ -838,36 +842,45 @@ function registerModelCommand(program2) {
838
842
  }
839
843
  async function refreshCache() {
840
844
  const { clearModelCache } = await import("@epoch-agent/core");
841
- for (const t40 of PROVIDER_TYPES2) clearModelCache(EPOCH_HOME, t40);
845
+ for (const type of PROVIDER_TYPES) clearModelCache(EPOCH_HOME, type);
842
846
  log5(t7("model.cache_cleared"));
843
847
  }
844
- function readCurrentSelection() {
845
- const yaml = readConfigYaml(CONFIG_PATH);
846
- return { provider: readKey(yaml, "provider.type"), model: readKey(yaml, "model") };
847
- }
848
848
  async function runWizard() {
849
849
  await ensureSecrets();
850
- const current = readCurrentSelection();
850
+ const control = buildModelEntriesControl({
851
+ homeDir: EPOCH_HOME,
852
+ config: () => loadConfig2(),
853
+ onChanged: () => void 0,
854
+ onRefChanged: () => void 0
855
+ });
851
856
  const provider = await select({
852
857
  message: t7("model.pick_provider"),
853
- choices: providerChoices(current.provider),
854
- pageSize: listPageSize(PROVIDER_INFOS.filter((p) => p.interactive).length),
855
- ...isKnownProvider(current.provider) ? { default: current.provider } : {}
858
+ choices: providerChoices(),
859
+ pageSize: listPageSize(PROVIDER_INFOS.filter((p) => p.interactive).length)
856
860
  });
857
861
  const baseUrl = provider === "openai-compatible" ? await askBaseUrl() : void 0;
858
- const keyForDiscover = await resolveApiKey(provider);
859
- const { discoverModels } = await import("@epoch-agent/core");
860
- const result = await discoverModels(EPOCH_HOME, provider, keyForDiscover, baseUrl);
861
- log5(describeDiscovery(result.source, result.models.length, keyForDiscover !== ""));
862
- const model = await pickModel(result.models, result.source, carriedModel(provider, current));
863
- let yaml = readConfigYaml(CONFIG_PATH);
864
- yaml = setSectionField(yaml, "provider", "type", provider);
865
- if (baseUrl) yaml = setSectionField(yaml, "provider", "baseUrl", baseUrl);
866
- yaml = setScalar(yaml, "model", model);
867
- writeConfigYaml(CONFIG_PATH, yaml);
868
- log5(`
869
- \u2705 ${provider} / ${model}
870
- ${t7("model.ready")}`);
862
+ const apiKey = await askApiKey(provider);
863
+ const draft = { provider, ...baseUrl ? { baseUrl } : {} };
864
+ const models = await control.discover({ ...draft, model: "" }, apiKey ?? void 0);
865
+ log5(models.length > 0 ? t7("model.from_api", { count: models.length }) : t7("model.list_empty"));
866
+ const model = await pickModel(models);
867
+ let saved;
868
+ try {
869
+ saved = await control.save({ ...draft, model }, apiKey ?? void 0);
870
+ } catch (err2) {
871
+ throw new CliError(
872
+ t7("model.save_failed", { reason: err2 instanceof Error ? err2.message : String(err2) }),
873
+ EXIT_CODES.FAILURE,
874
+ t7("model.save_failed_hint")
875
+ );
876
+ }
877
+ const { entry } = saved;
878
+ control.setRef("model", entry.id);
879
+ log5(
880
+ `
881
+ \u2705 ${t7("model.saved", { name: entryDisplayName(entry), id: entry.id })}
882
+ ${t7("model.ready")}`
883
+ );
871
884
  }
872
885
  async function ensureSecrets() {
873
886
  try {
@@ -877,83 +890,65 @@ async function ensureSecrets() {
877
890
  log5(t7("model.secret_init_failed", { reason: describeError(err2) }));
878
891
  }
879
892
  }
880
- async function resolveApiKey(provider) {
881
- const envKey = apiKeyEnvVar(provider);
882
- if (!envKey) return "";
883
- const existing = readProviderKeyEnv(EPOCH_HOME)[envKey];
884
- const message = existing ? t7("model.api_key_existing", { envKey }) : t7("model.api_key", { envKey });
885
- const typed = (await password({ message, mask: "*" })).trim();
886
- if (!typed) return existing ?? "";
887
- await saveApiKey(envKey, typed);
888
- return typed;
889
- }
890
- async function saveApiKey(envKey, apiKey) {
891
- const result = await writeProviderSecret(envKey, apiKey, ENV_PATH);
892
- log5(result.encrypted ? t7("model.key_stored", { detail: result.detail }) : ` \u26A0 ${result.detail}`);
893
+ async function askApiKey(provider) {
894
+ if (provider === "ollama") return null;
895
+ const optional = provider === "openai-compatible";
896
+ for (; ; ) {
897
+ const typed = (await password({
898
+ message: optional ? t7("model.api_key_optional") : t7("model.api_key"),
899
+ mask: "*"
900
+ })).trim();
901
+ if (typed || optional) return typed || null;
902
+ }
893
903
  }
894
904
  async function askBaseUrl() {
895
- const answer = (await input({
896
- message: t7("model.ask_base_url"),
897
- default: "http://localhost:8080/v1"
898
- })).trim();
899
- return answer || void 0;
900
- }
901
- async function pickModel(models, source, currentModel) {
902
- const choices3 = modelChoices(models, source, currentModel);
903
- if (choices3.length === 0) {
904
- const fallback2 = currentModel ?? "gpt-4o-mini";
905
- return await input({ message: t7("model.type_model"), default: fallback2 }) || fallback2;
906
- }
907
- const picked = await select({
908
- message: t7("model.pick_model"),
909
- choices: choices3,
910
- pageSize: listPageSize(choices3.length),
911
- ...currentModel && models.includes(currentModel) ? { default: currentModel } : {}
912
- });
913
- if (picked !== CUSTOM) return picked;
914
- const fallback = currentModel ?? models[0] ?? "gpt-4o-mini";
915
- return await input({ message: t7("model.type_model"), default: fallback }) || fallback;
905
+ for (; ; ) {
906
+ const answer = (await input({ message: t7("model.ask_base_url"), default: "http://localhost:8080/v1" })).trim();
907
+ if (!answer) return void 0;
908
+ if (isHttpUrl(answer)) return answer;
909
+ log5(t7("model.base_url_invalid", { value: answer }));
910
+ }
916
911
  }
917
- function isKnownProvider(value) {
918
- return PROVIDER_INFOS.some((p) => p.interactive && p.type === value);
912
+ function isHttpUrl(value) {
913
+ try {
914
+ const url = new URL(value);
915
+ return url.protocol === "http:" || url.protocol === "https:";
916
+ } catch {
917
+ return false;
918
+ }
919
919
  }
920
- function carriedModel(chosenProvider, current) {
921
- return chosenProvider === current.provider ? current.model : void 0;
920
+ async function pickModel(models) {
921
+ const choices3 = modelChoices(models);
922
+ if (choices3.length > 0) {
923
+ const picked = await select({
924
+ message: t7("model.pick_model"),
925
+ choices: choices3,
926
+ pageSize: listPageSize(choices3.length)
927
+ });
928
+ if (picked !== CUSTOM) return picked;
929
+ }
930
+ for (; ; ) {
931
+ const typed = (await input({ message: t7("model.type_model") })).trim();
932
+ if (typed) return typed;
933
+ }
922
934
  }
923
- function providerChoices(currentProvider) {
924
- return PROVIDER_INFOS.filter((p) => p.interactive).map((p) => {
925
- const label = providerLabel(p);
926
- return {
927
- name: p.type === currentProvider ? t7("model.current", { label }) : label,
928
- value: p.type
929
- };
930
- });
935
+ function providerChoices() {
936
+ return PROVIDER_INFOS.filter((p) => p.interactive).map((p) => ({
937
+ name: providerLabel(p),
938
+ value: p.type
939
+ }));
931
940
  }
932
- function modelChoices(models, source, currentModel) {
941
+ function modelChoices(models) {
933
942
  if (models.length === 0) return [];
934
- const choices3 = models.map((m) => ({
935
- name: m === currentModel ? t7("model.current", { label: m }) : m,
936
- value: m
937
- }));
938
- if (currentModel && !models.includes(currentModel)) {
939
- choices3.unshift({
940
- name: t7("model.current_not_listed", { label: currentModel }),
941
- value: currentModel
942
- });
943
- }
944
- if (source !== "live") choices3.push({ name: t7("model.custom_entry"), value: CUSTOM });
945
- return choices3;
943
+ return [
944
+ ...models.map((m) => ({ name: m, value: m })),
945
+ { name: t7("model.custom_entry"), value: CUSTOM }
946
+ ];
946
947
  }
947
948
  function listPageSize(itemCount, rows = process.stdout.rows) {
948
949
  const height = rows && rows > 0 ? rows : 24;
949
950
  return Math.min(itemCount, Math.max(3, height - 3));
950
951
  }
951
- function describeDiscovery(source, count, hasKey) {
952
- if (source === "live") return t7("model.from_api", { count });
953
- const why = hasKey ? t7("model.why_fetch_failed") : t7("model.why_no_key");
954
- const what = source === "cache" ? t7("model.fallback_cache") : t7("model.fallback_static");
955
- return t7("model.fallback_line", { why, what });
956
- }
957
952
  function describeError(err2) {
958
953
  return err2 instanceof Error ? err2.message : String(err2);
959
954
  }
@@ -1377,11 +1372,7 @@ import { dirname as dirname4, join as join5 } from "path";
1377
1372
  import { fileURLToPath as fileURLToPath3 } from "url";
1378
1373
  import { isNonInteractive as isNonInteractive8, OPERATION_TYPES as OPERATION_TYPES3, PERMISSION_LEVELS as PERMISSION_LEVELS3 } from "@epoch-agent/core";
1379
1374
  import { guardSpawn as guardSpawn3, t as t25 } from "@epoch-agent/infra";
1380
- import {
1381
- HEADLESS_INPUT_FORMATS as HEADLESS_INPUT_FORMATS2,
1382
- HEADLESS_OUTPUT_FORMATS as HEADLESS_OUTPUT_FORMATS2,
1383
- PROVIDER_TYPES as PROVIDER_TYPES4
1384
- } from "@epoch-agent/protocol";
1375
+ import { HEADLESS_INPUT_FORMATS as HEADLESS_INPUT_FORMATS2, HEADLESS_OUTPUT_FORMATS as HEADLESS_OUTPUT_FORMATS2 } from "@epoch-agent/protocol";
1385
1376
  // src/headless/session.ts
1386
1377
  import { OPERATION_TYPES } from "@epoch-agent/core";
1387
1378
  import { t as t12 } from "@epoch-agent/infra";
@@ -1654,7 +1645,7 @@ function initInfoOf(runtime, cwd) {
1654
1645
  return {
1655
1646
  sessionId: runtime.sessionId,
1656
1647
  cwd,
1657
- model: runtime.config.model,
1648
+ model: runtime.model?.get().model ?? runtime.config.model ?? "",
1658
1649
  ...provider ? { provider } : {},
1659
1650
  permissionLevel: runtime.permissions.level(),
1660
1651
  tools: runtime.tools.map((t40) => t40.name),
@@ -2803,7 +2794,7 @@ import {
2803
2794
  createImportGate,
2804
2795
  ImportTrustStore,
2805
2796
  isNonInteractive as isNonInteractive6,
2806
- loadConfig as loadConfig3,
2797
+ loadConfig as loadConfig4,
2807
2798
  resolveProjectRoot as resolveProjectRoot2,
2808
2799
  scanInstructions,
2809
2800
  setImportGate,
@@ -2817,7 +2808,7 @@ import {
2817
2808
  hasReadTierContent,
2818
2809
  inventoryProjectExtensions,
2819
2810
  isNonInteractive as isNonInteractive5,
2820
- loadConfig as loadConfig2,
2811
+ loadConfig as loadConfig3,
2821
2812
  resolveProjectRoot,
2822
2813
  TrustManager
2823
2814
  } from "@epoch-agent/core";
@@ -2899,7 +2890,7 @@ function restoreStdinDefault() {
2899
2890
  stdin.resume();
2900
2891
  }
2901
2892
  async function maybePromptForTrust(opts = {}) {
2902
- const config = opts.config ?? loadConfig2();
2893
+ const config = opts.config ?? loadConfig3();
2903
2894
  const store = opts.store ?? new TrustManager(trustPath(config.homeDir));
2904
2895
  const print = opts.print ?? ((msg) => process.stdout.write(msg + "\n"));
2905
2896
  const target = trustPromptTarget({
@@ -3017,7 +3008,7 @@ function choices2() {
3017
3008
  ];
3018
3009
  }
3019
3010
  async function maybePromptForExternalImports(opts = {}) {
3020
- const config = opts.config ?? loadConfig3();
3011
+ const config = opts.config ?? loadConfig4();
3021
3012
  const store = opts.store ?? new ImportTrustStore(trustedImportsPath(config.homeDir));
3022
3013
  const print = opts.print ?? ((msg) => process.stdout.write(msg + "\n"));
3023
3014
  const targets = externalImportTargets({
@@ -3359,7 +3350,7 @@ function reportHeadlessAudit(permission) {
3359
3350
  // src/commands/run-overrides.ts
3360
3351
  import { isPermissionLevel as isPermissionLevel2, PERMISSION_LEVELS as PERMISSION_LEVELS2 } from "@epoch-agent/core";
3361
3352
  import { t as t23 } from "@epoch-agent/infra";
3362
- import { isProviderType as isProviderType2, PROVIDER_TYPES as PROVIDER_TYPES3 } from "@epoch-agent/protocol";
3353
+ import { parseModelRef as parseModelRef2 } from "@epoch-agent/protocol";
3363
3354
  function applyRunFlags(opts) {
3364
3355
  applySettingsPath(opts.settings);
3365
3356
  applyAddDirs(opts.addDir);
@@ -3373,17 +3364,6 @@ function applyOverrides(opts) {
3373
3364
  if (opts.fallbackModel) {
3374
3365
  process.env.EPOCH_FALLBACK_MODEL = assertModelName(opts.fallbackModel, "--fallback-model");
3375
3366
  }
3376
- if (opts.baseUrl) process.env.EPOCH_BASE_URL = assertHttpUrl(opts.baseUrl);
3377
- if (opts.provider) {
3378
- if (!isProviderType2(opts.provider)) {
3379
- throw new CliError(
3380
- t23("flags.provider_unknown", { value: opts.provider }),
3381
- 1,
3382
- t23("flags.choices", { choices: PROVIDER_TYPES3.join(", ") })
3383
- );
3384
- }
3385
- process.env.EPOCH_PROVIDER = opts.provider;
3386
- }
3387
3367
  if (opts.permission) {
3388
3368
  if (!isPermissionLevel2(opts.permission)) {
3389
3369
  throw new CliError(
@@ -3395,28 +3375,15 @@ function applyOverrides(opts) {
3395
3375
  process.env.EPOCH_PERMISSION = opts.permission;
3396
3376
  }
3397
3377
  }
3398
- var MODEL_ID = /^[!-~]+$/;
3399
3378
  function assertModelName(value, flag) {
3400
3379
  const spec = value.trim();
3401
- if (MODEL_ID.test(spec)) return value;
3380
+ if (parseModelRef2(spec)) return spec;
3402
3381
  throw new CliError(
3403
3382
  t23("flags.model_not_a_name", { flag, value }),
3404
3383
  1,
3405
3384
  t23("flags.model_not_a_name_hint", { value: spec })
3406
3385
  );
3407
3386
  }
3408
- function assertHttpUrl(value) {
3409
- try {
3410
- const url = new URL(value.trim());
3411
- if (url.protocol === "http:" || url.protocol === "https:") return value;
3412
- } catch {
3413
- }
3414
- throw new CliError(
3415
- t23("flags.base_url_invalid", { value }),
3416
- 1,
3417
- t23("flags.base_url_invalid_hint", { value: value.trim() })
3418
- );
3419
- }
3420
3387
  // src/commands/sessions.ts
3421
3388
  import { writeFileSync as writeFileSync2 } from "fs";
3422
3389
  import {
@@ -3630,7 +3597,7 @@ function registerRunCommand(program2) {
3630
3597
  t25("run.opt_allow_operation", { types: OPERATION_TYPES3.join(" / ") }),
3631
3598
  collect,
3632
3599
  []
3633
- ).option("-i, --image <path>", t25("run.opt_image"), collect, []).option("-c, --continue", t25("run.opt_continue")).option("-r, --resume [id]", t25("run.opt_resume")).option("-m, --model <name>", t25("run.opt_model")).option("--fallback-model <name>", t25("run.opt_fallback_model")).option("-p, --provider <type>", t25("run.opt_provider", { types: PROVIDER_TYPES4.join(" / ") })).option("--base-url <url>", t25("run.opt_base_url")).option(
3600
+ ).option("-i, --image <path>", t25("run.opt_image"), collect, []).option("-c, --continue", t25("run.opt_continue")).option("-r, --resume [id]", t25("run.opt_resume")).option("-m, --model <name>", t25("run.opt_model")).option("--fallback-model <name>", t25("run.opt_fallback_model")).option(
3634
3601
  "--permission <level>",
3635
3602
  t25("run.opt_permission", { levels: PERMISSION_LEVELS3.join(" / ") })
3636
3603
  ).option("--settings <file>", t25("run.opt_settings")).option("--add-dir <dir>", t25("run.opt_add_dir"), collect, []).option("--agent <role>", t25("run.opt_agent")).option("--worktree", t25("run.opt_worktree")).option("--json", t25("run.opt_json")).option(
@@ -3670,7 +3637,7 @@ function registerRunCommand(program2) {
3670
3637
  t25("run.conflict_prompt_tool_hint")
3671
3638
  );
3672
3639
  }
3673
- if (!hasCredentials()) {
3640
+ if (!hasUsableModel()) {
3674
3641
  throw new CliError(
3675
3642
  t25("run.no_credentials_stream"),
3676
3643
  EXIT_CODES.FAILURE,
@@ -3682,7 +3649,7 @@ function registerRunCommand(program2) {
3682
3649
  }
3683
3650
  const carried = resumeArg.kind === "pick" ? resumeArg.query : void 0;
3684
3651
  const prompt = composePrompt(query ?? carried, await readStdin2());
3685
- if (!hasCredentials()) {
3652
+ if (!hasUsableModel()) {
3686
3653
  log8(t25("run.welcome"));
3687
3654
  return;
3688
3655
  }
@@ -3792,6 +3759,7 @@ import {
3792
3759
  isOperationType as isOperationType2,
3793
3760
  isPermissionLevel as isPermissionLevel3,
3794
3761
  OPERATION_TYPES as OPERATION_TYPES4,
3762
+ parseModelRef as parseModelRef3,
3795
3763
  PERMISSION_LEVELS as PERMISSION_LEVELS4,
3796
3764
  SCHEDULE_INTERVAL_MAX_MINUTES,
3797
3765
  SCHEDULE_INTERVAL_MIN_MINUTES
@@ -4127,6 +4095,7 @@ function buildInput(opts, trigger, permission) {
4127
4095
  t28("schedule.err_budget_hint")
4128
4096
  );
4129
4097
  }
4098
+ if (opts.model) assertModelRef(opts.model);
4130
4099
  return {
4131
4100
  name: opts.name ?? "",
4132
4101
  prompt: opts.prompt ?? "",
@@ -4165,6 +4134,14 @@ function printSummary(def) {
4165
4134
  log9("");
4166
4135
  log9(t28("schedule.created_next", { id: def.id.slice(0, 12) }));
4167
4136
  }
4137
+ function assertModelRef(value) {
4138
+ if (parseModelRef3(value)) return;
4139
+ throw new CliError(
4140
+ t28("schedule.err_model_ref", { value }),
4141
+ EXIT_CODES.FAILURE,
4142
+ t28("schedule.err_model_ref_hint")
4143
+ );
4144
+ }
4168
4145
  // src/schedule/doctor.ts
4169
4146
  import { diagnoseSchedules, pruneSchedules, repairSchedules } from "@epoch-agent/core";
4170
4147
  import { t as t29 } from "@epoch-agent/infra";
@@ -4469,7 +4446,7 @@ import { statfs } from "fs/promises";
4469
4446
  import {
4470
4447
  describeIsolation,
4471
4448
  getConfigIssues,
4472
- loadConfig as loadConfig4,
4449
+ loadConfig as loadConfig5,
4473
4450
  SANDBOX_COVERS,
4474
4451
  SANDBOX_EXCLUDES
4475
4452
  } from "@epoch-agent/core";
@@ -4562,7 +4539,7 @@ async function describeDisk(path = ".") {
4562
4539
  }
4563
4540
  function describeConfig() {
4564
4541
  if (!existsSync7(CONFIG_PATH)) return t35("cli.status.config_absent");
4565
- loadConfig4();
4542
+ loadConfig5();
4566
4543
  const n = getConfigIssues().length;
4567
4544
  return n === 0 ? t35("cli.status.config_present") : t35("cli.status.config_present_with_issues", { count: n });
4568
4545
  }
@@ -4838,7 +4815,7 @@ function registerStatusCommands(program2) {
4838
4815
  const avail = await describeDisk();
4839
4816
  if (avail) log10(t35("cli.doctor.disk", { avail }));
4840
4817
  log10(`${hasCredentials() ? "\u2713" : "\u25CB"} ${t35("cli.doctor.credentials")}`);
4841
- const configIssues = existsSync7(CONFIG_PATH) ? (loadConfig4(), getConfigIssues()) : [];
4818
+ const configIssues = existsSync7(CONFIG_PATH) ? (loadConfig5(), getConfigIssues()) : [];
4842
4819
  const configMark = !existsSync7(CONFIG_PATH) ? "\u25CB" : configIssues.length > 0 ? "\u26A0" : "\u2713";
4843
4820
  log10(`${configMark} config: ${CONFIG_PATH}`);
4844
4821
  try {
@@ -4913,7 +4890,7 @@ import { resolve as resolve4 } from "path";
4913
4890
  import {
4914
4891
  hasExecTierContent as hasExecTierContent2,
4915
4892
  inventoryProjectExtensions as inventoryProjectExtensions2,
4916
- loadConfig as loadConfig5,
4893
+ loadConfig as loadConfig6,
4917
4894
  TrustManager as TrustManager3
4918
4895
  } from "@epoch-agent/core";
4919
4896
  import { t as t36, trustPath as trustPath3, uiDateLocale as uiDateLocale4 } from "@epoch-agent/infra";
@@ -4984,7 +4961,7 @@ function registerTrustCommand(program2) {
4984
4961
  });
4985
4962
  }
4986
4963
  function printList3(tm) {
4987
- if (loadConfig5().trust?.enabled === false) {
4964
+ if (loadConfig6().trust?.enabled === false) {
4988
4965
  warn3(t36("trust.gate_off"));
4989
4966
  }
4990
4967
  log11(t36("trust.list_head", { path: trustPath3(EPOCH_HOME) }));
@@ -5213,17 +5190,17 @@ function fail(message) {
5213
5190
  process.exit(1);
5214
5191
  }
5215
5192
  // src/language.ts
5216
- import { loadConfig as loadConfig6, setDisplayCurrency } from "@epoch-agent/core";
5193
+ import { loadConfig as loadConfig7, setDisplayCurrency } from "@epoch-agent/core";
5217
5194
  import { resolveLang, setLang } from "@epoch-agent/infra";
5218
5195
  function applyConfiguredLanguage() {
5219
5196
  try {
5220
- setLang(resolveLang(loadConfig6().display?.language));
5197
+ setLang(resolveLang(loadConfig7().display?.language));
5221
5198
  } catch {
5222
5199
  }
5223
5200
  }
5224
5201
  function applyConfiguredCurrency() {
5225
5202
  try {
5226
- setDisplayCurrency(loadConfig6().display?.currency);
5203
+ setDisplayCurrency(loadConfig7().display?.currency);
5227
5204
  } catch {
5228
5205
  }
5229
5206
  }
package/dist/tui-entry.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/tui-entry.ts
2
- import { getCapability as getCapability2, loadKeybindings } from "@epoch-agent/core";
2
+ import { capabilityOfRef as capabilityOfRef2, loadKeybindings } from "@epoch-agent/core";
3
3
  import { keybindingsPath, t as t14 } from "@epoch-agent/infra";
4
4
  import { buildRuntime, withModelScope, withToolScope } from "@epoch-agent/runtime";
5
5
  import { DEFAULT_KEYBINDINGS, renderApp } from "@epoch-agent/tui";
@@ -33,7 +33,8 @@ function isCancellation(err) {
33
33
  var EXPECTED_FAILURES = {
34
34
  ManagedPolicyError: EXIT_CODES.MANAGED_POLICY,
35
35
  AgentRoleError: EXIT_CODES.FAILURE,
36
- SettingsFileError: EXIT_CODES.FAILURE
36
+ SettingsFileError: EXIT_CODES.FAILURE,
37
+ ModelEntryError: EXIT_CODES.FAILURE
37
38
  };
38
39
  function expectedFailureExitCode(err) {
39
40
  if (!(err instanceof Error)) return void 0;
@@ -447,7 +448,7 @@ function composeStartupNotices(parts) {
447
448
  }
448
449
  // src/tui-host.ts
449
450
  import {
450
- getCapability,
451
+ capabilityOfRef,
451
452
  listWorkspaceFiles,
452
453
  openArtifact,
453
454
  resolveMentions,
@@ -1461,13 +1462,8 @@ function buildHostActions(runtime, workDir) {
1461
1462
  supportsImages: () => {
1462
1463
  try {
1463
1464
  const sel = model?.get();
1464
- const id = sel?.model ?? runtime.config.model;
1465
- const caps = getCapability(
1466
- id,
1467
- runtime.config.homeDir,
1468
- sel?.provider ?? runtime.config.provider.type
1469
- );
1470
- return caps.supportsImages || caps.imagesUnknown === true;
1465
+ const caps = capabilityOfRef(runtime.config, sel ? `@${sel.entry}` : runtime.config.model);
1466
+ return caps ? caps.supportsImages || caps.imagesUnknown === true : false;
1471
1467
  } catch {
1472
1468
  return false;
1473
1469
  }
@@ -1563,7 +1559,7 @@ function buildHostActions(runtime, workDir) {
1563
1559
  ...model ? {
1564
1560
  getModelSelection: () => {
1565
1561
  const selection = model.get();
1566
- const { contextLength } = getCapability(selection.model, runtime.config.homeDir);
1562
+ const contextLength = capabilityOfRef(runtime.config, `@${selection.entry}`)?.contextLength ?? 0;
1567
1563
  return { selection, contextLength };
1568
1564
  },
1569
1565
  setModel: (ref, ctx) => {
@@ -1599,6 +1595,14 @@ function buildHostActions(runtime, workDir) {
1599
1595
  } : {}
1600
1596
  };
1601
1597
  }
1598
+ // src/tui-model-label.ts
1599
+ import { parseModelRef } from "@epoch-agent/protocol";
1600
+ function displayModelOf(config) {
1601
+ if (!config.model) return "unknown";
1602
+ const ref = parseModelRef(config.model);
1603
+ const entry = ref ? config.modelEntries?.find((e) => e.id === ref.entry) : void 0;
1604
+ return entry?.model ?? config.model;
1605
+ }
1602
1606
  // src/version.ts
1603
1607
  import { readFileSync as readFileSync2 } from "fs";
1604
1608
  import { dirname as dirname2, join as join3 } from "path";
@@ -1648,10 +1652,11 @@ ${runtime.diagnostics.join("\n")}
1648
1652
  `);
1649
1653
  process.exit(1);
1650
1654
  }
1651
- const model = config.model || "unknown";
1655
+ const modelRef = config.model;
1656
+ const model = displayModelOf(config);
1652
1657
  let contextLimit = 0;
1653
1658
  try {
1654
- contextLimit = getCapability2(model, config.homeDir).contextLength;
1659
+ contextLimit = capabilityOfRef2(config, modelRef)?.contextLength ?? 0;
1655
1660
  } catch {
1656
1661
  contextLimit = 0;
1657
1662
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@epoch-agent/cli",
3
- "version": "1.1.0",
3
+ "version": "2.0.0",
4
4
  "private": false,
5
5
  "description": "epoch-agent CLI 入口",
6
6
  "repository": {
@@ -22,12 +22,12 @@
22
22
  "commander": "^15.0.0",
23
23
  "ink": "^7.1.1",
24
24
  "react": "^19.2.8",
25
- "@epoch-agent/core": "1.1.0",
26
- "@epoch-agent/infra": "1.1.0",
27
- "@epoch-agent/server": "1.1.0",
28
- "@epoch-agent/runtime": "1.1.0",
29
- "@epoch-agent/protocol": "1.1.0",
30
- "@epoch-agent/tui": "^1.1.0"
25
+ "@epoch-agent/core": "2.0.0",
26
+ "@epoch-agent/infra": "2.0.0",
27
+ "@epoch-agent/protocol": "2.0.0",
28
+ "@epoch-agent/tui": "^2.0.0",
29
+ "@epoch-agent/server": "2.0.0",
30
+ "@epoch-agent/runtime": "2.0.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/node": "^22.20.1",
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- exportSecretsToEnv,
4
- parseEnvText,
5
- setEnvVarText,
6
- writeEnvFile,
7
- writeProviderSecret
8
- } from "./chunk-4SOT24BS.js";
9
- export {
10
- exportSecretsToEnv,
11
- parseEnvText,
12
- setEnvVarText as setEnvVar,
13
- writeEnvFile,
14
- writeProviderSecret as writeProviderKey
15
- };