@autopilot-agent/cli 0.2.0 → 0.4.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 +15 -6
- package/dist/activity-animation.d.ts +5 -0
- package/dist/activity-animation.js +13 -17
- package/dist/browser-client.d.ts +14 -0
- package/dist/browser-client.js +156 -0
- package/dist/composition-root.d.ts +41 -1
- package/dist/composition-root.js +141 -14
- package/dist/context-report.d.ts +9 -4
- package/dist/context-report.js +15 -3
- package/dist/controller.d.ts +81 -4
- package/dist/controller.js +468 -98
- package/dist/design-tokens.d.ts +7 -2
- package/dist/design-tokens.js +11 -3
- package/dist/desktop-status.d.ts +35 -0
- package/dist/desktop-status.js +304 -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 +74 -5
- package/dist/file-mention-budget.d.ts +16 -0
- package/dist/file-mention-budget.js +82 -0
- package/dist/file-mention-context.d.ts +26 -1
- package/dist/file-mention-context.js +70 -22
- package/dist/index.d.ts +1 -1
- package/dist/main.d.ts +3 -0
- package/dist/main.js +213 -12
- package/dist/managed-attach.d.ts +3 -0
- package/dist/managed-attach.js +132 -0
- package/dist/managed-controller.d.ts +49 -0
- package/dist/managed-controller.js +171 -0
- package/dist/orchestration-templates.d.ts +27 -0
- package/dist/orchestration-templates.js +20 -0
- package/dist/parser.d.ts +1 -1
- package/dist/parser.js +510 -2
- package/dist/renderer.js +3 -1
- package/dist/session-summary.d.ts +7 -0
- package/dist/session-summary.js +25 -0
- package/dist/session-title.d.ts +5 -0
- package/dist/session-title.js +10 -0
- package/dist/thread-commands.d.ts +37 -0
- package/dist/thread-commands.js +233 -0
- package/dist/thread-host.d.ts +36 -0
- package/dist/thread-host.js +79 -0
- package/dist/timeline-lines.js +36 -28
- package/dist/tui/app.d.ts +22 -0
- package/dist/tui/app.js +179 -43
- package/dist/tui/approval.d.ts +4 -0
- package/dist/tui/approval.js +13 -4
- package/dist/tui/brand/brand-header.d.ts +1 -3
- package/dist/tui/brand/brand-header.js +6 -8
- package/dist/tui/brand/logo.d.ts +3 -0
- package/dist/tui/brand/logo.js +89 -0
- package/dist/tui/brand/startup.d.ts +18 -0
- package/dist/tui/brand/startup.js +136 -0
- package/dist/tui/constants.d.ts +1 -1
- package/dist/tui/constants.js +1 -1
- package/dist/tui/context.js +1 -3
- package/dist/tui/desktop-resize.d.ts +9 -0
- package/dist/tui/desktop-resize.js +95 -0
- package/dist/tui/format.d.ts +1 -1
- package/dist/tui/format.js +19 -9
- package/dist/tui/hooks/use-file-mention-index.js +9 -4
- package/dist/tui/hooks/use-prompt-input.d.ts +54 -1
- package/dist/tui/hooks/use-prompt-input.js +159 -26
- package/dist/tui/hooks/use-status-view.d.ts +2 -2
- package/dist/tui/hooks/use-status-view.js +38 -11
- package/dist/tui/hooks/use-viewport.d.ts +2 -1
- package/dist/tui/hooks/use-viewport.js +15 -8
- 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 +12 -1
- package/dist/tui/input-area.js +28 -8
- package/dist/tui/lifecycle.d.ts +1 -1
- package/dist/tui/lifecycle.js +84 -16
- 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/pickers/permission.js +1 -1
- package/dist/tui/pickers/slash.d.ts +11 -2
- package/dist/tui/pickers/slash.js +21 -7
- package/dist/tui/prompt-input.d.ts +2 -0
- package/dist/tui/prompt-input.js +6 -4
- package/dist/tui/render-mode.d.ts +8 -4
- package/dist/tui/render-mode.js +17 -11
- package/dist/tui/run.js +53 -55
- package/dist/tui/session-manager.d.ts +116 -0
- package/dist/tui/session-manager.js +384 -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 +4 -0
- package/dist/tui/status-line.js +34 -13
- package/dist/tui/store.d.ts +3 -1
- package/dist/tui/store.js +60 -14
- package/dist/tui/timeline/live.js +2 -3
- package/dist/tui/timeline/progress.js +3 -2
- package/dist/tui/timeline/static-timeline.js +1 -2
- package/dist/tui/timeline/turn.js +3 -2
- package/dist/tui/transcript.d.ts +2 -1
- package/dist/tui/transcript.js +43 -5
- package/dist/tui/trust-dialog.d.ts +3 -0
- package/dist/tui/trust-dialog.js +23 -2
- package/dist/tui/types.d.ts +18 -1
- package/dist/tui/types.js +4 -1
- package/dist/tui/viewport/selection.d.ts +2 -2
- package/dist/tui/viewport/selection.js +13 -6
- package/dist/tui/viewport/sources.js +13 -14
- package/dist/types.d.ts +160 -3
- package/package.json +4 -4
package/dist/tui/store.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/** TUI 外部 Store:把安全事件归约为 React 可订阅快照,不读取 Core Store 或 checkpoint。 */
|
|
2
|
+
import { stripVTControlCharacters } from "node:util";
|
|
2
3
|
import { createInitialCliActivityState, reduceCliActivityState, settleCliActivityState, } from "../activity-animation.js";
|
|
3
4
|
import { TUI_EVENT_PUBLISH_INTERVAL_MS } from "./constants.js";
|
|
4
5
|
import { isTerminalStatus } from "./format.js";
|
|
5
6
|
import { recordTuiPerformanceDiagnostic } from "./performance-diagnostics.js";
|
|
6
7
|
import { captureTuiInputPosition } from "./timeline/turn-items.js";
|
|
8
|
+
import { getCliTuiExecutionMs } from "./types.js";
|
|
7
9
|
/** 创建 TUI 初始快照。 */
|
|
8
10
|
function createInitialTuiSnapshot(now = Date.now()) {
|
|
9
11
|
return {
|
|
@@ -106,14 +108,16 @@ export function createCliTuiStore() {
|
|
|
106
108
|
const metrics = metricsByTurn.get(turnId);
|
|
107
109
|
const thoughtDurationMs = metrics?.firstAnswerAt === undefined
|
|
108
110
|
? undefined
|
|
109
|
-
:
|
|
111
|
+
: metrics.firstAnswerDurationMs ?? 0;
|
|
110
112
|
const totalDurationMs = metrics?.completedAt === undefined
|
|
111
113
|
? undefined
|
|
112
|
-
:
|
|
114
|
+
: getCliTuiExecutionMs(metrics, metrics.completedAt);
|
|
113
115
|
// 终态先保留当前 live Turn,让这一帧同时接住最后的 answer/status block;
|
|
114
116
|
// 立即清空会让外层历史区过滤掉同一 Turn,导致最后一段回答不可见。
|
|
115
117
|
snapshot = {
|
|
116
118
|
...snapshot,
|
|
119
|
+
// Prompt 与所属 Turn 同帧移交历史,避免中断后仍留在动态区或恢复时重放。
|
|
120
|
+
activePrompt: snapshot.activePrompt?.turnId === turnId ? undefined : snapshot.activePrompt,
|
|
117
121
|
transcript: [
|
|
118
122
|
...snapshot.transcript,
|
|
119
123
|
{
|
|
@@ -144,20 +148,29 @@ export function createCliTuiStore() {
|
|
|
144
148
|
if (!trimmed)
|
|
145
149
|
return undefined;
|
|
146
150
|
// 运行中的 steer/queue 由已确认的 inputId 单独记录,避免发送前伪造成功展示。
|
|
147
|
-
if (
|
|
151
|
+
if (displayAsActive === false)
|
|
148
152
|
return undefined;
|
|
149
153
|
const key = "prompt:" + String(promptIndex++);
|
|
150
154
|
publish({
|
|
151
155
|
...snapshot,
|
|
152
156
|
// info 是下一次 Turn 之前的临时反馈;新 prompt 被接收后必须立即消费,不能留在新 Turn 的输入区上方。
|
|
153
157
|
transcript: [
|
|
154
|
-
...snapshot.transcript.filter(function omitConsumedNotice(item) { return item.kind !== "notice"; }),
|
|
158
|
+
...snapshot.transcript.filter(function omitConsumedNotice(item) { return item.kind !== "notice" || item.persistent === true; }),
|
|
155
159
|
{ kind: "prompt", key, content: trimmed },
|
|
156
160
|
],
|
|
157
|
-
activePrompt: displayAsActive ? { key, content: trimmed } : snapshot.activePrompt,
|
|
161
|
+
activePrompt: displayAsActive === true ? { key, content: trimmed } : snapshot.activePrompt,
|
|
158
162
|
});
|
|
159
163
|
return key;
|
|
160
164
|
},
|
|
165
|
+
/** 受信派单随首次附着回放,固定身份去重并保留 TASK 前后空行。 */
|
|
166
|
+
recordTask(id, content) {
|
|
167
|
+
const key = "task:" + id;
|
|
168
|
+
if (snapshot.transcript.some(function same(item) { return item.key === key; }))
|
|
169
|
+
return;
|
|
170
|
+
const text = stripVTControlCharacters(content).replace(/\r\n?/gu, "\n").replace(/\t/gu, " ").replace(/[\u0000-\u0009\u000b-\u001f\u007f-\u009f]/gu, "").trim();
|
|
171
|
+
if (text)
|
|
172
|
+
publish({ ...snapshot, transcript: [{ kind: "prompt", key, content: "\nTASK\n\n" + text }, ...snapshot.transcript] });
|
|
173
|
+
},
|
|
161
174
|
/** 在异步投递之前捕获真实提交位置。 */
|
|
162
175
|
captureInputPosition() { return { ...captureTuiInputPosition(snapshot.liveTurnId, snapshot.liveEvents, snapshot.livePresentation), order: submissionOrder++ }; },
|
|
163
176
|
/** 成功投递后才外显原文,消费与回调的先后次序不改变所属轮。 */
|
|
@@ -187,6 +200,14 @@ export function createCliTuiStore() {
|
|
|
187
200
|
],
|
|
188
201
|
});
|
|
189
202
|
},
|
|
203
|
+
/** 清除宿主已明确拒绝的队列项,迟到的已保存回执不会把它追加回来。 */
|
|
204
|
+
rejectPendingPrompt(inputId, message) {
|
|
205
|
+
if (settledInputIds.has(inputId))
|
|
206
|
+
return;
|
|
207
|
+
settledInputIds.add(inputId);
|
|
208
|
+
snapshot = { ...snapshot, pendingInputs: snapshot.pendingInputs.filter(function keep(input) { return input.inputId !== inputId; }) };
|
|
209
|
+
this.addNotice(message);
|
|
210
|
+
},
|
|
190
211
|
/** 在自动 queue Turn 开始前,将 prompt 放进目标 Turn 的事件序列并清除等待态。 */
|
|
191
212
|
markQueuedInputStarted(input) {
|
|
192
213
|
if (settledInputIds.has(input.inputId))
|
|
@@ -224,6 +245,10 @@ export function createCliTuiStore() {
|
|
|
224
245
|
eventsByTurn.set(turnId, nextEvents);
|
|
225
246
|
publish({ ...snapshot, liveEvents: snapshot.liveTurnId === turnId ? nextEvents : snapshot.liveEvents, pendingApproval: undefined });
|
|
226
247
|
},
|
|
248
|
+
/** 发布 Session 内的手动压缩等待态,切换视图后仍由原请求负责清除。 */
|
|
249
|
+
setCompacting(compacting) {
|
|
250
|
+
publish({ ...snapshot, compacting });
|
|
251
|
+
},
|
|
227
252
|
addNotice(message) {
|
|
228
253
|
const trimmed = message.trim();
|
|
229
254
|
if (!trimmed)
|
|
@@ -232,11 +257,15 @@ export function createCliTuiStore() {
|
|
|
232
257
|
...snapshot,
|
|
233
258
|
transcript: [
|
|
234
259
|
...snapshot.transcript,
|
|
235
|
-
{ kind: "notice", key: "notice:" + String(noticeIndex++), message: trimmed },
|
|
260
|
+
{ kind: "notice", key: "notice:" + String(noticeIndex++), message: trimmed, persistent: trimmed.includes("\n") },
|
|
236
261
|
],
|
|
237
262
|
});
|
|
238
263
|
},
|
|
239
264
|
acceptEvent(event, projection) {
|
|
265
|
+
if (event.type === "thread_wait") {
|
|
266
|
+
publish({ ...snapshot, threadWait: projection.threadWait });
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
240
269
|
// 用量变化只刷新动态状态栏事实,不进入 transcript 时间线或 scrollback。
|
|
241
270
|
if (event.type === "context_usage") {
|
|
242
271
|
if (snapshot.contextUsage === event.usage)
|
|
@@ -245,8 +274,11 @@ export function createCliTuiStore() {
|
|
|
245
274
|
return;
|
|
246
275
|
}
|
|
247
276
|
// Esc 后只等待 Runtime 的终态;取消请求之后已经在途的回答/工具尾部事件不再进入可见时间线。
|
|
248
|
-
if (snapshot.cancellationRequested && !(event.type === "status" && isTerminalStatus(event.status)))
|
|
277
|
+
if (snapshot.cancellationRequested && snapshot.liveTurnId === event.turnId && !(event.type === "status" && isTerminalStatus(event.status)))
|
|
249
278
|
return;
|
|
279
|
+
if (event.type === "turn_started" && finalizedTurns.delete(event.turnId)) {
|
|
280
|
+
snapshot = { ...snapshot, transcript: snapshot.transcript.filter(function previousSegment(item) { return item.kind !== "turn" || item.turnId !== event.turnId; }) };
|
|
281
|
+
}
|
|
250
282
|
const currentEvents = eventsByTurn.get(event.turnId) ?? [];
|
|
251
283
|
if (currentEvents.some(function hasSequence(item) { return item.type === event.type && item.seq === event.seq; }))
|
|
252
284
|
return;
|
|
@@ -254,18 +286,23 @@ export function createCliTuiStore() {
|
|
|
254
286
|
eventsByTurn.set(event.turnId, nextEvents);
|
|
255
287
|
presentationByTurn.set(event.turnId, projection.presentation);
|
|
256
288
|
const isNewTurn = snapshot.liveTurnId !== event.turnId;
|
|
257
|
-
const activePrompt = snapshot.activePrompt && snapshot.activePrompt.turnId === undefined
|
|
289
|
+
const activePrompt = snapshot.activePrompt && snapshot.activePrompt.turnId === undefined && !isTerminalStatus(projection.status)
|
|
258
290
|
? { ...snapshot.activePrompt, turnId: event.turnId }
|
|
259
291
|
: snapshot.activePrompt;
|
|
260
292
|
const eventTime = Date.now();
|
|
261
293
|
const previousMetrics = metricsByTurn.get(event.turnId);
|
|
262
294
|
const nextMetrics = {
|
|
263
|
-
startedAt:
|
|
295
|
+
startedAt: previousMetrics?.startedAt ?? eventTime,
|
|
296
|
+
elapsedMs: projection.presentation?.executionByTurn?.[event.turnId]?.elapsedMs ?? previousMetrics?.elapsedMs,
|
|
297
|
+
runningSince: projection.presentation?.executionByTurn?.[event.turnId]?.runningSince,
|
|
298
|
+
firstAnswerDurationMs: previousMetrics?.firstAnswerDurationMs,
|
|
264
299
|
firstAnswerAt: previousMetrics?.firstAnswerAt,
|
|
265
|
-
completedAt: previousMetrics?.completedAt,
|
|
300
|
+
completedAt: event.type === "turn_started" ? undefined : previousMetrics?.completedAt,
|
|
266
301
|
};
|
|
267
|
-
if (event.type === "answer_delta" && nextMetrics.firstAnswerAt === undefined)
|
|
302
|
+
if (event.type === "answer_delta" && nextMetrics.firstAnswerAt === undefined) {
|
|
268
303
|
nextMetrics.firstAnswerAt = eventTime;
|
|
304
|
+
nextMetrics.firstAnswerDurationMs = getCliTuiExecutionMs(nextMetrics, eventTime);
|
|
305
|
+
}
|
|
269
306
|
// Core 的 reset/discard 表示当前采样的暂定文字不能展示;下一次真正回答重新计时。
|
|
270
307
|
if (event.type === "answer_reset")
|
|
271
308
|
nextMetrics.firstAnswerAt = undefined;
|
|
@@ -283,12 +320,13 @@ export function createCliTuiStore() {
|
|
|
283
320
|
hasLiveApprovalEvent: isNewTurn ? event.type === "approval_required" : snapshot.hasLiveApprovalEvent || event.type === "approval_required",
|
|
284
321
|
activity: nextActivity,
|
|
285
322
|
status: projection.status,
|
|
323
|
+
threadWait: projection.threadWait,
|
|
286
324
|
recoverable: projection.recoverable,
|
|
287
325
|
pendingApproval: projection.pendingApproval && !submittedApprovalIds.has(projection.pendingApproval.approvalId)
|
|
288
326
|
? { ...projection.pendingApproval }
|
|
289
327
|
: undefined,
|
|
290
328
|
activeSkills: projection.activeSkills.map(function copySkill(skill) { return { ...skill }; }),
|
|
291
|
-
cancellationRequested: event.type === "status" && isTerminalStatus(event.status)
|
|
329
|
+
cancellationRequested: !isNewTurn && !(event.type === "status" && isTerminalStatus(event.status)) && snapshot.cancellationRequested,
|
|
292
330
|
};
|
|
293
331
|
if (event.type === "input_consumed") {
|
|
294
332
|
settledInputIds.add(event.inputId);
|
|
@@ -322,11 +360,18 @@ export function createCliTuiStore() {
|
|
|
322
360
|
}
|
|
323
361
|
},
|
|
324
362
|
syncProjection(projection) {
|
|
363
|
+
// Controller已过滤正在提交或已保存的请求,权威pending重现表示保存失败,可重试原请求。
|
|
364
|
+
if (projection.pendingApproval)
|
|
365
|
+
submittedApprovalIds.delete(projection.pendingApproval.approvalId);
|
|
366
|
+
// 身份失效只关闭交互;已打开的旧正文保留为最后观察到的历史,不伪造终态。
|
|
367
|
+
if (snapshot.liveTurnId && projection.turnId !== snapshot.liveTurnId && snapshot.liveEvents.length && !snapshot.transcript.some(function existing(item) { return item.kind === "turn" && item.turnId === snapshot.liveTurnId; })) {
|
|
368
|
+
snapshot = { ...snapshot, transcript: [...snapshot.transcript, { kind: "turn", key: "observed:" + snapshot.liveTurnId, turnId: snapshot.liveTurnId, events: snapshot.liveEvents, presentation: snapshot.livePresentation, status: snapshot.status }] };
|
|
369
|
+
}
|
|
325
370
|
if (projection.turnId && !eventsByTurn.has(projection.turnId) && projection.events.length > 0)
|
|
326
371
|
eventsByTurn.set(projection.turnId, projection.events.filter(function belongs(event) { return event.turnId === projection.turnId; }));
|
|
327
372
|
const turnIsFinalized = projection.turnId ? finalizedTurns.has(projection.turnId) : false;
|
|
328
373
|
const isNewTurn = projection.turnId !== undefined && projection.turnId !== snapshot.liveTurnId;
|
|
329
|
-
const activePrompt = snapshot.activePrompt && snapshot.activePrompt.turnId === undefined && projection.turnId
|
|
374
|
+
const activePrompt = snapshot.activePrompt && snapshot.activePrompt.turnId === undefined && projection.turnId && !isTerminalStatus(projection.status)
|
|
330
375
|
? { ...snapshot.activePrompt, turnId: projection.turnId }
|
|
331
376
|
: snapshot.activePrompt;
|
|
332
377
|
const keepFinalizedLiveTurn = Boolean(projection.turnId && turnIsFinalized && projection.turnId === snapshot.liveTurnId);
|
|
@@ -350,12 +395,13 @@ export function createCliTuiStore() {
|
|
|
350
395
|
hasLiveApprovalEvent: Boolean(keepLiveTurn && !isNewTurn && snapshot.hasLiveApprovalEvent),
|
|
351
396
|
activity,
|
|
352
397
|
status: projection.status,
|
|
398
|
+
threadWait: projection.threadWait,
|
|
353
399
|
recoverable: projection.recoverable,
|
|
354
400
|
pendingApproval: projection.pendingApproval && !submittedApprovalIds.has(projection.pendingApproval.approvalId)
|
|
355
401
|
? { ...projection.pendingApproval }
|
|
356
402
|
: undefined,
|
|
357
403
|
activeSkills: projection.activeSkills.map(function copySkill(skill) { return { ...skill }; }),
|
|
358
|
-
cancellationRequested: isTerminalStatus(projection.status)
|
|
404
|
+
cancellationRequested: !isNewTurn && !isTerminalStatus(projection.status) && snapshot.cancellationRequested,
|
|
359
405
|
};
|
|
360
406
|
if (projection.turnId && isTerminalStatus(projection.status)) {
|
|
361
407
|
finalizeTurn(projection.turnId, projection.status);
|
|
@@ -4,7 +4,7 @@ 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
9
|
import { TuiPromptLine } from "../transcript.js";
|
|
10
10
|
import { renderTuiToolTreeEvent } from "./tool-tree.js";
|
|
@@ -143,9 +143,8 @@ function renderTuiLiveTimelineBlock(block, useColor, renderMarkdown, maximumWidt
|
|
|
143
143
|
*/
|
|
144
144
|
export const TuiLiveTimeline = memo(function TuiLiveTimeline(props) {
|
|
145
145
|
const blocks = useCliTuiTimelineBlocks(props.events);
|
|
146
|
-
const firstAnswerKey = blocks.find(function findFirstAnswer(block) { return block.kind === "answer"; })?.key;
|
|
147
146
|
function renderBlock(block) {
|
|
148
|
-
return (
|
|
147
|
+
return (_jsx(Box, { flexDirection: "column", children: renderTuiLiveTimelineBlock(block, props.useColor, isTerminalStatus(props.status), props.maximumWidth) }, block.key));
|
|
149
148
|
}
|
|
150
149
|
return (_jsx(_Fragment, { children: blocks.map(function renderDynamicTimelineBlock(block) {
|
|
151
150
|
return renderBlock(block);
|
|
@@ -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
|
}
|
|
@@ -34,8 +34,7 @@ export function renderTimeline(events, useColor, timing, maximumWidth = 80, scre
|
|
|
34
34
|
function flushAnswer() {
|
|
35
35
|
if (!answer)
|
|
36
36
|
return;
|
|
37
|
-
|
|
38
|
-
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++)));
|
|
39
38
|
lastAnswerNodeIndex = nodes.length - 1;
|
|
40
39
|
answer = "";
|
|
41
40
|
}
|
|
@@ -2,6 +2,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
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";
|
|
@@ -10,12 +11,12 @@ import { TuiTodoList } from "../todo-list.js";
|
|
|
10
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
19
|
return (_jsxs(Box, { flexDirection: "column", children: [props.presentation && hasPresentation
|
|
19
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)
|
|
20
|
-
: _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(
|
|
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;
|
|
@@ -21,4 +21,5 @@ export declare const MemoizedTuiTranscriptItem: import("react").MemoExoticCompon
|
|
|
21
21
|
export declare function TuiPendingInputItem(props: {
|
|
22
22
|
item: CliTuiPendingInput;
|
|
23
23
|
useColor: boolean;
|
|
24
|
+
columns: number;
|
|
24
25
|
}): ReactNode;
|
package/dist/tui/transcript.js
CHANGED
|
@@ -1,12 +1,29 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
/** transcript 节点渲染:用户 prompt、通知、完整历史 Turn 与动态等待输入。 */
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { stripVTControlCharacters } from "node:util";
|
|
4
|
+
import { memo, useContext } from "react";
|
|
5
|
+
import { Box, Text, Transform } from "ink";
|
|
6
|
+
import stringWidth from "string-width";
|
|
7
|
+
import wrapAnsi from "wrap-ansi";
|
|
8
|
+
import { TUI_ACCENT_COLOR, TUI_MANAGED_PROMPT_BACKGROUND_SGR, TUI_PROMPT_BACKGROUND_COLOR, TUI_WAITING_BACKGROUND_COLOR } from "../design-tokens.js";
|
|
6
9
|
import { splitTuiFileMentionSegments } from "./input/file-mention.js";
|
|
10
|
+
import { TuiManagedTerminalStyles } from "./render-mode.js";
|
|
7
11
|
import { renderTimeline } from "./timeline/static-timeline.js";
|
|
8
12
|
/** 渲染一个用户 prompt;当前 Turn 会暂留在动态区,避免历史区固化时机丢失。@文件 片段用强调色加粗。 */
|
|
9
13
|
export function TuiPromptLine(props) {
|
|
14
|
+
const managedBackground = useContext(TuiManagedTerminalStyles);
|
|
15
|
+
if (managedBackground) {
|
|
16
|
+
// 仅清理显示副本,交给 Ink 的控制码只来自固定颜色 token。
|
|
17
|
+
const content = stripVTControlCharacters(props.content).replace(/\r\n?/gu, "\n").replace(/\t/gu, " ").replace(/[\u0000-\u0009\u000b-\u001f\u007f-\u009f]/gu, "");
|
|
18
|
+
const inset = props.columns > 3 ? " " : "";
|
|
19
|
+
const width = Math.max(1, props.columns - inset.length * 2);
|
|
20
|
+
const lines = wrapAnsi(content, width, { hard: true, trim: false }).split("\n")
|
|
21
|
+
.map(function indent(line) { return inset + line; }).join("\n");
|
|
22
|
+
return _jsx(Box, { width: props.columns, children: _jsx(Transform, { transform: function shadePromptRow(line) {
|
|
23
|
+
const fill = " ".repeat(Math.max(0, props.columns - stringWidth(line)));
|
|
24
|
+
return TUI_MANAGED_PROMPT_BACKGROUND_SGR + line + fill + "\u001b[49m";
|
|
25
|
+
}, children: lines }) }, props.keyValue);
|
|
26
|
+
}
|
|
10
27
|
const segments = splitTuiFileMentionSegments(props.content);
|
|
11
28
|
return (_jsx(Box, { width: props.columns, paddingX: 1, backgroundColor: props.useColor ? TUI_PROMPT_BACKGROUND_COLOR : undefined, children: _jsx(Text, { color: props.useColor ? TUI_ACCENT_COLOR : undefined, children: segments.map(function renderPromptSegment(segment, index) {
|
|
12
29
|
if (!segment.isMention)
|
|
@@ -14,8 +31,26 @@ export function TuiPromptLine(props) {
|
|
|
14
31
|
return _jsx(Text, { bold: props.useColor, children: segment.text }, index);
|
|
15
32
|
}) }) }, props.keyValue));
|
|
16
33
|
}
|
|
17
|
-
/**
|
|
34
|
+
/** 历史item生命周期内最多保留四个尺寸/颜色/读屏变体,跨重挂载复用稳定元素。 */
|
|
35
|
+
const transcriptRenderCache = new WeakMap();
|
|
36
|
+
/** 按不可变历史item引用复用元素;不冻结当前Turn或改变输出。 */
|
|
18
37
|
export function TuiTranscriptItem(props) {
|
|
38
|
+
const key = `${props.columns}:${props.useColor}:${props.screenReader ?? false}`;
|
|
39
|
+
let variants = transcriptRenderCache.get(props.item);
|
|
40
|
+
if (variants?.has(key))
|
|
41
|
+
return variants.get(key);
|
|
42
|
+
const rendered = renderTranscriptItem(props);
|
|
43
|
+
if (!variants) {
|
|
44
|
+
variants = new Map();
|
|
45
|
+
transcriptRenderCache.set(props.item, variants);
|
|
46
|
+
}
|
|
47
|
+
if (variants.size >= 4)
|
|
48
|
+
variants.delete(variants.keys().next().value);
|
|
49
|
+
variants.set(key, rendered);
|
|
50
|
+
return rendered;
|
|
51
|
+
}
|
|
52
|
+
/** 渲染已经完成的 prompt、notice 或完整 Turn。 */
|
|
53
|
+
function renderTranscriptItem(props) {
|
|
19
54
|
const item = props.item;
|
|
20
55
|
if (item.kind === "prompt") {
|
|
21
56
|
return _jsx(TuiPromptLine, { content: item.content, useColor: props.useColor, columns: props.columns, keyValue: item.key }, item.key);
|
|
@@ -29,6 +64,9 @@ export function TuiTranscriptItem(props) {
|
|
|
29
64
|
export const MemoizedTuiTranscriptItem = memo(TuiTranscriptItem);
|
|
30
65
|
/** queue 在等待区显示原文;steer 正文已按提交位置留在所属轮。 */
|
|
31
66
|
export function TuiPendingInputItem(props) {
|
|
67
|
+
const managedBackground = useContext(TuiManagedTerminalStyles);
|
|
32
68
|
const label = props.item.delivery === "queue" ? "[排队]" : "[引导]";
|
|
33
|
-
return (_jsxs(Box, { flexDirection: "column", backgroundColor: props.useColor ? TUI_WAITING_BACKGROUND_COLOR : undefined, children: [props.item.delivery === "queue" ?
|
|
69
|
+
return (_jsxs(Box, { flexDirection: "column", backgroundColor: props.useColor && !managedBackground ? TUI_WAITING_BACKGROUND_COLOR : undefined, children: [props.item.delivery === "queue" ? managedBackground
|
|
70
|
+
? _jsx(TuiPromptLine, { content: props.item.content, useColor: props.useColor, columns: props.columns })
|
|
71
|
+
: _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
72
|
}
|
|
@@ -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
|
@@ -17,6 +17,7 @@ export type CliTuiTranscriptItem = {
|
|
|
17
17
|
kind: "notice";
|
|
18
18
|
key: string;
|
|
19
19
|
message: string;
|
|
20
|
+
persistent?: boolean;
|
|
20
21
|
} | {
|
|
21
22
|
kind: "turn";
|
|
22
23
|
key: string;
|
|
@@ -68,8 +69,13 @@ export interface CliTuiInputPosition {
|
|
|
68
69
|
export interface CliTuiTurnMetrics {
|
|
69
70
|
startedAt: number;
|
|
70
71
|
firstAnswerAt?: number;
|
|
72
|
+
firstAnswerDurationMs?: number;
|
|
73
|
+
elapsedMs?: number;
|
|
74
|
+
runningSince?: number;
|
|
71
75
|
completedAt?: number;
|
|
72
76
|
}
|
|
77
|
+
/** 复用共享 Presentation 执行段;旧宿主缺少时钟事实时不擅自把等待计为执行。 */
|
|
78
|
+
export declare function getCliTuiExecutionMs(metrics: CliTuiTurnMetrics, now?: number): number;
|
|
73
79
|
/** 当前 Turn 的用户输入;动态区保留它,避免历史区固化时机导致 prompt 消失。 */
|
|
74
80
|
export interface CliTuiActivePrompt {
|
|
75
81
|
key: string;
|
|
@@ -91,6 +97,7 @@ export interface CliTuiSnapshot {
|
|
|
91
97
|
status: CliTurnStatus;
|
|
92
98
|
recoverable: boolean;
|
|
93
99
|
pendingApproval?: CliProjection["pendingApproval"];
|
|
100
|
+
threadWait?: CliProjection["threadWait"];
|
|
94
101
|
activeSkills: Array<{
|
|
95
102
|
skillId: string;
|
|
96
103
|
contentHash: string;
|
|
@@ -98,18 +105,21 @@ export interface CliTuiSnapshot {
|
|
|
98
105
|
/** 最近一次 context_usage 的安全 DTO;只驱动状态栏刷新,不进入时间线。 */
|
|
99
106
|
contextUsage?: ContextUsageView | null;
|
|
100
107
|
cancellationRequested: boolean;
|
|
108
|
+
/** 当前 Session 的手动压缩等待态,仅供 TUI 展示,不改变 Turn 状态。 */
|
|
109
|
+
compacting?: boolean;
|
|
101
110
|
requestedExitCode?: CliExitCode;
|
|
102
111
|
}
|
|
103
112
|
/** TUI Store 只负责把安全事件转成 React 可订阅快照。 */
|
|
104
113
|
export interface CliTuiStore {
|
|
105
114
|
getSnapshot(): CliTuiSnapshot;
|
|
106
115
|
subscribe(listener: () => void): () => void;
|
|
107
|
-
recordPrompt(content: string, displayAsActive?: boolean): string | undefined;
|
|
116
|
+
recordPrompt(content: string, displayAsActive?: boolean | "history"): string | undefined;
|
|
108
117
|
captureInputPosition(): CliTuiInputPosition;
|
|
109
118
|
addPendingPrompt(content: string, input: {
|
|
110
119
|
inputId: string;
|
|
111
120
|
delivery: "steer" | "queue";
|
|
112
121
|
}, position?: CliTuiInputPosition): void;
|
|
122
|
+
rejectPendingPrompt(inputId: string, message: string): void;
|
|
113
123
|
markQueuedInputStarted(input: CliQueuedInputStarted): void;
|
|
114
124
|
recordApprovalSubmission(decision: Extract<CliAction, {
|
|
115
125
|
type: "approve";
|
|
@@ -118,6 +128,7 @@ export interface CliTuiStore {
|
|
|
118
128
|
acceptEvent(event: CliPublicEvent, projection: CliProjection): void;
|
|
119
129
|
syncProjection(projection: CliProjection): void;
|
|
120
130
|
setCancellationRequested(requested: boolean): void;
|
|
131
|
+
setCompacting(compacting: boolean): void;
|
|
121
132
|
requestExit(code: CliExitCode): void;
|
|
122
133
|
}
|
|
123
134
|
/** TUI 的启动操作;resume 不把完整 checkpoint 传入 UI。 */
|
|
@@ -129,7 +140,13 @@ export type CliTuiInitialOperation = {
|
|
|
129
140
|
};
|
|
130
141
|
/** Ink TUI 的运行参数。 */
|
|
131
142
|
export interface RunCliTuiOptions {
|
|
143
|
+
/** 远端受管会话使用同一 Store 接收持久事件及连接提示。 */
|
|
144
|
+
store?: CliTuiStore;
|
|
145
|
+
/** Desktop 编排主控允许已提交消息灰底和模型名的局部强调色。 */
|
|
146
|
+
managedPromptBackground?: boolean;
|
|
132
147
|
controller: CliController;
|
|
148
|
+
/** Project级固定会话目录;选择只变视图,不恢复执行。 */
|
|
149
|
+
sessionManager?: import("./session-manager.js").CliSessionManager;
|
|
133
150
|
/** 主机已知的只读会话标识;仅用于备用屏退出后的安全摘要。 */
|
|
134
151
|
sessionId?: string;
|
|
135
152
|
/** 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
|
+
}
|
|
@@ -21,7 +21,7 @@ export declare function getTuiVisualLineSelectionRange(lines: TimelineVisualLine
|
|
|
21
21
|
start: number;
|
|
22
22
|
end: number;
|
|
23
23
|
} | undefined;
|
|
24
|
-
/** 将当前选区交给平台剪贴板;Windows 不经 shell 调用 clip,其它平台使用有界 OSC 52。 */
|
|
24
|
+
/** 将当前选区交给平台剪贴板;Windows/macOS 不经 shell 调用 clip/pbcopy,其它平台使用有界 OSC 52。 */
|
|
25
25
|
export declare function copyTuiSelectedText(text: string, stdout: {
|
|
26
26
|
write(chunk: string): void;
|
|
27
|
-
}): void
|
|
27
|
+
}): Promise<void>;
|
|
@@ -64,14 +64,21 @@ export function getTuiVisualLineSelectionRange(lines, selection, lineIndex) {
|
|
|
64
64
|
const end = lineIndex === endIndex ? Math.max(start, endPoint.sourceOffset - line.sourceStart) : line.text.length;
|
|
65
65
|
return start < end ? { start, end } : undefined;
|
|
66
66
|
}
|
|
67
|
-
/** 将当前选区交给平台剪贴板;Windows 不经 shell 调用 clip,其它平台使用有界 OSC 52。 */
|
|
68
|
-
export function copyTuiSelectedText(text, stdout) {
|
|
67
|
+
/** 将当前选区交给平台剪贴板;Windows/macOS 不经 shell 调用 clip/pbcopy,其它平台使用有界 OSC 52。 */
|
|
68
|
+
export async function copyTuiSelectedText(text, stdout) {
|
|
69
69
|
if (!text)
|
|
70
70
|
return;
|
|
71
|
-
if (process.platform === "win32") {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
if (process.platform === "win32" || process.platform === "darwin") {
|
|
72
|
+
await new Promise(function writeClipboard(resolve, reject) {
|
|
73
|
+
const clipboard = spawn(process.platform === "win32" ? "clip.exe" : "pbcopy", [], { stdio: "pipe", windowsHide: true });
|
|
74
|
+
clipboard.on("error", reject);
|
|
75
|
+
clipboard.stdin.on("error", reject);
|
|
76
|
+
clipboard.on("close", function copied(code) { if (code === 0)
|
|
77
|
+
resolve();
|
|
78
|
+
else
|
|
79
|
+
reject(new Error("剪贴板写入失败")); });
|
|
80
|
+
clipboard.stdin.end(process.platform === "win32" ? Buffer.from("\ufeff" + text, "utf16le") : Buffer.from(text, "utf8"));
|
|
81
|
+
});
|
|
75
82
|
return;
|
|
76
83
|
}
|
|
77
84
|
const bytes = Buffer.from(text);
|