@xzzpig/pi-subagents 0.24.2 → 0.25.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 (258) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/bundle/agent-management.js +4 -4
  3. package/bundle/agents.js +3 -3
  4. package/bundle/child-tool-plan.js +2 -2
  5. package/bundle/chunk-34TUUBRN.js +1107 -0
  6. package/bundle/{chunk-SW2VMNIU.js → chunk-5OD3OWTE.js} +2 -2
  7. package/bundle/{chunk-XWWUDWUW.js → chunk-5YEOWNSD.js} +371 -135
  8. package/bundle/{chunk-EUPJB4S7.js → chunk-5Z7JAORM.js} +196 -1219
  9. package/bundle/{chunk-LCDJWBVM.js → chunk-66JNFRFS.js} +1 -1
  10. package/bundle/{chunk-4UH4WS4G.js → chunk-6MNRKUHY.js} +23 -12
  11. package/bundle/{chunk-ED55MIC2.js → chunk-CGFF4WA3.js} +42 -19
  12. package/bundle/{chunk-TMHVDPYW.js → chunk-DLVPMML3.js} +263 -154
  13. package/bundle/chunk-HXRB42AF.js +108 -0
  14. package/bundle/{chunk-355ECEP2.js → chunk-IH7LQVEE.js} +29 -14
  15. package/bundle/{chunk-CYY5UMJU.js → chunk-IJWITCC6.js} +411 -249
  16. package/bundle/{chunk-RU522D5W.js → chunk-IKFKH5EL.js} +369 -50
  17. package/bundle/{chunk-Z6TFJ6BR.js → chunk-INWSUNI6.js} +1 -1
  18. package/bundle/{chunk-JEA2ZKUA.js → chunk-IUDEI6FJ.js} +35 -200
  19. package/bundle/{chunk-WW76JRIX.js → chunk-JAXVBXGF.js} +1 -1
  20. package/bundle/{chunk-ICNYIALB.js → chunk-JH5H4CYJ.js} +784 -474
  21. package/bundle/{chunk-35GII5EF.js → chunk-JWFLPSTP.js} +41 -117
  22. package/bundle/{chunk-224WMDIV.js → chunk-KCJFGKVK.js} +350 -123
  23. package/bundle/{chunk-RB4GELQA.js → chunk-LPJEKHOY.js} +1 -1
  24. package/bundle/chunk-LYKG4FKH.js +523 -0
  25. package/bundle/{chunk-X6LOM3Z4.js → chunk-LZ3HBDTR.js} +161 -78
  26. package/bundle/{chunk-FG6SQJAR.js → chunk-OGPOCGWX.js} +24 -6
  27. package/bundle/{chunk-BQ2OAB4Q.js → chunk-OSVXFWPG.js} +67 -30
  28. package/bundle/{chunk-FJWI64H7.js → chunk-RMSABUN3.js} +27 -13
  29. package/bundle/{chunk-H36HBZB2.js → chunk-SJPABBZG.js} +2 -2
  30. package/bundle/{chunk-3U633XDZ.js → chunk-U3ZDUUTM.js} +11 -3
  31. package/bundle/{chunk-LVWU2HOO.js → chunk-ULGMXABL.js} +16 -7
  32. package/bundle/{chunk-WPW4V6HM.js → chunk-W7ZA6TYD.js} +2 -2
  33. package/bundle/{chunk-V2KFIGFH.js → chunk-XAC2XNAP.js} +503 -304
  34. package/bundle/{chunk-O4D5PBVI.js → chunk-YWXILP5N.js} +3 -2
  35. package/bundle/control-channel.js +2 -2
  36. package/bundle/index.js +1 -1
  37. package/bundle/intercom-bridge.js +2 -2
  38. package/bundle/preflight.js +12 -10
  39. package/bundle/project-panes.js +3 -3
  40. package/bundle/workflow-resources.js +1 -1
  41. package/docs/agents.md +27 -6
  42. package/docs/configuration.md +20 -8
  43. package/docs/extension-api.md +18 -1
  44. package/docs/models.md +6 -2
  45. package/docs/observability.md +2 -0
  46. package/docs/tool-reference.md +7 -1
  47. package/docs/workflows.md +30 -2
  48. package/package.json +2 -2
  49. package/skills/pi-subagents/SKILL.md +15 -6
  50. package/skills/pi-subagents/references/prompting-and-roles.md +1 -0
  51. package/src/agents/agent-management.d.ts +1 -0
  52. package/src/agents/agent-management.js +46 -18
  53. package/src/agents/agent-memory.d.ts +1 -4
  54. package/src/agents/agent-memory.js +1 -4
  55. package/src/agents/agent-serializer.d.ts +2 -0
  56. package/src/agents/agent-serializer.js +1 -1
  57. package/src/agents/agents.d.ts +2 -3
  58. package/src/agents/agents.js +46 -20
  59. package/src/agents/frontmatter.js +1 -8
  60. package/src/agents/global-npm-root.d.ts +1 -0
  61. package/src/agents/global-npm-root.js +11 -3
  62. package/src/agents/skills.d.ts +0 -3
  63. package/src/agents/skills.js +0 -3
  64. package/src/api/preflight.d.ts +3 -1
  65. package/src/api/preflight.js +2 -0
  66. package/src/extension/config.d.ts +1 -0
  67. package/src/extension/config.js +13 -1
  68. package/src/extension/herdr-pi-bridge.js +10 -2
  69. package/src/extension/index.d.ts +0 -13
  70. package/src/extension/index.js +51 -37
  71. package/src/extension/public-execution.d.ts +1 -0
  72. package/src/extension/public-execution.js +4 -0
  73. package/src/extension/reply-workflow-script.js +24 -4
  74. package/src/extension/schemas.d.ts +12 -3
  75. package/src/extension/schemas.js +7 -3
  76. package/src/extension/session-switch.d.ts +25 -0
  77. package/src/extension/session-switch.js +138 -0
  78. package/src/extension/subagent-guide.d.ts +1 -1
  79. package/src/extension/subagent-guide.js +1 -1
  80. package/src/extension/subagent-launch-tool.d.ts +25 -0
  81. package/src/extension/subagent-launch-tool.js +48 -0
  82. package/src/extension/tool-activation.js +55 -15
  83. package/src/extension/tool-description.d.ts +1 -1
  84. package/src/extension/tool-description.js +14 -8
  85. package/src/inspectors/herdr/actions.d.ts +0 -1
  86. package/src/inspectors/herdr/actions.js +0 -1
  87. package/src/inspectors/session-roots-codec.d.ts +0 -1
  88. package/src/inspectors/session-roots-codec.js +0 -1
  89. package/src/inspectors/tmux/actions.d.ts +0 -1
  90. package/src/inspectors/tmux/actions.js +0 -1
  91. package/src/integrations/herdr-status.js +3 -8
  92. package/src/intercom/native-supervisor-channel.js +65 -9
  93. package/src/runs/background/async-execution.d.ts +7 -10
  94. package/src/runs/background/async-execution.js +66 -29
  95. package/src/runs/background/async-job-tracker.js +12 -0
  96. package/src/runs/background/async-resume.d.ts +2 -1
  97. package/src/runs/background/async-resume.js +114 -40
  98. package/src/runs/background/async-retention.d.ts +0 -2
  99. package/src/runs/background/async-retention.js +17 -6
  100. package/src/runs/background/async-status.d.ts +2 -0
  101. package/src/runs/background/async-status.js +4 -0
  102. package/src/runs/background/auto-drain.js +2 -1
  103. package/src/runs/background/boot-id.d.ts +1 -3
  104. package/src/runs/background/boot-id.js +1 -3
  105. package/src/runs/background/completion-batcher.d.ts +3 -4
  106. package/src/runs/background/completion-batcher.js +2 -3
  107. package/src/runs/background/control-channel.d.ts +0 -6
  108. package/src/runs/background/control-channel.js +0 -6
  109. package/src/runs/background/fleet-view.js +2 -3
  110. package/src/runs/background/notify.d.ts +0 -2
  111. package/src/runs/background/notify.js +0 -2
  112. package/src/runs/background/result-watcher.d.ts +1 -0
  113. package/src/runs/background/result-watcher.js +59 -29
  114. package/src/runs/background/resume-guidance.js +4 -2
  115. package/src/runs/background/retained-children.js +2 -1
  116. package/src/runs/background/run-child-session.d.ts +2 -3
  117. package/src/runs/background/run-child-session.js +5 -8
  118. package/src/runs/background/run-status.js +9 -7
  119. package/src/runs/background/runner-aliases.js +15 -0
  120. package/src/runs/background/scheduled-runs.d.ts +3 -1
  121. package/src/runs/background/scheduled-runs.js +13 -16
  122. package/src/runs/background/steering.d.ts +2 -11
  123. package/src/runs/background/steering.js +11 -6
  124. package/src/runs/background/subagent-runner.d.ts +2 -6
  125. package/src/runs/background/subagent-runner.js +88 -70
  126. package/src/runs/background/subagent-wait.js +12 -15
  127. package/src/runs/background/wait-config.d.ts +2 -0
  128. package/src/runs/background/wait-config.js +17 -3
  129. package/src/runs/background/wait-subscriptions.js +124 -12
  130. package/src/runs/background/wait-tool.js +4 -2
  131. package/src/runs/background/workflow-terminal-proof.d.ts +0 -1
  132. package/src/runs/background/workflow-terminal-proof.js +0 -1
  133. package/src/runs/foreground/async-steering-action.js +24 -9
  134. package/src/runs/foreground/async-stop-action.d.ts +1 -1
  135. package/src/runs/foreground/async-stop-action.js +9 -1
  136. package/src/runs/foreground/execution.d.ts +0 -3
  137. package/src/runs/foreground/execution.js +56 -24
  138. package/src/runs/foreground/prompt-audit.js +1 -0
  139. package/src/runs/foreground/subagent-executor.d.ts +5 -10
  140. package/src/runs/foreground/subagent-executor.js +164 -49
  141. package/src/runs/shared/acceptance.js +69 -26
  142. package/src/runs/shared/async-status-projection.d.ts +2 -0
  143. package/src/runs/shared/async-status-projection.js +10 -0
  144. package/src/runs/shared/child-commands.js +15 -2
  145. package/src/runs/shared/child-hooks.d.ts +1 -7
  146. package/src/runs/shared/child-hooks.js +13 -5
  147. package/src/runs/shared/child-launch.js +6 -2
  148. package/src/runs/shared/child-runtime-config.d.ts +0 -1
  149. package/src/runs/shared/child-session.d.ts +6 -5
  150. package/src/runs/shared/child-session.js +85 -38
  151. package/src/runs/shared/child-tool-plan.d.ts +0 -1
  152. package/src/runs/shared/child-tool-plan.js +0 -1
  153. package/src/runs/shared/claude-code-adapter.js +11 -0
  154. package/src/runs/shared/external-cli-contract.d.ts +49 -0
  155. package/src/runs/shared/external-cli-contract.js +18 -13
  156. package/src/runs/shared/external-cli-runner.js +26 -6
  157. package/src/runs/shared/herdr-connection.js +2 -1
  158. package/src/runs/shared/herdr-pane-host.d.ts +2 -2
  159. package/src/runs/shared/herdr-pane-host.js +17 -1
  160. package/src/runs/shared/herdr-placed-run.js +51 -24
  161. package/src/runs/shared/lane-metadata.d.ts +0 -1
  162. package/src/runs/shared/lane-metadata.js +0 -1
  163. package/src/runs/shared/mcp-config-sources.d.ts +4 -1
  164. package/src/runs/shared/mcp-config-sources.js +1 -1
  165. package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +0 -3
  166. package/src/runs/shared/mcp-direct-tool-allowlist.js +26 -17
  167. package/src/runs/shared/mcp-direct-tool-grant.js +8 -1
  168. package/src/runs/shared/model-resolution-diagnostic.d.ts +0 -1
  169. package/src/runs/shared/model-resolution.d.ts +20 -5
  170. package/src/runs/shared/model-resolution.js +55 -50
  171. package/src/runs/shared/model-scope.d.ts +1 -5
  172. package/src/runs/shared/model-scope.js +1 -5
  173. package/src/runs/shared/mutation-evidence.d.ts +1 -1
  174. package/src/runs/shared/mutation-evidence.js +52 -7
  175. package/src/runs/shared/nested-events.d.ts +1 -0
  176. package/src/runs/shared/nested-events.js +1 -1
  177. package/src/runs/shared/parallel-utils.d.ts +0 -1
  178. package/src/runs/shared/permissions.js +5 -3
  179. package/src/runs/shared/placement-host.d.ts +5 -1
  180. package/src/runs/shared/rex-pane-host.d.ts +0 -1
  181. package/src/runs/shared/rex-pane-host.js +0 -2
  182. package/src/runs/shared/run-launch-folder.d.ts +12 -0
  183. package/src/runs/shared/run-launch-folder.js +21 -0
  184. package/src/runs/shared/runner-launcher.d.ts +12 -1
  185. package/src/runs/shared/runner-launcher.js +16 -0
  186. package/src/runs/shared/single-output.d.ts +3 -3
  187. package/src/runs/shared/single-output.js +5 -3
  188. package/src/runs/shared/structured-output.d.ts +8 -0
  189. package/src/runs/shared/structured-output.js +40 -5
  190. package/src/runs/shared/subagent-prompt-runtime.d.ts +0 -1
  191. package/src/runs/shared/subagent-prompt-runtime.js +18 -4
  192. package/src/runs/shared/supervisor-wait-timer.d.ts +16 -0
  193. package/src/runs/shared/supervisor-wait-timer.js +61 -0
  194. package/src/runs/shared/tool-timeout.js +2 -1
  195. package/src/runs/shared/worktree-cleanup-plan.d.ts +0 -1
  196. package/src/runs/shared/worktree-cleanup-plan.js +0 -1
  197. package/src/runs/shared/worktree.d.ts +3 -0
  198. package/src/runs/shared/worktree.js +20 -0
  199. package/src/shared/artifacts.d.ts +1 -0
  200. package/src/shared/artifacts.js +132 -22
  201. package/src/shared/capacity-resilient-json.d.ts +1 -1
  202. package/src/shared/child-cache-retention.d.ts +1 -2
  203. package/src/shared/child-cache-retention.js +1 -2
  204. package/src/shared/fleet-transcript-reader.d.ts +51 -0
  205. package/src/shared/fleet-transcript-reader.js +333 -0
  206. package/src/shared/formatters.d.ts +0 -18
  207. package/src/shared/formatters.js +0 -18
  208. package/src/shared/pruned-fork.js +2 -2
  209. package/src/shared/reported-progress.d.ts +1 -0
  210. package/src/shared/reported-progress.js +12 -0
  211. package/src/shared/session-succession.d.ts +16 -1
  212. package/src/shared/session-succession.js +41 -2
  213. package/src/shared/session-warnings.d.ts +7 -0
  214. package/src/shared/session-warnings.js +26 -0
  215. package/src/shared/settings.d.ts +0 -23
  216. package/src/shared/settings.js +3 -35
  217. package/src/shared/status-format.d.ts +1 -0
  218. package/src/shared/status-format.js +1 -1
  219. package/src/shared/types.d.ts +108 -59
  220. package/src/shared/types.js +0 -12
  221. package/src/shared/utils.d.ts +3 -15
  222. package/src/shared/utils.js +4 -22
  223. package/src/shared/wait-tool-name.d.ts +8 -0
  224. package/src/shared/wait-tool-name.js +13 -0
  225. package/src/slash/slash-commands.js +2 -1
  226. package/src/slash/subagent-cost.d.ts +3 -2
  227. package/src/slash/subagent-cost.js +22 -3
  228. package/src/slash/subagents-admin.js +0 -1
  229. package/src/tui/fleet-status.d.ts +0 -5
  230. package/src/tui/fleet-status.js +4 -24
  231. package/src/tui/fleet.js +6 -4
  232. package/src/tui/render.d.ts +0 -9
  233. package/src/tui/render.js +194 -68
  234. package/src/tui/subagent-messages.js +3 -2
  235. package/src/watchdog/model-selection.js +2 -2
  236. package/src/watchdog/permission-arbiter.js +1 -0
  237. package/src/watchdog/register-child.d.ts +2 -3
  238. package/src/watchdog/register-child.js +2 -3
  239. package/src/watchdog/review.d.ts +0 -5
  240. package/src/watchdog/review.js +4 -3
  241. package/src/watchdog/turn-delta.js +2 -1
  242. package/src/workflows/scripted-workflow.d.ts +2 -0
  243. package/src/workflows/scripted-workflow.js +344 -59
  244. package/src/workflows/structured-workflow-scripts.d.ts +4 -3
  245. package/src/workflows/structured-workflow-scripts.js +32 -11
  246. package/src/workflows/workflow-launch-record.d.ts +15 -6
  247. package/src/workflows/workflow-launch-record.js +30 -12
  248. package/src/workflows/workflow-receipt.js +36 -53
  249. package/src/workflows/workflow-resources.js +4 -4
  250. package/src/workflows/workflow-resume-claim.d.ts +2 -0
  251. package/src/workflows/workflow-resume-claim.js +3 -3
  252. package/src/workflows/workflow-resume.d.ts +1 -1
  253. package/src/workflows/workflow-resume.js +13 -8
  254. package/src/workflows/workflow-script-worker.d.ts +13 -0
  255. package/src/workflows/workflow-script-worker.js +81 -0
  256. package/workflow-script-process.cjs +36 -0
  257. package/workflow-script-worker.cjs +4 -1
  258. package/bundle/chunk-U4ODUYAG.js +0 -235
@@ -119,9 +119,6 @@ function isNotFoundError(error) {
119
119
  && "code" in error
120
120
  && error.code === "ENOENT";
121
121
  }
122
- /**
123
- * Read async job status from disk (with mtime-based caching)
124
- */
125
122
  export function readStatus(asyncDir) {
126
123
  if (Buffer.byteLength(path.basename(asyncDir), "utf-8") > 255) {
127
124
  return null;
@@ -291,9 +288,10 @@ export function getFinalOutput(messages) {
291
288
  export function getSingleResultOutput(result) {
292
289
  return result.finalOutput ?? getFinalOutput(result.messages ?? []);
293
290
  }
294
- /**
295
- * Extract display items (text and tool calls) from messages
296
- */
291
+ export const TRUNCATED_RESPONSE_ERROR = "Response was truncated: the model reached its maximum output length.";
292
+ export function getTerminalAssistantStopReason(messages) {
293
+ return messages.findLast((message) => message.role === "assistant")?.stopReason;
294
+ }
297
295
  export function getDisplayItems(messages) {
298
296
  if (!messages || messages.length === 0)
299
297
  return [];
@@ -387,7 +385,6 @@ function addNestedCost(total, children) {
387
385
  addNestedCost(total, step.children);
388
386
  }
389
387
  }
390
- /** Sum input tokens, output tokens, and cost across a set of SingleResults. */
391
388
  export function sumResultsCost(results) {
392
389
  const total = { inputTokens: 0, outputTokens: 0, costUsd: 0 };
393
390
  for (const result of results) {
@@ -435,7 +432,6 @@ export function compactForegroundDetails(details) {
435
432
  export const MAX_STREAMED_RECENT_TOOLS = 32;
436
433
  export const MAX_STREAMED_TOOL_CALLS = 64;
437
434
  export const MAX_STREAMED_OUTPUT_LINE_CHARS = 2000;
438
- /** Keep only the most recent tool-history entries in a streamed snapshot. */
439
435
  export function boundStreamedRecentTools(recentTools) {
440
436
  return recentTools.slice(-MAX_STREAMED_RECENT_TOOLS).map((tool) => ({ ...tool }));
441
437
  }
@@ -519,9 +515,6 @@ export function detectSubagentError(messages) {
519
515
  }
520
516
  return { hasError: false };
521
517
  }
522
- /**
523
- * Extract a preview of tool arguments for display
524
- */
525
518
  export function extractToolArgsPreview(args) {
526
519
  const stringifyPreviewValue = (value) => {
527
520
  if (typeof value === "string" && value.trim().length > 0)
@@ -573,32 +566,24 @@ export function extractToolArgsPreview(args) {
573
566
  }
574
567
  return "";
575
568
  }
576
- /**
577
- * Extract text content from various message content formats
578
- */
579
569
  export function extractTextFromContent(content) {
580
570
  if (!content)
581
571
  return "";
582
- // Handle string content directly
583
572
  if (typeof content === "string")
584
573
  return content;
585
- // Handle array content
586
574
  if (!Array.isArray(content))
587
575
  return "";
588
576
  const texts = [];
589
577
  for (const part of content) {
590
578
  if (part && typeof part === "object") {
591
- // Handle { type: "text", text: "..." }
592
579
  if ("type" in part && part.type === "text" && "text" in part) {
593
580
  texts.push(String(part.text));
594
581
  }
595
- // Handle { type: "tool_result", content: "..." }
596
582
  else if ("type" in part && part.type === "tool_result" && "content" in part) {
597
583
  const inner = extractTextFromContent(part.content);
598
584
  if (inner)
599
585
  texts.push(inner);
600
586
  }
601
- // Handle { text: "..." } without type
602
587
  else if ("text" in part) {
603
588
  texts.push(String(part.text));
604
589
  }
@@ -606,7 +591,4 @@ export function extractTextFromContent(content) {
606
591
  }
607
592
  return texts.join("\n");
608
593
  }
609
- // ============================================================================
610
- // Concurrency Utilities
611
- // ============================================================================
612
594
  export { mapConcurrent } from "../runs/shared/parallel-utils.js";
@@ -0,0 +1,8 @@
1
+ export declare const DEFAULT_WAIT_TOOL_NAME = "bg_wait";
2
+ /**
3
+ * The name pi-subagents registers its wait tool under (`config.waitTool.name`). One value per process: the parent
4
+ * sets it from config, a child runtime from its launch config, and an async runner from its runner config, because
5
+ * every runtime in a process descends from the same parent setting.
6
+ */
7
+ export declare function waitToolName(): string;
8
+ export declare function setWaitToolName(name: string): void;
@@ -0,0 +1,13 @@
1
+ export const DEFAULT_WAIT_TOOL_NAME = "bg_wait";
2
+ let current = DEFAULT_WAIT_TOOL_NAME;
3
+ /**
4
+ * The name pi-subagents registers its wait tool under (`config.waitTool.name`). One value per process: the parent
5
+ * sets it from config, a child runtime from its launch config, and an async runner from its runner config, because
6
+ * every runtime in a process descends from the same parent setting.
7
+ */
8
+ export function waitToolName() {
9
+ return current;
10
+ }
11
+ export function setWaitToolName(name) {
12
+ current = name;
13
+ }
@@ -22,6 +22,7 @@ import { SUBAGENT_GUIDE_TOPICS } from "../extension/subagent-guide.js";
22
22
  import { getInspectorPlugins } from "../inspectors/plugins.js";
23
23
  import { applySlashUpdate, buildSlashInitialResult, failSlashResult, finalizeSlashResult, } from "./slash-live-state.js";
24
24
  import { SLASH_RESULT_TYPE, SLASH_TEXT_RESULT_TYPE, SLASH_TEXT_VIEW_ONLY_DETAILS, SLASH_SUBAGENT_CANCEL_EVENT, SLASH_SUBAGENT_REQUEST_EVENT, SLASH_SUBAGENT_RESPONSE_EVENT, SLASH_SUBAGENT_STARTED_EVENT, SLASH_SUBAGENT_UPDATE_EVENT, DIRS, } from "../shared/types.js";
25
+ import { waitToolName } from "../shared/wait-tool-name.js";
25
26
  const parseInlineConfig = (raw) => {
26
27
  const config = {};
27
28
  for (const part of raw.split(",")) {
@@ -729,7 +730,7 @@ export function registerSlashCommands(pi, state, options = {}) {
729
730
  ctx.ui.notify(`Foreground run ${control.runId} is not currently detachable.`, "info");
730
731
  return;
731
732
  }
732
- sendSlashText(pi, `Detached foreground run ${control.runId} without terminating its child. Use subagent({ action: "status", id: ${JSON.stringify(control.runId)} }) or bg_wait({ id: ${JSON.stringify(control.runId)} }) to recover the eventual result. This does not daemonize the process or guarantee survival across Pi reload/restart.`);
733
+ sendSlashText(pi, `Detached foreground run ${control.runId} without terminating its child. Use subagent({ action: "status", id: ${JSON.stringify(control.runId)} }) or ${waitToolName()}({ id: ${JSON.stringify(control.runId)} }) to recover the eventual result. This does not daemonize the process or guarantee survival across Pi reload/restart.`);
733
734
  };
734
735
  pi.registerCommand("subagents-detach", {
735
736
  description: "Detach the active foreground single-subagent run without terminating it",
@@ -21,8 +21,9 @@ export declare const SUBAGENT_COST_REPORT_VERSION: 1;
21
21
  /**
22
22
  * Collect parent and child usage for the current session branch. Foreground
23
23
  * children come from persisted `subagent`/`bg_wait` tool-result details; async
24
- * workflow children are resolved through receipts, and other async runs through
25
- * their status steps, then artifact metadata.
24
+ * runs come from those results and `subagent-notify` completions. Async workflow
25
+ * children are resolved through receipts, and other async runs through their
26
+ * status steps, then artifact metadata.
26
27
  */
27
28
  export declare function collectSubagentCost(ctx: ExtensionContext, state: Pick<SubagentState, "baseCwd" | "artifactDirPreference">): SubagentCostReport;
28
29
  /** The `/subagent-cost` text rendering of a collected report. */
@@ -6,6 +6,7 @@ import { DIRS, SLASH_RESULT_TYPE } from "../shared/types.js";
6
6
  import { readStatus } from "../shared/utils.js";
7
7
  import { readWorkflowReceipt } from "../workflows/workflow-receipt.js";
8
8
  import { resolveSlashMessageDetails } from "./slash-live-state.js";
9
+ import { DEFAULT_WAIT_TOOL_NAME, waitToolName } from "../shared/wait-tool-name.js";
9
10
  export const SUBAGENT_COST_REPORT_VERSION = 1;
10
11
  function emptyUsage() {
11
12
  return { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, turns: 0 };
@@ -95,10 +96,25 @@ function detailsFromSessionEntry(entry) {
95
96
  if (record.type !== "message" || !record.message || typeof record.message !== "object")
96
97
  return undefined;
97
98
  const message = record.message;
98
- if (message.role !== "toolResult" || (message.toolName !== "subagent" && message.toolName !== "bg_wait"))
99
+ // Results saved before a waitTool.name rename carry bg_wait; another extension's bg_wait results fail isSubagentDetails.
100
+ if (message.role !== "toolResult" || (message.toolName !== "subagent" && message.toolName !== waitToolName() && message.toolName !== DEFAULT_WAIT_TOOL_NAME))
99
101
  return undefined;
100
102
  return isSubagentDetails(message.details) ? message.details : undefined;
101
103
  }
104
+ /** Background runs a `subagent-notify` completion reports; an RPC `spawn` launch has no tool result, so this is its only record. */
105
+ function notifiedAsyncRuns(entry) {
106
+ if (!entry || typeof entry !== "object")
107
+ return [];
108
+ const record = entry;
109
+ if (record.type !== "custom_message" || record.customType !== "subagent-notify")
110
+ return [];
111
+ const runs = record.details?.runs;
112
+ if (!Array.isArray(runs))
113
+ return [];
114
+ return runs.flatMap((run) =>
115
+ // A detached foreground task keeps no async status directory to read usage from.
116
+ run && typeof run.runId === "string" && run.source !== "foreground" ? [{ runId: run.runId, workflow: run.workflowRunId === run.runId }] : []);
117
+ }
102
118
  function metadataUsage(artifactsDirs, input, indexes = [0, undefined]) {
103
119
  if (!/^[A-Za-z0-9._-]+$/.test(input.runId))
104
120
  return undefined;
@@ -126,8 +142,9 @@ function metadataUsage(artifactsDirs, input, indexes = [0, undefined]) {
126
142
  /**
127
143
  * Collect parent and child usage for the current session branch. Foreground
128
144
  * children come from persisted `subagent`/`bg_wait` tool-result details; async
129
- * workflow children are resolved through receipts, and other async runs through
130
- * their status steps, then artifact metadata.
145
+ * runs come from those results and `subagent-notify` completions. Async workflow
146
+ * children are resolved through receipts, and other async runs through their
147
+ * status steps, then artifact metadata.
131
148
  */
132
149
  export function collectSubagentCost(ctx, state) {
133
150
  const parent = emptyUsage();
@@ -163,6 +180,8 @@ export function collectSubagentCost(ctx, state) {
163
180
  const parentUsage = assistantUsageFromMessage(message) ?? compactionUsageFromEntry(entry);
164
181
  if (parentUsage)
165
182
  addUsage(parent, parentUsage);
183
+ for (const run of notifiedAsyncRuns(entry))
184
+ (run.workflow ? workflowRunIds : asyncRunIds).add(run.runId);
166
185
  const details = detailsFromSessionEntry(entry);
167
186
  if (!details)
168
187
  continue;
@@ -469,7 +469,6 @@ async function runAdminFlow(pi, ctx, args = "") {
469
469
  sendAdminMessage(pi, message);
470
470
  }
471
471
  else if (action === "Show details") {
472
- // Full metadata is now opt-in (previously always posted to the thread).
473
472
  sendAdminMessage(pi, metadataFor(agent));
474
473
  }
475
474
  }
@@ -34,11 +34,6 @@ export interface FleetStatusOptions {
34
34
  export declare function resolveFleetViewPlacement(value: unknown): FleetViewPlacement;
35
35
  export declare function formatFleetElapsed(ms: number): string;
36
36
  export declare function formatFleetTokens(count: number, window?: number, windowCount?: number): string;
37
- /**
38
- * Reports a Fleet problem once per process. Fleet refreshes on a timer, and console output while the TUI owns
39
- * the terminal is drawn over the editor, so an interactive session gets one TUI warning instead.
40
- */
41
- export declare function reportFleetWarning(state: SubagentState, message: string): void;
42
37
  export declare function collectFleetStatusEntries(state: SubagentState): FleetStatusEntry[];
43
38
  export declare class SubagentFleetStatus {
44
39
  private ctx;
@@ -5,7 +5,8 @@ import { projectAsyncWorkflowRows } from "../runs/shared/async-status-projection
5
5
  import { contextModeLabel } from "../runs/shared/context-mode.js";
6
6
  import { formatWorkflowJsonPreview } from "../workflows/scripted-workflow.js";
7
7
  import { hostStepReportName, hostStepVerdictLabel } from "../runs/shared/host-step-status.js";
8
- import { isStaleExtensionContextError, withCachedUiContext } from "../shared/extension-context.js";
8
+ import { isStaleExtensionContextError } from "../shared/extension-context.js";
9
+ import { reportSessionWarning } from "../shared/session-warnings.js";
9
10
  import { inlineWorkflowRenderKey } from "./render.js";
10
11
  import { runningTone } from "./running-tone.js";
11
12
  import { childThinkingLevel } from "../shared/model-info.js";
@@ -318,27 +319,6 @@ function projectPaneEntries(state) {
318
319
  projectPane: pane,
319
320
  }));
320
321
  }
321
- const reportedFleetWarnings = new Set();
322
- /**
323
- * Reports a Fleet problem once per process. Fleet refreshes on a timer, and console output while the TUI owns
324
- * the terminal is drawn over the editor, so an interactive session gets one TUI warning instead.
325
- */
326
- export function reportFleetWarning(state, message) {
327
- if (reportedFleetWarnings.has(message))
328
- return;
329
- reportedFleetWarnings.add(message);
330
- const text = `[pi-subagents] ${message}`;
331
- const cached = state.lastUiContext;
332
- const notified = withCachedUiContext(cached, () => {
333
- if (state.lastUiContext === cached)
334
- state.lastUiContext = null;
335
- }, (ctx) => {
336
- ctx.ui.notify(text, "warning");
337
- return true;
338
- });
339
- if (!notified)
340
- console.warn(text);
341
- }
342
322
  export function collectFleetStatusEntries(state) {
343
323
  const now = Date.now();
344
324
  const entries = [];
@@ -486,7 +466,7 @@ export function collectFleetStatusEntries(state) {
486
466
  }
487
467
  if (state.currentSessionId) {
488
468
  try {
489
- for (const run of snapshotExternalRuns(state.currentSessionId, { ignoreMalformed: true, onMalformedRecord: (message) => reportFleetWarning(state, `Removed ${message}`) })) {
469
+ for (const run of snapshotExternalRuns(state.currentSessionId, { ignoreMalformed: true, onMalformedRecord: (message) => reportSessionWarning(state, `Removed ${message}`) })) {
490
470
  if (!isActiveState(run.state))
491
471
  continue;
492
472
  entries.push({
@@ -501,7 +481,7 @@ export function collectFleetStatusEntries(state) {
501
481
  }
502
482
  }
503
483
  catch (cause) {
504
- reportFleetWarning(state, `Failed to inspect external jobs: ${cause instanceof Error ? cause.message : String(cause)}`);
484
+ reportSessionWarning(state, `Failed to inspect external jobs: ${cause instanceof Error ? cause.message : String(cause)}`);
505
485
  }
506
486
  }
507
487
  entries.push(...projectPaneEntries(state));
package/src/tui/fleet.js CHANGED
@@ -19,9 +19,11 @@ import { stopAsyncRun } from "../runs/foreground/async-stop-action.js";
19
19
  import { resolveWorkflowForegroundSteeringTarget, steerWorkflowForegroundTarget } from "../runs/foreground/workflow-foreground-steering.js";
20
20
  import { contextModeBadge, contextModeLabel } from "../runs/shared/context-mode.js";
21
21
  import { foregroundChildStateLabel } from "../runs/foreground/foreground-history.js";
22
- import { FLEET_STATUS_WIDGET_KEY, reportFleetWarning } from "./fleet-status.js";
22
+ import { FLEET_STATUS_WIDGET_KEY } from "./fleet-status.js";
23
+ import { reportSessionWarning } from "../shared/session-warnings.js";
23
24
  import { stepTaskSummary } from "./render.js";
24
- import { readFleetTranscript, renderFleetTranscript } from "./fleet-transcript.js";
25
+ import { renderFleetTranscript } from "./fleet-transcript.js";
26
+ import { readFleetTranscript } from "../shared/fleet-transcript-reader.js";
25
27
  import { buildNativeFleetTranscript, loadNativeTranscriptSupport } from "./fleet-native-transcript.js";
26
28
  import { runningTone } from "./running-tone.js";
27
29
  import { childThinkingLevel } from "../shared/model-info.js";
@@ -228,7 +230,7 @@ export function collectFleetSnapshot(state, options = {}) {
228
230
  entryLimit: MAX_FLEET_HISTORY_CANDIDATES,
229
231
  resultsDir: options.resultsDir ?? DIRS.results,
230
232
  reconcile: false,
231
- onCorruptStatus: (warning) => reportFleetWarning(state, warning),
233
+ onCorruptStatus: (warning) => reportSessionWarning(state, warning),
232
234
  }).filter((run) => !trackedIds.has(run.id));
233
235
  runs = [...trackedRuns, ...history];
234
236
  }
@@ -244,7 +246,7 @@ export function collectFleetSnapshot(state, options = {}) {
244
246
  }
245
247
  if (state.currentSessionId) {
246
248
  try {
247
- for (const run of snapshotExternalRuns(state.currentSessionId, { ignoreMalformed: true, onMalformedRecord: (message) => reportFleetWarning(state, `Removed ${message}`) })) {
249
+ for (const run of snapshotExternalRuns(state.currentSessionId, { ignoreMalformed: true, onMalformedRecord: (message) => reportSessionWarning(state, `Removed ${message}`) })) {
248
250
  items.push({
249
251
  key: `external:${run.id}`,
250
252
  kind: "external",
@@ -1,6 +1,3 @@
1
- /**
2
- * Rendering functions for subagent results
3
- */
4
1
  import type { AgentToolResult } from "@earendil-works/pi-agent-core";
5
2
  import { type ExtensionContext } from "@earendil-works/pi-coding-agent";
6
3
  import { type Component } from "@earendil-works/pi-tui";
@@ -50,16 +47,10 @@ export declare function inlineWorkflowRenderKey(job: AsyncJobState, children: As
50
47
  /** Presentation-only coverage from the mounted inline Fleet roster, never configuration. */
51
48
  export declare function setInlineWorkflowCoverage(ui: ExtensionContext["ui"], coverage: ReadonlyMap<string, string>): void;
52
49
  export declare function buildWidgetLines(jobs: AsyncJobState[], theme: Theme, width?: number, expanded?: boolean, frame?: number): string[];
53
- /**
54
- * Render the async jobs widget
55
- */
56
50
  export declare function renderWidget(ctx: ExtensionContext, jobs: AsyncJobState[], initiallyCollapsed?: boolean, layout?: AsyncWidgetLayout): void;
57
51
  export declare function renderSubagentSummary(result: AgentToolResult<Details>, options: {
58
52
  isPartial?: boolean;
59
53
  }, theme: Theme): Component;
60
- /**
61
- * Render a subagent result
62
- */
63
54
  export declare function renderSubagentResult(result: AgentToolResult<Details>, options: {
64
55
  expanded: boolean;
65
56
  }, theme: Theme, frame?: number, rendererConfig?: MainWindowRendererConfig, foregroundDetachShortcut?: string): Component;