@xzzpig/pi-subagents 0.24.2 → 0.25.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (263) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/bundle/agent-management.js +4 -4
  3. package/bundle/agents.js +3 -3
  4. package/bundle/child-tool-plan.js +2 -2
  5. package/bundle/chunk-34TUUBRN.js +1107 -0
  6. package/bundle/{chunk-SW2VMNIU.js → chunk-5OD3OWTE.js} +2 -2
  7. package/bundle/{chunk-EUPJB4S7.js → chunk-5Z7JAORM.js} +196 -1219
  8. package/bundle/{chunk-LCDJWBVM.js → chunk-66JNFRFS.js} +1 -1
  9. package/bundle/{chunk-ED55MIC2.js → chunk-CGFF4WA3.js} +42 -19
  10. package/bundle/{chunk-TMHVDPYW.js → chunk-DLVPMML3.js} +263 -154
  11. package/bundle/{chunk-RU522D5W.js → chunk-FQPV4O6C.js} +183 -28
  12. package/bundle/chunk-HXRB42AF.js +108 -0
  13. package/bundle/{chunk-355ECEP2.js → chunk-IH7LQVEE.js} +29 -14
  14. package/bundle/{chunk-Z6TFJ6BR.js → chunk-INWSUNI6.js} +1 -1
  15. package/bundle/{chunk-CYY5UMJU.js → chunk-IXCEOEJT.js} +411 -249
  16. package/bundle/{chunk-WW76JRIX.js → chunk-JAXVBXGF.js} +1 -1
  17. package/bundle/{chunk-ICNYIALB.js → chunk-JH5H4CYJ.js} +784 -474
  18. package/bundle/{chunk-224WMDIV.js → chunk-JUYNN63E.js} +350 -123
  19. package/bundle/{chunk-35GII5EF.js → chunk-JWFLPSTP.js} +41 -117
  20. package/bundle/{chunk-XWWUDWUW.js → chunk-KRNBJPZ2.js} +670 -400
  21. package/bundle/{chunk-RB4GELQA.js → chunk-LPJEKHOY.js} +1 -1
  22. package/bundle/chunk-LYKG4FKH.js +523 -0
  23. package/bundle/{chunk-X6LOM3Z4.js → chunk-LZ3HBDTR.js} +161 -78
  24. package/bundle/{chunk-JEA2ZKUA.js → chunk-MMJQMPOK.js} +37 -165
  25. package/bundle/{chunk-FG6SQJAR.js → chunk-OGPOCGWX.js} +24 -6
  26. package/bundle/{chunk-FJWI64H7.js → chunk-RMSABUN3.js} +27 -13
  27. package/bundle/{chunk-H36HBZB2.js → chunk-SJPABBZG.js} +2 -2
  28. package/bundle/{chunk-4UH4WS4G.js → chunk-SNDCIJMK.js} +23 -12
  29. package/bundle/{chunk-O4D5PBVI.js → chunk-TM2K53NX.js} +3 -2
  30. package/bundle/{chunk-3U633XDZ.js → chunk-U3ZDUUTM.js} +11 -3
  31. package/bundle/{chunk-LVWU2HOO.js → chunk-ULGMXABL.js} +16 -7
  32. package/bundle/{chunk-WPW4V6HM.js → chunk-W7ZA6TYD.js} +2 -2
  33. package/bundle/{chunk-BQ2OAB4Q.js → chunk-WWDUNXSE.js} +67 -30
  34. package/bundle/{chunk-V2KFIGFH.js → chunk-XAC2XNAP.js} +503 -304
  35. package/bundle/control-channel.js +2 -2
  36. package/bundle/index.js +1 -1
  37. package/bundle/intercom-bridge.js +2 -2
  38. package/bundle/preflight.js +12 -10
  39. package/bundle/project-panes.js +3 -3
  40. package/bundle/workflow-resources.js +1 -1
  41. package/docs/agents.md +27 -6
  42. package/docs/configuration.md +20 -8
  43. package/docs/extension-api.md +18 -1
  44. package/docs/models.md +6 -2
  45. package/docs/observability.md +2 -0
  46. package/docs/tool-reference.md +7 -1
  47. package/docs/workflows.md +30 -2
  48. package/package.json +2 -2
  49. package/skills/pi-subagents/SKILL.md +15 -6
  50. package/skills/pi-subagents/references/prompting-and-roles.md +1 -0
  51. package/src/agents/agent-management.d.ts +1 -0
  52. package/src/agents/agent-management.js +46 -18
  53. package/src/agents/agent-memory.d.ts +1 -4
  54. package/src/agents/agent-memory.js +1 -4
  55. package/src/agents/agent-serializer.d.ts +2 -0
  56. package/src/agents/agent-serializer.js +1 -1
  57. package/src/agents/agents.d.ts +2 -3
  58. package/src/agents/agents.js +46 -20
  59. package/src/agents/frontmatter.js +1 -8
  60. package/src/agents/global-npm-root.d.ts +1 -0
  61. package/src/agents/global-npm-root.js +11 -3
  62. package/src/agents/skills.d.ts +0 -3
  63. package/src/agents/skills.js +0 -3
  64. package/src/api/preflight.d.ts +3 -1
  65. package/src/api/preflight.js +2 -0
  66. package/src/extension/config.d.ts +1 -0
  67. package/src/extension/config.js +13 -1
  68. package/src/extension/herdr-pi-bridge.js +10 -2
  69. package/src/extension/index.d.ts +0 -13
  70. package/src/extension/index.js +51 -37
  71. package/src/extension/public-execution.d.ts +1 -0
  72. package/src/extension/public-execution.js +4 -0
  73. package/src/extension/reply-workflow-script.js +24 -4
  74. package/src/extension/schemas.d.ts +12 -3
  75. package/src/extension/schemas.js +7 -3
  76. package/src/extension/session-switch.d.ts +25 -0
  77. package/src/extension/session-switch.js +138 -0
  78. package/src/extension/subagent-guide.d.ts +1 -1
  79. package/src/extension/subagent-guide.js +1 -1
  80. package/src/extension/subagent-launch-tool.d.ts +25 -0
  81. package/src/extension/subagent-launch-tool.js +48 -0
  82. package/src/extension/tool-activation.js +55 -15
  83. package/src/extension/tool-description.d.ts +1 -1
  84. package/src/extension/tool-description.js +14 -8
  85. package/src/inspectors/herdr/actions.d.ts +0 -1
  86. package/src/inspectors/herdr/actions.js +0 -1
  87. package/src/inspectors/session-roots-codec.d.ts +0 -1
  88. package/src/inspectors/session-roots-codec.js +0 -1
  89. package/src/inspectors/tmux/actions.d.ts +0 -1
  90. package/src/inspectors/tmux/actions.js +0 -1
  91. package/src/integrations/herdr-status.js +3 -8
  92. package/src/intercom/native-supervisor-channel.js +65 -9
  93. package/src/runs/background/async-execution.d.ts +7 -10
  94. package/src/runs/background/async-execution.js +66 -29
  95. package/src/runs/background/async-job-tracker.js +12 -0
  96. package/src/runs/background/async-resume.d.ts +2 -1
  97. package/src/runs/background/async-resume.js +114 -40
  98. package/src/runs/background/async-retention.d.ts +0 -2
  99. package/src/runs/background/async-retention.js +17 -6
  100. package/src/runs/background/async-status.d.ts +2 -0
  101. package/src/runs/background/async-status.js +4 -0
  102. package/src/runs/background/auto-drain.js +2 -1
  103. package/src/runs/background/boot-id.d.ts +1 -3
  104. package/src/runs/background/boot-id.js +1 -3
  105. package/src/runs/background/completion-batcher.d.ts +3 -4
  106. package/src/runs/background/completion-batcher.js +2 -3
  107. package/src/runs/background/control-channel.d.ts +0 -6
  108. package/src/runs/background/control-channel.js +0 -6
  109. package/src/runs/background/fleet-view.js +2 -3
  110. package/src/runs/background/notify.d.ts +0 -2
  111. package/src/runs/background/notify.js +0 -2
  112. package/src/runs/background/result-watcher.d.ts +1 -0
  113. package/src/runs/background/result-watcher.js +59 -29
  114. package/src/runs/background/resume-guidance.js +4 -2
  115. package/src/runs/background/retained-children.js +2 -1
  116. package/src/runs/background/run-child-session.d.ts +2 -3
  117. package/src/runs/background/run-child-session.js +5 -8
  118. package/src/runs/background/run-status.js +9 -7
  119. package/src/runs/background/runner-aliases.js +15 -0
  120. package/src/runs/background/scheduled-runs.d.ts +3 -1
  121. package/src/runs/background/scheduled-runs.js +13 -16
  122. package/src/runs/background/steering.d.ts +2 -11
  123. package/src/runs/background/steering.js +11 -6
  124. package/src/runs/background/subagent-runner.d.ts +2 -6
  125. package/src/runs/background/subagent-runner.js +88 -70
  126. package/src/runs/background/subagent-wait.js +12 -15
  127. package/src/runs/background/wait-config.d.ts +2 -0
  128. package/src/runs/background/wait-config.js +17 -3
  129. package/src/runs/background/wait-subscriptions.js +124 -12
  130. package/src/runs/background/wait-tool.js +4 -2
  131. package/src/runs/background/workflow-terminal-proof.d.ts +0 -1
  132. package/src/runs/background/workflow-terminal-proof.js +0 -1
  133. package/src/runs/foreground/async-steering-action.js +24 -9
  134. package/src/runs/foreground/async-stop-action.d.ts +1 -1
  135. package/src/runs/foreground/async-stop-action.js +9 -1
  136. package/src/runs/foreground/execution.d.ts +0 -3
  137. package/src/runs/foreground/execution.js +68 -84
  138. package/src/runs/foreground/fork-tool-result-handler.d.ts +60 -0
  139. package/src/runs/foreground/fork-tool-result-handler.js +83 -0
  140. package/src/runs/foreground/prompt-audit.js +1 -0
  141. package/src/runs/foreground/subagent-executor.d.ts +5 -10
  142. package/src/runs/foreground/subagent-executor.js +164 -49
  143. package/src/runs/shared/acceptance.js +69 -26
  144. package/src/runs/shared/async-status-projection.d.ts +2 -0
  145. package/src/runs/shared/async-status-projection.js +10 -0
  146. package/src/runs/shared/child-commands.js +15 -2
  147. package/src/runs/shared/child-hooks.d.ts +1 -7
  148. package/src/runs/shared/child-hooks.js +13 -5
  149. package/src/runs/shared/child-launch.js +6 -2
  150. package/src/runs/shared/child-runtime-config.d.ts +0 -1
  151. package/src/runs/shared/child-session.d.ts +6 -5
  152. package/src/runs/shared/child-session.js +85 -38
  153. package/src/runs/shared/child-tool-plan.d.ts +0 -1
  154. package/src/runs/shared/child-tool-plan.js +0 -1
  155. package/src/runs/shared/claude-code-adapter.js +11 -0
  156. package/src/runs/shared/external-cli-contract.d.ts +49 -0
  157. package/src/runs/shared/external-cli-contract.js +18 -13
  158. package/src/runs/shared/external-cli-runner.js +26 -6
  159. package/src/runs/shared/herdr-connection.js +2 -1
  160. package/src/runs/shared/herdr-pane-host.d.ts +2 -2
  161. package/src/runs/shared/herdr-pane-host.js +17 -1
  162. package/src/runs/shared/herdr-placed-run.js +51 -24
  163. package/src/runs/shared/lane-metadata.d.ts +0 -1
  164. package/src/runs/shared/lane-metadata.js +0 -1
  165. package/src/runs/shared/mcp-config-sources.d.ts +4 -1
  166. package/src/runs/shared/mcp-config-sources.js +1 -1
  167. package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +0 -3
  168. package/src/runs/shared/mcp-direct-tool-allowlist.js +26 -17
  169. package/src/runs/shared/mcp-direct-tool-grant.js +8 -1
  170. package/src/runs/shared/model-resolution-diagnostic.d.ts +0 -1
  171. package/src/runs/shared/model-resolution.d.ts +20 -5
  172. package/src/runs/shared/model-resolution.js +55 -50
  173. package/src/runs/shared/model-scope.d.ts +1 -5
  174. package/src/runs/shared/model-scope.js +1 -5
  175. package/src/runs/shared/mutation-evidence.d.ts +1 -1
  176. package/src/runs/shared/mutation-evidence.js +52 -7
  177. package/src/runs/shared/nested-events.d.ts +1 -0
  178. package/src/runs/shared/nested-events.js +1 -1
  179. package/src/runs/shared/parallel-utils.d.ts +0 -1
  180. package/src/runs/shared/permissions.js +5 -3
  181. package/src/runs/shared/placement-host.d.ts +5 -1
  182. package/src/runs/shared/rex-pane-host.d.ts +0 -1
  183. package/src/runs/shared/rex-pane-host.js +0 -2
  184. package/src/runs/shared/run-launch-folder.d.ts +12 -0
  185. package/src/runs/shared/run-launch-folder.js +21 -0
  186. package/src/runs/shared/runner-launcher.d.ts +12 -1
  187. package/src/runs/shared/runner-launcher.js +16 -0
  188. package/src/runs/shared/single-output.d.ts +3 -3
  189. package/src/runs/shared/single-output.js +5 -3
  190. package/src/runs/shared/structured-output.d.ts +8 -0
  191. package/src/runs/shared/structured-output.js +40 -5
  192. package/src/runs/shared/subagent-prompt-runtime.d.ts +0 -1
  193. package/src/runs/shared/subagent-prompt-runtime.js +18 -4
  194. package/src/runs/shared/supervisor-wait-timer.d.ts +16 -0
  195. package/src/runs/shared/supervisor-wait-timer.js +61 -0
  196. package/src/runs/shared/tool-timeout.js +2 -1
  197. package/src/runs/shared/worktree-cleanup-plan.d.ts +0 -1
  198. package/src/runs/shared/worktree-cleanup-plan.js +0 -1
  199. package/src/runs/shared/worktree.d.ts +3 -0
  200. package/src/runs/shared/worktree.js +20 -0
  201. package/src/shared/artifacts.d.ts +1 -0
  202. package/src/shared/artifacts.js +132 -22
  203. package/src/shared/capacity-resilient-json.d.ts +1 -1
  204. package/src/shared/child-cache-retention.d.ts +1 -2
  205. package/src/shared/child-cache-retention.js +1 -2
  206. package/src/shared/fleet-transcript-reader.d.ts +64 -0
  207. package/src/shared/fleet-transcript-reader.js +376 -0
  208. package/src/shared/formatters.d.ts +0 -18
  209. package/src/shared/formatters.js +0 -18
  210. package/src/shared/pruned-fork.js +2 -2
  211. package/src/shared/reported-progress.d.ts +1 -0
  212. package/src/shared/reported-progress.js +12 -0
  213. package/src/shared/session-succession.d.ts +16 -1
  214. package/src/shared/session-succession.js +41 -2
  215. package/src/shared/session-warnings.d.ts +7 -0
  216. package/src/shared/session-warnings.js +26 -0
  217. package/src/shared/settings.d.ts +0 -23
  218. package/src/shared/settings.js +3 -35
  219. package/src/shared/status-format.d.ts +1 -0
  220. package/src/shared/status-format.js +1 -1
  221. package/src/shared/types.d.ts +108 -59
  222. package/src/shared/types.js +0 -12
  223. package/src/shared/utils.d.ts +3 -15
  224. package/src/shared/utils.js +4 -22
  225. package/src/shared/wait-tool-name.d.ts +8 -0
  226. package/src/shared/wait-tool-name.js +13 -0
  227. package/src/slash/slash-commands.js +2 -1
  228. package/src/slash/subagent-cost.d.ts +3 -2
  229. package/src/slash/subagent-cost.js +22 -3
  230. package/src/slash/subagents-admin.js +0 -1
  231. package/src/tui/fleet-native-transcript.js +1 -1
  232. package/src/tui/fleet-status.d.ts +0 -5
  233. package/src/tui/fleet-status.js +4 -24
  234. package/src/tui/fleet-transcript.d.ts +1 -57
  235. package/src/tui/fleet-transcript.js +4 -370
  236. package/src/tui/fleet.js +6 -4
  237. package/src/tui/render.d.ts +0 -9
  238. package/src/tui/render.js +194 -68
  239. package/src/tui/subagent-messages.js +3 -2
  240. package/src/watchdog/model-selection.js +2 -2
  241. package/src/watchdog/permission-arbiter.js +1 -0
  242. package/src/watchdog/register-child.d.ts +2 -3
  243. package/src/watchdog/register-child.js +2 -3
  244. package/src/watchdog/review.d.ts +0 -5
  245. package/src/watchdog/review.js +4 -3
  246. package/src/watchdog/turn-delta.js +2 -1
  247. package/src/workflows/scripted-workflow.d.ts +2 -0
  248. package/src/workflows/scripted-workflow.js +344 -59
  249. package/src/workflows/structured-workflow-scripts.d.ts +4 -3
  250. package/src/workflows/structured-workflow-scripts.js +32 -11
  251. package/src/workflows/workflow-launch-record.d.ts +15 -6
  252. package/src/workflows/workflow-launch-record.js +30 -12
  253. package/src/workflows/workflow-receipt.js +36 -53
  254. package/src/workflows/workflow-resources.js +4 -4
  255. package/src/workflows/workflow-resume-claim.d.ts +2 -0
  256. package/src/workflows/workflow-resume-claim.js +3 -3
  257. package/src/workflows/workflow-resume.d.ts +1 -1
  258. package/src/workflows/workflow-resume.js +13 -8
  259. package/src/workflows/workflow-script-worker.d.ts +13 -0
  260. package/src/workflows/workflow-script-worker.js +81 -0
  261. package/workflow-script-process.cjs +36 -0
  262. package/workflow-script-worker.cjs +4 -1
  263. package/bundle/chunk-U4ODUYAG.js +0 -235
@@ -1,3 +1,7 @@
1
+ import {
2
+ ownerSessionIds,
3
+ ownsRun
4
+ } from "./chunk-HXRB42AF.js";
1
5
  import {
2
6
  ACTIVE_RUN_INDEX_DIR,
3
7
  DEFAULT_STALE_TERMINAL_ACTIVE_MARKER_MS,
@@ -15,12 +19,15 @@ import {
15
19
  attachRootChildrenToSteps,
16
20
  buildNestedRouteIndex,
17
21
  cleanupWorktrees,
22
+ findListedWorktreeAgentCwd,
23
+ findListedWorktreeOnBranch,
18
24
  findNestedRouteForRootId,
19
25
  flatToLogicalStepIndex,
20
26
  hashedSegment,
21
27
  hostStepReportName,
22
28
  hostStepVerdictLabel,
23
29
  isActiveAsyncState,
30
+ isComparablePathInside,
24
31
  normalizeParallelGroups,
25
32
  normalizeWorktreeBaseRef,
26
33
  parseHostStepNode,
@@ -39,10 +46,13 @@ import {
39
46
  validateModelResponseAliases,
40
47
  withWorkflowChildRunModel,
41
48
  withWorktreeTransaction
42
- } from "./chunk-ICNYIALB.js";
49
+ } from "./chunk-JH5H4CYJ.js";
50
+ import {
51
+ missingForkCopyNote
52
+ } from "./chunk-LYKG4FKH.js";
43
53
  import {
44
54
  validateIntercomBridgeConfig
45
- } from "./chunk-WW76JRIX.js";
55
+ } from "./chunk-JAXVBXGF.js";
46
56
  import {
47
57
  stableJsonDigest
48
58
  } from "./chunk-BGIYHF2W.js";
@@ -77,7 +87,7 @@ import {
77
87
  validateToolBudgetConfig,
78
88
  waitForFileSystemRetry,
79
89
  writeAtomicJson
80
- } from "./chunk-V2KFIGFH.js";
90
+ } from "./chunk-XAC2XNAP.js";
81
91
  import {
82
92
  DIRS,
83
93
  RUNNER_LAUNCHER_NAME_PATTERN,
@@ -94,48 +104,6 @@ import {
94
104
  truncateDisplayText
95
105
  } from "./chunk-YFCK7H2S.js";
96
106
 
97
- // src/shared/session-succession.ts
98
- var SUCCESSION_KEY = /* @__PURE__ */ Symbol.for("pi-subagents.session-succession");
99
- var MAX_INHERITED_SESSIONS = 8;
100
- var MAX_RECORDED_SESSIONS = 64;
101
- function successions() {
102
- const runtime = globalThis;
103
- runtime[SUCCESSION_KEY] ??= /* @__PURE__ */ new Map();
104
- return runtime[SUCCESSION_KEY];
105
- }
106
- function recordSessionReplacement(sessionId, previousSessionId) {
107
- const chain = [.../* @__PURE__ */ new Set([previousSessionId, ...successions().get(previousSessionId) ?? []])].filter((id) => id !== sessionId);
108
- successions().delete(sessionId);
109
- successions().set(sessionId, chain.slice(0, MAX_INHERITED_SESSIONS));
110
- while (successions().size > MAX_RECORDED_SESSIONS) successions().delete(successions().keys().next().value);
111
- }
112
- function inheritedSessionIds(sessionId) {
113
- return successions().get(sessionId) ?? [];
114
- }
115
-
116
- // src/shared/extension-context.ts
117
- var MODEL_ONLY_TOOL = { exposure: "model-only" };
118
- function isStaleExtensionContextError(error) {
119
- return error instanceof Error && /extension ctx is stale|extension context no longer active|stale after session replacement or reload/i.test(error.message);
120
- }
121
- function canRenderComponents(ctx) {
122
- return ctx.mode === "tui" || process.env.PI_SUBAGENTS_COMPONENT_UI === "1";
123
- }
124
- function isUnboundExtensionRuntimeError(error) {
125
- return error instanceof Error && /extension runtime not initialized/i.test(error.message);
126
- }
127
- function withCachedUiContext(ctx, onStale, run) {
128
- if (!ctx) return void 0;
129
- try {
130
- if (!ctx.hasUI) return void 0;
131
- return run(ctx);
132
- } catch (error) {
133
- if (!isStaleExtensionContextError(error)) throw error;
134
- onStale();
135
- return void 0;
136
- }
137
- }
138
-
139
107
  // src/shared/status-format.ts
140
108
  function formatActivityAge(ms) {
141
109
  if (ms < 1e3) return "now";
@@ -750,56 +718,56 @@ function isPlainObject(value) {
750
718
  const prototype = Object.getPrototypeOf(value);
751
719
  return prototype === Object.prototype || prototype === null;
752
720
  }
753
- function assertPlainObject(value, path7) {
754
- if (!isPlainObject(value)) throw new Error(`${path7} must be a plain JSON object.`);
755
- if (Object.getOwnPropertySymbols(value).length > 0) throw new Error(`${path7} must not contain symbol keys.`);
721
+ function assertPlainObject(value, path9) {
722
+ if (!isPlainObject(value)) throw new Error(`${path9} must be a plain JSON object.`);
723
+ if (Object.getOwnPropertySymbols(value).length > 0) throw new Error(`${path9} must not contain symbol keys.`);
756
724
  for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
757
- if (!descriptor.enumerable || !("value" in descriptor)) throw new Error(`${path7}.${key} must be an enumerable data property.`);
725
+ if (!descriptor.enumerable || !("value" in descriptor)) throw new Error(`${path9}.${key} must be an enumerable data property.`);
758
726
  }
759
727
  }
760
- function assertKnownFields(value, allowed, path7) {
728
+ function assertKnownFields(value, allowed, path9) {
761
729
  for (const key of Object.keys(value)) {
762
- if (!allowed.has(key)) throw new Error(`${path7} contains unsupported field '${key}'.`);
730
+ if (!allowed.has(key)) throw new Error(`${path9} contains unsupported field '${key}'.`);
763
731
  }
764
732
  }
765
- function normalizeDisplayString(value, path7) {
766
- if (typeof value !== "string") throw new Error(`${path7} must be a string.`);
733
+ function normalizeDisplayString(value, path9) {
734
+ if (typeof value !== "string") throw new Error(`${path9} must be a string.`);
767
735
  const normalized = value.replace(/[\u0000-\u001f\u007f]/g, " ").replace(/\s+/g, " ").trim();
768
- if (!normalized) throw new Error(`${path7} must be a non-empty string.`);
736
+ if (!normalized) throw new Error(`${path9} must be a non-empty string.`);
769
737
  if (normalized.length > WORKFLOW_PREFLIGHT_MAX_STRING_LENGTH) {
770
- throw new Error(`${path7} exceeds the maximum length of ${WORKFLOW_PREFLIGHT_MAX_STRING_LENGTH}.`);
738
+ throw new Error(`${path9} exceeds the maximum length of ${WORKFLOW_PREFLIGHT_MAX_STRING_LENGTH}.`);
771
739
  }
772
740
  return normalized;
773
741
  }
774
742
  function normalizeLane(value, index) {
775
- const path7 = `preflight.lanes[${index}]`;
776
- assertPlainObject(value, path7);
777
- assertKnownFields(value, LANE_FIELDS, path7);
778
- const key = normalizeDisplayString(value.key, `${path7}.key`);
779
- if (!WORKFLOW_KEY_PATTERN.test(key)) throw new Error(`${path7}.key must be 1-128 characters using letters, numbers, '.', '_' or '-', and start with a letter or number.`);
743
+ const path9 = `preflight.lanes[${index}]`;
744
+ assertPlainObject(value, path9);
745
+ assertKnownFields(value, LANE_FIELDS, path9);
746
+ const key = normalizeDisplayString(value.key, `${path9}.key`);
747
+ if (!WORKFLOW_KEY_PATTERN.test(key)) throw new Error(`${path9}.key must be 1-128 characters using letters, numbers, '.', '_' or '-', and start with a letter or number.`);
780
748
  let mode;
781
749
  if (value.mode !== void 0) {
782
750
  if (typeof value.mode !== "string" || !PREFLIGHT_MODES.has(value.mode)) {
783
- throw new Error(`${path7}.mode must be one of: mutation, review, scout, gate.`);
751
+ throw new Error(`${path9}.mode must be one of: mutation, review, scout, gate.`);
784
752
  }
785
753
  mode = value.mode;
786
754
  }
787
755
  let claims;
788
756
  if (value.claims !== void 0) {
789
- if (!Array.isArray(value.claims)) throw new Error(`${path7}.claims must be an array of strings.`);
790
- if (value.claims.length > WORKFLOW_PREFLIGHT_MAX_CLAIMS) throw new Error(`${path7}.claims supports at most ${WORKFLOW_PREFLIGHT_MAX_CLAIMS} entries.`);
791
- claims = value.claims.map((claim, claimIndex) => normalizeDisplayString(claim, `${path7}.claims[${claimIndex}]`));
757
+ if (!Array.isArray(value.claims)) throw new Error(`${path9}.claims must be an array of strings.`);
758
+ if (value.claims.length > WORKFLOW_PREFLIGHT_MAX_CLAIMS) throw new Error(`${path9}.claims supports at most ${WORKFLOW_PREFLIGHT_MAX_CLAIMS} entries.`);
759
+ claims = value.claims.map((claim, claimIndex) => normalizeDisplayString(claim, `${path9}.claims[${claimIndex}]`));
792
760
  for (let claimIndex = 0; claimIndex < value.claims.length; claimIndex += 1) {
793
- if (!Object.prototype.hasOwnProperty.call(value.claims, claimIndex)) throw new Error(`${path7}.claims must not contain sparse arrays.`);
761
+ if (!Object.prototype.hasOwnProperty.call(value.claims, claimIndex)) throw new Error(`${path9}.claims must not contain sparse arrays.`);
794
762
  }
795
763
  }
796
764
  return {
797
765
  key,
798
766
  ...mode ? { mode } : {},
799
- ...value.decision !== void 0 ? { decision: normalizeDisplayString(value.decision, `${path7}.decision`) } : {},
767
+ ...value.decision !== void 0 ? { decision: normalizeDisplayString(value.decision, `${path9}.decision`) } : {},
800
768
  ...claims ? { claims } : {},
801
- ...value.expectedOutput !== void 0 ? { expectedOutput: normalizeDisplayString(value.expectedOutput, `${path7}.expectedOutput`) } : {},
802
- ...value.independence !== void 0 ? { independence: normalizeDisplayString(value.independence, `${path7}.independence`) } : {}
769
+ ...value.expectedOutput !== void 0 ? { expectedOutput: normalizeDisplayString(value.expectedOutput, `${path9}.expectedOutput`) } : {},
770
+ ...value.independence !== void 0 ? { independence: normalizeDisplayString(value.independence, `${path9}.independence`) } : {}
803
771
  };
804
772
  }
805
773
  function normalizeWorkflowPreflight(input) {
@@ -1280,6 +1248,8 @@ function projectStep(step, index, depth, ctx) {
1280
1248
  const activity = activityFor(step, ctx);
1281
1249
  const { id, label } = stepIdentity(step, index, ctx);
1282
1250
  const agent = publicOptionalText(step.agent, ctx.caps.maxStringLength);
1251
+ const progressText = publicOptionalText(step.progressText, ctx.caps.maxStringLength);
1252
+ const progressUpdatedAt = publicTime(step.progressUpdatedAt);
1283
1253
  const node = {
1284
1254
  id,
1285
1255
  kind: "step",
@@ -1288,7 +1258,9 @@ function projectStep(step, index, depth, ctx) {
1288
1258
  ...startedAt !== void 0 ? { startedAt } : {},
1289
1259
  ...updatedAt !== void 0 ? { updatedAt } : {},
1290
1260
  ...terminalState(state) && endedAt !== void 0 ? { endedAt } : {},
1291
- ...activity ? { activity } : {}
1261
+ ...activity ? { activity } : {},
1262
+ ...progressText ? { progressText } : {},
1263
+ ...progressUpdatedAt !== void 0 ? { progressUpdatedAt } : {}
1292
1264
  };
1293
1265
  if (agent) node.agent = agent;
1294
1266
  setStepModel(node, ctx, step);
@@ -1431,6 +1403,10 @@ function projectMaterializedStep(step, index, child, depth, ctx, childrenByParen
1431
1403
  const selfActivity = selfStep ? activityFor(selfStep, ctx) : void 0;
1432
1404
  const activity = laneActivity || selfActivity || live.activity ? { ...laneActivity, ...selfActivity, ...live.activity } : void 0;
1433
1405
  const node = { ...live, id, kind: "step", label };
1406
+ const progressText = publicOptionalText(selfStep?.progressText ?? step.progressText, ctx.caps.maxStringLength);
1407
+ const progressUpdatedAt = publicTime(selfStep?.progressUpdatedAt ?? step.progressUpdatedAt);
1408
+ if (progressText) node.progressText = progressText;
1409
+ if (progressUpdatedAt !== void 0) node.progressUpdatedAt = progressUpdatedAt;
1434
1410
  const agent = publicOptionalText(selfStep?.agent || step.agent, ctx.caps.maxStringLength);
1435
1411
  if (agent) node.agent = agent;
1436
1412
  if (activity) node.activity = activity;
@@ -1672,11 +1648,12 @@ function projectAsyncStatusSnapshot(jobs, options = {}) {
1672
1648
  }
1673
1649
 
1674
1650
  // src/runs/shared/mutation-evidence.ts
1675
- import { execFileSync } from "node:child_process";
1651
+ import { execFile, execFileSync } from "node:child_process";
1676
1652
  import { createHash } from "node:crypto";
1677
1653
  import * as fs2 from "node:fs";
1678
1654
  import * as os from "node:os";
1679
1655
  import * as path2 from "node:path";
1656
+ import { promisify } from "node:util";
1680
1657
  var MAX_TRACKED_PATHS = 500;
1681
1658
  var MAX_HASH_BYTES = 1024 * 1024;
1682
1659
  var MAX_TIMEOUT_FILES = 20;
@@ -1686,6 +1663,27 @@ function gitArguments(args) {
1686
1663
  function gitOutput(cwd, args, maxBuffer = MAX_HASH_BYTES) {
1687
1664
  return execFileSync("git", gitArguments(args), { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"], maxBuffer, windowsHide: true });
1688
1665
  }
1666
+ var execFileAsync = promisify(execFile);
1667
+ async function gitOutputAsync(cwd, args) {
1668
+ return (await execFileAsync("git", gitArguments(args), { cwd, encoding: "utf-8", maxBuffer: MAX_HASH_BYTES, windowsHide: true })).stdout;
1669
+ }
1670
+ async function hashFileAsync(diffPath) {
1671
+ const hash = createHash("sha256");
1672
+ const fd = fs2.openSync(diffPath, "r");
1673
+ try {
1674
+ const buffer = Buffer.alloc(64 * 1024);
1675
+ let chunks = 0;
1676
+ for (; ; ) {
1677
+ const bytesRead = fs2.readSync(fd, buffer, 0, buffer.length, null);
1678
+ if (bytesRead === 0) break;
1679
+ hash.update(bytesRead === buffer.length ? buffer : buffer.subarray(0, bytesRead));
1680
+ if (++chunks % 32 === 0) await new Promise((resolve5) => setImmediate(resolve5));
1681
+ }
1682
+ } finally {
1683
+ fs2.closeSync(fd);
1684
+ }
1685
+ return hash.digest("hex");
1686
+ }
1689
1687
  function splitNul(output) {
1690
1688
  return output.split("\0").filter((part) => part.length > 0);
1691
1689
  }
@@ -1711,8 +1709,9 @@ function hashLargeDiff(cwd, relativePath) {
1711
1709
  fs2.rmSync(tempDir, { recursive: true, force: true });
1712
1710
  }
1713
1711
  }
1714
- function listChangedTrackedFiles(cwd) {
1715
- const paths = splitNul(gitOutput(cwd, ["diff", "--no-ext-diff", "--name-only", "-z", "HEAD", "--"], MAX_HASH_BYTES));
1712
+ var CHANGED_FILES_ARGS = ["diff", "--no-ext-diff", "--name-only", "-z", "HEAD", "--"];
1713
+ function changedTrackedFiles(nameOnlyOutput) {
1714
+ const paths = splitNul(nameOnlyOutput);
1716
1715
  return { paths: paths.slice(0, MAX_TRACKED_PATHS), truncated: paths.length > MAX_TRACKED_PATHS };
1717
1716
  }
1718
1717
  function fingerprintPath(cwd, relativePath) {
@@ -1729,7 +1728,7 @@ function sameFingerprint(left, right) {
1729
1728
  }
1730
1729
  function snapshotTrackedMutations(cwd) {
1731
1730
  try {
1732
- const changed = listChangedTrackedFiles(cwd);
1731
+ const changed = changedTrackedFiles(gitOutput(cwd, CHANGED_FILES_ARGS));
1733
1732
  const fingerprints = {};
1734
1733
  for (const file of changed.paths) fingerprints[file] = fingerprintPath(cwd, file);
1735
1734
  return { source: "tracked-files", trackedOnly: true, cwd, dirtyFiles: changed.paths, fingerprints, truncated: changed.truncated };
@@ -1737,12 +1736,27 @@ function snapshotTrackedMutations(cwd) {
1737
1736
  return { source: "tracked-files", trackedOnly: true, cwd, dirtyFiles: [], fingerprints: {}, unavailable: error instanceof Error ? error.message : String(error) };
1738
1737
  }
1739
1738
  }
1740
- function collectTrackedMutationEvidence(snapshot, cwd = snapshot.cwd) {
1739
+ async function fingerprintPathAsync(cwd, relativePath) {
1740
+ try {
1741
+ const diff = await gitOutputAsync(cwd, ["diff", "--no-ext-diff", "--binary", "HEAD", "--", relativePath]);
1742
+ return { kind: "diff", digest: createHash("sha256").update(diff).digest("hex") };
1743
+ } catch {
1744
+ const tempDir = fs2.mkdtempSync(path2.join(os.tmpdir(), "pi-mutation-evidence-"));
1745
+ try {
1746
+ const diffPath = path2.join(tempDir, "diff.bin");
1747
+ await gitOutputAsync(cwd, ["diff", "--no-ext-diff", "--binary", `--output=${diffPath}`, "HEAD", "--", relativePath]);
1748
+ return { kind: "diff", digest: await hashFileAsync(diffPath) };
1749
+ } finally {
1750
+ fs2.rmSync(tempDir, { recursive: true, force: true });
1751
+ }
1752
+ }
1753
+ }
1754
+ async function collectTrackedMutationEvidence(snapshot, cwd = snapshot.cwd) {
1741
1755
  if (snapshot.unavailable) {
1742
1756
  return { source: "tracked-files", trackedOnly: true, changedFiles: [], attemptedMutation: false, unavailable: snapshot.unavailable };
1743
1757
  }
1744
1758
  try {
1745
- const current = listChangedTrackedFiles(cwd);
1759
+ const current = changedTrackedFiles(await gitOutputAsync(cwd, CHANGED_FILES_ARGS));
1746
1760
  const startDirty = new Set(snapshot.dirtyFiles);
1747
1761
  const candidates = /* @__PURE__ */ new Set([...snapshot.dirtyFiles, ...current.paths]);
1748
1762
  const changedFiles = [];
@@ -1751,7 +1765,7 @@ function collectTrackedMutationEvidence(snapshot, cwd = snapshot.cwd) {
1751
1765
  if (!snapshot.truncated) changedFiles.push(file);
1752
1766
  continue;
1753
1767
  }
1754
- if (!sameFingerprint(snapshot.fingerprints[file], fingerprintPath(cwd, file))) changedFiles.push(file);
1768
+ if (!sameFingerprint(snapshot.fingerprints[file], await fingerprintPathAsync(cwd, file))) changedFiles.push(file);
1755
1769
  }
1756
1770
  changedFiles.sort();
1757
1771
  return {
@@ -2120,14 +2134,6 @@ function formatWorkflowChecklistText(projection, indent = "", options = {}) {
2120
2134
  return lines;
2121
2135
  }
2122
2136
 
2123
- // src/runs/shared/run-ownership.ts
2124
- function ownerSessionIds(sessionId) {
2125
- return /* @__PURE__ */ new Set([sessionId, ...inheritedSessionIds(sessionId)]);
2126
- }
2127
- function ownsRun(currentSessionId, runSessionId) {
2128
- return currentSessionId ? ownerSessionIds(currentSessionId).has(runSessionId) : false;
2129
- }
2130
-
2131
2137
  // src/runs/background/async-status.ts
2132
2138
  function getErrorMessage(error) {
2133
2139
  return error instanceof Error ? error.message : String(error);
@@ -2302,6 +2308,8 @@ function statusToSummary(asyncDir, status, nestedWarnings = [], nestedRoute) {
2302
2308
  ...step.currentPath ? { currentPath: step.currentPath } : {},
2303
2309
  ...step.recentTools ? { recentTools: step.recentTools.map((tool) => ({ ...tool })) } : {},
2304
2310
  ...step.recentOutput ? { recentOutput: [...step.recentOutput] } : {},
2311
+ ...step.progressText ? { progressText: step.progressText } : {},
2312
+ ...step.progressUpdatedAt !== void 0 ? { progressUpdatedAt: step.progressUpdatedAt } : {},
2305
2313
  ...step.turnCount !== void 0 ? { turnCount: step.turnCount } : {},
2306
2314
  ...step.toolCount !== void 0 ? { toolCount: step.toolCount } : {},
2307
2315
  ...step.steering ? { steering: step.steering } : {},
@@ -2575,6 +2583,7 @@ function formatStepLine(step) {
2575
2583
  const modelThinking = formatModelThinking(step.model, step.thinking);
2576
2584
  if (modelThinking) parts.push(modelThinking);
2577
2585
  if (step.durationMs !== void 0) parts.push(formatDuration(step.durationMs));
2586
+ if (step.progressText && step.status === "running") parts.push(`progress: ${step.progressText}`);
2578
2587
  if (step.tokens) parts.push(`${formatTokens(step.tokens.total)} tok`);
2579
2588
  if (step.lane) parts.push(`lane ${step.lane.key}`);
2580
2589
  if (step.worktreePath) parts.push(`worktree ${shortenPath(step.worktreePath)} \xB7 branch ${step.branch ?? "unknown"}${step.provider ? ` \xB7 provider ${step.provider}` : ""}`);
@@ -3414,9 +3423,74 @@ function discardPreservedWorktreesUnlocked(manifestPath, authorization) {
3414
3423
  return { manifest, text: lines.join("\n") };
3415
3424
  }
3416
3425
 
3417
- // src/runs/background/async-resume.ts
3426
+ // src/workflows/workflow-launch-record.ts
3418
3427
  import * as fs6 from "node:fs";
3428
+ import * as path7 from "node:path";
3429
+
3430
+ // src/runs/shared/run-launch-folder.ts
3419
3431
  import * as path6 from "node:path";
3432
+ function runLaunchDir(runsRoot, runId) {
3433
+ if (!runId || runId !== path6.basename(runId) || runId === "." || runId === "..") throw new Error(`Invalid run id for a launch folder: '${runId}'.`);
3434
+ if (path6.basename(path6.dirname(runsRoot)) === "nested-subagent-runs") return path6.join(runsRoot, ".launches", runId);
3435
+ return path6.join(path6.dirname(runsRoot), "async-subagent-launches", runId);
3436
+ }
3437
+ function recoveryDescriptorPath(runsRoot, runId) {
3438
+ return path6.join(runLaunchDir(runsRoot, runId), "recovery-descriptor.json");
3439
+ }
3440
+
3441
+ // src/workflows/workflow-launch-record.ts
3442
+ var WORKFLOW_LAUNCH_RECORD_FILE = "launch.json";
3443
+ function launchRecordPath(asyncDirRoot, runId) {
3444
+ return path7.join(runLaunchDir(asyncDirRoot, runId), WORKFLOW_LAUNCH_RECORD_FILE);
3445
+ }
3446
+ function writeWorkflowLaunchRecord(asyncDirRoot, runId, record) {
3447
+ writeAtomicJson(launchRecordPath(asyncDirRoot, runId), record);
3448
+ }
3449
+ function isPlainObject2(value) {
3450
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
3451
+ }
3452
+ function invalid(error) {
3453
+ return { ok: false, missing: false, error };
3454
+ }
3455
+ function readWorkflowLaunchRecord(asyncDirRoot, runId) {
3456
+ let text2;
3457
+ try {
3458
+ text2 = fs6.readFileSync(launchRecordPath(asyncDirRoot, runId), "utf-8");
3459
+ } catch (error) {
3460
+ if (error.code === "ENOENT") return { ok: false, missing: true, error: "launch.json is missing" };
3461
+ return invalid(`could not be read: ${error instanceof Error ? error.message : String(error)}`);
3462
+ }
3463
+ let value;
3464
+ try {
3465
+ value = JSON.parse(text2);
3466
+ } catch (error) {
3467
+ return invalid(`not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
3468
+ }
3469
+ if (!isPlainObject2(value)) return invalid("not a JSON object");
3470
+ if (value.version !== 2) return invalid("version must be 2");
3471
+ if (typeof value.scriptDigest !== "string" || !value.scriptDigest) return invalid("scriptDigest must be a non-empty string");
3472
+ if (typeof value.sessionId !== "string" || !value.sessionId) return invalid("sessionId must be a non-empty string");
3473
+ let admissionCapabilityCeiling;
3474
+ try {
3475
+ if (value.admissionCapabilityCeiling !== void 0) admissionCapabilityCeiling = parseSubagentCapabilityCeiling(value.admissionCapabilityCeiling, "admissionCapabilityCeiling");
3476
+ } catch (error) {
3477
+ return invalid(error instanceof Error ? error.message : String(error));
3478
+ }
3479
+ const owner = {
3480
+ version: 2,
3481
+ scriptDigest: value.scriptDigest,
3482
+ sessionId: value.sessionId,
3483
+ ...admissionCapabilityCeiling ? { admissionCapabilityCeiling } : {}
3484
+ };
3485
+ if (value.source === "structured" || value.source === "internal") return { ok: true, record: { ...owner, source: value.source } };
3486
+ if (value.source !== "script" && value.source !== "resource") return invalid('source must be "script", "resource", "structured", or "internal"');
3487
+ if (!isPlainObject2(value.params)) return invalid("params must be an object");
3488
+ return { ok: true, record: { ...owner, source: value.source, params: value.params } };
3489
+ }
3490
+
3491
+ // src/runs/background/async-resume.ts
3492
+ import * as fs7 from "node:fs";
3493
+ import * as path8 from "node:path";
3420
3494
  function getErrorMessage2(error) {
3421
3495
  return error instanceof Error ? error.message : String(error);
3422
3496
  }
@@ -3480,7 +3554,7 @@ function validateResultFile(value, resultPath) {
3480
3554
  function readResultFile(resultPath) {
3481
3555
  let raw;
3482
3556
  try {
3483
- raw = fs6.readFileSync(resultPath, "utf-8");
3557
+ raw = fs7.readFileSync(resultPath, "utf-8");
3484
3558
  } catch (error) {
3485
3559
  throw new Error(`Failed to read async result file '${resultPath}': ${getErrorMessage2(error)}`, {
3486
3560
  cause: error instanceof Error ? error : void 0
@@ -3500,43 +3574,43 @@ function readResultFile(resultPath) {
3500
3574
  function assertRunId(value, field) {
3501
3575
  if (value === void 0) return void 0;
3502
3576
  if (value.trim() === "") throw new Error(`${field} must not be empty.`);
3503
- if (path6.isAbsolute(value) || /[\\/]/.test(value) || value.includes("..")) {
3577
+ if (path8.isAbsolute(value) || /[\\/]/.test(value) || value.includes("..")) {
3504
3578
  throw new Error(`${field} must be an async run id or prefix, not a path.`);
3505
3579
  }
3506
3580
  return value;
3507
3581
  }
3508
3582
  function assertInsideRoot(root, target, label) {
3509
- const rootPath = path6.resolve(root);
3510
- const targetPath = path6.resolve(target);
3511
- const relative3 = path6.relative(rootPath, targetPath);
3512
- if (relative3 === "" || !relative3.startsWith("..") && !path6.isAbsolute(relative3)) return;
3583
+ const rootPath = path8.resolve(root);
3584
+ const targetPath = path8.resolve(target);
3585
+ const relative3 = path8.relative(rootPath, targetPath);
3586
+ if (relative3 === "" || !relative3.startsWith("..") && !path8.isAbsolute(relative3)) return;
3513
3587
  throw new Error(`${label} must be inside ${rootPath}.`);
3514
3588
  }
3515
3589
  function prefixedRunIds(dir, prefix, suffix = "") {
3516
- if (!fs6.existsSync(dir)) return [];
3517
- return fs6.readdirSync(dir).filter((entry) => entry.startsWith(prefix) && (!suffix || entry.endsWith(suffix))).map((entry) => suffix ? entry.slice(0, -suffix.length) : entry).sort();
3590
+ if (!fs7.existsSync(dir)) return [];
3591
+ return fs7.readdirSync(dir).filter((entry) => entry.startsWith(prefix) && (!suffix || entry.endsWith(suffix))).map((entry) => suffix ? entry.slice(0, -suffix.length) : entry).sort();
3518
3592
  }
3519
3593
  function exactResultPath(resultsDir, runId) {
3520
3594
  const indexed = resultPayloadPathForIndexedRun(resultsDir, runId);
3521
3595
  if (indexed) return indexed;
3522
3596
  const resultPath = resultFilePath(resultsDir, runId);
3523
3597
  assertInsideRoot(resultsDir, resultPath, "Async result file");
3524
- return fs6.existsSync(resultPath) ? resultPath : null;
3598
+ return fs7.existsSync(resultPath) ? resultPath : null;
3525
3599
  }
3526
3600
  function findAsyncRunPrefixMatches(prefix, asyncDirRoot, resultsDir) {
3527
3601
  const requestedId = assertRunId(prefix, "id");
3528
3602
  if (!requestedId) return [];
3529
3603
  if (!canScanAsyncRunPrefix(requestedId)) return [];
3530
- const asyncRoot = path6.resolve(asyncDirRoot);
3531
- const resultRoot = path6.resolve(resultsDir);
3604
+ const asyncRoot = path8.resolve(asyncDirRoot);
3605
+ const resultRoot = path8.resolve(resultsDir);
3532
3606
  const matchingIds = prefixedRunIds(asyncRoot, requestedId).sort();
3533
3607
  return matchingIds.map((id) => {
3534
- const asyncDir = path6.join(asyncRoot, id);
3608
+ const asyncDir = path8.join(asyncRoot, id);
3535
3609
  assertInsideRoot(asyncRoot, asyncDir, "Async run directory");
3536
3610
  return {
3537
3611
  id,
3538
3612
  location: {
3539
- asyncDir: fs6.existsSync(asyncDir) ? asyncDir : null,
3613
+ asyncDir: fs7.existsSync(asyncDir) ? asyncDir : null,
3540
3614
  resultPath: exactResultPath(resultRoot, id),
3541
3615
  resolvedId: id
3542
3616
  }
@@ -3544,25 +3618,25 @@ function findAsyncRunPrefixMatches(prefix, asyncDirRoot, resultsDir) {
3544
3618
  });
3545
3619
  }
3546
3620
  function resolveAsyncRunLocation(params, asyncDirRoot, resultsDir) {
3547
- const asyncRoot = path6.resolve(asyncDirRoot);
3548
- const resultRoot = path6.resolve(resultsDir);
3621
+ const asyncRoot = path8.resolve(asyncDirRoot);
3622
+ const resultRoot = path8.resolve(resultsDir);
3549
3623
  const requestedId = assertRunId(params.id, "id") ?? assertRunId(params.runId, "runId");
3550
3624
  if (params.dir) {
3551
- const asyncDir = path6.resolve(params.dir);
3625
+ const asyncDir = path8.resolve(params.dir);
3552
3626
  assertInsideRoot(asyncRoot, asyncDir, "Async run directory");
3553
- const resolvedId = requestedId ?? path6.basename(asyncDir);
3554
- if (requestedId && requestedId !== path6.basename(asyncDir)) {
3555
- throw new Error(`Async run id '${requestedId}' does not match directory '${path6.basename(asyncDir)}'.`);
3627
+ const resolvedId = requestedId ?? path8.basename(asyncDir);
3628
+ if (requestedId && requestedId !== path8.basename(asyncDir)) {
3629
+ throw new Error(`Async run id '${requestedId}' does not match directory '${path8.basename(asyncDir)}'.`);
3556
3630
  }
3557
3631
  return { asyncDir, resultPath: exactResultPath(resultRoot, resolvedId), resolvedId };
3558
3632
  }
3559
3633
  if (!requestedId) return { asyncDir: null, resultPath: null };
3560
- const directAsyncDir = path6.join(asyncRoot, requestedId);
3634
+ const directAsyncDir = path8.join(asyncRoot, requestedId);
3561
3635
  assertInsideRoot(asyncRoot, directAsyncDir, "Async run directory");
3562
3636
  const directResultPath = exactResultPath(resultRoot, requestedId);
3563
- if (fs6.existsSync(directAsyncDir) || directResultPath) {
3637
+ if (fs7.existsSync(directAsyncDir) || directResultPath) {
3564
3638
  return {
3565
- asyncDir: fs6.existsSync(directAsyncDir) ? directAsyncDir : null,
3639
+ asyncDir: fs7.existsSync(directAsyncDir) ? directAsyncDir : null,
3566
3640
  resultPath: directResultPath,
3567
3641
  resolvedId: requestedId
3568
3642
  };
@@ -3626,13 +3700,12 @@ function resumeTargetMode(status, result) {
3626
3700
  if (result?.mode === "single" || result?.mode === "parallel" || result?.mode === "chain" || result?.mode === "workflow") return result.mode;
3627
3701
  return void 0;
3628
3702
  }
3629
- function readAsyncRecoveryDescriptor(asyncDir) {
3630
- if (!asyncDir) return void 0;
3631
- const descriptorPath = path6.join(asyncDir, "recovery-descriptor.json");
3632
- if (!fs6.existsSync(descriptorPath)) return void 0;
3703
+ function readAsyncRecoveryDescriptor(runsRoot, runId) {
3704
+ const descriptorPath = recoveryDescriptorPath(runsRoot, runId);
3705
+ if (!fs7.existsSync(descriptorPath)) return void 0;
3633
3706
  let value;
3634
3707
  try {
3635
- value = JSON.parse(fs6.readFileSync(descriptorPath, "utf-8"));
3708
+ value = JSON.parse(fs7.readFileSync(descriptorPath, "utf-8"));
3636
3709
  } catch (error) {
3637
3710
  throw new Error(`Failed to parse async recovery descriptor '${descriptorPath}': ${getErrorMessage2(error)}`, { cause: error instanceof Error ? error : void 0 });
3638
3711
  }
@@ -3695,6 +3768,9 @@ function readAsyncRecoveryDescriptor(asyncDir) {
3695
3768
  "lane",
3696
3769
  "baseRef",
3697
3770
  "launcher",
3771
+ "requiredLauncher",
3772
+ "sessionId",
3773
+ "managedWorktree",
3698
3774
  "extensionBindings",
3699
3775
  "requiredExtensions"
3700
3776
  ]);
@@ -3706,7 +3782,13 @@ function readAsyncRecoveryDescriptor(asyncDir) {
3706
3782
  if (typeof parsed[field] !== "string" || !parsed[field].trim()) throw new Error(`Invalid async recovery descriptor '${descriptorPath}': ${field} must be a non-empty string.`);
3707
3783
  }
3708
3784
  if (parsed.version !== 1) throw new Error(`Invalid async recovery descriptor '${descriptorPath}': version must be 1.`);
3709
- if (parsed.launcher !== void 0 && (typeof parsed.launcher !== "string" || !RUNNER_LAUNCHER_NAME_PATTERN.test(parsed.launcher))) throw new Error(`Invalid async recovery descriptor '${descriptorPath}': launcher must be a launcher name.`);
3785
+ if (parsed.launcher !== void 0 && parsed.launcher !== null && (typeof parsed.launcher !== "string" || !RUNNER_LAUNCHER_NAME_PATTERN.test(parsed.launcher))) throw new Error(`Invalid async recovery descriptor '${descriptorPath}': launcher must be a launcher name or null.`);
3786
+ if (parsed.requiredLauncher !== void 0) {
3787
+ const required = parsed.requiredLauncher;
3788
+ if (!required || typeof required !== "object" || Array.isArray(required) || Object.keys(required).some((key) => key !== "name" && key !== "definitionDigest") || typeof required.name !== "string" || !RUNNER_LAUNCHER_NAME_PATTERN.test(required.name) || typeof required.definitionDigest !== "string" || !/^[0-9a-f]{64}$/.test(required.definitionDigest)) {
3789
+ throw new Error(`Invalid async recovery descriptor '${descriptorPath}': requiredLauncher must be { name, definitionDigest }.`);
3790
+ }
3791
+ }
3710
3792
  try {
3711
3793
  parsed.runFanoutBudget = validateRunFanoutBudgetDescriptor(parsed.runFanoutBudget);
3712
3794
  } catch (error) {
@@ -3755,7 +3837,12 @@ function readAsyncRecoveryDescriptor(asyncDir) {
3755
3837
  if (item !== void 0 && (!Array.isArray(item) || item.some((entry) => typeof entry !== "string" || !entry.trim()))) throw new Error(`Invalid async recovery descriptor '${descriptorPath}': ${field} must contain non-empty strings.`);
3756
3838
  }
3757
3839
  if (parsed.systemPrompt !== void 0 && typeof parsed.systemPrompt !== "string") throw new Error(`Invalid async recovery descriptor '${descriptorPath}': systemPrompt must be a string.`);
3758
- for (const field of ["launchContractDigest", "sessionFile", "model", "modelProvider", "thinking", "agentFilePath", "outputPath", "sessionDir", "artifactsDir"]) {
3840
+ if (parsed.managedWorktree !== void 0) {
3841
+ const worktree = parsed.managedWorktree;
3842
+ const valid = !!worktree && typeof worktree === "object" && !Array.isArray(worktree) && (worktree.provider === "native" && typeof worktree.cwd === "string" && path8.isAbsolute(worktree.cwd) && Object.keys(worktree).length === 2 || worktree.provider === "worktrunk" && typeof worktree.branch === "string" && !!worktree.branch.trim() && Object.keys(worktree).length === 2);
3843
+ if (!valid) throw new Error(`Invalid async recovery descriptor '${descriptorPath}': managedWorktree is invalid.`);
3844
+ }
3845
+ for (const field of ["sessionId", "launchContractDigest", "sessionFile", "model", "modelProvider", "thinking", "agentFilePath", "outputPath", "sessionDir", "artifactsDir"]) {
3759
3846
  if (parsed[field] !== void 0 && (typeof parsed[field] !== "string" || !parsed[field].trim())) throw new Error(`Invalid async recovery descriptor '${descriptorPath}': ${field} must be a non-empty string.`);
3760
3847
  }
3761
3848
  if (parsed.baseRef !== void 0) {
@@ -3818,17 +3905,30 @@ function readAsyncRecoveryDescriptor(asyncDir) {
3818
3905
  if (parsed.acceptance !== void 0) parsed.acceptance = normalizeRecoveryAcceptance(parsed.acceptance, descriptorPath);
3819
3906
  return parsed;
3820
3907
  }
3908
+ function assertLaunchedWorktreeCwd(runId, launchCwd, launched, handoffCwd) {
3909
+ const listed = launched.provider === "native" ? void 0 : findListedWorktreeOnBranch(launchCwd, launched.branch);
3910
+ const matches = launched.provider === "native" ? isComparablePathInside(launched.cwd, handoffCwd) && isComparablePathInside(handoffCwd, launched.cwd) : listed !== void 0 && isComparablePathInside(listed, handoffCwd);
3911
+ if (!matches) throw new Error(`Async run '${runId}' managed worktree ${handoffCwd} is not the worktree its launch created.`);
3912
+ return handoffCwd;
3913
+ }
3914
+ function launchedWorktreeCwdWithoutHandoff(runId, launchCwd, launched) {
3915
+ const cwd = launched.provider === "native" ? launched.cwd : findListedWorktreeAgentCwd(launchCwd, launched.branch);
3916
+ if (cwd === void 0 || !fs7.statSync(cwd, { throwIfNoEntry: false })?.isDirectory()) {
3917
+ 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.`);
3918
+ }
3919
+ return cwd;
3920
+ }
3821
3921
  function validateResumeSessionFile(runId, sessionFile) {
3822
- if (path6.extname(sessionFile) !== ".jsonl") throw new Error(`Async run '${runId}' session file must be a .jsonl file: ${sessionFile}`);
3823
- const resolved = path6.resolve(sessionFile);
3824
- if (!fs6.existsSync(resolved)) throw new Error(`Async run '${runId}' session file does not exist: ${sessionFile}`);
3922
+ if (path8.extname(sessionFile) !== ".jsonl") throw new Error(`Async run '${runId}' session file must be a .jsonl file: ${sessionFile}`);
3923
+ const resolved = path8.resolve(sessionFile);
3924
+ if (!fs7.existsSync(resolved)) throw new Error(`Async run '${runId}' session file does not exist: ${sessionFile}${missingForkCopyNote(resolved)}`);
3825
3925
  return resolved;
3826
3926
  }
3827
3927
  function validateResumeCwd(runId, cwd) {
3828
3928
  if (!cwd) return void 0;
3829
- const resolved = path6.resolve(cwd);
3929
+ const resolved = path8.resolve(cwd);
3830
3930
  try {
3831
- if (!fs6.statSync(resolved).isDirectory()) throw new Error("path is not a directory");
3931
+ if (!fs7.statSync(resolved).isDirectory()) throw new Error("path is not a directory");
3832
3932
  } catch (error) {
3833
3933
  throw new Error(`Async run '${runId}' required cwd does not exist: ${cwd}`, { cause: error instanceof Error ? error : void 0 });
3834
3934
  }
@@ -3843,17 +3943,27 @@ function resolveAsyncResumeTarget(params, deps = {}, options = {}) {
3843
3943
  const requested = params.id ?? params.runId;
3844
3944
  throw new Error(requested ? `Async run not found for '${requested}'.` : "Async run not found. Provide id or dir.");
3845
3945
  }
3946
+ if (location.asyncDir) {
3947
+ let recordedRunId;
3948
+ try {
3949
+ recordedRunId = JSON.parse(fs7.readFileSync(path8.join(location.asyncDir, "status.json"), "utf-8")).runId;
3950
+ } catch {
3951
+ }
3952
+ if (typeof recordedRunId === "string" && recordedRunId !== path8.basename(location.asyncDir)) throw new Error(`Async run '${path8.basename(location.asyncDir)}' has a status file for a different run '${recordedRunId}'.`);
3953
+ }
3846
3954
  const reconciliation = location.asyncDir ? reconcileAsyncRun(location.asyncDir, { resultsDir, kill: deps.kill, now: deps.now }) : void 0;
3847
3955
  const status = reconciliation?.status ?? null;
3848
- validateStatusForResume(status, location.asyncDir ? path6.join(location.asyncDir, "status.json") : "status.json");
3849
- const recoveryDescriptor = readAsyncRecoveryDescriptor(location.asyncDir ?? void 0);
3956
+ validateStatusForResume(status, location.asyncDir ? path8.join(location.asyncDir, "status.json") : "status.json");
3957
+ const directRunFolder = location.asyncDir !== null && path8.dirname(location.asyncDir) === path8.resolve(asyncDirRoot);
3958
+ const recoveryDescriptor = directRunFolder ? readAsyncRecoveryDescriptor(asyncDirRoot, path8.basename(location.asyncDir)) : void 0;
3850
3959
  const result = location.resultPath ? readResultFile(location.resultPath) : void 0;
3851
- const runId = status?.runId ?? result?.runId ?? result?.id ?? location.resolvedId ?? (location.asyncDir ? path6.basename(location.asyncDir) : "unknown");
3852
- const mode = resumeTargetMode(status, result);
3853
- if (options.sessionId && (status && !ownsRun(options.sessionId, status.sessionId) || result && !ownsRun(options.sessionId, result.sessionId))) {
3960
+ const runId = location.asyncDir ? path8.basename(location.asyncDir) : result?.runId ?? result?.id ?? location.resolvedId ?? "unknown";
3961
+ const mode = recoveryDescriptor ? "single" : resumeTargetMode(status, result);
3962
+ const notOwned = recoveryDescriptor ? !ownsRun(options.sessionId, recoveryDescriptor.sessionId) : status && !ownsRun(options.sessionId, status.sessionId) || result && !ownsRun(options.sessionId, result.sessionId);
3963
+ if (options.sessionId && notOwned) {
3854
3964
  throw new Error(`Async run '${runId}' was not found in the active session.`);
3855
3965
  }
3856
- if (recoveryDescriptor && recoveryDescriptor.sourceRunId !== runId) throw new Error(`Async run '${runId}' has a recovery descriptor for a different source run.`);
3966
+ if (recoveryDescriptor && recoveryDescriptor.sourceRunId !== runId) throw new Error(`Async run '${runId}' has a recovery descriptor for a different source run '${recoveryDescriptor.sourceRunId}'.`);
3857
3967
  const state = status?.state ?? (result ? resultState(result) : void 0);
3858
3968
  if (!state) throw new Error(`Status file not found for async run '${runId}'.`);
3859
3969
  if (state === "stopped") throw new Error(`Async run '${runId}' was stopped and cannot be resumed. Start a new run instead.`);
@@ -3868,18 +3978,18 @@ function resolveAsyncResumeTarget(params, deps = {}, options = {}) {
3868
3978
  if (requestedIndex < 0 || requestedIndex >= stepCount) throw new Error(`Async run '${runId}' has ${stepCount} children. Index ${requestedIndex} is out of range.`);
3869
3979
  const selectedStep = statusSteps[requestedIndex];
3870
3980
  if (selectedStep?.status === "running") {
3871
- const capabilityCeiling2 = intersectSubagentCapabilityCeilings(status?.capabilityCeiling, selectedStep.capabilityCeiling);
3981
+ const capabilityCeiling2 = recoveryDescriptor ? recoveryDescriptor.capabilityCeiling : intersectSubagentCapabilityCeilings(status?.capabilityCeiling, selectedStep.capabilityCeiling);
3872
3982
  return {
3873
3983
  kind: "live",
3874
3984
  runId,
3875
3985
  asyncDir: location.asyncDir ?? void 0,
3876
3986
  state,
3877
3987
  ...mode ? { mode } : {},
3878
- agent: selectedStep.agent,
3988
+ agent: recoveryDescriptor?.agent ?? selectedStep.agent,
3879
3989
  ...selectedStep.sessionName ?? result?.results?.[requestedIndex]?.sessionName ? { sessionName: selectedStep.sessionName ?? result?.results?.[requestedIndex]?.sessionName } : {},
3880
3990
  index: requestedIndex,
3881
3991
  cwd: status?.cwd ?? result?.cwd,
3882
- sessionFile: selectedStep.sessionFile ?? status?.sessionFile ?? result?.sessionFile,
3992
+ sessionFile: recoveryDescriptor ? recoveryDescriptor.sessionFile : selectedStep.sessionFile ?? status?.sessionFile ?? result?.sessionFile,
3883
3993
  model: selectedStep.model,
3884
3994
  thinking: selectedStep.thinking,
3885
3995
  sandbox: selectedStep.sandbox ?? result?.results?.[requestedIndex]?.sandbox ?? result?.sandbox ?? recoveryDescriptor?.sandbox,
@@ -3900,18 +4010,18 @@ function resolveAsyncResumeTarget(params, deps = {}, options = {}) {
3900
4010
  if (!selected) {
3901
4011
  throw new Error(`Async run '${runId}' has ${running.length} running children. Provide index to choose one.`);
3902
4012
  }
3903
- const capabilityCeiling2 = intersectSubagentCapabilityCeilings(status?.capabilityCeiling, selected.step.capabilityCeiling);
4013
+ const capabilityCeiling2 = recoveryDescriptor ? recoveryDescriptor.capabilityCeiling : intersectSubagentCapabilityCeilings(status?.capabilityCeiling, selected.step.capabilityCeiling);
3904
4014
  return {
3905
4015
  kind: "live",
3906
4016
  runId,
3907
4017
  asyncDir: location.asyncDir ?? void 0,
3908
4018
  state,
3909
4019
  ...mode ? { mode } : {},
3910
- agent: selected.step.agent,
4020
+ agent: recoveryDescriptor?.agent ?? selected.step.agent,
3911
4021
  ...selected.step.sessionName ?? result?.results?.[selected.index]?.sessionName ? { sessionName: selected.step.sessionName ?? result?.results?.[selected.index]?.sessionName } : {},
3912
4022
  index: selected.index,
3913
4023
  cwd: status?.cwd ?? result?.cwd,
3914
- sessionFile: selected.step.sessionFile ?? status?.sessionFile ?? result?.sessionFile,
4024
+ sessionFile: recoveryDescriptor ? recoveryDescriptor.sessionFile : selected.step.sessionFile ?? status?.sessionFile ?? result?.sessionFile,
3915
4025
  model: selected.step.model,
3916
4026
  thinking: selected.step.thinking,
3917
4027
  sandbox: selected.step.sandbox ?? result?.results?.[selected.index]?.sandbox ?? result?.sandbox ?? recoveryDescriptor?.sandbox,
@@ -3935,18 +4045,19 @@ function resolveAsyncResumeTarget(params, deps = {}, options = {}) {
3935
4045
  if (selectedStatusStep?.status === "stopped" || selectedStatusStep?.stopped === true) {
3936
4046
  throw new Error(`Async run '${runId}' child ${index} was stopped and cannot be resumed. Start a new run instead.`);
3937
4047
  }
3938
- const agent = selectedStatusStep?.agent ?? resultSteps[index]?.agent ?? result?.agent;
4048
+ const agent = recoveryDescriptor ? recoveryDescriptor.agent : selectedStatusStep?.agent ?? resultSteps[index]?.agent ?? result?.agent;
3939
4049
  if (!agent) throw new Error(`Could not determine child agent for async run '${runId}'.`);
3940
- if (recoveryDescriptor && recoveryDescriptor.agent !== agent) throw new Error(`Async run '${runId}' has a recovery descriptor for '${recoveryDescriptor.agent}', not '${agent}'.`);
3941
- const sessionFile = statusSteps[index]?.sessionFile ?? resultSteps[index]?.sessionFile ?? (stepCount === 1 ? status?.sessionFile ?? result?.sessionFile : void 0);
4050
+ const sessionFile = recoveryDescriptor ? recoveryDescriptor.sessionFile : statusSteps[index]?.sessionFile ?? resultSteps[index]?.sessionFile ?? (stepCount === 1 ? status?.sessionFile ?? result?.sessionFile : void 0);
3942
4051
  if (!sessionFile && requireSessionFile) throw new Error(`Async run '${runId}' child ${index} does not have a persisted session file to resume from.`);
3943
4052
  const resolvedSessionFile = sessionFile ? validateResumeSessionFile(runId, sessionFile) : void 0;
3944
- const stepModel = statusSteps[index]?.launchModel ?? statusSteps[index]?.model ?? resultSteps[index]?.model ?? (stepCount === 1 ? result?.model : void 0);
3945
- const stepThinking = statusSteps[index]?.thinking ?? resultSteps[index]?.thinking ?? (stepCount === 1 ? result?.thinking : void 0);
3946
- const thinkingCeiling = statusSteps[index]?.thinkingCeiling ?? (stepCount === 1 ? recoveryDescriptor?.thinkingCeiling : void 0);
3947
- const capabilityCeiling = mode === "workflow" ? intersectSubagentCapabilityCeilings(status?.admissionCapabilityCeiling, result?.admissionCapabilityCeiling) : intersectSubagentCapabilityCeilings(status?.capabilityCeiling, statusSteps[index]?.capabilityCeiling, result?.capabilityCeiling, resultSteps[index]?.capabilityCeiling);
3948
- const managedWorktreeCwd = location.asyncDir ? resolveRetainedWorktreeCwd(parallelHandoffPath(location.asyncDir), runId, index, statusSteps[index]?.worktreePath) : void 0;
3949
- const resumeCwd = validateResumeCwd(runId, managedWorktreeCwd ?? status?.cwd ?? result?.cwd ?? recoveryDescriptor?.cwd);
4053
+ const stepModel = recoveryDescriptor ? recoveryDescriptor.model : statusSteps[index]?.launchModel ?? statusSteps[index]?.model ?? resultSteps[index]?.model ?? (stepCount === 1 ? result?.model : void 0);
4054
+ const stepThinking = recoveryDescriptor ? recoveryDescriptor.thinking : statusSteps[index]?.thinking ?? resultSteps[index]?.thinking ?? (stepCount === 1 ? result?.thinking : void 0);
4055
+ const thinkingCeiling = recoveryDescriptor ? recoveryDescriptor.thinkingCeiling : statusSteps[index]?.thinkingCeiling;
4056
+ const workflowLaunch = mode === "workflow" && directRunFolder ? readWorkflowLaunchRecord(asyncDirRoot, runId) : void 0;
4057
+ const capabilityCeiling = recoveryDescriptor ? recoveryDescriptor.capabilityCeiling : mode === "workflow" ? workflowLaunch?.ok ? workflowLaunch.record.admissionCapabilityCeiling : void 0 : intersectSubagentCapabilityCeilings(status?.capabilityCeiling, statusSteps[index]?.capabilityCeiling, result?.capabilityCeiling, resultSteps[index]?.capabilityCeiling);
4058
+ const handoffWorktreeCwd = location.asyncDir && (!recoveryDescriptor || recoveryDescriptor.managedWorktree) ? resolveRetainedWorktreeCwd(parallelHandoffPath(location.asyncDir), runId, index, statusSteps[index]?.worktreePath) : void 0;
4059
+ const managedWorktreeCwd = recoveryDescriptor?.managedWorktree ? handoffWorktreeCwd ? assertLaunchedWorktreeCwd(runId, recoveryDescriptor.cwd, recoveryDescriptor.managedWorktree, handoffWorktreeCwd) : launchedWorktreeCwdWithoutHandoff(runId, recoveryDescriptor.cwd, recoveryDescriptor.managedWorktree) : handoffWorktreeCwd;
4060
+ const resumeCwd = validateResumeCwd(runId, managedWorktreeCwd ?? (recoveryDescriptor ? recoveryDescriptor.cwd : status?.cwd ?? result?.cwd));
3950
4061
  return {
3951
4062
  kind: "revive",
3952
4063
  runId,
@@ -3963,9 +4074,10 @@ function resolveAsyncResumeTarget(params, deps = {}, options = {}) {
3963
4074
  ...stepThinking ? { thinking: stepThinking } : {},
3964
4075
  sandbox: statusSteps[index]?.sandbox ?? resultSteps[index]?.sandbox ?? result?.sandbox ?? recoveryDescriptor?.sandbox,
3965
4076
  permissionProfile: statusSteps[index]?.permissionProfile ?? resultSteps[index]?.permissionProfile ?? result?.permissionProfile ?? recoveryDescriptor?.permissionProfile,
3966
- launchContractDigest: statusSteps[index]?.launchContractDigest ?? resultSteps[index]?.launchContractDigest ?? result?.launchContractDigest ?? recoveryDescriptor?.launchContractDigest,
3967
- ...statusSteps[index]?.runner ? { runner: statusSteps[index].runner } : {},
3968
- ...statusSteps[index]?.externalJob ? { externalJob: statusSteps[index].externalJob } : {},
4077
+ launchContractDigest: recoveryDescriptor ? recoveryDescriptor.launchContractDigest : statusSteps[index]?.launchContractDigest ?? resultSteps[index]?.launchContractDigest ?? result?.launchContractDigest,
4078
+ // External runners write no recovery descriptor.
4079
+ ...!recoveryDescriptor && statusSteps[index]?.runner ? { runner: statusSteps[index].runner } : {},
4080
+ ...!recoveryDescriptor && statusSteps[index]?.externalJob ? { externalJob: statusSteps[index].externalJob } : {},
3969
4081
  ...capabilityCeiling ? { capabilityCeiling } : {},
3970
4082
  ...thinkingCeiling ? { thinkingCeiling } : {},
3971
4083
  ...recoveryDescriptor ? { recoveryDescriptor } : {}
@@ -4000,8 +4112,9 @@ function applySteeringRecoveryAgentConfig(agentConfig, descriptor) {
4000
4112
  output: descriptor.outputPath,
4001
4113
  toolBudget: descriptor.initialToolBudget,
4002
4114
  maxSubagentDepth: descriptor.maxSubagentDepth,
4003
- // The recorded launcher wins over the current agent file, including recorded absence.
4004
- launcher: descriptor.launcher
4115
+ // A recorded launcher, or a recorded null (ran unwrapped), wins over the current agent file.
4116
+ // A missing field says nothing, so the run never loses the agent file's launcher.
4117
+ launcher: descriptor.launcher === void 0 ? agentConfig.launcher : descriptor.launcher ?? void 0
4005
4118
  };
4006
4119
  }
4007
4120
  function buildRevivedAsyncTask(target, message) {
@@ -4040,17 +4153,9 @@ function opencodeSessionHeaders(model, sessionId) {
4040
4153
  }
4041
4154
 
4042
4155
  export {
4043
- recordSessionReplacement,
4044
- inheritedSessionIds,
4045
- ownerSessionIds,
4046
- ownsRun,
4047
- MODEL_ONLY_TOOL,
4048
- isStaleExtensionContextError,
4049
- canRenderComponents,
4050
- isUnboundExtensionRuntimeError,
4051
- withCachedUiContext,
4052
4156
  agentStreamOptions,
4053
4157
  opencodeSessionHeaders,
4158
+ formatActivityAge,
4054
4159
  formatActivityLabel,
4055
4160
  aggregateStepStatus,
4056
4161
  formatAgentRunningLabel,
@@ -4122,6 +4227,10 @@ export {
4122
4227
  formatParallelHandoffReference,
4123
4228
  formatParallelHandoffError,
4124
4229
  discardPreservedWorktrees,
4230
+ runLaunchDir,
4231
+ recoveryDescriptorPath,
4232
+ writeWorkflowLaunchRecord,
4233
+ readWorkflowLaunchRecord,
4125
4234
  findAsyncRunPrefixMatches,
4126
4235
  resolveAsyncRunLocation,
4127
4236
  asyncReviveRequiresRecoveryDescriptor,