@autopilot-agent/cli 0.1.0 → 0.3.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 +30 -153
- package/dist/activity-animation.d.ts +6 -0
- package/dist/activity-animation.js +15 -18
- package/dist/composition-root.d.ts +31 -1
- package/dist/composition-root.js +124 -3
- package/dist/context-report.d.ts +9 -4
- package/dist/context-report.js +16 -5
- package/dist/controller.d.ts +34 -4
- package/dist/controller.js +494 -90
- package/dist/design-tokens.d.ts +4 -0
- package/dist/design-tokens.js +4 -0
- package/dist/error-diagnostics.d.ts +2 -0
- package/dist/error-diagnostics.js +3 -1
- package/dist/event-projector.d.ts +16 -2
- package/dist/event-projector.js +78 -7
- package/dist/index.d.ts +1 -1
- package/dist/main.js +142 -7
- package/dist/parser.js +511 -4
- package/dist/renderer.js +19 -3
- package/dist/session-summary.d.ts +7 -0
- package/dist/session-summary.js +25 -0
- package/dist/session-title.d.ts +5 -0
- package/dist/session-title.js +10 -0
- package/dist/termination-format.js +1 -0
- package/dist/thread-commands.d.ts +37 -0
- package/dist/thread-commands.js +233 -0
- package/dist/thread-host.d.ts +31 -0
- package/dist/thread-host.js +76 -0
- package/dist/timeline-lines.js +36 -28
- package/dist/tui/app.d.ts +22 -0
- package/dist/tui/app.js +119 -44
- package/dist/tui/approval.d.ts +5 -1
- package/dist/tui/approval.js +20 -7
- package/dist/tui/constants.d.ts +1 -1
- package/dist/tui/constants.js +1 -1
- package/dist/tui/format.d.ts +1 -1
- package/dist/tui/format.js +23 -11
- package/dist/tui/hooks/use-prompt-input.d.ts +52 -0
- package/dist/tui/hooks/use-prompt-input.js +148 -20
- package/dist/tui/hooks/use-status-view.d.ts +2 -2
- package/dist/tui/hooks/use-status-view.js +38 -11
- package/dist/tui/inline-output.d.ts +17 -0
- package/dist/tui/inline-output.js +31 -0
- package/dist/tui/input/clipboard-image.d.ts +17 -0
- package/dist/tui/input/clipboard-image.js +117 -0
- package/dist/tui/input-area.d.ts +8 -0
- package/dist/tui/input-area.js +18 -3
- package/dist/tui/lifecycle.js +2 -5
- package/dist/tui/markdown/diff.d.ts +1 -1
- package/dist/tui/markdown/diff.js +28 -1
- package/dist/tui/performance-diagnostics.js +2 -0
- package/dist/tui/prompt-input.d.ts +1 -0
- package/dist/tui/prompt-input.js +5 -3
- package/dist/tui/render-mode.d.ts +4 -4
- package/dist/tui/render-mode.js +5 -11
- package/dist/tui/run.js +37 -49
- package/dist/tui/session-manager.d.ts +115 -0
- package/dist/tui/session-manager.js +383 -0
- package/dist/tui/session-workspace.d.ts +9 -0
- package/dist/tui/session-workspace.js +383 -0
- package/dist/tui/status-line.d.ts +3 -0
- package/dist/tui/status-line.js +12 -6
- package/dist/tui/store.js +111 -53
- package/dist/tui/timeline/live.js +9 -8
- package/dist/tui/timeline/presentation-timeline.d.ts +2 -1
- package/dist/tui/timeline/presentation-timeline.js +34 -15
- package/dist/tui/timeline/progress.js +3 -2
- package/dist/tui/timeline/static-timeline.js +17 -8
- package/dist/tui/timeline/turn-items.d.ts +12 -0
- package/dist/tui/timeline/turn-items.js +28 -0
- package/dist/tui/timeline/turn.js +8 -7
- package/dist/tui/transcript.d.ts +2 -2
- package/dist/tui/transcript.js +21 -3
- package/dist/tui/trust-dialog.d.ts +3 -0
- package/dist/tui/trust-dialog.js +23 -2
- package/dist/tui/types.d.ts +23 -1
- package/dist/tui/types.js +4 -1
- package/dist/tui/viewport/sources.d.ts +2 -2
- package/dist/tui/viewport/sources.js +75 -75
- package/dist/tui/viewport/viewport.js +5 -1
- package/dist/types.d.ts +165 -2
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,181 +1,58 @@
|
|
|
1
|
-
<!-- 本文件用于 npm CLI 用户了解安装、配置和使用方式。 -->
|
|
2
1
|
# @autopilot-agent/cli
|
|
3
2
|
|
|
4
|
-
Autopilot
|
|
5
|
-
|
|
6
|
-
安装后使用 `ap` 或 `autopilot` 启动,两者功能相同。
|
|
7
|
-
|
|
8
|
-
## 可以做什么
|
|
9
|
-
|
|
10
|
-
- **理解项目**:阅读文件、按文件名或内容搜索代码,梳理项目结构、解释实现、定位问题。输入 `@src/index.ts` 这样的相对路径,可以把指定文件带入当前对话。
|
|
11
|
-
- **编写和修改代码**:根据需求创建文件、修改已有代码,帮助修复 Bug、补充测试和整理文档;交互界面会展示文件修改信息。
|
|
12
|
-
- **执行开发命令**:运行测试、构建和其他命令,根据输出继续排查;耗时命令可以作为后台任务运行,随时查看输出或请求停止。
|
|
13
|
-
- **跟踪任务进度**:将复杂需求拆成待办事项,在执行过程中更新完成状态;任务运行时也可以排队提交下一条需求。
|
|
14
|
-
- **继续已有对话**:保存并管理项目会话,在已有会话中继续提问;中断后可恢复的任务可以通过 `ap resume` 继续。
|
|
15
|
-
- **管理上下文**:查看当前上下文用量,手动压缩对话;具备有效上下文预算时,也会按阈值自动压缩,帮助继续较长的任务。
|
|
16
|
-
- **控制操作权限**:确认项目是否可信,选择权限模式,并审批需要确认的操作;通过 `/undo` 预览并撤销当前会话最近一轮可撤销的文件修改。
|
|
17
|
-
- **扩展工具和工作流程**:加载已安装的 Skills,通过 `/skill` 选择使用;配置并授权 MCP 服务后,可以调用其提供的工具。
|
|
18
|
-
- **查资料和分析图片**:配置搜索服务后可以联网搜索、读取网页;配置可用的视觉模型后,可以分析项目中的图片,例如界面截图。
|
|
19
|
-
|
|
20
|
-
你可以直接用自然语言提出需求,例如:
|
|
21
|
-
|
|
22
|
-
```text
|
|
23
|
-
分析这个项目的入口和主要模块,先不要修改文件。
|
|
24
|
-
查找登录失败的原因,修复后运行相关测试。
|
|
25
|
-
根据这张UI设计图片,还原设计稿。
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## 常用交互命令
|
|
29
|
-
|
|
30
|
-
启动 `ap` 后,输入 `/` 可以查看命令建议。
|
|
31
|
-
|
|
32
|
-
| 命令 | 用途 |
|
|
33
|
-
|---|---|
|
|
34
|
-
| `/model`、`/effort` | 选择后续任务使用的模型和思考强度 |
|
|
35
|
-
| `/skill` | 查看并选择已安装的 Skills |
|
|
36
|
-
| `/permissions` | 查看或切换当前会话的权限模式 |
|
|
37
|
-
| `/context`、`/context all` | 查看上下文用量,或展开详细信息 |
|
|
38
|
-
| `/compact` | 手动压缩当前上下文 |
|
|
39
|
-
| `/jobs` | 查看后台任务,也可查看输出或请求停止 |
|
|
40
|
-
| `/queue <需求>` | 将下一条需求加入队列 |
|
|
41
|
-
| `/undo` | 预览最近一轮可撤销的文件修改,再确认是否撤销 |
|
|
42
|
-
| `/cancel`、`/exit` | 取消当前任务,或退出 CLI |
|
|
43
|
-
|
|
44
|
-
## 安装
|
|
45
|
-
|
|
46
|
-
请先安装 **Node.js >=20.11.0 且 <22** 和 npm,再运行以下命令。安装时需要联网。
|
|
3
|
+
Autopilot 的终端宿主包。普通用户安装主包 `autopilot-agent@0.3.0`,无需分别安装各个 scoped 包:
|
|
47
4
|
|
|
48
5
|
```bash
|
|
49
|
-
npm install -g autopilot-agent
|
|
6
|
+
npm install -g autopilot-agent@0.3.0
|
|
50
7
|
ap --help
|
|
51
8
|
```
|
|
52
9
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
## 配置 settings.json
|
|
10
|
+
完整安装、Anthropic / Chat Completions 配置、使用和限制见 [主包手册](https://github.com/C-Clay-W/autopilot/blob/main/packages/autopilot-agent/README.md),完整 argv / slash 语法见 [CLI 参考](https://github.com/C-Clay-W/autopilot/blob/main/agent/doc/CLI-Reference.md)。开发参考随源码更新,可能先于已发布版本的行为。
|
|
56
11
|
|
|
57
|
-
|
|
12
|
+
## 结构与职责
|
|
58
13
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
14
|
+
- parser.ts 解析 argv 与交互命令,main.ts 编排入口、输出及退出。
|
|
15
|
+
- composition-root.ts 注入共享 Core Runtime 与 Node Adapters,controller.ts 管理任务、审批与恢复。
|
|
16
|
+
- thread-commands.ts / thread-host.ts 承载同机会话协作:`ap thread ...` 薄命令复用 Core 协作协议,交互会话持有驱动 Runner;两者共用同一状态根与 Project。
|
|
17
|
+
- tui/ 使用 React / Ink;renderer.ts 与 event-projector.ts 支持纯文本和 JSONL。
|
|
18
|
+
- 内部依赖为 Core、Adapters、Presentation,0.3.0 使用匹配的精确版本。
|
|
63
19
|
|
|
64
|
-
|
|
20
|
+
本包的 bin 提供 ap/autopilot,主入口包再转发至本包的 dist/main.js,不复制 Runtime。TTY 使用交互界面;显式 --output text/jsonl 用于脚本,JSONL 不输出 ANSI 或交互提示。
|
|
65
21
|
|
|
66
|
-
|
|
22
|
+
## 编程入口
|
|
67
23
|
|
|
68
|
-
|
|
24
|
+
包根导出 parseArgv、parseSlashAction、renderHelp、createCliCompositionRoot、createCliController、main、事件投影和 TUI 相关类型。优先把它作为终端应用使用;自行嵌入时需要处理输入输出、Trust、审批和退出清理,不在模块导入时自动启动任务。
|
|
69
25
|
|
|
70
|
-
```
|
|
71
|
-
{
|
|
72
|
-
"env": {
|
|
73
|
-
"ANTHROPIC_BASE_URL": "https://api.anthropic.com",
|
|
74
|
-
"ANTHROPIC_API_KEY": "YOUR_API_KEY"
|
|
75
|
-
},
|
|
76
|
-
"model": "YOUR_MODEL_ID"
|
|
77
|
-
}
|
|
78
|
-
```
|
|
26
|
+
```typescript
|
|
27
|
+
import { parseArgv, renderHelp } from "@autopilot-agent/cli";
|
|
79
28
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
如果服务支持 OpenAI Chat Completions 协议,使用下面的配置。替换密钥、`baseUrl` 和两处 `YOUR_MODEL_ID`;其余字段可以保留示例写法。
|
|
85
|
-
|
|
86
|
-
```json
|
|
87
|
-
{
|
|
88
|
-
"env": { "USER_SETTINGS_CUSTOM_API_KEY": "YOUR_API_KEY" },
|
|
89
|
-
"providerRoutes": {
|
|
90
|
-
"custom": {
|
|
91
|
-
"id": "custom",
|
|
92
|
-
"apiProtocol": "openai-chat-completions",
|
|
93
|
-
"baseUrl": "https://api.example.com/v1",
|
|
94
|
-
"credentialRef": { "provider": "custom", "key": "USER_SETTINGS_CUSTOM_API_KEY" },
|
|
95
|
-
"models": [{ "id": "YOUR_MODEL_ID" }]
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
"model": "custom/YOUR_MODEL_ID"
|
|
99
|
-
}
|
|
29
|
+
const parsed = parseArgv(["chat", "解释项目结构", "--output", "text"]);
|
|
30
|
+
console.log(parsed);
|
|
31
|
+
console.log(renderHelp());
|
|
100
32
|
```
|
|
101
33
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
需要配置多个服务时,可以在 `providerRoutes` 中增加其他条目。每个条目的名称、`id` 和 `credentialRef.provider` 应一致;`credentialRef.key` 对应 `env` 中的密钥名称。`model` 使用 `服务名称/模型名称` 的形式,模型必须列在对应服务的 `models` 中。协议只支持 `anthropic-messages` 和 `openai-chat-completions`。
|
|
105
|
-
|
|
106
|
-
### 常用可选参数
|
|
107
|
-
|
|
108
|
-
| 字段 | 用途与写法 |
|
|
109
|
-
|---|---|
|
|
110
|
-
| `model` | 使用的模型名称,或上面示例中的 `服务名称/模型名称`;建议填写服务商提供的完整模型名称 |
|
|
111
|
-
| `availableModels` | 默认连接允许使用的模型列表,例如 `["MODEL_A", "MODEL_B"]`;不能为空、不能重复,当前模型也需要在列表中 |
|
|
112
|
-
| `effortLevel` | 思考强度,可选 `"low"`、`"medium"`、`"high"`,具体效果取决于模型支持情况 |
|
|
113
|
-
| `alwaysThinkingEnabled` | 是否启用思考,填写 `true` 或 `false`,不要加引号;需要模型支持 |
|
|
114
|
-
| `maxOutputTokens` | 单次输出的 token 上限,填写 1–1,000,000 的整数;不是上下文大小 |
|
|
115
|
-
| `env.API_TIMEOUT_MS` | 默认模型连接的请求超时,单位毫秒,填写 1,000–600,000 的整数字符串,例如 `"60000"` |
|
|
116
|
-
| `visionModel` | 图片分析使用的模型,填写已配置的 Chat Completions 服务中的 `服务名称/模型名称`;`false` 关闭,省略时使用主模型 |
|
|
117
|
-
| `webSearch` | `false` 关闭模型联网搜索;启用时需另行配置搜索服务 |
|
|
118
|
-
|
|
119
|
-
`env` 中的值都需要写成字符串。填写模型名称和密钥时,避免带入首尾空格或换行。建议通过顶层 `model` 和 `effortLevel` 设置模型与思考强度;`env.ANTHROPIC_MODEL` 和 `env.CLAUDE_CODE_EFFORT_LEVEL` 会覆盖对应设置。
|
|
120
|
-
|
|
121
|
-
服务地址、密钥、模型列表等连接设置请放在上面的个人配置文件中,不要把密钥提交到项目或版本控制。项目也可以提供 `.autopilot/settings.json` 和 `.autopilot/settings.local.json`,在你信任该项目后应用允许的设置;项目设置不能替换个人配置中的连接信息。
|
|
122
|
-
|
|
123
|
-
### 修改配置
|
|
34
|
+
## 源码开发
|
|
124
35
|
|
|
125
|
-
|
|
36
|
+
从 monorepo 根安装依赖,依次构建 Core、Adapters、Presentation,再执行:
|
|
126
37
|
|
|
127
38
|
```bash
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
39
|
+
npm run build -w apps/cli
|
|
40
|
+
node apps/cli/dist/main.js --help
|
|
41
|
+
npm run test -w apps/cli -- test/parser.test.ts
|
|
131
42
|
```
|
|
132
43
|
|
|
133
|
-
|
|
44
|
+
build 使用 TypeScript,输出 dist/*.js 与声明,不在 npm 包中发布源码映射和测试。当前 Node 声明为 >=20.11.0 <22;建议整仓构建使用 Node 20.20.2。
|
|
134
45
|
|
|
135
|
-
|
|
46
|
+
CLI 使用用户级 settings.json,默认工作区为当前目录,可显式指定 --workspace-root。CLI 不读取开发仓库 Web env,也不因配置中含 RAG 字段而自动启用私有知识库工具。重要项目保留版本控制,OS 沙箱、MCP 和平台限制见主包手册。
|
|
136
47
|
|
|
137
|
-
|
|
48
|
+
## 0.3.0 版本
|
|
138
49
|
|
|
139
|
-
|
|
140
|
-
ap
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
首次打开项目时,按提示确认是否信任该项目。确认后,可以检查配置和模型连接:
|
|
144
|
-
|
|
145
|
-
```bash
|
|
146
|
-
ap doctor
|
|
147
|
-
ap doctor --connectivity
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
`ap doctor` 检查本地配置,`--connectivity` 还会联网检查模型服务。未信任项目时,部分检查会跳过。
|
|
151
|
-
|
|
152
|
-
`ap` 会进入交互模式,你可以直接输入需求。也可以提交一次任务:
|
|
153
|
-
|
|
154
|
-
```bash
|
|
155
|
-
ap chat "分析当前项目结构,不修改文件"
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
常用管理命令:
|
|
50
|
+
新增单窗口多会话、任务分派与进展汇报、主子会话双入口审批和图片输入。`Ctrl+T` 切换会话,`Ctrl+A` 处理真实待办请求;历史结构化问题可在原目标会话回答并继续。历史按需加载,输出使用终端原生滚动,并改进启动、缩放和流式完成时的布局。
|
|
159
51
|
|
|
160
|
-
|
|
161
|
-
ap session list
|
|
162
|
-
ap trust status
|
|
163
|
-
ap sandbox status
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
查看各命令的具体参数与限制:`ap --help`。更新和卸载:
|
|
167
|
-
|
|
168
|
-
```bash
|
|
169
|
-
npm install -g autopilot-agent@latest
|
|
170
|
-
npm uninstall -g autopilot-agent
|
|
171
|
-
```
|
|
52
|
+
用户模型配置继续使用用户级 settings.json。图片处理取决于模型及工具能力,首次使用前按主包手册配置。已知旧版状态在受信初始化时自动备份升级,保留升级前数据。
|
|
172
53
|
|
|
173
|
-
|
|
54
|
+
本包随 npm 0.3.0 发布,内部依赖使用匹配的精确版本。Windows 命令、后台 Job 与 host MCP 逐次审批后以当前用户权限直接执行,审批不提供 OS 隔离;macOS 继续使用 Seatbelt。实机与进程树生命周期仍需按实际验证确认。
|
|
174
55
|
|
|
175
|
-
##
|
|
56
|
+
## 许可证
|
|
176
57
|
|
|
177
|
-
-
|
|
178
|
-
- 沙箱功能需要额外的平台支持,可通过 `ap doctor` 和 `ap sandbox status` 查看状态。MCP 工具默认在本机运行,不提供操作系统级隔离。
|
|
179
|
-
- Windows 后台任务的子进程可能无法全部停止;沙箱中的 MCP 工具也可能遇到输入无法转发的问题。需要可靠停止的长任务,建议先在测试项目中验证。
|
|
180
|
-
- macOS 尚未完成完整功能验证,Linux 暂未验证。模型服务的可用性、限额和费用以服务商为准。
|
|
181
|
-
- 当前为早期版本,处理重要项目时,请保留版本控制或备份。
|
|
58
|
+
公开源码采用 [MIT 许可证](https://github.com/C-Clay-W/autopilot/blob/main/LICENSE)。第三方依赖保留各自许可证。
|
|
@@ -42,9 +42,11 @@ export declare function resolveCliActivityView(input: {
|
|
|
42
42
|
status: CliTurnStatus;
|
|
43
43
|
now: number;
|
|
44
44
|
waitingForApproval?: boolean;
|
|
45
|
+
threadWait?: import("./types.js").CliProjection["threadWait"];
|
|
45
46
|
}): CliActivityView | undefined;
|
|
46
47
|
/** 渲染稳定活动文案和可选的固定宽度离散帧。 */
|
|
47
48
|
export declare function TuiActivityLine(props: {
|
|
49
|
+
threadWait?: import("./types.js").CliProjection["threadWait"];
|
|
48
50
|
activity: CliActivityState;
|
|
49
51
|
status: CliTurnStatus;
|
|
50
52
|
waitingForApproval: boolean;
|
|
@@ -53,5 +55,9 @@ export declare function TuiActivityLine(props: {
|
|
|
53
55
|
reducedMotion: boolean;
|
|
54
56
|
animationActive: boolean;
|
|
55
57
|
clock: TuiAnimationClock;
|
|
58
|
+
startedAt?: number;
|
|
59
|
+
elapsedMs?: number;
|
|
60
|
+
runningSince?: number;
|
|
61
|
+
activeForm?: string;
|
|
56
62
|
}): ReactNode;
|
|
57
63
|
export {};
|
|
@@ -72,16 +72,6 @@ export function getCliActivityFrame(phase, now) {
|
|
|
72
72
|
return "";
|
|
73
73
|
return CLI_ACTIVITY_SPINNER_FRAMES[Math.floor(Math.max(0, now) / CLI_ACTIVITY_SPINNER_FRAME_MS) % CLI_ACTIVITY_SPINNER_FRAMES.length] ?? "·";
|
|
74
74
|
}
|
|
75
|
-
function formatCliActivityElapsed(durationMs) {
|
|
76
|
-
const totalSeconds = Math.max(1, Math.floor(Math.max(0, durationMs) / 1_000));
|
|
77
|
-
if (totalSeconds < 60)
|
|
78
|
-
return `${totalSeconds}s`;
|
|
79
|
-
const minutes = Math.floor(totalSeconds / 60);
|
|
80
|
-
const seconds = totalSeconds % 60;
|
|
81
|
-
if (minutes < 60)
|
|
82
|
-
return `${minutes}m ${String(seconds).padStart(2, "0")}s`;
|
|
83
|
-
return `${Math.floor(minutes / 60)}h ${String(minutes % 60).padStart(2, "0")}m ${String(seconds).padStart(2, "0")}s`;
|
|
84
|
-
}
|
|
85
75
|
/** 返回活动阶段的稳定文案,供动画降级和 screen reader 使用。 */
|
|
86
76
|
function getCliActivityLabel(phase, input = {}) {
|
|
87
77
|
switch (phase) {
|
|
@@ -90,7 +80,7 @@ function getCliActivityLabel(phase, input = {}) {
|
|
|
90
80
|
case "waiting": return input.hasActiveTool ? "Waiting · tool result" : "Waiting · provider response";
|
|
91
81
|
case "transition": return "Running action · starting tool";
|
|
92
82
|
case "responding": return "Answering · receiving output";
|
|
93
|
-
case "stalled": return
|
|
83
|
+
case "stalled": return "Still working";
|
|
94
84
|
case "terminal": return "Completed";
|
|
95
85
|
}
|
|
96
86
|
}
|
|
@@ -104,6 +94,11 @@ export function resolveCliActivityView(input) {
|
|
|
104
94
|
if (input.waitingForApproval || status === "waiting_approval") {
|
|
105
95
|
return { phase: "waiting", label: "Waiting for approval", frame: getCliActivityFrame("waiting", now) };
|
|
106
96
|
}
|
|
97
|
+
if (status === "running" && input.threadWait) {
|
|
98
|
+
const fact = input.threadWait;
|
|
99
|
+
const label = fact.phase === "processing" ? "正在处理关联结果" : fact.approvals > 0 ? `等待关联审批 · ${fact.approvals}项待处理 · Ctrl+A处理` : fact.running > 0 ? `等待关联任务 · ${fact.running}项运行中` : `等待关联任务 · ${fact.pending}项未完成`;
|
|
100
|
+
return { phase: "waiting", label, frame: getCliActivityFrame("waiting", now) };
|
|
101
|
+
}
|
|
107
102
|
let phase = activity.phase;
|
|
108
103
|
if (phase === "transition" && activity.transitionStartedAt !== undefined && now - activity.transitionStartedAt >= CLI_ACTIVITY_TRANSITION_MS) {
|
|
109
104
|
phase = activity.hasActiveTool ? "waiting" : "thinking";
|
|
@@ -115,31 +110,33 @@ export function resolveCliActivityView(input) {
|
|
|
115
110
|
}
|
|
116
111
|
return {
|
|
117
112
|
phase,
|
|
118
|
-
label: getCliActivityLabel(phase, {
|
|
113
|
+
label: getCliActivityLabel(phase, { hasActiveTool: activity.hasActiveTool }),
|
|
119
114
|
frame: getCliActivityFrame(phase, now),
|
|
120
115
|
};
|
|
121
116
|
}
|
|
122
117
|
/** 渲染稳定活动文案和可选的固定宽度离散帧。 */
|
|
123
118
|
export function TuiActivityLine(props) {
|
|
124
119
|
const [clockTime, setClockTime] = useState(props.clock.now());
|
|
125
|
-
const view = resolveCliActivityView({ activity: props.activity, status: props.status, now: clockTime, waitingForApproval: props.waitingForApproval });
|
|
120
|
+
const view = resolveCliActivityView({ activity: props.activity, status: props.status, now: clockTime, waitingForApproval: props.waitingForApproval, threadWait: props.threadWait });
|
|
126
121
|
const shouldAnimate = props.animationActive && !props.screenReader && !props.reducedMotion && view !== undefined && view.phase !== "terminal";
|
|
122
|
+
const shouldTick = shouldAnimate || (props.runningSince !== undefined && props.status === "running");
|
|
127
123
|
useEffect(function subscribeActivityClock() {
|
|
128
|
-
props.clock.setActive(
|
|
129
|
-
if (!
|
|
124
|
+
props.clock.setActive(shouldTick);
|
|
125
|
+
if (!shouldTick) {
|
|
130
126
|
setClockTime(props.clock.now());
|
|
131
127
|
return;
|
|
132
128
|
}
|
|
133
129
|
setClockTime(props.clock.now());
|
|
134
130
|
return props.clock.subscribe(function updateActivityClock(time) {
|
|
135
|
-
|
|
131
|
+
// 禁动画仍按秒检查静默状态,复用同一枚时钟。
|
|
132
|
+
setClockTime(function next(previous) { return shouldAnimate || Math.floor(previous / 1000) !== Math.floor(time / 1000) ? time : previous; });
|
|
136
133
|
});
|
|
137
|
-
}, [props.clock, shouldAnimate]);
|
|
134
|
+
}, [props.clock, shouldAnimate, shouldTick]);
|
|
138
135
|
if (!view)
|
|
139
136
|
return null;
|
|
140
137
|
if (view.phase === "terminal")
|
|
141
138
|
return null;
|
|
142
139
|
const frame = shouldAnimate ? view.frame : "·";
|
|
143
140
|
const isStalled = view.phase === "stalled";
|
|
144
|
-
return (_jsxs(Box, { flexDirection: "row", children: [_jsx(Box, { width: 3, flexShrink: 0, children: _jsx(Text, { bold: isStalled, color: props.useColor ? "ansi256(208)" : undefined, children: frame }) }), _jsx(Text, { bold: isStalled, dimColor: props.useColor && !isStalled, children: view.label })] }));
|
|
141
|
+
return (_jsxs(Box, { flexDirection: "row", children: [_jsx(Box, { width: 3, flexShrink: 0, children: _jsx(Text, { bold: isStalled, color: props.useColor ? "ansi256(208)" : undefined, children: frame }) }), _jsx(Text, { bold: isStalled, dimColor: props.useColor && !isStalled, children: props.threadWait && props.status === "running" ? view.label : props.activeForm ?? view.label })] }));
|
|
145
142
|
}
|
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
* 负责选择 Core 默认 Runtime、共享 Node Adapter、canonical workspaceRoot、
|
|
5
5
|
* trust policy 和显式 stateRoot;不负责命令解析、事件投影或 Runtime 状态机。
|
|
6
6
|
*/
|
|
7
|
-
import { type AgentRuntime, type CapabilityLoader, type CreateRuntimeBootstrapServiceOptions, type RuntimeBootstrapService, type SafeBootstrapConfig, type SandboxCapabilityReport, type WorkspaceTrustEntry, type WorkspaceTrustPolicy } from "@autopilot-agent/core";
|
|
7
|
+
import { type AgentRuntime, type CapabilityLoader, type CreateRuntimeBootstrapServiceOptions, type RuntimeBootstrapService, type SafeBootstrapConfig, type SandboxCapabilityReport, type ThreadFacade, type WorkspaceTrustEntry, type WorkspaceTrustPolicy } from "@autopilot-agent/core";
|
|
8
8
|
import type { CliRuntimeStatusDefaults, CliSkillSummary } from "./types.js";
|
|
9
9
|
import { type WorkspaceRegistryEntry, type NodeCapabilityLoader, type NodeSettingsLoader } from "@autopilot-agent/adapters";
|
|
10
|
+
import { type CliThreadHost } from "./thread-host.js";
|
|
10
11
|
import type { AutopilotSettingsScope } from "@autopilot-agent/core";
|
|
11
12
|
/** Doctor 单项结果;只含状态和脱敏摘要,绝不包含路径、凭据或 Provider 正文。 */
|
|
12
13
|
export interface CliDoctorCheck {
|
|
@@ -74,6 +75,35 @@ export interface CliCompositionRoot {
|
|
|
74
75
|
sandboxSetup(workspaceRoot: string): Promise<SandboxCapabilityReport>;
|
|
75
76
|
createRuntime(workspaceRoot: string): Promise<AgentRuntime>;
|
|
76
77
|
bootstrap(): Promise<AgentRuntime>;
|
|
78
|
+
/** 绑定当前 Project 的协作范围;必须在 Project 确认后调用,Turn 装配据此注入协作工具。 */
|
|
79
|
+
bindThreadsProject(projectId: string): void;
|
|
80
|
+
/** 创建人类协作入口(薄命令);未绑定 Project 或缺少 Ports 时明确失败。 */
|
|
81
|
+
createHumanThreads(): ThreadFacade;
|
|
82
|
+
/** 创建常驻协作宿主(交互会话);未装配协作能力时明确失败。 */
|
|
83
|
+
createThreadHost(runtime: AgentRuntime, onError?: import("@autopilot-agent/adapters").NodeThreadRunnerOptions["onError"]): CliThreadHost;
|
|
84
|
+
/** 只读取当前宿主Store事件,不调用恢复或执行入口。 */
|
|
85
|
+
readSessionEvents(sessionId: string): Promise<import("@autopilot-agent/core").AgentEventEnvelope[]>;
|
|
86
|
+
/** 只读一页历史及其持续跟进游标,不恢复或执行目标。 */
|
|
87
|
+
readSessionEventPage(sessionId: string, input: {
|
|
88
|
+
cursor?: string;
|
|
89
|
+
limit: number;
|
|
90
|
+
}): Promise<import("./tui/session-manager.js").CliSessionEventPage>;
|
|
91
|
+
/** 普通目录只返回标题和内部UUID;未支持轻量能力时明确失败。 */
|
|
92
|
+
readSessionDirectoryPage(projectId: string, input: {
|
|
93
|
+
cursor?: string;
|
|
94
|
+
limit: number;
|
|
95
|
+
}): Promise<{
|
|
96
|
+
items: Array<{
|
|
97
|
+
id: string;
|
|
98
|
+
title?: string;
|
|
99
|
+
}>;
|
|
100
|
+
nextCursor?: string;
|
|
101
|
+
}>;
|
|
102
|
+
/** 关联摘要只读取轻量身份/活动事实。 */
|
|
103
|
+
readSessionSummary(sessionId: string, signal?: AbortSignal): Promise<(import("@autopilot-agent/core").SessionDirectoryEntry & {
|
|
104
|
+
currentTurnId?: string;
|
|
105
|
+
executionView?: import("@autopilot-agent/core").TurnExecutionView | null;
|
|
106
|
+
}) | null>;
|
|
77
107
|
getBootstrapService(): RuntimeBootstrapService;
|
|
78
108
|
/** 只向 Controller 暴露可安全显示的已热更新 settings 默认值。 */
|
|
79
109
|
getRuntimeStatusDefaults(): CliRuntimeStatusDefaults;
|
package/dist/composition-root.js
CHANGED
|
@@ -4,13 +4,39 @@
|
|
|
4
4
|
* 负责选择 Core 默认 Runtime、共享 Node Adapter、canonical workspaceRoot、
|
|
5
5
|
* trust policy 和显式 stateRoot;不负责命令解析、事件投影或 Runtime 状态机。
|
|
6
6
|
*/
|
|
7
|
+
import { readCliSessionSummary } from "./session-summary.js";
|
|
7
8
|
import { WEB_SEARCH_DATA_FLOW_NOTICE } from "@autopilot-agent/presentation";
|
|
8
|
-
import { createDefaultModelSamplerFactory, createRuntimeBootstrapService, createSafeBootstrapConfig, WorkspaceTrustError, getMcpServerGrantConstraint, } from "@autopilot-agent/core";
|
|
9
|
-
import { createNodeCredentialStore, createNodeCapabilityLoader, createNodeSandboxPort, createNodeSettingsLoader, createNodeSettingsWriter, ensureUserConfigDirectory, createNodeRuntimePorts, createNodeTrustPolicy, createNodeWorkspaceRegistry, createNodeWorkspaceAdapter, createNodeWorkspaceId, getNodeStateCorruptionDiagnostics, getNodeStatePaths, getNodeStateSchemaDiagnostic, initializeNodeStateRoot, resolveNodeSettingsPaths, resolveNodeStateRoot, assertNodeStateSchema, } from "@autopilot-agent/adapters";
|
|
9
|
+
import { AgentRuntimeError, createDefaultModelSamplerFactory, createRuntimeBootstrapService, createSafeBootstrapConfig, createThreadFacade, WorkspaceTrustError, getMcpServerGrantConstraint, } from "@autopilot-agent/core";
|
|
10
|
+
import { createNodeCredentialStore, createNodeCapabilityLoader, createNodeHostExecutionSandboxPort, createNodeSandboxPort, createNodeSettingsLoader, createNodeSettingsWriter, createNodeStateRootId, createNodeThreadHandoffWriter, ensureUserConfigDirectory, createNodeRuntimePorts, createNodeTrustPolicy, createNodeWorkspaceRegistry, createNodeWorkspaceAdapter, createNodeWorkspaceId, getNodeStateCorruptionDiagnostics, getNodeStatePaths, getNodeStateSchemaDiagnostic, initializeNodeStateRoot, LOCAL_HUMAN_PRINCIPAL_ID, resolveNodeSettingsPaths, resolveNodeStateRoot, assertNodeStateSchema, } from "@autopilot-agent/adapters";
|
|
11
|
+
import { createCliThreadHost } from "./thread-host.js";
|
|
10
12
|
import fs from "node:fs";
|
|
11
13
|
import path from "node:path";
|
|
12
14
|
/** CLI 专用模型行为补充:无结构化 answerer 时以普通正文完成最少必要澄清。 */
|
|
13
15
|
const CLI_TEXT_CLARIFICATION_INSTRUCTIONS = `当前宿主是 CLI,未提供 ask_user_question 或其他结构化用户回答能力。仅在完成任务确实缺少方向性信息、且不能从当前用户输入、会话历史或工作区安全获得时,才在普通助手正文中用最少必要的简短问题向用户澄清;提出问题后正常结束当前 Turn,等待用户下一条 prompt 作为同一 Session 的新 Turn 继续。不要臆造或调用 ask_user_question,不要把澄清伪装成审批,也不要在等待澄清时猜测并执行写入或命令工具。用户下一条 prompt 与任何 Other/custom 文本都不授予 Trust、权限或审批;后续工具调用仍必须遵守既有 Policy 与 Approval 约束。Agent 自身的临时脚本、截图裁剪和中间文件必须写入项目根目录的 .autopilot/tmp,不得写入 node_modules 或随意污染业务目录;用户明确指定的目标路径除外。`;
|
|
16
|
+
/**
|
|
17
|
+
* 子会话可用的工具目录:协作工具用于回报,Work 常用工具用于真正执行任务。
|
|
18
|
+
* 这是 CLI 宿主策略(与 Web 首版保持同一最小集合),会随组记录冻结并向用户展示。
|
|
19
|
+
*/
|
|
20
|
+
const CLI_THREAD_ALLOWED_TOOLS = [
|
|
21
|
+
"create_thread",
|
|
22
|
+
"list_threads",
|
|
23
|
+
"read_thread",
|
|
24
|
+
"send_thread",
|
|
25
|
+
"wait_threads",
|
|
26
|
+
"read_shared_state",
|
|
27
|
+
"update_shared_state",
|
|
28
|
+
"report_progress",
|
|
29
|
+
"read_progress",
|
|
30
|
+
"interrupt_thread",
|
|
31
|
+
"resume_thread",
|
|
32
|
+
"read_file",
|
|
33
|
+
"glob_files",
|
|
34
|
+
"grep_files",
|
|
35
|
+
"edit_file",
|
|
36
|
+
"write_file",
|
|
37
|
+
"run_command",
|
|
38
|
+
"todo_write",
|
|
39
|
+
];
|
|
14
40
|
/** 创建项目级 Agent 运行目录;拒绝链接/文件替代目录,避免临时文件逃逸工作区。 */
|
|
15
41
|
function ensureProjectAutopilotDirectory(workspaceRoot) {
|
|
16
42
|
try {
|
|
@@ -101,6 +127,27 @@ export function createCliCompositionRoot(options = {}) {
|
|
|
101
127
|
let stopSettingsWatch;
|
|
102
128
|
/** 最近一次 createRuntime 的 canonical workspaceRoot;tempRoot 注入以其为准。 */
|
|
103
129
|
let activeWorkspaceRoot;
|
|
130
|
+
/** 最近一次 bootstrap 产生的 Ports;协作 Facade 与宿主共用同一份存储。 */
|
|
131
|
+
let runtimePorts;
|
|
132
|
+
/** 已确认的 Project;未绑定时不向 Turn 注入协作能力。 */
|
|
133
|
+
let threadsProjectId;
|
|
134
|
+
/** 宿主合法模型目录;随 settings 热更新重建。 */
|
|
135
|
+
let threadsModelCatalog = [];
|
|
136
|
+
/** 返回当前可用的协作范围;缺 Project 或工作区时不注入,避免注册不可用工具。 */
|
|
137
|
+
function currentThreadsCapability() {
|
|
138
|
+
if (!threadsProjectId || !activeWorkspaceRoot)
|
|
139
|
+
return undefined;
|
|
140
|
+
return {
|
|
141
|
+
workspaceId: createNodeWorkspaceId(activeWorkspaceRoot),
|
|
142
|
+
executionHost: "cli-work-v1",
|
|
143
|
+
stateRootId: createNodeStateRootId(stateRoot),
|
|
144
|
+
projectId: threadsProjectId,
|
|
145
|
+
allowedTools: CLI_THREAD_ALLOWED_TOOLS,
|
|
146
|
+
modelCatalog: threadsModelCatalog,
|
|
147
|
+
humanPrincipalId: LOCAL_HUMAN_PRINCIPAL_ID,
|
|
148
|
+
handoff: createNodeThreadHandoffWriter({ workspaceRoot: activeWorkspaceRoot }),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
104
151
|
/** 返回当前 settings 选中模型对应的 route;firstParty 使用 CC 主配置。 */
|
|
105
152
|
function getSelectedProviderSettings(settings) {
|
|
106
153
|
const selectedRoute = settings.modelRef && settings.modelRef.provider !== "firstParty"
|
|
@@ -133,9 +180,16 @@ export function createCliCompositionRoot(options = {}) {
|
|
|
133
180
|
const loaded = settingsLoader.load(workspaceRoot);
|
|
134
181
|
resolvedSettings = loaded.settings;
|
|
135
182
|
userSettingsPath = loaded.paths.user;
|
|
183
|
+
// 模型目录只在 settings 变化时重建;协作创建不能由请求追加目录项。
|
|
184
|
+
threadsModelCatalog = getModelCapabilities().map(function toModelRef(capability) {
|
|
185
|
+
return { provider: capability.provider, modelId: capability.modelId };
|
|
186
|
+
});
|
|
136
187
|
stopSettingsWatch?.();
|
|
137
188
|
stopSettingsWatch = settingsLoader.watch(workspaceRoot, function replaceSettings(next) {
|
|
138
189
|
resolvedSettings = next.settings;
|
|
190
|
+
threadsModelCatalog = getModelCapabilities().map(function toModelRef(capability) {
|
|
191
|
+
return { provider: capability.provider, modelId: capability.modelId };
|
|
192
|
+
});
|
|
139
193
|
});
|
|
140
194
|
}
|
|
141
195
|
/** 只检查 Agent 主模型最小配置;不读取或显示任何真实 Key。 */
|
|
@@ -222,9 +276,19 @@ export function createCliCompositionRoot(options = {}) {
|
|
|
222
276
|
let sandboxPort;
|
|
223
277
|
let sandboxPortRoot;
|
|
224
278
|
function getSandboxPort(workspaceRoot) {
|
|
279
|
+
// Talk-Plan1022 S1:Windows 宿主执行模式——status/setup/doctor 只报告停用事实,
|
|
280
|
+
// 不加载 SRT、不触发 UAC provision;macOS 装配保持不变。
|
|
281
|
+
if (process.platform === "win32") {
|
|
282
|
+
if (!sandboxPort || sandboxPortRoot !== workspaceRoot) {
|
|
283
|
+
sandboxPort = createNodeHostExecutionSandboxPort();
|
|
284
|
+
sandboxPortRoot = workspaceRoot;
|
|
285
|
+
}
|
|
286
|
+
return sandboxPort;
|
|
287
|
+
}
|
|
225
288
|
if (!sandboxPort || sandboxPortRoot !== workspaceRoot) {
|
|
226
289
|
sandboxPort = createNodeSandboxPort({
|
|
227
290
|
workspaceRoot,
|
|
291
|
+
stateRoot,
|
|
228
292
|
tempRoot: path.join(workspaceRoot, ".autopilot", "tmp"),
|
|
229
293
|
});
|
|
230
294
|
sandboxPortRoot = workspaceRoot;
|
|
@@ -336,8 +400,9 @@ export function createCliCompositionRoot(options = {}) {
|
|
|
336
400
|
capabilityLoader,
|
|
337
401
|
createPorts(workspaceRoot) {
|
|
338
402
|
initializeNodeStateRoot(stateRoot);
|
|
339
|
-
|
|
403
|
+
const ports = createNodeRuntimePorts({
|
|
340
404
|
stateRoot,
|
|
405
|
+
trustRoot: options.trustRoot,
|
|
341
406
|
workspaceRoot,
|
|
342
407
|
env,
|
|
343
408
|
userSettingsPath: resolveNodeSettingsPaths(workspaceRoot).user,
|
|
@@ -345,6 +410,9 @@ export function createCliCompositionRoot(options = {}) {
|
|
|
345
410
|
//(目录由 ensureProjectAutopilotDirectory 创建并验证),不继承 ambient temp。
|
|
346
411
|
sandboxTempRoot: path.join(workspaceRoot, ".autopilot", "tmp"),
|
|
347
412
|
});
|
|
413
|
+
// 协作 Facade/宿主必须与 Runtime 使用同一份 Ports,不能另建存储。
|
|
414
|
+
runtimePorts = ports;
|
|
415
|
+
return ports;
|
|
348
416
|
},
|
|
349
417
|
defaultRunConfig: {
|
|
350
418
|
...options.defaultRunConfig,
|
|
@@ -354,7 +422,9 @@ export function createCliCompositionRoot(options = {}) {
|
|
|
354
422
|
const selectedProvider = getSelectedProviderSettings(resolvedSettings);
|
|
355
423
|
const visionRef = resolvedSettings.visionModelRef === false ? undefined : resolvedSettings.visionModelRef ?? resolvedSettings.modelRef;
|
|
356
424
|
const visionRoute = visionRef && resolvedSettings.providerRoutes[visionRef.provider];
|
|
425
|
+
const threads = currentThreadsCapability();
|
|
357
426
|
return {
|
|
427
|
+
...(resolvedSettings.maxTurns !== undefined ? { maxSteps: resolvedSettings.maxTurns } : {}),
|
|
358
428
|
...(resolvedSettings.modelRef ? { modelRef: resolvedSettings.modelRef } : {}),
|
|
359
429
|
...(resolvedSettings.reasoningProfile ? { reasoningProfile: resolvedSettings.reasoningProfile } : {}),
|
|
360
430
|
...(selectedProvider?.credentialRef ? { credentialRef: selectedProvider.credentialRef } : {}),
|
|
@@ -362,6 +432,8 @@ export function createCliCompositionRoot(options = {}) {
|
|
|
362
432
|
// tempRoot 固定指向当前 Runtime 工作区内的受控 .autopilot/tmp。
|
|
363
433
|
...(resolvedSettings.sandbox.mode ? { sandboxMode: resolvedSettings.sandbox.mode } : {}),
|
|
364
434
|
...(activeWorkspaceRoot ? { sandboxTempRoot: path.join(activeWorkspaceRoot, ".autopilot", "tmp") } : {}),
|
|
435
|
+
// 协作能力只来自宿主默认值;Turn/Project/Session override 不能注入或替换。
|
|
436
|
+
...(threads ? { threads } : {}),
|
|
365
437
|
providerSettings: {
|
|
366
438
|
...(selectedProvider ? { primary: selectedProvider } : {}),
|
|
367
439
|
routes: resolvedSettings.providerRoutes,
|
|
@@ -508,10 +580,59 @@ export function createCliCompositionRoot(options = {}) {
|
|
|
508
580
|
createRuntime: async function createRuntime(workspaceRoot) {
|
|
509
581
|
activateSettings(workspaceRoot);
|
|
510
582
|
activeWorkspaceRoot = workspaceRoot;
|
|
583
|
+
// 上一次 Runtime 的 Ports 不能沿用;协作 Facade 必须绑定当前 Runtime。
|
|
584
|
+
runtimePorts = undefined;
|
|
511
585
|
const runtime = await bootstrapService.createRuntime(workspaceRoot);
|
|
512
586
|
workspaceRegistry.register(workspaceRoot);
|
|
513
587
|
return runtime;
|
|
514
588
|
},
|
|
589
|
+
readSessionEvents: async function readSessionEvents(sessionId) {
|
|
590
|
+
if (!runtimePorts)
|
|
591
|
+
throw new Error("CLI_RUNTIME_NOT_ATTACHED");
|
|
592
|
+
return runtimePorts.transcriptStore.getEvents(sessionId);
|
|
593
|
+
},
|
|
594
|
+
readSessionEventPage: async function readSessionEventPage(sessionId, input) {
|
|
595
|
+
if (!runtimePorts)
|
|
596
|
+
throw new Error("CLI_RUNTIME_NOT_ATTACHED");
|
|
597
|
+
return runtimePorts.transcriptStore.readPage(sessionId, input);
|
|
598
|
+
},
|
|
599
|
+
readSessionDirectoryPage: async function readSessionDirectoryPage(projectId, input) {
|
|
600
|
+
if (!runtimePorts?.sessionStore.listDirectoryPage)
|
|
601
|
+
throw new Error("CLI_SESSION_DIRECTORY_UNAVAILABLE");
|
|
602
|
+
return runtimePorts.sessionStore.listDirectoryPage({ ...input, projectId });
|
|
603
|
+
},
|
|
604
|
+
readSessionSummary: async function readSessionSummary(sessionId, signal) {
|
|
605
|
+
if (!runtimePorts?.sessionStore.getDirectoryEntry)
|
|
606
|
+
throw new Error("CLI_SESSION_DIRECTORY_UNAVAILABLE");
|
|
607
|
+
return readCliSessionSummary(runtimePorts, sessionId, signal);
|
|
608
|
+
},
|
|
609
|
+
bindThreadsProject: function bindThreadsProject(projectId) {
|
|
610
|
+
threadsProjectId = projectId;
|
|
611
|
+
},
|
|
612
|
+
createHumanThreads: function createHumanThreads() {
|
|
613
|
+
const capability = currentThreadsCapability();
|
|
614
|
+
if (!capability || !runtimePorts || !activeWorkspaceRoot)
|
|
615
|
+
throw new AgentRuntimeError("THREADS_UNAVAILABLE", "THREADS_UNAVAILABLE");
|
|
616
|
+
return createThreadFacade(runtimePorts, {
|
|
617
|
+
...capability,
|
|
618
|
+
// 本机人类身份由受信宿主绑定;不来自请求参数、消息正文或模型输出。
|
|
619
|
+
actor: { kind: "human", principalId: LOCAL_HUMAN_PRINCIPAL_ID },
|
|
620
|
+
// 交接文档由 Node Adapter 原子写入受信工作区;Core 只接收安全引用。
|
|
621
|
+
handoff: createNodeThreadHandoffWriter({ workspaceRoot: activeWorkspaceRoot }),
|
|
622
|
+
});
|
|
623
|
+
},
|
|
624
|
+
createThreadHost: function createThreadHost(runtime, onError) {
|
|
625
|
+
const capability = currentThreadsCapability();
|
|
626
|
+
if (!capability || !runtimePorts)
|
|
627
|
+
throw new AgentRuntimeError("THREADS_UNAVAILABLE", "THREADS_UNAVAILABLE");
|
|
628
|
+
return createCliThreadHost({
|
|
629
|
+
workspaceId: capability.workspaceId,
|
|
630
|
+
stateRootId: capability.stateRootId,
|
|
631
|
+
runtime,
|
|
632
|
+
ports: runtimePorts,
|
|
633
|
+
...(onError ? { onError } : {}),
|
|
634
|
+
});
|
|
635
|
+
},
|
|
515
636
|
bootstrap: async function bootstrap() {
|
|
516
637
|
const trusted = await bootstrapService.establishTrust();
|
|
517
638
|
return bootstrapService.createRuntime(trusted.workspaceRoot);
|
package/dist/context-report.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Context
|
|
2
|
+
* Context / Turn 用量安全报告格式化。
|
|
3
3
|
*
|
|
4
|
-
* 所有输入只来自 Core 白名单 ContextUsageView DTO;宿主只做展示转换,
|
|
4
|
+
* 所有输入只来自 Core 白名单 ContextUsageView / TurnUsageSummaryView DTO;宿主只做展示转换,
|
|
5
5
|
* 不重算 token、不猜测窗口、不为非零分类强塞至少一格。
|
|
6
6
|
*/
|
|
7
|
-
import type { ContextUsageView } from "@autopilot-agent/core";
|
|
7
|
+
import type { ContextUsageView, TurnUsageSummaryView } from "@autopilot-agent/core";
|
|
8
8
|
/**
|
|
9
9
|
* 生成 Context 报告文本行。
|
|
10
10
|
* grid=false(Plain/screen reader/NO_COLOR)跳过装饰网格但保留完整文本;
|
|
@@ -16,5 +16,10 @@ export declare function formatContextReportLines(usage: ContextUsageView | null,
|
|
|
16
16
|
}): string[];
|
|
17
17
|
/** Plain/非 TTY 的稳定文本报告;始终跳过装饰网格。 */
|
|
18
18
|
export declare function formatPlainContextReport(usage: ContextUsageView | null, expanded: boolean): string[];
|
|
19
|
-
/**
|
|
19
|
+
/** 状态栏只显示整个窗口的整数剩余百分比;计量来源留在 /context all。 */
|
|
20
20
|
export declare function formatTuiContextStatus(usage: ContextUsageView | null): string;
|
|
21
|
+
/**
|
|
22
|
+
* 状态栏累计用量行:优先展示累计输入/输出分项,旧 checkpoint 缺少分项时降级为总量,
|
|
23
|
+
* 无数据(null/undefined)显示 unknown,不伪造 0;耗时仅在时间线末尾展示。
|
|
24
|
+
*/
|
|
25
|
+
export declare function formatTuiTurnUsageStatus(usage: TurnUsageSummaryView | null | undefined): string;
|
package/dist/context-report.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Context
|
|
2
|
+
* Context / Turn 用量安全报告格式化。
|
|
3
3
|
*
|
|
4
|
-
* 所有输入只来自 Core 白名单 ContextUsageView DTO;宿主只做展示转换,
|
|
4
|
+
* 所有输入只来自 Core 白名单 ContextUsageView / TurnUsageSummaryView DTO;宿主只做展示转换,
|
|
5
5
|
* 不重算 token、不猜测窗口、不为非零分类强塞至少一格。
|
|
6
6
|
*/
|
|
7
7
|
/** Core 固定枚举到 CLI 稳定中文标签的映射;不携带动态名称。 */
|
|
@@ -165,10 +165,21 @@ export function formatContextReportLines(usage, expanded, options) {
|
|
|
165
165
|
export function formatPlainContextReport(usage, expanded) {
|
|
166
166
|
return formatContextReportLines(usage, expanded, { grid: false, columns: Number.MAX_SAFE_INTEGER });
|
|
167
167
|
}
|
|
168
|
-
/**
|
|
168
|
+
/** 状态栏只显示整个窗口的整数剩余百分比;计量来源留在 /context all。 */
|
|
169
169
|
export function formatTuiContextStatus(usage) {
|
|
170
170
|
if (!usage)
|
|
171
171
|
return "unknown";
|
|
172
|
-
|
|
173
|
-
|
|
172
|
+
return `${Math.round(Math.max(0, 1 - usage.usageRatio) * 100)}%`;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* 状态栏累计用量行:优先展示累计输入/输出分项,旧 checkpoint 缺少分项时降级为总量,
|
|
176
|
+
* 无数据(null/undefined)显示 unknown,不伪造 0;耗时仅在时间线末尾展示。
|
|
177
|
+
*/
|
|
178
|
+
export function formatTuiTurnUsageStatus(usage) {
|
|
179
|
+
if (!usage)
|
|
180
|
+
return "unknown";
|
|
181
|
+
const counts = usage.inputTokens !== undefined && usage.outputTokens !== undefined
|
|
182
|
+
? `${formatTokens(usage.inputTokens)} in / ${formatTokens(usage.outputTokens)} out`
|
|
183
|
+
: `${formatTokens(usage.totalTokens)} total`;
|
|
184
|
+
return counts;
|
|
174
185
|
}
|