@autopilot-agent/cli 0.2.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 +10 -5
- package/dist/activity-animation.d.ts +4 -0
- package/dist/activity-animation.js +11 -17
- package/dist/composition-root.d.ts +31 -1
- package/dist/composition-root.js +112 -3
- package/dist/context-report.d.ts +8 -3
- package/dist/context-report.js +14 -2
- package/dist/controller.d.ts +34 -4
- package/dist/controller.js +434 -90
- 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/index.d.ts +1 -1
- package/dist/main.js +142 -7
- package/dist/parser.js +498 -0
- 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 +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 +112 -40
- package/dist/tui/approval.d.ts +4 -0
- package/dist/tui/approval.js +13 -4
- 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 +19 -9
- 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 +27 -5
- 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 +1 -1
- package/dist/tui/transcript.js +19 -1
- package/dist/tui/trust-dialog.d.ts +3 -0
- package/dist/tui/trust-dialog.js +23 -2
- package/dist/tui/types.d.ts +8 -0
- package/dist/tui/types.js +4 -1
- package/dist/tui/viewport/sources.js +6 -13
- package/dist/types.d.ts +152 -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";
|
|
@@ -20,7 +22,7 @@ import { TuiInfoLines, TuiStatusLine } from "./status-line.js";
|
|
|
20
22
|
import { TuiJobs } from "./jobs.js";
|
|
21
23
|
import { TuiLiveTurn } from "./timeline/turn.js";
|
|
22
24
|
import { getTuiTurnTodo } from "./timeline/turn-items.js";
|
|
23
|
-
import { MemoizedTuiTranscriptItem, TuiPendingInputItem
|
|
25
|
+
import { MemoizedTuiTranscriptItem, TuiPendingInputItem } from "./transcript.js";
|
|
24
26
|
import { getTuiSelectedText } from "./viewport/selection.js";
|
|
25
27
|
import { createTuiViewportSourceCache } from "./viewport/sources.js";
|
|
26
28
|
import { TuiViewportTimeline } from "./viewport/viewport.js";
|
|
@@ -45,20 +47,22 @@ export function CliTuiApp(props) {
|
|
|
45
47
|
const rawInputSequenceRef = useRef("");
|
|
46
48
|
const busy = useRef(false);
|
|
47
49
|
const keepOpenAfterCancel = useRef(false);
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
+
const localLastSubmittedPromptRef = useRef(undefined);
|
|
51
|
+
const lastSubmittedPromptRef = props.viewState?.lastSubmittedPrompt ?? localLastSubmittedPromptRef;
|
|
52
|
+
const initialStarted = useRef(props.viewState?.initialStarted ?? false);
|
|
50
53
|
const lastResult = useRef(undefined);
|
|
51
54
|
const animationClockRef = useRef(undefined);
|
|
52
55
|
if (!animationClockRef.current)
|
|
53
|
-
animationClockRef.current = createTuiAnimationClock();
|
|
56
|
+
animationClockRef.current = createTuiAnimationClock({ frameMs: 120 });
|
|
54
57
|
const animationClock = animationClockRef.current;
|
|
55
58
|
/** 防抖后的终端尺寸;Ink 与应用布局共同使用同一份稳定快照。 */
|
|
56
59
|
const [terminalSize, setTerminalSize] = useState(function createTerminalSize() {
|
|
57
60
|
return readTuiTerminalSize(terminalSizeSource);
|
|
58
61
|
});
|
|
59
|
-
const isViewportMode = props.renderMode === "alternate-screen" && !props.screenReader;
|
|
60
|
-
const columns = terminalSize.columns;
|
|
61
|
-
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;
|
|
62
66
|
const { statusView, refreshStatusView } = useStatusView(props.controller);
|
|
63
67
|
/** 输入子树通过 ref 读取 slash 与 @ 建议,父级只注入视口按键处理器。 */
|
|
64
68
|
const derivedRef = useRef({
|
|
@@ -81,12 +85,53 @@ export function CliTuiApp(props) {
|
|
|
81
85
|
.filter(function isNotice(item) { return item.kind === "notice"; })
|
|
82
86
|
.slice(-4)
|
|
83
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;
|
|
84
111
|
const approvalHeight = isViewportMode && snapshot.pendingApproval ? createTuiApprovalOptions(snapshot.pendingApproval).length + 6 : 0;
|
|
85
112
|
// Todo 展开态最多占 10 行;矮终端为输入框、状态栏和活动文案至少保留 6 行。
|
|
86
113
|
const todoRowLimit = Math.max(2, Math.min(10, rows - 6));
|
|
87
114
|
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 + (statusView ?
|
|
89
|
-
const
|
|
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));
|
|
90
135
|
const viewportSourceCacheRef = useRef(undefined);
|
|
91
136
|
if (!viewportSourceCacheRef.current)
|
|
92
137
|
viewportSourceCacheRef.current = createTuiViewportSourceCache();
|
|
@@ -114,16 +159,21 @@ export function CliTuiApp(props) {
|
|
|
114
159
|
});
|
|
115
160
|
derivedRef.current.handleTuiViewportKey = handleTuiViewportKey;
|
|
116
161
|
const selectedText = isViewportMode ? getTuiSelectedText(viewportLines, selection) : "";
|
|
117
|
-
const animationActive = isRawModeSupported && stdout.isTTY !== false && terminalFocused;
|
|
162
|
+
const animationActive = snapshot.status === "running" && !snapshot.threadWait && props.visible !== false && isRawModeSupported && stdout.isTTY !== false && terminalFocused;
|
|
118
163
|
/** 把用户动作交给 Controller;结束后刷新状态栏并按投影结果打开对应 picker。 */
|
|
119
164
|
async function dispatchAction(action, prompt, preserveSkillPickerQuery = false) {
|
|
120
|
-
|
|
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);
|
|
121
171
|
if (busy.current && !allowWhileRunning)
|
|
122
172
|
return;
|
|
123
173
|
const isJobAction = action.type === "list_jobs" || action.type === "show_job" || action.type === "read_job_output" || action.type === "stop_job";
|
|
124
174
|
const jobGeneration = isJobAction ? ++jobRequestGeneration.current : undefined;
|
|
125
175
|
const inputPosition = prompt && allowWhileRunning ? props.store.captureInputPosition() : undefined;
|
|
126
|
-
if (prompt) {
|
|
176
|
+
if (prompt && !answeringQuestion) {
|
|
127
177
|
lastSubmittedPromptRef.current = prompt.trim();
|
|
128
178
|
props.store.recordPrompt(prompt, !allowWhileRunning);
|
|
129
179
|
}
|
|
@@ -134,7 +184,7 @@ export function CliTuiApp(props) {
|
|
|
134
184
|
// D2/D5:仅交互 TUI 在发送前把 @ 引用的工作区文件内容以 <system-reminder> 附加块并入 action.content;
|
|
135
185
|
// start/steer/queue/initial 四条 TUI 提交路径都经过此处,时间线与 Esc 恢复仍使用原文 prompt。
|
|
136
186
|
let dispatchedAction = action;
|
|
137
|
-
if (action.type === "submit_prompt" && prompt && props.workspaceRoot) {
|
|
187
|
+
if (action.type === "submit_prompt" && !answeringQuestion && prompt && props.workspaceRoot) {
|
|
138
188
|
const resolved = await resolveFileMentionContext(action.content, props.workspaceRoot);
|
|
139
189
|
for (const message of resolved.notices)
|
|
140
190
|
props.store.addNotice(message);
|
|
@@ -151,7 +201,7 @@ export function CliTuiApp(props) {
|
|
|
151
201
|
kind: "error",
|
|
152
202
|
exitCode: 1,
|
|
153
203
|
lines: [],
|
|
154
|
-
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",
|
|
155
205
|
projection: props.controller.getProjection(),
|
|
156
206
|
};
|
|
157
207
|
}
|
|
@@ -210,7 +260,7 @@ export function CliTuiApp(props) {
|
|
|
210
260
|
useEffect(function subscribeTerminalResize() {
|
|
211
261
|
const onResize = terminalSizeSource.on;
|
|
212
262
|
const offResize = terminalSizeSource.off;
|
|
213
|
-
if (!onResize || !offResize)
|
|
263
|
+
if (props.availableColumns !== undefined || !onResize || !offResize)
|
|
214
264
|
return;
|
|
215
265
|
let timer;
|
|
216
266
|
function commitTerminalSize() {
|
|
@@ -235,16 +285,26 @@ export function CliTuiApp(props) {
|
|
|
235
285
|
};
|
|
236
286
|
}, [isViewportMode, terminalSizeSource]);
|
|
237
287
|
useLayoutEffect(function syncTerminalSizeToInk() {
|
|
238
|
-
props.
|
|
288
|
+
if (props.availableColumns === undefined)
|
|
289
|
+
props.onTerminalSizeChange?.(terminalSize);
|
|
239
290
|
}, [terminalSize, props.onTerminalSizeChange]);
|
|
240
291
|
useEffect(function bindTuiMouseInput() {
|
|
241
|
-
|
|
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);
|
|
242
300
|
return function unbindTuiMouseInput() {
|
|
243
301
|
props.mouseInput?.setHandler(undefined);
|
|
244
302
|
};
|
|
245
|
-
}, [props.mouseInput, isViewportMode, columns, viewportHeight, viewportLines.length]);
|
|
303
|
+
}, [inputEnabled, props.mouseInput, isViewportMode, columns, viewportHeight, viewportLines.length]);
|
|
246
304
|
useEffect(function resetApprovalSelection() {
|
|
247
305
|
pickers.updateApprovalPickerIndex(0);
|
|
306
|
+
setApprovalOffset(0);
|
|
307
|
+
setApprovalDetails(false);
|
|
248
308
|
}, [snapshot.pendingApproval?.approvalId]);
|
|
249
309
|
useEffect(function disposeTuiAnimationClock() {
|
|
250
310
|
return function disposeAnimationClock() {
|
|
@@ -256,13 +316,10 @@ export function CliTuiApp(props) {
|
|
|
256
316
|
setSnapshot(props.store.getSnapshot());
|
|
257
317
|
});
|
|
258
318
|
}, [props.store]);
|
|
259
|
-
|
|
319
|
+
// 同一提交的Turn/用量变化只触发一次刷新;在途变化由hook合并到下一次查询。
|
|
320
|
+
useEffect(function refreshStatusOnTurnAndUsageChange() {
|
|
260
321
|
void refreshStatusView();
|
|
261
|
-
}, [
|
|
262
|
-
// 用量事件到达时重新查询状态栏,让 context 行在 Turn 运行中也能反映三态变化。
|
|
263
|
-
useEffect(function refreshStatusOnContextUsage() {
|
|
264
|
-
void refreshStatusView();
|
|
265
|
-
}, [props.controller, snapshot.contextUsage]);
|
|
322
|
+
}, [refreshStatusView, snapshot.status, snapshot.liveTurnId, snapshot.contextUsage]);
|
|
266
323
|
useEffect(function subscribeStdinEnd() {
|
|
267
324
|
function handleStdinEnd() {
|
|
268
325
|
props.onEof();
|
|
@@ -300,6 +357,8 @@ export function CliTuiApp(props) {
|
|
|
300
357
|
if (initialStarted.current || !props.initial)
|
|
301
358
|
return;
|
|
302
359
|
initialStarted.current = true;
|
|
360
|
+
if (props.viewState)
|
|
361
|
+
props.viewState.initialStarted = true;
|
|
303
362
|
if (props.initial.type === "start") {
|
|
304
363
|
void dispatchAction({ type: "submit_prompt", content: props.initial.content }, props.initial.content);
|
|
305
364
|
}
|
|
@@ -312,12 +371,13 @@ export function CliTuiApp(props) {
|
|
|
312
371
|
try {
|
|
313
372
|
result = await props.controller.resume();
|
|
314
373
|
}
|
|
315
|
-
catch {
|
|
374
|
+
catch (error) {
|
|
375
|
+
recordTuiRuntimeErrorDiagnostic(error);
|
|
316
376
|
result = {
|
|
317
377
|
kind: "error",
|
|
318
378
|
exitCode: 1,
|
|
319
379
|
lines: [],
|
|
320
|
-
message: "CLI_RUNTIME_ERROR",
|
|
380
|
+
message: classifyCliError(error).category === "node_state" ? `${classifyCliError(error).code}:会话保存未完成,请检查存储可用性后重试;原记录保留` : "CLI_RUNTIME_ERROR",
|
|
321
381
|
projection: props.controller.getProjection(),
|
|
322
382
|
};
|
|
323
383
|
}
|
|
@@ -341,6 +401,8 @@ export function CliTuiApp(props) {
|
|
|
341
401
|
}, [props.closeWhenIdle, snapshot.status, snapshot.requestedExitCode]);
|
|
342
402
|
/** 在 Job 视图内复用 Ink 输入路由;Esc 只返回视图,不取消 Turn 或退出进程。 */
|
|
343
403
|
useInput(function handleJobInput(value, key) {
|
|
404
|
+
if (props.canReceiveInput?.(value, key) === false)
|
|
405
|
+
return;
|
|
344
406
|
const current = jobViewRef.current;
|
|
345
407
|
if (!current)
|
|
346
408
|
return;
|
|
@@ -377,19 +439,23 @@ export function CliTuiApp(props) {
|
|
|
377
439
|
void dispatchAction({ type: "stop_job", jobId: current.job.jobId });
|
|
378
440
|
else if (value === "r")
|
|
379
441
|
void dispatchAction({ type: current.output ? "read_job_output" : "show_job", jobId: current.job.jobId });
|
|
380
|
-
}, { isActive: isRawModeSupported && jobView !== undefined });
|
|
442
|
+
}, { isActive: inputEnabled && isRawModeSupported && jobView !== undefined });
|
|
381
443
|
/** 在 Context 覆盖视图内复用 Ink 输入路由;Esc 只关闭视图回到聊天,不取消 Turn 或退出进程。 */
|
|
382
444
|
useInput(function handleContextInput(value, key) {
|
|
445
|
+
if (props.canReceiveInput?.(value, key) === false)
|
|
446
|
+
return;
|
|
383
447
|
if (contextView === undefined)
|
|
384
448
|
return;
|
|
385
449
|
if (key.escape || value === "\u001b")
|
|
386
450
|
setContextView(undefined);
|
|
387
|
-
}, { isActive: isRawModeSupported && contextView !== undefined });
|
|
451
|
+
}, { isActive: inputEnabled && isRawModeSupported && contextView !== undefined });
|
|
388
452
|
// Ctrl+O 只切换 Todo 展开视图;picker 与审批等待打开时让位,避免按键语义冲突。
|
|
389
453
|
useInput(function handleTodoExpandInput(input, key) {
|
|
454
|
+
if (props.canReceiveInput?.(input, key) === false)
|
|
455
|
+
return;
|
|
390
456
|
if (key.ctrl && input === "o")
|
|
391
457
|
setTodoExpanded(function toggleTodoExpanded(previous) { return !previous; });
|
|
392
|
-
}, { isActive: isRawModeSupported && !pickers.isPickerActive && !snapshot.pendingApproval });
|
|
458
|
+
}, { isActive: inputEnabled && isRawModeSupported && !pickers.isPickerActive && !snapshot.pendingApproval });
|
|
393
459
|
const isLiveTurnTerminal = Boolean(snapshot.liveTurnId && isTerminalStatus(snapshot.status));
|
|
394
460
|
const inlineHistoryItems = isViewportMode ? [] : [
|
|
395
461
|
TUI_BRAND_HISTORY_ITEM,
|
|
@@ -398,16 +464,22 @@ export function CliTuiApp(props) {
|
|
|
398
464
|
return false;
|
|
399
465
|
if (item.kind === "turn")
|
|
400
466
|
return item.turnId !== snapshot.liveTurnId || isLiveTurnTerminal;
|
|
401
|
-
return
|
|
467
|
+
return true;
|
|
402
468
|
}),
|
|
403
469
|
];
|
|
404
|
-
const
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
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 })] })] })] }));
|
|
413
485
|
}
|
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 \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) {
|
|
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
|
}
|
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
|
@@ -18,7 +18,7 @@ export function getTuiStatusLabel(status) {
|
|
|
18
18
|
case "idle": return "Ready";
|
|
19
19
|
case "running": return "Working";
|
|
20
20
|
case "waiting_approval": return "Waiting for approval";
|
|
21
|
-
case "waiting_user_input": return "Waiting for
|
|
21
|
+
case "waiting_user_input": return "Waiting for answer";
|
|
22
22
|
case "interrupted": return "Stopped";
|
|
23
23
|
case "interrupted_recoverable": return "Paused — resume available";
|
|
24
24
|
case "completed": return "Completed";
|
|
@@ -30,8 +30,14 @@ export function getTuiStatusLabel(status) {
|
|
|
30
30
|
export function getTuiTurnFailureReason(events) {
|
|
31
31
|
for (let index = events.length - 1; index >= 0; index -= 1) {
|
|
32
32
|
const event = events[index];
|
|
33
|
-
if (event?.type === "status" && event.status === "failed"
|
|
34
|
-
|
|
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
|
+
}
|
|
35
41
|
}
|
|
36
42
|
return undefined;
|
|
37
43
|
}
|
|
@@ -45,8 +51,12 @@ export function getTuiTerminationSummary(events, currentStatus) {
|
|
|
45
51
|
return undefined;
|
|
46
52
|
for (let index = events.length - 1; index >= 0; index -= 1) {
|
|
47
53
|
const event = events[index];
|
|
48
|
-
if (event?.type === "status")
|
|
49
|
-
|
|
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
|
+
}
|
|
50
60
|
}
|
|
51
61
|
return undefined;
|
|
52
62
|
}
|
|
@@ -130,7 +140,7 @@ export function getTuiToolFailureMessage(status, errorCode, detail) {
|
|
|
130
140
|
if (status === "approval_required")
|
|
131
141
|
return "需要确认";
|
|
132
142
|
if (status === "question_required")
|
|
133
|
-
return "
|
|
143
|
+
return "等待回答,请在目标会话输入选项编号或自定义答案";
|
|
134
144
|
// 2.5:沙箱不可用类拒绝是环境阻塞而非用户拒绝,文案必须区分。
|
|
135
145
|
if (status === "denied")
|
|
136
146
|
return isSandboxUnavailableErrorCode(errorCode) ? "沙箱不可用,命令未启动" : "已拒绝";
|
|
@@ -169,10 +179,10 @@ export function getTuiPermissionModeLabel(mode) {
|
|
|
169
179
|
export function getTuiApprovalDecisionLabel(decision) {
|
|
170
180
|
return decision === "allow_once" ? "本次" : decision === "allow_session" ? "本次会话" : decision === "allow_workspace" ? "此工作区" : "拒绝";
|
|
171
181
|
}
|
|
172
|
-
/** 将终端流尺寸收敛为 TUI
|
|
182
|
+
/** 将终端流尺寸收敛为 TUI 布局使用的列/行数;物理尺寸不受正文宽度策略限制。 */
|
|
173
183
|
export function readTuiTerminalSize(stdout) {
|
|
174
184
|
return {
|
|
175
|
-
columns: Math.max(
|
|
176
|
-
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))),
|
|
177
187
|
};
|
|
178
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 {};
|