@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
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/test-helpers/accepted-turn-start.ts","../src/test-helpers/prepared-fixture-start.ts","../src/test-helpers/session-snapshot-fixtures.ts","../src/test-helpers/process-fixtures.ts","../src/test-helpers/unit-deps.ts"],"sourcesContent":["import type { ResolvedTurnStart } from \"@leitwerk-dev/domain\";\nimport type { AppContext } from \"../app.js\";\n\n/** @internal */\ntype AcceptedTurnRepos = Pick<\n\tAppContext[\"deps\"],\n\t\"processes\" | \"turnRecords\" | \"turnStarts\" | \"leases\"\n>;\n\n/** @internal */\ntype AcceptedTurnContext = {\n\t/** @internal */\n\tdeps: AcceptedTurnRepos;\n};\n\n/** Compatibility name for existing LLM fixtures. @internal */\nexport const createAcceptedLlmTurn = createAcceptedWorkerTurn;\n/** Compatibility name for existing LLM starts. @internal */\nexport const createAcceptedLlmTurnStart = createAcceptedWorkerTurnStart;\n\n/** @internal */\nexport function createAcceptedWorkerTurn(\n\tctx: AcceptedTurnContext | null,\n\tinput: Parameters<AcceptedTurnRepos[\"turnRecords\"][\"create\"]>[0] & {\n\t\t/** @internal */\n\t\tid: string;\n\t\t/** @internal */\n\t\tturnType: \"llm\" | \"automatic\";\n\t},\n\toptions: Parameters<typeof createAcceptedWorkerTurnStart>[3] & {\n\t\t/** @internal */\n\t\tcurrent?: boolean;\n\t\t/** @internal */\n\t\tworkerId?: string;\n\t} = {},\n) {\n\tif (!ctx) throw new Error(\"Server context not initialized\");\n\tconst { deps: repos } = ctx;\n\tconst current = options.current ?? input.status === \"running\";\n\tconst lease = repos.leases.create({\n\t\tinstanceId: input.instanceId,\n\t\tworkerId: options.workerId ?? `wkr_${input.id}`,\n\t\tstate: current ? (input.status === \"failed\" ? \"failed\" : \"busy\") : \"exited\",\n\t});\n\tconst start = createAcceptedWorkerTurnStart(ctx, input, lease.id, options);\n\tconst record = repos.turnRecords.create({\n\t\t...input,\n\t\tturnStartRecordId: start.id,\n\t\tacceptedWorkerLeaseId: lease.id,\n\t});\n\tif (current) {\n\t\trepos.processes.update(input.instanceId, {\n\t\t\tcurrentExecution: { kind: \"worker_start\", id: start.id },\n\t\t});\n\t} else {\n\t\trepos.leases.update(lease.id, {\n\t\t\texitedAt: input.endedAt ?? input.startedAt ?? new Date().toISOString(),\n\t\t});\n\t}\n\treturn record;\n}\n\n/** @internal */\nfunction createAcceptedWorkerTurnStart(\n\tctx: AcceptedTurnContext,\n\tinput: {\n\t\t/** @internal */\n\t\tturnType?: \"llm\" | \"automatic\";\n\t\t/** @internal */\n\t\tid: string;\n\t\t/** @internal */\n\t\tinstanceId: string;\n\t\t/** @internal */\n\t\tturnId: string;\n\t},\n\tacceptedWorkerLeaseId: string,\n\toptions: {\n\t\t/** @internal */\n\t\tid?: string;\n\t\t/** @internal */\n\t\tpreparedStart?: Extract<ResolvedTurnStart, { kind: \"llm\" }>;\n\t\t/** @internal */\n\t\tmodel?: {\n\t\t\t/** @internal */\n\t\t\tprofileId: string;\n\t\t\t/** @internal */\n\t\t\tproviderId: string;\n\t\t\t/** @internal */\n\t\t\tmodelId: string;\n\t\t\t/** @internal */\n\t\t\tthinkingLevel: \"off\";\n\t\t};\n\t\t/** @internal */\n\t\tpiResourceSnapshotDigest?: string;\n\t\t/** @internal */\n\t\tworkerRuntimeProfileId?: string;\n\t} = {},\n) {\n\treturn ctx.deps.turnStarts.create({\n\t\tid: options.id ?? `tsr_${input.id}`,\n\t\tinstanceId: input.instanceId,\n\t\tturnId: input.turnId,\n\t\tturnType: input.turnType ?? \"llm\",\n\t\tproposedTurnRecordId: input.id,\n\t\tstartKind: \"selected_turn\",\n\t\trecoveryTurnRecordId: null,\n\t\tcontinuation: null,\n\t\tstate: {\n\t\t\tkind: \"accepted\",\n\t\t\tstart:\n\t\t\t\tinput.turnType === \"automatic\"\n\t\t\t\t\t? { kind: \"automatic\" }\n\t\t\t\t\t: (options.preparedStart ?? {\n\t\t\t\t\t\t\tkind: \"llm\",\n\t\t\t\t\t\t\tmodel: options.model ?? {\n\t\t\t\t\t\t\t\tprofileId: \"fixture-profile\",\n\t\t\t\t\t\t\t\tproviderId: \"fixture-provider\",\n\t\t\t\t\t\t\t\tmodelId: \"fixture-model\",\n\t\t\t\t\t\t\t\tthinkingLevel: \"off\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tproviderOptions: {},\n\t\t\t\t\t\t\tproviderWorkerConfig: null,\n\t\t\t\t\t\t\tpiResourceSnapshotDigest:\n\t\t\t\t\t\t\t\toptions.piResourceSnapshotDigest ?? \"fixture-resource-digest\",\n\t\t\t\t\t\t\tworkerRuntimeProfileId: options.workerRuntimeProfileId ?? \"local\",\n\t\t\t\t\t\t\tpiSettings: {},\n\t\t\t\t\t\t}),\n\t\t\tturnRecordId: input.id,\n\t\t\tacceptedWorkerLeaseId,\n\t\t},\n\t});\n}\n","import type { ProcessInstance, ResolvedTurnStart } from \"@leitwerk-dev/domain\";\nimport type { ExtensionCatalog } from \"@leitwerk-dev/extension-runtime\";\nimport type { PiResourceBundle } from \"@leitwerk-dev/worker-protocol\";\nimport type { AppContext } from \"../app.js\";\nimport { createPiResourceBundleCache } from \"../pi-resources/index.js\";\nimport { prepareCreatedTurnStarts } from \"../process-engine/turn-start-preflight.js\";\nimport { createWrites, type TurnStartWrite } from \"../process-engine/writes/writes.js\";\n\n/** Prepare fixture resources through the same provider preflight as admitted work. @internal */\nexport async function prepareAcceptedFixtureStart(\n\tctx: AppContext,\n\tprocess: ProcessInstance,\n\tturnId: string,\n\tcontributions: ExtensionCatalog[\"piContributions\"],\n): Promise<{\n\t/** @internal */\n\tstart: Extract<ResolvedTurnStart, { kind: \"llm\" }>;\n\t/** @internal */\n\tbundle: PiResourceBundle;\n}> {\n\tconst profileId =\n\t\tprocess.selectedTurnModelProfileId ??\n\t\tprocess.defaultModelProfileId ??\n\t\tctx.config.process_configs?.[process.processId]?.default_model_profile;\n\tconst write: Extract<TurnStartWrite, { kind: \"create\" }> = {\n\t\tkind: \"create\",\n\t\tinput: {\n\t\t\tinstanceId: process.id,\n\t\t\tturnId,\n\t\t\tturnType: \"llm\",\n\t\t\tproposedTurnRecordId: \"fixture-preflight\",\n\t\t\tstartKind: \"selected_turn\",\n\t\t\trecoveryTurnRecordId: null,\n\t\t\tcontinuation: null,\n\t\t\tstate: {\n\t\t\t\tkind: \"preparation_failed\",\n\t\t\t\trequestedModelProfileId: profileId ?? null,\n\t\t\t\tproviderOptions: {},\n\t\t\t\tcode: \"model_required\",\n\t\t\t\tsafeSummary: \"Fixture preparation\",\n\t\t\t},\n\t\t},\n\t};\n\tconst writes = createWrites({ turnStartWrites: [write] });\n\tconst bundleCache = createPiResourceBundleCache();\n\tconst result = await prepareCreatedTurnStarts(\n\t\t{\n\t\t\tconfig: ctx.config,\n\t\t\tregistry: ctx.modelProviderRegistry,\n\t\t\tmodelStatusCache: ctx.modelStatusCache,\n\t\t\tpiContributions: contributions,\n\t\t\tbundleCache,\n\t\t\tprojects: ctx.deps.projects,\n\t\t\tprocessSkills: ctx.deps.processSkills,\n\t\t},\n\t\t{ ...process, selectedTurnId: turnId, selectedTurnModelProfileId: profileId ?? null },\n\t\twrites,\n\t);\n\tif (!result.ok) throw new Error(`Cannot prepare accepted fixture: ${result.message}`);\n\tconst state = write.input.state;\n\tif (state.kind !== \"starting\" || state.start.kind !== \"llm\") {\n\t\tthrow new Error(\n\t\t\t`Cannot prepare accepted fixture: ${state.kind === \"preparation_failed\" ? state.safeSummary : state.kind}`,\n\t\t);\n\t}\n\tconst bundle = bundleCache.get(state.start.piResourceSnapshotDigest);\n\tif (!bundle) throw new Error(\"Prepared fixture resource bundle is missing\");\n\treturn {\n\t\t/** @internal */\n\t\tstart: state.start,\n\t\t/** @internal */\n\t\tbundle,\n\t};\n}\n","import type { AppContext } from \"../app.js\";\nimport { createAllRepos } from \"../db/repositories.js\";\nimport { createFileBackedProcessSessionSnapshotStore } from \"../process-session-store.js\";\nimport { createProjectedSessionSnapshotStore } from \"../session-summary-projection.js\";\n\n/** Accept fixture snapshots through the same persisted projection as worker uploads. @internal */\nexport async function writeProcessSessionSnapshot(\n\tctx: Pick<AppContext, \"db\" | \"config\">,\n\tinstanceId: string,\n\tentries: readonly unknown[],\n): Promise<void> {\n\tconst store = createProjectedSessionSnapshotStore(\n\t\tcreateFileBackedProcessSessionSnapshotStore(ctx.config.storage.tree_files_dir),\n\t\tcreateAllRepos(ctx.db),\n\t);\n\tawait store.writeSnapshot(\n\t\tinstanceId,\n\t\t`${entries.map((entry) => JSON.stringify(entry)).join(\"\\n\")}\\n`,\n\t);\n}\n","import type { TurnId } from \"@leitwerk-dev/domain\";\nimport {\n\ttype AutomaticTurnDefinition,\n\tautomaticTurn,\n\tdefineProcess,\n\ttype ExtensionProcessDefinition,\n\temptyParamsCodec,\n\ttype HumanTurnDefinition,\n\thumanTurn,\n\ttype LlmTurnDefinition,\n\tllmTurn,\n\ttype TurnDefinition,\n} from \"@leitwerk-dev/process-sdk\";\n\nexport function createFixtureLlmTurn(\n\tdescription: string,\n\toverrides: Partial<LlmTurnDefinition<string, Record<string, never>, Record<string, never>>> = {},\n): LlmTurnDefinition<string, Record<string, never>, Record<string, never>> {\n\treturn llmTurn({\n\t\tavailableTools: [],\n\t\tdescription,\n\t\tbranchType: \"primary\",\n\t\tcontext: \"fresh\",\n\t\tprompt: async () => description,\n\t\tturnEnd: { outcome: \"done\", params: {}, complete: true },\n\t\t...overrides,\n\t});\n}\n\nexport function createFixtureHumanTurn(\n\toverrides: Partial<HumanTurnDefinition<Record<string, never>, Record<string, never>>> = {},\n): HumanTurnDefinition<Record<string, never>, Record<string, never>> {\n\treturn humanTurn({\n\t\tdescription: \"Review\",\n\t\treviewSemanticRef: \"plan\",\n\t\tactions: {\n\t\t\tmark_done: {\n\t\t\t\tlabel: \"Mark done\",\n\t\t\t\tacceptanceState: \"accepted\",\n\t\t\t\tcomplete: true,\n\t\t\t},\n\t\t},\n\t\t...overrides,\n\t});\n}\n\nexport function createFixtureAutomaticTurn(\n\tdescription = \"Automatic turn\",\n): AutomaticTurnDefinition<\"done\", Record<string, never>, Record<string, never>> {\n\treturn automaticTurn<Record<string, never>, Record<string, never>, \"done\">({\n\t\tdescription,\n\t\trun: async () => ({ outcome: \"done\", params: {} }),\n\t\tturnEnd: { outcome: \"done\", params: {}, complete: true },\n\t});\n}\n\nfunction ensureFixtureTurnIsValid(\n\tdefinition: TurnDefinition<Record<string, never>, Record<string, never>>,\n): TurnDefinition<Record<string, never>, Record<string, never>> {\n\tif (definition.kind === \"human\" && Object.keys(definition.actions).length === 0) {\n\t\treturn {\n\t\t\t...definition,\n\t\t\tactions: {\n\t\t\t\t__fixture_noop: { label: \"No-op\", acceptanceState: \"neutral\", complete: true },\n\t\t\t},\n\t\t};\n\t}\n\tif (\n\t\t(definition.kind === \"llm\" || definition.kind === \"automatic\") &&\n\t\tObject.keys(definition.outcomes ?? {}).length === 0 &&\n\t\t!definition.turnEnd\n\t) {\n\t\treturn {\n\t\t\t...definition,\n\t\t\tturnEnd: { outcome: \"done\", params: {}, complete: true },\n\t\t} as TurnDefinition<Record<string, never>, Record<string, never>>;\n\t}\n\treturn definition;\n}\n\nexport function createFixtureProcess(input: {\n\tid: string;\n\tentry: TurnId;\n\talternateEntries?: readonly TurnId[];\n\tturns?: Record<string, TurnDefinition<Record<string, never>, Record<string, never>>>;\n}): ExtensionProcessDefinition<Record<string, never>, Record<string, never>> {\n\tconst turns = input.turns ?? {};\n\tconst entries = [input.entry, ...(input.alternateEntries ?? [])];\n\treturn defineProcess<Record<string, never>, Record<string, never>>({\n\t\tid: input.id,\n\t\tdisplayName: input.id,\n\t\tentry: input.entry,\n\t\t...(input.alternateEntries ? { alternateEntries: input.alternateEntries } : {}),\n\t\tparamsCodec: emptyParamsCodec,\n\t\tstateCodec: emptyParamsCodec,\n\t\tinitialState: () => ({}),\n\t\tturns:\n\t\t\tObject.keys(turns).length > 0\n\t\t\t\t? Object.fromEntries(\n\t\t\t\t\t\tObject.entries(turns).map(([turnId, definition]) => [\n\t\t\t\t\t\t\tturnId,\n\t\t\t\t\t\t\tensureFixtureTurnIsValid(definition),\n\t\t\t\t\t\t]),\n\t\t\t\t\t)\n\t\t\t\t: Object.fromEntries(entries.map((turnId) => [turnId, createFixtureLlmTurn(turnId)])),\n\t});\n}\n\nexport function createProcessGraphRegistry(\n\tprocesses: readonly ExtensionProcessDefinition<unknown, unknown>[],\n): ReadonlyMap<string, ExtensionProcessDefinition<unknown, unknown>> {\n\treturn new Map(\n\t\tprocesses.map(\n\t\t\t(process) => [process.id, process as ExtensionProcessDefinition<unknown, unknown>] as const,\n\t\t),\n\t);\n}\n\nexport function createTurnOwnershipFixtureProcess(\n\tid = \"turn_ownership_process\",\n): ExtensionProcessDefinition<Record<string, never>, Record<string, never>> {\n\treturn createFixtureProcess({\n\t\tid,\n\t\tentry: \"llm_turn\",\n\t\tturns: {\n\t\t\tllm_turn: createFixtureLlmTurn(\"LLM turn\"),\n\t\t\tautomatic_turn: createFixtureAutomaticTurn(),\n\t\t\thuman_turn: createFixtureHumanTurn(),\n\t\t},\n\t});\n}\n\nexport function createDefaultTestProcessGraphRegistry(): ReadonlyMap<\n\tstring,\n\tExtensionProcessDefinition<unknown, unknown>\n> {\n\tconst ticket = createFixtureProcess({\n\t\tid: \"ticket_issue_process\",\n\t\tentry: \"generate_plan\",\n\t\tturns: {\n\t\t\tgenerate_plan: createFixtureLlmTurn(\"generate_plan\", {\n\t\t\t\tresultSemanticRef: \"plan\",\n\t\t\t\tturnEnd: undefined,\n\t\t\t\toutcomes: { plan_saved: { description: \"plan_saved\", parameters: {}, to: \"plan_review\" } },\n\t\t\t}),\n\t\t\tplan_review: createFixtureHumanTurn({\n\t\t\t\treviewSemanticRef: \"plan\",\n\t\t\t\tactions: {\n\t\t\t\t\trevision_requested: {\n\t\t\t\t\t\tlabel: \"Request revision\",\n\t\t\t\t\t\tacceptanceState: \"requires_changes\",\n\t\t\t\t\t\tto: \"generate_plan\",\n\t\t\t\t\t},\n\t\t\t\t\tplan_approved: {\n\t\t\t\t\t\tlabel: \"Approve plan\",\n\t\t\t\t\t\tacceptanceState: \"accepted\",\n\t\t\t\t\t\tto: \"implement\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t\timplement: createFixtureLlmTurn(\"implement\", {\n\t\t\t\tturnEnd: { outcome: \"done\", params: {}, to: \"handoff_review\" },\n\t\t\t}),\n\t\t\thandoff_review: createFixtureLlmTurn(\"handoff_review\", {\n\t\t\t\tturnEnd: { outcome: \"created\", params: {}, to: \"run_llm_review\" },\n\t\t\t}),\n\t\t\trun_llm_review: createFixtureLlmTurn(\"run_llm_review\", {\n\t\t\t\tresultSemanticRef: \"review\",\n\t\t\t\tturnEnd: undefined,\n\t\t\t\toutcomes: {\n\t\t\t\t\tissues_found: { description: \"issues_found\", parameters: {}, to: \"address_review\" },\n\t\t\t\t\tno_issues: { description: \"no_issues\", parameters: {}, to: \"implementation_review\" },\n\t\t\t\t},\n\t\t\t}),\n\t\t\taddress_review: createFixtureLlmTurn(\"address_review\", {\n\t\t\t\tturnEnd: { outcome: \"comments_addressed\", params: {}, to: \"verify_build\" },\n\t\t\t}),\n\t\t\tverify_build: createFixtureLlmTurn(\"verify_build\", {\n\t\t\t\tturnEnd: undefined,\n\t\t\t\toutcomes: {\n\t\t\t\t\tbuild_failing: { description: \"build_failing\", parameters: {}, to: \"fix_build\" },\n\t\t\t\t\tbuild_passing: {\n\t\t\t\t\t\tdescription: \"build_passing\",\n\t\t\t\t\t\tparameters: {},\n\t\t\t\t\t\tto: \"commit_and_complete\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t\tfix_build: createFixtureLlmTurn(\"fix_build\", {\n\t\t\t\tturnEnd: { outcome: \"build_fixed\", params: {}, to: \"verify_build\" },\n\t\t\t}),\n\t\t\tcommit_and_complete: createFixtureLlmTurn(\"commit_and_complete\", {\n\t\t\t\tturnEnd: { outcome: \"committed\", params: {}, to: \"implementation_review\" },\n\t\t\t}),\n\t\t\timplementation_review: createFixtureHumanTurn({\n\t\t\t\treviewSemanticRef: \"review\",\n\t\t\t}),\n\t\t},\n\t});\n\tconst mrPolish = createFixtureProcess({\n\t\tid: \"mr_polish_process\",\n\t\tentry: \"address_review\",\n\t\tturns: {\n\t\t\taddress_review: createFixtureLlmTurn(\"address_review\", {\n\t\t\t\tturnEnd: { outcome: \"comments_addressed\", params: {}, to: \"verify_build\" },\n\t\t\t}),\n\t\t\tverify_build: createFixtureLlmTurn(\"verify_build\", {\n\t\t\t\tturnEnd: undefined,\n\t\t\t\toutcomes: {\n\t\t\t\t\tbuild_failing: { description: \"build_failing\", parameters: {}, to: \"fix_build\" },\n\t\t\t\t\tbuild_passing: {\n\t\t\t\t\t\tdescription: \"build_passing\",\n\t\t\t\t\t\tparameters: {},\n\t\t\t\t\t\tto: \"commit_and_complete\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t\tfix_build: createFixtureLlmTurn(\"fix_build\", {\n\t\t\t\tturnEnd: { outcome: \"build_fixed\", params: {}, to: \"verify_build\" },\n\t\t\t}),\n\t\t\tcommit_and_complete: createFixtureLlmTurn(\"commit_and_complete\", {\n\t\t\t\tturnEnd: { outcome: \"committed\", params: {}, to: \"mr_polish_review\" },\n\t\t\t}),\n\t\t\tmr_polish_review: createFixtureHumanTurn({\n\t\t\t\treviewSemanticRef: \"review\",\n\t\t\t}),\n\t\t},\n\t});\n\treturn createProcessGraphRegistry([\n\t\tticket as ExtensionProcessDefinition<unknown, unknown>,\n\t\tmrPolish as ExtensionProcessDefinition<unknown, unknown>,\n\t]);\n}\n","import type { ProcessLaunchPlanServiceLike } from \"@leitwerk-dev/process-sdk\";\nimport { getDefaultConfig } from \"../config/config-loader.js\";\nimport { createDatabase, createInMemoryDatabase, type LeitwerkDb } from \"../db/database.js\";\nimport { createAllRepos, type RepositoryBundle } from \"../db/repositories.js\";\nimport type { ModelStatusCacheSnapshot } from \"../model-providers/model-status-cache.js\";\nimport {\n\tcreateServerProcessModelPolicy,\n\ttype ServerProcessModelPolicy,\n} from \"../process-model-policy/index.js\";\nimport { type Broadcaster, createBroadcaster } from \"../ws/broadcast.js\";\nimport { createDefaultTestProcessGraphRegistry } from \"./process-fixtures.js\";\n\n/** @internal */\nexport interface TestDeps extends RepositoryBundle {\n\t/** @internal */\n\tdb: LeitwerkDb;\n\t/** @internal */\n\tbroadcaster: Broadcaster;\n\t/** @internal */\n\tprocessModelPolicy: ServerProcessModelPolicy;\n\t/** @internal */\n\tlaunchPlans: ProcessLaunchPlanServiceLike;\n\t/** @internal */\n\tgetModelAvailabilitySnapshot: () => ModelStatusCacheSnapshot;\n}\n\n/** Select a turn-start fixture without creating a turn record or attempt. */\nexport function createSelectedTurnStart(\n\tdeps: TestDeps,\n\tinput: Omit<\n\t\tParameters<TestDeps[\"turnStarts\"][\"create\"]>[0],\n\t\t\"startKind\" | \"recoveryTurnRecordId\" | \"continuation\"\n\t>,\n) {\n\tconst record = deps.turnStarts.create({\n\t\t...input,\n\t\tstartKind: \"selected_turn\",\n\t\trecoveryTurnRecordId: null,\n\t\tcontinuation: null,\n\t});\n\tdeps.processes.update(input.instanceId, {\n\t\tcurrentExecution: { kind: \"worker_start\", id: record.id },\n\t});\n\treturn record;\n}\n\n/** @internal */\nexport function createTestDeps(\n\toptions: {\n\t\t/** @internal */\n\t\tsqlitePath?: string;\n\t} = {},\n): TestDeps {\n\tconst db = options.sqlitePath\n\t\t? createDatabase({ sqlitePath: options.sqlitePath, enableWAL: false })\n\t\t: createInMemoryDatabase();\n\tconst repos = createAllRepos(db);\n\tconst config = getDefaultConfig();\n\tconst processModelPolicy = createServerProcessModelPolicy({\n\t\tconfig,\n\t\tprocessGraphs: createDefaultTestProcessGraphRegistry(),\n\t\tprocessActionRegistry: { getTurnDefinition: () => undefined },\n\t});\n\tconst launchPlans: ProcessLaunchPlanServiceLike = {\n\t\tasync prepare(launchPlan, opts = {}) {\n\t\t\treturn processModelPolicy.prepareLaunchPlan(launchPlan, opts);\n\t\t},\n\t};\n\tconst getModelAvailabilitySnapshot = (): ModelStatusCacheSnapshot => ({\n\t\trevision: 1,\n\t\tcapturedAt: new Date().toISOString(),\n\t\tavailabilityTransitions: [],\n\t\tprofiles: config.pi.model_profiles.map((profile) => ({\n\t\t\tprofileId: profile.id,\n\t\t\tproviderId: profile.provider,\n\t\t\tmodelId: profile.model_id,\n\t\t\tavailability: \"available\",\n\t\t\tcheckedAt: new Date().toISOString(),\n\t\t\texpiresAt: new Date(Date.now() + 60_000).toISOString(),\n\t\t})),\n\t});\n\tconst createTurnRecord = repos.turnRecords.create.bind(repos.turnRecords);\n\trepos.turnRecords.create = (input) => {\n\t\tconst turnType = input.turnType ?? \"llm\";\n\t\tif (\n\t\t\t(turnType === \"llm\" || turnType === \"automatic\") &&\n\t\t\t(!input.turnStartRecordId || !input.acceptedWorkerLeaseId)\n\t\t) {\n\t\t\tconst turnRecordId = input.id ?? `trn_fixture_${crypto.randomUUID()}`;\n\t\t\tconst isCurrent =\n\t\t\t\tinput.status === \"running\" || input.status === \"failed\" || input.status === undefined;\n\t\t\tconst lease = repos.leases.create({\n\t\t\t\tinstanceId: input.instanceId,\n\t\t\t\tworkerId: `wkr_fixture_${turnRecordId}`,\n\t\t\t\tstate: input.status === \"failed\" ? \"failed\" : isCurrent ? \"busy\" : \"exited\",\n\t\t\t});\n\t\t\tconst start = repos.turnStarts.create({\n\t\t\t\tid: `tsr_fixture_${turnRecordId}`,\n\t\t\t\tinstanceId: input.instanceId,\n\t\t\t\tturnId: input.turnId,\n\t\t\t\tturnType,\n\t\t\t\tproposedTurnRecordId: turnRecordId,\n\t\t\t\tstartKind: \"selected_turn\",\n\t\t\t\trecoveryTurnRecordId: null,\n\t\t\t\tcontinuation: null,\n\t\t\t\tstate: {\n\t\t\t\t\tkind: \"accepted\",\n\t\t\t\t\tstart:\n\t\t\t\t\t\tturnType === \"automatic\"\n\t\t\t\t\t\t\t? { kind: \"automatic\" }\n\t\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\t\tkind: \"llm\",\n\t\t\t\t\t\t\t\t\tmodel: {\n\t\t\t\t\t\t\t\t\t\tprofileId: input.modelProfileId ?? \"fixture-model\",\n\t\t\t\t\t\t\t\t\t\tproviderId: \"fixture-provider\",\n\t\t\t\t\t\t\t\t\t\tmodelId: \"fixture-model\",\n\t\t\t\t\t\t\t\t\t\tthinkingLevel: \"low\",\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tproviderOptions: {},\n\t\t\t\t\t\t\t\t\tproviderWorkerConfig: null,\n\t\t\t\t\t\t\t\t\tpiResourceSnapshotDigest: \"fixture-resource-snapshot\",\n\t\t\t\t\t\t\t\t\tworkerRuntimeProfileId: \"local\",\n\t\t\t\t\t\t\t\t\tpiSettings: {},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\tturnRecordId,\n\t\t\t\t\tacceptedWorkerLeaseId: lease.id,\n\t\t\t\t},\n\t\t\t});\n\t\t\tconst record = createTurnRecord({\n\t\t\t\t...input,\n\t\t\t\tid: turnRecordId,\n\t\t\t\tturnStartRecordId: start.id,\n\t\t\t\tacceptedWorkerLeaseId: lease.id,\n\t\t\t});\n\t\t\tif (isCurrent) {\n\t\t\t\trepos.processes.update(record.instanceId, {\n\t\t\t\t\tcurrentExecution: { kind: \"worker_start\", id: start.id },\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\trepos.leases.update(lease.id, { exitedAt: record.endedAt ?? record.startedAt });\n\t\t\t}\n\t\t\treturn record;\n\t\t}\n\t\treturn createTurnRecord(input);\n\t};\n\treturn {\n\t\tdb,\n\t\t...repos,\n\t\tbroadcaster: createBroadcaster(),\n\t\tprocessModelPolicy,\n\t\tlaunchPlans,\n\t\tgetModelAvailabilitySnapshot,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAgBO,IAAM,wBAAwB;AAK9B,SAAS,yBACf,KACA,OAMA,UAKI,CAAC,GACJ;AACD,MAAI,CAAC,IAAK,OAAM,IAAI,MAAM,gCAAgC;AAC1D,QAAM,EAAE,MAAM,MAAM,IAAI;AACxB,QAAM,UAAU,QAAQ,WAAW,MAAM,WAAW;AACpD,QAAM,QAAQ,MAAM,OAAO,OAAO;AAAA,IACjC,YAAY,MAAM;AAAA,IAClB,UAAU,QAAQ,YAAY,OAAO,MAAM,EAAE;AAAA,IAC7C,OAAO,UAAW,MAAM,WAAW,WAAW,WAAW,SAAU;AAAA,EACpE,CAAC;AACD,QAAM,QAAQ,8BAA8B,KAAK,OAAO,MAAM,IAAI,OAAO;AACzE,QAAM,SAAS,MAAM,YAAY,OAAO;AAAA,IACvC,GAAG;AAAA,IACH,mBAAmB,MAAM;AAAA,IACzB,uBAAuB,MAAM;AAAA,EAC9B,CAAC;AACD,M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AAW;AAAA,QACX,sBAAsB;AAAA,QACtB,cAAc;AAAA,QACd,OAAO;AAAA,UACN,MAAM;AAAA,UACN,OACC,aAAa,cACV,EAAE,MAAM,YAAY,IACpB;AAAA,YACA,MAAM;AAAA,YACN,OAAO;AAAA,cACN,WAAW,MAAM,kBAAkB;AAAA,cACnC,YAAY;AAAA,cACZ,SAAS;AAAA,cACT,eAAe;AAAA,YAChB;AAAA,YACA,iBAAiB,CAAC;AAAA,YAClB,sBAAsB;AAAA,YACtB,0BAA0B;AAAA,YAC1B,wBAAwB;AAAA,YACxB,YAAY,CAAC;AAAA,UACd;AAAA,UACH;AAAA,UACA,uBAAuB,MAAM;AAAA,QAC9B;AAAA,MACD,CAAC;AACD,YAAM,SAAS,iBAAiB;AAAA,QAC/B,GAAG;AAAA,QACH,IAAI;AAAA,QACJ,mBAAmB,MAAM;AAAA,QACzB,uBAAuB,MAAM;AAAA,MAC9B,CAAC;AACD,UAAI,WAAW;AACd,cAAM,UAAU,OAAO,OAAO,YAAY;AAAA,UACzC,kBAAkB,EAAE,MAAM,gBAAgB,IAAI,MAAM,GAAG;AAAA,QACxD,CAAC;AAAA,MACF,OAAO;AACN,cAAM,OAAO,OAAO,MAAM,IAAI,EAAE,UAAU,OAAO,WAAW,OAAO,UAAU,CAAC;AAAA,MAC/E;AACA,aAAO;AAAA,IACR;AACA,WAAO,iBAAiB,KAAK;AAAA,EAC9B;AACA,SAAO;AAAA,IACN;AAAA,IACA,GAAG;AAAA,IACH,aAAa,kBAAkB;AAAA,IAC/B;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;","names":[]}
1
+ {"version":3,"sources":["../src/test-helpers/accepted-turn-start.ts","../src/test-helpers/prepared-fixture-start.ts","../src/test-helpers/session-snapshot-fixtures.ts","../src/test-helpers/process-fixtures.ts","../src/test-helpers/unit-deps.ts"],"sourcesContent":["import type { ResolvedTurnStart } from \"@leitwerk-dev/domain\";\nimport type { AppContext } from \"../app.js\";\n\n/** @internal */\ntype AcceptedTurnRepos = Pick<\n\tAppContext[\"deps\"],\n\t\"processes\" | \"turnRecords\" | \"turnStarts\" | \"leases\"\n>;\n\n/** @internal */\ntype AcceptedTurnContext = {\n\t/** @internal */\n\tdeps: AcceptedTurnRepos;\n};\n\n/** Compatibility name for existing LLM fixtures. @internal */\nexport const createAcceptedLlmTurn = createAcceptedWorkerTurn;\n/** Compatibility name for existing LLM starts. @internal */\nexport const createAcceptedLlmTurnStart = createAcceptedWorkerTurnStart;\n\n/** @internal */\nexport function createAcceptedWorkerTurn(\n\tctx: AcceptedTurnContext | null,\n\tinput: Parameters<AcceptedTurnRepos[\"turnRecords\"][\"create\"]>[0] & {\n\t\t/** @internal */\n\t\tid: string;\n\t\t/** @internal */\n\t\tturnType: \"llm\" | \"automatic\";\n\t},\n\toptions: Parameters<typeof createAcceptedWorkerTurnStart>[3] & {\n\t\t/** @internal */\n\t\tcurrent?: boolean;\n\t\t/** @internal */\n\t\tworkerId?: string;\n\t} = {},\n) {\n\tif (!ctx) throw new Error(\"Server context not initialized\");\n\tconst { deps: repos } = ctx;\n\tconst current = options.current ?? input.status === \"running\";\n\tconst lease = repos.leases.create({\n\t\tinstanceId: input.instanceId,\n\t\tworkerId: options.workerId ?? `wkr_${input.id}`,\n\t\tstate: current ? (input.status === \"failed\" ? \"failed\" : \"busy\") : \"exited\",\n\t});\n\tconst start = createAcceptedWorkerTurnStart(ctx, input, lease.id, options);\n\tconst record = repos.turnRecords.create({\n\t\t...input,\n\t\tturnStartRecordId: start.id,\n\t\tacceptedWorkerLeaseId: lease.id,\n\t});\n\tif (current) {\n\t\trepos.processes.update(input.instanceId, {\n\t\t\tcurrentExecution: { kind: \"worker_start\", id: start.id },\n\t\t});\n\t} else {\n\t\trepos.leases.update(lease.id, {\n\t\t\texitedAt: input.endedAt ?? input.startedAt ?? new Date().toISOString(),\n\t\t});\n\t}\n\treturn record;\n}\n\n/** @internal */\nfunction createAcceptedWorkerTurnStart(\n\tctx: AcceptedTurnContext,\n\tinput: {\n\t\t/** @internal */\n\t\tturnType?: \"llm\" | \"automatic\";\n\t\t/** @internal */\n\t\tid: string;\n\t\t/** @internal */\n\t\tinstanceId: string;\n\t\t/** @internal */\n\t\tturnId: string;\n\t},\n\tacceptedWorkerLeaseId: string,\n\toptions: {\n\t\t/** @internal */\n\t\tid?: string;\n\t\t/** @internal */\n\t\tpreparedStart?: Extract<ResolvedTurnStart, { kind: \"llm\" }>;\n\t\t/** @internal */\n\t\tmodel?: {\n\t\t\t/** @internal */\n\t\t\tprofileId: string;\n\t\t\t/** @internal */\n\t\t\tproviderId: string;\n\t\t\t/** @internal */\n\t\t\tmodelId: string;\n\t\t\t/** @internal */\n\t\t\tthinkingLevel: \"off\";\n\t\t};\n\t\t/** @internal */\n\t\tpiResourceSnapshotDigest?: string;\n\t\t/** @internal */\n\t\tworkerRuntimeProfileId?: string;\n\t} = {},\n) {\n\treturn ctx.deps.turnStarts.create({\n\t\tid: options.id ?? `tsr_${input.id}`,\n\t\tinstanceId: input.instanceId,\n\t\tturnId: input.turnId,\n\t\tturnType: input.turnType ?? \"llm\",\n\t\tproposedTurnRecordId: input.id,\n\t\tstartKind: \"selected_turn\",\n\t\trecoveryTurnRecordId: null,\n\t\tcontinuation: null,\n\t\tstate: {\n\t\t\tkind: \"accepted\",\n\t\t\tstart:\n\t\t\t\tinput.turnType === \"automatic\"\n\t\t\t\t\t? { kind: \"automatic\" }\n\t\t\t\t\t: (options.preparedStart ?? {\n\t\t\t\t\t\t\tkind: \"llm\",\n\t\t\t\t\t\t\tmodel: options.model ?? {\n\t\t\t\t\t\t\t\tprofileId: \"fixture-profile\",\n\t\t\t\t\t\t\t\tproviderId: \"fixture-provider\",\n\t\t\t\t\t\t\t\tmodelId: \"fixture-model\",\n\t\t\t\t\t\t\t\tthinkingLevel: \"off\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tproviderOptions: {},\n\t\t\t\t\t\t\tproviderWorkerConfig: null,\n\t\t\t\t\t\t\tpiResourceSnapshotDigest:\n\t\t\t\t\t\t\t\toptions.piResourceSnapshotDigest ?? \"fixture-resource-digest\",\n\t\t\t\t\t\t\tworkerRuntimeProfileId: options.workerRuntimeProfileId ?? \"local\",\n\t\t\t\t\t\t\tpiSettings: {},\n\t\t\t\t\t\t}),\n\t\t\tturnRecordId: input.id,\n\t\t\tacceptedWorkerLeaseId,\n\t\t},\n\t});\n}\n","import type { ProcessInstance, ResolvedTurnStart } from \"@leitwerk-dev/domain\";\nimport type { ExtensionCatalog } from \"@leitwerk-dev/extension-runtime\";\nimport type { PiResourceBundle } from \"@leitwerk-dev/worker-protocol\";\nimport type { AppContext } from \"../app.js\";\nimport { createPiResourceBundleCache } from \"../pi-resources/index.js\";\nimport { prepareCreatedTurnStarts } from \"../process-engine/turn-start-preflight.js\";\nimport { createWrites, type TurnStartWrite } from \"../process-engine/writes/writes.js\";\n\n/** Prepare fixture resources through the same provider preflight as admitted work. @internal */\nexport async function prepareAcceptedFixtureStart(\n\tctx: AppContext,\n\tprocess: ProcessInstance,\n\tturnId: string,\n\tcontributions: ExtensionCatalog[\"piContributions\"],\n): Promise<{\n\t/** @internal */\n\tstart: Extract<ResolvedTurnStart, { kind: \"llm\" }>;\n\t/** @internal */\n\tbundle: PiResourceBundle;\n}> {\n\tconst profileId =\n\t\tprocess.selectedTurnModelProfileId ??\n\t\tprocess.defaultModelProfileId ??\n\t\tctx.config.process_configs?.[process.processId]?.default_model_profile;\n\tconst write: Extract<TurnStartWrite, { kind: \"create\" }> = {\n\t\tkind: \"create\",\n\t\tinput: {\n\t\t\tinstanceId: process.id,\n\t\t\tturnId,\n\t\t\tturnType: \"llm\",\n\t\t\tproposedTurnRecordId: \"fixture-preflight\",\n\t\t\tstartKind: \"selected_turn\",\n\t\t\trecoveryTurnRecordId: null,\n\t\t\tcontinuation: null,\n\t\t\tstate: {\n\t\t\t\tkind: \"preparation_failed\",\n\t\t\t\trequestedModelProfileId: profileId ?? null,\n\t\t\t\tproviderOptions: {},\n\t\t\t\tcode: \"model_required\",\n\t\t\t\tsafeSummary: \"Fixture preparation\",\n\t\t\t},\n\t\t},\n\t};\n\tconst writes = createWrites({ turnStartWrites: [write] });\n\tconst bundleCache = createPiResourceBundleCache();\n\tconst result = await prepareCreatedTurnStarts(\n\t\t{\n\t\t\tconfig: ctx.config,\n\t\t\tprocessModelPolicy: ctx.deps.processModelPolicy,\n\t\t\tregistry: ctx.modelProviderRegistry,\n\t\t\tmodelStatusCache: ctx.modelStatusCache,\n\t\t\tpiContributions: contributions,\n\t\t\tbundleCache,\n\t\t\tprojects: ctx.deps.projects,\n\t\t\tprocessSkills: ctx.deps.processSkills,\n\t\t},\n\t\t{ ...process, selectedTurnId: turnId, selectedTurnModelProfileId: profileId ?? null },\n\t\twrites,\n\t);\n\tif (!result.ok) throw new Error(`Cannot prepare accepted fixture: ${result.message}`);\n\tconst state = write.input.state;\n\tif (state.kind !== \"starting\" || state.start.kind !== \"llm\") {\n\t\tthrow new Error(\n\t\t\t`Cannot prepare accepted fixture: ${state.kind === \"preparation_failed\" ? state.safeSummary : state.kind}`,\n\t\t);\n\t}\n\tconst bundle = bundleCache.get(state.start.piResourceSnapshotDigest);\n\tif (!bundle) throw new Error(\"Prepared fixture resource bundle is missing\");\n\treturn {\n\t\t/** @internal */\n\t\tstart: state.start,\n\t\t/** @internal */\n\t\tbundle,\n\t};\n}\n","import type { AppContext } from \"../app.js\";\nimport { createAllRepos } from \"../db/repositories.js\";\nimport { createFileBackedProcessSessionSnapshotStore } from \"../process-session-store.js\";\nimport { createProjectedSessionSnapshotStore } from \"../session-summary-projection.js\";\n\n/** Accept fixture snapshots through the same persisted projection as worker uploads. @internal */\nexport async function writeProcessSessionSnapshot(\n\tctx: Pick<AppContext, \"db\" | \"config\">,\n\tinstanceId: string,\n\tentries: readonly unknown[],\n): Promise<void> {\n\tconst store = createProjectedSessionSnapshotStore(\n\t\tcreateFileBackedProcessSessionSnapshotStore(ctx.config.storage.tree_files_dir),\n\t\tcreateAllRepos(ctx.db),\n\t);\n\tawait store.writeSnapshot(\n\t\tinstanceId,\n\t\t`${entries.map((entry) => JSON.stringify(entry)).join(\"\\n\")}\\n`,\n\t);\n}\n","import type { TurnId } from \"@leitwerk-dev/domain\";\nimport {\n\ttype AutomaticTurnDefinition,\n\tautomaticTurn,\n\tdefineProcess,\n\ttype ExtensionProcessDefinition,\n\temptyParamsCodec,\n\ttype HumanTurnDefinition,\n\thumanTurn,\n\ttype LlmTurnDefinition,\n\tllmTurn,\n\ttype TurnDefinition,\n} from \"@leitwerk-dev/process-sdk\";\n\nexport function createFixtureLlmTurn(\n\tdescription: string,\n\toverrides: Partial<LlmTurnDefinition<string, Record<string, never>, Record<string, never>>> = {},\n): LlmTurnDefinition<string, Record<string, never>, Record<string, never>> {\n\treturn llmTurn({\n\t\tavailableTools: [],\n\t\tdescription,\n\t\tbranchType: \"primary\",\n\t\tcontext: \"fresh\",\n\t\tprompt: async () => description,\n\t\tturnEnd: { outcome: \"done\", params: {}, complete: true },\n\t\t...overrides,\n\t});\n}\n\nexport function createFixtureHumanTurn(\n\toverrides: Partial<HumanTurnDefinition<Record<string, never>, Record<string, never>>> = {},\n): HumanTurnDefinition<Record<string, never>, Record<string, never>> {\n\treturn humanTurn({\n\t\tdescription: \"Review\",\n\t\treviewSemanticRef: \"plan\",\n\t\tactions: {\n\t\t\tmark_done: {\n\t\t\t\tlabel: \"Mark done\",\n\t\t\t\tacceptanceState: \"accepted\",\n\t\t\t\tcomplete: true,\n\t\t\t},\n\t\t},\n\t\t...overrides,\n\t});\n}\n\nexport function createFixtureAutomaticTurn(\n\tdescription = \"Automatic turn\",\n): AutomaticTurnDefinition<\"done\", Record<string, never>, Record<string, never>> {\n\treturn automaticTurn<Record<string, never>, Record<string, never>, \"done\">({\n\t\tdescription,\n\t\trun: async () => ({ outcome: \"done\", params: {} }),\n\t\tturnEnd: { outcome: \"done\", params: {}, complete: true },\n\t});\n}\n\nfunction ensureFixtureTurnIsValid(\n\tdefinition: TurnDefinition<Record<string, never>, Record<string, never>>,\n): TurnDefinition<Record<string, never>, Record<string, never>> {\n\tif (definition.kind === \"human\" && Object.keys(definition.actions).length === 0) {\n\t\treturn {\n\t\t\t...definition,\n\t\t\tactions: {\n\t\t\t\t__fixture_noop: { label: \"No-op\", acceptanceState: \"neutral\", complete: true },\n\t\t\t},\n\t\t};\n\t}\n\tif (\n\t\t(definition.kind === \"llm\" || definition.kind === \"automatic\") &&\n\t\tObject.keys(definition.outcomes ?? {}).length === 0 &&\n\t\t!definition.turnEnd\n\t) {\n\t\treturn {\n\t\t\t...definition,\n\t\t\tturnEnd: { outcome: \"done\", params: {}, complete: true },\n\t\t} as TurnDefinition<Record<string, never>, Record<string, never>>;\n\t}\n\treturn definition;\n}\n\nexport function createFixtureProcess(input: {\n\tid: string;\n\tentry: TurnId;\n\talternateEntries?: readonly TurnId[];\n\tturns?: Record<string, TurnDefinition<Record<string, never>, Record<string, never>>>;\n}): ExtensionProcessDefinition<Record<string, never>, Record<string, never>> {\n\tconst turns = input.turns ?? {};\n\tconst entries = [input.entry, ...(input.alternateEntries ?? [])];\n\treturn defineProcess<Record<string, never>, Record<string, never>>({\n\t\tid: input.id,\n\t\tdisplayName: input.id,\n\t\tentry: input.entry,\n\t\t...(input.alternateEntries ? { alternateEntries: input.alternateEntries } : {}),\n\t\tparamsCodec: emptyParamsCodec,\n\t\tstateCodec: emptyParamsCodec,\n\t\tinitialState: () => ({}),\n\t\tturns:\n\t\t\tObject.keys(turns).length > 0\n\t\t\t\t? Object.fromEntries(\n\t\t\t\t\t\tObject.entries(turns).map(([turnId, definition]) => [\n\t\t\t\t\t\t\tturnId,\n\t\t\t\t\t\t\tensureFixtureTurnIsValid(definition),\n\t\t\t\t\t\t]),\n\t\t\t\t\t)\n\t\t\t\t: Object.fromEntries(entries.map((turnId) => [turnId, createFixtureLlmTurn(turnId)])),\n\t});\n}\n\nexport function createProcessGraphRegistry(\n\tprocesses: readonly ExtensionProcessDefinition<unknown, unknown>[],\n): ReadonlyMap<string, ExtensionProcessDefinition<unknown, unknown>> {\n\treturn new Map(\n\t\tprocesses.map(\n\t\t\t(process) => [process.id, process as ExtensionProcessDefinition<unknown, unknown>] as const,\n\t\t),\n\t);\n}\n\nexport function createTurnOwnershipFixtureProcess(\n\tid = \"turn_ownership_process\",\n): ExtensionProcessDefinition<Record<string, never>, Record<string, never>> {\n\treturn createFixtureProcess({\n\t\tid,\n\t\tentry: \"llm_turn\",\n\t\tturns: {\n\t\t\tllm_turn: createFixtureLlmTurn(\"LLM turn\"),\n\t\t\tautomatic_turn: createFixtureAutomaticTurn(),\n\t\t\thuman_turn: createFixtureHumanTurn(),\n\t\t},\n\t});\n}\n\nexport function createDefaultTestProcessGraphRegistry(): ReadonlyMap<\n\tstring,\n\tExtensionProcessDefinition<unknown, unknown>\n> {\n\tconst ticket = createFixtureProcess({\n\t\tid: \"ticket_issue_process\",\n\t\tentry: \"generate_plan\",\n\t\tturns: {\n\t\t\tgenerate_plan: createFixtureLlmTurn(\"generate_plan\", {\n\t\t\t\tresultSemanticRef: \"plan\",\n\t\t\t\tturnEnd: undefined,\n\t\t\t\toutcomes: { plan_saved: { description: \"plan_saved\", parameters: {}, to: \"plan_review\" } },\n\t\t\t}),\n\t\t\tplan_review: createFixtureHumanTurn({\n\t\t\t\treviewSemanticRef: \"plan\",\n\t\t\t\tactions: {\n\t\t\t\t\trevision_requested: {\n\t\t\t\t\t\tlabel: \"Request revision\",\n\t\t\t\t\t\tacceptanceState: \"requires_changes\",\n\t\t\t\t\t\tto: \"generate_plan\",\n\t\t\t\t\t},\n\t\t\t\t\tplan_approved: {\n\t\t\t\t\t\tlabel: \"Approve plan\",\n\t\t\t\t\t\tacceptanceState: \"accepted\",\n\t\t\t\t\t\tto: \"implement\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t\timplement: createFixtureLlmTurn(\"implement\", {\n\t\t\t\tturnEnd: { outcome: \"done\", params: {}, to: \"handoff_review\" },\n\t\t\t}),\n\t\t\thandoff_review: createFixtureLlmTurn(\"handoff_review\", {\n\t\t\t\tturnEnd: { outcome: \"created\", params: {}, to: \"run_llm_review\" },\n\t\t\t}),\n\t\t\trun_llm_review: createFixtureLlmTurn(\"run_llm_review\", {\n\t\t\t\tresultSemanticRef: \"review\",\n\t\t\t\tturnEnd: undefined,\n\t\t\t\toutcomes: {\n\t\t\t\t\tissues_found: { description: \"issues_found\", parameters: {}, to: \"address_review\" },\n\t\t\t\t\tno_issues: { description: \"no_issues\", parameters: {}, to: \"implementation_review\" },\n\t\t\t\t},\n\t\t\t}),\n\t\t\taddress_review: createFixtureLlmTurn(\"address_review\", {\n\t\t\t\tturnEnd: { outcome: \"comments_addressed\", params: {}, to: \"verify_build\" },\n\t\t\t}),\n\t\t\tverify_build: createFixtureLlmTurn(\"verify_build\", {\n\t\t\t\tturnEnd: undefined,\n\t\t\t\toutcomes: {\n\t\t\t\t\tbuild_failing: { description: \"build_failing\", parameters: {}, to: \"fix_build\" },\n\t\t\t\t\tbuild_passing: {\n\t\t\t\t\t\tdescription: \"build_passing\",\n\t\t\t\t\t\tparameters: {},\n\t\t\t\t\t\tto: \"commit_and_complete\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t\tfix_build: createFixtureLlmTurn(\"fix_build\", {\n\t\t\t\tturnEnd: { outcome: \"build_fixed\", params: {}, to: \"verify_build\" },\n\t\t\t}),\n\t\t\tcommit_and_complete: createFixtureLlmTurn(\"commit_and_complete\", {\n\t\t\t\tturnEnd: { outcome: \"committed\", params: {}, to: \"implementation_review\" },\n\t\t\t}),\n\t\t\timplementation_review: createFixtureHumanTurn({\n\t\t\t\treviewSemanticRef: \"review\",\n\t\t\t}),\n\t\t},\n\t});\n\tconst mrPolish = createFixtureProcess({\n\t\tid: \"mr_polish_process\",\n\t\tentry: \"address_review\",\n\t\tturns: {\n\t\t\taddress_review: createFixtureLlmTurn(\"address_review\", {\n\t\t\t\tturnEnd: { outcome: \"comments_addressed\", params: {}, to: \"verify_build\" },\n\t\t\t}),\n\t\t\tverify_build: createFixtureLlmTurn(\"verify_build\", {\n\t\t\t\tturnEnd: undefined,\n\t\t\t\toutcomes: {\n\t\t\t\t\tbuild_failing: { description: \"build_failing\", parameters: {}, to: \"fix_build\" },\n\t\t\t\t\tbuild_passing: {\n\t\t\t\t\t\tdescription: \"build_passing\",\n\t\t\t\t\t\tparameters: {},\n\t\t\t\t\t\tto: \"commit_and_complete\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t\tfix_build: createFixtureLlmTurn(\"fix_build\", {\n\t\t\t\tturnEnd: { outcome: \"build_fixed\", params: {}, to: \"verify_build\" },\n\t\t\t}),\n\t\t\tcommit_and_complete: createFixtureLlmTurn(\"commit_and_complete\", {\n\t\t\t\tturnEnd: { outcome: \"committed\", params: {}, to: \"mr_polish_review\" },\n\t\t\t}),\n\t\t\tmr_polish_review: createFixtureHumanTurn({\n\t\t\t\treviewSemanticRef: \"review\",\n\t\t\t}),\n\t\t},\n\t});\n\treturn createProcessGraphRegistry([\n\t\tticket as ExtensionProcessDefinition<unknown, unknown>,\n\t\tmrPolish as ExtensionProcessDefinition<unknown, unknown>,\n\t]);\n}\n","import type { ProcessLaunchPlanServiceLike } from \"@leitwerk-dev/process-sdk\";\nimport { getDefaultConfig } from \"../config/config-loader.js\";\nimport { createDatabase, createInMemoryDatabase, type LeitwerkDb } from \"../db/database.js\";\nimport { createAllRepos, type RepositoryBundle } from \"../db/repositories.js\";\nimport type { ModelStatusCacheSnapshot } from \"../model-providers/model-status-cache.js\";\nimport {\n\tcreateServerProcessModelPolicy,\n\ttype ServerProcessModelPolicy,\n} from \"../process-model-policy/index.js\";\nimport { type Broadcaster, createBroadcaster } from \"../ws/broadcast.js\";\nimport { createDefaultTestProcessGraphRegistry } from \"./process-fixtures.js\";\n\n/** @internal */\nexport interface TestDeps extends RepositoryBundle {\n\t/** @internal */\n\tdb: LeitwerkDb;\n\t/** @internal */\n\tbroadcaster: Broadcaster;\n\t/** @internal */\n\tprocessModelPolicy: ServerProcessModelPolicy;\n\t/** @internal */\n\tlaunchPlans: ProcessLaunchPlanServiceLike;\n\t/** @internal */\n\tgetModelAvailabilitySnapshot: () => ModelStatusCacheSnapshot;\n}\n\n/** Select a turn-start fixture without creating a turn record or attempt. */\nexport function createSelectedTurnStart(\n\tdeps: TestDeps,\n\tinput: Omit<\n\t\tParameters<TestDeps[\"turnStarts\"][\"create\"]>[0],\n\t\t\"startKind\" | \"recoveryTurnRecordId\" | \"continuation\"\n\t>,\n) {\n\tconst record = deps.turnStarts.create({\n\t\t...input,\n\t\tstartKind: \"selected_turn\",\n\t\trecoveryTurnRecordId: null,\n\t\tcontinuation: null,\n\t});\n\tdeps.processes.update(input.instanceId, {\n\t\tcurrentExecution: { kind: \"worker_start\", id: record.id },\n\t});\n\treturn record;\n}\n\n/** @internal */\nexport function createTestDeps(\n\toptions: {\n\t\t/** @internal */\n\t\tsqlitePath?: string;\n\t} = {},\n): TestDeps {\n\tconst db = options.sqlitePath\n\t\t? createDatabase({ sqlitePath: options.sqlitePath, enableWAL: false })\n\t\t: createInMemoryDatabase();\n\tconst repos = createAllRepos(db);\n\tconst config = getDefaultConfig();\n\tconst processModelPolicy = createServerProcessModelPolicy({\n\t\tconfig,\n\t\tprocessGraphs: createDefaultTestProcessGraphRegistry(),\n\t\tprocessActionRegistry: { getTurnDefinition: () => undefined },\n\t});\n\tconst launchPlans: ProcessLaunchPlanServiceLike = {\n\t\tasync prepare(launchPlan, opts = {}) {\n\t\t\treturn processModelPolicy.prepareLaunchPlan(launchPlan, opts);\n\t\t},\n\t};\n\tconst getModelAvailabilitySnapshot = (): ModelStatusCacheSnapshot => ({\n\t\trevision: 1,\n\t\tcapturedAt: new Date().toISOString(),\n\t\tavailabilityTransitions: [],\n\t\tprofiles: config.pi.model_profiles.map((profile) => ({\n\t\t\tprofileId: profile.id,\n\t\t\tproviderId: profile.provider,\n\t\t\tmodelId: profile.model_id,\n\t\t\tavailability: \"available\",\n\t\t\tcheckedAt: new Date().toISOString(),\n\t\t\texpiresAt: new Date(Date.now() + 60_000).toISOString(),\n\t\t})),\n\t});\n\tconst createTurnRecord = repos.turnRecords.create.bind(repos.turnRecords);\n\trepos.turnRecords.create = (input) => {\n\t\tconst turnType = input.turnType ?? \"llm\";\n\t\tif (\n\t\t\t(turnType === \"llm\" || turnType === \"automatic\") &&\n\t\t\t(!input.turnStartRecordId || !input.acceptedWorkerLeaseId)\n\t\t) {\n\t\t\tconst turnRecordId = input.id ?? `trn_fixture_${crypto.randomUUID()}`;\n\t\t\tconst isCurrent =\n\t\t\t\tinput.status === \"running\" || input.status === \"failed\" || input.status === undefined;\n\t\t\tconst lease = repos.leases.create({\n\t\t\t\tinstanceId: input.instanceId,\n\t\t\t\tworkerId: `wkr_fixture_${turnRecordId}`,\n\t\t\t\tstate: input.status === \"failed\" ? \"failed\" : isCurrent ? \"busy\" : \"exited\",\n\t\t\t});\n\t\t\tconst start = repos.turnStarts.create({\n\t\t\t\tid: `tsr_fixture_${turnRecordId}`,\n\t\t\t\tinstanceId: input.instanceId,\n\t\t\t\tturnId: input.turnId,\n\t\t\t\tturnType,\n\t\t\t\tproposedTurnRecordId: turnRecordId,\n\t\t\t\tstartKind: \"selected_turn\",\n\t\t\t\trecoveryTurnRecordId: null,\n\t\t\t\tcontinuation: null,\n\t\t\t\tstate: {\n\t\t\t\t\tkind: \"accepted\",\n\t\t\t\t\tstart:\n\t\t\t\t\t\tturnType === \"automatic\"\n\t\t\t\t\t\t\t? { kind: \"automatic\" }\n\t\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\t\tkind: \"llm\",\n\t\t\t\t\t\t\t\t\tmodel: {\n\t\t\t\t\t\t\t\t\t\tprofileId: input.modelProfileId ?? \"fixture-model\",\n\t\t\t\t\t\t\t\t\t\tproviderId: \"fixture-provider\",\n\t\t\t\t\t\t\t\t\t\tmodelId: \"fixture-model\",\n\t\t\t\t\t\t\t\t\t\tthinkingLevel: \"low\",\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tproviderOptions: {},\n\t\t\t\t\t\t\t\t\tproviderWorkerConfig: null,\n\t\t\t\t\t\t\t\t\tpiResourceSnapshotDigest: \"fixture-resource-snapshot\",\n\t\t\t\t\t\t\t\t\tworkerRuntimeProfileId: \"local\",\n\t\t\t\t\t\t\t\t\tpiSettings: {},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\tturnRecordId,\n\t\t\t\t\tacceptedWorkerLeaseId: lease.id,\n\t\t\t\t},\n\t\t\t});\n\t\t\tconst record = createTurnRecord({\n\t\t\t\t...input,\n\t\t\t\tid: turnRecordId,\n\t\t\t\tturnStartRecordId: start.id,\n\t\t\t\tacceptedWorkerLeaseId: lease.id,\n\t\t\t});\n\t\t\tif (isCurrent) {\n\t\t\t\trepos.processes.update(record.instanceId, {\n\t\t\t\t\tcurrentExecution: { kind: \"worker_start\", id: start.id },\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\trepos.leases.update(lease.id, { exitedAt: record.endedAt ?? record.startedAt });\n\t\t\t}\n\t\t\treturn record;\n\t\t}\n\t\treturn createTurnRecord(input);\n\t};\n\treturn {\n\t\tdb,\n\t\t...repos,\n\t\tbroadcaster: createBroadcaster(),\n\t\tprocessModelPolicy,\n\t\tlaunchPlans,\n\t\tgetModelAvailabilitySnapshot,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAgBO,IAAM,wBAAwB;AAK9B,SAAS,yBACf,KACA,OAMA,UAKI,CAAC,GACJ;AACD,MAAI,CAAC,IAAK,OAAM,IAAI,MAAM,gCAAgC;AAC1D,QAAM,EAAE,MAAM,MAAM,IAAI;AACxB,QAAM,UAAU,QAAQ,WAAW,MAAM,WAAW;AACpD,QAAM,QAAQ,MAAM,OAAO,OAAO;AAAA,IACjC,YAAY,MAAM;AAAA,IAClB,UAAU,QAAQ,YAAY,OAAO,MAAM,EAAE;AAAA,IAC7C,OAAO,UAAW,MAA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A,IACA;AAAA,EACD;AACD;","names":[]}
@@ -1,6 +1,7 @@
1
1
  import type { Actor, ProcessToolApprovalDestination, ProcessToolApprovalRequest } from "@leitwerk-dev/domain";
2
2
  import type { RepositoryBundle } from "./db/repositories.js";
3
3
  import type { ProcessOperationCoordinator } from "./process-operation-coordinator.js";
4
+ import type { Broadcaster } from "./ws/broadcast.js";
4
5
  /** @internal */
5
6
  export type ToolApprovalDecision = {
6
7
  /** @internal */
@@ -22,6 +23,8 @@ export declare function createToolApprovalGate(input: {
22
23
  repos: ToolApprovalRepos;
23
24
  /** @internal */
24
25
  processOperations: ProcessOperationCoordinator;
26
+ /** @internal */
27
+ broadcaster: Pick<Broadcaster, "sendDurable">;
25
28
  }): {
26
29
  /** @internal */
27
30
  reconcile: (instanceId: string) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"tool-approval-gate.d.ts","sourceRoot":"","sources":["../src/tool-approval-gate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,KAAK,EACL,8BAA8B,EAC9B,0BAA0B,EAC1B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AAEtF,gBAAgB;AAChB,MAAM,MAAM,oBAAoB,GAC7B;IACA,gBAAgB;IAChB,IAAI,EAAE,UAAU,CAAC;CAChB,GACD;IACA,gBAAgB;IAChB,IAAI,EAAE,UAAU,CAAC;IACjB,gBAAgB;IAChB,QAAQ,EAAE,MAAM,CAAC;CAChB,GACD;IACA,gBAAgB;IAChB,IAAI,EAAE,UAAU,CAAC;CAChB,CAAC;AAEL,gBAAgB;AAChB,KAAK,iBAAiB,GAAG,IAAI,CAC5B,gBAAgB,EAChB,WAAW,GAAG,aAAa,GAAG,YAAY,GAAG,sBAAsB,GAAG,aAAa,CACnF,CAAC;AA6BF,gBAAgB;AAChB,wBAAgB,sBAAsB,CAA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turn-progress.d.ts","sourceRoot":"","sources":["../src/turn-progress.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAA0B,MAAM,sBAAsB,CAAC;AAEvF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AA0BrD,wBAAgB,0BAA0B,CACzC,KAAK,EAAE,OAAO,GACZ,WAAW,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,CAyBjD;AAED,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,OAAO,GAAG,kBAAkB,GAAG,IAAI,CAkCrF;AAED,wBAAgB,kBAAkB,CACjC,IAAI,EAAE,IAAI,CAAC,gBAAgB,EAAE,WAAW,GAAG,aAAa,GAAG,QAAQ,CAAC,GAAG;IACtE,WAAW,EAAE,WAAW,CAAC;CACzB,EACD,KAAK,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GAClE,OAAO,CA8BT"}
1
+ {"version":3,"file":"turn-progress.d.ts","sourceRoot":"","sources":["../src/turn-progress.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAA0B,MAAM,sBAAsB,CAAC;AAEvF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AA0BrD,wBAAgB,0BAA0B,CACzC,KAAK,EAAE,OAAO,GACZ,WAAW,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,CAyBjD;AAED,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,OAAO,GAAG,kBAAkB,GAAG,IAAI,CAmCrF;AAED,wBAAgB,kBAAkB,CACjC,IAAI,EAAE,IAAI,CAAC,gBAAgB,EAAE,WAAW,GAAG,aAAa,GAAG,QAAQ,CAAC,GAAG;IACtE,WAAW,EAAE,WAAW,CAAC;CACzB,EACD,KAAK,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GAClE,OAAO,CA8BT"}
@@ -0,0 +1,28 @@
1
+ import { type TurnWaitContext } from "@leitwerk-dev/process-sdk";
2
+ import type { CommitMessageConfig } from "./config/config-types.js";
3
+ import type { RepositoryBundle } from "./db/repositories.js";
4
+ import type { ProcessActionRegistry } from "./process-action-registry.js";
5
+ import type { ProcessEngine } from "./process-engine/types.js";
6
+ import type { ProcessGraphRegistry } from "./process-graph.js";
7
+ interface TurnWaitServiceDeps {
8
+ processes: RepositoryBundle["processes"];
9
+ projects: RepositoryBundle["projects"];
10
+ processGraphs: ProcessGraphRegistry;
11
+ registry: Pick<ProcessActionRegistry, "resolveContextData">;
12
+ commands: ProcessEngine;
13
+ require: TurnWaitContext["require"];
14
+ now?: () => number;
15
+ pollIntervalMs?: number;
16
+ timeoutMs?: number;
17
+ commitMessages?: CommitMessageConfig;
18
+ }
19
+ /** Runs read-only predicates outside lifecycle locks. The engine fences every result. */
20
+ export declare function createTurnWaitService(deps: TurnWaitServiceDeps): {
21
+ check: (instanceId: string) => Promise<void>;
22
+ poll(): Promise<{
23
+ errors: string[];
24
+ }>;
25
+ stop(): Promise<void>;
26
+ };
27
+ export {};
28
+ //# sourceMappingURL=turn-wait-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"turn-wait-service.d.ts","sourceRoot":"","sources":["../src/turn-wait-service.ts"],"names":[],"mappings":"AACA,OAAO,EAGN,KAAK,eAAe,EACpB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAG1E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAG/D,UAAU,mBAAmB;IAC5B,SAAS,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;IACzC,QAAQ,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;IACvC,aAAa,EAAE,oBAAoB,CAAC;IACpC,QAAQ,EAAE,IAAI,CAAC,qBAAqB,EAAE,oBAAoB,CAAC,CAAC;IAC5D,QAAQ,EAAE,aAAa,CAAC;IACxB,OAAO,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;IACpC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,mBAAmB,CAAC;CACrC;AAED,yFAAyF;AACzF,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,mBAAmB;wBA6JnC,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC;;;;;EAyCjD"}
@@ -67,5 +67,7 @@ export declare function buildRuntimeProfileSelectionInput(args: {
67
67
  processId: string;
68
68
  /** @internal */
69
69
  componentKeys: string[];
70
+ /** The registered process definition requires Docker. @internal */
71
+ docker?: boolean;
70
72
  }): RuntimeProfileSelectionInput;
71
73
  //# sourceMappingURL=worker-runtime-profile-selection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"worker-runtime-profile-selection.d.ts","sourceRoot":"","sources":["../src/worker-runtime-profile-selection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAC9E,OAAO,KAAK,EAAE,cAAc,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AAE3F;;;GAGG;AACH,gBAAgB;AAChB,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C;IACvB,gBAAgB;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB;IAChB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,mEAAmE;IACnE,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB,GAAG,4BAA4B,CAkB/B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leitwerk-dev/server",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/leitwerk-dev/leitwerk.git",
@@ -24,31 +24,32 @@
24
24
  "start": "node dist/main.js"
25
25
  },
26
26
  "dependencies": {
27
- "@earendil-works/pi-ai": "^0.81.1",
28
- "@earendil-works/pi-coding-agent": "^0.81.1",
29
- "@fastify/cookie": "11.0.2",
27
+ "@earendil-works/pi-ai": "^0.87.0",
28
+ "@earendil-works/pi-coding-agent": "^0.87.0",
29
+ "@fastify/cookie": "11.1.2",
30
30
  "@fastify/websocket": "^11.2.0",
31
- "@leitwerk-dev/domain": "0.3.1",
32
- "@leitwerk-dev/extension-runtime": "0.3.1",
33
- "@leitwerk-dev/external-writes": "0.3.1",
34
- "@leitwerk-dev/process-sdk": "0.3.1",
35
- "@leitwerk-dev/protocol": "0.3.1",
36
- "@leitwerk-dev/session-transfer": "0.3.1",
37
- "@leitwerk-dev/watcher-utils": "0.3.1",
38
- "@leitwerk-dev/worker-protocol": "0.3.1",
39
- "@leitwerk-dev/worker-runners": "0.3.1",
31
+ "@leitwerk-dev/domain": "0.4.0",
32
+ "@leitwerk-dev/extension-runtime": "0.4.0",
33
+ "@leitwerk-dev/external-writes": "0.4.0",
34
+ "@leitwerk-dev/process-sdk": "0.4.0",
35
+ "@leitwerk-dev/protocol": "0.4.0",
36
+ "@leitwerk-dev/session-transfer": "0.4.0",
37
+ "@leitwerk-dev/watcher-utils": "0.4.0",
38
+ "@leitwerk-dev/worker-protocol": "0.4.0",
39
+ "@leitwerk-dev/worker-runners": "0.4.0",
40
40
  "cron-parser": "^5.5.0",
41
41
  "defu": "^6.1.7",
42
- "drizzle-orm": "1.0.0-rc.4",
43
- "esbuild": "0.28.1",
42
+ "drizzle-orm": "1.0.0-rc.5-ab785fc",
43
+ "esbuild": "0.28.2",
44
44
  "fastify": "^5.8.4",
45
- "openid-client": "6.8.4",
46
- "sharp": "^0.34.5",
45
+ "openid-client": "6.8.8",
46
+ "sharp": "^0.35.0",
47
47
  "valibot": "^1.3.1",
48
- "yaml": "^2.8.3"
48
+ "yaml": "^2.8.3",
49
+ "@leitwerk-dev/wiki": "0.4.0"
49
50
  },
50
51
  "optionalDependencies": {
51
- "@leitwerk-dev/worker": "0.3.1"
52
+ "@leitwerk-dev/worker": "0.4.0"
52
53
  },
53
54
  "devDependencies": {
54
55
  "tsup": "^8.5.1",
package/src/app.ts CHANGED
@@ -14,9 +14,12 @@ import type {
14
14
  ProvidedCapability,
15
15
  ServerExtensionEventMap,
16
16
  } from "@leitwerk-dev/process-sdk";
17
+ import { scopedSettingsCapability } from "@leitwerk-dev/process-sdk";
17
18
  import type { ModelProfileSnapshot } from "@leitwerk-dev/protocol";
18
19
  import { DEFAULT_SESSION_TRANSFER_LIMITS } from "@leitwerk-dev/session-transfer";
19
20
  import { createPollingCoordinator, parseDurationMs } from "@leitwerk-dev/watcher-utils";
21
+ import { topicWikiCapability } from "@leitwerk-dev/wiki/integration";
22
+ import { createTopicWikiRepo, registerWikiTools } from "@leitwerk-dev/wiki/server";
20
23
  import {
21
24
  cleanupRetainedProcessVolumes,
22
25
  type ProcessStateExporter,
@@ -105,6 +108,7 @@ import {
105
108
  import { RepositoryCredentialService } from "./repository-credentials/service.js";
106
109
  import { ResultImageStore } from "./result-image-store.js";
107
110
  import type { RouteDeps } from "./routes/processes.js";
111
+ import { createScopedSettingsService } from "./scoped-settings-service.js";
108
112
  import { collectCleanupErrors, createAppLifecycle } from "./server-bootstrap/app-lifecycle.js";
109
113
  import { buildHostCapabilities } from "./server-bootstrap/build-host-capabilities.js";
110
114
  import { loadServerExtensionCatalog } from "./server-bootstrap/load-extension-catalog.js";
@@ -114,7 +118,9 @@ import { resolveServerTlsOptions } from "./server-topology.js";
114
118
  import { createProjectedSessionSnapshotStore } from "./session-summary-projection.js";
115
119
  import { createSessionTransferHelperRelays } from "./session-transfer-helper-relays.js";
116
120
  import { createSessionTransferService } from "./session-transfer-service.js";
121
+ import { importBundledSkills } from "./skills/bundled-skills.js";
117
122
  import { createSkillCatalogService } from "./skills/catalog-service.js";
123
+ import { importExtensionSkills } from "./skills/extension-importer.js";
118
124
  import { createDiagnosticTraceWriter } from "./supervisor/diagnostic-trace-writer.js";
119
125
  import { createIpcHandler, type IpcHandler } from "./supervisor/ipc-handler.js";
120
126
  import { startStaleHeartbeatWatchdog } from "./supervisor/stale-heartbeat-watchdog.js";
@@ -124,11 +130,22 @@ import {
124
130
  type WorkerWebSocketIpcManager,
125
131
  } from "./supervisor/worker-websocket-ipc.js";
126
132
  import { createToolApprovalGate } from "./tool-approval-gate.js";
133
+ import { recordTurnProgress } from "./turn-progress.js";
134
+ import { createTurnWaitService } from "./turn-wait-service.js";
127
135
  import { defaultWorkerRuntimeProfile } from "./worker-runtime-profile-selection.js";
128
136
  import { type Broadcaster, createBroadcaster } from "./ws/broadcast.js";
129
137
 
130
138
  /** @public */
131
139
  export interface AppOptions {
140
+ /** Clock and cadence seam for readiness integration tests. @internal */
141
+ turnWait?: {
142
+ /** @internal */
143
+ now?: () => number;
144
+ /** @internal */
145
+ pollIntervalMs?: number;
146
+ /** @internal */
147
+ timeoutMs?: number;
148
+ };
132
149
  /** @public */
133
150
  config?: LeitwerkConfig;
134
151
  /** @internal */
@@ -243,6 +260,11 @@ async function createConfiguredWorkerRunnerRuntime(input: {
243
260
  provided?: AppOptions["workerRunnerRuntime"];
244
261
  helperRelays: ProcessStateExportHelperRelayProvider;
245
262
  onVolumePoolError: () => void;
263
+ onImagePreparationEvent: NonNullable<
264
+ Parameters<
265
+ typeof import("@leitwerk-dev/worker-runners/kubernetes").createKubernetesWorkerRunner
266
+ >[0]["imagePreload"]
267
+ >["onEvent"];
246
268
  localWorkerSpawnImpl?: AppOptions["localWorkerSpawnImpl"];
247
269
  localWorkerDockerPreflightImpl?: AppOptions["localWorkerDockerPreflightImpl"];
248
270
  }): Promise<{
@@ -250,7 +272,7 @@ async function createConfiguredWorkerRunnerRuntime(input: {
250
272
  volume?: ProcessVolume;
251
273
  exporter: ProcessStateExporter;
252
274
  webSocketIpc: WorkerWebSocketIpcManager;
253
- volumePool?: { start(): void; stop(): Promise<void> };
275
+ preparation?: { start(): void; stop(): Promise<void> };
254
276
  }> {
255
277
  if (input.provided) {
256
278
  return {
@@ -289,6 +311,14 @@ async function createConfiguredWorkerRunnerRuntime(input: {
289
311
  preProvision: processVolume?.pre_provision
290
312
  ? { ...processVolume.pre_provision, onError: input.onVolumePoolError }
291
313
  : undefined,
314
+ imagePreload: input.config.kubernetes?.image_preload?.enabled
315
+ ? {
316
+ images: Object.values(input.config.worker_runtime_profiles ?? {}).map(
317
+ (profile) => profile.image,
318
+ ),
319
+ onEvent: input.onImagePreparationEvent,
320
+ }
321
+ : undefined,
292
322
  processNamespacePrefix:
293
323
  input.config.kubernetes?.process_namespace_prefix ?? "leitwerk-process-",
294
324
  volume: {
@@ -421,7 +451,9 @@ export async function createAppContext(opts: AppOptions = {}): Promise<AppContex
421
451
  const repos = createAllRepos(db, {
422
452
  ...(credentialCipher ? { credentialCipher } : {}),
423
453
  });
454
+ const extensionSkills = await importExtensionSkills(extensionCatalog.modules);
424
455
  repos.transaction((transactionRepos) => {
456
+ transactionRepos.skills.reconcileExtensions(extensionSkills);
425
457
  // Directly configured skills are no longer supported. Deactivate any left by an older release.
426
458
  transactionRepos.skills.reconcile([]);
427
459
  transactionRepos.skills.backfillDependencies();
@@ -429,6 +461,7 @@ export async function createAppContext(opts: AppOptions = {}): Promise<AppContex
429
461
  const skillCatalog = createSkillCatalogService({
430
462
  repositories: config.skill_repositories ?? [],
431
463
  repos,
464
+ bundledSkills: await importBundledSkills(extensionCatalog.piContributions),
432
465
  });
433
466
  await skillCatalog.refresh();
434
467
  markStartup("skill_catalog");
@@ -467,12 +500,34 @@ export async function createAppContext(opts: AppOptions = {}): Promise<AppContex
467
500
  markStartup("model_providers");
468
501
 
469
502
  const broadcaster = createBroadcaster();
503
+ repos.topicWiki = createTopicWikiRepo(db, (topicId) =>
504
+ broadcaster.sendDurable("wiki.updated", { topicId }),
505
+ );
470
506
  const processOperations = createProcessOperationCoordinator();
471
507
  const processGraphs = extensionCatalog.processes;
472
508
  const processActionRegistry = buildProcessActionRegistry(extensionCatalog);
473
509
  const integrationTools = new IntegrationToolRegistry(repos.externalWrites);
474
510
  const processUiRegistry = buildProcessUiRegistry(extensionCatalog);
511
+ const scopedSettings = createScopedSettingsService({
512
+ repos,
513
+ catalog: extensionCatalog,
514
+ config,
515
+ modelChoices: () =>
516
+ config.pi.model_profiles.map((profile) => {
517
+ const status = modelStatusCache
518
+ .snapshot()
519
+ .profiles.find((entry) => entry.profileId === profile.id);
520
+ return {
521
+ value: profile.id,
522
+ label: `${profile.id} — ${profile.provider}/${profile.model_id}`,
523
+ ...(status?.availability === "available"
524
+ ? {}
525
+ : { disabledReason: status?.safeReason ?? "Model unavailable" }),
526
+ };
527
+ }),
528
+ });
475
529
  const processModelPolicy = createServerProcessModelPolicy({
530
+ scopedSettings,
476
531
  config,
477
532
  processGraphs,
478
533
  processActionRegistry,
@@ -590,6 +645,7 @@ export async function createAppContext(opts: AppOptions = {}): Promise<AppContex
590
645
  },
591
646
  };
592
647
  const launcherModelConfigs = createLauncherModelConfigService({
648
+ scopedSettingsService: scopedSettings,
593
649
  launcherService,
594
650
  launchPlans,
595
651
  processModelPolicy,
@@ -737,6 +793,7 @@ export async function createAppContext(opts: AppOptions = {}): Promise<AppContex
737
793
  processModelPolicy,
738
794
  getModelAvailabilitySnapshot: () => modelStatusCache.snapshot(),
739
795
  afterRecord(process) {
796
+ invalidateExternalSourceArmings?.(process.id);
740
797
  // The process volume is the durable source for an already-created start.
741
798
  // A missing server-cache entry is valid after restart.
742
799
  piResourceBundlePins.reconcile(process);
@@ -749,11 +806,15 @@ export async function createAppContext(opts: AppOptions = {}): Promise<AppContex
749
806
  {
750
807
  config,
751
808
  registry: modelProviderRegistry,
809
+ processActionRegistry,
810
+ mappedRuns: baseDeps.mappedRuns,
752
811
  modelStatusCache,
753
812
  piContributions: extensionCatalog.piContributions,
754
813
  bundleCache: piResourceBundles,
755
814
  projects: baseDeps.projects,
756
815
  processSkills: baseDeps.processSkills,
816
+ scopedSettings,
817
+ processModelPolicy,
757
818
  },
758
819
  process,
759
820
  writes,
@@ -783,18 +844,23 @@ export async function createAppContext(opts: AppOptions = {}): Promise<AppContex
783
844
  const toolApprovalGate = createToolApprovalGate({
784
845
  repos: baseDeps,
785
846
  processOperations,
847
+ broadcaster,
786
848
  });
787
849
  const integrationToolRequests = createIntegrationToolRequestService({
788
850
  registry: integrationTools,
789
851
  repos: baseDeps,
790
852
  processActionRegistry,
791
853
  toolApprovalGate,
854
+ reportProgress: (report) => {
855
+ recordTurnProgress(baseDeps, report);
856
+ },
792
857
  });
793
858
  const diagnosticTraceWriter = createDiagnosticTraceWriter(
794
859
  path.join(config.storage.tree_files_dir, "diagnostic-traces"),
795
860
  );
796
861
  const ipcHandler = createIpcHandler(
797
862
  {
863
+ executionInspections: baseDeps.executionInspections,
798
864
  startupObservations: baseDeps.startupObservations,
799
865
  processes: baseDeps.processes,
800
866
  getLaunchCoordinator: () => launchCoordinator,
@@ -901,15 +967,20 @@ export async function createAppContext(opts: AppOptions = {}): Promise<AppContex
901
967
  helperRelays: sessionTransferHelperRelays,
902
968
  onVolumePoolError: () =>
903
969
  app.log.warn("Volume pre-provisioning failed; retrying in the background"),
970
+ onImagePreparationEvent: (event) => {
971
+ if (event.outcome === "succeeded") app.log.info(event, "Worker image prepared");
972
+ else app.log.warn(event, "Worker image preparation failed; retrying in the background");
973
+ },
904
974
  localWorkerSpawnImpl: opts.localWorkerSpawnImpl,
905
975
  localWorkerDockerPreflightImpl: opts.localWorkerDockerPreflightImpl,
906
976
  });
907
- if (runnerRuntime.volumePool) {
908
- startHooks.push(() => runnerRuntime.volumePool?.start());
909
- stopHooks.push(() => runnerRuntime.volumePool?.stop());
977
+ if (runnerRuntime.preparation) {
978
+ startHooks.push(() => runnerRuntime.preparation?.start());
979
+ stopHooks.push(() => runnerRuntime.preparation?.stop());
910
980
  }
911
981
  markStartup("worker_runner");
912
982
  supervisor = createWorkerSupervisor({
983
+ executionInspections: baseDeps.executionInspections,
913
984
  startupObservations: baseDeps.startupObservations,
914
985
  config: supervisorConfig,
915
986
  processGraphs,
@@ -1045,6 +1116,7 @@ export async function createAppContext(opts: AppOptions = {}): Promise<AppContex
1045
1116
  );
1046
1117
  const processLaunchDeps = {
1047
1118
  ...baseDeps,
1119
+ skillDefaults: config,
1048
1120
  broadcaster,
1049
1121
  commands: processEngine,
1050
1122
  processTitles,
@@ -1056,6 +1128,7 @@ export async function createAppContext(opts: AppOptions = {}): Promise<AppContex
1056
1128
  };
1057
1129
  const createProcess = createProcessFromLaunchPlan.bind(null, processLaunchDeps);
1058
1130
  futureExecutionLifecycle = createFutureExecutionLifecycle({
1131
+ skillDefaults: config,
1059
1132
  futureExecutions: baseDeps.futureExecutions,
1060
1133
  processes: baseDeps.processes,
1061
1134
  projects: baseDeps.projects,
@@ -1187,6 +1260,7 @@ export async function createAppContext(opts: AppOptions = {}): Promise<AppContex
1187
1260
  modelStatusCache,
1188
1261
  });
1189
1262
  const hostCapabilities = buildHostCapabilities({
1263
+ integrationTools,
1190
1264
  config,
1191
1265
  baseDeps,
1192
1266
  projectMutations,
@@ -1211,6 +1285,33 @@ export async function createAppContext(opts: AppOptions = {}): Promise<AppContex
1211
1285
  preProvidedCapabilities: opts.preProvidedCapabilities,
1212
1286
  });
1213
1287
 
1288
+ hostCapabilities.provide(scopedSettingsCapability, scopedSettings);
1289
+ const turnWaitService = createTurnWaitService({
1290
+ commitMessages: config.commit_messages,
1291
+ processes: baseDeps.processes,
1292
+ projects: baseDeps.projects,
1293
+ processGraphs,
1294
+ registry: processActionRegistry,
1295
+ commands: processEngine,
1296
+ require: hostCapabilities.require.bind(hostCapabilities),
1297
+ ...opts.turnWait,
1298
+ });
1299
+ polling.create({
1300
+ id: "turn-readiness",
1301
+ pollOnce: turnWaitService.poll,
1302
+ isEnabled: () => true,
1303
+ pollInterval: () => "1s",
1304
+ defaultIntervalMs: 1000,
1305
+ });
1306
+ afterSuccessHooks.add((instanceId) => {
1307
+ // Resolving readiness invokes this hook again; never await our own check.
1308
+ void turnWaitService.check(instanceId).catch((error: unknown) => {
1309
+ app.log.error({ err: error, instanceId }, "Turn readiness check failed");
1310
+ });
1311
+ });
1312
+ const wiki = hostCapabilities.require(topicWikiCapability);
1313
+ if (Array.isArray(wiki)) throw new Error("Wiki integration must be singular");
1314
+ registerWikiTools({ tool: (definition) => integrationTools.register(definition) }, wiki);
1214
1315
  await setupServerExtensions(
1215
1316
  extensionCatalog,
1216
1317
  {
@@ -1231,7 +1332,10 @@ export async function createAppContext(opts: AppOptions = {}): Promise<AppContex
1231
1332
  );
1232
1333
  integrationTools.validateTicketProcesses(extensionCatalog.processes);
1233
1334
  startHooks.push(() => polling.start());
1234
- stopHooks.push(() => polling.stop());
1335
+ stopHooks.push(async () => {
1336
+ await turnWaitService.stop();
1337
+ await polling.stop();
1338
+ });
1235
1339
  for (const process of extensionCatalog.processes.values()) {
1236
1340
  for (const [turnId, binding] of process.turns) {
1237
1341
  const definition = binding.definition;
@@ -1248,6 +1352,12 @@ export async function createAppContext(opts: AppOptions = {}): Promise<AppContex
1248
1352
  markStartup("server_extensions");
1249
1353
 
1250
1354
  const deps: RouteDeps = {
1355
+ onSettingsChanged: async () => {
1356
+ await futureExecutionLifecycle.reconcileModelAvailability({
1357
+ availability: modelStatusCache.snapshot(),
1358
+ });
1359
+ },
1360
+ scopedSettingsService: scopedSettings,
1251
1361
  externalSourceService,
1252
1362
  ...baseDeps,
1253
1363
  launchCoordinator,
@@ -2,16 +2,25 @@ import { type Actor, ADMIN_ACTOR } from "@leitwerk-dev/domain";
2
2
  import type { FastifyReply, FastifyRequest } from "fastify";
3
3
  import type { AuthService } from "./auth-service.js";
4
4
 
5
+ /** @internal */
5
6
  export interface TokenAuditContext {
7
+ /** @internal */
6
8
  operation: string;
9
+ /** @internal */
7
10
  tokenId?: string;
11
+ /** @internal */
8
12
  actor?: Actor;
13
+ /** @internal */
9
14
  ownerKind?: "user" | "anonymous";
15
+ /** @internal */
10
16
  count?: number;
11
17
  }
12
18
  declare module "fastify" {
19
+ /** @internal */
13
20
  interface FastifyRequest {
21
+ /** @internal */
14
22
  actor?: Actor;
23
+ /** @internal */
15
24
  tokenAudit?: TokenAuditContext;
16
25
  }
17
26
  }
@@ -57,9 +66,13 @@ export function authenticateRequest(auth: AuthService, request: FastifyRequest):
57
66
  const result = auth.apiTokens.resolve(match[1]);
58
67
  if (result.token) {
59
68
  request.tokenAudit = {
69
+ /** @internal */
60
70
  operation: "bearer_request",
71
+ /** @internal */
61
72
  tokenId: result.token.id,
73
+ /** @internal */
62
74
  actor: result.token.owner.actor,
75
+ /** @internal */
63
76
  ownerKind: result.token.owner.kind,
64
77
  };
65
78
  }