@jungjaehoon/mama-core 2.4.0 → 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 (374) 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/068-tool-trace-diagnostics.sql +13 -0
  9. package/db/migrations/069-create-registry-nodes.sql +52 -0
  10. package/db/migrations/070-record-identity.sql +35 -0
  11. package/db/migrations/071-service-operation-origins.sql +187 -0
  12. package/db/migrations/072-observation-versions.sql +29 -0
  13. package/db/migrations/073-registry-corrections.sql +45 -0
  14. package/db/migrations/074-work-graph-ref-kinds.sql +39 -0
  15. package/db/migrations/075-agent-judgments.sql +58 -0
  16. package/db/migrations/076-scoped-checkpoint-bindings.sql +15 -0
  17. package/db/migrations/077-legacy-record-kind.sql +6 -0
  18. package/db/migrations/078-source-ingest-commands.sql +18 -0
  19. package/db/migrations/079-twin-edge-relations.sql +43 -0
  20. package/db/migrations/080-restore-duration-days.sql +7 -0
  21. package/db/migrations/081-mailbox.sql +61 -0
  22. package/db/migrations/082-commitments-row-id.sql +12 -0
  23. package/db/migrations/083-observation-is-the-evidence.sql +49 -0
  24. package/db/migrations/084-scope-kind-is-not-the-cores-to-list.sql +34 -0
  25. package/db/migrations/085-a-migration-has-a-source.sql +37 -0
  26. package/db/migrations/086-the-mailbox-is-generic.sql +110 -0
  27. package/db/migrations/087-mailbox-payload.sql +5 -0
  28. package/db/migrations/088-native-input-journal.sql +14 -0
  29. package/db/migrations/089-native-turn-receipt-lookup.sql +3 -0
  30. package/db/migrations/090-model-run-native-inputs.sql +29 -0
  31. package/db/migrations/091-native-turn-results.sql +11 -0
  32. package/db/migrations/092-restore-decision-fts.sql +34 -0
  33. package/db/migrations/093-native-turn-primary-kind.sql +14 -0
  34. package/db/migrations/094-commitment-run-provenance.sql +9 -0
  35. package/db/migrations/095-model-run-native-input-identity.sql +39 -0
  36. package/db/migrations/096-drop-connector-event-index-fts.sql +9 -0
  37. package/db/migrations/097-native-input-json-validity.sql +37 -0
  38. package/db/migrations/098-workflow-memory-kind.sql +105 -0
  39. package/dist/action-contracts.d.ts +212 -0
  40. package/dist/action-contracts.js +10 -0
  41. package/dist/api/catalog.d.ts +118 -0
  42. package/dist/api/catalog.js +1756 -0
  43. package/dist/api/dispatch.d.ts +76 -0
  44. package/dist/api/dispatch.js +372 -0
  45. package/dist/canonicalize.d.ts +2 -2
  46. package/dist/canonicalize.js +3 -3
  47. package/dist/client/client.d.ts +33 -0
  48. package/dist/client/client.js +123 -0
  49. package/dist/client/ipc.d.ts +81 -0
  50. package/dist/client/ipc.js +314 -0
  51. package/dist/db-adapter/base-adapter.d.ts +6 -66
  52. package/dist/db-adapter/base-adapter.js +6 -6
  53. package/dist/db-adapter/index.d.ts +5 -5
  54. package/dist/db-adapter/index.js +2 -5
  55. package/dist/db-adapter/node-sqlite-adapter.d.ts +87 -15
  56. package/dist/db-adapter/node-sqlite-adapter.js +2045 -568
  57. package/dist/db-manager.d.ts +53 -97
  58. package/dist/db-manager.js +121 -603
  59. package/dist/embedding/embedder.d.ts +132 -0
  60. package/dist/embedding/embedder.js +299 -0
  61. package/dist/identity/principal-repository.d.ts +2 -2
  62. package/dist/index.d.ts +43 -58
  63. package/dist/index.js +99 -145
  64. package/dist/{context-compile/channel-grant.d.ts → knowledge/access.d.ts} +12 -17
  65. package/dist/knowledge/access.js +663 -0
  66. package/dist/knowledge/case-errors.d.ts +31 -0
  67. package/dist/knowledge/case-errors.js +40 -0
  68. package/dist/{cases/search-rollup.d.ts → knowledge/case-search-rollup.d.ts} +5 -4
  69. package/dist/{cases/search-rollup.js → knowledge/case-search-rollup.js} +6 -8
  70. package/dist/{cases/store.d.ts → knowledge/case-store.d.ts} +3 -6
  71. package/dist/{cases/store.js → knowledge/case-store.js} +7 -42
  72. package/dist/{cases/timeline-range.d.ts → knowledge/case-timeline-range.d.ts} +3 -3
  73. package/dist/{cases/timeline-range.js → knowledge/case-timeline-range.js} +47 -25
  74. package/dist/{cases/types.d.ts → knowledge/case-types.d.ts} +8 -2
  75. package/dist/{cases/types.js → knowledge/case-types.js} +1 -1
  76. package/dist/knowledge/commitments.d.ts +188 -0
  77. package/dist/knowledge/commitments.js +370 -0
  78. package/dist/knowledge/decision-edges.d.ts +70 -0
  79. package/dist/knowledge/decision-edges.js +123 -0
  80. package/dist/{agent-graph/types.d.ts → knowledge/graph-query.d.ts} +80 -70
  81. package/dist/knowledge/graph-query.js +1585 -0
  82. package/dist/knowledge/identity.d.ts +16 -0
  83. package/dist/knowledge/identity.js +22 -0
  84. package/dist/knowledge/index.d.ts +47 -0
  85. package/dist/knowledge/index.js +90 -0
  86. package/dist/knowledge/judgments.d.ts +118 -0
  87. package/dist/knowledge/judgments.js +808 -0
  88. package/dist/knowledge/observations.d.ts +160 -0
  89. package/dist/knowledge/observations.js +449 -0
  90. package/dist/knowledge/question-type.d.ts +34 -0
  91. package/dist/knowledge/question-type.js +70 -0
  92. package/dist/{search → knowledge}/ranker-features.js +1 -1
  93. package/dist/{search → knowledge}/search-quality.d.ts +0 -1
  94. package/dist/knowledge/search.d.ts +38 -0
  95. package/dist/knowledge/search.js +91 -0
  96. package/dist/knowledge/source-ingest.d.ts +65 -0
  97. package/dist/knowledge/source-ingest.js +174 -0
  98. package/dist/{edges/types.d.ts → knowledge/twin-edge-types.d.ts} +31 -4
  99. package/dist/{edges/types.js → knowledge/twin-edge-types.js} +13 -2
  100. package/dist/knowledge/work-dates.d.ts +49 -0
  101. package/dist/knowledge/work-dates.js +120 -0
  102. package/dist/mama-api.d.ts +116 -778
  103. package/dist/mama-api.js +313 -2457
  104. package/dist/memory/api.d.ts +264 -24
  105. package/dist/memory/api.js +1633 -843
  106. package/dist/memory/bootstrap-builder.d.ts +2 -1
  107. package/dist/memory/bootstrap-builder.js +5 -5
  108. package/dist/memory/channel-summary-state-store.d.ts +3 -2
  109. package/dist/memory/channel-summary-state-store.js +53 -51
  110. package/dist/memory/channel-summary-store.d.ts +5 -3
  111. package/dist/memory/channel-summary-store.js +3 -8
  112. package/dist/memory/dashboard-read.d.ts +46 -0
  113. package/dist/memory/dashboard-read.js +94 -0
  114. package/dist/memory/event-store.d.ts +3 -3
  115. package/dist/memory/event-store.js +3 -10
  116. package/dist/memory/finding-store.d.ts +3 -2
  117. package/dist/memory/finding-store.js +2 -7
  118. package/dist/memory/graph-read.d.ts +52 -0
  119. package/dist/memory/graph-read.js +130 -0
  120. package/dist/memory/judgment-types.d.ts +394 -0
  121. package/dist/memory/judgment-types.js +16 -0
  122. package/dist/memory/provenance-audit.d.ts +5 -2
  123. package/dist/memory/provenance-audit.js +8 -14
  124. package/dist/memory/provenance-live.d.ts +141 -0
  125. package/dist/memory/provenance-live.js +409 -0
  126. package/dist/memory/provenance-query.d.ts +5 -4
  127. package/dist/memory/provenance-query.js +21 -29
  128. package/dist/memory/provenance-resolver.d.ts +191 -0
  129. package/dist/memory/provenance-resolver.js +155 -0
  130. package/dist/memory/provenance.d.ts +1 -11
  131. package/dist/memory/provenance.js +2 -33
  132. package/dist/memory/recall-sanitize.d.ts +55 -0
  133. package/dist/memory/recall-sanitize.js +144 -0
  134. package/dist/memory/secret-filter.d.ts +32 -0
  135. package/dist/memory/secret-filter.js +126 -0
  136. package/dist/memory/truth-store.d.ts +2 -1
  137. package/dist/memory/truth-store.js +1 -4
  138. package/dist/memory/types.d.ts +74 -24
  139. package/dist/memory/types.js +75 -5
  140. package/dist/memory/write-adapters.d.ts +98 -0
  141. package/dist/memory/write-adapters.js +242 -0
  142. package/dist/operations/owner-action-effects.d.ts +53 -0
  143. package/dist/operations/owner-action-effects.js +96 -0
  144. package/dist/provenance/source-ref.d.ts +1 -1
  145. package/dist/provenance/source-ref.js +0 -2
  146. package/dist/registry/corrections.d.ts +31 -0
  147. package/dist/registry/corrections.js +332 -0
  148. package/dist/registry/record-identity.d.ts +49 -0
  149. package/dist/registry/record-identity.js +133 -0
  150. package/dist/registry/store.d.ts +101 -0
  151. package/dist/registry/store.js +395 -0
  152. package/dist/registry/types.d.ts +28 -0
  153. package/dist/registry/types.js +5 -0
  154. package/dist/relevance-scorer.js +2 -2
  155. package/dist/runtime/agent-event-bus.d.ts +50 -0
  156. package/dist/runtime/agent-event-bus.js +101 -0
  157. package/dist/runtime/drivers/claude-cli-wrapper.d.ts +155 -0
  158. package/dist/runtime/drivers/claude-cli-wrapper.js +392 -0
  159. package/dist/runtime/drivers/cli-arg-redaction.d.ts +2 -0
  160. package/dist/runtime/drivers/cli-arg-redaction.js +18 -0
  161. package/dist/runtime/drivers/cli-secret-redaction.d.ts +17 -0
  162. package/dist/runtime/drivers/cli-secret-redaction.js +126 -0
  163. package/dist/runtime/drivers/codex-app-server-process.d.ts +277 -0
  164. package/dist/runtime/drivers/codex-app-server-process.js +2342 -0
  165. package/dist/runtime/drivers/codex-auxiliary-tools.d.ts +17 -0
  166. package/dist/runtime/drivers/codex-auxiliary-tools.js +267 -0
  167. package/dist/runtime/drivers/codex-home.d.ts +20 -0
  168. package/dist/runtime/drivers/codex-home.js +674 -0
  169. package/dist/runtime/drivers/codex-thread-registry.d.ts +63 -0
  170. package/dist/runtime/drivers/codex-thread-registry.js +433 -0
  171. package/dist/runtime/drivers/persistent-cli-adapter.d.ts +160 -0
  172. package/dist/runtime/drivers/persistent-cli-adapter.js +396 -0
  173. package/dist/runtime/drivers/persistent-cli-process.d.ts +424 -0
  174. package/dist/runtime/drivers/persistent-cli-process.js +1543 -0
  175. package/dist/runtime/drivers/types.d.ts +456 -0
  176. package/dist/runtime/drivers/types.js +110 -0
  177. package/dist/runtime/mailbox.d.ts +223 -0
  178. package/dist/runtime/mailbox.js +582 -0
  179. package/dist/runtime/model-run-store.d.ts +28 -0
  180. package/dist/{model-runs/store.js → runtime/model-run-store.js} +81 -41
  181. package/dist/runtime/model-run-types.d.ts +132 -0
  182. package/dist/{model-runs/types.js → runtime/model-run-types.js} +1 -1
  183. package/dist/runtime/native-effect-observer.d.ts +22 -0
  184. package/dist/runtime/native-effect-observer.js +103 -0
  185. package/dist/runtime/native-input-journal.d.ts +46 -0
  186. package/dist/runtime/native-input-journal.js +308 -0
  187. package/dist/runtime/native-prompt.d.ts +118 -0
  188. package/dist/runtime/native-prompt.js +496 -0
  189. package/dist/runtime/native-session.d.ts +10 -0
  190. package/dist/{agent-graph/index.js → runtime/native-session.js} +9 -6
  191. package/dist/runtime/native-tool-trace-observer.d.ts +5 -0
  192. package/dist/runtime/native-tool-trace-observer.js +65 -0
  193. package/dist/runtime/native-turn.d.ts +272 -0
  194. package/dist/runtime/native-turn.js +1041 -0
  195. package/dist/runtime/operations.d.ts +236 -0
  196. package/dist/runtime/operations.js +565 -0
  197. package/dist/runtime/post-tool-handler.d.ts +74 -0
  198. package/dist/runtime/post-tool-handler.js +137 -0
  199. package/dist/runtime/prompt-layers.d.ts +126 -0
  200. package/dist/runtime/prompt-layers.js +239 -0
  201. package/dist/runtime/runtime-process.d.ts +102 -0
  202. package/dist/runtime/runtime-process.js +206 -0
  203. package/dist/runtime/runtime.d.ts +278 -0
  204. package/dist/runtime/runtime.js +563 -0
  205. package/dist/runtime/session-pool.d.ts +176 -0
  206. package/dist/runtime/session-pool.js +369 -0
  207. package/dist/runtime/stimulus-payload.d.ts +5 -0
  208. package/dist/runtime/stimulus-payload.js +50 -0
  209. package/dist/runtime/subagent-bridge.d.ts +24 -0
  210. package/dist/{agent-graph/types.js → runtime/subagent-bridge.js} +1 -1
  211. package/dist/runtime/text-completion.d.ts +22 -0
  212. package/dist/{agent-situation/types.js → runtime/text-completion.js} +1 -1
  213. package/dist/runtime/token-estimator.d.ts +25 -0
  214. package/dist/runtime/token-estimator.js +75 -0
  215. package/dist/runtime/tool-trace-store.d.ts +22 -0
  216. package/dist/runtime/tool-trace-store.js +242 -0
  217. package/dist/runtime/trace-summary.d.ts +5 -0
  218. package/dist/runtime/trace-summary.js +74 -0
  219. package/dist/runtime/turn-text.d.ts +23 -0
  220. package/dist/runtime/turn-text.js +41 -0
  221. package/dist/storage/database.d.ts +67 -0
  222. package/dist/storage/database.js +158 -0
  223. package/package.json +20 -34
  224. package/dist/agent-graph/alias-write.d.ts +0 -3
  225. package/dist/agent-graph/alias-write.js +0 -234
  226. package/dist/agent-graph/entity-resolve.d.ts +0 -3
  227. package/dist/agent-graph/entity-resolve.js +0 -271
  228. package/dist/agent-graph/errors.d.ts +0 -4
  229. package/dist/agent-graph/errors.js +0 -11
  230. package/dist/agent-graph/graph-query.d.ts +0 -5
  231. package/dist/agent-graph/graph-query.js +0 -360
  232. package/dist/agent-graph/index.d.ts +0 -6
  233. package/dist/agent-situation/builder.d.ts +0 -8
  234. package/dist/agent-situation/builder.js +0 -239
  235. package/dist/agent-situation/cache-key.d.ts +0 -4
  236. package/dist/agent-situation/cache-key.js +0 -64
  237. package/dist/agent-situation/index.d.ts +0 -7
  238. package/dist/agent-situation/index.js +0 -28
  239. package/dist/agent-situation/packet-store.d.ts +0 -27
  240. package/dist/agent-situation/packet-store.js +0 -228
  241. package/dist/agent-situation/ranking-policy.d.ts +0 -18
  242. package/dist/agent-situation/ranking-policy.js +0 -75
  243. package/dist/agent-situation/source-readers.d.ts +0 -52
  244. package/dist/agent-situation/source-readers.js +0 -300
  245. package/dist/agent-situation/types.d.ts +0 -195
  246. package/dist/cases/wiki-page-index.d.ts +0 -37
  247. package/dist/cases/wiki-page-index.js +0 -201
  248. package/dist/config-loader.d.ts +0 -68
  249. package/dist/config-loader.js +0 -239
  250. package/dist/connectors/event-index.d.ts +0 -24
  251. package/dist/connectors/event-index.js +0 -245
  252. package/dist/connectors/raw-query.d.ts +0 -40
  253. package/dist/connectors/raw-query.js +0 -412
  254. package/dist/connectors/types.d.ts +0 -117
  255. package/dist/connectors/types.js +0 -3
  256. package/dist/context-compile/boundary-defaults.d.ts +0 -12
  257. package/dist/context-compile/boundary-defaults.js +0 -105
  258. package/dist/context-compile/channel-grant.js +0 -66
  259. package/dist/context-compile/compiler-policy.d.ts +0 -39
  260. package/dist/context-compile/compiler-policy.js +0 -147
  261. package/dist/context-compile/compiler.d.ts +0 -18
  262. package/dist/context-compile/compiler.js +0 -404
  263. package/dist/context-compile/index.d.ts +0 -10
  264. package/dist/context-compile/index.js +0 -26
  265. package/dist/context-compile/packet-store.d.ts +0 -8
  266. package/dist/context-compile/packet-store.js +0 -239
  267. package/dist/context-compile/ref.d.ts +0 -7
  268. package/dist/context-compile/ref.js +0 -102
  269. package/dist/context-compile/source-readers.d.ts +0 -70
  270. package/dist/context-compile/source-readers.js +0 -840
  271. package/dist/context-compile/types.d.ts +0 -155
  272. package/dist/context-compile/types.js +0 -11
  273. package/dist/context-compile/visibility.d.ts +0 -21
  274. package/dist/context-compile/visibility.js +0 -224
  275. package/dist/decision-tracker.d.ts +0 -206
  276. package/dist/decision-tracker.js +0 -481
  277. package/dist/edges/ref-validation.d.ts +0 -7
  278. package/dist/edges/ref-validation.js +0 -321
  279. package/dist/edges/store.d.ts +0 -8
  280. package/dist/edges/store.js +0 -129
  281. package/dist/embedding-client.d.ts +0 -28
  282. package/dist/embedding-client.js +0 -53
  283. package/dist/embedding-server/index.d.ts +0 -67
  284. package/dist/embedding-server/index.js +0 -405
  285. package/dist/embedding-server/mobile/auth.d.ts +0 -44
  286. package/dist/embedding-server/mobile/auth.js +0 -150
  287. package/dist/embedding-server/mobile/daemon.d.ts +0 -129
  288. package/dist/embedding-server/mobile/daemon.js +0 -313
  289. package/dist/embedding-server/mobile/output-parser.d.ts +0 -115
  290. package/dist/embedding-server/mobile/output-parser.js +0 -241
  291. package/dist/embedding-server/mobile/session-api.d.ts +0 -57
  292. package/dist/embedding-server/mobile/session-api.js +0 -261
  293. package/dist/embedding-server/mobile/session-manager.d.ts +0 -138
  294. package/dist/embedding-server/mobile/session-manager.js +0 -378
  295. package/dist/embedding-server/mobile/websocket-handler.d.ts +0 -137
  296. package/dist/embedding-server/mobile/websocket-handler.js +0 -486
  297. package/dist/embeddings.d.ts +0 -68
  298. package/dist/embeddings.js +0 -244
  299. package/dist/entities/audit-metrics.d.ts +0 -68
  300. package/dist/entities/audit-metrics.js +0 -124
  301. package/dist/entities/candidate-generator.d.ts +0 -8
  302. package/dist/entities/candidate-generator.js +0 -24
  303. package/dist/entities/entity-linked-decision-counts.d.ts +0 -2
  304. package/dist/entities/entity-linked-decision-counts.js +0 -29
  305. package/dist/entities/entity-list.d.ts +0 -22
  306. package/dist/entities/entity-list.js +0 -3
  307. package/dist/entities/entity-orphan-list.d.ts +0 -17
  308. package/dist/entities/entity-orphan-list.js +0 -3
  309. package/dist/entities/entity-search.d.ts +0 -20
  310. package/dist/entities/entity-search.js +0 -3
  311. package/dist/entities/errors.d.ts +0 -55
  312. package/dist/entities/errors.js +0 -100
  313. package/dist/entities/lineage-store.d.ts +0 -28
  314. package/dist/entities/lineage-store.js +0 -204
  315. package/dist/entities/normalization.d.ts +0 -14
  316. package/dist/entities/normalization.js +0 -63
  317. package/dist/entities/policy-store.d.ts +0 -8
  318. package/dist/entities/policy-store.js +0 -75
  319. package/dist/entities/policy-types.d.ts +0 -72
  320. package/dist/entities/policy-types.js +0 -59
  321. package/dist/entities/projection.d.ts +0 -8
  322. package/dist/entities/projection.js +0 -82
  323. package/dist/entities/provenance-query.d.ts +0 -32
  324. package/dist/entities/provenance-query.js +0 -3
  325. package/dist/entities/read-identity.d.ts +0 -31
  326. package/dist/entities/read-identity.js +0 -264
  327. package/dist/entities/recall-bridge.d.ts +0 -5
  328. package/dist/entities/recall-bridge.js +0 -171
  329. package/dist/entities/resolution-engine.d.ts +0 -8
  330. package/dist/entities/resolution-engine.js +0 -3
  331. package/dist/entities/rollback-preview.d.ts +0 -35
  332. package/dist/entities/rollback-preview.js +0 -3
  333. package/dist/entities/source-locator.d.ts +0 -3
  334. package/dist/entities/source-locator.js +0 -32
  335. package/dist/entities/store.d.ts +0 -69
  336. package/dist/entities/store.js +0 -544
  337. package/dist/entities/types.d.ts +0 -166
  338. package/dist/entities/types.js +0 -30
  339. package/dist/memory/extraction-prompt.d.ts +0 -4
  340. package/dist/memory/extraction-prompt.js +0 -89
  341. package/dist/memory/scope-backfill.d.ts +0 -14
  342. package/dist/memory/scope-backfill.js +0 -3
  343. package/dist/memory/scope-store.d.ts +0 -4
  344. package/dist/memory/scope-store.js +0 -9
  345. package/dist/memory-store.d.ts +0 -87
  346. package/dist/memory-store.js +0 -78
  347. package/dist/model-runs/store.d.ts +0 -13
  348. package/dist/model-runs/tool-trace-store.d.ts +0 -4
  349. package/dist/model-runs/tool-trace-store.js +0 -118
  350. package/dist/model-runs/types.d.ts +0 -72
  351. package/dist/notification-manager.d.ts +0 -7
  352. package/dist/notification-manager.js +0 -12
  353. package/dist/outcome-tracker.d.ts +0 -151
  354. package/dist/outcome-tracker.js +0 -271
  355. package/dist/query-intent.d.ts +0 -23
  356. package/dist/query-intent.js +0 -114
  357. package/dist/runtime/trusted-provenance.d.ts +0 -3
  358. package/dist/runtime/trusted-provenance.js +0 -6
  359. package/dist/search/question-type.d.ts +0 -5
  360. package/dist/search/question-type.js +0 -41
  361. package/dist/test-utils.d.ts +0 -80
  362. package/dist/test-utils.js +0 -218
  363. package/dist/tier-validator.d.ts +0 -43
  364. package/dist/tier-validator.js +0 -159
  365. package/dist/time-formatter.d.ts +0 -25
  366. package/dist/time-formatter.js +0 -93
  367. /package/dist/{search → knowledge}/feedback-store.d.ts +0 -0
  368. /package/dist/{search → knowledge}/feedback-store.js +0 -0
  369. /package/dist/{search → knowledge}/ranker-features.d.ts +0 -0
  370. /package/dist/{search → knowledge}/ranker-rescore.d.ts +0 -0
  371. /package/dist/{search → knowledge}/ranker-rescore.js +0 -0
  372. /package/dist/{search → knowledge}/ranker-trainer.d.ts +0 -0
  373. /package/dist/{search → knowledge}/ranker-trainer.js +0 -0
  374. /package/dist/{search → knowledge}/search-quality.js +0 -0
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_QUESTION_VOCABULARY = exports.QUESTION_TYPES = void 0;
4
+ exports.declareQuestionVocabulary = declareQuestionVocabulary;
5
+ exports.resetQuestionVocabulary = resetQuestionVocabulary;
6
+ exports.classifyQuestionType = classifyQuestionType;
7
+ exports.isQuestionType = isQuestionType;
8
+ exports.QUESTION_TYPES = [
9
+ 'correction',
10
+ 'artifact',
11
+ 'timeline',
12
+ 'status',
13
+ 'decision_reason',
14
+ 'how_to',
15
+ 'unknown',
16
+ ];
17
+ // Korean: patterns for classifyQuestionType() multilingual query routing.
18
+ // A language is not a product: these words name no deployment, no connector and no
19
+ // package. Domain words belong in a caller's vocabulary, not here.
20
+ exports.DEFAULT_QUESTION_VOCABULARY = [
21
+ {
22
+ type: 'correction',
23
+ pattern: /\b(fix|revert|correct|correction|supersede|superseded|revise|revision)\b|수정|되돌|정정|교정/i,
24
+ },
25
+ {
26
+ type: 'artifact',
27
+ pattern: /\b(file|doc|docs|document|image|video|pdf|attachment|artifact)\b|파일|문서|이미지|영상|첨부/i,
28
+ },
29
+ {
30
+ type: 'timeline',
31
+ pattern: /\b(when|history|before|after|around|timeline|chronology)\b|언제|이력|히스토리|(?:^|\s)(?:전|후)(?=$|\s|[?.!,]|에|의|로|부터|까지|는|를|가|와|도)|즈음|\bon\s+\d{4}(?:-\d{1,2})?(?:-\d{1,2})?\b|\b\d{4}-\d{1,2}-\d{1,2}\b/i,
32
+ },
33
+ {
34
+ type: 'status',
35
+ pattern: /\b(status|state|current|currently|now|latest|progress|blocked|done)\b|상태|현재|최신|진행|진척/i,
36
+ },
37
+ { type: 'decision_reason', pattern: /\b(why|reason|because|rationale)\b|근거|이유|왜|때문/i },
38
+ {
39
+ type: 'how_to',
40
+ pattern: /\b(how\s+to|how\s+do|setup|set\s+up|configure|configuration|install)\b|설정|구성|어떻게/i,
41
+ },
42
+ ];
43
+ let vocabulary = exports.DEFAULT_QUESTION_VOCABULARY;
44
+ /**
45
+ * Declare the words this deployment asks questions with. Call once, at boot.
46
+ *
47
+ * Replaces the default outright rather than merging: a caller that wants the general
48
+ * words plus its own spreads DEFAULT_QUESTION_VOCABULARY itself, and can see in one
49
+ * place what its classifier actually knows.
50
+ */
51
+ function declareQuestionVocabulary(next) {
52
+ vocabulary = next;
53
+ }
54
+ /** Restore the default. For tests that declared their own. */
55
+ function resetQuestionVocabulary() {
56
+ vocabulary = exports.DEFAULT_QUESTION_VOCABULARY;
57
+ }
58
+ function classifyQuestionType(query) {
59
+ const normalized = query.trim();
60
+ for (const entry of vocabulary) {
61
+ if (entry.pattern.test(normalized)) {
62
+ return entry.type;
63
+ }
64
+ }
65
+ return 'unknown';
66
+ }
67
+ function isQuestionType(value) {
68
+ return exports.QUESTION_TYPES.includes(value);
69
+ }
70
+ //# sourceMappingURL=question-type.js.map
@@ -40,7 +40,7 @@ function sourceTypeKey(row) {
40
40
  case 'wiki_page':
41
41
  return 'artifact';
42
42
  case 'connector_event':
43
- case 'standalone_connector_hit':
43
+ case 'ungrouped_connector_hit':
44
44
  return 'connector_event';
45
45
  default:
46
46
  return null;
@@ -22,7 +22,6 @@ export interface SearchHitDiagnostics {
22
22
  retrieval_source: string;
23
23
  vector_similarity: number | null;
24
24
  lexical_support: boolean;
25
- entity_support: boolean;
26
25
  scope_support: boolean;
27
26
  graph_source: 'primary' | 'expanded' | null;
28
27
  is_vector_only: boolean;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Knowledge search: what the corpus can be asked for by meaning and by word.
3
+ *
4
+ * Both functions take the adapter they read through, so a caller cannot run a
5
+ * search against a database it did not open.
6
+ *
7
+ * @module knowledge/search
8
+ */
9
+ import type { DatabaseInstance, DecisionRecord } from '../db-manager.js';
10
+ import type { MemoryKindFilter } from '../memory/types.js';
11
+ /**
12
+ * Brute-force cosine similarity search over stored embeddings.
13
+ *
14
+ * Errors are not swallowed: an empty array means the corpus held nothing above
15
+ * `threshold`, never that the search failed.
16
+ *
17
+ * @param adapter - Database to read through
18
+ * @param queryEmbedding - Query embedding (1024-dim)
19
+ * @param limit - Max results to return
20
+ * @param threshold - Minimum similarity
21
+ * @param topicPrefix - Optional topic prefix pre-filter
22
+ * @param excludeStatuses - Optional decision statuses to pre-filter out
23
+ * @param kind - Optional memory kind pre-filter
24
+ */
25
+ export declare function vectorSearch(adapter: DatabaseInstance, queryEmbedding: Float32Array | number[], limit?: number, threshold?: number, topicPrefix?: string, excludeStatuses?: readonly string[], kind?: MemoryKindFilter): Promise<DecisionRecord[]>;
26
+ /**
27
+ * FTS5 keyword search on the decisions table.
28
+ *
29
+ * @param adapter - Database to read through
30
+ * @param query - FTS5 MATCH expression
31
+ * @param limit - Max rows to return
32
+ * @returns Matching decision IDs with BM25 rank scores
33
+ */
34
+ export declare function fts5Search(adapter: DatabaseInstance, query: string, limit?: number, kind?: MemoryKindFilter): Promise<{
35
+ id: string;
36
+ rank: number;
37
+ }[]>;
38
+ //# sourceMappingURL=search.d.ts.map
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ /**
3
+ * Knowledge search: what the corpus can be asked for by meaning and by word.
4
+ *
5
+ * Both functions take the adapter they read through, so a caller cannot run a
6
+ * search against a database it did not open.
7
+ *
8
+ * @module knowledge/search
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.vectorSearch = vectorSearch;
12
+ exports.fts5Search = fts5Search;
13
+ /**
14
+ * Brute-force cosine similarity search over stored embeddings.
15
+ *
16
+ * Errors are not swallowed: an empty array means the corpus held nothing above
17
+ * `threshold`, never that the search failed.
18
+ *
19
+ * @param adapter - Database to read through
20
+ * @param queryEmbedding - Query embedding (1024-dim)
21
+ * @param limit - Max results to return
22
+ * @param threshold - Minimum similarity
23
+ * @param topicPrefix - Optional topic prefix pre-filter
24
+ * @param excludeStatuses - Optional decision statuses to pre-filter out
25
+ * @param kind - Optional memory kind pre-filter
26
+ */
27
+ async function vectorSearch(adapter, queryEmbedding, limit = 5, threshold = 0.7, topicPrefix, excludeStatuses, kind) {
28
+ const results = await adapter.vectorSearch(queryEmbedding, limit * 3, topicPrefix, excludeStatuses, kind);
29
+ if (!results || results.length === 0) {
30
+ return [];
31
+ }
32
+ const stmt = adapter.prepare(`SELECT * FROM decisions WHERE rowid = ?`);
33
+ const decisions = [];
34
+ for (const row of results) {
35
+ const decision = stmt.get(row.rowid);
36
+ if (!decision) {
37
+ continue;
38
+ }
39
+ const similarity = row.similarity ?? Math.max(0, 1.0 - (row.distance ?? 1));
40
+ const distance = row.distance ?? Math.max(0, 1.0 - similarity);
41
+ if (similarity >= threshold) {
42
+ decisions.push({
43
+ ...decision,
44
+ distance,
45
+ similarity,
46
+ });
47
+ }
48
+ if (decisions.length >= limit) {
49
+ break;
50
+ }
51
+ }
52
+ return decisions;
53
+ }
54
+ /**
55
+ * FTS5 keyword search on the decisions table.
56
+ *
57
+ * @param adapter - Database to read through
58
+ * @param query - FTS5 MATCH expression
59
+ * @param limit - Max rows to return
60
+ * @returns Matching decision IDs with BM25 rank scores
61
+ */
62
+ async function fts5Search(adapter, query, limit = 10, kind) {
63
+ // An absent FTS table is a real answer - no rows. A failing adapter is not,
64
+ // so this lookup is left unguarded and its errors reach the caller.
65
+ const tableCheck = adapter
66
+ .prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='decisions_fts'")
67
+ .get();
68
+ if (!tableCheck)
69
+ return [];
70
+ // Query execution - let errors propagate to the caller
71
+ const kindClause = Array.isArray(kind)
72
+ ? `AND d.kind IN (${kind.map(() => '?').join(', ')})`
73
+ : kind === undefined
74
+ ? ''
75
+ : 'AND d.kind = ?';
76
+ const stmt = adapter.prepare(`
77
+ SELECT d.id, rank
78
+ FROM decisions_fts
79
+ JOIN decisions d ON decisions_fts.rowid = d.rowid
80
+ WHERE decisions_fts MATCH ?
81
+ ${kindClause}
82
+ ORDER BY rank
83
+ LIMIT ?
84
+ `);
85
+ return (Array.isArray(kind)
86
+ ? stmt.all(query, ...kind, limit)
87
+ : kind === undefined
88
+ ? stmt.all(query, limit)
89
+ : stmt.all(query, kind, limit));
90
+ }
91
+ //# sourceMappingURL=search.js.map
@@ -0,0 +1,65 @@
1
+ import type { DatabaseAdapter } from '../db-manager.js';
2
+ import type { JsonValue } from '../memory/judgment-types.js';
3
+ import type { MemoryEventRecord, MemoryScopeRef } from '../memory/types.js';
4
+ import { type JudgmentAccess } from './judgments.js';
5
+ /**
6
+ * `source.ingest` — the raw-evidence half of the command boundary.
7
+ *
8
+ * One command stores exactly one immutable `observation_versions` row plus its
9
+ * provenance event. Observations are evidence, not judgments: no decisions row
10
+ * is created, no edges are inferred, and nothing is extracted. The command id
11
+ * binds the request through `command_bindings` so a retried ingest replays the
12
+ * recorded receipt instead of writing a second observation.
13
+ */
14
+ export interface SourceIngestCommand {
15
+ /** Idempotency key. A repeated id replays the stored receipt; the same id
16
+ * bound to different content fails with COMMAND_CONFLICT. */
17
+ commandId: string;
18
+ /** Producing connector and the source-side identity of what was captured. */
19
+ source: {
20
+ connector: string;
21
+ id: string;
22
+ };
23
+ producerVersionId?: string | null;
24
+ /** The raw payload as observed. Never rewritten or summarized. */
25
+ body: string;
26
+ author?: string | null;
27
+ /** Source-side event time (ms epoch) when known. */
28
+ sourceAt?: number | null;
29
+ /** Capture time (ms epoch); defaults to commit time. */
30
+ observedAt?: number;
31
+ /** sha256 of body when omitted. */
32
+ contentHash?: string;
33
+ metadata?: Record<string, JsonValue>;
34
+ /** Free-form scope metadata persisted on the observation row. */
35
+ scope?: Record<string, JsonValue>;
36
+ /**
37
+ * Memory scopes this ingest is bound to. An explicit `[]` stores an unscoped
38
+ * observation; an omitted field inherits the access scope.
39
+ */
40
+ scopes?: MemoryScopeRef[];
41
+ /** Provenance metadata for the observation's memory_events row. */
42
+ event?: {
43
+ eventType?: MemoryEventRecord['event_type'];
44
+ actor?: MemoryEventRecord['actor'];
45
+ sourceTurnId?: string;
46
+ reason?: string;
47
+ evidenceRefs?: string[];
48
+ };
49
+ }
50
+ export interface SourceIngestReceipt {
51
+ status: 'committed';
52
+ commandId: string;
53
+ observationId: string;
54
+ eventId: string;
55
+ watermark: number;
56
+ diagnostics: Array<{
57
+ stage: string;
58
+ code: string;
59
+ message: string;
60
+ }>;
61
+ }
62
+ export declare function ingestSource(command: SourceIngestCommand, access: JudgmentAccess, options: {
63
+ adapter: DatabaseAdapter;
64
+ }): Promise<SourceIngestReceipt>;
65
+ //# sourceMappingURL=source-ingest.d.ts.map
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ingestSource = ingestSource;
7
+ const node_crypto_1 = __importDefault(require("node:crypto"));
8
+ const canonicalize_js_1 = require("../canonicalize.js");
9
+ const observations_js_1 = require("../knowledge/observations.js");
10
+ const event_store_js_1 = require("../memory/event-store.js");
11
+ const judgments_js_1 = require("./judgments.js");
12
+ function requireNonblank(value, field) {
13
+ if (typeof value !== 'string' || value.trim() === '') {
14
+ throw new judgments_js_1.JudgmentError('INVALID_COMMAND', `${field} must be nonblank`);
15
+ }
16
+ }
17
+ function commandHash(command) {
18
+ return node_crypto_1.default.createHash('sha256').update((0, canonicalize_js_1.canonicalizeJSON)(command)).digest('hex');
19
+ }
20
+ function parseReceipt(value) {
21
+ let parsed;
22
+ try {
23
+ parsed = JSON.parse(value);
24
+ }
25
+ catch (error) {
26
+ throw new Error('source_commands.receipt_json is malformed', { cause: error });
27
+ }
28
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
29
+ throw new Error('source_commands.receipt_json must contain an object');
30
+ }
31
+ return parsed;
32
+ }
33
+ function assertReplay(adapter, command, access, hash) {
34
+ const binding = adapter
35
+ .prepare('SELECT principal_id, action, payload_hash, receipt_key FROM command_bindings WHERE command_id = ?')
36
+ .get(command.commandId);
37
+ if (!binding)
38
+ return null;
39
+ if (binding.principal_id !== access.principalId ||
40
+ binding.action !== 'source.ingest' ||
41
+ binding.payload_hash !== hash) {
42
+ throw new judgments_js_1.JudgmentError('COMMAND_CONFLICT', 'The command id is already bound to another request');
43
+ }
44
+ const row = adapter
45
+ .prepare('SELECT receipt_json FROM source_commands WHERE command_id = ?')
46
+ .get(command.commandId);
47
+ if (!row) {
48
+ throw new Error('Command binding has no source ingest receipt');
49
+ }
50
+ return parseReceipt(row.receipt_json);
51
+ }
52
+ async function ingestSourceOnAdapter(adapter, command, access) {
53
+ requireNonblank(command.commandId, 'commandId');
54
+ requireNonblank(command.source?.connector, 'source.connector');
55
+ requireNonblank(command.source?.id, 'source.id');
56
+ requireNonblank(command.body, 'body');
57
+ requireNonblank(access.principalId, 'principalId');
58
+ requireNonblank(access.agentId, 'agentId');
59
+ if (command.sourceAt !== undefined &&
60
+ command.sourceAt !== null &&
61
+ (!Number.isFinite(command.sourceAt) || command.sourceAt < 0)) {
62
+ throw new judgments_js_1.JudgmentError('INVALID_TIME', 'sourceAt must be a finite nonnegative epoch');
63
+ }
64
+ if (command.observedAt !== undefined &&
65
+ (!Number.isFinite(command.observedAt) || command.observedAt < 0)) {
66
+ throw new judgments_js_1.JudgmentError('INVALID_TIME', 'observedAt must be a finite nonnegative epoch');
67
+ }
68
+ // Admission is validated before any write: every scope the command claims
69
+ // must already be inside the caller's admitted access.
70
+ (0, judgments_js_1.admittedScopeIds)(access);
71
+ const boundScopes = (0, judgments_js_1.boundScopeIdsFor)(access, command);
72
+ const effectiveScopes = command.scopes ?? [...access.scopes];
73
+ const effectiveCommand = command.scopes
74
+ ? command
75
+ : { ...command, scopes: [...access.scopes] };
76
+ const hash = commandHash(effectiveCommand);
77
+ const replay = assertReplay(adapter, command, access, hash);
78
+ if (replay) {
79
+ return replay;
80
+ }
81
+ const observedAt = command.observedAt ?? Date.now();
82
+ const contentHash = command.contentHash ?? node_crypto_1.default.createHash('sha256').update(command.body).digest('hex');
83
+ const observationInput = {
84
+ source: command.source.connector,
85
+ sourceId: command.source.id,
86
+ producerVersionId: command.producerVersionId ?? null,
87
+ body: command.body,
88
+ author: command.author ?? null,
89
+ sourceAt: command.sourceAt ?? null,
90
+ observedAt,
91
+ contentHash,
92
+ metadata: command.metadata ?? {},
93
+ scope: {
94
+ ...(command.scope ?? {}),
95
+ scopes: boundScopes.map((scopeId, index) => ({
96
+ scopeId,
97
+ kind: effectiveScopes[index]?.kind,
98
+ externalId: effectiveScopes[index]?.id,
99
+ primary: index === 0,
100
+ })),
101
+ },
102
+ };
103
+ const boundObservationId = (0, observations_js_1.observationVersionId)(observationInput);
104
+ let replayedReceipt = null;
105
+ let committed = null;
106
+ const now = Date.now();
107
+ const transaction = adapter.transactionImmediate
108
+ ? adapter.transactionImmediate.bind(adapter)
109
+ : adapter.transaction.bind(adapter);
110
+ transaction(() => {
111
+ const bindingResult = adapter
112
+ .prepare(`INSERT OR IGNORE INTO command_bindings
113
+ (command_id, principal_id, action, payload_hash, receipt_kind, receipt_key, created_at)
114
+ VALUES (?, ?, 'source.ingest', ?, 'observation', ?, ?)`)
115
+ .run(command.commandId, access.principalId, hash, boundObservationId, now);
116
+ if (bindingResult.changes === 0) {
117
+ replayedReceipt = assertReplay(adapter, command, access, hash);
118
+ if (!replayedReceipt) {
119
+ throw new Error('Command binding was not readable after a conflict-free insert');
120
+ }
121
+ return;
122
+ }
123
+ const observation = (0, observations_js_1.appendObservationVersion)(adapter, observationInput);
124
+ const eventId = (0, event_store_js_1.insertMemoryEventInTransaction)(adapter, {
125
+ event_type: command.event?.eventType ?? 'observed_conversation',
126
+ actor: command.event?.actor ?? `actor:${access.principalId}`,
127
+ source_turn_id: command.event?.sourceTurnId,
128
+ memory_id: observation.observationId,
129
+ topic: command.source.id,
130
+ scope_refs: effectiveScopes,
131
+ evidence_refs: command.event?.evidenceRefs,
132
+ reason: command.event?.reason ?? 'source ingest command',
133
+ created_at: observedAt,
134
+ });
135
+ const receipt = {
136
+ status: 'committed',
137
+ commandId: command.commandId,
138
+ observationId: observation.observationId,
139
+ eventId,
140
+ watermark: now,
141
+ diagnostics: [],
142
+ };
143
+ adapter
144
+ .prepare(`INSERT INTO source_commands
145
+ (command_id, observation_id, event_id, committed_watermark, receipt_json, created_at)
146
+ VALUES (?, ?, ?, ?, ?, ?)`)
147
+ .run(command.commandId, observation.observationId, eventId, receipt.watermark, (0, canonicalize_js_1.canonicalizeJSON)(receipt), now);
148
+ committed = { observationId: observation.observationId, eventId };
149
+ });
150
+ if (replayedReceipt) {
151
+ return replayedReceipt;
152
+ }
153
+ if (!committed) {
154
+ throw new Error('source.ingest committed no observation');
155
+ }
156
+ const committedRef = committed;
157
+ return {
158
+ status: 'committed',
159
+ commandId: command.commandId,
160
+ observationId: committedRef.observationId,
161
+ eventId: committedRef.eventId,
162
+ watermark: now,
163
+ diagnostics: [],
164
+ };
165
+ }
166
+ async function ingestSource(command, access, options) {
167
+ // The ingest boundary no longer reaches the process-global store: the
168
+ // caller names the database this observation commits to.
169
+ if (!options?.adapter) {
170
+ throw new judgments_js_1.JudgmentError('INVALID_COMMAND', 'ingestSource requires an explicit adapter; the process-global store is not a write path');
171
+ }
172
+ return ingestSourceOnAdapter(options.adapter, command, access);
173
+ }
174
+ //# sourceMappingURL=source-ingest.js.map
@@ -1,9 +1,9 @@
1
1
  import type { Buffer } from 'node:buffer';
2
- export declare const TWIN_REF_KINDS: readonly ["memory", "case", "entity", "report", "edge", "raw"];
2
+ export declare const TWIN_REF_KINDS: readonly ["memory", "case", "report", "edge", "raw", "registry", "observation"];
3
3
  export type TwinRefKind = (typeof TWIN_REF_KINDS)[number];
4
4
  export declare const TWIN_EDGE_SOURCES: readonly ["agent", "human", "code"];
5
5
  export type TwinEdgeSource = (typeof TWIN_EDGE_SOURCES)[number];
6
- export declare const TWIN_EDGE_TYPES: readonly ["supersedes", "builds_on", "debates", "synthesizes", "mentions", "derived_from", "case_member", "alias_of", "next_action_for", "blocks"];
6
+ export declare const TWIN_EDGE_TYPES: readonly ["supersedes", "refines", "contradicts", "builds_on", "debates", "synthesizes", "mentions", "derived_from", "case_member", "alias_of", "next_action_for", "blocks", "amends"];
7
7
  export type TwinEdgeType = (typeof TWIN_EDGE_TYPES)[number];
8
8
  export type TwinRef = {
9
9
  [Kind in TwinRefKind]: {
@@ -15,7 +15,11 @@ export type TwinEdgeSubjectRef = Exclude<TwinRef, {
15
15
  kind: 'raw';
16
16
  }>;
17
17
  export interface TwinScopeRef {
18
- kind: 'global' | 'user' | 'channel' | 'project';
18
+ /**
19
+ * The consumer's word for what kind of scope this is. The core matches it; it
20
+ * does not read it. Closed lists of kinds used to live here, in three copies.
21
+ */
22
+ kind: string;
19
23
  id: string;
20
24
  }
21
25
  export interface TwinProjectRef {
@@ -23,12 +27,18 @@ export interface TwinProjectRef {
23
27
  id: string;
24
28
  }
25
29
  export interface TwinVisibility {
30
+ principalId?: string;
31
+ agentId?: string;
26
32
  scopes?: TwinScopeRef[];
27
33
  connectors?: string[];
34
+ /** Host-stated connector-wide stored read, such as the configured owner has on source.read. */
35
+ connectorWideRead?: string[];
28
36
  projectRefs?: TwinProjectRef[];
29
37
  tenantId?: string | null;
30
38
  startMs?: number | null;
31
39
  asOfMs?: number | null;
40
+ /** Inclusive source/event-time ceiling for replay raw reads. */
41
+ maxSourceMs?: number | null;
32
42
  /**
33
43
  * Which channels of each connector may be read. When present it DECIDES raw visibility
34
44
  * here exactly as it does in the reader, so a ref reached through an edge or named as a
@@ -36,6 +46,13 @@ export interface TwinVisibility {
36
46
  * caller could reach past the read path by citing what it could not have read.
37
47
  */
38
48
  channels?: Record<string, readonly string[]>;
49
+ /**
50
+ * Read replaced records as history: lifts the superseded/superseded_by
51
+ * retirement check while every other rule — scope, connector, channel,
52
+ * tenant, time window — still applies. Quarantined, contradicted and stale
53
+ * records stay excluded in every mode; they are holds, not history.
54
+ */
55
+ includeReplaced?: boolean;
39
56
  }
40
57
  export interface InsertTwinEdgeInput {
41
58
  edge_id?: string;
@@ -57,6 +74,16 @@ export interface InsertTwinEdgeInput {
57
74
  reason_text?: string;
58
75
  evidence_refs?: unknown;
59
76
  }
77
+ /**
78
+ * One fully resolved twin_edges row to write. Callers own edge_id, content_hash,
79
+ * and created_at because each write path derives them differently (deterministic
80
+ * command hashes vs fresh UUIDs); the writer owns the INSERT itself.
81
+ */
82
+ export interface TwinEdgeInsert extends InsertTwinEdgeInput {
83
+ edge_id: string;
84
+ content_hash: Buffer;
85
+ created_at: number;
86
+ }
60
87
  export interface TwinEdgeRecord {
61
88
  edge_id: string;
62
89
  edge_type: TwinEdgeType;
@@ -95,4 +122,4 @@ export interface ListVisibleTwinEdgesOptions {
95
122
  * cannot silently drop the grant - it crossed this seam as an undeclared property. */
96
123
  channels?: Record<string, readonly string[]>;
97
124
  }
98
- //# sourceMappingURL=types.d.ts.map
125
+ //# sourceMappingURL=twin-edge-types.d.ts.map
@@ -1,10 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TWIN_EDGE_TYPES = exports.TWIN_EDGE_SOURCES = exports.TWIN_REF_KINDS = void 0;
4
- exports.TWIN_REF_KINDS = ['memory', 'case', 'entity', 'report', 'edge', 'raw'];
4
+ exports.TWIN_REF_KINDS = [
5
+ 'memory',
6
+ 'case',
7
+ 'report',
8
+ 'edge',
9
+ 'raw',
10
+ 'registry',
11
+ 'observation',
12
+ ];
5
13
  exports.TWIN_EDGE_SOURCES = ['agent', 'human', 'code'];
6
14
  exports.TWIN_EDGE_TYPES = [
7
15
  'supersedes',
16
+ 'refines',
17
+ 'contradicts',
8
18
  'builds_on',
9
19
  'debates',
10
20
  'synthesizes',
@@ -14,5 +24,6 @@ exports.TWIN_EDGE_TYPES = [
14
24
  'alias_of',
15
25
  'next_action_for',
16
26
  'blocks',
27
+ 'amends',
17
28
  ];
18
- //# sourceMappingURL=types.js.map
29
+ //# sourceMappingURL=twin-edge-types.js.map
@@ -0,0 +1,49 @@
1
+ /**
2
+ * The grammar of the OwnerWorkPatch date fields.
3
+ *
4
+ * A patch can state a deadline two ways: `dueAt` is an exact instant (RFC 3339
5
+ * with an explicit offset) and `deadline` is a bare calendar date. Readers fold
6
+ * the patch and parse both fields strictly, so a malformed value committed here
7
+ * makes the whole row unreadable. The writers validate before commit rather
8
+ * than letting a strict read discover the damage at boot.
9
+ *
10
+ * This module owns the field grammar only. Zone arithmetic — which local date
11
+ * an instant lands on, where a deadline day starts — belongs to the product's
12
+ * board projection, not the commitment log.
13
+ *
14
+ * @module knowledge/work-dates
15
+ */
16
+ import type { OwnerWorkPatch } from '../memory/judgment-types.js';
17
+ export declare const WORK_PATCH_DUE_AT_PATTERN: string;
18
+ export declare const WORK_PATCH_DEADLINE_PATTERN: string;
19
+ export interface ParsedExactDueAt {
20
+ dueAt: number;
21
+ deadline: string;
22
+ offsetMinutes: number;
23
+ }
24
+ /**
25
+ * Parse a `dueAt` value: an RFC 3339 timestamp with an explicit offset.
26
+ *
27
+ * A bare date is not an instant and a bare instant without an offset does not
28
+ * say where midnight falls, so neither is accepted - the caller states the
29
+ * offset it means.
30
+ */
31
+ export declare function parseExactDueAt(value: string): ParsedExactDueAt;
32
+ /**
33
+ * Reject a `deadline` value that is not a real calendar date.
34
+ *
35
+ * `2026-02-30` matches the date pattern but is not a day that exists, and a
36
+ * reader that computes the start of that day has no honest answer for it.
37
+ */
38
+ export declare function assertIsoDate(value: string, field: string): void;
39
+ /**
40
+ * Reject a work patch whose declared date fields cannot be read back.
41
+ *
42
+ * `null` is an absent statement, not a malformed one - the fold reads it as the
43
+ * field cleared. A non-null value must be a well-formed string of its grammar.
44
+ * What the fields mean together (whether `dueAt` and `deadline` may disagree)
45
+ * is the board's contract, not the log's: this checks only that each stated
46
+ * value parses.
47
+ */
48
+ export declare function assertWorkPatchValues(set: OwnerWorkPatch): void;
49
+ //# sourceMappingURL=work-dates.d.ts.map