nlm-memory 0.4.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 (472) hide show
  1. package/.agents/plugins/marketplace.json +20 -0
  2. package/.github/workflows/ci.yml +30 -0
  3. package/LICENSE +151 -0
  4. package/README.md +119 -0
  5. package/dist/cli/classify-parity.d.ts +48 -0
  6. package/dist/cli/classify-parity.js +182 -0
  7. package/dist/cli/classify-parity.js.map +1 -0
  8. package/dist/cli/launchctl-helpers.d.ts +26 -0
  9. package/dist/cli/launchctl-helpers.js +42 -0
  10. package/dist/cli/launchctl-helpers.js.map +1 -0
  11. package/dist/cli/nlm.d.ts +25 -0
  12. package/dist/cli/nlm.js +832 -0
  13. package/dist/cli/nlm.js.map +1 -0
  14. package/dist/core/actions/actions-log.d.ts +40 -0
  15. package/dist/core/actions/actions-log.js +72 -0
  16. package/dist/core/actions/actions-log.js.map +1 -0
  17. package/dist/core/actions/overlay.d.ts +30 -0
  18. package/dist/core/actions/overlay.js +101 -0
  19. package/dist/core/actions/overlay.js.map +1 -0
  20. package/dist/core/adapters/aider.d.ts +33 -0
  21. package/dist/core/adapters/aider.js +167 -0
  22. package/dist/core/adapters/aider.js.map +1 -0
  23. package/dist/core/adapters/claude-code.d.ts +32 -0
  24. package/dist/core/adapters/claude-code.js +270 -0
  25. package/dist/core/adapters/claude-code.js.map +1 -0
  26. package/dist/core/adapters/common.d.ts +20 -0
  27. package/dist/core/adapters/common.js +60 -0
  28. package/dist/core/adapters/common.js.map +1 -0
  29. package/dist/core/adapters/from-source.d.ts +11 -0
  30. package/dist/core/adapters/from-source.js +55 -0
  31. package/dist/core/adapters/from-source.js.map +1 -0
  32. package/dist/core/adapters/hermes-agent.d.ts +34 -0
  33. package/dist/core/adapters/hermes-agent.js +192 -0
  34. package/dist/core/adapters/hermes-agent.js.map +1 -0
  35. package/dist/core/adapters/hermes.d.ts +31 -0
  36. package/dist/core/adapters/hermes.js +247 -0
  37. package/dist/core/adapters/hermes.js.map +1 -0
  38. package/dist/core/adapters/jsonl-generic.d.ts +56 -0
  39. package/dist/core/adapters/jsonl-generic.js +185 -0
  40. package/dist/core/adapters/jsonl-generic.js.map +1 -0
  41. package/dist/core/adapters/opencode.d.ts +36 -0
  42. package/dist/core/adapters/opencode.js +213 -0
  43. package/dist/core/adapters/opencode.js.map +1 -0
  44. package/dist/core/adapters/pi.d.ts +32 -0
  45. package/dist/core/adapters/pi.js +233 -0
  46. package/dist/core/adapters/pi.js.map +1 -0
  47. package/dist/core/classifier/prompt.d.ts +60 -0
  48. package/dist/core/classifier/prompt.js +178 -0
  49. package/dist/core/classifier/prompt.js.map +1 -0
  50. package/dist/core/dataset/build-dataset.d.ts +87 -0
  51. package/dist/core/dataset/build-dataset.js +335 -0
  52. package/dist/core/dataset/build-dataset.js.map +1 -0
  53. package/dist/core/embedding/chunk-body.d.ts +30 -0
  54. package/dist/core/embedding/chunk-body.js +60 -0
  55. package/dist/core/embedding/chunk-body.js.map +1 -0
  56. package/dist/core/embedding/embed-backfill.d.ts +36 -0
  57. package/dist/core/embedding/embed-backfill.js +168 -0
  58. package/dist/core/embedding/embed-backfill.js.map +1 -0
  59. package/dist/core/embedding/embed-normalize.d.ts +28 -0
  60. package/dist/core/embedding/embed-normalize.js +98 -0
  61. package/dist/core/embedding/embed-normalize.js.map +1 -0
  62. package/dist/core/facts/backfill-facts.d.ts +58 -0
  63. package/dist/core/facts/backfill-facts.js +169 -0
  64. package/dist/core/facts/backfill-facts.js.map +1 -0
  65. package/dist/core/facts/extract-facts.d.ts +20 -0
  66. package/dist/core/facts/extract-facts.js +37 -0
  67. package/dist/core/facts/extract-facts.js.map +1 -0
  68. package/dist/core/hook/citation-detect.d.ts +32 -0
  69. package/dist/core/hook/citation-detect.js +105 -0
  70. package/dist/core/hook/citation-detect.js.map +1 -0
  71. package/dist/core/hook/cite-memo.d.ts +20 -0
  72. package/dist/core/hook/cite-memo.js +68 -0
  73. package/dist/core/hook/cite-memo.js.map +1 -0
  74. package/dist/core/hook/claude-settings.d.ts +34 -0
  75. package/dist/core/hook/claude-settings.js +117 -0
  76. package/dist/core/hook/claude-settings.js.map +1 -0
  77. package/dist/core/hook/gate.d.ts +11 -0
  78. package/dist/core/hook/gate.js +19 -0
  79. package/dist/core/hook/gate.js.map +1 -0
  80. package/dist/core/hook/hook-log.d.ts +25 -0
  81. package/dist/core/hook/hook-log.js +28 -0
  82. package/dist/core/hook/hook-log.js.map +1 -0
  83. package/dist/core/hook/memo-sweep.d.ts +55 -0
  84. package/dist/core/hook/memo-sweep.js +134 -0
  85. package/dist/core/hook/memo-sweep.js.map +1 -0
  86. package/dist/core/hook/memo.d.ts +20 -0
  87. package/dist/core/hook/memo.js +66 -0
  88. package/dist/core/hook/memo.js.map +1 -0
  89. package/dist/core/hook/pointer-block.d.ts +14 -0
  90. package/dist/core/hook/pointer-block.js +19 -0
  91. package/dist/core/hook/pointer-block.js.map +1 -0
  92. package/dist/core/hook/select.d.ts +21 -0
  93. package/dist/core/hook/select.js +15 -0
  94. package/dist/core/hook/select.js.map +1 -0
  95. package/dist/core/hook/transcript.d.ts +31 -0
  96. package/dist/core/hook/transcript.js +103 -0
  97. package/dist/core/hook/transcript.js.map +1 -0
  98. package/dist/core/ingest/ingest-session.d.ts +40 -0
  99. package/dist/core/ingest/ingest-session.js +71 -0
  100. package/dist/core/ingest/ingest-session.js.map +1 -0
  101. package/dist/core/providers/provider-models.d.ts +24 -0
  102. package/dist/core/providers/provider-models.js +72 -0
  103. package/dist/core/providers/provider-models.js.map +1 -0
  104. package/dist/core/providers/provider-registry.d.ts +62 -0
  105. package/dist/core/providers/provider-registry.js +143 -0
  106. package/dist/core/providers/provider-registry.js.map +1 -0
  107. package/dist/core/recall/citation-log.d.ts +28 -0
  108. package/dist/core/recall/citation-log.js +90 -0
  109. package/dist/core/recall/citation-log.js.map +1 -0
  110. package/dist/core/recall/filter.d.ts +11 -0
  111. package/dist/core/recall/filter.js +20 -0
  112. package/dist/core/recall/filter.js.map +1 -0
  113. package/dist/core/recall/index.d.ts +6 -0
  114. package/dist/core/recall/index.js +5 -0
  115. package/dist/core/recall/index.js.map +1 -0
  116. package/dist/core/recall/match-fields.d.ts +10 -0
  117. package/dist/core/recall/match-fields.js +37 -0
  118. package/dist/core/recall/match-fields.js.map +1 -0
  119. package/dist/core/recall/query-log.d.ts +36 -0
  120. package/dist/core/recall/query-log.js +112 -0
  121. package/dist/core/recall/query-log.js.map +1 -0
  122. package/dist/core/recall/query-shape.d.ts +22 -0
  123. package/dist/core/recall/query-shape.js +64 -0
  124. package/dist/core/recall/query-shape.js.map +1 -0
  125. package/dist/core/recall/recall-service.d.ts +19 -0
  126. package/dist/core/recall/recall-service.js +252 -0
  127. package/dist/core/recall/recall-service.js.map +1 -0
  128. package/dist/core/recall/recent-log.d.ts +16 -0
  129. package/dist/core/recall/recent-log.js +46 -0
  130. package/dist/core/recall/recent-log.js.map +1 -0
  131. package/dist/core/recall/tokenize.d.ts +7 -0
  132. package/dist/core/recall/tokenize.js +18 -0
  133. package/dist/core/recall/tokenize.js.map +1 -0
  134. package/dist/core/recall/useful-scan.d.ts +52 -0
  135. package/dist/core/recall/useful-scan.js +300 -0
  136. package/dist/core/recall/useful-scan.js.map +1 -0
  137. package/dist/core/recall-facts/fact-query-log.d.ts +42 -0
  138. package/dist/core/recall-facts/fact-query-log.js +115 -0
  139. package/dist/core/recall-facts/fact-query-log.js.map +1 -0
  140. package/dist/core/recall-facts/fact-recall-service.d.ts +34 -0
  141. package/dist/core/recall-facts/fact-recall-service.js +246 -0
  142. package/dist/core/recall-facts/fact-recall-service.js.map +1 -0
  143. package/dist/core/scheduler/scan-once.d.ts +32 -0
  144. package/dist/core/scheduler/scan-once.js +100 -0
  145. package/dist/core/scheduler/scan-once.js.map +1 -0
  146. package/dist/core/scheduler/scheduler.d.ts +59 -0
  147. package/dist/core/scheduler/scheduler.js +158 -0
  148. package/dist/core/scheduler/scheduler.js.map +1 -0
  149. package/dist/core/sources/source-registry.d.ts +68 -0
  150. package/dist/core/sources/source-registry.js +208 -0
  151. package/dist/core/sources/source-registry.js.map +1 -0
  152. package/dist/core/storage/db-restore.d.ts +53 -0
  153. package/dist/core/storage/db-restore.js +113 -0
  154. package/dist/core/storage/db-restore.js.map +1 -0
  155. package/dist/core/storage/live-status.d.ts +15 -0
  156. package/dist/core/storage/live-status.js +43 -0
  157. package/dist/core/storage/live-status.js.map +1 -0
  158. package/dist/core/storage/migrate.d.ts +14 -0
  159. package/dist/core/storage/migrate.js +52 -0
  160. package/dist/core/storage/migrate.js.map +1 -0
  161. package/dist/core/storage/sqlite-fact-store.d.ts +50 -0
  162. package/dist/core/storage/sqlite-fact-store.js +256 -0
  163. package/dist/core/storage/sqlite-fact-store.js.map +1 -0
  164. package/dist/core/storage/sqlite-session-store.d.ts +152 -0
  165. package/dist/core/storage/sqlite-session-store.js +587 -0
  166. package/dist/core/storage/sqlite-session-store.js.map +1 -0
  167. package/dist/hook/pre-compact-hook.d.ts +26 -0
  168. package/dist/hook/pre-compact-hook.js +94 -0
  169. package/dist/hook/pre-compact-hook.js.map +1 -0
  170. package/dist/hook/prompt-recall-hook.d.ts +23 -0
  171. package/dist/hook/prompt-recall-hook.js +141 -0
  172. package/dist/hook/prompt-recall-hook.js.map +1 -0
  173. package/dist/hook/session-end-hook.d.ts +18 -0
  174. package/dist/hook/session-end-hook.js +67 -0
  175. package/dist/hook/session-end-hook.js.map +1 -0
  176. package/dist/hook/session-start-hook.d.ts +25 -0
  177. package/dist/hook/session-start-hook.js +129 -0
  178. package/dist/hook/session-start-hook.js.map +1 -0
  179. package/dist/hook/stop-hook.d.ts +38 -0
  180. package/dist/hook/stop-hook.js +171 -0
  181. package/dist/hook/stop-hook.js.map +1 -0
  182. package/dist/hook/subagent-start-hook.d.ts +30 -0
  183. package/dist/hook/subagent-start-hook.js +108 -0
  184. package/dist/hook/subagent-start-hook.js.map +1 -0
  185. package/dist/http/app.d.ts +65 -0
  186. package/dist/http/app.js +1009 -0
  187. package/dist/http/app.js.map +1 -0
  188. package/dist/install/claude-code.d.ts +57 -0
  189. package/dist/install/claude-code.js +76 -0
  190. package/dist/install/claude-code.js.map +1 -0
  191. package/dist/install/codex.d.ts +82 -0
  192. package/dist/install/codex.js +277 -0
  193. package/dist/install/codex.js.map +1 -0
  194. package/dist/install/hermes-agent.d.ts +35 -0
  195. package/dist/install/hermes-agent.js +48 -0
  196. package/dist/install/hermes-agent.js.map +1 -0
  197. package/dist/install/hermes.d.ts +29 -0
  198. package/dist/install/hermes.js +52 -0
  199. package/dist/install/hermes.js.map +1 -0
  200. package/dist/install/ollama.d.ts +54 -0
  201. package/dist/install/ollama.js +178 -0
  202. package/dist/install/ollama.js.map +1 -0
  203. package/dist/install/setup.d.ts +37 -0
  204. package/dist/install/setup.js +339 -0
  205. package/dist/install/setup.js.map +1 -0
  206. package/dist/llm/classifier-box.d.ts +29 -0
  207. package/dist/llm/classifier-box.js +43 -0
  208. package/dist/llm/classifier-box.js.map +1 -0
  209. package/dist/llm/deepseek-client.d.ts +40 -0
  210. package/dist/llm/deepseek-client.js +114 -0
  211. package/dist/llm/deepseek-client.js.map +1 -0
  212. package/dist/llm/env-autoload.d.ts +8 -0
  213. package/dist/llm/env-autoload.js +54 -0
  214. package/dist/llm/env-autoload.js.map +1 -0
  215. package/dist/llm/ollama-client.d.ts +47 -0
  216. package/dist/llm/ollama-client.js +156 -0
  217. package/dist/llm/ollama-client.js.map +1 -0
  218. package/dist/mcp/server.d.ts +64 -0
  219. package/dist/mcp/server.js +430 -0
  220. package/dist/mcp/server.js.map +1 -0
  221. package/dist/ports/fact-store.d.ts +82 -0
  222. package/dist/ports/fact-store.js +16 -0
  223. package/dist/ports/fact-store.js.map +1 -0
  224. package/dist/ports/llm-client.d.ts +42 -0
  225. package/dist/ports/llm-client.js +14 -0
  226. package/dist/ports/llm-client.js.map +1 -0
  227. package/dist/ports/logger.d.ts +13 -0
  228. package/dist/ports/logger.js +8 -0
  229. package/dist/ports/logger.js.map +1 -0
  230. package/dist/ports/session-store.d.ts +29 -0
  231. package/dist/ports/session-store.js +9 -0
  232. package/dist/ports/session-store.js.map +1 -0
  233. package/dist/ports/transcript-adapter.d.ts +48 -0
  234. package/dist/ports/transcript-adapter.js +15 -0
  235. package/dist/ports/transcript-adapter.js.map +1 -0
  236. package/dist/shared/types.d.ts +129 -0
  237. package/dist/shared/types.js +6 -0
  238. package/dist/shared/types.js.map +1 -0
  239. package/dist/ui/assets/index-BA6IpU8g.css +1 -0
  240. package/dist/ui/assets/index-B_qIVV0k.js +69 -0
  241. package/dist/ui/index.html +13 -0
  242. package/docs/methodology/re-derivation-rate.md +112 -0
  243. package/docs/methodology/useful-hit-rate.md +79 -0
  244. package/docs/plans/2026-05-20-fts5-lexical-recall.md +1088 -0
  245. package/docs/plans/2026-05-20-recall-daemon-wedge-fix.md +662 -0
  246. package/docs/plans/2026-05-20-recall-hook-design.md +131 -0
  247. package/docs/plans/2026-05-20-recall-hook-implementation.md +1222 -0
  248. package/docs/plans/desktop-product.md +69 -0
  249. package/docs/plans/factstore-design.md +236 -0
  250. package/logs/CHANGELOG/CHANGELOG-2026.md +1389 -0
  251. package/logs/CHANGELOG/CHANGELOG.md +320 -0
  252. package/migrations/000_initial_schema.sql +174 -0
  253. package/migrations/001_entity_type_rename.sql +17 -0
  254. package/migrations/002_adapter_state_extend.sql +12 -0
  255. package/migrations/003_session_embeddings.sql +11 -0
  256. package/migrations/004_facts.sql +46 -0
  257. package/migrations/005_sources.sql +31 -0
  258. package/migrations/006_providers.sql +33 -0
  259. package/migrations/007_source_tokens.sql +17 -0
  260. package/migrations/008_fts_rebuild.sql +9 -0
  261. package/migrations/009_session_embedding_chunks.sql +46 -0
  262. package/migrations/010_sources_opencode.sql +30 -0
  263. package/migrations/011_sources_hermes_agent.sql +30 -0
  264. package/migrations/012_sources_aider.sql +30 -0
  265. package/migrations/013_adapter_state_failure_count.sql +12 -0
  266. package/package.json +56 -0
  267. package/plugin/.codex-plugin/plugin.json +22 -0
  268. package/plugin/.mcp.json +8 -0
  269. package/plugin/README.md +51 -0
  270. package/plugin/hooks/hooks.json +25 -0
  271. package/plugin/scripts/prompt-recall-hook.mjs +202 -0
  272. package/plugin/scripts/stop-hook.mjs +306 -0
  273. package/plugin-hermes-agent/README.md +49 -0
  274. package/plugin-hermes-agent/__init__.py +75 -0
  275. package/plugin-hermes-agent/plugin.yaml +15 -0
  276. package/scripts/backfill-citations.mjs +0 -0
  277. package/scripts/build-codex-plugin.mjs +61 -0
  278. package/scripts/deepseek-probe.mjs +67 -0
  279. package/scripts/extract-triples.mjs +207 -0
  280. package/scripts/longmemeval/embedding-cache.ts +77 -0
  281. package/scripts/longmemeval/fetch-dataset.sh +25 -0
  282. package/scripts/longmemeval/run-harness.ts +315 -0
  283. package/scripts/longmemeval/scorer.ts +99 -0
  284. package/scripts/longmemeval/tsconfig.json +9 -0
  285. package/scripts/longmemeval/types.ts +35 -0
  286. package/scripts/nlm-daily-digest.py +239 -0
  287. package/scripts/nlm-daily-digest.sh +28 -0
  288. package/src/cli/classify-parity.ts +257 -0
  289. package/src/cli/launchctl-helpers.ts +49 -0
  290. package/src/cli/nlm.ts +885 -0
  291. package/src/core/actions/actions-log.ts +118 -0
  292. package/src/core/actions/overlay.ts +117 -0
  293. package/src/core/adapters/aider.ts +205 -0
  294. package/src/core/adapters/claude-code.ts +293 -0
  295. package/src/core/adapters/common.ts +54 -0
  296. package/src/core/adapters/from-source.ts +57 -0
  297. package/src/core/adapters/hermes-agent.ts +240 -0
  298. package/src/core/adapters/hermes.ts +277 -0
  299. package/src/core/adapters/jsonl-generic.ts +208 -0
  300. package/src/core/adapters/opencode.ts +281 -0
  301. package/src/core/adapters/pi.ts +264 -0
  302. package/src/core/classifier/prompt.ts +200 -0
  303. package/src/core/dataset/build-dataset.ts +463 -0
  304. package/src/core/embedding/chunk-body.ts +76 -0
  305. package/src/core/embedding/embed-backfill.ts +210 -0
  306. package/src/core/embedding/embed-normalize.ts +135 -0
  307. package/src/core/facts/backfill-facts.ts +254 -0
  308. package/src/core/facts/extract-facts.ts +50 -0
  309. package/src/core/hook/citation-detect.ts +124 -0
  310. package/src/core/hook/cite-memo.ts +68 -0
  311. package/src/core/hook/claude-settings.ts +166 -0
  312. package/src/core/hook/gate.ts +25 -0
  313. package/src/core/hook/hook-log.ts +41 -0
  314. package/src/core/hook/memo-sweep.ts +164 -0
  315. package/src/core/hook/memo.ts +67 -0
  316. package/src/core/hook/pointer-block.ts +26 -0
  317. package/src/core/hook/select.ts +32 -0
  318. package/src/core/hook/transcript.ts +121 -0
  319. package/src/core/ingest/ingest-session.ts +111 -0
  320. package/src/core/providers/provider-models.ts +100 -0
  321. package/src/core/providers/provider-registry.ts +196 -0
  322. package/src/core/recall/citation-log.ts +108 -0
  323. package/src/core/recall/filter.ts +27 -0
  324. package/src/core/recall/index.ts +6 -0
  325. package/src/core/recall/match-fields.ts +40 -0
  326. package/src/core/recall/query-log.ts +149 -0
  327. package/src/core/recall/query-shape.ts +66 -0
  328. package/src/core/recall/recall-service.ts +320 -0
  329. package/src/core/recall/recent-log.ts +59 -0
  330. package/src/core/recall/tokenize.ts +18 -0
  331. package/src/core/recall/useful-scan.ts +336 -0
  332. package/src/core/recall-facts/fact-query-log.ts +150 -0
  333. package/src/core/recall-facts/fact-recall-service.ts +327 -0
  334. package/src/core/scheduler/scan-once.ts +142 -0
  335. package/src/core/scheduler/scheduler.ts +225 -0
  336. package/src/core/sources/source-registry.ts +260 -0
  337. package/src/core/storage/db-restore.ts +133 -0
  338. package/src/core/storage/live-status.ts +45 -0
  339. package/src/core/storage/migrate.ts +72 -0
  340. package/src/core/storage/sqlite-fact-store.ts +304 -0
  341. package/src/core/storage/sqlite-session-store.ts +765 -0
  342. package/src/hook/prompt-recall-hook.ts +174 -0
  343. package/src/hook/session-end-hook.ts +81 -0
  344. package/src/hook/session-start-hook.ts +165 -0
  345. package/src/hook/stop-hook.ts +236 -0
  346. package/src/http/app.ts +1114 -0
  347. package/src/install/claude-code.ts +128 -0
  348. package/src/install/codex.ts +367 -0
  349. package/src/install/hermes-agent.ts +76 -0
  350. package/src/install/hermes.ts +78 -0
  351. package/src/install/ollama.ts +208 -0
  352. package/src/install/setup.ts +368 -0
  353. package/src/llm/classifier-box.ts +64 -0
  354. package/src/llm/deepseek-client.ts +150 -0
  355. package/src/llm/env-autoload.ts +55 -0
  356. package/src/llm/ollama-client.ts +189 -0
  357. package/src/mcp/server.ts +534 -0
  358. package/src/ports/fact-store.ts +102 -0
  359. package/src/ports/llm-client.ts +52 -0
  360. package/src/ports/logger.ts +16 -0
  361. package/src/ports/session-store.ts +45 -0
  362. package/src/ports/transcript-adapter.ts +55 -0
  363. package/src/shared/types.ts +145 -0
  364. package/src/ui/App.tsx +58 -0
  365. package/src/ui/components/PromoteOpenButton.tsx +65 -0
  366. package/src/ui/components/SessionDrawer.tsx +136 -0
  367. package/src/ui/components/SideNav.tsx +162 -0
  368. package/src/ui/components/Skeleton.tsx +107 -0
  369. package/src/ui/index.html +13 -0
  370. package/src/ui/lib/actions.ts +30 -0
  371. package/src/ui/lib/api.ts +92 -0
  372. package/src/ui/lib/dataset.ts +141 -0
  373. package/src/ui/lib/registries.ts +155 -0
  374. package/src/ui/lib/view-settings.ts +41 -0
  375. package/src/ui/main.tsx +15 -0
  376. package/src/ui/pages/Live.tsx +229 -0
  377. package/src/ui/pages/Pulse.tsx +415 -0
  378. package/src/ui/pages/Recall.tsx +190 -0
  379. package/src/ui/pages/River.tsx +308 -0
  380. package/src/ui/pages/Search.tsx +93 -0
  381. package/src/ui/pages/Stub.tsx +9 -0
  382. package/src/ui/pages/Thread.tsx +262 -0
  383. package/src/ui/pages/settings/Classifier.tsx +227 -0
  384. package/src/ui/pages/settings/Data.tsx +190 -0
  385. package/src/ui/pages/settings/Index.tsx +65 -0
  386. package/src/ui/pages/settings/Labels.tsx +224 -0
  387. package/src/ui/pages/settings/Providers.tsx +305 -0
  388. package/src/ui/pages/settings/SettingsSubnav.tsx +28 -0
  389. package/src/ui/pages/settings/Sources.tsx +326 -0
  390. package/src/ui/pages/settings/Views.tsx +96 -0
  391. package/src/ui/styles.css +1766 -0
  392. package/src/ui/tsconfig.json +21 -0
  393. package/src/ui/vite.config.ts +19 -0
  394. package/tests/fixtures/claude_code/short_session.jsonl +2 -0
  395. package/tests/fixtures/claude_code/standard_iso.jsonl +4 -0
  396. package/tests/fixtures/claude_code/tool_heavy.jsonl +8 -0
  397. package/tests/fixtures/claude_code/with_subagent.jsonl +7 -0
  398. package/tests/fixtures/facts.ts +17 -0
  399. package/tests/fixtures/golden-corpus.ts +85 -0
  400. package/tests/fixtures/hermes/paired_request_dump.json +24 -0
  401. package/tests/fixtures/hermes/paired_session.json +23 -0
  402. package/tests/fixtures/hermes/request_dump.json +28 -0
  403. package/tests/fixtures/hermes/session_iso.json +38 -0
  404. package/tests/fixtures/hermes/session_unix.json +38 -0
  405. package/tests/fixtures/hermes/system_only.json +18 -0
  406. package/tests/fixtures/pi/error-connection-abort.jsonl +8 -0
  407. package/tests/fixtures/pi/short-successful.jsonl +5 -0
  408. package/tests/fixtures/pi/with-custom-message.jsonl +6 -0
  409. package/tests/fixtures/sessions.ts +22 -0
  410. package/tests/integration/backfill-facts.test.ts +362 -0
  411. package/tests/integration/citation-explicit.test.ts +111 -0
  412. package/tests/integration/cite-event.test.ts +169 -0
  413. package/tests/integration/cite-memo.test.ts +87 -0
  414. package/tests/integration/db-restore.test.ts +153 -0
  415. package/tests/integration/embed-backfill.test.ts +176 -0
  416. package/tests/integration/fact-supersedence.test.ts +313 -0
  417. package/tests/integration/fts-index.test.ts +60 -0
  418. package/tests/integration/getbyids-sqlite.test.ts +60 -0
  419. package/tests/integration/hermes-agent-hooks.test.ts +248 -0
  420. package/tests/integration/hook-claude-settings.test.ts +205 -0
  421. package/tests/integration/hook-log.test.ts +54 -0
  422. package/tests/integration/hook-memo.test.ts +68 -0
  423. package/tests/integration/hook-pre-compact.test.ts +105 -0
  424. package/tests/integration/hook-subagent-start.test.ts +102 -0
  425. package/tests/integration/http.test.ts +401 -0
  426. package/tests/integration/keyword-search-fts.test.ts +66 -0
  427. package/tests/integration/mcp-recall-logging.test.ts +88 -0
  428. package/tests/integration/mcp.test.ts +248 -0
  429. package/tests/integration/memo-sweep.test.ts +91 -0
  430. package/tests/integration/prompt-recall-hook.test.ts +88 -0
  431. package/tests/integration/provider-registry.test.ts +107 -0
  432. package/tests/integration/recall-golden.test.ts +59 -0
  433. package/tests/integration/recall-sqlite.test.ts +169 -0
  434. package/tests/integration/scheduler.test.ts +391 -0
  435. package/tests/integration/session-end-hook.test.ts +48 -0
  436. package/tests/integration/session-start-hook.test.ts +126 -0
  437. package/tests/integration/source-registry.test.ts +120 -0
  438. package/tests/integration/sqlite-fact-store.test.ts +346 -0
  439. package/tests/integration/stop-hook.test.ts +560 -0
  440. package/tests/integration/wal-checkpoint.test.ts +49 -0
  441. package/tests/unit/cli/launchctl-helpers.test.ts +60 -0
  442. package/tests/unit/core/adapters/aider.test.ts +230 -0
  443. package/tests/unit/core/adapters/claude-code.test.ts +118 -0
  444. package/tests/unit/core/adapters/hermes-agent.test.ts +329 -0
  445. package/tests/unit/core/adapters/hermes.test.ts +81 -0
  446. package/tests/unit/core/adapters/jsonl-generic.test.ts +142 -0
  447. package/tests/unit/core/adapters/opencode.test.ts +354 -0
  448. package/tests/unit/core/adapters/pi.test.ts +110 -0
  449. package/tests/unit/core/classifier/prompt.test.ts +126 -0
  450. package/tests/unit/core/embedding/chunk-body.test.ts +100 -0
  451. package/tests/unit/core/facts/extract-facts.test.ts +117 -0
  452. package/tests/unit/core/filter.test.ts +40 -0
  453. package/tests/unit/core/hook/citation-detect-cite-session.test.ts +96 -0
  454. package/tests/unit/core/hook/citation-detect.test.ts +124 -0
  455. package/tests/unit/core/hook/gate.test.ts +29 -0
  456. package/tests/unit/core/hook/pointer-block.test.ts +22 -0
  457. package/tests/unit/core/hook/select.test.ts +66 -0
  458. package/tests/unit/core/match-fields.test.ts +39 -0
  459. package/tests/unit/core/mcp-cite-session.test.ts +51 -0
  460. package/tests/unit/core/providers/provider-models.test.ts +101 -0
  461. package/tests/unit/core/query-shape.test.ts +92 -0
  462. package/tests/unit/core/recall-facts/fact-recall-service.test.ts +258 -0
  463. package/tests/unit/core/recall-service.test.ts +200 -0
  464. package/tests/unit/core/storage/live-status.test.ts +54 -0
  465. package/tests/unit/core/tokenize.test.ts +32 -0
  466. package/tests/unit/core/useful-scan.test.ts +537 -0
  467. package/tests/unit/llm/embed.test.ts +93 -0
  468. package/tests/unit/llm/ollama-client.test.ts +124 -0
  469. package/tests/unit/scripts/longmemeval-scorer.test.ts +114 -0
  470. package/tsconfig.json +31 -0
  471. package/tsconfig.test.json +11 -0
  472. package/vitest.config.ts +22 -0
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "nlm-memory-ts",
3
+ "interface": {
4
+ "displayName": "nlm-memory"
5
+ },
6
+ "plugins": [
7
+ {
8
+ "name": "nlm-memory",
9
+ "source": {
10
+ "source": "local",
11
+ "path": "./plugin"
12
+ },
13
+ "policy": {
14
+ "installation": "AVAILABLE",
15
+ "authentication": "ON_USE"
16
+ },
17
+ "category": "Coding"
18
+ }
19
+ ]
20
+ }
@@ -0,0 +1,30 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+
15
+ - uses: actions/setup-node@v4
16
+ with:
17
+ node-version: "20"
18
+ cache: npm
19
+
20
+ - name: Install dependencies
21
+ run: npm ci
22
+
23
+ - name: Typecheck
24
+ run: npm run typecheck
25
+
26
+ - name: Test
27
+ run: npm test
28
+
29
+ - name: Build (server)
30
+ run: npm run build
package/LICENSE ADDED
@@ -0,0 +1,151 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship made available under
36
+ the License, as indicated by a copyright notice that is included in
37
+ or attached to the work (an example is provided in the Appendix below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other transformations
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean, as submitted to the Licensor for inclusion
48
+ in the Work by the copyright owner or by an individual or Legal Entity
49
+ authorized to submit on behalf of the copyright owner. For the purposes
50
+ of this definition, "submitted" means any form of electronic, verbal,
51
+ or written communication sent to the Licensor or its representatives,
52
+ including but not limited to communication on electronic mailing lists,
53
+ source code control systems, and issue tracking systems that are managed
54
+ by, or on behalf of, the Licensor for the purpose of developing the Work,
55
+ but excluding communication that is conspicuously marked or designated
56
+ in writing by the copyright owner as "Not a Contribution."
57
+
58
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
59
+ whom a Contribution has been received by the Licensor and included
60
+ within the Work.
61
+
62
+ 2. Grant of Copyright License. Subject to the terms and conditions of
63
+ this License, each Contributor hereby grants to You a perpetual,
64
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
65
+ copyright license to reproduce, prepare Derivative Works of,
66
+ publicly display, publicly perform, sublicense, and distribute the
67
+ Work and such Derivative Works in Source or Object form.
68
+
69
+ 3. Grant of Patent License. Subject to the terms and conditions of
70
+ this License, each Contributor hereby grants to You a perpetual,
71
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
72
+ (except as stated in this section) patent license to make, have made,
73
+ use, offer to sell, sell, import, and otherwise transfer the Work,
74
+ where such license applies only to those patent claims licensable
75
+ by such Contributor that are necessarily infringed by their
76
+ Contribution(s) alone or by the combination of their Contribution(s)
77
+ with the Work to which such Contribution(s) was submitted. If You
78
+ institute patent litigation against any entity (including a cross-claim
79
+ or counterclaim in a lawsuit) alleging that the Work or any
80
+ Contribution embodied within the Work constitutes direct or
81
+ contributory patent infringement, then any patent licenses granted
82
+ to You under this License for that Work shall terminate as of the
83
+ date such litigation is filed.
84
+
85
+ 4. Redistribution. You may reproduce and distribute copies of the
86
+ Work or Derivative Works thereof in any medium, with or without
87
+ modifications, and in Source or Object form, provided that You
88
+ meet the following conditions:
89
+
90
+ (a) You must give any other recipients of the Work or Derivative Works
91
+ a copy of this License; and
92
+
93
+ (b) You must cause any modified files to carry prominent notices
94
+ stating that You changed the files; and
95
+
96
+ (c) You must retain, in the Source form of any Derivative Works
97
+ that You distribute, all copyright, patent, trademark, and
98
+ attribution notices from the Source form of the Work,
99
+ excluding those notices that do not pertain to any part of
100
+ the Derivative Works; and
101
+
102
+ (d) If the Work includes a "NOTICE" text file as part of its
103
+ distribution, You must include a readable copy of the attribution
104
+ notices contained within such NOTICE file, in at least one of the
105
+ following places: within a NOTICE text provided as part of the
106
+ Derivative Works; within the Source form or documentation, if
107
+ provided along with the Derivative Works; or, within a display
108
+ generated by the Derivative Works, if and wherever such third-party
109
+ notices normally appear. The contents of the NOTICE file are for
110
+ informational purposes only and do not modify the License.
111
+
112
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
113
+ any Contribution intentionally submitted for inclusion in the Work
114
+ by You to the Licensor shall be under the terms and conditions of
115
+ this License, without any additional terms or conditions.
116
+
117
+ 6. Trademarks. This License does not grant permission to use the trade
118
+ names, trademarks, service marks, or product names of the Licensor,
119
+ except as required for reasonable and customary use in describing the
120
+ origin of the Work and reproducing the content of the NOTICE file.
121
+
122
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed
123
+ to in writing, Licensor provides the Work (and each Contributor
124
+ provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES
125
+ OR CONDITIONS OF ANY KIND, either express or implied, including,
126
+ without limitation, any warranties or conditions of TITLE,
127
+ NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR
128
+ PURPOSE. You are solely responsible for determining the appropriateness
129
+ of using or reproducing the Work and assume any risks associated with
130
+ Your exercise of permissions under this License.
131
+
132
+ 8. Limitation of Liability. In no event and under no legal theory,
133
+ whether in tort (including negligence), contract, or otherwise,
134
+ unless required by applicable law (such as deliberate and grossly
135
+ negligent acts) or agreed to in writing, shall any Contributor be
136
+ liable to You for damages, including any direct, indirect, special,
137
+ incidental, or exemplary damages of any character arising as a result
138
+ of this License or out of the use or inability to use the Work.
139
+
140
+ 9. Accepting Warranty or Additional Liability. While redistributing
141
+ the Work or Derivative Works thereof, You may offer, and charge a fee
142
+ for, acceptance of support, warranty, indemnity, or other liability
143
+ obligations and/or rights consistent with this License. However, in
144
+ accepting such obligations, You may offer such obligations only on
145
+ Your own behalf and on a sole responsibility basis, not on behalf of
146
+ any other Contributor, and only if You agree to indemnify, defend,
147
+ and hold each Contributor harmless for any liability incurred by such
148
+ Contributor as a result of your accepting any warranty or additional
149
+ liability.
150
+
151
+ Copyright 2026 Edward Chalupa
package/README.md ADDED
@@ -0,0 +1,119 @@
1
+ # nlm-memory
2
+
3
+ > Local-first memory OS for AI operators — one corpus across every runtime you use.
4
+
5
+ `nlm-memory` indexes every session from Claude Code, Codex, OpenCode, Hermes, Aider, and pi into a single searchable store on your machine. Three properties no competitor ships together:
6
+
7
+ 1. **Cross-runtime reach.** Claude Code, Codex, and OpenCode ship today. Hermes, pi, and Aider follow the same adapter pattern. One index, every tool — not one per runtime.
8
+ 2. **Editable timeline.** Sessions can be superseded, retired, or marked aborted. Memory is non-linear: patch history retroactively. No other memory layer lets you do this.
9
+ 3. **97.2% R@5 baseline.** On a 14-month corpus, keyword recall surfaces the right session in the top 5 on 97.2% of evaluator queries. No fine-tuning, no cloud, no account.
10
+
11
+ Everything stays on your machine. No telemetry, no account required beyond your classifier of choice.
12
+
13
+ ---
14
+
15
+ ## Requirements
16
+
17
+ - **Node 20+**
18
+ - **[Ollama](https://ollama.com)** running locally with `nomic-embed-text` pulled:
19
+ ```sh
20
+ ollama pull nomic-embed-text
21
+ ```
22
+ - **A classifier** — [DeepSeek](https://platform.deepseek.com) is recommended (fast, cheap, ~$0.002/session). Set `DEEPSEEK_API_KEY` in `~/.nlm/.env`. Ollama works offline with `NLM_CLASSIFIER=ollama`.
23
+
24
+ ---
25
+
26
+ ## Install
27
+
28
+ ```sh
29
+ npm install -g github:pbmagnet4/nlm-memory-ts
30
+ nlm migrate
31
+ nlm install
32
+ ```
33
+
34
+ `nlm install` writes a macOS LaunchAgent that starts the daemon on login and keeps it running. Open **http://localhost:3940/ui** — done.
35
+
36
+ To stop or remove:
37
+ ```sh
38
+ launchctl stop com.github.pbmagnet4.nlm-memory # stop without uninstalling
39
+ nlm uninstall # remove the LaunchAgent entirely
40
+ ```
41
+
42
+ ---
43
+
44
+ ## Wire to your AI agents (MCP)
45
+
46
+ Add to `~/.mcp.json` (or your editor's MCP config):
47
+
48
+ ```json
49
+ {
50
+ "mcpServers": {
51
+ "nlm-memory": {
52
+ "command": "node",
53
+ "args": ["<path-to-global-npm>/lib/node_modules/nlm-memory/dist/cli/nlm.js", "mcp"]
54
+ }
55
+ }
56
+ }
57
+ ```
58
+
59
+ Find the path with `npm root -g` — the full path is `$(npm root -g)/nlm-memory/dist/cli/nlm.js`.
60
+
61
+ Or use the runtime-specific connect commands:
62
+
63
+ ```sh
64
+ nlm connect claude-code # writes to ~/.mcp.json + installs hooks
65
+ nlm connect codex # installs as a Codex marketplace plugin
66
+ nlm connect hermes # writes to ~/.hermes/config.yaml (MCP)
67
+ nlm connect hermes-agent # installs as a NousResearch Hermes plugin (hooks + MCP)
68
+ ```
69
+
70
+ Once wired, agents can call `recall_sessions` (search past conversations) and `recall_facts` (pull structured facts like decisions and project state) automatically.
71
+
72
+ ---
73
+
74
+ ## What's inside
75
+
76
+ | Page | What it shows |
77
+ |---|---|
78
+ | **Live** | Sessions being written in real time, recent reads and decisions |
79
+ | **Pulse** | System health — coherence, runtimes, stale entities, recent sessions |
80
+ | **River** | Full session timeline with density controls |
81
+ | **Thread** | Per-entity conversation history |
82
+ | **Search** | Keyword, semantic, or hybrid recall |
83
+ | **Recall** | Adoption telemetry — is the memory system actually being used? |
84
+ | **Settings** | Sources, providers, classifier, data backup/restore |
85
+
86
+ ---
87
+
88
+ ## How it differs from mem0 and graphiti
89
+
90
+ - **Unit of memory:** whole sessions with extracted markers (decisions, open questions, entities), not individual facts or graph edges.
91
+ - **Audience:** you querying your own past work, not an embedded SDK for app developers.
92
+ - **Cross-runtime:** one corpus across Claude Code, Codex, OpenCode, Hermes, and more. Competitors target one runtime.
93
+ - **Editable timeline:** sessions can be superseded, retired, aborted. No other tool lets you retrofit memory — a record from 6 months ago can be corrected today.
94
+ - **Local-only:** no hosted offering, no telemetry, no vendor dependency.
95
+
96
+ ---
97
+
98
+ ## Development
99
+
100
+ ```sh
101
+ git clone https://github.com/pbmagnet4/nlm-memory-ts
102
+ cd nlm-memory-ts
103
+ npm install # install dependencies
104
+ npm run build # compile dist/ — commit the result, it ships in the repo
105
+ npm run dev # hot-reload daemon
106
+ npm run ui:dev # hot-reload UI at localhost:5173 (proxies /api to :3940)
107
+ npm test # unit + integration tests
108
+ npm run typecheck
109
+ ```
110
+
111
+ `dist/` is committed to the repo so `npm install -g github:…` works without a build step on the user's machine. Rebuild and commit `dist/` whenever you change `src/`.
112
+
113
+ Database lives at `~/.nlm/canonical.sqlite`. Override with `NLM_DB_PATH`.
114
+
115
+ ---
116
+
117
+ ## License
118
+
119
+ Apache 2.0 — see [LICENSE](LICENSE).
@@ -0,0 +1,48 @@
1
+ /**
2
+ * `nlm classify-parity` — Phase C parity verification harness.
3
+ *
4
+ * Reads N sessions from ~/.nlm/canonical.sqlite (read-only by default),
5
+ * runs the TS OllamaClient.classify on each body, diffs the result
6
+ * against the persisted Python classifier output, and prints aggregate
7
+ * metrics: Jaccard similarity on entities/decisions/open sets, label
8
+ * exact match rate, summary length delta, schema-failure count.
9
+ *
10
+ * Safe: opens the live store in readonly mode. Does not write anything
11
+ * back. Designed to be run interactively from a terminal during the
12
+ * Phase C cutover-prep window.
13
+ */
14
+ export type Provider = "ollama" | "deepseek";
15
+ interface CliOptions {
16
+ readonly limit: number;
17
+ readonly dbPath: string;
18
+ readonly ollamaUrl: string;
19
+ readonly classifyModel: string;
20
+ readonly provider: Provider;
21
+ readonly verbose: boolean;
22
+ }
23
+ interface DiffMetrics {
24
+ sessionId: string;
25
+ labelMatch: boolean;
26
+ labelTs: string;
27
+ labelPy: string;
28
+ entityJaccard: number;
29
+ decisionJaccard: number;
30
+ openJaccard: number;
31
+ summaryDeltaChars: number;
32
+ schemaFailure: boolean;
33
+ errorMessage?: string;
34
+ }
35
+ export interface ParityReport {
36
+ attempted: number;
37
+ succeeded: number;
38
+ schemaFailures: number;
39
+ networkFailures: number;
40
+ labelExactMatchRate: number;
41
+ meanEntityJaccard: number;
42
+ meanDecisionJaccard: number;
43
+ meanOpenJaccard: number;
44
+ diffs: ReadonlyArray<DiffMetrics>;
45
+ }
46
+ export declare function runParity(opts: CliOptions): Promise<ParityReport>;
47
+ export declare function main(): Promise<void>;
48
+ export {};
@@ -0,0 +1,182 @@
1
+ /**
2
+ * `nlm classify-parity` — Phase C parity verification harness.
3
+ *
4
+ * Reads N sessions from ~/.nlm/canonical.sqlite (read-only by default),
5
+ * runs the TS OllamaClient.classify on each body, diffs the result
6
+ * against the persisted Python classifier output, and prints aggregate
7
+ * metrics: Jaccard similarity on entities/decisions/open sets, label
8
+ * exact match rate, summary length delta, schema-failure count.
9
+ *
10
+ * Safe: opens the live store in readonly mode. Does not write anything
11
+ * back. Designed to be run interactively from a terminal during the
12
+ * Phase C cutover-prep window.
13
+ */
14
+ import { homedir } from "node:os";
15
+ import { resolve } from "node:path";
16
+ import Database from "better-sqlite3";
17
+ import * as sqliteVec from "sqlite-vec";
18
+ import { LLMUnreachableError } from "../ports/llm-client.js";
19
+ import { DeepSeekClient } from "../llm/deepseek-client.js";
20
+ import { OllamaClient, ClassifierSchemaError } from "../llm/ollama-client.js";
21
+ import { autoloadEnv } from "../llm/env-autoload.js";
22
+ function parseArgs(argv) {
23
+ const flag = (name, fallback) => {
24
+ const i = argv.indexOf(name);
25
+ if (i === -1)
26
+ return fallback;
27
+ return argv[i + 1] ?? fallback;
28
+ };
29
+ const limit = Number.parseInt(flag("--limit", "10") ?? "10", 10);
30
+ const providerRaw = (flag("--provider", "deepseek") ?? "deepseek").toLowerCase();
31
+ const provider = providerRaw === "ollama" ? "ollama" : "deepseek";
32
+ const defaultModel = provider === "deepseek" ? "deepseek-v4-flash" : "phi4-mini:latest";
33
+ return {
34
+ limit: Number.isFinite(limit) && limit > 0 ? limit : 10,
35
+ dbPath: flag("--db", process.env["NLM_DB_PATH"] ?? resolve(homedir(), ".nlm/canonical.sqlite")) ??
36
+ resolve(homedir(), ".nlm/canonical.sqlite"),
37
+ ollamaUrl: flag("--ollama", process.env["NLM_OLLAMA_URL"] ?? "http://localhost:11434") ?? "http://localhost:11434",
38
+ classifyModel: flag("--model", defaultModel) ?? defaultModel,
39
+ provider,
40
+ verbose: argv.includes("--verbose"),
41
+ };
42
+ }
43
+ function buildClient(opts) {
44
+ if (opts.provider === "deepseek") {
45
+ autoloadEnv();
46
+ return new DeepSeekClient({ classifyModel: opts.classifyModel });
47
+ }
48
+ return new OllamaClient({ baseUrl: opts.ollamaUrl, classifyModel: opts.classifyModel });
49
+ }
50
+ function jaccard(a, b) {
51
+ const setA = new Set(a.map((s) => s.toLowerCase().trim()));
52
+ const setB = new Set(b.map((s) => s.toLowerCase().trim()));
53
+ if (setA.size === 0 && setB.size === 0)
54
+ return 1;
55
+ const inter = new Set([...setA].filter((x) => setB.has(x)));
56
+ const union = new Set([...setA, ...setB]);
57
+ return inter.size / union.size;
58
+ }
59
+ export async function runParity(opts) {
60
+ const db = new Database(opts.dbPath, { readonly: true });
61
+ sqliteVec.load(db);
62
+ const rows = db
63
+ .prepare(`SELECT id, label, summary, body
64
+ FROM sessions
65
+ WHERE body IS NOT NULL AND body != ''
66
+ ORDER BY started_at DESC
67
+ LIMIT ?`)
68
+ .all(opts.limit);
69
+ const persistedById = new Map();
70
+ for (const r of rows) {
71
+ const entities = db
72
+ .prepare("SELECT entity_canonical FROM session_entities WHERE session_id = ?")
73
+ .all(r.id)
74
+ .map((x) => x.entity_canonical);
75
+ const markers = db
76
+ .prepare("SELECT kind, text FROM markers WHERE session_id = ? ORDER BY position")
77
+ .all(r.id);
78
+ persistedById.set(r.id, {
79
+ label: r.label,
80
+ summary: r.summary,
81
+ entities,
82
+ decisions: markers.filter((m) => m.kind === "decision").map((m) => m.text),
83
+ open: markers.filter((m) => m.kind === "open").map((m) => m.text),
84
+ });
85
+ }
86
+ db.close();
87
+ const client = buildClient(opts);
88
+ const diffs = [];
89
+ let schemaFailures = 0;
90
+ let networkFailures = 0;
91
+ let idx = 0;
92
+ for (const r of rows) {
93
+ idx += 1;
94
+ const py = persistedById.get(r.id);
95
+ if (!py || !r.body)
96
+ continue;
97
+ const t0 = Date.now();
98
+ try {
99
+ const ts = await client.classify(r.body);
100
+ const elapsed = ((Date.now() - t0) / 1000).toFixed(1);
101
+ const labelMatch = ts.label.toLowerCase().trim() === py.label.toLowerCase().trim();
102
+ const entJ = jaccard(ts.entities, py.entities);
103
+ const decJ = jaccard(ts.decisions, py.decisions);
104
+ const openJ = jaccard(ts.open, py.open);
105
+ diffs.push({
106
+ sessionId: r.id,
107
+ labelMatch,
108
+ labelTs: ts.label,
109
+ labelPy: py.label,
110
+ entityJaccard: entJ,
111
+ decisionJaccard: decJ,
112
+ openJaccard: openJ,
113
+ summaryDeltaChars: ts.summary.length - py.summary.length,
114
+ schemaFailure: false,
115
+ });
116
+ if (opts.verbose) {
117
+ const tag = labelMatch ? "EQ " : "DIFF";
118
+ process.stderr.write(` [${idx}/${rows.length}] ${elapsed}s ${tag} ${r.id} ent=${entJ.toFixed(2)} dec=${decJ.toFixed(2)} open=${openJ.toFixed(2)}\n`);
119
+ }
120
+ }
121
+ catch (e) {
122
+ const elapsed = ((Date.now() - t0) / 1000).toFixed(1);
123
+ const message = e instanceof Error ? e.message : String(e);
124
+ if (e instanceof ClassifierSchemaError)
125
+ schemaFailures += 1;
126
+ else if (e instanceof LLMUnreachableError)
127
+ networkFailures += 1;
128
+ diffs.push({
129
+ sessionId: r.id,
130
+ labelMatch: false,
131
+ labelTs: "",
132
+ labelPy: py.label,
133
+ entityJaccard: 0,
134
+ decisionJaccard: 0,
135
+ openJaccard: 0,
136
+ summaryDeltaChars: 0,
137
+ schemaFailure: e instanceof ClassifierSchemaError,
138
+ errorMessage: message,
139
+ });
140
+ if (opts.verbose) {
141
+ process.stderr.write(` [${idx}/${rows.length}] ${elapsed}s ERR ${r.id} :: ${message}\n`);
142
+ }
143
+ }
144
+ }
145
+ const successes = diffs.filter((d) => !d.errorMessage);
146
+ const mean = (xs) => xs.length === 0 ? 0 : Math.round((xs.reduce((a, b) => a + b, 0) / xs.length) * 1000) / 1000;
147
+ return {
148
+ attempted: diffs.length,
149
+ succeeded: successes.length,
150
+ schemaFailures,
151
+ networkFailures,
152
+ labelExactMatchRate: mean(successes.map((d) => (d.labelMatch ? 1 : 0))),
153
+ meanEntityJaccard: mean(successes.map((d) => d.entityJaccard)),
154
+ meanDecisionJaccard: mean(successes.map((d) => d.decisionJaccard)),
155
+ meanOpenJaccard: mean(successes.map((d) => d.openJaccard)),
156
+ diffs,
157
+ };
158
+ }
159
+ export async function main() {
160
+ const opts = parseArgs(process.argv.slice(2));
161
+ console.error(`nlm classify-parity: ${opts.limit} sessions from ${opts.dbPath}`);
162
+ console.error(` provider: ${opts.provider} model: ${opts.classifyModel}` +
163
+ (opts.provider === "ollama" ? ` ollama: ${opts.ollamaUrl}` : ""));
164
+ const report = await runParity(opts);
165
+ console.error("");
166
+ console.error(`attempted: ${report.attempted}`);
167
+ console.error(`succeeded: ${report.succeeded}`);
168
+ console.error(`schema failures: ${report.schemaFailures}`);
169
+ console.error(`network failures: ${report.networkFailures}`);
170
+ console.error(`label exact match: ${(report.labelExactMatchRate * 100).toFixed(1)}%`);
171
+ console.error(`mean Jaccard ents: ${report.meanEntityJaccard.toFixed(3)}`);
172
+ console.error(`mean Jaccard decs: ${report.meanDecisionJaccard.toFixed(3)}`);
173
+ console.error(`mean Jaccard open: ${report.meanOpenJaccard.toFixed(3)}`);
174
+ }
175
+ const isMain = import.meta.url === `file://${process.argv[1]}`;
176
+ if (isMain) {
177
+ main().catch((e) => {
178
+ console.error("classify-parity fatal:", e);
179
+ process.exit(1);
180
+ });
181
+ }
182
+ //# sourceMappingURL=classify-parity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"classify-parity.js","sourceRoot":"","sources":["../../src/cli/classify-parity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,O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CAAC,CAAC;IAC1D,OAAO,CAAC,KAAK,CAAC,wBAAwB,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;IAC1D,OAAO,CAAC,KAAK,CAAC,wBAAwB,MAAM,CAAC,cAAc,EAAE,CAAC,CAAC;IAC/D,OAAO,CAAC,KAAK,CAAC,wBAAwB,MAAM,CAAC,eAAe,EAAE,CAAC,CAAC;IAChE,OAAO,CAAC,KAAK,CAAC,wBAAwB,CAAC,MAAM,CAAC,mBAAmB,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACxF,OAAO,CAAC,KAAK,CAAC,wBAAwB,MAAM,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC7E,OAAO,CAAC,KAAK,CAAC,wBAAwB,MAAM,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC/E,OAAO,CAAC,KAAK,CAAC,wBAAwB,MAAM,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAC7E,CAAC;AAED,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,UAAU,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;AAC/D,IAAI,MAAM,EAAE,CAAC;IACX,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;QACjB,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,CAAC,CAAC,CAAC;QAC3C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Pure helpers for parsing launchctl interactions.
3
+ *
4
+ * Extracted so the string-matching against launchctl's textual output can
5
+ * be unit-tested. The real launchctl process invocations live in nlm.ts
6
+ * where they're called.
7
+ */
8
+ /**
9
+ * True when launchctl's bootout stderr indicates the agent simply wasn't
10
+ * loaded — a benign condition during uninstall (we wanted it gone, it's
11
+ * already gone). Any other error means something we should surface.
12
+ *
13
+ * The exact strings come from observed macOS launchctl output across
14
+ * versions; match case-insensitively because phrasing varies.
15
+ */
16
+ export declare function isBenignBootoutError(stderr: string): boolean;
17
+ /**
18
+ * True when the named LaunchAgent label appears in `launchctl list`. This
19
+ * is the source of truth for "is the agent actually loaded right now" —
20
+ * more reliable than trusting bootout's exit code, which has been seen to
21
+ * return zero while leaving the daemon running and to return non-zero
22
+ * while successfully unloading.
23
+ *
24
+ * Injected `runner` keeps this testable without spawning a real process.
25
+ */
26
+ export declare function isAgentLoaded(label: string, runner?: () => string): boolean;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Pure helpers for parsing launchctl interactions.
3
+ *
4
+ * Extracted so the string-matching against launchctl's textual output can
5
+ * be unit-tested. The real launchctl process invocations live in nlm.ts
6
+ * where they're called.
7
+ */
8
+ import { execFileSync } from "node:child_process";
9
+ /**
10
+ * True when launchctl's bootout stderr indicates the agent simply wasn't
11
+ * loaded — a benign condition during uninstall (we wanted it gone, it's
12
+ * already gone). Any other error means something we should surface.
13
+ *
14
+ * The exact strings come from observed macOS launchctl output across
15
+ * versions; match case-insensitively because phrasing varies.
16
+ */
17
+ export function isBenignBootoutError(stderr) {
18
+ const s = stderr.toLowerCase();
19
+ return (s.includes("could not find service") ||
20
+ s.includes("no such process") ||
21
+ s.includes("not currently loaded"));
22
+ }
23
+ /**
24
+ * True when the named LaunchAgent label appears in `launchctl list`. This
25
+ * is the source of truth for "is the agent actually loaded right now" —
26
+ * more reliable than trusting bootout's exit code, which has been seen to
27
+ * return zero while leaving the daemon running and to return non-zero
28
+ * while successfully unloading.
29
+ *
30
+ * Injected `runner` keeps this testable without spawning a real process.
31
+ */
32
+ export function isAgentLoaded(label, runner = () => execFileSync("launchctl", ["list"], { stdio: "pipe", encoding: "utf8" })) {
33
+ let out;
34
+ try {
35
+ out = runner();
36
+ }
37
+ catch {
38
+ return false;
39
+ }
40
+ return out.split("\n").some((line) => line.includes(label));
41
+ }
42
+ //# sourceMappingURL=launchctl-helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"launchctl-helpers.js","sourceRoot":"","sources":["../../src/cli/launchctl-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAAc;IACjD,MAAM,CAAC,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;IAC/B,OAAO,CACL,CAAC,CAAC,QAAQ,CAAC,wBAAwB,CAAC;QACpC,CAAC,CAAC,QAAQ,CAAC,iBAAiB,CAAC;QAC7B,CAAC,CAAC,QAAQ,CAAC,sBAAsB,CAAC,CACnC,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAC3B,KAAa,EACb,SAAuB,GAAG,EAAE,CAC1B,YAAY,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;IAE1E,IAAI,GAAW,CAAC;IAChB,IAAI,CAAC;QACH,GAAG,GAAG,MAAM,EAAE,CAAC;IACjB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;AAC9D,CAAC"}
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * nlm — CLI entry point. Composition root for the whole stack.
4
+ *
5
+ * This is the one file that knows about every concrete implementation:
6
+ * SqliteSessionStore (storage), OllamaClient (LLM), Hono (HTTP),
7
+ * McpServer (MCP). Every other module depends on ports. Swapping a
8
+ * backend means editing this file, not anything inside core/.
9
+ *
10
+ * Subcommands:
11
+ * nlm start — boot HTTP server on $NLM_PORT (default 3940)
12
+ * nlm migrate — run pending migrations against the canonical SQLite
13
+ * nlm recall — one-shot recall query from the shell (debugging)
14
+ * nlm mcp — run as an MCP stdio server (for ~/.mcp.json wiring)
15
+ * nlm setup — interactive first-run wizard (recommended entry point)
16
+ * nlm install — install the macOS LaunchAgent (auto-start on login)
17
+ * nlm uninstall — remove the macOS LaunchAgent
18
+ * nlm hook install — add the recall hook to Claude Code (shadow mode)
19
+ * nlm hook uninstall — remove the recall hook from Claude Code
20
+ * nlm connect claude-code — write MCP server block to ~/.mcp.json
21
+ * nlm connect codex — install Codex marketplace plugin
22
+ * nlm disconnect claude-code — remove MCP block from ~/.mcp.json
23
+ * nlm disconnect codex — remove Codex plugin
24
+ */
25
+ export {};