@fgv/ts-agent-memory 5.1.0-46 → 5.1.0-48

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 (336) hide show
  1. package/README.md +55 -0
  2. package/dist/packlets/ingest/orchestrator.js +115 -20
  3. package/dist/packlets/ingest/orchestrator.js.map +1 -1
  4. package/dist/packlets/observe/memoryObservationStore.js +6 -0
  5. package/dist/packlets/observe/memoryObservationStore.js.map +1 -1
  6. package/dist/packlets/observe/observer.js.map +1 -1
  7. package/dist/packlets/store/fileTreeMemoryStore.js +63 -135
  8. package/dist/packlets/store/fileTreeMemoryStore.js.map +1 -1
  9. package/dist/packlets/store/vectorMaintenance.js +251 -0
  10. package/dist/packlets/store/vectorMaintenance.js.map +1 -0
  11. package/dist/packlets/vector/inMemoryCosineIndex.js +81 -18
  12. package/dist/packlets/vector/inMemoryCosineIndex.js.map +1 -1
  13. package/dist/packlets/vector/inMemoryFragmentCosineIndex.js +7 -0
  14. package/dist/packlets/vector/inMemoryFragmentCosineIndex.js.map +1 -1
  15. package/dist/packlets/vector/vectorIndex.js.map +1 -1
  16. package/dist/ts-agent-memory.d.ts +389 -71
  17. package/lib/packlets/ingest/orchestrator.d.ts +62 -5
  18. package/lib/packlets/ingest/orchestrator.d.ts.map +1 -1
  19. package/lib/packlets/ingest/orchestrator.js +115 -20
  20. package/lib/packlets/ingest/orchestrator.js.map +1 -1
  21. package/lib/packlets/observe/memoryObservationStore.d.ts.map +1 -1
  22. package/lib/packlets/observe/memoryObservationStore.js +6 -0
  23. package/lib/packlets/observe/memoryObservationStore.js.map +1 -1
  24. package/lib/packlets/observe/observer.d.ts +61 -0
  25. package/lib/packlets/observe/observer.d.ts.map +1 -1
  26. package/lib/packlets/observe/observer.js.map +1 -1
  27. package/lib/packlets/store/fileTreeMemoryStore.d.ts +97 -60
  28. package/lib/packlets/store/fileTreeMemoryStore.d.ts.map +1 -1
  29. package/lib/packlets/store/fileTreeMemoryStore.js +63 -135
  30. package/lib/packlets/store/fileTreeMemoryStore.js.map +1 -1
  31. package/lib/packlets/store/vectorMaintenance.d.ts +149 -0
  32. package/lib/packlets/store/vectorMaintenance.d.ts.map +1 -0
  33. package/lib/packlets/store/vectorMaintenance.js +255 -0
  34. package/lib/packlets/store/vectorMaintenance.js.map +1 -0
  35. package/lib/packlets/vector/inMemoryCosineIndex.d.ts +30 -7
  36. package/lib/packlets/vector/inMemoryCosineIndex.d.ts.map +1 -1
  37. package/lib/packlets/vector/inMemoryCosineIndex.js +80 -17
  38. package/lib/packlets/vector/inMemoryCosineIndex.js.map +1 -1
  39. package/lib/packlets/vector/inMemoryFragmentCosineIndex.d.ts +7 -0
  40. package/lib/packlets/vector/inMemoryFragmentCosineIndex.d.ts.map +1 -1
  41. package/lib/packlets/vector/inMemoryFragmentCosineIndex.js +7 -0
  42. package/lib/packlets/vector/inMemoryFragmentCosineIndex.js.map +1 -1
  43. package/lib/packlets/vector/vectorIndex.d.ts +129 -1
  44. package/lib/packlets/vector/vectorIndex.d.ts.map +1 -1
  45. package/lib/packlets/vector/vectorIndex.js.map +1 -1
  46. package/package.json +17 -7
  47. package/.rush/temp/6e1299d1cebb080772163a532c221cd181b54f9f.tar.log +0 -462
  48. package/.rush/temp/chunked-rush-logs/ts-agent-memory.build.chunks.jsonl +0 -9
  49. package/.rush/temp/operation/build/all.log +0 -9
  50. package/.rush/temp/operation/build/log-chunks.jsonl +0 -9
  51. package/.rush/temp/operation/build/state.json +0 -3
  52. package/.rush/temp/shrinkwrap-deps.json +0 -689
  53. package/config/api-extractor.json +0 -343
  54. package/config/jest.config.json +0 -14
  55. package/config/rig.json +0 -4
  56. package/dist/test/unit/converters/antagonistRoundTrip.test.js +0 -95
  57. package/dist/test/unit/converters/antagonistRoundTrip.test.js.map +0 -1
  58. package/dist/test/unit/converters/bodyConverterRegistry.test.js +0 -72
  59. package/dist/test/unit/converters/bodyConverterRegistry.test.js.map +0 -1
  60. package/dist/test/unit/converters/envelopeConverter.test.js +0 -313
  61. package/dist/test/unit/converters/envelopeConverter.test.js.map +0 -1
  62. package/dist/test/unit/index/memoryIndex.test.js +0 -214
  63. package/dist/test/unit/index/memoryIndex.test.js.map +0 -1
  64. package/dist/test/unit/ingest/antagonistCycleAndParity.test.js +0 -277
  65. package/dist/test/unit/ingest/antagonistCycleAndParity.test.js.map +0 -1
  66. package/dist/test/unit/ingest/cycleGuard.test.js +0 -81
  67. package/dist/test/unit/ingest/cycleGuard.test.js.map +0 -1
  68. package/dist/test/unit/ingest/orchestrator.test.js +0 -1055
  69. package/dist/test/unit/ingest/orchestrator.test.js.map +0 -1
  70. package/dist/test/unit/observe/memoryObservationStore.test.js +0 -118
  71. package/dist/test/unit/observe/memoryObservationStore.test.js.map +0 -1
  72. package/dist/test/unit/retrieve/fragmentSemanticRetriever.test.js +0 -116
  73. package/dist/test/unit/retrieve/fragmentSemanticRetriever.test.js.map +0 -1
  74. package/dist/test/unit/retrieve/linkTraversalRetriever.test.js +0 -257
  75. package/dist/test/unit/retrieve/linkTraversalRetriever.test.js.map +0 -1
  76. package/dist/test/unit/retrieve/retrievers.test.js +0 -768
  77. package/dist/test/unit/retrieve/retrievers.test.js.map +0 -1
  78. package/dist/test/unit/retrieve/temporalRetrievers.test.js +0 -182
  79. package/dist/test/unit/retrieve/temporalRetrievers.test.js.map +0 -1
  80. package/dist/test/unit/store/antagonistTemporalBoundary.test.js +0 -120
  81. package/dist/test/unit/store/antagonistTemporalBoundary.test.js.map +0 -1
  82. package/dist/test/unit/store/embedOnWrite.test.js +0 -317
  83. package/dist/test/unit/store/embedOnWrite.test.js.map +0 -1
  84. package/dist/test/unit/store/fileTreeMemoryStore.test.js +0 -778
  85. package/dist/test/unit/store/fileTreeMemoryStore.test.js.map +0 -1
  86. package/dist/test/unit/store/fragmentEmbedOnWrite.test.js +0 -255
  87. package/dist/test/unit/store/fragmentEmbedOnWrite.test.js.map +0 -1
  88. package/dist/test/unit/store/indexInjection.test.js +0 -432
  89. package/dist/test/unit/store/indexInjection.test.js.map +0 -1
  90. package/dist/test/unit/store/lenientOpen.test.js +0 -248
  91. package/dist/test/unit/store/lenientOpen.test.js.map +0 -1
  92. package/dist/test/unit/store/listScoped.test.js +0 -109
  93. package/dist/test/unit/store/listScoped.test.js.map +0 -1
  94. package/dist/test/unit/store/observations.test.js +0 -239
  95. package/dist/test/unit/store/observations.test.js.map +0 -1
  96. package/dist/test/unit/store/rankAxis.test.js +0 -254
  97. package/dist/test/unit/store/rankAxis.test.js.map +0 -1
  98. package/dist/test/unit/store/scopeEncoding.test.js +0 -24
  99. package/dist/test/unit/store/scopeEncoding.test.js.map +0 -1
  100. package/dist/test/unit/store/temporalStore.test.js +0 -398
  101. package/dist/test/unit/store/temporalStore.test.js.map +0 -1
  102. package/dist/test/unit/tools/memoryTools.test.js +0 -841
  103. package/dist/test/unit/tools/memoryTools.test.js.map +0 -1
  104. package/dist/test/unit/types/identityCodec.test.js +0 -187
  105. package/dist/test/unit/types/identityCodec.test.js.map +0 -1
  106. package/dist/test/unit/types/ids.test.js +0 -84
  107. package/dist/test/unit/types/ids.test.js.map +0 -1
  108. package/dist/test/unit/types/temporalCodec.test.js +0 -203
  109. package/dist/test/unit/types/temporalCodec.test.js.map +0 -1
  110. package/dist/test/unit/types/temporalPolicy.test.js +0 -83
  111. package/dist/test/unit/types/temporalPolicy.test.js.map +0 -1
  112. package/dist/test/unit/types/writePolicy.test.js +0 -331
  113. package/dist/test/unit/types/writePolicy.test.js.map +0 -1
  114. package/dist/test/unit/vector/fragmentConverters.test.js +0 -58
  115. package/dist/test/unit/vector/fragmentConverters.test.js.map +0 -1
  116. package/dist/test/unit/vector/inMemoryCosineIndex.test.js +0 -252
  117. package/dist/test/unit/vector/inMemoryCosineIndex.test.js.map +0 -1
  118. package/dist/test/unit/vector/inMemoryFragmentCosineIndex.test.js +0 -362
  119. package/dist/test/unit/vector/inMemoryFragmentCosineIndex.test.js.map +0 -1
  120. package/dist/test/unit/vector/vectorIndex.test.js +0 -51
  121. package/dist/test/unit/vector/vectorIndex.test.js.map +0 -1
  122. package/eslint.config.js +0 -15
  123. package/etc/ts-agent-memory.api.md +0 -938
  124. package/lib/test/unit/converters/antagonistRoundTrip.test.d.ts +0 -10
  125. package/lib/test/unit/converters/antagonistRoundTrip.test.d.ts.map +0 -1
  126. package/lib/test/unit/converters/antagonistRoundTrip.test.js +0 -97
  127. package/lib/test/unit/converters/antagonistRoundTrip.test.js.map +0 -1
  128. package/lib/test/unit/converters/bodyConverterRegistry.test.d.ts +0 -2
  129. package/lib/test/unit/converters/bodyConverterRegistry.test.d.ts.map +0 -1
  130. package/lib/test/unit/converters/bodyConverterRegistry.test.js +0 -74
  131. package/lib/test/unit/converters/bodyConverterRegistry.test.js.map +0 -1
  132. package/lib/test/unit/converters/envelopeConverter.test.d.ts +0 -2
  133. package/lib/test/unit/converters/envelopeConverter.test.d.ts.map +0 -1
  134. package/lib/test/unit/converters/envelopeConverter.test.js +0 -315
  135. package/lib/test/unit/converters/envelopeConverter.test.js.map +0 -1
  136. package/lib/test/unit/index/memoryIndex.test.d.ts +0 -2
  137. package/lib/test/unit/index/memoryIndex.test.d.ts.map +0 -1
  138. package/lib/test/unit/index/memoryIndex.test.js +0 -216
  139. package/lib/test/unit/index/memoryIndex.test.js.map +0 -1
  140. package/lib/test/unit/ingest/antagonistCycleAndParity.test.d.ts +0 -9
  141. package/lib/test/unit/ingest/antagonistCycleAndParity.test.d.ts.map +0 -1
  142. package/lib/test/unit/ingest/antagonistCycleAndParity.test.js +0 -279
  143. package/lib/test/unit/ingest/antagonistCycleAndParity.test.js.map +0 -1
  144. package/lib/test/unit/ingest/cycleGuard.test.d.ts +0 -2
  145. package/lib/test/unit/ingest/cycleGuard.test.d.ts.map +0 -1
  146. package/lib/test/unit/ingest/cycleGuard.test.js +0 -83
  147. package/lib/test/unit/ingest/cycleGuard.test.js.map +0 -1
  148. package/lib/test/unit/ingest/orchestrator.test.d.ts +0 -2
  149. package/lib/test/unit/ingest/orchestrator.test.d.ts.map +0 -1
  150. package/lib/test/unit/ingest/orchestrator.test.js +0 -1057
  151. package/lib/test/unit/ingest/orchestrator.test.js.map +0 -1
  152. package/lib/test/unit/observe/memoryObservationStore.test.d.ts +0 -2
  153. package/lib/test/unit/observe/memoryObservationStore.test.d.ts.map +0 -1
  154. package/lib/test/unit/observe/memoryObservationStore.test.js +0 -120
  155. package/lib/test/unit/observe/memoryObservationStore.test.js.map +0 -1
  156. package/lib/test/unit/retrieve/fragmentSemanticRetriever.test.d.ts +0 -2
  157. package/lib/test/unit/retrieve/fragmentSemanticRetriever.test.d.ts.map +0 -1
  158. package/lib/test/unit/retrieve/fragmentSemanticRetriever.test.js +0 -118
  159. package/lib/test/unit/retrieve/fragmentSemanticRetriever.test.js.map +0 -1
  160. package/lib/test/unit/retrieve/linkTraversalRetriever.test.d.ts +0 -2
  161. package/lib/test/unit/retrieve/linkTraversalRetriever.test.d.ts.map +0 -1
  162. package/lib/test/unit/retrieve/linkTraversalRetriever.test.js +0 -259
  163. package/lib/test/unit/retrieve/linkTraversalRetriever.test.js.map +0 -1
  164. package/lib/test/unit/retrieve/retrievers.test.d.ts +0 -2
  165. package/lib/test/unit/retrieve/retrievers.test.d.ts.map +0 -1
  166. package/lib/test/unit/retrieve/retrievers.test.js +0 -770
  167. package/lib/test/unit/retrieve/retrievers.test.js.map +0 -1
  168. package/lib/test/unit/retrieve/temporalRetrievers.test.d.ts +0 -2
  169. package/lib/test/unit/retrieve/temporalRetrievers.test.d.ts.map +0 -1
  170. package/lib/test/unit/retrieve/temporalRetrievers.test.js +0 -184
  171. package/lib/test/unit/retrieve/temporalRetrievers.test.js.map +0 -1
  172. package/lib/test/unit/store/antagonistTemporalBoundary.test.d.ts +0 -9
  173. package/lib/test/unit/store/antagonistTemporalBoundary.test.d.ts.map +0 -1
  174. package/lib/test/unit/store/antagonistTemporalBoundary.test.js +0 -122
  175. package/lib/test/unit/store/antagonistTemporalBoundary.test.js.map +0 -1
  176. package/lib/test/unit/store/embedOnWrite.test.d.ts +0 -2
  177. package/lib/test/unit/store/embedOnWrite.test.d.ts.map +0 -1
  178. package/lib/test/unit/store/embedOnWrite.test.js +0 -319
  179. package/lib/test/unit/store/embedOnWrite.test.js.map +0 -1
  180. package/lib/test/unit/store/fileTreeMemoryStore.test.d.ts +0 -2
  181. package/lib/test/unit/store/fileTreeMemoryStore.test.d.ts.map +0 -1
  182. package/lib/test/unit/store/fileTreeMemoryStore.test.js +0 -780
  183. package/lib/test/unit/store/fileTreeMemoryStore.test.js.map +0 -1
  184. package/lib/test/unit/store/fragmentEmbedOnWrite.test.d.ts +0 -2
  185. package/lib/test/unit/store/fragmentEmbedOnWrite.test.d.ts.map +0 -1
  186. package/lib/test/unit/store/fragmentEmbedOnWrite.test.js +0 -257
  187. package/lib/test/unit/store/fragmentEmbedOnWrite.test.js.map +0 -1
  188. package/lib/test/unit/store/indexInjection.test.d.ts +0 -2
  189. package/lib/test/unit/store/indexInjection.test.d.ts.map +0 -1
  190. package/lib/test/unit/store/indexInjection.test.js +0 -434
  191. package/lib/test/unit/store/indexInjection.test.js.map +0 -1
  192. package/lib/test/unit/store/lenientOpen.test.d.ts +0 -2
  193. package/lib/test/unit/store/lenientOpen.test.d.ts.map +0 -1
  194. package/lib/test/unit/store/lenientOpen.test.js +0 -250
  195. package/lib/test/unit/store/lenientOpen.test.js.map +0 -1
  196. package/lib/test/unit/store/listScoped.test.d.ts +0 -2
  197. package/lib/test/unit/store/listScoped.test.d.ts.map +0 -1
  198. package/lib/test/unit/store/listScoped.test.js +0 -111
  199. package/lib/test/unit/store/listScoped.test.js.map +0 -1
  200. package/lib/test/unit/store/observations.test.d.ts +0 -2
  201. package/lib/test/unit/store/observations.test.d.ts.map +0 -1
  202. package/lib/test/unit/store/observations.test.js +0 -241
  203. package/lib/test/unit/store/observations.test.js.map +0 -1
  204. package/lib/test/unit/store/rankAxis.test.d.ts +0 -2
  205. package/lib/test/unit/store/rankAxis.test.d.ts.map +0 -1
  206. package/lib/test/unit/store/rankAxis.test.js +0 -256
  207. package/lib/test/unit/store/rankAxis.test.js.map +0 -1
  208. package/lib/test/unit/store/scopeEncoding.test.d.ts +0 -2
  209. package/lib/test/unit/store/scopeEncoding.test.d.ts.map +0 -1
  210. package/lib/test/unit/store/scopeEncoding.test.js +0 -26
  211. package/lib/test/unit/store/scopeEncoding.test.js.map +0 -1
  212. package/lib/test/unit/store/temporalStore.test.d.ts +0 -2
  213. package/lib/test/unit/store/temporalStore.test.d.ts.map +0 -1
  214. package/lib/test/unit/store/temporalStore.test.js +0 -400
  215. package/lib/test/unit/store/temporalStore.test.js.map +0 -1
  216. package/lib/test/unit/tools/memoryTools.test.d.ts +0 -2
  217. package/lib/test/unit/tools/memoryTools.test.d.ts.map +0 -1
  218. package/lib/test/unit/tools/memoryTools.test.js +0 -843
  219. package/lib/test/unit/tools/memoryTools.test.js.map +0 -1
  220. package/lib/test/unit/types/identityCodec.test.d.ts +0 -2
  221. package/lib/test/unit/types/identityCodec.test.d.ts.map +0 -1
  222. package/lib/test/unit/types/identityCodec.test.js +0 -189
  223. package/lib/test/unit/types/identityCodec.test.js.map +0 -1
  224. package/lib/test/unit/types/ids.test.d.ts +0 -2
  225. package/lib/test/unit/types/ids.test.d.ts.map +0 -1
  226. package/lib/test/unit/types/ids.test.js +0 -86
  227. package/lib/test/unit/types/ids.test.js.map +0 -1
  228. package/lib/test/unit/types/temporalCodec.test.d.ts +0 -2
  229. package/lib/test/unit/types/temporalCodec.test.d.ts.map +0 -1
  230. package/lib/test/unit/types/temporalCodec.test.js +0 -205
  231. package/lib/test/unit/types/temporalCodec.test.js.map +0 -1
  232. package/lib/test/unit/types/temporalPolicy.test.d.ts +0 -2
  233. package/lib/test/unit/types/temporalPolicy.test.d.ts.map +0 -1
  234. package/lib/test/unit/types/temporalPolicy.test.js +0 -85
  235. package/lib/test/unit/types/temporalPolicy.test.js.map +0 -1
  236. package/lib/test/unit/types/writePolicy.test.d.ts +0 -2
  237. package/lib/test/unit/types/writePolicy.test.d.ts.map +0 -1
  238. package/lib/test/unit/types/writePolicy.test.js +0 -333
  239. package/lib/test/unit/types/writePolicy.test.js.map +0 -1
  240. package/lib/test/unit/vector/fragmentConverters.test.d.ts +0 -2
  241. package/lib/test/unit/vector/fragmentConverters.test.d.ts.map +0 -1
  242. package/lib/test/unit/vector/fragmentConverters.test.js +0 -60
  243. package/lib/test/unit/vector/fragmentConverters.test.js.map +0 -1
  244. package/lib/test/unit/vector/inMemoryCosineIndex.test.d.ts +0 -2
  245. package/lib/test/unit/vector/inMemoryCosineIndex.test.d.ts.map +0 -1
  246. package/lib/test/unit/vector/inMemoryCosineIndex.test.js +0 -254
  247. package/lib/test/unit/vector/inMemoryCosineIndex.test.js.map +0 -1
  248. package/lib/test/unit/vector/inMemoryFragmentCosineIndex.test.d.ts +0 -2
  249. package/lib/test/unit/vector/inMemoryFragmentCosineIndex.test.d.ts.map +0 -1
  250. package/lib/test/unit/vector/inMemoryFragmentCosineIndex.test.js +0 -364
  251. package/lib/test/unit/vector/inMemoryFragmentCosineIndex.test.js.map +0 -1
  252. package/lib/test/unit/vector/vectorIndex.test.d.ts +0 -2
  253. package/lib/test/unit/vector/vectorIndex.test.d.ts.map +0 -1
  254. package/lib/test/unit/vector/vectorIndex.test.js +0 -53
  255. package/lib/test/unit/vector/vectorIndex.test.js.map +0 -1
  256. package/rush-logs/ts-agent-memory.build.cache.log +0 -3
  257. package/rush-logs/ts-agent-memory.build.log +0 -9
  258. package/src/index.ts +0 -14
  259. package/src/packlets/converters/bodyConverterRegistry.ts +0 -105
  260. package/src/packlets/converters/envelopeConverter.ts +0 -233
  261. package/src/packlets/converters/index.ts +0 -7
  262. package/src/packlets/index/index.ts +0 -6
  263. package/src/packlets/index/memoryIndex.ts +0 -332
  264. package/src/packlets/ingest/cycleGuard.ts +0 -153
  265. package/src/packlets/ingest/hostStages.ts +0 -111
  266. package/src/packlets/ingest/index.ts +0 -9
  267. package/src/packlets/ingest/model.ts +0 -195
  268. package/src/packlets/ingest/orchestrator.ts +0 -873
  269. package/src/packlets/observe/index.ts +0 -7
  270. package/src/packlets/observe/memoryObservationStore.ts +0 -153
  271. package/src/packlets/observe/observer.ts +0 -119
  272. package/src/packlets/retrieve/fragmentSemanticRetriever.ts +0 -138
  273. package/src/packlets/retrieve/hybridRetriever.ts +0 -194
  274. package/src/packlets/retrieve/index.ts +0 -14
  275. package/src/packlets/retrieve/linkTraversalRetriever.ts +0 -158
  276. package/src/packlets/retrieve/recencyRetriever.ts +0 -54
  277. package/src/packlets/retrieve/retriever.ts +0 -291
  278. package/src/packlets/retrieve/semanticRetriever.ts +0 -152
  279. package/src/packlets/retrieve/structuredFilterRetriever.ts +0 -58
  280. package/src/packlets/retrieve/tagRetriever.ts +0 -58
  281. package/src/packlets/retrieve/temporalRetrievers.ts +0 -210
  282. package/src/packlets/store/fileTreeMemoryStore.ts +0 -1834
  283. package/src/packlets/store/index.ts +0 -7
  284. package/src/packlets/store/scopeEncoding.ts +0 -36
  285. package/src/packlets/tools/index.ts +0 -6
  286. package/src/packlets/tools/memoryTools.ts +0 -706
  287. package/src/packlets/types/envelope.ts +0 -196
  288. package/src/packlets/types/filenameSafety.ts +0 -57
  289. package/src/packlets/types/identityCodec.ts +0 -447
  290. package/src/packlets/types/ids.ts +0 -124
  291. package/src/packlets/types/index.ts +0 -11
  292. package/src/packlets/types/temporal.ts +0 -96
  293. package/src/packlets/types/writePolicy.ts +0 -612
  294. package/src/packlets/vector/fragmentConverters.ts +0 -55
  295. package/src/packlets/vector/inMemoryCosineIndex.ts +0 -196
  296. package/src/packlets/vector/inMemoryFragmentCosineIndex.ts +0 -289
  297. package/src/packlets/vector/index.ts +0 -9
  298. package/src/packlets/vector/vectorIndex.ts +0 -273
  299. package/src/test/unit/converters/antagonistRoundTrip.test.ts +0 -110
  300. package/src/test/unit/converters/bodyConverterRegistry.test.ts +0 -89
  301. package/src/test/unit/converters/envelopeConverter.test.ts +0 -418
  302. package/src/test/unit/index/memoryIndex.test.ts +0 -272
  303. package/src/test/unit/ingest/antagonistCycleAndParity.test.ts +0 -367
  304. package/src/test/unit/ingest/cycleGuard.test.ts +0 -110
  305. package/src/test/unit/ingest/orchestrator.test.ts +0 -1351
  306. package/src/test/unit/observe/memoryObservationStore.test.ts +0 -158
  307. package/src/test/unit/retrieve/fragmentSemanticRetriever.test.ts +0 -163
  308. package/src/test/unit/retrieve/linkTraversalRetriever.test.ts +0 -329
  309. package/src/test/unit/retrieve/retrievers.test.ts +0 -1018
  310. package/src/test/unit/retrieve/temporalRetrievers.test.ts +0 -226
  311. package/src/test/unit/store/antagonistTemporalBoundary.test.ts +0 -158
  312. package/src/test/unit/store/embedOnWrite.test.ts +0 -418
  313. package/src/test/unit/store/fileTreeMemoryStore.test.ts +0 -1041
  314. package/src/test/unit/store/fragmentEmbedOnWrite.test.ts +0 -349
  315. package/src/test/unit/store/indexInjection.test.ts +0 -550
  316. package/src/test/unit/store/lenientOpen.test.ts +0 -292
  317. package/src/test/unit/store/listScoped.test.ts +0 -138
  318. package/src/test/unit/store/observations.test.ts +0 -290
  319. package/src/test/unit/store/rankAxis.test.ts +0 -349
  320. package/src/test/unit/store/scopeEncoding.test.ts +0 -37
  321. package/src/test/unit/store/temporalStore.test.ts +0 -469
  322. package/src/test/unit/tools/memoryTools.test.ts +0 -1120
  323. package/src/test/unit/types/identityCodec.test.ts +0 -266
  324. package/src/test/unit/types/ids.test.ts +0 -94
  325. package/src/test/unit/types/temporalCodec.test.ts +0 -259
  326. package/src/test/unit/types/temporalPolicy.test.ts +0 -124
  327. package/src/test/unit/types/writePolicy.test.ts +0 -446
  328. package/src/test/unit/vector/fragmentConverters.test.ts +0 -80
  329. package/src/test/unit/vector/inMemoryCosineIndex.test.ts +0 -318
  330. package/src/test/unit/vector/inMemoryFragmentCosineIndex.test.ts +0 -477
  331. package/src/test/unit/vector/vectorIndex.test.ts +0 -64
  332. package/temp/build/lint/_eslint-5eVG3S6w.json +0 -302
  333. package/temp/build/typescript/ts_8nwakTlr.json +0 -1
  334. package/temp/ts-agent-memory.api.json +0 -20933
  335. package/temp/ts-agent-memory.api.md +0 -938
  336. package/tsconfig.json +0 -8
@@ -1,550 +0,0 @@
1
- /*
2
- * Copyright (c) 2026 Erik Fortune
3
- * SPDX-License-Identifier: MIT
4
- */
5
-
6
- import '@fgv/ts-utils-jest';
7
- import { Converters, Result, succeed } from '@fgv/ts-utils';
8
- import { FileTree } from '@fgv/ts-json-base';
9
- import {
10
- BodyConverterRegistry,
11
- EntityId,
12
- FileTreeMemoryStore,
13
- IBodyConverterRegistry,
14
- IEdgeTarget,
15
- IIdentityCodec,
16
- IIndexedMemoryRecord,
17
- IMemoryIndex,
18
- IMemoryRecord,
19
- IWritePolicy,
20
- Kind,
21
- KnowledgeIdentityCodec,
22
- MemoryCapCullPolicy,
23
- MemoryId,
24
- MemoryIndex,
25
- MemoryIndexPatchOp,
26
- MemoryScopeKey,
27
- MtmIdentityCodec,
28
- RecencyRetriever,
29
- Tag,
30
- TemporalIdentityCodec,
31
- TemporalVersionedPolicy,
32
- envelopeConverter
33
- } from '../../../index';
34
-
35
- const knowledgeKind: Kind = 'knowledge' as Kind;
36
- const knowledgeScope: MemoryScopeKey = 'knowledge' as MemoryScopeKey;
37
-
38
- function mutableRoot(): FileTree.IMutableFileTreeDirectoryItem {
39
- const tree = FileTree.inMemory([], { mutable: true }).orThrow();
40
- const root = tree.getDirectory('/').orThrow();
41
- if (!FileTree.isMutableDirectoryItem(root)) {
42
- throw new Error('expected a mutable root directory');
43
- }
44
- return root;
45
- }
46
-
47
- function knowledgeRecord(id: string, body: string, tags: ReadonlyArray<string> = []): IMemoryRecord<unknown> {
48
- return {
49
- envelope: envelopeConverter
50
- .convert({
51
- id,
52
- entityId: id,
53
- kind: 'knowledge',
54
- tags: [...tags],
55
- links: [],
56
- created: 0,
57
- updated: 0,
58
- seq: 0,
59
- contentHash: '',
60
- provenance: { source: 'agent' }
61
- })
62
- .orThrow(),
63
- body
64
- };
65
- }
66
-
67
- function storeWith(index?: IMemoryIndex, root?: FileTree.IMutableFileTreeDirectoryItem): FileTreeMemoryStore {
68
- const registry: IBodyConverterRegistry = BodyConverterRegistry.create().orThrow();
69
- registry.register(knowledgeKind, Converters.string);
70
- return FileTreeMemoryStore.create({
71
- root: root ?? mutableRoot(),
72
- registry,
73
- codecs: new Map<Kind, IIdentityCodec>([[knowledgeKind, new KnowledgeIdentityCodec()]]),
74
- index
75
- }).orThrow();
76
- }
77
-
78
- /** One recorded {@link IMemoryIndex.patch} call. */
79
- interface IPatchCall {
80
- readonly op: MemoryIndexPatchOp;
81
- readonly scope: MemoryScopeKey;
82
- readonly id: string;
83
- }
84
-
85
- /**
86
- * A counting/timing decorator over the shipped `MemoryIndex` — the exact shape
87
- * the injection seam exists to enable. Every call is delegated verbatim, so a
88
- * store wired with one behaves identically to a store using the default index;
89
- * the recorded counts are the measurement the consumer is after.
90
- */
91
- class RecordingMemoryIndex implements IMemoryIndex {
92
- public readonly rebuildSizes: number[] = [];
93
- public readonly patchCalls: IPatchCall[] = [];
94
- public entriesCalls: number = 0;
95
-
96
- private readonly _inner: IMemoryIndex;
97
-
98
- private constructor(inner: IMemoryIndex) {
99
- this._inner = inner;
100
- }
101
-
102
- public static create(): Result<RecordingMemoryIndex> {
103
- return MemoryIndex.create().onSuccess((inner) => succeed(new RecordingMemoryIndex(inner)));
104
- }
105
-
106
- public rebuild(entries: ReadonlyArray<IIndexedMemoryRecord>): Result<number> {
107
- this.rebuildSizes.push(entries.length);
108
- return this._inner.rebuild(entries);
109
- }
110
-
111
- public patch(op: MemoryIndexPatchOp, entry: IIndexedMemoryRecord): Result<IIndexedMemoryRecord> {
112
- this.patchCalls.push({ op, scope: entry.scope, id: entry.record.envelope.id });
113
- return this._inner.patch(op, entry);
114
- }
115
-
116
- public entries(): ReadonlyArray<IIndexedMemoryRecord> {
117
- this.entriesCalls += 1;
118
- return this._inner.entries();
119
- }
120
-
121
- public byKind(kind: Kind): ReadonlyArray<IMemoryRecord<unknown>> {
122
- return this._inner.byKind(kind);
123
- }
124
-
125
- public byTag(tag: Tag): ReadonlyArray<IMemoryRecord<unknown>> {
126
- return this._inner.byTag(tag);
127
- }
128
-
129
- public byRecency(): ReadonlyArray<IMemoryRecord<unknown>> {
130
- return this._inner.byRecency();
131
- }
132
-
133
- public byRank(): ReadonlyArray<IMemoryRecord<unknown>> {
134
- return this._inner.byRank();
135
- }
136
-
137
- public backlinks(target: IEdgeTarget): ReadonlyArray<IEdgeTarget> {
138
- return this._inner.backlinks(target);
139
- }
140
- }
141
-
142
- /**
143
- * An index that hides every record whose body contains `hidden` from the
144
- * `entries()` read surface. Not a realistic index — it exists to prove the store
145
- * reads from the INJECTED index rather than one it built for itself. A store
146
- * with a private index could not produce these results.
147
- */
148
- class HidingMemoryIndex implements IMemoryIndex {
149
- private readonly _inner: IMemoryIndex;
150
-
151
- private constructor(inner: IMemoryIndex) {
152
- this._inner = inner;
153
- }
154
-
155
- public static create(): Result<HidingMemoryIndex> {
156
- return MemoryIndex.create().onSuccess((inner) => succeed(new HidingMemoryIndex(inner)));
157
- }
158
-
159
- public rebuild(entries: ReadonlyArray<IIndexedMemoryRecord>): Result<number> {
160
- return this._inner.rebuild(entries);
161
- }
162
-
163
- public patch(op: MemoryIndexPatchOp, entry: IIndexedMemoryRecord): Result<IIndexedMemoryRecord> {
164
- return this._inner.patch(op, entry);
165
- }
166
-
167
- public entries(): ReadonlyArray<IIndexedMemoryRecord> {
168
- return this._inner.entries().filter((e) => !String(e.record.body).includes('hidden'));
169
- }
170
-
171
- public byKind(kind: Kind): ReadonlyArray<IMemoryRecord<unknown>> {
172
- return this._inner.byKind(kind);
173
- }
174
-
175
- public byTag(tag: Tag): ReadonlyArray<IMemoryRecord<unknown>> {
176
- return this._inner.byTag(tag);
177
- }
178
-
179
- public byRecency(): ReadonlyArray<IMemoryRecord<unknown>> {
180
- return this._inner.byRecency();
181
- }
182
-
183
- public byRank(): ReadonlyArray<IMemoryRecord<unknown>> {
184
- return this._inner.byRank();
185
- }
186
-
187
- public backlinks(target: IEdgeTarget): ReadonlyArray<IEdgeTarget> {
188
- return this._inner.backlinks(target);
189
- }
190
- }
191
-
192
- // ---------------------------------------------------------------------------
193
- // Temporal (versioned) and cap-cull fixtures.
194
- //
195
- // The `index` param's TSDoc claims that an injected index decides which version a
196
- // versioned `put` supersedes, which versions a `delete` tombstones, and what a
197
- // cap-cull policy evicts — because all three derive their working set from
198
- // `entries()` rather than from the FileTree. These fixtures exist so those claims
199
- // are evidenced by test rather than only reasoned about from the implementation.
200
- // ---------------------------------------------------------------------------
201
-
202
- const factKind: Kind = 'fact' as Kind;
203
- const factScope: MemoryScopeKey = 'facts/entities/fact-1' as MemoryScopeKey;
204
- const mtmKind: Kind = 'mtm' as Kind;
205
-
206
- let clockValue: number = 1000;
207
- const clock = (): number => clockValue;
208
-
209
- function factRecord(body: string): IMemoryRecord<unknown> {
210
- return {
211
- envelope: envelopeConverter
212
- .convert({
213
- id: 'fact-1',
214
- entityId: 'fact-1',
215
- kind: 'fact',
216
- tags: [],
217
- links: [],
218
- created: 0,
219
- updated: 0,
220
- seq: 0,
221
- contentHash: '',
222
- provenance: { source: 'agent' }
223
- })
224
- .orThrow(),
225
- body
226
- };
227
- }
228
-
229
- function versionedStore(index?: IMemoryIndex): FileTreeMemoryStore {
230
- const registry: IBodyConverterRegistry = BodyConverterRegistry.create().orThrow();
231
- registry.register(factKind, Converters.string);
232
- return FileTreeMemoryStore.create({
233
- root: mutableRoot(),
234
- registry,
235
- codecs: new Map<Kind, IIdentityCodec>([[factKind, TemporalIdentityCodec.create('facts').orThrow()]]),
236
- writePolicies: new Map<Kind, IWritePolicy>([[factKind, TemporalVersionedPolicy.create().orThrow()]]),
237
- clock,
238
- index
239
- }).orThrow();
240
- }
241
-
242
- function turnRecord(turn: number, body: string): IMemoryRecord<unknown> {
243
- return {
244
- envelope: envelopeConverter
245
- .convert({
246
- id: `turn-${turn}`,
247
- entityId: `conv-1:${turn}`,
248
- kind: 'mtm',
249
- tags: [],
250
- links: [],
251
- created: 0,
252
- updated: 0,
253
- seq: 0,
254
- contentHash: '',
255
- provenance: { source: 'agent' }
256
- })
257
- .orThrow(),
258
- body
259
- };
260
- }
261
-
262
- function cappedStore(index?: IMemoryIndex, maxRecords: number = 2): FileTreeMemoryStore {
263
- const registry: IBodyConverterRegistry = BodyConverterRegistry.create().orThrow();
264
- registry.register(mtmKind, Converters.string);
265
- return FileTreeMemoryStore.create({
266
- root: mutableRoot(),
267
- registry,
268
- codecs: new Map<Kind, IIdentityCodec>([[mtmKind, new MtmIdentityCodec()]]),
269
- writePolicies: new Map<Kind, IWritePolicy>([
270
- [
271
- mtmKind,
272
- MemoryCapCullPolicy.create({
273
- maxRecords,
274
- mutableFields: ['body', 'tags', 'links', 'provenance']
275
- }).orThrow()
276
- ]
277
- ]),
278
- clock,
279
- index
280
- }).orThrow();
281
- }
282
-
283
- describe('FileTreeMemoryStore index injection', () => {
284
- describe('default (index omitted)', () => {
285
- test('creates and serves reads from a default MemoryIndex', async () => {
286
- const store = storeWith();
287
- (await store.put(knowledgeRecord('doc-a', 'alpha'))).orThrow();
288
- (await store.put(knowledgeRecord('doc-b', 'beta'))).orThrow();
289
-
290
- expect(await store.list()).toSucceedAndSatisfy((records: ReadonlyArray<IMemoryRecord<unknown>>) => {
291
- expect(records.map((r) => r.envelope.id).sort()).toEqual(['doc-a', 'doc-b']);
292
- });
293
- expect(await store.get(knowledgeKind, 'doc-a' as EntityId)).toSucceedAndSatisfy(
294
- (record: IMemoryRecord<unknown> | undefined) => {
295
- expect(record?.body).toBe('alpha');
296
- }
297
- );
298
- expect(await store.listScoped()).toSucceedAndSatisfy((scoped) => {
299
- expect(scoped).toHaveLength(2);
300
- });
301
- });
302
-
303
- test('reopening an existing vault re-indexes it and resumes seq', async () => {
304
- const root = mutableRoot();
305
- const first = storeWith(undefined, root);
306
- (await first.put(knowledgeRecord('doc-a', 'alpha'))).orThrow();
307
-
308
- const reopened = storeWith(undefined, root);
309
- expect(await reopened.list()).toSucceedAndSatisfy((records: ReadonlyArray<IMemoryRecord<unknown>>) => {
310
- expect(records).toHaveLength(1);
311
- expect(records[0].envelope.id).toBe('doc-a');
312
- });
313
- // seq resumes past the persisted high-water mark rather than restarting at 1.
314
- expect(await reopened.put(knowledgeRecord('doc-b', 'beta'))).toSucceedAndSatisfy(
315
- (record: IMemoryRecord<unknown>) => {
316
- expect(record.envelope.seq).toBe(2);
317
- }
318
- );
319
- });
320
- });
321
-
322
- describe('absent index', () => {
323
- test('a null index is treated as absent, matching every sibling optional param', async () => {
324
- // `create()`'s other optional params all absorb absence with `??`, which takes
325
- // null and undefined alike. A JS caller (or a TS caller through an `unknown`
326
- // hatch) passing `null` here must get the default index too — installing
327
- // `null` would instead fail later inside `entries()`, naming neither the param
328
- // nor the cause.
329
- const store = storeWith(null as unknown as IMemoryIndex);
330
- (await store.put(knowledgeRecord('doc-a', 'alpha'))).orThrow();
331
-
332
- expect(await store.list()).toSucceedAndSatisfy((records: ReadonlyArray<IMemoryRecord<unknown>>) => {
333
- expect(records.map((r) => r.envelope.id)).toEqual(['doc-a']);
334
- });
335
- });
336
- });
337
-
338
- describe('injected index', () => {
339
- test('receives the create() rebuild of an existing vault', async () => {
340
- const root = mutableRoot();
341
- const seeded = storeWith(undefined, root);
342
- (await seeded.put(knowledgeRecord('doc-a', 'alpha'))).orThrow();
343
- (await seeded.put(knowledgeRecord('doc-b', 'beta'))).orThrow();
344
-
345
- const recording = RecordingMemoryIndex.create().orThrow();
346
- const reopened = storeWith(recording, root);
347
-
348
- // create() rebuilt the injected index exactly once, with both persisted records.
349
- expect(recording.rebuildSizes).toEqual([2]);
350
- expect(recording.patchCalls).toEqual([]);
351
- expect(await reopened.list()).toSucceedAndSatisfy((records: ReadonlyArray<IMemoryRecord<unknown>>) => {
352
- expect(records.map((r) => r.envelope.id).sort()).toEqual(['doc-a', 'doc-b']);
353
- });
354
- });
355
-
356
- test('receives a put patch and a delete patch', async () => {
357
- const recording = RecordingMemoryIndex.create().orThrow();
358
- const store = storeWith(recording);
359
-
360
- // The empty-vault open still rebuilds (with zero entries) and patches nothing.
361
- expect(recording.rebuildSizes).toEqual([0]);
362
- expect(recording.patchCalls).toEqual([]);
363
-
364
- (await store.put(knowledgeRecord('doc-a', 'alpha'))).orThrow();
365
- expect(recording.patchCalls).toEqual([{ op: 'put', scope: knowledgeScope, id: 'doc-a' }]);
366
-
367
- // A content revision of the same id is another 'put' patch, not a second entry.
368
- (await store.put(knowledgeRecord('doc-a', 'alpha revised'))).orThrow();
369
- expect(recording.patchCalls).toHaveLength(2);
370
- expect(recording.patchCalls[1]).toEqual({ op: 'put', scope: knowledgeScope, id: 'doc-a' });
371
-
372
- expect(await store.delete(knowledgeKind, 'doc-a' as EntityId)).toSucceedWith('doc-a' as MemoryId);
373
- expect(recording.patchCalls[2]).toEqual({ op: 'delete', scope: knowledgeScope, id: 'doc-a' });
374
- });
375
-
376
- test('serves the store read surface — no second index is built', async () => {
377
- const recording = RecordingMemoryIndex.create().orThrow();
378
- const store = storeWith(recording);
379
- (await store.put(knowledgeRecord('doc-a', 'alpha', ['topic']))).orThrow();
380
-
381
- const before: number = recording.entriesCalls;
382
- expect(await store.list()).toSucceed();
383
- expect(await store.listScoped()).toSucceed();
384
- expect(recording.entriesCalls).toBeGreaterThan(before);
385
-
386
- // The injected index really holds the store's records: its projection views
387
- // (never touched by the store itself) answer from the patched state.
388
- expect(recording.byKind(knowledgeKind).map((r) => r.envelope.id)).toEqual(['doc-a']);
389
- expect(recording.byTag('topic' as Tag).map((r) => r.envelope.id)).toEqual(['doc-a']);
390
- expect(recording.byRecency().map((r) => r.envelope.id)).toEqual(['doc-a']);
391
- expect(recording.byRank().map((r) => r.envelope.id)).toEqual(['doc-a']);
392
- expect(recording.backlinks({ scope: knowledgeScope, id: 'doc-a' as MemoryId })).toEqual([]);
393
- });
394
-
395
- test('shares one index with a retriever built over the same instance', async () => {
396
- const recording = RecordingMemoryIndex.create().orThrow();
397
- const store = storeWith(recording);
398
- (await store.put(knowledgeRecord('doc-a', 'alpha'))).orThrow();
399
- (await store.put(knowledgeRecord('doc-b', 'beta'))).orThrow();
400
-
401
- // The consumer's real pattern: the store maintains the index, retrievers read it.
402
- const retriever = RecencyRetriever.create(recording).orThrow();
403
- expect(await retriever.retrieve({ kind: knowledgeKind })).toSucceedAndSatisfy(
404
- (records: ReadonlyArray<IMemoryRecord<unknown>>) => {
405
- expect(records.map((r) => r.envelope.id).sort()).toEqual(['doc-a', 'doc-b']);
406
- }
407
- );
408
- });
409
-
410
- test('the injected index — not a private one — determines what the store returns', async () => {
411
- const hiding = HidingMemoryIndex.create().orThrow();
412
- const store = storeWith(hiding);
413
- (await store.put(knowledgeRecord('doc-a', 'alpha'))).orThrow();
414
- (await store.put(knowledgeRecord('doc-b', 'hidden beta'))).orThrow();
415
-
416
- // Both records persisted, but the injected index hides one from `entries()`,
417
- // and every store read that goes through the index reflects exactly that.
418
- expect(await store.list()).toSucceedAndSatisfy((records: ReadonlyArray<IMemoryRecord<unknown>>) => {
419
- expect(records.map((r) => r.envelope.id)).toEqual(['doc-a']);
420
- });
421
- expect(await store.listScoped()).toSucceedAndSatisfy((scoped) => {
422
- expect(scoped.map((s) => s.target.id)).toEqual(['doc-a']);
423
- });
424
- // The file is still on disk — `getById` reads through to the FileTree, which
425
- // remains the source of truth regardless of what the derived index projects.
426
- expect(await store.getById(knowledgeScope, 'doc-b' as MemoryId)).toSucceedAndSatisfy(
427
- (record: IMemoryRecord<unknown> | undefined) => {
428
- expect(record?.body).toBe('hidden beta');
429
- }
430
- );
431
- });
432
-
433
- test('an index that reshapes entries() changes write semantics, not just reads', async () => {
434
- // The store's content-hash dedup and write-policy admission cohort both read
435
- // the index's `entries()`, so an index that hides a record hides it from dedup
436
- // too. This is the documented caveat on the `index` param — the reason to
437
- // inject only a faithful delegating decorator.
438
- const control = storeWith();
439
- (await control.put(knowledgeRecord('doc-b', 'hidden beta'))).orThrow();
440
- // Default index: an identical body under a NEW id collapses onto the existing
441
- // record (knowledge declares `dedupScope: 'content'`).
442
- expect(await control.put(knowledgeRecord('doc-c', 'hidden beta'))).toSucceedAndSatisfy(
443
- (record: IMemoryRecord<unknown>) => {
444
- expect(record.envelope.id).toBe('doc-b');
445
- }
446
- );
447
-
448
- const hiding = storeWith(HidingMemoryIndex.create().orThrow());
449
- (await hiding.put(knowledgeRecord('doc-b', 'hidden beta'))).orThrow();
450
- // Hiding index: doc-b is invisible to `entries()`, so the content-hash lookup
451
- // finds no duplicate and doc-c is written as a distinct record.
452
- expect(await hiding.put(knowledgeRecord('doc-c', 'hidden beta'))).toSucceedAndSatisfy(
453
- (record: IMemoryRecord<unknown>) => {
454
- expect(record.envelope.id).toBe('doc-c');
455
- }
456
- );
457
- });
458
- });
459
-
460
- describe('injected index — temporal and cap-cull write paths', () => {
461
- beforeEach(() => {
462
- clockValue = 1000;
463
- });
464
-
465
- test('the injected index decides which version a versioned put supersedes and a delete tombstones', async () => {
466
- // Both the versioned put and the versioned delete resolve an entity's version
467
- // history through `_versionsForEntity`, which is a scope filter over the
468
- // index's `entries()`. A version the injected index hides is therefore
469
- // invisible to both — it stays on disk, but the store will not supersede,
470
- // invalidate, or tombstone it. That is the documented caveat, and the reason
471
- // only a faithful delegating decorator is safe to inject.
472
- const control = versionedStore();
473
- (await control.put(factRecord('hidden blue'))).orThrow();
474
- clockValue = 2000;
475
- (await control.put(factRecord('grey'))).orThrow();
476
-
477
- // Default index: v1 is visible, so the second put closes its world-truth
478
- // interval at the new version's `valid_at`.
479
- expect(await control.getById(factScope, 'fact-1-v1' as MemoryId)).toSucceedAndSatisfy(
480
- (v1: IMemoryRecord<unknown> | undefined) => {
481
- expect(v1?.envelope.temporal?.invalid_at).toBe(2000);
482
- }
483
- );
484
-
485
- const hiding = versionedStore(HidingMemoryIndex.create().orThrow());
486
- clockValue = 1000;
487
- (await hiding.put(factRecord('hidden blue'))).orThrow();
488
- clockValue = 2000;
489
- (await hiding.put(factRecord('grey'))).orThrow();
490
-
491
- // Hiding index: v1 is invisible to the version walk, so the second put sees no
492
- // current version, is built as a FIRST version, and invalidates nothing. v1 is
493
- // still on disk and still carries no `invalid_at` — two live currents.
494
- expect(await hiding.getById(factScope, 'fact-1-v1' as MemoryId)).toSucceedAndSatisfy(
495
- (v1: IMemoryRecord<unknown> | undefined) => {
496
- expect(v1?.body).toBe('hidden blue');
497
- expect(v1?.envelope.temporal?.invalid_at).toBeUndefined();
498
- }
499
- );
500
-
501
- // The delete half of the same claim: a soft delete tombstones every version the
502
- // index shows as current, so the hidden v1 survives it untouched.
503
- clockValue = 3000;
504
- expect(await hiding.delete(factKind, 'fact-1' as EntityId)).toSucceed();
505
- expect(await hiding.getById(factScope, 'fact-1-v2' as MemoryId)).toSucceedAndSatisfy(
506
- (v2: IMemoryRecord<unknown> | undefined) => {
507
- expect(v2?.envelope.temporal?.invalid_at).toBe(3000);
508
- }
509
- );
510
- expect(await hiding.getById(factScope, 'fact-1-v1' as MemoryId)).toSucceedAndSatisfy(
511
- (v1: IMemoryRecord<unknown> | undefined) => {
512
- expect(v1?.envelope.temporal?.invalid_at).toBeUndefined();
513
- }
514
- );
515
- });
516
-
517
- test('cap-cull patches the injected index, and a reshaped cohort changes what is evicted', async () => {
518
- // `maxRecords: 2` over the shared conversations/conv-1 MTM scope. The third
519
- // write's admission cohort is the two prior records, so it culls the oldest.
520
- const recording = RecordingMemoryIndex.create().orThrow();
521
- const recorded = cappedStore(recording);
522
- for (let turn = 0; turn < 3; turn++) {
523
- clockValue = 1000 + turn; // distinct `created`, so "oldest" is unambiguous
524
- (await recorded.put(turnRecord(turn, turn === 0 ? 'hidden zero' : `turn ${turn}`))).orThrow();
525
- }
526
-
527
- // The eviction reaches the INJECTED index as a `delete` patch — the store keeps
528
- // no private index it could have patched instead.
529
- expect(recording.patchCalls.filter((c) => c.op === 'delete')).toEqual([
530
- { op: 'delete', scope: 'conversations/conv-1', id: 'turn-0' }
531
- ]);
532
- expect(await recorded.get(mtmKind, 'conv-1:0' as EntityId)).toSucceedWith(undefined);
533
-
534
- // Same writes, but an index that hides turn-0 shrinks the admission cohort to
535
- // one, which is under the cap — so nothing is evicted and turn-0 survives.
536
- // The cohort the policy sees is the index's projection, not the vault's.
537
- const hidden = cappedStore(HidingMemoryIndex.create().orThrow());
538
- for (let turn = 0; turn < 3; turn++) {
539
- clockValue = 1000 + turn;
540
- (await hidden.put(turnRecord(turn, turn === 0 ? 'hidden zero' : `turn ${turn}`))).orThrow();
541
- }
542
-
543
- expect(await hidden.get(mtmKind, 'conv-1:0' as EntityId)).toSucceedAndSatisfy(
544
- (record: IMemoryRecord<unknown> | undefined) => {
545
- expect(record?.body).toBe('hidden zero');
546
- }
547
- );
548
- });
549
- });
550
- });