@xzzpig/pi-subagents 0.24.2 → 0.25.1

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 (263) hide show
  1. package/CHANGELOG.md +37 -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-EUPJB4S7.js → chunk-5Z7JAORM.js} +196 -1219
  8. package/bundle/{chunk-LCDJWBVM.js → chunk-66JNFRFS.js} +1 -1
  9. package/bundle/{chunk-ED55MIC2.js → chunk-CGFF4WA3.js} +42 -19
  10. package/bundle/{chunk-TMHVDPYW.js → chunk-DLVPMML3.js} +263 -154
  11. package/bundle/{chunk-RU522D5W.js → chunk-FQPV4O6C.js} +183 -28
  12. package/bundle/chunk-HXRB42AF.js +108 -0
  13. package/bundle/{chunk-355ECEP2.js → chunk-IH7LQVEE.js} +29 -14
  14. package/bundle/{chunk-Z6TFJ6BR.js → chunk-INWSUNI6.js} +1 -1
  15. package/bundle/{chunk-CYY5UMJU.js → chunk-IXCEOEJT.js} +411 -249
  16. package/bundle/{chunk-WW76JRIX.js → chunk-JAXVBXGF.js} +1 -1
  17. package/bundle/{chunk-ICNYIALB.js → chunk-JH5H4CYJ.js} +784 -474
  18. package/bundle/{chunk-224WMDIV.js → chunk-JUYNN63E.js} +350 -123
  19. package/bundle/{chunk-35GII5EF.js → chunk-JWFLPSTP.js} +41 -117
  20. package/bundle/{chunk-XWWUDWUW.js → chunk-KRNBJPZ2.js} +670 -400
  21. package/bundle/{chunk-RB4GELQA.js → chunk-LPJEKHOY.js} +1 -1
  22. package/bundle/chunk-LYKG4FKH.js +523 -0
  23. package/bundle/{chunk-X6LOM3Z4.js → chunk-LZ3HBDTR.js} +161 -78
  24. package/bundle/{chunk-JEA2ZKUA.js → chunk-MMJQMPOK.js} +37 -165
  25. package/bundle/{chunk-FG6SQJAR.js → chunk-OGPOCGWX.js} +24 -6
  26. package/bundle/{chunk-FJWI64H7.js → chunk-RMSABUN3.js} +27 -13
  27. package/bundle/{chunk-H36HBZB2.js → chunk-SJPABBZG.js} +2 -2
  28. package/bundle/{chunk-4UH4WS4G.js → chunk-SNDCIJMK.js} +23 -12
  29. package/bundle/{chunk-O4D5PBVI.js → chunk-TM2K53NX.js} +3 -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-BQ2OAB4Q.js → chunk-WWDUNXSE.js} +67 -30
  34. package/bundle/{chunk-V2KFIGFH.js → chunk-XAC2XNAP.js} +503 -304
  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 +68 -84
  138. package/src/runs/foreground/fork-tool-result-handler.d.ts +60 -0
  139. package/src/runs/foreground/fork-tool-result-handler.js +83 -0
  140. package/src/runs/foreground/prompt-audit.js +1 -0
  141. package/src/runs/foreground/subagent-executor.d.ts +5 -10
  142. package/src/runs/foreground/subagent-executor.js +164 -49
  143. package/src/runs/shared/acceptance.js +69 -26
  144. package/src/runs/shared/async-status-projection.d.ts +2 -0
  145. package/src/runs/shared/async-status-projection.js +10 -0
  146. package/src/runs/shared/child-commands.js +15 -2
  147. package/src/runs/shared/child-hooks.d.ts +1 -7
  148. package/src/runs/shared/child-hooks.js +13 -5
  149. package/src/runs/shared/child-launch.js +6 -2
  150. package/src/runs/shared/child-runtime-config.d.ts +0 -1
  151. package/src/runs/shared/child-session.d.ts +6 -5
  152. package/src/runs/shared/child-session.js +85 -38
  153. package/src/runs/shared/child-tool-plan.d.ts +0 -1
  154. package/src/runs/shared/child-tool-plan.js +0 -1
  155. package/src/runs/shared/claude-code-adapter.js +11 -0
  156. package/src/runs/shared/external-cli-contract.d.ts +49 -0
  157. package/src/runs/shared/external-cli-contract.js +18 -13
  158. package/src/runs/shared/external-cli-runner.js +26 -6
  159. package/src/runs/shared/herdr-connection.js +2 -1
  160. package/src/runs/shared/herdr-pane-host.d.ts +2 -2
  161. package/src/runs/shared/herdr-pane-host.js +17 -1
  162. package/src/runs/shared/herdr-placed-run.js +51 -24
  163. package/src/runs/shared/lane-metadata.d.ts +0 -1
  164. package/src/runs/shared/lane-metadata.js +0 -1
  165. package/src/runs/shared/mcp-config-sources.d.ts +4 -1
  166. package/src/runs/shared/mcp-config-sources.js +1 -1
  167. package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +0 -3
  168. package/src/runs/shared/mcp-direct-tool-allowlist.js +26 -17
  169. package/src/runs/shared/mcp-direct-tool-grant.js +8 -1
  170. package/src/runs/shared/model-resolution-diagnostic.d.ts +0 -1
  171. package/src/runs/shared/model-resolution.d.ts +20 -5
  172. package/src/runs/shared/model-resolution.js +55 -50
  173. package/src/runs/shared/model-scope.d.ts +1 -5
  174. package/src/runs/shared/model-scope.js +1 -5
  175. package/src/runs/shared/mutation-evidence.d.ts +1 -1
  176. package/src/runs/shared/mutation-evidence.js +52 -7
  177. package/src/runs/shared/nested-events.d.ts +1 -0
  178. package/src/runs/shared/nested-events.js +1 -1
  179. package/src/runs/shared/parallel-utils.d.ts +0 -1
  180. package/src/runs/shared/permissions.js +5 -3
  181. package/src/runs/shared/placement-host.d.ts +5 -1
  182. package/src/runs/shared/rex-pane-host.d.ts +0 -1
  183. package/src/runs/shared/rex-pane-host.js +0 -2
  184. package/src/runs/shared/run-launch-folder.d.ts +12 -0
  185. package/src/runs/shared/run-launch-folder.js +21 -0
  186. package/src/runs/shared/runner-launcher.d.ts +12 -1
  187. package/src/runs/shared/runner-launcher.js +16 -0
  188. package/src/runs/shared/single-output.d.ts +3 -3
  189. package/src/runs/shared/single-output.js +5 -3
  190. package/src/runs/shared/structured-output.d.ts +8 -0
  191. package/src/runs/shared/structured-output.js +40 -5
  192. package/src/runs/shared/subagent-prompt-runtime.d.ts +0 -1
  193. package/src/runs/shared/subagent-prompt-runtime.js +18 -4
  194. package/src/runs/shared/supervisor-wait-timer.d.ts +16 -0
  195. package/src/runs/shared/supervisor-wait-timer.js +61 -0
  196. package/src/runs/shared/tool-timeout.js +2 -1
  197. package/src/runs/shared/worktree-cleanup-plan.d.ts +0 -1
  198. package/src/runs/shared/worktree-cleanup-plan.js +0 -1
  199. package/src/runs/shared/worktree.d.ts +3 -0
  200. package/src/runs/shared/worktree.js +20 -0
  201. package/src/shared/artifacts.d.ts +1 -0
  202. package/src/shared/artifacts.js +132 -22
  203. package/src/shared/capacity-resilient-json.d.ts +1 -1
  204. package/src/shared/child-cache-retention.d.ts +1 -2
  205. package/src/shared/child-cache-retention.js +1 -2
  206. package/src/shared/fleet-transcript-reader.d.ts +64 -0
  207. package/src/shared/fleet-transcript-reader.js +376 -0
  208. package/src/shared/formatters.d.ts +0 -18
  209. package/src/shared/formatters.js +0 -18
  210. package/src/shared/pruned-fork.js +2 -2
  211. package/src/shared/reported-progress.d.ts +1 -0
  212. package/src/shared/reported-progress.js +12 -0
  213. package/src/shared/session-succession.d.ts +16 -1
  214. package/src/shared/session-succession.js +41 -2
  215. package/src/shared/session-warnings.d.ts +7 -0
  216. package/src/shared/session-warnings.js +26 -0
  217. package/src/shared/settings.d.ts +0 -23
  218. package/src/shared/settings.js +3 -35
  219. package/src/shared/status-format.d.ts +1 -0
  220. package/src/shared/status-format.js +1 -1
  221. package/src/shared/types.d.ts +108 -59
  222. package/src/shared/types.js +0 -12
  223. package/src/shared/utils.d.ts +3 -15
  224. package/src/shared/utils.js +4 -22
  225. package/src/shared/wait-tool-name.d.ts +8 -0
  226. package/src/shared/wait-tool-name.js +13 -0
  227. package/src/slash/slash-commands.js +2 -1
  228. package/src/slash/subagent-cost.d.ts +3 -2
  229. package/src/slash/subagent-cost.js +22 -3
  230. package/src/slash/subagents-admin.js +0 -1
  231. package/src/tui/fleet-native-transcript.js +1 -1
  232. package/src/tui/fleet-status.d.ts +0 -5
  233. package/src/tui/fleet-status.js +4 -24
  234. package/src/tui/fleet-transcript.d.ts +1 -57
  235. package/src/tui/fleet-transcript.js +4 -370
  236. package/src/tui/fleet.js +6 -4
  237. package/src/tui/render.d.ts +0 -9
  238. package/src/tui/render.js +194 -68
  239. package/src/tui/subagent-messages.js +3 -2
  240. package/src/watchdog/model-selection.js +2 -2
  241. package/src/watchdog/permission-arbiter.js +1 -0
  242. package/src/watchdog/register-child.d.ts +2 -3
  243. package/src/watchdog/register-child.js +2 -3
  244. package/src/watchdog/review.d.ts +0 -5
  245. package/src/watchdog/review.js +4 -3
  246. package/src/watchdog/turn-delta.js +2 -1
  247. package/src/workflows/scripted-workflow.d.ts +2 -0
  248. package/src/workflows/scripted-workflow.js +344 -59
  249. package/src/workflows/structured-workflow-scripts.d.ts +4 -3
  250. package/src/workflows/structured-workflow-scripts.js +32 -11
  251. package/src/workflows/workflow-launch-record.d.ts +15 -6
  252. package/src/workflows/workflow-launch-record.js +30 -12
  253. package/src/workflows/workflow-receipt.js +36 -53
  254. package/src/workflows/workflow-resources.js +4 -4
  255. package/src/workflows/workflow-resume-claim.d.ts +2 -0
  256. package/src/workflows/workflow-resume-claim.js +3 -3
  257. package/src/workflows/workflow-resume.d.ts +1 -1
  258. package/src/workflows/workflow-resume.js +13 -8
  259. package/src/workflows/workflow-script-worker.d.ts +13 -0
  260. package/src/workflows/workflow-script-worker.js +81 -0
  261. package/workflow-script-process.cjs +36 -0
  262. package/workflow-script-worker.cjs +4 -1
  263. package/bundle/chunk-U4ODUYAG.js +0 -235
@@ -1,4 +1,4 @@
1
- import type { Message, Usage as PiUsage } from "@earendil-works/pi-ai";
1
+ import type { Message, StopReason, Usage as PiUsage } from "@earendil-works/pi-ai";
2
2
  import type { AgentProgress, AsyncStatus, Details, DisplayItem, ErrorInfo, SingleResult, ToolCallSummary, Usage } from "./types.ts";
3
3
  export declare const PI_CODING_AGENT_PACKAGE_ROOT_ENV = "PI_SUBAGENTS_PI_CODING_AGENT_PACKAGE_ROOT";
4
4
  export declare const PROMPT_REDACTED = "[prompt redacted]";
@@ -11,9 +11,6 @@ export declare function getProjectConfigDir(projectRoot: string): string;
11
11
  export declare function getAgentDir(): string;
12
12
  export declare function pruneStatusCacheForAsyncRoot(asyncDirRoot: string, runIds: Iterable<string>): number;
13
13
  export declare function resolveChildCwd(baseCwd: string, childCwd: string | undefined): string;
14
- /**
15
- * Read async job status from disk (with mtime-based caching)
16
- */
17
14
  export declare function readStatus(asyncDir: string): AsyncStatus | null;
18
15
  export declare function getLastActivity(outputFile: string | undefined): string;
19
16
  export declare function findLatestSessionFile(sessionDir: string): string | null;
@@ -30,13 +27,11 @@ export declare function assistantMessageError(message: {
30
27
  }): string | undefined;
31
28
  export declare function getFinalOutput(messages: Message[]): string;
32
29
  export declare function getSingleResultOutput(result: Pick<SingleResult, "finalOutput" | "messages">): string;
33
- /**
34
- * Extract display items (text and tool calls) from messages
35
- */
30
+ export declare const TRUNCATED_RESPONSE_ERROR = "Response was truncated: the model reached its maximum output length.";
31
+ export declare function getTerminalAssistantStopReason(messages: Message[]): StopReason | undefined;
36
32
  export declare function getDisplayItems(messages: Message[] | undefined): DisplayItem[];
37
33
  export declare function sumResultsUsage(results: SingleResult[]): Usage;
38
34
  export declare function toAgentToolUsage(usage: Usage): PiUsage;
39
- /** Sum input tokens, output tokens, and cost across a set of SingleResults. */
40
35
  export declare function sumResultsCost(results: SingleResult[]): NonNullable<Details["totalCost"]>;
41
36
  export declare function compactForegroundResult(result: SingleResult): SingleResult;
42
37
  export declare function compactForegroundDetails(details: Details): Details;
@@ -56,7 +51,6 @@ export declare function compactForegroundDetails(details: Details): Details;
56
51
  export declare const MAX_STREAMED_RECENT_TOOLS = 32;
57
52
  export declare const MAX_STREAMED_TOOL_CALLS = 64;
58
53
  export declare const MAX_STREAMED_OUTPUT_LINE_CHARS = 2000;
59
- /** Keep only the most recent tool-history entries in a streamed snapshot. */
60
54
  export declare function boundStreamedRecentTools(recentTools: AgentProgress["recentTools"]): AgentProgress["recentTools"];
61
55
  /** Cap per-line length of recent output so one long line can't inflate a snapshot. */
62
56
  export declare function boundStreamedRecentOutput(recentOutput: string[]): string[];
@@ -72,12 +66,6 @@ export declare function formatEmptyTerminalAssistantResponseError(messages: Mess
72
66
  * Detect errors in subagent execution from messages (only errors with no subsequent success)
73
67
  */
74
68
  export declare function detectSubagentError(messages: Message[]): ErrorInfo;
75
- /**
76
- * Extract a preview of tool arguments for display
77
- */
78
69
  export declare function extractToolArgsPreview(args: Record<string, unknown>): string;
79
- /**
80
- * Extract text content from various message content formats
81
- */
82
70
  export declare function extractTextFromContent(content: unknown): string;
83
71
  export { mapConcurrent } from "../runs/shared/parallel-utils.ts";
@@ -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
  }
@@ -1,4 +1,4 @@
1
- import { readTranscriptRecords } from "./fleet-transcript.js";
1
+ import { readTranscriptRecords } from "../shared/fleet-transcript-reader.js";
2
2
  const REQUIRED_NATIVE_EXPORTS = [
3
3
  "createTranscriptState",
4
4
  "appendEntry",
@@ -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));
@@ -1,63 +1,7 @@
1
1
  import { type ExtensionContext } from "@earendil-works/pi-coding-agent";
2
2
  import { type MarkdownTheme } from "@earendil-works/pi-tui";
3
+ import { type FleetTranscript } from "../shared/fleet-transcript-reader.ts";
3
4
  type Theme = ExtensionContext["ui"]["theme"];
4
- export type FleetTranscriptEvent = {
5
- kind: "assistant";
6
- text: string;
7
- model?: string;
8
- timestamp?: number;
9
- } | {
10
- kind: "user";
11
- text: string;
12
- timestamp?: number;
13
- } | {
14
- kind: "tool";
15
- toolCallId?: string;
16
- name: string;
17
- args?: string;
18
- argsPayload?: string;
19
- output?: string;
20
- outputTruncated?: boolean;
21
- status: "running" | "complete" | "error";
22
- error?: string;
23
- startedAt?: number;
24
- endedAt?: number;
25
- timestamp?: number;
26
- } | {
27
- kind: "notice";
28
- text: string;
29
- tone: "muted" | "warning" | "error";
30
- timestamp?: number;
31
- };
32
- export interface FleetTranscript {
33
- path: string;
34
- events: FleetTranscriptEvent[];
35
- truncated: boolean;
36
- warning?: string;
37
- /** The path was refused or the file could not be read, as opposed to a read that only skipped records. */
38
- readFailed?: true;
39
- }
40
- export interface FleetTranscriptReadOptions {
41
- trustedRoots: string[];
42
- trustedFiles?: string[];
43
- trustedFileRoot?: string;
44
- maxRecords?: number;
45
- maxBytes?: number;
46
- }
47
- export declare function readFleetTranscript(filePath: string, options: FleetTranscriptReadOptions): FleetTranscript;
48
- export interface TranscriptRecordRead {
49
- readFailed?: true;
50
- records: Array<Record<string, unknown>>;
51
- truncated: boolean;
52
- warning?: string;
53
- }
54
- /**
55
- * Shared trusted-root-guarded tail reader that returns raw parsed JSONL
56
- * records instead of fleet events. Both the legacy rail renderer and the
57
- * native-component renderer ingest through this single validation path, so
58
- * symlink refusal and path-escape rejection cannot diverge between them.
59
- */
60
- export declare function readTranscriptRecords(filePath: string, options: FleetTranscriptReadOptions): TranscriptRecordRead;
61
5
  export declare function renderFleetTranscript(transcript: FleetTranscript, width: number, theme: Theme, markdownTheme: MarkdownTheme, options?: {
62
6
  expandedTools?: boolean;
63
7
  }): string[];