@fgv/ts-agent-memory 5.1.0-36

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 (331) hide show
  1. package/.rush/temp/chunked-rush-logs/ts-agent-memory.build.chunks.jsonl +9 -0
  2. package/.rush/temp/f6a88bfdd66517ccb98c2c7ae1be6e6fe9e15d38.tar.log +282 -0
  3. package/.rush/temp/operation/build/all.log +9 -0
  4. package/.rush/temp/operation/build/log-chunks.jsonl +9 -0
  5. package/.rush/temp/operation/build/state.json +3 -0
  6. package/.rush/temp/shrinkwrap-deps.json +688 -0
  7. package/LICENSE +21 -0
  8. package/README.md +45 -0
  9. package/config/api-extractor.json +343 -0
  10. package/config/jest.config.json +14 -0
  11. package/config/rig.json +4 -0
  12. package/dist/index.js +12 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/packlets/converters/bodyConverterRegistry.js +51 -0
  15. package/dist/packlets/converters/bodyConverterRegistry.js.map +1 -0
  16. package/dist/packlets/converters/envelopeConverter.js +159 -0
  17. package/dist/packlets/converters/envelopeConverter.js.map +1 -0
  18. package/dist/packlets/converters/index.js +7 -0
  19. package/dist/packlets/converters/index.js.map +1 -0
  20. package/dist/packlets/index/index.js +6 -0
  21. package/dist/packlets/index/index.js.map +1 -0
  22. package/dist/packlets/index/memoryIndex.js +170 -0
  23. package/dist/packlets/index/memoryIndex.js.map +1 -0
  24. package/dist/packlets/observe/index.js +7 -0
  25. package/dist/packlets/observe/index.js.map +1 -0
  26. package/dist/packlets/observe/memoryObservationStore.js +119 -0
  27. package/dist/packlets/observe/memoryObservationStore.js.map +1 -0
  28. package/dist/packlets/observe/observer.js +6 -0
  29. package/dist/packlets/observe/observer.js.map +1 -0
  30. package/dist/packlets/retrieve/hybridRetriever.js +135 -0
  31. package/dist/packlets/retrieve/hybridRetriever.js.map +1 -0
  32. package/dist/packlets/retrieve/index.js +12 -0
  33. package/dist/packlets/retrieve/index.js.map +1 -0
  34. package/dist/packlets/retrieve/linkTraversalRetriever.js +143 -0
  35. package/dist/packlets/retrieve/linkTraversalRetriever.js.map +1 -0
  36. package/dist/packlets/retrieve/recencyRetriever.js +33 -0
  37. package/dist/packlets/retrieve/recencyRetriever.js.map +1 -0
  38. package/dist/packlets/retrieve/retriever.js +110 -0
  39. package/dist/packlets/retrieve/retriever.js.map +1 -0
  40. package/dist/packlets/retrieve/semanticRetriever.js +86 -0
  41. package/dist/packlets/retrieve/semanticRetriever.js.map +1 -0
  42. package/dist/packlets/retrieve/structuredFilterRetriever.js +37 -0
  43. package/dist/packlets/retrieve/structuredFilterRetriever.js.map +1 -0
  44. package/dist/packlets/retrieve/tagRetriever.js +37 -0
  45. package/dist/packlets/retrieve/tagRetriever.js.map +1 -0
  46. package/dist/packlets/store/fileTreeMemoryStore.js +698 -0
  47. package/dist/packlets/store/fileTreeMemoryStore.js.map +1 -0
  48. package/dist/packlets/store/index.js +7 -0
  49. package/dist/packlets/store/index.js.map +1 -0
  50. package/dist/packlets/store/scopeEncoding.js +31 -0
  51. package/dist/packlets/store/scopeEncoding.js.map +1 -0
  52. package/dist/packlets/types/envelope.js +6 -0
  53. package/dist/packlets/types/envelope.js.map +1 -0
  54. package/dist/packlets/types/filenameSafety.js +52 -0
  55. package/dist/packlets/types/filenameSafety.js.map +1 -0
  56. package/dist/packlets/types/identityCodec.js +184 -0
  57. package/dist/packlets/types/identityCodec.js.map +1 -0
  58. package/dist/packlets/types/ids.js +67 -0
  59. package/dist/packlets/types/ids.js.map +1 -0
  60. package/dist/packlets/types/index.js +10 -0
  61. package/dist/packlets/types/index.js.map +1 -0
  62. package/dist/packlets/types/writePolicy.js +263 -0
  63. package/dist/packlets/types/writePolicy.js.map +1 -0
  64. package/dist/packlets/vector/inMemoryCosineIndex.js +150 -0
  65. package/dist/packlets/vector/inMemoryCosineIndex.js.map +1 -0
  66. package/dist/packlets/vector/index.js +7 -0
  67. package/dist/packlets/vector/index.js.map +1 -0
  68. package/dist/packlets/vector/vectorIndex.js +6 -0
  69. package/dist/packlets/vector/vectorIndex.js.map +1 -0
  70. package/dist/test/unit/converters/bodyConverterRegistry.test.js +72 -0
  71. package/dist/test/unit/converters/bodyConverterRegistry.test.js.map +1 -0
  72. package/dist/test/unit/converters/envelopeConverter.test.js +196 -0
  73. package/dist/test/unit/converters/envelopeConverter.test.js.map +1 -0
  74. package/dist/test/unit/index/memoryIndex.test.js +152 -0
  75. package/dist/test/unit/index/memoryIndex.test.js.map +1 -0
  76. package/dist/test/unit/observe/memoryObservationStore.test.js +118 -0
  77. package/dist/test/unit/observe/memoryObservationStore.test.js.map +1 -0
  78. package/dist/test/unit/retrieve/linkTraversalRetriever.test.js +182 -0
  79. package/dist/test/unit/retrieve/linkTraversalRetriever.test.js.map +1 -0
  80. package/dist/test/unit/retrieve/retrievers.test.js +506 -0
  81. package/dist/test/unit/retrieve/retrievers.test.js.map +1 -0
  82. package/dist/test/unit/store/embedOnWrite.test.js +260 -0
  83. package/dist/test/unit/store/embedOnWrite.test.js.map +1 -0
  84. package/dist/test/unit/store/fileTreeMemoryStore.test.js +647 -0
  85. package/dist/test/unit/store/fileTreeMemoryStore.test.js.map +1 -0
  86. package/dist/test/unit/store/observations.test.js +239 -0
  87. package/dist/test/unit/store/observations.test.js.map +1 -0
  88. package/dist/test/unit/store/scopeEncoding.test.js +24 -0
  89. package/dist/test/unit/store/scopeEncoding.test.js.map +1 -0
  90. package/dist/test/unit/types/identityCodec.test.js +187 -0
  91. package/dist/test/unit/types/identityCodec.test.js.map +1 -0
  92. package/dist/test/unit/types/ids.test.js +84 -0
  93. package/dist/test/unit/types/ids.test.js.map +1 -0
  94. package/dist/test/unit/types/writePolicy.test.js +241 -0
  95. package/dist/test/unit/types/writePolicy.test.js.map +1 -0
  96. package/dist/test/unit/vector/inMemoryCosineIndex.test.js +192 -0
  97. package/dist/test/unit/vector/inMemoryCosineIndex.test.js.map +1 -0
  98. package/dist/test/unit/vector/vectorIndex.test.js +42 -0
  99. package/dist/test/unit/vector/vectorIndex.test.js.map +1 -0
  100. package/dist/ts-agent-memory.d.ts +1901 -0
  101. package/dist/tsdoc-metadata.json +11 -0
  102. package/eslint.config.js +15 -0
  103. package/etc/ts-agent-memory.api.md +525 -0
  104. package/lib/index.d.ts +8 -0
  105. package/lib/index.d.ts.map +1 -0
  106. package/lib/index.js +28 -0
  107. package/lib/index.js.map +1 -0
  108. package/lib/packlets/converters/bodyConverterRegistry.d.ts +64 -0
  109. package/lib/packlets/converters/bodyConverterRegistry.d.ts.map +1 -0
  110. package/lib/packlets/converters/bodyConverterRegistry.js +55 -0
  111. package/lib/packlets/converters/bodyConverterRegistry.js.map +1 -0
  112. package/lib/packlets/converters/envelopeConverter.d.ts +70 -0
  113. package/lib/packlets/converters/envelopeConverter.d.ts.map +1 -0
  114. package/lib/packlets/converters/envelopeConverter.js +166 -0
  115. package/lib/packlets/converters/envelopeConverter.js.map +1 -0
  116. package/lib/packlets/converters/index.d.ts +3 -0
  117. package/lib/packlets/converters/index.d.ts.map +1 -0
  118. package/lib/packlets/converters/index.js +23 -0
  119. package/lib/packlets/converters/index.js.map +1 -0
  120. package/lib/packlets/index/index.d.ts +2 -0
  121. package/lib/packlets/index/index.d.ts.map +1 -0
  122. package/lib/packlets/index/index.js +22 -0
  123. package/lib/packlets/index/index.js.map +1 -0
  124. package/lib/packlets/index/memoryIndex.d.ts +127 -0
  125. package/lib/packlets/index/memoryIndex.d.ts.map +1 -0
  126. package/lib/packlets/index/memoryIndex.js +174 -0
  127. package/lib/packlets/index/memoryIndex.js.map +1 -0
  128. package/lib/packlets/observe/index.d.ts +3 -0
  129. package/lib/packlets/observe/index.d.ts.map +1 -0
  130. package/lib/packlets/observe/index.js +23 -0
  131. package/lib/packlets/observe/index.js.map +1 -0
  132. package/lib/packlets/observe/memoryObservationStore.d.ts +91 -0
  133. package/lib/packlets/observe/memoryObservationStore.d.ts.map +1 -0
  134. package/lib/packlets/observe/memoryObservationStore.js +123 -0
  135. package/lib/packlets/observe/memoryObservationStore.js.map +1 -0
  136. package/lib/packlets/observe/observer.d.ts +110 -0
  137. package/lib/packlets/observe/observer.d.ts.map +1 -0
  138. package/lib/packlets/observe/observer.js +7 -0
  139. package/lib/packlets/observe/observer.js.map +1 -0
  140. package/lib/packlets/retrieve/hybridRetriever.d.ts +79 -0
  141. package/lib/packlets/retrieve/hybridRetriever.d.ts.map +1 -0
  142. package/lib/packlets/retrieve/hybridRetriever.js +140 -0
  143. package/lib/packlets/retrieve/hybridRetriever.js.map +1 -0
  144. package/lib/packlets/retrieve/index.d.ts +8 -0
  145. package/lib/packlets/retrieve/index.d.ts.map +1 -0
  146. package/lib/packlets/retrieve/index.js +28 -0
  147. package/lib/packlets/retrieve/index.js.map +1 -0
  148. package/lib/packlets/retrieve/linkTraversalRetriever.d.ts +61 -0
  149. package/lib/packlets/retrieve/linkTraversalRetriever.d.ts.map +1 -0
  150. package/lib/packlets/retrieve/linkTraversalRetriever.js +147 -0
  151. package/lib/packlets/retrieve/linkTraversalRetriever.js.map +1 -0
  152. package/lib/packlets/retrieve/recencyRetriever.d.ts +21 -0
  153. package/lib/packlets/retrieve/recencyRetriever.d.ts.map +1 -0
  154. package/lib/packlets/retrieve/recencyRetriever.js +37 -0
  155. package/lib/packlets/retrieve/recencyRetriever.js.map +1 -0
  156. package/lib/packlets/retrieve/retriever.d.ts +133 -0
  157. package/lib/packlets/retrieve/retriever.d.ts.map +1 -0
  158. package/lib/packlets/retrieve/retriever.js +119 -0
  159. package/lib/packlets/retrieve/retriever.js.map +1 -0
  160. package/lib/packlets/retrieve/semanticRetriever.d.ts +69 -0
  161. package/lib/packlets/retrieve/semanticRetriever.d.ts.map +1 -0
  162. package/lib/packlets/retrieve/semanticRetriever.js +90 -0
  163. package/lib/packlets/retrieve/semanticRetriever.js.map +1 -0
  164. package/lib/packlets/retrieve/structuredFilterRetriever.d.ts +22 -0
  165. package/lib/packlets/retrieve/structuredFilterRetriever.d.ts.map +1 -0
  166. package/lib/packlets/retrieve/structuredFilterRetriever.js +41 -0
  167. package/lib/packlets/retrieve/structuredFilterRetriever.js.map +1 -0
  168. package/lib/packlets/retrieve/tagRetriever.d.ts +22 -0
  169. package/lib/packlets/retrieve/tagRetriever.d.ts.map +1 -0
  170. package/lib/packlets/retrieve/tagRetriever.js +41 -0
  171. package/lib/packlets/retrieve/tagRetriever.js.map +1 -0
  172. package/lib/packlets/store/fileTreeMemoryStore.d.ts +327 -0
  173. package/lib/packlets/store/fileTreeMemoryStore.d.ts.map +1 -0
  174. package/lib/packlets/store/fileTreeMemoryStore.js +702 -0
  175. package/lib/packlets/store/fileTreeMemoryStore.js.map +1 -0
  176. package/lib/packlets/store/index.d.ts +3 -0
  177. package/lib/packlets/store/index.d.ts.map +1 -0
  178. package/lib/packlets/store/index.js +23 -0
  179. package/lib/packlets/store/index.js.map +1 -0
  180. package/lib/packlets/store/scopeEncoding.d.ts +19 -0
  181. package/lib/packlets/store/scopeEncoding.d.ts.map +1 -0
  182. package/lib/packlets/store/scopeEncoding.js +34 -0
  183. package/lib/packlets/store/scopeEncoding.js.map +1 -0
  184. package/lib/packlets/types/envelope.d.ts +119 -0
  185. package/lib/packlets/types/envelope.d.ts.map +1 -0
  186. package/lib/packlets/types/envelope.js +7 -0
  187. package/lib/packlets/types/envelope.js.map +1 -0
  188. package/lib/packlets/types/filenameSafety.d.ts +16 -0
  189. package/lib/packlets/types/filenameSafety.d.ts.map +1 -0
  190. package/lib/packlets/types/filenameSafety.js +55 -0
  191. package/lib/packlets/types/filenameSafety.js.map +1 -0
  192. package/lib/packlets/types/identityCodec.d.ts +136 -0
  193. package/lib/packlets/types/identityCodec.d.ts.map +1 -0
  194. package/lib/packlets/types/identityCodec.js +190 -0
  195. package/lib/packlets/types/identityCodec.js.map +1 -0
  196. package/lib/packlets/types/ids.d.ts +55 -0
  197. package/lib/packlets/types/ids.d.ts.map +1 -0
  198. package/lib/packlets/types/ids.js +70 -0
  199. package/lib/packlets/types/ids.js.map +1 -0
  200. package/lib/packlets/types/index.d.ts +6 -0
  201. package/lib/packlets/types/index.d.ts.map +1 -0
  202. package/lib/packlets/types/index.js +26 -0
  203. package/lib/packlets/types/index.js.map +1 -0
  204. package/lib/packlets/types/writePolicy.d.ts +213 -0
  205. package/lib/packlets/types/writePolicy.d.ts.map +1 -0
  206. package/lib/packlets/types/writePolicy.js +268 -0
  207. package/lib/packlets/types/writePolicy.js.map +1 -0
  208. package/lib/packlets/vector/inMemoryCosineIndex.d.ts +69 -0
  209. package/lib/packlets/vector/inMemoryCosineIndex.d.ts.map +1 -0
  210. package/lib/packlets/vector/inMemoryCosineIndex.js +154 -0
  211. package/lib/packlets/vector/inMemoryCosineIndex.js.map +1 -0
  212. package/lib/packlets/vector/index.d.ts +3 -0
  213. package/lib/packlets/vector/index.d.ts.map +1 -0
  214. package/lib/packlets/vector/index.js +23 -0
  215. package/lib/packlets/vector/index.js.map +1 -0
  216. package/lib/packlets/vector/vectorIndex.d.ts +68 -0
  217. package/lib/packlets/vector/vectorIndex.d.ts.map +1 -0
  218. package/lib/packlets/vector/vectorIndex.js +7 -0
  219. package/lib/packlets/vector/vectorIndex.js.map +1 -0
  220. package/lib/test/unit/converters/bodyConverterRegistry.test.d.ts +2 -0
  221. package/lib/test/unit/converters/bodyConverterRegistry.test.d.ts.map +1 -0
  222. package/lib/test/unit/converters/bodyConverterRegistry.test.js +74 -0
  223. package/lib/test/unit/converters/bodyConverterRegistry.test.js.map +1 -0
  224. package/lib/test/unit/converters/envelopeConverter.test.d.ts +2 -0
  225. package/lib/test/unit/converters/envelopeConverter.test.d.ts.map +1 -0
  226. package/lib/test/unit/converters/envelopeConverter.test.js +198 -0
  227. package/lib/test/unit/converters/envelopeConverter.test.js.map +1 -0
  228. package/lib/test/unit/index/memoryIndex.test.d.ts +2 -0
  229. package/lib/test/unit/index/memoryIndex.test.d.ts.map +1 -0
  230. package/lib/test/unit/index/memoryIndex.test.js +154 -0
  231. package/lib/test/unit/index/memoryIndex.test.js.map +1 -0
  232. package/lib/test/unit/observe/memoryObservationStore.test.d.ts +2 -0
  233. package/lib/test/unit/observe/memoryObservationStore.test.d.ts.map +1 -0
  234. package/lib/test/unit/observe/memoryObservationStore.test.js +120 -0
  235. package/lib/test/unit/observe/memoryObservationStore.test.js.map +1 -0
  236. package/lib/test/unit/retrieve/linkTraversalRetriever.test.d.ts +2 -0
  237. package/lib/test/unit/retrieve/linkTraversalRetriever.test.d.ts.map +1 -0
  238. package/lib/test/unit/retrieve/linkTraversalRetriever.test.js +184 -0
  239. package/lib/test/unit/retrieve/linkTraversalRetriever.test.js.map +1 -0
  240. package/lib/test/unit/retrieve/retrievers.test.d.ts +2 -0
  241. package/lib/test/unit/retrieve/retrievers.test.d.ts.map +1 -0
  242. package/lib/test/unit/retrieve/retrievers.test.js +508 -0
  243. package/lib/test/unit/retrieve/retrievers.test.js.map +1 -0
  244. package/lib/test/unit/store/embedOnWrite.test.d.ts +2 -0
  245. package/lib/test/unit/store/embedOnWrite.test.d.ts.map +1 -0
  246. package/lib/test/unit/store/embedOnWrite.test.js +262 -0
  247. package/lib/test/unit/store/embedOnWrite.test.js.map +1 -0
  248. package/lib/test/unit/store/fileTreeMemoryStore.test.d.ts +2 -0
  249. package/lib/test/unit/store/fileTreeMemoryStore.test.d.ts.map +1 -0
  250. package/lib/test/unit/store/fileTreeMemoryStore.test.js +649 -0
  251. package/lib/test/unit/store/fileTreeMemoryStore.test.js.map +1 -0
  252. package/lib/test/unit/store/observations.test.d.ts +2 -0
  253. package/lib/test/unit/store/observations.test.d.ts.map +1 -0
  254. package/lib/test/unit/store/observations.test.js +241 -0
  255. package/lib/test/unit/store/observations.test.js.map +1 -0
  256. package/lib/test/unit/store/scopeEncoding.test.d.ts +2 -0
  257. package/lib/test/unit/store/scopeEncoding.test.d.ts.map +1 -0
  258. package/lib/test/unit/store/scopeEncoding.test.js +26 -0
  259. package/lib/test/unit/store/scopeEncoding.test.js.map +1 -0
  260. package/lib/test/unit/types/identityCodec.test.d.ts +2 -0
  261. package/lib/test/unit/types/identityCodec.test.d.ts.map +1 -0
  262. package/lib/test/unit/types/identityCodec.test.js +189 -0
  263. package/lib/test/unit/types/identityCodec.test.js.map +1 -0
  264. package/lib/test/unit/types/ids.test.d.ts +2 -0
  265. package/lib/test/unit/types/ids.test.d.ts.map +1 -0
  266. package/lib/test/unit/types/ids.test.js +86 -0
  267. package/lib/test/unit/types/ids.test.js.map +1 -0
  268. package/lib/test/unit/types/writePolicy.test.d.ts +2 -0
  269. package/lib/test/unit/types/writePolicy.test.d.ts.map +1 -0
  270. package/lib/test/unit/types/writePolicy.test.js +243 -0
  271. package/lib/test/unit/types/writePolicy.test.js.map +1 -0
  272. package/lib/test/unit/vector/inMemoryCosineIndex.test.d.ts +2 -0
  273. package/lib/test/unit/vector/inMemoryCosineIndex.test.d.ts.map +1 -0
  274. package/lib/test/unit/vector/inMemoryCosineIndex.test.js +194 -0
  275. package/lib/test/unit/vector/inMemoryCosineIndex.test.js.map +1 -0
  276. package/lib/test/unit/vector/vectorIndex.test.d.ts +2 -0
  277. package/lib/test/unit/vector/vectorIndex.test.d.ts.map +1 -0
  278. package/lib/test/unit/vector/vectorIndex.test.js +44 -0
  279. package/lib/test/unit/vector/vectorIndex.test.js.map +1 -0
  280. package/package.json +81 -0
  281. package/rush-logs/ts-agent-memory.build.cache.log +3 -0
  282. package/rush-logs/ts-agent-memory.build.log +9 -0
  283. package/src/index.ts +12 -0
  284. package/src/packlets/converters/bodyConverterRegistry.ts +105 -0
  285. package/src/packlets/converters/envelopeConverter.ts +210 -0
  286. package/src/packlets/converters/index.ts +7 -0
  287. package/src/packlets/index/index.ts +6 -0
  288. package/src/packlets/index/memoryIndex.ts +268 -0
  289. package/src/packlets/observe/index.ts +7 -0
  290. package/src/packlets/observe/memoryObservationStore.ts +153 -0
  291. package/src/packlets/observe/observer.ts +119 -0
  292. package/src/packlets/retrieve/hybridRetriever.ts +181 -0
  293. package/src/packlets/retrieve/index.ts +12 -0
  294. package/src/packlets/retrieve/linkTraversalRetriever.ts +169 -0
  295. package/src/packlets/retrieve/recencyRetriever.ts +54 -0
  296. package/src/packlets/retrieve/retriever.ts +207 -0
  297. package/src/packlets/retrieve/semanticRetriever.ts +147 -0
  298. package/src/packlets/retrieve/structuredFilterRetriever.ts +58 -0
  299. package/src/packlets/retrieve/tagRetriever.ts +58 -0
  300. package/src/packlets/store/fileTreeMemoryStore.ts +1073 -0
  301. package/src/packlets/store/index.ts +7 -0
  302. package/src/packlets/store/scopeEncoding.ts +36 -0
  303. package/src/packlets/types/envelope.ts +138 -0
  304. package/src/packlets/types/filenameSafety.ts +57 -0
  305. package/src/packlets/types/identityCodec.ts +263 -0
  306. package/src/packlets/types/ids.ts +124 -0
  307. package/src/packlets/types/index.ts +10 -0
  308. package/src/packlets/types/writePolicy.ts +447 -0
  309. package/src/packlets/vector/inMemoryCosineIndex.ts +173 -0
  310. package/src/packlets/vector/index.ts +7 -0
  311. package/src/packlets/vector/vectorIndex.ts +78 -0
  312. package/src/test/unit/converters/bodyConverterRegistry.test.ts +89 -0
  313. package/src/test/unit/converters/envelopeConverter.test.ts +261 -0
  314. package/src/test/unit/index/memoryIndex.test.ts +187 -0
  315. package/src/test/unit/observe/memoryObservationStore.test.ts +158 -0
  316. package/src/test/unit/retrieve/linkTraversalRetriever.test.ts +230 -0
  317. package/src/test/unit/retrieve/retrievers.test.ts +662 -0
  318. package/src/test/unit/store/embedOnWrite.test.ts +346 -0
  319. package/src/test/unit/store/fileTreeMemoryStore.test.ts +875 -0
  320. package/src/test/unit/store/observations.test.ts +290 -0
  321. package/src/test/unit/store/scopeEncoding.test.ts +37 -0
  322. package/src/test/unit/types/identityCodec.test.ts +266 -0
  323. package/src/test/unit/types/ids.test.ts +94 -0
  324. package/src/test/unit/types/writePolicy.test.ts +325 -0
  325. package/src/test/unit/vector/inMemoryCosineIndex.test.ts +242 -0
  326. package/src/test/unit/vector/vectorIndex.test.ts +48 -0
  327. package/temp/build/lint/_eslint-5eVG3S6w.json +182 -0
  328. package/temp/build/typescript/ts_8nwakTlr.json +1 -0
  329. package/temp/ts-agent-memory.api.json +12438 -0
  330. package/temp/ts-agent-memory.api.md +525 -0
  331. package/tsconfig.json +8 -0
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2026 Erik Fortune
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.BodyConverterRegistry = void 0;
8
+ const ts_utils_1 = require("@fgv/ts-utils");
9
+ /**
10
+ * Default in-memory {@link IBodyConverterRegistry}.
11
+ *
12
+ * @remarks
13
+ * Both `register` and `registerSchema` adapt the supplied converter/validator
14
+ * into a `Converter<unknown>` via `Converters.generic`, so the heterogeneous
15
+ * per-kind types are stored uniformly with no cast and no `any`. A
16
+ * `Converter<T>` is not structurally a `Converter<unknown>` (the `map` callback
17
+ * makes the type invariant), so the `generic` wrapper — whose callback returns
18
+ * `Result<T>` (assignable to `Result<unknown>`) — is the type-safe bridge.
19
+ * @public
20
+ */
21
+ class BodyConverterRegistry {
22
+ constructor() {
23
+ this._converters = new Map();
24
+ }
25
+ /** Family-convention factory. */
26
+ static create() {
27
+ return (0, ts_utils_1.succeed)(new BodyConverterRegistry());
28
+ }
29
+ /** {@inheritDoc IBodyConverterRegistry.register} */
30
+ register(kind, converter) {
31
+ this._converters.set(kind, ts_utils_1.Converters.generic((from) => converter.convert(from)));
32
+ }
33
+ /** {@inheritDoc IBodyConverterRegistry.registerSchema} */
34
+ registerSchema(kind, schema) {
35
+ this._converters.set(kind, ts_utils_1.Converters.generic((from) => schema.convert(from)));
36
+ }
37
+ /** {@inheritDoc IBodyConverterRegistry.has} */
38
+ has(kind) {
39
+ return this._converters.has(kind);
40
+ }
41
+ /** {@inheritDoc IBodyConverterRegistry.getConverter} */
42
+ getConverter(kind) {
43
+ const converter = this._converters.get(kind);
44
+ if (converter === undefined) {
45
+ return (0, ts_utils_1.fail)(`no converter registered for kind '${kind}'`);
46
+ }
47
+ return (0, ts_utils_1.succeed)(converter);
48
+ }
49
+ /** {@inheritDoc IBodyConverterRegistry.convert} */
50
+ convert(kind, body) {
51
+ return this.getConverter(kind).onSuccess((converter) => converter.convert(body));
52
+ }
53
+ }
54
+ exports.BodyConverterRegistry = BodyConverterRegistry;
55
+ //# sourceMappingURL=bodyConverterRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bodyConverterRegistry.js","sourceRoot":"","sources":["../../../src/packlets/converters/bodyConverterRegistry.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,4CAA6E;AAyC7E;;;;;;;;;;;GAWG;AACH,MAAa,qBAAqB;IAGhC;QACE,IAAI,CAAC,WAAW,GAAG,IAAI,GAAG,EAA4B,CAAC;IACzD,CAAC;IAED,iCAAiC;IAC1B,MAAM,CAAC,MAAM;QAClB,OAAO,IAAA,kBAAO,EAAC,IAAI,qBAAqB,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED,oDAAoD;IAC7C,QAAQ,CAAI,IAAU,EAAE,SAAuB;QACpD,IAAI,CAAC,WAAW,CAAC,GAAG,CAClB,IAAI,EACJ,qBAAU,CAAC,OAAO,CAAU,CAAC,IAAa,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CACxE,CAAC;IACJ,CAAC;IAED,0DAA0D;IACnD,cAAc,CAAI,IAAU,EAAE,MAAsC;QACzE,IAAI,CAAC,WAAW,CAAC,GAAG,CAClB,IAAI,EACJ,qBAAU,CAAC,OAAO,CAAU,CAAC,IAAa,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CACrE,CAAC;IACJ,CAAC;IAED,+CAA+C;IACxC,GAAG,CAAC,IAAU;QACnB,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,wDAAwD;IACjD,YAAY,CAAC,IAAU;QAC5B,MAAM,SAAS,GAAmC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC7E,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5B,OAAO,IAAA,eAAI,EAAC,qCAAqC,IAAI,GAAG,CAAC,CAAC;QAC5D,CAAC;QACD,OAAO,IAAA,kBAAO,EAAC,SAAS,CAAC,CAAC;IAC5B,CAAC;IAED,mDAAmD;IAC5C,OAAO,CAAC,IAAU,EAAE,IAAa;QACtC,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IACnF,CAAC;CACF;AA9CD,sDA8CC","sourcesContent":["/*\n * Copyright (c) 2026 Erik Fortune\n * SPDX-License-Identifier: MIT\n */\n\nimport { Converter, Converters, Result, fail, succeed } from '@fgv/ts-utils';\nimport { JsonSchema } from '@fgv/ts-json-base';\nimport { Kind } from '../types';\n\n/**\n * Registry of per-kind body Converters. Each memory {@link Kind} registers the\n * validated shape of its body; the store dispatches an `unknown` body through\n * the registered Converter on every write. Type-safe — no `any`.\n * @public\n */\nexport interface IBodyConverterRegistry {\n /**\n * Register a Converter for a kind. Replaces any prior registration for the\n * same kind.\n */\n register<T>(kind: Kind, converter: Converter<T>): void;\n\n /**\n * Register a `JsonSchema` validator (from `@fgv/ts-json-base`) for a kind —\n * the schema IS a Validator. Replaces any prior registration for the same\n * kind.\n */\n registerSchema<T>(kind: Kind, schema: JsonSchema.ISchemaValidator<T>): void;\n\n /** Returns `true` if a converter is registered for the kind. */\n has(kind: Kind): boolean;\n\n /**\n * Get the raw converter registered for a kind. Fails if the kind is\n * unregistered. Exposed for implementors that need to re-validate a patched\n * body (e.g. a temporal-versioned policy's `applyUpdate`).\n */\n getConverter(kind: Kind): Result<Converter<unknown>>;\n\n /**\n * Convert an `unknown` body value for the given kind. Fails with\n * `no converter registered for kind '<k>'` when unregistered.\n */\n convert(kind: Kind, body: unknown): Result<unknown>;\n}\n\n/**\n * Default in-memory {@link IBodyConverterRegistry}.\n *\n * @remarks\n * Both `register` and `registerSchema` adapt the supplied converter/validator\n * into a `Converter<unknown>` via `Converters.generic`, so the heterogeneous\n * per-kind types are stored uniformly with no cast and no `any`. A\n * `Converter<T>` is not structurally a `Converter<unknown>` (the `map` callback\n * makes the type invariant), so the `generic` wrapper — whose callback returns\n * `Result<T>` (assignable to `Result<unknown>`) — is the type-safe bridge.\n * @public\n */\nexport class BodyConverterRegistry implements IBodyConverterRegistry {\n private readonly _converters: Map<Kind, Converter<unknown>>;\n\n private constructor() {\n this._converters = new Map<Kind, Converter<unknown>>();\n }\n\n /** Family-convention factory. */\n public static create(): Result<BodyConverterRegistry> {\n return succeed(new BodyConverterRegistry());\n }\n\n /** {@inheritDoc IBodyConverterRegistry.register} */\n public register<T>(kind: Kind, converter: Converter<T>): void {\n this._converters.set(\n kind,\n Converters.generic<unknown>((from: unknown) => converter.convert(from))\n );\n }\n\n /** {@inheritDoc IBodyConverterRegistry.registerSchema} */\n public registerSchema<T>(kind: Kind, schema: JsonSchema.ISchemaValidator<T>): void {\n this._converters.set(\n kind,\n Converters.generic<unknown>((from: unknown) => schema.convert(from))\n );\n }\n\n /** {@inheritDoc IBodyConverterRegistry.has} */\n public has(kind: Kind): boolean {\n return this._converters.has(kind);\n }\n\n /** {@inheritDoc IBodyConverterRegistry.getConverter} */\n public getConverter(kind: Kind): Result<Converter<unknown>> {\n const converter: Converter<unknown> | undefined = this._converters.get(kind);\n if (converter === undefined) {\n return fail(`no converter registered for kind '${kind}'`);\n }\n return succeed(converter);\n }\n\n /** {@inheritDoc IBodyConverterRegistry.convert} */\n public convert(kind: Kind, body: unknown): Result<unknown> {\n return this.getConverter(kind).onSuccess((converter) => converter.convert(body));\n }\n}\n"]}
@@ -0,0 +1,70 @@
1
+ import { Converter, Result } from '@fgv/ts-utils';
2
+ import { IEdge, IMemoryEnvelope, IMemoryRecord, IProvenance, ITemporalBlock } from '../types';
3
+ import { IBodyConverterRegistry } from './bodyConverterRegistry';
4
+ /**
5
+ * Converter for {@link IProvenance}. Validates the known fields and preserves
6
+ * any extension keys verbatim (the `[key: string]: unknown` opaque payload),
7
+ * so a round-trip never drops consumer-attached data.
8
+ * @public
9
+ */
10
+ export declare const provenanceConverter: Converter<IProvenance>;
11
+ /**
12
+ * Converter for an attributed {@link IEdge}.
13
+ * @public
14
+ */
15
+ export declare const edgeConverter: Converter<IEdge>;
16
+ /**
17
+ * Converter for the optional {@link ITemporalBlock}.
18
+ * @public
19
+ */
20
+ export declare const temporalConverter: Converter<ITemporalBlock>;
21
+ /**
22
+ * Converter for the invariant {@link IMemoryEnvelope}. Validates a plain
23
+ * object (e.g. parsed YAML frontmatter) into a typed envelope.
24
+ * @public
25
+ */
26
+ export declare const envelopeConverter: Converter<IMemoryEnvelope>;
27
+ /**
28
+ * Converter that parses a YAML frontmatter string into an
29
+ * {@link IMemoryEnvelope}.
30
+ * @public
31
+ */
32
+ export declare const envelopeYamlConverter: Converter<IMemoryEnvelope>;
33
+ /**
34
+ * The two parts of a memory file: the YAML frontmatter (between the `---`
35
+ * delimiters) and the markdown body (everything after the closing delimiter).
36
+ * @public
37
+ */
38
+ export interface IMemoryFileParts {
39
+ /** The raw YAML frontmatter (delimiters stripped). */
40
+ readonly frontmatter: string;
41
+ /** The raw body text following the closing delimiter. */
42
+ readonly body: string;
43
+ }
44
+ /**
45
+ * Split a `---\n<yaml>\n---\n<body>` memory file into its frontmatter and
46
+ * body parts. Pure string handling — no external dependency.
47
+ * @public
48
+ */
49
+ export declare function splitFrontmatter(raw: string): Result<IMemoryFileParts>;
50
+ /**
51
+ * Join a YAML frontmatter string and a body into the canonical
52
+ * `---\n<yaml>\n---\n<body>` memory-file format.
53
+ * @public
54
+ */
55
+ export declare function joinFrontmatter(frontmatter: string, body: string): string;
56
+ /**
57
+ * Parse a complete memory file into a typed {@link IMemoryRecord}. Splits the
58
+ * frontmatter, validates the envelope, and dispatches the body through the
59
+ * registered Converter for the envelope's kind.
60
+ * @public
61
+ */
62
+ export declare function parseMemoryFile(raw: string, registry: IBodyConverterRegistry): Result<IMemoryRecord<unknown>>;
63
+ /**
64
+ * Serialize an envelope and its rendered body text into a memory file. The
65
+ * envelope is emitted as YAML frontmatter; the body is written verbatim after
66
+ * the closing delimiter.
67
+ * @public
68
+ */
69
+ export declare function serializeMemoryFile(envelope: IMemoryEnvelope, body: string): Result<string>;
70
+ //# sourceMappingURL=envelopeConverter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envelopeConverter.d.ts","sourceRoot":"","sources":["../../../src/packlets/converters/envelopeConverter.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAc,MAAM,EAAiB,MAAM,eAAe,CAAC;AAE7E,OAAO,EAAW,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACvG,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAqCjE;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,SAAS,CAAC,WAAW,CAUtD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,SAAS,CAAC,KAAK,CAU1C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,SAAS,CAAC,cAAc,CAMvD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,SAAS,CAAC,eAAe,CAgBxD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,EAAE,SAAS,CAAC,eAAe,CAAyC,CAAC;AAKvG;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,sDAAsD;IACtD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,yDAAyD;IACzD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAuBtE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAGzE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,sBAAsB,GAC/B,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAYhC;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAI3F"}
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2026 Erik Fortune
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.envelopeYamlConverter = exports.envelopeConverter = exports.temporalConverter = exports.edgeConverter = exports.provenanceConverter = void 0;
8
+ exports.splitFrontmatter = splitFrontmatter;
9
+ exports.joinFrontmatter = joinFrontmatter;
10
+ exports.parseMemoryFile = parseMemoryFile;
11
+ exports.serializeMemoryFile = serializeMemoryFile;
12
+ const ts_utils_1 = require("@fgv/ts-utils");
13
+ const ts_extras_1 = require("@fgv/ts-extras");
14
+ const types_1 = require("../types");
15
+ /** Matches exactly the JSON `null` literal. */
16
+ // eslint-disable-next-line @rushstack/no-new-null -- the envelope nullable fields (invalid_at, embeddingRef) carry meaningful null; design-lock §2.3-2.5
17
+ const nullConverter = ts_utils_1.Converters.generic((from) => from === null ? (0, ts_utils_1.succeed)(null) : (0, ts_utils_1.fail)('expected null'));
18
+ /** A nullable epoch-ms value (`number | null`). */
19
+ // eslint-disable-next-line @rushstack/no-new-null -- meaningful null for IEdge/ITemporalBlock.invalid_at; design-lock §2.3-2.4
20
+ const numberOrNull = ts_utils_1.Converters.oneOf([
21
+ ts_utils_1.Converters.number,
22
+ nullConverter
23
+ ]);
24
+ /** A nullable string value (`string | null`). */
25
+ // eslint-disable-next-line @rushstack/no-new-null -- meaningful null for IMemoryEnvelope.embeddingRef; design-lock §2.5
26
+ const stringOrNull = ts_utils_1.Converters.oneOf([
27
+ ts_utils_1.Converters.string,
28
+ nullConverter
29
+ ]);
30
+ /**
31
+ * Converter for the known {@link IProvenance} fields. The full
32
+ * {@link provenanceConverter} layers extension-key preservation on top.
33
+ */
34
+ const knownProvenanceConverter = ts_utils_1.Converters.object({
35
+ source: ts_utils_1.Converters.string,
36
+ by: ts_utils_1.Converters.string.optional(),
37
+ model: ts_utils_1.Converters.string.optional(),
38
+ confidence: ts_utils_1.Converters.number.optional(),
39
+ derivedFrom: types_1.Convert.memoryId.optional()
40
+ }, { optionalFields: ['by', 'model', 'confidence', 'derivedFrom'] });
41
+ /**
42
+ * Converter for {@link IProvenance}. Validates the known fields and preserves
43
+ * any extension keys verbatim (the `[key: string]: unknown` opaque payload),
44
+ * so a round-trip never drops consumer-attached data.
45
+ * @public
46
+ */
47
+ exports.provenanceConverter = ts_utils_1.Converters.generic((from) => knownProvenanceConverter.convert(from).onSuccess((known) => {
48
+ // `from` is guaranteed to be a non-null object here — the known-field
49
+ // converter only succeeds on objects. Spread the original keys first,
50
+ // then the validated/normalized known fields on top, so extension keys
51
+ // survive while the known fields carry their converted values.
52
+ const merged = Object.assign(Object.assign({}, from), known);
53
+ return (0, ts_utils_1.succeed)(merged);
54
+ }));
55
+ /**
56
+ * Converter for an attributed {@link IEdge}.
57
+ * @public
58
+ */
59
+ exports.edgeConverter = ts_utils_1.Converters.object({
60
+ type: types_1.Convert.linkType,
61
+ target: types_1.Convert.memoryId,
62
+ confidence: ts_utils_1.Converters.number.optional(),
63
+ provenance: exports.provenanceConverter.optional(),
64
+ valid_at: ts_utils_1.Converters.number.optional(),
65
+ invalid_at: numberOrNull.optional()
66
+ }, { optionalFields: ['confidence', 'provenance', 'valid_at', 'invalid_at'] });
67
+ /**
68
+ * Converter for the optional {@link ITemporalBlock}.
69
+ * @public
70
+ */
71
+ exports.temporalConverter = ts_utils_1.Converters.object({
72
+ valid_at: ts_utils_1.Converters.number.optional(),
73
+ invalid_at: numberOrNull.optional()
74
+ }, { optionalFields: ['valid_at', 'invalid_at'] });
75
+ /**
76
+ * Converter for the invariant {@link IMemoryEnvelope}. Validates a plain
77
+ * object (e.g. parsed YAML frontmatter) into a typed envelope.
78
+ * @public
79
+ */
80
+ exports.envelopeConverter = ts_utils_1.Converters.object({
81
+ id: types_1.Convert.memoryId,
82
+ entityId: types_1.Convert.entityId,
83
+ kind: types_1.Convert.kind,
84
+ tags: ts_utils_1.Converters.arrayOf(types_1.Convert.tag),
85
+ links: ts_utils_1.Converters.arrayOf(exports.edgeConverter),
86
+ created: ts_utils_1.Converters.number,
87
+ updated: ts_utils_1.Converters.number,
88
+ seq: ts_utils_1.Converters.number,
89
+ contentHash: ts_utils_1.Converters.string,
90
+ provenance: exports.provenanceConverter,
91
+ temporal: exports.temporalConverter.optional(),
92
+ embeddingRef: stringOrNull.optional()
93
+ }, { optionalFields: ['temporal', 'embeddingRef'] });
94
+ /**
95
+ * Converter that parses a YAML frontmatter string into an
96
+ * {@link IMemoryEnvelope}.
97
+ * @public
98
+ */
99
+ exports.envelopeYamlConverter = ts_extras_1.Yaml.yamlConverter(exports.envelopeConverter);
100
+ /** The frontmatter delimiter line. */
101
+ const FRONTMATTER_DELIMITER = '---';
102
+ /**
103
+ * Split a `---\n<yaml>\n---\n<body>` memory file into its frontmatter and
104
+ * body parts. Pure string handling — no external dependency.
105
+ * @public
106
+ */
107
+ function splitFrontmatter(raw) {
108
+ // Split on '\n' and strip a trailing '\r' per line so CRLF-authored files
109
+ // parse identically to LF — otherwise the '\r' would ride along into the
110
+ // returned frontmatter (perturbing YAML parsing) and body (corrupting
111
+ // round-trip fidelity).
112
+ const lines = raw.split('\n').map((line) => (line.endsWith('\r') ? line.slice(0, -1) : line));
113
+ if (lines[0].trim() !== FRONTMATTER_DELIMITER) {
114
+ return (0, ts_utils_1.fail)("memory file: missing opening frontmatter delimiter '---'");
115
+ }
116
+ let closeIndex = -1;
117
+ for (let i = 1; i < lines.length; i++) {
118
+ if (lines[i].trim() === FRONTMATTER_DELIMITER) {
119
+ closeIndex = i;
120
+ break;
121
+ }
122
+ }
123
+ if (closeIndex === -1) {
124
+ return (0, ts_utils_1.fail)("memory file: missing closing frontmatter delimiter '---'");
125
+ }
126
+ return (0, ts_utils_1.succeed)({
127
+ frontmatter: lines.slice(1, closeIndex).join('\n'),
128
+ body: lines.slice(closeIndex + 1).join('\n')
129
+ });
130
+ }
131
+ /**
132
+ * Join a YAML frontmatter string and a body into the canonical
133
+ * `---\n<yaml>\n---\n<body>` memory-file format.
134
+ * @public
135
+ */
136
+ function joinFrontmatter(frontmatter, body) {
137
+ const normalized = frontmatter.endsWith('\n') ? frontmatter : `${frontmatter}\n`;
138
+ return `${FRONTMATTER_DELIMITER}\n${normalized}${FRONTMATTER_DELIMITER}\n${body}`;
139
+ }
140
+ /**
141
+ * Parse a complete memory file into a typed {@link IMemoryRecord}. Splits the
142
+ * frontmatter, validates the envelope, and dispatches the body through the
143
+ * registered Converter for the envelope's kind.
144
+ * @public
145
+ */
146
+ function parseMemoryFile(raw, registry) {
147
+ return splitFrontmatter(raw).onSuccess((parts) => exports.envelopeYamlConverter
148
+ .convert(parts.frontmatter)
149
+ .withErrorFormat((msg) => `memory file: invalid envelope: ${msg}`)
150
+ .onSuccess((envelope) => registry
151
+ .convert(envelope.kind, parts.body)
152
+ .withErrorFormat((msg) => `memory file '${envelope.id}': invalid body: ${msg}`)
153
+ .onSuccess((body) => (0, ts_utils_1.succeed)({ envelope, body }))));
154
+ }
155
+ /**
156
+ * Serialize an envelope and its rendered body text into a memory file. The
157
+ * envelope is emitted as YAML frontmatter; the body is written verbatim after
158
+ * the closing delimiter.
159
+ * @public
160
+ */
161
+ function serializeMemoryFile(envelope, body) {
162
+ return ts_extras_1.Yaml.yamlStringify(envelope)
163
+ .withErrorFormat((msg) => `memory file '${envelope.id}': failed to serialize envelope: ${msg}`)
164
+ .onSuccess((frontmatter) => (0, ts_utils_1.succeed)(joinFrontmatter(frontmatter, body)));
165
+ }
166
+ //# sourceMappingURL=envelopeConverter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envelopeConverter.js","sourceRoot":"","sources":["../../../src/packlets/converters/envelopeConverter.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AA0IH,4CAuBC;AAOD,0CAGC;AAQD,0CAeC;AAQD,kDAIC;AA5MD,4CAA6E;AAC7E,8CAAsC;AACtC,oCAAuG;AAGvG,+CAA+C;AAC/C,yJAAyJ;AACzJ,MAAM,aAAa,GAAoB,qBAAU,CAAC,OAAO,CAAO,CAAC,IAAa,EAAE,EAAE,CAChF,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,IAAA,kBAAO,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAA,eAAI,EAAC,eAAe,CAAC,CACtD,CAAC;AAEF,mDAAmD;AACnD,+HAA+H;AAC/H,MAAM,YAAY,GAA6B,qBAAU,CAAC,KAAK,CAAgB;IAC7E,qBAAU,CAAC,MAAM;IACjB,aAAa;CACd,CAAC,CAAC;AAEH,iDAAiD;AACjD,wHAAwH;AACxH,MAAM,YAAY,GAA6B,qBAAU,CAAC,KAAK,CAAgB;IAC7E,qBAAU,CAAC,MAAM;IACjB,aAAa;CACd,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,wBAAwB,GAA2B,qBAAU,CAAC,MAAM,CACxE;IACE,MAAM,EAAE,qBAAU,CAAC,MAAM;IACzB,EAAE,EAAE,qBAAU,CAAC,MAAM,CAAC,QAAQ,EAAE;IAChC,KAAK,EAAE,qBAAU,CAAC,MAAM,CAAC,QAAQ,EAAE;IACnC,UAAU,EAAE,qBAAU,CAAC,MAAM,CAAC,QAAQ,EAAE;IACxC,WAAW,EAAE,eAAO,CAAC,QAAQ,CAAC,QAAQ,EAA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AS,CAAC,CAAC,QAAQ,EAAE,EAAE,CACtB,QAAQ;SACL,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC;SAClC,eAAe,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,gBAAgB,QAAQ,CAAC,EAAE,oBAAoB,GAAG,EAAE,CAAC;SAC9E,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,kBAAO,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CACpD,CACJ,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,QAAyB,EAAE,IAAY;IACzE,OAAO,gBAAI,CAAC,aAAa,CAAC,QAAQ,CAAC;SAChC,eAAe,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,gBAAgB,QAAQ,CAAC,EAAE,oCAAoC,GAAG,EAAE,CAAC;SAC9F,SAAS,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,IAAA,kBAAO,EAAC,eAAe,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AAC7E,CAAC","sourcesContent":["/*\n * Copyright (c) 2026 Erik Fortune\n * SPDX-License-Identifier: MIT\n */\n\nimport { Converter, Converters, Result, fail, succeed } from '@fgv/ts-utils';\nimport { Yaml } from '@fgv/ts-extras';\nimport { Convert, IEdge, IMemoryEnvelope, IMemoryRecord, IProvenance, ITemporalBlock } from '../types';\nimport { IBodyConverterRegistry } from './bodyConverterRegistry';\n\n/** Matches exactly the JSON `null` literal. */\n// eslint-disable-next-line @rushstack/no-new-null -- the envelope nullable fields (invalid_at, embeddingRef) carry meaningful null; design-lock §2.3-2.5\nconst nullConverter: Converter<null> = Converters.generic<null>((from: unknown) =>\n from === null ? succeed(null) : fail('expected null')\n);\n\n/** A nullable epoch-ms value (`number | null`). */\n// eslint-disable-next-line @rushstack/no-new-null -- meaningful null for IEdge/ITemporalBlock.invalid_at; design-lock §2.3-2.4\nconst numberOrNull: Converter<number | null> = Converters.oneOf<number | null>([\n Converters.number,\n nullConverter\n]);\n\n/** A nullable string value (`string | null`). */\n// eslint-disable-next-line @rushstack/no-new-null -- meaningful null for IMemoryEnvelope.embeddingRef; design-lock §2.5\nconst stringOrNull: Converter<string | null> = Converters.oneOf<string | null>([\n Converters.string,\n nullConverter\n]);\n\n/**\n * Converter for the known {@link IProvenance} fields. The full\n * {@link provenanceConverter} layers extension-key preservation on top.\n */\nconst knownProvenanceConverter: Converter<IProvenance> = Converters.object<IProvenance>(\n {\n source: Converters.string,\n by: Converters.string.optional(),\n model: Converters.string.optional(),\n confidence: Converters.number.optional(),\n derivedFrom: Convert.memoryId.optional()\n },\n { optionalFields: ['by', 'model', 'confidence', 'derivedFrom'] }\n);\n\n/**\n * Converter for {@link IProvenance}. Validates the known fields and preserves\n * any extension keys verbatim (the `[key: string]: unknown` opaque payload),\n * so a round-trip never drops consumer-attached data.\n * @public\n */\nexport const provenanceConverter: Converter<IProvenance> = Converters.generic<IProvenance>(\n (from: unknown): Result<IProvenance> =>\n knownProvenanceConverter.convert(from).onSuccess((known) => {\n // `from` is guaranteed to be a non-null object here — the known-field\n // converter only succeeds on objects. Spread the original keys first,\n // then the validated/normalized known fields on top, so extension keys\n // survive while the known fields carry their converted values.\n const merged: IProvenance = { ...(from as Record<string, unknown>), ...known };\n return succeed(merged);\n })\n);\n\n/**\n * Converter for an attributed {@link IEdge}.\n * @public\n */\nexport const edgeConverter: Converter<IEdge> = Converters.object<IEdge>(\n {\n type: Convert.linkType,\n target: Convert.memoryId,\n confidence: Converters.number.optional(),\n provenance: provenanceConverter.optional(),\n valid_at: Converters.number.optional(),\n invalid_at: numberOrNull.optional()\n },\n { optionalFields: ['confidence', 'provenance', 'valid_at', 'invalid_at'] }\n);\n\n/**\n * Converter for the optional {@link ITemporalBlock}.\n * @public\n */\nexport const temporalConverter: Converter<ITemporalBlock> = Converters.object<ITemporalBlock>(\n {\n valid_at: Converters.number.optional(),\n invalid_at: numberOrNull.optional()\n },\n { optionalFields: ['valid_at', 'invalid_at'] }\n);\n\n/**\n * Converter for the invariant {@link IMemoryEnvelope}. Validates a plain\n * object (e.g. parsed YAML frontmatter) into a typed envelope.\n * @public\n */\nexport const envelopeConverter: Converter<IMemoryEnvelope> = Converters.object<IMemoryEnvelope>(\n {\n id: Convert.memoryId,\n entityId: Convert.entityId,\n kind: Convert.kind,\n tags: Converters.arrayOf(Convert.tag),\n links: Converters.arrayOf(edgeConverter),\n created: Converters.number,\n updated: Converters.number,\n seq: Converters.number,\n contentHash: Converters.string,\n provenance: provenanceConverter,\n temporal: temporalConverter.optional(),\n embeddingRef: stringOrNull.optional()\n },\n { optionalFields: ['temporal', 'embeddingRef'] }\n);\n\n/**\n * Converter that parses a YAML frontmatter string into an\n * {@link IMemoryEnvelope}.\n * @public\n */\nexport const envelopeYamlConverter: Converter<IMemoryEnvelope> = Yaml.yamlConverter(envelopeConverter);\n\n/** The frontmatter delimiter line. */\nconst FRONTMATTER_DELIMITER: string = '---';\n\n/**\n * The two parts of a memory file: the YAML frontmatter (between the `---`\n * delimiters) and the markdown body (everything after the closing delimiter).\n * @public\n */\nexport interface IMemoryFileParts {\n /** The raw YAML frontmatter (delimiters stripped). */\n readonly frontmatter: string;\n /** The raw body text following the closing delimiter. */\n readonly body: string;\n}\n\n/**\n * Split a `---\\n<yaml>\\n---\\n<body>` memory file into its frontmatter and\n * body parts. Pure string handling — no external dependency.\n * @public\n */\nexport function splitFrontmatter(raw: string): Result<IMemoryFileParts> {\n // Split on '\\n' and strip a trailing '\\r' per line so CRLF-authored files\n // parse identically to LF — otherwise the '\\r' would ride along into the\n // returned frontmatter (perturbing YAML parsing) and body (corrupting\n // round-trip fidelity).\n const lines: string[] = raw.split('\\n').map((line) => (line.endsWith('\\r') ? line.slice(0, -1) : line));\n if (lines[0].trim() !== FRONTMATTER_DELIMITER) {\n return fail(\"memory file: missing opening frontmatter delimiter '---'\");\n }\n let closeIndex: number = -1;\n for (let i = 1; i < lines.length; i++) {\n if (lines[i].trim() === FRONTMATTER_DELIMITER) {\n closeIndex = i;\n break;\n }\n }\n if (closeIndex === -1) {\n return fail(\"memory file: missing closing frontmatter delimiter '---'\");\n }\n return succeed({\n frontmatter: lines.slice(1, closeIndex).join('\\n'),\n body: lines.slice(closeIndex + 1).join('\\n')\n });\n}\n\n/**\n * Join a YAML frontmatter string and a body into the canonical\n * `---\\n<yaml>\\n---\\n<body>` memory-file format.\n * @public\n */\nexport function joinFrontmatter(frontmatter: string, body: string): string {\n const normalized: string = frontmatter.endsWith('\\n') ? frontmatter : `${frontmatter}\\n`;\n return `${FRONTMATTER_DELIMITER}\\n${normalized}${FRONTMATTER_DELIMITER}\\n${body}`;\n}\n\n/**\n * Parse a complete memory file into a typed {@link IMemoryRecord}. Splits the\n * frontmatter, validates the envelope, and dispatches the body through the\n * registered Converter for the envelope's kind.\n * @public\n */\nexport function parseMemoryFile(\n raw: string,\n registry: IBodyConverterRegistry\n): Result<IMemoryRecord<unknown>> {\n return splitFrontmatter(raw).onSuccess((parts) =>\n envelopeYamlConverter\n .convert(parts.frontmatter)\n .withErrorFormat((msg) => `memory file: invalid envelope: ${msg}`)\n .onSuccess((envelope) =>\n registry\n .convert(envelope.kind, parts.body)\n .withErrorFormat((msg) => `memory file '${envelope.id}': invalid body: ${msg}`)\n .onSuccess((body) => succeed({ envelope, body }))\n )\n );\n}\n\n/**\n * Serialize an envelope and its rendered body text into a memory file. The\n * envelope is emitted as YAML frontmatter; the body is written verbatim after\n * the closing delimiter.\n * @public\n */\nexport function serializeMemoryFile(envelope: IMemoryEnvelope, body: string): Result<string> {\n return Yaml.yamlStringify(envelope)\n .withErrorFormat((msg) => `memory file '${envelope.id}': failed to serialize envelope: ${msg}`)\n .onSuccess((frontmatter) => succeed(joinFrontmatter(frontmatter, body)));\n}\n"]}
@@ -0,0 +1,3 @@
1
+ export * from './bodyConverterRegistry';
2
+ export * from './envelopeConverter';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/converters/index.ts"],"names":[],"mappings":"AAKA,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2026 Erik Fortune
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
18
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ __exportStar(require("./bodyConverterRegistry"), exports);
22
+ __exportStar(require("./envelopeConverter"), exports);
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/converters/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;AAEH,0DAAwC;AACxC,sDAAoC","sourcesContent":["/*\n * Copyright (c) 2026 Erik Fortune\n * SPDX-License-Identifier: MIT\n */\n\nexport * from './bodyConverterRegistry';\nexport * from './envelopeConverter';\n"]}
@@ -0,0 +1,2 @@
1
+ export * from './memoryIndex';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/index/index.ts"],"names":[],"mappings":"AAKA,cAAc,eAAe,CAAC"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2026 Erik Fortune
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
18
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ __exportStar(require("./memoryIndex"), exports);
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/index/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;AAEH,gDAA8B","sourcesContent":["/*\n * Copyright (c) 2026 Erik Fortune\n * SPDX-License-Identifier: MIT\n */\n\nexport * from './memoryIndex';\n"]}
@@ -0,0 +1,127 @@
1
+ import { Result } from '@fgv/ts-utils';
2
+ import { IMemoryRecord, Kind, MemoryId, MemoryScopeKey, Tag } from '../types';
3
+ /**
4
+ * The mutation a {@link IMemoryIndex.patch | patch} applies: a record was
5
+ * written (`'put'`) or removed (`'delete'`).
6
+ * @public
7
+ */
8
+ export type MemoryIndexPatchOp = 'put' | 'delete';
9
+ /**
10
+ * A memory record paired with the {@link MemoryScopeKey | scope} it lives
11
+ * under. The scope is not carried on the {@link IMemoryEnvelope} (it is derived
12
+ * from the entity id by the codec), so the store threads it alongside the
13
+ * record when patching or rebuilding the index. The `(scope, id)` pair is the
14
+ * index's primary key, keeping records distinct across scopes that reuse a
15
+ * filename stem (e.g. `turn-0` under different conversations in Phase C).
16
+ * @public
17
+ */
18
+ export interface IIndexedMemoryRecord {
19
+ /** The scope the record is stored under. */
20
+ readonly scope: MemoryScopeKey;
21
+ /** The memory record itself. */
22
+ readonly record: IMemoryRecord<unknown>;
23
+ }
24
+ /**
25
+ * The derived, in-memory secondary indexes the store maintains over its
26
+ * records. Never the source of truth — the FileTree is. The index is fully
27
+ * rebuildable from a walk of the store ({@link IMemoryIndex.rebuild}) and is
28
+ * patched incrementally on every write ({@link IMemoryIndex.patch}).
29
+ *
30
+ * @remarks
31
+ * B1 builds the maps; link-traversal BFS over {@link IMemoryIndex.backlinks}
32
+ * is B2. The accessors return records (not bare ids) so the B2 retrievers can
33
+ * consume them directly.
34
+ * @public
35
+ */
36
+ export interface IMemoryIndex {
37
+ /**
38
+ * Replace the entire index from a full set of records (a store walk).
39
+ * @returns The number of records indexed.
40
+ */
41
+ rebuild(entries: ReadonlyArray<IIndexedMemoryRecord>): Result<number>;
42
+ /**
43
+ * Apply a single incremental change. `'put'` inserts or replaces the entry
44
+ * at its `(scope, id)` key (removing any prior associations first); `'delete'`
45
+ * removes it.
46
+ * @returns The entry that was applied.
47
+ */
48
+ patch(op: MemoryIndexPatchOp, entry: IIndexedMemoryRecord): Result<IIndexedMemoryRecord>;
49
+ /** Every indexed entry (scope + record). Primary read surface for the store. */
50
+ entries(): ReadonlyArray<IIndexedMemoryRecord>;
51
+ /** Records of the given kind, in recency order (most-recently-updated first). */
52
+ byKind(kind: Kind): ReadonlyArray<IMemoryRecord<unknown>>;
53
+ /** Records carrying the given tag, in recency order. */
54
+ byTag(tag: Tag): ReadonlyArray<IMemoryRecord<unknown>>;
55
+ /** All records in recency order (most-recently-updated first). */
56
+ byRecency(): ReadonlyArray<IMemoryRecord<unknown>>;
57
+ /**
58
+ * The ids of records whose `links` point AT `target` (inbound edges).
59
+ * The seed map for B2 link-traversal.
60
+ */
61
+ backlinks(target: MemoryId): ReadonlyArray<MemoryId>;
62
+ }
63
+ /**
64
+ * Default in-memory {@link IMemoryIndex}. Maintains the derived `byKind` /
65
+ * `byTag` / `byRecency` / `backlinks` views incrementally; a `'put'` for an
66
+ * already-indexed key first removes the prior entry's associations so a changed
67
+ * kind / tag / link set never leaves a stale reference behind.
68
+ * @public
69
+ */
70
+ export declare class MemoryIndex implements IMemoryIndex {
71
+ /** Primary store: `(scope, id)` composite key → indexed entry. */
72
+ private readonly _byKey;
73
+ /** kind → set of composite keys. */
74
+ private readonly _byKind;
75
+ /** tag → set of composite keys. */
76
+ private readonly _byTag;
77
+ /**
78
+ * link target id → (source composite key → source id). Keyed by the source's
79
+ * `(scope, id)` composite — NOT its bare id — so two distinct source records
80
+ * that share an id across scopes (e.g. `turn-0` in different conversations)
81
+ * are tracked independently and removing one never drops the other's edge.
82
+ */
83
+ private readonly _backlinks;
84
+ private constructor();
85
+ /** Family-convention factory. */
86
+ static create(): Result<MemoryIndex>;
87
+ /**
88
+ * The composite primary key for an entry: scope + id, NUL-separated. NUL
89
+ * is excluded from both components (scope segments pass
90
+ * `assertPortableFilenameStem`; `MemoryId` is portable-filename-safe), so it
91
+ * is a collision-proof separator across every scope/id pair the codecs produce.
92
+ */
93
+ private static _keyOf;
94
+ /** {@inheritDoc IMemoryIndex.rebuild} */
95
+ rebuild(entries: ReadonlyArray<IIndexedMemoryRecord>): Result<number>;
96
+ /** {@inheritDoc IMemoryIndex.patch} */
97
+ patch(op: MemoryIndexPatchOp, entry: IIndexedMemoryRecord): Result<IIndexedMemoryRecord>;
98
+ /** {@inheritDoc IMemoryIndex.entries} */
99
+ entries(): ReadonlyArray<IIndexedMemoryRecord>;
100
+ /** {@inheritDoc IMemoryIndex.byKind} */
101
+ byKind(kind: Kind): ReadonlyArray<IMemoryRecord<unknown>>;
102
+ /** {@inheritDoc IMemoryIndex.byTag} */
103
+ byTag(tag: Tag): ReadonlyArray<IMemoryRecord<unknown>>;
104
+ /** {@inheritDoc IMemoryIndex.byRecency} */
105
+ byRecency(): ReadonlyArray<IMemoryRecord<unknown>>;
106
+ /** {@inheritDoc IMemoryIndex.backlinks} */
107
+ backlinks(target: MemoryId): ReadonlyArray<MemoryId>;
108
+ /**
109
+ * Resolve a set of composite keys to their records, ordered
110
+ * most-recently-updated first (with a `seq` tiebreak so equal-`updated`
111
+ * records sort deterministically).
112
+ */
113
+ private _recencyOrdered;
114
+ /** Insert an entry and register all its derived associations. */
115
+ private _add;
116
+ /** Remove the entry at `key` (if present) and all its derived associations. */
117
+ private _remove;
118
+ /** Register `sourceId` (keyed by its composite `sourceKey`) as linking at `target`. */
119
+ private _addBacklink;
120
+ /** Drop the backlink from `sourceKey` to `target`, removing the target map when empty. */
121
+ private _removeBacklink;
122
+ /** Add `member` to the set at `mapKey`, creating the set on first use. */
123
+ private _addToSetMap;
124
+ /** Remove `member` from the set at `mapKey`, dropping the set when empty. */
125
+ private _removeFromSetMap;
126
+ }
127
+ //# sourceMappingURL=memoryIndex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memoryIndex.d.ts","sourceRoot":"","sources":["../../../src/packlets/index/memoryIndex.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAW,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE9E;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,KAAK,GAAG,QAAQ,CAAC;AAKlD;;;;;;;;GAQG;AACH,MAAM,WAAW,oBAAoB;IACnC,4CAA4C;IAC5C,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAC/B,gCAAgC;IAChC,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;CACzC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,YAAY;IAC3B;;;OA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