@leitwerk-dev/server 0.3.1 → 0.4.1

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 (327) hide show
  1. package/dist/{app-BuJCdkvy.d.ts → app-CtlotzYm.d.ts} +312 -121
  2. package/dist/app-KR3N2JAE.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-OUA5EZS2.js} +3127 -689
  8. package/dist/chunk-OUA5EZS2.js.map +1 -0
  9. package/dist/{chunk-HK6BLLHA.js → chunk-YLWY4UTT.js} +2424 -1580
  10. package/dist/chunk-YLWY4UTT.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 +16 -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/dashboard-model-issues.d.ts +10 -0
  18. package/dist/dashboard-model-issues.d.ts.map +1 -0
  19. package/dist/db/database.d.ts.map +1 -1
  20. package/dist/db/execution-inspection-repo.d.ts +15 -0
  21. package/dist/db/execution-inspection-repo.d.ts.map +1 -0
  22. package/dist/db/history-window.d.ts +11 -0
  23. package/dist/db/history-window.d.ts.map +1 -0
  24. package/dist/db/process-event-repo.d.ts +2 -0
  25. package/dist/db/process-event-repo.d.ts.map +1 -1
  26. package/dist/db/process-instance-repo.d.ts +21 -1
  27. package/dist/db/process-instance-repo.d.ts.map +1 -1
  28. package/dist/db/process-leaf-outcome-snapshot-repo.d.ts +2 -1
  29. package/dist/db/process-leaf-outcome-snapshot-repo.d.ts.map +1 -1
  30. package/dist/db/process-project-repo.d.ts +2 -0
  31. package/dist/db/process-project-repo.d.ts.map +1 -1
  32. package/dist/db/process-skill-repo.d.ts.map +1 -1
  33. package/dist/db/process-turn-annotation-repo.d.ts +4 -1
  34. package/dist/db/process-turn-annotation-repo.d.ts.map +1 -1
  35. package/dist/db/process-turn-record-repo.d.ts +4 -0
  36. package/dist/db/process-turn-record-repo.d.ts.map +1 -1
  37. package/dist/db/publication-repo.d.ts +5 -0
  38. package/dist/db/publication-repo.d.ts.map +1 -0
  39. package/dist/db/repositories.d.ts +12 -0
  40. package/dist/db/repositories.d.ts.map +1 -1
  41. package/dist/db/schema.d.ts +693 -2
  42. package/dist/db/schema.d.ts.map +1 -1
  43. package/dist/db/scoped-settings-repo.d.ts +37 -0
  44. package/dist/db/scoped-settings-repo.d.ts.map +1 -0
  45. package/dist/db/skill-repo.d.ts +3 -0
  46. package/dist/db/skill-repo.d.ts.map +1 -1
  47. package/dist/db/turn-start-record-repo.d.ts +2 -1
  48. package/dist/db/turn-start-record-repo.d.ts.map +1 -1
  49. package/dist/db/turn-summary-repo.d.ts +10 -1
  50. package/dist/db/turn-summary-repo.d.ts.map +1 -1
  51. package/dist/db/worker-lease-repo.d.ts +2 -1
  52. package/dist/db/worker-lease-repo.d.ts.map +1 -1
  53. package/dist/domain-logic/outcome-tools.d.ts.map +1 -1
  54. package/dist/domain-logic/worker-lease-lifecycle.d.ts.map +1 -1
  55. package/dist/external-source-service.d.ts.map +1 -1
  56. package/dist/future-execution/execution.d.ts +4 -1
  57. package/dist/future-execution/execution.d.ts.map +1 -1
  58. package/dist/future-execution/launch-lifecycle.d.ts +9 -25
  59. package/dist/future-execution/launch-lifecycle.d.ts.map +1 -1
  60. package/dist/future-execution/lifecycle.d.ts +3 -28
  61. package/dist/future-execution/lifecycle.d.ts.map +1 -1
  62. package/dist/future-execution/model-projection.d.ts.map +1 -1
  63. package/dist/future-execution/reconciliation.d.ts +1 -0
  64. package/dist/future-execution/reconciliation.d.ts.map +1 -1
  65. package/dist/future-execution-presenter.d.ts.map +1 -1
  66. package/dist/index.js +2 -2
  67. package/dist/integration-tool-registry.d.ts +11 -2
  68. package/dist/integration-tool-registry.d.ts.map +1 -1
  69. package/dist/launch-coordinator.d.ts.map +1 -1
  70. package/dist/launcher-model-config-service.d.ts +7 -1
  71. package/dist/launcher-model-config-service.d.ts.map +1 -1
  72. package/dist/leaf-outcome-snapshot-capture.d.ts +1 -0
  73. package/dist/leaf-outcome-snapshot-capture.d.ts.map +1 -1
  74. package/dist/main.js +3 -3
  75. package/dist/primary-path-snapshot.d.ts.map +1 -1
  76. package/dist/process-action-presenter.d.ts +1 -6
  77. package/dist/process-action-presenter.d.ts.map +1 -1
  78. package/dist/process-action-registry.d.ts.map +1 -1
  79. package/dist/process-engine/decision.d.ts +2 -0
  80. package/dist/process-engine/decision.d.ts.map +1 -1
  81. package/dist/process-engine/engine.d.ts.map +1 -1
  82. package/dist/process-engine/mapped-turns.d.ts.map +1 -1
  83. package/dist/process-engine/ops/automatic-retry-startup.d.ts +8 -0
  84. package/dist/process-engine/ops/automatic-retry-startup.d.ts.map +1 -0
  85. package/dist/process-engine/ops/continue-failed-turn.d.ts.map +1 -1
  86. package/dist/process-engine/ops/process-observation.d.ts +6 -0
  87. package/dist/process-engine/ops/process-observation.d.ts.map +1 -0
  88. package/dist/process-engine/ops/retry-failed-turn.d.ts.map +1 -1
  89. package/dist/process-engine/ops/retry-startup.d.ts +2 -0
  90. package/dist/process-engine/ops/retry-startup.d.ts.map +1 -1
  91. package/dist/process-engine/ops/start-process.d.ts +2 -0
  92. package/dist/process-engine/ops/start-process.d.ts.map +1 -1
  93. package/dist/process-engine/ops/turn-outcome.d.ts.map +1 -1
  94. package/dist/process-engine/ops/turn-wait.d.ts +30 -0
  95. package/dist/process-engine/ops/turn-wait.d.ts.map +1 -0
  96. package/dist/process-engine/ops/update-model-config.d.ts +9 -0
  97. package/dist/process-engine/ops/update-model-config.d.ts.map +1 -0
  98. package/dist/process-engine/recorder.d.ts.map +1 -1
  99. package/dist/process-engine/turn-start-preflight.d.ts +6 -0
  100. package/dist/process-engine/turn-start-preflight.d.ts.map +1 -1
  101. package/dist/process-engine/turn-wait-state.d.ts +24 -0
  102. package/dist/process-engine/turn-wait-state.d.ts.map +1 -0
  103. package/dist/process-engine/turn-worker-requirement.d.ts +2 -0
  104. package/dist/process-engine/turn-worker-requirement.d.ts.map +1 -1
  105. package/dist/process-engine/types.d.ts +13 -2
  106. package/dist/process-engine/types.d.ts.map +1 -1
  107. package/dist/process-engine/writes/build-process-abort-writes.d.ts +3 -1
  108. package/dist/process-engine/writes/build-process-abort-writes.d.ts.map +1 -1
  109. package/dist/process-engine/writes/build-turn-outcome-writes.d.ts +2 -0
  110. package/dist/process-engine/writes/build-turn-outcome-writes.d.ts.map +1 -1
  111. package/dist/process-engine/writes/commit-writes.d.ts +2 -0
  112. package/dist/process-engine/writes/commit-writes.d.ts.map +1 -1
  113. package/dist/process-engine/writes/writes.d.ts +28 -60
  114. package/dist/process-engine/writes/writes.d.ts.map +1 -1
  115. package/dist/process-graph.d.ts +1 -1
  116. package/dist/process-graph.d.ts.map +1 -1
  117. package/dist/process-inspection-reader.d.ts +21 -0
  118. package/dist/process-inspection-reader.d.ts.map +1 -0
  119. package/dist/process-inspection-trace.d.ts +13 -0
  120. package/dist/process-inspection-trace.d.ts.map +1 -0
  121. package/dist/process-inspection.d.ts +22 -0
  122. package/dist/process-inspection.d.ts.map +1 -0
  123. package/dist/process-instance-tree-presenter.d.ts +4 -3
  124. package/dist/process-instance-tree-presenter.d.ts.map +1 -1
  125. package/dist/process-launch-executor.d.ts +2 -0
  126. package/dist/process-launch-executor.d.ts.map +1 -1
  127. package/dist/process-launch-plan.d.ts +1 -0
  128. package/dist/process-launch-plan.d.ts.map +1 -1
  129. package/dist/process-launcher-registry.d.ts.map +1 -1
  130. package/dist/process-model-availability-recovery.d.ts +1 -1
  131. package/dist/process-model-availability-recovery.d.ts.map +1 -1
  132. package/dist/process-model-config.d.ts +19 -0
  133. package/dist/process-model-config.d.ts.map +1 -0
  134. package/dist/process-model-policy/construct.d.ts.map +1 -1
  135. package/dist/process-model-policy/evaluate.d.ts.map +1 -1
  136. package/dist/process-model-policy/index.d.ts +4 -1
  137. package/dist/process-model-policy/index.d.ts.map +1 -1
  138. package/dist/process-model-policy/project.d.ts.map +1 -1
  139. package/dist/process-model-policy/types.d.ts +18 -0
  140. package/dist/process-model-policy/types.d.ts.map +1 -1
  141. package/dist/process-model-policy-presenter.d.ts.map +1 -1
  142. package/dist/process-runtime-availability.d.ts +2 -1
  143. package/dist/process-runtime-availability.d.ts.map +1 -1
  144. package/dist/process-turn-trace.d.ts.map +1 -1
  145. package/dist/process-ui-snapshot-presenter.d.ts +14 -3
  146. package/dist/process-ui-snapshot-presenter.d.ts.map +1 -1
  147. package/dist/routes/dashboard.d.ts +17 -0
  148. package/dist/routes/dashboard.d.ts.map +1 -0
  149. package/dist/routes/future-executions.d.ts.map +1 -1
  150. package/dist/routes/launchers.d.ts.map +1 -1
  151. package/dist/routes/process-actions.d.ts.map +1 -1
  152. package/dist/routes/process-detail.d.ts.map +1 -1
  153. package/dist/routes/process-model-config.d.ts +4 -0
  154. package/dist/routes/process-model-config.d.ts.map +1 -0
  155. package/dist/routes/process-route-helpers.d.ts +8 -9
  156. package/dist/routes/process-route-helpers.d.ts.map +1 -1
  157. package/dist/routes/processes.d.ts.map +1 -1
  158. package/dist/routes/settings.d.ts +11 -0
  159. package/dist/routes/settings.d.ts.map +1 -0
  160. package/dist/routes/ticket-creation.d.ts.map +1 -1
  161. package/dist/scoped-settings-service.d.ts +98 -0
  162. package/dist/scoped-settings-service.d.ts.map +1 -0
  163. package/dist/server-bootstrap/build-host-capabilities.d.ts +2 -0
  164. package/dist/server-bootstrap/build-host-capabilities.d.ts.map +1 -1
  165. package/dist/server-bootstrap/register-http.d.ts.map +1 -1
  166. package/dist/session-summary-projection.d.ts.map +1 -1
  167. package/dist/skills/bundled-skills.d.ts +5 -0
  168. package/dist/skills/bundled-skills.d.ts.map +1 -0
  169. package/dist/skills/catalog-service.d.ts +1 -0
  170. package/dist/skills/catalog-service.d.ts.map +1 -1
  171. package/dist/skills/extension-importer.d.ts +11 -0
  172. package/dist/skills/extension-importer.d.ts.map +1 -0
  173. package/dist/skills/launch-skills.d.ts +11 -0
  174. package/dist/skills/launch-skills.d.ts.map +1 -0
  175. package/dist/skills/skill-frontmatter.d.ts +7 -0
  176. package/dist/skills/skill-frontmatter.d.ts.map +1 -1
  177. package/dist/skills/source-importer.d.ts +3 -0
  178. package/dist/skills/source-importer.d.ts.map +1 -1
  179. package/dist/startup-evidence.d.ts +4 -3
  180. package/dist/startup-evidence.d.ts.map +1 -1
  181. package/dist/startup-retry-policy.d.ts +8 -0
  182. package/dist/startup-retry-policy.d.ts.map +1 -0
  183. package/dist/supervisor/execution-inspection-ingestor.d.ts +9 -0
  184. package/dist/supervisor/execution-inspection-ingestor.d.ts.map +1 -0
  185. package/dist/supervisor/ipc-handler.d.ts +2 -0
  186. package/dist/supervisor/ipc-handler.d.ts.map +1 -1
  187. package/dist/supervisor/worker-event-ingestor.d.ts +1 -0
  188. package/dist/supervisor/worker-event-ingestor.d.ts.map +1 -1
  189. package/dist/supervisor/worker-start-payload-builder.d.ts.map +1 -1
  190. package/dist/supervisor/worker-supervisor.d.ts +2 -0
  191. package/dist/supervisor/worker-supervisor.d.ts.map +1 -1
  192. package/dist/test-helpers/prepared-fixture-start.d.ts.map +1 -1
  193. package/dist/test-helpers/process-model-fixtures.d.ts +1 -0
  194. package/dist/test-helpers/process-model-fixtures.d.ts.map +1 -1
  195. package/dist/test-helpers/scoped-settings-fixtures.d.ts +16 -0
  196. package/dist/test-helpers/scoped-settings-fixtures.d.ts.map +1 -0
  197. package/dist/test-helpers/skill-fixtures.d.ts +4 -0
  198. package/dist/test-helpers/skill-fixtures.d.ts.map +1 -0
  199. package/dist/testing.js +2 -1
  200. package/dist/testing.js.map +1 -1
  201. package/dist/tool-approval-gate.d.ts +3 -0
  202. package/dist/tool-approval-gate.d.ts.map +1 -1
  203. package/dist/turn-progress.d.ts.map +1 -1
  204. package/dist/turn-wait-service.d.ts +28 -0
  205. package/dist/turn-wait-service.d.ts.map +1 -0
  206. package/dist/worker-runtime-profile-selection.d.ts +2 -0
  207. package/dist/worker-runtime-profile-selection.d.ts.map +1 -1
  208. package/package.json +20 -19
  209. package/src/app.ts +177 -25
  210. package/src/auth/fastify-auth.ts +13 -0
  211. package/src/config/config-loader.ts +42 -2
  212. package/src/config/config-types.ts +16 -1
  213. package/src/config/kubernetes-docker-isolation.ts +21 -0
  214. package/src/dashboard-model-issues.ts +199 -0
  215. package/src/db/database.ts +131 -40
  216. package/src/db/execution-inspection-repo.ts +163 -0
  217. package/src/db/history-window.ts +18 -0
  218. package/src/db/process-event-repo.ts +88 -10
  219. package/src/db/process-instance-repo.ts +33 -2
  220. package/src/db/process-leaf-outcome-snapshot-repo.ts +8 -2
  221. package/src/db/process-project-repo.ts +4 -0
  222. package/src/db/process-skill-repo.ts +9 -2
  223. package/src/db/process-turn-annotation-repo.ts +27 -9
  224. package/src/db/process-turn-record-repo.ts +45 -12
  225. package/src/db/publication-repo.ts +63 -0
  226. package/src/db/repositories.ts +17 -0
  227. package/src/db/schema.ts +103 -1
  228. package/src/db/scoped-settings-repo.ts +234 -0
  229. package/src/db/skill-repo.ts +89 -27
  230. package/src/db/turn-start-record-repo.ts +13 -3
  231. package/src/db/turn-summary-repo.ts +36 -4
  232. package/src/db/worker-lease-repo.ts +8 -2
  233. package/src/domain-logic/outcome-tools.ts +18 -216
  234. package/src/domain-logic/worker-lease-lifecycle.ts +2 -1
  235. package/src/external-source-service.ts +33 -7
  236. package/src/future-execution/execution.ts +9 -2
  237. package/src/future-execution/launch-lifecycle.ts +87 -78
  238. package/src/future-execution/lifecycle.ts +5 -34
  239. package/src/future-execution/model-projection.ts +2 -0
  240. package/src/future-execution/reconciliation.ts +7 -0
  241. package/src/future-execution-presenter.ts +7 -8
  242. package/src/integration-tool-registry.ts +59 -26
  243. package/src/launch-coordinator.ts +10 -1
  244. package/src/launcher-model-config-service.ts +24 -3
  245. package/src/leaf-outcome-snapshot-capture.ts +2 -0
  246. package/src/primary-path-snapshot.ts +3 -4
  247. package/src/process-action-presenter.ts +22 -57
  248. package/src/process-action-registry.ts +31 -39
  249. package/src/process-engine/decision.ts +10 -0
  250. package/src/process-engine/engine.ts +25 -2
  251. package/src/process-engine/mapped-turns.ts +5 -7
  252. package/src/process-engine/ops/automatic-retry-startup.ts +93 -0
  253. package/src/process-engine/ops/continue-failed-turn.ts +2 -13
  254. package/src/process-engine/ops/process-observation.ts +119 -0
  255. package/src/process-engine/ops/retry-failed-turn.ts +2 -12
  256. package/src/process-engine/ops/retry-startup.ts +20 -16
  257. package/src/process-engine/ops/start-process.ts +34 -2
  258. package/src/process-engine/ops/turn-outcome.ts +61 -60
  259. package/src/process-engine/ops/turn-wait.ts +225 -0
  260. package/src/process-engine/ops/update-model-config.ts +66 -0
  261. package/src/process-engine/recorder.ts +34 -5
  262. package/src/process-engine/turn-start-preflight.ts +168 -105
  263. package/src/process-engine/turn-wait-state.ts +126 -0
  264. package/src/process-engine/turn-worker-requirement.ts +4 -0
  265. package/src/process-engine/types.ts +21 -0
  266. package/src/process-engine/writes/build-process-abort-writes.ts +30 -20
  267. package/src/process-engine/writes/build-turn-outcome-writes.ts +39 -2
  268. package/src/process-engine/writes/commit-writes.ts +16 -4
  269. package/src/process-engine/writes/writes.ts +59 -74
  270. package/src/process-graph.ts +0 -1
  271. package/src/process-inspection-reader.ts +305 -0
  272. package/src/process-inspection-trace.ts +176 -0
  273. package/src/process-inspection.ts +169 -0
  274. package/src/process-instance-tree-presenter.ts +56 -216
  275. package/src/process-launch-executor.ts +5 -2
  276. package/src/process-launch-plan.ts +17 -2
  277. package/src/process-launcher-registry.ts +28 -16
  278. package/src/process-model-availability-recovery.ts +6 -4
  279. package/src/process-model-config.ts +100 -0
  280. package/src/process-model-policy/construct.ts +1 -0
  281. package/src/process-model-policy/evaluate.ts +34 -32
  282. package/src/process-model-policy/index.ts +45 -3
  283. package/src/process-model-policy/project.ts +62 -76
  284. package/src/process-model-policy/types.ts +26 -0
  285. package/src/process-model-policy-presenter.ts +7 -3
  286. package/src/process-runtime-availability.ts +9 -4
  287. package/src/process-turn-trace.ts +12 -24
  288. package/src/process-ui-snapshot-presenter.ts +210 -295
  289. package/src/routes/dashboard.ts +106 -0
  290. package/src/routes/future-executions.ts +5 -5
  291. package/src/routes/launchers.ts +51 -1
  292. package/src/routes/process-actions.ts +10 -10
  293. package/src/routes/process-detail.ts +25 -2
  294. package/src/routes/process-model-config.ts +70 -0
  295. package/src/routes/process-route-helpers.ts +153 -162
  296. package/src/routes/processes.ts +2 -0
  297. package/src/routes/settings.ts +173 -0
  298. package/src/routes/ticket-creation.ts +28 -5
  299. package/src/scoped-settings-service.ts +797 -0
  300. package/src/server-bootstrap/build-host-capabilities.ts +42 -0
  301. package/src/server-bootstrap/register-http.ts +12 -1
  302. package/src/session-summary-projection.ts +1 -2
  303. package/src/skills/bundled-skills.ts +64 -0
  304. package/src/skills/catalog-service.ts +35 -6
  305. package/src/skills/extension-importer.ts +94 -0
  306. package/src/skills/launch-skills.ts +19 -0
  307. package/src/skills/skill-frontmatter.ts +19 -6
  308. package/src/skills/source-importer.ts +7 -13
  309. package/src/startup-evidence.ts +29 -8
  310. package/src/startup-retry-policy.ts +106 -0
  311. package/src/supervisor/execution-inspection-ingestor.ts +55 -0
  312. package/src/supervisor/ipc-handler.ts +2 -0
  313. package/src/supervisor/worker-event-ingestor.ts +30 -14
  314. package/src/supervisor/worker-start-payload-builder.ts +17 -0
  315. package/src/supervisor/worker-supervisor.ts +26 -1
  316. package/src/test-helpers/prepared-fixture-start.ts +1 -0
  317. package/src/test-helpers/process-model-fixtures.ts +2 -0
  318. package/src/test-helpers/scoped-settings-fixtures.ts +126 -0
  319. package/src/test-helpers/skill-fixtures.ts +28 -0
  320. package/src/tool-approval-gate.ts +16 -0
  321. package/src/turn-progress.ts +3 -2
  322. package/src/turn-wait-service.ts +228 -0
  323. package/src/worker-runtime-profile-selection.ts +8 -1
  324. package/dist/app-MSJXFK33.js +0 -8
  325. package/dist/chunk-HK6BLLHA.js.map +0 -1
  326. package/dist/chunk-QCHS3X33.js.map +0 -1
  327. /package/dist/{app-MSJXFK33.js.map → app-KR3N2JAE.js.map} +0 -0
@@ -1,6 +1,7 @@
1
1
  import type { ProcessEvent } from "@leitwerk-dev/domain";
2
2
  import { applyEventToCompactTurnSummary, emptyCompactTurnSummary } from "@leitwerk-dev/protocol";
3
- import { and, asc, desc, eq, gte, inArray, like, type SQL, sql } from "drizzle-orm";
3
+ import type { SQL } from "drizzle-orm";
4
+ import { and, asc, desc, eq, getTableColumns, gte, inArray, like, sql } from "drizzle-orm";
4
5
  import type { LeitwerkDb } from "./database.js";
5
6
  import { generateId, now } from "./repo-helpers.js";
6
7
  import * as s from "./schema.js";
@@ -40,6 +41,87 @@ export function createProcessEventRepo(db: LeitwerkDb) {
40
41
  .all()
41
42
  .map(rowToProcessEvent);
42
43
  return {
44
+ /** Timeline facts without embedded process state or provider responses. @internal */
45
+ listUiSnapshotEvents(instanceId: string, turnRecordIds: readonly string[]): ProcessEvent[] {
46
+ const newestIds = (where: SQL | undefined, limit: number) =>
47
+ db
48
+ .select({ id: s.processEvents.id, sequence: s.processEvents.eventSequence })
49
+ .from(s.processEvents)
50
+ .where(where)
51
+ .orderBy(desc(s.processEvents.eventSequence))
52
+ .limit(limit)
53
+ .all();
54
+ // Select identities before loading payloads. Most candidates are discarded
55
+ // by the combined limit, and one provider response can be megabytes.
56
+ const candidates = [
57
+ "worker_capacity_queued",
58
+ "lifecycle_parked",
59
+ "worker_failed",
60
+ "external_trigger_listener_armed",
61
+ "external_source_armed",
62
+ "external_trigger_failed",
63
+ "external_source_failed",
64
+ "external_trigger_consumed",
65
+ "external_source_consumed",
66
+ ].flatMap((eventType) =>
67
+ newestIds(
68
+ and(eq(s.processEvents.instanceId, instanceId), eq(s.processEvents.eventType, eventType)),
69
+ 40,
70
+ ),
71
+ );
72
+ candidates.sort((left, right) => right.sequence - left.sequence);
73
+ const selected = candidates.slice(0, 40);
74
+ for (const turnRecordId of turnRecordIds) {
75
+ for (const eventType of ["turn.progress", "turn_outcome_recorded"]) {
76
+ selected.push(
77
+ ...newestIds(
78
+ and(
79
+ eq(s.processEvents.instanceId, instanceId),
80
+ eq(s.processEvents.turnRecordId, turnRecordId),
81
+ eq(s.processEvents.eventType, eventType),
82
+ ),
83
+ 1,
84
+ ),
85
+ );
86
+ }
87
+ }
88
+ const ids = [...new Set(selected.map((event) => event.id))];
89
+ if (ids.length === 0) return [];
90
+ const data = s.processEvents.data;
91
+ return db
92
+ .select({
93
+ ...getTableColumns(s.processEvents),
94
+ data: sql<string>`json_object(
95
+ 'turnRecordId', json_extract(${data}, '$.turnRecordId'),
96
+ 'turnId', json_extract(${data}, '$.turnId'),
97
+ 'outcome', json_extract(${data}, '$.outcome'),
98
+ 'params', json_object(
99
+ 'summary', json_extract(${data}, '$.params.summary'),
100
+ 'planMarkdown', json_extract(${data}, '$.params.planMarkdown'),
101
+ 'reviewMarkdown', json_extract(${data}, '$.params.reviewMarkdown'),
102
+ 'feedback', json_extract(${data}, '$.params.feedback')),
103
+ 'report', json_extract(${data}, '$.report'),
104
+ 'revision', json_extract(${data}, '$.revision'),
105
+ 'startRecordId', json_extract(${data}, '$.startRecordId'),
106
+ 'reason', json_extract(${data}, '$.reason'),
107
+ 'message', json_extract(${data}, '$.message'),
108
+ 'errorCode', json_extract(${data}, '$.errorCode'),
109
+ 'errorClass', json_extract(${data}, '$.errorClass'),
110
+ 'armingId', json_extract(${data}, '$.armingId'),
111
+ 'trigger', json_extract(${data}, '$.trigger'),
112
+ 'path', json_extract(${data}, '$.path'),
113
+ 'pollInterval', json_extract(${data}, '$.pollInterval'),
114
+ 'provider', json_object(
115
+ 'path', json_extract(${data}, '$.provider.path'),
116
+ 'pollInterval', json_extract(${data}, '$.provider.pollInterval'))
117
+ )`,
118
+ })
119
+ .from(s.processEvents)
120
+ .where(inArray(s.processEvents.id, ids))
121
+ .orderBy(asc(s.processEvents.createdAt), asc(s.processEvents.id))
122
+ .all()
123
+ .map(rowToProcessEvent);
124
+ },
43
125
  /** @internal */
44
126
  create(input: CreateProcessEventInput): ProcessEvent {
45
127
  const id = generateId("evt");
@@ -111,20 +193,16 @@ export function createProcessEventRepo(db: LeitwerkDb) {
111
193
  turnRecordId: string,
112
194
  eventType: string,
113
195
  ): ProcessEvent | null {
114
- const row = db
115
- .select()
116
- .from(s.processEvents)
117
- .where(
196
+ return (
197
+ listNewest(
118
198
  and(
119
199
  eq(s.processEvents.instanceId, instanceId),
120
200
  eq(s.processEvents.turnRecordId, turnRecordId),
121
201
  eq(s.processEvents.eventType, eventType),
122
202
  ),
123
- )
124
- .orderBy(desc(s.processEvents.eventSequence))
125
- .limit(1)
126
- .get();
127
- return row ? rowToProcessEvent(row) : null;
203
+ 1,
204
+ )[0] ?? null
205
+ );
128
206
  },
129
207
  /** @internal */
130
208
  summary(turnRecordId: string) {
@@ -252,6 +252,30 @@ export function createProcessInstanceRepo(db: LeitwerkDb) {
252
252
  .map(rowToProcessInstance);
253
253
  },
254
254
 
255
+ /** Model references for current work without loading prompts or process state. @internal */
256
+ listModelConfigurations() {
257
+ return db
258
+ .select({
259
+ /** @internal */
260
+ id: s.processInstances.id,
261
+ /** @internal */
262
+ processId: s.processInstances.processId,
263
+ /** @internal */
264
+ title: s.processInstances.title,
265
+ /** @internal */
266
+ defaultModelProfileId: s.processInstances.defaultModelProfileId,
267
+ /** @internal */
268
+ turnConfigsJson: s.processInstances.turnConfigsJson,
269
+ /** @internal */
270
+ selectedTurnId: s.processInstances.selectedTurnId,
271
+ /** @internal */
272
+ selectedTurnModelProfileId: s.processInstances.selectedTurnModelProfileId,
273
+ })
274
+ .from(s.processInstances)
275
+ .where(notInArray(s.processInstances.lifecycleStatus, ["completed", "aborted"]))
276
+ .all();
277
+ },
278
+
255
279
  /** @internal */
256
280
  listCurrent(limit: number): ProcessInstance[] {
257
281
  return db
@@ -362,10 +386,17 @@ export function createProcessInstanceRepo(db: LeitwerkDb) {
362
386
  },
363
387
 
364
388
  /** @public */
365
- update(id: string, input: UpdateProcessInstanceInput): ProcessInstance | null {
389
+ update(
390
+ id: string,
391
+ input: UpdateProcessInstanceInput,
392
+ options: {
393
+ /** Scheduling-only writes retain process activity time; never part of a process patch. @internal */
394
+ preserveUpdatedAt?: boolean;
395
+ } = {},
396
+ ): ProcessInstance | null {
366
397
  const ts = now();
367
398
  const setValues: SQLiteUpdateSetSource<typeof s.processInstances> = {
368
- updatedAt: ts,
399
+ ...(options.preserveUpdatedAt ? {} : { updatedAt: ts }),
369
400
  defaultModelProfileId: input.defaultModelProfileId,
370
401
  initialDefaultModelProfileId: input.initialDefaultModelProfileId,
371
402
  selectedTurnId: input.selectedTurnId,
@@ -4,6 +4,7 @@ import type {
4
4
  } from "@leitwerk-dev/domain";
5
5
  import { and, asc, desc, eq, sql } from "drizzle-orm";
6
6
  import type { LeitwerkDb } from "./database.js";
7
+ import { type HistoryWindow, historyWindow } from "./history-window.js";
7
8
  import { generateId, now, parseJsonRecord } from "./repo-helpers.js";
8
9
  import * as s from "./schema.js";
9
10
 
@@ -82,11 +83,16 @@ export function createProcessLeafOutcomeSnapshotRepo(db: LeitwerkDb) {
82
83
  },
83
84
 
84
85
  /** @internal */
85
- listByInstance(instanceId: string): ProcessLeafOutcomeSnapshot[] {
86
+ listByInstance(instanceId: string, window?: HistoryWindow): ProcessLeafOutcomeSnapshot[] {
86
87
  return db
87
88
  .select()
88
89
  .from(s.processLeafOutcomeSnapshots)
89
- .where(eq(s.processLeafOutcomeSnapshots.instanceId, instanceId))
90
+ .where(
91
+ and(
92
+ eq(s.processLeafOutcomeSnapshots.instanceId, instanceId),
93
+ historyWindow(s.processLeafOutcomeSnapshots.anchoredAt, window),
94
+ ),
95
+ )
90
96
  .orderBy(
91
97
  asc(s.processLeafOutcomeSnapshots.anchoredAt),
92
98
  asc(s.processLeafOutcomeSnapshots.createdAt),
@@ -60,6 +60,10 @@ function rowToProcessProject(row: typeof s.processProjects.$inferSelect): Proces
60
60
  /** @public */
61
61
  export function createProcessProjectRepo(db: LeitwerkDb) {
62
62
  return {
63
+ /** @internal */
64
+ listAll(): ProcessProject[] {
65
+ return db.select().from(s.processProjects).all().map(rowToProcessProject);
66
+ },
63
67
  /** @internal */
64
68
  create(input: CreateProcessProjectInput): ProcessProject {
65
69
  const id = generateId("prj");
@@ -49,15 +49,22 @@ export function createProcessSkillRepo(db: LeitwerkDb) {
49
49
  .select({
50
50
  digest: skillRevisions.bundleDigest,
51
51
  bytes: skillRevisions.bundleBytes,
52
+ provenance: skillRevisions.provenance,
52
53
  })
53
54
  .from(processSkills)
54
55
  .innerJoin(skillRevisions, eq(processSkills.skillRevisionId, skillRevisions.id))
55
56
  .where(eq(processSkills.instanceId, instanceId))
56
57
  .orderBy(asc(processSkills.position))
57
58
  .all()
58
- .map(({ digest, bytes }) => ({
59
+ .map(({ digest, bytes, provenance }) => ({
59
60
  bundle: { digest, bytes },
60
- owner: SKILL_RESOURCE_OWNER,
61
+ owner: provenance
62
+ ? {
63
+ kind: "skill" as const,
64
+ ownerExtensionId: provenance.extensionId,
65
+ packageName: provenance.packageName,
66
+ }
67
+ : SKILL_RESOURCE_OWNER,
61
68
  }));
62
69
  },
63
70
  };
@@ -1,8 +1,9 @@
1
1
  import type { ProcessTurnAnnotation, TurnAnnotationReference } from "@leitwerk-dev/domain";
2
2
  import { parseTurnAnnotationReferences } from "@leitwerk-dev/domain";
3
- import { and, asc, eq } from "drizzle-orm";
3
+ import { and, asc, eq, getTableColumns, sql } from "drizzle-orm";
4
4
  import type { SQLiteUpdateSetSource } from "drizzle-orm/sqlite-core";
5
5
  import type { LeitwerkDb } from "./database.js";
6
+ import { type HistoryWindow, historyWindow } from "./history-window.js";
6
7
  import { generateId, now, parseJsonRecord } from "./repo-helpers.js";
7
8
  import * as s from "./schema.js";
8
9
 
@@ -65,6 +66,24 @@ function rowToProcessTurnAnnotation(
65
66
 
66
67
  /** @internal */
67
68
  export function createProcessTurnAnnotationRepo(db: LeitwerkDb) {
69
+ const list = (instanceId: string, window: HistoryWindow | undefined, compact: boolean) =>
70
+ db
71
+ .select({
72
+ ...getTableColumns(s.turnAnnotations),
73
+ payloadJson: compact
74
+ ? sql<string>`json_remove(${s.turnAnnotations.payloadJson}, '$.event')`
75
+ : s.turnAnnotations.payloadJson,
76
+ })
77
+ .from(s.turnAnnotations)
78
+ .where(
79
+ and(
80
+ eq(s.turnAnnotations.instanceId, instanceId),
81
+ historyWindow(s.turnAnnotations.createdAt, window),
82
+ ),
83
+ )
84
+ .orderBy(asc(s.turnAnnotations.createdAt))
85
+ .all()
86
+ .map(rowToProcessTurnAnnotation);
68
87
  return {
69
88
  /** @internal */
70
89
  create(input: CreateProcessTurnAnnotationInput): ProcessTurnAnnotation {
@@ -111,14 +130,13 @@ export function createProcessTurnAnnotationRepo(db: LeitwerkDb) {
111
130
  },
112
131
 
113
132
  /** @internal */
114
- listByInstance(instanceId: string): ProcessTurnAnnotation[] {
115
- return db
116
- .select()
117
- .from(s.turnAnnotations)
118
- .where(eq(s.turnAnnotations.instanceId, instanceId))
119
- .orderBy(asc(s.turnAnnotations.createdAt))
120
- .all()
121
- .map(rowToProcessTurnAnnotation);
133
+ listByInstance(instanceId: string, window?: HistoryWindow): ProcessTurnAnnotation[] {
134
+ return list(instanceId, window, false);
135
+ },
136
+
137
+ /** Keep presentation and observation fields without the raw source event. @internal */
138
+ listForTimeline(instanceId: string, window?: HistoryWindow): ProcessTurnAnnotation[] {
139
+ return list(instanceId, window, true);
122
140
  },
123
141
 
124
142
  /** @internal */
@@ -8,7 +8,7 @@ import type {
8
8
  TurnId,
9
9
  WorkerErrorClass,
10
10
  } from "@leitwerk-dev/domain";
11
- import { asc, desc, eq } from "drizzle-orm";
11
+ import { and, asc, desc, eq, getTableColumns, isNull, ne, sql } from "drizzle-orm";
12
12
  import type { SQLiteUpdateSetSource } from "drizzle-orm/sqlite-core";
13
13
  import type { LeitwerkDb } from "./database.js";
14
14
  import { generateId, mappedItemRef, now } from "./repo-helpers.js";
@@ -145,23 +145,56 @@ export function createProcessTurnRecordRepo(db: LeitwerkDb) {
145
145
  .map(rowToProcessTurnRecord);
146
146
  },
147
147
 
148
+ /** Only absent summaries need repair; don't read every retained turn at startup. @internal */
149
+ listMissingSummaries(instanceId: string): ProcessTurnRecord[] {
150
+ return db
151
+ .select(getTableColumns(s.turnRecords))
152
+ .from(s.turnRecords)
153
+ .leftJoin(s.turnSummaries, eq(s.turnSummaries.turnRecordId, s.turnRecords.id))
154
+ .where(and(eq(s.turnRecords.instanceId, instanceId), isNull(s.turnSummaries.turnRecordId)))
155
+ .all()
156
+ .map(rowToProcessTurnRecord);
157
+ },
158
+ /** A stable page, even when new turns arrive or timestamps tie. @internal */
159
+ listPage(
160
+ instanceId: string,
161
+ before?: Pick<ProcessTurnRecord, "startedAt" | "id">,
162
+ limit = 40,
163
+ ): ProcessTurnRecord[] {
164
+ return db
165
+ .select()
166
+ .from(s.turnRecords)
167
+ .where(
168
+ and(
169
+ eq(s.turnRecords.instanceId, instanceId),
170
+ before
171
+ ? sql`(${s.turnRecords.startedAt}, ${s.turnRecords.id}) < (${before.startedAt}, ${before.id})`
172
+ : undefined,
173
+ ),
174
+ )
175
+ .orderBy(desc(s.turnRecords.startedAt), desc(s.turnRecords.id))
176
+ .limit(limit)
177
+ .all()
178
+ .map(rowToProcessTurnRecord)
179
+ .reverse();
180
+ },
181
+
148
182
  /** @internal */
149
183
  getLatestSucceededPrimaryByInstance(instanceId: string): ProcessTurnRecord | null {
150
184
  const row = db
151
185
  .select()
152
186
  .from(s.turnRecords)
153
- .where(eq(s.turnRecords.instanceId, instanceId))
187
+ .where(
188
+ and(
189
+ eq(s.turnRecords.instanceId, instanceId),
190
+ eq(s.turnRecords.status, "succeeded"),
191
+ eq(s.turnRecords.pathType, "primary"),
192
+ ne(s.turnRecords.resultPiEntryId, ""),
193
+ ),
194
+ )
154
195
  .orderBy(desc(s.turnRecords.startedAt))
155
- .all()
156
- .map(rowToProcessTurnRecord)
157
- .find(
158
- (run) =>
159
- run.status === "succeeded" &&
160
- run.pathType === "primary" &&
161
- typeof run.resultPiEntryId === "string" &&
162
- run.resultPiEntryId.length > 0,
163
- );
164
- return row ?? null;
196
+ .get();
197
+ return row ? rowToProcessTurnRecord(row) : null;
165
198
  },
166
199
 
167
200
  /** @internal */
@@ -0,0 +1,63 @@
1
+ import type { PublicationReceipt, PublicationStore } from "@leitwerk-dev/external-writes";
2
+ import { eq } from "drizzle-orm";
3
+ import type { LeitwerkDb } from "./database.js";
4
+ import { topicPublications } from "./schema.js";
5
+
6
+ /** @internal */
7
+ export function createPublicationRepo(db: LeitwerkDb): PublicationStore {
8
+ const store: PublicationStore = {
9
+ publication(key) {
10
+ const row = db.select().from(topicPublications).where(eq(topicPublications.key, key)).get();
11
+ return row ? JSON.parse(row.data) : null;
12
+ },
13
+ publicationByExternalId(externalId) {
14
+ const row = db
15
+ .select()
16
+ .from(topicPublications)
17
+ .where(eq(topicPublications.externalId, externalId))
18
+ .get();
19
+ return row ? JSON.parse(row.data) : null;
20
+ },
21
+ reservePublication(input) {
22
+ return (
23
+ Number(
24
+ db
25
+ .insert(topicPublications)
26
+ .values({
27
+ key: input.key,
28
+ topicId: input.topicId,
29
+ externalId: null,
30
+ data: JSON.stringify(input),
31
+ })
32
+ .onConflictDoNothing()
33
+ .run().changes,
34
+ ) === 1
35
+ );
36
+ },
37
+ finishPublication(key, externalId, url) {
38
+ const current = store.publication(key);
39
+ if (!current || (current.externalId && current.externalId !== externalId))
40
+ throw new Error("Publication receipt conflict");
41
+ const receipt: PublicationReceipt = { ...current, externalId, url };
42
+ db.update(topicPublications)
43
+ .set({ externalId, data: JSON.stringify(receipt) })
44
+ .where(eq(topicPublications.key, key))
45
+ .run();
46
+ },
47
+ releaseRejectedPublication(key) {
48
+ const current = store.publication(key);
49
+ if (current?.externalId) throw new Error("Cannot release a published ticket");
50
+ db.delete(topicPublications).where(eq(topicPublications.key, key)).run();
51
+ },
52
+ markPublicationTriggered(key) {
53
+ const current = store.publication(key);
54
+ if (!current?.externalId)
55
+ throw new Error("Ticket receipt is required before triggering changes");
56
+ db.update(topicPublications)
57
+ .set({ data: JSON.stringify({ ...current, triggered: true }) })
58
+ .where(eq(topicPublications.key, key))
59
+ .run();
60
+ },
61
+ };
62
+ return store;
63
+ }
@@ -1,4 +1,8 @@
1
+ import { createTopicWikiRepo } from "@leitwerk-dev/wiki/server";
1
2
  import { createApiTokenRepo } from "./api-token-repo.js";
3
+ import { createExecutionInspectionRepo } from "./execution-inspection-repo.js";
4
+ import { createPublicationRepo } from "./publication-repo.js";
5
+ import { createScopedSettingsRepo } from "./scoped-settings-repo.js";
2
6
  import { createStartupObservationRepo } from "./startup-observation-repo.js";
3
7
  import { createTurnSummaryRepo } from "./turn-summary-repo.js";
4
8
 
@@ -66,6 +70,14 @@ import { createWorkerLeaseRepo } from "./worker-lease-repo.js";
66
70
 
67
71
  /** @public */
68
72
  export interface RepositoryBundle {
73
+ /** @internal */
74
+ topicWiki: ReturnType<typeof createTopicWikiRepo>;
75
+ /** @internal */
76
+ publications: ReturnType<typeof createPublicationRepo>;
77
+ /** @internal */
78
+ executionInspections: ReturnType<typeof createExecutionInspectionRepo>;
79
+ /** @internal */
80
+ scopedSettings: ReturnType<typeof createScopedSettingsRepo>;
69
81
  /** @internal */
70
82
  startupObservations: ReturnType<typeof createStartupObservationRepo>;
71
83
  /** @internal */
@@ -140,6 +152,11 @@ export function createAllRepos(
140
152
  ): RepositoryBundle {
141
153
  const credentialCipher = options.credentialCipher ?? createUnavailableCredentialCipher();
142
154
  const bundle: RepositoryBundle = {
155
+ topicWiki: createTopicWikiRepo(db),
156
+ publications: createPublicationRepo(db),
157
+ executionInspections: createExecutionInspectionRepo(db),
158
+
159
+ scopedSettings: createScopedSettingsRepo(db),
143
160
  startupObservations: createStartupObservationRepo(db),
144
161
  turnSummaries: createTurnSummaryRepo(db),
145
162
  processes: createProcessInstanceRepo(db),
package/src/db/schema.ts CHANGED
@@ -1,8 +1,13 @@
1
+ import { wikiTopics } from "@leitwerk-dev/wiki/server";
2
+
3
+ export { wikiPages, wikiRevisions, wikiTopics } from "@leitwerk-dev/wiki/server";
4
+
1
5
  import {
2
6
  type MappedItem,
3
7
  type MappedRunStatus,
4
8
  SERIALIZED_SYSTEM_ACTOR,
5
9
  } from "@leitwerk-dev/domain";
10
+ import type { SkillRevisionProvenance } from "@leitwerk-dev/protocol";
6
11
  import type { SessionTransferPhase } from "@leitwerk-dev/session-transfer";
7
12
  import { sql } from "drizzle-orm";
8
13
  import {
@@ -15,6 +20,19 @@ import {
15
20
  uniqueIndex,
16
21
  } from "drizzle-orm/sqlite-core";
17
22
 
23
+ export const topicPublications = sqliteTable(
24
+ "topic_publications",
25
+ {
26
+ key: text("key").primaryKey(),
27
+ topicId: text("topic_id")
28
+ .notNull()
29
+ .references(() => wikiTopics.id),
30
+ externalId: text("external_id"),
31
+ data: text("data").notNull(),
32
+ },
33
+ (table) => [uniqueIndex("idx_topic_publications_external").on(table.externalId)],
34
+ );
35
+
18
36
  export const startupObservations = sqliteTable(
19
37
  "startup_observations",
20
38
  {
@@ -27,6 +45,33 @@ export const startupObservations = sqliteTable(
27
45
  (t) => [uniqueIndex("idx_startup_observations_lease_milestone").on(t.workerLeaseId, t.milestone)],
28
46
  );
29
47
 
48
+ export const inspectionContents = sqliteTable("inspection_contents", {
49
+ digest: text("digest").primaryKey(),
50
+ contentJson: text("content_json").notNull(),
51
+ });
52
+
53
+ export const executionInspections = sqliteTable(
54
+ "execution_inspections",
55
+ {
56
+ sequence: integer("sequence").primaryKey({ autoIncrement: true }),
57
+ id: text("id").notNull(),
58
+ instanceId: text("instance_id")
59
+ .notNull()
60
+ .references(() => processInstances.id, { onDelete: "cascade" }),
61
+ turnRecordId: text("turn_record_id")
62
+ .notNull()
63
+ .references(() => turnRecords.id, { onDelete: "cascade" }),
64
+ startRecordId: text("start_record_id").notNull(),
65
+ workerLeaseId: text("worker_lease_id").notNull(),
66
+ capturedAt: text("captured_at").notNull(),
67
+ factJson: text("fact_json").notNull(),
68
+ },
69
+ (t) => [
70
+ uniqueIndex("idx_execution_inspections_id").on(t.id),
71
+ index("idx_execution_inspections_turn").on(t.instanceId, t.turnRecordId),
72
+ ],
73
+ );
74
+
30
75
  export const processInstances = sqliteTable(
31
76
  "process_instances",
32
77
  {
@@ -99,7 +144,8 @@ export const skills = sqliteTable("skills", {
99
144
  activeRevisionId: text("active_revision_id"),
100
145
  createdAt: text("created_at").notNull(),
101
146
  updatedAt: text("updated_at").notNull(),
102
- registrationKind: text("registration_kind", { enum: ["configuration", "catalog"] })
147
+ ownerExtensionId: text("owner_extension_id"),
148
+ registrationKind: text("registration_kind", { enum: ["configuration", "catalog", "extension"] })
103
149
  .notNull()
104
150
  .default("configuration"),
105
151
  });
@@ -113,6 +159,7 @@ export const skillRevisions = sqliteTable(
113
159
  .references(() => skills.id),
114
160
  bundleDigest: text("bundle_digest").notNull(),
115
161
  bundleBytes: blob("bundle_bytes", { mode: "buffer" }).notNull(),
162
+ provenance: text("provenance_json", { mode: "json" }).$type<SkillRevisionProvenance>(),
116
163
  sourceRevision: text("source_revision"),
117
164
  importedAt: text("imported_at").notNull(),
118
165
  },
@@ -457,6 +504,7 @@ export const turnRecords = sqliteTable(
457
504
  mappedItemIndex: integer("mapped_item_index"),
458
505
  },
459
506
  (t) => [
507
+ index("idx_turn_records_page").on(t.instanceId, t.startedAt, t.id),
460
508
  uniqueIndex("uq_turn_records_instance_id").on(t.instanceId, t.id),
461
509
  uniqueIndex("uq_turn_records_turn_start_record").on(t.turnStartRecordId),
462
510
  index("idx_turn_records_instance").on(t.instanceId),
@@ -565,6 +613,7 @@ export const turnAnnotations = sqliteTable(
565
613
  updatedAt: text("updated_at").notNull(),
566
614
  },
567
615
  (t) => [
616
+ index("idx_turn_annotations_created").on(t.instanceId, t.createdAt),
568
617
  index("idx_turn_annotations_instance").on(t.instanceId),
569
618
  index("idx_turn_annotations_type").on(t.annotationType),
570
619
  uniqueIndex("uq_turn_annotations_instance_key").on(t.instanceId, t.annotationKey),
@@ -595,6 +644,8 @@ export const workerLeases = sqliteTable(
595
644
  readyAt: text("ready_at"),
596
645
  },
597
646
  (t) => [
647
+ index("idx_worker_leases_exited").on(t.instanceId, t.exitedAt),
648
+ index("idx_worker_leases_started").on(t.instanceId, t.startedAt),
598
649
  uniqueIndex("uq_worker_leases_instance_id").on(t.instanceId, t.id),
599
650
  index("idx_worker_leases_instance").on(t.instanceId),
600
651
  index("idx_worker_leases_turn_start").on(t.turnStartRecordId),
@@ -931,3 +982,54 @@ export const sessionSummaries = sqliteTable("session_summaries", {
931
982
  .references(() => processInstances.id, { onDelete: "cascade" }),
932
983
  summaryJson: text("summary_json").notNull(),
933
984
  });
985
+ export const settingsSubjects = sqliteTable(
986
+ "settings_subjects",
987
+ {
988
+ id: text("id").primaryKey(),
989
+ scopeType: text("scope_type").notNull(),
990
+ identity: text("identity").notNull(),
991
+ label: text("label").notNull(),
992
+ contextJson: text("context_json").notNull(),
993
+ schemaVersion: integer("schema_version").notNull(),
994
+ revision: integer("revision").notNull(),
995
+ createdAt: text("created_at").notNull(),
996
+ updatedAt: text("updated_at").notNull(),
997
+ actorJson: text("actor_json").notNull(),
998
+ },
999
+ (t) => [uniqueIndex("uq_settings_subject_identity").on(t.scopeType, t.identity)],
1000
+ );
1001
+
1002
+ export const settingsAliases = sqliteTable("settings_aliases", {
1003
+ alias: text("alias").primaryKey(),
1004
+ subjectId: text("subject_id")
1005
+ .notNull()
1006
+ .references(() => settingsSubjects.id),
1007
+ });
1008
+
1009
+ export const settingsSubjectRedirects = sqliteTable("settings_subject_redirects", {
1010
+ subjectId: text("subject_id")
1011
+ .primaryKey()
1012
+ .references(() => settingsSubjects.id),
1013
+ canonicalSubjectId: text("canonical_subject_id")
1014
+ .notNull()
1015
+ .references(() => settingsSubjects.id),
1016
+ });
1017
+
1018
+ export const settingsOverrides = sqliteTable(
1019
+ "settings_overrides",
1020
+ {
1021
+ subjectId: text("subject_id")
1022
+ .notNull()
1023
+ .references(() => settingsSubjects.id),
1024
+ key: text("key").notNull(),
1025
+ valueJson: text("value_json").notNull(),
1026
+ mode: text("mode").notNull(),
1027
+ reset: integer("reset", { mode: "boolean" }).notNull(),
1028
+ schemaVersion: integer("schema_version").notNull(),
1029
+ revision: integer("revision").notNull(),
1030
+ createdAt: text("created_at").notNull(),
1031
+ updatedAt: text("updated_at").notNull(),
1032
+ actorJson: text("actor_json").notNull(),
1033
+ },
1034
+ (t) => [uniqueIndex("uq_settings_override").on(t.subjectId, t.key)],
1035
+ );