squish-memory 1.2.0 → 1.2.1

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 (449) hide show
  1. package/bin/squish-mcp.mjs +40 -42
  2. package/core/scheduler/cron-scheduler.ts +10 -1
  3. package/core/worker.ts +10 -1
  4. package/package.json +119 -119
  5. package/packages/mcp/src/index.ts +99 -36
  6. package/dist/config.d.ts +0 -106
  7. package/dist/config.js +0 -194
  8. package/dist/core/adapters/config/claude-code.d.ts +0 -45
  9. package/dist/core/adapters/config/claude-code.js +0 -113
  10. package/dist/core/adapters/config/cursor.d.ts +0 -26
  11. package/dist/core/adapters/config/cursor.js +0 -74
  12. package/dist/core/adapters/config/opencode.d.ts +0 -23
  13. package/dist/core/adapters/config/opencode.js +0 -73
  14. package/dist/core/adapters/config/windsurf.d.ts +0 -26
  15. package/dist/core/adapters/config/windsurf.js +0 -74
  16. package/dist/core/adapters/index.d.ts +0 -45
  17. package/dist/core/adapters/index.js +0 -84
  18. package/dist/core/adapters/scripts/install-adapter.d.ts +0 -19
  19. package/dist/core/adapters/scripts/install-adapter.js +0 -149
  20. package/dist/core/adapters/timeline.d.ts +0 -23
  21. package/dist/core/adapters/timeline.js +0 -88
  22. package/dist/core/adapters/types.d.ts +0 -137
  23. package/dist/core/adapters/types.js +0 -50
  24. package/dist/core/agent-preferences.d.ts +0 -16
  25. package/dist/core/agent-preferences.js +0 -124
  26. package/dist/core/algorithms/analytics/token-estimator.d.ts +0 -50
  27. package/dist/core/algorithms/analytics/token-estimator.js +0 -154
  28. package/dist/core/algorithms/detection/hash-filters.d.ts +0 -47
  29. package/dist/core/algorithms/detection/hash-filters.js +0 -190
  30. package/dist/core/algorithms/detection/semantic-ranker.d.ts +0 -32
  31. package/dist/core/algorithms/detection/semantic-ranker.js +0 -118
  32. package/dist/core/algorithms/detection/two-stage-detector.d.ts +0 -52
  33. package/dist/core/algorithms/detection/two-stage-detector.js +0 -299
  34. package/dist/core/algorithms/handlers/approve-merge.d.ts +0 -22
  35. package/dist/core/algorithms/handlers/approve-merge.js +0 -179
  36. package/dist/core/algorithms/handlers/detect-duplicates.d.ts +0 -47
  37. package/dist/core/algorithms/handlers/detect-duplicates.js +0 -145
  38. package/dist/core/algorithms/handlers/get-stats.d.ts +0 -39
  39. package/dist/core/algorithms/handlers/get-stats.js +0 -88
  40. package/dist/core/algorithms/handlers/list-proposals.d.ts +0 -45
  41. package/dist/core/algorithms/handlers/list-proposals.js +0 -83
  42. package/dist/core/algorithms/handlers/preview-merge.d.ts +0 -39
  43. package/dist/core/algorithms/handlers/preview-merge.js +0 -93
  44. package/dist/core/algorithms/handlers/reject-merge.d.ts +0 -28
  45. package/dist/core/algorithms/handlers/reject-merge.js +0 -69
  46. package/dist/core/algorithms/handlers/reverse-merge.d.ts +0 -21
  47. package/dist/core/algorithms/handlers/reverse-merge.js +0 -121
  48. package/dist/core/algorithms/index.d.ts +0 -21
  49. package/dist/core/algorithms/index.js +0 -26
  50. package/dist/core/algorithms/operations/cache-maintenance.d.ts +0 -12
  51. package/dist/core/algorithms/operations/cache-maintenance.js +0 -157
  52. package/dist/core/algorithms/safety/safety-checks.d.ts +0 -18
  53. package/dist/core/algorithms/safety/safety-checks.js +0 -179
  54. package/dist/core/algorithms/strategies/merge-strategies.d.ts +0 -50
  55. package/dist/core/algorithms/strategies/merge-strategies.js +0 -288
  56. package/dist/core/algorithms/types.d.ts +0 -125
  57. package/dist/core/algorithms/types.js +0 -5
  58. package/dist/core/algorithms/utils/response-builder.d.ts +0 -28
  59. package/dist/core/algorithms/utils/response-builder.js +0 -37
  60. package/dist/core/associations.d.ts +0 -33
  61. package/dist/core/associations.js +0 -284
  62. package/dist/core/autosave.d.ts +0 -19
  63. package/dist/core/autosave.js +0 -16
  64. package/dist/core/beliefs/decay.d.ts +0 -27
  65. package/dist/core/beliefs/decay.js +0 -217
  66. package/dist/core/beliefs/extractor.d.ts +0 -9
  67. package/dist/core/beliefs/extractor.js +0 -113
  68. package/dist/core/beliefs/store.d.ts +0 -46
  69. package/dist/core/beliefs/store.js +0 -466
  70. package/dist/core/beliefs/types.d.ts +0 -28
  71. package/dist/core/beliefs/types.js +0 -2
  72. package/dist/core/commands/mcp-server.d.ts +0 -2
  73. package/dist/core/commands/mcp-server.js +0 -6
  74. package/dist/core/commands/remember.d.ts +0 -24
  75. package/dist/core/commands/remember.js +0 -144
  76. package/dist/core/compression.d.ts +0 -45
  77. package/dist/core/compression.js +0 -160
  78. package/dist/core/consolidation.d.ts +0 -37
  79. package/dist/core/consolidation.js +0 -248
  80. package/dist/core/context/agent-context.d.ts +0 -106
  81. package/dist/core/context/agent-context.js +0 -274
  82. package/dist/core/context/context-paging.d.ts +0 -80
  83. package/dist/core/context/context-paging.js +0 -328
  84. package/dist/core/context/context-window.d.ts +0 -40
  85. package/dist/core/context/context-window.js +0 -177
  86. package/dist/core/context/context.d.ts +0 -7
  87. package/dist/core/context/context.js +0 -22
  88. package/dist/core/embeddings/embeddings.d.ts +0 -29
  89. package/dist/core/embeddings/embeddings.js +0 -546
  90. package/dist/core/embeddings/google-multimodal.d.ts +0 -14
  91. package/dist/core/embeddings/google-multimodal.js +0 -146
  92. package/dist/core/embeddings/local-embeddings.d.ts +0 -11
  93. package/dist/core/embeddings/local-embeddings.js +0 -11
  94. package/dist/core/embeddings/qmd-client.d.ts +0 -136
  95. package/dist/core/embeddings/qmd-client.js +0 -403
  96. package/dist/core/embeddings/transformers-local.d.ts +0 -64
  97. package/dist/core/embeddings/transformers-local.js +0 -213
  98. package/dist/core/embeddings.d.ts +0 -2
  99. package/dist/core/embeddings.js +0 -3
  100. package/dist/core/error-handling.d.ts +0 -63
  101. package/dist/core/error-handling.js +0 -173
  102. package/dist/core/graph/entity-deduplicator.d.ts +0 -24
  103. package/dist/core/graph/entity-deduplicator.js +0 -183
  104. package/dist/core/graph/graph-builder.d.ts +0 -46
  105. package/dist/core/graph/graph-builder.js +0 -174
  106. package/dist/core/graph/graph-traversal.d.ts +0 -80
  107. package/dist/core/graph/graph-traversal.js +0 -315
  108. package/dist/core/graph/index.d.ts +0 -19
  109. package/dist/core/graph/index.js +0 -13
  110. package/dist/core/graph/llm-entity-extractor.d.ts +0 -49
  111. package/dist/core/graph/llm-entity-extractor.js +0 -313
  112. package/dist/core/graph/multi-hop-retrieval.d.ts +0 -48
  113. package/dist/core/graph/multi-hop-retrieval.js +0 -215
  114. package/dist/core/graph/relationship-extractor.d.ts +0 -48
  115. package/dist/core/graph/relationship-extractor.js +0 -351
  116. package/dist/core/hooks/agent-hooks.d.ts +0 -83
  117. package/dist/core/hooks/agent-hooks.js +0 -521
  118. package/dist/core/hooks/auto-tagger.d.ts +0 -19
  119. package/dist/core/hooks/auto-tagger.js +0 -155
  120. package/dist/core/hooks/capture-filter.d.ts +0 -41
  121. package/dist/core/hooks/capture-filter.js +0 -128
  122. package/dist/core/hot-cache.d.ts +0 -86
  123. package/dist/core/hot-cache.js +0 -285
  124. package/dist/core/index.d.ts +0 -10
  125. package/dist/core/index.js +0 -11
  126. package/dist/core/ingestion/agent-memory.d.ts +0 -22
  127. package/dist/core/ingestion/agent-memory.js +0 -109
  128. package/dist/core/ingestion/core-memory.d.ts +0 -78
  129. package/dist/core/ingestion/core-memory.js +0 -226
  130. package/dist/core/ingestion/learnings.d.ts +0 -57
  131. package/dist/core/ingestion/learnings.js +0 -205
  132. package/dist/core/ingestion/signal-engine.d.ts +0 -41
  133. package/dist/core/ingestion/signal-engine.js +0 -201
  134. package/dist/core/integrations/obsidian-vault.d.ts +0 -31
  135. package/dist/core/integrations/obsidian-vault.js +0 -156
  136. package/dist/core/layers/generator.d.ts +0 -25
  137. package/dist/core/layers/generator.js +0 -76
  138. package/dist/core/lib/db-client.d.ts +0 -114
  139. package/dist/core/lib/db-client.js +0 -130
  140. package/dist/core/lib/parse-embedding.d.ts +0 -9
  141. package/dist/core/lib/parse-embedding.js +0 -58
  142. package/dist/core/lib/schemas.d.ts +0 -132
  143. package/dist/core/lib/schemas.js +0 -87
  144. package/dist/core/lib/types.d.ts +0 -45
  145. package/dist/core/lib/types.js +0 -6
  146. package/dist/core/lib/utils.d.ts +0 -18
  147. package/dist/core/lib/utils.js +0 -145
  148. package/dist/core/lib/validation.d.ts +0 -38
  149. package/dist/core/lib/validation.js +0 -151
  150. package/dist/core/lifecycle.d.ts +0 -25
  151. package/dist/core/lifecycle.js +0 -292
  152. package/dist/core/logger.d.ts +0 -17
  153. package/dist/core/logger.js +0 -46
  154. package/dist/core/mcp/client.d.ts +0 -17
  155. package/dist/core/mcp/client.js +0 -101
  156. package/dist/core/mcp/index.d.ts +0 -6
  157. package/dist/core/mcp/index.js +0 -6
  158. package/dist/core/mcp/server.d.ts +0 -18
  159. package/dist/core/mcp/server.js +0 -157
  160. package/dist/core/mcp/standalone-server.d.ts +0 -13
  161. package/dist/core/mcp/standalone-server.js +0 -46
  162. package/dist/core/mcp/tools.d.ts +0 -7
  163. package/dist/core/mcp/tools.js +0 -278
  164. package/dist/core/mcp/types.d.ts +0 -87
  165. package/dist/core/mcp/types.js +0 -48
  166. package/dist/core/memory/bridge-discovery.d.ts +0 -50
  167. package/dist/core/memory/bridge-discovery.js +0 -291
  168. package/dist/core/memory/categorizer.d.ts +0 -27
  169. package/dist/core/memory/categorizer.js +0 -306
  170. package/dist/core/memory/conflict-detector.d.ts +0 -7
  171. package/dist/core/memory/conflict-detector.js +0 -43
  172. package/dist/core/memory/consolidation.d.ts +0 -42
  173. package/dist/core/memory/consolidation.js +0 -277
  174. package/dist/core/memory/context-collector.d.ts +0 -10
  175. package/dist/core/memory/context-collector.js +0 -56
  176. package/dist/core/memory/contradiction-resolver.d.ts +0 -40
  177. package/dist/core/memory/contradiction-resolver.js +0 -368
  178. package/dist/core/memory/edit-workflow.d.ts +0 -19
  179. package/dist/core/memory/edit-workflow.js +0 -120
  180. package/dist/core/memory/entity-extractor.d.ts +0 -37
  181. package/dist/core/memory/entity-extractor.js +0 -350
  182. package/dist/core/memory/entity-resolver.d.ts +0 -23
  183. package/dist/core/memory/entity-resolver.js +0 -64
  184. package/dist/core/memory/explain.d.ts +0 -18
  185. package/dist/core/memory/explain.js +0 -92
  186. package/dist/core/memory/fact-deriver.d.ts +0 -31
  187. package/dist/core/memory/fact-deriver.js +0 -236
  188. package/dist/core/memory/fact-extractor.d.ts +0 -24
  189. package/dist/core/memory/fact-extractor.js +0 -89
  190. package/dist/core/memory/feedback-tracker.d.ts +0 -12
  191. package/dist/core/memory/feedback-tracker.js +0 -155
  192. package/dist/core/memory/hooks.d.ts +0 -88
  193. package/dist/core/memory/hooks.js +0 -174
  194. package/dist/core/memory/hybrid-retrieval.d.ts +0 -27
  195. package/dist/core/memory/hybrid-retrieval.js +0 -37
  196. package/dist/core/memory/hybrid-scorer.d.ts +0 -40
  197. package/dist/core/memory/hybrid-scorer.js +0 -267
  198. package/dist/core/memory/hybrid-search.d.ts +0 -23
  199. package/dist/core/memory/hybrid-search.js +0 -596
  200. package/dist/core/memory/importance.d.ts +0 -46
  201. package/dist/core/memory/importance.js +0 -241
  202. package/dist/core/memory/index.d.ts +0 -9
  203. package/dist/core/memory/index.js +0 -11
  204. package/dist/core/memory/loader.d.ts +0 -31
  205. package/dist/core/memory/loader.js +0 -141
  206. package/dist/core/memory/markdown/markdown-storage.d.ts +0 -72
  207. package/dist/core/memory/markdown/markdown-storage.js +0 -243
  208. package/dist/core/memory/memories.d.ts +0 -43
  209. package/dist/core/memory/memories.js +0 -452
  210. package/dist/core/memory/memory-lifecycle.d.ts +0 -8
  211. package/dist/core/memory/memory-lifecycle.js +0 -47
  212. package/dist/core/memory/memory-manager.d.ts +0 -15
  213. package/dist/core/memory/memory-manager.js +0 -46
  214. package/dist/core/memory/migrate.d.ts +0 -21
  215. package/dist/core/memory/migrate.js +0 -134
  216. package/dist/core/memory/normalization.d.ts +0 -7
  217. package/dist/core/memory/normalization.js +0 -26
  218. package/dist/core/memory/path-strengthener.d.ts +0 -39
  219. package/dist/core/memory/path-strengthener.js +0 -150
  220. package/dist/core/memory/progressive-disclosure.d.ts +0 -43
  221. package/dist/core/memory/progressive-disclosure.js +0 -280
  222. package/dist/core/memory/query-processor.d.ts +0 -21
  223. package/dist/core/memory/query-processor.js +0 -106
  224. package/dist/core/memory/query-rewriter.d.ts +0 -13
  225. package/dist/core/memory/query-rewriter.js +0 -118
  226. package/dist/core/memory/response-analyzer.d.ts +0 -9
  227. package/dist/core/memory/response-analyzer.js +0 -61
  228. package/dist/core/memory/retrieval-feedback.d.ts +0 -70
  229. package/dist/core/memory/retrieval-feedback.js +0 -213
  230. package/dist/core/memory/serialization.d.ts +0 -10
  231. package/dist/core/memory/serialization.js +0 -84
  232. package/dist/core/memory/stale-cleaner.d.ts +0 -26
  233. package/dist/core/memory/stale-cleaner.js +0 -97
  234. package/dist/core/memory/stats.d.ts +0 -32
  235. package/dist/core/memory/stats.js +0 -143
  236. package/dist/core/memory/telemetry.d.ts +0 -69
  237. package/dist/core/memory/telemetry.js +0 -313
  238. package/dist/core/memory/temporal-facts.d.ts +0 -41
  239. package/dist/core/memory/temporal-facts.js +0 -283
  240. package/dist/core/memory/temporal-parser.d.ts +0 -32
  241. package/dist/core/memory/temporal-parser.js +0 -385
  242. package/dist/core/memory/trigger-detector.d.ts +0 -21
  243. package/dist/core/memory/trigger-detector.js +0 -79
  244. package/dist/core/memory/write-gate.d.ts +0 -54
  245. package/dist/core/memory/write-gate.js +0 -210
  246. package/dist/core/places/index.d.ts +0 -14
  247. package/dist/core/places/index.js +0 -14
  248. package/dist/core/places/memory-places.d.ts +0 -68
  249. package/dist/core/places/memory-places.js +0 -261
  250. package/dist/core/places/places.d.ts +0 -88
  251. package/dist/core/places/places.js +0 -314
  252. package/dist/core/places/rules.d.ts +0 -74
  253. package/dist/core/places/rules.js +0 -240
  254. package/dist/core/places/walking.d.ts +0 -56
  255. package/dist/core/places/walking.js +0 -121
  256. package/dist/core/projects.d.ts +0 -17
  257. package/dist/core/projects.js +0 -116
  258. package/dist/core/redis.d.ts +0 -11
  259. package/dist/core/redis.js +0 -69
  260. package/dist/core/responses.d.ts +0 -96
  261. package/dist/core/responses.js +0 -122
  262. package/dist/core/runtime/trust-report.d.ts +0 -102
  263. package/dist/core/runtime/trust-report.js +0 -107
  264. package/dist/core/runtime/trust-state.d.ts +0 -12
  265. package/dist/core/runtime/trust-state.js +0 -309
  266. package/dist/core/scheduler/cron-scheduler.d.ts +0 -32
  267. package/dist/core/scheduler/cron-scheduler.js +0 -493
  268. package/dist/core/scheduler/heartbeat.d.ts +0 -11
  269. package/dist/core/scheduler/heartbeat.js +0 -73
  270. package/dist/core/scheduler/index.d.ts +0 -8
  271. package/dist/core/scheduler/index.js +0 -8
  272. package/dist/core/scheduler/job-runner.d.ts +0 -11
  273. package/dist/core/scheduler/job-runner.js +0 -164
  274. package/dist/core/search/conversations.d.ts +0 -25
  275. package/dist/core/search/conversations.js +0 -110
  276. package/dist/core/search/entities.d.ts +0 -12
  277. package/dist/core/search/entities.js +0 -31
  278. package/dist/core/search/folder-context.d.ts +0 -25
  279. package/dist/core/search/folder-context.js +0 -119
  280. package/dist/core/search/graph-boost.d.ts +0 -7
  281. package/dist/core/search/graph-boost.js +0 -23
  282. package/dist/core/search/index.d.ts +0 -4
  283. package/dist/core/search/index.js +0 -5
  284. package/dist/core/search/qmd-wrapper.d.ts +0 -36
  285. package/dist/core/search/qmd-wrapper.js +0 -58
  286. package/dist/core/security/encrypt.d.ts +0 -6
  287. package/dist/core/security/encrypt.js +0 -47
  288. package/dist/core/security/governance.d.ts +0 -26
  289. package/dist/core/security/governance.js +0 -79
  290. package/dist/core/security/privacy.d.ts +0 -23
  291. package/dist/core/security/privacy.js +0 -82
  292. package/dist/core/security/secret-detector.d.ts +0 -32
  293. package/dist/core/security/secret-detector.js +0 -88
  294. package/dist/core/session/auto-load.d.ts +0 -6
  295. package/dist/core/session/auto-load.js +0 -144
  296. package/dist/core/session/entity-tracker.d.ts +0 -62
  297. package/dist/core/session/entity-tracker.js +0 -287
  298. package/dist/core/session/index.d.ts +0 -7
  299. package/dist/core/session/index.js +0 -7
  300. package/dist/core/session/reference-resolver.d.ts +0 -26
  301. package/dist/core/session/reference-resolver.js +0 -121
  302. package/dist/core/session/self-iteration-job.d.ts +0 -35
  303. package/dist/core/session/self-iteration-job.js +0 -387
  304. package/dist/core/session/session-hooks.d.ts +0 -18
  305. package/dist/core/session/session-hooks.js +0 -58
  306. package/dist/core/session/types.d.ts +0 -26
  307. package/dist/core/session/types.js +0 -10
  308. package/dist/core/session/working-set.d.ts +0 -50
  309. package/dist/core/session/working-set.js +0 -212
  310. package/dist/core/snapshots/cleanup.d.ts +0 -9
  311. package/dist/core/snapshots/cleanup.js +0 -12
  312. package/dist/core/snapshots/comparison.d.ts +0 -19
  313. package/dist/core/snapshots/comparison.js +0 -43
  314. package/dist/core/snapshots/creation.d.ts +0 -13
  315. package/dist/core/snapshots/creation.js +0 -117
  316. package/dist/core/snapshots/retrieval.d.ts +0 -7
  317. package/dist/core/snapshots/retrieval.js +0 -41
  318. package/dist/core/snapshots/stats.d.ts +0 -11
  319. package/dist/core/snapshots/stats.js +0 -52
  320. package/dist/core/storage/cache.d.ts +0 -13
  321. package/dist/core/storage/cache.js +0 -202
  322. package/dist/core/storage/database.d.ts +0 -12
  323. package/dist/core/storage/database.js +0 -12
  324. package/dist/core/summarization/cleanup.d.ts +0 -9
  325. package/dist/core/summarization/cleanup.js +0 -12
  326. package/dist/core/summarization/queries.d.ts +0 -9
  327. package/dist/core/summarization/queries.js +0 -28
  328. package/dist/core/summarization/stats.d.ts +0 -14
  329. package/dist/core/summarization/stats.js +0 -52
  330. package/dist/core/summarization/strategies.d.ts +0 -24
  331. package/dist/core/summarization/strategies.js +0 -28
  332. package/dist/core/summarization.d.ts +0 -37
  333. package/dist/core/summarization.js +0 -188
  334. package/dist/core/temporal-facts.d.ts +0 -54
  335. package/dist/core/temporal-facts.js +0 -193
  336. package/dist/core/tracing/collector.d.ts +0 -111
  337. package/dist/core/tracing/collector.js +0 -350
  338. package/dist/core/tracing/visualizer.d.ts +0 -32
  339. package/dist/core/tracing/visualizer.js +0 -165
  340. package/dist/core/utils/cleanup-operations.d.ts +0 -13
  341. package/dist/core/utils/cleanup-operations.js +0 -44
  342. package/dist/core/utils/content-extraction.d.ts +0 -19
  343. package/dist/core/utils/content-extraction.js +0 -75
  344. package/dist/core/utils/filter-builder.d.ts +0 -13
  345. package/dist/core/utils/filter-builder.js +0 -44
  346. package/dist/core/utils/history-traversal.d.ts +0 -13
  347. package/dist/core/utils/history-traversal.js +0 -50
  348. package/dist/core/utils/memory-operations.d.ts +0 -17
  349. package/dist/core/utils/memory-operations.js +0 -43
  350. package/dist/core/utils/query-operations.d.ts +0 -18
  351. package/dist/core/utils/query-operations.js +0 -65
  352. package/dist/core/utils/summarization-helpers.d.ts +0 -17
  353. package/dist/core/utils/summarization-helpers.js +0 -33
  354. package/dist/core/utils/temporal-queries.d.ts +0 -13
  355. package/dist/core/utils/temporal-queries.js +0 -27
  356. package/dist/core/utils/vector-operations.d.ts +0 -71
  357. package/dist/core/utils/vector-operations.js +0 -129
  358. package/dist/core/utils/version-management.d.ts +0 -9
  359. package/dist/core/utils/version-management.js +0 -61
  360. package/dist/core/worker.d.ts +0 -82
  361. package/dist/core/worker.js +0 -272
  362. package/dist/db/adapter.d.ts +0 -7
  363. package/dist/db/adapter.js +0 -175
  364. package/dist/db/bootstrap.d.ts +0 -11
  365. package/dist/db/bootstrap.js +0 -1034
  366. package/dist/db/drizzle/schema-sqlite.d.ts +0 -5538
  367. package/dist/db/drizzle/schema-sqlite.js +0 -763
  368. package/dist/db/drizzle/schema.d.ts +0 -4734
  369. package/dist/db/drizzle/schema.js +0 -859
  370. package/dist/db/drizzle.config.d.ts +0 -3
  371. package/dist/db/drizzle.config.js +0 -12
  372. package/dist/db/index.d.ts +0 -7
  373. package/dist/db/index.js +0 -89
  374. package/dist/db/migrations/associations.d.ts +0 -6
  375. package/dist/db/migrations/associations.js +0 -29
  376. package/dist/db/migrations/beliefs.d.ts +0 -10
  377. package/dist/db/migrations/beliefs.js +0 -76
  378. package/dist/db/migrations/core-memory.d.ts +0 -6
  379. package/dist/db/migrations/core-memory.js +0 -29
  380. package/dist/db/migrations/fts.d.ts +0 -6
  381. package/dist/db/migrations/fts.js +0 -52
  382. package/dist/db/migrations/index.d.ts +0 -25
  383. package/dist/db/migrations/index.js +0 -51
  384. package/dist/db/migrations/indexes.d.ts +0 -6
  385. package/dist/db/migrations/indexes.js +0 -30
  386. package/dist/db/migrations/learnings.d.ts +0 -7
  387. package/dist/db/migrations/learnings.js +0 -26
  388. package/dist/db/migrations/maintenance.d.ts +0 -6
  389. package/dist/db/migrations/maintenance.js +0 -61
  390. package/dist/db/migrations/memories.d.ts +0 -7
  391. package/dist/db/migrations/memories.js +0 -16
  392. package/dist/db/migrations/memory-places.d.ts +0 -6
  393. package/dist/db/migrations/memory-places.js +0 -29
  394. package/dist/db/migrations/places.d.ts +0 -6
  395. package/dist/db/migrations/places.js +0 -43
  396. package/dist/db/migrations/projects.d.ts +0 -3
  397. package/dist/db/migrations/projects.js +0 -13
  398. package/dist/db/migrations/tier-conversion.d.ts +0 -7
  399. package/dist/db/migrations/tier-conversion.js +0 -20
  400. package/dist/db/neon.d.ts +0 -8
  401. package/dist/db/neon.js +0 -20
  402. package/dist/db/schema/beliefs.d.ts +0 -9
  403. package/dist/db/schema/beliefs.js +0 -46
  404. package/dist/db/schema/generator.d.ts +0 -38
  405. package/dist/db/schema/generator.js +0 -108
  406. package/dist/db/schema/index.d.ts +0 -39
  407. package/dist/db/schema/index.js +0 -51
  408. package/dist/db/schema/learnings.d.ts +0 -7
  409. package/dist/db/schema/learnings.js +0 -30
  410. package/dist/db/schema/memories.d.ts +0 -7
  411. package/dist/db/schema/memories.js +0 -81
  412. package/dist/db/schema/projects.d.ts +0 -4
  413. package/dist/db/schema/projects.js +0 -31
  414. package/dist/db/schema/tables/context-sessions.d.ts +0 -9
  415. package/dist/db/schema/tables/context-sessions.js +0 -37
  416. package/dist/db/schema/tables/conversations.d.ts +0 -9
  417. package/dist/db/schema/tables/conversations.js +0 -47
  418. package/dist/db/schema/tables/core-memory.d.ts +0 -9
  419. package/dist/db/schema/tables/core-memory.js +0 -41
  420. package/dist/db/schema/tables/entities.d.ts +0 -9
  421. package/dist/db/schema/tables/entities.js +0 -39
  422. package/dist/db/schema/tables/entity-relations.d.ts +0 -9
  423. package/dist/db/schema/tables/entity-relations.js +0 -31
  424. package/dist/db/schema/tables/learnings.d.ts +0 -9
  425. package/dist/db/schema/tables/learnings.js +0 -66
  426. package/dist/db/schema/tables/memories.d.ts +0 -9
  427. package/dist/db/schema/tables/memories.js +0 -161
  428. package/dist/db/schema/tables/memory-associations.d.ts +0 -9
  429. package/dist/db/schema/tables/memory-associations.js +0 -39
  430. package/dist/db/schema/tables/memory-hash-cache.d.ts +0 -9
  431. package/dist/db/schema/tables/memory-hash-cache.js +0 -29
  432. package/dist/db/schema/tables/memory-merge-history.d.ts +0 -9
  433. package/dist/db/schema/tables/memory-merge-history.js +0 -33
  434. package/dist/db/schema/tables/memory-merge-proposals.d.ts +0 -9
  435. package/dist/db/schema/tables/memory-merge-proposals.js +0 -39
  436. package/dist/db/schema/tables/messages.d.ts +0 -9
  437. package/dist/db/schema/tables/messages.js +0 -41
  438. package/dist/db/schema/tables/namespaces.d.ts +0 -9
  439. package/dist/db/schema/tables/namespaces.js +0 -37
  440. package/dist/db/schema/tables/projects.d.ts +0 -9
  441. package/dist/db/schema/tables/projects.js +0 -31
  442. package/dist/db/schema/tables/users.d.ts +0 -9
  443. package/dist/db/schema/tables/users.js +0 -27
  444. package/dist/db/schema.d.ts +0 -3
  445. package/dist/db/schema.js +0 -11
  446. package/dist/db/supabase.d.ts +0 -9
  447. package/dist/db/supabase.js +0 -24
  448. package/dist/packages/mcp/src/index.d.ts +0 -3
  449. package/dist/packages/mcp/src/index.js +0 -733
@@ -1,21 +0,0 @@
1
- /**
2
- * Query Processor - Phase 4
3
- * Expands queries for better retrieval coverage
4
- */
5
- export interface ProcessedQuery {
6
- original: string;
7
- expanded: string[];
8
- entities: string[];
9
- synonyms: Map<string, string[]>;
10
- }
11
- /**
12
- * Simple synonym expansion without LLM calls
13
- * Fast, deterministic, no API costs
14
- */
15
- export declare function expandQuery(query: string): ProcessedQuery;
16
- /**
17
- * Multi-query search combiner
18
- * Searches with multiple query variants and merges results
19
- */
20
- export declare function multiQuerySearch<T>(queries: string[], searchFn: (query: string) => Promise<T[]>, dedupeKey: (item: T) => string): Promise<T[]>;
21
- //# sourceMappingURL=query-processor.d.ts.map
@@ -1,106 +0,0 @@
1
- /**
2
- * Query Processor - Phase 4
3
- * Expands queries for better retrieval coverage
4
- */
5
- /**
6
- * Simple synonym expansion without LLM calls
7
- * Fast, deterministic, no API costs
8
- */
9
- export function expandQuery(query) {
10
- const synonyms = new Map();
11
- // Define common synonym mappings
12
- const synonymMap = {
13
- 'manager': ['manager', 'boss', 'supervisor', 'lead'],
14
- 'team': ['team', 'group', 'staff', 'crew'],
15
- 'project': ['project', 'initiative', 'endeavor', 'work'],
16
- 'start': ['start', 'begin', 'commence', 'initiate'],
17
- 'budget': ['budget', 'funding', 'cost', 'allocation'],
18
- 'language': ['language', 'tech', 'stack', 'technology'],
19
- 'feature': ['feature', 'capability', 'function', 'aspect'],
20
- 'based': ['based', 'located', 'situated', 'headquartered'],
21
- };
22
- const lowerQuery = query.toLowerCase();
23
- // Find matching synonyms
24
- for (const [key, values] of Object.entries(synonymMap)) {
25
- if (lowerQuery.includes(key)) {
26
- synonyms.set(key, values);
27
- }
28
- }
29
- // Generate expanded queries by substituting synonyms
30
- const expanded = [query]; // Original
31
- // Add one variation per synonym found
32
- for (const [term, variants] of synonyms) {
33
- for (const variant of variants) {
34
- if (variant !== term) {
35
- expanded.push(query.replace(new RegExp(term, 'gi'), variant));
36
- }
37
- }
38
- }
39
- // Extract entities (capitalized words), filtering common stopwords
40
- const STOP_WORDS = new Set([
41
- 'The', 'A', 'An', 'This', 'That', 'These', 'Those',
42
- 'I', 'You', 'We', 'They', 'He', 'She', 'It',
43
- 'What', 'When', 'Where', 'Why', 'How',
44
- 'My', 'Your', 'Our', 'Their', 'Its',
45
- 'If', 'But', 'Or', 'And', 'So', 'Then',
46
- 'Just', 'Only', 'Also', 'Very', 'Too',
47
- 'Has', 'Have', 'Had', 'Does', 'Did', 'Will', 'Would', 'Could', 'Should',
48
- 'Can', 'May', 'Might', 'Must', 'Shall',
49
- 'With', 'Without', 'From', 'Into', 'About', 'After', 'Before', 'Between',
50
- 'During', 'Through', 'Under', 'Over', 'Above', 'Below',
51
- 'All', 'Some', 'Any', 'No', 'Not', 'Each', 'Every', 'Most', 'Many', 'Much',
52
- 'Few', 'Both', 'Either', 'Neither', 'Another', 'Other',
53
- 'Such', 'Same', 'Different', 'New', 'Old', 'First', 'Last', 'Next', 'Last',
54
- 'See', 'Get', 'Make', 'Do', 'Say', 'Tell', 'Know', 'Think', 'Want', 'Use',
55
- 'Find', 'Give', 'Take', 'Show', 'Send', 'Put', 'Keep', 'Let', 'Begin', 'Seem',
56
- ]);
57
- // Common tech stack terms that ARE entities (preserves known entities)
58
- const TECH_TERMS = new Set([
59
- 'TypeScript', 'JavaScript', 'Python', 'Java', 'Go', 'Rust', 'Ruby', 'PHP',
60
- 'React', 'Vue', 'Angular', 'Svelte', 'Next', 'Nuxt', 'Astro',
61
- 'Node', 'Express', 'Fastify', 'Deno', 'Bun',
62
- 'PostgreSQL', 'MySQL', 'MongoDB', 'Redis', 'SQLite', 'DynamoDB',
63
- 'AWS', 'GCP', 'Azure', 'Docker', 'Kubernetes', 'Terraform',
64
- 'OpenAI', 'Anthropic', 'Google', 'Meta', 'Microsoft', 'Apple',
65
- 'HTML', 'CSS', 'Tailwind', 'GraphQL', 'REST', 'gRPC', 'WebSocket',
66
- 'CI', 'CD', 'Git', 'GitHub', 'GitLab', 'Bitbucket',
67
- ]);
68
- const entityMatches = query.match(/\b[A-Z][a-z]{2,}\b/g) || [];
69
- const entities = [...new Set(entityMatches)].filter(e => {
70
- // Always include known tech terms
71
- if (TECH_TERMS.has(e))
72
- return true;
73
- // Filter out stopwords
74
- return !STOP_WORDS.has(e);
75
- });
76
- return {
77
- original: query,
78
- expanded: [...new Set(expanded)], // Deduplicate
79
- entities,
80
- synonyms,
81
- };
82
- }
83
- /**
84
- * Multi-query search combiner
85
- * Searches with multiple query variants and merges results
86
- */
87
- export async function multiQuerySearch(queries, searchFn, dedupeKey) {
88
- const allResults = [];
89
- // Search with each query variant
90
- for (const query of queries) {
91
- const results = await searchFn(query);
92
- allResults.push(...results);
93
- }
94
- // Deduplicate by key
95
- const seen = new Set();
96
- const unique = [];
97
- for (const item of allResults) {
98
- const key = dedupeKey(item);
99
- if (!seen.has(key)) {
100
- seen.add(key);
101
- unique.push(item);
102
- }
103
- }
104
- return unique;
105
- }
106
- //# sourceMappingURL=query-processor.js.map
@@ -1,13 +0,0 @@
1
- /** Query Rewriter - Rewrite user queries for better retrieval using LLM */
2
- import { type ContextMessage } from './context-collector.js';
3
- export interface RewriteResult {
4
- original: string;
5
- rewritten: string;
6
- expansions: string[];
7
- intent: 'search' | 'recall' | 'question' | 'context';
8
- confidence: number;
9
- method: 'llm' | 'synonym' | 'none';
10
- }
11
- export declare function rewriteQuery(query: string, context: ContextMessage[]): Promise<RewriteResult>;
12
- export declare function wouldBenefitFromRewrite(query: string): boolean;
13
- //# sourceMappingURL=query-rewriter.d.ts.map
@@ -1,118 +0,0 @@
1
- /** Query Rewriter - Rewrite user queries for better retrieval using LLM */
2
- import { logger } from '../logger.js';
3
- import { config } from '../../config.js';
4
- import { expandQuery } from './query-processor.js';
5
- const REWRITE_SYSTEM_PROMPT = `You are a search query optimizer. Given a conversation context and a user's latest message, rewrite the message into the single most effective search query to retrieve relevant memories.
6
-
7
- Rules:
8
- 1. Output ONLY the optimized search query - no explanations or extra text
9
- 2. Remove filler words (please, can you, etc.)
10
- 3. Focus on the core information need
11
- 4. Preserve important entities (names, dates, technical terms)
12
- 5. Add synonyms for key terms if helpful
13
- 6. Consider what memories would be most relevant
14
- 7. If the message is about recalling something specific, include those details`;
15
- export async function rewriteQuery(query, context) {
16
- if (!config.queryRewritingEnabled) {
17
- return {
18
- original: query,
19
- rewritten: query,
20
- expansions: [],
21
- intent: detectIntent(query),
22
- confidence: 1.0,
23
- method: 'none',
24
- };
25
- }
26
- if (config.queryRewritingFallbackEnabled) {
27
- try {
28
- const llmResult = await rewriteWithLLM(query, context);
29
- if (llmResult)
30
- return llmResult;
31
- }
32
- catch (error) {
33
- logger.warn(`[QueryRewriter] LLM rewrite failed, falling back to synonym: ${error instanceof Error ? error.message : String(error)}`);
34
- }
35
- }
36
- if (config.queryRewritingFallbackEnabled) {
37
- const expanded = expandQuery(query);
38
- return {
39
- original: query,
40
- rewritten: expanded.expanded[0] || query,
41
- expansions: expanded.expanded.slice(1),
42
- intent: detectIntent(query),
43
- confidence: 0.7,
44
- method: 'synonym',
45
- };
46
- }
47
- return {
48
- original: query,
49
- rewritten: query,
50
- expansions: [],
51
- intent: detectIntent(query),
52
- confidence: 1.0,
53
- method: 'none',
54
- };
55
- }
56
- async function rewriteWithLLM(query, context) {
57
- if (context.length < 2)
58
- return null;
59
- const lastUserMsg = context.filter(m => m.role === 'user').pop()?.content || '';
60
- const pronounPattern = /\b(it|that|this|they|them|those|these|he|she|his|her)\b/i;
61
- const hasPronouns = pronounPattern.test(query);
62
- const vaguePattern = /\b(the thing|the stuff|what (we|I) (talked|discussed|mentioned))\b/i;
63
- const hasVagueRef = vaguePattern.test(query);
64
- if (!hasPronouns && !hasVagueRef)
65
- return null;
66
- let rewritten = query;
67
- const entityPattern = /\b([A-Z][a-z]+(?:\s+[A-Z][a-z]+)*)\b/g;
68
- const contextEntities = lastUserMsg.match(entityPattern) || [];
69
- const techPattern = /\b([a-z]+\.(?:ts|js|py|json|md)|@[a-z]+\/[a-z]+|\b[A-Z]{2,}\b)\b/gi;
70
- const techTerms = lastUserMsg.match(techPattern) || [];
71
- if (contextEntities.length > 0 && hasPronouns) {
72
- const mostLikelyEntity = contextEntities[contextEntities.length - 1];
73
- if (!query.toLowerCase().includes(mostLikelyEntity.toLowerCase())) {
74
- rewritten = `${query} ${mostLikelyEntity}`;
75
- }
76
- }
77
- const firstTechTerm = techTerms[0];
78
- if (firstTechTerm && !query.includes(firstTechTerm)) {
79
- rewritten = `${rewritten} ${firstTechTerm}`;
80
- }
81
- if (rewritten !== query) {
82
- logger.info(`[QueryRewriter] Rewrote "${query}" -> "${rewritten}"`);
83
- return {
84
- original: query,
85
- rewritten,
86
- expansions: [],
87
- intent: detectIntent(query),
88
- confidence: 0.8,
89
- method: 'llm',
90
- };
91
- }
92
- return null;
93
- }
94
- function detectIntent(query) {
95
- const lower = query.toLowerCase();
96
- if (/\b(remember|recall|what did (we|I)|what was|retrieve)\b/.test(lower)) {
97
- return 'recall';
98
- }
99
- if (/^(what|who|when|where|why|how|which|is|are|can|do|does)/.test(lower)) {
100
- return 'question';
101
- }
102
- if (/\b(context|background|about|regarding|concerning)\b/.test(lower)) {
103
- return 'context';
104
- }
105
- return 'search';
106
- }
107
- export function wouldBenefitFromRewrite(query) {
108
- if (query.split(/\s+/).length < 3)
109
- return true;
110
- const pronounPattern = /\b(it|that|this|they|them|those|these|he|she|his|her)\b/i;
111
- if (pronounPattern.test(query))
112
- return true;
113
- const vaguePattern = /\b(the thing|the stuff|what (we|I) (talked|discussed|mentioned))\b/i;
114
- if (vaguePattern.test(query))
115
- return true;
116
- return false;
117
- }
118
- //# sourceMappingURL=query-rewriter.js.map
@@ -1,9 +0,0 @@
1
- /** Response Analyzer - Analyze LLM responses for memory references (Echo/Fizzle tracking) */
2
- export interface AnalysisResult {
3
- referencedMemoryIds: string[];
4
- referenceCount: number;
5
- hasReferences: boolean;
6
- }
7
- export declare function analyzeResponseForMemoryReferences(responseText: string, injectedMemoryIds: string[], injectedMemoryContent: Map<string, string>): AnalysisResult;
8
- export declare function mightContainMemoryReferences(responseText: string): boolean;
9
- //# sourceMappingURL=response-analyzer.d.ts.map
@@ -1,61 +0,0 @@
1
- /** Response Analyzer - Analyze LLM responses for memory references (Echo/Fizzle tracking) */
2
- import { logger } from '../logger.js';
3
- const REFERENCE_PATTERNS = [
4
- /[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/gi,
5
- /as (?:i |we )?(?:mentioned|noted|remembered|recalled|stored|saved)/gi,
6
- /(?:based|drawing) on (?:my|our|the) (?:memory|previous|earlier)/gi,
7
- /(?:i |we )?(?:recall|remember|noted) (?:that |earlier )?/gi,
8
- /from (?:my|our|the) (?:memory|notes|records)/gi,
9
- ];
10
- export function analyzeResponseForMemoryReferences(responseText, injectedMemoryIds, injectedMemoryContent) {
11
- const referencedMemoryIds = [];
12
- const responseLower = responseText.toLowerCase();
13
- for (const memoryId of injectedMemoryIds) {
14
- if (responseText.includes(memoryId)) {
15
- referencedMemoryIds.push(memoryId);
16
- logger.debug(`[ResponseAnalyzer] Direct reference found: ${memoryId}`);
17
- }
18
- }
19
- for (const [memoryId, content] of injectedMemoryContent) {
20
- if (referencedMemoryIds.includes(memoryId))
21
- continue;
22
- const contentWords = content.toLowerCase().split(/\s+/).filter(w => w.length > 3);
23
- if (contentWords.length < 5)
24
- continue;
25
- let matchCount = 0;
26
- for (const word of contentWords) {
27
- if (responseLower.includes(word)) {
28
- matchCount++;
29
- }
30
- }
31
- const matchRatio = matchCount / contentWords.length;
32
- if (matchRatio > 0.5) {
33
- referencedMemoryIds.push(memoryId);
34
- logger.debug(`[ResponseAnalyzer] Content match (${(matchRatio * 100).toFixed(0)}%): ${memoryId}`);
35
- }
36
- }
37
- for (const pattern of REFERENCE_PATTERNS) {
38
- const matches = responseText.match(pattern);
39
- if (matches && matches.length > 0) {
40
- logger.debug(`[ResponseAnalyzer] Reference pattern found: ${matches.length} matches`);
41
- }
42
- }
43
- const result = {
44
- referencedMemoryIds: [...new Set(referencedMemoryIds)],
45
- referenceCount: referencedMemoryIds.length,
46
- hasReferences: referencedMemoryIds.length > 0,
47
- };
48
- if (result.hasReferences) {
49
- logger.info(`[ResponseAnalyzer] Found ${result.referenceCount} memory references`);
50
- }
51
- return result;
52
- }
53
- export function mightContainMemoryReferences(responseText) {
54
- const responseLower = responseText.toLowerCase();
55
- const quickPatterns = [
56
- 'remember', 'recall', 'mentioned', 'noted', 'earlier',
57
- 'previous', 'as i', 'as we', 'from my', 'from our',
58
- ];
59
- return quickPatterns.some(pattern => responseLower.includes(pattern));
60
- }
61
- //# sourceMappingURL=response-analyzer.js.map
@@ -1,70 +0,0 @@
1
- /**
2
- * Retrieval Feedback System
3
- *
4
- * Tracks whether retrieved memories were useful in responses.
5
- * Strengthens useful paths, prunes stale nodes, tunes edge weights.
6
- */
7
- export interface RetrievalFeedback {
8
- memoryId: string;
9
- query: string;
10
- wasUseful: boolean;
11
- cited: boolean;
12
- responseId?: string;
13
- timestamp: Date;
14
- }
15
- export interface FeedbackStats {
16
- totalRetrievals: number;
17
- usefulRetrievals: number;
18
- citedRetrievals: number;
19
- usefulnessRate: number;
20
- citationRate: number;
21
- }
22
- /**
23
- * Record that a memory was retrieved for a query.
24
- * Call this when a memory appears in search results.
25
- */
26
- export declare function recordRetrieval(memoryId: string, query: string, options?: {
27
- sessionId?: string;
28
- }): void;
29
- /**
30
- * Record that a retrieved memory was actually useful.
31
- * Call this when a memory is cited or referenced in a response.
32
- */
33
- export declare function recordUsefulRetrieval(memoryId: string, query: string, options?: {
34
- cited?: boolean;
35
- responseId?: string;
36
- sessionId?: string;
37
- }): void;
38
- /**
39
- * Record that a memory was cited in a response.
40
- * This is stronger feedback than just "useful" - it means the memory
41
- * was explicitly referenced.
42
- */
43
- export declare function recordCitation(memoryId: string, responseId: string, options?: {
44
- sessionId?: string;
45
- }): void;
46
- /**
47
- * Get feedback statistics for a specific memory.
48
- */
49
- export declare function getRetrievalStats(memoryId: string): FeedbackStats;
50
- /**
51
- * Get overall feedback statistics.
52
- */
53
- export declare function getOverallFeedbackStats(): FeedbackStats;
54
- /**
55
- * Flush feedback to the database, updating association weights.
56
- */
57
- export declare function flushFeedback(): Promise<{
58
- strengthened: number;
59
- weakened: number;
60
- total: number;
61
- }>;
62
- /**
63
- * Start the periodic feedback flush timer.
64
- */
65
- export declare function startFeedbackFlushTimer(): void;
66
- /**
67
- * Stop the periodic feedback flush timer.
68
- */
69
- export declare function stopFeedbackFlushTimer(): void;
70
- //# sourceMappingURL=retrieval-feedback.d.ts.map
@@ -1,213 +0,0 @@
1
- /**
2
- * Retrieval Feedback System
3
- *
4
- * Tracks whether retrieved memories were useful in responses.
5
- * Strengthens useful paths, prunes stale nodes, tunes edge weights.
6
- */
7
- import { eq, sql } from 'drizzle-orm';
8
- import { getDb } from '../../db/index.js';
9
- import { getSchema } from '../../db/schema.js';
10
- import { logger } from '../logger.js';
11
- // ─── In-Memory Feedback Buffer ───────────────────────────────────────────────
12
- const feedbackBuffer = new Map();
13
- const MAX_BUFFER_SIZE = 1000;
14
- const FLUSH_INTERVAL_MS = 60000; // 1 minute
15
- let flushTimer = null;
16
- /**
17
- * Record that a memory was retrieved for a query.
18
- * Call this when a memory appears in search results.
19
- */
20
- export function recordRetrieval(memoryId, query, options) {
21
- const key = options?.sessionId || 'default';
22
- const buffer = feedbackBuffer.get(key) || [];
23
- buffer.push({
24
- memoryId,
25
- query,
26
- wasUseful: false, // Will be updated later
27
- cited: false,
28
- timestamp: new Date(),
29
- });
30
- // Trim buffer if too large
31
- if (buffer.length > MAX_BUFFER_SIZE) {
32
- buffer.splice(0, buffer.length - MAX_BUFFER_SIZE);
33
- }
34
- feedbackBuffer.set(key, buffer);
35
- }
36
- /**
37
- * Record that a retrieved memory was actually useful.
38
- * Call this when a memory is cited or referenced in a response.
39
- */
40
- export function recordUsefulRetrieval(memoryId, query, options) {
41
- const key = options?.sessionId || 'default';
42
- const buffer = feedbackBuffer.get(key) || [];
43
- // Find the existing retrieval record and update it
44
- const existing = buffer.find(f => f.memoryId === memoryId && f.query === query && !f.wasUseful);
45
- if (existing) {
46
- existing.wasUseful = true;
47
- existing.cited = options?.cited ?? false;
48
- existing.responseId = options?.responseId;
49
- }
50
- else {
51
- // Add a new record
52
- buffer.push({
53
- memoryId,
54
- query,
55
- wasUseful: true,
56
- cited: options?.cited ?? false,
57
- responseId: options?.responseId,
58
- timestamp: new Date(),
59
- });
60
- }
61
- feedbackBuffer.set(key, buffer);
62
- }
63
- /**
64
- * Record that a memory was cited in a response.
65
- * This is stronger feedback than just "useful" - it means the memory
66
- * was explicitly referenced.
67
- */
68
- export function recordCitation(memoryId, responseId, options) {
69
- const key = options?.sessionId || 'default';
70
- const buffer = feedbackBuffer.get(key) || [];
71
- // Mark all retrievals of this memory as useful
72
- for (const feedback of buffer) {
73
- if (feedback.memoryId === memoryId) {
74
- feedback.wasUseful = true;
75
- feedback.cited = true;
76
- feedback.responseId = responseId;
77
- }
78
- }
79
- feedbackBuffer.set(key, buffer);
80
- }
81
- /**
82
- * Get feedback statistics for a specific memory.
83
- */
84
- export function getRetrievalStats(memoryId) {
85
- let totalRetrievals = 0;
86
- let usefulRetrievals = 0;
87
- let citedRetrievals = 0;
88
- for (const [, buffer] of feedbackBuffer) {
89
- for (const feedback of buffer) {
90
- if (feedback.memoryId === memoryId) {
91
- totalRetrievals++;
92
- if (feedback.wasUseful)
93
- usefulRetrievals++;
94
- if (feedback.cited)
95
- citedRetrievals++;
96
- }
97
- }
98
- }
99
- return {
100
- totalRetrievals,
101
- usefulRetrievals,
102
- citedRetrievals,
103
- usefulnessRate: totalRetrievals > 0 ? usefulRetrievals / totalRetrievals : 0,
104
- citationRate: totalRetrievals > 0 ? citedRetrievals / totalRetrievals : 0,
105
- };
106
- }
107
- /**
108
- * Get overall feedback statistics.
109
- */
110
- export function getOverallFeedbackStats() {
111
- let totalRetrievals = 0;
112
- let usefulRetrievals = 0;
113
- let citedRetrievals = 0;
114
- for (const [, buffer] of feedbackBuffer) {
115
- for (const feedback of buffer) {
116
- totalRetrievals++;
117
- if (feedback.wasUseful)
118
- usefulRetrievals++;
119
- if (feedback.cited)
120
- citedRetrievals++;
121
- }
122
- }
123
- return {
124
- totalRetrievals,
125
- usefulRetrievals,
126
- citedRetrievals,
127
- usefulnessRate: totalRetrievals > 0 ? usefulRetrievals / totalRetrievals : 0,
128
- citationRate: totalRetrievals > 0 ? citedRetrievals / totalRetrievals : 0,
129
- };
130
- }
131
- /**
132
- * Flush feedback to the database, updating association weights.
133
- */
134
- export async function flushFeedback() {
135
- const db = await getDb();
136
- const schema = await getSchema();
137
- let strengthened = 0;
138
- let weakened = 0;
139
- let total = 0;
140
- for (const [, buffer] of feedbackBuffer) {
141
- for (const feedback of buffer) {
142
- total++;
143
- try {
144
- // Get associations involving this memory
145
- const associations = await db
146
- .select()
147
- .from(schema.memoryAssociations)
148
- .where(sql `${schema.memoryAssociations.fromMemoryId} = ${feedback.memoryId} OR ${schema.memoryAssociations.toMemoryId} = ${feedback.memoryId}`);
149
- for (const assoc of associations) {
150
- if (feedback.wasUseful) {
151
- // Strengthen: increase weight and coactivation count
152
- await db
153
- .update(schema.memoryAssociations)
154
- .set({
155
- weight: sql `${schema.memoryAssociations.weight} + 1`,
156
- coactivationCount: sql `${schema.memoryAssociations.coactivationCount} + 1`,
157
- lastCoactivatedAt: new Date(),
158
- })
159
- .where(eq(schema.memoryAssociations.id, assoc.id));
160
- strengthened++;
161
- }
162
- else {
163
- // Weaken: decrease weight slightly (but don't go below 1)
164
- await db
165
- .update(schema.memoryAssociations)
166
- .set({
167
- weight: sql `GREATEST(${schema.memoryAssociations.weight} - 0.5, 1)`,
168
- })
169
- .where(eq(schema.memoryAssociations.id, assoc.id));
170
- weakened++;
171
- }
172
- }
173
- }
174
- catch (error) {
175
- logger.debug('Error updating association weights', {
176
- memoryId: feedback.memoryId,
177
- error: error,
178
- });
179
- }
180
- }
181
- }
182
- // Clear the buffer after flushing
183
- feedbackBuffer.clear();
184
- logger.info('Feedback flushed', { strengthened, weakened, total });
185
- return { strengthened, weakened, total };
186
- }
187
- /**
188
- * Start the periodic feedback flush timer.
189
- */
190
- export function startFeedbackFlushTimer() {
191
- if (flushTimer)
192
- return;
193
- flushTimer = setInterval(async () => {
194
- try {
195
- await flushFeedback();
196
- }
197
- catch (error) {
198
- logger.error('Error flushing feedback', { error: error });
199
- }
200
- }, FLUSH_INTERVAL_MS);
201
- logger.info('Feedback flush timer started', { intervalMs: FLUSH_INTERVAL_MS });
202
- }
203
- /**
204
- * Stop the periodic feedback flush timer.
205
- */
206
- export function stopFeedbackFlushTimer() {
207
- if (flushTimer) {
208
- clearInterval(flushTimer);
209
- flushTimer = null;
210
- logger.info('Feedback flush timer stopped');
211
- }
212
- }
213
- //# sourceMappingURL=retrieval-feedback.js.map
@@ -1,10 +0,0 @@
1
- export declare function normalizeTags(tags?: string[]): string[];
2
- export declare function toSqliteJson(value: unknown): string | null;
3
- export declare function fromSqliteJson<T>(value: string | null | undefined): T | null;
4
- export declare function toSqliteTags(tags?: string[]): string | null;
5
- export declare function fromSqliteTags(value: string | null | undefined): string[];
6
- export declare function serializeTags(tags?: string[]): string[] | string | null | undefined;
7
- export declare function deserializeTags(value: string[] | string | null | undefined): string[];
8
- export declare function serializeMetadata(metadata: Record<string, unknown> | null | undefined): Record<string, unknown> | string | null;
9
- export declare function deserializeMetadata(value: Record<string, unknown> | string | null | undefined): Record<string, unknown> | null;
10
- //# sourceMappingURL=serialization.d.ts.map