nlm-memory 0.20.1 → 0.21.12

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 (475) hide show
  1. package/README.md +69 -12
  2. package/assets/replay-eval-dark.svg +26 -0
  3. package/assets/replay-eval-light.svg +26 -0
  4. package/dist/cli/digest.js +69 -4
  5. package/dist/cli/digest.js.map +1 -1
  6. package/dist/cli/nlm.d.ts +14 -0
  7. package/dist/cli/nlm.js +556 -71
  8. package/dist/cli/nlm.js.map +1 -1
  9. package/dist/cli/reprocess-job-adapters.d.ts +35 -0
  10. package/dist/cli/reprocess-job-adapters.js +80 -0
  11. package/dist/cli/reprocess-job-adapters.js.map +1 -0
  12. package/dist/cli/scope-backfill.d.ts +34 -0
  13. package/dist/cli/scope-backfill.js +237 -0
  14. package/dist/cli/scope-backfill.js.map +1 -0
  15. package/dist/cli/scope-coverage.d.ts +44 -0
  16. package/dist/cli/scope-coverage.js +208 -0
  17. package/dist/cli/scope-coverage.js.map +1 -0
  18. package/dist/cli/supersede.js +8 -7
  19. package/dist/cli/supersede.js.map +1 -1
  20. package/dist/core/actions/actions-log.d.ts +65 -8
  21. package/dist/core/actions/actions-log.js +134 -17
  22. package/dist/core/actions/actions-log.js.map +1 -1
  23. package/dist/core/actions/overlay.d.ts +11 -2
  24. package/dist/core/actions/overlay.js +18 -6
  25. package/dist/core/actions/overlay.js.map +1 -1
  26. package/dist/core/adapters/claude-code.d.ts +14 -0
  27. package/dist/core/adapters/claude-code.js +30 -0
  28. package/dist/core/adapters/claude-code.js.map +1 -1
  29. package/dist/core/adapters/from-source.js +11 -3
  30. package/dist/core/adapters/from-source.js.map +1 -1
  31. package/dist/core/adapters/fs-wiki-writer.d.ts +44 -0
  32. package/dist/core/adapters/fs-wiki-writer.js +132 -0
  33. package/dist/core/adapters/fs-wiki-writer.js.map +1 -0
  34. package/dist/core/adapters/hermes-agent.d.ts +15 -2
  35. package/dist/core/adapters/hermes-agent.js +57 -11
  36. package/dist/core/adapters/hermes-agent.js.map +1 -1
  37. package/dist/core/adapters/memory-wiki-writer.d.ts +8 -0
  38. package/dist/core/adapters/memory-wiki-writer.js +16 -0
  39. package/dist/core/adapters/memory-wiki-writer.js.map +1 -0
  40. package/dist/core/adapters/muse.d.ts +51 -0
  41. package/dist/core/adapters/muse.js +271 -0
  42. package/dist/core/adapters/muse.js.map +1 -0
  43. package/dist/core/adapters/opencode.d.ts +11 -4
  44. package/dist/core/adapters/opencode.js +41 -7
  45. package/dist/core/adapters/opencode.js.map +1 -1
  46. package/dist/core/alerts/alert-state.d.ts +17 -0
  47. package/dist/core/alerts/alert-state.js +45 -0
  48. package/dist/core/alerts/alert-state.js.map +1 -0
  49. package/dist/core/alerts/check-and-alert.d.ts +28 -0
  50. package/dist/core/alerts/check-and-alert.js +53 -0
  51. package/dist/core/alerts/check-and-alert.js.map +1 -0
  52. package/dist/core/alerts/drift-transition.d.ts +27 -0
  53. package/dist/core/alerts/drift-transition.js +56 -0
  54. package/dist/core/alerts/drift-transition.js.map +1 -0
  55. package/dist/core/alerts/embedder-transition.d.ts +23 -0
  56. package/dist/core/alerts/embedder-transition.js +40 -0
  57. package/dist/core/alerts/embedder-transition.js.map +1 -0
  58. package/dist/core/alerts/fire-alert.d.ts +24 -0
  59. package/dist/core/alerts/fire-alert.js +72 -0
  60. package/dist/core/alerts/fire-alert.js.map +1 -0
  61. package/dist/core/alerts/job-alert.d.ts +12 -0
  62. package/dist/core/alerts/job-alert.js +37 -0
  63. package/dist/core/alerts/job-alert.js.map +1 -0
  64. package/dist/core/alerts/types.d.ts +104 -0
  65. package/dist/core/alerts/types.js +11 -0
  66. package/dist/core/alerts/types.js.map +1 -0
  67. package/dist/core/alerts/wiki-alert.d.ts +15 -0
  68. package/dist/core/alerts/wiki-alert.js +31 -0
  69. package/dist/core/alerts/wiki-alert.js.map +1 -0
  70. package/dist/core/classifier/prompt.d.ts +13 -0
  71. package/dist/core/classifier/prompt.js +52 -2
  72. package/dist/core/classifier/prompt.js.map +1 -1
  73. package/dist/core/dataset/build-dataset.d.ts +16 -1
  74. package/dist/core/dataset/build-dataset.js +46 -13
  75. package/dist/core/dataset/build-dataset.js.map +1 -1
  76. package/dist/core/digest/compose.d.ts +11 -3
  77. package/dist/core/digest/compose.js +70 -17
  78. package/dist/core/digest/compose.js.map +1 -1
  79. package/dist/core/digest/hook-injection.d.ts +43 -0
  80. package/dist/core/digest/hook-injection.js +87 -0
  81. package/dist/core/digest/hook-injection.js.map +1 -0
  82. package/dist/core/digest/hook-version-parity.d.ts +31 -0
  83. package/dist/core/digest/hook-version-parity.js +56 -0
  84. package/dist/core/digest/hook-version-parity.js.map +1 -0
  85. package/dist/core/embedding/pg-embed-backfill.js +1 -1
  86. package/dist/core/embedding/pg-embed-backfill.js.map +1 -1
  87. package/dist/core/exemplars/capture-from-session.d.ts +2 -1
  88. package/dist/core/exemplars/capture-from-session.js +4 -4
  89. package/dist/core/exemplars/capture-from-session.js.map +1 -1
  90. package/dist/core/exemplars/embed-backfill.d.ts +9 -0
  91. package/dist/core/exemplars/embed-backfill.js +9 -1
  92. package/dist/core/exemplars/embed-backfill.js.map +1 -1
  93. package/dist/core/exemplars/extract-exemplar.d.ts +2 -0
  94. package/dist/core/exemplars/extract-exemplar.js +7 -1
  95. package/dist/core/exemplars/extract-exemplar.js.map +1 -1
  96. package/dist/core/exemplars/ingest-exemplar.d.ts +1 -0
  97. package/dist/core/exemplars/ingest-exemplar.js +1 -0
  98. package/dist/core/exemplars/ingest-exemplar.js.map +1 -1
  99. package/dist/core/exemplars/recall-code.d.ts +1 -1
  100. package/dist/core/exemplars/recall-code.js +2 -2
  101. package/dist/core/exemplars/recall-code.js.map +1 -1
  102. package/dist/core/facts/backfill-facts.d.ts +1 -1
  103. package/dist/core/facts/backfill-facts.js +4 -4
  104. package/dist/core/facts/backfill-facts.js.map +1 -1
  105. package/dist/core/facts/embed-backfill.d.ts +54 -0
  106. package/dist/core/facts/embed-backfill.js +109 -0
  107. package/dist/core/facts/embed-backfill.js.map +1 -0
  108. package/dist/core/facts/reconcile-facts.d.ts +42 -0
  109. package/dist/core/facts/reconcile-facts.js +133 -0
  110. package/dist/core/facts/reconcile-facts.js.map +1 -0
  111. package/dist/core/health/embed-failure-state.d.ts +4 -0
  112. package/dist/core/health/embed-failure-state.js +12 -0
  113. package/dist/core/health/embed-failure-state.js.map +1 -0
  114. package/dist/core/health/warmup-retry.d.ts +27 -0
  115. package/dist/core/health/warmup-retry.js +53 -0
  116. package/dist/core/health/warmup-retry.js.map +1 -0
  117. package/dist/core/health/warmup-state.d.ts +15 -0
  118. package/dist/core/health/warmup-state.js +15 -1
  119. package/dist/core/health/warmup-state.js.map +1 -1
  120. package/dist/core/hook/cite-memo.d.ts +11 -7
  121. package/dist/core/hook/cite-memo.js +25 -17
  122. package/dist/core/hook/cite-memo.js.map +1 -1
  123. package/dist/core/hook/claude-settings.d.ts +1 -1
  124. package/dist/core/hook/claude-settings.js +0 -1
  125. package/dist/core/hook/claude-settings.js.map +1 -1
  126. package/dist/core/hook/hook-log.d.ts +13 -2
  127. package/dist/core/hook/hook-log.js +16 -8
  128. package/dist/core/hook/hook-log.js.map +1 -1
  129. package/dist/core/hook/memo.d.ts +10 -6
  130. package/dist/core/hook/memo.js +25 -17
  131. package/dist/core/hook/memo.js.map +1 -1
  132. package/dist/core/hook/pointer-block.d.ts +8 -1
  133. package/dist/core/hook/pointer-block.js +17 -4
  134. package/dist/core/hook/pointer-block.js.map +1 -1
  135. package/dist/core/hook/resolve-conversation-by-query.d.ts +6 -5
  136. package/dist/core/hook/resolve-conversation-by-query.js +24 -12
  137. package/dist/core/hook/resolve-conversation-by-query.js.map +1 -1
  138. package/dist/core/ingest/backfill-derivables.d.ts +92 -0
  139. package/dist/core/ingest/backfill-derivables.js +175 -0
  140. package/dist/core/ingest/backfill-derivables.js.map +1 -0
  141. package/dist/core/ingest/ingest-session.d.ts +1 -1
  142. package/dist/core/ingest/ingest-session.js +23 -3
  143. package/dist/core/ingest/ingest-session.js.map +1 -1
  144. package/dist/core/ingest/reclassify-oversized.d.ts +1 -1
  145. package/dist/core/ingest/reclassify-oversized.js +8 -2
  146. package/dist/core/ingest/reclassify-oversized.js.map +1 -1
  147. package/dist/core/ingest/reprocess.d.ts +1 -1
  148. package/dist/core/ingest/reprocess.js +7 -2
  149. package/dist/core/ingest/reprocess.js.map +1 -1
  150. package/dist/core/ingest/transcript-derivables.d.ts +27 -0
  151. package/dist/core/ingest/transcript-derivables.js +138 -0
  152. package/dist/core/ingest/transcript-derivables.js.map +1 -0
  153. package/dist/core/jobs/job-supervisor.d.ts +168 -0
  154. package/dist/core/jobs/job-supervisor.js +335 -0
  155. package/dist/core/jobs/job-supervisor.js.map +1 -0
  156. package/dist/core/learner/model.d.ts +63 -0
  157. package/dist/core/learner/model.js +30 -0
  158. package/dist/core/learner/model.js.map +1 -0
  159. package/dist/core/learner/service.d.ts +42 -0
  160. package/dist/core/learner/service.js +74 -0
  161. package/dist/core/learner/service.js.map +1 -0
  162. package/dist/core/learner/summary.d.ts +28 -0
  163. package/dist/core/learner/summary.js +70 -0
  164. package/dist/core/learner/summary.js.map +1 -0
  165. package/dist/core/learner/validate.d.ts +18 -0
  166. package/dist/core/learner/validate.js +95 -0
  167. package/dist/core/learner/validate.js.map +1 -0
  168. package/dist/core/metrics/re-derivation.d.ts +31 -2
  169. package/dist/core/metrics/re-derivation.js +36 -4
  170. package/dist/core/metrics/re-derivation.js.map +1 -1
  171. package/dist/core/outcome/coverage.d.ts +33 -0
  172. package/dist/core/outcome/coverage.js +46 -0
  173. package/dist/core/outcome/coverage.js.map +1 -0
  174. package/dist/core/outcome/rollup.d.ts +33 -0
  175. package/dist/core/outcome/rollup.js +113 -0
  176. package/dist/core/outcome/rollup.js.map +1 -0
  177. package/dist/core/providers/provider-registry.d.ts +40 -23
  178. package/dist/core/providers/provider-registry.js +99 -81
  179. package/dist/core/providers/provider-registry.js.map +1 -1
  180. package/dist/core/recall/citation-log.d.ts +10 -5
  181. package/dist/core/recall/citation-log.js +21 -10
  182. package/dist/core/recall/citation-log.js.map +1 -1
  183. package/dist/core/recall/hook-recall-log.d.ts +7 -4
  184. package/dist/core/recall/hook-recall-log.js +14 -8
  185. package/dist/core/recall/hook-recall-log.js.map +1 -1
  186. package/dist/core/recall/miss-log.d.ts +7 -4
  187. package/dist/core/recall/miss-log.js +18 -11
  188. package/dist/core/recall/miss-log.js.map +1 -1
  189. package/dist/core/recall/query-log.d.ts +8 -5
  190. package/dist/core/recall/query-log.js +16 -9
  191. package/dist/core/recall/query-log.js.map +1 -1
  192. package/dist/core/recall/recall-service.d.ts +10 -1
  193. package/dist/core/recall/recall-service.js +31 -12
  194. package/dist/core/recall/recall-service.js.map +1 -1
  195. package/dist/core/recall/recent-log.d.ts +6 -1
  196. package/dist/core/recall/recent-log.js +13 -5
  197. package/dist/core/recall/recent-log.js.map +1 -1
  198. package/dist/core/recall/related-concepts.d.ts +29 -0
  199. package/dist/core/recall/related-concepts.js +67 -0
  200. package/dist/core/recall/related-concepts.js.map +1 -0
  201. package/dist/core/recall/related-exemplars.d.ts +1 -1
  202. package/dist/core/recall/related-exemplars.js +2 -2
  203. package/dist/core/recall/related-exemplars.js.map +1 -1
  204. package/dist/core/recall/related-facts.d.ts +1 -1
  205. package/dist/core/recall/related-facts.js +3 -3
  206. package/dist/core/recall/related-facts.js.map +1 -1
  207. package/dist/core/recall-facts/fact-query-log.d.ts +8 -4
  208. package/dist/core/recall-facts/fact-query-log.js +16 -8
  209. package/dist/core/recall-facts/fact-query-log.js.map +1 -1
  210. package/dist/core/recall-facts/fact-recall-service.d.ts +2 -2
  211. package/dist/core/recall-facts/fact-recall-service.js +13 -12
  212. package/dist/core/recall-facts/fact-recall-service.js.map +1 -1
  213. package/dist/core/scheduler/scan-once.js +15 -12
  214. package/dist/core/scheduler/scan-once.js.map +1 -1
  215. package/dist/core/scheduler/scheduler.d.ts +3 -0
  216. package/dist/core/scheduler/scheduler.js +45 -10
  217. package/dist/core/scheduler/scheduler.js.map +1 -1
  218. package/dist/core/scope/alias-map.d.ts +10 -0
  219. package/dist/core/scope/alias-map.js +41 -0
  220. package/dist/core/scope/alias-map.js.map +1 -0
  221. package/dist/core/scope/derive-scope.d.ts +8 -0
  222. package/dist/core/scope/derive-scope.js +54 -0
  223. package/dist/core/scope/derive-scope.js.map +1 -0
  224. package/dist/core/scope/scope-clause.d.ts +16 -0
  225. package/dist/core/scope/scope-clause.js +21 -0
  226. package/dist/core/scope/scope-clause.js.map +1 -0
  227. package/dist/core/scope/stamp-flag.d.ts +1 -0
  228. package/dist/core/scope/stamp-flag.js +4 -0
  229. package/dist/core/scope/stamp-flag.js.map +1 -0
  230. package/dist/core/signals/code-signal.d.ts +1 -0
  231. package/dist/core/signals/code-signal.js +1 -0
  232. package/dist/core/signals/code-signal.js.map +1 -1
  233. package/dist/core/signals/failure-mode-recall.d.ts +1 -1
  234. package/dist/core/signals/failure-mode-recall.js +2 -2
  235. package/dist/core/signals/failure-mode-recall.js.map +1 -1
  236. package/dist/core/signals/ingest-signal.d.ts +1 -1
  237. package/dist/core/signals/ingest-signal.js +3 -1
  238. package/dist/core/signals/ingest-signal.js.map +1 -1
  239. package/dist/core/signals/stamp-scope.d.ts +18 -0
  240. package/dist/core/signals/stamp-scope.js +28 -0
  241. package/dist/core/signals/stamp-scope.js.map +1 -0
  242. package/dist/core/sources/source-registry.d.ts +49 -28
  243. package/dist/core/sources/source-registry.js +113 -70
  244. package/dist/core/sources/source-registry.js.map +1 -1
  245. package/dist/core/storage/pg-code-exemplar-store.d.ts +19 -10
  246. package/dist/core/storage/pg-code-exemplar-store.js +62 -27
  247. package/dist/core/storage/pg-code-exemplar-store.js.map +1 -1
  248. package/dist/core/storage/pg-entity-store.d.ts +6 -1
  249. package/dist/core/storage/pg-entity-store.js +33 -18
  250. package/dist/core/storage/pg-entity-store.js.map +1 -1
  251. package/dist/core/storage/pg-fact-ingest.d.ts +1 -1
  252. package/dist/core/storage/pg-fact-ingest.js +10 -7
  253. package/dist/core/storage/pg-fact-ingest.js.map +1 -1
  254. package/dist/core/storage/pg-fact-store.d.ts +29 -17
  255. package/dist/core/storage/pg-fact-store.js +99 -46
  256. package/dist/core/storage/pg-fact-store.js.map +1 -1
  257. package/dist/core/storage/pg-learner-store.d.ts +27 -0
  258. package/dist/core/storage/pg-learner-store.js +174 -0
  259. package/dist/core/storage/pg-learner-store.js.map +1 -0
  260. package/dist/core/storage/pg-session-store.d.ts +25 -21
  261. package/dist/core/storage/pg-session-store.js +186 -114
  262. package/dist/core/storage/pg-session-store.js.map +1 -1
  263. package/dist/core/storage/pg-signal-store.d.ts +10 -5
  264. package/dist/core/storage/pg-signal-store.js +26 -13
  265. package/dist/core/storage/pg-signal-store.js.map +1 -1
  266. package/dist/core/storage/pg-storage.d.ts +4 -0
  267. package/dist/core/storage/pg-storage.js +6 -0
  268. package/dist/core/storage/pg-storage.js.map +1 -1
  269. package/dist/core/storage/pg-workstream-store.d.ts +17 -11
  270. package/dist/core/storage/pg-workstream-store.js +47 -29
  271. package/dist/core/storage/pg-workstream-store.js.map +1 -1
  272. package/dist/core/storage/sqlite-code-exemplar-store.d.ts +24 -10
  273. package/dist/core/storage/sqlite-code-exemplar-store.js +86 -40
  274. package/dist/core/storage/sqlite-code-exemplar-store.js.map +1 -1
  275. package/dist/core/storage/sqlite-entity-store.d.ts +8 -1
  276. package/dist/core/storage/sqlite-entity-store.js +46 -27
  277. package/dist/core/storage/sqlite-entity-store.js.map +1 -1
  278. package/dist/core/storage/sqlite-fact-store.d.ts +45 -19
  279. package/dist/core/storage/sqlite-fact-store.js +175 -64
  280. package/dist/core/storage/sqlite-fact-store.js.map +1 -1
  281. package/dist/core/storage/sqlite-learner-store.d.ts +33 -0
  282. package/dist/core/storage/sqlite-learner-store.js +178 -0
  283. package/dist/core/storage/sqlite-learner-store.js.map +1 -0
  284. package/dist/core/storage/sqlite-outcome-store.d.ts +104 -0
  285. package/dist/core/storage/sqlite-outcome-store.js +211 -0
  286. package/dist/core/storage/sqlite-outcome-store.js.map +1 -0
  287. package/dist/core/storage/sqlite-session-store.d.ts +50 -21
  288. package/dist/core/storage/sqlite-session-store.js +233 -149
  289. package/dist/core/storage/sqlite-session-store.js.map +1 -1
  290. package/dist/core/storage/sqlite-signal-store.d.ts +12 -5
  291. package/dist/core/storage/sqlite-signal-store.js +29 -15
  292. package/dist/core/storage/sqlite-signal-store.js.map +1 -1
  293. package/dist/core/storage/sqlite-storage.d.ts +4 -0
  294. package/dist/core/storage/sqlite-storage.js +10 -2
  295. package/dist/core/storage/sqlite-storage.js.map +1 -1
  296. package/dist/core/storage/sqlite-workstream-store.d.ts +17 -11
  297. package/dist/core/storage/sqlite-workstream-store.js +53 -31
  298. package/dist/core/storage/sqlite-workstream-store.js.map +1 -1
  299. package/dist/core/storage/supersedence-log.d.ts +10 -7
  300. package/dist/core/storage/supersedence-log.js +21 -14
  301. package/dist/core/storage/supersedence-log.js.map +1 -1
  302. package/dist/core/telemetry/probe-filter.d.ts +35 -0
  303. package/dist/core/telemetry/probe-filter.js +56 -0
  304. package/dist/core/telemetry/probe-filter.js.map +1 -0
  305. package/dist/core/tenancy/default-team.d.ts +6 -0
  306. package/dist/core/tenancy/default-team.js +7 -0
  307. package/dist/core/tenancy/default-team.js.map +1 -0
  308. package/dist/core/tenancy/hosted-mode.d.ts +9 -0
  309. package/dist/core/tenancy/hosted-mode.js +12 -0
  310. package/dist/core/tenancy/hosted-mode.js.map +1 -0
  311. package/dist/core/tenancy/team-auth.d.ts +16 -0
  312. package/dist/core/tenancy/team-auth.js +22 -0
  313. package/dist/core/tenancy/team-auth.js.map +1 -0
  314. package/dist/core/tenancy/team-token-store.d.ts +45 -0
  315. package/dist/core/tenancy/team-token-store.js +52 -0
  316. package/dist/core/tenancy/team-token-store.js.map +1 -0
  317. package/dist/core/tenancy/tenant-clause.d.ts +37 -0
  318. package/dist/core/tenancy/tenant-clause.js +11 -0
  319. package/dist/core/tenancy/tenant-clause.js.map +1 -0
  320. package/dist/core/tenancy/tenant-state-path.d.ts +28 -0
  321. package/dist/core/tenancy/tenant-state-path.js +49 -0
  322. package/dist/core/tenancy/tenant-state-path.js.map +1 -0
  323. package/dist/core/update-check/check.d.ts +6 -0
  324. package/dist/core/update-check/check.js +35 -0
  325. package/dist/core/update-check/check.js.map +1 -1
  326. package/dist/core/wiki/project.d.ts +17 -0
  327. package/dist/core/wiki/project.js +37 -0
  328. package/dist/core/wiki/project.js.map +1 -0
  329. package/dist/core/wiki/reconcile.d.ts +15 -0
  330. package/dist/core/wiki/reconcile.js +14 -0
  331. package/dist/core/wiki/reconcile.js.map +1 -0
  332. package/dist/core/wiki/render.d.ts +5 -0
  333. package/dist/core/wiki/render.js +84 -0
  334. package/dist/core/wiki/render.js.map +1 -0
  335. package/dist/core/wiki/rollup.d.ts +28 -0
  336. package/dist/core/wiki/rollup.js +91 -0
  337. package/dist/core/wiki/rollup.js.map +1 -0
  338. package/dist/core/wiki/select.d.ts +8 -0
  339. package/dist/core/wiki/select.js +7 -0
  340. package/dist/core/wiki/select.js.map +1 -0
  341. package/dist/core/wiki/slug.d.ts +36 -0
  342. package/dist/core/wiki/slug.js +71 -0
  343. package/dist/core/wiki/slug.js.map +1 -0
  344. package/dist/core/wiki/types.d.ts +37 -0
  345. package/dist/core/wiki/types.js +2 -0
  346. package/dist/core/wiki/types.js.map +1 -0
  347. package/dist/core/work-digest/build-work-digest.d.ts +1 -1
  348. package/dist/core/work-digest/build-work-digest.js +3 -3
  349. package/dist/core/work-digest/build-work-digest.js.map +1 -1
  350. package/dist/core/workstream/bind.d.ts +3 -2
  351. package/dist/core/workstream/bind.js +29 -10
  352. package/dist/core/workstream/bind.js.map +1 -1
  353. package/dist/core/workstream/model.d.ts +1 -0
  354. package/dist/core/workstream/model.js.map +1 -1
  355. package/dist/core/workstream/rollup.d.ts +1 -1
  356. package/dist/core/workstream/rollup.js +6 -6
  357. package/dist/core/workstream/rollup.js.map +1 -1
  358. package/dist/hook/hook-helpers.d.ts +14 -0
  359. package/dist/hook/hook-helpers.js +29 -2
  360. package/dist/hook/hook-helpers.js.map +1 -1
  361. package/dist/hook/pre-compact-hook.js +8 -5
  362. package/dist/hook/pre-compact-hook.js.map +1 -1
  363. package/dist/hook/prompt-recall-hook.d.ts +7 -3
  364. package/dist/hook/prompt-recall-hook.js +35 -20
  365. package/dist/hook/prompt-recall-hook.js.map +1 -1
  366. package/dist/hook/recall-over-http.d.ts +28 -3
  367. package/dist/hook/recall-over-http.js +58 -12
  368. package/dist/hook/recall-over-http.js.map +1 -1
  369. package/dist/hook/session-end-hook.js +7 -5
  370. package/dist/hook/session-end-hook.js.map +1 -1
  371. package/dist/hook/session-start-hook.d.ts +14 -1
  372. package/dist/hook/session-start-hook.js +57 -16
  373. package/dist/hook/session-start-hook.js.map +1 -1
  374. package/dist/hook/stop-hook.js +11 -8
  375. package/dist/hook/stop-hook.js.map +1 -1
  376. package/dist/http/app.d.ts +47 -3
  377. package/dist/http/app.js +379 -132
  378. package/dist/http/app.js.map +1 -1
  379. package/dist/install/claude-code.d.ts +17 -0
  380. package/dist/install/claude-code.js +44 -5
  381. package/dist/install/claude-code.js.map +1 -1
  382. package/dist/install/codex.d.ts +23 -2
  383. package/dist/install/codex.js +111 -14
  384. package/dist/install/codex.js.map +1 -1
  385. package/dist/install/cursor.d.ts +2 -2
  386. package/dist/install/cursor.js +7 -7
  387. package/dist/install/cursor.js.map +1 -1
  388. package/dist/install/hermes.d.ts +8 -0
  389. package/dist/install/hermes.js +28 -5
  390. package/dist/install/hermes.js.map +1 -1
  391. package/dist/install/local-source.d.ts +20 -0
  392. package/dist/install/local-source.js +28 -0
  393. package/dist/install/local-source.js.map +1 -0
  394. package/dist/install/mcp-block.d.ts +77 -0
  395. package/dist/install/mcp-block.js +99 -0
  396. package/dist/install/mcp-block.js.map +1 -0
  397. package/dist/install/pi.d.ts +26 -0
  398. package/dist/install/pi.js +43 -0
  399. package/dist/install/pi.js.map +1 -1
  400. package/dist/install/setup.js +6 -0
  401. package/dist/install/setup.js.map +1 -1
  402. package/dist/install/windsurf.d.ts +2 -2
  403. package/dist/install/windsurf.js +7 -7
  404. package/dist/install/windsurf.js.map +1 -1
  405. package/dist/llm/classifier-box.d.ts +5 -0
  406. package/dist/llm/classifier-box.js +5 -0
  407. package/dist/llm/classifier-box.js.map +1 -1
  408. package/dist/mcp/server.d.ts +94 -15
  409. package/dist/mcp/server.js +402 -79
  410. package/dist/mcp/server.js.map +1 -1
  411. package/dist/ports/clock.d.ts +12 -0
  412. package/dist/ports/clock.js +10 -0
  413. package/dist/ports/clock.js.map +1 -0
  414. package/dist/ports/code-exemplar-store.d.ts +13 -13
  415. package/dist/ports/entity-store.d.ts +5 -1
  416. package/dist/ports/fact-store.d.ts +0 -0
  417. package/dist/ports/fact-store.js +0 -0
  418. package/dist/ports/fact-store.js.map +1 -1
  419. package/dist/ports/learner-store.d.ts +80 -0
  420. package/dist/ports/learner-store.js +19 -0
  421. package/dist/ports/learner-store.js.map +1 -0
  422. package/dist/ports/outcome.d.ts +85 -0
  423. package/dist/ports/outcome.js +11 -0
  424. package/dist/ports/outcome.js.map +1 -0
  425. package/dist/ports/session-store.d.ts +20 -20
  426. package/dist/ports/session-store.js +5 -0
  427. package/dist/ports/session-store.js.map +1 -1
  428. package/dist/ports/signal-store.d.ts +12 -8
  429. package/dist/ports/spawn-child.d.ts +14 -0
  430. package/dist/ports/spawn-child.js +10 -0
  431. package/dist/ports/spawn-child.js.map +1 -0
  432. package/dist/ports/storage.d.ts +6 -0
  433. package/dist/ports/transcript-adapter.d.ts +11 -0
  434. package/dist/ports/wiki-writer.d.ts +19 -0
  435. package/dist/ports/wiki-writer.js +12 -0
  436. package/dist/ports/wiki-writer.js.map +1 -0
  437. package/dist/ports/workstream-store.d.ts +20 -12
  438. package/dist/shared/net.d.ts +3 -0
  439. package/dist/shared/net.js +4 -0
  440. package/dist/shared/net.js.map +1 -0
  441. package/dist/shared/types.d.ts +55 -0
  442. package/dist/shared/types.js +4 -1
  443. package/dist/shared/types.js.map +1 -1
  444. package/dist/shared/version.d.ts +9 -0
  445. package/dist/shared/version.js +11 -0
  446. package/dist/shared/version.js.map +1 -0
  447. package/dist/ui/assets/index-D6F3xAis.js +11 -0
  448. package/dist/ui/index.html +1 -1
  449. package/migrations/029_project_scope.sql +21 -0
  450. package/migrations/032_session_derivables.sql +11 -0
  451. package/migrations/033_actions_kind_check.sql +58 -0
  452. package/migrations/034_tenancy_teams_and_stamps.sql +40 -0
  453. package/migrations/035_tenancy_entity_rekey.sql +75 -0
  454. package/migrations/036_tenant_name_uniqueness.sql +59 -0
  455. package/migrations/037_sessions_covering_index.sql +25 -0
  456. package/migrations/038_sources_muse.sql +33 -0
  457. package/migrations/039_learner_evidence.sql +51 -0
  458. package/migrations/pg/030_project_scope.sql +23 -0
  459. package/migrations/pg/031_widen_session_edges_kind.sql +11 -0
  460. package/migrations/pg/032_session_derivables.sql +17 -0
  461. package/migrations/pg/033_actions_kind_check.sql +17 -0
  462. package/migrations/pg/034_tenancy.sql +77 -0
  463. package/migrations/pg/035_tenant_name_uniqueness.sql +15 -0
  464. package/migrations/pg/036_sources_muse.sql +12 -0
  465. package/migrations/pg/037_learner_evidence.sql +55 -0
  466. package/nlm/index.js +258 -59
  467. package/package.json +10 -5
  468. package/plugin/.codex-plugin/plugin.json +1 -1
  469. package/plugin/scripts/prompt-recall-hook.mjs +256 -58
  470. package/plugin/scripts/session-start-hook.mjs +283 -55
  471. package/plugin/scripts/stop-hook.mjs +199 -38
  472. package/dist/hook/subagent-start-hook.d.ts +0 -28
  473. package/dist/hook/subagent-start-hook.js +0 -81
  474. package/dist/hook/subagent-start-hook.js.map +0 -1
  475. package/dist/ui/assets/index-CMpQkbQy.js +0 -11
@@ -11,13 +11,15 @@
11
11
  * UserPromptSubmit. Fail-open by design: any error yields a clean exit
12
12
  * with no output, so the hook can never block Claude Code shutdown.
13
13
  */
14
- import { pathToFileURL } from "node:url";
15
14
  import { clearSurfaced } from "../core/hook/memo.js";
15
+ import { DEFAULT_TEAM_ID } from "../core/tenancy/default-team.js";
16
16
  import { clearCited } from "../core/hook/cite-memo.js";
17
- import { readStdin, hookModeFromEnv, appendHookEvent } from "./hook-helpers.js";
17
+ import { readStdin, hookModeFromEnv, appendHookEvent, isMainModule } from "./hook-helpers.js";
18
18
  export function runSessionEnd(conversationId) {
19
- const surfacedCleared = clearSurfaced(conversationId);
20
- const citedCleared = clearCited(conversationId);
19
+ // Client-side hook composition root: no per-tenant CLI/hook concept exists
20
+ // today, so DEFAULT_TEAM_ID is this surface's real identity, not a placeholder.
21
+ const surfacedCleared = clearSurfaced(DEFAULT_TEAM_ID, conversationId);
22
+ const citedCleared = clearCited(DEFAULT_TEAM_ID, conversationId);
21
23
  return { conversationId, cleared: surfacedCleared || citedCleared };
22
24
  }
23
25
  function logSessionEnd(result) {
@@ -40,7 +42,7 @@ async function main() {
40
42
  // Fail open — never block Claude Code shutdown.
41
43
  }
42
44
  }
43
- if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
45
+ if (isMainModule(import.meta.url, process.argv[1])) {
44
46
  void main();
45
47
  }
46
48
  //# sourceMappingURL=session-end-hook.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"session-end-hook.js","sourceRoot":"","sources":["../../src/hook/session-end-hook.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAOhF,MAAM,UAAU,aAAa,CAAC,cAAsB;IAClD,MAAM,eAAe,GAAG,aAAa,CAAC,cAAc,CAAC,CAAC;IACtD,MAAM,YAAY,GAAG,UAAU,CAAC,cAAc,CAAC,CAAC;IAChD,OAA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
14
14
  import { type RecallHitInput } from "../core/hook/select.js";
15
+ import { type RecallOutcome } from "./recall-over-http.js";
15
16
  export type HookMode = "shadow" | "live";
17
+ export interface SessionStartRecall {
18
+ readonly hits: ReadonlyArray<RecallHitInput>;
19
+ readonly outcome: RecallOutcome;
20
+ }
16
21
  export interface SessionStartInput {
17
22
  readonly conversationId: string;
18
23
  readonly query: string;
19
24
  }
20
25
  export interface RunSessionStartDeps {
21
26
  readonly mode: HookMode;
22
- readonly recall: (query: string, conversationId?: string) => Promise<ReadonlyArray<RecallHitInput>>;
27
+ readonly recall: (query: string, conversationId?: string) => Promise<SessionStartRecall>;
23
28
  }
24
29
  /** Orchestration. Returns the text to emit on stdout ("" for nothing). */
25
30
  export declare function runHook(input: SessionStartInput, deps: RunSessionStartDeps): Promise<string>;
26
31
  /** Join the failure-mode block (if any) above the session-recall block. */
27
32
  export declare function composeSessionStartOutput(failureModeBlock: string, recallBlock: string): string;
33
+ /**
34
+ * Branch name plus recent commit subjects. A bare directory name is often a
35
+ * single word ("nlm-memory"), which the recall query extractor rejects as too
36
+ * short, so SessionStart surfaced nothing for most repos.
37
+ */
38
+ export declare function readGitContext(workingDirectory: string): string;
39
+ /** Derive a best-effort query from SessionStart payload fields. */
40
+ export declare function buildQuery(workingDirectory: string, projectName: string, gitContext: string): string;
@@ -11,49 +11,59 @@
11
11
  * Mirrors prompt-recall-hook.ts shape exactly: same pointer-block format, same
12
12
  * memo writes, same NLM_HOOK_MODE semantics.
13
13
  */
14
- import { pathToFileURL } from "node:url";
14
+ import { execFileSync } from "node:child_process";
15
15
  import { appendHookLog } from "../core/hook/hook-log.js";
16
16
  import { loadSurfaced, recordSurfaced } from "../core/hook/memo.js";
17
+ import { DEFAULT_TEAM_ID } from "../core/tenancy/default-team.js";
17
18
  import { formatPointerBlock } from "../core/hook/pointer-block.js";
18
19
  import { selectHits } from "../core/hook/select.js";
19
20
  import { autoloadEnv } from "../llm/env-autoload.js";
20
21
  import { hookAuthHeaders } from "./hook-auth.js";
21
22
  import { parseScoreFloor, parseRelativeFloor } from "./score-floor.js";
22
23
  import { recallOverHttp } from "./recall-over-http.js";
23
- import { readStdin, hookModeFromEnv, fetchWithTimeout } from "./hook-helpers.js";
24
+ import { readStdin, hookModeFromEnv, fetchWithTimeout, isMainModule } from "./hook-helpers.js";
25
+ import { DEFAULT_NLM_PORT } from "../shared/net.js";
24
26
  // This hook recalls in hybrid mode, whose matchScore is normalized to 0..1
25
27
  // (mergeHybrid in recall-service.ts), so the default absolute floor is 0.
26
28
  // NLM_RECALL_SCORE_FLOOR is shared with the keyword-mode prompt hook; the
27
29
  // calibrated keyword floor (2.0, raw BM25) would deny-all here on the 0..1
28
30
  // scale, so it is opt-in only. parseScoreFloor guards a bad env value.
29
- const SCORE_THRESHOLD = parseScoreFloor(process.env["NLM_RECALL_SCORE_FLOOR"]);
31
+ // Lazy, not module-scope: autoloadEnv() runs inside main(), after imports are
32
+ // evaluated, so an eager read silently ignores ~/.nlm/.env. See recallTimeoutMs
33
+ // in recall-over-http.ts.
34
+ const scoreThreshold = () => parseScoreFloor(process.env["NLM_RECALL_SCORE_FLOOR"]);
30
35
  // The relative floor IS scale-invariant (ratio to the fire median), so it
31
36
  // applies cleanly to this hybrid path too — parity with the per-message hook.
32
- const RELATIVE_FLOOR = parseRelativeFloor(process.env["NLM_RECALL_REL_FLOOR"], 0.9);
37
+ const relativeFloor = () => parseRelativeFloor(process.env["NLM_RECALL_REL_FLOOR"], 0.9);
33
38
  const PER_FIRE_CAP = 3;
34
39
  const PER_CONVERSATION_CAP = 10;
35
40
  const RECALL_TIMEOUT_MS = 2000;
36
41
  /** Orchestration. Returns the text to emit on stdout ("" for nothing). */
37
42
  export async function runHook(input, deps) {
38
43
  let hits = [];
44
+ let recallOutcome = "unreachable";
39
45
  try {
40
- hits = await deps.recall(input.query, input.conversationId);
46
+ const fetched = await deps.recall(input.query, input.conversationId);
47
+ hits = fetched.hits;
48
+ recallOutcome = fetched.outcome;
41
49
  }
42
50
  catch {
43
51
  hits = [];
44
52
  }
45
- const surfaced = loadSurfaced(input.conversationId);
53
+ // Client-side hook composition root: no per-tenant CLI/hook concept exists
54
+ // today, so DEFAULT_TEAM_ID is this surface's real identity, not a placeholder.
55
+ const surfaced = loadSurfaced(DEFAULT_TEAM_ID, input.conversationId);
46
56
  const selected = selectHits({
47
57
  hits,
48
58
  surfaced,
49
- scoreThreshold: SCORE_THRESHOLD,
50
- relativeFloor: RELATIVE_FLOOR,
59
+ scoreThreshold: scoreThreshold(),
60
+ relativeFloor: relativeFloor(),
51
61
  perFireCap: PER_FIRE_CAP,
52
62
  perConversationCap: PER_CONVERSATION_CAP,
53
63
  });
54
64
  const block = formatPointerBlock(selected);
55
65
  const estTokens = Math.ceil(block.length / 4);
56
- appendHookLog({
66
+ appendHookLog(DEFAULT_TEAM_ID, {
57
67
  ts: new Date().toISOString(),
58
68
  conversationId: input.conversationId,
59
69
  promptPreview: input.query,
@@ -62,9 +72,10 @@ export async function runHook(input, deps) {
62
72
  wouldInject: selected.map((h) => h.id),
63
73
  estTokens,
64
74
  mode: deps.mode,
75
+ recallOutcome,
65
76
  });
66
77
  if (deps.mode === "live" && selected.length > 0) {
67
- recordSurfaced(input.conversationId, selected.map((h) => h.id));
78
+ recordSurfaced(DEFAULT_TEAM_ID, input.conversationId, selected.map((h) => h.id));
68
79
  return block;
69
80
  }
70
81
  return "";
@@ -76,7 +87,7 @@ export function composeSessionStartOutput(failureModeBlock, recallBlock) {
76
87
  async function fetchFailureModeBlock(repo) {
77
88
  if (!repo)
78
89
  return "";
79
- const portValue = process.env["NLM_PORT"] ?? "3940";
90
+ const portValue = process.env["NLM_PORT"] ?? DEFAULT_NLM_PORT;
80
91
  const url = `http://127.0.0.1:${portValue}/api/signals/failure-modes?repo=${encodeURIComponent(repo)}`;
81
92
  try {
82
93
  const res = await fetchWithTimeout(url, {
@@ -91,10 +102,37 @@ async function fetchFailureModeBlock(repo) {
91
102
  return "";
92
103
  }
93
104
  }
105
+ const GIT_TIMEOUT_MS = 300;
106
+ const RECENT_COMMITS = 3;
107
+ function git(cwd, args) {
108
+ try {
109
+ return execFileSync("git", ["-C", cwd, ...args], {
110
+ encoding: "utf8",
111
+ timeout: GIT_TIMEOUT_MS,
112
+ stdio: ["ignore", "pipe", "ignore"],
113
+ }).trim();
114
+ }
115
+ catch {
116
+ return "";
117
+ }
118
+ }
119
+ /**
120
+ * Branch name plus recent commit subjects. A bare directory name is often a
121
+ * single word ("nlm-memory"), which the recall query extractor rejects as too
122
+ * short, so SessionStart surfaced nothing for most repos.
123
+ */
124
+ export function readGitContext(workingDirectory) {
125
+ if (!workingDirectory)
126
+ return "";
127
+ const branch = git(workingDirectory, ["rev-parse", "--abbrev-ref", "HEAD"]);
128
+ const subjects = git(workingDirectory, ["log", `-${RECENT_COMMITS}`, "--format=%s"]);
129
+ const branchWords = branch === "HEAD" ? "" : branch.replace(/[/_-]+/g, " ");
130
+ return [branchWords, subjects.replace(/\n/g, " ")].filter(Boolean).join(" ");
131
+ }
94
132
  /** Derive a best-effort query from SessionStart payload fields. */
95
- function buildQuery(workingDirectory, projectName) {
133
+ export function buildQuery(workingDirectory, projectName, gitContext) {
96
134
  const dirTail = workingDirectory.split("/").filter(Boolean).at(-1) ?? "";
97
- const parts = [dirTail, projectName].filter(Boolean);
135
+ const parts = [dirTail, projectName, gitContext].filter(Boolean);
98
136
  return parts.join(" ").trim() || "session start";
99
137
  }
100
138
  async function main() {
@@ -109,12 +147,15 @@ async function main() {
109
147
  ? payload.working_directory
110
148
  : "";
111
149
  const projectName = typeof payload.project_name === "string" ? payload.project_name : "";
112
- const query = buildQuery(workingDirectory, projectName);
150
+ const query = buildQuery(workingDirectory, projectName, readGitContext(workingDirectory));
113
151
  const mode = hookModeFromEnv();
114
152
  const [out, failureModes] = await Promise.all([
115
153
  runHook({ conversationId, query }, {
116
154
  mode,
117
- recall: async (q, cid) => (await recallOverHttp(q, "claude-code", cid === "unknown" ? undefined : cid, "hybrid")).hits,
155
+ recall: async (q, cid) => {
156
+ const r = await recallOverHttp(q, "claude-code", cid === "unknown" ? undefined : cid, "hybrid", "session-start-hook");
157
+ return { hits: r.hits, outcome: r.outcome };
158
+ },
118
159
  }),
119
160
  mode === "live" ? fetchFailureModeBlock(workingDirectory) : Promise.resolve(""),
120
161
  ]);
@@ -126,7 +167,7 @@ async function main() {
126
167
  // Fail open — never block or fail a session start.
127
168
  }
128
169
  }
129
- if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
170
+ if (isMainModule(import.meta.url, process.argv[1])) {
130
171
  void main();
131
172
  }
132
173
  //# sourceMappingURL=session-start-hook.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"session-start-hook.js","sourceRoot":"","sources":["../../src/hook/session-start-hook.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,UAAU,EAAuB,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAEjF,2EAA2E;AAC3E,0EAA0E;AAC1E,0EAA0E;AAC1E,2EAA2E;AAC3E,uEAAuE;AACvE,MAAM,eAAe,GAAG,eAAe,CAAC,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAA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B,EAAE,WAAW,EAAE,cAAc,CAAC,gBAAgB,CAAC,CAAC,CAAC;QAC1F,MAAM,IAAI,GAAa,eAAe,EAAE,CAAC;QACzC,MAAM,CAAC,GAAG,EAAE,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YAC5C,OAAO,CACL,EAAE,cAAc,EAAE,KAAK,EAAE,EACzB;gBACE,IAAI;gBACJ,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE;oBACvB,MAAM,CAAC,GAAG,MAAM,cAAc,CAC5B,CAAC,EACD,aAAa,EACb,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,EACnC,QAAQ,EACR,oBAAoB,CACrB,CAAC;oBACF,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;gBAC9C,CAAC;aACF,CACF;YACD,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,qBAAqB,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;SAChF,CAAC,CAAC;QACH,MAAM,QAAQ,GAAG,yBAAyB,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC;QAC9D,IAAI,QAAQ;YAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC/C,CAAC;IAAC,MAAM,CAAC;QACP,mDAAmD;IACrD,CAAC;AACH,CAAC;AAED,IAAI,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACnD,KAAK,IAAI,EAAE,CAAC;AACd,CAAC"}
@@ -11,16 +11,17 @@
11
11
  * Fail-open by design: any error yields a clean exit with no output. The
12
12
  * Stop hook can never block Claude Code's response.
13
13
  */
14
- import { pathToFileURL } from "node:url";
15
14
  import { detectCitations, } from "../core/hook/citation-detect.js";
16
15
  import { detectMisses } from "../core/hook/miss-detect.js";
17
16
  import { loadSurfaced } from "../core/hook/memo.js";
18
17
  import { loadCited, recordCited } from "../core/hook/cite-memo.js";
19
18
  import { appendMisses } from "../core/recall/miss-log.js";
19
+ import { DEFAULT_TEAM_ID } from "../core/tenancy/default-team.js";
20
20
  import { readAllAssistantTurns, } from "../core/hook/transcript.js";
21
21
  import { autoloadEnv } from "../llm/env-autoload.js";
22
22
  import { hookAuthHeaders } from "./hook-auth.js";
23
- import { readStdin, fetchWithTimeout, hookModeFromEnv, appendHookEvent } from "./hook-helpers.js";
23
+ import { readStdin, fetchWithTimeout, hookModeFromEnv, appendHookEvent, isMainModule } from "./hook-helpers.js";
24
+ import { DEFAULT_NLM_PORT } from "../shared/net.js";
24
25
  const RESPONSE_PREVIEW_CHARS = 200;
25
26
  const POST_TIMEOUT_MS = 1500;
26
27
  export async function runStopHook(input, deps) {
@@ -35,7 +36,9 @@ export async function runStopHook(input, deps) {
35
36
  skipped: true,
36
37
  };
37
38
  }
38
- const surfaced = loadSurfaced(input.conversationId);
39
+ // Client-side hook composition root: no per-tenant CLI/hook concept exists
40
+ // today, so DEFAULT_TEAM_ID is this surface's real identity, not a placeholder.
41
+ const surfaced = loadSurfaced(DEFAULT_TEAM_ID, input.conversationId);
39
42
  if (surfaced.size === 0) {
40
43
  return {
41
44
  conversationId: input.conversationId,
@@ -69,7 +72,7 @@ export async function runStopHook(input, deps) {
69
72
  toolUses: allToolUses,
70
73
  surfacedIds: surfaced,
71
74
  });
72
- const alreadyCited = loadCited(input.conversationId);
75
+ const alreadyCited = loadCited(DEFAULT_TEAM_ID, input.conversationId);
73
76
  const fresh = detected.filter((c) => !alreadyCited.has(c.id));
74
77
  // Spec E: passive miss detection. Any session the agent explicitly
75
78
  // fetched via get_session / cite_session that was NOT in the surfaced
@@ -78,7 +81,7 @@ export async function runStopHook(input, deps) {
78
81
  // the Stop hook return.
79
82
  const misses = detectMisses({ toolUses: allToolUses, surfacedIds: surfaced });
80
83
  if (misses.length > 0) {
81
- void appendMisses(misses.map((m) => ({
84
+ void appendMisses(DEFAULT_TEAM_ID, misses.map((m) => ({
82
85
  conversationId: input.conversationId,
83
86
  missedId: m.id,
84
87
  kind: m.kind,
@@ -92,7 +95,7 @@ export async function runStopHook(input, deps) {
92
95
  const preview = lastText.slice(0, RESPONSE_PREVIEW_CHARS);
93
96
  await Promise.allSettled(fresh.map((c) => deps.postCitation(input.conversationId, c.id, c.kind, preview)));
94
97
  if (fresh.length > 0) {
95
- recordCited(input.conversationId, fresh.map((c) => c.id));
98
+ recordCited(DEFAULT_TEAM_ID, input.conversationId, fresh.map((c) => c.id));
96
99
  }
97
100
  return {
98
101
  conversationId: input.conversationId,
@@ -115,7 +118,7 @@ function logStopResult(result) {
115
118
  });
116
119
  }
117
120
  async function postCitationOverHttp(conversationId, citedId, kind, responsePreview) {
118
- const port = process.env["NLM_PORT"] ?? "3940";
121
+ const port = process.env["NLM_PORT"] ?? DEFAULT_NLM_PORT;
119
122
  const url = `http://127.0.0.1:${port}/api/recall/cite-event`;
120
123
  await fetchWithTimeout(url, {
121
124
  method: "POST",
@@ -143,7 +146,7 @@ async function main() {
143
146
  // Fail open — never block Claude Code's response.
144
147
  }
145
148
  }
146
- if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
149
+ if (isMainModule(import.meta.url, process.argv[1])) {
147
150
  void main();
148
151
  }
149
152
  //# sourceMappingURL=stop-hook.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"stop-hook.js","sourceRoot":"","sources":["../../src/hook/stop-hook.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EACL,eAAe,GAEhB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE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MAAM,CAAC,CAAC;IACxB,CAAC;IAAC,MAAM,CAAC;QACP,kDAAkD;IACpD,CAAC;AACH,CAAC;AAED,IAAI,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACnD,KAAK,IAAI,EAAE,CAAC;AACd,CAAC"}
@@ -19,8 +19,10 @@
19
19
  */
20
20
  import { Hono } from "hono";
21
21
  import type { RecallService } from "../core/recall/recall-service.js";
22
+ import { type UpdateCheckDeps } from "../core/update-check/check.js";
22
23
  import type { FactRecallService } from "../core/recall-facts/fact-recall-service.js";
23
24
  import type { FactStore } from "../ports/fact-store.js";
25
+ import type { LearnerStore } from "../ports/learner-store.js";
24
26
  import { ClassifierBox } from "../llm/classifier-box.js";
25
27
  import { SourceRegistry, PgSourceRegistry } from "../core/sources/source-registry.js";
26
28
  import { ProviderRegistry, PgProviderRegistry } from "../core/providers/provider-registry.js";
@@ -32,6 +34,9 @@ import type { McpDeps } from "../mcp/server.js";
32
34
  import type { SignalStore } from "../ports/signal-store.js";
33
35
  import type { CodeExemplarStore } from "../ports/code-exemplar-store.js";
34
36
  import type { CodeEmbedder } from "../ports/code-embedder.js";
37
+ import { type SessionScopeReader } from "../core/signals/stamp-scope.js";
38
+ import type { TeamTokenStorePort } from "../core/tenancy/team-token-store.js";
39
+ import type { JobSupervisor } from "../core/jobs/job-supervisor.js";
35
40
  export interface HttpDeps {
36
41
  readonly recall: RecallService;
37
42
  readonly store: SessionStore;
@@ -54,6 +59,11 @@ export interface HttpDeps {
54
59
  readonly sources?: SourceRegistry | PgSourceRegistry;
55
60
  /** Providers registry — exposes /api/providers CRUD for the desktop UI. */
56
61
  readonly providers?: ProviderRegistry | PgProviderRegistry;
62
+ /** Wire to enable GET /api/learner/by-session/:id. When omitted, the route 404s. */
63
+ readonly learnerRecall?: {
64
+ readonly learners: LearnerStore;
65
+ readonly sessions: Pick<SessionStore, "getWorkstreamIds">;
66
+ };
57
67
  /** Wire to enable POST /api/ingest. When omitted, push ingest is disabled. */
58
68
  readonly ingest?: IngestDeps;
59
69
  /** Static embedder info — embeddings are always Ollama in this build (DeepSeek has no /embed). */
@@ -65,18 +75,39 @@ export interface HttpDeps {
65
75
  /** Directory containing the built UI (dist/ui). When set, /ui/* serves the SPA. */
66
76
  readonly uiDist?: string;
67
77
  /**
68
- * When provided, POST /mcp is mounted and token-gated with NLM_MCP_TOKEN.
69
- * Omitting this keeps the route absent — no auth surface, no risk.
78
+ * When provided, POST /mcp is mounted and token-gated via team_tokens
79
+ * lookup (program spec §3 M3). Omitting this keeps the route absent — no
80
+ * auth surface, no risk.
70
81
  */
71
82
  readonly mcpDeps?: McpDeps;
83
+ /**
84
+ * Bearer-token -> team resolution (M3). Wired whenever the daemon's
85
+ * Storage exposes it (always, in practice — both SqliteStorage and
86
+ * PgStorage construct one). Optional here only so unit tests that build a
87
+ * bare-bones HttpDeps without a real Storage still compile; when absent,
88
+ * the general gate falls back to pre-M3 local-mode behavior (DEFAULT_TEAM_ID
89
+ * on loopback) and /mcp refuses to mount.
90
+ */
91
+ readonly teamTokens?: TeamTokenStorePort;
72
92
  /** Signal store - wire to enable POST /api/signal + GET /api/signals/*. */
73
93
  readonly signalStore?: SignalStore;
74
94
  /** Per-install scope stamped on every ingested signal. */
75
95
  readonly installScope?: string;
96
+ /** Used to inherit scope from a session when the signal carries a session_id. */
97
+ readonly sessionScopeReader?: SessionScopeReader;
76
98
  /** Code exemplar store — wire to enable POST /api/exemplar + GET /api/recall-code. */
77
99
  readonly exemplarStore?: CodeExemplarStore;
78
100
  /** Optional code embedder for semantic recall-code queries. */
79
101
  readonly codeEmbedder?: CodeEmbedder;
102
+ /** Test-only override for /api/health's update-check cache read (defaults to ~/.nlm/update-check.json via NLM_UPDATE_CHECK_CACHE). */
103
+ readonly updateCheckDeps?: Pick<UpdateCheckDeps, "cachePath" | "now">;
104
+ /**
105
+ * Wire to enable POST/DELETE /api/jobs/reprocess + the `job` block on
106
+ * GET /api/health. Narrowed to the three methods the routes need so unit
107
+ * tests can pass a plain fake instead of a real JobSupervisor (which
108
+ * would otherwise require real spawnChild/clock ports).
109
+ */
110
+ readonly jobSupervisor?: Pick<JobSupervisor, "start" | "stop" | "snapshot">;
80
111
  }
81
112
  export declare function isLoopbackHost(host: string | undefined, port: number): boolean;
82
113
  export declare function isLoopbackOrigin(origin: string | undefined, port: number): boolean;
@@ -84,4 +115,17 @@ export declare function parseAllowedOrigins(raw: string): {
84
115
  origins: Set<string>;
85
116
  hosts: Set<string>;
86
117
  };
87
- export declare function createApp(deps: HttpDeps): Hono;
118
+ /**
119
+ * Hono context Variables (program spec §3 M3): `installLocalOnlyMiddleware`
120
+ * resolves the request's tenant exactly once (host/origin checks, then
121
+ * hosted/local/cookie/token auth) and stashes it via `c.set("tenantId", …)`;
122
+ * every downstream route handler reads it back via `c.get("tenantId")`
123
+ * instead of the composition-time `DEFAULT_TEAM_ID` constant M2 used as a
124
+ * placeholder.
125
+ */
126
+ export interface AppEnv {
127
+ readonly Variables: {
128
+ tenantId: string;
129
+ };
130
+ }
131
+ export declare function createApp(deps: HttpDeps): Hono<AppEnv>;