@psiclawops/hypermem 0.8.1 → 0.8.3

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/INSTALL.md ADDED
@@ -0,0 +1,887 @@
1
+ # hypermem — Installation Guide
2
+
3
+ ## Prerequisites
4
+
5
+ - **Node.js 22+** (uses built-in `node:sqlite`)
6
+ - **OpenClaw** must already be installed, onboarded, and running. HyperMem is a plugin for an existing OpenClaw deployment -- it does not bootstrap OpenClaw itself. If you have never run `openclaw gateway start` or completed OpenClaw onboarding, do that first. The HyperMem install guide picks up after OpenClaw is operational.
7
+ - **Disk space:** allow at least 2 GB free. Plugin builds pull OpenClaw as a dev dependency.
8
+
9
+ **Verify before starting:**
10
+
11
+ ```bash
12
+ openclaw gateway status # should show "running" or "ready"
13
+ openclaw config get gateway # should return gateway config, not an error
14
+ ```
15
+
16
+ If `gateway status` shows "disabled" or "not configured", complete OpenClaw onboarding first. `openclaw gateway restart` only works when the gateway service is already set up. On a brand-new OpenClaw install that has never been started, you need `openclaw gateway start` (or the full onboarding flow) before installing plugins.
17
+
18
+ ## Quick Start
19
+
20
+ ```bash
21
+ npm install @psiclawops/hypermem
22
+ npx hypermem-install
23
+ ```
24
+
25
+ `hypermem-install` stages the plugin runtime into `~/.openclaw/plugins/hypermem`. It does **not** modify your OpenClaw config and does **not** restart the gateway.
26
+
27
+ > **Prerequisites:** OpenClaw must be installed and onboarded. Run `openclaw gateway status` to confirm. If the gateway is not configured, complete OpenClaw setup first.
28
+ >
29
+ > **Config merge warning:** if you already have values in `plugins.load.paths` or `plugins.allow`, merge them instead of overwriting blindly.
30
+
31
+ Create the config directory and set the embedding provider:
32
+
33
+ ```bash
34
+ mkdir -p ~/.openclaw/hypermem
35
+ cat > ~/.openclaw/hypermem/config.json <<'JSON'
36
+ {
37
+ "embedding": {
38
+ "provider": "none"
39
+ }
40
+ }
41
+ JSON
42
+ ```
43
+
44
+ Wire both plugins into OpenClaw:
45
+
46
+ **Step 1: Check your existing config (mandatory — do this before wiring).**
47
+
48
+ ```bash
49
+ openclaw config get plugins.load.paths
50
+ openclaw config get plugins.allow
51
+ ```
52
+
53
+ Note any existing values. You must include them in the commands below.
54
+
55
+ **Step 2: Wire plugins.**
56
+
57
+ ```bash
58
+ # Wire plugin load paths — merge with any existing paths from Step 1:
59
+ openclaw config set plugins.load.paths "[\"${HOME}/.openclaw/plugins/hypermem/plugin\",\"${HOME}/.openclaw/plugins/hypermem/memory-plugin\"]" --strict-json
60
+
61
+ # Set the context engine and memory slots:
62
+ openclaw config set plugins.slots.contextEngine hypercompositor
63
+ openclaw config set plugins.slots.memory hypermem
64
+
65
+ # Allow both plugins — merge with any existing allowed plugins from Step 1.
66
+ # Example (if "my-plugin" was already allowed):
67
+ ocplatform config set plugins.allow '["my-plugin","hypercompositor","hypermem"]' --strict-json
68
+ ```
69
+
70
+ > **⚠️ Merge, don't replace.** The command above sets `plugins.allow` to whatever you specify. If `plugins.allow` was non-empty in Step 1, include those entries in the array. Replacing it drops existing plugins (including bundled OpenClaw CLI surfaces and channel plugins).
71
+
72
+ **Step 3: Restart.**
73
+
74
+ ```bash
75
+ openclaw gateway restart
76
+ ```
77
+
78
+ OpenClaw loads the plugin runtime from `~/.openclaw/plugins/hypermem/`.
79
+
80
+ ### Verification checkpoints
81
+
82
+ 1. **Build verified**
83
+ - root build succeeds
84
+ - `plugin` build succeeds
85
+ - `memory-plugin` build succeeds
86
+
87
+ 2. **Wiring verified**
88
+ - OpenClaw accepts `plugins.load.paths`
89
+ - slots are set to `hypercompositor` and `hypermem`
90
+ - gateway restart succeeds
91
+
92
+ 3. **Runtime verified active**
93
+
94
+ Send a message to any agent, then verify:
95
+
96
+ ```bash
97
+ openclaw logs --limit 100 | grep -E 'hypermem|context-engine'
98
+ ```
99
+
100
+ Expected lightweight-mode lines:
101
+ - `[hypermem] hypermem initialized`
102
+ - `[hypermem] Embedding provider: none — semantic search disabled, using FTS5 fallback`
103
+ - `[hypermem:compose]`
104
+
105
+ If you see a fallback like `falling back to default engine "legacy"`, the install is **not** fully active yet even if the build and wiring steps succeeded.
106
+
107
+ ---
108
+
109
+ ## What hypermem Does
110
+
111
+ hypermem replaces OpenClaw's default context assembly with a four-layer SQLite-backed memory system. Every turn, it queries all layers in parallel and composes context within a fixed token budget. No transcript accumulates. No lossy summarization. Content that doesn't fit this turn stays in storage instead of being destroyed.
112
+
113
+ | Layer | Storage | What it holds | Speed |
114
+ |---|---|---|---|
115
+ | **L1** | SQLite in-memory | Session cache: identity, recent history, active state | 0.08ms |
116
+ | **L2** | Per-agent SQLite | Conversation history, survives restarts, rotates at 100MB | 0.13ms |
117
+ | **L3** | Per-agent SQLite + sqlite-vec | Semantic search via embeddings | 0.29ms |
118
+ | **L4** | Shared SQLite | Structured knowledge: facts, episodes, preferences, fleet registry | 0.09ms |
119
+
120
+ Everything runs in-process on SQLite memory databases. No external database services required.
121
+
122
+ ---
123
+
124
+ ## Requirements
125
+
126
+ | Dependency | Required | Notes |
127
+ |---|---|---|
128
+ | Node.js 22+ | **Yes** | Uses built-in `node:sqlite`. No standalone SQLite install needed. |
129
+ | OpenClaw | **Yes** | Any version with context engine plugin support |
130
+ | Ollama | Local embeddings only | [ollama.ai](https://ollama.ai) — pull `nomic-embed-text` |
131
+ | OpenRouter API key | Hosted embeddings only | Alternative to local: [openrouter.ai](https://openrouter.ai) |
132
+ | Gemini API key | Gemini embeddings only | Alternative: [aistudio.google.com](https://aistudio.google.com/apikey) |
133
+
134
+ `sqlite-vec` is the only native dependency and installs automatically via npm.
135
+
136
+ > **Package versions:** the root package (`hypermem`) and the two plugins (`hypercompositor`, `hypermem-memory`) are versioned independently. Plugin versions trail the core by one minor version when no plugin-facing API changes ship in a release — this is expected.
137
+
138
+ The **embedding layer** (L3 semantic search) requires a configured provider. Without one, hypermem falls back to FTS5 keyword matching. This is functional but degrades recall quality. See [Setup Styles](#setup-styles) below.
139
+
140
+ ---
141
+
142
+ ## Setup Styles
143
+
144
+ Pick a style based on your hardware and cost tolerance. All styles support full history, fact recall, and session continuity — the differences are in semantic search quality and local resource requirements.
145
+
146
+ | Style | Embedding | Reranker | Semantic recall | Cost | Hardware |
147
+ |---|---|---|---|---|---|
148
+ | **Lightweight** | None (FTS5 only) | None | Keyword match only | Free | Any |
149
+ | **Local** | Ollama nomic-embed-text | None (RRF) or Ollama Qwen3-Reranker (GPU only) | Good | Free | ~1GB RAM + GPU for reranker |
150
+ | **High** | OpenRouter Qwen3-8B | OpenRouter Cohere Rerank 4 | Best (MTEB #1) | ~pennies/day | API key |
151
+
152
+ The **reranker is optional at every tier.** Without one, results are ordered by RRF fusion score (FTS5 + vector) — a solid default. The reranker improves precision but requires a GPU for the local option; CPU-only systems should leave it as None.
153
+
154
+ ---
155
+
156
+ ## Embedding Providers
157
+
158
+ Pick a tier based on your hardware:
159
+
160
+ | Tier | Provider | Quality | Cost | Setup |
161
+ |---|---|---|---|---|
162
+ | **Minimal** | None (FTS5 keyword only) | Keyword-only, no semantic recall | Free | None |
163
+ | **Local** | Ollama + nomic-embed-text (768d) | Good | Free | Ollama required |
164
+ | **Hosted** | OpenRouter + Qwen3 Embedding 8B (4096d) | Best (MTEB #1) | ~pennies/day | API key |
165
+ | **Gemini** | Google Gemini Embedding (768d) | Good | Free tier available | API key |
166
+
167
+ ### Minimal (no embedder)
168
+
169
+ No Ollama, no API key. This config must exist **before gateway restart and runtime verification** so the clean install validates the intended lightweight behavior. Set `provider: 'none'` explicitly in `~/.openclaw/hypermem/config.json` to disable embedding entirely:
170
+
171
+ ```json
172
+ {
173
+ "embedding": {
174
+ "provider": "none"
175
+ }
176
+ }
177
+ ```
178
+
179
+ Without a config file, the default provider is `ollama` — if Ollama isn't running, the vector store initialization fails non-fatally and hypermem falls back to FTS5. Using `provider: 'none'` makes the intent explicit and avoids the init attempt.
180
+
181
+ You'll see in the logs:
182
+ ```
183
+ [hypermem] Embedding provider: none — semantic search disabled, using FTS5 fallback
184
+ ```
185
+
186
+ Upgrade to a higher tier later without losing stored data.
187
+
188
+ ### Troubleshooting clean installs
189
+
190
+ **Symptom:** `Context engine "hypercompositor" ... falling back to default engine "legacy"`
191
+ - The plugin was found, but the context engine did not activate correctly.
192
+ - Treat the install as failed at runtime, not successful.
193
+ - Check for release artifact mismatch, stale plugin build output, or config collisions with existing plugin paths.
194
+
195
+ **Symptom:** HyperMem logs never appear after restart
196
+ - Re-check `plugins.load.paths` for exact absolute paths.
197
+ - Confirm the clone directory still exists and was not created in a temp location.
198
+ - Confirm existing `plugins.allow` and `plugins.load.paths` values were merged correctly instead of overwritten incorrectly.
199
+
200
+ **Symptom:** build succeeds, but behavior is not lightweight mode
201
+ - Confirm `~/.openclaw/hypermem/config.json` existed before restart.
202
+ - Confirm it contains:
203
+ ```json
204
+ {
205
+ "embedding": {
206
+ "provider": "none"
207
+ }
208
+ }
209
+ ```
210
+
211
+ ### Local — Ollama + nomic-embed-text
212
+
213
+ ```bash
214
+ ollama pull nomic-embed-text
215
+ ```
216
+
217
+ No config file needed. Ollama on `localhost:11434` with `nomic-embed-text` is the default. Requires ~1GB RAM for the model.
218
+
219
+ ### Hosted — OpenRouter + Qwen3 Embedding 8B (Recommended)
220
+
221
+ Best quality, no local compute. Embedding is async and doesn't affect agent response time.
222
+
223
+ Create or edit `~/.openclaw/hypermem/config.json`:
224
+
225
+ ```json
226
+ {
227
+ "embedding": {
228
+ "provider": "openai",
229
+ "openaiApiKey": "sk-or-YOUR_OPENROUTER_KEY",
230
+ "openaiBaseUrl": "https://openrouter.ai/api/v1",
231
+ "model": "qwen/qwen3-embedding-8b",
232
+ "dimensions": 4096,
233
+ "batchSize": 128
234
+ }
235
+ }
236
+ ```
237
+
238
+ Get a key at [openrouter.ai](https://openrouter.ai). Cost at typical agent volumes: under a cent per day.
239
+
240
+ ### Gemini
241
+
242
+ Create or edit `~/.openclaw/hypermem/config.json`:
243
+
244
+ ```json
245
+ {
246
+ "embedding": {
247
+ "provider": "gemini",
248
+ "geminiApiKey": "YOUR_GEMINI_API_KEY",
249
+ "model": "text-embedding-004",
250
+ "dimensions": 768,
251
+ "batchSize": 128
252
+ }
253
+ }
254
+ ```
255
+
256
+ Get a key at [aistudio.google.com](https://aistudio.google.com/apikey). The free tier covers typical agent usage.
257
+
258
+ Optional Gemini-specific settings:
259
+ - `geminiBaseUrl`: defaults to `https://generativelanguage.googleapis.com`
260
+ - `geminiIndexTaskType`: defaults to `RETRIEVAL_DOCUMENT`
261
+ - `geminiQueryTaskType`: defaults to `RETRIEVAL_QUERY`
262
+
263
+ ### Switching providers
264
+
265
+ Changing providers after vectors are built requires a full re-index (dimensions are incompatible):
266
+
267
+ ```bash
268
+ node scripts/embed-existing.mjs
269
+ ```
270
+
271
+ Fresh installs don't need this.
272
+
273
+ ---
274
+
275
+ ## Reranker (Optional)
276
+
277
+ The reranker re-orders semantic search candidates by relevance before injection. Without it, results are ordered by RRF fusion score (FTS5 + KNN). The reranker is optional — the system degrades gracefully to original order on any failure.
278
+
279
+ | Provider | Model | Cost | Hardware | Notes |
280
+ |---|---|---|---|---|
281
+ | **None** | — | Free | Any | Default — RRF fusion ordering |
282
+ | **Ollama (local)** | Qwen3-Reranker-0.6B | Free | GPU recommended | CPU-only: too slow for >5 candidates |
283
+ | **OpenRouter** | cohere/rerank-4-pro | ~pennies/day | Any | Best quality, uses existing key |
284
+ | **ZeroEntropy** | zerank-2 | ~pennies/day | Any | Dedicated reranking service |
285
+
286
+ **CPU-only systems:** skip the local reranker. Sequential inference makes it 2-10 seconds per document on CPU — unusable at any reasonable candidate depth. RRF fusion (`provider: "none"`) is the right default for CPU-only setups and is meaningfully better than raw vector ordering alone.
287
+
288
+ ### No reranker (default)
289
+
290
+ No config needed. RRF fusion of FTS5 + vector results is the default ordering. For most conversational memory workloads, this is sufficient and runs on any hardware.
291
+
292
+ ### Local — Ollama Qwen3-Reranker-0.6B
293
+
294
+ Best option for air-gapped or GPU-equipped setups. Slower than hosted due to sequential inference (one model call per candidate document) — requires a GPU for practical use.
295
+
296
+ ```bash
297
+ ollama pull dengcao/Qwen3-Reranker-0.6B:Q5_K_M
298
+ ```
299
+
300
+ Add to `~/.openclaw/hypermem/config.json`:
301
+
302
+ ```json
303
+ {
304
+ "reranker": {
305
+ "provider": "local",
306
+ "ollamaUrl": "http://localhost:11434",
307
+ "ollamaModel": "dengcao/Qwen3-Reranker-0.6B:Q5_K_M",
308
+ "topK": 10,
309
+ "minCandidates": 5
310
+ }
311
+ }
312
+ ```
313
+
314
+ ### Hosted — OpenRouter (Cohere Rerank 4)
315
+
316
+ Fastest, highest quality. Uses the same OpenRouter key as hosted embeddings if you already have one.
317
+
318
+ Put the key in your environment, not the config file:
319
+
320
+ ```bash
321
+ export OPENROUTER_API_KEY="sk-or-YOUR_OPENROUTER_KEY"
322
+ ```
323
+
324
+ Then in `~/.openclaw/hypermem/config.json`:
325
+
326
+ ```json
327
+ {
328
+ "reranker": {
329
+ "provider": "openrouter",
330
+ "openrouterModel": "cohere/rerank-4-pro",
331
+ "topK": 10,
332
+ "minCandidates": 5
333
+ }
334
+ }
335
+ ```
336
+
337
+ `openrouterApiKey` in the config file is still honored as a fallback for compatibility, but env-var-first keeps credentials out of any config-under-version-control.
338
+
339
+ ### Hosted — ZeroEntropy (zerank-2)
340
+
341
+ Alternative hosted option, specialized reranking service.
342
+
343
+ ```bash
344
+ export ZEROENTROPY_API_KEY="YOUR_ZEROENTROPY_KEY"
345
+ ```
346
+
347
+ Then:
348
+
349
+ ```json
350
+ {
351
+ "reranker": {
352
+ "provider": "zeroentropy",
353
+ "zeroEntropyModel": "zerank-2",
354
+ "topK": 10,
355
+ "minCandidates": 5
356
+ }
357
+ }
358
+ ```
359
+
360
+ `zeroEntropyApiKey` in the config file is still honored as a fallback. Get a key at [zeroentropy.dev](https://zeroentropy.dev).
361
+
362
+ ---
363
+
364
+ ## Installation Steps
365
+
366
+ ### Step 1 — Source Build (contributors)
367
+
368
+ > **Most users should use the npm Quick Start above.** This section is for contributors or users who need to modify HyperMem source.
369
+
370
+ ```bash
371
+ git clone https://github.com/PsiClawOps/hypermem.git
372
+ cd hypermem
373
+ npm install
374
+ npm run build
375
+ ```
376
+
377
+ Build both plugins, then install the runtime payload into OCPlatform's durable plugin directory:
378
+
379
+ ```bash
380
+ npm --prefix plugin install && npm --prefix plugin run build
381
+ npm --prefix memory-plugin install && npm --prefix memory-plugin run build
382
+ npm run install:runtime
383
+ ```
384
+
385
+ Verify:
386
+
387
+ ```bash
388
+ npm test
389
+ ```
390
+
391
+ The full suite takes 30–60 seconds. When complete, output ends with `N passed, 0 failed`. If you see `ENOSPC`, free up disk space and retry.
392
+
393
+ ### Step 2 — Wire the plugins
394
+
395
+ Use the OpenClaw CLI. **Do not edit `openclaw.json` directly.**
396
+
397
+ ```bash
398
+ # Check existing values first — merge if non-empty:
399
+ ocplatform config get plugins.load.paths
400
+ openclaw config get plugins.allow
401
+
402
+ # Wire plugin load paths (merge with any existing paths):
403
+ openclaw config set plugins.load.paths "[\"${HOME}/.openclaw/plugins/hypermem/plugin\",\"${HOME}/.openclaw/plugins/hypermem/memory-plugin\"]" --strict-json
404
+
405
+ # Set the context engine and memory slots:
406
+ openclaw config set plugins.slots.contextEngine hypercompositor
407
+ openclaw config set plugins.slots.memory hypermem
408
+
409
+ # Allow both plugins — merge with any existing allowed plugins (example includes "my-plugin"):
410
+ ocplatform config set plugins.allow '["my-plugin","hypercompositor","hypermem"]' --strict-json
411
+ ```
412
+
413
+ > **⚠️ Merge, don't replace.** Check `openclaw config get plugins.allow` before running this command and include all existing entries in the array.
414
+
415
+ ### Step 3 — Choose embedding provider
416
+
417
+ See [Embedding Providers](#embedding-providers) above.
418
+
419
+ - **Lightweight (no embedder):** create `~/.openclaw/hypermem/config.json` with `{"embedding":{"provider":"none"}}`. The Quick Start block above already does this. Without this file, the default provider is `ollama` and you'll see a non-fatal init warning if Ollama isn't running.
420
+ - **Local:** `ollama pull nomic-embed-text`. No config file needed (Ollama is the default).
421
+ - **Hosted/Gemini:** create `~/.openclaw/hypermem/config.json` with the provider config block from the relevant section above.
422
+
423
+ ### Step 4 — Restart and verify
424
+
425
+ ```bash
426
+ openclaw gateway restart
427
+ ```
428
+
429
+ > **If restart reports the gateway is disabled or not configured:** you need to complete OpenClaw onboarding before this step. See [Prerequisites](#prerequisites). `gateway restart` only works on an already-running gateway.
430
+
431
+ Send a message to any agent, then check:
432
+
433
+ ```bash
434
+ openclaw logs --limit 50 | grep hypermem
435
+ ```
436
+
437
+ > **If `openclaw logs` fails with an auth or token error:** the gateway API requires authentication. Run `openclaw gateway status` to confirm the gateway is running and accessible. If the gateway is running but logs fail, check `openclaw config get gateway.token` and ensure your shell session has the correct auth context.
438
+
439
+ Expected:
440
+ ```
441
+ [hypermem] hypermem initialized — dataDir=/home/.../.openclaw/hypermem
442
+ [hypermem:compose] agent=main triggers=0 fallback=true facts=3 semantic=2 ...
443
+ ```
444
+
445
+ Full health check (run from the repo clone directory — `bin/` is a relative path):
446
+
447
+ ```bash
448
+ node bin/hypermem-status.mjs # full dashboard
449
+ node bin/hypermem-status.mjs --health # health checks only (exit 1 on failure)
450
+ ```
451
+
452
+ > **Note:** The health check requires the data directory to exist. It is created on first gateway restart with the plugin active. Run the `openclaw logs` check first to confirm initialization, then run the health check.
453
+ >
454
+ > **Empty results on fresh installs are normal.** If the health check shows `facts=0`, `episodes=0`, or `no agent messages.db found`, that means the install worked but no conversations have happened yet. Data populates after real agent sessions.
455
+
456
+ If the plugin didn't load:
457
+
458
+ ```bash
459
+ openclaw config get plugins.slots.contextEngine # should be: hypercompositor
460
+ openclaw config get plugins.slots.memory # should be: hypermem
461
+ openclaw status # look for hypermem in plugins
462
+ ```
463
+
464
+ ### Step 5 — Configure your fleet
465
+
466
+ hypermem works out of the box for both single-agent and multi-agent installs. The source ships with generic placeholder agent names (`agent1`, `agent2`, `director1`, etc.) in two files that define fleet topology:
467
+
468
+ | File | What it defines |
469
+ |---|---|
470
+ | `src/cross-agent.ts` | Org membership, agent tiers, visibility scoping |
471
+ | `src/background-indexer.ts` | Agent-to-domain mapping for fact classification |
472
+
473
+ #### Single-agent installs
474
+
475
+ No code changes needed. hypermem resolves your agent ID from your OpenClaw config at runtime. The placeholder names are never used.
476
+
477
+ Verify it's working after Step 4:
478
+
479
+ ```bash
480
+ openclaw logs --limit 20 | grep hypermem
481
+ ```
482
+
483
+ You should see your agent ID (not a placeholder) in the compose logs:
484
+
485
+ ```
486
+ [hypermem:compose] agent=my-agent triggers=0 fallback=true facts=3 semantic=2 ...
487
+ ```
488
+
489
+ Facts, episodes, and topics are all scoped to your agent ID automatically. Cross-agent features (org visibility, shared facts) are dormant with a single agent and activate only when additional agents are configured.
490
+
491
+ #### Multi-agent installs
492
+
493
+ hypermem ships with generic placeholder agent names (`agent1`, `agent2`, `director1`, etc.) in the two fleet topology files listed above.
494
+
495
+ Replace the placeholder names with your fleet:
496
+
497
+ **1. Edit `src/cross-agent.ts`** — replace the `agents` map and `orgs` map in `defaultOrgRegistry()` with your fleet:
498
+
499
+ ```typescript
500
+ // Before (placeholder):
501
+ agent1: { agentId: 'agent1', tier: 'council' },
502
+
503
+ // After (your fleet):
504
+ architect: { agentId: 'architect', tier: 'council' },
505
+ ```
506
+
507
+ **2. Edit `src/background-indexer.ts`** — update `AGENT_DOMAIN_MAP` with your agent IDs and their domains:
508
+
509
+ ```typescript
510
+ // Before (placeholder):
511
+ agent1: 'infrastructure',
512
+
513
+ // After (your fleet):
514
+ architect: 'infrastructure',
515
+ ```
516
+
517
+ **3. Rebuild and restart:**
518
+
519
+ ```bash
520
+ npm run build
521
+ npm --prefix plugin run build
522
+ openclaw gateway restart
523
+ ```
524
+
525
+ Agents not listed in `AGENT_DOMAIN_MAP` default to domain `'general'`, which is fine for most setups. The org registry only matters if you use cross-agent memory visibility (org-scoped or council-scoped facts). If all your facts are agent-private or fleet-wide, you can skip the org structure entirely.
526
+
527
+ **Test fixtures use the placeholder names by design.** Don't rename them in `test/` — the tests validate the cross-agent logic, not your specific fleet topology.
528
+
529
+ ---
530
+
531
+ ## Upgrading from 0.5.x
532
+
533
+ ```bash
534
+ cd <path-to-hypermem>
535
+ git pull
536
+ npm install
537
+ npm run build
538
+ npm --prefix plugin install && npm --prefix plugin run build
539
+ npm --prefix memory-plugin install && npm --prefix memory-plugin run build
540
+ openclaw gateway restart
541
+ ```
542
+
543
+ What changed on the path from 0.5.x to current:
544
+ - **0.6.0**: SQLite `:memory:` became the only hot layer. Redis was fully removed and the runtime no longer depends on any external cache service.
545
+ - **0.7.0**: Temporal validity, expertise storage, contradiction detection, and maintenance APIs landed.
546
+ - **0.8.1**: Documentation fixes — install instructions rewritten for clean first-run, `$HOME` replaces `~` in shell-interpolated paths, Lightweight mode config clarified.
547
+ - **0.8.0**: Phase C correctness guards, tool-artifact store, schema v10/v19, BLAKE3 dedup, RRF fusion, and fleet registry seeding shipped.
548
+ - **Upgrade impact**: current releases use `messages.db` schema v10 and `library.db` schema v19. If you are upgrading from older 0.5.x installs, expect both schema and runtime-behavior changes.
549
+
550
+ What changed in 0.5.x releases:
551
+ - **0.5.5**: Plugin config schema, tuning knobs moved into `openclaw.json`. Manual `config.json` edits for compositor settings may be superseded by the plugin schema.
552
+ - **0.5.6**: Content fingerprint dedup, indexer circuit breaker, SQL parameterization hardening.
553
+ - **Exports field** added to `package.json`: if you import from `@psiclawops/hypermem`, verify your import paths still resolve.
554
+
555
+ If you switch embedding providers during the upgrade, re-index:
556
+
557
+ ```bash
558
+ node scripts/embed-existing.mjs
559
+ ```
560
+
561
+ Check [CHANGELOG.md](CHANGELOG.md) for the full list of changes per version.
562
+
563
+ **Build errors after upgrade:** Clean `dist/` directories and rebuild:
564
+
565
+ ```bash
566
+ rm -rf dist plugin/dist memory-plugin/dist
567
+ npm run build
568
+ npm --prefix plugin run build
569
+ npm --prefix memory-plugin run build
570
+ ```
571
+
572
+ ---
573
+
574
+ ## OpenClaw Platform Settings
575
+
576
+ HyperMem manages its own context pressure, memory injection, and compaction. Several OpenClaw defaults conflict with this or are too conservative for memory-augmented agents. Apply these after plugin installation, before the gateway restart.
577
+
578
+ ### Disable OpenClaw context pruning (required)
579
+
580
+ OpenClaw has a built-in context pruning system (`cache-ttl` mode) that independently truncates and clears tool results from the message history based on time and context-window ratio thresholds. When HyperMem is active, these two systems fight each other: OpenClaw prunes tool results to free space, then HyperMem injects context that refills it, triggering aggressive compaction on the next turn. The result is unpredictable amnesia.
581
+
582
+ Disable OpenClaw's pruning and let HyperMem handle context pressure exclusively:
583
+
584
+ ```bash
585
+ openclaw config set agents.defaults.contextPruning.mode off
586
+ ```
587
+
588
+ ### Startup context (recommended)
589
+
590
+ Controls how much daily memory context agents receive on session start. The defaults are very conservative (2 days, 2800 chars total). For memory-augmented agents, increase these so agents wake up with meaningful context:
591
+
592
+ ```bash
593
+ openclaw config set agents.defaults.startupContext.dailyMemoryDays 4 --strict-json
594
+ openclaw config set agents.defaults.startupContext.maxFileChars 4000 --strict-json
595
+ openclaw config set agents.defaults.startupContext.maxTotalChars 12000 --strict-json
596
+ openclaw config set agents.defaults.startupContext.maxFileBytes 32768 --strict-json
597
+ ```
598
+
599
+ This gives agents 4 days of working memory at startup (~12k chars total). Still under 10% of a 128k context window.
600
+
601
+ ### Bootstrap max chars (recommended)
602
+
603
+ Controls the maximum size of bootstrap files (AGENTS.md, SOUL.md, etc.) injected on session start. The default (12000) is tight for agents with governance rules, tool references, and identity docs:
604
+
605
+ ```bash
606
+ ocplatform config set agents.defaults.bootstrapMaxChars 20000 --strict-json
607
+ ```
608
+
609
+ ### Compaction safety net
610
+
611
+ OpenClaw's built-in compaction (`safeguard` mode) serves as a last-resort safety net. Keep it enabled but tuned so it only fires when HyperMem's own pressure management is insufficient:
612
+
613
+ ```bash
614
+ ocplatform config set agents.defaults.compaction.mode safeguard
615
+ openclaw config set agents.defaults.compaction.reserveTokens 16384 --strict-json
616
+ ocplatform config set agents.defaults.compaction.keepRecentTokens 6000 --strict-json
617
+ ocplatform config set agents.defaults.compaction.reserveTokensFloor 15000 --strict-json
618
+ openclaw config set agents.defaults.compaction.maxHistoryShare 0.65 --strict-json
619
+ ```
620
+
621
+ This reserves 16k tokens for reply generation. HyperMem's own pressure system (afterTurn at 80%, nuclear at 85%) fires first in normal operation. OpenClaw's safeguard catches edge cases.
622
+
623
+ ### LLM idle timeout
624
+
625
+ Tool-heavy sessions with large outputs can stall during streaming. Raise the idle timeout from the default (120s):
626
+
627
+ ```bash
628
+ openclaw config set agents.defaults.llm.idleTimeoutSeconds 300 --strict-json
629
+ ```
630
+
631
+ ### Tighter session store retention
632
+
633
+ With HyperMem active, SQLite is the durable record. JSONL transcripts provide no memory benefit:
634
+
635
+ ```bash
636
+ openclaw config set sessions.maintenance.pruneAfter "14d"
637
+ openclaw config set sessions.maintenance.maxEntries 200 --strict-json
638
+ ```
639
+
640
+ OpenClaw defaults: `pruneAfter: 30d`, `maxEntries: 500`. If you browse conversation history older than 14 days via the session list, keep the higher value.
641
+
642
+ ### Session max-age (fleet installs only)
643
+
644
+ Prevents idle sessions from accumulating indefinitely:
645
+
646
+ ```bash
647
+ openclaw config set sessions.maxAgeHours 168 --strict-json # 7 days
648
+ ```
649
+
650
+ Solo installs can skip this.
651
+
652
+ ---
653
+
654
+ ## Token Budget Tuning
655
+
656
+ These settings live in `~/.openclaw/hypermem/config.json` under the `compositor` key. All fields are optional — omit any knob to get the code-level default. Gateway restart required after changes.
657
+
658
+ The recommended starting config for a standard single-agent deployment is intentionally lean on turn-1 warming. Semantic recall and fact triggers fire against each incoming message, so topic-relevant context surfaces as the conversation takes shape. This produces a steadier pressure profile than aggressive pre-loading and avoids the warm→trim→compact cycling you see when every session starts near the top of the budget.
659
+
660
+ ```json
661
+ {
662
+ "compositor": {
663
+ "budgetFraction": 0.55,
664
+ "contextWindowReserve": 0.25,
665
+ "targetBudgetFraction": 0.50,
666
+ "warmHistoryBudgetFraction": 0.27,
667
+ "maxFacts": 25,
668
+ "maxHistoryMessages": 500,
669
+ "maxCrossSessionContext": 4000,
670
+ "maxRecentToolPairs": 3,
671
+ "maxProseToolPairs": 10,
672
+ "keystoneHistoryFraction": 0.15,
673
+ "keystoneMaxMessages": 12,
674
+ "wikiTokenCap": 500
675
+ }
676
+ }
677
+ ```
678
+
679
+ | Knob | Recommended | What it controls | Notes |
680
+ |---|---|---|---|
681
+ | `budgetFraction` | 0.55 | Fraction of the detected context window used as input budget | Raise to 0.65 for agents that aggressively tool-use. Autodetect only handles known model families — see *Context window overrides* below for custom/local/finetuned models |
682
+ | `contextWindowReserve` | 0.25 | Reserve left for output and tool results | Below 0.20 on large-context models invites late-turn overflow |
683
+ | `targetBudgetFraction` | 0.50 | Split between context assembly and history | Higher = richer facts/wiki; lower = more conversation headroom |
684
+ | `warmHistoryBudgetFraction` | 0.27 | History's share of first-turn warming | The key lever against tight trim cycles; don't push below 0.20 |
685
+ | `maxFacts` | 25 | Structured facts injected per turn | Recall surfaces more as topics emerge; 35 is fine for long-memory seats |
686
+ | `maxHistoryMessages` | 500 | Candidate pool for history ranking | Pool size, not load size. 300 is fine for short-session agents |
687
+ | `maxCrossSessionContext` | 4000 | Cross-session context tokens | Solo agents with one session: set to 0 |
688
+ | `maxRecentToolPairs` | 3 | Verbatim tool pairs kept | Raise to 5 for code agents with heavy tool output |
689
+ | `maxProseToolPairs` | 10 | Compressed tool pairs before stubbing | |
690
+ | `keystoneHistoryFraction` | 0.15 | Older significant turns reserved within history slot | |
691
+ | `keystoneMaxMessages` | 12 | Max keystone candidates per turn | Raise to 18 if the agent loses track of older decisions |
692
+ | `wikiTokenCap` | 500 | Cap on wiki/knowledge injection | Raise if your agent uses heavy doc content |
693
+
694
+ **Lean profile** (~35–45% fewer tokens per turn) — for constrained hosts, small models, or cost-sensitive deployments:
695
+
696
+ ```json
697
+ {
698
+ "compositor": {
699
+ "budgetFraction": 0.55,
700
+ "contextWindowReserve": 0.30,
701
+ "warmHistoryBudgetFraction": 0.20,
702
+ "maxFacts": 10,
703
+ "maxHistoryMessages": 150,
704
+ "maxCrossSessionContext": 0,
705
+ "maxRecentToolPairs": 2,
706
+ "maxProseToolPairs": 6,
707
+ "keystoneHistoryFraction": 0.10,
708
+ "keystoneMaxMessages": 5,
709
+ "wikiTokenCap": 300,
710
+ "hyperformProfile": "light"
711
+ }
712
+ }
713
+ ```
714
+
715
+ ---
716
+
717
+ ### Context window overrides (custom, local, or finetuned models)
718
+
719
+ HyperMem sizes the token budget from the model string using an internal pattern table covering known families (Claude, GPT, Gemini, GLM, Qwen, DeepSeek). If your model string doesn't match a known pattern, resolution silently falls through to `defaultTokenBudget` (90k), and **every downstream dial in this section becomes wrong**, because they're all fractions of the context window:
720
+
721
+ - `budgetFraction` × *wrong window* → wrong input budget
722
+ - `warmHistoryBudgetFraction` × *wrong budget* → wrong warm load on first turn
723
+ - Trim tiers and compaction thresholds fire against the wrong ceiling
724
+
725
+ The two symptoms that indicate window-detection failure:
726
+
727
+ 1. **Undersized window detected** (you have a 200k model, HyperMem thinks it's 90k): every turn warms near the top of the misdetected budget, trim fires constantly, semantic recall and facts get starved. You see continuous `warm→trim→compact` cycling even on short sessions.
728
+ 2. **Oversized window detected** (you have a 32k local model, HyperMem thinks it's larger): warm loads overshoot the real context window, turns land mid-response with truncated output or provider-side 400s on token overflow.
729
+
730
+ **Check what HyperMem is using.** Enable `verboseLogging: true` in the compositor config and look for the `budget source:` log line on each turn:
731
+
732
+ ```
733
+ [hypermem-plugin] budget source: runtime tokenBudget=163840 model=provider/my-model
734
+ [hypermem-plugin] budget source: contextWindowOverrides[provider/my-model]=131072, reserve=0.25, effective=98304
735
+ [hypermem-plugin] budget source: fallback contextWindowSize=90000, reserve=0.25, effective=67500 model=provider/my-model
736
+ ```
737
+
738
+ If you see `fallback contextWindowSize` for your model, detection failed and you need an override.
739
+
740
+ **Apply an override.** Add a `contextWindowOverrides` block to `~/.openclaw/hypermem/config.json`. The key is `"provider/model"` as it appears in your agent's model string (lowercase, exact match):
741
+
742
+ ```json
743
+ {
744
+ "compositor": {
745
+ "budgetFraction": 0.55,
746
+ "contextWindowReserve": 0.25,
747
+ "warmHistoryBudgetFraction": 0.27,
748
+ "contextWindowOverrides": {
749
+ "ollama/llama-3.3-70b": { "contextTokens": 131072 },
750
+ "copilot-local/custom-sft": { "contextTokens": 32768 },
751
+ "vllm/qwen3-coder-ft": { "contextTokens": 262144 }
752
+ }
753
+ }
754
+ }
755
+ ```
756
+
757
+ Resolution order, highest-to-lowest priority:
758
+
759
+ 1. Runtime `tokenBudget` passed by OpenClaw (always wins if present)
760
+ 2. `contextWindowOverrides["provider/model"]` from this config
761
+ 3. Internal pattern-table match against the model string
762
+ 4. `defaultTokenBudget` fallback (90k) — **you do not want to end up here**
763
+
764
+ Gateway restart required after editing overrides. Invalid override entries (malformed keys, impossible ranges, empty values) are dropped on load with a warning; the sanitizer will not let a bad override poison the resolver.
765
+
766
+ **Interaction with warming and trimming.** Once the correct window is in place:
767
+
768
+ - First-turn warm load = `detectedWindow × budgetFraction × (1 - contextWindowReserve) × warmHistoryBudgetFraction`
769
+ - Trim pressure zones are computed from the same `detectedWindow × budgetFraction × (1 - reserve)` effective budget, so trim fires at the right proportions of the real window, not a wrong one
770
+ - Compaction thresholds (85% nuclear, 80% afterTurn trim) are also against the effective budget, not the raw window
771
+
772
+ TL;DR for operators running custom/local/finetuned models: **set `contextWindowOverrides` before tuning anything else in this section**. Every other knob here assumes the detected window is right.
773
+
774
+ ---
775
+
776
+ ## Data Directory
777
+
778
+ Created automatically on first run at `~/.openclaw/hypermem/`:
779
+
780
+ ```
781
+ ~/.openclaw/hypermem/
782
+ ├── config.json ← embedding and compositor tuning (user-created)
783
+ ├── library.db ← L4: facts, episodes, knowledge, fleet registry (shared)
784
+ └── agents/
785
+ └── {agentId}/
786
+ ├── messages.db ← L2: conversation history (per-agent)
787
+ └── vectors.db ← L3: semantic search index (per-agent)
788
+ ```
789
+
790
+ **Backup:** `library.db` and per-agent `messages.db` files are persistent memory. Back them up before major upgrades.
791
+
792
+ **Rotation:** `messages.db` rotates at 100MB or 90 days. Archives (`messages_2026Q1.db` etc.) remain searchable.
793
+
794
+ ---
795
+
796
+ ## Troubleshooting
797
+
798
+ **Semantic search not working / no vector results**
799
+
800
+ Check your embedding tier:
801
+ - **Local (Ollama):** Confirm Ollama is running with `ollama list`. If `nomic-embed-text` is missing, `ollama pull nomic-embed-text` and restart the gateway.
802
+ - **Hosted (OpenRouter):** Verify `openaiApiKey` and `openaiBaseUrl` in `~/.openclaw/hypermem/config.json`.
803
+ - **Gemini:** Verify `geminiApiKey` in config.
804
+ - **Minimal:** Semantic search is intentionally disabled. FTS5 keyword fallback is active.
805
+
806
+ The background indexer runs on a 5-minute interval. After the first cycle, check `openclaw logs | grep embed`.
807
+
808
+ **`facts=0 semantic=0` every turn**
809
+
810
+ Expected on fresh installs. Facts and episodes accumulate over real conversations. After a few sessions these numbers grow. Workspace files can be seeded manually via the seeder API.
811
+
812
+ **Lost bundled plugins after setting `plugins.allow`**
813
+
814
+ If you set `plugins.allow` to only `["hypercompositor","hypermem"]` without including your pre-existing allowed plugins, OpenClaw will stop loading everything else (including built-in CLI surfaces and bundled channel plugins). Fix: re-read your OpenClaw defaults (`openclaw config get plugins.allow`), merge hypermem entries back into the full list, and `openclaw gateway restart`.
815
+
816
+ **Plugin not found**
817
+
818
+ Confirm the installed runtime artifacts exist:
819
+
820
+ ```bash
821
+ ls ~/.openclaw/plugins/hypermem/plugin/dist/index.js
822
+ ls ~/.openclaw/plugins/hypermem/memory-plugin/dist/index.js
823
+ ls ~/.openclaw/plugins/hypermem/dist/index.js
824
+ ```
825
+
826
+ If missing, rebuild and reinstall the runtime payload:
827
+
828
+ ```bash
829
+ cd <path-to-hypermem>
830
+ npm run build
831
+ npm --prefix plugin run build
832
+ npm --prefix memory-plugin run build
833
+ npm run install:runtime
834
+ ```
835
+
836
+ Then restart the gateway.
837
+
838
+ **Build errors after upgrade**
839
+
840
+ Clean `dist/` and rebuild:
841
+
842
+ ```bash
843
+ rm -rf dist plugin/dist memory-plugin/dist
844
+ npm run build
845
+ npm --prefix plugin run build
846
+ npm --prefix memory-plugin run build
847
+ ```
848
+
849
+ **Agent not resuming context after restart**
850
+
851
+ Check that `~/.openclaw/hypermem/agents/{agentId}/messages.db` exists. If missing, the agent hasn't bootstrapped yet and will create it on first session.
852
+
853
+ ---
854
+
855
+ ## Uninstalling
856
+
857
+ To return to OpenClaw's default context engine:
858
+
859
+ ```bash
860
+ openclaw config set plugins.slots.contextEngine legacy
861
+ openclaw config set plugins.slots.memory none
862
+ openclaw gateway restart
863
+ ```
864
+
865
+ Data in `~/.openclaw/hypermem/` is untouched. Re-enable by switching back.
866
+
867
+ ---
868
+
869
+ ## Environment Variables
870
+
871
+ | Variable | Default | Description |
872
+ |---|---|---|
873
+ | `HYPERMEM_DATA_DIR` | `~/.openclaw/hypermem` | Override the data directory where hypermem stores `library.db`, per-agent `messages.db` files, and `vectors.db`. Useful when you want data on a separate volume, need isolated test data dirs, or run multiple hypermem instances. The directory is created automatically if it does not exist. |
874
+
875
+ Example:
876
+
877
+ ```bash
878
+ # Point hypermem at a different data location:
879
+ export HYPERMEM_DATA_DIR=/mnt/data/hypermem
880
+ openclaw gateway restart
881
+ ```
882
+
883
+ > The config file path (`~/.openclaw/hypermem/config.json`) is separate from the data directory. Moving `HYPERMEM_DATA_DIR` does not move the config file.
884
+
885
+ ---
886
+
887
+ _Questions or issues: file against [the repo](https://github.com/PsiClawOps/hypermem) or ask in `#hypermem`._