@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
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** 合并既有 Presentation 与宿主输入位置,并读取每轮最后一次安全 Todo。 */
|
|
2
|
+
import { capturePresentationInputPosition, reducePresentationInput, selectTurnTimeline } from "@autopilot-agent/presentation";
|
|
3
|
+
/** 保存当前可见事实的稳定边界,连续回答以字符位置保留输入前后的正文。 */
|
|
4
|
+
export function captureTuiInputPosition(turnId, events, presentation) {
|
|
5
|
+
return { turnId, eventCount: events.filter(function publicEvent(event) { return event.type !== "tui_input_consumed"; }).length, items: presentation && turnId ? capturePresentationInputPosition(presentation, turnId).items : [] };
|
|
6
|
+
}
|
|
7
|
+
/** 只采用该轮自身的最后一次 todo_updated;显式空列表保持清空语义。 */
|
|
8
|
+
export function getTuiTurnTodo(events, turnId) {
|
|
9
|
+
for (let index = events.length - 1; index >= 0; index -= 1) {
|
|
10
|
+
const event = events[index];
|
|
11
|
+
if (event?.type === "todo_updated" && event.turnId === turnId)
|
|
12
|
+
return { id: `todo:${turnId}`, kind: "todo", turnId, todos: event.todos, counts: event.counts };
|
|
13
|
+
}
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
/** 按提交边界切分共享节点,再复用 selector 分组;宿主正文不会被后来的分组或回答吞到前面。 */
|
|
17
|
+
export function getTuiTurnItems(presentation, turnId, events) {
|
|
18
|
+
const inputs = events.filter(function host(event) { return event.type === "tui_input_consumed"; });
|
|
19
|
+
let state = presentation;
|
|
20
|
+
for (const input of inputs) {
|
|
21
|
+
state = reducePresentationInput(state, { kind: "host_event", event: { kind: "input", input: { turnId: input.turnId, inputId: input.inputId, delivery: input.delivery, content: input.content, position: input.position ?? { items: [] }, cancelled: input.cancelled, state: input.consumed === false ? "queued" : "consumed" } } });
|
|
22
|
+
}
|
|
23
|
+
const todo = getTuiTurnTodo(events, turnId);
|
|
24
|
+
// CLI 只采用本轮 events;不把恢复或 Session latest 误当作本轮更新。
|
|
25
|
+
state = { ...state, todosByTurn: { ...state.todosByTurn, [turnId]: todo ?? { id: `todo:${turnId}`, kind: "todo", turnId, todos: [], counts: { completed: 0, pending: 0, inProgress: 0 } } } };
|
|
26
|
+
const inputById = new Map(inputs.map(function pair(input) { return [input.inputId, input]; }));
|
|
27
|
+
return selectTurnTimeline(state, turnId).map(function host(item) { return item.kind === "input_notice" ? inputById.get(item.inputId) ?? item : item; });
|
|
28
|
+
}
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
/** 渲染当前 Turn;它会随安全事件更新,完成后整体进入历史树。 */
|
|
3
3
|
import { memo } from "react";
|
|
4
4
|
import { Box, Text } from "ink";
|
|
5
|
+
import { getCliTuiExecutionMs } from "../types.js";
|
|
5
6
|
import { TuiApprovalPrompt } from "../approval.js";
|
|
6
7
|
import { formatTuiDuration, getTuiTerminationSummary, getTuiTurnFailureReason } from "../format.js";
|
|
7
8
|
import { TuiLiveTimeline } from "./live.js";
|
|
8
9
|
import { renderTuiPresentationTimeline } from "./presentation-timeline.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
10
|
+
import { TuiTodoList } from "../todo-list.js";
|
|
11
|
+
import { getTuiTurnTodo } from "./turn-items.js";
|
|
11
12
|
/** 渲染当前 Turn;memo 保证输入光标更新不会触发 live timeline 组件执行。 */
|
|
12
13
|
export const TuiLiveTurn = memo(function TuiLiveTurn(props) {
|
|
13
|
-
if (!props.turnId || props.events.length === 0)
|
|
14
|
+
if (!props.turnId || (props.events.length === 0 && !props.pendingApproval))
|
|
14
15
|
return null;
|
|
15
16
|
const hasPresentation = props.presentation?.items.some(function belongsToTurn(item) { return item.kind === "capability_notice" || ("turnId" in item && item.turnId === props.turnId); }) ?? false;
|
|
16
17
|
const failureReason = getTuiTurnFailureReason(props.events);
|
|
17
18
|
const terminationSummary = getTuiTerminationSummary(props.events, props.status);
|
|
18
|
-
return (_jsxs(Box, { flexDirection: "column", children: [
|
|
19
|
-
? renderTuiPresentationTimeline(props.presentation, props.turnId, props.useColor, props.maximumWidth, { expanded: props.todoExpanded, screenReader: props.screenReader, rowLimit: props.todoRowLimit, showToggleHint: true, toolGroupsExpanded: props.todoExpanded })
|
|
20
|
-
: _jsx(TuiLiveTimeline, { turnId: props.turnId, events: props.events, status: props.status, metrics: props.metrics, useColor: props.useColor, maximumWidth: props.maximumWidth }), terminationSummary ? _jsxs(Text, { children: ["\u7EC8\u6001\uFF1A", terminationSummary] }) : hasPresentation && failureReason ? _jsxs(Text, { children: ["\u539F\u56E0\uFF1A", failureReason] }) : null, props.pendingApproval ? _jsx(TuiApprovalPrompt, { pendingApproval: props.pendingApproval, selectedIndex: props.approvalSelectedIndex, useColor: props.useColor, screenReader: props.screenReader }) : null, props.metrics?.completedAt !== undefined ? _jsxs(Text, { dimColor: props.useColor, children: ["* Cogitated for ", formatTuiDuration(
|
|
19
|
+
return (_jsxs(Box, { flexDirection: "column", children: [props.presentation && hasPresentation
|
|
20
|
+
? renderTuiPresentationTimeline(props.presentation, props.turnId, props.useColor, props.maximumWidth, { expanded: props.todoExpanded, screenReader: props.screenReader, rowLimit: props.todoRowLimit, showToggleHint: true, toolGroupsExpanded: props.todoExpanded }, props.events)
|
|
21
|
+
: _jsxs(_Fragment, { children: [_jsx(TuiLiveTimeline, { turnId: props.turnId, events: props.events, status: props.status, metrics: props.metrics, useColor: props.useColor, maximumWidth: props.maximumWidth }), getTuiTurnTodo(props.events, props.turnId) ? _jsx(TuiTodoList, { item: getTuiTurnTodo(props.events, props.turnId), expanded: props.todoExpanded || props.screenReader, screenReader: props.screenReader, useColor: props.useColor, columns: props.maximumWidth + 2, rowLimit: props.todoRowLimit, showToggleHint: true }) : null] }), terminationSummary ? _jsxs(Text, { children: ["\u7EC8\u6001\uFF1A", terminationSummary] }) : hasPresentation && failureReason ? _jsxs(Text, { children: ["\u539F\u56E0\uFF1A", failureReason] }) : null, props.pendingApproval ? _jsx(TuiApprovalPrompt, { pendingApproval: props.pendingApproval, selectedIndex: props.approvalSelectedIndex, useColor: props.useColor, screenReader: props.screenReader }) : null, props.metrics?.completedAt !== undefined ? _jsxs(Text, { dimColor: props.useColor, children: ["* Cogitated for ", formatTuiDuration(getCliTuiExecutionMs(props.metrics, props.metrics.completedAt))] }) : null] }));
|
|
21
22
|
});
|
package/dist/tui/transcript.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare function TuiPromptLine(props: {
|
|
|
8
8
|
columns: number;
|
|
9
9
|
keyValue?: string;
|
|
10
10
|
}): ReactNode;
|
|
11
|
-
/**
|
|
11
|
+
/** 按不可变历史item引用复用元素;不冻结当前Turn或改变输出。 */
|
|
12
12
|
export declare function TuiTranscriptItem(props: {
|
|
13
13
|
item: CliTuiTranscriptItem;
|
|
14
14
|
useColor: boolean;
|
|
@@ -17,7 +17,7 @@ export declare function TuiTranscriptItem(props: {
|
|
|
17
17
|
}): ReactNode;
|
|
18
18
|
/** 历史节点保持引用稳定;回答流动时只重新计算当前 Turn。 */
|
|
19
19
|
export declare const MemoizedTuiTranscriptItem: import("react").MemoExoticComponent<typeof TuiTranscriptItem>;
|
|
20
|
-
/**
|
|
20
|
+
/** queue 在等待区显示原文;steer 正文已按提交位置留在所属轮。 */
|
|
21
21
|
export declare function TuiPendingInputItem(props: {
|
|
22
22
|
item: CliTuiPendingInput;
|
|
23
23
|
useColor: boolean;
|
package/dist/tui/transcript.js
CHANGED
|
@@ -14,8 +14,26 @@ export function TuiPromptLine(props) {
|
|
|
14
14
|
return _jsx(Text, { bold: props.useColor, children: segment.text }, index);
|
|
15
15
|
}) }) }, props.keyValue));
|
|
16
16
|
}
|
|
17
|
-
/**
|
|
17
|
+
/** 历史item生命周期内最多保留四个尺寸/颜色/读屏变体,跨重挂载复用稳定元素。 */
|
|
18
|
+
const transcriptRenderCache = new WeakMap();
|
|
19
|
+
/** 按不可变历史item引用复用元素;不冻结当前Turn或改变输出。 */
|
|
18
20
|
export function TuiTranscriptItem(props) {
|
|
21
|
+
const key = `${props.columns}:${props.useColor}:${props.screenReader ?? false}`;
|
|
22
|
+
let variants = transcriptRenderCache.get(props.item);
|
|
23
|
+
if (variants?.has(key))
|
|
24
|
+
return variants.get(key);
|
|
25
|
+
const rendered = renderTranscriptItem(props);
|
|
26
|
+
if (!variants) {
|
|
27
|
+
variants = new Map();
|
|
28
|
+
transcriptRenderCache.set(props.item, variants);
|
|
29
|
+
}
|
|
30
|
+
if (variants.size >= 4)
|
|
31
|
+
variants.delete(variants.keys().next().value);
|
|
32
|
+
variants.set(key, rendered);
|
|
33
|
+
return rendered;
|
|
34
|
+
}
|
|
35
|
+
/** 渲染已经完成的 prompt、notice 或完整 Turn。 */
|
|
36
|
+
function renderTranscriptItem(props) {
|
|
19
37
|
const item = props.item;
|
|
20
38
|
if (item.kind === "prompt") {
|
|
21
39
|
return _jsx(TuiPromptLine, { content: item.content, useColor: props.useColor, columns: props.columns, keyValue: item.key }, item.key);
|
|
@@ -27,8 +45,8 @@ export function TuiTranscriptItem(props) {
|
|
|
27
45
|
}
|
|
28
46
|
/** 历史节点保持引用稳定;回答流动时只重新计算当前 Turn。 */
|
|
29
47
|
export const MemoizedTuiTranscriptItem = memo(TuiTranscriptItem);
|
|
30
|
-
/**
|
|
48
|
+
/** queue 在等待区显示原文;steer 正文已按提交位置留在所属轮。 */
|
|
31
49
|
export function TuiPendingInputItem(props) {
|
|
32
50
|
const label = props.item.delivery === "queue" ? "[排队]" : "[引导]";
|
|
33
|
-
return (
|
|
51
|
+
return (_jsxs(Box, { flexDirection: "column", backgroundColor: props.useColor ? TUI_WAITING_BACKGROUND_COLOR : undefined, children: [props.item.delivery === "queue" ? _jsx(Text, { children: props.item.content }) : null, _jsxs(Text, { dimColor: props.useColor, children: ["\u21B3 ", label, " \u7B49\u5F85\u5F53\u524D\u6B65\u9AA4\u7ED3\u675F"] })] }, props.item.key));
|
|
34
52
|
}
|
|
@@ -39,6 +39,9 @@ export interface CliTrustDialogOptions {
|
|
|
39
39
|
write(chunk: string): void;
|
|
40
40
|
isTTY?: boolean;
|
|
41
41
|
columns?: number;
|
|
42
|
+
rows?: number;
|
|
43
|
+
on?(event: "resize", listener: () => void): unknown;
|
|
44
|
+
off?(event: "resize", listener: () => void): unknown;
|
|
42
45
|
};
|
|
43
46
|
stdin: NodeJS.ReadStream;
|
|
44
47
|
};
|
package/dist/tui/trust-dialog.js
CHANGED
|
@@ -9,7 +9,8 @@ import { useRef, useState } from "react";
|
|
|
9
9
|
import { Box, Text, render, useInput } from "ink";
|
|
10
10
|
import { TUI_ACCENT_COLOR } from "../design-tokens.js";
|
|
11
11
|
import { parseTuiControlAction } from "./input/keys.js";
|
|
12
|
-
import { createRoutedTuiStdin, createTuiTerminalLifecycle } from "./lifecycle.js";
|
|
12
|
+
import { createRoutedTuiStdin, createTuiRenderStdout, createTuiTerminalLifecycle } from "./lifecycle.js";
|
|
13
|
+
import { readTuiTerminalSize } from "./format.js";
|
|
13
14
|
import { resolveNoColor, resolveScreenReader } from "./render-mode.js";
|
|
14
15
|
/** Trust 对话框固定选项;Yes 是唯一授权动作。 */
|
|
15
16
|
export const TRUST_DIALOG_OPTIONS = [
|
|
@@ -45,6 +46,24 @@ export function runCliTrustDialog(options) {
|
|
|
45
46
|
const screenReader = resolveScreenReader(env);
|
|
46
47
|
const routedStdin = createRoutedTuiStdin(options.streams.stdin);
|
|
47
48
|
const terminalLifecycle = createTuiTerminalLifecycle(options.streams.stdout, "inline");
|
|
49
|
+
const renderStdout = createTuiRenderStdout(options.streams.stdout, readTuiTerminalSize(options.streams.stdout));
|
|
50
|
+
let resizeTimer;
|
|
51
|
+
/** 防抖后提交稳定尺寸,复用主界面的缩窄清理。 */
|
|
52
|
+
function handleResize() {
|
|
53
|
+
if (resizeTimer)
|
|
54
|
+
clearTimeout(resizeTimer);
|
|
55
|
+
resizeTimer = setTimeout(function commitSize() {
|
|
56
|
+
resizeTimer = undefined;
|
|
57
|
+
renderStdout.setSize(readTuiTerminalSize(options.streams.stdout));
|
|
58
|
+
}, 200);
|
|
59
|
+
}
|
|
60
|
+
/** 所有退出路径移除尺寸监听及待处理定时器。 */
|
|
61
|
+
function detachResize() {
|
|
62
|
+
if (resizeTimer)
|
|
63
|
+
clearTimeout(resizeTimer);
|
|
64
|
+
options.streams.stdout.off?.("resize", handleResize);
|
|
65
|
+
}
|
|
66
|
+
options.streams.stdout.on?.("resize", handleResize);
|
|
48
67
|
let decision = "declined";
|
|
49
68
|
let settled = false;
|
|
50
69
|
let instance;
|
|
@@ -100,7 +119,7 @@ export function runCliTrustDialog(options) {
|
|
|
100
119
|
try {
|
|
101
120
|
terminalLifecycle.enter();
|
|
102
121
|
instance = render(_jsx(TrustDialogApp, {}), {
|
|
103
|
-
stdout:
|
|
122
|
+
stdout: renderStdout.stdout,
|
|
104
123
|
stdin: routedStdin,
|
|
105
124
|
exitOnCtrlC: false,
|
|
106
125
|
patchConsole: true,
|
|
@@ -110,6 +129,7 @@ export function runCliTrustDialog(options) {
|
|
|
110
129
|
}
|
|
111
130
|
catch {
|
|
112
131
|
terminalLifecycle.restore();
|
|
132
|
+
detachResize();
|
|
113
133
|
detachTrustInput();
|
|
114
134
|
options.signalSource?.removeListener("SIGINT", handleSigint);
|
|
115
135
|
options.signalSource?.removeListener("SIGTERM", handleSigterm);
|
|
@@ -118,6 +138,7 @@ export function runCliTrustDialog(options) {
|
|
|
118
138
|
}
|
|
119
139
|
void instance.waitUntilExit().then(function finishTrustDialog() {
|
|
120
140
|
terminalLifecycle.restore();
|
|
141
|
+
detachResize();
|
|
121
142
|
detachTrustInput();
|
|
122
143
|
options.signalSource?.removeListener("SIGINT", handleSigint);
|
|
123
144
|
options.signalSource?.removeListener("SIGTERM", handleSigterm);
|
package/dist/tui/types.d.ts
CHANGED
|
@@ -35,6 +35,9 @@ export type CliTuiTimelineEvent = CliPublicEvent | {
|
|
|
35
35
|
inputId: string;
|
|
36
36
|
content: string;
|
|
37
37
|
delivery: "steer" | "queue";
|
|
38
|
+
consumed?: boolean;
|
|
39
|
+
cancelled?: boolean;
|
|
40
|
+
position?: CliTuiInputPosition;
|
|
38
41
|
} | {
|
|
39
42
|
type: "tui_approval_submitted";
|
|
40
43
|
seq: number;
|
|
@@ -51,12 +54,27 @@ export interface CliTuiPendingInput {
|
|
|
51
54
|
inputId: string;
|
|
52
55
|
delivery: "steer" | "queue";
|
|
53
56
|
}
|
|
57
|
+
/** 提交瞬间的本地位置;只引用安全展示节点,不保存附件展开或私有消息。 */
|
|
58
|
+
export interface CliTuiInputPosition {
|
|
59
|
+
turnId?: string;
|
|
60
|
+
eventCount: number;
|
|
61
|
+
order?: number;
|
|
62
|
+
items: Array<{
|
|
63
|
+
id: string;
|
|
64
|
+
answerLength?: number;
|
|
65
|
+
}>;
|
|
66
|
+
}
|
|
54
67
|
/** Turn 的本地展示计时;只用于 TUI 文案,不进入 Runtime 或持久化事件。 */
|
|
55
68
|
export interface CliTuiTurnMetrics {
|
|
56
69
|
startedAt: number;
|
|
57
70
|
firstAnswerAt?: number;
|
|
71
|
+
firstAnswerDurationMs?: number;
|
|
72
|
+
elapsedMs?: number;
|
|
73
|
+
runningSince?: number;
|
|
58
74
|
completedAt?: number;
|
|
59
75
|
}
|
|
76
|
+
/** 复用共享 Presentation 执行段;旧宿主缺少时钟事实时不擅自把等待计为执行。 */
|
|
77
|
+
export declare function getCliTuiExecutionMs(metrics: CliTuiTurnMetrics, now?: number): number;
|
|
60
78
|
/** 当前 Turn 的用户输入;动态区保留它,避免历史区固化时机导致 prompt 消失。 */
|
|
61
79
|
export interface CliTuiActivePrompt {
|
|
62
80
|
key: string;
|
|
@@ -78,6 +96,7 @@ export interface CliTuiSnapshot {
|
|
|
78
96
|
status: CliTurnStatus;
|
|
79
97
|
recoverable: boolean;
|
|
80
98
|
pendingApproval?: CliProjection["pendingApproval"];
|
|
99
|
+
threadWait?: CliProjection["threadWait"];
|
|
81
100
|
activeSkills: Array<{
|
|
82
101
|
skillId: string;
|
|
83
102
|
contentHash: string;
|
|
@@ -92,10 +111,11 @@ export interface CliTuiStore {
|
|
|
92
111
|
getSnapshot(): CliTuiSnapshot;
|
|
93
112
|
subscribe(listener: () => void): () => void;
|
|
94
113
|
recordPrompt(content: string, displayAsActive?: boolean): string | undefined;
|
|
114
|
+
captureInputPosition(): CliTuiInputPosition;
|
|
95
115
|
addPendingPrompt(content: string, input: {
|
|
96
116
|
inputId: string;
|
|
97
117
|
delivery: "steer" | "queue";
|
|
98
|
-
}): void;
|
|
118
|
+
}, position?: CliTuiInputPosition): void;
|
|
99
119
|
markQueuedInputStarted(input: CliQueuedInputStarted): void;
|
|
100
120
|
recordApprovalSubmission(decision: Extract<CliAction, {
|
|
101
121
|
type: "approve";
|
|
@@ -116,6 +136,8 @@ export type CliTuiInitialOperation = {
|
|
|
116
136
|
/** Ink TUI 的运行参数。 */
|
|
117
137
|
export interface RunCliTuiOptions {
|
|
118
138
|
controller: CliController;
|
|
139
|
+
/** Project级固定会话目录;选择只变视图,不恢复执行。 */
|
|
140
|
+
sessionManager?: import("./session-manager.js").CliSessionManager;
|
|
119
141
|
/** 主机已知的只读会话标识;仅用于备用屏退出后的安全摘要。 */
|
|
120
142
|
sessionId?: string;
|
|
121
143
|
/** canonical 工作区根;仅用于 @ 文件候选索引预热。 */
|
package/dist/tui/types.js
CHANGED
|
@@ -2,4 +2,7 @@
|
|
|
2
2
|
* 仅 TUI 层自有类型。Controller / 投影 / 事件等宿主协议类型统一从
|
|
3
3
|
* ../types.js 与 ../controller.js 复用,不在这里重复声明领域协议。
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
/** 复用共享 Presentation 执行段;旧宿主缺少时钟事实时不擅自把等待计为执行。 */
|
|
6
|
+
export function getCliTuiExecutionMs(metrics, now = Date.now()) {
|
|
7
|
+
return (metrics.elapsedMs ?? 0) + (metrics.runningSince === undefined ? 0 : Math.max(0, now - metrics.runningSince));
|
|
8
|
+
}
|
|
@@ -7,7 +7,7 @@ export declare function formatTuiViewportMarkdown(content: string, maximumWidth:
|
|
|
7
7
|
/** 将历史版本的 unified diff 直角卡片转换为备用屏可裁剪的文字源,并保留边框与逐行语义颜色。 */
|
|
8
8
|
export declare function createTuiViewportDiffSource(itemId: string, diff: string, contentWidth: number): TimelineLineSource;
|
|
9
9
|
/** 将已完成与当前动态时间线统一变为可裁剪的视觉行来源。 */
|
|
10
|
-
export declare function createTuiViewportSources(snapshot: CliTuiSnapshot, statusView: CliStatusView | undefined, approvalSelectedIndex: number, contentWidth: number, toolGroupsExpanded?: boolean, decorativeGrid?: boolean): TimelineLineSource[];
|
|
10
|
+
export declare function createTuiViewportSources(snapshot: CliTuiSnapshot, statusView: CliStatusView | undefined, approvalSelectedIndex: number, contentWidth: number, toolGroupsExpanded?: boolean, decorativeGrid?: boolean, todoRowLimit?: number): TimelineLineSource[];
|
|
11
11
|
/** 备用屏 source 缓存计数,区分历史命中与 live tail 重建。 */
|
|
12
12
|
export interface TuiViewportSourceCacheStats {
|
|
13
13
|
brandBuilds: number;
|
|
@@ -21,7 +21,7 @@ export interface TuiViewportSourceCacheStats {
|
|
|
21
21
|
}
|
|
22
22
|
/** 按 transcript item 与 live tail 增量生成备用屏 source 的内部接口。 */
|
|
23
23
|
export interface TuiViewportSourceCache {
|
|
24
|
-
getSources(snapshot: CliTuiSnapshot, statusView: CliStatusView | undefined, approvalSelectedIndex: number, contentWidth: number, toolGroupsExpanded?: boolean, decorativeGrid?: boolean): TimelineLineSource[];
|
|
24
|
+
getSources(snapshot: CliTuiSnapshot, statusView: CliStatusView | undefined, approvalSelectedIndex: number, contentWidth: number, toolGroupsExpanded?: boolean, decorativeGrid?: boolean, todoRowLimit?: number): TimelineLineSource[];
|
|
25
25
|
getStats(): TuiViewportSourceCacheStats;
|
|
26
26
|
clear(): void;
|
|
27
27
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/** 备用屏时间线来源:把安全事件转为可裁剪的纯文本视觉行来源。 */
|
|
2
2
|
import stringWidth from "string-width";
|
|
3
3
|
import wrapAnsi from "wrap-ansi";
|
|
4
|
-
import { WEB_SEARCH_DATA_FLOW_NOTICE, getPresentationCopy,
|
|
4
|
+
import { WEB_SEARCH_DATA_FLOW_NOTICE, getPresentationCopy, getToolPresentationProfile, isSandboxUnavailableErrorCode, selectToolCalls } from "@autopilot-agent/presentation";
|
|
5
|
+
import { getCliTuiExecutionMs } from "../types.js";
|
|
5
6
|
import { createAutopilotStaticWordRows } from "../brand/pixel.js";
|
|
6
7
|
import { AUTOPILOT_VERSION, TUI_AGENT_LABEL } from "../constants.js";
|
|
7
|
-
import { getTuiTodoDisplay, getTuiTodoStatusGlyph } from "../todo-list.js";
|
|
8
8
|
import { cleanTuiToolSummary, formatTuiDiffStats, formatTuiDuration, formatTuiInputConsumed, formatTuiToolLine, getTuiDiffStats, getTuiStatusLabel, getTuiToolLabel, getTuiTurnFailureReason, getTuiTerminationSummary, } from "../format.js";
|
|
9
9
|
import { getTuiMarkdownTableColumnWidths, isLooseMarkdownTable, isMarkdownTableDivider, normalizeMarkdownTableCells, splitMarkdownTableRow, } from "../markdown/table.js";
|
|
10
|
+
import { getTuiTurnItems, getTuiTurnTodo } from "../timeline/turn-items.js";
|
|
11
|
+
import { getTuiTodoDisplay, getTuiTodoStatusLabel } from "../todo-list.js";
|
|
10
12
|
/** 将对用户安全公开的时间线事件转换为备用屏内的纯文本行。 */
|
|
11
13
|
function formatTuiViewportEvent(event) {
|
|
12
14
|
if (event.type === "answer_delta")
|
|
@@ -213,46 +215,26 @@ function createTuiViewportBrandSource(statusView) {
|
|
|
213
215
|
],
|
|
214
216
|
};
|
|
215
217
|
}
|
|
216
|
-
/** 将 Todo 任务链转换为备用屏文本源;备用屏空间充足,始终以展开形态显示最终清单。 */
|
|
217
|
-
function createTuiTodoViewportSource(itemId, item, contentWidth) {
|
|
218
|
-
const display = getTuiTodoDisplay(item, { expanded: true, screenReader: false, columns: contentWidth });
|
|
219
|
-
if (!display)
|
|
220
|
-
return undefined;
|
|
221
|
-
const output = [];
|
|
222
|
-
const spans = [];
|
|
223
|
-
let sourceOffset = 0;
|
|
224
|
-
/** 追加一行 Todo 文本并按状态记录相对样式范围。 */
|
|
225
|
-
function appendTodoLine(line, style) {
|
|
226
|
-
output.push(line);
|
|
227
|
-
if (style && line)
|
|
228
|
-
spans.push({ start: sourceOffset, end: sourceOffset + line.length, style });
|
|
229
|
-
sourceOffset += line.length + 1;
|
|
230
|
-
}
|
|
231
|
-
appendTodoLine(display.header, undefined);
|
|
232
|
-
for (const row of display.rows) {
|
|
233
|
-
if (row.hidden)
|
|
234
|
-
appendTodoLine(`+${row.text}`, "muted");
|
|
235
|
-
else
|
|
236
|
-
appendTodoLine(`${getTuiTodoStatusGlyph(row.status)} ${row.text}`, row.status === "in_progress" ? "accent" : row.status === "completed" ? "muted" : undefined);
|
|
237
|
-
}
|
|
238
|
-
return { itemId, text: output.join("\n"), spans };
|
|
239
|
-
}
|
|
240
218
|
/** 将共享 Presentation selector 转成备用屏文本源,与 inline TUI 复用同一事实和顺序。 */
|
|
241
|
-
function createTuiPresentationViewportSources(presentation, turnId, itemId, contentWidth, toolGroupsExpanded) {
|
|
219
|
+
function createTuiPresentationViewportSources(presentation, turnId, itemId, contentWidth, toolGroupsExpanded, events, live, rowLimit = 10) {
|
|
242
220
|
const sources = [];
|
|
243
221
|
// 构建 callId 索引供展开分组取回组内调用。
|
|
244
222
|
const callIndex = new Map(selectToolCalls(presentation, turnId).map(function indexToolCall(call) { return [call.callId, call]; }));
|
|
245
223
|
let index = 0;
|
|
246
|
-
for (const item of
|
|
224
|
+
for (const item of getTuiTurnItems(presentation, turnId, events)) {
|
|
225
|
+
if ("type" in item) {
|
|
226
|
+
sources.push({ itemId: `${itemId}:input:${item.inputId}`, text: item.content, spans: createTuiViewportTextSpans(item.content, "accent") });
|
|
227
|
+
sources.push({ itemId: `${itemId}:input:${item.inputId}:state`, text: item.cancelled ? "[引导] 已取消" : item.consumed === false ? "[引导] 等待当前步骤结束" : formatTuiInputConsumed(item) });
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
247
230
|
if (item.kind !== "capability_notice" && (!("turnId" in item) || item.turnId !== turnId))
|
|
248
231
|
continue;
|
|
249
232
|
const sourceId = `${itemId}:presentation:${String(index++)}`;
|
|
250
233
|
if (item.kind === "todo") {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
sources.push(todoSource);
|
|
234
|
+
sources.push(...createTuiTodoSources(item, sourceId, contentWidth, live ? toolGroupsExpanded : true, live, rowLimit));
|
|
235
|
+
continue;
|
|
254
236
|
}
|
|
255
|
-
|
|
237
|
+
if (item.kind === "thinking")
|
|
256
238
|
sources.push({ itemId: sourceId, text: `✢ ${item.summary}`, spans: createTuiViewportTextSpans(`✢ ${item.summary}`, "muted") });
|
|
257
239
|
else if (item.kind === "tool_group") {
|
|
258
240
|
const text = `• Exploring codebase · ${item.toolCallIds.length} operations`;
|
|
@@ -279,13 +261,15 @@ function createTuiPresentationViewportSources(presentation, turnId, itemId, cont
|
|
|
279
261
|
const detail = `${[jobProgramLabel ? undefined : item.target, item.resultSummary].filter(Boolean).join(" · ")}${diffStatsText ? ` ${diffStatsText}` : ""}`;
|
|
280
262
|
const detailLine = jobProgramLabel ? `\n └─ ${jobProgramLabel}${detail ? ` · ${detail}` : ""}` : detail ? `\n └─ ${detail}` : "";
|
|
281
263
|
const jobHint = item.job?.action === "start" && (item.job.observedStatus === "starting" || item.job.observedStatus === "running") ? "\n /jobs 查看后台任务" : "";
|
|
282
|
-
const title = getPresentationCopy(item.titleKey);
|
|
283
|
-
|
|
264
|
+
const title = getPresentationCopy(item.state === "failed" ? getToolPresentationProfile(item.toolName).completedTitleKey : item.titleKey);
|
|
265
|
+
// 2.5:沙箱不可用类拒绝是环境阻塞而非用户拒绝,文案必须区分。
|
|
266
|
+
const stateText = item.state === "denied" ? (isSandboxUnavailableErrorCode(item.errorCode) ? "沙箱不可用,命令未启动" : "已拒绝") : item.state === "cancelled" ? "已取消" : item.state === "timeout" ? "已超时" : undefined;
|
|
267
|
+
const badgeText = `[${title}]${stateText ? ` · ${stateText}` : ""}`;
|
|
268
|
+
const text = `${item.state === "failed" ? "×" : "•"} ${badgeText}${detailLine}${item.errorCode ? `\n └─ ${item.errorCode}` : ""}${jobHint}`;
|
|
284
269
|
const programStart = jobProgramLabel ? text.indexOf(jobProgramLabel) : -1;
|
|
285
270
|
const hintStart = jobHint ? text.length - jobHint.trimStart().length : -1;
|
|
286
271
|
const badgeStart = 2;
|
|
287
|
-
const badgeEnd = badgeStart +
|
|
288
|
-
const firstLineEnd = text.indexOf("\n") < 0 ? text.length : text.indexOf("\n");
|
|
272
|
+
const badgeEnd = badgeStart + badgeText.length;
|
|
289
273
|
const spans = createTuiViewportDiffStatsSpans(text, diffStats);
|
|
290
274
|
if (programStart >= 0 && jobProgramLabel)
|
|
291
275
|
spans.push({ start: programStart, end: programStart + jobProgramLabel.length, style: "accent" });
|
|
@@ -297,7 +281,7 @@ function createTuiPresentationViewportSources(presentation, turnId, itemId, cont
|
|
|
297
281
|
spans.push({ start: badgeStart, end: badgeEnd, style: "chip-active" });
|
|
298
282
|
}
|
|
299
283
|
else {
|
|
300
|
-
spans.push({ start:
|
|
284
|
+
spans.push({ start: badgeStart, end: badgeEnd, style: "chip-error" });
|
|
301
285
|
}
|
|
302
286
|
if (hintStart >= 0)
|
|
303
287
|
spans.push({ start: hintStart, end: text.length, style: "muted" });
|
|
@@ -320,7 +304,7 @@ function createTuiPresentationViewportSources(presentation, turnId, itemId, cont
|
|
|
320
304
|
sources.push({ itemId: sourceId, text, spans: createTuiViewportTextSpans(text, "accent") });
|
|
321
305
|
}
|
|
322
306
|
else if (item.kind === "input_notice") {
|
|
323
|
-
const text =
|
|
307
|
+
const text = `${item.delivery === "steer" ? "[引导] " : item.delivery === "queue" ? "[排队] " : ""}Input ${item.state}`;
|
|
324
308
|
sources.push({ itemId: sourceId, text, spans: createTuiViewportTextSpans(text, "muted") });
|
|
325
309
|
}
|
|
326
310
|
else if (item.kind === "context_notice")
|
|
@@ -332,11 +316,19 @@ function createTuiPresentationViewportSources(presentation, turnId, itemId, cont
|
|
|
332
316
|
}
|
|
333
317
|
return sources;
|
|
334
318
|
}
|
|
319
|
+
/** Todo 行复用既有紧凑/展开数据;历史不输出失效快捷键。 */
|
|
320
|
+
function createTuiTodoSources(item, itemId, contentWidth, expanded, live, rowLimit = 10) {
|
|
321
|
+
const display = getTuiTodoDisplay(item, { expanded, screenReader: false, columns: contentWidth + 1, rowLimit });
|
|
322
|
+
if (!display)
|
|
323
|
+
return [];
|
|
324
|
+
const text = [display.header, ...display.rows.map(function row(row) { return row.hidden ? `+${row.text}` : `[${getTuiTodoStatusLabel(row.status)}] ${row.text}`; }), ...(live ? [`Ctrl+O ${expanded ? "收起" : "展开"}`] : [])].join("\n");
|
|
325
|
+
return [{ itemId, text }];
|
|
326
|
+
}
|
|
335
327
|
/** 将一个历史或 live Turn 的安全事件转换为可缓存的备用屏 source 列表。 */
|
|
336
328
|
function createTuiViewportEventSources(itemId, events, contentWidth, timing, toolGroupsExpanded = false) {
|
|
337
329
|
const sources = [];
|
|
338
330
|
if (timing?.presentation && timing.turnId && timing.presentation.items.some(function belongsToTurn(item) { return item.kind === "capability_notice" || ("turnId" in item && item.turnId === timing.turnId); })) {
|
|
339
|
-
sources.push(...createTuiPresentationViewportSources(timing.presentation, timing.turnId, itemId, contentWidth, toolGroupsExpanded));
|
|
331
|
+
sources.push(...createTuiPresentationViewportSources(timing.presentation, timing.turnId, itemId, contentWidth, toolGroupsExpanded, events, timing.status === "running" || timing.status === "waiting_approval", timing.todoRowLimit));
|
|
340
332
|
const failureReason = getTuiTurnFailureReason(events);
|
|
341
333
|
const terminationSummary = getTuiTerminationSummary(events, timing?.status);
|
|
342
334
|
if (terminationSummary) {
|
|
@@ -361,15 +353,9 @@ function createTuiViewportEventSources(itemId, events, contentWidth, timing, too
|
|
|
361
353
|
function flushAnswer() {
|
|
362
354
|
if (!answer)
|
|
363
355
|
return;
|
|
364
|
-
let thoughtIndex;
|
|
365
|
-
if (answerCount === 0 && timing?.thoughtDurationMs !== undefined) {
|
|
366
|
-
const text = `Thought for ${formatTuiDuration(timing.thoughtDurationMs)}`;
|
|
367
|
-
sources.push({ itemId: `${itemId}:thought`, text, spans: createTuiViewportTextSpans(text, "muted") });
|
|
368
|
-
thoughtIndex = sources.length - 1;
|
|
369
|
-
}
|
|
370
356
|
const answerText = `• ${TUI_AGENT_LABEL}\n${formatTuiViewportMarkdown(answer, contentWidth)}`;
|
|
371
357
|
sources.push({ itemId: `${itemId}:answer:${String(answerCount++)}`, text: answerText, spans: [{ start: 0, end: `• ${TUI_AGENT_LABEL}`.length, style: "accent" }] });
|
|
372
|
-
lastAnswerSource = { answerIndex: sources.length - 1
|
|
358
|
+
lastAnswerSource = { answerIndex: sources.length - 1 };
|
|
373
359
|
answer = "";
|
|
374
360
|
}
|
|
375
361
|
/** 收到 Core reset/discard 后撤销当前采样的暂定回答及其思考计时。 */
|
|
@@ -378,8 +364,6 @@ function createTuiViewportEventSources(itemId, events, contentWidth, timing, too
|
|
|
378
364
|
if (!lastAnswerSource)
|
|
379
365
|
return;
|
|
380
366
|
sources.splice(lastAnswerSource.answerIndex, 1);
|
|
381
|
-
if (lastAnswerSource.thoughtIndex !== undefined)
|
|
382
|
-
sources.splice(lastAnswerSource.thoughtIndex, 1);
|
|
383
367
|
answerCount = Math.max(0, answerCount - 1);
|
|
384
368
|
lastAnswerSource = undefined;
|
|
385
369
|
}
|
|
@@ -405,8 +389,15 @@ function createTuiViewportEventSources(itemId, events, contentWidth, timing, too
|
|
|
405
389
|
continue;
|
|
406
390
|
}
|
|
407
391
|
flushAnswer();
|
|
392
|
+
if (event.type === "tui_input_consumed") {
|
|
393
|
+
sources.push({ itemId: `${itemId}:input:${event.inputId}`, text: event.content, spans: createTuiViewportTextSpans(event.content, "accent") });
|
|
394
|
+
sources.push({ itemId: `${itemId}:input:${event.inputId}:state`, text: event.cancelled ? "[引导] 已取消" : event.consumed === false ? "[引导] 等待当前步骤结束" : formatTuiInputConsumed(event) });
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
if (event.type === "status")
|
|
398
|
+
continue;
|
|
408
399
|
const text = formatTuiViewportEvent(event);
|
|
409
|
-
const style = event.type === "tool_started" || event.type === "reasoning_summary" ? "muted" :
|
|
400
|
+
const style = event.type === "tool_started" || event.type === "reasoning_summary" ? "muted" : undefined;
|
|
410
401
|
if (text) {
|
|
411
402
|
const spans = event.type === "tool_result"
|
|
412
403
|
? createTuiViewportDiffStatsSpans(text, getTuiDiffStats(event.diff ? { text: event.diff } : undefined))
|
|
@@ -422,6 +413,15 @@ function createTuiViewportEventSources(itemId, events, contentWidth, timing, too
|
|
|
422
413
|
}
|
|
423
414
|
}
|
|
424
415
|
flushAnswer();
|
|
416
|
+
const todo = getTuiTurnTodo(events, timing?.turnId ?? events[0]?.turnId ?? "");
|
|
417
|
+
const live = timing?.status === "running" || timing?.status === "waiting_approval";
|
|
418
|
+
if (todo)
|
|
419
|
+
sources.push(...createTuiTodoSources(todo, `${itemId}:todo`, contentWidth, live ? toolGroupsExpanded : true, live, timing?.todoRowLimit));
|
|
420
|
+
const terminationSummary = getTuiTerminationSummary(events, timing?.status);
|
|
421
|
+
if (terminationSummary)
|
|
422
|
+
sources.push({ itemId: `${itemId}:termination`, text: `终态:${terminationSummary}` });
|
|
423
|
+
else if (getTuiTurnFailureReason(events))
|
|
424
|
+
sources.push({ itemId: `${itemId}:failure-reason`, text: `原因:${getTuiTurnFailureReason(events)}` });
|
|
425
425
|
if (timing?.totalDurationMs !== undefined) {
|
|
426
426
|
const text = `* Cogitated for ${formatTuiDuration(timing.totalDurationMs)}`;
|
|
427
427
|
sources.push({ itemId: `${itemId}:total-duration`, text, spans: createTuiViewportTextSpans(text, "muted") });
|
|
@@ -429,7 +429,7 @@ function createTuiViewportEventSources(itemId, events, contentWidth, timing, too
|
|
|
429
429
|
return sources;
|
|
430
430
|
}
|
|
431
431
|
/** 将已完成与当前动态时间线统一变为可裁剪的视觉行来源。 */
|
|
432
|
-
export function createTuiViewportSources(snapshot, statusView, approvalSelectedIndex, contentWidth, toolGroupsExpanded = false, decorativeGrid = false) {
|
|
432
|
+
export function createTuiViewportSources(snapshot, statusView, approvalSelectedIndex, contentWidth, toolGroupsExpanded = false, decorativeGrid = false, todoRowLimit = 10) {
|
|
433
433
|
const sources = [];
|
|
434
434
|
sources.push(createTuiViewportBrandSource(statusView));
|
|
435
435
|
function appendEventGroup(itemId, events, timing, expandGroups = false) {
|
|
@@ -438,7 +438,7 @@ export function createTuiViewportSources(snapshot, statusView, approvalSelectedI
|
|
|
438
438
|
let renderedActivePrompt = false;
|
|
439
439
|
for (const item of snapshot.transcript) {
|
|
440
440
|
if (item.kind === "prompt") {
|
|
441
|
-
sources.push({ itemId: item.key, text: item.content });
|
|
441
|
+
sources.push({ itemId: item.key, text: item.content, spans: createTuiViewportTextSpans(item.content, "accent") });
|
|
442
442
|
if (item.key === snapshot.activePrompt?.key)
|
|
443
443
|
renderedActivePrompt = true;
|
|
444
444
|
}
|
|
@@ -447,17 +447,18 @@ export function createTuiViewportSources(snapshot, statusView, approvalSelectedI
|
|
|
447
447
|
}
|
|
448
448
|
}
|
|
449
449
|
if (snapshot.activePrompt && !renderedActivePrompt)
|
|
450
|
-
sources.push({ itemId: snapshot.activePrompt.key, text: snapshot.activePrompt.content });
|
|
450
|
+
sources.push({ itemId: snapshot.activePrompt.key, text: snapshot.activePrompt.content, spans: createTuiViewportTextSpans(snapshot.activePrompt.content, "accent") });
|
|
451
451
|
const liveCompletedAt = snapshot.liveMetrics?.completedAt;
|
|
452
|
-
appendEventGroup(snapshot.liveTurnId ?? "live", snapshot.liveEvents,
|
|
453
|
-
|
|
454
|
-
|
|
452
|
+
appendEventGroup(snapshot.liveTurnId ?? "live", snapshot.liveEvents, {
|
|
453
|
+
todoRowLimit,
|
|
454
|
+
thoughtDurationMs: snapshot.liveMetrics?.firstAnswerAt === undefined ? undefined : snapshot.liveMetrics?.firstAnswerDurationMs ?? 0,
|
|
455
|
+
totalDurationMs: liveCompletedAt === undefined ? undefined : getCliTuiExecutionMs(snapshot.liveMetrics, liveCompletedAt),
|
|
455
456
|
presentation: snapshot.livePresentation,
|
|
456
457
|
turnId: snapshot.liveTurnId,
|
|
457
458
|
status: snapshot.status,
|
|
458
459
|
}, toolGroupsExpanded);
|
|
459
|
-
for (const item of snapshot.pendingInputs)
|
|
460
|
-
sources.push({ itemId: item.key, text: `${item.delivery === "queue" ? "[
|
|
460
|
+
for (const item of snapshot.pendingInputs.filter(function queue(item) { return item.delivery === "queue"; }))
|
|
461
|
+
sources.push({ itemId: item.key, text: `${item.delivery === "queue" ? item.content + "\n[排队]" : "[引导]"} 等待当前步骤结束` });
|
|
461
462
|
return sources;
|
|
462
463
|
}
|
|
463
464
|
/** 创建备用屏 source 增量缓存;历史 item 不变时只复用其 source,live tail 单独更新。 */
|
|
@@ -489,7 +490,7 @@ export function createTuiViewportSourceCache() {
|
|
|
489
490
|
return previous.sources;
|
|
490
491
|
}
|
|
491
492
|
const sources = item.kind === "prompt"
|
|
492
|
-
? [{ itemId: item.key, text: item.content }]
|
|
493
|
+
? [{ itemId: item.key, text: item.content, spans: createTuiViewportTextSpans(item.content, "accent") }]
|
|
493
494
|
: item.kind === "turn"
|
|
494
495
|
? createTuiViewportEventSources(item.key, item.events, contentWidth, item)
|
|
495
496
|
: [];
|
|
@@ -501,7 +502,7 @@ export function createTuiViewportSourceCache() {
|
|
|
501
502
|
function getActivePromptSource(prompt) {
|
|
502
503
|
if (activePrompt && activePrompt.key === prompt.key && activePrompt.content === prompt.content)
|
|
503
504
|
return activePrompt.sources;
|
|
504
|
-
const sources = [{ itemId: prompt.key, text: prompt.content }];
|
|
505
|
+
const sources = [{ itemId: prompt.key, text: prompt.content, spans: createTuiViewportTextSpans(prompt.content, "accent") }];
|
|
505
506
|
activePrompt = { key: prompt.key, content: prompt.content, sources };
|
|
506
507
|
return sources;
|
|
507
508
|
}
|
|
@@ -512,36 +513,35 @@ export function createTuiViewportSourceCache() {
|
|
|
512
513
|
stats.pendingHits += 1;
|
|
513
514
|
return previous.sources;
|
|
514
515
|
}
|
|
515
|
-
const sources = [{ itemId: item.key, text: `${item.delivery === "queue" ? "[
|
|
516
|
+
const sources = [{ itemId: item.key, text: `${item.delivery === "queue" ? item.content + "\n[排队]" : "[引导]"} 等待当前步骤结束` }];
|
|
516
517
|
pending.set(item.key, { key: item.key, content: item.content, delivery: item.delivery, sources });
|
|
517
518
|
stats.pendingBuilds += 1;
|
|
518
519
|
return sources;
|
|
519
520
|
}
|
|
520
521
|
/** 获取当前 live tail source;历史 transcript 不参与本次重建。 */
|
|
521
|
-
function getLiveSources(snapshot, contentWidth, toolGroupsExpanded) {
|
|
522
|
+
function getLiveSources(snapshot, contentWidth, toolGroupsExpanded, todoRowLimit) {
|
|
522
523
|
const liveTurnId = snapshot.liveTurnId;
|
|
523
524
|
const metrics = snapshot.liveMetrics;
|
|
524
|
-
if (live && live.turnId === liveTurnId && live.events === snapshot.liveEvents && live.presentation === snapshot.livePresentation && live.metrics === metrics && live.width === contentWidth && live.toolGroupsExpanded === toolGroupsExpanded) {
|
|
525
|
+
if (live && live.turnId === liveTurnId && live.events === snapshot.liveEvents && live.presentation === snapshot.livePresentation && live.metrics === metrics && live.width === contentWidth && live.toolGroupsExpanded === toolGroupsExpanded && live.todoRowLimit === todoRowLimit) {
|
|
525
526
|
stats.liveHits += 1;
|
|
526
527
|
return live.sources;
|
|
527
528
|
}
|
|
528
529
|
const liveCompletedAt = metrics?.completedAt;
|
|
529
|
-
const timing =
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
: undefined;
|
|
530
|
+
const timing = {
|
|
531
|
+
todoRowLimit,
|
|
532
|
+
thoughtDurationMs: metrics?.firstAnswerAt === undefined ? undefined : metrics?.firstAnswerDurationMs ?? 0,
|
|
533
|
+
totalDurationMs: liveCompletedAt === undefined ? undefined : getCliTuiExecutionMs(metrics, liveCompletedAt),
|
|
534
|
+
presentation: snapshot.livePresentation,
|
|
535
|
+
turnId: liveTurnId,
|
|
536
|
+
status: snapshot.status,
|
|
537
|
+
};
|
|
538
538
|
const sources = createTuiViewportEventSources(liveTurnId ?? "live", snapshot.liveEvents, contentWidth, timing, toolGroupsExpanded);
|
|
539
|
-
live = { turnId: liveTurnId, events: snapshot.liveEvents, presentation: snapshot.livePresentation, metrics, width: contentWidth, toolGroupsExpanded, sources };
|
|
539
|
+
live = { turnId: liveTurnId, events: snapshot.liveEvents, presentation: snapshot.livePresentation, metrics, width: contentWidth, toolGroupsExpanded, todoRowLimit, sources };
|
|
540
540
|
stats.liveBuilds += 1;
|
|
541
541
|
return sources;
|
|
542
542
|
}
|
|
543
543
|
/** 返回按稳定历史、live tail 和 pending 输入拼接的当前 source 顺序。 */
|
|
544
|
-
function getSources(snapshot, statusView, _approvalSelectedIndex, contentWidth, toolGroupsExpanded = false, decorativeGrid = false) {
|
|
544
|
+
function getSources(snapshot, statusView, _approvalSelectedIndex, contentWidth, toolGroupsExpanded = false, decorativeGrid = false, todoRowLimit = 10) {
|
|
545
545
|
invalidateWidth(contentWidth);
|
|
546
546
|
if (!brand || brand.statusView !== statusView) {
|
|
547
547
|
brand = { statusView, source: createTuiViewportBrandSource(statusView) };
|
|
@@ -561,8 +561,8 @@ export function createTuiViewportSourceCache() {
|
|
|
561
561
|
}
|
|
562
562
|
if (snapshot.activePrompt && !renderedActivePrompt)
|
|
563
563
|
sources.push(...getActivePromptSource(snapshot.activePrompt));
|
|
564
|
-
sources.push(...getLiveSources(snapshot, contentWidth, toolGroupsExpanded));
|
|
565
|
-
for (const item of snapshot.pendingInputs)
|
|
564
|
+
sources.push(...getLiveSources(snapshot, contentWidth, toolGroupsExpanded, todoRowLimit));
|
|
565
|
+
for (const item of snapshot.pendingInputs.filter(function queue(item) { return item.delivery === "queue"; }))
|
|
566
566
|
sources.push(...getPendingSource(item));
|
|
567
567
|
return sources;
|
|
568
568
|
}
|
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
/** 备用屏视口:按应用层视口裁剪时间线并渲染自绘滚动条。 */
|
|
3
3
|
import { memo } from "react";
|
|
4
4
|
import { Box, Text } from "ink";
|
|
5
|
-
import { CLI_TUI_COLORS, TUI_ACCENT_BG_COLOR, TUI_ACCENT_COLOR, TUI_CHIP_TEXT_COLOR, TUI_DIFF_ADDED_COLOR, TUI_DIFF_REMOVED_COLOR, TUI_TOOL_ERROR_COLOR } from "../../design-tokens.js";
|
|
5
|
+
import { CLI_TUI_COLORS, TUI_ACCENT_BG_COLOR, TUI_ACCENT_COLOR, TUI_CHIP_TEXT_COLOR, TUI_DIFF_ADDED_COLOR, TUI_DIFF_REMOVED_COLOR, TUI_TOOL_ERROR_BG_COLOR, TUI_TOOL_ERROR_COLOR, TUI_TOOL_ERROR_TEXT_COLOR } from "../../design-tokens.js";
|
|
6
6
|
import { getTuiVisualLineSelectionRange } from "./selection.js";
|
|
7
7
|
/** 将备用屏时间线的品牌样式映射回 Design.md 规定的 ANSI token。 */
|
|
8
8
|
function getTuiViewportSpanColor(style, useColor) {
|
|
@@ -28,6 +28,8 @@ function getTuiViewportSpanColor(style, useColor) {
|
|
|
28
28
|
return TUI_TOOL_ERROR_COLOR;
|
|
29
29
|
if (style === "chip-active")
|
|
30
30
|
return TUI_CHIP_TEXT_COLOR;
|
|
31
|
+
if (style === "chip-error")
|
|
32
|
+
return TUI_TOOL_ERROR_TEXT_COLOR;
|
|
31
33
|
return undefined;
|
|
32
34
|
}
|
|
33
35
|
/** 取得备用屏 span 的背景与粗体强调;活动工具徽标 chip 使用强调背景 + 深色粗体文字。 */
|
|
@@ -36,6 +38,8 @@ function getTuiViewportSpanEmphasis(style, useColor) {
|
|
|
36
38
|
return {};
|
|
37
39
|
if (style === "chip-active")
|
|
38
40
|
return { backgroundColor: TUI_ACCENT_BG_COLOR, bold: true };
|
|
41
|
+
if (style === "chip-error")
|
|
42
|
+
return { backgroundColor: TUI_TOOL_ERROR_BG_COLOR, bold: true };
|
|
39
43
|
return {};
|
|
40
44
|
}
|
|
41
45
|
/** 在视口的已换行文本中保留来源样式,并与鼠标划选反显组合。 */
|