@sema-agent/core 7.71.1 → 7.73.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 (348) hide show
  1. package/CHANGELOG.md +500 -0
  2. package/dist/agents/cross-session-ref.d.ts +2 -2
  3. package/dist/agents/cross-session-ref.js +7 -2
  4. package/dist/agents/inherited-tool-pool.d.ts +30 -2
  5. package/dist/agents/inherited-tool-pool.js +53 -7
  6. package/dist/agents/parked-resume-drive.d.ts +10 -0
  7. package/dist/agents/parked-resume-drive.js +9 -0
  8. package/dist/agents/retain-ledger.d.ts +3 -0
  9. package/dist/agents/send-message-tool.js +7 -2
  10. package/dist/agents/send-user-message-tool.d.ts +12 -0
  11. package/dist/agents/send-user-message-tool.js +67 -0
  12. package/dist/agents/subagent-steps.d.ts +9 -0
  13. package/dist/agents/subagent-steps.js +38 -0
  14. package/dist/agents/subagent.d.ts +2 -0
  15. package/dist/agents/subagent.js +47 -12
  16. package/dist/agents/verify.js +23 -7
  17. package/dist/agents/yield-adoption.js +3 -1
  18. package/dist/brain/anthropic.js +14 -9
  19. package/dist/brain/open-responses.js +4 -5
  20. package/dist/brain/openai.js +30 -23
  21. package/dist/brain/stream-engine.js +159 -151
  22. package/dist/core/a2a.d.ts +24 -3
  23. package/dist/core/a2a.js +27 -8
  24. package/dist/core/actions-digest.d.ts +43 -0
  25. package/dist/core/actions-digest.js +22 -0
  26. package/dist/core/agent-state.d.ts +28 -7
  27. package/dist/core/agent-state.js +19 -6
  28. package/dist/core/allow-entry.js +3 -3
  29. package/dist/core/approval-object.d.ts +7 -3
  30. package/dist/core/approval-object.js +30 -9
  31. package/dist/core/auto-mode.d.ts +7 -9
  32. package/dist/core/auto-mode.js +114 -8
  33. package/dist/core/checkpoint-features.d.ts +16 -5
  34. package/dist/core/checkpoint-features.js +35 -6
  35. package/dist/core/checkpoint-rekey.d.ts +1 -1
  36. package/dist/core/checkpoint-rekey.js +6 -1
  37. package/dist/core/checkpoint-requirements.d.ts +23 -3
  38. package/dist/core/checkpoint-requirements.js +5 -1
  39. package/dist/core/checkpoint-row-verdict.d.ts +1 -1
  40. package/dist/core/checkpoint-row-verdict.js +10 -4
  41. package/dist/core/checkpoint-store.d.ts +24 -2
  42. package/dist/core/checkpoint-store.js +1 -0
  43. package/dist/core/child-clamp-seats.d.ts +15 -0
  44. package/dist/core/child-clamp-seats.js +15 -0
  45. package/dist/core/delegation-frames.d.ts +1 -0
  46. package/dist/core/delegation-frames.js +1 -1
  47. package/dist/core/effective-path-target.d.ts +19 -0
  48. package/dist/core/effective-path-target.js +95 -38
  49. package/dist/core/engine-capabilities.d.ts +5 -1
  50. package/dist/core/engine-capabilities.js +1 -1
  51. package/dist/core/engine-notice.d.ts +34 -23
  52. package/dist/core/engine-version.js +1 -1
  53. package/dist/core/entries-not-applied.d.ts +19 -7
  54. package/dist/core/entries-not-applied.js +33 -1
  55. package/dist/core/file-history-store.d.ts +15 -4
  56. package/dist/core/file-history-store.js +53 -23
  57. package/dist/core/gate-fold.js +3 -1
  58. package/dist/core/governance-codes.d.ts +10 -1
  59. package/dist/core/governance-codes.js +17 -5
  60. package/dist/core/hooks.d.ts +3 -0
  61. package/dist/core/hooks.js +1 -0
  62. package/dist/core/host-instance.d.ts +23 -0
  63. package/dist/core/host-instance.js +69 -0
  64. package/dist/core/instruction-preview.d.ts +63 -0
  65. package/dist/core/instruction-preview.js +406 -0
  66. package/dist/core/judged-read.d.ts +57 -0
  67. package/dist/core/judged-read.js +1 -0
  68. package/dist/core/leg-budget.d.ts +26 -0
  69. package/dist/core/leg-budget.js +9 -0
  70. package/dist/core/leg-identity.d.ts +51 -1
  71. package/dist/core/leg-identity.js +45 -2
  72. package/dist/core/manager-launch-check.d.ts +48 -0
  73. package/dist/core/manager-launch-check.js +64 -0
  74. package/dist/core/mcp-call-meta.d.ts +2 -2
  75. package/dist/core/mcp-host-seat.d.ts +5 -0
  76. package/dist/core/mcp-host-seat.js +7 -1
  77. package/dist/core/mcp-injection-drop.d.ts +20 -10
  78. package/dist/core/mcp-injection-drop.js +9 -3
  79. package/dist/core/mcp-server-spec.d.ts +2 -1
  80. package/dist/core/mcp.js +3 -1
  81. package/dist/core/member-outcome.d.ts +3 -2
  82. package/dist/core/member-outcome.js +1 -1
  83. package/dist/core/memory-engine/deletion-record.d.ts +46 -0
  84. package/dist/core/memory-engine/deletion-record.js +96 -0
  85. package/dist/core/memory-engine/engine.js +24 -16
  86. package/dist/core/memory-engine/file-backend.js +7 -5
  87. package/dist/core/memory-engine/index.d.ts +1 -1
  88. package/dist/core/memory-engine/index.js +1 -1
  89. package/dist/core/memory-engine/layout.js +6 -4
  90. package/dist/core/memory-engine/projection-ledger.d.ts +1 -1
  91. package/dist/core/memory-engine/projection-ledger.js +1 -1
  92. package/dist/core/memory-engine/scope-contract.d.ts +69 -11
  93. package/dist/core/memory-engine/scope-contract.js +99 -34
  94. package/dist/core/memory-engine/sync-client.js +26 -6
  95. package/dist/core/memory-engine/sync.d.ts +20 -2
  96. package/dist/core/memory-engine/sync.js +18 -17
  97. package/dist/core/mode-policy.d.ts +21 -6
  98. package/dist/core/mode-policy.js +15 -6
  99. package/dist/core/mounted-mcp.d.ts +7 -2
  100. package/dist/core/mounted-mcp.js +10 -1
  101. package/dist/core/own-property-receipt.js +11 -4
  102. package/dist/core/param-rule-reach.d.ts +8 -3
  103. package/dist/core/param-rule-reach.js +9 -1
  104. package/dist/core/parent-spec-seat.d.ts +13 -1
  105. package/dist/core/parent-spec-seat.js +18 -0
  106. package/dist/core/peer-registration.d.ts +52 -0
  107. package/dist/core/peer-registration.js +37 -0
  108. package/dist/core/peer-seat.d.ts +3 -1
  109. package/dist/core/peer-seat.js +3 -3
  110. package/dist/core/peer-task-store.d.ts +365 -0
  111. package/dist/core/peer-task-store.js +682 -0
  112. package/dist/core/permission-rule-consent.js +6 -11
  113. package/dist/core/permission-rule-model.d.ts +27 -0
  114. package/dist/core/permission-rule-model.js +34 -6
  115. package/dist/core/permission-rule-provider.d.ts +35 -33
  116. package/dist/core/permission-rule-provider.js +38 -295
  117. package/dist/core/permission-rule-store.d.ts +181 -8
  118. package/dist/core/permission-rule-store.js +420 -17
  119. package/dist/core/permission-rule-sync.js +15 -1
  120. package/dist/core/project-seat.d.ts +55 -0
  121. package/dist/core/project-seat.js +96 -0
  122. package/dist/core/protocol-http-auth.d.ts +3 -2
  123. package/dist/core/protocol-http-auth.js +26 -18
  124. package/dist/core/remote-env.d.ts +4 -4
  125. package/dist/core/retired-keys.js +1 -0
  126. package/dist/core/rule-offer-read.d.ts +1 -1
  127. package/dist/core/rule-offer-read.js +32 -4
  128. package/dist/core/run-ledger-seat.d.ts +66 -0
  129. package/dist/core/run-ledger-seat.js +70 -0
  130. package/dist/core/run-ledger.d.ts +332 -0
  131. package/dist/core/run-ledger.js +550 -0
  132. package/dist/core/runner/chain-mismatch.d.ts +32 -0
  133. package/dist/core/runner/chain-mismatch.js +29 -0
  134. package/dist/core/runner/changes-history.d.ts +1 -0
  135. package/dist/core/runner/changes-history.js +2 -2
  136. package/dist/core/runner/checkpoint-scope.d.ts +13 -3
  137. package/dist/core/runner/checkpoint-scope.js +12 -4
  138. package/dist/core/runner/construction-doors.js +6 -0
  139. package/dist/core/runner/contracts.d.ts +22 -3
  140. package/dist/core/runner/delegation-owner.d.ts +30 -0
  141. package/dist/core/runner/delegation-owner.js +20 -4
  142. package/dist/core/runner/file-history-restore.d.ts +3 -1
  143. package/dist/core/runner/file-history-restore.js +9 -6
  144. package/dist/core/runner/finish-reason-seat.js +4 -2
  145. package/dist/core/runner/leg-frame.js +3 -0
  146. package/dist/core/runner/loaded-skills.d.ts +2 -0
  147. package/dist/core/runner/loaded-skills.js +10 -0
  148. package/dist/core/runner/nested-memory-lane.d.ts +22 -5
  149. package/dist/core/runner/nested-memory-lane.js +91 -30
  150. package/dist/core/runner/person-path-rows.d.ts +23 -20
  151. package/dist/core/runner/person-path-rows.js +82 -18
  152. package/dist/core/runner/prepare-caps-and-workflow.d.ts +4 -0
  153. package/dist/core/runner/prepare-caps-and-workflow.js +105 -90
  154. package/dist/core/runner/prepare-config-doors.d.ts +1 -0
  155. package/dist/core/runner/prepare-config-doors.js +5 -3
  156. package/dist/core/runner/prepare-context-lane.js +1 -0
  157. package/dist/core/runner/prepare-delegation-surface.d.ts +3 -0
  158. package/dist/core/runner/prepare-delegation-surface.js +6 -0
  159. package/dist/core/runner/prepare-execution-env.d.ts +3 -3
  160. package/dist/core/runner/prepare-file-history.js +1 -1
  161. package/dist/core/runner/prepare-hands-readface.d.ts +10 -2
  162. package/dist/core/runner/prepare-hands-readface.js +36 -22
  163. package/dist/core/runner/prepare-inherited-gate.d.ts +8 -5
  164. package/dist/core/runner/prepare-inherited-gate.js +14 -6
  165. package/dist/core/runner/prepare-memory-engine-session.d.ts +2 -2
  166. package/dist/core/runner/prepare-memory-engine-session.js +2 -2
  167. package/dist/core/runner/prepare-memory.js +3 -15
  168. package/dist/core/runner/prepare-project-context.d.ts +1 -1
  169. package/dist/core/runner/prepare-project-context.js +3 -7
  170. package/dist/core/runner/prepare-protocol-tools.d.ts +5 -0
  171. package/dist/core/runner/prepare-protocol-tools.js +2 -2
  172. package/dist/core/runner/prepare-run-refs.d.ts +1 -1
  173. package/dist/core/runner/prepare-run-refs.js +3 -2
  174. package/dist/core/runner/prepare-suspend-saga.d.ts +6 -2
  175. package/dist/core/runner/prepare-suspend-saga.js +4 -2
  176. package/dist/core/runner/prepare-task.js +50 -37
  177. package/dist/core/runner/prepare-turn-wiring.d.ts +4 -3
  178. package/dist/core/runner/prepare-turn-wiring.js +2 -1
  179. package/dist/core/runner/prepare-wiring-manifest.d.ts +5 -1
  180. package/dist/core/runner/prepare-wiring-manifest.js +8 -4
  181. package/dist/core/runner/read-session-changes.js +1 -1
  182. package/dist/core/runner/resume-apply.js +11 -5
  183. package/dist/core/runner/resume-checkpoint-screen.d.ts +8 -7
  184. package/dist/core/runner/resume-checkpoint-screen.js +7 -6
  185. package/dist/core/runner/resume-review-outcome.d.ts +3 -0
  186. package/dist/core/runner/resume-review-outcome.js +24 -1
  187. package/dist/core/runner/rewind-files.js +3 -2
  188. package/dist/core/runner/run-harness-handlers.js +3 -0
  189. package/dist/core/runner/run-identity-wiring.js +3 -2
  190. package/dist/core/runner/run-leg.js +9 -2
  191. package/dist/core/runner/run-notification-lane.js +20 -1
  192. package/dist/core/runner/run-settle-and-teardown.js +21 -12
  193. package/dist/core/runner/run-stop-and-final-verify.js +6 -0
  194. package/dist/core/runner/run-telemetry-and-budget-seats.js +1 -1
  195. package/dist/core/runner/runtask.d.ts +6 -2
  196. package/dist/core/runner/runtask.js +21 -9
  197. package/dist/core/runner/shell-env-withheld.d.ts +3 -2
  198. package/dist/core/runner/shell-env-withheld.js +1 -2
  199. package/dist/core/runner/stop-tail-notice.d.ts +10 -2
  200. package/dist/core/runner/stop-tail-notice.js +9 -2
  201. package/dist/core/runner/stream-settle-backstop.d.ts +1 -0
  202. package/dist/core/runner/stream-settle-backstop.js +1 -0
  203. package/dist/core/runner/task-start-doors.js +6 -3
  204. package/dist/core/runner/terminal-account.d.ts +10 -1
  205. package/dist/core/runner/terminal-account.js +23 -3
  206. package/dist/core/runner/tool-face-overlay.d.ts +2 -11
  207. package/dist/core/runner/tool-face-overlay.js +39 -0
  208. package/dist/core/runner/trim-stretch.js +7 -2
  209. package/dist/core/runner/unreadable-person-rows.d.ts +2 -1
  210. package/dist/core/runner-deps.d.ts +13 -10
  211. package/dist/core/scheduler.d.ts +47 -7
  212. package/dist/core/scheduler.js +19 -7
  213. package/dist/core/secret-env.d.ts +60 -37
  214. package/dist/core/secret-env.js +45 -48
  215. package/dist/core/sensitive-path-policy.js +14 -7
  216. package/dist/core/session-checkout.d.ts +3 -0
  217. package/dist/core/session-checkout.js +1 -0
  218. package/dist/core/session-store.d.ts +12 -6
  219. package/dist/core/session-store.js +26 -6
  220. package/dist/core/session.d.ts +31 -8
  221. package/dist/core/shell-read-silence.js +1 -0
  222. package/dist/core/store-contracts/checkpoint-store-contract.js +17 -0
  223. package/dist/core/store-contracts/peer-task-store-contract.d.ts +21 -0
  224. package/dist/core/store-contracts/peer-task-store-contract.js +516 -0
  225. package/dist/core/store-contracts/session-store-contract.d.ts +15 -2
  226. package/dist/core/store-contracts/session-store-contract.js +87 -3
  227. package/dist/core/store-contracts/workflow-journal-store-contract.d.ts +19 -1
  228. package/dist/core/store-contracts/workflow-journal-store-contract.js +89 -1
  229. package/dist/core/task-event.d.ts +11 -3
  230. package/dist/core/task-notification.d.ts +97 -10
  231. package/dist/core/task-notification.js +129 -5
  232. package/dist/core/task-registry-shared.d.ts +12 -1
  233. package/dist/core/task-registry-shared.js +3 -1
  234. package/dist/core/task-registry-workflow.d.ts +1 -1
  235. package/dist/core/task-registry-workflow.js +9 -1
  236. package/dist/core/task-registry.d.ts +39 -2
  237. package/dist/core/task-registry.js +76 -12
  238. package/dist/core/task-result.d.ts +13 -0
  239. package/dist/core/task-spec-members.d.ts +3 -1
  240. package/dist/core/task-spec-members.js +11 -3
  241. package/dist/core/task-spec.d.ts +57 -23
  242. package/dist/core/tool-catalog-entries.js +4 -0
  243. package/dist/core/tool-face-reader.js +1 -1
  244. package/dist/core/tool-face.d.ts +7 -0
  245. package/dist/core/tool-face.js +1 -0
  246. package/dist/core/tool-mount-facts.d.ts +5 -3
  247. package/dist/core/tool-mount-facts.js +4 -3
  248. package/dist/core/tool-mount-plan.d.ts +7 -3
  249. package/dist/core/tool-mount-plan.js +11 -5
  250. package/dist/core/tool-mount-static.d.ts +2 -2
  251. package/dist/core/tool-mount-static.js +28 -14
  252. package/dist/core/tool-registry.d.ts +33 -1
  253. package/dist/core/tool-registry.js +33 -0
  254. package/dist/core/tool-result-store.d.ts +19 -2
  255. package/dist/core/tool-result-store.js +51 -2
  256. package/dist/core/tool-roster.d.ts +16 -0
  257. package/dist/core/tool-roster.js +6 -0
  258. package/dist/core/tool-spec.d.ts +13 -4
  259. package/dist/core/tools.d.ts +6 -0
  260. package/dist/core/tools.js +1 -1
  261. package/dist/core/user-attachment.d.ts +5 -1
  262. package/dist/core/user-attachment.js +14 -7
  263. package/dist/core/wiring-manifest.d.ts +89 -29
  264. package/dist/core/wiring-manifest.js +44 -4
  265. package/dist/core/workflow-journal-store.d.ts +53 -10
  266. package/dist/core/workflow-journal-store.js +27 -4
  267. package/dist/core/workflow-run-store-contract.js +16 -0
  268. package/dist/core/workflow-run-store.d.ts +9 -7
  269. package/dist/core/workflow-run-store.js +4 -1
  270. package/dist/engine/execution-env/node-execution-env.js +3 -1
  271. package/dist/engine/harness/messages.d.ts +1 -1
  272. package/dist/engine/harness/messages.js +2 -1
  273. package/dist/engine/harness/types.d.ts +24 -1
  274. package/dist/engine/harness/types.js +10 -0
  275. package/dist/engine/llm/types.d.ts +5 -7
  276. package/dist/engine/loop/types.d.ts +2 -0
  277. package/dist/engine/lsp/node-lsp-manager.js +2 -1
  278. package/dist/engine/session/import-validate.js +6 -1
  279. package/dist/engine/session/session.d.ts +15 -2
  280. package/dist/engine/session/session.js +35 -5
  281. package/dist/index.d.ts +27 -12
  282. package/dist/index.js +20 -8
  283. package/dist/orchestration/run-workflow-tool.js +40 -32
  284. package/dist/orchestration/workflow-park-adoption.d.ts +51 -12
  285. package/dist/orchestration/workflow-park-adoption.js +47 -12
  286. package/dist/orchestration/workflow-stop.d.ts +128 -0
  287. package/dist/orchestration/workflow-stop.js +156 -0
  288. package/dist/orchestration/workflow.d.ts +30 -6
  289. package/dist/orchestration/workflow.js +117 -54
  290. package/dist/prompts/manager-recipe.d.ts +18 -0
  291. package/dist/prompts/manager-recipe.js +24 -0
  292. package/dist/stores/file/adoption/marker.d.ts +2 -27
  293. package/dist/stores/file/adoption/marker.js +12 -0
  294. package/dist/stores/file/index.d.ts +1 -1
  295. package/dist/stores/file/index.js +1 -1
  296. package/dist/stores/file/permission-rule-store.d.ts +3 -1
  297. package/dist/stores/file/permission-rule-store.js +0 -1
  298. package/dist/stores/file/workflow-journal-store.d.ts +16 -3
  299. package/dist/stores/file/workflow-journal-store.js +93 -5
  300. package/dist/stores/file/workflow-run-store.d.ts +1 -1
  301. package/dist/tools/artifact/artifact-tool.js +11 -6
  302. package/dist/tools/fs/file-read-check.d.ts +45 -11
  303. package/dist/tools/fs/file-read-check.js +200 -57
  304. package/dist/tools/fs/file-write-check.js +9 -3
  305. package/dist/tools/fs/index.d.ts +8 -7
  306. package/dist/tools/fs/index.js +4 -4
  307. package/dist/tools/fs/judged-reads.d.ts +51 -0
  308. package/dist/tools/fs/judged-reads.js +68 -0
  309. package/dist/tools/fs/read-deny-home.d.ts +1 -1
  310. package/dist/tools/fs/read-deny-home.js +5 -5
  311. package/dist/tools/fs/read-deny.d.ts +33 -8
  312. package/dist/tools/fs/read-deny.js +114 -25
  313. package/dist/tools/fs/safety.d.ts +12 -1
  314. package/dist/tools/fs/safety.js +16 -3
  315. package/dist/tools/fs/shell-read-check.d.ts +25 -5
  316. package/dist/tools/fs/shell-read-check.js +100 -15
  317. package/dist/tools/fs/shell-read-establish.d.ts +9 -0
  318. package/dist/tools/fs/shell-read-establish.js +34 -14
  319. package/dist/tools/fs/shell-read-judge.d.ts +13 -1
  320. package/dist/tools/fs/shell-read-judge.js +26 -7
  321. package/dist/tools/fs/shell-read-plan.d.ts +5 -0
  322. package/dist/tools/fs/shell-read-write-targets.js +17 -9
  323. package/dist/tools/scheduler-store-move.d.ts +74 -0
  324. package/dist/tools/scheduler-store-move.js +103 -0
  325. package/dist/tools/scheduler-tools.d.ts +43 -29
  326. package/dist/tools/scheduler-tools.js +161 -118
  327. package/package.json +2 -2
  328. package/test/export-surface.snapshot.json +173 -3
  329. package/wire-changes/answers/core-stores-sql@7.72.0.json +12 -0
  330. package/wire-changes/answers/core-stores-sql@7.73.0.json +28 -0
  331. package/wire-changes/answers/core@7.72.0.json +84 -0
  332. package/wire-changes/answers/core@7.73.0.json +216 -0
  333. package/wire-changes/answers/mods-kernel@7.72.0.json +7 -0
  334. package/wire-changes/answers/mods-kernel@7.73.0.json +7 -0
  335. package/wire-changes/answers/primitives@7.72.0.json +6 -0
  336. package/wire-changes/answers/primitives@7.73.0.json +12 -0
  337. package/wire-changes/answers/wiki-gate@7.72.0.json +7 -0
  338. package/wire-changes/answers/wiki-gate@7.73.0.json +7 -0
  339. package/wire-changes/core-stores-sql@7.72.0.json +215 -0
  340. package/wire-changes/core-stores-sql@7.73.0.json +326 -0
  341. package/wire-changes/core@7.72.0.json +2426 -0
  342. package/wire-changes/core@7.73.0.json +6480 -0
  343. package/wire-changes/mods-kernel@7.72.0.json +147 -0
  344. package/wire-changes/mods-kernel@7.73.0.json +147 -0
  345. package/wire-changes/primitives@7.72.0.json +143 -0
  346. package/wire-changes/primitives@7.73.0.json +227 -0
  347. package/wire-changes/wiki-gate@7.72.0.json +145 -0
  348. package/wire-changes/wiki-gate@7.73.0.json +145 -0
@@ -10,9 +10,10 @@ import { foreignLine } from "../core/protocol-http-auth.js";
10
10
  import { withDelegationProvenance } from "../core/tool-policy.js";
11
11
  import { LAUNCH_RECEIPT_OWN_WORDS_CLAUSE, launchReceiptNoQuoteClause } from "../agents/launch-receipt-contract.js";
12
12
  import { createHash, randomUUID } from "node:crypto";
13
- import { startWorkflow, WORKFLOW_STORE_WAIT_BOUND_MS, takeWorkflowResumeClaim, releaseWorkflowResumeClaim } from "./workflow.js";
13
+ import { startWorkflow, WORKFLOW_STORE_WAIT_BOUND_MS, takeWorkflowResumeClaims, releaseWorkflowResumeClaims } from "./workflow.js";
14
+ import { workflowStopOf } from "./workflow-stop.js";
14
15
  import { assertJournalStoreGivesClaimsBack, journalKeepsLaunches } from "../core/workflow-journal-store.js";
15
- import { boundedStoreRead, createWorkflowParkAdopter, otherWaitingLine, readWorkflowRunTree, readWorkflowRunTreeWithin, registerWorkflowParkAdopter, workflowLineForkReason, workflowLineTailOf, workflowTreeOverBoundSentence } from "./workflow-park-adoption.js";
16
+ import { boundedStoreRead, createWorkflowParkAdopter, otherWaitingLine, readWorkflowRunTree, readWorkflowRunTreeWithin, registerWorkflowParkAdopter, sameClaimKeys, workflowClaimKeysOf, workflowLineForkReason, workflowLineTailOf, workflowTreeOverBoundSentence } from "./workflow-park-adoption.js";
16
17
  import { settledRunOf } from "../core/workflow-settled-run.js";
17
18
  import { WORKFLOW_AGENT_PARKED_ERROR_CODE, WORKFLOW_STEP_ASKED_AGAIN, firstFailedAgentCodeOf, parkedAgentsOf, workflowMembersOf, workflowParkHolderOf } from "./workflow-types.js";
18
19
  import { memberLedgerClause, memberRefusalsText } from "../core/member-outcome.js";
@@ -140,7 +141,7 @@ function workflowUsageBlock(run) {
140
141
  ...(run.endedAt !== undefined ? { duration_ms: run.endedAt - run.startedAt } : {}),
141
142
  };
142
143
  }
143
- function workflowDiagnostics(runId, journalRef, resumeMiss, record, held) {
144
+ function workflowDiagnostics(runId, journalRef, resumeMiss, record, held, stoppedBy) {
144
145
  const journalTeach = journalRef === undefined
145
146
  ? ""
146
147
  : journalRef.includes("://")
@@ -152,10 +153,13 @@ function workflowDiagnostics(runId, journalRef, resumeMiss, record, held) {
152
153
  return ((record ?? "") +
153
154
  journalTeach +
154
155
  resumeMissTeach +
155
- (held !== undefined
156
- ? ` ${heldStepSentence(held)}.`
157
- : ` To continue after editing the script: re-invoke with resumeFromRunId: "${runId}" (completed agents replay from the journal; only new/changed calls run).`)).trimStart();
156
+ (stoppedBy !== undefined
157
+ ? ` ${workflowStoppedSentence(stoppedBy)}.`
158
+ : held !== undefined
159
+ ? ` ${heldStepSentence(held)}.`
160
+ : ` To continue after editing the script: re-invoke with resumeFromRunId: "${runId}" (completed agents replay from the journal; only new/changed calls run).`)).trimStart();
158
161
  }
162
+ const workflowStoppedSentence = (stoppedBy) => `The workflow was stopped (by ${JSON.stringify(boundedRedactedSummary(stoppedBy, 64))}): no run of it starts another step, so resuming it (resumeFromRunId) is refused — to run the work again, start the workflow again`;
159
163
  const heldStepSentence = (held) => held.holder !== undefined
160
164
  ? `The parked step still belongs to run "${held.holder}": with a person's decision on its card, that run continues from the step; ` +
161
165
  `if the card is no longer waiting (expired, removed, or decided elsewhere), a resume of "${held.holder}" records the step as failed and its script continues`
@@ -188,8 +192,8 @@ const SCRIPT_ERROR_CODES = new Set([
188
192
  "workflow.result_too_large",
189
193
  "workflow.budget_exceeded",
190
194
  ]);
191
- function failureSummary(err, runId, run, held) {
192
- return withUnusedDecisions(failureSummaryOf(err, runId, run, held), run);
195
+ function failureSummary(err, runId, run, held, stoppedBy) {
196
+ return withUnusedDecisions(failureSummaryOf(err, runId, run, held, stoppedBy), run);
193
197
  }
194
198
  const RESUME_REFUSAL_CODES = new Set(["workflow.parked_call_changed", "workflow.park_truth_unreadable", "workflow.park_binding_broken", "workflow.park_requires_run_store"]);
195
199
  function withUnusedDecisions(summary, run) {
@@ -221,7 +225,7 @@ function continuedBeforeSentence(run) {
221
225
  const ended = `${before.status}${before.errorCode !== undefined ? ` (${before.errorCode})` : ""}`;
222
226
  return ` — run "${boundedRedactedSummary(run.resume.fromRunId, 80)}" had already been continued as run "${boundedRedactedSummary(before.runId, 80)}", which ended ${ended}; this run continued from that earlier point, so the steps after it that had not completed there ran again here`;
223
227
  }
224
- function failureSummaryOf(err, runId, run, held) {
228
+ function failureSummaryOf(err, runId, run, held, stoppedBy) {
225
229
  const codeWord = readMember(err, "code");
226
230
  const thrownCode = typeof codeWord === "string" && codeWord !== WORKFLOW_AGENT_PARKED_ERROR_CODE ? codeWord : undefined;
227
231
  const code = run !== undefined ? run.errorCode : thrownCode;
@@ -244,11 +248,13 @@ function failureSummaryOf(err, runId, run, held) {
244
248
  (runId ? `; the diagnostics below name its record (the parked agent's row reads status "parked")` : "") +
245
249
  `; do not re-issue the same call — once a person decides the approval, the decision continues this run from the parked call; you do not resume it, and if it cannot be continued you are told then`);
246
250
  }
247
- const guide = held !== undefined
248
- ? `; which agents failed is in the diagnostics below. ${heldStepSentence(held)}`
249
- : runId
250
- ? `; which agents failed is in the diagnostics below; after fixing, re-invoke with resumeFromRunId: "${runId}" (completed agents replay from the journal)`
251
- : "";
251
+ const guide = stoppedBy !== undefined
252
+ ? `; ${workflowStoppedSentence(stoppedBy)}`
253
+ : held !== undefined
254
+ ? `; which agents failed is in the diagnostics below. ${heldStepSentence(held)}`
255
+ : runId
256
+ ? `; which agents failed is in the diagnostics below; after fixing, re-invoke with resumeFromRunId: "${runId}" (completed agents replay from the journal)`
257
+ : "";
252
258
  const scriptWords = code && SCRIPT_ERROR_CODES.has(code) ? readMember(err, "message") : undefined;
253
259
  if (code && typeof scriptWords === "string") {
254
260
  const msg = egressText("same-principal", scriptWords);
@@ -332,11 +338,11 @@ function claimWithin(p, late) {
332
338
  });
333
339
  });
334
340
  }
335
- async function takeToolResumeClaim(journal, args, what, runId, reportStoreFault) {
341
+ async function takeToolResumeClaim(journal, args, what, runId, reportStoreFault, carriesDecision = false) {
336
342
  const who = what === "record" ? "record of a person's answer" : what;
337
343
  let verdict;
338
344
  try {
339
- verdict = await claimWithin(takeWorkflowResumeClaim(journal, args), (late) => void (late.granted ? releaseWorkflowResumeClaim(journal, args, late.fallback) : undefined));
345
+ verdict = await claimWithin(takeWorkflowResumeClaims(journal, args.keys, args.newRunId, args.scope, carriesDecision), (late) => void (late.granted ? releaseWorkflowResumeClaims(journal, args.keys, args.newRunId, args.scope, late.fallback) : undefined));
340
346
  }
341
347
  catch (err) {
342
348
  reportStoreFault?.(`the ${who}'s resume claim on workflow run ${JSON.stringify(runId)} could not be taken`, err);
@@ -936,14 +942,14 @@ async function mountRunWorkflowTool(d) {
936
942
  return `an approval card of workflow run "${inlineUntrusted(target, 64)}"'s workflow could not be read — not started; resume again once the checkpoint store answers`;
937
943
  if (line.kind === "waiting")
938
944
  return notContinuedRefusalOf(namedResume, "waiting_elsewhere", { waiting: line.lines, decisionIds: heldDecisionIds });
939
- return { root: line.root, target };
945
+ return { keys: workflowClaimKeysOf(tree).keys, target };
940
946
  };
941
947
  const firstLine = await modelLineRefusal();
942
948
  if (typeof firstLine === "string")
943
949
  return structuredError(firstLine);
944
950
  if (firstLine !== undefined)
945
951
  resumeFromRunId = firstLine.target;
946
- const claimKey = continuation !== undefined ? continuation.claimKey : firstLine?.root;
952
+ const claimKeys = continuation !== undefined ? continuation.claimKeys : firstLine?.keys;
947
953
  let sourceLaunch = continuation?.launch;
948
954
  if (continuation === undefined && resumeFromRunId !== undefined && journalKeepsLaunches(d.journalStore)) {
949
955
  const scope = runScope;
@@ -982,17 +988,17 @@ async function mountRunWorkflowTool(d) {
982
988
  let continuationDecisions = continuation?.decisions;
983
989
  const releaseContinuationClaim = () => {
984
990
  if (continuationClaim !== undefined && d.journalStore !== undefined)
985
- void releaseWorkflowResumeClaim(d.journalStore, continuationClaim.args, continuationClaim.fallback);
991
+ void releaseWorkflowResumeClaims(d.journalStore, continuationClaim.args.keys, continuationClaim.args.newRunId, continuationClaim.args.scope, continuationClaim.fallback);
986
992
  };
987
- if (resumeFromRunId !== undefined && claimKey !== undefined && d.journalStore !== undefined && launchRunId !== undefined) {
993
+ if (resumeFromRunId !== undefined && claimKeys !== undefined && d.journalStore !== undefined && launchRunId !== undefined) {
988
994
  const journal = d.journalStore;
989
- const args = { sourceRunId: claimKey, newRunId: launchRunId, scope: resumeScope };
990
- const taken = await takeToolResumeClaim(journal, args, continuation !== undefined ? "continuation" : "resume", resumeFromRunId, reportStoreFault);
995
+ const args = { keys: claimKeys, newRunId: launchRunId, scope: resumeScope };
996
+ const taken = await takeToolResumeClaim(journal, args, continuation !== undefined ? "continuation" : "resume", resumeFromRunId, reportStoreFault, continuation !== undefined || heldDecisionIds.length > 0);
991
997
  if ("refused" in taken)
992
998
  return structuredError(taken.refused);
993
999
  if ("held" in taken) {
994
1000
  if (continuation === undefined)
995
- return structuredError(notContinuedRefusalOf(namedResume ?? resumeFromRunId, "continuing_elsewhere", { ...taken.held, decisionIds: heldDecisionIds }));
1001
+ return structuredError(notContinuedRefusalOf(namedResume ?? resumeFromRunId, taken.held.stoppedBy !== undefined ? "workflow_stopped" : "continuing_elsewhere", { ...taken.held, decisionIds: heldDecisionIds }));
996
1002
  continuation.onClaimHeld(taken.held);
997
1003
  return structuredError("another run already holds this run's resume claim — not started");
998
1004
  }
@@ -1005,7 +1011,7 @@ async function mountRunWorkflowTool(d) {
1005
1011
  catch {
1006
1012
  again = `the records of workflow run "${inlineUntrusted(resumeFromRunId, 64)}"'s workflow could not be read — not started`;
1007
1013
  }
1008
- if (again !== undefined && typeof again !== "string" && (again.root !== claimKey || again.target !== resumeFromRunId)) {
1014
+ if (again !== undefined && typeof again !== "string" && (!sameClaimKeys(again.keys, claimKeys) || again.target !== resumeFromRunId)) {
1009
1015
  again = `the records of workflow run "${inlineUntrusted(namedResume ?? "", 64)}"'s workflow changed while this call took its resume claim (a run of it was continued, removed or created again meanwhile) — not started; call again to continue from what they say now`;
1010
1016
  }
1011
1017
  if (typeof again === "string") {
@@ -1114,7 +1120,7 @@ async function mountRunWorkflowTool(d) {
1114
1120
  workflowDepth: d.workflowDepth,
1115
1121
  launchingTool: tool,
1116
1122
  ...((ctx.toolSelector?.layers ?? d.parentToolCeiling) !== undefined ? { toolCeiling: (ctx.toolSelector?.layers ?? d.parentToolCeiling) } : {}),
1117
- ...(continuationClaim !== undefined ? { resumeClaimKey: continuationClaim.args.sourceRunId } : {}),
1123
+ ...(continuationClaim !== undefined && continuationClaim.args.keys[0] !== undefined ? { resumeClaimKey: continuationClaim.args.keys[0] } : {}),
1118
1124
  ...(namedResume !== undefined && resumeFromRunId !== namedResume ? { resumeAsked: namedResume } : {}),
1119
1125
  });
1120
1126
  }
@@ -1135,6 +1141,7 @@ async function mountRunWorkflowTool(d) {
1135
1141
  description: meta.name ?? meta.description,
1136
1142
  toolUseId: ctx.toolCallId,
1137
1143
  ...(taskOwner !== undefined ? { owner: taskOwner } : {}),
1144
+ ...(sourceTaskId !== undefined && sourceTaskId !== (ctx.sessionId ?? d.originatingSessionId) ? { parentTaskId: sourceTaskId } : {}),
1138
1145
  scope: runScope,
1139
1146
  ...(d.originatingSessionId !== undefined ? { originatingSessionId: d.originatingSessionId } : {}),
1140
1147
  ...occupantStamp(rootOccupantSeat(ctx.rootSessionId ?? d.rootSessionId ?? d.originatingSessionId, ctx, d)),
@@ -1201,7 +1208,7 @@ async function mountRunWorkflowTool(d) {
1201
1208
  summary: completionSummary(meta.name, res.run) + continuedBeforeSentence(res.run),
1202
1209
  result: boundedRedactedSummary(res.result, 4000),
1203
1210
  usage: workflowUsageBlock(res.run),
1204
- diagnostics: workflowDiagnostics(runId, journalLocatorOf(runId, res.run.scope), res.run.resume?.journalEntries === 0, recordOf(res.run)),
1211
+ diagnostics: workflowDiagnostics(runId, journalLocatorOf(runId, res.run.scope), res.run.resume?.journalEntries === 0, recordOf(res.run), undefined, workflowStopOf(handle)),
1205
1212
  completionId: res.run.completionId,
1206
1213
  members: workflowMembersOf(res.run),
1207
1214
  }), async (err) => {
@@ -1213,11 +1220,12 @@ async function mountRunWorkflowTool(d) {
1213
1220
  const failedRun = settledRunOf(handle.done);
1214
1221
  const record = failedRun !== undefined ? recordOf(failedRun) : workflowRecordPickupOf(undefined).line;
1215
1222
  const held = await heldStepOf(failedRun, d.store);
1216
- const summary = failureSummary(err, runId, failedRun, held) + continuedBeforeSentence(failedRun);
1223
+ const stoppedBy = workflowStopOf(handle);
1224
+ const summary = failureSummary(err, runId, failedRun, held, stoppedBy) + continuedBeforeSentence(failedRun);
1217
1225
  const settleId = failedRun?.completionId;
1218
1226
  parts = {
1219
1227
  summary,
1220
- diagnostics: workflowDiagnostics(runId, undefined, undefined, record, held),
1228
+ diagnostics: workflowDiagnostics(runId, undefined, undefined, record, held, stoppedBy),
1221
1229
  ...(settleId !== undefined ? { completionId: settleId } : {}),
1222
1230
  ...(failedRun !== undefined ? { members: workflowMembersOf(failedRun) } : {}),
1223
1231
  ...((code) => (code !== undefined ? { errorCode: code } : {}))(failedRun === undefined ? undefined : workflowNotifiedCodeOf(failedRun)),
@@ -1278,12 +1286,12 @@ async function mountRunWorkflowTool(d) {
1278
1286
  return { refused: launchRefusalText(details?.content) };
1279
1287
  return { runId: details.details.workflowRunId };
1280
1288
  },
1281
- underClaim: async (claimKey, scope, body) => {
1289
+ underClaim: async (claimKeys, scope, body) => {
1282
1290
  const journal = d.journalStore;
1283
1291
  if (journal === undefined)
1284
1292
  return { refused: "no journal store holds this workflow's resume claim" };
1285
- const args = { sourceRunId: claimKey, newRunId: answerRecordClaimHolder(), scope };
1286
- const taken = await takeToolResumeClaim(journal, args, "record", claimKey, reportStoreFault);
1293
+ const args = { keys: claimKeys, newRunId: answerRecordClaimHolder(), scope };
1294
+ const taken = await takeToolResumeClaim(journal, args, "record", claimKeys[0] ?? "", reportStoreFault);
1287
1295
  if ("refused" in taken)
1288
1296
  return { refused: taken.refused };
1289
1297
  if ("held" in taken)
@@ -1292,7 +1300,7 @@ async function mountRunWorkflowTool(d) {
1292
1300
  return { value: await body() };
1293
1301
  }
1294
1302
  finally {
1295
- void releaseWorkflowResumeClaim(journal, args, taken.granted.fallback);
1303
+ void releaseWorkflowResumeClaims(journal, args.keys, args.newRunId, args.scope, taken.granted.fallback);
1296
1304
  }
1297
1305
  },
1298
1306
  waitBoundMs: WORKFLOW_STORE_WAIT_BOUND_MS,
@@ -15,7 +15,7 @@ export interface WorkflowParkDecision {
15
15
  readonly inheritedGate?: InheritedGate;
16
16
  }
17
17
  /** Why a decision did not continue its run — the closed set `workflow.parked_decision_unused` carries as `detail.reason`. */
18
- export declare const WORKFLOW_PARK_UNUSED_REASONS: readonly ["workflow_not_mounted", "entry_unreadable", "record_unreadable", "not_holder", "not_pending", "decision_spent", "launch_unrecorded", "launch_unreadable", "host_changed", "denied", "ask_unanswerable", "call_changed", "launch_refused", "continuing_elsewhere", "card_unresumable", "waiting_elsewhere", "run_not_ended"];
18
+ export declare const WORKFLOW_PARK_UNUSED_REASONS: readonly ["workflow_not_mounted", "entry_unreadable", "record_unreadable", "not_holder", "not_pending", "decision_spent", "launch_unrecorded", "launch_unreadable", "host_changed", "denied", "ask_unanswerable", "call_changed", "launch_refused", "continuing_elsewhere", "card_unresumable", "waiting_elsewhere", "run_not_ended", "workflow_stopped"];
19
19
  export type WorkflowParkUnusedReason = (typeof WORKFLOW_PARK_UNUSED_REASONS)[number];
20
20
  /** What is left to do with a decision a reason answers (#5208): `deliverable` — the same decision stays usable, and a later hand-over of
21
21
  * it is judged again; `decide_again` — only a person's new decision for the card continues the run (this one is spent, or — kept —
@@ -110,6 +110,9 @@ export declare const WORKFLOW_PARK_UNUSED_REASON_CLASS: {
110
110
  readonly run_not_ended: {
111
111
  readonly kept: "deliverable";
112
112
  };
113
+ readonly workflow_stopped: {
114
+ readonly kept: "withdraw";
115
+ };
113
116
  };
114
117
  /** The class of an answer `reason` gave, as {@link WORKFLOW_PARK_UNUSED_REASON_CLASS} reads it — a lookup and nothing else: the row's
115
118
  * `spent` class when `spent` is `true`, its `kept` class when it is `false`. Undefined — no guess, never the other arm — for a word
@@ -218,6 +221,9 @@ export type WorkflowParkAdoption = {
218
221
  /** `continuing_elsewhere`: the store answered a remaining time for the claim that does not read — no instant is named, and
219
222
  * the sentence says so. Absent otherwise. */
220
223
  readonly claimLapseUnreadable?: true;
224
+ /** `workflow_stopped`: who stopped the workflow, as the journal store reports its stop (`ResumeClaimAnswer.stopped.by`). Not on
225
+ * the notice; the sentence reads it. */
226
+ readonly stoppedBy?: string;
221
227
  /** `waiting_elsewhere`: the lines of the workflow that wait and hold this run off — each line's head run and what it waits
222
228
  * on ({@link WorkflowWaitingLine}). The notice's detail carries their runs as `holder` (the run, or every run when more
223
229
  * than one line waits, as for a fork); a host finds each card by the holder law. */
@@ -260,10 +266,11 @@ export type WorkflowParkAdoption = {
260
266
  readonly why?: string;
261
267
  };
262
268
  /** What a refused resume claim tells of its hold: the run it is held for and when the store's expiry frees it, each when the
263
- * store said — the members `continuing_elsewhere` carries. */
269
+ * store said — the members `continuing_elsewhere` carries; or, for a workflow that was stopped, who stopped it (`stoppedBy`, the
270
+ * member `workflow_stopped` carries: a stop holds the claim for good, for no run). */
264
271
  export type WorkflowClaimHeld = Pick<Extract<WorkflowParkAdoption, {
265
272
  kind: "unused";
266
- }>, "claimExpiresAt" | "claimLapseUnreadable" | "heldForAnswer"> & {
273
+ }>, "claimExpiresAt" | "claimLapseUnreadable" | "heldForAnswer" | "stoppedBy"> & {
267
274
  readonly holder?: string;
268
275
  };
269
276
  /** What the remaining time a refused resume claim's answer carries tells ({@link claimRemainingOf}): `unsaid` — the store
@@ -290,10 +297,14 @@ export declare function claimRemainingOf(answer: {
290
297
  export declare function answerRecordClaimHolder(): string;
291
298
  export declare function isAnswerRecordClaimHolder(holder: string | undefined): boolean;
292
299
  /** The hold a refused claim's verdict tells ({@link WorkflowClaimHeld}), its remaining time as {@link claimRemainingOf} read it; a
293
- * holder that records a person's answer is no run, and is told as that ({@link isAnswerRecordClaimHolder}: `heldForAnswer`). */
300
+ * holder that records a person's answer is no run, and is told as that ({@link isAnswerRecordClaimHolder}: `heldForAnswer`); a
301
+ * stop the store reports (`stopped`) is told as that alone — it is no run's hold and never lapses. */
294
302
  export declare function claimHeldOf(verdict: {
295
303
  readonly holder?: string;
296
304
  readonly lapse?: WorkflowClaimLapse;
305
+ readonly stopped?: {
306
+ readonly by: string;
307
+ };
297
308
  }): WorkflowClaimHeld;
298
309
  /** The words a refusal says, in brackets, of a claim whose store answered a remaining time that does not read. */
299
310
  export declare const CLAIM_REMAINING_UNREADABLE_NOTE = "the journal store answered a remaining time for the claim that does not read, so no time is named";
@@ -348,8 +359,8 @@ export interface WorkflowContinuation {
348
359
  readonly decisionId: string;
349
360
  readonly inheritedGate?: InheritedGate;
350
361
  }>;
351
- /** The root of `fromRunId`'s tree ({@link workflowTreeOf}) — what the workflow's resume claim is keyed by. */
352
- readonly claimKey: string;
362
+ /** The keys the workflow's resume claim is taken under ({@link workflowClaimKeysOf} of `fromRunId`'s tree): its root first. */
363
+ readonly claimKeys: readonly string[];
353
364
  }
354
365
  /** The seats the Workflow tool's closure hands its adopter. Every seat that reads the call's context reads the one the leg
355
366
  * hands (`WorkflowParkAdoptionLeg.ctxOf`): the context a model's own call of this leg is run with, so the continuation's
@@ -383,10 +394,11 @@ export interface WorkflowParkAdopterSeats {
383
394
  } | {
384
395
  readonly superseded: true;
385
396
  }>;
386
- /** Hold the workflow's resume claim — keyed by `claimKey` (its tree's root) in `scope`, taken as the launch takes it, no run
387
- * started under it — while `body` runs, and give it back once `body` has settled: `value`, what `body` answered; `claimHeld`,
388
- * the claim another run holds (as the store told it); `refused`, a store that threw or did not answer in time (`body` not run). */
389
- readonly underClaim: <T>(claimKey: string, scope: string, body: () => Promise<T>) => Promise<{
397
+ /** Hold the workflow's resume claim — under `claimKeys` ({@link workflowClaimKeysOf}) in `scope`, taken as the launch takes it, no
398
+ * run started under it — while `body` runs, and give it back once `body` has settled: `value`, what `body` answered; `claimHeld`,
399
+ * the claim another run holds or a stop (as the store told it); `refused`, a store that threw or did not answer in time (`body`
400
+ * not run). */
401
+ readonly underClaim: <T>(claimKeys: readonly string[], scope: string, body: () => Promise<T>) => Promise<{
390
402
  readonly value: T;
391
403
  } | {
392
404
  readonly claimHeld: WorkflowClaimHeld;
@@ -481,6 +493,9 @@ declare const WORKFLOW_RUN_TREE: unique symbol;
481
493
  export interface WorkflowRunTree {
482
494
  readonly root: WorkflowRun;
483
495
  readonly records: readonly WorkflowRun[];
496
+ /** The id the root names as its source when the reader found a record under it that is another creation (the source was removed and
497
+ * the id used again): that id now names another workflow's run. */
498
+ readonly sourceRecreated?: string;
484
499
  readonly [WORKFLOW_RUN_TREE]: true;
485
500
  }
486
501
  /**
@@ -492,6 +507,30 @@ export interface WorkflowRunTree {
492
507
  * judging whether a card is still waited on, reads the whole tree: {@link readWorkflowRunTree}.
493
508
  */
494
509
  export declare function workflowRunTreeOfOne(run: WorkflowRun): WorkflowRunTree;
510
+ /**
511
+ * The names a workflow's tree answers to on the journal store's claim table (#5156): the keys its resume claim is taken under and a stop
512
+ * writes its tombstone on — the tree's root first, then the tree id the root records when it is another id (a root whose own edge up
513
+ * does not hold: its source was removed). A root that names no source is its own tree id (one key). A root that names a source it does
514
+ * not reach and records no tree id (an older engine's record, its line broken) has no tree id: `fragment`, and the root alone is its
515
+ * key — a stop of it stops that part of the workflow only. So is a tree id that the reader found used again by another workflow's run
516
+ * (`sourceRecreated`): that id is the other workflow's key now. Every reader that takes, re-takes or stops the claim reads it here.
517
+ */
518
+ export declare function workflowClaimKeysOf(tree: WorkflowRunTree): {
519
+ readonly keys: readonly string[];
520
+ readonly fragment: boolean;
521
+ };
522
+ /** The one judgment of whether a park a run's record names binds a checkpoint row — read by a resume's admission before it acts on the
523
+ * row and by a stop before it withdraws the card: why it does not (the record names no token or no session for it; the store answered a
524
+ * row under another token; the row belongs to another session), or `undefined` when it binds. Without `row`, the key alone is judged. */
525
+ export declare function parkBindingFault(key: {
526
+ readonly token: string;
527
+ readonly sessionId: string;
528
+ }, row?: {
529
+ readonly token: string;
530
+ readonly sessionId: string;
531
+ }): string | undefined;
532
+ /** Whether two key lists ({@link workflowClaimKeysOf}) name the same keys in the same order. */
533
+ export declare function sameClaimKeys(a: readonly string[], b: readonly string[]): boolean;
495
534
  /** The record of `id` in `tree`, if it is one of its runs. */
496
535
  export declare function workflowRunInTree(tree: WorkflowRunTree, id: string): WorkflowRun | undefined;
497
536
  /** The runs of `tree` below `id` (its successors, theirs, …), in the order the tree holds them. */
@@ -638,9 +677,9 @@ export declare function workflowParkUnusedSentence(o: Extract<WorkflowParkAdopti
638
677
  }>): string;
639
678
  /** The refusal of a model's `Workflow({ resumeFromRunId })` call for a run that is not continued: the reason's own sentence (the
640
679
  * engine's continuation tells the person the same one), with the decision half only when the call carried decisions. */
641
- export declare function notContinuedRefusalOf(runId: string, reason: "launch_unreadable" | "waiting_elsewhere" | "continuing_elsewhere", more?: Pick<Extract<WorkflowParkAdoption, {
680
+ export declare function notContinuedRefusalOf(runId: string, reason: "launch_unreadable" | "waiting_elsewhere" | "continuing_elsewhere" | "workflow_stopped", more?: Pick<Extract<WorkflowParkAdoption, {
642
681
  kind: "unused";
643
- }>, "code" | "holder" | "waiting" | "claimExpiresAt" | "claimLapseUnreadable" | "heldForAnswer"> & {
682
+ }>, "code" | "holder" | "waiting" | "claimExpiresAt" | "claimLapseUnreadable" | "heldForAnswer" | "stoppedBy"> & {
644
683
  readonly decisionIds?: readonly string[];
645
684
  }): string;
646
685
  /** Why a run of a tree past {@link WORKFLOW_TREE_RUNS_MAX} is not continued, and the way out — one wording for the model's own
@@ -26,6 +26,7 @@ export const WORKFLOW_PARK_UNUSED_REASONS = Object.freeze([
26
26
  "card_unresumable",
27
27
  "waiting_elsewhere",
28
28
  "run_not_ended",
29
+ "workflow_stopped",
29
30
  ]);
30
31
  function frozenRows(table) {
31
32
  for (const row of Object.values(table))
@@ -50,6 +51,7 @@ export const WORKFLOW_PARK_UNUSED_REASON_CLASS = frozenRows({
50
51
  card_unresumable: { kept: "deliverable", spent: "start_over", spentWhen: "terminal" },
51
52
  waiting_elsewhere: { kept: "deliverable" },
52
53
  run_not_ended: { kept: "deliverable" },
54
+ workflow_stopped: { kept: "withdraw" },
53
55
  });
54
56
  export function workflowParkUnusedClassOf(reason, spent) {
55
57
  if (typeof spent !== "boolean" || typeof reason !== "string" || !Object.hasOwn(WORKFLOW_PARK_UNUSED_REASON_CLASS, reason))
@@ -58,7 +60,7 @@ export function workflowParkUnusedClassOf(reason, spent) {
58
60
  return spent ? row.spent : row.kept;
59
61
  }
60
62
  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"]);
63
+ const UNMARKED_REASONS = new Set(["workflow_not_mounted", "entry_unreadable", "record_unreadable", "run_not_ended", "not_pending", "not_holder", "workflow_stopped"]);
62
64
  function settlesDecision(o) {
63
65
  if (!Object.hasOwn(WORKFLOW_PARK_UNUSED_REASON_CLASS, o.reason))
64
66
  return false;
@@ -171,6 +173,8 @@ export function isAnswerRecordClaimHolder(holder) {
171
173
  return holder !== undefined && holder.startsWith(ANSWER_RECORD_CLAIM_HOLDER_PREFIX);
172
174
  }
173
175
  export function claimHeldOf(verdict) {
176
+ if (verdict.stopped !== undefined)
177
+ return { stoppedBy: verdict.stopped.by };
174
178
  const lapse = verdict.lapse;
175
179
  return {
176
180
  ...(isAnswerRecordClaimHolder(verdict.holder) ? { heldForAnswer: true } : verdict.holder !== undefined ? { holder: verdict.holder } : {}),
@@ -250,10 +254,31 @@ export function isContinuationOf(a, b) {
250
254
  return typeof named !== "string" || workflowRunCreationIdOf(a) === named;
251
255
  }
252
256
  const WORKFLOW_RUN_TREE = Symbol("WorkflowRunTree");
253
- const mintTree = (root, records) => ({ root, records, [WORKFLOW_RUN_TREE]: true });
257
+ const mintTree = (root, records, sourceRecreated) => ({ root, records, ...(sourceRecreated !== undefined ? { sourceRecreated } : {}), [WORKFLOW_RUN_TREE]: true });
254
258
  export function workflowRunTreeOfOne(run) {
255
259
  return mintTree(run, [run]);
256
260
  }
261
+ export function workflowClaimKeysOf(tree) {
262
+ const root = tree.root;
263
+ const recorded = root.treeId;
264
+ const named = typeof recorded === "string" ? recorded : resumedFromOf(root) === undefined ? root.id : undefined;
265
+ const treeId = named !== undefined && named === tree.sourceRecreated ? undefined : named;
266
+ return { keys: treeId === undefined || treeId === root.id ? [root.id] : [root.id, treeId], fragment: treeId === undefined };
267
+ }
268
+ export function parkBindingFault(key, row) {
269
+ if (key.token === "" || key.sessionId === "")
270
+ return "the record names no token or no session for it";
271
+ if (row === undefined)
272
+ return undefined;
273
+ if (row.token !== key.token)
274
+ return "the checkpoint store answered a row under another token";
275
+ if (row.sessionId !== key.sessionId)
276
+ return "the checkpoint belongs to another session than the parked row";
277
+ return undefined;
278
+ }
279
+ export function sameClaimKeys(a, b) {
280
+ return a.length === b.length && a.every((k, i) => k === b[i]);
281
+ }
257
282
  export function workflowRunInTree(tree, id) {
258
283
  return tree.records.find((r) => r.id === id);
259
284
  }
@@ -314,6 +339,7 @@ export async function readWorkflowRunTreeWithin(store, runId, scope, within, sel
314
339
  let at = await read(runId);
315
340
  if (at === "unreadable" || at === null)
316
341
  return "unreadable";
342
+ let sourceRecreated;
317
343
  for (;;) {
318
344
  line.push(at);
319
345
  const up = resumedFromOf(at);
@@ -324,8 +350,11 @@ export async function readWorkflowRunTreeWithin(store, runId, scope, within, sel
324
350
  const source = await read(up);
325
351
  if (source === "unreadable")
326
352
  return "unreadable";
327
- if (source === null || !isContinuationOf(source, at))
353
+ if (source === null || !isContinuationOf(source, at)) {
354
+ if (source !== null)
355
+ sourceRecreated = up;
328
356
  break;
357
+ }
329
358
  if (line.length >= WORKFLOW_TREE_RUNS_MAX)
330
359
  return "over_bound";
331
360
  at = source;
@@ -373,7 +402,7 @@ export async function readWorkflowRunTreeWithin(store, runId, scope, within, sel
373
402
  if (down === undefined || workflowRunCreationIdOf(down) !== workflowRunCreationIdOf(r))
374
403
  return "unreadable";
375
404
  }
376
- return mintTree(root, records);
405
+ return mintTree(root, records, sourceRecreated);
377
406
  }
378
407
  export async function otherWaitingLine(tree, parkStore, fromRunId, within) {
379
408
  const records = tree.records;
@@ -731,9 +760,11 @@ export function createWorkflowParkAdopter(seats) {
731
760
  const line = await otherWaitingLine(over, parkStore, x.id, within);
732
761
  return line.kind === "unreadable" ? unusedCarried("record_unreadable") : line.kind === "waiting" ? unusedCarried("waiting_elsewhere", { waiting: line.lines }) : line.root;
733
762
  };
734
- const claimKey = await lineOf(tree);
735
- if (typeof claimKey !== "string")
736
- return told(claimKey);
763
+ const line0 = await lineOf(tree);
764
+ if (typeof line0 !== "string")
765
+ return told(line0);
766
+ const claimKeys = workflowClaimKeysOf(tree).keys;
767
+ const sameTree = (over) => sameClaimKeys(workflowClaimKeysOf(over).keys, claimKeys);
737
768
  if (x.errorCode !== WORKFLOW_AGENT_PARKED_ERROR_CODE)
738
769
  return unusedCarried("record_unreadable");
739
770
  let launch;
@@ -801,14 +832,14 @@ export function createWorkflowParkAdopter(seats) {
801
832
  const line = await lineOf(judgedTree);
802
833
  if (typeof line !== "string")
803
834
  superseded = line;
804
- else if (line !== claimKey)
835
+ else if (!sameTree(judgedTree))
805
836
  superseded = unusedCarried("record_unreadable");
806
837
  return superseded === undefined ? carried.map(({ entry }) => decisionOf(entry)) : false;
807
838
  };
808
839
  const deniedUnderClaim = async (layer) => {
809
840
  if ((await rejudge()) === false || carried.length === 0)
810
841
  return undefined;
811
- if (judgedTree.root.id !== claimKey) {
842
+ if (!sameTree(judgedTree)) {
812
843
  superseded = unusedCarried("record_unreadable");
813
844
  return undefined;
814
845
  }
@@ -844,7 +875,9 @@ export function createWorkflowParkAdopter(seats) {
844
875
  }
845
876
  if (judged.kind === "denied" && judged.explicit) {
846
877
  const layer = judged.layer;
847
- const under = await seats.underClaim(claimKey, scope, () => deniedUnderClaim(layer));
878
+ const under = await seats.underClaim(claimKeys, scope, () => deniedUnderClaim(layer));
879
+ if ("claimHeld" in under && under.claimHeld.stoppedBy !== undefined)
880
+ return unusedCarried("workflow_stopped", { stoppedBy: under.claimHeld.stoppedBy });
848
881
  if ("claimHeld" in under)
849
882
  return unusedCarried("continuing_elsewhere", { ...under.claimHeld, answerUnrecorded: true });
850
883
  if ("refused" in under)
@@ -860,7 +893,7 @@ export function createWorkflowParkAdopter(seats) {
860
893
  }
861
894
  let started;
862
895
  try {
863
- started = await seats.launch({ fromRunId: runId, launch, decisions: carried.map(({ entry }) => decisionOf(entry)), claimKey }, ctx, confirm);
896
+ started = await seats.launch({ fromRunId: runId, launch, decisions: carried.map(({ entry }) => decisionOf(entry)), claimKeys }, ctx, confirm);
864
897
  }
865
898
  catch (e) {
866
899
  started = { refused: `the continuation's launch threw ${storeErrorClassOf(e)}` };
@@ -869,7 +902,7 @@ export function createWorkflowParkAdopter(seats) {
869
902
  if ("refused" in started)
870
903
  return told(unusedCarried("launch_refused", { why: neutral(started.refused, WHY_ECHO_MAX) }));
871
904
  if ("claimHeld" in started)
872
- return told(unusedCarried("continuing_elsewhere", started.claimHeld));
905
+ return told(started.claimHeld.stoppedBy !== undefined ? unusedCarried("workflow_stopped", { stoppedBy: started.claimHeld.stoppedBy }) : unusedCarried("continuing_elsewhere", started.claimHeld));
873
906
  if ("superseded" in started)
874
907
  return supersededAnswer();
875
908
  const stepDenied = carried.some((c) => isObject(c.entry.outcome) && c.entry.outcome.decision === "deny");
@@ -952,6 +985,8 @@ export function workflowParkUnusedSentence(o) {
952
985
  const echo = (s) => `"${neutral(s)}"`;
953
986
  const waiting = "The approval card is still waiting";
954
987
  switch (o.reason) {
988
+ case "workflow_stopped":
989
+ return `the workflow was stopped${o.stoppedBy !== undefined ? ` (by ${echo(o.stoppedBy)})` : ""}: it does not run another step, so this decision continues nothing and nothing was started. Nothing is left to do for this decision; to run the work again, start the workflow again`;
955
990
  case "workflow_not_mounted":
956
991
  return `this run of the session cannot start workflows. ${waiting}, and the decision is kept for a later run of the session that can`;
957
992
  case "entry_unreadable":