@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,434 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2026 Erik Fortune
4
- * SPDX-License-Identifier: MIT
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- require("@fgv/ts-utils-jest");
8
- const ts_utils_1 = require("@fgv/ts-utils");
9
- const ts_json_base_1 = require("@fgv/ts-json-base");
10
- const index_1 = require("../../../index");
11
- const knowledgeKind = 'knowledge';
12
- const knowledgeScope = 'knowledge';
13
- function mutableRoot() {
14
- const tree = ts_json_base_1.FileTree.inMemory([], { mutable: true }).orThrow();
15
- const root = tree.getDirectory('/').orThrow();
16
- if (!ts_json_base_1.FileTree.isMutableDirectoryItem(root)) {
17
- throw new Error('expected a mutable root directory');
18
- }
19
- return root;
20
- }
21
- function knowledgeRecord(id, body, tags = []) {
22
- return {
23
- envelope: index_1.envelopeConverter
24
- .convert({
25
- id,
26
- entityId: id,
27
- kind: 'knowledge',
28
- tags: [...tags],
29
- links: [],
30
- created: 0,
31
- updated: 0,
32
- seq: 0,
33
- contentHash: '',
34
- provenance: { source: 'agent' }
35
- })
36
- .orThrow(),
37
- body
38
- };
39
- }
40
- function storeWith(index, root) {
41
- const registry = index_1.BodyConverterRegistry.create().orThrow();
42
- registry.register(knowledgeKind, ts_utils_1.Converters.string);
43
- return index_1.FileTreeMemoryStore.create({
44
- root: root !== null && root !== void 0 ? root : mutableRoot(),
45
- registry,
46
- codecs: new Map([[knowledgeKind, new index_1.KnowledgeIdentityCodec()]]),
47
- index
48
- }).orThrow();
49
- }
50
- /**
51
- * A counting/timing decorator over the shipped `MemoryIndex` — the exact shape
52
- * the injection seam exists to enable. Every call is delegated verbatim, so a
53
- * store wired with one behaves identically to a store using the default index;
54
- * the recorded counts are the measurement the consumer is after.
55
- */
56
- class RecordingMemoryIndex {
57
- constructor(inner) {
58
- this.rebuildSizes = [];
59
- this.patchCalls = [];
60
- this.entriesCalls = 0;
61
- this._inner = inner;
62
- }
63
- static create() {
64
- return index_1.MemoryIndex.create().onSuccess((inner) => (0, ts_utils_1.succeed)(new RecordingMemoryIndex(inner)));
65
- }
66
- rebuild(entries) {
67
- this.rebuildSizes.push(entries.length);
68
- return this._inner.rebuild(entries);
69
- }
70
- patch(op, entry) {
71
- this.patchCalls.push({ op, scope: entry.scope, id: entry.record.envelope.id });
72
- return this._inner.patch(op, entry);
73
- }
74
- entries() {
75
- this.entriesCalls += 1;
76
- return this._inner.entries();
77
- }
78
- byKind(kind) {
79
- return this._inner.byKind(kind);
80
- }
81
- byTag(tag) {
82
- return this._inner.byTag(tag);
83
- }
84
- byRecency() {
85
- return this._inner.byRecency();
86
- }
87
- byRank() {
88
- return this._inner.byRank();
89
- }
90
- backlinks(target) {
91
- return this._inner.backlinks(target);
92
- }
93
- }
94
- /**
95
- * An index that hides every record whose body contains `hidden` from the
96
- * `entries()` read surface. Not a realistic index — it exists to prove the store
97
- * reads from the INJECTED index rather than one it built for itself. A store
98
- * with a private index could not produce these results.
99
- */
100
- class HidingMemoryIndex {
101
- constructor(inner) {
102
- this._inner = inner;
103
- }
104
- static create() {
105
- return index_1.MemoryIndex.create().onSuccess((inner) => (0, ts_utils_1.succeed)(new HidingMemoryIndex(inner)));
106
- }
107
- rebuild(entries) {
108
- return this._inner.rebuild(entries);
109
- }
110
- patch(op, entry) {
111
- return this._inner.patch(op, entry);
112
- }
113
- entries() {
114
- return this._inner.entries().filter((e) => !String(e.record.body).includes('hidden'));
115
- }
116
- byKind(kind) {
117
- return this._inner.byKind(kind);
118
- }
119
- byTag(tag) {
120
- return this._inner.byTag(tag);
121
- }
122
- byRecency() {
123
- return this._inner.byRecency();
124
- }
125
- byRank() {
126
- return this._inner.byRank();
127
- }
128
- backlinks(target) {
129
- return this._inner.backlinks(target);
130
- }
131
- }
132
- // ---------------------------------------------------------------------------
133
- // Temporal (versioned) and cap-cull fixtures.
134
- //
135
- // The `index` param's TSDoc claims that an injected index decides which version a
136
- // versioned `put` supersedes, which versions a `delete` tombstones, and what a
137
- // cap-cull policy evicts — because all three derive their working set from
138
- // `entries()` rather than from the FileTree. These fixtures exist so those claims
139
- // are evidenced by test rather than only reasoned about from the implementation.
140
- // ---------------------------------------------------------------------------
141
- const factKind = 'fact';
142
- const factScope = 'facts/entities/fact-1';
143
- const mtmKind = 'mtm';
144
- let clockValue = 1000;
145
- const clock = () => clockValue;
146
- function factRecord(body) {
147
- return {
148
- envelope: index_1.envelopeConverter
149
- .convert({
150
- id: 'fact-1',
151
- entityId: 'fact-1',
152
- kind: 'fact',
153
- tags: [],
154
- links: [],
155
- created: 0,
156
- updated: 0,
157
- seq: 0,
158
- contentHash: '',
159
- provenance: { source: 'agent' }
160
- })
161
- .orThrow(),
162
- body
163
- };
164
- }
165
- function versionedStore(index) {
166
- const registry = index_1.BodyConverterRegistry.create().orThrow();
167
- registry.register(factKind, ts_utils_1.Converters.string);
168
- return index_1.FileTreeMemoryStore.create({
169
- root: mutableRoot(),
170
- registry,
171
- codecs: new Map([[factKind, index_1.TemporalIdentityCodec.create('facts').orThrow()]]),
172
- writePolicies: new Map([[factKind, index_1.TemporalVersionedPolicy.create().orThrow()]]),
173
- clock,
174
- index
175
- }).orThrow();
176
- }
177
- function turnRecord(turn, body) {
178
- return {
179
- envelope: index_1.envelopeConverter
180
- .convert({
181
- id: `turn-${turn}`,
182
- entityId: `conv-1:${turn}`,
183
- kind: 'mtm',
184
- tags: [],
185
- links: [],
186
- created: 0,
187
- updated: 0,
188
- seq: 0,
189
- contentHash: '',
190
- provenance: { source: 'agent' }
191
- })
192
- .orThrow(),
193
- body
194
- };
195
- }
196
- function cappedStore(index, maxRecords = 2) {
197
- const registry = index_1.BodyConverterRegistry.create().orThrow();
198
- registry.register(mtmKind, ts_utils_1.Converters.string);
199
- return index_1.FileTreeMemoryStore.create({
200
- root: mutableRoot(),
201
- registry,
202
- codecs: new Map([[mtmKind, new index_1.MtmIdentityCodec()]]),
203
- writePolicies: new Map([
204
- [
205
- mtmKind,
206
- index_1.MemoryCapCullPolicy.create({
207
- maxRecords,
208
- mutableFields: ['body', 'tags', 'links', 'provenance']
209
- }).orThrow()
210
- ]
211
- ]),
212
- clock,
213
- index
214
- }).orThrow();
215
- }
216
- describe('FileTreeMemoryStore index injection', () => {
217
- describe('default (index omitted)', () => {
218
- test('creates and serves reads from a default MemoryIndex', async () => {
219
- const store = storeWith();
220
- (await store.put(knowledgeRecord('doc-a', 'alpha'))).orThrow();
221
- (await store.put(knowledgeRecord('doc-b', 'beta'))).orThrow();
222
- expect(await store.list()).toSucceedAndSatisfy((records) => {
223
- expect(records.map((r) => r.envelope.id).sort()).toEqual(['doc-a', 'doc-b']);
224
- });
225
- expect(await store.get(knowledgeKind, 'doc-a')).toSucceedAndSatisfy((record) => {
226
- expect(record === null || record === void 0 ? void 0 : record.body).toBe('alpha');
227
- });
228
- expect(await store.listScoped()).toSucceedAndSatisfy((scoped) => {
229
- expect(scoped).toHaveLength(2);
230
- });
231
- });
232
- test('reopening an existing vault re-indexes it and resumes seq', async () => {
233
- const root = mutableRoot();
234
- const first = storeWith(undefined, root);
235
- (await first.put(knowledgeRecord('doc-a', 'alpha'))).orThrow();
236
- const reopened = storeWith(undefined, root);
237
- expect(await reopened.list()).toSucceedAndSatisfy((records) => {
238
- expect(records).toHaveLength(1);
239
- expect(records[0].envelope.id).toBe('doc-a');
240
- });
241
- // seq resumes past the persisted high-water mark rather than restarting at 1.
242
- expect(await reopened.put(knowledgeRecord('doc-b', 'beta'))).toSucceedAndSatisfy((record) => {
243
- expect(record.envelope.seq).toBe(2);
244
- });
245
- });
246
- });
247
- describe('absent index', () => {
248
- test('a null index is treated as absent, matching every sibling optional param', async () => {
249
- // `create()`'s other optional params all absorb absence with `??`, which takes
250
- // null and undefined alike. A JS caller (or a TS caller through an `unknown`
251
- // hatch) passing `null` here must get the default index too — installing
252
- // `null` would instead fail later inside `entries()`, naming neither the param
253
- // nor the cause.
254
- const store = storeWith(null);
255
- (await store.put(knowledgeRecord('doc-a', 'alpha'))).orThrow();
256
- expect(await store.list()).toSucceedAndSatisfy((records) => {
257
- expect(records.map((r) => r.envelope.id)).toEqual(['doc-a']);
258
- });
259
- });
260
- });
261
- describe('injected index', () => {
262
- test('receives the create() rebuild of an existing vault', async () => {
263
- const root = mutableRoot();
264
- const seeded = storeWith(undefined, root);
265
- (await seeded.put(knowledgeRecord('doc-a', 'alpha'))).orThrow();
266
- (await seeded.put(knowledgeRecord('doc-b', 'beta'))).orThrow();
267
- const recording = RecordingMemoryIndex.create().orThrow();
268
- const reopened = storeWith(recording, root);
269
- // create() rebuilt the injected index exactly once, with both persisted records.
270
- expect(recording.rebuildSizes).toEqual([2]);
271
- expect(recording.patchCalls).toEqual([]);
272
- expect(await reopened.list()).toSucceedAndSatisfy((records) => {
273
- expect(records.map((r) => r.envelope.id).sort()).toEqual(['doc-a', 'doc-b']);
274
- });
275
- });
276
- test('receives a put patch and a delete patch', async () => {
277
- const recording = RecordingMemoryIndex.create().orThrow();
278
- const store = storeWith(recording);
279
- // The empty-vault open still rebuilds (with zero entries) and patches nothing.
280
- expect(recording.rebuildSizes).toEqual([0]);
281
- expect(recording.patchCalls).toEqual([]);
282
- (await store.put(knowledgeRecord('doc-a', 'alpha'))).orThrow();
283
- expect(recording.patchCalls).toEqual([{ op: 'put', scope: knowledgeScope, id: 'doc-a' }]);
284
- // A content revision of the same id is another 'put' patch, not a second entry.
285
- (await store.put(knowledgeRecord('doc-a', 'alpha revised'))).orThrow();
286
- expect(recording.patchCalls).toHaveLength(2);
287
- expect(recording.patchCalls[1]).toEqual({ op: 'put', scope: knowledgeScope, id: 'doc-a' });
288
- expect(await store.delete(knowledgeKind, 'doc-a')).toSucceedWith('doc-a');
289
- expect(recording.patchCalls[2]).toEqual({ op: 'delete', scope: knowledgeScope, id: 'doc-a' });
290
- });
291
- test('serves the store read surface — no second index is built', async () => {
292
- const recording = RecordingMemoryIndex.create().orThrow();
293
- const store = storeWith(recording);
294
- (await store.put(knowledgeRecord('doc-a', 'alpha', ['topic']))).orThrow();
295
- const before = recording.entriesCalls;
296
- expect(await store.list()).toSucceed();
297
- expect(await store.listScoped()).toSucceed();
298
- expect(recording.entriesCalls).toBeGreaterThan(before);
299
- // The injected index really holds the store's records: its projection views
300
- // (never touched by the store itself) answer from the patched state.
301
- expect(recording.byKind(knowledgeKind).map((r) => r.envelope.id)).toEqual(['doc-a']);
302
- expect(recording.byTag('topic').map((r) => r.envelope.id)).toEqual(['doc-a']);
303
- expect(recording.byRecency().map((r) => r.envelope.id)).toEqual(['doc-a']);
304
- expect(recording.byRank().map((r) => r.envelope.id)).toEqual(['doc-a']);
305
- expect(recording.backlinks({ scope: knowledgeScope, id: 'doc-a' })).toEqual([]);
306
- });
307
- test('shares one index with a retriever built over the same instance', async () => {
308
- const recording = RecordingMemoryIndex.create().orThrow();
309
- const store = storeWith(recording);
310
- (await store.put(knowledgeRecord('doc-a', 'alpha'))).orThrow();
311
- (await store.put(knowledgeRecord('doc-b', 'beta'))).orThrow();
312
- // The consumer's real pattern: the store maintains the index, retrievers read it.
313
- const retriever = index_1.RecencyRetriever.create(recording).orThrow();
314
- expect(await retriever.retrieve({ kind: knowledgeKind })).toSucceedAndSatisfy((records) => {
315
- expect(records.map((r) => r.envelope.id).sort()).toEqual(['doc-a', 'doc-b']);
316
- });
317
- });
318
- test('the injected index — not a private one — determines what the store returns', async () => {
319
- const hiding = HidingMemoryIndex.create().orThrow();
320
- const store = storeWith(hiding);
321
- (await store.put(knowledgeRecord('doc-a', 'alpha'))).orThrow();
322
- (await store.put(knowledgeRecord('doc-b', 'hidden beta'))).orThrow();
323
- // Both records persisted, but the injected index hides one from `entries()`,
324
- // and every store read that goes through the index reflects exactly that.
325
- expect(await store.list()).toSucceedAndSatisfy((records) => {
326
- expect(records.map((r) => r.envelope.id)).toEqual(['doc-a']);
327
- });
328
- expect(await store.listScoped()).toSucceedAndSatisfy((scoped) => {
329
- expect(scoped.map((s) => s.target.id)).toEqual(['doc-a']);
330
- });
331
- // The file is still on disk — `getById` reads through to the FileTree, which
332
- // remains the source of truth regardless of what the derived index projects.
333
- expect(await store.getById(knowledgeScope, 'doc-b')).toSucceedAndSatisfy((record) => {
334
- expect(record === null || record === void 0 ? void 0 : record.body).toBe('hidden beta');
335
- });
336
- });
337
- test('an index that reshapes entries() changes write semantics, not just reads', async () => {
338
- // The store's content-hash dedup and write-policy admission cohort both read
339
- // the index's `entries()`, so an index that hides a record hides it from dedup
340
- // too. This is the documented caveat on the `index` param — the reason to
341
- // inject only a faithful delegating decorator.
342
- const control = storeWith();
343
- (await control.put(knowledgeRecord('doc-b', 'hidden beta'))).orThrow();
344
- // Default index: an identical body under a NEW id collapses onto the existing
345
- // record (knowledge declares `dedupScope: 'content'`).
346
- expect(await control.put(knowledgeRecord('doc-c', 'hidden beta'))).toSucceedAndSatisfy((record) => {
347
- expect(record.envelope.id).toBe('doc-b');
348
- });
349
- const hiding = storeWith(HidingMemoryIndex.create().orThrow());
350
- (await hiding.put(knowledgeRecord('doc-b', 'hidden beta'))).orThrow();
351
- // Hiding index: doc-b is invisible to `entries()`, so the content-hash lookup
352
- // finds no duplicate and doc-c is written as a distinct record.
353
- expect(await hiding.put(knowledgeRecord('doc-c', 'hidden beta'))).toSucceedAndSatisfy((record) => {
354
- expect(record.envelope.id).toBe('doc-c');
355
- });
356
- });
357
- });
358
- describe('injected index — temporal and cap-cull write paths', () => {
359
- beforeEach(() => {
360
- clockValue = 1000;
361
- });
362
- test('the injected index decides which version a versioned put supersedes and a delete tombstones', async () => {
363
- // Both the versioned put and the versioned delete resolve an entity's version
364
- // history through `_versionsForEntity`, which is a scope filter over the
365
- // index's `entries()`. A version the injected index hides is therefore
366
- // invisible to both — it stays on disk, but the store will not supersede,
367
- // invalidate, or tombstone it. That is the documented caveat, and the reason
368
- // only a faithful delegating decorator is safe to inject.
369
- const control = versionedStore();
370
- (await control.put(factRecord('hidden blue'))).orThrow();
371
- clockValue = 2000;
372
- (await control.put(factRecord('grey'))).orThrow();
373
- // Default index: v1 is visible, so the second put closes its world-truth
374
- // interval at the new version's `valid_at`.
375
- expect(await control.getById(factScope, 'fact-1-v1')).toSucceedAndSatisfy((v1) => {
376
- var _a;
377
- expect((_a = v1 === null || v1 === void 0 ? void 0 : v1.envelope.temporal) === null || _a === void 0 ? void 0 : _a.invalid_at).toBe(2000);
378
- });
379
- const hiding = versionedStore(HidingMemoryIndex.create().orThrow());
380
- clockValue = 1000;
381
- (await hiding.put(factRecord('hidden blue'))).orThrow();
382
- clockValue = 2000;
383
- (await hiding.put(factRecord('grey'))).orThrow();
384
- // Hiding index: v1 is invisible to the version walk, so the second put sees no
385
- // current version, is built as a FIRST version, and invalidates nothing. v1 is
386
- // still on disk and still carries no `invalid_at` — two live currents.
387
- expect(await hiding.getById(factScope, 'fact-1-v1')).toSucceedAndSatisfy((v1) => {
388
- var _a;
389
- expect(v1 === null || v1 === void 0 ? void 0 : v1.body).toBe('hidden blue');
390
- expect((_a = v1 === null || v1 === void 0 ? void 0 : v1.envelope.temporal) === null || _a === void 0 ? void 0 : _a.invalid_at).toBeUndefined();
391
- });
392
- // The delete half of the same claim: a soft delete tombstones every version the
393
- // index shows as current, so the hidden v1 survives it untouched.
394
- clockValue = 3000;
395
- expect(await hiding.delete(factKind, 'fact-1')).toSucceed();
396
- expect(await hiding.getById(factScope, 'fact-1-v2')).toSucceedAndSatisfy((v2) => {
397
- var _a;
398
- expect((_a = v2 === null || v2 === void 0 ? void 0 : v2.envelope.temporal) === null || _a === void 0 ? void 0 : _a.invalid_at).toBe(3000);
399
- });
400
- expect(await hiding.getById(factScope, 'fact-1-v1')).toSucceedAndSatisfy((v1) => {
401
- var _a;
402
- expect((_a = v1 === null || v1 === void 0 ? void 0 : v1.envelope.temporal) === null || _a === void 0 ? void 0 : _a.invalid_at).toBeUndefined();
403
- });
404
- });
405
- test('cap-cull patches the injected index, and a reshaped cohort changes what is evicted', async () => {
406
- // `maxRecords: 2` over the shared conversations/conv-1 MTM scope. The third
407
- // write's admission cohort is the two prior records, so it culls the oldest.
408
- const recording = RecordingMemoryIndex.create().orThrow();
409
- const recorded = cappedStore(recording);
410
- for (let turn = 0; turn < 3; turn++) {
411
- clockValue = 1000 + turn; // distinct `created`, so "oldest" is unambiguous
412
- (await recorded.put(turnRecord(turn, turn === 0 ? 'hidden zero' : `turn ${turn}`))).orThrow();
413
- }
414
- // The eviction reaches the INJECTED index as a `delete` patch — the store keeps
415
- // no private index it could have patched instead.
416
- expect(recording.patchCalls.filter((c) => c.op === 'delete')).toEqual([
417
- { op: 'delete', scope: 'conversations/conv-1', id: 'turn-0' }
418
- ]);
419
- expect(await recorded.get(mtmKind, 'conv-1:0')).toSucceedWith(undefined);
420
- // Same writes, but an index that hides turn-0 shrinks the admission cohort to
421
- // one, which is under the cap — so nothing is evicted and turn-0 survives.
422
- // The cohort the policy sees is the index's projection, not the vault's.
423
- const hidden = cappedStore(HidingMemoryIndex.create().orThrow());
424
- for (let turn = 0; turn < 3; turn++) {
425
- clockValue = 1000 + turn;
426
- (await hidden.put(turnRecord(turn, turn === 0 ? 'hidden zero' : `turn ${turn}`))).orThrow();
427
- }
428
- expect(await hidden.get(mtmKind, 'conv-1:0')).toSucceedAndSatisfy((record) => {
429
- expect(record === null || record === void 0 ? void 0 : record.body).toBe('hidden zero');
430
- });
431
- });
432
- });
433
- });
434
- //# sourceMappingURL=indexInjection.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"indexInjection.test.js","sourceRoot":"","sources":["../../../../src/test/unit/store/indexInjection.test.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAEH,8BAA4B;AAC5B,4CAA4D;AAC5D,oDAA6C;AAC7C,0CAwBwB;AAExB,MAAM,aAAa,GAAS,WAAmB,CAAC;AAChD,MAAM,cAAc,GAAmB,WAA6B,CAAC;AAErE,SAAS,WAAW;IAClB,MAAM,IAAI,GAAG,uBAAQ,C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Q,CAAC,CAAC,CAAC,OAAO,CAAC;gBACpE,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,sBAAsB,EAAE,EAAE,EAAE,QAAQ,EAAE;aAC9D,CAAC,CAAC;YACH,MAAM,CAAC,MAAM,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,UAAsB,CAAC,CAAC,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;YAErF,8EAA8E;YAC9E,2EAA2E;YAC3E,yEAAyE;YACzE,MAAM,MAAM,GAAG,WAAW,CAAC,iBAAiB,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;YACjE,KAAK,IAAI,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC;gBACpC,UAAU,GAAG,IAAI,GAAG,IAAI,CAAC;gBACzB,CAAC,MAAM,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;YAC9F,CAAC;YAED,MAAM,CAAC,MAAM,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,UAAsB,CAAC,CAAC,CAAC,mBAAmB,CAC3E,CAAC,MAA0C,EAAE,EAAE;gBAC7C,MAAM,CAAC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YAC3C,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/*\n * Copyright (c) 2026 Erik Fortune\n * SPDX-License-Identifier: MIT\n */\n\nimport '@fgv/ts-utils-jest';\nimport { Converters, Result, succeed } from '@fgv/ts-utils';\nimport { FileTree } from '@fgv/ts-json-base';\nimport {\n BodyConverterRegistry,\n EntityId,\n FileTreeMemoryStore,\n IBodyConverterRegistry,\n IEdgeTarget,\n IIdentityCodec,\n IIndexedMemoryRecord,\n IMemoryIndex,\n IMemoryRecord,\n IWritePolicy,\n Kind,\n KnowledgeIdentityCodec,\n MemoryCapCullPolicy,\n MemoryId,\n MemoryIndex,\n MemoryIndexPatchOp,\n MemoryScopeKey,\n MtmIdentityCodec,\n RecencyRetriever,\n Tag,\n TemporalIdentityCodec,\n TemporalVersionedPolicy,\n envelopeConverter\n} from '../../../index';\n\nconst knowledgeKind: Kind = 'knowledge' as Kind;\nconst knowledgeScope: MemoryScopeKey = 'knowledge' as MemoryScopeKey;\n\nfunction mutableRoot(): FileTree.IMutableFileTreeDirectoryItem {\n const tree = FileTree.inMemory([], { mutable: true }).orThrow();\n const root = tree.getDirectory('/').orThrow();\n if (!FileTree.isMutableDirectoryItem(root)) {\n throw new Error('expected a mutable root directory');\n }\n return root;\n}\n\nfunction knowledgeRecord(id: string, body: string, tags: ReadonlyArray<string> = []): IMemoryRecord<unknown> {\n return {\n envelope: envelopeConverter\n .convert({\n id,\n entityId: id,\n kind: 'knowledge',\n tags: [...tags],\n links: [],\n created: 0,\n updated: 0,\n seq: 0,\n contentHash: '',\n provenance: { source: 'agent' }\n })\n .orThrow(),\n body\n };\n}\n\nfunction storeWith(index?: IMemoryIndex, root?: FileTree.IMutableFileTreeDirectoryItem): FileTreeMemoryStore {\n const registry: IBodyConverterRegistry = BodyConverterRegistry.create().orThrow();\n registry.register(knowledgeKind, Converters.string);\n return FileTreeMemoryStore.create({\n root: root ?? mutableRoot(),\n registry,\n codecs: new Map<Kind, IIdentityCodec>([[knowledgeKind, new KnowledgeIdentityCodec()]]),\n index\n }).orThrow();\n}\n\n/** One recorded {@link IMemoryIndex.patch} call. */\ninterface IPatchCall {\n readonly op: MemoryIndexPatchOp;\n readonly scope: MemoryScopeKey;\n readonly id: string;\n}\n\n/**\n * A counting/timing decorator over the shipped `MemoryIndex` — the exact shape\n * the injection seam exists to enable. Every call is delegated verbatim, so a\n * store wired with one behaves identically to a store using the default index;\n * the recorded counts are the measurement the consumer is after.\n */\nclass RecordingMemoryIndex implements IMemoryIndex {\n public readonly rebuildSizes: number[] = [];\n public readonly patchCalls: IPatchCall[] = [];\n public entriesCalls: number = 0;\n\n private readonly _inner: IMemoryIndex;\n\n private constructor(inner: IMemoryIndex) {\n this._inner = inner;\n }\n\n public static create(): Result<RecordingMemoryIndex> {\n return MemoryIndex.create().onSuccess((inner) => succeed(new RecordingMemoryIndex(inner)));\n }\n\n public rebuild(entries: ReadonlyArray<IIndexedMemoryRecord>): Result<number> {\n this.rebuildSizes.push(entries.length);\n return this._inner.rebuild(entries);\n }\n\n public patch(op: MemoryIndexPatchOp, entry: IIndexedMemoryRecord): Result<IIndexedMemoryRecord> {\n this.patchCalls.push({ op, scope: entry.scope, id: entry.record.envelope.id });\n return this._inner.patch(op, entry);\n }\n\n public entries(): ReadonlyArray<IIndexedMemoryRecord> {\n this.entriesCalls += 1;\n return this._inner.entries();\n }\n\n public byKind(kind: Kind): ReadonlyArray<IMemoryRecord<unknown>> {\n return this._inner.byKind(kind);\n }\n\n public byTag(tag: Tag): ReadonlyArray<IMemoryRecord<unknown>> {\n return this._inner.byTag(tag);\n }\n\n public byRecency(): ReadonlyArray<IMemoryRecord<unknown>> {\n return this._inner.byRecency();\n }\n\n public byRank(): ReadonlyArray<IMemoryRecord<unknown>> {\n return this._inner.byRank();\n }\n\n public backlinks(target: IEdgeTarget): ReadonlyArray<IEdgeTarget> {\n return this._inner.backlinks(target);\n }\n}\n\n/**\n * An index that hides every record whose body contains `hidden` from the\n * `entries()` read surface. Not a realistic index — it exists to prove the store\n * reads from the INJECTED index rather than one it built for itself. A store\n * with a private index could not produce these results.\n */\nclass HidingMemoryIndex implements IMemoryIndex {\n private readonly _inner: IMemoryIndex;\n\n private constructor(inner: IMemoryIndex) {\n this._inner = inner;\n }\n\n public static create(): Result<HidingMemoryIndex> {\n return MemoryIndex.create().onSuccess((inner) => succeed(new HidingMemoryIndex(inner)));\n }\n\n public rebuild(entries: ReadonlyArray<IIndexedMemoryRecord>): Result<number> {\n return this._inner.rebuild(entries);\n }\n\n public patch(op: MemoryIndexPatchOp, entry: IIndexedMemoryRecord): Result<IIndexedMemoryRecord> {\n return this._inner.patch(op, entry);\n }\n\n public entries(): ReadonlyArray<IIndexedMemoryRecord> {\n return this._inner.entries().filter((e) => !String(e.record.body).includes('hidden'));\n }\n\n public byKind(kind: Kind): ReadonlyArray<IMemoryRecord<unknown>> {\n return this._inner.byKind(kind);\n }\n\n public byTag(tag: Tag): ReadonlyArray<IMemoryRecord<unknown>> {\n return this._inner.byTag(tag);\n }\n\n public byRecency(): ReadonlyArray<IMemoryRecord<unknown>> {\n return this._inner.byRecency();\n }\n\n public byRank(): ReadonlyArray<IMemoryRecord<unknown>> {\n return this._inner.byRank();\n }\n\n public backlinks(target: IEdgeTarget): ReadonlyArray<IEdgeTarget> {\n return this._inner.backlinks(target);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Temporal (versioned) and cap-cull fixtures.\n//\n// The `index` param's TSDoc claims that an injected index decides which version a\n// versioned `put` supersedes, which versions a `delete` tombstones, and what a\n// cap-cull policy evicts — because all three derive their working set from\n// `entries()` rather than from the FileTree. These fixtures exist so those claims\n// are evidenced by test rather than only reasoned about from the implementation.\n// ---------------------------------------------------------------------------\n\nconst factKind: Kind = 'fact' as Kind;\nconst factScope: MemoryScopeKey = 'facts/entities/fact-1' as MemoryScopeKey;\nconst mtmKind: Kind = 'mtm' as Kind;\n\nlet clockValue: number = 1000;\nconst clock = (): number => clockValue;\n\nfunction factRecord(body: string): IMemoryRecord<unknown> {\n return {\n envelope: envelopeConverter\n .convert({\n id: 'fact-1',\n entityId: 'fact-1',\n kind: 'fact',\n tags: [],\n links: [],\n created: 0,\n updated: 0,\n seq: 0,\n contentHash: '',\n provenance: { source: 'agent' }\n })\n .orThrow(),\n body\n };\n}\n\nfunction versionedStore(index?: IMemoryIndex): FileTreeMemoryStore {\n const registry: IBodyConverterRegistry = BodyConverterRegistry.create().orThrow();\n registry.register(factKind, Converters.string);\n return FileTreeMemoryStore.create({\n root: mutableRoot(),\n registry,\n codecs: new Map<Kind, IIdentityCodec>([[factKind, TemporalIdentityCodec.create('facts').orThrow()]]),\n writePolicies: new Map<Kind, IWritePolicy>([[factKind, TemporalVersionedPolicy.create().orThrow()]]),\n clock,\n index\n }).orThrow();\n}\n\nfunction turnRecord(turn: number, body: string): IMemoryRecord<unknown> {\n return {\n envelope: envelopeConverter\n .convert({\n id: `turn-${turn}`,\n entityId: `conv-1:${turn}`,\n kind: 'mtm',\n tags: [],\n links: [],\n created: 0,\n updated: 0,\n seq: 0,\n contentHash: '',\n provenance: { source: 'agent' }\n })\n .orThrow(),\n body\n };\n}\n\nfunction cappedStore(index?: IMemoryIndex, maxRecords: number = 2): FileTreeMemoryStore {\n const registry: IBodyConverterRegistry = BodyConverterRegistry.create().orThrow();\n registry.register(mtmKind, Converters.string);\n return FileTreeMemoryStore.create({\n root: mutableRoot(),\n registry,\n codecs: new Map<Kind, IIdentityCodec>([[mtmKind, new MtmIdentityCodec()]]),\n writePolicies: new Map<Kind, IWritePolicy>([\n [\n mtmKind,\n MemoryCapCullPolicy.create({\n maxRecords,\n mutableFields: ['body', 'tags', 'links', 'provenance']\n }).orThrow()\n ]\n ]),\n clock,\n index\n }).orThrow();\n}\n\ndescribe('FileTreeMemoryStore index injection', () => {\n describe('default (index omitted)', () => {\n test('creates and serves reads from a default MemoryIndex', async () => {\n const store = storeWith();\n (await store.put(knowledgeRecord('doc-a', 'alpha'))).orThrow();\n (await store.put(knowledgeRecord('doc-b', 'beta'))).orThrow();\n\n expect(await store.list()).toSucceedAndSatisfy((records: ReadonlyArray<IMemoryRecord<unknown>>) => {\n expect(records.map((r) => r.envelope.id).sort()).toEqual(['doc-a', 'doc-b']);\n });\n expect(await store.get(knowledgeKind, 'doc-a' as EntityId)).toSucceedAndSatisfy(\n (record: IMemoryRecord<unknown> | undefined) => {\n expect(record?.body).toBe('alpha');\n }\n );\n expect(await store.listScoped()).toSucceedAndSatisfy((scoped) => {\n expect(scoped).toHaveLength(2);\n });\n });\n\n test('reopening an existing vault re-indexes it and resumes seq', async () => {\n const root = mutableRoot();\n const first = storeWith(undefined, root);\n (await first.put(knowledgeRecord('doc-a', 'alpha'))).orThrow();\n\n const reopened = storeWith(undefined, root);\n expect(await reopened.list()).toSucceedAndSatisfy((records: ReadonlyArray<IMemoryRecord<unknown>>) => {\n expect(records).toHaveLength(1);\n expect(records[0].envelope.id).toBe('doc-a');\n });\n // seq resumes past the persisted high-water mark rather than restarting at 1.\n expect(await reopened.put(knowledgeRecord('doc-b', 'beta'))).toSucceedAndSatisfy(\n (record: IMemoryRecord<unknown>) => {\n expect(record.envelope.seq).toBe(2);\n }\n );\n });\n });\n\n describe('absent index', () => {\n test('a null index is treated as absent, matching every sibling optional param', async () => {\n // `create()`'s other optional params all absorb absence with `??`, which takes\n // null and undefined alike. A JS caller (or a TS caller through an `unknown`\n // hatch) passing `null` here must get the default index too — installing\n // `null` would instead fail later inside `entries()`, naming neither the param\n // nor the cause.\n const store = storeWith(null as unknown as IMemoryIndex);\n (await store.put(knowledgeRecord('doc-a', 'alpha'))).orThrow();\n\n expect(await store.list()).toSucceedAndSatisfy((records: ReadonlyArray<IMemoryRecord<unknown>>) => {\n expect(records.map((r) => r.envelope.id)).toEqual(['doc-a']);\n });\n });\n });\n\n describe('injected index', () => {\n test('receives the create() rebuild of an existing vault', async () => {\n const root = mutableRoot();\n const seeded = storeWith(undefined, root);\n (await seeded.put(knowledgeRecord('doc-a', 'alpha'))).orThrow();\n (await seeded.put(knowledgeRecord('doc-b', 'beta'))).orThrow();\n\n const recording = RecordingMemoryIndex.create().orThrow();\n const reopened = storeWith(recording, root);\n\n // create() rebuilt the injected index exactly once, with both persisted records.\n expect(recording.rebuildSizes).toEqual([2]);\n expect(recording.patchCalls).toEqual([]);\n expect(await reopened.list()).toSucceedAndSatisfy((records: ReadonlyArray<IMemoryRecord<unknown>>) => {\n expect(records.map((r) => r.envelope.id).sort()).toEqual(['doc-a', 'doc-b']);\n });\n });\n\n test('receives a put patch and a delete patch', async () => {\n const recording = RecordingMemoryIndex.create().orThrow();\n const store = storeWith(recording);\n\n // The empty-vault open still rebuilds (with zero entries) and patches nothing.\n expect(recording.rebuildSizes).toEqual([0]);\n expect(recording.patchCalls).toEqual([]);\n\n (await store.put(knowledgeRecord('doc-a', 'alpha'))).orThrow();\n expect(recording.patchCalls).toEqual([{ op: 'put', scope: knowledgeScope, id: 'doc-a' }]);\n\n // A content revision of the same id is another 'put' patch, not a second entry.\n (await store.put(knowledgeRecord('doc-a', 'alpha revised'))).orThrow();\n expect(recording.patchCalls).toHaveLength(2);\n expect(recording.patchCalls[1]).toEqual({ op: 'put', scope: knowledgeScope, id: 'doc-a' });\n\n expect(await store.delete(knowledgeKind, 'doc-a' as EntityId)).toSucceedWith('doc-a' as MemoryId);\n expect(recording.patchCalls[2]).toEqual({ op: 'delete', scope: knowledgeScope, id: 'doc-a' });\n });\n\n test('serves the store read surface — no second index is built', async () => {\n const recording = RecordingMemoryIndex.create().orThrow();\n const store = storeWith(recording);\n (await store.put(knowledgeRecord('doc-a', 'alpha', ['topic']))).orThrow();\n\n const before: number = recording.entriesCalls;\n expect(await store.list()).toSucceed();\n expect(await store.listScoped()).toSucceed();\n expect(recording.entriesCalls).toBeGreaterThan(before);\n\n // The injected index really holds the store's records: its projection views\n // (never touched by the store itself) answer from the patched state.\n expect(recording.byKind(knowledgeKind).map((r) => r.envelope.id)).toEqual(['doc-a']);\n expect(recording.byTag('topic' as Tag).map((r) => r.envelope.id)).toEqual(['doc-a']);\n expect(recording.byRecency().map((r) => r.envelope.id)).toEqual(['doc-a']);\n expect(recording.byRank().map((r) => r.envelope.id)).toEqual(['doc-a']);\n expect(recording.backlinks({ scope: knowledgeScope, id: 'doc-a' as MemoryId })).toEqual([]);\n });\n\n test('shares one index with a retriever built over the same instance', async () => {\n const recording = RecordingMemoryIndex.create().orThrow();\n const store = storeWith(recording);\n (await store.put(knowledgeRecord('doc-a', 'alpha'))).orThrow();\n (await store.put(knowledgeRecord('doc-b', 'beta'))).orThrow();\n\n // The consumer's real pattern: the store maintains the index, retrievers read it.\n const retriever = RecencyRetriever.create(recording).orThrow();\n expect(await retriever.retrieve({ kind: knowledgeKind })).toSucceedAndSatisfy(\n (records: ReadonlyArray<IMemoryRecord<unknown>>) => {\n expect(records.map((r) => r.envelope.id).sort()).toEqual(['doc-a', 'doc-b']);\n }\n );\n });\n\n test('the injected index — not a private one — determines what the store returns', async () => {\n const hiding = HidingMemoryIndex.create().orThrow();\n const store = storeWith(hiding);\n (await store.put(knowledgeRecord('doc-a', 'alpha'))).orThrow();\n (await store.put(knowledgeRecord('doc-b', 'hidden beta'))).orThrow();\n\n // Both records persisted, but the injected index hides one from `entries()`,\n // and every store read that goes through the index reflects exactly that.\n expect(await store.list()).toSucceedAndSatisfy((records: ReadonlyArray<IMemoryRecord<unknown>>) => {\n expect(records.map((r) => r.envelope.id)).toEqual(['doc-a']);\n });\n expect(await store.listScoped()).toSucceedAndSatisfy((scoped) => {\n expect(scoped.map((s) => s.target.id)).toEqual(['doc-a']);\n });\n // The file is still on disk — `getById` reads through to the FileTree, which\n // remains the source of truth regardless of what the derived index projects.\n expect(await store.getById(knowledgeScope, 'doc-b' as MemoryId)).toSucceedAndSatisfy(\n (record: IMemoryRecord<unknown> | undefined) => {\n expect(record?.body).toBe('hidden beta');\n }\n );\n });\n\n test('an index that reshapes entries() changes write semantics, not just reads', async () => {\n // The store's content-hash dedup and write-policy admission cohort both read\n // the index's `entries()`, so an index that hides a record hides it from dedup\n // too. This is the documented caveat on the `index` param — the reason to\n // inject only a faithful delegating decorator.\n const control = storeWith();\n (await control.put(knowledgeRecord('doc-b', 'hidden beta'))).orThrow();\n // Default index: an identical body under a NEW id collapses onto the existing\n // record (knowledge declares `dedupScope: 'content'`).\n expect(await control.put(knowledgeRecord('doc-c', 'hidden beta'))).toSucceedAndSatisfy(\n (record: IMemoryRecord<unknown>) => {\n expect(record.envelope.id).toBe('doc-b');\n }\n );\n\n const hiding = storeWith(HidingMemoryIndex.create().orThrow());\n (await hiding.put(knowledgeRecord('doc-b', 'hidden beta'))).orThrow();\n // Hiding index: doc-b is invisible to `entries()`, so the content-hash lookup\n // finds no duplicate and doc-c is written as a distinct record.\n expect(await hiding.put(knowledgeRecord('doc-c', 'hidden beta'))).toSucceedAndSatisfy(\n (record: IMemoryRecord<unknown>) => {\n expect(record.envelope.id).toBe('doc-c');\n }\n );\n });\n });\n\n describe('injected index — temporal and cap-cull write paths', () => {\n beforeEach(() => {\n clockValue = 1000;\n });\n\n test('the injected index decides which version a versioned put supersedes and a delete tombstones', async () => {\n // Both the versioned put and the versioned delete resolve an entity's version\n // history through `_versionsForEntity`, which is a scope filter over the\n // index's `entries()`. A version the injected index hides is therefore\n // invisible to both — it stays on disk, but the store will not supersede,\n // invalidate, or tombstone it. That is the documented caveat, and the reason\n // only a faithful delegating decorator is safe to inject.\n const control = versionedStore();\n (await control.put(factRecord('hidden blue'))).orThrow();\n clockValue = 2000;\n (await control.put(factRecord('grey'))).orThrow();\n\n // Default index: v1 is visible, so the second put closes its world-truth\n // interval at the new version's `valid_at`.\n expect(await control.getById(factScope, 'fact-1-v1' as MemoryId)).toSucceedAndSatisfy(\n (v1: IMemoryRecord<unknown> | undefined) => {\n expect(v1?.envelope.temporal?.invalid_at).toBe(2000);\n }\n );\n\n const hiding = versionedStore(HidingMemoryIndex.create().orThrow());\n clockValue = 1000;\n (await hiding.put(factRecord('hidden blue'))).orThrow();\n clockValue = 2000;\n (await hiding.put(factRecord('grey'))).orThrow();\n\n // Hiding index: v1 is invisible to the version walk, so the second put sees no\n // current version, is built as a FIRST version, and invalidates nothing. v1 is\n // still on disk and still carries no `invalid_at` — two live currents.\n expect(await hiding.getById(factScope, 'fact-1-v1' as MemoryId)).toSucceedAndSatisfy(\n (v1: IMemoryRecord<unknown> | undefined) => {\n expect(v1?.body).toBe('hidden blue');\n expect(v1?.envelope.temporal?.invalid_at).toBeUndefined();\n }\n );\n\n // The delete half of the same claim: a soft delete tombstones every version the\n // index shows as current, so the hidden v1 survives it untouched.\n clockValue = 3000;\n expect(await hiding.delete(factKind, 'fact-1' as EntityId)).toSucceed();\n expect(await hiding.getById(factScope, 'fact-1-v2' as MemoryId)).toSucceedAndSatisfy(\n (v2: IMemoryRecord<unknown> | undefined) => {\n expect(v2?.envelope.temporal?.invalid_at).toBe(3000);\n }\n );\n expect(await hiding.getById(factScope, 'fact-1-v1' as MemoryId)).toSucceedAndSatisfy(\n (v1: IMemoryRecord<unknown> | undefined) => {\n expect(v1?.envelope.temporal?.invalid_at).toBeUndefined();\n }\n );\n });\n\n test('cap-cull patches the injected index, and a reshaped cohort changes what is evicted', async () => {\n // `maxRecords: 2` over the shared conversations/conv-1 MTM scope. The third\n // write's admission cohort is the two prior records, so it culls the oldest.\n const recording = RecordingMemoryIndex.create().orThrow();\n const recorded = cappedStore(recording);\n for (let turn = 0; turn < 3; turn++) {\n clockValue = 1000 + turn; // distinct `created`, so \"oldest\" is unambiguous\n (await recorded.put(turnRecord(turn, turn === 0 ? 'hidden zero' : `turn ${turn}`))).orThrow();\n }\n\n // The eviction reaches the INJECTED index as a `delete` patch — the store keeps\n // no private index it could have patched instead.\n expect(recording.patchCalls.filter((c) => c.op === 'delete')).toEqual([\n { op: 'delete', scope: 'conversations/conv-1', id: 'turn-0' }\n ]);\n expect(await recorded.get(mtmKind, 'conv-1:0' as EntityId)).toSucceedWith(undefined);\n\n // Same writes, but an index that hides turn-0 shrinks the admission cohort to\n // one, which is under the cap — so nothing is evicted and turn-0 survives.\n // The cohort the policy sees is the index's projection, not the vault's.\n const hidden = cappedStore(HidingMemoryIndex.create().orThrow());\n for (let turn = 0; turn < 3; turn++) {\n clockValue = 1000 + turn;\n (await hidden.put(turnRecord(turn, turn === 0 ? 'hidden zero' : `turn ${turn}`))).orThrow();\n }\n\n expect(await hidden.get(mtmKind, 'conv-1:0' as EntityId)).toSucceedAndSatisfy(\n (record: IMemoryRecord<unknown> | undefined) => {\n expect(record?.body).toBe('hidden zero');\n }\n );\n });\n });\n});\n"]}
@@ -1,2 +0,0 @@
1
- import '@fgv/ts-utils-jest';
2
- //# sourceMappingURL=lenientOpen.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lenientOpen.test.d.ts","sourceRoot":"","sources":["../../../../src/test/unit/store/lenientOpen.test.ts"],"names":[],"mappings":"AAKA,OAAO,oBAAoB,CAAC"}