@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
|
@@ -1,8 +1,35 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Box, Text } from "ink";
|
|
3
3
|
import { TUI_ACCENT_COLOR, TUI_DIFF_ADDED_COLOR, TUI_DIFF_REMOVED_COLOR } from "../../design-tokens.js";
|
|
4
|
-
/**
|
|
4
|
+
/** 字符串diff没有对象身份;只保留最多32项/2Mi字符及每项4个键/颜色变体。 */
|
|
5
|
+
const diffRenderCache = new Map();
|
|
6
|
+
let cachedDiffCharacters = 0;
|
|
7
|
+
/** 复用既有逐行渲染元素,避免同一diff重挂载时重新split和创建节点。 */
|
|
5
8
|
export function TuiDiffBlock(props) {
|
|
9
|
+
const key = `${props.useColor}:${props.keyPrefix}`;
|
|
10
|
+
let variants = diffRenderCache.get(props.diff);
|
|
11
|
+
if (variants?.has(key))
|
|
12
|
+
return variants.get(key);
|
|
13
|
+
const rendered = renderDiffBlock(props);
|
|
14
|
+
if (props.diff.length > 2 * 1024 * 1024)
|
|
15
|
+
return rendered;
|
|
16
|
+
if (!variants) {
|
|
17
|
+
while (diffRenderCache.size >= 32 || cachedDiffCharacters + props.diff.length > 2 * 1024 * 1024) {
|
|
18
|
+
const oldest = diffRenderCache.keys().next().value;
|
|
19
|
+
cachedDiffCharacters -= oldest.length;
|
|
20
|
+
diffRenderCache.delete(oldest);
|
|
21
|
+
}
|
|
22
|
+
variants = new Map();
|
|
23
|
+
diffRenderCache.set(props.diff, variants);
|
|
24
|
+
cachedDiffCharacters += props.diff.length;
|
|
25
|
+
}
|
|
26
|
+
if (variants.size >= 4)
|
|
27
|
+
variants.delete(variants.keys().next().value);
|
|
28
|
+
variants.set(key, rendered);
|
|
29
|
+
return rendered;
|
|
30
|
+
}
|
|
31
|
+
/** 将 Core 提供的最终 unified diff 逐行着色,保持与 Web 的 edit_file 展示语义一致。 */
|
|
32
|
+
function renderDiffBlock(props) {
|
|
6
33
|
return (_jsxs(Box, { marginLeft: 2, marginTop: 1, flexDirection: "column", borderStyle: "single", borderColor: props.useColor ? TUI_ACCENT_COLOR : undefined, paddingX: 1, children: [_jsx(Text, { bold: true, color: props.useColor ? TUI_ACCENT_COLOR : undefined, children: "diff" }), props.diff.split("\n").map(function renderDiffLine(line, index) {
|
|
7
34
|
const isAdded = line.startsWith("+") && !line.startsWith("+++");
|
|
8
35
|
const isRemoved = line.startsWith("-") && !line.startsWith("---");
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* CLI 性能诊断事件:只缓冲渲染与输入时刻、耗时和事件类型,退出时一次性写入显式文件。
|
|
3
3
|
*/
|
|
4
|
+
import { NodeStateError } from "@autopilot-agent/adapters";
|
|
4
5
|
import fs from "node:fs";
|
|
5
6
|
import path from "node:path";
|
|
6
7
|
import { classifyCliError } from "../error-diagnostics.js";
|
|
@@ -53,5 +54,6 @@ export function recordTuiRuntimeErrorDiagnostic(error) {
|
|
|
53
54
|
monotonicMs: Number(performance.now().toFixed(3)),
|
|
54
55
|
errorCategory: classification.category,
|
|
55
56
|
errorCode: classification.code,
|
|
57
|
+
...(error instanceof NodeStateError ? { storage: error.getStorageDiagnostic() } : {}),
|
|
56
58
|
});
|
|
57
59
|
}
|
package/dist/tui/prompt-input.js
CHANGED
|
@@ -49,11 +49,13 @@ export function TuiPromptInput(props) {
|
|
|
49
49
|
const layout = createTuiPromptLayout(props.input, props.cursorIndex, Math.max(1, props.columns - 4));
|
|
50
50
|
const nodes = [];
|
|
51
51
|
const placeholder = props.screenReader && !props.input ? "prompt" : "";
|
|
52
|
-
|
|
52
|
+
const startLine = Math.max(0, layout.cursorLine - (props.maximumRows ?? layout.lines.length) + 1);
|
|
53
|
+
const endLine = Math.min(layout.lines.length, startLine + (props.maximumRows ?? layout.lines.length));
|
|
54
|
+
for (let index = startLine; index < endLine; index += 1) {
|
|
53
55
|
const line = layout.lines[index];
|
|
54
56
|
if (!line)
|
|
55
57
|
continue;
|
|
56
|
-
if (index >
|
|
58
|
+
if (index > startLine)
|
|
57
59
|
nodes.push("\n");
|
|
58
60
|
const isCursorLine = index === layout.cursorLine;
|
|
59
61
|
let lineText = line.text;
|
|
@@ -69,5 +71,5 @@ export function TuiPromptInput(props) {
|
|
|
69
71
|
if (isCursorLine && placeholder)
|
|
70
72
|
nodes.push(placeholder);
|
|
71
73
|
}
|
|
72
|
-
return (_jsx(Box, { "aria-role": "textbox", "aria-state": { busy: props.busy, multiline: true }, width: props.columns, marginTop: 1, borderStyle: "single", borderColor: props.useColor ? TUI_ACCENT_COLOR : undefined, paddingX: 1, children: _jsx(Text, { wrap: "wrap", children: nodes }) }));
|
|
74
|
+
return (_jsx(Box, { "aria-role": "textbox", "aria-state": { busy: props.busy, multiline: true }, width: props.columns, flexShrink: 0, marginTop: 1, borderStyle: "single", borderColor: props.useColor ? TUI_ACCENT_COLOR : undefined, paddingX: 1, children: _jsx(Text, { wrap: "wrap", children: nodes }) }));
|
|
73
75
|
}
|
|
@@ -4,13 +4,13 @@ import type { TuiRenderMode } from "./types.js";
|
|
|
4
4
|
export declare function resolveNoColor(env: NodeJS.ProcessEnv): boolean;
|
|
5
5
|
/** 解析 Ink screen-reader 开关,并保留 Ink 官方环境变量兼容性。 */
|
|
6
6
|
export declare function resolveScreenReader(env: NodeJS.ProcessEnv): boolean;
|
|
7
|
-
/**
|
|
8
|
-
export declare function resolveTuiRenderModePolicy(
|
|
7
|
+
/** 交互统一使用inline主屏,滚动交给终端,不启用备用屏/正文滚动条。 */
|
|
8
|
+
export declare function resolveTuiRenderModePolicy(_input: {
|
|
9
9
|
env: NodeJS.ProcessEnv;
|
|
10
10
|
platform: NodeJS.Platform | string;
|
|
11
11
|
}): TuiRenderMode;
|
|
12
|
-
/**
|
|
13
|
-
export declare function getTuiRenderModeFallbackNotice(
|
|
12
|
+
/** 各平台统一inline,不增加额外模式回落提示。 */
|
|
13
|
+
export declare function getTuiRenderModeFallbackNotice(_input: {
|
|
14
14
|
env: NodeJS.ProcessEnv;
|
|
15
15
|
platform: NodeJS.Platform | string;
|
|
16
16
|
}): string | undefined;
|
package/dist/tui/render-mode.js
CHANGED
|
@@ -7,19 +7,13 @@ export function resolveNoColor(env) {
|
|
|
7
7
|
export function resolveScreenReader(env) {
|
|
8
8
|
return env.INK_SCREEN_READER === "true" || env.SCREEN_READER === "1" || env.SCREEN_READER === "true";
|
|
9
9
|
}
|
|
10
|
-
/**
|
|
11
|
-
export function resolveTuiRenderModePolicy(
|
|
12
|
-
if (resolveScreenReader(input.env) || input.env.AUTOPILOT_INLINE_TUI === "1")
|
|
13
|
-
return "inline";
|
|
14
|
-
if (input.env.AUTOPILOT_TUI_FULLSCREEN === "1" && input.platform !== "win32")
|
|
15
|
-
return "alternate-screen";
|
|
10
|
+
/** 交互统一使用inline主屏,滚动交给终端,不启用备用屏/正文滚动条。 */
|
|
11
|
+
export function resolveTuiRenderModePolicy(_input) {
|
|
16
12
|
return "inline";
|
|
17
13
|
}
|
|
18
|
-
/**
|
|
19
|
-
export function getTuiRenderModeFallbackNotice(
|
|
20
|
-
|
|
21
|
-
return undefined;
|
|
22
|
-
return "AUTOPILOT_TUI_FULLSCREEN is unsupported on win32; using inline mode. Remove AUTOPILOT_TUI_FULLSCREEN to cancel this request.\n";
|
|
14
|
+
/** 各平台统一inline,不增加额外模式回落提示。 */
|
|
15
|
+
export function getTuiRenderModeFallbackNotice(_input) {
|
|
16
|
+
return undefined;
|
|
23
17
|
}
|
|
24
18
|
/** 仅在 TUI 启动期决定内联或备用屏;宿主 TTY/Plain 门禁仍由 main.ts 保持。 */
|
|
25
19
|
export function resolveTuiRenderMode(env, platform = process.platform) {
|
package/dist/tui/run.js
CHANGED
|
@@ -2,6 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
/** TUI 入口编排:启动 Ink,统一处理信号、退出码和动态渲染生命周期。 */
|
|
3
3
|
import { render } from "ink";
|
|
4
4
|
import { createTuiInputRouter } from "../tui-input-router.js";
|
|
5
|
+
import { CliSessionWorkspace } from "./session-workspace.js";
|
|
5
6
|
import { CliTuiApp } from "./app.js";
|
|
6
7
|
import { getTuiStatusLabel, isActiveTuiStatus, isTerminalStatus, readTuiTerminalSize } from "./format.js";
|
|
7
8
|
import { createRoutedTuiStdin, createTuiMouseInputSink, createTuiRenderStdout, createTuiTerminalLifecycle } from "./lifecycle.js";
|
|
@@ -17,7 +18,7 @@ export function formatCliTuiRecap(recap) {
|
|
|
17
18
|
/** 启动 Ink,统一处理信号、退出码和动态渲染生命周期。 */
|
|
18
19
|
export async function runCliTui(options) {
|
|
19
20
|
const env = options.env ?? process.env;
|
|
20
|
-
const store = createCliTuiStore();
|
|
21
|
+
const store = options.sessionManager?.selected().store ?? createCliTuiStore();
|
|
21
22
|
const noColor = resolveNoColor(env);
|
|
22
23
|
const screenReader = resolveScreenReader(env);
|
|
23
24
|
const renderMode = resolveTuiRenderMode(env);
|
|
@@ -36,7 +37,18 @@ export async function runCliTui(options) {
|
|
|
36
37
|
let requestedExitCode;
|
|
37
38
|
let lastResult;
|
|
38
39
|
let instance;
|
|
39
|
-
let
|
|
40
|
+
let pendingRenderSize;
|
|
41
|
+
/** 先让Ink用旧尺寸完成新短帧,再提交真实新尺寸,避免旧帧高度触发Static全量重放。 */
|
|
42
|
+
function requestRenderSize(size) { pendingRenderSize = size; }
|
|
43
|
+
/** onRender回调发生在同步输出之前,微任务确保高度记账已更新;尺寸不伪造。 */
|
|
44
|
+
function commitRenderedSize() {
|
|
45
|
+
queueMicrotask(function commit() {
|
|
46
|
+
const size = pendingRenderSize;
|
|
47
|
+
pendingRenderSize = undefined;
|
|
48
|
+
if (size)
|
|
49
|
+
renderStdout.setSize(size);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
40
52
|
let pendingWheelNotches = 0;
|
|
41
53
|
let pendingWheelEvent;
|
|
42
54
|
let mouseFlushTimer;
|
|
@@ -93,13 +105,13 @@ export async function runCliTui(options) {
|
|
|
93
105
|
function writeTuiRecap() {
|
|
94
106
|
if (!options.sessionId)
|
|
95
107
|
return;
|
|
96
|
-
const snapshot = store.getSnapshot();
|
|
108
|
+
const snapshot = (options.sessionManager?.selected().store ?? store).getSnapshot();
|
|
97
109
|
const completedTurnCount = snapshot.transcript.filter(function countCompletedTurn(item) {
|
|
98
110
|
return item.kind === "turn" && item.status === "completed";
|
|
99
111
|
}).length;
|
|
100
112
|
try {
|
|
101
113
|
options.streams.stdout.write(`\n${formatCliTuiRecap({
|
|
102
|
-
sessionId: options.sessionId,
|
|
114
|
+
sessionId: options.sessionManager?.selected().sessionId ?? options.sessionId,
|
|
103
115
|
completedTurnCount,
|
|
104
116
|
finalStatus: snapshot.status,
|
|
105
117
|
recoverable: snapshot.recoverable,
|
|
@@ -136,52 +148,24 @@ export async function runCliTui(options) {
|
|
|
136
148
|
store.addNotice("turn cancellation failed");
|
|
137
149
|
});
|
|
138
150
|
}
|
|
139
|
-
/**
|
|
140
|
-
function requestInterrupt() {
|
|
141
|
-
|
|
142
|
-
const current = store.getSnapshot();
|
|
143
|
-
if (isActiveTuiStatus(current.status)) {
|
|
144
|
-
if (current.cancellationRequested) {
|
|
145
|
-
if (now - lastInterruptAt < 100)
|
|
146
|
-
return;
|
|
147
|
-
options.streams.stderr.write("forced exit before cancellation completed; recovery status unknown\n");
|
|
148
|
-
finish(130);
|
|
149
|
-
terminalLifecycle.restore();
|
|
150
|
-
options.forceExit?.(130);
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
lastInterruptAt = now;
|
|
154
|
-
requestCancellation();
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
finish(130);
|
|
158
|
-
}
|
|
159
|
-
/** 处理 Esc:只取消活动 Turn,不把 Esc 解释为退出进程。 */
|
|
151
|
+
/** Ctrl+C退出整个宿主;具体owner收尾交Main,不沿创建来源取消。 */
|
|
152
|
+
function requestInterrupt() { finish(130); }
|
|
153
|
+
/** Esc只取消提交时选中目标,列表/picker优先消费;不退出宿主。 */
|
|
160
154
|
function requestCancel() {
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
/** 处理宿主 SIGINT/SIGTERM:取消后以相应进程退出码收口。 */
|
|
164
|
-
function requestSignalStop(code) {
|
|
165
|
-
requestedExitCode = requestedExitCode ?? code;
|
|
166
|
-
store.requestExit(code);
|
|
167
|
-
if (isActiveTuiStatus(store.getSnapshot().status)) {
|
|
155
|
+
if (!options.sessionManager) {
|
|
168
156
|
requestCancellation();
|
|
169
157
|
return;
|
|
170
158
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
requestedExitCode = requestedExitCode ?? 0;
|
|
175
|
-
store.requestExit(0);
|
|
176
|
-
const current = store.getSnapshot();
|
|
177
|
-
if (current.status === "running" || current.status === "waiting_approval") {
|
|
178
|
-
void options.controller.dispatch({ type: "cancel_turn" }).then(handleResult).catch(function ignoreEofCancelFailure() {
|
|
179
|
-
finish(0);
|
|
180
|
-
});
|
|
159
|
+
const entry = options.sessionManager.selected();
|
|
160
|
+
const current = entry.store.getSnapshot();
|
|
161
|
+
if (!isActiveTuiStatus(current.status) || current.cancellationRequested)
|
|
181
162
|
return;
|
|
182
|
-
|
|
183
|
-
|
|
163
|
+
entry.store.setCancellationRequested(true);
|
|
164
|
+
void entry.controller.dispatch({ type: "cancel_turn" }).then(function completed(result) { options.sessionManager.handleResult(entry, result); }).catch(function failed() { entry.store.setCancellationRequested(false); entry.store.addNotice("turn cancellation failed"); });
|
|
184
165
|
}
|
|
166
|
+
/** SIGTERM与EOF都退出整个宿主,不把等待审批伪装为完成。 */
|
|
167
|
+
function requestSignalStop(code) { finish(code); }
|
|
168
|
+
function handleEof() { finish(0); }
|
|
185
169
|
function handleSigint() { requestInterrupt(); }
|
|
186
170
|
function handleSigterm() { requestSignalStop(143); }
|
|
187
171
|
options.signalSource.on("SIGINT", handleSigint);
|
|
@@ -191,11 +175,14 @@ export async function runCliTui(options) {
|
|
|
191
175
|
if (event.type === "status" && isTerminalStatus(event.status) && requestedExitCode !== undefined)
|
|
192
176
|
finish(requestedExitCode);
|
|
193
177
|
};
|
|
194
|
-
options.
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
178
|
+
if (!options.sessionManager)
|
|
179
|
+
options.controller.setEventListener?.(listener);
|
|
180
|
+
if (!options.sessionManager)
|
|
181
|
+
options.controller.setQueuedInputListener?.(function receiveQueuedInputStarted(input) {
|
|
182
|
+
store.markQueuedInputStarted(input);
|
|
183
|
+
});
|
|
184
|
+
const App = options.sessionManager ? CliSessionWorkspace : CliTuiApp;
|
|
185
|
+
const node = (_jsx(App, { manager: options.sessionManager, store: store, controller: options.controller, initial: options.initial, closeWhenIdle: options.closeWhenIdle, workspaceRoot: options.workspaceRoot, useColor: !noColor && !screenReader, screenReader: screenReader, renderMode: renderMode, reducedMotion: reducedMotion, mouseInput: mouseInput, onResult: options.sessionManager ? function rememberResult(result) { lastResult = result; } : handleResult, onRequestInterrupt: requestInterrupt, onRequestCancel: requestCancel, onEof: handleEof, onAppExit: finish, terminalSizeSource: terminalSizeSource, onTerminalSizeChange: requestRenderSize }));
|
|
199
186
|
try {
|
|
200
187
|
terminalLifecycle.enter();
|
|
201
188
|
instance = render(node, {
|
|
@@ -207,6 +194,7 @@ export async function runCliTui(options) {
|
|
|
207
194
|
// 输入框和动态时间线会改变行高;Windows Terminal 下增量渲染会残留旧帧,
|
|
208
195
|
// 表现为逐字符重复或内容重叠。使用完整帧保证当前交互区域正确。
|
|
209
196
|
incrementalRendering: false,
|
|
197
|
+
onRender: commitRenderedSize,
|
|
210
198
|
isScreenReaderEnabled: screenReader,
|
|
211
199
|
kittyKeyboard: { mode: kittyKeyboardMode },
|
|
212
200
|
});
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { AgentEventEnvelope, AgentRuntime, Session, TurnExecutionView } from "@autopilot-agent/core";
|
|
2
|
+
import type { CliController, CliControllerResult } from "../controller.js";
|
|
3
|
+
import type { CliTuiStore } from "./types.js";
|
|
4
|
+
import type { CliTuiDraftRef } from "./hooks/use-prompt-input.js";
|
|
5
|
+
/** 主子视图共用已保存交互文案,底层暂停状态保持原样。 */
|
|
6
|
+
export declare function getCliInteractionLabel(view?: TurnExecutionView): string | undefined;
|
|
7
|
+
/** 已打开或有关联活动的目标;未打开的普通目录项没有Controller/Store。 */
|
|
8
|
+
export interface CliSessionEntry {
|
|
9
|
+
sessionId: string;
|
|
10
|
+
title: string;
|
|
11
|
+
attachments: string[];
|
|
12
|
+
controller: CliController;
|
|
13
|
+
store: CliTuiStore;
|
|
14
|
+
unread: boolean;
|
|
15
|
+
hydrated: boolean;
|
|
16
|
+
opened: boolean;
|
|
17
|
+
parentSessionId?: string;
|
|
18
|
+
historyCursor?: string;
|
|
19
|
+
historyMore: boolean;
|
|
20
|
+
historyLoading: boolean;
|
|
21
|
+
summaryCursor?: string;
|
|
22
|
+
summaryTurnId?: string;
|
|
23
|
+
summaryStatus?: Session["status"];
|
|
24
|
+
summaryKnown?: boolean;
|
|
25
|
+
summaryReady?: boolean;
|
|
26
|
+
summaryApproval?: AgentEventEnvelope;
|
|
27
|
+
summaryRejectedId?: string;
|
|
28
|
+
executionView?: TurnExecutionView;
|
|
29
|
+
interactionNotice?: string;
|
|
30
|
+
viewState: {
|
|
31
|
+
draftRef: CliTuiDraftRef;
|
|
32
|
+
initialStarted: boolean;
|
|
33
|
+
lastSubmittedPrompt: {
|
|
34
|
+
current: string | undefined;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
pendingPrompts?: NonNullable<Session["presentation"]>["messages"];
|
|
38
|
+
}
|
|
39
|
+
/** 退出只陈述当前宿主确认的执行事实。 */
|
|
40
|
+
export interface CliSessionExitReport {
|
|
41
|
+
stopped: string[];
|
|
42
|
+
waiting: string[];
|
|
43
|
+
recoverable: string[];
|
|
44
|
+
unconfirmed: string[];
|
|
45
|
+
}
|
|
46
|
+
/** 普通目录只持有显示标题与内部路由身份。 */
|
|
47
|
+
export interface CliSessionDirectoryItem {
|
|
48
|
+
sessionId: string;
|
|
49
|
+
title: string;
|
|
50
|
+
}
|
|
51
|
+
/** 历史分页保留末尾游标,nextCursor仅表示还有旧页。 */
|
|
52
|
+
export interface CliSessionEventPage {
|
|
53
|
+
items: AgentEventEnvelope[];
|
|
54
|
+
cursor?: string;
|
|
55
|
+
nextCursor?: string;
|
|
56
|
+
}
|
|
57
|
+
/** 关联轻量状态由受信宿主绑定,普通独立会话不进入此列表。 */
|
|
58
|
+
export interface CliSessionRelation {
|
|
59
|
+
threadId: string;
|
|
60
|
+
parentThreadId: string | null;
|
|
61
|
+
title?: string;
|
|
62
|
+
status?: Session["status"];
|
|
63
|
+
activeTurnId?: string;
|
|
64
|
+
executionView?: TurnExecutionView | null;
|
|
65
|
+
}
|
|
66
|
+
/** 创建Project级轻量目录,所有分页/异步结果固定写回原目标。 */
|
|
67
|
+
export declare function createCliSessionManager(options: {
|
|
68
|
+
runtime: AgentRuntime;
|
|
69
|
+
projectId: string;
|
|
70
|
+
initialSession: Session;
|
|
71
|
+
initialController: CliController;
|
|
72
|
+
createController(sessionId: string): CliController;
|
|
73
|
+
readRelations?(sessionId: string, signal?: AbortSignal): Promise<CliSessionRelation[]>;
|
|
74
|
+
readSummary?(sessionId: string, signal?: AbortSignal): Promise<{
|
|
75
|
+
title?: string;
|
|
76
|
+
status?: Session["status"];
|
|
77
|
+
activeTurnId?: string;
|
|
78
|
+
currentTurnId?: string;
|
|
79
|
+
executionView?: TurnExecutionView | null;
|
|
80
|
+
} | null>;
|
|
81
|
+
readDirectoryPage?(input: {
|
|
82
|
+
cursor?: string;
|
|
83
|
+
limit: number;
|
|
84
|
+
}): Promise<{
|
|
85
|
+
items: Array<{
|
|
86
|
+
id: string;
|
|
87
|
+
title?: string;
|
|
88
|
+
}>;
|
|
89
|
+
nextCursor?: string;
|
|
90
|
+
}>;
|
|
91
|
+
readEventPage?(sessionId: string, input: {
|
|
92
|
+
cursor?: string;
|
|
93
|
+
limit: number;
|
|
94
|
+
}): Promise<CliSessionEventPage>;
|
|
95
|
+
}): {
|
|
96
|
+
entries: () => CliSessionEntry[];
|
|
97
|
+
directory: () => CliSessionDirectoryItem[];
|
|
98
|
+
directoryState: () => {
|
|
99
|
+
loading: boolean;
|
|
100
|
+
more: boolean;
|
|
101
|
+
};
|
|
102
|
+
selected: () => CliSessionEntry;
|
|
103
|
+
related: (sessionId?: string) => CliSessionEntry[];
|
|
104
|
+
select: (sessionId: string) => Promise<void>;
|
|
105
|
+
refresh: () => Promise<void>;
|
|
106
|
+
loadDirectory: () => Promise<void>;
|
|
107
|
+
loadHistory: (sessionId?: string) => Promise<void>;
|
|
108
|
+
handleResult: (entry: CliSessionEntry, result: CliControllerResult) => void;
|
|
109
|
+
stop: () => Promise<CliSessionExitReport>;
|
|
110
|
+
subscribe: (listener: () => void) => () => void;
|
|
111
|
+
/** 首屏不等待历史;仅已打开/关联活动目标后续按游标有界观察。 */
|
|
112
|
+
start: () => void;
|
|
113
|
+
};
|
|
114
|
+
/** TUI只依赖轻量目录接口,不接触底层存储。 */
|
|
115
|
+
export type CliSessionManager = ReturnType<typeof createCliSessionManager>;
|