@jungjaehoon/mama-core 2.4.1 → 4.0.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 (371) hide show
  1. package/README.md +76 -239
  2. package/db/migrations/030-case-first-memory-substrate.sql +13 -98
  3. package/db/migrations/034-add-connector-event-scope-columns.sql +9 -13
  4. package/db/migrations/039-add-connector-event-operator-ingest-seq.sql +9 -95
  5. package/db/migrations/062-refresh-connector-event-sequences.sql +9 -113
  6. package/db/migrations/063-refresh-legacy-connector-event-updates.sql +9 -32
  7. package/db/migrations/067-add-connector-event-source-entity-id.sql +9 -13
  8. package/db/migrations/069-create-registry-nodes.sql +52 -0
  9. package/db/migrations/070-record-identity.sql +35 -0
  10. package/db/migrations/071-service-operation-origins.sql +187 -0
  11. package/db/migrations/072-observation-versions.sql +29 -0
  12. package/db/migrations/073-registry-corrections.sql +45 -0
  13. package/db/migrations/074-work-graph-ref-kinds.sql +39 -0
  14. package/db/migrations/075-agent-judgments.sql +58 -0
  15. package/db/migrations/076-scoped-checkpoint-bindings.sql +15 -0
  16. package/db/migrations/077-legacy-record-kind.sql +6 -0
  17. package/db/migrations/078-source-ingest-commands.sql +18 -0
  18. package/db/migrations/079-twin-edge-relations.sql +43 -0
  19. package/db/migrations/080-restore-duration-days.sql +7 -0
  20. package/db/migrations/081-mailbox.sql +61 -0
  21. package/db/migrations/082-commitments-row-id.sql +12 -0
  22. package/db/migrations/083-observation-is-the-evidence.sql +49 -0
  23. package/db/migrations/084-scope-kind-is-not-the-cores-to-list.sql +34 -0
  24. package/db/migrations/085-a-migration-has-a-source.sql +37 -0
  25. package/db/migrations/086-the-mailbox-is-generic.sql +110 -0
  26. package/db/migrations/087-mailbox-payload.sql +5 -0
  27. package/db/migrations/088-native-input-journal.sql +14 -0
  28. package/db/migrations/089-native-turn-receipt-lookup.sql +3 -0
  29. package/db/migrations/090-model-run-native-inputs.sql +29 -0
  30. package/db/migrations/091-native-turn-results.sql +11 -0
  31. package/db/migrations/092-restore-decision-fts.sql +34 -0
  32. package/db/migrations/093-native-turn-primary-kind.sql +14 -0
  33. package/db/migrations/094-commitment-run-provenance.sql +9 -0
  34. package/db/migrations/095-model-run-native-input-identity.sql +39 -0
  35. package/db/migrations/096-drop-connector-event-index-fts.sql +9 -0
  36. package/db/migrations/097-native-input-json-validity.sql +37 -0
  37. package/db/migrations/098-workflow-memory-kind.sql +105 -0
  38. package/dist/action-contracts.d.ts +212 -0
  39. package/dist/action-contracts.js +10 -0
  40. package/dist/api/catalog.d.ts +118 -0
  41. package/dist/api/catalog.js +1756 -0
  42. package/dist/api/dispatch.d.ts +76 -0
  43. package/dist/api/dispatch.js +372 -0
  44. package/dist/canonicalize.d.ts +2 -2
  45. package/dist/canonicalize.js +3 -3
  46. package/dist/client/client.d.ts +33 -0
  47. package/dist/client/client.js +123 -0
  48. package/dist/client/ipc.d.ts +81 -0
  49. package/dist/client/ipc.js +314 -0
  50. package/dist/db-adapter/base-adapter.d.ts +6 -66
  51. package/dist/db-adapter/base-adapter.js +6 -6
  52. package/dist/db-adapter/index.d.ts +5 -5
  53. package/dist/db-adapter/index.js +2 -5
  54. package/dist/db-adapter/node-sqlite-adapter.d.ts +85 -15
  55. package/dist/db-adapter/node-sqlite-adapter.js +1968 -570
  56. package/dist/db-manager.d.ts +53 -97
  57. package/dist/db-manager.js +121 -603
  58. package/dist/embedding/embedder.d.ts +132 -0
  59. package/dist/embedding/embedder.js +299 -0
  60. package/dist/identity/principal-repository.d.ts +2 -2
  61. package/dist/index.d.ts +43 -58
  62. package/dist/index.js +97 -145
  63. package/dist/{context-compile/channel-grant.d.ts → knowledge/access.d.ts} +12 -17
  64. package/dist/knowledge/access.js +663 -0
  65. package/dist/knowledge/case-errors.d.ts +31 -0
  66. package/dist/knowledge/case-errors.js +40 -0
  67. package/dist/{cases/search-rollup.d.ts → knowledge/case-search-rollup.d.ts} +5 -4
  68. package/dist/{cases/search-rollup.js → knowledge/case-search-rollup.js} +6 -8
  69. package/dist/{cases/store.d.ts → knowledge/case-store.d.ts} +3 -6
  70. package/dist/{cases/store.js → knowledge/case-store.js} +7 -42
  71. package/dist/{cases/timeline-range.d.ts → knowledge/case-timeline-range.d.ts} +3 -3
  72. package/dist/{cases/timeline-range.js → knowledge/case-timeline-range.js} +47 -25
  73. package/dist/{cases/types.d.ts → knowledge/case-types.d.ts} +8 -2
  74. package/dist/{cases/types.js → knowledge/case-types.js} +1 -1
  75. package/dist/knowledge/commitments.d.ts +188 -0
  76. package/dist/knowledge/commitments.js +370 -0
  77. package/dist/knowledge/decision-edges.d.ts +70 -0
  78. package/dist/knowledge/decision-edges.js +123 -0
  79. package/dist/{agent-graph/types.d.ts → knowledge/graph-query.d.ts} +80 -70
  80. package/dist/knowledge/graph-query.js +1585 -0
  81. package/dist/knowledge/identity.d.ts +16 -0
  82. package/dist/knowledge/identity.js +22 -0
  83. package/dist/knowledge/index.d.ts +47 -0
  84. package/dist/knowledge/index.js +90 -0
  85. package/dist/knowledge/judgments.d.ts +118 -0
  86. package/dist/knowledge/judgments.js +808 -0
  87. package/dist/knowledge/observations.d.ts +160 -0
  88. package/dist/knowledge/observations.js +449 -0
  89. package/dist/knowledge/question-type.d.ts +34 -0
  90. package/dist/knowledge/question-type.js +70 -0
  91. package/dist/{search → knowledge}/ranker-features.js +1 -1
  92. package/dist/{search → knowledge}/search-quality.d.ts +0 -1
  93. package/dist/knowledge/search.d.ts +38 -0
  94. package/dist/knowledge/search.js +91 -0
  95. package/dist/knowledge/source-ingest.d.ts +65 -0
  96. package/dist/knowledge/source-ingest.js +174 -0
  97. package/dist/{edges/types.d.ts → knowledge/twin-edge-types.d.ts} +31 -4
  98. package/dist/{edges/types.js → knowledge/twin-edge-types.js} +13 -2
  99. package/dist/knowledge/work-dates.d.ts +49 -0
  100. package/dist/knowledge/work-dates.js +120 -0
  101. package/dist/mama-api.d.ts +114 -778
  102. package/dist/mama-api.js +313 -2461
  103. package/dist/memory/api.d.ts +264 -24
  104. package/dist/memory/api.js +1633 -843
  105. package/dist/memory/bootstrap-builder.d.ts +2 -1
  106. package/dist/memory/bootstrap-builder.js +5 -5
  107. package/dist/memory/channel-summary-state-store.d.ts +3 -2
  108. package/dist/memory/channel-summary-state-store.js +53 -51
  109. package/dist/memory/channel-summary-store.d.ts +5 -3
  110. package/dist/memory/channel-summary-store.js +3 -8
  111. package/dist/memory/dashboard-read.d.ts +46 -0
  112. package/dist/memory/dashboard-read.js +94 -0
  113. package/dist/memory/event-store.d.ts +3 -3
  114. package/dist/memory/event-store.js +3 -10
  115. package/dist/memory/finding-store.d.ts +3 -2
  116. package/dist/memory/finding-store.js +2 -7
  117. package/dist/memory/graph-read.d.ts +52 -0
  118. package/dist/memory/graph-read.js +130 -0
  119. package/dist/memory/judgment-types.d.ts +394 -0
  120. package/dist/memory/judgment-types.js +16 -0
  121. package/dist/memory/provenance-audit.d.ts +5 -2
  122. package/dist/memory/provenance-audit.js +8 -14
  123. package/dist/memory/provenance-live.d.ts +141 -0
  124. package/dist/memory/provenance-live.js +409 -0
  125. package/dist/memory/provenance-query.d.ts +5 -4
  126. package/dist/memory/provenance-query.js +21 -29
  127. package/dist/memory/provenance-resolver.d.ts +191 -0
  128. package/dist/memory/provenance-resolver.js +155 -0
  129. package/dist/memory/provenance.d.ts +1 -11
  130. package/dist/memory/provenance.js +2 -33
  131. package/dist/memory/recall-sanitize.d.ts +55 -0
  132. package/dist/memory/recall-sanitize.js +144 -0
  133. package/dist/memory/secret-filter.d.ts +32 -0
  134. package/dist/memory/secret-filter.js +126 -0
  135. package/dist/memory/truth-store.d.ts +2 -1
  136. package/dist/memory/truth-store.js +1 -4
  137. package/dist/memory/types.d.ts +74 -24
  138. package/dist/memory/types.js +75 -5
  139. package/dist/memory/write-adapters.d.ts +98 -0
  140. package/dist/memory/write-adapters.js +242 -0
  141. package/dist/operations/owner-action-effects.d.ts +53 -0
  142. package/dist/operations/owner-action-effects.js +96 -0
  143. package/dist/provenance/source-ref.d.ts +1 -1
  144. package/dist/provenance/source-ref.js +0 -2
  145. package/dist/registry/corrections.d.ts +31 -0
  146. package/dist/registry/corrections.js +332 -0
  147. package/dist/registry/record-identity.d.ts +49 -0
  148. package/dist/registry/record-identity.js +133 -0
  149. package/dist/registry/store.d.ts +101 -0
  150. package/dist/registry/store.js +395 -0
  151. package/dist/registry/types.d.ts +28 -0
  152. package/dist/registry/types.js +5 -0
  153. package/dist/relevance-scorer.js +2 -2
  154. package/dist/runtime/agent-event-bus.d.ts +50 -0
  155. package/dist/runtime/agent-event-bus.js +101 -0
  156. package/dist/runtime/drivers/claude-cli-wrapper.d.ts +155 -0
  157. package/dist/runtime/drivers/claude-cli-wrapper.js +392 -0
  158. package/dist/runtime/drivers/cli-arg-redaction.d.ts +2 -0
  159. package/dist/runtime/drivers/cli-arg-redaction.js +18 -0
  160. package/dist/runtime/drivers/cli-secret-redaction.d.ts +17 -0
  161. package/dist/runtime/drivers/cli-secret-redaction.js +126 -0
  162. package/dist/runtime/drivers/codex-app-server-process.d.ts +277 -0
  163. package/dist/runtime/drivers/codex-app-server-process.js +2342 -0
  164. package/dist/runtime/drivers/codex-auxiliary-tools.d.ts +17 -0
  165. package/dist/runtime/drivers/codex-auxiliary-tools.js +267 -0
  166. package/dist/runtime/drivers/codex-home.d.ts +20 -0
  167. package/dist/runtime/drivers/codex-home.js +674 -0
  168. package/dist/runtime/drivers/codex-thread-registry.d.ts +63 -0
  169. package/dist/runtime/drivers/codex-thread-registry.js +433 -0
  170. package/dist/runtime/drivers/persistent-cli-adapter.d.ts +160 -0
  171. package/dist/runtime/drivers/persistent-cli-adapter.js +396 -0
  172. package/dist/runtime/drivers/persistent-cli-process.d.ts +424 -0
  173. package/dist/runtime/drivers/persistent-cli-process.js +1543 -0
  174. package/dist/runtime/drivers/types.d.ts +456 -0
  175. package/dist/runtime/drivers/types.js +110 -0
  176. package/dist/runtime/mailbox.d.ts +223 -0
  177. package/dist/runtime/mailbox.js +582 -0
  178. package/dist/runtime/model-run-store.d.ts +28 -0
  179. package/dist/{model-runs/store.js → runtime/model-run-store.js} +81 -41
  180. package/dist/{model-runs/types.d.ts → runtime/model-run-types.d.ts} +33 -4
  181. package/dist/{model-runs/types.js → runtime/model-run-types.js} +1 -1
  182. package/dist/runtime/native-effect-observer.d.ts +22 -0
  183. package/dist/runtime/native-effect-observer.js +103 -0
  184. package/dist/runtime/native-input-journal.d.ts +46 -0
  185. package/dist/runtime/native-input-journal.js +308 -0
  186. package/dist/runtime/native-prompt.d.ts +118 -0
  187. package/dist/runtime/native-prompt.js +496 -0
  188. package/dist/runtime/native-session.d.ts +10 -0
  189. package/dist/{agent-graph/index.js → runtime/native-session.js} +9 -6
  190. package/dist/runtime/native-tool-trace-observer.d.ts +5 -0
  191. package/dist/runtime/native-tool-trace-observer.js +65 -0
  192. package/dist/runtime/native-turn.d.ts +272 -0
  193. package/dist/runtime/native-turn.js +1041 -0
  194. package/dist/runtime/operations.d.ts +236 -0
  195. package/dist/runtime/operations.js +565 -0
  196. package/dist/runtime/post-tool-handler.d.ts +74 -0
  197. package/dist/runtime/post-tool-handler.js +137 -0
  198. package/dist/runtime/prompt-layers.d.ts +126 -0
  199. package/dist/runtime/prompt-layers.js +239 -0
  200. package/dist/runtime/runtime-process.d.ts +102 -0
  201. package/dist/runtime/runtime-process.js +206 -0
  202. package/dist/runtime/runtime.d.ts +278 -0
  203. package/dist/runtime/runtime.js +563 -0
  204. package/dist/runtime/session-pool.d.ts +176 -0
  205. package/dist/runtime/session-pool.js +369 -0
  206. package/dist/runtime/stimulus-payload.d.ts +5 -0
  207. package/dist/runtime/stimulus-payload.js +50 -0
  208. package/dist/runtime/subagent-bridge.d.ts +24 -0
  209. package/dist/{agent-graph/types.js → runtime/subagent-bridge.js} +1 -1
  210. package/dist/runtime/text-completion.d.ts +22 -0
  211. package/dist/{agent-situation/types.js → runtime/text-completion.js} +1 -1
  212. package/dist/runtime/token-estimator.d.ts +25 -0
  213. package/dist/runtime/token-estimator.js +75 -0
  214. package/dist/runtime/tool-trace-store.d.ts +22 -0
  215. package/dist/{model-runs → runtime}/tool-trace-store.js +46 -27
  216. package/dist/runtime/trace-summary.d.ts +5 -0
  217. package/dist/runtime/trace-summary.js +74 -0
  218. package/dist/runtime/turn-text.d.ts +23 -0
  219. package/dist/runtime/turn-text.js +41 -0
  220. package/dist/storage/database.d.ts +67 -0
  221. package/dist/storage/database.js +158 -0
  222. package/package.json +20 -34
  223. package/dist/agent-graph/alias-write.d.ts +0 -3
  224. package/dist/agent-graph/alias-write.js +0 -234
  225. package/dist/agent-graph/entity-resolve.d.ts +0 -3
  226. package/dist/agent-graph/entity-resolve.js +0 -271
  227. package/dist/agent-graph/errors.d.ts +0 -4
  228. package/dist/agent-graph/errors.js +0 -11
  229. package/dist/agent-graph/graph-query.d.ts +0 -5
  230. package/dist/agent-graph/graph-query.js +0 -360
  231. package/dist/agent-graph/index.d.ts +0 -6
  232. package/dist/agent-situation/builder.d.ts +0 -8
  233. package/dist/agent-situation/builder.js +0 -239
  234. package/dist/agent-situation/cache-key.d.ts +0 -4
  235. package/dist/agent-situation/cache-key.js +0 -64
  236. package/dist/agent-situation/index.d.ts +0 -7
  237. package/dist/agent-situation/index.js +0 -28
  238. package/dist/agent-situation/packet-store.d.ts +0 -27
  239. package/dist/agent-situation/packet-store.js +0 -228
  240. package/dist/agent-situation/ranking-policy.d.ts +0 -18
  241. package/dist/agent-situation/ranking-policy.js +0 -75
  242. package/dist/agent-situation/source-readers.d.ts +0 -52
  243. package/dist/agent-situation/source-readers.js +0 -300
  244. package/dist/agent-situation/types.d.ts +0 -195
  245. package/dist/cases/wiki-page-index.d.ts +0 -37
  246. package/dist/cases/wiki-page-index.js +0 -201
  247. package/dist/config-loader.d.ts +0 -68
  248. package/dist/config-loader.js +0 -239
  249. package/dist/connectors/event-index.d.ts +0 -24
  250. package/dist/connectors/event-index.js +0 -245
  251. package/dist/connectors/raw-query.d.ts +0 -40
  252. package/dist/connectors/raw-query.js +0 -412
  253. package/dist/connectors/types.d.ts +0 -117
  254. package/dist/connectors/types.js +0 -3
  255. package/dist/context-compile/boundary-defaults.d.ts +0 -12
  256. package/dist/context-compile/boundary-defaults.js +0 -105
  257. package/dist/context-compile/channel-grant.js +0 -66
  258. package/dist/context-compile/compiler-policy.d.ts +0 -39
  259. package/dist/context-compile/compiler-policy.js +0 -147
  260. package/dist/context-compile/compiler.d.ts +0 -18
  261. package/dist/context-compile/compiler.js +0 -404
  262. package/dist/context-compile/index.d.ts +0 -10
  263. package/dist/context-compile/index.js +0 -26
  264. package/dist/context-compile/packet-store.d.ts +0 -8
  265. package/dist/context-compile/packet-store.js +0 -239
  266. package/dist/context-compile/ref.d.ts +0 -7
  267. package/dist/context-compile/ref.js +0 -102
  268. package/dist/context-compile/source-readers.d.ts +0 -70
  269. package/dist/context-compile/source-readers.js +0 -840
  270. package/dist/context-compile/types.d.ts +0 -155
  271. package/dist/context-compile/types.js +0 -11
  272. package/dist/context-compile/visibility.d.ts +0 -21
  273. package/dist/context-compile/visibility.js +0 -224
  274. package/dist/decision-tracker.d.ts +0 -206
  275. package/dist/decision-tracker.js +0 -481
  276. package/dist/edges/ref-validation.d.ts +0 -7
  277. package/dist/edges/ref-validation.js +0 -321
  278. package/dist/edges/store.d.ts +0 -8
  279. package/dist/edges/store.js +0 -129
  280. package/dist/embedding-client.d.ts +0 -28
  281. package/dist/embedding-client.js +0 -53
  282. package/dist/embedding-server/index.d.ts +0 -67
  283. package/dist/embedding-server/index.js +0 -405
  284. package/dist/embedding-server/mobile/auth.d.ts +0 -44
  285. package/dist/embedding-server/mobile/auth.js +0 -150
  286. package/dist/embedding-server/mobile/daemon.d.ts +0 -129
  287. package/dist/embedding-server/mobile/daemon.js +0 -313
  288. package/dist/embedding-server/mobile/output-parser.d.ts +0 -115
  289. package/dist/embedding-server/mobile/output-parser.js +0 -241
  290. package/dist/embedding-server/mobile/session-api.d.ts +0 -57
  291. package/dist/embedding-server/mobile/session-api.js +0 -261
  292. package/dist/embedding-server/mobile/session-manager.d.ts +0 -138
  293. package/dist/embedding-server/mobile/session-manager.js +0 -378
  294. package/dist/embedding-server/mobile/websocket-handler.d.ts +0 -137
  295. package/dist/embedding-server/mobile/websocket-handler.js +0 -486
  296. package/dist/embeddings.d.ts +0 -68
  297. package/dist/embeddings.js +0 -244
  298. package/dist/entities/audit-metrics.d.ts +0 -68
  299. package/dist/entities/audit-metrics.js +0 -124
  300. package/dist/entities/candidate-generator.d.ts +0 -8
  301. package/dist/entities/candidate-generator.js +0 -24
  302. package/dist/entities/entity-linked-decision-counts.d.ts +0 -2
  303. package/dist/entities/entity-linked-decision-counts.js +0 -29
  304. package/dist/entities/entity-list.d.ts +0 -22
  305. package/dist/entities/entity-list.js +0 -3
  306. package/dist/entities/entity-orphan-list.d.ts +0 -17
  307. package/dist/entities/entity-orphan-list.js +0 -3
  308. package/dist/entities/entity-search.d.ts +0 -20
  309. package/dist/entities/entity-search.js +0 -3
  310. package/dist/entities/errors.d.ts +0 -55
  311. package/dist/entities/errors.js +0 -100
  312. package/dist/entities/lineage-store.d.ts +0 -28
  313. package/dist/entities/lineage-store.js +0 -204
  314. package/dist/entities/normalization.d.ts +0 -14
  315. package/dist/entities/normalization.js +0 -63
  316. package/dist/entities/policy-store.d.ts +0 -8
  317. package/dist/entities/policy-store.js +0 -75
  318. package/dist/entities/policy-types.d.ts +0 -72
  319. package/dist/entities/policy-types.js +0 -59
  320. package/dist/entities/projection.d.ts +0 -8
  321. package/dist/entities/projection.js +0 -82
  322. package/dist/entities/provenance-query.d.ts +0 -32
  323. package/dist/entities/provenance-query.js +0 -3
  324. package/dist/entities/read-identity.d.ts +0 -31
  325. package/dist/entities/read-identity.js +0 -264
  326. package/dist/entities/recall-bridge.d.ts +0 -5
  327. package/dist/entities/recall-bridge.js +0 -171
  328. package/dist/entities/resolution-engine.d.ts +0 -8
  329. package/dist/entities/resolution-engine.js +0 -3
  330. package/dist/entities/rollback-preview.d.ts +0 -35
  331. package/dist/entities/rollback-preview.js +0 -3
  332. package/dist/entities/source-locator.d.ts +0 -3
  333. package/dist/entities/source-locator.js +0 -32
  334. package/dist/entities/store.d.ts +0 -69
  335. package/dist/entities/store.js +0 -544
  336. package/dist/entities/types.d.ts +0 -166
  337. package/dist/entities/types.js +0 -30
  338. package/dist/memory/extraction-prompt.d.ts +0 -4
  339. package/dist/memory/extraction-prompt.js +0 -89
  340. package/dist/memory/scope-backfill.d.ts +0 -14
  341. package/dist/memory/scope-backfill.js +0 -3
  342. package/dist/memory/scope-store.d.ts +0 -4
  343. package/dist/memory/scope-store.js +0 -9
  344. package/dist/memory-store.d.ts +0 -87
  345. package/dist/memory-store.js +0 -78
  346. package/dist/model-runs/store.d.ts +0 -13
  347. package/dist/model-runs/tool-trace-store.d.ts +0 -8
  348. package/dist/notification-manager.d.ts +0 -7
  349. package/dist/notification-manager.js +0 -12
  350. package/dist/outcome-tracker.d.ts +0 -151
  351. package/dist/outcome-tracker.js +0 -271
  352. package/dist/query-intent.d.ts +0 -23
  353. package/dist/query-intent.js +0 -114
  354. package/dist/runtime/trusted-provenance.d.ts +0 -3
  355. package/dist/runtime/trusted-provenance.js +0 -6
  356. package/dist/search/question-type.d.ts +0 -5
  357. package/dist/search/question-type.js +0 -41
  358. package/dist/test-utils.d.ts +0 -80
  359. package/dist/test-utils.js +0 -218
  360. package/dist/tier-validator.d.ts +0 -43
  361. package/dist/tier-validator.js +0 -159
  362. package/dist/time-formatter.d.ts +0 -25
  363. package/dist/time-formatter.js +0 -93
  364. /package/dist/{search → knowledge}/feedback-store.d.ts +0 -0
  365. /package/dist/{search → knowledge}/feedback-store.js +0 -0
  366. /package/dist/{search → knowledge}/ranker-features.d.ts +0 -0
  367. /package/dist/{search → knowledge}/ranker-rescore.d.ts +0 -0
  368. /package/dist/{search → knowledge}/ranker-rescore.js +0 -0
  369. /package/dist/{search → knowledge}/ranker-trainer.d.ts +0 -0
  370. /package/dist/{search → knowledge}/ranker-trainer.js +0 -0
  371. /package/dist/{search → knowledge}/search-quality.js +0 -0
@@ -1,114 +1,10 @@
1
- ALTER TABLE connector_event_index
2
- ADD COLUMN operator_observation_seq INTEGER CHECK (
3
- operator_observation_seq IS NULL OR operator_observation_seq >= 1
4
- );
1
+ -- Retired: this migration declared the observation sequence on the connector event index.
2
+ --
3
+ -- The index moved to the package that has connectors. Three of the four consumers
4
+ -- of this core have none, and were running these statements against tables they
5
+ -- never write. The schema is declared whole in standalone/db/migrations/001.
6
+ --
7
+ -- The file stays, and the number stays claimed: databases in the field recorded
8
+ -- 62 as applied, and a number that comes back meaning something else is worse
9
+ -- than a number that means nothing.
5
10
 
6
- CREATE TABLE IF NOT EXISTS connector_event_index_observation_cursors (
7
- source_connector TEXT PRIMARY KEY,
8
- next_seq INTEGER NOT NULL CHECK (next_seq >= 1)
9
- );
10
-
11
- WITH ranked AS (
12
- SELECT event_index_id,
13
- ROW_NUMBER() OVER (
14
- PARTITION BY source_connector
15
- ORDER BY source_timestamp_ms, rowid
16
- ) AS seq
17
- FROM connector_event_index
18
- )
19
- UPDATE connector_event_index
20
- SET operator_observation_seq = (
21
- SELECT seq FROM ranked WHERE ranked.event_index_id = connector_event_index.event_index_id
22
- );
23
-
24
- INSERT INTO connector_event_index_observation_cursors (source_connector, next_seq)
25
- SELECT source_connector, MAX(operator_observation_seq) + 1
26
- FROM connector_event_index
27
- GROUP BY source_connector
28
- ON CONFLICT(source_connector) DO UPDATE SET next_seq = CASE
29
- WHEN connector_event_index_observation_cursors.next_seq < excluded.next_seq
30
- THEN excluded.next_seq
31
- ELSE connector_event_index_observation_cursors.next_seq
32
- END;
33
-
34
- CREATE UNIQUE INDEX IF NOT EXISTS idx_connector_event_index_observation_seq
35
- ON connector_event_index(source_connector, operator_observation_seq)
36
- WHERE operator_observation_seq IS NOT NULL;
37
-
38
- CREATE TRIGGER IF NOT EXISTS trg_connector_event_index_operator_ingest_seq_au
39
- AFTER UPDATE OF operator_ingest_seq ON connector_event_index
40
- WHEN NEW.operator_ingest_seq IS NULL AND OLD.operator_ingest_seq IS NOT NULL
41
- BEGIN
42
- INSERT INTO connector_event_index_operator_seq_cursors
43
- (source_connector, channel, next_seq)
44
- VALUES (NEW.source_connector, COALESCE(NEW.channel, ''), 1)
45
- ON CONFLICT(source_connector, channel) DO NOTHING;
46
- UPDATE connector_event_index
47
- SET operator_ingest_seq = (
48
- SELECT next_seq FROM connector_event_index_operator_seq_cursors
49
- WHERE source_connector = NEW.source_connector
50
- AND channel = COALESCE(NEW.channel, '')
51
- )
52
- WHERE event_index_id = NEW.event_index_id;
53
- UPDATE connector_event_index_operator_seq_cursors
54
- SET next_seq = next_seq + 1
55
- WHERE source_connector = NEW.source_connector
56
- AND channel = COALESCE(NEW.channel, '');
57
- END;
58
-
59
- CREATE TRIGGER IF NOT EXISTS trg_connector_event_index_observation_seq_ai
60
- AFTER INSERT ON connector_event_index
61
- WHEN NEW.operator_observation_seq IS NULL
62
- BEGIN
63
- INSERT INTO connector_event_index_observation_cursors
64
- (source_connector, next_seq)
65
- VALUES (NEW.source_connector, 1)
66
- ON CONFLICT(source_connector) DO NOTHING;
67
- UPDATE connector_event_index
68
- SET operator_observation_seq = (
69
- SELECT next_seq FROM connector_event_index_observation_cursors
70
- WHERE source_connector = NEW.source_connector
71
- )
72
- WHERE event_index_id = NEW.event_index_id;
73
- UPDATE connector_event_index_observation_cursors
74
- SET next_seq = next_seq + 1
75
- WHERE source_connector = NEW.source_connector;
76
- END;
77
-
78
- CREATE TRIGGER IF NOT EXISTS trg_connector_event_index_observation_seq_au
79
- AFTER UPDATE OF operator_observation_seq ON connector_event_index
80
- WHEN NEW.operator_observation_seq IS NULL AND OLD.operator_observation_seq IS NOT NULL
81
- BEGIN
82
- INSERT INTO connector_event_index_observation_cursors
83
- (source_connector, next_seq)
84
- VALUES (NEW.source_connector, 1)
85
- ON CONFLICT(source_connector) DO NOTHING;
86
- UPDATE connector_event_index
87
- SET operator_observation_seq = (
88
- SELECT next_seq FROM connector_event_index_observation_cursors
89
- WHERE source_connector = NEW.source_connector
90
- )
91
- WHERE event_index_id = NEW.event_index_id;
92
- UPDATE connector_event_index_observation_cursors
93
- SET next_seq = next_seq + 1
94
- WHERE source_connector = NEW.source_connector;
95
- END;
96
-
97
- CREATE TRIGGER IF NOT EXISTS trg_connector_event_index_observation_seq_explicit_ai
98
- AFTER INSERT ON connector_event_index
99
- WHEN NEW.operator_observation_seq IS NOT NULL
100
- BEGIN
101
- INSERT INTO connector_event_index_observation_cursors
102
- (source_connector, next_seq)
103
- VALUES (NEW.source_connector, 1)
104
- ON CONFLICT(source_connector) DO NOTHING;
105
- UPDATE connector_event_index_observation_cursors
106
- SET next_seq = CASE
107
- WHEN next_seq <= NEW.operator_observation_seq THEN NEW.operator_observation_seq + 1
108
- ELSE next_seq
109
- END
110
- WHERE source_connector = NEW.source_connector;
111
- END;
112
-
113
- INSERT INTO schema_version (version, description)
114
- VALUES (62, 'Refresh connector event delivery and observation sequences');
@@ -1,33 +1,10 @@
1
- SELECT content_hash, metadata_json, source_timestamp_ms, source_type, channel,
2
- operator_ingest_seq, operator_observation_seq
3
- FROM connector_event_index
4
- LIMIT 0;
1
+ -- Retired: this migration declared the legacy content refresh trigger on the connector event index.
2
+ --
3
+ -- The index moved to the package that has connectors. Three of the four consumers
4
+ -- of this core have none, and were running these statements against tables they
5
+ -- never write. The schema is declared whole in standalone/db/migrations/001.
6
+ --
7
+ -- The file stays, and the number stays claimed: databases in the field recorded
8
+ -- 63 as applied, and a number that comes back meaning something else is worse
9
+ -- than a number that means nothing.
5
10
 
6
- CREATE TRIGGER IF NOT EXISTS trg_connector_event_index_legacy_content_refresh_au
7
- AFTER UPDATE OF content_hash, metadata_json, source_timestamp_ms, source_type, channel
8
- ON connector_event_index
9
- WHEN (
10
- OLD.content_hash IS NOT NEW.content_hash
11
- OR OLD.metadata_json IS NOT NEW.metadata_json
12
- OR OLD.source_timestamp_ms IS NOT NEW.source_timestamp_ms
13
- OR OLD.source_type IS NOT NEW.source_type
14
- OR OLD.channel IS NOT NEW.channel
15
- ) AND (
16
- NEW.operator_ingest_seq IS OLD.operator_ingest_seq
17
- OR NEW.operator_observation_seq IS OLD.operator_observation_seq
18
- )
19
- BEGIN
20
- UPDATE connector_event_index
21
- SET operator_ingest_seq = CASE
22
- WHEN NEW.operator_ingest_seq IS OLD.operator_ingest_seq THEN NULL
23
- ELSE NEW.operator_ingest_seq
24
- END,
25
- operator_observation_seq = CASE
26
- WHEN NEW.operator_observation_seq IS OLD.operator_observation_seq THEN NULL
27
- ELSE NEW.operator_observation_seq
28
- END
29
- WHERE event_index_id = NEW.event_index_id;
30
- END;
31
-
32
- INSERT OR IGNORE INTO schema_version (version, description)
33
- VALUES (63, 'Refresh sequences for legacy connector event updates');
@@ -1,14 +1,10 @@
1
- -- Migration 067: give connector_event_index a first-class source_entity_id so an agent can read an
2
- -- entity's change history (the revisions save() preserves) through the same grant-bounded core index
3
- -- it already searches. Previously sourceEntityId lived only inside metadata_json, with no by-entity
4
- -- query. Additive and backward-compatible: existing rows are backfilled from metadata_json.
5
- ALTER TABLE connector_event_index ADD COLUMN source_entity_id TEXT;
1
+ -- Retired: this migration declared the source entity id on the connector event index.
2
+ --
3
+ -- The index moved to the package that has connectors. Three of the four consumers
4
+ -- of this core have none, and were running these statements against tables they
5
+ -- never write. The schema is declared whole in standalone/db/migrations/001.
6
+ --
7
+ -- The file stays, and the number stays claimed: databases in the field recorded
8
+ -- 67 as applied, and a number that comes back meaning something else is worse
9
+ -- than a number that means nothing.
6
10
 
7
- UPDATE connector_event_index
8
- SET source_entity_id = json_extract(metadata_json, '$.sourceEntityId')
9
- WHERE source_entity_id IS NULL
10
- AND metadata_json IS NOT NULL
11
- AND json_extract(metadata_json, '$.sourceEntityId') IS NOT NULL;
12
-
13
- CREATE INDEX IF NOT EXISTS idx_connector_event_source_entity
14
- ON connector_event_index(source_connector, source_entity_id);
@@ -0,0 +1,52 @@
1
+ -- Registry: the one place that says "these names are the same thing".
2
+ --
3
+ -- A work item or a person is a node; every spelling it is known by is an alias row. Records
4
+ -- and tasks point at the node, so a fact filed under one spelling and a task titled with
5
+ -- another still join.
6
+ --
7
+ -- Merging is a decision, never a similarity guess. Alias uniqueness is keyed by kind and
8
+ -- visibility scope, so a contested alias inside one scope is explicit while separate scopes
9
+ -- may use the same spelling independently.
10
+
11
+ CREATE TABLE IF NOT EXISTS registry_nodes (
12
+ id TEXT PRIMARY KEY,
13
+ kind TEXT NOT NULL CHECK (kind IN ('item', 'person', 'client')),
14
+ name TEXT NOT NULL,
15
+ -- Set when an owner correction splits one item into the files it really covers.
16
+ parent_id TEXT REFERENCES registry_nodes(id) ON DELETE SET NULL,
17
+ -- Set when this node was merged away; resolution follows the pointer to the survivor.
18
+ merged_into TEXT REFERENCES registry_nodes(id) ON DELETE SET NULL,
19
+ merge_reason TEXT,
20
+ note TEXT,
21
+ created_at INTEGER NOT NULL,
22
+ updated_at INTEGER NOT NULL
23
+ );
24
+
25
+ CREATE INDEX IF NOT EXISTS idx_registry_nodes_kind ON registry_nodes(kind, merged_into);
26
+ CREATE INDEX IF NOT EXISTS idx_registry_nodes_parent ON registry_nodes(parent_id);
27
+
28
+ CREATE TABLE IF NOT EXISTS registry_aliases (
29
+ node_id TEXT NOT NULL REFERENCES registry_nodes(id) ON DELETE CASCADE,
30
+ kind TEXT NOT NULL CHECK (kind IN ('item', 'person', 'client')),
31
+ -- Case- and space-normalised at write time; the display form stays in `alias_display`.
32
+ alias TEXT NOT NULL,
33
+ alias_display TEXT NOT NULL,
34
+ scope_kind TEXT NOT NULL CHECK (scope_kind IN ('global', 'user', 'channel', 'project')),
35
+ scope_id TEXT NOT NULL,
36
+ created_at INTEGER NOT NULL,
37
+ PRIMARY KEY (kind, alias, scope_kind, scope_id)
38
+ );
39
+
40
+ CREATE INDEX IF NOT EXISTS idx_registry_aliases_node ON registry_aliases(node_id);
41
+ CREATE INDEX IF NOT EXISTS idx_registry_aliases_scope
42
+ ON registry_aliases(kind, alias, scope_kind, scope_id);
43
+
44
+ CREATE TABLE IF NOT EXISTS registry_scope_bindings (
45
+ node_id TEXT NOT NULL REFERENCES registry_nodes(id) ON DELETE CASCADE,
46
+ scope_kind TEXT NOT NULL CHECK (scope_kind IN ('global', 'user', 'channel', 'project')),
47
+ scope_id TEXT NOT NULL,
48
+ PRIMARY KEY (node_id, scope_kind, scope_id)
49
+ );
50
+
51
+ CREATE INDEX IF NOT EXISTS idx_registry_scope_lookup
52
+ ON registry_scope_bindings(scope_kind, scope_id, node_id);
@@ -0,0 +1,35 @@
1
+ -- What a record is about, and who was involved, as references instead of prose.
2
+ --
3
+ -- The only statement of subject used to be the `topic` text. `item_id` points at a
4
+ -- registry node, so two spellings of one item join.
5
+ --
6
+ -- `record_actors` is a table rather than a column because one record routinely involves
7
+ -- several people in different roles - the person who did the work, the one who relayed it,
8
+ -- the client contact. The single `assignee` slot on a task was losing that distinction, and
9
+ -- putting it back as one column would lose it again. The role is free text: production work
10
+ -- and a booking do not share a role vocabulary, and the registry holds the person while the
11
+ -- role belongs to this record.
12
+ --
13
+ -- No foreign key to registry_nodes: the store validates the node and its kind before
14
+ -- writing, and a merge rewrites nothing (readers canonicalise through merged_into), so a
15
+ -- database-level constraint would only add a failure mode without adding a guarantee.
16
+
17
+ ALTER TABLE decisions ADD COLUMN item_id TEXT;
18
+
19
+ -- Only the item. A composite index over
20
+ -- COALESCE(event_datetime, created_at) was tried first and broke recovery of databases whose
21
+ -- schema_version is newer than their structure - event_datetime arrives in migration 030 and
22
+ -- is not guaranteed to exist when this one runs.
23
+ CREATE INDEX IF NOT EXISTS idx_decisions_item ON decisions(item_id);
24
+
25
+ CREATE TABLE IF NOT EXISTS record_actors (
26
+ record_id TEXT NOT NULL REFERENCES decisions(id) ON DELETE CASCADE,
27
+ person_id TEXT NOT NULL,
28
+ role TEXT NOT NULL,
29
+ -- Insertion order, so the actor list reads back the way the agent stated it.
30
+ position INTEGER NOT NULL DEFAULT 0,
31
+ created_at INTEGER NOT NULL,
32
+ PRIMARY KEY (record_id, person_id, role)
33
+ );
34
+
35
+ CREATE INDEX IF NOT EXISTS idx_record_actors_person ON record_actors(person_id, record_id);
@@ -0,0 +1,187 @@
1
+ -- Migration 071: a truthful service/CLI operation can trace itself.
2
+ --
3
+ -- tool_traces was model-only: model_run_id was NOT NULL with an FK to
4
+ -- model_runs, so a host operation could be recorded only by forging a fake
5
+ -- model run. This migration relaxes that: model_run_id becomes nullable, and
6
+ -- an operation-origin row is anchored instead by a nonempty operation_id and
7
+ -- actor_principal_id. A CHECK forbids a row with neither origin. Legacy rows
8
+ -- keep their model id and semantics; the model_runs FK is preserved.
9
+ --
10
+ -- WHY A TABLE REBUILD: dropping the NOT NULL on model_run_id and adding a CHECK
11
+ -- cannot be done with ALTER; SQLite requires create/copy/drop/rename. This SQL
12
+ -- file rebuilds the canonical (post-068) column set and is what the plain
13
+ -- applyAll test path runs. The migration runner special-cases version 71 with a
14
+ -- dynamic rebuild that additionally preserves any extra runtime columns/indexes/
15
+ -- triggers a live database may carry (see node-sqlite-adapter). Both produce the
16
+ -- same canonical shape. The rebuild copies every existing row and re-creates
17
+ -- every 033/061/068 index; nothing is dropped.
18
+ --
19
+ -- GUARD: this canonical-only direct-SQL path can express ONLY the exact pre-071
20
+ -- canonical tool_traces (the fresh 033/061/068 chain: 17 columns with fixed
21
+ -- types/NOT NULL/DEFAULT/PK, one FK to model_runs, the PK auto-index, and the
22
+ -- four 033/068 named indexes). It copies no origin values and carries no
23
+ -- triggers, embedded constraints, custom/unique indexes or referencing children
24
+ -- across the rebuild. Against anything else it would SILENTLY DROP it (a runtime
25
+ -- column, a changed column constraint/default, an embedded CHECK/UNIQUE, an
26
+ -- extra outgoing FK, a trigger, a custom/unique index, an already-present
27
+ -- operation_id / actor_principal_id value) or CASCADE-delete a referencing child
28
+ -- row on the DROP TABLE. Production extended-schema upgrades must instead go
29
+ -- through the dynamic adapter path, which preserves all of those verbatim. So
30
+ -- this guard fails LOUDLY, before altering any data, on any deviation from the
31
+ -- exact canonical pre-071 shape: the CHECK on _migration071_guard aborts the
32
+ -- whole script if the CASE evaluates to 0.
33
+ --
34
+ -- This is a strict canonical-shape precondition (a fingerprint of the known
35
+ -- fresh pre-071 chain), NOT a general SQL migration engine and NOT a policy on
36
+ -- the production adapter. It enumerates the full canonical column tuples, the
37
+ -- single canonical FK, exactly one auto-index (the PK), and rejects embedded
38
+ -- CHECK text, triggers, extra explicit indexes, and referencing children.
39
+ -- NOTE: the pre-071 canonical shape has NO operation_id/actor_principal_id
40
+ -- columns (071 adds them); their presence means a noncanonical source this path
41
+ -- cannot faithfully carry.
42
+
43
+ CREATE TEMP TABLE _migration071_guard (ok INTEGER NOT NULL CHECK (ok = 1));
44
+ INSERT INTO _migration071_guard (ok)
45
+ SELECT CASE
46
+ -- (1) column count must be exactly the 17 canonical columns (catches an extra
47
+ -- column - including an already-present origin column this path cannot
48
+ -- copy - and a missing column).
49
+ WHEN (SELECT count(*) FROM pragma_table_info('tool_traces')) <> 17 THEN 0
50
+ -- (2) every column must match the canonical (name, type, NOT NULL, DEFAULT, PK)
51
+ -- tuple. Catches a renamed/extra column, a changed column constraint, a
52
+ -- changed default, and an already-present operation_id/actor_principal_id.
53
+ WHEN EXISTS (
54
+ SELECT 1 FROM pragma_table_info('tool_traces') ti
55
+ WHERE NOT EXISTS (
56
+ SELECT 1 FROM (
57
+ SELECT 'trace_id' AS cname, 'TEXT' AS ctype, 0 AS cnn, NULL AS cdflt, 1 AS cpk
58
+ UNION ALL SELECT 'model_run_id', 'TEXT', 1, NULL, 0
59
+ UNION ALL SELECT 'gateway_call_id', 'TEXT', 0, NULL, 0
60
+ UNION ALL SELECT 'tool_name', 'TEXT', 1, NULL, 0
61
+ UNION ALL SELECT 'input_summary', 'TEXT', 0, NULL, 0
62
+ UNION ALL SELECT 'output_summary', 'TEXT', 0, NULL, 0
63
+ UNION ALL SELECT 'execution_status', 'TEXT', 0, NULL, 0
64
+ UNION ALL SELECT 'duration_ms', 'INTEGER', 0, '0', 0
65
+ UNION ALL SELECT 'envelope_hash', 'TEXT', 0, NULL, 0
66
+ UNION ALL SELECT 'created_at', 'INTEGER', 1, NULL, 0
67
+ UNION ALL SELECT 'failure_code', 'TEXT', 0, NULL, 0
68
+ UNION ALL SELECT 'diagnostic_json', 'TEXT', 0, NULL, 0
69
+ UNION ALL SELECT 'evidence_json', 'TEXT', 0, NULL, 0
70
+ UNION ALL SELECT 'catalog_revision', 'TEXT', 0, NULL, 0
71
+ UNION ALL SELECT 'owner_scope', 'TEXT', 0, NULL, 0
72
+ UNION ALL SELECT 'project_id', 'TEXT', 0, NULL, 0
73
+ UNION ALL SELECT 'channel_id', 'TEXT', 0, NULL, 0
74
+ ) canon
75
+ WHERE canon.cname = ti.name
76
+ AND canon.ctype = ti.type
77
+ AND canon.cnn = ti."notnull"
78
+ AND canon.cpk = ti.pk
79
+ AND ((canon.cdflt IS NULL AND ti.dflt_value IS NULL) OR canon.cdflt = ti.dflt_value)
80
+ )
81
+ ) THEN 0
82
+ -- (3) the outgoing FK set must be exactly the single canonical model_runs FK
83
+ -- (catches an extra or changed outgoing FK).
84
+ WHEN (SELECT count(*) FROM pragma_foreign_key_list('tool_traces')) <> 1 THEN 0
85
+ WHEN NOT EXISTS (
86
+ SELECT 1 FROM pragma_foreign_key_list('tool_traces')
87
+ WHERE "from" = 'model_run_id' AND "table" = 'model_runs' AND "to" = 'model_run_id'
88
+ ) THEN 0
89
+ -- (4) no embedded CHECK constraint. pragma does not expose CHECK, so scan the
90
+ -- stored CREATE TABLE text; the canonical shape carries no CHECK keyword.
91
+ WHEN EXISTS (
92
+ SELECT 1 FROM sqlite_master
93
+ WHERE type = 'table' AND name = 'tool_traces' AND instr(upper(sql), 'CHECK') > 0
94
+ ) THEN 0
95
+ -- (5) exactly one auto-index (the trace_id PK). An embedded UNIQUE constraint
96
+ -- (table- or column-level) adds a second sql-IS-NULL auto-index; merely
97
+ -- ignoring sql-IS-NULL auto-indexes would silently drop it on rebuild.
98
+ WHEN (
99
+ SELECT count(*) FROM sqlite_master
100
+ WHERE type = 'index' AND tbl_name = 'tool_traces' AND sql IS NULL
101
+ ) <> 1 THEN 0
102
+ -- (6) any trigger on tool_traces (DROP/RENAME would not carry it).
103
+ WHEN EXISTS (
104
+ SELECT 1 FROM sqlite_master WHERE type = 'trigger' AND tbl_name = 'tool_traces'
105
+ ) THEN 0
106
+ -- (7) any non-canonical explicit index on tool_traces (a user/unique index
107
+ -- with its own CREATE statement this path does not recreate).
108
+ WHEN EXISTS (
109
+ SELECT 1 FROM sqlite_master
110
+ WHERE type = 'index' AND tbl_name = 'tool_traces' AND sql IS NOT NULL
111
+ AND name NOT IN (
112
+ 'idx_tool_traces_model_run_id', 'idx_tool_traces_gateway_call_id',
113
+ 'idx_tool_traces_scope_recency', 'idx_tool_traces_channel_recency'
114
+ )
115
+ ) THEN 0
116
+ -- (8) any table that references tool_traces - the DROP TABLE below would
117
+ -- CASCADE-delete its rows. Detected via the per-table FK list.
118
+ WHEN EXISTS (
119
+ SELECT 1 FROM sqlite_master m
120
+ WHERE m.type = 'table' AND m.name NOT LIKE 'sqlite_%' AND m.name <> 'tool_traces'
121
+ AND EXISTS (
122
+ SELECT 1 FROM pragma_foreign_key_list(m.name) fk WHERE fk."table" = 'tool_traces'
123
+ )
124
+ ) THEN 0
125
+ ELSE 1
126
+ END;
127
+ DROP TABLE _migration071_guard;
128
+
129
+ CREATE TABLE tool_traces_071_new (
130
+ trace_id TEXT PRIMARY KEY,
131
+ model_run_id TEXT,
132
+ gateway_call_id TEXT,
133
+ tool_name TEXT NOT NULL,
134
+ input_summary TEXT,
135
+ output_summary TEXT,
136
+ execution_status TEXT,
137
+ duration_ms INTEGER DEFAULT 0,
138
+ envelope_hash TEXT,
139
+ created_at INTEGER NOT NULL,
140
+ failure_code TEXT,
141
+ diagnostic_json TEXT,
142
+ evidence_json TEXT,
143
+ catalog_revision TEXT,
144
+ owner_scope TEXT,
145
+ project_id TEXT,
146
+ channel_id TEXT,
147
+ operation_id TEXT,
148
+ actor_principal_id TEXT,
149
+ CHECK (
150
+ (model_run_id IS NOT NULL AND operation_id IS NULL AND actor_principal_id IS NULL)
151
+ OR (
152
+ operation_id IS NOT NULL AND length(trim(operation_id)) > 0
153
+ AND actor_principal_id IS NOT NULL AND length(trim(actor_principal_id)) > 0
154
+ )
155
+ ),
156
+ FOREIGN KEY (model_run_id) REFERENCES model_runs(model_run_id)
157
+ );
158
+
159
+ INSERT INTO tool_traces_071_new (
160
+ trace_id, model_run_id, gateway_call_id, tool_name, input_summary, output_summary,
161
+ execution_status, duration_ms, envelope_hash, created_at, failure_code,
162
+ diagnostic_json, evidence_json, catalog_revision, owner_scope, project_id, channel_id
163
+ )
164
+ SELECT
165
+ trace_id, model_run_id, gateway_call_id, tool_name, input_summary, output_summary,
166
+ execution_status, duration_ms, envelope_hash, created_at, failure_code,
167
+ diagnostic_json, evidence_json, catalog_revision, owner_scope, project_id, channel_id
168
+ FROM tool_traces;
169
+
170
+ DROP TABLE tool_traces;
171
+ ALTER TABLE tool_traces_071_new RENAME TO tool_traces;
172
+
173
+ CREATE INDEX IF NOT EXISTS idx_tool_traces_model_run_id
174
+ ON tool_traces(model_run_id, created_at DESC);
175
+ CREATE INDEX IF NOT EXISTS idx_tool_traces_gateway_call_id
176
+ ON tool_traces(gateway_call_id);
177
+ CREATE INDEX IF NOT EXISTS idx_tool_traces_scope_recency
178
+ ON tool_traces(owner_scope, project_id, created_at DESC, trace_id DESC);
179
+ CREATE INDEX IF NOT EXISTS idx_tool_traces_channel_recency
180
+ ON tool_traces(owner_scope, project_id, channel_id, created_at DESC, trace_id DESC);
181
+ CREATE INDEX IF NOT EXISTS idx_tool_traces_operation_id
182
+ ON tool_traces(operation_id, created_at DESC);
183
+ CREATE INDEX IF NOT EXISTS idx_tool_traces_actor_principal
184
+ ON tool_traces(actor_principal_id, created_at DESC);
185
+
186
+ INSERT OR IGNORE INTO schema_version (version, description)
187
+ VALUES (71, 'Service operation-origin tool traces');
@@ -0,0 +1,29 @@
1
+ -- Immutable source observations. The current event index points at the exact captured version;
2
+ -- retention of the mutable index never deletes the historical observation.
3
+ CREATE TABLE IF NOT EXISTS observation_versions (
4
+ observation_id TEXT PRIMARY KEY,
5
+ source TEXT NOT NULL CHECK (length(trim(source)) > 0),
6
+ source_id TEXT NOT NULL CHECK (length(trim(source_id)) > 0),
7
+ producer_version_id TEXT,
8
+ body TEXT,
9
+ body_location_json TEXT,
10
+ author TEXT,
11
+ source_at INTEGER,
12
+ observed_at INTEGER NOT NULL,
13
+ content_hash TEXT NOT NULL CHECK (length(trim(content_hash)) > 0),
14
+ metadata_json TEXT NOT NULL,
15
+ scope_json TEXT NOT NULL,
16
+ CHECK ((body IS NOT NULL AND body_location_json IS NULL)
17
+ OR (body IS NULL AND body_location_json IS NOT NULL))
18
+ );
19
+
20
+ CREATE INDEX IF NOT EXISTS observation_source_versions
21
+ ON observation_versions(source, source_id, observed_at, observation_id);
22
+
23
+ -- `connector_event_index.current_observation_id` was added here. The index belongs
24
+ -- to the package that has connectors and declares that column itself; the core no
25
+ -- longer knows the table exists. The direction it records is unchanged, and it was
26
+ -- always the right one: the index points at the observation.
27
+
28
+ INSERT OR IGNORE INTO schema_version (version, description)
29
+ VALUES (72, 'Immutable connector and owner observation versions');
@@ -0,0 +1,45 @@
1
+ -- Atomic, scoped identity corrections. Migration 069 remains the authority for aliases and
2
+ -- scope bindings; correction history extends that schema without rewriting it.
3
+ CREATE TABLE IF NOT EXISTS registry_identity_state (
4
+ singleton INTEGER PRIMARY KEY CHECK (singleton = 1),
5
+ revision INTEGER NOT NULL CHECK (revision >= 0)
6
+ );
7
+ INSERT OR IGNORE INTO registry_identity_state (singleton, revision) VALUES (1, 0);
8
+
9
+ CREATE TABLE IF NOT EXISTS registry_corrections (
10
+ command_id TEXT PRIMARY KEY,
11
+ operation TEXT NOT NULL CHECK (operation IN ('add_alias', 'merge', 'split', 'assign_refs')),
12
+ expected_revision INTEGER NOT NULL CHECK (expected_revision >= 0),
13
+ committed_revision INTEGER NOT NULL UNIQUE CHECK (committed_revision > expected_revision),
14
+ principal_id TEXT,
15
+ agent_id TEXT,
16
+ origin TEXT NOT NULL CHECK (origin IN ('trusted', 'legacy_unattributed')),
17
+ payload_json TEXT NOT NULL,
18
+ reason TEXT NOT NULL CHECK (length(trim(reason)) > 0),
19
+ evidence_json TEXT NOT NULL,
20
+ scope_json TEXT NOT NULL,
21
+ receipt_json TEXT NOT NULL,
22
+ created_at INTEGER NOT NULL,
23
+ CHECK (
24
+ (origin = 'trusted' AND principal_id IS NOT NULL AND length(trim(principal_id)) > 0
25
+ AND agent_id IS NOT NULL AND length(trim(agent_id)) > 0)
26
+ OR (origin = 'legacy_unattributed' AND principal_id IS NULL AND agent_id IS NULL)
27
+ )
28
+ );
29
+
30
+ CREATE TABLE IF NOT EXISTS registry_ref_assignments (
31
+ command_id TEXT NOT NULL REFERENCES registry_corrections(command_id) ON DELETE CASCADE,
32
+ edge_id TEXT NOT NULL,
33
+ endpoint TEXT NOT NULL CHECK (endpoint IN ('from', 'to')),
34
+ original_kind TEXT NOT NULL,
35
+ original_id TEXT NOT NULL,
36
+ resolved_node_id TEXT REFERENCES registry_nodes(id),
37
+ committed_revision INTEGER NOT NULL,
38
+ created_at INTEGER NOT NULL,
39
+ PRIMARY KEY (command_id, edge_id, endpoint)
40
+ );
41
+ CREATE INDEX IF NOT EXISTS idx_registry_ref_assignments_current
42
+ ON registry_ref_assignments(edge_id, endpoint, committed_revision DESC);
43
+
44
+ INSERT OR IGNORE INTO schema_version (version, description)
45
+ VALUES (73, 'Atomic scoped registry correction history');
@@ -0,0 +1,39 @@
1
+ -- Extend work-graph reference kinds without rewriting edge identity or provenance.
2
+ ALTER TABLE twin_edges RENAME TO twin_edges_legacy_074;
3
+ CREATE TABLE twin_edges (
4
+ edge_id TEXT PRIMARY KEY,
5
+ edge_type TEXT NOT NULL CHECK (edge_type IN ('supersedes','builds_on','debates','synthesizes','mentions','derived_from','case_member','alias_of','next_action_for','blocks')),
6
+ subject_kind TEXT NOT NULL CHECK (subject_kind IN ('memory','case','entity','report','edge','registry','observation')),
7
+ subject_id TEXT NOT NULL,
8
+ object_kind TEXT NOT NULL CHECK (object_kind IN ('memory','case','entity','report','edge','raw','registry','observation')),
9
+ object_id TEXT NOT NULL,
10
+ relation_attrs_json TEXT,
11
+ confidence REAL NOT NULL DEFAULT 1.0 CHECK (confidence >= 0.0 AND confidence <= 1.0),
12
+ source TEXT NOT NULL CHECK (source IN ('agent','human','code')),
13
+ agent_id TEXT,
14
+ model_run_id TEXT,
15
+ envelope_hash TEXT,
16
+ human_actor_id TEXT,
17
+ human_actor_role TEXT,
18
+ authority_scope_json TEXT,
19
+ reason_classification TEXT,
20
+ reason_text TEXT,
21
+ evidence_refs_json TEXT,
22
+ request_idempotency_key TEXT,
23
+ edge_idempotency_key TEXT,
24
+ content_hash BLOB NOT NULL CHECK(length(content_hash)=32),
25
+ created_at INTEGER NOT NULL
26
+ );
27
+ INSERT INTO twin_edges SELECT * FROM twin_edges_legacy_074;
28
+ DROP TABLE twin_edges_legacy_074;
29
+ CREATE INDEX idx_twin_edges_subject ON twin_edges(subject_kind, subject_id, created_at DESC);
30
+ CREATE INDEX idx_twin_edges_object ON twin_edges(object_kind, object_id, created_at DESC);
31
+ CREATE INDEX idx_twin_edges_model_run_id ON twin_edges(model_run_id, created_at DESC);
32
+ CREATE INDEX idx_twin_edges_request_idempotency
33
+ ON twin_edges(model_run_id, request_idempotency_key, created_at DESC)
34
+ WHERE model_run_id IS NOT NULL AND request_idempotency_key IS NOT NULL;
35
+ CREATE UNIQUE INDEX ux_twin_edges_model_run_edge_idempotency
36
+ ON twin_edges(model_run_id, edge_idempotency_key)
37
+ WHERE model_run_id IS NOT NULL AND edge_idempotency_key IS NOT NULL;
38
+ INSERT OR IGNORE INTO schema_version (version, description)
39
+ VALUES (74, 'Registry and observation work graph references');
@@ -0,0 +1,58 @@
1
+ -- Core-owned judgment and commitment command bindings.
2
+ -- Existing decisions, registry, observations, edges, and effect receipts remain authoritative.
3
+
4
+ ALTER TABLE decisions ADD COLUMN record_kind TEXT NOT NULL DEFAULT 'legacy'
5
+ CHECK (record_kind IN ('legacy', 'judgment', 'commitment'));
6
+ ALTER TABLE decisions ADD COLUMN payload_json TEXT NOT NULL DEFAULT '{}'
7
+ CHECK (json_valid(payload_json));
8
+ ALTER TABLE decisions ADD COLUMN applies_from INTEGER;
9
+ ALTER TABLE decisions ADD COLUMN applies_until INTEGER;
10
+
11
+ CREATE TABLE IF NOT EXISTS command_bindings (
12
+ command_id TEXT PRIMARY KEY,
13
+ principal_id TEXT NOT NULL CHECK (length(trim(principal_id)) > 0),
14
+ action TEXT NOT NULL CHECK (length(trim(action)) > 0),
15
+ payload_hash TEXT NOT NULL CHECK (length(trim(payload_hash)) > 0),
16
+ receipt_kind TEXT NOT NULL CHECK (receipt_kind IN ('judgment', 'observation', 'identity', 'effect')),
17
+ receipt_key TEXT NOT NULL CHECK (length(trim(receipt_key)) > 0),
18
+ created_at INTEGER NOT NULL CHECK (created_at >= 0)
19
+ );
20
+
21
+ CREATE TABLE IF NOT EXISTS judgment_commands (
22
+ command_id TEXT PRIMARY KEY REFERENCES command_bindings(command_id) ON DELETE RESTRICT,
23
+ record_id TEXT NOT NULL REFERENCES decisions(id) ON DELETE RESTRICT,
24
+ committed_watermark INTEGER NOT NULL CHECK (committed_watermark >= 0),
25
+ receipt_json TEXT NOT NULL CHECK (json_valid(receipt_json)),
26
+ created_at INTEGER NOT NULL CHECK (created_at >= 0)
27
+ );
28
+
29
+ CREATE TABLE IF NOT EXISTS commitments (
30
+ task_id INTEGER PRIMARY KEY AUTOINCREMENT,
31
+ commitment_id TEXT NOT NULL UNIQUE,
32
+ current_revision INTEGER NOT NULL CHECK (current_revision >= 1),
33
+ head_record_id TEXT NOT NULL REFERENCES decisions(id) ON DELETE RESTRICT,
34
+ withdrawn INTEGER NOT NULL DEFAULT 0 CHECK (withdrawn IN (0, 1)),
35
+ created_at INTEGER NOT NULL CHECK (created_at >= 0),
36
+ updated_at INTEGER NOT NULL CHECK (updated_at >= 0)
37
+ );
38
+
39
+ CREATE TABLE IF NOT EXISTS commitment_assignments (
40
+ commitment_id TEXT NOT NULL REFERENCES commitments(commitment_id) ON DELETE RESTRICT,
41
+ revision INTEGER NOT NULL CHECK (revision >= 1),
42
+ record_id TEXT NOT NULL REFERENCES decisions(id) ON DELETE RESTRICT,
43
+ operation TEXT NOT NULL CHECK (operation IN ('create', 'revise', 'withdraw')),
44
+ set_json TEXT NOT NULL CHECK (json_valid(set_json)),
45
+ clear_json TEXT NOT NULL CHECK (json_valid(clear_json)),
46
+ applies_from INTEGER,
47
+ applies_until INTEGER,
48
+ created_at INTEGER NOT NULL CHECK (created_at >= 0),
49
+ PRIMARY KEY (commitment_id, revision),
50
+ UNIQUE (commitment_id, record_id)
51
+ );
52
+
53
+ CREATE INDEX IF NOT EXISTS idx_judgment_commands_record ON judgment_commands(record_id, created_at DESC);
54
+ CREATE INDEX IF NOT EXISTS idx_commitments_head ON commitments(head_record_id);
55
+ CREATE INDEX IF NOT EXISTS idx_commitment_assignments_record ON commitment_assignments(record_id);
56
+
57
+ INSERT OR IGNORE INTO schema_version (version, description)
58
+ VALUES (75, 'Core-owned agent judgment and commitment commands');
@@ -0,0 +1,15 @@
1
+ -- Checkpoints are readable only when their explicit scope is bound. Legacy rows remain unscoped.
2
+
3
+ CREATE TABLE IF NOT EXISTS checkpoint_scope_bindings (
4
+ checkpoint_id INTEGER NOT NULL REFERENCES checkpoints(id) ON DELETE CASCADE,
5
+ scope_id TEXT NOT NULL REFERENCES memory_scopes(id) ON DELETE RESTRICT,
6
+ is_primary INTEGER NOT NULL DEFAULT 0 CHECK (is_primary IN (0, 1)),
7
+ created_at INTEGER NOT NULL CHECK (created_at >= 0),
8
+ PRIMARY KEY (checkpoint_id, scope_id)
9
+ );
10
+
11
+ CREATE INDEX IF NOT EXISTS idx_checkpoint_scope_bindings_scope
12
+ ON checkpoint_scope_bindings(scope_id, checkpoint_id DESC);
13
+
14
+ INSERT OR IGNORE INTO schema_version (version, description)
15
+ VALUES (76, 'Scoped checkpoint bindings');