@epoch-agent/cli 0.1.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/LICENSE ADDED
@@ -0,0 +1,219 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
203
+
204
+ --------------------------------------------------------------------------------
205
+
206
+ epoch-agent
207
+ Copyright 2024-2026 bowen
208
+
209
+ Portions of this software are derived from the Gemini CLI
210
+ (https://github.com/google-gemini/gemini-cli), Copyright 2025 Google LLC,
211
+ licensed under the Apache License, Version 2.0. Those files have been modified;
212
+ each one retains its original copyright notice and SPDX-License-Identifier
213
+ header. See the NOTICE file in the project source repository for the complete
214
+ list of derived files.
215
+
216
+ This software also quotes, with attribution, two lines of prose from OpenAI
217
+ Codex (https://github.com/openai/codex), Copyright 2025 OpenAI, licensed under
218
+ the Apache License, Version 2.0. No source file is a derived work of Codex.
219
+ See the NOTICE file for details.
package/README.md ADDED
@@ -0,0 +1,199 @@
1
+ # @epoch-agent/cli
2
+
3
+ CLI 入口。装了它才有 `epoch` 这个可执行文件。
4
+
5
+ - ✅ **做**:commander 参数解析、TUI 启动、审批与信任的终端交互、输出格式化、
6
+ 退出码、更新检查、shell 补全
7
+ - ❌ **不做**:装配(在 [runtime](../runtime))、领域逻辑(在 [core](../core))、
8
+ 渲染细节(在 [tui](../tui))
9
+ - **依赖**:[protocol](../protocol) + [infra](../infra) + [core](../core) +
10
+ [runtime](../runtime) + [server](../server) + [tui](../tui) +
11
+ `commander` + `@inquirer/prompts` + `ink` + `react`
12
+
13
+ **命令的完整清单(含全局选项和每个子命令)在
14
+ [docs/CLI.md](../../docs/CLI.md)**,这里不重复一遍——两处抄同一份清单必然漂。
15
+
16
+ ```bash
17
+ epoch model # 首次使用:交互式选 provider + 模型,key 写进 ~/.epoch/.env
18
+ epoch doctor # 装不上 / 跑不起来时第一个跑这个
19
+ ```
20
+
21
+ 没有 `epoch setup`,也没有 `epoch config init`——初始化就走 `epoch model`。
22
+
23
+ ## 文件
24
+
25
+ | 文件 / 目录 | 职责 |
26
+ | ----------------------------- | --------------------------------------------------------------------------------------------------------------------- |
27
+ | `index.ts` | commander 装配,每个子命令挂在这里 |
28
+ | `commands/run.ts` | `epoch [query]`:判断走 TUI / 单次问答 / 长驻模式 / 读 stdin |
29
+ | `commands/run-once.ts` | 单次问答的输出(三种 `--output-format`)+ 收尾(后台任务摘要、退出码) |
30
+ | `commands/run-stream.ts` | `text` 档两条流(模型正文 / 工具实时输出)在同一块屏幕上怎么交错:`createStreamWriter` |
31
+ | `commands/run-flags.ts` | 全局选项的解析(纯函数):会话续接三态、格式、限额、审批器路径 |
32
+ | `commands/run-overrides.ts` | **分流之前**那一步:所有带值 flag 的落地与校验都挂在 `applyRunFlags` 这一个入口(见下) |
33
+ | `commands/sessions.ts` | `epoch sessions`,同时是**会话续接的唯一实现处**:`-c` / `-r` 与 `sessions resume` 共用它的 id 解析 |
34
+ | `headless/` | 程序驱动那条路(方案 28):见下面「headless 协议」 |
35
+ | `commands/schedule.ts` | `epoch schedule` 的命令注册(薄壳) |
36
+ | `schedule/` | 定时任务那一族的实现:`add` / `view` / `run` / `manage` / `doctor`,`labels.ts` 是**码 → 文案的唯一出口**(见下) |
37
+ | `commands/*.ts` | `config` / `mcp` / `model` / `status` / `sessions` / `trust` / `agents` / `plugin` / `upgrade` / `web` / `completion` |
38
+ | `commands/web-open.ts` | 跨平台打开浏览器(`start` / `open` / `xdg-open`) |
39
+ | `tui-entry.ts` | TUI 启动:建 runtime、接 `AgentSession`、`renderApp()` |
40
+ | `approval.ts` | 非 TUI 场景的终端审批交互 |
41
+ | `trust-prompt.ts` | 工作区信任的首次询问 |
42
+ | `import-prompt.ts` | 指令文件引用项目**之外**的文件时的逐个询问(方案 33) |
43
+ | `files/` | `config.yaml` / `.env` 的读写(保留注释与格式);以及 `epoch config schema` 写出的 `.epoch/schemas/*.json` |
44
+ | `errors.ts` / `exit-codes.ts` | 错误 → 人话 + 稳定退出码(CI 靠它判断)。别的包抛的「预期内失败」按 `err.name` 查一张表,不打 stack |
45
+ | `update-check.ts` | 后台查新版本,detached 子进程,不拖慢启动 |
46
+ | `installation.ts` | 判断安装方式(npm / pnpm / 本地),`epoch upgrade` 靠它给出正确命令 |
47
+ | `clipboard.ts` | 读剪贴板里的**图片**(TUI 的 Ctrl+V)。放在 cli 是因为 tui 不该 spawn 子进程 |
48
+ | `statusline.ts` | 自定义状态栏:跑用户配的命令,第一行给 TUI(超时 2s / 截 60 字 / 失败保留旧值)。放 cli 同上:要 spawn |
49
+ | `worktree.ts` | `--worktree` 的 git 那一侧:建 worktree + 新分支、收尾时**有改动就不删** |
50
+ | `paths.ts` / `version.ts` | CLI 侧的路径与版本号;`--version` 那三行也在 `version.ts`,**第一行必须是裸版本号** |
51
+
52
+ ## 带值的 flag 在**分流之前**落地,其中九个走环境变量
53
+
54
+ 「分流」= `commands/run.ts` 里那句「没有 prompt 就起 TUI」。所有带值 flag 的落地
55
+ 与校验都排在它**前面**,入口只有一个:`commands/run-overrides.ts` 的
56
+ `applyRunFlags`。**加新 flag 时挂进那一个函数。**
57
+
58
+ 这条规矩是修出来的(前因见
59
+ [方案 28 验收记录第七章](../../docs/verify/VERIFY_RECORD-28-headless-protocol.md)):`--provider` 的值校验原来住在 `runOnce`
60
+ 里、排在分流后面,而打错一个带值的 flag 必然让位置参数为空 —— 于是
61
+ `epoch -p "跑一下测试"` 这类手滑永远走不到校验,一律表现为**静默进 TUI**,
62
+ 一个字都不说。
63
+
64
+ 九个走环境变量的(其余全局选项是解析成 `BuildRuntimeOptions` 的字段传下去的):
65
+
66
+ | 选项 | 环境变量 | 值 |
67
+ | ------------------ | ---------------------- | ------------------------------------ |
68
+ | `--settings` | `EPOCH_SETTINGS` | 绝对路径 |
69
+ | `--add-dir` | `EPOCH_ADD_DIR` | 绝对路径,按 `path.delimiter` 连起来 |
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) 地址 |
75
+ | `--permission` | `EPOCH_PERMISSION` | 收窄过的权限级别 |
76
+ | `-c` / `-r` | `EPOCH_RESUME` | 选中的会话 id |
77
+
78
+ 因为无参进 TUI 那条路**不经过 `runOnce`**——TUI 起的是另一个进程,选项对象过不去,
79
+ 只有环境变量带得过去。路径一律转**绝对**:子进程的 cwd 不保证一样。
80
+
81
+ 前八个在 action 一开头就落进 env,`launchTui` 那边 `{ ...process.env }` 白拿;
82
+ 只有 `EPOCH_RESUME` 要显式塞,因为它是**算出来的**(`-c` 要查库、`-r` 不带值
83
+ 要弹选择器)。加新 flag 时按这条分。
84
+
85
+ 取值是**开放集合**的那三个(`-m` / `--fallback-model` / `--base-url`)没有可选值
86
+ 清单可以对,所以判**字形**:模型 id 得是 ASCII 可见字符,base URL 得能被
87
+ `new URL()` 解析且是 http(s)。卡得松是刻意的 —— 误伤一个合法模型名的代价是
88
+ 「那个模型压根用不了」,比放过一句话严重得多。
89
+
90
+ 反面例子是 `--worktree`:它**没有**对应的 `EPOCH_*`,因为它不是「传下去的一个设置」,
91
+ 而是父进程先 `chdir` 到新建的 worktree,子进程照常继承 cwd —— 落成环境变量的话
92
+ 父子两边都会各建一个。它的时序也是硬的:建 + `chdir` 必须排在 `--add-dir` 落地和
93
+ `-c` 查会话**之后**,那两件事都以「用户敲命令的那个目录」为准,chdir 之后项目根就
94
+ 变成 worktree 了,它们会一起错,而且错得很安静(`-c` 查不到任何会话,于是默默开新的)。
95
+
96
+ 也因此 `launchTui()` 现在 **await 到子进程退出**才返回(以前是发射后不管,靠继承的
97
+ stdio 让父进程自然活着):worktree 的收尾得等 TUI 真的退出,否则会在用户还在里面
98
+ 打字的时候问他「要不要删这个 worktree」。
99
+
100
+ `-c` / `-r` 还多一条:**选哪一段在父进程里就定完**(含 `-r` 不带 id 时的选择器)。
101
+ ink 一接管 stdin,inquirer 就抢不回来 —— 和信任闸门必须排在 `renderApp` 之前是
102
+ 同一个约束。
103
+
104
+ 三处的「坏输入」都**报错退出**,不静默当没给:
105
+
106
+ - `--settings` 文件不存在 / 不是合法 JSON → 静默降级的表现是「规则一条都没生效」,
107
+ 在 CI 里正好等于「审批全部走默认」,是最不该悄悄发生的那种失败。
108
+ JSON 坏了这一半由 core 抛 `SettingsFileError`(错误里带行号)
109
+ - `--add-dir` 指的目录不存在 / 不是目录 → 静默失效等于 agent 的地盘和用户想的不一样,
110
+ 而这件事只在它拒绝读某个文件时才露头。「白给」(已经在工作区里了)不算错,
111
+ 由运行时报一条诊断
112
+ - `--agent` 名字不认识 → 由 **runtime** 抛 `AgentRoleError`(可用角色都在消息里)。
113
+ 故意不在 CLI 侧先查一遍:三层角色表只有 `buildRuntime()` 合并得出来,
114
+ 在这儿再发现一遍等于养第二份逻辑,而两份迟早会给出不同答案
115
+
116
+ 这三个错误加上 `ManagedPolicyError` 共用 `errors.ts` 里那张 `name → 退出码` 表,
117
+ 一律只打一行 message(有 hint 再一行)、**不打 stack**:那段 stack 指向别人包里的
118
+ 一行 throw,对着它排查纯属浪费。
119
+
120
+ 分层语义(谁压过谁、哪几层过信任闸门)见 [docs/SETTINGS.md](../../docs/SETTINGS.md)。
121
+
122
+ ## 单次问答的两条流
123
+
124
+ 流式模式下 stdout 与 stderr 各有分工,`createStreamWriter` 是唯一的出口:
125
+
126
+ | 流 | 内容 |
127
+ | -------- | -------------------------------------------------------- |
128
+ | `stdout` | **只有模型的回答**——`epoch "…" > a.txt` 必须是纯回答 |
129
+ | `stderr` | 工具执行期间的实时输出(每行 `│ ` 前缀)、诊断、用量汇总 |
130
+
131
+ 两条流必须由同一个东西管:它们在终端里落到**同一块屏幕**上,各写各的就会互相插队。
132
+ 正文停在半行上时先补一个换行再插工具输出,否则 `pnpm build` 的几百行会怼在模型半
133
+ 句话后面。两种机器格式(`json` / `stream-json`)下这个 writer 一个字节都不写——
134
+ 它们的契约是 **stdout 只有协议内容**。
135
+
136
+ 实时输出**不进** `json` 的载荷:它的最终版本本来就在工具结果里,塞进去是重复的。
137
+ `stream-json` 下它是协议的一部分(`tool-output-delta` 帧),所以也不再往 stderr
138
+ 抄一份带 `│ ` 前缀的。
139
+
140
+ ## headless 协议
141
+
142
+ 对外的完整说明在 **[docs/HEADLESS.md](../../docs/HEADLESS.md)**(含「什么时候该直接
143
+ 用库而不是走协议」)。线上的形状在
144
+ [protocol/src/headless-wire.ts](../protocol/src/headless-wire.ts) —— 本目录只做编解码。
145
+
146
+ | 文件 | 职责 |
147
+ | ---------------------- | ------------------------------------------------------------------------- |
148
+ | `headless/emit.ts` | 事件 → stdout 的一行 JSON。`seq` 编号、审批中继、artifact 的 base64 摘除 |
149
+ | `headless/read.ts` | stdin 的一行 → 入站事件 + **给人看的**错误信息(坏行跳过不杀进程) |
150
+ | `headless/outcome.ts` | 收尾语义:报什么 `reason`、退什么码。单次问答与长驻模式**共用这一份** |
151
+ | `headless/driver.ts` | 长驻模式的状态机:排队、审批往返、`abort` / `close`、宿主没了怎么收摊 |
152
+ | `headless/session.ts` | 长驻模式的装配(`interactive: true`、不问信任、不接交互式审批) |
153
+ | `headless/approver.ts` | `--permission-prompt-tool` 的子进程桥:喂 JSON、收裁决、答不出来一律拒绝 |
154
+ | `headless/tasks.ts` | 单次问答收尾时的后台任务摘要(措辞复用 core 的 `describeBackgroundTask`) |
155
+
156
+ 三条不许改回去的规矩,每一条都在对应文件的头注释里写了理由:
157
+
158
+ 1. **stdout 只有协议内容。** 混一行中文,`epoch "…" --json | jq` 当场碎
159
+ 2. **`seq` 的编号规则和 [server 的 hub](../server/src/hub.ts) 逐条一致** ——
160
+ `fixtures/wire/*.json` 那几份录像因此能同时当两边的夹具
161
+ 3. **宿主没了不等于用户拒绝。** 不许逐个 `respond('deny')`,要放弃就
162
+ `abandonApprovals()` + `abort()`(同 [runtime/src/serialize.ts](../runtime/src/serialize.ts))
163
+
164
+ ## 定时任务的文案走**穷举的表**,不走模板字符串
165
+
166
+ [`schedule/labels.ts`](src/schedule/labels.ts) 把每个码映射到一个 catalog key,
167
+ 写成 `Record<ScheduleIssueCode, string>` 而不是 ``t(`schedule.issue.${code}`)``。
168
+ 两条理由缺一不可:
169
+
170
+ 1. **少一条当场编译不过。** 模板字符串那种写法漏掉的表现是用户看到一行
171
+ `schedule.issue.xxx` 的 key 路径 —— 而那要等到有人真撞上那条校验才被发现。
172
+ 2. **catalog 的「死 key」检查扫的是字面量**(根 `__tests__/i18n-catalog.test.ts`)。
173
+ key 拼在模板里的话,那几十条文案会被判成死 key,然后下一个人照着报告删掉它们。
174
+
175
+ `core` / `runtime` 那两层**一个中文都没有**:它们给的是 `ScheduleIssueCode`、
176
+ `ScheduleRunStatus` 这种码和技术细节,人话全在这一层。判据同
177
+ `SettingWriteRefused.reason` 那条「是码不是句子」。
178
+
179
+ ## Web UI 的产物不在这个包里
180
+
181
+ `epoch web` 托管的前端产物随 [server](../server) 一起发(`<server 包>/dist/web`),
182
+ 本包**不再**拷一份——2026-08-14 之前它在 `cli/dist/web`,搬家的理由见
183
+ [server/scripts/copy-web-assets.mjs](../server/scripts/copy-web-assets.mjs) 的头注释
184
+ (一句话:嵌入宿主依赖的是 server,产物留在 cli 里等于它们拿不到界面)。
185
+
186
+ 所以本包的 `build` 就是一句 `tsup`,`epoch web` 也不再自己去探产物目录——
187
+ 不传 `webRoot`,由 `createWebServer()` 定位自带的那份。
188
+
189
+ ## 开发
190
+
191
+ ```bash
192
+ pnpm epoch:dev --version # tsx 直跑源码,不用 build
193
+ pnpm epoch:dev doctor
194
+ ```
195
+
196
+ > ⚠️ **`pnpm epoch:dev` 只有本包是源码。** [tui](../tui) / [runtime](../runtime) /
197
+ > [core](../core) / [server](../server) 都是按 package.json 的 `exports` 从各自
198
+ > **`dist/`** 解析的(没有 tsconfig paths 映射)。改了那些包不 `pnpm build` 就来测,
199
+ > 测的是上一次的产物——而且 typecheck 也读 dist 的 `.d.ts`,两边一起骗你。
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/files/env-file.ts
4
+ import { readFileSync } from "fs";
5
+ import {
6
+ getSecretStore,
7
+ parseEnvText,
8
+ setEnvVarText,
9
+ writeEnvFile
10
+ } from "@epoch-agent/infra";
11
+ async function writeProviderKey(name, value, fallbackEnvPath) {
12
+ const store = getSecretStore();
13
+ if (!store) {
14
+ writeEnvFile(fallbackEnvPath, setEnvVarText(readOrEmpty(fallbackEnvPath), name, value));
15
+ return { backend: "plaintext", encrypted: false, detail: `\u660E\u6587\u5199\u5165 ${fallbackEnvPath}` };
16
+ }
17
+ await store.set(name, value);
18
+ return { backend: store.backend, encrypted: store.encrypted, detail: store.detail };
19
+ }
20
+ async function exportSecretsToEnv(store, envFilePath, names) {
21
+ let text = readOrEmpty(envFilePath);
22
+ const written = [];
23
+ for (const name of names) {
24
+ const value = await store.get(name);
25
+ if (!value) continue;
26
+ text = setEnvVarText(text, name, value);
27
+ written.push(name);
28
+ }
29
+ if (written.length > 0) writeEnvFile(envFilePath, text);
30
+ return written;
31
+ }
32
+ function readOrEmpty(path) {
33
+ try {
34
+ return readFileSync(path, "utf-8");
35
+ } catch {
36
+ return "";
37
+ }
38
+ }
39
+
40
+ export {
41
+ parseEnvText,
42
+ setEnvVarText,
43
+ writeEnvFile,
44
+ writeProviderKey,
45
+ exportSecretsToEnv
46
+ };
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ exportSecretsToEnv,
4
+ parseEnvText,
5
+ setEnvVarText,
6
+ writeEnvFile,
7
+ writeProviderKey
8
+ } from "./chunk-3SCZQI5W.js";
9
+ export {
10
+ exportSecretsToEnv,
11
+ parseEnvText,
12
+ setEnvVarText as setEnvVar,
13
+ writeEnvFile,
14
+ writeProviderKey
15
+ };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * epoch-agent CLI 入口。
3
+ *
4
+ * ✅ 做:命令解析(commander)+ 终端输出 + 交互式审批
5
+ * ❌ 不做:模块装配(@epoch-agent/runtime)、领域逻辑(@epoch-agent/core)、
6
+ * 渲染(@epoch-agent/tui)
7
+ *
8
+ * 这个文件只负责组装 program 然后 parse,每个命令的实现在 commands/ 下。
9
+ * 原来是一个 356 行的文件,命令定义、配置读写、凭据探测、模型发现交互全混在
10
+ * 一起,还手抄了 4 份 provider 清单。
11
+ */
12
+ /**
13
+ * `--help` / `--version` 只是打一段文本就退出,为它 spawn 一个 detached 子进程
14
+ * 纯属浪费。补全脚本会高频调 `epoch --help`,那更不该每次都起进程。
15
+ */
16
+ declare function isMetaInvocation(argv: readonly string[]): boolean;
17
+
18
+ export { isMetaInvocation };