@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
@@ -17,6 +17,7 @@ import { resolveDockerRegistryCredentials } from "../docker-registry-credentials
17
17
  import { isValidStorageSize } from "../process-storage-size.js";
18
18
  import { SAFE_SKILL_ID_PATTERN } from "../skills/skill-id.js";
19
19
  import type { LeitwerkConfig } from "./config-types.js";
20
+ import { resolveKubernetesDockerIsolation } from "./kubernetes-docker-isolation.js";
20
21
  import { isHttpsOrLoopbackHttpUrl, isValidHttpUrl, parseHttpUrl } from "./url-policy.js";
21
22
 
22
23
  const DEFAULT_SEARCH_PATHS = ["./leitwerk.yaml", "~/.leitwerk/leitwerk.yaml"];
@@ -135,12 +136,19 @@ export function loadConfigFromFile(filePath: string): ConfigLoadResult | ConfigL
135
136
  export function loadConfig(explicitPath?: string): ConfigLoadResult | ConfigLoadError {
136
137
  const filePath = resolveConfigPath(explicitPath);
137
138
  if (!filePath) {
138
- return { ok: true, config: getDefaultConfig(), filePath: "<defaults>" };
139
+ return {
140
+ ok: false,
141
+ error:
142
+ "Configuration file required: configure pi.default_model_profile and pi.model_profiles",
143
+ };
139
144
  }
140
145
  return loadConfigFromFile(filePath);
141
146
  }
142
147
 
143
148
  const stringArraySchema = v.array(v.string());
149
+ const skillIdsSchema = v.array(
150
+ v.pipe(v.string(), v.regex(SAFE_SKILL_ID_PATTERN, "Invalid skill ID")),
151
+ );
144
152
  const modelTurnConfigSchema = v.looseObject({
145
153
  model_profile: v.optional(v.string()),
146
154
  });
@@ -287,6 +295,10 @@ const configSchema = v.looseObject({
287
295
  ),
288
296
  pi: v.looseObject({
289
297
  agent_dir: v.string(),
298
+ default_model_profile: v.pipe(
299
+ v.string(),
300
+ v.check((value) => value.trim() !== "", "Must be a non-empty model profile ID"),
301
+ ),
290
302
  model_profiles: v.array(
291
303
  v.looseObject({
292
304
  id: v.string(),
@@ -320,6 +332,7 @@ const configSchema = v.looseObject({
320
332
  v.record(
321
333
  v.string(),
322
334
  v.looseObject({
335
+ default_skills: v.optional(skillIdsSchema),
323
336
  default_model_profile: v.optional(v.string()),
324
337
  allowed_model_profiles: v.optional(v.pipe(stringArraySchema, v.nonEmpty())),
325
338
  worker_runtime_profile: v.optional(v.string()),
@@ -350,6 +363,7 @@ const configSchema = v.looseObject({
350
363
  sources: stringArraySchema,
351
364
  }),
352
365
  auth: v.optional(authConfigSchema),
366
+ default_skills: v.optional(skillIdsSchema),
353
367
  docker_registries: v.optional(
354
368
  v.strictObject({
355
369
  profiles: v.record(v.string(), v.strictObject(dockerRegistryCredentialSchema.entries)),
@@ -381,6 +395,7 @@ const configSchema = v.looseObject({
381
395
  api_server_url: v.optional(v.string()),
382
396
  default_worker_runtime_profile: v.optional(v.string()),
383
397
  worker_service_account: v.optional(v.string()),
398
+ image_preload: v.optional(v.strictObject({ enabled: v.boolean() })),
384
399
  process_volume: v.looseObject({
385
400
  storage_class_name: v.optional(v.string()),
386
401
  pre_provision: v.optional(
@@ -392,8 +407,11 @@ const configSchema = v.looseObject({
392
407
  }),
393
408
  docker: v.optional(
394
409
  v.strictObject({
410
+ worker_runtime_profile: v.optional(v.pipe(v.string(), v.trim(), v.nonEmpty())),
411
+ node_selector: v.optional(v.record(v.string(), v.string())),
395
412
  runtime_class_name: v.optional(v.string()),
396
413
  host_users: v.optional(v.boolean()),
414
+ isolation: v.optional(v.picklist(["gvisor", "virtual-machine"])),
397
415
  gvisor: v.optional(v.boolean()),
398
416
  process_storage_class_name: v.optional(v.string()),
399
417
  network: v.optional(dockerNetworkSchema),
@@ -495,6 +513,11 @@ function collectModelProfileReferenceErrors(config: LeitwerkConfig): string[] {
495
513
  .filter((profileId) => typeof profileId === "string" && profileId.trim() !== ""),
496
514
  );
497
515
  const titleModelProfile = config.pi.process_title_generation.model_profile;
516
+ if (!configuredModelProfileIds.has(config.pi.default_model_profile)) {
517
+ errors.push(
518
+ `Unknown model profile '${config.pi.default_model_profile}' at pi.default_model_profile`,
519
+ );
520
+ }
498
521
  if (typeof titleModelProfile === "string") {
499
522
  if (titleModelProfile.trim() === "") {
500
523
  errors.push(
@@ -560,6 +583,10 @@ function collectWorkerRuntimeProfileErrors(config: LeitwerkConfig): string[] {
560
583
  config.kubernetes?.default_worker_runtime_profile,
561
584
  "kubernetes.default_worker_runtime_profile",
562
585
  );
586
+ checkReference(
587
+ config.kubernetes?.docker?.worker_runtime_profile,
588
+ "kubernetes.docker.worker_runtime_profile",
589
+ );
563
590
  }
564
591
  for (const [key, component] of Object.entries(config.components)) {
565
592
  checkReference(component.worker_runtime_profile, `components.${key}.worker_runtime_profile`);
@@ -737,6 +764,14 @@ function collectKubernetesRunnerConfigErrors(config: LeitwerkConfig): string[] {
737
764
  errors.push(
738
765
  "worker_runtime_profiles must include at least one profile when workers.runner is 'kubernetes'",
739
766
  );
767
+ if (k.image_preload?.enabled) {
768
+ for (const [id, profile] of Object.entries(config.worker_runtime_profiles ?? {})) {
769
+ if (!/^[a-zA-Z0-9][a-zA-Z0-9._:/-]*@sha256:[0-9a-f]{64}$/.test(profile.image))
770
+ errors.push(
771
+ `worker_runtime_profiles.${id}.image must be digest-qualified when kubernetes.image_preload.enabled is true`,
772
+ );
773
+ }
774
+ }
740
775
  const defaultProfile = k.default_worker_runtime_profile ?? config.workers.default_runtime_profile;
741
776
  if (!defaultProfile?.trim())
742
777
  errors.push(
@@ -935,6 +970,7 @@ function validateResolvedConfig(config: Record<string, unknown>): string[] {
935
970
  ...collectLocalRunnerConfigErrors(resolvedConfig),
936
971
  ...collectDockerRunnerConfigErrors(resolvedConfig),
937
972
  ...collectKubernetesRunnerConfigErrors(resolvedConfig),
973
+ ...resolveKubernetesDockerIsolation(resolvedConfig.kubernetes?.docker).errors,
938
974
  ...collectInternalTlsConfigErrors(resolvedConfig),
939
975
  ...collectAuthConfigErrors(resolvedConfig),
940
976
  ];
@@ -974,7 +1010,7 @@ export function sanitizeConfigForLogging(value: unknown, path: readonly string[]
974
1010
  return sanitized;
975
1011
  }
976
1012
 
977
- /** @public */
1013
+ /** Configuration template; set model_profiles and default_model_profile before startup. @public */
978
1014
  export function getDefaultConfig(): LeitwerkConfig {
979
1015
  return {
980
1016
  skill_repositories: [],
@@ -1028,6 +1064,7 @@ export function getDefaultConfig(): LeitwerkConfig {
1028
1064
  pi: {
1029
1065
  agent_dir: "~/.pi/leitwerk",
1030
1066
  model_profiles: [],
1067
+ default_model_profile: "",
1031
1068
  process_title_generation: {
1032
1069
  model_profile: null,
1033
1070
  retry: {
@@ -1048,6 +1085,7 @@ export function getDefaultConfig(): LeitwerkConfig {
1048
1085
  },
1049
1086
  },
1050
1087
  process_configs: {},
1088
+ default_skills: [],
1051
1089
  notifications: {
1052
1090
  all: { enabled: false, type: "teams_webhook", url: "" },
1053
1091
  debug: { enabled: false, type: "teams_webhook", url: "" },
@@ -165,11 +165,17 @@ export interface KubernetesProcessVolumeConfig {
165
165
 
166
166
  /** @internal */
167
167
  export interface KubernetesDockerConfig {
168
+ /** Default profile for Docker processes without an explicit process/component profile. @internal */
169
+ worker_runtime_profile?: string;
170
+ /** Docker-only selector keys override matching global Pod selector keys. @internal */
171
+ node_selector?: Record<string, string>;
168
172
  /** Pod RuntimeClass selected for every Docker-requiring process. @internal */
169
173
  runtime_class_name?: string;
170
174
  /** Pod user-namespace policy passed directly to spec.hostUsers. @internal */
171
175
  host_users?: boolean;
172
- /** @internal Opt in to the verified gVisor Docker wrapper and guest capabilities. */
176
+ /** Trusted sandbox policy for a separately qualified cluster runtime. @internal */
177
+ isolation?: "gvisor" | "virtual-machine";
178
+ /** Legacy alias for isolation: gvisor when isolation is omitted. @internal */
173
179
  gvisor?: boolean;
174
180
  /** StorageClass selected for the process's single retained PVC. @internal */
175
181
  process_storage_class_name?: string;
@@ -217,6 +223,11 @@ export interface LocalWorkerRunnerConfig {
217
223
 
218
224
  /** @internal */
219
225
  export interface KubernetesRunnerConfig {
226
+ /** Optional worker image preparation on eligible nodes; disabled by default. @internal */
227
+ image_preload?: {
228
+ /** @internal */
229
+ enabled: boolean;
230
+ };
220
231
  /** Dedicated namespace where the singleton server runs. @internal */
221
232
  server_namespace: string;
222
233
  /** Safe DNS prefix used to derive one namespace per process instance. @internal */
@@ -394,6 +405,8 @@ export interface LeitwerkConfig extends ConfigSnapshot {
394
405
  internal_tls?: InternalTlsConfig;
395
406
  /** Git repositories scanned for operator-managed skills. @internal */
396
407
  skill_repositories?: SkillRepositoryConfig[];
408
+ /** Installed skill IDs included in new launches unless replaced by process defaults. @public */
409
+ default_skills?: string[];
397
410
  /** Server-owned repository-aware commit-message generation rules. @internal */
398
411
  commit_messages?: CommitMessageConfig;
399
412
  /** Bounded archive and extraction ceilings for local session transfer. @internal */
@@ -0,0 +1,21 @@
1
+ import type { KubernetesDockerConfig } from "./config-types.js";
2
+
3
+ /** Normalize trusted sandbox selection before passing it to a worker runner. @internal */
4
+ export function resolveKubernetesDockerIsolation(docker: KubernetesDockerConfig | undefined): {
5
+ isolation: KubernetesDockerConfig["isolation"];
6
+ errors: string[];
7
+ } {
8
+ const isolation = docker?.isolation ?? (docker?.gvisor ? "gvisor" : undefined);
9
+ const errors: string[] = [];
10
+ if (
11
+ docker?.isolation !== undefined &&
12
+ docker.gvisor !== undefined &&
13
+ docker.gvisor !== (docker.isolation === "gvisor")
14
+ ) {
15
+ errors.push("kubernetes.docker.gvisor conflicts with kubernetes.docker.isolation");
16
+ }
17
+ if (isolation !== undefined && docker?.host_users !== undefined) {
18
+ errors.push("kubernetes.docker.host_users must be omitted for sandbox isolation");
19
+ }
20
+ return { isolation, errors };
21
+ }
@@ -44,6 +44,17 @@ export class DatabaseSchemaMismatchError extends Error {
44
44
  }
45
45
 
46
46
  const ALL_TABLES = [
47
+ schema.wikiTopics,
48
+ schema.wikiPages,
49
+ schema.wikiRevisions,
50
+ schema.topicPublications,
51
+ schema.inspectionContents,
52
+ schema.executionInspections,
53
+
54
+ schema.settingsSubjects,
55
+ schema.settingsAliases,
56
+ schema.settingsOverrides,
57
+ schema.settingsSubjectRedirects,
47
58
  schema.startupObservations,
48
59
  schema.processInstances,
49
60
  schema.launchRuns,
@@ -338,25 +349,82 @@ interface KnownMigration {
338
349
  apply(sqlite: DatabaseSync): void;
339
350
  }
340
351
 
341
- const KNOWN_MIGRATIONS: readonly KnownMigration[] = [
342
- {
343
- id: "20260911_add_startup_observations",
344
- tableNames: ["startup_observations"],
345
- matches: (sqlite) =>
346
- hasExistingSchema(sqlite) && existingTableSql(sqlite, "startup_observations") === null,
352
+ function addTablesMigration(
353
+ id: string,
354
+ tables: readonly SQLiteTable[],
355
+ matches: KnownMigration["matches"],
356
+ ): KnownMigration {
357
+ return {
358
+ id,
359
+ tableNames: tables.map(getTableName),
360
+ matches,
347
361
  apply(sqlite) {
348
- createTableWithIndexes(sqlite, schema.startupObservations);
362
+ for (const table of tables) createTableWithIndexes(sqlite, table);
349
363
  },
350
- },
364
+ };
365
+ }
366
+ const HISTORY_INDEXES = [
367
+ "idx_turn_records_page",
368
+ "idx_turn_annotations_created",
369
+ "idx_worker_leases_started",
370
+ "idx_worker_leases_exited",
371
+ ] as const;
372
+
373
+ const KNOWN_MIGRATIONS: readonly KnownMigration[] = [
351
374
  {
352
- id: "20260823_add_ticket_destination_recents",
353
- tableNames: ["ticket_destination_recents"],
375
+ id: "20261008_remove_repository_instruction_overrides",
376
+ tableNames: [],
354
377
  matches: (sqlite) =>
355
- hasExistingSchema(sqlite) && existingTableSql(sqlite, "ticket_destination_recents") === null,
378
+ existingTableSql(sqlite, "settings_overrides") !== null &&
379
+ Boolean(
380
+ sqlite
381
+ .prepare("SELECT 1 FROM settings_overrides WHERE key = ? LIMIT 1")
382
+ .get("coding.repository_instructions"),
383
+ ),
356
384
  apply(sqlite) {
357
- createTableWithIndexes(sqlite, schema.ticketDestinationRecents);
385
+ sqlite
386
+ .prepare("DELETE FROM settings_overrides WHERE key = ?")
387
+ .run("coding.repository_instructions");
358
388
  },
359
389
  },
390
+ addTablesMigration(
391
+ "20260930_add_topic_wiki",
392
+ [schema.wikiTopics, schema.wikiPages, schema.wikiRevisions, schema.topicPublications],
393
+ (sqlite) => hasExistingSchema(sqlite) && existingTableSql(sqlite, "wiki_topics") === null,
394
+ ),
395
+ addTablesMigration(
396
+ "20260925_add_execution_inspections",
397
+ [schema.inspectionContents, schema.executionInspections],
398
+ (sqlite) =>
399
+ hasExistingSchema(sqlite) && existingTableSql(sqlite, "execution_inspections") === null,
400
+ ),
401
+ addTablesMigration(
402
+ "20260926_add_scoped_settings",
403
+ [schema.settingsSubjects, schema.settingsAliases, schema.settingsOverrides],
404
+ (sqlite) =>
405
+ existingTableSql(sqlite, "process_instances") !== null &&
406
+ existingTableSql(sqlite, "settings_subjects") === null &&
407
+ existingTableSql(sqlite, "settings_aliases") === null &&
408
+ existingTableSql(sqlite, "settings_overrides") === null,
409
+ ),
410
+ addTablesMigration(
411
+ "20260926_add_settings_subject_redirects",
412
+ [schema.settingsSubjectRedirects],
413
+ (sqlite) =>
414
+ hasExistingSchema(sqlite) && existingTableSql(sqlite, "settings_subject_redirects") === null,
415
+ ),
416
+ addTablesMigration(
417
+ "20260911_add_startup_observations",
418
+ [schema.startupObservations],
419
+ (sqlite) =>
420
+ hasExistingSchema(sqlite) && existingTableSql(sqlite, "startup_observations") === null,
421
+ ),
422
+ addTablesMigration(
423
+ "20260823_add_ticket_destination_recents",
424
+ [schema.ticketDestinationRecents],
425
+ (sqlite) =>
426
+ hasExistingSchema(sqlite) && existingTableSql(sqlite, "ticket_destination_recents") === null,
427
+ ),
360
428
  {
361
429
  id: "20260909_add_reasoning_summaries",
362
430
  tableNames: ["process_events", "turn_summaries", "session_summaries"],
@@ -391,14 +459,13 @@ const KNOWN_MIGRATIONS: readonly KnownMigration[] = [
391
459
  createTableWithIndexes(sqlite, schema.sessionSummaries);
392
460
  },
393
461
  },
394
- {
395
- id: "20260908_add_api_tokens",
396
- tableNames: ["api_tokens"],
397
- matches: (sqlite) =>
462
+ addTablesMigration(
463
+ "20260908_add_api_tokens",
464
+ [schema.apiTokens],
465
+ (sqlite) =>
398
466
  existingTableSql(sqlite, "auth_sessions") !== null &&
399
467
  existingTableSql(sqlite, "api_tokens") === null,
400
- apply: (sqlite) => createTableWithIndexes(sqlite, schema.apiTokens),
401
- },
468
+ ),
402
469
  {
403
470
  id: "20260901_add_session_transfers",
404
471
  tableNames: ["session_transfer_grants", "session_transfer_attempts"],
@@ -553,18 +620,13 @@ const KNOWN_MIGRATIONS: readonly KnownMigration[] = [
553
620
  }
554
621
  },
555
622
  },
556
- {
557
- id: "20260726_add_sql_backed_skills",
558
- tableNames: ["skills", "skill_revisions", "process_skills"],
559
- matches: (sqlite) =>
623
+ addTablesMigration(
624
+ "20260726_add_sql_backed_skills",
625
+ [schema.skills, schema.skillRevisions, schema.processSkills],
626
+ (sqlite) =>
560
627
  existingTableSql(sqlite, "process_instances") !== null &&
561
628
  existingTableSql(sqlite, "skills") === null,
562
- apply(sqlite) {
563
- for (const table of [schema.skills, schema.skillRevisions, schema.processSkills]) {
564
- createTableWithIndexes(sqlite, table);
565
- }
566
- },
567
- },
629
+ ),
568
630
  {
569
631
  id: "20260728_add_skill_catalog_and_invocations",
570
632
  tableNames: ["skills", "skill_catalog_entries", "skill_invocations"],
@@ -599,21 +661,30 @@ const KNOWN_MIGRATIONS: readonly KnownMigration[] = [
599
661
  },
600
662
  },
601
663
  {
602
- id: "20260729_add_skill_revision_dependencies",
603
- tableNames: ["skill_revision_dependencies"],
604
- matches: (sqlite) => existingTableSql(sqlite, "skill_revision_dependencies") === null,
605
- apply(sqlite) {
606
- createTableWithIndexes(sqlite, schema.skillRevisionDependencies);
607
- },
608
- },
609
- {
610
- id: "20260726_add_process_question_requests",
611
- tableNames: ["process_question_requests"],
612
- matches: (sqlite) => existingTableSql(sqlite, "process_question_requests") === null,
664
+ id: "20261006_add_extension_skill_provenance",
665
+ tableNames: ["skills", "skill_revisions"],
666
+ matches: (sqlite) =>
667
+ !tableHasColumn(sqlite, "skills", "owner_extension_id") ||
668
+ !tableHasColumn(sqlite, "skill_revisions", "provenance_json"),
613
669
  apply(sqlite) {
614
- createTableWithIndexes(sqlite, schema.processQuestionRequests);
670
+ if (!tableHasColumn(sqlite, "skills", "owner_extension_id")) {
671
+ sqlite.exec("ALTER TABLE skills ADD COLUMN owner_extension_id text");
672
+ }
673
+ if (!tableHasColumn(sqlite, "skill_revisions", "provenance_json")) {
674
+ sqlite.exec("ALTER TABLE skill_revisions ADD COLUMN provenance_json text");
675
+ }
615
676
  },
616
677
  },
678
+ addTablesMigration(
679
+ "20260729_add_skill_revision_dependencies",
680
+ [schema.skillRevisionDependencies],
681
+ (sqlite) => existingTableSql(sqlite, "skill_revision_dependencies") === null,
682
+ ),
683
+ addTablesMigration(
684
+ "20260726_add_process_question_requests",
685
+ [schema.processQuestionRequests],
686
+ (sqlite) => existingTableSql(sqlite, "process_question_requests") === null,
687
+ ),
617
688
  {
618
689
  id: "20260725_add_model_policy_provenance_and_future_blocks",
619
690
  tableNames: ["process_instances", "future_executions", "turn_records"],
@@ -864,6 +935,26 @@ const KNOWN_MIGRATIONS: readonly KnownMigration[] = [
864
935
  }
865
936
  },
866
937
  },
938
+ {
939
+ id: "20261005_add_process_history_indexes",
940
+ tableNames: [],
941
+ legacyIndexNames: [...HISTORY_INDEXES, "idx_leaf_outcomes_anchored"],
942
+ matches(sqlite) {
943
+ const indexes = existingSchemaObjects(sqlite, "index");
944
+ return (
945
+ hasExistingSchema(sqlite) &&
946
+ (indexes.has("idx_leaf_outcomes_anchored") ||
947
+ HISTORY_INDEXES.some((name) => !indexes.has(name)))
948
+ );
949
+ },
950
+ apply(sqlite) {
951
+ sqlite.exec(`CREATE INDEX IF NOT EXISTS idx_turn_records_page ON turn_records(instance_id, started_at, id);
952
+ CREATE INDEX IF NOT EXISTS idx_turn_annotations_created ON turn_annotations(instance_id, created_at);
953
+ CREATE INDEX IF NOT EXISTS idx_worker_leases_started ON worker_leases(instance_id, started_at);
954
+ CREATE INDEX IF NOT EXISTS idx_worker_leases_exited ON worker_leases(instance_id, exited_at);
955
+ DROP INDEX IF EXISTS idx_leaf_outcomes_anchored;`);
956
+ },
957
+ },
867
958
  ];
868
959
 
869
960
  function backupSqliteFiles(sqlite: DatabaseSync, sqlitePath: string): string {
@@ -0,0 +1,163 @@
1
+ import { createHash } from "node:crypto";
2
+ import type {
3
+ ExecutionInspectionCapture,
4
+ ExecutionInspectionRecord,
5
+ InspectionContextObservation,
6
+ } from "@leitwerk-dev/domain";
7
+ import type { InspectionConfigurationRevision } from "@leitwerk-dev/protocol";
8
+ import { and, asc, eq, inArray, sql } from "drizzle-orm";
9
+ import type { LeitwerkDb } from "./database.js";
10
+ import { executionInspections, inspectionContents } from "./schema.js";
11
+
12
+ /** Immutable content and incremental observation references. No session ancestry is copied. @internal */
13
+ export function createExecutionInspectionRepo(db: LeitwerkDb) {
14
+ function pack(value: unknown): unknown {
15
+ if (Array.isArray(value)) return value.map(pack);
16
+ if (!value || typeof value !== "object") return value;
17
+ const record = value as Record<string, unknown>;
18
+ if ((record.state === "recorded" || record.state === "redacted") && "value" in record) {
19
+ const contentJson = JSON.stringify(record.value);
20
+ const digest = createHash("sha256").update(contentJson).digest("hex");
21
+ db.insert(inspectionContents).values({ digest, contentJson }).onConflictDoNothing().run();
22
+ return { state: record.state, contentDigest: digest };
23
+ }
24
+ return Object.fromEntries(Object.entries(record).map(([key, item]) => [key, pack(item)]));
25
+ }
26
+ function unpack(value: unknown): unknown {
27
+ if (Array.isArray(value)) return value.map(unpack);
28
+ if (!value || typeof value !== "object") return value;
29
+ const record = value as Record<string, unknown>;
30
+ if (typeof record.contentDigest === "string") {
31
+ const row = db
32
+ .select()
33
+ .from(inspectionContents)
34
+ .where(eq(inspectionContents.digest, record.contentDigest))
35
+ .get();
36
+ return row
37
+ ? { state: record.state, value: JSON.parse(row.contentJson) }
38
+ : { state: "unavailable", reason: "Recorded content is unavailable" };
39
+ }
40
+ return Object.fromEntries(Object.entries(record).map(([key, item]) => [key, unpack(item)]));
41
+ }
42
+ return {
43
+ /** Model identities without loading retained prompts or message contents. @internal */
44
+ modelInputs(
45
+ instanceId: string,
46
+ turnRecordId: string,
47
+ ): Pick<InspectionConfigurationRevision, "id" | "timestamp" | "boundaryEntryId" | "model">[] {
48
+ return db
49
+ .select({
50
+ id: executionInspections.id,
51
+ timestamp: executionInspections.capturedAt,
52
+ boundaryEntryId: sql<
53
+ string | null
54
+ >`json_extract(${executionInspections.factJson}, '$.boundaryEntryId')`,
55
+ model: sql<string>`json_extract(${executionInspections.factJson}, '$.model')`,
56
+ })
57
+ .from(executionInspections)
58
+ .where(
59
+ and(
60
+ eq(executionInspections.instanceId, instanceId),
61
+ eq(executionInspections.turnRecordId, turnRecordId),
62
+ sql`json_extract(${executionInspections.factJson}, '$.kind') = 'model_input'`,
63
+ ),
64
+ )
65
+ .orderBy(asc(executionInspections.sequence))
66
+ .all()
67
+ .map((row) => ({
68
+ ...row,
69
+ model: JSON.parse(row.model) as InspectionConfigurationRevision["model"],
70
+ }));
71
+ },
72
+ /** @internal */
73
+ append(input: Omit<ExecutionInspectionRecord, "sequence">): "stored" | "replay" {
74
+ return db.transaction(() => {
75
+ const factJson = JSON.stringify(pack(input.fact));
76
+ const existing = db
77
+ .select()
78
+ .from(executionInspections)
79
+ .where(eq(executionInspections.id, input.id))
80
+ .get();
81
+ if (existing) {
82
+ if (
83
+ existing.instanceId !== input.instanceId ||
84
+ existing.turnRecordId !== input.turnRecordId ||
85
+ existing.factJson !== factJson
86
+ )
87
+ throw new Error("Inspection observation identity was reused with different evidence");
88
+ return "replay";
89
+ }
90
+ db.insert(executionInspections)
91
+ .values({
92
+ id: input.id,
93
+ instanceId: input.instanceId,
94
+ turnRecordId: input.turnRecordId,
95
+ startRecordId: input.startRecordId,
96
+ workerLeaseId: input.workerLeaseId,
97
+ capturedAt: input.timestamp,
98
+ factJson,
99
+ })
100
+ .run();
101
+ return "stored";
102
+ });
103
+ },
104
+ /** Expanded evidence is read only on demand. @internal */
105
+ list(instanceId: string, turnRecordId: string): ExecutionInspectionRecord[] {
106
+ return db
107
+ .select()
108
+ .from(executionInspections)
109
+ .where(
110
+ and(
111
+ eq(executionInspections.instanceId, instanceId),
112
+ eq(executionInspections.turnRecordId, turnRecordId),
113
+ ),
114
+ )
115
+ .orderBy(asc(executionInspections.sequence))
116
+ .all()
117
+ .map((row) => ({
118
+ version: 1,
119
+ id: row.id,
120
+ sequence: row.sequence,
121
+ instanceId: row.instanceId,
122
+ turnRecordId: row.turnRecordId,
123
+ startRecordId: row.startRecordId,
124
+ workerLeaseId: row.workerLeaseId,
125
+ timestamp: row.capturedAt,
126
+ fact: unpack(JSON.parse(row.factJson)) as ExecutionInspectionCapture["fact"],
127
+ }));
128
+ },
129
+ /** Small origin/product references for compact lineage without loading prompts. @internal */
130
+ listContextFacts(instanceId: string, turnRecordIds?: string[]): InspectionContextObservation[] {
131
+ if (turnRecordIds?.length === 0) return [];
132
+ return db
133
+ .select()
134
+ .from(executionInspections)
135
+ .where(
136
+ and(
137
+ eq(executionInspections.instanceId, instanceId),
138
+ turnRecordIds ? inArray(executionInspections.turnRecordId, turnRecordIds) : undefined,
139
+ sql`json_extract(${executionInspections.factJson}, '$.kind') IN ('supplied_context', 'product_consumed', 'entry_link')`,
140
+ ),
141
+ )
142
+ .orderBy(asc(executionInspections.sequence))
143
+ .all()
144
+ .map((row) => {
145
+ const fact = JSON.parse(row.factJson) as Extract<
146
+ ExecutionInspectionCapture["fact"],
147
+ { kind: "supplied_context" | "product_consumed" | "entry_link" }
148
+ >;
149
+ return {
150
+ id: row.id,
151
+ turnRecordId: row.turnRecordId,
152
+ fact:
153
+ fact.kind === "supplied_context"
154
+ ? {
155
+ ...fact,
156
+ products: fact.products.map(({ content: _content, ...source }) => source),
157
+ }
158
+ : fact,
159
+ };
160
+ });
161
+ },
162
+ };
163
+ }
@@ -0,0 +1,18 @@
1
+ import { and, gte, lte } from "drizzle-orm";
2
+ import type { SQLiteColumn } from "drizzle-orm/sqlite-core";
3
+
4
+ /** @internal */
5
+ export interface HistoryWindow {
6
+ /** @internal */
7
+ since?: string;
8
+ /** @internal */
9
+ until?: string;
10
+ }
11
+
12
+ /** @internal */
13
+ export function historyWindow(column: SQLiteColumn, window?: HistoryWindow) {
14
+ return and(
15
+ window?.since ? gte(column, window.since) : undefined,
16
+ window?.until ? lte(column, window.until) : undefined,
17
+ );
18
+ }