@psiclawops/hypermem 0.8.5 → 0.9.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 (87) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/INSTALL.md +132 -9
  3. package/README.md +119 -272
  4. package/bench/README.md +42 -0
  5. package/bench/data-access-bench.mjs +380 -0
  6. package/bin/hypermem-bench.mjs +2 -0
  7. package/bin/hypermem-doctor.mjs +412 -0
  8. package/bin/hypermem-model-audit.mjs +339 -0
  9. package/bin/hypermem-status.mjs +491 -70
  10. package/dist/adaptive-lifecycle.d.ts +81 -0
  11. package/dist/adaptive-lifecycle.d.ts.map +1 -0
  12. package/dist/adaptive-lifecycle.js +190 -0
  13. package/dist/budget-policy.d.ts +1 -1
  14. package/dist/budget-policy.d.ts.map +1 -1
  15. package/dist/budget-policy.js +10 -5
  16. package/dist/cache.d.ts +1 -0
  17. package/dist/cache.d.ts.map +1 -1
  18. package/dist/cache.js +2 -0
  19. package/dist/composition-snapshot-integrity.d.ts +36 -0
  20. package/dist/composition-snapshot-integrity.d.ts.map +1 -0
  21. package/dist/composition-snapshot-integrity.js +131 -0
  22. package/dist/composition-snapshot-runtime.d.ts +59 -0
  23. package/dist/composition-snapshot-runtime.d.ts.map +1 -0
  24. package/dist/composition-snapshot-runtime.js +250 -0
  25. package/dist/composition-snapshot-store.d.ts +44 -0
  26. package/dist/composition-snapshot-store.d.ts.map +1 -0
  27. package/dist/composition-snapshot-store.js +117 -0
  28. package/dist/compositor.d.ts +125 -1
  29. package/dist/compositor.d.ts.map +1 -1
  30. package/dist/compositor.js +692 -44
  31. package/dist/doc-chunk-store.d.ts +19 -0
  32. package/dist/doc-chunk-store.d.ts.map +1 -1
  33. package/dist/doc-chunk-store.js +56 -6
  34. package/dist/hybrid-retrieval.d.ts +38 -0
  35. package/dist/hybrid-retrieval.d.ts.map +1 -1
  36. package/dist/hybrid-retrieval.js +86 -1
  37. package/dist/index.d.ts +12 -3
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +28 -2
  40. package/dist/knowledge-store.d.ts +4 -1
  41. package/dist/knowledge-store.d.ts.map +1 -1
  42. package/dist/knowledge-store.js +27 -4
  43. package/dist/library-schema.d.ts +12 -8
  44. package/dist/library-schema.d.ts.map +1 -1
  45. package/dist/library-schema.js +22 -8
  46. package/dist/message-store.d.ts.map +1 -1
  47. package/dist/message-store.js +7 -3
  48. package/dist/metrics-dashboard.d.ts +18 -1
  49. package/dist/metrics-dashboard.d.ts.map +1 -1
  50. package/dist/metrics-dashboard.js +52 -14
  51. package/dist/reranker.d.ts +1 -1
  52. package/dist/reranker.js +2 -2
  53. package/dist/schema.d.ts +1 -1
  54. package/dist/schema.d.ts.map +1 -1
  55. package/dist/schema.js +28 -1
  56. package/dist/seed.d.ts.map +1 -1
  57. package/dist/seed.js +2 -0
  58. package/dist/topic-synthesizer.d.ts +20 -0
  59. package/dist/topic-synthesizer.d.ts.map +1 -1
  60. package/dist/topic-synthesizer.js +113 -3
  61. package/dist/trigger-registry.d.ts.map +1 -1
  62. package/dist/trigger-registry.js +10 -2
  63. package/dist/types.d.ts +271 -1
  64. package/dist/types.d.ts.map +1 -1
  65. package/dist/version.d.ts +7 -7
  66. package/dist/version.d.ts.map +1 -1
  67. package/dist/version.js +17 -7
  68. package/docs/DIAGNOSTICS.md +205 -0
  69. package/docs/INTEGRATION_VALIDATION.md +186 -0
  70. package/docs/MIGRATION.md +9 -6
  71. package/docs/MIGRATION_GUIDE.md +125 -101
  72. package/docs/ROADMAP.md +238 -20
  73. package/docs/TUNING.md +19 -5
  74. package/install.sh +152 -401
  75. package/memory-plugin/LICENSE +190 -0
  76. package/memory-plugin/README.md +20 -0
  77. package/memory-plugin/dist/index.js +50 -0
  78. package/memory-plugin/package.json +2 -2
  79. package/package.json +18 -4
  80. package/plugin/LICENSE +190 -0
  81. package/plugin/README.md +20 -0
  82. package/plugin/dist/index.d.ts +29 -0
  83. package/plugin/dist/index.d.ts.map +1 -1
  84. package/plugin/dist/index.js +288 -23
  85. package/plugin/dist/index.js.map +1 -1
  86. package/plugin/package.json +2 -2
  87. package/scripts/install-runtime.mjs +12 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,32 @@
2
2
 
3
3
  All notable changes to hypermem are documented here.
4
4
 
5
+ ## 0.9.0 - adaptive context lifecycle
6
+
7
+ - **Adaptive lifecycle is now production behavior.** Compose, afterTurn, recall, trim, compaction, and eviction share the same pressure-band policy across bootstrap, warmup, steady, elevated, high, and critical states.
8
+ - **Smart recall and adaptive eviction landed.** `/new` and confident topic shifts widen recall, high-pressure turns gate recall down, and topic-centroid-guided eviction activates only at elevated pressure or worse.
9
+ - **Lifecycle telemetry is release-gated.** Trim and compose reports classify lifecycle bands, divergence, and metadata-only topic signal without exposing topic names, prompt text, document text, or user content.
10
+ - **Deterministic topic evidence replaces live-sample gating.** The 0.9.0 topic-bearing compose gate is covered by deterministic fixtures and report tests, while live topic-bearing samples remain future tuning evidence only.
11
+ - **Forked-context integration is wired.** Forked subagent children inherit bounded parent hot-window context and start warmup or steady instead of cold bootstrap unless `/new` is explicit.
12
+ - **Vector coverage is repaired.** Active facts, knowledge, and eligible episodes reached 100% vector coverage before the release candidate validation pass.
13
+
14
+ ## 0.8.8 - release hardening, diagnostics, lifecycle visibility
15
+
16
+ - **Release packaging aligned across packages.** Core, hypercompositor, and memory plugin versions align at 0.8.8, with version parity validation and bump-script hardening to prevent stale plugin dependencies or lockfile drift.
17
+ - **Installer path simplified.** The shell installer now follows the npm-first path, stages the runtime with `hypermem-install`, preserves existing config/data, backs up existing staged runtime when confirmed, and prints merge-safe OpenClaw activation commands.
18
+ - **Integration validation documented.** `docs/INTEGRATION_VALIDATION.md` defines the install state machine, fresh install checks, upgrade checks, package dry-run validation, and common integration failure signatures.
19
+ - **Diagnostics documented.** `docs/DIAGNOSTICS.md` covers `hypermem-status`, `hypermem-model-audit`, compose/trim reports, version parity, release-path checks, runtime logs, warm restore diagnostics, adaptive lifecycle diagnostics, and the runtime diagnostics API allowlist blocker.
20
+ - **Adaptive lifecycle visibility landed.** The pure lifecycle policy kernel, compose diagnostics, and afterTurn gradient cap are wired while leaving recall breadth, eviction tuning, and telemetry tuning deferred to 0.9.0.
21
+ - **Warm restore hardening is included.** Snapshot integrity, repaired restore paths, provider/parity gates, repair notices, and repair-depth caps are covered by validation guidance and release tests.
22
+ - **Reranker and embedding fixes are included.** Reranker wiring, ZeroEntropy endpoint handling, sqlite-vec native runtime packaging, and provider/model diagnostics are part of the 0.8.8 operational release train.
23
+
24
+ ## 0.8.6 — docs cleanup, model audit config parsing, validator fix
25
+
26
+ - **`hypermem-model-audit` now understands object-shaped OpenClaw model config.** It correctly reads `model.primary` plus fallback arrays from modern agent config instead of reporting an empty model set.
27
+ - **Docs release notes no longer drift on package version text.** README and INSTALL now point operators to the next npm release instead of hard-coding conflicting minimum versions.
28
+ - **README and INSTALL roles are clearer.** INSTALL is explicitly the canonical operator bring-up guide, while README stays as the shorter install-state overview.
29
+ - **Docs validator false positives fixed.** `scripts/validate-docs.mjs` now checks only `openclaw config set plugins.slots.* ...` lines, so `config get` examples no longer trigger bogus plugin-id mismatch warnings.
30
+
5
31
  ## 0.8.5 — provider/model-aware failover detection, release parity
6
32
 
7
33
  - **Provider + model identity is now tracked explicitly in HyperCompositor model state.** Mid-session routing changes are detected on the full `provider/model` key, not budget alone, so `github-copilot/claude-sonnet-4-6` and `anthropic/claude-sonnet-4-6` are treated as different operational envelopes.
package/INSTALL.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # hypermem — Installation Guide
2
2
 
3
+ This is the canonical install procedure. Keep README shorter and point operators here for the full bring-up path.
4
+
3
5
  ## Prerequisites
4
6
 
5
7
  - **Node.js 22+** (uses built-in `node:sqlite`)
@@ -15,11 +17,41 @@ openclaw config get gateway # should return gateway config, not an error
15
17
 
16
18
  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
19
 
20
+ ## Non-OpenClaw usage
21
+
22
+ HyperMem can also be used as a normal Node.js library without OpenClaw plugins. This mode is useful for tests, custom agents, migration tooling, and experiments with the memory/composition API.
23
+
24
+ ```bash
25
+ npm install @psiclawops/hypermem
26
+ ```
27
+
28
+ ```typescript
29
+ import { HyperMem } from '@psiclawops/hypermem';
30
+ import { join } from 'node:path';
31
+ import { homedir } from 'node:os';
32
+
33
+ const hm = await HyperMem.create({
34
+ dataDir: join(homedir(), '.openclaw', 'hypermem'),
35
+ embedding: { provider: 'none' },
36
+ });
37
+
38
+ await hm.recordUserMessage('my-agent', 'session-1', 'Hello');
39
+ const composed = await hm.compose({
40
+ agentId: 'my-agent',
41
+ sessionKey: 'session-1',
42
+ prompt: 'Hello',
43
+ tokenBudget: 4000,
44
+ provider: 'anthropic',
45
+ });
46
+ ```
47
+
48
+ No gateway, plugin load path, or OpenClaw config is required in library mode. OpenClaw-specific setup starts below.
49
+
18
50
  ## Quick Start
19
51
 
20
52
  This guide is deliberately declarative. Follow the steps in order and verify each install state before moving on.
21
53
 
22
- > **Release note:** if the npm package you installed does not contain `hypermem-install` or `install:runtime`, you are on an older public release. Use the source-clone path in this guide or wait for `0.8.4+`.
54
+ > **Release note:** if the npm package you installed does not contain `hypermem-install`, `install:runtime`, and `hypermem-model-audit`, you are on an older public release. Use the source-clone path in this guide or wait for the next npm release.
23
55
 
24
56
  ```bash
25
57
  npm install @psiclawops/hypermem
@@ -28,6 +60,16 @@ npx hypermem-install
28
60
 
29
61
  `hypermem-install` stages the plugin runtime into `~/.openclaw/plugins/hypermem`. It does **not** modify your OpenClaw config and does **not** restart the gateway. That means a successful `npx hypermem-install` is **not** a completed install. It is only a completed staging step.
30
62
 
63
+ The shell installer is now a thin npm-first wrapper around this same path:
64
+
65
+ ```bash
66
+ curl -fsSL https://raw.githubusercontent.com/PsiClawOps/hypermem/main/install.sh | bash
67
+ ```
68
+
69
+ It installs the npm package into `~/.hypermem`, backs up any existing staged runtime when confirmed, stages the runtime with `hypermem-install`, writes a lightweight starter config only if no config exists, and prints merge-safe OpenClaw activation commands. It does not edit OpenClaw config and does not restart the gateway.
70
+
71
+ Release validation details live in [docs/INTEGRATION_VALIDATION.md](./docs/INTEGRATION_VALIDATION.md). Diagnostic surfaces live in [docs/DIAGNOSTICS.md](./docs/DIAGNOSTICS.md).
72
+
31
73
  > **Prerequisites:** OpenClaw must be installed and onboarded. Run `openclaw gateway status` to confirm. If the gateway is not configured, complete OpenClaw setup first.
32
74
  >
33
75
  > **Config merge warning:** if you already have values in `plugins.load.paths` or `plugins.allow`, merge them instead of overwriting blindly.
@@ -118,7 +160,17 @@ OpenClaw loads the plugin runtime from `~/.openclaw/plugins/hypermem/`.
118
160
 
119
161
  ### Verification checkpoints
120
162
 
121
- Walk the install state machine explicitly:
163
+ Run the installed-system doctor first:
164
+
165
+ ```bash
166
+ hypermem-doctor --fix-plan
167
+ ```
168
+
169
+ `hypermem-doctor` is read-only. It inspects OpenClaw config, HyperMem config, plugin wiring, recommended OpenClaw runtime settings, data directory shape, runtime plugin load state, and active model context-window risk. It prints exact `openclaw config set ...` commands when something needs review. It does not edit config or restart the gateway.
170
+
171
+ Expected result after a complete install: no required failures. Recommendation warnings should be reviewed before production use, especially context-window warnings for GPT/OpenAI-compatible/local gateways.
172
+
173
+ Walk the install state machine explicitly if you need a manual check:
122
174
 
123
175
  1. **Runtime staged**
124
176
  ```bash
@@ -142,29 +194,73 @@ Walk the install state machine explicitly:
142
194
  Expected: both `hypercompositor` and `hypermem` show as loaded.
143
195
 
144
196
  4. **Runtime healthy**
145
- Run from the repo clone directory, because `bin/` is a relative path:
146
197
  ```bash
147
- node bin/hypermem-status.mjs --health
198
+ hypermem-status --health
148
199
  ```
149
200
  Expected on fresh installs: the plugin may report `no sessions ingested` or empty counts. That means healthy but unused, not broken.
150
201
 
151
- 5. **Runtime active**
202
+ 5. **Model budget audited**
203
+ ```bash
204
+ hypermem-model-audit --strict
205
+ ```
206
+ Expected: every configured model either matches a known context-window pattern or has explicit `contextWindowOverrides`. For GPT/OpenAI-compatible/local gateways, prefer explicit overrides unless logs prove OpenClaw passes a correct runtime `tokenBudget`.
207
+
208
+ 6. **Runtime active**
152
209
 
153
210
  Send a message to any agent, then verify:
154
211
 
155
212
  ```bash
156
- openclaw logs --limit 100 | grep -E 'hypermem|context-engine'
213
+ openclaw logs --limit 100 | grep -E 'hypermem|context-engine|budget source'
157
214
  ```
158
215
 
159
216
  Expected lightweight-mode lines:
160
217
  - `[hypermem] hypermem initialized`
161
218
  - `[hypermem] Embedding provider: none — semantic search disabled, using FTS5 fallback`
162
219
  - `[hypermem:compose]`
220
+ - `budget source: runtime tokenBudget=...` or `budget source: contextWindowOverrides[...]` for the active model
163
221
 
164
222
  If you see a fallback like `falling back to default engine "legacy"`, the install is **not** fully active yet even if staging and wiring succeeded.
165
223
 
166
224
  ---
167
225
 
226
+ ## Upgrade Path
227
+
228
+ Upgrades preserve the HyperMem data directory and existing config. The runtime staging directory is replaceable.
229
+
230
+ ```bash
231
+ cp -a ~/.openclaw/plugins/hypermem ~/.openclaw/plugins/hypermem.backup.$(date +%Y%m%d-%H%M%S) 2>/dev/null || true
232
+ npm install @psiclawops/hypermem@latest
233
+ npx hypermem-install
234
+ openclaw gateway restart
235
+ ```
236
+
237
+ Then validate:
238
+
239
+ ```bash
240
+ openclaw plugins list
241
+ openclaw logs --limit 100 | grep -E 'hypermem|context-engine|falling back'
242
+ hypermem-status --health
243
+ hypermem-model-audit --strict
244
+ ```
245
+
246
+ Pass criteria:
247
+
248
+ - `~/.openclaw/hypermem/config.json` is preserved unless the operator edits it intentionally.
249
+ - existing `~/.openclaw/hypermem/agents/*/messages.db` files remain present.
250
+ - `openclaw plugins list` shows both `hypercompositor` and `hypermem`.
251
+ - logs do not show `falling back to default engine "legacy"`.
252
+ - health output is clean, or reports only healthy-empty state on unused installs.
253
+
254
+ Rollback disables HyperMem without deleting data:
255
+
256
+ ```bash
257
+ openclaw config set plugins.slots.contextEngine legacy
258
+ openclaw config set plugins.slots.memory none
259
+ openclaw gateway restart
260
+ ```
261
+
262
+ ---
263
+
168
264
  ## What hypermem Does
169
265
 
170
266
  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.
@@ -716,6 +812,16 @@ Solo installs can skip this.
716
812
 
717
813
  ## Token Budget Tuning
718
814
 
815
+ **Lookup paths for operators and agents.** To inspect the active config at any time:
816
+
817
+ ```bash
818
+ cat ~/.openclaw/hypermem/config.json
819
+ openclaw config get plugins.entries.hypercompositor.config
820
+ openclaw config get plugins.slots.contextEngine
821
+ ```
822
+
823
+ Resolution order is: (1) `plugins.entries.hypercompositor.config` in `openclaw.json`, (2) `~/.openclaw/hypermem/config.json`, (3) code defaults. See [docs/TUNING.md](./docs/TUNING.md) for the full tuning reference.
824
+
719
825
  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.
720
826
 
721
827
  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.
@@ -785,6 +891,10 @@ HyperMem sizes the token budget from the model string using an internal pattern
785
891
  - `warmHistoryBudgetFraction` × *wrong budget* → wrong warm load on first turn
786
892
  - Trim tiers and compaction thresholds fire against the wrong ceiling
787
893
 
894
+ **Treat this as mandatory tuning, not optional polish.** If the runtime does not pass the real model budget, you must supply the correct window yourself. In practice that means OpenAI-compatible surfaces, Codex/OpenRouter-style providers, custom provider prefixes, and local model gateways often need an explicit override because the model string alone is not a trustworthy source of truth.
895
+
896
+ **When you know both numbers, set both.** Each override entry accepts `contextTokens` and `contextWindow`. HyperMem resolves from `contextTokens` first, then `contextWindow`, and the validator enforces `contextTokens <= contextWindow`. Setting both makes your intended usable budget explicit and documents the full advertised window for future operators.
897
+
788
898
  The two symptoms that indicate window-detection failure:
789
899
 
790
900
  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.
@@ -800,6 +910,16 @@ The two symptoms that indicate window-detection failure:
800
910
 
801
911
  If you see `fallback contextWindowSize` for your model, detection failed and you need an override.
802
912
 
913
+ **Packaged audit helper.** HyperMem now ships `hypermem-model-audit`, which inspects your configured models plus any existing `contextWindowOverrides` and flags models that are running on risky autodetect paths:
914
+
915
+ ```bash
916
+ hypermem-model-audit
917
+ hypermem-model-audit --strict
918
+ hypermem-model-audit --models openai-codex/gpt-5.4,ollama/llama-3.3-70b
919
+ ```
920
+
921
+ Use it during install and after model changes. `--strict` exits non-zero if a model is missing explicit metadata or is only partially overridden.
922
+
803
923
  **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):
804
924
 
805
925
  ```json
@@ -809,9 +929,10 @@ If you see `fallback contextWindowSize` for your model, detection failed and you
809
929
  "contextWindowReserve": 0.25,
810
930
  "warmHistoryBudgetFraction": 0.27,
811
931
  "contextWindowOverrides": {
812
- "ollama/llama-3.3-70b": { "contextTokens": 131072 },
813
- "copilot-local/custom-sft": { "contextTokens": 32768 },
814
- "vllm/qwen3-coder-ft": { "contextTokens": 262144 }
932
+ "ollama/llama-3.3-70b": { "contextTokens": 131072, "contextWindow": 131072 },
933
+ "openai-codex/gpt-5.4": { "contextTokens": 200000, "contextWindow": 200000 },
934
+ "copilot-local/custom-sft": { "contextTokens": 32768, "contextWindow": 32768 },
935
+ "vllm/qwen3-coder-ft": { "contextTokens": 262144, "contextWindow": 262144 }
815
936
  }
816
937
  }
817
938
  }
@@ -826,6 +947,8 @@ Resolution order, highest-to-lowest priority:
826
947
 
827
948
  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.
828
949
 
950
+ **OpenAI-family warning.** Do not assume `gpt-*`, `openai/*`, `openai-codex/*`, or OpenAI-compatible hosted endpoints will always arrive with correct runtime budget metadata. If you cannot prove the runtime is logging `runtime tokenBudget=...` for that exact model, add an explicit override and verify it in logs before tuning anything else.
951
+
829
952
  **Interaction with warming and trimming.** Once the correct window is in place:
830
953
 
831
954
  - First-turn warm load = `detectedWindow × budgetFraction × (1 - contextWindowReserve) × warmHistoryBudgetFraction`