nlm-memory 0.5.0 → 0.5.2

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 (257) hide show
  1. package/README.md +89 -34
  2. package/dist/cli/digest.d.ts +20 -0
  3. package/dist/cli/digest.js +142 -0
  4. package/dist/cli/digest.js.map +1 -0
  5. package/dist/cli/nlm.d.ts +1 -0
  6. package/dist/cli/nlm.js +25 -1
  7. package/dist/cli/nlm.js.map +1 -1
  8. package/dist/core/digest/compose.d.ts +38 -0
  9. package/dist/core/digest/compose.js +93 -0
  10. package/dist/core/digest/compose.js.map +1 -0
  11. package/dist/core/digest/hook-liveness.d.ts +32 -0
  12. package/dist/core/digest/hook-liveness.js +54 -0
  13. package/dist/core/digest/hook-liveness.js.map +1 -0
  14. package/dist/http/app.js +2 -1
  15. package/dist/http/app.js.map +1 -1
  16. package/dist/mcp/server.js +20 -1
  17. package/dist/mcp/server.js.map +1 -1
  18. package/dist/ui/assets/{index-C8cpwbYJ.css → index-Beo8psd-.css} +1 -1
  19. package/dist/ui/assets/{index-CB50QnL-.js → index-CSPTTeeM.js} +8 -8
  20. package/dist/ui/index.html +2 -2
  21. package/package.json +26 -1
  22. package/.agents/plugins/marketplace.json +0 -20
  23. package/.github/workflows/ci.yml +0 -30
  24. package/docs/methodology/re-derivation-rate.md +0 -112
  25. package/docs/methodology/useful-hit-rate.md +0 -79
  26. package/docs/plans/2026-05-20-fts5-lexical-recall.md +0 -1088
  27. package/docs/plans/2026-05-20-recall-daemon-wedge-fix.md +0 -662
  28. package/docs/plans/2026-05-20-recall-hook-design.md +0 -131
  29. package/docs/plans/2026-05-20-recall-hook-implementation.md +0 -1222
  30. package/docs/plans/desktop-product.md +0 -69
  31. package/docs/plans/factstore-design.md +0 -236
  32. package/logs/CHANGELOG/CHANGELOG-2026.md +0 -1575
  33. package/logs/CHANGELOG/CHANGELOG.md +0 -209
  34. package/migrations/000_initial_schema.sql +0 -174
  35. package/migrations/001_entity_type_rename.sql +0 -17
  36. package/migrations/002_adapter_state_extend.sql +0 -12
  37. package/migrations/003_session_embeddings.sql +0 -11
  38. package/migrations/004_facts.sql +0 -46
  39. package/migrations/005_sources.sql +0 -31
  40. package/migrations/006_providers.sql +0 -33
  41. package/migrations/007_source_tokens.sql +0 -17
  42. package/migrations/008_fts_rebuild.sql +0 -9
  43. package/migrations/009_session_embedding_chunks.sql +0 -46
  44. package/migrations/010_sources_opencode.sql +0 -30
  45. package/migrations/011_sources_hermes_agent.sql +0 -30
  46. package/migrations/012_sources_aider.sql +0 -30
  47. package/migrations/013_adapter_state_failure_count.sql +0 -12
  48. package/migrations/014_sources_cursor.sql +0 -30
  49. package/migrations/015_sources_windsurf.sql +0 -30
  50. package/plugin-hermes-agent/README.md +0 -49
  51. package/plugin-hermes-agent/__init__.py +0 -75
  52. package/plugin-hermes-agent/plugin.yaml +0 -15
  53. package/scripts/backfill-citations.mjs +0 -0
  54. package/scripts/build-codex-plugin.mjs +0 -61
  55. package/scripts/deepseek-probe.mjs +0 -67
  56. package/scripts/extract-triples.mjs +0 -207
  57. package/scripts/longmemeval/embedding-cache.ts +0 -77
  58. package/scripts/longmemeval/fetch-dataset.sh +0 -25
  59. package/scripts/longmemeval/run-harness.ts +0 -315
  60. package/scripts/longmemeval/scorer.ts +0 -99
  61. package/scripts/longmemeval/tsconfig.json +0 -9
  62. package/scripts/longmemeval/types.ts +0 -35
  63. package/scripts/nlm-daily-digest.py +0 -239
  64. package/scripts/nlm-daily-digest.sh +0 -28
  65. package/src/cli/classify-parity.ts +0 -257
  66. package/src/cli/launchctl-helpers.ts +0 -49
  67. package/src/cli/nlm.ts +0 -1078
  68. package/src/core/actions/actions-log.ts +0 -118
  69. package/src/core/actions/overlay.ts +0 -117
  70. package/src/core/adapters/aider.ts +0 -205
  71. package/src/core/adapters/claude-code.ts +0 -293
  72. package/src/core/adapters/common.ts +0 -54
  73. package/src/core/adapters/cursor.ts +0 -486
  74. package/src/core/adapters/from-source.ts +0 -67
  75. package/src/core/adapters/hermes-agent.ts +0 -240
  76. package/src/core/adapters/hermes.ts +0 -277
  77. package/src/core/adapters/jsonl-generic.ts +0 -208
  78. package/src/core/adapters/opencode.ts +0 -281
  79. package/src/core/adapters/pi.ts +0 -264
  80. package/src/core/adapters/windsurf.ts +0 -386
  81. package/src/core/classifier/prompt.ts +0 -200
  82. package/src/core/dataset/build-dataset.ts +0 -463
  83. package/src/core/embedding/chunk-body.ts +0 -76
  84. package/src/core/embedding/embed-backfill.ts +0 -210
  85. package/src/core/embedding/embed-normalize.ts +0 -135
  86. package/src/core/facts/backfill-facts.ts +0 -254
  87. package/src/core/facts/extract-facts.ts +0 -50
  88. package/src/core/hook/citation-detect.ts +0 -124
  89. package/src/core/hook/cite-memo.ts +0 -68
  90. package/src/core/hook/claude-settings.ts +0 -187
  91. package/src/core/hook/gate.ts +0 -25
  92. package/src/core/hook/hook-log.ts +0 -41
  93. package/src/core/hook/memo-sweep.ts +0 -164
  94. package/src/core/hook/memo.ts +0 -67
  95. package/src/core/hook/pointer-block.ts +0 -26
  96. package/src/core/hook/select.ts +0 -32
  97. package/src/core/hook/transcript.ts +0 -121
  98. package/src/core/ingest/ingest-session.ts +0 -111
  99. package/src/core/providers/provider-models.ts +0 -100
  100. package/src/core/providers/provider-registry.ts +0 -196
  101. package/src/core/recall/citation-log.ts +0 -108
  102. package/src/core/recall/filter.ts +0 -27
  103. package/src/core/recall/index.ts +0 -6
  104. package/src/core/recall/match-fields.ts +0 -40
  105. package/src/core/recall/query-log.ts +0 -149
  106. package/src/core/recall/query-shape.ts +0 -66
  107. package/src/core/recall/recall-service.ts +0 -320
  108. package/src/core/recall/recent-log.ts +0 -59
  109. package/src/core/recall/tokenize.ts +0 -18
  110. package/src/core/recall/useful-scan.ts +0 -336
  111. package/src/core/recall-facts/fact-query-log.ts +0 -150
  112. package/src/core/recall-facts/fact-recall-service.ts +0 -327
  113. package/src/core/scheduler/scan-once.ts +0 -142
  114. package/src/core/scheduler/scheduler.ts +0 -225
  115. package/src/core/sources/source-registry.ts +0 -278
  116. package/src/core/storage/db-restore.ts +0 -133
  117. package/src/core/storage/live-status.ts +0 -45
  118. package/src/core/storage/migrate.ts +0 -72
  119. package/src/core/storage/sqlite-fact-store.ts +0 -304
  120. package/src/core/storage/sqlite-session-store.ts +0 -810
  121. package/src/hook/hook-auth.ts +0 -18
  122. package/src/hook/prompt-recall-hook.ts +0 -180
  123. package/src/hook/session-end-hook.ts +0 -81
  124. package/src/hook/session-start-hook.ts +0 -168
  125. package/src/hook/stop-hook.ts +0 -239
  126. package/src/http/app.ts +0 -1215
  127. package/src/install/claude-code.ts +0 -128
  128. package/src/install/codex.ts +0 -367
  129. package/src/install/cursor.ts +0 -68
  130. package/src/install/hermes-agent.ts +0 -76
  131. package/src/install/hermes.ts +0 -78
  132. package/src/install/nlm-dir-perms.ts +0 -55
  133. package/src/install/ollama.ts +0 -284
  134. package/src/install/setup.ts +0 -489
  135. package/src/install/windsurf.ts +0 -68
  136. package/src/llm/classifier-box.ts +0 -64
  137. package/src/llm/deepseek-client.ts +0 -150
  138. package/src/llm/env-autoload.ts +0 -55
  139. package/src/llm/ollama-client.ts +0 -189
  140. package/src/mcp/server.ts +0 -534
  141. package/src/ports/fact-store.ts +0 -102
  142. package/src/ports/llm-client.ts +0 -52
  143. package/src/ports/logger.ts +0 -16
  144. package/src/ports/session-store.ts +0 -45
  145. package/src/ports/transcript-adapter.ts +0 -55
  146. package/src/shared/types.ts +0 -149
  147. package/src/ui/App.tsx +0 -58
  148. package/src/ui/components/PromoteOpenButton.tsx +0 -65
  149. package/src/ui/components/SessionDrawer.tsx +0 -199
  150. package/src/ui/components/SideNav.tsx +0 -162
  151. package/src/ui/components/Skeleton.tsx +0 -107
  152. package/src/ui/index.html +0 -13
  153. package/src/ui/lib/actions.ts +0 -30
  154. package/src/ui/lib/api.ts +0 -92
  155. package/src/ui/lib/dataset.ts +0 -141
  156. package/src/ui/lib/registries.ts +0 -155
  157. package/src/ui/lib/view-settings.ts +0 -41
  158. package/src/ui/main.tsx +0 -15
  159. package/src/ui/pages/Live.tsx +0 -229
  160. package/src/ui/pages/Pulse.tsx +0 -415
  161. package/src/ui/pages/Recall.tsx +0 -190
  162. package/src/ui/pages/River.tsx +0 -354
  163. package/src/ui/pages/Search.tsx +0 -386
  164. package/src/ui/pages/Stub.tsx +0 -9
  165. package/src/ui/pages/Thread.tsx +0 -473
  166. package/src/ui/pages/settings/Classifier.tsx +0 -227
  167. package/src/ui/pages/settings/Data.tsx +0 -190
  168. package/src/ui/pages/settings/Index.tsx +0 -65
  169. package/src/ui/pages/settings/Labels.tsx +0 -224
  170. package/src/ui/pages/settings/Providers.tsx +0 -305
  171. package/src/ui/pages/settings/SettingsSubnav.tsx +0 -28
  172. package/src/ui/pages/settings/Sources.tsx +0 -326
  173. package/src/ui/pages/settings/Views.tsx +0 -96
  174. package/src/ui/styles.css +0 -1890
  175. package/src/ui/tsconfig.json +0 -21
  176. package/src/ui/vite.config.ts +0 -19
  177. package/tests/fixtures/claude_code/short_session.jsonl +0 -2
  178. package/tests/fixtures/claude_code/standard_iso.jsonl +0 -4
  179. package/tests/fixtures/claude_code/tool_heavy.jsonl +0 -8
  180. package/tests/fixtures/claude_code/with_subagent.jsonl +0 -7
  181. package/tests/fixtures/facts.ts +0 -17
  182. package/tests/fixtures/golden-corpus.ts +0 -85
  183. package/tests/fixtures/hermes/paired_request_dump.json +0 -24
  184. package/tests/fixtures/hermes/paired_session.json +0 -23
  185. package/tests/fixtures/hermes/request_dump.json +0 -28
  186. package/tests/fixtures/hermes/session_iso.json +0 -38
  187. package/tests/fixtures/hermes/session_unix.json +0 -38
  188. package/tests/fixtures/hermes/system_only.json +0 -18
  189. package/tests/fixtures/pi/error-connection-abort.jsonl +0 -8
  190. package/tests/fixtures/pi/short-successful.jsonl +0 -5
  191. package/tests/fixtures/pi/with-custom-message.jsonl +0 -6
  192. package/tests/fixtures/sessions.ts +0 -22
  193. package/tests/integration/backfill-facts.test.ts +0 -362
  194. package/tests/integration/citation-explicit.test.ts +0 -111
  195. package/tests/integration/cite-event.test.ts +0 -169
  196. package/tests/integration/cite-memo.test.ts +0 -87
  197. package/tests/integration/db-restore.test.ts +0 -153
  198. package/tests/integration/embed-backfill.test.ts +0 -176
  199. package/tests/integration/fact-supersedence.test.ts +0 -313
  200. package/tests/integration/fts-index.test.ts +0 -60
  201. package/tests/integration/getbyids-sqlite.test.ts +0 -100
  202. package/tests/integration/hermes-agent-hooks.test.ts +0 -248
  203. package/tests/integration/hook-claude-settings.test.ts +0 -218
  204. package/tests/integration/hook-log.test.ts +0 -54
  205. package/tests/integration/hook-memo.test.ts +0 -68
  206. package/tests/integration/hook-pre-compact.test.ts +0 -105
  207. package/tests/integration/hook-subagent-start.test.ts +0 -102
  208. package/tests/integration/http.test.ts +0 -401
  209. package/tests/integration/keyword-search-fts.test.ts +0 -66
  210. package/tests/integration/mcp-recall-logging.test.ts +0 -88
  211. package/tests/integration/mcp.test.ts +0 -260
  212. package/tests/integration/memo-sweep.test.ts +0 -91
  213. package/tests/integration/prompt-recall-hook.test.ts +0 -88
  214. package/tests/integration/provider-registry.test.ts +0 -107
  215. package/tests/integration/recall-golden.test.ts +0 -59
  216. package/tests/integration/recall-sqlite.test.ts +0 -169
  217. package/tests/integration/scheduler.test.ts +0 -391
  218. package/tests/integration/session-end-hook.test.ts +0 -48
  219. package/tests/integration/session-start-hook.test.ts +0 -126
  220. package/tests/integration/source-registry.test.ts +0 -122
  221. package/tests/integration/sqlite-fact-store.test.ts +0 -346
  222. package/tests/integration/stop-hook.test.ts +0 -560
  223. package/tests/integration/wal-checkpoint.test.ts +0 -49
  224. package/tests/unit/cli/launchctl-helpers.test.ts +0 -60
  225. package/tests/unit/core/adapters/aider.test.ts +0 -230
  226. package/tests/unit/core/adapters/claude-code.test.ts +0 -118
  227. package/tests/unit/core/adapters/cursor.test.ts +0 -485
  228. package/tests/unit/core/adapters/hermes-agent.test.ts +0 -329
  229. package/tests/unit/core/adapters/hermes.test.ts +0 -81
  230. package/tests/unit/core/adapters/jsonl-generic.test.ts +0 -142
  231. package/tests/unit/core/adapters/opencode.test.ts +0 -354
  232. package/tests/unit/core/adapters/pi.test.ts +0 -110
  233. package/tests/unit/core/adapters/windsurf.test.ts +0 -416
  234. package/tests/unit/core/classifier/prompt.test.ts +0 -126
  235. package/tests/unit/core/embedding/chunk-body.test.ts +0 -100
  236. package/tests/unit/core/facts/extract-facts.test.ts +0 -117
  237. package/tests/unit/core/filter.test.ts +0 -40
  238. package/tests/unit/core/hook/citation-detect-cite-session.test.ts +0 -96
  239. package/tests/unit/core/hook/citation-detect.test.ts +0 -124
  240. package/tests/unit/core/hook/gate.test.ts +0 -29
  241. package/tests/unit/core/hook/pointer-block.test.ts +0 -22
  242. package/tests/unit/core/hook/select.test.ts +0 -66
  243. package/tests/unit/core/match-fields.test.ts +0 -39
  244. package/tests/unit/core/mcp-cite-session.test.ts +0 -51
  245. package/tests/unit/core/providers/provider-models.test.ts +0 -101
  246. package/tests/unit/core/query-shape.test.ts +0 -92
  247. package/tests/unit/core/recall-facts/fact-recall-service.test.ts +0 -258
  248. package/tests/unit/core/recall-service.test.ts +0 -200
  249. package/tests/unit/core/storage/live-status.test.ts +0 -54
  250. package/tests/unit/core/tokenize.test.ts +0 -32
  251. package/tests/unit/core/useful-scan.test.ts +0 -537
  252. package/tests/unit/llm/embed.test.ts +0 -93
  253. package/tests/unit/llm/ollama-client.test.ts +0 -124
  254. package/tests/unit/scripts/longmemeval-scorer.test.ts +0 -114
  255. package/tsconfig.json +0 -31
  256. package/tsconfig.test.json +0 -11
  257. package/vitest.config.ts +0 -22
@@ -1,69 +0,0 @@
1
- # NLM desktop product — phased plan
2
-
3
- **Product name.** NLM (Non-Linear Memory). The repo / package / internal modules keep their current `nle-memory` codename — renaming code is a separate, invasive task that doesn't block the product. User-facing strings (window title, installer, landing page, README hero) use NLM.
4
-
5
- **License.** MIT. Free on GitHub, anyone can fork or vendor.
6
-
7
- **Distribution.** GitHub Releases. Skipping app stores for now (review overhead, Apple's 30%, slower iteration).
8
-
9
- **Pricing.** Free forever. Open source.
10
-
11
- **Goal.** Ship NLM as a local-first desktop app others can install and use. Single-user-per-instance. SQLite on the user's disk. No SaaS infra, no auth, no multi-tenancy.
12
-
13
- **Why desktop.** Privacy story is the product (transcripts never leave the machine). Sidesteps the entire SaaS infra tax (hosting, billing, auth, compliance). Architecture leaves a multi-tenant door open if we ever want it.
14
-
15
- **Stack decision.** Tauri 2 wrapper around the existing Node daemon + Vite UI. Rust shell is ~3MB; bundles the daemon as a sidecar binary. Cross-platform (mac/windows/linux) from one codebase. Auto-update via Tauri's built-in updater. Alternative was Electron — rejected on bundle size (100MB+) and resource footprint.
16
-
17
- **Out of scope for v1.** Multi-tenant, cloud sync, mobile, fact extraction UI, RAG over transcripts, agent marketplace.
18
-
19
- ---
20
-
21
- ## Phase 0 — Architecture changes (no UI yet)
22
-
23
- Required before the UI can be config-driven. Backend-only.
24
-
25
- 1. **Sources registry.** New `sources` table: `id, kind, name, path_or_url, runtime_label, parse_config (json), enabled, created_at`. Migrate existing adapter detection to seed three default rows (`claude-code`, `hermes`, `pi`) on first boot of an empty DB.
26
- 2. **Generic JSONL adapter.** One `TranscriptAdapter` implementation that reads any directory of JSONL files using `parse_config` for field mapping. The three existing adapters become preset configs for this generic adapter.
27
- 3. **Providers registry.** New `providers` table: `id, kind, name, api_key_ref, base_url, default_model, enabled`. API keys stored in the OS keychain via Tauri's `keyring` plugin (not in SQLite). Migrate the current DeepSeek/Ollama wiring to seed default rows.
28
- 4. **Live model discovery.** Provider interface gains `listModels()`. Ollama hits `/api/tags`; OpenAI/Anthropic/OpenRouter hit `/v1/models`; DeepSeek stays hardcoded.
29
- 5. **Webhook ingest.** `POST /api/ingest` with a body conforming to the canonical session shape. Token-gated via a token stored in user prefs.
30
-
31
- **Deliverables.** Migrations, new tables, generic adapter, provider abstraction, ingest endpoint, tests. No UI changes yet.
32
-
33
- ## Phase 1 — Settings UI for sources + providers
34
-
35
- The configuration surface. Existing Settings pages get extended.
36
-
37
- 1. **Sources page** — list configured sources with status (enabled / last scanned / session count). "Add source" opens a wizard: pick preset (Claude Code / Hermes / pi.dev / Custom JSONL / Webhook). Preset auto-fills paths and parse config; user can override. Custom JSONL is a directory picker + field-mapping form.
38
- 2. **Providers page** — list configured providers with status (key present / last used / model count). "Add provider" picks kind (DeepSeek / Ollama / OpenAI / Anthropic / OpenRouter / Custom OpenAI-compatible), then prompts for key + base URL. "Test connection" button hits `listModels()` and shows results.
39
- 3. **Classifier page rewrite** — Provider/Model dropdowns now populate from configured providers, not hardcoded constants. The free-text Model fallback stays.
40
-
41
- **Deliverables.** Two new settings pages (or one expanded), provider/source CRUD endpoints, connection-test endpoint.
42
-
43
- ## Phase 2 — Tauri shell + first-run experience
44
-
45
- Make it installable.
46
-
47
- 1. **Tauri wrapper.** Bundle the Node daemon as a sidecar process. Tauri shell loads the UI at `localhost:3940/ui` in a webview. Auto-start daemon on app launch, auto-stop on quit.
48
- 2. **First-run wizard.** If `sources` table is empty: full-screen wizard. Step 1: detect presets ("We found Claude Code at ~/.claude/projects/ — enable?"). Step 2: pick a provider (skip if you only want recall + UI without ingest). Step 3: done.
49
- 3. **Auto-updater.** Tauri updater wired to a GitHub releases feed. Signed builds.
50
- 4. **Installer artifacts.** `.dmg` (mac, notarized), `.msi` (windows, signed), `.deb` + `.AppImage` (linux). CI on tag push.
51
-
52
- **Deliverables.** Tauri project, sidecar wiring, wizard UI, signed installers in GitHub Releases.
53
-
54
- ## Phase 3 — Polish for public release
55
-
56
- Things you can ship without, but probably shouldn't.
57
-
58
- 1. **Onboarding telemetry** — opt-in, anonymous: "user got past first-run wizard, has N sources, K providers." Helps you find the install funnel that bleeds the most users.
59
- 2. **Backup + restore** — one-click SQLite export. Restore from a `.nle-backup` file.
60
- 3. **Open-source license + landing page** — pick a license (MIT or AGPL — different go-to-markets), throw up a site, write the README that explains what nle-memory is in <60s.
61
- 4. **First 5 users.** Manual recruit. Watch each one install. Fix what breaks.
62
-
63
- **Deliverables.** Telemetry endpoint, backup CLI + UI button, public repo, landing page, install support for 5 users.
64
-
65
- ---
66
-
67
- ## Decisions log
68
-
69
- - **2026-05-19** — Name: NLM (Non-Linear Memory). License: MIT. Distribution: GitHub Releases. Pricing: free forever.
@@ -1,236 +0,0 @@
1
- # FactStore Design Plan (nle-memory-ts)
2
-
3
- **Deliverable target:** `/Users/echalupa/Documents/Coding Projects/nle-memory-ts/docs/plans/factstore-design.md`
4
- **Status:** Design only. No code in this pass.
5
- **Author context:** Edward Chalupa, May 2026. Phase F shipped; SqliteSessionStore is live (not pending — prompt was stale on that point).
6
-
7
- ## Context
8
-
9
- nle-memory today treats the **session** as the unit of memory. Sessions work for *operator recall* ("what did we decide about pgvector"): a digest with label, summary, decisions[], open[], entities[] is the right grain when the consumer is a human paging through their own history.
10
-
11
- Sessions are the **wrong** unit for *agent-in-loop recall*. When Claude Code mid-task needs to know "what model alias does the Mac Pro endpoint expose" or "did Edward pick Hono or Fastify," the answer is a single sentence. Returning a 6KB session digest forces the agent to re-extract the fact from prose — burning tokens and trusting an LLM read-through to find what was already extracted at ingest time.
12
-
13
- The raw signal is already captured. `src/core/classifier/prompt.ts` extracts `decisions[]`, `open[]`, `entities[]` from every transcript. Those live as denormalized arrays on the Session row. The work is **promotion**: turn those strings into first-class queryable records with their own port, store, recall path, and MCP surface — without breaking hexagonal discipline and without diluting the session-as-primary-unit differentiator (vs. Mem0's fact-soup and Graphiti's graph edges).
14
-
15
- This plan covers the seven design decisions needed to ship a FactStore alongside SessionStore. Phased rollout at the end; no Phase A.2 work is gated by this plan because SqliteSessionStore is already shipped.
16
-
17
- ---
18
-
19
- ## 1. Fact Model
20
-
21
- Minimum schema for a `Fact` record:
22
-
23
- ```ts
24
- interface Fact {
25
- id: string; // ULID
26
- kind: "decision" | "open" | "attribute";
27
- subject: string; // normalized entity or topic, lowercased
28
- predicate: string; // short verb-phrase, lowercased ("framework", "endpoint", "decided-on")
29
- value: string; // the answer, free text, sentence-ish
30
- sourceSessionId: string; // FK → sessions.id
31
- sourceQuote: string | null; // verbatim slice from session.body (provenance)
32
- createdAt: string; // ISO 8601, copied from session.endedAt
33
- supersededBy: string | null; // FK → facts.id (null = current)
34
- confidence: number; // 0..1, inherited from classifier confidence
35
- }
36
- ```
37
-
38
- **Decision:** Ship with exactly these fields. No `scope`, no `expiry`.
39
- **Why:** `scope` is implicit in `subject` (subject="mac-pro-llm-host" is its own scope). `expiry` is what `supersededBy` is for — facts don't time out, they get replaced. `confidence` earns its row because the classifier already returns it; dropping it forfeits a free signal for ranking and conflict resolution. `sourceQuote` is the cheap insurance against hallucinated extraction — when a fact looks wrong, the operator wants to see the exact line from the transcript without re-reading the whole session.
40
-
41
- Indexed on `(subject, predicate)` and `subject` alone. No `kind` index — `attribute` will dominate volume and selectivity comes from `subject`.
42
-
43
- ---
44
-
45
- ## 2. Supersedence Semantics
46
-
47
- **Decision:** Deterministic-first hybrid. On ingest, exact `(subject, predicate)` collision against an existing non-superseded fact sets the old fact's `supersededBy = new.id`. No LLM in the hot path. A separate `consolidate_facts` operator-triggered MCP tool runs LLM-driven semantic dedup over candidate clusters (same subject, no exact predicate match) when Edward explicitly asks.
48
-
49
- **Why:** Pure LLM-driven supersedence at every ingest doubles classifier cost and introduces non-determinism — bad for a local-first daemon that runs unattended on a laptop. Pure rule-driven misses "use Hono"/"chose Hono as the framework" because predicates won't match. Manual-only forfeits the obvious wins. The hybrid keeps ingest cheap and deterministic, accepts some duplicate-fact accumulation as the cost of that determinism, and gives Edward an explicit tool to clean up when he notices clusters. Supersedence is also reversible (set `supersededBy` back to null) because we keep the old row — facts are append-only with a tombstone pointer, never deleted.
50
-
51
- Predicate normalization matters here: the classifier prompt extension (Section 3) must map synonymous phrasings to a canonical predicate during extraction, or the deterministic path catches nothing. We give the LLM a closed list of ~20 common predicates ("framework", "endpoint", "model", "decided-on", "pricing", "deadline", "owner") and an "other" escape hatch. This is the same trick `entities[]` uses today — controlled vocabulary at extraction time, not at query time.
52
-
53
- ---
54
-
55
- ## 3. Ingest Path
56
-
57
- **Decision:** Extend the existing classifier prompt to return structured facts alongside the existing six fields. No new `core/fact-extractor` module, no post-ingest pass. The classifier port (`LLMClient.classify`) already runs once per session; piggyback on that call. A new pure function in `src/core/facts/extract-facts.ts` converts `ClassifyResult.facts[]` into `Fact[]` for the store.
58
-
59
- **Why:** A separate post-ingest pass means a second LLM call per session — doubles classifier cost for a marginal architectural cleanliness win. A new core module without a port means the classifier still does the work but pretends it doesn't, which is worse. The classifier prompt is already the chokepoint where "raw transcript → structured signal" happens; facts are just more structured signal. The pure-function transform stays in core, keeps the no-framework-imports rule, and is unit-testable against fake `ClassifyResult` fixtures.
60
-
61
- Classifier prompt addition (rough shape):
62
-
63
- ```
64
- "facts": [
65
- {"kind": "decision", "subject": "nle-memory-ts", "predicate": "framework", "value": "Hono"},
66
- {"kind": "attribute", "subject": "mac-pro-llm-host", "predicate": "endpoint", "value": "http://macpro:8080/v1"}
67
- ]
68
- ```
69
-
70
- The existing `decisions[]` / `open[]` / `entities[]` fields on Session stay. They are the operator-facing prose digest. Facts are the agent-facing normalized projection. Both come from the same LLM call. Duplication is intentional — sessions and facts answer different questions.
71
-
72
- Confidence cap: facts with classifier-reported confidence below 0.6 are extracted but flagged `confidence < 0.6` in queries by default (filterable). Below 0.4, dropped entirely.
73
-
74
- ---
75
-
76
- ## 4. Recall Blending
77
-
78
- **Decision:** Separate `FactRecallService.search()` and a separate MCP tool `recall_facts`. Session recall and fact recall do not blend in a unified result type. The UI (Edward browsing) gets a small enrichment — when a session result has facts attributable to it, the digest shows a fact count and a "view facts" affordance, but the primary list stays session-keyed.
79
-
80
- **Why:** The two consumers want incompatibly-shaped results. An agent calling `recall_facts(subject="mac-pro-llm-host", predicate="endpoint")` wants `[{value: "http://macpro:8080/v1", confidence: 0.9, sourceSessionId: "..."}]` — a JSON array of 1-3 items at most, no prose. Edward calling `recall_sessions("pgvector decision")` wants a ranked list of session digests with summaries. A unified `kind: session | fact` result type forces both consumers to handle a polymorphic shape, hurts both, and obscures the conceptual primacy of sessions. The "facts only surface as enrichment" option fails the agent use case — the agent shouldn't have to fetch a session to read a fact.
81
-
82
- `FactRecallService.search()` signature:
83
-
84
- ```ts
85
- interface FactQuery {
86
- subject?: string; // exact match, normalized
87
- predicate?: string; // exact match, normalized
88
- query?: string; // free-text against value, keyword + optional semantic
89
- kind?: Fact["kind"];
90
- includeSuperseded?: boolean; // default false
91
- minConfidence?: number; // default 0.6
92
- limit?: number; // default 10
93
- }
94
- ```
95
-
96
- Semantic search over `value` reuses the existing nomic-embed-text + sqlite-vec stack. Subject/predicate exact match runs first as a cheap filter; query-text scoring runs over the filtered set.
97
-
98
- ---
99
-
100
- ## 5. Storage
101
-
102
- **Decision:** Same SQLite file. New tables `facts` and `fact_embeddings (vec0)`. FactStore is a separate port (`src/ports/fact-store.ts`) with a separate adapter (`src/core/storage/sqlite-fact-store.ts`).
103
-
104
- **Why:** Two SQLite files would mean either (a) two database connections in the composition root with no cross-store transaction, or (b) attaching one to the other at runtime with all the locking surprises that brings. Atomic session-plus-facts ingest is the common case — when a transcript classifies into one session row + 4 fact rows, those should commit together or roll back together. One file, one connection, one transaction. sqlite-vec is already loaded for `session_embeddings`; reusing it for `fact_embeddings` is free.
105
-
106
- Separate port is non-negotiable for the hexagonal discipline. A future Postgres adapter implements both `SessionStore` and `FactStore` against the same connection pool; an in-memory test adapter implements only what the test needs. The port boundary is what makes core testable without a real DB.
107
-
108
- Schema sketch (illustrative — not final DDL):
109
-
110
- ```sql
111
- CREATE TABLE facts (
112
- id TEXT PRIMARY KEY,
113
- kind TEXT NOT NULL CHECK (kind IN ('decision', 'open', 'attribute')),
114
- subject TEXT NOT NULL,
115
- predicate TEXT NOT NULL,
116
- value TEXT NOT NULL,
117
- source_session_id TEXT NOT NULL REFERENCES sessions(id),
118
- source_quote TEXT,
119
- created_at TEXT NOT NULL,
120
- superseded_by TEXT REFERENCES facts(id),
121
- confidence REAL NOT NULL
122
- );
123
- CREATE INDEX idx_facts_subject_predicate ON facts(subject, predicate) WHERE superseded_by IS NULL;
124
- CREATE INDEX idx_facts_subject ON facts(subject) WHERE superseded_by IS NULL;
125
- CREATE INDEX idx_facts_session ON facts(source_session_id);
126
-
127
- CREATE VIRTUAL TABLE fact_embeddings USING vec0(
128
- fact_id TEXT PRIMARY KEY,
129
- embedding FLOAT[768]
130
- );
131
- ```
132
-
133
- Partial indexes on `superseded_by IS NULL` keep the common-case query (current facts only) on the small index.
134
-
135
- ---
136
-
137
- ## 6. MCP Surface
138
-
139
- **Decision:** Two new tools.
140
-
141
- **`recall_facts`** — primary agent surface.
142
-
143
- ```
144
- inputs:
145
- subject?: string
146
- predicate?: string
147
- query?: string
148
- kind?: "decision" | "open" | "attribute"
149
- includeSuperseded?: boolean (default false)
150
- minConfidence?: number (default 0.6)
151
- limit?: number (default 10)
152
- output:
153
- { facts: Fact[], total: number }
154
- ```
155
-
156
- **`get_fact_history`** — supersedence chain inspection.
157
-
158
- ```
159
- inputs:
160
- subject: string
161
- predicate?: string
162
- output:
163
- { chains: Array<{ subject, predicate, history: Fact[] }> } // newest → oldest
164
- ```
165
-
166
- **Why these two and not more:** `recall_facts` covers both the agent's "tell me the current value" case (subject+predicate exact) and the agent's "what do we know about X" case (subject only, or free query). `get_fact_history` covers the meta-case — "wait, was this changed recently?" — which is uncommon enough to deserve its own tool rather than a flag on the primary one. Skipping a `write_fact` MCP tool: facts are derived from sessions, not user-asserted. Manual fact insertion punctures the "sessions are primary, facts are derived" invariant and turns nle-memory into Mem0.
167
-
168
- A future `consolidate_facts(subject)` tool implements the LLM-driven semantic dedup from Section 2. Not in initial ship.
169
-
170
- ---
171
-
172
- ## 7. Migration Path
173
-
174
- **Decision:** One-shot backfill script invoked by operator. No lazy-on-read, no never. The script re-runs classifier extraction over every existing session body and writes facts. Existing `decisions[]` / `open[]` string arrays on the Session row are **not** parsed into facts directly — they go back through the classifier with the fact-extraction prompt extension, because the existing strings lack subject/predicate structure and reparsing them with regex would produce worse data than just paying the LLM cost once.
175
-
176
- **Why:** Lazy-on-read needs a "have I backfilled this session yet" flag on the session row and a write path in the read path — bad shape, hurts read latency, and the backfill never actually completes for cold sessions. Never-backfill means the FactStore is empty on day one and stays useless until enough new sessions accumulate, which for low-volume runtimes (pi, Codex) could be weeks. One-shot is honest: one LLM-cost spike, one clear before/after, one resumable script with a `last_processed_id` checkpoint. On the Mac Pro local llama-server endpoint at ~22 tok/s, backfilling Edward's session corpus (call it 2000 sessions averaging 8KB body) costs roughly 4-6 hours of wall time on idle iron. Acceptable.
177
-
178
- The script lives at `scripts/backfill-facts.ts`, takes `--from <session-id>` and `--limit N` for resumability, logs to `logs/CHANGELOG/CHANGELOG.md` on completion. It re-uses the same `LLMClient` adapter the daemon uses, so no separate inference path to maintain.
179
-
180
- Sessions ingested *during* backfill go through the normal path and write facts inline — no race because the backfill script only touches sessions older than its start timestamp.
181
-
182
- ---
183
-
184
- ## Phased Rollout
185
-
186
- **Phase B.1 — FactStore port + adapter (no extraction yet).**
187
- Ship `src/ports/fact-store.ts`, `src/core/storage/sqlite-fact-store.ts`, schema migration, unit tests with fake adapter. Composition root wires it but nothing writes to it yet. Gates nothing downstream; can ship behind any session work.
188
-
189
- **Phase B.2 — Classifier prompt extension + ingest write path.**
190
- Extend `src/core/classifier/prompt.ts` to return `facts[]`. Pure function `src/core/facts/extract-facts.ts` converts to `Fact[]`. Ingest pipeline writes facts atomically with session row. Gated on B.1. New sessions get facts; old sessions stay session-only.
191
-
192
- **Phase B.3 — FactRecallService + MCP `recall_facts` + `get_fact_history`.**
193
- Read path goes live. Agents can query. Gated on B.2 (no point shipping read if write is broken).
194
-
195
- **Phase B.4 — Supersedence-on-collision logic in ingest.**
196
- Deterministic supersedence path. Gated on B.2 (need writes happening) and a week or two of B.3 data to validate predicate normalization isn't too lossy. If predicates fragment badly, iterate the closed vocabulary before shipping supersedence — otherwise we cement bad equivalence classes.
197
-
198
- **Phase B.5 — Backfill script.**
199
- `scripts/backfill-facts.ts`. Run once. Gated on B.2 + B.4 stable (don't backfill before supersedence works or you're re-running it after).
200
-
201
- **Phase B.6 — UI surfacing (fact count on session digest).**
202
- React SPA addition. Gated on B.3. Lowest priority — agents are the primary consumer, Edward's session-browsing flow works without it.
203
-
204
- **Phase C (deferred) — `consolidate_facts` MCP tool.**
205
- LLM-driven semantic dedup, operator-triggered. Ships only after Edward reports actual duplicate clusters in production. May never ship if predicate normalization holds up.
206
-
207
- ---
208
-
209
- ## Critical Files (for the implementer in Phase B)
210
-
211
- - `src/ports/session-store.ts` — model the new `FactStore` port on this file's shape and conventions.
212
- - `src/ports/llm-client.ts` — `ClassifyResult` interface gets a new `facts?` field; existing consumers ignore it.
213
- - `src/core/classifier/prompt.ts` lines 47-83 — prompt extension lives here. Preserve the 15K char truncation and JSON validators.
214
- - `src/core/storage/sqlite-session-store.ts` — pattern for the new `sqlite-fact-store.ts`; especially the migration and the atomic insert transaction.
215
- - `src/core/recall/recall-service.ts` — pattern for `fact-recall-service.ts`. Reuse `tokenize.ts` and `score-keyword.ts`.
216
- - `src/mcp/server.ts` lines 76-108 — register `recall_facts` and `get_fact_history` next to existing tools.
217
- - `src/shared/types.ts` lines 18-34 — add `Fact` interface near `Session`.
218
-
219
- ## Verification
220
-
221
- Each phase ships with tests; ship-readiness for the FactStore as a whole:
222
-
223
- 1. **Unit:** classifier prompt extension produces well-formed `facts[]` against fixture transcripts. Fact extraction pure function maps `ClassifyResult` → `Fact[]` deterministically. Supersedence logic correctly marks predecessors on collision.
224
- 2. **Integration:** real SQLite + real Ollama, ingest a fixture transcript end-to-end, assert facts row appears with correct subject/predicate, assert `recall_facts(subject, predicate)` returns it, assert second ingest with different value supersedes first.
225
- 3. **MCP smoke:** spawn the daemon, call `recall_facts` over MCP stdio, assert JSON shape matches contract.
226
- 4. **Backfill dry-run:** `scripts/backfill-facts.ts --limit 10 --dry-run` against production DB copy, eyeball the extracted facts for sanity before live run.
227
-
228
- ---
229
-
230
- ## Open Questions (defer until implementation)
231
-
232
- These do not block shipping the design but should be revisited during Phase B.2:
233
-
234
- - Predicate vocabulary: should the closed list ship in the prompt or be config-driven? Lean prompt for v1, config for v2 if the vocabulary drifts per-domain.
235
- - Should `kind: open` facts have their own resolution affordance (mark resolved without a supersedent)? Probably yes but punt to Phase C.
236
- - Cross-runtime entity normalization: "mac-pro-llm-host" vs "macpro" vs "Mac Pro" — does the classifier normalize, or do we ship an alias table? Defer; let the data tell us how bad the problem is.