@matrixorigin/thememoria 0.4.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.
package/README.md ADDED
@@ -0,0 +1,368 @@
1
+ # Memory (Memoria) for OpenClaw
2
+
3
+ This package turns [MatrixOrigin Memoria](https://github.com/matrixorigin/Memoria) into an installable OpenClaw `memory` plugin.
4
+
5
+ The plugin targets the current Rust Memoria CLI and API release line. Installer release tag is configurable via `--memoria-version` / `MEMORIA_RELEASE_TAG`. There is no bundled Python runtime, no virtualenv, and no `pip install` step.
6
+
7
+ ## Architecture
8
+
9
+ - `backend: "embedded"` runs the Rust `memoria` CLI locally via `memoria mcp --db-url ... --user ...`
10
+ - `backend: "http"` connects to an existing Rust Memoria API server
11
+ - OpenClaw keeps its own tool and hook surface, but the storage and retrieval backend is Memoria
12
+
13
+ In practice that means:
14
+
15
+ - durable memory still lives in MatrixOne
16
+ - snapshots, rollback, branches, merge, diff, governance, reflect, and entity extraction are handled by Rust Memoria
17
+ - the plugin shells out to the `memoria` binary instead of importing bundled backend code
18
+ - the `memoria` binary is required even in cloud mode — it serves as the local MCP stdio bridge between OpenClaw and the Memoria backend
19
+
20
+ ## Quick Start
21
+
22
+ ### Preflight
23
+
24
+ Verify prerequisites before installing:
25
+
26
+ ```bash
27
+ openclaw --version
28
+ # -> OpenClaw vX.Y.Z (CLI is installed and in PATH)
29
+
30
+ memoria --version 2>/dev/null || echo "not installed (installer can install it)"
31
+ # -> memoria X.Y.Z or fallback message
32
+
33
+ openclaw plugins list
34
+ # -> command succeeds and prints plugin table
35
+ ```
36
+
37
+ Assume OpenClaw is already installed and healthy.
38
+
39
+ ### Usage Paths
40
+
41
+ 1. GitHub README (this file): cloud-first setup plus local setup.
42
+ 2. OpenClaw chat/agent: user asks agent to install, agent runs commands and returns raw outputs.
43
+
44
+ ### 1) Cloud (Recommended)
45
+
46
+ Cloud is the default path for new users.
47
+
48
+ #### Developer Flow
49
+
50
+ ```bash
51
+ # A0. Optional cleanup (if you installed an older/source-linked memory-memoria before)
52
+ openclaw plugins uninstall memory-memoria
53
+ ```
54
+
55
+ ```bash
56
+ # A0.5. Ensure memoria CLI exists (required even for cloud mode)
57
+ command -v memoria >/dev/null || \
58
+ curl -sSL https://raw.githubusercontent.com/matrixorigin/Memoria/main/scripts/install.sh | bash -s -- -y -d ~/.local/bin
59
+ ```
60
+
61
+ ```bash
62
+ # A1. Install plugin from npm
63
+ openclaw plugins install @matrixorigin/thememoria
64
+ openclaw plugins enable memory-memoria
65
+ # Note: OpenClaw may print "Restart the gateway to apply."
66
+ # This is unnecessary for CLI commands like `setup` below, but harmless if you do restart.
67
+ ```
68
+
69
+ ```bash
70
+ # A2. If npm package is unavailable, use source-link instead
71
+ mkdir -p ~/.openclaw/plugins-src
72
+ if [ ! -d ~/.openclaw/plugins-src/Memoria/.git ]; then
73
+ git clone https://github.com/matrixorigin/Memoria.git ~/.openclaw/plugins-src/Memoria
74
+ else
75
+ git -C ~/.openclaw/plugins-src/Memoria pull --ff-only
76
+ fi
77
+ openclaw plugins install --link ~/.openclaw/plugins-src/Memoria/plugins/openclaw
78
+ openclaw plugins enable memory-memoria
79
+ ```
80
+
81
+ ```bash
82
+ # B. Setup Memoria Cloud
83
+ openclaw memoria setup \
84
+ --mode cloud \
85
+ --api-url <MEMORIA_API_URL> \
86
+ --api-key <MEMORIA_API_KEY> \
87
+ --install-memoria
88
+ ```
89
+
90
+ Success standard:
91
+
92
+ ```bash
93
+ openclaw memoria health
94
+ # must include: "status": "ok"
95
+ ```
96
+
97
+ #### Agent Prompt (Cloud)
98
+
99
+ ```text
100
+ Install Memoria plugin for my OpenClaw in cloud mode.
101
+ Use:
102
+ - apiUrl: <MEMORIA_API_URL>
103
+ - apiKey: <MEMORIA_API_KEY>
104
+
105
+ Execute exactly:
106
+ 1) Ensure memoria CLI exists:
107
+ command -v memoria >/dev/null || curl -sSL https://raw.githubusercontent.com/matrixorigin/Memoria/main/scripts/install.sh | bash -s -- -y -d ~/.local/bin
108
+ 2) Try npm install first:
109
+ openclaw plugins install @matrixorigin/thememoria
110
+ 3) If step 2 fails, fallback:
111
+ mkdir -p ~/.openclaw/plugins-src
112
+ if [ ! -d ~/.openclaw/plugins-src/Memoria/.git ]; then git clone https://github.com/matrixorigin/Memoria.git ~/.openclaw/plugins-src/Memoria; else git -C ~/.openclaw/plugins-src/Memoria pull --ff-only; fi
113
+ openclaw plugins install --link ~/.openclaw/plugins-src/Memoria/plugins/openclaw
114
+ 4) Enable plugin:
115
+ openclaw plugins enable memory-memoria
116
+ 5) Setup cloud:
117
+ openclaw memoria setup --mode cloud --api-url <MEMORIA_API_URL> --api-key <MEMORIA_API_KEY> --install-memoria
118
+ 6) Verify:
119
+ openclaw memoria health
120
+
121
+ Output requirements:
122
+ - Return all executed commands and raw outputs
123
+ - If failed, classify as network/auth/config and provide exact fix commands
124
+ - Do not hide or summarize errors
125
+ ```
126
+
127
+ ### 2) Local (Embedded)
128
+
129
+ Use local mode when you explicitly want self-hosted storage/runtime.
130
+
131
+ #### Developer Flow
132
+
133
+ ```bash
134
+ # A. Install memoria CLI (if missing)
135
+ curl -sSL https://raw.githubusercontent.com/matrixorigin/Memoria/main/scripts/install.sh | bash -s -- -y -d ~/.local/bin
136
+
137
+ # B1. Install + enable plugin from npm
138
+ openclaw plugins install @matrixorigin/thememoria
139
+ openclaw plugins enable memory-memoria
140
+ ```
141
+
142
+ ```bash
143
+ # B2. If npm package is unavailable, use source-link instead
144
+ mkdir -p ~/.openclaw/plugins-src
145
+ if [ ! -d ~/.openclaw/plugins-src/Memoria/.git ]; then
146
+ git clone https://github.com/matrixorigin/Memoria.git ~/.openclaw/plugins-src/Memoria
147
+ else
148
+ git -C ~/.openclaw/plugins-src/Memoria pull --ff-only
149
+ fi
150
+ openclaw plugins install --link ~/.openclaw/plugins-src/Memoria/plugins/openclaw
151
+ openclaw plugins enable memory-memoria
152
+ ```
153
+
154
+ ```bash
155
+ # C0. Local quick start (use plugin defaults for db/provider/model)
156
+ openclaw memoria setup \
157
+ --mode local \
158
+ --install-memoria \
159
+ --embedding-api-key <EMBEDDING_API_KEY>
160
+ ```
161
+
162
+ ```bash
163
+ # C. Setup local backend (advanced/custom values)
164
+ openclaw memoria setup \
165
+ --mode local \
166
+ --db-url <MATRIXONE_DSN> \
167
+ --embedding-provider <provider> \
168
+ --embedding-model <model> \
169
+ --embedding-api-key <embedding_key> \
170
+ --embedding-dim <dim> \
171
+ --install-memoria \
172
+ --memoria-bin ~/.local/bin/memoria
173
+ ```
174
+
175
+ Success standard:
176
+
177
+ ```bash
178
+ openclaw memoria health
179
+ # must include: "status": "ok"
180
+ ```
181
+
182
+ #### Agent Prompt (Local)
183
+
184
+ ```text
185
+ Install Memoria plugin for my OpenClaw in local mode.
186
+ Use:
187
+ - dbUrl: <MATRIXONE_DSN>
188
+ - embeddingProvider: <provider>
189
+ - embeddingModel: <model>
190
+ - embeddingApiKey: <embedding_key>
191
+ - embeddingDim: <dim>
192
+
193
+ Execute exactly:
194
+ 1) Ensure memoria CLI exists (install if missing):
195
+ curl -sSL https://raw.githubusercontent.com/matrixorigin/Memoria/main/scripts/install.sh | bash -s -- -y -d ~/.local/bin
196
+ 2) Try npm install first:
197
+ openclaw plugins install @matrixorigin/thememoria
198
+ 3) If step 2 fails, fallback:
199
+ mkdir -p ~/.openclaw/plugins-src
200
+ if [ ! -d ~/.openclaw/plugins-src/Memoria/.git ]; then git clone https://github.com/matrixorigin/Memoria.git ~/.openclaw/plugins-src/Memoria; else git -C ~/.openclaw/plugins-src/Memoria pull --ff-only; fi
201
+ openclaw plugins install --link ~/.openclaw/plugins-src/Memoria/plugins/openclaw
202
+ 4) Enable plugin:
203
+ openclaw plugins enable memory-memoria
204
+ 5) Setup local (quick start):
205
+ openclaw memoria setup --mode local --install-memoria --embedding-api-key <EMBEDDING_API_KEY>
206
+ If custom MatrixOne/provider/model is required, append:
207
+ --db-url <MATRIXONE_DSN> --embedding-provider <provider> --embedding-model <model> --embedding-dim <dim>
208
+ 6) Verify:
209
+ openclaw memoria health
210
+
211
+ Output requirements:
212
+ - Return all executed commands and raw outputs
213
+ - If failed, report the missing dependency/permission/config exactly
214
+ - Do not hide or summarize errors
215
+ ```
216
+
217
+ ## Local Installer Inputs (Optional)
218
+
219
+ Use this section when you choose `openclaw memoria install` for local bootstrap/repair.
220
+
221
+ > **Cloud users:** skip all embedding and LLM environment variables below. These are only used in local/embedded mode. Cloud mode only needs `--api-url` and `--api-key` via `openclaw memoria setup`.
222
+
223
+ Important environment variables (local/embedded mode only):
224
+
225
+ - `MEMORIA_DB_URL`: embedded MatrixOne DSN. Default: `mysql://root:111@127.0.0.1:6001/memoria`
226
+ - `MEMORIA_EMBEDDING_PROVIDER`: usually `openai`; `local` only works if your `memoria` binary was built with the `local-embedding` feature
227
+ - `MEMORIA_EMBEDDING_MODEL`: for example `text-embedding-3-small` or `BAAI/bge-m3`
228
+ - `MEMORIA_EMBEDDING_API_KEY`: required for local/embedded mode unless embedding provider is `local`. Not needed for cloud mode.
229
+ - `MEMORIA_EMBEDDING_BASE_URL`: optional for official OpenAI, required for compatible gateways
230
+ - `MEMORIA_EMBEDDING_DIM`: must match the embedding model before first startup
231
+ - `MEMORIA_LLM_API_KEY`, `MEMORIA_LLM_BASE_URL`, `MEMORIA_LLM_MODEL`: optional, only needed for `autoObserve` and internal LLM-backed Memoria tools
232
+ - `MEMORIA_EXECUTABLE`: optional explicit path to an existing `memoria` binary
233
+ - `MEMORIA_RELEASE_TAG`: Rust Memoria release tag to install. Default: installer-defined release tag
234
+
235
+ Installer flags:
236
+
237
+ - `--openclaw-bin <path|command>`: use an explicit `openclaw` executable
238
+ - `--memoria-bin <path|command>`: use an existing `memoria` executable
239
+ - `--memoria-version <tag>`: override the Rust Memoria release tag
240
+ - `--memoria-install-dir <path>`: where to install `memoria` if it is missing
241
+ - `--binary-only`: install/validate `memoria` binary only, skip plugin config rewrite
242
+ - `--skip-memoria-install`: require an existing `memoria` executable
243
+ - `--skip-plugin-install`: only rewrite plugin config; assume OpenClaw already installed and the plugin already loaded
244
+ - `--verify`: run a post-install smoke check
245
+
246
+ ## ⚠️ Common Pitfalls
247
+
248
+ **macOS `sh` vs `bash`:** The installer script is bash (`#!/usr/bin/env bash`) and uses bash-specific syntax.
249
+ If you pipe a script, use `bash -s --`, not `sh -s --`.
250
+
251
+ ```bash
252
+ # ✅ Correct
253
+ curl -fsSL <url> | bash -s --
254
+
255
+ # ❌ May fail with "bad substitution"
256
+ curl -fsSL <url> | sh -s --
257
+ ```
258
+
259
+ **Explicit memory mode is default (`autoObserve=false`):** the plugin does not auto-write memories from conversation turns.
260
+ Writes happen when the agent explicitly calls tools like `memory_store` (or related write tools).
261
+ This keeps memory writes intentional and reviewable.
262
+ If you want auto-capture, set `MEMORIA_AUTO_OBSERVE=true` and provide `MEMORIA_LLM_API_KEY` + `MEMORIA_LLM_MODEL`.
263
+
264
+ **Old schema vs new runtime:** If you upgraded from an older Memoria setup, existing DB schema may not match current Rust runtime expectations.
265
+ Use a fresh database name in `MEMORIA_DB_URL` for a clean install path.
266
+
267
+ ```text
268
+ # Old/default style
269
+ mysql://root:111@127.0.0.1:6001/memoria
270
+
271
+ # Clean-start recommendation
272
+ mysql://root:111@127.0.0.1:6001/memoria_v2
273
+ ```
274
+
275
+ ## Tool Surface
276
+
277
+ The OpenClaw plugin exposes:
278
+
279
+ - `memory_search`, `memory_get`, `memory_store`, `memory_retrieve`, `memory_recall`
280
+ - `memory_list`, `memory_stats`, `memory_profile`, `memory_correct`, `memory_purge`, `memory_forget`, `memory_health`
281
+ - `memory_observe`, `memory_governance`, `memory_consolidate`, `memory_reflect`, `memory_extract_entities`, `memory_link_entities`, `memory_rebuild_index`, `memory_capabilities`
282
+ - `memory_snapshot`, `memory_snapshots`, `memory_rollback`
283
+ - `memory_branch`, `memory_branches`, `memory_checkout`, `memory_branch_delete`, `memory_merge`, `memory_diff`
284
+ - compatibility CLI aliases under `openclaw ltm ...`
285
+
286
+ ## Compatibility Notes
287
+
288
+ This plugin now follows the Rust Memoria behavior, not the old embedded Python bridge.
289
+
290
+ Current differences to be aware of:
291
+
292
+ - `memory_get` is resolved from recent tool results plus a bounded scan, because the Rust MCP toolset does not expose a direct get-by-id call
293
+ - `memory_stats` is derived from available MCP outputs, so inactive-memory totals and entity totals are not currently available
294
+ - `memory_entities` is no longer exposed, because the Rust Memoria MCP toolset does not provide a matching tool
295
+ - old `mysql+pymysql://...` DSNs are normalized to `mysql://...` automatically during install and config parsing
296
+ - if you previously used an older Memoria stack, schema drift can cause runtime errors; using a fresh DB name (for example `memoria_v2`) avoids most upgrade collisions
297
+
298
+ ## Uninstall
299
+
300
+ ```bash
301
+ curl -fsSL https://raw.githubusercontent.com/matrixorigin/Memoria/main/plugins/openclaw/scripts/uninstall-openclaw-memoria.sh | \
302
+ bash -s --
303
+ ```
304
+
305
+ That removes the plugin entry, tool policy additions, managed skills, and the default managed checkout path.
306
+
307
+ ## Verification
308
+
309
+ ### Success Criteria
310
+
311
+ | Level | Check | Command | Pass |
312
+ |---|---|---|---|
313
+ | 1. Plugin loaded | OpenClaw recognizes plugin | `openclaw plugins list` | `memory-memoria` is listed and enabled |
314
+ | 2. Backend reachable | Memoria can reach configured backend | `openclaw memoria health` | returns `status: ok` |
315
+ | 3. Memory persisted | Store -> retrieve round-trip works | `openclaw memoria stats` + `openclaw ltm list --limit 10` | non-zero memory appears after a write |
316
+
317
+ Before the smoke check, confirm the CLIs you are about to use are the ones you expect:
318
+
319
+ ```bash
320
+ openclaw --version
321
+ openclaw memoria verify
322
+ ```
323
+
324
+ After install:
325
+
326
+ ```bash
327
+ openclaw memoria capabilities
328
+ openclaw memoria stats
329
+ openclaw ltm list --limit 10
330
+ ```
331
+
332
+ Notes:
333
+
334
+ - `openclaw memoria capabilities` is a config/plugin check and does not require a live Memoria backend
335
+ - `openclaw memoria stats` and `openclaw ltm list` require the configured backend to be reachable; in embedded mode that means MatrixOne must be up and the embedding config must be valid
336
+ - OpenClaw reserves `openclaw memory` for its built-in file memory, so this plugin uses `openclaw memoria` and the compatibility alias `openclaw ltm`
337
+ - `openclaw memoria setup` is the recommended onboarding command for cloud/local setup
338
+ - `openclaw memoria connect` remains available as the lower-level config-only entrypoint (no `--install-memoria` support)
339
+ - `setup/connect` will merge `memory-memoria` into `plugins.allow` to satisfy OpenClaw allow-list policy
340
+ - on fresh install without explicit backend config, `openclaw plugins enable` logs a one-time hint with cloud (recommended), local (optional), and `openclaw memoria setup --help`
341
+ - OpenClaw may print "Restart the gateway" after `plugins install` or `plugins enable` — this is unnecessary for CLI commands like `setup` and `health`, but harmless if you do restart
342
+ - `openclaw memoria install` is optional local bootstrap/repair (runtime + config rewrite)
343
+ - `openclaw memoria verify` is an optional deeper diagnostic; `openclaw memoria health` is the primary quick connectivity check
344
+
345
+ If `openclaw memoria setup` (or `connect`) is missing:
346
+
347
+ ```bash
348
+ openclaw plugins update memory-memoria
349
+ openclaw plugins enable memory-memoria
350
+ openclaw memoria --help
351
+ ```
352
+
353
+ Low-level fallback:
354
+
355
+ ```bash
356
+ node scripts/verify_plugin_install.mjs \
357
+ --openclaw-bin "$(which openclaw)" \
358
+ --memoria-bin "$(which memoria)"
359
+ ```
360
+
361
+ ## Development
362
+
363
+ What changed in this repo:
364
+
365
+ - `openclaw/client.ts` now talks to Rust Memoria over MCP stdio
366
+ - the plugin manifest and config surface now use `memoriaExecutable`
367
+ - the installer/uninstaller are pure shell + Node, with no Python dependency
368
+ - the package no longer publishes the old bundled Python runtime