@autopilot-agent/cli 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -153
- package/dist/activity-animation.d.ts +6 -0
- package/dist/activity-animation.js +15 -18
- package/dist/composition-root.d.ts +31 -1
- package/dist/composition-root.js +124 -3
- package/dist/context-report.d.ts +9 -4
- package/dist/context-report.js +16 -5
- package/dist/controller.d.ts +34 -4
- package/dist/controller.js +494 -90
- package/dist/design-tokens.d.ts +4 -0
- package/dist/design-tokens.js +4 -0
- package/dist/error-diagnostics.d.ts +2 -0
- package/dist/error-diagnostics.js +3 -1
- package/dist/event-projector.d.ts +16 -2
- package/dist/event-projector.js +78 -7
- package/dist/index.d.ts +1 -1
- package/dist/main.js +142 -7
- package/dist/parser.js +511 -4
- package/dist/renderer.js +19 -3
- package/dist/session-summary.d.ts +7 -0
- package/dist/session-summary.js +25 -0
- package/dist/session-title.d.ts +5 -0
- package/dist/session-title.js +10 -0
- package/dist/termination-format.js +1 -0
- package/dist/thread-commands.d.ts +37 -0
- package/dist/thread-commands.js +233 -0
- package/dist/thread-host.d.ts +31 -0
- package/dist/thread-host.js +76 -0
- package/dist/timeline-lines.js +36 -28
- package/dist/tui/app.d.ts +22 -0
- package/dist/tui/app.js +119 -44
- package/dist/tui/approval.d.ts +5 -1
- package/dist/tui/approval.js +20 -7
- package/dist/tui/constants.d.ts +1 -1
- package/dist/tui/constants.js +1 -1
- package/dist/tui/format.d.ts +1 -1
- package/dist/tui/format.js +23 -11
- package/dist/tui/hooks/use-prompt-input.d.ts +52 -0
- package/dist/tui/hooks/use-prompt-input.js +148 -20
- package/dist/tui/hooks/use-status-view.d.ts +2 -2
- package/dist/tui/hooks/use-status-view.js +38 -11
- package/dist/tui/inline-output.d.ts +17 -0
- package/dist/tui/inline-output.js +31 -0
- package/dist/tui/input/clipboard-image.d.ts +17 -0
- package/dist/tui/input/clipboard-image.js +117 -0
- package/dist/tui/input-area.d.ts +8 -0
- package/dist/tui/input-area.js +18 -3
- package/dist/tui/lifecycle.js +2 -5
- package/dist/tui/markdown/diff.d.ts +1 -1
- package/dist/tui/markdown/diff.js +28 -1
- package/dist/tui/performance-diagnostics.js +2 -0
- package/dist/tui/prompt-input.d.ts +1 -0
- package/dist/tui/prompt-input.js +5 -3
- package/dist/tui/render-mode.d.ts +4 -4
- package/dist/tui/render-mode.js +5 -11
- package/dist/tui/run.js +37 -49
- package/dist/tui/session-manager.d.ts +115 -0
- package/dist/tui/session-manager.js +383 -0
- package/dist/tui/session-workspace.d.ts +9 -0
- package/dist/tui/session-workspace.js +383 -0
- package/dist/tui/status-line.d.ts +3 -0
- package/dist/tui/status-line.js +12 -6
- package/dist/tui/store.js +111 -53
- package/dist/tui/timeline/live.js +9 -8
- package/dist/tui/timeline/presentation-timeline.d.ts +2 -1
- package/dist/tui/timeline/presentation-timeline.js +34 -15
- package/dist/tui/timeline/progress.js +3 -2
- package/dist/tui/timeline/static-timeline.js +17 -8
- package/dist/tui/timeline/turn-items.d.ts +12 -0
- package/dist/tui/timeline/turn-items.js +28 -0
- package/dist/tui/timeline/turn.js +8 -7
- package/dist/tui/transcript.d.ts +2 -2
- package/dist/tui/transcript.js +21 -3
- package/dist/tui/trust-dialog.d.ts +3 -0
- package/dist/tui/trust-dialog.js +23 -2
- package/dist/tui/types.d.ts +23 -1
- package/dist/tui/types.js +4 -1
- package/dist/tui/viewport/sources.d.ts +2 -2
- package/dist/tui/viewport/sources.js +75 -75
- package/dist/tui/viewport/viewport.js +5 -1
- package/dist/types.d.ts +165 -2
- package/package.json +4 -4
package/dist/tui/app.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } 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, 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";
|
|
@@ -19,7 +21,8 @@ import { TuiInputArea } from "./input-area.js";
|
|
|
19
21
|
import { TuiInfoLines, TuiStatusLine } from "./status-line.js";
|
|
20
22
|
import { TuiJobs } from "./jobs.js";
|
|
21
23
|
import { TuiLiveTurn } from "./timeline/turn.js";
|
|
22
|
-
import {
|
|
24
|
+
import { getTuiTurnTodo } from "./timeline/turn-items.js";
|
|
25
|
+
import { MemoizedTuiTranscriptItem, TuiPendingInputItem } from "./transcript.js";
|
|
23
26
|
import { getTuiSelectedText } from "./viewport/selection.js";
|
|
24
27
|
import { createTuiViewportSourceCache } from "./viewport/sources.js";
|
|
25
28
|
import { TuiViewportTimeline } from "./viewport/viewport.js";
|
|
@@ -44,20 +47,22 @@ export function CliTuiApp(props) {
|
|
|
44
47
|
const rawInputSequenceRef = useRef("");
|
|
45
48
|
const busy = useRef(false);
|
|
46
49
|
const keepOpenAfterCancel = useRef(false);
|
|
47
|
-
const
|
|
48
|
-
const
|
|
50
|
+
const localLastSubmittedPromptRef = useRef(undefined);
|
|
51
|
+
const lastSubmittedPromptRef = props.viewState?.lastSubmittedPrompt ?? localLastSubmittedPromptRef;
|
|
52
|
+
const initialStarted = useRef(props.viewState?.initialStarted ?? false);
|
|
49
53
|
const lastResult = useRef(undefined);
|
|
50
54
|
const animationClockRef = useRef(undefined);
|
|
51
55
|
if (!animationClockRef.current)
|
|
52
|
-
animationClockRef.current = createTuiAnimationClock();
|
|
56
|
+
animationClockRef.current = createTuiAnimationClock({ frameMs: 120 });
|
|
53
57
|
const animationClock = animationClockRef.current;
|
|
54
58
|
/** 防抖后的终端尺寸;Ink 与应用布局共同使用同一份稳定快照。 */
|
|
55
59
|
const [terminalSize, setTerminalSize] = useState(function createTerminalSize() {
|
|
56
60
|
return readTuiTerminalSize(terminalSizeSource);
|
|
57
61
|
});
|
|
58
|
-
const isViewportMode = props.renderMode === "alternate-screen" && !props.screenReader;
|
|
59
|
-
const columns = terminalSize.columns;
|
|
60
|
-
const
|
|
62
|
+
const isViewportMode = props.visible !== false && props.renderMode === "alternate-screen" && !props.screenReader;
|
|
63
|
+
const columns = props.availableColumns ?? terminalSize.columns;
|
|
64
|
+
const inputEnabled = props.visible !== false && props.inputActive !== false;
|
|
65
|
+
const rows = props.availableRows ?? terminalSize.rows;
|
|
61
66
|
const { statusView, refreshStatusView } = useStatusView(props.controller);
|
|
62
67
|
/** 输入子树通过 ref 读取 slash 与 @ 建议,父级只注入视口按键处理器。 */
|
|
63
68
|
const derivedRef = useRef({
|
|
@@ -80,11 +85,53 @@ export function CliTuiApp(props) {
|
|
|
80
85
|
.filter(function isNotice(item) { return item.kind === "notice"; })
|
|
81
86
|
.slice(-4)
|
|
82
87
|
.map(function getNoticeMessage(item) { return item.message; });
|
|
88
|
+
const [approvalOffset, setApprovalOffset] = useState(0);
|
|
89
|
+
const [approvalDetails, setApprovalDetails] = useState(false);
|
|
90
|
+
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 - (statusView ? 8 : 3))) : 0;
|
|
92
|
+
/** 主会话普通审批与原地卡片使用同一详情滚动/固定决定组件。 */
|
|
93
|
+
function handleApprovalKey(value, key) {
|
|
94
|
+
if (key.pageUp || key.pageDown) {
|
|
95
|
+
setApprovalOffset(function move(current) { return Math.max(0, Math.min(approvalMaximumRef.current, current + (key.pageDown ? 1 : -1) * Math.max(1, approvalCardHeight - 5))); });
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
if (value === "d") {
|
|
99
|
+
setApprovalDetails(function toggle(current) { return !current; });
|
|
100
|
+
setApprovalOffset(0);
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
if (key.escape || value === "\u001b") {
|
|
104
|
+
setApprovalDetails(false);
|
|
105
|
+
setApprovalOffset(0);
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
derivedRef.current.handleApprovalKey = handleApprovalKey;
|
|
83
111
|
const approvalHeight = isViewportMode && snapshot.pendingApproval ? createTuiApprovalOptions(snapshot.pendingApproval).length + 6 : 0;
|
|
84
|
-
const fixedHeight = inputLayout.promptHeight + inputLayout.pickerHeight + approvalHeight + infoMessages.length + 1 + (statusView ? 5 : 2);
|
|
85
|
-
const viewportHeight = Math.max(1, rows - fixedHeight);
|
|
86
112
|
// Todo 展开态最多占 10 行;矮终端为输入框、状态栏和活动文案至少保留 6 行。
|
|
87
113
|
const todoRowLimit = Math.max(2, Math.min(10, rows - 6));
|
|
114
|
+
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) + 1 + (statusView ? 6 : 1) + (props.sessionTitle ? 1 : 0);
|
|
116
|
+
const fixedRef = useRef(null);
|
|
117
|
+
const inlineBodyRef = useRef(null);
|
|
118
|
+
const [inlineHeight, setInlineHeight] = useState();
|
|
119
|
+
// Ink 6 不支持 maxHeight;测量未收缩正文,给动态帧设置自然高度与窗口上限。
|
|
120
|
+
useLayoutEffect(function measureInlineLayout() {
|
|
121
|
+
if (isViewportMode || !inlineBodyRef.current || !fixedRef.current)
|
|
122
|
+
return;
|
|
123
|
+
const height = measureElement(inlineBodyRef.current).height + measureElement(fixedRef.current).height + approvalCardHeight;
|
|
124
|
+
setInlineHeight(function update(previous) { return previous === height ? previous : height; });
|
|
125
|
+
});
|
|
126
|
+
const approvalBoxRef = useRef(null);
|
|
127
|
+
const [measuredFixedHeight, setMeasuredFixedHeight] = useState();
|
|
128
|
+
useLayoutEffect(function measureFixedLayout() {
|
|
129
|
+
if (!isViewportMode || !fixedRef.current)
|
|
130
|
+
return;
|
|
131
|
+
const height = measureElement(fixedRef.current).height + (approvalBoxRef.current ? measureElement(approvalBoxRef.current).height : 0);
|
|
132
|
+
setMeasuredFixedHeight(function update(previous) { return previous === height ? previous : height; });
|
|
133
|
+
});
|
|
134
|
+
const viewportHeight = Math.max(1, rows - (measuredFixedHeight ?? fixedHeight));
|
|
88
135
|
const viewportSourceCacheRef = useRef(undefined);
|
|
89
136
|
if (!viewportSourceCacheRef.current)
|
|
90
137
|
viewportSourceCacheRef.current = createTuiViewportSourceCache();
|
|
@@ -94,9 +141,9 @@ export function CliTuiApp(props) {
|
|
|
94
141
|
const viewportContentWidth = Math.max(1, columns - 1);
|
|
95
142
|
const viewportSources = useMemo(function getCachedViewportSources() {
|
|
96
143
|
return isViewportMode
|
|
97
|
-
? viewportSourceCacheRef.current.getSources(snapshot, statusView, pickers.approvalPickerIndex, viewportContentWidth, todoExpanded, props.useColor)
|
|
144
|
+
? viewportSourceCacheRef.current.getSources(snapshot, statusView, pickers.approvalPickerIndex, viewportContentWidth, todoExpanded, props.useColor, todoRowLimit)
|
|
98
145
|
: EMPTY_VIEWPORT_SOURCES;
|
|
99
|
-
}, [isViewportMode, pickers.approvalPickerIndex, snapshot, statusView, viewportContentWidth, todoExpanded, props.useColor]);
|
|
146
|
+
}, [isViewportMode, pickers.approvalPickerIndex, snapshot, statusView, viewportContentWidth, todoExpanded, props.useColor, todoRowLimit]);
|
|
100
147
|
const viewportLines = useMemo(function getCachedViewportLines() {
|
|
101
148
|
return isViewportMode
|
|
102
149
|
? viewportLineCacheRef.current.getLines(viewportSources, viewportContentWidth)
|
|
@@ -112,15 +159,21 @@ export function CliTuiApp(props) {
|
|
|
112
159
|
});
|
|
113
160
|
derivedRef.current.handleTuiViewportKey = handleTuiViewportKey;
|
|
114
161
|
const selectedText = isViewportMode ? getTuiSelectedText(viewportLines, selection) : "";
|
|
115
|
-
const animationActive = isRawModeSupported && stdout.isTTY !== false && terminalFocused;
|
|
162
|
+
const animationActive = snapshot.status === "running" && !snapshot.threadWait && props.visible !== false && isRawModeSupported && stdout.isTTY !== false && terminalFocused;
|
|
116
163
|
/** 把用户动作交给 Controller;结束后刷新状态栏并按投影结果打开对应 picker。 */
|
|
117
164
|
async function dispatchAction(action, prompt, preserveSkillPickerQuery = false) {
|
|
118
|
-
|
|
165
|
+
if (action.type === "exit") {
|
|
166
|
+
props.onAppExit(0);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const answeringQuestion = action.type === "submit_prompt" && props.store.getSnapshot().status === "waiting_user_input";
|
|
170
|
+
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);
|
|
119
171
|
if (busy.current && !allowWhileRunning)
|
|
120
172
|
return;
|
|
121
173
|
const isJobAction = action.type === "list_jobs" || action.type === "show_job" || action.type === "read_job_output" || action.type === "stop_job";
|
|
122
174
|
const jobGeneration = isJobAction ? ++jobRequestGeneration.current : undefined;
|
|
123
|
-
|
|
175
|
+
const inputPosition = prompt && allowWhileRunning ? props.store.captureInputPosition() : undefined;
|
|
176
|
+
if (prompt && !answeringQuestion) {
|
|
124
177
|
lastSubmittedPromptRef.current = prompt.trim();
|
|
125
178
|
props.store.recordPrompt(prompt, !allowWhileRunning);
|
|
126
179
|
}
|
|
@@ -131,7 +184,7 @@ export function CliTuiApp(props) {
|
|
|
131
184
|
// D2/D5:仅交互 TUI 在发送前把 @ 引用的工作区文件内容以 <system-reminder> 附加块并入 action.content;
|
|
132
185
|
// start/steer/queue/initial 四条 TUI 提交路径都经过此处,时间线与 Esc 恢复仍使用原文 prompt。
|
|
133
186
|
let dispatchedAction = action;
|
|
134
|
-
if (action.type === "submit_prompt" && prompt && props.workspaceRoot) {
|
|
187
|
+
if (action.type === "submit_prompt" && !answeringQuestion && prompt && props.workspaceRoot) {
|
|
135
188
|
const resolved = await resolveFileMentionContext(action.content, props.workspaceRoot);
|
|
136
189
|
for (const message of resolved.notices)
|
|
137
190
|
props.store.addNotice(message);
|
|
@@ -148,7 +201,7 @@ export function CliTuiApp(props) {
|
|
|
148
201
|
kind: "error",
|
|
149
202
|
exitCode: 1,
|
|
150
203
|
lines: [],
|
|
151
|
-
message: "CLI_RUNTIME_ERROR",
|
|
204
|
+
message: classifyCliError(error).code === "THREAD_RECOVERY_REQUIRED" ? CLI_THREAD_RECOVERY_HINT : classifyCliError(error).category === "node_state" ? `${classifyCliError(error).code}:会话保存未完成,请检查存储可用性后重试;原记录保留` : "CLI_RUNTIME_ERROR",
|
|
152
205
|
projection: props.controller.getProjection(),
|
|
153
206
|
};
|
|
154
207
|
}
|
|
@@ -177,9 +230,9 @@ export function CliTuiApp(props) {
|
|
|
177
230
|
}
|
|
178
231
|
if (result.contextView)
|
|
179
232
|
setContextView(result.contextView);
|
|
180
|
-
await refreshStatusView();
|
|
181
233
|
if (prompt && result.submittedInput)
|
|
182
|
-
props.store.addPendingPrompt(prompt, result.submittedInput);
|
|
234
|
+
props.store.addPendingPrompt(prompt, result.submittedInput, inputPosition);
|
|
235
|
+
await refreshStatusView();
|
|
183
236
|
if (result.skillOptions) {
|
|
184
237
|
pickers.setSkillPickerSkills(result.skillOptions);
|
|
185
238
|
if (!preserveSkillPickerQuery)
|
|
@@ -207,7 +260,7 @@ export function CliTuiApp(props) {
|
|
|
207
260
|
useEffect(function subscribeTerminalResize() {
|
|
208
261
|
const onResize = terminalSizeSource.on;
|
|
209
262
|
const offResize = terminalSizeSource.off;
|
|
210
|
-
if (!onResize || !offResize)
|
|
263
|
+
if (props.availableColumns !== undefined || !onResize || !offResize)
|
|
211
264
|
return;
|
|
212
265
|
let timer;
|
|
213
266
|
function commitTerminalSize() {
|
|
@@ -232,16 +285,26 @@ export function CliTuiApp(props) {
|
|
|
232
285
|
};
|
|
233
286
|
}, [isViewportMode, terminalSizeSource]);
|
|
234
287
|
useLayoutEffect(function syncTerminalSizeToInk() {
|
|
235
|
-
props.
|
|
288
|
+
if (props.availableColumns === undefined)
|
|
289
|
+
props.onTerminalSizeChange?.(terminalSize);
|
|
236
290
|
}, [terminalSize, props.onTerminalSizeChange]);
|
|
237
291
|
useEffect(function bindTuiMouseInput() {
|
|
238
|
-
|
|
292
|
+
if (!inputEnabled)
|
|
293
|
+
return;
|
|
294
|
+
/** 鼠标同样按实时交互门路由,隐藏或旧代次不能修改后台阅读位置。 */
|
|
295
|
+
function routeSelectedMouse(event, notches) {
|
|
296
|
+
if (props.canReceiveInput?.() !== false)
|
|
297
|
+
handleTuiMouseEvent(event, notches);
|
|
298
|
+
}
|
|
299
|
+
props.mouseInput?.setHandler(routeSelectedMouse);
|
|
239
300
|
return function unbindTuiMouseInput() {
|
|
240
301
|
props.mouseInput?.setHandler(undefined);
|
|
241
302
|
};
|
|
242
|
-
}, [props.mouseInput, isViewportMode, columns, viewportHeight, viewportLines.length]);
|
|
303
|
+
}, [inputEnabled, props.mouseInput, isViewportMode, columns, viewportHeight, viewportLines.length]);
|
|
243
304
|
useEffect(function resetApprovalSelection() {
|
|
244
305
|
pickers.updateApprovalPickerIndex(0);
|
|
306
|
+
setApprovalOffset(0);
|
|
307
|
+
setApprovalDetails(false);
|
|
245
308
|
}, [snapshot.pendingApproval?.approvalId]);
|
|
246
309
|
useEffect(function disposeTuiAnimationClock() {
|
|
247
310
|
return function disposeAnimationClock() {
|
|
@@ -253,13 +316,10 @@ export function CliTuiApp(props) {
|
|
|
253
316
|
setSnapshot(props.store.getSnapshot());
|
|
254
317
|
});
|
|
255
318
|
}, [props.store]);
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}, [props.controller, snapshot.status, snapshot.liveTurnId]);
|
|
259
|
-
// 用量事件到达时重新查询状态栏,让 context 行在 Turn 运行中也能反映三态变化。
|
|
260
|
-
useEffect(function refreshStatusOnContextUsage() {
|
|
319
|
+
// 同一提交的Turn/用量变化只触发一次刷新;在途变化由hook合并到下一次查询。
|
|
320
|
+
useEffect(function refreshStatusOnTurnAndUsageChange() {
|
|
261
321
|
void refreshStatusView();
|
|
262
|
-
}, [
|
|
322
|
+
}, [refreshStatusView, snapshot.status, snapshot.liveTurnId, snapshot.contextUsage]);
|
|
263
323
|
useEffect(function subscribeStdinEnd() {
|
|
264
324
|
function handleStdinEnd() {
|
|
265
325
|
props.onEof();
|
|
@@ -297,6 +357,8 @@ export function CliTuiApp(props) {
|
|
|
297
357
|
if (initialStarted.current || !props.initial)
|
|
298
358
|
return;
|
|
299
359
|
initialStarted.current = true;
|
|
360
|
+
if (props.viewState)
|
|
361
|
+
props.viewState.initialStarted = true;
|
|
300
362
|
if (props.initial.type === "start") {
|
|
301
363
|
void dispatchAction({ type: "submit_prompt", content: props.initial.content }, props.initial.content);
|
|
302
364
|
}
|
|
@@ -309,12 +371,13 @@ export function CliTuiApp(props) {
|
|
|
309
371
|
try {
|
|
310
372
|
result = await props.controller.resume();
|
|
311
373
|
}
|
|
312
|
-
catch {
|
|
374
|
+
catch (error) {
|
|
375
|
+
recordTuiRuntimeErrorDiagnostic(error);
|
|
313
376
|
result = {
|
|
314
377
|
kind: "error",
|
|
315
378
|
exitCode: 1,
|
|
316
379
|
lines: [],
|
|
317
|
-
message: "CLI_RUNTIME_ERROR",
|
|
380
|
+
message: classifyCliError(error).category === "node_state" ? `${classifyCliError(error).code}:会话保存未完成,请检查存储可用性后重试;原记录保留` : "CLI_RUNTIME_ERROR",
|
|
318
381
|
projection: props.controller.getProjection(),
|
|
319
382
|
};
|
|
320
383
|
}
|
|
@@ -338,6 +401,8 @@ export function CliTuiApp(props) {
|
|
|
338
401
|
}, [props.closeWhenIdle, snapshot.status, snapshot.requestedExitCode]);
|
|
339
402
|
/** 在 Job 视图内复用 Ink 输入路由;Esc 只返回视图,不取消 Turn 或退出进程。 */
|
|
340
403
|
useInput(function handleJobInput(value, key) {
|
|
404
|
+
if (props.canReceiveInput?.(value, key) === false)
|
|
405
|
+
return;
|
|
341
406
|
const current = jobViewRef.current;
|
|
342
407
|
if (!current)
|
|
343
408
|
return;
|
|
@@ -374,19 +439,23 @@ export function CliTuiApp(props) {
|
|
|
374
439
|
void dispatchAction({ type: "stop_job", jobId: current.job.jobId });
|
|
375
440
|
else if (value === "r")
|
|
376
441
|
void dispatchAction({ type: current.output ? "read_job_output" : "show_job", jobId: current.job.jobId });
|
|
377
|
-
}, { isActive: isRawModeSupported && jobView !== undefined });
|
|
442
|
+
}, { isActive: inputEnabled && isRawModeSupported && jobView !== undefined });
|
|
378
443
|
/** 在 Context 覆盖视图内复用 Ink 输入路由;Esc 只关闭视图回到聊天,不取消 Turn 或退出进程。 */
|
|
379
444
|
useInput(function handleContextInput(value, key) {
|
|
445
|
+
if (props.canReceiveInput?.(value, key) === false)
|
|
446
|
+
return;
|
|
380
447
|
if (contextView === undefined)
|
|
381
448
|
return;
|
|
382
449
|
if (key.escape || value === "\u001b")
|
|
383
450
|
setContextView(undefined);
|
|
384
|
-
}, { isActive: isRawModeSupported && contextView !== undefined });
|
|
451
|
+
}, { isActive: inputEnabled && isRawModeSupported && contextView !== undefined });
|
|
385
452
|
// Ctrl+O 只切换 Todo 展开视图;picker 与审批等待打开时让位,避免按键语义冲突。
|
|
386
453
|
useInput(function handleTodoExpandInput(input, key) {
|
|
454
|
+
if (props.canReceiveInput?.(input, key) === false)
|
|
455
|
+
return;
|
|
387
456
|
if (key.ctrl && input === "o")
|
|
388
457
|
setTodoExpanded(function toggleTodoExpanded(previous) { return !previous; });
|
|
389
|
-
}, { isActive: isRawModeSupported && !pickers.isPickerActive && !snapshot.pendingApproval });
|
|
458
|
+
}, { isActive: inputEnabled && isRawModeSupported && !pickers.isPickerActive && !snapshot.pendingApproval });
|
|
390
459
|
const isLiveTurnTerminal = Boolean(snapshot.liveTurnId && isTerminalStatus(snapshot.status));
|
|
391
460
|
const inlineHistoryItems = isViewportMode ? [] : [
|
|
392
461
|
TUI_BRAND_HISTORY_ITEM,
|
|
@@ -395,16 +464,22 @@ export function CliTuiApp(props) {
|
|
|
395
464
|
return false;
|
|
396
465
|
if (item.kind === "turn")
|
|
397
466
|
return item.turnId !== snapshot.liveTurnId || isLiveTurnTerminal;
|
|
398
|
-
return
|
|
467
|
+
return true;
|
|
399
468
|
}),
|
|
400
469
|
];
|
|
401
|
-
const
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
470
|
+
const inlineOutput = inlineHistoryItems.map(function output(item) {
|
|
471
|
+
if (item.kind === "turn") {
|
|
472
|
+
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; }));
|
|
473
|
+
return { key: `${props.inlineOutputKey ?? "session"}:turn:${item.turnId}`, sequence, render: function segment(after) {
|
|
474
|
+
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; }) };
|
|
475
|
+
return _jsx(MemoizedTuiTranscriptItem, { item: segment, columns: columns, useColor: props.useColor, screenReader: props.screenReader });
|
|
476
|
+
} };
|
|
477
|
+
}
|
|
478
|
+
return { key: `${props.inlineOutputKey ?? "session"}:${item.key}`, node: item.kind === "brand"
|
|
479
|
+
? _jsx(TuiBrandHeader, { statusView: statusView, columns: columns, useColor: props.useColor, screenReader: props.screenReader, reducedMotion: true, animationActive: false })
|
|
480
|
+
: _jsx(MemoizedTuiTranscriptItem, { item: item, columns: columns, useColor: props.useColor, screenReader: props.screenReader }) };
|
|
481
|
+
});
|
|
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 ?? rows - 1, rows - 1)), overflow: "hidden", "aria-role": "list", children: [_jsx(Box, { flexDirection: "column", flexGrow: 1, flexShrink: 1, overflow: "hidden", justifyContent: !isViewportMode && !jobView && !contextView ? "flex-end" : "flex-start", children: _jsx(Box, { ref: inlineBodyRef, position: isViewportMode ? "relative" : "absolute", width: columns, flexDirection: "column", flexShrink: 0, children: 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: [_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) {
|
|
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 - (statusView ? 12 : 7))), 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, canReceiveInput: props.canReceiveInput, bindInputHandler: props.bindInputHandler, onAttachmentsChange: props.onDraftAttachmentsChange, showInput: jobView === undefined && contextView === 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: props.interactionLabel, sessionTitle: props.sessionTitle, useColor: props.useColor, screenReader: props.screenReader, selectionCharacters: selectedText.length, escapeClosesPanel: props.escapeClosesPanel })] })] })] }));
|
|
410
485
|
}
|
package/dist/tui/approval.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface CliTuiApprovalOption {
|
|
|
8
8
|
}>["decision"];
|
|
9
9
|
label: string;
|
|
10
10
|
}
|
|
11
|
-
/**
|
|
11
|
+
/** 根据待审批工具收窄菜单;旧记录缺少冻结范围时保持最保守的单次/拒绝。 */
|
|
12
12
|
export declare function createTuiApprovalOptions(pendingApproval: NonNullable<CliProjection["pendingApproval"]>): CliTuiApprovalOption[];
|
|
13
13
|
/** 以 CC 风格上下选择、回车确认渲染当前审批菜单。 */
|
|
14
14
|
export declare function TuiApprovalPrompt(props: {
|
|
@@ -16,4 +16,8 @@ export declare function TuiApprovalPrompt(props: {
|
|
|
16
16
|
selectedIndex: number;
|
|
17
17
|
useColor: boolean;
|
|
18
18
|
screenReader: boolean;
|
|
19
|
+
details?: boolean;
|
|
20
|
+
height?: number;
|
|
21
|
+
offset?: number;
|
|
22
|
+
onMaximumOffset?(maximum: number): void;
|
|
19
23
|
}): ReactNode;
|
package/dist/tui/approval.js
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
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
|
+
/** 根据待审批工具收窄菜单;旧记录缺少冻结范围时保持最保守的单次/拒绝。 */
|
|
6
8
|
export function createTuiApprovalOptions(pendingApproval) {
|
|
7
9
|
if (pendingApproval.allowedDecisions) {
|
|
10
|
+
// run_command 的工作区级授权展示为"记住此命令"(精确命令约束,与 Web 审批卡同一文案);
|
|
11
|
+
// todo_write 的单次批准即任务文件集合批准,与 Web 审批卡同一文案。
|
|
8
12
|
const labels = {
|
|
9
|
-
allow_once: "
|
|
13
|
+
allow_once: pendingApproval.toolName === "todo_write"
|
|
14
|
+
? pendingApproval.constraint === "task-ext-files:v1" ? "批准本任务外部文件修改" : "批准本任务文件修改"
|
|
15
|
+
: "允许本次",
|
|
10
16
|
allow_session: "本次会话允许",
|
|
11
|
-
allow_workspace: "此工作区允许",
|
|
17
|
+
allow_workspace: pendingApproval.toolName === "run_command" ? "记住此命令" : "此工作区允许",
|
|
12
18
|
deny: "拒绝",
|
|
13
19
|
};
|
|
14
20
|
return pendingApproval.allowedDecisions.map(function createFrozenOption(decision) { return { decision, label: labels[decision] }; });
|
|
@@ -30,8 +36,15 @@ export function createTuiApprovalOptions(pendingApproval) {
|
|
|
30
36
|
export function TuiApprovalPrompt(props) {
|
|
31
37
|
const options = createTuiApprovalOptions(props.pendingApproval);
|
|
32
38
|
const selectedIndex = Math.max(0, Math.min(props.selectedIndex, options.length - 1));
|
|
33
|
-
|
|
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 \u5916\u90E8\u8DEF\u5F84\uFF1A\u547D\u4EE4\u58F0\u660E\u4E86\u5DE5\u4F5C\u533A\u5916\u76EE\u6807\uFF0C\u4F46\u5BBF\u4E3B\u8FDB\u7A0B\u4E0D\u53D7\u8BE5\u6587\u4EF6\u8303\u56F4\u7EA6\u675F\uFF0C\u53EF\u80FD\u540C\u65F6\u5F71\u54CD\u5176\u4ED6\u6587\u4EF6\uFF1B\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.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) {
|
|
34
47
|
const selected = index === selectedIndex;
|
|
35
|
-
return _jsxs(Text, { inverse: selected && props.useColor, children: [selected ? "›" : " ", " ", option.label, selected && props.screenReader ? "(已选择)" : ""] }, option.decision);
|
|
36
|
-
}), _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" })] }));
|
|
37
50
|
}
|
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.3.0";
|
|
7
7
|
/** 品牌像素字母的完整单词。 */
|
|
8
8
|
export declare const AUTOPILOT_BRAND_WORD = "AUTOPILOT";
|
|
9
9
|
/** 开场动画总时长(毫秒)。 */
|
package/dist/tui/constants.js
CHANGED
package/dist/tui/format.d.ts
CHANGED
|
@@ -65,7 +65,7 @@ export declare function getTuiPermissionModeLabel(mode: CliStatusView["permissio
|
|
|
65
65
|
export declare function getTuiApprovalDecisionLabel(decision: Extract<CliAction, {
|
|
66
66
|
type: "approve";
|
|
67
67
|
}>["decision"]): string;
|
|
68
|
-
/** 将终端流尺寸收敛为 TUI
|
|
68
|
+
/** 将终端流尺寸收敛为 TUI 布局使用的列/行数;物理尺寸不受正文宽度策略限制。 */
|
|
69
69
|
export declare function readTuiTerminalSize(stdout: {
|
|
70
70
|
columns?: number;
|
|
71
71
|
rows?: number;
|
package/dist/tui/format.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* 已消费输入文案和终端尺寸读取。本文件不依赖任何 React 组件。
|
|
4
4
|
*/
|
|
5
5
|
import { formatAgentTermination } from "../termination-format.js";
|
|
6
|
+
import { isSandboxUnavailableErrorCode } from "@autopilot-agent/presentation";
|
|
6
7
|
/** 判断一个状态是否已经离开可继续执行的活动阶段;waiting_user_input 是可恢复等待,不算终态。 */
|
|
7
8
|
export function isTerminalStatus(status) {
|
|
8
9
|
return status !== "idle" && status !== "running" && status !== "waiting_approval" && status !== "waiting_user_input";
|
|
@@ -17,7 +18,7 @@ export function getTuiStatusLabel(status) {
|
|
|
17
18
|
case "idle": return "Ready";
|
|
18
19
|
case "running": return "Working";
|
|
19
20
|
case "waiting_approval": return "Waiting for approval";
|
|
20
|
-
case "waiting_user_input": return "Waiting for
|
|
21
|
+
case "waiting_user_input": return "Waiting for answer";
|
|
21
22
|
case "interrupted": return "Stopped";
|
|
22
23
|
case "interrupted_recoverable": return "Paused — resume available";
|
|
23
24
|
case "completed": return "Completed";
|
|
@@ -29,8 +30,14 @@ export function getTuiStatusLabel(status) {
|
|
|
29
30
|
export function getTuiTurnFailureReason(events) {
|
|
30
31
|
for (let index = events.length - 1; index >= 0; index -= 1) {
|
|
31
32
|
const event = events[index];
|
|
32
|
-
if (event?.type === "status" && event.status === "failed"
|
|
33
|
-
|
|
33
|
+
if (event?.type === "status" && event.status === "failed") {
|
|
34
|
+
const details = [
|
|
35
|
+
event.providerHttpStatus !== undefined ? `HTTP 状态:${event.providerHttpStatus}` : undefined,
|
|
36
|
+
event.providerFailureDetail ? `上游标识:${event.providerFailureDetail}` : undefined,
|
|
37
|
+
event.feedbackId ? `反馈 ID:${event.feedbackId}` : undefined,
|
|
38
|
+
].filter(Boolean);
|
|
39
|
+
return [event.reason, ...details].filter(Boolean).join(" · ") || undefined;
|
|
40
|
+
}
|
|
34
41
|
}
|
|
35
42
|
return undefined;
|
|
36
43
|
}
|
|
@@ -44,8 +51,12 @@ export function getTuiTerminationSummary(events, currentStatus) {
|
|
|
44
51
|
return undefined;
|
|
45
52
|
for (let index = events.length - 1; index >= 0; index -= 1) {
|
|
46
53
|
const event = events[index];
|
|
47
|
-
if (event?.type === "status")
|
|
48
|
-
|
|
54
|
+
if (event?.type === "status") {
|
|
55
|
+
if (!event.termination || !isRealTurnEndStatus(event.status))
|
|
56
|
+
return undefined;
|
|
57
|
+
const failureReason = event.status === "failed" ? getTuiTurnFailureReason([event]) : undefined;
|
|
58
|
+
return [failureReason, formatAgentTermination(event.termination)].filter(Boolean).join(" · ");
|
|
59
|
+
}
|
|
49
60
|
}
|
|
50
61
|
return undefined;
|
|
51
62
|
}
|
|
@@ -129,9 +140,10 @@ export function getTuiToolFailureMessage(status, errorCode, detail) {
|
|
|
129
140
|
if (status === "approval_required")
|
|
130
141
|
return "需要确认";
|
|
131
142
|
if (status === "question_required")
|
|
132
|
-
return "
|
|
143
|
+
return "等待回答,请在目标会话输入选项编号或自定义答案";
|
|
144
|
+
// 2.5:沙箱不可用类拒绝是环境阻塞而非用户拒绝,文案必须区分。
|
|
133
145
|
if (status === "denied")
|
|
134
|
-
return "已拒绝";
|
|
146
|
+
return isSandboxUnavailableErrorCode(errorCode) ? "沙箱不可用,命令未启动" : "已拒绝";
|
|
135
147
|
if (status === "cancelled")
|
|
136
148
|
return "已取消";
|
|
137
149
|
if (status === "timeout")
|
|
@@ -153,7 +165,7 @@ export function getTuiToolFailureMessage(status, errorCode, detail) {
|
|
|
153
165
|
/** 将已由 Controller 成功投递的输入统一为可读的插入提示。 */
|
|
154
166
|
export function formatTuiInputConsumed(event) {
|
|
155
167
|
const label = event.delivery === "queue" ? "[排队]" : "[引导]";
|
|
156
|
-
return `${label}
|
|
168
|
+
return `${label} 已插入当前 turn`;
|
|
157
169
|
}
|
|
158
170
|
/** 将 Core 权限模式转换为状态栏可读的中文标签。 */
|
|
159
171
|
export function getTuiPermissionModeLabel(mode) {
|
|
@@ -167,10 +179,10 @@ export function getTuiPermissionModeLabel(mode) {
|
|
|
167
179
|
export function getTuiApprovalDecisionLabel(decision) {
|
|
168
180
|
return decision === "allow_once" ? "本次" : decision === "allow_session" ? "本次会话" : decision === "allow_workspace" ? "此工作区" : "拒绝";
|
|
169
181
|
}
|
|
170
|
-
/** 将终端流尺寸收敛为 TUI
|
|
182
|
+
/** 将终端流尺寸收敛为 TUI 布局使用的列/行数;物理尺寸不受正文宽度策略限制。 */
|
|
171
183
|
export function readTuiTerminalSize(stdout) {
|
|
172
184
|
return {
|
|
173
|
-
columns: Math.max(
|
|
174
|
-
rows: Math.max(
|
|
185
|
+
columns: Math.max(1, Math.floor(Number(stdout.columns ?? 80))),
|
|
186
|
+
rows: Math.max(1, Math.floor(Number(stdout.rows ?? 24))),
|
|
175
187
|
};
|
|
176
188
|
}
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
/** prompt 输入状态与 handleInput:字符串/光标/历史维护与按键分发。 */
|
|
2
2
|
import type { Key } from "ink";
|
|
3
3
|
import type { CliAction, CliSlashCommand } from "../../types.js";
|
|
4
|
+
import { type TuiInputHistoryState } from "../../tui-input-history.js";
|
|
4
5
|
import { parseTuiControlAction } from "../input/keys.js";
|
|
5
6
|
import type { CliTuiStore } from "../types.js";
|
|
7
|
+
import { type CliDraftImage } from "../input/clipboard-image.js";
|
|
6
8
|
/** usePromptInput 的运行依赖;派生值(slash 建议、视口按键)由 app.tsx 通过 ref 注入。 */
|
|
7
9
|
export interface UsePromptInputInput {
|
|
8
10
|
store: CliTuiStore;
|
|
9
11
|
columns: number;
|
|
12
|
+
draftRef?: {
|
|
13
|
+
current?: ReturnType<typeof createPromptDraft>;
|
|
14
|
+
};
|
|
15
|
+
onAttachmentsChange?(names: string[]): void;
|
|
10
16
|
busy: {
|
|
11
17
|
current: boolean;
|
|
12
18
|
};
|
|
@@ -43,12 +49,58 @@ export interface UsePromptInputInput {
|
|
|
43
49
|
slashCommandSuggestions: CliSlashCommand[];
|
|
44
50
|
fileMentionSuggestions: string[];
|
|
45
51
|
handleTuiViewportKey: (key: Key) => boolean;
|
|
52
|
+
handleApprovalKey?: (value: string, key: Key) => boolean;
|
|
46
53
|
};
|
|
47
54
|
};
|
|
48
55
|
}
|
|
56
|
+
/** 保存已打开会话的输入状态;视图卸载时不保留React子树或正文派生计算。 */
|
|
57
|
+
declare function createPromptDraft(): {
|
|
58
|
+
inputRef: {
|
|
59
|
+
current: string;
|
|
60
|
+
};
|
|
61
|
+
cursorIndexRef: {
|
|
62
|
+
current: number;
|
|
63
|
+
};
|
|
64
|
+
verticalColumnRef: {
|
|
65
|
+
current: number | undefined;
|
|
66
|
+
};
|
|
67
|
+
bracketedPasteRef: {
|
|
68
|
+
current: boolean;
|
|
69
|
+
};
|
|
70
|
+
bracketedPasteHadContentRef: {
|
|
71
|
+
current: boolean;
|
|
72
|
+
};
|
|
73
|
+
pasteCarriageReturnRef: {
|
|
74
|
+
current: boolean;
|
|
75
|
+
};
|
|
76
|
+
inputHistoryRef: {
|
|
77
|
+
current: TuiInputHistoryState;
|
|
78
|
+
};
|
|
79
|
+
imageDraftsRef: {
|
|
80
|
+
current: Map<number, CliDraftImage>;
|
|
81
|
+
};
|
|
82
|
+
historyImagesRef: {
|
|
83
|
+
current: Array<Map<number, CliDraftImage>>;
|
|
84
|
+
};
|
|
85
|
+
historyDraftImagesRef: {
|
|
86
|
+
current: Map<number, CliDraftImage>;
|
|
87
|
+
};
|
|
88
|
+
lastSubmittedImagesRef: {
|
|
89
|
+
current: Map<number, CliDraftImage>;
|
|
90
|
+
};
|
|
91
|
+
pasteQueueRef: {
|
|
92
|
+
current: Promise<void>;
|
|
93
|
+
};
|
|
94
|
+
pastingCountRef: {
|
|
95
|
+
current: number;
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
/** Session宿主持有的草稿引用,不包含React生命周期。 */
|
|
99
|
+
export type CliTuiDraftRef = NonNullable<UsePromptInputInput["draftRef"]>;
|
|
49
100
|
/** 管理 prompt 输入状态、历史与按键分发,并暴露 handleInput 供 Ink 的 useInput 使用。 */
|
|
50
101
|
export declare function usePromptInput(input: UsePromptInputInput): {
|
|
51
102
|
input: string;
|
|
52
103
|
cursorIndex: number;
|
|
53
104
|
handleInput: (value: string, key: Key) => void;
|
|
54
105
|
};
|
|
106
|
+
export {};
|