@leitwerk-dev/server 0.3.1 → 0.4.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 (309) hide show
  1. package/dist/{app-BuJCdkvy.d.ts → app-CsuxFZT5.d.ts} +262 -121
  2. package/dist/app-JM4CBTND.js +8 -0
  3. package/dist/app.d.ts +9 -0
  4. package/dist/app.d.ts.map +1 -1
  5. package/dist/auth/fastify-auth.d.ts +9 -0
  6. package/dist/auth/fastify-auth.d.ts.map +1 -1
  7. package/dist/{chunk-QCHS3X33.js → chunk-FPMDWQF7.js} +2617 -562
  8. package/dist/chunk-FPMDWQF7.js.map +1 -0
  9. package/dist/{chunk-HK6BLLHA.js → chunk-MBHRCQFE.js} +2303 -1576
  10. package/dist/chunk-MBHRCQFE.js.map +1 -0
  11. package/dist/config/config-loader.d.ts +1 -1
  12. package/dist/config/config-loader.d.ts.map +1 -1
  13. package/dist/config/config-types.d.ts +14 -1
  14. package/dist/config/config-types.d.ts.map +1 -1
  15. package/dist/config/kubernetes-docker-isolation.d.ts +7 -0
  16. package/dist/config/kubernetes-docker-isolation.d.ts.map +1 -0
  17. package/dist/db/database.d.ts.map +1 -1
  18. package/dist/db/execution-inspection-repo.d.ts +15 -0
  19. package/dist/db/execution-inspection-repo.d.ts.map +1 -0
  20. package/dist/db/history-window.d.ts +11 -0
  21. package/dist/db/history-window.d.ts.map +1 -0
  22. package/dist/db/process-event-repo.d.ts +2 -0
  23. package/dist/db/process-event-repo.d.ts.map +1 -1
  24. package/dist/db/process-instance-repo.d.ts +4 -1
  25. package/dist/db/process-instance-repo.d.ts.map +1 -1
  26. package/dist/db/process-leaf-outcome-snapshot-repo.d.ts +2 -1
  27. package/dist/db/process-leaf-outcome-snapshot-repo.d.ts.map +1 -1
  28. package/dist/db/process-project-repo.d.ts +2 -0
  29. package/dist/db/process-project-repo.d.ts.map +1 -1
  30. package/dist/db/process-skill-repo.d.ts.map +1 -1
  31. package/dist/db/process-turn-annotation-repo.d.ts +4 -1
  32. package/dist/db/process-turn-annotation-repo.d.ts.map +1 -1
  33. package/dist/db/process-turn-record-repo.d.ts +4 -0
  34. package/dist/db/process-turn-record-repo.d.ts.map +1 -1
  35. package/dist/db/publication-repo.d.ts +5 -0
  36. package/dist/db/publication-repo.d.ts.map +1 -0
  37. package/dist/db/repositories.d.ts +12 -0
  38. package/dist/db/repositories.d.ts.map +1 -1
  39. package/dist/db/schema.d.ts +693 -2
  40. package/dist/db/schema.d.ts.map +1 -1
  41. package/dist/db/scoped-settings-repo.d.ts +37 -0
  42. package/dist/db/scoped-settings-repo.d.ts.map +1 -0
  43. package/dist/db/skill-repo.d.ts +3 -0
  44. package/dist/db/skill-repo.d.ts.map +1 -1
  45. package/dist/db/turn-start-record-repo.d.ts +2 -1
  46. package/dist/db/turn-start-record-repo.d.ts.map +1 -1
  47. package/dist/db/turn-summary-repo.d.ts +1 -1
  48. package/dist/db/turn-summary-repo.d.ts.map +1 -1
  49. package/dist/db/worker-lease-repo.d.ts +2 -1
  50. package/dist/db/worker-lease-repo.d.ts.map +1 -1
  51. package/dist/domain-logic/outcome-tools.d.ts.map +1 -1
  52. package/dist/external-source-service.d.ts.map +1 -1
  53. package/dist/future-execution/execution.d.ts +4 -1
  54. package/dist/future-execution/execution.d.ts.map +1 -1
  55. package/dist/future-execution/launch-lifecycle.d.ts +9 -25
  56. package/dist/future-execution/launch-lifecycle.d.ts.map +1 -1
  57. package/dist/future-execution/lifecycle.d.ts +3 -28
  58. package/dist/future-execution/lifecycle.d.ts.map +1 -1
  59. package/dist/future-execution/model-projection.d.ts.map +1 -1
  60. package/dist/future-execution/reconciliation.d.ts +1 -0
  61. package/dist/future-execution/reconciliation.d.ts.map +1 -1
  62. package/dist/future-execution-presenter.d.ts.map +1 -1
  63. package/dist/index.js +2 -2
  64. package/dist/integration-tool-registry.d.ts +11 -2
  65. package/dist/integration-tool-registry.d.ts.map +1 -1
  66. package/dist/launch-coordinator.d.ts.map +1 -1
  67. package/dist/launcher-model-config-service.d.ts +7 -1
  68. package/dist/launcher-model-config-service.d.ts.map +1 -1
  69. package/dist/leaf-outcome-snapshot-capture.d.ts +1 -0
  70. package/dist/leaf-outcome-snapshot-capture.d.ts.map +1 -1
  71. package/dist/main.js +3 -3
  72. package/dist/primary-path-snapshot.d.ts.map +1 -1
  73. package/dist/process-action-presenter.d.ts +1 -6
  74. package/dist/process-action-presenter.d.ts.map +1 -1
  75. package/dist/process-action-registry.d.ts.map +1 -1
  76. package/dist/process-engine/decision.d.ts +2 -0
  77. package/dist/process-engine/decision.d.ts.map +1 -1
  78. package/dist/process-engine/engine.d.ts.map +1 -1
  79. package/dist/process-engine/mapped-turns.d.ts.map +1 -1
  80. package/dist/process-engine/ops/continue-failed-turn.d.ts.map +1 -1
  81. package/dist/process-engine/ops/process-observation.d.ts +6 -0
  82. package/dist/process-engine/ops/process-observation.d.ts.map +1 -0
  83. package/dist/process-engine/ops/retry-failed-turn.d.ts.map +1 -1
  84. package/dist/process-engine/ops/retry-startup.d.ts.map +1 -1
  85. package/dist/process-engine/ops/start-process.d.ts +2 -0
  86. package/dist/process-engine/ops/start-process.d.ts.map +1 -1
  87. package/dist/process-engine/ops/turn-outcome.d.ts.map +1 -1
  88. package/dist/process-engine/ops/turn-wait.d.ts +30 -0
  89. package/dist/process-engine/ops/turn-wait.d.ts.map +1 -0
  90. package/dist/process-engine/ops/update-model-config.d.ts +9 -0
  91. package/dist/process-engine/ops/update-model-config.d.ts.map +1 -0
  92. package/dist/process-engine/recorder.d.ts.map +1 -1
  93. package/dist/process-engine/turn-start-preflight.d.ts +6 -0
  94. package/dist/process-engine/turn-start-preflight.d.ts.map +1 -1
  95. package/dist/process-engine/turn-wait-state.d.ts +24 -0
  96. package/dist/process-engine/turn-wait-state.d.ts.map +1 -0
  97. package/dist/process-engine/turn-worker-requirement.d.ts +2 -0
  98. package/dist/process-engine/turn-worker-requirement.d.ts.map +1 -1
  99. package/dist/process-engine/types.d.ts +5 -1
  100. package/dist/process-engine/types.d.ts.map +1 -1
  101. package/dist/process-engine/writes/build-process-abort-writes.d.ts +3 -1
  102. package/dist/process-engine/writes/build-process-abort-writes.d.ts.map +1 -1
  103. package/dist/process-engine/writes/build-turn-outcome-writes.d.ts +2 -0
  104. package/dist/process-engine/writes/build-turn-outcome-writes.d.ts.map +1 -1
  105. package/dist/process-engine/writes/commit-writes.d.ts +2 -0
  106. package/dist/process-engine/writes/commit-writes.d.ts.map +1 -1
  107. package/dist/process-engine/writes/writes.d.ts +28 -60
  108. package/dist/process-engine/writes/writes.d.ts.map +1 -1
  109. package/dist/process-graph.d.ts +1 -1
  110. package/dist/process-graph.d.ts.map +1 -1
  111. package/dist/process-inspection-reader.d.ts +21 -0
  112. package/dist/process-inspection-reader.d.ts.map +1 -0
  113. package/dist/process-inspection-trace.d.ts +13 -0
  114. package/dist/process-inspection-trace.d.ts.map +1 -0
  115. package/dist/process-inspection.d.ts +22 -0
  116. package/dist/process-inspection.d.ts.map +1 -0
  117. package/dist/process-instance-tree-presenter.d.ts +4 -3
  118. package/dist/process-instance-tree-presenter.d.ts.map +1 -1
  119. package/dist/process-launch-executor.d.ts +2 -0
  120. package/dist/process-launch-executor.d.ts.map +1 -1
  121. package/dist/process-launch-plan.d.ts +1 -0
  122. package/dist/process-launch-plan.d.ts.map +1 -1
  123. package/dist/process-launcher-registry.d.ts.map +1 -1
  124. package/dist/process-model-config.d.ts +19 -0
  125. package/dist/process-model-config.d.ts.map +1 -0
  126. package/dist/process-model-policy/construct.d.ts.map +1 -1
  127. package/dist/process-model-policy/evaluate.d.ts.map +1 -1
  128. package/dist/process-model-policy/index.d.ts +4 -1
  129. package/dist/process-model-policy/index.d.ts.map +1 -1
  130. package/dist/process-model-policy/project.d.ts.map +1 -1
  131. package/dist/process-model-policy/types.d.ts +18 -0
  132. package/dist/process-model-policy/types.d.ts.map +1 -1
  133. package/dist/process-model-policy-presenter.d.ts.map +1 -1
  134. package/dist/process-runtime-availability.d.ts +2 -1
  135. package/dist/process-runtime-availability.d.ts.map +1 -1
  136. package/dist/process-turn-trace.d.ts.map +1 -1
  137. package/dist/process-ui-snapshot-presenter.d.ts +14 -3
  138. package/dist/process-ui-snapshot-presenter.d.ts.map +1 -1
  139. package/dist/routes/future-executions.d.ts.map +1 -1
  140. package/dist/routes/launchers.d.ts.map +1 -1
  141. package/dist/routes/process-actions.d.ts.map +1 -1
  142. package/dist/routes/process-detail.d.ts.map +1 -1
  143. package/dist/routes/process-model-config.d.ts +4 -0
  144. package/dist/routes/process-model-config.d.ts.map +1 -0
  145. package/dist/routes/process-route-helpers.d.ts +8 -9
  146. package/dist/routes/process-route-helpers.d.ts.map +1 -1
  147. package/dist/routes/processes.d.ts.map +1 -1
  148. package/dist/routes/settings.d.ts +11 -0
  149. package/dist/routes/settings.d.ts.map +1 -0
  150. package/dist/routes/ticket-creation.d.ts.map +1 -1
  151. package/dist/scoped-settings-service.d.ts +83 -0
  152. package/dist/scoped-settings-service.d.ts.map +1 -0
  153. package/dist/server-bootstrap/build-host-capabilities.d.ts +2 -0
  154. package/dist/server-bootstrap/build-host-capabilities.d.ts.map +1 -1
  155. package/dist/server-bootstrap/register-http.d.ts.map +1 -1
  156. package/dist/session-summary-projection.d.ts.map +1 -1
  157. package/dist/skills/bundled-skills.d.ts +5 -0
  158. package/dist/skills/bundled-skills.d.ts.map +1 -0
  159. package/dist/skills/catalog-service.d.ts +1 -0
  160. package/dist/skills/catalog-service.d.ts.map +1 -1
  161. package/dist/skills/extension-importer.d.ts +11 -0
  162. package/dist/skills/extension-importer.d.ts.map +1 -0
  163. package/dist/skills/launch-skills.d.ts +11 -0
  164. package/dist/skills/launch-skills.d.ts.map +1 -0
  165. package/dist/skills/skill-frontmatter.d.ts +5 -0
  166. package/dist/skills/skill-frontmatter.d.ts.map +1 -1
  167. package/dist/skills/source-importer.d.ts +3 -0
  168. package/dist/skills/source-importer.d.ts.map +1 -1
  169. package/dist/startup-evidence.d.ts +3 -0
  170. package/dist/startup-evidence.d.ts.map +1 -1
  171. package/dist/supervisor/execution-inspection-ingestor.d.ts +9 -0
  172. package/dist/supervisor/execution-inspection-ingestor.d.ts.map +1 -0
  173. package/dist/supervisor/ipc-handler.d.ts +2 -0
  174. package/dist/supervisor/ipc-handler.d.ts.map +1 -1
  175. package/dist/supervisor/worker-event-ingestor.d.ts +1 -0
  176. package/dist/supervisor/worker-event-ingestor.d.ts.map +1 -1
  177. package/dist/supervisor/worker-start-payload-builder.d.ts.map +1 -1
  178. package/dist/supervisor/worker-supervisor.d.ts +2 -0
  179. package/dist/supervisor/worker-supervisor.d.ts.map +1 -1
  180. package/dist/test-helpers/prepared-fixture-start.d.ts.map +1 -1
  181. package/dist/test-helpers/process-model-fixtures.d.ts +1 -0
  182. package/dist/test-helpers/process-model-fixtures.d.ts.map +1 -1
  183. package/dist/test-helpers/scoped-settings-fixtures.d.ts +16 -0
  184. package/dist/test-helpers/scoped-settings-fixtures.d.ts.map +1 -0
  185. package/dist/test-helpers/skill-fixtures.d.ts +4 -0
  186. package/dist/test-helpers/skill-fixtures.d.ts.map +1 -0
  187. package/dist/testing.js +2 -1
  188. package/dist/testing.js.map +1 -1
  189. package/dist/tool-approval-gate.d.ts +3 -0
  190. package/dist/tool-approval-gate.d.ts.map +1 -1
  191. package/dist/turn-progress.d.ts.map +1 -1
  192. package/dist/turn-wait-service.d.ts +28 -0
  193. package/dist/turn-wait-service.d.ts.map +1 -0
  194. package/dist/worker-runtime-profile-selection.d.ts +2 -0
  195. package/dist/worker-runtime-profile-selection.d.ts.map +1 -1
  196. package/package.json +20 -19
  197. package/src/app.ts +115 -5
  198. package/src/auth/fastify-auth.ts +13 -0
  199. package/src/config/config-loader.ts +40 -2
  200. package/src/config/config-types.ts +14 -1
  201. package/src/config/kubernetes-docker-isolation.ts +21 -0
  202. package/src/db/database.ts +131 -40
  203. package/src/db/execution-inspection-repo.ts +163 -0
  204. package/src/db/history-window.ts +18 -0
  205. package/src/db/process-event-repo.ts +88 -10
  206. package/src/db/process-instance-repo.ts +9 -2
  207. package/src/db/process-leaf-outcome-snapshot-repo.ts +8 -2
  208. package/src/db/process-project-repo.ts +4 -0
  209. package/src/db/process-skill-repo.ts +9 -2
  210. package/src/db/process-turn-annotation-repo.ts +27 -9
  211. package/src/db/process-turn-record-repo.ts +45 -12
  212. package/src/db/publication-repo.ts +63 -0
  213. package/src/db/repositories.ts +17 -0
  214. package/src/db/schema.ts +103 -1
  215. package/src/db/scoped-settings-repo.ts +234 -0
  216. package/src/db/skill-repo.ts +89 -27
  217. package/src/db/turn-start-record-repo.ts +8 -2
  218. package/src/db/turn-summary-repo.ts +12 -3
  219. package/src/db/worker-lease-repo.ts +8 -2
  220. package/src/domain-logic/outcome-tools.ts +4 -193
  221. package/src/external-source-service.ts +33 -7
  222. package/src/future-execution/execution.ts +9 -2
  223. package/src/future-execution/launch-lifecycle.ts +87 -78
  224. package/src/future-execution/lifecycle.ts +5 -34
  225. package/src/future-execution/model-projection.ts +2 -0
  226. package/src/future-execution/reconciliation.ts +7 -0
  227. package/src/future-execution-presenter.ts +7 -8
  228. package/src/integration-tool-registry.ts +59 -26
  229. package/src/launch-coordinator.ts +10 -1
  230. package/src/launcher-model-config-service.ts +24 -3
  231. package/src/leaf-outcome-snapshot-capture.ts +2 -0
  232. package/src/primary-path-snapshot.ts +3 -4
  233. package/src/process-action-presenter.ts +22 -57
  234. package/src/process-action-registry.ts +31 -39
  235. package/src/process-engine/decision.ts +10 -0
  236. package/src/process-engine/engine.ts +11 -2
  237. package/src/process-engine/mapped-turns.ts +5 -7
  238. package/src/process-engine/ops/continue-failed-turn.ts +2 -13
  239. package/src/process-engine/ops/process-observation.ts +119 -0
  240. package/src/process-engine/ops/retry-failed-turn.ts +2 -12
  241. package/src/process-engine/ops/retry-startup.ts +9 -13
  242. package/src/process-engine/ops/start-process.ts +34 -2
  243. package/src/process-engine/ops/turn-outcome.ts +61 -60
  244. package/src/process-engine/ops/turn-wait.ts +225 -0
  245. package/src/process-engine/ops/update-model-config.ts +66 -0
  246. package/src/process-engine/recorder.ts +21 -5
  247. package/src/process-engine/turn-start-preflight.ts +168 -105
  248. package/src/process-engine/turn-wait-state.ts +126 -0
  249. package/src/process-engine/turn-worker-requirement.ts +4 -0
  250. package/src/process-engine/types.ts +9 -0
  251. package/src/process-engine/writes/build-process-abort-writes.ts +30 -20
  252. package/src/process-engine/writes/build-turn-outcome-writes.ts +39 -2
  253. package/src/process-engine/writes/commit-writes.ts +15 -2
  254. package/src/process-engine/writes/writes.ts +59 -74
  255. package/src/process-graph.ts +0 -1
  256. package/src/process-inspection-reader.ts +305 -0
  257. package/src/process-inspection-trace.ts +176 -0
  258. package/src/process-inspection.ts +169 -0
  259. package/src/process-instance-tree-presenter.ts +56 -216
  260. package/src/process-launch-executor.ts +5 -2
  261. package/src/process-launch-plan.ts +17 -2
  262. package/src/process-launcher-registry.ts +28 -16
  263. package/src/process-model-config.ts +100 -0
  264. package/src/process-model-policy/construct.ts +1 -0
  265. package/src/process-model-policy/evaluate.ts +34 -32
  266. package/src/process-model-policy/index.ts +45 -3
  267. package/src/process-model-policy/project.ts +62 -76
  268. package/src/process-model-policy/types.ts +26 -0
  269. package/src/process-model-policy-presenter.ts +7 -3
  270. package/src/process-runtime-availability.ts +9 -4
  271. package/src/process-turn-trace.ts +12 -24
  272. package/src/process-ui-snapshot-presenter.ts +210 -295
  273. package/src/routes/future-executions.ts +5 -5
  274. package/src/routes/launchers.ts +51 -1
  275. package/src/routes/process-actions.ts +9 -9
  276. package/src/routes/process-detail.ts +25 -2
  277. package/src/routes/process-model-config.ts +70 -0
  278. package/src/routes/process-route-helpers.ts +153 -162
  279. package/src/routes/processes.ts +2 -0
  280. package/src/routes/settings.ts +173 -0
  281. package/src/routes/ticket-creation.ts +28 -5
  282. package/src/scoped-settings-service.ts +736 -0
  283. package/src/server-bootstrap/build-host-capabilities.ts +42 -0
  284. package/src/server-bootstrap/register-http.ts +7 -1
  285. package/src/session-summary-projection.ts +1 -2
  286. package/src/skills/bundled-skills.ts +64 -0
  287. package/src/skills/catalog-service.ts +35 -6
  288. package/src/skills/extension-importer.ts +97 -0
  289. package/src/skills/launch-skills.ts +19 -0
  290. package/src/skills/skill-frontmatter.ts +13 -0
  291. package/src/skills/source-importer.ts +3 -0
  292. package/src/startup-evidence.ts +20 -0
  293. package/src/supervisor/execution-inspection-ingestor.ts +55 -0
  294. package/src/supervisor/ipc-handler.ts +2 -0
  295. package/src/supervisor/worker-event-ingestor.ts +30 -14
  296. package/src/supervisor/worker-start-payload-builder.ts +17 -0
  297. package/src/supervisor/worker-supervisor.ts +3 -0
  298. package/src/test-helpers/prepared-fixture-start.ts +1 -0
  299. package/src/test-helpers/process-model-fixtures.ts +2 -0
  300. package/src/test-helpers/scoped-settings-fixtures.ts +126 -0
  301. package/src/test-helpers/skill-fixtures.ts +28 -0
  302. package/src/tool-approval-gate.ts +16 -0
  303. package/src/turn-progress.ts +3 -2
  304. package/src/turn-wait-service.ts +228 -0
  305. package/src/worker-runtime-profile-selection.ts +8 -1
  306. package/dist/app-MSJXFK33.js +0 -8
  307. package/dist/chunk-HK6BLLHA.js.map +0 -1
  308. package/dist/chunk-QCHS3X33.js.map +0 -1
  309. /package/dist/{app-MSJXFK33.js.map → app-JM4CBTND.js.map} +0 -0
@@ -57,6 +57,8 @@ export interface RecordCommit {
57
57
  /** @internal */
58
58
  committedProject: ProcessProject | null;
59
59
  /** @internal */
60
+ initialProjects?: ProcessProject[];
61
+ /** @internal */
60
62
  committedTurnRecords: ProcessTurnRecord[];
61
63
  /** @internal */
62
64
  committedLeafOutcomeSnapshots: ProcessLeafOutcomeSnapshot[];
@@ -250,7 +252,9 @@ export function commitWrites(
250
252
 
251
253
  const processAfter =
252
254
  writes.changedFields.length > 0
253
- ? repos.processes.update(instanceId, writes.processPatch)
255
+ ? repos.processes.update(instanceId, writes.processPatch, {
256
+ preserveUpdatedAt: writes.preserveUpdatedAt,
257
+ })
254
258
  : repos.processes.getById(instanceId);
255
259
  const committedProject = writes.projectWrite
256
260
  ? repos.projects.update(writes.projectWrite.id, writes.projectWrite.input)
@@ -263,6 +267,11 @@ export function commitWrites(
263
267
  `Process project '${committedProject.id}' does not belong to '${instanceId}'`,
264
268
  );
265
269
  }
270
+ const initialProjects = (writes.initialProjects ?? []).map((project) => {
271
+ if (project.instanceId !== instanceId)
272
+ throw new Error("Initial repository belongs to another process");
273
+ return repos.projects.create(project);
274
+ });
266
275
 
267
276
  for (const write of writes.pendingExternalSourceFireWrites) {
268
277
  if (write.kind === "create") {
@@ -303,6 +312,7 @@ export function commitWrites(
303
312
  processBefore,
304
313
  processAfter,
305
314
  committedProject,
315
+ initialProjects,
306
316
  committedTurnRecords,
307
317
  turnEventSequences,
308
318
  committedLeafOutcomeSnapshots,
@@ -325,6 +335,8 @@ export function deriveReactions(
325
335
  effects.push({ kind: "broadcast", frame });
326
336
  }
327
337
  if (commit.committedProject) effects.push(buildProjectUpdatedEffect(commit.committedProject));
338
+ for (const project of commit.initialProjects ?? [])
339
+ effects.push(buildProjectUpdatedEffect(project));
328
340
  if (writes.changedFields.length > 0) {
329
341
  const includeClosedAt =
330
342
  commit.processAfter !== null &&
@@ -335,7 +347,8 @@ export function deriveReactions(
335
347
  ...(includeClosedAt ? { closedAt: commit.processAfter?.closedAt ?? null } : {}),
336
348
  };
337
349
  let changedFields =
338
- commit.processAfter?.updatedAt && !writes.changedFields.includes("updatedAt")
350
+ commit.processAfter?.updatedAt !== commit.processBefore?.updatedAt &&
351
+ !writes.changedFields.includes("updatedAt")
339
352
  ? [...writes.changedFields, "updatedAt"]
340
353
  : writes.changedFields;
341
354
  if (includeClosedAt && !changedFields.includes("closedAt")) {
@@ -18,7 +18,10 @@ import type {
18
18
  import type { CreateProcessEventInput } from "../../db/process-event-repo.js";
19
19
  import type { UpdateProcessInstanceInput } from "../../db/process-instance-repo.js";
20
20
  import type { CreateProcessLeafOutcomeSnapshotInput } from "../../db/process-leaf-outcome-snapshot-repo.js";
21
- import type { UpdateProcessProjectInput } from "../../db/process-project-repo.js";
21
+ import type {
22
+ CreateProcessProjectInput,
23
+ UpdateProcessProjectInput,
24
+ } from "../../db/process-project-repo.js";
22
25
  import type {
23
26
  CreateProcessTurnAnnotationInput,
24
27
  UpdateProcessTurnAnnotationInput,
@@ -34,34 +37,45 @@ import type { DeferredProcessExtensionEvent } from "./deferred-extension-events.
34
37
  /** @internal */
35
38
  export type DurableBroadcast = DurableWsFrameInput;
36
39
 
40
+ /** @internal */
41
+ type CreateWrite<T> = {
42
+ /** @internal */
43
+ kind: "create";
44
+ /** @internal */
45
+ input: T;
46
+ };
47
+
48
+ /** @internal */
49
+ type UpdateWrite<T> = {
50
+ /** @internal */
51
+ kind: "update";
52
+ /** @internal */
53
+ id: string;
54
+ /** @internal */
55
+ input: T;
56
+ };
57
+
58
+ /** @internal */
59
+ type DeleteWrite = {
60
+ /** @internal */
61
+ kind: "delete";
62
+ /** @internal */
63
+ id: string;
64
+ };
65
+
37
66
  /** @internal */
38
67
  export type TurnRecordWrite =
39
- | {
40
- /** @internal */
41
- kind: "create";
42
- /** @internal */
43
- input: CreateProcessTurnRecordInput;
44
- }
45
- | {
46
- /** @internal */
47
- kind: "update";
48
- /** @internal */
49
- id: string;
50
- /** @internal */
51
- input: UpdateProcessTurnRecordInput;
52
- };
68
+ | CreateWrite<CreateProcessTurnRecordInput>
69
+ | UpdateWrite<UpdateProcessTurnRecordInput>;
53
70
 
54
71
  /** @internal */
55
72
  export type TurnStartWrite =
56
- | {
57
- /** @internal */
58
- kind: "create";
59
- /** @internal */
60
- input: Omit<TurnStartRecord, "id" | "createdAt" | "updatedAt"> & {
73
+ | CreateWrite<
74
+ Omit<TurnStartRecord, "id" | "createdAt" | "updatedAt"> & {
61
75
  /** @internal */
62
76
  id?: string;
63
- };
64
- }
77
+ }
78
+ >
65
79
  | {
66
80
  /** @internal */
67
81
  kind: "cas_state";
@@ -75,35 +89,13 @@ export type TurnStartWrite =
75
89
 
76
90
  /** @internal */
77
91
  export type TurnAnnotationWrite =
78
- | {
79
- /** @internal */
80
- kind: "create";
81
- /** @internal */
82
- input: CreateProcessTurnAnnotationInput;
83
- }
84
- | {
85
- /** @internal */
86
- kind: "update";
87
- /** @internal */
88
- id: string;
89
- /** @internal */
90
- input: UpdateProcessTurnAnnotationInput;
91
- }
92
- | {
93
- /** @internal */
94
- kind: "delete";
95
- /** @internal */
96
- id: string;
97
- };
92
+ | CreateWrite<CreateProcessTurnAnnotationInput>
93
+ | UpdateWrite<UpdateProcessTurnAnnotationInput>
94
+ | DeleteWrite;
98
95
 
99
96
  /** Mapped-run writes, committed in order before turn starts. @internal */
100
97
  export type MappedRunWrite =
101
- | {
102
- /** @internal */
103
- kind: "create";
104
- /** @internal */
105
- input: CreateMappedRunInput;
106
- }
98
+ | CreateWrite<CreateMappedRunInput>
107
99
  | {
108
100
  /** @internal */
109
101
  kind: "complete_item";
@@ -116,12 +108,7 @@ export type MappedRunWrite =
116
108
  };
117
109
 
118
110
  /** @internal */
119
- export type LeafOutcomeSnapshotWrite = {
120
- /** @internal */
121
- kind: "create";
122
- /** @internal */
123
- input: CreateProcessLeafOutcomeSnapshotInput;
124
- };
111
+ export type LeafOutcomeSnapshotWrite = CreateWrite<CreateProcessLeafOutcomeSnapshotInput>;
125
112
 
126
113
  /** @internal */
127
114
  export type WorkerIntent =
@@ -152,26 +139,9 @@ export type WorkerIntent =
152
139
 
153
140
  /** @internal */
154
141
  export type PendingExternalSourceFireWrite =
155
- | {
156
- /** @internal */
157
- kind: "create";
158
- /** @internal */
159
- input: CreatePendingExternalSourceFireInput;
160
- }
161
- | {
162
- /** @internal */
163
- kind: "update";
164
- /** @internal */
165
- id: string;
166
- /** @internal */
167
- input: UpdatePendingExternalSourceFireInput;
168
- }
169
- | {
170
- /** @internal */
171
- kind: "delete";
172
- /** @internal */
173
- id: string;
174
- };
142
+ | CreateWrite<CreatePendingExternalSourceFireInput>
143
+ | UpdateWrite<UpdatePendingExternalSourceFireInput>
144
+ | DeleteWrite;
175
145
 
176
146
  /** @internal */
177
147
  export interface DecisionMetadata {
@@ -194,6 +164,10 @@ const METADATA_KEY_GROUPS = {
194
164
 
195
165
  /** @internal */
196
166
  export interface Writes {
167
+ /** Internal scheduling writes do not count as process activity. @internal */
168
+ preserveUpdatedAt?: boolean;
169
+ /** A fenced, successful server-side wait check. Never supplied by extensions. @internal */
170
+ waitForAdmission?: string;
197
171
  /** @internal */
198
172
  processPatch: UpdateProcessInstanceInput;
199
173
  /** @internal */
@@ -205,6 +179,8 @@ export interface Writes {
205
179
  /** @internal */
206
180
  input: UpdateProcessProjectInput;
207
181
  };
182
+ /** Initial bindings, committed before the first worker start. @internal */
183
+ initialProjects?: CreateProcessProjectInput[];
208
184
  /** @internal */
209
185
  turnRecordWrites: TurnRecordWrite[];
210
186
  /** @internal */
@@ -246,9 +222,12 @@ export type WriteBuildResult = Writes | WriteBuildFailure;
246
222
 
247
223
  export function createWrites(init: Partial<Writes> = {}): Writes {
248
224
  return {
225
+ ...(init.preserveUpdatedAt ? { preserveUpdatedAt: true } : {}),
226
+ ...(init.waitForAdmission ? { waitForAdmission: init.waitForAdmission } : {}),
249
227
  processPatch: init.processPatch ?? {},
250
228
  changedFields: [...(init.changedFields ?? [])],
251
229
  ...(init.projectWrite ? { projectWrite: init.projectWrite } : {}),
230
+ ...(init.initialProjects ? { initialProjects: [...init.initialProjects] } : {}),
252
231
  turnRecordWrites: [...(init.turnRecordWrites ?? [])],
253
232
  turnStartWrites: [...(init.turnStartWrites ?? [])],
254
233
  mappedRunWrites: [...(init.mappedRunWrites ?? [])],
@@ -269,6 +248,7 @@ export function mergeWrites(...writesList: Array<Writes | undefined>): Writes {
269
248
  for (const writes of writesList) {
270
249
  if (!writes) continue;
271
250
  Object.assign(merged.processPatch, writes.processPatch);
251
+ if (writes.waitForAdmission) merged.waitForAdmission = writes.waitForAdmission;
272
252
  for (const field of writes.changedFields) {
273
253
  if (!merged.changedFields.includes(field)) {
274
254
  merged.changedFields.push(field);
@@ -278,6 +258,11 @@ export function mergeWrites(...writesList: Array<Writes | undefined>): Writes {
278
258
  if (merged.projectWrite) throw new Error("Cannot merge multiple process-project writes");
279
259
  merged.projectWrite = writes.projectWrite;
280
260
  }
261
+ if (writes.initialProjects) {
262
+ if (merged.initialProjects)
263
+ throw new Error("Cannot merge multiple initial repository bindings");
264
+ merged.initialProjects = writes.initialProjects;
265
+ }
281
266
  merged.turnRecordWrites.push(...writes.turnRecordWrites);
282
267
  merged.turnStartWrites.push(...writes.turnStartWrites);
283
268
  merged.mappedRunWrites.push(...writes.mappedRunWrites);
@@ -16,7 +16,6 @@ export {
16
16
  type ProcessGraphView,
17
17
  serializeProcessGraph,
18
18
  toProcessGraphView,
19
- validateProcessGraphEntryTurns,
20
19
  validateProcessGraphProducts,
21
20
  validateProcessGraphTurnTransitions,
22
21
  } from "@leitwerk-dev/process-sdk";
@@ -0,0 +1,305 @@
1
+ import type {
2
+ InspectionEvidence,
3
+ InspectionModelInput,
4
+ ProcessTurnRecord,
5
+ } from "@leitwerk-dev/domain";
6
+ import type {
7
+ ExecutionInspectionConfiguration,
8
+ ExecutionInspectionContext,
9
+ ExecutionInspectionSummary,
10
+ ExecutionInspectionTrace,
11
+ InspectionTargetState,
12
+ } from "@leitwerk-dev/protocol";
13
+ import { createInspectionLineage } from "./process-inspection.js";
14
+ import { buildInspectionTraceMessages } from "./process-inspection-trace.js";
15
+ import { ProcessUiSnapshotAssembler } from "./process-ui-snapshot-presenter.js";
16
+
17
+ /** One server-owned adapter for compact facts and on-demand inspection evidence. @internal */
18
+ export class ProcessInspectionReader {
19
+ private readonly history: ProcessUiSnapshotAssembler;
20
+ constructor(private readonly deps: ConstructorParameters<typeof ProcessUiSnapshotAssembler>[0]) {
21
+ this.history = new ProcessUiSnapshotAssembler(deps);
22
+ }
23
+ private selected(instanceId: string, turnRecordId: string) {
24
+ if (!this.deps.processes.getById(instanceId)) return null;
25
+ const record = this.deps.turnRecords.getById(turnRecordId);
26
+ return record?.instanceId === instanceId ? record : null;
27
+ }
28
+ private lineageSnapshot(instanceId: string) {
29
+ return {
30
+ records: this.deps.turnRecords.listByInstance(instanceId),
31
+ leases: this.deps.leases.listByInstance(instanceId),
32
+ observations: this.deps.executionInspections.listContextFacts(instanceId),
33
+ };
34
+ }
35
+ /** No session or immutable-content reads are needed to open the shell. */
36
+ summary(instanceId: string, turnRecordId: string): ExecutionInspectionSummary | null {
37
+ const record = this.selected(instanceId, turnRecordId);
38
+ if (!record) return null;
39
+ const records = this.deps.turnRecords
40
+ .listByInstance(instanceId)
41
+ .sort((a, b) => a.startedAt.localeCompare(b.startedAt) || a.id.localeCompare(b.id));
42
+ const index = records.findIndex((candidate) => candidate.id === turnRecordId);
43
+ const start = record.turnStartRecordId
44
+ ? this.deps.turnStarts.getById(record.turnStartRecordId)
45
+ : null;
46
+ const inputs = this.deps.executionInspections.modelInputs(instanceId, turnRecordId);
47
+ const accepted =
48
+ start && "start" in start.state && start.state.start?.kind === "llm"
49
+ ? start.state.start.model
50
+ : null;
51
+ let model: InspectionEvidence<InspectionModelInput["model"]> =
52
+ record.turnType === "llm"
53
+ ? { state: "not_recorded", reason: "The historical model was not recorded" }
54
+ : {
55
+ state: "not_applicable",
56
+ reason: `This ${record.turnType} execution does not invoke a model`,
57
+ };
58
+ const effective = inputs.at(-1)?.model;
59
+ if (effective) model = { state: "recorded", value: effective };
60
+ else if (accepted)
61
+ model = {
62
+ state: "recorded",
63
+ value: {
64
+ provider: accepted.providerId,
65
+ id: accepted.modelId,
66
+ thinkingLevel: accepted.thinkingLevel,
67
+ },
68
+ };
69
+ const { turnResultMarkdown: _output, ...execution } = record;
70
+ return {
71
+ instanceId,
72
+ execution,
73
+ origin: createInspectionLineage(this.lineageSnapshot(instanceId)).origin(record),
74
+ startKind: start
75
+ ? { state: "recorded", value: start.startKind }
76
+ : { state: "not_recorded", reason: "Execution start kind was not recorded" },
77
+ model,
78
+ modelInputCount: inputs.length,
79
+ usage: this.deps.turnSummaries.get(turnRecordId)?.usage ?? null,
80
+ previousTurnRecordId: records[index - 1]?.id ?? null,
81
+ nextTurnRecordId: records[index + 1]?.id ?? null,
82
+ };
83
+ }
84
+ private missingModelEvidence<T>(record: ProcessTurnRecord): InspectionEvidence<T> {
85
+ return record.turnType === "llm"
86
+ ? {
87
+ state: "not_recorded",
88
+ reason:
89
+ "No model input was recorded for this execution. Historical instructions cannot be reconstructed from current settings.",
90
+ }
91
+ : {
92
+ state: "not_applicable",
93
+ reason: `This ${record.turnType} execution does not invoke a model`,
94
+ };
95
+ }
96
+ configuration(instanceId: string, turnRecordId: string): ExecutionInspectionConfiguration | null {
97
+ const record = this.selected(instanceId, turnRecordId);
98
+ if (!record) return null;
99
+ const revisions = this.deps.executionInspections
100
+ .list(instanceId, turnRecordId)
101
+ .flatMap((capture) => {
102
+ if (capture.fact.kind !== "model_input") return [];
103
+ const { messages: _messages, kind: _kind, ...configuration } = capture.fact;
104
+ return [{ id: capture.id, timestamp: capture.timestamp, ...configuration }];
105
+ });
106
+ return {
107
+ instanceId,
108
+ turnRecordId,
109
+ revisions: revisions.length
110
+ ? { state: "recorded", value: revisions }
111
+ : this.missingModelEvidence(record),
112
+ currentWorkflowTurnId: record.turnId,
113
+ };
114
+ }
115
+ async context(
116
+ instanceId: string,
117
+ turnRecordId: string,
118
+ ): Promise<ExecutionInspectionContext | null> {
119
+ const record = this.selected(instanceId, turnRecordId);
120
+ if (!record) return null;
121
+ const lineageSnapshot = this.lineageSnapshot(instanceId);
122
+ const captures = this.deps.executionInspections.list(instanceId, turnRecordId);
123
+ const session = await this.deps.sessionReader.readSessionTree(instanceId);
124
+ const lineage = createInspectionLineage({ ...lineageSnapshot, tree: session.piTree });
125
+ const supplies = captures.filter((capture) => capture.fact.kind === "supplied_context");
126
+ const products = supplies.flatMap((capture) =>
127
+ capture.fact.kind === "supplied_context"
128
+ ? capture.fact.products.map((product) => ({
129
+ ...product,
130
+ supplyId: capture.id,
131
+ consumed: captures.some(
132
+ (candidate) =>
133
+ candidate.fact.kind === "product_consumed" &&
134
+ `${turnRecordId}:${candidate.fact.supplyId}` === capture.id &&
135
+ candidate.fact.name === product.name,
136
+ ),
137
+ }))
138
+ : [],
139
+ );
140
+ const modelInputs = captures.flatMap((capture) =>
141
+ capture.fact.kind === "model_input"
142
+ ? [
143
+ {
144
+ id: capture.id,
145
+ timestamp: capture.timestamp,
146
+ boundaryEntryId: capture.fact.boundaryEntryId,
147
+ model: capture.fact.model,
148
+ messages: capture.fact.messages.map((message) => {
149
+ const sourceTurnRecordId = message.entryId ? lineage.owner(message.entryId) : null;
150
+ return {
151
+ entryId: message.entryId,
152
+ sourceTurnRecordId,
153
+ role: message.role,
154
+ content:
155
+ sourceTurnRecordId && sourceTurnRecordId !== turnRecordId
156
+ ? null
157
+ : message.content,
158
+ };
159
+ }),
160
+ },
161
+ ]
162
+ : [],
163
+ );
164
+ const boundaries = new Set(
165
+ modelInputs
166
+ .map((revision) => revision.boundaryEntryId)
167
+ .filter((id): id is string => id !== null),
168
+ );
169
+ if (record.resultPiEntryId) boundaries.add(record.resultPiEntryId);
170
+ const contextEntries = new Map(
171
+ [...boundaries].flatMap((boundary) =>
172
+ session.piTree.getBranch(boundary).map((entry) => [entry.id, entry] as const),
173
+ ),
174
+ );
175
+ const compactions = [...contextEntries.values()].flatMap((entry) =>
176
+ entry.type === "compaction"
177
+ ? [{ entryId: entry.id, firstKeptEntryId: entry.firstKeptEntryId, summary: entry.summary }]
178
+ : [],
179
+ );
180
+ const inputMessages = buildInspectionTraceMessages({
181
+ tree: session.piTree,
182
+ record,
183
+ captures,
184
+ events: [],
185
+ owner: lineage.owner,
186
+ }).filter((message) => message.role === "user" || message.role === "system");
187
+ return {
188
+ instanceId,
189
+ turnRecordId,
190
+ origin: lineage.origin(record),
191
+ ancestry: lineage.ancestry(record),
192
+ products: supplies.length
193
+ ? { state: "recorded", value: products }
194
+ : { state: "not_recorded", reason: "Supplied product versions were not recorded" },
195
+ modelInputs: modelInputs.length
196
+ ? { state: "recorded", value: modelInputs }
197
+ : this.missingModelEvidence(record),
198
+ compactions,
199
+ inputMessages,
200
+ };
201
+ }
202
+ async trace(
203
+ instanceId: string,
204
+ turnRecordId: string,
205
+ target: { entryId?: string; itemId?: string; boundaryFor?: string } = {},
206
+ ): Promise<ExecutionInspectionTrace | null> {
207
+ // Keep every durable fact at the same boundary as the reasoning history.
208
+ // Session storage is asynchronous and can advance independently.
209
+ const lineageSnapshot = this.lineageSnapshot(instanceId);
210
+ const captures = this.deps.executionInspections.list(instanceId, turnRecordId);
211
+ const annotations = this.deps.turnAnnotations
212
+ .listByInstance(instanceId)
213
+ .filter((annotation) =>
214
+ annotation.references.some(
215
+ (reference) =>
216
+ reference.kind === "turn_record" && reference.turnRecordId === turnRecordId,
217
+ ),
218
+ );
219
+ const evidence = await this.history.readReasoningEvidence({
220
+ instanceId,
221
+ turnRecordId,
222
+ includeSession: true,
223
+ });
224
+ if (!evidence?.session) return null;
225
+ const { detail: history, turnRecord: record, events, session } = evidence;
226
+ const lineage = createInspectionLineage({ ...lineageSnapshot, tree: session.piTree });
227
+ const messages = buildInspectionTraceMessages({
228
+ tree: session.piTree,
229
+ record,
230
+ captures,
231
+ events,
232
+ owner: lineage.owner,
233
+ });
234
+ let targetState: InspectionTargetState | null = null;
235
+ let inheritedBoundary: ExecutionInspectionTrace["inheritedBoundary"] = null;
236
+ const unavailable = {
237
+ state: "unavailable",
238
+ reason: "The requested item is unavailable or does not belong to this execution",
239
+ } as const;
240
+ let itemId = target.entryId ? `entry:${target.entryId}` : target.itemId;
241
+ if (itemId === "input")
242
+ itemId =
243
+ messages.find((message) => message.role === "user" || message.role === "system")?.id ??
244
+ itemId;
245
+ if (itemId === "reasoning")
246
+ itemId =
247
+ messages
248
+ .flatMap((message) => message.blocks)
249
+ .find((block) => block.content.type === "thinking")?.id ??
250
+ events
251
+ .filter(
252
+ (event) =>
253
+ event.eventType === "pi.stream.delta" && event.data.streamType === "thinking",
254
+ )
255
+ .map((event) => `event:${event.eventSequence}`)[0] ??
256
+ itemId;
257
+ if (itemId) {
258
+ const message = messages.find(
259
+ (message) =>
260
+ message.id === itemId ||
261
+ message.aliases.includes(itemId) ||
262
+ message.blocks.some((block) => block.id === itemId),
263
+ );
264
+ const event = events.find((event) => `event:${event.eventSequence}` === itemId);
265
+ targetState =
266
+ message || event
267
+ ? { state: "available", itemId: message?.aliases.includes(itemId) ? message.id : itemId }
268
+ : unavailable;
269
+ }
270
+ if (target.boundaryFor) {
271
+ const child = lineageSnapshot.records.find((record) => record.id === target.boundaryFor);
272
+ const context = child ? lineage.origin(child).conversation : null;
273
+ const boundary = context?.state === "recorded" ? context.value : null;
274
+ if (
275
+ boundary?.turnRecordId === turnRecordId &&
276
+ (!target.entryId || boundary.entryId === target.entryId)
277
+ ) {
278
+ inheritedBoundary = boundary;
279
+ targetState = messages.some((message) => message.entryId === boundary.entryId)
280
+ ? { state: "available", itemId: `entry:${boundary.entryId}` }
281
+ : {
282
+ state: "unavailable",
283
+ reason: "The inheritance boundary is recorded, but its source entry is unavailable",
284
+ };
285
+ } else targetState = unavailable;
286
+ }
287
+ return {
288
+ ...history,
289
+ messages,
290
+ unassignedMessages: buildInspectionTraceMessages({
291
+ tree: session.piTree,
292
+ record,
293
+ scope: "unassigned_branch",
294
+ captures: [],
295
+ events: [],
296
+ owner: lineage.owner,
297
+ }),
298
+ events,
299
+ annotations,
300
+ output: record.turnResultMarkdown,
301
+ target: targetState,
302
+ inheritedBoundary,
303
+ };
304
+ }
305
+ }