@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,15 +0,0 @@
1
- export const READ_ONLY_CONSULT_TOOLS = ["read", "grep", "find", "ls"] as const;
2
-
3
- const READ_ONLY_CONSULT_TOOL_SET = new Set<string>(READ_ONLY_CONSULT_TOOLS);
4
-
5
- export function resolveConsultTools(tools: readonly string[] | undefined): string[] {
6
- if (tools === undefined) return [...READ_ONLY_CONSULT_TOOLS];
7
- const seen = new Set<string>();
8
- const effective: string[] = [];
9
- for (const tool of tools) {
10
- if (!READ_ONLY_CONSULT_TOOL_SET.has(tool) || seen.has(tool)) continue;
11
- seen.add(tool);
12
- effective.push(tool);
13
- }
14
- return effective;
15
- }
@@ -1,125 +0,0 @@
1
- import type { ExtensionAPI, ToolDefinition } from "@earendil-works/pi-coding-agent";
2
- import { cachedModuleLoader, throwIfAborted } from "./cached-module-loader.js";
3
- import type { RegisterSubagentConsultOptions } from "./consult.js";
4
- import { renderConsultCall, renderConsultResult } from "./consult-render.js";
5
- import { type ConsultDetails, SubagentConsultParams } from "./consult-tool.js";
6
-
7
- interface ConsultExecutionModule {
8
- executeSubagentConsult: typeof import("./consult.js").executeSubagentConsult;
9
- }
10
-
11
- export interface ConsultRegistrationDependencies {
12
- loadExecution?: () => Promise<ConsultExecutionModule>;
13
- }
14
-
15
- export function registerSubagentConsult(
16
- pi: ExtensionAPI,
17
- options: RegisterSubagentConsultOptions,
18
- dependencies: ConsultRegistrationDependencies = {},
19
- ): void {
20
- const loadExecution = cachedModuleLoader(
21
- dependencies.loadExecution ?? (() => import("./consult.js")),
22
- );
23
- let generation = 0;
24
- const active = new Set<AbortController>();
25
- const activeWork = new Set<Promise<unknown>>();
26
- const cancelActive = (reason: string) => {
27
- generation++;
28
- for (const controller of active) {
29
- controller.abort(new DOMException(reason, "AbortError"));
30
- }
31
- active.clear();
32
- };
33
- const cancelAndWaitForWork = async (reason: string) => {
34
- cancelActive(reason);
35
- await Promise.allSettled([...activeWork]);
36
- };
37
- pi.on("session_start", () => cancelAndWaitForWork("Subagent consultation session replaced"));
38
- pi.on("session_shutdown", () => cancelAndWaitForWork("Subagent consultation session shut down"));
39
-
40
- const description =
41
- "Run one ephemeral subagent synchronously under enforced read-only tool and resource policies and return its answer. The child can use only the effective subset of Pi's built-in read, grep, find, and ls tools. Shell commands, file writes, extension tools, detached lifecycle operations, and persistent agent state are disabled. The current working-directory policy, trusted-target resource policy, and available agent definitions are published in the pi-subagents session-guidance message. Allowed targets without effective trust inherit no target or project resources. This is not a filesystem sandbox.";
42
- const definition: ToolDefinition<typeof SubagentConsultParams, ConsultDetails> = {
43
- name: "subagent_consult",
44
- label: "Consult Read-only Subagent",
45
- description,
46
- promptSnippet: "Consult one constrained read-only subagent and wait for its answer",
47
- promptGuidelines: [
48
- "Use subagent_consult only for bounded read-only evidence gathering when an independent perspective is worth making the main agent wait.",
49
- "Keep ordinary planning and review in the main agent with applicable skills and deterministic checks; use subagent_consult only when synchronous read-only isolation adds concrete value.",
50
- "Set subagent_consult timeoutMs to the shortest realistic work deadline for the task difficulty; split oversized consultations instead of extending the deadline merely to compensate for broad scope.",
51
- "Implementation-shaped subagent_consult tasks remain read-only and can return only analysis or instructions.",
52
- ],
53
- parameters: SubagentConsultParams,
54
- async execute(_toolCallId, params, signal, onUpdate, ctx) {
55
- const ownerGeneration = generation;
56
- const ownedController = new AbortController();
57
- active.add(ownedController);
58
- const combined = combineAbortSignals(signal, ownedController.signal);
59
- const work = (async () => {
60
- throwIfAborted(combined.signal, "Subagent consultation loading was cancelled");
61
- let executionModule: ConsultExecutionModule;
62
- try {
63
- executionModule = await loadExecution();
64
- } catch (error) {
65
- throwIfAborted(combined.signal, "Subagent consultation loading was cancelled");
66
- throw error;
67
- }
68
- throwIfAborted(combined.signal, "Subagent consultation loading was cancelled");
69
- if (ownerGeneration !== generation) {
70
- throw new DOMException("Subagent consultation owner was replaced", "AbortError");
71
- }
72
- return executionModule.executeSubagentConsult(
73
- params,
74
- combined.signal,
75
- onUpdate,
76
- ctx,
77
- options,
78
- () => ownerGeneration === generation,
79
- );
80
- })();
81
- activeWork.add(work);
82
- try {
83
- return await work;
84
- } finally {
85
- combined.dispose();
86
- active.delete(ownedController);
87
- activeWork.delete(work);
88
- }
89
- },
90
- renderCall(args, theme) {
91
- return renderConsultCall(args, theme);
92
- },
93
- renderResult(result, renderOptions, theme, context) {
94
- return renderConsultResult(result, renderOptions, theme, context);
95
- },
96
- };
97
- pi.registerTool<typeof SubagentConsultParams, ConsultDetails>(definition);
98
- pi.on("tool_result", (event) => {
99
- if (event.toolName !== "subagent_consult") return;
100
- if ((event.details as ConsultDetails | undefined)?.isError) return { isError: true };
101
- });
102
- }
103
-
104
- function combineAbortSignals(
105
- external: AbortSignal | undefined,
106
- owned: AbortSignal,
107
- ): { signal: AbortSignal; dispose(): void } {
108
- if (!external) return { signal: owned, dispose() {} };
109
- const controller = new AbortController();
110
- const sources = [external, owned];
111
- const listeners = sources.map((source) => {
112
- const listener = () => {
113
- if (!controller.signal.aborted) controller.abort(source.reason);
114
- };
115
- if (source.aborted) listener();
116
- else source.addEventListener("abort", listener, { once: true });
117
- return { source, listener };
118
- });
119
- return {
120
- signal: controller.signal,
121
- dispose() {
122
- for (const { source, listener } of listeners) source.removeEventListener("abort", listener);
123
- },
124
- };
125
- }
@@ -1,194 +0,0 @@
1
- import type { AgentToolResult } from "@earendil-works/pi-agent-core";
2
- import {
3
- getMarkdownTheme,
4
- type Theme,
5
- type ToolRenderResultOptions,
6
- } from "@earendil-works/pi-coding-agent";
7
- import { Container, Markdown, Spacer, Text } from "@earendil-works/pi-tui";
8
- import type { ConsultDetails, SubagentConsultParams } from "./consult.js";
9
- import {
10
- COLLAPSED_ANSWER_LINES,
11
- COLLAPSED_LIST_LIMIT,
12
- expansionHint,
13
- previewLines,
14
- projectRenderActivity,
15
- type RenderStatus,
16
- recordValue,
17
- renderActivityLines,
18
- renderFallbackResult,
19
- safeBlock,
20
- safeLine,
21
- statusBadge,
22
- stringValue,
23
- type ToolRendererContext,
24
- textResult,
25
- toolHeader,
26
- } from "./render-common.js";
27
- import { formatUsageStats } from "./usage-format.js";
28
-
29
- export function renderConsultCall(args: Partial<SubagentConsultParams>, theme: Theme) {
30
- const scope = args.agentScope ?? "user";
31
- const text = [
32
- toolHeader(theme, "subagent_consult", args.agent, [`[${scope}]`, "read-only"]),
33
- ` ${theme.fg("dim", safeLine(args.task, "...", 2 * 1024))}`,
34
- ].join("\n");
35
- return new Text(text, 0, 0);
36
- }
37
-
38
- export function renderConsultResult(
39
- result: AgentToolResult<ConsultDetails>,
40
- options: ToolRenderResultOptions,
41
- theme: Theme,
42
- context: ToolRendererContext<SubagentConsultParams>,
43
- ) {
44
- const details = recordValue(result.details);
45
- if (!details || !recordValue(details.policy)) {
46
- return renderFallbackResult(result, options, theme, context.isError);
47
- }
48
-
49
- const progress = recordValue(details.progress);
50
- const child = recordValue(details.child);
51
- const status = consultStatus(details, progress, options, context.isError);
52
- const agent = safeLine(details.agent, safeLine(context.args?.agent, "subagent"), 256);
53
- const source = safeLine(details.agentSource, "unknown", 128);
54
- const usage = recordValue(progress?.usage ?? child?.usage);
55
- const usageText = formatUnknownUsage(
56
- usage,
57
- stringValue(details.model) || undefined,
58
- stringValue(details.thinkingLevel) || undefined,
59
- stringValue(progress?.actualProvider ?? child?.actualProvider) || undefined,
60
- stringValue(progress?.actualModel ?? child?.actualModel) || undefined,
61
- );
62
- const effectiveTools = stringList(recordValue(details.policy)?.effectiveTools);
63
- const activity = projectRenderActivity(progress?.recentActivity);
64
- const activityTotal = Math.max(
65
- activity.length,
66
- typeof progress?.recentActivityTotal === "number" ? progress.recentActivityTotal : 0,
67
- );
68
- const answer = safeBlock(textResult(result), "", 50 * 1024).trim();
69
-
70
- if (options.expanded) {
71
- const container = new Container();
72
- container.addChild(
73
- new Text(
74
- `${statusBadge(theme, status)} · ${theme.fg("toolTitle", theme.bold(agent))}${theme.fg("muted", ` (${source})`)}`,
75
- 0,
76
- 0,
77
- ),
78
- );
79
- if (usageText) container.addChild(new Text(theme.fg("dim", usageText), 0, 0));
80
- container.addChild(new Spacer(1));
81
- container.addChild(new Text(theme.fg("muted", "─── Task ───"), 0, 0));
82
- container.addChild(
83
- new Text(theme.fg("dim", safeBlock(context.args?.task, "(unavailable)", 50 * 1024)), 0, 0),
84
- );
85
- container.addChild(new Spacer(1));
86
- container.addChild(new Text(theme.fg("muted", "─── Policy ───"), 0, 0));
87
- container.addChild(new Text(theme.fg("dim", policySummary(details.policy)), 0, 0));
88
- if (activity.length > 0) {
89
- container.addChild(new Spacer(1));
90
- container.addChild(new Text(theme.fg("muted", "─── Activity ───"), 0, 0));
91
- container.addChild(
92
- new Text(renderActivityLines(activity, theme, undefined, activityTotal), 0, 0),
93
- );
94
- }
95
- container.addChild(new Spacer(1));
96
- container.addChild(new Text(theme.fg("muted", "─── Answer ───"), 0, 0));
97
- if (answer) container.addChild(new Markdown(answer, 0, 0, getMarkdownTheme()));
98
- else
99
- container.addChild(
100
- new Text(
101
- theme.fg("muted", options.isPartial ? "(waiting for output)" : "(no output)"),
102
- 0,
103
- 0,
104
- ),
105
- );
106
- return container;
107
- }
108
-
109
- const lines = [
110
- `${statusBadge(theme, status)} · ${theme.fg("toolTitle", theme.bold(agent))}${theme.fg("muted", ` (${source})`)}`,
111
- ];
112
- if (usageText) lines.push(theme.fg("dim", usageText));
113
- if (effectiveTools.length > 0 && options.isPartial) {
114
- lines.push(theme.fg("dim", `tools: ${effectiveTools.join(", ")}`));
115
- }
116
- if (activity.length > 0) {
117
- lines.push(renderActivityLines(activity, theme, COLLAPSED_LIST_LIMIT, activityTotal));
118
- } else if (options.isPartial) {
119
- lines.push(
120
- theme.fg("muted", status === "starting" ? "(starting child)" : "(waiting for activity)"),
121
- );
122
- } else if (answer) {
123
- lines.push(theme.fg("toolOutput", previewLines(answer, COLLAPSED_ANSWER_LINES)));
124
- } else {
125
- const error = safeBlock(child?.error, "", 2 * 1024).trim();
126
- lines.push(theme.fg(status === "failed" ? "error" : "muted", error || "(no output)"));
127
- }
128
- if (!options.isPartial) lines.push(expansionHint());
129
- return new Text(lines.filter(Boolean).join("\n"), 0, 0);
130
- }
131
-
132
- function consultStatus(
133
- details: Record<string, unknown>,
134
- progress: Record<string, unknown> | undefined,
135
- options: ToolRenderResultOptions,
136
- isError: boolean,
137
- ): RenderStatus {
138
- if (details.cancelled === true) return "cancelled";
139
- if (isError || details.isError === true) {
140
- const child = recordValue(details.child);
141
- return child?.aborted === true && child?.timedOut !== true ? "cancelled" : "failed";
142
- }
143
- if (options.isPartial) return progress?.phase === "starting" ? "starting" : "running";
144
- return "completed";
145
- }
146
-
147
- function stringList(value: unknown): string[] {
148
- return Array.isArray(value)
149
- ? value.flatMap((item) => (typeof item === "string" ? [safeLine(item, "", 256)] : []))
150
- : [];
151
- }
152
-
153
- function policySummary(value: unknown): string {
154
- const policy = recordValue(value);
155
- if (!policy) return "(unavailable)";
156
- const resources = recordValue(policy.effectiveResources);
157
- const tools = stringList(policy.effectiveTools);
158
- return [
159
- `tools: ${tools.length > 0 ? tools.join(", ") : "none"}`,
160
- `resources: ${safeLine(resources?.policy ?? policy.requestedResources, "unknown", 256)}`,
161
- `extensions: ${safeLine(policy.extensions, "unknown", 128)}`,
162
- `session persistence: ${safeLine(policy.sessionPersistence, "unknown", 128)}`,
163
- `retained agent: ${policy.retainedAgent === false ? "no" : "unknown"}`,
164
- ].join("\n");
165
- }
166
-
167
- function formatUnknownUsage(
168
- value: Record<string, unknown> | undefined,
169
- model?: string,
170
- thinkingLevel?: string,
171
- actualProvider?: string,
172
- actualModel?: string,
173
- ): string {
174
- const usage = value ?? {};
175
- return formatUsageStats(
176
- {
177
- input: safeNumber(usage.input),
178
- output: safeNumber(usage.output),
179
- cacheRead: safeNumber(usage.cacheRead),
180
- cacheWrite: safeNumber(usage.cacheWrite),
181
- cost: safeNumber(usage.cost),
182
- contextTokens: safeNumber(usage.contextTokens),
183
- turns: safeNumber(usage.turns),
184
- },
185
- model,
186
- thinkingLevel as never,
187
- actualProvider,
188
- actualModel,
189
- );
190
- }
191
-
192
- function safeNumber(value: unknown): number {
193
- return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : 0;
194
- }
@@ -1,51 +0,0 @@
1
- import type { ConsultResourcePolicy } from "./agents/types.js";
2
- import { DEFAULT_MAX_CONTEXT_BYTES, truncateUtf8 } from "./limits.js";
3
- import { resolvePiPromptResources } from "./prompt-resources.js";
4
- import type { ChildLaunchPolicy } from "./runner-types.js";
5
-
6
- const MINIMAL_CONSULT_SYSTEM_PROMPT =
7
- "You are a read-only consultation assistant. Analyze the delegated task using only executor-provided capabilities and return a grounded answer.";
8
-
9
- /**
10
- * Resolve Pi-owned prompt files without loading target settings, packages, or extensions.
11
- * The child still owns context-file, skill, and prompt-template loading according to this policy.
12
- */
13
- export async function resolveConsultResourceLaunchPolicy(
14
- policy: ConsultResourcePolicy,
15
- projectTrusted: boolean,
16
- cwd: string,
17
- ): Promise<ChildLaunchPolicy> {
18
- if (policy === "none") {
19
- return {
20
- disableExtensions: true,
21
- disableSkills: true,
22
- disablePromptTemplates: true,
23
- disableContextFiles: true,
24
- projectTrust: false,
25
- baseSystemPrompt: MINIMAL_CONSULT_SYSTEM_PROMPT,
26
- };
27
- }
28
-
29
- const resources = await resolvePiPromptResources(cwd, projectTrusted);
30
- const discoveredSystemPrompt = resources.systemPrompt;
31
- const baseSystemPrompt = discoveredSystemPrompt
32
- ? truncateUtf8(discoveredSystemPrompt, DEFAULT_MAX_CONTEXT_BYTES).text
33
- : undefined;
34
- const appendSystemPromptPaths = resources.appendSystemPromptPaths;
35
- const shared = {
36
- disableExtensions: true,
37
- disableContextFiles: !projectTrusted,
38
- projectTrust: projectTrusted,
39
- baseSystemPrompt,
40
- appendSystemPromptPaths:
41
- appendSystemPromptPaths.length > 0 ? appendSystemPromptPaths : undefined,
42
- };
43
- if (policy === "project-context") {
44
- return {
45
- ...shared,
46
- disableSkills: true,
47
- disablePromptTemplates: true,
48
- };
49
- }
50
- return shared;
51
- }
@@ -1,95 +0,0 @@
1
- import { StringEnum } from "@earendil-works/pi-ai";
2
- import { type Static, Type } from "typebox";
3
- import type { AgentScope, ConsultResourcePolicy } from "./agents/types.js";
4
- import { THINKING_LEVELS } from "./agents/types.js";
5
- import { DEFAULT_MAX_CONTEXT_BYTES, MAX_SUBAGENT_TIMEOUT_MS } from "./limits.js";
6
-
7
- const ConsultScopeSchema = StringEnum(["user", "project", "both"] as const, {
8
- default: "user",
9
- description: "Agent definition scope. Project scopes require a trusted project.",
10
- });
11
- const ConsultThinkingSchema = StringEnum(THINKING_LEVELS);
12
-
13
- export const SubagentConsultParams = Type.Object(
14
- {
15
- agent: Type.String({ minLength: 1 }),
16
- task: Type.String({ minLength: 1, maxLength: DEFAULT_MAX_CONTEXT_BYTES }),
17
- agentScope: Type.Optional(ConsultScopeSchema),
18
- confirmProjectAgents: Type.Optional(Type.Boolean({ default: true })),
19
- cwd: Type.Optional(Type.String({ minLength: 1 })),
20
- timeoutMs: Type.Optional(
21
- Type.Number({
22
- minimum: 1,
23
- maximum: MAX_SUBAGENT_TIMEOUT_MS,
24
- description:
25
- "Work deadline selected for the consultation difficulty. On expiry, Pi aborts the work and makes one separately bounded summary attempt.",
26
- }),
27
- ),
28
- thinkingLevel: Type.Optional(ConsultThinkingSchema),
29
- },
30
- { additionalProperties: false },
31
- );
32
-
33
- export type SubagentConsultParams = Static<typeof SubagentConsultParams>;
34
-
35
- export interface ConsultProgressActivity {
36
- type: "text" | "toolCall";
37
- text?: string;
38
- name?: "read" | "grep" | "find" | "ls";
39
- args?: Record<string, string | number | boolean>;
40
- }
41
-
42
- export interface ConsultProgress {
43
- phase: "starting" | "running";
44
- recentActivity: ConsultProgressActivity[];
45
- recentActivityTotal: number;
46
- actualProvider?: string;
47
- actualModel?: string;
48
- usage: {
49
- input: number;
50
- output: number;
51
- cacheRead: number;
52
- cacheWrite: number;
53
- cost: number;
54
- contextTokens: number;
55
- turns: number;
56
- };
57
- }
58
-
59
- export interface ConsultDetails {
60
- agent: string;
61
- agentSource: string;
62
- agentScope: AgentScope;
63
- cwd: string;
64
- model?: string;
65
- thinkingLevel?: string;
66
- timeoutMs: number;
67
- policy: {
68
- requestedTools: string[] | null;
69
- effectiveTools: string[];
70
- cwdBoundary: "current-workspace" | "external";
71
- targetTrust: {
72
- kind: string;
73
- projectTrusted: boolean;
74
- sourcePath?: string;
75
- warning?: string;
76
- };
77
- requestedResources: ConsultResourcePolicy;
78
- effectiveResources: {
79
- policy: ConsultResourcePolicy;
80
- projectResources: boolean;
81
- contextFiles: boolean;
82
- skills: boolean;
83
- promptTemplates: boolean;
84
- };
85
- resourceDowngradeReason?: string;
86
- extensions: "disabled";
87
- sessionPersistence: "disabled";
88
- retainedAgent: false;
89
- };
90
- child?: Record<string, unknown>;
91
- progress?: ConsultProgress;
92
- cancelled?: boolean;
93
- isError?: boolean;
94
- truncated?: boolean;
95
- }