@caupulican/pi-adaptative 0.81.39 → 0.81.41

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 (884) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/README.md +2 -0
  3. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts +2 -0
  4. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts.map +1 -1
  5. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js +3 -0
  6. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js.map +1 -1
  7. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.ts +4 -0
  8. package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts +9 -0
  9. package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -1
  10. package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +290 -107
  11. package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -1
  12. package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +357 -122
  13. package/dist/bundled-resources/skills/tool-call-repair/references/repair-catalogue.md +2 -2
  14. package/dist/cli/args.d.ts +4 -0
  15. package/dist/cli/args.d.ts.map +1 -1
  16. package/dist/cli/args.js +31 -1
  17. package/dist/cli/args.js.map +1 -1
  18. package/dist/core/agent-directory-layout.d.ts +15 -0
  19. package/dist/core/agent-directory-layout.d.ts.map +1 -0
  20. package/dist/core/agent-directory-layout.js +72 -0
  21. package/dist/core/agent-directory-layout.js.map +1 -0
  22. package/dist/core/agent-paths.d.ts +25 -2
  23. package/dist/core/agent-paths.d.ts.map +1 -1
  24. package/dist/core/agent-paths.js +79 -4
  25. package/dist/core/agent-paths.js.map +1 -1
  26. package/dist/core/agent-session-contracts.d.ts +293 -0
  27. package/dist/core/agent-session-contracts.d.ts.map +1 -0
  28. package/dist/core/agent-session-contracts.js +26 -0
  29. package/dist/core/agent-session-contracts.js.map +1 -0
  30. package/dist/core/agent-session-runtime.d.ts +52 -8
  31. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  32. package/dist/core/agent-session-runtime.js +400 -79
  33. package/dist/core/agent-session-runtime.js.map +1 -1
  34. package/dist/core/agent-session-services.d.ts +1 -0
  35. package/dist/core/agent-session-services.d.ts.map +1 -1
  36. package/dist/core/agent-session-services.js +1 -0
  37. package/dist/core/agent-session-services.js.map +1 -1
  38. package/dist/core/agent-session.d.ts +74 -518
  39. package/dist/core/agent-session.d.ts.map +1 -1
  40. package/dist/core/agent-session.js +370 -1432
  41. package/dist/core/agent-session.js.map +1 -1
  42. package/dist/core/auth-storage.d.ts.map +1 -1
  43. package/dist/core/auth-storage.js +3 -1
  44. package/dist/core/auth-storage.js.map +1 -1
  45. package/dist/core/autonomy/approval-gate.d.ts +3 -2
  46. package/dist/core/autonomy/approval-gate.d.ts.map +1 -1
  47. package/dist/core/autonomy/approval-gate.js +6 -28
  48. package/dist/core/autonomy/approval-gate.js.map +1 -1
  49. package/dist/core/autonomy/bounded-completion.d.ts +1 -1
  50. package/dist/core/autonomy/bounded-completion.d.ts.map +1 -1
  51. package/dist/core/autonomy/bounded-completion.js +1 -1
  52. package/dist/core/autonomy/bounded-completion.js.map +1 -1
  53. package/dist/core/autonomy/contracts.d.ts +20 -12
  54. package/dist/core/autonomy/contracts.d.ts.map +1 -1
  55. package/dist/core/autonomy/contracts.js.map +1 -1
  56. package/dist/core/autonomy/foreground-envelope.d.ts +8 -2
  57. package/dist/core/autonomy/foreground-envelope.d.ts.map +1 -1
  58. package/dist/core/autonomy/foreground-envelope.js +8 -25
  59. package/dist/core/autonomy/foreground-envelope.js.map +1 -1
  60. package/dist/core/autonomy/gates.d.ts.map +1 -1
  61. package/dist/core/autonomy/gates.js +8 -10
  62. package/dist/core/autonomy/gates.js.map +1 -1
  63. package/dist/core/autonomy/lane-private-paths.d.ts +2 -0
  64. package/dist/core/autonomy/lane-private-paths.d.ts.map +1 -0
  65. package/dist/core/autonomy/lane-private-paths.js +16 -0
  66. package/dist/core/autonomy/lane-private-paths.js.map +1 -0
  67. package/dist/core/autonomy/lane-tool-surface.d.ts +10 -0
  68. package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
  69. package/dist/core/autonomy/lane-tool-surface.js +48 -9
  70. package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
  71. package/dist/core/autonomy/lane-tracker.d.ts +14 -0
  72. package/dist/core/autonomy/lane-tracker.d.ts.map +1 -1
  73. package/dist/core/autonomy/lane-tracker.js +38 -0
  74. package/dist/core/autonomy/lane-tracker.js.map +1 -1
  75. package/dist/core/autonomy/risk-assessment.d.ts +1 -2
  76. package/dist/core/autonomy/risk-assessment.d.ts.map +1 -1
  77. package/dist/core/autonomy/risk-assessment.js +1 -123
  78. package/dist/core/autonomy/risk-assessment.js.map +1 -1
  79. package/dist/core/autonomy/session-lane-record.d.ts +4 -4
  80. package/dist/core/autonomy/session-lane-record.d.ts.map +1 -1
  81. package/dist/core/autonomy/session-lane-record.js +16 -29
  82. package/dist/core/autonomy/session-lane-record.js.map +1 -1
  83. package/dist/core/autonomy/telemetry-events.d.ts +1 -1
  84. package/dist/core/autonomy/telemetry-events.d.ts.map +1 -1
  85. package/dist/core/autonomy/telemetry-events.js +1 -1
  86. package/dist/core/autonomy/telemetry-events.js.map +1 -1
  87. package/dist/core/autonomy-telemetry.d.ts +7 -7
  88. package/dist/core/autonomy-telemetry.d.ts.map +1 -1
  89. package/dist/core/autonomy-telemetry.js +9 -9
  90. package/dist/core/autonomy-telemetry.js.map +1 -1
  91. package/dist/core/background-lane-controller.d.ts +56 -236
  92. package/dist/core/background-lane-controller.d.ts.map +1 -1
  93. package/dist/core/background-lane-controller.js +141 -1273
  94. package/dist/core/background-lane-controller.js.map +1 -1
  95. package/dist/core/bedrock-sso-login.d.ts +16 -0
  96. package/dist/core/bedrock-sso-login.d.ts.map +1 -0
  97. package/dist/core/bedrock-sso-login.js +98 -0
  98. package/dist/core/bedrock-sso-login.js.map +1 -0
  99. package/dist/core/capability-contract.d.ts +4 -0
  100. package/dist/core/capability-contract.d.ts.map +1 -0
  101. package/dist/core/capability-contract.js +28 -0
  102. package/dist/core/capability-contract.js.map +1 -0
  103. package/dist/core/compaction-controller.d.ts +90 -0
  104. package/dist/core/compaction-controller.d.ts.map +1 -0
  105. package/dist/core/compaction-controller.js +452 -0
  106. package/dist/core/compaction-controller.js.map +1 -0
  107. package/dist/core/compaction-support.d.ts +13 -17
  108. package/dist/core/compaction-support.d.ts.map +1 -1
  109. package/dist/core/compaction-support.js +3 -3
  110. package/dist/core/compaction-support.js.map +1 -1
  111. package/dist/core/context/context-artifacts.d.ts +6 -2
  112. package/dist/core/context/context-artifacts.d.ts.map +1 -1
  113. package/dist/core/context/context-artifacts.js +34 -2
  114. package/dist/core/context/context-artifacts.js.map +1 -1
  115. package/dist/core/context/context-store-retention.d.ts +8 -2
  116. package/dist/core/context/context-store-retention.d.ts.map +1 -1
  117. package/dist/core/context/context-store-retention.js +158 -35
  118. package/dist/core/context/context-store-retention.js.map +1 -1
  119. package/dist/core/context/okf-memory.d.ts.map +1 -1
  120. package/dist/core/context/okf-memory.js +9 -11
  121. package/dist/core/context/okf-memory.js.map +1 -1
  122. package/dist/core/context/sqlite-runtime-index.d.ts.map +1 -1
  123. package/dist/core/context/sqlite-runtime-index.js +6 -8
  124. package/dist/core/context/sqlite-runtime-index.js.map +1 -1
  125. package/dist/core/context-gc.d.ts +3 -0
  126. package/dist/core/context-gc.d.ts.map +1 -1
  127. package/dist/core/context-gc.js +10 -5
  128. package/dist/core/context-gc.js.map +1 -1
  129. package/dist/core/context-pipeline.d.ts +1 -1
  130. package/dist/core/context-pipeline.d.ts.map +1 -1
  131. package/dist/core/context-pipeline.js +16 -37
  132. package/dist/core/context-pipeline.js.map +1 -1
  133. package/dist/core/cost/cost-summary.d.ts.map +1 -1
  134. package/dist/core/cost/cost-summary.js +5 -3
  135. package/dist/core/cost/cost-summary.js.map +1 -1
  136. package/dist/core/cost/daily-usage.d.ts.map +1 -1
  137. package/dist/core/cost/daily-usage.js +4 -5
  138. package/dist/core/cost/daily-usage.js.map +1 -1
  139. package/dist/core/default-tool-surface.d.ts.map +1 -1
  140. package/dist/core/default-tool-surface.js +2 -0
  141. package/dist/core/default-tool-surface.js.map +1 -1
  142. package/dist/core/delegation/managed-lane-controller.d.ts +34 -0
  143. package/dist/core/delegation/managed-lane-controller.d.ts.map +1 -0
  144. package/dist/core/delegation/managed-lane-controller.js +217 -0
  145. package/dist/core/delegation/managed-lane-controller.js.map +1 -0
  146. package/dist/core/delegation/session-worker-claim.d.ts +44 -0
  147. package/dist/core/delegation/session-worker-claim.d.ts.map +1 -0
  148. package/dist/core/delegation/session-worker-claim.js +98 -0
  149. package/dist/core/delegation/session-worker-claim.js.map +1 -0
  150. package/dist/core/delegation/worker-actions.d.ts +7 -5
  151. package/dist/core/delegation/worker-actions.d.ts.map +1 -1
  152. package/dist/core/delegation/worker-actions.js +20 -4
  153. package/dist/core/delegation/worker-actions.js.map +1 -1
  154. package/dist/core/delegation/{worker-result.d.ts → worker-claim.d.ts} +13 -13
  155. package/dist/core/delegation/worker-claim.d.ts.map +1 -0
  156. package/dist/core/delegation/{worker-result.js → worker-claim.js} +61 -51
  157. package/dist/core/delegation/worker-claim.js.map +1 -0
  158. package/dist/core/delegation/worker-delegation-controller.d.ts +110 -0
  159. package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -0
  160. package/dist/core/delegation/worker-delegation-controller.js +861 -0
  161. package/dist/core/delegation/worker-delegation-controller.js.map +1 -0
  162. package/dist/core/delegation/worker-delegation-request.d.ts +11 -0
  163. package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -0
  164. package/dist/core/delegation/worker-delegation-request.js +2 -0
  165. package/dist/core/delegation/worker-delegation-request.js.map +1 -0
  166. package/dist/core/delegation/worker-dispatch-scheduler.d.ts +40 -0
  167. package/dist/core/delegation/worker-dispatch-scheduler.d.ts.map +1 -0
  168. package/dist/core/delegation/worker-dispatch-scheduler.js +93 -0
  169. package/dist/core/delegation/worker-dispatch-scheduler.js.map +1 -0
  170. package/dist/core/delegation/worker-execution-policy.d.ts +62 -0
  171. package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -0
  172. package/dist/core/delegation/worker-execution-policy.js +160 -0
  173. package/dist/core/delegation/worker-execution-policy.js.map +1 -0
  174. package/dist/core/delegation/worker-lane-projection.d.ts +14 -0
  175. package/dist/core/delegation/worker-lane-projection.d.ts.map +1 -0
  176. package/dist/core/delegation/worker-lane-projection.js +100 -0
  177. package/dist/core/delegation/worker-lane-projection.js.map +1 -0
  178. package/dist/core/delegation/worker-lifecycle.d.ts +97 -0
  179. package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -0
  180. package/dist/core/delegation/worker-lifecycle.js +339 -0
  181. package/dist/core/delegation/worker-lifecycle.js.map +1 -0
  182. package/dist/core/delegation/worker-notification-coordinator.d.ts +36 -0
  183. package/dist/core/delegation/worker-notification-coordinator.d.ts.map +1 -0
  184. package/dist/core/delegation/worker-notification-coordinator.js +90 -0
  185. package/dist/core/delegation/worker-notification-coordinator.js.map +1 -0
  186. package/dist/core/delegation/worker-profile-resolver.d.ts +55 -0
  187. package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -0
  188. package/dist/core/delegation/worker-profile-resolver.js +113 -0
  189. package/dist/core/delegation/worker-profile-resolver.js.map +1 -0
  190. package/dist/core/delegation/worker-runner.d.ts +25 -14
  191. package/dist/core/delegation/worker-runner.d.ts.map +1 -1
  192. package/dist/core/delegation/worker-runner.js +122 -53
  193. package/dist/core/delegation/worker-runner.js.map +1 -1
  194. package/dist/core/delegation/worker-task-label.d.ts +3 -0
  195. package/dist/core/delegation/worker-task-label.d.ts.map +1 -0
  196. package/dist/core/delegation/worker-task-label.js +11 -0
  197. package/dist/core/delegation/worker-task-label.js.map +1 -0
  198. package/dist/core/doctor.d.ts +8 -0
  199. package/dist/core/doctor.d.ts.map +1 -1
  200. package/dist/core/doctor.js +32 -1
  201. package/dist/core/doctor.js.map +1 -1
  202. package/dist/core/extension-import-authority.d.ts +6 -0
  203. package/dist/core/extension-import-authority.d.ts.map +1 -0
  204. package/dist/core/extension-import-authority.js +10 -0
  205. package/dist/core/extension-import-authority.js.map +1 -0
  206. package/dist/core/extensions/index.d.ts +1 -1
  207. package/dist/core/extensions/index.d.ts.map +1 -1
  208. package/dist/core/extensions/index.js.map +1 -1
  209. package/dist/core/extensions/loader.d.ts +5 -1
  210. package/dist/core/extensions/loader.d.ts.map +1 -1
  211. package/dist/core/extensions/loader.js +52 -18
  212. package/dist/core/extensions/loader.js.map +1 -1
  213. package/dist/core/extensions/runner.d.ts +3 -0
  214. package/dist/core/extensions/runner.d.ts.map +1 -1
  215. package/dist/core/extensions/runner.js +20 -5
  216. package/dist/core/extensions/runner.js.map +1 -1
  217. package/dist/core/extensions/stale-context.d.ts +2 -0
  218. package/dist/core/extensions/stale-context.d.ts.map +1 -0
  219. package/dist/core/extensions/stale-context.js +2 -0
  220. package/dist/core/extensions/stale-context.js.map +1 -0
  221. package/dist/core/extensions/storage.d.ts +8 -0
  222. package/dist/core/extensions/storage.d.ts.map +1 -0
  223. package/dist/core/extensions/storage.js +28 -0
  224. package/dist/core/extensions/storage.js.map +1 -0
  225. package/dist/core/extensions/types.d.ts +78 -21
  226. package/dist/core/extensions/types.d.ts.map +1 -1
  227. package/dist/core/extensions/types.js.map +1 -1
  228. package/dist/core/failure-corpus.d.ts +1 -15
  229. package/dist/core/failure-corpus.d.ts.map +1 -1
  230. package/dist/core/failure-corpus.js +9 -37
  231. package/dist/core/failure-corpus.js.map +1 -1
  232. package/dist/core/foreground-recovery-controller.d.ts +53 -0
  233. package/dist/core/foreground-recovery-controller.d.ts.map +1 -0
  234. package/dist/core/foreground-recovery-controller.js +111 -0
  235. package/dist/core/foreground-recovery-controller.js.map +1 -0
  236. package/dist/core/gateways/channel-provider.d.ts +3 -0
  237. package/dist/core/gateways/channel-provider.d.ts.map +1 -1
  238. package/dist/core/gateways/channel-provider.js +31 -6
  239. package/dist/core/gateways/channel-provider.js.map +1 -1
  240. package/dist/core/goal-loop-controller.d.ts +14 -9
  241. package/dist/core/goal-loop-controller.d.ts.map +1 -1
  242. package/dist/core/goal-loop-controller.js +47 -75
  243. package/dist/core/goal-loop-controller.js.map +1 -1
  244. package/dist/core/goals/compact-goal-context.d.ts +11 -0
  245. package/dist/core/goals/compact-goal-context.d.ts.map +1 -0
  246. package/dist/core/goals/compact-goal-context.js +59 -0
  247. package/dist/core/goals/compact-goal-context.js.map +1 -0
  248. package/dist/core/goals/goal-acceptance.d.ts +11 -0
  249. package/dist/core/goals/goal-acceptance.d.ts.map +1 -0
  250. package/dist/core/goals/goal-acceptance.js +27 -0
  251. package/dist/core/goals/goal-acceptance.js.map +1 -0
  252. package/dist/core/goals/goal-auto-continue-controller.d.ts +28 -0
  253. package/dist/core/goals/goal-auto-continue-controller.d.ts.map +1 -0
  254. package/dist/core/goals/goal-auto-continue-controller.js +90 -0
  255. package/dist/core/goals/goal-auto-continue-controller.js.map +1 -0
  256. package/dist/core/goals/goal-continuation-controller.d.ts +2 -2
  257. package/dist/core/goals/goal-continuation-controller.d.ts.map +1 -1
  258. package/dist/core/goals/goal-continuation-controller.js +52 -11
  259. package/dist/core/goals/goal-continuation-controller.js.map +1 -1
  260. package/dist/core/goals/goal-continuation-defaults.d.ts +4 -29
  261. package/dist/core/goals/goal-continuation-defaults.d.ts.map +1 -1
  262. package/dist/core/goals/goal-continuation-defaults.js +4 -32
  263. package/dist/core/goals/goal-continuation-defaults.js.map +1 -1
  264. package/dist/core/goals/goal-continuation-prompt.d.ts +8 -18
  265. package/dist/core/goals/goal-continuation-prompt.d.ts.map +1 -1
  266. package/dist/core/goals/goal-continuation-prompt.js +9 -179
  267. package/dist/core/goals/goal-continuation-prompt.js.map +1 -1
  268. package/dist/core/goals/goal-lifecycle.d.ts +43 -0
  269. package/dist/core/goals/goal-lifecycle.d.ts.map +1 -0
  270. package/dist/core/goals/goal-lifecycle.js +102 -0
  271. package/dist/core/goals/goal-lifecycle.js.map +1 -0
  272. package/dist/core/goals/goal-record.d.ts +17 -0
  273. package/dist/core/goals/goal-record.d.ts.map +1 -0
  274. package/dist/core/goals/goal-record.js +31 -0
  275. package/dist/core/goals/goal-record.js.map +1 -0
  276. package/dist/core/goals/goal-runtime-snapshot.d.ts +11 -9
  277. package/dist/core/goals/goal-runtime-snapshot.d.ts.map +1 -1
  278. package/dist/core/goals/goal-runtime-snapshot.js +10 -8
  279. package/dist/core/goals/goal-runtime-snapshot.js.map +1 -1
  280. package/dist/core/goals/goal-session-controller.d.ts +42 -0
  281. package/dist/core/goals/goal-session-controller.d.ts.map +1 -0
  282. package/dist/core/goals/goal-session-controller.js +128 -0
  283. package/dist/core/goals/goal-session-controller.js.map +1 -0
  284. package/dist/core/goals/goal-state.d.ts +46 -25
  285. package/dist/core/goals/goal-state.d.ts.map +1 -1
  286. package/dist/core/goals/goal-state.js +91 -24
  287. package/dist/core/goals/goal-state.js.map +1 -1
  288. package/dist/core/goals/goal-tool-core.d.ts +9 -10
  289. package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
  290. package/dist/core/goals/goal-tool-core.js +60 -75
  291. package/dist/core/goals/goal-tool-core.js.map +1 -1
  292. package/dist/core/goals/session-goal-state.d.ts +20 -12
  293. package/dist/core/goals/session-goal-state.d.ts.map +1 -1
  294. package/dist/core/goals/session-goal-state.js +133 -33
  295. package/dist/core/goals/session-goal-state.js.map +1 -1
  296. package/dist/core/human-input-controller.d.ts +47 -0
  297. package/dist/core/human-input-controller.d.ts.map +1 -0
  298. package/dist/core/human-input-controller.js +181 -0
  299. package/dist/core/human-input-controller.js.map +1 -0
  300. package/dist/core/human-input.d.ts +100 -0
  301. package/dist/core/human-input.d.ts.map +1 -0
  302. package/dist/core/human-input.js +362 -0
  303. package/dist/core/human-input.js.map +1 -0
  304. package/dist/core/index.d.ts +9 -1
  305. package/dist/core/index.d.ts.map +1 -1
  306. package/dist/core/index.js +9 -1
  307. package/dist/core/index.js.map +1 -1
  308. package/dist/core/{telemetry.d.ts → install-telemetry.d.ts} +1 -1
  309. package/dist/core/install-telemetry.d.ts.map +1 -0
  310. package/dist/core/{telemetry.js → install-telemetry.js} +1 -1
  311. package/dist/core/install-telemetry.js.map +1 -0
  312. package/dist/core/keybindings.d.ts +17 -1
  313. package/dist/core/keybindings.d.ts.map +1 -1
  314. package/dist/core/keybindings.js +24 -6
  315. package/dist/core/keybindings.js.map +1 -1
  316. package/dist/core/learning/learning-audit.d.ts +2 -4
  317. package/dist/core/learning/learning-audit.d.ts.map +1 -1
  318. package/dist/core/learning/learning-audit.js +9 -29
  319. package/dist/core/learning/learning-audit.js.map +1 -1
  320. package/dist/core/learning/learning-gate.d.ts.map +1 -1
  321. package/dist/core/learning/learning-gate.js +1 -6
  322. package/dist/core/learning/learning-gate.js.map +1 -1
  323. package/dist/core/learning/session-learning-decision.d.ts +2 -4
  324. package/dist/core/learning/session-learning-decision.d.ts.map +1 -1
  325. package/dist/core/learning/session-learning-decision.js +9 -29
  326. package/dist/core/learning/session-learning-decision.js.map +1 -1
  327. package/dist/core/local-runtime-controller.d.ts +1 -1
  328. package/dist/core/local-runtime-controller.d.ts.map +1 -1
  329. package/dist/core/local-runtime-controller.js.map +1 -1
  330. package/dist/core/memory-controller.d.ts.map +1 -1
  331. package/dist/core/memory-controller.js +4 -4
  332. package/dist/core/memory-controller.js.map +1 -1
  333. package/dist/core/model-capability.d.ts +0 -19
  334. package/dist/core/model-capability.d.ts.map +1 -1
  335. package/dist/core/model-capability.js +1 -19
  336. package/dist/core/model-capability.js.map +1 -1
  337. package/dist/core/model-registry.d.ts +6 -1
  338. package/dist/core/model-registry.d.ts.map +1 -1
  339. package/dist/core/model-registry.js +13 -5
  340. package/dist/core/model-registry.js.map +1 -1
  341. package/dist/core/model-resolver.d.ts +17 -2
  342. package/dist/core/model-resolver.d.ts.map +1 -1
  343. package/dist/core/model-resolver.js +38 -25
  344. package/dist/core/model-resolver.js.map +1 -1
  345. package/dist/core/model-router/intent-classifier.d.ts +1 -4
  346. package/dist/core/model-router/intent-classifier.d.ts.map +1 -1
  347. package/dist/core/model-router/intent-classifier.js +1 -156
  348. package/dist/core/model-router/intent-classifier.js.map +1 -1
  349. package/dist/core/model-router-controller.d.ts +1 -1
  350. package/dist/core/model-router-controller.d.ts.map +1 -1
  351. package/dist/core/model-router-controller.js +2 -2
  352. package/dist/core/model-router-controller.js.map +1 -1
  353. package/dist/core/model-selection-controller.d.ts +5 -5
  354. package/dist/core/model-selection-controller.d.ts.map +1 -1
  355. package/dist/core/model-selection-controller.js.map +1 -1
  356. package/dist/core/model-tool-protocol.d.ts +23 -0
  357. package/dist/core/model-tool-protocol.d.ts.map +1 -0
  358. package/dist/core/model-tool-protocol.js +43 -0
  359. package/dist/core/model-tool-protocol.js.map +1 -0
  360. package/dist/core/models/adaptation-store.d.ts +4 -6
  361. package/dist/core/models/adaptation-store.d.ts.map +1 -1
  362. package/dist/core/models/adaptation-store.js +95 -83
  363. package/dist/core/models/adaptation-store.js.map +1 -1
  364. package/dist/core/models/fitness-store.d.ts +2 -12
  365. package/dist/core/models/fitness-store.d.ts.map +1 -1
  366. package/dist/core/models/fitness-store.js +84 -57
  367. package/dist/core/models/fitness-store.js.map +1 -1
  368. package/dist/core/models/host-state-store.d.ts +34 -0
  369. package/dist/core/models/host-state-store.d.ts.map +1 -0
  370. package/dist/core/models/host-state-store.js +86 -0
  371. package/dist/core/models/host-state-store.js.map +1 -0
  372. package/dist/core/orchestration/agent-resume.d.ts +24 -0
  373. package/dist/core/orchestration/agent-resume.d.ts.map +1 -0
  374. package/dist/core/orchestration/agent-resume.js +90 -0
  375. package/dist/core/orchestration/agent-resume.js.map +1 -0
  376. package/dist/core/orchestration/capability-gateway.d.ts +61 -0
  377. package/dist/core/orchestration/capability-gateway.d.ts.map +1 -0
  378. package/dist/core/orchestration/capability-gateway.js +152 -0
  379. package/dist/core/orchestration/capability-gateway.js.map +1 -0
  380. package/dist/core/orchestration/contracts.d.ts +343 -0
  381. package/dist/core/orchestration/contracts.d.ts.map +1 -0
  382. package/dist/core/orchestration/contracts.js +135 -0
  383. package/dist/core/orchestration/contracts.js.map +1 -0
  384. package/dist/core/orchestration/delegation-ledger.d.ts +56 -0
  385. package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -0
  386. package/dist/core/orchestration/delegation-ledger.js +200 -0
  387. package/dist/core/orchestration/delegation-ledger.js.map +1 -0
  388. package/dist/core/orchestration/event-store.d.ts +83 -0
  389. package/dist/core/orchestration/event-store.d.ts.map +1 -0
  390. package/dist/core/orchestration/event-store.js +560 -0
  391. package/dist/core/orchestration/event-store.js.map +1 -0
  392. package/dist/core/orchestration/lane-tool-manifests.d.ts +9 -0
  393. package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -0
  394. package/dist/core/orchestration/lane-tool-manifests.js +37 -0
  395. package/dist/core/orchestration/lane-tool-manifests.js.map +1 -0
  396. package/dist/core/orchestration/model-binding.d.ts +15 -0
  397. package/dist/core/orchestration/model-binding.d.ts.map +1 -0
  398. package/dist/core/orchestration/model-binding.js +29 -0
  399. package/dist/core/orchestration/model-binding.js.map +1 -0
  400. package/dist/core/orchestration/policy-compiler.d.ts +49 -0
  401. package/dist/core/orchestration/policy-compiler.d.ts.map +1 -0
  402. package/dist/core/orchestration/policy-compiler.js +191 -0
  403. package/dist/core/orchestration/policy-compiler.js.map +1 -0
  404. package/dist/core/orchestration/policy-gate.d.ts +18 -0
  405. package/dist/core/orchestration/policy-gate.d.ts.map +1 -0
  406. package/dist/core/orchestration/policy-gate.js +24 -0
  407. package/dist/core/orchestration/policy-gate.js.map +1 -0
  408. package/dist/core/orchestration/profile-registry.d.ts +51 -0
  409. package/dist/core/orchestration/profile-registry.d.ts.map +1 -0
  410. package/dist/core/orchestration/profile-registry.js +393 -0
  411. package/dist/core/orchestration/profile-registry.js.map +1 -0
  412. package/dist/core/orchestration/profile-store.d.ts +31 -0
  413. package/dist/core/orchestration/profile-store.d.ts.map +1 -0
  414. package/dist/core/orchestration/profile-store.js +136 -0
  415. package/dist/core/orchestration/profile-store.js.map +1 -0
  416. package/dist/core/orchestration/risk-budget.d.ts +9 -0
  417. package/dist/core/orchestration/risk-budget.d.ts.map +1 -0
  418. package/dist/core/orchestration/risk-budget.js +48 -0
  419. package/dist/core/orchestration/risk-budget.js.map +1 -0
  420. package/dist/core/orchestration/task-runtime.d.ts +168 -0
  421. package/dist/core/orchestration/task-runtime.d.ts.map +1 -0
  422. package/dist/core/orchestration/task-runtime.js +1600 -0
  423. package/dist/core/orchestration/task-runtime.js.map +1 -0
  424. package/dist/core/orchestration/work-state-projection.d.ts +32 -0
  425. package/dist/core/orchestration/work-state-projection.d.ts.map +1 -0
  426. package/dist/core/orchestration/work-state-projection.js +116 -0
  427. package/dist/core/orchestration/work-state-projection.js.map +1 -0
  428. package/dist/core/orchestration/worker-execution-contract.d.ts +21 -0
  429. package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -0
  430. package/dist/core/orchestration/worker-execution-contract.js +179 -0
  431. package/dist/core/orchestration/worker-execution-contract.js.map +1 -0
  432. package/dist/core/orchestration/worker-result-adapter.d.ts +21 -0
  433. package/dist/core/orchestration/worker-result-adapter.d.ts.map +1 -0
  434. package/dist/core/orchestration/worker-result-adapter.js +109 -0
  435. package/dist/core/orchestration/worker-result-adapter.js.map +1 -0
  436. package/dist/core/package-manager.d.ts.map +1 -1
  437. package/dist/core/package-manager.js +20 -3
  438. package/dist/core/package-manager.js.map +1 -1
  439. package/dist/core/process-identity.d.ts +11 -0
  440. package/dist/core/process-identity.d.ts.map +1 -0
  441. package/dist/core/process-identity.js +26 -0
  442. package/dist/core/process-identity.js.map +1 -0
  443. package/dist/core/process-matrix/codes.d.ts +14 -3
  444. package/dist/core/process-matrix/codes.d.ts.map +1 -1
  445. package/dist/core/process-matrix/codes.js.map +1 -1
  446. package/dist/core/process-matrix/resume-launcher.d.ts +26 -0
  447. package/dist/core/process-matrix/resume-launcher.d.ts.map +1 -0
  448. package/dist/core/process-matrix/resume-launcher.js +62 -0
  449. package/dist/core/process-matrix/resume-launcher.js.map +1 -0
  450. package/dist/core/process-matrix/runtime.d.ts +37 -22
  451. package/dist/core/process-matrix/runtime.d.ts.map +1 -1
  452. package/dist/core/process-matrix/runtime.js +399 -76
  453. package/dist/core/process-matrix/runtime.js.map +1 -1
  454. package/dist/core/process-matrix/store.d.ts +5 -2
  455. package/dist/core/process-matrix/store.d.ts.map +1 -1
  456. package/dist/core/process-matrix/store.js +123 -14
  457. package/dist/core/process-matrix/store.js.map +1 -1
  458. package/dist/core/process-matrix/supervisor.d.ts +10 -7
  459. package/dist/core/process-matrix/supervisor.d.ts.map +1 -1
  460. package/dist/core/process-matrix/supervisor.js +45 -14
  461. package/dist/core/process-matrix/supervisor.js.map +1 -1
  462. package/dist/core/profile-filter-controller.d.ts +8 -1
  463. package/dist/core/profile-filter-controller.d.ts.map +1 -1
  464. package/dist/core/profile-filter-controller.js +23 -5
  465. package/dist/core/profile-filter-controller.js.map +1 -1
  466. package/dist/core/profile-registry.d.ts.map +1 -1
  467. package/dist/core/profile-registry.js +6 -8
  468. package/dist/core/profile-registry.js.map +1 -1
  469. package/dist/core/prompt-templates.d.ts +1 -0
  470. package/dist/core/prompt-templates.d.ts.map +1 -1
  471. package/dist/core/prompt-templates.js +18 -29
  472. package/dist/core/prompt-templates.js.map +1 -1
  473. package/dist/core/reflection-controller.d.ts +5 -5
  474. package/dist/core/reflection-controller.d.ts.map +1 -1
  475. package/dist/core/reflection-controller.js +5 -2
  476. package/dist/core/reflection-controller.js.map +1 -1
  477. package/dist/core/reload-blockers.d.ts.map +1 -1
  478. package/dist/core/reload-blockers.js +6 -8
  479. package/dist/core/reload-blockers.js.map +1 -1
  480. package/dist/core/request-auth.d.ts +7 -0
  481. package/dist/core/request-auth.d.ts.map +1 -0
  482. package/dist/core/request-auth.js +8 -0
  483. package/dist/core/request-auth.js.map +1 -0
  484. package/dist/core/research/evidence-bundle.d.ts.map +1 -1
  485. package/dist/core/research/evidence-bundle.js +1 -6
  486. package/dist/core/research/evidence-bundle.js.map +1 -1
  487. package/dist/core/research/lane-model-resolver.d.ts +33 -0
  488. package/dist/core/research/lane-model-resolver.d.ts.map +1 -0
  489. package/dist/core/research/lane-model-resolver.js +65 -0
  490. package/dist/core/research/lane-model-resolver.js.map +1 -0
  491. package/dist/core/research/model-fitness-controller.d.ts +38 -0
  492. package/dist/core/research/model-fitness-controller.d.ts.map +1 -0
  493. package/dist/core/research/model-fitness-controller.js +106 -0
  494. package/dist/core/research/model-fitness-controller.js.map +1 -0
  495. package/dist/core/research/model-fitness.d.ts +1 -1
  496. package/dist/core/research/model-fitness.d.ts.map +1 -1
  497. package/dist/core/research/model-fitness.js +4 -4
  498. package/dist/core/research/model-fitness.js.map +1 -1
  499. package/dist/core/research/research-gate.d.ts.map +1 -1
  500. package/dist/core/research/research-gate.js +7 -7
  501. package/dist/core/research/research-gate.js.map +1 -1
  502. package/dist/core/research/research-lane-controller.d.ts +62 -0
  503. package/dist/core/research/research-lane-controller.d.ts.map +1 -0
  504. package/dist/core/research/research-lane-controller.js +292 -0
  505. package/dist/core/research/research-lane-controller.js.map +1 -0
  506. package/dist/core/research/session-evidence-bundle.d.ts +2 -4
  507. package/dist/core/research/session-evidence-bundle.d.ts.map +1 -1
  508. package/dist/core/research/session-evidence-bundle.js +10 -46
  509. package/dist/core/research/session-evidence-bundle.js.map +1 -1
  510. package/dist/core/resource-loader.d.ts.map +1 -1
  511. package/dist/core/resource-loader.js +23 -8
  512. package/dist/core/resource-loader.js.map +1 -1
  513. package/dist/core/risk-classifier.d.ts +6 -0
  514. package/dist/core/risk-classifier.d.ts.map +1 -0
  515. package/dist/core/risk-classifier.js +233 -0
  516. package/dist/core/risk-classifier.js.map +1 -0
  517. package/dist/core/runtime-builder.d.ts +41 -23
  518. package/dist/core/runtime-builder.d.ts.map +1 -1
  519. package/dist/core/runtime-builder.js +365 -253
  520. package/dist/core/runtime-builder.js.map +1 -1
  521. package/dist/core/sdk.d.ts +6 -3
  522. package/dist/core/sdk.d.ts.map +1 -1
  523. package/dist/core/sdk.js +68 -25
  524. package/dist/core/sdk.js.map +1 -1
  525. package/dist/core/secrets/credential-exposure-guard.d.ts +9 -0
  526. package/dist/core/secrets/credential-exposure-guard.d.ts.map +1 -0
  527. package/dist/core/secrets/credential-exposure-guard.js +241 -0
  528. package/dist/core/secrets/credential-exposure-guard.js.map +1 -0
  529. package/dist/core/secrets/secret-dotenv.d.ts +27 -0
  530. package/dist/core/secrets/secret-dotenv.d.ts.map +1 -0
  531. package/dist/core/secrets/secret-dotenv.js +183 -0
  532. package/dist/core/secrets/secret-dotenv.js.map +1 -0
  533. package/dist/core/secrets/secret-vault-format.d.ts +112 -0
  534. package/dist/core/secrets/secret-vault-format.d.ts.map +1 -0
  535. package/dist/core/secrets/secret-vault-format.js +397 -0
  536. package/dist/core/secrets/secret-vault-format.js.map +1 -0
  537. package/dist/core/secrets/secret-vault.d.ts +72 -0
  538. package/dist/core/secrets/secret-vault.d.ts.map +1 -0
  539. package/dist/core/secrets/secret-vault.js +671 -0
  540. package/dist/core/secrets/secret-vault.js.map +1 -0
  541. package/dist/core/session-analytics.d.ts +4 -23
  542. package/dist/core/session-analytics.d.ts.map +1 -1
  543. package/dist/core/session-analytics.js +67 -70
  544. package/dist/core/session-analytics.js.map +1 -1
  545. package/dist/core/session-image-store.d.ts +33 -0
  546. package/dist/core/session-image-store.d.ts.map +1 -0
  547. package/dist/core/session-image-store.js +283 -0
  548. package/dist/core/session-image-store.js.map +1 -0
  549. package/dist/core/session-role.d.ts +11 -4
  550. package/dist/core/session-role.d.ts.map +1 -1
  551. package/dist/core/session-role.js +24 -5
  552. package/dist/core/session-role.js.map +1 -1
  553. package/dist/core/session-snapshot.d.ts +34 -0
  554. package/dist/core/session-snapshot.d.ts.map +1 -0
  555. package/dist/core/session-snapshot.js +68 -0
  556. package/dist/core/session-snapshot.js.map +1 -0
  557. package/dist/core/session-supervision-runtime.d.ts +31 -0
  558. package/dist/core/session-supervision-runtime.d.ts.map +1 -0
  559. package/dist/core/session-supervision-runtime.js +97 -0
  560. package/dist/core/session-supervision-runtime.js.map +1 -0
  561. package/dist/core/session-tree-navigator.d.ts +4 -6
  562. package/dist/core/session-tree-navigator.d.ts.map +1 -1
  563. package/dist/core/session-tree-navigator.js +4 -1
  564. package/dist/core/session-tree-navigator.js.map +1 -1
  565. package/dist/core/settings-manager.d.ts +10 -5
  566. package/dist/core/settings-manager.d.ts.map +1 -1
  567. package/dist/core/settings-manager.js +81 -29
  568. package/dist/core/settings-manager.js.map +1 -1
  569. package/dist/core/slash-commands.d.ts.map +1 -1
  570. package/dist/core/slash-commands.js +2 -2
  571. package/dist/core/slash-commands.js.map +1 -1
  572. package/dist/core/tasks/session-task-state.d.ts +2 -4
  573. package/dist/core/tasks/session-task-state.d.ts.map +1 -1
  574. package/dist/core/tasks/session-task-state.js +10 -28
  575. package/dist/core/tasks/session-task-state.js.map +1 -1
  576. package/dist/core/tasks/task-projection.d.ts +20 -0
  577. package/dist/core/tasks/task-projection.d.ts.map +1 -0
  578. package/dist/core/tasks/task-projection.js +47 -0
  579. package/dist/core/tasks/task-projection.js.map +1 -0
  580. package/dist/core/tasks/task-state.d.ts +4 -0
  581. package/dist/core/tasks/task-state.d.ts.map +1 -1
  582. package/dist/core/tasks/task-state.js +28 -11
  583. package/dist/core/tasks/task-state.js.map +1 -1
  584. package/dist/core/tool-capability-policy.d.ts +13 -0
  585. package/dist/core/tool-capability-policy.d.ts.map +1 -0
  586. package/dist/core/tool-capability-policy.js +86 -0
  587. package/dist/core/tool-capability-policy.js.map +1 -0
  588. package/dist/core/tool-gate-controller.d.ts.map +1 -1
  589. package/dist/core/tool-gate-controller.js +8 -2
  590. package/dist/core/tool-gate-controller.js.map +1 -1
  591. package/dist/core/tool-protocol-controller.d.ts +89 -0
  592. package/dist/core/tool-protocol-controller.d.ts.map +1 -0
  593. package/dist/core/tool-protocol-controller.js +512 -0
  594. package/dist/core/tool-protocol-controller.js.map +1 -0
  595. package/dist/core/tool-recovery-log-records.d.ts +2 -3
  596. package/dist/core/tool-recovery-log-records.d.ts.map +1 -1
  597. package/dist/core/tool-recovery-log-records.js +9 -35
  598. package/dist/core/tool-recovery-log-records.js.map +1 -1
  599. package/dist/core/tool-recovery-stats.d.ts +21 -1
  600. package/dist/core/tool-recovery-stats.d.ts.map +1 -1
  601. package/dist/core/tool-recovery-stats.js.map +1 -1
  602. package/dist/core/tool-selection/tool-performance-store.d.ts +3 -7
  603. package/dist/core/tool-selection/tool-performance-store.d.ts.map +1 -1
  604. package/dist/core/tool-selection/tool-performance-store.js +97 -138
  605. package/dist/core/tool-selection/tool-performance-store.js.map +1 -1
  606. package/dist/core/tools/ask-question.d.ts +124 -0
  607. package/dist/core/tools/ask-question.d.ts.map +1 -0
  608. package/dist/core/tools/ask-question.js +693 -0
  609. package/dist/core/tools/ask-question.js.map +1 -0
  610. package/dist/core/tools/bash.d.ts +5 -0
  611. package/dist/core/tools/bash.d.ts.map +1 -1
  612. package/dist/core/tools/bash.js +59 -5
  613. package/dist/core/tools/bash.js.map +1 -1
  614. package/dist/core/tools/delegate-status.d.ts +31 -3
  615. package/dist/core/tools/delegate-status.d.ts.map +1 -1
  616. package/dist/core/tools/delegate-status.js +148 -29
  617. package/dist/core/tools/delegate-status.js.map +1 -1
  618. package/dist/core/tools/delegate.d.ts +15 -13
  619. package/dist/core/tools/delegate.d.ts.map +1 -1
  620. package/dist/core/tools/delegate.js +106 -23
  621. package/dist/core/tools/delegate.js.map +1 -1
  622. package/dist/core/tools/extensionify.d.ts.map +1 -1
  623. package/dist/core/tools/extensionify.js +1 -0
  624. package/dist/core/tools/extensionify.js.map +1 -1
  625. package/dist/core/tools/git-filter.d.ts +1 -8
  626. package/dist/core/tools/git-filter.d.ts.map +1 -1
  627. package/dist/core/tools/git-filter.js +2 -63
  628. package/dist/core/tools/git-filter.js.map +1 -1
  629. package/dist/core/tools/goal.d.ts +10 -8
  630. package/dist/core/tools/goal.d.ts.map +1 -1
  631. package/dist/core/tools/goal.js +106 -28
  632. package/dist/core/tools/goal.js.map +1 -1
  633. package/dist/core/tools/index.d.ts +1 -0
  634. package/dist/core/tools/index.d.ts.map +1 -1
  635. package/dist/core/tools/index.js +1 -0
  636. package/dist/core/tools/index.js.map +1 -1
  637. package/dist/core/tools/model-fitness.d.ts.map +1 -1
  638. package/dist/core/tools/model-fitness.js +2 -2
  639. package/dist/core/tools/model-fitness.js.map +1 -1
  640. package/dist/core/tools/orchestration-panel.d.ts +40 -0
  641. package/dist/core/tools/orchestration-panel.d.ts.map +1 -0
  642. package/dist/core/tools/orchestration-panel.js +124 -0
  643. package/dist/core/tools/orchestration-panel.js.map +1 -0
  644. package/dist/core/tools/output-accumulator.d.ts +11 -0
  645. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  646. package/dist/core/tools/output-accumulator.js +36 -3
  647. package/dist/core/tools/output-accumulator.js.map +1 -1
  648. package/dist/core/tools/python.d.ts +2 -0
  649. package/dist/core/tools/python.d.ts.map +1 -1
  650. package/dist/core/tools/python.js +3 -1
  651. package/dist/core/tools/python.js.map +1 -1
  652. package/dist/core/tools/read.d.ts.map +1 -1
  653. package/dist/core/tools/read.js +1 -1
  654. package/dist/core/tools/read.js.map +1 -1
  655. package/dist/core/tools/run-process.d.ts +26 -0
  656. package/dist/core/tools/run-process.d.ts.map +1 -0
  657. package/dist/core/tools/run-process.js +138 -0
  658. package/dist/core/tools/run-process.js.map +1 -0
  659. package/dist/core/tools/search-command-guard.d.ts +14 -0
  660. package/dist/core/tools/search-command-guard.d.ts.map +1 -0
  661. package/dist/core/tools/search-command-guard.js +333 -0
  662. package/dist/core/tools/search-command-guard.js.map +1 -0
  663. package/dist/core/tools/secret-store.d.ts +38 -0
  664. package/dist/core/tools/secret-store.d.ts.map +1 -0
  665. package/dist/core/tools/secret-store.js +412 -0
  666. package/dist/core/tools/secret-store.js.map +1 -0
  667. package/dist/core/tools/shell-command-parser.d.ts +16 -0
  668. package/dist/core/tools/shell-command-parser.d.ts.map +1 -0
  669. package/dist/core/tools/shell-command-parser.js +113 -0
  670. package/dist/core/tools/shell-command-parser.js.map +1 -0
  671. package/dist/core/tools/task-steps.d.ts +2 -0
  672. package/dist/core/tools/task-steps.d.ts.map +1 -1
  673. package/dist/core/tools/task-steps.js +99 -0
  674. package/dist/core/tools/task-steps.js.map +1 -1
  675. package/dist/core/tools/tmux-dispatch.d.ts +3 -5
  676. package/dist/core/tools/tmux-dispatch.d.ts.map +1 -1
  677. package/dist/core/tools/tmux-dispatch.js +4 -4
  678. package/dist/core/tools/tmux-dispatch.js.map +1 -1
  679. package/dist/core/tools/windows-shell-engine.d.ts.map +1 -1
  680. package/dist/core/tools/windows-shell-engine.js +4 -6
  681. package/dist/core/tools/windows-shell-engine.js.map +1 -1
  682. package/dist/core/util/atomic-file.d.ts +6 -2
  683. package/dist/core/util/atomic-file.d.ts.map +1 -1
  684. package/dist/core/util/atomic-file.js +4 -4
  685. package/dist/core/util/atomic-file.js.map +1 -1
  686. package/dist/core/util/bounded-jsonl.d.ts +10 -0
  687. package/dist/core/util/bounded-jsonl.d.ts.map +1 -0
  688. package/dist/core/util/bounded-jsonl.js +75 -0
  689. package/dist/core/util/bounded-jsonl.js.map +1 -0
  690. package/dist/core/util/value-guards.d.ts +5 -0
  691. package/dist/core/util/value-guards.d.ts.map +1 -0
  692. package/dist/core/util/value-guards.js +12 -0
  693. package/dist/core/util/value-guards.js.map +1 -0
  694. package/dist/core/worktree-sync/store.d.ts +3 -3
  695. package/dist/core/worktree-sync/store.d.ts.map +1 -1
  696. package/dist/core/worktree-sync/store.js +10 -5
  697. package/dist/core/worktree-sync/store.js.map +1 -1
  698. package/dist/index.d.ts +15 -4
  699. package/dist/index.d.ts.map +1 -1
  700. package/dist/index.js +14 -3
  701. package/dist/index.js.map +1 -1
  702. package/dist/main.d.ts.map +1 -1
  703. package/dist/main.js +149 -51
  704. package/dist/main.js.map +1 -1
  705. package/dist/migrations.d.ts +4 -6
  706. package/dist/migrations.d.ts.map +1 -1
  707. package/dist/migrations.js +186 -28
  708. package/dist/migrations.js.map +1 -1
  709. package/dist/modes/interactive/auth-dialogs-controller.d.ts +4 -0
  710. package/dist/modes/interactive/auth-dialogs-controller.d.ts.map +1 -1
  711. package/dist/modes/interactive/auth-dialogs-controller.js +60 -1
  712. package/dist/modes/interactive/auth-dialogs-controller.js.map +1 -1
  713. package/dist/modes/interactive/clipboard-input.d.ts +7 -1
  714. package/dist/modes/interactive/clipboard-input.d.ts.map +1 -1
  715. package/dist/modes/interactive/clipboard-input.js +44 -6
  716. package/dist/modes/interactive/clipboard-input.js.map +1 -1
  717. package/dist/modes/interactive/components/activity-lane.d.ts +55 -0
  718. package/dist/modes/interactive/components/activity-lane.d.ts.map +1 -0
  719. package/dist/modes/interactive/components/activity-lane.js +304 -0
  720. package/dist/modes/interactive/components/activity-lane.js.map +1 -0
  721. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  722. package/dist/modes/interactive/components/assistant-message.js +19 -10
  723. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  724. package/dist/modes/interactive/components/expandable-text.d.ts +12 -0
  725. package/dist/modes/interactive/components/expandable-text.d.ts.map +1 -0
  726. package/dist/modes/interactive/components/expandable-text.js +17 -0
  727. package/dist/modes/interactive/components/expandable-text.js.map +1 -0
  728. package/dist/modes/interactive/components/extension-editor.d.ts +15 -1
  729. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  730. package/dist/modes/interactive/components/extension-editor.js +30 -21
  731. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  732. package/dist/modes/interactive/components/extension-input.d.ts +1 -0
  733. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
  734. package/dist/modes/interactive/components/extension-input.js +6 -1
  735. package/dist/modes/interactive/components/extension-input.js.map +1 -1
  736. package/dist/modes/interactive/components/scoped-models-selector.d.ts +2 -2
  737. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  738. package/dist/modes/interactive/components/scoped-models-selector.js +23 -14
  739. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  740. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  741. package/dist/modes/interactive/components/settings-selector.js +6 -6
  742. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  743. package/dist/modes/interactive/components/tool-execution.d.ts +19 -11
  744. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  745. package/dist/modes/interactive/components/tool-execution.js +53 -20
  746. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  747. package/dist/modes/interactive/components/tool-group.d.ts.map +1 -1
  748. package/dist/modes/interactive/components/tool-group.js +3 -0
  749. package/dist/modes/interactive/components/tool-group.js.map +1 -1
  750. package/dist/modes/interactive/components/usage-action-selector.d.ts +16 -0
  751. package/dist/modes/interactive/components/usage-action-selector.d.ts.map +1 -0
  752. package/dist/modes/interactive/components/usage-action-selector.js +46 -0
  753. package/dist/modes/interactive/components/usage-action-selector.js.map +1 -0
  754. package/dist/modes/interactive/config-backup.d.ts.map +1 -1
  755. package/dist/modes/interactive/config-backup.js +5 -4
  756. package/dist/modes/interactive/config-backup.js.map +1 -1
  757. package/dist/modes/interactive/extension-ui-host.d.ts +14 -0
  758. package/dist/modes/interactive/extension-ui-host.d.ts.map +1 -1
  759. package/dist/modes/interactive/extension-ui-host.js +77 -15
  760. package/dist/modes/interactive/extension-ui-host.js.map +1 -1
  761. package/dist/modes/interactive/external-editor.d.ts +15 -0
  762. package/dist/modes/interactive/external-editor.d.ts.map +1 -1
  763. package/dist/modes/interactive/external-editor.js +27 -19
  764. package/dist/modes/interactive/external-editor.js.map +1 -1
  765. package/dist/modes/interactive/history-reload-math.d.ts +6 -2
  766. package/dist/modes/interactive/history-reload-math.d.ts.map +1 -1
  767. package/dist/modes/interactive/history-reload-math.js +10 -5
  768. package/dist/modes/interactive/history-reload-math.js.map +1 -1
  769. package/dist/modes/interactive/interactive-event-controller.d.ts +74 -0
  770. package/dist/modes/interactive/interactive-event-controller.d.ts.map +1 -0
  771. package/dist/modes/interactive/interactive-event-controller.js +328 -0
  772. package/dist/modes/interactive/interactive-event-controller.js.map +1 -0
  773. package/dist/modes/interactive/interactive-mode.d.ts +22 -24
  774. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  775. package/dist/modes/interactive/interactive-mode.js +245 -595
  776. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  777. package/dist/modes/interactive/key-handlers.d.ts.map +1 -1
  778. package/dist/modes/interactive/key-handlers.js +1 -1
  779. package/dist/modes/interactive/key-handlers.js.map +1 -1
  780. package/dist/modes/interactive/loaded-resources-view.d.ts +20 -0
  781. package/dist/modes/interactive/loaded-resources-view.d.ts.map +1 -0
  782. package/dist/modes/interactive/loaded-resources-view.js +147 -0
  783. package/dist/modes/interactive/loaded-resources-view.js.map +1 -0
  784. package/dist/modes/interactive/profile-menu-controller.d.ts.map +1 -1
  785. package/dist/modes/interactive/profile-menu-controller.js +7 -7
  786. package/dist/modes/interactive/profile-menu-controller.js.map +1 -1
  787. package/dist/modes/interactive/report-commands.d.ts.map +1 -1
  788. package/dist/modes/interactive/report-commands.js +21 -0
  789. package/dist/modes/interactive/report-commands.js.map +1 -1
  790. package/dist/modes/interactive/resource-display.d.ts.map +1 -1
  791. package/dist/modes/interactive/resource-display.js +8 -2
  792. package/dist/modes/interactive/resource-display.js.map +1 -1
  793. package/dist/modes/interactive/resource-shell-commands.d.ts +1 -5
  794. package/dist/modes/interactive/resource-shell-commands.d.ts.map +1 -1
  795. package/dist/modes/interactive/resource-shell-commands.js +0 -5
  796. package/dist/modes/interactive/resource-shell-commands.js.map +1 -1
  797. package/dist/modes/interactive/session-flow-commands.d.ts +27 -8
  798. package/dist/modes/interactive/session-flow-commands.d.ts.map +1 -1
  799. package/dist/modes/interactive/session-flow-commands.js +150 -64
  800. package/dist/modes/interactive/session-flow-commands.js.map +1 -1
  801. package/dist/modes/interactive/session-io-commands.d.ts.map +1 -1
  802. package/dist/modes/interactive/session-io-commands.js +16 -6
  803. package/dist/modes/interactive/session-io-commands.js.map +1 -1
  804. package/dist/modes/interactive/session-replacement-errors.d.ts +7 -0
  805. package/dist/modes/interactive/session-replacement-errors.d.ts.map +1 -0
  806. package/dist/modes/interactive/session-replacement-errors.js +15 -0
  807. package/dist/modes/interactive/session-replacement-errors.js.map +1 -0
  808. package/dist/modes/interactive/startup-checks.d.ts.map +1 -1
  809. package/dist/modes/interactive/startup-checks.js +1 -1
  810. package/dist/modes/interactive/startup-checks.js.map +1 -1
  811. package/dist/modes/interactive/usage-commands.d.ts +34 -0
  812. package/dist/modes/interactive/usage-commands.d.ts.map +1 -0
  813. package/dist/modes/interactive/usage-commands.js +225 -0
  814. package/dist/modes/interactive/usage-commands.js.map +1 -0
  815. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  816. package/dist/modes/rpc/rpc-mode.js +82 -23
  817. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  818. package/dist/modes/rpc/rpc-types.d.ts +15 -0
  819. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  820. package/dist/modes/rpc/rpc-types.js +138 -1
  821. package/dist/modes/rpc/rpc-types.js.map +1 -1
  822. package/dist/utils/clipboard-image.d.ts.map +1 -1
  823. package/dist/utils/clipboard-image.js +2 -13
  824. package/dist/utils/clipboard-image.js.map +1 -1
  825. package/dist/utils/clipboard-native.d.ts +1 -0
  826. package/dist/utils/clipboard-native.d.ts.map +1 -1
  827. package/dist/utils/clipboard-native.js.map +1 -1
  828. package/dist/utils/clipboard.d.ts +1 -0
  829. package/dist/utils/clipboard.d.ts.map +1 -1
  830. package/dist/utils/clipboard.js +52 -1
  831. package/dist/utils/clipboard.js.map +1 -1
  832. package/dist/utils/platform.d.ts +3 -0
  833. package/dist/utils/platform.d.ts.map +1 -0
  834. package/dist/utils/platform.js +8 -0
  835. package/dist/utils/platform.js.map +1 -0
  836. package/dist/utils/shell.d.ts.map +1 -1
  837. package/dist/utils/shell.js +5 -3
  838. package/dist/utils/shell.js.map +1 -1
  839. package/dist/utils/version-check.d.ts.map +1 -1
  840. package/dist/utils/version-check.js +3 -1
  841. package/dist/utils/version-check.js.map +1 -1
  842. package/dist/utils/work-directory.d.ts +11 -0
  843. package/dist/utils/work-directory.d.ts.map +1 -1
  844. package/dist/utils/work-directory.js +30 -9
  845. package/dist/utils/work-directory.js.map +1 -1
  846. package/docs/UI_POLISH_ORCHESTRATION.md +38 -0
  847. package/docs/UI_QUALITY_ORCHESTRATION.md +28 -0
  848. package/docs/docs.json +4 -0
  849. package/docs/extensions.md +62 -2
  850. package/docs/harness-architecture.md +156 -0
  851. package/docs/keybindings.md +11 -1
  852. package/docs/process-matrix.md +59 -26
  853. package/docs/providers.md +9 -1
  854. package/docs/rpc.md +45 -2
  855. package/docs/sessions.md +15 -0
  856. package/docs/settings.md +125 -11
  857. package/docs/task-steps.md +8 -0
  858. package/docs/telemetry.md +19 -0
  859. package/docs/tmux-agent-manager.md +10 -3
  860. package/docs/ui-reference/README.md +9 -0
  861. package/docs/ui-reference/orchestration-after.txt +14 -0
  862. package/docs/ui-reference/orchestration-before.txt +13 -0
  863. package/docs/ui-reference/orchestration-reference.txt +16 -0
  864. package/docs/usage.md +22 -2
  865. package/docs/work-directory.md +19 -8
  866. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  867. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  868. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  869. package/examples/extensions/question.ts +34 -245
  870. package/examples/extensions/questionnaire.ts +41 -407
  871. package/examples/extensions/sandbox/package-lock.json +2 -2
  872. package/examples/extensions/sandbox/package.json +1 -1
  873. package/examples/extensions/with-deps/package-lock.json +2 -2
  874. package/examples/extensions/with-deps/package.json +1 -1
  875. package/npm-shrinkwrap.json +13 -13
  876. package/package.json +4 -4
  877. package/dist/core/delegation/session-worker-result.d.ts +0 -46
  878. package/dist/core/delegation/session-worker-result.d.ts.map +0 -1
  879. package/dist/core/delegation/session-worker-result.js +0 -113
  880. package/dist/core/delegation/session-worker-result.js.map +0 -1
  881. package/dist/core/delegation/worker-result.d.ts.map +0 -1
  882. package/dist/core/delegation/worker-result.js.map +0 -1
  883. package/dist/core/telemetry.d.ts.map +0 -1
  884. package/dist/core/telemetry.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task-runtime.d.ts","sourceRoot":"","sources":["../../../src/core/orchestration/task-runtime.ts"],"names":[],"mappings":"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","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { isDeepStrictEqual } from \"node:util\";\nimport type { JsonObject } from \"../autonomy/contracts.ts\";\nimport { createAgentIdentity } from \"./agent-resume.ts\";\nimport {\n\ttype AcceptanceCriterion,\n\ttype AgentBindingContract,\n\ttype AgentIdentityContract,\n\ttype AgentResumeContext,\n\ttype AppendOrchestrationEventInput,\n\ttype ApprovalOutcome,\n\ttype ApprovalRequestContract,\n\ttype ApprovalResolutionContract,\n\ttype AttemptCheckpoint,\n\ttype AttemptLease,\n\ttype AttemptStatus,\n\ttype EvidenceContract,\n\ttype ExecutionGrant,\n\tisHarnessCapability,\n\ttype ObjectiveContract,\n\ttype ObjectiveStatus,\n\tORCHESTRATION_SCHEMA_VERSION,\n\ttype OrchestrationDispatchRequest,\n\ttype OrchestrationEvent,\n\ttype OrchestrationTaskStatus,\n\ttype RiskBudget,\n\ttype TaskContract,\n\ttoJsonObject,\n\ttype WorkerExecutionContract,\n\ttype WorkerResultContract,\n} from \"./contracts.ts\";\nimport { type OrchestrationEventStore, OrchestrationSnapshotRequiredError } from \"./event-store.ts\";\nimport { validateRiskBudget } from \"./risk-budget.ts\";\nimport { parseWorkerExecutionContract } from \"./worker-execution-contract.ts\";\n\nexport interface ObjectiveRuntimeState {\n\tobjective: ObjectiveContract;\n\ttaskIds: readonly string[];\n\tevidence: readonly EvidenceContract[];\n}\n\nexport interface TaskRuntimeState {\n\ttask: TaskContract;\n\tattemptIds: readonly string[];\n\tverification?: {\n\t\tverifierTaskId: string;\n\t\tverifierAttemptId: string;\n\t\tverdict: \"accepted\" | \"rejected\" | \"inconclusive\";\n\t\treasonCode: string;\n\t\tcompletedAt: string;\n\t};\n}\n\nexport interface AttemptRuntimeState {\n\tattemptId: string;\n\ttaskId: string;\n\tdispatch: OrchestrationDispatchRequest;\n\tstatus: AttemptStatus;\n\treasonCode?: string;\n\tgrantId?: string;\n\t/** Full compiled authority for new attempts; grantId alone is retained only when replaying legacy events. */\n\tgrant?: ExecutionGrant;\n\tagentId?: string;\n\tlease?: AttemptLease;\n\tcheckpointIds: readonly string[];\n\tresult?: WorkerResultContract;\n\tcreatedAt: string;\n\tupdatedAt: string;\n}\n\nexport interface NotificationRuntimeState {\n\tnotificationId: string;\n\tobjectiveId: string;\n\tattemptId?: string;\n\tstatus: \"pending\" | \"delivered\";\n\tmessage: string;\n\tcreatedAt: string;\n\tdeliveredAt?: string;\n}\n\nexport interface ApprovalRuntimeState {\n\trequest: ApprovalRequestContract;\n\tstatus: \"pending\" | ApprovalOutcome;\n\tresolution?: ApprovalResolutionContract;\n}\n\nexport interface TaskRuntimeProjection {\n\tlastOrdinal: number;\n\tagents: Readonly<Record<string, AgentBindingContract>>;\n\tobjectives: Readonly<Record<string, ObjectiveRuntimeState>>;\n\ttasks: Readonly<Record<string, TaskRuntimeState>>;\n\tattempts: Readonly<Record<string, AttemptRuntimeState>>;\n\tcheckpoints: Readonly<Record<string, AttemptCheckpoint>>;\n\tapprovals: Readonly<Record<string, ApprovalRuntimeState>>;\n\tnotifications: Readonly<Record<string, NotificationRuntimeState>>;\n}\n\nexport interface CreateObjectiveInput {\n\tobjectiveId?: string;\n\ttitle: string;\n\tdescription: string;\n\tconstraints?: readonly string[];\n\tacceptanceCriteria?: readonly AcceptanceCriterion[];\n\triskBudget?: RiskBudget;\n}\n\nexport interface CreateTaskInput {\n\ttaskId?: string;\n\tobjectiveId: string;\n\ttitle: string;\n\tdescription: string;\n\trole: TaskContract[\"role\"];\n\tdependsOn?: readonly string[];\n\trequiredCapabilities?: TaskContract[\"requiredCapabilities\"];\n\tacceptanceCriterionIds?: readonly string[];\n\tverificationOfTaskId?: string;\n\triskBudget?: RiskBudget;\n}\n\nexport interface DurableTaskRuntimeOptions {\n\tstore: OrchestrationEventStore;\n\tnow?: () => number;\n\tcreateId?: () => string;\n}\n\nexport interface RegisterAgentInput {\n\tagentId?: string;\n\trole: AgentBindingContract[\"role\"];\n\tresumeContext: AgentResumeContext;\n}\n\nexport class DurableTaskRuntimeError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"DurableTaskRuntimeError\";\n\t}\n}\n\nfunction emptyProjection(): TaskRuntimeProjection {\n\treturn {\n\t\tlastOrdinal: 0,\n\t\tagents: {},\n\t\tobjectives: {},\n\t\ttasks: {},\n\t\tattempts: {},\n\t\tcheckpoints: {},\n\t\tapprovals: {},\n\t\tnotifications: {},\n\t};\n}\n\nfunction cloneProjection(state: TaskRuntimeProjection): TaskRuntimeProjection {\n\treturn structuredClone(state);\n}\n\nfunction projectionFromSnapshot(projection: JsonObject, throughOrdinal: number): TaskRuntimeProjection {\n\tconst candidate = record(projection, \"orchestration projection snapshot\");\n\tif (candidate.lastOrdinal !== throughOrdinal) {\n\t\tthrow new DurableTaskRuntimeError(\"Orchestration projection snapshot ordinal does not match its baseline.\");\n\t}\n\tfor (const field of [\n\t\t\"agents\",\n\t\t\"objectives\",\n\t\t\"tasks\",\n\t\t\"attempts\",\n\t\t\"checkpoints\",\n\t\t\"approvals\",\n\t\t\"notifications\",\n\t] as const) {\n\t\trecord(candidate[field], `orchestration projection snapshot.${field}`);\n\t}\n\treturn structuredClone(candidate) as unknown as TaskRuntimeProjection;\n}\n\nfunction record(value: unknown, label: string): Record<string, unknown> {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) {\n\t\tthrow new DurableTaskRuntimeError(`${label} is not an object.`);\n\t}\n\treturn value as Record<string, unknown>;\n}\n\nfunction string(value: unknown, label: string): string {\n\tif (typeof value !== \"string\" || value.length === 0) throw new DurableTaskRuntimeError(`${label} is required.`);\n\treturn value;\n}\n\nfunction number(value: unknown, label: string): number {\n\tif (typeof value !== \"number\" || !Number.isFinite(value)) throw new DurableTaskRuntimeError(`${label} is invalid.`);\n\treturn value;\n}\n\nfunction boolean(value: unknown, label: string): boolean {\n\tif (typeof value !== \"boolean\") throw new DurableTaskRuntimeError(`${label} is invalid.`);\n\treturn value;\n}\n\nfunction assertRiskBudget(budget: RiskBudget | undefined, label: string): void {\n\ttry {\n\t\tvalidateRiskBudget(budget ?? {}, label);\n\t} catch (error) {\n\t\tthrow new DurableTaskRuntimeError(error instanceof Error ? error.message : String(error));\n\t}\n}\n\nfunction stringArray(value: unknown, label: string): string[] {\n\tif (!Array.isArray(value) || !value.every((entry) => typeof entry === \"string\")) {\n\t\tthrow new DurableTaskRuntimeError(`${label} must be a string array.`);\n\t}\n\treturn [...value];\n}\n\nconst DISPATCH_FIELDS = new Set([\n\t\"taskId\",\n\t\"profileId\",\n\t\"instructions\",\n\t\"resourcePointerIds\",\n\t\"executionKind\",\n\t\"logicalLaneId\",\n\t\"dispatchSequence\",\n\t\"provider\",\n\t\"authorizationId\",\n\t\"worktreeLaneKey\",\n\t\"executionContract\",\n]);\n\nfunction dispatchFromValue(value: unknown, label: string): OrchestrationDispatchRequest {\n\tconst dispatch = record(value, label);\n\tconst unsupportedField = Object.keys(dispatch).find((field) => !DISPATCH_FIELDS.has(field));\n\tif (unsupportedField) throw new DurableTaskRuntimeError(`${label}.${unsupportedField} is unsupported.`);\n\tconst executionKind = dispatch.executionKind;\n\tif (executionKind !== undefined && executionKind !== \"in-process\" && executionKind !== \"managed-process\") {\n\t\tthrow new DurableTaskRuntimeError(`${label}.executionKind is invalid.`);\n\t}\n\tfor (const field of [\"logicalLaneId\", \"provider\", \"authorizationId\", \"worktreeLaneKey\"] as const) {\n\t\tif (dispatch[field] !== undefined && typeof dispatch[field] !== \"string\") {\n\t\t\tthrow new DurableTaskRuntimeError(`${label}.${field} is invalid.`);\n\t\t}\n\t}\n\tif (\n\t\tdispatch.dispatchSequence !== undefined &&\n\t\t(!Number.isSafeInteger(dispatch.dispatchSequence) || Number(dispatch.dispatchSequence) < 1)\n\t) {\n\t\tthrow new DurableTaskRuntimeError(`${label}.dispatchSequence is invalid.`);\n\t}\n\tlet executionContract: WorkerExecutionContract | undefined;\n\ttry {\n\t\texecutionContract = dispatch.executionContract\n\t\t\t? parseWorkerExecutionContract(dispatch.executionContract)\n\t\t\t: undefined;\n\t} catch (error) {\n\t\tthrow new DurableTaskRuntimeError(error instanceof Error ? error.message : String(error));\n\t}\n\tif (executionContract && executionKind === \"managed-process\") {\n\t\tthrow new DurableTaskRuntimeError(`${label} cannot combine a worker execution contract with managed execution.`);\n\t}\n\treturn {\n\t\ttaskId: string(dispatch.taskId, `${label}.taskId`),\n\t\tprofileId: string(dispatch.profileId, `${label}.profileId`),\n\t\tinstructions: string(dispatch.instructions, `${label}.instructions`),\n\t\tresourcePointerIds: stringArray(dispatch.resourcePointerIds, `${label}.resourcePointerIds`),\n\t\t...(executionKind ? { executionKind } : {}),\n\t\t...(typeof dispatch.logicalLaneId === \"string\" ? { logicalLaneId: dispatch.logicalLaneId } : {}),\n\t\t...(typeof dispatch.dispatchSequence === \"number\" ? { dispatchSequence: dispatch.dispatchSequence } : {}),\n\t\t...(typeof dispatch.provider === \"string\" ? { provider: dispatch.provider } : {}),\n\t\t...(typeof dispatch.authorizationId === \"string\" ? { authorizationId: dispatch.authorizationId } : {}),\n\t\t...(typeof dispatch.worktreeLaneKey === \"string\" ? { worktreeLaneKey: dispatch.worktreeLaneKey } : {}),\n\t\t...(executionContract ? { executionContract } : {}),\n\t};\n}\n\nfunction objectiveFromPayload(payload: JsonObject): ObjectiveContract {\n\treturn structuredClone(record(payload.objective, \"objective\")) as unknown as ObjectiveContract;\n}\n\nfunction evidenceFromPayload(payload: JsonObject): EvidenceContract {\n\treturn structuredClone(record(payload.evidence, \"evidence\")) as unknown as EvidenceContract;\n}\n\nfunction assertAcceptanceCriteria(criteria: readonly AcceptanceCriterion[]): void {\n\tconst criterionIds = criteria.map((criterion) => criterion.id);\n\tif (\n\t\tcriterionIds.some((id) => !id.trim()) ||\n\t\tnew Set(criterionIds).size !== criterionIds.length ||\n\t\tcriteria.some((criterion) => !criterion.description.trim())\n\t) {\n\t\tthrow new DurableTaskRuntimeError(\"Objective acceptance criteria require unique ids and descriptions.\");\n\t}\n}\n\nfunction taskFromPayload(payload: JsonObject): TaskContract {\n\treturn structuredClone(record(payload.task, \"task\")) as unknown as TaskContract;\n}\n\nfunction leaseFromPayload(payload: JsonObject): AttemptLease {\n\tconst lease = record(payload.lease, \"lease\");\n\treturn {\n\t\tleaseId: string(lease.leaseId, \"lease.leaseId\"),\n\t\tattemptId: string(lease.attemptId, \"lease.attemptId\"),\n\t\townerId: string(lease.ownerId, \"lease.ownerId\"),\n\t\tfencingToken: number(lease.fencingToken, \"lease.fencingToken\"),\n\t\tissuedAt: string(lease.issuedAt, \"lease.issuedAt\"),\n\t\texpiresAt: string(lease.expiresAt, \"lease.expiresAt\"),\n\t};\n}\n\nfunction checkpointFromPayload(payload: JsonObject): AttemptCheckpoint {\n\tconst checkpoint = record(payload.checkpoint, \"checkpoint\");\n\treturn {\n\t\tcheckpointId: string(checkpoint.checkpointId, \"checkpoint.checkpointId\"),\n\t\tattemptId: string(checkpoint.attemptId, \"checkpoint.attemptId\"),\n\t\tfencingToken: number(checkpoint.fencingToken, \"checkpoint.fencingToken\"),\n\t\tsummary: string(checkpoint.summary, \"checkpoint.summary\"),\n\t\tartifactIds: stringArray(checkpoint.artifactIds, \"checkpoint.artifactIds\"),\n\t\tevidenceIds: stringArray(checkpoint.evidenceIds, \"checkpoint.evidenceIds\"),\n\t\tcreatedAt: string(checkpoint.createdAt, \"checkpoint.createdAt\"),\n\t};\n}\n\nfunction resultFromPayload(payload: JsonObject): WorkerResultContract {\n\treturn structuredClone(record(payload.result, \"result\")) as unknown as WorkerResultContract;\n}\n\nfunction agentFromPayload(payload: JsonObject): AgentBindingContract {\n\treturn structuredClone(record(payload.agent, \"agent\")) as unknown as AgentBindingContract;\n}\n\nfunction approvalFromPayload(payload: JsonObject): ApprovalRequestContract {\n\tconst approval = record(payload.approval, \"approval\");\n\tconst capabilities = stringArray(approval.requestedCapabilities, \"approval.requestedCapabilities\");\n\tif (!capabilities.every(isHarnessCapability)) {\n\t\tthrow new DurableTaskRuntimeError(\"Approval contains an unknown capability.\");\n\t}\n\tconst requestedBudget = approval.requestedBudget\n\t\t? (structuredClone(record(approval.requestedBudget, \"approval.requestedBudget\")) as RiskBudget)\n\t\t: undefined;\n\tassertRiskBudget(requestedBudget, \"approval.requestedBudget\");\n\tif (capabilities.length === 0 && !requestedBudget) {\n\t\tthrow new DurableTaskRuntimeError(\"Approval must request capabilities or budget.\");\n\t}\n\tif (approval.schemaVersion !== ORCHESTRATION_SCHEMA_VERSION) {\n\t\tthrow new DurableTaskRuntimeError(\"Approval schema version is invalid.\");\n\t}\n\treturn {\n\t\tschemaVersion: ORCHESTRATION_SCHEMA_VERSION,\n\t\tapprovalId: string(approval.approvalId, \"approval.approvalId\"),\n\t\tobjectiveId: string(approval.objectiveId, \"approval.objectiveId\"),\n\t\t...(typeof approval.taskId === \"string\" ? { taskId: string(approval.taskId, \"approval.taskId\") } : {}),\n\t\t...(typeof approval.attemptId === \"string\"\n\t\t\t? { attemptId: string(approval.attemptId, \"approval.attemptId\") }\n\t\t\t: {}),\n\t\treasonCode: string(approval.reasonCode, \"approval.reasonCode\"),\n\t\tsummary: string(approval.summary, \"approval.summary\"),\n\t\trequestedCapabilities: capabilities,\n\t\t...(requestedBudget ? { requestedBudget } : {}),\n\t\treversible: boolean(approval.reversible, \"approval.reversible\"),\n\t\tcreatedAt: string(approval.createdAt, \"approval.createdAt\"),\n\t};\n}\n\nfunction approvalResolutionFromPayload(payload: JsonObject): ApprovalResolutionContract {\n\tconst resolution = record(payload.resolution, \"resolution\");\n\tif (resolution.schemaVersion !== ORCHESTRATION_SCHEMA_VERSION) {\n\t\tthrow new DurableTaskRuntimeError(\"Approval resolution schema version is invalid.\");\n\t}\n\tconst outcome = string(resolution.outcome, \"resolution.outcome\");\n\tif (outcome !== \"approved\" && outcome !== \"rejected\") {\n\t\tthrow new DurableTaskRuntimeError(`Unknown approval outcome '${outcome}'.`);\n\t}\n\treturn {\n\t\tschemaVersion: ORCHESTRATION_SCHEMA_VERSION,\n\t\tapprovalId: string(resolution.approvalId, \"resolution.approvalId\"),\n\t\toutcome,\n\t\treasonCode: string(resolution.reasonCode, \"resolution.reasonCode\"),\n\t\tresolvedAt: string(resolution.resolvedAt, \"resolution.resolvedAt\"),\n\t};\n}\n\nfunction updateObjectiveStatus(\n\tstate: TaskRuntimeProjection,\n\tobjectiveId: string,\n\tstatus: ObjectiveStatus,\n\tat: string,\n): void {\n\tconst current = state.objectives[objectiveId];\n\tif (!current) throw new DurableTaskRuntimeError(`Unknown objective '${objectiveId}'.`);\n\t(state.objectives as Record<string, ObjectiveRuntimeState>)[objectiveId] = {\n\t\t...current,\n\t\tobjective: { ...current.objective, status, updatedAt: at },\n\t};\n}\n\nfunction terminalAttemptStatus(status: AttemptStatus): boolean {\n\treturn [\"completed\", \"partial\", \"blocked\", \"failed\", \"cancelled\", \"expired\"].includes(status);\n}\n\nfunction cancelOpenObjectiveWork(\n\tstate: TaskRuntimeProjection,\n\tobjectiveId: string,\n\tat: string,\n\treasonCode: string,\n): void {\n\tconst objective = state.objectives[objectiveId];\n\tconst tasks = state.tasks as Record<string, TaskRuntimeState>;\n\tconst attempts = state.attempts as Record<string, AttemptRuntimeState>;\n\tfor (const taskId of objective?.taskIds ?? []) {\n\t\tconst taskState = tasks[taskId];\n\t\tif (taskState && ![\"completed\", \"failed\", \"cancelled\"].includes(taskState.task.status)) {\n\t\t\ttasks[taskId] = {\n\t\t\t\t...taskState,\n\t\t\t\ttask: { ...taskState.task, status: \"cancelled\", updatedAt: at },\n\t\t\t};\n\t\t}\n\t\tfor (const attemptId of taskState?.attemptIds ?? []) {\n\t\t\tconst attempt = attempts[attemptId];\n\t\t\tif (attempt && !terminalAttemptStatus(attempt.status)) {\n\t\t\t\tattempts[attemptId] = { ...attempt, status: \"cancelled\", reasonCode, updatedAt: at };\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction taskStatusForResult(status: WorkerResultContract[\"status\"]): OrchestrationTaskStatus {\n\tif (status === \"completed\") return \"completed\";\n\tif (status === \"failed\") return \"failed\";\n\tif (status === \"cancelled\") return \"cancelled\";\n\treturn \"blocked\";\n}\n\nfunction missingTrustedCriteria(result: WorkerResultContract, criterionIds: readonly string[]): string[] {\n\tconst proven = new Set(\n\t\tresult.evidence.flatMap((evidence) => (evidence.trusted && evidence.criterionId ? [evidence.criterionId] : [])),\n\t);\n\treturn criterionIds.filter((criterionId) => !proven.has(criterionId));\n}\n\nfunction refreshReadyTasks(state: TaskRuntimeProjection, objectiveId: string, at: string): void {\n\tconst objective = state.objectives[objectiveId];\n\tif (!objective || objective.objective.status !== \"active\") return;\n\tconst mutableTasks = state.tasks as Record<string, TaskRuntimeState>;\n\tfor (const taskId of objective.taskIds) {\n\t\tconst current = mutableTasks[taskId];\n\t\tif (!current || current.task.status !== \"pending\") continue;\n\t\tif (current.task.dependsOn.every((dependencyId) => mutableTasks[dependencyId]?.task.status === \"completed\")) {\n\t\t\tmutableTasks[taskId] = { ...current, task: { ...current.task, status: \"ready\", updatedAt: at } };\n\t\t}\n\t}\n}\n\nexport function reduceOrchestrationEvent(\n\tprojection: TaskRuntimeProjection,\n\tevent: OrchestrationEvent,\n): TaskRuntimeProjection {\n\tif (event.ordinal <= projection.lastOrdinal) return projection;\n\tconst state = cloneProjection(projection);\n\tconst agents = state.agents as Record<string, AgentBindingContract>;\n\tconst objectives = state.objectives as Record<string, ObjectiveRuntimeState>;\n\tconst tasks = state.tasks as Record<string, TaskRuntimeState>;\n\tconst attempts = state.attempts as Record<string, AttemptRuntimeState>;\n\tconst checkpoints = state.checkpoints as Record<string, AttemptCheckpoint>;\n\tconst approvals = state.approvals as Record<string, ApprovalRuntimeState>;\n\tconst notifications = state.notifications as Record<string, NotificationRuntimeState>;\n\n\tswitch (event.type) {\n\t\tcase \"objective.created\": {\n\t\t\tconst objective = objectiveFromPayload(event.payload);\n\t\t\tif (objectives[objective.objectiveId]) {\n\t\t\t\tthrow new DurableTaskRuntimeError(`Objective '${objective.objectiveId}' was created more than once.`);\n\t\t\t}\n\t\t\tobjectives[objective.objectiveId] = { objective, taskIds: [], evidence: [] };\n\t\t\tbreak;\n\t\t}\n\t\tcase \"objective.updated\": {\n\t\t\tconst objective = objectiveFromPayload(event.payload);\n\t\t\tconst current = objectives[event.aggregateId];\n\t\t\tif (!current) throw new DurableTaskRuntimeError(`Unknown objective '${event.aggregateId}'.`);\n\t\t\tif (objective.objectiveId !== event.aggregateId) {\n\t\t\t\tthrow new DurableTaskRuntimeError(\n\t\t\t\t\t`Updated objective id '${objective.objectiveId}' does not match aggregate.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tobjectives[event.aggregateId] = { ...current, objective };\n\t\t\tbreak;\n\t\t}\n\t\tcase \"objective.evidence_recorded\": {\n\t\t\tconst evidence = evidenceFromPayload(event.payload);\n\t\t\tconst current = objectives[event.aggregateId];\n\t\t\tif (!current) throw new DurableTaskRuntimeError(`Unknown objective '${event.aggregateId}'.`);\n\t\t\tconst existing = current.evidence.find((candidate) => candidate.evidenceId === evidence.evidenceId);\n\t\t\tif (existing && !isDeepStrictEqual(existing, evidence)) {\n\t\t\t\tthrow new DurableTaskRuntimeError(`Objective evidence '${evidence.evidenceId}' has conflicting content.`);\n\t\t\t}\n\t\t\tif (!existing) objectives[event.aggregateId] = { ...current, evidence: [...current.evidence, evidence] };\n\t\t\tbreak;\n\t\t}\n\t\tcase \"objective.paused\":\n\t\t\tupdateObjectiveStatus(state, event.aggregateId, \"paused\", event.occurredAt);\n\t\t\tbreak;\n\t\tcase \"objective.resumed\":\n\t\t\tupdateObjectiveStatus(state, event.aggregateId, \"active\", event.occurredAt);\n\t\t\trefreshReadyTasks(state, event.aggregateId, event.occurredAt);\n\t\t\tbreak;\n\t\tcase \"objective.completed\":\n\t\t\tupdateObjectiveStatus(state, event.aggregateId, \"completed\", event.occurredAt);\n\t\t\tcancelOpenObjectiveWork(state, event.aggregateId, event.occurredAt, \"objective_completed\");\n\t\t\tbreak;\n\t\tcase \"objective.cancelled\": {\n\t\t\tupdateObjectiveStatus(state, event.aggregateId, \"cancelled\", event.occurredAt);\n\t\t\tcancelOpenObjectiveWork(state, event.aggregateId, event.occurredAt, \"objective_cancelled\");\n\t\t\tbreak;\n\t\t}\n\t\tcase \"task.created\": {\n\t\t\tconst task = taskFromPayload(event.payload);\n\t\t\tconst objective = objectives[task.objectiveId];\n\t\t\tif (!objective) throw new DurableTaskRuntimeError(`Task '${task.taskId}' references an unknown objective.`);\n\t\t\tif (tasks[task.taskId]) throw new DurableTaskRuntimeError(`Task '${task.taskId}' was created more than once.`);\n\t\t\ttasks[task.taskId] = { task, attemptIds: [] };\n\t\t\tobjectives[task.objectiveId] = { ...objective, taskIds: [...objective.taskIds, task.taskId] };\n\t\t\trefreshReadyTasks(state, task.objectiveId, event.occurredAt);\n\t\t\tbreak;\n\t\t}\n\t\tcase \"task.ready\": {\n\t\t\tconst taskId = string(event.payload.taskId, \"task.ready.taskId\");\n\t\t\tconst current = tasks[taskId];\n\t\t\tif (!current) throw new DurableTaskRuntimeError(`Unknown task '${taskId}'.`);\n\t\t\ttasks[taskId] = { ...current, task: { ...current.task, status: \"ready\", updatedAt: event.occurredAt } };\n\t\t\tbreak;\n\t\t}\n\t\tcase \"task.failed\": {\n\t\t\tconst taskId = string(event.payload.taskId, \"task.failed.taskId\");\n\t\t\tconst current = tasks[taskId];\n\t\t\tif (!current) throw new DurableTaskRuntimeError(`Unknown task '${taskId}'.`);\n\t\t\ttasks[taskId] = { ...current, task: { ...current.task, status: \"failed\", updatedAt: event.occurredAt } };\n\t\t\tbreak;\n\t\t}\n\t\tcase \"task.verification_finished\": {\n\t\t\tconst taskId = string(event.payload.taskId, \"task.verification_finished.taskId\");\n\t\t\tconst verifierTaskId = string(event.payload.verifierTaskId, \"task.verification_finished.verifierTaskId\");\n\t\t\tconst verifierAttemptId = string(\n\t\t\t\tevent.payload.verifierAttemptId,\n\t\t\t\t\"task.verification_finished.verifierAttemptId\",\n\t\t\t);\n\t\t\tconst verdict = string(event.payload.verdict, \"task.verification_finished.verdict\");\n\t\t\tif (verdict !== \"accepted\" && verdict !== \"rejected\" && verdict !== \"inconclusive\") {\n\t\t\t\tthrow new DurableTaskRuntimeError(`Unknown verification verdict '${verdict}'.`);\n\t\t\t}\n\t\t\tconst current = tasks[taskId];\n\t\t\tif (!current) throw new DurableTaskRuntimeError(`Unknown task '${taskId}'.`);\n\t\t\tconst reasonCode = string(event.payload.reasonCode, \"task.verification_finished.reasonCode\");\n\t\t\ttasks[taskId] = {\n\t\t\t\t...current,\n\t\t\t\ttask: {\n\t\t\t\t\t...current.task,\n\t\t\t\t\tstatus: verdict === \"accepted\" ? \"completed\" : \"blocked\",\n\t\t\t\t\tupdatedAt: event.occurredAt,\n\t\t\t\t},\n\t\t\t\tverification: {\n\t\t\t\t\tverifierTaskId,\n\t\t\t\t\tverifierAttemptId,\n\t\t\t\t\tverdict,\n\t\t\t\t\treasonCode,\n\t\t\t\t\tcompletedAt: event.occurredAt,\n\t\t\t\t},\n\t\t\t};\n\t\t\trefreshReadyTasks(state, current.task.objectiveId, event.occurredAt);\n\t\t\tbreak;\n\t\t}\n\t\tcase \"agent.registered\": {\n\t\t\tconst agent = agentFromPayload(event.payload);\n\t\t\tif (agents[agent.agentId])\n\t\t\t\tthrow new DurableTaskRuntimeError(`Agent '${agent.agentId}' was registered more than once.`);\n\t\t\tagents[agent.agentId] = agent;\n\t\t\tbreak;\n\t\t}\n\t\tcase \"agent.suspended\": {\n\t\t\tconst agentId = string(event.payload.agentId, \"agent.suspended.agentId\");\n\t\t\tconst agent = agents[agentId];\n\t\t\tif (!agent) throw new DurableTaskRuntimeError(`Unknown agent '${agentId}'.`);\n\t\t\tagents[agentId] = { ...agent, status: \"suspended\", updatedAt: event.occurredAt };\n\t\t\tbreak;\n\t\t}\n\t\tcase \"agent.resume_requested\": {\n\t\t\tconst agentId = string(event.payload.agentId, \"agent.resume_requested.agentId\");\n\t\t\tconst agent = agents[agentId];\n\t\t\tif (!agent) throw new DurableTaskRuntimeError(`Unknown agent '${agentId}'.`);\n\t\t\tagents[agentId] = { ...agent, status: \"resuming\", updatedAt: event.occurredAt };\n\t\t\tbreak;\n\t\t}\n\t\tcase \"agent.resumed\": {\n\t\t\tconst agentId = string(event.payload.agentId, \"agent.resumed.agentId\");\n\t\t\tconst attemptId = string(event.payload.attemptId, \"agent.resumed.attemptId\");\n\t\t\tconst agent = agents[agentId];\n\t\t\tif (!agent) throw new DurableTaskRuntimeError(`Unknown agent '${agentId}'.`);\n\t\t\tagents[agentId] = { ...agent, status: \"active\", activeAttemptId: attemptId, updatedAt: event.occurredAt };\n\t\t\tbreak;\n\t\t}\n\t\tcase \"attempt.queued\": {\n\t\t\tconst attemptId = string(event.payload.attemptId, \"attempt.queued.attemptId\");\n\t\t\tconst taskId = string(event.payload.taskId, \"attempt.queued.taskId\");\n\t\t\tconst task = tasks[taskId];\n\t\t\tif (!task) throw new DurableTaskRuntimeError(`Attempt '${attemptId}' references an unknown task.`);\n\t\t\tif (attempts[attemptId])\n\t\t\t\tthrow new DurableTaskRuntimeError(`Attempt '${attemptId}' was queued more than once.`);\n\t\t\tconst dispatch = dispatchFromValue(event.payload.dispatch, \"attempt.queued.dispatch\");\n\t\t\tif (dispatch.taskId !== taskId) {\n\t\t\t\tthrow new DurableTaskRuntimeError(`Attempt '${attemptId}' dispatch task does not match its task.`);\n\t\t\t}\n\t\t\tif (\n\t\t\t\tdispatch.executionContract &&\n\t\t\t\t(dispatch.executionContract.worker.profile.profileId !== dispatch.profileId ||\n\t\t\t\t\tdispatch.executionContract.worker.profile.role !== task.task.role)\n\t\t\t) {\n\t\t\t\tthrow new DurableTaskRuntimeError(`Attempt '${attemptId}' execution contract does not match its dispatch.`);\n\t\t\t}\n\t\t\tattempts[attemptId] = {\n\t\t\t\tattemptId,\n\t\t\t\ttaskId,\n\t\t\t\tdispatch,\n\t\t\t\tstatus: \"queued\",\n\t\t\t\t...(typeof event.payload.grantId === \"string\" ? { grantId: event.payload.grantId } : {}),\n\t\t\t\tcheckpointIds: [],\n\t\t\t\tcreatedAt: event.occurredAt,\n\t\t\t\tupdatedAt: event.occurredAt,\n\t\t\t};\n\t\t\ttasks[taskId] = {\n\t\t\t\t...task,\n\t\t\t\ttask: { ...task.task, status: \"running\", updatedAt: event.occurredAt },\n\t\t\t\tattemptIds: [...task.attemptIds, attemptId],\n\t\t\t};\n\t\t\tbreak;\n\t\t}\n\t\tcase \"attempt.grant_bound\": {\n\t\t\tconst attemptId = string(event.payload.attemptId, \"attempt.grant_bound.attemptId\");\n\t\t\tconst attempt = attempts[attemptId];\n\t\t\tif (!attempt) throw new DurableTaskRuntimeError(`Unknown attempt '${attemptId}'.`);\n\t\t\tconst grant = event.payload.grant\n\t\t\t\t? (structuredClone(record(event.payload.grant, \"attempt.grant_bound.grant\")) as unknown as ExecutionGrant)\n\t\t\t\t: undefined;\n\t\t\tattempts[attemptId] = {\n\t\t\t\t...attempt,\n\t\t\t\tgrantId: grant?.grantId ?? string(event.payload.grantId, \"attempt.grant_bound.grantId\"),\n\t\t\t\t...(grant ? { grant } : {}),\n\t\t\t\tupdatedAt: event.occurredAt,\n\t\t\t};\n\t\t\tbreak;\n\t\t}\n\t\tcase \"attempt.leased\": {\n\t\t\tconst lease = leaseFromPayload(event.payload);\n\t\t\tconst attempt = attempts[lease.attemptId];\n\t\t\tif (!attempt) throw new DurableTaskRuntimeError(`Unknown attempt '${lease.attemptId}'.`);\n\t\t\tconst agentId = typeof event.payload.agentId === \"string\" ? event.payload.agentId : undefined;\n\t\t\tif (agentId) {\n\t\t\t\tconst agent = agents[agentId];\n\t\t\t\tif (!agent) throw new DurableTaskRuntimeError(`Unknown agent '${agentId}'.`);\n\t\t\t\tagents[agentId] = {\n\t\t\t\t\t...agent,\n\t\t\t\t\tstatus: \"active\",\n\t\t\t\t\tactiveAttemptId: lease.attemptId,\n\t\t\t\t\tupdatedAt: event.occurredAt,\n\t\t\t\t};\n\t\t\t}\n\t\t\tattempts[lease.attemptId] = {\n\t\t\t\t...attempt,\n\t\t\t\tstatus: \"leased\",\n\t\t\t\tlease,\n\t\t\t\t...(agentId ? { agentId } : {}),\n\t\t\t\tupdatedAt: event.occurredAt,\n\t\t\t};\n\t\t\tbreak;\n\t\t}\n\t\tcase \"attempt.started\": {\n\t\t\tconst attemptId = string(event.payload.attemptId, \"attempt.started.attemptId\");\n\t\t\tconst attempt = attempts[attemptId];\n\t\t\tif (!attempt) throw new DurableTaskRuntimeError(`Unknown attempt '${attemptId}'.`);\n\t\t\tattempts[attemptId] = { ...attempt, status: \"running\", updatedAt: event.occurredAt };\n\t\t\tbreak;\n\t\t}\n\t\tcase \"attempt.checkpointed\": {\n\t\t\tconst checkpoint = checkpointFromPayload(event.payload);\n\t\t\tconst attempt = attempts[checkpoint.attemptId];\n\t\t\tif (!attempt) throw new DurableTaskRuntimeError(`Unknown attempt '${checkpoint.attemptId}'.`);\n\t\t\tcheckpoints[checkpoint.checkpointId] = checkpoint;\n\t\t\tattempts[checkpoint.attemptId] = {\n\t\t\t\t...attempt,\n\t\t\t\tcheckpointIds: [...attempt.checkpointIds, checkpoint.checkpointId],\n\t\t\t\tupdatedAt: event.occurredAt,\n\t\t\t};\n\t\t\tif (attempt.agentId) {\n\t\t\t\tconst agent = agents[attempt.agentId];\n\t\t\t\tif (agent) {\n\t\t\t\t\tagents[attempt.agentId] = {\n\t\t\t\t\t\t...agent,\n\t\t\t\t\t\tresumeContext: { ...agent.resumeContext, latestCheckpointId: checkpoint.checkpointId },\n\t\t\t\t\t\tupdatedAt: event.occurredAt,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tcase \"attempt.suspended\": {\n\t\t\tconst attemptId = string(event.payload.attemptId, \"attempt.suspended.attemptId\");\n\t\t\tconst attempt = attempts[attemptId];\n\t\t\tif (!attempt) throw new DurableTaskRuntimeError(`Unknown attempt '${attemptId}'.`);\n\t\t\tattempts[attemptId] = {\n\t\t\t\t...attempt,\n\t\t\t\tstatus: \"suspended\",\n\t\t\t\t...(typeof event.payload.reasonCode === \"string\" ? { reasonCode: event.payload.reasonCode } : {}),\n\t\t\t\tupdatedAt: event.occurredAt,\n\t\t\t};\n\t\t\tif (attempt.agentId) {\n\t\t\t\tconst agent = agents[attempt.agentId];\n\t\t\t\tif (agent) agents[attempt.agentId] = { ...agent, status: \"suspended\", updatedAt: event.occurredAt };\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tcase \"attempt.resumed\": {\n\t\t\tconst lease = leaseFromPayload(event.payload);\n\t\t\tconst agentId = string(event.payload.agentId, \"attempt.resumed.agentId\");\n\t\t\tconst attempt = attempts[lease.attemptId];\n\t\t\tconst agent = agents[agentId];\n\t\t\tif (!attempt) throw new DurableTaskRuntimeError(`Unknown attempt '${lease.attemptId}'.`);\n\t\t\tif (!agent) throw new DurableTaskRuntimeError(`Unknown agent '${agentId}'.`);\n\t\t\tattempts[lease.attemptId] = {\n\t\t\t\t...attempt,\n\t\t\t\tstatus: \"leased\",\n\t\t\t\tagentId,\n\t\t\t\tlease,\n\t\t\t\tupdatedAt: event.occurredAt,\n\t\t\t};\n\t\t\tagents[agentId] = {\n\t\t\t\t...agent,\n\t\t\t\tstatus: \"active\",\n\t\t\t\tactiveAttemptId: lease.attemptId,\n\t\t\t\tupdatedAt: event.occurredAt,\n\t\t\t};\n\t\t\tbreak;\n\t\t}\n\t\tcase \"attempt.cancelled\": {\n\t\t\tconst attemptId = string(event.payload.attemptId, \"attempt.cancelled.attemptId\");\n\t\t\tconst attempt = attempts[attemptId];\n\t\t\tif (!attempt) throw new DurableTaskRuntimeError(`Unknown attempt '${attemptId}'.`);\n\t\t\tattempts[attemptId] = {\n\t\t\t\t...attempt,\n\t\t\t\tstatus: \"cancelled\",\n\t\t\t\treasonCode: string(event.payload.reasonCode, \"attempt.cancelled.reasonCode\"),\n\t\t\t\tupdatedAt: event.occurredAt,\n\t\t\t};\n\t\t\tconst task = tasks[attempt.taskId];\n\t\t\tif (task) {\n\t\t\t\ttasks[attempt.taskId] = {\n\t\t\t\t\t...task,\n\t\t\t\t\ttask: { ...task.task, status: \"cancelled\", updatedAt: event.occurredAt },\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (attempt.agentId) {\n\t\t\t\tconst agent = agents[attempt.agentId];\n\t\t\t\tif (agent) {\n\t\t\t\t\tconst next = { ...agent, status: \"registered\" as const, updatedAt: event.occurredAt };\n\t\t\t\t\tdelete next.activeAttemptId;\n\t\t\t\t\tagents[attempt.agentId] = next;\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tcase \"attempt.finished\": {\n\t\t\tconst result = resultFromPayload(event.payload);\n\t\t\tconst attempt = attempts[result.attemptId];\n\t\t\tif (!attempt) throw new DurableTaskRuntimeError(`Unknown attempt '${result.attemptId}'.`);\n\t\t\tattempts[result.attemptId] = { ...attempt, status: result.status, result, updatedAt: event.occurredAt };\n\t\t\tconst task = tasks[result.taskId];\n\t\t\tif (!task) throw new DurableTaskRuntimeError(`Unknown task '${result.taskId}'.`);\n\t\t\ttasks[result.taskId] = {\n\t\t\t\t...task,\n\t\t\t\ttask: { ...task.task, status: taskStatusForResult(result.status), updatedAt: event.occurredAt },\n\t\t\t};\n\t\t\tif (attempt.agentId) {\n\t\t\t\tconst agent = agents[attempt.agentId];\n\t\t\t\tif (agent) {\n\t\t\t\t\tconst next = { ...agent, status: \"registered\" as const, updatedAt: event.occurredAt };\n\t\t\t\t\tdelete next.activeAttemptId;\n\t\t\t\t\tagents[attempt.agentId] = next;\n\t\t\t\t}\n\t\t\t}\n\t\t\trefreshReadyTasks(state, task.task.objectiveId, event.occurredAt);\n\t\t\tbreak;\n\t\t}\n\t\tcase \"attempt.lease_expired\": {\n\t\t\tconst attemptId = string(event.payload.attemptId, \"attempt.lease_expired.attemptId\");\n\t\t\tconst attempt = attempts[attemptId];\n\t\t\tif (!attempt) throw new DurableTaskRuntimeError(`Unknown attempt '${attemptId}'.`);\n\t\t\tattempts[attemptId] = {\n\t\t\t\t...attempt,\n\t\t\t\tstatus: \"expired\",\n\t\t\t\t...(typeof event.payload.reasonCode === \"string\" ? { reasonCode: event.payload.reasonCode } : {}),\n\t\t\t\tupdatedAt: event.occurredAt,\n\t\t\t};\n\t\t\tconst task = tasks[attempt.taskId];\n\t\t\tif (task)\n\t\t\t\ttasks[attempt.taskId] = { ...task, task: { ...task.task, status: \"ready\", updatedAt: event.occurredAt } };\n\t\t\tbreak;\n\t\t}\n\t\tcase \"approval.requested\": {\n\t\t\tconst approval = approvalFromPayload(event.payload);\n\t\t\tif (approvals[approval.approvalId]) {\n\t\t\t\tthrow new DurableTaskRuntimeError(`Approval '${approval.approvalId}' was requested more than once.`);\n\t\t\t}\n\t\t\tapprovals[approval.approvalId] = { request: approval, status: \"pending\" };\n\t\t\tconst notificationId = `approval-requested:${approval.approvalId}`;\n\t\t\tif (notifications[notificationId]) {\n\t\t\t\tthrow new DurableTaskRuntimeError(`Notification '${notificationId}' already exists.`);\n\t\t\t}\n\t\t\tnotifications[notificationId] = {\n\t\t\t\tnotificationId,\n\t\t\t\tobjectiveId: approval.objectiveId,\n\t\t\t\t...(approval.attemptId ? { attemptId: approval.attemptId } : {}),\n\t\t\t\tstatus: \"pending\",\n\t\t\t\tmessage: approval.summary,\n\t\t\t\tcreatedAt: event.occurredAt,\n\t\t\t};\n\t\t\tbreak;\n\t\t}\n\t\tcase \"approval.resolved\": {\n\t\t\tconst resolution = approvalResolutionFromPayload(event.payload);\n\t\t\tconst approval = approvals[resolution.approvalId];\n\t\t\tif (!approval) throw new DurableTaskRuntimeError(`Unknown approval '${resolution.approvalId}'.`);\n\t\t\tapprovals[resolution.approvalId] = {\n\t\t\t\t...approval,\n\t\t\t\tstatus: resolution.outcome,\n\t\t\t\tresolution,\n\t\t\t};\n\t\t\tconst approvalNotification = notifications[`approval-requested:${resolution.approvalId}`];\n\t\t\tif (approvalNotification?.status === \"pending\") {\n\t\t\t\tnotifications[approvalNotification.notificationId] = {\n\t\t\t\t\t...approvalNotification,\n\t\t\t\t\tstatus: \"delivered\",\n\t\t\t\t\tdeliveredAt: event.occurredAt,\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (resolution.outcome === \"rejected\" && approval.request.attemptId) {\n\t\t\t\tconst attempt = attempts[approval.request.attemptId];\n\t\t\t\tif (attempt && !terminalAttemptStatus(attempt.status)) {\n\t\t\t\t\tattempts[attempt.attemptId] = {\n\t\t\t\t\t\t...attempt,\n\t\t\t\t\t\tstatus: \"blocked\",\n\t\t\t\t\t\treasonCode: \"approval_rejected\",\n\t\t\t\t\t\tupdatedAt: event.occurredAt,\n\t\t\t\t\t};\n\t\t\t\t\tconst task = tasks[attempt.taskId];\n\t\t\t\t\tif (task) {\n\t\t\t\t\t\ttasks[attempt.taskId] = {\n\t\t\t\t\t\t\t...task,\n\t\t\t\t\t\t\ttask: { ...task.task, status: \"blocked\", updatedAt: event.occurredAt },\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tcase \"notification.enqueued\": {\n\t\t\tconst notificationId = string(event.payload.notificationId, \"notification.enqueued.notificationId\");\n\t\t\tnotifications[notificationId] = {\n\t\t\t\tnotificationId,\n\t\t\t\tobjectiveId: string(event.payload.objectiveId, \"notification.enqueued.objectiveId\"),\n\t\t\t\t...(typeof event.payload.attemptId === \"string\" ? { attemptId: event.payload.attemptId } : {}),\n\t\t\t\tstatus: \"pending\",\n\t\t\t\tmessage: string(event.payload.message, \"notification.enqueued.message\"),\n\t\t\t\tcreatedAt: event.occurredAt,\n\t\t\t};\n\t\t\tbreak;\n\t\t}\n\t\tcase \"notification.delivered\": {\n\t\t\tconst notificationId = string(event.payload.notificationId, \"notification.delivered.notificationId\");\n\t\t\tconst notification = notifications[notificationId];\n\t\t\tif (!notification) throw new DurableTaskRuntimeError(`Unknown notification '${notificationId}'.`);\n\t\t\tnotifications[notificationId] = { ...notification, status: \"delivered\", deliveredAt: event.occurredAt };\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn { ...state, lastOrdinal: event.ordinal };\n}\n\nexport function projectOrchestrationEvents(events: readonly OrchestrationEvent[]): TaskRuntimeProjection {\n\treturn events.reduce(reduceOrchestrationEvent, emptyProjection());\n}\n\nexport class DurableTaskRuntime {\n\tprivate readonly store: OrchestrationEventStore;\n\tprivate readonly now: () => number;\n\tprivate readonly createId: () => string;\n\tprivate state: TaskRuntimeProjection;\n\n\tconstructor(options: DurableTaskRuntimeOptions) {\n\t\tthis.store = options.store;\n\t\tthis.now = options.now ?? Date.now;\n\t\tthis.createId = options.createId ?? randomUUID;\n\t\tconst snapshot = this.store.readProjectionSnapshot();\n\t\tif (snapshot) {\n\t\t\tthis.state = projectionFromSnapshot(snapshot.projection, snapshot.throughOrdinal);\n\t\t} else {\n\t\t\tconst events = this.store.readAll();\n\t\t\t// Compaction may install a baseline between the first snapshot read and readAll(). In that\n\t\t\t// case readAll() returns only the new tail, which must be applied to that baseline rather\n\t\t\t// than projected as a standalone history.\n\t\t\tconst snapshotAfterRead = this.store.readProjectionSnapshot();\n\t\t\tthis.state = snapshotAfterRead\n\t\t\t\t? events\n\t\t\t\t\t\t.filter((event) => event.ordinal > snapshotAfterRead.throughOrdinal)\n\t\t\t\t\t\t.reduce(\n\t\t\t\t\t\t\treduceOrchestrationEvent,\n\t\t\t\t\t\t\tprojectionFromSnapshot(snapshotAfterRead.projection, snapshotAfterRead.throughOrdinal),\n\t\t\t\t\t\t)\n\t\t\t\t: projectOrchestrationEvents(events);\n\t\t}\n\t\tthis.refresh();\n\t}\n\n\tgetSnapshot(): TaskRuntimeProjection {\n\t\tthis.refresh();\n\t\treturn cloneProjection(this.state);\n\t}\n\n\tregisterAgent(input: RegisterAgentInput): AgentBindingContract {\n\t\tthis.refresh();\n\t\tconst now = this.nowIso();\n\t\tlet identity: AgentIdentityContract;\n\t\ttry {\n\t\t\tidentity = createAgentIdentity(input.agentId ?? `agent-${this.createId()}`, input.resumeContext);\n\t\t} catch (error) {\n\t\t\tthrow new DurableTaskRuntimeError(error instanceof Error ? error.message : String(error));\n\t\t}\n\t\tconst agent: AgentBindingContract = {\n\t\t\tschemaVersion: ORCHESTRATION_SCHEMA_VERSION,\n\t\t\t...identity,\n\t\t\trole: input.role,\n\t\t\tstatus: \"registered\",\n\t\t\tcreatedAt: now,\n\t\t\tupdatedAt: now,\n\t\t};\n\t\tif (this.state.agents[agent.agentId])\n\t\t\tthrow new DurableTaskRuntimeError(`Agent '${agent.agentId}' already exists.`);\n\t\tthis.commit({\n\t\t\ttype: \"agent.registered\",\n\t\t\taggregateId: agent.agentId,\n\t\t\tactor: \"runtime\",\n\t\t\tidempotencyKey: `agent-registered:${agent.agentId}`,\n\t\t\tpayload: toJsonObject({ agent }),\n\t\t});\n\t\treturn structuredClone(agent);\n\t}\n\n\tcreateObjective(input: CreateObjectiveInput): ObjectiveContract {\n\t\tthis.refresh();\n\t\tassertRiskBudget(input.riskBudget, \"objective.riskBudget\");\n\t\tconst now = this.nowIso();\n\t\tconst objective: ObjectiveContract = {\n\t\t\tschemaVersion: ORCHESTRATION_SCHEMA_VERSION,\n\t\t\tobjectiveId: input.objectiveId ?? `objective-${this.createId()}`,\n\t\t\ttitle: input.title.trim(),\n\t\t\tdescription: input.description.trim(),\n\t\t\tstatus: \"active\",\n\t\t\tconstraints: [...(input.constraints ?? [])],\n\t\t\tacceptanceCriteria: structuredClone(input.acceptanceCriteria ?? []),\n\t\t\triskBudget: { ...(input.riskBudget ?? {}) },\n\t\t\tcreatedAt: now,\n\t\t\tupdatedAt: now,\n\t\t};\n\t\tif (!objective.title || !objective.description)\n\t\t\tthrow new DurableTaskRuntimeError(\"Objective title and description are required.\");\n\t\tassertAcceptanceCriteria(objective.acceptanceCriteria);\n\t\tif (this.state.objectives[objective.objectiveId]) {\n\t\t\tthrow new DurableTaskRuntimeError(`Objective '${objective.objectiveId}' already exists.`);\n\t\t}\n\t\tthis.commit({\n\t\t\ttype: \"objective.created\",\n\t\t\taggregateId: objective.objectiveId,\n\t\t\tactor: \"kernel\",\n\t\t\tidempotencyKey: `objective-created:${objective.objectiveId}`,\n\t\t\tpayload: toJsonObject({ objective }),\n\t\t});\n\t\treturn structuredClone(objective);\n\t}\n\n\t/** Create or synchronize owner-authored objective metadata without disturbing lifecycle or task state. */\n\tensureObjective(input: CreateObjectiveInput & { objectiveId: string }): ObjectiveContract {\n\t\tthis.refresh();\n\t\tconst current = this.state.objectives[input.objectiveId];\n\t\tif (!current) return this.createObjective(input);\n\t\tassertRiskBudget(input.riskBudget, \"objective.riskBudget\");\n\t\tconst acceptanceCriteria = structuredClone(input.acceptanceCriteria ?? []);\n\t\tassertAcceptanceCriteria(acceptanceCriteria);\n\t\tconst nextFields = {\n\t\t\ttitle: input.title.trim(),\n\t\t\tdescription: input.description.trim(),\n\t\t\tconstraints: [...(input.constraints ?? [])],\n\t\t\tacceptanceCriteria,\n\t\t\triskBudget: { ...(input.riskBudget ?? {}) },\n\t\t};\n\t\tif (!nextFields.title || !nextFields.description) {\n\t\t\tthrow new DurableTaskRuntimeError(\"Objective title and description are required.\");\n\t\t}\n\t\tconst currentFields = {\n\t\t\ttitle: current.objective.title,\n\t\t\tdescription: current.objective.description,\n\t\t\tconstraints: current.objective.constraints,\n\t\t\tacceptanceCriteria: current.objective.acceptanceCriteria,\n\t\t\triskBudget: current.objective.riskBudget,\n\t\t};\n\t\tif (isDeepStrictEqual(currentFields, nextFields)) return structuredClone(current.objective);\n\n\t\tconst retainedCriterionIds = new Set(acceptanceCriteria.map((criterion) => criterion.id));\n\t\tconst referencedRemovedIds = current.taskIds.flatMap((taskId) =>\n\t\t\t(this.state.tasks[taskId]?.task.acceptanceCriterionIds ?? []).filter(\n\t\t\t\t(criterionId) => !retainedCriterionIds.has(criterionId),\n\t\t\t),\n\t\t);\n\t\tif (referencedRemovedIds.length > 0) {\n\t\t\tthrow new DurableTaskRuntimeError(\n\t\t\t\t`Cannot remove acceptance criteria referenced by tasks: ${[...new Set(referencedRemovedIds)].join(\", \")}.`,\n\t\t\t);\n\t\t}\n\t\tconst objective: ObjectiveContract = {\n\t\t\t...current.objective,\n\t\t\t...nextFields,\n\t\t\tupdatedAt: this.nowIso(),\n\t\t};\n\t\tthis.commit({\n\t\t\ttype: \"objective.updated\",\n\t\t\taggregateId: objective.objectiveId,\n\t\t\tactor: \"kernel\",\n\t\t\tpayload: toJsonObject({ objective }),\n\t\t});\n\t\treturn structuredClone(objective);\n\t}\n\n\trecordObjectiveEvidence(objectiveId: string, evidence: EvidenceContract): EvidenceContract {\n\t\tthis.refresh();\n\t\tconst objective = this.requireObjective(objectiveId);\n\t\tconst existing = objective.evidence.find((candidate) => candidate.evidenceId === evidence.evidenceId);\n\t\tif (existing) {\n\t\t\tif (!isDeepStrictEqual(existing, evidence)) {\n\t\t\t\tthrow new DurableTaskRuntimeError(`Objective evidence '${evidence.evidenceId}' has conflicting content.`);\n\t\t\t}\n\t\t\treturn structuredClone(existing);\n\t\t}\n\t\tif (!evidence.evidenceId.trim() || !evidence.summary.trim() || !evidence.createdAt.trim()) {\n\t\t\tthrow new DurableTaskRuntimeError(\"Objective evidence requires an id, summary, and creation time.\");\n\t\t}\n\t\tif (\n\t\t\tevidence.criterionId &&\n\t\t\t!objective.objective.acceptanceCriteria.some((criterion) => criterion.id === evidence.criterionId)\n\t\t) {\n\t\t\tthrow new DurableTaskRuntimeError(\n\t\t\t\t`Objective evidence references unknown acceptance criterion '${evidence.criterionId}'.`,\n\t\t\t);\n\t\t}\n\t\tthis.commit({\n\t\t\ttype: \"objective.evidence_recorded\",\n\t\t\taggregateId: objectiveId,\n\t\t\tactor: \"kernel\",\n\t\t\tidempotencyKey: `objective-evidence-recorded:${objectiveId}:${evidence.evidenceId}`,\n\t\t\tpayload: toJsonObject({ evidence }),\n\t\t});\n\t\treturn structuredClone(evidence);\n\t}\n\n\tcreateTask(input: CreateTaskInput): TaskContract {\n\t\tthis.refresh();\n\t\tassertRiskBudget(input.riskBudget, \"task.riskBudget\");\n\t\tconst objectiveState = this.state.objectives[input.objectiveId];\n\t\tif (!objectiveState) throw new DurableTaskRuntimeError(`Unknown objective '${input.objectiveId}'.`);\n\t\tif (objectiveState.objective.status !== \"active\") {\n\t\t\tthrow new DurableTaskRuntimeError(`Objective '${input.objectiveId}' is not active.`);\n\t\t}\n\t\tconst dependsOn = [...new Set(input.dependsOn ?? [])];\n\t\tconst acceptanceCriterionIds = [...new Set(input.acceptanceCriterionIds ?? [])];\n\t\tconst objectiveCriterionIds = new Set(\n\t\t\tobjectiveState.objective.acceptanceCriteria.map((criterion) => criterion.id),\n\t\t);\n\t\tconst unknownCriterionIds = acceptanceCriterionIds.filter(\n\t\t\t(criterionId) => !objectiveCriterionIds.has(criterionId),\n\t\t);\n\t\tif (unknownCriterionIds.length > 0) {\n\t\t\tthrow new DurableTaskRuntimeError(\n\t\t\t\t`Task references unknown acceptance criteria: ${unknownCriterionIds.join(\", \")}.`,\n\t\t\t);\n\t\t}\n\t\tfor (const dependencyId of dependsOn) {\n\t\t\tconst dependency = this.state.tasks[dependencyId];\n\t\t\tif (!dependency || dependency.task.objectiveId !== input.objectiveId) {\n\t\t\t\tthrow new DurableTaskRuntimeError(\n\t\t\t\t\t`Task dependency '${dependencyId}' is not in objective '${input.objectiveId}'.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tif (input.verificationOfTaskId) {\n\t\t\tconst subject = this.state.tasks[input.verificationOfTaskId];\n\t\t\tif (!subject || subject.task.objectiveId !== input.objectiveId) {\n\t\t\t\tthrow new DurableTaskRuntimeError(\n\t\t\t\t\t`Verification subject '${input.verificationOfTaskId}' is not in objective '${input.objectiveId}'.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (input.role !== \"verifier\") {\n\t\t\t\tthrow new DurableTaskRuntimeError(\"Only verifier tasks may declare verificationOfTaskId.\");\n\t\t\t}\n\t\t\tif (subject.task.role === \"verifier\") {\n\t\t\t\tthrow new DurableTaskRuntimeError(\"A verifier task cannot independently verify another verifier task.\");\n\t\t\t}\n\t\t}\n\t\tconst now = this.nowIso();\n\t\tconst task: TaskContract = {\n\t\t\tschemaVersion: ORCHESTRATION_SCHEMA_VERSION,\n\t\t\ttaskId: input.taskId ?? `task-${this.createId()}`,\n\t\t\tobjectiveId: input.objectiveId,\n\t\t\ttitle: input.title.trim(),\n\t\t\tdescription: input.description.trim(),\n\t\t\trole: input.role,\n\t\t\tstatus: dependsOn.length === 0 ? \"ready\" : \"pending\",\n\t\t\tdependsOn,\n\t\t\trequiredCapabilities: [...new Set(input.requiredCapabilities ?? [])],\n\t\t\tacceptanceCriterionIds,\n\t\t\t...(input.verificationOfTaskId ? { verificationOfTaskId: input.verificationOfTaskId } : {}),\n\t\t\triskBudget: { ...(input.riskBudget ?? {}) },\n\t\t\tcreatedAt: now,\n\t\t\tupdatedAt: now,\n\t\t};\n\t\tif (!task.title || !task.description)\n\t\t\tthrow new DurableTaskRuntimeError(\"Task title and description are required.\");\n\t\tif (this.state.tasks[task.taskId]) throw new DurableTaskRuntimeError(`Task '${task.taskId}' already exists.`);\n\t\tthis.commit({\n\t\t\ttype: \"task.created\",\n\t\t\taggregateId: task.objectiveId,\n\t\t\tactor: \"runtime\",\n\t\t\tidempotencyKey: `task-created:${task.taskId}`,\n\t\t\tpayload: toJsonObject({ task }),\n\t\t});\n\t\treturn structuredClone(this.state.tasks[task.taskId]!.task);\n\t}\n\n\tqueueAttempt(taskId: string, dispatch: OrchestrationDispatchRequest, grantId?: string): AttemptRuntimeState {\n\t\tthis.refresh();\n\t\tconst task = this.requireDispatchableTask(taskId);\n\t\tconst pendingApproval = this.pendingApprovalForTask(taskId);\n\t\tif (pendingApproval) {\n\t\t\tthrow new DurableTaskRuntimeError(\n\t\t\t\t`Task '${taskId}' is awaiting approval '${pendingApproval.request.approvalId}'.`,\n\t\t\t);\n\t\t}\n\t\tconst normalizedDispatch = dispatchFromValue(dispatch, \"dispatch\");\n\t\tif (normalizedDispatch.taskId !== taskId) {\n\t\t\tthrow new DurableTaskRuntimeError(\"Dispatch taskId does not match the queued task.\");\n\t\t}\n\t\tif (\n\t\t\tnormalizedDispatch.executionContract &&\n\t\t\t(normalizedDispatch.executionContract.worker.profile.profileId !== normalizedDispatch.profileId ||\n\t\t\t\tnormalizedDispatch.executionContract.worker.profile.role !== task.task.role)\n\t\t) {\n\t\t\tthrow new DurableTaskRuntimeError(\"Execution contract does not match the dispatch profile and task role.\");\n\t\t}\n\t\tconst objective = this.state.objectives[task.task.objectiveId]!.objective;\n\t\tconst attemptCeilings = [task.task.riskBudget.maxAttempts, objective.riskBudget.maxAttempts].filter(\n\t\t\t(value): value is number => value !== undefined,\n\t\t);\n\t\tconst maxAttempts = attemptCeilings.length > 0 ? Math.min(...attemptCeilings) : undefined;\n\t\tif (maxAttempts !== undefined && task.attemptIds.length >= maxAttempts) {\n\t\t\tthrow new DurableTaskRuntimeError(`Task '${taskId}' exhausted its ${maxAttempts} attempt budget.`);\n\t\t}\n\t\tconst attemptId = `attempt-${this.createId()}`;\n\t\tthis.commit({\n\t\t\ttype: \"attempt.queued\",\n\t\t\taggregateId: taskId,\n\t\t\tactor: \"runtime\",\n\t\t\tidempotencyKey: `attempt-queued:${attemptId}`,\n\t\t\tpayload: toJsonObject({ attemptId, taskId, dispatch: normalizedDispatch, ...(grantId ? { grantId } : {}) }),\n\t\t});\n\t\treturn structuredClone(this.state.attempts[attemptId]!);\n\t}\n\n\tbindAttemptGrant(attemptId: string, grant: ExecutionGrant): AttemptRuntimeState {\n\t\tthis.refresh();\n\t\tconst attempt = this.requireAttempt(attemptId);\n\t\tif (![\"queued\", \"leased\", \"running\"].includes(attempt.status)) {\n\t\t\tthrow new DurableTaskRuntimeError(`Attempt '${attemptId}' cannot bind a grant from '${attempt.status}'.`);\n\t\t}\n\t\tif (!grant.grantId.trim()) throw new DurableTaskRuntimeError(\"Grant id is required.\");\n\t\tconst task = this.state.tasks[attempt.taskId];\n\t\tif (\n\t\t\t!task ||\n\t\t\tgrant.schemaVersion !== ORCHESTRATION_SCHEMA_VERSION ||\n\t\t\tgrant.attemptId !== attemptId ||\n\t\t\tgrant.taskId !== attempt.taskId ||\n\t\t\tgrant.objectiveId !== task.task.objectiveId ||\n\t\t\tgrant.role !== task.task.role\n\t\t) {\n\t\t\tthrow new DurableTaskRuntimeError(\"Execution grant target does not match the attempt.\");\n\t\t}\n\t\tconst approval = this.approvalForAttempt(attemptId);\n\t\tif (approval?.status === \"pending\") {\n\t\t\tthrow new DurableTaskRuntimeError(\n\t\t\t\t`Attempt '${attemptId}' is awaiting approval '${approval.request.approvalId}'.`,\n\t\t\t);\n\t\t}\n\t\tif (approval?.status === \"rejected\") {\n\t\t\tthrow new DurableTaskRuntimeError(`Approval '${approval.request.approvalId}' was rejected.`);\n\t\t}\n\t\tif (attempt.grantId === grant.grantId) {\n\t\t\tif (attempt.grant && !isDeepStrictEqual(attempt.grant, grant)) {\n\t\t\t\tthrow new DurableTaskRuntimeError(`Attempt '${attemptId}' grant has conflicting content.`);\n\t\t\t}\n\t\t\treturn structuredClone(attempt);\n\t\t}\n\t\tif (attempt.grantId) throw new DurableTaskRuntimeError(`Attempt '${attemptId}' already has a different grant.`);\n\t\tthis.commit({\n\t\t\ttype: \"attempt.grant_bound\",\n\t\t\taggregateId: attemptId,\n\t\t\tactor: \"policy\",\n\t\t\tidempotencyKey: `attempt-grant-bound:${attemptId}:${grant.grantId}`,\n\t\t\tpayload: toJsonObject({ attemptId, grant }),\n\t\t});\n\t\treturn structuredClone(this.state.attempts[attemptId]!);\n\t}\n\n\tleaseAttempt(attemptId: string, ownerId: string, ttlMs: number, agentId?: string): AttemptLease {\n\t\tthis.refresh();\n\t\tconst attempt = this.requireAttempt(attemptId);\n\t\tif (attempt.status !== \"queued\") throw new DurableTaskRuntimeError(`Attempt '${attemptId}' is not queued.`);\n\t\tthis.requireActiveObjectiveForAttempt(attempt);\n\t\tconst approval = this.approvalForAttempt(attemptId);\n\t\tif (approval?.status === \"pending\") {\n\t\t\tthrow new DurableTaskRuntimeError(\n\t\t\t\t`Attempt '${attemptId}' is awaiting approval '${approval.request.approvalId}'.`,\n\t\t\t);\n\t\t}\n\t\tif (!attempt.grantId) {\n\t\t\tthrow new DurableTaskRuntimeError(`Attempt '${attemptId}' requires an execution grant before leasing.`);\n\t\t}\n\t\tif (agentId) {\n\t\t\tconst agent = this.state.agents[agentId];\n\t\t\tif (!agent) throw new DurableTaskRuntimeError(`Unknown agent '${agentId}'.`);\n\t\t\tif (agent.status !== \"registered\") throw new DurableTaskRuntimeError(`Agent '${agentId}' is not idle.`);\n\t\t\tconst task = this.state.tasks[attempt.taskId];\n\t\t\tif (!task || task.task.role !== agent.role)\n\t\t\t\tthrow new DurableTaskRuntimeError(`Agent '${agentId}' role does not match task.`);\n\t\t}\n\t\tif (!Number.isFinite(ttlMs) || ttlMs <= 0) throw new DurableTaskRuntimeError(\"Lease TTL must be positive.\");\n\t\tconst issuedAtMs = this.now();\n\t\tconst lease: AttemptLease = {\n\t\t\tleaseId: `lease-${this.createId()}`,\n\t\t\tattemptId,\n\t\t\townerId,\n\t\t\tfencingToken: (attempt.lease?.fencingToken ?? 0) + 1,\n\t\t\tissuedAt: new Date(issuedAtMs).toISOString(),\n\t\t\texpiresAt: new Date(issuedAtMs + ttlMs).toISOString(),\n\t\t};\n\t\tthis.commit({\n\t\t\ttype: \"attempt.leased\",\n\t\t\taggregateId: attemptId,\n\t\t\tactor: \"runtime\",\n\t\t\tidempotencyKey: `attempt-leased:${lease.leaseId}`,\n\t\t\tpayload: toJsonObject({ lease, ...(agentId ? { agentId } : {}) }),\n\t\t});\n\t\treturn structuredClone(lease);\n\t}\n\n\tstartAttempt(attemptId: string, leaseId: string, fencingToken: number): AttemptRuntimeState {\n\t\tthis.refresh();\n\t\tconst attempt = this.requireLiveLease(attemptId, leaseId, fencingToken);\n\t\tthis.requireActiveObjectiveForAttempt(attempt);\n\t\tif (attempt.status !== \"leased\") throw new DurableTaskRuntimeError(`Attempt '${attemptId}' is not leased.`);\n\t\tthis.commit({\n\t\t\ttype: \"attempt.started\",\n\t\t\taggregateId: attemptId,\n\t\t\tactor: \"worker\",\n\t\t\tidempotencyKey: `attempt-started:${attemptId}:${fencingToken}`,\n\t\t\tpayload: toJsonObject({ attemptId, leaseId, fencingToken }),\n\t\t});\n\t\treturn structuredClone(this.state.attempts[attemptId]!);\n\t}\n\n\tcheckpointAttempt(args: {\n\t\tattemptId: string;\n\t\tleaseId: string;\n\t\tfencingToken: number;\n\t\tsummary: string;\n\t\tartifactIds?: readonly string[];\n\t\tevidenceIds?: readonly string[];\n\t}): AttemptCheckpoint {\n\t\tthis.refresh();\n\t\tconst attempt = this.requireLiveLease(args.attemptId, args.leaseId, args.fencingToken);\n\t\tif (attempt.status !== \"running\")\n\t\t\tthrow new DurableTaskRuntimeError(`Attempt '${args.attemptId}' is not running.`);\n\t\tconst checkpoint: AttemptCheckpoint = {\n\t\t\tcheckpointId: `checkpoint-${this.createId()}`,\n\t\t\tattemptId: args.attemptId,\n\t\t\tfencingToken: args.fencingToken,\n\t\t\tsummary: args.summary.trim(),\n\t\t\tartifactIds: [...(args.artifactIds ?? [])],\n\t\t\tevidenceIds: [...(args.evidenceIds ?? [])],\n\t\t\tcreatedAt: this.nowIso(),\n\t\t};\n\t\tif (!checkpoint.summary) throw new DurableTaskRuntimeError(\"Checkpoint summary is required.\");\n\t\tthis.commit({\n\t\t\ttype: \"attempt.checkpointed\",\n\t\t\taggregateId: args.attemptId,\n\t\t\tactor: \"worker\",\n\t\t\tidempotencyKey: `attempt-checkpointed:${checkpoint.checkpointId}`,\n\t\t\tpayload: toJsonObject({ checkpoint, leaseId: args.leaseId }),\n\t\t});\n\t\treturn structuredClone(checkpoint);\n\t}\n\n\tfinishAttempt(result: WorkerResultContract): AttemptRuntimeState {\n\t\tthis.refresh();\n\t\tconst attempt = this.requireLiveLease(result.attemptId, result.leaseId, result.fencingToken);\n\t\tif (attempt.status !== \"running\" && attempt.status !== \"leased\") {\n\t\t\tthrow new DurableTaskRuntimeError(`Attempt '${result.attemptId}' cannot finish from '${attempt.status}'.`);\n\t\t}\n\t\tif (attempt.taskId !== result.taskId)\n\t\t\tthrow new DurableTaskRuntimeError(\"Worker result taskId does not match attempt.\");\n\t\tconst task = this.state.tasks[attempt.taskId];\n\t\tif (!task || task.task.objectiveId !== result.objectiveId) {\n\t\t\tthrow new DurableTaskRuntimeError(\"Worker result objectiveId does not match attempt.\");\n\t\t}\n\t\tif (result.status === \"completed\") {\n\t\t\tconst missingCriteria = missingTrustedCriteria(result, task.task.acceptanceCriterionIds);\n\t\t\tif (missingCriteria.length > 0) {\n\t\t\t\tthrow new DurableTaskRuntimeError(\n\t\t\t\t\t`Completed result lacks trusted evidence for acceptance criteria: ${missingCriteria.join(\", \")}.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tthis.commit({\n\t\t\ttype: \"attempt.finished\",\n\t\t\taggregateId: result.attemptId,\n\t\t\tactor: \"worker\",\n\t\t\tidempotencyKey: `attempt-finished:${result.resultId}`,\n\t\t\tpayload: toJsonObject({ result }),\n\t\t});\n\t\treturn structuredClone(this.state.attempts[result.attemptId]!);\n\t}\n\n\tfinishVerification(args: {\n\t\ttaskId: string;\n\t\tverifierTaskId: string;\n\t\tverifierAttemptId: string;\n\t\tverdict: \"accepted\" | \"rejected\" | \"inconclusive\";\n\t\treasonCode: string;\n\t}): TaskRuntimeState {\n\t\tthis.refresh();\n\t\tconst subject = this.state.tasks[args.taskId];\n\t\tconst verifierTask = this.state.tasks[args.verifierTaskId];\n\t\tconst verifierAttempt = this.state.attempts[args.verifierAttemptId];\n\t\tif (!subject) throw new DurableTaskRuntimeError(`Unknown verification subject '${args.taskId}'.`);\n\t\tif (!verifierTask || verifierTask.task.verificationOfTaskId !== args.taskId) {\n\t\t\tthrow new DurableTaskRuntimeError(`Task '${args.verifierTaskId}' is not the verifier for '${args.taskId}'.`);\n\t\t}\n\t\tif (!verifierAttempt || verifierAttempt.taskId !== args.verifierTaskId) {\n\t\t\tthrow new DurableTaskRuntimeError(`Unknown verifier attempt '${args.verifierAttemptId}'.`);\n\t\t}\n\t\tif (args.verdict === \"inconclusive\") {\n\t\t\tif (\n\t\t\t\tverifierAttempt.status === \"queued\" ||\n\t\t\t\tverifierAttempt.status === \"leased\" ||\n\t\t\t\tverifierAttempt.status === \"running\"\n\t\t\t) {\n\t\t\t\tthrow new DurableTaskRuntimeError(`Verifier attempt '${args.verifierAttemptId}' is not terminal.`);\n\t\t\t}\n\t\t} else if (verifierAttempt.status !== \"completed\" || !verifierAttempt.result) {\n\t\t\tthrow new DurableTaskRuntimeError(`Verifier attempt '${args.verifierAttemptId}' is not completed.`);\n\t\t}\n\t\tif (subject.task.status !== \"blocked\") {\n\t\t\tthrow new DurableTaskRuntimeError(\n\t\t\t\t`Verification subject '${args.taskId}' cannot reconcile from '${subject.task.status}'.`,\n\t\t\t);\n\t\t}\n\t\tif (!args.reasonCode.trim()) throw new DurableTaskRuntimeError(\"Verification reason code is required.\");\n\t\tif (\n\t\t\targs.verdict === \"accepted\" &&\n\t\t\t!verifierAttempt.result?.evidence.some(\n\t\t\t\t(evidence) =>\n\t\t\t\t\tevidence.trusted && evidence.kind === \"review\" && evidence.metadata?.subjectTaskId === args.taskId,\n\t\t\t)\n\t\t) {\n\t\t\tthrow new DurableTaskRuntimeError(\n\t\t\t\t\"Accepted verification requires trusted review evidence for the subject task.\",\n\t\t\t);\n\t\t}\n\t\tthis.commit({\n\t\t\ttype: \"task.verification_finished\",\n\t\t\taggregateId: args.taskId,\n\t\t\tactor: \"runtime\",\n\t\t\tidempotencyKey: `task-verification-finished:${args.taskId}:${args.verifierAttemptId}`,\n\t\t\tpayload: toJsonObject({ ...args, reasonCode: args.reasonCode.trim() }),\n\t\t});\n\t\treturn structuredClone(this.state.tasks[args.taskId]!);\n\t}\n\n\tcancelAttempt(attemptId: string, reasonCode: string): AttemptRuntimeState {\n\t\tthis.refresh();\n\t\tconst attempt = this.requireAttempt(attemptId);\n\t\tif (terminalAttemptStatus(attempt.status)) return structuredClone(attempt);\n\t\tif (!reasonCode.trim()) throw new DurableTaskRuntimeError(\"Cancellation reason is required.\");\n\t\tthis.commit({\n\t\t\ttype: \"attempt.cancelled\",\n\t\t\taggregateId: attemptId,\n\t\t\tactor: \"runtime\",\n\t\t\tidempotencyKey: `attempt-cancelled:${attemptId}`,\n\t\t\tpayload: toJsonObject({ attemptId, reasonCode: reasonCode.trim() }),\n\t\t});\n\t\treturn structuredClone(this.state.attempts[attemptId]!);\n\t}\n\n\tfailTask(taskId: string, reasonCode: string): TaskContract {\n\t\tthis.refresh();\n\t\tconst task = this.state.tasks[taskId];\n\t\tif (!task) throw new DurableTaskRuntimeError(`Unknown task '${taskId}'.`);\n\t\tif ([\"completed\", \"failed\", \"cancelled\"].includes(task.task.status)) return structuredClone(task.task);\n\t\tif (!reasonCode.trim()) throw new DurableTaskRuntimeError(\"Task failure reason is required.\");\n\t\tthis.commit({\n\t\t\ttype: \"task.failed\",\n\t\t\taggregateId: taskId,\n\t\t\tactor: \"runtime\",\n\t\t\tidempotencyKey: `task-failed:${taskId}:${reasonCode.trim()}`,\n\t\t\tpayload: toJsonObject({ taskId, reasonCode: reasonCode.trim() }),\n\t\t});\n\t\treturn structuredClone(this.state.tasks[taskId]!.task);\n\t}\n\n\t/**\n\t * Recover unbound in-process work after a process restart. A completion has no resumable model\n\t * transcript, so its old lease is fenced and the task becomes dispatchable for a fresh attempt.\n\t * Agent-bound attempts are intentionally excluded: those must wake the same logical agent.\n\t */\n\trecoverInterruptedUnboundAttempts(shouldRecover: (attempt: AttemptRuntimeState) => boolean = () => true): string[] {\n\t\tthis.refresh();\n\t\tconst recovered: string[] = [];\n\t\tfor (const attempt of Object.values(this.state.attempts)) {\n\t\t\tif (\n\t\t\t\t(attempt.status !== \"leased\" && attempt.status !== \"running\") ||\n\t\t\t\tattempt.agentId ||\n\t\t\t\t!shouldRecover(attempt)\n\t\t\t) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthis.commit({\n\t\t\t\ttype: \"attempt.lease_expired\",\n\t\t\t\taggregateId: attempt.attemptId,\n\t\t\t\tactor: \"runtime\",\n\t\t\t\tidempotencyKey: `attempt-process-interrupted:${attempt.attemptId}:${attempt.lease?.leaseId ?? \"none\"}`,\n\t\t\t\tpayload: toJsonObject({\n\t\t\t\t\tattemptId: attempt.attemptId,\n\t\t\t\t\t...(attempt.lease ? { leaseId: attempt.lease.leaseId, fencingToken: attempt.lease.fencingToken } : {}),\n\t\t\t\t\treasonCode: \"worker_process_interrupted\",\n\t\t\t\t}),\n\t\t\t});\n\t\t\trecovered.push(attempt.attemptId);\n\t\t}\n\t\treturn recovered;\n\t}\n\n\texpireLeases(at = this.now()): string[] {\n\t\tthis.refresh();\n\t\tconst expired: string[] = [];\n\t\tfor (const attempt of Object.values(this.state.attempts)) {\n\t\t\tif ((attempt.status !== \"leased\" && attempt.status !== \"running\") || !attempt.lease) continue;\n\t\t\tif (Date.parse(attempt.lease.expiresAt) > at) continue;\n\t\t\tthis.commit({\n\t\t\t\ttype: attempt.agentId ? \"attempt.suspended\" : \"attempt.lease_expired\",\n\t\t\t\taggregateId: attempt.attemptId,\n\t\t\t\tactor: \"runtime\",\n\t\t\t\tidempotencyKey: `attempt-lease-expired:${attempt.lease.leaseId}`,\n\t\t\t\tpayload: toJsonObject({\n\t\t\t\t\tattemptId: attempt.attemptId,\n\t\t\t\t\tleaseId: attempt.lease.leaseId,\n\t\t\t\t\tfencingToken: attempt.lease.fencingToken,\n\t\t\t\t}),\n\t\t\t});\n\t\t\texpired.push(attempt.attemptId);\n\t\t}\n\t\treturn expired;\n\t}\n\n\trequestAgentResume(agentId: string): AgentBindingContract {\n\t\tthis.refresh();\n\t\tconst agent = this.state.agents[agentId];\n\t\tif (!agent) throw new DurableTaskRuntimeError(`Unknown agent '${agentId}'.`);\n\t\tif (agent.status !== \"suspended\") throw new DurableTaskRuntimeError(`Agent '${agentId}' is not suspended.`);\n\t\tthis.commit({\n\t\t\ttype: \"agent.resume_requested\",\n\t\t\taggregateId: agentId,\n\t\t\tactor: \"runtime\",\n\t\t\tidempotencyKey: `agent-resume-requested:${agentId}:${this.state.lastOrdinal}`,\n\t\t\tpayload: toJsonObject({ agentId }),\n\t\t});\n\t\treturn structuredClone(this.state.agents[agentId]!);\n\t}\n\n\tresumeAttempt(attemptId: string, agentId: string, ttlMs: number): AttemptLease {\n\t\tthis.refresh();\n\t\tconst attempt = this.requireAttempt(attemptId);\n\t\tconst agent = this.state.agents[agentId];\n\t\tif (attempt.status !== \"suspended\" || attempt.agentId !== agentId) {\n\t\t\tthrow new DurableTaskRuntimeError(`Attempt '${attemptId}' is not suspended for agent '${agentId}'.`);\n\t\t}\n\t\tif (!agent || agent.status !== \"resuming\")\n\t\t\tthrow new DurableTaskRuntimeError(`Agent '${agentId}' is not resuming.`);\n\t\tthis.requireActiveObjectiveForAttempt(attempt);\n\t\tif (!Number.isFinite(ttlMs) || ttlMs <= 0) throw new DurableTaskRuntimeError(\"Lease TTL must be positive.\");\n\t\tconst issuedAtMs = this.now();\n\t\tconst lease: AttemptLease = {\n\t\t\tleaseId: `lease-${this.createId()}`,\n\t\t\tattemptId,\n\t\t\townerId: agentId,\n\t\t\tfencingToken: (attempt.lease?.fencingToken ?? 0) + 1,\n\t\t\tissuedAt: new Date(issuedAtMs).toISOString(),\n\t\t\texpiresAt: new Date(issuedAtMs + ttlMs).toISOString(),\n\t\t};\n\t\tthis.commit({\n\t\t\ttype: \"attempt.resumed\",\n\t\t\taggregateId: attemptId,\n\t\t\tactor: \"runtime\",\n\t\t\tidempotencyKey: `attempt-resumed:${lease.leaseId}`,\n\t\t\tpayload: toJsonObject({ agentId, lease }),\n\t\t});\n\t\treturn structuredClone(lease);\n\t}\n\n\tpauseObjective(objectiveId: string): void {\n\t\tthis.transitionObjective(objectiveId, \"objective.paused\", \"paused\");\n\t}\n\n\tresumeObjective(objectiveId: string): void {\n\t\tthis.transitionObjective(objectiveId, \"objective.resumed\", \"active\");\n\t}\n\n\tcancelObjective(objectiveId: string): void {\n\t\tthis.transitionObjective(objectiveId, \"objective.cancelled\", \"cancelled\");\n\t}\n\n\tcompleteObjective(objectiveId: string): void {\n\t\tthis.refresh();\n\t\tconst objective = this.requireObjective(objectiveId);\n\t\tconst incomplete = objective.taskIds.filter((taskId) => this.state.tasks[taskId]?.task.status !== \"completed\");\n\t\tif (incomplete.length > 0) {\n\t\t\tthrow new DurableTaskRuntimeError(\n\t\t\t\t`Objective '${objectiveId}' has incomplete tasks: ${incomplete.join(\", \")}.`,\n\t\t\t);\n\t\t}\n\t\tconst requiredCriterionIds = objective.objective.acceptanceCriteria\n\t\t\t.filter((criterion) => criterion.required)\n\t\t\t.map((criterion) => criterion.id);\n\t\tconst evidence = [\n\t\t\t...objective.evidence,\n\t\t\t...objective.taskIds.flatMap((taskId) => {\n\t\t\t\tconst task = this.state.tasks[taskId];\n\t\t\t\treturn (\n\t\t\t\t\ttask?.attemptIds.flatMap((attemptId) => this.state.attempts[attemptId]?.result?.evidence ?? []) ?? []\n\t\t\t\t);\n\t\t\t}),\n\t\t];\n\t\tconst provenCriterionIds = new Set(\n\t\t\tevidence.flatMap((item) => (item.trusted && item.criterionId ? [item.criterionId] : [])),\n\t\t);\n\t\tconst unproven = requiredCriterionIds.filter((criterionId) => !provenCriterionIds.has(criterionId));\n\t\tif (unproven.length > 0) {\n\t\t\tthrow new DurableTaskRuntimeError(\n\t\t\t\t`Objective '${objectiveId}' lacks trusted evidence for required criteria: ${unproven.join(\", \")}.`,\n\t\t\t);\n\t\t}\n\t\tthis.transitionObjective(objectiveId, \"objective.completed\", \"completed\");\n\t}\n\n\tcompleteObjectiveFromOwner(objectiveId: string, acceptanceOverride: boolean): void {\n\t\tthis.refresh();\n\t\tconst objective = this.requireObjective(objectiveId);\n\t\tif (objective.objective.status === \"completed\") return;\n\t\tif (objective.objective.status === \"cancelled\") {\n\t\t\tthrow new DurableTaskRuntimeError(`Objective '${objectiveId}' is terminal.`);\n\t\t}\n\t\tif (!acceptanceOverride) {\n\t\t\tconst provenCriterionIds = new Set(\n\t\t\t\tobjective.evidence.flatMap((evidence) =>\n\t\t\t\t\tevidence.trusted && evidence.criterionId ? [evidence.criterionId] : [],\n\t\t\t\t),\n\t\t\t);\n\t\t\tconst unproven = objective.objective.acceptanceCriteria\n\t\t\t\t.filter((criterion) => criterion.required && !provenCriterionIds.has(criterion.id))\n\t\t\t\t.map((criterion) => criterion.id);\n\t\t\tif (unproven.length > 0) {\n\t\t\t\tthrow new DurableTaskRuntimeError(\n\t\t\t\t\t`Objective '${objectiveId}' lacks trusted owner evidence for required criteria: ${unproven.join(\", \")}.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tthis.transitionObjective(objectiveId, \"objective.completed\", \"completed\");\n\t}\n\n\trequestApproval(approval: ApprovalRequestContract): ApprovalRuntimeState {\n\t\tthis.refresh();\n\t\tconst normalized = approvalFromPayload(toJsonObject({ approval }));\n\t\tconst existing = this.state.approvals[normalized.approvalId];\n\t\tif (existing) {\n\t\t\tif (!isDeepStrictEqual(existing.request, normalized)) {\n\t\t\t\tthrow new DurableTaskRuntimeError(`Approval id '${normalized.approvalId}' has conflicting content.`);\n\t\t\t}\n\t\t\treturn structuredClone(existing);\n\t\t}\n\t\tthis.validateApprovalRequest(normalized);\n\t\tconst pendingForTarget = Object.values(this.state.approvals).find(\n\t\t\t(candidate) =>\n\t\t\t\tcandidate.status === \"pending\" &&\n\t\t\t\tcandidate.request.objectiveId === normalized.objectiveId &&\n\t\t\t\tcandidate.request.taskId === normalized.taskId &&\n\t\t\t\tcandidate.request.attemptId === normalized.attemptId,\n\t\t);\n\t\tif (pendingForTarget) {\n\t\t\tthrow new DurableTaskRuntimeError(`Target already awaits approval '${pendingForTarget.request.approvalId}'.`);\n\t\t}\n\t\tthis.commit({\n\t\t\ttype: \"approval.requested\",\n\t\t\taggregateId: normalized.attemptId ?? normalized.taskId ?? normalized.objectiveId,\n\t\t\tactor: \"policy\",\n\t\t\tidempotencyKey: `approval-requested:${normalized.approvalId}`,\n\t\t\tpayload: toJsonObject({ approval: normalized }),\n\t\t});\n\t\treturn structuredClone(this.state.approvals[normalized.approvalId]!);\n\t}\n\n\tresolveApproval(approvalId: string, outcome: ApprovalOutcome, reasonCode: string): ApprovalRuntimeState {\n\t\tthis.refresh();\n\t\tconst approval = this.state.approvals[approvalId];\n\t\tif (!approval) throw new DurableTaskRuntimeError(`Unknown approval '${approvalId}'.`);\n\t\tif (approval.status !== \"pending\") {\n\t\t\tif (approval.status === outcome) return structuredClone(approval);\n\t\t\tthrow new DurableTaskRuntimeError(`Approval '${approvalId}' was already ${approval.status}.`);\n\t\t}\n\t\tif (outcome !== \"approved\" && outcome !== \"rejected\") {\n\t\t\tthrow new DurableTaskRuntimeError(`Unknown approval outcome '${String(outcome)}'.`);\n\t\t}\n\t\tif (!reasonCode.trim()) throw new DurableTaskRuntimeError(\"Approval resolution reason is required.\");\n\t\tconst resolution: ApprovalResolutionContract = {\n\t\t\tschemaVersion: ORCHESTRATION_SCHEMA_VERSION,\n\t\t\tapprovalId,\n\t\t\toutcome,\n\t\t\treasonCode: reasonCode.trim(),\n\t\t\tresolvedAt: this.nowIso(),\n\t\t};\n\t\tthis.commit({\n\t\t\ttype: \"approval.resolved\",\n\t\t\taggregateId: approval.request.attemptId ?? approval.request.taskId ?? approval.request.objectiveId,\n\t\t\tactor: \"human\",\n\t\t\tidempotencyKey: `approval-resolved:${approvalId}`,\n\t\t\tpayload: toJsonObject({ resolution }),\n\t\t});\n\t\treturn structuredClone(this.state.approvals[approvalId]!);\n\t}\n\n\tenqueueNotification(args: {\n\t\tnotificationId?: string;\n\t\tobjectiveId: string;\n\t\tattemptId?: string;\n\t\tmessage: string;\n\t}): NotificationRuntimeState {\n\t\tthis.refresh();\n\t\tthis.requireObjective(args.objectiveId);\n\t\tconst notificationId = args.notificationId ?? `notification-${this.createId()}`;\n\t\tconst existing = this.state.notifications[notificationId];\n\t\tif (existing) return structuredClone(existing);\n\t\tthis.commit({\n\t\t\ttype: \"notification.enqueued\",\n\t\t\taggregateId: args.objectiveId,\n\t\t\tactor: \"runtime\",\n\t\t\tidempotencyKey: `notification-enqueued:${notificationId}`,\n\t\t\tpayload: toJsonObject({ ...args, notificationId }),\n\t\t});\n\t\treturn structuredClone(this.state.notifications[notificationId]!);\n\t}\n\n\tmarkNotificationDelivered(notificationId: string): NotificationRuntimeState {\n\t\tthis.refresh();\n\t\tconst notification = this.state.notifications[notificationId];\n\t\tif (!notification) throw new DurableTaskRuntimeError(`Unknown notification '${notificationId}'.`);\n\t\tif (notification.status === \"delivered\") return structuredClone(notification);\n\t\tthis.commit({\n\t\t\ttype: \"notification.delivered\",\n\t\t\taggregateId: notification.objectiveId,\n\t\t\tactor: \"runtime\",\n\t\t\tidempotencyKey: `notification-delivered:${notificationId}`,\n\t\t\tpayload: toJsonObject({ notificationId }),\n\t\t});\n\t\treturn structuredClone(this.state.notifications[notificationId]!);\n\t}\n\n\tprivate transitionObjective(\n\t\tobjectiveId: string,\n\t\ttype: \"objective.paused\" | \"objective.resumed\" | \"objective.cancelled\" | \"objective.completed\",\n\t\ttarget: ObjectiveStatus,\n\t): void {\n\t\tthis.refresh();\n\t\tconst objective = this.requireObjective(objectiveId);\n\t\tif (objective.objective.status === target) return;\n\t\tif ([\"completed\", \"cancelled\"].includes(objective.objective.status)) {\n\t\t\tthrow new DurableTaskRuntimeError(`Objective '${objectiveId}' is terminal.`);\n\t\t}\n\t\tthis.commit({\n\t\t\ttype,\n\t\t\taggregateId: objectiveId,\n\t\t\tactor: \"human\",\n\t\t\tidempotencyKey: `${type}:${objectiveId}:${this.state.lastOrdinal}`,\n\t\t\tpayload: {},\n\t\t});\n\t}\n\n\tprivate requireObjective(objectiveId: string): ObjectiveRuntimeState {\n\t\tconst objective = this.state.objectives[objectiveId];\n\t\tif (!objective) throw new DurableTaskRuntimeError(`Unknown objective '${objectiveId}'.`);\n\t\treturn objective;\n\t}\n\n\tprivate requireDispatchableTask(taskId: string): TaskRuntimeState {\n\t\tconst task = this.state.tasks[taskId];\n\t\tif (!task) throw new DurableTaskRuntimeError(`Unknown task '${taskId}'.`);\n\t\tconst objective = this.requireObjective(task.task.objectiveId);\n\t\tif (objective.objective.status !== \"active\") {\n\t\t\tthrow new DurableTaskRuntimeError(`Objective '${objective.objective.objectiveId}' is not active.`);\n\t\t}\n\t\tif (![\"ready\", \"blocked\", \"failed\"].includes(task.task.status)) {\n\t\t\tthrow new DurableTaskRuntimeError(`Task '${taskId}' is not dispatchable from '${task.task.status}'.`);\n\t\t}\n\t\treturn task;\n\t}\n\n\tprivate requireAttempt(attemptId: string): AttemptRuntimeState {\n\t\tconst attempt = this.state.attempts[attemptId];\n\t\tif (!attempt) throw new DurableTaskRuntimeError(`Unknown attempt '${attemptId}'.`);\n\t\treturn attempt;\n\t}\n\n\tprivate approvalForAttempt(attemptId: string): ApprovalRuntimeState | undefined {\n\t\treturn Object.values(this.state.approvals).find((approval) => approval.request.attemptId === attemptId);\n\t}\n\n\tprivate pendingApprovalForTask(taskId: string): ApprovalRuntimeState | undefined {\n\t\tconst task = this.state.tasks[taskId];\n\t\tif (!task) return undefined;\n\t\treturn Object.values(this.state.approvals).find(\n\t\t\t(approval) =>\n\t\t\t\tapproval.status === \"pending\" &&\n\t\t\t\tapproval.request.attemptId === undefined &&\n\t\t\t\tapproval.request.objectiveId === task.task.objectiveId &&\n\t\t\t\t(approval.request.taskId === undefined || approval.request.taskId === taskId),\n\t\t);\n\t}\n\n\tprivate requireActiveObjectiveForAttempt(attempt: AttemptRuntimeState): void {\n\t\tconst task = this.state.tasks[attempt.taskId];\n\t\tif (!task) throw new DurableTaskRuntimeError(`Unknown task '${attempt.taskId}'.`);\n\t\tconst objective = this.requireObjective(task.task.objectiveId).objective;\n\t\tif (objective.status !== \"active\") {\n\t\t\tthrow new DurableTaskRuntimeError(`Objective '${objective.objectiveId}' is not active.`);\n\t\t}\n\t}\n\n\tprivate validateApprovalRequest(approval: ApprovalRequestContract): void {\n\t\tconst objective = this.requireObjective(approval.objectiveId).objective;\n\t\tif (objective.status !== \"active\") {\n\t\t\tthrow new DurableTaskRuntimeError(`Objective '${approval.objectiveId}' is not active.`);\n\t\t}\n\t\tif (approval.attemptId && !approval.taskId) {\n\t\t\tthrow new DurableTaskRuntimeError(\"Attempt-scoped approval requires a taskId.\");\n\t\t}\n\t\tif (approval.taskId) {\n\t\t\tconst task = this.state.tasks[approval.taskId];\n\t\t\tif (!task || task.task.objectiveId !== approval.objectiveId) {\n\t\t\t\tthrow new DurableTaskRuntimeError(`Approval task '${approval.taskId}' does not belong to its objective.`);\n\t\t\t}\n\t\t}\n\t\tif (approval.attemptId) {\n\t\t\tconst attempt = this.state.attempts[approval.attemptId];\n\t\t\tif (!attempt || attempt.taskId !== approval.taskId) {\n\t\t\t\tthrow new DurableTaskRuntimeError(`Approval attempt '${approval.attemptId}' does not belong to its task.`);\n\t\t\t}\n\t\t\tif (attempt.status !== \"queued\" || attempt.grantId) {\n\t\t\t\tthrow new DurableTaskRuntimeError(`Approval attempt '${approval.attemptId}' is not awaiting policy.`);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate requireLiveLease(attemptId: string, leaseId: string, fencingToken: number): AttemptRuntimeState {\n\t\tconst attempt = this.requireAttempt(attemptId);\n\t\tif (!attempt.lease || attempt.lease.leaseId !== leaseId || attempt.lease.fencingToken !== fencingToken) {\n\t\t\tthrow new DurableTaskRuntimeError(`Attempt '${attemptId}' lease or fencing token is stale.`);\n\t\t}\n\t\tif (Date.parse(attempt.lease.expiresAt) <= this.now()) {\n\t\t\tthrow new DurableTaskRuntimeError(`Attempt '${attemptId}' lease expired.`);\n\t\t}\n\t\treturn attempt;\n\t}\n\n\tprivate refresh(): void {\n\t\tlet events: OrchestrationEvent[];\n\t\ttry {\n\t\t\tevents = this.store.readAfter(this.state.lastOrdinal);\n\t\t} catch (error) {\n\t\t\tif (!(error instanceof OrchestrationSnapshotRequiredError)) throw error;\n\t\t\tconst snapshot = this.store.readProjectionSnapshot();\n\t\t\tif (!snapshot || snapshot.throughOrdinal < error.throughOrdinal) {\n\t\t\t\tthrow new DurableTaskRuntimeError(\"Required orchestration projection snapshot is unavailable.\");\n\t\t\t}\n\t\t\tthis.state = projectionFromSnapshot(snapshot.projection, snapshot.throughOrdinal);\n\t\t\tevents = this.store.readAfter(this.state.lastOrdinal);\n\t\t}\n\t\tfor (const event of events) {\n\t\t\tthis.state = reduceOrchestrationEvent(this.state, event);\n\t\t}\n\t\tthis.compactCurrentProjection();\n\t}\n\n\tprivate commit(input: AppendOrchestrationEventInput): void {\n\t\tthis.compactCurrentProjection();\n\t\tconst event = this.store.append(input, { expectedLastOrdinal: this.state.lastOrdinal });\n\t\tif (event.ordinal > this.state.lastOrdinal) this.state = reduceOrchestrationEvent(this.state, event);\n\t}\n\n\tprivate compactCurrentProjection(): void {\n\t\tif (this.state.lastOrdinal > 0) {\n\t\t\tthis.store.compactIfNeeded(this.state.lastOrdinal, () => toJsonObject(this.state));\n\t\t}\n\t}\n\n\tprivate nowIso(): string {\n\t\treturn new Date(this.now()).toISOString();\n\t}\n}\n"]}