@autopilot-agent/cli 0.2.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 +10 -5
- package/dist/activity-animation.d.ts +4 -0
- package/dist/activity-animation.js +11 -17
- package/dist/composition-root.d.ts +31 -1
- package/dist/composition-root.js +112 -3
- package/dist/context-report.d.ts +8 -3
- package/dist/context-report.js +14 -2
- package/dist/controller.d.ts +34 -4
- package/dist/controller.js +434 -90
- 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 +74 -5
- package/dist/index.d.ts +1 -1
- package/dist/main.js +142 -7
- package/dist/parser.js +498 -0
- package/dist/renderer.js +3 -1
- 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/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 +112 -40
- package/dist/tui/approval.d.ts +4 -0
- package/dist/tui/approval.js +13 -4
- 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 +19 -9
- 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 +27 -5
- package/dist/tui/timeline/live.js +2 -3
- package/dist/tui/timeline/progress.js +3 -2
- package/dist/tui/timeline/static-timeline.js +1 -2
- package/dist/tui/timeline/turn.js +3 -2
- package/dist/tui/transcript.d.ts +1 -1
- package/dist/tui/transcript.js +19 -1
- package/dist/tui/trust-dialog.d.ts +3 -0
- package/dist/tui/trust-dialog.js +23 -2
- package/dist/tui/types.d.ts +8 -0
- package/dist/tui/types.js +4 -1
- package/dist/tui/viewport/sources.js +6 -13
- package/dist/types.d.ts +152 -2
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# @autopilot-agent/cli
|
|
2
2
|
|
|
3
|
-
Autopilot 的终端宿主包。普通用户安装主包 `autopilot-agent@0.
|
|
3
|
+
Autopilot 的终端宿主包。普通用户安装主包 `autopilot-agent@0.3.0`,无需分别安装各个 scoped 包:
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
|
-
npm install -g autopilot-agent@0.
|
|
6
|
+
npm install -g autopilot-agent@0.3.0
|
|
7
7
|
ap --help
|
|
8
8
|
```
|
|
9
9
|
|
|
@@ -13,8 +13,9 @@ ap --help
|
|
|
13
13
|
|
|
14
14
|
- parser.ts 解析 argv 与交互命令,main.ts 编排入口、输出及退出。
|
|
15
15
|
- composition-root.ts 注入共享 Core Runtime 与 Node Adapters,controller.ts 管理任务、审批与恢复。
|
|
16
|
+
- thread-commands.ts / thread-host.ts 承载同机会话协作:`ap thread ...` 薄命令复用 Core 协作协议,交互会话持有驱动 Runner;两者共用同一状态根与 Project。
|
|
16
17
|
- tui/ 使用 React / Ink;renderer.ts 与 event-projector.ts 支持纯文本和 JSONL。
|
|
17
|
-
- 内部依赖为 Core、Adapters、Presentation,0.
|
|
18
|
+
- 内部依赖为 Core、Adapters、Presentation,0.3.0 使用匹配的精确版本。
|
|
18
19
|
|
|
19
20
|
本包的 bin 提供 ap/autopilot,主入口包再转发至本包的 dist/main.js,不复制 Runtime。TTY 使用交互界面;显式 --output text/jsonl 用于脚本,JSONL 不输出 ANSI 或交互提示。
|
|
20
21
|
|
|
@@ -44,9 +45,13 @@ build 使用 TypeScript,输出 dist/*.js 与声明,不在 npm 包中发布
|
|
|
44
45
|
|
|
45
46
|
CLI 使用用户级 settings.json,默认工作区为当前目录,可显式指定 --workspace-root。CLI 不读取开发仓库 Web env,也不因配置中含 RAG 字段而自动启用私有知识库工具。重要项目保留版本控制,OS 沙箱、MCP 和平台限制见主包手册。
|
|
46
47
|
|
|
47
|
-
## 0.
|
|
48
|
+
## 0.3.0 版本
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
新增单窗口多会话、任务分派与进展汇报、主子会话双入口审批和图片输入。`Ctrl+T` 切换会话,`Ctrl+A` 处理真实待办请求;历史结构化问题可在原目标会话回答并继续。历史按需加载,输出使用终端原生滚动,并改进启动、缩放和流式完成时的布局。
|
|
51
|
+
|
|
52
|
+
用户模型配置继续使用用户级 settings.json。图片处理取决于模型及工具能力,首次使用前按主包手册配置。已知旧版状态在受信初始化时自动备份升级,保留升级前数据。
|
|
53
|
+
|
|
54
|
+
本包随 npm 0.3.0 发布,内部依赖使用匹配的精确版本。Windows 命令、后台 Job 与 host MCP 逐次审批后以当前用户权限直接执行,审批不提供 OS 隔离;macOS 继续使用 Seatbelt。实机与进程树生命周期仍需按实际验证确认。
|
|
50
55
|
|
|
51
56
|
## 许可证
|
|
52
57
|
|
|
@@ -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;
|
|
@@ -54,6 +56,8 @@ export declare function TuiActivityLine(props: {
|
|
|
54
56
|
animationActive: boolean;
|
|
55
57
|
clock: TuiAnimationClock;
|
|
56
58
|
startedAt?: number;
|
|
59
|
+
elapsedMs?: number;
|
|
60
|
+
runningSince?: number;
|
|
57
61
|
activeForm?: string;
|
|
58
62
|
}): ReactNode;
|
|
59
63
|
export {};
|
|
@@ -8,7 +8,6 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
8
8
|
*/
|
|
9
9
|
import { useEffect, useState } from "react";
|
|
10
10
|
import { Box, Text } from "ink";
|
|
11
|
-
import { formatTuiDuration } from "./tui/format.js";
|
|
12
11
|
export const CLI_ACTIVITY_STALLED_AFTER_MS = 20_000;
|
|
13
12
|
export const CLI_ACTIVITY_TRANSITION_MS = 2_000;
|
|
14
13
|
/** CC v2.1.88 的默认 spinner glyph;首尾重复保证 ping-pong 转向自然。 */
|
|
@@ -73,16 +72,6 @@ export function getCliActivityFrame(phase, now) {
|
|
|
73
72
|
return "";
|
|
74
73
|
return CLI_ACTIVITY_SPINNER_FRAMES[Math.floor(Math.max(0, now) / CLI_ACTIVITY_SPINNER_FRAME_MS) % CLI_ACTIVITY_SPINNER_FRAMES.length] ?? "·";
|
|
75
74
|
}
|
|
76
|
-
function formatCliActivityElapsed(durationMs) {
|
|
77
|
-
const totalSeconds = Math.max(1, Math.floor(Math.max(0, durationMs) / 1_000));
|
|
78
|
-
if (totalSeconds < 60)
|
|
79
|
-
return `${totalSeconds}s`;
|
|
80
|
-
const minutes = Math.floor(totalSeconds / 60);
|
|
81
|
-
const seconds = totalSeconds % 60;
|
|
82
|
-
if (minutes < 60)
|
|
83
|
-
return `${minutes}m ${String(seconds).padStart(2, "0")}s`;
|
|
84
|
-
return `${Math.floor(minutes / 60)}h ${String(minutes % 60).padStart(2, "0")}m ${String(seconds).padStart(2, "0")}s`;
|
|
85
|
-
}
|
|
86
75
|
/** 返回活动阶段的稳定文案,供动画降级和 screen reader 使用。 */
|
|
87
76
|
function getCliActivityLabel(phase, input = {}) {
|
|
88
77
|
switch (phase) {
|
|
@@ -91,7 +80,7 @@ function getCliActivityLabel(phase, input = {}) {
|
|
|
91
80
|
case "waiting": return input.hasActiveTool ? "Waiting · tool result" : "Waiting · provider response";
|
|
92
81
|
case "transition": return "Running action · starting tool";
|
|
93
82
|
case "responding": return "Answering · receiving output";
|
|
94
|
-
case "stalled": return
|
|
83
|
+
case "stalled": return "Still working";
|
|
95
84
|
case "terminal": return "Completed";
|
|
96
85
|
}
|
|
97
86
|
}
|
|
@@ -105,6 +94,11 @@ export function resolveCliActivityView(input) {
|
|
|
105
94
|
if (input.waitingForApproval || status === "waiting_approval") {
|
|
106
95
|
return { phase: "waiting", label: "Waiting for approval", frame: getCliActivityFrame("waiting", now) };
|
|
107
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
|
+
}
|
|
108
102
|
let phase = activity.phase;
|
|
109
103
|
if (phase === "transition" && activity.transitionStartedAt !== undefined && now - activity.transitionStartedAt >= CLI_ACTIVITY_TRANSITION_MS) {
|
|
110
104
|
phase = activity.hasActiveTool ? "waiting" : "thinking";
|
|
@@ -116,16 +110,16 @@ export function resolveCliActivityView(input) {
|
|
|
116
110
|
}
|
|
117
111
|
return {
|
|
118
112
|
phase,
|
|
119
|
-
label: getCliActivityLabel(phase, {
|
|
113
|
+
label: getCliActivityLabel(phase, { hasActiveTool: activity.hasActiveTool }),
|
|
120
114
|
frame: getCliActivityFrame(phase, now),
|
|
121
115
|
};
|
|
122
116
|
}
|
|
123
117
|
/** 渲染稳定活动文案和可选的固定宽度离散帧。 */
|
|
124
118
|
export function TuiActivityLine(props) {
|
|
125
119
|
const [clockTime, setClockTime] = useState(props.clock.now());
|
|
126
|
-
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 });
|
|
127
121
|
const shouldAnimate = props.animationActive && !props.screenReader && !props.reducedMotion && view !== undefined && view.phase !== "terminal";
|
|
128
|
-
const shouldTick = shouldAnimate || (props.
|
|
122
|
+
const shouldTick = shouldAnimate || (props.runningSince !== undefined && props.status === "running");
|
|
129
123
|
useEffect(function subscribeActivityClock() {
|
|
130
124
|
props.clock.setActive(shouldTick);
|
|
131
125
|
if (!shouldTick) {
|
|
@@ -134,7 +128,7 @@ export function TuiActivityLine(props) {
|
|
|
134
128
|
}
|
|
135
129
|
setClockTime(props.clock.now());
|
|
136
130
|
return props.clock.subscribe(function updateActivityClock(time) {
|
|
137
|
-
//
|
|
131
|
+
// 禁动画仍按秒检查静默状态,复用同一枚时钟。
|
|
138
132
|
setClockTime(function next(previous) { return shouldAnimate || Math.floor(previous / 1000) !== Math.floor(time / 1000) ? time : previous; });
|
|
139
133
|
});
|
|
140
134
|
}, [props.clock, shouldAnimate, shouldTick]);
|
|
@@ -144,5 +138,5 @@ export function TuiActivityLine(props) {
|
|
|
144
138
|
return null;
|
|
145
139
|
const frame = shouldAnimate ? view.frame : "·";
|
|
146
140
|
const isStalled = view.phase === "stalled";
|
|
147
|
-
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 }) }),
|
|
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 })] }));
|
|
148
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, createNodeHostExecutionSandboxPort, 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。 */
|
|
@@ -346,7 +400,7 @@ export function createCliCompositionRoot(options = {}) {
|
|
|
346
400
|
capabilityLoader,
|
|
347
401
|
createPorts(workspaceRoot) {
|
|
348
402
|
initializeNodeStateRoot(stateRoot);
|
|
349
|
-
|
|
403
|
+
const ports = createNodeRuntimePorts({
|
|
350
404
|
stateRoot,
|
|
351
405
|
trustRoot: options.trustRoot,
|
|
352
406
|
workspaceRoot,
|
|
@@ -356,6 +410,9 @@ export function createCliCompositionRoot(options = {}) {
|
|
|
356
410
|
//(目录由 ensureProjectAutopilotDirectory 创建并验证),不继承 ambient temp。
|
|
357
411
|
sandboxTempRoot: path.join(workspaceRoot, ".autopilot", "tmp"),
|
|
358
412
|
});
|
|
413
|
+
// 协作 Facade/宿主必须与 Runtime 使用同一份 Ports,不能另建存储。
|
|
414
|
+
runtimePorts = ports;
|
|
415
|
+
return ports;
|
|
359
416
|
},
|
|
360
417
|
defaultRunConfig: {
|
|
361
418
|
...options.defaultRunConfig,
|
|
@@ -365,6 +422,7 @@ export function createCliCompositionRoot(options = {}) {
|
|
|
365
422
|
const selectedProvider = getSelectedProviderSettings(resolvedSettings);
|
|
366
423
|
const visionRef = resolvedSettings.visionModelRef === false ? undefined : resolvedSettings.visionModelRef ?? resolvedSettings.modelRef;
|
|
367
424
|
const visionRoute = visionRef && resolvedSettings.providerRoutes[visionRef.provider];
|
|
425
|
+
const threads = currentThreadsCapability();
|
|
368
426
|
return {
|
|
369
427
|
...(resolvedSettings.maxTurns !== undefined ? { maxSteps: resolvedSettings.maxTurns } : {}),
|
|
370
428
|
...(resolvedSettings.modelRef ? { modelRef: resolvedSettings.modelRef } : {}),
|
|
@@ -374,6 +432,8 @@ export function createCliCompositionRoot(options = {}) {
|
|
|
374
432
|
// tempRoot 固定指向当前 Runtime 工作区内的受控 .autopilot/tmp。
|
|
375
433
|
...(resolvedSettings.sandbox.mode ? { sandboxMode: resolvedSettings.sandbox.mode } : {}),
|
|
376
434
|
...(activeWorkspaceRoot ? { sandboxTempRoot: path.join(activeWorkspaceRoot, ".autopilot", "tmp") } : {}),
|
|
435
|
+
// 协作能力只来自宿主默认值;Turn/Project/Session override 不能注入或替换。
|
|
436
|
+
...(threads ? { threads } : {}),
|
|
377
437
|
providerSettings: {
|
|
378
438
|
...(selectedProvider ? { primary: selectedProvider } : {}),
|
|
379
439
|
routes: resolvedSettings.providerRoutes,
|
|
@@ -520,10 +580,59 @@ export function createCliCompositionRoot(options = {}) {
|
|
|
520
580
|
createRuntime: async function createRuntime(workspaceRoot) {
|
|
521
581
|
activateSettings(workspaceRoot);
|
|
522
582
|
activeWorkspaceRoot = workspaceRoot;
|
|
583
|
+
// 上一次 Runtime 的 Ports 不能沿用;协作 Facade 必须绑定当前 Runtime。
|
|
584
|
+
runtimePorts = undefined;
|
|
523
585
|
const runtime = await bootstrapService.createRuntime(workspaceRoot);
|
|
524
586
|
workspaceRegistry.register(workspaceRoot);
|
|
525
587
|
return runtime;
|
|
526
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
|
+
},
|
|
527
636
|
bootstrap: async function bootstrap() {
|
|
528
637
|
const trusted = await bootstrapService.establishTrust();
|
|
529
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)跳过装饰网格但保留完整文本;
|
|
@@ -18,3 +18,8 @@ export declare function formatContextReportLines(usage: ContextUsageView | null,
|
|
|
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 稳定中文标签的映射;不携带动态名称。 */
|
|
@@ -171,3 +171,15 @@ export function formatTuiContextStatus(usage) {
|
|
|
171
171
|
return "unknown";
|
|
172
172
|
return `${Math.round(Math.max(0, 1 - usage.usageRatio) * 100)}%`;
|
|
173
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;
|
|
185
|
+
}
|
package/dist/controller.d.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* Session/Turn 状态机,审批只从当前安全 projection 取得 approvalId,绝不
|
|
6
6
|
* 生成 callId、toolName、normalizedInputHash 或冻结工具输入。
|
|
7
7
|
*/
|
|
8
|
-
import type { AgentEvent, ApprovalDecision, ContextUsageView } from "@autopilot-agent/core";
|
|
9
|
-
import type { CliAction, CliCommand, CliEffortOption, CliExitCode, CliEventListener, CliJobView, CliQueuedInputStartedListener, CliModelOption, CliPermissionOption, CliProjection, CliRenderer, CliRuntimeStatusDefaults, CliSkillCatalogLister, CliSkillResolver, CliSkillSummary, CliStatusView, CliRuntime } from "./types.js";
|
|
8
|
+
import type { AgentEvent, AgentEventEnvelope, ApprovalDecision, ContextUsageView } from "@autopilot-agent/core";
|
|
9
|
+
import type { CliAction, CliCommand, CliEffortOption, CliExitCode, CliEventListener, CliJobView, CliQueuedInputStartedListener, CliModelOption, CliPermissionOption, CliProjection, CliRenderer, CliRuntimeStatusDefaults, CliSkillCatalogLister, CliSkillResolver, CliSkillSummary, CliStatusView, CliTurnStatus, CliRuntime } from "./types.js";
|
|
10
10
|
/** 为当前 Controller 注入的审批提交回调;四字段之外不允许宿主提供凭证。 */
|
|
11
11
|
export type CliApprovalSubmit = (input: {
|
|
12
12
|
sessionId: string;
|
|
@@ -56,6 +56,15 @@ export interface CreateCliControllerOptions {
|
|
|
56
56
|
/** 读取已热更新的安全 Runtime 默认值;仅用于 idle/Completed 状态栏,不参与 Turn 冻结。 */
|
|
57
57
|
getRuntimeStatusDefaults?: () => CliRuntimeStatusDefaults;
|
|
58
58
|
onEvent?: CliEventListener;
|
|
59
|
+
/** 普通执行与现有 Runner 共享 owner 索引;不因前台选择转移 owner。 */
|
|
60
|
+
registerExecution?(input: {
|
|
61
|
+
threadId: string;
|
|
62
|
+
turnId: string;
|
|
63
|
+
cancel(): void;
|
|
64
|
+
}): {
|
|
65
|
+
activate(): void;
|
|
66
|
+
release(): void;
|
|
67
|
+
};
|
|
59
68
|
/** 自动启动 queue Turn 前通知交互 TUI,避免等待 prompt 残留在底部。 */
|
|
60
69
|
onQueuedInputStarted?: CliQueuedInputStartedListener;
|
|
61
70
|
now?: () => Date;
|
|
@@ -64,10 +73,31 @@ export interface CreateCliControllerOptions {
|
|
|
64
73
|
export interface CliController {
|
|
65
74
|
dispatch(action: CliAction): Promise<CliControllerResult>;
|
|
66
75
|
consume(events: AsyncIterable<AgentEvent>): Promise<CliControllerResult>;
|
|
67
|
-
resume(
|
|
76
|
+
resume(expectedApproval?: {
|
|
77
|
+
turnId: string;
|
|
78
|
+
approvalId: string;
|
|
79
|
+
}): Promise<CliControllerResult>;
|
|
80
|
+
/** 只读回放安全事件,不领取输入、执行lease或恢复Turn。 */
|
|
81
|
+
observe?(events: readonly AgentEventEnvelope[]): void;
|
|
82
|
+
/** 只读权威身份改变时失效旧交互与在途结果,不恢复或执行。 */
|
|
83
|
+
invalidateObservedTurn?(input: {
|
|
84
|
+
turnId?: string;
|
|
85
|
+
status: CliTurnStatus;
|
|
86
|
+
}): void;
|
|
87
|
+
/** 同步权威当前交互,不改变正文回放游标。 */
|
|
88
|
+
syncObservedInteraction?(input: {
|
|
89
|
+
turnId: string;
|
|
90
|
+
status: CliTurnStatus;
|
|
91
|
+
approval?: AgentEventEnvelope;
|
|
92
|
+
requestId?: string;
|
|
93
|
+
}): void;
|
|
94
|
+
isExecuting?(): boolean;
|
|
95
|
+
beginShutdown?(): void;
|
|
68
96
|
getProjection(): CliProjection;
|
|
69
97
|
/** 读取当前 Session 默认或活动 Turn frozen 的脱敏状态栏视图。 */
|
|
70
|
-
getStatusView?(
|
|
98
|
+
getStatusView?(input?: {
|
|
99
|
+
signal?: AbortSignal;
|
|
100
|
+
}): Promise<CliStatusView>;
|
|
71
101
|
setSession(sessionId: string): void;
|
|
72
102
|
setEventListener(listener?: import("./types.js").CliEventListener): void;
|
|
73
103
|
/** 绑定 queue Turn 启动通知;Plain 宿主不需要注册。 */
|