sessionmem 1.7.0 → 1.8.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.
@@ -0,0 +1,86 @@
1
+ # Automatic capture and recall
2
+
3
+ Install once and restart the host so it loads its MCP configuration and guidance.
4
+ The installed flow does not ask the user to run scans, recall commands or save
5
+ commands during ordinary agent work. Host tool permissions must allow the memory
6
+ tools. `sessionmem doctor --adapter <name>` checks the configured flow and gives
7
+ repair hints for missing hooks, stale instructions, disabled MCP wiring and stale
8
+ watcher checkpoints.
9
+
10
+ ## Host audit and behavior
11
+
12
+ | Host | Capture after install | Session-start recall | Recall on prompts |
13
+ | --- | --- | --- | --- |
14
+ | Claude Code | PostToolUse captures Bash/Edit/Write/MultiEdit; SessionEnd summarizes; login watcher also imports transcripts | SessionStart hook catches up transcripts and injects context | UserPromptSubmit hook retrieves context for the submitted prompt |
15
+ | Codex | Login-started watcher imports local rollout transcripts | Global AGENTS.md and MCP instructions tell the agent to search before work and fetch selected details | Instructions tell the agent to search for a new topic |
16
+ | Cursor | Login-started watcher imports supported local composer SQLite records | Project always-apply rule and global MCP instructions tell the agent to search before work | Same instruction-driven topic recall |
17
+ | Windsurf | Agent calls storeMemory/batchStoreMemory under global rules; no transcript importer | Global rules and MCP instructions | Instruction-driven topic recall |
18
+ | Cline | Agent calls storeMemory/batchStoreMemory under installed rules; no transcript importer | Installed rules and MCP instructions | Instruction-driven topic recall |
19
+ | Antigravity, QCoder adapters | Agent tool saves when the host loads the configured MCP server and guidance; no transcript importer | Instruction-driven; existing adapter file paths are unverified against the native products | Instruction-driven; host loading must be verified |
20
+ | Generic MCP | Agent tool saves when the host reads project AGENTS.md or MCP instructions; no transcript importer | Instruction-driven, dependent on host support | Instruction-driven topic recall |
21
+
22
+ Only Claude Code has deterministic host hooks in this integration. Instruction-
23
+ driven recall is configured by install, but doctor cannot prove that a model
24
+ executed the instructions or that an unverified native host loaded a guessed
25
+ configuration path. Doctor marks Antigravity/QCoder automation unestablished and
26
+ gives a native-settings verification hint. Its output identifies this distinction. The tests simulate
27
+ an agent following the installed instructions; they do not launch proprietary
28
+ host interfaces or claim that every model obeys instructions.
29
+
30
+ The watcher starts immediately at install and at login through launchd on macOS,
31
+ a user systemd service on Linux, or Task Scheduler on Windows. It polls supported
32
+ transcripts every five seconds by default. Capture requires readable transcript
33
+ files in a supported format. A missing directory is valid before the first
34
+ session; an unsupported format or unreadable source is a diagnostic failure.
35
+ No user action is needed to import later sessions while the service is healthy.
36
+
37
+ Claude Code SessionStart and a new MCP server connection also perform an
38
+ incremental catch-up. A session opened immediately after another session can
39
+ therefore recall newly written transcript events before the next watcher poll.
40
+ The MCP server advertises the startup, new-topic recall and decision-save flow
41
+ in its protocol instructions for all hosts. Existing user prose is preserved
42
+ when managed guidance blocks are updated.
43
+
44
+ Cursor rules are project scoped. The old home-level `.cursor/rules` location did
45
+ not establish a rule for arbitrary projects. Install now writes the rule in the
46
+ current project, repairs `alwaysApply:true`, and supplies the same flow through
47
+ the global MCP server's instructions in other projects. A host that ignores MCP
48
+ instructions needs an active native rule in that project.
49
+
50
+ Plain-terminal install detection recognizes Claude Code, Codex, Cursor and
51
+ Windsurf CLI executables when on PATH, plus the documented native Claude paths.
52
+ Other hosts still need selection at setup with `--adapter`. Configuration
53
+ directories alone are not treated as evidence of an installed host.
54
+
55
+ Cline's installed MCP entry preapproves the local search, detail and capture tools
56
+ so these calls do not require a separate user action each time. Deletion and
57
+ external operations are excluded. Other hosts retain their own permission rules.
58
+
59
+ ## Diagnosis and repair
60
+
61
+ Doctor separately reports hook definitions, MCP startup and tool availability,
62
+ current agent instructions, capture mode and recall mode. For hookless hosts it
63
+ says that recall is instruction-driven and execution is unverified. For hosts
64
+ without transcript support it says that capture consists of agent-driven saves,
65
+ not background transcript import. Hook and guidance configuration are checked
66
+ against the current installed version. Failed guidance writes make install fail
67
+ instead of printing a successful setup message.
68
+
69
+ Doctor's MCP probe bypasses startup capture so diagnosis does not import
70
+ transcripts or alter the user's memories. Its isolated storage canary rolls back.
71
+ The watcher-health check requires a recent, successful checkpoint for the selected
72
+ database, rather than assuming that a registered service is running.
73
+
74
+ ## CI evidence
75
+
76
+ `tests/integration/cli/automatic-memory-flow.spec.ts` runs in the CI OS matrix.
77
+ It uses a temporary home and project. The OS supervisor commands are simulated,
78
+ but the registered watcher command performs real transcript ingestion.
79
+
80
+ The Claude case installs the actual hook definitions, feeds capture events,
81
+ ends the session, starts a new session, and verifies the startup and prompt
82
+ context envelopes contain the stored database decision. The Codex and Cursor
83
+ cases create real-format transcript fixtures, install and run the automatic
84
+ watcher sweep, run doctor, then open a new MCP session. A simulated agent follows
85
+ the installed instructions and verifies selected full details reach its context.
86
+ No manual import or scan command is used.
package/docs/benchmark.md CHANGED
@@ -5,6 +5,13 @@
5
5
  [benchmarks/README.md](../benchmarks/README.md) for the corpus license, selection
6
6
  rules, metric definitions, and detailed reproduction instructions.
7
7
 
8
+ ## Compact tools, temporal retrieval and entity fusion
9
+
10
+ See the [retrieval evaluation](../benchmarks/retrieval-gaps.md) for fresh 1.7.0
11
+ baselines, per-category before/after tables, complete regression artifacts and
12
+ measured compact-tool token costs. Temporal and source-informed additive experiments remain off by default. Entity
13
+ coverage improves default BM25; optional hybrid results are preserved.
14
+
8
15
  ## Local semantic and competitor comparison
9
16
 
10
17
  The [measured comparison](../COMPARISON.md) records a new unchanged-main run,
@@ -1,6 +1,8 @@
1
1
  # Optional local semantic retrieval
2
2
 
3
- The default is BM25 plus entity overlap. To add a learned semantic candidate pool,
3
+ The default is BM25 with entity-link coverage. Active MiniLM retains the existing
4
+ entity-overlap fusion because stronger coverage lowered its hit rate and recall.
5
+ To add a learned semantic candidate pool,
4
6
  install the optional packages beside sessionmem and enable it:
5
7
 
6
8
  ```bash
@@ -0,0 +1,144 @@
1
+ # Compact retrieval and optional ranking
2
+
3
+ ## Search, inspect nearby context, then fetch details
4
+
5
+ The MCP server exposes these tools alongside the existing tools. Project scope
6
+ comes from the server, so callers do not supply `projectId` over MCP.
7
+
8
+ | Tool | Input | Output |
9
+ | --- | --- | --- |
10
+ | `searchMemoryIndex` | `query`, optional `limit`, `includeHistory`, `tags` | IDs, one-line summaries, kind, capture date, numeric score, `hasMore` |
11
+ | `memoryTimeline` | `memoryId`, or both `fromDate` and `toDate`; optional `limit`, `includeHistory` | Compact rows in capture order; scores are null |
12
+ | `getMemory` | `memoryId` | One complete stored memory, including content and metadata |
13
+
14
+ Start with `searchMemoryIndex({"query":"database migration","limit":5})`.
15
+ Inspect the surrounding records with
16
+ `memoryTimeline({"memoryId":"selected-id","limit":5})` when chronology matters.
17
+ Fetch only the records needed with `getMemory({"memoryId":"selected-id"})`.
18
+ The existing get-by-ID tool already returns full bodies, so no duplicate tool is
19
+ needed. Existing `retrieveMemories` remains available.
20
+
21
+ Index and timeline limits default to 10 and accept integers from 1 to 50. Summaries
22
+ are extractive previews of stored text, with whitespace collapsed and at most 160
23
+ characters. They can omit qualifiers from longer memories; read the full body
24
+ before relying on a fact. No summaries or inference are generated for these tools.
25
+ Search scores are rounded to four decimal places. Search uses the same ranker as
26
+ `retrieveMemories`, without its startup formatting or access-counter updates.
27
+
28
+ Index `hasMore` describes the bounded retrieval candidate pool, not an exhaustive
29
+ store count. Timeline `hasMore` means more visible records exist outside the
30
+ returned window. Around an ID, it balances earlier and later records and fills
31
+ remaining slots from the available side. Timestamp ties use ID ordering. Ranges
32
+ are inclusive UTC ISO timestamps, for example:
33
+
34
+ ```json
35
+ {"fromDate":"2026-01-01T00:00:00Z","toDate":"2026-01-31T23:59:59.999Z","limit":10}
36
+ ```
37
+
38
+ Timeline dates are **capture dates**, not dates mentioned inside prose. Timeline
39
+ includes superseded records by default so it can explain changes; set
40
+ `includeHistory:false` for current records only. Index excludes fully superseded
41
+ records by default. All three tools enforce project scope and expiry. Compact
42
+ search and timeline do not update access counters. Optional local semantic search
43
+ can still backfill its derived vector index, as with ordinary retrieval.
44
+
45
+ ## Optional temporal retrieval
46
+
47
+ `temporalRetrieval` defaults off. It did not improve the pinned-clock LoCoMo run.
48
+ Enable it for stores with meaningful observation times:
49
+
50
+ ```bash
51
+ sessionmem config set temporalRetrieval true
52
+ ```
53
+
54
+ A deterministic English cue detector recognizes current state (`current`,
55
+ `currently`, `now`, `latest`, `today`, `at present`) and historical questions
56
+ (`before`, `previously`, `formerly`, `prior`, `used to`, `no longer`, `when did`,
57
+ `when was`, `when were`, `in the past`, `historical`, `history`). Dated clauses take
58
+ precedence over current-state cues. With no recognized cue, the previous retrieval
59
+ behavior and scores stay unchanged, even when enabled.
60
+
61
+ Supported ranges are `YYYY-MM-DD`, `YYYY-MM`, `in YYYY`, `during YYYY`, `yesterday`,
62
+ `last/previous week/month/year`, and numeric day/week offsets such as `2 days ago`.
63
+ Relative dates use the injected retrieval clock in UTC; weeks start on Monday and
64
+ months are calendar months. The detector does not interpret arbitrary natural
65
+ language dates, future plans, locale-specific dates or conversational reference
66
+ times. An invalid date supplies no date signal.
67
+
68
+ Historical intent includes superseded candidates automatically unless the caller
69
+ explicitly sets `includeHistory:false`. That decision applies to both lexical and
70
+ optional semantic candidates. Explicit `true` also works for current-state queries.
71
+ Existing supersession rules still determine which facts have changed; no new
72
+ contradiction inference is added.
73
+
74
+ Within relevance, temporal scoring uses a fixed 90% existing relevance and 10%
75
+ time signal. Current-state signals average the non-superseded claim fraction and
76
+ freshness, `1 / (1 + ageDays / 30)`. Historical ranges use the distance from the
77
+ range with the same 30-day scale. `before` and similar previous-state cues favor
78
+ the superseded fraction. Undated historical questions have a neutral time signal.
79
+ The time is the latest extracted claim observation timestamp, falling back to
80
+ original capture time. Editing a row does not invent a new event date.
81
+
82
+ Past queries neutralize ordinary recency and inactivity-based importance decay,
83
+ so age alone does not suppress historical evidence. Stored importance and access
84
+ boosts still apply. Dates rerank candidates; they are not hard date filters and do
85
+ not guarantee that a relevant memory outside the candidate pool will be found.
86
+ For exact capture-date browsing, use `memoryTimeline`.
87
+
88
+ ## Optional entity-link boost
89
+
90
+ Entity coverage is enabled by default when retrieval uses BM25, including when
91
+ optional inference is unavailable. It improves all three primary LoCoMo metrics
92
+ in that mode. With active MiniLM it defaults off because hit rate and recall
93
+ regressed. An explicit `entityLinkBoost` value overrides that mode-specific
94
+ choice. To enable it explicitly:
95
+
96
+ ```bash
97
+ sessionmem config set entityLinkBoost true
98
+ ```
99
+
100
+ The query links literal normalized name spans against the existing
101
+ `memory_entities` tables. Explicit aliases cover `postgres`/`postgresql`,
102
+ `node`/`node.js` and `k8s`/`kubernetes`. There is no fuzzy name matching, pronoun
103
+ resolution, entity embedding, or graph traversal. Extraction rules stay unchanged.
104
+ Project, expiry and requested history visibility apply before link scoring.
105
+
106
+ Each linked `(kind, name)` receives weight
107
+ `1 + log((visibleMemoryCount + 1) / (matchingMemoryCount + 1))`. A memory's entity
108
+ score is its matched weight divided by the total linked weight. Up to 50 highest
109
+ entity-score IDs are admitted to the candidate union, with ID tie breaks. This
110
+ channel can admit rows that were absent from the BM25 or semantic pool.
111
+
112
+ The fixed fusion is 80% base relevance and 20% linked-entity score. With semantic
113
+ search enabled, base relevance retains the existing 2:1 BM25/positive-cosine blend.
114
+ When no entity is linked, the prior scoring path is retained. The existing 10%
115
+ entity-overlap signal remains in use when coverage is off. Temporal
116
+ fusion, when enabled too, follows entity fusion. Outer relevance, recency and
117
+ importance weights remain 60%, 25% and 15%.
118
+
119
+ Disable coverage with `sessionmem config set entityLinkBoost false` and temporal
120
+ retrieval with `sessionmem config set temporalRetrieval false`.
121
+
122
+ ## Source-informed fusion alternatives
123
+
124
+ The optional `retrievalRanking` setting accepts `legacy`, `adaptive-bm25`,
125
+ `hub-additive` and `adaptive-hub-additive`. `legacy` means the existing BM25/dense
126
+ fusion, with the mode-specific entity-coverage default above. Other modes default
127
+ to their stated experiment without coverage, unless explicitly overridden.
128
+
129
+ `adaptive-bm25` uses a query-length adaptive sigmoid on raw positive FTS5 BM25.
130
+ The additive modes use a hub-damped maximum entity boost from at most eight names,
131
+ plus lexical and optional dense signals, divided by the maximum score of active
132
+ channels. A 0.2 semantic gate applies before additive fusion. The adaptive additive
133
+ variant also enables the sigmoid. These hypotheses did not pass the three-metric
134
+ regression gate and remain opt-in. See the
135
+ [source notes](../benchmarks/retrieval-source-notes.md) for exact parameters,
136
+ algorithm differences and licensing scope. No competitor source or prompt was
137
+ adapted. The current defaults select entity coverage for BM25 and the existing
138
+ fusion for MiniLM; there are no per-query-label or per-category exceptions.
139
+
140
+ The temporal and entity settings work alongside the existing `semanticSearch`
141
+ setting. Results,
142
+ per-category losses and token measurements are in the
143
+ [retrieval evaluation](../benchmarks/retrieval-gaps.md). They do not establish
144
+ accuracy for generated answers or gains on coding workloads.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sessionmem",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Local-first MCP memory layer for coding agents across Claude Code, Codex, Cursor, Cline, Windsurf, and other MCP-compatible hosts.",