@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
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/** Desktop agent-light.svg 的 64×64 单色采样,转为终端 Braille 点阵,无运行期图片依赖。 */
|
|
2
|
+
const LOGO_MASK = [
|
|
3
|
+
"0000000000000000000000000000000000000000000000000000000000000000",
|
|
4
|
+
"0000000000000000000000000000000000000000000000000000000000000000",
|
|
5
|
+
"0000000000000000000000000000000000000000000000000000000000000000",
|
|
6
|
+
"0000000000000000000000000000001111000000000000000000000000000000",
|
|
7
|
+
"0000000000000000000000000000011111100000000000000000000000000000",
|
|
8
|
+
"0000000000000000000000000000011111100000000000000000000000000000",
|
|
9
|
+
"0000000000011110000000000000111111110000000000000000000000000000",
|
|
10
|
+
"0000000000011111000000000000111111110000000000000000000000000000",
|
|
11
|
+
"0000000000111111000000000000111111110000000000000000000000000000",
|
|
12
|
+
"0000000000111111000000000000111111110000000000000000000000000000",
|
|
13
|
+
"0000000011111111111000000001111111111000000000000000000000000000",
|
|
14
|
+
"0000001111111111111100000001111111111000000000000000000000000000",
|
|
15
|
+
"0000001111111111111110000001111111111000000000000000000000000000",
|
|
16
|
+
"0000001111111111111110000001111111111000000000000000000000000000",
|
|
17
|
+
"0000001111111111111100000011111111111100000000000000000000000000",
|
|
18
|
+
"0000000111111111111000000011111111111100000000000000000000000000",
|
|
19
|
+
"0000000000111111000000000011111111111100000000000000000000000000",
|
|
20
|
+
"0000000000111111000000000011111001111100000000000000000000000000",
|
|
21
|
+
"0000000000011111000000000111111001111110000000000000000000000000",
|
|
22
|
+
"0000000000011110000000000111111001111110000000000000000000000000",
|
|
23
|
+
"0000000000001100000000000111111001111110000000000000000000000000",
|
|
24
|
+
"0000000000000000000000000111111001111110000000000000000000000000",
|
|
25
|
+
"0000000000000000000000001111110000111111000000000000000000000000",
|
|
26
|
+
"0000000000000000000000001111110000111111000000000000000000000000",
|
|
27
|
+
"0000000000000000000000111111110000111111110000000000000000000000",
|
|
28
|
+
"0000000000000000001111111111100000011111111111000000000000000000",
|
|
29
|
+
"0000000000000011111111111111100000011111111111111100000000000000",
|
|
30
|
+
"0000000000111111111111111111000000001111111111111111110000000000",
|
|
31
|
+
"0000001111111111111111111110000000000111111111111111111111000000",
|
|
32
|
+
"0000111111111111111111111000000000000001111111111111111111110000",
|
|
33
|
+
"0001111111111111111111000000000000000000001111111111111111111000",
|
|
34
|
+
"0001111111111111100000000000000000000000000000011111111111111000",
|
|
35
|
+
"0001111111111111100000000000000000000000000000011111111111111000",
|
|
36
|
+
"0001111111111111111111000000000000000000000111111111111111111000",
|
|
37
|
+
"0000111111111111111111111000000000000001111111111111111111110000",
|
|
38
|
+
"0000001111111111111111111110000000000111111111111111111111000000",
|
|
39
|
+
"0000000000111111111111111111000000001111111111111111110000000000",
|
|
40
|
+
"0000000000000011111111111111100000011111111111111100000000000000",
|
|
41
|
+
"0000000000000000001111111111100000011111111111000000000000000000",
|
|
42
|
+
"0000000000000000000000111111110000111111110000000000000000000000",
|
|
43
|
+
"0000000000000000000000001111110000111111000000000000000000000000",
|
|
44
|
+
"0000000000000000000000001111110000111111000000000000000000000000",
|
|
45
|
+
"0000000000000000000000000111110001111110000000000000000000000000",
|
|
46
|
+
"0000000000000000000000000111111001111110000000000011000000000000",
|
|
47
|
+
"0000000000000000000000000111111001111110000000000111100000000000",
|
|
48
|
+
"0000000000000000000000000111111001111110000000001111100000000000",
|
|
49
|
+
"0000000000000000000000000011111001111100000000001111110000000000",
|
|
50
|
+
"0000000000000000000000000011111111111100000000001111110000000000",
|
|
51
|
+
"0000000000000000000000000011111111111100000001111111111110000000",
|
|
52
|
+
"0000000000000000000000000011111111111100000011111111111111000000",
|
|
53
|
+
"0000000000000000000000000001111111111000000111111111111111000000",
|
|
54
|
+
"0000000000000000000000000001111111111000000111111111111111000000",
|
|
55
|
+
"0000000000000000000000000001111111111000000011111111111111000000",
|
|
56
|
+
"0000000000000000000000000001111111111000000000111111111100000000",
|
|
57
|
+
"0000000000000000000000000000111111110000000000001111110000000000",
|
|
58
|
+
"0000000000000000000000000000111111110000000000001111110000000000",
|
|
59
|
+
"0000000000000000000000000000111111110000000000001111100000000000",
|
|
60
|
+
"0000000000000000000000000000111111110000000000000111100000000000",
|
|
61
|
+
"0000000000000000000000000000011111100000000000000000000000000000",
|
|
62
|
+
"0000000000000000000000000000011111100000000000000000000000000000",
|
|
63
|
+
"0000000000000000000000000000001111000000000000000000000000000000",
|
|
64
|
+
"0000000000000000000000000000000000000000000000000000000000000000",
|
|
65
|
+
"0000000000000000000000000000000000000000000000000000000000000000",
|
|
66
|
+
"0000000000000000000000000000000000000000000000000000000000000000",
|
|
67
|
+
];
|
|
68
|
+
/** 按字符网格采样原图,每个 Braille 字符承载 2×4 个点。 */
|
|
69
|
+
export function createAgentLogoRows(width, height) {
|
|
70
|
+
const rows = [];
|
|
71
|
+
const bits = [[0, 3], [1, 4], [2, 5], [6, 7]];
|
|
72
|
+
for (let row = 0; row < height; row += 1) {
|
|
73
|
+
let line = "";
|
|
74
|
+
for (let column = 0; column < width; column += 1) {
|
|
75
|
+
let dots = 0;
|
|
76
|
+
for (let y = 0; y < 4; y += 1) {
|
|
77
|
+
for (let x = 0; x < 2; x += 1) {
|
|
78
|
+
const sourceY = Math.min(63, Math.floor((row * 4 + y + 0.5) * 64 / (height * 4)));
|
|
79
|
+
const sourceX = Math.min(63, Math.floor((column * 2 + x + 0.5) * 64 / (width * 2)));
|
|
80
|
+
if (LOGO_MASK[sourceY]?.[sourceX] === "1")
|
|
81
|
+
dots |= 1 << bits[y][x];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
line += dots ? String.fromCharCode(0x2800 + dots) : " ";
|
|
85
|
+
}
|
|
86
|
+
rows.push(line);
|
|
87
|
+
}
|
|
88
|
+
return rows;
|
|
89
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** 启动临时品牌画面,与本地初始化并行,退出时只擦除本次 Ink 动态帧。 */
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
|
+
import type { TuiOutputStream } from "../types.js";
|
|
4
|
+
/** 居中显示等比例点阵,小网格和读屏使用稳定文字,灰白扫光只提供装饰。 */
|
|
5
|
+
export declare function TuiStartupLogo(props: {
|
|
6
|
+
columns: number;
|
|
7
|
+
rows: number;
|
|
8
|
+
elapsed: number;
|
|
9
|
+
useColor: boolean;
|
|
10
|
+
screenReader: boolean;
|
|
11
|
+
}): ReactNode;
|
|
12
|
+
/** 挂载临时画面,首帧真正写入后计时;调用方仅在本地就绪后等待门槛。 */
|
|
13
|
+
export declare function startCliStartupLogo(output: TuiOutputStream, input: NodeJS.ReadStream, env?: NodeJS.ProcessEnv): {
|
|
14
|
+
/** CI 没有临时帧需要清理。 */
|
|
15
|
+
dispose: () => void;
|
|
16
|
+
/** 沿用 Ink 的 CI 静态输出,不施加不可见动画门槛。 */
|
|
17
|
+
finish: () => Promise<void>;
|
|
18
|
+
};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/** 启动临时品牌画面,与本地初始化并行,退出时只擦除本次 Ink 动态帧。 */
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import { stripVTControlCharacters } from "node:util";
|
|
5
|
+
import { Box, Text, render } from "ink";
|
|
6
|
+
import { createTuiAnimationClock } from "../../animation-clock.js";
|
|
7
|
+
import { CLI_TUI_COLORS } from "../../design-tokens.js";
|
|
8
|
+
import { createDesktopResize } from "../desktop-resize.js";
|
|
9
|
+
import { readTuiTerminalSize } from "../format.js";
|
|
10
|
+
import { createTuiRenderStdout } from "../lifecycle.js";
|
|
11
|
+
import { getWindowsTuiResizeHost, resolveNoColor, resolveReducedMotion, resolveScreenReader } from "../render-mode.js";
|
|
12
|
+
import { createAgentLogoRows } from "./logo.js";
|
|
13
|
+
import { renderAutopilotColoredRows } from "./pixel.js";
|
|
14
|
+
/** 居中显示等比例点阵,小网格和读屏使用稳定文字,灰白扫光只提供装饰。 */
|
|
15
|
+
export function TuiStartupLogo(props) {
|
|
16
|
+
const height = Math.max(1, Math.min(20, props.rows - 1));
|
|
17
|
+
const logoHeight = Math.min(16, height - 2, Math.floor(props.columns / 2));
|
|
18
|
+
const logoWidth = logoHeight * 2;
|
|
19
|
+
const compact = props.screenReader || logoHeight < 5;
|
|
20
|
+
const rows = compact ? [] : createAgentLogoRows(logoWidth, logoHeight);
|
|
21
|
+
/** 按时间与列位置选择现有灰阶,保持字符和占行完全稳定。 */
|
|
22
|
+
function colorCell(char, column) {
|
|
23
|
+
if (!props.useColor || char === " ")
|
|
24
|
+
return undefined;
|
|
25
|
+
const light = (Math.sin(props.elapsed / 650 - column / 5) + 1) / 2;
|
|
26
|
+
return light > 0.7 ? CLI_TUI_COLORS.copilotInk : light > 0.25 ? CLI_TUI_COLORS.copilotMuted : CLI_TUI_COLORS.copilotOutline;
|
|
27
|
+
}
|
|
28
|
+
return _jsx(Box, { width: props.columns, height: compact ? 1 : height, flexDirection: "column", alignItems: "center", justifyContent: "center", children: compact ? _jsx(Text, { wrap: "truncate-end", children: "Autopilot loading\u2026" }) : _jsxs(_Fragment, { children: [renderAutopilotColoredRows(rows, colorCell, logoWidth), _jsx(Text, { children: "Loading\u2026" })] }) });
|
|
29
|
+
}
|
|
30
|
+
/** 挂载临时画面,首帧真正写入后计时;调用方仅在本地就绪后等待门槛。 */
|
|
31
|
+
export function startCliStartupLogo(output, input, env = process.env) {
|
|
32
|
+
// Ink 在 CI 中不输出动态帧,沿用其进程环境判定,避免等待永远不可见的首帧。
|
|
33
|
+
if ([process.env.CI, process.env.CONTINUOUS_INTEGRATION].some(function enabled(value) { return value !== undefined && value !== "0" && value !== "false"; })) {
|
|
34
|
+
return {
|
|
35
|
+
/** CI 没有临时帧需要清理。 */
|
|
36
|
+
dispose: function dispose() { },
|
|
37
|
+
/** 沿用 Ink 的 CI 静态输出,不施加不可见动画门槛。 */
|
|
38
|
+
finish: async function finish() { },
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const desktop = createDesktopResize(output, env);
|
|
42
|
+
const proxy = createTuiRenderStdout(output, readTuiTerminalSize(desktop.source), getWindowsTuiResizeHost(output.isTTY, env) !== undefined, written);
|
|
43
|
+
const screenReader = resolveScreenReader(env);
|
|
44
|
+
const animate = !screenReader && !resolveReducedMotion(env) && !resolveNoColor(env);
|
|
45
|
+
const clock = createTuiAnimationClock({ frameMs: 120 });
|
|
46
|
+
let instance;
|
|
47
|
+
let firstFrame;
|
|
48
|
+
let markVisible;
|
|
49
|
+
const visible = new Promise(function waitVisible(resolve) { markVisible = resolve; });
|
|
50
|
+
let pendingSize;
|
|
51
|
+
let timer;
|
|
52
|
+
let release;
|
|
53
|
+
let disposed = false;
|
|
54
|
+
/** 在输出代理真正写入可见文字后开始计时,排除 Ink 布局与节流等待。 */
|
|
55
|
+
function written(chunk) {
|
|
56
|
+
desktop.written(chunk);
|
|
57
|
+
if (disposed || firstFrame !== undefined || !stripVTControlCharacters(chunk).trim())
|
|
58
|
+
return;
|
|
59
|
+
firstFrame = Date.now();
|
|
60
|
+
markVisible();
|
|
61
|
+
}
|
|
62
|
+
/** 清理动画、尺寸监听和临时画面,既有 scrollback 不参与清理。 */
|
|
63
|
+
function dispose() {
|
|
64
|
+
if (disposed)
|
|
65
|
+
return;
|
|
66
|
+
disposed = true;
|
|
67
|
+
markVisible();
|
|
68
|
+
if (timer)
|
|
69
|
+
clearTimeout(timer);
|
|
70
|
+
release?.();
|
|
71
|
+
clock.dispose();
|
|
72
|
+
instance?.rerender(_jsx(_Fragment, {}));
|
|
73
|
+
instance?.clear();
|
|
74
|
+
instance?.unmount();
|
|
75
|
+
desktop.close();
|
|
76
|
+
}
|
|
77
|
+
/** 尺寸先通过组件提交短帧,再提交给 Ink,沿用 Desktop 两阶段缩窗机制。 */
|
|
78
|
+
function StartupApp() {
|
|
79
|
+
const [size, setSize] = useState(readTuiTerminalSize(desktop.source));
|
|
80
|
+
const [elapsed, setElapsed] = useState(0);
|
|
81
|
+
/** 同一时钟只刷新装饰亮度,无色和辅助模式没有动画订阅。 */
|
|
82
|
+
function subscribeAnimation() {
|
|
83
|
+
if (!animate)
|
|
84
|
+
return;
|
|
85
|
+
return clock.subscribe(function tick(time) { setElapsed(time - (firstFrame ?? time)); });
|
|
86
|
+
}
|
|
87
|
+
/** 将 resize 同步到布局目标,真正的 Ink 尺寸在该帧写入后提交。 */
|
|
88
|
+
function subscribeResize() {
|
|
89
|
+
function resized() {
|
|
90
|
+
const next = readTuiTerminalSize(desktop.source);
|
|
91
|
+
pendingSize = next;
|
|
92
|
+
setSize(next);
|
|
93
|
+
}
|
|
94
|
+
desktop.source.on?.("resize", resized);
|
|
95
|
+
return function detach() { desktop.source.off?.("resize", resized); };
|
|
96
|
+
}
|
|
97
|
+
useEffect(subscribeAnimation, []);
|
|
98
|
+
useEffect(subscribeResize, []);
|
|
99
|
+
return _jsx(TuiStartupLogo, { ...size, elapsed: elapsed, useColor: !resolveNoColor(env) && !screenReader, screenReader: screenReader });
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
instance = render(_jsx(StartupApp, {}), {
|
|
103
|
+
stdout: proxy.stdout, stdin: input, exitOnCtrlC: false,
|
|
104
|
+
patchConsole: false, incrementalRendering: false, isScreenReaderEnabled: screenReader,
|
|
105
|
+
/** Ink 在实际输出前回调,微任务在同步写入完成后提交真实尺寸。 */
|
|
106
|
+
onRender: function rendered() {
|
|
107
|
+
queueMicrotask(function committed() {
|
|
108
|
+
if (disposed)
|
|
109
|
+
return;
|
|
110
|
+
const next = pendingSize;
|
|
111
|
+
pendingSize = undefined;
|
|
112
|
+
if (next)
|
|
113
|
+
proxy.setSize(next);
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
dispose();
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
dispose,
|
|
124
|
+
/** 本地就绪后补足首帧两秒,初始化失败直接走 dispose,无额外延迟。 */
|
|
125
|
+
async finish() {
|
|
126
|
+
await visible;
|
|
127
|
+
if (disposed)
|
|
128
|
+
return;
|
|
129
|
+
await new Promise(function waitMinimum(resolve) {
|
|
130
|
+
release = resolve;
|
|
131
|
+
timer = setTimeout(resolve, Math.max(0, 2000 - (Date.now() - (firstFrame ?? Date.now()))));
|
|
132
|
+
});
|
|
133
|
+
dispose();
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
}
|
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.4.0";
|
|
7
7
|
/** 品牌像素字母的完整单词。 */
|
|
8
8
|
export declare const AUTOPILOT_BRAND_WORD = "AUTOPILOT";
|
|
9
9
|
/** 开场动画总时长(毫秒)。 */
|
package/dist/tui/constants.js
CHANGED
package/dist/tui/context.js
CHANGED
|
@@ -3,9 +3,7 @@ import { Box, Text } from "ink";
|
|
|
3
3
|
import { formatContextReportLines } from "../context-report.js";
|
|
4
4
|
/** 渲染当前 Context 报告覆盖视图;按键由 app.tsx 统一分发,避免创建第二套输入器。 */
|
|
5
5
|
export function TuiContextReport(props) {
|
|
6
|
-
|
|
7
|
-
const decorative = props.useColor && !(props.screenReader ?? false);
|
|
8
|
-
const lines = formatContextReportLines(props.usage, props.expanded, { grid: decorative, columns: props.columns });
|
|
6
|
+
const lines = formatContextReportLines(props.usage, props.expanded, { grid: !props.screenReader, columns: props.columns });
|
|
9
7
|
return _jsxs(Box, { flexDirection: "column", width: props.columns, children: [lines.map(function renderReportLine(line, index) {
|
|
10
8
|
return _jsx(Text, { children: line }, String(index));
|
|
11
9
|
}), _jsxs(Text, { dimColor: props.useColor, children: ["Esc \u8FD4\u56DE\u804A\u5929", props.screenReader ? " · context report" : ""] })] });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TuiOutputStream, TuiTerminalSizeSource } from "./types.js";
|
|
2
|
+
/** 仅接受宿主创建的随机本机管道;布局预提交不更改真实 TTY 尺寸。 */
|
|
3
|
+
export declare function createDesktopResize(source: TuiOutputStream, env: NodeJS.ProcessEnv): {
|
|
4
|
+
source: TuiTerminalSizeSource;
|
|
5
|
+
/** 只有真实输出已适合两阶段网格才确认;OSC 让 renderer 等到该帧解析完成。 */
|
|
6
|
+
written(chunk: string): void;
|
|
7
|
+
/** 退出只关闭本进程的管道与监听,不影响持久 shell。 */
|
|
8
|
+
close(): void;
|
|
9
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/** Windows Desktop 缩网格前先提交可同时容纳于旧、新网格的动态帧;普通 CLI 不启用。 */
|
|
2
|
+
import { createServer } from "node:net";
|
|
3
|
+
import { stripVTControlCharacters } from "node:util";
|
|
4
|
+
import stringWidth from "string-width";
|
|
5
|
+
/** 仅接受宿主创建的随机本机管道;布局预提交不更改真实 TTY 尺寸。 */
|
|
6
|
+
export function createDesktopResize(source, env) {
|
|
7
|
+
const pipe = env.AUTOPILOT_DESKTOP_RESIZE_PIPE;
|
|
8
|
+
const enabled = process.platform === "win32" && env.TERM_PROGRAM === "autopilot-desktop" && /^\\\\\.\\pipe\\autopilot-desktop-[a-f0-9-]{36}$/.test(pipe ?? "");
|
|
9
|
+
let target;
|
|
10
|
+
let latestFrame = "";
|
|
11
|
+
let pending;
|
|
12
|
+
const listeners = new Set();
|
|
13
|
+
const layoutSource = {
|
|
14
|
+
get columns() { return target ? Math.min(source.columns ?? 80, target.columns) : source.columns; },
|
|
15
|
+
get rows() { return target ? Math.min(source.rows ?? 24, target.rows) : source.rows; },
|
|
16
|
+
on(event, listener) { if (event === "resize")
|
|
17
|
+
listeners.add(listener); },
|
|
18
|
+
off(event, listener) { if (event === "resize")
|
|
19
|
+
listeners.delete(listener); },
|
|
20
|
+
};
|
|
21
|
+
/** 发布布局目标,仍由现有 React/Ink 路径计算和输出帧。 */
|
|
22
|
+
function notify() { for (const listener of listeners)
|
|
23
|
+
listener(); }
|
|
24
|
+
/** 仅目标网格确已应用才解除预排版;迟到的旧 resize 不能恢复旧宽帧。 */
|
|
25
|
+
function resized() {
|
|
26
|
+
if (!target || source.columns === target.columns && source.rows === target.rows)
|
|
27
|
+
target = undefined;
|
|
28
|
+
notify();
|
|
29
|
+
}
|
|
30
|
+
/** 已输出帧若本来就能容纳目标网格,放大时无需等待一次无变化的 Ink 写入。 */
|
|
31
|
+
function confirmFrame() {
|
|
32
|
+
if (!pending || !target || !latestFrame)
|
|
33
|
+
return;
|
|
34
|
+
const lines = stripVTControlCharacters(latestFrame).trimEnd().split("\n");
|
|
35
|
+
if (lines.length > layoutSource.rows || lines.some(function tooWide(line) { return stringWidth(line) > layoutSource.columns; }))
|
|
36
|
+
return;
|
|
37
|
+
const request = pending;
|
|
38
|
+
pending = undefined;
|
|
39
|
+
clearTimeout(request.timer);
|
|
40
|
+
const write = source.write;
|
|
41
|
+
write.call(source, `\x1b]777;autopilot-resize;${request.token}\x07`, function flushed() { request.socket.end(request.token); });
|
|
42
|
+
}
|
|
43
|
+
const server = enabled ? createServer(function connected(socket) {
|
|
44
|
+
let input = "";
|
|
45
|
+
socket.setTimeout(1500, function timedOut() { socket.destroy(); });
|
|
46
|
+
socket.on("error", function ignored() { });
|
|
47
|
+
socket.on("data", function received(data) {
|
|
48
|
+
input += data.toString();
|
|
49
|
+
if (input.length > 160 || pending) {
|
|
50
|
+
socket.destroy();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (!input.endsWith("\n"))
|
|
54
|
+
return;
|
|
55
|
+
const match = /^(\d{1,4}) (\d{1,4}) ([a-f0-9-]{36})\n$/.exec(input);
|
|
56
|
+
if (!match || +match[1] < 2 || +match[1] > 1000 || +match[2] < 1 || +match[2] > 1000) {
|
|
57
|
+
socket.destroy();
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
target = { columns: +match[1], rows: +match[2] };
|
|
61
|
+
const timer = setTimeout(function abandoned() { pending = undefined; target = undefined; socket.destroy(); notify(); }, 1500);
|
|
62
|
+
pending = { socket, token: match[3], timer };
|
|
63
|
+
notify();
|
|
64
|
+
confirmFrame();
|
|
65
|
+
});
|
|
66
|
+
}) : undefined;
|
|
67
|
+
// 无可用管道时保留原 CLI 展示;不输出本机地址或原始错误。
|
|
68
|
+
server?.on("error", function unavailable() { });
|
|
69
|
+
server?.listen(pipe);
|
|
70
|
+
if (enabled)
|
|
71
|
+
source.on?.("resize", resized);
|
|
72
|
+
return {
|
|
73
|
+
source: enabled ? layoutSource : source,
|
|
74
|
+
/** 只有真实输出已适合两阶段网格才确认;OSC 让 renderer 等到该帧解析完成。 */
|
|
75
|
+
written(chunk) {
|
|
76
|
+
if (!enabled)
|
|
77
|
+
return;
|
|
78
|
+
const text = stripVTControlCharacters(chunk);
|
|
79
|
+
if (!text.includes("\n"))
|
|
80
|
+
return;
|
|
81
|
+
latestFrame = chunk;
|
|
82
|
+
confirmFrame();
|
|
83
|
+
},
|
|
84
|
+
/** 退出只关闭本进程的管道与监听,不影响持久 shell。 */
|
|
85
|
+
close() {
|
|
86
|
+
if (pending) {
|
|
87
|
+
clearTimeout(pending.timer);
|
|
88
|
+
pending.socket.destroy();
|
|
89
|
+
}
|
|
90
|
+
if (enabled)
|
|
91
|
+
source.off?.("resize", resized);
|
|
92
|
+
server?.close();
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
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
|
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { useEffect, useState } from "react";
|
|
6
6
|
import { listWorkspaceFiles } from "@autopilot-agent/core";
|
|
7
|
+
import { resolveTrustedFileMentionRoot } from "../../file-mention-context.js";
|
|
7
8
|
let cachedMentionEntries;
|
|
8
9
|
let cachedMentionLoad;
|
|
9
10
|
/** 清空模块级 @ 索引缓存;仅供测试在用例间隔离。 */
|
|
@@ -23,6 +24,13 @@ function buildMentionEntries(files) {
|
|
|
23
24
|
return left.localeCompare(right);
|
|
24
25
|
});
|
|
25
26
|
}
|
|
27
|
+
/** 枚举前后核对受信根,防止其被重定向时把其他目录的文件名显示为候选。 */
|
|
28
|
+
async function loadMentionEntries(workspaceRoot) {
|
|
29
|
+
const root = await resolveTrustedFileMentionRoot(workspaceRoot);
|
|
30
|
+
const { files } = await listWorkspaceFiles({ workspaceRoot: root });
|
|
31
|
+
await resolveTrustedFileMentionRoot(root);
|
|
32
|
+
return buildMentionEntries(files);
|
|
33
|
+
}
|
|
26
34
|
/** 挂载后预热 @ 文件索引;workspaceRoot 缺失或 Core 枚举失败时静默降级为空候选,不影响普通输入。 */
|
|
27
35
|
export function useFileMentionIndex(workspaceRoot) {
|
|
28
36
|
const [entries, setEntries] = useState(function readCachedEntries() {
|
|
@@ -35,10 +43,7 @@ export function useFileMentionIndex(workspaceRoot) {
|
|
|
35
43
|
if (!workspaceRoot || cachedMentionEntries !== undefined)
|
|
36
44
|
return;
|
|
37
45
|
if (!cachedMentionLoad) {
|
|
38
|
-
cachedMentionLoad =
|
|
39
|
-
.then(function collect(result) {
|
|
40
|
-
return buildMentionEntries(result.files);
|
|
41
|
-
})
|
|
46
|
+
cachedMentionLoad = loadMentionEntries(workspaceRoot)
|
|
42
47
|
.catch(function degradeOnFailure() {
|
|
43
48
|
return [];
|
|
44
49
|
});
|
|
@@ -1,12 +1,19 @@
|
|
|
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 {
|
|
10
|
+
parseInput?: import("../../controller.js").CliController["parseInput"];
|
|
8
11
|
store: CliTuiStore;
|
|
9
12
|
columns: number;
|
|
13
|
+
draftRef?: {
|
|
14
|
+
current?: ReturnType<typeof createPromptDraft>;
|
|
15
|
+
};
|
|
16
|
+
onAttachmentsChange?(names: string[]): void;
|
|
10
17
|
busy: {
|
|
11
18
|
current: boolean;
|
|
12
19
|
};
|
|
@@ -42,13 +49,59 @@ export interface UsePromptInputInput {
|
|
|
42
49
|
current: {
|
|
43
50
|
slashCommandSuggestions: CliSlashCommand[];
|
|
44
51
|
fileMentionSuggestions: string[];
|
|
45
|
-
handleTuiViewportKey: (key: Key) => boolean;
|
|
52
|
+
handleTuiViewportKey: (key: Key, value?: string) => boolean;
|
|
53
|
+
handleApprovalKey?: (value: string, key: Key) => boolean;
|
|
46
54
|
};
|
|
47
55
|
};
|
|
48
56
|
}
|
|
57
|
+
/** 保存已打开会话的输入状态;视图卸载时不保留React子树或正文派生计算。 */
|
|
58
|
+
declare function createPromptDraft(): {
|
|
59
|
+
inputRef: {
|
|
60
|
+
current: string;
|
|
61
|
+
};
|
|
62
|
+
cursorIndexRef: {
|
|
63
|
+
current: number;
|
|
64
|
+
};
|
|
65
|
+
verticalColumnRef: {
|
|
66
|
+
current: number | undefined;
|
|
67
|
+
};
|
|
68
|
+
bracketedPasteRef: {
|
|
69
|
+
current: boolean;
|
|
70
|
+
};
|
|
71
|
+
bracketedPasteHadContentRef: {
|
|
72
|
+
current: boolean;
|
|
73
|
+
};
|
|
74
|
+
pasteCarriageReturnRef: {
|
|
75
|
+
current: boolean;
|
|
76
|
+
};
|
|
77
|
+
inputHistoryRef: {
|
|
78
|
+
current: TuiInputHistoryState;
|
|
79
|
+
};
|
|
80
|
+
imageDraftsRef: {
|
|
81
|
+
current: Map<number, CliDraftImage>;
|
|
82
|
+
};
|
|
83
|
+
historyImagesRef: {
|
|
84
|
+
current: Array<Map<number, CliDraftImage>>;
|
|
85
|
+
};
|
|
86
|
+
historyDraftImagesRef: {
|
|
87
|
+
current: Map<number, CliDraftImage>;
|
|
88
|
+
};
|
|
89
|
+
lastSubmittedImagesRef: {
|
|
90
|
+
current: Map<number, CliDraftImage>;
|
|
91
|
+
};
|
|
92
|
+
pasteQueueRef: {
|
|
93
|
+
current: Promise<void>;
|
|
94
|
+
};
|
|
95
|
+
pastingCountRef: {
|
|
96
|
+
current: number;
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
/** Session宿主持有的草稿引用,不包含React生命周期。 */
|
|
100
|
+
export type CliTuiDraftRef = NonNullable<UsePromptInputInput["draftRef"]>;
|
|
49
101
|
/** 管理 prompt 输入状态、历史与按键分发,并暴露 handleInput 供 Ink 的 useInput 使用。 */
|
|
50
102
|
export declare function usePromptInput(input: UsePromptInputInput): {
|
|
51
103
|
input: string;
|
|
52
104
|
cursorIndex: number;
|
|
53
105
|
handleInput: (value: string, key: Key) => void;
|
|
54
106
|
};
|
|
107
|
+
export {};
|