@leitwerk-dev/server 0.1.9 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1037) hide show
  1. package/dist/app-D4XHIbwA.d.ts +3250 -0
  2. package/dist/app-I4QQUL5B.js +10 -0
  3. package/dist/app-I4QQUL5B.js.map +1 -0
  4. package/dist/app.d.ts +4 -1
  5. package/dist/app.d.ts.map +1 -1
  6. package/dist/auth/api-token-audit.d.ts +3 -0
  7. package/dist/auth/api-token-audit.d.ts.map +1 -0
  8. package/dist/auth/api-token-policy.d.ts +8 -0
  9. package/dist/auth/api-token-policy.d.ts.map +1 -0
  10. package/dist/auth/api-token-routes.d.ts +4 -0
  11. package/dist/auth/api-token-routes.d.ts.map +1 -0
  12. package/dist/auth/api-token-service.d.ts +27 -0
  13. package/dist/auth/api-token-service.d.ts.map +1 -0
  14. package/dist/auth/auth-service.d.ts +3 -1
  15. package/dist/auth/auth-service.d.ts.map +1 -1
  16. package/dist/auth/auth-tokens.d.ts +4 -1
  17. package/dist/auth/auth-tokens.d.ts.map +1 -1
  18. package/dist/auth/fastify-auth.d.ts +10 -0
  19. package/dist/auth/fastify-auth.d.ts.map +1 -1
  20. package/dist/auth/routes.d.ts.map +1 -1
  21. package/dist/{chunk-2ESDXLNE.js → chunk-AGC2ND53.js} +6843 -4438
  22. package/dist/chunk-AGC2ND53.js.map +1 -0
  23. package/dist/{chunk-DFHOPJRZ.js → chunk-XTXH6623.js} +17275 -15915
  24. package/dist/chunk-XTXH6623.js.map +1 -0
  25. package/dist/config/config-loader.d.ts.map +1 -1
  26. package/dist/config/config-types.d.ts +56 -23
  27. package/dist/config/config-types.d.ts.map +1 -1
  28. package/dist/db/api-token-repo.d.ts +33 -0
  29. package/dist/db/api-token-repo.d.ts.map +1 -0
  30. package/dist/db/auth-repo.d.ts.map +1 -1
  31. package/dist/db/database.d.ts +9 -10
  32. package/dist/db/database.d.ts.map +1 -1
  33. package/dist/db/external-write-log-repo.d.ts +3 -6
  34. package/dist/db/external-write-log-repo.d.ts.map +1 -1
  35. package/dist/db/future-execution-repo.d.ts +0 -2
  36. package/dist/db/future-execution-repo.d.ts.map +1 -1
  37. package/dist/db/launch-run-repo.d.ts +22 -0
  38. package/dist/db/launch-run-repo.d.ts.map +1 -0
  39. package/dist/db/launcher-recent-value-repo.d.ts +0 -1
  40. package/dist/db/launcher-recent-value-repo.d.ts.map +1 -1
  41. package/dist/db/pending-external-source-fire-repo.d.ts +0 -2
  42. package/dist/db/pending-external-source-fire-repo.d.ts.map +1 -1
  43. package/dist/db/process-event-repo.d.ts +4 -0
  44. package/dist/db/process-event-repo.d.ts.map +1 -1
  45. package/dist/db/process-handoff-dedup-key-repo.d.ts +2 -5
  46. package/dist/db/process-handoff-dedup-key-repo.d.ts.map +1 -1
  47. package/dist/db/process-input-repo.d.ts +2 -2
  48. package/dist/db/process-input-repo.d.ts.map +1 -1
  49. package/dist/db/process-instance-repo.d.ts.map +1 -1
  50. package/dist/db/process-leaf-outcome-snapshot-repo.d.ts.map +1 -1
  51. package/dist/db/process-project-repo.d.ts +1 -7
  52. package/dist/db/process-project-repo.d.ts.map +1 -1
  53. package/dist/db/process-question-request-repo.d.ts.map +1 -1
  54. package/dist/db/process-relation-repo.d.ts +10 -0
  55. package/dist/db/process-relation-repo.d.ts.map +1 -0
  56. package/dist/db/process-title-job-repo.d.ts +9 -33
  57. package/dist/db/process-title-job-repo.d.ts.map +1 -1
  58. package/dist/db/process-tool-approval-request-repo.d.ts +27 -0
  59. package/dist/db/process-tool-approval-request-repo.d.ts.map +1 -0
  60. package/dist/db/process-turn-annotation-repo.d.ts.map +1 -1
  61. package/dist/db/process-turn-record-repo.d.ts +1 -15
  62. package/dist/db/process-turn-record-repo.d.ts.map +1 -1
  63. package/dist/db/repo-helpers.d.ts +2 -0
  64. package/dist/db/repo-helpers.d.ts.map +1 -1
  65. package/dist/db/repositories.d.ts +22 -0
  66. package/dist/db/repositories.d.ts.map +1 -1
  67. package/dist/db/schema-ddl.d.ts +0 -1
  68. package/dist/db/schema-ddl.d.ts.map +1 -1
  69. package/dist/db/schema.d.ts +2027 -1310
  70. package/dist/db/schema.d.ts.map +1 -1
  71. package/dist/db/session-transfer-repo.d.ts +64 -0
  72. package/dist/db/session-transfer-repo.d.ts.map +1 -0
  73. package/dist/db/skill-repo.d.ts +2 -2
  74. package/dist/db/skill-repo.d.ts.map +1 -1
  75. package/dist/db/startup-observation-repo.d.ts +7 -0
  76. package/dist/db/startup-observation-repo.d.ts.map +1 -0
  77. package/dist/db/ticket-destination-recent-repo.d.ts +19 -0
  78. package/dist/db/ticket-destination-recent-repo.d.ts.map +1 -0
  79. package/dist/db/turn-summary-repo.d.ts +25 -0
  80. package/dist/db/turn-summary-repo.d.ts.map +1 -0
  81. package/dist/db/worker-lease-repo.d.ts +6 -0
  82. package/dist/db/worker-lease-repo.d.ts.map +1 -1
  83. package/dist/deployment-preflight.d.ts +1 -1
  84. package/dist/deployment-preflight.d.ts.map +1 -1
  85. package/dist/docker-registry-credentials.d.ts +5 -0
  86. package/dist/docker-registry-credentials.d.ts.map +1 -0
  87. package/dist/domain-logic/outcome-tools.d.ts.map +1 -1
  88. package/dist/domain-logic/process-state-machine.d.ts +0 -5
  89. package/dist/domain-logic/process-state-machine.d.ts.map +1 -1
  90. package/dist/domain-logic/turn-record-guards.d.ts +2 -2
  91. package/dist/domain-logic/turn-record-guards.d.ts.map +1 -1
  92. package/dist/effects/post-commit-effect.d.ts +4 -6
  93. package/dist/effects/post-commit-effect.d.ts.map +1 -1
  94. package/dist/effects/post-commit-runner.d.ts.map +1 -1
  95. package/dist/entry-ref-patch.d.ts +8 -0
  96. package/dist/entry-ref-patch.d.ts.map +1 -0
  97. package/dist/extension-ui/catalog.d.ts +5 -25
  98. package/dist/extension-ui/catalog.d.ts.map +1 -1
  99. package/dist/external-source-reporting.d.ts +4 -0
  100. package/dist/external-source-reporting.d.ts.map +1 -0
  101. package/dist/external-source-service.d.ts +5 -1
  102. package/dist/external-source-service.d.ts.map +1 -1
  103. package/dist/future-execution/execution.d.ts +3 -2
  104. package/dist/future-execution/execution.d.ts.map +1 -1
  105. package/dist/future-execution/index.d.ts +1 -1
  106. package/dist/future-execution/index.d.ts.map +1 -1
  107. package/dist/future-execution/launch-lifecycle.d.ts +136 -0
  108. package/dist/future-execution/launch-lifecycle.d.ts.map +1 -0
  109. package/dist/future-execution/lifecycle.d.ts +21 -77
  110. package/dist/future-execution/lifecycle.d.ts.map +1 -1
  111. package/dist/future-execution/reconciliation.d.ts.map +1 -1
  112. package/dist/future-execution/support.d.ts +11 -0
  113. package/dist/future-execution/support.d.ts.map +1 -1
  114. package/dist/future-execution-presenter.d.ts.map +1 -1
  115. package/dist/index.d.ts +1 -1
  116. package/dist/index.d.ts.map +1 -1
  117. package/dist/index.js +246 -29
  118. package/dist/index.js.map +1 -1
  119. package/dist/integration-tool-registry.d.ts +27 -5
  120. package/dist/integration-tool-registry.d.ts.map +1 -1
  121. package/dist/launch-coordinator-test-harness.d.ts +55 -0
  122. package/dist/launch-coordinator-test-harness.d.ts.map +1 -0
  123. package/dist/launch-coordinator.d.ts +72 -0
  124. package/dist/launch-coordinator.d.ts.map +1 -0
  125. package/dist/launch-idempotency.d.ts +17 -0
  126. package/dist/launch-idempotency.d.ts.map +1 -0
  127. package/dist/launch-pipeline.d.ts +105 -0
  128. package/dist/launch-pipeline.d.ts.map +1 -0
  129. package/dist/leaf-outcome-snapshot-capture.d.ts +1 -2
  130. package/dist/leaf-outcome-snapshot-capture.d.ts.map +1 -1
  131. package/dist/main.js +198 -71
  132. package/dist/main.js.map +1 -1
  133. package/dist/model-providers/builtin-server-adapter.d.ts.map +1 -1
  134. package/dist/model-providers/credentials.d.ts +2 -4
  135. package/dist/model-providers/credentials.d.ts.map +1 -1
  136. package/dist/model-providers/model-status-cache.d.ts.map +1 -1
  137. package/dist/model-providers/registry.d.ts.map +1 -1
  138. package/dist/physical-worker-starts.d.ts +8 -0
  139. package/dist/physical-worker-starts.d.ts.map +1 -0
  140. package/dist/pi-resources/assemble.d.ts.map +1 -1
  141. package/dist/pi-resources/bundle-cache.d.ts.map +1 -1
  142. package/dist/pi-resources/bundle-pin-lifecycle.d.ts.map +1 -1
  143. package/dist/pi-resources/resource-collector.d.ts +1 -0
  144. package/dist/pi-resources/resource-collector.d.ts.map +1 -1
  145. package/dist/primary-path-snapshot.d.ts +0 -4
  146. package/dist/primary-path-snapshot.d.ts.map +1 -1
  147. package/dist/process-action-next-turn-model.d.ts +1 -1
  148. package/dist/process-action-next-turn-model.d.ts.map +1 -1
  149. package/dist/process-action-planner.d.ts +1 -1
  150. package/dist/process-action-planner.d.ts.map +1 -1
  151. package/dist/process-action-registry.d.ts +6 -7
  152. package/dist/process-action-registry.d.ts.map +1 -1
  153. package/dist/process-attention-notifier.d.ts.map +1 -1
  154. package/dist/process-deletion-service.d.ts +3 -0
  155. package/dist/process-deletion-service.d.ts.map +1 -1
  156. package/dist/process-engine/engine.d.ts.map +1 -1
  157. package/dist/process-engine/operation.d.ts +7 -4
  158. package/dist/process-engine/operation.d.ts.map +1 -1
  159. package/dist/process-engine/ops/abort-process.d.ts +1 -0
  160. package/dist/process-engine/ops/abort-process.d.ts.map +1 -1
  161. package/dist/process-engine/ops/abort-turn.d.ts.map +1 -1
  162. package/dist/process-engine/ops/continue-failed-turn.d.ts +2 -7
  163. package/dist/process-engine/ops/continue-failed-turn.d.ts.map +1 -1
  164. package/dist/process-engine/ops/execute-action.d.ts +2 -10
  165. package/dist/process-engine/ops/execute-action.d.ts.map +1 -1
  166. package/dist/process-engine/ops/retry-failed-turn.d.ts.map +1 -1
  167. package/dist/process-engine/ops/retry-startup.d.ts +2 -0
  168. package/dist/process-engine/ops/retry-startup.d.ts.map +1 -1
  169. package/dist/process-engine/ops/start-process.d.ts +1 -0
  170. package/dist/process-engine/ops/start-process.d.ts.map +1 -1
  171. package/dist/process-engine/ops/turn-failed.d.ts +1 -0
  172. package/dist/process-engine/ops/turn-failed.d.ts.map +1 -1
  173. package/dist/process-engine/ops/turn-outcome.d.ts +1 -0
  174. package/dist/process-engine/ops/turn-outcome.d.ts.map +1 -1
  175. package/dist/process-engine/ops/update-semantic-refs.d.ts.map +1 -1
  176. package/dist/process-engine/ops/worker-failure.d.ts.map +1 -1
  177. package/dist/process-engine/runner.d.ts +2 -2
  178. package/dist/process-engine/runner.d.ts.map +1 -1
  179. package/dist/process-engine/startup-reconciliation.d.ts +2 -2
  180. package/dist/process-engine/startup-reconciliation.d.ts.map +1 -1
  181. package/dist/process-engine/turn-start-preflight.d.ts.map +1 -1
  182. package/dist/process-engine/types.d.ts +6 -9
  183. package/dist/process-engine/types.d.ts.map +1 -1
  184. package/dist/process-engine/writes/build-continue-failed-turn-writes.d.ts +2 -5
  185. package/dist/process-engine/writes/build-continue-failed-turn-writes.d.ts.map +1 -1
  186. package/dist/process-engine/writes/build-process-abort-writes.d.ts.map +1 -1
  187. package/dist/process-engine/writes/build-process-action-writes.d.ts +1 -1
  188. package/dist/process-engine/writes/build-process-action-writes.d.ts.map +1 -1
  189. package/dist/process-engine/writes/build-process-park-writes.d.ts.map +1 -1
  190. package/dist/process-engine/writes/build-recovery-start-writes.d.ts +17 -0
  191. package/dist/process-engine/writes/build-recovery-start-writes.d.ts.map +1 -0
  192. package/dist/process-engine/writes/build-retry-writes.d.ts +2 -5
  193. package/dist/process-engine/writes/build-retry-writes.d.ts.map +1 -1
  194. package/dist/process-engine/writes/build-server-transition-writes.d.ts +6 -1
  195. package/dist/process-engine/writes/build-server-transition-writes.d.ts.map +1 -1
  196. package/dist/process-engine/writes/build-turn-outcome-writes.d.ts +1 -1
  197. package/dist/process-engine/writes/build-turn-outcome-writes.d.ts.map +1 -1
  198. package/dist/process-engine/writes/build-turn-selection-writes.d.ts +0 -1
  199. package/dist/process-engine/writes/build-turn-selection-writes.d.ts.map +1 -1
  200. package/dist/process-engine/writes/commit-writes.d.ts +1 -0
  201. package/dist/process-engine/writes/commit-writes.d.ts.map +1 -1
  202. package/dist/process-engine/writes/process-plan-collector.d.ts +14 -0
  203. package/dist/process-engine/writes/process-plan-collector.d.ts.map +1 -0
  204. package/dist/process-execution.d.ts +5 -0
  205. package/dist/process-execution.d.ts.map +1 -0
  206. package/dist/process-input-dispatch.d.ts +3 -8
  207. package/dist/process-input-dispatch.d.ts.map +1 -1
  208. package/dist/process-instance-tree-presenter.d.ts.map +1 -1
  209. package/dist/process-launch-executor.d.ts +37 -14
  210. package/dist/process-launch-executor.d.ts.map +1 -1
  211. package/dist/process-launch-pipeline-adapter.d.ts +17 -0
  212. package/dist/process-launch-pipeline-adapter.d.ts.map +1 -0
  213. package/dist/process-launch-plan.d.ts +2 -1
  214. package/dist/process-launch-plan.d.ts.map +1 -1
  215. package/dist/process-launcher-registry.d.ts.map +1 -1
  216. package/dist/process-model-policy/input.d.ts +1 -1
  217. package/dist/process-model-policy/input.d.ts.map +1 -1
  218. package/dist/process-model-selection.d.ts +1 -1
  219. package/dist/process-model-selection.d.ts.map +1 -1
  220. package/dist/process-operation-coordinator.d.ts.map +1 -1
  221. package/dist/process-operator-attention.d.ts.map +1 -1
  222. package/dist/process-overview-presenter.d.ts.map +1 -1
  223. package/dist/process-runtime-availability.d.ts +18 -0
  224. package/dist/process-runtime-availability.d.ts.map +1 -0
  225. package/dist/process-session-store.d.ts.map +1 -1
  226. package/dist/process-storage-size.d.ts +13 -0
  227. package/dist/process-storage-size.d.ts.map +1 -0
  228. package/dist/process-title-generator.d.ts +3 -0
  229. package/dist/process-title-generator.d.ts.map +1 -1
  230. package/dist/process-turn-navigation.d.ts +46 -0
  231. package/dist/process-turn-navigation.d.ts.map +1 -0
  232. package/dist/process-turn-trace.d.ts +6 -0
  233. package/dist/process-turn-trace.d.ts.map +1 -1
  234. package/dist/process-ui-registry.d.ts +0 -3
  235. package/dist/process-ui-registry.d.ts.map +1 -1
  236. package/dist/process-ui-snapshot-presenter.d.ts +28 -17
  237. package/dist/process-ui-snapshot-presenter.d.ts.map +1 -1
  238. package/dist/process-watcher-registry.d.ts.map +1 -1
  239. package/dist/product-ref-state.d.ts.map +1 -1
  240. package/dist/repository-credentials/service.d.ts +2 -2
  241. package/dist/repository-credentials/service.d.ts.map +1 -1
  242. package/dist/routes/bearer-token.d.ts +4 -0
  243. package/dist/routes/bearer-token.d.ts.map +1 -0
  244. package/dist/routes/internal-session-transfer-exports.d.ts +4 -0
  245. package/dist/routes/internal-session-transfer-exports.d.ts.map +1 -0
  246. package/dist/routes/internal-worker-auth.d.ts.map +1 -1
  247. package/dist/routes/internal-worker-session-snapshot.d.ts.map +1 -1
  248. package/dist/routes/launchers.d.ts.map +1 -1
  249. package/dist/routes/process-actions.d.ts.map +1 -1
  250. package/dist/routes/process-engine-http.d.ts.map +1 -1
  251. package/dist/routes/process-primary-path-assembler.d.ts.map +1 -1
  252. package/dist/routes/process-route-helpers.d.ts +13 -12
  253. package/dist/routes/process-route-helpers.d.ts.map +1 -1
  254. package/dist/routes/processes.d.ts.map +1 -1
  255. package/dist/routes/result-images.d.ts.map +1 -1
  256. package/dist/routes/session-transfers.d.ts +4 -0
  257. package/dist/routes/session-transfers.d.ts.map +1 -0
  258. package/dist/routes/skills.d.ts.map +1 -1
  259. package/dist/routes/ticket-creation.d.ts +5 -0
  260. package/dist/routes/ticket-creation.d.ts.map +1 -0
  261. package/dist/scheduled-action-preflight.d.ts +1 -1
  262. package/dist/scheduled-action-preflight.d.ts.map +1 -1
  263. package/dist/semantic-entry-ref-state.d.ts +2 -4
  264. package/dist/semantic-entry-ref-state.d.ts.map +1 -1
  265. package/dist/server-bootstrap/build-host-capabilities.d.ts +5 -8
  266. package/dist/server-bootstrap/build-host-capabilities.d.ts.map +1 -1
  267. package/dist/server-bootstrap/load-extension-catalog.d.ts.map +1 -1
  268. package/dist/server-bootstrap/register-http.d.ts +2 -0
  269. package/dist/server-bootstrap/register-http.d.ts.map +1 -1
  270. package/dist/server-bootstrap/register-websocket.d.ts.map +1 -1
  271. package/dist/session-summary-projection.d.ts +12 -0
  272. package/dist/session-summary-projection.d.ts.map +1 -0
  273. package/dist/session-transfer-helper-relays.d.ts +36 -0
  274. package/dist/session-transfer-helper-relays.d.ts.map +1 -0
  275. package/dist/session-transfer-service.d.ts +93 -0
  276. package/dist/session-transfer-service.d.ts.map +1 -0
  277. package/dist/skills/invocation-detector.d.ts.map +1 -1
  278. package/dist/skills/skill-frontmatter.d.ts +0 -2
  279. package/dist/skills/skill-frontmatter.d.ts.map +1 -1
  280. package/dist/skills/source-importer.d.ts +1 -1
  281. package/dist/skills/source-importer.d.ts.map +1 -1
  282. package/dist/startup-evidence.d.ts +32 -0
  283. package/dist/startup-evidence.d.ts.map +1 -0
  284. package/dist/supervisor/accepted-turn-start-replay.d.ts +0 -1
  285. package/dist/supervisor/accepted-turn-start-replay.d.ts.map +1 -1
  286. package/dist/supervisor/adoption/worker-adoption-coordinator.d.ts +4 -5
  287. package/dist/supervisor/adoption/worker-adoption-coordinator.d.ts.map +1 -1
  288. package/dist/supervisor/diagnostic-trace-writer.d.ts +5 -0
  289. package/dist/supervisor/diagnostic-trace-writer.d.ts.map +1 -0
  290. package/dist/supervisor/ipc-handler.d.ts +6 -11
  291. package/dist/supervisor/ipc-handler.d.ts.map +1 -1
  292. package/dist/supervisor/record-worker-lifecycle-event.d.ts +10 -0
  293. package/dist/supervisor/record-worker-lifecycle-event.d.ts.map +1 -0
  294. package/dist/supervisor/stale-heartbeat-watchdog.d.ts +1 -1
  295. package/dist/supervisor/stale-heartbeat-watchdog.d.ts.map +1 -1
  296. package/dist/supervisor/startup-observer.d.ts +14 -0
  297. package/dist/supervisor/startup-observer.d.ts.map +1 -0
  298. package/dist/supervisor/worker-capacity-queue.d.ts +15 -0
  299. package/dist/supervisor/worker-capacity-queue.d.ts.map +1 -0
  300. package/dist/supervisor/worker-connect-token.d.ts +4 -3
  301. package/dist/supervisor/worker-connect-token.d.ts.map +1 -1
  302. package/dist/supervisor/worker-event-ingestor.d.ts +2 -0
  303. package/dist/supervisor/worker-event-ingestor.d.ts.map +1 -1
  304. package/dist/supervisor/worker-lease-observer.d.ts +1 -0
  305. package/dist/supervisor/worker-lease-observer.d.ts.map +1 -1
  306. package/dist/supervisor/worker-shutdown-controller.d.ts.map +1 -1
  307. package/dist/supervisor/worker-start-payload-builder.d.ts +7 -5
  308. package/dist/supervisor/worker-start-payload-builder.d.ts.map +1 -1
  309. package/dist/supervisor/worker-storage-layout.d.ts +1 -0
  310. package/dist/supervisor/worker-storage-layout.d.ts.map +1 -1
  311. package/dist/supervisor/worker-supervisor.d.ts +10 -2
  312. package/dist/supervisor/worker-supervisor.d.ts.map +1 -1
  313. package/dist/supervisor/worker-turn-ipc-recorder.d.ts +11 -1
  314. package/dist/supervisor/worker-turn-ipc-recorder.d.ts.map +1 -1
  315. package/dist/supervisor/worker-unit-reclaimer.d.ts +23 -0
  316. package/dist/supervisor/worker-unit-reclaimer.d.ts.map +1 -0
  317. package/dist/supervisor/worker-websocket-ipc.d.ts.map +1 -1
  318. package/dist/test-helpers/accepted-turn-start.d.ts +24 -0
  319. package/dist/test-helpers/accepted-turn-start.d.ts.map +1 -0
  320. package/dist/test-helpers/ipc-handler-harness.d.ts +3 -1
  321. package/dist/test-helpers/ipc-handler-harness.d.ts.map +1 -1
  322. package/dist/test-helpers/process-binding-fixtures.d.ts.map +1 -1
  323. package/dist/test-helpers/process-fixtures.d.ts +1 -6
  324. package/dist/test-helpers/process-fixtures.d.ts.map +1 -1
  325. package/dist/test-helpers/session-snapshot-fixtures.d.ts +4 -0
  326. package/dist/test-helpers/session-snapshot-fixtures.d.ts.map +1 -0
  327. package/dist/test-helpers/structural-process-fixtures.d.ts +2 -2
  328. package/dist/test-helpers/structural-process-fixtures.d.ts.map +1 -1
  329. package/dist/test-helpers/unit-deps.d.ts +2 -0
  330. package/dist/test-helpers/unit-deps.d.ts.map +1 -1
  331. package/dist/test-helpers/worker-runner-runtime.d.ts +3 -0
  332. package/dist/test-helpers/worker-runner-runtime.d.ts.map +1 -0
  333. package/dist/testing.d.ts +2 -0
  334. package/dist/testing.d.ts.map +1 -1
  335. package/dist/testing.js +411 -6
  336. package/dist/testing.js.map +1 -1
  337. package/dist/tool-approval-gate.d.ts +32 -0
  338. package/dist/tool-approval-gate.d.ts.map +1 -0
  339. package/dist/turn-preparation.d.ts +13 -0
  340. package/dist/turn-preparation.d.ts.map +1 -0
  341. package/dist/turn-progress.d.ts +1 -0
  342. package/dist/turn-progress.d.ts.map +1 -1
  343. package/dist/{semantic-turn-result-markdown.d.ts → turn-result-markdown.d.ts} +10 -5
  344. package/dist/turn-result-markdown.d.ts.map +1 -0
  345. package/dist/worker-runtime-profile-selection.d.ts +2 -3
  346. package/dist/worker-runtime-profile-selection.d.ts.map +1 -1
  347. package/package.json +13 -14
  348. package/src/app.ts +208 -13
  349. package/src/auth/api-token-audit.ts +25 -0
  350. package/src/auth/api-token-policy.ts +56 -0
  351. package/src/auth/api-token-routes.ts +113 -0
  352. package/src/auth/api-token-service.ts +118 -0
  353. package/src/auth/auth-service.ts +9 -1
  354. package/src/auth/auth-tokens.ts +22 -3
  355. package/src/auth/fastify-auth.ts +54 -13
  356. package/src/auth/routes.ts +6 -5
  357. package/src/config/config-loader.ts +145 -99
  358. package/src/config/config-types.ts +53 -24
  359. package/src/db/api-token-repo.ts +90 -0
  360. package/src/db/auth-repo.ts +4 -15
  361. package/src/db/database.ts +492 -70
  362. package/src/db/external-write-log-repo.ts +2 -6
  363. package/src/db/future-execution-repo.ts +12 -22
  364. package/src/db/launch-run-repo.ts +143 -0
  365. package/src/db/launcher-recent-value-repo.ts +22 -60
  366. package/src/db/pending-external-source-fire-repo.ts +6 -30
  367. package/src/db/process-event-repo.ts +116 -55
  368. package/src/db/process-handoff-dedup-key-repo.ts +2 -6
  369. package/src/db/process-input-repo.ts +18 -24
  370. package/src/db/process-instance-repo.ts +19 -38
  371. package/src/db/process-leaf-outcome-snapshot-repo.ts +2 -16
  372. package/src/db/process-project-repo.ts +12 -36
  373. package/src/db/process-question-request-repo.ts +13 -11
  374. package/src/db/process-relation-repo.ts +55 -0
  375. package/src/db/process-title-job-repo.ts +84 -190
  376. package/src/db/process-tool-approval-request-repo.ts +145 -0
  377. package/src/db/process-turn-annotation-repo.ts +6 -19
  378. package/src/db/process-turn-record-repo.ts +17 -33
  379. package/src/db/repo-helpers.ts +15 -0
  380. package/src/db/repositories.ts +34 -3
  381. package/src/db/schema-ddl.ts +3 -10
  382. package/src/db/schema.ts +246 -12
  383. package/src/db/session-transfer-repo.ts +286 -0
  384. package/src/db/skill-repo.ts +64 -77
  385. package/src/db/startup-observation-repo.ts +40 -0
  386. package/src/db/ticket-destination-recent-repo.ts +92 -0
  387. package/src/db/turn-summary-repo.ts +68 -0
  388. package/src/db/worker-lease-repo.ts +48 -11
  389. package/src/deployment-preflight.ts +9 -5
  390. package/src/docker-registry-credentials.ts +21 -0
  391. package/src/domain-logic/outcome-tools.ts +47 -134
  392. package/src/domain-logic/process-state-machine.ts +47 -94
  393. package/src/domain-logic/turn-record-guards.ts +4 -8
  394. package/src/effects/post-commit-effect.ts +9 -8
  395. package/src/effects/post-commit-runner.ts +33 -58
  396. package/src/entry-ref-patch.ts +56 -0
  397. package/src/extension-ui/catalog.ts +11 -42
  398. package/src/external-source-reporting.ts +37 -0
  399. package/src/external-source-service.ts +267 -301
  400. package/src/future-execution/execution.ts +123 -56
  401. package/src/future-execution/index.ts +2 -0
  402. package/src/future-execution/launch-lifecycle.ts +665 -0
  403. package/src/future-execution/lifecycle.ts +57 -653
  404. package/src/future-execution/reconciliation.ts +10 -14
  405. package/src/future-execution/support.ts +20 -0
  406. package/src/future-execution-presenter.ts +18 -46
  407. package/src/index.ts +0 -4
  408. package/src/integration-tool-registry.ts +422 -27
  409. package/src/launch-coordinator-test-harness.ts +155 -0
  410. package/src/launch-coordinator.ts +719 -0
  411. package/src/launch-idempotency.ts +30 -0
  412. package/src/launch-pipeline.ts +365 -0
  413. package/src/leaf-outcome-snapshot-capture.ts +2 -20
  414. package/src/model-providers/builtin-server-adapter.ts +25 -4
  415. package/src/model-providers/credentials.ts +10 -36
  416. package/src/model-providers/model-status-cache.ts +42 -70
  417. package/src/model-providers/registry.ts +1 -4
  418. package/src/physical-worker-starts.ts +64 -0
  419. package/src/pi-resources/assemble.ts +4 -11
  420. package/src/pi-resources/bundle-cache.ts +17 -41
  421. package/src/pi-resources/bundle-pin-lifecycle.ts +6 -11
  422. package/src/pi-resources/resource-collector.ts +13 -29
  423. package/src/primary-path-snapshot.ts +12 -29
  424. package/src/process-action-next-turn-model.ts +1 -4
  425. package/src/process-action-planner.ts +1 -1
  426. package/src/process-action-registry.ts +81 -182
  427. package/src/process-attention-notifier.ts +2 -8
  428. package/src/process-deletion-service.ts +40 -31
  429. package/src/process-engine/engine.ts +16 -25
  430. package/src/process-engine/operation.ts +8 -5
  431. package/src/process-engine/ops/abort-process.ts +12 -9
  432. package/src/process-engine/ops/abort-turn.ts +5 -6
  433. package/src/process-engine/ops/continue-failed-turn.ts +4 -15
  434. package/src/process-engine/ops/execute-action.ts +5 -9
  435. package/src/process-engine/ops/retry-failed-turn.ts +2 -29
  436. package/src/process-engine/ops/retry-startup.ts +24 -4
  437. package/src/process-engine/ops/start-process.ts +10 -1
  438. package/src/process-engine/ops/turn-failed.ts +5 -3
  439. package/src/process-engine/ops/turn-outcome.ts +51 -47
  440. package/src/process-engine/ops/update-semantic-refs.ts +1 -9
  441. package/src/process-engine/ops/worker-failure.ts +15 -10
  442. package/src/process-engine/runner.ts +24 -47
  443. package/src/process-engine/startup-reconciliation.ts +19 -48
  444. package/src/process-engine/turn-start-preflight.ts +2 -14
  445. package/src/process-engine/types.ts +7 -11
  446. package/src/process-engine/writes/build-continue-failed-turn-writes.ts +17 -56
  447. package/src/process-engine/writes/build-process-abort-writes.ts +11 -34
  448. package/src/process-engine/writes/build-process-action-writes.ts +36 -150
  449. package/src/process-engine/writes/build-process-park-writes.ts +11 -14
  450. package/src/process-engine/writes/build-recovery-start-writes.ts +71 -0
  451. package/src/process-engine/writes/build-retry-writes.ts +10 -60
  452. package/src/process-engine/writes/build-server-transition-writes.ts +35 -87
  453. package/src/process-engine/writes/build-turn-outcome-writes.ts +15 -91
  454. package/src/process-engine/writes/build-turn-selection-writes.ts +23 -75
  455. package/src/process-engine/writes/commit-writes.ts +20 -8
  456. package/src/process-engine/writes/process-plan-collector.ts +77 -0
  457. package/src/process-execution.ts +10 -0
  458. package/src/process-input-dispatch.ts +2 -12
  459. package/src/process-instance-tree-presenter.ts +6 -23
  460. package/src/process-launch-executor.ts +109 -64
  461. package/src/process-launch-pipeline-adapter.ts +57 -0
  462. package/src/process-launch-plan.ts +19 -0
  463. package/src/process-launcher-registry.ts +38 -58
  464. package/src/process-model-policy/input.ts +5 -12
  465. package/src/process-model-selection.ts +1 -4
  466. package/src/process-operation-coordinator.ts +1 -4
  467. package/src/process-operator-attention.ts +2 -10
  468. package/src/process-overview-presenter.ts +30 -41
  469. package/src/process-runtime-availability.ts +74 -0
  470. package/src/process-session-store.ts +13 -4
  471. package/src/process-storage-size.ts +45 -0
  472. package/src/process-title-generator.ts +56 -21
  473. package/src/process-turn-navigation.ts +24 -0
  474. package/src/process-turn-trace.ts +92 -202
  475. package/src/process-ui-registry.ts +5 -16
  476. package/src/process-ui-snapshot-presenter.ts +343 -199
  477. package/src/process-watcher-registry.ts +53 -50
  478. package/src/product-ref-state.ts +4 -70
  479. package/src/repository-credentials/service.ts +40 -9
  480. package/src/routes/bearer-token.ts +10 -0
  481. package/src/routes/internal-session-transfer-exports.ts +65 -0
  482. package/src/routes/internal-worker-auth.ts +2 -3
  483. package/src/routes/internal-worker-session-snapshot.ts +17 -31
  484. package/src/routes/launchers.ts +70 -6
  485. package/src/routes/process-actions.ts +12 -23
  486. package/src/routes/process-engine-http.ts +14 -16
  487. package/src/routes/process-primary-path-assembler.ts +2 -9
  488. package/src/routes/process-route-helpers.ts +54 -82
  489. package/src/routes/processes.ts +8 -0
  490. package/src/routes/result-images.ts +5 -9
  491. package/src/routes/session-transfers.ts +144 -0
  492. package/src/routes/skills.ts +3 -1
  493. package/src/routes/ticket-creation.ts +240 -0
  494. package/src/scheduled-action-preflight.ts +1 -1
  495. package/src/semantic-entry-ref-state.ts +5 -85
  496. package/src/server-bootstrap/build-host-capabilities.ts +29 -48
  497. package/src/server-bootstrap/load-extension-catalog.ts +4 -8
  498. package/src/server-bootstrap/register-http.ts +17 -1
  499. package/src/server-bootstrap/register-websocket.ts +3 -6
  500. package/src/session-summary-projection.ts +110 -0
  501. package/src/session-transfer-helper-relays.ts +201 -0
  502. package/src/session-transfer-service.ts +439 -0
  503. package/src/skills/invocation-detector.ts +1 -6
  504. package/src/skills/skill-frontmatter.ts +9 -5
  505. package/src/skills/source-importer.ts +32 -16
  506. package/src/startup-evidence.ts +388 -0
  507. package/src/supervisor/accepted-turn-start-replay.ts +1 -2
  508. package/src/supervisor/adoption/worker-adoption-coordinator.ts +22 -19
  509. package/src/supervisor/diagnostic-trace-writer.ts +18 -0
  510. package/src/supervisor/ipc-handler.ts +47 -54
  511. package/src/supervisor/record-worker-lifecycle-event.ts +18 -0
  512. package/src/supervisor/stale-heartbeat-watchdog.ts +41 -31
  513. package/src/supervisor/startup-observer.ts +98 -0
  514. package/src/supervisor/worker-capacity-queue.ts +72 -0
  515. package/src/supervisor/worker-connect-token.ts +5 -14
  516. package/src/supervisor/worker-event-ingestor.ts +73 -21
  517. package/src/supervisor/worker-lease-observer.ts +2 -0
  518. package/src/supervisor/worker-shutdown-controller.ts +14 -13
  519. package/src/supervisor/worker-start-payload-builder.ts +106 -77
  520. package/src/supervisor/worker-storage-layout.ts +8 -1
  521. package/src/supervisor/worker-supervisor.ts +295 -143
  522. package/src/supervisor/worker-turn-ipc-recorder.ts +100 -58
  523. package/src/supervisor/worker-unit-reclaimer.ts +136 -0
  524. package/src/supervisor/worker-websocket-ipc.ts +6 -20
  525. package/src/test-helpers/accepted-turn-start.ts +79 -0
  526. package/src/test-helpers/ipc-handler-harness.ts +5 -0
  527. package/src/test-helpers/process-binding-fixtures.ts +1 -5
  528. package/src/test-helpers/process-fixtures.ts +4 -35
  529. package/src/test-helpers/session-snapshot-fixtures.ts +20 -0
  530. package/src/test-helpers/structural-process-fixtures.ts +1 -10
  531. package/src/test-helpers/unit-deps.ts +20 -0
  532. package/src/test-helpers/worker-runner-runtime.ts +32 -0
  533. package/src/testing.ts +5 -0
  534. package/src/tool-approval-gate.ts +116 -0
  535. package/src/turn-preparation.ts +53 -0
  536. package/src/turn-progress.ts +43 -27
  537. package/src/turn-result-markdown.ts +102 -0
  538. package/src/worker-runtime-profile-selection.ts +15 -9
  539. package/dist/app.js +0 -922
  540. package/dist/app.js.map +0 -1
  541. package/dist/auth/auth-client.js +0 -19
  542. package/dist/auth/auth-client.js.map +0 -1
  543. package/dist/auth/auth-config.js +0 -52
  544. package/dist/auth/auth-config.js.map +0 -1
  545. package/dist/auth/auth-service.js +0 -133
  546. package/dist/auth/auth-service.js.map +0 -1
  547. package/dist/auth/auth-test-helpers.js +0 -30
  548. package/dist/auth/auth-test-helpers.js.map +0 -1
  549. package/dist/auth/auth-tokens.js +0 -11
  550. package/dist/auth/auth-tokens.js.map +0 -1
  551. package/dist/auth/fastify-auth.js +0 -20
  552. package/dist/auth/fastify-auth.js.map +0 -1
  553. package/dist/auth/github-oauth-client.js +0 -79
  554. package/dist/auth/github-oauth-client.js.map +0 -1
  555. package/dist/auth/oidc-client.js +0 -55
  556. package/dist/auth/oidc-client.js.map +0 -1
  557. package/dist/auth/routes.js +0 -74
  558. package/dist/auth/routes.js.map +0 -1
  559. package/dist/chunk-2ESDXLNE.js.map +0 -1
  560. package/dist/chunk-DFHOPJRZ.js.map +0 -1
  561. package/dist/commit-message-policy.js +0 -15
  562. package/dist/commit-message-policy.js.map +0 -1
  563. package/dist/config/config-loader.js +0 -838
  564. package/dist/config/config-loader.js.map +0 -1
  565. package/dist/config/config-types.js +0 -2
  566. package/dist/config/config-types.js.map +0 -1
  567. package/dist/config/index.js +0 -2
  568. package/dist/config/index.js.map +0 -1
  569. package/dist/config/url-policy.js +0 -25
  570. package/dist/config/url-policy.js.map +0 -1
  571. package/dist/db/auth-repo.js +0 -92
  572. package/dist/db/auth-repo.js.map +0 -1
  573. package/dist/db/credential-cipher.js +0 -47
  574. package/dist/db/credential-cipher.js.map +0 -1
  575. package/dist/db/database.js +0 -423
  576. package/dist/db/database.js.map +0 -1
  577. package/dist/db/external-write-log-repo.js +0 -49
  578. package/dist/db/external-write-log-repo.js.map +0 -1
  579. package/dist/db/future-execution-repo.js +0 -267
  580. package/dist/db/future-execution-repo.js.map +0 -1
  581. package/dist/db/index.js +0 -4
  582. package/dist/db/index.js.map +0 -1
  583. package/dist/db/launcher-recent-value-repo.js +0 -76
  584. package/dist/db/launcher-recent-value-repo.js.map +0 -1
  585. package/dist/db/pending-external-source-fire-repo.js +0 -108
  586. package/dist/db/pending-external-source-fire-repo.js.map +0 -1
  587. package/dist/db/process-event-repo.js +0 -98
  588. package/dist/db/process-event-repo.js.map +0 -1
  589. package/dist/db/process-handoff-dedup-key-repo.js +0 -34
  590. package/dist/db/process-handoff-dedup-key-repo.js.map +0 -1
  591. package/dist/db/process-input-repo.js +0 -90
  592. package/dist/db/process-input-repo.js.map +0 -1
  593. package/dist/db/process-instance-repo.js +0 -281
  594. package/dist/db/process-instance-repo.js.map +0 -1
  595. package/dist/db/process-leaf-outcome-snapshot-repo.js +0 -77
  596. package/dist/db/process-leaf-outcome-snapshot-repo.js.map +0 -1
  597. package/dist/db/process-project-repo.js +0 -129
  598. package/dist/db/process-project-repo.js.map +0 -1
  599. package/dist/db/process-question-request-repo.js +0 -99
  600. package/dist/db/process-question-request-repo.js.map +0 -1
  601. package/dist/db/process-skill-repo.js +0 -58
  602. package/dist/db/process-skill-repo.js.map +0 -1
  603. package/dist/db/process-title-job-repo.js +0 -173
  604. package/dist/db/process-title-job-repo.js.map +0 -1
  605. package/dist/db/process-turn-annotation-repo.js +0 -104
  606. package/dist/db/process-turn-annotation-repo.js.map +0 -1
  607. package/dist/db/process-turn-record-repo.js +0 -125
  608. package/dist/db/process-turn-record-repo.js.map +0 -1
  609. package/dist/db/provider-credential-repo.js +0 -60
  610. package/dist/db/provider-credential-repo.js.map +0 -1
  611. package/dist/db/repo-helpers.js +0 -20
  612. package/dist/db/repo-helpers.js.map +0 -1
  613. package/dist/db/repositories.js +0 -73
  614. package/dist/db/repositories.js.map +0 -1
  615. package/dist/db/schema-ddl.js +0 -99
  616. package/dist/db/schema-ddl.js.map +0 -1
  617. package/dist/db/schema.js +0 -475
  618. package/dist/db/schema.js.map +0 -1
  619. package/dist/db/skill-repo.js +0 -468
  620. package/dist/db/skill-repo.js.map +0 -1
  621. package/dist/db/turn-start-record-repo.js +0 -67
  622. package/dist/db/turn-start-record-repo.js.map +0 -1
  623. package/dist/db/worker-lease-repo.js +0 -109
  624. package/dist/db/worker-lease-repo.js.map +0 -1
  625. package/dist/deployment-preflight.js +0 -69
  626. package/dist/deployment-preflight.js.map +0 -1
  627. package/dist/domain-logic/cron.js +0 -25
  628. package/dist/domain-logic/cron.js.map +0 -1
  629. package/dist/domain-logic/outcome-tools.js +0 -267
  630. package/dist/domain-logic/outcome-tools.js.map +0 -1
  631. package/dist/domain-logic/process-state-machine.js +0 -140
  632. package/dist/domain-logic/process-state-machine.js.map +0 -1
  633. package/dist/domain-logic/scheduled-action-lock.js +0 -39
  634. package/dist/domain-logic/scheduled-action-lock.js.map +0 -1
  635. package/dist/domain-logic/turn-record-guards.js +0 -26
  636. package/dist/domain-logic/turn-record-guards.js.map +0 -1
  637. package/dist/domain-logic/worker-lease-lifecycle.js +0 -77
  638. package/dist/domain-logic/worker-lease-lifecycle.js.map +0 -1
  639. package/dist/effects/post-commit-effect.js +0 -8
  640. package/dist/effects/post-commit-effect.js.map +0 -1
  641. package/dist/effects/post-commit-runner.js +0 -215
  642. package/dist/effects/post-commit-runner.js.map +0 -1
  643. package/dist/extension-ui/catalog.js +0 -265
  644. package/dist/extension-ui/catalog.js.map +0 -1
  645. package/dist/extensions/extension-host.js +0 -34
  646. package/dist/extensions/extension-host.js.map +0 -1
  647. package/dist/external-source-service.js +0 -1036
  648. package/dist/external-source-service.js.map +0 -1
  649. package/dist/future-execution/execution.js +0 -309
  650. package/dist/future-execution/execution.js.map +0 -1
  651. package/dist/future-execution/index.js +0 -2
  652. package/dist/future-execution/index.js.map +0 -1
  653. package/dist/future-execution/lifecycle.js +0 -783
  654. package/dist/future-execution/lifecycle.js.map +0 -1
  655. package/dist/future-execution/model-projection.js +0 -98
  656. package/dist/future-execution/model-projection.js.map +0 -1
  657. package/dist/future-execution/reconciliation.js +0 -91
  658. package/dist/future-execution/reconciliation.js.map +0 -1
  659. package/dist/future-execution/support.js +0 -36
  660. package/dist/future-execution/support.js.map +0 -1
  661. package/dist/future-execution/transition-planner.js +0 -84
  662. package/dist/future-execution/transition-planner.js.map +0 -1
  663. package/dist/future-execution-broadcast.js +0 -13
  664. package/dist/future-execution-broadcast.js.map +0 -1
  665. package/dist/future-execution-presenter.js +0 -143
  666. package/dist/future-execution-presenter.js.map +0 -1
  667. package/dist/future-execution-scheduler.js +0 -37
  668. package/dist/future-execution-scheduler.js.map +0 -1
  669. package/dist/instance-tree.js +0 -41
  670. package/dist/instance-tree.js.map +0 -1
  671. package/dist/integration-tool-registry.js +0 -140
  672. package/dist/integration-tool-registry.js.map +0 -1
  673. package/dist/launch-title.js +0 -36
  674. package/dist/launch-title.js.map +0 -1
  675. package/dist/launcher-model-config-service.js +0 -73
  676. package/dist/launcher-model-config-service.js.map +0 -1
  677. package/dist/launcher-recent-values-service.js +0 -43
  678. package/dist/launcher-recent-values-service.js.map +0 -1
  679. package/dist/leaf-outcome-snapshot-capture.js +0 -101
  680. package/dist/leaf-outcome-snapshot-capture.js.map +0 -1
  681. package/dist/live-turn-projection.d.ts +0 -2
  682. package/dist/live-turn-projection.d.ts.map +0 -1
  683. package/dist/live-turn-projection.js +0 -2
  684. package/dist/live-turn-projection.js.map +0 -1
  685. package/dist/model-providers/builtin-server-adapter.js +0 -73
  686. package/dist/model-providers/builtin-server-adapter.js.map +0 -1
  687. package/dist/model-providers/credentials.js +0 -165
  688. package/dist/model-providers/credentials.js.map +0 -1
  689. package/dist/model-providers/index.js +0 -7
  690. package/dist/model-providers/index.js.map +0 -1
  691. package/dist/model-providers/model-status-cache.js +0 -220
  692. package/dist/model-providers/model-status-cache.js.map +0 -1
  693. package/dist/model-providers/provider-boundary-utils.js +0 -32
  694. package/dist/model-providers/provider-boundary-utils.js.map +0 -1
  695. package/dist/model-providers/provider-options.js +0 -76
  696. package/dist/model-providers/provider-options.js.map +0 -1
  697. package/dist/model-providers/registry.js +0 -138
  698. package/dist/model-providers/registry.js.map +0 -1
  699. package/dist/model-providers/server-adapters.js +0 -63
  700. package/dist/model-providers/server-adapters.js.map +0 -1
  701. package/dist/pi-resources/assemble.js +0 -275
  702. package/dist/pi-resources/assemble.js.map +0 -1
  703. package/dist/pi-resources/bundle-cache.js +0 -125
  704. package/dist/pi-resources/bundle-cache.js.map +0 -1
  705. package/dist/pi-resources/bundle-pin-lifecycle.js +0 -41
  706. package/dist/pi-resources/bundle-pin-lifecycle.js.map +0 -1
  707. package/dist/pi-resources/index.js +0 -4
  708. package/dist/pi-resources/index.js.map +0 -1
  709. package/dist/pi-resources/resource-collector.js +0 -163
  710. package/dist/pi-resources/resource-collector.js.map +0 -1
  711. package/dist/pi-session-tree.js +0 -106
  712. package/dist/pi-session-tree.js.map +0 -1
  713. package/dist/primary-path-snapshot.js +0 -246
  714. package/dist/primary-path-snapshot.js.map +0 -1
  715. package/dist/process-action-input-validation.js +0 -75
  716. package/dist/process-action-input-validation.js.map +0 -1
  717. package/dist/process-action-next-turn-model.js +0 -102
  718. package/dist/process-action-next-turn-model.js.map +0 -1
  719. package/dist/process-action-planner.js +0 -93
  720. package/dist/process-action-planner.js.map +0 -1
  721. package/dist/process-action-registry.js +0 -335
  722. package/dist/process-action-registry.js.map +0 -1
  723. package/dist/process-attention-notifier.js +0 -41
  724. package/dist/process-attention-notifier.js.map +0 -1
  725. package/dist/process-deletion-service.js +0 -48
  726. package/dist/process-deletion-service.js.map +0 -1
  727. package/dist/process-engine/decision.js +0 -22
  728. package/dist/process-engine/decision.js.map +0 -1
  729. package/dist/process-engine/engine.js +0 -168
  730. package/dist/process-engine/engine.js.map +0 -1
  731. package/dist/process-engine/index.js +0 -8
  732. package/dist/process-engine/index.js.map +0 -1
  733. package/dist/process-engine/internal-failures.js +0 -32
  734. package/dist/process-engine/internal-failures.js.map +0 -1
  735. package/dist/process-engine/operation.js +0 -4
  736. package/dist/process-engine/operation.js.map +0 -1
  737. package/dist/process-engine/ops/abort-process.js +0 -104
  738. package/dist/process-engine/ops/abort-process.js.map +0 -1
  739. package/dist/process-engine/ops/abort-turn.js +0 -48
  740. package/dist/process-engine/ops/abort-turn.js.map +0 -1
  741. package/dist/process-engine/ops/accept-worker-turn-start.js +0 -137
  742. package/dist/process-engine/ops/accept-worker-turn-start.js.map +0 -1
  743. package/dist/process-engine/ops/continue-failed-turn.js +0 -109
  744. package/dist/process-engine/ops/continue-failed-turn.js.map +0 -1
  745. package/dist/process-engine/ops/deferred-process-activation.js +0 -98
  746. package/dist/process-engine/ops/deferred-process-activation.js.map +0 -1
  747. package/dist/process-engine/ops/execute-action.js +0 -289
  748. package/dist/process-engine/ops/execute-action.js.map +0 -1
  749. package/dist/process-engine/ops/index.js +0 -17
  750. package/dist/process-engine/ops/index.js.map +0 -1
  751. package/dist/process-engine/ops/park-process.js +0 -14
  752. package/dist/process-engine/ops/park-process.js.map +0 -1
  753. package/dist/process-engine/ops/queue-inputs.js +0 -35
  754. package/dist/process-engine/ops/queue-inputs.js.map +0 -1
  755. package/dist/process-engine/ops/retry-failed-turn.js +0 -74
  756. package/dist/process-engine/ops/retry-failed-turn.js.map +0 -1
  757. package/dist/process-engine/ops/retry-startup.js +0 -65
  758. package/dist/process-engine/ops/retry-startup.js.map +0 -1
  759. package/dist/process-engine/ops/start-process.js +0 -20
  760. package/dist/process-engine/ops/start-process.js.map +0 -1
  761. package/dist/process-engine/ops/turn-failed.js +0 -34
  762. package/dist/process-engine/ops/turn-failed.js.map +0 -1
  763. package/dist/process-engine/ops/turn-outcome.js +0 -345
  764. package/dist/process-engine/ops/turn-outcome.js.map +0 -1
  765. package/dist/process-engine/ops/update-product-refs.js +0 -18
  766. package/dist/process-engine/ops/update-product-refs.js.map +0 -1
  767. package/dist/process-engine/ops/update-semantic-refs.js +0 -21
  768. package/dist/process-engine/ops/update-semantic-refs.js.map +0 -1
  769. package/dist/process-engine/ops/worker-failure.js +0 -81
  770. package/dist/process-engine/ops/worker-failure.js.map +0 -1
  771. package/dist/process-engine/reactions.js +0 -23
  772. package/dist/process-engine/reactions.js.map +0 -1
  773. package/dist/process-engine/recorder.js +0 -245
  774. package/dist/process-engine/recorder.js.map +0 -1
  775. package/dist/process-engine/runner.js +0 -206
  776. package/dist/process-engine/runner.js.map +0 -1
  777. package/dist/process-engine/startup-reconciliation.js +0 -130
  778. package/dist/process-engine/startup-reconciliation.js.map +0 -1
  779. package/dist/process-engine/state-json.js +0 -5
  780. package/dist/process-engine/state-json.js.map +0 -1
  781. package/dist/process-engine/turn-start-preflight.js +0 -229
  782. package/dist/process-engine/turn-start-preflight.js.map +0 -1
  783. package/dist/process-engine/turn-worker-requirement.js +0 -11
  784. package/dist/process-engine/turn-worker-requirement.js.map +0 -1
  785. package/dist/process-engine/types.js +0 -2
  786. package/dist/process-engine/types.js.map +0 -1
  787. package/dist/process-engine/worker-reconciliation.js +0 -29
  788. package/dist/process-engine/worker-reconciliation.js.map +0 -1
  789. package/dist/process-engine/writes/build-continue-failed-turn-writes.js +0 -95
  790. package/dist/process-engine/writes/build-continue-failed-turn-writes.js.map +0 -1
  791. package/dist/process-engine/writes/build-process-abort-writes.js +0 -64
  792. package/dist/process-engine/writes/build-process-abort-writes.js.map +0 -1
  793. package/dist/process-engine/writes/build-process-action-writes.js +0 -140
  794. package/dist/process-engine/writes/build-process-action-writes.js.map +0 -1
  795. package/dist/process-engine/writes/build-process-park-writes.js +0 -48
  796. package/dist/process-engine/writes/build-process-park-writes.js.map +0 -1
  797. package/dist/process-engine/writes/build-retry-writes.js +0 -83
  798. package/dist/process-engine/writes/build-retry-writes.js.map +0 -1
  799. package/dist/process-engine/writes/build-server-transition-writes.js +0 -75
  800. package/dist/process-engine/writes/build-server-transition-writes.js.map +0 -1
  801. package/dist/process-engine/writes/build-turn-failed-writes.js +0 -52
  802. package/dist/process-engine/writes/build-turn-failed-writes.js.map +0 -1
  803. package/dist/process-engine/writes/build-turn-outcome-writes.js +0 -170
  804. package/dist/process-engine/writes/build-turn-outcome-writes.js.map +0 -1
  805. package/dist/process-engine/writes/build-turn-selection-writes.js +0 -158
  806. package/dist/process-engine/writes/build-turn-selection-writes.js.map +0 -1
  807. package/dist/process-engine/writes/build-worker-failure-writes.js +0 -59
  808. package/dist/process-engine/writes/build-worker-failure-writes.js.map +0 -1
  809. package/dist/process-engine/writes/commit-writes.js +0 -252
  810. package/dist/process-engine/writes/commit-writes.js.map +0 -1
  811. package/dist/process-engine/writes/deferred-extension-events.js +0 -13
  812. package/dist/process-engine/writes/deferred-extension-events.js.map +0 -1
  813. package/dist/process-engine/writes/process-effects.js +0 -20
  814. package/dist/process-engine/writes/process-effects.js.map +0 -1
  815. package/dist/process-engine/writes/writes.js +0 -139
  816. package/dist/process-engine/writes/writes.js.map +0 -1
  817. package/dist/process-graph.js +0 -7
  818. package/dist/process-graph.js.map +0 -1
  819. package/dist/process-input-dispatch.js +0 -85
  820. package/dist/process-input-dispatch.js.map +0 -1
  821. package/dist/process-instance-tree-presenter.js +0 -202
  822. package/dist/process-instance-tree-presenter.js.map +0 -1
  823. package/dist/process-launch-executor.js +0 -310
  824. package/dist/process-launch-executor.js.map +0 -1
  825. package/dist/process-launch-plan-model-config.js +0 -22
  826. package/dist/process-launch-plan-model-config.js.map +0 -1
  827. package/dist/process-launch-plan.js +0 -64
  828. package/dist/process-launch-plan.js.map +0 -1
  829. package/dist/process-launcher-registry.js +0 -104
  830. package/dist/process-launcher-registry.js.map +0 -1
  831. package/dist/process-model-availability-recovery.js +0 -41
  832. package/dist/process-model-availability-recovery.js.map +0 -1
  833. package/dist/process-model-availability-transitions.js +0 -14
  834. package/dist/process-model-availability-transitions.js.map +0 -1
  835. package/dist/process-model-integrity-reconciler.js +0 -27
  836. package/dist/process-model-integrity-reconciler.js.map +0 -1
  837. package/dist/process-model-policy/construct.js +0 -94
  838. package/dist/process-model-policy/construct.js.map +0 -1
  839. package/dist/process-model-policy/evaluate.js +0 -163
  840. package/dist/process-model-policy/evaluate.js.map +0 -1
  841. package/dist/process-model-policy/fingerprint.js +0 -39
  842. package/dist/process-model-policy/fingerprint.js.map +0 -1
  843. package/dist/process-model-policy/index.js +0 -47
  844. package/dist/process-model-policy/index.js.map +0 -1
  845. package/dist/process-model-policy/input.js +0 -79
  846. package/dist/process-model-policy/input.js.map +0 -1
  847. package/dist/process-model-policy/integrity.js +0 -53
  848. package/dist/process-model-policy/integrity.js.map +0 -1
  849. package/dist/process-model-policy/launch.js +0 -171
  850. package/dist/process-model-policy/launch.js.map +0 -1
  851. package/dist/process-model-policy/project.js +0 -144
  852. package/dist/process-model-policy/project.js.map +0 -1
  853. package/dist/process-model-policy/stable-availability.js +0 -16
  854. package/dist/process-model-policy/stable-availability.js.map +0 -1
  855. package/dist/process-model-policy/types.js +0 -9
  856. package/dist/process-model-policy/types.js.map +0 -1
  857. package/dist/process-model-policy-presenter.js +0 -77
  858. package/dist/process-model-policy-presenter.js.map +0 -1
  859. package/dist/process-model-selection.js +0 -101
  860. package/dist/process-model-selection.js.map +0 -1
  861. package/dist/process-operation-coordinator.js +0 -23
  862. package/dist/process-operation-coordinator.js.map +0 -1
  863. package/dist/process-operator-attention.js +0 -149
  864. package/dist/process-operator-attention.js.map +0 -1
  865. package/dist/process-overview-presenter.js +0 -220
  866. package/dist/process-overview-presenter.js.map +0 -1
  867. package/dist/process-question-service.js +0 -131
  868. package/dist/process-question-service.js.map +0 -1
  869. package/dist/process-session-store.js +0 -210
  870. package/dist/process-session-store.js.map +0 -1
  871. package/dist/process-title-generator.js +0 -628
  872. package/dist/process-title-generator.js.map +0 -1
  873. package/dist/process-turn-trace.js +0 -482
  874. package/dist/process-turn-trace.js.map +0 -1
  875. package/dist/process-ui-registry.js +0 -22
  876. package/dist/process-ui-registry.js.map +0 -1
  877. package/dist/process-ui-snapshot-presenter.js +0 -894
  878. package/dist/process-ui-snapshot-presenter.js.map +0 -1
  879. package/dist/process-watcher-registry.js +0 -159
  880. package/dist/process-watcher-registry.js.map +0 -1
  881. package/dist/product-ref-state.js +0 -84
  882. package/dist/product-ref-state.js.map +0 -1
  883. package/dist/product-turn-result-markdown.d.ts +0 -9
  884. package/dist/product-turn-result-markdown.d.ts.map +0 -1
  885. package/dist/product-turn-result-markdown.js +0 -44
  886. package/dist/product-turn-result-markdown.js.map +0 -1
  887. package/dist/project-mutation-service.js +0 -68
  888. package/dist/project-mutation-service.js.map +0 -1
  889. package/dist/repository-credentials/service.js +0 -49
  890. package/dist/repository-credentials/service.js.map +0 -1
  891. package/dist/result-image-store.js +0 -85
  892. package/dist/result-image-store.js.map +0 -1
  893. package/dist/result-image-validation.js +0 -47
  894. package/dist/result-image-validation.js.map +0 -1
  895. package/dist/routes/future-executions.js +0 -62
  896. package/dist/routes/future-executions.js.map +0 -1
  897. package/dist/routes/internal-worker-auth.js +0 -33
  898. package/dist/routes/internal-worker-auth.js.map +0 -1
  899. package/dist/routes/internal-worker-session-snapshot.js +0 -172
  900. package/dist/routes/internal-worker-session-snapshot.js.map +0 -1
  901. package/dist/routes/launchers.js +0 -140
  902. package/dist/routes/launchers.js.map +0 -1
  903. package/dist/routes/process-actions.js +0 -210
  904. package/dist/routes/process-actions.js.map +0 -1
  905. package/dist/routes/process-detail.js +0 -110
  906. package/dist/routes/process-detail.js.map +0 -1
  907. package/dist/routes/process-diagnostics-assembler.js +0 -92
  908. package/dist/routes/process-diagnostics-assembler.js.map +0 -1
  909. package/dist/routes/process-engine-http.js +0 -82
  910. package/dist/routes/process-engine-http.js.map +0 -1
  911. package/dist/routes/process-primary-path-assembler.js +0 -67
  912. package/dist/routes/process-primary-path-assembler.js.map +0 -1
  913. package/dist/routes/process-questions.js +0 -12
  914. package/dist/routes/process-questions.js.map +0 -1
  915. package/dist/routes/process-route-helpers.js +0 -523
  916. package/dist/routes/process-route-helpers.js.map +0 -1
  917. package/dist/routes/process-session.js +0 -24
  918. package/dist/routes/process-session.js.map +0 -1
  919. package/dist/routes/processes.js +0 -15
  920. package/dist/routes/processes.js.map +0 -1
  921. package/dist/routes/result-images.js +0 -92
  922. package/dist/routes/result-images.js.map +0 -1
  923. package/dist/routes/skills.js +0 -35
  924. package/dist/routes/skills.js.map +0 -1
  925. package/dist/routes/ui-renderers.js +0 -40
  926. package/dist/routes/ui-renderers.js.map +0 -1
  927. package/dist/routes/watchers.js +0 -46
  928. package/dist/routes/watchers.js.map +0 -1
  929. package/dist/runtime-server-config.js +0 -46
  930. package/dist/runtime-server-config.js.map +0 -1
  931. package/dist/scheduled-action-preflight.js +0 -53
  932. package/dist/scheduled-action-preflight.js.map +0 -1
  933. package/dist/semantic-entry-ref-state.js +0 -97
  934. package/dist/semantic-entry-ref-state.js.map +0 -1
  935. package/dist/semantic-state-json.d.ts +0 -6
  936. package/dist/semantic-state-json.d.ts.map +0 -1
  937. package/dist/semantic-state-json.js +0 -6
  938. package/dist/semantic-state-json.js.map +0 -1
  939. package/dist/semantic-turn-result-markdown.d.ts.map +0 -1
  940. package/dist/semantic-turn-result-markdown.js +0 -45
  941. package/dist/semantic-turn-result-markdown.js.map +0 -1
  942. package/dist/server-automatic-turn-drainer.d.ts +0 -13
  943. package/dist/server-automatic-turn-drainer.d.ts.map +0 -1
  944. package/dist/server-automatic-turn-drainer.js +0 -250
  945. package/dist/server-automatic-turn-drainer.js.map +0 -1
  946. package/dist/server-bootstrap/build-host-capabilities.js +0 -83
  947. package/dist/server-bootstrap/build-host-capabilities.js.map +0 -1
  948. package/dist/server-bootstrap/load-extension-catalog.js +0 -17
  949. package/dist/server-bootstrap/load-extension-catalog.js.map +0 -1
  950. package/dist/server-bootstrap/register-http.js +0 -52
  951. package/dist/server-bootstrap/register-http.js.map +0 -1
  952. package/dist/server-bootstrap/register-websocket.js +0 -111
  953. package/dist/server-bootstrap/register-websocket.js.map +0 -1
  954. package/dist/server-topology.js +0 -33
  955. package/dist/server-topology.js.map +0 -1
  956. package/dist/skills/catalog-service.js +0 -66
  957. package/dist/skills/catalog-service.js.map +0 -1
  958. package/dist/skills/invocation-detector.js +0 -54
  959. package/dist/skills/invocation-detector.js.map +0 -1
  960. package/dist/skills/skill-dependencies.js +0 -17
  961. package/dist/skills/skill-dependencies.js.map +0 -1
  962. package/dist/skills/skill-frontmatter.js +0 -13
  963. package/dist/skills/skill-frontmatter.js.map +0 -1
  964. package/dist/skills/skill-id.js +0 -3
  965. package/dist/skills/skill-id.js.map +0 -1
  966. package/dist/skills/source-importer.js +0 -105
  967. package/dist/skills/source-importer.js.map +0 -1
  968. package/dist/supervisor/accepted-turn-start-replay.js +0 -23
  969. package/dist/supervisor/accepted-turn-start-replay.js.map +0 -1
  970. package/dist/supervisor/adoption/adoption-plan.js +0 -25
  971. package/dist/supervisor/adoption/adoption-plan.js.map +0 -1
  972. package/dist/supervisor/adoption/worker-adoption-coordinator.js +0 -227
  973. package/dist/supervisor/adoption/worker-adoption-coordinator.js.map +0 -1
  974. package/dist/supervisor/idle-worker-ttl.js +0 -26
  975. package/dist/supervisor/idle-worker-ttl.js.map +0 -1
  976. package/dist/supervisor/ipc-handler.js +0 -281
  977. package/dist/supervisor/ipc-handler.js.map +0 -1
  978. package/dist/supervisor/stale-heartbeat-watchdog.js +0 -88
  979. package/dist/supervisor/stale-heartbeat-watchdog.js.map +0 -1
  980. package/dist/supervisor/synthetic-worker-failure.js +0 -21
  981. package/dist/supervisor/synthetic-worker-failure.js.map +0 -1
  982. package/dist/supervisor/worker-api-compatibility.js +0 -20
  983. package/dist/supervisor/worker-api-compatibility.js.map +0 -1
  984. package/dist/supervisor/worker-connect-token.js +0 -13
  985. package/dist/supervisor/worker-connect-token.js.map +0 -1
  986. package/dist/supervisor/worker-event-ingestor.js +0 -209
  987. package/dist/supervisor/worker-event-ingestor.js.map +0 -1
  988. package/dist/supervisor/worker-input-ack-handler.js +0 -37
  989. package/dist/supervisor/worker-input-ack-handler.js.map +0 -1
  990. package/dist/supervisor/worker-lease-observer.js +0 -79
  991. package/dist/supervisor/worker-lease-observer.js.map +0 -1
  992. package/dist/supervisor/worker-shutdown-controller.js +0 -68
  993. package/dist/supervisor/worker-shutdown-controller.js.map +0 -1
  994. package/dist/supervisor/worker-start-payload-builder.js +0 -286
  995. package/dist/supervisor/worker-start-payload-builder.js.map +0 -1
  996. package/dist/supervisor/worker-storage-layout.js +0 -60
  997. package/dist/supervisor/worker-storage-layout.js.map +0 -1
  998. package/dist/supervisor/worker-supervisor.js +0 -703
  999. package/dist/supervisor/worker-supervisor.js.map +0 -1
  1000. package/dist/supervisor/worker-turn-ipc-recorder.js +0 -158
  1001. package/dist/supervisor/worker-turn-ipc-recorder.js.map +0 -1
  1002. package/dist/supervisor/worker-websocket-ipc.js +0 -230
  1003. package/dist/supervisor/worker-websocket-ipc.js.map +0 -1
  1004. package/dist/test-helpers/fake-worker-supervisor.js +0 -64
  1005. package/dist/test-helpers/fake-worker-supervisor.js.map +0 -1
  1006. package/dist/test-helpers/ipc-handler-harness.js +0 -314
  1007. package/dist/test-helpers/ipc-handler-harness.js.map +0 -1
  1008. package/dist/test-helpers/model-provider-fixtures.js +0 -8
  1009. package/dist/test-helpers/model-provider-fixtures.js.map +0 -1
  1010. package/dist/test-helpers/process-binding-fixtures.js +0 -121
  1011. package/dist/test-helpers/process-binding-fixtures.js.map +0 -1
  1012. package/dist/test-helpers/process-fixtures.js +0 -206
  1013. package/dist/test-helpers/process-fixtures.js.map +0 -1
  1014. package/dist/test-helpers/process-model-fixtures.js +0 -159
  1015. package/dist/test-helpers/process-model-fixtures.js.map +0 -1
  1016. package/dist/test-helpers/process-title-fixtures.js +0 -36
  1017. package/dist/test-helpers/process-title-fixtures.js.map +0 -1
  1018. package/dist/test-helpers/structural-process-fixtures.js +0 -24
  1019. package/dist/test-helpers/structural-process-fixtures.js.map +0 -1
  1020. package/dist/test-helpers/turn-fixtures.js +0 -148
  1021. package/dist/test-helpers/turn-fixtures.js.map +0 -1
  1022. package/dist/test-helpers/turn-start-preflight-fixtures.js +0 -34
  1023. package/dist/test-helpers/turn-start-preflight-fixtures.js.map +0 -1
  1024. package/dist/test-helpers/unit-deps.js +0 -106
  1025. package/dist/test-helpers/unit-deps.js.map +0 -1
  1026. package/dist/turn-progress.js +0 -108
  1027. package/dist/turn-progress.js.map +0 -1
  1028. package/dist/worker-runtime-profile-selection.js +0 -90
  1029. package/dist/worker-runtime-profile-selection.js.map +0 -1
  1030. package/dist/writes-DNXpryd0.d.ts +0 -6653
  1031. package/dist/ws/broadcast.js +0 -34
  1032. package/dist/ws/broadcast.js.map +0 -1
  1033. package/src/live-turn-projection.ts +0 -8
  1034. package/src/product-turn-result-markdown.ts +0 -70
  1035. package/src/semantic-state-json.ts +0 -18
  1036. package/src/semantic-turn-result-markdown.ts +0 -93
  1037. package/src/server-automatic-turn-drainer.ts +0 -316
@@ -1,7 +1,14 @@
1
- import type { ProcessInstance, ProcessProject, TurnId } from "@leitwerk-dev/domain";
1
+ import { createHash } from "node:crypto";
2
+ import {
3
+ asUnknownRecord,
4
+ type ProcessInstance,
5
+ type ProcessProject,
6
+ readNonBlankString,
7
+ type TurnId,
8
+ } from "@leitwerk-dev/domain";
2
9
  import type {
3
10
  ActionExecutionResultLike,
4
- ExternalActionSource,
11
+ ExternalObservationInput,
5
12
  ExternalSourceArmingLike,
6
13
  ExternalSourceFireInput,
7
14
  ExternalSourceServiceLike,
@@ -19,11 +26,18 @@ import {
19
26
  } from "@leitwerk-dev/process-sdk";
20
27
  import { generateId, now } from "./db/repo-helpers.js";
21
28
  import type { PendingExternalSourceFire, RepositoryBundle } from "./db/repositories.js";
29
+ import {
30
+ normalizeExternalEventDescription,
31
+ normalizeExternalObservation,
32
+ } from "./external-source-reporting.js";
22
33
  import type { ProcessActionRegistry } from "./process-action-registry.js";
23
34
  import { accept, reject } from "./process-engine/decision.js";
24
35
  import { defineOperation } from "./process-engine/operation.js";
25
- import type { ProcessEngine } from "./process-engine/types.js";
26
- import { buildServerTransitionWrites } from "./process-engine/writes/build-server-transition-writes.js";
36
+ import type { EngineFailure, ProcessEngine } from "./process-engine/types.js";
37
+ import {
38
+ buildServerTransitionWrites,
39
+ transitionStartReferences,
40
+ } from "./process-engine/writes/build-server-transition-writes.js";
27
41
  import { createDeferredExtensionEvent } from "./process-engine/writes/deferred-extension-events.js";
28
42
  import { appendProcessEffects } from "./process-engine/writes/process-effects.js";
29
43
  import {
@@ -45,7 +59,6 @@ interface ExternalTransitionRuntime<TParams = unknown, TState = unknown> {
45
59
  }
46
60
 
47
61
  interface ResolvedExternalSourceArming extends ExternalSourceArmingLike {
48
- transitionIndex: number;
49
62
  transition: ExternalTransitionRuntime;
50
63
  transitionTrigger: string;
51
64
  label: string | null;
@@ -63,12 +76,16 @@ interface KnownExternalArming {
63
76
  }
64
77
 
65
78
  export interface ExternalSourceServiceDeps
66
- extends Pick<RepositoryBundle, "processes" | "projects" | "pendingExternalSourceFires"> {
79
+ extends Pick<
80
+ RepositoryBundle,
81
+ "processes" | "projects" | "pendingExternalSourceFires" | "events"
82
+ > {
67
83
  commands: ProcessEngine;
68
84
  processActionRegistry: ProcessActionRegistry;
69
85
  }
70
86
 
71
87
  export interface ExternalSourceService extends ExternalSourceServiceLike {
88
+ currentGenerations(instanceId: string): Array<{ id: string; generation: string }>;
72
89
  drainQueued(instanceId: string): Promise<void>;
73
90
  invalidateArmings(instanceId: string): void;
74
91
  reconcileArmings(instanceId: string): Promise<void>;
@@ -78,34 +95,7 @@ export interface ExternalSourceService extends ExternalSourceServiceLike {
78
95
  const TERMINAL_STATUSES = new Set(["completed", "aborted"]);
79
96
 
80
97
  function normalizeRecord(value: unknown): Record<string, unknown> {
81
- return typeof value === "object" && value !== null && !Array.isArray(value)
82
- ? { ...(value as Record<string, unknown>) }
83
- : {};
84
- }
85
-
86
- function sourceLabel(source: ExternalActionSource): string | null {
87
- return typeof source.label === "string" && source.label.trim() !== "" ? source.label : null;
88
- }
89
-
90
- function sourceDescription(source: ExternalActionSource): string | null {
91
- return typeof source.description === "string" && source.description.trim() !== ""
92
- ? source.description
93
- : null;
94
- }
95
-
96
- function resolveSource(input: {
97
- source: ExternalActionSource;
98
- process: ProcessInstance;
99
- projects: readonly ProcessProject[];
100
- params: unknown;
101
- state: unknown;
102
- }): unknown {
103
- return input.source.resolve?.({
104
- process: input.process,
105
- projects: input.projects,
106
- params: input.params,
107
- state: input.state,
108
- });
98
+ return { ...asUnknownRecord(value) };
109
99
  }
110
100
 
111
101
  function isSelectedWaitingTurn(process: ProcessInstance): boolean {
@@ -217,6 +207,18 @@ function buildExternalSourceEventPayload(input: {
217
207
  };
218
208
  }
219
209
 
210
+ function armingEventData(arming: ResolvedExternalSourceArming) {
211
+ return {
212
+ armingId: arming.id,
213
+ instanceId: arming.instanceId,
214
+ turnId: arming.turnId,
215
+ externalActionId: arming.externalActionId,
216
+ sourceKind: arming.source.kind,
217
+ label: arming.label,
218
+ description: arming.description,
219
+ };
220
+ }
221
+
220
222
  function readPublishedInput(input: {
221
223
  arming: ResolvedExternalSourceArming;
222
224
  fireInput: Record<string, unknown>;
@@ -300,24 +302,12 @@ async function buildExternalSourceEffectWrites(input: {
300
302
  return writes;
301
303
  }
302
304
 
303
- function parseNewExternalActionArmingId(armingId: string): {
304
- turnId: string;
305
- externalActionId: string;
306
- } | null {
307
- const separator = armingId.indexOf(":");
308
- if (separator <= 0 || separator === armingId.length - 1) {
309
- return null;
310
- }
311
- return {
312
- turnId: armingId.slice(0, separator),
313
- externalActionId: armingId.slice(separator + 1),
314
- };
315
- }
305
+ const INSTRUCTION_KEYS = ["instruction", "bodyMarkdown", "message", "text", "content"];
316
306
 
317
307
  function mergeInstructionText(values: readonly Record<string, unknown>[]): string | null {
318
308
  const parts: string[] = [];
319
309
  for (const input of values) {
320
- for (const key of ["instruction", "bodyMarkdown", "message", "text", "content"]) {
310
+ for (const key of INSTRUCTION_KEYS) {
321
311
  const value = input[key];
322
312
  if (typeof value === "string" && value.trim() !== "") {
323
313
  parts.push(value.trim());
@@ -328,23 +318,20 @@ function mergeInstructionText(values: readonly Record<string, unknown>[]): strin
328
318
  return parts.length > 0 ? parts.join("\n\n") : null;
329
319
  }
330
320
 
331
- function providerEventsFrom(event: Record<string, unknown>): Record<string, unknown>[] {
332
- const nested = event.providerEvents;
333
- if (Array.isArray(nested)) {
334
- return nested.map(normalizeRecord).filter((entry) => Object.keys(entry).length > 0);
335
- }
336
- return Object.keys(event).length > 0 ? [event] : [];
337
- }
338
-
339
- function providerInputsFrom(input: Record<string, unknown>): Record<string, unknown>[] {
340
- const nested = input.providerInputs;
321
+ function providerRecordsFrom(
322
+ value: Record<string, unknown>,
323
+ key: "providerEvents" | "providerInputs",
324
+ ): Record<string, unknown>[] {
325
+ const nested = value[key];
341
326
  if (Array.isArray(nested)) {
342
327
  return nested.map(normalizeRecord).filter((entry) => Object.keys(entry).length > 0);
343
328
  }
344
- return Object.keys(input).length > 0 ? [input] : [];
329
+ return Object.keys(value).length > 0 ? [value] : [];
345
330
  }
346
331
 
347
- function mergePendingFires(fires: readonly PendingExternalSourceFire[]): {
332
+ function mergePendingFires(
333
+ fires: readonly Pick<PendingExternalSourceFire, "input" | "event" | "queuedCount">[],
334
+ ): {
348
335
  input: Record<string, unknown>;
349
336
  event: Record<string, unknown>;
350
337
  queuedCount: number;
@@ -356,24 +343,16 @@ function mergePendingFires(fires: readonly PendingExternalSourceFire[]): {
356
343
  const mergedInput = { ...(first?.input ?? {}) };
357
344
  const instruction = mergeInstructionText(fires.map((fire) => fire.input));
358
345
  if (instruction !== null) {
359
- for (const key of ["instruction", "bodyMarkdown", "message", "text", "content"]) {
360
- if (Object.hasOwn(mergedInput, key)) {
361
- mergedInput[key] = instruction;
362
- }
363
- }
364
- if (
365
- !Object.keys(mergedInput).some((key) =>
366
- ["instruction", "bodyMarkdown", "message", "text", "content"].includes(key),
367
- )
368
- ) {
369
- mergedInput.instruction = instruction;
346
+ const keys = INSTRUCTION_KEYS.filter((key) => Object.hasOwn(mergedInput, key));
347
+ for (const key of keys.length > 0 ? keys : ["instruction"]) {
348
+ mergedInput[key] = instruction;
370
349
  }
371
350
  }
372
- const providerInputs = fires.flatMap((fire) => providerInputsFrom(fire.input));
351
+ const providerInputs = fires.flatMap((fire) => providerRecordsFrom(fire.input, "providerInputs"));
373
352
  if (providerInputs.length > 0) {
374
353
  mergedInput.providerInputs = providerInputs;
375
354
  }
376
- const providerEvents = fires.flatMap((fire) => providerEventsFrom(fire.event));
355
+ const providerEvents = fires.flatMap((fire) => providerRecordsFrom(fire.event, "providerEvents"));
377
356
  return {
378
357
  input: mergedInput,
379
358
  event: {
@@ -384,6 +363,19 @@ function mergePendingFires(fires: readonly PendingExternalSourceFire[]): {
384
363
  };
385
364
  }
386
365
 
366
+ function externalSourceFailure(result: EngineFailure<unknown>): ActionExecutionResultLike {
367
+ if (result.stage === "post_commit" && result.process) {
368
+ return {
369
+ ok: false,
370
+ stage: "post_commit",
371
+ process: result.process,
372
+ code: result.code,
373
+ error: result.message,
374
+ };
375
+ }
376
+ return { ok: false, stage: "pre_commit", code: result.code, error: result.message };
377
+ }
378
+
387
379
  function terminal(process: ProcessInstance): boolean {
388
380
  return TERMINAL_STATUSES.has(process.lifecycleStatus);
389
381
  }
@@ -417,6 +409,7 @@ export function createExternalSourceService(
417
409
  process,
418
410
  );
419
411
  const projects = deps.projects.listByInstance(process.id);
412
+ const context = { process, projects, params, state };
420
413
 
421
414
  if (isExternalTurnDefinition(turnDef)) {
422
415
  turnDef.transitions.forEach((transition, transitionIndex) => {
@@ -432,22 +425,12 @@ export function createExternalSourceService(
432
425
  turnId,
433
426
  externalActionId: `${transition.source.kind}:${transitionIndex}`,
434
427
  source: transition.source,
435
- resolved: resolveSource({
436
- source: transition.source,
437
- process,
438
- projects,
439
- params,
440
- state,
441
- }),
442
- transitionIndex,
428
+ resolved: transition.source.resolve?.({ ...context }),
443
429
  transition,
444
430
  transitionTrigger: id,
445
- label: sourceLabel(transition.source),
446
- description: sourceDescription(transition.source),
447
- process,
448
- projects,
449
- params,
450
- state,
431
+ label: readNonBlankString(transition.source.label),
432
+ description: readNonBlankString(transition.source.description),
433
+ ...context,
451
434
  });
452
435
  });
453
436
  return armed;
@@ -457,7 +440,7 @@ export function createExternalSourceService(
457
440
  return [];
458
441
  }
459
442
  for (const [externalActionId, action] of Object.entries(turnDef.externalActions ?? {})) {
460
- if (action.when && !action.when({ process, projects, params, state })) {
443
+ if (action.when && !action.when({ ...context })) {
461
444
  continue;
462
445
  }
463
446
  const id = getExternalActionArmingId({ turnId, externalActionId });
@@ -468,22 +451,12 @@ export function createExternalSourceService(
468
451
  turnId,
469
452
  externalActionId,
470
453
  source: action.source,
471
- resolved: resolveSource({
472
- source: action.source,
473
- process,
474
- projects,
475
- params,
476
- state,
477
- }),
478
- transitionIndex: 0,
454
+ resolved: action.source.resolve?.({ ...context }),
479
455
  transition: action,
480
456
  transitionTrigger: getExternalActionTransitionTrigger({ externalActionId }),
481
- label: action.label ?? sourceLabel(action.source),
482
- description: action.description ?? sourceDescription(action.source),
483
- process,
484
- projects,
485
- params,
486
- state,
457
+ label: action.label ?? readNonBlankString(action.source.label),
458
+ description: action.description ?? readNonBlankString(action.source.description),
459
+ ...context,
487
460
  });
488
461
  }
489
462
  return armed;
@@ -516,6 +489,23 @@ export function createExternalSourceService(
516
489
  return [...currentArmingsByInstance.values()].flat();
517
490
  }
518
491
 
492
+ function generationFor(arming: ResolvedExternalSourceArming): string {
493
+ return createHash("sha256")
494
+ .update(
495
+ JSON.stringify({
496
+ instanceId: arming.instanceId,
497
+ id: arming.id,
498
+ revision: arming.process.planRevision,
499
+ selectionId:
500
+ deps.events.listByInstanceEventTypes(arming.instanceId, ["turn_selected"], 1)[0]?.id ??
501
+ null,
502
+ config: arming.source.config,
503
+ resolved: arming.resolved,
504
+ }),
505
+ )
506
+ .digest("hex");
507
+ }
508
+
519
509
  function resolveArming(
520
510
  instanceId: string,
521
511
  armingId: string,
@@ -589,13 +579,7 @@ export function createExternalSourceService(
589
579
  instanceId: entry.instanceId,
590
580
  eventType: "external_source_armed",
591
581
  data: buildExternalSourceEventPayload({
592
- armingId: entry.id,
593
- instanceId: entry.instanceId,
594
- turnId: entry.turnId,
595
- externalActionId: entry.externalActionId,
596
- sourceKind: entry.source.kind,
597
- label: entry.label,
598
- description: entry.description,
582
+ ...armingEventData(entry),
599
583
  resolved: entry.resolved,
600
584
  provider: normalizeRecord(entry.resolved),
601
585
  }),
@@ -700,6 +684,7 @@ export function createExternalSourceService(
700
684
  {
701
685
  instanceId: string;
702
686
  armingId: string;
687
+ generation?: string;
703
688
  input: Record<string, unknown>;
704
689
  event: Record<string, unknown>;
705
690
  queuedCount?: number;
@@ -711,6 +696,9 @@ export function createExternalSourceService(
711
696
  label: "Fire external source",
712
697
  async decide(ctx, input) {
713
698
  const arming = resolveArming(input.instanceId, input.armingId);
699
+ if (input.generation && (!arming || generationFor(arming) !== input.generation)) {
700
+ return reject("external_source_superseded", "External source subscription was superseded");
701
+ }
714
702
  if (!arming) {
715
703
  return reject(
716
704
  "external_source_not_armed",
@@ -727,59 +715,43 @@ export function createExternalSourceService(
727
715
  );
728
716
  }
729
717
 
730
- const effectWrites = await buildExternalSourceEffectWrites({
731
- arming,
732
- fireInput: input.input,
733
- fireEvent: input.event,
734
- });
735
- if (isWriteBuildFailure(effectWrites)) {
736
- const failedWrites = createWrites();
718
+ const failedDecision = (failure: { code: string; message: string }) => {
719
+ const writes = createWrites();
737
720
  appendExternalSourceEvent(
738
- failedWrites,
721
+ writes,
739
722
  arming.instanceId,
740
723
  "external_source_failed",
741
724
  buildExternalSourceEventPayload({
742
- armingId: arming.id,
743
- instanceId: arming.instanceId,
744
- turnId: arming.turnId,
745
- externalActionId: arming.externalActionId,
746
- sourceKind: arming.source.kind,
747
- label: arming.label,
748
- description: arming.description,
725
+ ...armingEventData(arming),
749
726
  provider: input.event,
750
727
  fireInput: input.input,
751
- code: effectWrites.code,
752
- message: effectWrites.message,
728
+ code: failure.code,
729
+ message: failure.message,
753
730
  }),
754
731
  );
755
- return accept({ writes: failedWrites, data: { ok: false, code: effectWrites.code } });
756
- }
732
+ return accept({ writes, data: { ok: false, code: failure.code } });
733
+ };
734
+
735
+ const effectWrites = await buildExternalSourceEffectWrites({
736
+ arming,
737
+ fireInput: input.input,
738
+ fireEvent: input.event,
739
+ });
740
+ if (isWriteBuildFailure(effectWrites)) return failedDecision(effectWrites);
757
741
 
758
- const recordedAt = now();
759
- const turnRecordId = generateId("trn");
760
742
  const publishedInput = readPublishedInput({ arming, fireInput: input.input });
761
- if (publishedInput && "ok" in publishedInput && publishedInput.ok === false) {
762
- const failedWrites = createWrites();
763
- appendExternalSourceEvent(
764
- failedWrites,
765
- arming.instanceId,
766
- "external_source_failed",
767
- buildExternalSourceEventPayload({
768
- armingId: arming.id,
769
- instanceId: arming.instanceId,
770
- turnId: arming.turnId,
771
- externalActionId: arming.externalActionId,
772
- sourceKind: arming.source.kind,
773
- label: arming.label,
774
- description: arming.description,
775
- provider: input.event,
776
- fireInput: input.input,
777
- code: publishedInput.code,
778
- message: publishedInput.message,
779
- }),
743
+ if (publishedInput && "ok" in publishedInput) return failedDecision(publishedInput);
744
+
745
+ let eventDescription: ReturnType<typeof normalizeExternalEventDescription> = null;
746
+ try {
747
+ eventDescription = normalizeExternalEventDescription(
748
+ arming.source.describeEvent?.(input.event ?? {}),
780
749
  );
781
- return accept({ writes: failedWrites, data: { ok: false, code: publishedInput.code } });
750
+ } catch {
751
+ // Optional reporting must not change event consumption or process routing.
782
752
  }
753
+ const recordedAt = now();
754
+ const turnRecordId = generateId("trn");
783
755
 
784
756
  const externalWrites = createWrites({
785
757
  turnRecordWrites: [
@@ -792,7 +764,7 @@ export function createExternalSourceService(
792
764
  turnType: "external",
793
765
  status: "succeeded",
794
766
  pathType: "primary",
795
- ...(publishedInput && !("ok" in publishedInput)
767
+ ...(publishedInput
796
768
  ? {
797
769
  resultPiEntryId: `external:${turnRecordId}:${publishedInput.productName}`,
798
770
  turnResultMarkdown: publishedInput.markdown,
@@ -818,10 +790,10 @@ export function createExternalSourceService(
818
790
  sourceKind: arming.source.kind,
819
791
  label: arming.label,
820
792
  description: arming.description,
793
+ ...(eventDescription ? { eventDescription } : {}),
794
+ actionSource: "external",
821
795
  event: input.event,
822
- ...(publishedInput && !("ok" in publishedInput)
823
- ? { publishedProduct: publishedInput.productName }
824
- : {}),
796
+ ...(publishedInput ? { publishedProduct: publishedInput.productName } : {}),
825
797
  },
826
798
  createdAt: recordedAt,
827
799
  updatedAt: recordedAt,
@@ -830,7 +802,7 @@ export function createExternalSourceService(
830
802
  ],
831
803
  });
832
804
 
833
- if (publishedInput && !("ok" in publishedInput)) {
805
+ if (publishedInput) {
834
806
  const baseStateJson = effectWrites.processPatch.stateJson ?? ctx.process.stateJson;
835
807
  const patchedStateJson = mergeProductRefPatchIntoStateJson(
836
808
  baseStateJson,
@@ -864,19 +836,12 @@ export function createExternalSourceService(
864
836
  arming.instanceId,
865
837
  "external_source_consumed",
866
838
  buildExternalSourceEventPayload({
867
- armingId: arming.id,
868
- instanceId: arming.instanceId,
869
- turnId: arming.turnId,
870
- externalActionId: arming.externalActionId,
871
- sourceKind: arming.source.kind,
872
- label: arming.label,
873
- description: arming.description,
839
+ ...armingEventData(arming),
874
840
  resolved: arming.resolved,
875
841
  provider: input.event,
876
842
  fireInput: input.input,
877
843
  queuedCount: input.queuedCount,
878
- publishedProduct:
879
- publishedInput && !("ok" in publishedInput) ? publishedInput.productName : null,
844
+ publishedProduct: publishedInput ? publishedInput.productName : null,
880
845
  }),
881
846
  );
882
847
 
@@ -894,6 +859,14 @@ export function createExternalSourceService(
894
859
  return reject(transitionWrites.code, transitionWrites.message);
895
860
  }
896
861
 
862
+ const annotation = externalWrites.turnAnnotationWrites[0];
863
+ if (annotation?.kind === "create") {
864
+ annotation.input.payload = {
865
+ ...annotation.input.payload,
866
+ selectedTurnIdAfter: transitionWrites.processPatch.selectedTurnId ?? null,
867
+ ...transitionStartReferences(transitionWrites),
868
+ };
869
+ }
897
870
  return accept({
898
871
  writes: mergeWrites(effectWrites, externalWrites, transitionWrites),
899
872
  data: {
@@ -906,6 +879,61 @@ export function createExternalSourceService(
906
879
  },
907
880
  });
908
881
 
882
+ const ObserveExternalSource = defineOperation<
883
+ "observe_external_source",
884
+ ExternalObservationInput,
885
+ void
886
+ >({
887
+ kind: "observe_external_source",
888
+ label: "Observe external source",
889
+ async decide(ctx, input) {
890
+ const arming = resolveArming(input.instanceId, input.armingId);
891
+ if (!arming || generationFor(arming) !== input.generation)
892
+ return reject("external_observation_stale", "Subscription generation is no longer current");
893
+ if (!input.observation && !input.refreshError)
894
+ return reject(
895
+ "external_observation_invalid",
896
+ "An observation or refresh error is required",
897
+ );
898
+ const observation =
899
+ input.observation === undefined
900
+ ? undefined
901
+ : normalizeExternalObservation(input.observation);
902
+ if (observation === null)
903
+ return reject("external_observation_invalid", "Invalid observation report");
904
+ const key = `external_observation:${input.armingId}:${input.generation}`;
905
+ const previous = ctx.deps.turnAnnotations.findByKey(input.instanceId, key);
906
+ const recordedAt = now();
907
+ const payload = {
908
+ ...previous?.payload,
909
+ armingId: input.armingId,
910
+ generation: input.generation,
911
+ turnId: arming.turnId,
912
+ ...(observation ? { observation } : {}),
913
+ refreshError: input.refreshError ?? null,
914
+ refreshedAt: recordedAt,
915
+ };
916
+ const writes = createWrites();
917
+ writes.turnAnnotationWrites.push(
918
+ previous
919
+ ? { kind: "update", id: previous.id, input: { payload, updatedAt: recordedAt } }
920
+ : {
921
+ kind: "create",
922
+ input: {
923
+ instanceId: input.instanceId,
924
+ annotationType: "external_observation",
925
+ annotationKey: key,
926
+ references: [],
927
+ payload,
928
+ createdAt: recordedAt,
929
+ updatedAt: recordedAt,
930
+ },
931
+ },
932
+ );
933
+ return accept({ writes });
934
+ },
935
+ });
936
+
909
937
  const QueueExternalSourceFire = defineOperation<
910
938
  "queue_external_source_fire",
911
939
  {
@@ -944,18 +972,9 @@ export function createExternalSourceService(
944
972
  const merged = mergePendingFires([
945
973
  existing,
946
974
  {
947
- id: "pending:new",
948
- instanceId: input.instanceId,
949
- armingId: input.armingId,
950
- turnId: input.known.turnId,
951
- externalActionId: input.known.externalActionId,
952
- sourceKind: input.known.sourceKind,
953
975
  input: input.fireInput,
954
976
  event: input.fireEvent,
955
- mergeKey,
956
977
  queuedCount: 1,
957
- createdAt: now(),
958
- updatedAt: now(),
959
978
  },
960
979
  ]);
961
980
  queuedCount = merged.queuedCount;
@@ -1064,23 +1083,7 @@ export function createExternalSourceService(
1064
1083
  fireEvent: input.fireEvent,
1065
1084
  mergeKey: input.mergeKey ?? null,
1066
1085
  });
1067
- if (!result.ok) {
1068
- if (result.stage === "post_commit" && result.process) {
1069
- return {
1070
- ok: false,
1071
- stage: "post_commit",
1072
- process: result.process,
1073
- code: result.code,
1074
- error: result.message,
1075
- };
1076
- }
1077
- return {
1078
- ok: false,
1079
- stage: "pre_commit",
1080
- code: result.code,
1081
- error: result.message,
1082
- };
1083
- }
1086
+ if (!result.ok) return externalSourceFailure(result);
1084
1087
  return {
1085
1088
  ok: true,
1086
1089
  process: result.process,
@@ -1088,31 +1091,10 @@ export function createExternalSourceService(
1088
1091
  };
1089
1092
  }
1090
1093
 
1091
- async function dropPendingFire(input: {
1092
- instanceId: string;
1093
- armingId: string;
1094
- known: KnownExternalArming;
1095
- fireInput?: Record<string, unknown>;
1096
- fireEvent?: Record<string, unknown>;
1097
- code: string;
1098
- message: string;
1099
- pendingFireId?: string;
1100
- }): Promise<void> {
1101
- await deps.commands.run(DropExternalSourceFire, {
1102
- instanceId: input.instanceId,
1103
- armingId: input.armingId,
1104
- known: input.known,
1105
- fireInput: input.fireInput,
1106
- fireEvent: input.fireEvent,
1107
- code: input.code,
1108
- message: input.message,
1109
- pendingFireId: input.pendingFireId,
1110
- });
1111
- }
1112
-
1113
1094
  async function fireImmediate(input: {
1114
1095
  instanceId: string;
1115
1096
  armingId: string;
1097
+ generation?: string;
1116
1098
  fireInput: Record<string, unknown>;
1117
1099
  fireEvent: Record<string, unknown>;
1118
1100
  queuedCount?: number;
@@ -1121,28 +1103,13 @@ export function createExternalSourceService(
1121
1103
  const result = await deps.commands.run(FireExternalSource, {
1122
1104
  instanceId: input.instanceId,
1123
1105
  armingId: input.armingId,
1106
+ generation: input.generation,
1124
1107
  input: input.fireInput,
1125
1108
  event: input.fireEvent,
1126
1109
  queuedCount: input.queuedCount,
1127
1110
  pendingFireIds: input.pendingFireIds,
1128
1111
  });
1129
- if (!result.ok) {
1130
- if (result.stage === "post_commit" && result.process) {
1131
- return {
1132
- ok: false,
1133
- stage: "post_commit",
1134
- process: result.process,
1135
- code: result.code,
1136
- error: result.message,
1137
- };
1138
- }
1139
- return {
1140
- ok: false,
1141
- stage: "pre_commit",
1142
- code: result.code,
1143
- error: result.message,
1144
- };
1145
- }
1112
+ if (!result.ok) return externalSourceFailure(result);
1146
1113
  if ((result.data as { ok?: unknown }).ok === false) {
1147
1114
  return {
1148
1115
  ok: false,
@@ -1160,8 +1127,6 @@ export function createExternalSourceService(
1160
1127
  fireInput: Record<string, unknown>;
1161
1128
  fireEvent: Record<string, unknown>;
1162
1129
  mergeKey?: string | null;
1163
- code?: string;
1164
- message?: string;
1165
1130
  }): Promise<ActionExecutionResultLike> {
1166
1131
  const process = deps.processes.getById(input.instanceId);
1167
1132
  if (!process) {
@@ -1182,7 +1147,7 @@ export function createExternalSourceService(
1182
1147
  };
1183
1148
  }
1184
1149
  if (terminal(process)) {
1185
- await dropPendingFire({
1150
+ await deps.commands.run(DropExternalSourceFire, {
1186
1151
  instanceId: input.instanceId,
1187
1152
  armingId: input.armingId,
1188
1153
  known,
@@ -1208,6 +1173,26 @@ export function createExternalSourceService(
1208
1173
  });
1209
1174
  }
1210
1175
 
1176
+ async function dropQueuedFires(
1177
+ instanceId: string,
1178
+ fires: readonly PendingExternalSourceFire[],
1179
+ code: string,
1180
+ message: string,
1181
+ ): Promise<void> {
1182
+ for (const fire of fires) {
1183
+ await deps.commands.run(DropExternalSourceFire, {
1184
+ instanceId,
1185
+ armingId: fire.armingId,
1186
+ known: fire,
1187
+ fireInput: fire.input,
1188
+ fireEvent: fire.event,
1189
+ code,
1190
+ message,
1191
+ pendingFireId: fire.id,
1192
+ });
1193
+ }
1194
+ }
1195
+
1211
1196
  async function drainQueued(instanceId: string): Promise<void> {
1212
1197
  if (drainingInstances.has(instanceId)) {
1213
1198
  drainAgain.add(instanceId);
@@ -1228,39 +1213,26 @@ export function createExternalSourceService(
1228
1213
  continue;
1229
1214
  }
1230
1215
  if (terminal(process)) {
1231
- for (const pendingFire of pending) {
1232
- await dropPendingFire({
1233
- instanceId,
1234
- armingId: pendingFire.armingId,
1235
- known: pendingFire,
1236
- fireInput: pendingFire.input,
1237
- fireEvent: pendingFire.event,
1238
- code: "external_source_terminal",
1239
- message: "Queued external source was dropped because the process is terminal",
1240
- pendingFireId: pendingFire.id,
1241
- });
1242
- }
1216
+ await dropQueuedFires(
1217
+ instanceId,
1218
+ pending,
1219
+ "external_source_terminal",
1220
+ "Queued external source was dropped because the process is terminal",
1221
+ );
1243
1222
  continue;
1244
1223
  }
1245
1224
  await reconcileArmings(instanceId);
1246
- const active = process ? listArmingsForProcess(process) : [];
1225
+ const active = listArmingsForProcess(process);
1247
1226
  const activeIds = new Set(active.map((entry) => entry.id));
1248
1227
  const drainable = pending.find((entry) => activeIds.has(entry.armingId));
1249
1228
  if (!drainable) {
1250
1229
  if (process.lifecycleStatus === "waiting") {
1251
- for (const pendingFire of pending) {
1252
- await dropPendingFire({
1253
- instanceId,
1254
- armingId: pendingFire.armingId,
1255
- known: pendingFire,
1256
- fireInput: pendingFire.input,
1257
- fireEvent: pendingFire.event,
1258
- code: "external_source_no_longer_exposed",
1259
- message:
1260
- "Queued external source was dropped because the selected turn no longer exposes that external action",
1261
- pendingFireId: pendingFire.id,
1262
- });
1263
- }
1230
+ await dropQueuedFires(
1231
+ instanceId,
1232
+ pending,
1233
+ "external_source_no_longer_exposed",
1234
+ "Queued external source was dropped because the selected turn no longer exposes that external action",
1235
+ );
1264
1236
  }
1265
1237
  continue;
1266
1238
  }
@@ -1277,18 +1249,12 @@ export function createExternalSourceService(
1277
1249
  pendingFireIds: group.map((pendingFire) => pendingFire.id),
1278
1250
  });
1279
1251
  if (!result.ok) {
1280
- for (const pendingFire of group) {
1281
- await dropPendingFire({
1282
- instanceId,
1283
- armingId: pendingFire.armingId,
1284
- known: pendingFire,
1285
- fireInput: pendingFire.input,
1286
- fireEvent: pendingFire.event,
1287
- code: result.code ?? "external_source_failed",
1288
- message: result.error,
1289
- pendingFireId: pendingFire.id,
1290
- });
1291
- }
1252
+ await dropQueuedFires(
1253
+ instanceId,
1254
+ group,
1255
+ result.code ?? "external_source_failed",
1256
+ result.error,
1257
+ );
1292
1258
  }
1293
1259
  } while (drainAgain.has(instanceId));
1294
1260
  } finally {
@@ -1298,6 +1264,13 @@ export function createExternalSourceService(
1298
1264
  }
1299
1265
 
1300
1266
  return {
1267
+ currentGenerations(instanceId) {
1268
+ const process = deps.processes.getById(instanceId);
1269
+ return (process ? listArmingsForProcess(process) : []).map((arming) => ({
1270
+ id: arming.id,
1271
+ generation: generationFor(arming),
1272
+ }));
1273
+ },
1301
1274
  listArmed(kind: string) {
1302
1275
  const armed = listAllArmed();
1303
1276
  return armed
@@ -1305,7 +1278,6 @@ export function createExternalSourceService(
1305
1278
  .map(
1306
1279
  ({
1307
1280
  transition: _transition,
1308
- transitionIndex: _transitionIndex,
1309
1281
  transitionTrigger: _transitionTrigger,
1310
1282
  label: _label,
1311
1283
  description: _description,
@@ -1314,41 +1286,37 @@ export function createExternalSourceService(
1314
1286
  params: _params,
1315
1287
  state: _state,
1316
1288
  ...entry
1317
- }) => entry,
1289
+ }) => ({
1290
+ ...entry,
1291
+ generation: generationFor({
1292
+ ...entry,
1293
+ process: _process,
1294
+ } as ResolvedExternalSourceArming),
1295
+ }),
1318
1296
  );
1319
1297
  },
1298
+ async observe(input: ExternalObservationInput): Promise<ActionExecutionResultLike> {
1299
+ const result = await deps.commands.run(ObserveExternalSource, input);
1300
+ if (!result.ok) return externalSourceFailure(result);
1301
+ return { ok: true, process: result.process };
1302
+ },
1320
1303
  async fire(input: ExternalSourceFireInput): Promise<ActionExecutionResultLike> {
1321
- const fireInput = normalizeRecord(input.input);
1322
- const fireEvent = normalizeRecord(input.event);
1323
- const active = resolveArming(input.instanceId, input.armingId);
1324
- if (!active) {
1325
- return queueOrDrop({
1326
- instanceId: input.instanceId,
1327
- armingId: input.armingId,
1328
- fireInput,
1329
- fireEvent,
1330
- mergeKey: input.mergeKey,
1331
- });
1332
- }
1333
- const result = await fireImmediate({
1304
+ const fire = {
1334
1305
  instanceId: input.instanceId,
1335
1306
  armingId: input.armingId,
1336
- fireInput,
1337
- fireEvent,
1338
- });
1307
+ generation: input.generation,
1308
+ fireInput: normalizeRecord(input.input),
1309
+ fireEvent: normalizeRecord(input.event),
1310
+ };
1311
+ if (input.generation) return fireImmediate(fire);
1312
+ const active = resolveArming(input.instanceId, input.armingId);
1313
+ const result = active ? await fireImmediate(fire) : null;
1339
1314
  if (
1340
- !result.ok &&
1341
- (result.code === "external_source_stale" || result.code === "external_source_not_armed")
1315
+ !result ||
1316
+ (!result.ok &&
1317
+ (result.code === "external_source_stale" || result.code === "external_source_not_armed"))
1342
1318
  ) {
1343
- return queueOrDrop({
1344
- instanceId: input.instanceId,
1345
- armingId: input.armingId,
1346
- fireInput,
1347
- fireEvent,
1348
- mergeKey: input.mergeKey,
1349
- code: result.code,
1350
- message: result.error,
1351
- });
1319
+ return queueOrDrop({ ...fire, mergeKey: input.mergeKey });
1352
1320
  }
1353
1321
  if (result.ok) {
1354
1322
  await drainQueued(input.instanceId);
@@ -1363,5 +1331,3 @@ export function createExternalSourceService(
1363
1331
  reconcileAllArmings,
1364
1332
  };
1365
1333
  }
1366
-
1367
- void parseNewExternalActionArmingId;