@autopilot-agent/cli 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -6
- package/dist/activity-animation.d.ts +5 -0
- package/dist/activity-animation.js +13 -17
- package/dist/browser-client.d.ts +14 -0
- package/dist/browser-client.js +156 -0
- package/dist/composition-root.d.ts +41 -1
- package/dist/composition-root.js +141 -14
- package/dist/context-report.d.ts +9 -4
- package/dist/context-report.js +15 -3
- package/dist/controller.d.ts +81 -4
- package/dist/controller.js +468 -98
- package/dist/design-tokens.d.ts +7 -2
- package/dist/design-tokens.js +11 -3
- package/dist/desktop-status.d.ts +35 -0
- package/dist/desktop-status.js +304 -0
- package/dist/error-diagnostics.d.ts +2 -0
- package/dist/error-diagnostics.js +3 -1
- package/dist/event-projector.d.ts +16 -2
- package/dist/event-projector.js +74 -5
- package/dist/file-mention-budget.d.ts +16 -0
- package/dist/file-mention-budget.js +82 -0
- package/dist/file-mention-context.d.ts +26 -1
- package/dist/file-mention-context.js +70 -22
- package/dist/index.d.ts +1 -1
- package/dist/main.d.ts +3 -0
- package/dist/main.js +213 -12
- package/dist/managed-attach.d.ts +3 -0
- package/dist/managed-attach.js +132 -0
- package/dist/managed-controller.d.ts +49 -0
- package/dist/managed-controller.js +171 -0
- package/dist/orchestration-templates.d.ts +27 -0
- package/dist/orchestration-templates.js +20 -0
- package/dist/parser.d.ts +1 -1
- package/dist/parser.js +510 -2
- package/dist/renderer.js +3 -1
- package/dist/session-summary.d.ts +7 -0
- package/dist/session-summary.js +25 -0
- package/dist/session-title.d.ts +5 -0
- package/dist/session-title.js +10 -0
- package/dist/thread-commands.d.ts +37 -0
- package/dist/thread-commands.js +233 -0
- package/dist/thread-host.d.ts +36 -0
- package/dist/thread-host.js +79 -0
- package/dist/timeline-lines.js +36 -28
- package/dist/tui/app.d.ts +22 -0
- package/dist/tui/app.js +179 -43
- package/dist/tui/approval.d.ts +4 -0
- package/dist/tui/approval.js +13 -4
- package/dist/tui/brand/brand-header.d.ts +1 -3
- package/dist/tui/brand/brand-header.js +6 -8
- package/dist/tui/brand/logo.d.ts +3 -0
- package/dist/tui/brand/logo.js +89 -0
- package/dist/tui/brand/startup.d.ts +18 -0
- package/dist/tui/brand/startup.js +136 -0
- package/dist/tui/constants.d.ts +1 -1
- package/dist/tui/constants.js +1 -1
- package/dist/tui/context.js +1 -3
- package/dist/tui/desktop-resize.d.ts +9 -0
- package/dist/tui/desktop-resize.js +95 -0
- package/dist/tui/format.d.ts +1 -1
- package/dist/tui/format.js +19 -9
- package/dist/tui/hooks/use-file-mention-index.js +9 -4
- package/dist/tui/hooks/use-prompt-input.d.ts +54 -1
- package/dist/tui/hooks/use-prompt-input.js +159 -26
- package/dist/tui/hooks/use-status-view.d.ts +2 -2
- package/dist/tui/hooks/use-status-view.js +38 -11
- package/dist/tui/hooks/use-viewport.d.ts +2 -1
- package/dist/tui/hooks/use-viewport.js +15 -8
- package/dist/tui/inline-output.d.ts +17 -0
- package/dist/tui/inline-output.js +31 -0
- package/dist/tui/input/clipboard-image.d.ts +17 -0
- package/dist/tui/input/clipboard-image.js +117 -0
- package/dist/tui/input-area.d.ts +12 -1
- package/dist/tui/input-area.js +28 -8
- package/dist/tui/lifecycle.d.ts +1 -1
- package/dist/tui/lifecycle.js +84 -16
- package/dist/tui/markdown/diff.d.ts +1 -1
- package/dist/tui/markdown/diff.js +28 -1
- package/dist/tui/performance-diagnostics.js +2 -0
- package/dist/tui/pickers/permission.js +1 -1
- package/dist/tui/pickers/slash.d.ts +11 -2
- package/dist/tui/pickers/slash.js +21 -7
- package/dist/tui/prompt-input.d.ts +2 -0
- package/dist/tui/prompt-input.js +6 -4
- package/dist/tui/render-mode.d.ts +8 -4
- package/dist/tui/render-mode.js +17 -11
- package/dist/tui/run.js +53 -55
- package/dist/tui/session-manager.d.ts +116 -0
- package/dist/tui/session-manager.js +384 -0
- package/dist/tui/session-workspace.d.ts +9 -0
- package/dist/tui/session-workspace.js +383 -0
- package/dist/tui/status-line.d.ts +4 -0
- package/dist/tui/status-line.js +34 -13
- package/dist/tui/store.d.ts +3 -1
- package/dist/tui/store.js +60 -14
- package/dist/tui/timeline/live.js +2 -3
- package/dist/tui/timeline/progress.js +3 -2
- package/dist/tui/timeline/static-timeline.js +1 -2
- package/dist/tui/timeline/turn.js +3 -2
- package/dist/tui/transcript.d.ts +2 -1
- package/dist/tui/transcript.js +43 -5
- package/dist/tui/trust-dialog.d.ts +3 -0
- package/dist/tui/trust-dialog.js +23 -2
- package/dist/tui/types.d.ts +18 -1
- package/dist/tui/types.js +4 -1
- package/dist/tui/viewport/selection.d.ts +2 -2
- package/dist/tui/viewport/selection.js +13 -6
- package/dist/tui/viewport/sources.js +13 -14
- package/dist/types.d.ts +160 -3
- package/package.json +4 -4
package/dist/tui/input-area.d.ts
CHANGED
|
@@ -2,13 +2,15 @@
|
|
|
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;普通按键不需要把输入正文写回父级。 */
|
|
8
9
|
export interface TuiInputDerivedState {
|
|
9
10
|
slashCommandSuggestions: CliSlashCommand[];
|
|
10
11
|
fileMentionSuggestions: string[];
|
|
11
|
-
handleTuiViewportKey: (key: Key) => boolean;
|
|
12
|
+
handleTuiViewportKey: (key: Key, value?: string) => boolean;
|
|
13
|
+
handleApprovalKey?: (value: string, key: Key) => boolean;
|
|
12
14
|
}
|
|
13
15
|
/** React ref 形状;输入子树与父级共享同一份派生值容器。 */
|
|
14
16
|
export type TuiInputDerivedRef = {
|
|
@@ -23,7 +25,12 @@ 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
|
+
parseInput?: import("../controller.js").CliController["parseInput"];
|
|
29
|
+
suggestSlashCommands?: import("../controller.js").CliController["suggestSlashCommands"];
|
|
30
|
+
draftRef?: CliTuiDraftRef;
|
|
26
31
|
columns: number;
|
|
32
|
+
availableRows: number;
|
|
33
|
+
maximumPromptRows?: number;
|
|
27
34
|
busy: {
|
|
28
35
|
current: boolean;
|
|
29
36
|
};
|
|
@@ -42,6 +49,10 @@ export declare const TuiInputArea: import("react").NamedExoticComponent<{
|
|
|
42
49
|
onRequestCancel: () => void;
|
|
43
50
|
isRawModeSupported: boolean;
|
|
44
51
|
isInputActive: boolean;
|
|
52
|
+
/** 每次按键按宿主实时模式再检查,不能只依赖render时isActive。 */
|
|
53
|
+
canReceiveInput?(value?: string, key?: Key): boolean;
|
|
54
|
+
bindInputHandler?(handler: ((value: string, key: Key) => void) | undefined): void;
|
|
55
|
+
onAttachmentsChange?(names: string[]): void;
|
|
45
56
|
showInput: boolean;
|
|
46
57
|
useColor: boolean;
|
|
47
58
|
screenReader: boolean;
|
package/dist/tui/input-area.js
CHANGED
|
@@ -12,7 +12,7 @@ import { TuiFileMentionMenu, TUI_FILE_MENTION_VISIBLE_ROWS } from "./pickers/fil
|
|
|
12
12
|
import { TuiModelPicker } from "./pickers/model.js";
|
|
13
13
|
import { TuiPermissionPicker } from "./pickers/permission.js";
|
|
14
14
|
import { TuiSkillPicker } from "./pickers/skill.js";
|
|
15
|
-
import { TuiSlashCommandMenu } from "./pickers/slash.js";
|
|
15
|
+
import { getTuiSlashMenuLayout, TuiSlashCommandMenu } from "./pickers/slash.js";
|
|
16
16
|
import { TuiPromptInput } from "./prompt-input.js";
|
|
17
17
|
/** 根据当前 picker 估算固定区高度,供备用屏计算可用视口高度。 */
|
|
18
18
|
function getTuiPickerHeight(input) {
|
|
@@ -24,8 +24,8 @@ function getTuiPickerHeight(input) {
|
|
|
24
24
|
return input.efforts.length + 5;
|
|
25
25
|
if (input.skills)
|
|
26
26
|
return Math.min(8, input.skills.length) + 8;
|
|
27
|
-
if (input.
|
|
28
|
-
return input.
|
|
27
|
+
if (input.slashMenuHeight > 0)
|
|
28
|
+
return input.slashMenuHeight;
|
|
29
29
|
if (input.fileMentionCandidates.length > 0)
|
|
30
30
|
return Math.min(TUI_FILE_MENTION_VISIBLE_ROWS, input.fileMentionCandidates.length) + 5;
|
|
31
31
|
return 0;
|
|
@@ -34,8 +34,11 @@ 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
|
+
parseInput: props.parseInput,
|
|
38
|
+
draftRef: props.draftRef,
|
|
37
39
|
store: props.store,
|
|
38
40
|
columns: props.columns,
|
|
41
|
+
onAttachmentsChange: props.onAttachmentsChange,
|
|
39
42
|
busy: props.busy,
|
|
40
43
|
keepOpenAfterCancel: props.keepOpenAfterCancel,
|
|
41
44
|
lastSubmittedPromptRef: props.lastSubmittedPromptRef,
|
|
@@ -55,7 +58,7 @@ export const TuiInputArea = memo(function TuiInputArea(props) {
|
|
|
55
58
|
setFileMentionDismissedInput: pickers.setFileMentionDismissedInput,
|
|
56
59
|
derivedRef: props.derivedRef,
|
|
57
60
|
});
|
|
58
|
-
const slashCommandSuggestions = getSlashCommandSuggestions(input);
|
|
61
|
+
const slashCommandSuggestions = (props.suggestSlashCommands ?? getSlashCommandSuggestions)(input);
|
|
59
62
|
props.derivedRef.current.slashCommandSuggestions = slashCommandSuggestions;
|
|
60
63
|
// @ 菜单派生:索引就绪且未被 Esc 关闭时,按当前 token 的四档评分过滤候选池。
|
|
61
64
|
const fileMentionToken = props.fileMentionIndex?.ready ? extractFileMentionToken(input, cursorIndex) : null;
|
|
@@ -63,9 +66,13 @@ export const TuiInputArea = memo(function TuiInputArea(props) {
|
|
|
63
66
|
? filterFileMentionCandidates(props.fileMentionIndex?.entries ?? [], fileMentionToken.query)
|
|
64
67
|
: [];
|
|
65
68
|
props.derivedRef.current.fileMentionSuggestions = fileMentionSuggestions;
|
|
66
|
-
const
|
|
69
|
+
const promptRows = Math.min(props.maximumPromptRows ?? Infinity, createTuiPromptLayout(input, cursorIndex, Math.max(1, props.columns - 4)).lines.length);
|
|
70
|
+
const showSlash = props.showInput && !pickers.isPickerActive && slashCommandSuggestions.length > 0;
|
|
71
|
+
const compactPrompt = showSlash && props.availableRows <= promptRows + 3;
|
|
72
|
+
const promptHeight = props.showInput ? compactPrompt ? 1 : promptRows + 3 : 0;
|
|
73
|
+
const slashLayout = showSlash ? getTuiSlashMenuLayout(slashCommandSuggestions.length, props.availableRows - promptHeight, props.columns) : undefined;
|
|
67
74
|
const pickerHeight = props.showInput
|
|
68
|
-
? getTuiPickerHeight({ permissions: pickers.permissionPickerOptions, models: pickers.modelPickerOptions, efforts: pickers.effortPickerOptions, skills: pickers.skillPickerSkills,
|
|
75
|
+
? getTuiPickerHeight({ permissions: pickers.permissionPickerOptions, models: pickers.modelPickerOptions, efforts: pickers.effortPickerOptions, skills: pickers.skillPickerSkills, slashMenuHeight: slashLayout?.height ?? 0, fileMentionCandidates: fileMentionSuggestions })
|
|
69
76
|
: 0;
|
|
70
77
|
useLayoutEffect(function notifyInputLayoutChange() {
|
|
71
78
|
props.onLayoutChange?.({ promptHeight, pickerHeight });
|
|
@@ -82,8 +89,21 @@ export const TuiInputArea = memo(function TuiInputArea(props) {
|
|
|
82
89
|
useEffect(function resetFileMentionSelection() {
|
|
83
90
|
pickers.updateFileMentionIndex(0);
|
|
84
91
|
}, [fileMentionSuggestions.join("\u0000")]);
|
|
85
|
-
|
|
92
|
+
/** React订阅尚未刷新时仍拒绝旧会话/列表已消费事件,原草稿和光标保持不变。 */
|
|
93
|
+
function handleActiveInput(value, key) {
|
|
94
|
+
if (props.canReceiveInput?.(value, key) === false)
|
|
95
|
+
return;
|
|
96
|
+
handleInput(value, key);
|
|
97
|
+
}
|
|
98
|
+
/** 根输入桥在layout提交时就绪,不依赖新会话useInput的被动订阅时序。 */
|
|
99
|
+
useLayoutEffect(function bindCurrentInput() {
|
|
100
|
+
if (!props.bindInputHandler)
|
|
101
|
+
return;
|
|
102
|
+
props.bindInputHandler(props.isRawModeSupported && props.isInputActive ? handleActiveInput : undefined);
|
|
103
|
+
return function unbind() { props.bindInputHandler?.(undefined); };
|
|
104
|
+
});
|
|
105
|
+
useInput(handleActiveInput, { isActive: !props.bindInputHandler && props.isRawModeSupported && props.isInputActive });
|
|
86
106
|
if (!props.showInput)
|
|
87
107
|
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 })) :
|
|
108
|
+
return _jsxs(_Fragment, { children: [_jsx(TuiPromptInput, { compact: compactPrompt, maximumRows: compactPrompt ? 1 : 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 })) : slashLayout ? (_jsx(TuiSlashCommandMenu, { commands: slashCommandSuggestions, selectedIndex: pickers.slashCommandIndex, layout: slashLayout, useColor: props.useColor, screenReader: props.screenReader })) : fileMentionSuggestions.length > 0 ? (_jsx(TuiFileMentionMenu, { candidates: fileMentionSuggestions, selectedIndex: pickers.fileMentionIndex, useColor: props.useColor, screenReader: props.screenReader })) : null] });
|
|
89
109
|
});
|
package/dist/tui/lifecycle.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { TuiOutputStream } from "./types.js";
|
|
|
6
6
|
export declare function createTuiRenderStdout(source: TuiOutputStream, initialSize: {
|
|
7
7
|
columns: number;
|
|
8
8
|
rows: number;
|
|
9
|
-
}): {
|
|
9
|
+
}, reflow?: boolean, onWritten?: (chunk: string) => void, replayOnWidthChange?: boolean): {
|
|
10
10
|
stdout: TuiOutputStream;
|
|
11
11
|
setSize(size: {
|
|
12
12
|
columns: number;
|
package/dist/tui/lifecycle.js
CHANGED
|
@@ -1,52 +1,120 @@
|
|
|
1
1
|
/** TUI 终端生命周期:鼠标事件入口、Ink stdin 包装与幂等的控制序列生命周期。 */
|
|
2
2
|
import { PassThrough } from "node:stream";
|
|
3
|
-
import {
|
|
3
|
+
import { stripVTControlCharacters } from "node:util";
|
|
4
|
+
import wrapAnsi from "wrap-ansi";
|
|
5
|
+
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
6
|
/** Ink 使用的稳定尺寸输出代理;它转发写入并在新布局提交后通知 resize。 */
|
|
5
7
|
class StableTuiOutputStream {
|
|
6
8
|
source;
|
|
9
|
+
reflow;
|
|
10
|
+
onWritten;
|
|
11
|
+
replayOnWidthChange;
|
|
7
12
|
size;
|
|
13
|
+
frame = "";
|
|
14
|
+
replayInkOutput = false;
|
|
15
|
+
observedColumns;
|
|
16
|
+
replayPending = false;
|
|
17
|
+
replayTimer;
|
|
18
|
+
observeWidth = this.observeTerminalWidth.bind(this);
|
|
8
19
|
resizeListeners = new Set();
|
|
9
|
-
constructor(source, initialSize) {
|
|
20
|
+
constructor(source, initialSize, reflow = false, onWritten, replayOnWidthChange = false) {
|
|
10
21
|
this.source = source;
|
|
22
|
+
this.reflow = reflow;
|
|
23
|
+
this.onWritten = onWritten;
|
|
24
|
+
this.replayOnWidthChange = replayOnWidthChange;
|
|
11
25
|
this.size = initialSize;
|
|
26
|
+
this.observedColumns = initialSize.columns;
|
|
27
|
+
}
|
|
28
|
+
/** 按真实列宽记录整次拖动;即使最后回到原宽,也要清掉中间宽度留下的历史边线。 */
|
|
29
|
+
observeTerminalWidth() {
|
|
30
|
+
const columns = this.source.columns;
|
|
31
|
+
if (columns === undefined || columns === this.observedColumns)
|
|
32
|
+
return;
|
|
33
|
+
this.observedColumns = columns;
|
|
34
|
+
this.replayPending = true;
|
|
35
|
+
clearTimeout(this.replayTimer);
|
|
36
|
+
this.replayTimer = setTimeout(function replayWhenSettled(stream) {
|
|
37
|
+
stream.replayTimer = undefined;
|
|
38
|
+
stream.setSize(stream.size);
|
|
39
|
+
}, 200, this);
|
|
12
40
|
}
|
|
13
41
|
get columns() { return this.size.columns; }
|
|
14
|
-
|
|
42
|
+
// Ink 在上一帧达到输出高度时会清屏并重放 Static。只在同步 resize 回调中触发一次。
|
|
43
|
+
get rows() { return this.replayInkOutput ? 0 : this.size.rows; }
|
|
15
44
|
get isTTY() { return this.source.isTTY; }
|
|
16
|
-
/**
|
|
45
|
+
/** 转发 Ink 输出,并在适用的 ConPTY 宿主按旧帧实际占行修正动态擦除。 */
|
|
17
46
|
write(chunk, ...args) {
|
|
47
|
+
// ConPTY 会重排旧动态帧,Ink 仍按旧逻辑行数擦除,须按实际新宽度计物理行。
|
|
48
|
+
let columns = this.source.columns ?? this.size.columns;
|
|
49
|
+
if (this.reflow) {
|
|
50
|
+
// Node20 的 columns 缓存直到 resize 事件才更新,ConPTY 可在该事件前完成重排。
|
|
51
|
+
const handle = this.source._handle;
|
|
52
|
+
const actual = [0, 0];
|
|
53
|
+
if (handle?.getWindowSize(actual) === 0 && actual[0] > 0)
|
|
54
|
+
columns = actual[0];
|
|
55
|
+
}
|
|
56
|
+
const erase = /\x1b\[2K(?:\x1b\[1A\x1b\[2K)*\x1b\[G/;
|
|
57
|
+
const eraseMatch = chunk.match(erase);
|
|
58
|
+
if (this.reflow && this.frame && eraseMatch) {
|
|
59
|
+
// Ink 的整屏回放含 Static 历史;仅当逻辑行数与本次动态擦除一致时使用捕获帧。
|
|
60
|
+
const logicalRows = eraseMatch[0].match(/\x1b\[2K/g).length;
|
|
61
|
+
if (logicalRows === this.frame.split("\n").length) {
|
|
62
|
+
const rows = wrapAnsi(this.frame, Math.max(1, columns), { hard: true, wordWrap: false, trim: false }).split("\n").length;
|
|
63
|
+
chunk = chunk.replace(erase, "\x1b[2K" + "\x1b[1A\x1b[2K".repeat(rows - 1) + "\x1b[G");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (this.reflow) {
|
|
67
|
+
const text = stripVTControlCharacters(chunk);
|
|
68
|
+
if (text.includes("\n") || erase.test(chunk))
|
|
69
|
+
this.frame = text;
|
|
70
|
+
}
|
|
18
71
|
const write = this.source.write;
|
|
19
72
|
const result = write.call(this.source, chunk, ...args);
|
|
73
|
+
this.onWritten?.(chunk);
|
|
20
74
|
return result !== false;
|
|
21
75
|
}
|
|
22
76
|
/** 保存 Ink 的 resize 监听,等待应用布局提交后再触发。 */
|
|
23
77
|
on(event, listener) {
|
|
24
|
-
if (event === "resize")
|
|
78
|
+
if (event === "resize") {
|
|
79
|
+
if (this.replayOnWidthChange && !this.resizeListeners.size)
|
|
80
|
+
this.source.on?.("resize", this.observeWidth);
|
|
25
81
|
this.resizeListeners.add(listener);
|
|
82
|
+
}
|
|
26
83
|
return this;
|
|
27
84
|
}
|
|
28
85
|
/** 移除 Ink 的 resize 监听,满足 Ink 卸载时的监听清理。 */
|
|
29
86
|
off(event, listener) {
|
|
30
|
-
if (event === "resize")
|
|
31
|
-
this.
|
|
87
|
+
if (event === "resize" && this.resizeListeners.delete(listener) && !this.resizeListeners.size && this.replayOnWidthChange) {
|
|
88
|
+
this.source.off?.("resize", this.observeWidth);
|
|
89
|
+
clearTimeout(this.replayTimer);
|
|
90
|
+
this.replayTimer = undefined;
|
|
91
|
+
this.replayPending = false;
|
|
92
|
+
}
|
|
32
93
|
return this;
|
|
33
94
|
}
|
|
34
|
-
/** 更新 Ink
|
|
95
|
+
/** 更新 Ink 后续布局使用的稳定尺寸,并交由 Ink 自身失效旧输出缓存后重绘。 */
|
|
35
96
|
setSize(size) {
|
|
36
97
|
const changed = size.columns !== this.size.columns || size.rows !== this.size.rows;
|
|
37
|
-
|
|
98
|
+
// 拖动停稳且布局已提交最终列宽后,只重放一次静态历史和当前帧。
|
|
99
|
+
const replay = this.replayPending && this.replayTimer === undefined && size.columns === this.observedColumns;
|
|
38
100
|
this.size = size;
|
|
39
|
-
if (!changed)
|
|
101
|
+
if (!changed && !replay)
|
|
40
102
|
return;
|
|
41
|
-
if (
|
|
42
|
-
this.
|
|
43
|
-
|
|
44
|
-
|
|
103
|
+
if (replay)
|
|
104
|
+
this.replayPending = false;
|
|
105
|
+
this.replayInkOutput = replay;
|
|
106
|
+
try {
|
|
107
|
+
for (const listener of this.resizeListeners)
|
|
108
|
+
listener();
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
this.replayInkOutput = false;
|
|
112
|
+
}
|
|
45
113
|
}
|
|
46
114
|
}
|
|
47
115
|
/** 创建跨 DPI resize 时使用的 Ink 输出代理与尺寸提交函数。 */
|
|
48
|
-
export function createTuiRenderStdout(source, initialSize) {
|
|
49
|
-
const stable = new StableTuiOutputStream(source, initialSize);
|
|
116
|
+
export function createTuiRenderStdout(source, initialSize, reflow = false, onWritten, replayOnWidthChange = false) {
|
|
117
|
+
const stable = new StableTuiOutputStream(source, initialSize, reflow, onWritten, replayOnWidthChange);
|
|
50
118
|
return {
|
|
51
119
|
stdout: stable,
|
|
52
120
|
setSize(size) { stable.setSize(size); },
|
|
@@ -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;
|
|
@@ -1,8 +1,35 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Box, Text } from "ink";
|
|
3
3
|
import { TUI_ACCENT_COLOR, TUI_DIFF_ADDED_COLOR, TUI_DIFF_REMOVED_COLOR } from "../../design-tokens.js";
|
|
4
|
-
/**
|
|
4
|
+
/** 字符串diff没有对象身份;只保留最多32项/2Mi字符及每项4个键/颜色变体。 */
|
|
5
|
+
const diffRenderCache = new Map();
|
|
6
|
+
let cachedDiffCharacters = 0;
|
|
7
|
+
/** 复用既有逐行渲染元素,避免同一diff重挂载时重新split和创建节点。 */
|
|
5
8
|
export function TuiDiffBlock(props) {
|
|
9
|
+
const key = `${props.useColor}:${props.keyPrefix}`;
|
|
10
|
+
let variants = diffRenderCache.get(props.diff);
|
|
11
|
+
if (variants?.has(key))
|
|
12
|
+
return variants.get(key);
|
|
13
|
+
const rendered = renderDiffBlock(props);
|
|
14
|
+
if (props.diff.length > 2 * 1024 * 1024)
|
|
15
|
+
return rendered;
|
|
16
|
+
if (!variants) {
|
|
17
|
+
while (diffRenderCache.size >= 32 || cachedDiffCharacters + props.diff.length > 2 * 1024 * 1024) {
|
|
18
|
+
const oldest = diffRenderCache.keys().next().value;
|
|
19
|
+
cachedDiffCharacters -= oldest.length;
|
|
20
|
+
diffRenderCache.delete(oldest);
|
|
21
|
+
}
|
|
22
|
+
variants = new Map();
|
|
23
|
+
diffRenderCache.set(props.diff, variants);
|
|
24
|
+
cachedDiffCharacters += props.diff.length;
|
|
25
|
+
}
|
|
26
|
+
if (variants.size >= 4)
|
|
27
|
+
variants.delete(variants.keys().next().value);
|
|
28
|
+
variants.set(key, rendered);
|
|
29
|
+
return rendered;
|
|
30
|
+
}
|
|
31
|
+
/** 将 Core 提供的最终 unified diff 逐行着色,保持与 Web 的 edit_file 展示语义一致。 */
|
|
32
|
+
function renderDiffBlock(props) {
|
|
6
33
|
return (_jsxs(Box, { marginLeft: 2, marginTop: 1, flexDirection: "column", borderStyle: "single", borderColor: props.useColor ? TUI_ACCENT_COLOR : undefined, paddingX: 1, children: [_jsx(Text, { bold: true, color: props.useColor ? TUI_ACCENT_COLOR : undefined, children: "diff" }), props.diff.split("\n").map(function renderDiffLine(line, index) {
|
|
7
34
|
const isAdded = line.startsWith("+") && !line.startsWith("+++");
|
|
8
35
|
const isRemoved = line.startsWith("-") && !line.startsWith("---");
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* CLI 性能诊断事件:只缓冲渲染与输入时刻、耗时和事件类型,退出时一次性写入显式文件。
|
|
3
3
|
*/
|
|
4
|
+
import { NodeStateError } from "@autopilot-agent/adapters";
|
|
4
5
|
import fs from "node:fs";
|
|
5
6
|
import path from "node:path";
|
|
6
7
|
import { classifyCliError } from "../error-diagnostics.js";
|
|
@@ -53,5 +54,6 @@ export function recordTuiRuntimeErrorDiagnostic(error) {
|
|
|
53
54
|
monotonicMs: Number(performance.now().toFixed(3)),
|
|
54
55
|
errorCategory: classification.category,
|
|
55
56
|
errorCode: classification.code,
|
|
57
|
+
...(error instanceof NodeStateError ? { storage: error.getStorageDiagnostic() } : {}),
|
|
56
58
|
});
|
|
57
59
|
}
|
|
@@ -9,5 +9,5 @@ export function TuiPermissionPicker(props) {
|
|
|
9
9
|
const focused = index === selectedIndex;
|
|
10
10
|
const checkboxColor = option.mode === "full_access" && option.selected && props.useColor ? CLI_TUI_COLORS.permissionFullAccess : undefined;
|
|
11
11
|
return _jsxs(Text, { bold: focused, color: focused && props.useColor ? TUI_ACCENT_COLOR : undefined, children: [focused ? "› " : " ", _jsxs(Text, { color: checkboxColor, dimColor: false, children: ["[", option.selected ? "on" : "off", "]"] }), " ", option.label, " (", option.mode, ")"] }, option.mode);
|
|
12
|
-
}), selectedOption ? _jsxs(Text, { dimColor: props.useColor, children: [" ", selectedOption.description] }) : null, _jsxs(Text, { dimColor: props.useColor, children: [selectedOption?.selected ? "已选择;Enter
|
|
12
|
+
}), selectedOption ? _jsxs(Text, { dimColor: props.useColor, children: [" ", selectedOption.description] }) : null, _jsxs(Text, { dimColor: props.useColor, children: [selectedOption?.selected ? "已选择;Enter 保存,下次安全恢复或新回合生效" : "Space 选择此权限模式", props.screenReader ? " · permission selector" : ""] })] }));
|
|
13
13
|
}
|
|
@@ -1,10 +1,19 @@
|
|
|
1
|
-
/** `/`
|
|
1
|
+
/** `/` 触发的命令目录,按终端可用行数展示选中项所在的候选窗口。 */
|
|
2
2
|
import { type ReactNode } from "react";
|
|
3
3
|
import type { CliSlashCommand } from "../../types.js";
|
|
4
|
-
/**
|
|
4
|
+
/** 保证每条候选占一行;边框、引导和计数也从同一行数预算扣除。 */
|
|
5
|
+
export declare function getTuiSlashMenuLayout(commandCount: number, availableRows: number, columns: number): {
|
|
6
|
+
framed: boolean;
|
|
7
|
+
inlineCount: boolean;
|
|
8
|
+
visibleRows: number;
|
|
9
|
+
height: number;
|
|
10
|
+
columns: number;
|
|
11
|
+
};
|
|
12
|
+
/** 展示选中项所在的窗口,仍按整个候选目录编号。 */
|
|
5
13
|
export declare function TuiSlashCommandMenu(props: {
|
|
6
14
|
commands: CliSlashCommand[];
|
|
7
15
|
selectedIndex: number;
|
|
16
|
+
layout: ReturnType<typeof getTuiSlashMenuLayout>;
|
|
8
17
|
useColor: boolean;
|
|
9
18
|
screenReader: boolean;
|
|
10
19
|
}): ReactNode;
|
|
@@ -1,11 +1,25 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Box, Text } from "ink";
|
|
3
3
|
import { TUI_ACCENT_COLOR } from "../../design-tokens.js";
|
|
4
|
-
/**
|
|
4
|
+
/** 保证每条候选占一行;边框、引导和计数也从同一行数预算扣除。 */
|
|
5
|
+
export function getTuiSlashMenuLayout(commandCount, availableRows, columns) {
|
|
6
|
+
const framed = availableRows >= 7 && columns >= 24;
|
|
7
|
+
const inlineCount = availableRows <= 1;
|
|
8
|
+
const chromeRows = framed ? 6 : inlineCount ? 0 : 1;
|
|
9
|
+
const visibleRows = Math.max(1, Math.min(commandCount, availableRows - chromeRows));
|
|
10
|
+
return { framed, inlineCount, visibleRows, height: visibleRows + chromeRows, columns };
|
|
11
|
+
}
|
|
12
|
+
/** 展示选中项所在的窗口,仍按整个候选目录编号。 */
|
|
5
13
|
export function TuiSlashCommandMenu(props) {
|
|
6
|
-
const selectedIndex = Math.max(0, Math.min(props.selectedIndex,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
14
|
+
const selectedIndex = Math.max(0, Math.min(props.selectedIndex, props.commands.length - 1));
|
|
15
|
+
const { framed, inlineCount, visibleRows, columns } = props.layout;
|
|
16
|
+
const start = Math.max(0, selectedIndex - visibleRows + 1);
|
|
17
|
+
const count = `${selectedIndex + 1}/${props.commands.length}`;
|
|
18
|
+
return (_jsxs(Box, { marginTop: framed ? 1 : 0, borderStyle: framed ? "single" : undefined, borderColor: props.useColor ? TUI_ACCENT_COLOR : undefined, paddingX: framed ? 1 : 0, flexDirection: "column", "aria-role": "listbox", children: [framed ? _jsxs(_Fragment, { children: [_jsx(Text, { bold: true, color: props.useColor ? TUI_ACCENT_COLOR : undefined, children: "Commands" }), _jsx(Text, { wrap: "truncate-end", dimColor: props.useColor, children: columns >= 55 ? "↑↓ select · Tab complete · Enter choose · Esc close" : "↑↓ · Tab/Enter · Esc" })] }) : null, props.commands.slice(start, start + visibleRows).map(function renderSlashCommand(command, offset) {
|
|
19
|
+
const selected = start + offset === selectedIndex;
|
|
20
|
+
const label = !inlineCount ? command.usage : command.name.length + count.length + 3 <= columns
|
|
21
|
+
? `${command.name} ${count}`
|
|
22
|
+
: `${count} ${command.name}`;
|
|
23
|
+
return (_jsxs(Text, { wrap: "truncate-end", bold: selected, color: selected && props.useColor ? TUI_ACCENT_COLOR : undefined, children: [selected ? "› " : " ", label, " ", _jsx(Text, { dimColor: props.useColor, children: command.description })] }, command.name));
|
|
24
|
+
}), inlineCount ? null : _jsxs(Text, { wrap: "truncate-end", dimColor: props.useColor, children: [count, " commands", props.screenReader ? " · command selector" : ""] })] }));
|
|
11
25
|
}
|
package/dist/tui/prompt-input.js
CHANGED
|
@@ -46,14 +46,16 @@ function renderLineWithCursor(lineText, cursorOffset, useColor, lineKey) {
|
|
|
46
46
|
}
|
|
47
47
|
/** 渲染带可视光标的多行输入;所有 prompt 文本放进同一个 Text,避免兄弟节点分别换行。 */
|
|
48
48
|
export function TuiPromptInput(props) {
|
|
49
|
-
const layout = createTuiPromptLayout(props.input, props.cursorIndex, Math.max(1, props.columns - 4));
|
|
49
|
+
const layout = createTuiPromptLayout(props.input, props.cursorIndex, Math.max(1, props.columns - (props.compact ? 0 : 4)));
|
|
50
50
|
const nodes = [];
|
|
51
51
|
const placeholder = props.screenReader && !props.input ? "prompt" : "";
|
|
52
|
-
|
|
52
|
+
const startLine = Math.max(0, layout.cursorLine - (props.maximumRows ?? layout.lines.length) + 1);
|
|
53
|
+
const endLine = Math.min(layout.lines.length, startLine + (props.maximumRows ?? layout.lines.length));
|
|
54
|
+
for (let index = startLine; index < endLine; index += 1) {
|
|
53
55
|
const line = layout.lines[index];
|
|
54
56
|
if (!line)
|
|
55
57
|
continue;
|
|
56
|
-
if (index >
|
|
58
|
+
if (index > startLine)
|
|
57
59
|
nodes.push("\n");
|
|
58
60
|
const isCursorLine = index === layout.cursorLine;
|
|
59
61
|
let lineText = line.text;
|
|
@@ -69,5 +71,5 @@ export function TuiPromptInput(props) {
|
|
|
69
71
|
if (isCursorLine && placeholder)
|
|
70
72
|
nodes.push(placeholder);
|
|
71
73
|
}
|
|
72
|
-
return (_jsx(Box, { "aria-role": "textbox", "aria-state": { busy: props.busy, multiline: true }, width: props.columns, marginTop: 1, borderStyle: "single", borderColor: props.useColor ? TUI_ACCENT_COLOR : undefined, paddingX: 1, children: _jsx(Text, { wrap: "wrap", children: nodes }) }));
|
|
74
|
+
return (_jsx(Box, { "aria-role": "textbox", "aria-state": { busy: props.busy, multiline: true }, width: props.columns, flexShrink: 0, marginTop: props.compact ? 0 : 1, borderStyle: props.compact ? undefined : "single", borderColor: props.useColor ? TUI_ACCENT_COLOR : undefined, paddingX: props.compact ? 0 : 1, children: _jsx(Text, { wrap: "wrap", children: nodes }) }));
|
|
73
75
|
}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
/** TUI 启动期一次性解析的渲染模式纯函数:颜色/读屏/降级/渲染模式策略。 */
|
|
2
2
|
import type { TuiRenderMode } from "./types.js";
|
|
3
|
+
/** 编排受管终端的局部样式,只由受管入口开启,并在读屏模式禁用。 */
|
|
4
|
+
export declare const TuiManagedTerminalStyles: import("react").Context<boolean>;
|
|
5
|
+
/** 资源管理器启动的 cmd 可由 Windows Terminal 承载,但不继承 WT_SESSION。 */
|
|
6
|
+
export declare function getWindowsTuiResizeHost(isTTY: boolean | undefined, env: NodeJS.ProcessEnv, platform?: NodeJS.Platform): "desktop" | "external" | undefined;
|
|
3
7
|
/** 判断当前环境是否要求关闭 ANSI 颜色。 */
|
|
4
8
|
export declare function resolveNoColor(env: NodeJS.ProcessEnv): boolean;
|
|
5
9
|
/** 解析 Ink screen-reader 开关,并保留 Ink 官方环境变量兼容性。 */
|
|
6
10
|
export declare function resolveScreenReader(env: NodeJS.ProcessEnv): boolean;
|
|
7
|
-
/**
|
|
8
|
-
export declare function resolveTuiRenderModePolicy(
|
|
11
|
+
/** 交互统一使用inline主屏,滚动交给终端,不启用备用屏/正文滚动条。 */
|
|
12
|
+
export declare function resolveTuiRenderModePolicy(_input: {
|
|
9
13
|
env: NodeJS.ProcessEnv;
|
|
10
14
|
platform: NodeJS.Platform | string;
|
|
11
15
|
}): TuiRenderMode;
|
|
12
|
-
/**
|
|
13
|
-
export declare function getTuiRenderModeFallbackNotice(
|
|
16
|
+
/** 各平台统一inline,不增加额外模式回落提示。 */
|
|
17
|
+
export declare function getTuiRenderModeFallbackNotice(_input: {
|
|
14
18
|
env: NodeJS.ProcessEnv;
|
|
15
19
|
platform: NodeJS.Platform | string;
|
|
16
20
|
}): string | undefined;
|
package/dist/tui/render-mode.js
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
/** TUI 启动期一次性解析的渲染模式纯函数:颜色/读屏/降级/渲染模式策略。 */
|
|
2
|
+
import { createContext } from "react";
|
|
3
|
+
/** 编排受管终端的局部样式,只由受管入口开启,并在读屏模式禁用。 */
|
|
4
|
+
export const TuiManagedTerminalStyles = createContext(false);
|
|
5
|
+
/** 资源管理器启动的 cmd 可由 Windows Terminal 承载,但不继承 WT_SESSION。 */
|
|
6
|
+
export function getWindowsTuiResizeHost(isTTY, env, platform = process.platform) {
|
|
7
|
+
if (platform !== "win32" || !isTTY)
|
|
8
|
+
return;
|
|
9
|
+
if (env.TERM_PROGRAM === "autopilot-desktop")
|
|
10
|
+
return "desktop";
|
|
11
|
+
if (!env.TERM_PROGRAM || env.WT_SESSION)
|
|
12
|
+
return "external";
|
|
13
|
+
}
|
|
2
14
|
/** 判断当前环境是否要求关闭 ANSI 颜色。 */
|
|
3
15
|
export function resolveNoColor(env) {
|
|
4
16
|
return env.NO_COLOR !== undefined && env.NO_COLOR !== "";
|
|
@@ -7,19 +19,13 @@ export function resolveNoColor(env) {
|
|
|
7
19
|
export function resolveScreenReader(env) {
|
|
8
20
|
return env.INK_SCREEN_READER === "true" || env.SCREEN_READER === "1" || env.SCREEN_READER === "true";
|
|
9
21
|
}
|
|
10
|
-
/**
|
|
11
|
-
export function resolveTuiRenderModePolicy(
|
|
12
|
-
if (resolveScreenReader(input.env) || input.env.AUTOPILOT_INLINE_TUI === "1")
|
|
13
|
-
return "inline";
|
|
14
|
-
if (input.env.AUTOPILOT_TUI_FULLSCREEN === "1" && input.platform !== "win32")
|
|
15
|
-
return "alternate-screen";
|
|
22
|
+
/** 交互统一使用inline主屏,滚动交给终端,不启用备用屏/正文滚动条。 */
|
|
23
|
+
export function resolveTuiRenderModePolicy(_input) {
|
|
16
24
|
return "inline";
|
|
17
25
|
}
|
|
18
|
-
/**
|
|
19
|
-
export function getTuiRenderModeFallbackNotice(
|
|
20
|
-
|
|
21
|
-
return undefined;
|
|
22
|
-
return "AUTOPILOT_TUI_FULLSCREEN is unsupported on win32; using inline mode. Remove AUTOPILOT_TUI_FULLSCREEN to cancel this request.\n";
|
|
26
|
+
/** 各平台统一inline,不增加额外模式回落提示。 */
|
|
27
|
+
export function getTuiRenderModeFallbackNotice(_input) {
|
|
28
|
+
return undefined;
|
|
23
29
|
}
|
|
24
30
|
/** 仅在 TUI 启动期决定内联或备用屏;宿主 TTY/Plain 门禁仍由 main.ts 保持。 */
|
|
25
31
|
export function resolveTuiRenderMode(env, platform = process.platform) {
|