@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** prompt 输入状态与 handleInput:字符串/光标/历史维护与按键分发。 */
|
|
2
|
-
import {
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
3
|
import { parseSlashAction } from "../../parser.js";
|
|
4
4
|
import { canNavigateTuiInputHistory, createTuiInputHistoryState, navigateTuiInputHistory, recordTuiInputHistory, updateTuiInputHistoryDraft, } from "../../tui-input-history.js";
|
|
5
5
|
import { createTuiApprovalOptions } from "../approval.js";
|
|
@@ -9,20 +9,93 @@ import { applyFileMentionSuggestion, extractFileMentionToken } from "../input/fi
|
|
|
9
9
|
import { hasTuiUnescapedContinuation, isTuiMultilineEnter, isTuiTerminalFocusSequence, isTuiViewportScrollKey, parseTuiControlAction, resolveTuiBracketedPasteBoundary, resolveTuiDeleteDirection, } from "../input/keys.js";
|
|
10
10
|
import { createTuiPromptLayout, resolveTuiPromptCursorIndex } from "../input/prompt-layout.js";
|
|
11
11
|
import { recordTuiPerformanceDiagnostic } from "../performance-diagnostics.js";
|
|
12
|
+
import { readMacClipboard, readWindowsClipboard } from "../input/clipboard-image.js";
|
|
13
|
+
/** 保存已打开会话的输入状态;视图卸载时不保留React子树或正文派生计算。 */
|
|
14
|
+
function createPromptDraft() {
|
|
15
|
+
return {
|
|
16
|
+
inputRef: { current: "" }, cursorIndexRef: { current: 0 },
|
|
17
|
+
verticalColumnRef: { current: undefined }, bracketedPasteRef: { current: false },
|
|
18
|
+
bracketedPasteHadContentRef: { current: false }, pasteCarriageReturnRef: { current: false },
|
|
19
|
+
inputHistoryRef: { current: createTuiInputHistoryState() },
|
|
20
|
+
imageDraftsRef: { current: new Map() }, historyImagesRef: { current: [] },
|
|
21
|
+
historyDraftImagesRef: { current: new Map() }, lastSubmittedImagesRef: { current: new Map() },
|
|
22
|
+
pasteQueueRef: { current: Promise.resolve() }, pastingCountRef: { current: 0 },
|
|
23
|
+
};
|
|
24
|
+
}
|
|
12
25
|
/** 管理 prompt 输入状态、历史与按键分发,并暴露 handleInput 供 Ink 的 useInput 使用。 */
|
|
13
26
|
export function usePromptInput(input) {
|
|
14
27
|
const { store, columns, busy, keepOpenAfterCancel, lastSubmittedPromptRef, rawInputSequenceRef, dispatchAction, onEof, onRequestInterrupt, onRequestCancel, isPickerActive, dispatchPickerInput, approvalPickerIndexRef, updateApprovalPickerIndex, slashCommandIndexRef, updateSlashCommandIndex, fileMentionIndexRef, updateFileMentionIndex, setFileMentionDismissedInput, derivedRef, } = input;
|
|
15
|
-
const [
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const cursorIndexRef =
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
28
|
+
const [draft] = useState(function initialDraft() { return input.draftRef?.current ?? createPromptDraft(); });
|
|
29
|
+
if (input.draftRef)
|
|
30
|
+
input.draftRef.current = draft;
|
|
31
|
+
const { inputRef, cursorIndexRef, verticalColumnRef, bracketedPasteRef, bracketedPasteHadContentRef, pasteCarriageReturnRef, inputHistoryRef, imageDraftsRef, historyImagesRef, historyDraftImagesRef, lastSubmittedImagesRef, pasteQueueRef, pastingCountRef } = draft;
|
|
32
|
+
const [inputValue, setInput] = useState(inputRef.current);
|
|
33
|
+
const [cursorIndex, setCursorIndex] = useState(cursorIndexRef.current);
|
|
34
|
+
/** 定位当前草稿中有附件身份的占位符,以 grapheme 位置保护原子编辑。 */
|
|
35
|
+
function imageSpans(value) {
|
|
36
|
+
const spans = [];
|
|
37
|
+
for (const match of value.matchAll(/\[Image (\d+)\]/g)) {
|
|
38
|
+
const id = Number(match[1]);
|
|
39
|
+
if (!imageDraftsRef.current.has(id))
|
|
40
|
+
continue;
|
|
41
|
+
const start = splitTuiInputGraphemes(value.slice(0, match.index)).length;
|
|
42
|
+
spans.push({ id, start, end: start + match[0].length });
|
|
43
|
+
}
|
|
44
|
+
return spans;
|
|
45
|
+
}
|
|
46
|
+
/** 把异步读取的剪贴板图片及文本按次序插入当前光标。 */
|
|
47
|
+
function pasteClipboard() {
|
|
48
|
+
pastingCountRef.current++;
|
|
49
|
+
const pending = (process.platform === "darwin" ? readMacClipboard() : readWindowsClipboard()).then(function read(value) { return { value }; }, function failed(error) { return { error }; });
|
|
50
|
+
pasteQueueRef.current = pasteQueueRef.current.then(async function insertPaste() {
|
|
51
|
+
try {
|
|
52
|
+
const outcome = await pending;
|
|
53
|
+
if ("error" in outcome)
|
|
54
|
+
throw outcome.error;
|
|
55
|
+
const result = outcome.value;
|
|
56
|
+
const currentCount = imageSpans(inputRef.current).length;
|
|
57
|
+
if (currentCount + result.images.length > 10)
|
|
58
|
+
throw new Error("一次最多发送 10 张图片");
|
|
59
|
+
const currentBytes = imageSpans(inputRef.current).reduce(function total(sum, span) { return sum + (imageDraftsRef.current.get(span.id)?.bytes.byteLength ?? 0); }, 0);
|
|
60
|
+
if (currentBytes + result.images.reduce(function total(sum, image) { return sum + image.bytes.byteLength; }, 0) > 20 * 1024 * 1024)
|
|
61
|
+
throw new Error("图片总大小超过 20 MiB");
|
|
62
|
+
if (result.images.some(function isGif(image) { return image.gifFirstFrame; }))
|
|
63
|
+
store.addNotice("GIF 图片仅发送静态首帧");
|
|
64
|
+
let inserted = result.text ?? "";
|
|
65
|
+
for (const image of result.images) {
|
|
66
|
+
const id = Math.max(0, ...imageDraftsRef.current.keys()) + 1;
|
|
67
|
+
imageDraftsRef.current.set(id, image);
|
|
68
|
+
inserted += `${inserted ? " " : ""}[Image ${id}]`;
|
|
69
|
+
}
|
|
70
|
+
if (!inserted)
|
|
71
|
+
return;
|
|
72
|
+
const chars = splitTuiInputGraphemes(inputRef.current);
|
|
73
|
+
const inside = imageSpans(inputRef.current).find(function contains(span) { return cursorIndexRef.current > span.start && cursorIndexRef.current < span.end; });
|
|
74
|
+
const cursor = inside?.end ?? cursorIndexRef.current;
|
|
75
|
+
const addition = splitTuiInputGraphemes(inserted);
|
|
76
|
+
chars.splice(cursor, 0, ...addition);
|
|
77
|
+
const next = chars.join("");
|
|
78
|
+
inputHistoryRef.current = updateTuiInputHistoryDraft(inputHistoryRef.current, next);
|
|
79
|
+
updateInput(next, cursor + addition.length);
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
const safeMessages = ["一次最多发送 10 张图片", "一次最多粘贴 10 张图片", "剪贴板包含不支持的文件", "图片超过 20 MiB 输入上限", "图片总大小超过 20 MiB"];
|
|
83
|
+
store.addNotice(error instanceof Error && safeMessages.includes(error.message) ? error.message : "剪贴板图片读取或处理失败");
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
pastingCountRef.current--;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
23
90
|
/** 同步维护字符串与光标位置,避免只移动光标时 React 跳过重绘;输入变化即解除 @ 菜单的 Esc 关闭标记。 */
|
|
24
91
|
function updateInput(nextInput, nextCursorIndex) {
|
|
25
92
|
verticalColumnRef.current = undefined;
|
|
93
|
+
for (const id of imageDraftsRef.current.keys())
|
|
94
|
+
if (!nextInput.includes(`[Image ${id}]`))
|
|
95
|
+
imageDraftsRef.current.delete(id);
|
|
96
|
+
const inside = imageSpans(nextInput).find(function contains(span) { return nextCursorIndex > span.start && nextCursorIndex < span.end; });
|
|
97
|
+
if (inside)
|
|
98
|
+
nextCursorIndex = inside.end;
|
|
26
99
|
inputRef.current = nextInput;
|
|
27
100
|
cursorIndexRef.current = nextCursorIndex;
|
|
28
101
|
setFileMentionDismissedInput(undefined);
|
|
@@ -31,6 +104,9 @@ export function usePromptInput(input) {
|
|
|
31
104
|
}
|
|
32
105
|
/** 只移动逻辑光标,不清除上下键要保持的目标视觉列。 */
|
|
33
106
|
function updateCursorIndex(nextCursorIndex) {
|
|
107
|
+
const inside = imageSpans(inputRef.current).find(function contains(span) { return nextCursorIndex > span.start && nextCursorIndex < span.end; });
|
|
108
|
+
if (inside)
|
|
109
|
+
nextCursorIndex = inside.end;
|
|
34
110
|
cursorIndexRef.current = nextCursorIndex;
|
|
35
111
|
setCursorIndex(nextCursorIndex);
|
|
36
112
|
}
|
|
@@ -45,8 +121,10 @@ export function usePromptInput(input) {
|
|
|
45
121
|
const prompt = lastSubmittedPromptRef.current;
|
|
46
122
|
if (!prompt || inputRef.current !== "" || current.pendingInputs.length > 0)
|
|
47
123
|
return;
|
|
124
|
+
imageDraftsRef.current = new Map(lastSubmittedImagesRef.current);
|
|
48
125
|
updateInput(prompt, splitTuiInputGraphemes(prompt).length);
|
|
49
126
|
}
|
|
127
|
+
/** 分发终端按键并保持图片占位符与草稿身份一致。 */
|
|
50
128
|
function handleInput(value, key) {
|
|
51
129
|
recordTuiPerformanceDiagnostic("input_key_arrived", value && !key.ctrl && !key.meta ? "text" : "control");
|
|
52
130
|
const controlAction = parseTuiControlAction(value, key);
|
|
@@ -66,18 +144,30 @@ export function usePromptInput(input) {
|
|
|
66
144
|
const pasteBoundary = resolveTuiBracketedPasteBoundary(value);
|
|
67
145
|
if (pasteBoundary === "start") {
|
|
68
146
|
bracketedPasteRef.current = true;
|
|
147
|
+
bracketedPasteHadContentRef.current = false;
|
|
69
148
|
pasteCarriageReturnRef.current = false;
|
|
70
149
|
return;
|
|
71
150
|
}
|
|
72
151
|
if (pasteBoundary === "end") {
|
|
73
152
|
bracketedPasteRef.current = false;
|
|
74
153
|
pasteCarriageReturnRef.current = false;
|
|
154
|
+
if (!bracketedPasteHadContentRef.current && (process.platform === "win32" || process.platform === "darwin"))
|
|
155
|
+
pasteClipboard();
|
|
75
156
|
return;
|
|
76
157
|
}
|
|
158
|
+
if (bracketedPasteRef.current && (value || key.return))
|
|
159
|
+
bracketedPasteHadContentRef.current = true;
|
|
77
160
|
if (isPickerActive) {
|
|
78
161
|
dispatchPickerInput(value, key, controlAction);
|
|
79
162
|
return;
|
|
80
163
|
}
|
|
164
|
+
if (current.status !== "waiting_approval" && !bracketedPasteRef.current && (process.platform === "win32" || process.platform === "darwin") && ((key.ctrl && value.toLowerCase() === "v") || (key.meta && value.toLowerCase() === "v") || value === "\u0016")) {
|
|
165
|
+
pasteClipboard();
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
// 审批详情是当前顶层交互,翻页/关闭不穿透到历史滚动或 Turn 取消。
|
|
169
|
+
if (current.status === "waiting_approval" && current.pendingApproval && derivedRef.current.handleApprovalKey?.(value, key))
|
|
170
|
+
return;
|
|
81
171
|
if (controlAction === "cancel") {
|
|
82
172
|
// D3:@ 菜单激活时 Esc 仅关闭菜单,prompt 保留;再次 Esc 时菜单已关,走正常取消路径。
|
|
83
173
|
if (derivedRef.current.fileMentionSuggestions.length > 0) {
|
|
@@ -171,6 +261,15 @@ export function usePromptInput(input) {
|
|
|
171
261
|
const removeIndex = deleteDirection === "backspace" ? cursor - 1 : cursor;
|
|
172
262
|
if (removeIndex < 0 || removeIndex >= characters.length)
|
|
173
263
|
return;
|
|
264
|
+
const image = imageSpans(inputRef.current).find(function contains(span) { return removeIndex >= span.start && removeIndex < span.end; });
|
|
265
|
+
if (image) {
|
|
266
|
+
characters.splice(image.start, image.end - image.start);
|
|
267
|
+
imageDraftsRef.current.delete(image.id);
|
|
268
|
+
const next = characters.join("");
|
|
269
|
+
inputHistoryRef.current = updateTuiInputHistoryDraft(inputHistoryRef.current, next);
|
|
270
|
+
updateInput(next, image.start);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
174
273
|
characters.splice(removeIndex, 1);
|
|
175
274
|
const nextInput = characters.join("");
|
|
176
275
|
inputHistoryRef.current = updateTuiInputHistoryDraft(inputHistoryRef.current, nextInput);
|
|
@@ -178,11 +277,13 @@ export function usePromptInput(input) {
|
|
|
178
277
|
return;
|
|
179
278
|
}
|
|
180
279
|
if (key.leftArrow) {
|
|
181
|
-
|
|
280
|
+
const image = imageSpans(inputRef.current).find(function atEnd(span) { return cursorIndexRef.current > span.start && cursorIndexRef.current <= span.end; });
|
|
281
|
+
updateInput(inputRef.current, image?.start ?? Math.max(0, cursorIndexRef.current - 1));
|
|
182
282
|
return;
|
|
183
283
|
}
|
|
184
284
|
if (key.rightArrow) {
|
|
185
|
-
|
|
285
|
+
const image = imageSpans(inputRef.current).find(function atStart(span) { return cursorIndexRef.current >= span.start && cursorIndexRef.current < span.end; });
|
|
286
|
+
updateInput(inputRef.current, image?.end ?? Math.min(splitTuiInputGraphemes(inputRef.current).length, cursorIndexRef.current + 1));
|
|
186
287
|
return;
|
|
187
288
|
}
|
|
188
289
|
if (key.upArrow || key.downArrow) {
|
|
@@ -198,9 +299,13 @@ export function usePromptInput(input) {
|
|
|
198
299
|
}
|
|
199
300
|
const historyDirection = key.upArrow ? "up" : "down";
|
|
200
301
|
const canNavigateHistory = canNavigateTuiInputHistory(historyDirection, layout.cursorLine, layout.lines.length, inputHistoryRef.current.index !== undefined, false);
|
|
302
|
+
const previousIndex = inputHistoryRef.current.index;
|
|
303
|
+
if (canNavigateHistory && previousIndex === undefined)
|
|
304
|
+
historyDraftImagesRef.current = new Map(imageDraftsRef.current);
|
|
201
305
|
const navigation = navigateTuiInputHistory(inputHistoryRef.current, historyDirection, inputRef.current, canNavigateHistory);
|
|
202
|
-
if (navigation.changed) {
|
|
306
|
+
if (navigation.changed || navigation.state.index !== previousIndex) {
|
|
203
307
|
inputHistoryRef.current = navigation.state;
|
|
308
|
+
imageDraftsRef.current = new Map(navigation.state.index === undefined ? historyDraftImagesRef.current : historyImagesRef.current[navigation.state.index] ?? []);
|
|
204
309
|
updateInput(navigation.input, splitTuiInputGraphemes(navigation.input).length);
|
|
205
310
|
}
|
|
206
311
|
return;
|
|
@@ -227,26 +332,46 @@ export function usePromptInput(input) {
|
|
|
227
332
|
}
|
|
228
333
|
pasteCarriageReturnRef.current = false;
|
|
229
334
|
if (key.return) {
|
|
335
|
+
if (pastingCountRef.current > 0) {
|
|
336
|
+
store.addNotice("图片仍在处理,请稍候发送");
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
230
339
|
const content = inputRef.current.trim();
|
|
231
|
-
updateInput("", 0);
|
|
232
340
|
if (!content)
|
|
233
341
|
return;
|
|
342
|
+
const spans = imageSpans(content);
|
|
343
|
+
if (new Set(spans.map(function id(span) { return span.id; })).size !== spans.length) {
|
|
344
|
+
store.addNotice("图片占位符重复,请删除重复内容");
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
const images = spans.map(function image(span) { return imageDraftsRef.current.get(span.id); });
|
|
348
|
+
const parsed = parseSlashAction(content);
|
|
349
|
+
if (parsed.kind === "error") {
|
|
350
|
+
store.addNotice(parsed.message);
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
if (images.length && parsed.action.type !== "submit_prompt") {
|
|
354
|
+
store.addNotice("图片不能附加到命令,请先发送或删除图片");
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
if (parsed.action.type === "submit_prompt") {
|
|
358
|
+
lastSubmittedImagesRef.current = new Map(imageDraftsRef.current);
|
|
359
|
+
historyImagesRef.current = [...historyImagesRef.current, new Map(imageDraftsRef.current)].slice(-100);
|
|
360
|
+
}
|
|
361
|
+
updateInput("", 0);
|
|
362
|
+
imageDraftsRef.current = new Map();
|
|
234
363
|
void (async function dispatchEnteredLine() {
|
|
235
|
-
const parsed = parseSlashAction(content);
|
|
236
|
-
if (parsed.kind === "error") {
|
|
237
|
-
store.addNotice(parsed.message);
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
364
|
const prompt = parsed.action.type === "submit_prompt" ? parsed.action.content : undefined;
|
|
241
365
|
if (prompt)
|
|
242
366
|
inputHistoryRef.current = recordTuiInputHistory(inputHistoryRef.current, prompt);
|
|
243
|
-
await dispatchAction(parsed.action, prompt);
|
|
367
|
+
await dispatchAction(parsed.action.type === "submit_prompt" && images.length ? { ...parsed.action, images } : parsed.action, prompt);
|
|
244
368
|
})();
|
|
245
369
|
return;
|
|
246
370
|
}
|
|
247
371
|
if (value && !key.ctrl && !key.meta) {
|
|
248
372
|
const characters = splitTuiInputGraphemes(inputRef.current);
|
|
249
|
-
const
|
|
373
|
+
const inside = imageSpans(inputRef.current).find(function contains(span) { return cursorIndexRef.current > span.start && cursorIndexRef.current < span.end; });
|
|
374
|
+
const cursor = inside?.end ?? cursorIndexRef.current;
|
|
250
375
|
const inserted = splitTuiInputGraphemes(normalizeTuiInputLineEndings(value));
|
|
251
376
|
characters.splice(cursor, 0, ...inserted);
|
|
252
377
|
const nextInput = characters.join("");
|
|
@@ -254,5 +379,8 @@ export function usePromptInput(input) {
|
|
|
254
379
|
updateInput(nextInput, cursor + inserted.length);
|
|
255
380
|
}
|
|
256
381
|
}
|
|
382
|
+
const attachmentNames = [...imageDraftsRef.current.values()].map(function name(image) { return image.name; });
|
|
383
|
+
/** 附件区只投影当前草稿的既有图片名,不复制图片字节或触发采样。 */
|
|
384
|
+
useEffect(function publishAttachments() { input.onAttachmentsChange?.(attachmentNames); }, [attachmentNames.join("\0"), input.onAttachmentsChange]);
|
|
257
385
|
return { input: inputValue, cursorIndex, handleInput };
|
|
258
386
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/** statusView
|
|
1
|
+
/** statusView异步刷新hook:合并同批/在途刷新,切换和卸载失效旧订阅。 */
|
|
2
2
|
import type { CliController } from "../../controller.js";
|
|
3
3
|
import type { CliStatusView } from "../../types.js";
|
|
4
|
-
/**
|
|
4
|
+
/** 每挂载持有独立取消身份;一次查询期间的新刷新最多合并成一次后续查询。 */
|
|
5
5
|
export declare function useStatusView(controller: CliController): {
|
|
6
6
|
statusView: CliStatusView | undefined;
|
|
7
7
|
refreshStatusView: () => Promise<void>;
|
|
@@ -1,13 +1,40 @@
|
|
|
1
|
-
/** statusView
|
|
2
|
-
import { useState } from "react";
|
|
3
|
-
/**
|
|
1
|
+
/** statusView异步刷新hook:合并同批/在途刷新,切换和卸载失效旧订阅。 */
|
|
2
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
3
|
+
/** 每挂载持有独立取消身份;一次查询期间的新刷新最多合并成一次后续查询。 */
|
|
4
4
|
export function useStatusView(controller) {
|
|
5
|
-
const [
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
const [state, setState] = useState();
|
|
6
|
+
const lifecycle = useMemo(function createLifecycle() {
|
|
7
|
+
return { active: true, abort: new AbortController(), requested: false, pending: undefined };
|
|
8
|
+
}, [controller]);
|
|
9
|
+
useEffect(function bindStatusLifecycle() {
|
|
10
|
+
lifecycle.active = true;
|
|
11
|
+
if (lifecycle.abort.signal.aborted)
|
|
12
|
+
lifecycle.abort = new AbortController();
|
|
13
|
+
return function cancelStatusLifecycle() {
|
|
14
|
+
lifecycle.active = false;
|
|
15
|
+
lifecycle.requested = false;
|
|
16
|
+
lifecycle.abort.abort();
|
|
17
|
+
};
|
|
18
|
+
}, [lifecycle]);
|
|
19
|
+
const refreshStatusView = useCallback(async function refreshStatusView() {
|
|
20
|
+
if (!lifecycle.active || !controller.getStatusView)
|
|
21
|
+
return;
|
|
22
|
+
lifecycle.requested = true;
|
|
23
|
+
if (!lifecycle.pending) {
|
|
24
|
+
// 微任务合并同次提交触发的刷新,不额外叠加时间节流。
|
|
25
|
+
lifecycle.pending = Promise.resolve().then(async function drainStatusRefreshes() {
|
|
26
|
+
while (lifecycle.active && lifecycle.requested) {
|
|
27
|
+
lifecycle.requested = false;
|
|
28
|
+
try {
|
|
29
|
+
const next = await controller.getStatusView?.({ signal: lifecycle.abort.signal });
|
|
30
|
+
if (next && lifecycle.active && !lifecycle.abort.signal.aborted)
|
|
31
|
+
setState({ controller, value: next });
|
|
32
|
+
}
|
|
33
|
+
catch { /* 查询失败或失效不写入其他Session,也不产生未处理拒绝。 */ }
|
|
34
|
+
}
|
|
35
|
+
}).finally(function releaseStatusRefresh() { lifecycle.pending = undefined; });
|
|
36
|
+
}
|
|
37
|
+
await lifecycle.pending;
|
|
38
|
+
}, [controller, lifecycle]);
|
|
39
|
+
return { statusView: state?.controller === controller ? state.value : undefined, refreshStatusView };
|
|
13
40
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** 单窗口唯一追加输出所有者:跨会话与resize保持Static挂载,稳定键只输出一次。 */
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
|
+
interface InlineItem {
|
|
4
|
+
key: string;
|
|
5
|
+
node?: ReactNode;
|
|
6
|
+
sequence?: number;
|
|
7
|
+
render?(after?: number): ReactNode;
|
|
8
|
+
}
|
|
9
|
+
/** 在会话壳之外持有追加列表,避免子会话卸载导致历史重放。 */
|
|
10
|
+
export declare function TuiInlineOutputOwner(props: {
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
}): ReactNode;
|
|
13
|
+
/** 只提交新稳定内容,父所有者存在时不创建第二个Static。 */
|
|
14
|
+
export declare function TuiInlineOutput(props: {
|
|
15
|
+
items: InlineItem[];
|
|
16
|
+
}): ReactNode;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/** 单窗口唯一追加输出所有者:跨会话与resize保持Static挂载,稳定键只输出一次。 */
|
|
3
|
+
import { createContext, useCallback, useContext, useLayoutEffect, useRef, useState } from "react";
|
|
4
|
+
import { Box, Static } from "ink";
|
|
5
|
+
const InlineOutputContext = createContext(undefined);
|
|
6
|
+
/** 在会话壳之外持有追加列表,避免子会话卸载导致历史重放。 */
|
|
7
|
+
export function TuiInlineOutputOwner(props) {
|
|
8
|
+
const seen = useRef(new Map());
|
|
9
|
+
const [items, setItems] = useState([]);
|
|
10
|
+
const append = useCallback(function append(next) {
|
|
11
|
+
const fresh = [];
|
|
12
|
+
for (const item of next) {
|
|
13
|
+
const previous = seen.current.get(item.key);
|
|
14
|
+
if (seen.current.has(item.key) && (item.sequence === undefined || item.sequence <= (previous ?? -1)))
|
|
15
|
+
continue;
|
|
16
|
+
seen.current.set(item.key, item.sequence);
|
|
17
|
+
fresh.push({ key: `${item.key}:${item.sequence ?? "once"}`, node: item.render ? item.render(previous) : item.node });
|
|
18
|
+
}
|
|
19
|
+
if (fresh.length)
|
|
20
|
+
setItems(function add(current) { return [...current, ...fresh]; });
|
|
21
|
+
}, []);
|
|
22
|
+
return _jsxs(InlineOutputContext.Provider, { value: append, children: [_jsx(Static, { items: items, children: function render(item) { return _jsx(Box, { flexDirection: "column", children: item.node }, item.key); } }), props.children] });
|
|
23
|
+
}
|
|
24
|
+
/** 只提交新稳定内容,父所有者存在时不创建第二个Static。 */
|
|
25
|
+
export function TuiInlineOutput(props) {
|
|
26
|
+
const append = useContext(InlineOutputContext);
|
|
27
|
+
useLayoutEffect(function publish() { append?.(props.items); }, [append, props.items]);
|
|
28
|
+
if (append)
|
|
29
|
+
return null;
|
|
30
|
+
return _jsx(TuiInlineOutputOwner, { children: _jsx(TuiInlineOutput, { ...props }) });
|
|
31
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** 待发送的有界图片副本。 */
|
|
2
|
+
export interface CliDraftImage {
|
|
3
|
+
name: string;
|
|
4
|
+
mimeType: string;
|
|
5
|
+
bytes: Uint8Array;
|
|
6
|
+
gifFirstFrame?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/** 使用 STA 剪贴板读取文件列表或截图;普通文本作为文本返回。 */
|
|
9
|
+
export declare function readWindowsClipboard(): Promise<{
|
|
10
|
+
images: CliDraftImage[];
|
|
11
|
+
text?: string;
|
|
12
|
+
}>;
|
|
13
|
+
/** 使用 macOS 自带的 JXA 和 AppKit 按需读取文件列表、位图或普通文本。 */
|
|
14
|
+
export declare function readMacClipboard(): Promise<{
|
|
15
|
+
images: CliDraftImage[];
|
|
16
|
+
text?: string;
|
|
17
|
+
}>;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/** Windows 与 macOS 剪贴板图片摄取:仅读取显式粘贴事件,不后台轮询。 */
|
|
2
|
+
import { execFile } from "node:child_process";
|
|
3
|
+
import { readFile, stat } from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { promisify } from "node:util";
|
|
6
|
+
import { normalizeWorkImage } from "@autopilot-agent/core";
|
|
7
|
+
const runFile = promisify(execFile);
|
|
8
|
+
/** 使用 STA 剪贴板读取文件列表或截图;普通文本作为文本返回。 */
|
|
9
|
+
export async function readWindowsClipboard() {
|
|
10
|
+
if (process.platform !== "win32")
|
|
11
|
+
return { images: [] };
|
|
12
|
+
const script = `[Console]::OutputEncoding = [Text.Encoding]::UTF8
|
|
13
|
+
Add-Type -AssemblyName System.Windows.Forms
|
|
14
|
+
Add-Type -AssemblyName System.Drawing
|
|
15
|
+
if ([Windows.Forms.Clipboard]::ContainsFileDropList()) {
|
|
16
|
+
@{ kind = 'files'; value = @([Windows.Forms.Clipboard]::GetFileDropList() | ForEach-Object { $_ }) } | ConvertTo-Json -Compress
|
|
17
|
+
} elseif ([Windows.Forms.Clipboard]::ContainsImage()) {
|
|
18
|
+
$image = [Windows.Forms.Clipboard]::GetImage()
|
|
19
|
+
$stream = New-Object IO.MemoryStream
|
|
20
|
+
try { if (([long]$image.Width * [long]$image.Height) -gt 40000000) { throw 'IMAGE_TOO_LARGE' }; $image.Save($stream, [Drawing.Imaging.ImageFormat]::Png); if ($stream.Length -gt 20971520) { throw 'IMAGE_TOO_LARGE' }; @{ kind = 'image'; value = [Convert]::ToBase64String($stream.ToArray()) } | ConvertTo-Json -Compress } finally { $stream.Dispose(); $image.Dispose() }
|
|
21
|
+
} elseif ([Windows.Forms.Clipboard]::ContainsText()) {
|
|
22
|
+
@{ kind = 'text'; value = [Windows.Forms.Clipboard]::GetText() } | ConvertTo-Json -Compress
|
|
23
|
+
} else { @{ kind = 'empty'; value = '' } | ConvertTo-Json -Compress }`;
|
|
24
|
+
const { stdout } = await runFile("powershell.exe", ["-NoProfile", "-NonInteractive", "-STA", "-Command", script], { windowsHide: true, maxBuffer: 29 * 1024 * 1024, timeout: 15_000 });
|
|
25
|
+
const payload = JSON.parse(stdout);
|
|
26
|
+
return normalizeClipboardPayload(payload);
|
|
27
|
+
}
|
|
28
|
+
/** 使用 macOS 自带的 JXA 和 AppKit 按需读取文件列表、位图或普通文本。 */
|
|
29
|
+
export async function readMacClipboard() {
|
|
30
|
+
if (process.platform !== "darwin")
|
|
31
|
+
return { images: [] };
|
|
32
|
+
const script = `ObjC.import('AppKit');
|
|
33
|
+
function exists(value) { var unwrapped = ObjC.unwrap(value); return unwrapped !== null && unwrapped !== undefined; }
|
|
34
|
+
function run() {
|
|
35
|
+
var board = $.NSPasteboard.generalPasteboard;
|
|
36
|
+
var urls = board.readObjectsForClassesOptions($.NSArray.arrayWithObject($.NSURL), $.NSDictionary.dictionaryWithObjectForKey($.NSNumber.numberWithBool(true), $.NSPasteboardURLReadingFileURLsOnlyKey));
|
|
37
|
+
if (exists(urls) && Number(urls.count) > 0) {
|
|
38
|
+
if (Number(urls.count) > 10) throw new Error('TOO_MANY_IMAGES');
|
|
39
|
+
var files = [];
|
|
40
|
+
for (var i = 0; i < Number(urls.count); i++) files.push(ObjC.unwrap(urls.objectAtIndex(i).path));
|
|
41
|
+
return JSON.stringify({kind: 'files', value: files});
|
|
42
|
+
}
|
|
43
|
+
var data = board.dataForType($.NSPasteboardTypePNG);
|
|
44
|
+
if (!exists(data)) data = board.dataForType($.NSPasteboardTypeTIFF);
|
|
45
|
+
if (exists(data)) {
|
|
46
|
+
if (Number(data.length) > 20971520) throw new Error('IMAGE_TOO_LARGE');
|
|
47
|
+
var rep = $.NSBitmapImageRep.imageRepWithData(data);
|
|
48
|
+
if (!exists(rep) || Number(rep.pixelsWide) * Number(rep.pixelsHigh) > 40000000) throw new Error('IMAGE_TOO_LARGE');
|
|
49
|
+
var png = rep.representationUsingTypeProperties($.NSBitmapImageFileTypePNG, $.NSDictionary.dictionary);
|
|
50
|
+
if (!exists(png) || Number(png.length) > 20971520) throw new Error('IMAGE_TOO_LARGE');
|
|
51
|
+
var text = board.stringForType($.NSPasteboardTypeString);
|
|
52
|
+
return JSON.stringify({kind: 'image', value: ObjC.unwrap(png.base64EncodedStringWithOptions(0)), text: exists(text) ? ObjC.unwrap(text) : undefined});
|
|
53
|
+
}
|
|
54
|
+
var text = board.stringForType($.NSPasteboardTypeString);
|
|
55
|
+
return JSON.stringify(exists(text) ? {kind: 'text', value: ObjC.unwrap(text)} : {kind: 'empty', value: ''});
|
|
56
|
+
}`;
|
|
57
|
+
let payload;
|
|
58
|
+
try {
|
|
59
|
+
const { stdout } = await runFile("/usr/bin/osascript", ["-l", "JavaScript", "-e", script], { maxBuffer: 29 * 1024 * 1024, timeout: 15_000 });
|
|
60
|
+
payload = JSON.parse(stdout);
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
const stderr = error && typeof error === "object" && "stderr" in error && typeof error.stderr === "string" ? error.stderr : "";
|
|
64
|
+
if (stderr.includes("TOO_MANY_IMAGES"))
|
|
65
|
+
throw new Error("一次最多粘贴 10 张图片");
|
|
66
|
+
if (stderr.includes("IMAGE_TOO_LARGE"))
|
|
67
|
+
throw new Error("图片超过 20 MiB 输入上限");
|
|
68
|
+
throw new Error("剪贴板图片读取或处理失败");
|
|
69
|
+
}
|
|
70
|
+
if (!payload || typeof payload !== "object" || (payload.text !== undefined && typeof payload.text !== "string"))
|
|
71
|
+
throw new Error("剪贴板图片读取或处理失败");
|
|
72
|
+
if (payload.kind === "image" && (typeof payload.value !== "string" || !payload.value.length || payload.value.length > 27_962_028 || payload.value.length % 4 !== 0 || !/^[A-Za-z0-9+/]*={0,2}$/.test(payload.value)))
|
|
73
|
+
throw new Error("剪贴板图片读取或处理失败");
|
|
74
|
+
if (payload.kind === "files" && (!Array.isArray(payload.value) || payload.value.some(function invalid(value) { return typeof value !== "string" || !value; })))
|
|
75
|
+
throw new Error("剪贴板图片读取或处理失败");
|
|
76
|
+
if ((payload.kind === "text" || payload.kind === "empty") && typeof payload.value !== "string")
|
|
77
|
+
throw new Error("剪贴板图片读取或处理失败");
|
|
78
|
+
if (!["image", "files", "text", "empty"].includes(String(payload.kind)))
|
|
79
|
+
throw new Error("剪贴板图片读取或处理失败");
|
|
80
|
+
return normalizeClipboardPayload(payload);
|
|
81
|
+
}
|
|
82
|
+
/** 复用同一有界文件读取和图片规范化,保持两平台的输入限制一致。 */
|
|
83
|
+
async function normalizeClipboardPayload(payload) {
|
|
84
|
+
if (payload.kind === "text")
|
|
85
|
+
return { images: [], text: typeof payload.value === "string" ? payload.value : "" };
|
|
86
|
+
const candidates = [];
|
|
87
|
+
if (payload.kind === "image" && typeof payload.value === "string")
|
|
88
|
+
candidates.push({ name: "clipboard.png", mimeType: "image/png", bytes: Buffer.from(payload.value, "base64") });
|
|
89
|
+
if (payload.kind === "files") {
|
|
90
|
+
const files = Array.isArray(payload.value) ? payload.value : [payload.value];
|
|
91
|
+
if (files.length > 10)
|
|
92
|
+
throw new Error("一次最多粘贴 10 张图片");
|
|
93
|
+
for (const file of files) {
|
|
94
|
+
const extension = path.extname(file).toLowerCase();
|
|
95
|
+
const mimeType = extension === ".png" ? "image/png" : extension === ".jpg" || extension === ".jpeg" ? "image/jpeg" : extension === ".webp" ? "image/webp" : extension === ".gif" ? "image/gif" : "";
|
|
96
|
+
if (!mimeType)
|
|
97
|
+
throw new Error("剪贴板包含不支持的文件");
|
|
98
|
+
const info = await stat(file);
|
|
99
|
+
if (!info.isFile() || info.size > 20 * 1024 * 1024)
|
|
100
|
+
throw new Error("图片超过 20 MiB 输入上限");
|
|
101
|
+
const bytes = await readFile(file);
|
|
102
|
+
if (bytes.length !== info.size)
|
|
103
|
+
throw new Error("图片读取失败");
|
|
104
|
+
candidates.push({ name: path.basename(file), mimeType, bytes });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const images = [];
|
|
108
|
+
let total = 0;
|
|
109
|
+
for (const candidate of candidates) {
|
|
110
|
+
const normalized = await normalizeWorkImage(candidate);
|
|
111
|
+
total += normalized.bytes.byteLength;
|
|
112
|
+
if (total > 20 * 1024 * 1024)
|
|
113
|
+
throw new Error("图片总大小超过 20 MiB");
|
|
114
|
+
images.push({ name: candidate.name, mimeType: normalized.mimeType, bytes: normalized.bytes, gifFirstFrame: normalized.gifFirstFrame });
|
|
115
|
+
}
|
|
116
|
+
return { images, ...(typeof payload.text === "string" ? { text: payload.text } : {}) };
|
|
117
|
+
}
|
package/dist/tui/input-area.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { type Key } from "ink";
|
|
3
3
|
import type { CliAction, CliSlashCommand } from "../types.js";
|
|
4
4
|
import { usePickers } from "./hooks/use-pickers.js";
|
|
5
|
+
import { type CliTuiDraftRef } from "./hooks/use-prompt-input.js";
|
|
5
6
|
import type { FileMentionIndex } from "./hooks/use-file-mention-index.js";
|
|
6
7
|
import type { CliTuiStore } from "./types.js";
|
|
7
8
|
/** 输入区与父级之间共享的稳定 ref;普通按键不需要把输入正文写回父级。 */
|
|
@@ -9,6 +10,7 @@ export interface TuiInputDerivedState {
|
|
|
9
10
|
slashCommandSuggestions: CliSlashCommand[];
|
|
10
11
|
fileMentionSuggestions: string[];
|
|
11
12
|
handleTuiViewportKey: (key: Key) => boolean;
|
|
13
|
+
handleApprovalKey?: (value: string, key: Key) => boolean;
|
|
12
14
|
}
|
|
13
15
|
/** React ref 形状;输入子树与父级共享同一份派生值容器。 */
|
|
14
16
|
export type TuiInputDerivedRef = {
|
|
@@ -23,7 +25,9 @@ type TuiDispatchAction = (action: CliAction, prompt?: string, preserveSkillPicke
|
|
|
23
25
|
/** 将 prompt 状态、输入分发和 picker 展示隔离到独立子树。 */
|
|
24
26
|
export declare const TuiInputArea: import("react").NamedExoticComponent<{
|
|
25
27
|
store: CliTuiStore;
|
|
28
|
+
draftRef?: CliTuiDraftRef;
|
|
26
29
|
columns: number;
|
|
30
|
+
maximumPromptRows?: number;
|
|
27
31
|
busy: {
|
|
28
32
|
current: boolean;
|
|
29
33
|
};
|
|
@@ -42,6 +46,10 @@ export declare const TuiInputArea: import("react").NamedExoticComponent<{
|
|
|
42
46
|
onRequestCancel: () => void;
|
|
43
47
|
isRawModeSupported: boolean;
|
|
44
48
|
isInputActive: boolean;
|
|
49
|
+
/** 每次按键按宿主实时模式再检查,不能只依赖render时isActive。 */
|
|
50
|
+
canReceiveInput?(value?: string, key?: Key): boolean;
|
|
51
|
+
bindInputHandler?(handler: ((value: string, key: Key) => void) | undefined): void;
|
|
52
|
+
onAttachmentsChange?(names: string[]): void;
|
|
45
53
|
showInput: boolean;
|
|
46
54
|
useColor: boolean;
|
|
47
55
|
screenReader: boolean;
|
package/dist/tui/input-area.js
CHANGED
|
@@ -34,8 +34,10 @@ function getTuiPickerHeight(input) {
|
|
|
34
34
|
export const TuiInputArea = memo(function TuiInputArea(props) {
|
|
35
35
|
const pickers = props.pickers;
|
|
36
36
|
const { input, cursorIndex, handleInput } = usePromptInput({
|
|
37
|
+
draftRef: props.draftRef,
|
|
37
38
|
store: props.store,
|
|
38
39
|
columns: props.columns,
|
|
40
|
+
onAttachmentsChange: props.onAttachmentsChange,
|
|
39
41
|
busy: props.busy,
|
|
40
42
|
keepOpenAfterCancel: props.keepOpenAfterCancel,
|
|
41
43
|
lastSubmittedPromptRef: props.lastSubmittedPromptRef,
|
|
@@ -63,7 +65,7 @@ export const TuiInputArea = memo(function TuiInputArea(props) {
|
|
|
63
65
|
? filterFileMentionCandidates(props.fileMentionIndex?.entries ?? [], fileMentionToken.query)
|
|
64
66
|
: [];
|
|
65
67
|
props.derivedRef.current.fileMentionSuggestions = fileMentionSuggestions;
|
|
66
|
-
const promptHeight = props.showInput ? createTuiPromptLayout(input, cursorIndex, Math.max(1, props.columns - 4)).lines.length + 3 : 0;
|
|
68
|
+
const promptHeight = props.showInput ? Math.min(props.maximumPromptRows ?? Infinity, createTuiPromptLayout(input, cursorIndex, Math.max(1, props.columns - 4)).lines.length) + 3 : 0;
|
|
67
69
|
const pickerHeight = props.showInput
|
|
68
70
|
? getTuiPickerHeight({ permissions: pickers.permissionPickerOptions, models: pickers.modelPickerOptions, efforts: pickers.effortPickerOptions, skills: pickers.skillPickerSkills, slashCommands: slashCommandSuggestions, fileMentionCandidates: fileMentionSuggestions })
|
|
69
71
|
: 0;
|
|
@@ -82,8 +84,21 @@ export const TuiInputArea = memo(function TuiInputArea(props) {
|
|
|
82
84
|
useEffect(function resetFileMentionSelection() {
|
|
83
85
|
pickers.updateFileMentionIndex(0);
|
|
84
86
|
}, [fileMentionSuggestions.join("\u0000")]);
|
|
85
|
-
|
|
87
|
+
/** React订阅尚未刷新时仍拒绝旧会话/列表已消费事件,原草稿和光标保持不变。 */
|
|
88
|
+
function handleActiveInput(value, key) {
|
|
89
|
+
if (props.canReceiveInput?.(value, key) === false)
|
|
90
|
+
return;
|
|
91
|
+
handleInput(value, key);
|
|
92
|
+
}
|
|
93
|
+
/** 根输入桥在layout提交时就绪,不依赖新会话useInput的被动订阅时序。 */
|
|
94
|
+
useLayoutEffect(function bindCurrentInput() {
|
|
95
|
+
if (!props.bindInputHandler)
|
|
96
|
+
return;
|
|
97
|
+
props.bindInputHandler(props.isRawModeSupported && props.isInputActive ? handleActiveInput : undefined);
|
|
98
|
+
return function unbind() { props.bindInputHandler?.(undefined); };
|
|
99
|
+
});
|
|
100
|
+
useInput(handleActiveInput, { isActive: !props.bindInputHandler && props.isRawModeSupported && props.isInputActive });
|
|
86
101
|
if (!props.showInput)
|
|
87
102
|
return null;
|
|
88
|
-
return _jsxs(_Fragment, { children: [_jsx(TuiPromptInput, { input: input, cursorIndex: cursorIndex, columns: props.columns, useColor: props.useColor, screenReader: props.screenReader, busy: props.busy.current }), pickers.permissionPickerOptions ? (_jsx(TuiPermissionPicker, { options: pickers.permissionPickerOptions, selectedIndex: pickers.permissionPickerIndex, useColor: props.useColor, screenReader: props.screenReader })) : pickers.modelPickerOptions ? (_jsx(TuiModelPicker, { options: pickers.modelPickerOptions, selectedIndex: pickers.modelPickerIndex, useColor: props.useColor, screenReader: props.screenReader })) : pickers.effortPickerOptions ? (_jsx(TuiEffortPicker, { options: pickers.effortPickerOptions, selectedIndex: pickers.effortPickerIndex, useColor: props.useColor, screenReader: props.screenReader })) : pickers.skillPickerSkills ? (_jsx(TuiSkillPicker, { skills: pickers.skillPickerSkills, query: pickers.skillPickerQuery, selectedIndex: pickers.skillPickerIndex, useColor: props.useColor, screenReader: props.screenReader })) : slashCommandSuggestions.length > 0 ? (_jsx(TuiSlashCommandMenu, { commands: slashCommandSuggestions, selectedIndex: pickers.slashCommandIndex, useColor: props.useColor, screenReader: props.screenReader })) : fileMentionSuggestions.length > 0 ? (_jsx(TuiFileMentionMenu, { candidates: fileMentionSuggestions, selectedIndex: pickers.fileMentionIndex, useColor: props.useColor, screenReader: props.screenReader })) : null] });
|
|
103
|
+
return _jsxs(_Fragment, { children: [_jsx(TuiPromptInput, { maximumRows: props.maximumPromptRows, input: input, cursorIndex: cursorIndex, columns: props.columns, useColor: props.useColor, screenReader: props.screenReader, busy: props.busy.current }), pickers.permissionPickerOptions ? (_jsx(TuiPermissionPicker, { options: pickers.permissionPickerOptions, selectedIndex: pickers.permissionPickerIndex, useColor: props.useColor, screenReader: props.screenReader })) : pickers.modelPickerOptions ? (_jsx(TuiModelPicker, { options: pickers.modelPickerOptions, selectedIndex: pickers.modelPickerIndex, useColor: props.useColor, screenReader: props.screenReader })) : pickers.effortPickerOptions ? (_jsx(TuiEffortPicker, { options: pickers.effortPickerOptions, selectedIndex: pickers.effortPickerIndex, useColor: props.useColor, screenReader: props.screenReader })) : pickers.skillPickerSkills ? (_jsx(TuiSkillPicker, { skills: pickers.skillPickerSkills, query: pickers.skillPickerQuery, selectedIndex: pickers.skillPickerIndex, useColor: props.useColor, screenReader: props.screenReader })) : slashCommandSuggestions.length > 0 ? (_jsx(TuiSlashCommandMenu, { commands: slashCommandSuggestions, selectedIndex: pickers.slashCommandIndex, useColor: props.useColor, screenReader: props.screenReader })) : fileMentionSuggestions.length > 0 ? (_jsx(TuiFileMentionMenu, { candidates: fileMentionSuggestions, selectedIndex: pickers.fileMentionIndex, useColor: props.useColor, screenReader: props.screenReader })) : null] });
|
|
89
104
|
});
|
package/dist/tui/lifecycle.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** TUI 终端生命周期:鼠标事件入口、Ink stdin 包装与幂等的控制序列生命周期。 */
|
|
2
2
|
import { PassThrough } from "node:stream";
|
|
3
|
-
import { TUI_ALTERNATE_SCREEN_DISABLE, TUI_ALTERNATE_SCREEN_ENABLE, TUI_BRACKETED_PASTE_DISABLE, TUI_BRACKETED_PASTE_ENABLE,
|
|
3
|
+
import { TUI_ALTERNATE_SCREEN_DISABLE, TUI_ALTERNATE_SCREEN_ENABLE, TUI_BRACKETED_PASTE_DISABLE, TUI_BRACKETED_PASTE_ENABLE, TUI_MOUSE_TRACKING_DISABLE, TUI_MOUSE_TRACKING_ENABLE, TUI_TERMINAL_FOCUS_DISABLE, TUI_TERMINAL_FOCUS_ENABLE, } from "./constants.js";
|
|
4
4
|
/** Ink 使用的稳定尺寸输出代理;它转发写入并在新布局提交后通知 resize。 */
|
|
5
5
|
class StableTuiOutputStream {
|
|
6
6
|
source;
|
|
@@ -31,15 +31,12 @@ class StableTuiOutputStream {
|
|
|
31
31
|
this.resizeListeners.delete(listener);
|
|
32
32
|
return this;
|
|
33
33
|
}
|
|
34
|
-
/** 更新 Ink
|
|
34
|
+
/** 更新 Ink 后续布局使用的稳定尺寸,并交由 Ink 自身失效旧输出缓存后重绘。 */
|
|
35
35
|
setSize(size) {
|
|
36
36
|
const changed = size.columns !== this.size.columns || size.rows !== this.size.rows;
|
|
37
|
-
const widthDecreased = size.columns < this.size.columns;
|
|
38
37
|
this.size = size;
|
|
39
38
|
if (!changed)
|
|
40
39
|
return;
|
|
41
|
-
if (widthDecreased)
|
|
42
|
-
this.source.write(TUI_INLINE_RESIZE_CLEAR);
|
|
43
40
|
for (const listener of this.resizeListeners)
|
|
44
41
|
listener();
|
|
45
42
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** unified diff 的逐行着色渲染;保持与 Web 的 edit_file 展示语义一致。 */
|
|
2
2
|
import { type ReactNode } from "react";
|
|
3
|
-
/**
|
|
3
|
+
/** 复用既有逐行渲染元素,避免同一diff重挂载时重新split和创建节点。 */
|
|
4
4
|
export declare function TuiDiffBlock(props: {
|
|
5
5
|
diff: string;
|
|
6
6
|
keyPrefix: string;
|