@sema-agent/core 7.69.1 → 7.71.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 (988) hide show
  1. package/CHANGELOG.md +3205 -0
  2. package/dist/agents/agent-definition.d.ts +18 -0
  3. package/dist/agents/agent-definition.js +10 -0
  4. package/dist/agents/agent-transcript-tool.d.ts +2 -1
  5. package/dist/agents/agent-transcript-tool.js +45 -19
  6. package/dist/agents/cascade.d.ts +10 -0
  7. package/dist/agents/cascade.js +33 -5
  8. package/dist/agents/cc-peer-directory.d.ts +1 -1
  9. package/dist/agents/cc-peer-directory.js +2 -1
  10. package/dist/agents/child-model-seat.d.ts +1 -1
  11. package/dist/agents/composition-allowance.d.ts +63 -19
  12. package/dist/agents/composition-allowance.js +62 -45
  13. package/dist/agents/composition-placement.d.ts +22 -4
  14. package/dist/agents/composition-placement.js +10 -1
  15. package/dist/agents/cross-session-envelope.d.ts +4 -5
  16. package/dist/agents/cross-session-envelope.js +4 -5
  17. package/dist/agents/inherited-tool-pool.d.ts +5 -1
  18. package/dist/agents/inherited-tool-pool.js +7 -2
  19. package/dist/agents/list-agents-tool.js +2 -1
  20. package/dist/agents/parked-resume-drive.d.ts +38 -0
  21. package/dist/agents/parked-resume-drive.js +57 -0
  22. package/dist/agents/peer-admission.js +4 -3
  23. package/dist/agents/peer-held-queue.d.ts +4 -2
  24. package/dist/agents/peer-held-queue.js +2 -1
  25. package/dist/agents/peer-session-drain.d.ts +2 -0
  26. package/dist/agents/peer-session-drain.js +49 -29
  27. package/dist/agents/repair-loop.js +15 -11
  28. package/dist/agents/retain-ledger.d.ts +71 -18
  29. package/dist/agents/retain-ledger.js +47 -13
  30. package/dist/agents/roster-store.d.ts +11 -3
  31. package/dist/agents/roster-store.js +6 -2
  32. package/dist/agents/send-message-tool.d.ts +14 -2
  33. package/dist/agents/send-message-tool.js +57 -16
  34. package/dist/agents/subagent.d.ts +24 -7
  35. package/dist/agents/subagent.js +287 -154
  36. package/dist/agents/tool-filter.js +1 -2
  37. package/dist/agents/verify.d.ts +4 -1
  38. package/dist/agents/verify.js +34 -17
  39. package/dist/agents/yield-adoption.js +13 -2
  40. package/dist/bench/metrics.js +2 -2
  41. package/dist/brain/anthropic.d.ts +2 -1
  42. package/dist/brain/anthropic.js +3 -3
  43. package/dist/brain/circuit-breaker.js +1 -1
  44. package/dist/brain/claude-model-id.d.ts +11 -0
  45. package/dist/brain/claude-model-id.js +3 -1
  46. package/dist/brain/model-lane.d.ts +2 -1
  47. package/dist/brain/model-lane.js +22 -9
  48. package/dist/brain/open-responses.d.ts +77 -1
  49. package/dist/brain/open-responses.js +1 -1
  50. package/dist/brain/openai.d.ts +2 -1
  51. package/dist/brain/openai.js +3 -3
  52. package/dist/brain/reasoning.d.ts +8 -1
  53. package/dist/brain/reasoning.js +3 -0
  54. package/dist/brain/reference-model-traits.d.ts +13 -12
  55. package/dist/brain/reference-model-traits.js +11 -10
  56. package/dist/brain/request-route.d.ts +1 -1
  57. package/dist/brain/request-route.js +2 -2
  58. package/dist/brain/route-adjudicator.d.ts +72 -2
  59. package/dist/brain/route-adjudicator.js +210 -69
  60. package/dist/brain/route-conformance.js +35 -0
  61. package/dist/brain/routing.js +2 -2
  62. package/dist/brain/spend-meter.d.ts +56 -0
  63. package/dist/brain/spend-meter.js +263 -0
  64. package/dist/brain/stream-shared.d.ts +1 -1
  65. package/dist/brain/stream-shared.js +3 -1
  66. package/dist/config/catalog.js +10 -1
  67. package/dist/config/defaults.d.ts +3 -0
  68. package/dist/config/defaults.js +1 -0
  69. package/dist/core/a2a-bound-grant.d.ts +110 -0
  70. package/dist/core/a2a-bound-grant.js +83 -0
  71. package/dist/core/a2a-task-state.d.ts +153 -51
  72. package/dist/core/a2a-task-state.js +85 -45
  73. package/dist/core/a2a.d.ts +62 -14
  74. package/dist/core/a2a.js +298 -57
  75. package/dist/core/agent-config-dir.d.ts +53 -6
  76. package/dist/core/agent-config-dir.js +59 -6
  77. package/dist/core/agent-definition.d.ts +1 -1
  78. package/dist/core/agent-state.d.ts +10 -1
  79. package/dist/core/agent-state.js +11 -4
  80. package/dist/core/allow-entry.d.ts +80 -42
  81. package/dist/core/allow-entry.js +119 -62
  82. package/dist/core/allow-rule-shadow.d.ts +25 -3
  83. package/dist/core/allow-rule-shadow.js +7 -0
  84. package/dist/core/approval-object.js +2 -2
  85. package/dist/core/artifact-host.d.ts +109 -6
  86. package/dist/core/artifact-host.js +68 -0
  87. package/dist/core/ask-headline.d.ts +10 -9
  88. package/dist/core/ask-headline.js +9 -3
  89. package/dist/core/ask-origin.d.ts +143 -49
  90. package/dist/core/ask-origin.js +91 -53
  91. package/dist/core/ask-question.d.ts +74 -39
  92. package/dist/core/ask-question.js +150 -23
  93. package/dist/core/ask-unresolvable-notice.d.ts +80 -10
  94. package/dist/core/ask-unresolvable-notice.js +52 -14
  95. package/dist/core/attachment-source.d.ts +1 -1
  96. package/dist/core/attachment-source.js +2 -0
  97. package/dist/core/auto-compaction.d.ts +17 -53
  98. package/dist/core/auto-compaction.js +6 -10
  99. package/dist/core/auto-mode-directive.d.ts +17 -5
  100. package/dist/core/auto-mode-directive.js +12 -3
  101. package/dist/core/auto-mode.d.ts +34 -5
  102. package/dist/core/auto-mode.js +43 -5
  103. package/dist/core/auto-strip.js +2 -0
  104. package/dist/core/background-agent-store.d.ts +100 -11
  105. package/dist/core/background-agent-store.js +64 -6
  106. package/dist/core/background-shell.d.ts +9 -0
  107. package/dist/core/background-shell.js +10 -0
  108. package/dist/core/caller-text.d.ts +4 -35
  109. package/dist/core/caller-text.js +2 -23
  110. package/dist/core/caller-tool-name.d.ts +6 -0
  111. package/dist/core/caller-tool-name.js +2 -2
  112. package/dist/core/canonical-json.d.ts +9 -0
  113. package/dist/core/canonical-json.js +6 -0
  114. package/dist/core/checkpoint-features.d.ts +79 -500
  115. package/dist/core/checkpoint-features.js +53 -19
  116. package/dist/core/checkpoint-generation.d.ts +89 -19
  117. package/dist/core/checkpoint-generation.js +89 -14
  118. package/dist/core/checkpoint-queries.d.ts +109 -18
  119. package/dist/core/checkpoint-queries.js +117 -11
  120. package/dist/core/checkpoint-rekey.d.ts +2 -1
  121. package/dist/core/checkpoint-rekey.js +2 -2
  122. package/dist/core/checkpoint-requirements.d.ts +76 -8
  123. package/dist/core/checkpoint-requirements.js +14 -7
  124. package/dist/core/checkpoint-row-verdict.d.ts +71 -19
  125. package/dist/core/checkpoint-row-verdict.js +93 -68
  126. package/dist/core/checkpoint-store.d.ts +139 -109
  127. package/dist/core/checkpoint-store.js +50 -34
  128. package/dist/core/classifier-unavailable-arm.d.ts +6 -1
  129. package/dist/core/classifier-unavailable-arm.js +8 -5
  130. package/dist/core/command-sandbox.d.ts +5 -3
  131. package/dist/core/command-sandbox.js +17 -9
  132. package/dist/core/config-refusal-codes.d.ts +7 -5
  133. package/dist/core/config-refusal-codes.js +8 -2
  134. package/dist/core/config-refusal-input.d.ts +46 -0
  135. package/dist/core/config-refusal-input.js +62 -0
  136. package/dist/core/context-edit.d.ts +18 -1
  137. package/dist/core/context-edit.js +13 -2
  138. package/dist/core/context-guard.d.ts +60 -13
  139. package/dist/core/context-guard.js +77 -35
  140. package/dist/core/context-settings.d.ts +2 -1
  141. package/dist/core/context-settings.js +10 -6
  142. package/dist/core/corrupt-session-form.d.ts +97 -0
  143. package/dist/core/corrupt-session-form.js +54 -0
  144. package/dist/core/cross-boundary-taint.d.ts +3 -3
  145. package/dist/core/data-root.d.ts +32 -0
  146. package/dist/core/data-root.js +86 -0
  147. package/dist/core/decision-receipt.d.ts +2 -0
  148. package/dist/core/decision-receipt.js +3 -2
  149. package/dist/core/declaration-words.d.ts +38 -0
  150. package/dist/core/declaration-words.js +32 -0
  151. package/dist/core/delegation-frames.d.ts +76 -35
  152. package/dist/core/delegation-frames.js +21 -1
  153. package/dist/core/durable-sync.d.ts +9 -0
  154. package/dist/core/durable-sync.js +37 -0
  155. package/dist/core/effective-path-target.d.ts +23 -0
  156. package/dist/core/effective-path-target.js +15 -1
  157. package/dist/core/engine-attestation.d.ts +5 -1
  158. package/dist/core/engine-attestation.js +1 -0
  159. package/dist/core/engine-capabilities.d.ts +123 -11
  160. package/dist/core/engine-capabilities.js +1 -1
  161. package/dist/core/engine-notice.d.ts +313 -163
  162. package/dist/core/engine-notice.js +13 -19
  163. package/dist/core/engine-version.js +1 -1
  164. package/dist/core/entries-not-applied.d.ts +22 -0
  165. package/dist/core/entries-not-applied.js +27 -0
  166. package/dist/core/exec-gate.d.ts +8 -1
  167. package/dist/core/exec-gate.js +24 -9
  168. package/dist/core/exec-outcome.d.ts +102 -0
  169. package/dist/core/exec-outcome.js +79 -0
  170. package/dist/core/existing-target.d.ts +45 -0
  171. package/dist/core/existing-target.js +54 -8
  172. package/dist/core/fast-tier-door.d.ts +2 -2
  173. package/dist/core/fast-tier-door.js +3 -3
  174. package/dist/core/file-history-store.d.ts +230 -27
  175. package/dist/core/file-history-store.js +234 -45
  176. package/dist/core/gate-fold.js +21 -8
  177. package/dist/core/gate-lanes.js +72 -45
  178. package/dist/core/gate-outcome.d.ts +3 -1
  179. package/dist/core/gate-outcome.js +7 -1
  180. package/dist/core/git-worktree-env.d.ts +25 -5
  181. package/dist/core/git-worktree-env.js +38 -13
  182. package/dist/core/governance-codes.d.ts +231 -43
  183. package/dist/core/governance-codes.js +552 -47
  184. package/dist/core/grant-holder.d.ts +53 -0
  185. package/dist/core/grant-holder.js +80 -0
  186. package/dist/core/hands-band.d.ts +1 -1
  187. package/dist/core/hooks.d.ts +80 -14
  188. package/dist/core/hooks.js +6 -2
  189. package/dist/core/host-floor.d.ts +1 -1
  190. package/dist/core/host-floor.js +1 -1
  191. package/dist/core/identity-rekey.d.ts +2 -1
  192. package/dist/core/identity-rekey.js +5 -5
  193. package/dist/core/image-admission.d.ts +2 -2
  194. package/dist/core/image-admission.js +1 -1
  195. package/dist/core/isolation-scope.d.ts +42 -17
  196. package/dist/core/isolation-scope.js +12 -4
  197. package/dist/core/leg-identity.d.ts +17 -2
  198. package/dist/core/leg-identity.js +6 -1
  199. package/dist/core/locked-config.d.ts +93 -17
  200. package/dist/core/locked-config.js +109 -36
  201. package/dist/core/mailbox-store.d.ts +4 -0
  202. package/dist/core/mailbox-store.js +7 -0
  203. package/dist/core/mcp-call-meta.d.ts +52 -7
  204. package/dist/core/mcp-call-meta.js +21 -2
  205. package/dist/core/mcp-failure.d.ts +13 -4
  206. package/dist/core/mcp-failure.js +10 -0
  207. package/dist/core/mcp-host-read.d.ts +1 -1
  208. package/dist/core/mcp-injection-drop.d.ts +30 -13
  209. package/dist/core/mcp-injection-drop.js +25 -7
  210. package/dist/core/mcp-leg-wait.d.ts +88 -0
  211. package/dist/core/mcp-leg-wait.js +100 -0
  212. package/dist/core/mcp-name-judge.js +1 -2
  213. package/dist/core/mcp-probe.d.ts +30 -1
  214. package/dist/core/mcp-probe.js +5 -3
  215. package/dist/core/mcp-read-bound.d.ts +51 -0
  216. package/dist/core/mcp-read-bound.js +49 -0
  217. package/dist/core/mcp-server-link.js +4 -3
  218. package/dist/core/mcp-server-spec.d.ts +115 -26
  219. package/dist/core/mcp-server-spec.js +52 -19
  220. package/dist/core/mcp-server-unavailable-notice.d.ts +15 -6
  221. package/dist/core/mcp-server-unavailable-notice.js +12 -11
  222. package/dist/core/mcp-stderr-lines.d.ts +69 -0
  223. package/dist/core/mcp-stderr-lines.js +333 -0
  224. package/dist/core/mcp.d.ts +32 -9
  225. package/dist/core/mcp.js +189 -46
  226. package/dist/core/member-outcome.d.ts +302 -0
  227. package/dist/core/member-outcome.js +305 -0
  228. package/dist/core/memory-engine/consolidation.js +3 -3
  229. package/dist/core/memory-engine/content-origin.js +5 -4
  230. package/dist/core/memory-engine/control-objects.js +6 -4
  231. package/dist/core/memory-engine/delegation-settlement.js +5 -5
  232. package/dist/core/memory-engine/distiller.js +2 -2
  233. package/dist/core/memory-engine/dual-root.d.ts +12 -5
  234. package/dist/core/memory-engine/dual-root.js +13 -7
  235. package/dist/core/memory-engine/engine.d.ts +27 -31
  236. package/dist/core/memory-engine/engine.js +122 -80
  237. package/dist/core/memory-engine/file-backend.d.ts +23 -5
  238. package/dist/core/memory-engine/file-backend.js +29 -32
  239. package/dist/core/memory-engine/frontmatter.js +1 -1
  240. package/dist/core/memory-engine/index-copies.d.ts +8 -6
  241. package/dist/core/memory-engine/index-copies.js +2 -1
  242. package/dist/core/memory-engine/index.d.ts +4 -2
  243. package/dist/core/memory-engine/index.js +4 -2
  244. package/dist/core/memory-engine/layout.d.ts +197 -29
  245. package/dist/core/memory-engine/layout.js +271 -59
  246. package/dist/core/memory-engine/memory-backend-contract.js +20 -20
  247. package/dist/core/memory-engine/memory-deployment.d.ts +29 -16
  248. package/dist/core/memory-engine/memory-deployment.js +38 -28
  249. package/dist/core/memory-engine/mount-failed-notice.d.ts +71 -4
  250. package/dist/core/memory-engine/mount-failed-notice.js +54 -3
  251. package/dist/core/memory-engine/projection-ledger.d.ts +48 -0
  252. package/dist/core/memory-engine/projection-ledger.js +130 -0
  253. package/dist/core/memory-engine/scope-contract.js +2 -2
  254. package/dist/core/memory-engine/sync-client.js +1 -2
  255. package/dist/core/memory-engine/types.d.ts +10 -4
  256. package/dist/core/memory.js +3 -5
  257. package/dist/core/mode-policy.d.ts +87 -16
  258. package/dist/core/mode-policy.js +69 -29
  259. package/dist/core/model-seat.d.ts +13 -1
  260. package/dist/core/mods/classic-events.d.ts +13 -1
  261. package/dist/core/mods/dollar.js +2 -1
  262. package/dist/core/mods/extension-call.d.ts +3 -0
  263. package/dist/core/mods/extension-call.js +3 -0
  264. package/dist/core/mods/host.d.ts +2 -1
  265. package/dist/core/mods/host.js +7 -6
  266. package/dist/core/mods/kernel/dispatch.d.ts +4 -0
  267. package/dist/core/mods/kernel/dispatch.js +3 -3
  268. package/dist/core/mods/kernel/events.d.ts +11 -3
  269. package/dist/core/mods/kernel/events.js +4 -4
  270. package/dist/core/mods/kernel/index.d.ts +1 -1
  271. package/dist/core/mods/kernel/index.js +1 -1
  272. package/dist/core/mods/kernel/registration.d.ts +5 -2
  273. package/dist/core/mods/kernel/registration.js +19 -3
  274. package/dist/core/mods/message-display.d.ts +6 -3
  275. package/dist/core/mods/message-display.js +13 -5
  276. package/dist/core/mods/package.d.ts +12 -1
  277. package/dist/core/mods/package.js +36 -9
  278. package/dist/core/mods/stations.d.ts +15 -2
  279. package/dist/core/mods/stations.js +22 -6
  280. package/dist/core/mods/teammate-stations.d.ts +78 -0
  281. package/dist/core/mods/teammate-stations.js +108 -0
  282. package/dist/core/mounted-mcp.js +1 -2
  283. package/dist/core/namespaced-rule-name.d.ts +1 -1
  284. package/dist/core/namespaced-rule-name.js +1 -1
  285. package/dist/core/native-signal.d.ts +13 -0
  286. package/dist/core/native-signal.js +18 -0
  287. package/dist/core/notice-fact.d.ts +28 -0
  288. package/dist/core/notice-fact.js +25 -0
  289. package/dist/core/owner-identity.d.ts +8 -3
  290. package/dist/core/owner-identity.js +6 -3
  291. package/dist/core/parent-spec-seat.d.ts +16 -6
  292. package/dist/core/parent-spec-seat.js +28 -6
  293. package/dist/core/park-resumability.d.ts +25 -18
  294. package/dist/core/park-resumability.js +12 -4
  295. package/dist/core/park-selfcheck.js +2 -1
  296. package/dist/core/path-rule-binding.js +1 -1
  297. package/dist/core/peer-seat.d.ts +1 -2
  298. package/dist/core/permission-rule-consent.d.ts +50 -1
  299. package/dist/core/permission-rule-consent.js +121 -14
  300. package/dist/core/permission-rule-model.d.ts +145 -43
  301. package/dist/core/permission-rule-model.js +155 -26
  302. package/dist/core/permission-rule-org.d.ts +13 -0
  303. package/dist/core/permission-rule-org.js +9 -1
  304. package/dist/core/permission-rule-provider.d.ts +112 -8
  305. package/dist/core/permission-rule-provider.js +439 -29
  306. package/dist/core/permission-rule-session.d.ts +35 -5
  307. package/dist/core/permission-rule-session.js +35 -2
  308. package/dist/core/permission-rule-store.d.ts +24 -3
  309. package/dist/core/permission-rule-store.js +56 -14
  310. package/dist/core/permission-rule-sync.js +5 -2
  311. package/dist/core/permission-rules.d.ts +2 -2
  312. package/dist/core/permission-rules.js +9 -5
  313. package/dist/core/persisted-rule-arms.d.ts +10 -4
  314. package/dist/core/persisted-rule-arms.js +16 -11
  315. package/dist/core/persisted-rule-buckets.d.ts +66 -0
  316. package/dist/core/persisted-rule-buckets.js +57 -0
  317. package/dist/core/plan-review-facts.d.ts +33 -0
  318. package/dist/core/plan-review-facts.js +25 -0
  319. package/dist/core/prefix-declaration.d.ts +50 -0
  320. package/dist/core/prefix-declaration.js +13 -0
  321. package/dist/core/present-plan-tool.d.ts +13 -3
  322. package/dist/core/present-plan-tool.js +14 -3
  323. package/dist/core/pricing.d.ts +5 -1
  324. package/dist/core/pricing.js +8 -5
  325. package/dist/core/principal-name.d.ts +67 -5
  326. package/dist/core/principal-name.js +61 -16
  327. package/dist/core/process-identity.d.ts +11 -7
  328. package/dist/core/process-identity.js +26 -36
  329. package/dist/core/process-table.d.ts +67 -0
  330. package/dist/core/process-table.js +177 -0
  331. package/dist/core/protocol-http-auth.d.ts +75 -12
  332. package/dist/core/protocol-http-auth.js +223 -26
  333. package/dist/core/protocol-revocation.d.ts +29 -10
  334. package/dist/core/protocol-revocation.js +9 -5
  335. package/dist/core/read-only-shell.d.ts +1 -1
  336. package/dist/core/read-only-shell.js +1 -1
  337. package/dist/core/read-root-grant-screen.d.ts +19 -7
  338. package/dist/core/read-root-grant-screen.js +14 -5
  339. package/dist/core/reminder-mint.d.ts +6 -0
  340. package/dist/core/reminder-mint.js +13 -0
  341. package/dist/core/remote-env.d.ts +153 -11
  342. package/dist/core/remote-env.js +20 -0
  343. package/dist/core/request-copy-projection.js +97 -18
  344. package/dist/core/resource-limit-reasons.d.ts +52 -0
  345. package/dist/core/resource-limit-reasons.js +6 -0
  346. package/dist/core/resume-at-refusal.d.ts +10 -6
  347. package/dist/core/resume-at-refusal.js +2 -2
  348. package/dist/core/resume-config-judge.d.ts +3 -2
  349. package/dist/core/resume-config-judge.js +3 -2
  350. package/dist/core/resume-startup-cause.d.ts +35 -6
  351. package/dist/core/resume-startup-cause.js +53 -10
  352. package/dist/core/retention.d.ts +12 -2
  353. package/dist/core/retention.js +6 -1
  354. package/dist/core/retired-keys.d.ts +5 -0
  355. package/dist/core/retired-keys.js +12 -0
  356. package/dist/core/rewind-conversation.d.ts +58 -0
  357. package/dist/core/rewind-conversation.js +1 -0
  358. package/dist/core/rewrite-rejudge.d.ts +9 -1
  359. package/dist/core/rewrite-rejudge.js +11 -1
  360. package/dist/core/roles.d.ts +61 -3
  361. package/dist/core/roles.js +81 -28
  362. package/dist/core/rule-lane-reads.d.ts +2 -1
  363. package/dist/core/rule-lane-reads.js +54 -29
  364. package/dist/core/rule-offer-read.js +8 -4
  365. package/dist/core/rule-owner.d.ts +6 -1
  366. package/dist/core/rule-owner.js +8 -2
  367. package/dist/core/rule-store-fault.d.ts +4 -2
  368. package/dist/core/rule-store-fault.js +4 -1
  369. package/dist/core/runner/advertised-writable-dirs.d.ts +17 -0
  370. package/dist/core/runner/advertised-writable-dirs.js +15 -9
  371. package/dist/core/runner/announce-once-ledger.js +12 -11
  372. package/dist/core/runner/assemble-result.d.ts +36 -17
  373. package/dist/core/runner/assemble-result.js +35 -8
  374. package/dist/core/runner/auto-strip-notice.d.ts +1 -1
  375. package/dist/core/runner/boundary-reminders.d.ts +104 -0
  376. package/dist/core/runner/boundary-reminders.js +108 -0
  377. package/dist/core/runner/branch-window.d.ts +25 -2
  378. package/dist/core/runner/branch-window.js +47 -11
  379. package/dist/core/runner/branch-writeback.d.ts +21 -7
  380. package/dist/core/runner/branch-writeback.js +44 -6
  381. package/dist/core/runner/chain-refusal-throw.d.ts +19 -0
  382. package/dist/core/runner/chain-refusal-throw.js +30 -0
  383. package/dist/core/runner/changes-git.d.ts +21 -0
  384. package/dist/core/runner/changes-git.js +291 -0
  385. package/dist/core/runner/changes-history.d.ts +80 -0
  386. package/dist/core/runner/changes-history.js +351 -0
  387. package/dist/core/runner/checkpoint-scope.d.ts +16 -8
  388. package/dist/core/runner/checkpoint-scope.js +6 -4
  389. package/dist/core/runner/child-tree.d.ts +31 -20
  390. package/dist/core/runner/child-tree.js +24 -9
  391. package/dist/core/runner/classifier-ladder.d.ts +4 -2
  392. package/dist/core/runner/classifier-ladder.js +14 -12
  393. package/dist/core/runner/clock-and-limits.d.ts +0 -3
  394. package/dist/core/runner/clock-and-limits.js +1 -2
  395. package/dist/core/runner/command-sandbox-frame.js +2 -1
  396. package/dist/core/runner/compact-session.js +27 -51
  397. package/dist/core/runner/compaction-restate.js +2 -1
  398. package/dist/core/runner/constraint-layers.d.ts +120 -0
  399. package/dist/core/runner/constraint-layers.js +115 -0
  400. package/dist/core/runner/construction-doors.js +2 -0
  401. package/dist/core/runner/content-ask-bindings.d.ts +3 -3
  402. package/dist/core/runner/continuation-gate.d.ts +8 -4
  403. package/dist/core/runner/continuation-gate.js +5 -1
  404. package/dist/core/runner/continues-from.d.ts +7 -0
  405. package/dist/core/runner/continues-from.js +9 -0
  406. package/dist/core/runner/contracts.d.ts +225 -55
  407. package/dist/core/runner/cross-boundary-lane.js +2 -1
  408. package/dist/core/runner/decide-continuation.d.ts +2 -2
  409. package/dist/core/runner/delegation-owner.d.ts +246 -45
  410. package/dist/core/runner/delegation-owner.js +237 -63
  411. package/dist/core/runner/denial-limit-arms.js +3 -4
  412. package/dist/core/runner/earlier-grammar-notice.js +5 -3
  413. package/dist/core/runner/env-capability-census.js +2 -1
  414. package/dist/core/runner/expire-settle.d.ts +17 -0
  415. package/dist/core/runner/expire-settle.js +8 -2
  416. package/dist/core/runner/file-history-request.d.ts +4 -3
  417. package/dist/core/runner/file-history-request.js +4 -1
  418. package/dist/core/runner/file-history-restore.d.ts +46 -12
  419. package/dist/core/runner/file-history-restore.js +45 -10
  420. package/dist/core/runner/finish-reason-seat.js +13 -4
  421. package/dist/core/runner/gate-exit.d.ts +30 -1
  422. package/dist/core/runner/gate-exit.js +37 -14
  423. package/dist/core/runner/halt-attribution.js +1 -1
  424. package/dist/core/runner/initial-run-state.d.ts +1 -1
  425. package/dist/core/runner/initial-run-state.js +2 -2
  426. package/dist/core/runner/left-as-is-seat.js +1 -1
  427. package/dist/core/runner/mcp-redial.d.ts +15 -4
  428. package/dist/core/runner/mcp-redial.js +53 -6
  429. package/dist/core/runner/memory-capture-optout.d.ts +7 -11
  430. package/dist/core/runner/memory-capture-optout.js +7 -4
  431. package/dist/core/runner/memory-phase-refusals.d.ts +19 -0
  432. package/dist/core/runner/memory-phase-refusals.js +18 -0
  433. package/dist/core/runner/messages-omitted-seat.d.ts +24 -1
  434. package/dist/core/runner/messages-omitted-seat.js +30 -9
  435. package/dist/core/runner/model-fallback-seat.d.ts +18 -5
  436. package/dist/core/runner/model-fallback-seat.js +29 -24
  437. package/dist/core/runner/model-lane-seat.d.ts +23 -1
  438. package/dist/core/runner/model-lane-seat.js +20 -2
  439. package/dist/core/runner/nested-memory-content.js +1 -1
  440. package/dist/core/runner/nested-memory-lane.d.ts +74 -59
  441. package/dist/core/runner/nested-memory-lane.js +335 -114
  442. package/dist/core/runner/own-model-money-door.d.ts +13 -0
  443. package/dist/core/runner/own-model-money-door.js +17 -0
  444. package/dist/core/runner/park-commit.d.ts +29 -6
  445. package/dist/core/runner/park-commit.js +20 -8
  446. package/dist/core/runner/permission-rule-lanes.d.ts +9 -0
  447. package/dist/core/runner/permission-rule-lanes.js +51 -11
  448. package/dist/core/runner/person-path-rows.d.ts +124 -21
  449. package/dist/core/runner/person-path-rows.js +179 -20
  450. package/dist/core/runner/placement-fence.d.ts +8 -2
  451. package/dist/core/runner/placement-fence.js +8 -3
  452. package/dist/core/runner/policy-throw.d.ts +3 -2
  453. package/dist/core/runner/policy-throw.js +2 -2
  454. package/dist/core/runner/prefix-ledger.d.ts +57 -3
  455. package/dist/core/runner/prefix-ledger.js +98 -8
  456. package/dist/core/runner/prepare-acquire-reconcile.d.ts +24 -14
  457. package/dist/core/runner/prepare-acquire-reconcile.js +44 -78
  458. package/dist/core/runner/prepare-advisor.js +2 -1
  459. package/dist/core/runner/prepare-artifact.d.ts +18 -2
  460. package/dist/core/runner/prepare-artifact.js +8 -3
  461. package/dist/core/runner/prepare-ask-lane.d.ts +12 -0
  462. package/dist/core/runner/prepare-ask-lane.js +19 -8
  463. package/dist/core/runner/prepare-boundary-parks.js +12 -5
  464. package/dist/core/runner/prepare-caps-and-workflow.js +37 -25
  465. package/dist/core/runner/prepare-config-doors.d.ts +22 -18
  466. package/dist/core/runner/prepare-config-doors.js +143 -127
  467. package/dist/core/runner/prepare-context-lane.d.ts +32 -11
  468. package/dist/core/runner/prepare-context-lane.js +77 -48
  469. package/dist/core/runner/prepare-defer-classify.d.ts +16 -0
  470. package/dist/core/runner/prepare-defer-classify.js +30 -8
  471. package/dist/core/runner/prepare-delegation-surface.d.ts +2 -0
  472. package/dist/core/runner/prepare-delegation-surface.js +8 -4
  473. package/dist/core/runner/prepare-execution-env.d.ts +7 -1
  474. package/dist/core/runner/prepare-execution-env.js +18 -8
  475. package/dist/core/runner/prepare-file-history.d.ts +26 -0
  476. package/dist/core/runner/prepare-file-history.js +19 -2
  477. package/dist/core/runner/prepare-gate-stations.d.ts +10 -0
  478. package/dist/core/runner/prepare-gate-stations.js +15 -6
  479. package/dist/core/runner/prepare-hands-readface.d.ts +28 -7
  480. package/dist/core/runner/prepare-hands-readface.js +83 -23
  481. package/dist/core/runner/prepare-inherited-gate.d.ts +28 -14
  482. package/dist/core/runner/prepare-inherited-gate.js +35 -17
  483. package/dist/core/runner/prepare-leg-adoption.d.ts +2 -2
  484. package/dist/core/runner/prepare-memory-engine-session.js +4 -2
  485. package/dist/core/runner/prepare-memory.d.ts +8 -1
  486. package/dist/core/runner/prepare-memory.js +37 -33
  487. package/dist/core/runner/prepare-offload-wrappers.d.ts +7 -7
  488. package/dist/core/runner/prepare-offload-wrappers.js +26 -17
  489. package/dist/core/runner/prepare-park-ask.d.ts +8 -11
  490. package/dist/core/runner/prepare-park-ask.js +18 -12
  491. package/dist/core/runner/prepare-policy-chain.d.ts +29 -1
  492. package/dist/core/runner/prepare-policy-chain.js +69 -33
  493. package/dist/core/runner/prepare-project-context.d.ts +4 -0
  494. package/dist/core/runner/prepare-project-context.js +9 -8
  495. package/dist/core/runner/prepare-prompt-assembly.d.ts +3 -0
  496. package/dist/core/runner/prepare-prompt-assembly.js +6 -5
  497. package/dist/core/runner/prepare-protocol-tools.d.ts +2 -2
  498. package/dist/core/runner/prepare-protocol-tools.js +44 -24
  499. package/dist/core/runner/prepare-question-face.d.ts +4 -9
  500. package/dist/core/runner/prepare-question-face.js +8 -3
  501. package/dist/core/runner/prepare-suspend-saga.d.ts +11 -2
  502. package/dist/core/runner/prepare-suspend-saga.js +28 -8
  503. package/dist/core/runner/prepare-task.d.ts +4 -7
  504. package/dist/core/runner/prepare-task.js +203 -74
  505. package/dist/core/runner/prepare-tool-disclosure-mount.js +10 -5
  506. package/dist/core/runner/prepare-turn-wiring.d.ts +3 -1
  507. package/dist/core/runner/prepare-turn-wiring.js +15 -11
  508. package/dist/core/runner/prepare-wiring-manifest.d.ts +6 -19
  509. package/dist/core/runner/prepare-wiring-manifest.js +17 -35
  510. package/dist/core/runner/prepare-workspace-restore.d.ts +4 -11
  511. package/dist/core/runner/prepare-workspace-restore.js +60 -42
  512. package/dist/core/runner/read-root-grant.d.ts +49 -13
  513. package/dist/core/runner/read-root-grant.js +54 -21
  514. package/dist/core/runner/read-session-changes.d.ts +9 -0
  515. package/dist/core/runner/read-session-changes.js +192 -0
  516. package/dist/core/runner/remote-env-retry.d.ts +4 -4
  517. package/dist/core/runner/resume-admission.d.ts +14 -7
  518. package/dist/core/runner/resume-admission.js +28 -16
  519. package/dist/core/runner/resume-apply.js +9 -6
  520. package/dist/core/runner/resume-checkpoint-screen.d.ts +7 -2
  521. package/dist/core/runner/resume-checkpoint-screen.js +32 -17
  522. package/dist/core/runner/resume-claim.d.ts +2 -2
  523. package/dist/core/runner/resume-claim.js +4 -4
  524. package/dist/core/runner/resume-internals-and-config.d.ts +3 -0
  525. package/dist/core/runner/resume-internals-and-config.js +10 -7
  526. package/dist/core/runner/resume-policy-outcome.d.ts +5 -4
  527. package/dist/core/runner/resume-policy-outcome.js +8 -6
  528. package/dist/core/runner/resume-preflight.d.ts +3 -0
  529. package/dist/core/runner/resume-preflight.js +10 -3
  530. package/dist/core/runner/retired-name-policy.d.ts +15 -0
  531. package/dist/core/runner/retired-name-policy.js +37 -0
  532. package/dist/core/runner/retired-runner-deps.js +3 -1
  533. package/dist/core/runner/rewind-conversation.d.ts +10 -0
  534. package/dist/core/runner/rewind-conversation.js +107 -0
  535. package/dist/core/runner/rewind-files.js +56 -24
  536. package/dist/core/runner/rewind-outcome.d.ts +27 -0
  537. package/dist/core/runner/rewind-outcome.js +14 -0
  538. package/dist/core/runner/rewind-target.d.ts +28 -0
  539. package/dist/core/runner/rewind-target.js +58 -0
  540. package/dist/core/runner/role-resolution-table.d.ts +3 -16
  541. package/dist/core/runner/role-resolution-table.js +1 -3
  542. package/dist/core/runner/role-seat-defaulted.d.ts +14 -5
  543. package/dist/core/runner/role-seat-defaulted.js +17 -13
  544. package/dist/core/runner/rule-store-unreadable-notice.d.ts +8 -6
  545. package/dist/core/runner/rule-store-unreadable-notice.js +6 -4
  546. package/dist/core/runner/run-attachment-seats.js +2 -1
  547. package/dist/core/runner/run-clock-and-content.js +2 -0
  548. package/dist/core/runner/run-compaction-machinery.js +2 -2
  549. package/dist/core/runner/run-harness-handlers.js +43 -11
  550. package/dist/core/runner/run-identity-wiring.d.ts +2 -0
  551. package/dist/core/runner/run-identity-wiring.js +5 -2
  552. package/dist/core/runner/run-leg.js +30 -29
  553. package/dist/core/runner/run-notification-lane.d.ts +3 -0
  554. package/dist/core/runner/run-notification-lane.js +4 -4
  555. package/dist/core/runner/run-settle-and-teardown.d.ts +4 -2
  556. package/dist/core/runner/run-settle-and-teardown.js +78 -51
  557. package/dist/core/runner/run-stop-and-final-verify.d.ts +4 -0
  558. package/dist/core/runner/run-stop-and-final-verify.js +71 -73
  559. package/dist/core/runner/run-telemetry-and-budget-seats.js +14 -8
  560. package/dist/core/runner/run-terminal-adoption.d.ts +1 -1
  561. package/dist/core/runner/run-terminal-adoption.js +3 -3
  562. package/dist/core/runner/run-turn-boundary.js +10 -6
  563. package/dist/core/runner/runtask.d.ts +29 -20
  564. package/dist/core/runner/runtask.js +35 -16
  565. package/dist/core/runner/sandbox-network-seat.js +1 -1
  566. package/dist/core/runner/seat-model-doors.d.ts +6 -5
  567. package/dist/core/runner/seat-model-doors.js +4 -3
  568. package/dist/core/runner/session-call-grant-station.d.ts +64 -0
  569. package/dist/core/runner/session-call-grant-station.js +119 -0
  570. package/dist/core/runner/session-file-state-replay.d.ts +47 -8
  571. package/dist/core/runner/session-file-state-replay.js +99 -13
  572. package/dist/core/runner/session-files-open.d.ts +64 -0
  573. package/dist/core/runner/session-files-open.js +33 -0
  574. package/dist/core/runner/session-prompt-seats.d.ts +95 -0
  575. package/dist/core/runner/session-prompt-seats.js +62 -0
  576. package/dist/core/runner/session-read-file-states.d.ts +37 -41
  577. package/dist/core/runner/session-read-file-states.js +14 -6
  578. package/dist/core/runner/session-rule-policy.d.ts +5 -0
  579. package/dist/core/runner/session-rule-policy.js +16 -9
  580. package/dist/core/runner/session-verb-doors.d.ts +41 -4
  581. package/dist/core/runner/session-verb-doors.js +66 -11
  582. package/dist/core/runner/session-write-ledger.d.ts +8 -0
  583. package/dist/core/runner/session-write-ledger.js +16 -0
  584. package/dist/core/runner/shared-read-classifier.d.ts +14 -3
  585. package/dist/core/runner/shared-read-classifier.js +14 -6
  586. package/dist/core/runner/shell-env-withheld.d.ts +4 -2
  587. package/dist/core/runner/shell-env-withheld.js +3 -2
  588. package/dist/core/runner/side-call-account.d.ts +47 -5
  589. package/dist/core/runner/side-call-account.js +42 -4
  590. package/dist/core/runner/skipped-rules-notice.d.ts +5 -5
  591. package/dist/core/runner/skipped-rules-notice.js +3 -3
  592. package/dist/core/runner/stop-tail-notice.d.ts +7 -0
  593. package/dist/core/runner/stop-tail-notice.js +23 -8
  594. package/dist/core/runner/stream-reap.js +4 -2
  595. package/dist/core/runner/stream-settle-backstop.d.ts +1 -1
  596. package/dist/core/runner/stream-settle-backstop.js +20 -20
  597. package/dist/core/runner/sub-agent-deny-lists.d.ts +26 -7
  598. package/dist/core/runner/sub-agent-deny-lists.js +23 -15
  599. package/dist/core/runner/task-start-doors.d.ts +7 -3
  600. package/dist/core/runner/task-start-doors.js +72 -31
  601. package/dist/core/runner/terminal-account.js +26 -11
  602. package/dist/core/runner/terminal-projection.d.ts +4 -2
  603. package/dist/core/runner/terminal-projection.js +2 -2
  604. package/dist/core/runner/tool-defer-gate.d.ts +1 -1
  605. package/dist/core/runner/tool-end-body.d.ts +8 -1
  606. package/dist/core/runner/tool-end-body.js +4 -3
  607. package/dist/core/runner/tool-face-overlay.js +6 -4
  608. package/dist/core/runner/tool-result-media-seat.d.ts +2 -1
  609. package/dist/core/runner/tool-table-view.js +1 -1
  610. package/dist/core/runner/tool-turn-repair-seat.d.ts +2 -2
  611. package/dist/core/runner/tool-turn-repair-seat.js +12 -7
  612. package/dist/core/runner/trim-stretch.d.ts +43 -0
  613. package/dist/core/runner/trim-stretch.js +34 -0
  614. package/dist/core/runner/turn-attachments.d.ts +22 -1
  615. package/dist/core/runner/turn-attachments.js +27 -5
  616. package/dist/core/runner/unreadable-person-rows.d.ts +39 -0
  617. package/dist/core/runner/unreadable-person-rows.js +20 -0
  618. package/dist/core/runner/verdict-refusal.d.ts +22 -7
  619. package/dist/core/runner/verdict-refusal.js +35 -3
  620. package/dist/core/runner/workspace-sync.d.ts +49 -0
  621. package/dist/core/runner/workspace-sync.js +170 -0
  622. package/dist/core/runner-deps.d.ts +63 -34
  623. package/dist/core/scheduler.d.ts +34 -14
  624. package/dist/core/secret-env.d.ts +188 -18
  625. package/dist/core/secret-env.js +291 -56
  626. package/dist/core/sensitive-path-policy.js +3 -2
  627. package/dist/core/session-call-grant-screen.d.ts +58 -0
  628. package/dist/core/session-call-grant-screen.js +18 -0
  629. package/dist/core/session-call-grant.d.ts +93 -0
  630. package/dist/core/session-call-grant.js +524 -0
  631. package/dist/core/session-changes.d.ts +260 -0
  632. package/dist/core/session-changes.js +40 -0
  633. package/dist/core/session-checkout.d.ts +90 -3
  634. package/dist/core/session-checkout.js +142 -9
  635. package/dist/core/session-log-transfer.js +13 -7
  636. package/dist/core/session-policy-store.d.ts +54 -12
  637. package/dist/core/session-policy-store.js +66 -26
  638. package/dist/core/session-store.d.ts +41 -11
  639. package/dist/core/session-store.js +59 -16
  640. package/dist/core/session.d.ts +92 -13
  641. package/dist/core/session.js +8 -1
  642. package/dist/core/shared-artifact-reads.d.ts +93 -0
  643. package/dist/core/shared-artifact-reads.js +94 -0
  644. package/dist/core/shell-read-silence.d.ts +3 -3
  645. package/dist/core/shell-read-silence.js +3 -1
  646. package/dist/core/shell-run-candidates.d.ts +23 -6
  647. package/dist/core/shell-run-candidates.js +34 -11
  648. package/dist/core/skill-grant.d.ts +11 -6
  649. package/dist/core/skill-grant.js +24 -16
  650. package/dist/core/skills-directory.d.ts +9 -45
  651. package/dist/core/skills-directory.js +9 -722
  652. package/dist/core/spend-account.d.ts +232 -0
  653. package/dist/core/spend-account.js +289 -0
  654. package/dist/core/store-contracts/background-agent-store-contract.js +85 -0
  655. package/dist/core/store-contracts/checkpoint-store-contract.d.ts +28 -6
  656. package/dist/core/store-contracts/checkpoint-store-contract.js +423 -35
  657. package/dist/core/store-contracts/file-history-store-contract.d.ts +11 -3
  658. package/dist/core/store-contracts/file-history-store-contract.js +66 -6
  659. package/dist/core/store-contracts/grant-fixture.d.ts +52 -0
  660. package/dist/core/store-contracts/grant-fixture.js +84 -0
  661. package/dist/core/store-contracts/mailbox-store-contract.d.ts +2 -1
  662. package/dist/core/store-contracts/mailbox-store-contract.js +22 -11
  663. package/dist/core/store-contracts/peer-directory-contract.js +8 -0
  664. package/dist/core/store-contracts/permission-rule-sync-contract.js +3 -3
  665. package/dist/core/store-contracts/session-deletion-cascade-contract.js +23 -4
  666. package/dist/core/store-contracts/session-policy-store-contract.js +9 -0
  667. package/dist/core/store-contracts/session-repo-contract.js +56 -1
  668. package/dist/core/store-contracts/session-store-contract.d.ts +35 -2
  669. package/dist/core/store-contracts/session-store-contract.js +579 -6
  670. package/dist/core/store-contracts/tool-result-store-contract.js +8 -7
  671. package/dist/core/store-contracts/workflow-journal-store-contract.js +80 -8
  672. package/dist/core/suspend-lane-reasons.d.ts +13 -0
  673. package/dist/core/suspend-lane-reasons.js +5 -0
  674. package/dist/core/synthetic-read-verdict.d.ts +5 -3
  675. package/dist/core/synthetic-read-verdict.js +1 -1
  676. package/dist/core/task-event.d.ts +57 -53
  677. package/dist/core/task-limits.d.ts +30 -8
  678. package/dist/core/task-notification.d.ts +50 -19
  679. package/dist/core/task-notification.js +54 -18
  680. package/dist/core/task-registry-agent.d.ts +36 -31
  681. package/dist/core/task-registry-agent.js +116 -35
  682. package/dist/core/task-registry-monitor.js +2 -1
  683. package/dist/core/task-registry-shared.d.ts +112 -20
  684. package/dist/core/task-registry-shared.js +33 -7
  685. package/dist/core/task-registry-workflow.d.ts +9 -1
  686. package/dist/core/task-registry-workflow.js +11 -3
  687. package/dist/core/task-registry.d.ts +47 -28
  688. package/dist/core/task-registry.js +77 -20
  689. package/dist/core/task-result.d.ts +199 -35
  690. package/dist/core/task-spec-members.d.ts +21 -3
  691. package/dist/core/task-spec-members.js +11 -2
  692. package/dist/core/task-spec.d.ts +59 -48
  693. package/dist/core/task-start-judge.js +10 -3
  694. package/dist/core/task-stream.d.ts +2 -1
  695. package/dist/core/terminal-cause.d.ts +94 -3
  696. package/dist/core/tool-catalog-entries.js +2 -2
  697. package/dist/core/tool-check-reading.js +2 -1
  698. package/dist/core/tool-errors.js +2 -0
  699. package/dist/core/tool-face-reader.d.ts +3 -2
  700. package/dist/core/tool-gate-phase.d.ts +16 -0
  701. package/dist/core/tool-gate-phase.js +1 -0
  702. package/dist/core/tool-list-grammar.d.ts +0 -47
  703. package/dist/core/tool-list-grammar.js +1 -75
  704. package/dist/core/tool-model-gate.d.ts +7 -11
  705. package/dist/core/tool-model-gate.js +5 -8
  706. package/dist/core/tool-mount-plan.d.ts +7 -0
  707. package/dist/core/tool-mount-plan.js +25 -1
  708. package/dist/core/tool-mount-static.js +3 -2
  709. package/dist/core/tool-name-aliases.d.ts +81 -106
  710. package/dist/core/tool-name-aliases.js +59 -155
  711. package/dist/core/tool-name-readings.d.ts +6 -0
  712. package/dist/core/tool-name-readings.js +10 -1
  713. package/dist/core/tool-policy.d.ts +211 -64
  714. package/dist/core/tool-policy.js +146 -81
  715. package/dist/core/tool-registry.d.ts +2 -0
  716. package/dist/core/tool-registry.js +3 -0
  717. package/dist/core/tool-result-bytes.d.ts +27 -3
  718. package/dist/core/tool-result-bytes.js +53 -0
  719. package/dist/core/tool-result-store.d.ts +11 -28
  720. package/dist/core/tool-result-store.js +7 -38
  721. package/dist/core/tool-roster.d.ts +33 -22
  722. package/dist/core/tool-roster.js +28 -18
  723. package/dist/core/tool-spec-members.d.ts +12 -0
  724. package/dist/core/tool-spec-members.js +31 -0
  725. package/dist/core/tool-spec.d.ts +46 -29
  726. package/dist/core/trace.d.ts +21 -64
  727. package/dist/core/trace.js +2 -3
  728. package/dist/core/types.d.ts +7 -7
  729. package/dist/core/types.js +2 -2
  730. package/dist/core/unavailable-landing.d.ts +72 -0
  731. package/dist/core/unavailable-landing.js +18 -0
  732. package/dist/core/untrusted-egress.d.ts +27 -5
  733. package/dist/core/untrusted-egress.js +32 -10
  734. package/dist/core/untrusted-text.d.ts +8 -0
  735. package/dist/core/untrusted-text.js +14 -0
  736. package/dist/core/usage-window-store.d.ts +11 -1
  737. package/dist/core/usage-window-store.js +5 -0
  738. package/dist/core/user-attachment.d.ts +89 -48
  739. package/dist/core/user-attachment.js +168 -76
  740. package/dist/core/user-row-origin.d.ts +10 -0
  741. package/dist/core/user-row-origin.js +6 -0
  742. package/dist/core/wiring-manifest.d.ts +95 -30
  743. package/dist/core/wiring-manifest.js +65 -13
  744. package/dist/core/workflow-journal-store.d.ts +70 -14
  745. package/dist/core/workflow-journal-store.js +68 -16
  746. package/dist/core/workflow-run-store-contract.js +158 -1
  747. package/dist/core/workflow-run-store.d.ts +138 -23
  748. package/dist/core/workflow-run-store.js +91 -13
  749. package/dist/engine/compaction/compaction.d.ts +15 -3
  750. package/dist/engine/compaction/compaction.js +29 -10
  751. package/dist/engine/execution-env/kill-tree.js +44 -49
  752. package/dist/engine/execution-env/node-execution-env.d.ts +6 -1
  753. package/dist/engine/execution-env/node-execution-env.js +22 -11
  754. package/dist/engine/harness/agent-harness.d.ts +23 -5
  755. package/dist/engine/harness/agent-harness.js +28 -5
  756. package/dist/engine/harness/types.d.ts +118 -30
  757. package/dist/engine/harness/types.js +36 -4
  758. package/dist/engine/llm/rejected-images.js +1 -1
  759. package/dist/engine/llm/tool-turns.d.ts +1 -1
  760. package/dist/engine/llm/types.d.ts +27 -6
  761. package/dist/engine/llm/types.js +5 -2
  762. package/dist/engine/loop/agent-loop.js +43 -11
  763. package/dist/engine/loop/types.d.ts +11 -0
  764. package/dist/engine/session/import-validate.d.ts +9 -0
  765. package/dist/engine/session/import-validate.js +50 -9
  766. package/dist/engine/session/memory-repo.d.ts +20 -4
  767. package/dist/engine/session/memory-repo.js +28 -5
  768. package/dist/engine/session/memory-storage.d.ts +5 -0
  769. package/dist/engine/session/memory-storage.js +8 -3
  770. package/dist/engine/session/parent-chain-guard.js +1 -1
  771. package/dist/engine/session/path-to-root.js +1 -1
  772. package/dist/engine/session/repo-utils.d.ts +28 -12
  773. package/dist/engine/session/repo-utils.js +26 -7
  774. package/dist/engine/session/session.d.ts +30 -10
  775. package/dist/engine/session/session.js +52 -20
  776. package/dist/engine/session/storage-base.d.ts +20 -7
  777. package/dist/engine/session/storage-base.js +15 -3
  778. package/dist/fixtures/index.d.ts +3 -1
  779. package/dist/fixtures/index.js +3 -0
  780. package/dist/host-env.d.ts +17 -0
  781. package/dist/host-env.js +1 -0
  782. package/dist/index.d.ts +113 -53
  783. package/dist/index.js +88 -39
  784. package/dist/internal/harness-types.d.ts +1 -1
  785. package/dist/internal/harness.d.ts +5 -3
  786. package/dist/internal/harness.js +4 -3
  787. package/dist/internal/llm.d.ts +1 -1
  788. package/dist/internal/llm.js +1 -1
  789. package/dist/orchestration/run-workflow-tool.d.ts +53 -13
  790. package/dist/orchestration/run-workflow-tool.js +305 -133
  791. package/dist/orchestration/workflow-catalog.d.ts +254 -0
  792. package/dist/orchestration/workflow-catalog.js +702 -0
  793. package/dist/orchestration/workflow-governance.d.ts +1 -1
  794. package/dist/orchestration/workflow-meta.d.ts +11 -1
  795. package/dist/orchestration/workflow-meta.js +48 -0
  796. package/dist/orchestration/workflow-observe.d.ts +8 -10
  797. package/dist/orchestration/workflow-observe.js +6 -1
  798. package/dist/orchestration/workflow-park-adoption.d.ts +355 -100
  799. package/dist/orchestration/workflow-park-adoption.js +676 -298
  800. package/dist/orchestration/workflow-requirements.d.ts +51 -0
  801. package/dist/orchestration/workflow-requirements.js +54 -0
  802. package/dist/orchestration/workflow-script-runner.d.ts +18 -0
  803. package/dist/orchestration/workflow-script-store.d.ts +19 -64
  804. package/dist/orchestration/workflow-script-store.js +1 -24
  805. package/dist/orchestration/workflow-tree-id.d.ts +66 -0
  806. package/dist/orchestration/workflow-tree-id.js +66 -0
  807. package/dist/orchestration/workflow-types.d.ts +258 -47
  808. package/dist/orchestration/workflow-types.js +32 -5
  809. package/dist/orchestration/workflow.d.ts +86 -46
  810. package/dist/orchestration/workflow.js +1050 -225
  811. package/dist/prompt-assembly/catalog/constitution.js +5 -1
  812. package/dist/prompt-assembly/catalog/core-behavior.d.ts +3 -4
  813. package/dist/prompt-assembly/catalog/core-behavior.js +67 -24
  814. package/dist/prompt-assembly/catalog/engine.d.ts +36 -0
  815. package/dist/prompt-assembly/catalog/engine.js +4 -0
  816. package/dist/prompt-assembly/catalog/environment.js +2 -2
  817. package/dist/prompt-assembly/catalog/events.d.ts +32 -0
  818. package/dist/prompt-assembly/catalog/events.js +4 -0
  819. package/dist/prompt-assembly/catalog/locales/zh-Hans/core-behavior.js +79 -44
  820. package/dist/prompt-assembly/catalog/locales/zh-Hans/engine.js +4 -0
  821. package/dist/prompt-assembly/catalog/locales/zh-Hans/environment.js +2 -2
  822. package/dist/prompt-assembly/catalog/locales/zh-Hans/events.js +4 -0
  823. package/dist/prompt-assembly/catalog/locales/zh-Hans/mechanism.js +2 -2
  824. package/dist/prompt-assembly/catalog/mechanism.js +2 -2
  825. package/dist/prompt-assembly/catalog/schema.d.ts +10 -3
  826. package/dist/prompt-assembly/catalog/schema.js +3 -0
  827. package/dist/prompt-assembly/catalog/sections.js +3 -14
  828. package/dist/prompt-assembly/epoch.d.ts +26 -0
  829. package/dist/prompt-assembly/epoch.js +29 -0
  830. package/dist/prompt-assembly/event-registry.js +4 -0
  831. package/dist/prompt-assembly/select.js +1 -0
  832. package/dist/prompt-assembly/tool-catalog.d.ts +11 -8
  833. package/dist/prompt-assembly/tool-catalog.js +21 -7
  834. package/dist/prompt-assembly/turn-snapshot.d.ts +1 -1
  835. package/dist/prompt-assembly/types.d.ts +3 -0
  836. package/dist/prompts/default.d.ts +6 -3
  837. package/dist/prompts/default.js +6 -0
  838. package/dist/shell/lex.d.ts +10 -7
  839. package/dist/shell/lex.js +56 -6
  840. package/dist/stores/file/adoption/adopt.d.ts +12 -0
  841. package/dist/stores/file/adoption/adopt.js +78 -31
  842. package/dist/stores/file/adoption/marker.d.ts +48 -26
  843. package/dist/stores/file/adoption/marker.js +24 -11
  844. package/dist/stores/file/background-agent-store.d.ts +5 -0
  845. package/dist/stores/file/background-agent-store.js +26 -5
  846. package/dist/stores/file/checkpoint-store.d.ts +11 -10
  847. package/dist/stores/file/checkpoint-store.js +36 -10
  848. package/dist/stores/file/data-root-declaration.js +2 -1
  849. package/dist/stores/file/descriptor-seat.d.ts +100 -0
  850. package/dist/stores/file/descriptor-seat.js +150 -0
  851. package/dist/stores/file/file-history-store.d.ts +6 -0
  852. package/dist/stores/file/file-history-store.js +23 -5
  853. package/dist/stores/file/fs-atomic.d.ts +127 -79
  854. package/dist/stores/file/fs-atomic.js +313 -253
  855. package/dist/stores/file/index.d.ts +24 -5
  856. package/dist/stores/file/index.js +49 -21
  857. package/dist/stores/file/ledger-damage.js +6 -10
  858. package/dist/stores/file/lock-reading.d.ts +158 -0
  859. package/dist/stores/file/lock-reading.js +252 -0
  860. package/dist/stores/file/mailbox-store.d.ts +8 -5
  861. package/dist/stores/file/mailbox-store.js +23 -14
  862. package/dist/stores/file/permission-rule-adopt.js +11 -11
  863. package/dist/stores/file/permission-rule-store.d.ts +14 -3
  864. package/dist/stores/file/permission-rule-store.js +33 -37
  865. package/dist/stores/file/process-anchor.d.ts +93 -0
  866. package/dist/stores/file/process-anchor.js +392 -0
  867. package/dist/stores/file/session-policy-store.d.ts +18 -2
  868. package/dist/stores/file/session-policy-store.js +56 -5
  869. package/dist/stores/file/session-store.d.ts +46 -1
  870. package/dist/stores/file/session-store.js +129 -25
  871. package/dist/stores/file/shared-ledger.d.ts +3 -3
  872. package/dist/stores/file/task-list-store.js +1 -1
  873. package/dist/stores/file/tool-result-store.js +2 -1
  874. package/dist/stores/file/usage-window-store.js +1 -1
  875. package/dist/stores/file/workflow-journal-store.d.ts +19 -6
  876. package/dist/stores/file/workflow-journal-store.js +43 -48
  877. package/dist/stores/file/workflow-run-store.d.ts +20 -4
  878. package/dist/stores/file/workflow-run-store.js +95 -12
  879. package/dist/tools/artifact/artifact-text.d.ts +29 -11
  880. package/dist/tools/artifact/artifact-text.js +13 -6
  881. package/dist/tools/artifact/artifact-tool.d.ts +45 -8
  882. package/dist/tools/artifact/artifact-tool.js +256 -46
  883. package/dist/tools/artifact/conformance.d.ts +27 -5
  884. package/dist/tools/artifact/conformance.js +420 -45
  885. package/dist/tools/artifact/local-stub.d.ts +2 -2
  886. package/dist/tools/artifact/local-stub.js +29 -26
  887. package/dist/tools/fs/bash-failure-output.d.ts +64 -0
  888. package/dist/tools/fs/bash-failure-output.js +40 -0
  889. package/dist/tools/fs/bash-program-position.d.ts +17 -7
  890. package/dist/tools/fs/bash-program-position.js +20 -14
  891. package/dist/tools/fs/bash-readonly-classifier.d.ts +7 -4
  892. package/dist/tools/fs/bash-readonly-classifier.js +9 -2
  893. package/dist/tools/fs/bound-open.d.ts +9 -8
  894. package/dist/tools/fs/bound-open.js +6 -4
  895. package/dist/tools/fs/dead-cwd.d.ts +8 -0
  896. package/dist/tools/fs/dead-cwd.js +7 -7
  897. package/dist/tools/fs/file-read-check.d.ts +8 -6
  898. package/dist/tools/fs/file-read-check.js +8 -4
  899. package/dist/tools/fs/file-write-check.d.ts +14 -0
  900. package/dist/tools/fs/file-write-check.js +35 -0
  901. package/dist/tools/fs/find-actions.d.ts +200 -0
  902. package/dist/tools/fs/find-actions.js +791 -0
  903. package/dist/tools/fs/fs-bash.d.ts +6 -3
  904. package/dist/tools/fs/fs-bash.js +75 -65
  905. package/dist/tools/fs/fs-pdf.js +16 -5
  906. package/dist/tools/fs/fs-read.js +5 -3
  907. package/dist/tools/fs/fs-shared.d.ts +67 -32
  908. package/dist/tools/fs/fs-shared.js +70 -39
  909. package/dist/tools/fs/fs-write.d.ts +23 -3
  910. package/dist/tools/fs/fs-write.js +139 -34
  911. package/dist/tools/fs/index.d.ts +15 -2
  912. package/dist/tools/fs/index.js +8 -4
  913. package/dist/tools/fs/program-read-model.d.ts +17 -1
  914. package/dist/tools/fs/program-read-model.js +7 -2
  915. package/dist/tools/fs/program-read-model.rows.js +5 -1
  916. package/dist/tools/fs/read-deny-home.js +12 -5
  917. package/dist/tools/fs/read-deny.d.ts +6 -1
  918. package/dist/tools/fs/read-deny.js +6 -1
  919. package/dist/tools/fs/read-floor.d.ts +22 -0
  920. package/dist/tools/fs/read-floor.js +15 -6
  921. package/dist/tools/fs/removal-actions.d.ts +43 -0
  922. package/dist/tools/fs/removal-actions.js +25 -0
  923. package/dist/tools/fs/removal-targets.d.ts +4 -5
  924. package/dist/tools/fs/removal-targets.js +115 -6
  925. package/dist/tools/fs/safety.d.ts +39 -1
  926. package/dist/tools/fs/safety.js +61 -2
  927. package/dist/tools/fs/shell-climb.d.ts +46 -0
  928. package/dist/tools/fs/shell-climb.js +79 -0
  929. package/dist/tools/fs/shell-read-bindings.d.ts +56 -7
  930. package/dist/tools/fs/shell-read-bindings.js +175 -26
  931. package/dist/tools/fs/shell-read-check.d.ts +11 -2
  932. package/dist/tools/fs/shell-read-check.js +78 -24
  933. package/dist/tools/fs/shell-read-command-environment.d.ts +56 -0
  934. package/dist/tools/fs/shell-read-command-environment.js +75 -0
  935. package/dist/tools/fs/shell-read-establish.js +97 -37
  936. package/dist/tools/fs/shell-read-judge.d.ts +62 -9
  937. package/dist/tools/fs/shell-read-judge.js +67 -25
  938. package/dist/tools/fs/shell-read-lost-walk.d.ts +19 -0
  939. package/dist/tools/fs/shell-read-lost-walk.js +35 -0
  940. package/dist/tools/fs/shell-read-plan.d.ts +7 -0
  941. package/dist/tools/fs/shell-read-plan.js +47 -13
  942. package/dist/tools/fs/shell-read-sourced.d.ts +4 -3
  943. package/dist/tools/fs/shell-read-sourced.js +28 -3
  944. package/dist/tools/fs/shell-read-start.d.ts +7 -0
  945. package/dist/tools/fs/shell-read-word.js +1 -0
  946. package/dist/tools/fs/shell-read-workdir.d.ts +9 -11
  947. package/dist/tools/fs/shell-read-workdir.js +23 -28
  948. package/dist/tools/fs/shell-read-write-targets.d.ts +17 -8
  949. package/dist/tools/fs/shell-read-write-targets.js +54 -9
  950. package/dist/tools/monitor.d.ts +2 -1
  951. package/dist/tools/monitor.js +2 -0
  952. package/dist/tools/scheduler-tools.d.ts +7 -4
  953. package/dist/tools/scheduler-tools.js +60 -20
  954. package/dist/tools/task-list.d.ts +11 -1
  955. package/dist/tools/task-list.js +187 -134
  956. package/dist/tools/todo.d.ts +1 -1
  957. package/dist/tools/worktree.js +10 -9
  958. package/package.json +6 -2
  959. package/test/export-surface.snapshot.json +760 -36
  960. package/wire-changes/core-stores-sql@7.68.7.json +39 -0
  961. package/wire-changes/core-stores-sql@7.70.0.json +414 -0
  962. package/wire-changes/core-stores-sql@7.71.0.json +40 -0
  963. package/wire-changes/core@7.68.7.json +140 -0
  964. package/wire-changes/core@7.70.0.json +14689 -0
  965. package/wire-changes/core@7.71.0.json +5827 -0
  966. package/wire-changes/mods-kernel@7.68.7.json +39 -0
  967. package/wire-changes/mods-kernel@7.70.0.json +75 -0
  968. package/wire-changes/mods-kernel@7.71.0.json +52 -0
  969. package/wire-changes/primitives@7.68.7.json +39 -0
  970. package/wire-changes/primitives@7.70.0.json +807 -0
  971. package/wire-changes/primitives@7.71.0.json +473 -0
  972. package/wire-changes/wiki-gate@7.68.7.json +39 -0
  973. package/wire-changes/wiki-gate@7.70.0.json +40 -0
  974. package/wire-changes/wiki-gate@7.71.0.json +40 -0
  975. package/dist/core/cache-break-detector.d.ts +0 -98
  976. package/dist/core/cache-break-detector.js +0 -146
  977. package/dist/core/compaction-retired-members.d.ts +0 -12
  978. package/dist/core/compaction-retired-members.js +0 -22
  979. package/dist/core/frontmatter-fence.d.ts +0 -10
  980. package/dist/core/frontmatter-fence.js +0 -6
  981. package/dist/core/loopback-host.d.ts +0 -18
  982. package/dist/core/loopback-host.js +0 -40
  983. package/dist/core/permission-rule-syntax.d.ts +0 -46
  984. package/dist/core/permission-rule-syntax.js +0 -52
  985. package/dist/core/protocol-naming.d.ts +0 -95
  986. package/dist/core/protocol-naming.js +0 -70
  987. package/dist/core/protocol-table.d.ts +0 -88
  988. package/dist/core/protocol-table.js +0 -47
@@ -1,11 +1,13 @@
1
- import { journalKeepsLaunches, readKeptLaunch } from "../core/workflow-journal-store.js";
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import { resumedFromOf, workflowRunCreationIdOf } from "../core/workflow-run-store.js";
3
+ import { journalKeepsLaunches, readKeptLaunch, RESUME_CLAIM_REMAINING_MS_MAX } from "../core/workflow-journal-store.js";
2
4
  import { parentConstraintChainVerdict } from "../core/runner/resume-checkpoint-screen.js";
3
5
  import { judgeCheckpointRow } from "../core/checkpoint-row-verdict.js";
4
6
  import { readMember, thrownName, thrownText } from "../core/thrown-value.js";
5
7
  import { inlineUntrusted } from "../core/untrusted-text.js";
6
8
  import { egressText } from "../core/untrusted-egress.js";
7
9
  import { foreignLine } from "../core/protocol-http-auth.js";
8
- import { WORKFLOW_AGENT_PARKED_ERROR_CODE, WORKFLOW_PARK_SETTLED_DECISIONS_MAX, workflowParkHolderOf } from "./workflow-types.js";
10
+ import { WORKFLOW_AGENT_PARKED_ERROR_CODE, WORKFLOW_PARK_DECISION_MARK_BYTES_MAX, WORKFLOW_PARK_SETTLED_DECISIONS_MAX, WORKFLOW_STORE_WAIT_BOUND_MS, parkHolderAmong, workflowParkHolderOf } from "./workflow-types.js";
9
11
  export const WORKFLOW_PARK_UNUSED_REASONS = Object.freeze([
10
12
  "workflow_not_mounted",
11
13
  "entry_unreadable",
@@ -18,21 +20,56 @@ export const WORKFLOW_PARK_UNUSED_REASONS = Object.freeze([
18
20
  "host_changed",
19
21
  "denied",
20
22
  "ask_unanswerable",
23
+ "call_changed",
21
24
  "launch_refused",
22
25
  "continuing_elsewhere",
23
26
  "card_unresumable",
24
27
  "waiting_elsewhere",
25
28
  "run_not_ended",
26
29
  ]);
27
- export const WORKFLOW_PARK_SETTLING_REASONS = Object.freeze(["decision_spent", "card_unresumable", "launch_unreadable", "denied"]);
28
- const SETTLING = new Set(WORKFLOW_PARK_SETTLING_REASONS);
30
+ function frozenRows(table) {
31
+ for (const row of Object.values(table))
32
+ Object.freeze(row);
33
+ return Object.freeze(table);
34
+ }
35
+ export const WORKFLOW_PARK_UNUSED_REASON_CLASS = frozenRows({
36
+ workflow_not_mounted: { kept: "deliverable" },
37
+ entry_unreadable: { kept: "decide_again" },
38
+ record_unreadable: { kept: "deliverable" },
39
+ not_holder: { kept: "deliverable" },
40
+ not_pending: { kept: "withdraw" },
41
+ decision_spent: { spent: "decide_again" },
42
+ launch_unrecorded: { kept: "deliverable" },
43
+ launch_unreadable: { spent: "start_over" },
44
+ host_changed: { kept: "deliverable" },
45
+ denied: { kept: "deliverable", spent: "decide_again", spentWhen: "explicit" },
46
+ ask_unanswerable: { kept: "deliverable" },
47
+ call_changed: { kept: "deliverable" },
48
+ launch_refused: { kept: "deliverable" },
49
+ continuing_elsewhere: { kept: "deliverable" },
50
+ card_unresumable: { kept: "deliverable", spent: "start_over", spentWhen: "terminal" },
51
+ waiting_elsewhere: { kept: "deliverable" },
52
+ run_not_ended: { kept: "deliverable" },
53
+ });
54
+ export function workflowParkUnusedClassOf(reason, spent) {
55
+ if (typeof spent !== "boolean" || typeof reason !== "string" || !Object.hasOwn(WORKFLOW_PARK_UNUSED_REASON_CLASS, reason))
56
+ return undefined;
57
+ const row = WORKFLOW_PARK_UNUSED_REASON_CLASS[reason];
58
+ return spent ? row.spent : row.kept;
59
+ }
60
+ const SETTLING = new Set(WORKFLOW_PARK_UNUSED_REASONS.filter((r) => WORKFLOW_PARK_UNUSED_REASON_CLASS[r].spent !== undefined));
61
+ const UNMARKED_REASONS = new Set(["workflow_not_mounted", "entry_unreadable", "record_unreadable", "run_not_ended", "not_pending", "not_holder"]);
29
62
  function settlesDecision(o) {
30
- return SETTLING.has(o.reason) && (o.reason !== "card_unresumable" || o.terminal === true) && (o.reason !== "denied" || o.explicit === true);
63
+ if (!Object.hasOwn(WORKFLOW_PARK_UNUSED_REASON_CLASS, o.reason))
64
+ return false;
65
+ const row = WORKFLOW_PARK_UNUSED_REASON_CLASS[o.reason];
66
+ return row.spent !== undefined && (row.kept === undefined || o[row.spentWhen] === true);
31
67
  }
68
+ const UNUSED_REASONS = new Set(WORKFLOW_PARK_UNUSED_REASONS);
32
69
  function parkEntriesOn(token, records) {
33
70
  const out = [];
34
71
  for (const r of records) {
35
- if (r === null || r === undefined || !Array.isArray(r.parks))
72
+ if (!Array.isArray(r.parks))
36
73
  continue;
37
74
  for (const entry of r.parks)
38
75
  if (isObject(entry) && entry.token === token)
@@ -40,26 +77,56 @@ function parkEntriesOn(token, records) {
40
77
  }
41
78
  return out;
42
79
  }
43
- function settledMarkOf(token, decisionId, records) {
80
+ function holderEntriesOn(token, records) {
81
+ const holder = parkHolderAmong(token, records);
82
+ const ids = holder.kind === "held" ? [holder.runId] : holder.kind === "fork" ? holder.runIds : [];
83
+ return parkEntriesOn(token, records).filter(({ runId, entry }) => ids.includes(runId) && entry.parkedBy === runId);
84
+ }
85
+ function markKindOf(m) {
86
+ if (!isObject(m) || typeof m.decisionId !== "string" || typeof m.reason !== "string")
87
+ return undefined;
88
+ if (m.condition === undefined)
89
+ return SETTLING.has(m.reason) ? "final" : undefined;
90
+ return typeof m.condition === "string" && m.condition !== "" && UNUSED_REASONS.has(m.reason) ? "recoverable" : undefined;
91
+ }
92
+ function holderMarkOf(token, decisionId, records) {
44
93
  for (const { runId, entry } of parkEntriesOn(token, records)) {
45
- if (!Array.isArray(entry.settledDecisions))
94
+ const m = Array.isArray(entry.settledDecisions) ? entry.settledDecisions.find((s) => markKindOf(s) === "final" && s.decisionId === decisionId) : undefined;
95
+ if (m !== undefined)
96
+ return { kind: "spent", runId, reason: m.reason, ...(typeof m.code === "string" ? { code: m.code } : {}), by: "mark" };
97
+ }
98
+ for (const { runId, entry } of holderEntriesOn(token, records)) {
99
+ const m = Array.isArray(entry.settledDecisions) ? entry.settledDecisions.find((s) => markKindOf(s) === "recoverable" && s.decisionId === decisionId) : undefined;
100
+ if (m === undefined)
46
101
  continue;
47
- for (const m of entry.settledDecisions) {
48
- if (!isObject(m) || m.decisionId !== decisionId || typeof m.reason !== "string" || !SETTLING.has(m.reason))
49
- continue;
50
- return { kind: "spent", runId, reason: m.reason, ...(typeof m.code === "string" ? { code: m.code } : {}) };
51
- }
102
+ const inputs = Array.isArray(m.inputs) ? m.inputs.filter((k) => HOST_FOLD_INPUTS.includes(k)) : [];
103
+ return { kind: "blocked", runId, reason: m.reason, ...(typeof m.code === "string" ? { code: m.code } : {}), ...(inputs.length > 0 ? { inputs } : {}), condition: m.condition };
52
104
  }
53
105
  return undefined;
54
106
  }
55
- export function workflowParkDecisionOf(token, decisionId, records) {
107
+ export function workflowParkDecisionOf(token, decisionId, tree, card) {
108
+ if (card !== undefined && !PARK_CARD_STATES.has(card))
109
+ throw new TypeError(`workflowParkDecisionOf: card (${typeof card === "string" ? JSON.stringify(card) : `a ${typeof card}`}) is not one of ${[...PARK_CARD_STATES].join("/")}`);
110
+ const state = decisionStateOf(token, decisionId, tree);
111
+ if (card === undefined || card === "pending")
112
+ return state;
113
+ if (card !== "unread")
114
+ return { ...state, class: "withdraw" };
115
+ if (!("class" in state))
116
+ return state;
117
+ const { class: _class, ...rest } = state;
118
+ return rest;
119
+ }
120
+ const PARK_CARD_STATES = new Set(["pending", "resolved", "expired", "absent", "unread"]);
121
+ function decisionStateOf(token, decisionId, tree) {
122
+ const records = tree.records;
56
123
  const callKeys = new Set(parkEntriesOn(token, records).map(({ entry }) => entry.callKey).filter((k) => typeof k === "string"));
57
124
  let driven;
58
125
  let refused;
59
126
  let carried;
60
127
  for (const r of records) {
61
- const rows = r?.resume?.decisions;
62
- if (r === null || r === undefined || !Array.isArray(rows))
128
+ const rows = r.decisions;
129
+ if (!Array.isArray(rows))
63
130
  continue;
64
131
  for (const d of rows) {
65
132
  if (!isObject(d) || d.decisionId !== decisionId || typeof d.callKey !== "string" || !callKeys.has(d.callKey))
@@ -67,16 +134,50 @@ export function workflowParkDecisionOf(token, decisionId, records) {
67
134
  if (d.result === "driven")
68
135
  driven ??= { kind: "driven", runId: r.id };
69
136
  else if (d.result === "refused")
70
- refused ??= { kind: "spent", runId: r.id, reason: "decision_spent", ...(typeof d.code === "string" ? { code: d.code } : {}) };
137
+ refused ??= { kind: "spent", runId: r.id, reason: "decision_spent", ...(typeof d.code === "string" ? { code: d.code } : {}), by: "drive" };
71
138
  else if (d.result === "not_reached")
72
139
  carried ??= { kind: "carried", runId: r.id };
73
140
  }
74
141
  }
75
- return driven ?? settledMarkOf(token, decisionId, records) ?? refused ?? carried ?? { kind: "open" };
142
+ const mark = holderMarkOf(token, decisionId, records);
143
+ return classed(driven ?? (mark?.kind === "spent" ? mark : undefined) ?? refused ?? carried ?? (mark?.kind === "blocked" ? mark : undefined) ?? { kind: "open" });
144
+ }
145
+ function classed(state) {
146
+ if (state.kind !== "spent" && state.kind !== "blocked")
147
+ return state;
148
+ const c = workflowParkUnusedClassOf(state.reason, state.kind === "spent");
149
+ return c === undefined ? state : { ...state, class: c };
150
+ }
151
+ export function claimRemainingOf(answer, now) {
152
+ let remaining;
153
+ try {
154
+ remaining = answer.remainingMs;
155
+ }
156
+ catch {
157
+ return { kind: "unreadable" };
158
+ }
159
+ if (remaining === undefined)
160
+ return { kind: "unsaid" };
161
+ if (typeof remaining !== "number" || !Number.isSafeInteger(remaining) || remaining < 1 || remaining > RESUME_CLAIM_REMAINING_MS_MAX)
162
+ return { kind: "unreadable" };
163
+ const at = now + remaining;
164
+ return claimLapseInstant(at) === undefined ? { kind: "unreadable" } : { kind: "at", at };
165
+ }
166
+ const ANSWER_RECORD_CLAIM_HOLDER_PREFIX = "answer-record:";
167
+ export function answerRecordClaimHolder() {
168
+ return `${ANSWER_RECORD_CLAIM_HOLDER_PREFIX}${randomUUID()}`;
169
+ }
170
+ export function isAnswerRecordClaimHolder(holder) {
171
+ return holder !== undefined && holder.startsWith(ANSWER_RECORD_CLAIM_HOLDER_PREFIX);
76
172
  }
77
173
  export function claimHeldOf(verdict) {
78
- return { ...(verdict.holder !== undefined ? { holder: verdict.holder } : {}), ...(verdict.expiresAt !== undefined ? { claimExpiresAt: verdict.expiresAt } : {}) };
174
+ const lapse = verdict.lapse;
175
+ return {
176
+ ...(isAnswerRecordClaimHolder(verdict.holder) ? { heldForAnswer: true } : verdict.holder !== undefined ? { holder: verdict.holder } : {}),
177
+ ...(lapse?.kind === "at" ? { claimExpiresAt: lapse.at } : lapse?.kind === "unreadable" ? { claimLapseUnreadable: true } : {}),
178
+ };
79
179
  }
180
+ export const CLAIM_REMAINING_UNREADABLE_NOTE = "the journal store answered a remaining time for the claim that does not read, so no time is named";
80
181
  export function claimLapseInstant(expiresAt) {
81
182
  if (typeof expiresAt !== "number" || !Number.isFinite(expiresAt))
82
183
  return undefined;
@@ -142,84 +243,142 @@ export async function readWorkflowRunIn(store, id, scope, within) {
142
243
  return "unreadable";
143
244
  return got.value !== null && got.value.scope === scope ? got.value : null;
144
245
  }
145
- export async function workflowRunSuccessors(store, rootId, scope, within) {
246
+ export function isContinuationOf(a, b) {
247
+ if (resumedFromOf(b) !== a.id)
248
+ return false;
249
+ const named = b.resume?.fromCreationId;
250
+ return typeof named !== "string" || workflowRunCreationIdOf(a) === named;
251
+ }
252
+ const WORKFLOW_RUN_TREE = Symbol("WorkflowRunTree");
253
+ const mintTree = (root, records) => ({ root, records, [WORKFLOW_RUN_TREE]: true });
254
+ export function workflowRunTreeOfOne(run) {
255
+ return mintTree(run, [run]);
256
+ }
257
+ export function workflowRunInTree(tree, id) {
258
+ return tree.records.find((r) => r.id === id);
259
+ }
260
+ export function workflowRunsBelow(tree, id) {
261
+ const below = new Set([id]);
146
262
  const out = [];
147
- const seen = new Set([rootId]);
148
- let frontier = [rootId];
263
+ for (const r of tree.records) {
264
+ if (r === tree.root)
265
+ continue;
266
+ const up = resumedFromOf(r);
267
+ if (up !== undefined && below.has(up) && !below.has(r.id)) {
268
+ below.add(r.id);
269
+ out.push(r);
270
+ }
271
+ }
272
+ return out;
273
+ }
274
+ export function workflowRunChildrenIn(tree, id) {
275
+ return tree.records.filter((r) => r !== tree.root && resumedFromOf(r) === id);
276
+ }
277
+ export function workflowRunLineIn(tree, id) {
278
+ const line = [];
279
+ const byId = new Map(tree.records.map((r) => [r.id, r]));
280
+ let at = byId.get(id);
281
+ while (at !== undefined && line.length < tree.records.length) {
282
+ line.push(at.id);
283
+ if (at === tree.root)
284
+ break;
285
+ at = byId.get(resumedFromOf(at) ?? "");
286
+ }
287
+ return line;
288
+ }
289
+ export function workflowLineTailOf(tree, runId) {
290
+ let at = runId;
291
+ for (let n = 0; n <= tree.records.length; n++) {
292
+ const next = workflowRunChildrenIn(tree, at);
293
+ if (next.length === 0)
294
+ return { kind: "tail", runId: at };
295
+ if (next.length > 1) {
296
+ const below = workflowRunsBelow(tree, runId);
297
+ return { kind: "fork", leaves: below.filter((r) => workflowRunChildrenIn(tree, r.id).length === 0).map((r) => r.id) };
298
+ }
299
+ at = next[0].id;
300
+ }
301
+ return { kind: "tail", runId: at };
302
+ }
303
+ const FORK_LEAVES_NAMED_MAX = 4;
304
+ export function workflowLineForkReason(leaves) {
305
+ const shown = leaves.slice(0, FORK_LEAVES_NAMED_MAX).map((l) => `"${l}"`);
306
+ return `that run was already continued, and the runs that continued it split into ${leaves.length} lines, so which one to continue is not one answer. The last run of each line is ${shown.join(", ")}${leaves.length > shown.length ? `, and ${leaves.length - shown.length} more` : ""}: resume from the one you mean (resumeFromRunId set to it), or start the workflow again`;
307
+ }
308
+ export function readWorkflowRunTree(store, runId, scope) {
309
+ return readWorkflowRunTreeWithin(store, runId, scope, boundedStoreRead(WORKFLOW_STORE_WAIT_BOUND_MS));
310
+ }
311
+ export async function readWorkflowRunTreeWithin(store, runId, scope, within, self) {
312
+ const read = (id) => (self !== undefined && id === self.id ? Promise.resolve(self) : readWorkflowRunIn(store, id, scope, within));
313
+ const line = [];
314
+ let at = await read(runId);
315
+ if (at === "unreadable" || at === null)
316
+ return "unreadable";
317
+ for (;;) {
318
+ line.push(at);
319
+ const up = resumedFromOf(at);
320
+ if (up === undefined)
321
+ break;
322
+ if (line.some((r) => r.id === up))
323
+ return "unreadable";
324
+ const source = await read(up);
325
+ if (source === "unreadable")
326
+ return "unreadable";
327
+ if (source === null || !isContinuationOf(source, at))
328
+ break;
329
+ if (line.length >= WORKFLOW_TREE_RUNS_MAX)
330
+ return "over_bound";
331
+ at = source;
332
+ }
333
+ const root = line[line.length - 1];
334
+ const records = [root];
335
+ const seen = new Set([root.id]);
336
+ let frontier = [root];
149
337
  while (frontier.length > 0) {
150
338
  const next = [];
151
- for (const id of frontier) {
152
- const listed = await within(Promise.resolve().then(() => store.listByScope(scope, { resumedFrom: id })));
339
+ for (const parent of frontier) {
340
+ const listed = await within(Promise.resolve().then(() => store.listByScope(scope, { resumedFrom: parent.id })));
153
341
  if (!listed.ok)
154
342
  return "unreadable";
343
+ const ids = [];
155
344
  for (const s of listed.value) {
156
- if ("rowVerdict" in s || s.resumedFrom !== id)
157
- continue;
158
- const r = await readWorkflowRunIn(store, s.id, scope, within);
345
+ if ("rowVerdict" in s)
346
+ return "unreadable";
347
+ if (s.resumedFrom === parent.id)
348
+ ids.push(s.id);
349
+ }
350
+ if (self !== undefined && self.id !== root.id && resumedFromOf(self) === parent.id && !ids.includes(self.id))
351
+ ids.push(self.id);
352
+ for (const id of ids) {
353
+ const r = await read(id);
159
354
  if (r === "unreadable")
160
355
  return "unreadable";
161
- if (r === null || r.resume?.fromRunId !== id)
356
+ if (r === null || !isContinuationOf(parent, r))
162
357
  continue;
163
358
  if (seen.has(r.id))
164
- continue;
359
+ return "unreadable";
165
360
  seen.add(r.id);
166
- out.push(r);
167
- next.push(r.id);
168
- if (seen.size > WORKFLOW_TREE_RUNS_MAX)
361
+ records.push(r);
362
+ next.push(r);
363
+ if (records.length > WORKFLOW_TREE_RUNS_MAX)
169
364
  return "over_bound";
170
365
  }
171
366
  }
172
367
  frontier = next;
173
368
  }
174
- return out;
175
- }
176
- export async function readWorkflowRunChain(store, rootId, scope, within) {
177
- const root = await readWorkflowRunIn(store, rootId, scope, within);
178
- if (root === "unreadable" || root === null)
179
- return "unreadable";
180
- const successors = await workflowRunSuccessors(store, rootId, scope, within);
181
- return typeof successors === "string" ? successors : { root, successors };
182
- }
183
- export async function workflowTreeOf(store, runId, scope, within) {
184
- const walked = await workflowLineOf(store, runId, scope, within);
185
- return typeof walked === "string" ? walked : { root: walked.root, line: walked.line, recorded: walked.recorded };
186
- }
187
- async function workflowLineOf(store, runId, scope, within) {
188
- const line = [];
189
- const records = [];
190
- const seen = new Set();
191
- let id = runId;
192
- for (;;) {
193
- const r = await readWorkflowRunIn(store, id, scope, within);
194
- if (r === "unreadable")
195
- return "unreadable";
196
- if (r === null)
197
- return line.length === 0 ? { root: runId, line: [runId], recorded: false, records } : { root: line[line.length - 1], line, recorded: true, records };
198
- if (line.length >= WORKFLOW_TREE_RUNS_MAX)
199
- return "over_bound";
200
- line.push(id);
201
- records.push(r);
202
- seen.add(id);
203
- const up = r.resume?.fromRunId;
204
- if (up === undefined)
205
- return { root: id, line, recorded: true, records };
206
- if (seen.has(up))
369
+ for (const r of line) {
370
+ if (r === self)
371
+ continue;
372
+ const down = records.find((d) => d.id === r.id);
373
+ if (down === undefined || workflowRunCreationIdOf(down) !== workflowRunCreationIdOf(r))
207
374
  return "unreadable";
208
- id = up;
209
375
  }
376
+ return mintTree(root, records);
210
377
  }
211
- export async function otherWaitingLine(store, parkStore, fromRunId, scope, within, walked) {
212
- const tree = walked ?? (await workflowTreeOf(store, fromRunId, scope, within));
213
- if (typeof tree === "string")
214
- return { kind: tree };
215
- if (!tree.recorded)
216
- return { kind: "none", root: tree.root };
217
- const chain = await readWorkflowRunChain(store, tree.root, scope, within);
218
- if (typeof chain === "string")
219
- return { kind: chain };
220
- const records = [chain.root, ...chain.successors];
221
- const onLine = new Set(tree.line);
222
- const parentOf = new Map(records.map((r) => [r.id, r.resume?.fromRunId]));
378
+ export async function otherWaitingLine(tree, parkStore, fromRunId, within) {
379
+ const records = tree.records;
380
+ const onLine = new Set(workflowRunLineIn(tree, fromRunId));
381
+ const parentOf = new Map(records.map((r) => [r.id, r === tree.root ? undefined : resumedFromOf(r)]));
223
382
  const below = (id, top) => {
224
383
  for (let up = parentOf.get(id), n = 0; up !== undefined && n <= records.length; up = parentOf.get(up), n++)
225
384
  if (up === top)
@@ -233,20 +392,21 @@ export async function otherWaitingLine(store, parkStore, fromRunId, scope, withi
233
392
  for (const p of [...(r.parks ?? [])].sort((a, b) => own(a.token) - own(b.token))) {
234
393
  if (p.parkedBy !== r.id)
235
394
  continue;
236
- const holder = workflowParkHolderOf(p.token, records);
395
+ const holder = workflowParkHolderOf(p.token, tree);
237
396
  const counts = (holder.kind === "held" && holder.runId === r.id) || (holder.kind === "fork" && holder.runIds.includes(r.id) && (onLine.has(r.id) || !holder.runIds.some((id) => onLine.has(id))));
238
397
  if (!counts)
239
398
  continue;
240
399
  if (parkStore === undefined)
241
400
  return "unreadable";
242
- const read = await within(Promise.resolve().then(() => parkStore.get(p.token)));
243
- if (!read.ok)
401
+ const read = await within(Promise.resolve().then(() => parkStore.get(p.token)).then((row) => ({ row, state: parkCardStateOf(row, p.token) })));
402
+ if (!read.ok || read.value.state === "unread")
244
403
  return "unreadable";
245
- if (read.value === null || read.value.status !== "pending")
404
+ if (read.value.state !== "pending")
246
405
  continue;
406
+ const row = read.value.row;
247
407
  const label = r.agents.find((a) => a.parkedCheckpointToken === p.token)?.label;
248
- const checkpointId = read.value.checkpointId;
249
- return { runId: r.id, ...(label !== undefined ? { label } : {}), ...(typeof checkpointId === "string" ? { checkpointId } : {}), ...(read.value.gate.kind === "resource_limit" ? { yielded: true } : {}) };
408
+ const checkpointId = row.checkpointId;
409
+ return { runId: r.id, ...(label !== undefined ? { label } : {}), ...(typeof checkpointId === "string" ? { checkpointId } : {}), ...(row.gate.kind === "resource_limit" ? { yielded: true } : {}) };
250
410
  }
251
411
  return undefined;
252
412
  };
@@ -265,12 +425,71 @@ export async function otherWaitingLine(store, parkStore, fromRunId, scope, withi
265
425
  holding.push(w);
266
426
  }
267
427
  const heads = holding.filter((h) => !holding.some((o) => o !== h && below(o.runId, h.runId)));
268
- return heads.length === 0 ? { kind: "none", root: tree.root } : { kind: "waiting", root: tree.root, lines: heads };
428
+ return heads.length === 0 ? { kind: "none", root: tree.root.id } : { kind: "waiting", root: tree.root.id, lines: heads };
269
429
  }
270
- export function runThatDrove(records, callKey) {
271
- return records.find((r) => r.resume?.decisions?.some((d) => d.callKey === callKey && d.result === "driven") === true);
430
+ export function runThatDrove(records, token, callKey) {
431
+ return records.find((r) => (r.parks ?? []).some((p) => isObject(p) && p.token === token) && r.decisions?.some((d) => d.callKey === callKey && d.result === "driven") === true);
432
+ }
433
+ export function workflowParkWaitOf(token, runId, tree, card) {
434
+ const present = tree.records;
435
+ const own = present.find((r) => r.id === runId);
436
+ const entry = own?.parks?.find((p) => isObject(p) && p.token === token && p.parkedBy === runId);
437
+ if (own === undefined || entry === undefined)
438
+ return { kind: "unknown", why: "chain_incomplete" };
439
+ const drove = runThatDrove(present.filter((r) => r.id !== runId), token, entry.callKey);
440
+ if (drove !== undefined)
441
+ return { kind: "moved_on", runIds: [drove.id] };
442
+ const holder = workflowParkHolderOf(token, tree);
443
+ if (holder.kind === "held" && holder.runId !== runId)
444
+ return { kind: "moved_on", runIds: [holder.runId] };
445
+ if (holder.kind === "fork" && !holder.runIds.includes(runId))
446
+ return { kind: "moved_on", runIds: holder.runIds };
447
+ if (holder.kind === "none")
448
+ return { kind: "unknown", why: "chain_incomplete" };
449
+ if (card === "unread")
450
+ return { kind: "unknown", why: "card_unread" };
451
+ if (card !== "pending")
452
+ return { kind: "lapsed", card };
453
+ let top = -1;
454
+ let again = [];
455
+ for (const r of workflowRunsBelow(tree, runId)) {
456
+ for (const p of r.parks ?? []) {
457
+ if (!isObject(p) || p.callKey !== entry.callKey || p.token === token || p.parkedBy !== r.id || !Number.isSafeInteger(p.generation))
458
+ continue;
459
+ const g = p.generation;
460
+ if (g > top)
461
+ (top = g), (again = [r.id]);
462
+ else if (g === top && !again.includes(r.id))
463
+ again.push(r.id);
464
+ }
465
+ }
466
+ return again.length > 0 ? { kind: "moved_on", runIds: again.sort() } : { kind: "waiting" };
467
+ }
468
+ export async function readWorkflowParkWaits(seats, runId, scope) {
469
+ const within = boundedStoreRead(WORKFLOW_STORE_WAIT_BOUND_MS);
470
+ const tree = await readWorkflowRunTreeWithin(seats.runStore, runId, scope, within);
471
+ if (typeof tree === "string")
472
+ return tree;
473
+ const own = workflowRunInTree(tree, runId);
474
+ const tokens = [...new Set((own.parks ?? []).filter((p) => isObject(p) && p.parkedBy === runId && typeof p.token === "string").map((p) => p.token))];
475
+ const cardOf = async (token) => {
476
+ const read = await within(Promise.resolve()
477
+ .then(() => seats.checkpointStore.get(token))
478
+ .then((row) => ((s) => (s === "status_unknown" ? "unread" : s))(parkCardStateOf(row, token))));
479
+ return read.ok ? read.value : "unread";
480
+ };
481
+ const cards = await Promise.all(tokens.map(cardOf));
482
+ return new Map(tokens.map((token, i) => [token, workflowParkWaitOf(token, runId, tree, cards[i])]));
272
483
  }
273
484
  const isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
485
+ function parkCardStateOf(row, token) {
486
+ if (row === null)
487
+ return "absent";
488
+ if (row.token !== token)
489
+ return "unread";
490
+ const status = row.status;
491
+ return status === "pending" || status === "resolved" || status === "expired" ? status : "status_unknown";
492
+ }
274
493
  const decisionOf = (entry) => ({ token: entry.token, outcome: entry.outcome, decisionId: entry.decisionId, ...(entry.inheritedGate !== undefined ? { inheritedGate: entry.inheritedGate } : {}) });
275
494
  function readDecisions(raw) {
276
495
  const usable = [];
@@ -289,278 +508,391 @@ function readDecisions(raw) {
289
508
  return { usable, unreadable };
290
509
  }
291
510
  const SETTLE_ATTEMPTS = 3;
511
+ export function conditionOf(o) {
512
+ const holder = holderDetailOf(o).holder;
513
+ const said = [o.reason, o.code ?? null, o.changed ?? null, o.inputs ?? null, holder === undefined ? null : typeof holder === "string" ? holder : [...holder].sort(), o.why ?? null, o.rowReason ?? null, o.terminal === true, ...(o.heldForAnswer === true ? ["held_for_answer"] : [])];
514
+ return createHash("sha256").update(JSON.stringify(said)).digest("hex").slice(0, 32);
515
+ }
516
+ function placeMark(kept, m) {
517
+ const mark = { decisionId: m.decisionId, reason: m.reason, ...(m.code !== undefined ? { code: m.code } : {}), ...(m.inputs !== undefined && m.inputs.length > 0 ? { inputs: [...m.inputs] } : {}), ...(m.condition !== undefined ? { condition: m.condition } : {}) };
518
+ if (new TextEncoder().encode(JSON.stringify(mark)).length > WORKFLOW_PARK_DECISION_MARK_BYTES_MAX)
519
+ return "skipped";
520
+ const ofThis = (s) => s.decisionId === m.decisionId;
521
+ if (kept.some((s) => ofThis(s) && markKindOf(s) === "final"))
522
+ return "recorded";
523
+ const was = kept.findIndex((s) => ofThis(s) && markKindOf(s) === "recoverable");
524
+ if (was >= 0 && m.condition !== undefined && kept[was].condition === m.condition)
525
+ return "recorded";
526
+ const without = (at) => [...kept.slice(0, at), ...kept.slice(at + 1)];
527
+ if (was >= 0)
528
+ return [...without(was), mark];
529
+ if (kept.length < WORKFLOW_PARK_SETTLED_DECISIONS_MAX)
530
+ return [...kept, mark];
531
+ const oldest = m.condition === undefined ? kept.findIndex((s) => markKindOf(s) === "recoverable") : -1;
532
+ return oldest < 0 ? "skipped" : [...without(oldest), mark];
533
+ }
292
534
  export function createWorkflowParkAdopter(seats) {
293
535
  const within = boundedStoreRead(seats.waitBoundMs);
294
536
  const readRun = async (id, scope) => (seats.store === undefined ? "unreadable" : readWorkflowRunIn(seats.store, id, scope, within));
295
- const successorsOf = async (x, scope) => (seats.store === undefined ? "unreadable" : workflowRunSuccessors(seats.store, x.id, scope, within));
296
- const settleOn = async (held, scope, all) => {
537
+ const readTree = async (id, scope) => (seats.store === undefined ? "unreadable" : readWorkflowRunTreeWithin(seats.store, id, scope, within));
538
+ const settleOn = async (tree, scope, all, named) => {
297
539
  const others = new Set();
298
540
  const store = seats.store;
299
541
  if (store === undefined)
300
542
  return others;
543
+ let marks = all.filter((m, i) => all.findIndex((o) => o.token === m.token && o.decisionId === m.decisionId) === i);
544
+ let judged = tree;
545
+ for (let judgment = 0; judgment < 2 && marks.length > 0; judgment++) {
546
+ const byHolder = new Map();
547
+ for (const m of marks) {
548
+ const holder = workflowParkHolderOf(m.token, judged);
549
+ const home = holder.kind === "held" ? holder.runId : holder.kind === "fork" && holder.runIds.includes(named) ? named : undefined;
550
+ if (home !== undefined)
551
+ byHolder.set(home, [...(byHolder.get(home) ?? []), m]);
552
+ }
553
+ const moved = [];
554
+ for (const [holderId, ofHolder] of byHolder) {
555
+ const record = workflowRunInTree(judged, holderId);
556
+ if (record !== undefined)
557
+ moved.push(...(await settleOnHolder(store, record, scope, ofHolder, others)));
558
+ }
559
+ if (moved.length === 0 || judgment === 1)
560
+ break;
561
+ const again = await readTree(tree.root.id, scope);
562
+ if (typeof again === "string")
563
+ break;
564
+ judged = again;
565
+ marks = moved;
566
+ }
567
+ return others;
568
+ };
569
+ const settleOnHolder = async (store, held, scope, marks, others) => {
301
570
  const runId = held.id;
302
- const marks = all.filter((m, i) => all.findIndex((o) => o.token === m.token && o.decisionId === m.decisionId) === i);
303
571
  let mineMayHaveLanded = false;
572
+ const creationId = workflowRunCreationIdOf(held);
304
573
  for (let attempt = 0; attempt < SETTLE_ATTEMPTS; attempt++) {
305
- const now = attempt === 0 ? held : await readRun(runId, scope);
306
- if (now === "unreadable" || now === null || now.status === "running")
307
- return others;
574
+ const now = await readRun(runId, scope);
575
+ if (now === "unreadable" || now === null || now.status === "running" || workflowRunCreationIdOf(now) !== creationId)
576
+ return [];
308
577
  const next = structuredClone(now);
309
578
  let added = false;
579
+ const moved = [];
310
580
  for (const m of marks) {
311
581
  const entry = next.parks?.find((p) => isObject(p) && p.token === m.token && p.parkedBy === runId);
312
582
  if (entry === undefined)
313
583
  continue;
314
- const kept = Array.isArray(entry.settledDecisions) ? entry.settledDecisions.filter((s) => isObject(s)) : [];
315
- if (settledMarkOf(m.token, m.decisionId, [{ id: runId, parks: [{ ...entry, settledDecisions: kept }] }]) !== undefined) {
584
+ if (entry.passedTo !== undefined) {
585
+ moved.push(m);
586
+ continue;
587
+ }
588
+ const placed = placeMark(Array.isArray(entry.settledDecisions) ? entry.settledDecisions.filter((s) => isObject(s)) : [], m);
589
+ if (placed === "recorded") {
316
590
  if (!mineMayHaveLanded)
317
591
  others.add(m.decisionId);
318
592
  continue;
319
593
  }
320
- if (kept.length >= WORKFLOW_PARK_SETTLED_DECISIONS_MAX)
594
+ if (placed === "skipped")
321
595
  continue;
322
- entry.settledDecisions = [...kept, { decisionId: m.decisionId, reason: m.reason, ...(m.code !== undefined ? { code: m.code } : {}) }];
596
+ entry.settledDecisions = placed;
323
597
  added = true;
324
598
  }
325
599
  if (!added)
326
- return others;
327
- const won = await within(Promise.resolve().then(() => store.update(runId, scope, next, { rev: now.rev ?? 0 }, { cause: "park_decision_settled" })));
600
+ return moved;
601
+ const won = await within(Promise.resolve().then(() => store.update(runId, scope, next, { rev: now.rev ?? 0, creationId }, { cause: "park_decision_settled" })));
328
602
  if (won.ok && won.value)
329
- return others;
603
+ return moved;
330
604
  if (!won.ok)
331
605
  mineMayHaveLanded = true;
332
606
  }
333
- return others;
607
+ return [];
334
608
  };
335
609
  const cardOf = async (parkStore, token) => {
336
610
  if (parkStore === undefined)
337
- return { kind: "unread" };
338
- const read = await within(Promise.resolve().then(() => parkStore.get(token)));
611
+ return { state: "unread" };
612
+ const read = await within(Promise.resolve().then(() => parkStore.get(token)).then((row) => ({ row, state: parkCardStateOf(row, token) })));
339
613
  if (!read.ok)
340
- return { kind: "unread" };
341
- return read.value === null || read.value.status !== "pending" ? { kind: "gone" } : { kind: "pending", row: read.value };
614
+ return { state: "unread" };
615
+ return read.value.state === "pending" ? { state: "pending", row: read.value.row } : { state: read.value.state };
342
616
  };
343
- const judgeCards = async (x, records, parkStore, entries, unused, settle, quiet) => {
617
+ const judgeCards = async (x, tree, parkStore, entries, settle, quiet) => {
618
+ const records = tree.records;
344
619
  const carried = [];
345
- let first;
620
+ const own = [];
621
+ const ownOf = (entry, reason, more = {}) => void own.push({ kind: "unused", runId: x.id, decisionIds: [entry.decisionId], reason, ...more });
346
622
  let unresumable;
347
623
  for (const entry of entries) {
348
624
  const card = await cardOf(parkStore, entry.token);
349
- if (card.kind === "unread") {
350
- first ??= unused("record_unreadable");
625
+ const was = workflowParkDecisionOf(entry.token, entry.decisionId, tree, card.state === "status_unknown" ? "unread" : card.state);
626
+ if (was.kind === "spent" && was.by === "mark")
627
+ quiet.add(entry.decisionId);
628
+ if (card.state === "unread") {
629
+ ownOf(entry, "record_unreadable", { cardUnread: true });
351
630
  continue;
352
631
  }
353
632
  const key = x.parks?.find((p) => p.token === entry.token);
354
- if (card.kind === "gone") {
355
- const continuedAs = key === undefined ? undefined : runThatDrove(records, key.callKey)?.id;
356
- first ??= unused("not_pending", continuedAs !== undefined ? { continuedAs } : {});
633
+ if (card.state !== "pending") {
634
+ const continuedAs = key === undefined ? undefined : runThatDrove(records, entry.token, key.callKey)?.id;
635
+ ownOf(entry, "not_pending", continuedAs !== undefined ? { continuedAs } : {});
357
636
  continue;
358
637
  }
359
- const holder = workflowParkHolderOf(entry.token, records);
360
- if (holder.kind !== "held" || holder.runId !== x.id) {
361
- first ??= unused("not_holder", holder.kind === "held" ? { holder: holder.runId } : holder.kind === "fork" ? { holder: holder.runIds } : {});
638
+ const holder = workflowParkHolderOf(entry.token, tree);
639
+ if (holder.kind === "held" ? holder.runId !== x.id : holder.kind === "fork" ? !holder.runIds.includes(x.id) : true) {
640
+ ownOf(entry, "not_holder", holder.kind === "held" ? { holder: holder.runId } : holder.kind === "fork" ? { holder: holder.runIds } : {});
362
641
  continue;
363
642
  }
364
643
  const row = judgeCheckpointRow(card.row);
365
644
  if (row.kind !== "ok") {
366
- unresumable ??= unused("card_unresumable", { code: row.code, ...(row.reason !== undefined ? { rowReason: row.reason } : {}), rowSentence: row.sentence, ...(row.terminal === true ? { terminal: true } : {}) });
367
- first ??= unresumable;
645
+ const facts = { code: row.code, ...(row.reason !== undefined ? { rowReason: row.reason } : {}), rowSentence: row.sentence };
646
+ unresumable ??= facts;
647
+ ownOf(entry, "card_unresumable", { ...facts, ...(row.terminal === true ? { terminal: true } : {}) });
368
648
  if (row.terminal === true)
369
649
  settle(entry, "card_unresumable", row.code);
370
650
  continue;
371
651
  }
372
- const was = workflowParkDecisionOf(entry.token, entry.decisionId, records);
373
652
  if (was.kind === "spent") {
374
- if (was.reason !== "decision_spent" || quiet.has(entry.decisionId))
375
- quiet.add(entry.decisionId);
376
- else {
377
- first ??= unused("decision_spent", was.code !== undefined ? { code: was.code } : {});
378
- settle(entry, "decision_spent", was.code);
379
- }
653
+ if (quiet.has(entry.decisionId))
654
+ continue;
655
+ ownOf(entry, "decision_spent", was.code !== undefined ? { code: was.code } : {});
656
+ settle(entry, "decision_spent", was.code);
380
657
  continue;
381
658
  }
382
659
  carried.push({ entry, state: card.row.state });
383
660
  }
384
- return { carried, ...(first !== undefined ? { first } : {}), ...(unresumable !== undefined ? { unresumable } : {}) };
661
+ return { carried, own, ...(unresumable !== undefined ? { unresumable } : {}) };
385
662
  };
386
- const adoptOne = async (runId, entries, leg, quiet, approvedCall) => {
387
- const unused = (reason, more = {}) => ({ kind: "unused", runId, decisionIds: entries.map((e) => e.decisionId), reason, ...more });
663
+ const adoptOne = async (runId, entries, leg, quiet, asides, approvedCall) => {
664
+ const own = [];
388
665
  const toolCallId = leg.mintCallId();
389
666
  const ctx = leg.ctxOf(toolCallId);
390
667
  const scope = seats.scopeOf(ctx);
391
- const x = await readRun(runId, scope);
668
+ const tree = await readTree(runId, scope);
669
+ const x = typeof tree === "string" ? tree : workflowRunInTree(tree, runId);
392
670
  const parkStore = seats.parkStoreOf(ctx);
393
671
  const cardsFirst = async (reason) => {
394
- let first;
395
- const waiting = [];
396
672
  for (const entry of entries) {
397
673
  const card = await cardOf(parkStore, entry.token);
398
- if (card.kind === "pending")
399
- waiting.push(entry.decisionId);
400
- else
401
- first ??= unused(card.kind === "gone" ? "not_pending" : "record_unreadable");
674
+ own.push({ kind: "unused", runId, decisionIds: [entry.decisionId], ...(card.state === "pending" ? { reason } : card.state === "unread" ? { reason: "record_unreadable", cardUnread: true } : { reason: "not_pending" }) });
402
675
  }
403
- return waiting.length > 0 ? { kind: "unused", runId, decisionIds: waiting, reason } : (first ?? unused(reason));
676
+ for (const o of groupedByAnswer(own))
677
+ asides.push(o);
678
+ return "settled_before";
404
679
  };
405
- if (x === "unreadable" || x === null || x.resumeAdmissionIncomplete === true)
680
+ if (typeof tree === "string" || typeof x === "string" || x.resumeAdmissionIncomplete === true)
406
681
  return cardsFirst("record_unreadable");
407
- if (approvedCall === undefined)
408
- for (const e of entries)
409
- if (settledMarkOf(e.token, e.decisionId, [x]) !== undefined)
410
- quiet.add(e.decisionId);
411
- if (entries.every((e) => quiet.has(e.decisionId)))
412
- return "settled_before";
413
682
  if (x.status === "running")
414
683
  return cardsFirst("run_not_ended");
415
- const successors = await successorsOf(x, scope);
416
- if (typeof successors === "string")
417
- return cardsFirst("record_unreadable");
418
- const records = [x, ...successors];
419
684
  const settling = [];
420
685
  const settle = (entry, reason, code) => {
421
686
  if (approvedCall === undefined && !quiet.has(entry.decisionId))
422
687
  settling.push({ token: entry.token, decisionId: entry.decisionId, reason, ...(code !== undefined ? { code } : {}) });
423
688
  };
689
+ let judgedTree = tree;
424
690
  const told = async (o) => {
425
- if (o.kind !== "unused" || !settlesDecision(o))
691
+ if (o.kind !== "unused" || approvedCall !== undefined)
426
692
  return o;
427
- const marks = settling.filter((m) => m.reason === o.reason && m.code === o.code && o.decisionIds.includes(m.decisionId));
693
+ if (settlesDecision(o)) {
694
+ const marks = settling.filter((m) => m.reason === o.reason && m.code === o.code && o.decisionIds.includes(m.decisionId));
695
+ if (marks.length > 0)
696
+ for (const id of await settleOn(judgedTree, scope, marks, runId))
697
+ quiet.add(id);
698
+ return o;
699
+ }
700
+ if (UNMARKED_REASONS.has(o.reason))
701
+ return o;
702
+ const condition = conditionOf(o);
703
+ const marks = [];
704
+ for (const id of o.decisionIds) {
705
+ const entry = entries.find((e) => e.decisionId === id);
706
+ if (entry === undefined || quiet.has(id))
707
+ continue;
708
+ marks.push({ token: entry.token, decisionId: id, reason: o.reason, ...(o.code !== undefined ? { code: o.code } : {}), ...(o.inputs !== undefined ? { inputs: o.inputs } : {}), condition });
709
+ }
428
710
  if (marks.length > 0)
429
- for (const id of await settleOn(x, scope, marks))
711
+ for (const id of await settleOn(judgedTree, scope, marks, runId))
430
712
  quiet.add(id);
431
713
  return o;
432
714
  };
433
- const judged = await judgeCards(x, records, parkStore, entries, unused, settle, quiet);
434
- if (judged.unresumable !== undefined)
435
- return told(judged.unresumable);
436
- if (judged.carried.length === 0)
437
- return told(judged.first ?? unused("record_unreadable"));
438
- const walked = seats.store === undefined ? "unreadable" : await workflowLineOf(seats.store, x.id, scope, within);
439
- const unrecordedOn = (w, of) => typeof w === "string"
440
- ? of
441
- : of.filter((c) => {
442
- const recorded = settledMarkOf(c.entry.token, c.entry.decisionId, w.records) !== undefined;
443
- if (recorded)
444
- quiet.add(c.entry.decisionId);
445
- return !recorded;
446
- });
447
- let carried = unrecordedOn(walked, judged.carried);
448
- if (carried.length === 0)
449
- return judged.first !== undefined ? told(judged.first) : "settled_before";
450
- const carriedIdsOf = () => carried.map((c) => c.entry.decisionId);
451
- const unusedCarried = (reason, more = {}) => ({ kind: "unused", runId, decisionIds: carriedIdsOf(), reason, ...more });
452
- const settledCarried = (reason, more = {}) => {
453
- for (const { entry } of carried)
454
- settle(entry, reason, more.code);
455
- return told(unusedCarried(reason, more));
456
- };
457
- const lineOf = async (walked) => {
458
- const line = seats.store === undefined ? { kind: "unreadable" } : await otherWaitingLine(seats.store, parkStore, x.id, scope, within, walked);
459
- return line.kind === "unreadable" || line.kind === "over_bound" ? unusedCarried("record_unreadable") : line.kind === "waiting" ? unusedCarried("waiting_elsewhere", { waiting: line.lines }) : line.root;
460
- };
461
- const treeOf = (w) => (typeof w === "string" ? w : { root: w.root, line: w.line, recorded: w.recorded });
462
- const claimKey = await lineOf(treeOf(walked));
463
- if (typeof claimKey !== "string")
464
- return claimKey;
465
- if (x.errorCode !== WORKFLOW_AGENT_PARKED_ERROR_CODE)
466
- return unusedCarried("record_unreadable");
467
- let launch;
468
- if (journalKeepsLaunches(seats.journalStore)) {
469
- const launchRead = await readKeptLaunch(seats.journalStore, runId, scope, seats.waitBoundMs);
470
- if (launchRead.kind === "failed") {
471
- if (launchRead.cause !== undefined)
472
- seats.reportStoreFault?.(`the launch record of workflow run ${JSON.stringify(runId)} could not be read by the engine's continuation`, launchRead.cause.err);
715
+ const answer = await (async () => {
716
+ const judged = await judgeCards(x, tree, parkStore, entries, settle, quiet);
717
+ own.push(...judged.own);
718
+ if (judged.carried.length === 0)
719
+ return "settled_before";
720
+ let carried = judged.carried;
721
+ const carriedIdsOf = () => carried.map((c) => c.entry.decisionId);
722
+ const unusedCarried = (reason, more = {}) => ({ kind: "unused", runId, decisionIds: carriedIdsOf(), reason, ...more });
723
+ if (judged.unresumable !== undefined)
724
+ return told(unusedCarried("card_unresumable", { ...judged.unresumable, otherCard: true }));
725
+ const settledCarried = (reason, more = {}) => {
726
+ for (const { entry } of carried)
727
+ settle(entry, reason, more.code);
728
+ return told(unusedCarried(reason, more));
729
+ };
730
+ const lineOf = async (over) => {
731
+ const line = await otherWaitingLine(over, parkStore, x.id, within);
732
+ return line.kind === "unreadable" ? unusedCarried("record_unreadable") : line.kind === "waiting" ? unusedCarried("waiting_elsewhere", { waiting: line.lines }) : line.root;
733
+ };
734
+ const claimKey = await lineOf(tree);
735
+ if (typeof claimKey !== "string")
736
+ return told(claimKey);
737
+ if (x.errorCode !== WORKFLOW_AGENT_PARKED_ERROR_CODE)
473
738
  return unusedCarried("record_unreadable");
739
+ let launch;
740
+ if (journalKeepsLaunches(seats.journalStore)) {
741
+ const launchRead = await readKeptLaunch(seats.journalStore, runId, scope, seats.waitBoundMs);
742
+ if (launchRead.kind === "failed") {
743
+ if (launchRead.cause !== undefined)
744
+ seats.reportStoreFault?.(`the launch record of workflow run ${JSON.stringify(runId)} could not be read by the engine's continuation`, launchRead.cause.err);
745
+ return unusedCarried("record_unreadable");
746
+ }
747
+ if (launchRead.kind === "defect")
748
+ return settledCarried("launch_unreadable", { code: launchRead.member });
749
+ if (launchRead.kind === "record")
750
+ launch = launchRead.record;
474
751
  }
475
- if (launchRead.kind === "defect")
476
- return settledCarried("launch_unreadable", { code: launchRead.member });
477
- if (launchRead.kind === "record")
478
- launch = launchRead.record;
479
- }
480
- if (launch !== undefined || x.hostFoldDigest !== undefined) {
481
- let fold;
482
- try {
483
- fold = seats.hostFoldDigest(ctx, launch);
752
+ if (launch !== undefined || x.hostFoldDigest !== undefined) {
753
+ let fold;
754
+ try {
755
+ fold = seats.hostFoldDigest(ctx, launch);
756
+ }
757
+ catch {
758
+ fold = undefined;
759
+ }
760
+ if (fold === undefined || x.hostFoldDigest === undefined || fold !== x.hostFoldDigest) {
761
+ const inputs = fold === undefined || x.hostFoldDigest === undefined ? undefined : hostFoldChanges(x.hostFoldDigest, fold);
762
+ return told(unusedCarried("host_changed", { changed: "identity", ...(inputs !== undefined && inputs.length > 0 ? { inputs } : {}) }));
763
+ }
484
764
  }
485
- catch {
486
- fold = undefined;
765
+ for (const { entry, state } of carried) {
766
+ const verdict = parentConstraintChainVerdict(state, entry.inheritedGate?.parentConstraints ?? seats.chainToHand(ctx));
767
+ if (verdict !== undefined)
768
+ return told(unusedCarried("host_changed", { changed: "parent_chain", code: verdict.code }));
487
769
  }
488
- if (fold === undefined || x.hostFoldDigest === undefined || fold !== x.hostFoldDigest) {
489
- const inputs = fold === undefined || x.hostFoldDigest === undefined ? undefined : hostFoldChanges(x.hostFoldDigest, fold);
490
- return unusedCarried("host_changed", { changed: "identity", ...(inputs !== undefined && inputs.length > 0 ? { inputs } : {}) });
770
+ if (approvedCall !== undefined) {
771
+ seats.holdForCall(runId, approvedCall, { decisions: carried.map(({ entry }) => decisionOf(entry)) });
772
+ return "carried";
491
773
  }
492
- }
493
- for (const { entry, state } of carried) {
494
- const verdict = parentConstraintChainVerdict(state, entry.inheritedGate?.parentConstraints ?? seats.chainToHand(ctx));
495
- if (verdict !== undefined)
496
- return unusedCarried("host_changed", { changed: "parent_chain", code: verdict.code });
497
- }
498
- if (approvedCall !== undefined) {
499
- seats.holdForCall(runId, approvedCall, { decisions: carried.map(({ entry }) => decisionOf(entry)) });
500
- return "carried";
501
- }
502
- if (launch === undefined)
503
- return seats.instructOnce(carriedIdsOf()) ? unusedCarried("launch_unrecorded") : unusedCarried("launch_unrecorded", { askedBefore: true });
504
- const name = launch.callArgs.name;
505
- const input = { script: launch.script, ...(launch.effectiveArgs !== undefined ? { args: launch.effectiveArgs } : {}), ...(typeof name === "string" ? { name } : {}), resumeFromRunId: runId };
506
- const byPerson = carried.every((c) => isObject(c.entry.outcome) && isObject(c.entry.outcome.hostDecision) && c.entry.outcome.hostDecision.decidedBy === "person");
507
- if (leg.gate !== undefined) {
508
- let judged;
509
- try {
510
- judged = await leg.gate.judge({ toolCallId, toolName: seats.toolName, input }, byPerson ? "person" : "none");
774
+ if (launch === undefined)
775
+ return told(unusedCarried("launch_unrecorded"));
776
+ let superseded;
777
+ const rejudge = async () => {
778
+ const now = await readTree(runId, scope);
779
+ const xNow = typeof now === "string" ? undefined : workflowRunInTree(now, runId);
780
+ if (typeof now === "string" || xNow === undefined || xNow.status === "running" || xNow.resumeAdmissionIncomplete === true) {
781
+ superseded = unusedCarried("record_unreadable");
782
+ return false;
783
+ }
784
+ judgedTree = now;
785
+ const again = await judgeCards(xNow, now, parkStore, carried.map((c) => c.entry), settle, quiet);
786
+ own.push(...again.own);
787
+ const lost = carried.filter((c) => !again.carried.some((a) => a.entry === c.entry) && !quiet.has(c.entry.decisionId)).length;
788
+ carried = again.carried;
789
+ if (carried.length === 0)
790
+ superseded = "settled_before";
791
+ return { lost, ...(again.unresumable !== undefined ? { unresumable: again.unresumable } : {}) };
792
+ };
793
+ const confirm = async () => {
794
+ const again = await rejudge();
795
+ if (again === false || carried.length === 0)
796
+ return false;
797
+ if (again.unresumable !== undefined || again.lost > 0) {
798
+ superseded = again.unresumable !== undefined ? unusedCarried("card_unresumable", { ...again.unresumable, otherCard: true }) : unusedCarried("record_unreadable");
799
+ return false;
800
+ }
801
+ const line = await lineOf(judgedTree);
802
+ if (typeof line !== "string")
803
+ superseded = line;
804
+ else if (line !== claimKey)
805
+ superseded = unusedCarried("record_unreadable");
806
+ return superseded === undefined ? carried.map(({ entry }) => decisionOf(entry)) : false;
807
+ };
808
+ const deniedUnderClaim = async (layer) => {
809
+ if ((await rejudge()) === false || carried.length === 0)
810
+ return undefined;
811
+ if (judgedTree.root.id !== claimKey) {
812
+ superseded = unusedCarried("record_unreadable");
813
+ return undefined;
814
+ }
815
+ const o = await settledCarried("denied", { code: layer, explicit: true });
816
+ if (o.kind !== "unused")
817
+ return o;
818
+ const after = await readTree(runId, scope);
819
+ const stands = (id) => {
820
+ const entry = carried.find((c) => c.entry.decisionId === id)?.entry;
821
+ if (typeof after === "string" || entry === undefined)
822
+ return false;
823
+ const was = workflowParkDecisionOf(entry.token, id, after);
824
+ return was.kind === "spent" && was.by === "mark" && was.reason === "denied" && was.code === layer;
825
+ };
826
+ const unrecorded = o.decisionIds.filter((id) => !stands(id));
827
+ if (unrecorded.length === 0)
828
+ return o;
829
+ own.push({ kind: "unused", runId, decisionIds: unrecorded, reason: "record_unreadable", answerUnrecorded: true });
830
+ const recorded = o.decisionIds.filter((id) => !unrecorded.includes(id));
831
+ return recorded.length > 0 ? { ...o, decisionIds: recorded } : "settled_before";
832
+ };
833
+ const supersededAnswer = () => (superseded === "settled_before" ? superseded : told(superseded ?? unusedCarried("record_unreadable")));
834
+ const name = launch.callArgs.name;
835
+ const input = { script: launch.script, ...(launch.effectiveArgs !== undefined ? { args: launch.effectiveArgs } : {}), ...(typeof name === "string" ? { name } : {}), resumeFromRunId: runId };
836
+ const byPerson = carried.every((c) => isObject(c.entry.outcome) && isObject(c.entry.outcome.hostDecision) && c.entry.outcome.hostDecision.decidedBy === "person");
837
+ if (leg.gate !== undefined) {
838
+ let judged;
839
+ try {
840
+ judged = await leg.gate.judge({ toolCallId, toolName: seats.toolName, input }, byPerson ? "person" : "none");
841
+ }
842
+ catch {
843
+ judged = { kind: "ask_unanswerable" };
844
+ }
845
+ if (judged.kind === "denied" && judged.explicit) {
846
+ const layer = judged.layer;
847
+ const under = await seats.underClaim(claimKey, scope, () => deniedUnderClaim(layer));
848
+ if ("claimHeld" in under)
849
+ return unusedCarried("continuing_elsewhere", { ...under.claimHeld, answerUnrecorded: true });
850
+ if ("refused" in under)
851
+ return unusedCarried("record_unreadable", { answerUnrecorded: true });
852
+ return under.value ?? supersededAnswer();
853
+ }
854
+ if (judged.kind === "denied")
855
+ return settledCarried("denied", { code: judged.layer });
856
+ if (judged.kind === "ask_unanswerable")
857
+ return told(unusedCarried("ask_unanswerable"));
858
+ if (judged.kind === "call_changed")
859
+ return told(unusedCarried("call_changed"));
511
860
  }
512
- catch {
513
- judged = { kind: "ask_unanswerable" };
861
+ let started;
862
+ try {
863
+ started = await seats.launch({ fromRunId: runId, launch, decisions: carried.map(({ entry }) => decisionOf(entry)), claimKey }, ctx, confirm);
514
864
  }
515
- if (judged.kind === "denied")
516
- return settledCarried("denied", { code: judged.layer, ...(judged.explicit ? { explicit: true } : {}) });
517
- if (judged.kind === "ask_unanswerable")
518
- return seats.instructOnce(carriedIdsOf()) ? unusedCarried("ask_unanswerable") : unusedCarried("ask_unanswerable", { askedBefore: true });
519
- }
520
- let superseded;
521
- const confirm = async () => {
522
- const lineNow = seats.store === undefined ? "unreadable" : await workflowLineOf(seats.store, x.id, scope, within);
523
- carried = unrecordedOn(lineNow, carried);
524
- if (carried.length === 0) {
525
- superseded = "settled_before";
526
- return false;
865
+ catch (e) {
866
+ started = { refused: `the continuation's launch threw ${storeErrorClassOf(e)}` };
867
+ seats.reportStoreFault?.(`the continuation's launch of workflow run ${JSON.stringify(runId)} threw`, e);
527
868
  }
528
- const now = await successorsOf(x, scope);
529
- const again = typeof now === "string" ? undefined : await judgeCards(x, [x, ...now], parkStore, carried.map((c) => c.entry), unusedCarried, settle, quiet);
530
- superseded = again === undefined ? unusedCarried("record_unreadable") : (again.unresumable ?? (again.carried.length < carried.length ? (again.first ?? unusedCarried("record_unreadable")) : undefined));
531
- if (superseded !== undefined)
532
- return false;
533
- const line = await lineOf(treeOf(lineNow));
534
- if (typeof line !== "string")
535
- superseded = line;
536
- return superseded === undefined ? carried.map(({ entry }) => decisionOf(entry)) : false;
537
- };
538
- let started;
539
- try {
540
- started = await seats.launch({ fromRunId: runId, launch, decisions: carried.map(({ entry }) => decisionOf(entry)), claimKey }, ctx, confirm);
541
- }
542
- catch (e) {
543
- started = { refused: `the continuation's launch threw ${storeErrorClassOf(e)}` };
544
- seats.reportStoreFault?.(`the continuation's launch of workflow run ${JSON.stringify(runId)} threw`, e);
545
- }
546
- if ("refused" in started)
547
- return unusedCarried("launch_refused", { why: neutral(started.refused, WHY_ECHO_MAX) });
548
- if ("claimHeld" in started)
549
- return unusedCarried("continuing_elsewhere", started.claimHeld);
550
- if ("superseded" in started)
551
- return superseded === "settled_before" ? superseded : told(superseded ?? unusedCarried("record_unreadable"));
552
- const stepDenied = carried.some((c) => isObject(c.entry.outcome) && c.entry.outcome.decision === "deny");
553
- return { kind: "started", runId, decisionIds: carriedIdsOf(), continuedAs: started.runId, ...(stepDenied ? { stepDenied: true } : {}) };
869
+ if ("refused" in started)
870
+ return told(unusedCarried("launch_refused", { why: neutral(started.refused, WHY_ECHO_MAX) }));
871
+ if ("claimHeld" in started)
872
+ return told(unusedCarried("continuing_elsewhere", started.claimHeld));
873
+ if ("superseded" in started)
874
+ return supersededAnswer();
875
+ const stepDenied = carried.some((c) => isObject(c.entry.outcome) && c.entry.outcome.decision === "deny");
876
+ return { kind: "started", runId, decisionIds: carriedIdsOf(), continuedAs: started.runId, ...(stepDenied ? { stepDenied: true } : {}) };
877
+ })();
878
+ for (const o of groupedByAnswer(own))
879
+ asides.push(await told(o));
880
+ return answer;
554
881
  };
555
882
  return async (leg) => {
556
883
  const { usable, unreadable } = readDecisions(seats.decisions);
557
884
  const out = [];
558
885
  const byRun = new Map();
559
- for (const e of usable)
560
- byRun.set(e.runId, [...(byRun.get(e.runId) ?? []), e]);
886
+ for (const e of usable) {
887
+ const was = byRun.get(e.runId) ?? [];
888
+ if (!was.some((s) => s.token === e.token && s.decisionId === e.decisionId))
889
+ byRun.set(e.runId, [...was, e]);
890
+ }
561
891
  const unreadableRuns = new Map();
562
- for (const u of unreadable)
563
- unreadableRuns.set(u.runId, [...(unreadableRuns.get(u.runId) ?? []), ...(u.decisionId !== undefined ? [u.decisionId] : [])]);
892
+ for (const u of unreadable) {
893
+ const was = unreadableRuns.get(u.runId) ?? [];
894
+ unreadableRuns.set(u.runId, u.decisionId !== undefined && !was.includes(u.decisionId) ? [...was, u.decisionId] : was);
895
+ }
564
896
  for (const [runId, ids] of unreadableRuns)
565
897
  if (!byRun.has(runId))
566
898
  out.push({ kind: "unused", runId, decisionIds: ids, reason: "entry_unreadable" });
@@ -569,8 +901,10 @@ export function createWorkflowParkAdopter(seats) {
569
901
  if (resumed !== undefined) {
570
902
  if (resumed.approved) {
571
903
  try {
572
- const adopted = await adoptOne(runId, entries, leg, new Set(), resumed.toolCallId);
573
- const refusal = adopted === "carried" || adopted === "settled_before" ? undefined : resumedCallRefusalOf(adopted);
904
+ const own = [];
905
+ const adopted = await adoptOne(runId, entries, leg, new Set(), own, resumed.toolCallId);
906
+ const answered = own.find((o) => o.kind === "unused" && o.reason === "card_unresumable") ?? (adopted === "settled_before" ? own[0] : adopted);
907
+ const refusal = answered === undefined || answered === "carried" ? undefined : resumedCallRefusalOf(answered);
574
908
  if (refusal !== undefined)
575
909
  seats.holdForCall(runId, resumed.toolCallId, { refusal });
576
910
  }
@@ -581,14 +915,15 @@ export function createWorkflowParkAdopter(seats) {
581
915
  }
582
916
  try {
583
917
  const quiet = new Set();
584
- const adopted = await adoptOne(runId, entries, leg, quiet);
585
- if (adopted === "carried" || adopted === "settled_before")
586
- continue;
587
- const kept = adopted.kind === "unused" ? adopted.decisionIds.filter((id) => !quiet.has(id)) : [];
588
- if (adopted.kind !== "unused" || kept.length === adopted.decisionIds.length)
589
- out.push(adopted);
590
- else if (kept.length > 0)
591
- out.push({ ...adopted, decisionIds: kept });
918
+ const asides = [];
919
+ const adopted = await adoptOne(runId, entries, leg, quiet, asides);
920
+ for (const o of adopted === "carried" || adopted === "settled_before" ? asides : [adopted, ...asides]) {
921
+ const kept = o.kind === "unused" ? o.decisionIds.filter((id) => !quiet.has(id)) : [];
922
+ if (o.kind !== "unused" || kept.length === o.decisionIds.length)
923
+ out.push(o);
924
+ else if (kept.length > 0)
925
+ out.push({ ...o, decisionIds: kept });
926
+ }
592
927
  }
593
928
  catch {
594
929
  out.push({ kind: "unused", runId, decisionIds: entries.map((e) => e.decisionId), reason: "record_unreadable" });
@@ -622,6 +957,10 @@ export function workflowParkUnusedSentence(o) {
622
957
  case "entry_unreadable":
623
958
  return `the deployment handed the decision over without its decision id or its outcome. ${waiting}; decide it again, and report the defect to the deployment if this repeats`;
624
959
  case "record_unreadable":
960
+ if (o.cardUnread === true)
961
+ return `the approval card could not be read right now, so whether it is still waiting is not known; the next run of this session tries again`;
962
+ if (o.answerUnrecorded === true)
963
+ return `a person answered no when asked to continue the workflow, and the engine could not confirm that it recorded that answer, so nothing was started and the same decision may be asked about again. If the approval card is still waiting, decide it again (a new decision) to continue the run, or start the workflow again`;
625
964
  return `the workflow run's record could not be read right now, or the run did not stop on an approval. ${waiting}; the next run of this session tries again. If the answer stays the same, the workflow may have more runs than the ${WORKFLOW_TREE_RUNS_MAX} the engine reads to judge a continuation (every continuation of a run adds one): then start the workflow again — it runs from its first step`;
626
965
  case "run_not_ended":
627
966
  return `the run that holds the approval card has not written down how it ended — its record still says it is running — so the engine cannot continue it from this decision and nothing was started. ${waiting}; if that run is still running, decide again once it has ended, and if it stopped without writing its end, nothing continues it from this card: start the workflow again — it runs from its first step`;
@@ -635,14 +974,29 @@ export function workflowParkUnusedSentence(o) {
635
974
  : "the approval card is no longer waiting for a decision (it was decided elsewhere, it expired, or it was removed). Nothing is left to do for this decision";
636
975
  case "continuing_elsewhere": {
637
976
  const self = typeof o.holder === "string" && o.holder === o.runId;
638
- const who = self ? `run ${echo(o.runId)} itself holds the claim to continue this workflow right now (it is still running, or has just stopped and not yet given the claim back)` : `another run${o.holder !== undefined && typeof o.holder === "string" ? ` (run ${echo(o.holder)})` : ""} holds the claim to continue this workflow right now`;
977
+ const holderRun = typeof o.holder === "string" ? `run ${echo(o.holder)}` : undefined;
978
+ const recording = "another leg of this workflow, recording a person's answer to continuing it";
639
979
  const at = claimLapseInstant(o.claimExpiresAt);
640
- const lapse = `or once the claim lapses${at !== undefined ? ` (at ${at} at the latest)` : ""} if its process stopped without giving it back`;
980
+ const when = at !== undefined ? `at ${at} at the latest` : o.claimLapseUnreadable === true ? CLAIM_REMAINING_UNREADABLE_NOTE : undefined;
981
+ const lapse = `or once the claim lapses${when !== undefined ? ` (${when})` : ""} if its process stopped without giving it back`;
982
+ const mayHaveUsed = o.heldForAnswer !== true && !self;
983
+ const whatCame = `${mayHaveUsed && holderRun !== undefined ? `If ${holderRun} was started, its completion notification and record tell what came of it. ` : ""}The workflow's run records tell whether the run was continued, and the approval card tells whether it still waits for a decision`;
984
+ if (o.answerUnrecorded === true) {
985
+ const holderSaid = o.heldForAnswer === true ? `${recording},` : self ? `run ${echo(o.runId)} itself (it is still running, or has just stopped and not yet given the claim back)` : holderRun ?? "another leg of this workflow";
986
+ return `a person answered no when asked to continue the workflow, and that answer was not recorded: ${holderSaid} held the workflow's resume claim at that moment${mayHaveUsed ? " and may have continued the run with this same decision" : ""}, so this leg started nothing. ${whatCame}`;
987
+ }
988
+ const who = o.heldForAnswer === true ? `${recording}, holds the claim to continue this workflow` : self ? `run ${echo(o.runId)} itself holds the claim to continue this workflow right now (it is still running, or has just stopped and not yet given the claim back)` : `another run${holderRun !== undefined ? ` (${holderRun})` : ""} holds the claim to continue this workflow right now`;
989
+ if (o.heldForAnswer === true) {
990
+ const back = `The claim comes free when that leg gives it back, ${lapse}`;
991
+ return `${who}, so ${o.decisionIds.length > 0
992
+ ? `this leg did not use this decision; what that leg records about it is read the next time the decision is handed over. ${back}`
993
+ : `nothing was started. ${back}; the run's approval card then tells whether the run waits for a decision`}`;
994
+ }
641
995
  return `${who}, so ${o.decisionIds.length > 0
642
- ? `this decision was not used this time; it can still be used when it is handed over again${at !== undefined ? ` (the claim lapses at ${at} at the latest)` : ""}`
996
+ ? `this decision was not used this time${mayHaveUsed ? "; that run may be continuing the run with this same decision" : ""}. ${whatCame}. The claim comes free when that run gives it back, ${lapse}`
643
997
  : self
644
998
  ? `nothing was started; it can be continued once it has ended and given the claim back, ${lapse}`
645
- : `nothing was started; the workflow can be continued once that run has ended, ${lapse}`}`;
999
+ : `nothing was started. If you were told that the engine continues this run${holderRun !== undefined ? ` as ${holderRun}` : ""}, do not call again: ${holderRun !== undefined ? `${holderRun}'s` : "that continuation's"} completion notification tells what came of it. If you were not told that, ${holderRun ?? "the run that holds the claim"} is another continuation of this workflow, and this run cannot be continued while that run holds the claim, which comes free when that run gives it back, ${lapse}`}`;
646
1000
  }
647
1001
  case "waiting_elsewhere": {
648
1002
  const lines = o.waiting ?? [];
@@ -657,45 +1011,45 @@ export function workflowParkUnusedSentence(o) {
657
1011
  const run = l !== undefined ? runOf(l) : "another run of it";
658
1012
  const what = l !== undefined ? stopped(l) : `${run} stopped on an approval card`;
659
1013
  const wayOut = l?.yielded === true ? `continue ${run} first` : `decide that card first, or continue ${run} instead`;
660
- return `another line of this workflow is waiting: ${what}, and a workflow runs or waits on one line at a time. ${kept ? `${waiting} and the decision is kept; ${wayOut}, then hand this decision over again` : `Nothing was started; ${wayOut}`}`;
1014
+ return `another line of this workflow is waiting: ${what}, and a workflow runs or waits on one line at a time. ${kept ? `${waiting}; ${wayOut}, then decide this card again to continue the run` : `Nothing was started; ${wayOut}`}`;
661
1015
  }
662
1016
  const shown = lines.slice(0, WAITING_LINES_NAMED_MAX);
663
1017
  const list = `${shown.map(stopped).join("; ")}${lines.length > shown.length ? `; and ${lines.length - shown.length} more` : ""}`;
664
1018
  const anyCard = lines.some((l) => l.yielded !== true);
665
1019
  const wayOut = anyCard ? "decide any one of those cards first, or continue one of those runs instead" : "continue one of those runs first";
666
- return `other lines of this workflow are waiting: ${list}, and a workflow runs or waits on one line at a time. ${kept ? `${waiting} and the decision is kept; ${wayOut} — each moves its own line —, then hand this decision over again once none of them waits` : `Nothing was started; ${wayOut}`}`;
1020
+ return `other lines of this workflow are waiting: ${list}, and a workflow runs or waits on one line at a time. ${kept ? `${waiting}; ${wayOut} — each moves its own line —, then decide this card again once none of them waits` : `Nothing was started; ${wayOut}`}`;
667
1021
  }
668
1022
  case "card_unresumable":
1023
+ if (o.otherCard === true)
1024
+ return `another approval card of this workflow run is one this engine cannot resume${unresumableCode(o)}: ${o.rowSentence ?? ""} A continuation would stop on that card, so none was started. ${waiting}: handed over again without that card's decision, this decision continues the run (which then stops on that card once more)`;
669
1025
  return o.terminal === true
670
1026
  ? `the approval card's checkpoint is one no engine release resumes${unresumableCode(o)}: ${o.rowSentence ?? ""} The workflow run cannot be continued from this card; start the workflow again`
671
1027
  : `this engine cannot resume the approval card's checkpoint${unresumableCode(o)}: ${o.rowSentence ?? ""} This engine cannot continue the workflow run from this card. If the deployment still runs a worker whose engine release reads the card, the decision can continue the run there; otherwise cancel the run and start the workflow again`;
672
1028
  case "decision_spent":
673
1029
  return `this decision was already used once to continue the run, and that continuation refused it${o.code !== undefined ? ` (${neutral(o.code)})` : ""}. ${waiting}; decide it again — a new decision — to continue the run`;
674
1030
  case "launch_unrecorded":
675
- return `this run has no record of what the workflow was started with (it was stopped before this deployment kept one, or the record is gone), so the engine cannot continue it on its own. ${waiting} and the decision is kept: ${o.askedBefore === true
676
- ? "the session's model was already told once to continue the run by calling the Workflow tool with the run's original script and resumeFromRunId, so it is not told again"
677
- : "the session's model continues the run by calling the Workflow tool with the run's original script and resumeFromRunId"} — where that call needs an approval, the approved call carries the decision and continues the run; where it does not, the run stops on the same card once more, under a new run, and the decision continues it once it is handed over again`;
1031
+ return `this run has no record of what the workflow was started with (it was stopped before this deployment kept one, or the record is gone), so the engine cannot continue it on its own. ${waiting}: the session's model continues the run by calling the Workflow tool with the run's original script and resumeFromRunId — where that call needs an approval, the approved call carries the decision and continues the run; where it does not, the run stops on the same card once more, under a new run, and deciding that card again continues it`;
678
1032
  case "launch_unreadable":
679
1033
  return `the record of what the workflow was started with does not read back in the shape it was written in${o.code !== undefined ? ` (${neutral(o.code)})` : ""}, so the run cannot be continued here. Start the workflow again, and report the defect to the deployment`;
680
1034
  case "host_changed":
681
1035
  return o.changed === "parent_chain"
682
- ? `the permission rules the workflow's agents were stopped under have changed since. ${waiting} and the decision is kept: once those rules are back to what they were, the same decision continues the run when it is handed over again — or start the workflow again`
1036
+ ? `the permission rules the workflow's agents were stopped under have changed since. ${waiting}: once those rules are back to what they were, deciding the card again continues the run — or start the workflow again`
683
1037
  : o.inputs !== undefined
684
- ? `what the workflow's agents run under has changed since the workflow stopped: ${o.inputs.map((k) => HOST_FOLD_INPUT_WORDS[k]).join("; ")}. ${waiting} and the decision is kept: once ${o.inputs.length === 1 ? "it is back to what it was" : "they are back to what they were"}, the same decision continues the run when it is handed over again — or start the workflow again`
685
- : `what the workflow's agents run under (the deployment's settings for workflow agents, this session's permission limits, the workflow's model, or the account it runs for) has changed since the workflow stopped. ${waiting} and the decision is kept: once it is back to what it was, the same decision continues the run when it is handed over again — or start the workflow again`;
1038
+ ? `what the workflow's agents run under has changed since the workflow stopped: ${o.inputs.map((k) => HOST_FOLD_INPUT_WORDS[k]).join("; ")}. ${waiting}: once ${o.inputs.length === 1 ? "it is back to what it was" : "they are back to what they were"}, deciding the card again continues the run — or start the workflow again`
1039
+ : `what the workflow's agents run under (the deployment's settings for workflow agents, this session's permission limits, the workflow's model, or the account it runs for) has changed since the workflow stopped. ${waiting}: once it is back to what it was, deciding the card again continues the run — or start the workflow again`;
686
1040
  case "denied":
687
1041
  return o.explicit === true
688
1042
  ? `a person answered no when asked to continue the workflow. ${waiting}; decide the card again (a new decision) to continue the run, or start the workflow again`
689
- : `this session's permission settings now refuse to run the workflow${o.code !== undefined ? ` (${neutral(o.code)})` : ""}. ${waiting} and the decision is kept: once ${o.code === "persisted_rule" ? "that deny rule for the Workflow tool is removed" : o.code === "mode" ? "the session is out of that permission mode" : "the Workflow tool is allowed again"}, the same decision continues the run when it is handed over again — or start the workflow again`;
1043
+ : `this session's permission settings now refuse to run the workflow${o.code !== undefined ? ` (${neutral(o.code)})` : ""}. ${waiting}: once ${o.code === "persisted_rule" ? "that deny rule for the Workflow tool is removed" : o.code === "mode" ? "the session is out of that permission mode" : "the Workflow tool is allowed again"}, deciding the card again continues the run — or start the workflow again`;
1044
+ case "call_changed":
1045
+ return `the Workflow call that continues the run came back changed when it was judged (an approver's edit, or a policy's or a hook's rewrite of its arguments), and the engine's continuation runs only what the workflow was started with, so nothing was started. ${waiting}: the session's model can call the Workflow tool with resumeFromRunId itself — that call is judged on its own card, where the change can be made again; it runs as approved and stops on the same approval step once more, under a new run, and deciding that step's card continues it`;
690
1046
  case "ask_unanswerable":
691
- return o.askedBefore === true
692
- ? `continuing the workflow needs a person's approval that nobody can give in this session right now, and the session's model was already asked once to request it as a new card without the run going on, so it is not asked again. ${waiting} and the decision is kept; decide the card again where a person can approve`
693
- : `continuing the workflow needs a person's approval that nobody can give in this session right now. ${waiting} and the decision is kept: the session's model can ask for that approval as a new card, or the card can be decided again where a person can approve`;
1047
+ return `continuing the workflow needs a person's approval that nobody can give in this session right now. ${waiting}: the session's model can ask for that approval as a new card, or the card can be decided again where a person can approve`;
694
1048
  case "launch_refused":
695
- return `the workflow could not be started${o.why !== undefined ? `: ${neutral(o.why, WHY_ECHO_MAX)}` : ""}. ${waiting}, and the decision can still be used when it is handed over again; if the cause does not clear, start the workflow again`;
1049
+ return `the workflow could not be started${o.why !== undefined ? `: ${neutral(o.why, WHY_ECHO_MAX)}` : ""}. ${waiting}: once the cause clears, deciding the card again continues the run; if it does not clear, start the workflow again`;
696
1050
  }
697
1051
  }
698
- const settledForGood = (o) => o.reason === "not_pending" || settlesDecision(o);
1052
+ const settledForGood = (o) => workflowParkUnusedClassOf(o.reason, settlesDecision(o)) !== "deliverable";
699
1053
  export function notContinuedRefusalOf(runId, reason, more = {}) {
700
1054
  const { decisionIds = [], ...rest } = more;
701
1055
  return `workflow run "${neutral(runId)}" is not continued: ${workflowParkUnusedSentence({ kind: "unused", runId, decisionIds, reason, ...rest })}.`;
@@ -719,6 +1073,9 @@ const ECHO_MAX = 64;
719
1073
  const WAITING_LINES_NAMED_MAX = 3;
720
1074
  const WHY_ECHO_MAX = 160;
721
1075
  const neutral = (s, max = ECHO_MAX) => inlineUntrusted(s, max);
1076
+ function decisionKeyOf(runId, decisionIds) {
1077
+ return createHash("sha256").update(JSON.stringify([runId, [...new Set(decisionIds)].sort()])).digest("hex").slice(0, 32);
1078
+ }
722
1079
  export function workflowParksContributor(input) {
723
1080
  const decisions = input.decisions;
724
1081
  if (decisions === undefined || decisions.length === 0)
@@ -726,13 +1083,23 @@ export function workflowParksContributor(input) {
726
1083
  return async () => {
727
1084
  const outcomes = input.adopter !== undefined ? await input.adopter({ gate: input.gate, mintCallId: input.mintCallId, ctxOf: input.ctxOf, ...(input.resumedCall !== undefined ? { resumedCall: input.resumedCall } : {}) }) : unmountedWorkflowParkAdoptions(decisions);
728
1085
  for (const o of outcomes) {
729
- if (o.kind !== "unused")
1086
+ if (o.kind === "started") {
1087
+ try {
1088
+ input.deliver({
1089
+ code: "workflow.parked_decision_used",
1090
+ message: `the approval decision for workflow run "${neutral(o.runId)}" was used to continue it, as run "${neutral(o.continuedAs)}".`,
1091
+ detail: { runId: o.runId, decisionIds: [...o.decisionIds], decisionKey: decisionKeyOf(o.runId, o.decisionIds), continuedAs: o.continuedAs },
1092
+ });
1093
+ }
1094
+ catch {
1095
+ }
730
1096
  continue;
1097
+ }
731
1098
  try {
732
1099
  input.deliver({
733
1100
  code: "workflow.parked_decision_unused",
734
1101
  message: `the approval decision for workflow run "${neutral(o.runId)}" was not used to continue it: ${workflowParkUnusedSentence(o)}.`,
735
- detail: { runId: o.runId, decisionIds: [...o.decisionIds], reason: o.reason, ...holderDetailOf(o), ...(o.code !== undefined ? { code: o.code } : {}), ...(o.changed !== undefined ? { changed: o.changed } : {}), ...(o.inputs !== undefined ? { inputs: [...o.inputs] } : {}), ...(o.why !== undefined ? { why: o.why } : {}), ...(o.askedBefore === true ? { askedBefore: true } : {}), ...(o.rowReason !== undefined ? { rowReason: o.rowReason } : {}), ...(o.terminal === true ? { terminal: true } : {}), ...(o.continuedAs !== undefined ? { continuedAs: o.continuedAs } : {}) },
1102
+ detail: { runId: o.runId, decisionIds: [...o.decisionIds], decisionKey: decisionKeyOf(o.runId, o.decisionIds), reason: o.reason, ...holderDetailOf(o), ...(o.code !== undefined ? { code: o.code } : {}), ...(o.changed !== undefined ? { changed: o.changed } : {}), ...(o.inputs !== undefined ? { inputs: [...o.inputs] } : {}), ...(o.why !== undefined ? { why: o.why } : {}), ...(o.rowReason !== undefined ? { rowReason: o.rowReason } : {}), ...(o.terminal === true ? { terminal: true } : {}), ...(o.continuedAs !== undefined ? { continuedAs: o.continuedAs } : {}), spent: settlesDecision(o) },
736
1103
  });
737
1104
  }
738
1105
  catch {
@@ -741,12 +1108,23 @@ export function workflowParksContributor(input) {
741
1108
  return workflowContinuationFrameBody(outcomes, input.toolName, input.say);
742
1109
  };
743
1110
  }
1111
+ function groupedByAnswer(answers) {
1112
+ const groups = new Map();
1113
+ for (const o of answers) {
1114
+ if (o.kind !== "unused")
1115
+ continue;
1116
+ const { decisionIds, ...rest } = o;
1117
+ const key = JSON.stringify(Object.entries(rest).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
1118
+ const g = groups.get(key);
1119
+ groups.set(key, g === undefined ? o : { ...g, decisionIds: [...g.decisionIds, ...decisionIds] });
1120
+ }
1121
+ return [...groups.values()];
1122
+ }
744
1123
  function holderDetailOf(o) {
745
1124
  const holder = o.waiting !== undefined && o.waiting.length > 0 ? (o.waiting.length === 1 ? o.waiting[0].runId : o.waiting.map((l) => l.runId)) : o.holder;
746
1125
  return holder === undefined ? {} : { holder: typeof holder === "string" ? holder : [...holder] };
747
1126
  }
748
- export function workflowContinuationFrameBody(all, toolName, say) {
749
- const outcomes = all.filter((o) => o.kind !== "unused" || o.askedBefore !== true);
1127
+ export function workflowContinuationFrameBody(outcomes, toolName, say) {
750
1128
  if (outcomes.length === 0)
751
1129
  return undefined;
752
1130
  const id = (s) => neutral(s, FRAME_RUN_ID_ECHO_MAX);