@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
|
@@ -2,6 +2,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
2
2
|
/** 渲染当前 Turn;它会随安全事件更新,完成后整体进入历史树。 */
|
|
3
3
|
import { memo } from "react";
|
|
4
4
|
import { Box, Text } from "ink";
|
|
5
|
+
import { getCliTuiExecutionMs } from "../types.js";
|
|
5
6
|
import { TuiApprovalPrompt } from "../approval.js";
|
|
6
7
|
import { formatTuiDuration, getTuiTerminationSummary, getTuiTurnFailureReason } from "../format.js";
|
|
7
8
|
import { TuiLiveTimeline } from "./live.js";
|
|
@@ -10,12 +11,12 @@ import { TuiTodoList } from "../todo-list.js";
|
|
|
10
11
|
import { getTuiTurnTodo } from "./turn-items.js";
|
|
11
12
|
/** 渲染当前 Turn;memo 保证输入光标更新不会触发 live timeline 组件执行。 */
|
|
12
13
|
export const TuiLiveTurn = memo(function TuiLiveTurn(props) {
|
|
13
|
-
if (!props.turnId || props.events.length === 0)
|
|
14
|
+
if (!props.turnId || (props.events.length === 0 && !props.pendingApproval))
|
|
14
15
|
return null;
|
|
15
16
|
const hasPresentation = props.presentation?.items.some(function belongsToTurn(item) { return item.kind === "capability_notice" || ("turnId" in item && item.turnId === props.turnId); }) ?? false;
|
|
16
17
|
const failureReason = getTuiTurnFailureReason(props.events);
|
|
17
18
|
const terminationSummary = getTuiTerminationSummary(props.events, props.status);
|
|
18
19
|
return (_jsxs(Box, { flexDirection: "column", children: [props.presentation && hasPresentation
|
|
19
20
|
? renderTuiPresentationTimeline(props.presentation, props.turnId, props.useColor, props.maximumWidth, { expanded: props.todoExpanded, screenReader: props.screenReader, rowLimit: props.todoRowLimit, showToggleHint: true, toolGroupsExpanded: props.todoExpanded }, props.events)
|
|
20
|
-
: _jsxs(_Fragment, { children: [_jsx(TuiLiveTimeline, { turnId: props.turnId, events: props.events, status: props.status, metrics: props.metrics, useColor: props.useColor, maximumWidth: props.maximumWidth }), getTuiTurnTodo(props.events, props.turnId) ? _jsx(TuiTodoList, { item: getTuiTurnTodo(props.events, props.turnId), expanded: props.todoExpanded || props.screenReader, screenReader: props.screenReader, useColor: props.useColor, columns: props.maximumWidth + 2, rowLimit: props.todoRowLimit, showToggleHint: true }) : null] }), terminationSummary ? _jsxs(Text, { children: ["\u7EC8\u6001\uFF1A", terminationSummary] }) : hasPresentation && failureReason ? _jsxs(Text, { children: ["\u539F\u56E0\uFF1A", failureReason] }) : null, props.pendingApproval ? _jsx(TuiApprovalPrompt, { pendingApproval: props.pendingApproval, selectedIndex: props.approvalSelectedIndex, useColor: props.useColor, screenReader: props.screenReader }) : null, props.metrics?.completedAt !== undefined ? _jsxs(Text, { dimColor: props.useColor, children: ["* Cogitated for ", formatTuiDuration(
|
|
21
|
+
: _jsxs(_Fragment, { children: [_jsx(TuiLiveTimeline, { turnId: props.turnId, events: props.events, status: props.status, metrics: props.metrics, useColor: props.useColor, maximumWidth: props.maximumWidth }), getTuiTurnTodo(props.events, props.turnId) ? _jsx(TuiTodoList, { item: getTuiTurnTodo(props.events, props.turnId), expanded: props.todoExpanded || props.screenReader, screenReader: props.screenReader, useColor: props.useColor, columns: props.maximumWidth + 2, rowLimit: props.todoRowLimit, showToggleHint: true }) : null] }), terminationSummary ? _jsxs(Text, { children: ["\u7EC8\u6001\uFF1A", terminationSummary] }) : hasPresentation && failureReason ? _jsxs(Text, { children: ["\u539F\u56E0\uFF1A", failureReason] }) : null, props.pendingApproval ? _jsx(TuiApprovalPrompt, { pendingApproval: props.pendingApproval, selectedIndex: props.approvalSelectedIndex, useColor: props.useColor, screenReader: props.screenReader }) : null, props.metrics?.completedAt !== undefined ? _jsxs(Text, { dimColor: props.useColor, children: ["* Cogitated for ", formatTuiDuration(getCliTuiExecutionMs(props.metrics, props.metrics.completedAt))] }) : null] }));
|
|
21
22
|
});
|
package/dist/tui/transcript.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare function TuiPromptLine(props: {
|
|
|
8
8
|
columns: number;
|
|
9
9
|
keyValue?: string;
|
|
10
10
|
}): ReactNode;
|
|
11
|
-
/**
|
|
11
|
+
/** 按不可变历史item引用复用元素;不冻结当前Turn或改变输出。 */
|
|
12
12
|
export declare function TuiTranscriptItem(props: {
|
|
13
13
|
item: CliTuiTranscriptItem;
|
|
14
14
|
useColor: boolean;
|
package/dist/tui/transcript.js
CHANGED
|
@@ -14,8 +14,26 @@ export function TuiPromptLine(props) {
|
|
|
14
14
|
return _jsx(Text, { bold: props.useColor, children: segment.text }, index);
|
|
15
15
|
}) }) }, props.keyValue));
|
|
16
16
|
}
|
|
17
|
-
/**
|
|
17
|
+
/** 历史item生命周期内最多保留四个尺寸/颜色/读屏变体,跨重挂载复用稳定元素。 */
|
|
18
|
+
const transcriptRenderCache = new WeakMap();
|
|
19
|
+
/** 按不可变历史item引用复用元素;不冻结当前Turn或改变输出。 */
|
|
18
20
|
export function TuiTranscriptItem(props) {
|
|
21
|
+
const key = `${props.columns}:${props.useColor}:${props.screenReader ?? false}`;
|
|
22
|
+
let variants = transcriptRenderCache.get(props.item);
|
|
23
|
+
if (variants?.has(key))
|
|
24
|
+
return variants.get(key);
|
|
25
|
+
const rendered = renderTranscriptItem(props);
|
|
26
|
+
if (!variants) {
|
|
27
|
+
variants = new Map();
|
|
28
|
+
transcriptRenderCache.set(props.item, variants);
|
|
29
|
+
}
|
|
30
|
+
if (variants.size >= 4)
|
|
31
|
+
variants.delete(variants.keys().next().value);
|
|
32
|
+
variants.set(key, rendered);
|
|
33
|
+
return rendered;
|
|
34
|
+
}
|
|
35
|
+
/** 渲染已经完成的 prompt、notice 或完整 Turn。 */
|
|
36
|
+
function renderTranscriptItem(props) {
|
|
19
37
|
const item = props.item;
|
|
20
38
|
if (item.kind === "prompt") {
|
|
21
39
|
return _jsx(TuiPromptLine, { content: item.content, useColor: props.useColor, columns: props.columns, keyValue: item.key }, item.key);
|
|
@@ -39,6 +39,9 @@ export interface CliTrustDialogOptions {
|
|
|
39
39
|
write(chunk: string): void;
|
|
40
40
|
isTTY?: boolean;
|
|
41
41
|
columns?: number;
|
|
42
|
+
rows?: number;
|
|
43
|
+
on?(event: "resize", listener: () => void): unknown;
|
|
44
|
+
off?(event: "resize", listener: () => void): unknown;
|
|
42
45
|
};
|
|
43
46
|
stdin: NodeJS.ReadStream;
|
|
44
47
|
};
|
package/dist/tui/trust-dialog.js
CHANGED
|
@@ -9,7 +9,8 @@ import { useRef, useState } from "react";
|
|
|
9
9
|
import { Box, Text, render, useInput } from "ink";
|
|
10
10
|
import { TUI_ACCENT_COLOR } from "../design-tokens.js";
|
|
11
11
|
import { parseTuiControlAction } from "./input/keys.js";
|
|
12
|
-
import { createRoutedTuiStdin, createTuiTerminalLifecycle } from "./lifecycle.js";
|
|
12
|
+
import { createRoutedTuiStdin, createTuiRenderStdout, createTuiTerminalLifecycle } from "./lifecycle.js";
|
|
13
|
+
import { readTuiTerminalSize } from "./format.js";
|
|
13
14
|
import { resolveNoColor, resolveScreenReader } from "./render-mode.js";
|
|
14
15
|
/** Trust 对话框固定选项;Yes 是唯一授权动作。 */
|
|
15
16
|
export const TRUST_DIALOG_OPTIONS = [
|
|
@@ -45,6 +46,24 @@ export function runCliTrustDialog(options) {
|
|
|
45
46
|
const screenReader = resolveScreenReader(env);
|
|
46
47
|
const routedStdin = createRoutedTuiStdin(options.streams.stdin);
|
|
47
48
|
const terminalLifecycle = createTuiTerminalLifecycle(options.streams.stdout, "inline");
|
|
49
|
+
const renderStdout = createTuiRenderStdout(options.streams.stdout, readTuiTerminalSize(options.streams.stdout));
|
|
50
|
+
let resizeTimer;
|
|
51
|
+
/** 防抖后提交稳定尺寸,复用主界面的缩窄清理。 */
|
|
52
|
+
function handleResize() {
|
|
53
|
+
if (resizeTimer)
|
|
54
|
+
clearTimeout(resizeTimer);
|
|
55
|
+
resizeTimer = setTimeout(function commitSize() {
|
|
56
|
+
resizeTimer = undefined;
|
|
57
|
+
renderStdout.setSize(readTuiTerminalSize(options.streams.stdout));
|
|
58
|
+
}, 200);
|
|
59
|
+
}
|
|
60
|
+
/** 所有退出路径移除尺寸监听及待处理定时器。 */
|
|
61
|
+
function detachResize() {
|
|
62
|
+
if (resizeTimer)
|
|
63
|
+
clearTimeout(resizeTimer);
|
|
64
|
+
options.streams.stdout.off?.("resize", handleResize);
|
|
65
|
+
}
|
|
66
|
+
options.streams.stdout.on?.("resize", handleResize);
|
|
48
67
|
let decision = "declined";
|
|
49
68
|
let settled = false;
|
|
50
69
|
let instance;
|
|
@@ -100,7 +119,7 @@ export function runCliTrustDialog(options) {
|
|
|
100
119
|
try {
|
|
101
120
|
terminalLifecycle.enter();
|
|
102
121
|
instance = render(_jsx(TrustDialogApp, {}), {
|
|
103
|
-
stdout:
|
|
122
|
+
stdout: renderStdout.stdout,
|
|
104
123
|
stdin: routedStdin,
|
|
105
124
|
exitOnCtrlC: false,
|
|
106
125
|
patchConsole: true,
|
|
@@ -110,6 +129,7 @@ export function runCliTrustDialog(options) {
|
|
|
110
129
|
}
|
|
111
130
|
catch {
|
|
112
131
|
terminalLifecycle.restore();
|
|
132
|
+
detachResize();
|
|
113
133
|
detachTrustInput();
|
|
114
134
|
options.signalSource?.removeListener("SIGINT", handleSigint);
|
|
115
135
|
options.signalSource?.removeListener("SIGTERM", handleSigterm);
|
|
@@ -118,6 +138,7 @@ export function runCliTrustDialog(options) {
|
|
|
118
138
|
}
|
|
119
139
|
void instance.waitUntilExit().then(function finishTrustDialog() {
|
|
120
140
|
terminalLifecycle.restore();
|
|
141
|
+
detachResize();
|
|
121
142
|
detachTrustInput();
|
|
122
143
|
options.signalSource?.removeListener("SIGINT", handleSigint);
|
|
123
144
|
options.signalSource?.removeListener("SIGTERM", handleSigterm);
|
package/dist/tui/types.d.ts
CHANGED
|
@@ -68,8 +68,13 @@ export interface CliTuiInputPosition {
|
|
|
68
68
|
export interface CliTuiTurnMetrics {
|
|
69
69
|
startedAt: number;
|
|
70
70
|
firstAnswerAt?: number;
|
|
71
|
+
firstAnswerDurationMs?: number;
|
|
72
|
+
elapsedMs?: number;
|
|
73
|
+
runningSince?: number;
|
|
71
74
|
completedAt?: number;
|
|
72
75
|
}
|
|
76
|
+
/** 复用共享 Presentation 执行段;旧宿主缺少时钟事实时不擅自把等待计为执行。 */
|
|
77
|
+
export declare function getCliTuiExecutionMs(metrics: CliTuiTurnMetrics, now?: number): number;
|
|
73
78
|
/** 当前 Turn 的用户输入;动态区保留它,避免历史区固化时机导致 prompt 消失。 */
|
|
74
79
|
export interface CliTuiActivePrompt {
|
|
75
80
|
key: string;
|
|
@@ -91,6 +96,7 @@ export interface CliTuiSnapshot {
|
|
|
91
96
|
status: CliTurnStatus;
|
|
92
97
|
recoverable: boolean;
|
|
93
98
|
pendingApproval?: CliProjection["pendingApproval"];
|
|
99
|
+
threadWait?: CliProjection["threadWait"];
|
|
94
100
|
activeSkills: Array<{
|
|
95
101
|
skillId: string;
|
|
96
102
|
contentHash: string;
|
|
@@ -130,6 +136,8 @@ export type CliTuiInitialOperation = {
|
|
|
130
136
|
/** Ink TUI 的运行参数。 */
|
|
131
137
|
export interface RunCliTuiOptions {
|
|
132
138
|
controller: CliController;
|
|
139
|
+
/** Project级固定会话目录;选择只变视图,不恢复执行。 */
|
|
140
|
+
sessionManager?: import("./session-manager.js").CliSessionManager;
|
|
133
141
|
/** 主机已知的只读会话标识;仅用于备用屏退出后的安全摘要。 */
|
|
134
142
|
sessionId?: string;
|
|
135
143
|
/** canonical 工作区根;仅用于 @ 文件候选索引预热。 */
|
package/dist/tui/types.js
CHANGED
|
@@ -2,4 +2,7 @@
|
|
|
2
2
|
* 仅 TUI 层自有类型。Controller / 投影 / 事件等宿主协议类型统一从
|
|
3
3
|
* ../types.js 与 ../controller.js 复用,不在这里重复声明领域协议。
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
/** 复用共享 Presentation 执行段;旧宿主缺少时钟事实时不擅自把等待计为执行。 */
|
|
6
|
+
export function getCliTuiExecutionMs(metrics, now = Date.now()) {
|
|
7
|
+
return (metrics.elapsedMs ?? 0) + (metrics.runningSince === undefined ? 0 : Math.max(0, now - metrics.runningSince));
|
|
8
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import stringWidth from "string-width";
|
|
3
3
|
import wrapAnsi from "wrap-ansi";
|
|
4
4
|
import { WEB_SEARCH_DATA_FLOW_NOTICE, getPresentationCopy, getToolPresentationProfile, isSandboxUnavailableErrorCode, selectToolCalls } from "@autopilot-agent/presentation";
|
|
5
|
+
import { getCliTuiExecutionMs } from "../types.js";
|
|
5
6
|
import { createAutopilotStaticWordRows } from "../brand/pixel.js";
|
|
6
7
|
import { AUTOPILOT_VERSION, TUI_AGENT_LABEL } from "../constants.js";
|
|
7
8
|
import { cleanTuiToolSummary, formatTuiDiffStats, formatTuiDuration, formatTuiInputConsumed, formatTuiToolLine, getTuiDiffStats, getTuiStatusLabel, getTuiToolLabel, getTuiTurnFailureReason, getTuiTerminationSummary, } from "../format.js";
|
|
@@ -352,15 +353,9 @@ function createTuiViewportEventSources(itemId, events, contentWidth, timing, too
|
|
|
352
353
|
function flushAnswer() {
|
|
353
354
|
if (!answer)
|
|
354
355
|
return;
|
|
355
|
-
let thoughtIndex;
|
|
356
|
-
if (answerCount === 0 && timing?.thoughtDurationMs !== undefined) {
|
|
357
|
-
const text = `Thought for ${formatTuiDuration(timing.thoughtDurationMs)}`;
|
|
358
|
-
sources.push({ itemId: `${itemId}:thought`, text, spans: createTuiViewportTextSpans(text, "muted") });
|
|
359
|
-
thoughtIndex = sources.length - 1;
|
|
360
|
-
}
|
|
361
356
|
const answerText = `• ${TUI_AGENT_LABEL}\n${formatTuiViewportMarkdown(answer, contentWidth)}`;
|
|
362
357
|
sources.push({ itemId: `${itemId}:answer:${String(answerCount++)}`, text: answerText, spans: [{ start: 0, end: `• ${TUI_AGENT_LABEL}`.length, style: "accent" }] });
|
|
363
|
-
lastAnswerSource = { answerIndex: sources.length - 1
|
|
358
|
+
lastAnswerSource = { answerIndex: sources.length - 1 };
|
|
364
359
|
answer = "";
|
|
365
360
|
}
|
|
366
361
|
/** 收到 Core reset/discard 后撤销当前采样的暂定回答及其思考计时。 */
|
|
@@ -369,8 +364,6 @@ function createTuiViewportEventSources(itemId, events, contentWidth, timing, too
|
|
|
369
364
|
if (!lastAnswerSource)
|
|
370
365
|
return;
|
|
371
366
|
sources.splice(lastAnswerSource.answerIndex, 1);
|
|
372
|
-
if (lastAnswerSource.thoughtIndex !== undefined)
|
|
373
|
-
sources.splice(lastAnswerSource.thoughtIndex, 1);
|
|
374
367
|
answerCount = Math.max(0, answerCount - 1);
|
|
375
368
|
lastAnswerSource = undefined;
|
|
376
369
|
}
|
|
@@ -458,8 +451,8 @@ export function createTuiViewportSources(snapshot, statusView, approvalSelectedI
|
|
|
458
451
|
const liveCompletedAt = snapshot.liveMetrics?.completedAt;
|
|
459
452
|
appendEventGroup(snapshot.liveTurnId ?? "live", snapshot.liveEvents, {
|
|
460
453
|
todoRowLimit,
|
|
461
|
-
thoughtDurationMs: snapshot.liveMetrics?.firstAnswerAt === undefined ? undefined :
|
|
462
|
-
totalDurationMs: liveCompletedAt === undefined ? undefined :
|
|
454
|
+
thoughtDurationMs: snapshot.liveMetrics?.firstAnswerAt === undefined ? undefined : snapshot.liveMetrics?.firstAnswerDurationMs ?? 0,
|
|
455
|
+
totalDurationMs: liveCompletedAt === undefined ? undefined : getCliTuiExecutionMs(snapshot.liveMetrics, liveCompletedAt),
|
|
463
456
|
presentation: snapshot.livePresentation,
|
|
464
457
|
turnId: snapshot.liveTurnId,
|
|
465
458
|
status: snapshot.status,
|
|
@@ -536,8 +529,8 @@ export function createTuiViewportSourceCache() {
|
|
|
536
529
|
const liveCompletedAt = metrics?.completedAt;
|
|
537
530
|
const timing = {
|
|
538
531
|
todoRowLimit,
|
|
539
|
-
thoughtDurationMs: metrics?.firstAnswerAt === undefined ? undefined :
|
|
540
|
-
totalDurationMs: liveCompletedAt === undefined ? undefined :
|
|
532
|
+
thoughtDurationMs: metrics?.firstAnswerAt === undefined ? undefined : metrics?.firstAnswerDurationMs ?? 0,
|
|
533
|
+
totalDurationMs: liveCompletedAt === undefined ? undefined : getCliTuiExecutionMs(metrics, liveCompletedAt),
|
|
541
534
|
presentation: snapshot.livePresentation,
|
|
542
535
|
turnId: liveTurnId,
|
|
543
536
|
status: snapshot.status,
|
package/dist/types.d.ts
CHANGED
|
@@ -4,12 +4,126 @@
|
|
|
4
4
|
* 这些类型只描述 argv、slash action、事件投影和输出格式,不能替代 Core
|
|
5
5
|
* Runtime 的领域类型,也不携带审批冻结凭证或完整 checkpoint。
|
|
6
6
|
*/
|
|
7
|
-
import type { AgentEvent, AgentRuntime, AgentTerminationView, ApprovalDisplayFacts, ContextUsageView, JobListView, JobReadView, JobView, RecoverableTurnView, TodoCounts, TodoItem, ToolDisplayFacts } from "@autopilot-agent/core";
|
|
7
|
+
import type { AgentEvent, AgentRuntime, AgentTerminationView, ApprovalDisplayFacts, ContextUsageView, JobListView, JobReadView, JobView, RecoverableTurnView, TodoCounts, TodoItem, ToolDisplayFacts, TurnUsageSummaryView } from "@autopilot-agent/core";
|
|
8
8
|
import type { AgentPresentationState } from "@autopilot-agent/presentation";
|
|
9
9
|
/** CLI 当前支持的 Session 工具权限模式;与 Core 的公共枚举保持同值域。 */
|
|
10
10
|
export type CliPermissionMode = "ask" | "auto_approve" | "full_access";
|
|
11
11
|
/** CLI 输出模式;interactive 在 Step 5.4 才接入 Ink。 */
|
|
12
12
|
export type CliOutputFormat = "interactive" | "text" | "jsonl";
|
|
13
|
+
/** 协作投递模式;与 Core 冻结的三种模式同值域,必须显式声明。 */
|
|
14
|
+
export type CliThreadMode = "notify" | "run" | "steer";
|
|
15
|
+
/**
|
|
16
|
+
* 协作命令语法树。
|
|
17
|
+
*
|
|
18
|
+
* 只保存不透明身份、模式与正文来源;正文、交接文档和共享板值在宿主边界读取,
|
|
19
|
+
* 组归属、幂等、容量和交付事实都由 Core 判定。
|
|
20
|
+
*/
|
|
21
|
+
export type CliThreadCommand = {
|
|
22
|
+
type: "bind_host";
|
|
23
|
+
groupId: string;
|
|
24
|
+
threadId: string;
|
|
25
|
+
expectedRevision: number;
|
|
26
|
+
executionHost: "cli-work-v1" | "web-work-v1";
|
|
27
|
+
} | {
|
|
28
|
+
type: "group_of";
|
|
29
|
+
threadId: string;
|
|
30
|
+
} | {
|
|
31
|
+
type: "group_enable";
|
|
32
|
+
requestId: string;
|
|
33
|
+
rootThreadId: string;
|
|
34
|
+
} | {
|
|
35
|
+
type: "group_disable";
|
|
36
|
+
requestId: string;
|
|
37
|
+
groupId: string;
|
|
38
|
+
} | {
|
|
39
|
+
type: "create";
|
|
40
|
+
requestId: string;
|
|
41
|
+
groupId: string;
|
|
42
|
+
parentThreadId: string;
|
|
43
|
+
title?: string;
|
|
44
|
+
roleLabel?: string;
|
|
45
|
+
modelRef?: {
|
|
46
|
+
provider: string;
|
|
47
|
+
modelId: string;
|
|
48
|
+
};
|
|
49
|
+
reasoningEffort?: "none" | "low" | "medium" | "high" | "max";
|
|
50
|
+
} | {
|
|
51
|
+
type: "associate";
|
|
52
|
+
groupId: string;
|
|
53
|
+
threadId: string;
|
|
54
|
+
requestId: string;
|
|
55
|
+
} | {
|
|
56
|
+
type: "list";
|
|
57
|
+
groupId: string;
|
|
58
|
+
cursor?: string;
|
|
59
|
+
limit?: number;
|
|
60
|
+
} | {
|
|
61
|
+
type: "read";
|
|
62
|
+
groupId: string;
|
|
63
|
+
threadId: string;
|
|
64
|
+
cursor?: string;
|
|
65
|
+
limit?: number;
|
|
66
|
+
} | {
|
|
67
|
+
type: "send";
|
|
68
|
+
requestId: string;
|
|
69
|
+
groupId: string;
|
|
70
|
+
threadId: string;
|
|
71
|
+
mode: CliThreadMode;
|
|
72
|
+
contentSource: {
|
|
73
|
+
kind: "file";
|
|
74
|
+
path: string;
|
|
75
|
+
} | {
|
|
76
|
+
kind: "stdin";
|
|
77
|
+
};
|
|
78
|
+
replyTo?: string;
|
|
79
|
+
expectedTurnId?: string;
|
|
80
|
+
handoff?: {
|
|
81
|
+
title: string;
|
|
82
|
+
markdownFile: string;
|
|
83
|
+
};
|
|
84
|
+
} | {
|
|
85
|
+
type: "wait";
|
|
86
|
+
groupId: string;
|
|
87
|
+
targets: Array<{
|
|
88
|
+
threadId: string;
|
|
89
|
+
taskId?: string;
|
|
90
|
+
cursor?: string;
|
|
91
|
+
}>;
|
|
92
|
+
timeoutMs: number;
|
|
93
|
+
} | {
|
|
94
|
+
type: "state_read";
|
|
95
|
+
groupId: string;
|
|
96
|
+
} | {
|
|
97
|
+
type: "state_set";
|
|
98
|
+
requestId: string;
|
|
99
|
+
groupId: string;
|
|
100
|
+
expectedRevision: number;
|
|
101
|
+
key: string;
|
|
102
|
+
value: {
|
|
103
|
+
kind: "inline";
|
|
104
|
+
json: string;
|
|
105
|
+
} | {
|
|
106
|
+
kind: "file";
|
|
107
|
+
path: string;
|
|
108
|
+
};
|
|
109
|
+
} | {
|
|
110
|
+
type: "state_remove";
|
|
111
|
+
requestId: string;
|
|
112
|
+
groupId: string;
|
|
113
|
+
expectedRevision: number;
|
|
114
|
+
key: string;
|
|
115
|
+
} | {
|
|
116
|
+
type: "interrupt";
|
|
117
|
+
requestId: string;
|
|
118
|
+
groupId: string;
|
|
119
|
+
threadId: string;
|
|
120
|
+
expectedTurnId: string;
|
|
121
|
+
} | {
|
|
122
|
+
type: "watch";
|
|
123
|
+
groupId: string;
|
|
124
|
+
cursor?: string;
|
|
125
|
+
limit?: number;
|
|
126
|
+
};
|
|
13
127
|
/** CLI 命令语法树;命令本身不包含宿主状态根或 Runtime 实例。 */
|
|
14
128
|
export type CliCommand = {
|
|
15
129
|
type: "project_open";
|
|
@@ -79,6 +193,9 @@ export type CliCommand = {
|
|
|
79
193
|
} | {
|
|
80
194
|
type: "sandbox_setup";
|
|
81
195
|
yes: boolean;
|
|
196
|
+
} | {
|
|
197
|
+
type: "thread";
|
|
198
|
+
command: CliThreadCommand;
|
|
82
199
|
} | {
|
|
83
200
|
type: "chat";
|
|
84
201
|
prompt?: string;
|
|
@@ -96,8 +213,18 @@ export type CliAction =
|
|
|
96
213
|
type: "submit_prompt";
|
|
97
214
|
content: string;
|
|
98
215
|
delivery?: "steer" | "queue";
|
|
216
|
+
images?: Array<{
|
|
217
|
+
name: string;
|
|
218
|
+
mimeType: string;
|
|
219
|
+
bytes: Uint8Array;
|
|
220
|
+
}>;
|
|
99
221
|
} | {
|
|
100
222
|
type: "approve";
|
|
223
|
+
expected?: {
|
|
224
|
+
sessionId: string;
|
|
225
|
+
turnId: string;
|
|
226
|
+
approvalId: string;
|
|
227
|
+
};
|
|
101
228
|
decision: "allow_once" | "allow_session" | "allow_workspace" | "deny";
|
|
102
229
|
} | {
|
|
103
230
|
type: "compact";
|
|
@@ -148,6 +275,8 @@ export type CliAction =
|
|
|
148
275
|
} | {
|
|
149
276
|
type: "stop_job";
|
|
150
277
|
jobId: string;
|
|
278
|
+
} | {
|
|
279
|
+
type: "resume";
|
|
151
280
|
} | {
|
|
152
281
|
type: "cancel_turn";
|
|
153
282
|
} | {
|
|
@@ -204,7 +333,7 @@ export interface CliEventEnvelope {
|
|
|
204
333
|
event: AgentEvent;
|
|
205
334
|
}
|
|
206
335
|
/** Controller 使用的最小 Core Runtime 依赖;不包含 Web 或 Core private 类型。inbox 用于 Turn 终态后领取遗留排队输入。 */
|
|
207
|
-
export type CliRuntime = Pick<AgentRuntime, "turns" | "projects" | "sessions" | "approvals" | "inbox" | "jobs" | "undo"
|
|
336
|
+
export type CliRuntime = Pick<AgentRuntime, "turns" | "projects" | "sessions" | "approvals" | "inbox" | "jobs" | "undo"> & Partial<Pick<AgentRuntime, "questions">>;
|
|
208
337
|
/** TUI/Plain 共用的当前 Session Job 安全视图;不携带命令、路径、PID 或 owner。 */
|
|
209
338
|
export type CliJobView = {
|
|
210
339
|
mode: "list";
|
|
@@ -259,6 +388,8 @@ export interface CliStatusView {
|
|
|
259
388
|
nextEffort?: string;
|
|
260
389
|
/** 当前 Session 的上下文用量安全 DTO;null 表示无数据(unknown),省略表示无法查询(无 Runtime/Session)。 */
|
|
261
390
|
contextUsage?: ContextUsageView | null;
|
|
391
|
+
/** 最近 Turn 的累计用量安全 DTO(输入/输出/总量与执行段耗时);null 表示无数据(unknown),省略表示无法查询。 */
|
|
392
|
+
turnUsage?: TurnUsageSummaryView | null;
|
|
262
393
|
}
|
|
263
394
|
/** Composition Root 提供给 Controller 的热更新安全默认值;不携带 Provider 部署或凭据字段。 */
|
|
264
395
|
export interface CliRuntimeStatusDefaults {
|
|
@@ -298,6 +429,14 @@ export interface CliRenderer {
|
|
|
298
429
|
}
|
|
299
430
|
/** Renderer 可见的安全事件联合类型。 */
|
|
300
431
|
export type CliPublicEvent = {
|
|
432
|
+
type: "thread_wait";
|
|
433
|
+
seq: number;
|
|
434
|
+
turnId: string;
|
|
435
|
+
phase: "waiting" | "processing" | "none";
|
|
436
|
+
pending: number;
|
|
437
|
+
running: number;
|
|
438
|
+
approvals: number;
|
|
439
|
+
} | {
|
|
301
440
|
type: "turn_started";
|
|
302
441
|
seq: number;
|
|
303
442
|
turnId: string;
|
|
@@ -429,6 +568,9 @@ export type CliPublicEvent = {
|
|
|
429
568
|
status: "running" | "waiting_approval" | "waiting_user_input" | "interrupted" | "interrupted_recoverable" | "completed" | "failed" | "limit_reached";
|
|
430
569
|
code?: string;
|
|
431
570
|
reason?: string;
|
|
571
|
+
feedbackId?: string;
|
|
572
|
+
providerHttpStatus?: number;
|
|
573
|
+
providerFailureDetail?: string;
|
|
432
574
|
termination?: AgentTerminationView;
|
|
433
575
|
};
|
|
434
576
|
/** CLI 投影中的安全生命周期状态。 */
|
|
@@ -436,7 +578,15 @@ export type CliTurnStatus = "idle" | "running" | "waiting_approval" | "waiting_u
|
|
|
436
578
|
/** 投影器的状态;seenKeys 仅供本地去重,不会交给 Renderer。 */
|
|
437
579
|
export interface CliProjection {
|
|
438
580
|
turnId?: string;
|
|
581
|
+
/** 当前历史问题的受信请求身份,输入在异步校验前冻结此值。 */
|
|
582
|
+
questionRequestId?: string;
|
|
439
583
|
status: CliTurnStatus;
|
|
584
|
+
threadWait?: {
|
|
585
|
+
phase: "waiting" | "processing";
|
|
586
|
+
pending: number;
|
|
587
|
+
running: number;
|
|
588
|
+
approvals: number;
|
|
589
|
+
};
|
|
440
590
|
/** 只复制 Core RecoverableTurnView/终态投影确认的恢复布尔值。 */
|
|
441
591
|
recoverable: boolean;
|
|
442
592
|
answer: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autopilot-agent/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
"test:watch": "vitest --config vitest.config.ts"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@autopilot-agent/adapters": "0.
|
|
45
|
-
"@autopilot-agent/core": "0.
|
|
46
|
-
"@autopilot-agent/presentation": "0.
|
|
44
|
+
"@autopilot-agent/adapters": "0.3.0",
|
|
45
|
+
"@autopilot-agent/core": "0.3.0",
|
|
46
|
+
"@autopilot-agent/presentation": "0.3.0",
|
|
47
47
|
"ink": "6.8.0",
|
|
48
48
|
"react": "19.2.4",
|
|
49
49
|
"string-width": "^8.1.1",
|