pi-web-ui 0.113.1 → 0.114.1

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 (280) hide show
  1. package/CHANGELOG.md +71 -1
  2. package/README.md +187 -316
  3. package/README.zh-CN.md +227 -299
  4. package/README.zh-TW.md +227 -299
  5. package/bin/device-hub-cli.mjs +577 -0
  6. package/bin/frp-manager.mjs +1573 -1573
  7. package/bin/pi-device-hub.mjs +9 -0
  8. package/bin/pi-web-ui.mjs +4081 -4041
  9. package/deploy/nginx-subpath.conf +100 -100
  10. package/deploy/pi-web-ui.service +36 -36
  11. package/dist/server/agent-service-daemon.js +102 -24
  12. package/dist/server/agent-service.js +2419 -1174
  13. package/dist/server/approval-rules.js +29 -3
  14. package/dist/server/ask-user-question-tool.js +8 -8
  15. package/dist/server/atomic-file.js +35 -14
  16. package/dist/server/attachment-store.js +71 -35
  17. package/dist/server/attachments.js +69 -13
  18. package/dist/server/canvas/canvas-agent-tool.js +68 -18
  19. package/dist/server/canvas/canvas-cards.js +1 -1
  20. package/dist/server/canvas/canvas-dispatch.js +61 -20
  21. package/dist/server/canvas/canvas-orchestrator.js +519 -202
  22. package/dist/server/canvas/canvas-scheduled-task.js +45 -0
  23. package/dist/server/canvas/canvas-scheduler.js +99 -0
  24. package/dist/server/canvas/canvas-store.js +107 -54
  25. package/dist/server/canvas/canvas-validation.js +131 -0
  26. package/dist/server/canvas/canvas-workspace.js +284 -0
  27. package/dist/server/client-id-utils.js +8 -0
  28. package/dist/server/client-state.js +110 -24
  29. package/dist/server/communicate-tool.js +76 -0
  30. package/dist/server/compact-context-tool.js +2 -3
  31. package/dist/server/compaction-instructions.js +75 -0
  32. package/dist/server/compaction-markers.js +7 -2
  33. package/dist/server/compaction-state.js +84 -0
  34. package/dist/server/composer-drafts.js +43 -40
  35. package/dist/server/context-evidence.js +346 -0
  36. package/dist/server/conversation-communication.js +368 -0
  37. package/dist/server/conversation-read-tool.js +3 -4
  38. package/dist/server/conversation-tool-names.js +14 -0
  39. package/dist/server/conversation-tool.js +57 -0
  40. package/dist/server/delegate-mode.js +17 -4
  41. package/dist/server/device-center/bot-catalog.js +88 -0
  42. package/dist/server/device-center/bot-execution.js +106 -0
  43. package/dist/server/device-center/bots.js +170 -0
  44. package/dist/server/device-center/collab-service.js +153 -0
  45. package/dist/server/device-center/collab-tool.js +184 -0
  46. package/dist/server/device-center/connector.js +351 -0
  47. package/dist/server/device-center/desktop-linux.js +372 -0
  48. package/dist/server/device-center/desktop-native.js +413 -0
  49. package/dist/server/device-center/desktop-page.js +232 -0
  50. package/dist/server/device-center/desktop-setup.js +30 -0
  51. package/dist/server/device-center/desktop.js +387 -0
  52. package/dist/server/device-center/device-portals.js +241 -0
  53. package/dist/server/device-center/execution-failure.js +70 -0
  54. package/dist/server/device-center/executor.js +371 -0
  55. package/dist/server/device-center/file-sync.js +493 -0
  56. package/dist/server/device-center/hub-auth.js +69 -0
  57. package/dist/server/device-center/hub-page.js +68 -0
  58. package/dist/server/device-center/hub-setup.js +214 -0
  59. package/dist/server/device-center/hub.js +830 -0
  60. package/dist/server/device-center/local-hub.js +92 -0
  61. package/dist/server/device-center/local.js +529 -0
  62. package/dist/server/device-center/main.js +118 -0
  63. package/dist/server/device-center/native-desktop/macos.js +192 -0
  64. package/dist/server/device-center/native-desktop/windows.js +118 -0
  65. package/dist/server/device-center/path-portal.js +120 -0
  66. package/dist/server/device-center/relay.js +996 -0
  67. package/dist/server/device-center/runtime.js +253 -0
  68. package/dist/server/device-center/store.js +122 -0
  69. package/dist/server/device-center/task-error.js +14 -0
  70. package/dist/server/device-center/transfers.js +293 -0
  71. package/dist/server/device-center/workspaces.js +45 -0
  72. package/dist/server/dispatch-domain-handlers.js +84 -27
  73. package/dist/server/dsh/dsh-agent-service.js +282 -159
  74. package/dist/server/dsh/dsh-client.js +12 -2
  75. package/dist/server/dsh/runtime/cordis.yml +1 -1
  76. package/dist/server/dsh/runtime/custom-prompt.mjs +33 -33
  77. package/dist/server/dsh/runtime/goal-rpc.mjs +1309 -1309
  78. package/dist/server/dsh/runtime/launcher.mjs +235 -235
  79. package/dist/server/dsh/runtime/override.patch.yml +89 -89
  80. package/dist/server/dsh/runtime/runtime-root.mjs +405 -405
  81. package/dist/server/durable/durable-agent-service.js +1 -1
  82. package/dist/server/engine-probe.js +36 -6
  83. package/dist/server/eval-tool.js +135 -135
  84. package/dist/server/evidence-tool-hooks.js +49 -0
  85. package/dist/server/file-save.js +95 -0
  86. package/dist/server/file-transfer-routes.js +97 -47
  87. package/dist/server/files-service.js +38 -26
  88. package/dist/server/global-loader.js +40 -2
  89. package/dist/server/goal-review-gate.js +16 -6
  90. package/dist/server/goal-service.js +54 -30
  91. package/dist/server/http-proxy.js +120 -0
  92. package/dist/server/index.js +285 -255
  93. package/dist/server/load-timing.js +31 -0
  94. package/dist/server/mcp-bridge.js +219 -94
  95. package/dist/server/mcp-hot-reload.js +31 -5
  96. package/dist/server/mcp-manager.js +192 -93
  97. package/dist/server/mcp-oauth-login.js +169 -0
  98. package/dist/server/mcp-oauth-ui.js +137 -0
  99. package/dist/server/mcp-oauth.js +395 -0
  100. package/dist/server/mcp-project-runtime.js +207 -0
  101. package/dist/server/message-window.js +74 -21
  102. package/dist/server/net-guard.js +122 -20
  103. package/dist/server/patch-bash-process.js +125 -0
  104. package/dist/server/patch-tool.js +9 -9
  105. package/dist/server/patch-turn-end-boundary.js +3 -3
  106. package/dist/server/payload-limits.js +17 -0
  107. package/dist/server/pending-question.js +82 -0
  108. package/dist/server/persona-chain.js +8 -8
  109. package/dist/server/plan-mode.js +338 -137
  110. package/dist/server/plugin-assets.js +8 -4
  111. package/dist/server/plugin-chat-attachments.js +48 -0
  112. package/dist/server/plugin-facilities.js +67 -220
  113. package/dist/server/plugin-installer.js +2 -1
  114. package/dist/server/plugin-removal.js +49 -0
  115. package/dist/server/plugin-secrets.js +179 -0
  116. package/dist/server/plugins.js +288 -94
  117. package/dist/server/preset-fields.js +56 -0
  118. package/dist/server/preset-plugin-dependencies.js +57 -0
  119. package/dist/server/preset-share.js +113 -72
  120. package/dist/server/prompt-templates.js +106 -0
  121. package/dist/server/protocol-version.js +1 -1
  122. package/dist/server/queue-modes.js +10 -0
  123. package/dist/server/remote-ssh-service.js +199 -106
  124. package/dist/server/request-context.js +164 -0
  125. package/dist/server/resolve-global-sdk.js +2 -0
  126. package/dist/server/sandbox-data.js +655 -0
  127. package/dist/server/sandbox-engines.js +7 -0
  128. package/dist/server/sandbox-runtime-gate.js +41 -0
  129. package/dist/server/sandbox-service.js +139 -698
  130. package/dist/server/sandbox-tool.js +21 -4
  131. package/dist/server/schedule-agent-tool.js +39 -21
  132. package/dist/server/scheduler-tasks.js +106 -55
  133. package/dist/server/scm-commitmsg.js +10 -10
  134. package/dist/server/serialize.js +48 -19
  135. package/dist/server/session-branch.js +25 -3
  136. package/dist/server/session-parser.js +28 -18
  137. package/dist/server/session-scan.js +130 -0
  138. package/dist/server/session-search.js +51 -37
  139. package/dist/server/settings-service.js +273 -111
  140. package/dist/server/setup-config.js +58 -0
  141. package/dist/server/setup-page.js +620 -620
  142. package/dist/server/skill-maintenance.js +112 -24
  143. package/dist/server/subagent-helpers.js +4 -1
  144. package/dist/server/subagent-notify.js +4 -1
  145. package/dist/server/subagent-security-gate.js +52 -11
  146. package/dist/server/subagent-task.js +27 -0
  147. package/dist/server/subagents.js +217 -46
  148. package/dist/server/tabs.js +9 -1
  149. package/dist/server/terminals.js +467 -363
  150. package/dist/server/text-quote.js +9 -0
  151. package/dist/server/tool-guards.js +42 -6
  152. package/dist/server/tool-manager.js +48 -20
  153. package/dist/server/tool-overrides.js +13 -11
  154. package/dist/server/tool-prompt-overrides.js +32 -2
  155. package/dist/server/tool-prompts.js +1 -1
  156. package/dist/server/turn-timing.js +11 -0
  157. package/dist/server/universal/drivers/claude-code.js +5 -0
  158. package/dist/server/universal/drivers/codex.js +336 -0
  159. package/dist/server/universal/index.js +1 -0
  160. package/dist/server/universal/session-store.js +48 -6
  161. package/dist/server/universal/universal-attachments.js +24 -1
  162. package/dist/server/universal/universal-service.js +1 -1
  163. package/dist/server/universal/universal-session.js +357 -231
  164. package/dist/server/uploads.js +64 -5
  165. package/dist/server/vision-bridge.js +18 -18
  166. package/dist/server/worktree-service.js +32 -24
  167. package/dist/server/ws-pending-queue.js +73 -27
  168. package/docs/device-center.md +148 -0
  169. package/docs/device-desktop.md +48 -0
  170. package/docs/dsh-engine.md +493 -493
  171. package/extensions/webui.ts +335 -335
  172. package/package.json +5 -2
  173. package/plugin-sdk/README.md +174 -174
  174. package/plugin-sdk/client-utils.mjs +279 -279
  175. package/plugin-sdk/import-check.mjs +210 -210
  176. package/plugin-sdk/index.d.ts +698 -676
  177. package/plugin-sdk/index.mjs +696 -696
  178. package/plugin-sdk/package.json +13 -13
  179. package/plugin-sdk/ssh-host-trust.mjs +225 -0
  180. package/plugins/catalog.json +11 -1
  181. package/themes/aetheris.css +501 -607
  182. package/themes/ayu-light.css +116 -140
  183. package/themes/bases/flow-base.css +1357 -1363
  184. package/themes/bases/obsidian-base.css +895 -895
  185. package/themes/bases/statusbar-flat-base.css +112 -0
  186. package/themes/bases/zhujian-base.css +688 -687
  187. package/themes/bases/zhupi-base.css +660 -659
  188. package/themes/catppuccin-latte.css +119 -142
  189. package/themes/catppuccin.css +116 -147
  190. package/themes/claude-code-dark.css +147 -146
  191. package/themes/codex.css +114 -138
  192. package/themes/cyberpunk.css +50 -108
  193. package/themes/dark-teal.css +264 -265
  194. package/themes/dazzle.css +38 -108
  195. package/themes/everforest-light.css +115 -138
  196. package/themes/flow-light.css +164 -164
  197. package/themes/flow.css +161 -161
  198. package/themes/geist.css +114 -138
  199. package/themes/gruvbox-light.css +115 -138
  200. package/themes/kanagawa-lotus.css +115 -138
  201. package/themes/md-preview.css +24 -234
  202. package/themes/mist.css +166 -186
  203. package/themes/nord.css +107 -138
  204. package/themes/one-dark.css +106 -139
  205. package/themes/paper.css +174 -186
  206. package/themes/rose-pine-dawn.css +114 -138
  207. package/themes/sakura.css +166 -186
  208. package/themes/solarized-light.css +114 -137
  209. package/themes/tokyo-night.css +115 -146
  210. package/themes/translucent.css +85 -85
  211. package/themes/transparent.css +116 -116
  212. package/themes/vs-code-dark.css +147 -147
  213. package/themes/wallpaper-flow.css +382 -382
  214. package/themes/wallpaper-obsidian.css +74 -74
  215. package/themes/white.css +164 -186
  216. package/themes/zhujian-dark.css +115 -114
  217. package/themes/zhujian.css +114 -114
  218. package/themes/zhupi-dark.css +115 -114
  219. package/themes/zhupi.css +114 -114
  220. package/web/dist/.build-assets.json +1 -0
  221. package/web/dist/assets/BgTasksModal-BcXJ20RO.js +1 -0
  222. package/web/dist/assets/BgTasksModal-DjQmiKnE.js +1 -0
  223. package/web/dist/assets/CanvasStudio-PI9pid0Y.js +1579 -0
  224. package/web/dist/assets/CanvasStudio-nf5-HxLM.js +1579 -0
  225. package/web/dist/assets/DeviceCenter-CYttJw2a.js +3 -0
  226. package/web/dist/assets/DeviceCenter-DPe4sz74.js +3 -0
  227. package/web/dist/assets/DeviceGroups-D2rogxEN.js +1 -0
  228. package/web/dist/assets/Dropdown-ZLS04O8p.js +1 -0
  229. package/web/dist/assets/FilePreview-C9Ut4Lq6.js +2 -0
  230. package/web/dist/assets/FilePreview-CvK3ZzX5.js +2 -0
  231. package/web/dist/assets/GlobalSearchModal-C5e-OCw2.js +1 -0
  232. package/web/dist/assets/GlobalSearchModal-H7pFK2UC.js +1 -0
  233. package/web/dist/assets/GroupConversation-C2wNM0dQ.js +1 -0
  234. package/web/dist/assets/GroupConversation-ChN3TWQK.js +1 -0
  235. package/web/dist/assets/ModelConfigModal-DDZccDYt.js +2 -0
  236. package/web/dist/assets/PiSetupModal-DHbqfx8T.js +1 -0
  237. package/web/dist/assets/ProviderOAuthControls-C-MK36Dk.js +1 -0
  238. package/web/dist/assets/SCMPanel-buTGziDB.js +2 -0
  239. package/web/dist/assets/SCMPanel-kx-SCL2s.js +2 -0
  240. package/web/dist/assets/SettingsModal-BsUF8jqr.js +20 -0
  241. package/web/dist/assets/SettingsModal-D357Ky7P.js +20 -0
  242. package/web/dist/assets/TerminalPanel-BBuM_Sez.js +3 -0
  243. package/web/dist/assets/TerminalPanel-D6x6xz8Q.js +3 -0
  244. package/web/dist/assets/TuiOverlayModal-CdbGV3Za.js +1 -0
  245. package/web/dist/assets/TuiOverlayModal-d6x9u25n.js +1 -0
  246. package/web/dist/assets/app-globals-DcyO0UPi.js +1 -0
  247. package/web/dist/assets/desktop-YguLbrX1.js +1 -0
  248. package/web/dist/assets/es-DWMIuDU2.js +2 -0
  249. package/web/dist/assets/fi-DaSO0Q-m.js +325 -0
  250. package/web/dist/assets/index-BPvpea8t.js +85 -0
  251. package/web/dist/assets/index-D6u8xH0o.js +85 -0
  252. package/web/dist/assets/index-DDZMv6LO.css +1 -0
  253. package/web/dist/assets/markdown-BggnuQ4H.js +40 -0
  254. package/web/dist/assets/markdown-C8LL_u4z.css +1 -0
  255. package/web/dist/assets/math-1uRJCsA9.js +257 -0
  256. package/web/dist/assets/math-BorAY7qD.css +1 -0
  257. package/web/dist/assets/plugin-host-BRBg6zmQ.js +1 -0
  258. package/web/dist/assets/shortcut-stack-hhrDyRBn.js +1 -0
  259. package/web/dist/assets/theme-DDl-Oy1b.js +1 -0
  260. package/web/dist/assets/uuid-BzDIGCwP.js +1 -0
  261. package/web/dist/index.html +42 -35
  262. package/web/dist/sw.js +179 -179
  263. package/web/public/sw.js +179 -179
  264. package/dist/gh-comment-781.md +0 -5
  265. package/dist/server/durable/durable-capabilities.js +0 -11
  266. package/dist/server/markers/builtins/services.js +0 -123
  267. package/dist/server/markers/builtins/todo.js +0 -189
  268. package/dist/server/markers-list-tool.js +0 -34
  269. package/dist/server/orchestrator.js +0 -109
  270. package/dist/server/system-prompt-soul.js +0 -41
  271. package/dist/server/univer-service.js +0 -448
  272. package/dist/server/universal/drivers/dsh-driver.js +0 -379
  273. package/dist/test-artifact.md +0 -9
  274. package/dist/test-preview-modal.md +0 -11
  275. package/dist/test-report.html +0 -20
  276. package/web/dist/assets/TerminalPanel-Ci55JtJL.js +0 -3
  277. package/web/dist/assets/index-ByiO9f-N.js +0 -2008
  278. package/web/dist/assets/index-ycGLh4a4.css +0 -1
  279. package/web/dist/assets/markdown-BJZlfvdP.js +0 -296
  280. package/web/dist/assets/markdown-DSNUiDzp.css +0 -1
@@ -30,6 +30,8 @@ import { Type } from "typebox";
30
30
  import { pick } from "./i18n.js";
31
31
  import { resolveSecurityMode } from "./subagent-security-gate.js";
32
32
  import { THINKING_LEVELS } from "./subagent-templates.js";
33
+ import { CONVERSATION_TOOL_NAME, SUBAGENT_TOOL_NAME } from "./tool-manager.js";
34
+ export { CONVERSATION_TOOL_NAME, SUBAGENT_TOOL_NAME } from "./tool-manager.js";
33
35
  /**
34
36
  * subagent_wait_all 的最长阻塞时间:必须短暂低于工具看门狗(默认 20 分钟,
35
37
  * PI_WEB_TOOL_TIMEOUT_MS 可调),否则看门狗会先中止整个会话而不是让 wait
@@ -49,10 +51,10 @@ export function computeWaitCapMs(watchdogMs) {
49
51
  : 20 * 60_000;
50
52
  return Math.max(Math.floor(watchdog * 0.8), 5_000);
51
53
  }
52
- /** 子代理是否已到终态(运行结束、被中止或出错)。wait 工具据此判断
53
- * 是否可以取结果;streaming=false 即可(error/canceled 都在快照里带标记)。 */
54
+ /** Idle is terminal only when the host has no pending task dependencies.
55
+ * Idle failures/cancellations remain terminal regardless of pending dependencies. */
54
56
  export function isSubagentTerminal(r) {
55
- return !!r && !r.streaming;
57
+ return !!r && !r.streaming && (!r.taskPending || !!r.error || !!r.canceled);
56
58
  }
57
59
  /** 从 prompt 取首行作为标题(截断 40 字符)。 */
58
60
  export function subagentTitle(prompt) {
@@ -68,29 +70,39 @@ export function subagentTitle(prompt) {
68
70
  * 可能已切到别的项目,直接读 activeId 会把孩子记到无关会话名下(错组/沉底)。
69
71
  * 每个会话创建 runtime 时用本函数包一层,让它的 spawn 天然带自己的会话 id。
70
72
  */
71
- export function withSubagentOwner(host, ownerId) {
73
+ export function withSubagentOwner(host, ownerId, resolveOwner = () => ownerId) {
72
74
  return {
73
75
  ...host,
74
- spawnSubagent: (prompt, type, cwd, templateName, model, _parentId, persist, thinking, notifyOnDone, isolation, extra) => {
75
- const args = [prompt, type, cwd, templateName, model, ownerId, persist, thinking, notifyOnDone];
76
- if (isolation !== undefined || extra !== undefined) {
76
+ spawnSubagent: (prompt, type, cwd, templateName, model, _parentId, persist, thinking, notifyOnDone, isolation, extra, signal) => {
77
+ signal?.throwIfAborted();
78
+ const args = [prompt, type, cwd, templateName, model, resolveOwner(), persist, thinking, notifyOnDone];
79
+ if (isolation !== undefined || extra !== undefined || signal !== undefined) {
77
80
  args.push(isolation);
78
81
  }
79
- if (extra !== undefined) {
82
+ if (extra !== undefined || signal !== undefined) {
80
83
  args.push(extra);
81
84
  }
85
+ if (signal !== undefined)
86
+ args.push(signal);
82
87
  return host.spawnSubagent(...args);
83
88
  },
84
- handoffSubagent: (fromRunId, toRunId, payload) => host.handoffSubagent(fromRunId || ownerId, toRunId, payload),
89
+ handoffSubagent: async (fromRunId, toRunId, payload) => {
90
+ const selfId = resolveOwner();
91
+ if (!selfId)
92
+ throw new Error("Handoff requires a verified conversation identity.");
93
+ if (fromRunId && fromRunId !== selfId)
94
+ throw new Error("Handoff source must match the calling conversation.");
95
+ return host.handoffSubagent(selfId, toRunId, payload);
96
+ },
85
97
  markSubagentsConsumed: (runIds) => host.markSubagentsConsumed?.(runIds),
86
98
  finalizeSubagentWorktree: (convId) => host.finalizeSubagentWorktree?.(convId) ?? Promise.resolve(),
87
99
  getActiveConversationId: () => host.getActiveConversationId?.(),
88
100
  dismissSubagent: (convId, opts) => host.dismissSubagent?.(convId, opts) ?? Promise.resolve({ ok: false, reason: "unsupported" }),
89
101
  };
90
102
  }
91
- export const SUBAGENT_TOOL_NAME = "subagent";
92
103
  export const SUBAGENT_ACTIONS = [
93
104
  "spawn",
105
+ "complete",
94
106
  "get_result",
95
107
  "steer",
96
108
  "list",
@@ -99,6 +111,9 @@ export const SUBAGENT_ACTIONS = [
99
111
  "templates",
100
112
  "handoff",
101
113
  "dismiss",
114
+ "consult",
115
+ "answer",
116
+ "escalate",
102
117
  ];
103
118
  /**
104
119
  * 单 action 子代理总工具(注册进每个会话的 customTools,供主 agent 驱动子代理)。
@@ -120,6 +135,9 @@ export function makeSubagentTool(host, lang, selfConvId) {
120
135
  content: [{ type: "text", text: t }],
121
136
  details,
122
137
  });
138
+ // Share delivery memory across the primary tool and legacy alias. Keep only live requests.
139
+ const deliveredConsults = new Set();
140
+ const consultKey = (parentId, runId, requestId) => JSON.stringify([parentId, runId, requestId]);
123
141
  const expandDescendants = (roots) => {
124
142
  if (roots instanceof Set ? roots.size === 0 : roots.length === 0)
125
143
  return [];
@@ -182,29 +200,62 @@ export function makeSubagentTool(host, lang, selfConvId) {
182
200
  : computeWaitCapMs();
183
201
  const capSeconds = Math.floor(currentWaitCapMs / 1000);
184
202
  return defineTool({
185
- name: SUBAGENT_TOOL_NAME,
186
- label: "Subagent manager",
187
- description: "Manage background subagent conversations for parallel delegation, research, and execution. " +
203
+ name: CONVERSATION_TOOL_NAME,
204
+ label: "Conversation collaboration",
205
+ description: "Create and manage collaborative conversations, including temporary subagents and persistent sessions, for delegation, research, and execution. " +
188
206
  "Each action's arguments are documented on the parameters below.",
189
- promptSnippet: "manage background subagents (spawn/steer/wait/dismiss)",
207
+ promptSnippet: "Delegate tasks, inspect results, or request task completion.",
208
+ promptGuidelines: [
209
+ "Prefer communicate for messages and questions; consult/answer/escalate/handoff remain compatible.",
210
+ ],
190
211
  parameters: Type.Object({
191
212
  action: Type.Unsafe({
192
213
  type: "string",
193
214
  enum: [...SUBAGENT_ACTIONS],
194
215
  description: "The subagent action to perform.",
195
216
  }),
217
+ questions: Type.Optional(Type.Array(Type.Object({
218
+ id: Type.String({ minLength: 1 }),
219
+ question: Type.String({ minLength: 1 }),
220
+ detail: Type.Optional(Type.String()),
221
+ header: Type.Optional(Type.String()),
222
+ options: Type.Optional(Type.Array(Type.Object({
223
+ label: Type.String(),
224
+ description: Type.Optional(Type.String()),
225
+ preview: Type.Optional(Type.String()),
226
+ recommended: Type.Optional(Type.Boolean()),
227
+ }))),
228
+ multiSelect: Type.Optional(Type.Boolean()),
229
+ dependsOn: Type.Optional(Type.Object({
230
+ questionId: Type.String(),
231
+ value: Type.Optional(Type.Union([Type.String(), Type.Array(Type.String())])),
232
+ })),
233
+ optionsMap: Type.Optional(Type.Record(Type.String(), Type.Array(Type.Object({
234
+ label: Type.String(),
235
+ description: Type.Optional(Type.String()),
236
+ preview: Type.Optional(Type.String()),
237
+ recommended: Type.Optional(Type.Boolean()),
238
+ })))),
239
+ }), { description: "consult: ask the parent for a decision.", minItems: 1, maxItems: 3 })),
240
+ requestId: Type.Optional(Type.String({ description: "answer/escalate: pending consult request ID." })),
241
+ answers: Type.Optional(Type.Array(Type.Object({
242
+ id: Type.String(),
243
+ selected: Type.Array(Type.String()),
244
+ custom: Type.Optional(Type.String()),
245
+ }), { description: "answer: responses to the child's consult.", minItems: 1 })),
196
246
  prompt: Type.Optional(Type.String({
197
247
  description: "spawn: instructions (goal, constraints, expected output).",
198
248
  })),
199
249
  runId: Type.Optional(Type.String({
200
- description: "get_result/steer/stop/dismiss: target conversation ID.",
250
+ description: "get_result/steer/stop/dismiss/answer/escalate: target conversation ID.",
201
251
  })),
202
252
  runIds: Type.Optional(Type.Array(Type.String(), {
203
253
  description: "wait_all/dismiss: conversation IDs to wait for or dismiss.",
204
254
  })),
205
255
  message: Type.Optional(Type.String({
206
- description: "steer: follow-up instruction.",
256
+ description: "steer: follow-up instruction; complete: completion summary alias.",
207
257
  })),
258
+ summary: Type.Optional(Type.String({ description: "complete: final task summary." })),
208
259
  payload: Type.Optional(Type.String({
209
260
  description: "handoff: what to transfer to the peer.",
210
261
  })),
@@ -212,7 +263,7 @@ export function makeSubagentTool(host, lang, selfConvId) {
212
263
  description: "handoff: target peer ID.",
213
264
  })),
214
265
  fromRunId: Type.Optional(Type.String({
215
- description: "handoff: source ID (default = this subagent).",
266
+ description: "handoff: optional source ID; must match the calling conversation.",
216
267
  })),
217
268
  type: Type.Optional(Type.String({
218
269
  description: "spawn: role/type (e.g. explore/implement/review, default: general). When matching a template name, the template and its security profile (e.g. readonly for explore, verify for review) are automatically applied.",
@@ -227,8 +278,8 @@ export function makeSubagentTool(host, lang, selfConvId) {
227
278
  enum: [...THINKING_LEVELS],
228
279
  description: 'spawn: thinking budget level ("off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max").',
229
280
  })),
230
- notifyOnDone: Type.Optional(Type.Boolean({
231
- description: "spawn: notify and wake parent conversation when finished (default: true).",
281
+ notifyOnDone: Type.Optional(Type.Union([Type.Boolean(), Type.Literal("manual")], {
282
+ description: "spawn: true wakes parent per turn, false disables wakes, manual waits for task completion (default: true).",
232
283
  })),
233
284
  cwd: Type.Optional(Type.String({
234
285
  description: "spawn: working directory (default = current).",
@@ -245,7 +296,7 @@ export function makeSubagentTool(host, lang, selfConvId) {
245
296
  description: "list: filter subagents by kind (default: all).",
246
297
  })),
247
298
  timeoutSeconds: Type.Optional(Type.Integer({
248
- description: `wait_all: max wait in seconds (default: ${capSeconds}s).`,
299
+ description: `wait_all: max wait in seconds (default: ${capSeconds}s); returns early for new parent consults.`,
249
300
  minimum: 1,
250
301
  maximum: capSeconds,
251
302
  })),
@@ -263,9 +314,75 @@ export function makeSubagentTool(host, lang, selfConvId) {
263
314
  execute: async (_id, p, signal, _onUpdate, ctx) => {
264
315
  const action = (p.action ?? "").trim().toLowerCase();
265
316
  if (!action) {
266
- return text(pick(getLang(), "subagent 工具缺少 action 参数(可选:spawn, get_result, steer, list, stop, wait_all, templates, handoff, dismiss)。", "subagent tool requires an action parameter (one of: spawn, get_result, steer, list, stop, wait_all, templates, handoff, dismiss).", "subagents.action.missing"));
317
+ return text(pick(getLang(), `subagent 工具缺少 action 参数(可选:${SUBAGENT_ACTIONS.join(", ")})。`, `subagent tool requires an action parameter (one of: ${SUBAGENT_ACTIONS.join(", ")}).`, "subagents.action.missing"));
267
318
  }
268
319
  switch (action) {
320
+ case "complete": {
321
+ signal?.throwIfAborted();
322
+ const selfId = selfIdOf();
323
+ if (!selfId || !host.completeSubagent)
324
+ throw new Error("Task completion is unavailable.");
325
+ const summary = (p.summary ?? p.message ?? "").trim();
326
+ if (!summary)
327
+ throw new Error("complete requires a nonempty summary or message.");
328
+ const result = await host.completeSubagent(selfId, summary);
329
+ if (result && typeof result === "object" && "ok" in result && result.ok === false) {
330
+ throw new Error(String("error" in result ? result.error : "Completion request rejected."));
331
+ }
332
+ return text("Completion intent recorded; settlement waits for idle state and pending dependencies.", {
333
+ status: "completion_requested",
334
+ runId: selfId,
335
+ });
336
+ }
337
+ case "consult": {
338
+ signal?.throwIfAborted();
339
+ const selfId = selfIdOf();
340
+ if (!selfId || !host.consultParent)
341
+ throw new Error("Parent consultation is unavailable.");
342
+ if (!Array.isArray(p.questions) ||
343
+ p.questions.length < 1 ||
344
+ p.questions.length > 3 ||
345
+ p.questions.some((q) => !q || typeof q.id !== "string" || !q.id.trim() || typeof q.question !== "string" || !q.question.trim()) ||
346
+ new Set(p.questions.map((q) => q.id)).size !== p.questions.length) {
347
+ throw new Error("consult requires 1-3 questions with unique IDs and nonempty text.");
348
+ }
349
+ const result = await host.consultParent(selfId, p.questions, signal);
350
+ signal?.throwIfAborted();
351
+ return text(`${JSON.stringify(result) ?? "Consult resolved."}\nIf timed_out, do not choose on the parent's behalf. Ask again with only the context needed for the decision.`, result);
352
+ }
353
+ case "answer":
354
+ case "escalate": {
355
+ signal?.throwIfAborted();
356
+ const selfId = selfIdOf();
357
+ if (!selfId || !p.runId?.trim() || !p.requestId?.trim()) {
358
+ throw new Error(`${action} requires caller identity, runId and requestId.`);
359
+ }
360
+ let result;
361
+ if (action === "answer") {
362
+ if (!host.answerConsult)
363
+ throw new Error("Consult answers are unavailable.");
364
+ if (!Array.isArray(p.answers) ||
365
+ p.answers.length === 0 ||
366
+ p.answers.some((a) => !a ||
367
+ typeof a.id !== "string" ||
368
+ !a.id.trim() ||
369
+ !Array.isArray(a.selected) ||
370
+ a.selected.some((s) => typeof s !== "string") ||
371
+ (a.custom !== undefined && typeof a.custom !== "string"))) {
372
+ throw new Error("answer requires structured answers.");
373
+ }
374
+ result = await host.answerConsult(selfId, p.runId, p.requestId, p.answers);
375
+ }
376
+ else {
377
+ if (!host.escalateConsult)
378
+ throw new Error("Consult escalation is unavailable.");
379
+ result = await host.escalateConsult(selfId, p.runId, p.requestId);
380
+ }
381
+ if (result && typeof result === "object" && "ok" in result && result.ok === false) {
382
+ throw new Error("error" in result ? String(result.error) : `Consult ${action} rejected.`);
383
+ }
384
+ return text(JSON.stringify(result) ?? `Consult ${action} submitted.`, result);
385
+ }
269
386
  case "spawn": {
270
387
  if (!p.prompt || typeof p.prompt !== "string" || !p.prompt.trim()) {
271
388
  return text(pick(getLang(), 'subagent(action="spawn") 缺少 prompt 参数。', 'subagent(action="spawn") requires prompt parameter.', "subagents.spawn.missing.prompt"));
@@ -304,12 +421,15 @@ export function makeSubagentTool(host, lang, selfConvId) {
304
421
  p.thinking,
305
422
  p.notifyOnDone,
306
423
  ];
307
- if (isolationMode === "worktree" || extra !== undefined) {
424
+ if (isolationMode === "worktree" || extra !== undefined || signal !== undefined) {
308
425
  spawnArgs.push(isolationMode === "worktree" ? "worktree" : undefined);
309
426
  }
310
- if (extra !== undefined) {
427
+ if (extra !== undefined || signal !== undefined) {
311
428
  spawnArgs.push(extra);
312
429
  }
430
+ if (signal !== undefined)
431
+ spawnArgs.push(signal);
432
+ signal?.throwIfAborted();
313
433
  convId = await host.spawnSubagent(...spawnArgs);
314
434
  }
315
435
  catch (err) {
@@ -359,7 +479,7 @@ export function makeSubagentTool(host, lang, selfConvId) {
359
479
  model: p.model,
360
480
  thinking: p.thinking,
361
481
  persisted: !!p.persist,
362
- notifyOnDone: p.notifyOnDone !== false,
482
+ notifyOnDone: p.notifyOnDone ?? true,
363
483
  isolation: isolationMode === "worktree" ? "worktree" : undefined,
364
484
  });
365
485
  }
@@ -376,7 +496,7 @@ export function makeSubagentTool(host, lang, selfConvId) {
376
496
  const doneDetail = verdictText(r, getLang());
377
497
  const doneOutput = r.output || (getLang() === "zh" ? "(无结果)" : "(no result)");
378
498
  const modelTag = r.model ? ` · ${r.model}${r.thinkingLevel ? `:${r.thinkingLevel}` : ""}` : "";
379
- if (r.streaming || r.state === "running") {
499
+ if (!isSubagentTerminal(r)) {
380
500
  const runningId = shortId(r.convId);
381
501
  const runningOutput = r.output || (getLang() === "zh" ? "(暂无输出)" : "(no output yet)");
382
502
  return text(pick(getLang(), `子代理 ${runningId}(${r.type}${modelTag})仍在运行(状态 ${r.state})。\n当前输出:\n${runningOutput}`, `Subagent ${runningId} (${r.type}${modelTag}) is still running (state ${r.state}).\nCurrent output:\n${runningOutput}`, "subagents.get.running", { runningId, "r.type": r.type, modelTag, "r.state": r.state, runningOutput }), r);
@@ -497,7 +617,29 @@ export function makeSubagentTool(host, lang, selfConvId) {
497
617
  wanted.delete(selfId);
498
618
  for (const ancId of selfAncestorIds)
499
619
  wanted.delete(ancId);
620
+ const collectConsults = () => {
621
+ const parentId = selfIdOf();
622
+ if (!parentId || !host.getPendingConsults || signal?.aborted)
623
+ return;
624
+ // The host authorizes direct-child requests for this parent, independent of runIds.
625
+ const pending = host.getPendingConsults(parentId);
626
+ const liveKeys = new Set(pending.map((r) => consultKey(parentId, r.runId, r.requestId)));
627
+ for (const key of deliveredConsults) {
628
+ if (!liveKeys.has(key))
629
+ deliveredConsults.delete(key);
630
+ }
631
+ const requests = pending.filter((r) => !deliveredConsults.has(consultKey(parentId, r.runId, r.requestId)));
632
+ if (requests.length === 0)
633
+ return;
634
+ for (const r of requests)
635
+ deliveredConsults.add(consultKey(parentId, r.runId, r.requestId));
636
+ const result = { status: "needs_input", requests };
637
+ return text(`Child consults need your decision. Use answer or escalate before waiting again.\n${JSON.stringify(result)}`, result);
638
+ };
500
639
  if (wanted.size === 0) {
640
+ const consults = collectConsults();
641
+ if (consults)
642
+ return consults;
501
643
  return text(pick(getLang(), "没有需要等待的子代理(调用者自身与其祖先永不计入等待;子代理无参数调用时只等待属于它自己的后代)。", "No subagents to wait for (the calling session itself and its ancestors are never waited on; a subagent without runIds only waits for its own descendants).", "subagents.wait.empty"));
502
644
  }
503
645
  const liveWaitCapMs = typeof host.getWatchdogTimeoutMs === "function"
@@ -507,24 +649,37 @@ export function makeSubagentTool(host, lang, selfConvId) {
507
649
  const timeoutMs = Math.min(Math.max(p.timeoutSeconds ?? liveCapSeconds, 1), liveCapSeconds) * 1000;
508
650
  const startedAt = Date.now();
509
651
  const POLL_INTERVAL_MS = 250;
510
- while (!signal?.aborted && Date.now() - startedAt < timeoutMs) {
511
- for (const descId of expandDescendants(wanted)) {
512
- if (selfId && descId === selfId)
513
- continue;
514
- if (selfAncestorIds.has(descId))
515
- continue;
516
- wanted.add(descId);
652
+ try {
653
+ const waitingParentId = selfIdOf();
654
+ if (waitingParentId)
655
+ host.setConsultWaiting?.(waitingParentId, true);
656
+ while (!signal?.aborted && Date.now() - startedAt < timeoutMs) {
657
+ for (const descId of expandDescendants(wanted)) {
658
+ if (selfId && descId === selfId)
659
+ continue;
660
+ if (selfAncestorIds.has(descId))
661
+ continue;
662
+ wanted.add(descId);
663
+ }
664
+ const consults = collectConsults();
665
+ if (consults)
666
+ return consults;
667
+ const allDone = Array.from(wanted).every((id) => {
668
+ const r = host.getSubagent(id);
669
+ // #488:getSubagent 返回 undefined = 已被移出(强行关闭/收尾清理)
670
+ // ——视为终态,与下方报告段「已移出或不存在」口径一致;否则等待
671
+ // 集合含被移出子代理时 allDone 恒 false,必然白等满 timeoutMs。
672
+ return r === undefined || isSubagentTerminal(r);
673
+ });
674
+ if (allDone)
675
+ break;
676
+ await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));
517
677
  }
518
- const allDone = Array.from(wanted).every((id) => {
519
- const r = host.getSubagent(id);
520
- // #488:getSubagent 返回 undefined = 已被移出(强行关闭/收尾清理)
521
- // ——视为终态,与下方报告段「已移出或不存在」口径一致;否则等待
522
- // 集合含被移出子代理时 allDone 恒 false,必然白等满 timeoutMs。
523
- return r === undefined || isSubagentTerminal(r);
524
- });
525
- if (allDone)
526
- break;
527
- await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));
678
+ }
679
+ finally {
680
+ const waitingParentId = selfIdOf();
681
+ if (waitingParentId)
682
+ host.setConsultWaiting?.(waitingParentId, false);
528
683
  }
529
684
  const tLang = getLang();
530
685
  const waitedSecs = Math.max(1, Math.round((Date.now() - startedAt) / 1000));
@@ -609,7 +764,13 @@ export function makeSubagentTool(host, lang, selfConvId) {
609
764
  return text(pick(getLang(), `可用的子代理模板(subagent 的 template 参数传名字,如 subagent(action="spawn", template="${firstTemplateName}")):\n${templateLines}`, `Available subagent templates (pass the name as subagent's template param, e.g. subagent(action="spawn", template="${firstTemplateName}")):\n${templateLines}`, "subagents.templates.list", { firstTemplateName, templateLines }));
610
765
  }
611
766
  case "handoff": {
612
- const fromId = p.fromRunId || selfIdOf() || "unknown";
767
+ signal?.throwIfAborted();
768
+ const fromId = selfIdOf();
769
+ if (!fromId)
770
+ throw new Error("Handoff requires a verified conversation identity.");
771
+ if (p.fromRunId && p.fromRunId !== fromId) {
772
+ throw new Error("Handoff source must match the calling conversation.");
773
+ }
613
774
  if (!p.toRunId || typeof p.toRunId !== "string" || !p.toRunId.trim()) {
614
775
  return text(pick(getLang(), 'subagent(action="handoff") 缺少 toRunId 参数。', 'subagent(action="handoff") requires toRunId parameter.', "subagents.handoff.missing.toRunId"));
615
776
  }
@@ -807,7 +968,7 @@ export function makeSubagentTool(host, lang, selfConvId) {
807
968
  return text(pick(getLang(), `已成功移出 ${dismissed.length} 个子代理${skippedZh}。移出后不可逆(会话已从左栏移除并释放运行时与临时数据)。提示:如需获取产物,请在移出前调用 subagent(action="get_result")。`, `Successfully dismissed ${dismissed.length} subagent(s)${skippedEn}. Dismissal is irreversible (sessions removed from panel, runtimes and temporary data released). Note: call subagent(action="get_result") before dismissal if you need their outputs.`, "subagents.dismiss.success.batch", { count: dismissed.length, skippedZh, skippedEn }), { dismissed, skipped });
808
969
  }
809
970
  default:
810
- return text(pick(getLang(), `未知 action:${action}。支持的 action:spawn, get_result, steer, list, stop, wait_all, templates, handoff, dismiss。`, `Unknown action: ${action}. Supported actions: spawn, get_result, steer, list, stop, wait_all, templates, handoff, dismiss.`, "subagents.action.unknown", { action }));
971
+ return text(pick(getLang(), `未知 action:${action}。支持的 action:${SUBAGENT_ACTIONS.join(", ")}。`, `Unknown action: ${action}. Supported actions: ${SUBAGENT_ACTIONS.join(", ")}.`, "subagents.action.unknown", { action }));
811
972
  }
812
973
  },
813
974
  });
@@ -816,7 +977,17 @@ export function makeSubagentTool(host, lang, selfConvId) {
816
977
  * 保持数组签名的子代理工具导出,兼容原有调用点与批处理包装。
817
978
  */
818
979
  export function makeSubagentTools(host, lang, selfConvId) {
819
- return [makeSubagentTool(host, lang, selfConvId)];
980
+ const primary = makeSubagentTool(host, lang, selfConvId);
981
+ return [
982
+ primary,
983
+ {
984
+ ...primary,
985
+ name: SUBAGENT_TOOL_NAME,
986
+ label: "Conversation collaboration (legacy alias)",
987
+ description: "Compatibility alias for conversation. Prefer conversation for new calls; parameters and behavior are identical.",
988
+ promptSnippet: "support existing subagent calls; prefer conversation",
989
+ },
990
+ ];
820
991
  }
821
992
  /** 短 id 前缀(前端展示/日志用)。 */
822
993
  function shortId(id) {
@@ -873,7 +1044,7 @@ function subagentVerdict(r, lang = "en") {
873
1044
  return pick(lang, "error(报错)", "error", "subagents.verdict.error");
874
1045
  if (r.canceled)
875
1046
  return pick(lang, "canceled(已中止)", "canceled", "subagents.verdict.canceled");
876
- return r.state;
1047
+ return r.taskPending ? "pending" : r.state;
877
1048
  }
878
1049
  /** 终态的可读说明(错误文本 / 中止说明 / 空)。运行中返回空。 */
879
1050
  function verdictText(r, lang = "en") {
@@ -32,7 +32,15 @@ export const ALL_TABS = ["chat", "terminal", "git", "search", "tasks", "settings
32
32
  * is exactly the failure this module exists to prevent.
33
33
  */
34
34
  const OWNED = {
35
- terminal: ["terminal_create", "terminal_input", "terminal_resize", "terminal_kill", "rename_terminal", "run_command"],
35
+ terminal: [
36
+ "terminal_attach",
37
+ "terminal_create",
38
+ "terminal_input",
39
+ "terminal_resize",
40
+ "terminal_kill",
41
+ "rename_terminal",
42
+ "run_command",
43
+ ],
36
44
  git: ["scm_status", "scm_history", "scm_filediff", "scm_commit"],
37
45
  tasks: ["list_bg_servers", "kill_background_server", "kill_background_servers"],
38
46
  search: ["search_files", "search_sessions"],