@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
@@ -4,13 +4,41 @@
4
4
  * 负责选择 Core 默认 Runtime、共享 Node Adapter、canonical workspaceRoot、
5
5
  * trust policy 和显式 stateRoot;不负责命令解析、事件投影或 Runtime 状态机。
6
6
  */
7
+ import { readCliSessionSummary } from "./session-summary.js";
8
+ import { createDesktopBrowserCapability } from "./browser-client.js";
7
9
  import { WEB_SEARCH_DATA_FLOW_NOTICE } from "@autopilot-agent/presentation";
8
- import { createDefaultModelSamplerFactory, createRuntimeBootstrapService, createSafeBootstrapConfig, WorkspaceTrustError, getMcpServerGrantConstraint, } from "@autopilot-agent/core";
9
- import { createNodeCredentialStore, createNodeCapabilityLoader, createNodeHostExecutionSandboxPort, createNodeSandboxPort, createNodeSettingsLoader, createNodeSettingsWriter, ensureUserConfigDirectory, createNodeRuntimePorts, createNodeTrustPolicy, createNodeWorkspaceRegistry, createNodeWorkspaceAdapter, createNodeWorkspaceId, getNodeStateCorruptionDiagnostics, getNodeStatePaths, getNodeStateSchemaDiagnostic, initializeNodeStateRoot, resolveNodeSettingsPaths, resolveNodeStateRoot, assertNodeStateSchema, } from "@autopilot-agent/adapters";
10
+ import { AgentRuntimeError, resolveRouteModelCapability, createDefaultModelSamplerFactory, createRuntimeBootstrapService, createSafeBootstrapConfig, createThreadFacade, WorkspaceTrustError, getMcpServerGrantConstraint, } from "@autopilot-agent/core";
11
+ import { createNodeCredentialStore, createNodeCapabilityLoader, createNodeHostExecutionSandboxPort, createNodeSandboxPort, createNodeSettingsLoader, createNodeSettingsWriter, createNodeStateRootId, createNodeThreadHandoffWriter, ensureUserConfigDirectory, createNodeRuntimePorts, createNodeTrustPolicy, createNodeWorkspaceRegistry, createNodeWorkspaceAdapter, createNodeWorkspaceId, getNodeStateCorruptionDiagnostics, getNodeStatePaths, getNodeStateSchemaDiagnostic, initializeNodeStateRoot, LOCAL_HUMAN_PRINCIPAL_ID, resolveNodeSettingsPaths, resolveNodeStateRoot, assertNodeStateSchema, } from "@autopilot-agent/adapters";
12
+ import { createCliThreadHost } from "./thread-host.js";
10
13
  import fs from "node:fs";
11
14
  import path from "node:path";
12
15
  /** CLI 专用模型行为补充:无结构化 answerer 时以普通正文完成最少必要澄清。 */
13
- const CLI_TEXT_CLARIFICATION_INSTRUCTIONS = `当前宿主是 CLI,未提供 ask_user_question 或其他结构化用户回答能力。仅在完成任务确实缺少方向性信息、且不能从当前用户输入、会话历史或工作区安全获得时,才在普通助手正文中用最少必要的简短问题向用户澄清;提出问题后正常结束当前 Turn,等待用户下一条 prompt 作为同一 Session 的新 Turn 继续。不要臆造或调用 ask_user_question,不要把澄清伪装成审批,也不要在等待澄清时猜测并执行写入或命令工具。用户下一条 prompt 与任何 Other/custom 文本都不授予 Trust、权限或审批;后续工具调用仍必须遵守既有 Policy 与 Approval 约束。Agent 自身的临时脚本、截图裁剪和中间文件必须写入项目根目录的 .autopilot/tmp,不得写入 node_modules 或随意污染业务目录;用户明确指定的目标路径除外。`;
16
+ const CLI_TEXT_CLARIFICATION_INSTRUCTIONS = `当前宿主是 CLI,未提供 ask_user_question 或其他结构化用户回答能力。仅在完成任务确实缺少方向性信息、且不能从当前用户输入、会话历史或工作区安全获得时,才在普通助手正文中用最少必要的简短问题向用户澄清;提出问题后正常结束当前 Turn,等待用户下一条 prompt 作为同一 Session 的新 Turn 继续。不要臆造或调用 ask_user_question,不要把澄清伪装成审批,也不要在等待澄清时猜测并执行写入或命令工具。`;
17
+ const CLI_TOOL_CONSTRAINTS = `用户下一条 prompt 与任何 Other/custom 文本都不授予 Trust、权限或审批;后续工具调用仍必须遵守既有 Policy 与 Approval 约束。Agent 自身的临时脚本、截图裁剪和中间文件必须写入项目根目录的 .autopilot/tmp,不得写入 node_modules 或随意污染业务目录;用户明确指定的目标路径除外。`;
18
+ /**
19
+ * 子会话可用的工具目录:协作工具用于回报,Work 常用工具用于真正执行任务。
20
+ * 这是 CLI 宿主策略(与 Web 首版保持同一最小集合),会随组记录冻结并向用户展示。
21
+ */
22
+ const CLI_THREAD_ALLOWED_TOOLS = [
23
+ "create_thread",
24
+ "list_threads",
25
+ "read_thread",
26
+ "send_thread",
27
+ "wait_threads",
28
+ "read_shared_state",
29
+ "update_shared_state",
30
+ "report_progress",
31
+ "read_progress",
32
+ "interrupt_thread",
33
+ "resume_thread",
34
+ "read_file",
35
+ "glob_files",
36
+ "grep_files",
37
+ "edit_file",
38
+ "write_file",
39
+ "run_command",
40
+ "todo_write",
41
+ ];
14
42
  /** 创建项目级 Agent 运行目录;拒绝链接/文件替代目录,避免临时文件逃逸工作区。 */
15
43
  function ensureProjectAutopilotDirectory(workspaceRoot) {
16
44
  try {
@@ -47,7 +75,7 @@ function omitCliRagCapabilityLoader(loader) {
47
75
  return safeLoader;
48
76
  }
49
77
  /** 为任意 CLI Provider 工厂叠加宿主澄清指令,保留原采样和完成策略。 */
50
- function withCliTextClarificationBehavior(factory) {
78
+ function withCliTextClarificationBehavior(factory, enableUserQuestions = false) {
51
79
  return {
52
80
  create(input) {
53
81
  const sampler = factory.create(input);
@@ -56,7 +84,7 @@ function withCliTextClarificationBehavior(factory) {
56
84
  ...sampler,
57
85
  behaviorProfile: {
58
86
  id: `${profile?.id ?? "cli"}-text-clarification`,
59
- instructions: [profile?.instructions, CLI_TEXT_CLARIFICATION_INSTRUCTIONS].filter(Boolean).join("\n\n"),
87
+ instructions: [profile?.instructions, enableUserQuestions ? CLI_TOOL_CONSTRAINTS : CLI_TEXT_CLARIFICATION_INSTRUCTIONS + " " + CLI_TOOL_CONSTRAINTS].filter(Boolean).join("\n\n"),
60
88
  completionPolicy: profile?.completionPolicy,
61
89
  },
62
90
  };
@@ -101,6 +129,27 @@ export function createCliCompositionRoot(options = {}) {
101
129
  let stopSettingsWatch;
102
130
  /** 最近一次 createRuntime 的 canonical workspaceRoot;tempRoot 注入以其为准。 */
103
131
  let activeWorkspaceRoot;
132
+ /** 最近一次 bootstrap 产生的 Ports;协作 Facade 与宿主共用同一份存储。 */
133
+ let runtimePorts;
134
+ /** 已确认的 Project;未绑定时不向 Turn 注入协作能力。 */
135
+ let threadsProjectId;
136
+ /** 宿主合法模型目录;随 settings 热更新重建。 */
137
+ let threadsModelCatalog = [];
138
+ /** 返回当前可用的协作范围;缺 Project 或工作区时不注入,避免注册不可用工具。 */
139
+ function currentThreadsCapability() {
140
+ if (!threadsProjectId || !activeWorkspaceRoot)
141
+ return undefined;
142
+ return {
143
+ workspaceId: createNodeWorkspaceId(activeWorkspaceRoot),
144
+ executionHost: "cli-work-v1",
145
+ stateRootId: createNodeStateRootId(stateRoot),
146
+ projectId: threadsProjectId,
147
+ allowedTools: CLI_THREAD_ALLOWED_TOOLS,
148
+ modelCatalog: threadsModelCatalog,
149
+ humanPrincipalId: LOCAL_HUMAN_PRINCIPAL_ID,
150
+ handoff: createNodeThreadHandoffWriter({ workspaceRoot: activeWorkspaceRoot }),
151
+ };
152
+ }
104
153
  /** 返回当前 settings 选中模型对应的 route;firstParty 使用 CC 主配置。 */
105
154
  function getSelectedProviderSettings(settings) {
106
155
  const selectedRoute = settings.modelRef && settings.modelRef.provider !== "firstParty"
@@ -133,9 +182,16 @@ export function createCliCompositionRoot(options = {}) {
133
182
  const loaded = settingsLoader.load(workspaceRoot);
134
183
  resolvedSettings = loaded.settings;
135
184
  userSettingsPath = loaded.paths.user;
185
+ // 模型目录只在 settings 变化时重建;协作创建不能由请求追加目录项。
186
+ threadsModelCatalog = getModelCapabilities().map(function toModelRef(capability) {
187
+ return { provider: capability.provider, modelId: capability.modelId };
188
+ });
136
189
  stopSettingsWatch?.();
137
190
  stopSettingsWatch = settingsLoader.watch(workspaceRoot, function replaceSettings(next) {
138
191
  resolvedSettings = next.settings;
192
+ threadsModelCatalog = getModelCapabilities().map(function toModelRef(capability) {
193
+ return { provider: capability.provider, modelId: capability.modelId };
194
+ });
139
195
  });
140
196
  }
141
197
  /** 只检查 Agent 主模型最小配置;不读取或显示任何真实 Key。 */
@@ -161,17 +217,16 @@ export function createCliCompositionRoot(options = {}) {
161
217
  const seen = new Set();
162
218
  const firstPartyEfforts = ["none", "low", "medium", "high", "max"];
163
219
  function getRouteRequestableEfforts(route, modelId) {
164
- const model = route.models.find(function findModel(candidate) { return candidate.id === modelId; });
165
- const profile = model?.protocolProfile ?? route.protocolProfile;
166
- return route.apiProtocol === "openai-chat-completions"
167
- && (profile?.apiProtocol !== "openai-chat-completions" || !profile.supportsReasoningContent) ? ["none"] : firstPartyEfforts;
220
+ return resolveRouteModelCapability(route, modelId).supportedReasoningEfforts ?? [];
168
221
  }
169
222
  function addCapability(provider, modelId, requestableEfforts) {
170
223
  const key = `${provider}/${modelId}`;
171
224
  if (!modelId || seen.has(key))
172
225
  return;
173
226
  seen.add(key);
174
- capabilities.push({ provider, modelId, requestableEfforts });
227
+ const route = resolvedSettings?.providerRoutes[provider];
228
+ const capability = route ? resolveRouteModelCapability(route, modelId) : undefined;
229
+ capabilities.push({ provider, modelId, requestableEfforts, defaultReasoningEffort: capability?.defaultReasoningEffort, reasoningCapabilityUnknown: route ? capability?.supportedReasoningEfforts === undefined : false, supportsToolCalls: capability?.supportsToolCalls });
175
230
  }
176
231
  // 开发态 CLI 可能仍链接上一轮 Core 产物;回退 availableModels 以保持 settings 热更新兼容。
177
232
  const configuredModels = resolvedSettings.modelCandidates.length > 0
@@ -322,12 +377,21 @@ export function createCliCompositionRoot(options = {}) {
322
377
  };
323
378
  const baseCapabilityLoader = options.capabilityLoader ?? defaultCapabilityLoader;
324
379
  const safeBaseCapabilityLoader = omitCliRagCapabilityLoader(baseCapabilityLoader);
380
+ const desktopBrowserEnv = {
381
+ AUTOPILOT_BROWSER_ENDPOINT: process.env.AUTOPILOT_BROWSER_ENDPOINT,
382
+ AUTOPILOT_BROWSER_NATIVE_TOKEN: process.env.AUTOPILOT_BROWSER_NATIVE_TOKEN,
383
+ };
384
+ // 原生浏览器凭据只留在组合根闭包,工作区工具的子进程不能继承。
385
+ delete process.env.AUTOPILOT_BROWSER_NATIVE_TOKEN;
386
+ let desktopBrowser;
325
387
  let loadedSkills;
326
388
  const capabilityLoader = {
327
389
  ...safeBaseCapabilityLoader,
390
+ /** Trust后只加载Desktop授予的原生连接;独立CLI无环境凭据时不注册工具。 */
391
+ loadBrowser: safeBaseCapabilityLoader.loadBrowser ?? function loadBrowser() { return desktopBrowser ??= createDesktopBrowserCapability(desktopBrowserEnv); },
328
392
  ...(safeBaseCapabilityLoader.loadProvider ? {
329
393
  async loadProvider(workspaceRoot) {
330
- return withCliTextClarificationBehavior(await safeBaseCapabilityLoader.loadProvider(workspaceRoot));
394
+ return withCliTextClarificationBehavior(await safeBaseCapabilityLoader.loadProvider(workspaceRoot), options.enableUserQuestions);
331
395
  },
332
396
  } : {}),
333
397
  async loadSkills(workspaceRoot) {
@@ -335,8 +399,8 @@ export function createCliCompositionRoot(options = {}) {
335
399
  const skills = safeBaseCapabilityLoader.loadSkills
336
400
  ? await safeBaseCapabilityLoader.loadSkills(workspaceRoot)
337
401
  : undefined;
338
- loadedSkills = skills;
339
- return skills;
402
+ loadedSkills = options.decorateSkills ? options.decorateSkills(skills) : skills;
403
+ return loadedSkills;
340
404
  },
341
405
  };
342
406
  const bootstrapService = createRuntimeBootstrapService({
@@ -344,9 +408,10 @@ export function createCliCompositionRoot(options = {}) {
344
408
  workspaceAdapter,
345
409
  trustPolicy,
346
410
  capabilityLoader,
411
+ enableUserQuestions: options.enableUserQuestions,
347
412
  createPorts(workspaceRoot) {
348
413
  initializeNodeStateRoot(stateRoot);
349
- return createNodeRuntimePorts({
414
+ const ports = createNodeRuntimePorts({
350
415
  stateRoot,
351
416
  trustRoot: options.trustRoot,
352
417
  workspaceRoot,
@@ -356,6 +421,9 @@ export function createCliCompositionRoot(options = {}) {
356
421
  //(目录由 ensureProjectAutopilotDirectory 创建并验证),不继承 ambient temp。
357
422
  sandboxTempRoot: path.join(workspaceRoot, ".autopilot", "tmp"),
358
423
  });
424
+ // 协作 Facade/宿主必须与 Runtime 使用同一份 Ports,不能另建存储。
425
+ runtimePorts = options.decoratePorts?.(ports) ?? ports;
426
+ return runtimePorts;
359
427
  },
360
428
  defaultRunConfig: {
361
429
  ...options.defaultRunConfig,
@@ -365,6 +433,7 @@ export function createCliCompositionRoot(options = {}) {
365
433
  const selectedProvider = getSelectedProviderSettings(resolvedSettings);
366
434
  const visionRef = resolvedSettings.visionModelRef === false ? undefined : resolvedSettings.visionModelRef ?? resolvedSettings.modelRef;
367
435
  const visionRoute = visionRef && resolvedSettings.providerRoutes[visionRef.provider];
436
+ const threads = currentThreadsCapability();
368
437
  return {
369
438
  ...(resolvedSettings.maxTurns !== undefined ? { maxSteps: resolvedSettings.maxTurns } : {}),
370
439
  ...(resolvedSettings.modelRef ? { modelRef: resolvedSettings.modelRef } : {}),
@@ -374,6 +443,8 @@ export function createCliCompositionRoot(options = {}) {
374
443
  // tempRoot 固定指向当前 Runtime 工作区内的受控 .autopilot/tmp。
375
444
  ...(resolvedSettings.sandbox.mode ? { sandboxMode: resolvedSettings.sandbox.mode } : {}),
376
445
  ...(activeWorkspaceRoot ? { sandboxTempRoot: path.join(activeWorkspaceRoot, ".autopilot", "tmp") } : {}),
446
+ // 协作能力只来自宿主默认值;Turn/Project/Session override 不能注入或替换。
447
+ ...(threads ? { threads } : {}),
377
448
  providerSettings: {
378
449
  ...(selectedProvider ? { primary: selectedProvider } : {}),
379
450
  routes: resolvedSettings.providerRoutes,
@@ -520,10 +591,66 @@ export function createCliCompositionRoot(options = {}) {
520
591
  createRuntime: async function createRuntime(workspaceRoot) {
521
592
  activateSettings(workspaceRoot);
522
593
  activeWorkspaceRoot = workspaceRoot;
594
+ // 上一次 Runtime 的 Ports 不能沿用;协作 Facade 必须绑定当前 Runtime。
595
+ runtimePorts = undefined;
523
596
  const runtime = await bootstrapService.createRuntime(workspaceRoot);
524
597
  workspaceRegistry.register(workspaceRoot);
525
598
  return runtime;
526
599
  },
600
+ readSessionEvents: async function readSessionEvents(sessionId) {
601
+ if (!runtimePorts)
602
+ throw new Error("CLI_RUNTIME_NOT_ATTACHED");
603
+ return runtimePorts.transcriptStore.getEvents(sessionId);
604
+ },
605
+ readSessionEventPage: async function readSessionEventPage(sessionId, input) {
606
+ if (!runtimePorts)
607
+ throw new Error("CLI_RUNTIME_NOT_ATTACHED");
608
+ return runtimePorts.transcriptStore.readPage(sessionId, input);
609
+ },
610
+ readSessionDirectoryPage: async function readSessionDirectoryPage(projectId, input) {
611
+ if (!runtimePorts?.sessionStore.listDirectoryPage)
612
+ throw new Error("CLI_SESSION_DIRECTORY_UNAVAILABLE");
613
+ return runtimePorts.sessionStore.listDirectoryPage({ ...input, projectId });
614
+ },
615
+ readSessionSummary: async function readSessionSummary(sessionId, signal) {
616
+ if (!runtimePorts?.sessionStore.getDirectoryEntry)
617
+ throw new Error("CLI_SESSION_DIRECTORY_UNAVAILABLE");
618
+ return readCliSessionSummary(runtimePorts, sessionId, signal);
619
+ },
620
+ bindThreadsProject: function bindThreadsProject(projectId) {
621
+ threadsProjectId = projectId;
622
+ },
623
+ createHumanThreads: function createHumanThreads() {
624
+ const capability = currentThreadsCapability();
625
+ if (!capability || !runtimePorts || !activeWorkspaceRoot)
626
+ throw new AgentRuntimeError("THREADS_UNAVAILABLE", "THREADS_UNAVAILABLE");
627
+ return createThreadFacade(runtimePorts, {
628
+ ...capability,
629
+ // 本机人类身份由受信宿主绑定;不来自请求参数、消息正文或模型输出。
630
+ actor: { kind: "human", principalId: LOCAL_HUMAN_PRINCIPAL_ID },
631
+ // 交接文档由 Node Adapter 原子写入受信工作区;Core 只接收安全引用。
632
+ handoff: createNodeThreadHandoffWriter({ workspaceRoot: activeWorkspaceRoot }),
633
+ });
634
+ },
635
+ getDesktopStatusWorkspace: function getDesktopStatusWorkspace() {
636
+ const capability = currentThreadsCapability();
637
+ if (!capability || !activeWorkspaceRoot)
638
+ return undefined;
639
+ return { workspaceId: capability.workspaceId, stateRootId: capability.stateRootId, projectId: capability.projectId, displayName: path.basename(activeWorkspaceRoot).replace(/[\x00-\x1f\x7f/\\]/g, "").slice(0, 80) };
640
+ },
641
+ createThreadHost: function createThreadHost(runtime, onError, observeExecution) {
642
+ const capability = currentThreadsCapability();
643
+ if (!capability || !runtimePorts)
644
+ throw new AgentRuntimeError("THREADS_UNAVAILABLE", "THREADS_UNAVAILABLE");
645
+ return createCliThreadHost({
646
+ workspaceId: capability.workspaceId,
647
+ stateRootId: capability.stateRootId,
648
+ runtime,
649
+ ports: runtimePorts,
650
+ ...(onError ? { onError } : {}),
651
+ observeExecution,
652
+ });
653
+ },
527
654
  bootstrap: async function bootstrap() {
528
655
  const trusted = await bootstrapService.establishTrust();
529
656
  return bootstrapService.createRuntime(trusted.workspaceRoot);
@@ -1,13 +1,13 @@
1
1
  /**
2
- * Context Usage 安全报告格式化。
2
+ * Context / Turn 用量安全报告格式化。
3
3
  *
4
- * 所有输入只来自 Core 白名单 ContextUsageView DTO;宿主只做展示转换,
4
+ * 所有输入只来自 Core 白名单 ContextUsageView / TurnUsageSummaryView DTO;宿主只做展示转换,
5
5
  * 不重算 token、不猜测窗口、不为非零分类强塞至少一格。
6
6
  */
7
- import type { ContextUsageView } from "@autopilot-agent/core";
7
+ import type { ContextUsageView, TurnUsageSummaryView } from "@autopilot-agent/core";
8
8
  /**
9
9
  * 生成 Context 报告文本行。
10
- * grid=false(Plain/screen reader/NO_COLOR)跳过装饰网格但保留完整文本;
10
+ * grid=false(Plain/screen reader)跳过装饰网格但保留完整文本;
11
11
  * 列数不足以并排时整体改为上下堆叠。
12
12
  */
13
13
  export declare function formatContextReportLines(usage: ContextUsageView | null, expanded: boolean, options: {
@@ -18,3 +18,8 @@ export declare function formatContextReportLines(usage: ContextUsageView | null,
18
18
  export declare function formatPlainContextReport(usage: ContextUsageView | null, expanded: boolean): string[];
19
19
  /** 状态栏只显示整个窗口的整数剩余百分比;计量来源留在 /context all。 */
20
20
  export declare function formatTuiContextStatus(usage: ContextUsageView | null): string;
21
+ /**
22
+ * 状态栏累计用量行:优先展示累计输入/输出分项,旧 checkpoint 缺少分项时降级为总量,
23
+ * 无数据(null/undefined)显示 unknown,不伪造 0;耗时仅在时间线末尾展示。
24
+ */
25
+ export declare function formatTuiTurnUsageStatus(usage: TurnUsageSummaryView | null | undefined): string;
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Context Usage 安全报告格式化。
2
+ * Context / Turn 用量安全报告格式化。
3
3
  *
4
- * 所有输入只来自 Core 白名单 ContextUsageView DTO;宿主只做展示转换,
4
+ * 所有输入只来自 Core 白名单 ContextUsageView / TurnUsageSummaryView DTO;宿主只做展示转换,
5
5
  * 不重算 token、不猜测窗口、不为非零分类强塞至少一格。
6
6
  */
7
7
  /** Core 固定枚举到 CLI 稳定中文标签的映射;不携带动态名称。 */
@@ -132,7 +132,7 @@ function renderGridLines(usage, columns) {
132
132
  }
133
133
  /**
134
134
  * 生成 Context 报告文本行。
135
- * grid=false(Plain/screen reader/NO_COLOR)跳过装饰网格但保留完整文本;
135
+ * grid=false(Plain/screen reader)跳过装饰网格但保留完整文本;
136
136
  * 列数不足以并排时整体改为上下堆叠。
137
137
  */
138
138
  export function formatContextReportLines(usage, expanded, options) {
@@ -171,3 +171,15 @@ export function formatTuiContextStatus(usage) {
171
171
  return "unknown";
172
172
  return `${Math.round(Math.max(0, 1 - usage.usageRatio) * 100)}%`;
173
173
  }
174
+ /**
175
+ * 状态栏累计用量行:优先展示累计输入/输出分项,旧 checkpoint 缺少分项时降级为总量,
176
+ * 无数据(null/undefined)显示 unknown,不伪造 0;耗时仅在时间线末尾展示。
177
+ */
178
+ export function formatTuiTurnUsageStatus(usage) {
179
+ if (!usage)
180
+ return "unknown";
181
+ const counts = usage.inputTokens !== undefined && usage.outputTokens !== undefined
182
+ ? `${formatTokens(usage.inputTokens)} in / ${formatTokens(usage.outputTokens)} out`
183
+ : `${formatTokens(usage.totalTokens)} total`;
184
+ return counts;
185
+ }
@@ -5,8 +5,9 @@
5
5
  * Session/Turn 状态机,审批只从当前安全 projection 取得 approvalId,绝不
6
6
  * 生成 callId、toolName、normalizedInputHash 或冻结工具输入。
7
7
  */
8
- import type { AgentEvent, ApprovalDecision, ContextUsageView } from "@autopilot-agent/core";
9
- import type { CliAction, CliCommand, CliEffortOption, CliExitCode, CliEventListener, CliJobView, CliQueuedInputStartedListener, CliModelOption, CliPermissionOption, CliProjection, CliRenderer, CliRuntimeStatusDefaults, CliSkillCatalogLister, CliSkillResolver, CliSkillSummary, CliStatusView, CliRuntime } from "./types.js";
8
+ import type { FileMentionReference } from "./file-mention-budget.js";
9
+ import type { AgentEvent, AgentEventEnvelope, ApprovalDecision, ContextUsageView, SessionImageRef } from "@autopilot-agent/core";
10
+ import type { CliAction, CliCommand, CliEffortOption, CliExitCode, CliEventListener, CliJobView, CliQueuedInputStartedListener, CliModelOption, CliPermissionOption, CliProjection, CliRenderer, CliRuntimeStatusDefaults, CliSkillCatalogLister, CliSkillResolver, CliSkillSummary, CliStatusView, CliTurnStatus, CliRuntime } from "./types.js";
10
11
  /** 为当前 Controller 注入的审批提交回调;四字段之外不允许宿主提供凭证。 */
11
12
  export type CliApprovalSubmit = (input: {
12
13
  sessionId: string;
@@ -20,6 +21,8 @@ export interface CliControllerResult {
20
21
  exitCode: CliExitCode;
21
22
  lines: string[];
22
23
  message?: string;
24
+ /** 仅在交互 TUI 的滚动覆盖层显示,不进入通知。 */
25
+ infoReport?: string;
23
26
  skillOptions?: CliSkillSummary[];
24
27
  /** 交互 TTY 用于打开权限 picker;Plain 模式使用同一结果中的稳定 lines。 */
25
28
  permissionOptions?: CliPermissionOption[];
@@ -41,8 +44,38 @@ export interface CliControllerResult {
41
44
  inputId: string;
42
45
  delivery: "steer" | "queue";
43
46
  };
47
+ /** Host 已持久记录的追加原文;不是Core inbox回执,不伪造inputId。 */
48
+ hostRecordedPrompt?: string;
49
+ continuationRequested?: boolean;
50
+ preparedPrompt?: {
51
+ content: string;
52
+ delivery?: "steer" | "queue";
53
+ attachments: SessionImageRef[];
54
+ selectedSkills: Array<{
55
+ skillRef: string;
56
+ skillId: string;
57
+ contentHash: string;
58
+ pinned: boolean;
59
+ }>;
60
+ activeSkills: Array<{
61
+ skillId: string;
62
+ contentHash: string;
63
+ }>;
64
+ fileMentions?: readonly FileMentionReference[];
65
+ };
44
66
  projection: CliProjection;
45
67
  }
68
+ /** 普通问题和宿主恢复问题共用编号/自定义答案解析,不将自然语言映射为隐式选择。 */
69
+ export declare function parseQuestionAnswer(content: string, item: {
70
+ id: string;
71
+ options: {
72
+ label: string;
73
+ }[];
74
+ }): {
75
+ id: string;
76
+ selected: string[];
77
+ custom?: string;
78
+ };
46
79
  /** Controller 创建参数。 */
47
80
  export interface CreateCliControllerOptions {
48
81
  runtime?: CliRuntime;
@@ -55,24 +88,68 @@ export interface CreateCliControllerOptions {
55
88
  workspaceRoot?: string;
56
89
  /** 读取已热更新的安全 Runtime 默认值;仅用于 idle/Completed 状态栏,不参与 Turn 冻结。 */
57
90
  getRuntimeStatusDefaults?: () => CliRuntimeStatusDefaults;
91
+ /** 受管宿主在原生附件与Skill解析后接管投递,不允许Controller另开执行。 */
92
+ handoffPrompt?: boolean;
58
93
  onEvent?: CliEventListener;
94
+ /** 普通执行与现有 Runner 共享 owner 索引;不因前台选择转移 owner。 */
95
+ registerExecution?(input: {
96
+ threadId: string;
97
+ turnId: string;
98
+ cancel(): void;
99
+ }): {
100
+ activate(): void;
101
+ release(): void;
102
+ };
59
103
  /** 自动启动 queue Turn 前通知交互 TUI,避免等待 prompt 残留在底部。 */
60
104
  onQueuedInputStarted?: CliQueuedInputStartedListener;
61
105
  now?: () => Date;
62
106
  }
63
107
  /** CLI Controller 对外接口。 */
64
108
  export interface CliController {
109
+ /** Desktop Worker 核验受管输入的文件路径,本地终端直接发送原文。 */
110
+ readonly resolveFileMentionsInHost?: true;
111
+ /** 受管执行者的审批反馈由宿主回执确认。 */
112
+ readonly hostApprovalFeedback?: true;
113
+ /** 当前受管审批暂停点的宿主回执。 */
114
+ getHostApprovalStatus?(): string | undefined;
115
+ /** 受管宿主可在公共目录上提供它实际执行的补全命令。 */
116
+ suggestSlashCommands?(input: string): import("./types.js").CliSlashCommand[];
117
+ /** 受管宿主可扩展输入命令;普通 CLI 继续采用默认解析。 */
118
+ parseInput?(input: string): import("./types.js").CliActionParseResult;
65
119
  dispatch(action: CliAction): Promise<CliControllerResult>;
66
120
  consume(events: AsyncIterable<AgentEvent>): Promise<CliControllerResult>;
67
- resume(): Promise<CliControllerResult>;
121
+ resume(expectedApproval?: {
122
+ turnId: string;
123
+ approvalId: string;
124
+ }): Promise<CliControllerResult>;
125
+ /** 只读回放安全事件,不领取输入、执行lease或恢复Turn。 */
126
+ observe?(events: readonly AgentEventEnvelope[]): void;
127
+ /** 只读权威身份改变时失效旧交互与在途结果,不恢复或执行。 */
128
+ invalidateObservedTurn?(input: {
129
+ turnId?: string;
130
+ status: CliTurnStatus;
131
+ }): void;
132
+ /** 同步权威当前交互,不改变正文回放游标。 */
133
+ syncObservedInteraction?(input: {
134
+ turnId: string;
135
+ status: CliTurnStatus;
136
+ approval?: AgentEventEnvelope;
137
+ requestId?: string;
138
+ }): void;
139
+ isExecuting?(): boolean;
140
+ beginShutdown?(): void;
68
141
  getProjection(): CliProjection;
69
142
  /** 读取当前 Session 默认或活动 Turn frozen 的脱敏状态栏视图。 */
70
- getStatusView?(): Promise<CliStatusView>;
143
+ getStatusView?(input?: {
144
+ signal?: AbortSignal;
145
+ }): Promise<CliStatusView>;
71
146
  setSession(sessionId: string): void;
72
147
  setEventListener(listener?: import("./types.js").CliEventListener): void;
73
148
  /** 绑定 queue Turn 启动通知;Plain 宿主不需要注册。 */
74
149
  setQueuedInputListener?(listener?: CliQueuedInputStartedListener): void;
75
150
  }
151
+ /** 将受信问题的当前题目与原选项投影为终端提示,数字选择与自定义文本共用原Core校验。 */
152
+ export declare function questionLines(question: NonNullable<NonNullable<import("@autopilot-agent/core").TurnExecutionView["interaction"]>["question"]>, index?: number): string[];
76
153
  /** 创建无 React 依赖的 Controller;Renderer 和 Runtime 均通过参数注入。 */
77
154
  export declare function createCliController(options: CreateCliControllerOptions): CliController;
78
155
  /** 将 argv 命令转换为 Step 5.2 可执行范围内的 Controller Action。 */