@hasna/mementos 0.14.84 → 0.14.86

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 (556) hide show
  1. package/bun.lock +63 -4
  2. package/dist/cli/index.js +769 -261
  3. package/dist/diagnostics/historical-project-registration-receipt.js +1675 -0
  4. package/dist/index.js +343 -85
  5. package/dist/mcp/index.js +419 -99
  6. package/dist/pg-sync-worker.js +7 -5
  7. package/dist/project-registration.js +309 -68
  8. package/dist/sdk/index.js +123 -30
  9. package/dist/server/index.js +677 -317
  10. package/dist/storage.js +63 -26
  11. package/hasna.contract.json +5 -4
  12. package/package.json +6 -4
  13. package/dist/cli/__fixtures__/clean-fallback-stub-server.d.ts +0 -2
  14. package/dist/cli/__fixtures__/clean-fallback-stub-server.d.ts.map +0 -1
  15. package/dist/cli/brains.d.ts +0 -3
  16. package/dist/cli/brains.d.ts.map +0 -1
  17. package/dist/cli/commands/agent.d.ts +0 -3
  18. package/dist/cli/commands/agent.d.ts.map +0 -1
  19. package/dist/cli/commands/consolidation.d.ts +0 -3
  20. package/dist/cli/commands/consolidation.d.ts.map +0 -1
  21. package/dist/cli/commands/entity.d.ts +0 -3
  22. package/dist/cli/commands/entity.d.ts.map +0 -1
  23. package/dist/cli/commands/graph.d.ts +0 -3
  24. package/dist/cli/commands/graph.d.ts.map +0 -1
  25. package/dist/cli/commands/info-context.d.ts +0 -3
  26. package/dist/cli/commands/info-context.d.ts.map +0 -1
  27. package/dist/cli/commands/info-history.d.ts +0 -3
  28. package/dist/cli/commands/info-history.d.ts.map +0 -1
  29. package/dist/cli/commands/info-report.d.ts +0 -3
  30. package/dist/cli/commands/info-report.d.ts.map +0 -1
  31. package/dist/cli/commands/info-stale.d.ts +0 -3
  32. package/dist/cli/commands/info-stale.d.ts.map +0 -1
  33. package/dist/cli/commands/info-stats.d.ts +0 -3
  34. package/dist/cli/commands/info-stats.d.ts.map +0 -1
  35. package/dist/cli/commands/info.d.ts +0 -12
  36. package/dist/cli/commands/info.d.ts.map +0 -1
  37. package/dist/cli/commands/init.d.ts +0 -3
  38. package/dist/cli/commands/init.d.ts.map +0 -1
  39. package/dist/cli/commands/io-backup.d.ts +0 -3
  40. package/dist/cli/commands/io-backup.d.ts.map +0 -1
  41. package/dist/cli/commands/io-clean.d.ts +0 -3
  42. package/dist/cli/commands/io-clean.d.ts.map +0 -1
  43. package/dist/cli/commands/io-export.d.ts +0 -3
  44. package/dist/cli/commands/io-export.d.ts.map +0 -1
  45. package/dist/cli/commands/io-import.d.ts +0 -3
  46. package/dist/cli/commands/io-import.d.ts.map +0 -1
  47. package/dist/cli/commands/io-restore.d.ts +0 -3
  48. package/dist/cli/commands/io-restore.d.ts.map +0 -1
  49. package/dist/cli/commands/io.d.ts +0 -12
  50. package/dist/cli/commands/io.d.ts.map +0 -1
  51. package/dist/cli/commands/memory-cmd-bulk.d.ts +0 -3
  52. package/dist/cli/commands/memory-cmd-bulk.d.ts.map +0 -1
  53. package/dist/cli/commands/memory-cmd-chain.d.ts +0 -3
  54. package/dist/cli/commands/memory-cmd-chain.d.ts.map +0 -1
  55. package/dist/cli/commands/memory-cmd-crud.d.ts +0 -3
  56. package/dist/cli/commands/memory-cmd-crud.d.ts.map +0 -1
  57. package/dist/cli/commands/memory-cmd-diff.d.ts +0 -3
  58. package/dist/cli/commands/memory-cmd-diff.d.ts.map +0 -1
  59. package/dist/cli/commands/memory-cmd-list.d.ts +0 -3
  60. package/dist/cli/commands/memory-cmd-list.d.ts.map +0 -1
  61. package/dist/cli/commands/memory-cmd-recall-exit.d.ts +0 -3
  62. package/dist/cli/commands/memory-cmd-recall-exit.d.ts.map +0 -1
  63. package/dist/cli/commands/memory-cmd-recall.d.ts +0 -3
  64. package/dist/cli/commands/memory-cmd-recall.d.ts.map +0 -1
  65. package/dist/cli/commands/memory-cmd-remove.d.ts +0 -3
  66. package/dist/cli/commands/memory-cmd-remove.d.ts.map +0 -1
  67. package/dist/cli/commands/memory-cmd-search.d.ts +0 -3
  68. package/dist/cli/commands/memory-cmd-search.d.ts.map +0 -1
  69. package/dist/cli/commands/memory-cmd-tail.d.ts +0 -3
  70. package/dist/cli/commands/memory-cmd-tail.d.ts.map +0 -1
  71. package/dist/cli/commands/memory-cmd-util.d.ts +0 -3
  72. package/dist/cli/commands/memory-cmd-util.d.ts.map +0 -1
  73. package/dist/cli/commands/memory-cmd-view.d.ts +0 -3
  74. package/dist/cli/commands/memory-cmd-view.d.ts.map +0 -1
  75. package/dist/cli/commands/memory-cmd-watch.d.ts +0 -3
  76. package/dist/cli/commands/memory-cmd-watch.d.ts.map +0 -1
  77. package/dist/cli/commands/memory-cmd-when-to-use.d.ts +0 -3
  78. package/dist/cli/commands/memory-cmd-when-to-use.d.ts.map +0 -1
  79. package/dist/cli/commands/memory.d.ts +0 -3
  80. package/dist/cli/commands/memory.d.ts.map +0 -1
  81. package/dist/cli/commands/project-panel.d.ts +0 -3
  82. package/dist/cli/commands/project-panel.d.ts.map +0 -1
  83. package/dist/cli/commands/project.d.ts +0 -3
  84. package/dist/cli/commands/project.d.ts.map +0 -1
  85. package/dist/cli/commands/relation.d.ts +0 -3
  86. package/dist/cli/commands/relation.d.ts.map +0 -1
  87. package/dist/cli/commands/storage.d.ts +0 -3
  88. package/dist/cli/commands/storage.d.ts.map +0 -1
  89. package/dist/cli/commands/system-auto-memory.d.ts +0 -3
  90. package/dist/cli/commands/system-auto-memory.d.ts.map +0 -1
  91. package/dist/cli/commands/system-completions.d.ts +0 -13
  92. package/dist/cli/commands/system-completions.d.ts.map +0 -1
  93. package/dist/cli/commands/system-config.d.ts +0 -3
  94. package/dist/cli/commands/system-config.d.ts.map +0 -1
  95. package/dist/cli/commands/system-doctor.d.ts +0 -3
  96. package/dist/cli/commands/system-doctor.d.ts.map +0 -1
  97. package/dist/cli/commands/system-hooks.d.ts +0 -3
  98. package/dist/cli/commands/system-hooks.d.ts.map +0 -1
  99. package/dist/cli/commands/system-mcp.d.ts +0 -3
  100. package/dist/cli/commands/system-mcp.d.ts.map +0 -1
  101. package/dist/cli/commands/system-misc.d.ts +0 -3
  102. package/dist/cli/commands/system-misc.d.ts.map +0 -1
  103. package/dist/cli/commands/system-profile.d.ts +0 -3
  104. package/dist/cli/commands/system-profile.d.ts.map +0 -1
  105. package/dist/cli/commands/system-session.d.ts +0 -3
  106. package/dist/cli/commands/system-session.d.ts.map +0 -1
  107. package/dist/cli/commands/system-sessions.d.ts +0 -3
  108. package/dist/cli/commands/system-sessions.d.ts.map +0 -1
  109. package/dist/cli/commands/system-synthesis.d.ts +0 -3
  110. package/dist/cli/commands/system-synthesis.d.ts.map +0 -1
  111. package/dist/cli/commands/system-synthesized-profile.d.ts +0 -3
  112. package/dist/cli/commands/system-synthesized-profile.d.ts.map +0 -1
  113. package/dist/cli/commands/system-tools.d.ts +0 -3
  114. package/dist/cli/commands/system-tools.d.ts.map +0 -1
  115. package/dist/cli/commands/system-watch.d.ts +0 -3
  116. package/dist/cli/commands/system-watch.d.ts.map +0 -1
  117. package/dist/cli/commands/system.d.ts +0 -3
  118. package/dist/cli/commands/system.d.ts.map +0 -1
  119. package/dist/cli/exit-codes.d.ts +0 -13
  120. package/dist/cli/exit-codes.d.ts.map +0 -1
  121. package/dist/cli/global-options.d.ts +0 -27
  122. package/dist/cli/global-options.d.ts.map +0 -1
  123. package/dist/cli/helpers.d.ts +0 -119
  124. package/dist/cli/helpers.d.ts.map +0 -1
  125. package/dist/cli/index.d.ts +0 -3
  126. package/dist/cli/index.d.ts.map +0 -1
  127. package/dist/cli/register-all.d.ts +0 -17
  128. package/dist/cli/register-all.d.ts.map +0 -1
  129. package/dist/cli/startup-side-effects.d.ts +0 -9
  130. package/dist/cli/startup-side-effects.d.ts.map +0 -1
  131. package/dist/db/__fixtures__/fail-closed-stub-server.d.ts +0 -2
  132. package/dist/db/__fixtures__/fail-closed-stub-server.d.ts.map +0 -1
  133. package/dist/db/acl.d.ts +0 -34
  134. package/dist/db/acl.d.ts.map +0 -1
  135. package/dist/db/agents.d.ts +0 -21
  136. package/dist/db/agents.d.ts.map +0 -1
  137. package/dist/db/analytics.d.ts +0 -107
  138. package/dist/db/analytics.d.ts.map +0 -1
  139. package/dist/db/api-mode.d.ts +0 -127
  140. package/dist/db/api-mode.d.ts.map +0 -1
  141. package/dist/db/audit.d.ts +0 -53
  142. package/dist/db/audit.d.ts.map +0 -1
  143. package/dist/db/database.d.ts +0 -26
  144. package/dist/db/database.d.ts.map +0 -1
  145. package/dist/db/entities.d.ts +0 -62
  146. package/dist/db/entities.d.ts.map +0 -1
  147. package/dist/db/entity-memories.d.ts +0 -34
  148. package/dist/db/entity-memories.d.ts.map +0 -1
  149. package/dist/db/feedback.d.ts +0 -9
  150. package/dist/db/feedback.d.ts.map +0 -1
  151. package/dist/db/locks.d.ts +0 -63
  152. package/dist/db/locks.d.ts.map +0 -1
  153. package/dist/db/machines.d.ts +0 -23
  154. package/dist/db/machines.d.ts.map +0 -1
  155. package/dist/db/memories.d.ts +0 -137
  156. package/dist/db/memories.d.ts.map +0 -1
  157. package/dist/db/memory-links.d.ts +0 -21
  158. package/dist/db/memory-links.d.ts.map +0 -1
  159. package/dist/db/memory-project-link.d.ts +0 -13
  160. package/dist/db/memory-project-link.d.ts.map +0 -1
  161. package/dist/db/migrations.d.ts +0 -3
  162. package/dist/db/migrations.d.ts.map +0 -1
  163. package/dist/db/pg-migrate.d.ts +0 -27
  164. package/dist/db/pg-migrate.d.ts.map +0 -1
  165. package/dist/db/pg-migrations.d.ts +0 -2
  166. package/dist/db/pg-migrations.d.ts.map +0 -1
  167. package/dist/db/projects.d.ts +0 -27
  168. package/dist/db/projects.d.ts.map +0 -1
  169. package/dist/db/ratings.d.ts +0 -23
  170. package/dist/db/ratings.d.ts.map +0 -1
  171. package/dist/db/relations.d.ts +0 -49
  172. package/dist/db/relations.d.ts.map +0 -1
  173. package/dist/db/session-jobs.d.ts +0 -49
  174. package/dist/db/session-jobs.d.ts.map +0 -1
  175. package/dist/db/store-backend.d.ts +0 -42
  176. package/dist/db/store-backend.d.ts.map +0 -1
  177. package/dist/db/subscriptions.d.ts +0 -24
  178. package/dist/db/subscriptions.d.ts.map +0 -1
  179. package/dist/db/synthesis.d.ts +0 -101
  180. package/dist/db/synthesis.d.ts.map +0 -1
  181. package/dist/db/tasks.d.ts +0 -89
  182. package/dist/db/tasks.d.ts.map +0 -1
  183. package/dist/db/tool-events.d.ts +0 -27
  184. package/dist/db/tool-events.d.ts.map +0 -1
  185. package/dist/db/webhook_hooks.d.ts +0 -25
  186. package/dist/db/webhook_hooks.d.ts.map +0 -1
  187. package/dist/generated/storage-kit/backend.d.ts +0 -20
  188. package/dist/generated/storage-kit/backend.d.ts.map +0 -1
  189. package/dist/generated/storage-kit/health.d.ts +0 -20
  190. package/dist/generated/storage-kit/health.d.ts.map +0 -1
  191. package/dist/generated/storage-kit/index.d.ts +0 -8
  192. package/dist/generated/storage-kit/index.d.ts.map +0 -1
  193. package/dist/generated/storage-kit/migrations.d.ts +0 -48
  194. package/dist/generated/storage-kit/migrations.d.ts.map +0 -1
  195. package/dist/generated/storage-kit/own.d.ts +0 -11
  196. package/dist/generated/storage-kit/own.d.ts.map +0 -1
  197. package/dist/generated/storage-kit/pool.d.ts +0 -35
  198. package/dist/generated/storage-kit/pool.d.ts.map +0 -1
  199. package/dist/generated/storage-kit/query.d.ts +0 -36
  200. package/dist/generated/storage-kit/query.d.ts.map +0 -1
  201. package/dist/generated/storage-kit/tls.d.ts +0 -53
  202. package/dist/generated/storage-kit/tls.d.ts.map +0 -1
  203. package/dist/index.d.ts +0 -45
  204. package/dist/index.d.ts.map +0 -1
  205. package/dist/lib/activation-matcher.d.ts +0 -17
  206. package/dist/lib/activation-matcher.d.ts.map +0 -1
  207. package/dist/lib/asmr/categorizer.d.ts +0 -31
  208. package/dist/lib/asmr/categorizer.d.ts.map +0 -1
  209. package/dist/lib/asmr/context-agent.d.ts +0 -4
  210. package/dist/lib/asmr/context-agent.d.ts.map +0 -1
  211. package/dist/lib/asmr/ensemble.d.ts +0 -23
  212. package/dist/lib/asmr/ensemble.d.ts.map +0 -1
  213. package/dist/lib/asmr/fact-agent.d.ts +0 -4
  214. package/dist/lib/asmr/fact-agent.d.ts.map +0 -1
  215. package/dist/lib/asmr/index.d.ts +0 -7
  216. package/dist/lib/asmr/index.d.ts.map +0 -1
  217. package/dist/lib/asmr/orchestrator.d.ts +0 -4
  218. package/dist/lib/asmr/orchestrator.d.ts.map +0 -1
  219. package/dist/lib/asmr/recall.d.ts +0 -3
  220. package/dist/lib/asmr/recall.d.ts.map +0 -1
  221. package/dist/lib/asmr/temporal-agent.d.ts +0 -4
  222. package/dist/lib/asmr/temporal-agent.d.ts.map +0 -1
  223. package/dist/lib/asmr/types.d.ts +0 -27
  224. package/dist/lib/asmr/types.d.ts.map +0 -1
  225. package/dist/lib/auto-inject-orchestrator.d.ts +0 -57
  226. package/dist/lib/auto-inject-orchestrator.d.ts.map +0 -1
  227. package/dist/lib/auto-memory-queue.d.ts +0 -48
  228. package/dist/lib/auto-memory-queue.d.ts.map +0 -1
  229. package/dist/lib/auto-memory.d.ts +0 -19
  230. package/dist/lib/auto-memory.d.ts.map +0 -1
  231. package/dist/lib/bench.d.ts +0 -20
  232. package/dist/lib/bench.d.ts.map +0 -1
  233. package/dist/lib/built-in-hooks.d.ts +0 -12
  234. package/dist/lib/built-in-hooks.d.ts.map +0 -1
  235. package/dist/lib/channel-pusher.d.ts +0 -39
  236. package/dist/lib/channel-pusher.d.ts.map +0 -1
  237. package/dist/lib/config.d.ts +0 -9
  238. package/dist/lib/config.d.ts.map +0 -1
  239. package/dist/lib/connectors/files.d.ts +0 -8
  240. package/dist/lib/connectors/files.d.ts.map +0 -1
  241. package/dist/lib/connectors/github.d.ts +0 -7
  242. package/dist/lib/connectors/github.d.ts.map +0 -1
  243. package/dist/lib/connectors/index.d.ts +0 -12
  244. package/dist/lib/connectors/index.d.ts.map +0 -1
  245. package/dist/lib/connectors/notion.d.ts +0 -7
  246. package/dist/lib/connectors/notion.d.ts.map +0 -1
  247. package/dist/lib/connectors/types.d.ts +0 -27
  248. package/dist/lib/connectors/types.d.ts.map +0 -1
  249. package/dist/lib/consolidation.d.ts +0 -52
  250. package/dist/lib/consolidation.d.ts.map +0 -1
  251. package/dist/lib/context-extractor.d.ts +0 -14
  252. package/dist/lib/context-extractor.d.ts.map +0 -1
  253. package/dist/lib/context.d.ts +0 -36
  254. package/dist/lib/context.d.ts.map +0 -1
  255. package/dist/lib/contradiction.d.ts +0 -50
  256. package/dist/lib/contradiction.d.ts.map +0 -1
  257. package/dist/lib/decay.d.ts +0 -35
  258. package/dist/lib/decay.d.ts.map +0 -1
  259. package/dist/lib/dedup.d.ts +0 -33
  260. package/dist/lib/dedup.d.ts.map +0 -1
  261. package/dist/lib/duration.d.ts +0 -28
  262. package/dist/lib/duration.d.ts.map +0 -1
  263. package/dist/lib/embeddings.d.ts +0 -20
  264. package/dist/lib/embeddings.d.ts.map +0 -1
  265. package/dist/lib/enum-validation.d.ts +0 -20
  266. package/dist/lib/enum-validation.d.ts.map +0 -1
  267. package/dist/lib/export-v1.d.ts +0 -30
  268. package/dist/lib/export-v1.d.ts.map +0 -1
  269. package/dist/lib/extractor.d.ts +0 -9
  270. package/dist/lib/extractor.d.ts.map +0 -1
  271. package/dist/lib/extractors/audio.d.ts +0 -8
  272. package/dist/lib/extractors/audio.d.ts.map +0 -1
  273. package/dist/lib/extractors/index.d.ts +0 -12
  274. package/dist/lib/extractors/index.d.ts.map +0 -1
  275. package/dist/lib/extractors/ocr.d.ts +0 -7
  276. package/dist/lib/extractors/ocr.d.ts.map +0 -1
  277. package/dist/lib/extractors/pdf.d.ts +0 -7
  278. package/dist/lib/extractors/pdf.d.ts.map +0 -1
  279. package/dist/lib/extractors/types.d.ts +0 -12
  280. package/dist/lib/extractors/types.d.ts.map +0 -1
  281. package/dist/lib/file-deps.d.ts +0 -27
  282. package/dist/lib/file-deps.d.ts.map +0 -1
  283. package/dist/lib/focus.d.ts +0 -58
  284. package/dist/lib/focus.d.ts.map +0 -1
  285. package/dist/lib/gatherer.d.ts +0 -16
  286. package/dist/lib/gatherer.d.ts.map +0 -1
  287. package/dist/lib/gdpr.d.ts +0 -39
  288. package/dist/lib/gdpr.d.ts.map +0 -1
  289. package/dist/lib/hooks.d.ts +0 -50
  290. package/dist/lib/hooks.d.ts.map +0 -1
  291. package/dist/lib/importers/index.d.ts +0 -38
  292. package/dist/lib/importers/index.d.ts.map +0 -1
  293. package/dist/lib/injector.d.ts +0 -89
  294. package/dist/lib/injector.d.ts.map +0 -1
  295. package/dist/lib/machine-visibility.d.ts +0 -6
  296. package/dist/lib/machine-visibility.d.ts.map +0 -1
  297. package/dist/lib/matryoshka.d.ts +0 -50
  298. package/dist/lib/matryoshka.d.ts.map +0 -1
  299. package/dist/lib/memory-lock.d.ts +0 -58
  300. package/dist/lib/memory-lock.d.ts.map +0 -1
  301. package/dist/lib/model-config.d.ts +0 -14
  302. package/dist/lib/model-config.d.ts.map +0 -1
  303. package/dist/lib/open-sessions-connector.d.ts +0 -60
  304. package/dist/lib/open-sessions-connector.d.ts.map +0 -1
  305. package/dist/lib/package-version.d.ts +0 -3
  306. package/dist/lib/package-version.d.ts.map +0 -1
  307. package/dist/lib/poisoning.d.ts +0 -19
  308. package/dist/lib/poisoning.d.ts.map +0 -1
  309. package/dist/lib/poll.d.ts +0 -17
  310. package/dist/lib/poll.d.ts.map +0 -1
  311. package/dist/lib/procedural-extractor.d.ts +0 -21
  312. package/dist/lib/procedural-extractor.d.ts.map +0 -1
  313. package/dist/lib/profile-sync.d.ts +0 -20
  314. package/dist/lib/profile-sync.d.ts.map +0 -1
  315. package/dist/lib/profile-synthesizer.d.ts +0 -20
  316. package/dist/lib/profile-synthesizer.d.ts.map +0 -1
  317. package/dist/lib/project-detect.d.ts +0 -18
  318. package/dist/lib/project-detect.d.ts.map +0 -1
  319. package/dist/lib/project-panel.d.ts +0 -7
  320. package/dist/lib/project-panel.d.ts.map +0 -1
  321. package/dist/lib/providers/anthropic.d.ts +0 -21
  322. package/dist/lib/providers/anthropic.d.ts.map +0 -1
  323. package/dist/lib/providers/base.d.ts +0 -96
  324. package/dist/lib/providers/base.d.ts.map +0 -1
  325. package/dist/lib/providers/cerebras.d.ts +0 -20
  326. package/dist/lib/providers/cerebras.d.ts.map +0 -1
  327. package/dist/lib/providers/grok.d.ts +0 -19
  328. package/dist/lib/providers/grok.d.ts.map +0 -1
  329. package/dist/lib/providers/index.d.ts +0 -7
  330. package/dist/lib/providers/index.d.ts.map +0 -1
  331. package/dist/lib/providers/openai-compat.d.ts +0 -18
  332. package/dist/lib/providers/openai-compat.d.ts.map +0 -1
  333. package/dist/lib/providers/openai.d.ts +0 -20
  334. package/dist/lib/providers/openai.d.ts.map +0 -1
  335. package/dist/lib/providers/registry.d.ts +0 -38
  336. package/dist/lib/providers/registry.d.ts.map +0 -1
  337. package/dist/lib/quality.d.ts +0 -16
  338. package/dist/lib/quality.d.ts.map +0 -1
  339. package/dist/lib/redact.d.ts +0 -10
  340. package/dist/lib/redact.d.ts.map +0 -1
  341. package/dist/lib/reflection.d.ts +0 -83
  342. package/dist/lib/reflection.d.ts.map +0 -1
  343. package/dist/lib/retention.d.ts +0 -17
  344. package/dist/lib/retention.d.ts.map +0 -1
  345. package/dist/lib/retired-storage-mode.d.ts +0 -11
  346. package/dist/lib/retired-storage-mode.d.ts.map +0 -1
  347. package/dist/lib/search.d.ts +0 -52
  348. package/dist/lib/search.d.ts.map +0 -1
  349. package/dist/lib/session-auto-resolve.d.ts +0 -28
  350. package/dist/lib/session-auto-resolve.d.ts.map +0 -1
  351. package/dist/lib/session-processor.d.ts +0 -38
  352. package/dist/lib/session-processor.d.ts.map +0 -1
  353. package/dist/lib/session-queue.d.ts +0 -28
  354. package/dist/lib/session-queue.d.ts.map +0 -1
  355. package/dist/lib/session-registry.d.ts +0 -47
  356. package/dist/lib/session-registry.d.ts.map +0 -1
  357. package/dist/lib/session-start-briefing.d.ts +0 -10
  358. package/dist/lib/session-start-briefing.d.ts.map +0 -1
  359. package/dist/lib/session-watcher.d.ts +0 -30
  360. package/dist/lib/session-watcher.d.ts.map +0 -1
  361. package/dist/lib/storage-sync.d.ts +0 -45
  362. package/dist/lib/storage-sync.d.ts.map +0 -1
  363. package/dist/lib/sync.d.ts +0 -10
  364. package/dist/lib/sync.d.ts.map +0 -1
  365. package/dist/lib/synthesis/corpus-builder.d.ts +0 -30
  366. package/dist/lib/synthesis/corpus-builder.d.ts.map +0 -1
  367. package/dist/lib/synthesis/executor.d.ts +0 -14
  368. package/dist/lib/synthesis/executor.d.ts.map +0 -1
  369. package/dist/lib/synthesis/index.d.ts +0 -37
  370. package/dist/lib/synthesis/index.d.ts.map +0 -1
  371. package/dist/lib/synthesis/llm-analyzer.d.ts +0 -18
  372. package/dist/lib/synthesis/llm-analyzer.d.ts.map +0 -1
  373. package/dist/lib/synthesis/metrics.d.ts +0 -13
  374. package/dist/lib/synthesis/metrics.d.ts.map +0 -1
  375. package/dist/lib/synthesis/scheduler.d.ts +0 -18
  376. package/dist/lib/synthesis/scheduler.d.ts.map +0 -1
  377. package/dist/lib/synthesis/validator.d.ts +0 -19
  378. package/dist/lib/synthesis/validator.d.ts.map +0 -1
  379. package/dist/lib/task-runner.d.ts +0 -37
  380. package/dist/lib/task-runner.d.ts.map +0 -1
  381. package/dist/lib/tool-lesson-extractor.d.ts +0 -24
  382. package/dist/lib/tool-lesson-extractor.d.ts.map +0 -1
  383. package/dist/lib/tool-memory-synthesizer.d.ts +0 -28
  384. package/dist/lib/tool-memory-synthesizer.d.ts.map +0 -1
  385. package/dist/lib/topic-clusterer.d.ts +0 -21
  386. package/dist/lib/topic-clusterer.d.ts.map +0 -1
  387. package/dist/lib/when-to-use-generator.d.ts +0 -22
  388. package/dist/lib/when-to-use-generator.d.ts.map +0 -1
  389. package/dist/mcp/http.d.ts +0 -17
  390. package/dist/mcp/http.d.ts.map +0 -1
  391. package/dist/mcp/index.d.ts +0 -6
  392. package/dist/mcp/index.d.ts.map +0 -1
  393. package/dist/mcp/memory-broadcast.d.ts +0 -12
  394. package/dist/mcp/memory-broadcast.d.ts.map +0 -1
  395. package/dist/mcp/tools/agent-tools.d.ts +0 -3
  396. package/dist/mcp/tools/agent-tools.d.ts.map +0 -1
  397. package/dist/mcp/tools/auto-memory-tools.d.ts +0 -5
  398. package/dist/mcp/tools/auto-memory-tools.d.ts.map +0 -1
  399. package/dist/mcp/tools/bulk-tools.d.ts +0 -3
  400. package/dist/mcp/tools/bulk-tools.d.ts.map +0 -1
  401. package/dist/mcp/tools/consolidation-tools.d.ts +0 -3
  402. package/dist/mcp/tools/consolidation-tools.d.ts.map +0 -1
  403. package/dist/mcp/tools/focus-tools.d.ts +0 -3
  404. package/dist/mcp/tools/focus-tools.d.ts.map +0 -1
  405. package/dist/mcp/tools/graph-entity-tools.d.ts +0 -3
  406. package/dist/mcp/tools/graph-entity-tools.d.ts.map +0 -1
  407. package/dist/mcp/tools/graph-query-tools.d.ts +0 -3
  408. package/dist/mcp/tools/graph-query-tools.d.ts.map +0 -1
  409. package/dist/mcp/tools/graph-relation-tools.d.ts +0 -3
  410. package/dist/mcp/tools/graph-relation-tools.d.ts.map +0 -1
  411. package/dist/mcp/tools/graph-tools.d.ts +0 -3
  412. package/dist/mcp/tools/graph-tools.d.ts.map +0 -1
  413. package/dist/mcp/tools/graph-utils.d.ts +0 -5
  414. package/dist/mcp/tools/graph-utils.d.ts.map +0 -1
  415. package/dist/mcp/tools/hook-tools.d.ts +0 -3
  416. package/dist/mcp/tools/hook-tools.d.ts.map +0 -1
  417. package/dist/mcp/tools/lock-tools.d.ts +0 -3
  418. package/dist/mcp/tools/lock-tools.d.ts.map +0 -1
  419. package/dist/mcp/tools/memory-audit.d.ts +0 -3
  420. package/dist/mcp/tools/memory-audit.d.ts.map +0 -1
  421. package/dist/mcp/tools/memory-crud.d.ts +0 -3
  422. package/dist/mcp/tools/memory-crud.d.ts.map +0 -1
  423. package/dist/mcp/tools/memory-health.d.ts +0 -3
  424. package/dist/mcp/tools/memory-health.d.ts.map +0 -1
  425. package/dist/mcp/tools/memory-history.d.ts +0 -3
  426. package/dist/mcp/tools/memory-history.d.ts.map +0 -1
  427. package/dist/mcp/tools/memory-inject.d.ts +0 -3
  428. package/dist/mcp/tools/memory-inject.d.ts.map +0 -1
  429. package/dist/mcp/tools/memory-io.d.ts +0 -3
  430. package/dist/mcp/tools/memory-io.d.ts.map +0 -1
  431. package/dist/mcp/tools/memory-lifecycle.d.ts +0 -3
  432. package/dist/mcp/tools/memory-lifecycle.d.ts.map +0 -1
  433. package/dist/mcp/tools/memory-search.d.ts +0 -3
  434. package/dist/mcp/tools/memory-search.d.ts.map +0 -1
  435. package/dist/mcp/tools/memory-stats.d.ts +0 -3
  436. package/dist/mcp/tools/memory-stats.d.ts.map +0 -1
  437. package/dist/mcp/tools/memory-tools.d.ts +0 -17
  438. package/dist/mcp/tools/memory-tools.d.ts.map +0 -1
  439. package/dist/mcp/tools/memory-utils.d.ts +0 -27
  440. package/dist/mcp/tools/memory-utils.d.ts.map +0 -1
  441. package/dist/mcp/tools/memory-validation.d.ts +0 -3
  442. package/dist/mcp/tools/memory-validation.d.ts.map +0 -1
  443. package/dist/mcp/tools/project-tools.d.ts +0 -3
  444. package/dist/mcp/tools/project-tools.d.ts.map +0 -1
  445. package/dist/mcp/tools/session-tools.d.ts +0 -3
  446. package/dist/mcp/tools/session-tools.d.ts.map +0 -1
  447. package/dist/mcp/tools/storage-tools.d.ts +0 -3
  448. package/dist/mcp/tools/storage-tools.d.ts.map +0 -1
  449. package/dist/mcp/tools/synthesis-tools.d.ts +0 -3
  450. package/dist/mcp/tools/synthesis-tools.d.ts.map +0 -1
  451. package/dist/mcp/tools/system-tools-events.d.ts +0 -3
  452. package/dist/mcp/tools/system-tools-events.d.ts.map +0 -1
  453. package/dist/mcp/tools/system-tools-memory-admin.d.ts +0 -3
  454. package/dist/mcp/tools/system-tools-memory-admin.d.ts.map +0 -1
  455. package/dist/mcp/tools/system-tools-shared.d.ts +0 -23
  456. package/dist/mcp/tools/system-tools-shared.d.ts.map +0 -1
  457. package/dist/mcp/tools/system-tools.d.ts +0 -3
  458. package/dist/mcp/tools/system-tools.d.ts.map +0 -1
  459. package/dist/mcp/tools/tool-registry.d.ts +0 -30
  460. package/dist/mcp/tools/tool-registry.d.ts.map +0 -1
  461. package/dist/mcp/tools/utility-tools.d.ts +0 -3
  462. package/dist/mcp/tools/utility-tools.d.ts.map +0 -1
  463. package/dist/memory-project-link/index.d.ts +0 -2
  464. package/dist/memory-project-link/index.d.ts.map +0 -1
  465. package/dist/memory-project-link/schema.d.ts +0 -5
  466. package/dist/memory-project-link/schema.d.ts.map +0 -1
  467. package/dist/pg-sync-worker.d.ts +0 -2
  468. package/dist/pg-sync-worker.d.ts.map +0 -1
  469. package/dist/project-registration/authority.d.ts +0 -43
  470. package/dist/project-registration/authority.d.ts.map +0 -1
  471. package/dist/project-registration/http.d.ts +0 -32
  472. package/dist/project-registration/http.d.ts.map +0 -1
  473. package/dist/project-registration/identity.d.ts +0 -20
  474. package/dist/project-registration/identity.d.ts.map +0 -1
  475. package/dist/project-registration/index.d.ts +0 -11
  476. package/dist/project-registration/index.d.ts.map +0 -1
  477. package/dist/project-registration/project-references.d.ts +0 -71
  478. package/dist/project-registration/project-references.d.ts.map +0 -1
  479. package/dist/project-registration/project-resources.d.ts +0 -22
  480. package/dist/project-registration/project-resources.d.ts.map +0 -1
  481. package/dist/project-registration/schema.d.ts +0 -5
  482. package/dist/project-registration/schema.d.ts.map +0 -1
  483. package/dist/project-registration/types.d.ts +0 -293
  484. package/dist/project-registration/types.d.ts.map +0 -1
  485. package/dist/project-registration.d.ts +0 -2
  486. package/dist/project-registration.d.ts.map +0 -1
  487. package/dist/sdk/index.d.ts +0 -971
  488. package/dist/sdk/index.d.ts.map +0 -1
  489. package/dist/server/auth.d.ts +0 -11
  490. package/dist/server/auth.d.ts.map +0 -1
  491. package/dist/server/helpers.d.ts +0 -22
  492. package/dist/server/helpers.d.ts.map +0 -1
  493. package/dist/server/index.d.ts +0 -14
  494. package/dist/server/index.d.ts.map +0 -1
  495. package/dist/server/openapi.d.ts +0 -2
  496. package/dist/server/openapi.d.ts.map +0 -1
  497. package/dist/server/router.d.ts +0 -17
  498. package/dist/server/router.d.ts.map +0 -1
  499. package/dist/server/routes/agents.d.ts +0 -2
  500. package/dist/server/routes/agents.d.ts.map +0 -1
  501. package/dist/server/routes/entities.d.ts +0 -2
  502. package/dist/server/routes/entities.d.ts.map +0 -1
  503. package/dist/server/routes/memories-bulk.d.ts +0 -2
  504. package/dist/server/routes/memories-bulk.d.ts.map +0 -1
  505. package/dist/server/routes/memories-crud.d.ts +0 -2
  506. package/dist/server/routes/memories-crud.d.ts.map +0 -1
  507. package/dist/server/routes/memories-io.d.ts +0 -2
  508. package/dist/server/routes/memories-io.d.ts.map +0 -1
  509. package/dist/server/routes/memories-misc.d.ts +0 -2
  510. package/dist/server/routes/memories-misc.d.ts.map +0 -1
  511. package/dist/server/routes/memories-search.d.ts +0 -2
  512. package/dist/server/routes/memories-search.d.ts.map +0 -1
  513. package/dist/server/routes/memories-stats.d.ts +0 -2
  514. package/dist/server/routes/memories-stats.d.ts.map +0 -1
  515. package/dist/server/routes/memories.d.ts +0 -19
  516. package/dist/server/routes/memories.d.ts.map +0 -1
  517. package/dist/server/routes/memory-project-link.d.ts +0 -2
  518. package/dist/server/routes/memory-project-link.d.ts.map +0 -1
  519. package/dist/server/routes/project-registration.d.ts +0 -2
  520. package/dist/server/routes/project-registration.d.ts.map +0 -1
  521. package/dist/server/routes/projects.d.ts +0 -2
  522. package/dist/server/routes/projects.d.ts.map +0 -1
  523. package/dist/server/routes/system-auto-memory.d.ts +0 -2
  524. package/dist/server/routes/system-auto-memory.d.ts.map +0 -1
  525. package/dist/server/routes/system-chain.d.ts +0 -2
  526. package/dist/server/routes/system-chain.d.ts.map +0 -1
  527. package/dist/server/routes/system-consolidation.d.ts +0 -2
  528. package/dist/server/routes/system-consolidation.d.ts.map +0 -1
  529. package/dist/server/routes/system-hooks.d.ts +0 -2
  530. package/dist/server/routes/system-hooks.d.ts.map +0 -1
  531. package/dist/server/routes/system-sessions.d.ts +0 -2
  532. package/dist/server/routes/system-sessions.d.ts.map +0 -1
  533. package/dist/server/routes/system-subscriptions.d.ts +0 -2
  534. package/dist/server/routes/system-subscriptions.d.ts.map +0 -1
  535. package/dist/server/routes/system-synthesis.d.ts +0 -2
  536. package/dist/server/routes/system-synthesis.d.ts.map +0 -1
  537. package/dist/server/routes/system-tools.d.ts +0 -2
  538. package/dist/server/routes/system-tools.d.ts.map +0 -1
  539. package/dist/server/routes/system.d.ts +0 -2
  540. package/dist/server/routes/system.d.ts.map +0 -1
  541. package/dist/server/routes/tasks.d.ts +0 -2
  542. package/dist/server/routes/tasks.d.ts.map +0 -1
  543. package/dist/storage.d.ts +0 -266
  544. package/dist/storage.d.ts.map +0 -1
  545. package/dist/test-support/preload-local-store.d.ts +0 -2
  546. package/dist/test-support/preload-local-store.d.ts.map +0 -1
  547. package/dist/test-support/project-authority-identity.d.ts +0 -8
  548. package/dist/test-support/project-authority-identity.d.ts.map +0 -1
  549. package/dist/test-support/store-isolation.d.ts +0 -108
  550. package/dist/test-support/store-isolation.d.ts.map +0 -1
  551. package/dist/test-support/strip-ansi.d.ts +0 -3
  552. package/dist/test-support/strip-ansi.d.ts.map +0 -1
  553. package/dist/types/hooks.d.ts +0 -136
  554. package/dist/types/hooks.d.ts.map +0 -1
  555. package/dist/types/index.d.ts +0 -472
  556. package/dist/types/index.d.ts.map +0 -1
@@ -20,7 +20,7 @@ async function ensureConnected() {
20
20
  }
21
21
  await connecting;
22
22
  }
23
- function respond(statusCode, payload) {
23
+ function respond(gen, statusCode, payload) {
24
24
  const bytes = encoder.encode(JSON.stringify(payload));
25
25
  if (bytes.length > dataView.length) {
26
26
  const errBytes = encoder.encode(JSON.stringify({
@@ -28,21 +28,23 @@ function respond(statusCode, payload) {
28
28
  }));
29
29
  dataView.set(errBytes, 0);
30
30
  Atomics.store(status, 1, errBytes.length);
31
- Atomics.store(status, 0, 2);
31
+ Atomics.store(status, 2, 2);
32
+ Atomics.store(status, 0, gen);
32
33
  Atomics.notify(status, 0);
33
34
  return;
34
35
  }
35
36
  dataView.set(bytes, 0);
36
37
  Atomics.store(status, 1, bytes.length);
37
- Atomics.store(status, 0, statusCode);
38
+ Atomics.store(status, 2, statusCode);
39
+ Atomics.store(status, 0, gen);
38
40
  Atomics.notify(status, 0);
39
41
  }
40
42
  parentPort?.on("message", async (msg) => {
41
43
  try {
42
44
  await ensureConnected();
43
45
  const result = await client.query(msg.sql, msg.params);
44
- respond(1, { rows: result.rows, rowCount: result.rowCount });
46
+ respond(msg.gen, 1, { rows: result.rows, rowCount: result.rowCount });
45
47
  } catch (error) {
46
- respond(2, { message: error instanceof Error ? error.message : String(error) });
48
+ respond(msg.gen, 2, { message: error instanceof Error ? error.message : String(error) });
47
49
  }
48
50
  });
@@ -235,6 +235,7 @@ function translateSql(sql) {
235
235
  let translated = sql.replace(/\?/g, () => `$${++parameterIndex}`);
236
236
  const ISO_FMT = `'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"'`;
237
237
  translated = translated.replace(/datetime\s*\(\s*'now'\s*\)/gi, `to_char(now() AT TIME ZONE 'UTC', ${ISO_FMT})`);
238
+ translated = translated.replace(/strftime\s*\(\s*'%Y-%m-%dT%H:%M:%fZ'\s*,\s*'now'\s*\)/gi, `to_char(now() AT TIME ZONE 'UTC', ${ISO_FMT})`);
238
239
  translated = translated.replace(/datetime\s*\(\s*'now'\s*,\s*'(-?\d+)\s+(minutes?|hours?|days?|seconds?)'\s*\)/gi, (_match, amount, unit) => {
239
240
  const parsed = parseInt(String(amount), 10);
240
241
  const absolute = Math.abs(parsed);
@@ -736,16 +737,24 @@ function transferRows(target, table, rows, options) {
736
737
  const conflictColumn = options.conflictColumn ?? "updated_at";
737
738
  let written = 0;
738
739
  let skipped = 0;
740
+ let maxSyncedAt = null;
739
741
  const errors = [];
742
+ const bumpMaxSyncedAt = (row) => {
743
+ const value = row[conflictColumn];
744
+ if (typeof value === "string" && (maxSyncedAt === null || value > maxSyncedAt)) {
745
+ maxSyncedAt = value;
746
+ }
747
+ };
740
748
  if (rows.length === 0) {
741
- return { written, skipped, errors };
749
+ return { written, skipped, errors, maxSyncedAt };
742
750
  }
743
751
  const columns = Object.keys(rows[0] ?? {});
744
752
  if (!columns.includes(primaryKey)) {
745
753
  return {
746
754
  written,
747
755
  skipped,
748
- errors: [`Table "${table}" has no "${primaryKey}" column; skipping`]
756
+ errors: [`Table "${table}" has no "${primaryKey}" column; skipping`],
757
+ maxSyncedAt
749
758
  };
750
759
  }
751
760
  const hasConflictColumn = columns.includes(conflictColumn);
@@ -758,6 +767,7 @@ function transferRows(target, table, rows, options) {
758
767
  const incomingTime = Date.parse(String(row[conflictColumn]));
759
768
  if (Number.isFinite(existingTime) && Number.isFinite(incomingTime) && existingTime >= incomingTime) {
760
769
  skipped++;
770
+ bumpMaxSyncedAt(row);
761
771
  continue;
762
772
  }
763
773
  }
@@ -770,11 +780,12 @@ function transferRows(target, table, rows, options) {
770
780
  target.run(`INSERT INTO "${table}" (${columnList}) VALUES (${placeholders})`, ...columns.map((column) => row[column]));
771
781
  }
772
782
  written++;
783
+ bumpMaxSyncedAt(row);
773
784
  } catch (error) {
774
785
  errors.push(`Row ${String(row[primaryKey] ?? "unknown")}: ${error instanceof Error ? error.message : String(error)}`);
775
786
  }
776
787
  }
777
- return { written, skipped, errors };
788
+ return { written, skipped, errors, maxSyncedAt };
778
789
  }
779
790
  function incrementalSyncPush(local, remote, tables, options = {}) {
780
791
  return runIncrementalSync("push", local, remote, local, tables, options);
@@ -812,22 +823,29 @@ function runIncrementalSync(direction, source, target, metaDb, tables, options)
812
823
  rows = source.all(`SELECT * FROM "${table}"`);
813
824
  stat.first_sync = true;
814
825
  }
826
+ let maxSyncedAt = null;
815
827
  for (let offset = 0;offset < rows.length; offset += batchSize) {
816
828
  const batch = rows.slice(offset, offset + batchSize);
817
829
  const result = transferRows(target, table, batch, options);
818
830
  stat.synced_rows += result.written;
819
831
  stat.skipped_rows += result.skipped;
820
832
  stat.errors.push(...result.errors);
833
+ if (result.maxSyncedAt !== null && (maxSyncedAt === null || result.maxSyncedAt > maxSyncedAt)) {
834
+ maxSyncedAt = result.maxSyncedAt;
835
+ }
821
836
  }
822
837
  if (rows.length === 0) {
823
838
  stat.skipped_rows = stat.total_rows;
824
839
  }
825
- upsertSyncMeta(metaDb, {
826
- table_name: table,
827
- last_synced_at: new Date().toISOString(),
828
- last_synced_row_count: stat.synced_rows,
829
- direction
830
- });
840
+ const nextCursor = maxSyncedAt ?? meta?.last_synced_at ?? null;
841
+ if (rows.length > 0 && stat.errors.length === 0 && nextCursor !== null) {
842
+ upsertSyncMeta(metaDb, {
843
+ table_name: table,
844
+ last_synced_at: nextCursor,
845
+ last_synced_row_count: stat.synced_rows,
846
+ direction
847
+ });
848
+ }
831
849
  } catch (error) {
832
850
  stat.errors.push(`Table "${table}": ${error instanceof Error ? error.message : String(error)}`);
833
851
  }
@@ -866,8 +884,13 @@ var init_storage = __esm(() => {
866
884
  data;
867
885
  closed = false;
868
886
  lastError = null;
887
+ generation = 0;
869
888
  static DATA_BYTES = 128 * 1024 * 1024;
870
- static QUERY_TIMEOUT_MS = 60000;
889
+ static queryTimeoutMs() {
890
+ const raw = process.env["MEMENTOS_PGSYNC_QUERY_TIMEOUT_MS"]?.trim();
891
+ const parsed = raw ? Number(raw) : Number.NaN;
892
+ return Number.isFinite(parsed) && parsed > 0 ? parsed : 60000;
893
+ }
871
894
  static resolveWorkerPath() {
872
895
  const ext = import.meta.url.endsWith(".ts") ? ".ts" : ".js";
873
896
  const here = fileURLToPath(new URL(".", import.meta.url));
@@ -882,12 +905,12 @@ var init_storage = __esm(() => {
882
905
  }
883
906
  return candidates[0];
884
907
  }
885
- constructor(connectionString) {
886
- const control = new SharedArrayBuffer(8);
908
+ constructor(connectionString, workerPath) {
909
+ const control = new SharedArrayBuffer(12);
887
910
  const dataSab = new SharedArrayBuffer(PgSyncPool.DATA_BYTES);
888
911
  this.status = new Int32Array(control);
889
912
  this.data = new Uint8Array(dataSab);
890
- this.worker = new Worker(PgSyncPool.resolveWorkerPath(), {
913
+ this.worker = new Worker(workerPath ?? PgSyncPool.resolveWorkerPath(), {
891
914
  workerData: {
892
915
  dsn: stripSslParams(connectionString),
893
916
  ssl: sslConfigFor(connectionString),
@@ -905,21 +928,35 @@ var init_storage = __esm(() => {
905
928
  throw new Error("PgSyncPool is closed");
906
929
  if (this.lastError)
907
930
  throw this.lastError;
931
+ const timeoutMs = PgSyncPool.queryTimeoutMs();
932
+ const gen = ++this.generation;
908
933
  Atomics.store(this.status, 0, 0);
909
- this.worker.postMessage({ sql, params });
910
- const waitResult = Atomics.wait(this.status, 0, 0, PgSyncPool.QUERY_TIMEOUT_MS);
911
- const code = Atomics.load(this.status, 0);
912
- if (code === 0 || waitResult === "timed-out") {
913
- if (this.lastError)
914
- throw this.lastError;
915
- throw new Error("PostgreSQL query timed out after 60s");
916
- }
917
- const len = Atomics.load(this.status, 1);
918
- const payload = JSON.parse(new TextDecoder().decode(this.data.subarray(0, len)));
919
- if (code === 2) {
920
- throw new Error(payload.message ?? "PostgreSQL error");
934
+ Atomics.store(this.status, 2, 0);
935
+ this.worker.postMessage({ sql, params, gen });
936
+ const deadline = Date.now() + timeoutMs;
937
+ for (;; ) {
938
+ const remaining = deadline - Date.now();
939
+ const responding = Atomics.load(this.status, 0);
940
+ if (responding === gen) {
941
+ const code = Atomics.load(this.status, 2);
942
+ const len = Atomics.load(this.status, 1);
943
+ const payload = JSON.parse(new TextDecoder().decode(this.data.subarray(0, len)));
944
+ if (code === 2) {
945
+ throw new Error(payload.message ?? "PostgreSQL error");
946
+ }
947
+ return payload;
948
+ }
949
+ if (responding !== 0) {
950
+ Atomics.compareExchange(this.status, 0, responding, 0);
951
+ continue;
952
+ }
953
+ if (remaining <= 0) {
954
+ if (this.lastError)
955
+ throw this.lastError;
956
+ throw new Error(`PostgreSQL query timed out after ${timeoutMs}ms`);
957
+ }
958
+ Atomics.wait(this.status, 0, 0, remaining);
921
959
  }
922
- return payload;
923
960
  }
924
961
  end() {
925
962
  if (this.closed)
@@ -1147,7 +1184,16 @@ x-api-key: ${cfg.apiKey}
1147
1184
  function apiJson(method, path, body, options) {
1148
1185
  const raw = apiRequestRaw(method, path, body);
1149
1186
  if (raw.status >= 200 && raw.status < 300) {
1150
- const data = raw.body.trim() ? JSON.parse(raw.body) : undefined;
1187
+ let data;
1188
+ if (raw.body.trim()) {
1189
+ try {
1190
+ data = JSON.parse(raw.body);
1191
+ } catch (e) {
1192
+ throw new ApiRequestError(`mementos cloud ${method} ${path} returned status ${raw.status} with a body that is not valid JSON (${e instanceof Error ? e.message : String(e)}) \u2014 the response is truncated or the server is unhealthy`, raw.status, raw.body.slice(0, 500));
1193
+ }
1194
+ } else {
1195
+ data = undefined;
1196
+ }
1151
1197
  return { status: raw.status, data };
1152
1198
  }
1153
1199
  if (raw.status === 404 && options?.allow404) {
@@ -2886,6 +2932,90 @@ class MementosProjectRegistrationError extends Error {
2886
2932
  }
2887
2933
  }
2888
2934
 
2935
+ // src/project-registration/historical-receipt.ts
2936
+ var ROOT_TENANT_ID = "adfd95c7-ee8b-52cb-ae47-4ae65dae3313";
2937
+ var FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION = {
2938
+ authority: "mementos",
2939
+ authority_route: "mementos.project-registration.v1",
2940
+ package_version: "1.0.0-rc.3",
2941
+ authority_id: "mementos",
2942
+ tenant_id: "default",
2943
+ corpus_id: "default",
2944
+ operation_id: "op-cli-register-full",
2945
+ step_id: "mementos_project",
2946
+ resource_kind: "project",
2947
+ direction: "forward",
2948
+ target_selector: "wks_005285827590a93b70e5",
2949
+ target_id: "mm_project_f75606ef14e51fb577a15882ba0ab8ed333b2c29",
2950
+ idempotency_key: "prk_786cdc6babddeae1be8d5078d0f75322d1ea1010ac5d8a50",
2951
+ receipt_id: "mmpr_a647f9908a33bb64bf137f584202590f91b72a33",
2952
+ request_digest: "8eb0e3fee26fdb7edb8a444aeddaaedb79a84a5a36e742ae03616f62b19f5c22",
2953
+ precondition_digest: "0b6c22fcf75d835f9f27308b1a9d40e8902e48a97da370fd56df5acacfcd968e",
2954
+ result_revision: "2026-08-09T13:37:43.068Z",
2955
+ result_digest: "26fb0dd5c5e20909d3653ab0ddd8fa45e5142728e4e66d595e2419f7ed40b036",
2956
+ created_at: "2026-08-09T13:37:43.068Z",
2957
+ identity_digest: "1108dd972c90e4989036fb6ecec7dde10f54641a697bd53cfcd64017f589ace7",
2958
+ target_digest: "72789fcd60668eeb66ee068936d3afa96deadcb007228830c64b6de783b6dcef",
2959
+ operation_digest: "d7e37bfb2c0d28f8c4086c53224cd855d14694f32807b74c102b61a99963f3c0",
2960
+ idempotency_digest: "b56d8ec37efb818759cdd2ee3b58bc1401ac13384c8d64c1813bb5c198b1e376",
2961
+ receipt_digest: "52ce90c5de6817989f107d9d27e06156962a2b9c365e34e16a57aa37886501a2",
2962
+ response_digest: "2fa3ed508f5f192c18753b1205ced996340fdf02f735420d32db897fc239805c"
2963
+ };
2964
+ var FLEET_RESOURCES_HISTORICAL_RECEIPT = {
2965
+ receipt_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.receipt_id,
2966
+ authority: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.authority,
2967
+ route: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.authority_route,
2968
+ package_version: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.package_version,
2969
+ authority_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.authority_id,
2970
+ tenant_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.tenant_id,
2971
+ corpus_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.corpus_id,
2972
+ operation_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.operation_id,
2973
+ step_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.step_id,
2974
+ resource_kind: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.resource_kind,
2975
+ direction: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.direction,
2976
+ idempotency_key: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.idempotency_key,
2977
+ request_digest: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.request_digest,
2978
+ precondition_digest: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.precondition_digest,
2979
+ outcome: "accepted",
2980
+ reason: null,
2981
+ target_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.target_id,
2982
+ result_revision: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.result_revision,
2983
+ result_digest: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.result_digest,
2984
+ duplicate_of_receipt_id: null,
2985
+ accepted_receipt_id: null,
2986
+ created_by_operation: true,
2987
+ created_at: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.created_at
2988
+ };
2989
+ var FLEET_RESOURCES_CURRENT_PROJECT_REGISTRATION_IDENTITY = {
2990
+ authority_id: "mementos",
2991
+ tenant_id: ROOT_TENANT_ID,
2992
+ corpus_id: "mementos:postgresql"
2993
+ };
2994
+ var FLEET_RESOURCES_HISTORICAL_LOOKUP_IDENTITY = {
2995
+ source: {
2996
+ authority: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.authority,
2997
+ authority_route: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.authority_route,
2998
+ package_version: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.package_version,
2999
+ authority_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.authority_id,
3000
+ tenant_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.tenant_id,
3001
+ corpus_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.corpus_id,
3002
+ operation_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.operation_id,
3003
+ step_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.step_id,
3004
+ resource_kind: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.resource_kind,
3005
+ direction: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.direction,
3006
+ target_selector: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.target_selector,
3007
+ target_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.target_id,
3008
+ idempotency_key: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.idempotency_key,
3009
+ receipt_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.receipt_id
3010
+ },
3011
+ destination: FLEET_RESOURCES_CURRENT_PROJECT_REGISTRATION_IDENTITY,
3012
+ lookup_only: true,
3013
+ immutable_receipt: true
3014
+ };
3015
+ function supportsFleetResourcesHistoricalReceiptLookup(capability) {
3016
+ return capability.authority_id === FLEET_RESOURCES_CURRENT_PROJECT_REGISTRATION_IDENTITY.authority_id && capability.tenant_id === FLEET_RESOURCES_CURRENT_PROJECT_REGISTRATION_IDENTITY.tenant_id && capability.corpus_id === FLEET_RESOURCES_CURRENT_PROJECT_REGISTRATION_IDENTITY.corpus_id;
3017
+ }
3018
+
2889
3019
  // src/project-registration/identity.ts
2890
3020
  var MEMENTOS_PROJECT_AUTHORITY_ENV = {
2891
3021
  authorityId: "MEMENTOS_PROJECT_AUTHORITY_ID",
@@ -2927,12 +3057,13 @@ function resolveMementosProjectAuthorityIdentity(options = {}) {
2927
3057
  }
2928
3058
  function buildMementosProjectRegistrationCapability(options = {}) {
2929
3059
  const identity = resolveMementosProjectAuthorityIdentity(options);
2930
- return {
3060
+ const capability = {
2931
3061
  authority: "mementos",
2932
3062
  route: MEMENTOS_PROJECT_REGISTRATION_ROUTE,
2933
3063
  package_version: options.packageVersion ?? getMementosPackageVersion(),
2934
3064
  ...identity,
2935
3065
  supported_resources: ["project"],
3066
+ supported_historical_lookup_identities: [],
2936
3067
  conditional_create: true,
2937
3068
  immutable_receipts: true,
2938
3069
  exact_terminal_lookup: true,
@@ -2951,6 +3082,12 @@ function buildMementosProjectRegistrationCapability(options = {}) {
2951
3082
  stable_keyset_pagination: true,
2952
3083
  explicit_membership_only: true
2953
3084
  };
3085
+ if (supportsFleetResourcesHistoricalReceiptLookup(capability)) {
3086
+ capability.supported_historical_lookup_identities = [
3087
+ FLEET_RESOURCES_HISTORICAL_LOOKUP_IDENTITY
3088
+ ];
3089
+ }
3090
+ return capability;
2954
3091
  }
2955
3092
 
2956
3093
  // src/db/projects.ts
@@ -4028,12 +4165,21 @@ function assertInverseRequest(request, capability) {
4028
4165
  }
4029
4166
  return accepted;
4030
4167
  }
4168
+ function matchesCurrentLookupIdentity(request, capability) {
4169
+ return request.authority_route === capability.route && request.package_version === capability.package_version && request.authority_id === capability.authority_id && request.tenant_id === capability.tenant_id && request.corpus_id === capability.corpus_id;
4170
+ }
4171
+ function matchesFleetResourcesHistoricalLookup(request, capability) {
4172
+ if (!supportsFleetResourcesHistoricalReceiptLookup(capability))
4173
+ return false;
4174
+ const source = FLEET_RESOURCES_HISTORICAL_LOOKUP_IDENTITY.source;
4175
+ return request.authority === source.authority && request.authority_route === source.authority_route && request.package_version === source.package_version && request.authority_id === source.authority_id && request.tenant_id === source.tenant_id && request.corpus_id === source.corpus_id && request.operation_id === source.operation_id && request.step_id === source.step_id && request.resource_kind === source.resource_kind && request.direction === source.direction && request.target_selector === source.target_selector && request.target_id === source.target_id && request.idempotency_key === source.idempotency_key;
4176
+ }
4031
4177
  function assertLookup(request, capability) {
4032
4178
  assertBounds(request);
4033
4179
  if (request.max_items !== 1) {
4034
4180
  throw new MementosProjectRegistrationError("MEMENTOS_PROJECT_REGISTRATION_INVALID_BOUNDS", "terminal receipt lookup requires max_items exactly 1");
4035
4181
  }
4036
- if (request.authority !== "mementos" || request.resource_kind !== "project" || request.authority_route !== capability.route || request.package_version !== capability.package_version || request.authority_id !== capability.authority_id || request.tenant_id !== capability.tenant_id || request.corpus_id !== capability.corpus_id) {
4182
+ if (request.authority !== "mementos" || request.resource_kind !== "project" || !matchesCurrentLookupIdentity(request, capability) && !matchesFleetResourcesHistoricalLookup(request, capability)) {
4037
4183
  throw new MementosProjectRegistrationError("MEMENTOS_PROJECT_REGISTRATION_CAPABILITY_MISMATCH", "receipt lookup does not match this authority capability identity");
4038
4184
  }
4039
4185
  requireString(request.operation_id, "operation_id", { pattern: OPERATION_PATTERN });
@@ -4051,6 +4197,7 @@ function assertLookup(request, capability) {
4051
4197
  pattern: PROJECT_ID_PATTERN
4052
4198
  });
4053
4199
  }
4200
+ return matchesCurrentLookupIdentity(request, capability) ? "current" : "fleet_resources_historical";
4054
4201
  }
4055
4202
 
4056
4203
  class PackageOwnedMementosProjectRegistrationAuthority {
@@ -4315,11 +4462,14 @@ class PackageOwnedMementosProjectRegistrationAuthority {
4315
4462
  }
4316
4463
  async lookupReceipt(request) {
4317
4464
  const startedAt = Date.now();
4318
- assertLookup(request, this.capabilityValue);
4465
+ const lookupIdentity = assertLookup(request, this.capabilityValue);
4319
4466
  const receipt = getReceiptForLookup(this.db, request);
4320
4467
  if (!receipt || request.target_id !== undefined && receipt.target_id !== request.target_id) {
4321
4468
  throw new MementosProjectRegistrationError("MEMENTOS_PROJECT_REGISTRATION_RECEIPT_NOT_FOUND", "exact immutable terminal receipt was not found");
4322
4469
  }
4470
+ if (lookupIdentity === "fleet_resources_historical" && (receipt.receipt_id !== FLEET_RESOURCES_HISTORICAL_LOOKUP_IDENTITY.source.receipt_id || canonicalMementosProjectRegistrationJson(publicReceipt(receipt)) !== canonicalMementosProjectRegistrationJson(FLEET_RESOURCES_HISTORICAL_RECEIPT))) {
4471
+ throw new MementosProjectRegistrationError("MEMENTOS_PROJECT_REGISTRATION_RECEIPT_NOT_FOUND", "exact immutable historical terminal receipt was not found");
4472
+ }
4323
4473
  return withResponseControl(publicReceipt(receipt), request, startedAt);
4324
4474
  }
4325
4475
  async compensate(request) {
@@ -5242,7 +5392,26 @@ function parseMemoryRow(row) {
5242
5392
  accessed_at: row["accessed_at"] || null
5243
5393
  };
5244
5394
  }
5395
+ var RESERVED_AGENT_IDS = new Set([
5396
+ "agent-a",
5397
+ "agent-x",
5398
+ "agent-z",
5399
+ "nonexistent-agent"
5400
+ ]);
5401
+ function reservedAgentIdViolation(agentId) {
5402
+ if (!agentId)
5403
+ return null;
5404
+ const normalized = agentId.trim().toLowerCase();
5405
+ if (RESERVED_AGENT_IDS.has(normalized)) {
5406
+ return `Reserved placeholder agent id "${agentId}" cannot own a memory. ` + `Refusing to write: test harnesses must not write memories under placeholder agent ` + `identities. Register a real agent (mementos register-agent <name>) and pass its id.`;
5407
+ }
5408
+ return null;
5409
+ }
5245
5410
  function createMemory(input, dedupeMode = "merge", db) {
5411
+ const reservedViolation = reservedAgentIdViolation(input.agent_id);
5412
+ if (reservedViolation) {
5413
+ throw new Error(reservedViolation);
5414
+ }
5246
5415
  if (!db && isApiMode()) {
5247
5416
  const { status, data } = apiJson("POST", "/memories", { ...input, dedupe: dedupeMode });
5248
5417
  if (!data || !data.id) {
@@ -5292,7 +5461,8 @@ function createMemory(input, dedupeMode = "merge", db) {
5292
5461
  importance = ?, metadata = ?, expires_at = ?,
5293
5462
  when_to_use = ?,
5294
5463
  pinned = COALESCE(pinned, 0),
5295
- version = version + 1, updated_at = ?
5464
+ version = version + 1, updated_at = ?,
5465
+ updated_by_agent = ?
5296
5466
  WHERE id = ?`, [
5297
5467
  safeValue,
5298
5468
  input.category || "knowledge",
@@ -5303,6 +5473,7 @@ function createMemory(input, dedupeMode = "merge", db) {
5303
5473
  expiresAt,
5304
5474
  input.when_to_use || null,
5305
5475
  timestamp,
5476
+ input.agent_id || null,
5306
5477
  existing.id
5307
5478
  ]);
5308
5479
  d.run("DELETE FROM memory_tags WHERE memory_id = ?", [existing.id]);
@@ -5476,29 +5647,7 @@ function getMemoriesByKey(key, scope, agentId, projectId, db) {
5476
5647
  const rows = d.query(sql).all(...params);
5477
5648
  return rows.map(parseMemoryRow);
5478
5649
  }
5479
- function listMemories(filter, db) {
5480
- if (!db && isApiMode()) {
5481
- const f = filter || {};
5482
- const q = toQuery({
5483
- key: f.key,
5484
- scope: f.scope,
5485
- category: f.category,
5486
- status: f.status,
5487
- tags: f.tags,
5488
- min_importance: f.min_importance,
5489
- pinned: f.pinned,
5490
- agent_id: f.agent_id,
5491
- project_id: f.project_id,
5492
- session_id: f.session_id,
5493
- namespace: f.namespace,
5494
- as_of: f.as_of,
5495
- limit: f.limit,
5496
- offset: f.offset
5497
- });
5498
- const { data } = apiJson("GET", `/memories${q}`);
5499
- return data?.memories ?? [];
5500
- }
5501
- const d = db || getDatabase();
5650
+ function buildMemoryListConditions(filter) {
5502
5651
  const conditions = [];
5503
5652
  const params = [];
5504
5653
  if (filter) {
@@ -5610,21 +5759,104 @@ function listMemories(filter, db) {
5610
5759
  } else {
5611
5760
  conditions.push("status = 'active'");
5612
5761
  }
5762
+ return { conditions, params };
5763
+ }
5764
+ function listMemoriesPage(filter, db) {
5765
+ const f = filter || {};
5766
+ if (!db && isApiMode()) {
5767
+ const q = toQuery({
5768
+ key: f.key,
5769
+ scope: f.scope,
5770
+ category: f.category,
5771
+ status: f.status,
5772
+ tags: f.tags,
5773
+ min_importance: f.min_importance,
5774
+ pinned: f.pinned,
5775
+ agent_id: f.agent_id,
5776
+ project_id: f.project_id,
5777
+ session_id: f.session_id,
5778
+ machine_id: f.machine_id,
5779
+ visible_to_machine_id: f.visible_to_machine_id,
5780
+ search: f.search,
5781
+ source: f.source,
5782
+ flag: f.flag,
5783
+ namespace: f.namespace,
5784
+ as_of: f.as_of,
5785
+ limit: f.limit,
5786
+ offset: f.offset
5787
+ });
5788
+ const { data } = apiJson("GET", `/memories${q}`);
5789
+ return {
5790
+ rows: data?.memories ?? [],
5791
+ has_more: data?.has_more,
5792
+ next_cursor: data?.next_cursor ?? null
5793
+ };
5794
+ }
5795
+ const d = db || getDatabase();
5796
+ const { conditions, params } = buildMemoryListConditions(f);
5613
5797
  let sql = "SELECT * FROM memories";
5614
5798
  if (conditions.length > 0) {
5615
5799
  sql += ` WHERE ${conditions.join(" AND ")}`;
5616
5800
  }
5617
5801
  sql += " ORDER BY importance DESC, created_at DESC";
5618
- if (filter?.limit) {
5802
+ if (f.limit) {
5619
5803
  sql += " LIMIT ?";
5620
- params.push(filter.limit);
5804
+ params.push(f.limit);
5621
5805
  }
5622
- if (filter?.offset) {
5806
+ if (f.offset) {
5623
5807
  sql += " OFFSET ?";
5624
- params.push(filter.offset);
5808
+ params.push(f.offset);
5625
5809
  }
5626
5810
  const rows = d.query(sql).all(...params);
5627
- return rows.map(parseMemoryRow);
5811
+ const parsed = rows.map(parseMemoryRow);
5812
+ const hasMore = f.limit !== undefined && parsed.length === f.limit;
5813
+ return {
5814
+ rows: parsed,
5815
+ has_more: hasMore,
5816
+ next_cursor: hasMore ? (f.offset ?? 0) + parsed.length : null
5817
+ };
5818
+ }
5819
+ function listMemories(filter, db) {
5820
+ return listMemoriesPage(filter, db).rows;
5821
+ }
5822
+ function listMemoriesBounded(filter = {}, target, db) {
5823
+ const pageSize = 1000;
5824
+ const maxPages = 1000;
5825
+ const want = target === undefined ? undefined : target + 1;
5826
+ const rows = [];
5827
+ const seenCursors = new Set;
5828
+ let cursor = filter.offset ?? 0;
5829
+ let pages = 0;
5830
+ for (;; ) {
5831
+ if (want !== undefined && rows.length >= want)
5832
+ break;
5833
+ if (++pages > maxPages) {
5834
+ throw new Error(`memories list traversal exceeded ${maxPages} pages while collecting rows \u2014 aborting (cursor cycle?)`);
5835
+ }
5836
+ const limit = Math.min(want === undefined ? pageSize : want - rows.length, pageSize);
5837
+ const page = listMemoriesPage({ ...filter, limit, offset: cursor }, db);
5838
+ rows.push(...page.rows);
5839
+ if (page.has_more === false)
5840
+ break;
5841
+ if (page.has_more === undefined && page.rows.length < limit)
5842
+ break;
5843
+ if (page.has_more === true && (page.next_cursor === null || page.next_cursor === undefined)) {
5844
+ throw new Error("memories list page claimed more results without a next cursor \u2014 aborting");
5845
+ }
5846
+ const next = page.next_cursor ?? cursor + page.rows.length;
5847
+ if (seenCursors.has(next)) {
5848
+ throw new Error("memories list traversal repeated a cursor \u2014 aborting");
5849
+ }
5850
+ seenCursors.add(next);
5851
+ cursor = next;
5852
+ }
5853
+ const hasMore = target !== undefined && rows.length > target;
5854
+ const trimmed = hasMore ? rows.slice(0, target) : rows;
5855
+ return {
5856
+ rows: trimmed,
5857
+ has_more: hasMore,
5858
+ next_cursor: hasMore ? (filter.offset ?? 0) + trimmed.length : null
5859
+ };
5628
5860
  }
5629
5861
  function updateMemory(id, input, db) {
5630
5862
  if (!db && isApiMode()) {
@@ -5690,20 +5922,29 @@ function updateMemory(id, input, db) {
5690
5922
  sets.push("when_to_use = ?");
5691
5923
  params.push(input.when_to_use ?? null);
5692
5924
  }
5925
+ if (input.updated_by_agent !== undefined) {
5926
+ sets.push("updated_by_agent = ?");
5927
+ params.push(input.updated_by_agent ?? null);
5928
+ }
5693
5929
  if (input.tags !== undefined) {
5694
5930
  sets.push("tags = ?");
5695
5931
  params.push(JSON.stringify(input.tags));
5696
- d.run("DELETE FROM memory_tags WHERE memory_id = ?", [memoryId]);
5697
- const insertTag = d.prepare("INSERT OR IGNORE INTO memory_tags (memory_id, tag) VALUES (?, ?)");
5698
- for (const tag of input.tags) {
5699
- insertTag.run(memoryId, tag);
5700
- }
5701
5932
  }
5702
5933
  params.push(memoryId);
5703
- const result = d.run(`UPDATE memories SET ${sets.join(", ")} WHERE id = ?`, params);
5704
- if (result.changes === 0) {
5705
- throw new Error(`Update affected no rows for memory ${memoryId}: the record was read but not written. ` + `This is a bug in @hasna/mementos, not a bad argument \u2014 please report it.`);
5706
- }
5934
+ d.transaction(() => {
5935
+ const res = d.run(`UPDATE memories SET ${sets.join(", ")} WHERE id = ?`, params);
5936
+ if (res.changes === 0) {
5937
+ throw new Error(`Update affected no rows for memory ${memoryId}: the record was read but not written. ` + `This is a bug in @hasna/mementos, not a bad argument \u2014 please report it.`);
5938
+ }
5939
+ if (input.tags !== undefined) {
5940
+ d.run("DELETE FROM memory_tags WHERE memory_id = ?", [memoryId]);
5941
+ const insertTag = d.prepare("INSERT OR IGNORE INTO memory_tags (memory_id, tag) VALUES (?, ?)");
5942
+ for (const tag of input.tags) {
5943
+ insertTag.run(memoryId, tag);
5944
+ }
5945
+ }
5946
+ return res;
5947
+ });
5707
5948
  const updated = getMemory(memoryId, d);
5708
5949
  if (input.value !== undefined) {
5709
5950
  try {