nlm-memory 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. package/README.md +72 -34
  2. package/dist/cli/nlm.js +2 -1
  3. package/dist/cli/nlm.js.map +1 -1
  4. package/dist/http/app.js +2 -1
  5. package/dist/http/app.js.map +1 -1
  6. package/dist/mcp/server.js +20 -1
  7. package/dist/mcp/server.js.map +1 -1
  8. package/dist/ui/assets/{index-C8cpwbYJ.css → index-Beo8psd-.css} +1 -1
  9. package/dist/ui/assets/{index-CB50QnL-.js → index-CSPTTeeM.js} +8 -8
  10. package/dist/ui/index.html +2 -2
  11. package/package.json +26 -1
  12. package/.agents/plugins/marketplace.json +0 -20
  13. package/.github/workflows/ci.yml +0 -30
  14. package/docs/methodology/re-derivation-rate.md +0 -112
  15. package/docs/methodology/useful-hit-rate.md +0 -79
  16. package/docs/plans/2026-05-20-fts5-lexical-recall.md +0 -1088
  17. package/docs/plans/2026-05-20-recall-daemon-wedge-fix.md +0 -662
  18. package/docs/plans/2026-05-20-recall-hook-design.md +0 -131
  19. package/docs/plans/2026-05-20-recall-hook-implementation.md +0 -1222
  20. package/docs/plans/desktop-product.md +0 -69
  21. package/docs/plans/factstore-design.md +0 -236
  22. package/logs/CHANGELOG/CHANGELOG-2026.md +0 -1575
  23. package/logs/CHANGELOG/CHANGELOG.md +0 -209
  24. package/migrations/000_initial_schema.sql +0 -174
  25. package/migrations/001_entity_type_rename.sql +0 -17
  26. package/migrations/002_adapter_state_extend.sql +0 -12
  27. package/migrations/003_session_embeddings.sql +0 -11
  28. package/migrations/004_facts.sql +0 -46
  29. package/migrations/005_sources.sql +0 -31
  30. package/migrations/006_providers.sql +0 -33
  31. package/migrations/007_source_tokens.sql +0 -17
  32. package/migrations/008_fts_rebuild.sql +0 -9
  33. package/migrations/009_session_embedding_chunks.sql +0 -46
  34. package/migrations/010_sources_opencode.sql +0 -30
  35. package/migrations/011_sources_hermes_agent.sql +0 -30
  36. package/migrations/012_sources_aider.sql +0 -30
  37. package/migrations/013_adapter_state_failure_count.sql +0 -12
  38. package/migrations/014_sources_cursor.sql +0 -30
  39. package/migrations/015_sources_windsurf.sql +0 -30
  40. package/plugin-hermes-agent/README.md +0 -49
  41. package/plugin-hermes-agent/__init__.py +0 -75
  42. package/plugin-hermes-agent/plugin.yaml +0 -15
  43. package/scripts/backfill-citations.mjs +0 -0
  44. package/scripts/build-codex-plugin.mjs +0 -61
  45. package/scripts/deepseek-probe.mjs +0 -67
  46. package/scripts/extract-triples.mjs +0 -207
  47. package/scripts/longmemeval/embedding-cache.ts +0 -77
  48. package/scripts/longmemeval/fetch-dataset.sh +0 -25
  49. package/scripts/longmemeval/run-harness.ts +0 -315
  50. package/scripts/longmemeval/scorer.ts +0 -99
  51. package/scripts/longmemeval/tsconfig.json +0 -9
  52. package/scripts/longmemeval/types.ts +0 -35
  53. package/scripts/nlm-daily-digest.py +0 -239
  54. package/scripts/nlm-daily-digest.sh +0 -28
  55. package/src/cli/classify-parity.ts +0 -257
  56. package/src/cli/launchctl-helpers.ts +0 -49
  57. package/src/cli/nlm.ts +0 -1078
  58. package/src/core/actions/actions-log.ts +0 -118
  59. package/src/core/actions/overlay.ts +0 -117
  60. package/src/core/adapters/aider.ts +0 -205
  61. package/src/core/adapters/claude-code.ts +0 -293
  62. package/src/core/adapters/common.ts +0 -54
  63. package/src/core/adapters/cursor.ts +0 -486
  64. package/src/core/adapters/from-source.ts +0 -67
  65. package/src/core/adapters/hermes-agent.ts +0 -240
  66. package/src/core/adapters/hermes.ts +0 -277
  67. package/src/core/adapters/jsonl-generic.ts +0 -208
  68. package/src/core/adapters/opencode.ts +0 -281
  69. package/src/core/adapters/pi.ts +0 -264
  70. package/src/core/adapters/windsurf.ts +0 -386
  71. package/src/core/classifier/prompt.ts +0 -200
  72. package/src/core/dataset/build-dataset.ts +0 -463
  73. package/src/core/embedding/chunk-body.ts +0 -76
  74. package/src/core/embedding/embed-backfill.ts +0 -210
  75. package/src/core/embedding/embed-normalize.ts +0 -135
  76. package/src/core/facts/backfill-facts.ts +0 -254
  77. package/src/core/facts/extract-facts.ts +0 -50
  78. package/src/core/hook/citation-detect.ts +0 -124
  79. package/src/core/hook/cite-memo.ts +0 -68
  80. package/src/core/hook/claude-settings.ts +0 -187
  81. package/src/core/hook/gate.ts +0 -25
  82. package/src/core/hook/hook-log.ts +0 -41
  83. package/src/core/hook/memo-sweep.ts +0 -164
  84. package/src/core/hook/memo.ts +0 -67
  85. package/src/core/hook/pointer-block.ts +0 -26
  86. package/src/core/hook/select.ts +0 -32
  87. package/src/core/hook/transcript.ts +0 -121
  88. package/src/core/ingest/ingest-session.ts +0 -111
  89. package/src/core/providers/provider-models.ts +0 -100
  90. package/src/core/providers/provider-registry.ts +0 -196
  91. package/src/core/recall/citation-log.ts +0 -108
  92. package/src/core/recall/filter.ts +0 -27
  93. package/src/core/recall/index.ts +0 -6
  94. package/src/core/recall/match-fields.ts +0 -40
  95. package/src/core/recall/query-log.ts +0 -149
  96. package/src/core/recall/query-shape.ts +0 -66
  97. package/src/core/recall/recall-service.ts +0 -320
  98. package/src/core/recall/recent-log.ts +0 -59
  99. package/src/core/recall/tokenize.ts +0 -18
  100. package/src/core/recall/useful-scan.ts +0 -336
  101. package/src/core/recall-facts/fact-query-log.ts +0 -150
  102. package/src/core/recall-facts/fact-recall-service.ts +0 -327
  103. package/src/core/scheduler/scan-once.ts +0 -142
  104. package/src/core/scheduler/scheduler.ts +0 -225
  105. package/src/core/sources/source-registry.ts +0 -278
  106. package/src/core/storage/db-restore.ts +0 -133
  107. package/src/core/storage/live-status.ts +0 -45
  108. package/src/core/storage/migrate.ts +0 -72
  109. package/src/core/storage/sqlite-fact-store.ts +0 -304
  110. package/src/core/storage/sqlite-session-store.ts +0 -810
  111. package/src/hook/hook-auth.ts +0 -18
  112. package/src/hook/prompt-recall-hook.ts +0 -180
  113. package/src/hook/session-end-hook.ts +0 -81
  114. package/src/hook/session-start-hook.ts +0 -168
  115. package/src/hook/stop-hook.ts +0 -239
  116. package/src/http/app.ts +0 -1215
  117. package/src/install/claude-code.ts +0 -128
  118. package/src/install/codex.ts +0 -367
  119. package/src/install/cursor.ts +0 -68
  120. package/src/install/hermes-agent.ts +0 -76
  121. package/src/install/hermes.ts +0 -78
  122. package/src/install/nlm-dir-perms.ts +0 -55
  123. package/src/install/ollama.ts +0 -284
  124. package/src/install/setup.ts +0 -489
  125. package/src/install/windsurf.ts +0 -68
  126. package/src/llm/classifier-box.ts +0 -64
  127. package/src/llm/deepseek-client.ts +0 -150
  128. package/src/llm/env-autoload.ts +0 -55
  129. package/src/llm/ollama-client.ts +0 -189
  130. package/src/mcp/server.ts +0 -534
  131. package/src/ports/fact-store.ts +0 -102
  132. package/src/ports/llm-client.ts +0 -52
  133. package/src/ports/logger.ts +0 -16
  134. package/src/ports/session-store.ts +0 -45
  135. package/src/ports/transcript-adapter.ts +0 -55
  136. package/src/shared/types.ts +0 -149
  137. package/src/ui/App.tsx +0 -58
  138. package/src/ui/components/PromoteOpenButton.tsx +0 -65
  139. package/src/ui/components/SessionDrawer.tsx +0 -199
  140. package/src/ui/components/SideNav.tsx +0 -162
  141. package/src/ui/components/Skeleton.tsx +0 -107
  142. package/src/ui/index.html +0 -13
  143. package/src/ui/lib/actions.ts +0 -30
  144. package/src/ui/lib/api.ts +0 -92
  145. package/src/ui/lib/dataset.ts +0 -141
  146. package/src/ui/lib/registries.ts +0 -155
  147. package/src/ui/lib/view-settings.ts +0 -41
  148. package/src/ui/main.tsx +0 -15
  149. package/src/ui/pages/Live.tsx +0 -229
  150. package/src/ui/pages/Pulse.tsx +0 -415
  151. package/src/ui/pages/Recall.tsx +0 -190
  152. package/src/ui/pages/River.tsx +0 -354
  153. package/src/ui/pages/Search.tsx +0 -386
  154. package/src/ui/pages/Stub.tsx +0 -9
  155. package/src/ui/pages/Thread.tsx +0 -473
  156. package/src/ui/pages/settings/Classifier.tsx +0 -227
  157. package/src/ui/pages/settings/Data.tsx +0 -190
  158. package/src/ui/pages/settings/Index.tsx +0 -65
  159. package/src/ui/pages/settings/Labels.tsx +0 -224
  160. package/src/ui/pages/settings/Providers.tsx +0 -305
  161. package/src/ui/pages/settings/SettingsSubnav.tsx +0 -28
  162. package/src/ui/pages/settings/Sources.tsx +0 -326
  163. package/src/ui/pages/settings/Views.tsx +0 -96
  164. package/src/ui/styles.css +0 -1890
  165. package/src/ui/tsconfig.json +0 -21
  166. package/src/ui/vite.config.ts +0 -19
  167. package/tests/fixtures/claude_code/short_session.jsonl +0 -2
  168. package/tests/fixtures/claude_code/standard_iso.jsonl +0 -4
  169. package/tests/fixtures/claude_code/tool_heavy.jsonl +0 -8
  170. package/tests/fixtures/claude_code/with_subagent.jsonl +0 -7
  171. package/tests/fixtures/facts.ts +0 -17
  172. package/tests/fixtures/golden-corpus.ts +0 -85
  173. package/tests/fixtures/hermes/paired_request_dump.json +0 -24
  174. package/tests/fixtures/hermes/paired_session.json +0 -23
  175. package/tests/fixtures/hermes/request_dump.json +0 -28
  176. package/tests/fixtures/hermes/session_iso.json +0 -38
  177. package/tests/fixtures/hermes/session_unix.json +0 -38
  178. package/tests/fixtures/hermes/system_only.json +0 -18
  179. package/tests/fixtures/pi/error-connection-abort.jsonl +0 -8
  180. package/tests/fixtures/pi/short-successful.jsonl +0 -5
  181. package/tests/fixtures/pi/with-custom-message.jsonl +0 -6
  182. package/tests/fixtures/sessions.ts +0 -22
  183. package/tests/integration/backfill-facts.test.ts +0 -362
  184. package/tests/integration/citation-explicit.test.ts +0 -111
  185. package/tests/integration/cite-event.test.ts +0 -169
  186. package/tests/integration/cite-memo.test.ts +0 -87
  187. package/tests/integration/db-restore.test.ts +0 -153
  188. package/tests/integration/embed-backfill.test.ts +0 -176
  189. package/tests/integration/fact-supersedence.test.ts +0 -313
  190. package/tests/integration/fts-index.test.ts +0 -60
  191. package/tests/integration/getbyids-sqlite.test.ts +0 -100
  192. package/tests/integration/hermes-agent-hooks.test.ts +0 -248
  193. package/tests/integration/hook-claude-settings.test.ts +0 -218
  194. package/tests/integration/hook-log.test.ts +0 -54
  195. package/tests/integration/hook-memo.test.ts +0 -68
  196. package/tests/integration/hook-pre-compact.test.ts +0 -105
  197. package/tests/integration/hook-subagent-start.test.ts +0 -102
  198. package/tests/integration/http.test.ts +0 -401
  199. package/tests/integration/keyword-search-fts.test.ts +0 -66
  200. package/tests/integration/mcp-recall-logging.test.ts +0 -88
  201. package/tests/integration/mcp.test.ts +0 -260
  202. package/tests/integration/memo-sweep.test.ts +0 -91
  203. package/tests/integration/prompt-recall-hook.test.ts +0 -88
  204. package/tests/integration/provider-registry.test.ts +0 -107
  205. package/tests/integration/recall-golden.test.ts +0 -59
  206. package/tests/integration/recall-sqlite.test.ts +0 -169
  207. package/tests/integration/scheduler.test.ts +0 -391
  208. package/tests/integration/session-end-hook.test.ts +0 -48
  209. package/tests/integration/session-start-hook.test.ts +0 -126
  210. package/tests/integration/source-registry.test.ts +0 -122
  211. package/tests/integration/sqlite-fact-store.test.ts +0 -346
  212. package/tests/integration/stop-hook.test.ts +0 -560
  213. package/tests/integration/wal-checkpoint.test.ts +0 -49
  214. package/tests/unit/cli/launchctl-helpers.test.ts +0 -60
  215. package/tests/unit/core/adapters/aider.test.ts +0 -230
  216. package/tests/unit/core/adapters/claude-code.test.ts +0 -118
  217. package/tests/unit/core/adapters/cursor.test.ts +0 -485
  218. package/tests/unit/core/adapters/hermes-agent.test.ts +0 -329
  219. package/tests/unit/core/adapters/hermes.test.ts +0 -81
  220. package/tests/unit/core/adapters/jsonl-generic.test.ts +0 -142
  221. package/tests/unit/core/adapters/opencode.test.ts +0 -354
  222. package/tests/unit/core/adapters/pi.test.ts +0 -110
  223. package/tests/unit/core/adapters/windsurf.test.ts +0 -416
  224. package/tests/unit/core/classifier/prompt.test.ts +0 -126
  225. package/tests/unit/core/embedding/chunk-body.test.ts +0 -100
  226. package/tests/unit/core/facts/extract-facts.test.ts +0 -117
  227. package/tests/unit/core/filter.test.ts +0 -40
  228. package/tests/unit/core/hook/citation-detect-cite-session.test.ts +0 -96
  229. package/tests/unit/core/hook/citation-detect.test.ts +0 -124
  230. package/tests/unit/core/hook/gate.test.ts +0 -29
  231. package/tests/unit/core/hook/pointer-block.test.ts +0 -22
  232. package/tests/unit/core/hook/select.test.ts +0 -66
  233. package/tests/unit/core/match-fields.test.ts +0 -39
  234. package/tests/unit/core/mcp-cite-session.test.ts +0 -51
  235. package/tests/unit/core/providers/provider-models.test.ts +0 -101
  236. package/tests/unit/core/query-shape.test.ts +0 -92
  237. package/tests/unit/core/recall-facts/fact-recall-service.test.ts +0 -258
  238. package/tests/unit/core/recall-service.test.ts +0 -200
  239. package/tests/unit/core/storage/live-status.test.ts +0 -54
  240. package/tests/unit/core/tokenize.test.ts +0 -32
  241. package/tests/unit/core/useful-scan.test.ts +0 -537
  242. package/tests/unit/llm/embed.test.ts +0 -93
  243. package/tests/unit/llm/ollama-client.test.ts +0 -124
  244. package/tests/unit/scripts/longmemeval-scorer.test.ts +0 -114
  245. package/tsconfig.json +0 -31
  246. package/tsconfig.test.json +0 -11
  247. package/vitest.config.ts +0 -22
@@ -1,117 +0,0 @@
1
- /**
2
- * extractFacts — pure transform from ClassifyResult to Fact[]. No DB, no
3
- * randomness (idGenerator is injected).
4
- */
5
-
6
- import { describe, expect, it } from "vitest";
7
- import { extractFacts } from "../../../../src/core/facts/extract-facts.js";
8
- import type { ClassifyResult } from "../../../../src/ports/llm-client.js";
9
-
10
- function classifyResult(overrides: Partial<ClassifyResult> = {}): ClassifyResult {
11
- return {
12
- label: "L",
13
- summary: "S",
14
- entities: [],
15
- decisions: [],
16
- open: [],
17
- confidence: 0.9,
18
- facts: [],
19
- ...overrides,
20
- };
21
- }
22
-
23
- describe("extractFacts", () => {
24
- it("returns an empty array when classify result has no facts", () => {
25
- const out = extractFacts(classifyResult(), "sess_1", "2026-05-19T10:00:00Z");
26
- expect(out).toEqual([]);
27
- });
28
-
29
- it("maps classifier facts to full Fact records with injected id + timestamp", () => {
30
- let n = 0;
31
- const result = classifyResult({
32
- confidence: 0.85,
33
- facts: [
34
- { kind: "decision", subject: "nlm-memory-ts", predicate: "framework", value: "Hono" },
35
- {
36
- kind: "attribute",
37
- subject: "mac-pro",
38
- predicate: "endpoint",
39
- value: "http://macpro:8080/v1",
40
- sourceQuote: "endpoint at :8080",
41
- },
42
- ],
43
- });
44
- const out = extractFacts(result, "sess_1", "2026-05-19T10:00:00Z", {
45
- idGenerator: () => `fact_${++n}`,
46
- });
47
- expect(out).toEqual([
48
- {
49
- id: "fact_1",
50
- kind: "decision",
51
- subject: "nlm-memory-ts",
52
- predicate: "framework",
53
- value: "Hono",
54
- sourceSessionId: "sess_1",
55
- sourceQuote: null,
56
- createdAt: "2026-05-19T10:00:00Z",
57
- supersededBy: null,
58
- confidence: 0.85,
59
- },
60
- {
61
- id: "fact_2",
62
- kind: "attribute",
63
- subject: "mac-pro",
64
- predicate: "endpoint",
65
- value: "http://macpro:8080/v1",
66
- sourceSessionId: "sess_1",
67
- sourceQuote: "endpoint at :8080",
68
- createdAt: "2026-05-19T10:00:00Z",
69
- supersededBy: null,
70
- confidence: 0.85,
71
- },
72
- ]);
73
- });
74
-
75
- it("drops all facts when classifier confidence is below 0.4", () => {
76
- const result = classifyResult({
77
- confidence: 0.35,
78
- facts: [
79
- { kind: "decision", subject: "x", predicate: "framework", value: "y" },
80
- ],
81
- });
82
- expect(extractFacts(result, "sess_1", "2026-05-19T10:00:00Z")).toEqual([]);
83
- });
84
-
85
- it("keeps facts when confidence is exactly the floor (0.4)", () => {
86
- const result = classifyResult({
87
- confidence: 0.4,
88
- facts: [
89
- { kind: "decision", subject: "x", predicate: "framework", value: "y" },
90
- ],
91
- });
92
- expect(extractFacts(result, "sess_1", "2026-05-19T10:00:00Z")).toHaveLength(1);
93
- });
94
-
95
- it("uses default id generator (fact_<uuid>) when none provided", () => {
96
- const result = classifyResult({
97
- facts: [{ kind: "decision", subject: "x", predicate: "framework", value: "y" }],
98
- });
99
- const out = extractFacts(result, "sess_1", "2026-05-19T10:00:00Z");
100
- expect(out[0]?.id).toMatch(/^fact_[0-9a-f-]{36}$/);
101
- });
102
-
103
- it("each fact gets its own id from the generator (no reuse)", () => {
104
- let n = 0;
105
- const result = classifyResult({
106
- facts: [
107
- { kind: "decision", subject: "a", predicate: "framework", value: "x" },
108
- { kind: "decision", subject: "b", predicate: "framework", value: "y" },
109
- { kind: "decision", subject: "c", predicate: "framework", value: "z" },
110
- ],
111
- });
112
- const out = extractFacts(result, "sess_1", "2026-05-19T10:00:00Z", {
113
- idGenerator: () => `fact_${++n}`,
114
- });
115
- expect(out.map((f) => f.id)).toEqual(["fact_1", "fact_2", "fact_3"]);
116
- });
117
- });
@@ -1,40 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { applyFilter } from "../../../src/core/recall/filter.js";
3
- import { makeSession } from "../../fixtures/sessions.js";
4
-
5
- describe("applyFilter", () => {
6
- const noDecisionsNoOpen = makeSession({ id: "a", entities: ["Whtnxt"] });
7
- const onlyDecisions = makeSession({ id: "b", entities: ["NLM"], decisions: ["picked Hono"] });
8
- const onlyOpen = makeSession({ id: "c", entities: ["NLM"], open: ["pgvector later"] });
9
- const both = makeSession({
10
- id: "d",
11
- entities: ["NLM", "Whtnxt"],
12
- decisions: ["use SQLite + sqlite-vec"],
13
- open: ["Tauri or Electron"],
14
- });
15
- const corpus = [noDecisionsNoOpen, onlyDecisions, onlyOpen, both];
16
-
17
- it("returns input unchanged when filter is empty", () => {
18
- expect(applyFilter(corpus, {})).toEqual(corpus);
19
- });
20
-
21
- it("filters by entity tag", () => {
22
- const result = applyFilter(corpus, { entity: "NLM" });
23
- expect(result.map((s) => s.id)).toEqual(["b", "c", "d"]);
24
- });
25
-
26
- it("filters by kind=decision (drops sessions with no decisions)", () => {
27
- const result = applyFilter(corpus, { kind: "decision" });
28
- expect(result.map((s) => s.id)).toEqual(["b", "d"]);
29
- });
30
-
31
- it("filters by kind=open (drops sessions with no open questions)", () => {
32
- const result = applyFilter(corpus, { kind: "open" });
33
- expect(result.map((s) => s.id)).toEqual(["c", "d"]);
34
- });
35
-
36
- it("combines entity and kind constraints (AND semantics)", () => {
37
- const result = applyFilter(corpus, { entity: "Whtnxt", kind: "decision" });
38
- expect(result.map((s) => s.id)).toEqual(["d"]);
39
- });
40
- });
@@ -1,96 +0,0 @@
1
- /**
2
- * cite_session tool_use handling in the Stop hook detector.
3
- *
4
- * The MCP server's citeSessionHandler already calls appendCitation() directly
5
- * when the model invokes cite_session. The Stop hook must NOT detect the same
6
- * cite_session tool_use and write a second log entry (double-count). The A1
7
- * sub-case in detectCitations now skips cite_session calls entirely.
8
- *
9
- * Implicit citations via other NLM tools (get_session, recall_sessions, etc.)
10
- * still fire through the A2 path as before.
11
- */
12
-
13
- import { describe, expect, it } from "vitest";
14
- import { detectCitations } from "../../../../src/core/hook/citation-detect.js";
15
-
16
- describe("detectCitations — cite_session skipped to prevent double-count", () => {
17
- it("does not detect cite_session as a citation (MCP handler already logged it)", () => {
18
- const result = detectCitations({
19
- responseText: "Based on that session, here is my answer.",
20
- toolUses: [
21
- {
22
- name: "mcp__nlm-memory__cite_session",
23
- input: { id: "cc_sub_a139f4ab7ca5aa909" },
24
- },
25
- ],
26
- surfacedIds: ["cc_sub_a139f4ab7ca5aa909"],
27
- });
28
- expect(result).toEqual([]);
29
- });
30
-
31
- it("does not detect cite_session even for a surfaced ID", () => {
32
- const result = detectCitations({
33
- responseText: "",
34
- toolUses: [
35
- {
36
- name: "mcp__nlm-memory__cite_session",
37
- input: { id: "cc_sub_a139f4ab7ca5aa909" },
38
- },
39
- ],
40
- surfacedIds: ["cc_sub_a139f4ab7ca5aa909"],
41
- });
42
- expect(result).toEqual([]);
43
- });
44
-
45
- it("falls back to prose detection when cite_session is skipped and ID appears in text", () => {
46
- const result = detectCitations({
47
- responseText: "Per cc_sub_a139f4ab7ca5aa909, the decision was FTS5.",
48
- toolUses: [
49
- {
50
- name: "mcp__nlm-memory__cite_session",
51
- input: { id: "cc_sub_a139f4ab7ca5aa909" },
52
- },
53
- ],
54
- surfacedIds: ["cc_sub_a139f4ab7ca5aa909"],
55
- });
56
- expect(result).toHaveLength(1);
57
- expect(result[0]).toEqual({ id: "cc_sub_a139f4ab7ca5aa909", kind: "prose" });
58
- });
59
-
60
- it("returns empty when multiple cite_session calls are skipped and no prose match", () => {
61
- const result = detectCitations({
62
- responseText: "",
63
- toolUses: [
64
- {
65
- name: "mcp__nlm-memory__cite_session",
66
- input: { id: "cc_sub_a139f4ab7ca5aa909" },
67
- },
68
- {
69
- name: "mcp__nlm-memory__cite_session",
70
- input: { id: "hm_20260427_6ff562" },
71
- },
72
- ],
73
- surfacedIds: ["cc_sub_a139f4ab7ca5aa909", "hm_20260427_6ff562"],
74
- });
75
- expect(result).toEqual([]);
76
- });
77
-
78
- it("A2 path (get_session) still fires while cite_session is skipped for the same turn", () => {
79
- const result = detectCitations({
80
- responseText: "",
81
- toolUses: [
82
- {
83
- name: "mcp__nlm-memory__cite_session",
84
- input: { id: "cc_sub_a139f4ab7ca5aa909" },
85
- },
86
- {
87
- name: "mcp__nlm-memory__get_session",
88
- input: { id: "hm_20260427_6ff562" },
89
- },
90
- ],
91
- surfacedIds: ["cc_sub_a139f4ab7ca5aa909", "hm_20260427_6ff562"],
92
- });
93
- expect(result).toHaveLength(1);
94
- expect(result[0]).toMatchObject({ id: "hm_20260427_6ff562", kind: "tool_use" });
95
- });
96
- });
@@ -1,124 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import {
3
- detectCitations,
4
- detectCitedIds,
5
- } from "../../../../src/core/hook/citation-detect.js";
6
-
7
- describe("detectCitedIds (back-compat prose-only)", () => {
8
- it("returns IDs that appear as substrings in the response", () => {
9
- const surfaced = new Set([
10
- "cc_sub_a139f4ab7ca5aa909",
11
- "hm_20260427_6ff562",
12
- ]);
13
- const text = "Per cc_sub_a139f4ab7ca5aa909 and hm_20260427_6ff562 we chose FTS5.";
14
- expect(detectCitedIds(text, surfaced).sort()).toEqual(
15
- ["cc_sub_a139f4ab7ca5aa909", "hm_20260427_6ff562"].sort(),
16
- );
17
- });
18
-
19
- it("returns empty when no surfaced IDs appear", () => {
20
- expect(detectCitedIds("unrelated", new Set(["cc_sub_abc123def456"]))).toEqual([]);
21
- });
22
-
23
- it("ignores IDs shorter than the minimum length", () => {
24
- expect(detectCitedIds("a ab abc abcdef", new Set(["a", "ab", "abc"]))).toEqual([]);
25
- });
26
- });
27
-
28
- describe("detectCitations (combined tool_use + prose)", () => {
29
- it("emits a tool_use citation when an NLM MCP tool input references a surfaced ID", () => {
30
- const result = detectCitations({
31
- responseText: "Let me look at that.",
32
- toolUses: [
33
- {
34
- name: "mcp__nlm-memory__get_session",
35
- input: { id: "cc_sub_a139f4ab7ca5aa909" },
36
- },
37
- ],
38
- surfacedIds: ["cc_sub_a139f4ab7ca5aa909", "hm_20260427_6ff562"],
39
- });
40
- expect(result).toEqual([
41
- { id: "cc_sub_a139f4ab7ca5aa909", kind: "tool_use" },
42
- ]);
43
- });
44
-
45
- it("emits a prose citation when only the response text mentions the ID", () => {
46
- const result = detectCitations({
47
- responseText: "We decided on FTS5 per cc_sub_a139f4ab7ca5aa909.",
48
- toolUses: [],
49
- surfacedIds: ["cc_sub_a139f4ab7ca5aa909"],
50
- });
51
- expect(result).toEqual([
52
- { id: "cc_sub_a139f4ab7ca5aa909", kind: "prose" },
53
- ]);
54
- });
55
-
56
- it("prefers tool_use over prose when both fire on the same ID", () => {
57
- const result = detectCitations({
58
- responseText: "Per cc_sub_a139f4ab7ca5aa909, here is the answer.",
59
- toolUses: [
60
- {
61
- name: "mcp__nlm-memory__get_session",
62
- input: { id: "cc_sub_a139f4ab7ca5aa909" },
63
- },
64
- ],
65
- surfacedIds: ["cc_sub_a139f4ab7ca5aa909"],
66
- });
67
- expect(result).toEqual([
68
- { id: "cc_sub_a139f4ab7ca5aa909", kind: "tool_use" },
69
- ]);
70
- });
71
-
72
- it("ignores non-NLM tool_use blocks even when they happen to contain the ID", () => {
73
- const result = detectCitations({
74
- responseText: "",
75
- toolUses: [
76
- {
77
- name: "Bash",
78
- input: { command: "grep cc_sub_a139f4ab7ca5aa909 /tmp/log" },
79
- },
80
- ],
81
- surfacedIds: ["cc_sub_a139f4ab7ca5aa909"],
82
- });
83
- expect(result).toEqual([]);
84
- });
85
-
86
- it("handles multiple NLM tool calls in one turn", () => {
87
- const result = detectCitations({
88
- responseText: "",
89
- toolUses: [
90
- {
91
- name: "mcp__nlm-memory__get_session",
92
- input: { id: "cc_sub_a139f4ab7ca5aa909" },
93
- },
94
- {
95
- name: "mcp__nlm-memory__get_session",
96
- input: { id: "hm_20260427_6ff562" },
97
- },
98
- ],
99
- surfacedIds: [
100
- "cc_sub_a139f4ab7ca5aa909",
101
- "hm_20260427_6ff562",
102
- "cc_unused_id_xyz",
103
- ],
104
- });
105
- expect(result.map((c) => c.id).sort()).toEqual(
106
- ["cc_sub_a139f4ab7ca5aa909", "hm_20260427_6ff562"].sort(),
107
- );
108
- expect(result.every((c) => c.kind === "tool_use")).toBe(true);
109
- });
110
-
111
- it("recognizes recall_sessions tool calls with query+limit (no direct id) — does not emit when no ID present in input", () => {
112
- const result = detectCitations({
113
- responseText: "",
114
- toolUses: [
115
- {
116
- name: "mcp__nlm-memory__recall_sessions",
117
- input: { query: "FTS5 vs pgvector", limit: 5 },
118
- },
119
- ],
120
- surfacedIds: ["cc_sub_a139f4ab7ca5aa909"],
121
- });
122
- expect(result).toEqual([]);
123
- });
124
- });
@@ -1,29 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { classifyPrompt } from "../../../../src/core/hook/gate.js";
3
-
4
- describe("classifyPrompt", () => {
5
- it("classifies obvious generative openers as generative", () => {
6
- expect(classifyPrompt("draft a LinkedIn post about FTS5")).toBe("generative");
7
- expect(classifyPrompt("write the migration")).toBe("generative");
8
- expect(classifyPrompt("brainstorm names for the feature")).toBe("generative");
9
- expect(classifyPrompt("Create a test file")).toBe("generative");
10
- });
11
-
12
- it("classifies retrospective prompts as evaluate", () => {
13
- expect(classifyPrompt("what did we decide about pgvector")).toBe("evaluate");
14
- expect(classifyPrompt("have I worked with this client before")).toBe("evaluate");
15
- expect(classifyPrompt("why is the recall backend returning zero results")).toBe("evaluate");
16
- });
17
-
18
- it("strips leading filler before checking the opener", () => {
19
- expect(classifyPrompt("can you write a script")).toBe("generative");
20
- expect(classifyPrompt("please draft the email")).toBe("generative");
21
- expect(classifyPrompt("could you tell me what we decided")).toBe("evaluate");
22
- });
23
-
24
- it("defaults to evaluate for empty or ambiguous prompts", () => {
25
- expect(classifyPrompt("")).toBe("evaluate");
26
- expect(classifyPrompt("the FTS5 work")).toBe("evaluate");
27
- expect(classifyPrompt("fix the failing test")).toBe("evaluate");
28
- });
29
- });
@@ -1,22 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { formatPointerBlock } from "../../../../src/core/hook/pointer-block.js";
3
-
4
- describe("formatPointerBlock", () => {
5
- it("returns an empty string for no hits", () => {
6
- expect(formatPointerBlock([])).toBe("");
7
- });
8
-
9
- it("renders a header, one line per hit, and the tool footer", () => {
10
- const block = formatPointerBlock([
11
- { id: "sess_a", label: "FTS5 vs pgvector decision", startedAt: "2026-05-15T10:00:00.000Z" },
12
- { id: "sess_b", label: "Semantic recall via sqlite-vec", startedAt: "2026-05-17T09:30:00.000Z" },
13
- ]);
14
- expect(block).toContain("## Possibly-relevant prior sessions (nlm-memory)");
15
- expect(block).toContain("- sess_a · FTS5 vs pgvector decision (2026-05-15)");
16
- expect(block).toContain("- sess_b · Semantic recall via sqlite-vec (2026-05-17)");
17
- expect(block).toContain("recall_sessions");
18
- expect(block).toContain("get_session");
19
- expect(block).toContain("recall_facts");
20
- expect(block).toContain("get_fact_history");
21
- });
22
- });
@@ -1,66 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { selectHits, type RecallHitInput } from "../../../../src/core/hook/select.js";
3
-
4
- const hit = (id: string, matchScore: number): RecallHitInput => ({
5
- id,
6
- label: `label ${id}`,
7
- startedAt: "2026-05-15T10:00:00.000Z",
8
- matchScore,
9
- });
10
-
11
- describe("selectHits", () => {
12
- it("drops hits below the score threshold", () => {
13
- const out = selectHits({
14
- hits: [hit("a", 0.9), hit("b", 0.3)],
15
- surfaced: new Set(),
16
- scoreThreshold: 0.5,
17
- perFireCap: 3,
18
- perConversationCap: 10,
19
- });
20
- expect(out.map((h) => h.id)).toEqual(["a"]);
21
- });
22
-
23
- it("drops hits already surfaced in this conversation", () => {
24
- const out = selectHits({
25
- hits: [hit("a", 0.9), hit("b", 0.8)],
26
- surfaced: new Set(["a"]),
27
- scoreThreshold: 0.5,
28
- perFireCap: 3,
29
- perConversationCap: 10,
30
- });
31
- expect(out.map((h) => h.id)).toEqual(["b"]);
32
- });
33
-
34
- it("caps the number surfaced per fire", () => {
35
- const out = selectHits({
36
- hits: [hit("a", 0.9), hit("b", 0.8), hit("c", 0.7), hit("d", 0.6)],
37
- surfaced: new Set(),
38
- scoreThreshold: 0.5,
39
- perFireCap: 3,
40
- perConversationCap: 10,
41
- });
42
- expect(out.map((h) => h.id)).toEqual(["a", "b", "c"]);
43
- });
44
-
45
- it("respects the remaining per-conversation budget", () => {
46
- const out = selectHits({
47
- hits: [hit("a", 0.9), hit("b", 0.8), hit("c", 0.7)],
48
- surfaced: new Set(["x", "y", "z", "p", "q", "r", "s", "t", "u"]), // 9 surfaced
49
- scoreThreshold: 0.5,
50
- perFireCap: 3,
51
- perConversationCap: 10,
52
- });
53
- expect(out.map((h) => h.id)).toEqual(["a"]); // only 1 slot left
54
- });
55
-
56
- it("returns nothing when the per-conversation cap is already met", () => {
57
- const out = selectHits({
58
- hits: [hit("a", 0.9)],
59
- surfaced: new Set(Array.from({ length: 10 }, (_, i) => `s${i}`)),
60
- scoreThreshold: 0.5,
61
- perFireCap: 3,
62
- perConversationCap: 10,
63
- });
64
- expect(out).toEqual([]);
65
- });
66
- });
@@ -1,39 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { keywordMatchFields } from "../../../src/core/recall/match-fields.js";
3
- import { tokenSet } from "../../../src/core/recall/tokenize.js";
4
- import { makeSession } from "../../fixtures/sessions.js";
5
-
6
- describe("keywordMatchFields", () => {
7
- it("returns no fields for empty query tokens", () => {
8
- expect(keywordMatchFields(makeSession({ label: "anything" }), new Set())).toEqual([]);
9
- });
10
-
11
- it("reports the label field on a label match", () => {
12
- const session = makeSession({ label: "pgvector migration plan" });
13
- expect(keywordMatchFields(session, tokenSet("pgvector"))).toEqual(["label"]);
14
- });
15
-
16
- it("reports decisions and open from marker text", () => {
17
- const session = makeSession({
18
- decisions: ["picked Hono for HTTP"],
19
- open: ["whether to use Tauri later"],
20
- });
21
- expect(keywordMatchFields(session, tokenSet("Hono"))).toEqual(["decisions"]);
22
- expect(keywordMatchFields(session, tokenSet("Tauri"))).toEqual(["open"]);
23
- });
24
-
25
- it("reports every matching field in label, decisions, open, summary order", () => {
26
- const session = makeSession({
27
- label: "recall port",
28
- summary: "ported recall to TypeScript",
29
- decisions: ["use sqlite-vec for semantic recall"],
30
- open: ["recall stats endpoint"],
31
- });
32
- expect(keywordMatchFields(session, tokenSet("recall"))).toEqual([
33
- "label",
34
- "decisions",
35
- "open",
36
- "summary",
37
- ]);
38
- });
39
- });
@@ -1,51 +0,0 @@
1
- /**
2
- * citeSessionHandler unit tests. Exercises the MCP tool handler directly
3
- * without a transport or store dependency — appendCitation writes to a tmp
4
- * file so we can verify the entry was written.
5
- */
6
-
7
- import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
8
- import { tmpdir } from "node:os";
9
- import { join } from "node:path";
10
- import { afterEach, beforeEach, describe, expect, it } from "vitest";
11
- import { citeSessionHandler } from "../../../src/mcp/server.js";
12
-
13
- describe("citeSessionHandler", () => {
14
- let tmp: string;
15
-
16
- beforeEach(() => {
17
- tmp = mkdtempSync(join(tmpdir(), "nlm-cite-session-"));
18
- });
19
-
20
- afterEach(() => {
21
- rmSync(tmp, { recursive: true, force: true });
22
- });
23
-
24
- it("returns logged:true for a valid id", async () => {
25
- const result = await citeSessionHandler({ id: "cc_sub_abc123def456" });
26
- expect(result.isError).toBeFalsy();
27
- const parsed = JSON.parse(result.content[0]!.text) as Record<string, unknown>;
28
- expect(parsed["logged"]).toBe(true);
29
- expect(parsed["id"]).toBe("cc_sub_abc123def456");
30
- });
31
-
32
- it("returns an error for an id that is too short", async () => {
33
- const result = await citeSessionHandler({ id: "short" });
34
- expect(result.isError).toBe(true);
35
- expect(result.content[0]!.text).toContain("Error");
36
- });
37
-
38
- it("returns an error for an empty id", async () => {
39
- const result = await citeSessionHandler({ id: "" });
40
- expect(result.isError).toBe(true);
41
- });
42
-
43
- it("accepts optional conversation_id and reason without error", async () => {
44
- const result = await citeSessionHandler({
45
- id: "cc_sub_abc123def456",
46
- conversation_id: "conv_test_001",
47
- reason: "Used to confirm FTS5 choice.",
48
- });
49
- expect(result.isError).toBeFalsy();
50
- });
51
- });