@autopilot-agent/cli 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -153
- package/dist/activity-animation.d.ts +6 -0
- package/dist/activity-animation.js +15 -18
- package/dist/composition-root.d.ts +31 -1
- package/dist/composition-root.js +124 -3
- package/dist/context-report.d.ts +9 -4
- package/dist/context-report.js +16 -5
- package/dist/controller.d.ts +34 -4
- package/dist/controller.js +494 -90
- package/dist/design-tokens.d.ts +4 -0
- package/dist/design-tokens.js +4 -0
- package/dist/error-diagnostics.d.ts +2 -0
- package/dist/error-diagnostics.js +3 -1
- package/dist/event-projector.d.ts +16 -2
- package/dist/event-projector.js +78 -7
- package/dist/index.d.ts +1 -1
- package/dist/main.js +142 -7
- package/dist/parser.js +511 -4
- package/dist/renderer.js +19 -3
- package/dist/session-summary.d.ts +7 -0
- package/dist/session-summary.js +25 -0
- package/dist/session-title.d.ts +5 -0
- package/dist/session-title.js +10 -0
- package/dist/termination-format.js +1 -0
- package/dist/thread-commands.d.ts +37 -0
- package/dist/thread-commands.js +233 -0
- package/dist/thread-host.d.ts +31 -0
- package/dist/thread-host.js +76 -0
- package/dist/timeline-lines.js +36 -28
- package/dist/tui/app.d.ts +22 -0
- package/dist/tui/app.js +119 -44
- package/dist/tui/approval.d.ts +5 -1
- package/dist/tui/approval.js +20 -7
- package/dist/tui/constants.d.ts +1 -1
- package/dist/tui/constants.js +1 -1
- package/dist/tui/format.d.ts +1 -1
- package/dist/tui/format.js +23 -11
- package/dist/tui/hooks/use-prompt-input.d.ts +52 -0
- package/dist/tui/hooks/use-prompt-input.js +148 -20
- package/dist/tui/hooks/use-status-view.d.ts +2 -2
- package/dist/tui/hooks/use-status-view.js +38 -11
- package/dist/tui/inline-output.d.ts +17 -0
- package/dist/tui/inline-output.js +31 -0
- package/dist/tui/input/clipboard-image.d.ts +17 -0
- package/dist/tui/input/clipboard-image.js +117 -0
- package/dist/tui/input-area.d.ts +8 -0
- package/dist/tui/input-area.js +18 -3
- package/dist/tui/lifecycle.js +2 -5
- package/dist/tui/markdown/diff.d.ts +1 -1
- package/dist/tui/markdown/diff.js +28 -1
- package/dist/tui/performance-diagnostics.js +2 -0
- package/dist/tui/prompt-input.d.ts +1 -0
- package/dist/tui/prompt-input.js +5 -3
- package/dist/tui/render-mode.d.ts +4 -4
- package/dist/tui/render-mode.js +5 -11
- package/dist/tui/run.js +37 -49
- package/dist/tui/session-manager.d.ts +115 -0
- package/dist/tui/session-manager.js +383 -0
- package/dist/tui/session-workspace.d.ts +9 -0
- package/dist/tui/session-workspace.js +383 -0
- package/dist/tui/status-line.d.ts +3 -0
- package/dist/tui/status-line.js +12 -6
- package/dist/tui/store.js +111 -53
- package/dist/tui/timeline/live.js +9 -8
- package/dist/tui/timeline/presentation-timeline.d.ts +2 -1
- package/dist/tui/timeline/presentation-timeline.js +34 -15
- package/dist/tui/timeline/progress.js +3 -2
- package/dist/tui/timeline/static-timeline.js +17 -8
- package/dist/tui/timeline/turn-items.d.ts +12 -0
- package/dist/tui/timeline/turn-items.js +28 -0
- package/dist/tui/timeline/turn.js +8 -7
- package/dist/tui/transcript.d.ts +2 -2
- package/dist/tui/transcript.js +21 -3
- package/dist/tui/trust-dialog.d.ts +3 -0
- package/dist/tui/trust-dialog.js +23 -2
- package/dist/tui/types.d.ts +23 -1
- package/dist/tui/types.js +4 -1
- package/dist/tui/viewport/sources.d.ts +2 -2
- package/dist/tui/viewport/sources.js +75 -75
- package/dist/tui/viewport/viewport.js +5 -1
- package/dist/types.d.ts +165 -2
- package/package.json +4 -4
package/dist/tui/store.js
CHANGED
|
@@ -3,6 +3,8 @@ import { createInitialCliActivityState, reduceCliActivityState, settleCliActivit
|
|
|
3
3
|
import { TUI_EVENT_PUBLISH_INTERVAL_MS } from "./constants.js";
|
|
4
4
|
import { isTerminalStatus } from "./format.js";
|
|
5
5
|
import { recordTuiPerformanceDiagnostic } from "./performance-diagnostics.js";
|
|
6
|
+
import { captureTuiInputPosition } from "./timeline/turn-items.js";
|
|
7
|
+
import { getCliTuiExecutionMs } from "./types.js";
|
|
6
8
|
/** 创建 TUI 初始快照。 */
|
|
7
9
|
function createInitialTuiSnapshot(now = Date.now()) {
|
|
8
10
|
return {
|
|
@@ -25,6 +27,10 @@ export function createCliTuiStore() {
|
|
|
25
27
|
let promptIndex = 0;
|
|
26
28
|
let scheduledNotify;
|
|
27
29
|
const settledInputIds = new Set();
|
|
30
|
+
const consumedPositions = new Map();
|
|
31
|
+
const cancelledTurns = new Set();
|
|
32
|
+
let submissionOrder = 0;
|
|
33
|
+
const submittedInputIds = new Set();
|
|
28
34
|
const submittedApprovalIds = new Set();
|
|
29
35
|
const listeners = new Set();
|
|
30
36
|
const eventsByTurn = new Map();
|
|
@@ -56,18 +62,40 @@ export function createCliTuiStore() {
|
|
|
56
62
|
listener();
|
|
57
63
|
recordTuiPerformanceDiagnostic("tui_store_published", "snapshot", performance.now() - startedAt);
|
|
58
64
|
}
|
|
59
|
-
/**
|
|
60
|
-
function
|
|
61
|
-
const
|
|
62
|
-
if (!
|
|
65
|
+
/** 更新所属轮的宿主输入事实;晚到回调同时刷新历史快照,不挪到当前另一轮。 */
|
|
66
|
+
function putInput(content, input, position, consumed) {
|
|
67
|
+
const turnId = position.turnId;
|
|
68
|
+
if (!turnId)
|
|
63
69
|
return;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
]
|
|
70
|
-
|
|
70
|
+
const events = [...(eventsByTurn.get(turnId) ?? [])];
|
|
71
|
+
const priorIndex = events.findIndex(function same(event) { return event.type === "tui_input_consumed" && event.inputId === input.inputId; });
|
|
72
|
+
const prior = priorIndex >= 0 ? events[priorIndex] : undefined;
|
|
73
|
+
const event = { type: "tui_input_consumed", seq: 0, turnId, ...input, content, consumed, cancelled: !consumed && cancelledTurns.has(turnId), position: prior?.type === "tui_input_consumed" ? prior.position : position };
|
|
74
|
+
if (priorIndex >= 0)
|
|
75
|
+
events[priorIndex] = event;
|
|
76
|
+
else {
|
|
77
|
+
let publicCount = 0;
|
|
78
|
+
let insertAt = events.length;
|
|
79
|
+
for (let index = 0; index < events.length; index += 1) {
|
|
80
|
+
const current = events[index];
|
|
81
|
+
if (current.type === "tui_input_consumed") {
|
|
82
|
+
if (publicCount >= position.eventCount && (current.position?.order ?? 0) > (position.order ?? 0)) {
|
|
83
|
+
insertAt = index;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
if (publicCount >= position.eventCount) {
|
|
89
|
+
insertAt = index;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
publicCount += 1;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
events.splice(insertAt, 0, event);
|
|
96
|
+
}
|
|
97
|
+
eventsByTurn.set(turnId, events);
|
|
98
|
+
snapshot = { ...snapshot, liveEvents: snapshot.liveTurnId === turnId ? events : snapshot.liveEvents, transcript: snapshot.transcript.map(function update(item) { return item.kind === "turn" && item.turnId === turnId ? { ...item, events } : item; }) };
|
|
71
99
|
}
|
|
72
100
|
function finalizeTurn(turnId, status) {
|
|
73
101
|
if (finalizedTurns.has(turnId))
|
|
@@ -79,10 +107,10 @@ export function createCliTuiStore() {
|
|
|
79
107
|
const metrics = metricsByTurn.get(turnId);
|
|
80
108
|
const thoughtDurationMs = metrics?.firstAnswerAt === undefined
|
|
81
109
|
? undefined
|
|
82
|
-
:
|
|
110
|
+
: metrics.firstAnswerDurationMs ?? 0;
|
|
83
111
|
const totalDurationMs = metrics?.completedAt === undefined
|
|
84
112
|
? undefined
|
|
85
|
-
:
|
|
113
|
+
: getCliTuiExecutionMs(metrics, metrics.completedAt);
|
|
86
114
|
// 终态先保留当前 live Turn,让这一帧同时接住最后的 answer/status block;
|
|
87
115
|
// 立即清空会让外层历史区过滤掉同一 Turn,导致最后一段回答不可见。
|
|
88
116
|
snapshot = {
|
|
@@ -116,7 +144,7 @@ export function createCliTuiStore() {
|
|
|
116
144
|
const trimmed = content.trim();
|
|
117
145
|
if (!trimmed)
|
|
118
146
|
return undefined;
|
|
119
|
-
// 运行中的 steer/queue
|
|
147
|
+
// 运行中的 steer/queue 由已确认的 inputId 单独记录,避免发送前伪造成功展示。
|
|
120
148
|
if (!displayAsActive)
|
|
121
149
|
return undefined;
|
|
122
150
|
const key = "prompt:" + String(promptIndex++);
|
|
@@ -131,12 +159,20 @@ export function createCliTuiStore() {
|
|
|
131
159
|
});
|
|
132
160
|
return key;
|
|
133
161
|
},
|
|
134
|
-
/**
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
162
|
+
/** 在异步投递之前捕获真实提交位置。 */
|
|
163
|
+
captureInputPosition() { return { ...captureTuiInputPosition(snapshot.liveTurnId, snapshot.liveEvents, snapshot.livePresentation), order: submissionOrder++ }; },
|
|
164
|
+
/** 成功投递后才外显原文,消费与回调的先后次序不改变所属轮。 */
|
|
165
|
+
addPendingPrompt(content, input, position = captureTuiInputPosition(snapshot.liveTurnId, snapshot.liveEvents, snapshot.livePresentation)) {
|
|
166
|
+
if (!content.trim() || submittedInputIds.has(input.inputId))
|
|
138
167
|
return;
|
|
139
|
-
|
|
168
|
+
submittedInputIds.add(input.inputId);
|
|
169
|
+
const consumed = settledInputIds.has(input.inputId);
|
|
170
|
+
const settledPosition = consumedPositions.get(input.inputId);
|
|
171
|
+
const target = input.delivery === "steer" && position.turnId && (!settledPosition || settledPosition.turnId === position.turnId) ? position : settledPosition;
|
|
172
|
+
if (target)
|
|
173
|
+
putInput(content, input, target, consumed);
|
|
174
|
+
if (consumed || (position.turnId && cancelledTurns.has(position.turnId))) {
|
|
175
|
+
publish(snapshot);
|
|
140
176
|
return;
|
|
141
177
|
}
|
|
142
178
|
publish({
|
|
@@ -145,7 +181,7 @@ export function createCliTuiStore() {
|
|
|
145
181
|
...snapshot.pendingInputs,
|
|
146
182
|
{
|
|
147
183
|
key: "pending:" + String(promptIndex++),
|
|
148
|
-
content
|
|
184
|
+
content,
|
|
149
185
|
inputId: input.inputId,
|
|
150
186
|
delivery: input.delivery,
|
|
151
187
|
},
|
|
@@ -157,28 +193,17 @@ export function createCliTuiStore() {
|
|
|
157
193
|
if (settledInputIds.has(input.inputId))
|
|
158
194
|
return;
|
|
159
195
|
settledInputIds.add(input.inputId);
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
...currentEvents,
|
|
167
|
-
{
|
|
168
|
-
type: "tui_input_consumed",
|
|
169
|
-
seq: 0,
|
|
170
|
-
turnId: input.turnId,
|
|
171
|
-
inputId: input.inputId,
|
|
172
|
-
content: input.content,
|
|
173
|
-
delivery: input.delivery,
|
|
174
|
-
},
|
|
175
|
-
];
|
|
176
|
-
eventsByTurn.set(input.turnId, nextEvents);
|
|
196
|
+
const position = { turnId: input.turnId, eventCount: 0, items: [] };
|
|
197
|
+
consumedPositions.set(input.inputId, position);
|
|
198
|
+
const pending = snapshot.pendingInputs.find(function same(item) { return item.inputId === input.inputId; });
|
|
199
|
+
// 领取回调的 content 可能带附件展开,只在原文已经确认时输出正文。
|
|
200
|
+
if (pending)
|
|
201
|
+
putInput(pending.content, input, position, true);
|
|
177
202
|
publish({
|
|
178
203
|
...snapshot,
|
|
179
204
|
pendingInputs: snapshot.pendingInputs.filter(function keepUnstartedInput(item) { return item.inputId !== input.inputId; }),
|
|
180
205
|
liveTurnId: snapshot.liveTurnId === input.turnId ? input.turnId : snapshot.liveTurnId,
|
|
181
|
-
liveEvents: snapshot.
|
|
206
|
+
liveEvents: snapshot.liveEvents,
|
|
182
207
|
});
|
|
183
208
|
},
|
|
184
209
|
/** 用户选择审批范围后立即将等待卡收束为已提交结果;Runtime 后续事件仍是最终执行依据。 */
|
|
@@ -213,6 +238,10 @@ export function createCliTuiStore() {
|
|
|
213
238
|
});
|
|
214
239
|
},
|
|
215
240
|
acceptEvent(event, projection) {
|
|
241
|
+
if (event.type === "thread_wait") {
|
|
242
|
+
publish({ ...snapshot, threadWait: projection.threadWait });
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
216
245
|
// 用量变化只刷新动态状态栏事实,不进入 transcript 时间线或 scrollback。
|
|
217
246
|
if (event.type === "context_usage") {
|
|
218
247
|
if (snapshot.contextUsage === event.usage)
|
|
@@ -223,6 +252,9 @@ export function createCliTuiStore() {
|
|
|
223
252
|
// Esc 后只等待 Runtime 的终态;取消请求之后已经在途的回答/工具尾部事件不再进入可见时间线。
|
|
224
253
|
if (snapshot.cancellationRequested && !(event.type === "status" && isTerminalStatus(event.status)))
|
|
225
254
|
return;
|
|
255
|
+
if (event.type === "turn_started" && finalizedTurns.delete(event.turnId)) {
|
|
256
|
+
snapshot = { ...snapshot, transcript: snapshot.transcript.filter(function previousSegment(item) { return item.kind !== "turn" || item.turnId !== event.turnId; }) };
|
|
257
|
+
}
|
|
226
258
|
const currentEvents = eventsByTurn.get(event.turnId) ?? [];
|
|
227
259
|
if (currentEvents.some(function hasSequence(item) { return item.type === event.type && item.seq === event.seq; }))
|
|
228
260
|
return;
|
|
@@ -236,12 +268,17 @@ export function createCliTuiStore() {
|
|
|
236
268
|
const eventTime = Date.now();
|
|
237
269
|
const previousMetrics = metricsByTurn.get(event.turnId);
|
|
238
270
|
const nextMetrics = {
|
|
239
|
-
startedAt:
|
|
271
|
+
startedAt: previousMetrics?.startedAt ?? eventTime,
|
|
272
|
+
elapsedMs: projection.presentation?.executionByTurn?.[event.turnId]?.elapsedMs ?? previousMetrics?.elapsedMs,
|
|
273
|
+
runningSince: projection.presentation?.executionByTurn?.[event.turnId]?.runningSince,
|
|
274
|
+
firstAnswerDurationMs: previousMetrics?.firstAnswerDurationMs,
|
|
240
275
|
firstAnswerAt: previousMetrics?.firstAnswerAt,
|
|
241
|
-
completedAt: previousMetrics?.completedAt,
|
|
276
|
+
completedAt: event.type === "turn_started" ? undefined : previousMetrics?.completedAt,
|
|
242
277
|
};
|
|
243
|
-
if (event.type === "answer_delta" && nextMetrics.firstAnswerAt === undefined)
|
|
278
|
+
if (event.type === "answer_delta" && nextMetrics.firstAnswerAt === undefined) {
|
|
244
279
|
nextMetrics.firstAnswerAt = eventTime;
|
|
280
|
+
nextMetrics.firstAnswerDurationMs = getCliTuiExecutionMs(nextMetrics, eventTime);
|
|
281
|
+
}
|
|
245
282
|
// Core 的 reset/discard 表示当前采样的暂定文字不能展示;下一次真正回答重新计时。
|
|
246
283
|
if (event.type === "answer_reset")
|
|
247
284
|
nextMetrics.firstAnswerAt = undefined;
|
|
@@ -259,6 +296,7 @@ export function createCliTuiStore() {
|
|
|
259
296
|
hasLiveApprovalEvent: isNewTurn ? event.type === "approval_required" : snapshot.hasLiveApprovalEvent || event.type === "approval_required",
|
|
260
297
|
activity: nextActivity,
|
|
261
298
|
status: projection.status,
|
|
299
|
+
threadWait: projection.threadWait,
|
|
262
300
|
recoverable: projection.recoverable,
|
|
263
301
|
pendingApproval: projection.pendingApproval && !submittedApprovalIds.has(projection.pendingApproval.approvalId)
|
|
264
302
|
? { ...projection.pendingApproval }
|
|
@@ -268,18 +306,21 @@ export function createCliTuiStore() {
|
|
|
268
306
|
};
|
|
269
307
|
if (event.type === "input_consumed") {
|
|
270
308
|
settledInputIds.add(event.inputId);
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
});
|
|
282
|
-
|
|
309
|
+
if (!consumedPositions.has(event.inputId))
|
|
310
|
+
consumedPositions.set(event.inputId, captureTuiInputPosition(event.turnId, currentEvents, snapshot.livePresentation));
|
|
311
|
+
const pending = nextSnapshot.pendingInputs.find(function same(item) { return item.inputId === event.inputId; });
|
|
312
|
+
nextSnapshot.pendingInputs = nextSnapshot.pendingInputs.filter(function keepPendingInput(item) { return item.inputId !== event.inputId; });
|
|
313
|
+
const host = nextEvents.find(function same(item) { return item.type === "tui_input_consumed" && item.inputId === event.inputId; });
|
|
314
|
+
if (host?.type === "tui_input_consumed")
|
|
315
|
+
nextSnapshot.liveEvents = nextEvents.map(function consume(item) { return item === host ? { ...host, consumed: true } : item; });
|
|
316
|
+
eventsByTurn.set(event.turnId, nextSnapshot.liveEvents);
|
|
317
|
+
if (!host && pending) {
|
|
318
|
+
snapshot = nextSnapshot;
|
|
319
|
+
const position = pending.delivery === "queue" ? { turnId: event.turnId, eventCount: 0, items: [] } : consumedPositions.get(event.inputId);
|
|
320
|
+
consumedPositions.set(event.inputId, position);
|
|
321
|
+
putInput(pending.content, pending, position, true);
|
|
322
|
+
nextSnapshot.liveEvents = snapshot.liveEvents;
|
|
323
|
+
nextSnapshot.transcript = snapshot.transcript;
|
|
283
324
|
}
|
|
284
325
|
}
|
|
285
326
|
snapshot = nextSnapshot;
|
|
@@ -295,6 +336,15 @@ export function createCliTuiStore() {
|
|
|
295
336
|
}
|
|
296
337
|
},
|
|
297
338
|
syncProjection(projection) {
|
|
339
|
+
// Controller已过滤正在提交或已保存的请求,权威pending重现表示保存失败,可重试原请求。
|
|
340
|
+
if (projection.pendingApproval)
|
|
341
|
+
submittedApprovalIds.delete(projection.pendingApproval.approvalId);
|
|
342
|
+
// 身份失效只关闭交互;已打开的旧正文保留为最后观察到的历史,不伪造终态。
|
|
343
|
+
if (snapshot.liveTurnId && projection.turnId !== snapshot.liveTurnId && snapshot.liveEvents.length && !snapshot.transcript.some(function existing(item) { return item.kind === "turn" && item.turnId === snapshot.liveTurnId; })) {
|
|
344
|
+
snapshot = { ...snapshot, transcript: [...snapshot.transcript, { kind: "turn", key: "observed:" + snapshot.liveTurnId, turnId: snapshot.liveTurnId, events: snapshot.liveEvents, presentation: snapshot.livePresentation, status: snapshot.status }] };
|
|
345
|
+
}
|
|
346
|
+
if (projection.turnId && !eventsByTurn.has(projection.turnId) && projection.events.length > 0)
|
|
347
|
+
eventsByTurn.set(projection.turnId, projection.events.filter(function belongs(event) { return event.turnId === projection.turnId; }));
|
|
298
348
|
const turnIsFinalized = projection.turnId ? finalizedTurns.has(projection.turnId) : false;
|
|
299
349
|
const isNewTurn = projection.turnId !== undefined && projection.turnId !== snapshot.liveTurnId;
|
|
300
350
|
const activePrompt = snapshot.activePrompt && snapshot.activePrompt.turnId === undefined && projection.turnId
|
|
@@ -317,9 +367,11 @@ export function createCliTuiStore() {
|
|
|
317
367
|
liveTurnId: keepLiveTurn ? projection.turnId : undefined,
|
|
318
368
|
liveEvents: keepLiveTurn ? [...(eventsByTurn.get(projection.turnId) ?? [])] : [],
|
|
319
369
|
livePresentation: keepLiveTurn ? projection.presentation : undefined,
|
|
370
|
+
liveMetrics: keepLiveTurn && projection.turnId ? metricsByTurn.get(projection.turnId) : undefined,
|
|
320
371
|
hasLiveApprovalEvent: Boolean(keepLiveTurn && !isNewTurn && snapshot.hasLiveApprovalEvent),
|
|
321
372
|
activity,
|
|
322
373
|
status: projection.status,
|
|
374
|
+
threadWait: projection.threadWait,
|
|
323
375
|
recoverable: projection.recoverable,
|
|
324
376
|
pendingApproval: projection.pendingApproval && !submittedApprovalIds.has(projection.pendingApproval.approvalId)
|
|
325
377
|
? { ...projection.pendingApproval }
|
|
@@ -335,6 +387,12 @@ export function createCliTuiStore() {
|
|
|
335
387
|
setCancellationRequested(requested) {
|
|
336
388
|
if (snapshot.cancellationRequested === requested)
|
|
337
389
|
return;
|
|
390
|
+
if (requested && snapshot.liveTurnId) {
|
|
391
|
+
cancelledTurns.add(snapshot.liveTurnId);
|
|
392
|
+
const events = snapshot.liveEvents.map(function cancel(event) { return event.type === "tui_input_consumed" && event.consumed === false ? { ...event, cancelled: true } : event; });
|
|
393
|
+
eventsByTurn.set(snapshot.liveTurnId, events);
|
|
394
|
+
snapshot = { ...snapshot, liveEvents: events, pendingInputs: [] };
|
|
395
|
+
}
|
|
338
396
|
publish({ ...snapshot, cancellationRequested: requested });
|
|
339
397
|
},
|
|
340
398
|
requestExit(code) {
|
|
@@ -4,8 +4,9 @@ import { memo, useRef } from "react";
|
|
|
4
4
|
import { Box, Text } from "ink";
|
|
5
5
|
import { TUI_ACCENT_COLOR } from "../../design-tokens.js";
|
|
6
6
|
import { TUI_AGENT_LABEL } from "../constants.js";
|
|
7
|
-
import {
|
|
7
|
+
import { formatTuiInputConsumed, getTuiApprovalDecisionLabel, isTerminalStatus } from "../format.js";
|
|
8
8
|
import { TuiMarkdown } from "../markdown/markdown.js";
|
|
9
|
+
import { TuiPromptLine } from "../transcript.js";
|
|
9
10
|
import { renderTuiToolTreeEvent } from "./tool-tree.js";
|
|
10
11
|
/** 为增量时间线生成稳定键,避免 answer delta 到达时重建历史节点。 */
|
|
11
12
|
function getCliTuiTimelineEventKey(event) {
|
|
@@ -17,6 +18,9 @@ function getCliTuiTimelineEventKey(event) {
|
|
|
17
18
|
function isCliTuiTimelineAppendOnly(cache, events) {
|
|
18
19
|
if (cache.eventCount === 0)
|
|
19
20
|
return true;
|
|
21
|
+
const hostInputs = events.filter(function host(event) { return event.type === "tui_input_consumed"; });
|
|
22
|
+
if (hostInputs.length !== cache.hostInputs.length || hostInputs.some(function changed(event, index) { return event !== cache.hostInputs[index]; }))
|
|
23
|
+
return false;
|
|
20
24
|
return events.length >= cache.eventCount && events[cache.eventCount - 1] === cache.lastEvent;
|
|
21
25
|
}
|
|
22
26
|
/** 应用一条时间线事件,只修改新增尾部或当前回答块。 */
|
|
@@ -50,7 +54,7 @@ function appendCliTuiTimelineEvent(cache, event) {
|
|
|
50
54
|
}
|
|
51
55
|
/** 首次或 Turn 切换时完整归约时间线;后续更新走尾部增量路径。 */
|
|
52
56
|
function createCliTuiTimelineCache(events) {
|
|
53
|
-
const cache = { eventCount: 0, blocks: [] };
|
|
57
|
+
const cache = { eventCount: 0, blocks: [], hostInputs: events.filter(function host(event) { return event.type === "tui_input_consumed"; }) };
|
|
54
58
|
for (const event of events)
|
|
55
59
|
appendCliTuiTimelineEvent(cache, event);
|
|
56
60
|
cache.eventCount = events.length;
|
|
@@ -80,7 +84,7 @@ function useCliTuiTimelineBlocks(events) {
|
|
|
80
84
|
function TuiLiveEventBlock(props) {
|
|
81
85
|
const event = props.event;
|
|
82
86
|
if (event.type === "tui_input_consumed") {
|
|
83
|
-
return _jsx(Text, { dimColor: props.useColor, children: formatTuiInputConsumed(event) });
|
|
87
|
+
return _jsxs(Box, { flexDirection: "column", children: [_jsx(TuiPromptLine, { content: event.content, useColor: props.useColor, columns: props.maximumWidth + 2 }), _jsx(Text, { dimColor: props.useColor, children: event.cancelled ? "[引导] 已取消" : event.consumed === false ? "[引导] 等待当前步骤结束" : formatTuiInputConsumed(event) })] });
|
|
84
88
|
}
|
|
85
89
|
if (event.type === "tui_approval_submitted") {
|
|
86
90
|
return _jsxs(Text, { dimColor: props.useColor, children: ["Approval submitted \u00B7 ", getTuiApprovalDecisionLabel(event.decision)] });
|
|
@@ -107,8 +111,6 @@ function TuiLiveEventBlock(props) {
|
|
|
107
111
|
return _jsx(Text, { children: "Context organization failed" });
|
|
108
112
|
if (event.type === "context_compact_circuit_open")
|
|
109
113
|
return _jsx(Text, { children: "Context organization temporarily unavailable" });
|
|
110
|
-
if (event.type === "status" && event.status === "failed" && event.reason)
|
|
111
|
-
return _jsxs(Text, { children: ["\u539F\u56E0\uFF1A", event.reason] });
|
|
112
114
|
if (event.type === "status")
|
|
113
115
|
return null;
|
|
114
116
|
return null;
|
|
@@ -132,7 +134,7 @@ function renderTuiLiveTimelineBlock(block, useColor, renderMarkdown, maximumWidt
|
|
|
132
134
|
return null;
|
|
133
135
|
if (block.event.type === "answer_delta")
|
|
134
136
|
return null;
|
|
135
|
-
return _jsx(MemoizedTuiLiveEventBlock, { event: block.event, useColor: useColor });
|
|
137
|
+
return _jsx(MemoizedTuiLiveEventBlock, { event: block.event, useColor: useColor, maximumWidth: maximumWidth });
|
|
136
138
|
}
|
|
137
139
|
/**
|
|
138
140
|
* Ink 在动态区超过一屏后会清空终端并从顶部重绘;把已经确定的块交给
|
|
@@ -141,9 +143,8 @@ function renderTuiLiveTimelineBlock(block, useColor, renderMarkdown, maximumWidt
|
|
|
141
143
|
*/
|
|
142
144
|
export const TuiLiveTimeline = memo(function TuiLiveTimeline(props) {
|
|
143
145
|
const blocks = useCliTuiTimelineBlocks(props.events);
|
|
144
|
-
const firstAnswerKey = blocks.find(function findFirstAnswer(block) { return block.kind === "answer"; })?.key;
|
|
145
146
|
function renderBlock(block) {
|
|
146
|
-
return (
|
|
147
|
+
return (_jsx(Box, { flexDirection: "column", children: renderTuiLiveTimelineBlock(block, props.useColor, isTerminalStatus(props.status), props.maximumWidth) }, block.key));
|
|
147
148
|
}
|
|
148
149
|
return (_jsx(_Fragment, { children: blocks.map(function renderDynamicTimelineBlock(block) {
|
|
149
150
|
return renderBlock(block);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** 基于共享 Presentation selector 的 CLI 时间线;不读取旧工具 summary、detail 或审批 preview。 */
|
|
2
2
|
import { type AgentPresentationState } from "@autopilot-agent/presentation";
|
|
3
3
|
import { type ReactNode } from "react";
|
|
4
|
+
import type { CliTuiTimelineEvent } from "../types.js";
|
|
4
5
|
/** 详情视图参数:expanded 驱动 Todo 卡展开,toolGroupsExpanded 驱动工具分组展开;screen reader 恒展开全部明细。 */
|
|
5
6
|
type TuiDetailView = {
|
|
6
7
|
expanded: boolean;
|
|
@@ -10,5 +11,5 @@ type TuiDetailView = {
|
|
|
10
11
|
toolGroupsExpanded?: boolean;
|
|
11
12
|
};
|
|
12
13
|
/** 渲染指定 Turn 的共享 Presentation 时间线;无匹配节点时由调用方回退兼容旧事件。 */
|
|
13
|
-
export declare function renderTuiPresentationTimeline(presentation: AgentPresentationState, turnId: string, useColor: boolean, maximumWidth: number, detailView: TuiDetailView): ReactNode[];
|
|
14
|
+
export declare function renderTuiPresentationTimeline(presentation: AgentPresentationState, turnId: string, useColor: boolean, maximumWidth: number, detailView: TuiDetailView, events?: CliTuiTimelineEvent[]): ReactNode[];
|
|
14
15
|
export {};
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
/** 基于共享 Presentation selector 的 CLI 时间线;不读取旧工具 summary、detail 或审批 preview。 */
|
|
3
|
-
import { getPresentationCopy,
|
|
3
|
+
import { getPresentationCopy, getToolPresentationProfile, isSandboxUnavailableErrorCode, selectToolCalls } from "@autopilot-agent/presentation";
|
|
4
4
|
import { Box, Text } from "ink";
|
|
5
|
-
import { TUI_ACCENT_BG_COLOR, TUI_ACCENT_COLOR, TUI_CHIP_TEXT_COLOR,
|
|
5
|
+
import { TUI_ACCENT_BG_COLOR, TUI_ACCENT_COLOR, TUI_CHIP_TEXT_COLOR, TUI_TOOL_ERROR_BG_COLOR, TUI_TOOL_ERROR_TEXT_COLOR } from "../../design-tokens.js";
|
|
6
6
|
import { TUI_AGENT_LABEL } from "../constants.js";
|
|
7
7
|
import { TuiDiffStats } from "../diff-stats.js";
|
|
8
8
|
import { getTuiDiffStats } from "../format.js";
|
|
9
9
|
import { TuiDiffBlock } from "../markdown/diff.js";
|
|
10
10
|
import { TuiMarkdown } from "../markdown/markdown.js";
|
|
11
|
+
import { TuiPromptLine } from "../transcript.js";
|
|
11
12
|
import { TuiTodoList } from "../todo-list.js";
|
|
13
|
+
import { getTuiTurnItems } from "./turn-items.js";
|
|
12
14
|
/** 取得 ToolCall 的纯文本状态标志,不依赖颜色表达执行结果。 */
|
|
13
15
|
function getToolStateGlyph(state) {
|
|
14
16
|
if (state === "completed")
|
|
@@ -21,6 +23,16 @@ function getToolStateGlyph(state) {
|
|
|
21
23
|
return "×";
|
|
22
24
|
return "✢";
|
|
23
25
|
}
|
|
26
|
+
/** 取得拒绝、取消与超时文字;执行失败由叉号和错误详情表达。沙箱不可用类拒绝是环境阻塞而非用户拒绝,文案必须区分。 */
|
|
27
|
+
function getToolStateText(state, errorCode) {
|
|
28
|
+
if (state === "denied")
|
|
29
|
+
return isSandboxUnavailableErrorCode(errorCode) ? "沙箱不可用,命令未启动" : "已拒绝";
|
|
30
|
+
if (state === "cancelled")
|
|
31
|
+
return "已取消";
|
|
32
|
+
if (state === "timeout")
|
|
33
|
+
return "已超时";
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
24
36
|
/** 判断工具是否处于失败类终态;失败步骤文字使用错误红并保留文字标签。 */
|
|
25
37
|
function isFailedToolState(state) {
|
|
26
38
|
return state === "failed" || state === "denied" || state === "cancelled" || state === "timeout";
|
|
@@ -42,6 +54,8 @@ function getWebToolDetailText(item) {
|
|
|
42
54
|
}
|
|
43
55
|
/** 将一个共享 selector 节点渲染为 Ink 视图,Tool 节点的 React key 始终绑定 callId。 */
|
|
44
56
|
function renderPresentationItem(item, useColor, maximumWidth, detailView, toolCallIndex) {
|
|
57
|
+
if (item.kind === "todo")
|
|
58
|
+
return _jsx(Box, { flexDirection: "column", children: _jsx(TuiTodoList, { item: item, expanded: detailView.expanded || detailView.screenReader, useColor: useColor, screenReader: detailView.screenReader, columns: maximumWidth + 2, rowLimit: detailView.rowLimit, showToggleHint: detailView.showToggleHint }) }, item.id);
|
|
45
59
|
if (item.kind === "thinking")
|
|
46
60
|
return _jsxs(Text, { dimColor: useColor, children: ["\u2722 ", item.summary] }, item.id);
|
|
47
61
|
if (item.kind === "tool_group") {
|
|
@@ -55,25 +69,28 @@ function renderPresentationItem(item, useColor, maximumWidth, detailView, toolCa
|
|
|
55
69
|
return (_jsxs(Box, { flexDirection: "column", children: [summary, children.map(function renderGroupChild(child) { return _jsx(Box, { paddingLeft: 2, children: renderPresentationItem(child, useColor, maximumWidth, detailView, toolCallIndex) }, child.callId); })] }, item.id));
|
|
56
70
|
}
|
|
57
71
|
if (item.kind === "tool_call") {
|
|
58
|
-
const title = getPresentationCopy(item.titleKey);
|
|
72
|
+
const title = getPresentationCopy(item.state === "failed" ? getToolPresentationProfile(item.toolName).completedTitleKey : item.titleKey);
|
|
59
73
|
const jobProgramLabel = item.job?.action === "start" ? item.job.programLabel?.toUpperCase() : undefined;
|
|
60
74
|
const diffStats = getTuiDiffStats(item.diff);
|
|
61
75
|
const detail = getWebToolDetailText(item) ?? [jobProgramLabel ? undefined : item.target, item.resultSummary].filter(Boolean).join(" · ");
|
|
62
76
|
const glyph = getToolStateGlyph(item.state);
|
|
63
|
-
//
|
|
77
|
+
// 失败沿用完成态工具名称,仅徽标使用错误红;前缀符号独立显示。
|
|
78
|
+
const stateText = getToolStateText(item.state, item.errorCode);
|
|
64
79
|
const head = isFailedToolState(item.state)
|
|
65
|
-
? _jsxs(Text, { color: useColor ?
|
|
80
|
+
? _jsxs(Text, { children: [_jsxs(Text, { color: useColor ? TUI_TOOL_ERROR_BG_COLOR : undefined, children: [glyph, " "] }), _jsxs(Text, { backgroundColor: useColor ? TUI_TOOL_ERROR_BG_COLOR : undefined, color: useColor ? TUI_TOOL_ERROR_TEXT_COLOR : undefined, bold: useColor || undefined, children: ["[", title, "]", stateText ? ` · ${stateText}` : ""] })] })
|
|
66
81
|
: _jsxs(Text, { children: [_jsxs(Text, { dimColor: useColor, children: [glyph, " "] }), _jsxs(Text, { backgroundColor: useColor ? TUI_ACCENT_BG_COLOR : undefined, color: useColor ? TUI_CHIP_TEXT_COLOR : undefined, bold: useColor || undefined, children: ["[", title, "]"] })] });
|
|
67
|
-
return _jsxs(Box, { flexDirection: "column", children: [head, jobProgramLabel ? _jsxs(Text, { children: [" \u2514\u2500 ", _jsx(Text, { bold: true, color: useColor ? TUI_ACCENT_COLOR : undefined, children: jobProgramLabel }), detail ? _jsxs(Text, { dimColor: useColor, children: [" \u00B7 ", detail] }) : null] }) : detail || diffStats ? _jsxs(Text, { children: [" \u2514\u2500 ", detail ? _jsxs(Text, { dimColor: useColor, children: [detail, " "] }) : null, diffStats ? _jsx(TuiDiffStats, { ...diffStats, useColor: useColor }) : null] }) : null, item.errorCode ? _jsxs(Text, { dimColor: useColor, children: [" \u2514\u2500 ", item.errorCode] }) : null, item.job?.action === "start" && (item.job.observedStatus === "starting" || item.job.observedStatus === "running") ? _jsx(Text, { dimColor: useColor, children: " /jobs \u67E5\u770B\u540E\u53F0\u4EFB\u52A1" }) : null, item.diff?.text ? _jsx(TuiDiffBlock, { diff: item.diff.text, keyPrefix: item.callId, useColor: useColor }) : null] }, item.callId);
|
|
82
|
+
return _jsxs(Box, { flexDirection: "column", children: [head, jobProgramLabel ? _jsxs(Text, { children: [" \u2514\u2500 ", _jsx(Text, { bold: true, color: useColor ? TUI_ACCENT_COLOR : undefined, children: jobProgramLabel }), detail ? _jsxs(Text, { dimColor: useColor, children: [" \u00B7 ", detail] }) : null] }) : detail || diffStats ? _jsxs(Text, { children: [" \u2514\u2500 ", detail ? _jsxs(Text, { dimColor: useColor, children: [detail, " "] }) : null, diffStats ? _jsx(TuiDiffStats, { ...diffStats, useColor: useColor }) : null] }) : null, item.errorCode ? _jsxs(Text, { dimColor: useColor, children: [" \u2514\u2500 ", item.errorCode] }) : null, item.executionMode === "unisolated" ? _jsx(Text, { color: useColor ? TUI_TOOL_ERROR_TEXT_COLOR : undefined, children: " \u2514\u2500 \u672A\u9694\u79BB\uFF1A\u5BBF\u4E3B\u76F4\u63A5\u6267\u884C" }) : null, item.diagnostics?.length ? _jsxs(Text, { dimColor: useColor, children: [" \u2514\u2500 \u8BCA\u65AD\uFF1A", item.diagnostics.join(";")] }) : null, item.job?.action === "start" && (item.job.observedStatus === "starting" || item.job.observedStatus === "running") ? _jsx(Text, { dimColor: useColor, children: " /jobs \u67E5\u770B\u540E\u53F0\u4EFB\u52A1" }) : null, item.diff?.text ? _jsx(TuiDiffBlock, { diff: item.diff.text, keyPrefix: item.callId, useColor: useColor }) : null] }, item.callId);
|
|
68
83
|
}
|
|
69
84
|
if (item.kind === "approval") {
|
|
70
85
|
const detail = item.display?.actionPreview ?? item.display?.operation ?? "需要确认";
|
|
71
|
-
|
|
86
|
+
// 历史行与待审卡共用 constraint 判定,普通批准与无沙箱批准不得混淆。
|
|
87
|
+
const noSandbox = item.constraint === "no-sandbox-exec:v1" ? " · 无沙箱直接执行" : "";
|
|
88
|
+
// Talk-Plan1022 S3:宿主执行审批事实与 no-sandbox 降级卡分开呈现,措辞不宣称已执行。
|
|
89
|
+
const hostExecution = item.display?.executionMode === "unisolated" ? " · 将在当前用户权限下运行(未启用沙箱隔离)" : "";
|
|
90
|
+
return _jsxs(Text, { dimColor: useColor, children: ["\u26A0 ", detail, noSandbox, hostExecution, item.state === "resolved" ? " · 已处理" : ""] }, item.id);
|
|
72
91
|
}
|
|
73
92
|
if (item.kind === "user_question")
|
|
74
93
|
return _jsx(Text, { dimColor: useColor, children: "\u8BF7\u5728\u652F\u6301\u7ED3\u6784\u5316\u56DE\u7B54\u7684 Web \u4E2D\u5904\u7406" }, item.id);
|
|
75
|
-
if (item.kind === "todo")
|
|
76
|
-
return _jsx(TuiTodoList, { item: item, expanded: detailView.expanded, useColor: useColor, screenReader: detailView.screenReader, columns: maximumWidth, rowLimit: detailView.rowLimit, showToggleHint: detailView.showToggleHint }, item.id);
|
|
77
94
|
if (item.kind === "assistant_answer") {
|
|
78
95
|
if (item.channel === "process")
|
|
79
96
|
return _jsx(TuiMarkdown, { content: item.content, keyPrefix: item.id, useColor: useColor, maximumWidth: maximumWidth }, item.id);
|
|
@@ -87,7 +104,7 @@ function renderPresentationItem(item, useColor, maximumWidth, detailView, toolCa
|
|
|
87
104
|
return _jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { dimColor: useColor, children: [item.state === "completed" ? "✓" : "⚠", " ", title] }), item.restoredPaths.length > 0 ? _jsxs(Text, { dimColor: useColor, children: [" restored: ", item.restoredPaths.join(", ")] }) : null, item.compensatedPaths.length > 0 ? _jsxs(Text, { dimColor: useColor, children: [" compensated: ", item.compensatedPaths.join(", ")] }) : null, item.conflicts.length > 0 ? _jsxs(Text, { dimColor: useColor, children: [" conflicts (not overwritten): ", item.conflicts.join(", ")] }) : null] }, item.id);
|
|
88
105
|
}
|
|
89
106
|
if (item.kind === "input_notice")
|
|
90
|
-
return _jsxs(Text, { dimColor: useColor, children: ["
|
|
107
|
+
return _jsxs(Text, { dimColor: useColor, children: [item.delivery === "steer" ? "[引导] " : item.delivery === "queue" ? "[排队] " : "", "Input ", item.state] }, item.id);
|
|
91
108
|
if (item.kind === "turn_summary")
|
|
92
109
|
return _jsxs(Text, { dimColor: useColor, children: [getTurnStateGlyph(item.state), " ", getPresentationCopy(`turn.${item.state}`), " \u00B7 ", item.toolCount, " tools"] }, item.id);
|
|
93
110
|
if (item.kind === "job") {
|
|
@@ -100,10 +117,12 @@ function renderPresentationItem(item, useColor, maximumWidth, detailView, toolCa
|
|
|
100
117
|
return null;
|
|
101
118
|
}
|
|
102
119
|
/** 渲染指定 Turn 的共享 Presentation 时间线;无匹配节点时由调用方回退兼容旧事件。 */
|
|
103
|
-
export function renderTuiPresentationTimeline(presentation, turnId, useColor, maximumWidth, detailView) {
|
|
120
|
+
export function renderTuiPresentationTimeline(presentation, turnId, useColor, maximumWidth, detailView, events = []) {
|
|
104
121
|
// 构建 callId 索引供展开分组取回组内调用;分组只按 callId 引用,不携带子节点事实。
|
|
105
122
|
const toolCallIndex = new Map(selectToolCalls(presentation, turnId).map(function indexToolCall(call) { return [call.callId, call]; }));
|
|
106
|
-
return
|
|
107
|
-
|
|
108
|
-
|
|
123
|
+
return getTuiTurnItems(presentation, turnId, events).map(function renderSharedTimelineItem(item) {
|
|
124
|
+
if ("type" in item)
|
|
125
|
+
return _jsxs(Box, { flexDirection: "column", children: [_jsx(TuiPromptLine, { content: item.content, useColor: useColor, columns: maximumWidth + 2 }), _jsxs(Text, { dimColor: useColor, children: [item.delivery === "queue" ? "[排队]" : "[引导]", " ", item.cancelled ? "已取消" : item.consumed === false ? "等待当前步骤结束" : "已插入当前 turn"] })] }, `input:${item.inputId}`);
|
|
126
|
+
return renderPresentationItem(item, useColor, maximumWidth, detailView, toolCallIndex);
|
|
127
|
+
});
|
|
109
128
|
}
|
|
@@ -2,6 +2,7 @@ import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
/** 当前思考进度汇总;只统计已发出的 tool_started,避免结果重复计数。 */
|
|
3
3
|
import { useEffect, useState } from "react";
|
|
4
4
|
import { Text } from "ink";
|
|
5
|
+
import { getCliTuiExecutionMs } from "../types.js";
|
|
5
6
|
import { formatTuiDuration } from "../format.js";
|
|
6
7
|
/** 汇总 Claude Code 风格的当前思考进度;只统计已发出的 tool_started,避免结果重复计数。 */
|
|
7
8
|
export function TuiLiveProgressSummary(props) {
|
|
@@ -17,7 +18,7 @@ export function TuiLiveProgressSummary(props) {
|
|
|
17
18
|
return null;
|
|
18
19
|
// Todo 的 activeForm 是模型声明的稳定活动文案,优先于宿主猜测的工具动词短语。
|
|
19
20
|
if (props.activeTodoForm) {
|
|
20
|
-
return _jsxs(Text, { dimColor: props.useColor, children: [props.activeTodoForm, " \u00B7 ", formatTuiDuration(
|
|
21
|
+
return _jsxs(Text, { dimColor: props.useColor, children: [props.activeTodoForm, " \u00B7 ", formatTuiDuration(getCliTuiExecutionMs(props.metrics, now)), "\u2026"] });
|
|
21
22
|
}
|
|
22
23
|
const counts = new Map();
|
|
23
24
|
for (const event of props.events) {
|
|
@@ -38,6 +39,6 @@ export function TuiLiveProgressSummary(props) {
|
|
|
38
39
|
phrase("run_command", "running", "shell command");
|
|
39
40
|
phrase("write_file", "writing", "file");
|
|
40
41
|
phrase("edit_file", "editing", "file");
|
|
41
|
-
const thinking = `Thinking for ${formatTuiDuration(
|
|
42
|
+
const thinking = `Thinking for ${formatTuiDuration(getCliTuiExecutionMs(props.metrics, now))}`;
|
|
42
43
|
return _jsxs(Text, { dimColor: props.useColor, children: [thinking, phrases.length > 0 ? `, ${phrases.join(", ")}` : "", "\u2026"] });
|
|
43
44
|
}
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Box, Text } from "ink";
|
|
3
|
-
import { TUI_ACCENT_COLOR } from "../../design-tokens.js";
|
|
3
|
+
import { TUI_ACCENT_COLOR, TUI_TOOL_ERROR_TEXT_COLOR } from "../../design-tokens.js";
|
|
4
4
|
import { TUI_AGENT_LABEL } from "../constants.js";
|
|
5
5
|
import { formatTuiDuration, formatTuiInputConsumed, getTuiApprovalDecisionLabel, getTuiToolLabel, getTuiTerminationSummary, getTuiTurnFailureReason } from "../format.js";
|
|
6
6
|
import { TuiMarkdown } from "../markdown/markdown.js";
|
|
7
7
|
import { renderTuiToolTreeEvent } from "./tool-tree.js";
|
|
8
8
|
import { renderTuiPresentationTimeline } from "./presentation-timeline.js";
|
|
9
|
+
import { TuiPromptLine } from "../transcript.js";
|
|
10
|
+
import { TuiTodoList } from "../todo-list.js";
|
|
11
|
+
import { getTuiTurnTodo } from "./turn-items.js";
|
|
9
12
|
/** 将安全事件聚合为可读的时间线行,连续 answer_delta 只显示为一个回答块。 */
|
|
10
13
|
export function renderTimeline(events, useColor, timing, maximumWidth = 80, screenReader = false) {
|
|
11
14
|
// 历史区在 Turn 终态只固化一次最终快照;读屏模式继续输出中文状态,不能退化为 glyph-only。
|
|
12
15
|
if (timing?.presentation && timing.turnId && timing.presentation.items.some(function belongsToTurn(item) { return item.kind === "capability_notice" || ("turnId" in item && item.turnId === timing.turnId); })) {
|
|
13
|
-
const nodes = renderTuiPresentationTimeline(timing.presentation, timing.turnId, useColor, maximumWidth, { expanded: true, screenReader });
|
|
16
|
+
const nodes = renderTuiPresentationTimeline(timing.presentation, timing.turnId, useColor, maximumWidth, { expanded: true, screenReader }, events);
|
|
14
17
|
const failureReason = getTuiTurnFailureReason(events);
|
|
15
18
|
const terminationSummary = getTuiTerminationSummary(events, timing?.status);
|
|
16
19
|
if (terminationSummary)
|
|
@@ -31,8 +34,7 @@ export function renderTimeline(events, useColor, timing, maximumWidth = 80, scre
|
|
|
31
34
|
function flushAnswer() {
|
|
32
35
|
if (!answer)
|
|
33
36
|
return;
|
|
34
|
-
|
|
35
|
-
nodes.push(_jsxs(Box, { flexDirection: "column", children: [isFirstAnswer && timing?.thoughtDurationMs !== undefined ? _jsxs(Text, { dimColor: useColor, children: ["Thought for ", formatTuiDuration(timing.thoughtDurationMs)] }) : null, _jsxs(Text, { bold: true, color: useColor ? TUI_ACCENT_COLOR : undefined, children: ["\u2022 ", TUI_AGENT_LABEL] }), _jsx(TuiMarkdown, { content: answer, keyPrefix: "answer:" + String(answerSeq), useColor: useColor, maximumWidth: maximumWidth })] }, "answer:" + String(answerSeq++)));
|
|
37
|
+
nodes.push(_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { bold: true, color: useColor ? TUI_ACCENT_COLOR : undefined, children: ["\u2022 ", TUI_AGENT_LABEL] }), _jsx(TuiMarkdown, { content: answer, keyPrefix: "answer:" + String(answerSeq), useColor: useColor, maximumWidth: maximumWidth })] }, "answer:" + String(answerSeq++)));
|
|
36
38
|
lastAnswerNodeIndex = nodes.length - 1;
|
|
37
39
|
answer = "";
|
|
38
40
|
}
|
|
@@ -56,7 +58,7 @@ export function renderTimeline(events, useColor, timing, maximumWidth = 80, scre
|
|
|
56
58
|
}
|
|
57
59
|
flushAnswer();
|
|
58
60
|
if (event.type === "tui_input_consumed") {
|
|
59
|
-
nodes.push(_jsx(Text, { dimColor: useColor, children: formatTuiInputConsumed(event) }
|
|
61
|
+
nodes.push(_jsxs(Box, { flexDirection: "column", children: [_jsx(TuiPromptLine, { content: event.content, useColor: useColor, columns: maximumWidth + 2 }), _jsx(Text, { dimColor: useColor, children: event.cancelled ? "[引导] 已取消" : event.consumed === false ? "[引导] 等待当前步骤结束" : formatTuiInputConsumed(event) })] }, "input:" + event.inputId));
|
|
60
62
|
}
|
|
61
63
|
else if (event.type === "tui_approval_submitted") {
|
|
62
64
|
nodes.push(_jsxs(Text, { dimColor: useColor, children: ["Approval submitted \u00B7 ", getTuiApprovalDecisionLabel(event.decision)] }, String(event.seq) + ":approval:" + event.approvalId));
|
|
@@ -76,7 +78,7 @@ export function renderTimeline(events, useColor, timing, maximumWidth = 80, scre
|
|
|
76
78
|
else if (event.type === "approval_required") {
|
|
77
79
|
if (submittedApprovalIds.has(event.approvalId))
|
|
78
80
|
continue;
|
|
79
|
-
nodes.push(_jsxs(Box, { borderStyle: "single", borderColor: useColor ? TUI_ACCENT_COLOR : undefined, paddingX: 1, flexDirection: "column", children: [_jsx(Text, { bold: true, color: useColor ? TUI_ACCENT_COLOR : undefined, children: "Approval required" }), _jsxs(Text, { children: ["\u64CD\u4F5C\uFF1A", getTuiToolLabel(event.toolName)] }), _jsxs(Text, { children: ["\u539F\u56E0\uFF1A", event.reason] }), _jsx(Text, { dimColor: useColor, children: "[y] \u672C\u6B21 [s] \u672C\u6B21\u4F1A\u8BDD [w] \u6B64\u5DE5\u4F5C\u533A [n] \u62D2\u7EDD" })] }, String(event.seq)));
|
|
81
|
+
nodes.push(_jsxs(Box, { borderStyle: "single", borderColor: useColor ? TUI_ACCENT_COLOR : undefined, paddingX: 1, flexDirection: "column", children: [_jsx(Text, { bold: true, color: useColor ? TUI_ACCENT_COLOR : undefined, children: "Approval required" }), _jsxs(Text, { children: ["\u64CD\u4F5C\uFF1A", getTuiToolLabel(event.toolName)] }), _jsxs(Text, { children: ["\u539F\u56E0\uFF1A", event.reason] }), event.display?.executionMode === "unisolated" && _jsx(Text, { color: useColor ? TUI_TOOL_ERROR_TEXT_COLOR : undefined, children: "\u5C06\u5728\u5F53\u524D\u7528\u6237\u6743\u9650\u4E0B\u8FD0\u884C\uFF08\u672A\u542F\u7528\u6C99\u7BB1\u9694\u79BB\uFF09" }), _jsx(Text, { dimColor: useColor, children: "[y] \u672C\u6B21 [s] \u672C\u6B21\u4F1A\u8BDD [w] \u6B64\u5DE5\u4F5C\u533A [n] \u62D2\u7EDD" })] }, String(event.seq)));
|
|
80
82
|
}
|
|
81
83
|
else if (event.type === "input_queued") {
|
|
82
84
|
nodes.push(_jsx(Text, { dimColor: useColor, children: "Additional instruction queued; waiting for the current step" }, String(event.seq)));
|
|
@@ -110,11 +112,18 @@ export function renderTimeline(events, useColor, timing, maximumWidth = 80, scre
|
|
|
110
112
|
continue;
|
|
111
113
|
}
|
|
112
114
|
else if (event.type === "status") {
|
|
113
|
-
|
|
114
|
-
nodes.push(_jsxs(Text, { children: ["\u539F\u56E0\uFF1A", event.reason] }, String(event.seq)));
|
|
115
|
+
continue;
|
|
115
116
|
}
|
|
116
117
|
}
|
|
117
118
|
flushAnswer();
|
|
119
|
+
const todo = getTuiTurnTodo(events, timing?.turnId ?? events[0]?.turnId ?? "");
|
|
120
|
+
if (todo)
|
|
121
|
+
nodes.push(_jsx(Box, { flexDirection: "column", children: _jsx(TuiTodoList, { item: todo, expanded: true, useColor: useColor, screenReader: screenReader, columns: maximumWidth + 2 }) }, "turn:todo"));
|
|
122
|
+
const terminationSummary = getTuiTerminationSummary(events, timing?.status);
|
|
123
|
+
if (terminationSummary)
|
|
124
|
+
nodes.push(_jsxs(Text, { children: ["\u7EC8\u6001\uFF1A", terminationSummary] }, "turn:termination"));
|
|
125
|
+
else if (getTuiTurnFailureReason(events))
|
|
126
|
+
nodes.push(_jsxs(Text, { children: ["\u539F\u56E0\uFF1A", getTuiTurnFailureReason(events)] }, "turn:failure-reason"));
|
|
118
127
|
if (timing?.totalDurationMs !== undefined)
|
|
119
128
|
nodes.push(_jsxs(Text, { dimColor: useColor, children: ["* Cogitated for ", formatTuiDuration(timing.totalDurationMs)] }, "turn:total-duration"));
|
|
120
129
|
return nodes.filter(function isVisibleTimelineNode(node) { return node !== undefined; });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** 合并既有 Presentation 与宿主输入位置,并读取每轮最后一次安全 Todo。 */
|
|
2
|
+
import { type AgentPresentationState, type TimelineItem, type TodoSnapshotItem } from "@autopilot-agent/presentation";
|
|
3
|
+
import type { CliTuiInputPosition, CliTuiTimelineEvent } from "../types.js";
|
|
4
|
+
export type TuiHostInput = Extract<CliTuiTimelineEvent, {
|
|
5
|
+
type: "tui_input_consumed";
|
|
6
|
+
}>;
|
|
7
|
+
/** 保存当前可见事实的稳定边界,连续回答以字符位置保留输入前后的正文。 */
|
|
8
|
+
export declare function captureTuiInputPosition(turnId: string | undefined, events: CliTuiTimelineEvent[], presentation?: AgentPresentationState): CliTuiInputPosition;
|
|
9
|
+
/** 只采用该轮自身的最后一次 todo_updated;显式空列表保持清空语义。 */
|
|
10
|
+
export declare function getTuiTurnTodo(events: CliTuiTimelineEvent[], turnId: string): TodoSnapshotItem | undefined;
|
|
11
|
+
/** 按提交边界切分共享节点,再复用 selector 分组;宿主正文不会被后来的分组或回答吞到前面。 */
|
|
12
|
+
export declare function getTuiTurnItems(presentation: AgentPresentationState, turnId: string, events: CliTuiTimelineEvent[]): Array<TimelineItem | TuiHostInput>;
|