@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
@@ -1,8 +1,9 @@
1
1
  import * as fs from "node:fs";
2
2
  import * as path from "node:path";
3
3
  import { formatDuration, formatModelThinking, formatTokens, shortenPath } from "../../shared/formatters.ts";
4
+ import { previewDisplayText } from "../../shared/display-text.ts";
4
5
  import { formatActivityLabel, formatParallelOutcome } from "../../shared/status-format.ts";
5
- import { type ActivityState, type AsyncJobStep, type AsyncParallelGroupStatus, type AsyncStatus, type CostSummary, type Details, type LaunchResolvedChildExtensionsV1, type RuntimeAcknowledgedChildExtensionsV1, type NestedRunSummary, type SteeringStatus, type SubagentRunMode, type TokenUsage, type TurnBudgetState, type UsageBudgetState } from "../../shared/types.ts";
6
+ import { type ActivityState, type AsyncJobStep, type AsyncParallelGroupStatus, type AsyncStatus, type CostSummary, type Details, type HostStepNodeV1, type HostStepState, type LaunchResolvedChildExtensionsV1, type RuntimeAcknowledgedChildExtensionsV1, type NestedRunSummary, type SteeringStatus, type SubagentRunMode, type TimeoutRecoveryProjection, type TokenUsage, type TurnBudgetState, type UsageBudgetState, type WorktreeNaming, type WorkflowPreflightV1, type WorkflowGraphSnapshot } from "../../shared/types.ts";
6
7
  import type { ResolvedSubagentCapabilityCeiling, SubagentCapabilityAudit } from "../shared/capability-ceiling.ts";
7
8
  import { readStatus } from "../../shared/utils.ts";
8
9
  import { attachRootChildrenToSteps, buildNestedRouteIndex, findNestedRouteForRootId, type NestedRoute, projectNestedEvents } from "../shared/nested-events.ts";
@@ -15,14 +16,33 @@ import { readProcessTerminal, sanitizeProcessTerminal } from "./process-terminal
15
16
  import { ACTIVE_RUN_INDEX_DIR, DEFAULT_STALE_TERMINAL_ACTIVE_MARKER_MS, activeRunMarkerAgeMs, isActiveAsyncState, readActiveRunIndex, releaseActiveRunIndex, updateActiveRunIndex } from "./active-run-index.ts";
16
17
  import { readRecentTerminalRunIndex, TERMINAL_RUN_INDEX_DIR } from "./terminal-run-index.ts";
17
18
  import { canScanAsyncRunPrefix } from "./run-id-query.ts";
19
+ import { asyncStatusChildIdentity } from "../shared/child-identity.ts";
20
+ import { parseWorkflowChildSummary } from "../../workflows/workflow-child-summary.ts";
21
+ import { assertWorkflowGraphHostSteps, hostStepReportName, hostStepVerdictLabel, validHostStepNodes } from "../shared/host-step-status.ts";
22
+ import { projectAsyncWorkflowRows } from "../shared/async-status-projection.ts";
23
+ import { validateAsyncStatusLaneMetadata } from "../shared/lane-metadata.ts";
24
+ import { formatWorkflowPreflightPlanSummary, formatWorkflowPreflightWarningSummary } from "../../workflows/workflow-preflight.ts";
25
+ import { workflowGraphStageNodes } from "../shared/workflow-graph.ts";
26
+ import { formatTimeoutRecoveryLines, projectTimeoutRecovery } from "../shared/mutation-evidence.ts";
27
+ import { formatWorkflowChecklistText, projectWorkflowChecklist } from "../../workflows/workflow-checklist.ts";
18
28
 
19
29
  interface AsyncRunStepSummary {
20
30
  index: number;
31
+ childId?: string;
21
32
  agent: string;
33
+ /** Human-readable display name for the child session, when derived at launch. */
34
+ sessionName?: string;
22
35
  context?: ContextMode;
23
36
  label?: string;
24
37
  description?: string;
25
38
  phase?: string;
39
+ workflowKey?: string;
40
+ lane?: AsyncJobStep["lane"];
41
+ worktreePath?: string;
42
+ branch?: string;
43
+ provider?: "native" | "worktrunk";
44
+ naming?: WorktreeNaming;
45
+ runId?: string;
26
46
  outputName?: string;
27
47
  structured?: boolean;
28
48
  status: AsyncJobStep["status"];
@@ -43,6 +63,7 @@ interface AsyncRunStepSummary {
43
63
  totalCost?: CostSummary;
44
64
  skills?: string[];
45
65
  model?: string;
66
+ contextLimit?: number;
46
67
  thinking?: string;
47
68
  attemptedModels?: string[];
48
69
  sessionFile?: string;
@@ -52,6 +73,7 @@ interface AsyncRunStepSummary {
52
73
  stopped?: boolean;
53
74
  turnBudget?: TurnBudgetState;
54
75
  turnBudgetExceeded?: boolean;
76
+ toolBudgetBlocked?: boolean;
55
77
  wrapUpRequested?: boolean;
56
78
  acceptance?: AsyncJobStep["acceptance"];
57
79
  agentContract?: AsyncJobStep["agentContract"];
@@ -59,6 +81,7 @@ interface AsyncRunStepSummary {
59
81
  review?: AsyncJobStep["review"];
60
82
  effects?: AsyncJobStep["effects"];
61
83
  processTerminal?: AsyncJobStep["processTerminal"];
84
+ timeoutRecovery?: TimeoutRecoveryProjection;
62
85
  launchResolvedExtensions?: LaunchResolvedChildExtensionsV1;
63
86
  runtimeAcknowledgedExtensions?: RuntimeAcknowledgedChildExtensionsV1;
64
87
  capabilityCeiling?: ResolvedSubagentCapabilityCeiling;
@@ -71,7 +94,7 @@ export interface AsyncRunSummary {
71
94
  asyncDir: string;
72
95
  toolCallId?: string;
73
96
  sessionId?: string;
74
- state: "queued" | "running" | "complete" | "failed" | "paused" | "stopped" | "rejected";
97
+ state: "queued" | "running" | "complete" | "failed" | "partial" | "paused" | "stopped" | "rejected";
75
98
  error?: string;
76
99
  activityState?: ActivityState;
77
100
  lastActivityAt?: number;
@@ -99,6 +122,8 @@ export interface AsyncRunSummary {
99
122
  chainStepCount?: number;
100
123
  pendingAppends?: number;
101
124
  parallelGroups?: AsyncParallelGroupStatus[];
125
+ hostSteps?: HostStepNodeV1[];
126
+ workflowGraph?: AsyncStatus["workflowGraph"];
102
127
  steps: AsyncRunStepSummary[];
103
128
  sessionDir?: string;
104
129
  outputFile?: string;
@@ -116,7 +141,10 @@ export interface AsyncRunSummary {
116
141
  capabilityAudit?: SubagentCapabilityAudit;
117
142
  parentWorkflowRunId?: string;
118
143
  workflowKey?: string;
144
+ lane?: AsyncStatus["lane"];
119
145
  workflow?: Details["workflow"];
146
+ workflowChildren?: Details["workflowChildren"];
147
+ preflight?: WorkflowPreflightV1;
120
148
  }
121
149
 
122
150
  interface AsyncRunListOptions {
@@ -141,6 +169,40 @@ function getErrorMessage(error: unknown): string {
141
169
  return error instanceof Error ? error.message : String(error);
142
170
  }
143
171
 
172
+ function isAsyncStatusIsolationError(asyncDir: string, error: unknown): boolean {
173
+ const statusPath = path.join(asyncDir, "status.json");
174
+ const message = getErrorMessage(error);
175
+ return /^(?:Failed to (?:inspect|read|parse|validate) async status file|Invalid async status file) '/.test(message)
176
+ || message.startsWith(`Invalid async status '${statusPath}'`)
177
+ || message.startsWith(`Invalid host step '${statusPath}`)
178
+ || /^(workflowChildren|Invalid workflowChildren)/.test(message);
179
+ }
180
+
181
+ function isolateCorruptActiveRun(asyncDir: string, runId: string, error: unknown, now?: () => number): void {
182
+ const statusPath = path.join(asyncDir, "status.json");
183
+ const processTerminal = readProcessTerminal(asyncDir, { runId });
184
+ let markerAge: number | undefined;
185
+ try {
186
+ markerAge = activeRunMarkerAgeMs(asyncDir, now?.());
187
+ } catch (markerError) {
188
+ console.error(`Failed to inspect corrupt async active-run marker for '${runId}':`, markerError);
189
+ }
190
+ const markerCanBeReleased = processTerminal?.state === "observed"
191
+ || (markerAge !== undefined && markerAge > DEFAULT_STALE_TERMINAL_ACTIVE_MARKER_MS);
192
+ let markerAction = "active marker retained because runner liveness is unknown";
193
+ if (markerCanBeReleased) {
194
+ try {
195
+ releaseActiveRunIndex(asyncDir);
196
+ markerAction = processTerminal?.state === "observed"
197
+ ? "active marker released after observed process-terminal proof"
198
+ : "stale active marker released";
199
+ } catch (releaseError) {
200
+ markerAction = `failed to release active marker: ${getErrorMessage(releaseError)}`;
201
+ }
202
+ }
203
+ console.error(`[pi-subagents] Skipping corrupt active async run '${runId}' at '${statusPath}': ${getErrorMessage(error)}; ${markerAction}.`);
204
+ }
205
+
144
206
  function isNotFoundError(error: unknown): boolean {
145
207
  return typeof error === "object"
146
208
  && error !== null
@@ -225,19 +287,34 @@ function deriveAsyncActivityState(asyncDir: string, status: AsyncStatus): { acti
225
287
  }
226
288
 
227
289
  function statusToSummary(asyncDir: string, status: AsyncStatus & { cwd?: string }, nestedWarnings: string[] = [], nestedRoute?: NestedRoute): AsyncRunSummary {
290
+ const statusPath = path.join(asyncDir, "status.json");
291
+ validateAsyncStatusLaneMetadata(status, `Invalid async status '${statusPath}'`);
292
+ const workflowChildren = parseWorkflowChildSummary(status.workflowChildren);
293
+ if (workflowChildren && workflowChildren.workflowRunId !== status.runId) throw new Error(`Invalid async status '${statusPath}': workflowChildren.workflowRunId does not match.`);
294
+ assertWorkflowGraphHostSteps(status.workflowGraph, statusPath, status.runId);
295
+ const hostSteps = validHostStepNodes(status.workflowGraph);
228
296
  if (status.sessionId !== undefined && typeof status.sessionId !== "string") {
229
- throw new Error(`Invalid async status '${path.join(asyncDir, "status.json")}': sessionId must be a string.`);
297
+ throw new Error(`Invalid async status '${statusPath}': sessionId must be a string.`);
230
298
  }
299
+ if (status.outputFile !== undefined && typeof status.outputFile !== "string") throw new Error(`Invalid async status '${statusPath}': outputFile must be a string.`);
231
300
  const { activityState, lastActivityAt } = deriveAsyncActivityState(asyncDir, status);
232
301
  const processTerminal = readProcessTerminal(asyncDir, { runId: status.runId, runnerProcessInstanceId: status.processTerminal?.runnerProcessInstanceId })
233
302
  ?? sanitizeProcessTerminal(status.processTerminal, { runId: status.runId, runnerProcessInstanceId: status.processTerminal?.runnerProcessInstanceId }, path.join(asyncDir, "status.json"));
234
- const runFanoutBudgetDescriptor = readRunFanoutBudgetDescriptor(asyncDir);
235
- const runFanoutBudget = runFanoutBudgetDescriptor ? getRunFanoutBudgetSnapshot(runFanoutBudgetDescriptor) : status.runFanoutBudget;
303
+ const nestedProjectionAllowed = nestedWarnings.length === 0;
304
+ // Degrade to the status-stored snapshot when the persisted budget is unavailable (e.g. removed
305
+ // by OS temp cleanup) instead of failing the whole run list; admission paths stay strict.
306
+ let runFanoutBudget: AsyncStatus["runFanoutBudget"] = status.runFanoutBudget;
307
+ try {
308
+ const runFanoutBudgetDescriptor = readRunFanoutBudgetDescriptor(asyncDir);
309
+ if (runFanoutBudgetDescriptor) runFanoutBudget = getRunFanoutBudgetSnapshot(runFanoutBudgetDescriptor);
310
+ } catch (error) {
311
+ nestedWarnings.push(`Run fan-out status unavailable: ${getErrorMessage(error)}`);
312
+ }
236
313
  const steps = status.steps ?? [];
237
314
  const chainStepCount = status.chainStepCount ?? steps.length;
238
315
  const parallelGroups = normalizeParallelGroups(status.parallelGroups, steps.length, chainStepCount);
239
316
  let nestedChildren: NestedRunSummary[] = [];
240
- if (nestedWarnings.length === 0 && nestedRoute) {
317
+ if (nestedProjectionAllowed && nestedRoute) {
241
318
  try {
242
319
  // The route is resolved by the caller via buildNestedRouteIndex, so this
243
320
  // avoids a fresh scan of the nested-events directory per run.
@@ -249,13 +326,23 @@ function statusToSummary(asyncDir: string, status: AsyncStatus & { cwd?: string
249
326
  const summarizedSteps = steps.map((step, index) => {
250
327
  const stepActivityState = step.activityState;
251
328
  const stepLastActivityAt = step.lastActivityAt;
329
+ const timeoutRecovery = projectTimeoutRecovery(step.timeoutRecovery);
252
330
  return {
253
331
  index,
332
+ childId: asyncStatusChildIdentity(step, index),
254
333
  agent: step.agent,
334
+ ...(step.sessionName ? { sessionName: step.sessionName } : {}),
255
335
  ...(step.context ? { context: step.context } : {}),
256
336
  ...(step.label ? { label: step.label } : {}),
257
337
  ...(step.description ? { description: step.description } : {}),
258
338
  ...(step.phase ? { phase: step.phase } : {}),
339
+ ...(step.workflowKey ? { workflowKey: step.workflowKey } : {}),
340
+ ...(step.lane ? { lane: step.lane } : {}),
341
+ ...(step.worktreePath ? { worktreePath: step.worktreePath } : {}),
342
+ ...(step.branch ? { branch: step.branch } : {}),
343
+ ...(step.provider ? { provider: step.provider } : {}),
344
+ ...(step.naming ? { naming: step.naming } : {}),
345
+ ...(step.runId ? { runId: step.runId } : {}),
259
346
  ...(step.outputName ? { outputName: step.outputName } : {}),
260
347
  ...(step.structured ? { structured: step.structured } : {}),
261
348
  status: step.status,
@@ -276,15 +363,20 @@ function statusToSummary(asyncDir: string, status: AsyncStatus & { cwd?: string
276
363
  ...(step.totalCost ? { totalCost: step.totalCost } : {}),
277
364
  ...(step.skills ? { skills: step.skills } : {}),
278
365
  ...(step.model ? { model: step.model } : {}),
366
+ ...(step.contextLimit !== undefined ? { contextLimit: step.contextLimit } : {}),
279
367
  ...(step.thinking ? { thinking: step.thinking } : {}),
368
+ ...(step.thinkingCeiling ? { thinkingCeiling: step.thinkingCeiling } : {}),
280
369
  ...(step.attemptedModels ? { attemptedModels: step.attemptedModels } : {}),
281
370
  ...(step.sessionFile ? { sessionFile: step.sessionFile } : {}),
282
371
  ...(step.transcriptPath ? { transcriptPath: step.transcriptPath } : {}),
283
372
  ...(step.error ? { error: step.error } : {}),
284
373
  ...(step.timedOut !== undefined ? { timedOut: step.timedOut } : {}),
285
374
  ...(step.stopped !== undefined ? { stopped: step.stopped } : {}),
375
+ ...(step.stopRequested !== undefined ? { stopRequested: step.stopRequested } : {}),
376
+ ...(step.stopRequestedAt !== undefined ? { stopRequestedAt: step.stopRequestedAt } : {}),
286
377
  ...(step.turnBudget ? { turnBudget: step.turnBudget } : {}),
287
378
  ...(step.turnBudgetExceeded !== undefined ? { turnBudgetExceeded: step.turnBudgetExceeded } : {}),
379
+ ...(step.toolBudgetBlocked !== undefined ? { toolBudgetBlocked: step.toolBudgetBlocked } : {}),
288
380
  ...(step.wrapUpRequested !== undefined ? { wrapUpRequested: step.wrapUpRequested } : {}),
289
381
  ...(step.acceptance ? { acceptance: step.acceptance } : {}),
290
382
  ...(step.agentContract ? { agentContract: step.agentContract } : {}),
@@ -294,7 +386,9 @@ function statusToSummary(asyncDir: string, status: AsyncStatus & { cwd?: string
294
386
  ...(step.execution ? { execution: step.execution } : {}),
295
387
  ...(step.review ? { review: step.review } : {}),
296
388
  ...(step.effects ? { effects: step.effects } : {}),
389
+ ...(step.watchdog ? { watchdog: step.watchdog } : {}),
297
390
  ...(step.processTerminal ? { processTerminal: sanitizeProcessTerminal(step.processTerminal, { runId: status.runId, runnerProcessInstanceId: step.processTerminal.runnerProcessInstanceId }, `${path.join(asyncDir, "status.json")} step ${index}`) } : {}),
391
+ ...(timeoutRecovery ? { timeoutRecovery } : {}),
298
392
  ...(step.capabilityCeiling ? { capabilityCeiling: step.capabilityCeiling } : {}),
299
393
  ...(step.capabilityAudit ? { capabilityAudit: step.capabilityAudit } : {}),
300
394
  ...(step.children?.length ? { children: step.children } : {}),
@@ -334,6 +428,8 @@ function statusToSummary(asyncDir: string, status: AsyncStatus & { cwd?: string
334
428
  ...(status.chainStepCount !== undefined ? { chainStepCount: status.chainStepCount } : {}),
335
429
  ...(status.pendingAppends !== undefined ? { pendingAppends: status.pendingAppends } : {}),
336
430
  ...(parallelGroups.length ? { parallelGroups } : {}),
431
+ ...(hostSteps.length ? { hostSteps } : {}),
432
+ ...(status.mode === "workflow" && status.workflowGraph ? { workflowGraph: status.workflowGraph } : {}),
337
433
  steps: summarizedSteps,
338
434
  ...(nestedChildren.length ? { nestedChildren } : {}),
339
435
  ...(nestedWarnings.length ? { nestedWarnings } : {}),
@@ -346,7 +442,10 @@ function statusToSummary(asyncDir: string, status: AsyncStatus & { cwd?: string
346
442
  ...(status.capabilityAudit ? { capabilityAudit: status.capabilityAudit } : {}),
347
443
  ...(status.parentWorkflowRunId ? { parentWorkflowRunId: status.parentWorkflowRunId } : {}),
348
444
  ...(status.workflowKey ? { workflowKey: status.workflowKey } : {}),
445
+ ...(status.lane ? { lane: status.lane } : {}),
349
446
  ...(status.workflow ? { workflow: status.workflow } : {}),
447
+ ...(workflowChildren ? { workflowChildren } : {}),
448
+ ...(status.preflight ? { preflight: status.preflight } : {}),
350
449
  ...(status.sessionDir ? { sessionDir: status.sessionDir } : {}),
351
450
  ...(status.outputFile ? { outputFile: status.outputFile } : {}),
352
451
  ...(status.totalTokens ? { totalTokens: status.totalTokens } : {}),
@@ -366,6 +465,7 @@ function sortRuns(runs: AsyncRunSummary[]): AsyncRunSummary[] {
366
465
  case "running": return 0;
367
466
  case "queued": return 1;
368
467
  case "failed": return 2;
468
+ case "partial": return 2;
369
469
  case "stopped": return 2;
370
470
  case "paused": return 2;
371
471
  case "complete": return 3;
@@ -440,10 +540,17 @@ export function listAsyncRuns(asyncDirRoot: string, options: AsyncRunListOptions
440
540
  };
441
541
  for (const entry of entries) {
442
542
  const asyncDir = path.join(asyncDirRoot, entry);
443
- const reconciliation = options.reconcile === false
444
- ? undefined
445
- : reconcileAsyncRun(asyncDir, { resultsDir: options.resultsDir, kill: options.kill, now: options.now });
446
- const status = (reconciliation?.status ?? readStatus(asyncDir)) as (AsyncStatus & { cwd?: string }) | null;
543
+ let status: (AsyncStatus & { cwd?: string }) | null;
544
+ try {
545
+ const reconciliation = options.reconcile === false
546
+ ? undefined
547
+ : reconcileAsyncRun(asyncDir, { resultsDir: options.resultsDir, kill: options.kill, now: options.now });
548
+ status = (reconciliation?.status ?? readStatus(asyncDir)) as (AsyncStatus & { cwd?: string }) | null;
549
+ } catch (error) {
550
+ if (!activeEntries.has(entry) || !isAsyncStatusIsolationError(asyncDir, error)) throw error;
551
+ isolateCorruptActiveRun(asyncDir, entry, error, options.now);
552
+ continue;
553
+ }
447
554
  if (!status) {
448
555
  if (activeEntries.has(entry)) updateActiveRunIndex(asyncDir, "failed");
449
556
  continue;
@@ -469,7 +576,14 @@ export function listAsyncRuns(asyncDirRoot: string, options: AsyncRunListOptions
469
576
  nestedWarnings.push(`Nested status unavailable: ${getErrorMessage(error)}`);
470
577
  }
471
578
  }
472
- const summary = statusToSummary(asyncDir, status, nestedWarnings, nestedRoute);
579
+ let summary: AsyncRunSummary;
580
+ try {
581
+ summary = statusToSummary(asyncDir, status, nestedWarnings, nestedRoute);
582
+ } catch (error) {
583
+ if (!activeEntries.has(entry) || !isAsyncStatusIsolationError(asyncDir, error)) throw error;
584
+ isolateCorruptActiveRun(asyncDir, entry, error, options.now);
585
+ continue;
586
+ }
473
587
  runs.push(summary);
474
588
  }
475
589
 
@@ -494,7 +608,7 @@ function formatActivityFacts(input: { activityState?: ActivityState; lastActivit
494
608
  }
495
609
 
496
610
  function formatStepLine(step: AsyncRunStepSummary): string {
497
- const display = step.label ? `${step.label} (${step.agent})` : step.agent;
611
+ const display = step.sessionName?.trim() || (step.label ? `${step.label} (${step.agent})` : step.agent);
498
612
  const context = contextModeLabel(step.context);
499
613
  const phase = step.phase ? `[${step.phase}] ` : "";
500
614
  const parts = [`${step.index + 1}. ${phase}${display}${context ? ` ${context}` : ""}`, step.status];
@@ -504,15 +618,61 @@ function formatStepLine(step: AsyncRunStepSummary): string {
504
618
  if (modelThinking) parts.push(modelThinking);
505
619
  if (step.durationMs !== undefined) parts.push(formatDuration(step.durationMs));
506
620
  if (step.tokens) parts.push(`${formatTokens(step.tokens.total)} tok`);
621
+ if (step.lane) parts.push(`lane ${step.lane.key}`);
622
+ if (step.worktreePath) parts.push(`worktree ${shortenPath(step.worktreePath)} · branch ${step.branch ?? "unknown"}${step.provider ? ` · provider ${step.provider}` : ""}`);
507
623
  return parts.join(" | ");
508
624
  }
509
625
 
626
+ function formatHostStepLine(row: ReturnType<typeof projectAsyncWorkflowRows>[number]): string {
627
+ if (!row.kind) return "";
628
+ const state = hostStepVerdictLabel(row.state as HostStepState, row.verdict);
629
+ const details = [
630
+ row.provider ? `provider:${row.provider}` : undefined,
631
+ row.role ? `role:${row.role}` : undefined,
632
+ row.target,
633
+ row.detail,
634
+ row.reasonCode ? `reason:${row.reasonCode}` : undefined,
635
+ row.freshness?.stale ? "stale" : row.freshness?.observedRef ? `ref:${row.freshness.observedRef}` : undefined,
636
+ row.reportPath ? `out:${hostStepReportName(row.reportPath)}` : undefined,
637
+ ].filter((value): value is string => Boolean(value));
638
+ return `host ${row.kind}: ${row.name} | ${state}${details.length ? ` | ${details.join(" | ")}` : ""}`;
639
+ }
640
+
641
+ function workflowStageStateLabel(status: WorkflowGraphSnapshot["nodes"][number]["status"]): string {
642
+ switch (status) {
643
+ case "completed":
644
+ return "complete";
645
+ case "detached":
646
+ return "paused";
647
+ default:
648
+ return status;
649
+ }
650
+ }
651
+
652
+ export function formatWorkflowStageLine(node: WorkflowGraphSnapshot["nodes"][number], index: number, total: number): string {
653
+ const state = workflowStageStateLabel(node.status);
654
+ const id = previewDisplayText(node.id, 160);
655
+ const label = node.label ? previewDisplayText(node.label, 160) : "";
656
+ const display = label && label !== id ? ` | ${label}` : "";
657
+ const agent = node.agent ? ` | ${previewDisplayText(node.agent, 80)}` : "";
658
+ const error = node.error ? ` | ${previewDisplayText(node.error, 240)}` : "";
659
+ return `stage ${index + 1}/${total}: ${id}${display}${agent} | ${state}${error}`;
660
+ }
661
+
510
662
  export function formatAsyncRunOutputPath(run: Pick<AsyncRunSummary, "asyncDir" | "outputFile">): string | undefined {
511
663
  if (!run.outputFile) return undefined;
512
664
  return path.isAbsolute(run.outputFile) ? run.outputFile : path.join(run.asyncDir, run.outputFile);
513
665
  }
514
666
 
515
- export function formatAsyncRunProgressLabel(run: Pick<AsyncRunSummary, "mode" | "state" | "currentStep" | "chainStepCount" | "parallelGroups" | "steps">): string {
667
+ export function formatAsyncRunProgressLabel(run: Pick<AsyncRunSummary, "mode" | "state" | "currentStep" | "chainStepCount" | "parallelGroups" | "steps"> & { workflowGraph?: WorkflowGraphSnapshot }): string {
668
+ const graphStages = run.mode === "workflow" ? workflowGraphStageNodes(run.workflowGraph) : [];
669
+ if (graphStages.length > 0) {
670
+ const currentNode = graphStages.find((node) => node.id === run.workflowGraph?.currentNodeId);
671
+ if (currentNode && currentNode.status !== "completed") return `stage ${graphStages.indexOf(currentNode) + 1}/${graphStages.length}`;
672
+ const activeNode = graphStages.find((node) => node.status === "running") ?? graphStages.find((node) => node.status !== "completed");
673
+ if (activeNode) return `stage ${graphStages.indexOf(activeNode) + 1}/${graphStages.length}`;
674
+ return `stage ${graphStages.length}/${graphStages.length}`;
675
+ }
516
676
  const stepCount = run.steps.length || 1;
517
677
  const chainStepCount = run.chainStepCount ?? stepCount;
518
678
  const groups = normalizeParallelGroups(run.parallelGroups, run.steps.length, chainStepCount);
@@ -539,7 +699,8 @@ function formatRunHeader(run: AsyncRunSummary): string {
539
699
  const activity = formatActivityFacts(run);
540
700
  const pending = run.pendingAppends ? ` | ${run.pendingAppends} pending append${run.pendingAppends === 1 ? "" : "s"}` : "";
541
701
  const context = contextModeLabel(run.context);
542
- return `${run.id} | ${run.state}${activity ? ` | ${activity}` : ""} | ${run.mode}${context ? ` ${context}` : ""} | ${stepLabel}${pending} | ${cwd}`;
702
+ const lane = run.lane ? ` | lane ${run.lane.key}` : "";
703
+ return `${run.id} | ${run.state}${activity ? ` | ${activity}` : ""} | ${run.mode}${context ? ` ${context}` : ""} | ${stepLabel}${pending}${lane} | ${cwd}`;
543
704
  }
544
705
 
545
706
  export function formatAsyncRunList(runs: AsyncRunSummary[], heading = "Active async runs"): string {
@@ -548,10 +709,34 @@ export function formatAsyncRunList(runs: AsyncRunSummary[], heading = "Active as
548
709
  const lines = [`${heading}: ${runs.length}`, ""];
549
710
  for (const run of runs) {
550
711
  lines.push(`- ${formatRunHeader(run)}`);
712
+ if (run.preflight) lines.push(formatWorkflowPreflightPlanSummary(run.preflight, { indent: " " }));
713
+ const preflightWarning = formatWorkflowPreflightWarningSummary(run.workflow?.preflightWarnings, { indent: " " });
714
+ if (preflightWarning) lines.push(preflightWarning);
715
+ if (run.mode === "workflow") {
716
+ const checklist = projectWorkflowChecklist({
717
+ graph: run.workflowGraph,
718
+ steps: run.steps,
719
+ hostSteps: run.hostSteps,
720
+ preflight: run.preflight,
721
+ trace: run.workflow?.trace,
722
+ now: run.lastUpdate ?? run.endedAt ?? Date.now(),
723
+ });
724
+ lines.push(...formatWorkflowChecklistText(checklist, " ", { includeItems: false }));
725
+ }
551
726
  for (const step of run.steps) {
552
727
  lines.push(` ${formatStepLine(step)}`);
728
+ lines.push(...formatTimeoutRecoveryLines(step.timeoutRecovery, " "));
553
729
  lines.push(...formatNestedRunStatusLines(step.children, { indent: " ", maxLines: 12 }));
554
730
  }
731
+ const loadedWorkflowKeys = new Set(run.steps.flatMap((step) => step.workflowKey ? [step.workflowKey] : []));
732
+ const graphStages = run.mode === "workflow" ? workflowGraphStageNodes(run.workflowGraph) : [];
733
+ for (const [index, node] of graphStages.entries()) {
734
+ if (!loadedWorkflowKeys.has(node.id)) lines.push(` ${formatWorkflowStageLine(node, index, graphStages.length)}`);
735
+ }
736
+ for (const row of projectAsyncWorkflowRows([], run.hostSteps)) {
737
+ const line = formatHostStepLine(row);
738
+ if (line) lines.push(` ${line}`);
739
+ }
555
740
  const attached = new Set(run.steps.flatMap((step) => step.children?.map((child) => child.id) ?? []));
556
741
  const unattached = run.nestedChildren?.filter((child) => !attached.has(child.id)) ?? [];
557
742
  lines.push(...formatNestedRunStatusLines(unattached, { indent: " ", maxLines: 12 }));
@@ -62,7 +62,7 @@ export async function drainOutstandingWork(deps: AutoDrainDeps): Promise<void> {
62
62
  },
63
63
  );
64
64
  if (waitResult.isError) {
65
- throw new Error(`Auto-drain failed for session '${sessionId}': ${resultText(waitResult) || "subagent_wait returned an error without details"}.`);
65
+ throw new Error(`Auto-drain failed for session '${sessionId}': ${resultText(waitResult) || "bg_wait returned an error without details"}.`);
66
66
  }
67
67
  }
68
68
  }
@@ -3,8 +3,9 @@ import * as fs from "node:fs";
3
3
  import * as path from "node:path";
4
4
  import { writeAtomicJson } from "../../shared/atomic-json.ts";
5
5
  import { appendJsonl } from "../../shared/artifacts.ts";
6
- import type { AsyncParallelGroupStatus, AsyncStatus, WorkflowGraphNode, WorkflowGraphSnapshot } from "../../shared/types.ts";
6
+ import type { AsyncStatus, WorkflowGraphNode, WorkflowGraphSnapshot } from "../../shared/types.ts";
7
7
  import { PROMPT_REDACTED, readStatus } from "../../shared/utils.ts";
8
+ import { deriveChildSessionName } from "../../shared/child-session-name.ts";
8
9
  import type { DynamicRunnerGroup, ParallelStepGroup, RunnerStep, RunnerSubagentStep } from "../shared/parallel-utils.ts";
9
10
  import { isDynamicRunnerGroup, isParallelGroup } from "../shared/parallel-utils.ts";
10
11
 
@@ -160,8 +161,10 @@ export function statusStepDescription(task: string | undefined): string | undefi
160
161
 
161
162
  function statusStepForTask(task: RunnerSubagentStep): StatusStep {
162
163
  const description = statusStepDescription(task.task);
164
+ const sessionName = task.sessionName ?? deriveChildSessionName({ agent: task.agent, task: task.task, label: task.label });
163
165
  return {
164
166
  agent: task.agent,
167
+ ...(sessionName ? { sessionName } : {}),
165
168
  ...(description ? { description } : {}),
166
169
  ...(task.context ? { context: task.context } : {}),
167
170
  phase: task.phase,
@@ -172,6 +175,7 @@ function statusStepForTask(task: RunnerSubagentStep): StatusStep {
172
175
  ...(task.sessionFile ? { sessionFile: task.sessionFile } : {}),
173
176
  skills: task.skills,
174
177
  model: task.model,
178
+ ...(task.contextLimit !== undefined ? { contextLimit: task.contextLimit } : {}),
175
179
  thinking: task.thinking,
176
180
  attemptedModels: task.modelCandidates && task.modelCandidates.length > 0 ? task.modelCandidates : task.model ? [task.model] : undefined,
177
181
  recentTools: [],
@@ -179,7 +183,7 @@ function statusStepForTask(task: RunnerSubagentStep): StatusStep {
179
183
  };
180
184
  }
181
185
 
182
- function statusStepsForRunnerStep(step: RunnerStep, stepIndex: number): StatusStep[] {
186
+ function statusStepsForRunnerStep(step: RunnerStep): StatusStep[] {
183
187
  if (isParallelGroup(step)) return step.parallel.map(statusStepForTask);
184
188
  if (isDynamicRunnerGroup(step)) {
185
189
  return [{
@@ -189,6 +193,7 @@ function statusStepsForRunnerStep(step: RunnerStep, stepIndex: number): StatusSt
189
193
  label: step.label ?? step.parallel.label ?? `Dynamic fanout (${step.collect.as})`,
190
194
  outputName: step.collect.as,
191
195
  structured: Boolean(step.collect.outputSchema),
196
+ ...(step.parallel.contextLimit !== undefined ? { contextLimit: step.parallel.contextLimit } : {}),
192
197
  status: "pending",
193
198
  recentTools: [],
194
199
  recentOutput: [],
@@ -295,7 +300,7 @@ export function appendRunnerStepsToStatus(input: {
295
300
  for (const step of input.steps) {
296
301
  const stepIndex = input.status.chainStepCount ?? input.status.steps?.length ?? 0;
297
302
  const flatIndex = input.status.steps?.length ?? 0;
298
- const statusSteps = statusStepsForRunnerStep(step, stepIndex);
303
+ const statusSteps = statusStepsForRunnerStep(step);
299
304
  input.status.steps ??= [];
300
305
  input.status.steps.push(...statusSteps);
301
306
  if (isParallelGroup(step)) {