sessionmem 1.3.0 → 1.5.0

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 (68) hide show
  1. package/.github/sessionmem-logo.svg +57 -0
  2. package/CHANGELOG.md +128 -0
  3. package/CONTRIBUTING.md +130 -0
  4. package/README.md +292 -108
  5. package/SECURITY.md +33 -0
  6. package/dist/adapters/diagnostics.js +109 -0
  7. package/dist/adapters/generic.js +6 -2
  8. package/dist/adapters/global/antigravity.js +4 -1
  9. package/dist/adapters/global/claudeCode.js +19 -4
  10. package/dist/adapters/global/codex.js +7 -6
  11. package/dist/adapters/global/qcoder.js +4 -1
  12. package/dist/adapters/ide/cline.js +3 -0
  13. package/dist/adapters/ide/cursor.js +3 -0
  14. package/dist/adapters/ide/installer.js +17 -5
  15. package/dist/adapters/ide/windsurf.js +3 -0
  16. package/dist/adapters/installedHosts.js +51 -0
  17. package/dist/cli/commands/dedupe.js +1 -1
  18. package/dist/cli/commands/doctor.js +146 -0
  19. package/dist/cli/commands/entities.js +27 -0
  20. package/dist/cli/commands/history.js +23 -0
  21. package/dist/cli/commands/import.js +15 -44
  22. package/dist/cli/commands/ingestHook.js +4 -78
  23. package/dist/cli/commands/install.js +37 -59
  24. package/dist/cli/commands/list.js +3 -0
  25. package/dist/cli/commands/run.js +10 -12
  26. package/dist/cli/commands/scan.js +16 -0
  27. package/dist/cli/commands/search.js +9 -4
  28. package/dist/cli/commands/team.js +7 -3
  29. package/dist/cli/commands/ui.js +67 -0
  30. package/dist/cli/commands/uninstall.js +2 -1
  31. package/dist/cli/commands/watch.js +48 -0
  32. package/dist/cli/context.js +8 -6
  33. package/dist/cli/index.js +48 -7
  34. package/dist/cli/projectId.js +1 -2
  35. package/dist/cli/transcriptSweep.js +182 -0
  36. package/dist/core/api/contracts.js +1 -0
  37. package/dist/core/api/memoryCoreService.js +8 -0
  38. package/dist/core/api/sessionLifecycleService.js +13 -1
  39. package/dist/core/capture/toolEvent.js +82 -0
  40. package/dist/core/config/policyConfig.js +5 -1
  41. package/dist/core/extract/factClaims.js +97 -0
  42. package/dist/core/extract/knowledge.js +127 -0
  43. package/dist/core/injection/tokenBudget.js +10 -2
  44. package/dist/core/retrieve/retrieveMemories.js +20 -4
  45. package/dist/core/schema/migrations/012_transcript_checkpoints.sql +4 -0
  46. package/dist/core/schema/migrations/013_fts_porter.sql +32 -0
  47. package/dist/core/schema/migrations/014_memory_entities.sql +19 -0
  48. package/dist/core/schema/migrations/015_memory_supersessions.sql +41 -0
  49. package/dist/core/schema/runMigrations.js +55 -5
  50. package/dist/core/storage/db.js +31 -9
  51. package/dist/core/storage/knowledgeRepo.js +67 -0
  52. package/dist/core/storage/memoryRepo.js +45 -12
  53. package/dist/core/storage/memorySearchRepo.js +30 -20
  54. package/dist/core/storage/supersessionRepo.js +101 -0
  55. package/dist/core/summarize/cloudSummarizer.js +3 -8
  56. package/dist/core/summarize/summaryShape.js +1 -1
  57. package/dist/ui/assets.js +181 -0
  58. package/dist/ui/server.js +147 -0
  59. package/docs/REGISTRY_LISTING.md +88 -0
  60. package/docs/architecture.md +77 -0
  61. package/docs/benchmark.md +122 -0
  62. package/docs/cloud-summarization.md +57 -0
  63. package/docs/migration.md +44 -0
  64. package/docs/privacy-and-retention.md +139 -0
  65. package/docs/team-mode.md +117 -0
  66. package/docs/troubleshooting.md +126 -0
  67. package/docs/typescript-upgrade.md +48 -0
  68. package/package.json +25 -13
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
  <a href="https://github.com/catfish-1234/sessionmem/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"></a>
10
10
  </p>
11
11
 
12
- **85.6% fewer tokens. Every session starts knowing your codebase. Stored entirely on your machine.**
12
+ **Project memory between sessions, stored on your machine.**
13
13
 
14
14
  ```
15
15
  New session. Claude starts fresh.
@@ -27,15 +27,15 @@ WITH sessionmem:
27
27
  Claude: "Looks like you're mid-Stripe migration. Where do you want to pick up?"
28
28
  ```
29
29
 
30
- `sessionmem` is an MCP server that watches your coding sessions and stores what actually mattered -- decisions, warnings, things that would bite you if Claude forgot them. At the start of each new session it injects the relevant bits automatically. Works with Claude Code, Cursor, Cline, Codex, Windsurf, and anything that speaks [MCP](https://modelcontextprotocol.io).
30
+ `sessionmem` is an MCP server that stores decisions, warnings, and project context across sessions. Claude Code hooks capture supported tool events and load relevant memories automatically. Other hosts use its MCP tools and installed instructions; session automation depends on the host. It works with Claude Code, Cursor, Cline, Codex, Windsurf, and other [MCP](https://modelcontextprotocol.io) hosts.
31
31
 
32
- Everything stays on your machine. No account, no cloud, no data leaving your computer unless you explicitly turn that on.
32
+ By default, everything stays on your machine. You don't need an account or a cloud service. Data only leaves your computer if you enable sharing or cloud summarization.
33
33
 
34
34
  ---
35
35
 
36
36
  ## Quickstart
37
37
 
38
- No programming experience needed. You just need a terminal (Command Prompt, Terminal, or PowerShell) and [Node.js](https://nodejs.org) installed.
38
+ You need a terminal (Command Prompt, Terminal, or PowerShell) and [Node.js](https://nodejs.org), version 20.19+ on the Node 20 line, or 22.13+. Node 22 LTS is recommended. No programming experience is required.
39
39
 
40
40
  ### 1. Install sessionmem
41
41
 
@@ -45,34 +45,49 @@ npm install -g sessionmem
45
45
 
46
46
  ### 2. Register it with your AI tool
47
47
 
48
- Run this inside the project folder you're working on, with your AI tool (Claude Code, Cursor, etc.) configured:
48
+ Run this in your project folder after configuring your AI tool (Claude Code, Cursor, etc.):
49
49
 
50
50
  ```bash
51
51
  sessionmem install
52
+ # Optional: select one host explicitly, including in automation:
53
+ sessionmem install --adapter claude-code
54
+ # Other names: cursor, cline, codex, windsurf, antigravity, qcoder, generic
52
55
  ```
53
56
 
54
- This does three things:
55
- - Tells your AI tool's MCP host about `sessionmem` so it can be launched automatically.
56
- - Creates a config file at `~/.sessionmem/config.json` with safe, privacy-respecting defaults, but only if one doesn't already exist.
57
- - Injects instructions into `~/.claude/CLAUDE.md` so Claude Code knows about sessionmem's tools and uses them proactively (idempotent, so safe to re-run).
57
+ `install` detects installed hosts from local executables, including from a plain
58
+ terminal, and configures every host found. Automatic discovery currently supports
59
+ Claude Code on `PATH` or in its standard native install locations. Use
60
+ `--adapter <name>` for the other adapters or to override discovery. The existing
61
+ `SESSIONMEM_ADAPTER` environment override also works; the flag takes precedence.
62
+ If no supported host is found, the command says so and exits nonzero before
63
+ creating files. Discovery and configuration work fully offline.
58
64
 
59
- ### 3. Start using your AI tool as normal
65
+ This initializes the database and, for each selected adapter:
60
66
 
61
- ```bash
62
- sessionmem run
63
- ```
67
+ - Registers `sessionmem` with your AI tool's MCP host so the host can start it automatically.
68
+ - Creates `~/.sessionmem/config.json` with secret redaction enabled and a 90-day retention window, if the file doesn't already exist.
69
+ - Adds instructions to the selected host's guidance file, such as `~/.claude/CLAUDE.md` for Claude Code or `~/.codex/AGENTS.md` for Codex. You can re-run the command without duplicating those instructions.
70
+ - Installs Claude Code's SessionStart, SessionEnd, and PostToolUse hooks and prints what was configured per host. If a host fails, the remaining hosts are still attempted and the command exits nonzero.
71
+
72
+ ### 3. Restart your AI tool
73
+
74
+ Restart your editor or agent so it loads the MCP registration. Your host starts
75
+ `sessionmem run` automatically; running it directly starts a stdio server that
76
+ waits for MCP messages, so it can appear to hang in a terminal. For an unknown
77
+ host (`generic`), install writes a project-local `.mcp.json`; if your host uses
78
+ another format or location, copy its server entry into that host’s MCP config.
64
79
 
65
- (Most of the time you won't run this yourself. Your AI tool's host starts it automatically once it's registered.)
80
+ After restarting:
66
81
 
67
- That's it. From here:
68
- - `sessionmem` watches your sessions in the background.
69
- - At the end of each session, it writes down a short summary of what mattered.
70
- - At the start of your next session, it quietly reminds your assistant of the relevant bits.
82
+ - In Claude Code, the installed PostToolUse, SessionEnd, and SessionStart hooks capture supported tool events, summarize them, and load prior memories automatically.
83
+ - Other MCP hosts use sessionmem's tools and installed instructions. Automatic capture and session lifecycle calls depend on the host or agent. MCP registration alone does not install Claude Code hooks there.
71
84
 
72
- You can verify everything is working with:
85
+ Check the installation offline:
73
86
 
74
87
  ```bash
75
- sessionmem ping
88
+ sessionmem doctor
89
+ # For an explicitly selected host:
90
+ sessionmem doctor --adapter claude-code
76
91
  ```
77
92
 
78
93
  ---
@@ -92,6 +107,7 @@ sessionmem ping
92
107
  - [Further documentation](#further-documentation)
93
108
  - [Troubleshooting](#troubleshooting)
94
109
  - [FAQ](#faq)
110
+ - [Security](#security)
95
111
  - [Contributing](#contributing)
96
112
  - [License](#license)
97
113
 
@@ -99,73 +115,56 @@ sessionmem ping
99
115
 
100
116
  ## What problem does this solve?
101
117
 
102
- If you've used an AI coding assistant for more than a day, you've probably hit this:
118
+ Most AI coding assistants rely on the current conversation for context. Start a new session and you may need to explain the project's setup, libraries, fixed bugs, and design decisions again.
103
119
 
104
- > You spend twenty minutes explaining your project's setup, the libraries you use, a tricky bug you already fixed, and a decision you made about how authentication should work. The assistant nods along, helps you out... and then in your **next session**, it has forgotten all of it. You explain everything again.
120
+ `sessionmem` keeps short notes between sessions:
105
121
 
106
- This happens because most AI assistants only "know" what's inside the current conversation. Once that conversation ends, the context is gone.
122
+ 1. While you work, it captures session events.
123
+ 2. At session end, it summarizes decisions, warnings, and useful facts into stored memories.
124
+ 3. At the next session start, it loads the most relevant memories within a small token budget.
107
125
 
108
- `sessionmem` fixes this by sitting quietly between your assistant and your project:
109
-
110
- 1. While you work, it **captures** what happens in the session.
111
- 2. When the session ends, it **summarizes** the important parts (decisions made, warnings, useful facts) into short, durable notes.
112
- 3. The next time you start a session, it **reminds** the assistant of the most relevant notes, automatically, in a small amount of text.
113
-
114
- You don't run any of these steps yourself. Once installed, it just works in the background.
126
+ Claude Code runs these steps through the installed hooks. Other hosts need their
127
+ agent to call the MCP memory and lifecycle tools; the installed guidance explains
128
+ how to do that.
115
129
 
116
130
  ---
117
131
 
118
132
  ## How is sessionmem different?
119
133
 
120
- There are other "memory for Claude" projects out there (for example, tools like *claude-mem* and similar community projects). Here's what sets `sessionmem` apart:
134
+ Compared with projects such as *claude-mem* and other cloud or Claude-only memory tools, `sessionmem` focuses on local storage and support for multiple MCP hosts:
121
135
 
122
136
  | | **sessionmem** | Typical cloud/Claude-only memory tools |
123
137
  |---|---|---|
124
138
  | **Where is data stored?** | A single SQLite file on your computer (`~/.sessionmem/memories.db`) | Often a hosted service, a cloud vector database, or a separate server process you have to run |
125
- | **Account / sign-up required?** | No, never | Sometimes |
139
+ | **Account / sign-up required?** | No | Sometimes |
126
140
  | **Which AI tools does it work with?** | Claude Code, Cursor, Codex, Cline, Windsurf, Antigravity, QCoder, and any other MCP-compatible host | Usually just one specific tool (commonly Claude Code only) |
127
141
  | **Secret redaction** | Built in, on by default. API keys, tokens, passwords, and private keys are scrubbed before anything is saved. | Often not handled, or left to the user |
128
- | **Token budget control** | Injected memories are trimmed to a small, fixed token budget so they don't bloat every conversation (see benchmarks below) | Varies, often unbounded |
129
- | **Old/stale memory cleanup** | Built-in retention policy automatically prunes old memories (configurable, on by default) | Often grows forever ("memory rot") |
142
+ | **Token budget control** | Injected memories are trimmed to a small, fixed token budget (see benchmarks below) | Varies, often unbounded |
143
+ | **Old/stale memory cleanup** | Built-in retention policy automatically prunes old memories (configurable, on by default) | Often no automatic cleanup ("memory rot") |
130
144
  | **Team sharing** | Optional, via a shared folder you already control (network drive, synced directory). No server needed. | Usually requires a shared hosted backend |
131
- | **Offline-capable** | Yes, fully. Works with no network connection by default. | Usually requires network access to the memory service |
145
+ | **Offline-capable** | Yes. Works with no network connection by default. | Usually requires network access to the memory service |
132
146
 
133
- In short: `sessionmem` is the **boring, local, "just a SQLite file" option**: easy to inspect, back up, and delete, with no lock-in to any one vendor's AI tool.
147
+ The SQLite file is easy to inspect, back up, or delete, and you can use it across AI tools from different vendors.
134
148
 
135
149
  ---
136
150
 
137
151
  ## Benchmark results
138
152
 
139
- These numbers come from `npm run benchmark` (`scripts/benchmark.mjs`), which runs the real production retrieval and injection code over a fixed, synthetic set of test data with no network calls. The results are fully reproducible. See [`docs/benchmark.md`](docs/benchmark.md) for the full report and how to regenerate it.
140
-
141
- ### Token savings
142
-
143
- > **~85.6% reduction** in tokens compared to carrying full session history.
144
-
145
- | | Tokens |
146
- |---|---|
147
- | Full session history (baseline) | 1,587 |
148
- | What sessionmem injects at the start of your next session | 228 |
149
-
150
- In practice: instead of re-reading (or re-explaining) about 1,600 tokens of past context every session, the assistant gets a 230-token summary of just the things that matter: decisions, warnings, and key facts.
151
-
152
- ### Retrieval accuracy
153
-
154
- > **100% hit-rate**: every one of the 10 test queries successfully retrieved the memory it was supposed to.
155
-
156
- | Metric | Result |
157
- |---|---|
158
- | Hit-rate (10 curated queries) | 100.0% |
159
- | Recall | 100.0% |
160
- | Precision | 33.3% |
153
+ `npm run benchmark` evaluates conversational retrieval on the committed LoCoMo
154
+ corpus: 10 conversations, 272 sessions, 5,882 turns, and 1,527 scored questions.
155
+ It captures dialogue through the public `storeMemory` API and asks the original
156
+ questions through `retrieveMemories`, fully offline with no API keys.
161
157
 
162
- Precision of 33.3% is expected here: each query retrieves the top 3 candidate memories, and only one of those three is the "expected" match for a given test query. The other two are still relevant context for the agent, just not the one being scored. The important number is recall/hit-rate: **the right memory is never missed.**
163
-
164
- These benchmarks are deterministic and reproducible. Run them yourself:
158
+ The evaluation reports hit rate, precision, recall, complete-evidence retrieval,
159
+ and latency. Production retrieval uses offline BM25 ranking with English stemming;
160
+ conversational questions test recall beyond exact copies of memory text.
161
+ See [benchmark results](docs/benchmark.md) and the
162
+ [methodology, dataset license, and metric definitions](benchmarks/README.md).
165
163
 
166
164
  ```bash
167
- npm run build # benchmark imports the compiled code from dist/
168
- npm run benchmark # regenerates docs/benchmark.md
165
+ npm run build
166
+ npm run benchmark
167
+ npm run benchmark -- --output benchmarks/results/locomo.json
169
168
  ```
170
169
 
171
170
  ---
@@ -198,11 +197,11 @@ npm run benchmark # regenerates docs/benchmark.md
198
197
  └──────────────────────────────────────────────┘
199
198
  ```
200
199
 
201
- - **Adapters** are small pieces that know how to talk to each specific AI tool. This is why sessionmem can support many tools: adding a new one doesn't change how memory itself works.
202
- - **The core engine** is the same no matter which tool you use. It decides what's worth remembering, how relevant it is later, and how much of it fits in a small "reminder" at the start of your next session.
203
- - **The database** is just a file. You can back it up, move it, inspect it, or delete it like any other file on your computer.
200
+ - **Adapters** connect each AI tool to sessionmem. Supporting another tool doesn't require changing the memory engine.
201
+ - **The core engine** stores memories, ranks their relevance, and selects what fits in the next session's context budget. Every adapter uses the same engine.
202
+ - **The database** is a local file. You can back it up, move it, inspect it, or delete it.
204
203
 
205
- For a deeper technical dive, see [`docs/architecture.md`](docs/architecture.md).
204
+ See [`docs/architecture.md`](docs/architecture.md) for the technical overview.
206
205
 
207
206
  ---
208
207
 
@@ -210,33 +209,194 @@ For a deeper technical dive, see [`docs/architecture.md`](docs/architecture.md).
210
209
 
211
210
  | Command | What it does |
212
211
  |---------|--------------|
213
- | `sessionmem install` | Register sessionmem with the current MCP host and write default config. |
214
- | `sessionmem uninstall [--purge]` | Remove sessionmem from the host. `--purge` also deletes the local database. |
212
+ | `sessionmem install [--adapter <name>]` | Detect installed hosts, register sessionmem with each, and write default config; the flag selects one host. |
213
+ | `sessionmem doctor [--adapter <name>]` | Check the store, schema, hooks, MCP wiring, and canary recall offline; print PASS/FAIL and repair hints. |
214
+ | `sessionmem uninstall [--adapter <name>] [--purge]` | Remove sessionmem from the host. `--purge` also deletes the local database. |
215
215
  | `sessionmem run` | Start the MCP server. |
216
- | `sessionmem ping` | Check server connectivity. |
217
- | `sessionmem search <query> [--limit <n>]` | Search memories by semantic query. |
218
- | `sessionmem list` | List all memories for the current project. |
219
- | `sessionmem show <id>` | Show full details of a memory. |
216
+ | `sessionmem ui [--port N]` | Open the local read-only web viewer (default port 3777). |
217
+ | `sessionmem ping` | Check the local version and database reachability. |
218
+ | `sessionmem search <query> [--limit <n>] [--include-history]` | Search current memories by text query (limit 1–100, default 10). Include superseded facts with `--include-history`. |
219
+ | `sessionmem list` | List up to 200 recent memories for the current project; warns when truncated. |
220
+ | `sessionmem entities [--project <id>] [--json]` | List extracted entities, typed relations, and their source memory IDs. Defaults to the current project. |
221
+ | `sessionmem history [--project <id>] [--json]` | List supersession chains with old/new values, source memory IDs, reasons, and timestamps. |
222
+ | `sessionmem show <id>` | Show memory details (content capped at 2000 characters; use export for full content). |
220
223
  | `sessionmem forget <id> [--force]` | Delete a memory by ID. |
221
- | `sessionmem export [path]` | Export memories to a JSON file. |
222
- | `sessionmem import <path> [--merge]` | Import memories from a JSON file. |
224
+ | `sessionmem export [path]` | Export all current-project memories to JSON (default `~/.sessionmem/export-YYYY-MM-DD.json`). |
225
+ | `sessionmem import <path> [--merge]` | Import up to 1000 valid records from UTF-8 JSON into the current project. Existing IDs are preserved, including with `--merge`; invalid records are skipped with warnings. |
226
+ | `sessionmem scan [--transcripts-dir <path>]` | Import existing Claude Code JSONL transcripts into local session memories. Reports files found, sessions imported, memories created, skipped files, and errors. |
227
+ | `sessionmem watch [--once] [--interval <seconds>] [--transcripts-dir <path>]` | Capture new or updated Claude Code transcripts. Polls every 5 seconds by default; `--once` runs a single sweep. |
223
228
  | `sessionmem stats` | Show memory statistics for the current project. |
224
229
  | `sessionmem savings [--json]` | Show token savings from compression and injection, with percentage. |
225
230
  | `sessionmem redact-scan [--apply]` | Scan stored memories for secrets; `--apply` redacts in place. |
226
231
  | `sessionmem retention prune [--force] [--days <n>]` | Prune old memories (dry-run by default). |
227
232
  | `sessionmem config get <key>` / `config set <key> <value>` | Read and write policy config. |
228
- | `sessionmem team enable <path>` / `team disable` / `team status` | Manage shared-path team memory mode. |
233
+ | `sessionmem team enable <path>` / `team disable [--remove-team-memories]` / `team status` | Manage shared-path team memory mode. |
229
234
  | `sessionmem sync` | Push local memories and pull teammate memories via the shared path. |
235
+ | `sessionmem browse [--project <id>]` | List projects or preview up to 50 recent memories from one project. |
236
+ | `sessionmem dedupe [--apply] [--threshold <n>]` | Preview duplicate memories; `--apply` deletes them (threshold >0–1, default 0.85). |
237
+ | `sessionmem re-embed` | Refresh memories with stale embedding versions. |
238
+ | `sessionmem session-start` | Print prior context as Claude Code SessionStart hook JSON. |
239
+ | `sessionmem ingest-hook` | Read a Claude Code PostToolUse JSON payload from stdin and capture supported tool events. |
240
+ | `sessionmem session-end` | Summarize ingested events and apply retention pruning; reads the hook session ID from stdin. |
241
+
242
+ Use `sessionmem --help` or `sessionmem <command> --help` for options, and
243
+ `sessionmem --version` for the installed version. Destructive commands require
244
+ `--force`, `--apply`, or `--purge` as shown above. `team disable` preserves
245
+ teammate memories unless `--remove-team-memories` is passed.
246
+
247
+ The default database is `~/.sessionmem/memories.db`. Set `SESSIONMEM_DB_PATH`
248
+ to use another file; its parent directories are created automatically and the
249
+ default directory is not created by database commands. Server logs are written
250
+ to `logs/mcp.log` beside the selected database (disabled for `:memory:`). Config remains at
251
+ `~/.sessionmem/config.json`. `uninstall --purge` deletes the selected database.
252
+ Quote paths containing spaces (for example `"C:\Users\Ada Lovelace\memory.db"`
253
+ on Windows). In JSON config files, use forward slashes or escaped backslashes
254
+ for Windows paths. Imports accept CRLF and a UTF-8 BOM; convert other encodings to UTF-8.
255
+
256
+ `SESSIONMEM_PROJECT_ID` pins the project bucket (useful when moving a repository);
257
+ otherwise it is derived from the repository root or working directory.
258
+ `SESSIONMEM_ADAPTER` selects the install/doctor/uninstall host unless `--adapter` is set.
259
+ `SESSIONMEM_DEBUG=1` enables ingest-hook diagnostics on stderr.
260
+
261
+ ### Inspect memories in your browser
262
+
263
+ ```bash
264
+ sessionmem ui
265
+ sessionmem ui --port 8080
266
+ sessionmem ui --port 0 # Pick an available port
267
+ ```
268
+
269
+ The command prints its URL and opens your default browser. It binds only to
270
+ `127.0.0.1`, needs no authentication, and serves all assets locally using Node's
271
+ built-in HTTP server. No external services, CDNs, or additional runtime dependencies
272
+ are used. If browser launch is unavailable, open the printed URL manually. Press
273
+ Ctrl-C to stop the server and close its database connection.
274
+
275
+ The viewer starts on the current project, with a selector for other projects in
276
+ the same store. Browse saved memories, search through the existing recall path,
277
+ inspect extracted entities and relations with their source memories, and follow
278
+ supersession chains with old/new values, source IDs, assertion times, detection
279
+ times, and partial/full status. Search returns up to 50 results and defaults to
280
+ current facts; select **Include superseded facts in search** to recall history.
281
+ Browsing lists all saved records, including superseded and expired ones, in pages
282
+ of 50. Source IDs open full memory details. Entity visibility and history links
283
+ use the same rules as `sessionmem entities` and `sessionmem history`.
284
+
285
+ The database is opened read-only. Browsing and on-demand search do not increment
286
+ access counts, migrate the schema, or change memories. Only HTTP GET and HEAD are
287
+ accepted; no write, delete, or edit routes are exposed. Responses are not cached,
288
+ and cross-origin browser requests and unexpected Host headers are rejected. Run
289
+ `sessionmem ping` first to initialize a missing store or upgrade an older schema.
290
+ The usual `SESSIONMEM_DB_PATH` and `SESSIONMEM_PROJECT_ID` overrides
291
+ apply. Anyone with access to this computer can read the local viewer while it is
292
+ running; stop it when finished inspecting private memories.
293
+
294
+ ### Import existing sessions and watch for new ones
295
+
296
+ When a fact changes, sessionmem can link its replacement locally. For example, “I use VS Code” followed by “I switched to Neovim” supersedes the earlier editor choice. Recall excludes fully superseded memories by default. `retrieveMemories` accepts the optional `includeHistory: true`; `sessionmem search --include-history` searches earlier facts too. `sessionmem history` shows what replaced what. The old memory stays available through show, list, and export.
297
+
298
+ Detection uses deterministic entity/relation rules, shared purpose words, a small tool-category vocabulary, and explicit negation or replacement phrases. It needs no API or model. Unfamiliar wording can be missed, and ambiguous changes can be misclassified. A memory with independent claims remains searchable while any claim is current; history labels these partial supersessions. See [supersession details](docs/architecture.md#contradiction-and-supersession).
299
+
300
+ Run a scan to capture Claude Code sessions from before sessionmem was installed:
301
+
302
+ ```bash
303
+ sessionmem scan
304
+ sessionmem watch --once
305
+ sessionmem watch --interval 10
306
+ ```
307
+
308
+ Both commands recursively read `~/.claude/projects/**/*.jsonl`. Use
309
+ `--transcripts-dir "/path/to/projects"` to select another transcript tree. They
310
+ work fully offline without API keys and always use the local summarizer, even
311
+ if cloud summarization is enabled elsewhere.
312
+
313
+ Transcript user/assistant text and supported tool uses (Bash, Edit, Write,
314
+ MultiEdit) pass through the existing event-ingestion, redaction, and session-summary
315
+ pipeline. Each session gets one summary memory, including short sessions with
316
+ only one event. Updated sessions refresh that summary. Project buckets come from
317
+ each transcript's `cwd`, using its repository root when available; the directory
318
+ where you run scan/watch does not select the project. `SESSIONMEM_PROJECT_ID`
319
+ can explicitly pin all imports to one bucket. Transcripts without a working
320
+ directory or capturable events are skipped; nested subagent files get separate
321
+ session summaries.
322
+
323
+ Re-running either command does not duplicate memories or transcript events.
324
+ File checkpoints live in the selected memory database, and unchanged files are
325
+ skipped across restarts. Stable event IDs also make interrupted imports safe to
326
+ retry. Partial or malformed JSONL lines are reported and retried on later sweeps;
327
+ valid events in the same file can still be captured. A single sweep exits with
328
+ status 1 if it encounters errors. The daemon keeps running and retries errors.
329
+
330
+ `watch` prints its first sweep and subsequent imports or errors. It runs in the
331
+ foreground until SIGINT or SIGTERM. For a background process:
332
+
333
+ ```bash
334
+ nohup sessionmem watch > sessionmem-watch.log 2>&1 &
335
+ ```
336
+
337
+ For macOS launchd, save this as
338
+ `~/Library/LaunchAgents/io.sessionmem.watch.plist`. Replace the executable path
339
+ with the output of `command -v sessionmem`, and adjust PATH for your Node install:
340
+
341
+ ```xml
342
+ <?xml version="1.0" encoding="UTF-8"?>
343
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
344
+ <plist version="1.0">
345
+ <dict>
346
+ <key>Label</key><string>io.sessionmem.watch</string>
347
+ <key>ProgramArguments</key>
348
+ <array><string>/opt/homebrew/bin/sessionmem</string><string>watch</string></array>
349
+ <key>EnvironmentVariables</key>
350
+ <dict><key>PATH</key><string>/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin</string></dict>
351
+ <key>RunAtLoad</key><true/>
352
+ <key>KeepAlive</key><true/>
353
+ </dict>
354
+ </plist>
355
+ ```
356
+
357
+ ```bash
358
+ launchctl bootstrap "gui/$(id -u)" ~/Library/LaunchAgents/io.sessionmem.watch.plist
359
+ # Stop and unload:
360
+ launchctl bootout "gui/$(id -u)/io.sessionmem.watch"
361
+ ```
362
+
363
+ For a Linux systemd user service, save this as
364
+ `~/.config/systemd/user/sessionmem-watch.service`. Replace the executable path
365
+ and adjust PATH for your Node install:
366
+
367
+ ```ini
368
+ [Unit]
369
+ Description=Capture Claude Code transcripts with sessionmem
370
+
371
+ [Service]
372
+ ExecStart=/usr/local/bin/sessionmem watch
373
+ Environment=PATH=/usr/local/bin:/usr/bin:/bin
374
+ Restart=on-failure
375
+ RestartSec=5
376
+
377
+ [Install]
378
+ WantedBy=default.target
379
+ ```
380
+
381
+ ```bash
382
+ systemctl --user daemon-reload
383
+ systemctl --user enable --now sessionmem-watch.service
384
+ journalctl --user -u sessionmem-watch.service -f
385
+ # Stop and disable:
386
+ systemctl --user disable --now sessionmem-watch.service
387
+ ```
388
+
389
+ These are optional examples; `sessionmem install` does not register a daemon.
230
390
 
231
391
  ---
232
392
 
233
393
  ## Privacy, secrets, and your data
234
394
 
235
- **Everything stays on your machine by default.** No account, no telemetry, no hosted memory service. Storage, retrieval, and summarization all run locally, governed by `~/.sessionmem/config.json`.
395
+ Storage, retrieval, and summarization run locally by default. There is no account, telemetry, or hosted memory service. Settings live in `~/.sessionmem/config.json`.
236
396
 
237
397
  ### Secrets are scrubbed automatically
238
398
 
239
- Before anything is saved, `sessionmem` automatically removes common secret patterns and replaces them with `REDACTED`:
399
+ Before saving memory content, `sessionmem` replaces common secret patterns with `REDACTED`:
240
400
 
241
401
  - Email addresses
242
402
  - API keys (`sk-...`, AWS `AKIA...`, GitHub `ghp_...`/`gho_...`, etc.)
@@ -244,7 +404,7 @@ Before anything is saved, `sessionmem` automatically removes common secret patte
244
404
  - Private key blocks (`-----BEGIN ... PRIVATE KEY-----`)
245
405
  - Connection-string style secrets (`password=...`, `secret=...`)
246
406
 
247
- This is **on by default**. You can scan and clean up older memories at any time:
407
+ Redaction is on by default. To scan and clean up older memories:
248
408
 
249
409
  ```bash
250
410
  sessionmem redact-scan # see what would be redacted
@@ -257,26 +417,26 @@ Full details: [`docs/privacy-and-retention.md`](docs/privacy-and-retention.md).
257
417
 
258
418
  ## Memory rot: keeping memory accurate over time
259
419
 
260
- "Memory rot" is what happens when a memory system keeps accumulating notes forever. Eventually it fills up with outdated decisions, duplicate facts, and noise, and the assistant starts surfacing stale information instead of helpful information.
420
+ Old decisions and duplicate facts can accumulate in a memory store, causing the assistant to use outdated information. This is sometimes called "memory rot."
261
421
 
262
- `sessionmem` is designed to avoid this in a few ways:
422
+ `sessionmem` handles it through retention, ranking, and sync rules:
263
423
 
264
- 1. **Retention pruning**: memories older than a configurable window (default 90 days) are automatically eligible for cleanup. This runs as a light check at the end of every session, and can also be run manually:
424
+ 1. **Retention pruning**: memories older than a configurable window (90 days by default) are eligible for deletion. A lightweight check runs at session end. You can also run it manually:
265
425
 
266
426
  ```bash
267
427
  sessionmem retention prune # dry run - shows what *would* be deleted
268
428
  sessionmem retention prune --force # actually deletes
269
429
  ```
270
430
 
271
- 2. **Importance-weighted ranking**: when memories are retrieved, they're ranked by a blend of semantic relevance, recency, and importance. Old, low-importance notes naturally sink to the bottom and stop being surfaced even before they're pruned.
431
+ 2. **Importance-weighted ranking**: retrieval ranks memories by offline BM25 lexical relevance, entity overlap, recency, and importance. Older, less important notes rank lower even before they are pruned.
272
432
 
273
- 3. **Token-budgeted injection**: only the top-ranked, most relevant memories are injected (trimmed to a small token budget, see [benchmarks](#benchmark-results)), so even a large memory store doesn't produce bloated, noisy context.
433
+ 3. **Token-budgeted injection**: only the highest-ranked memories are loaded, trimmed to a small token budget (see [benchmarks](#benchmark-results)). The context stays within that budget as the store grows.
274
434
 
275
- 4. **Conflict resolution in team mode**: when memories are merged from teammates, the system uses last-write-wins by id (so stale duplicates don't pile up) while preserving the higher importance score (so a critical warning doesn't get silently downgraded).
435
+ 4. **Conflict resolution in team mode**: merging teammate memories uses last-write-wins by id to avoid stale duplicates and keeps the higher importance score so a warning isn't downgraded.
276
436
 
277
- The retrieval benchmark above (100% hit-rate / 100% recall) demonstrates that even with the ranking and trimming in place, the right memory still surfaces. Accuracy is not traded away for compactness.
437
+ The [conversational benchmark](benchmarks/README.md) measures retrieval quality separately from retention and startup token budgets.
278
438
 
279
- You're always in control: export everything first if you want a permanent record before pruning:
439
+ Export your memories before pruning if you want to keep a copy:
280
440
 
281
441
  ```bash
282
442
  sessionmem export
@@ -286,17 +446,17 @@ sessionmem export
286
446
 
287
447
  ## Team mode (optional)
288
448
 
289
- Want your whole team's AI assistants to share decisions and warnings? Point `sessionmem` at a shared folder (a network drive, a synced directory, or any location everyone can read and write):
449
+ To share decisions and warnings across your team's AI assistants, point `sessionmem` at a folder everyone can read and write, such as a network drive or synced directory:
290
450
 
291
451
  ```bash
292
452
  sessionmem team enable <shared-path>
293
453
  sessionmem sync
294
454
  ```
295
455
 
296
- - **Off by default**: nothing is shared until you turn it on.
297
- - No server needed. It's just files in a folder you already control.
298
- - Teammates' memories show up with an `author:` prefix so you know where they came from.
299
- - Secrets are re-redacted on every pulled memory, so a teammate's snapshot can't reintroduce something your redaction policy would have stripped.
456
+ - Team mode is off by default. Nothing is shared until you enable it.
457
+ - Memories are shared as files in that folder; no server is needed.
458
+ - Teammate memories appear with an `author:` prefix identifying their source.
459
+ - Redaction runs on every pulled memory using your redaction policy.
300
460
 
301
461
  Full details, including the trust model: [`docs/team-mode.md`](docs/team-mode.md).
302
462
 
@@ -304,9 +464,9 @@ Full details, including the trust model: [`docs/team-mode.md`](docs/team-mode.md
304
464
 
305
465
  ## Cloud summarization (optional, off by default)
306
466
 
307
- By default, summarization (turning a session into a short memory) happens entirely locally, with no API calls.
467
+ By default, session summaries are created locally, with no API calls.
308
468
 
309
- If you explicitly opt in (`allowCloudSummarization=true`) and provide an `ANTHROPIC_API_KEY`, summarization can use Claude's API for higher-quality summaries. If that ever fails, it automatically falls back to local summarization. Your sessions are never left unsummarized.
469
+ To use Claude's API for higher-quality summaries, set `allowCloudSummarization=true` and provide an `ANTHROPIC_API_KEY`. If cloud summarization fails after retries, sessionmem uses local summarization. Failures are recorded for diagnosis; see the configuration guide below.
310
470
 
311
471
  Details: [`docs/cloud-summarization.md`](docs/cloud-summarization.md).
312
472
 
@@ -324,14 +484,14 @@ Details: [`docs/cloud-summarization.md`](docs/cloud-summarization.md).
324
484
  - Antigravity
325
485
  - QCoder
326
486
 
327
- ...and any other tool that implements the [Model Context Protocol](https://modelcontextprotocol.io).
487
+ Other tools that implement the [Model Context Protocol](https://modelcontextprotocol.io) can connect too.
328
488
 
329
489
  ---
330
490
 
331
491
  ## Further documentation
332
492
 
333
493
  - [Architecture](docs/architecture.md): how the core engine, adapters, CLI, and SQLite storage fit together.
334
- - [Benchmark](docs/benchmark.md): full token-reduction and retrieval-accuracy report, and how to reproduce it.
494
+ - [Benchmark](docs/benchmark.md): conversational retrieval results and reproduction steps.
335
495
  - [Privacy and retention](docs/privacy-and-retention.md): secret redaction, retention pruning, and config.
336
496
  - [Team mode](docs/team-mode.md): shared-path team memory.
337
497
  - [Cloud summarization](docs/cloud-summarization.md): the opt-in cloud summarization path.
@@ -342,21 +502,34 @@ Details: [`docs/cloud-summarization.md`](docs/cloud-summarization.md).
342
502
 
343
503
  ## Troubleshooting
344
504
 
345
- Run into trouble installing or running `sessionmem`? Start with [`docs/troubleshooting.md`](docs/troubleshooting.md). It covers install failures, adapter-specific issues, missing session data, and native module (`better-sqlite3`) build problems on different platforms.
505
+ For install failures, adapter issues, missing session data, or `better-sqlite3` native-build problems, see [`docs/troubleshooting.md`](docs/troubleshooting.md).
346
506
 
347
- Two quick checks that resolve most reports:
507
+ Start with offline diagnostics:
348
508
 
349
509
  ```bash
350
- sessionmem install # idempotent — re-registers the MCP server and all three hooks
351
- sessionmem stats # memories, sessions, and session_events for the current project
510
+ sessionmem doctor
511
+ sessionmem doctor --adapter claude-code # explicit host override
352
512
  ```
353
513
 
514
+ `doctor` reports a separate PASS or FAIL for the memory store, schema, hook
515
+ definitions shipped with the current version, configured MCP command, and a
516
+ canary write/recall. It exits nonzero if any check fails and prints fix hints,
517
+ including exact commands for safe repairs. It does not create a missing store or
518
+ apply migrations. Its temporary canary is isolated from your projects and rolled
519
+ back even on failure. The MCP check starts the installed local command and verifies
520
+ its version, tools, and a stats response; it does not require a running agent.
521
+
522
+ Use `sessionmem ping` to initialize a missing store or apply pending schema
523
+ migrations, or `sessionmem install --adapter claude-code` to refresh Claude Code's
524
+ MCP registration and hooks. Run repairs with the same `SESSIONMEM_DB_PATH` as
525
+ doctor when using a custom store.
526
+
354
527
  If `stats` shows `sessions: 0` after real work, see [“0 sessions” / no session data recorded](docs/troubleshooting.md#0-sessions--no-session-data-recorded). Memories are keyed to the **repository root**, so every directory inside one repo shares a bucket; outside a repo the working directory itself is the key.
355
528
 
356
- Quick checks:
529
+ To check database access and memory counts:
357
530
 
358
531
  ```bash
359
- sessionmem ping # is the server reachable?
532
+ sessionmem ping # can the local database be opened?
360
533
  sessionmem stats # is data being stored?
361
534
  ```
362
535
 
@@ -365,16 +538,16 @@ sessionmem stats # is data being stored?
365
538
  ## FAQ
366
539
 
367
540
  **How do I give Cursor, Cline, or Windsurf memory between sessions?**
368
- Install sessionmem (`npm i -g sessionmem`), then run `sessionmem install` in your project. It registers as an MCP server with any supported host automatically.
541
+ Install sessionmem (`npm i -g sessionmem`), then run `sessionmem install` in your project. Use `--adapter cursor`, `--adapter cline`, or `--adapter windsurf` when auto-detection cannot identify your host.
369
542
 
370
543
  **How do I give Claude Code persistent memory?**
371
- Same install. sessionmem also ships as a Claude Code plugin (the `.claude-plugin` file in the repo), so it works with Claude Code's native plugin system too.
544
+ Use the same install steps above. sessionmem also ships as a Claude Code plugin (the `.claude-plugin` directory in the repo) for Claude Code's native plugin system.
372
545
 
373
546
  **Is there a local MCP memory server that works offline with no API key?**
374
- Yes. sessionmem stores everything in a single SQLite file at `~/.sessionmem/memories.db` and works fully offline by default. Nothing leaves your machine unless you explicitly enable the optional cloud summarization path.
547
+ Yes. sessionmem stores memories in a single SQLite file at `~/.sessionmem/memories.db` and works offline by default. Sharing and cloud summarization are optional and off by default.
375
548
 
376
549
  **How is sessionmem different from claude-mem?**
377
- sessionmem is not Claude-only. It works with Cursor, Cline, Codex, Windsurf, Antigravity, QCoder, and any other MCP host, not just Claude Code. It also redacts secrets (API keys, tokens, JWTs) by default, prunes stale memory automatically, and ships reproducible benchmarks you can run yourself.
550
+ sessionmem works with Claude Code, Cursor, Cline, Codex, Windsurf, Antigravity, QCoder, and other MCP hosts. It redacts secrets (API keys, tokens, JWTs) by default, prunes old memories automatically, and includes reproducible benchmarks.
378
551
 
379
552
  **Does sessionmem send my code to the cloud?**
380
553
  No. Nothing leaves your machine by default. The optional cloud summarization path is opt-in and off by default.
@@ -384,18 +557,29 @@ Run `sessionmem savings` to see a breakdown of storage compression (raw session
384
557
 
385
558
  ---
386
559
 
560
+ ## Security
561
+
562
+ See the [security policy](SECURITY.md) for supported versions, private vulnerability
563
+ reporting through GitHub security advisories, and response expectations.
564
+
565
+ ---
566
+
387
567
  ## Contributing
388
568
 
389
569
  Issues and pull requests are welcome. The codebase is TypeScript, tested with [Vitest](https://vitest.dev), and linted with ESLint:
390
570
 
391
571
  ```bash
392
- npm install
572
+ npm ci
393
573
  npm run build
574
+ npm run typecheck
394
575
  npm test
395
576
  npm run lint
396
577
  ```
397
578
 
398
- **MCP config for local development:** Copy `.mcp.json.example` to `.mcp.json` for local dev, or use `sessionmem install` to auto-configure. The `.mcp.json` file is gitignored because it contains machine-specific paths.
579
+ **MCP config for local development:** Clone the repository, build it, copy
580
+ `.mcp.json.example` to `.mcp.json`, and replace the example path with the absolute
581
+ path to your checkout’s `dist/cli/index.js`. This runs your local build.
582
+ `sessionmem install` registers the `sessionmem` executable on PATH instead. The `.mcp.json` file is gitignored because it contains machine-specific paths.
399
583
 
400
584
  ---
401
585