@hasna/mementos 0.14.85 → 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 (564) hide show
  1. package/bun.lock +63 -4
  2. package/dist/cli/index.js +419 -188
  3. package/dist/diagnostics/historical-project-registration-receipt.js +36 -17
  4. package/dist/index.js +139 -50
  5. package/dist/mcp/index.js +181 -60
  6. package/dist/pg-sync-worker.js +7 -5
  7. package/dist/project-registration.js +108 -36
  8. package/dist/sdk/index.js +1 -0
  9. package/dist/server/index.js +384 -280
  10. package/dist/storage.js +63 -26
  11. package/hasna.contract.json +5 -4
  12. package/package.json +4 -3
  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 -150
  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 -120
  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 -193
  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/diagnostics/historical-project-registration-receipt.d.ts +0 -39
  188. package/dist/diagnostics/historical-project-registration-receipt.d.ts.map +0 -1
  189. package/dist/generated/storage-kit/backend.d.ts +0 -20
  190. package/dist/generated/storage-kit/backend.d.ts.map +0 -1
  191. package/dist/generated/storage-kit/health.d.ts +0 -20
  192. package/dist/generated/storage-kit/health.d.ts.map +0 -1
  193. package/dist/generated/storage-kit/index.d.ts +0 -8
  194. package/dist/generated/storage-kit/index.d.ts.map +0 -1
  195. package/dist/generated/storage-kit/migrations.d.ts +0 -48
  196. package/dist/generated/storage-kit/migrations.d.ts.map +0 -1
  197. package/dist/generated/storage-kit/own.d.ts +0 -11
  198. package/dist/generated/storage-kit/own.d.ts.map +0 -1
  199. package/dist/generated/storage-kit/pool.d.ts +0 -35
  200. package/dist/generated/storage-kit/pool.d.ts.map +0 -1
  201. package/dist/generated/storage-kit/query.d.ts +0 -36
  202. package/dist/generated/storage-kit/query.d.ts.map +0 -1
  203. package/dist/generated/storage-kit/tls.d.ts +0 -53
  204. package/dist/generated/storage-kit/tls.d.ts.map +0 -1
  205. package/dist/index.d.ts +0 -45
  206. package/dist/index.d.ts.map +0 -1
  207. package/dist/lib/activation-matcher.d.ts +0 -17
  208. package/dist/lib/activation-matcher.d.ts.map +0 -1
  209. package/dist/lib/asmr/categorizer.d.ts +0 -31
  210. package/dist/lib/asmr/categorizer.d.ts.map +0 -1
  211. package/dist/lib/asmr/context-agent.d.ts +0 -4
  212. package/dist/lib/asmr/context-agent.d.ts.map +0 -1
  213. package/dist/lib/asmr/ensemble.d.ts +0 -23
  214. package/dist/lib/asmr/ensemble.d.ts.map +0 -1
  215. package/dist/lib/asmr/fact-agent.d.ts +0 -4
  216. package/dist/lib/asmr/fact-agent.d.ts.map +0 -1
  217. package/dist/lib/asmr/index.d.ts +0 -7
  218. package/dist/lib/asmr/index.d.ts.map +0 -1
  219. package/dist/lib/asmr/orchestrator.d.ts +0 -4
  220. package/dist/lib/asmr/orchestrator.d.ts.map +0 -1
  221. package/dist/lib/asmr/recall.d.ts +0 -3
  222. package/dist/lib/asmr/recall.d.ts.map +0 -1
  223. package/dist/lib/asmr/temporal-agent.d.ts +0 -4
  224. package/dist/lib/asmr/temporal-agent.d.ts.map +0 -1
  225. package/dist/lib/asmr/types.d.ts +0 -27
  226. package/dist/lib/asmr/types.d.ts.map +0 -1
  227. package/dist/lib/auto-inject-orchestrator.d.ts +0 -57
  228. package/dist/lib/auto-inject-orchestrator.d.ts.map +0 -1
  229. package/dist/lib/auto-memory-queue.d.ts +0 -48
  230. package/dist/lib/auto-memory-queue.d.ts.map +0 -1
  231. package/dist/lib/auto-memory.d.ts +0 -19
  232. package/dist/lib/auto-memory.d.ts.map +0 -1
  233. package/dist/lib/bench.d.ts +0 -20
  234. package/dist/lib/bench.d.ts.map +0 -1
  235. package/dist/lib/built-in-hooks.d.ts +0 -12
  236. package/dist/lib/built-in-hooks.d.ts.map +0 -1
  237. package/dist/lib/channel-pusher.d.ts +0 -39
  238. package/dist/lib/channel-pusher.d.ts.map +0 -1
  239. package/dist/lib/config.d.ts +0 -9
  240. package/dist/lib/config.d.ts.map +0 -1
  241. package/dist/lib/connectors/files.d.ts +0 -8
  242. package/dist/lib/connectors/files.d.ts.map +0 -1
  243. package/dist/lib/connectors/github.d.ts +0 -7
  244. package/dist/lib/connectors/github.d.ts.map +0 -1
  245. package/dist/lib/connectors/index.d.ts +0 -12
  246. package/dist/lib/connectors/index.d.ts.map +0 -1
  247. package/dist/lib/connectors/notion.d.ts +0 -7
  248. package/dist/lib/connectors/notion.d.ts.map +0 -1
  249. package/dist/lib/connectors/types.d.ts +0 -27
  250. package/dist/lib/connectors/types.d.ts.map +0 -1
  251. package/dist/lib/consolidation.d.ts +0 -52
  252. package/dist/lib/consolidation.d.ts.map +0 -1
  253. package/dist/lib/context-extractor.d.ts +0 -14
  254. package/dist/lib/context-extractor.d.ts.map +0 -1
  255. package/dist/lib/context.d.ts +0 -36
  256. package/dist/lib/context.d.ts.map +0 -1
  257. package/dist/lib/contradiction.d.ts +0 -50
  258. package/dist/lib/contradiction.d.ts.map +0 -1
  259. package/dist/lib/decay.d.ts +0 -35
  260. package/dist/lib/decay.d.ts.map +0 -1
  261. package/dist/lib/dedup.d.ts +0 -33
  262. package/dist/lib/dedup.d.ts.map +0 -1
  263. package/dist/lib/duration.d.ts +0 -28
  264. package/dist/lib/duration.d.ts.map +0 -1
  265. package/dist/lib/embeddings.d.ts +0 -20
  266. package/dist/lib/embeddings.d.ts.map +0 -1
  267. package/dist/lib/enum-validation.d.ts +0 -20
  268. package/dist/lib/enum-validation.d.ts.map +0 -1
  269. package/dist/lib/export-v1.d.ts +0 -30
  270. package/dist/lib/export-v1.d.ts.map +0 -1
  271. package/dist/lib/extractor.d.ts +0 -9
  272. package/dist/lib/extractor.d.ts.map +0 -1
  273. package/dist/lib/extractors/audio.d.ts +0 -8
  274. package/dist/lib/extractors/audio.d.ts.map +0 -1
  275. package/dist/lib/extractors/index.d.ts +0 -12
  276. package/dist/lib/extractors/index.d.ts.map +0 -1
  277. package/dist/lib/extractors/ocr.d.ts +0 -7
  278. package/dist/lib/extractors/ocr.d.ts.map +0 -1
  279. package/dist/lib/extractors/pdf.d.ts +0 -7
  280. package/dist/lib/extractors/pdf.d.ts.map +0 -1
  281. package/dist/lib/extractors/types.d.ts +0 -12
  282. package/dist/lib/extractors/types.d.ts.map +0 -1
  283. package/dist/lib/file-deps.d.ts +0 -27
  284. package/dist/lib/file-deps.d.ts.map +0 -1
  285. package/dist/lib/focus.d.ts +0 -58
  286. package/dist/lib/focus.d.ts.map +0 -1
  287. package/dist/lib/gatherer.d.ts +0 -16
  288. package/dist/lib/gatherer.d.ts.map +0 -1
  289. package/dist/lib/gdpr.d.ts +0 -39
  290. package/dist/lib/gdpr.d.ts.map +0 -1
  291. package/dist/lib/hooks.d.ts +0 -50
  292. package/dist/lib/hooks.d.ts.map +0 -1
  293. package/dist/lib/importers/index.d.ts +0 -38
  294. package/dist/lib/importers/index.d.ts.map +0 -1
  295. package/dist/lib/injector.d.ts +0 -89
  296. package/dist/lib/injector.d.ts.map +0 -1
  297. package/dist/lib/machine-visibility.d.ts +0 -6
  298. package/dist/lib/machine-visibility.d.ts.map +0 -1
  299. package/dist/lib/matryoshka.d.ts +0 -50
  300. package/dist/lib/matryoshka.d.ts.map +0 -1
  301. package/dist/lib/memory-lock.d.ts +0 -58
  302. package/dist/lib/memory-lock.d.ts.map +0 -1
  303. package/dist/lib/model-config.d.ts +0 -14
  304. package/dist/lib/model-config.d.ts.map +0 -1
  305. package/dist/lib/open-sessions-connector.d.ts +0 -60
  306. package/dist/lib/open-sessions-connector.d.ts.map +0 -1
  307. package/dist/lib/package-version.d.ts +0 -3
  308. package/dist/lib/package-version.d.ts.map +0 -1
  309. package/dist/lib/poisoning.d.ts +0 -19
  310. package/dist/lib/poisoning.d.ts.map +0 -1
  311. package/dist/lib/poll.d.ts +0 -17
  312. package/dist/lib/poll.d.ts.map +0 -1
  313. package/dist/lib/procedural-extractor.d.ts +0 -21
  314. package/dist/lib/procedural-extractor.d.ts.map +0 -1
  315. package/dist/lib/profile-sync.d.ts +0 -20
  316. package/dist/lib/profile-sync.d.ts.map +0 -1
  317. package/dist/lib/profile-synthesizer.d.ts +0 -20
  318. package/dist/lib/profile-synthesizer.d.ts.map +0 -1
  319. package/dist/lib/project-detect.d.ts +0 -18
  320. package/dist/lib/project-detect.d.ts.map +0 -1
  321. package/dist/lib/project-panel.d.ts +0 -7
  322. package/dist/lib/project-panel.d.ts.map +0 -1
  323. package/dist/lib/providers/anthropic.d.ts +0 -21
  324. package/dist/lib/providers/anthropic.d.ts.map +0 -1
  325. package/dist/lib/providers/base.d.ts +0 -96
  326. package/dist/lib/providers/base.d.ts.map +0 -1
  327. package/dist/lib/providers/cerebras.d.ts +0 -20
  328. package/dist/lib/providers/cerebras.d.ts.map +0 -1
  329. package/dist/lib/providers/grok.d.ts +0 -19
  330. package/dist/lib/providers/grok.d.ts.map +0 -1
  331. package/dist/lib/providers/index.d.ts +0 -7
  332. package/dist/lib/providers/index.d.ts.map +0 -1
  333. package/dist/lib/providers/openai-compat.d.ts +0 -18
  334. package/dist/lib/providers/openai-compat.d.ts.map +0 -1
  335. package/dist/lib/providers/openai.d.ts +0 -20
  336. package/dist/lib/providers/openai.d.ts.map +0 -1
  337. package/dist/lib/providers/registry.d.ts +0 -38
  338. package/dist/lib/providers/registry.d.ts.map +0 -1
  339. package/dist/lib/quality.d.ts +0 -16
  340. package/dist/lib/quality.d.ts.map +0 -1
  341. package/dist/lib/redact.d.ts +0 -10
  342. package/dist/lib/redact.d.ts.map +0 -1
  343. package/dist/lib/reflection.d.ts +0 -83
  344. package/dist/lib/reflection.d.ts.map +0 -1
  345. package/dist/lib/retention.d.ts +0 -17
  346. package/dist/lib/retention.d.ts.map +0 -1
  347. package/dist/lib/retired-storage-mode.d.ts +0 -11
  348. package/dist/lib/retired-storage-mode.d.ts.map +0 -1
  349. package/dist/lib/search.d.ts +0 -52
  350. package/dist/lib/search.d.ts.map +0 -1
  351. package/dist/lib/session-auto-resolve.d.ts +0 -28
  352. package/dist/lib/session-auto-resolve.d.ts.map +0 -1
  353. package/dist/lib/session-processor.d.ts +0 -38
  354. package/dist/lib/session-processor.d.ts.map +0 -1
  355. package/dist/lib/session-queue.d.ts +0 -28
  356. package/dist/lib/session-queue.d.ts.map +0 -1
  357. package/dist/lib/session-registry.d.ts +0 -47
  358. package/dist/lib/session-registry.d.ts.map +0 -1
  359. package/dist/lib/session-start-briefing.d.ts +0 -10
  360. package/dist/lib/session-start-briefing.d.ts.map +0 -1
  361. package/dist/lib/session-watcher.d.ts +0 -30
  362. package/dist/lib/session-watcher.d.ts.map +0 -1
  363. package/dist/lib/storage-sync.d.ts +0 -45
  364. package/dist/lib/storage-sync.d.ts.map +0 -1
  365. package/dist/lib/sync.d.ts +0 -10
  366. package/dist/lib/sync.d.ts.map +0 -1
  367. package/dist/lib/synthesis/corpus-builder.d.ts +0 -30
  368. package/dist/lib/synthesis/corpus-builder.d.ts.map +0 -1
  369. package/dist/lib/synthesis/executor.d.ts +0 -14
  370. package/dist/lib/synthesis/executor.d.ts.map +0 -1
  371. package/dist/lib/synthesis/index.d.ts +0 -37
  372. package/dist/lib/synthesis/index.d.ts.map +0 -1
  373. package/dist/lib/synthesis/llm-analyzer.d.ts +0 -18
  374. package/dist/lib/synthesis/llm-analyzer.d.ts.map +0 -1
  375. package/dist/lib/synthesis/metrics.d.ts +0 -13
  376. package/dist/lib/synthesis/metrics.d.ts.map +0 -1
  377. package/dist/lib/synthesis/scheduler.d.ts +0 -18
  378. package/dist/lib/synthesis/scheduler.d.ts.map +0 -1
  379. package/dist/lib/synthesis/validator.d.ts +0 -19
  380. package/dist/lib/synthesis/validator.d.ts.map +0 -1
  381. package/dist/lib/task-runner.d.ts +0 -37
  382. package/dist/lib/task-runner.d.ts.map +0 -1
  383. package/dist/lib/tool-lesson-extractor.d.ts +0 -24
  384. package/dist/lib/tool-lesson-extractor.d.ts.map +0 -1
  385. package/dist/lib/tool-memory-synthesizer.d.ts +0 -28
  386. package/dist/lib/tool-memory-synthesizer.d.ts.map +0 -1
  387. package/dist/lib/topic-clusterer.d.ts +0 -21
  388. package/dist/lib/topic-clusterer.d.ts.map +0 -1
  389. package/dist/lib/when-to-use-generator.d.ts +0 -22
  390. package/dist/lib/when-to-use-generator.d.ts.map +0 -1
  391. package/dist/mcp/http.d.ts +0 -17
  392. package/dist/mcp/http.d.ts.map +0 -1
  393. package/dist/mcp/index.d.ts +0 -6
  394. package/dist/mcp/index.d.ts.map +0 -1
  395. package/dist/mcp/memory-broadcast.d.ts +0 -12
  396. package/dist/mcp/memory-broadcast.d.ts.map +0 -1
  397. package/dist/mcp/tools/agent-tools.d.ts +0 -3
  398. package/dist/mcp/tools/agent-tools.d.ts.map +0 -1
  399. package/dist/mcp/tools/auto-memory-tools.d.ts +0 -5
  400. package/dist/mcp/tools/auto-memory-tools.d.ts.map +0 -1
  401. package/dist/mcp/tools/bulk-tools.d.ts +0 -3
  402. package/dist/mcp/tools/bulk-tools.d.ts.map +0 -1
  403. package/dist/mcp/tools/consolidation-tools.d.ts +0 -3
  404. package/dist/mcp/tools/consolidation-tools.d.ts.map +0 -1
  405. package/dist/mcp/tools/focus-tools.d.ts +0 -3
  406. package/dist/mcp/tools/focus-tools.d.ts.map +0 -1
  407. package/dist/mcp/tools/graph-entity-tools.d.ts +0 -3
  408. package/dist/mcp/tools/graph-entity-tools.d.ts.map +0 -1
  409. package/dist/mcp/tools/graph-query-tools.d.ts +0 -3
  410. package/dist/mcp/tools/graph-query-tools.d.ts.map +0 -1
  411. package/dist/mcp/tools/graph-relation-tools.d.ts +0 -3
  412. package/dist/mcp/tools/graph-relation-tools.d.ts.map +0 -1
  413. package/dist/mcp/tools/graph-tools.d.ts +0 -3
  414. package/dist/mcp/tools/graph-tools.d.ts.map +0 -1
  415. package/dist/mcp/tools/graph-utils.d.ts +0 -5
  416. package/dist/mcp/tools/graph-utils.d.ts.map +0 -1
  417. package/dist/mcp/tools/hook-tools.d.ts +0 -3
  418. package/dist/mcp/tools/hook-tools.d.ts.map +0 -1
  419. package/dist/mcp/tools/lock-tools.d.ts +0 -3
  420. package/dist/mcp/tools/lock-tools.d.ts.map +0 -1
  421. package/dist/mcp/tools/memory-audit.d.ts +0 -3
  422. package/dist/mcp/tools/memory-audit.d.ts.map +0 -1
  423. package/dist/mcp/tools/memory-crud.d.ts +0 -3
  424. package/dist/mcp/tools/memory-crud.d.ts.map +0 -1
  425. package/dist/mcp/tools/memory-health.d.ts +0 -3
  426. package/dist/mcp/tools/memory-health.d.ts.map +0 -1
  427. package/dist/mcp/tools/memory-history.d.ts +0 -3
  428. package/dist/mcp/tools/memory-history.d.ts.map +0 -1
  429. package/dist/mcp/tools/memory-inject.d.ts +0 -3
  430. package/dist/mcp/tools/memory-inject.d.ts.map +0 -1
  431. package/dist/mcp/tools/memory-io.d.ts +0 -3
  432. package/dist/mcp/tools/memory-io.d.ts.map +0 -1
  433. package/dist/mcp/tools/memory-lifecycle.d.ts +0 -3
  434. package/dist/mcp/tools/memory-lifecycle.d.ts.map +0 -1
  435. package/dist/mcp/tools/memory-search.d.ts +0 -3
  436. package/dist/mcp/tools/memory-search.d.ts.map +0 -1
  437. package/dist/mcp/tools/memory-stats.d.ts +0 -3
  438. package/dist/mcp/tools/memory-stats.d.ts.map +0 -1
  439. package/dist/mcp/tools/memory-tools.d.ts +0 -17
  440. package/dist/mcp/tools/memory-tools.d.ts.map +0 -1
  441. package/dist/mcp/tools/memory-utils.d.ts +0 -27
  442. package/dist/mcp/tools/memory-utils.d.ts.map +0 -1
  443. package/dist/mcp/tools/memory-validation.d.ts +0 -3
  444. package/dist/mcp/tools/memory-validation.d.ts.map +0 -1
  445. package/dist/mcp/tools/project-tools.d.ts +0 -3
  446. package/dist/mcp/tools/project-tools.d.ts.map +0 -1
  447. package/dist/mcp/tools/session-tools.d.ts +0 -3
  448. package/dist/mcp/tools/session-tools.d.ts.map +0 -1
  449. package/dist/mcp/tools/storage-tools.d.ts +0 -3
  450. package/dist/mcp/tools/storage-tools.d.ts.map +0 -1
  451. package/dist/mcp/tools/synthesis-tools.d.ts +0 -3
  452. package/dist/mcp/tools/synthesis-tools.d.ts.map +0 -1
  453. package/dist/mcp/tools/system-tools-events.d.ts +0 -3
  454. package/dist/mcp/tools/system-tools-events.d.ts.map +0 -1
  455. package/dist/mcp/tools/system-tools-memory-admin.d.ts +0 -3
  456. package/dist/mcp/tools/system-tools-memory-admin.d.ts.map +0 -1
  457. package/dist/mcp/tools/system-tools-shared.d.ts +0 -23
  458. package/dist/mcp/tools/system-tools-shared.d.ts.map +0 -1
  459. package/dist/mcp/tools/system-tools.d.ts +0 -3
  460. package/dist/mcp/tools/system-tools.d.ts.map +0 -1
  461. package/dist/mcp/tools/tool-registry.d.ts +0 -30
  462. package/dist/mcp/tools/tool-registry.d.ts.map +0 -1
  463. package/dist/mcp/tools/utility-tools.d.ts +0 -3
  464. package/dist/mcp/tools/utility-tools.d.ts.map +0 -1
  465. package/dist/memory-project-link/index.d.ts +0 -2
  466. package/dist/memory-project-link/index.d.ts.map +0 -1
  467. package/dist/memory-project-link/schema.d.ts +0 -5
  468. package/dist/memory-project-link/schema.d.ts.map +0 -1
  469. package/dist/pg-sync-worker.d.ts +0 -2
  470. package/dist/pg-sync-worker.d.ts.map +0 -1
  471. package/dist/project-registration/authority.d.ts +0 -43
  472. package/dist/project-registration/authority.d.ts.map +0 -1
  473. package/dist/project-registration/historical-receipt.d.ts +0 -38
  474. package/dist/project-registration/historical-receipt.d.ts.map +0 -1
  475. package/dist/project-registration/http.d.ts +0 -32
  476. package/dist/project-registration/http.d.ts.map +0 -1
  477. package/dist/project-registration/identity.d.ts +0 -20
  478. package/dist/project-registration/identity.d.ts.map +0 -1
  479. package/dist/project-registration/index.d.ts +0 -11
  480. package/dist/project-registration/index.d.ts.map +0 -1
  481. package/dist/project-registration/project-references.d.ts +0 -71
  482. package/dist/project-registration/project-references.d.ts.map +0 -1
  483. package/dist/project-registration/project-resources.d.ts +0 -22
  484. package/dist/project-registration/project-resources.d.ts.map +0 -1
  485. package/dist/project-registration/schema.d.ts +0 -5
  486. package/dist/project-registration/schema.d.ts.map +0 -1
  487. package/dist/project-registration/types.d.ts +0 -319
  488. package/dist/project-registration/types.d.ts.map +0 -1
  489. package/dist/project-registration.d.ts +0 -2
  490. package/dist/project-registration.d.ts.map +0 -1
  491. package/dist/sdk/index.d.ts +0 -978
  492. package/dist/sdk/index.d.ts.map +0 -1
  493. package/dist/server/auth.d.ts +0 -11
  494. package/dist/server/auth.d.ts.map +0 -1
  495. package/dist/server/helpers.d.ts +0 -22
  496. package/dist/server/helpers.d.ts.map +0 -1
  497. package/dist/server/index.d.ts +0 -14
  498. package/dist/server/index.d.ts.map +0 -1
  499. package/dist/server/openapi.d.ts +0 -2
  500. package/dist/server/openapi.d.ts.map +0 -1
  501. package/dist/server/router.d.ts +0 -17
  502. package/dist/server/router.d.ts.map +0 -1
  503. package/dist/server/routes/agents.d.ts +0 -2
  504. package/dist/server/routes/agents.d.ts.map +0 -1
  505. package/dist/server/routes/entities.d.ts +0 -2
  506. package/dist/server/routes/entities.d.ts.map +0 -1
  507. package/dist/server/routes/memories-bulk.d.ts +0 -2
  508. package/dist/server/routes/memories-bulk.d.ts.map +0 -1
  509. package/dist/server/routes/memories-crud.d.ts +0 -2
  510. package/dist/server/routes/memories-crud.d.ts.map +0 -1
  511. package/dist/server/routes/memories-io.d.ts +0 -2
  512. package/dist/server/routes/memories-io.d.ts.map +0 -1
  513. package/dist/server/routes/memories-misc.d.ts +0 -2
  514. package/dist/server/routes/memories-misc.d.ts.map +0 -1
  515. package/dist/server/routes/memories-search.d.ts +0 -2
  516. package/dist/server/routes/memories-search.d.ts.map +0 -1
  517. package/dist/server/routes/memories-stats.d.ts +0 -2
  518. package/dist/server/routes/memories-stats.d.ts.map +0 -1
  519. package/dist/server/routes/memories.d.ts +0 -19
  520. package/dist/server/routes/memories.d.ts.map +0 -1
  521. package/dist/server/routes/memory-project-link.d.ts +0 -2
  522. package/dist/server/routes/memory-project-link.d.ts.map +0 -1
  523. package/dist/server/routes/project-registration.d.ts +0 -2
  524. package/dist/server/routes/project-registration.d.ts.map +0 -1
  525. package/dist/server/routes/projects.d.ts +0 -2
  526. package/dist/server/routes/projects.d.ts.map +0 -1
  527. package/dist/server/routes/system-auto-memory.d.ts +0 -2
  528. package/dist/server/routes/system-auto-memory.d.ts.map +0 -1
  529. package/dist/server/routes/system-chain.d.ts +0 -2
  530. package/dist/server/routes/system-chain.d.ts.map +0 -1
  531. package/dist/server/routes/system-consolidation.d.ts +0 -2
  532. package/dist/server/routes/system-consolidation.d.ts.map +0 -1
  533. package/dist/server/routes/system-hooks.d.ts +0 -2
  534. package/dist/server/routes/system-hooks.d.ts.map +0 -1
  535. package/dist/server/routes/system-sessions.d.ts +0 -2
  536. package/dist/server/routes/system-sessions.d.ts.map +0 -1
  537. package/dist/server/routes/system-subscriptions.d.ts +0 -2
  538. package/dist/server/routes/system-subscriptions.d.ts.map +0 -1
  539. package/dist/server/routes/system-synthesis.d.ts +0 -2
  540. package/dist/server/routes/system-synthesis.d.ts.map +0 -1
  541. package/dist/server/routes/system-tools.d.ts +0 -2
  542. package/dist/server/routes/system-tools.d.ts.map +0 -1
  543. package/dist/server/routes/system.d.ts +0 -2
  544. package/dist/server/routes/system.d.ts.map +0 -1
  545. package/dist/server/routes/tasks.d.ts +0 -2
  546. package/dist/server/routes/tasks.d.ts.map +0 -1
  547. package/dist/storage.d.ts +0 -266
  548. package/dist/storage.d.ts.map +0 -1
  549. package/dist/test-support/memories-page-stub-server.d.ts +0 -2
  550. package/dist/test-support/memories-page-stub-server.d.ts.map +0 -1
  551. package/dist/test-support/memories-page-stub.d.ts +0 -28
  552. package/dist/test-support/memories-page-stub.d.ts.map +0 -1
  553. package/dist/test-support/preload-local-store.d.ts +0 -2
  554. package/dist/test-support/preload-local-store.d.ts.map +0 -1
  555. package/dist/test-support/project-authority-identity.d.ts +0 -8
  556. package/dist/test-support/project-authority-identity.d.ts.map +0 -1
  557. package/dist/test-support/store-isolation.d.ts +0 -108
  558. package/dist/test-support/store-isolation.d.ts.map +0 -1
  559. package/dist/test-support/strip-ansi.d.ts +0 -3
  560. package/dist/test-support/strip-ansi.d.ts.map +0 -1
  561. package/dist/types/hooks.d.ts +0 -136
  562. package/dist/types/hooks.d.ts.map +0 -1
  563. package/dist/types/index.d.ts +0 -472
  564. package/dist/types/index.d.ts.map +0 -1
@@ -243,6 +243,7 @@ function translateSql(sql) {
243
243
  let translated = sql.replace(/\?/g, () => `$${++parameterIndex}`);
244
244
  const ISO_FMT = `'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"'`;
245
245
  translated = translated.replace(/datetime\s*\(\s*'now'\s*\)/gi, `to_char(now() AT TIME ZONE 'UTC', ${ISO_FMT})`);
246
+ 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})`);
246
247
  translated = translated.replace(/datetime\s*\(\s*'now'\s*,\s*'(-?\d+)\s+(minutes?|hours?|days?|seconds?)'\s*\)/gi, (_match, amount, unit) => {
247
248
  const parsed = parseInt(String(amount), 10);
248
249
  const absolute = Math.abs(parsed);
@@ -524,8 +525,13 @@ var init_storage = __esm(() => {
524
525
  data;
525
526
  closed = false;
526
527
  lastError = null;
528
+ generation = 0;
527
529
  static DATA_BYTES = 128 * 1024 * 1024;
528
- static QUERY_TIMEOUT_MS = 60000;
530
+ static queryTimeoutMs() {
531
+ const raw = process.env["MEMENTOS_PGSYNC_QUERY_TIMEOUT_MS"]?.trim();
532
+ const parsed = raw ? Number(raw) : Number.NaN;
533
+ return Number.isFinite(parsed) && parsed > 0 ? parsed : 60000;
534
+ }
529
535
  static resolveWorkerPath() {
530
536
  const ext = import.meta.url.endsWith(".ts") ? ".ts" : ".js";
531
537
  const here = fileURLToPath(new URL(".", import.meta.url));
@@ -540,12 +546,12 @@ var init_storage = __esm(() => {
540
546
  }
541
547
  return candidates[0];
542
548
  }
543
- constructor(connectionString) {
544
- const control = new SharedArrayBuffer(8);
549
+ constructor(connectionString, workerPath) {
550
+ const control = new SharedArrayBuffer(12);
545
551
  const dataSab = new SharedArrayBuffer(PgSyncPool.DATA_BYTES);
546
552
  this.status = new Int32Array(control);
547
553
  this.data = new Uint8Array(dataSab);
548
- this.worker = new Worker(PgSyncPool.resolveWorkerPath(), {
554
+ this.worker = new Worker(workerPath ?? PgSyncPool.resolveWorkerPath(), {
549
555
  workerData: {
550
556
  dsn: stripSslParams(connectionString),
551
557
  ssl: sslConfigFor(connectionString),
@@ -563,21 +569,35 @@ var init_storage = __esm(() => {
563
569
  throw new Error("PgSyncPool is closed");
564
570
  if (this.lastError)
565
571
  throw this.lastError;
572
+ const timeoutMs = PgSyncPool.queryTimeoutMs();
573
+ const gen = ++this.generation;
566
574
  Atomics.store(this.status, 0, 0);
567
- this.worker.postMessage({ sql, params });
568
- const waitResult = Atomics.wait(this.status, 0, 0, PgSyncPool.QUERY_TIMEOUT_MS);
569
- const code = Atomics.load(this.status, 0);
570
- if (code === 0 || waitResult === "timed-out") {
571
- if (this.lastError)
572
- throw this.lastError;
573
- throw new Error("PostgreSQL query timed out after 60s");
574
- }
575
- const len = Atomics.load(this.status, 1);
576
- const payload = JSON.parse(new TextDecoder().decode(this.data.subarray(0, len)));
577
- if (code === 2) {
578
- throw new Error(payload.message ?? "PostgreSQL error");
575
+ Atomics.store(this.status, 2, 0);
576
+ this.worker.postMessage({ sql, params, gen });
577
+ const deadline = Date.now() + timeoutMs;
578
+ for (;; ) {
579
+ const remaining = deadline - Date.now();
580
+ const responding = Atomics.load(this.status, 0);
581
+ if (responding === gen) {
582
+ const code = Atomics.load(this.status, 2);
583
+ const len = Atomics.load(this.status, 1);
584
+ const payload = JSON.parse(new TextDecoder().decode(this.data.subarray(0, len)));
585
+ if (code === 2) {
586
+ throw new Error(payload.message ?? "PostgreSQL error");
587
+ }
588
+ return payload;
589
+ }
590
+ if (responding !== 0) {
591
+ Atomics.compareExchange(this.status, 0, responding, 0);
592
+ continue;
593
+ }
594
+ if (remaining <= 0) {
595
+ if (this.lastError)
596
+ throw this.lastError;
597
+ throw new Error(`PostgreSQL query timed out after ${timeoutMs}ms`);
598
+ }
599
+ Atomics.wait(this.status, 0, 0, remaining);
579
600
  }
580
- return payload;
581
601
  }
582
602
  end() {
583
603
  if (this.closed)
@@ -2704,6 +2724,7 @@ __export(exports_memories, {
2704
2724
  updateMemory: () => updateMemory,
2705
2725
  touchMemory: () => touchMemory,
2706
2726
  semanticSearch: () => semanticSearch,
2727
+ reservedAgentIdViolation: () => reservedAgentIdViolation,
2707
2728
  parseMemoryRow: () => parseMemoryRow,
2708
2729
  listMemoryHistoryPage: () => listMemoryHistoryPage,
2709
2730
  listMemoryHistory: () => listMemoryHistory,
@@ -2775,7 +2796,20 @@ function parseMemoryRow(row) {
2775
2796
  accessed_at: row["accessed_at"] || null
2776
2797
  };
2777
2798
  }
2799
+ function reservedAgentIdViolation(agentId) {
2800
+ if (!agentId)
2801
+ return null;
2802
+ const normalized = agentId.trim().toLowerCase();
2803
+ if (RESERVED_AGENT_IDS.has(normalized)) {
2804
+ 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.`;
2805
+ }
2806
+ return null;
2807
+ }
2778
2808
  function createMemory(input, dedupeMode = "merge", db) {
2809
+ const reservedViolation = reservedAgentIdViolation(input.agent_id);
2810
+ if (reservedViolation) {
2811
+ throw new Error(reservedViolation);
2812
+ }
2779
2813
  if (!db && isApiMode()) {
2780
2814
  const { status, data } = apiJson("POST", "/memories", { ...input, dedupe: dedupeMode });
2781
2815
  if (!data || !data.id) {
@@ -2825,7 +2859,8 @@ function createMemory(input, dedupeMode = "merge", db) {
2825
2859
  importance = ?, metadata = ?, expires_at = ?,
2826
2860
  when_to_use = ?,
2827
2861
  pinned = COALESCE(pinned, 0),
2828
- version = version + 1, updated_at = ?
2862
+ version = version + 1, updated_at = ?,
2863
+ updated_by_agent = ?
2829
2864
  WHERE id = ?`, [
2830
2865
  safeValue,
2831
2866
  input.category || "knowledge",
@@ -2836,6 +2871,7 @@ function createMemory(input, dedupeMode = "merge", db) {
2836
2871
  expiresAt,
2837
2872
  input.when_to_use || null,
2838
2873
  timestamp,
2874
+ input.agent_id || null,
2839
2875
  existing.id
2840
2876
  ]);
2841
2877
  d.run("DELETE FROM memory_tags WHERE memory_id = ?", [existing.id]);
@@ -2940,6 +2976,12 @@ function bulkUpsertMemories(memories, db) {
2940
2976
  errors.push(`Rejected "${key}": ${formatEnumViolation(violation)}`);
2941
2977
  continue;
2942
2978
  }
2979
+ const agentViolation = reservedAgentIdViolation(typeof mem["agent_id"] === "string" ? mem["agent_id"] : undefined);
2980
+ if (agentViolation) {
2981
+ rejected++;
2982
+ errors.push(`Rejected "${key}": ${agentViolation}`);
2983
+ continue;
2984
+ }
2943
2985
  const timestamp = now();
2944
2986
  let tags = [];
2945
2987
  const rawTags = mem["tags"];
@@ -3218,6 +3260,11 @@ function listMemoriesPage(filter, db) {
3218
3260
  agent_id: f.agent_id,
3219
3261
  project_id: f.project_id,
3220
3262
  session_id: f.session_id,
3263
+ machine_id: f.machine_id,
3264
+ visible_to_machine_id: f.visible_to_machine_id,
3265
+ search: f.search,
3266
+ source: f.source,
3267
+ flag: f.flag,
3221
3268
  namespace: f.namespace,
3222
3269
  as_of: f.as_of,
3223
3270
  limit: f.limit,
@@ -3497,20 +3544,29 @@ function updateMemory(id, input, db) {
3497
3544
  sets.push("when_to_use = ?");
3498
3545
  params.push(input.when_to_use ?? null);
3499
3546
  }
3547
+ if (input.updated_by_agent !== undefined) {
3548
+ sets.push("updated_by_agent = ?");
3549
+ params.push(input.updated_by_agent ?? null);
3550
+ }
3500
3551
  if (input.tags !== undefined) {
3501
3552
  sets.push("tags = ?");
3502
3553
  params.push(JSON.stringify(input.tags));
3503
- d.run("DELETE FROM memory_tags WHERE memory_id = ?", [memoryId]);
3504
- const insertTag = d.prepare("INSERT OR IGNORE INTO memory_tags (memory_id, tag) VALUES (?, ?)");
3505
- for (const tag of input.tags) {
3506
- insertTag.run(memoryId, tag);
3507
- }
3508
3554
  }
3509
3555
  params.push(memoryId);
3510
- const result = d.run(`UPDATE memories SET ${sets.join(", ")} WHERE id = ?`, params);
3511
- if (result.changes === 0) {
3512
- 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.`);
3513
- }
3556
+ d.transaction(() => {
3557
+ const res = d.run(`UPDATE memories SET ${sets.join(", ")} WHERE id = ?`, params);
3558
+ if (res.changes === 0) {
3559
+ 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.`);
3560
+ }
3561
+ if (input.tags !== undefined) {
3562
+ d.run("DELETE FROM memory_tags WHERE memory_id = ?", [memoryId]);
3563
+ const insertTag = d.prepare("INSERT OR IGNORE INTO memory_tags (memory_id, tag) VALUES (?, ?)");
3564
+ for (const tag of input.tags) {
3565
+ insertTag.run(memoryId, tag);
3566
+ }
3567
+ }
3568
+ return res;
3569
+ });
3514
3570
  const updated = getMemory(memoryId, d);
3515
3571
  if (input.value !== undefined) {
3516
3572
  try {
@@ -3681,7 +3737,7 @@ async function semanticSearch(queryText, options = {}, db) {
3681
3737
  scored.sort((a, b) => b.score - a.score);
3682
3738
  return scored.slice(0, limit);
3683
3739
  }
3684
- var RECALL_PROMOTE_THRESHOLD = 3;
3740
+ var RESERVED_AGENT_IDS, RECALL_PROMOTE_THRESHOLD = 3;
3685
3741
  var init_memories = __esm(() => {
3686
3742
  init_types();
3687
3743
  init_database();
@@ -3691,6 +3747,12 @@ var init_memories = __esm(() => {
3691
3747
  init_poisoning();
3692
3748
  init_entity_memories();
3693
3749
  init_api_mode();
3750
+ RESERVED_AGENT_IDS = new Set([
3751
+ "agent-a",
3752
+ "agent-x",
3753
+ "agent-z",
3754
+ "nonexistent-agent"
3755
+ ]);
3694
3756
  });
3695
3757
 
3696
3758
  // src/db/entities.ts
@@ -4273,7 +4335,7 @@ function buildFilterConditions(filter) {
4273
4335
  const conditions = [];
4274
4336
  const params = [];
4275
4337
  conditions.push("m.status = 'active'");
4276
- conditions.push("(m.expires_at IS NULL OR m.expires_at >= datetime('now'))");
4338
+ conditions.push("(m.expires_at IS NULL OR m.expires_at >= strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))");
4277
4339
  if (!filter)
4278
4340
  return { conditions, params };
4279
4341
  if (filter.scope) {
@@ -6309,7 +6371,7 @@ async function detectContradiction(newKey, newValue, options = {}, db) {
6309
6371
  conditions.push("project_id = ?");
6310
6372
  params.push(project_id);
6311
6373
  }
6312
- conditions.push("(valid_until IS NULL OR valid_until > datetime('now'))");
6374
+ conditions.push("(valid_until IS NULL OR valid_until > strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))");
6313
6375
  const sql = `SELECT * FROM memories WHERE ${conditions.join(" AND ")} ORDER BY importance DESC LIMIT 10`;
6314
6376
  const rows = d.query(sql).all(...params);
6315
6377
  if (rows.length === 0) {
@@ -55943,6 +56005,18 @@ function getNextPendingJob(db) {
55943
56005
  return null;
55944
56006
  return parseJobRow(row);
55945
56007
  }
56008
+ function claimSessionJob(id, db) {
56009
+ const d = db || getDatabase();
56010
+ const startedAt = now();
56011
+ const result = d.run("UPDATE session_memory_jobs SET status = 'processing', started_at = ? WHERE id = ? AND status = 'pending'", [startedAt, id]);
56012
+ return result.changes;
56013
+ }
56014
+ function recoverStaleProcessingJobs(maxAgeMs, db) {
56015
+ const d = db || getDatabase();
56016
+ const cutoff = new Date(Date.now() - maxAgeMs).toISOString();
56017
+ const result = d.run("UPDATE session_memory_jobs SET status = 'pending', started_at = NULL WHERE status = 'processing' AND started_at < ?", [cutoff]);
56018
+ return result.changes;
56019
+ }
55946
56020
 
55947
56021
  // src/lib/session-processor.ts
55948
56022
  init_memories();
@@ -56445,7 +56519,11 @@ async function processSessionJob(jobId, db) {
56445
56519
  return result;
56446
56520
  }
56447
56521
  try {
56448
- updateSessionJob(jobId, { status: "processing", started_at: new Date().toISOString() }, db);
56522
+ const changes = claimSessionJob(jobId, db);
56523
+ if (changes === 0) {
56524
+ result.errors.push(`Job already claimed or not pending: ${jobId}`);
56525
+ return result;
56526
+ }
56449
56527
  } catch (e) {
56450
56528
  result.errors.push(`Failed to mark job as processing: ${String(e)}`);
56451
56529
  return result;
@@ -56553,6 +56631,9 @@ function startSessionQueueWorker() {
56553
56631
  return;
56554
56632
  _workerStarted = true;
56555
56633
  setInterval(() => {
56634
+ try {
56635
+ recoverStaleProcessingJobs(30 * 60 * 1000);
56636
+ } catch {}
56556
56637
  _processNext();
56557
56638
  }, 5000);
56558
56639
  }
@@ -56824,7 +56905,7 @@ function getTaskStats(db, filter) {
56824
56905
  const priorityRows = db.query(`SELECT priority, COUNT(*) as c FROM tasks ${where} GROUP BY priority`).all(...params);
56825
56906
  for (const row of priorityRows)
56826
56907
  byPriority[row.priority] = row.c;
56827
- const overdue = db.query(`SELECT COUNT(*) as c FROM tasks ${where} AND status != 'completed' AND status != 'cancelled' AND due_at IS NOT NULL AND due_at < datetime('now')`).get(...params).c;
56908
+ const overdue = db.query(`SELECT COUNT(*) as c FROM tasks ${where} AND status != 'completed' AND status != 'cancelled' AND due_at IS NOT NULL AND due_at < strftime('%Y-%m-%dT%H:%M:%fZ', 'now')`).get(...params).c;
56828
56909
  return {
56829
56910
  total,
56830
56911
  by_status: {
@@ -56955,6 +57036,255 @@ async function _tick() {
56955
57036
 
56956
57037
  // src/server/index.ts
56957
57038
  init_storage();
57039
+
57040
+ // src/db/analytics.ts
57041
+ init_database();
57042
+ init_api_mode();
57043
+ function getMemoryStats(db) {
57044
+ if (!db && isApiMode()) {
57045
+ const { data } = apiJson("GET", "/memories/stats");
57046
+ return normalizeStats(data);
57047
+ }
57048
+ const d = db || getDatabase();
57049
+ const total = d.query("SELECT COUNT(*) as c FROM memories WHERE status = 'active'").get().c;
57050
+ const byScope = d.query("SELECT scope, COUNT(*) as c FROM memories WHERE status = 'active' GROUP BY scope").all();
57051
+ const byCategory = d.query("SELECT category, COUNT(*) as c FROM memories WHERE status = 'active' GROUP BY category").all();
57052
+ const byStatus = d.query("SELECT status, COUNT(*) as c FROM memories WHERE status = 'active' GROUP BY status").all();
57053
+ const pinnedCount = d.query("SELECT COUNT(*) as c FROM memories WHERE pinned = 1 AND status = 'active'").get().c;
57054
+ const expiredCount = d.query("SELECT COUNT(*) as c FROM memories WHERE status = 'expired'").get().c;
57055
+ const expiresAtCount = d.query("SELECT COUNT(*) as c FROM memories WHERE expires_at IS NOT NULL").get().c;
57056
+ const nowIso = new Date().toISOString();
57057
+ const expiredDueCount = d.query("SELECT COUNT(*) as c FROM memories WHERE status = 'expired' OR (expires_at IS NOT NULL AND expires_at < ?)").get(nowIso).c;
57058
+ const stats = {
57059
+ total,
57060
+ by_scope: { global: 0, shared: 0, private: 0, working: 0 },
57061
+ by_category: { preference: 0, fact: 0, knowledge: 0, history: 0, procedural: 0, resource: 0 },
57062
+ by_status: { active: 0, archived: 0, expired: 0 },
57063
+ by_agent: {},
57064
+ pinned_count: pinnedCount,
57065
+ expired_count: expiredCount,
57066
+ expires_at_count: expiresAtCount,
57067
+ expired_due_count: expiredDueCount
57068
+ };
57069
+ for (const row of byScope)
57070
+ if (row.scope in stats.by_scope)
57071
+ stats.by_scope[row.scope] = row.c;
57072
+ for (const row of byCategory)
57073
+ if (row.category in stats.by_category)
57074
+ stats.by_category[row.category] = row.c;
57075
+ for (const row of byStatus) {
57076
+ if (row.status in stats.by_status) {
57077
+ stats.by_status[row.status] = row.c;
57078
+ }
57079
+ }
57080
+ const byAgent = d.query("SELECT agent_id, COUNT(*) as c FROM memories WHERE status = 'active' AND agent_id IS NOT NULL GROUP BY agent_id").all();
57081
+ for (const row of byAgent)
57082
+ stats.by_agent[row.agent_id] = row.c;
57083
+ return stats;
57084
+ }
57085
+ function normalizeStats(data) {
57086
+ return {
57087
+ total: data?.total ?? 0,
57088
+ by_scope: { global: 0, shared: 0, private: 0, working: 0, ...data?.by_scope ?? {} },
57089
+ by_category: {
57090
+ preference: 0,
57091
+ fact: 0,
57092
+ knowledge: 0,
57093
+ history: 0,
57094
+ procedural: 0,
57095
+ resource: 0,
57096
+ ...data?.by_category ?? {}
57097
+ },
57098
+ by_status: { active: 0, archived: 0, expired: 0, ...data?.by_status ?? {} },
57099
+ by_agent: data?.by_agent ?? {},
57100
+ pinned_count: data?.pinned_count ?? 0,
57101
+ expired_count: data?.expired_count ?? 0,
57102
+ expires_at_count: data?.expires_at_count ?? 0,
57103
+ expired_due_count: data?.expired_due_count ?? 0
57104
+ };
57105
+ }
57106
+ function getMemoryActivity(filter = {}, db) {
57107
+ const days = Math.min(filter.days || 30, 365);
57108
+ if (!db && isApiMode()) {
57109
+ const q = toQuery({ days, scope: filter.scope, agent_id: filter.agent_id, project_id: filter.project_id });
57110
+ const { data } = apiJson("GET", `/activity${q}`);
57111
+ return { activity: data?.activity ?? [], days: data?.days ?? days, total: data?.total ?? 0 };
57112
+ }
57113
+ const d = db || getDatabase();
57114
+ const conditions = ["status = 'active'"];
57115
+ const params = [];
57116
+ if (filter.scope) {
57117
+ conditions.push("scope = ?");
57118
+ params.push(filter.scope);
57119
+ }
57120
+ if (filter.agent_id) {
57121
+ conditions.push("agent_id = ?");
57122
+ params.push(filter.agent_id);
57123
+ }
57124
+ if (filter.project_id) {
57125
+ conditions.push("project_id = ?");
57126
+ params.push(filter.project_id);
57127
+ }
57128
+ const where = conditions.map((c) => `AND ${c}`).join(" ");
57129
+ const cutoffDate = new Date(Date.now() - days * 86400000).toISOString().slice(0, 10);
57130
+ params.push(cutoffDate);
57131
+ const rows = d.query(`
57132
+ SELECT
57133
+ date(created_at) AS date,
57134
+ COUNT(*) AS memories_created,
57135
+ SUM(CASE WHEN scope = 'global' THEN 1 ELSE 0 END) AS global_count,
57136
+ SUM(CASE WHEN scope = 'shared' THEN 1 ELSE 0 END) AS shared_count,
57137
+ SUM(CASE WHEN scope = 'private' THEN 1 ELSE 0 END) AS private_count,
57138
+ AVG(importance) AS avg_importance
57139
+ FROM memories
57140
+ WHERE date(created_at) >= ? ${where}
57141
+ GROUP BY date(created_at)
57142
+ ORDER BY date ASC
57143
+ `).all(...params);
57144
+ return { activity: rows, days, total: rows.reduce((s, r) => s + r.memories_created, 0) };
57145
+ }
57146
+ function getMemoryReport(filter = {}, db) {
57147
+ const days = Math.min(filter.days || 7, 365);
57148
+ if (!db && isApiMode()) {
57149
+ const q = toQuery({ days, project_id: filter.project_id, agent_id: filter.agent_id });
57150
+ const { data } = apiJson("GET", `/report${q}`);
57151
+ return {
57152
+ total: data?.total ?? 0,
57153
+ pinned: data?.pinned ?? 0,
57154
+ days: data?.days ?? days,
57155
+ recent: data?.recent ?? { total: 0, activity: [] },
57156
+ by_scope: data?.by_scope ?? {},
57157
+ by_category: data?.by_category ?? {},
57158
+ top_memories: data?.top_memories ?? [],
57159
+ top_agents: data?.top_agents ?? []
57160
+ };
57161
+ }
57162
+ const d = db || getDatabase();
57163
+ const cutoffDate = new Date(Date.now() - days * 86400000).toISOString().slice(0, 10);
57164
+ const scopedCond = [
57165
+ filter.project_id ? "AND project_id = ?" : "",
57166
+ filter.agent_id ? "AND agent_id = ?" : ""
57167
+ ].filter(Boolean).join(" ");
57168
+ const scopedParams = [
57169
+ ...filter.project_id ? [filter.project_id] : [],
57170
+ ...filter.agent_id ? [filter.agent_id] : []
57171
+ ];
57172
+ const recentParams = [cutoffDate, ...scopedParams];
57173
+ const total = d.query(`SELECT COUNT(*) as c FROM memories WHERE status = 'active' ${scopedCond}`).get(...scopedParams).c;
57174
+ const pinned = d.query(`SELECT COUNT(*) as c FROM memories WHERE status = 'active' AND pinned = 1 ${scopedCond}`).get(...scopedParams).c;
57175
+ const actRows = d.query(`
57176
+ SELECT date(created_at) AS date, COUNT(*) AS memories_created
57177
+ FROM memories WHERE status = 'active' AND date(created_at) >= ? ${scopedCond}
57178
+ GROUP BY date(created_at) ORDER BY date(created_at) ASC
57179
+ `).all(...recentParams);
57180
+ const recentTotal = actRows.reduce((s, r) => s + r.memories_created, 0);
57181
+ const byScopeRows = d.query(`SELECT scope, COUNT(*) as c FROM memories WHERE status = 'active' ${scopedCond} GROUP BY scope`).all(...scopedParams);
57182
+ const byCatRows = d.query(`SELECT category, COUNT(*) as c FROM memories WHERE status = 'active' ${scopedCond} GROUP BY category`).all(...scopedParams);
57183
+ const topMems = d.query(`SELECT id, key, value, importance, scope, category FROM memories WHERE status = 'active' ${scopedCond} ORDER BY importance DESC, access_count DESC LIMIT 5`).all(...scopedParams);
57184
+ const topAgents = d.query(`SELECT agent_id, COUNT(*) as c FROM memories WHERE status = 'active' AND agent_id IS NOT NULL ${scopedCond} GROUP BY agent_id ORDER BY c DESC LIMIT 5`).all(...scopedParams);
57185
+ return {
57186
+ total,
57187
+ pinned,
57188
+ days,
57189
+ recent: { total: recentTotal, activity: actRows },
57190
+ by_scope: Object.fromEntries(byScopeRows.map((r) => [r.scope, r.c])),
57191
+ by_category: Object.fromEntries(byCatRows.map((r) => [r.category, r.c])),
57192
+ top_memories: topMems,
57193
+ top_agents: topAgents
57194
+ };
57195
+ }
57196
+ function getStaleMemoriesPage(filter = {}, db) {
57197
+ const days = Math.min(filter.days || 30, 365);
57198
+ const limit = filter.limit ?? 20;
57199
+ const offset = filter.offset ?? 0;
57200
+ if (!db && isApiMode()) {
57201
+ const q = toQuery({ days, project_id: filter.project_id, agent_id: filter.agent_id, pinned: filter.pinned, limit, offset });
57202
+ const { data } = apiJson("GET", `/memories/stale${q}`);
57203
+ const rows2 = data?.memories ?? [];
57204
+ return {
57205
+ rows: rows2,
57206
+ total: data?.total ?? rows2.length,
57207
+ has_more: data?.has_more,
57208
+ next_cursor: data?.next_cursor ?? null
57209
+ };
57210
+ }
57211
+ const d = db || getDatabase();
57212
+ const cutoffDate = new Date(Date.now() - days * 86400000).toISOString();
57213
+ const conds = ["status = 'active'", "(accessed_at IS NULL OR accessed_at < ?)"];
57214
+ const params = [cutoffDate];
57215
+ if (filter.pinned !== undefined) {
57216
+ conds.push("pinned = ?");
57217
+ params.push(filter.pinned ? 1 : 0);
57218
+ } else {
57219
+ conds.push("pinned = 0");
57220
+ }
57221
+ if (filter.project_id) {
57222
+ conds.push("project_id = ?");
57223
+ params.push(filter.project_id);
57224
+ }
57225
+ if (filter.agent_id) {
57226
+ conds.push("agent_id = ?");
57227
+ params.push(filter.agent_id);
57228
+ }
57229
+ const where = conds.join(" AND ");
57230
+ const countRow = d.query(`SELECT COUNT(*) AS c FROM memories WHERE ${where}`).get(...params);
57231
+ let sql = `SELECT id, key, value, importance, scope, category, accessed_at, access_count, created_at FROM memories WHERE ${where} ORDER BY COALESCE(accessed_at, created_at) ASC LIMIT ?`;
57232
+ params.push(limit);
57233
+ if (offset) {
57234
+ sql += " OFFSET ?";
57235
+ params.push(offset);
57236
+ }
57237
+ const rows = d.query(sql).all(...params);
57238
+ const hasMore = rows.length === limit;
57239
+ return {
57240
+ rows,
57241
+ total: countRow?.c ?? 0,
57242
+ has_more: hasMore,
57243
+ next_cursor: hasMore ? offset + rows.length : null
57244
+ };
57245
+ }
57246
+ function getMemoryHealth(filter = {}, db) {
57247
+ const staleDays = filter.stale_days ?? 30;
57248
+ const forgottenDays = filter.forgotten_days ?? 60;
57249
+ const limit = filter.limit ?? 10;
57250
+ if (!db && isApiMode()) {
57251
+ const q = toQuery({
57252
+ stale_days: staleDays,
57253
+ forgotten_days: forgottenDays,
57254
+ project_id: filter.project_id,
57255
+ agent_id: filter.agent_id,
57256
+ limit
57257
+ });
57258
+ const { data } = apiJson("GET", `/memories/health${q}`);
57259
+ return { stale: data?.stale ?? [], forgotten: data?.forgotten ?? [], dupes: data?.dupes ?? [] };
57260
+ }
57261
+ const d = db || getDatabase();
57262
+ const extraWhere = [
57263
+ ...filter.project_id ? ["project_id = ?"] : [],
57264
+ ...filter.agent_id ? ["agent_id = ?"] : []
57265
+ ].join(" AND ");
57266
+ const scopeParams = [
57267
+ ...filter.project_id ? [filter.project_id] : [],
57268
+ ...filter.agent_id ? [filter.agent_id] : []
57269
+ ];
57270
+ const staleCutoff = new Date(Date.now() - staleDays * 86400000).toISOString();
57271
+ const forgottenCutoff = new Date(Date.now() - forgottenDays * 86400000).toISOString();
57272
+ const base = `status = 'active' AND pinned = 0${extraWhere ? " AND " + extraWhere : ""}`;
57273
+ const stale = d.prepare(`SELECT id, key, value, importance, scope, created_at FROM memories
57274
+ WHERE ${base} AND access_count = 0 AND created_at < ?
57275
+ ORDER BY created_at ASC LIMIT ?`).all(...scopeParams, staleCutoff, limit);
57276
+ const forgotten = d.prepare(`SELECT id, key, value, importance, scope, accessed_at FROM memories
57277
+ WHERE ${base} AND importance >= 7
57278
+ AND (accessed_at IS NULL OR accessed_at < ?)
57279
+ ORDER BY importance DESC, COALESCE(accessed_at, created_at) ASC LIMIT ?`).all(...scopeParams, forgottenCutoff, limit);
57280
+ const dupes = d.prepare(`SELECT key, COUNT(*) as cnt, MAX(updated_at) as latest, MIN(created_at) as oldest
57281
+ FROM memories WHERE ${base}
57282
+ GROUP BY key HAVING COUNT(*) > 1
57283
+ ORDER BY cnt DESC LIMIT ?`).all(...scopeParams, limit);
57284
+ return { stale, forgotten, dupes };
57285
+ }
57286
+
57287
+ // src/server/index.ts
56958
57288
  init_router();
56959
57289
 
56960
57290
  // src/server/helpers.ts
@@ -57226,6 +57556,16 @@ addRoute("GET", "/api/memories", (_req, url) => {
57226
57556
  filter.project_id = q["project_id"];
57227
57557
  if (q["session_id"])
57228
57558
  filter.session_id = q["session_id"];
57559
+ if (q["machine_id"])
57560
+ filter.machine_id = q["machine_id"];
57561
+ if (q["visible_to_machine_id"])
57562
+ filter.visible_to_machine_id = q["visible_to_machine_id"];
57563
+ if (q["search"])
57564
+ filter.search = q["search"];
57565
+ if (q["source"])
57566
+ filter.source = q["source"].includes(",") ? q["source"].split(",") : q["source"];
57567
+ if (q["flag"])
57568
+ filter.flag = q["flag"];
57229
57569
  if (q["namespace"])
57230
57570
  filter.namespace = q["namespace"];
57231
57571
  if (q["status"])
@@ -57356,242 +57696,6 @@ addRoute("DELETE", "/api/memories/:id", (_req, _url, params) => {
57356
57696
 
57357
57697
  // src/server/routes/memories-stats.ts
57358
57698
  init_database();
57359
-
57360
- // src/db/analytics.ts
57361
- init_database();
57362
- init_api_mode();
57363
- function getMemoryStats(db) {
57364
- if (!db && isApiMode()) {
57365
- const { data } = apiJson("GET", "/memories/stats");
57366
- return normalizeStats(data);
57367
- }
57368
- const d = db || getDatabase();
57369
- const total = d.query("SELECT COUNT(*) as c FROM memories WHERE status = 'active'").get().c;
57370
- const byScope = d.query("SELECT scope, COUNT(*) as c FROM memories WHERE status = 'active' GROUP BY scope").all();
57371
- const byCategory = d.query("SELECT category, COUNT(*) as c FROM memories WHERE status = 'active' GROUP BY category").all();
57372
- const byStatus = d.query("SELECT status, COUNT(*) as c FROM memories WHERE status = 'active' GROUP BY status").all();
57373
- const pinnedCount = d.query("SELECT COUNT(*) as c FROM memories WHERE pinned = 1 AND status = 'active'").get().c;
57374
- const expiredCount = d.query("SELECT COUNT(*) as c FROM memories WHERE status = 'expired' OR (expires_at IS NOT NULL AND expires_at < datetime('now'))").get().c;
57375
- const stats = {
57376
- total,
57377
- by_scope: { global: 0, shared: 0, private: 0, working: 0 },
57378
- by_category: { preference: 0, fact: 0, knowledge: 0, history: 0, procedural: 0, resource: 0 },
57379
- by_status: { active: 0, archived: 0, expired: 0 },
57380
- by_agent: {},
57381
- pinned_count: pinnedCount,
57382
- expired_count: expiredCount
57383
- };
57384
- for (const row of byScope)
57385
- if (row.scope in stats.by_scope)
57386
- stats.by_scope[row.scope] = row.c;
57387
- for (const row of byCategory)
57388
- if (row.category in stats.by_category)
57389
- stats.by_category[row.category] = row.c;
57390
- for (const row of byStatus) {
57391
- if (row.status in stats.by_status) {
57392
- stats.by_status[row.status] = row.c;
57393
- }
57394
- }
57395
- const byAgent = d.query("SELECT agent_id, COUNT(*) as c FROM memories WHERE status = 'active' AND agent_id IS NOT NULL GROUP BY agent_id").all();
57396
- for (const row of byAgent)
57397
- stats.by_agent[row.agent_id] = row.c;
57398
- return stats;
57399
- }
57400
- function normalizeStats(data) {
57401
- return {
57402
- total: data?.total ?? 0,
57403
- by_scope: { global: 0, shared: 0, private: 0, working: 0, ...data?.by_scope ?? {} },
57404
- by_category: {
57405
- preference: 0,
57406
- fact: 0,
57407
- knowledge: 0,
57408
- history: 0,
57409
- procedural: 0,
57410
- resource: 0,
57411
- ...data?.by_category ?? {}
57412
- },
57413
- by_status: { active: 0, archived: 0, expired: 0, ...data?.by_status ?? {} },
57414
- by_agent: data?.by_agent ?? {},
57415
- pinned_count: data?.pinned_count ?? 0,
57416
- expired_count: data?.expired_count ?? 0
57417
- };
57418
- }
57419
- function getMemoryActivity(filter = {}, db) {
57420
- const days = Math.min(filter.days || 30, 365);
57421
- if (!db && isApiMode()) {
57422
- const q = toQuery({ days, scope: filter.scope, agent_id: filter.agent_id, project_id: filter.project_id });
57423
- const { data } = apiJson("GET", `/activity${q}`);
57424
- return { activity: data?.activity ?? [], days: data?.days ?? days, total: data?.total ?? 0 };
57425
- }
57426
- const d = db || getDatabase();
57427
- const conditions = ["status = 'active'"];
57428
- const params = [];
57429
- if (filter.scope) {
57430
- conditions.push("scope = ?");
57431
- params.push(filter.scope);
57432
- }
57433
- if (filter.agent_id) {
57434
- conditions.push("agent_id = ?");
57435
- params.push(filter.agent_id);
57436
- }
57437
- if (filter.project_id) {
57438
- conditions.push("project_id = ?");
57439
- params.push(filter.project_id);
57440
- }
57441
- const where = conditions.map((c) => `AND ${c}`).join(" ");
57442
- const cutoffDate = new Date(Date.now() - days * 86400000).toISOString().slice(0, 10);
57443
- params.push(cutoffDate);
57444
- const rows = d.query(`
57445
- SELECT
57446
- date(created_at) AS date,
57447
- COUNT(*) AS memories_created,
57448
- SUM(CASE WHEN scope = 'global' THEN 1 ELSE 0 END) AS global_count,
57449
- SUM(CASE WHEN scope = 'shared' THEN 1 ELSE 0 END) AS shared_count,
57450
- SUM(CASE WHEN scope = 'private' THEN 1 ELSE 0 END) AS private_count,
57451
- AVG(importance) AS avg_importance
57452
- FROM memories
57453
- WHERE date(created_at) >= ? ${where}
57454
- GROUP BY date(created_at)
57455
- ORDER BY date ASC
57456
- `).all(...params);
57457
- return { activity: rows, days, total: rows.reduce((s, r) => s + r.memories_created, 0) };
57458
- }
57459
- function getMemoryReport(filter = {}, db) {
57460
- const days = Math.min(filter.days || 7, 365);
57461
- if (!db && isApiMode()) {
57462
- const q = toQuery({ days, project_id: filter.project_id, agent_id: filter.agent_id });
57463
- const { data } = apiJson("GET", `/report${q}`);
57464
- return {
57465
- total: data?.total ?? 0,
57466
- pinned: data?.pinned ?? 0,
57467
- days: data?.days ?? days,
57468
- recent: data?.recent ?? { total: 0, activity: [] },
57469
- by_scope: data?.by_scope ?? {},
57470
- by_category: data?.by_category ?? {},
57471
- top_memories: data?.top_memories ?? [],
57472
- top_agents: data?.top_agents ?? []
57473
- };
57474
- }
57475
- const d = db || getDatabase();
57476
- const cutoffDate = new Date(Date.now() - days * 86400000).toISOString().slice(0, 10);
57477
- const scopedCond = [
57478
- filter.project_id ? "AND project_id = ?" : "",
57479
- filter.agent_id ? "AND agent_id = ?" : ""
57480
- ].filter(Boolean).join(" ");
57481
- const scopedParams = [
57482
- ...filter.project_id ? [filter.project_id] : [],
57483
- ...filter.agent_id ? [filter.agent_id] : []
57484
- ];
57485
- const recentParams = [cutoffDate, ...scopedParams];
57486
- const total = d.query(`SELECT COUNT(*) as c FROM memories WHERE status = 'active' ${scopedCond}`).get(...scopedParams).c;
57487
- const pinned = d.query(`SELECT COUNT(*) as c FROM memories WHERE status = 'active' AND pinned = 1 ${scopedCond}`).get(...scopedParams).c;
57488
- const actRows = d.query(`
57489
- SELECT date(created_at) AS date, COUNT(*) AS memories_created
57490
- FROM memories WHERE status = 'active' AND date(created_at) >= ? ${scopedCond}
57491
- GROUP BY date(created_at) ORDER BY date(created_at) ASC
57492
- `).all(...recentParams);
57493
- const recentTotal = actRows.reduce((s, r) => s + r.memories_created, 0);
57494
- const byScopeRows = d.query(`SELECT scope, COUNT(*) as c FROM memories WHERE status = 'active' ${scopedCond} GROUP BY scope`).all(...scopedParams);
57495
- const byCatRows = d.query(`SELECT category, COUNT(*) as c FROM memories WHERE status = 'active' ${scopedCond} GROUP BY category`).all(...scopedParams);
57496
- const topMems = d.query(`SELECT id, key, value, importance, scope, category FROM memories WHERE status = 'active' ${scopedCond} ORDER BY importance DESC, access_count DESC LIMIT 5`).all(...scopedParams);
57497
- const topAgents = d.query(`SELECT agent_id, COUNT(*) as c FROM memories WHERE status = 'active' AND agent_id IS NOT NULL ${scopedCond} GROUP BY agent_id ORDER BY c DESC LIMIT 5`).all(...scopedParams);
57498
- return {
57499
- total,
57500
- pinned,
57501
- days,
57502
- recent: { total: recentTotal, activity: actRows },
57503
- by_scope: Object.fromEntries(byScopeRows.map((r) => [r.scope, r.c])),
57504
- by_category: Object.fromEntries(byCatRows.map((r) => [r.category, r.c])),
57505
- top_memories: topMems,
57506
- top_agents: topAgents
57507
- };
57508
- }
57509
- function getStaleMemoriesPage(filter = {}, db) {
57510
- const days = Math.min(filter.days || 30, 365);
57511
- const limit = filter.limit ?? 20;
57512
- const offset = filter.offset ?? 0;
57513
- if (!db && isApiMode()) {
57514
- const q = toQuery({ days, project_id: filter.project_id, agent_id: filter.agent_id, limit, offset });
57515
- const { data } = apiJson("GET", `/memories/stale${q}`);
57516
- const rows2 = data?.memories ?? [];
57517
- return {
57518
- rows: rows2,
57519
- total: data?.total ?? rows2.length,
57520
- has_more: data?.has_more,
57521
- next_cursor: data?.next_cursor ?? null
57522
- };
57523
- }
57524
- const d = db || getDatabase();
57525
- const cutoffDate = new Date(Date.now() - days * 86400000).toISOString();
57526
- const conds = ["status = 'active'", "(accessed_at IS NULL OR accessed_at < ?)", "pinned = 0"];
57527
- const params = [cutoffDate];
57528
- if (filter.project_id) {
57529
- conds.push("project_id = ?");
57530
- params.push(filter.project_id);
57531
- }
57532
- if (filter.agent_id) {
57533
- conds.push("agent_id = ?");
57534
- params.push(filter.agent_id);
57535
- }
57536
- const where = conds.join(" AND ");
57537
- const countRow = d.query(`SELECT COUNT(*) AS c FROM memories WHERE ${where}`).get(...params);
57538
- let sql = `SELECT id, key, value, importance, scope, category, accessed_at, access_count, created_at FROM memories WHERE ${where} ORDER BY COALESCE(accessed_at, created_at) ASC LIMIT ?`;
57539
- params.push(limit);
57540
- if (offset) {
57541
- sql += " OFFSET ?";
57542
- params.push(offset);
57543
- }
57544
- const rows = d.query(sql).all(...params);
57545
- const hasMore = rows.length === limit;
57546
- return {
57547
- rows,
57548
- total: countRow?.c ?? 0,
57549
- has_more: hasMore,
57550
- next_cursor: hasMore ? offset + rows.length : null
57551
- };
57552
- }
57553
- function getMemoryHealth(filter = {}, db) {
57554
- const staleDays = filter.stale_days ?? 30;
57555
- const forgottenDays = filter.forgotten_days ?? 60;
57556
- const limit = filter.limit ?? 10;
57557
- if (!db && isApiMode()) {
57558
- const q = toQuery({
57559
- stale_days: staleDays,
57560
- forgotten_days: forgottenDays,
57561
- project_id: filter.project_id,
57562
- agent_id: filter.agent_id,
57563
- limit
57564
- });
57565
- const { data } = apiJson("GET", `/memories/health${q}`);
57566
- return { stale: data?.stale ?? [], forgotten: data?.forgotten ?? [], dupes: data?.dupes ?? [] };
57567
- }
57568
- const d = db || getDatabase();
57569
- const extraWhere = [
57570
- ...filter.project_id ? ["project_id = ?"] : [],
57571
- ...filter.agent_id ? ["agent_id = ?"] : []
57572
- ].join(" AND ");
57573
- const scopeParams = [
57574
- ...filter.project_id ? [filter.project_id] : [],
57575
- ...filter.agent_id ? [filter.agent_id] : []
57576
- ];
57577
- const staleCutoff = new Date(Date.now() - staleDays * 86400000).toISOString();
57578
- const forgottenCutoff = new Date(Date.now() - forgottenDays * 86400000).toISOString();
57579
- const base = `status = 'active' AND pinned = 0${extraWhere ? " AND " + extraWhere : ""}`;
57580
- const stale = d.prepare(`SELECT id, key, value, importance, scope, created_at FROM memories
57581
- WHERE ${base} AND access_count = 0 AND created_at < ?
57582
- ORDER BY created_at ASC LIMIT ?`).all(...scopeParams, staleCutoff, limit);
57583
- const forgotten = d.prepare(`SELECT id, key, value, importance, scope, accessed_at FROM memories
57584
- WHERE ${base} AND importance >= 7
57585
- AND (accessed_at IS NULL OR accessed_at < ?)
57586
- ORDER BY importance DESC, COALESCE(accessed_at, created_at) ASC LIMIT ?`).all(...scopeParams, forgottenCutoff, limit);
57587
- const dupes = d.prepare(`SELECT key, COUNT(*) as cnt, MAX(updated_at) as latest, MIN(created_at) as oldest
57588
- FROM memories WHERE ${base}
57589
- GROUP BY key HAVING COUNT(*) > 1
57590
- ORDER BY cnt DESC LIMIT ?`).all(...scopeParams, limit);
57591
- return { stale, forgotten, dupes };
57592
- }
57593
-
57594
- // src/server/routes/memories-stats.ts
57595
57699
  init_memories();
57596
57700
  init_router();
57597
57701
  addRoute("GET", "/api/memories/stats", () => {
@@ -57635,8 +57739,10 @@ addRoute("GET", "/api/memories/stale", (_req, url) => {
57635
57739
  const limit = Number.isInteger(parsedLimit) && parsedLimit > 0 ? Math.min(parsedLimit, 1000) : 20;
57636
57740
  const parsedOffset = Number(q["offset"]);
57637
57741
  const offset = Number.isInteger(parsedOffset) && parsedOffset >= 0 ? parsedOffset : 0;
57742
+ const pinned = q["pinned"] === "1" || q["pinned"] === "true" ? true : q["pinned"] === "0" || q["pinned"] === "false" ? false : undefined;
57638
57743
  const page = getStaleMemoriesPage({
57639
57744
  days,
57745
+ pinned,
57640
57746
  project_id: q["project_id"],
57641
57747
  agent_id: q["agent_id"],
57642
57748
  limit,
@@ -57708,7 +57814,7 @@ function hasFts5Table2(db) {
57708
57814
  function buildScopeFilter(opts) {
57709
57815
  const conditions = [
57710
57816
  "m.status = 'active'",
57711
- "(m.expires_at IS NULL OR m.expires_at >= datetime('now'))",
57817
+ "(m.expires_at IS NULL OR m.expires_at >= strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))",
57712
57818
  "m.category IN ('preference', 'fact', 'knowledge')"
57713
57819
  ];
57714
57820
  const params = [];
@@ -57976,7 +58082,7 @@ async function runTemporalAgent(db, query, opts) {
57976
58082
  const maxResults = opts.max_results ?? 20;
57977
58083
  const limit = maxResults * 3;
57978
58084
  const conditions = [
57979
- "(m.expires_at IS NULL OR m.expires_at >= datetime('now'))"
58085
+ "(m.expires_at IS NULL OR m.expires_at >= strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))"
57980
58086
  ];
57981
58087
  const params = [];
57982
58088
  if (opts.project_id) {
@@ -59810,7 +59916,7 @@ function acquireLock(agentId, resourceType, resourceId, lockType = "exclusive",
59810
59916
  }
59811
59917
  const d = db || getDatabase();
59812
59918
  cleanExpiredLocks(d);
59813
- const ownLock = d.query("SELECT * FROM resource_locks WHERE resource_type = ? AND resource_id = ? AND agent_id = ? AND lock_type = ? AND expires_at > datetime('now')").get(resourceType, resourceId, agentId, lockType);
59919
+ const ownLock = d.query("SELECT * FROM resource_locks WHERE resource_type = ? AND resource_id = ? AND agent_id = ? AND lock_type = ? AND expires_at > strftime('%Y-%m-%dT%H:%M:%fZ', 'now')").get(resourceType, resourceId, agentId, lockType);
59814
59920
  if (ownLock) {
59815
59921
  const newExpiry = new Date(Date.now() + ttlSeconds * 1000).toISOString();
59816
59922
  d.run("UPDATE resource_locks SET expires_at = ? WHERE id = ?", [
@@ -59820,7 +59926,7 @@ function acquireLock(agentId, resourceType, resourceId, lockType = "exclusive",
59820
59926
  return parseLockRow({ ...ownLock, expires_at: newExpiry });
59821
59927
  }
59822
59928
  if (lockType === "exclusive") {
59823
- const existing = d.query("SELECT * FROM resource_locks WHERE resource_type = ? AND resource_id = ? AND lock_type = 'exclusive' AND agent_id != ? AND expires_at > datetime('now')").get(resourceType, resourceId, agentId);
59929
+ const existing = d.query("SELECT * FROM resource_locks WHERE resource_type = ? AND resource_id = ? AND lock_type = 'exclusive' AND agent_id != ? AND expires_at > strftime('%Y-%m-%dT%H:%M:%fZ', 'now')").get(resourceType, resourceId, agentId);
59824
59930
  if (existing) {
59825
59931
  return null;
59826
59932
  }
@@ -59865,7 +59971,7 @@ function checkLock(resourceType, resourceId, lockType, db) {
59865
59971
  }
59866
59972
  const d = db || getDatabase();
59867
59973
  cleanExpiredLocks(d);
59868
- const query = lockType ? "SELECT * FROM resource_locks WHERE resource_type = ? AND resource_id = ? AND lock_type = ? AND expires_at > datetime('now')" : "SELECT * FROM resource_locks WHERE resource_type = ? AND resource_id = ? AND expires_at > datetime('now')";
59974
+ const query = lockType ? "SELECT * FROM resource_locks WHERE resource_type = ? AND resource_id = ? AND lock_type = ? AND expires_at > strftime('%Y-%m-%dT%H:%M:%fZ', 'now')" : "SELECT * FROM resource_locks WHERE resource_type = ? AND resource_id = ? AND expires_at > strftime('%Y-%m-%dT%H:%M:%fZ', 'now')";
59869
59975
  const rows = lockType ? d.query(query).all(resourceType, resourceId, lockType) : d.query(query).all(resourceType, resourceId);
59870
59976
  return rows.map(parseLockRow);
59871
59977
  }
@@ -59876,7 +59982,7 @@ function listAgentLocks(agentId, db) {
59876
59982
  }
59877
59983
  const d = db || getDatabase();
59878
59984
  cleanExpiredLocks(d);
59879
- const rows = d.query("SELECT * FROM resource_locks WHERE agent_id = ? AND expires_at > datetime('now') ORDER BY locked_at DESC").all(agentId);
59985
+ const rows = d.query("SELECT * FROM resource_locks WHERE agent_id = ? AND expires_at > strftime('%Y-%m-%dT%H:%M:%fZ', 'now') ORDER BY locked_at DESC").all(agentId);
59880
59986
  return rows.map(parseLockRow);
59881
59987
  }
59882
59988
  function cleanExpiredLocks(db) {
@@ -59885,7 +59991,7 @@ function cleanExpiredLocks(db) {
59885
59991
  return data?.cleaned ?? 0;
59886
59992
  }
59887
59993
  const d = db || getDatabase();
59888
- const result = d.run("DELETE FROM resource_locks WHERE expires_at <= datetime('now')");
59994
+ const result = d.run("DELETE FROM resource_locks WHERE expires_at <= strftime('%Y-%m-%dT%H:%M:%fZ', 'now')");
59889
59995
  return result.changes;
59890
59996
  }
59891
59997
 
@@ -64976,13 +65082,11 @@ function startServer(port) {
64976
65082
  const profile = getActiveProfile();
64977
65083
  try {
64978
65084
  const db = getDatabase();
64979
- const total = db.query("SELECT COUNT(*) as c FROM memories WHERE status = 'active'").get().c;
64980
- const expired = db.query("SELECT COUNT(*) as c FROM memories WHERE status = 'expired' OR (expires_at IS NOT NULL AND expires_at < datetime('now'))").get().c;
64981
- const pinned = db.query("SELECT COUNT(*) as c FROM memories WHERE status = 'active' AND pinned = 1").get().c;
65085
+ const stats = getMemoryStats(db);
64982
65086
  const agents = db.query("SELECT COUNT(*) as c FROM agents").get().c;
64983
65087
  const projects = db.query("SELECT COUNT(*) as c FROM projects").get().c;
64984
- const status = expired > 50 ? "warn" : "ok";
64985
- return json({ status, version: pkgVersion(), backend, profile: profile ?? "default", db_path: getDbPath(), hostname: hostname3, memories: { total, expired, pinned }, agents, projects });
65088
+ const status = stats.expired_due_count > 50 ? "warn" : "ok";
65089
+ return json({ status, version: pkgVersion(), backend, profile: profile ?? "default", db_path: getDbPath(), hostname: hostname3, memories: { total: stats.total, expired: stats.expired_count, expired_due: stats.expired_due_count, pinned: stats.pinned_count }, agents, projects });
64986
65090
  } catch (e) {
64987
65091
  return json({ status: "error", version: pkgVersion(), backend, error: e instanceof Error ? e.message : String(e) }, 503);
64988
65092
  }