@narumitw/pi-subagents 2.1.3 → 3.0.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 (314) hide show
  1. package/README.md +181 -1250
  2. package/dist/child-communication-bridge.ts +136 -0
  3. package/dist/child-communication-bridge.ts.map +7 -0
  4. package/dist/chunks/chunk-UKTWUQRM.js +667 -0
  5. package/dist/chunks/chunk-UKTWUQRM.js.map +7 -0
  6. package/dist/index.ts +1448 -1598
  7. package/dist/index.ts.map +4 -4
  8. package/docs/design-principles.md +31 -0
  9. package/docs/ipc-transport-idea.md +103 -0
  10. package/docs/tools.md +109 -0
  11. package/package.json +11 -19
  12. package/src/broker-credentials.ts +71 -0
  13. package/src/child-communication-bridge.ts +153 -0
  14. package/src/child-communication-tools.ts +147 -0
  15. package/src/completion-renderer.ts +60 -0
  16. package/src/index.ts +1 -1
  17. package/src/message-broker.ts +628 -0
  18. package/src/model-output.ts +42 -0
  19. package/src/process.ts +688 -0
  20. package/src/runtime.ts +538 -0
  21. package/src/subagents.ts +33 -34
  22. package/src/tools.ts +416 -0
  23. package/src/types.ts +85 -0
  24. package/src/widget.ts +130 -0
  25. package/dist/chunks/auto-transport-FUUKFDIG.ts +0 -109
  26. package/dist/chunks/auto-transport-FUUKFDIG.ts.map +0 -7
  27. package/dist/chunks/capability-grant-PR72SWWS.ts +0 -19
  28. package/dist/chunks/capability-grant-PR72SWWS.ts.map +0 -7
  29. package/dist/chunks/child-peer-bridge.ts +0 -108
  30. package/dist/chunks/child-peer-bridge.ts.map +0 -7
  31. package/dist/chunks/chunk-2LMJU25E.ts +0 -1641
  32. package/dist/chunks/chunk-2LMJU25E.ts.map +0 -7
  33. package/dist/chunks/chunk-47SK2QYC.ts +0 -56
  34. package/dist/chunks/chunk-47SK2QYC.ts.map +0 -7
  35. package/dist/chunks/chunk-4AQSF7AS.ts +0 -29
  36. package/dist/chunks/chunk-4AQSF7AS.ts.map +0 -7
  37. package/dist/chunks/chunk-5DGRMKNV.ts +0 -126
  38. package/dist/chunks/chunk-5DGRMKNV.ts.map +0 -7
  39. package/dist/chunks/chunk-6H6TBBED.ts +0 -108
  40. package/dist/chunks/chunk-6H6TBBED.ts.map +0 -7
  41. package/dist/chunks/chunk-6KJ34M6S.ts +0 -159
  42. package/dist/chunks/chunk-6KJ34M6S.ts.map +0 -7
  43. package/dist/chunks/chunk-6NSJVPXX.ts +0 -480
  44. package/dist/chunks/chunk-6NSJVPXX.ts.map +0 -7
  45. package/dist/chunks/chunk-7AAJEUSL.ts +0 -238
  46. package/dist/chunks/chunk-7AAJEUSL.ts.map +0 -7
  47. package/dist/chunks/chunk-BFK2Z4ZF.ts +0 -189
  48. package/dist/chunks/chunk-BFK2Z4ZF.ts.map +0 -7
  49. package/dist/chunks/chunk-BOAXY55Y.ts +0 -153
  50. package/dist/chunks/chunk-BOAXY55Y.ts.map +0 -7
  51. package/dist/chunks/chunk-D4CR7T73.ts +0 -353
  52. package/dist/chunks/chunk-D4CR7T73.ts.map +0 -7
  53. package/dist/chunks/chunk-FEVPWRMU.ts +0 -300
  54. package/dist/chunks/chunk-FEVPWRMU.ts.map +0 -7
  55. package/dist/chunks/chunk-G6VZTCFH.ts +0 -70
  56. package/dist/chunks/chunk-G6VZTCFH.ts.map +0 -7
  57. package/dist/chunks/chunk-H3FP6DLR.ts +0 -160
  58. package/dist/chunks/chunk-H3FP6DLR.ts.map +0 -7
  59. package/dist/chunks/chunk-HA36LPCO.ts +0 -130
  60. package/dist/chunks/chunk-HA36LPCO.ts.map +0 -7
  61. package/dist/chunks/chunk-HOP5FXDT.ts +0 -27
  62. package/dist/chunks/chunk-HOP5FXDT.ts.map +0 -7
  63. package/dist/chunks/chunk-IGAMVWFN.ts +0 -139
  64. package/dist/chunks/chunk-IGAMVWFN.ts.map +0 -7
  65. package/dist/chunks/chunk-ILEQ27AL.ts +0 -45
  66. package/dist/chunks/chunk-ILEQ27AL.ts.map +0 -7
  67. package/dist/chunks/chunk-ITVWPNU4.ts +0 -819
  68. package/dist/chunks/chunk-ITVWPNU4.ts.map +0 -7
  69. package/dist/chunks/chunk-IWC32VPY.ts +0 -172
  70. package/dist/chunks/chunk-IWC32VPY.ts.map +0 -7
  71. package/dist/chunks/chunk-JSZIP73U.ts +0 -362
  72. package/dist/chunks/chunk-JSZIP73U.ts.map +0 -7
  73. package/dist/chunks/chunk-JU6LUNLP.ts +0 -380
  74. package/dist/chunks/chunk-JU6LUNLP.ts.map +0 -7
  75. package/dist/chunks/chunk-KMGKCEO4.ts +0 -38
  76. package/dist/chunks/chunk-KMGKCEO4.ts.map +0 -7
  77. package/dist/chunks/chunk-LASD73CM.ts +0 -339
  78. package/dist/chunks/chunk-LASD73CM.ts.map +0 -7
  79. package/dist/chunks/chunk-LEOYDZI3.ts +0 -22
  80. package/dist/chunks/chunk-LEOYDZI3.ts.map +0 -7
  81. package/dist/chunks/chunk-LL4LP2T7.ts +0 -737
  82. package/dist/chunks/chunk-LL4LP2T7.ts.map +0 -7
  83. package/dist/chunks/chunk-N2T5IN4X.ts +0 -18
  84. package/dist/chunks/chunk-N2T5IN4X.ts.map +0 -7
  85. package/dist/chunks/chunk-N7BLVXKK.ts +0 -73
  86. package/dist/chunks/chunk-N7BLVXKK.ts.map +0 -7
  87. package/dist/chunks/chunk-NLT67IZS.ts +0 -322
  88. package/dist/chunks/chunk-NLT67IZS.ts.map +0 -7
  89. package/dist/chunks/chunk-NTRPLF46.ts +0 -63
  90. package/dist/chunks/chunk-NTRPLF46.ts.map +0 -7
  91. package/dist/chunks/chunk-ONDTY4EL.ts +0 -91
  92. package/dist/chunks/chunk-ONDTY4EL.ts.map +0 -7
  93. package/dist/chunks/chunk-OVPHFGKO.ts +0 -1769
  94. package/dist/chunks/chunk-OVPHFGKO.ts.map +0 -7
  95. package/dist/chunks/chunk-P7OH4XMF.ts +0 -60
  96. package/dist/chunks/chunk-P7OH4XMF.ts.map +0 -7
  97. package/dist/chunks/chunk-PBZMBTNJ.ts +0 -422
  98. package/dist/chunks/chunk-PBZMBTNJ.ts.map +0 -7
  99. package/dist/chunks/chunk-PGLSFLYW.ts +0 -52
  100. package/dist/chunks/chunk-PGLSFLYW.ts.map +0 -7
  101. package/dist/chunks/chunk-RRR66UWR.ts +0 -28
  102. package/dist/chunks/chunk-RRR66UWR.ts.map +0 -7
  103. package/dist/chunks/chunk-RSUXZD6S.ts +0 -275
  104. package/dist/chunks/chunk-RSUXZD6S.ts.map +0 -7
  105. package/dist/chunks/chunk-RTCVYIZA.ts +0 -221
  106. package/dist/chunks/chunk-RTCVYIZA.ts.map +0 -7
  107. package/dist/chunks/chunk-RY2AEGMZ.ts +0 -34
  108. package/dist/chunks/chunk-RY2AEGMZ.ts.map +0 -7
  109. package/dist/chunks/chunk-SWGQLFSD.ts +0 -60
  110. package/dist/chunks/chunk-SWGQLFSD.ts.map +0 -7
  111. package/dist/chunks/chunk-TM2R67J3.ts +0 -52
  112. package/dist/chunks/chunk-TM2R67J3.ts.map +0 -7
  113. package/dist/chunks/chunk-TMZRHIIK.ts +0 -497
  114. package/dist/chunks/chunk-TMZRHIIK.ts.map +0 -7
  115. package/dist/chunks/chunk-TZ34IQ3M.ts +0 -59
  116. package/dist/chunks/chunk-TZ34IQ3M.ts.map +0 -7
  117. package/dist/chunks/chunk-UMBPMVJW.ts +0 -22
  118. package/dist/chunks/chunk-UMBPMVJW.ts.map +0 -7
  119. package/dist/chunks/chunk-VDG7LTYE.ts +0 -80
  120. package/dist/chunks/chunk-VDG7LTYE.ts.map +0 -7
  121. package/dist/chunks/chunk-X4NMONPE.ts +0 -73
  122. package/dist/chunks/chunk-X4NMONPE.ts.map +0 -7
  123. package/dist/chunks/chunk-YPJEN6NU.ts +0 -65
  124. package/dist/chunks/chunk-YPJEN6NU.ts.map +0 -7
  125. package/dist/chunks/chunk-YU53SHA7.ts +0 -328
  126. package/dist/chunks/chunk-YU53SHA7.ts.map +0 -7
  127. package/dist/chunks/completion-delivery-RSJU6BXL.ts +0 -17
  128. package/dist/chunks/completion-delivery-RSJU6BXL.ts.map +0 -7
  129. package/dist/chunks/config-status-FKGDECZ3.ts +0 -35
  130. package/dist/chunks/config-status-FKGDECZ3.ts.map +0 -7
  131. package/dist/chunks/config-ui-ABHYNGQ7.ts +0 -1212
  132. package/dist/chunks/config-ui-ABHYNGQ7.ts.map +0 -7
  133. package/dist/chunks/consult-LJU3IQY5.ts +0 -519
  134. package/dist/chunks/consult-LJU3IQY5.ts.map +0 -7
  135. package/dist/chunks/context-QDKLVQXE.ts +0 -11
  136. package/dist/chunks/context-QDKLVQXE.ts.map +0 -7
  137. package/dist/chunks/create-stateful-transport-JWC2EFYL.ts +0 -130
  138. package/dist/chunks/create-stateful-transport-JWC2EFYL.ts.map +0 -7
  139. package/dist/chunks/cwd-policy-NB6XZ5GF.ts +0 -17
  140. package/dist/chunks/cwd-policy-NB6XZ5GF.ts.map +0 -7
  141. package/dist/chunks/delegation-contract-LA56I5DT.ts +0 -24
  142. package/dist/chunks/delegation-contract-LA56I5DT.ts.map +0 -7
  143. package/dist/chunks/discovery-MIFB2U4Y.ts +0 -12
  144. package/dist/chunks/discovery-MIFB2U4Y.ts.map +0 -7
  145. package/dist/chunks/execution-Q2JZLKJA.ts +0 -4037
  146. package/dist/chunks/execution-Q2JZLKJA.ts.map +0 -7
  147. package/dist/chunks/in-process-transport-HJ6TZXC3.ts +0 -39
  148. package/dist/chunks/in-process-transport-HJ6TZXC3.ts.map +0 -7
  149. package/dist/chunks/inspect-UH2TKH6E.ts +0 -634
  150. package/dist/chunks/inspect-UH2TKH6E.ts.map +0 -7
  151. package/dist/chunks/peer-communication-KL36Z6CO.ts +0 -294
  152. package/dist/chunks/peer-communication-KL36Z6CO.ts.map +0 -7
  153. package/dist/chunks/persistence-UY3PY6E5.ts +0 -348
  154. package/dist/chunks/persistence-UY3PY6E5.ts.map +0 -7
  155. package/dist/chunks/registry-BT54L6CY.ts +0 -1445
  156. package/dist/chunks/registry-BT54L6CY.ts.map +0 -7
  157. package/dist/chunks/retained-semantic-state-GM75FZGE.ts +0 -81
  158. package/dist/chunks/retained-semantic-state-GM75FZGE.ts.map +0 -7
  159. package/dist/chunks/rpc-transport-7R7DVCEB.ts +0 -1222
  160. package/dist/chunks/rpc-transport-7R7DVCEB.ts.map +0 -7
  161. package/dist/chunks/runtime-policy-5YELCOVC.ts +0 -15
  162. package/dist/chunks/runtime-policy-5YELCOVC.ts.map +0 -7
  163. package/dist/chunks/semantic-snapshot-WPJ3UAFW.ts +0 -19
  164. package/dist/chunks/semantic-snapshot-WPJ3UAFW.ts.map +0 -7
  165. package/dist/chunks/spawn-idempotency-BNHOSMZW.ts +0 -13
  166. package/dist/chunks/spawn-idempotency-BNHOSMZW.ts.map +0 -7
  167. package/dist/chunks/stateful-lifecycle-JAR6K55H.ts +0 -15
  168. package/dist/chunks/stateful-lifecycle-JAR6K55H.ts.map +0 -7
  169. package/dist/chunks/subprocess-transport-VHZJRBTW.ts +0 -160
  170. package/dist/chunks/subprocess-transport-VHZJRBTW.ts.map +0 -7
  171. package/dist/chunks/usage-recording-store-CW3EH2SZ.ts +0 -164
  172. package/dist/chunks/usage-recording-store-CW3EH2SZ.ts.map +0 -7
  173. package/dist/chunks/workspace-WDKLN72J.ts +0 -11
  174. package/dist/chunks/workspace-WDKLN72J.ts.map +0 -7
  175. package/docs/async-runtime-protocol.md +0 -84
  176. package/docs/implementation-notes/pi-subagents-capability-matrix.md +0 -62
  177. package/docs/implementation-notes/pi-subagents-current-direction.md +0 -99
  178. package/docs/implementation-notes/pi-subagents-rpc-v1.md +0 -153
  179. package/docs/pi-subagents-diagrams.md +0 -183
  180. package/src/adaptive-scheduler.ts +0 -224
  181. package/src/admission-benchmark.ts +0 -95
  182. package/src/admission-policy.ts +0 -78
  183. package/src/agent-projection.ts +0 -53
  184. package/src/agents/built-ins.ts +0 -71
  185. package/src/agents/catalog.ts +0 -241
  186. package/src/agents/discovery.ts +0 -265
  187. package/src/agents/types.ts +0 -100
  188. package/src/agents.ts +0 -51
  189. package/src/async-subagent-benchmark.ts +0 -532
  190. package/src/auto-transport.ts +0 -121
  191. package/src/blocking-status.ts +0 -63
  192. package/src/cached-module-loader.ts +0 -18
  193. package/src/capabilities.ts +0 -145
  194. package/src/capability-grant.ts +0 -115
  195. package/src/capability-router.ts +0 -107
  196. package/src/child-peer-bridge.ts +0 -124
  197. package/src/child-peer-tools.ts +0 -132
  198. package/src/completion-delivery.ts +0 -409
  199. package/src/completion-render.ts +0 -190
  200. package/src/completion-requirement.ts +0 -479
  201. package/src/completion-routing.ts +0 -24
  202. package/src/config-registration.ts +0 -114
  203. package/src/config-status.ts +0 -217
  204. package/src/config-ui.ts +0 -983
  205. package/src/consult-policy.ts +0 -15
  206. package/src/consult-registration.ts +0 -125
  207. package/src/consult-render.ts +0 -194
  208. package/src/consult-resources.ts +0 -51
  209. package/src/consult-tool.ts +0 -95
  210. package/src/consult.ts +0 -566
  211. package/src/context.ts +0 -126
  212. package/src/create-stateful-transport.ts +0 -157
  213. package/src/cwd-policy.ts +0 -183
  214. package/src/delegation-contract.ts +0 -463
  215. package/src/execution/budget.ts +0 -56
  216. package/src/execution/runtime-policy.ts +0 -19
  217. package/src/execution-plan.ts +0 -322
  218. package/src/execution-ui.ts +0 -259
  219. package/src/execution.ts +0 -1679
  220. package/src/in-process-transport.ts +0 -941
  221. package/src/inspect-registration.ts +0 -64
  222. package/src/inspect-render.ts +0 -334
  223. package/src/inspect-tool.ts +0 -45
  224. package/src/inspect.ts +0 -769
  225. package/src/integration-controller.ts +0 -98
  226. package/src/limits.ts +0 -75
  227. package/src/orchestration-metrics.ts +0 -116
  228. package/src/outcome.ts +0 -61
  229. package/src/panel-child-group.ts +0 -35
  230. package/src/panel-contract.ts +0 -343
  231. package/src/panel-evidence.ts +0 -59
  232. package/src/panel-execution.ts +0 -769
  233. package/src/panel-failure.ts +0 -56
  234. package/src/panel-planning.ts +0 -175
  235. package/src/panel-presets.ts +0 -3
  236. package/src/panel-prompts.ts +0 -132
  237. package/src/panel-reconciliation.ts +0 -57
  238. package/src/panel-render.ts +0 -103
  239. package/src/parallel-limit-ui.ts +0 -113
  240. package/src/params.ts +0 -278
  241. package/src/peer-communication.ts +0 -352
  242. package/src/peer-transport.ts +0 -49
  243. package/src/persistence.ts +0 -522
  244. package/src/pi-args.ts +0 -43
  245. package/src/pi-invocation.ts +0 -168
  246. package/src/process-control.ts +0 -43
  247. package/src/prompt-resources.ts +0 -38
  248. package/src/prompt-source-safety.ts +0 -48
  249. package/src/protocol.ts +0 -76
  250. package/src/registry-types.ts +0 -204
  251. package/src/registry.ts +0 -1698
  252. package/src/render-common.ts +0 -252
  253. package/src/render.ts +0 -704
  254. package/src/result-contract.ts +0 -431
  255. package/src/retained-semantic-state.ts +0 -100
  256. package/src/rpc-timeout-finalization.ts +0 -207
  257. package/src/rpc-transport-metadata.ts +0 -65
  258. package/src/rpc-transport.ts +0 -1035
  259. package/src/rpc-turn-capture.ts +0 -217
  260. package/src/runner-outcome.ts +0 -31
  261. package/src/runner-result.ts +0 -55
  262. package/src/runner-types.ts +0 -102
  263. package/src/runner-usage.ts +0 -48
  264. package/src/runner.ts +0 -866
  265. package/src/safe-text.ts +0 -67
  266. package/src/semantic-snapshot.ts +0 -214
  267. package/src/session-guidance-contract.ts +0 -399
  268. package/src/settings/inspection.ts +0 -302
  269. package/src/settings/schema.ts +0 -195
  270. package/src/settings-reader.ts +0 -215
  271. package/src/settings.ts +0 -452
  272. package/src/spawn-idempotency.ts +0 -68
  273. package/src/stateful-agent-view.ts +0 -85
  274. package/src/stateful-config.ts +0 -13
  275. package/src/stateful-guidance.ts +0 -29
  276. package/src/stateful-lifecycle.ts +0 -74
  277. package/src/stateful-limit-ui.ts +0 -249
  278. package/src/stateful-limits.ts +0 -96
  279. package/src/stateful-prompt.ts +0 -49
  280. package/src/stateful-registration.ts +0 -1320
  281. package/src/stateful-render.ts +0 -318
  282. package/src/stateful-safety.ts +0 -47
  283. package/src/stateful-tool-params.ts +0 -215
  284. package/src/stateful.ts +0 -12
  285. package/src/subagent-details.ts +0 -43
  286. package/src/subagents-extension.ts +0 -355
  287. package/src/subprocess-transport.ts +0 -145
  288. package/src/supervision.ts +0 -104
  289. package/src/task-path.ts +0 -65
  290. package/src/timeout-checkpoint.ts +0 -305
  291. package/src/timeout-finalization.ts +0 -75
  292. package/src/tool-schema-compatibility.ts +0 -73
  293. package/src/transport-types.ts +0 -74
  294. package/src/transport-ui.ts +0 -135
  295. package/src/transport.ts +0 -43
  296. package/src/turn-budget.ts +0 -109
  297. package/src/usage-format.ts +0 -42
  298. package/src/usage-recording-config.ts +0 -13
  299. package/src/usage-recording-store.ts +0 -183
  300. package/src/usage-recording.ts +0 -478
  301. package/src/verification-harness.ts +0 -516
  302. package/src/verification-policy.ts +0 -67
  303. package/src/verification-receipt.ts +0 -275
  304. package/src/verified-execution-benchmark.ts +0 -86
  305. package/src/verified-execution-contract.ts +0 -191
  306. package/src/verified-execution-schema.ts +0 -32
  307. package/src/work-item-ledger.ts +0 -1404
  308. package/src/work-item-persistence.ts +0 -254
  309. package/src/workflow-completion-controller.ts +0 -397
  310. package/src/workflow-planning.ts +0 -172
  311. package/src/workflow-tree-identity.ts +0 -289
  312. package/src/workflow-ui.ts +0 -69
  313. package/src/workflow-verification.ts +0 -296
  314. package/src/workspace.ts +0 -174
package/src/render.ts DELETED
@@ -1,704 +0,0 @@
1
- import type { AgentToolResult } from "@earendil-works/pi-agent-core";
2
- import type { Message } from "@earendil-works/pi-ai";
3
- import {
4
- getMarkdownTheme,
5
- type Theme,
6
- type ThemeColor,
7
- type ToolRenderResultOptions,
8
- } from "@earendil-works/pi-coding-agent";
9
- import { Container, Markdown, Spacer, Text } from "@earendil-works/pi-tui";
10
- import type { AgentScope } from "./agents/types.js";
11
- import { renderPanelCall, renderPanelResult } from "./panel-render.js";
12
- import { hasUsableAggregator, type SubagentParams } from "./params.js";
13
- import { expansionHint, formatToolActivity, safeBlock, safeLine } from "./render-common.js";
14
- import { getResultFinalOutput, isResultError } from "./runner-outcome.js";
15
- import type { SingleResult } from "./runner-types.js";
16
- import type { SubagentDetails } from "./subagent-details.js";
17
- import { formatUsageStats } from "./usage-format.js";
18
-
19
- const COLLAPSED_ITEM_COUNT = 5;
20
-
21
- function previewTask(task: unknown, maxLength = 40): string {
22
- const safe = safeLine(task, "...", 2 * 1024);
23
- return safe.length > maxLength ? `${safe.slice(0, maxLength)}...` : safe;
24
- }
25
-
26
- function previewAgent(agent: unknown): string {
27
- return safeLine(agent, "...", 256);
28
- }
29
-
30
- function formatResultUsageStats(result: SingleResult): string {
31
- return formatUsageStats(
32
- result.usage,
33
- result.model,
34
- result.thinkingLevel,
35
- result.actualProvider,
36
- result.actualModel,
37
- );
38
- }
39
-
40
- function formatToolCall(
41
- toolName: string,
42
- args: Record<string, unknown>,
43
- themeFg: (color: ThemeColor, text: string) => string,
44
- ): string {
45
- return formatToolActivity(toolName, args, themeFg);
46
- }
47
-
48
- type DisplayItem =
49
- | { type: "text"; text: string }
50
- | { type: "toolCall"; name: string; args: Record<string, unknown> };
51
-
52
- function getDisplayItems(messages: Message[]): DisplayItem[] {
53
- const items: DisplayItem[] = [];
54
- for (const msg of messages) {
55
- if (msg.role === "assistant") {
56
- for (const part of msg.content) {
57
- if (part.type === "text") {
58
- const text = safeBlock(part.text, "", 8 * 1024).trim();
59
- if (text) items.push({ type: "text", text });
60
- } else if (part.type === "toolCall") {
61
- items.push({
62
- type: "toolCall",
63
- name: safeLine(part.name, "tool", 256),
64
- args: part.arguments,
65
- });
66
- }
67
- }
68
- }
69
- }
70
- return items;
71
- }
72
- function getCollapsedDisplayItems(result: SingleResult): { items: DisplayItem[]; total: number } {
73
- if (result.recentActivity && result.recentActivity.length > 0) {
74
- return {
75
- items: result.recentActivity,
76
- total: Math.max(result.recentActivity.length, result.recentActivityTotal ?? 0),
77
- };
78
- }
79
- const items = getDisplayItems(result.messages);
80
- return { items, total: items.length };
81
- }
82
-
83
- function sanitizeSingleResultForRender(result: SingleResult): SingleResult {
84
- return {
85
- ...result,
86
- agent: safeLine(result.agent, "subagent", 256),
87
- task: safeBlock(result.task, "", 50 * 1024),
88
- stderr: safeBlock(result.stderr, "", 8 * 1024),
89
- model: result.model ? safeLine(result.model, "", 256) : undefined,
90
- actualProvider: result.actualProvider ? safeLine(result.actualProvider, "", 256) : undefined,
91
- actualModel: result.actualModel ? safeLine(result.actualModel, "", 256) : undefined,
92
- stopReason: result.stopReason ? safeLine(result.stopReason, "", 256) : undefined,
93
- errorMessage: result.errorMessage ? safeBlock(result.errorMessage, "", 8 * 1024) : undefined,
94
- finalOutput: result.finalOutput ? safeBlock(result.finalOutput, "", 50 * 1024) : undefined,
95
- };
96
- }
97
-
98
- function renderResultStatus(result: SingleResult, isPartial: boolean): string {
99
- if (result.outcome && !["completed", "partial"].includes(result.outcome.status)) {
100
- return result.outcome.status
101
- .split("-")
102
- .map((part) => `${part.slice(0, 1).toUpperCase()}${part.slice(1)}`)
103
- .join(" ");
104
- }
105
- if (isResultError(result)) {
106
- return result.stopReason === "aborted" || result.aborted ? "Cancelled" : "Failed";
107
- }
108
- return isPartial || result.exitCode === -1 ? "Running" : "Completed";
109
- }
110
-
111
- function coloredStatus(theme: Theme, status: string): string {
112
- const color: ThemeColor =
113
- status === "Failed" ? "error" : status === "Completed" ? "success" : "warning";
114
- return theme.fg(color, status);
115
- }
116
-
117
- function coloredResultStatus(theme: Theme, result: SingleResult, isPartial: boolean): string {
118
- return coloredStatus(theme, renderResultStatus(result, isPartial));
119
- }
120
-
121
- function formatResultIntelligence(result: SingleResult): string {
122
- const structured =
123
- result.structuredResult?.version === "pi-subagents:result:v2"
124
- ? result.structuredResult
125
- : undefined;
126
- return [
127
- result.contract ? `contract: ${result.contract.level} · ${result.contract.taskId}` : undefined,
128
- result.outcome
129
- ? `outcome: ${result.outcome.status}${result.outcome.reasonCode ? ` · ${result.outcome.reasonCode}` : ""}`
130
- : undefined,
131
- structured
132
- ? `evidence: ${structured.claims.length} claims · ${structured.artifacts.length} artifacts · ${structured.verification.length} verification items · ${structured.limitations.length} limitations`
133
- : undefined,
134
- result.resultContractInvalid ? "contract warning: invalid structured result" : undefined,
135
- result.executionPlan
136
- ? `plan: ${result.executionPlan.id.slice(0, 12)} · generation ${result.executionPlan.taskGeneration} · admission ${result.executionPlan.admission.recommendation}`
137
- : undefined,
138
- result.capabilityGrant
139
- ? `grant: ${result.capabilityGrant.state} · expires ${result.capabilityGrant.expiresAt}`
140
- : undefined,
141
- ]
142
- .filter((line): line is string => Boolean(line))
143
- .join("\n");
144
- }
145
-
146
- function formatResultPolicy(result: SingleResult): string {
147
- if (!result.policy) return "";
148
- return [
149
- `inherited: ${result.policy.inherited.map((tool) => safeLine(tool, "", 256)).join(", ") || "none"}`,
150
- `overridden: ${result.policy.overridden.map((tool) => safeLine(tool, "", 256)).join(", ") || "none"}`,
151
- `unsupported: ${result.policy.unsupported.map((tool) => safeLine(tool, "", 256)).join(", ") || "none"}`,
152
- ].join("\n");
153
- }
154
-
155
- export function renderSubagentCall(args: SubagentParams, theme: Theme) {
156
- const scope: AgentScope = args.agentScope ?? "user";
157
- const limits = [
158
- typeof args.timeoutMs === "number" ? `timeout:${args.timeoutMs}ms` : undefined,
159
- typeof args.totalTimeoutMs === "number" ? `total:${args.totalTimeoutMs}ms` : undefined,
160
- typeof args.idleTimeoutMs === "number" ? `idle:${args.idleTimeoutMs}ms` : undefined,
161
- typeof args.maxTurns === "number" ? `turns:${args.maxTurns}` : undefined,
162
- typeof args.maxToolCalls === "number" ? `tools:${args.maxToolCalls}` : undefined,
163
- ].filter((value): value is string => Boolean(value));
164
- const limitText = limits.length > 0 ? ` · ${limits.join(" · ")}` : "";
165
- const panelCall = renderPanelCall(args, theme);
166
- if (panelCall) return panelCall;
167
- if (args.workflow && args.workflow.tasks.length > 0) {
168
- let text =
169
- theme.fg("toolTitle", theme.bold("subagent ")) +
170
- theme.fg("accent", `workflow (${args.workflow.tasks.length} tasks)`) +
171
- theme.fg("muted", ` [${scope}]${limitText}`);
172
- for (const task of args.workflow.tasks.slice(0, 3)) {
173
- text += `\n ${theme.fg("muted", `${task.id}:`)} ${theme.fg("accent", previewAgent(task.agent))}${theme.fg("dim", ` ${previewTask(task.task)}`)}`;
174
- }
175
- if (args.workflow.tasks.length > 3) {
176
- text += `\n ${theme.fg("muted", `... +${args.workflow.tasks.length - 3} more`)}`;
177
- }
178
- return new Text(text, 0, 0);
179
- }
180
- if (args.chain && args.chain.length > 0) {
181
- let text =
182
- theme.fg("toolTitle", theme.bold("subagent ")) +
183
- theme.fg("accent", `chain (${args.chain.length} steps)`) +
184
- theme.fg("muted", ` [${scope}]${limitText}`);
185
- for (let i = 0; i < Math.min(args.chain.length, 3); i++) {
186
- const step = args.chain[i] as { agent?: unknown; task?: unknown } | undefined;
187
- // Clean up {previous} placeholder for display
188
- const cleanTask =
189
- typeof step?.task === "string" ? step.task.replace(/\{previous\}/g, "").trim() : undefined;
190
- text +=
191
- "\n " +
192
- theme.fg("muted", `${i + 1}.`) +
193
- " " +
194
- theme.fg("accent", previewAgent(step?.agent)) +
195
- theme.fg("dim", ` ${previewTask(cleanTask)}`);
196
- }
197
- if (args.chain.length > 3)
198
- text += `\n ${theme.fg("muted", `... +${args.chain.length - 3} more`)}`;
199
- return new Text(text, 0, 0);
200
- }
201
- if (args.tasks && args.tasks.length > 0) {
202
- let text =
203
- theme.fg("toolTitle", theme.bold("subagent ")) +
204
- theme.fg("accent", `parallel (${args.tasks.length} tasks)`) +
205
- theme.fg("muted", ` [${scope}]${limitText}`);
206
- for (const task of args.tasks.slice(0, 3)) {
207
- const item = task as { agent?: unknown; task?: unknown } | undefined;
208
- text += `\n ${theme.fg("accent", previewAgent(item?.agent))}${theme.fg("dim", ` ${previewTask(item?.task)}`)}`;
209
- }
210
- if (args.tasks.length > 3)
211
- text += `\n ${theme.fg("muted", `... +${args.tasks.length - 3} more`)}`;
212
- if (hasUsableAggregator(args.aggregator)) {
213
- const aggregator = args.aggregator;
214
- text += `\n ${theme.fg("muted", "fan-in → ")}${theme.fg("accent", previewAgent(aggregator.agent))}${theme.fg(
215
- "dim",
216
- ` ${previewTask(aggregator.task)}`,
217
- )}`;
218
- }
219
- return new Text(text, 0, 0);
220
- }
221
- const agentName = previewAgent(args.agent);
222
- const preview = previewTask(args.task, 60);
223
- let text =
224
- theme.fg("toolTitle", theme.bold("subagent ")) +
225
- theme.fg("accent", agentName) +
226
- theme.fg("muted", ` [${scope}]${limitText}`);
227
- text += `\n ${theme.fg("dim", preview)}`;
228
- return new Text(text, 0, 0);
229
- }
230
-
231
- export function renderSubagentResult(
232
- result: AgentToolResult<SubagentDetails>,
233
- { expanded, isPartial }: ToolRenderResultOptions,
234
- theme: Theme,
235
- ) {
236
- const rawDetails = result.details as SubagentDetails | undefined;
237
- if (rawDetails?.mode === "panel") {
238
- const panelResult = renderPanelResult(rawDetails, expanded, isPartial, theme);
239
- if (panelResult) return panelResult;
240
- }
241
- if (!rawDetails || rawDetails.results.length === 0) {
242
- const text = result.content[0];
243
- return new Text(
244
- text?.type === "text" ? safeBlock(text.text, "(no output)", 8 * 1024) : "(no output)",
245
- 0,
246
- 0,
247
- );
248
- }
249
- const details: SubagentDetails = {
250
- ...rawDetails,
251
- results: rawDetails.results.map(sanitizeSingleResultForRender),
252
- aggregator: rawDetails.aggregator
253
- ? sanitizeSingleResultForRender(rawDetails.aggregator)
254
- : undefined,
255
- };
256
-
257
- const mdTheme = getMarkdownTheme();
258
-
259
- const renderDisplayItems = (items: DisplayItem[], limit?: number, total = items.length) => {
260
- const toShow = limit ? items.slice(-limit) : items;
261
- const skipped = Math.max(0, total - toShow.length);
262
- let text = "";
263
- if (skipped > 0) text += theme.fg("muted", `... ${skipped} earlier items\n`);
264
- for (const item of toShow) {
265
- if (item.type === "text") {
266
- const safeText = safeBlock(item.text, "", 8 * 1024);
267
- const preview = expanded ? safeText : safeText.split("\n").slice(0, 3).join("\n");
268
- text += `${theme.fg("toolOutput", preview)}\n`;
269
- } else {
270
- text += `${theme.fg("muted", "→ ") + formatToolCall(item.name, item.args, theme.fg.bind(theme))}\n`;
271
- }
272
- }
273
- return text.trimEnd();
274
- };
275
-
276
- if (details.mode === "single" && details.results.length === 1) {
277
- const r = details.results[0];
278
- const isError = isResultError(r);
279
- const icon = isError
280
- ? theme.fg("error", "✗")
281
- : isPartial
282
- ? theme.fg("warning", "⏳")
283
- : theme.fg("success", "✓");
284
- const displayItems = getDisplayItems(r.messages);
285
- const finalOutput = getResultFinalOutput(r);
286
-
287
- if (expanded) {
288
- const container = new Container();
289
- let header = `${icon} ${theme.fg("toolTitle", theme.bold(r.agent))}${theme.fg("muted", ` (${safeLine(r.agentSource, "unknown", 128)})`)} · ${coloredResultStatus(theme, r, isPartial)}`;
290
- if (isError && r.stopReason) header += ` ${theme.fg("error", `[${r.stopReason}]`)}`;
291
- container.addChild(new Text(header, 0, 0));
292
- if (isError && r.errorMessage)
293
- container.addChild(new Text(theme.fg("error", `Error: ${r.errorMessage}`), 0, 0));
294
- container.addChild(new Spacer(1));
295
- container.addChild(new Text(theme.fg("muted", "─── Task ───"), 0, 0));
296
- container.addChild(new Text(theme.fg("dim", r.task), 0, 0));
297
- const intelligence = formatResultIntelligence(r);
298
- if (intelligence) {
299
- container.addChild(new Spacer(1));
300
- container.addChild(new Text(theme.fg("muted", "─── Delegation ───"), 0, 0));
301
- container.addChild(new Text(theme.fg("dim", intelligence), 0, 0));
302
- }
303
- const policy = formatResultPolicy(r);
304
- if (policy) {
305
- container.addChild(new Spacer(1));
306
- container.addChild(new Text(theme.fg("muted", "─── Policy ───"), 0, 0));
307
- container.addChild(new Text(theme.fg("dim", policy), 0, 0));
308
- }
309
- container.addChild(new Spacer(1));
310
- container.addChild(new Text(theme.fg("muted", "─── Output ───"), 0, 0));
311
- if (displayItems.length === 0 && !finalOutput) {
312
- container.addChild(new Text(theme.fg("muted", "(no output)"), 0, 0));
313
- } else {
314
- for (const item of displayItems) {
315
- if (item.type === "toolCall")
316
- container.addChild(
317
- new Text(
318
- theme.fg("muted", "→ ") +
319
- formatToolCall(item.name, item.args, theme.fg.bind(theme)),
320
- 0,
321
- 0,
322
- ),
323
- );
324
- }
325
- if (finalOutput) {
326
- container.addChild(new Spacer(1));
327
- container.addChild(new Markdown(finalOutput.trim(), 0, 0, mdTheme));
328
- }
329
- }
330
- const usageStr = formatResultUsageStats(r);
331
- if (usageStr) {
332
- container.addChild(new Spacer(1));
333
- container.addChild(new Text(theme.fg("dim", usageStr), 0, 0));
334
- }
335
- return container;
336
- }
337
-
338
- const collapsed = getCollapsedDisplayItems(r);
339
- let text = `${icon} ${theme.fg("toolTitle", theme.bold(r.agent))}${theme.fg("muted", ` (${safeLine(r.agentSource, "unknown", 128)})`)} · ${coloredResultStatus(theme, r, isPartial)}`;
340
- if (isError && r.stopReason) text += ` ${theme.fg("error", `[${r.stopReason}]`)}`;
341
- if (isError && r.errorMessage) text += `\n${theme.fg("error", `Error: ${r.errorMessage}`)}`;
342
- if (collapsed.items.length > 0) {
343
- text += `\n${renderDisplayItems(collapsed.items, COLLAPSED_ITEM_COUNT, collapsed.total)}`;
344
- if (collapsed.total > COLLAPSED_ITEM_COUNT) text += `\n${expansionHint()}`;
345
- } else if (finalOutput.trim()) {
346
- const outputLines = finalOutput.trim().split("\n");
347
- text += `\n${theme.fg("toolOutput", outputLines.slice(0, 3).join("\n"))}`;
348
- if (outputLines.length > 3) text += `\n${expansionHint()}`;
349
- } else if (!isError || !r.errorMessage) {
350
- text += `\n${theme.fg("muted", isPartial && !isError ? "(running...)" : "(no output)")}`;
351
- }
352
- const usageStr = formatResultUsageStats(r);
353
- if (usageStr) text += `\n${theme.fg("dim", usageStr)}`;
354
- return new Text(text, 0, 0);
355
- }
356
-
357
- const aggregateUsage = (results: SingleResult[]) => {
358
- const total = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, turns: 0 };
359
- for (const r of results) {
360
- total.input += r.usage.input;
361
- total.output += r.usage.output;
362
- total.cacheRead += r.usage.cacheRead;
363
- total.cacheWrite += r.usage.cacheWrite;
364
- total.cost += r.usage.cost;
365
- total.turns += r.usage.turns;
366
- }
367
- return total;
368
- };
369
-
370
- if (details.mode === "chain") {
371
- const currentResult = details.results.at(-1);
372
- const currentIsRunning =
373
- isPartial && currentResult !== undefined && !isResultError(currentResult);
374
- const successCount = details.results.filter(
375
- (result) => !isResultError(result) && (!currentIsRunning || result !== currentResult),
376
- ).length;
377
- const icon = currentIsRunning
378
- ? theme.fg("warning", "⏳")
379
- : successCount === details.results.length
380
- ? theme.fg("success", "✓")
381
- : theme.fg("error", "✗");
382
- const overallStatus = currentIsRunning
383
- ? "Running"
384
- : successCount === details.results.length
385
- ? "Completed"
386
- : "Failed";
387
-
388
- if (expanded) {
389
- const container = new Container();
390
- container.addChild(
391
- new Text(
392
- icon +
393
- " " +
394
- theme.fg("toolTitle", theme.bold("chain ")) +
395
- theme.fg("accent", `${successCount}/${details.results.length} steps`) +
396
- ` · ${coloredStatus(theme, overallStatus)}`,
397
- 0,
398
- 0,
399
- ),
400
- );
401
-
402
- for (const r of details.results) {
403
- const rFailed = isResultError(r);
404
- const rIcon = rFailed
405
- ? theme.fg("error", "✗")
406
- : currentIsRunning && r === currentResult
407
- ? theme.fg("warning", "⏳")
408
- : theme.fg("success", "✓");
409
- const displayItems = getDisplayItems(r.messages);
410
- const finalOutput = getResultFinalOutput(r);
411
-
412
- container.addChild(new Spacer(1));
413
- container.addChild(
414
- new Text(
415
- `${theme.fg("muted", `─── Step ${r.step}: `) + theme.fg("accent", r.agent)} ${rIcon} ${coloredResultStatus(theme, r, currentIsRunning && r === currentResult)}`,
416
- 0,
417
- 0,
418
- ),
419
- );
420
- container.addChild(new Text(theme.fg("muted", "Task: ") + theme.fg("dim", r.task), 0, 0));
421
- const policy = formatResultPolicy(r);
422
- if (policy)
423
- container.addChild(
424
- new Text(theme.fg("muted", "Policy:\n") + theme.fg("dim", policy), 0, 0),
425
- );
426
- if (rFailed && r.errorMessage)
427
- container.addChild(new Text(theme.fg("error", `Error: ${r.errorMessage}`), 0, 0));
428
-
429
- // Show tool calls
430
- for (const item of displayItems) {
431
- if (item.type === "toolCall") {
432
- container.addChild(
433
- new Text(
434
- theme.fg("muted", "→ ") +
435
- formatToolCall(item.name, item.args, theme.fg.bind(theme)),
436
- 0,
437
- 0,
438
- ),
439
- );
440
- }
441
- }
442
-
443
- // Show final output as markdown
444
- if (finalOutput) {
445
- container.addChild(new Spacer(1));
446
- container.addChild(new Markdown(finalOutput.trim(), 0, 0, mdTheme));
447
- }
448
-
449
- const stepUsage = formatResultUsageStats(r);
450
- if (stepUsage) container.addChild(new Text(theme.fg("dim", stepUsage), 0, 0));
451
- }
452
-
453
- const usageStr = formatUsageStats(aggregateUsage(details.results));
454
- if (usageStr) {
455
- container.addChild(new Spacer(1));
456
- container.addChild(new Text(theme.fg("dim", `Total: ${usageStr}`), 0, 0));
457
- }
458
- return container;
459
- }
460
-
461
- // Collapsed view
462
- let text =
463
- icon +
464
- " " +
465
- theme.fg("toolTitle", theme.bold("chain ")) +
466
- theme.fg("accent", `${successCount}/${details.results.length} steps`) +
467
- ` · ${coloredStatus(theme, overallStatus)}`;
468
- for (const r of details.results) {
469
- const rFailed = isResultError(r);
470
- const rIcon = rFailed
471
- ? theme.fg("error", "✗")
472
- : currentIsRunning && r === currentResult
473
- ? theme.fg("warning", "⏳")
474
- : theme.fg("success", "✓");
475
- const collapsed = getCollapsedDisplayItems(r);
476
- const finalOutput = getResultFinalOutput(r).trim();
477
- text += `\n\n${theme.fg("muted", `─── Step ${r.step}: `)}${theme.fg("accent", r.agent)} ${rIcon} ${coloredResultStatus(theme, r, currentIsRunning && r === currentResult)}`;
478
- if (rFailed && r.errorMessage) text += `\n${theme.fg("error", `Error: ${r.errorMessage}`)}`;
479
- if (collapsed.items.length > 0)
480
- text += `\n${renderDisplayItems(collapsed.items, 5, collapsed.total)}`;
481
- else if (currentIsRunning && r === currentResult)
482
- text += `\n${theme.fg("muted", "(running...)")}`;
483
- else if (finalOutput)
484
- text += `\n${theme.fg("toolOutput", finalOutput.split("\n").slice(0, 3).join("\n"))}`;
485
- else if (!rFailed || !r.errorMessage) text += `\n${theme.fg("muted", "(no output)")}`;
486
- }
487
- const usageStr = formatUsageStats(aggregateUsage(details.results));
488
- if (usageStr) text += `\n\n${theme.fg("dim", `Total: ${usageStr}`)}`;
489
- text += `\n${expansionHint()}`;
490
- return new Text(text, 0, 0);
491
- }
492
-
493
- if (details.mode === "parallel" || details.mode === "workflow") {
494
- const modeLabel = details.mode === "workflow" ? "workflow" : "parallel";
495
- const resultIsRunning = (result: SingleResult) =>
496
- result.exitCode === -1 && !isResultError(result);
497
- const running = details.results.filter(resultIsRunning).length;
498
- const successCount = details.results.filter(
499
- (result) => result.exitCode !== -1 && !isResultError(result),
500
- ).length;
501
- const failCount = details.results.filter(isResultError).length;
502
- const aggregator = details.aggregator;
503
- const aggregatorFailed = aggregator ? isResultError(aggregator) : false;
504
- const aggregatorRunning = aggregator
505
- ? !aggregatorFailed && (isPartial || aggregator.exitCode === -1)
506
- : false;
507
- const pendingSuccessfulSettlement =
508
- isPartial && !aggregator && running === 0 && failCount === 0;
509
- const isRunning = running > 0 || aggregatorRunning || pendingSuccessfulSettlement;
510
- const icon = isRunning
511
- ? theme.fg("warning", "⏳")
512
- : failCount > 0 || aggregatorFailed
513
- ? theme.fg("warning", "◐")
514
- : theme.fg("success", "✓");
515
- const status = isRunning
516
- ? aggregatorRunning
517
- ? `${successCount + failCount}/${details.results.length} done, fan-in running`
518
- : running > 0
519
- ? `${successCount + failCount}/${details.results.length} done, ${running} running`
520
- : `${successCount + failCount}/${details.results.length} done, running`
521
- : aggregator
522
- ? `${successCount}/${details.results.length} tasks + fan-in`
523
- : `${successCount}/${details.results.length} tasks`;
524
- const overallStatus = isRunning
525
- ? "Running"
526
- : failCount > 0 || aggregatorFailed
527
- ? "Failed"
528
- : "Completed";
529
-
530
- if (expanded && !isRunning) {
531
- const container = new Container();
532
- container.addChild(
533
- new Text(
534
- `${icon} ${theme.fg("toolTitle", theme.bold(`${modeLabel} `))}${theme.fg("accent", status)} · ${coloredStatus(theme, overallStatus)}`,
535
- 0,
536
- 0,
537
- ),
538
- );
539
-
540
- for (const r of details.results) {
541
- const rFailed = isResultError(r);
542
- const rIcon = rFailed
543
- ? theme.fg("error", "✗")
544
- : resultIsRunning(r)
545
- ? theme.fg("warning", "⏳")
546
- : theme.fg("success", "✓");
547
- const displayItems = getDisplayItems(r.messages);
548
- const finalOutput = getResultFinalOutput(r);
549
-
550
- container.addChild(new Spacer(1));
551
- container.addChild(
552
- new Text(
553
- `${theme.fg("muted", "─── ") + theme.fg("accent", r.agent)} ${rIcon} ${coloredResultStatus(theme, r, resultIsRunning(r))}`,
554
- 0,
555
- 0,
556
- ),
557
- );
558
- container.addChild(new Text(theme.fg("muted", "Task: ") + theme.fg("dim", r.task), 0, 0));
559
- const policy = formatResultPolicy(r);
560
- if (policy)
561
- container.addChild(
562
- new Text(theme.fg("muted", "Policy:\n") + theme.fg("dim", policy), 0, 0),
563
- );
564
- if (rFailed && r.errorMessage)
565
- container.addChild(new Text(theme.fg("error", `Error: ${r.errorMessage}`), 0, 0));
566
-
567
- // Show tool calls
568
- for (const item of displayItems) {
569
- if (item.type === "toolCall") {
570
- container.addChild(
571
- new Text(
572
- theme.fg("muted", "→ ") +
573
- formatToolCall(item.name, item.args, theme.fg.bind(theme)),
574
- 0,
575
- 0,
576
- ),
577
- );
578
- }
579
- }
580
-
581
- // Show final output as markdown
582
- if (finalOutput) {
583
- container.addChild(new Spacer(1));
584
- container.addChild(new Markdown(finalOutput.trim(), 0, 0, mdTheme));
585
- }
586
-
587
- const taskUsage = formatResultUsageStats(r);
588
- if (taskUsage) container.addChild(new Text(theme.fg("dim", taskUsage), 0, 0));
589
- }
590
-
591
- if (aggregator) {
592
- const rIcon = aggregatorFailed
593
- ? theme.fg("error", "✗")
594
- : aggregatorRunning
595
- ? theme.fg("warning", "⏳")
596
- : theme.fg("success", "✓");
597
- const displayItems = getDisplayItems(aggregator.messages);
598
- const finalOutput = getResultFinalOutput(aggregator);
599
-
600
- container.addChild(new Spacer(1));
601
- container.addChild(
602
- new Text(
603
- `${theme.fg("muted", "─── fan-in → ") + theme.fg("accent", aggregator.agent)} ${rIcon} ${coloredResultStatus(theme, aggregator, aggregatorRunning)}`,
604
- 0,
605
- 0,
606
- ),
607
- );
608
- container.addChild(
609
- new Text(theme.fg("muted", "Task: ") + theme.fg("dim", aggregator.task), 0, 0),
610
- );
611
- const aggregatorPolicy = formatResultPolicy(aggregator);
612
- if (aggregatorPolicy)
613
- container.addChild(
614
- new Text(theme.fg("muted", "Policy:\n") + theme.fg("dim", aggregatorPolicy), 0, 0),
615
- );
616
- if (aggregatorFailed && aggregator.errorMessage)
617
- container.addChild(
618
- new Text(theme.fg("error", `Error: ${aggregator.errorMessage}`), 0, 0),
619
- );
620
- for (const item of displayItems) {
621
- if (item.type === "toolCall") {
622
- container.addChild(
623
- new Text(
624
- theme.fg("muted", "→ ") +
625
- formatToolCall(item.name, item.args, theme.fg.bind(theme)),
626
- 0,
627
- 0,
628
- ),
629
- );
630
- }
631
- }
632
- if (finalOutput) {
633
- container.addChild(new Spacer(1));
634
- container.addChild(new Markdown(finalOutput.trim(), 0, 0, mdTheme));
635
- }
636
- const fanInUsage = formatResultUsageStats(aggregator);
637
- if (fanInUsage) container.addChild(new Text(theme.fg("dim", fanInUsage), 0, 0));
638
- }
639
-
640
- const usageResults = aggregator ? [...details.results, aggregator] : details.results;
641
- const usageStr = formatUsageStats(aggregateUsage(usageResults));
642
- if (usageStr) {
643
- container.addChild(new Spacer(1));
644
- container.addChild(new Text(theme.fg("dim", `Total: ${usageStr}`), 0, 0));
645
- }
646
- return container;
647
- }
648
-
649
- // Collapsed view (or still running)
650
- let text = `${icon} ${theme.fg("toolTitle", theme.bold(`${modeLabel} `))}${theme.fg("accent", status)} · ${coloredStatus(theme, overallStatus)}`;
651
- for (const r of details.results) {
652
- const rFailed = isResultError(r);
653
- const rRunning = resultIsRunning(r);
654
- const rIcon = rFailed
655
- ? theme.fg("error", "✗")
656
- : rRunning
657
- ? theme.fg("warning", "⏳")
658
- : theme.fg("success", "✓");
659
- const collapsed = getCollapsedDisplayItems(r);
660
- const finalOutput = getResultFinalOutput(r).trim();
661
- text += `\n\n${theme.fg("muted", "─── ")}${theme.fg("accent", r.agent)} ${rIcon} ${coloredResultStatus(theme, r, rRunning)}`;
662
- if (rFailed && r.errorMessage) text += `\n${theme.fg("error", `Error: ${r.errorMessage}`)}`;
663
- if (collapsed.items.length > 0)
664
- text += `\n${renderDisplayItems(collapsed.items, 5, collapsed.total)}`;
665
- else if (rRunning) text += `\n${theme.fg("muted", "(running...)")}`;
666
- else if (finalOutput)
667
- text += `\n${theme.fg("toolOutput", finalOutput.split("\n").slice(0, 3).join("\n"))}`;
668
- else if (!rFailed || !r.errorMessage) text += `\n${theme.fg("muted", "(no output)")}`;
669
- }
670
- if (aggregator) {
671
- const rIcon = aggregatorFailed
672
- ? theme.fg("error", "✗")
673
- : aggregatorRunning
674
- ? theme.fg("warning", "⏳")
675
- : theme.fg("success", "✓");
676
- const collapsed = getCollapsedDisplayItems(aggregator);
677
- const finalOutput = getResultFinalOutput(aggregator).trim();
678
- text += `\n\n${theme.fg("muted", "─── fan-in → ")}${theme.fg("accent", aggregator.agent)} ${rIcon} ${coloredResultStatus(theme, aggregator, aggregatorRunning)}`;
679
- if (aggregatorFailed && aggregator.errorMessage)
680
- text += `\n${theme.fg("error", `Error: ${aggregator.errorMessage}`)}`;
681
- if (collapsed.items.length > 0)
682
- text += `\n${renderDisplayItems(collapsed.items, 5, collapsed.total)}`;
683
- else if (aggregatorRunning) text += `\n${theme.fg("muted", "(running...)")}`;
684
- else if (finalOutput)
685
- text += `\n${theme.fg("toolOutput", finalOutput.split("\n").slice(0, 3).join("\n"))}`;
686
- else if (!aggregatorFailed || !aggregator.errorMessage)
687
- text += `\n${theme.fg("muted", "(no output)")}`;
688
- }
689
- if (!isRunning) {
690
- const usageResults = aggregator ? [...details.results, aggregator] : details.results;
691
- const usageStr = formatUsageStats(aggregateUsage(usageResults));
692
- if (usageStr) text += `\n\n${theme.fg("dim", `Total: ${usageStr}`)}`;
693
- }
694
- if (!expanded) text += `\n${expansionHint()}`;
695
- return new Text(text, 0, 0);
696
- }
697
-
698
- const text = result.content[0];
699
- return new Text(
700
- text?.type === "text" ? safeBlock(text.text, "(no output)", 8 * 1024) : "(no output)",
701
- 0,
702
- 0,
703
- );
704
- }