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.
- package/README.md +72 -34
- package/dist/cli/nlm.js +2 -1
- package/dist/cli/nlm.js.map +1 -1
- package/dist/http/app.js +2 -1
- package/dist/http/app.js.map +1 -1
- package/dist/mcp/server.js +20 -1
- package/dist/mcp/server.js.map +1 -1
- package/dist/ui/assets/{index-C8cpwbYJ.css → index-Beo8psd-.css} +1 -1
- package/dist/ui/assets/{index-CB50QnL-.js → index-CSPTTeeM.js} +8 -8
- package/dist/ui/index.html +2 -2
- package/package.json +26 -1
- package/.agents/plugins/marketplace.json +0 -20
- package/.github/workflows/ci.yml +0 -30
- package/docs/methodology/re-derivation-rate.md +0 -112
- package/docs/methodology/useful-hit-rate.md +0 -79
- package/docs/plans/2026-05-20-fts5-lexical-recall.md +0 -1088
- package/docs/plans/2026-05-20-recall-daemon-wedge-fix.md +0 -662
- package/docs/plans/2026-05-20-recall-hook-design.md +0 -131
- package/docs/plans/2026-05-20-recall-hook-implementation.md +0 -1222
- package/docs/plans/desktop-product.md +0 -69
- package/docs/plans/factstore-design.md +0 -236
- package/logs/CHANGELOG/CHANGELOG-2026.md +0 -1575
- package/logs/CHANGELOG/CHANGELOG.md +0 -209
- package/migrations/000_initial_schema.sql +0 -174
- package/migrations/001_entity_type_rename.sql +0 -17
- package/migrations/002_adapter_state_extend.sql +0 -12
- package/migrations/003_session_embeddings.sql +0 -11
- package/migrations/004_facts.sql +0 -46
- package/migrations/005_sources.sql +0 -31
- package/migrations/006_providers.sql +0 -33
- package/migrations/007_source_tokens.sql +0 -17
- package/migrations/008_fts_rebuild.sql +0 -9
- package/migrations/009_session_embedding_chunks.sql +0 -46
- package/migrations/010_sources_opencode.sql +0 -30
- package/migrations/011_sources_hermes_agent.sql +0 -30
- package/migrations/012_sources_aider.sql +0 -30
- package/migrations/013_adapter_state_failure_count.sql +0 -12
- package/migrations/014_sources_cursor.sql +0 -30
- package/migrations/015_sources_windsurf.sql +0 -30
- package/plugin-hermes-agent/README.md +0 -49
- package/plugin-hermes-agent/__init__.py +0 -75
- package/plugin-hermes-agent/plugin.yaml +0 -15
- package/scripts/backfill-citations.mjs +0 -0
- package/scripts/build-codex-plugin.mjs +0 -61
- package/scripts/deepseek-probe.mjs +0 -67
- package/scripts/extract-triples.mjs +0 -207
- package/scripts/longmemeval/embedding-cache.ts +0 -77
- package/scripts/longmemeval/fetch-dataset.sh +0 -25
- package/scripts/longmemeval/run-harness.ts +0 -315
- package/scripts/longmemeval/scorer.ts +0 -99
- package/scripts/longmemeval/tsconfig.json +0 -9
- package/scripts/longmemeval/types.ts +0 -35
- package/scripts/nlm-daily-digest.py +0 -239
- package/scripts/nlm-daily-digest.sh +0 -28
- package/src/cli/classify-parity.ts +0 -257
- package/src/cli/launchctl-helpers.ts +0 -49
- package/src/cli/nlm.ts +0 -1078
- package/src/core/actions/actions-log.ts +0 -118
- package/src/core/actions/overlay.ts +0 -117
- package/src/core/adapters/aider.ts +0 -205
- package/src/core/adapters/claude-code.ts +0 -293
- package/src/core/adapters/common.ts +0 -54
- package/src/core/adapters/cursor.ts +0 -486
- package/src/core/adapters/from-source.ts +0 -67
- package/src/core/adapters/hermes-agent.ts +0 -240
- package/src/core/adapters/hermes.ts +0 -277
- package/src/core/adapters/jsonl-generic.ts +0 -208
- package/src/core/adapters/opencode.ts +0 -281
- package/src/core/adapters/pi.ts +0 -264
- package/src/core/adapters/windsurf.ts +0 -386
- package/src/core/classifier/prompt.ts +0 -200
- package/src/core/dataset/build-dataset.ts +0 -463
- package/src/core/embedding/chunk-body.ts +0 -76
- package/src/core/embedding/embed-backfill.ts +0 -210
- package/src/core/embedding/embed-normalize.ts +0 -135
- package/src/core/facts/backfill-facts.ts +0 -254
- package/src/core/facts/extract-facts.ts +0 -50
- package/src/core/hook/citation-detect.ts +0 -124
- package/src/core/hook/cite-memo.ts +0 -68
- package/src/core/hook/claude-settings.ts +0 -187
- package/src/core/hook/gate.ts +0 -25
- package/src/core/hook/hook-log.ts +0 -41
- package/src/core/hook/memo-sweep.ts +0 -164
- package/src/core/hook/memo.ts +0 -67
- package/src/core/hook/pointer-block.ts +0 -26
- package/src/core/hook/select.ts +0 -32
- package/src/core/hook/transcript.ts +0 -121
- package/src/core/ingest/ingest-session.ts +0 -111
- package/src/core/providers/provider-models.ts +0 -100
- package/src/core/providers/provider-registry.ts +0 -196
- package/src/core/recall/citation-log.ts +0 -108
- package/src/core/recall/filter.ts +0 -27
- package/src/core/recall/index.ts +0 -6
- package/src/core/recall/match-fields.ts +0 -40
- package/src/core/recall/query-log.ts +0 -149
- package/src/core/recall/query-shape.ts +0 -66
- package/src/core/recall/recall-service.ts +0 -320
- package/src/core/recall/recent-log.ts +0 -59
- package/src/core/recall/tokenize.ts +0 -18
- package/src/core/recall/useful-scan.ts +0 -336
- package/src/core/recall-facts/fact-query-log.ts +0 -150
- package/src/core/recall-facts/fact-recall-service.ts +0 -327
- package/src/core/scheduler/scan-once.ts +0 -142
- package/src/core/scheduler/scheduler.ts +0 -225
- package/src/core/sources/source-registry.ts +0 -278
- package/src/core/storage/db-restore.ts +0 -133
- package/src/core/storage/live-status.ts +0 -45
- package/src/core/storage/migrate.ts +0 -72
- package/src/core/storage/sqlite-fact-store.ts +0 -304
- package/src/core/storage/sqlite-session-store.ts +0 -810
- package/src/hook/hook-auth.ts +0 -18
- package/src/hook/prompt-recall-hook.ts +0 -180
- package/src/hook/session-end-hook.ts +0 -81
- package/src/hook/session-start-hook.ts +0 -168
- package/src/hook/stop-hook.ts +0 -239
- package/src/http/app.ts +0 -1215
- package/src/install/claude-code.ts +0 -128
- package/src/install/codex.ts +0 -367
- package/src/install/cursor.ts +0 -68
- package/src/install/hermes-agent.ts +0 -76
- package/src/install/hermes.ts +0 -78
- package/src/install/nlm-dir-perms.ts +0 -55
- package/src/install/ollama.ts +0 -284
- package/src/install/setup.ts +0 -489
- package/src/install/windsurf.ts +0 -68
- package/src/llm/classifier-box.ts +0 -64
- package/src/llm/deepseek-client.ts +0 -150
- package/src/llm/env-autoload.ts +0 -55
- package/src/llm/ollama-client.ts +0 -189
- package/src/mcp/server.ts +0 -534
- package/src/ports/fact-store.ts +0 -102
- package/src/ports/llm-client.ts +0 -52
- package/src/ports/logger.ts +0 -16
- package/src/ports/session-store.ts +0 -45
- package/src/ports/transcript-adapter.ts +0 -55
- package/src/shared/types.ts +0 -149
- package/src/ui/App.tsx +0 -58
- package/src/ui/components/PromoteOpenButton.tsx +0 -65
- package/src/ui/components/SessionDrawer.tsx +0 -199
- package/src/ui/components/SideNav.tsx +0 -162
- package/src/ui/components/Skeleton.tsx +0 -107
- package/src/ui/index.html +0 -13
- package/src/ui/lib/actions.ts +0 -30
- package/src/ui/lib/api.ts +0 -92
- package/src/ui/lib/dataset.ts +0 -141
- package/src/ui/lib/registries.ts +0 -155
- package/src/ui/lib/view-settings.ts +0 -41
- package/src/ui/main.tsx +0 -15
- package/src/ui/pages/Live.tsx +0 -229
- package/src/ui/pages/Pulse.tsx +0 -415
- package/src/ui/pages/Recall.tsx +0 -190
- package/src/ui/pages/River.tsx +0 -354
- package/src/ui/pages/Search.tsx +0 -386
- package/src/ui/pages/Stub.tsx +0 -9
- package/src/ui/pages/Thread.tsx +0 -473
- package/src/ui/pages/settings/Classifier.tsx +0 -227
- package/src/ui/pages/settings/Data.tsx +0 -190
- package/src/ui/pages/settings/Index.tsx +0 -65
- package/src/ui/pages/settings/Labels.tsx +0 -224
- package/src/ui/pages/settings/Providers.tsx +0 -305
- package/src/ui/pages/settings/SettingsSubnav.tsx +0 -28
- package/src/ui/pages/settings/Sources.tsx +0 -326
- package/src/ui/pages/settings/Views.tsx +0 -96
- package/src/ui/styles.css +0 -1890
- package/src/ui/tsconfig.json +0 -21
- package/src/ui/vite.config.ts +0 -19
- package/tests/fixtures/claude_code/short_session.jsonl +0 -2
- package/tests/fixtures/claude_code/standard_iso.jsonl +0 -4
- package/tests/fixtures/claude_code/tool_heavy.jsonl +0 -8
- package/tests/fixtures/claude_code/with_subagent.jsonl +0 -7
- package/tests/fixtures/facts.ts +0 -17
- package/tests/fixtures/golden-corpus.ts +0 -85
- package/tests/fixtures/hermes/paired_request_dump.json +0 -24
- package/tests/fixtures/hermes/paired_session.json +0 -23
- package/tests/fixtures/hermes/request_dump.json +0 -28
- package/tests/fixtures/hermes/session_iso.json +0 -38
- package/tests/fixtures/hermes/session_unix.json +0 -38
- package/tests/fixtures/hermes/system_only.json +0 -18
- package/tests/fixtures/pi/error-connection-abort.jsonl +0 -8
- package/tests/fixtures/pi/short-successful.jsonl +0 -5
- package/tests/fixtures/pi/with-custom-message.jsonl +0 -6
- package/tests/fixtures/sessions.ts +0 -22
- package/tests/integration/backfill-facts.test.ts +0 -362
- package/tests/integration/citation-explicit.test.ts +0 -111
- package/tests/integration/cite-event.test.ts +0 -169
- package/tests/integration/cite-memo.test.ts +0 -87
- package/tests/integration/db-restore.test.ts +0 -153
- package/tests/integration/embed-backfill.test.ts +0 -176
- package/tests/integration/fact-supersedence.test.ts +0 -313
- package/tests/integration/fts-index.test.ts +0 -60
- package/tests/integration/getbyids-sqlite.test.ts +0 -100
- package/tests/integration/hermes-agent-hooks.test.ts +0 -248
- package/tests/integration/hook-claude-settings.test.ts +0 -218
- package/tests/integration/hook-log.test.ts +0 -54
- package/tests/integration/hook-memo.test.ts +0 -68
- package/tests/integration/hook-pre-compact.test.ts +0 -105
- package/tests/integration/hook-subagent-start.test.ts +0 -102
- package/tests/integration/http.test.ts +0 -401
- package/tests/integration/keyword-search-fts.test.ts +0 -66
- package/tests/integration/mcp-recall-logging.test.ts +0 -88
- package/tests/integration/mcp.test.ts +0 -260
- package/tests/integration/memo-sweep.test.ts +0 -91
- package/tests/integration/prompt-recall-hook.test.ts +0 -88
- package/tests/integration/provider-registry.test.ts +0 -107
- package/tests/integration/recall-golden.test.ts +0 -59
- package/tests/integration/recall-sqlite.test.ts +0 -169
- package/tests/integration/scheduler.test.ts +0 -391
- package/tests/integration/session-end-hook.test.ts +0 -48
- package/tests/integration/session-start-hook.test.ts +0 -126
- package/tests/integration/source-registry.test.ts +0 -122
- package/tests/integration/sqlite-fact-store.test.ts +0 -346
- package/tests/integration/stop-hook.test.ts +0 -560
- package/tests/integration/wal-checkpoint.test.ts +0 -49
- package/tests/unit/cli/launchctl-helpers.test.ts +0 -60
- package/tests/unit/core/adapters/aider.test.ts +0 -230
- package/tests/unit/core/adapters/claude-code.test.ts +0 -118
- package/tests/unit/core/adapters/cursor.test.ts +0 -485
- package/tests/unit/core/adapters/hermes-agent.test.ts +0 -329
- package/tests/unit/core/adapters/hermes.test.ts +0 -81
- package/tests/unit/core/adapters/jsonl-generic.test.ts +0 -142
- package/tests/unit/core/adapters/opencode.test.ts +0 -354
- package/tests/unit/core/adapters/pi.test.ts +0 -110
- package/tests/unit/core/adapters/windsurf.test.ts +0 -416
- package/tests/unit/core/classifier/prompt.test.ts +0 -126
- package/tests/unit/core/embedding/chunk-body.test.ts +0 -100
- package/tests/unit/core/facts/extract-facts.test.ts +0 -117
- package/tests/unit/core/filter.test.ts +0 -40
- package/tests/unit/core/hook/citation-detect-cite-session.test.ts +0 -96
- package/tests/unit/core/hook/citation-detect.test.ts +0 -124
- package/tests/unit/core/hook/gate.test.ts +0 -29
- package/tests/unit/core/hook/pointer-block.test.ts +0 -22
- package/tests/unit/core/hook/select.test.ts +0 -66
- package/tests/unit/core/match-fields.test.ts +0 -39
- package/tests/unit/core/mcp-cite-session.test.ts +0 -51
- package/tests/unit/core/providers/provider-models.test.ts +0 -101
- package/tests/unit/core/query-shape.test.ts +0 -92
- package/tests/unit/core/recall-facts/fact-recall-service.test.ts +0 -258
- package/tests/unit/core/recall-service.test.ts +0 -200
- package/tests/unit/core/storage/live-status.test.ts +0 -54
- package/tests/unit/core/tokenize.test.ts +0 -32
- package/tests/unit/core/useful-scan.test.ts +0 -537
- package/tests/unit/llm/embed.test.ts +0 -93
- package/tests/unit/llm/ollama-client.test.ts +0 -124
- package/tests/unit/scripts/longmemeval-scorer.test.ts +0 -114
- package/tsconfig.json +0 -31
- package/tsconfig.test.json +0 -11
- 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.
|