sensorium-mcp 3.0.103 → 3.1.0-board.0

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 (664) hide show
  1. package/Install-Sensorium.ps1 +113 -20
  2. package/README.md +25 -0
  3. package/dist/config/agent-settings.d.ts +82 -0
  4. package/dist/config/agent-settings.d.ts.map +1 -0
  5. package/dist/config/agent-settings.js +261 -0
  6. package/dist/config/agent-settings.js.map +1 -0
  7. package/dist/config/agent-templates.d.ts +39 -0
  8. package/dist/config/agent-templates.d.ts.map +1 -0
  9. package/dist/config/agent-templates.js +105 -0
  10. package/dist/config/agent-templates.js.map +1 -0
  11. package/dist/config/detail-grant.d.ts +39 -0
  12. package/dist/config/detail-grant.d.ts.map +1 -0
  13. package/dist/config/detail-grant.js +61 -0
  14. package/dist/config/detail-grant.js.map +1 -0
  15. package/dist/config/index.d.ts +17 -0
  16. package/dist/config/index.d.ts.map +1 -0
  17. package/dist/config/index.js +59 -0
  18. package/dist/config/index.js.map +1 -0
  19. package/dist/config/keep-alive-settings.d.ts +29 -0
  20. package/dist/config/keep-alive-settings.d.ts.map +1 -0
  21. package/dist/config/keep-alive-settings.js +100 -0
  22. package/dist/config/keep-alive-settings.js.map +1 -0
  23. package/dist/config/mcp-settings.d.ts +59 -0
  24. package/dist/config/mcp-settings.d.ts.map +1 -0
  25. package/dist/config/mcp-settings.js +196 -0
  26. package/dist/config/mcp-settings.js.map +1 -0
  27. package/dist/config/misc-settings.d.ts +48 -0
  28. package/dist/config/misc-settings.d.ts.map +1 -0
  29. package/dist/config/misc-settings.js +168 -0
  30. package/dist/config/misc-settings.js.map +1 -0
  31. package/dist/config/settings-store.d.ts +49 -0
  32. package/dist/config/settings-store.d.ts.map +1 -0
  33. package/dist/config/settings-store.js +203 -0
  34. package/dist/config/settings-store.js.map +1 -0
  35. package/dist/dashboard/log-parser.d.ts +3 -0
  36. package/dist/dashboard/log-parser.d.ts.map +1 -1
  37. package/dist/dashboard/log-parser.js +49 -5
  38. package/dist/dashboard/log-parser.js.map +1 -1
  39. package/dist/dashboard/presets.d.ts +1 -1
  40. package/dist/dashboard/presets.d.ts.map +1 -1
  41. package/dist/dashboard/presets.js +1 -1
  42. package/dist/dashboard/presets.js.map +1 -1
  43. package/dist/dashboard/routes/agent-templates.d.ts.map +1 -1
  44. package/dist/dashboard/routes/agent-templates.js +13 -8
  45. package/dist/dashboard/routes/agent-templates.js.map +1 -1
  46. package/dist/dashboard/routes/board.d.ts +67 -0
  47. package/dist/dashboard/routes/board.d.ts.map +1 -0
  48. package/dist/dashboard/routes/board.js +612 -0
  49. package/dist/dashboard/routes/board.js.map +1 -0
  50. package/dist/dashboard/routes/claude.d.ts.map +1 -1
  51. package/dist/dashboard/routes/claude.js +14 -3
  52. package/dist/dashboard/routes/claude.js.map +1 -1
  53. package/dist/dashboard/routes/copilot.d.ts.map +1 -1
  54. package/dist/dashboard/routes/copilot.js +32 -7
  55. package/dist/dashboard/routes/copilot.js.map +1 -1
  56. package/dist/dashboard/routes/data.d.ts.map +1 -1
  57. package/dist/dashboard/routes/data.js +43 -15
  58. package/dist/dashboard/routes/data.js.map +1 -1
  59. package/dist/dashboard/routes/env-vars.d.ts.map +1 -1
  60. package/dist/dashboard/routes/env-vars.js.map +1 -1
  61. package/dist/dashboard/routes/mcp-servers.d.ts.map +1 -1
  62. package/dist/dashboard/routes/mcp-servers.js +11 -5
  63. package/dist/dashboard/routes/mcp-servers.js.map +1 -1
  64. package/dist/dashboard/routes/prompts.d.ts.map +1 -1
  65. package/dist/dashboard/routes/prompts.js +2 -2
  66. package/dist/dashboard/routes/prompts.js.map +1 -1
  67. package/dist/dashboard/routes/settings.d.ts +2 -0
  68. package/dist/dashboard/routes/settings.d.ts.map +1 -1
  69. package/dist/dashboard/routes/settings.js +29 -3
  70. package/dist/dashboard/routes/settings.js.map +1 -1
  71. package/dist/dashboard/routes/skills.d.ts.map +1 -1
  72. package/dist/dashboard/routes/skills.js +4 -4
  73. package/dist/dashboard/routes/skills.js.map +1 -1
  74. package/dist/dashboard/routes/snapshots.d.ts.map +1 -1
  75. package/dist/dashboard/routes/snapshots.js +18 -11
  76. package/dist/dashboard/routes/snapshots.js.map +1 -1
  77. package/dist/dashboard/routes/templates.d.ts.map +1 -1
  78. package/dist/dashboard/routes/templates.js +6 -3
  79. package/dist/dashboard/routes/templates.js.map +1 -1
  80. package/dist/dashboard/routes/threads-create.d.ts +22 -0
  81. package/dist/dashboard/routes/threads-create.d.ts.map +1 -0
  82. package/dist/dashboard/routes/threads-create.js +225 -0
  83. package/dist/dashboard/routes/threads-create.js.map +1 -0
  84. package/dist/dashboard/routes/threads-helpers.d.ts +28 -0
  85. package/dist/dashboard/routes/threads-helpers.d.ts.map +1 -0
  86. package/dist/dashboard/routes/threads-helpers.js +138 -0
  87. package/dist/dashboard/routes/threads-helpers.js.map +1 -0
  88. package/dist/dashboard/routes/threads-read.d.ts +26 -0
  89. package/dist/dashboard/routes/threads-read.d.ts.map +1 -0
  90. package/dist/dashboard/routes/threads-read.js +125 -0
  91. package/dist/dashboard/routes/threads-read.js.map +1 -0
  92. package/dist/dashboard/routes/threads.d.ts +5 -44
  93. package/dist/dashboard/routes/threads.d.ts.map +1 -1
  94. package/dist/dashboard/routes/threads.js +44 -500
  95. package/dist/dashboard/routes/threads.js.map +1 -1
  96. package/dist/dashboard/routes/types.d.ts +6 -0
  97. package/dist/dashboard/routes/types.d.ts.map +1 -1
  98. package/dist/dashboard/routes/types.js.map +1 -1
  99. package/dist/dashboard/routes.d.ts.map +1 -1
  100. package/dist/dashboard/routes.js +55 -10
  101. package/dist/dashboard/routes.js.map +1 -1
  102. package/dist/dashboard/spa.html +12 -12
  103. package/dist/data/board/board-schema.d.ts +22 -0
  104. package/dist/data/board/board-schema.d.ts.map +1 -0
  105. package/dist/data/board/board-schema.js +103 -0
  106. package/dist/data/board/board-schema.js.map +1 -0
  107. package/dist/data/board/board-types.d.ts +117 -0
  108. package/dist/data/board/board-types.d.ts.map +1 -0
  109. package/dist/data/board/board-types.js +9 -0
  110. package/dist/data/board/board-types.js.map +1 -0
  111. package/dist/data/board/card.repository.d.ts +64 -0
  112. package/dist/data/board/card.repository.d.ts.map +1 -0
  113. package/dist/data/board/card.repository.js +272 -0
  114. package/dist/data/board/card.repository.js.map +1 -0
  115. package/dist/data/board/comment.repository.d.ts +12 -0
  116. package/dist/data/board/comment.repository.d.ts.map +1 -0
  117. package/dist/data/board/comment.repository.js +31 -0
  118. package/dist/data/board/comment.repository.js.map +1 -0
  119. package/dist/data/board/lane.repository.d.ts +18 -0
  120. package/dist/data/board/lane.repository.d.ts.map +1 -0
  121. package/dist/data/board/lane.repository.js +44 -0
  122. package/dist/data/board/lane.repository.js.map +1 -0
  123. package/dist/data/board/profile-defaults.d.ts +19 -0
  124. package/dist/data/board/profile-defaults.d.ts.map +1 -0
  125. package/dist/data/board/profile-defaults.js +118 -0
  126. package/dist/data/board/profile-defaults.js.map +1 -0
  127. package/dist/data/daily-marker.d.ts.map +1 -1
  128. package/dist/data/daily-marker.js +1 -1
  129. package/dist/data/daily-marker.js.map +1 -1
  130. package/dist/data/file-storage.d.ts.map +1 -1
  131. package/dist/data/file-storage.js +40 -16
  132. package/dist/data/file-storage.js.map +1 -1
  133. package/dist/data/interfaces.d.ts +23 -2
  134. package/dist/data/interfaces.d.ts.map +1 -1
  135. package/dist/data/memory/bootstrap.d.ts +8 -1
  136. package/dist/data/memory/bootstrap.d.ts.map +1 -1
  137. package/dist/data/memory/bootstrap.js +76 -28
  138. package/dist/data/memory/bootstrap.js.map +1 -1
  139. package/dist/data/memory/consolidation.d.ts +9 -4
  140. package/dist/data/memory/consolidation.d.ts.map +1 -1
  141. package/dist/data/memory/consolidation.js +38 -17
  142. package/dist/data/memory/consolidation.js.map +1 -1
  143. package/dist/data/memory/db-types.d.ts +4 -0
  144. package/dist/data/memory/db-types.d.ts.map +1 -0
  145. package/dist/data/memory/db-types.js +2 -0
  146. package/dist/data/memory/db-types.js.map +1 -0
  147. package/dist/data/memory/episodes.d.ts.map +1 -1
  148. package/dist/data/memory/episodes.js +3 -5
  149. package/dist/data/memory/episodes.js.map +1 -1
  150. package/dist/data/memory/index.d.ts +27 -14
  151. package/dist/data/memory/index.d.ts.map +1 -1
  152. package/dist/data/memory/index.js +27 -14
  153. package/dist/data/memory/index.js.map +1 -1
  154. package/dist/data/memory/migration-runner.d.ts +25 -2
  155. package/dist/data/memory/migration-runner.d.ts.map +1 -1
  156. package/dist/data/memory/migration-runner.js +110 -16
  157. package/dist/data/memory/migration-runner.js.map +1 -1
  158. package/dist/data/memory/narrative-lint.d.ts +12 -0
  159. package/dist/data/memory/narrative-lint.d.ts.map +1 -0
  160. package/dist/data/memory/narrative-lint.js +117 -0
  161. package/dist/data/memory/narrative-lint.js.map +1 -0
  162. package/dist/data/memory/narrative-resolutions.d.ts +26 -0
  163. package/dist/data/memory/narrative-resolutions.d.ts.map +1 -0
  164. package/dist/data/memory/narrative-resolutions.js +81 -0
  165. package/dist/data/memory/narrative-resolutions.js.map +1 -0
  166. package/dist/data/memory/narrative-sources.d.ts +19 -0
  167. package/dist/data/memory/narrative-sources.d.ts.map +1 -0
  168. package/dist/data/memory/narrative-sources.js +150 -0
  169. package/dist/data/memory/narrative-sources.js.map +1 -0
  170. package/dist/data/memory/narrative-store.d.ts +11 -0
  171. package/dist/data/memory/narrative-store.d.ts.map +1 -0
  172. package/dist/data/memory/narrative-store.js +80 -0
  173. package/dist/data/memory/narrative-store.js.map +1 -0
  174. package/dist/data/memory/narrative-types.d.ts +15 -0
  175. package/dist/data/memory/narrative-types.d.ts.map +1 -0
  176. package/dist/data/memory/narrative-types.js +3 -0
  177. package/dist/data/memory/narrative-types.js.map +1 -0
  178. package/dist/data/memory/narrative.d.ts +5 -2
  179. package/dist/data/memory/narrative.d.ts.map +1 -1
  180. package/dist/data/memory/narrative.js +35 -521
  181. package/dist/data/memory/narrative.js.map +1 -1
  182. package/dist/data/memory/note-archival.d.ts +42 -0
  183. package/dist/data/memory/note-archival.d.ts.map +1 -0
  184. package/dist/data/memory/note-archival.js +77 -0
  185. package/dist/data/memory/note-archival.js.map +1 -0
  186. package/dist/data/memory/note-embeddings.d.ts +27 -0
  187. package/dist/data/memory/note-embeddings.d.ts.map +1 -0
  188. package/dist/data/memory/note-embeddings.js +98 -0
  189. package/dist/data/memory/note-embeddings.js.map +1 -0
  190. package/dist/data/memory/reflection-dedup.d.ts +17 -0
  191. package/dist/data/memory/reflection-dedup.d.ts.map +1 -0
  192. package/dist/data/memory/reflection-dedup.js +55 -0
  193. package/dist/data/memory/reflection-dedup.js.map +1 -0
  194. package/dist/data/memory/reflection-gates.d.ts +40 -0
  195. package/dist/data/memory/reflection-gates.d.ts.map +1 -0
  196. package/dist/data/memory/reflection-gates.js +220 -0
  197. package/dist/data/memory/reflection-gates.js.map +1 -0
  198. package/dist/data/memory/reflection-sources.d.ts +13 -0
  199. package/dist/data/memory/reflection-sources.d.ts.map +1 -0
  200. package/dist/data/memory/reflection-sources.js +115 -0
  201. package/dist/data/memory/reflection-sources.js.map +1 -0
  202. package/dist/data/memory/reflection.d.ts +5 -35
  203. package/dist/data/memory/reflection.d.ts.map +1 -1
  204. package/dist/data/memory/reflection.js +32 -332
  205. package/dist/data/memory/reflection.js.map +1 -1
  206. package/dist/data/memory/schema-ddl.d.ts +2 -2
  207. package/dist/data/memory/schema-ddl.d.ts.map +1 -1
  208. package/dist/data/memory/schema-ddl.js +13 -11
  209. package/dist/data/memory/schema-ddl.js.map +1 -1
  210. package/dist/data/memory/schema-guard.d.ts +1 -1
  211. package/dist/data/memory/schema-guard.d.ts.map +1 -1
  212. package/dist/data/memory/schema-guard.js +5 -4
  213. package/dist/data/memory/schema-guard.js.map +1 -1
  214. package/dist/data/memory/schema.d.ts +2 -2
  215. package/dist/data/memory/schema.d.ts.map +1 -1
  216. package/dist/data/memory/schema.js +8 -2
  217. package/dist/data/memory/schema.js.map +1 -1
  218. package/dist/data/memory/semantic-notes.d.ts +120 -0
  219. package/dist/data/memory/semantic-notes.d.ts.map +1 -0
  220. package/dist/data/memory/semantic-notes.js +330 -0
  221. package/dist/data/memory/semantic-notes.js.map +1 -0
  222. package/dist/data/memory/semantic-search.d.ts +29 -0
  223. package/dist/data/memory/semantic-search.d.ts.map +1 -0
  224. package/dist/data/memory/semantic-search.js +158 -0
  225. package/dist/data/memory/semantic-search.js.map +1 -0
  226. package/dist/data/memory/synthesis.d.ts.map +1 -1
  227. package/dist/data/memory/synthesis.js +15 -7
  228. package/dist/data/memory/synthesis.js.map +1 -1
  229. package/dist/data/memory/thread-registry.d.ts +2 -2
  230. package/dist/data/memory/thread-registry.d.ts.map +1 -1
  231. package/dist/data/memory/thread-registry.js +91 -37
  232. package/dist/data/memory/thread-registry.js.map +1 -1
  233. package/dist/data/memory/topic-shift.js +3 -3
  234. package/dist/data/memory/topic-shift.js.map +1 -1
  235. package/dist/data/memory/utils.d.ts +0 -5
  236. package/dist/data/memory/utils.d.ts.map +1 -1
  237. package/dist/data/memory/utils.js +0 -94
  238. package/dist/data/memory/utils.js.map +1 -1
  239. package/dist/data/sent-message.repository.js +2 -2
  240. package/dist/data/sent-message.repository.js.map +1 -1
  241. package/dist/data/templates.js +2 -2
  242. package/dist/data/templates.js.map +1 -1
  243. package/dist/index.js +135 -38
  244. package/dist/index.js.map +1 -1
  245. package/dist/integrations/openai/chat.d.ts +7 -1
  246. package/dist/integrations/openai/chat.d.ts.map +1 -1
  247. package/dist/integrations/openai/chat.js +24 -7
  248. package/dist/integrations/openai/chat.js.map +1 -1
  249. package/dist/integrations/openai/speech.d.ts +5 -2
  250. package/dist/integrations/openai/speech.d.ts.map +1 -1
  251. package/dist/integrations/openai/speech.js +7 -4
  252. package/dist/integrations/openai/speech.js.map +1 -1
  253. package/dist/integrations/openai/video.d.ts.map +1 -1
  254. package/dist/integrations/openai/video.js +21 -10
  255. package/dist/integrations/openai/video.js.map +1 -1
  256. package/dist/integrations/openai/vision.d.ts.map +1 -1
  257. package/dist/integrations/openai/vision.js.map +1 -1
  258. package/dist/integrations/openai/voice-emotion.d.ts.map +1 -1
  259. package/dist/integrations/openai/voice-emotion.js +2 -2
  260. package/dist/integrations/openai/voice-emotion.js.map +1 -1
  261. package/dist/integrations/telegram/types.d.ts +9 -0
  262. package/dist/integrations/telegram/types.d.ts.map +1 -1
  263. package/dist/lib/logger.d.ts.map +1 -0
  264. package/dist/{logger.js → lib/logger.js} +98 -52
  265. package/dist/lib/logger.js.map +1 -0
  266. package/dist/lib/markdown.d.ts +13 -0
  267. package/dist/lib/markdown.d.ts.map +1 -0
  268. package/dist/{markdown.js → lib/markdown.js} +58 -5
  269. package/dist/lib/markdown.js.map +1 -0
  270. package/dist/{types.d.ts → lib/types.d.ts} +0 -1
  271. package/dist/lib/types.d.ts.map +1 -0
  272. package/dist/lib/types.js.map +1 -0
  273. package/dist/lib/usage-metering/index.d.ts +13 -0
  274. package/dist/lib/usage-metering/index.d.ts.map +1 -0
  275. package/dist/lib/usage-metering/index.js +10 -0
  276. package/dist/lib/usage-metering/index.js.map +1 -0
  277. package/dist/lib/usage-metering/meter.d.ts +34 -0
  278. package/dist/lib/usage-metering/meter.d.ts.map +1 -0
  279. package/dist/lib/usage-metering/meter.js +28 -0
  280. package/dist/lib/usage-metering/meter.js.map +1 -0
  281. package/dist/lib/usage-metering/pricing.d.ts +39 -0
  282. package/dist/lib/usage-metering/pricing.d.ts.map +1 -0
  283. package/dist/lib/usage-metering/pricing.js +49 -0
  284. package/dist/lib/usage-metering/pricing.js.map +1 -0
  285. package/dist/lib/usage-metering/sink.d.ts +24 -0
  286. package/dist/lib/usage-metering/sink.d.ts.map +1 -0
  287. package/dist/lib/usage-metering/sink.js +56 -0
  288. package/dist/lib/usage-metering/sink.js.map +1 -0
  289. package/dist/lib/utils.d.ts.map +1 -0
  290. package/dist/{utils.js → lib/utils.js} +29 -9
  291. package/dist/lib/utils.js.map +1 -0
  292. package/dist/llm/json.d.ts +14 -0
  293. package/dist/llm/json.d.ts.map +1 -0
  294. package/dist/llm/json.js +112 -0
  295. package/dist/llm/json.js.map +1 -0
  296. package/dist/llm/prompts/narrative.d.ts +7 -0
  297. package/dist/llm/prompts/narrative.d.ts.map +1 -0
  298. package/dist/llm/prompts/narrative.js +124 -0
  299. package/dist/llm/prompts/narrative.js.map +1 -0
  300. package/dist/llm/prompts/reflection.d.ts +6 -0
  301. package/dist/llm/prompts/reflection.d.ts.map +1 -0
  302. package/dist/llm/prompts/reflection.js +77 -0
  303. package/dist/llm/prompts/reflection.js.map +1 -0
  304. package/dist/server/factory.d.ts +2 -2
  305. package/dist/server/factory.d.ts.map +1 -1
  306. package/dist/server/factory.js +176 -84
  307. package/dist/server/factory.js.map +1 -1
  308. package/dist/{http-server.d.ts → server/http-server.d.ts} +6 -3
  309. package/dist/server/http-server.d.ts.map +1 -0
  310. package/dist/{http-server.js → server/http-server.js} +92 -24
  311. package/dist/server/http-server.js.map +1 -0
  312. package/dist/{stdio-server.d.ts → server/stdio-server.d.ts} +1 -1
  313. package/dist/server/stdio-server.d.ts.map +1 -0
  314. package/dist/{stdio-server.js → server/stdio-server.js} +25 -11
  315. package/dist/server/stdio-server.js.map +1 -0
  316. package/dist/services/agent-spawn.service.d.ts +4 -4
  317. package/dist/services/agent-spawn.service.d.ts.map +1 -1
  318. package/dist/services/agent-spawn.service.js +30 -14
  319. package/dist/services/agent-spawn.service.js.map +1 -1
  320. package/dist/services/background-runner.d.ts +2 -2
  321. package/dist/services/background-runner.d.ts.map +1 -1
  322. package/dist/services/background-runner.js +13 -4
  323. package/dist/services/background-runner.js.map +1 -1
  324. package/dist/services/board/board-signals.d.ts +25 -0
  325. package/dist/services/board/board-signals.d.ts.map +1 -0
  326. package/dist/services/board/board-signals.js +83 -0
  327. package/dist/services/board/board-signals.js.map +1 -0
  328. package/dist/services/board/card-briefing.d.ts +17 -0
  329. package/dist/services/board/card-briefing.d.ts.map +1 -0
  330. package/dist/services/board/card-briefing.js +84 -0
  331. package/dist/services/board/card-briefing.js.map +1 -0
  332. package/dist/services/board/orchestrator.service.d.ts +55 -0
  333. package/dist/services/board/orchestrator.service.d.ts.map +1 -0
  334. package/dist/services/board/orchestrator.service.js +193 -0
  335. package/dist/services/board/orchestrator.service.js.map +1 -0
  336. package/dist/services/board/release-worker.d.ts +32 -0
  337. package/dist/services/board/release-worker.d.ts.map +1 -0
  338. package/dist/services/board/release-worker.js +49 -0
  339. package/dist/services/board/release-worker.js.map +1 -0
  340. package/dist/services/board/report-capture.d.ts +48 -0
  341. package/dist/services/board/report-capture.d.ts.map +1 -0
  342. package/dist/services/board/report-capture.js +172 -0
  343. package/dist/services/board/report-capture.js.map +1 -0
  344. package/dist/services/board/worker-spawn.d.ts +30 -0
  345. package/dist/services/board/worker-spawn.d.ts.map +1 -0
  346. package/dist/services/board/worker-spawn.js +90 -0
  347. package/dist/services/board/worker-spawn.js.map +1 -0
  348. package/dist/services/broker-client.d.ts +181 -0
  349. package/dist/services/broker-client.d.ts.map +1 -0
  350. package/dist/services/broker-client.js +323 -0
  351. package/dist/services/broker-client.js.map +1 -0
  352. package/dist/services/claude-spawn.service.d.ts +1 -1
  353. package/dist/services/claude-spawn.service.d.ts.map +1 -1
  354. package/dist/services/claude-spawn.service.js +138 -55
  355. package/dist/services/claude-spawn.service.js.map +1 -1
  356. package/dist/services/codex-spawn.service.d.ts +1 -1
  357. package/dist/services/codex-spawn.service.d.ts.map +1 -1
  358. package/dist/services/codex-spawn.service.js +54 -47
  359. package/dist/services/codex-spawn.service.js.map +1 -1
  360. package/dist/services/consolidation-prompts.d.ts +26 -0
  361. package/dist/services/consolidation-prompts.d.ts.map +1 -0
  362. package/dist/services/consolidation-prompts.js +144 -0
  363. package/dist/services/consolidation-prompts.js.map +1 -0
  364. package/dist/services/consolidation.service.d.ts +1 -5
  365. package/dist/services/consolidation.service.d.ts.map +1 -1
  366. package/dist/services/consolidation.service.js +99 -352
  367. package/dist/services/consolidation.service.js.map +1 -1
  368. package/dist/services/copilot-spawn.service.d.ts +1 -1
  369. package/dist/services/copilot-spawn.service.d.ts.map +1 -1
  370. package/dist/services/copilot-spawn.service.js +105 -59
  371. package/dist/services/copilot-spawn.service.js.map +1 -1
  372. package/dist/{daily-session.d.ts → services/daily-session.d.ts} +1 -1
  373. package/dist/services/daily-session.d.ts.map +1 -0
  374. package/dist/{daily-session.js → services/daily-session.js} +15 -14
  375. package/dist/services/daily-session.js.map +1 -0
  376. package/dist/services/dispatcher/broker.d.ts +10 -9
  377. package/dist/services/dispatcher/broker.d.ts.map +1 -1
  378. package/dist/services/dispatcher/broker.js +67 -47
  379. package/dist/services/dispatcher/broker.js.map +1 -1
  380. package/dist/services/dispatcher/index.d.ts +1 -1
  381. package/dist/services/dispatcher/index.d.ts.map +1 -1
  382. package/dist/services/dispatcher/index.js +1 -1
  383. package/dist/services/dispatcher/index.js.map +1 -1
  384. package/dist/services/dispatcher/lock.d.ts.map +1 -1
  385. package/dist/services/dispatcher/lock.js +24 -9
  386. package/dist/services/dispatcher/lock.js.map +1 -1
  387. package/dist/services/dispatcher/poller.d.ts +1 -1
  388. package/dist/services/dispatcher/poller.d.ts.map +1 -1
  389. package/dist/services/dispatcher/poller.js +112 -53
  390. package/dist/services/dispatcher/poller.js.map +1 -1
  391. package/dist/services/drive.d.ts.map +1 -0
  392. package/dist/{drive.js → services/drive.js} +1 -1
  393. package/dist/services/drive.js.map +1 -0
  394. package/dist/services/flight-recorder.service.d.ts +37 -0
  395. package/dist/services/flight-recorder.service.d.ts.map +1 -0
  396. package/dist/services/flight-recorder.service.js +211 -0
  397. package/dist/services/flight-recorder.service.js.map +1 -0
  398. package/dist/services/intent.d.ts.map +1 -0
  399. package/dist/{intent.js → services/intent.js} +78 -23
  400. package/dist/services/intent.js.map +1 -0
  401. package/dist/services/keep-alive-sync.service.d.ts +11 -0
  402. package/dist/services/keep-alive-sync.service.d.ts.map +1 -0
  403. package/dist/services/keep-alive-sync.service.js +47 -0
  404. package/dist/services/keep-alive-sync.service.js.map +1 -0
  405. package/dist/services/keeper.service.d.ts +10 -1
  406. package/dist/services/keeper.service.d.ts.map +1 -1
  407. package/dist/services/keeper.service.js +303 -43
  408. package/dist/services/keeper.service.js.map +1 -1
  409. package/dist/services/maintenance-signal.js +1 -1
  410. package/dist/services/maintenance-signal.js.map +1 -1
  411. package/dist/services/mcp-config.service.d.ts.map +1 -1
  412. package/dist/services/mcp-config.service.js +19 -6
  413. package/dist/services/mcp-config.service.js.map +1 -1
  414. package/dist/services/memory-briefing.service.d.ts.map +1 -1
  415. package/dist/services/memory-briefing.service.js +13 -7
  416. package/dist/services/memory-briefing.service.js.map +1 -1
  417. package/dist/services/memory-pruning.service.d.ts +12 -0
  418. package/dist/services/memory-pruning.service.d.ts.map +1 -0
  419. package/dist/services/memory-pruning.service.js +179 -0
  420. package/dist/services/memory-pruning.service.js.map +1 -0
  421. package/dist/services/passive-notice.service.d.ts +39 -0
  422. package/dist/services/passive-notice.service.d.ts.map +1 -0
  423. package/dist/services/passive-notice.service.js +274 -0
  424. package/dist/services/passive-notice.service.js.map +1 -0
  425. package/dist/services/process.service.d.ts +43 -9
  426. package/dist/services/process.service.d.ts.map +1 -1
  427. package/dist/services/process.service.js +184 -309
  428. package/dist/services/process.service.js.map +1 -1
  429. package/dist/services/reconnect-snapshot.service.d.ts.map +1 -1
  430. package/dist/services/reconnect-snapshot.service.js +3 -3
  431. package/dist/services/reconnect-snapshot.service.js.map +1 -1
  432. package/dist/{scheduler.d.ts → services/scheduler.d.ts} +2 -23
  433. package/dist/services/scheduler.d.ts.map +1 -0
  434. package/dist/{scheduler.js → services/scheduler.js} +72 -19
  435. package/dist/services/scheduler.js.map +1 -0
  436. package/dist/services/self-update.service.d.ts +26 -5
  437. package/dist/services/self-update.service.d.ts.map +1 -1
  438. package/dist/services/self-update.service.js +208 -95
  439. package/dist/services/self-update.service.js.map +1 -1
  440. package/dist/services/spawn-common.d.ts +67 -17
  441. package/dist/services/spawn-common.d.ts.map +1 -1
  442. package/dist/services/spawn-common.js +401 -50
  443. package/dist/services/spawn-common.js.map +1 -1
  444. package/dist/services/spawn-exit-watcher.d.ts +32 -0
  445. package/dist/services/spawn-exit-watcher.d.ts.map +1 -0
  446. package/dist/services/spawn-exit-watcher.js +102 -0
  447. package/dist/services/spawn-exit-watcher.js.map +1 -0
  448. package/dist/{telegram.d.ts → services/telegram.d.ts} +3 -3
  449. package/dist/services/telegram.d.ts.map +1 -0
  450. package/dist/{telegram.js → services/telegram.js} +16 -8
  451. package/dist/services/telegram.js.map +1 -0
  452. package/dist/services/thread-config.service.d.ts +25 -0
  453. package/dist/services/thread-config.service.d.ts.map +1 -0
  454. package/dist/services/thread-config.service.js +73 -0
  455. package/dist/services/thread-config.service.js.map +1 -0
  456. package/dist/services/thread-health.service.d.ts +19 -1
  457. package/dist/services/thread-health.service.d.ts.map +1 -1
  458. package/dist/services/thread-health.service.js +101 -17
  459. package/dist/services/thread-health.service.js.map +1 -1
  460. package/dist/services/thread-lifecycle.service.d.ts.map +1 -1
  461. package/dist/services/thread-lifecycle.service.js +26 -7
  462. package/dist/services/thread-lifecycle.service.js.map +1 -1
  463. package/dist/services/topic.service.d.ts.map +1 -1
  464. package/dist/services/topic.service.js +17 -6
  465. package/dist/services/topic.service.js.map +1 -1
  466. package/dist/services/worker-cleanup.service.d.ts +21 -3
  467. package/dist/services/worker-cleanup.service.d.ts.map +1 -1
  468. package/dist/services/worker-cleanup.service.js +348 -90
  469. package/dist/services/worker-cleanup.service.js.map +1 -1
  470. package/dist/sessions/dashboard-registry.d.ts +38 -0
  471. package/dist/sessions/dashboard-registry.d.ts.map +1 -0
  472. package/dist/sessions/dashboard-registry.js +84 -0
  473. package/dist/sessions/dashboard-registry.js.map +1 -0
  474. package/dist/{sessions.d.ts → sessions/mcp-registry.d.ts} +9 -60
  475. package/dist/sessions/mcp-registry.d.ts.map +1 -0
  476. package/dist/{sessions.js → sessions/mcp-registry.js} +13 -214
  477. package/dist/sessions/mcp-registry.js.map +1 -0
  478. package/dist/sessions/session-store.d.ts +17 -0
  479. package/dist/sessions/session-store.d.ts.map +1 -0
  480. package/dist/sessions/session-store.js +69 -0
  481. package/dist/sessions/session-store.js.map +1 -0
  482. package/dist/sessions/topic-registry.d.ts +14 -0
  483. package/dist/sessions/topic-registry.d.ts.map +1 -0
  484. package/dist/sessions/topic-registry.js +67 -0
  485. package/dist/sessions/topic-registry.js.map +1 -0
  486. package/dist/tools/definitions.d.ts +1 -9
  487. package/dist/tools/definitions.d.ts.map +1 -1
  488. package/dist/tools/definitions.js.map +1 -1
  489. package/dist/tools/defs/memory-defs.d.ts +1 -1
  490. package/dist/tools/defs/memory-defs.d.ts.map +1 -1
  491. package/dist/tools/defs/memory-defs.js +1 -1
  492. package/dist/tools/defs/memory-defs.js.map +1 -1
  493. package/dist/tools/defs/session-defs.d.ts +1 -1
  494. package/dist/tools/defs/session-defs.d.ts.map +1 -1
  495. package/dist/tools/defs/session-defs.js +24 -17
  496. package/dist/tools/defs/session-defs.js.map +1 -1
  497. package/dist/tools/defs/skill-defs.d.ts +1 -1
  498. package/dist/tools/defs/skill-defs.d.ts.map +1 -1
  499. package/dist/tools/defs/types.d.ts +11 -0
  500. package/dist/tools/defs/types.d.ts.map +1 -0
  501. package/dist/{chat-ui/src → tools/defs}/types.js.map +1 -1
  502. package/dist/tools/defs/utility-defs.d.ts +1 -1
  503. package/dist/tools/defs/utility-defs.d.ts.map +1 -1
  504. package/dist/tools/defs/utility-defs.js +4 -3
  505. package/dist/tools/defs/utility-defs.js.map +1 -1
  506. package/dist/tools/defs/wait-defs.d.ts +1 -1
  507. package/dist/tools/defs/wait-defs.d.ts.map +1 -1
  508. package/dist/tools/delegate-tool.d.ts +3 -3
  509. package/dist/tools/delegate-tool.d.ts.map +1 -1
  510. package/dist/tools/delegate-tool.js +177 -45
  511. package/dist/tools/delegate-tool.js.map +1 -1
  512. package/dist/tools/memory-tools.d.ts +3 -3
  513. package/dist/tools/memory-tools.d.ts.map +1 -1
  514. package/dist/tools/memory-tools.js +111 -40
  515. package/dist/tools/memory-tools.js.map +1 -1
  516. package/dist/{response-builders.d.ts → tools/response-builders.d.ts} +2 -2
  517. package/dist/tools/response-builders.d.ts.map +1 -0
  518. package/dist/{response-builders.js → tools/response-builders.js} +151 -30
  519. package/dist/tools/response-builders.js.map +1 -0
  520. package/dist/tools/session-tools.d.ts +5 -14
  521. package/dist/tools/session-tools.d.ts.map +1 -1
  522. package/dist/tools/session-tools.js +51 -32
  523. package/dist/tools/session-tools.js.map +1 -1
  524. package/dist/tools/shared-agent-utils.d.ts +1 -1
  525. package/dist/tools/shared-agent-utils.d.ts.map +1 -1
  526. package/dist/tools/shared-agent-utils.js +2 -4
  527. package/dist/tools/shared-agent-utils.js.map +1 -1
  528. package/dist/tools/skill-tools.d.ts +1 -1
  529. package/dist/tools/skill-tools.d.ts.map +1 -1
  530. package/dist/tools/skill-tools.js +12 -7
  531. package/dist/tools/skill-tools.js.map +1 -1
  532. package/dist/tools/start-session-tool.d.ts +3 -3
  533. package/dist/tools/start-session-tool.d.ts.map +1 -1
  534. package/dist/tools/start-session-tool.js +35 -25
  535. package/dist/tools/start-session-tool.js.map +1 -1
  536. package/dist/tools/utility-tools.d.ts +3 -3
  537. package/dist/tools/utility-tools.d.ts.map +1 -1
  538. package/dist/tools/utility-tools.js +47 -29
  539. package/dist/tools/utility-tools.js.map +1 -1
  540. package/dist/tools/wait/auto-forward.d.ts +1 -1
  541. package/dist/tools/wait/auto-forward.d.ts.map +1 -1
  542. package/dist/tools/wait/auto-forward.js +6 -4
  543. package/dist/tools/wait/auto-forward.js.map +1 -1
  544. package/dist/tools/wait/context.d.ts +58 -0
  545. package/dist/tools/wait/context.d.ts.map +1 -0
  546. package/dist/tools/wait/context.js +5 -0
  547. package/dist/tools/wait/context.js.map +1 -0
  548. package/dist/tools/wait/drive-handler.d.ts +2 -2
  549. package/dist/tools/wait/drive-handler.d.ts.map +1 -1
  550. package/dist/tools/wait/drive-handler.js +25 -13
  551. package/dist/tools/wait/drive-handler.js.map +1 -1
  552. package/dist/tools/wait/index.d.ts +2 -1
  553. package/dist/tools/wait/index.d.ts.map +1 -1
  554. package/dist/tools/wait/index.js.map +1 -1
  555. package/dist/tools/wait/media-processor.d.ts +4 -4
  556. package/dist/tools/wait/media-processor.d.ts.map +1 -1
  557. package/dist/tools/wait/media-processor.js +18 -9
  558. package/dist/tools/wait/media-processor.js.map +1 -1
  559. package/dist/tools/wait/message-delivery.d.ts +15 -5
  560. package/dist/tools/wait/message-delivery.d.ts.map +1 -1
  561. package/dist/tools/wait/message-delivery.js +139 -38
  562. package/dist/tools/wait/message-delivery.js.map +1 -1
  563. package/dist/tools/wait/message-processing.d.ts +2 -2
  564. package/dist/tools/wait/message-processing.d.ts.map +1 -1
  565. package/dist/tools/wait/message-processing.js +95 -37
  566. package/dist/tools/wait/message-processing.js.map +1 -1
  567. package/dist/tools/wait/poll-loop.d.ts +2 -41
  568. package/dist/tools/wait/poll-loop.d.ts.map +1 -1
  569. package/dist/tools/wait/poll-loop.js +101 -24
  570. package/dist/tools/wait/poll-loop.js.map +1 -1
  571. package/dist/tools/wait/reaction-handler.d.ts +3 -3
  572. package/dist/tools/wait/reaction-handler.d.ts.map +1 -1
  573. package/dist/tools/wait/reaction-handler.js +6 -6
  574. package/dist/tools/wait/reaction-handler.js.map +1 -1
  575. package/dist/tools/wait/task-handler.d.ts +1 -1
  576. package/dist/tools/wait/task-handler.d.ts.map +1 -1
  577. package/dist/tools/wait/task-handler.js +5 -4
  578. package/dist/tools/wait/task-handler.js.map +1 -1
  579. package/package.json +12 -2
  580. package/templates/code-review.default.md +1 -1
  581. package/templates/fire-and-forget.default.md +1 -1
  582. package/templates/handoff.default.md +1 -1
  583. package/templates/sensorium-repair.default.md +1 -1
  584. package/templates/sleep.default.md +1 -1
  585. package/templates/swarm.default.md +4 -1
  586. package/dist/chat-ui/src/main.d.ts +0 -2
  587. package/dist/chat-ui/src/main.d.ts.map +0 -1
  588. package/dist/chat-ui/src/main.js +0 -4
  589. package/dist/chat-ui/src/main.js.map +0 -1
  590. package/dist/chat-ui/src/markdown.d.ts +0 -2
  591. package/dist/chat-ui/src/markdown.d.ts.map +0 -1
  592. package/dist/chat-ui/src/markdown.js +0 -39
  593. package/dist/chat-ui/src/markdown.js.map +0 -1
  594. package/dist/chat-ui/src/mock-data.d.ts +0 -4
  595. package/dist/chat-ui/src/mock-data.d.ts.map +0 -1
  596. package/dist/chat-ui/src/mock-data.js +0 -230
  597. package/dist/chat-ui/src/mock-data.js.map +0 -1
  598. package/dist/chat-ui/src/types.d.ts +0 -47
  599. package/dist/chat-ui/src/types.d.ts.map +0 -1
  600. package/dist/chat-ui/vite.config.d.ts +0 -3
  601. package/dist/chat-ui/vite.config.d.ts.map +0 -1
  602. package/dist/chat-ui/vite.config.js +0 -14
  603. package/dist/chat-ui/vite.config.js.map +0 -1
  604. package/dist/config.d.ts +0 -228
  605. package/dist/config.d.ts.map +0 -1
  606. package/dist/config.js +0 -841
  607. package/dist/config.js.map +0 -1
  608. package/dist/daily-session.d.ts.map +0 -1
  609. package/dist/daily-session.js.map +0 -1
  610. package/dist/dashboard.d.ts +0 -10
  611. package/dist/dashboard.d.ts.map +0 -1
  612. package/dist/dashboard.js +0 -10
  613. package/dist/dashboard.js.map +0 -1
  614. package/dist/data/memory/semantic.d.ts +0 -158
  615. package/dist/data/memory/semantic.d.ts.map +0 -1
  616. package/dist/data/memory/semantic.js +0 -588
  617. package/dist/data/memory/semantic.js.map +0 -1
  618. package/dist/dispatcher.d.ts +0 -9
  619. package/dist/dispatcher.d.ts.map +0 -1
  620. package/dist/dispatcher.js +0 -9
  621. package/dist/dispatcher.js.map +0 -1
  622. package/dist/drive.d.ts.map +0 -1
  623. package/dist/drive.js.map +0 -1
  624. package/dist/http-server.d.ts.map +0 -1
  625. package/dist/http-server.js.map +0 -1
  626. package/dist/intent.d.ts.map +0 -1
  627. package/dist/intent.js.map +0 -1
  628. package/dist/logger.d.ts.map +0 -1
  629. package/dist/logger.js.map +0 -1
  630. package/dist/markdown.d.ts +0 -26
  631. package/dist/markdown.d.ts.map +0 -1
  632. package/dist/markdown.js.map +0 -1
  633. package/dist/memory.d.ts +0 -9
  634. package/dist/memory.d.ts.map +0 -1
  635. package/dist/memory.js +0 -9
  636. package/dist/memory.js.map +0 -1
  637. package/dist/openai.d.ts +0 -13
  638. package/dist/openai.d.ts.map +0 -1
  639. package/dist/openai.js +0 -17
  640. package/dist/openai.js.map +0 -1
  641. package/dist/response-builders.d.ts.map +0 -1
  642. package/dist/response-builders.js.map +0 -1
  643. package/dist/scheduler.d.ts.map +0 -1
  644. package/dist/scheduler.js.map +0 -1
  645. package/dist/sessions.d.ts.map +0 -1
  646. package/dist/sessions.js.map +0 -1
  647. package/dist/stdio-server.d.ts.map +0 -1
  648. package/dist/stdio-server.js.map +0 -1
  649. package/dist/telegram.d.ts.map +0 -1
  650. package/dist/telegram.js.map +0 -1
  651. package/dist/tool-definitions.d.ts +0 -2
  652. package/dist/tool-definitions.d.ts.map +0 -1
  653. package/dist/tool-definitions.js +0 -2
  654. package/dist/tool-definitions.js.map +0 -1
  655. package/dist/types.d.ts.map +0 -1
  656. package/dist/types.js.map +0 -1
  657. package/dist/utils.d.ts.map +0 -1
  658. package/dist/utils.js.map +0 -1
  659. /package/dist/{logger.d.ts → lib/logger.d.ts} +0 -0
  660. /package/dist/{types.js → lib/types.js} +0 -0
  661. /package/dist/{utils.d.ts → lib/utils.d.ts} +0 -0
  662. /package/dist/{drive.d.ts → services/drive.d.ts} +0 -0
  663. /package/dist/{intent.d.ts → services/intent.d.ts} +0 -0
  664. /package/dist/{chat-ui/src → tools/defs}/types.js +0 -0
@@ -1,154 +1,24 @@
1
1
  import { getUnconsolidatedEpisodes, markConsolidated } from "../data/memory/episodes.js";
2
- import { saveSemanticNote, searchByEmbedding, saveNoteEmbedding, supersedeNote, updateSemanticNote, rebuildTopicIndex, } from "../data/memory/semantic.js";
3
- import { cleanupConsolidationHousekeeping, getCandidateNotesForPruning, getUnconsolidatedThreadIds, getActiveNoteContent, hasActiveNote, expireNote, logConsolidation, mergeDuplicateNote, sweepOrphanedNotes, sweepOrphanedEmbeddings, } from "../data/memory/consolidation.js";
4
- import { passesStructuralGate, passesQualityGate, parseReflectionFields } from "../data/memory/reflection.js";
2
+ import { saveSemanticNote, supersedeNote, updateSemanticNote, } from "../data/memory/semantic-notes.js";
3
+ import { searchByEmbedding, saveNoteEmbedding } from "../data/memory/note-embeddings.js";
4
+ import { cleanupConsolidationHousekeeping, getUnconsolidatedThreadIds, hasActiveNote, expireNote, logConsolidation, sweepOrphanedNotes, sweepOrphanedEmbeddings, } from "../data/memory/consolidation.js";
5
+ import { passesStructuralGate, passesQualityGate, parseReflectionFields, } from "../data/memory/reflection-gates.js";
6
+ import { buildExtractionPrompt, buildSupersedePrompt, buildLinkingPrompt, } from "./consolidation-prompts.js";
7
+ import { runMemoryPruning } from "./memory-pruning.service.js";
5
8
  import { getThread } from "../data/memory/thread-registry.js";
6
- import { chatCompletion, generateEmbedding } from "../integrations/openai/chat.js";
7
- import { log } from "../logger.js";
8
- import { nowISO, repairAndParseJSON } from "../data/memory/utils.js";
9
- import { errorMessage } from "../utils.js";
9
+ import { generateEmbedding } from "../integrations/openai/chat.js";
10
+ import { chatCompletionJson } from "../llm/json.js";
11
+ import { log } from "../lib/logger.js";
12
+ import { nowISO } from "../data/memory/utils.js";
13
+ import { errorMessage } from "../lib/utils.js";
10
14
  const CONSOLIDATION_DEDUP_THRESHOLD = 0.88;
11
15
  /** Higher similarity floor required before an obsolescence (non-contradiction) supersede is honored. */
12
- const OBSOLESCENCE_SIM_THRESHOLD = 0.60;
16
+ const OBSOLESCENCE_SIM_THRESHOLD = 0.6;
13
17
  const VALID_NOTE_TYPES = ["fact", "preference", "pattern", "entity", "relationship"];
14
18
  let consolidationInProgress = false;
15
- function extractEpisodeText(episodes) {
16
- return episodes
17
- .map((episode, index) => {
18
- const contentRecord = episode.content;
19
- let content;
20
- if (contentRecord && typeof contentRecord === "object") {
21
- content = contentRecord.text ?? contentRecord.caption ?? JSON.stringify(contentRecord);
22
- }
23
- else {
24
- content = JSON.stringify(episode.content);
25
- }
26
- return `[${index + 1}] (${episode.type}/${episode.modality}, ${episode.timestamp}) ${content}`;
27
- })
28
- .join("\n");
29
- }
30
- function buildExtractionPrompt(episodes) {
31
- const episodesText = extractEpisodeText(episodes);
32
- return `You are a memory consolidation agent. Extract ONLY actionable, durable knowledge from these episodes. Quality over quantity — fewer, better notes.
33
-
34
- Episodes:
35
- ${episodesText}
36
-
37
- Output a JSON object with:
38
- {
39
- "notes": [
40
- {
41
- "type": "fact" | "preference" | "pattern" | "entity",
42
- "content": "One clear, actionable sentence",
43
- "keywords": ["keyword1", "keyword2", "keyword3"],
44
- "confidence": 0.0-1.0,
45
- "priority": 0 | 1 | 2,
46
- "quality_score": 1-5
47
- }
48
- ]
49
- }
50
-
51
- ACTIONABILITY TEST — apply to every note before including it:
52
- - Facts must answer: "What should the agent DO with this information?" If a fact is just "X was discussed" or "Y happened" with no implication for future behavior, do NOT extract it.
53
- - Preferences must be testable: "Given situation X, the operator wants Y." Vague preferences like "prefers quality" are useless — specify the concrete behavior.
54
- - If a note doesn't change how the agent acts in a future session, it's not worth saving. Prefer zero notes over low-quality notes.
55
-
56
- BANNED content — do NOT extract:
57
- - Notes about the memory system, consolidation, audits, reflection quality, or memory management
58
- - Self-assessments or meta-observations about the agent's own behavior ("I tend to...", "I regularly...")
59
- - Passive observations that don't inform decisions ("a discussion occurred", "code was reviewed")
60
- - Transient status ("currently working on X", "PR is open", "tests passing")
61
- - Point-in-time state / counters / metrics: "audio ingested with 789 transcriptions", "monthly cost ~$33", "42 files processed", any note whose value is a snapshot number that will be different next week. If the number is a live counter or balance rather than a fixed decision/threshold, do NOT extract it.
62
- - Future-tense plans / intentions: "will implement", "plans to", "going to", "intends to", "is about to". Plans belong in tasks, not durable memory. Only extract an action after it happened and had an outcome.
63
- - Reconstructable git history: commit hashes, "commit df10c39 added…", "the fix was implemented in <sha>", "PR #123 merged". Git log/blame is authoritative — never store what a commit hash would tell you. Store the durable decision or constraint, not the commit event.
64
-
65
- EXCEPTION: If the operator explicitly corrected the agent's behavior, extract that correction as a preference.
66
-
67
- TYPE RULES:
68
- - fact: Durable knowledge about the project, codebase, architecture, people, or external world
69
- - preference: Operator's explicit or strongly implied preference for how things should be done
70
- - pattern: Recurring behavior or decision pattern that predicts future situations
71
- - entity: Named entity (person, project, service) with identifying attributes
72
-
73
- PRIORITY DETECTION:
74
- - priority 2: operator says "important", "crucial", "don't forget", shows strong emotional investment
75
- - priority 1: operator says "would be nice", "should", mentions something repeatedly
76
- - priority 0: default for routine facts
77
-
78
- QUALITY SCORE (quality_score):
79
- - 1: Vague or useless — generic statement with no actionable implication
80
- - 2: Weak — some value but missing context or specificity
81
- - 3: Acceptable — actionable but not particularly memorable
82
- - 4: Good — specific, actionable, with context or motivation
83
- - 5: Highly actionable — captures a decision, constraint, or pattern with full context and clear behavioral implication
84
- Assign honestly. A score below 3 flags the note for monitoring — do NOT use this to suppress extraction; assign a low score and let the system decide.
85
-
86
- CONTENT QUALITY:
87
- - Name specific components, features, versions, or decisions — never "a bug fix was completed"
88
- - Capture WHY (motivation/context), not just WHAT. Include outcome if known
89
- - If neither WHY nor outcome is available, the note is probably not worth extracting
90
- - Include dates when they pin a decision (e.g. "On April 15 the operator chose X"). Dates that anchor a durable decision stay; dates that merely log that an event happened do not.
91
- - Return {"notes": []} if nothing actionable
92
-
93
- SPECIFICITY GATE — apply to every note before including it:
94
- - Every note MUST contain at least one specific anchor: a file name, component, person name, config key, or fixed threshold value. A commit hash does NOT count as specificity. If you cannot name something specific, do not create the note.
95
- - Do NOT create notes that merely say "X was completed" or "Y was done." If something was completed, state WHAT specifically was done — which files changed, what bug was fixed, what the outcome was. Headlines without substance are useless.`;
96
- }
97
- function buildSupersedePrompt(batch) {
98
- const notesSection = batch
99
- .map((item) => `[${item.noteIndex}] New: "${item.content}"\n` +
100
- (item.candidates.length > 0
101
- ? ` Candidates:\n${item.candidates.map((c) => ` [${c.noteId}] (${c.type}, conf: ${c.confidence}) ${c.content}`).join("\n")}`
102
- : ` Candidates: none`))
103
- .join("\n\n");
104
- return `You are a memory-freshness detector. For each new note, decide whether it makes any of its candidate existing notes stale.
105
-
106
- ${notesSection}
107
-
108
- Output a JSON object:
109
- {
110
- "results": [
111
- { "noteIndex": 0, "verdict": "contradict", "targetNoteId": "sn_xxx", "reason": "Why the candidate is now outdated" },
112
- { "noteIndex": 1, "verdict": "obsolete", "targetNoteId": "sn_yyy", "reason": "Same subject, but the new note reflects a later reality" },
113
- { "noteIndex": 2, "verdict": "keep" }
114
- ]
115
- }
116
-
117
- Verdicts (choose exactly one per note index):
118
- - "contradict": the new note explicitly contradicts, updates, or replaces a candidate (e.g., newer value, completed/abandoned project, changed preference, updated version). The new note is MORE RECENT than the candidate.
119
- - "obsolete": the new note does not directly contradict a candidate, but makes it OUTDATED — same subject, and the new note reflects a later reality that supersedes the candidate's still-true-sounding claim.
120
- - "keep": the new note adds different information without invalidating any candidate, OR no candidates are listed.
121
-
122
- Rules:
123
- - Output exactly one result per note index, in ascending order.
124
- - For "contradict" and "obsolete" you MUST include targetNoteId and reason.
125
- - Only one candidate can be targeted per new note (the most directly affected one).
126
- - When unsure, prefer "keep".`;
127
- }
128
- function buildLinkingPrompt(newNote, neighbors) {
129
- const neighborsSection = neighbors.map((n) => `[${n.noteId}] (${n.type}) ${n.content}`).join("\n");
130
- return `You are a causal link detector for a memory system. Determine if any of these existing notes are causally related to the new note.
131
-
132
- New note: "${newNote.content}"
133
-
134
- Existing notes to compare:
135
- ${neighborsSection}
136
-
137
- Output a JSON object:
138
- {
139
- "links": [
140
- { "noteId": "sn_xxx", "reason": "Brief causal relationship — one caused the other, or they are part of the same chain" }
141
- ]
142
- }
143
-
144
- Rules:
145
- - Only include notes where there is a CLEAR causal or sequential relationship (one caused the other, one is a consequence of the other, or they are part of the same decision chain)
146
- - Do NOT link notes that are merely on the same topic or share keywords — the relationship must be directional and causal
147
- - If no causal relationships exist, output { "links": [] }`;
148
- }
149
19
  async function checkConsolidationDuplicate(db, content, apiKey, threadId) {
150
20
  try {
151
- const embedding = await generateEmbedding(content, apiKey);
21
+ const embedding = await generateEmbedding(content, apiKey, threadId);
152
22
  const matches = searchByEmbedding(db, embedding, {
153
23
  maxResults: 1,
154
24
  minSimilarity: CONSOLIDATION_DEDUP_THRESHOLD,
@@ -226,13 +96,6 @@ export async function runConsolidationAllThreads(db, options) {
226
96
  catch (err) {
227
97
  log.warn(`[memory] Orphan embeddings sweep failed: ${errorMessage(err)}`);
228
98
  }
229
- try {
230
- const topicCount = rebuildTopicIndex(db);
231
- allDetails.push(`Topic index rebuilt: ${topicCount} topics`);
232
- }
233
- catch (err) {
234
- log.warn(`[memory] Topic index rebuild failed: ${errorMessage(err)}`);
235
- }
236
99
  return {
237
100
  episodesProcessed: totalProcessed,
238
101
  notesCreated: totalNotes,
@@ -257,7 +120,12 @@ export async function runIntelligentConsolidation(db, threadId, options) {
257
120
  const threadEntry = getThread(db, threadId);
258
121
  if (threadEntry?.type === "worker") {
259
122
  log.info(`[consolidation] Skipping — thread ${threadId} is a worker thread`);
260
- return { episodesProcessed: 0, notesCreated: 0, durationMs: 0, details: ["Skipped — worker thread."] };
123
+ return {
124
+ episodesProcessed: 0,
125
+ notesCreated: 0,
126
+ durationMs: 0,
127
+ details: ["Skipped — worker thread."],
128
+ };
261
129
  }
262
130
  const skipLock = options?._skipLock ?? false;
263
131
  if (!skipLock && consolidationInProgress) {
@@ -277,12 +145,25 @@ export async function runIntelligentConsolidation(db, threadId, options) {
277
145
  const dryRun = options?.dryRun ?? false;
278
146
  // Recency-aware (obsolescence) supersede gate. Contradiction supersede is unaffected by this flag.
279
147
  // off — obsolescence verdicts ignored entirely (legacy behavior).
280
- // shadow — evaluate + log what WOULD be superseded, but do NOT mutate (default).
281
- // active — actually supersede obsolete notes via the soft supersedeNote path.
282
- const supersedeObsolescenceRaw = (process.env.SUPERSEDE_OBSOLESCENCE ?? "shadow").toLowerCase();
283
- const supersedeObsolescenceMode = supersedeObsolescenceRaw === "off" ? "off"
284
- : supersedeObsolescenceRaw === "active" ? "active"
285
- : "shadow";
148
+ // shadow — evaluate + log what WOULD be superseded, but do NOT mutate.
149
+ // active — actually supersede obsolete notes via the soft supersedeNote path (default).
150
+ // The two-key gate below (similarity floor AND facts-only) plus the guardrail/pinned
151
+ // exclusion is what keeps "active" safe; an unrecognized value falls back to the
152
+ // non-mutating "shadow" rather than silently writing on a typo'd config.
153
+ const supersedeObsolescenceRaw = process.env.SUPERSEDE_OBSOLESCENCE?.trim().toLowerCase();
154
+ let supersedeObsolescenceMode;
155
+ if (!supersedeObsolescenceRaw) {
156
+ supersedeObsolescenceMode = "active";
157
+ }
158
+ else if (supersedeObsolescenceRaw === "off" ||
159
+ supersedeObsolescenceRaw === "shadow" ||
160
+ supersedeObsolescenceRaw === "active") {
161
+ supersedeObsolescenceMode = supersedeObsolescenceRaw;
162
+ }
163
+ else {
164
+ log.warn(`[consolidation] Unrecognized SUPERSEDE_OBSOLESCENCE="${supersedeObsolescenceRaw}" — falling back to shadow (no mutation)`);
165
+ supersedeObsolescenceMode = "shadow";
166
+ }
286
167
  const episodes = getUnconsolidatedEpisodes(db, threadId, maxEpisodes);
287
168
  if (episodes.length === 0) {
288
169
  return {
@@ -304,23 +185,30 @@ export async function runIntelligentConsolidation(db, threadId, options) {
304
185
  { role: "system", content: buildExtractionPrompt(episodes) },
305
186
  { role: "user", content: "Extract knowledge from the episodes above." },
306
187
  ];
307
- const extractRaw = await chatCompletion(extractMessages, apiKey, {
188
+ const extractParsed = (await chatCompletionJson(extractMessages, apiKey, {
308
189
  model: process.env.CONSOLIDATION_MODEL ?? "gpt-4o",
190
+ category: "consolidation",
191
+ threadId,
309
192
  maxTokens: 4096,
310
193
  responseFormat: { type: "json_object" },
311
194
  timeoutMs: 60_000,
312
- });
313
- const extractParsed = repairAndParseJSON(extractRaw);
195
+ }));
314
196
  const extractedNotes = extractParsed.notes ?? [];
315
197
  const episodeIds = episodes.map((episode) => episode.episodeId);
316
198
  if (!dryRun) {
317
199
  const noteWrites = [];
318
200
  for (const note of extractedNotes) {
319
- if (typeof note.content !== "string" || note.content.length === 0 || note.content.length >= 2000) {
201
+ if (typeof note.content !== "string" ||
202
+ note.content.length === 0 ||
203
+ note.content.length >= 2000) {
320
204
  log.warn(`[consolidation] Skipping note with invalid content (type=${typeof note.content}, len=${typeof note.content === "string" ? note.content.length : "N/A"})`);
321
205
  continue;
322
206
  }
323
- const noteType = (VALID_NOTE_TYPES.includes(note.type) ? note.type : "fact");
207
+ const typeDeclared = VALID_NOTE_TYPES.includes(note.type);
208
+ const noteType = (typeDeclared ? note.type : "fact");
209
+ if (!typeDeclared) {
210
+ log.warn(`[consolidation] Extracted note has unrecognized type "${note.type}" — saving as "fact", not eligible for obsolescence supersede`);
211
+ }
324
212
  const dedup = await checkConsolidationDuplicate(db, note.content, apiKey, knowledgeThreadId);
325
213
  if (dedup.isDuplicate) {
326
214
  log.debug(`[consolidation] Dedup: skipping note similar to ${dedup.matchId} at ${dedup.similarity?.toFixed(3)}`);
@@ -334,6 +222,7 @@ export async function runIntelligentConsolidation(db, threadId, options) {
334
222
  priority: Math.max(0, Math.min(2, note.priority ?? 0)),
335
223
  qualityScore: typeof note.quality_score === "number" ? note.quality_score : null,
336
224
  embedding: dedup.embedding,
225
+ typeDeclared,
337
226
  });
338
227
  }
339
228
  // ── Step 2: Supersede check (batched LLM calls) ───────────────────
@@ -363,20 +252,23 @@ export async function runIntelligentConsolidation(db, threadId, options) {
363
252
  })),
364
253
  }));
365
254
  try {
366
- const supersedeRaw = await chatCompletion([
255
+ const supersedeParsed = (await chatCompletionJson([
367
256
  { role: "system", content: buildSupersedePrompt(batch) },
368
257
  { role: "user", content: "Check for contradictions." },
369
258
  ], apiKey, {
370
259
  model: process.env.CONSOLIDATION_MODEL ?? "gpt-4o",
260
+ category: "consolidation",
261
+ threadId,
371
262
  maxTokens: 1024,
372
263
  responseFormat: { type: "json_object" },
373
264
  timeoutMs: 30_000,
374
- });
375
- const supersedeParsed = repairAndParseJSON(supersedeRaw);
265
+ }));
376
266
  for (const result of supersedeParsed.results ?? []) {
377
267
  // Back-compat: a legacy {supersede:true} is a contradiction verdict.
378
268
  const verdict = result.verdict ?? (result.supersede ? "contradict" : "keep");
379
- if ((verdict !== "contradict" && verdict !== "obsolete") || !result.targetNoteId || typeof result.noteIndex !== "number") {
269
+ if ((verdict !== "contradict" && verdict !== "obsolete") ||
270
+ !result.targetNoteId ||
271
+ typeof result.noteIndex !== "number") {
380
272
  continue;
381
273
  }
382
274
  const item = chunk[result.noteIndex];
@@ -402,15 +294,27 @@ export async function runIntelligentConsolidation(db, threadId, options) {
402
294
  log.debug(`[consolidation] Obsolescence rejected: sim ${candidate.similarity.toFixed(3)} < ${OBSOLESCENCE_SIM_THRESHOLD}`);
403
295
  continue;
404
296
  }
405
- if (item.nw.type !== "fact" || candidate.type !== "fact") {
406
- log.debug(`[consolidation] Obsolescence rejected: non-fact (new=${item.nw.type}, candidate=${candidate.type})`);
297
+ // Facts-only, and only when the extractor *declared* the type — a
298
+ // coerced "fact" is an unknown, not a fact.
299
+ if (!item.nw.typeDeclared || item.nw.type !== "fact" || candidate.type !== "fact") {
300
+ log.debug(`[consolidation] Obsolescence rejected: non-fact (new=${item.nw.type}${item.nw.typeDeclared ? "" : " [coerced]"}, candidate=${candidate.type})`);
407
301
  continue;
408
302
  }
409
- item.nw.supersede = { targetNoteId: candidate.noteId, reason: result.reason ?? "", verdict: "obsolete", similarity: candidate.similarity };
303
+ item.nw.supersede = {
304
+ targetNoteId: candidate.noteId,
305
+ reason: result.reason ?? "",
306
+ verdict: "obsolete",
307
+ similarity: candidate.similarity,
308
+ };
410
309
  }
411
310
  else {
412
311
  // Contradiction path — unchanged behavior for any non-guardrail/pinned candidate.
413
- item.nw.supersede = { targetNoteId: candidate.noteId, reason: result.reason ?? "", verdict: "contradict", similarity: candidate.similarity };
312
+ item.nw.supersede = {
313
+ targetNoteId: candidate.noteId,
314
+ reason: result.reason ?? "",
315
+ verdict: "contradict",
316
+ similarity: candidate.similarity,
317
+ };
414
318
  }
415
319
  }
416
320
  }
@@ -421,6 +325,7 @@ export async function runIntelligentConsolidation(db, threadId, options) {
421
325
  // ── Transaction: all DB writes ────────────────────────────────────
422
326
  const savedNotes = [];
423
327
  let supersededCount = 0;
328
+ let obsoleteSupersededCount = 0;
424
329
  db.transaction(() => {
425
330
  for (const { nw } of notesWithCandidates) {
426
331
  let noteId;
@@ -438,7 +343,14 @@ export async function runIntelligentConsolidation(db, threadId, options) {
438
343
  sourceEpisodes: episodeIds,
439
344
  });
440
345
  supersededCount++;
441
- details.push(`[supersede:${sup.verdict}] ${sup.targetNoteId} → ${noteId}: ${sup.reason}`);
346
+ if (sup.verdict === "obsolete")
347
+ obsoleteSupersededCount++;
348
+ const supersedeMsg = `[supersede:${sup.verdict}] ${sup.targetNoteId} → ${noteId} (sim=${sup.similarity.toFixed(3)}, reason=${sup.reason})`;
349
+ // Log the pair, not just the count: this is the only durable record of
350
+ // which note expired and what replaced it. Shadow mode logs its proposed
351
+ // pairs, so the mutating path must not log less than the dry one.
352
+ log.info(`[memory] ${supersedeMsg}`);
353
+ details.push(supersedeMsg);
442
354
  }
443
355
  else {
444
356
  noteId = saveSemanticNote(db, {
@@ -474,7 +386,10 @@ export async function runIntelligentConsolidation(db, threadId, options) {
474
386
  });
475
387
  })();
476
388
  if (supersededCount > 0) {
477
- log.info(`[memory] Contradiction resolution: superseded ${supersededCount} outdated note(s)`);
389
+ // Obsolescence supersedes are counted separately: they are the ones the
390
+ // SUPERSEDE_OBSOLESCENCE flag turned on, and the ones to look at first if
391
+ // memory goes missing.
392
+ log.info(`[memory] Superseded ${supersededCount} outdated note(s) — ${supersededCount - obsoleteSupersededCount} contradiction, ${obsoleteSupersededCount} obsolescence`);
478
393
  }
479
394
  // ── Step 3: Linking enrichment (post-save, optional) ──────────────
480
395
  for (const saved of savedNotes) {
@@ -486,10 +401,12 @@ export async function runIntelligentConsolidation(db, threadId, options) {
486
401
  minSimilarity: 0.4,
487
402
  skipAccessTracking: true,
488
403
  threadId: knowledgeThreadId,
489
- }).filter((n) => n.noteId !== saved.noteId).slice(0, 5);
404
+ })
405
+ .filter((n) => n.noteId !== saved.noteId)
406
+ .slice(0, 5);
490
407
  if (neighbors.length === 0)
491
408
  continue;
492
- const linkRaw = await chatCompletion([
409
+ const linkParsed = (await chatCompletionJson([
493
410
  {
494
411
  role: "system",
495
412
  content: buildLinkingPrompt({ noteId: saved.noteId, content: saved.content }, neighbors.map((n) => ({ noteId: n.noteId, type: n.type, content: n.content }))),
@@ -497,13 +414,16 @@ export async function runIntelligentConsolidation(db, threadId, options) {
497
414
  { role: "user", content: "Identify causal links." },
498
415
  ], apiKey, {
499
416
  model: process.env.CONSOLIDATION_MODEL ?? "gpt-4o",
417
+ category: "consolidation",
418
+ threadId,
500
419
  maxTokens: 512,
501
420
  responseFormat: { type: "json_object" },
502
421
  timeoutMs: 20_000,
503
- });
504
- const linkParsed = repairAndParseJSON(linkRaw);
422
+ }));
505
423
  const neighborIds = new Set(neighbors.map((n) => n.noteId));
506
- const links = (linkParsed.links ?? []).filter((l) => typeof l.noteId === "string" && typeof l.reason === "string" && neighborIds.has(l.noteId));
424
+ const links = (linkParsed.links ?? []).filter((l) => typeof l.noteId === "string" &&
425
+ typeof l.reason === "string" &&
426
+ neighborIds.has(l.noteId));
507
427
  if (links.length > 0) {
508
428
  const linkedNotes = links.map((l) => l.noteId);
509
429
  const linkReasons = {};
@@ -552,13 +472,13 @@ export async function runIntelligentConsolidation(db, threadId, options) {
552
472
  // expiring historical notes is a separate, backed-up cleanup step, not this sweep.
553
473
  const structural = passesStructuralGate(fields, { requireAnchor: false });
554
474
  if (!structural.pass) {
555
- expireNote(db, row.note_id, nowStr);
475
+ expireNote(db, row.note_id, nowStr, "quality-gate");
556
476
  expiredReflections++;
557
477
  continue;
558
478
  }
559
479
  const quality = passesQualityGate(row.content, row.confidence);
560
480
  if (!quality.pass) {
561
- expireNote(db, row.note_id, nowStr);
481
+ expireNote(db, row.note_id, nowStr, "quality-gate");
562
482
  expiredReflections++;
563
483
  }
564
484
  }
@@ -570,17 +490,6 @@ export async function runIntelligentConsolidation(db, threadId, options) {
570
490
  log.warn(`[consolidation] Reflection quality gate cleanup failed: ${errorMessage(err)}`);
571
491
  }
572
492
  }
573
- // Keep meta_topic_index accurate on the hot path (drive-handler / daily-session).
574
- // Skipped when running inside runConsolidationAllThreads (_skipLock), which rebuilds
575
- // once after its pruning/sweep phase to avoid N redundant per-thread rebuilds.
576
- if (!skipLock && !dryRun) {
577
- try {
578
- rebuildTopicIndex(db);
579
- }
580
- catch (err) {
581
- log.warn(`[memory] Topic index rebuild failed: ${errorMessage(err)}`);
582
- }
583
- }
584
493
  return {
585
494
  episodesProcessed: episodes.length,
586
495
  notesCreated,
@@ -593,166 +502,4 @@ export async function runIntelligentConsolidation(db, threadId, options) {
593
502
  consolidationInProgress = false;
594
503
  }
595
504
  }
596
- export async function runMemoryPruning(db, options) {
597
- const pruningEnabled = process.env.PRUNING_ENABLED;
598
- if (pruningEnabled === "false" || pruningEnabled === "0") {
599
- return {
600
- notesScanned: 0,
601
- notesExpired: 0,
602
- notesMerged: 0,
603
- durationMs: 0,
604
- details: ["Pruning disabled via PRUNING_ENABLED env var."],
605
- };
606
- }
607
- const apiKey = process.env.OPENAI_API_KEY;
608
- if (!apiKey) {
609
- return {
610
- notesScanned: 0,
611
- notesExpired: 0,
612
- notesMerged: 0,
613
- durationMs: 0,
614
- details: ["Pruning skipped — OPENAI_API_KEY not set."],
615
- };
616
- }
617
- const startMs = Date.now();
618
- const envSampleSize = parseInt(process.env.PRUNING_SAMPLE_SIZE ?? "", 10);
619
- const maxNotes = options?.maxNotes ?? (Number.isFinite(envSampleSize) && envSampleSize > 0 ? envSampleSize : 60);
620
- const dryRun = options?.dryRun ?? false;
621
- const details = [];
622
- const candidates = getCandidateNotesForPruning(db, maxNotes);
623
- if (candidates.length < 5) {
624
- return {
625
- notesScanned: 0,
626
- notesExpired: 0,
627
- notesMerged: 0,
628
- durationMs: Date.now() - startMs,
629
- details: ["Too few candidate notes for pruning (< 5)."],
630
- };
631
- }
632
- const now = new Date();
633
- const notesText = candidates
634
- .map((row) => {
635
- const ageMs = now.getTime() - new Date(row.created_at).getTime();
636
- const ageDays = Math.round(ageMs / (1000 * 60 * 60 * 24));
637
- return `[${row.note_id}] (${row.type}, conf: ${row.confidence}, accesses: ${row.access_count}, age: ${ageDays}d) ${row.content}`;
638
- })
639
- .join("\n");
640
- const systemPrompt = `You are a memory quality manager. Review these semantic notes and identify problems.
641
-
642
- Notes to review:
643
- ${notesText}
644
-
645
- Output a JSON object:
646
- {
647
- "expire": [
648
- { "noteId": "sn_xxx", "reason": "Brief explanation" }
649
- ],
650
- "merge": [
651
- { "keepId": "sn_xxx", "expireId": "sn_yyy", "mergedContent": "Best combined version", "reason": "Brief explanation" }
652
- ]
653
- }
654
-
655
- Decision criteria:
656
- - EXPIRE if: the note is vague/non-actionable ("the system has issues"), trivially obvious, or clearly outdated (references old versions, completed tasks still marked pending)
657
- - MERGE if: two or more notes convey the same information — keep the more specific/accurate one. Provide mergedContent combining the best of both when useful.
658
- - KEEP (omit from output) if: the note contains unique, specific, actionable information
659
-
660
- Be conservative — when in doubt, keep the note. Only expire notes you are confident are low-value.
661
- Do NOT expire preferences or guardrails unless they clearly contradict each other.
662
- Return {"expire": [], "merge": []} if nothing needs pruning.`;
663
- try {
664
- const messages = [
665
- { role: "system", content: systemPrompt },
666
- { role: "user", content: "Review the notes above and identify any that should be expired or merged." },
667
- ];
668
- const raw = await chatCompletion(messages, apiKey, {
669
- model: process.env.CONSOLIDATION_MODEL ?? "gpt-4o",
670
- maxTokens: 4096,
671
- responseFormat: { type: "json_object" },
672
- timeoutMs: 60_000,
673
- });
674
- const parsed = repairAndParseJSON(raw);
675
- if (parsed == null || typeof parsed !== "object" || Array.isArray(parsed)) {
676
- throw new Error(`LLM returned non-object response: ${typeof parsed}`);
677
- }
678
- const result = parsed;
679
- const expireActions = (Array.isArray(result.expire) ? result.expire : []);
680
- const mergeActions = (Array.isArray(result.merge) ? result.merge : []);
681
- const candidateIds = new Set(candidates.map((candidate) => candidate.note_id));
682
- let expired = 0;
683
- let merged = 0;
684
- const nowStr = nowISO();
685
- if (!dryRun) {
686
- db.transaction(() => {
687
- for (const action of expireActions) {
688
- if (!action.noteId)
689
- continue;
690
- if (!candidateIds.has(action.noteId)) {
691
- details.push(`[skip-expire] ${action.noteId} not in candidate set`);
692
- continue;
693
- }
694
- if (!hasActiveNote(db, action.noteId)) {
695
- details.push(`[skip-expire] ${action.noteId} not found or already expired`);
696
- continue;
697
- }
698
- expireNote(db, action.noteId, nowStr);
699
- expired++;
700
- details.push(`[pruned] ${action.noteId}: ${action.reason}`);
701
- }
702
- for (const action of mergeActions) {
703
- if (!action.keepId || !action.expireId)
704
- continue;
705
- if (action.keepId === action.expireId) {
706
- details.push(`[skip-merge] ${action.keepId}: keepId === expireId`);
707
- continue;
708
- }
709
- if (!candidateIds.has(action.keepId) || !candidateIds.has(action.expireId)) {
710
- details.push(`[skip-merge] ${action.keepId}/${action.expireId} not in candidate set`);
711
- continue;
712
- }
713
- const keepNote = getActiveNoteContent(db, action.keepId);
714
- const expireNoteRow = getActiveNoteContent(db, action.expireId);
715
- if (!keepNote || !expireNoteRow) {
716
- details.push(`[skip-merge] ${action.keepId}/${action.expireId} not found`);
717
- continue;
718
- }
719
- mergeDuplicateNote(db, keepNote.noteId, expireNoteRow.noteId, nowStr, action.mergedContent && action.mergedContent !== keepNote.content ? action.mergedContent : undefined);
720
- merged++;
721
- details.push(`[merged] ${action.expireId} → ${action.keepId}: ${action.reason}`);
722
- }
723
- })();
724
- }
725
- else {
726
- for (const action of expireActions) {
727
- details.push(`[dry-run] [prune] ${action.noteId}: ${action.reason}`);
728
- expired++;
729
- }
730
- for (const action of mergeActions) {
731
- details.push(`[dry-run] [merge] ${action.expireId} → ${action.keepId}: ${action.reason}`);
732
- merged++;
733
- }
734
- }
735
- if (expired + merged > 0) {
736
- log.info(`[memory] Pruning: expired ${expired}, merged ${merged} note(s)`);
737
- }
738
- return {
739
- notesScanned: candidates.length,
740
- notesExpired: expired,
741
- notesMerged: merged,
742
- durationMs: Date.now() - startMs,
743
- details,
744
- };
745
- }
746
- catch (err) {
747
- const msg = errorMessage(err);
748
- log.error(`[memory] Pruning failed: ${msg}`);
749
- return {
750
- notesScanned: candidates.length,
751
- notesExpired: 0,
752
- notesMerged: 0,
753
- durationMs: Date.now() - startMs,
754
- details: [`Pruning failed: ${msg}`],
755
- };
756
- }
757
- }
758
505
  //# sourceMappingURL=consolidation.service.js.map