@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/app.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
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, useInput, useStdin, useStdout } from "ink";
|
|
4
|
+
import { Box, Text, measureElement, useInput, useStdin, useStdout } from "ink";
|
|
5
|
+
import { TuiInlineOutput } from "./inline-output.js";
|
|
5
6
|
import { TuiActivityLine } from "../activity-animation.js";
|
|
6
7
|
import { createTuiAnimationClock } from "../animation-clock.js";
|
|
8
|
+
import { classifyCliError, CLI_THREAD_RECOVERY_HINT } from "../error-diagnostics.js";
|
|
7
9
|
import { resolveFileMentionContext } from "../file-mention-context.js";
|
|
8
10
|
import { createTimelineVisualLineCache } from "../timeline-lines.js";
|
|
9
11
|
import { TuiApprovalPrompt, createTuiApprovalOptions } from "./approval.js";
|
|
@@ -24,6 +26,7 @@ import { MemoizedTuiTranscriptItem, TuiPendingInputItem, TuiPromptLine } from ".
|
|
|
24
26
|
import { getTuiSelectedText } from "./viewport/selection.js";
|
|
25
27
|
import { createTuiViewportSourceCache } from "./viewport/sources.js";
|
|
26
28
|
import { TuiViewportTimeline } from "./viewport/viewport.js";
|
|
29
|
+
import wrapAnsi from "wrap-ansi";
|
|
27
30
|
const EMPTY_VIEWPORT_SOURCES = [];
|
|
28
31
|
const EMPTY_VIEWPORT_LINES = [];
|
|
29
32
|
/** Ink 应用组件;useInput 只把用户动作交给 Controller Action。 */
|
|
@@ -42,23 +45,27 @@ export function CliTuiApp(props) {
|
|
|
42
45
|
const jobRequestGeneration = useRef(0);
|
|
43
46
|
/** /context 覆盖视图;打开时取代时间线渲染,Esc 关闭后回到正常聊天。 */
|
|
44
47
|
const [contextView, setContextView] = useState(undefined);
|
|
48
|
+
const [infoReport, setInfoReport] = useState();
|
|
45
49
|
const rawInputSequenceRef = useRef("");
|
|
46
50
|
const busy = useRef(false);
|
|
47
51
|
const keepOpenAfterCancel = useRef(false);
|
|
48
|
-
const
|
|
49
|
-
const
|
|
52
|
+
const localLastSubmittedPromptRef = useRef(undefined);
|
|
53
|
+
const lastSubmittedPromptRef = props.viewState?.lastSubmittedPrompt ?? localLastSubmittedPromptRef;
|
|
54
|
+
const initialStarted = useRef(props.viewState?.initialStarted ?? false);
|
|
50
55
|
const lastResult = useRef(undefined);
|
|
51
56
|
const animationClockRef = useRef(undefined);
|
|
52
57
|
if (!animationClockRef.current)
|
|
53
|
-
animationClockRef.current = createTuiAnimationClock();
|
|
58
|
+
animationClockRef.current = createTuiAnimationClock({ frameMs: 120 });
|
|
54
59
|
const animationClock = animationClockRef.current;
|
|
55
60
|
/** 防抖后的终端尺寸;Ink 与应用布局共同使用同一份稳定快照。 */
|
|
56
61
|
const [terminalSize, setTerminalSize] = useState(function createTerminalSize() {
|
|
57
62
|
return readTuiTerminalSize(terminalSizeSource);
|
|
58
63
|
});
|
|
59
|
-
const isViewportMode = props.renderMode === "alternate-screen" && !props.screenReader;
|
|
60
|
-
const columns = terminalSize.columns;
|
|
61
|
-
const
|
|
64
|
+
const isViewportMode = props.visible !== false && props.renderMode === "alternate-screen" && !props.screenReader;
|
|
65
|
+
const columns = props.availableColumns ?? terminalSize.columns;
|
|
66
|
+
const inputEnabled = props.visible !== false && props.inputActive !== false;
|
|
67
|
+
const rows = props.availableRows ?? terminalSize.rows;
|
|
68
|
+
const maximumFrameRows = isViewportMode ? rows : Math.max(1, rows - 1);
|
|
62
69
|
const { statusView, refreshStatusView } = useStatusView(props.controller);
|
|
63
70
|
/** 输入子树通过 ref 读取 slash 与 @ 建议,父级只注入视口按键处理器。 */
|
|
64
71
|
const derivedRef = useRef({
|
|
@@ -78,15 +85,75 @@ export function CliTuiApp(props) {
|
|
|
78
85
|
});
|
|
79
86
|
}, []);
|
|
80
87
|
const infoMessages = snapshot.transcript
|
|
81
|
-
.filter(function isNotice(item) { return item.kind === "notice"; })
|
|
88
|
+
.filter(function isNotice(item) { return item.kind === "notice" && !item.persistent; })
|
|
82
89
|
.slice(-4)
|
|
83
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);
|
|
97
|
+
const [approvalOffset, setApprovalOffset] = useState(0);
|
|
98
|
+
const [approvalDetails, setApprovalDetails] = useState(false);
|
|
99
|
+
const [submittedFeedback, setApprovalFeedback] = useState();
|
|
100
|
+
const hostStatus = props.controller.getHostApprovalStatus?.();
|
|
101
|
+
const approvalFeedback = hostStatus ? undefined : submittedFeedback;
|
|
102
|
+
const approvalMaximumRef = useRef(0);
|
|
103
|
+
const approvalCardHeight = snapshot.pendingApproval ? Math.max(createTuiApprovalOptions(snapshot.pendingApproval).length + 4, Math.min(Math.floor(rows / 2), rows - inputLayout.promptHeight - statusHeight - 2)) : 0;
|
|
104
|
+
/** 主会话普通审批与原地卡片使用同一详情滚动/固定决定组件。 */
|
|
105
|
+
function handleApprovalKey(value, key) {
|
|
106
|
+
if (key.pageUp || key.pageDown) {
|
|
107
|
+
setApprovalOffset(function move(current) { return Math.max(0, Math.min(approvalMaximumRef.current, current + (key.pageDown ? 1 : -1) * Math.max(1, approvalCardHeight - 5))); });
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
if (value === "d") {
|
|
111
|
+
setApprovalDetails(function toggle(current) { return !current; });
|
|
112
|
+
setApprovalOffset(0);
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
if (key.escape || value === "\u001b") {
|
|
116
|
+
setApprovalDetails(false);
|
|
117
|
+
setApprovalOffset(0);
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
derivedRef.current.handleApprovalKey = handleApprovalKey;
|
|
84
123
|
const approvalHeight = isViewportMode && snapshot.pendingApproval ? createTuiApprovalOptions(snapshot.pendingApproval).length + 6 : 0;
|
|
85
124
|
// Todo 展开态最多占 10 行;矮终端为输入框、状态栏和活动文案至少保留 6 行。
|
|
86
125
|
const todoRowLimit = Math.max(2, Math.min(10, rows - 6));
|
|
87
126
|
const activeTodoForm = getTuiTurnTodo(snapshot.liveEvents, snapshot.liveTurnId ?? "")?.todos.find(function active(todo) { return todo.status === "in_progress"; })?.activeForm;
|
|
88
|
-
const fixedHeight = inputLayout.promptHeight + inputLayout.pickerHeight + approvalHeight + infoMessages.length + 1 + (
|
|
89
|
-
const
|
|
127
|
+
const fixedHeight = inputLayout.promptHeight + inputLayout.pickerHeight + approvalHeight + infoMessages.length + (infoMessages.length ? 1 : 0) + (approvalFeedback ? 1 : 0) + 1 + statusHeight;
|
|
128
|
+
const fixedRef = useRef(null);
|
|
129
|
+
const inputAreaRef = useRef(null);
|
|
130
|
+
const approvalBoxRef = useRef(null);
|
|
131
|
+
const inlineBodyRef = useRef(null);
|
|
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
|
+
});
|
|
142
|
+
// Ink 6 不支持 maxHeight;测量未收缩正文,给动态帧设置自然高度与窗口上限。
|
|
143
|
+
useLayoutEffect(function measureInlineLayout() {
|
|
144
|
+
if (isViewportMode || !inlineBodyRef.current || !fixedRef.current)
|
|
145
|
+
return;
|
|
146
|
+
const height = measureElement(inlineBodyRef.current).height + measureElement(fixedRef.current).height + approvalCardHeight;
|
|
147
|
+
setInlineHeight(function update(previous) { return previous === height ? previous : height; });
|
|
148
|
+
});
|
|
149
|
+
const [measuredFixedHeight, setMeasuredFixedHeight] = useState();
|
|
150
|
+
useLayoutEffect(function measureFixedLayout() {
|
|
151
|
+
if (!isViewportMode || !fixedRef.current)
|
|
152
|
+
return;
|
|
153
|
+
const height = measureElement(fixedRef.current).height + (approvalBoxRef.current ? measureElement(approvalBoxRef.current).height : 0);
|
|
154
|
+
setMeasuredFixedHeight(function update(previous) { return previous === height ? previous : height; });
|
|
155
|
+
});
|
|
156
|
+
const viewportHeight = Math.max(1, rows - (measuredFixedHeight ?? fixedHeight));
|
|
90
157
|
const viewportSourceCacheRef = useRef(undefined);
|
|
91
158
|
if (!viewportSourceCacheRef.current)
|
|
92
159
|
viewportSourceCacheRef.current = createTuiViewportSourceCache();
|
|
@@ -111,30 +178,41 @@ export function CliTuiApp(props) {
|
|
|
111
178
|
viewportHeight,
|
|
112
179
|
stdout,
|
|
113
180
|
onCopyText: props.onCopyText,
|
|
181
|
+
onCopyError: function copyFailed() { props.store.addNotice("复制失败,请检查系统剪贴板后重试。"); },
|
|
114
182
|
});
|
|
115
183
|
derivedRef.current.handleTuiViewportKey = handleTuiViewportKey;
|
|
116
184
|
const selectedText = isViewportMode ? getTuiSelectedText(viewportLines, selection) : "";
|
|
117
|
-
const animationActive = isRawModeSupported && stdout.isTTY !== false && terminalFocused;
|
|
185
|
+
const animationActive = (snapshot.compacting || snapshot.status === "running" && !snapshot.threadWait) && props.visible !== false && isRawModeSupported && stdout.isTTY !== false && terminalFocused;
|
|
118
186
|
/** 把用户动作交给 Controller;结束后刷新状态栏并按投影结果打开对应 picker。 */
|
|
119
187
|
async function dispatchAction(action, prompt, preserveSkillPickerQuery = false) {
|
|
120
|
-
|
|
121
|
-
|
|
188
|
+
if (action.type === "exit") {
|
|
189
|
+
props.onAppExit(0);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const answeringQuestion = action.type === "submit_prompt" && props.store.getSnapshot().status === "waiting_user_input";
|
|
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);
|
|
194
|
+
if (props.store.getSnapshot().compacting || busy.current && !allowWhileRunning)
|
|
122
195
|
return;
|
|
123
196
|
const isJobAction = action.type === "list_jobs" || action.type === "show_job" || action.type === "read_job_output" || action.type === "stop_job";
|
|
124
197
|
const jobGeneration = isJobAction ? ++jobRequestGeneration.current : undefined;
|
|
125
198
|
const inputPosition = prompt && allowWhileRunning ? props.store.captureInputPosition() : undefined;
|
|
126
|
-
if (prompt) {
|
|
199
|
+
if (prompt && !answeringQuestion) {
|
|
127
200
|
lastSubmittedPromptRef.current = prompt.trim();
|
|
128
201
|
props.store.recordPrompt(prompt, !allowWhileRunning);
|
|
129
202
|
}
|
|
130
203
|
if (action.type === "approve")
|
|
131
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);
|
|
132
210
|
if (!allowWhileRunning)
|
|
133
211
|
busy.current = true;
|
|
134
212
|
// D2/D5:仅交互 TUI 在发送前把 @ 引用的工作区文件内容以 <system-reminder> 附加块并入 action.content;
|
|
135
213
|
// start/steer/queue/initial 四条 TUI 提交路径都经过此处,时间线与 Esc 恢复仍使用原文 prompt。
|
|
136
214
|
let dispatchedAction = action;
|
|
137
|
-
if (action.type === "submit_prompt" && prompt && props.workspaceRoot) {
|
|
215
|
+
if (action.type === "submit_prompt" && !answeringQuestion && prompt && props.workspaceRoot && !props.controller.resolveFileMentionsInHost) {
|
|
138
216
|
const resolved = await resolveFileMentionContext(action.content, props.workspaceRoot);
|
|
139
217
|
for (const message of resolved.notices)
|
|
140
218
|
props.store.addNotice(message);
|
|
@@ -142,6 +220,8 @@ export function CliTuiApp(props) {
|
|
|
142
220
|
dispatchedAction = { ...action, content: resolved.content };
|
|
143
221
|
}
|
|
144
222
|
let result;
|
|
223
|
+
if (action.type === "compact")
|
|
224
|
+
props.store.setCompacting(true);
|
|
145
225
|
try {
|
|
146
226
|
result = await props.controller.dispatch(dispatchedAction);
|
|
147
227
|
}
|
|
@@ -151,16 +231,26 @@ export function CliTuiApp(props) {
|
|
|
151
231
|
kind: "error",
|
|
152
232
|
exitCode: 1,
|
|
153
233
|
lines: [],
|
|
154
|
-
message: "CLI_RUNTIME_ERROR",
|
|
234
|
+
message: classifyCliError(error).code === "THREAD_RECOVERY_REQUIRED" ? CLI_THREAD_RECOVERY_HINT : classifyCliError(error).category === "node_state" ? `${classifyCliError(error).code}:会话保存未完成,请检查存储可用性后重试;原记录保留` : "CLI_RUNTIME_ERROR",
|
|
155
235
|
projection: props.controller.getProjection(),
|
|
156
236
|
};
|
|
157
237
|
}
|
|
158
238
|
finally {
|
|
239
|
+
if (action.type === "compact")
|
|
240
|
+
props.store.setCompacting(false);
|
|
159
241
|
if (!allowWhileRunning)
|
|
160
242
|
busy.current = false;
|
|
161
243
|
}
|
|
162
244
|
lastResult.current = result;
|
|
163
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 });
|
|
164
254
|
if (result.jobView && jobGeneration === jobRequestGeneration.current) {
|
|
165
255
|
jobViewRef.current = result.jobView;
|
|
166
256
|
setJobView(result.jobView);
|
|
@@ -180,6 +270,8 @@ export function CliTuiApp(props) {
|
|
|
180
270
|
}
|
|
181
271
|
if (result.contextView)
|
|
182
272
|
setContextView(result.contextView);
|
|
273
|
+
if (result.hostRecordedPrompt && allowWhileRunning)
|
|
274
|
+
props.store.recordPrompt(result.hostRecordedPrompt, "history");
|
|
183
275
|
if (prompt && result.submittedInput)
|
|
184
276
|
props.store.addPendingPrompt(prompt, result.submittedInput, inputPosition);
|
|
185
277
|
await refreshStatusView();
|
|
@@ -210,7 +302,7 @@ export function CliTuiApp(props) {
|
|
|
210
302
|
useEffect(function subscribeTerminalResize() {
|
|
211
303
|
const onResize = terminalSizeSource.on;
|
|
212
304
|
const offResize = terminalSizeSource.off;
|
|
213
|
-
if (!onResize || !offResize)
|
|
305
|
+
if (props.availableColumns !== undefined || !onResize || !offResize)
|
|
214
306
|
return;
|
|
215
307
|
let timer;
|
|
216
308
|
function commitTerminalSize() {
|
|
@@ -235,17 +327,29 @@ export function CliTuiApp(props) {
|
|
|
235
327
|
};
|
|
236
328
|
}, [isViewportMode, terminalSizeSource]);
|
|
237
329
|
useLayoutEffect(function syncTerminalSizeToInk() {
|
|
238
|
-
props.
|
|
330
|
+
if (props.availableColumns === undefined)
|
|
331
|
+
props.onTerminalSizeChange?.(terminalSize);
|
|
239
332
|
}, [terminalSize, props.onTerminalSizeChange]);
|
|
240
333
|
useEffect(function bindTuiMouseInput() {
|
|
241
|
-
|
|
334
|
+
if (!inputEnabled)
|
|
335
|
+
return;
|
|
336
|
+
/** 鼠标同样按实时交互门路由,隐藏或旧代次不能修改后台阅读位置。 */
|
|
337
|
+
function routeSelectedMouse(event, notches) {
|
|
338
|
+
if (props.canReceiveInput?.() !== false)
|
|
339
|
+
handleTuiMouseEvent(event, notches);
|
|
340
|
+
}
|
|
341
|
+
props.mouseInput?.setHandler(routeSelectedMouse);
|
|
242
342
|
return function unbindTuiMouseInput() {
|
|
243
343
|
props.mouseInput?.setHandler(undefined);
|
|
244
344
|
};
|
|
245
|
-
}, [props.mouseInput, isViewportMode, columns, viewportHeight, viewportLines.length]);
|
|
345
|
+
}, [inputEnabled, props.mouseInput, isViewportMode, columns, viewportHeight, viewportLines.length]);
|
|
246
346
|
useEffect(function resetApprovalSelection() {
|
|
247
347
|
pickers.updateApprovalPickerIndex(0);
|
|
248
|
-
|
|
348
|
+
setApprovalOffset(0);
|
|
349
|
+
setApprovalDetails(false);
|
|
350
|
+
if (snapshot.pendingApproval || hostStatus || snapshot.status !== "waiting_approval")
|
|
351
|
+
setApprovalFeedback(undefined);
|
|
352
|
+
}, [snapshot.pendingApproval?.approvalId, hostStatus, snapshot.status]);
|
|
249
353
|
useEffect(function disposeTuiAnimationClock() {
|
|
250
354
|
return function disposeAnimationClock() {
|
|
251
355
|
animationClock.dispose();
|
|
@@ -256,13 +360,10 @@ export function CliTuiApp(props) {
|
|
|
256
360
|
setSnapshot(props.store.getSnapshot());
|
|
257
361
|
});
|
|
258
362
|
}, [props.store]);
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
}, [props.controller, snapshot.status, snapshot.liveTurnId]);
|
|
262
|
-
// 用量事件到达时重新查询状态栏,让 context 行在 Turn 运行中也能反映三态变化。
|
|
263
|
-
useEffect(function refreshStatusOnContextUsage() {
|
|
363
|
+
// 同一提交的Turn/用量变化只触发一次刷新;在途变化由hook合并到下一次查询。
|
|
364
|
+
useEffect(function refreshStatusOnTurnAndUsageChange() {
|
|
264
365
|
void refreshStatusView();
|
|
265
|
-
}, [
|
|
366
|
+
}, [refreshStatusView, snapshot.status, snapshot.liveTurnId, snapshot.contextUsage]);
|
|
266
367
|
useEffect(function subscribeStdinEnd() {
|
|
267
368
|
function handleStdinEnd() {
|
|
268
369
|
props.onEof();
|
|
@@ -300,6 +401,8 @@ export function CliTuiApp(props) {
|
|
|
300
401
|
if (initialStarted.current || !props.initial)
|
|
301
402
|
return;
|
|
302
403
|
initialStarted.current = true;
|
|
404
|
+
if (props.viewState)
|
|
405
|
+
props.viewState.initialStarted = true;
|
|
303
406
|
if (props.initial.type === "start") {
|
|
304
407
|
void dispatchAction({ type: "submit_prompt", content: props.initial.content }, props.initial.content);
|
|
305
408
|
}
|
|
@@ -312,12 +415,13 @@ export function CliTuiApp(props) {
|
|
|
312
415
|
try {
|
|
313
416
|
result = await props.controller.resume();
|
|
314
417
|
}
|
|
315
|
-
catch {
|
|
418
|
+
catch (error) {
|
|
419
|
+
recordTuiRuntimeErrorDiagnostic(error);
|
|
316
420
|
result = {
|
|
317
421
|
kind: "error",
|
|
318
422
|
exitCode: 1,
|
|
319
423
|
lines: [],
|
|
320
|
-
message: "CLI_RUNTIME_ERROR",
|
|
424
|
+
message: classifyCliError(error).category === "node_state" ? `${classifyCliError(error).code}:会话保存未完成,请检查存储可用性后重试;原记录保留` : "CLI_RUNTIME_ERROR",
|
|
321
425
|
projection: props.controller.getProjection(),
|
|
322
426
|
};
|
|
323
427
|
}
|
|
@@ -339,8 +443,27 @@ export function CliTuiApp(props) {
|
|
|
339
443
|
props.onAppExit(snapshot.requestedExitCode ?? lastResult.current?.exitCode ?? 0);
|
|
340
444
|
}
|
|
341
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) });
|
|
342
463
|
/** 在 Job 视图内复用 Ink 输入路由;Esc 只返回视图,不取消 Turn 或退出进程。 */
|
|
343
464
|
useInput(function handleJobInput(value, key) {
|
|
465
|
+
if (props.canReceiveInput?.(value, key) === false)
|
|
466
|
+
return;
|
|
344
467
|
const current = jobViewRef.current;
|
|
345
468
|
if (!current)
|
|
346
469
|
return;
|
|
@@ -377,37 +500,50 @@ export function CliTuiApp(props) {
|
|
|
377
500
|
void dispatchAction({ type: "stop_job", jobId: current.job.jobId });
|
|
378
501
|
else if (value === "r")
|
|
379
502
|
void dispatchAction({ type: current.output ? "read_job_output" : "show_job", jobId: current.job.jobId });
|
|
380
|
-
}, { isActive: isRawModeSupported && jobView !== undefined });
|
|
503
|
+
}, { isActive: inputEnabled && isRawModeSupported && jobView !== undefined && !infoReport });
|
|
381
504
|
/** 在 Context 覆盖视图内复用 Ink 输入路由;Esc 只关闭视图回到聊天,不取消 Turn 或退出进程。 */
|
|
382
505
|
useInput(function handleContextInput(value, key) {
|
|
506
|
+
if (props.canReceiveInput?.(value, key) === false)
|
|
507
|
+
return;
|
|
383
508
|
if (contextView === undefined)
|
|
384
509
|
return;
|
|
385
510
|
if (key.escape || value === "\u001b")
|
|
386
511
|
setContextView(undefined);
|
|
387
|
-
}, { isActive: isRawModeSupported && contextView !== undefined });
|
|
512
|
+
}, { isActive: inputEnabled && isRawModeSupported && contextView !== undefined && !infoReport });
|
|
388
513
|
// Ctrl+O 只切换 Todo 展开视图;picker 与审批等待打开时让位,避免按键语义冲突。
|
|
389
514
|
useInput(function handleTodoExpandInput(input, key) {
|
|
515
|
+
if (props.canReceiveInput?.(input, key) === false)
|
|
516
|
+
return;
|
|
390
517
|
if (key.ctrl && input === "o")
|
|
391
518
|
setTodoExpanded(function toggleTodoExpanded(previous) { return !previous; });
|
|
392
|
-
}, { isActive: isRawModeSupported && !pickers.isPickerActive && !snapshot.pendingApproval });
|
|
519
|
+
}, { isActive: inputEnabled && isRawModeSupported && !pickers.isPickerActive && !snapshot.pendingApproval && !infoReport });
|
|
393
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"));
|
|
394
522
|
const inlineHistoryItems = isViewportMode ? [] : [
|
|
395
523
|
TUI_BRAND_HISTORY_ITEM,
|
|
396
524
|
...snapshot.transcript.filter(function selectInlineHistoryItem(item) {
|
|
397
525
|
if (item.kind === "notice")
|
|
526
|
+
return item.persistent === true;
|
|
527
|
+
if (item.kind === "prompt" && item.key === snapshot.activePrompt?.key && !archiveActivePrompt)
|
|
398
528
|
return false;
|
|
399
529
|
if (item.kind === "turn")
|
|
400
530
|
return item.turnId !== snapshot.liveTurnId || isLiveTurnTerminal;
|
|
401
|
-
return
|
|
531
|
+
return true;
|
|
402
532
|
}),
|
|
403
533
|
];
|
|
404
|
-
const
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
534
|
+
const inlineOutput = inlineHistoryItems.map(function output(item) {
|
|
535
|
+
if (item.kind === "turn") {
|
|
536
|
+
const sequence = Math.max(0, ...item.events.filter(function runtime(event) { return event.seq < Number.MAX_SAFE_INTEGER; }).map(function seq(event) { return event.seq; }));
|
|
537
|
+
return { key: `${props.inlineOutputKey ?? "session"}:turn:${item.turnId}`, sequence, render: function segment(after) {
|
|
538
|
+
const segment = after === undefined ? item : { ...item, presentation: undefined, events: item.events.filter(function newer(event) { return event.seq > after && event.seq < Number.MAX_SAFE_INTEGER; }) };
|
|
539
|
+
return _jsx(MemoizedTuiTranscriptItem, { item: segment, columns: columns, useColor: props.useColor, screenReader: props.screenReader });
|
|
540
|
+
} };
|
|
541
|
+
}
|
|
542
|
+
return { key: `${props.inlineOutputKey ?? "session"}:${item.key}`, node: item.kind === "brand"
|
|
543
|
+
? _jsx(TuiBrandHeader, { columns: columns, useColor: props.useColor, screenReader: props.screenReader, reducedMotion: true, animationActive: false })
|
|
544
|
+
: _jsx(MemoizedTuiTranscriptItem, { item: item, columns: columns, useColor: props.useColor, screenReader: props.screenReader }) };
|
|
545
|
+
});
|
|
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 })] })] })] }));
|
|
413
549
|
}
|
package/dist/tui/approval.d.ts
CHANGED
package/dist/tui/approval.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
|
|
2
|
+
/** 审批菜单:根据待审批工具收窄选项,并以 CC 风格上下选择、回车确认。 */
|
|
3
|
+
import { useLayoutEffect, useRef } from "react";
|
|
4
|
+
import { Box, Text, measureElement } from "ink";
|
|
3
5
|
import { TUI_ACCENT_COLOR } from "../design-tokens.js";
|
|
4
6
|
import { getTuiToolLabel } from "./format.js";
|
|
5
7
|
/** 根据待审批工具收窄菜单;旧记录缺少冻结范围时保持最保守的单次/拒绝。 */
|
|
@@ -34,8 +36,15 @@ export function createTuiApprovalOptions(pendingApproval) {
|
|
|
34
36
|
export function TuiApprovalPrompt(props) {
|
|
35
37
|
const options = createTuiApprovalOptions(props.pendingApproval);
|
|
36
38
|
const selectedIndex = Math.max(0, Math.min(props.selectedIndex, options.length - 1));
|
|
37
|
-
|
|
39
|
+
const contentRef = useRef(null);
|
|
40
|
+
const viewportRef = useRef(null);
|
|
41
|
+
/** 以实际换行高度收敛详情滚动范围,固定决定区始终留在卡片底部。 */
|
|
42
|
+
useLayoutEffect(function measureApprovalDetails() {
|
|
43
|
+
if (contentRef.current && viewportRef.current)
|
|
44
|
+
props.onMaximumOffset?.(Math.max(0, measureElement(contentRef.current).height - measureElement(viewportRef.current).height));
|
|
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 \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) {
|
|
38
47
|
const selected = index === selectedIndex;
|
|
39
|
-
return _jsxs(Text, { inverse: selected && props.useColor, children: [selected ? "›" : " ", " ", option.label, selected && props.screenReader ? "(已选择)" : ""] }, option.decision);
|
|
40
|
-
}), _jsx(Text, { dimColor: props.useColor, children: "\u2191/\u2193 \u9009\u62E9 \u00B7 Enter \u786E\u8BA4" })] }));
|
|
48
|
+
return _jsxs(Text, { wrap: "truncate", inverse: selected && props.useColor, children: [selected ? "›" : " ", " ", option.label, selected && props.screenReader ? "(已选择)" : ""] }, option.decision);
|
|
49
|
+
}), _jsx(Text, { wrap: "truncate", dimColor: props.useColor, children: "\u2191/\u2193 \u9009\u62E9 \u00B7 Enter \u786E\u8BA4 \u00B7 PgUp/PgDn\u8BE6\u60C5" })] }));
|
|
41
50
|
}
|
|
@@ -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
|
}
|