@graphorin/memory 0.5.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 (287) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/LICENSE +21 -0
  3. package/README.md +401 -0
  4. package/dist/conflict/index.d.ts +3 -0
  5. package/dist/conflict/index.js +7 -0
  6. package/dist/conflict/locale-packs/en.js +262 -0
  7. package/dist/conflict/locale-packs/en.js.map +1 -0
  8. package/dist/conflict/locale-packs/index.js +4 -0
  9. package/dist/conflict/locale-packs/types.d.ts +103 -0
  10. package/dist/conflict/locale-packs/types.d.ts.map +1 -0
  11. package/dist/conflict/locale-packs/types.js +55 -0
  12. package/dist/conflict/locale-packs/types.js.map +1 -0
  13. package/dist/conflict/pipeline.d.ts +35 -0
  14. package/dist/conflict/pipeline.d.ts.map +1 -0
  15. package/dist/conflict/pipeline.js +257 -0
  16. package/dist/conflict/pipeline.js.map +1 -0
  17. package/dist/conflict/stages/helpers.js +66 -0
  18. package/dist/conflict/stages/helpers.js.map +1 -0
  19. package/dist/conflict/stages/stage1-exact-dedup.js +21 -0
  20. package/dist/conflict/stages/stage1-exact-dedup.js.map +1 -0
  21. package/dist/conflict/stages/stage2-embedding-three-zone.js +37 -0
  22. package/dist/conflict/stages/stage2-embedding-three-zone.js.map +1 -0
  23. package/dist/conflict/stages/stage3-heuristic-regex.js +45 -0
  24. package/dist/conflict/stages/stage3-heuristic-regex.js.map +1 -0
  25. package/dist/conflict/stages/stage4-subject-predicate.js +31 -0
  26. package/dist/conflict/stages/stage4-subject-predicate.js.map +1 -0
  27. package/dist/conflict/stages/stage5-defer-to-deep.js +22 -0
  28. package/dist/conflict/stages/stage5-defer-to-deep.js.map +1 -0
  29. package/dist/conflict/types.d.ts +222 -0
  30. package/dist/conflict/types.d.ts.map +1 -0
  31. package/dist/conflict/types.js +50 -0
  32. package/dist/conflict/types.js.map +1 -0
  33. package/dist/consolidator/budget.d.ts +1 -0
  34. package/dist/consolidator/budget.js +214 -0
  35. package/dist/consolidator/budget.js.map +1 -0
  36. package/dist/consolidator/decay.d.ts +35 -0
  37. package/dist/consolidator/decay.d.ts.map +1 -0
  38. package/dist/consolidator/decay.js +91 -0
  39. package/dist/consolidator/decay.js.map +1 -0
  40. package/dist/consolidator/dlq.js +58 -0
  41. package/dist/consolidator/dlq.js.map +1 -0
  42. package/dist/consolidator/errors.d.ts +54 -0
  43. package/dist/consolidator/errors.d.ts.map +1 -0
  44. package/dist/consolidator/errors.js +67 -0
  45. package/dist/consolidator/errors.js.map +1 -0
  46. package/dist/consolidator/idempotency.d.ts +1 -0
  47. package/dist/consolidator/idempotency.js +22 -0
  48. package/dist/consolidator/idempotency.js.map +1 -0
  49. package/dist/consolidator/index.d.ts +34 -0
  50. package/dist/consolidator/index.d.ts.map +1 -0
  51. package/dist/consolidator/index.js +163 -0
  52. package/dist/consolidator/index.js.map +1 -0
  53. package/dist/consolidator/lock.d.ts +2 -0
  54. package/dist/consolidator/lock.js +89 -0
  55. package/dist/consolidator/lock.js.map +1 -0
  56. package/dist/consolidator/noise-filter.d.ts +2 -0
  57. package/dist/consolidator/noise-filter.js +173 -0
  58. package/dist/consolidator/noise-filter.js.map +1 -0
  59. package/dist/consolidator/phases/deep.d.ts +4 -0
  60. package/dist/consolidator/phases/deep.js +198 -0
  61. package/dist/consolidator/phases/deep.js.map +1 -0
  62. package/dist/consolidator/phases/induce.d.ts +154 -0
  63. package/dist/consolidator/phases/induce.d.ts.map +1 -0
  64. package/dist/consolidator/phases/induce.js +253 -0
  65. package/dist/consolidator/phases/induce.js.map +1 -0
  66. package/dist/consolidator/phases/light.d.ts +4 -0
  67. package/dist/consolidator/phases/light.js +99 -0
  68. package/dist/consolidator/phases/light.js.map +1 -0
  69. package/dist/consolidator/phases/reflect.js +287 -0
  70. package/dist/consolidator/phases/reflect.js.map +1 -0
  71. package/dist/consolidator/phases/standard.d.ts +8 -0
  72. package/dist/consolidator/phases/standard.js +499 -0
  73. package/dist/consolidator/phases/standard.js.map +1 -0
  74. package/dist/consolidator/reconcile.js +192 -0
  75. package/dist/consolidator/reconcile.js.map +1 -0
  76. package/dist/consolidator/runtime.d.ts +62 -0
  77. package/dist/consolidator/runtime.d.ts.map +1 -0
  78. package/dist/consolidator/runtime.js +580 -0
  79. package/dist/consolidator/runtime.js.map +1 -0
  80. package/dist/consolidator/scheduler.d.ts +111 -0
  81. package/dist/consolidator/scheduler.d.ts.map +1 -0
  82. package/dist/consolidator/scheduler.js +71 -0
  83. package/dist/consolidator/scheduler.js.map +1 -0
  84. package/dist/consolidator/triggers.d.ts +40 -0
  85. package/dist/consolidator/triggers.d.ts.map +1 -0
  86. package/dist/consolidator/triggers.js +94 -0
  87. package/dist/consolidator/triggers.js.map +1 -0
  88. package/dist/consolidator/types.d.ts +397 -0
  89. package/dist/consolidator/types.d.ts.map +1 -0
  90. package/dist/consolidator/types.js +117 -0
  91. package/dist/consolidator/types.js.map +1 -0
  92. package/dist/context-engine/annotations.d.ts +118 -0
  93. package/dist/context-engine/annotations.d.ts.map +1 -0
  94. package/dist/context-engine/annotations.js +102 -0
  95. package/dist/context-engine/annotations.js.map +1 -0
  96. package/dist/context-engine/auto-recall.d.ts +52 -0
  97. package/dist/context-engine/auto-recall.d.ts.map +1 -0
  98. package/dist/context-engine/auto-recall.js +41 -0
  99. package/dist/context-engine/auto-recall.js.map +1 -0
  100. package/dist/context-engine/compaction/clear-tool-results.d.ts +55 -0
  101. package/dist/context-engine/compaction/clear-tool-results.d.ts.map +1 -0
  102. package/dist/context-engine/compaction/clear-tool-results.js +97 -0
  103. package/dist/context-engine/compaction/clear-tool-results.js.map +1 -0
  104. package/dist/context-engine/compaction/compactor.d.ts +52 -0
  105. package/dist/context-engine/compaction/compactor.d.ts.map +1 -0
  106. package/dist/context-engine/compaction/compactor.js +196 -0
  107. package/dist/context-engine/compaction/compactor.js.map +1 -0
  108. package/dist/context-engine/compaction/hooks/reanchor-persona-block.d.ts +15 -0
  109. package/dist/context-engine/compaction/hooks/reanchor-persona-block.d.ts.map +1 -0
  110. package/dist/context-engine/compaction/hooks/reanchor-persona-block.js +27 -0
  111. package/dist/context-engine/compaction/hooks/reanchor-persona-block.js.map +1 -0
  112. package/dist/context-engine/compaction/hooks/reanchor-pinned-facts.d.ts +18 -0
  113. package/dist/context-engine/compaction/hooks/reanchor-pinned-facts.d.ts.map +1 -0
  114. package/dist/context-engine/compaction/hooks/reanchor-pinned-facts.js +47 -0
  115. package/dist/context-engine/compaction/hooks/reanchor-pinned-facts.js.map +1 -0
  116. package/dist/context-engine/compaction/hooks/reanchor-project-rules.d.ts +15 -0
  117. package/dist/context-engine/compaction/hooks/reanchor-project-rules.d.ts.map +1 -0
  118. package/dist/context-engine/compaction/hooks/reanchor-project-rules.js +32 -0
  119. package/dist/context-engine/compaction/hooks/reanchor-project-rules.js.map +1 -0
  120. package/dist/context-engine/compaction/hooks/types.d.ts +42 -0
  121. package/dist/context-engine/compaction/hooks/types.d.ts.map +1 -0
  122. package/dist/context-engine/compaction/index.d.ts +9 -0
  123. package/dist/context-engine/compaction/index.js +9 -0
  124. package/dist/context-engine/compaction/templates/summary-9-section.d.ts +84 -0
  125. package/dist/context-engine/compaction/templates/summary-9-section.d.ts.map +1 -0
  126. package/dist/context-engine/compaction/templates/summary-9-section.js +84 -0
  127. package/dist/context-engine/compaction/templates/summary-9-section.js.map +1 -0
  128. package/dist/context-engine/compaction/thresholds.d.ts +68 -0
  129. package/dist/context-engine/compaction/thresholds.d.ts.map +1 -0
  130. package/dist/context-engine/compaction/thresholds.js +63 -0
  131. package/dist/context-engine/compaction/thresholds.js.map +1 -0
  132. package/dist/context-engine/compaction/types.d.ts +202 -0
  133. package/dist/context-engine/compaction/types.d.ts.map +1 -0
  134. package/dist/context-engine/engine.d.ts +258 -0
  135. package/dist/context-engine/engine.d.ts.map +1 -0
  136. package/dist/context-engine/engine.js +424 -0
  137. package/dist/context-engine/engine.js.map +1 -0
  138. package/dist/context-engine/index.d.ts +68 -0
  139. package/dist/context-engine/index.d.ts.map +1 -0
  140. package/dist/context-engine/index.js +24 -0
  141. package/dist/context-engine/locale-packs/en.d.ts +14 -0
  142. package/dist/context-engine/locale-packs/en.d.ts.map +1 -0
  143. package/dist/context-engine/locale-packs/en.js +87 -0
  144. package/dist/context-engine/locale-packs/en.js.map +1 -0
  145. package/dist/context-engine/locale-packs/index.js +4 -0
  146. package/dist/context-engine/locale-packs/resolver.d.ts +41 -0
  147. package/dist/context-engine/locale-packs/resolver.d.ts.map +1 -0
  148. package/dist/context-engine/locale-packs/resolver.js +119 -0
  149. package/dist/context-engine/locale-packs/resolver.js.map +1 -0
  150. package/dist/context-engine/locale-packs/types.d.ts +119 -0
  151. package/dist/context-engine/locale-packs/types.d.ts.map +1 -0
  152. package/dist/context-engine/locale-packs/types.js +24 -0
  153. package/dist/context-engine/locale-packs/types.js.map +1 -0
  154. package/dist/context-engine/metadata.d.ts +40 -0
  155. package/dist/context-engine/metadata.d.ts.map +1 -0
  156. package/dist/context-engine/metadata.js +66 -0
  157. package/dist/context-engine/metadata.js.map +1 -0
  158. package/dist/context-engine/preambles/inbound-en.d.ts +20 -0
  159. package/dist/context-engine/preambles/inbound-en.d.ts.map +1 -0
  160. package/dist/context-engine/preambles/inbound-en.js +23 -0
  161. package/dist/context-engine/preambles/inbound-en.js.map +1 -0
  162. package/dist/context-engine/privacy-filter.d.ts +108 -0
  163. package/dist/context-engine/privacy-filter.d.ts.map +1 -0
  164. package/dist/context-engine/privacy-filter.js +113 -0
  165. package/dist/context-engine/privacy-filter.js.map +1 -0
  166. package/dist/context-engine/templates/base-en.d.ts +19 -0
  167. package/dist/context-engine/templates/base-en.d.ts.map +1 -0
  168. package/dist/context-engine/templates/base-en.js +22 -0
  169. package/dist/context-engine/templates/base-en.js.map +1 -0
  170. package/dist/context-engine/templates/composer.d.ts +55 -0
  171. package/dist/context-engine/templates/composer.d.ts.map +1 -0
  172. package/dist/context-engine/templates/composer.js +51 -0
  173. package/dist/context-engine/templates/composer.js.map +1 -0
  174. package/dist/context-engine/token-budget.d.ts +99 -0
  175. package/dist/context-engine/token-budget.d.ts.map +1 -0
  176. package/dist/context-engine/token-budget.js +211 -0
  177. package/dist/context-engine/token-budget.js.map +1 -0
  178. package/dist/context-engine/token-counter.d.ts +54 -0
  179. package/dist/context-engine/token-counter.d.ts.map +1 -0
  180. package/dist/context-engine/token-counter.js +81 -0
  181. package/dist/context-engine/token-counter.js.map +1 -0
  182. package/dist/errors/index.d.ts +171 -0
  183. package/dist/errors/index.d.ts.map +1 -0
  184. package/dist/errors/index.js +206 -0
  185. package/dist/errors/index.js.map +1 -0
  186. package/dist/facade.d.ts +278 -0
  187. package/dist/facade.d.ts.map +1 -0
  188. package/dist/facade.js +265 -0
  189. package/dist/facade.js.map +1 -0
  190. package/dist/graph/entity-resolver.d.ts +135 -0
  191. package/dist/graph/entity-resolver.d.ts.map +1 -0
  192. package/dist/graph/entity-resolver.js +202 -0
  193. package/dist/graph/entity-resolver.js.map +1 -0
  194. package/dist/graph/index.d.ts +1 -0
  195. package/dist/index.d.ts +103 -0
  196. package/dist/index.d.ts.map +1 -0
  197. package/dist/index.js +95 -0
  198. package/dist/index.js.map +1 -0
  199. package/dist/internal/contextualize.d.ts +14 -0
  200. package/dist/internal/contextualize.d.ts.map +1 -0
  201. package/dist/internal/contextualize.js +110 -0
  202. package/dist/internal/contextualize.js.map +1 -0
  203. package/dist/internal/embedder-binding.js +50 -0
  204. package/dist/internal/embedder-binding.js.map +1 -0
  205. package/dist/internal/id.js +24 -0
  206. package/dist/internal/id.js.map +1 -0
  207. package/dist/internal/injection-heuristics.js +64 -0
  208. package/dist/internal/injection-heuristics.js.map +1 -0
  209. package/dist/internal/spans.js +35 -0
  210. package/dist/internal/spans.js.map +1 -0
  211. package/dist/internal/storage-adapter.d.ts +742 -0
  212. package/dist/internal/storage-adapter.d.ts.map +1 -0
  213. package/dist/migration/embedder-migration.d.ts +124 -0
  214. package/dist/migration/embedder-migration.d.ts.map +1 -0
  215. package/dist/migration/embedder-migration.js +109 -0
  216. package/dist/migration/embedder-migration.js.map +1 -0
  217. package/dist/migration/index.d.ts +2 -0
  218. package/dist/migration/index.js +3 -0
  219. package/dist/search/explain.d.ts +74 -0
  220. package/dist/search/explain.d.ts.map +1 -0
  221. package/dist/search/explain.js +50 -0
  222. package/dist/search/explain.js.map +1 -0
  223. package/dist/search/index.d.ts +6 -0
  224. package/dist/search/index.js +6 -0
  225. package/dist/search/iterative.d.ts +223 -0
  226. package/dist/search/iterative.d.ts.map +1 -0
  227. package/dist/search/iterative.js +330 -0
  228. package/dist/search/iterative.js.map +1 -0
  229. package/dist/search/query-transform.d.ts +112 -0
  230. package/dist/search/query-transform.d.ts.map +1 -0
  231. package/dist/search/query-transform.js +184 -0
  232. package/dist/search/query-transform.js.map +1 -0
  233. package/dist/search/rrf.d.ts +95 -0
  234. package/dist/search/rrf.d.ts.map +1 -0
  235. package/dist/search/rrf.js +166 -0
  236. package/dist/search/rrf.js.map +1 -0
  237. package/dist/search/types.d.ts +50 -0
  238. package/dist/search/types.d.ts.map +1 -0
  239. package/dist/tiers/episodic-memory.d.ts +142 -0
  240. package/dist/tiers/episodic-memory.d.ts.map +1 -0
  241. package/dist/tiers/episodic-memory.js +254 -0
  242. package/dist/tiers/episodic-memory.js.map +1 -0
  243. package/dist/tiers/index.d.ts +8 -0
  244. package/dist/tiers/index.js +9 -0
  245. package/dist/tiers/insight-memory.d.ts +71 -0
  246. package/dist/tiers/insight-memory.d.ts.map +1 -0
  247. package/dist/tiers/insight-memory.js +133 -0
  248. package/dist/tiers/insight-memory.js.map +1 -0
  249. package/dist/tiers/procedural-memory.d.ts +147 -0
  250. package/dist/tiers/procedural-memory.d.ts.map +1 -0
  251. package/dist/tiers/procedural-memory.js +267 -0
  252. package/dist/tiers/procedural-memory.js.map +1 -0
  253. package/dist/tiers/semantic-memory.d.ts +461 -0
  254. package/dist/tiers/semantic-memory.d.ts.map +1 -0
  255. package/dist/tiers/semantic-memory.js +631 -0
  256. package/dist/tiers/semantic-memory.js.map +1 -0
  257. package/dist/tiers/session-memory.d.ts +117 -0
  258. package/dist/tiers/session-memory.d.ts.map +1 -0
  259. package/dist/tiers/session-memory.js +163 -0
  260. package/dist/tiers/session-memory.js.map +1 -0
  261. package/dist/tiers/shared-memory.d.ts +29 -0
  262. package/dist/tiers/shared-memory.d.ts.map +1 -0
  263. package/dist/tiers/shared-memory.js +58 -0
  264. package/dist/tiers/shared-memory.js.map +1 -0
  265. package/dist/tiers/working-memory.d.ts +129 -0
  266. package/dist/tiers/working-memory.d.ts.map +1 -0
  267. package/dist/tiers/working-memory.js +229 -0
  268. package/dist/tiers/working-memory.js.map +1 -0
  269. package/dist/tools/block-tools.d.ts +98 -0
  270. package/dist/tools/block-tools.d.ts.map +1 -0
  271. package/dist/tools/block-tools.js +114 -0
  272. package/dist/tools/block-tools.js.map +1 -0
  273. package/dist/tools/fact-tools.d.ts +294 -0
  274. package/dist/tools/fact-tools.d.ts.map +1 -0
  275. package/dist/tools/fact-tools.js +293 -0
  276. package/dist/tools/fact-tools.js.map +1 -0
  277. package/dist/tools/index.d.ts +35 -0
  278. package/dist/tools/index.d.ts.map +1 -0
  279. package/dist/tools/index.js +36 -0
  280. package/dist/tools/index.js.map +1 -0
  281. package/dist/tools/recall-tools.d.ts +209 -0
  282. package/dist/tools/recall-tools.d.ts.map +1 -0
  283. package/dist/tools/recall-tools.js +170 -0
  284. package/dist/tools/recall-tools.js.map +1 -0
  285. package/dist/tools/types.d.ts +40 -0
  286. package/dist/tools/types.d.ts.map +1 -0
  287. package/package.json +119 -0
@@ -0,0 +1,742 @@
1
+ import { EntityRole, Episode as Episode$1, EpisodicMemoryStore, Fact as Fact$1, GraphEntity, Insight as Insight$1, MemoryHit, MemoryStatus, MemoryStore, Message as Message$1, ProceduralMemoryStore, SemanticMemoryStore, SessionMemoryStore, SessionScope as SessionScope$1 } from "@graphorin/core";
2
+
3
+ //#region src/internal/storage-adapter.d.ts
4
+
5
+ /**
6
+ * Shape of the embedding payload threaded through the optional
7
+ * embedded write helpers exposed by adapters such as
8
+ * `@graphorin/store-sqlite`. Matches the storage adapter's
9
+ * `SqliteMemoryWriteOptions` byte-for-byte but is declared
10
+ * structurally here so `@graphorin/memory` does not import the
11
+ * storage package directly.
12
+ *
13
+ * @stable
14
+ */
15
+ interface EmbeddedWriteOptions {
16
+ readonly embedding?: {
17
+ readonly embedderId: string;
18
+ readonly vector: Float32Array;
19
+ };
20
+ /**
21
+ * Contextual-retrieval index text (P1-3). When supplied, the adapter
22
+ * indexes its lexical (FTS) surface against this context-prepended
23
+ * text while persisting the canonical `text` unchanged. Absent ⇒ the
24
+ * canonical text is indexed (pre-P1-3 behaviour).
25
+ */
26
+ readonly indexText?: string;
27
+ }
28
+ /**
29
+ * Extension of the typed `EpisodicMemoryStore` with optional
30
+ * embedding-aware helpers + lifecycle helpers that storage adapters
31
+ * may expose.
32
+ *
33
+ * @stable
34
+ */
35
+ interface EpisodicMemoryStoreExt extends EpisodicMemoryStore {
36
+ putWithEmbedding?(episode: Episode$1, options: EmbeddedWriteOptions): Promise<void>;
37
+ searchVector?(scope: SessionScope$1, embedding: Float32Array, embedderId: string, topK: number, /** Point-in-time filter (`started_at <= asOf`, ISO-8601). P0-2. */
38
+ asOf?: string, /** Include quarantined episodes (validation/inspector path). P1-4. */
39
+ includeQuarantined?: boolean): Promise<ReadonlyArray<MemoryHit<Episode$1>>>;
40
+ /** Mark an episode archived. Soft-archive — the row stays for replay. */
41
+ archive?(id: string, reason?: string): Promise<void>;
42
+ /**
43
+ * Most-recent episodes by end time (newest first), with no FTS / vector
44
+ * query — recency, not relevance (MCON-1). Powers `EpisodicMemory.recent()`
45
+ * and the deep-phase reflection gate. The default `@graphorin/store-sqlite`
46
+ * adapter implements it.
47
+ */
48
+ listRecent?(scope: SessionScope$1, limit: number, options?: {
49
+ includeQuarantined?: boolean;
50
+ }): Promise<ReadonlyArray<Episode$1>>;
51
+ /**
52
+ * Set an episode's retrieval-trust `status` (MCON-2) — promote a quarantined
53
+ * (auto-formed) episode into default recall or re-quarantine an active one,
54
+ * with a `memory_history` audit row. Powers {@link EpisodicMemory.validate}.
55
+ */
56
+ setStatus?(id: string, status: MemoryStatus, reason?: string): Promise<void>;
57
+ /**
58
+ * Count the recall-eligible episodes for the scope (CE-5) — a `COUNT(*)`,
59
+ * never materialising rows. Powers honest `metadata()` counts.
60
+ */
61
+ count?(scope: SessionScope$1): Promise<number>;
62
+ }
63
+ /**
64
+ * Extension of the typed `SemanticMemoryStore` with optional
65
+ * embedding-aware helpers + lifecycle helpers that storage adapters
66
+ * may expose.
67
+ *
68
+ * @stable
69
+ */
70
+ interface SemanticMemoryStoreExt extends SemanticMemoryStore {
71
+ rememberWithEmbedding?(fact: Fact$1, options: EmbeddedWriteOptions): Promise<void>;
72
+ searchVector?(scope: SessionScope$1, embedding: Float32Array, embedderId: string, topK: number,
73
+ /**
74
+ * Point-in-time filter applied after KNN: only facts whose
75
+ * validity interval contains `asOf` (ISO-8601) survive. P0-2.
76
+ */
77
+ asOf?: string,
78
+ /**
79
+ * Include quarantined facts in the KNN result (validation /
80
+ * inspector path). Default reads exclude them. P1-4.
81
+ */
82
+ includeQuarantined?: boolean): Promise<ReadonlyArray<MemoryHit<Fact$1>>>;
83
+ /** Lookup a single fact by id (returns `null` when absent or soft-deleted). */
84
+ get?(id: string): Promise<Fact$1 | null>;
85
+ /**
86
+ * Set a fact's retrieval-trust `status` and write a `memory_history`
87
+ * audit row (P1-4). Promotes a quarantined fact to `active` (the
88
+ * validation path) or re-quarantines an active one. Never touches
89
+ * content / embedding / tombstone — quarantine is a retrieval gate.
90
+ * Powers {@link SemanticMemory.validate}; the default
91
+ * `@graphorin/store-sqlite` adapter implements it.
92
+ */
93
+ setStatus?(factId: string, status: MemoryStatus, reason?: string): Promise<void>;
94
+ /**
95
+ * Count the recall-eligible facts for the scope (CE-5) — a `COUNT(*)` with
96
+ * the default recall filters (live, non-archived, non-quarantined), never
97
+ * materialising rows. Powers honest `metadata()` counts.
98
+ */
99
+ count?(scope: SessionScope$1): Promise<number>;
100
+ /**
101
+ * Hard-delete a fact (GDPR path). The audit log row is preserved
102
+ * but the row itself + every per-embedder vec0 entry is removed.
103
+ * Distinct from {@link SemanticMemoryStore.forget} (soft-delete).
104
+ */
105
+ purge?(id: string, reason?: string): Promise<void>;
106
+ /**
107
+ * Walk the bi-temporal supersede chain that `factId` belongs to and
108
+ * return every fact in it, oldest → newest (by `validFrom`),
109
+ * including superseded / soft-deleted rows so callers can answer
110
+ * "how did this fact change over time". Scope-guarded and
111
+ * cycle-safe; returns `[]` for an unknown id. Powers
112
+ * {@link SemanticMemory.history} (P0-2). The default
113
+ * `@graphorin/store-sqlite` adapter implements it.
114
+ */
115
+ historyOf?(scope: SessionScope$1, factId: string): Promise<ReadonlyArray<Fact$1>>;
116
+ }
117
+ /**
118
+ * Single message tuple returned by
119
+ * {@link SessionMemoryStoreExt.listMessagesSince}. The optional
120
+ * `tokenCount` field is the value cached in the storage layer
121
+ * (DEC-131); `null` indicates the cache is empty.
122
+ *
123
+ * @stable
124
+ */
125
+ interface SessionMessageRecord {
126
+ readonly id: string;
127
+ readonly sequence: number;
128
+ readonly createdAt: string;
129
+ readonly tokenCount: number | null;
130
+ readonly message: Message$1;
131
+ }
132
+ /**
133
+ * Extension of the typed `SessionMemoryStore` with optional
134
+ * token-cache + vector-search + cursor-aware reader helpers that
135
+ * storage adapters may expose.
136
+ *
137
+ * @stable
138
+ */
139
+ interface SessionMemoryStoreExt extends SessionMemoryStore {
140
+ searchVector?(scope: SessionScope$1, embedding: Float32Array, embedderId: string, topK: number): Promise<ReadonlyArray<MemoryHit>>;
141
+ /**
142
+ * Sum of `session_messages.token_count` for the supplied scope.
143
+ * Returns `null` when the cache is empty / partially populated so
144
+ * callers can fall back to a heuristic. Surfaced per DEC-131.
145
+ */
146
+ totalCachedTokens?(scope: SessionScope$1): Promise<number | null>;
147
+ /**
148
+ * List messages for the supplied scope past the optional
149
+ * `lastMessageId` cursor, oldest-first, capped at `limit`. Used by
150
+ * the consolidator's standard phase to advance the per-scope
151
+ * idempotency cursor without rereading already-processed turns.
152
+ */
153
+ listMessagesSince?(scope: SessionScope$1, lastMessageId: string | null, limit: number): Promise<ReadonlyArray<SessionMessageRecord>>;
154
+ /**
155
+ * Count the live messages in the scoped session (CE-5) — a `COUNT(*)`, never
156
+ * materialising rows; `0` for a user-only scope. Powers honest `metadata()`
157
+ * counts instead of `list(...)`-materialising up to 1000 rows.
158
+ */
159
+ count?(scope: SessionScope$1): Promise<number>;
160
+ }
161
+ /**
162
+ * Optional extension surface for storage adapters' embedder registry.
163
+ * The interface is structural so any adapter that matches the shape
164
+ * works.
165
+ *
166
+ * @stable
167
+ */
168
+ interface EmbeddingMetaRegistryLike {
169
+ registerOrReturn(input: {
170
+ readonly id: string;
171
+ readonly embedderKind: string;
172
+ readonly model: string;
173
+ readonly dim: number;
174
+ readonly distanceMetric?: 'cosine' | 'dot' | 'euclidean';
175
+ readonly configHash: string;
176
+ readonly notes?: string | null;
177
+ }): {
178
+ readonly id: string;
179
+ };
180
+ get(id: string): unknown | null;
181
+ assertKnown(id: string): void;
182
+ retire(id: string, retiredAt?: number): void;
183
+ listAll(): ReadonlyArray<{
184
+ readonly id: string;
185
+ readonly retiredAt: number | null;
186
+ }>;
187
+ listActive(): ReadonlyArray<{
188
+ readonly id: string;
189
+ readonly retiredAt: number | null;
190
+ }>;
191
+ }
192
+ /**
193
+ * Stable lowercase identifier for the pipeline stage that produced a
194
+ * conflict decision. Mirrored byte-for-byte by
195
+ * `@graphorin/store-sqlite`'s `ConflictPipelineStage`.
196
+ *
197
+ * @stable
198
+ */
199
+ type ConflictAuditStage = 'exact-dedup' | 'embedding-three-zone' | 'heuristic-regex' | 'subject-predicate' | 'defer-to-deep';
200
+ /**
201
+ * Final pipeline outcome recorded against the candidate fact. Matches
202
+ * the storage adapter's `ConflictPipelineDecision` exactly.
203
+ * `'judge-unparseable'` closes a pending row whose deep-phase judge
204
+ * call repeatedly failed (MCON-9) so it stops being re-billed forever.
205
+ *
206
+ * @stable
207
+ */
208
+ type ConflictAuditDecision = 'admit' | 'dedup' | 'supersede' | 'pending' | 'judge-unparseable';
209
+ /**
210
+ * Single audit row written by `runConflictPipeline(...)`. The optional
211
+ * `ConflictMemoryStoreExt.recordDecision` accepts this shape; the
212
+ * default `@graphorin/store-sqlite` implementation persists it into
213
+ * the `fact_conflicts` table introduced by Phase 10b.
214
+ *
215
+ * @stable
216
+ */
217
+ interface ConflictAuditInputLike {
218
+ readonly scope: SessionScope$1;
219
+ readonly candidateId: string;
220
+ readonly existingId?: string;
221
+ readonly decision: ConflictAuditDecision;
222
+ readonly stage: ConflictAuditStage;
223
+ readonly detectionZone?: string;
224
+ readonly similarity?: number;
225
+ readonly reason?: string;
226
+ readonly detectedBy?: string;
227
+ }
228
+ /**
229
+ * Pending-queue payload — Stage 5 (defer-to-deep) hands the row over
230
+ * to the deep-phase LLM judge (Phase 10c).
231
+ *
232
+ * @stable
233
+ */
234
+ interface PendingConflictInputLike {
235
+ readonly scope: SessionScope$1;
236
+ readonly factId: string;
237
+ readonly candidateText: string;
238
+ readonly stage: ConflictAuditStage;
239
+ readonly reason?: string;
240
+ /** Top-K conflicting existing fact ids surfaced by Stage 2. */
241
+ readonly conflictingIds?: ReadonlyArray<string>;
242
+ }
243
+ /**
244
+ * Read-back shape returned by `listPending(...)`.
245
+ *
246
+ * @stable
247
+ */
248
+ interface PendingConflictRowLike {
249
+ readonly id: number;
250
+ readonly scopeUserId: string;
251
+ readonly factId: string;
252
+ readonly candidateText: string;
253
+ readonly stage: string;
254
+ readonly reason: string | null;
255
+ readonly enqueuedAt: number;
256
+ readonly attemptedAt: number | null;
257
+ readonly resolvedAt: number | null;
258
+ readonly decision: string | null;
259
+ /** Top-K conflicting existing fact ids; empty when omitted at enqueue. */
260
+ readonly conflictingIds: ReadonlyArray<string>;
261
+ }
262
+ /**
263
+ * Optional storage extension surfacing the audit + pending queue
264
+ * tables Phase 10b owns. Adapters that opt out leave the property
265
+ * undefined; the conflict pipeline degrades gracefully (no audit, no
266
+ * deferred queue, but every other stage still functions).
267
+ *
268
+ * @stable
269
+ */
270
+ interface ConflictMemoryStoreExt {
271
+ recordDecision(input: ConflictAuditInputLike): Promise<{
272
+ readonly id: number;
273
+ readonly detectedAt: number;
274
+ }>;
275
+ enqueuePending(input: PendingConflictInputLike): Promise<{
276
+ readonly id: number;
277
+ }>;
278
+ listPending(scope: SessionScope$1, limit?: number): Promise<ReadonlyArray<PendingConflictRowLike>>;
279
+ markResolved(id: number, decision: ConflictAuditDecision): Promise<void>;
280
+ /**
281
+ * Stamp `attemptedAt` on a pending row whose judge call failed
282
+ * (MCON-9). The deep phase closes the row as `'judge-unparseable'`
283
+ * on the NEXT failure, so a poisoned row is billed at most twice.
284
+ * Optional — without it the deep phase falls back to skip-and-retry.
285
+ */
286
+ markAttempted?(id: number, attemptedAt?: number): Promise<void>;
287
+ }
288
+ /**
289
+ * Persisted per-scope consolidator state row mirrored byte-for-byte
290
+ * by `@graphorin/store-sqlite`'s `consolidator_state` table. The lock
291
+ * fields (`activeLockHeldBy` / `activeLockAcquiredAt`) are populated
292
+ * while a phase is running and cleared when it finishes; the cursor
293
+ * fields advance as the standard phase processes a batch of
294
+ * messages.
295
+ *
296
+ * @stable
297
+ */
298
+ interface ConsolidatorStateRow {
299
+ readonly scope: SessionScope$1;
300
+ readonly lastProcessedMessageId: string | null;
301
+ readonly lastPhase: 'light' | 'standard' | 'deep' | null;
302
+ readonly lastCompletedAt: number | null;
303
+ readonly nextEligibleAt: number | null;
304
+ readonly activeLockHeldBy: string | null;
305
+ readonly activeLockAcquiredAt: number | null;
306
+ /**
307
+ * `ended_at` (epoch ms) of the newest episode the deep-phase reflection
308
+ * pass has already reflected on (MCON-13). A later pass accumulates
309
+ * importance only from strictly-newer episodes; `null` ⇒ nothing reflected
310
+ * yet.
311
+ */
312
+ readonly reflectionWatermark: number | null;
313
+ }
314
+ /**
315
+ * Patch shape accepted by
316
+ * {@link ConsolidatorMemoryStoreExt.upsertState}. Every field is
317
+ * optional so callers may advance the cursor and the run stamp
318
+ * independently. `null` clears a column; `undefined` leaves it
319
+ * untouched.
320
+ *
321
+ * @stable
322
+ */
323
+ interface ConsolidatorStatePatch {
324
+ readonly lastProcessedMessageId?: string | null;
325
+ readonly lastPhase?: 'light' | 'standard' | 'deep' | null;
326
+ readonly lastCompletedAt?: number | null;
327
+ readonly nextEligibleAt?: number | null;
328
+ readonly activeLockHeldBy?: string | null;
329
+ readonly activeLockAcquiredAt?: number | null;
330
+ readonly reflectionWatermark?: number | null;
331
+ }
332
+ /**
333
+ * Phase invocation audit row written to `consolidator_runs`. The
334
+ * accompanying `id` is generated by the caller so a partial / failed
335
+ * run can be reconciled by replay.
336
+ *
337
+ * @stable
338
+ */
339
+ interface ConsolidatorRunInput {
340
+ readonly id: string;
341
+ readonly scope: SessionScope$1;
342
+ readonly triggerKind: 'turn' | 'idle' | 'cron' | 'event' | 'budget' | 'manual';
343
+ readonly phase: 'light' | 'standard' | 'deep';
344
+ readonly startedAt: number;
345
+ }
346
+ /** @stable */
347
+ interface ConsolidatorRunFinish {
348
+ readonly id: string;
349
+ readonly finishedAt: number;
350
+ readonly status: 'completed' | 'failed' | 'deferred' | 'partial';
351
+ readonly llmTokensUsed?: number;
352
+ readonly llmCostUsd?: number | null;
353
+ readonly factsCreated?: number;
354
+ readonly factsUpdated?: number;
355
+ readonly conflictsResolved?: number;
356
+ readonly noiseFilteredCount?: number;
357
+ readonly emptyExtractions?: number;
358
+ /** Episodes auto-formed by the run (P1-2 / MCON-17). */
359
+ readonly episodesFormed?: number;
360
+ /** Insights synthesized by the run's reflection pass (P1-1 / MCON-17). */
361
+ readonly insightsCreated?: number;
362
+ readonly errorMessage?: string | null;
363
+ readonly retryCount?: number;
364
+ }
365
+ /** @stable */
366
+ interface DlqBatchInput {
367
+ readonly id: string;
368
+ readonly consolidatorRunId: string | null;
369
+ readonly scope: SessionScope$1;
370
+ readonly messageIds: ReadonlyArray<string>;
371
+ readonly errorKind: string;
372
+ readonly errorMessage: string;
373
+ readonly failedAt: number;
374
+ readonly nextRetryAt: number;
375
+ readonly retryCount: number;
376
+ /**
377
+ * Phase that failed (MCON-10) so `drainDlq` replays the SAME phase
378
+ * instead of inferring (the old inference hard-coded `'standard'`).
379
+ * Absent / `null` ⇒ legacy row, replayed as `'standard'`.
380
+ */
381
+ readonly phase?: 'light' | 'standard' | 'deep' | null;
382
+ }
383
+ /** @stable */
384
+ interface DlqBatchRow {
385
+ readonly id: string;
386
+ readonly consolidatorRunId: string | null;
387
+ readonly scope: SessionScope$1;
388
+ readonly messageIds: ReadonlyArray<string>;
389
+ readonly errorKind: string;
390
+ readonly errorMessage: string;
391
+ readonly failedAt: number;
392
+ readonly nextRetryAt: number | null;
393
+ readonly retryCount: number;
394
+ /** Phase that failed (MCON-10); `null`/absent ⇒ legacy row. */
395
+ readonly phase?: 'light' | 'standard' | 'deep' | null;
396
+ }
397
+ /**
398
+ * Optional consolidator-state surface every storage adapter exposes
399
+ * for Phase 10c. Mirrors the `consolidator_state`,
400
+ * `consolidator_runs`, and `consolidator_failed_batches` tables
401
+ * shipped in Phase 05's migration 009. Adapters that do not
402
+ * implement the surface degrade gracefully — the consolidator runs
403
+ * in stateless mode (no DLQ, no cursor persistence) and emits a
404
+ * one-shot WARN.
405
+ *
406
+ * @stable
407
+ */
408
+ interface ConsolidatorMemoryStoreExt {
409
+ getState(scope: SessionScope$1): Promise<ConsolidatorStateRow | null>;
410
+ upsertState(scope: SessionScope$1, patch: ConsolidatorStatePatch): Promise<ConsolidatorStateRow>;
411
+ /**
412
+ * Atomically claim the per-scope lock. Returns `true` when the
413
+ * row was either unlocked, owned by `runId`, or stale (the held
414
+ * timestamp is older than `maxAgeMs`); `false` otherwise. The
415
+ * `now` argument allows the lock manager to inject a deterministic
416
+ * clock during tests.
417
+ */
418
+ acquireLock(scope: SessionScope$1, runId: string, now: number, maxAgeMs: number): Promise<boolean>;
419
+ releaseLock(scope: SessionScope$1, runId: string): Promise<void>;
420
+ recordRunStart(input: ConsolidatorRunInput): Promise<void>;
421
+ recordRunFinish(finish: ConsolidatorRunFinish): Promise<void>;
422
+ listRecentRuns(scope: SessionScope$1, limit?: number): Promise<ReadonlyArray<{
423
+ readonly id: string;
424
+ readonly phase: 'light' | 'standard' | 'deep';
425
+ readonly status: string;
426
+ readonly startedAt: number;
427
+ readonly finishedAt: number | null;
428
+ readonly llmCostUsd: number | null;
429
+ readonly llmTokensUsed: number;
430
+ readonly factsCreated: number;
431
+ readonly factsUpdated: number;
432
+ }>>;
433
+ enqueueFailedBatch(input: DlqBatchInput): Promise<void>;
434
+ /**
435
+ * Claim every DLQ row whose `nextRetryAt` is at or before `now`,
436
+ * up to `limit`. Returns the rows in failed-at order so the
437
+ * oldest backlog drains first.
438
+ */
439
+ claimReadyBatches(scope: SessionScope$1, now: number, limit?: number): Promise<ReadonlyArray<DlqBatchRow>>;
440
+ /** Mark the row succeeded — removes it from the DLQ. */
441
+ markBatchSucceeded(id: string): Promise<void>;
442
+ /**
443
+ * Schedule the next retry attempt. The caller computes
444
+ * `nextRetryAt` so the backoff schedule is centralized in the
445
+ * consolidator.
446
+ */
447
+ rescheduleBatch(id: string, retryCount: number, nextRetryAt: number): Promise<void>;
448
+ /**
449
+ * Mark the row exhausted (`retryCount` exceeded the configured
450
+ * cap). The row stays in the DLQ for operator inspection.
451
+ * Implementations MUST clear `nextRetryAt` so the row is no
452
+ * longer eligible for `claimReadyBatches`. The optional
453
+ * `retryCount` argument is recorded against the row so the
454
+ * persisted count reflects the final attempt that triggered the
455
+ * exhaustion.
456
+ */
457
+ markBatchExhausted(id: string, errorMessage: string, retryCount?: number): Promise<void>;
458
+ listFailedBatches(scope: SessionScope$1, limit?: number): Promise<ReadonlyArray<DlqBatchRow>>;
459
+ }
460
+ /**
461
+ * Decay-aware extension of the typed `SemanticMemoryStore`. Phase
462
+ * 10c's light phase reads the strength + last-accessed columns and
463
+ * archives facts whose retention curve falls below the configured
464
+ * threshold. Adapters that do not maintain decay columns may omit
465
+ * the surface entirely — the light phase skips the archive step
466
+ * with an INFO log.
467
+ *
468
+ * @stable
469
+ */
470
+ interface DecayMemoryStoreExt {
471
+ /**
472
+ * List facts for the scope ordered by `lastAccessedAt` ASC so the
473
+ * caller can apply Ebbinghaus retention without scanning the
474
+ * whole table. `limit` defaults to `1000`.
475
+ *
476
+ * Archived rows are EXCLUDED by default (MCON-6) — they never receive
477
+ * access bumps, so they would pin the LRU head and saturate the decay
478
+ * window, structurally stopping threshold-archiving and capacity
479
+ * eviction for live facts. Inspection paths pass
480
+ * `{ includeArchived: true }`.
481
+ *
482
+ * `importance` / `status` / `provenance` (X-1) feed the multi-signal
483
+ * salience score that orders capacity-bounded eviction.
484
+ */
485
+ listForDecay(scope: SessionScope$1, limit?: number, opts?: {
486
+ readonly includeArchived?: boolean;
487
+ }): Promise<ReadonlyArray<{
488
+ readonly id: string;
489
+ readonly text: string;
490
+ readonly strength: number;
491
+ readonly lastAccessedAt: number | null;
492
+ readonly createdAt: number;
493
+ readonly archived: boolean;
494
+ /** Importance hint in `[0, 1]`; `null` when unscored (X-1). */
495
+ readonly importance: number | null;
496
+ /** Retrieval-trust state (P1-4): `'active'` | `'quarantined'`. */
497
+ readonly status: string;
498
+ /** Trust-provenance tag (P1-4); `null` for first-party rows. */
499
+ readonly provenance: string | null;
500
+ }>>;
501
+ /**
502
+ * Soft-archive a fact (sets `archived = 1`). The audit row in
503
+ * `memory_history` records the archive event.
504
+ */
505
+ archiveFact(id: string, reason?: string): Promise<void>;
506
+ /**
507
+ * Record a retrieval access for the given facts (MRET-7): stamp
508
+ * `lastAccessedAt` and reinforce `strength` (implementation-capped).
509
+ * Optional — adapters without decay columns may omit it; callers
510
+ * MUST treat failures as non-fatal (the read path never breaks on a
511
+ * bookkeeping write).
512
+ */
513
+ markAccessed?(ids: ReadonlyArray<string>, accessedAt?: number): Promise<void>;
514
+ /**
515
+ * Narrow decay-column read for exactly the given fact ids (MRET-8) —
516
+ * powers per-search decay re-ranking without the old O(scope)
517
+ * 1000-row window read. Optional; absent ⇒ the tier falls back to
518
+ * `listForDecay`.
519
+ */
520
+ listDecaySignals?(ids: ReadonlyArray<string>): Promise<ReadonlyArray<{
521
+ readonly id: string;
522
+ readonly strength: number;
523
+ readonly lastAccessedAt: number | null;
524
+ readonly createdAt: number;
525
+ }>>;
526
+ }
527
+ /** Options accepted by {@link InsightMemoryStoreExt.list}. */
528
+ interface InsightListOptions {
529
+ readonly limit?: number;
530
+ /** Include quarantined insights (validation / inspector path). */
531
+ readonly includeQuarantined?: boolean;
532
+ }
533
+ /** Options accepted by {@link InsightMemoryStoreExt.search}. */
534
+ interface InsightSearchStoreOptions {
535
+ readonly topK?: number;
536
+ /** Include quarantined insights (validation / inspector path). */
537
+ readonly includeQuarantined?: boolean;
538
+ }
539
+ /**
540
+ * Optional storage extension for the reflection `insights` table
541
+ * (P1-1). The consolidator's reflection pass inserts quarantined,
542
+ * cited insights here; the thin `InsightMemory` read surface lists /
543
+ * searches them; the ExpeL salience loop bumps + prunes them. Search is
544
+ * FTS-only by design — insights are a soft, rank-capped inspector
545
+ * surface, not primary recall.
546
+ *
547
+ * Adapters that opt out leave the property undefined; reflection then
548
+ * degrades to a no-op (it never writes) and `InsightMemory`
549
+ * search/list return empty. The default `@graphorin/store-sqlite`
550
+ * adapter implements it.
551
+ *
552
+ * @stable
553
+ */
554
+ interface InsightMemoryStoreExt {
555
+ /** Persist a synthesized insight (idempotent on `id`). */
556
+ insert(insight: Insight$1): Promise<void>;
557
+ /** Most-recent insights for the scope (newest first). */
558
+ list(scope: SessionScope$1, opts?: InsightListOptions): Promise<ReadonlyArray<Insight$1>>;
559
+ /** FTS keyword search over insight text. */
560
+ search(scope: SessionScope$1, query: string, opts?: InsightSearchStoreOptions): Promise<ReadonlyArray<MemoryHit<Insight$1>>>;
561
+ /** Lookup a single insight by id (`null` when absent / pruned). */
562
+ get?(id: string): Promise<Insight$1 | null>;
563
+ /**
564
+ * Set an insight's retrieval-trust `status` (MCON-2) — promote a quarantined
565
+ * (reflection) insight or re-quarantine an active one, with a
566
+ * `memory_history` audit row. Powers {@link InsightMemory.validate}.
567
+ */
568
+ setStatus?(id: string, status: MemoryStatus, reason?: string): Promise<void>;
569
+ /**
570
+ * Adjust an insight's ExpeL salience by `delta`, clamped at 0. The
571
+ * floor is the value at which {@link prune} removes it.
572
+ */
573
+ bumpSalience(id: string, delta: number, reason?: string): Promise<void>;
574
+ /**
575
+ * Soft-delete every salience-0 insight for the scope (the ExpeL
576
+ * forgetting step). Returns the number pruned. Tombstone only —
577
+ * pruned insights stay auditable.
578
+ */
579
+ prune(scope: SessionScope$1): Promise<number>;
580
+ }
581
+ /**
582
+ * Extension of the typed `ProceduralMemoryStore` with the optional
583
+ * promotion helper that storage adapters may expose (MCON-2).
584
+ *
585
+ * @stable
586
+ */
587
+ interface ProceduralMemoryStoreExt extends ProceduralMemoryStore {
588
+ /**
589
+ * Set a rule's retrieval-trust `status` — promote a quarantined (induced)
590
+ * procedure into `activate()` or re-quarantine an active one, with a
591
+ * `memory_history` audit row. Powers {@link ProceduralMemory.validate}.
592
+ */
593
+ setStatus?(id: string, status: MemoryStatus, reason?: string): Promise<void>;
594
+ /**
595
+ * Record one demonstrated successful reuse of a rule and return the
596
+ * new counter value (MCON-2 part 4). Powers
597
+ * promotion-by-demonstrated-success via
598
+ * {@link ProceduralMemory.recordOutcome}. Optional — adapters without
599
+ * the counter simply never auto-promote.
600
+ */
601
+ recordSuccess?(id: string): Promise<number>;
602
+ }
603
+ /** Find-or-create payload for {@link GraphMemoryStoreExt.upsertEntity}. */
604
+ interface EntityUpsertInput {
605
+ /** Display name as first observed. */
606
+ readonly name: string;
607
+ /** Folded key for lexical dedup + the canonical unique index. */
608
+ readonly normalizedName: string;
609
+ /** Optional name embedding (back-filled on a hit that lacked one). */
610
+ readonly vector?: Float32Array;
611
+ /** Embedder that produced {@link EntityUpsertInput.vector}. */
612
+ readonly embedderId?: string;
613
+ }
614
+ /**
615
+ * A canonical {@link GraphEntity} returned with its name embedding so the
616
+ * resolver can run cosine dedup in-process (entity counts are small).
617
+ */
618
+ interface EntityWithEmbedding extends GraphEntity {
619
+ readonly vector: Float32Array | null;
620
+ readonly embedderId: string | null;
621
+ }
622
+ /** One row of the append-only merge / unmerge audit ledger (P2-1). */
623
+ interface EntityMergeRecord {
624
+ readonly id: string;
625
+ readonly userId: string;
626
+ readonly kind: 'merge' | 'unmerge';
627
+ readonly fromEntityId: string;
628
+ readonly intoEntityId: string | null;
629
+ readonly reason?: string;
630
+ readonly createdAt: string;
631
+ }
632
+ /** Options for {@link GraphMemoryStoreExt.expandOneHop}. */
633
+ interface ExpandHopsStoreOptions {
634
+ /** Traversal depth (default `1`). */
635
+ readonly maxHops?: number;
636
+ /** Max neighbours to return (default `60`). */
637
+ readonly limit?: number;
638
+ /** Include quarantined neighbours (validation / inspector path). */
639
+ readonly includeQuarantined?: boolean;
640
+ /** Point-in-time filter, ISO-8601 (same semantics as fact search). */
641
+ readonly asOf?: string;
642
+ }
643
+ /**
644
+ * Optional storage extension for the lightweight in-SQLite relation
645
+ * graph (P2-1). Owns the canonical `entities` table, the `fact_entities`
646
+ * mapping, and the append-only `entity_merges` ledger. The entity
647
+ * *resolution policy* (lexical + embedding dedup, optional LLM
648
+ * adjudication) lives in `@graphorin/memory`; this surface is the pure
649
+ * persistence + the recursive-CTE traversal.
650
+ *
651
+ * Adapters that opt out leave the property undefined; entity resolution
652
+ * on write degrades to a no-op and `search({ expandHops })` skips
653
+ * expansion. The default `@graphorin/store-sqlite` adapter implements it.
654
+ *
655
+ * @stable
656
+ */
657
+ interface GraphMemoryStoreExt {
658
+ /** Find-or-create the canonical (root) entity for the normalized name. */
659
+ upsertEntity(scope: SessionScope$1, input: EntityUpsertInput): Promise<string>;
660
+ /** Link a fact's subject / object to a canonical entity (idempotent). */
661
+ linkFactEntity(factId: string, entityId: string, role: EntityRole): Promise<void>;
662
+ /** Candidate entities for the resolver (roots only unless `includeMerged`). */
663
+ listEntities(scope: SessionScope$1, opts?: {
664
+ readonly includeMerged?: boolean;
665
+ readonly limit?: number;
666
+ }): Promise<ReadonlyArray<EntityWithEmbedding>>;
667
+ /**
668
+ * Uncapped indexed lookup of the canonical root for an exact normalized
669
+ * name. Lets the resolver dedup an exact alias of an arbitrarily-old
670
+ * entity without scanning (and deserializing) the bounded
671
+ * {@link listEntities} candidate window (CS-11). Optional: stores without
672
+ * it fall back to the capped lexical scan inside `resolveEntityDecision`.
673
+ */
674
+ findEntityByNormalizedName?(scope: SessionScope$1, normalizedName: string): Promise<EntityWithEmbedding | null>;
675
+ /** Lookup one entity by id (any merge state). */
676
+ getEntity(scope: SessionScope$1, id: string): Promise<GraphEntity | null>;
677
+ /** Follow `mergedInto` to the canonical root id. */
678
+ resolveCanonical(scope: SessionScope$1, id: string): Promise<string>;
679
+ /** Merge `fromId` into `intoId`'s root; auditable + reversible. */
680
+ mergeEntities(scope: SessionScope$1, fromId: string, intoId: string, reason?: string): Promise<void>;
681
+ /** Reverse a merge: make `id` a root again + record an audit row. */
682
+ unmergeEntity(scope: SessionScope$1, id: string, reason?: string): Promise<void>;
683
+ /** The append-only merge / unmerge ledger, newest first. */
684
+ listMerges(scope: SessionScope$1, opts?: {
685
+ readonly limit?: number;
686
+ }): Promise<ReadonlyArray<EntityMergeRecord>>;
687
+ /** Expand seed facts to neighbours sharing a canonical entity (one-hop CTE). */
688
+ expandOneHop(scope: SessionScope$1, seedFactIds: ReadonlyArray<string>, opts?: ExpandHopsStoreOptions): Promise<ReadonlyArray<Fact$1>>;
689
+ }
690
+ /**
691
+ * Composite shape every `@graphorin/memory` consumer must supply at
692
+ * construction time. Mirrors the typed `MemoryStore` from
693
+ * `@graphorin/core` but widens the per-tier sub-store types with the
694
+ * optional embedding-aware extension methods.
695
+ *
696
+ * Concrete adapters (most notably `@graphorin/store-sqlite`)
697
+ * implement every member by construction; in-memory test doubles
698
+ * implement the minimum and leave the optional members undefined.
699
+ *
700
+ * @stable
701
+ */
702
+ interface MemoryStoreAdapter extends Omit<MemoryStore, 'session' | 'episodic' | 'semantic' | 'procedural'> {
703
+ readonly session: SessionMemoryStoreExt;
704
+ readonly episodic: EpisodicMemoryStoreExt;
705
+ readonly semantic: SemanticMemoryStoreExt & Partial<DecayMemoryStoreExt>;
706
+ readonly procedural: ProceduralMemoryStoreExt;
707
+ /**
708
+ * Optional conflict audit + pending queue surface. Defined on the
709
+ * default `@graphorin/store-sqlite` adapter, omitted on the
710
+ * minimal in-memory test doubles.
711
+ *
712
+ * @stable
713
+ */
714
+ readonly conflicts?: ConflictMemoryStoreExt;
715
+ /**
716
+ * Optional consolidator state + runs + DLQ surface. Defined on
717
+ * the default `@graphorin/store-sqlite` adapter; in-memory test
718
+ * doubles may opt in via the fixture.
719
+ *
720
+ * @stable
721
+ */
722
+ readonly consolidator?: ConsolidatorMemoryStoreExt;
723
+ /**
724
+ * Optional reflection insight surface (P1-1). Defined on the default
725
+ * `@graphorin/store-sqlite` adapter; omitted ⇒ reflection is a no-op
726
+ * and `InsightMemory` reads return empty.
727
+ *
728
+ * @stable
729
+ */
730
+ readonly insights?: InsightMemoryStoreExt;
731
+ /**
732
+ * Optional relation-graph surface (P2-1). Defined on the default
733
+ * `@graphorin/store-sqlite` adapter; omitted ⇒ entity resolution on
734
+ * write is a no-op and `search({ expandHops })` skips expansion.
735
+ *
736
+ * @stable
737
+ */
738
+ readonly graph?: GraphMemoryStoreExt;
739
+ }
740
+ //#endregion
741
+ export { ConflictAuditDecision, ConflictAuditInputLike, ConflictAuditStage, ConflictMemoryStoreExt, ConsolidatorMemoryStoreExt, ConsolidatorRunFinish, ConsolidatorRunInput, ConsolidatorStatePatch, ConsolidatorStateRow, DecayMemoryStoreExt, DlqBatchInput, DlqBatchRow, EmbeddedWriteOptions, EmbeddingMetaRegistryLike, EpisodicMemoryStoreExt, GraphMemoryStoreExt, InsightListOptions, InsightMemoryStoreExt, InsightSearchStoreOptions, MemoryStoreAdapter, PendingConflictInputLike, PendingConflictRowLike, SemanticMemoryStoreExt, SessionMemoryStoreExt, SessionMessageRecord };
742
+ //# sourceMappingURL=storage-adapter.d.ts.map