@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
@@ -1,64 +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 { SubagentInspectRuntime } from "./inspect.js";
4
- import { renderInspectCall, renderInspectResult } from "./inspect-render.js";
5
- import { SubagentInspectParams } from "./inspect-tool.js";
6
-
7
- interface InspectExecutionModule {
8
- executeSubagentInspect: typeof import("./inspect.js").executeSubagentInspect;
9
- }
10
-
11
- export interface InspectRegistrationDependencies {
12
- loadExecution?: () => Promise<InspectExecutionModule>;
13
- }
14
-
15
- export function registerSubagentInspect(
16
- pi: ExtensionAPI,
17
- runtime: SubagentInspectRuntime,
18
- dependencies: InspectRegistrationDependencies = {},
19
- ): void {
20
- const loadExecution = cachedModuleLoader(
21
- dependencies.loadExecution ?? (() => import("./inspect.js")),
22
- );
23
- let lifecycleGeneration = 0;
24
- pi.on("session_start", () => {
25
- lifecycleGeneration += 1;
26
- });
27
- pi.on("session_shutdown", () => {
28
- lifecycleGeneration += 1;
29
- });
30
- const definition: ToolDefinition<typeof SubagentInspectParams, Record<string, unknown>> = {
31
- name: "subagent_inspect",
32
- label: "Inspect Subagents",
33
- description:
34
- "Inspect available subagent definitions, models, retained runs, persisted blocking workflows, runtime status, and diagnostics without changing subagent or workspace state. This tool never starts a child, sends or acknowledges messages, interrupts or closes runs, changes settings, or modifies files.",
35
- promptSnippet: "Inspect subagent metadata and runtime state without changing it",
36
- parameters: SubagentInspectParams,
37
- async execute(_toolCallId, params, signal, _onUpdate, ctx) {
38
- const ownerGeneration = lifecycleGeneration;
39
- throwIfAborted(signal, "Subagent inspection loading was cancelled");
40
- let executionModule: InspectExecutionModule;
41
- try {
42
- executionModule = await loadExecution();
43
- } catch (error) {
44
- throwIfAborted(signal, "Subagent inspection loading was cancelled");
45
- if (ownerGeneration !== lifecycleGeneration) {
46
- throw new DOMException("Subagent inspection session was replaced", "AbortError");
47
- }
48
- throw error;
49
- }
50
- throwIfAborted(signal, "Subagent inspection loading was cancelled");
51
- if (ownerGeneration !== lifecycleGeneration) {
52
- throw new DOMException("Subagent inspection session was replaced", "AbortError");
53
- }
54
- return executionModule.executeSubagentInspect(params, ctx, runtime);
55
- },
56
- renderCall(args, theme) {
57
- return renderInspectCall(args, theme);
58
- },
59
- renderResult(result, options, theme, context) {
60
- return renderInspectResult(result, options, theme, context);
61
- },
62
- };
63
- pi.registerTool(definition);
64
- }
@@ -1,334 +0,0 @@
1
- import type { AgentToolResult } from "@earendil-works/pi-agent-core";
2
- import type { Theme, ToolRenderResultOptions } from "@earendil-works/pi-coding-agent";
3
- import { Text } from "@earendil-works/pi-tui";
4
- import type { SubagentInspectParams } from "./inspect.js";
5
- import {
6
- booleanValue,
7
- COLLAPSED_LIST_LIMIT,
8
- expansionHint,
9
- numberValue,
10
- recordList,
11
- recordValue,
12
- renderFallbackResult,
13
- safeBlock,
14
- safeLine,
15
- statusBadge,
16
- stringValue,
17
- type ToolRendererContext,
18
- toolHeader,
19
- } from "./render-common.js";
20
-
21
- export function renderInspectCall(args: Partial<SubagentInspectParams>, theme: Theme) {
22
- const action = safeLine(args.action, "...", 128);
23
- const metadata: string[] = [];
24
- if (args.agentScope) metadata.push(`[${args.agentScope}]`);
25
- if (args.agent) metadata.push(`agent:${safeLine(args.agent, "", 256)}`);
26
- if (args.agentId) metadata.push(`id:${safeLine(args.agentId, "", 256)}`);
27
- if (args.workflowId) metadata.push(`workflow:${safeLine(args.workflowId, "", 256)}`);
28
- if (args.includeClosed) metadata.push("include closed");
29
- return new Text(toolHeader(theme, "subagent_inspect", action, metadata), 0, 0);
30
- }
31
-
32
- export function renderInspectResult(
33
- result: AgentToolResult<Record<string, unknown>>,
34
- options: ToolRenderResultOptions,
35
- theme: Theme,
36
- context: ToolRendererContext<SubagentInspectParams>,
37
- ) {
38
- const details = recordValue(result.details);
39
- const action = stringValue(details?.action);
40
- if (!details || !action) return renderFallbackResult(result, options, theme, context.isError);
41
-
42
- const rendered = renderAction(action, details, options.expanded, theme);
43
- if (!rendered) return renderFallbackResult(result, options, theme, context.isError);
44
- return new Text(rendered, 0, 0);
45
- }
46
-
47
- function renderAction(
48
- action: string,
49
- details: Record<string, unknown>,
50
- expanded: boolean,
51
- theme: Theme,
52
- ): string | undefined {
53
- switch (action) {
54
- case "list_agents":
55
- return renderList("agent", recordList(details.agents), details, expanded, theme, formatAgent);
56
- case "get_agent": {
57
- const agent = recordValue(details.agent);
58
- if (!agent) return undefined;
59
- const lines = [
60
- `${statusBadge(theme, "completed")} · ${theme.fg("toolTitle", theme.bold(safeLine(agent.name, "agent", 256)))}${theme.fg("muted", ` (${safeLine(agent.source, "unknown", 128)})`)}`,
61
- formatAgent(agent, theme, true),
62
- ];
63
- if (!expanded) lines.push(expansionHint());
64
- return lines.join("\n");
65
- }
66
- case "list_runs":
67
- return renderList("run", recordList(details.runs), details, expanded, theme, formatRun);
68
- case "get_run": {
69
- const run = recordValue(details.run);
70
- if (!run) return undefined;
71
- const lines = [
72
- `${statusBadge(theme, "completed")} · run ${theme.fg("accent", safeLine(run.id, "run", 256))}`,
73
- formatRun(run, theme, true),
74
- ];
75
- if (!expanded) lines.push(expansionHint());
76
- return lines.join("\n");
77
- }
78
- case "list_workflows":
79
- return renderList(
80
- "workflow",
81
- recordList(details.workflows),
82
- details,
83
- expanded,
84
- theme,
85
- formatWorkflow,
86
- );
87
- case "get_workflow": {
88
- const workflow = recordValue(details.workflow);
89
- if (!workflow) return undefined;
90
- return [
91
- `${statusBadge(theme, "completed")} · workflow ${theme.fg("accent", safeLine(workflow.workflowId, "workflow", 256))}`,
92
- formatWorkflow(workflow, theme, expanded),
93
- ].join("\n");
94
- }
95
- case "list_models":
96
- return renderList(
97
- "model",
98
- recordList(details.models),
99
- details,
100
- expanded,
101
- theme,
102
- formatModel,
103
- stringValue(details.source),
104
- );
105
- case "preview_context": {
106
- const preview = recordValue(details.preview);
107
- if (!preview) return undefined;
108
- return [
109
- `${statusBadge(theme, "completed")} · context ${theme.fg("accent", safeLine(preview.mode, "none", 128))}`,
110
- theme.fg(
111
- "dim",
112
- `${numberValue(preview.turns)} turns · ${numberValue(preview.sourceCount)} sources · ${numberValue(preview.bytes)} bytes${preview.truncated === true ? " · truncated" : ""}`,
113
- ),
114
- ].join("\n");
115
- }
116
- case "status":
117
- return renderStatus(details, expanded, theme);
118
- case "diagnose":
119
- return renderDiagnose(details, expanded, theme);
120
- default:
121
- return undefined;
122
- }
123
- }
124
-
125
- function renderList(
126
- label: string,
127
- items: Record<string, unknown>[],
128
- details: Record<string, unknown>,
129
- expanded: boolean,
130
- theme: Theme,
131
- format: (item: Record<string, unknown>, theme: Theme, expanded: boolean) => string,
132
- source = "",
133
- ): string {
134
- const returned = numberValue(details.returned, items.length);
135
- const omitted = numberValue(details.omitted);
136
- const noun = `${label}${returned === 1 ? "" : "s"}`;
137
- const lines = [
138
- `${statusBadge(theme, "completed")} · ${returned} ${noun}${source ? theme.fg("muted", ` · ${safeLine(source, "", 256)}`) : ""}`,
139
- ];
140
- const selected = expanded ? items : items.slice(0, COLLAPSED_LIST_LIMIT);
141
- for (const item of selected) lines.push(format(item, theme, expanded));
142
- const hidden = Math.max(0, items.length - selected.length) + omitted;
143
- if (hidden > 0) lines.push(theme.fg("muted", `… ${hidden} omitted`));
144
- if (items.length === 0) lines.push(theme.fg("muted", `(no ${label}s)`));
145
- if (!expanded && (items.length > 0 || omitted > 0)) lines.push(expansionHint());
146
- return lines.join("\n");
147
- }
148
-
149
- function formatAgent(agent: Record<string, unknown>, theme: Theme, expanded: boolean): string {
150
- const name = safeLine(agent.name, "agent", 256);
151
- const source = safeLine(agent.source, "unknown", 128);
152
- const model = stringValue(agent.model);
153
- const toolCount = typeof agent.toolCount === "number" ? agent.toolCount : undefined;
154
- const description = safeBlock(agent.description, "", 512).trim();
155
- const lines = [
156
- `${theme.fg("muted", "• ")}${theme.fg("accent", name)} ${theme.fg("muted", source)}${model ? theme.fg("dim", ` · ${safeLine(model, "", 256)}`) : ""}${toolCount !== undefined ? theme.fg("dim", ` · ${toolCount} tools`) : ""}`,
157
- ];
158
- if (description) lines.push(` ${theme.fg("toolOutput", description)}`);
159
- if (expanded) {
160
- const path = stringValue(agent.path);
161
- const consultTools = stringList(agent.consultTools);
162
- if (path) lines.push(` ${theme.fg("dim", `path: ${safeLine(path, "", 2 * 1024)}`)}`);
163
- lines.push(` ${theme.fg("dim", `consult tools: ${consultTools.join(", ") || "none"}`)}`);
164
- }
165
- return lines.join("\n");
166
- }
167
-
168
- function formatRun(run: Record<string, unknown>, theme: Theme, expanded: boolean): string {
169
- const id = safeLine(run.id, "run", 256);
170
- const agent = safeLine(run.agent, "agent", 256);
171
- const state = safeLine(run.state, "unknown", 128);
172
- const unread = numberValue(run.unreadMessages);
173
- const lines = [
174
- `${theme.fg("muted", "• ")}${theme.fg("accent", id)} ${theme.fg("toolOutput", agent)} ${theme.fg("muted", state)}${unread > 0 ? theme.fg("warning", ` · unread:${unread}`) : ""}`,
175
- ];
176
- if (expanded) {
177
- const thinking = stringValue(run.thinkingLevel);
178
- const timeout = numberValue(run.currentTimeoutMs) || numberValue(run.timeoutMs);
179
- const idleTimeout = numberValue(run.currentIdleTimeoutMs) || numberValue(run.idleTimeoutMs);
180
- const maxTurns = numberValue(run.currentMaxTurns) || numberValue(run.maxTurns);
181
- const maxToolCalls = numberValue(run.currentMaxToolCalls) || numberValue(run.maxToolCalls);
182
- const task = safeBlock(run.currentTask, "", 2 * 1024).trim();
183
- const error = safeBlock(run.error, "", 2 * 1024).trim();
184
- lines.push(
185
- ` ${theme.fg("dim", `${numberValue(run.historyCount)} history · ${thinking ? `thinking:${safeLine(thinking, "", 128)} · ` : ""}${timeout ? `timeout:${timeout}ms · ` : ""}${idleTimeout ? `idle:${idleTimeout}ms · ` : ""}${maxTurns ? `turns:${maxTurns} · ` : ""}${maxToolCalls ? `tools:${maxToolCalls} · ` : ""}${numberValue(run.children)} children`)}`,
186
- );
187
- const context = recordValue(run.context);
188
- const telemetry = recordValue(run.telemetry);
189
- if (context) {
190
- lines.push(
191
- ` ${theme.fg("dim", `context: ${numberValue(context.turns)} turns · ${numberValue(context.sources)} sources · ${numberValue(context.bytes)} bytes${context.truncated === true ? " · truncated" : ""}`)}`,
192
- );
193
- }
194
- if (telemetry) {
195
- lines.push(
196
- ` ${theme.fg("dim", `transport: ${safeLine(telemetry.transport, "unknown", 128)} · phase:${safeLine(telemetry.phase, "unknown", 128)}${stringValue(telemetry.protocol) ? ` · ${safeLine(telemetry.protocol, "", 128)}` : ""}`)}`,
197
- );
198
- }
199
- if (task) lines.push(` ${theme.fg("dim", `task: ${task}`)}`);
200
- if (error) lines.push(` ${theme.fg("error", `error: ${error}`)}`);
201
- }
202
- return lines.join("\n");
203
- }
204
-
205
- function formatWorkflow(
206
- workflow: Record<string, unknown>,
207
- theme: Theme,
208
- expanded: boolean,
209
- ): string {
210
- const id = safeLine(workflow.workflowId, "workflow", 256);
211
- const states = recordValue(workflow.states);
212
- const stateText = states
213
- ? Object.entries(states)
214
- .map(([state, count]) => `${safeLine(state, "unknown", 128)}:${numberValue(count)}`)
215
- .join(" · ")
216
- : "";
217
- const lines = [
218
- `${theme.fg("muted", "• ")}${theme.fg("accent", id)} ${theme.fg("muted", `${numberValue(workflow.itemCount)} items · generation:${numberValue(workflow.generation)}`)}`,
219
- ];
220
- if (stateText) lines.push(` ${theme.fg("dim", stateText)}`);
221
- if (expanded) {
222
- for (const item of recordList(workflow.items).slice(0, COLLAPSED_LIST_LIMIT)) {
223
- lines.push(
224
- ` ${theme.fg("muted", "- ")}${theme.fg("toolOutput", safeLine(item.id, "task", 256))} ${theme.fg("dim", safeLine(item.state, "unknown", 128))}`,
225
- );
226
- }
227
- const omitted = numberValue(workflow.omittedItems);
228
- if (omitted > 0) lines.push(theme.fg("muted", ` … ${omitted} tasks omitted`));
229
- }
230
- return lines.join("\n");
231
- }
232
-
233
- function formatModel(model: Record<string, unknown>, theme: Theme, expanded: boolean): string {
234
- const identity = `${safeLine(model.provider, "provider", 256)}/${safeLine(model.id, "model", 256)}`;
235
- const current = booleanValue(model.current) ? theme.fg("success", " · current") : "";
236
- const reasoning = booleanValue(model.reasoning) ? theme.fg("dim", " · reasoning") : "";
237
- const lines = [`${theme.fg("muted", "• ")}${theme.fg("accent", identity)}${current}${reasoning}`];
238
- if (expanded) {
239
- const name = stringValue(model.name);
240
- const thinking = stringValue(model.thinkingLevel);
241
- if (name) lines.push(` ${theme.fg("toolOutput", safeLine(name, "", 512))}`);
242
- lines.push(
243
- ` ${theme.fg("dim", `context:${numberValue(model.contextWindow)} · max:${numberValue(model.maxTokens)}${thinking ? ` · thinking:${safeLine(thinking, "", 128)}` : ""}`)}`,
244
- );
245
- }
246
- return lines.join("\n");
247
- }
248
-
249
- function renderStatus(
250
- details: Record<string, unknown>,
251
- expanded: boolean,
252
- theme: Theme,
253
- ): string | undefined {
254
- const status = recordValue(details.status);
255
- const stateful = recordValue(status?.stateful);
256
- if (!status || !stateful) return undefined;
257
- const currentLimits = recordValue(status.statefulLimits) ?? recordValue(stateful.limits);
258
- const lines = [
259
- `${statusBadge(theme, "completed")} · runtime status`,
260
- `${theme.fg("muted", "workflow: ")}${theme.fg("accent", safeLine(status.workflow, "unknown", 128))} · ${numberValue(stateful.activeAgents)} active · ${numberValue(stateful.retainedAgents)} retained`,
261
- `${theme.fg("muted", "stateful: ")}${stateful.initialized === true ? "initialized" : "not initialized"} · resources: ${safeLine(status.consultResources, "unknown", 128)}`,
262
- ];
263
- if (currentLimits) {
264
- lines.push(`${theme.fg("muted", "limits: ")}${formatDetachedLimits(currentLimits)}`);
265
- }
266
- if (expanded) {
267
- const delivery = stringValue(stateful.completionDelivery);
268
- const transport = stringValue(stateful.transport);
269
- if (transport || delivery) {
270
- lines.push(
271
- theme.fg(
272
- "dim",
273
- [
274
- transport && `transport:${safeLine(transport)}`,
275
- delivery && `delivery:${safeLine(delivery)}`,
276
- ]
277
- .filter(Boolean)
278
- .join(" · "),
279
- ),
280
- );
281
- }
282
- const configured = recordValue(status.configuredStatefulLimits);
283
- const sources = recordValue(status.configuredStatefulLimitSources);
284
- if (configured) {
285
- lines.push(theme.fg("dim", `configured: ${formatDetachedLimits(configured, sources)}`));
286
- }
287
- } else lines.push(expansionHint());
288
- return lines.join("\n");
289
- }
290
-
291
- function formatDetachedLimits(
292
- limits: Record<string, unknown>,
293
- sources?: Record<string, unknown>,
294
- ): string {
295
- return [
296
- ["agents", "maxAgents"],
297
- ["active", "maxActiveTurns"],
298
- ["children", "maxChildrenPerAgent"],
299
- ["depth", "maxDepth"],
300
- ["stored", "maxStoredAgents"],
301
- ]
302
- .map(([label, field]) => {
303
- const source = stringValue(sources?.[field]);
304
- return `${label}:${numberValue(limits[field])}${source ? ` (${safeLine(source, "", 64)})` : ""}`;
305
- })
306
- .join(" · ");
307
- }
308
-
309
- function renderDiagnose(details: Record<string, unknown>, expanded: boolean, theme: Theme): string {
310
- const checks = recordList(details.checks);
311
- const hasFail = checks.some((check) => check.status === "fail");
312
- const hasWarning = checks.some((check) => check.status === "warning");
313
- const overall = hasFail ? "failed" : hasWarning ? "warnings" : "passed";
314
- const status = hasFail ? "failed" : hasWarning ? "warning" : "completed";
315
- const lines = [`${statusBadge(theme, status)} · Diagnostics ${overall}`];
316
- const selected = expanded ? checks : checks.slice(0, COLLAPSED_LIST_LIMIT);
317
- for (const check of selected) {
318
- const checkStatus = safeLine(check.status, "unknown", 64);
319
- const color =
320
- checkStatus === "fail" ? "error" : checkStatus === "warning" ? "warning" : "success";
321
- lines.push(
322
- `${theme.fg(color, checkStatus.toUpperCase())} ${theme.fg("accent", safeLine(check.name, "check", 256))} · ${theme.fg("toolOutput", safeBlock(check.message, "", 2 * 1024))}`,
323
- );
324
- }
325
- if (checks.length === 0) lines.push(theme.fg("muted", "(no diagnostic checks)"));
326
- if (!expanded && checks.length > 0) lines.push(expansionHint());
327
- return lines.join("\n");
328
- }
329
-
330
- function stringList(value: unknown): string[] {
331
- return Array.isArray(value)
332
- ? value.flatMap((item) => (typeof item === "string" ? [safeLine(item, "", 256)] : []))
333
- : [];
334
- }
@@ -1,45 +0,0 @@
1
- import { StringEnum } from "@earendil-works/pi-ai";
2
- import { type Static, Type } from "typebox";
3
-
4
- const INSPECT_ACTIONS = [
5
- "list_agents",
6
- "get_agent",
7
- "list_runs",
8
- "get_run",
9
- "list_workflows",
10
- "get_workflow",
11
- "list_models",
12
- "preview_context",
13
- "status",
14
- "diagnose",
15
- ] as const;
16
-
17
- const AgentScopeSchema = StringEnum(["user", "project", "both"] as const, {
18
- default: "user",
19
- description: "Agent definition scope. Project scopes require a trusted project.",
20
- });
21
- const LimitSchema = Type.Number({ minimum: 1, maximum: 100, multipleOf: 1 });
22
- const ContextModeSchema = Type.Union([
23
- StringEnum(["none", "all", "summary"] as const),
24
- Type.Number({ minimum: 1, multipleOf: 1 }),
25
- ]);
26
-
27
- export const SubagentInspectParams = Type.Object(
28
- {
29
- action: StringEnum(INSPECT_ACTIONS),
30
- agent: Type.Optional(Type.String({ minLength: 1 })),
31
- agentId: Type.Optional(
32
- Type.String({ minLength: 1, description: "Retained agent ID or canonical task path." }),
33
- ),
34
- workflowId: Type.Optional(Type.String({ minLength: 1, maxLength: 256 })),
35
- agentScope: Type.Optional(AgentScopeSchema),
36
- limit: Type.Optional(LimitSchema),
37
- includeClosed: Type.Optional(Type.Boolean({ default: false })),
38
- context: Type.Optional(ContextModeSchema),
39
- contextEntryIds: Type.Optional(Type.Array(Type.String({ minLength: 1 }))),
40
- },
41
- { additionalProperties: false },
42
- );
43
-
44
- export type SubagentInspectParams = Static<typeof SubagentInspectParams>;
45
- export { INSPECT_ACTIONS };