@autopilot-agent/cli 0.3.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 +8 -4
- package/dist/activity-animation.d.ts +1 -0
- package/dist/activity-animation.js +4 -2
- package/dist/browser-client.d.ts +14 -0
- package/dist/browser-client.js +156 -0
- package/dist/composition-root.d.ts +12 -2
- package/dist/composition-root.js +33 -15
- package/dist/context-report.d.ts +1 -1
- package/dist/context-report.js +1 -1
- package/dist/controller.d.ts +48 -1
- package/dist/controller.js +50 -24
- 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/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/main.d.ts +3 -0
- package/dist/main.js +76 -10
- 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 +14 -4
- package/dist/thread-host.d.ts +5 -0
- package/dist/thread-host.js +3 -0
- package/dist/tui/app.js +82 -18
- package/dist/tui/approval.js +1 -1
- 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/hooks/use-file-mention-index.js +9 -4
- package/dist/tui/hooks/use-prompt-input.d.ts +2 -1
- package/dist/tui/hooks/use-prompt-input.js +12 -7
- package/dist/tui/hooks/use-viewport.d.ts +2 -1
- package/dist/tui/hooks/use-viewport.js +15 -8
- package/dist/tui/input-area.d.ts +4 -1
- package/dist/tui/input-area.js +12 -7
- package/dist/tui/lifecycle.d.ts +1 -1
- package/dist/tui/lifecycle.js +82 -11
- 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 +1 -0
- package/dist/tui/prompt-input.js +2 -2
- package/dist/tui/render-mode.d.ts +4 -0
- package/dist/tui/render-mode.js +12 -0
- package/dist/tui/run.js +17 -7
- package/dist/tui/session-manager.d.ts +1 -0
- package/dist/tui/session-manager.js +1 -0
- package/dist/tui/status-line.d.ts +1 -0
- package/dist/tui/status-line.js +29 -14
- package/dist/tui/store.d.ts +3 -1
- package/dist/tui/store.js +33 -9
- package/dist/tui/transcript.d.ts +1 -0
- package/dist/tui/transcript.js +24 -4
- package/dist/tui/types.d.ts +10 -1
- package/dist/tui/viewport/selection.d.ts +2 -2
- package/dist/tui/viewport/selection.js +13 -6
- package/dist/tui/viewport/sources.js +7 -1
- package/dist/types.d.ts +9 -2
- package/package.json +4 -4
package/dist/tui/app.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { jsx as _jsx,
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
/** 瘦身后的 Ink 应用组件:编排 store 订阅、dispatchAction、动画时钟与渲染。 */
|
|
3
3
|
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
4
|
-
import { Box, measureElement, useInput, useStdin, useStdout } from "ink";
|
|
4
|
+
import { Box, Text, measureElement, useInput, useStdin, useStdout } from "ink";
|
|
5
5
|
import { TuiInlineOutput } from "./inline-output.js";
|
|
6
6
|
import { TuiActivityLine } from "../activity-animation.js";
|
|
7
7
|
import { createTuiAnimationClock } from "../animation-clock.js";
|
|
@@ -22,10 +22,11 @@ import { TuiInfoLines, TuiStatusLine } from "./status-line.js";
|
|
|
22
22
|
import { TuiJobs } from "./jobs.js";
|
|
23
23
|
import { TuiLiveTurn } from "./timeline/turn.js";
|
|
24
24
|
import { getTuiTurnTodo } from "./timeline/turn-items.js";
|
|
25
|
-
import { MemoizedTuiTranscriptItem, TuiPendingInputItem } from "./transcript.js";
|
|
25
|
+
import { MemoizedTuiTranscriptItem, TuiPendingInputItem, TuiPromptLine } from "./transcript.js";
|
|
26
26
|
import { getTuiSelectedText } from "./viewport/selection.js";
|
|
27
27
|
import { createTuiViewportSourceCache } from "./viewport/sources.js";
|
|
28
28
|
import { TuiViewportTimeline } from "./viewport/viewport.js";
|
|
29
|
+
import wrapAnsi from "wrap-ansi";
|
|
29
30
|
const EMPTY_VIEWPORT_SOURCES = [];
|
|
30
31
|
const EMPTY_VIEWPORT_LINES = [];
|
|
31
32
|
/** Ink 应用组件;useInput 只把用户动作交给 Controller Action。 */
|
|
@@ -44,6 +45,7 @@ export function CliTuiApp(props) {
|
|
|
44
45
|
const jobRequestGeneration = useRef(0);
|
|
45
46
|
/** /context 覆盖视图;打开时取代时间线渲染,Esc 关闭后回到正常聊天。 */
|
|
46
47
|
const [contextView, setContextView] = useState(undefined);
|
|
48
|
+
const [infoReport, setInfoReport] = useState();
|
|
47
49
|
const rawInputSequenceRef = useRef("");
|
|
48
50
|
const busy = useRef(false);
|
|
49
51
|
const keepOpenAfterCancel = useRef(false);
|
|
@@ -63,6 +65,7 @@ export function CliTuiApp(props) {
|
|
|
63
65
|
const columns = props.availableColumns ?? terminalSize.columns;
|
|
64
66
|
const inputEnabled = props.visible !== false && props.inputActive !== false;
|
|
65
67
|
const rows = props.availableRows ?? terminalSize.rows;
|
|
68
|
+
const maximumFrameRows = isViewportMode ? rows : Math.max(1, rows - 1);
|
|
66
69
|
const { statusView, refreshStatusView } = useStatusView(props.controller);
|
|
67
70
|
/** 输入子树通过 ref 读取 slash 与 @ 建议,父级只注入视口按键处理器。 */
|
|
68
71
|
const derivedRef = useRef({
|
|
@@ -82,13 +85,22 @@ export function CliTuiApp(props) {
|
|
|
82
85
|
});
|
|
83
86
|
}, []);
|
|
84
87
|
const infoMessages = snapshot.transcript
|
|
85
|
-
.filter(function isNotice(item) { return item.kind === "notice"; })
|
|
88
|
+
.filter(function isNotice(item) { return item.kind === "notice" && !item.persistent; })
|
|
86
89
|
.slice(-4)
|
|
87
90
|
.map(function getNoticeMessage(item) { return item.message; });
|
|
91
|
+
const reportLines = infoReport ? wrapAnsi(infoReport.text, Math.max(1, columns - 2), { hard: true, trim: false }).split("\n") : [];
|
|
92
|
+
// 有配置视图时为状态、配置、Context、工作区四行和上边距留空间。
|
|
93
|
+
const statusHeight = (statusView ? 5 : 1) + (props.sessionTitle ? 1 : 0);
|
|
94
|
+
const reportHeight = Math.max(1, rows - statusHeight - 4);
|
|
95
|
+
const reportMaximum = Math.max(0, reportLines.length - reportHeight);
|
|
96
|
+
const reportOffset = Math.min(infoReport?.offset ?? 0, reportMaximum);
|
|
88
97
|
const [approvalOffset, setApprovalOffset] = useState(0);
|
|
89
98
|
const [approvalDetails, setApprovalDetails] = useState(false);
|
|
99
|
+
const [submittedFeedback, setApprovalFeedback] = useState();
|
|
100
|
+
const hostStatus = props.controller.getHostApprovalStatus?.();
|
|
101
|
+
const approvalFeedback = hostStatus ? undefined : submittedFeedback;
|
|
90
102
|
const approvalMaximumRef = useRef(0);
|
|
91
|
-
const approvalCardHeight = snapshot.pendingApproval ? Math.max(createTuiApprovalOptions(snapshot.pendingApproval).length + 4, Math.min(Math.floor(rows / 2), rows - inputLayout.promptHeight -
|
|
103
|
+
const approvalCardHeight = snapshot.pendingApproval ? Math.max(createTuiApprovalOptions(snapshot.pendingApproval).length + 4, Math.min(Math.floor(rows / 2), rows - inputLayout.promptHeight - statusHeight - 2)) : 0;
|
|
92
104
|
/** 主会话普通审批与原地卡片使用同一详情滚动/固定决定组件。 */
|
|
93
105
|
function handleApprovalKey(value, key) {
|
|
94
106
|
if (key.pageUp || key.pageDown) {
|
|
@@ -112,10 +124,21 @@ export function CliTuiApp(props) {
|
|
|
112
124
|
// Todo 展开态最多占 10 行;矮终端为输入框、状态栏和活动文案至少保留 6 行。
|
|
113
125
|
const todoRowLimit = Math.max(2, Math.min(10, rows - 6));
|
|
114
126
|
const activeTodoForm = getTuiTurnTodo(snapshot.liveEvents, snapshot.liveTurnId ?? "")?.todos.find(function active(todo) { return todo.status === "in_progress"; })?.activeForm;
|
|
115
|
-
const fixedHeight = inputLayout.promptHeight + inputLayout.pickerHeight + approvalHeight + infoMessages.length + (infoMessages.length ? 1 : 0) +
|
|
127
|
+
const fixedHeight = inputLayout.promptHeight + inputLayout.pickerHeight + approvalHeight + infoMessages.length + (infoMessages.length ? 1 : 0) + (approvalFeedback ? 1 : 0) + 1 + statusHeight;
|
|
116
128
|
const fixedRef = useRef(null);
|
|
129
|
+
const inputAreaRef = useRef(null);
|
|
130
|
+
const approvalBoxRef = useRef(null);
|
|
117
131
|
const inlineBodyRef = useRef(null);
|
|
118
132
|
const [inlineHeight, setInlineHeight] = useState();
|
|
133
|
+
const [reservedInputRows, setReservedInputRows] = useState(0);
|
|
134
|
+
/** 量出输入之外的固定行,避免活动行、状态栏折行和审批卡侵占命令窗口。 */
|
|
135
|
+
useLayoutEffect(function measureSpaceAroundInput() {
|
|
136
|
+
if (!fixedRef.current || !inputAreaRef.current)
|
|
137
|
+
return;
|
|
138
|
+
const approvalRows = approvalBoxRef.current ? measureElement(approvalBoxRef.current).height : 0;
|
|
139
|
+
const reserved = measureElement(fixedRef.current).height - measureElement(inputAreaRef.current).height + approvalRows;
|
|
140
|
+
setReservedInputRows(reserved);
|
|
141
|
+
});
|
|
119
142
|
// Ink 6 不支持 maxHeight;测量未收缩正文,给动态帧设置自然高度与窗口上限。
|
|
120
143
|
useLayoutEffect(function measureInlineLayout() {
|
|
121
144
|
if (isViewportMode || !inlineBodyRef.current || !fixedRef.current)
|
|
@@ -123,7 +146,6 @@ export function CliTuiApp(props) {
|
|
|
123
146
|
const height = measureElement(inlineBodyRef.current).height + measureElement(fixedRef.current).height + approvalCardHeight;
|
|
124
147
|
setInlineHeight(function update(previous) { return previous === height ? previous : height; });
|
|
125
148
|
});
|
|
126
|
-
const approvalBoxRef = useRef(null);
|
|
127
149
|
const [measuredFixedHeight, setMeasuredFixedHeight] = useState();
|
|
128
150
|
useLayoutEffect(function measureFixedLayout() {
|
|
129
151
|
if (!isViewportMode || !fixedRef.current)
|
|
@@ -156,10 +178,11 @@ export function CliTuiApp(props) {
|
|
|
156
178
|
viewportHeight,
|
|
157
179
|
stdout,
|
|
158
180
|
onCopyText: props.onCopyText,
|
|
181
|
+
onCopyError: function copyFailed() { props.store.addNotice("复制失败,请检查系统剪贴板后重试。"); },
|
|
159
182
|
});
|
|
160
183
|
derivedRef.current.handleTuiViewportKey = handleTuiViewportKey;
|
|
161
184
|
const selectedText = isViewportMode ? getTuiSelectedText(viewportLines, selection) : "";
|
|
162
|
-
const animationActive = snapshot.status === "running" && !snapshot.threadWait && props.visible !== false && isRawModeSupported && stdout.isTTY !== false && terminalFocused;
|
|
185
|
+
const animationActive = (snapshot.compacting || snapshot.status === "running" && !snapshot.threadWait) && props.visible !== false && isRawModeSupported && stdout.isTTY !== false && terminalFocused;
|
|
163
186
|
/** 把用户动作交给 Controller;结束后刷新状态栏并按投影结果打开对应 picker。 */
|
|
164
187
|
async function dispatchAction(action, prompt, preserveSkillPickerQuery = false) {
|
|
165
188
|
if (action.type === "exit") {
|
|
@@ -168,7 +191,7 @@ export function CliTuiApp(props) {
|
|
|
168
191
|
}
|
|
169
192
|
const answeringQuestion = action.type === "submit_prompt" && props.store.getSnapshot().status === "waiting_user_input";
|
|
170
193
|
const allowWhileRunning = action.type === "cancel_turn" || (action.type === "submit_prompt" || action.type === "open_permissions" || action.type === "set_permission_mode" || action.type === "open_model_picker" || action.type === "set_model" || action.type === "open_effort_picker" || action.type === "set_effort" || action.type === "list_jobs" || action.type === "show_job" || action.type === "read_job_output" || action.type === "stop_job") && isActiveTuiStatus(props.store.getSnapshot().status);
|
|
171
|
-
if (busy.current && !allowWhileRunning)
|
|
194
|
+
if (props.store.getSnapshot().compacting || busy.current && !allowWhileRunning)
|
|
172
195
|
return;
|
|
173
196
|
const isJobAction = action.type === "list_jobs" || action.type === "show_job" || action.type === "read_job_output" || action.type === "stop_job";
|
|
174
197
|
const jobGeneration = isJobAction ? ++jobRequestGeneration.current : undefined;
|
|
@@ -179,12 +202,17 @@ export function CliTuiApp(props) {
|
|
|
179
202
|
}
|
|
180
203
|
if (action.type === "approve")
|
|
181
204
|
props.store.recordApprovalSubmission(action.decision);
|
|
205
|
+
const hostApproval = action.type === "approve" && props.controller.hostApprovalFeedback;
|
|
206
|
+
if (hostApproval)
|
|
207
|
+
setApprovalFeedback("正在提交审批决定…");
|
|
208
|
+
else
|
|
209
|
+
setApprovalFeedback(undefined);
|
|
182
210
|
if (!allowWhileRunning)
|
|
183
211
|
busy.current = true;
|
|
184
212
|
// D2/D5:仅交互 TUI 在发送前把 @ 引用的工作区文件内容以 <system-reminder> 附加块并入 action.content;
|
|
185
213
|
// start/steer/queue/initial 四条 TUI 提交路径都经过此处,时间线与 Esc 恢复仍使用原文 prompt。
|
|
186
214
|
let dispatchedAction = action;
|
|
187
|
-
if (action.type === "submit_prompt" && !answeringQuestion && prompt && props.workspaceRoot) {
|
|
215
|
+
if (action.type === "submit_prompt" && !answeringQuestion && prompt && props.workspaceRoot && !props.controller.resolveFileMentionsInHost) {
|
|
188
216
|
const resolved = await resolveFileMentionContext(action.content, props.workspaceRoot);
|
|
189
217
|
for (const message of resolved.notices)
|
|
190
218
|
props.store.addNotice(message);
|
|
@@ -192,6 +220,8 @@ export function CliTuiApp(props) {
|
|
|
192
220
|
dispatchedAction = { ...action, content: resolved.content };
|
|
193
221
|
}
|
|
194
222
|
let result;
|
|
223
|
+
if (action.type === "compact")
|
|
224
|
+
props.store.setCompacting(true);
|
|
195
225
|
try {
|
|
196
226
|
result = await props.controller.dispatch(dispatchedAction);
|
|
197
227
|
}
|
|
@@ -206,11 +236,21 @@ export function CliTuiApp(props) {
|
|
|
206
236
|
};
|
|
207
237
|
}
|
|
208
238
|
finally {
|
|
239
|
+
if (action.type === "compact")
|
|
240
|
+
props.store.setCompacting(false);
|
|
209
241
|
if (!allowWhileRunning)
|
|
210
242
|
busy.current = false;
|
|
211
243
|
}
|
|
212
244
|
lastResult.current = result;
|
|
213
245
|
props.onResult(result);
|
|
246
|
+
if (hostApproval)
|
|
247
|
+
setApprovalFeedback(result.kind === "ok" && props.controller.getHostApprovalStatus ? undefined : result.lines[0] ?? result.message ?? "审批提交未确认,请核查原决定。");
|
|
248
|
+
const reportText = result.infoReport ?? result.lines.join("\n");
|
|
249
|
+
const dedicatedView = hostApproval || result.jobView || result.contextView || result.skillOptions || result.permissionOptions || result.modelOptions || result.effortOptions || jobViewRef.current || contextView || pickers.isPickerActive || props.store.getSnapshot().pendingApproval;
|
|
250
|
+
if (dedicatedView)
|
|
251
|
+
setInfoReport(undefined);
|
|
252
|
+
else if (result.infoReport || result.lines.length > 1 || reportText.includes("\n") || reportText.length > columns - 6)
|
|
253
|
+
setInfoReport({ text: reportText, offset: 0 });
|
|
214
254
|
if (result.jobView && jobGeneration === jobRequestGeneration.current) {
|
|
215
255
|
jobViewRef.current = result.jobView;
|
|
216
256
|
setJobView(result.jobView);
|
|
@@ -230,6 +270,8 @@ export function CliTuiApp(props) {
|
|
|
230
270
|
}
|
|
231
271
|
if (result.contextView)
|
|
232
272
|
setContextView(result.contextView);
|
|
273
|
+
if (result.hostRecordedPrompt && allowWhileRunning)
|
|
274
|
+
props.store.recordPrompt(result.hostRecordedPrompt, "history");
|
|
233
275
|
if (prompt && result.submittedInput)
|
|
234
276
|
props.store.addPendingPrompt(prompt, result.submittedInput, inputPosition);
|
|
235
277
|
await refreshStatusView();
|
|
@@ -305,7 +347,9 @@ export function CliTuiApp(props) {
|
|
|
305
347
|
pickers.updateApprovalPickerIndex(0);
|
|
306
348
|
setApprovalOffset(0);
|
|
307
349
|
setApprovalDetails(false);
|
|
308
|
-
|
|
350
|
+
if (snapshot.pendingApproval || hostStatus || snapshot.status !== "waiting_approval")
|
|
351
|
+
setApprovalFeedback(undefined);
|
|
352
|
+
}, [snapshot.pendingApproval?.approvalId, hostStatus, snapshot.status]);
|
|
309
353
|
useEffect(function disposeTuiAnimationClock() {
|
|
310
354
|
return function disposeAnimationClock() {
|
|
311
355
|
animationClock.dispose();
|
|
@@ -399,6 +443,23 @@ export function CliTuiApp(props) {
|
|
|
399
443
|
props.onAppExit(snapshot.requestedExitCode ?? lastResult.current?.exitCode ?? 0);
|
|
400
444
|
}
|
|
401
445
|
}, [props.closeWhenIdle, snapshot.status, snapshot.requestedExitCode]);
|
|
446
|
+
/** 长报告独占按键,Esc 只关闭报告;输入组件保持挂载以保留草稿。 */
|
|
447
|
+
useInput(function handleInfoReport(value, key) {
|
|
448
|
+
if (props.canReceiveInput?.(value, key) === false)
|
|
449
|
+
return;
|
|
450
|
+
if (!infoReport) {
|
|
451
|
+
if (key.ctrl && value === "g")
|
|
452
|
+
setInfoReport({ text: snapshot.transcript.filter(function notice(item) { return item.kind === "notice"; }).map(function message(item) { return item.message; }).join("\n\n") || "暂无提示", offset: 0 });
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
if (key.escape || value === "\u001b") {
|
|
456
|
+
setInfoReport(undefined);
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
const delta = key.pageDown ? reportHeight : key.pageUp ? -reportHeight : key.downArrow ? 1 : key.upArrow ? -1 : 0;
|
|
460
|
+
if (delta)
|
|
461
|
+
setInfoReport({ ...infoReport, offset: Math.max(0, Math.min(reportMaximum, reportOffset + delta)) });
|
|
462
|
+
}, { isActive: inputEnabled && isRawModeSupported && (infoReport !== undefined || !jobView && !contextView && !pickers.isPickerActive && !snapshot.pendingApproval) });
|
|
402
463
|
/** 在 Job 视图内复用 Ink 输入路由;Esc 只返回视图,不取消 Turn 或退出进程。 */
|
|
403
464
|
useInput(function handleJobInput(value, key) {
|
|
404
465
|
if (props.canReceiveInput?.(value, key) === false)
|
|
@@ -439,7 +500,7 @@ export function CliTuiApp(props) {
|
|
|
439
500
|
void dispatchAction({ type: "stop_job", jobId: current.job.jobId });
|
|
440
501
|
else if (value === "r")
|
|
441
502
|
void dispatchAction({ type: current.output ? "read_job_output" : "show_job", jobId: current.job.jobId });
|
|
442
|
-
}, { isActive: inputEnabled && isRawModeSupported && jobView !== undefined });
|
|
503
|
+
}, { isActive: inputEnabled && isRawModeSupported && jobView !== undefined && !infoReport });
|
|
443
504
|
/** 在 Context 覆盖视图内复用 Ink 输入路由;Esc 只关闭视图回到聊天,不取消 Turn 或退出进程。 */
|
|
444
505
|
useInput(function handleContextInput(value, key) {
|
|
445
506
|
if (props.canReceiveInput?.(value, key) === false)
|
|
@@ -448,19 +509,22 @@ export function CliTuiApp(props) {
|
|
|
448
509
|
return;
|
|
449
510
|
if (key.escape || value === "\u001b")
|
|
450
511
|
setContextView(undefined);
|
|
451
|
-
}, { isActive: inputEnabled && isRawModeSupported && contextView !== undefined });
|
|
512
|
+
}, { isActive: inputEnabled && isRawModeSupported && contextView !== undefined && !infoReport });
|
|
452
513
|
// Ctrl+O 只切换 Todo 展开视图;picker 与审批等待打开时让位,避免按键语义冲突。
|
|
453
514
|
useInput(function handleTodoExpandInput(input, key) {
|
|
454
515
|
if (props.canReceiveInput?.(input, key) === false)
|
|
455
516
|
return;
|
|
456
517
|
if (key.ctrl && input === "o")
|
|
457
518
|
setTodoExpanded(function toggleTodoExpanded(previous) { return !previous; });
|
|
458
|
-
}, { isActive: inputEnabled && isRawModeSupported && !pickers.isPickerActive && !snapshot.pendingApproval });
|
|
519
|
+
}, { isActive: inputEnabled && isRawModeSupported && !pickers.isPickerActive && !snapshot.pendingApproval && !infoReport });
|
|
459
520
|
const isLiveTurnTerminal = Boolean(snapshot.liveTurnId && isTerminalStatus(snapshot.status));
|
|
521
|
+
const archiveActivePrompt = Boolean(snapshot.activePrompt?.turnId && snapshot.activePrompt.turnId === snapshot.liveTurnId && (snapshot.status === "completed" || snapshot.status === "failed"));
|
|
460
522
|
const inlineHistoryItems = isViewportMode ? [] : [
|
|
461
523
|
TUI_BRAND_HISTORY_ITEM,
|
|
462
524
|
...snapshot.transcript.filter(function selectInlineHistoryItem(item) {
|
|
463
525
|
if (item.kind === "notice")
|
|
526
|
+
return item.persistent === true;
|
|
527
|
+
if (item.kind === "prompt" && item.key === snapshot.activePrompt?.key && !archiveActivePrompt)
|
|
464
528
|
return false;
|
|
465
529
|
if (item.kind === "turn")
|
|
466
530
|
return item.turnId !== snapshot.liveTurnId || isLiveTurnTerminal;
|
|
@@ -476,10 +540,10 @@ export function CliTuiApp(props) {
|
|
|
476
540
|
} };
|
|
477
541
|
}
|
|
478
542
|
return { key: `${props.inlineOutputKey ?? "session"}:${item.key}`, node: item.kind === "brand"
|
|
479
|
-
? _jsx(TuiBrandHeader, {
|
|
543
|
+
? _jsx(TuiBrandHeader, { columns: columns, useColor: props.useColor, screenReader: props.screenReader, reducedMotion: true, animationActive: false })
|
|
480
544
|
: _jsx(MemoizedTuiTranscriptItem, { item: item, columns: columns, useColor: props.useColor, screenReader: props.screenReader }) };
|
|
481
545
|
});
|
|
482
|
-
return (_jsxs(_Fragment, { children: [!isViewportMode ? _jsx(TuiInlineOutput, { items: inlineOutput }) : null, _jsxs(Box, { flexDirection: "column", width: columns, height: isViewportMode ? rows : Math.max(1, Math.min(inlineHeight ??
|
|
483
|
-
return item.delivery === "queue" ? _jsx(TuiPendingInputItem, { item: item, useColor: props.useColor }, item.key) : null;
|
|
484
|
-
})] }) }) }), !isViewportMode && snapshot.pendingApproval ? _jsx(TuiApprovalPrompt, { height: approvalCardHeight, offset: approvalOffset, onMaximumOffset: function rememberMaximum(maximum) { approvalMaximumRef.current = maximum; }, details: approvalDetails, pendingApproval: snapshot.pendingApproval, selectedIndex: pickers.approvalPickerIndex, useColor: props.useColor, screenReader: props.screenReader }) : null, _jsxs(Box, { ref: fixedRef, flexDirection: "column", flexShrink: 0, children: [_jsx(TuiActivityLine, { threadWait: snapshot.threadWait, activity: snapshot.activity, status: snapshot.status, waitingForApproval: snapshot.pendingApproval !== undefined, useColor: props.useColor, screenReader: props.screenReader, reducedMotion: props.reducedMotion ?? false, animationActive: animationActive, clock: animationClock, runningSince: snapshot.liveMetrics?.runningSince, activeForm: activeTodoForm }), _jsx(Box, { height: infoMessages.length ? 2 : 0, overflow: "hidden", children: _jsx(TuiInfoLines, { messages: infoMessages, useColor: props.useColor }) }), _jsx(TuiInputArea, { draftRef: props.viewState?.draftRef, store: props.store, columns: columns, maximumPromptRows: Math.max(1, Math.min(4, rows - approvalCardHeight -
|
|
546
|
+
return (_jsxs(_Fragment, { children: [!isViewportMode ? _jsx(TuiInlineOutput, { items: inlineOutput }) : null, _jsxs(Box, { flexDirection: "column", width: columns, height: isViewportMode ? rows : Math.max(1, Math.min(inlineHeight ?? maximumFrameRows, maximumFrameRows)), overflow: "hidden", "aria-role": "list", children: [_jsx(Box, { flexDirection: "column", flexGrow: 1, flexShrink: 1, overflow: "hidden", justifyContent: !isViewportMode && !jobView && !contextView && !infoReport ? "flex-end" : "flex-start", children: _jsx(Box, { ref: inlineBodyRef, position: isViewportMode ? "relative" : "absolute", width: columns, flexDirection: "column", flexShrink: 0, children: infoReport ? _jsxs(Box, { flexDirection: "column", width: columns, children: [reportLines.slice(reportOffset, reportOffset + reportHeight).map(function line(text, index) { return _jsx(Text, { children: text || " " }, index); }), _jsxs(Text, { dimColor: props.useColor, children: ["Esc \u8FD4\u56DE\u804A\u5929 \u00B7 \u2191\u2193 / PgUp PgDn \u00B7 ", reportOffset + 1, "/", reportLines.length] })] }) : jobView ? _jsx(TuiJobs, { view: jobView, selectedIndex: jobSelectedIndex, useColor: props.useColor, screenReader: props.screenReader }) : contextView ? _jsx(TuiContextReport, { usage: contextView.usage, expanded: contextView.expanded, columns: columns, useColor: props.useColor, screenReader: props.screenReader }) : isViewportMode ? _jsxs(_Fragment, { children: [_jsx(TuiViewportTimeline, { lines: viewportLines, state: viewportState, columns: columns, useColor: props.useColor, selection: selection }), snapshot.pendingApproval ? _jsx(Box, { ref: approvalBoxRef, flexDirection: "column", flexShrink: 0, children: _jsx(TuiApprovalPrompt, { height: approvalCardHeight, offset: approvalOffset, onMaximumOffset: function rememberMaximum(maximum) { approvalMaximumRef.current = maximum; }, details: approvalDetails, pendingApproval: snapshot.pendingApproval, selectedIndex: pickers.approvalPickerIndex, useColor: props.useColor, screenReader: props.screenReader }) }) : null] }) : _jsxs(Box, { flexDirection: "column", flexShrink: 0, children: [snapshot.activePrompt && !archiveActivePrompt ? _jsx(TuiPromptLine, { content: snapshot.activePrompt.content, keyValue: snapshot.activePrompt.key, columns: columns, useColor: props.useColor }) : null, _jsx(TuiLiveTurn, { turnId: isLiveTurnTerminal ? undefined : snapshot.liveTurnId, events: snapshot.liveEvents, presentation: snapshot.livePresentation, pendingApproval: undefined, approvalSelectedIndex: pickers.approvalPickerIndex, status: snapshot.status, metrics: snapshot.liveMetrics, useColor: props.useColor, screenReader: props.screenReader, todoExpanded: todoExpanded, todoRowLimit: todoRowLimit, maximumWidth: Math.max(1, columns - 2) }), snapshot.pendingInputs.map(function renderPendingInput(item) {
|
|
547
|
+
return item.delivery === "queue" ? _jsx(TuiPendingInputItem, { item: item, useColor: props.useColor, columns: columns }, item.key) : null;
|
|
548
|
+
})] }) }) }), !isViewportMode && snapshot.pendingApproval ? _jsx(Box, { ref: approvalBoxRef, flexDirection: "column", flexShrink: 0, children: _jsx(TuiApprovalPrompt, { height: approvalCardHeight, offset: approvalOffset, onMaximumOffset: function rememberMaximum(maximum) { approvalMaximumRef.current = maximum; }, details: approvalDetails, pendingApproval: snapshot.pendingApproval, selectedIndex: pickers.approvalPickerIndex, useColor: props.useColor, screenReader: props.screenReader }) }) : null, _jsxs(Box, { ref: fixedRef, flexDirection: "column", flexShrink: 0, children: [_jsx(TuiActivityLine, { compacting: snapshot.compacting, threadWait: snapshot.threadWait, activity: snapshot.activity, status: snapshot.status, waitingForApproval: snapshot.pendingApproval !== undefined, useColor: props.useColor, screenReader: props.screenReader, reducedMotion: props.reducedMotion ?? false, animationActive: animationActive, clock: animationClock, runningSince: snapshot.liveMetrics?.runningSince, activeForm: activeTodoForm }), approvalFeedback && _jsx(Text, { wrap: "truncate", children: approvalFeedback }), _jsx(Box, { height: !infoReport && infoMessages.length ? 2 : 0, overflow: "hidden", children: _jsx(TuiInfoLines, { columns: columns, messages: infoMessages, useColor: props.useColor }) }), _jsx(Box, { ref: inputAreaRef, flexDirection: "column", flexShrink: 0, children: _jsx(TuiInputArea, { parseInput: props.controller.parseInput, suggestSlashCommands: props.controller.suggestSlashCommands, draftRef: props.viewState?.draftRef, store: props.store, columns: columns, availableRows: maximumFrameRows - reservedInputRows, maximumPromptRows: Math.max(1, Math.min(4, rows - approvalCardHeight - statusHeight - 6)), busy: busy, keepOpenAfterCancel: keepOpenAfterCancel, lastSubmittedPromptRef: lastSubmittedPromptRef, rawInputSequenceRef: rawInputSequenceRef, dispatchAction: dispatchAction, onEof: props.onEof, onRequestInterrupt: props.onRequestInterrupt, onRequestCancel: props.onRequestCancel, isRawModeSupported: isRawModeSupported, isInputActive: inputEnabled && jobView === undefined && contextView === undefined && infoReport === undefined, canReceiveInput: props.canReceiveInput, bindInputHandler: props.bindInputHandler, onAttachmentsChange: props.onDraftAttachmentsChange, showInput: jobView === undefined && contextView === undefined && infoReport === undefined, useColor: props.useColor, screenReader: props.screenReader, pickers: pickers, derivedRef: derivedRef, fileMentionIndex: snapshot.status === "waiting_user_input" ? { entries: [], ready: false } : fileMentionIndex, onLayoutChange: handleInputLayoutChange }) }), _jsx(TuiStatusLine, { snapshot: snapshot, statusView: statusView, interactionLabel: hostStatus ?? props.interactionLabel, sessionTitle: props.sessionTitle, useColor: props.useColor, screenReader: props.screenReader, selectionCharacters: selectedText.length, escapeClosesPanel: props.escapeClosesPanel })] })] })] }));
|
|
485
549
|
}
|
package/dist/tui/approval.js
CHANGED
|
@@ -43,7 +43,7 @@ export function TuiApprovalPrompt(props) {
|
|
|
43
43
|
if (contentRef.current && viewportRef.current)
|
|
44
44
|
props.onMaximumOffset?.(Math.max(0, measureElement(contentRef.current).height - measureElement(viewportRef.current).height));
|
|
45
45
|
});
|
|
46
|
-
return (_jsxs(Box, { height: props.height, flexShrink: 0, overflow: "hidden", borderStyle: "single", borderColor: props.useColor ? TUI_ACCENT_COLOR : undefined, paddingX: 1, flexDirection: "column", children: [_jsx(Box, { ref: viewportRef, height: props.height === undefined ? undefined : Math.max(1, props.height - options.length - 3), flexDirection: "column", overflow: "hidden", flexShrink: 0, children: _jsxs(Box, { ref: contentRef, flexDirection: "column", flexShrink: 0, marginTop: -(props.offset ?? 0), children: [_jsx(Text, { bold: true, color: props.useColor ? TUI_ACCENT_COLOR : undefined, children: "\u9700\u8981\u4F60\u7684\u786E\u8BA4" }), _jsxs(Text, { children: ["\u64CD\u4F5C\uFF1A", props.pendingApproval.display?.operation ?? getTuiToolLabel(props.pendingApproval.toolName)] }), _jsxs(Text, { children: ["\u539F\u56E0\uFF1A", props.pendingApproval.reason] }), props.pendingApproval.display?.resource ? _jsxs(Text, { children: ["\u5F71\u54CD\uFF1A", props.pendingApproval.display.resource] }) : null, props.pendingApproval.display?.cwd ? _jsxs(Text, { children: ["\u5DE5\u4F5C\u76EE\u5F55\uFF1A", props.pendingApproval.display.cwd] }) : null, props.pendingApproval.display?.effect === "external" && props.pendingApproval.display?.hostExecution === true ? (_jsx(Text, { color: props.useColor ? TUI_ACCENT_COLOR : undefined, children: "\u26A0 \
|
|
46
|
+
return (_jsxs(Box, { height: props.height, flexShrink: 0, overflow: "hidden", borderStyle: "single", borderColor: props.useColor ? TUI_ACCENT_COLOR : undefined, paddingX: 1, flexDirection: "column", children: [_jsx(Box, { ref: viewportRef, height: props.height === undefined ? undefined : Math.max(1, props.height - options.length - 3), flexDirection: "column", overflow: "hidden", flexShrink: 0, children: _jsxs(Box, { ref: contentRef, flexDirection: "column", flexShrink: 0, marginTop: -(props.offset ?? 0), children: [_jsx(Text, { bold: true, color: props.useColor ? TUI_ACCENT_COLOR : undefined, children: "\u9700\u8981\u4F60\u7684\u786E\u8BA4" }), _jsxs(Text, { children: ["\u64CD\u4F5C\uFF1A", props.pendingApproval.display?.operation ?? getTuiToolLabel(props.pendingApproval.toolName)] }), _jsxs(Text, { children: ["\u539F\u56E0\uFF1A", props.pendingApproval.reason] }), props.pendingApproval.display?.resource ? _jsxs(Text, { children: ["\u5F71\u54CD\uFF1A", props.pendingApproval.display.resource] }) : null, props.pendingApproval.display?.cwd ? _jsxs(Text, { children: ["\u5DE5\u4F5C\u76EE\u5F55\uFF1A", props.pendingApproval.display.cwd] }) : null, props.pendingApproval.display?.effect === "external" && props.pendingApproval.display?.hostExecution === true ? (_jsx(Text, { color: props.useColor ? TUI_ACCENT_COLOR : undefined, children: "\u26A0 \u6267\u884C\u8303\u56F4\u672A\u9650\u5B9A\uFF1A\u5BBF\u4E3B\u8FDB\u7A0B\u4E0D\u53D7\u6587\u4EF6\u8303\u56F4\u9694\u79BB\uFF0C\u53EF\u80FD\u5F71\u54CD\u5176\u4ED6\u6587\u4EF6\uFF1B\u8BF7\u5BA1\u67E5\u5B8C\u6574\u547D\u4EE4\uFF0C\u6279\u51C6\u4E0D\u6784\u6210\u7CBE\u786E\u8303\u56F4\u4FDD\u8BC1" })) : null, props.pendingApproval.display?.effect === "external" && props.pendingApproval.display?.hostExecution !== true && props.pendingApproval.display?.unknownScope ? (_jsx(Text, { color: props.useColor ? TUI_ACCENT_COLOR : undefined, children: "\u26A0 \u4FEE\u6539\u8303\u56F4\u65E0\u6CD5\u7CBE\u786E\u9650\u5B9A\uFF1A\u8BE5\u547D\u4EE4\u672A\u58F0\u660E\u7CBE\u786E\u5916\u90E8\u76EE\u6807\uFF0C\u8BF7\u5BA1\u67E5\u5B8C\u6574\u547D\u4EE4\u540E\u518D\u51B3\u5B9A" })) : null, props.pendingApproval.toolName !== "browser" && props.pendingApproval.display?.effect === "external" && props.pendingApproval.display?.hostExecution !== true && !props.pendingApproval.display?.unknownScope ? (_jsx(Text, { color: props.useColor ? TUI_ACCENT_COLOR : undefined, children: "\u26A0 \u5916\u90E8\u8DEF\u5F84\uFF1A\u76EE\u6807\u4F4D\u4E8E\u5DE5\u4F5C\u533A\u4E4B\u5916\uFF0C\u6388\u6743\u4EC5\u8986\u76D6\u4E0A\u8FF0\u7CBE\u786E\u76EE\u6807" })) : null, props.pendingApproval.display?.hostExecution === true ? (_jsx(Text, { color: props.useColor ? TUI_ACCENT_COLOR : undefined, children: "Windows \u5BBF\u4E3B\u6267\u884C\uFF1A\u672C\u6B21\u547D\u4EE4\u5C06\u5728\u5F53\u524D\u7528\u6237\u6743\u9650\u4E0B\u76F4\u63A5\u8FD0\u884C\uFF0C\u672A\u542F\u7528\u6C99\u7BB1\u9694\u79BB\uFF1B\u6279\u51C6\u4EC5\u5BF9\u672C\u6B21\u8C03\u7528\u6709\u6548\uFF0C\u62D2\u7EDD\u5219\u4E0D\u6267\u884C" })) : null, props.pendingApproval.toolName === "run_command" && options.some(function hasWorkspaceOption(option) { return option.decision === "allow_workspace"; }) ? (_jsx(Text, { dimColor: props.useColor, children: "\u9009\u62E9\u201C\u8BB0\u4F4F\u6B64\u547D\u4EE4\u201D\u4F1A\u8BB0\u4F4F\u672C\u6761\u547D\u4EE4\uFF08\u7A0B\u5E8F\u3001\u53C2\u6570\u4E0E\u5DE5\u4F5C\u76EE\u5F55\u5B8C\u5168\u4E00\u81F4\uFF09\uFF0C\u6B64\u540E\u5728\u672C\u5DE5\u4F5C\u533A\u81EA\u52A8\u653E\u884C\uFF1B\u53C2\u6570\u6216\u76EE\u5F55\u4E0D\u540C\u7684\u547D\u4EE4\u4ECD\u4F1A\u91CD\u65B0\u8BE2\u95EE" })) : null, props.pendingApproval.constraint === "task-ext-files:v1" ? (_jsx(Text, { color: props.useColor ? TUI_ACCENT_COLOR : undefined, children: "\u26A0 \u5916\u90E8\u8DEF\u5F84\uFF1A\u76EE\u6807\u4F4D\u4E8E\u5DE5\u4F5C\u533A\u4E4B\u5916\uFF0C\u4E0E\u5DE5\u4F5C\u533A\u6587\u4EF6\u96C6\u5408\u5206\u5F00\u5355\u72EC\u6279\u51C6\uFF1B\u6388\u6743\u4EC5\u8986\u76D6\u6E05\u5355\u5185\u7CBE\u786E\u6587\u4EF6\uFF0C\u4E0D\u542B\u7236\u76EE\u5F55\u6216\u9012\u5F52\u6743\u9650" })) : null, props.pendingApproval.toolName === "todo_write" && props.pendingApproval.constraint !== "task-ext-files:v1" && options.some(function hasOnceOption(option) { return option.decision === "allow_once"; }) ? (_jsx(Text, { dimColor: props.useColor, children: "\u6279\u51C6\u540E\uFF0C\u672C\u4EFB\u52A1\u5185\u5BF9\u6E05\u5355\u5185\u6587\u4EF6\u7684\u5BF9\u5E94\u4FEE\u6539\u5C06\u81EA\u52A8\u653E\u884C\uFF1B\u6E05\u5355\u5916\u7684\u65B0\u6587\u4EF6\u4ECD\u4F1A\u9010\u6B21\u8BE2\u95EE\uFF1B\u6388\u6743\u4EC5\u8986\u76D6\u5F53\u524D\u4EFB\u52A1" })) : null, props.pendingApproval.constraint === "task-ext-files:v1" && options.some(function hasOnceOption(option) { return option.decision === "allow_once"; }) ? (_jsx(Text, { dimColor: props.useColor, children: "\u6279\u51C6\u540E\uFF0C\u672C\u4EFB\u52A1\u5185\u5BF9\u6E05\u5355\u5185\u7CBE\u786E\u6587\u4EF6\u7684\u5BF9\u5E94\u4FEE\u6539\u5C06\u81EA\u52A8\u653E\u884C\uFF1B\u6E05\u5355\u5916\u76EE\u6807\u4ECD\u9010\u6B21\u8BE2\u95EE\uFF1B\u6388\u6743\u4EC5\u8986\u76D6\u5F53\u524D\u4EFB\u52A1\uFF0C\u65B0\u76EE\u5F55\u6216\u65B0\u6587\u4EF6\u4E0D\u4F1A\u56E0\u6B64\u83B7\u5F97\u6388\u6743" })) : null, props.pendingApproval.constraint === "no-sandbox-exec:v1" ? (_jsx(Text, { color: props.useColor ? "yellow" : undefined, children: "\u6C99\u7BB1\u542F\u52A8\u5931\u8D25\uFF1A\u672C\u6B21\u5C06\u65E0\u6C99\u7BB1\u9694\u79BB\u76F4\u63A5\u6267\u884C\u4E0A\u8FF0\u547D\u4EE4\uFF1B\u6279\u51C6\u4EC5\u5BF9\u672C\u6B21\u8C03\u7528\u6709\u6548\uFF0C\u62D2\u7EDD\u5219\u4EFB\u52A1\u505C\u6B62" })) : null, props.pendingApproval.display?.effect === "external" && props.pendingApproval.toolName !== "run_command" && options.some(function hasWorkspaceOption(option) { return option.decision === "allow_workspace"; }) ? (_jsx(Text, { dimColor: props.useColor, children: "\u9009\u62E9\u201C\u6B64\u5DE5\u4F5C\u533A\u5141\u8BB8\u201D\u5C06\u628A\u8BE5\u89C4\u5219\u5199\u5165\u5DE5\u4F5C\u533A .autopilot/settings.local.json" })) : null, props.details && props.pendingApproval.display?.actionPreview && props.pendingApproval.display.actionPreview !== props.pendingApproval.reason ? _jsx(Text, { children: props.pendingApproval.display.actionPreview }) : null] }) }), options.map(function renderApprovalOption(option, index) {
|
|
47
47
|
const selected = index === selectedIndex;
|
|
48
48
|
return _jsxs(Text, { wrap: "truncate", inverse: selected && props.useColor, children: [selected ? "›" : " ", " ", option.label, selected && props.screenReader ? "(已选择)" : ""] }, option.decision);
|
|
49
49
|
}), _jsx(Text, { wrap: "truncate", dimColor: props.useColor, children: "\u2191/\u2193 \u9009\u62E9 \u00B7 Enter \u786E\u8BA4 \u00B7 PgUp/PgDn\u8BE6\u60C5" })] }));
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** 顶部品牌头:静态像素图形与 Autopilot 版本。 */
|
|
2
2
|
import { type ReactNode } from "react";
|
|
3
|
-
import type { CliStatusView } from "../../types.js";
|
|
4
3
|
import type { CliTuiTranscriptItem } from "../types.js";
|
|
5
4
|
/** 内联历史项标记:用于把品牌头和 transcript 放入同一棵可重排的渲染树。 */
|
|
6
5
|
export declare const TUI_BRAND_HISTORY_ITEM: {
|
|
@@ -11,7 +10,6 @@ export declare const TUI_BRAND_HISTORY_ITEM: {
|
|
|
11
10
|
export type TuiInlineHistoryItem = typeof TUI_BRAND_HISTORY_ITEM | CliTuiTranscriptItem;
|
|
12
11
|
/** 渲染顶部品牌头。 */
|
|
13
12
|
export declare function TuiBrandHeader(props: {
|
|
14
|
-
statusView?: CliStatusView;
|
|
15
13
|
columns: number;
|
|
16
14
|
useColor: boolean;
|
|
17
15
|
screenReader: boolean;
|
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
/** 顶部品牌头:静态像素字标 + Autopilot 版本/模型/推理强度信息。 */
|
|
3
|
-
import { WEB_SEARCH_DATA_FLOW_NOTICE } from "@autopilot-agent/presentation";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
2
|
import { Box, Text } from "ink";
|
|
5
3
|
import { CLI_TUI_COLORS } from "../../design-tokens.js";
|
|
6
4
|
import { AUTOPILOT_VERSION } from "../constants.js";
|
|
7
5
|
import { createAutopilotStaticWordRows, renderAutopilotColoredRows } from "./pixel.js";
|
|
6
|
+
import { createAgentLogoRows } from "./logo.js";
|
|
8
7
|
/** 内联历史项标记:用于把品牌头和 transcript 放入同一棵可重排的渲染树。 */
|
|
9
8
|
export const TUI_BRAND_HISTORY_ITEM = { kind: "brand", key: "brand" };
|
|
10
|
-
/**
|
|
9
|
+
/** 将 Logo 与原尺寸字标并排输出,让各终端共用同一横幅。 */
|
|
11
10
|
function renderAutopilotStaticWord(useColor, columns) {
|
|
12
|
-
const
|
|
11
|
+
const logo = createAgentLogoRows(14, 7);
|
|
12
|
+
const rows = createAutopilotStaticWordRows().map(function addLogo(row, index) { return `${logo[index]} ${row}`; });
|
|
13
13
|
return renderAutopilotColoredRows(rows, function colorStaticWord(char) {
|
|
14
14
|
return useColor && char !== " " ? CLI_TUI_COLORS.copilotBlue : undefined;
|
|
15
15
|
}, columns);
|
|
16
16
|
}
|
|
17
17
|
/** 渲染顶部品牌头。 */
|
|
18
18
|
export function TuiBrandHeader(props) {
|
|
19
|
-
|
|
20
|
-
const effort = props.statusView?.effort ?? "runtime default";
|
|
21
|
-
return (_jsxs(Box, { flexDirection: "column", marginTop: 1, marginBottom: 1, width: props.columns, children: [renderAutopilotStaticWord(props.useColor, props.columns), _jsxs(Box, { marginTop: 1, marginLeft: 2, flexDirection: "column", alignItems: "flex-start", children: [_jsxs(Text, { bold: true, color: props.useColor ? CLI_TUI_COLORS.copilotBlue : undefined, children: ["Autopilot ", _jsxs(Text, { color: props.useColor ? CLI_TUI_COLORS.copilotInk : undefined, children: ["v", AUTOPILOT_VERSION] })] }), _jsxs(Text, { color: props.useColor ? CLI_TUI_COLORS.copilotMuted : undefined, children: ["Model ", model] }), _jsxs(Text, { color: props.useColor ? CLI_TUI_COLORS.copilotMuted : undefined, children: ["Thinking ", effort] }), _jsx(Text, { color: props.useColor ? CLI_TUI_COLORS.copilotMuted : undefined, children: WEB_SEARCH_DATA_FLOW_NOTICE })] })] }));
|
|
19
|
+
return (_jsxs(Box, { flexDirection: "column", marginTop: 1, marginBottom: 1, width: props.columns, children: [props.screenReader ? _jsx(Text, { children: "Autopilot" }) : renderAutopilotStaticWord(props.useColor, props.columns), _jsx(Box, { marginTop: 1, marginLeft: 2, flexDirection: "column", alignItems: "flex-start", children: _jsxs(Text, { bold: true, color: props.useColor ? CLI_TUI_COLORS.copilotBlue : undefined, children: ["Autopilot ", _jsxs(Text, { color: props.useColor ? CLI_TUI_COLORS.copilotInk : undefined, children: ["v", AUTOPILOT_VERSION] })] }) })] }));
|
|
22
20
|
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/** Desktop agent-light.svg 的 64×64 单色采样,转为终端 Braille 点阵,无运行期图片依赖。 */
|
|
2
|
+
const LOGO_MASK = [
|
|
3
|
+
"0000000000000000000000000000000000000000000000000000000000000000",
|
|
4
|
+
"0000000000000000000000000000000000000000000000000000000000000000",
|
|
5
|
+
"0000000000000000000000000000000000000000000000000000000000000000",
|
|
6
|
+
"0000000000000000000000000000001111000000000000000000000000000000",
|
|
7
|
+
"0000000000000000000000000000011111100000000000000000000000000000",
|
|
8
|
+
"0000000000000000000000000000011111100000000000000000000000000000",
|
|
9
|
+
"0000000000011110000000000000111111110000000000000000000000000000",
|
|
10
|
+
"0000000000011111000000000000111111110000000000000000000000000000",
|
|
11
|
+
"0000000000111111000000000000111111110000000000000000000000000000",
|
|
12
|
+
"0000000000111111000000000000111111110000000000000000000000000000",
|
|
13
|
+
"0000000011111111111000000001111111111000000000000000000000000000",
|
|
14
|
+
"0000001111111111111100000001111111111000000000000000000000000000",
|
|
15
|
+
"0000001111111111111110000001111111111000000000000000000000000000",
|
|
16
|
+
"0000001111111111111110000001111111111000000000000000000000000000",
|
|
17
|
+
"0000001111111111111100000011111111111100000000000000000000000000",
|
|
18
|
+
"0000000111111111111000000011111111111100000000000000000000000000",
|
|
19
|
+
"0000000000111111000000000011111111111100000000000000000000000000",
|
|
20
|
+
"0000000000111111000000000011111001111100000000000000000000000000",
|
|
21
|
+
"0000000000011111000000000111111001111110000000000000000000000000",
|
|
22
|
+
"0000000000011110000000000111111001111110000000000000000000000000",
|
|
23
|
+
"0000000000001100000000000111111001111110000000000000000000000000",
|
|
24
|
+
"0000000000000000000000000111111001111110000000000000000000000000",
|
|
25
|
+
"0000000000000000000000001111110000111111000000000000000000000000",
|
|
26
|
+
"0000000000000000000000001111110000111111000000000000000000000000",
|
|
27
|
+
"0000000000000000000000111111110000111111110000000000000000000000",
|
|
28
|
+
"0000000000000000001111111111100000011111111111000000000000000000",
|
|
29
|
+
"0000000000000011111111111111100000011111111111111100000000000000",
|
|
30
|
+
"0000000000111111111111111111000000001111111111111111110000000000",
|
|
31
|
+
"0000001111111111111111111110000000000111111111111111111111000000",
|
|
32
|
+
"0000111111111111111111111000000000000001111111111111111111110000",
|
|
33
|
+
"0001111111111111111111000000000000000000001111111111111111111000",
|
|
34
|
+
"0001111111111111100000000000000000000000000000011111111111111000",
|
|
35
|
+
"0001111111111111100000000000000000000000000000011111111111111000",
|
|
36
|
+
"0001111111111111111111000000000000000000000111111111111111111000",
|
|
37
|
+
"0000111111111111111111111000000000000001111111111111111111110000",
|
|
38
|
+
"0000001111111111111111111110000000000111111111111111111111000000",
|
|
39
|
+
"0000000000111111111111111111000000001111111111111111110000000000",
|
|
40
|
+
"0000000000000011111111111111100000011111111111111100000000000000",
|
|
41
|
+
"0000000000000000001111111111100000011111111111000000000000000000",
|
|
42
|
+
"0000000000000000000000111111110000111111110000000000000000000000",
|
|
43
|
+
"0000000000000000000000001111110000111111000000000000000000000000",
|
|
44
|
+
"0000000000000000000000001111110000111111000000000000000000000000",
|
|
45
|
+
"0000000000000000000000000111110001111110000000000000000000000000",
|
|
46
|
+
"0000000000000000000000000111111001111110000000000011000000000000",
|
|
47
|
+
"0000000000000000000000000111111001111110000000000111100000000000",
|
|
48
|
+
"0000000000000000000000000111111001111110000000001111100000000000",
|
|
49
|
+
"0000000000000000000000000011111001111100000000001111110000000000",
|
|
50
|
+
"0000000000000000000000000011111111111100000000001111110000000000",
|
|
51
|
+
"0000000000000000000000000011111111111100000001111111111110000000",
|
|
52
|
+
"0000000000000000000000000011111111111100000011111111111111000000",
|
|
53
|
+
"0000000000000000000000000001111111111000000111111111111111000000",
|
|
54
|
+
"0000000000000000000000000001111111111000000111111111111111000000",
|
|
55
|
+
"0000000000000000000000000001111111111000000011111111111111000000",
|
|
56
|
+
"0000000000000000000000000001111111111000000000111111111100000000",
|
|
57
|
+
"0000000000000000000000000000111111110000000000001111110000000000",
|
|
58
|
+
"0000000000000000000000000000111111110000000000001111110000000000",
|
|
59
|
+
"0000000000000000000000000000111111110000000000001111100000000000",
|
|
60
|
+
"0000000000000000000000000000111111110000000000000111100000000000",
|
|
61
|
+
"0000000000000000000000000000011111100000000000000000000000000000",
|
|
62
|
+
"0000000000000000000000000000011111100000000000000000000000000000",
|
|
63
|
+
"0000000000000000000000000000001111000000000000000000000000000000",
|
|
64
|
+
"0000000000000000000000000000000000000000000000000000000000000000",
|
|
65
|
+
"0000000000000000000000000000000000000000000000000000000000000000",
|
|
66
|
+
"0000000000000000000000000000000000000000000000000000000000000000",
|
|
67
|
+
];
|
|
68
|
+
/** 按字符网格采样原图,每个 Braille 字符承载 2×4 个点。 */
|
|
69
|
+
export function createAgentLogoRows(width, height) {
|
|
70
|
+
const rows = [];
|
|
71
|
+
const bits = [[0, 3], [1, 4], [2, 5], [6, 7]];
|
|
72
|
+
for (let row = 0; row < height; row += 1) {
|
|
73
|
+
let line = "";
|
|
74
|
+
for (let column = 0; column < width; column += 1) {
|
|
75
|
+
let dots = 0;
|
|
76
|
+
for (let y = 0; y < 4; y += 1) {
|
|
77
|
+
for (let x = 0; x < 2; x += 1) {
|
|
78
|
+
const sourceY = Math.min(63, Math.floor((row * 4 + y + 0.5) * 64 / (height * 4)));
|
|
79
|
+
const sourceX = Math.min(63, Math.floor((column * 2 + x + 0.5) * 64 / (width * 2)));
|
|
80
|
+
if (LOGO_MASK[sourceY]?.[sourceX] === "1")
|
|
81
|
+
dots |= 1 << bits[y][x];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
line += dots ? String.fromCharCode(0x2800 + dots) : " ";
|
|
85
|
+
}
|
|
86
|
+
rows.push(line);
|
|
87
|
+
}
|
|
88
|
+
return rows;
|
|
89
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** 启动临时品牌画面,与本地初始化并行,退出时只擦除本次 Ink 动态帧。 */
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
|
+
import type { TuiOutputStream } from "../types.js";
|
|
4
|
+
/** 居中显示等比例点阵,小网格和读屏使用稳定文字,灰白扫光只提供装饰。 */
|
|
5
|
+
export declare function TuiStartupLogo(props: {
|
|
6
|
+
columns: number;
|
|
7
|
+
rows: number;
|
|
8
|
+
elapsed: number;
|
|
9
|
+
useColor: boolean;
|
|
10
|
+
screenReader: boolean;
|
|
11
|
+
}): ReactNode;
|
|
12
|
+
/** 挂载临时画面,首帧真正写入后计时;调用方仅在本地就绪后等待门槛。 */
|
|
13
|
+
export declare function startCliStartupLogo(output: TuiOutputStream, input: NodeJS.ReadStream, env?: NodeJS.ProcessEnv): {
|
|
14
|
+
/** CI 没有临时帧需要清理。 */
|
|
15
|
+
dispose: () => void;
|
|
16
|
+
/** 沿用 Ink 的 CI 静态输出,不施加不可见动画门槛。 */
|
|
17
|
+
finish: () => Promise<void>;
|
|
18
|
+
};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/** 启动临时品牌画面,与本地初始化并行,退出时只擦除本次 Ink 动态帧。 */
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import { stripVTControlCharacters } from "node:util";
|
|
5
|
+
import { Box, Text, render } from "ink";
|
|
6
|
+
import { createTuiAnimationClock } from "../../animation-clock.js";
|
|
7
|
+
import { CLI_TUI_COLORS } from "../../design-tokens.js";
|
|
8
|
+
import { createDesktopResize } from "../desktop-resize.js";
|
|
9
|
+
import { readTuiTerminalSize } from "../format.js";
|
|
10
|
+
import { createTuiRenderStdout } from "../lifecycle.js";
|
|
11
|
+
import { getWindowsTuiResizeHost, resolveNoColor, resolveReducedMotion, resolveScreenReader } from "../render-mode.js";
|
|
12
|
+
import { createAgentLogoRows } from "./logo.js";
|
|
13
|
+
import { renderAutopilotColoredRows } from "./pixel.js";
|
|
14
|
+
/** 居中显示等比例点阵,小网格和读屏使用稳定文字,灰白扫光只提供装饰。 */
|
|
15
|
+
export function TuiStartupLogo(props) {
|
|
16
|
+
const height = Math.max(1, Math.min(20, props.rows - 1));
|
|
17
|
+
const logoHeight = Math.min(16, height - 2, Math.floor(props.columns / 2));
|
|
18
|
+
const logoWidth = logoHeight * 2;
|
|
19
|
+
const compact = props.screenReader || logoHeight < 5;
|
|
20
|
+
const rows = compact ? [] : createAgentLogoRows(logoWidth, logoHeight);
|
|
21
|
+
/** 按时间与列位置选择现有灰阶,保持字符和占行完全稳定。 */
|
|
22
|
+
function colorCell(char, column) {
|
|
23
|
+
if (!props.useColor || char === " ")
|
|
24
|
+
return undefined;
|
|
25
|
+
const light = (Math.sin(props.elapsed / 650 - column / 5) + 1) / 2;
|
|
26
|
+
return light > 0.7 ? CLI_TUI_COLORS.copilotInk : light > 0.25 ? CLI_TUI_COLORS.copilotMuted : CLI_TUI_COLORS.copilotOutline;
|
|
27
|
+
}
|
|
28
|
+
return _jsx(Box, { width: props.columns, height: compact ? 1 : height, flexDirection: "column", alignItems: "center", justifyContent: "center", children: compact ? _jsx(Text, { wrap: "truncate-end", children: "Autopilot loading\u2026" }) : _jsxs(_Fragment, { children: [renderAutopilotColoredRows(rows, colorCell, logoWidth), _jsx(Text, { children: "Loading\u2026" })] }) });
|
|
29
|
+
}
|
|
30
|
+
/** 挂载临时画面,首帧真正写入后计时;调用方仅在本地就绪后等待门槛。 */
|
|
31
|
+
export function startCliStartupLogo(output, input, env = process.env) {
|
|
32
|
+
// Ink 在 CI 中不输出动态帧,沿用其进程环境判定,避免等待永远不可见的首帧。
|
|
33
|
+
if ([process.env.CI, process.env.CONTINUOUS_INTEGRATION].some(function enabled(value) { return value !== undefined && value !== "0" && value !== "false"; })) {
|
|
34
|
+
return {
|
|
35
|
+
/** CI 没有临时帧需要清理。 */
|
|
36
|
+
dispose: function dispose() { },
|
|
37
|
+
/** 沿用 Ink 的 CI 静态输出,不施加不可见动画门槛。 */
|
|
38
|
+
finish: async function finish() { },
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const desktop = createDesktopResize(output, env);
|
|
42
|
+
const proxy = createTuiRenderStdout(output, readTuiTerminalSize(desktop.source), getWindowsTuiResizeHost(output.isTTY, env) !== undefined, written);
|
|
43
|
+
const screenReader = resolveScreenReader(env);
|
|
44
|
+
const animate = !screenReader && !resolveReducedMotion(env) && !resolveNoColor(env);
|
|
45
|
+
const clock = createTuiAnimationClock({ frameMs: 120 });
|
|
46
|
+
let instance;
|
|
47
|
+
let firstFrame;
|
|
48
|
+
let markVisible;
|
|
49
|
+
const visible = new Promise(function waitVisible(resolve) { markVisible = resolve; });
|
|
50
|
+
let pendingSize;
|
|
51
|
+
let timer;
|
|
52
|
+
let release;
|
|
53
|
+
let disposed = false;
|
|
54
|
+
/** 在输出代理真正写入可见文字后开始计时,排除 Ink 布局与节流等待。 */
|
|
55
|
+
function written(chunk) {
|
|
56
|
+
desktop.written(chunk);
|
|
57
|
+
if (disposed || firstFrame !== undefined || !stripVTControlCharacters(chunk).trim())
|
|
58
|
+
return;
|
|
59
|
+
firstFrame = Date.now();
|
|
60
|
+
markVisible();
|
|
61
|
+
}
|
|
62
|
+
/** 清理动画、尺寸监听和临时画面,既有 scrollback 不参与清理。 */
|
|
63
|
+
function dispose() {
|
|
64
|
+
if (disposed)
|
|
65
|
+
return;
|
|
66
|
+
disposed = true;
|
|
67
|
+
markVisible();
|
|
68
|
+
if (timer)
|
|
69
|
+
clearTimeout(timer);
|
|
70
|
+
release?.();
|
|
71
|
+
clock.dispose();
|
|
72
|
+
instance?.rerender(_jsx(_Fragment, {}));
|
|
73
|
+
instance?.clear();
|
|
74
|
+
instance?.unmount();
|
|
75
|
+
desktop.close();
|
|
76
|
+
}
|
|
77
|
+
/** 尺寸先通过组件提交短帧,再提交给 Ink,沿用 Desktop 两阶段缩窗机制。 */
|
|
78
|
+
function StartupApp() {
|
|
79
|
+
const [size, setSize] = useState(readTuiTerminalSize(desktop.source));
|
|
80
|
+
const [elapsed, setElapsed] = useState(0);
|
|
81
|
+
/** 同一时钟只刷新装饰亮度,无色和辅助模式没有动画订阅。 */
|
|
82
|
+
function subscribeAnimation() {
|
|
83
|
+
if (!animate)
|
|
84
|
+
return;
|
|
85
|
+
return clock.subscribe(function tick(time) { setElapsed(time - (firstFrame ?? time)); });
|
|
86
|
+
}
|
|
87
|
+
/** 将 resize 同步到布局目标,真正的 Ink 尺寸在该帧写入后提交。 */
|
|
88
|
+
function subscribeResize() {
|
|
89
|
+
function resized() {
|
|
90
|
+
const next = readTuiTerminalSize(desktop.source);
|
|
91
|
+
pendingSize = next;
|
|
92
|
+
setSize(next);
|
|
93
|
+
}
|
|
94
|
+
desktop.source.on?.("resize", resized);
|
|
95
|
+
return function detach() { desktop.source.off?.("resize", resized); };
|
|
96
|
+
}
|
|
97
|
+
useEffect(subscribeAnimation, []);
|
|
98
|
+
useEffect(subscribeResize, []);
|
|
99
|
+
return _jsx(TuiStartupLogo, { ...size, elapsed: elapsed, useColor: !resolveNoColor(env) && !screenReader, screenReader: screenReader });
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
instance = render(_jsx(StartupApp, {}), {
|
|
103
|
+
stdout: proxy.stdout, stdin: input, exitOnCtrlC: false,
|
|
104
|
+
patchConsole: false, incrementalRendering: false, isScreenReaderEnabled: screenReader,
|
|
105
|
+
/** Ink 在实际输出前回调,微任务在同步写入完成后提交真实尺寸。 */
|
|
106
|
+
onRender: function rendered() {
|
|
107
|
+
queueMicrotask(function committed() {
|
|
108
|
+
if (disposed)
|
|
109
|
+
return;
|
|
110
|
+
const next = pendingSize;
|
|
111
|
+
pendingSize = undefined;
|
|
112
|
+
if (next)
|
|
113
|
+
proxy.setSize(next);
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
dispose();
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
dispose,
|
|
124
|
+
/** 本地就绪后补足首帧两秒,初始化失败直接走 dispose,无额外延迟。 */
|
|
125
|
+
async finish() {
|
|
126
|
+
await visible;
|
|
127
|
+
if (disposed)
|
|
128
|
+
return;
|
|
129
|
+
await new Promise(function waitMinimum(resolve) {
|
|
130
|
+
release = resolve;
|
|
131
|
+
timer = setTimeout(resolve, Math.max(0, 2000 - (Date.now() - (firstFrame ?? Date.now()))));
|
|
132
|
+
});
|
|
133
|
+
dispose();
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
}
|
package/dist/tui/constants.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* 代理展示名。颜色语义 token 集中在 design-tokens.ts,这里不重复定义。
|
|
4
4
|
*/
|
|
5
5
|
/** Autopilot 品牌版本号。 */
|
|
6
|
-
export declare const AUTOPILOT_VERSION = "0.
|
|
6
|
+
export declare const AUTOPILOT_VERSION = "0.4.0";
|
|
7
7
|
/** 品牌像素字母的完整单词。 */
|
|
8
8
|
export declare const AUTOPILOT_BRAND_WORD = "AUTOPILOT";
|
|
9
9
|
/** 开场动画总时长(毫秒)。 */
|