@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.
Files changed (110) hide show
  1. package/README.md +15 -6
  2. package/dist/activity-animation.d.ts +5 -0
  3. package/dist/activity-animation.js +13 -17
  4. package/dist/browser-client.d.ts +14 -0
  5. package/dist/browser-client.js +156 -0
  6. package/dist/composition-root.d.ts +41 -1
  7. package/dist/composition-root.js +141 -14
  8. package/dist/context-report.d.ts +9 -4
  9. package/dist/context-report.js +15 -3
  10. package/dist/controller.d.ts +81 -4
  11. package/dist/controller.js +468 -98
  12. package/dist/design-tokens.d.ts +7 -2
  13. package/dist/design-tokens.js +11 -3
  14. package/dist/desktop-status.d.ts +35 -0
  15. package/dist/desktop-status.js +304 -0
  16. package/dist/error-diagnostics.d.ts +2 -0
  17. package/dist/error-diagnostics.js +3 -1
  18. package/dist/event-projector.d.ts +16 -2
  19. package/dist/event-projector.js +74 -5
  20. package/dist/file-mention-budget.d.ts +16 -0
  21. package/dist/file-mention-budget.js +82 -0
  22. package/dist/file-mention-context.d.ts +26 -1
  23. package/dist/file-mention-context.js +70 -22
  24. package/dist/index.d.ts +1 -1
  25. package/dist/main.d.ts +3 -0
  26. package/dist/main.js +213 -12
  27. package/dist/managed-attach.d.ts +3 -0
  28. package/dist/managed-attach.js +132 -0
  29. package/dist/managed-controller.d.ts +49 -0
  30. package/dist/managed-controller.js +171 -0
  31. package/dist/orchestration-templates.d.ts +27 -0
  32. package/dist/orchestration-templates.js +20 -0
  33. package/dist/parser.d.ts +1 -1
  34. package/dist/parser.js +510 -2
  35. package/dist/renderer.js +3 -1
  36. package/dist/session-summary.d.ts +7 -0
  37. package/dist/session-summary.js +25 -0
  38. package/dist/session-title.d.ts +5 -0
  39. package/dist/session-title.js +10 -0
  40. package/dist/thread-commands.d.ts +37 -0
  41. package/dist/thread-commands.js +233 -0
  42. package/dist/thread-host.d.ts +36 -0
  43. package/dist/thread-host.js +79 -0
  44. package/dist/timeline-lines.js +36 -28
  45. package/dist/tui/app.d.ts +22 -0
  46. package/dist/tui/app.js +179 -43
  47. package/dist/tui/approval.d.ts +4 -0
  48. package/dist/tui/approval.js +13 -4
  49. package/dist/tui/brand/brand-header.d.ts +1 -3
  50. package/dist/tui/brand/brand-header.js +6 -8
  51. package/dist/tui/brand/logo.d.ts +3 -0
  52. package/dist/tui/brand/logo.js +89 -0
  53. package/dist/tui/brand/startup.d.ts +18 -0
  54. package/dist/tui/brand/startup.js +136 -0
  55. package/dist/tui/constants.d.ts +1 -1
  56. package/dist/tui/constants.js +1 -1
  57. package/dist/tui/context.js +1 -3
  58. package/dist/tui/desktop-resize.d.ts +9 -0
  59. package/dist/tui/desktop-resize.js +95 -0
  60. package/dist/tui/format.d.ts +1 -1
  61. package/dist/tui/format.js +19 -9
  62. package/dist/tui/hooks/use-file-mention-index.js +9 -4
  63. package/dist/tui/hooks/use-prompt-input.d.ts +54 -1
  64. package/dist/tui/hooks/use-prompt-input.js +159 -26
  65. package/dist/tui/hooks/use-status-view.d.ts +2 -2
  66. package/dist/tui/hooks/use-status-view.js +38 -11
  67. package/dist/tui/hooks/use-viewport.d.ts +2 -1
  68. package/dist/tui/hooks/use-viewport.js +15 -8
  69. package/dist/tui/inline-output.d.ts +17 -0
  70. package/dist/tui/inline-output.js +31 -0
  71. package/dist/tui/input/clipboard-image.d.ts +17 -0
  72. package/dist/tui/input/clipboard-image.js +117 -0
  73. package/dist/tui/input-area.d.ts +12 -1
  74. package/dist/tui/input-area.js +28 -8
  75. package/dist/tui/lifecycle.d.ts +1 -1
  76. package/dist/tui/lifecycle.js +84 -16
  77. package/dist/tui/markdown/diff.d.ts +1 -1
  78. package/dist/tui/markdown/diff.js +28 -1
  79. package/dist/tui/performance-diagnostics.js +2 -0
  80. package/dist/tui/pickers/permission.js +1 -1
  81. package/dist/tui/pickers/slash.d.ts +11 -2
  82. package/dist/tui/pickers/slash.js +21 -7
  83. package/dist/tui/prompt-input.d.ts +2 -0
  84. package/dist/tui/prompt-input.js +6 -4
  85. package/dist/tui/render-mode.d.ts +8 -4
  86. package/dist/tui/render-mode.js +17 -11
  87. package/dist/tui/run.js +53 -55
  88. package/dist/tui/session-manager.d.ts +116 -0
  89. package/dist/tui/session-manager.js +384 -0
  90. package/dist/tui/session-workspace.d.ts +9 -0
  91. package/dist/tui/session-workspace.js +383 -0
  92. package/dist/tui/status-line.d.ts +4 -0
  93. package/dist/tui/status-line.js +34 -13
  94. package/dist/tui/store.d.ts +3 -1
  95. package/dist/tui/store.js +60 -14
  96. package/dist/tui/timeline/live.js +2 -3
  97. package/dist/tui/timeline/progress.js +3 -2
  98. package/dist/tui/timeline/static-timeline.js +1 -2
  99. package/dist/tui/timeline/turn.js +3 -2
  100. package/dist/tui/transcript.d.ts +2 -1
  101. package/dist/tui/transcript.js +43 -5
  102. package/dist/tui/trust-dialog.d.ts +3 -0
  103. package/dist/tui/trust-dialog.js +23 -2
  104. package/dist/tui/types.d.ts +18 -1
  105. package/dist/tui/types.js +4 -1
  106. package/dist/tui/viewport/selection.d.ts +2 -2
  107. package/dist/tui/viewport/selection.js +13 -6
  108. package/dist/tui/viewport/sources.js +13 -14
  109. package/dist/types.d.ts +160 -3
  110. package/package.json +4 -4
@@ -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, thoughtIndex };
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
  }
@@ -449,6 +442,9 @@ export function createTuiViewportSources(snapshot, statusView, approvalSelectedI
449
442
  if (item.key === snapshot.activePrompt?.key)
450
443
  renderedActivePrompt = true;
451
444
  }
445
+ else if (item.kind === "notice" && item.persistent) {
446
+ sources.push({ itemId: item.key, text: item.message });
447
+ }
452
448
  else if (item.kind === "turn" && item.turnId !== snapshot.liveTurnId) {
453
449
  appendEventGroup(item.key, item.events, item);
454
450
  }
@@ -458,8 +454,8 @@ export function createTuiViewportSources(snapshot, statusView, approvalSelectedI
458
454
  const liveCompletedAt = snapshot.liveMetrics?.completedAt;
459
455
  appendEventGroup(snapshot.liveTurnId ?? "live", snapshot.liveEvents, {
460
456
  todoRowLimit,
461
- thoughtDurationMs: snapshot.liveMetrics?.firstAnswerAt === undefined ? undefined : Math.max(0, snapshot.liveMetrics?.firstAnswerAt - snapshot.liveMetrics.startedAt),
462
- totalDurationMs: liveCompletedAt === undefined ? undefined : Math.max(0, liveCompletedAt - snapshot.liveMetrics.startedAt),
457
+ thoughtDurationMs: snapshot.liveMetrics?.firstAnswerAt === undefined ? undefined : snapshot.liveMetrics?.firstAnswerDurationMs ?? 0,
458
+ totalDurationMs: liveCompletedAt === undefined ? undefined : getCliTuiExecutionMs(snapshot.liveMetrics, liveCompletedAt),
463
459
  presentation: snapshot.livePresentation,
464
460
  turnId: snapshot.liveTurnId,
465
461
  status: snapshot.status,
@@ -500,7 +496,7 @@ export function createTuiViewportSourceCache() {
500
496
  ? [{ itemId: item.key, text: item.content, spans: createTuiViewportTextSpans(item.content, "accent") }]
501
497
  : item.kind === "turn"
502
498
  ? createTuiViewportEventSources(item.key, item.events, contentWidth, item)
503
- : [];
499
+ : item.kind === "notice" && item.persistent ? [{ itemId: item.key, text: item.message }] : [];
504
500
  history.set(item.key, { item, width: contentWidth, decorativeGrid, sources });
505
501
  stats.historyBuilds += 1;
506
502
  return sources;
@@ -536,8 +532,8 @@ export function createTuiViewportSourceCache() {
536
532
  const liveCompletedAt = metrics?.completedAt;
537
533
  const timing = {
538
534
  todoRowLimit,
539
- thoughtDurationMs: metrics?.firstAnswerAt === undefined ? undefined : Math.max(0, metrics?.firstAnswerAt - metrics.startedAt),
540
- totalDurationMs: liveCompletedAt === undefined ? undefined : Math.max(0, liveCompletedAt - metrics.startedAt),
535
+ thoughtDurationMs: metrics?.firstAnswerAt === undefined ? undefined : metrics?.firstAnswerDurationMs ?? 0,
536
+ totalDurationMs: liveCompletedAt === undefined ? undefined : getCliTuiExecutionMs(metrics, liveCompletedAt),
541
537
  presentation: snapshot.livePresentation,
542
538
  turnId: liveTurnId,
543
539
  status: snapshot.status,
@@ -562,6 +558,9 @@ export function createTuiViewportSourceCache() {
562
558
  if (item.key === snapshot.activePrompt?.key)
563
559
  renderedActivePrompt = true;
564
560
  }
561
+ else if (item.kind === "notice" && item.persistent) {
562
+ sources.push(...getHistorySources(item, contentWidth, decorativeGrid));
563
+ }
565
564
  else if (item.kind === "turn" && item.turnId !== snapshot.liveTurnId) {
566
565
  sources.push(...getHistorySources(item, contentWidth, decorativeGrid));
567
566
  }
package/dist/types.d.ts CHANGED
@@ -4,14 +4,132 @@
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" | "xhigh" | "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 = {
129
+ type: "browser";
130
+ operation: import("@autopilot-agent/core").BrowserOperation;
131
+ permit?: string;
132
+ } | {
15
133
  type: "project_open";
16
134
  path?: string;
17
135
  } | {
@@ -79,6 +197,9 @@ export type CliCommand = {
79
197
  } | {
80
198
  type: "sandbox_setup";
81
199
  yes: boolean;
200
+ } | {
201
+ type: "thread";
202
+ command: CliThreadCommand;
82
203
  } | {
83
204
  type: "chat";
84
205
  prompt?: string;
@@ -96,8 +217,18 @@ export type CliAction =
96
217
  type: "submit_prompt";
97
218
  content: string;
98
219
  delivery?: "steer" | "queue";
220
+ images?: Array<{
221
+ name: string;
222
+ mimeType: string;
223
+ bytes: Uint8Array;
224
+ }>;
99
225
  } | {
100
226
  type: "approve";
227
+ expected?: {
228
+ sessionId: string;
229
+ turnId: string;
230
+ approvalId: string;
231
+ };
101
232
  decision: "allow_once" | "allow_session" | "allow_workspace" | "deny";
102
233
  } | {
103
234
  type: "compact";
@@ -148,6 +279,8 @@ export type CliAction =
148
279
  } | {
149
280
  type: "stop_job";
150
281
  jobId: string;
282
+ } | {
283
+ type: "resume";
151
284
  } | {
152
285
  type: "cancel_turn";
153
286
  } | {
@@ -204,7 +337,7 @@ export interface CliEventEnvelope {
204
337
  event: AgentEvent;
205
338
  }
206
339
  /** Controller 使用的最小 Core Runtime 依赖;不包含 Web 或 Core private 类型。inbox 用于 Turn 终态后领取遗留排队输入。 */
207
- export type CliRuntime = Pick<AgentRuntime, "turns" | "projects" | "sessions" | "approvals" | "inbox" | "jobs" | "undo">;
340
+ export type CliRuntime = Pick<AgentRuntime, "turns" | "projects" | "sessions" | "approvals" | "inbox" | "jobs" | "undo"> & Partial<Pick<AgentRuntime, "questions">>;
208
341
  /** TUI/Plain 共用的当前 Session Job 安全视图;不携带命令、路径、PID 或 owner。 */
209
342
  export type CliJobView = {
210
343
  mode: "list";
@@ -251,7 +384,7 @@ export interface CliStatusView {
251
384
  permissionMode: CliPermissionMode;
252
385
  workspaceRoot?: string;
253
386
  source: "runtime_default" | "session_default" | "turn_frozen";
254
- /** 活动 Turn 存在时,Session 默认权限若不同则提示下轮值。 */
387
+ /** 当前执行段权限与人类已保存选择不同时,提示下次安全恢复或新回合值。 */
255
388
  nextPermissionMode?: CliPermissionMode;
256
389
  /** 活动 Turn 存在时显示已保存、但尚未冻结到当前 Turn 的下一轮模型。 */
257
390
  nextModel?: string;
@@ -259,6 +392,8 @@ export interface CliStatusView {
259
392
  nextEffort?: string;
260
393
  /** 当前 Session 的上下文用量安全 DTO;null 表示无数据(unknown),省略表示无法查询(无 Runtime/Session)。 */
261
394
  contextUsage?: ContextUsageView | null;
395
+ /** 最近 Turn 的累计用量安全 DTO(输入/输出/总量与执行段耗时);null 表示无数据(unknown),省略表示无法查询。 */
396
+ turnUsage?: TurnUsageSummaryView | null;
262
397
  }
263
398
  /** Composition Root 提供给 Controller 的热更新安全默认值;不携带 Provider 部署或凭据字段。 */
264
399
  export interface CliRuntimeStatusDefaults {
@@ -274,6 +409,9 @@ export interface CliRuntimeStatusDefaults {
274
409
  provider: string;
275
410
  modelId: string;
276
411
  requestableEfforts: readonly string[];
412
+ defaultReasoningEffort?: string;
413
+ reasoningCapabilityUnknown?: boolean;
414
+ supportsToolCalls?: boolean;
277
415
  }>;
278
416
  }
279
417
  /** CLI Composition Root 提供的 Skill catalog 只读查询。 */
@@ -298,6 +436,14 @@ export interface CliRenderer {
298
436
  }
299
437
  /** Renderer 可见的安全事件联合类型。 */
300
438
  export type CliPublicEvent = {
439
+ type: "thread_wait";
440
+ seq: number;
441
+ turnId: string;
442
+ phase: "waiting" | "processing" | "none";
443
+ pending: number;
444
+ running: number;
445
+ approvals: number;
446
+ } | {
301
447
  type: "turn_started";
302
448
  seq: number;
303
449
  turnId: string;
@@ -429,6 +575,9 @@ export type CliPublicEvent = {
429
575
  status: "running" | "waiting_approval" | "waiting_user_input" | "interrupted" | "interrupted_recoverable" | "completed" | "failed" | "limit_reached";
430
576
  code?: string;
431
577
  reason?: string;
578
+ feedbackId?: string;
579
+ providerHttpStatus?: number;
580
+ providerFailureDetail?: string;
432
581
  termination?: AgentTerminationView;
433
582
  };
434
583
  /** CLI 投影中的安全生命周期状态。 */
@@ -436,7 +585,15 @@ export type CliTurnStatus = "idle" | "running" | "waiting_approval" | "waiting_u
436
585
  /** 投影器的状态;seenKeys 仅供本地去重,不会交给 Renderer。 */
437
586
  export interface CliProjection {
438
587
  turnId?: string;
588
+ /** 当前历史问题的受信请求身份,输入在异步校验前冻结此值。 */
589
+ questionRequestId?: string;
439
590
  status: CliTurnStatus;
591
+ threadWait?: {
592
+ phase: "waiting" | "processing";
593
+ pending: number;
594
+ running: number;
595
+ approvals: number;
596
+ };
440
597
  /** 只复制 Core RecoverableTurnView/终态投影确认的恢复布尔值。 */
441
598
  recoverable: boolean;
442
599
  answer: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autopilot-agent/cli",
3
- "version": "0.2.0",
3
+ "version": "0.4.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.2.0",
45
- "@autopilot-agent/core": "0.2.0",
46
- "@autopilot-agent/presentation": "0.2.0",
44
+ "@autopilot-agent/adapters": "0.4.0",
45
+ "@autopilot-agent/core": "0.4.0",
46
+ "@autopilot-agent/presentation": "0.4.0",
47
47
  "ink": "6.8.0",
48
48
  "react": "19.2.4",
49
49
  "string-width": "^8.1.1",