nlm-memory 0.4.2 → 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 (285) hide show
  1. package/README.md +72 -34
  2. package/dist/cli/nlm.js +223 -33
  3. package/dist/cli/nlm.js.map +1 -1
  4. package/dist/core/adapters/cursor.d.ts +45 -0
  5. package/dist/core/adapters/cursor.js +397 -0
  6. package/dist/core/adapters/cursor.js.map +1 -0
  7. package/dist/core/adapters/from-source.js +10 -0
  8. package/dist/core/adapters/from-source.js.map +1 -1
  9. package/dist/core/adapters/windsurf.d.ts +44 -0
  10. package/dist/core/adapters/windsurf.js +299 -0
  11. package/dist/core/adapters/windsurf.js.map +1 -0
  12. package/dist/core/hook/claude-settings.d.ts +12 -5
  13. package/dist/core/hook/claude-settings.js +21 -6
  14. package/dist/core/hook/claude-settings.js.map +1 -1
  15. package/dist/core/sources/source-registry.d.ts +1 -1
  16. package/dist/core/sources/source-registry.js +18 -0
  17. package/dist/core/sources/source-registry.js.map +1 -1
  18. package/dist/core/storage/sqlite-session-store.d.ts +2 -0
  19. package/dist/core/storage/sqlite-session-store.js +38 -2
  20. package/dist/core/storage/sqlite-session-store.js.map +1 -1
  21. package/dist/hook/hook-auth.d.ts +13 -0
  22. package/dist/hook/hook-auth.js +19 -0
  23. package/dist/hook/hook-auth.js.map +1 -0
  24. package/dist/hook/prompt-recall-hook.js +7 -1
  25. package/dist/hook/prompt-recall-hook.js.map +1 -1
  26. package/dist/hook/session-start-hook.js +4 -1
  27. package/dist/hook/session-start-hook.js.map +1 -1
  28. package/dist/hook/stop-hook.js +4 -1
  29. package/dist/hook/stop-hook.js.map +1 -1
  30. package/dist/http/app.d.ts +2 -0
  31. package/dist/http/app.js +76 -1
  32. package/dist/http/app.js.map +1 -1
  33. package/dist/install/claude-code.js +1 -1
  34. package/dist/install/claude-code.js.map +1 -1
  35. package/dist/install/cursor.d.ts +25 -0
  36. package/dist/install/cursor.js +43 -0
  37. package/dist/install/cursor.js.map +1 -0
  38. package/dist/install/nlm-dir-perms.d.ts +19 -0
  39. package/dist/install/nlm-dir-perms.js +43 -0
  40. package/dist/install/nlm-dir-perms.js.map +1 -0
  41. package/dist/install/ollama.d.ts +18 -1
  42. package/dist/install/ollama.js +62 -7
  43. package/dist/install/ollama.js.map +1 -1
  44. package/dist/install/setup.d.ts +4 -0
  45. package/dist/install/setup.js +141 -18
  46. package/dist/install/setup.js.map +1 -1
  47. package/dist/install/windsurf.d.ts +25 -0
  48. package/dist/install/windsurf.js +43 -0
  49. package/dist/install/windsurf.js.map +1 -0
  50. package/dist/mcp/server.js +20 -1
  51. package/dist/mcp/server.js.map +1 -1
  52. package/dist/shared/types.d.ts +4 -0
  53. package/dist/ui/assets/{index-BA6IpU8g.css → index-Beo8psd-.css} +1 -1
  54. package/dist/ui/assets/index-CSPTTeeM.js +69 -0
  55. package/dist/ui/index.html +2 -2
  56. package/package.json +26 -1
  57. package/plugin/scripts/prompt-recall-hook.mjs +55 -4
  58. package/plugin/scripts/stop-hook.mjs +57 -6
  59. package/.agents/plugins/marketplace.json +0 -20
  60. package/.github/workflows/ci.yml +0 -30
  61. package/dist/ui/assets/index-B_qIVV0k.js +0 -69
  62. package/docs/methodology/re-derivation-rate.md +0 -112
  63. package/docs/methodology/useful-hit-rate.md +0 -79
  64. package/docs/plans/2026-05-20-fts5-lexical-recall.md +0 -1088
  65. package/docs/plans/2026-05-20-recall-daemon-wedge-fix.md +0 -662
  66. package/docs/plans/2026-05-20-recall-hook-design.md +0 -131
  67. package/docs/plans/2026-05-20-recall-hook-implementation.md +0 -1222
  68. package/docs/plans/desktop-product.md +0 -69
  69. package/docs/plans/factstore-design.md +0 -236
  70. package/logs/CHANGELOG/CHANGELOG-2026.md +0 -1389
  71. package/logs/CHANGELOG/CHANGELOG.md +0 -337
  72. package/migrations/000_initial_schema.sql +0 -174
  73. package/migrations/001_entity_type_rename.sql +0 -17
  74. package/migrations/002_adapter_state_extend.sql +0 -12
  75. package/migrations/003_session_embeddings.sql +0 -11
  76. package/migrations/004_facts.sql +0 -46
  77. package/migrations/005_sources.sql +0 -31
  78. package/migrations/006_providers.sql +0 -33
  79. package/migrations/007_source_tokens.sql +0 -17
  80. package/migrations/008_fts_rebuild.sql +0 -9
  81. package/migrations/009_session_embedding_chunks.sql +0 -46
  82. package/migrations/010_sources_opencode.sql +0 -30
  83. package/migrations/011_sources_hermes_agent.sql +0 -30
  84. package/migrations/012_sources_aider.sql +0 -30
  85. package/migrations/013_adapter_state_failure_count.sql +0 -12
  86. package/plugin-hermes-agent/README.md +0 -49
  87. package/plugin-hermes-agent/__init__.py +0 -75
  88. package/plugin-hermes-agent/plugin.yaml +0 -15
  89. package/scripts/backfill-citations.mjs +0 -0
  90. package/scripts/build-codex-plugin.mjs +0 -61
  91. package/scripts/deepseek-probe.mjs +0 -67
  92. package/scripts/extract-triples.mjs +0 -207
  93. package/scripts/longmemeval/embedding-cache.ts +0 -77
  94. package/scripts/longmemeval/fetch-dataset.sh +0 -25
  95. package/scripts/longmemeval/run-harness.ts +0 -315
  96. package/scripts/longmemeval/scorer.ts +0 -99
  97. package/scripts/longmemeval/tsconfig.json +0 -9
  98. package/scripts/longmemeval/types.ts +0 -35
  99. package/scripts/nlm-daily-digest.py +0 -239
  100. package/scripts/nlm-daily-digest.sh +0 -28
  101. package/src/cli/classify-parity.ts +0 -257
  102. package/src/cli/launchctl-helpers.ts +0 -49
  103. package/src/cli/nlm.ts +0 -885
  104. package/src/core/actions/actions-log.ts +0 -118
  105. package/src/core/actions/overlay.ts +0 -117
  106. package/src/core/adapters/aider.ts +0 -205
  107. package/src/core/adapters/claude-code.ts +0 -293
  108. package/src/core/adapters/common.ts +0 -54
  109. package/src/core/adapters/from-source.ts +0 -57
  110. package/src/core/adapters/hermes-agent.ts +0 -240
  111. package/src/core/adapters/hermes.ts +0 -277
  112. package/src/core/adapters/jsonl-generic.ts +0 -208
  113. package/src/core/adapters/opencode.ts +0 -281
  114. package/src/core/adapters/pi.ts +0 -264
  115. package/src/core/classifier/prompt.ts +0 -200
  116. package/src/core/dataset/build-dataset.ts +0 -463
  117. package/src/core/embedding/chunk-body.ts +0 -76
  118. package/src/core/embedding/embed-backfill.ts +0 -210
  119. package/src/core/embedding/embed-normalize.ts +0 -135
  120. package/src/core/facts/backfill-facts.ts +0 -254
  121. package/src/core/facts/extract-facts.ts +0 -50
  122. package/src/core/hook/citation-detect.ts +0 -124
  123. package/src/core/hook/cite-memo.ts +0 -68
  124. package/src/core/hook/claude-settings.ts +0 -166
  125. package/src/core/hook/gate.ts +0 -25
  126. package/src/core/hook/hook-log.ts +0 -41
  127. package/src/core/hook/memo-sweep.ts +0 -164
  128. package/src/core/hook/memo.ts +0 -67
  129. package/src/core/hook/pointer-block.ts +0 -26
  130. package/src/core/hook/select.ts +0 -32
  131. package/src/core/hook/transcript.ts +0 -121
  132. package/src/core/ingest/ingest-session.ts +0 -111
  133. package/src/core/providers/provider-models.ts +0 -100
  134. package/src/core/providers/provider-registry.ts +0 -196
  135. package/src/core/recall/citation-log.ts +0 -108
  136. package/src/core/recall/filter.ts +0 -27
  137. package/src/core/recall/index.ts +0 -6
  138. package/src/core/recall/match-fields.ts +0 -40
  139. package/src/core/recall/query-log.ts +0 -149
  140. package/src/core/recall/query-shape.ts +0 -66
  141. package/src/core/recall/recall-service.ts +0 -320
  142. package/src/core/recall/recent-log.ts +0 -59
  143. package/src/core/recall/tokenize.ts +0 -18
  144. package/src/core/recall/useful-scan.ts +0 -336
  145. package/src/core/recall-facts/fact-query-log.ts +0 -150
  146. package/src/core/recall-facts/fact-recall-service.ts +0 -327
  147. package/src/core/scheduler/scan-once.ts +0 -142
  148. package/src/core/scheduler/scheduler.ts +0 -225
  149. package/src/core/sources/source-registry.ts +0 -260
  150. package/src/core/storage/db-restore.ts +0 -133
  151. package/src/core/storage/live-status.ts +0 -45
  152. package/src/core/storage/migrate.ts +0 -72
  153. package/src/core/storage/sqlite-fact-store.ts +0 -304
  154. package/src/core/storage/sqlite-session-store.ts +0 -765
  155. package/src/hook/prompt-recall-hook.ts +0 -174
  156. package/src/hook/session-end-hook.ts +0 -81
  157. package/src/hook/session-start-hook.ts +0 -165
  158. package/src/hook/stop-hook.ts +0 -236
  159. package/src/http/app.ts +0 -1137
  160. package/src/install/claude-code.ts +0 -128
  161. package/src/install/codex.ts +0 -367
  162. package/src/install/hermes-agent.ts +0 -76
  163. package/src/install/hermes.ts +0 -78
  164. package/src/install/ollama.ts +0 -211
  165. package/src/install/setup.ts +0 -368
  166. package/src/llm/classifier-box.ts +0 -64
  167. package/src/llm/deepseek-client.ts +0 -150
  168. package/src/llm/env-autoload.ts +0 -55
  169. package/src/llm/ollama-client.ts +0 -189
  170. package/src/mcp/server.ts +0 -534
  171. package/src/ports/fact-store.ts +0 -102
  172. package/src/ports/llm-client.ts +0 -52
  173. package/src/ports/logger.ts +0 -16
  174. package/src/ports/session-store.ts +0 -45
  175. package/src/ports/transcript-adapter.ts +0 -55
  176. package/src/shared/types.ts +0 -145
  177. package/src/ui/App.tsx +0 -58
  178. package/src/ui/components/PromoteOpenButton.tsx +0 -65
  179. package/src/ui/components/SessionDrawer.tsx +0 -136
  180. package/src/ui/components/SideNav.tsx +0 -162
  181. package/src/ui/components/Skeleton.tsx +0 -107
  182. package/src/ui/index.html +0 -13
  183. package/src/ui/lib/actions.ts +0 -30
  184. package/src/ui/lib/api.ts +0 -92
  185. package/src/ui/lib/dataset.ts +0 -141
  186. package/src/ui/lib/registries.ts +0 -155
  187. package/src/ui/lib/view-settings.ts +0 -41
  188. package/src/ui/main.tsx +0 -15
  189. package/src/ui/pages/Live.tsx +0 -229
  190. package/src/ui/pages/Pulse.tsx +0 -415
  191. package/src/ui/pages/Recall.tsx +0 -190
  192. package/src/ui/pages/River.tsx +0 -308
  193. package/src/ui/pages/Search.tsx +0 -93
  194. package/src/ui/pages/Stub.tsx +0 -9
  195. package/src/ui/pages/Thread.tsx +0 -262
  196. package/src/ui/pages/settings/Classifier.tsx +0 -227
  197. package/src/ui/pages/settings/Data.tsx +0 -190
  198. package/src/ui/pages/settings/Index.tsx +0 -65
  199. package/src/ui/pages/settings/Labels.tsx +0 -224
  200. package/src/ui/pages/settings/Providers.tsx +0 -305
  201. package/src/ui/pages/settings/SettingsSubnav.tsx +0 -28
  202. package/src/ui/pages/settings/Sources.tsx +0 -326
  203. package/src/ui/pages/settings/Views.tsx +0 -96
  204. package/src/ui/styles.css +0 -1766
  205. package/src/ui/tsconfig.json +0 -21
  206. package/src/ui/vite.config.ts +0 -19
  207. package/tests/fixtures/claude_code/short_session.jsonl +0 -2
  208. package/tests/fixtures/claude_code/standard_iso.jsonl +0 -4
  209. package/tests/fixtures/claude_code/tool_heavy.jsonl +0 -8
  210. package/tests/fixtures/claude_code/with_subagent.jsonl +0 -7
  211. package/tests/fixtures/facts.ts +0 -17
  212. package/tests/fixtures/golden-corpus.ts +0 -85
  213. package/tests/fixtures/hermes/paired_request_dump.json +0 -24
  214. package/tests/fixtures/hermes/paired_session.json +0 -23
  215. package/tests/fixtures/hermes/request_dump.json +0 -28
  216. package/tests/fixtures/hermes/session_iso.json +0 -38
  217. package/tests/fixtures/hermes/session_unix.json +0 -38
  218. package/tests/fixtures/hermes/system_only.json +0 -18
  219. package/tests/fixtures/pi/error-connection-abort.jsonl +0 -8
  220. package/tests/fixtures/pi/short-successful.jsonl +0 -5
  221. package/tests/fixtures/pi/with-custom-message.jsonl +0 -6
  222. package/tests/fixtures/sessions.ts +0 -22
  223. package/tests/integration/backfill-facts.test.ts +0 -362
  224. package/tests/integration/citation-explicit.test.ts +0 -111
  225. package/tests/integration/cite-event.test.ts +0 -169
  226. package/tests/integration/cite-memo.test.ts +0 -87
  227. package/tests/integration/db-restore.test.ts +0 -153
  228. package/tests/integration/embed-backfill.test.ts +0 -176
  229. package/tests/integration/fact-supersedence.test.ts +0 -313
  230. package/tests/integration/fts-index.test.ts +0 -60
  231. package/tests/integration/getbyids-sqlite.test.ts +0 -60
  232. package/tests/integration/hermes-agent-hooks.test.ts +0 -248
  233. package/tests/integration/hook-claude-settings.test.ts +0 -205
  234. package/tests/integration/hook-log.test.ts +0 -54
  235. package/tests/integration/hook-memo.test.ts +0 -68
  236. package/tests/integration/hook-pre-compact.test.ts +0 -105
  237. package/tests/integration/hook-subagent-start.test.ts +0 -102
  238. package/tests/integration/http.test.ts +0 -401
  239. package/tests/integration/keyword-search-fts.test.ts +0 -66
  240. package/tests/integration/mcp-recall-logging.test.ts +0 -88
  241. package/tests/integration/mcp.test.ts +0 -248
  242. package/tests/integration/memo-sweep.test.ts +0 -91
  243. package/tests/integration/prompt-recall-hook.test.ts +0 -88
  244. package/tests/integration/provider-registry.test.ts +0 -107
  245. package/tests/integration/recall-golden.test.ts +0 -59
  246. package/tests/integration/recall-sqlite.test.ts +0 -169
  247. package/tests/integration/scheduler.test.ts +0 -391
  248. package/tests/integration/session-end-hook.test.ts +0 -48
  249. package/tests/integration/session-start-hook.test.ts +0 -126
  250. package/tests/integration/source-registry.test.ts +0 -120
  251. package/tests/integration/sqlite-fact-store.test.ts +0 -346
  252. package/tests/integration/stop-hook.test.ts +0 -560
  253. package/tests/integration/wal-checkpoint.test.ts +0 -49
  254. package/tests/unit/cli/launchctl-helpers.test.ts +0 -60
  255. package/tests/unit/core/adapters/aider.test.ts +0 -230
  256. package/tests/unit/core/adapters/claude-code.test.ts +0 -118
  257. package/tests/unit/core/adapters/hermes-agent.test.ts +0 -329
  258. package/tests/unit/core/adapters/hermes.test.ts +0 -81
  259. package/tests/unit/core/adapters/jsonl-generic.test.ts +0 -142
  260. package/tests/unit/core/adapters/opencode.test.ts +0 -354
  261. package/tests/unit/core/adapters/pi.test.ts +0 -110
  262. package/tests/unit/core/classifier/prompt.test.ts +0 -126
  263. package/tests/unit/core/embedding/chunk-body.test.ts +0 -100
  264. package/tests/unit/core/facts/extract-facts.test.ts +0 -117
  265. package/tests/unit/core/filter.test.ts +0 -40
  266. package/tests/unit/core/hook/citation-detect-cite-session.test.ts +0 -96
  267. package/tests/unit/core/hook/citation-detect.test.ts +0 -124
  268. package/tests/unit/core/hook/gate.test.ts +0 -29
  269. package/tests/unit/core/hook/pointer-block.test.ts +0 -22
  270. package/tests/unit/core/hook/select.test.ts +0 -66
  271. package/tests/unit/core/match-fields.test.ts +0 -39
  272. package/tests/unit/core/mcp-cite-session.test.ts +0 -51
  273. package/tests/unit/core/providers/provider-models.test.ts +0 -101
  274. package/tests/unit/core/query-shape.test.ts +0 -92
  275. package/tests/unit/core/recall-facts/fact-recall-service.test.ts +0 -258
  276. package/tests/unit/core/recall-service.test.ts +0 -200
  277. package/tests/unit/core/storage/live-status.test.ts +0 -54
  278. package/tests/unit/core/tokenize.test.ts +0 -32
  279. package/tests/unit/core/useful-scan.test.ts +0 -537
  280. package/tests/unit/llm/embed.test.ts +0 -93
  281. package/tests/unit/llm/ollama-client.test.ts +0 -124
  282. package/tests/unit/scripts/longmemeval-scorer.test.ts +0 -114
  283. package/tsconfig.json +0 -31
  284. package/tsconfig.test.json +0 -11
  285. package/vitest.config.ts +0 -22
@@ -1,45 +0,0 @@
1
- /**
2
- * SessionStore — the only way core/ reads or writes the session corpus.
3
- *
4
- * Implementations live in core/storage. Adapters and use cases depend on this
5
- * interface, never on better-sqlite3 directly. Swapping SQLite for Postgres
6
- * tomorrow means writing a new implementation; core/ does not change.
7
- */
8
-
9
- import type { Session, SessionStatus } from "@shared/types.js";
10
-
11
- export interface SessionFilter {
12
- readonly entity?: string;
13
- readonly hasDecisions?: boolean;
14
- readonly hasOpenQuestions?: boolean;
15
- }
16
-
17
- export interface SemanticNeighbor {
18
- readonly sessionId: string;
19
- readonly distance: number;
20
- }
21
-
22
- export interface KeywordNeighbor {
23
- readonly sessionId: string;
24
- readonly score: number;
25
- }
26
-
27
- export interface SessionStore {
28
- list(filter?: SessionFilter): Promise<ReadonlyArray<Session>>;
29
-
30
- getById(sessionId: string): Promise<Session | null>;
31
-
32
- getByIds(ids: ReadonlyArray<string>): Promise<ReadonlyArray<Session>>;
33
-
34
- semanticSearch(
35
- queryVector: Float32Array,
36
- limit: number,
37
- ): Promise<ReadonlyArray<SemanticNeighbor>>;
38
-
39
- keywordSearch(
40
- query: string,
41
- limit: number,
42
- ): Promise<ReadonlyArray<KeywordNeighbor>>;
43
-
44
- updateStatus(sessionId: string, status: SessionStatus): Promise<void>;
45
- }
@@ -1,55 +0,0 @@
1
- /**
2
- * TranscriptAdapter — the port every runtime-specific reader implements.
3
- *
4
- * One adapter per AI runtime (claude-code, hermes, pi, codex, gemini, aider).
5
- * Adapters discover transcript files on disk and parse one into a normalized
6
- * SessionChunk that the classifier/ingest pipeline can hand off to the
7
- * SessionStore. Adapters do not touch storage; they convert "files on disk"
8
- * into "candidate sessions" and stop there.
9
- *
10
- * Layering: core/recall consumes Session (already-classified). This port
11
- * lives between raw transcripts and the classifier — invoked by the
12
- * Scheduler in Phase D.
13
- */
14
-
15
- export interface DetectionResult {
16
- readonly adapterName: string;
17
- readonly enabled: boolean;
18
- readonly path: string | null;
19
- readonly hint: string | null;
20
- }
21
-
22
- export interface SessionChunk {
23
- readonly id: string;
24
- readonly runtime: string;
25
- readonly runtimeSessionId: string;
26
- readonly sourcePath: string;
27
- readonly startedAt: string;
28
- readonly endedAt: string;
29
- readonly durationMin: number;
30
- readonly turnCount: number;
31
- readonly byteRange: readonly [number, number];
32
- readonly projectDir: string;
33
- readonly gitBranch: string;
34
- readonly text: string;
35
- readonly label: string;
36
- }
37
-
38
- export interface DiscoverOptions {
39
- readonly since?: Date;
40
- }
41
-
42
- export interface TranscriptAdapter {
43
- readonly name: string;
44
- readonly runtimeVersion: string;
45
- readonly transcriptKind: string;
46
-
47
- /** Detection: is this adapter usable on this host? */
48
- detect(): DetectionResult;
49
-
50
- /** List candidate transcript files, optionally filtered by mtime. */
51
- discover(options?: DiscoverOptions): Promise<ReadonlyArray<string>>;
52
-
53
- /** Parse one transcript into a SessionChunk, or null if it's empty/garbage. */
54
- parseSession(path: string): Promise<SessionChunk | null>;
55
- }
@@ -1,145 +0,0 @@
1
- /**
2
- * Shared domain types crossed by core, http, mcp, and ui layers.
3
- * No runtime behavior here — types only.
4
- */
5
-
6
- /**
7
- * Session status as exposed to UI / recall consumers.
8
- *
9
- * Persisted values in `sessions.status` CHECK: 'active' | 'closed' | 'superseded'.
10
- * `idle` is a derived state computed from transcript mtime, returned by the
11
- * storage layer alongside the persisted value. `superseded` always wins over
12
- * mtime-derived state.
13
- */
14
- export type SessionStatus = "active" | "idle" | "closed" | "superseded";
15
-
16
- export type MarkerKind = "decision" | "open";
17
-
18
- export interface Session {
19
- readonly id: string;
20
- readonly runtime: string;
21
- readonly runtimeSessionId: string;
22
- readonly startedAt: string;
23
- readonly endedAt: string | null;
24
- readonly durationMin: number | null;
25
- readonly label: string;
26
- readonly summary: string;
27
- readonly status: SessionStatus;
28
- readonly transcriptKind: string;
29
- readonly transcriptPath: string | null;
30
- readonly body: string;
31
- readonly entities: ReadonlyArray<string>;
32
- readonly decisions: ReadonlyArray<string>;
33
- readonly open: ReadonlyArray<string>;
34
- }
35
-
36
- export type RecallMode = "keyword" | "semantic" | "hybrid";
37
-
38
- export type RecallKindFilter = "decision" | "open";
39
-
40
- export interface RecallQuery {
41
- readonly query: string;
42
- readonly entity?: string;
43
- readonly kind?: RecallKindFilter;
44
- readonly mode?: RecallMode;
45
- readonly limit?: number;
46
- }
47
-
48
- export interface RecallHit {
49
- readonly id: string;
50
- readonly startedAt: string;
51
- readonly label: string;
52
- readonly summary: string;
53
- readonly entities: ReadonlyArray<string>;
54
- readonly decisions: ReadonlyArray<string>;
55
- readonly open: ReadonlyArray<string>;
56
- readonly status: SessionStatus;
57
- readonly matchScore: number;
58
- readonly matchedIn: ReadonlyArray<MatchField>;
59
- readonly keywordScore?: number;
60
- readonly semanticScore?: number;
61
- }
62
-
63
- export type MatchField = "label" | "decisions" | "open" | "summary" | "semantic";
64
-
65
- export interface RecallResult {
66
- readonly query: string;
67
- readonly entity: string | null;
68
- readonly kind: RecallKindFilter | null;
69
- readonly mode: RecallMode;
70
- readonly limit: number;
71
- readonly total: number;
72
- readonly results: ReadonlyArray<RecallHit>;
73
- readonly modeUnavailable?: "ollama_unreachable";
74
- }
75
-
76
- /**
77
- * Fact — a single normalized claim derived from a session.
78
- *
79
- * The product treats sessions as the unit of operator recall. Facts are the
80
- * agent-facing projection: queryable by (subject, predicate), supersedence-
81
- * aware, with provenance back to the session they came from. See
82
- * docs/plans/factstore-design.md for the full design rationale.
83
- *
84
- * `kind` mirrors the marker taxonomy plus a third category for entity
85
- * attributes ("mac-pro-llm-host" + "endpoint" + "http://macpro:8080/v1").
86
- *
87
- * `subject` and `predicate` are normalized (lowercased, trimmed) at extraction
88
- * time so the deterministic supersedence path can do exact-match collision
89
- * detection without per-query normalization.
90
- *
91
- * `supersededBy` is a tombstone pointer — when a newer fact replaces this one
92
- * the old row stays and gets pointed at the new id. Never deleted.
93
- */
94
- export type FactKind = "decision" | "open" | "attribute";
95
-
96
- export interface Fact {
97
- readonly id: string;
98
- readonly kind: FactKind;
99
- readonly subject: string;
100
- readonly predicate: string;
101
- readonly value: string;
102
- readonly sourceSessionId: string;
103
- readonly sourceQuote: string | null;
104
- readonly createdAt: string;
105
- readonly supersededBy: string | null;
106
- readonly confidence: number;
107
- }
108
-
109
- export type FactMatchField = "value" | "subject" | "predicate" | "semantic";
110
-
111
- export interface FactRecallQuery {
112
- readonly query?: string;
113
- readonly subject?: string;
114
- readonly predicate?: string;
115
- readonly kind?: FactKind;
116
- readonly includeSuperseded?: boolean;
117
- readonly minConfidence?: number;
118
- readonly mode?: RecallMode;
119
- readonly limit?: number;
120
- }
121
-
122
- export interface FactHit extends Fact {
123
- readonly matchScore: number;
124
- readonly matchedIn: ReadonlyArray<FactMatchField>;
125
- readonly keywordScore?: number;
126
- readonly semanticScore?: number;
127
- }
128
-
129
- export interface FactRecallResult {
130
- readonly query: string;
131
- readonly subject: string | null;
132
- readonly predicate: string | null;
133
- readonly kind: FactKind | null;
134
- readonly mode: RecallMode;
135
- readonly limit: number;
136
- readonly total: number;
137
- readonly results: ReadonlyArray<FactHit>;
138
- readonly modeUnavailable?: "ollama_unreachable";
139
- }
140
-
141
- export interface FactHistoryChain {
142
- readonly subject: string;
143
- readonly predicate: string;
144
- readonly history: ReadonlyArray<Fact>;
145
- }
package/src/ui/App.tsx DELETED
@@ -1,58 +0,0 @@
1
- import { Navigate, Route, Routes, useLocation } from "react-router-dom";
2
- import { SideNav } from "./components/SideNav.js";
3
- import { LivePage } from "./pages/Live.js";
4
- import { PulsePage } from "./pages/Pulse.js";
5
- import { RiverPage } from "./pages/River.js";
6
- import { SearchPage } from "./pages/Search.js";
7
- import { ThreadPage } from "./pages/Thread.js";
8
- import { RecallPage } from "./pages/Recall.js";
9
- import { SettingsIndexPage } from "./pages/settings/Index.js";
10
- import { SettingsDataPage } from "./pages/settings/Data.js";
11
- import { SettingsViewsPage } from "./pages/settings/Views.js";
12
- import { SettingsLabelsPage } from "./pages/settings/Labels.js";
13
- import { SettingsClassifierPage } from "./pages/settings/Classifier.js";
14
- import { SettingsSourcesPage } from "./pages/settings/Sources.js";
15
- import { SettingsProvidersPage } from "./pages/settings/Providers.js";
16
- import { StubPage } from "./pages/Stub.js";
17
- import { readViewSettings } from "./lib/view-settings.js";
18
-
19
- export function App() {
20
- return (
21
- <div className="page-shell">
22
- <SideNav />
23
- <div className="page-main">
24
- <AppHeader />
25
- <Routes>
26
- <Route path="/" element={<Navigate to={`/${readViewSettings().landing}`} replace />} />
27
- <Route path="/live" element={<LivePage />} />
28
- <Route path="/pulse" element={<PulsePage />} />
29
- <Route path="/river" element={<RiverPage />} />
30
- <Route path="/thread" element={<ThreadPage />} />
31
- <Route path="/search" element={<SearchPage />} />
32
- <Route path="/recall" element={<RecallPage />} />
33
- <Route path="/settings" element={<SettingsIndexPage />} />
34
- <Route path="/settings/sources" element={<SettingsSourcesPage />} />
35
- <Route path="/settings/providers" element={<SettingsProvidersPage />} />
36
- <Route path="/settings/labels" element={<SettingsLabelsPage />} />
37
- <Route path="/settings/classifier" element={<SettingsClassifierPage />} />
38
- <Route path="/settings/data" element={<SettingsDataPage />} />
39
- <Route path="/settings/views" element={<SettingsViewsPage />} />
40
- <Route path="*" element={<StubPage page="not found" />} />
41
- </Routes>
42
- </div>
43
- </div>
44
- );
45
- }
46
-
47
- function AppHeader() {
48
- const { pathname } = useLocation();
49
- const page = pathname.replace(/^\//, "").replace(/\/+$/, "") || "live";
50
- return (
51
- <header className="app-header">
52
- <span className="wordmark-page">{page}</span>
53
- <span className="header-spacer" />
54
- <span className="status-dot" aria-hidden="true" />
55
- <span className="header-info">nlm-memory · :3940</span>
56
- </header>
57
- );
58
- }
@@ -1,65 +0,0 @@
1
- import { useState } from "react";
2
- import { postAction } from "../lib/actions.js";
3
-
4
- interface PromoteOpenButtonProps {
5
- openId: string;
6
- defaultText: string;
7
- onPromoted: () => void | Promise<void>;
8
- }
9
-
10
- /**
11
- * Inline "flip → decision" control for an open question.
12
- * Click → expands a small editor pre-filled with the original text;
13
- * the user accepts as-is or rewords, then submits. POSTs a
14
- * `promote_open` action which the dataset overlay projects as a
15
- * decision on the next read.
16
- */
17
- export function PromoteOpenButton({ openId, defaultText, onPromoted }: PromoteOpenButtonProps) {
18
- const [editing, setEditing] = useState(false);
19
- const [busy, setBusy] = useState(false);
20
- const [value, setValue] = useState(defaultText);
21
-
22
- const submit = async () => {
23
- const resolution = value.trim();
24
- if (!resolution) return;
25
- setBusy(true);
26
- try {
27
- await postAction({
28
- kind: "promote_open",
29
- subject_type: "open_question",
30
- subject_id: openId,
31
- payload: { resolution, original_text: defaultText },
32
- });
33
- await onPromoted();
34
- setEditing(false);
35
- } catch {
36
- setBusy(false);
37
- }
38
- };
39
-
40
- if (!editing) {
41
- return (
42
- <button type="button" className="chip promote-chip" onClick={() => { setValue(defaultText); setEditing(true); }}>
43
- → decision
44
- </button>
45
- );
46
- }
47
-
48
- return (
49
- <div className="promote-editor" onClick={(e) => e.stopPropagation()}>
50
- <input
51
- className="form-input form-input-inline promote-input"
52
- value={value}
53
- onChange={(e) => setValue(e.target.value)}
54
- onKeyDown={(e) => {
55
- if (e.key === "Enter") { e.preventDefault(); void submit(); }
56
- if (e.key === "Escape") { e.preventDefault(); setEditing(false); }
57
- }}
58
- disabled={busy}
59
- autoFocus
60
- />
61
- <button type="button" className="chip" onClick={() => void submit()} disabled={busy || !value.trim()}>save</button>
62
- <button type="button" className="chip" onClick={() => setEditing(false)} disabled={busy}>cancel</button>
63
- </div>
64
- );
65
- }
@@ -1,136 +0,0 @@
1
- /**
2
- * SessionDrawer — right-side detail panel for a single session.
3
- * Fetches /api/session/:id on open. Shared between Thread (entity timeline)
4
- * and Pulse (Recent sessions) — and ready for any future caller.
5
- */
6
-
7
- import { useEffect, useState } from "react";
8
- import { Link } from "react-router-dom";
9
- import { SessionDrawerSkeleton } from "./Skeleton.js";
10
-
11
- interface SessionDetail {
12
- id: string;
13
- label: string;
14
- summary: string;
15
- body: string;
16
- status: string;
17
- startedAt: string | null;
18
- endedAt: string | null;
19
- durationMin: number | null;
20
- runtime: string;
21
- entities: string[];
22
- decisions: string[];
23
- open: string[];
24
- }
25
-
26
- interface SessionDrawerProps {
27
- sessionId: string;
28
- onClose: () => void;
29
- /** Optional dot color (Thread passes the entity color). */
30
- entityColor?: string;
31
- }
32
-
33
- export function SessionDrawer({ sessionId, onClose, entityColor }: SessionDrawerProps) {
34
- const [session, setSession] = useState<SessionDetail | null>(null);
35
- const [error, setError] = useState<string | null>(null);
36
-
37
- useEffect(() => {
38
- setSession(null);
39
- setError(null);
40
- fetch(`/api/session/${encodeURIComponent(sessionId)}`)
41
- .then(async (r) => {
42
- if (!r.ok) throw new Error(`HTTP ${r.status}`);
43
- const raw = (await r.json()) as Record<string, unknown>;
44
- setSession({
45
- id: String(raw["id"] ?? sessionId),
46
- label: String(raw["label"] ?? ""),
47
- summary: String(raw["summary"] ?? ""),
48
- body: String(raw["body"] ?? ""),
49
- status: String(raw["status"] ?? "closed"),
50
- startedAt: typeof raw["startedAt"] === "string" ? (raw["startedAt"] as string) : null,
51
- endedAt: typeof raw["endedAt"] === "string" ? (raw["endedAt"] as string) : null,
52
- durationMin: typeof raw["durationMin"] === "number" ? (raw["durationMin"] as number) : null,
53
- runtime: String(raw["runtime"] ?? ""),
54
- entities: Array.isArray(raw["entities"]) ? (raw["entities"] as string[]) : [],
55
- decisions: Array.isArray(raw["decisions"]) ? (raw["decisions"] as string[]) : [],
56
- open: Array.isArray(raw["open"]) ? (raw["open"] as string[]) : [],
57
- });
58
- })
59
- .catch((e: unknown) => setError(e instanceof Error ? e.message : String(e)));
60
- }, [sessionId]);
61
-
62
- useEffect(() => {
63
- const onEsc = (e: KeyboardEvent) => { if (e.key === "Escape") onClose(); };
64
- window.addEventListener("keydown", onEsc);
65
- return () => window.removeEventListener("keydown", onEsc);
66
- }, [onClose]);
67
-
68
- return (
69
- <>
70
- <div className="drawer-backdrop" onClick={onClose} />
71
- <aside className="session-drawer" role="dialog" aria-modal="true">
72
- <header className="drawer-head">
73
- {entityColor && <span className="dot" style={{ background: entityColor }} />}
74
- <h3 className="drawer-title">{session?.label ?? sessionId}</h3>
75
- <button type="button" className="drawer-close" onClick={onClose} aria-label="Close">×</button>
76
- </header>
77
- {error && <div className="muted error drawer-body">{error}</div>}
78
- {!session && !error && <SessionDrawerSkeleton />}
79
- {session && (
80
- <div className="drawer-body">
81
- <dl className="kv-list">
82
- <dt className="kv-label">Status</dt>
83
- <dd className="kv-value"><span className={`chip-inline status-${session.status}`}>{session.status}</span></dd>
84
- <dt className="kv-label">Started</dt>
85
- <dd className="kv-value mono small">{session.startedAt ?? "—"}</dd>
86
- <dt className="kv-label">Duration</dt>
87
- <dd className="kv-value">{session.durationMin ?? "—"} min</dd>
88
- <dt className="kv-label">Runtime</dt>
89
- <dd className="kv-value mono small">{session.runtime}</dd>
90
- <dt className="kv-label">Session ID</dt>
91
- <dd className="kv-value mono small">{session.id}</dd>
92
- </dl>
93
- {session.entities.length > 0 && (
94
- <>
95
- <h4 className="drawer-section">Entities</h4>
96
- <div className="entity-chips">
97
- {session.entities.map((e) => (
98
- <Link key={e} to={`/thread?entity=${encodeURIComponent(e)}`} className="chip" onClick={onClose}>{e}</Link>
99
- ))}
100
- </div>
101
- </>
102
- )}
103
- {session.decisions.length > 0 && (
104
- <>
105
- <h4 className="drawer-section">Decisions</h4>
106
- <ul className="drawer-list">
107
- {session.decisions.map((d, i) => <li key={i}><span className="live-tag" data-kind="decision">decision</span> {d}</li>)}
108
- </ul>
109
- </>
110
- )}
111
- {session.open.length > 0 && (
112
- <>
113
- <h4 className="drawer-section">Open questions</h4>
114
- <ul className="drawer-list">
115
- {session.open.map((q, i) => <li key={i}><span className="live-tag" data-kind="open">open</span> {q}</li>)}
116
- </ul>
117
- </>
118
- )}
119
- {session.summary && (
120
- <>
121
- <h4 className="drawer-section">Summary</h4>
122
- <p className="drawer-paragraph">{session.summary}</p>
123
- </>
124
- )}
125
- {session.body && (
126
- <>
127
- <h4 className="drawer-section">Transcript excerpt</h4>
128
- <pre className="drawer-body-text">{session.body.slice(0, 3000)}{session.body.length > 3000 ? "\n\n[…truncated]" : ""}</pre>
129
- </>
130
- )}
131
- </div>
132
- )}
133
- </aside>
134
- </>
135
- );
136
- }
@@ -1,162 +0,0 @@
1
- import { useEffect, useState } from "react";
2
- import { NavLink } from "react-router-dom";
3
-
4
- const STORAGE_KEY = "nlm.sidenav.collapsed";
5
-
6
- interface NavItem {
7
- to: string;
8
- label: string;
9
- icon: JSX.Element;
10
- }
11
-
12
- const NAV_ITEMS: NavItem[] = [
13
- { to: "/live", label: "Live", icon: liveIcon() },
14
- { to: "/pulse", label: "Pulse", icon: pulseIcon() },
15
- { to: "/river", label: "River", icon: riverIcon() },
16
- { to: "/thread", label: "Thread", icon: threadIcon() },
17
- { to: "/search", label: "Search", icon: searchIcon() },
18
- { to: "/recall", label: "Recall", icon: recallIcon() },
19
- { to: "/settings", label: "Settings", icon: settingsIcon() },
20
- ];
21
-
22
- export function SideNav() {
23
- const [collapsed, setCollapsed] = useState<boolean>(() => {
24
- if (typeof window === "undefined") return false;
25
- return window.localStorage.getItem(STORAGE_KEY) === "1";
26
- });
27
-
28
- useEffect(() => {
29
- document.body.style.setProperty("--sidenav-w", collapsed ? "52px" : "180px");
30
- window.localStorage.setItem(STORAGE_KEY, collapsed ? "1" : "0");
31
- }, [collapsed]);
32
-
33
- return (
34
- <nav className={`sidenav${collapsed ? " collapsed" : ""}`} aria-label="Primary navigation">
35
- <div className="sidenav-header">
36
- <span className="sidenav-wordmark">NLM</span>
37
- <button
38
- className="sidenav-toggle"
39
- aria-label="Toggle sidebar"
40
- onClick={() => setCollapsed((c) => !c)}
41
- >
42
- {collapsed ? chevronRight() : chevronLeft()}
43
- </button>
44
- </div>
45
-
46
- <div className="sidenav-items">
47
- {NAV_ITEMS.map((item) => (
48
- <NavLink
49
- key={item.to}
50
- to={item.to}
51
- className={({ isActive }) => `sidenav-item${isActive ? " active" : ""}`}
52
- data-label={item.label}
53
- >
54
- <span className="item-icon">{item.icon}</span>
55
- <span className="item-label">{item.label}</span>
56
- </NavLink>
57
- ))}
58
- </div>
59
-
60
- <div className="sidenav-footer">
61
- <NavLink to="/settings/data" className="sidenav-item sidenav-data" data-label="Data">
62
- <span className="item-icon">{dataIcon()}</span>
63
- <span className="item-label">Data</span>
64
- </NavLink>
65
- </div>
66
- </nav>
67
- );
68
- }
69
-
70
- // ── icons — extracted verbatim from Astro SideNav for visual parity ──────
71
-
72
- function svg(children: JSX.Element, size = 16) {
73
- return (
74
- <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={1.75} strokeLinecap="round" strokeLinejoin="round">
75
- {children}
76
- </svg>
77
- );
78
- }
79
-
80
- function liveIcon() {
81
- // green-dot broadcast — distinct from pulse so /live reads as its own thing
82
- return svg(
83
- <>
84
- <circle cx="12" cy="12" r="3" />
85
- <path d="M19 12a7 7 0 00-14 0M22 12a10 10 0 00-20 0" />
86
- </>,
87
- );
88
- }
89
-
90
- function pulseIcon() {
91
- return svg(<polyline points="22 12 18 12 15 21 9 3 6 12 2 12" />);
92
- }
93
-
94
- function riverIcon() {
95
- return svg(<path d="M2 12c1.5-3 3-4.5 4.5-4.5S9 9 10.5 12s3 4.5 4.5 4.5S18 15 19.5 12 21 7.5 22 7.5" />);
96
- }
97
-
98
- function threadIcon() {
99
- return svg(
100
- <>
101
- <line x1="6" y1="3" x2="6" y2="15" />
102
- <circle cx="18" cy="6" r="3" />
103
- <circle cx="6" cy="18" r="3" />
104
- <path d="M18 9a9 9 0 01-9 9" />
105
- </>,
106
- );
107
- }
108
-
109
- function searchIcon() {
110
- return svg(
111
- <>
112
- <circle cx="11" cy="11" r="8" />
113
- <line x1="21" y1="21" x2="16.65" y2="16.65" />
114
- </>,
115
- );
116
- }
117
-
118
- function recallIcon() {
119
- // bar-chart — observability / adoption telemetry
120
- return svg(
121
- <>
122
- <line x1="6" y1="20" x2="6" y2="13" />
123
- <line x1="12" y1="20" x2="12" y2="4" />
124
- <line x1="18" y1="20" x2="18" y2="9" />
125
- </>,
126
- );
127
- }
128
-
129
- function settingsIcon() {
130
- return svg(
131
- <>
132
- <path d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" />
133
- <circle cx="12" cy="12" r="3" />
134
- </>,
135
- );
136
- }
137
-
138
- function dataIcon() {
139
- return (
140
- <svg width={14} height={14} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={1.75} strokeLinecap="round" strokeLinejoin="round">
141
- <ellipse cx="12" cy="5" rx="9" ry="3" />
142
- <path d="M21 12c0 1.657-4.03 3-9 3S3 13.657 3 12" />
143
- <path d="M3 5v14c0 1.657 4.03 3 9 3s9-1.343 9-3V5" />
144
- </svg>
145
- );
146
- }
147
-
148
- function chevronLeft() {
149
- return (
150
- <svg width={14} height={14} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round">
151
- <polyline points="15 18 9 12 15 6" />
152
- </svg>
153
- );
154
- }
155
-
156
- function chevronRight() {
157
- return (
158
- <svg width={14} height={14} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round">
159
- <polyline points="9 18 15 12 9 6" />
160
- </svg>
161
- );
162
- }