@narumitw/pi-subagents 2.1.4 → 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 (312) hide show
  1. package/README.md +187 -1228
  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 -1614
  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 -139
  179. package/docs/pi-subagents-diagrams.md +0 -183
  180. package/src/adaptive-scheduler.ts +0 -224
  181. package/src/admission-policy.ts +0 -78
  182. package/src/agent-projection.ts +0 -53
  183. package/src/agents/built-ins.ts +0 -71
  184. package/src/agents/catalog.ts +0 -241
  185. package/src/agents/discovery.ts +0 -265
  186. package/src/agents/types.ts +0 -100
  187. package/src/agents.ts +0 -51
  188. package/src/auto-transport.ts +0 -121
  189. package/src/blocking-status.ts +0 -63
  190. package/src/cached-module-loader.ts +0 -18
  191. package/src/capabilities.ts +0 -145
  192. package/src/capability-grant.ts +0 -115
  193. package/src/capability-router.ts +0 -107
  194. package/src/child-peer-bridge.ts +0 -124
  195. package/src/child-peer-tools.ts +0 -132
  196. package/src/completion-delivery.ts +0 -409
  197. package/src/completion-render.ts +0 -190
  198. package/src/completion-requirement.ts +0 -479
  199. package/src/completion-routing.ts +0 -24
  200. package/src/config-registration.ts +0 -114
  201. package/src/config-status.ts +0 -217
  202. package/src/config-ui.ts +0 -983
  203. package/src/consult-policy.ts +0 -15
  204. package/src/consult-registration.ts +0 -125
  205. package/src/consult-render.ts +0 -194
  206. package/src/consult-resources.ts +0 -51
  207. package/src/consult-tool.ts +0 -95
  208. package/src/consult.ts +0 -566
  209. package/src/context.ts +0 -126
  210. package/src/create-stateful-transport.ts +0 -157
  211. package/src/cwd-policy.ts +0 -183
  212. package/src/delegation-contract.ts +0 -463
  213. package/src/execution/budget.ts +0 -56
  214. package/src/execution/runtime-policy.ts +0 -19
  215. package/src/execution-plan.ts +0 -322
  216. package/src/execution-ui.ts +0 -259
  217. package/src/execution.ts +0 -1679
  218. package/src/in-process-transport.ts +0 -941
  219. package/src/inspect-registration.ts +0 -64
  220. package/src/inspect-render.ts +0 -334
  221. package/src/inspect-tool.ts +0 -45
  222. package/src/inspect.ts +0 -769
  223. package/src/integration-controller.ts +0 -98
  224. package/src/limits.ts +0 -75
  225. package/src/orchestration-metrics.ts +0 -116
  226. package/src/outcome.ts +0 -61
  227. package/src/panel-child-group.ts +0 -35
  228. package/src/panel-contract.ts +0 -343
  229. package/src/panel-evidence.ts +0 -59
  230. package/src/panel-execution.ts +0 -769
  231. package/src/panel-failure.ts +0 -56
  232. package/src/panel-planning.ts +0 -175
  233. package/src/panel-presets.ts +0 -3
  234. package/src/panel-prompts.ts +0 -132
  235. package/src/panel-reconciliation.ts +0 -57
  236. package/src/panel-render.ts +0 -103
  237. package/src/parallel-limit-ui.ts +0 -113
  238. package/src/params.ts +0 -278
  239. package/src/peer-communication.ts +0 -352
  240. package/src/peer-transport.ts +0 -49
  241. package/src/persistence.ts +0 -522
  242. package/src/pi-args.ts +0 -43
  243. package/src/pi-invocation.ts +0 -168
  244. package/src/process-control.ts +0 -43
  245. package/src/prompt-resources.ts +0 -38
  246. package/src/prompt-source-safety.ts +0 -48
  247. package/src/protocol.ts +0 -76
  248. package/src/registry-types.ts +0 -204
  249. package/src/registry.ts +0 -1698
  250. package/src/render-common.ts +0 -252
  251. package/src/render.ts +0 -704
  252. package/src/result-contract.ts +0 -431
  253. package/src/retained-semantic-state.ts +0 -100
  254. package/src/rpc-timeout-finalization.ts +0 -207
  255. package/src/rpc-transport-metadata.ts +0 -65
  256. package/src/rpc-transport.ts +0 -1035
  257. package/src/rpc-turn-capture.ts +0 -217
  258. package/src/runner-outcome.ts +0 -31
  259. package/src/runner-result.ts +0 -55
  260. package/src/runner-types.ts +0 -102
  261. package/src/runner-usage.ts +0 -48
  262. package/src/runner.ts +0 -866
  263. package/src/safe-text.ts +0 -67
  264. package/src/semantic-snapshot.ts +0 -214
  265. package/src/session-guidance-contract.ts +0 -399
  266. package/src/settings/inspection.ts +0 -302
  267. package/src/settings/schema.ts +0 -195
  268. package/src/settings-reader.ts +0 -215
  269. package/src/settings.ts +0 -452
  270. package/src/spawn-idempotency.ts +0 -68
  271. package/src/stateful-agent-view.ts +0 -85
  272. package/src/stateful-config.ts +0 -13
  273. package/src/stateful-guidance.ts +0 -29
  274. package/src/stateful-lifecycle.ts +0 -74
  275. package/src/stateful-limit-ui.ts +0 -249
  276. package/src/stateful-limits.ts +0 -96
  277. package/src/stateful-prompt.ts +0 -49
  278. package/src/stateful-registration.ts +0 -1320
  279. package/src/stateful-render.ts +0 -318
  280. package/src/stateful-safety.ts +0 -47
  281. package/src/stateful-tool-params.ts +0 -215
  282. package/src/stateful.ts +0 -12
  283. package/src/subagent-details.ts +0 -43
  284. package/src/subagents-extension.ts +0 -372
  285. package/src/subprocess-transport.ts +0 -145
  286. package/src/supervision.ts +0 -104
  287. package/src/task-path.ts +0 -65
  288. package/src/timeout-checkpoint.ts +0 -305
  289. package/src/timeout-finalization.ts +0 -75
  290. package/src/tool-schema-compatibility.ts +0 -73
  291. package/src/transport-types.ts +0 -74
  292. package/src/transport-ui.ts +0 -135
  293. package/src/transport.ts +0 -43
  294. package/src/turn-budget.ts +0 -109
  295. package/src/usage-format.ts +0 -42
  296. package/src/usage-recording-config.ts +0 -13
  297. package/src/usage-recording-store.ts +0 -183
  298. package/src/usage-recording.ts +0 -478
  299. package/src/verification-harness.ts +0 -516
  300. package/src/verification-policy.ts +0 -67
  301. package/src/verification-receipt.ts +0 -275
  302. package/src/verified-execution-benchmark.ts +0 -86
  303. package/src/verified-execution-contract.ts +0 -191
  304. package/src/verified-execution-schema.ts +0 -32
  305. package/src/work-item-ledger.ts +0 -1404
  306. package/src/work-item-persistence.ts +0 -254
  307. package/src/workflow-completion-controller.ts +0 -397
  308. package/src/workflow-planning.ts +0 -172
  309. package/src/workflow-tree-identity.ts +0 -289
  310. package/src/workflow-ui.ts +0 -69
  311. package/src/workflow-verification.ts +0 -296
  312. package/src/workspace.ts +0 -174
@@ -1,769 +0,0 @@
1
- import type { AgentToolResult, AgentToolUpdateCallback } from "@earendil-works/pi-agent-core";
2
- import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
3
- import type { AgentConfig, AgentScope, SubagentThinkingLevel } from "./agents/types.js";
4
- import { panelReviewStatus, panelSynthesisStatus, startSubagentStatus } from "./blocking-status.js";
5
- import { issueCapabilityGrant, revokeCapabilityGrant } from "./capability-grant.js";
6
- import type { ResolvedSubagentTarget } from "./cwd-policy.js";
7
- import { targetPolicyAudit } from "./cwd-policy.js";
8
- import type { DelegationContract } from "./delegation-contract.js";
9
- import {
10
- acknowledgeExecutionPlan,
11
- createExecutionPlan,
12
- resolveContractTools,
13
- } from "./execution-plan.js";
14
- import {
15
- DEFAULT_MAX_OUTPUT_BYTES,
16
- MAX_BLOCKING_PARALLEL_CONCURRENCY,
17
- truncateUtf8,
18
- } from "./limits.js";
19
- import { calculateOrchestrationMetrics } from "./orchestration-metrics.js";
20
- import { PanelChildGroup } from "./panel-child-group.js";
21
- import { type PanelReview, parsePanelReview, parsePanelSynthesis } from "./panel-contract.js";
22
- import { PanelEvidenceLedger } from "./panel-evidence.js";
23
- import { classifyPanelFailure, type PanelFailure } from "./panel-failure.js";
24
- import {
25
- createPanelWorkLedger,
26
- type PanelPreset,
27
- planPanelBudgets,
28
- validatePanelRequest,
29
- } from "./panel-planning.js";
30
- import { buildPanelReviewerPrompt, buildPanelSynthesisPrompt } from "./panel-prompts.js";
31
- import { reconcilePanel } from "./panel-reconciliation.js";
32
- import type { SubagentParams } from "./params.js";
33
- import {
34
- getResultFinalOutput,
35
- isResultError,
36
- mapWithConcurrencyLimit,
37
- runSingleAgent,
38
- } from "./runner.js";
39
- import type { ChildLaunchPolicy, SingleResult } from "./runner-types.js";
40
- import { boundedPrivateText, boundText } from "./safe-text.js";
41
- import type { SubagentDetails } from "./subagent-details.js";
42
- import { createSessionWorkItemPersistence } from "./work-item-persistence.js";
43
- import { assertWorkspaceIsolationReady } from "./workspace.js";
44
-
45
- export interface PanelExecutionInput {
46
- toolCallId: string;
47
- params: SubagentParams;
48
- panel: NonNullable<SubagentParams["panel"]>;
49
- signal?: AbortSignal;
50
- onUpdate?: AgentToolUpdateCallback<SubagentDetails>;
51
- ctx: ExtensionContext;
52
- agents: AgentConfig[];
53
- agentScope: AgentScope;
54
- projectAgentsDir: string | null;
55
- maxParallelTasks: number;
56
- target: ResolvedSubagentTarget;
57
- resolveThinkingLevel: (
58
- agentName: string,
59
- local?: SubagentThinkingLevel,
60
- ) => SubagentThinkingLevel | undefined;
61
- resolveTimeoutMs: (agentName: string, local?: number) => number;
62
- }
63
-
64
- type PanelToolResult = AgentToolResult<SubagentDetails> & { isError?: boolean };
65
-
66
- const PANEL_READ_ONLY_TOOLS = new Set(["read", "grep", "find", "ls"]);
67
-
68
- export async function preflightPanelExecution(
69
- input: Pick<
70
- PanelExecutionInput,
71
- "panel" | "agents" | "target" | "resolveThinkingLevel" | "resolveTimeoutMs" | "signal"
72
- >,
73
- ): Promise<void> {
74
- assertPanelActive(input.signal);
75
- let requiresWorktree = false;
76
- for (const [index, reviewer] of input.panel.reviewers.entries()) {
77
- assertPanelActive(input.signal);
78
- const agent = input.agents.find((candidate) => candidate.name === reviewer.agent);
79
- if (!agent) throw new Error(`Unknown panel agent: ${reviewer.agent}`);
80
- requiresWorktree ||= !isReadOnlyAgent(agent);
81
- const policy = launchPolicy(
82
- input as PanelExecutionInput,
83
- reviewer.agent,
84
- input.resolveThinkingLevel(reviewer.agent, reviewer.thinkingLevel),
85
- input.panel.task,
86
- input.resolveTimeoutMs(reviewer.agent, reviewer.timeoutMs),
87
- index + 1,
88
- isReadOnlyAgent(agent) ? "shared" : "worktree",
89
- "review",
90
- );
91
- if (policy.capabilityGrant) {
92
- revokeCapabilityGrant(policy.capabilityGrant, "preflight-complete", Date.now());
93
- }
94
- }
95
- if (requiresWorktree) {
96
- await assertWorkspaceIsolationReady(input.target.cwd);
97
- assertPanelActive(input.signal);
98
- }
99
- const synthesizer = input.panel.synthesizer;
100
- const policy = launchPolicy(
101
- input as PanelExecutionInput,
102
- synthesizer.agent,
103
- input.resolveThinkingLevel(synthesizer.agent, synthesizer.thinkingLevel),
104
- "Panel synthesis",
105
- input.resolveTimeoutMs(synthesizer.agent, synthesizer.timeoutMs),
106
- input.panel.reviewers.length + 1,
107
- "shared",
108
- "tool-less",
109
- );
110
- if (policy.capabilityGrant) {
111
- revokeCapabilityGrant(policy.capabilityGrant, "preflight-complete", Date.now());
112
- }
113
- }
114
-
115
- export async function executePanel(input: PanelExecutionInput): Promise<PanelToolResult> {
116
- validatePanelRequest(input.panel, input.maxParallelTasks);
117
- const panelId = input.panel.id ?? `panel-${input.toolCallId}`;
118
- const preset: PanelPreset = input.panel.preset ?? "custom";
119
- const minValidReviews = input.panel.minValidReviews ?? 2;
120
- const requestedReviewTimeout = Math.max(
121
- ...input.panel.reviewers.map((reviewer) =>
122
- input.resolveTimeoutMs(reviewer.agent, reviewer.timeoutMs),
123
- ),
124
- );
125
- const requestedSynthesisTimeout = input.resolveTimeoutMs(
126
- input.panel.synthesizer.agent,
127
- input.panel.synthesizer.timeoutMs,
128
- );
129
- const totalMs =
130
- input.params.totalTimeoutMs ?? requestedReviewTimeout + requestedSynthesisTimeout + 60_000;
131
- const budgets = planPanelBudgets(totalMs, input.panel.reviewers.length);
132
- const panelStartedAt = Date.now();
133
- const failureMessageLimit = Math.max(128, Math.floor((8 * 1024) / input.panel.reviewers.length));
134
- const requiredAgents = [
135
- ...input.panel.reviewers.map((reviewer) => reviewer.agent),
136
- input.panel.synthesizer.agent,
137
- ];
138
- for (const agentName of requiredAgents) {
139
- if (!input.agents.some((agent) => agent.name === agentName)) {
140
- throw new Error(`Unknown panel agent: ${agentName}`);
141
- }
142
- }
143
-
144
- const group = new PanelChildGroup(input.signal);
145
- const ledger = new PanelEvidenceLedger(panelId, input.panel.reviewers.length);
146
- const workLedger = createPanelWorkLedger(panelId, input.panel, input.agents);
147
- const persistenceOwner =
148
- input.ctx.sessionManager.getSessionId?.() ??
149
- input.ctx.sessionManager.getSessionFile?.() ??
150
- `ephemeral:${input.ctx.cwd}`;
151
- const workPersistence = createSessionWorkItemPersistence(persistenceOwner, panelId);
152
- const persistWork = () => workPersistence.save(workLedger.snapshot());
153
- const workspaceByReviewer = new Map<string, string>();
154
- let output: PanelToolResult | undefined;
155
- const results: SingleResult[] = [];
156
- const failures: PanelFailure[] = [];
157
- let panelDetails = createPanelDetails({
158
- panelId,
159
- preset,
160
- reviewerIds: input.panel.reviewers.map((reviewer) => reviewer.id),
161
- sharedTask: input.panel.task,
162
- budgets,
163
- });
164
- const makeDetails = (currentResults: SingleResult[] = results): SubagentDetails => ({
165
- mode: "panel",
166
- agentScope: input.agentScope,
167
- projectAgentsDir: input.projectAgentsDir,
168
- results: [...currentResults],
169
- workflow: workLedger.snapshot(),
170
- metrics: calculateOrchestrationMetrics(workLedger.snapshot(), currentResults, panelDetails),
171
- panel: panelDetails,
172
- });
173
- const status = startSubagentStatus(
174
- input.ctx,
175
- input.toolCallId,
176
- panelReviewStatus(0, input.panel.reviewers.length, input.panel.reviewers.length),
177
- );
178
-
179
- try {
180
- await persistWork();
181
- assertPanelActive(group.signal);
182
- for (const reviewer of input.panel.reviewers) {
183
- assertPanelActive(group.signal);
184
- const agent = input.agents.find(
185
- (candidate) => candidate.name === reviewer.agent,
186
- ) as AgentConfig;
187
- if (isReadOnlyAgent(agent)) continue;
188
- const workspace = await group.createWorkspace(`${panelId}:${reviewer.id}`, input.target.cwd);
189
- assertPanelActive(group.signal);
190
- workspaceByReviewer.set(reviewer.id, workspace.path);
191
- }
192
-
193
- let completed = 0;
194
- const reviewPhaseStartedAt = panelStartedAt;
195
- const reviewResults = await mapWithConcurrencyLimit(
196
- input.panel.reviewers,
197
- Math.min(MAX_BLOCKING_PARALLEL_CONCURRENCY, input.maxParallelTasks),
198
- async (reviewer, index) => {
199
- const workItemId = `review:${reviewer.id}`;
200
- const startedWork = workLedger.start(workItemId, `agent:${reviewer.agent}`);
201
- const taskGeneration = startedWork.taskGeneration;
202
- const prompt = buildPanelReviewerPrompt({
203
- panelId,
204
- preset,
205
- task: input.panel.task,
206
- context: input.panel.context,
207
- reviewerId: reviewer.id,
208
- focus: reviewer.focus,
209
- });
210
- const phaseRemaining = budgets.reviewMs - (Date.now() - reviewPhaseStartedAt);
211
- const reviewBudgetAvailable = phaseRemaining >= 1;
212
- const timeoutMs = Math.min(
213
- input.resolveTimeoutMs(reviewer.agent, reviewer.timeoutMs),
214
- phaseRemaining,
215
- );
216
- const thinkingLevel = input.resolveThinkingLevel(reviewer.agent, reviewer.thinkingLevel);
217
- let artifactRevision = 0;
218
- let latestFingerprint = "";
219
- let repeatedEvidenceUpdates = 0;
220
- const reviewerController = new AbortController();
221
- const reviewerSignal = AbortSignal.any([group.signal, reviewerController.signal]);
222
- const publishOutput = (candidate: SingleResult): PanelReview | undefined => {
223
- const parsed = parsePanelReview(getResultFinalOutput(candidate), reviewer.id, {
224
- agent: reviewer.agent,
225
- model: candidate.actualModel ?? candidate.model,
226
- taskGeneration,
227
- });
228
- if (!parsed) return undefined;
229
- const fingerprint = JSON.stringify(parsed);
230
- if (fingerprint === latestFingerprint) {
231
- repeatedEvidenceUpdates += 1;
232
- if (repeatedEvidenceUpdates >= 8 && !reviewerController.signal.aborted) {
233
- reviewerController.abort("semantic-stall");
234
- }
235
- return parsed;
236
- }
237
- artifactRevision += 1;
238
- if (!ledger.publish(parsed, artifactRevision)) {
239
- artifactRevision -= 1;
240
- return undefined;
241
- }
242
- latestFingerprint = fingerprint;
243
- repeatedEvidenceUpdates = 0;
244
- return parsed;
245
- };
246
- const runAttempt = async (attempt: number): Promise<SingleResult> => {
247
- if (!reviewBudgetAvailable) {
248
- return panelReviewerBudgetExhaustedResult(
249
- input.agents,
250
- reviewer.agent,
251
- input.panel.task,
252
- thinkingLevel,
253
- );
254
- }
255
- const result = await runSingleAgent(
256
- input.ctx.cwd,
257
- input.agents,
258
- reviewer.agent,
259
- prompt,
260
- workspaceByReviewer.get(reviewer.id) ?? input.target.cwd,
261
- index + 1,
262
- reviewerSignal,
263
- thinkingLevel,
264
- timeoutMs,
265
- (partial) => {
266
- const partialResult = partial.details?.results[0];
267
- if (partialResult) publishOutput(partialResult);
268
- input.onUpdate?.({
269
- content: partial.content,
270
- details: makeDetails(),
271
- });
272
- },
273
- makeDetails,
274
- undefined,
275
- launchPolicy(
276
- input,
277
- reviewer.agent,
278
- thinkingLevel,
279
- `Panel review ${reviewer.id}`,
280
- timeoutMs,
281
- taskGeneration,
282
- workspaceByReviewer.has(reviewer.id) ? "worktree" : "shared",
283
- "review",
284
- {
285
- idleTimeoutMs: reviewer.idleTimeoutMs ?? input.params.idleTimeoutMs,
286
- maxTurns: reviewer.maxTurns ?? input.params.maxTurns,
287
- maxToolCalls: reviewer.maxToolCalls ?? input.params.maxToolCalls,
288
- },
289
- reviewPhaseStartedAt + budgets.reviewMs + budgets.finalizationMs,
290
- ),
291
- );
292
- result.target = targetPolicyAudit(input.target);
293
- result.attemptCount = attempt;
294
- if (
295
- reviewerController.signal.reason === "semantic-stall" &&
296
- result.aborted &&
297
- !group.signal.aborted
298
- ) {
299
- result.aborted = false;
300
- result.stopReason = "semantic-stall";
301
- result.errorMessage =
302
- "Panel reviewer stopped after repeated updates without new valid evidence";
303
- }
304
- return result;
305
- };
306
-
307
- let result = await runAttempt(1);
308
- let parsed = publishOutput(result) ?? ledger.latest(reviewer.id)?.review;
309
- let classification = classifyPanelFailure(result);
310
- if (!parsed && classification.retryable && !group.signal.aborted) {
311
- result = await runAttempt(2);
312
- parsed = publishOutput(result) ?? ledger.latest(reviewer.id)?.review;
313
- classification = classifyPanelFailure(result);
314
- }
315
- if (!parsed && result.timedOut && reviewBudgetAvailable && !group.signal.aborted) {
316
- const finalizationPrompt = `${prompt}\n\nYour prior attempt stopped before a valid artifact. Use this bounded checkpoint and return the required panel-review JSON now:\n${boundText(getResultFinalOutput(result), 8 * 1024, 200).text}`;
317
- const finalized = await runSingleAgent(
318
- input.ctx.cwd,
319
- input.agents,
320
- reviewer.agent,
321
- finalizationPrompt,
322
- workspaceByReviewer.get(reviewer.id) ?? input.target.cwd,
323
- index + 1,
324
- group.signal,
325
- thinkingLevel,
326
- budgets.finalizationMs,
327
- undefined,
328
- makeDetails,
329
- undefined,
330
- {
331
- ...launchPolicy(
332
- input,
333
- reviewer.agent,
334
- thinkingLevel,
335
- `Panel review finalization ${reviewer.id}`,
336
- budgets.finalizationMs,
337
- taskGeneration,
338
- workspaceByReviewer.has(reviewer.id) ? "worktree" : "shared",
339
- "tool-less",
340
- ),
341
- finalizeOnTimeout: false,
342
- },
343
- );
344
- finalized.attemptCount = (result.attemptCount ?? 1) + 1;
345
- result = finalized;
346
- parsed = publishOutput(result) ?? ledger.latest(reviewer.id)?.review;
347
- classification = classifyPanelFailure(result);
348
- }
349
- if (parsed && isResultError(result)) {
350
- failures.push({
351
- reviewerId: reviewer.id,
352
- ...classification,
353
- message: boundedPrivateText(
354
- result.errorMessage ??
355
- (result.stderr.trim() || "Reviewer failed after publishing valid evidence"),
356
- failureMessageLimit,
357
- ),
358
- });
359
- }
360
- if (!parsed) {
361
- if (!isResultError(result)) result.resultContractInvalid = true;
362
- classification = classifyPanelFailure(result);
363
- failures.push({
364
- reviewerId: reviewer.id,
365
- ...classification,
366
- message: boundedPrivateText(
367
- result.errorMessage ?? (result.stderr.trim() || "No valid panel review artifact"),
368
- failureMessageLimit,
369
- ),
370
- });
371
- workLedger.settle(
372
- workItemId,
373
- result.aborted ? "interrupted" : "failed",
374
- classification.kind,
375
- );
376
- } else {
377
- const artifact = ledger.latest(reviewer.id);
378
- workLedger.complete(workItemId, {
379
- taskGeneration,
380
- executionPlanId: result.executionPlan?.id,
381
- artifacts: artifact
382
- ? [
383
- {
384
- id: `panel-review:${reviewer.id}`,
385
- kind: "panel-review",
386
- version: String(artifact.revision),
387
- verified: false,
388
- },
389
- ]
390
- : [],
391
- });
392
- }
393
- completed += 1;
394
- status.update(
395
- panelReviewStatus(
396
- completed,
397
- input.panel.reviewers.length,
398
- input.panel.reviewers.length - completed,
399
- ),
400
- );
401
- return compactPanelResult(result);
402
- },
403
- group.signal,
404
- (reviewer) => {
405
- const workItemId = `review:${reviewer.id}`;
406
- workLedger.settle(workItemId, "interrupted", "parent-aborted-before-launch");
407
- failures.push({
408
- reviewerId: reviewer.id,
409
- kind: "cancelled",
410
- retryable: false,
411
- message: "Panel reviewer was not launched because the parent call was cancelled",
412
- });
413
- completed += 1;
414
- return cancelledPanelResult(
415
- input.agents,
416
- reviewer.agent,
417
- input.panel.task,
418
- input.resolveThinkingLevel(reviewer.agent, reviewer.thinkingLevel),
419
- );
420
- },
421
- );
422
- results.push(...reviewResults);
423
- await persistWork();
424
- const reviews = ledger.snapshot().map((artifact) => artifact.review);
425
- const reconciliation = reconcilePanel({ reviews, failures, minValidReviews });
426
- panelDetails = {
427
- ...panelDetails,
428
- validReviewCount: reviews.length,
429
- failedReviewCount: failures.length,
430
- blockingObjectionCount: reconciliation.blockingObjections.length,
431
- evidence: ledger.snapshot(),
432
- failures: [...reconciliation.failures],
433
- };
434
- if (reconciliation.kind === "insufficient-panel") {
435
- workLedger.settle(
436
- "synthesis",
437
- group.signal.aborted ? "interrupted" : "blocked",
438
- "insufficient-valid-reviews",
439
- );
440
- await persistWork();
441
- panelDetails.state = group.signal.aborted ? "cancelled" : "insufficient-panel";
442
- output = {
443
- content: [
444
- {
445
- type: "text",
446
- text: boundText(
447
- `Insufficient panel: ${reviews.length}/${minValidReviews} valid reviews. Partial evidence was preserved; synthesis was not run.`,
448
- DEFAULT_MAX_OUTPUT_BYTES,
449
- ).text,
450
- },
451
- ],
452
- details: { ...makeDetails(), isError: true },
453
- isError: true,
454
- };
455
- } else {
456
- const synthesisWork = workLedger.start("synthesis", `agent:${input.panel.synthesizer.agent}`);
457
- await persistWork();
458
- status.update(panelSynthesisStatus(input.panel.synthesizer.agent));
459
- const synthesisPrompt = buildPanelSynthesisPrompt({
460
- panelId,
461
- task: input.panel.task,
462
- reviews: reconciliation.reviews,
463
- failures: reconciliation.failures,
464
- });
465
- const synthesisTimeout = Math.min(
466
- input.resolveTimeoutMs(input.panel.synthesizer.agent, input.panel.synthesizer.timeoutMs),
467
- budgets.synthesisMs,
468
- Math.max(0, panelStartedAt + budgets.totalMs - budgets.cleanupMs - Date.now()),
469
- );
470
- const synthesisThinkingLevel = input.resolveThinkingLevel(
471
- input.panel.synthesizer.agent,
472
- input.panel.synthesizer.thinkingLevel,
473
- );
474
- const synthesisResult =
475
- synthesisTimeout < 1
476
- ? panelBudgetExhaustedResult(
477
- input.agents,
478
- input.panel.synthesizer.agent,
479
- synthesisPrompt,
480
- synthesisThinkingLevel,
481
- )
482
- : await runSingleAgent(
483
- input.ctx.cwd,
484
- input.agents,
485
- input.panel.synthesizer.agent,
486
- synthesisPrompt,
487
- input.target.cwd,
488
- undefined,
489
- group.signal,
490
- synthesisThinkingLevel,
491
- synthesisTimeout,
492
- undefined,
493
- makeDetails,
494
- undefined,
495
- {
496
- ...launchPolicy(
497
- input,
498
- input.panel.synthesizer.agent,
499
- synthesisThinkingLevel,
500
- "Panel synthesis",
501
- synthesisTimeout,
502
- input.panel.reviewers.length + 1,
503
- "shared",
504
- "tool-less",
505
- {
506
- idleTimeoutMs:
507
- input.panel.synthesizer.idleTimeoutMs ?? input.params.idleTimeoutMs,
508
- maxTurns: input.panel.synthesizer.maxTurns ?? input.params.maxTurns,
509
- maxToolCalls: input.panel.synthesizer.maxToolCalls ?? input.params.maxToolCalls,
510
- },
511
- ),
512
- },
513
- );
514
- synthesisResult.target = targetPolicyAudit(input.target);
515
- const synthesis = parsePanelSynthesis(
516
- getResultFinalOutput(synthesisResult),
517
- reconciliation.reviews,
518
- reconciliation.failures
519
- .map((failure) => failure.reviewerId)
520
- .filter((id): id is string => Boolean(id)),
521
- );
522
- compactPanelResult(synthesisResult);
523
- const synthesisErrored = isResultError(synthesisResult);
524
- panelDetails = {
525
- ...panelDetails,
526
- synthesizerResult: synthesisResult,
527
- synthesis,
528
- dissentCount: synthesis?.disagreements.length ?? 0,
529
- state: synthesisErrored
530
- ? group.signal.aborted
531
- ? "cancelled"
532
- : "failed"
533
- : synthesis
534
- ? failures.length > 0
535
- ? "degraded"
536
- : "completed"
537
- : group.signal.aborted
538
- ? "cancelled"
539
- : "failed",
540
- };
541
- const synthesisInvalid = !synthesis || synthesisErrored;
542
- if (!synthesis && !isResultError(synthesisResult)) {
543
- synthesisResult.resultContractInvalid = true;
544
- }
545
- if (synthesisInvalid) {
546
- workLedger.settle(
547
- "synthesis",
548
- synthesisResult.aborted ? "interrupted" : "failed",
549
- "invalid-panel-synthesis",
550
- );
551
- } else {
552
- workLedger.complete("synthesis", {
553
- taskGeneration: synthesisWork.taskGeneration,
554
- executionPlanId: synthesisResult.executionPlan?.id,
555
- });
556
- }
557
- await persistWork();
558
- output = {
559
- content: [
560
- {
561
- type: "text",
562
- text: synthesis
563
- ? boundText(synthesis.summary, DEFAULT_MAX_OUTPUT_BYTES).text
564
- : "Panel synthesis failed or returned an invalid panel-synthesis contract.",
565
- },
566
- ],
567
- details: { ...makeDetails(), isError: synthesisInvalid || undefined },
568
- isError: synthesisInvalid || undefined,
569
- };
570
- }
571
- } finally {
572
- status.clear();
573
- await group.close();
574
- panelDetails.cleanupComplete = true;
575
- if (output?.details.panel) output.details.panel.cleanupComplete = true;
576
- }
577
- return output as PanelToolResult;
578
- }
579
-
580
- function assertPanelActive(signal?: AbortSignal): void {
581
- if (!signal?.aborted) return;
582
- if (signal.reason instanceof Error) throw signal.reason;
583
- throw new DOMException("Panel execution was cancelled during setup", "AbortError");
584
- }
585
-
586
- function isReadOnlyAgent(agent: AgentConfig): boolean {
587
- return agent.capabilityManifest?.authority?.filesystem === "read";
588
- }
589
-
590
- function launchPolicy(
591
- input: PanelExecutionInput,
592
- agentName: string,
593
- thinkingLevel: SubagentThinkingLevel | undefined,
594
- displayTask: string,
595
- timeoutMs: number,
596
- taskGeneration: number,
597
- workspaceMode: "shared" | "worktree",
598
- toolMode: "review" | "tool-less",
599
- turnLimits?: ChildLaunchPolicy["turnLimits"],
600
- orchestrationDeadlineAt?: number,
601
- ): ChildLaunchPolicy {
602
- const agent = input.agents.find((candidate) => candidate.name === agentName);
603
- if (!agent) throw new Error(`Unknown panel agent: ${agentName}`);
604
- const resolvedTools = resolveContractTools(agent.tools, undefined);
605
- const tools =
606
- toolMode === "tool-less"
607
- ? []
608
- : workspaceMode === "shared"
609
- ? (resolvedTools?.filter((tool) => PANEL_READ_ONLY_TOOLS.has(tool)) ?? [])
610
- : resolvedTools;
611
- const contract: DelegationContract = {
612
- version: "pi-subagents:delegation:v2",
613
- level: "minimal",
614
- taskId: `panel-${taskGeneration}`,
615
- objective: truncateUtf8(displayTask, 16 * 1024).text,
616
- nonGoals: [],
617
- dependencies: [],
618
- requiredInputs: [],
619
- acceptanceCriteria: ["Return one valid bounded panel contract"],
620
- requiredEvidence: [],
621
- sideEffectPolicy:
622
- toolMode === "tool-less" || workspaceMode === "shared" ? "read-only" : "mutating",
623
- enforcement: "audit",
624
- };
625
- const executionPlan = createExecutionPlan({
626
- contract,
627
- agent,
628
- effectiveTools: tools,
629
- target: targetPolicyAudit(input.target),
630
- workspaceMode,
631
- transport: "subprocess",
632
- resultFormat: "text",
633
- model: agent.model,
634
- thinkingLevel,
635
- timeoutMs,
636
- taskGeneration,
637
- });
638
- const acknowledgement = acknowledgeExecutionPlan(executionPlan);
639
- if (acknowledgement.status === "rejected") {
640
- throw new Error(`Panel execution plan rejected: ${JSON.stringify(acknowledgement)}`);
641
- }
642
- return {
643
- projectTrust: input.target.trust.projectTrusted,
644
- tools,
645
- contract,
646
- displayTask,
647
- turnLimits,
648
- orchestrationDeadlineAt,
649
- finalizeOnTimeout: false,
650
- executionPlan,
651
- capabilityGrant: issueCapabilityGrant(executionPlan, Date.now(), timeoutMs + 60_000),
652
- };
653
- }
654
-
655
- function cancelledPanelResult(
656
- agents: AgentConfig[],
657
- agentName: string,
658
- task: string,
659
- thinkingLevel: SubagentThinkingLevel | undefined,
660
- ): SingleResult {
661
- const message = "Panel reviewer was not launched because the parent call was cancelled";
662
- return {
663
- agent: agentName,
664
- agentSource: agents.find((agent) => agent.name === agentName)?.source ?? "unknown",
665
- task,
666
- exitCode: 130,
667
- messages: [],
668
- stderr: message,
669
- usage: {
670
- input: 0,
671
- output: 0,
672
- cacheRead: 0,
673
- cacheWrite: 0,
674
- cost: 0,
675
- contextTokens: 0,
676
- turns: 0,
677
- },
678
- thinkingLevel,
679
- finalOutput: "",
680
- errorMessage: message,
681
- aborted: true,
682
- stopReason: "aborted",
683
- };
684
- }
685
-
686
- function panelReviewerBudgetExhaustedResult(
687
- agents: AgentConfig[],
688
- agentName: string,
689
- task: string,
690
- thinkingLevel: SubagentThinkingLevel | undefined,
691
- ): SingleResult {
692
- const result = panelBudgetExhaustedResult(agents, agentName, task, thinkingLevel);
693
- result.errorMessage = "Panel review budget was exhausted before launch";
694
- result.stderr = result.errorMessage;
695
- return result;
696
- }
697
-
698
- function panelBudgetExhaustedResult(
699
- agents: AgentConfig[],
700
- agentName: string,
701
- task: string,
702
- thinkingLevel: SubagentThinkingLevel | undefined,
703
- ): SingleResult {
704
- const message = "Panel synthesis budget was exhausted before launch";
705
- return {
706
- agent: agentName,
707
- agentSource: agents.find((agent) => agent.name === agentName)?.source ?? "unknown",
708
- task,
709
- exitCode: 124,
710
- messages: [],
711
- stderr: message,
712
- usage: {
713
- input: 0,
714
- output: 0,
715
- cacheRead: 0,
716
- cacheWrite: 0,
717
- cost: 0,
718
- contextTokens: 0,
719
- turns: 0,
720
- },
721
- thinkingLevel,
722
- finalOutput: "",
723
- errorMessage: message,
724
- timedOut: true,
725
- stopReason: "timeout",
726
- };
727
- }
728
-
729
- function compactPanelResult(result: SingleResult): SingleResult {
730
- result.messages = [];
731
- result.recentActivity = undefined;
732
- result.recentActivityTotal = undefined;
733
- result.task = boundText(result.task, 512, 20).text;
734
- result.finalOutput = result.finalOutput
735
- ? boundText(result.finalOutput, 512, 20).text
736
- : result.finalOutput;
737
- result.partialOutput = result.partialOutput
738
- ? boundText(result.partialOutput, 512, 20).text
739
- : result.partialOutput;
740
- result.stderr = boundText(result.stderr, 512, 20).text;
741
- result.errorMessage = result.errorMessage
742
- ? boundedPrivateText(result.errorMessage, 512)
743
- : result.errorMessage;
744
- return result;
745
- }
746
-
747
- function createPanelDetails(input: {
748
- panelId: string;
749
- preset: PanelPreset;
750
- reviewerIds: string[];
751
- sharedTask: string;
752
- budgets: ReturnType<typeof planPanelBudgets>;
753
- }): NonNullable<SubagentDetails["panel"]> {
754
- return {
755
- id: input.panelId,
756
- preset: input.preset,
757
- sharedTaskPreview: boundedPrivateText(input.sharedTask, 2 * 1024),
758
- state: "running",
759
- reviewerIds: input.reviewerIds,
760
- validReviewCount: 0,
761
- failedReviewCount: 0,
762
- blockingObjectionCount: 0,
763
- dissentCount: 0,
764
- budgets: input.budgets,
765
- evidence: [],
766
- failures: [],
767
- cleanupComplete: false,
768
- };
769
- }