@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
@@ -14,8 +14,10 @@ import {
14
14
  type ProvidedCapability,
15
15
  type RegisteredProcessWatcherLike,
16
16
  } from "@leitwerk-dev/process-sdk";
17
+ import { createWikiIntegration, topicWikiCapability } from "@leitwerk-dev/wiki/integration";
17
18
  import type { LeitwerkConfig } from "../config/index.js";
18
19
  import type { RepositoryBundle } from "../db/repositories.js";
20
+ import type { IntegrationToolRegistry } from "../integration-tool-registry.js";
19
21
  import type { LaunchCoordinator } from "../launch-coordinator.js";
20
22
  import type { ProcessEngine } from "../process-engine/types.js";
21
23
  import type { ProjectMutationService } from "../project-mutation-service.js";
@@ -28,6 +30,7 @@ export function buildHostCapabilities(input: {
28
30
  baseDeps: RepositoryBundle & { broadcaster: Broadcaster };
29
31
  projectMutations: ProjectMutationService;
30
32
  commands: ProcessEngine;
33
+ integrationTools: IntegrationToolRegistry;
31
34
  getSupervisor: () => WorkerSupervisor | undefined;
32
35
  listVisibleActionsForProcess: (instanceId: string) => readonly ProcessActionSummaryLike[];
33
36
  launcherService: unknown;
@@ -45,9 +48,47 @@ export function buildHostCapabilities(input: {
45
48
  preProvidedCapabilities?: readonly ProvidedCapability[];
46
49
  }) {
47
50
  const hostCapabilities = createCapabilityAccessor([
51
+ { token: topicWikiCapability, value: createWikiIntegration(input.baseDeps.topicWiki) },
48
52
  {
49
53
  token: coreHostCapabilities.serverSetup,
50
54
  value: {
55
+ async callIntegrationTool(
56
+ expected: import("@leitwerk-dev/domain").ProcessInstance,
57
+ projectKey: string,
58
+ name: string,
59
+ args: Record<string, unknown>,
60
+ signal: AbortSignal,
61
+ ) {
62
+ const process = input.baseDeps.processes.getById(expected.id);
63
+ if (
64
+ !process ||
65
+ process.lifecycleStatus !== expected.lifecycleStatus ||
66
+ process.selectedTurnId !== expected.selectedTurnId ||
67
+ process.paramsJson !== expected.paramsJson ||
68
+ process.stateJson !== expected.stateJson ||
69
+ process.planRevision !== expected.planRevision
70
+ )
71
+ throw new Error("Process changed before maintenance delivery");
72
+ const projects = input.baseDeps.projects.listByInstance(process.id);
73
+ const project = projects.find((candidate) => candidate.key === projectKey);
74
+ const turn = input.baseDeps.turnRecords.listByInstance(process.id).at(-1);
75
+ if (!project || !turn)
76
+ throw new Error(
77
+ "Maintenance delivery requires a bound project and publication history",
78
+ );
79
+ return input.integrationTools.executeServer(
80
+ name,
81
+ { ...args, projectKey },
82
+ {
83
+ process,
84
+ projects,
85
+ project,
86
+ turn,
87
+ idempotencyKey: `maintenance:${process.id}:${projectKey}:${name}`,
88
+ },
89
+ signal,
90
+ );
91
+ },
51
92
  get serverBaseUrl() {
52
93
  return input.config.server.base_url;
53
94
  },
@@ -56,6 +97,7 @@ export function buildHostCapabilities(input: {
56
97
  },
57
98
  components: input.config.components,
58
99
  externalWrites: input.baseDeps.externalWrites,
100
+ publications: input.baseDeps.publications,
59
101
  processes: input.baseDeps.processes,
60
102
  projects: input.projectMutations,
61
103
  events: input.baseDeps.events,
@@ -1,7 +1,8 @@
1
+ import { registerTopicWikiRoutes } from "@leitwerk-dev/wiki/server";
1
2
  import type { FastifyInstance } from "fastify";
2
3
  import { registerApiTokenAudit } from "../auth/api-token-audit.js";
3
4
  import type { AuthService } from "../auth/auth-service.js";
4
- import { requireApiActor } from "../auth/fastify-auth.js";
5
+ import { actorForRequest, requireApiActor } from "../auth/fastify-auth.js";
5
6
  import { registerAuthRoutes } from "../auth/routes.js";
6
7
  import type { ExtensionUiCatalog } from "../extension-ui/catalog.js";
7
8
  import type { IntegrationToolRegistry } from "../integration-tool-registry.js";
@@ -11,6 +12,7 @@ import { registerInternalSessionTransferExportRoutes } from "../routes/internal-
11
12
  import { registerInternalWorkerSessionSnapshotRoutes } from "../routes/internal-worker-session-snapshot.js";
12
13
  import { type RouteDeps, registerProcessRoutes } from "../routes/processes.js";
13
14
  import { registerResultImageRoutes } from "../routes/result-images.js";
15
+ import { registerSettingsRoutes } from "../routes/settings.js";
14
16
  import { registerSkillRoutes } from "../routes/skills.js";
15
17
  import { registerTicketCreationRoutes } from "../routes/ticket-creation.js";
16
18
  import { registerUiRendererRoutes } from "../routes/ui-renderers.js";
@@ -74,6 +76,10 @@ export function registerHttp(input: {
74
76
  store: input.resultImages,
75
77
  });
76
78
  registerProcessRoutes(input.app, input.deps);
79
+ if (input.deps.topicWiki)
80
+ registerTopicWikiRoutes(input.app, input.deps.topicWiki, actorForRequest);
81
+ if (input.deps.scopedSettingsService)
82
+ registerSettingsRoutes(input.app, input.deps.scopedSettingsService, input.deps);
77
83
  registerWatcherRoutes(input.app, { processWatchers: input.processWatcherService });
78
84
  registerTicketCreationRoutes(input.app, input.deps, input.integrationTools);
79
85
  if (input.deps.skillCatalog) {
@@ -90,8 +90,7 @@ export function createProjectedSessionSnapshotStore(
90
90
  },
91
91
  backfill(instanceId: string) {
92
92
  return serial(instanceId, async () => {
93
- for (const turn of repos.turnRecords.listByInstance(instanceId)) {
94
- if (repos.turnSummaries.get(turn.id)) continue;
93
+ for (const turn of repos.turnRecords.listMissingSummaries(instanceId)) {
95
94
  let summary = emptyCompactTurnSummary();
96
95
  for (const event of repos.events.listByTurnRecord(instanceId, turn.id)) {
97
96
  summary = applyEventToCompactTurnSummary(summary, {
@@ -0,0 +1,64 @@
1
+ import path from "node:path";
2
+ import type { CatalogPiContribution } from "@leitwerk-dev/extension-runtime";
3
+ import type { InstalledSkillCatalogDetail } from "@leitwerk-dev/protocol";
4
+ import { createCanonicalPiResourceBundle } from "@leitwerk-dev/worker-protocol";
5
+ import { ResourceCollector } from "../pi-resources/resource-collector.js";
6
+ import { isSkillModelInvocable, skillMetadata } from "./skill-frontmatter.js";
7
+ import { SAFE_SKILL_ID_PATTERN } from "./skill-id.js";
8
+
9
+ /** Read the same declared skill directories used by worker snapshots. @internal */
10
+ export async function importBundledSkills(
11
+ contributions: readonly CatalogPiContribution[],
12
+ ): Promise<InstalledSkillCatalogDetail[]> {
13
+ const skills = new Map<string, InstalledSkillCatalogDetail>();
14
+ const collector = new ResourceCollector();
15
+ for (const contribution of contributions) {
16
+ for (const directory of contribution.resources.skillDirectories) {
17
+ await collector.addDirectory(directory, "skills", {
18
+ kind: "skill",
19
+ ownerExtensionId: contribution.ownerExtensionId,
20
+ packageName: contribution.packageName,
21
+ });
22
+ }
23
+ }
24
+ const files = collector.toResourceFiles();
25
+ for (const file of files) {
26
+ if (!file.path.endsWith("/SKILL.md")) continue;
27
+ const skillRoot = path.posix.dirname(file.path);
28
+ const skillId = path.posix.basename(skillRoot);
29
+ if (!SAFE_SKILL_ID_PATTERN.test(skillId)) {
30
+ throw new Error(`Bundled skill has an invalid id '${skillId}' at '${file.path}'`);
31
+ }
32
+ if (skills.has(skillId)) throw new Error(`Duplicate bundled skill id '${skillId}'`);
33
+ const skillMarkdown = Buffer.from(file.content).toString("utf8");
34
+ const metadata = skillMetadata(skillMarkdown);
35
+ const sourceExtensionId = collector.provenance.find(
36
+ (source) => source.snapshotPath === file.path,
37
+ )?.ownerExtensionId;
38
+ const bundle = createCanonicalPiResourceBundle(
39
+ files.filter((candidate) => candidate.path.startsWith(`${skillRoot}/`)),
40
+ );
41
+ skills.set(skillId, {
42
+ id: skillId,
43
+ label: metadata.name ?? skillId,
44
+ description: metadata.description,
45
+ registrationKind: "bundled",
46
+ ...(sourceExtensionId ? { sourceExtensionId } : {}),
47
+ activeRevisionId: bundle.digest,
48
+ activeSourceRevision: null,
49
+ sourceRepositoryId: null,
50
+ updateAvailable: false,
51
+ modelInvocable: isSkillModelInvocable(skillMarkdown),
52
+ usage: {
53
+ attachedAllTime: 0,
54
+ attachedLast30Days: 0,
55
+ invokedAllTime: 0,
56
+ invokedLast30Days: 0,
57
+ },
58
+ skillMarkdown,
59
+ processes: [],
60
+ revisions: [],
61
+ });
62
+ }
63
+ return [...skills.values()];
64
+ }
@@ -27,9 +27,16 @@ export interface SkillCatalogService {
27
27
  export function createSkillCatalogService(input: {
28
28
  repositories: readonly SkillRepositoryConfig[];
29
29
  repos: RepositoryBundle;
30
+ bundledSkills?: readonly InstalledSkillCatalogDetail[];
30
31
  importRepository?: typeof importSkillRepository;
31
32
  }): SkillCatalogService {
32
33
  const importRepository = input.importRepository ?? importSkillRepository;
34
+ const bundledSkills = new Map((input.bundledSkills ?? []).map((skill) => [skill.id, skill]));
35
+ for (const skill of input.repos.skills.listAvailable()) {
36
+ if (bundledSkills.has(skill.id)) {
37
+ throw new Error(`Bundled skill '${skill.id}' conflicts with an installed skill`);
38
+ }
39
+ }
33
40
  const statuses = new Map<string, { lastRefreshedAt: string | null; error: string | null }>();
34
41
  let refreshPromise: Promise<SkillsCatalogResponseBody> | null = null;
35
42
  input.repos.transaction((repos) =>
@@ -52,10 +59,25 @@ export function createSkillCatalogService(input: {
52
59
  };
53
60
  });
54
61
 
55
- const list = (): SkillsCatalogResponseBody => ({
56
- repositories: summaries(),
57
- ...input.repos.skills.catalog(),
58
- });
62
+ const list = (): SkillsCatalogResponseBody => {
63
+ const catalog = input.repos.skills.catalog();
64
+ return {
65
+ repositories: summaries(),
66
+ availableSkills: catalog.availableSkills.map((skill) =>
67
+ bundledSkills.has(skill.id)
68
+ ? { ...skill, conflict: !skill.stale, registered: false, updateAvailable: false }
69
+ : skill,
70
+ ),
71
+ installedSkills: [
72
+ ...catalog.installedSkills,
73
+ ...[...bundledSkills.values()].map(
74
+ ({ skillMarkdown, processes, revisions, ...skill }) => skill,
75
+ ),
76
+ ].sort(
77
+ (left, right) => left.label.localeCompare(right.label) || left.id.localeCompare(right.id),
78
+ ),
79
+ };
80
+ };
59
81
 
60
82
  const refresh = (): Promise<SkillsCatalogResponseBody> => {
61
83
  if (refreshPromise) return refreshPromise;
@@ -88,17 +110,24 @@ export function createSkillCatalogService(input: {
88
110
  list,
89
111
  refresh,
90
112
  detail(repositoryId, skillId) {
91
- return input.repos.skills.getCatalogDetail(repositoryId, skillId);
113
+ const detail = input.repos.skills.getCatalogDetail(repositoryId, skillId);
114
+ return detail && bundledSkills.has(skillId)
115
+ ? { ...detail, conflict: !detail.stale, registered: false, updateAvailable: false }
116
+ : detail;
92
117
  },
93
118
  installedDetail(skillId) {
94
- return input.repos.skills.getInstalledDetail(skillId);
119
+ return bundledSkills.get(skillId) ?? input.repos.skills.getInstalledDetail(skillId);
95
120
  },
96
121
  register(repositoryId, skillId) {
122
+ if (bundledSkills.has(skillId)) {
123
+ throw new Error(`Skill '${skillId}' has a conflicting bundled extension skill`);
124
+ }
97
125
  return input.repos.transaction((repos) =>
98
126
  repos.skills.registerCatalogEntry(repositoryId, skillId),
99
127
  );
100
128
  },
101
129
  remove(skillId) {
130
+ if (bundledSkills.has(skillId)) return false;
102
131
  return input.repos.transaction((repos) => repos.skills.remove(skillId));
103
132
  },
104
133
  };
@@ -0,0 +1,97 @@
1
+ import { lstat, readFile, realpath } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import type { LoadedExtensionModule } from "@leitwerk-dev/extension-runtime";
4
+ import { parseSkillPackManifest, type SkillRevisionProvenance } from "@leitwerk-dev/protocol";
5
+ import { createCanonicalPiResourceBundle } from "@leitwerk-dev/worker-protocol";
6
+ import { parse as parseYaml } from "yaml";
7
+ import { ResourceCollector } from "../pi-resources/resource-collector.js";
8
+ import type { ImportedSkill } from "./source-importer.js";
9
+
10
+ /** @internal */
11
+ export interface ImportedExtensionSkill extends ImportedSkill {
12
+ /** @internal */
13
+ provenance: SkillRevisionProvenance;
14
+ }
15
+
16
+ async function packagePath(packageRoot: string, target: string): Promise<string> {
17
+ const relative = path.relative(packageRoot, target);
18
+ if (
19
+ !relative ||
20
+ relative === ".." ||
21
+ relative.startsWith(`..${path.sep}`) ||
22
+ path.isAbsolute(relative)
23
+ ) {
24
+ throw new Error(`Skill-pack path escapes package: ${target}`);
25
+ }
26
+ let current = packageRoot;
27
+ for (const part of relative.split(path.sep)) {
28
+ current = path.join(current, part);
29
+ if ((await lstat(current)).isSymbolicLink())
30
+ throw new Error(`Skill-pack symlink is forbidden: ${current}`);
31
+ }
32
+ return current;
33
+ }
34
+
35
+ /** Import only declared packages; no network or patch execution at runtime. @internal */
36
+ export async function importExtensionSkills(
37
+ modules: readonly LoadedExtensionModule[],
38
+ ): Promise<ImportedExtensionSkill[]> {
39
+ const imported: ImportedExtensionSkill[] = [];
40
+ for (const loaded of modules) {
41
+ if (!loaded.skillPackPath) continue;
42
+ const packageRoot = await realpath(loaded.packageDir);
43
+ const manifestPath = await packagePath(
44
+ packageRoot,
45
+ path.resolve(packageRoot, path.relative(loaded.packageDir, loaded.skillPackPath)),
46
+ );
47
+ const manifest = parseSkillPackManifest(JSON.parse(await readFile(manifestPath, "utf8")));
48
+ for (const skill of manifest.skills) {
49
+ const directory = await packagePath(
50
+ packageRoot,
51
+ path.resolve(path.dirname(manifestPath), skill.directory),
52
+ );
53
+ const provenance: SkillRevisionProvenance = {
54
+ extensionId: loaded.module.manifest.id,
55
+ packageName: loaded.packageName,
56
+ packageVersion: loaded.packageVersion ?? loaded.module.manifest.version,
57
+ upstream: manifest.upstream,
58
+ sourcePath: skill.sourcePath,
59
+ patchDigest: manifest.patchDigest,
60
+ dependencies: skill.dependencies,
61
+ };
62
+ const collector = new ResourceCollector();
63
+ await collector.addDirectory(
64
+ directory,
65
+ `skills/${skill.id}`,
66
+ {
67
+ kind: "skill",
68
+ ownerExtensionId: provenance.extensionId,
69
+ packageName: provenance.packageName,
70
+ },
71
+ { forbiddenNames: new Set([".git", ".leitwerk-skill.json"]) },
72
+ );
73
+ const markdown = collector.files.get(`skills/${skill.id}/SKILL.md`);
74
+ const header =
75
+ markdown &&
76
+ /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(Buffer.from(markdown).toString("utf8"));
77
+ const metadata = header ? parseYaml(header[1]) : null;
78
+ if (metadata?.name !== skill.id || metadata.description !== skill.description) {
79
+ throw new Error(`Skill '${skill.id}' frontmatter does not match its pack manifest`);
80
+ }
81
+ // Include dependency/provenance changes in revision identity even when prose is unchanged.
82
+ collector.addBytes(
83
+ `skills/${skill.id}/.leitwerk-skill.json`,
84
+ Buffer.from(JSON.stringify(provenance)),
85
+ );
86
+ imported.push({
87
+ skillId: skill.id,
88
+ label: skill.label,
89
+ description: skill.description,
90
+ sourceRevision: manifest.upstream.commit,
91
+ provenance,
92
+ bundle: createCanonicalPiResourceBundle(collector.toResourceFiles()),
93
+ });
94
+ }
95
+ }
96
+ return imported;
97
+ }
@@ -0,0 +1,19 @@
1
+ import type { SkillSelection } from "@leitwerk-dev/protocol";
2
+ import type { LeitwerkConfig } from "../config/config-types.js";
3
+ import type { RepositoryBundle } from "../db/repositories.js";
4
+
5
+ /** Server-owned defaults, resolved only when selecting skills for a new launch. @internal */
6
+ export type LaunchSkillDefaults = Pick<LeitwerkConfig, "default_skills" | "process_configs">;
7
+
8
+ /** @internal */
9
+ export function resolveLaunchSkills(
10
+ deps: { skills: RepositoryBundle["skills"]; skillDefaults?: LaunchSkillDefaults },
11
+ processId: string,
12
+ selectedSkillIds: readonly string[] = [],
13
+ ): SkillSelection[] {
14
+ const defaults =
15
+ deps.skillDefaults?.process_configs?.[processId]?.default_skills ??
16
+ deps.skillDefaults?.default_skills ??
17
+ [];
18
+ return deps.skills.resolveActive([...new Set([...defaults, ...selectedSkillIds])]);
19
+ }
@@ -15,3 +15,16 @@ function frontmatter(markdown: string): Record<string, unknown> | null {
15
15
  export function isSkillModelInvocable(markdown: string): boolean {
16
16
  return frontmatter(markdown)?.["disable-model-invocation"] !== true;
17
17
  }
18
+
19
+ /** @internal */
20
+ export function skillMetadata(markdown: string): {
21
+ name: string | null;
22
+ description: string | null;
23
+ } {
24
+ const metadata = frontmatter(markdown);
25
+ const text = (key: string): string | null => {
26
+ const value = metadata?.[key];
27
+ return typeof value === "string" ? value.trim() || null : null;
28
+ };
29
+ return { name: text("name"), description: text("description") };
30
+ }
@@ -3,6 +3,7 @@ import { mkdtemp, readdir, readFile, rm } from "node:fs/promises";
3
3
  import { tmpdir } from "node:os";
4
4
  import path from "node:path";
5
5
  import { promisify } from "node:util";
6
+ import type { SkillRevisionProvenance } from "@leitwerk-dev/protocol";
6
7
  import {
7
8
  createCanonicalPiResourceBundle,
8
9
  type PiResourceBundle,
@@ -17,6 +18,8 @@ const FORBIDDEN_SKILL_NAMES = new Set([".git"]);
17
18
 
18
19
  /** @internal */
19
20
  export interface ImportedSkill {
21
+ /** Explicit extension provenance and dependencies. @internal */
22
+ provenance?: SkillRevisionProvenance;
20
23
  /** @internal */
21
24
  skillId: string;
22
25
  /** @internal */
@@ -13,6 +13,7 @@ import type {
13
13
  StartupRecoverySummary,
14
14
  } from "@leitwerk-dev/protocol";
15
15
  import { completeLaunchWhenReady, failLaunchRun } from "./launch-pipeline.js";
16
+ import { pendingTurnWait } from "./process-engine/turn-wait-state.js";
16
17
 
17
18
  export interface StartupEvidenceInput {
18
19
  process: ProcessInstance;
@@ -23,6 +24,7 @@ export interface StartupEvidenceInput {
23
24
  }
24
25
 
25
26
  export interface StartupEvidence {
27
+ readiness?: { message: string | null };
26
28
  attempts: readonly StartupAttemptSummary[];
27
29
  currentAttempt: StartupAttemptSummary | null;
28
30
  authoritativeAttemptId: string | null;
@@ -259,6 +261,9 @@ export function buildStartupEvidence(input: StartupEvidenceInput): StartupEviden
259
261
  null;
260
262
  return {
261
263
  attempts: recoveredAttempts,
264
+ ...(pendingTurnWait(input.process)?.initialSelection
265
+ ? { readiness: { message: pendingTurnWait(input.process)?.message ?? null } }
266
+ : {}),
262
267
  currentAttempt,
263
268
  authoritativeAttemptId: authoritative?.startRecordId ?? null,
264
269
  recovery: buildStartupRecovery(input.process, turnStartsById),
@@ -343,6 +348,21 @@ export function projectLaunchRunStartup(
343
348
  }),
344
349
  };
345
350
  const failedStep = attempt?.steps.find((step) => step.status === "failed");
351
+ if (!attempt && evidence.readiness) {
352
+ next = {
353
+ ...next,
354
+ steps: next.steps.map((step) =>
355
+ step.id === "start_worker"
356
+ ? {
357
+ ...step,
358
+ status: "pending",
359
+ label: "Waiting for startup prerequisites",
360
+ safeSummary: evidence.readiness?.message ?? "Checking startup prerequisites…",
361
+ }
362
+ : step,
363
+ ),
364
+ };
365
+ }
346
366
  if (failedStep) {
347
367
  next = failLaunchRun(
348
368
  next,
@@ -0,0 +1,55 @@
1
+ import type { ExecutionInspectionCapture } from "@leitwerk-dev/domain";
2
+ import type { RepositoryBundle } from "../db/repositories.js";
3
+
4
+ /** Accepted execution ownership is checked before retaining any expanded evidence. */
5
+ export function ingestExecutionInspection(
6
+ deps: Pick<RepositoryBundle, "executionInspections" | "turnRecords" | "leases">,
7
+ input: { instanceId: string; workerId: string; turnRecordId: string; capture: unknown },
8
+ ): boolean {
9
+ const record = deps.turnRecords.getById(input.turnRecordId);
10
+ const lease = deps.leases.getByInstance(input.instanceId);
11
+ if (
12
+ !record ||
13
+ record.instanceId !== input.instanceId ||
14
+ record.status !== "running" ||
15
+ !record.turnStartRecordId ||
16
+ !lease ||
17
+ lease.workerId !== input.workerId ||
18
+ lease.turnStartRecordId !== record.turnStartRecordId ||
19
+ lease.exitedAt !== null
20
+ )
21
+ return false;
22
+ const capture = input.capture as ExecutionInspectionCapture | null;
23
+ if (
24
+ !capture ||
25
+ capture.version !== 1 ||
26
+ typeof capture.id !== "string" ||
27
+ !capture.id ||
28
+ typeof capture.timestamp !== "string" ||
29
+ !capture.fact ||
30
+ !["model_input", "supplied_context", "product_consumed", "entry_link"].includes(
31
+ capture.fact.kind,
32
+ )
33
+ )
34
+ return false;
35
+ if (capture.fact.kind === "supplied_context") {
36
+ for (const product of capture.fact.products) {
37
+ const producer = deps.turnRecords.getById(product.producerTurnRecordId);
38
+ if (
39
+ !producer ||
40
+ producer.instanceId !== input.instanceId ||
41
+ producer.resultPiEntryId !== product.entryId
42
+ )
43
+ return false;
44
+ }
45
+ }
46
+ deps.executionInspections.append({
47
+ ...capture,
48
+ id: `${input.turnRecordId}:${capture.id}`,
49
+ instanceId: input.instanceId,
50
+ turnRecordId: record.id,
51
+ startRecordId: record.turnStartRecordId,
52
+ workerLeaseId: lease.id,
53
+ });
54
+ return true;
55
+ }
@@ -48,6 +48,8 @@ export interface IpcHandlerDeps
48
48
  /** @internal */
49
49
  startupObservations?: RepositoryBundle["startupObservations"];
50
50
  /** @internal */
51
+ executionInspections?: RepositoryBundle["executionInspections"];
52
+ /** @internal */
51
53
  getLaunchCoordinator?: () => LaunchCoordinator | undefined;
52
54
  /** @internal */
53
55
  processQuestions?: ProcessQuestionService;
@@ -1,12 +1,10 @@
1
1
  import {
2
- applyPiEventToLiveTurnProjection,
3
2
  asWsEventPayloadRecord,
4
- buildLiveTurnProjectionFromEvents,
5
3
  createDurableWsFrame,
6
4
  createEphemeralWsFrame,
7
- createMutableLiveTurnProjection,
5
+ createLiveTurnProjection,
8
6
  isStreamableEvent,
9
- type MutableLiveTurnProjection,
7
+ type LiveTurnProjection,
10
8
  mapWorkerEventToWsType,
11
9
  readWsEventNonEmptyString,
12
10
  readWsEventPiTurnId,
@@ -21,6 +19,7 @@ import type { RepositoryBundle } from "../db/repositories.js";
21
19
  import { recordTurnPreparation } from "../turn-preparation.js";
22
20
  import { recordTurnProgress } from "../turn-progress.js";
23
21
  import type { Broadcaster } from "../ws/broadcast.js";
22
+ import { ingestExecutionInspection } from "./execution-inspection-ingestor.js";
24
23
  import { recordInitialTurnObservation } from "./startup-observer.js";
25
24
 
26
25
  /** @internal */
@@ -48,6 +47,7 @@ export interface WorkerEventLogEntry {
48
47
  export interface WorkerEventIngestorDeps
49
48
  extends Pick<RepositoryBundle, "processes" | "events" | "turnRecords"> {
50
49
  leases?: RepositoryBundle["leases"];
50
+ executionInspections?: RepositoryBundle["executionInspections"];
51
51
  startupObservations?: RepositoryBundle["startupObservations"];
52
52
  broadcaster: Broadcaster;
53
53
  workerEventLogger?: (entry: WorkerEventLogEntry) => void;
@@ -70,28 +70,28 @@ function hydrateLiveTurnProjection(
70
70
  deps: Pick<WorkerEventIngestorDeps, "events" | "turnRecords">,
71
71
  instanceId: string,
72
72
  turnRecordId: string | null,
73
- ): MutableLiveTurnProjection {
73
+ ): LiveTurnProjection {
74
74
  if (!turnRecordId) {
75
- return createMutableLiveTurnProjection();
75
+ return createLiveTurnProjection();
76
76
  }
77
77
  const turnRecord = deps.turnRecords.getById(turnRecordId);
78
78
  if (!turnRecord) {
79
- return createMutableLiveTurnProjection();
79
+ return createLiveTurnProjection();
80
80
  }
81
- return buildLiveTurnProjectionFromEvents(deps.events.listByTurnRecord(instanceId, turnRecordId));
81
+ return createLiveTurnProjection(deps.events.listByTurnRecord(instanceId, turnRecordId));
82
82
  }
83
83
 
84
84
  export function createWorkerEventIngestor(deps: WorkerEventIngestorDeps) {
85
85
  const liveTurnRecordIds = new Map<string, string>();
86
86
  const liveTurnProjections = new Map<
87
87
  string,
88
- { turnRecordId: string | null; projection: MutableLiveTurnProjection }
88
+ { turnRecordId: string | null; projection: LiveTurnProjection }
89
89
  >();
90
90
 
91
91
  function getLiveTurnProjection(
92
92
  instanceId: string,
93
93
  turnRecordId: string | null,
94
- ): MutableLiveTurnProjection {
94
+ ): LiveTurnProjection {
95
95
  const existing = liveTurnProjections.get(instanceId);
96
96
  if (existing && existing.turnRecordId === turnRecordId) {
97
97
  return existing.projection;
@@ -104,7 +104,7 @@ export function createWorkerEventIngestor(deps: WorkerEventIngestorDeps) {
104
104
  function setLiveTurnProjection(instanceId: string, turnRecordId: string | null) {
105
105
  liveTurnProjections.set(instanceId, {
106
106
  turnRecordId,
107
- projection: createMutableLiveTurnProjection(),
107
+ projection: createLiveTurnProjection(),
108
108
  });
109
109
  }
110
110
 
@@ -171,6 +171,18 @@ export function createWorkerEventIngestor(deps: WorkerEventIngestorDeps) {
171
171
  }
172
172
 
173
173
  if (suppliedTurnRecordId && suppliedTurnRecordId !== currentTurnRecordId) return;
174
+ if (payload.eventType === "execution.inspection") {
175
+ if (suppliedTurnRecordId && deps.executionInspections && deps.leases)
176
+ ingestExecutionInspection(
177
+ {
178
+ executionInspections: deps.executionInspections,
179
+ turnRecords: deps.turnRecords,
180
+ leases: deps.leases,
181
+ },
182
+ { instanceId, workerId, turnRecordId: suppliedTurnRecordId, capture: data.capture },
183
+ );
184
+ return;
185
+ }
174
186
  if (payload.eventType === "turn.progress") {
175
187
  const reportedTurnRecordId = readWsEventNonEmptyString(data.turnRecordId);
176
188
  if (!reportedTurnRecordId || reportedTurnRecordId !== currentTurnRecordId) return;
@@ -192,7 +204,7 @@ export function createWorkerEventIngestor(deps: WorkerEventIngestorDeps) {
192
204
  return;
193
205
  }
194
206
  const projection = getLiveTurnProjection(instanceId, currentTurnRecordId);
195
- const appliedProjectionEvent = applyPiEventToLiveTurnProjection(projection, {
207
+ const appliedProjectionEvent = projection.apply({
196
208
  eventType: payload.eventType,
197
209
  data,
198
210
  fallbackTimestamp: new Date().toISOString(),
@@ -200,7 +212,11 @@ export function createWorkerEventIngestor(deps: WorkerEventIngestorDeps) {
200
212
  const projectionData = appliedProjectionEvent.canonicalData;
201
213
  const enrichedData: Record<string, unknown> =
202
214
  currentTurnRecordId && !readWsEventNonEmptyString(projectionData.turnRecordId)
203
- ? { ...projectionData, turnRecordId: currentTurnRecordId }
215
+ ? {
216
+ ...projectionData,
217
+ turnRecordId: currentTurnRecordId,
218
+ workerLeaseId: deps.leases?.getByInstance(instanceId)?.id ?? null,
219
+ }
204
220
  : projectionData;
205
221
  const currentSelectedTurnId = payload.selectedTurnId ?? process.selectedTurnId ?? null;
206
222
  const normalizedTimestamp = eventTimestamp(enrichedData);
@@ -263,7 +279,7 @@ export function createWorkerEventIngestor(deps: WorkerEventIngestorDeps) {
263
279
  );
264
280
  }
265
281
  } else if (payload.eventType === "pi.usage") {
266
- const usage = projection.usage;
282
+ const usage = appliedProjectionEvent.usage;
267
283
  if (usage) {
268
284
  deps.broadcaster.broadcast(
269
285
  createEphemeralWsFrame({
@@ -285,6 +285,22 @@ export function createWorkerStartPayloadBuilder(deps: WorkerStartPayloadBuilderD
285
285
  function buildWorkerRuntimeContextSnapshot(process: ProcessInstance, start: TurnStartRecord) {
286
286
  const turnResultMarkdownBySemanticRef = buildTurnResultMarkdownBySemanticRef(process, deps);
287
287
  const turnResultMarkdownByProduct = buildTurnResultMarkdownByProduct(process, deps);
288
+ const productRefs = parseProductRefsFromStateJsonLenient(process.stateJson);
289
+ const inspectionProducts = Object.entries(turnResultMarkdownByProduct ?? {}).flatMap(
290
+ ([name, content]) => {
291
+ const ref = productRefs[name];
292
+ return ref?.turnRecordId
293
+ ? [
294
+ {
295
+ name,
296
+ producerTurnRecordId: ref.turnRecordId,
297
+ entryId: ref.entryId,
298
+ content: { state: "recorded" as const, value: content },
299
+ },
300
+ ]
301
+ : [];
302
+ },
303
+ );
288
304
  const prepared =
289
305
  start.state.kind === "starting" ||
290
306
  start.state.kind === "accepted" ||
@@ -302,6 +318,7 @@ export function createWorkerStartPayloadBuilder(deps: WorkerStartPayloadBuilderD
302
318
  projectSnapshots: buildProjectSnapshots(process.id),
303
319
  ...(turnResultMarkdownBySemanticRef ? { turnResultMarkdownBySemanticRef } : {}),
304
320
  ...(turnResultMarkdownByProduct ? { turnResultMarkdownByProduct } : {}),
321
+ inspectionProducts,
305
322
  };
306
323
  }
307
324