pi-subagents 0.84.0 → 0.86.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 (210) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/bundle/agents.js +3 -3
  3. package/bundle/child-tool-plan.js +2 -2
  4. package/bundle/{chunk-JG4QKI5M.js → chunk-2IYBCYFU.js} +214 -97
  5. package/bundle/{chunk-V2BZYLEP.js → chunk-374MZFF4.js} +7 -2
  6. package/bundle/{chunk-4E7BKDTX.js → chunk-3RKFH2UZ.js} +11 -156
  7. package/bundle/{chunk-F4ASL6OV.js → chunk-5H4BICQZ.js} +1 -1
  8. package/bundle/{chunk-PALJGGYC.js → chunk-6VD7BGIC.js} +6 -3
  9. package/bundle/{chunk-C5P5CHYK.js → chunk-77ASNIEM.js} +1 -1
  10. package/bundle/{chunk-XDQORLZ5.js → chunk-7ADDXUGF.js} +15 -6
  11. package/bundle/{chunk-PV63UFUR.js → chunk-7QA7ZA46.js} +183 -28
  12. package/bundle/{chunk-NKQ6JNAS.js → chunk-7ZUFN6ME.js} +2 -1
  13. package/bundle/{chunk-SSG7IEP5.js → chunk-A637IMAO.js} +2 -2
  14. package/bundle/{chunk-L3WFKBEI.js → chunk-BGXEAYUM.js} +247 -153
  15. package/bundle/{chunk-J5YL7LYR.js → chunk-BU6PFPVX.js} +59 -27
  16. package/bundle/{chunk-DZDETGRJ.js → chunk-BWC2LVII.js} +259 -216
  17. package/bundle/{chunk-CGN2TVE7.js → chunk-GJGTMLPE.js} +322 -18
  18. package/bundle/{chunk-D3JAFGMO.js → chunk-GRJHIXYF.js} +1 -1
  19. package/bundle/chunk-HXRB42AF.js +108 -0
  20. package/bundle/{chunk-LFDBD4PW.js → chunk-LGINOOY5.js} +2 -2
  21. package/bundle/{chunk-G2Z6ZH26.js → chunk-NAFLUJ26.js} +1 -1
  22. package/bundle/{chunk-235AWJUQ.js → chunk-O3YH7XIY.js} +324 -111
  23. package/bundle/{chunk-2DHZTCOL.js → chunk-PYOAIN3V.js} +2 -2
  24. package/bundle/{chunk-LNRJCP2Y.js → chunk-QGO6HXHG.js} +417 -242
  25. package/bundle/{chunk-VQVVHSY6.js → chunk-QM3JGE4W.js} +22 -11
  26. package/bundle/{chunk-2S4K53MV.js → chunk-S2Q75LP3.js} +1 -1
  27. package/bundle/{chunk-NENDSQUY.js → chunk-UR7OW5S7.js} +9 -6
  28. package/bundle/{chunk-AKOIVLA5.js → chunk-WN2E5XHN.js} +135 -77
  29. package/bundle/{chunk-2D52JFLF.js → chunk-YK3QYNLE.js} +41 -117
  30. package/bundle/{chunk-7BWGNDNK.js → chunk-ZJJCPV3L.js} +190 -1177
  31. package/bundle/chunk-ZPY5QZCS.js +1067 -0
  32. package/bundle/control-channel.js +2 -2
  33. package/bundle/index.js +1 -1
  34. package/bundle/intercom-bridge.js +2 -2
  35. package/bundle/preflight.js +8 -8
  36. package/bundle/project-panes.js +3 -3
  37. package/docs/agents.md +23 -2
  38. package/docs/configuration.md +4 -4
  39. package/docs/extension-api.md +16 -1
  40. package/docs/tool-reference.md +2 -0
  41. package/docs/workflows.md +30 -2
  42. package/package.json +1 -1
  43. package/src/agents/agent-management.js +27 -11
  44. package/src/agents/agent-memory.d.ts +1 -4
  45. package/src/agents/agent-memory.js +1 -4
  46. package/src/agents/agents.d.ts +1 -3
  47. package/src/agents/agents.js +7 -6
  48. package/src/agents/frontmatter.js +1 -8
  49. package/src/agents/global-npm-root.d.ts +1 -0
  50. package/src/agents/global-npm-root.js +11 -3
  51. package/src/agents/skills.d.ts +0 -3
  52. package/src/agents/skills.js +0 -3
  53. package/src/extension/config.js +7 -1
  54. package/src/extension/herdr-pi-bridge.js +10 -2
  55. package/src/extension/index.d.ts +0 -13
  56. package/src/extension/index.js +43 -32
  57. package/src/extension/public-execution.d.ts +1 -0
  58. package/src/extension/public-execution.js +4 -0
  59. package/src/extension/reply-workflow-script.js +24 -4
  60. package/src/extension/schemas.d.ts +8 -3
  61. package/src/extension/schemas.js +5 -3
  62. package/src/extension/session-switch.d.ts +25 -0
  63. package/src/extension/session-switch.js +138 -0
  64. package/src/extension/subagent-guide.d.ts +1 -1
  65. package/src/extension/subagent-guide.js +1 -1
  66. package/src/extension/subagent-launch-tool.d.ts +25 -0
  67. package/src/extension/subagent-launch-tool.js +48 -0
  68. package/src/extension/tool-activation.js +35 -12
  69. package/src/extension/tool-description.d.ts +1 -1
  70. package/src/extension/tool-description.js +14 -8
  71. package/src/inspectors/herdr/actions.d.ts +0 -1
  72. package/src/inspectors/herdr/actions.js +0 -1
  73. package/src/inspectors/session-roots-codec.d.ts +0 -1
  74. package/src/inspectors/session-roots-codec.js +0 -1
  75. package/src/inspectors/tmux/actions.d.ts +0 -1
  76. package/src/inspectors/tmux/actions.js +0 -1
  77. package/src/integrations/herdr-status.js +3 -8
  78. package/src/intercom/native-supervisor-channel.js +65 -9
  79. package/src/runs/background/async-execution.d.ts +5 -9
  80. package/src/runs/background/async-execution.js +62 -27
  81. package/src/runs/background/async-job-tracker.js +12 -0
  82. package/src/runs/background/async-resume.d.ts +2 -1
  83. package/src/runs/background/async-resume.js +112 -39
  84. package/src/runs/background/async-retention.js +6 -1
  85. package/src/runs/background/auto-drain.js +2 -1
  86. package/src/runs/background/boot-id.d.ts +1 -3
  87. package/src/runs/background/boot-id.js +1 -3
  88. package/src/runs/background/completion-batcher.d.ts +3 -4
  89. package/src/runs/background/completion-batcher.js +2 -3
  90. package/src/runs/background/control-channel.d.ts +0 -6
  91. package/src/runs/background/control-channel.js +0 -6
  92. package/src/runs/background/fleet-view.js +2 -3
  93. package/src/runs/background/notify.d.ts +0 -2
  94. package/src/runs/background/notify.js +0 -2
  95. package/src/runs/background/result-watcher.d.ts +1 -0
  96. package/src/runs/background/result-watcher.js +59 -29
  97. package/src/runs/background/resume-guidance.js +4 -2
  98. package/src/runs/background/retained-children.js +2 -1
  99. package/src/runs/background/run-child-session.d.ts +0 -1
  100. package/src/runs/background/run-child-session.js +1 -1
  101. package/src/runs/background/run-status.js +9 -7
  102. package/src/runs/background/scheduled-runs.d.ts +3 -1
  103. package/src/runs/background/scheduled-runs.js +13 -16
  104. package/src/runs/background/subagent-runner.d.ts +2 -4
  105. package/src/runs/background/subagent-runner.js +15 -12
  106. package/src/runs/background/subagent-wait.js +12 -15
  107. package/src/runs/background/wait-config.d.ts +2 -0
  108. package/src/runs/background/wait-config.js +17 -3
  109. package/src/runs/background/wait-tool.js +4 -2
  110. package/src/runs/background/workflow-terminal-proof.d.ts +0 -1
  111. package/src/runs/background/workflow-terminal-proof.js +0 -1
  112. package/src/runs/foreground/execution.d.ts +0 -3
  113. package/src/runs/foreground/execution.js +17 -9
  114. package/src/runs/foreground/subagent-executor.d.ts +3 -2
  115. package/src/runs/foreground/subagent-executor.js +107 -26
  116. package/src/runs/shared/acceptance.js +69 -26
  117. package/src/runs/shared/child-commands.js +15 -2
  118. package/src/runs/shared/child-hooks.d.ts +1 -7
  119. package/src/runs/shared/child-hooks.js +13 -5
  120. package/src/runs/shared/child-launch.js +6 -2
  121. package/src/runs/shared/child-runtime-config.d.ts +0 -1
  122. package/src/runs/shared/child-session.d.ts +1 -1
  123. package/src/runs/shared/child-session.js +21 -2
  124. package/src/runs/shared/child-tool-plan.d.ts +0 -1
  125. package/src/runs/shared/child-tool-plan.js +0 -1
  126. package/src/runs/shared/claude-code-adapter.js +11 -0
  127. package/src/runs/shared/external-cli-contract.d.ts +49 -0
  128. package/src/runs/shared/external-cli-contract.js +18 -13
  129. package/src/runs/shared/external-cli-runner.js +26 -6
  130. package/src/runs/shared/herdr-connection.js +2 -1
  131. package/src/runs/shared/herdr-pane-host.d.ts +2 -2
  132. package/src/runs/shared/herdr-pane-host.js +17 -1
  133. package/src/runs/shared/herdr-placed-run.js +48 -22
  134. package/src/runs/shared/lane-metadata.d.ts +0 -1
  135. package/src/runs/shared/lane-metadata.js +0 -1
  136. package/src/runs/shared/mcp-direct-tool-grant.js +8 -1
  137. package/src/runs/shared/model-resolution-diagnostic.d.ts +0 -1
  138. package/src/runs/shared/model-resolution.d.ts +2 -2
  139. package/src/runs/shared/model-resolution.js +7 -1
  140. package/src/runs/shared/model-scope.d.ts +1 -5
  141. package/src/runs/shared/model-scope.js +1 -5
  142. package/src/runs/shared/mutation-evidence.d.ts +1 -1
  143. package/src/runs/shared/mutation-evidence.js +52 -7
  144. package/src/runs/shared/nested-events.d.ts +1 -0
  145. package/src/runs/shared/nested-events.js +1 -1
  146. package/src/runs/shared/parallel-utils.d.ts +0 -1
  147. package/src/runs/shared/permissions.js +5 -3
  148. package/src/runs/shared/placement-host.d.ts +5 -1
  149. package/src/runs/shared/rex-pane-host.d.ts +0 -1
  150. package/src/runs/shared/rex-pane-host.js +0 -2
  151. package/src/runs/shared/run-launch-folder.d.ts +12 -0
  152. package/src/runs/shared/run-launch-folder.js +21 -0
  153. package/src/runs/shared/runner-launcher.d.ts +12 -1
  154. package/src/runs/shared/runner-launcher.js +16 -0
  155. package/src/runs/shared/single-output.d.ts +3 -3
  156. package/src/runs/shared/single-output.js +5 -3
  157. package/src/runs/shared/structured-output.d.ts +8 -0
  158. package/src/runs/shared/structured-output.js +40 -5
  159. package/src/runs/shared/subagent-prompt-runtime.d.ts +0 -1
  160. package/src/runs/shared/subagent-prompt-runtime.js +4 -2
  161. package/src/runs/shared/tool-timeout.js +2 -1
  162. package/src/runs/shared/worktree-cleanup-plan.d.ts +0 -1
  163. package/src/runs/shared/worktree-cleanup-plan.js +0 -1
  164. package/src/runs/shared/worktree.d.ts +3 -0
  165. package/src/runs/shared/worktree.js +20 -0
  166. package/src/shared/capacity-resilient-json.d.ts +1 -1
  167. package/src/shared/child-cache-retention.d.ts +1 -2
  168. package/src/shared/child-cache-retention.js +1 -2
  169. package/src/shared/fleet-transcript-reader.d.ts +51 -0
  170. package/src/shared/fleet-transcript-reader.js +333 -0
  171. package/src/shared/formatters.d.ts +0 -18
  172. package/src/shared/formatters.js +0 -18
  173. package/src/shared/session-succession.d.ts +16 -1
  174. package/src/shared/session-succession.js +41 -2
  175. package/src/shared/session-warnings.d.ts +7 -0
  176. package/src/shared/session-warnings.js +26 -0
  177. package/src/shared/settings.d.ts +0 -23
  178. package/src/shared/settings.js +3 -35
  179. package/src/shared/types.d.ts +85 -59
  180. package/src/shared/types.js +0 -12
  181. package/src/shared/utils.d.ts +0 -14
  182. package/src/shared/utils.js +0 -22
  183. package/src/shared/wait-tool-name.d.ts +8 -0
  184. package/src/shared/wait-tool-name.js +13 -0
  185. package/src/slash/slash-commands.js +2 -1
  186. package/src/slash/subagent-cost.d.ts +3 -2
  187. package/src/slash/subagent-cost.js +22 -3
  188. package/src/slash/subagents-admin.js +0 -1
  189. package/src/tui/fleet-status.d.ts +0 -5
  190. package/src/tui/fleet-status.js +4 -24
  191. package/src/tui/fleet-transcript.d.ts +1 -44
  192. package/src/tui/fleet-transcript.js +1 -327
  193. package/src/tui/fleet.js +6 -4
  194. package/src/tui/render.d.ts +0 -9
  195. package/src/tui/render.js +161 -66
  196. package/src/tui/subagent-messages.js +3 -2
  197. package/src/watchdog/register-child.d.ts +2 -3
  198. package/src/watchdog/register-child.js +2 -3
  199. package/src/watchdog/turn-delta.js +2 -1
  200. package/src/workflows/scripted-workflow.js +241 -20
  201. package/src/workflows/workflow-launch-record.d.ts +15 -6
  202. package/src/workflows/workflow-launch-record.js +30 -12
  203. package/src/workflows/workflow-receipt.js +36 -53
  204. package/src/workflows/workflow-resume-claim.js +2 -2
  205. package/src/workflows/workflow-resume.d.ts +1 -1
  206. package/src/workflows/workflow-resume.js +11 -8
  207. package/src/workflows/workflow-script-worker.d.ts +13 -0
  208. package/src/workflows/workflow-script-worker.js +79 -0
  209. package/workflow-script-process.cjs +36 -0
  210. package/workflow-script-worker.cjs +4 -1
@@ -13,11 +13,13 @@ import { reconcileAsyncRun } from "./stale-run-reconciler.js";
13
13
  import { resultFilePath, resultPayloadPathForIndexedRun } from "./result-files.js";
14
14
  import { canScanAsyncRunPrefix, MIN_SAFE_ASYNC_RUN_PREFIX_LENGTH } from "./run-id-query.js";
15
15
  import { parallelHandoffPath, resolveRetainedWorktreeCwd } from "../shared/parallel-handoff.js";
16
- import { normalizeWorktreeBaseRef } from "../shared/worktree.js";
16
+ import { findListedWorktreeAgentCwd, findListedWorktreeOnBranch, isComparablePathInside, normalizeWorktreeBaseRef } from "../shared/worktree.js";
17
17
  import { intersectThinkingCeilings, parseThinkingLevel } from "../../shared/thinking-ceiling.js";
18
18
  import { assertWorkflowGraphHostSteps } from "../shared/host-step-status.js";
19
19
  import { validateIntercomBridgeConfig } from "../../intercom/intercom-bridge.js";
20
20
  import { validateModelResponseAliases } from "../../shared/model-response-aliases.js";
21
+ import { readWorkflowLaunchRecord } from "../../workflows/workflow-launch-record.js";
22
+ import { recoveryDescriptorPath } from "../shared/run-launch-folder.js";
21
23
  function getErrorMessage(error) {
22
24
  return error instanceof Error ? error.message : String(error);
23
25
  }
@@ -251,6 +253,7 @@ function normalizeRecoveryAcceptance(value, descriptorPath) {
251
253
  throw new Error(`Invalid async recovery descriptor '${descriptorPath}': ${errors.join(" ")}`);
252
254
  return value;
253
255
  }
256
+ /** A workflow-mode target has a ceiling only when its parent-owned launch record exists (resolveAsyncResumeTarget). */
254
257
  export function asyncReviveRequiresRecoveryDescriptor(target) {
255
258
  if (target.recoveryDescriptor)
256
259
  return false;
@@ -263,10 +266,8 @@ function resumeTargetMode(status, result) {
263
266
  return result.mode;
264
267
  return undefined;
265
268
  }
266
- export function readAsyncRecoveryDescriptor(asyncDir) {
267
- if (!asyncDir)
268
- return undefined;
269
- const descriptorPath = path.join(asyncDir, "recovery-descriptor.json");
269
+ export function readAsyncRecoveryDescriptor(runsRoot, runId) {
270
+ const descriptorPath = recoveryDescriptorPath(runsRoot, runId);
270
271
  if (!fs.existsSync(descriptorPath))
271
272
  return undefined;
272
273
  let value;
@@ -284,7 +285,7 @@ export function readAsyncRecoveryDescriptor(asyncDir) {
284
285
  "subagentOnlyExtensions", "mcpDirectTools", "excludeTools", "mutationTools", "systemPrompt", "systemPromptMode", "inheritProjectContext", "inheritGlobalContext", "inheritSkills", "skills",
285
286
  "skillPath", "agentFilePath", "memory", "outputPath", "outputMode", "structuredOutputSchema", "acceptance", "sessionDir", "artifactConfig",
286
287
  "artifactsDir", "maxOutput", "controlConfig", "context", "intercomBridge", "absoluteDeadlineAt", "initialTurnBudget", "initialToolBudget", "maxSubagentDepth", "share", "capabilityCeiling",
287
- "launchResolvedExtensions", "runFanoutBudget", "lane", "baseRef", "launcher",
288
+ "launchResolvedExtensions", "runFanoutBudget", "lane", "baseRef", "launcher", "requiredLauncher", "sessionId", "managedWorktree",
288
289
  "extensionBindings",
289
290
  "requiredExtensions",
290
291
  ]);
@@ -299,8 +300,16 @@ export function readAsyncRecoveryDescriptor(asyncDir) {
299
300
  }
300
301
  if (parsed.version !== 1)
301
302
  throw new Error(`Invalid async recovery descriptor '${descriptorPath}': version must be 1.`);
302
- if (parsed.launcher !== undefined && (typeof parsed.launcher !== "string" || !RUNNER_LAUNCHER_NAME_PATTERN.test(parsed.launcher)))
303
- throw new Error(`Invalid async recovery descriptor '${descriptorPath}': launcher must be a launcher name.`);
303
+ if (parsed.launcher !== undefined && parsed.launcher !== null && (typeof parsed.launcher !== "string" || !RUNNER_LAUNCHER_NAME_PATTERN.test(parsed.launcher)))
304
+ throw new Error(`Invalid async recovery descriptor '${descriptorPath}': launcher must be a launcher name or null.`);
305
+ if (parsed.requiredLauncher !== undefined) {
306
+ const required = parsed.requiredLauncher;
307
+ if (!required || typeof required !== "object" || Array.isArray(required) || Object.keys(required).some((key) => key !== "name" && key !== "definitionDigest")
308
+ || typeof required.name !== "string" || !RUNNER_LAUNCHER_NAME_PATTERN.test(required.name)
309
+ || typeof required.definitionDigest !== "string" || !/^[0-9a-f]{64}$/.test(required.definitionDigest)) {
310
+ throw new Error(`Invalid async recovery descriptor '${descriptorPath}': requiredLauncher must be { name, definitionDigest }.`);
311
+ }
312
+ }
304
313
  try {
305
314
  parsed.runFanoutBudget = validateRunFanoutBudgetDescriptor(parsed.runFanoutBudget);
306
315
  }
@@ -372,7 +381,14 @@ export function readAsyncRecoveryDescriptor(asyncDir) {
372
381
  }
373
382
  if (parsed.systemPrompt !== undefined && typeof parsed.systemPrompt !== "string")
374
383
  throw new Error(`Invalid async recovery descriptor '${descriptorPath}': systemPrompt must be a string.`);
375
- for (const field of ["launchContractDigest", "sessionFile", "model", "modelProvider", "thinking", "agentFilePath", "outputPath", "sessionDir", "artifactsDir"]) {
384
+ if (parsed.managedWorktree !== undefined) {
385
+ const worktree = parsed.managedWorktree;
386
+ const valid = !!worktree && typeof worktree === "object" && !Array.isArray(worktree) && ((worktree.provider === "native" && typeof worktree.cwd === "string" && path.isAbsolute(worktree.cwd) && Object.keys(worktree).length === 2)
387
+ || (worktree.provider === "worktrunk" && typeof worktree.branch === "string" && !!worktree.branch.trim() && Object.keys(worktree).length === 2));
388
+ if (!valid)
389
+ throw new Error(`Invalid async recovery descriptor '${descriptorPath}': managedWorktree is invalid.`);
390
+ }
391
+ for (const field of ["sessionId", "launchContractDigest", "sessionFile", "model", "modelProvider", "thinking", "agentFilePath", "outputPath", "sessionDir", "artifactsDir"]) {
376
392
  if (parsed[field] !== undefined && (typeof parsed[field] !== "string" || !parsed[field].trim()))
377
393
  throw new Error(`Invalid async recovery descriptor '${descriptorPath}': ${field} must be a non-empty string.`);
378
394
  }
@@ -457,6 +473,27 @@ export function readAsyncRecoveryDescriptor(asyncDir) {
457
473
  parsed.acceptance = normalizeRecoveryAcceptance(parsed.acceptance, descriptorPath);
458
474
  return parsed;
459
475
  }
476
+ /**
477
+ * handoff.json sits in the run directory, so its worktree cwd must be the one the launch chose: the
478
+ * native path the parent computed, or a worktree git itself lists on the requested Worktrunk branch.
479
+ */
480
+ function assertLaunchedWorktreeCwd(runId, launchCwd, launched, handoffCwd) {
481
+ const listed = launched.provider === "native" ? undefined : findListedWorktreeOnBranch(launchCwd, launched.branch);
482
+ const matches = launched.provider === "native"
483
+ ? isComparablePathInside(launched.cwd, handoffCwd) && isComparablePathInside(handoffCwd, launched.cwd)
484
+ : listed !== undefined && isComparablePathInside(listed, handoffCwd);
485
+ if (!matches)
486
+ throw new Error(`Async run '${runId}' managed worktree ${handoffCwd} is not the worktree its launch created.`);
487
+ return handoffCwd;
488
+ }
489
+ /** A run launched in a worktree resumes in it, never in the source checkout, even when handoff.json is missing. */
490
+ function launchedWorktreeCwdWithoutHandoff(runId, launchCwd, launched) {
491
+ const cwd = launched.provider === "native" ? launched.cwd : findListedWorktreeAgentCwd(launchCwd, launched.branch);
492
+ if (cwd === undefined || !fs.statSync(cwd, { throwIfNoEntry: false })?.isDirectory()) {
493
+ throw new Error(`Async run '${runId}' ran in a managed worktree (${launched.provider === "native" ? launched.cwd : `branch ${launched.branch}`}) that no longer exists; it cannot resume in the source checkout.`);
494
+ }
495
+ return cwd;
496
+ }
460
497
  function validateResumeSessionFile(runId, sessionFile) {
461
498
  if (path.extname(sessionFile) !== ".jsonl")
462
499
  throw new Error(`Async run '${runId}' session file must be a .jsonl file: ${sessionFile}`);
@@ -487,20 +524,40 @@ export function resolveAsyncResumeTarget(params, deps = {}, options = {}) {
487
524
  const requested = params.id ?? params.runId;
488
525
  throw new Error(requested ? `Async run not found for '${requested}'.` : "Async run not found. Provide id or dir.");
489
526
  }
527
+ // A run directory is always named for its run, so a status file naming another run is refused, and
528
+ // before reconciling: its repair publishes a result under the status file's run id.
529
+ if (location.asyncDir) {
530
+ let recordedRunId;
531
+ try {
532
+ recordedRunId = JSON.parse(fs.readFileSync(path.join(location.asyncDir, "status.json"), "utf-8")).runId;
533
+ }
534
+ catch { /* missing or unreadable: validateStatusForResume reports it */ }
535
+ if (typeof recordedRunId === "string" && recordedRunId !== path.basename(location.asyncDir))
536
+ throw new Error(`Async run '${path.basename(location.asyncDir)}' has a status file for a different run '${recordedRunId}'.`);
537
+ }
490
538
  const reconciliation = location.asyncDir
491
539
  ? reconcileAsyncRun(location.asyncDir, { resultsDir, kill: deps.kill, now: deps.now })
492
540
  : undefined;
493
541
  const status = reconciliation?.status ?? null;
494
542
  validateStatusForResume(status, location.asyncDir ? path.join(location.asyncDir, "status.json") : "status.json");
495
- const recoveryDescriptor = readAsyncRecoveryDescriptor(location.asyncDir ?? undefined);
543
+ // Records are trusted only for a run folder directly under the runs root: `dir` may name a
544
+ // runs-shaped tree a run built inside its own folder.
545
+ const directRunFolder = location.asyncDir !== null && path.dirname(location.asyncDir) === path.resolve(asyncDirRoot);
546
+ const recoveryDescriptor = directRunFolder ? readAsyncRecoveryDescriptor(asyncDirRoot, path.basename(location.asyncDir)) : undefined;
496
547
  const result = location.resultPath ? readResultFile(location.resultPath) : undefined;
497
- const runId = status?.runId ?? result?.runId ?? result?.id ?? location.resolvedId ?? (location.asyncDir ? path.basename(location.asyncDir) : "unknown");
498
- const mode = resumeTargetMode(status, result);
499
- if (options.sessionId && ((status && !ownsRun(options.sessionId, status.sessionId)) || (result && !ownsRun(options.sessionId, result.sessionId)))) {
548
+ const runId = location.asyncDir ? path.basename(location.asyncDir) : result?.runId ?? result?.id ?? location.resolvedId ?? "unknown";
549
+ // Only a single run writes a recovery descriptor. When one exists, the run's identity (agent,
550
+ // session, cwd, model, ceilings) comes from it alone: status.json and the shared results directory
551
+ // are writable by a run behind a runner launcher.
552
+ const mode = recoveryDescriptor ? "single" : resumeTargetMode(status, result);
553
+ const notOwned = recoveryDescriptor
554
+ ? !ownsRun(options.sessionId, recoveryDescriptor.sessionId)
555
+ : (status && !ownsRun(options.sessionId, status.sessionId)) || (result && !ownsRun(options.sessionId, result.sessionId));
556
+ if (options.sessionId && notOwned) {
500
557
  throw new Error(`Async run '${runId}' was not found in the active session.`);
501
558
  }
502
559
  if (recoveryDescriptor && recoveryDescriptor.sourceRunId !== runId)
503
- throw new Error(`Async run '${runId}' has a recovery descriptor for a different source run.`);
560
+ throw new Error(`Async run '${runId}' has a recovery descriptor for a different source run '${recoveryDescriptor.sourceRunId}'.`);
504
561
  const state = status?.state ?? (result ? resultState(result) : undefined);
505
562
  if (!state)
506
563
  throw new Error(`Status file not found for async run '${runId}'.`);
@@ -519,18 +576,18 @@ export function resolveAsyncResumeTarget(params, deps = {}, options = {}) {
519
576
  throw new Error(`Async run '${runId}' has ${stepCount} children. Index ${requestedIndex} is out of range.`);
520
577
  const selectedStep = statusSteps[requestedIndex];
521
578
  if (selectedStep?.status === "running") {
522
- const capabilityCeiling = intersectSubagentCapabilityCeilings(status?.capabilityCeiling, selectedStep.capabilityCeiling);
579
+ const capabilityCeiling = recoveryDescriptor ? recoveryDescriptor.capabilityCeiling : intersectSubagentCapabilityCeilings(status?.capabilityCeiling, selectedStep.capabilityCeiling);
523
580
  return {
524
581
  kind: "live",
525
582
  runId,
526
583
  asyncDir: location.asyncDir ?? undefined,
527
584
  state,
528
585
  ...(mode ? { mode } : {}),
529
- agent: selectedStep.agent,
586
+ agent: recoveryDescriptor?.agent ?? selectedStep.agent,
530
587
  ...(selectedStep.sessionName ?? result?.results?.[requestedIndex]?.sessionName ? { sessionName: selectedStep.sessionName ?? result?.results?.[requestedIndex]?.sessionName } : {}),
531
588
  index: requestedIndex,
532
589
  cwd: status?.cwd ?? result?.cwd,
533
- sessionFile: selectedStep.sessionFile ?? status?.sessionFile ?? result?.sessionFile,
590
+ sessionFile: recoveryDescriptor ? recoveryDescriptor.sessionFile : selectedStep.sessionFile ?? status?.sessionFile ?? result?.sessionFile,
534
591
  model: selectedStep.model,
535
592
  thinking: selectedStep.thinking,
536
593
  launchContractDigest: selectedStep.launchContractDigest ?? result?.results?.[requestedIndex]?.launchContractDigest ?? result?.launchContractDigest ?? recoveryDescriptor?.launchContractDigest,
@@ -554,18 +611,18 @@ export function resolveAsyncResumeTarget(params, deps = {}, options = {}) {
554
611
  if (!selected) {
555
612
  throw new Error(`Async run '${runId}' has ${running.length} running children. Provide index to choose one.`);
556
613
  }
557
- const capabilityCeiling = intersectSubagentCapabilityCeilings(status?.capabilityCeiling, selected.step.capabilityCeiling);
614
+ const capabilityCeiling = recoveryDescriptor ? recoveryDescriptor.capabilityCeiling : intersectSubagentCapabilityCeilings(status?.capabilityCeiling, selected.step.capabilityCeiling);
558
615
  return {
559
616
  kind: "live",
560
617
  runId,
561
618
  asyncDir: location.asyncDir ?? undefined,
562
619
  state,
563
620
  ...(mode ? { mode } : {}),
564
- agent: selected.step.agent,
621
+ agent: recoveryDescriptor?.agent ?? selected.step.agent,
565
622
  ...(selected.step.sessionName ?? result?.results?.[selected.index]?.sessionName ? { sessionName: selected.step.sessionName ?? result?.results?.[selected.index]?.sessionName } : {}),
566
623
  index: selected.index,
567
624
  cwd: status?.cwd ?? result?.cwd,
568
- sessionFile: selected.step.sessionFile ?? status?.sessionFile ?? result?.sessionFile,
625
+ sessionFile: recoveryDescriptor ? recoveryDescriptor.sessionFile : selected.step.sessionFile ?? status?.sessionFile ?? result?.sessionFile,
569
626
  model: selected.step.model,
570
627
  thinking: selected.step.thinking,
571
628
  launchContractDigest: selected.step.launchContractDigest ?? result?.results?.[selected.index]?.launchContractDigest ?? result?.launchContractDigest ?? recoveryDescriptor?.launchContractDigest,
@@ -589,27 +646,41 @@ export function resolveAsyncResumeTarget(params, deps = {}, options = {}) {
589
646
  if (selectedStatusStep?.status === "stopped" || selectedStatusStep?.stopped === true) {
590
647
  throw new Error(`Async run '${runId}' child ${index} was stopped and cannot be resumed. Start a new run instead.`);
591
648
  }
592
- const agent = selectedStatusStep?.agent ?? resultSteps[index]?.agent ?? result?.agent;
649
+ const agent = recoveryDescriptor ? recoveryDescriptor.agent : selectedStatusStep?.agent ?? resultSteps[index]?.agent ?? result?.agent;
593
650
  if (!agent)
594
651
  throw new Error(`Could not determine child agent for async run '${runId}'.`);
595
- if (recoveryDescriptor && recoveryDescriptor.agent !== agent)
596
- throw new Error(`Async run '${runId}' has a recovery descriptor for '${recoveryDescriptor.agent}', not '${agent}'.`);
597
- const sessionFile = statusSteps[index]?.sessionFile
598
- ?? resultSteps[index]?.sessionFile
599
- ?? (stepCount === 1 ? status?.sessionFile ?? result?.sessionFile : undefined);
652
+ const sessionFile = recoveryDescriptor
653
+ ? recoveryDescriptor.sessionFile
654
+ : statusSteps[index]?.sessionFile
655
+ ?? resultSteps[index]?.sessionFile
656
+ ?? (stepCount === 1 ? status?.sessionFile ?? result?.sessionFile : undefined);
600
657
  if (!sessionFile && requireSessionFile)
601
658
  throw new Error(`Async run '${runId}' child ${index} does not have a persisted session file to resume from.`);
602
659
  const resolvedSessionFile = sessionFile ? validateResumeSessionFile(runId, sessionFile) : undefined;
603
- const stepModel = statusSteps[index]?.launchModel ?? statusSteps[index]?.model ?? resultSteps[index]?.model ?? (stepCount === 1 ? result?.model : undefined);
604
- const stepThinking = statusSteps[index]?.thinking ?? resultSteps[index]?.thinking ?? (stepCount === 1 ? result?.thinking : undefined);
605
- const thinkingCeiling = statusSteps[index]?.thinkingCeiling ?? (stepCount === 1 ? recoveryDescriptor?.thinkingCeiling : undefined);
606
- const capabilityCeiling = mode === "workflow"
607
- ? intersectSubagentCapabilityCeilings(status?.admissionCapabilityCeiling, result?.admissionCapabilityCeiling)
608
- : intersectSubagentCapabilityCeilings(status?.capabilityCeiling, statusSteps[index]?.capabilityCeiling, result?.capabilityCeiling, resultSteps[index]?.capabilityCeiling);
609
- const managedWorktreeCwd = location.asyncDir
660
+ const stepModel = recoveryDescriptor ? recoveryDescriptor.model : statusSteps[index]?.launchModel ?? statusSteps[index]?.model ?? resultSteps[index]?.model ?? (stepCount === 1 ? result?.model : undefined);
661
+ const stepThinking = recoveryDescriptor ? recoveryDescriptor.thinking : statusSteps[index]?.thinking ?? resultSteps[index]?.thinking ?? (stepCount === 1 ? result?.thinking : undefined);
662
+ const thinkingCeiling = recoveryDescriptor ? recoveryDescriptor.thinkingCeiling : statusSteps[index]?.thinkingCeiling;
663
+ // A workflow's admission ceiling comes only from the parent-owned launch record of its run directory:
664
+ // a run behind a launcher can write its own status.json (including a directory nested in it) and the
665
+ // shared results directory. Without a record there is no ceiling, so a revive without a recovery
666
+ // descriptor is refused.
667
+ const workflowLaunch = mode === "workflow" && directRunFolder
668
+ ? readWorkflowLaunchRecord(asyncDirRoot, runId)
669
+ : undefined;
670
+ const capabilityCeiling = recoveryDescriptor
671
+ ? recoveryDescriptor.capabilityCeiling
672
+ : mode === "workflow"
673
+ ? (workflowLaunch?.ok ? workflowLaunch.record.admissionCapabilityCeiling : undefined)
674
+ : intersectSubagentCapabilityCeilings(status?.capabilityCeiling, statusSteps[index]?.capabilityCeiling, result?.capabilityCeiling, resultSteps[index]?.capabilityCeiling);
675
+ const handoffWorktreeCwd = location.asyncDir && (!recoveryDescriptor || recoveryDescriptor.managedWorktree)
610
676
  ? resolveRetainedWorktreeCwd(parallelHandoffPath(location.asyncDir), runId, index, statusSteps[index]?.worktreePath)
611
677
  : undefined;
612
- const resumeCwd = validateResumeCwd(runId, managedWorktreeCwd ?? status?.cwd ?? result?.cwd ?? recoveryDescriptor?.cwd);
678
+ const managedWorktreeCwd = recoveryDescriptor?.managedWorktree
679
+ ? handoffWorktreeCwd
680
+ ? assertLaunchedWorktreeCwd(runId, recoveryDescriptor.cwd, recoveryDescriptor.managedWorktree, handoffWorktreeCwd)
681
+ : launchedWorktreeCwdWithoutHandoff(runId, recoveryDescriptor.cwd, recoveryDescriptor.managedWorktree)
682
+ : handoffWorktreeCwd;
683
+ const resumeCwd = validateResumeCwd(runId, managedWorktreeCwd ?? (recoveryDescriptor ? recoveryDescriptor.cwd : status?.cwd ?? result?.cwd));
613
684
  return {
614
685
  kind: "revive",
615
686
  runId,
@@ -624,9 +695,10 @@ export function resolveAsyncResumeTarget(params, deps = {}, options = {}) {
624
695
  ...(resolvedSessionFile ? { sessionFile: resolvedSessionFile } : {}),
625
696
  ...(stepModel ? { model: stepModel } : {}),
626
697
  ...(stepThinking ? { thinking: stepThinking } : {}),
627
- launchContractDigest: statusSteps[index]?.launchContractDigest ?? resultSteps[index]?.launchContractDigest ?? result?.launchContractDigest ?? recoveryDescriptor?.launchContractDigest,
628
- ...(statusSteps[index]?.runner ? { runner: statusSteps[index].runner } : {}),
629
- ...(statusSteps[index]?.externalJob ? { externalJob: statusSteps[index].externalJob } : {}),
698
+ launchContractDigest: recoveryDescriptor ? recoveryDescriptor.launchContractDigest : statusSteps[index]?.launchContractDigest ?? resultSteps[index]?.launchContractDigest ?? result?.launchContractDigest,
699
+ // External runners write no recovery descriptor.
700
+ ...(!recoveryDescriptor && statusSteps[index]?.runner ? { runner: statusSteps[index].runner } : {}),
701
+ ...(!recoveryDescriptor && statusSteps[index]?.externalJob ? { externalJob: statusSteps[index].externalJob } : {}),
630
702
  ...(capabilityCeiling ? { capabilityCeiling } : {}),
631
703
  ...(thinkingCeiling ? { thinkingCeiling } : {}),
632
704
  ...(recoveryDescriptor ? { recoveryDescriptor } : {}),
@@ -659,8 +731,9 @@ export function applySteeringRecoveryAgentConfig(agentConfig, descriptor) {
659
731
  output: descriptor.outputPath,
660
732
  toolBudget: descriptor.initialToolBudget,
661
733
  maxSubagentDepth: descriptor.maxSubagentDepth,
662
- // The recorded launcher wins over the current agent file, including recorded absence.
663
- launcher: descriptor.launcher,
734
+ // A recorded launcher, or a recorded null (ran unwrapped), wins over the current agent file.
735
+ // A missing field says nothing, so the run never loses the agent file's launcher.
736
+ launcher: descriptor.launcher === undefined ? agentConfig.launcher : descriptor.launcher ?? undefined,
664
737
  };
665
738
  }
666
739
  export function buildRevivedAsyncTask(target, message) {
@@ -11,6 +11,7 @@ import { REVIVAL_ORIGIN_FILE } from "../../workflows/workflow-revival.js";
11
11
  import { ACTIVE_RUN_INDEX_DIR } from "./active-run-index.js";
12
12
  import { encodeIndexSegment } from "./index-segment.js";
13
13
  import { reconcileAsyncRun } from "./stale-run-reconciler.js";
14
+ import { recoveryDescriptorPath, runLaunchDir } from "../shared/run-launch-folder.js";
14
15
  export const ASYNC_RETENTION_DAYS = 30;
15
16
  export const ASYNC_RETENTION_BATCH_SIZE = 100;
16
17
  export const ASYNC_RETENTION_DELAY_MS = 60_000;
@@ -106,7 +107,8 @@ function hasResumableContract(runDir, status) {
106
107
  const statusSessionFiles = [status.sessionFile, ...(status.steps ?? []).map((step) => step.sessionFile)];
107
108
  if (statusSessionFiles.some(existingRegularFile))
108
109
  return true;
109
- const descriptorPath = path.join(runDir, "recovery-descriptor.json");
110
+ // runDir may be a tombstone; the launch folder is keyed by the run id.
111
+ const descriptorPath = recoveryDescriptorPath(path.dirname(runDir), status.runId);
110
112
  if (!fs.existsSync(descriptorPath))
111
113
  return false;
112
114
  const descriptor = readJson(descriptorPath);
@@ -793,6 +795,7 @@ export async function cleanupAsyncRetention(options) {
793
795
  }
794
796
  mutationStateChanged = true;
795
797
  fs.rmSync(runDir, { recursive: true });
798
+ fs.rmSync(runLaunchDir(options.asyncDirRoot, status.runId), { recursive: true, force: true });
796
799
  removeRunTombstoneMarker(maintenanceRoot, status.runId);
797
800
  result.reapedTombstones += 1;
798
801
  deletedIds.push(`run-tombstone:${status.runId}`);
@@ -824,6 +827,8 @@ export async function cleanupAsyncRetention(options) {
824
827
  continue;
825
828
  }
826
829
  fs.rmSync(tombstone, { recursive: true });
830
+ // Retention never deletes a workflow run, so this removes only a single run's recovery descriptor.
831
+ fs.rmSync(runLaunchDir(options.asyncDirRoot, status.runId), { recursive: true, force: true });
827
832
  removeRunTombstoneMarker(maintenanceRoot, status.runId);
828
833
  result.deletedRuns += 1;
829
834
  deletedIds.push(`run:${status.runId}`);
@@ -1,5 +1,6 @@
1
1
  import { listAsyncRuns } from "./async-status.js";
2
2
  import { backgroundWorkForSession, waitForSubagents, waitRunScopes } from "./subagent-wait.js";
3
+ import { waitToolName } from "../../shared/wait-tool-name.js";
3
4
  export const DEFAULT_AUTO_DRAIN_TIMEOUT_MS = 30 * 60 * 1000;
4
5
  function resultText(value) {
5
6
  return value.content.map((part) => part.type === "text" ? part.text : "").join(" ").trim();
@@ -55,7 +56,7 @@ export async function drainOutstandingWork(deps, observation) {
55
56
  hasPendingSupervisorRequest: deps.hasPendingSupervisorRequest,
56
57
  });
57
58
  if (waitResult.isError) {
58
- throw new Error(`Auto-drain failed for session '${sessionId}': ${resultText(waitResult) || "bg_wait returned an error without details"}.`);
59
+ throw new Error(`Auto-drain failed for session '${sessionId}': ${resultText(waitResult) || `${waitToolName()} returned an error without details`}.`);
59
60
  }
60
61
  if (waitResult.details.wait?.reason === "supervisor_request")
61
62
  break;
@@ -4,9 +4,7 @@ import type { RecordedPid } from "./stale-run-reconciler.ts";
4
4
  * different boot id cannot still be running. Undefined when the platform has none.
5
5
  */
6
6
  export declare function currentBootId(): string | undefined;
7
- /** This process as a recorded pid, without the fields the platform does not have. */
8
7
  export declare function currentRecordedPid(): RecordedPid;
9
- /** Fixes the boot id without reading the OS; runners take Pi's value from their config. */
8
+ /** Runners take Pi's value from their config. */
10
9
  export declare function primeBootId(value: string | undefined): void;
11
- /** Clears the cache so the next read calls `nextReader` (default: the OS reader). */
12
10
  export declare function resetBootIdForTesting(nextReader?: () => string | undefined): void;
@@ -30,17 +30,15 @@ export function currentBootId() {
30
30
  runtime[BOOT_ID_KEY] = { value };
31
31
  return value;
32
32
  }
33
- /** This process as a recorded pid, without the fields the platform does not have. */
34
33
  export function currentRecordedPid() {
35
34
  const pidNamespaceScope = currentPidNamespaceScope();
36
35
  const bootId = currentBootId();
37
36
  return { pid: process.pid, ...(pidNamespaceScope ? { pidNamespaceScope } : {}), ...(bootId ? { bootId } : {}) };
38
37
  }
39
- /** Fixes the boot id without reading the OS; runners take Pi's value from their config. */
38
+ /** Runners take Pi's value from their config. */
40
39
  export function primeBootId(value) {
41
40
  runtime[BOOT_ID_KEY] = { value };
42
41
  }
43
- /** Clears the cache so the next read calls `nextReader` (default: the OS reader). */
44
42
  export function resetBootIdForTesting(nextReader) {
45
43
  reader = nextReader ?? readBootIdFromOs;
46
44
  delete runtime[BOOT_ID_KEY];
@@ -36,7 +36,7 @@ export interface CompletionBatcherOptions<T> {
36
36
  now?: () => number;
37
37
  }
38
38
  export interface CompletionBatcher<T> {
39
- /** Add a batchable item. Emits immediately when batching is disabled. */
39
+ /** Emits immediately when batching is disabled. */
40
40
  push(item: T): void;
41
41
  /** Emit any held items immediately as a single group. */
42
42
  flush(): void;
@@ -44,8 +44,7 @@ export interface CompletionBatcher<T> {
44
44
  dispose(): T[];
45
45
  }
46
46
  /**
47
- * Create a completion batcher. The batcher is single-use per registration: it
48
- * holds at most one open group. `flush` forces emission; `dispose` tears down
49
- * timers for reload/shutdown without emitting.
47
+ * The batcher is single-use per registration: it holds at most one open group.
48
+ * `flush` forces emission; `dispose` tears down timers for reload/shutdown without emitting.
50
49
  */
51
50
  export declare function createCompletionBatcher<T>(options: CompletionBatcherOptions<T>): CompletionBatcher<T>;
@@ -50,9 +50,8 @@ function unrefHandle(handle) {
50
50
  }
51
51
  }
52
52
  /**
53
- * Create a completion batcher. The batcher is single-use per registration: it
54
- * holds at most one open group. `flush` forces emission; `dispose` tears down
55
- * timers for reload/shutdown without emitting.
53
+ * The batcher is single-use per registration: it holds at most one open group.
54
+ * `flush` forces emission; `dispose` tears down timers for reload/shutdown without emitting.
56
55
  */
57
56
  export function createCompletionBatcher(options) {
58
57
  const timers = options.timers ?? defaultTimers;
@@ -63,17 +63,11 @@ export interface CommandRequest {
63
63
  }
64
64
  export declare function requestAsyncCommand(dir: string, request: CommandRequest): void;
65
65
  export declare const MAX_STEER_QUEUE_SIZE = 20;
66
- /** Control inbox directory inside an async run dir. */
67
66
  export declare function controlInboxDir(asyncDir: string): string;
68
- /** Path of the portable interrupt request file. */
69
67
  export declare function interruptRequestPath(asyncDir: string): string;
70
- /** Path of the portable timeout request file. */
71
68
  export declare function timeoutRequestPath(asyncDir: string): string;
72
- /** Path of the portable manual stop request file. */
73
69
  export declare function stopRequestPath(asyncDir: string): string;
74
- /** Directory of parent-to-runner stop requests. */
75
70
  export declare function stopRequestsDir(asyncDir: string): string;
76
- /** Directory of parent-to-runner steering requests. */
77
71
  export declare function steerRequestsDir(asyncDir: string): string;
78
72
  export declare function steerInboxClosedPath(asyncDir: string): string;
79
73
  export declare function stopInboxClosedPath(asyncDir: string): string;
@@ -82,27 +82,21 @@ const STOP_INBOX_CLOSED_FILE = "stop-inbox-closed.json";
82
82
  const STOP_INBOX_CLOSED_MESSAGE = "Runner stop inbox is closed. Retry stop after runner shutdown is observed.";
83
83
  const MAX_STEER_MESSAGE_BYTES = 128 * 1024;
84
84
  const MAX_STEER_REQUEST_ID_LENGTH = 256;
85
- /** Control inbox directory inside an async run dir. */
86
85
  export function controlInboxDir(asyncDir) {
87
86
  return path.join(asyncDir, "control");
88
87
  }
89
- /** Path of the portable interrupt request file. */
90
88
  export function interruptRequestPath(asyncDir) {
91
89
  return path.join(controlInboxDir(asyncDir), "interrupt.json");
92
90
  }
93
- /** Path of the portable timeout request file. */
94
91
  export function timeoutRequestPath(asyncDir) {
95
92
  return path.join(controlInboxDir(asyncDir), "timeout.json");
96
93
  }
97
- /** Path of the portable manual stop request file. */
98
94
  export function stopRequestPath(asyncDir) {
99
95
  return path.join(controlInboxDir(asyncDir), "stop.json");
100
96
  }
101
- /** Directory of parent-to-runner stop requests. */
102
97
  export function stopRequestsDir(asyncDir) {
103
98
  return path.join(controlInboxDir(asyncDir), STOP_REQUESTS_DIR);
104
99
  }
105
- /** Directory of parent-to-runner steering requests. */
106
100
  export function steerRequestsDir(asyncDir) {
107
101
  return path.join(controlInboxDir(asyncDir), STEER_REQUESTS_DIR);
108
102
  }
@@ -9,6 +9,7 @@ import { formatNestedRunStatusLines } from "../shared/nested-render.js";
9
9
  import { contextModeLabel, summarizeContextModes } from "../shared/context-mode.js";
10
10
  import { formatAsyncRunOutputPath, formatAsyncRunProgressLabel, listAsyncRuns } from "./async-status.js";
11
11
  import { isTrustedRecordedSessionFile } from "../../shared/session-file-trust.js";
12
+ import { waitToolName } from "../../shared/wait-tool-name.js";
12
13
  const DEFAULT_TRANSCRIPT_LINES = 80;
13
14
  const MAX_TRANSCRIPT_LINES = 500;
14
15
  const TRANSCRIPT_TAIL_BYTES = 256 * 1024;
@@ -299,7 +300,7 @@ function formatDetachedForegroundFleetLines(runs) {
299
300
  const childSummary = detachedChildren.map((child) => `${fleetChildDisplayName(child)} #${child.index}`).join(", ");
300
301
  lines.push(`- ${run.runId} | detached | ${run.mode}${childSummary ? ` | ${childSummary}` : ""}`);
301
302
  lines.push(` status: subagent({ action: "status", id: "${run.runId}" })`);
302
- lines.push(` recovery: reply to the supervisor request first, then wait with bg_wait({ id: "${run.runId}" }); do not resume or launch a replacement while any child remains detached.`);
303
+ lines.push(` recovery: reply to the supervisor request first, then wait with ${waitToolName()}({ id: "${run.runId}" }); do not resume or launch a replacement while any child remains detached.`);
303
304
  }
304
305
  return lines;
305
306
  }
@@ -467,8 +468,6 @@ function appendKnownArtifacts(lines, input) {
467
468
  lines.push(` ${artifact}`);
468
469
  }
469
470
  /**
470
- * Sanitizes each assembled line independently.
471
- *
472
471
  * Sanitizing the joined response would let a single binary fragment in child
473
472
  * output collapse the whole transcript, including run state, artifact paths, and
474
473
  * warnings, into the binary placeholder. Per-line sanitization keeps that damage
@@ -1,6 +1,4 @@
1
1
  /**
2
- * Completion notification delivery.
3
- *
4
2
  * Async result files call this notifier directly and are deleted only after
5
3
  * `sendMessage()` accepts the notification. The event bus remains an
6
4
  * observation channel, not a delivery acknowledgement.
@@ -1,6 +1,4 @@
1
1
  /**
2
- * Completion notification delivery.
3
- *
4
2
  * Async result files call this notifier directly and are deleted only after
5
3
  * `sendMessage()` accepts the notification. The event bus remains an
6
4
  * observation channel, not a delivery acknowledgement.
@@ -86,6 +86,7 @@ export declare function createResultWatcher(pi: {
86
86
  triggerTurn?: boolean;
87
87
  }) => void;
88
88
  deliverPendingResults: () => Promise<void>;
89
+ hasPendingResults: () => boolean;
89
90
  refreshResultDelivery: () => void;
90
91
  stopResultWatcher: () => void;
91
92
  };