@xzzpig/pi-subagents 0.7.0 → 0.9.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 (234) hide show
  1. package/CHANGELOG.md +456 -4
  2. package/README.md +3 -3
  3. package/agents/claude-code-writer.md +15 -0
  4. package/agents/claude-code.md +15 -0
  5. package/agents/codex-exec-writer.md +15 -0
  6. package/agents/codex-exec.md +15 -0
  7. package/agents/cursor-agent-writer.md +14 -0
  8. package/agents/cursor-agent.md +14 -0
  9. package/agents/reviewer.md +13 -3
  10. package/agents/scout.md +1 -1
  11. package/docs/agents.md +154 -42
  12. package/docs/configuration.md +85 -26
  13. package/docs/extension-api.md +81 -16
  14. package/docs/missions.md +2 -0
  15. package/docs/models.md +75 -11
  16. package/docs/observability.md +34 -21
  17. package/docs/tool-reference.md +142 -18
  18. package/docs/watchdog.md +92 -114
  19. package/docs/workflows.md +148 -4
  20. package/index.ts +10 -1
  21. package/install.mjs +1 -1
  22. package/package.json +7 -6
  23. package/prompts/council.md +19 -7
  24. package/prompts/parallel-review.md +5 -1
  25. package/prompts/review-loop.md +11 -7
  26. package/skills/council-mode/SKILL.md +44 -215
  27. package/skills/council-mode/references/pass-contracts.md +150 -0
  28. package/skills/pi-subagents/SKILL.md +90 -32
  29. package/skills/pi-subagents/references/constraints-and-recipes.md +34 -223
  30. package/skills/pi-subagents/references/execution-controls.md +104 -19
  31. package/skills/pi-subagents/references/management-authoring-rpc.md +5 -5
  32. package/skills/pi-subagents/references/multi-lane-orchestration.md +16 -4
  33. package/skills/pi-subagents/references/prompting-and-roles.md +71 -36
  34. package/skills/pi-subagents/references/review-and-validation.md +73 -0
  35. package/src/agents/agent-management.ts +471 -114
  36. package/src/agents/agent-refinements.ts +4 -4
  37. package/src/agents/agent-serializer.ts +16 -4
  38. package/src/agents/agents.ts +1076 -351
  39. package/src/agents/builtin-names.ts +6 -0
  40. package/src/agents/runtime-agent-events.ts +70 -0
  41. package/src/agents/runtime-agent-registry.ts +31 -20
  42. package/src/api/agents.ts +10 -5
  43. package/src/api/background-work.ts +12 -3
  44. package/src/api/capability-ceiling.ts +0 -1
  45. package/src/api/{pi-args.ts → child-tool-plan.ts} +1 -1
  46. package/src/api/delegation.ts +0 -7
  47. package/src/api/external-job-provider.ts +10 -1
  48. package/src/api/external-runs.ts +67 -4
  49. package/src/api/preflight.ts +97 -34
  50. package/src/api/project-panes.ts +2 -0
  51. package/src/api/shared-types.ts +6 -0
  52. package/src/extension/config.ts +90 -0
  53. package/src/extension/doctor.ts +15 -13
  54. package/src/extension/fanout-child.ts +17 -16
  55. package/src/extension/index.ts +139 -41
  56. package/src/extension/public-execution.ts +113 -22
  57. package/src/extension/rpc.ts +182 -13
  58. package/src/extension/schemas.ts +63 -21
  59. package/src/extension/tool-description.ts +48 -23
  60. package/src/extension/tool-result.ts +19 -0
  61. package/src/inspectors/herdr/actions.ts +2 -1
  62. package/src/inspectors/herdr/client.ts +3 -3
  63. package/src/inspectors/herdr/focus.ts +55 -0
  64. package/src/inspectors/herdr/inspector-runner.ts +21 -23
  65. package/src/inspectors/herdr/project-panes.ts +228 -44
  66. package/src/inspectors/herdr/session-roots-codec.ts +42 -0
  67. package/src/integrations/herdr-status.ts +75 -5
  68. package/src/intercom/native-supervisor-channel.ts +138 -60
  69. package/src/intercom/result-intercom.ts +2 -0
  70. package/src/intercom/supervisor-ui.ts +243 -0
  71. package/src/profiles/profiles.ts +5 -6
  72. package/src/runs/background/active-async-capacity.ts +103 -18
  73. package/src/runs/background/async-execution.ts +492 -125
  74. package/src/runs/background/async-job-tracker.ts +127 -28
  75. package/src/runs/background/async-resume.ts +67 -29
  76. package/src/runs/background/async-retention.ts +21 -4
  77. package/src/runs/background/async-status-snapshot.ts +23 -261
  78. package/src/runs/background/async-status.ts +199 -14
  79. package/src/runs/background/auto-drain.ts +1 -1
  80. package/src/runs/background/chain-append.ts +8 -3
  81. package/src/runs/background/chain-root-attachment.ts +79 -8
  82. package/src/runs/background/control-channel.ts +101 -214
  83. package/src/runs/background/fleet-view.ts +38 -22
  84. package/src/runs/background/inspect-rpc.ts +8 -8
  85. package/src/runs/background/notify.ts +295 -8
  86. package/src/runs/background/process-terminal.ts +16 -0
  87. package/src/runs/background/result-delivery-ownership.ts +45 -0
  88. package/src/runs/background/result-files.ts +28 -14
  89. package/src/runs/background/result-watcher.ts +43 -19
  90. package/src/runs/background/resume-guidance.ts +2 -2
  91. package/src/runs/background/retained-children.ts +1 -1
  92. package/src/runs/background/run-child-session.ts +613 -0
  93. package/src/runs/background/run-status.ts +99 -18
  94. package/src/runs/background/runner-aliases.ts +125 -0
  95. package/src/runs/background/runner-child-sessions.ts +31 -0
  96. package/src/runs/background/scheduled-runs.ts +174 -18
  97. package/src/runs/background/stale-run-reconciler.ts +13 -4
  98. package/src/runs/background/steering.ts +8 -15
  99. package/src/runs/background/subagent-runner.ts +959 -1159
  100. package/src/runs/background/subagent-wait.ts +86 -31
  101. package/src/runs/background/terminal-run-index.ts +1 -1
  102. package/src/runs/background/wait-completions.ts +45 -2
  103. package/src/runs/background/wait-config.ts +23 -9
  104. package/src/runs/background/wait-tool.ts +27 -19
  105. package/src/runs/foreground/async-steering-action.ts +3 -19
  106. package/src/runs/foreground/async-stop-action.ts +23 -2
  107. package/src/runs/foreground/execution.ts +585 -481
  108. package/src/runs/foreground/foreground-control.ts +13 -0
  109. package/src/runs/foreground/foreground-history.ts +26 -3
  110. package/src/runs/foreground/subagent-executor.ts +1549 -410
  111. package/src/runs/foreground/workflow-detach-reconcile.ts +141 -104
  112. package/src/runs/foreground/workflow-foreground-steering.ts +24 -98
  113. package/src/runs/shared/abort-recovery.ts +119 -0
  114. package/src/runs/shared/acceptance.ts +147 -39
  115. package/src/runs/shared/agent-contract.ts +1 -1
  116. package/src/runs/shared/async-status-projection.ts +565 -0
  117. package/src/runs/shared/background-process-options.ts +9 -0
  118. package/src/runs/shared/capability-ceiling.ts +2 -2
  119. package/src/runs/shared/child-hooks.ts +25 -0
  120. package/src/runs/shared/child-identity.ts +62 -0
  121. package/src/runs/shared/child-launch-plan.ts +151 -0
  122. package/src/runs/shared/child-launch.ts +314 -0
  123. package/src/runs/shared/child-lifecycle.ts +25 -0
  124. package/src/runs/shared/child-runtime-config.ts +126 -0
  125. package/src/runs/shared/child-session.ts +342 -0
  126. package/src/runs/shared/child-tool-plan.ts +540 -0
  127. package/src/runs/shared/claude-code-adapter.ts +133 -0
  128. package/src/runs/shared/codex-exec-adapter.ts +129 -0
  129. package/src/runs/shared/completion-evidence.ts +89 -0
  130. package/src/runs/shared/completion-guard.ts +57 -6
  131. package/src/runs/shared/cursor-agent-adapter.ts +114 -0
  132. package/src/runs/shared/dynamic-fanout.ts +4 -4
  133. package/src/runs/shared/extension-bindings.ts +78 -0
  134. package/src/runs/shared/external-cli-contract.ts +167 -0
  135. package/src/runs/shared/external-cli-preflight.ts +138 -0
  136. package/src/runs/shared/external-cli-runner.ts +349 -54
  137. package/src/runs/shared/external-job-bridge.ts +53 -37
  138. package/src/runs/shared/external-job-runner.ts +126 -23
  139. package/src/runs/shared/fast-mode-extension.ts +10 -0
  140. package/src/runs/shared/host-step-status.ts +231 -0
  141. package/src/runs/shared/lane-metadata.ts +126 -0
  142. package/src/runs/shared/launch-cwd.ts +16 -0
  143. package/src/runs/shared/long-running-guard.ts +2 -1
  144. package/src/runs/shared/mcp-config-sources.ts +422 -0
  145. package/src/runs/shared/mcp-direct-tool-allowlist.ts +222 -158
  146. package/src/runs/shared/mcp-direct-tool-grant.ts +194 -0
  147. package/src/runs/shared/model-exclusions.ts +141 -10
  148. package/src/runs/shared/model-fallback.ts +187 -33
  149. package/src/runs/shared/model-scope.ts +106 -39
  150. package/src/runs/shared/mutation-evidence.ts +199 -0
  151. package/src/runs/shared/nested-events.ts +38 -48
  152. package/src/runs/shared/nested-path.ts +0 -14
  153. package/src/runs/shared/nested-render.ts +9 -5
  154. package/src/runs/shared/orca-progress-tabs.ts +83 -16
  155. package/src/runs/shared/parallel-handoff.ts +423 -7
  156. package/src/runs/shared/parallel-utils.ts +28 -5
  157. package/src/runs/shared/permissions.ts +1 -14
  158. package/src/runs/shared/pi-spawn.ts +69 -35
  159. package/src/runs/shared/process-signal.ts +16 -0
  160. package/src/runs/shared/run-fanout-budget.ts +0 -13
  161. package/src/runs/shared/run-history.ts +21 -1
  162. package/src/runs/shared/runtime-acknowledged-extensions.ts +0 -27
  163. package/src/runs/shared/single-output.ts +89 -22
  164. package/src/runs/shared/structured-output.ts +61 -7
  165. package/src/runs/shared/subagent-control.ts +6 -2
  166. package/src/runs/shared/subagent-prompt-runtime.ts +216 -360
  167. package/src/runs/shared/task-intent.ts +21 -7
  168. package/src/runs/shared/tool-availability.ts +18 -64
  169. package/src/runs/shared/tool-budget.ts +0 -14
  170. package/src/runs/shared/tool-timeout.ts +1 -1
  171. package/src/runs/shared/workflow-graph.ts +16 -0
  172. package/src/runs/shared/worktree-cleanup-plan.ts +866 -0
  173. package/src/runs/shared/worktree.ts +571 -62
  174. package/src/shared/atomic-json.ts +3 -1
  175. package/src/shared/child-session-name.ts +46 -0
  176. package/src/shared/extension-context.ts +24 -0
  177. package/src/shared/fork-context.ts +21 -12
  178. package/src/shared/fork-session-cwd.ts +27 -0
  179. package/src/shared/formatters.ts +18 -3
  180. package/src/shared/jsonl-writer.ts +11 -0
  181. package/src/shared/launch-contract.ts +20 -6
  182. package/src/shared/pruned-fork.ts +450 -0
  183. package/src/shared/session-file-trust.ts +19 -0
  184. package/src/shared/session-tokens.ts +14 -3
  185. package/src/shared/settings.ts +21 -102
  186. package/src/shared/shortcuts.ts +17 -0
  187. package/src/shared/thinking-ceiling.ts +46 -0
  188. package/src/shared/types.ts +644 -75
  189. package/src/shared/utils.ts +60 -93
  190. package/src/shared/workflow-child-permit.ts +207 -0
  191. package/src/slash/delegation-adapters.ts +1 -9
  192. package/src/slash/delegation-request.ts +0 -4
  193. package/src/slash/prompt-template-bridge.ts +37 -1
  194. package/src/slash/slash-bridge.ts +1 -2
  195. package/src/slash/slash-commands.ts +383 -116
  196. package/src/slash/slash-live-state.ts +22 -11
  197. package/src/slash/subagents-admin.ts +29 -12
  198. package/src/tui/fleet-native-transcript.ts +4 -0
  199. package/src/tui/fleet-status.ts +278 -90
  200. package/src/tui/fleet-transcript.ts +11 -5
  201. package/src/tui/fleet.ts +54 -28
  202. package/src/tui/render-helpers.ts +31 -0
  203. package/src/tui/render.ts +1433 -166
  204. package/src/watchdog/change-signature.ts +40 -1
  205. package/src/watchdog/child-status.ts +54 -34
  206. package/src/watchdog/diff-tool.ts +77 -0
  207. package/src/watchdog/emission-guard.ts +5 -3
  208. package/src/watchdog/guidance.ts +20 -0
  209. package/src/watchdog/permission-arbiter.ts +59 -52
  210. package/src/watchdog/register-child.ts +28 -25
  211. package/src/watchdog/register-main.ts +10 -9
  212. package/src/watchdog/render.ts +4 -5
  213. package/src/watchdog/review.ts +15 -4
  214. package/src/watchdog/rules.ts +70 -0
  215. package/src/watchdog/runtime.ts +75 -92
  216. package/src/watchdog/scope.ts +0 -11
  217. package/src/watchdog/settings.ts +48 -104
  218. package/src/watchdog/turn-delta.ts +1 -1
  219. package/src/watchdog/types.ts +18 -32
  220. package/src/watchdog/warning-format.ts +0 -1
  221. package/src/workflows/chat-progress.ts +7 -3
  222. package/src/workflows/host-command.ts +235 -0
  223. package/src/workflows/scripted-workflow.ts +1142 -69
  224. package/src/workflows/workflow-checklist.ts +439 -0
  225. package/src/workflows/workflow-child-summary.ts +121 -0
  226. package/src/workflows/workflow-preflight.ts +297 -0
  227. package/src/workflows/workflow-receipt.ts +232 -6
  228. package/src/workflows/workflow-resources.ts +150 -0
  229. package/src/workflows/workflow-settlement.ts +246 -0
  230. package/src/runs/shared/child-protocol.ts +0 -401
  231. package/src/runs/shared/pi-args.ts +0 -858
  232. package/src/runs/shared/subagent-startup-retry.ts +0 -116
  233. package/src/runs/shared/turn-budget.ts +0 -98
  234. package/src/shared/post-exit-stdio-guard.ts +0 -85
@@ -25,6 +25,7 @@ import { recordWaitCompletion } from "./wait-completions.ts";
25
25
  import { MISSION_BINDING_FILE, syncMissionFromAsyncCompletion } from "../../missions/lifecycle.ts";
26
26
  import { missionObserverResultCandidateFiles, promotePendingResultFile, removeMissionObserverIndex, removeResultIndex, resultCandidateFilesForSession, resultPayloadPathForIndexedRun, resultPayloadPathForMissionObserverRun, resultPayloadPathForSessionRun, writeAsyncResultFile, writeResultIndexForData } from "./result-files.ts";
27
27
  import type { CompletionNotifier, CompletionNotification } from "./notify.ts";
28
+ import type { ResultDeliveryOwnership } from "./result-delivery-ownership.ts";
28
29
 
29
30
  const WATCHER_RESTART_DELAY_MS = 3000;
30
31
  const POLL_INTERVAL_MS = 3000;
@@ -57,13 +58,16 @@ type ResultWatcherDeps = {
57
58
  coalesceDelayMs?: number;
58
59
  /** Returns true while a durable completion source needs periodic delivery checks. */
59
60
  hasDeliveryDemand?: () => boolean;
60
- /** Control how slow result-index scans are logged. Defaults to \"all\". */
61
+ /** Control how slow result-index scans are logged. Defaults to \"activity\". */
61
62
  resultScanLogging?: "all" | "activity" | "off";
62
63
  platform?: NodeJS.Platform;
64
+ /** Shared current/predecessor session ownership used by the notifier. */
65
+ ownership?: Pick<ResultDeliveryOwnership, "owns" | "claimedSessionIds">;
63
66
  };
64
67
 
65
68
  type ResultFileChild = {
66
69
  agent?: string;
70
+ sessionName?: string;
67
71
  output?: string;
68
72
  structuredOutput?: unknown;
69
73
  outputState?: SubagentOutputState;
@@ -148,6 +152,10 @@ function isNotFound(error: unknown): boolean {
148
152
  return errorCode(error) === "ENOENT";
149
153
  }
150
154
 
155
+ function isAbsentResultCandidate(error: unknown): boolean {
156
+ return isNotFound(error) || errorCode(error) === "ENAMETOOLONG";
157
+ }
158
+
151
159
  function isAccessDenied(error: unknown): boolean {
152
160
  const code = errorCode(error);
153
161
  return code === "EPERM" || code === "EACCES";
@@ -196,6 +204,7 @@ export function createResultWatcher(
196
204
  deps: ResultWatcherDeps = {},
197
205
  ): {
198
206
  startResultWatcher: () => void;
207
+ transitionResultDelivery: () => void;
199
208
  primeExistingResults: (options?: { triggerTurn?: boolean }) => void;
200
209
  refreshResultDelivery: () => void;
201
210
  stopResultWatcher: () => void;
@@ -214,14 +223,16 @@ export function createResultWatcher(
214
223
  // The sole in-memory ownership lease. It is acquired for one active session
215
224
  // and revoked before the watcher, queues, or callbacks are torn down.
216
225
  let activeSessionId: string | null = null;
226
+ const ownsResult = deps.ownership?.owns
227
+ ?? ((sessionId: string, completionOwnerId: unknown) => sessionId === state.currentSessionId
228
+ && typeof completionOwnerId === "string"
229
+ && completionOwnerId === state.completionOwnerId);
230
+ const claimedSessionIds = () => deps.ownership?.claimedSessionIds() ?? [];
217
231
 
218
232
  const ownsCompletion = (sessionId: string, completionOwnerId: unknown, epoch: number) => {
219
233
  if (!deliveryActive || epoch !== deliveryEpoch) return false;
220
234
  if (!activeSessionId && state.currentSessionId) activeSessionId = state.currentSessionId;
221
- return activeSessionId === sessionId
222
- && state.currentSessionId === sessionId
223
- && typeof completionOwnerId === "string"
224
- && completionOwnerId === state.completionOwnerId;
235
+ return activeSessionId === state.currentSessionId && ownsResult(sessionId, completionOwnerId);
225
236
  };
226
237
 
227
238
  const scheduleResult = (file: string, triggerTurn: boolean, delayMs = 0) => {
@@ -235,15 +246,18 @@ export function createResultWatcher(
235
246
  try {
236
247
  return fsApi.statSync(publicResultPath(file)).isFile();
237
248
  } catch (error) {
238
- if (!isNotFound(error)) console.error(`Failed to inspect subagent result file '${publicResultPath(file)}':`, error);
249
+ if (!isAbsentResultCandidate(error)) console.error(`Failed to inspect subagent result file '${publicResultPath(file)}':`, error);
239
250
  return false;
240
251
  }
241
252
  };
242
253
  const resultPayloadPath = (file: string, observed?: ReadonlySet<string>): string | undefined => {
243
254
  if (file !== path.basename(file) || !file.endsWith(".json")) return undefined;
244
255
  const runId = file.replace(/\.json$/i, "");
245
- const sessionResult = state.currentSessionId ? resultPayloadPathForSessionRun(resultsDir, state.currentSessionId, runId) : undefined;
246
- if (sessionResult) return sessionResult;
256
+ for (const sessionId of [state.currentSessionId, ...claimedSessionIds()]) {
257
+ if (!sessionId) continue;
258
+ const sessionResult = resultPayloadPathForSessionRun(resultsDir, sessionId, runId);
259
+ if (sessionResult) return sessionResult;
260
+ }
247
261
  const observerResult = resultPayloadPathForMissionObserverRun(resultsDir, runId);
248
262
  if (observerResult) return observerResult;
249
263
  if (observed?.has(runId)) {
@@ -265,7 +279,7 @@ export function createResultWatcher(
265
279
  } catch (error) {
266
280
  identityCache.delete(file);
267
281
  if (isAccessDenied(error)) throw error;
268
- if (!isNotFound(error)) console.error(`Failed to inspect subagent result file '${resultPath}':`, error);
282
+ if (!isAbsentResultCandidate(error)) console.error(`Failed to inspect subagent result file '${resultPath}':`, error);
269
283
  return undefined;
270
284
  }
271
285
  };
@@ -283,7 +297,7 @@ export function createResultWatcher(
283
297
  } catch (error) {
284
298
  identityCache.delete(file);
285
299
  if (isAccessDenied(error)) throw error;
286
- if (!isNotFound(error)) console.error(`Failed to inspect subagent result file '${resultPath}':`, error);
300
+ if (!isAbsentResultCandidate(error)) console.error(`Failed to inspect subagent result file '${resultPath}':`, error);
287
301
  return undefined;
288
302
  }
289
303
  };
@@ -304,7 +318,7 @@ export function createResultWatcher(
304
318
  // Missing identity stays on the normal parser path so malformed or legacy
305
319
  // files keep their existing diagnostics and compatibility behavior.
306
320
  if (!identity.sessionId) return true;
307
- if (identity.sessionId === state.currentSessionId && identity.completionOwnerId === state.completionOwnerId) return true;
321
+ if (ownsResult(identity.sessionId, identity.completionOwnerId)) return true;
308
322
  if (identity.asyncDir && fsApi.existsSync(path.join(identity.asyncDir, MISSION_BINDING_FILE))) return true;
309
323
  if (identity.runId && (observed ?? observedRunIds()).has(identity.runId)) return true;
310
324
  return Boolean(deps.observeCompletion && !deps.observedCompletionRunIds);
@@ -317,7 +331,7 @@ export function createResultWatcher(
317
331
  removeResultIndex(resultsDir, sessionId, runId, toolCallId);
318
332
  return true;
319
333
  } catch (error) {
320
- if (!isNotFound(error)) {
334
+ if (!isAbsentResultCandidate(error)) {
321
335
  console.error(`Failed to remove delivered subagent result '${publicResultPath(file)}'; will retry:`, error);
322
336
  return false;
323
337
  }
@@ -384,7 +398,7 @@ export function createResultWatcher(
384
398
  if (!resultPayloadWasReplaced(data, readPublicResultIdentity())) return false;
385
399
  } catch (error) {
386
400
  if (isAccessDenied(error)) throw error;
387
- if (isNotFound(error)) return false;
401
+ if (isAbsentResultCandidate(error)) return false;
388
402
  console.error(`Failed to re-read subagent result file '${publicResultPath(file)}':`, error);
389
403
  }
390
404
  identityCache.delete(file);
@@ -412,7 +426,7 @@ export function createResultWatcher(
412
426
  if (observerSucceeded) removeMissionObserverIndex(resultsDir, runId);
413
427
  const epoch = deliveryEpoch;
414
428
  if (!ownsCompletion(sessionId, completionOwnerId, epoch)) return;
415
- // Recorded before dedupe and before the unlink below so subagent_wait can
429
+ // Recorded before dedupe and before the unlink below so bg_wait can
416
430
  // use the in-memory record or its bounded durable replay after cleanup.
417
431
  recordWaitCompletion(state, runId, data, Date.now(), completionTtlMs, {
418
432
  resultsDir,
@@ -469,6 +483,7 @@ export function createResultWatcher(
469
483
  : undefined;
470
484
  return {
471
485
  agent: result.agent ?? data.agent ?? `step-${index + 1}`,
486
+ ...(result.sessionName ? { sessionName: result.sessionName } : {}),
472
487
  status: resolveSubagentResultStatus({
473
488
  success: result.success,
474
489
  state: childState,
@@ -606,18 +621,20 @@ export function createResultWatcher(
606
621
  const logScanStats = (stats: ResultScanStats) => {
607
622
  const elapsed = Date.now() - stats.startedAt;
608
623
  if (elapsed < SLOW_RESULT_SCAN_MS) return;
609
- if (deps.resultScanLogging === "off") return;
624
+ const resultScanLogging = deps.resultScanLogging ?? "activity";
625
+ if (resultScanLogging === "off") return;
610
626
  // A scan that inspected and scheduled nothing is a quiet no-op (e.g. the
611
627
  // healthy periodic rescan while no async runs are pending). Under
612
628
  // "activity", skip it so empty scans do not burn context tokens in the
613
629
  // session transcript.
614
- if (deps.resultScanLogging === "activity" && stats.files === 0 && stats.scheduled === 0) return;
630
+ if (resultScanLogging === "activity" && stats.files === 0 && stats.scheduled === 0) return;
615
631
  console.error(`Subagent result scan inspected ${stats.files} indexed result file(s), scheduled ${stats.scheduled} in ${elapsed}ms (${resultsDir}).`);
616
632
  };
617
633
  const indexedResultCandidates = (observed: ReadonlySet<string>): string[] => {
618
634
  const files = new Set<string>();
619
- if (state.currentSessionId) {
620
- for (const file of resultCandidateFilesForSession(resultsDir, state.currentSessionId)) files.add(file);
635
+ for (const sessionId of [state.currentSessionId, ...claimedSessionIds()]) {
636
+ if (!sessionId) continue;
637
+ for (const file of resultCandidateFilesForSession(resultsDir, sessionId)) files.add(file);
621
638
  }
622
639
  for (const runId of state.asyncJobs.keys()) files.add(`${runId}.json`);
623
640
  for (const file of missionObserverResultCandidateFiles(resultsDir)) files.add(file);
@@ -750,6 +767,13 @@ export function createResultWatcher(
750
767
  }
751
768
  };
752
769
 
770
+ const transitionResultDelivery = () => {
771
+ deliveryActive = true;
772
+ activeSessionId = state.currentSessionId;
773
+ deliveryEpoch += 1;
774
+ identityCache.clear();
775
+ };
776
+
753
777
  const stopResultWatcher = () => {
754
778
  deliveryActive = false;
755
779
  activeSessionId = null;
@@ -764,5 +788,5 @@ export function createResultWatcher(
764
788
  identityCache.clear();
765
789
  };
766
790
 
767
- return { startResultWatcher, primeExistingResults, stopResultWatcher, refreshResultDelivery: () => { primeExistingResults(); startDemandPolling(); } };
791
+ return { startResultWatcher, transitionResultDelivery, primeExistingResults, stopResultWatcher, refreshResultDelivery: () => { primeExistingResults(); startDemandPolling(); } };
768
792
  }
@@ -12,7 +12,7 @@ function isIntercomDetached(run: AsyncRunSummary): boolean {
12
12
 
13
13
  function formatIntercomDetachGuidance(run: AsyncRunSummary): string | undefined {
14
14
  if (!isIntercomDetached(run)) return undefined;
15
- return `Run "${run.id}" detached for intercom coordination. Reply to the supervisor request first, then wait with subagent_wait({ id: "${run.id}" }). Use subagent({ action: "status", id: "${run.id}" }) to recover the result; do not resume or launch a replacement while it remains detached.`;
15
+ return `Run "${run.id}" detached for intercom coordination. Reply to the supervisor request first, then wait with bg_wait({ id: "${run.id}" }). Use subagent({ action: "status", id: "${run.id}" }) to recover the result; do not resume or launch a replacement while it remains detached.`;
16
16
  }
17
17
 
18
18
  export function formatAsyncReviveCommand(run: AsyncRunSummary): string | undefined {
@@ -39,7 +39,7 @@ export function formatResumeFirstFailedRunDetail(run: AsyncRunSummary): string |
39
39
  }
40
40
 
41
41
  export function formatResumeFirstFailedRunsNote(runs: AsyncRunSummary[]): string {
42
- const failedRuns = runs.filter((run) => run.state === "failed");
42
+ const failedRuns = runs.filter((run) => run.state === "failed" || run.state === "partial");
43
43
  const detachGuidance = failedRuns
44
44
  .map(formatIntercomDetachGuidance)
45
45
  .filter((guidance): guidance is string => Boolean(guidance));
@@ -27,7 +27,7 @@ export interface RetainedChild {
27
27
  }
28
28
 
29
29
  function isRetainedChildState(state: AsyncRunSummary["state"]): state is RetainedChildState {
30
- return state === "complete" || state === "failed" || state === "paused" || state === "stopped";
30
+ return state === "complete" || state === "failed" || state === "partial" || state === "paused" || state === "stopped";
31
31
  }
32
32
 
33
33
  function isTerminalStepStatus(status: AsyncRunSummary["steps"][number]["status"]): boolean {