@mysten-incubation/oc-memwal 0.0.1-dev.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 (60) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +216 -0
  3. package/dist/capture.d.ts +25 -0
  4. package/dist/capture.d.ts.map +1 -0
  5. package/dist/capture.js +80 -0
  6. package/dist/capture.js.map +1 -0
  7. package/dist/cli/index.d.ts +10 -0
  8. package/dist/cli/index.d.ts.map +1 -0
  9. package/dist/cli/index.js +18 -0
  10. package/dist/cli/index.js.map +1 -0
  11. package/dist/cli/search.d.ts +10 -0
  12. package/dist/cli/search.d.ts.map +1 -0
  13. package/dist/cli/search.js +32 -0
  14. package/dist/cli/search.js.map +1 -0
  15. package/dist/cli/stats.d.ts +10 -0
  16. package/dist/cli/stats.d.ts.map +1 -0
  17. package/dist/cli/stats.js +31 -0
  18. package/dist/cli/stats.js.map +1 -0
  19. package/dist/config.d.ts +40 -0
  20. package/dist/config.d.ts.map +1 -0
  21. package/dist/config.js +107 -0
  22. package/dist/config.js.map +1 -0
  23. package/dist/format.d.ts +55 -0
  24. package/dist/format.d.ts.map +1 -0
  25. package/dist/format.js +122 -0
  26. package/dist/format.js.map +1 -0
  27. package/dist/hooks/capture.d.ts +12 -0
  28. package/dist/hooks/capture.d.ts.map +1 -0
  29. package/dist/hooks/capture.js +49 -0
  30. package/dist/hooks/capture.js.map +1 -0
  31. package/dist/hooks/index.d.ts +11 -0
  32. package/dist/hooks/index.d.ts.map +1 -0
  33. package/dist/hooks/index.js +16 -0
  34. package/dist/hooks/index.js.map +1 -0
  35. package/dist/hooks/recall.d.ts +12 -0
  36. package/dist/hooks/recall.d.ts.map +1 -0
  37. package/dist/hooks/recall.js +50 -0
  38. package/dist/hooks/recall.js.map +1 -0
  39. package/dist/index.d.ts +28 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +61 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/tools/index.d.ts +12 -0
  44. package/dist/tools/index.d.ts.map +1 -0
  45. package/dist/tools/index.js +15 -0
  46. package/dist/tools/index.js.map +1 -0
  47. package/dist/tools/search.d.ts +13 -0
  48. package/dist/tools/search.d.ts.map +1 -0
  49. package/dist/tools/search.js +83 -0
  50. package/dist/tools/search.js.map +1 -0
  51. package/dist/tools/store.d.ts +12 -0
  52. package/dist/tools/store.d.ts.map +1 -0
  53. package/dist/tools/store.js +87 -0
  54. package/dist/tools/store.js.map +1 -0
  55. package/dist/types.d.ts +24 -0
  56. package/dist/types.d.ts.map +1 -0
  57. package/dist/types.js +5 -0
  58. package/dist/types.js.map +1 -0
  59. package/openclaw.plugin.json +101 -0
  60. package/package.json +49 -0
package/LICENSE ADDED
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute
108
+ must include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
package/README.md ADDED
@@ -0,0 +1,216 @@
1
+ <h1 align="center">@mysten-incubation/oc-memwal</h1>
2
+
3
+ <p align="center">
4
+ Cloud-based long-term memory plugin for NemoClaw/OpenClaw — gives your AI agents persistent, encrypted, cross-session memory powered by <strong>MemWal</strong>.
5
+ </p>
6
+
7
+ <p align="center">
8
+ <a href="https://docs.memwal.ai/openclaw/overview"><strong>Documentation</strong></a> ·
9
+ <a href="#quick-start"><strong>Quick Start</strong></a> ·
10
+ <a href="#verify"><strong>Verify</strong></a> ·
11
+ <a href="#how-it-works"><strong>How It Works</strong></a>
12
+ </p>
13
+ <br/>
14
+
15
+ ## Overview
16
+
17
+ Replaces OpenClaw's default file-based memory with a **remote memory backend**. After setup, the plugin runs silently — your agent remembers things from past conversations and learns new facts automatically, with no user intervention required.
18
+
19
+ Memories are **encrypted** and stored on **MemWal**, a privacy-preserving memory protocol built on Walrus decentralized storage. Each user owns their memories via an **Ed25519 key** — no platform can access them without it.
20
+
21
+ **Features:**
22
+ - **Auto-recall** — relevant memories injected before each conversation turn
23
+ - **Auto-capture** — facts extracted and stored after each turn
24
+ - **Agent tools** — `memory_search` and `memory_store` for explicit LLM control
25
+ - **Multi-agent isolation** — each agent gets its own memory namespace
26
+ - **Prompt injection protection** — detection and escaping on all read/write paths
27
+ - **CLI** — `openclaw memwal search` and `openclaw memwal stats` for debugging
28
+
29
+ ## Prerequisites
30
+
31
+ ### OpenClaw
32
+
33
+ You need [OpenClaw](https://openclaw.ai) `>=2026.3.11` installed and running, and a package manager ([bun](https://bun.sh), pnpm, or npm).
34
+
35
+ ### MemWal Setup
36
+
37
+ **MemWal** is an open-source, self-hostable memory infrastructure kit for encrypted, decentralized storage. You can run your own relayer or use a managed endpoint.
38
+
39
+ The plugin needs three values:
40
+
41
+ | Value | What it is |
42
+ |-------|-----------|
43
+ | **Delegate Key** | Private key (64-char hex) used to sign requests and encrypt memories |
44
+ | **Account ID** | Your MemWalAccount object ID on Sui (`0x...`) |
45
+ | **Relayer URL** | The MemWal relayer endpoint that handles search, storage, and encryption |
46
+
47
+ Get your delegate key and account ID from the [MemWal dashboard](https://memwal.ai), or see the [Quick Start guide](/getting-started/quick-start) for detailed setup.
48
+
49
+ For the relayer, use a managed endpoint or [self-host your own](/relayer/self-hosting):
50
+
51
+ | Environment | Relayer URL |
52
+ |-------------|-------------|
53
+ | **Production** (mainnet) | `https://relayer.memwal.ai` |
54
+ | **Development** (testnet) | `https://relayer.dev.memwal.ai` |
55
+
56
+ ## Quick Start
57
+
58
+ ### 1. Install
59
+
60
+ ```bash
61
+ openclaw plugins install @mysten-incubation/oc-memwal
62
+ ```
63
+
64
+ ### 2. Set your delegate key
65
+
66
+ Store your delegate key as an environment variable so it's never hardcoded in config files:
67
+
68
+ ```bash
69
+ # Add to your shell profile (.zshrc, .bashrc, etc.)
70
+ export MEMWAL_PRIVATE_KEY="your-64-char-hex-key"
71
+ ```
72
+
73
+ ### 3. Configure OpenClaw
74
+
75
+ Add the plugin config to `~/.openclaw/openclaw.json`:
76
+
77
+ ```jsonc
78
+ {
79
+ "plugins": {
80
+ "slots": { "memory": "oc-memwal" },
81
+ "entries": {
82
+ "oc-memwal": {
83
+ "enabled": true,
84
+ "config": {
85
+ "privateKey": "${MEMWAL_PRIVATE_KEY}", // References the env var
86
+ "accountId": "0x3247e3da...", // Your account ID from the dashboard
87
+ "serverUrl": "https://relayer.dev.memwal.ai" // Or your self-hosted relayer
88
+ }
89
+ }
90
+ }
91
+ }
92
+ }
93
+ ```
94
+
95
+ Optional settings you can add to the `config` block:
96
+
97
+ | Option | Default | Description |
98
+ |--------|---------|-------------|
99
+ | `autoRecall` | `true` | Inject relevant memories before each turn |
100
+ | `autoCapture` | `true` | Extract and store facts after each turn |
101
+ | `maxRecallResults` | `5` | Max memories to inject per turn |
102
+ | `minRelevance` | `0.3` | Relevance threshold (0-1) for memory injection |
103
+ | `captureMaxMessages` | `10` | How many recent messages to analyze for facts |
104
+
105
+ The defaults work well for most setups — you don't need to change them to get started.
106
+
107
+ ### 4. Start OpenClaw
108
+
109
+ ```bash
110
+ openclaw gateway stop && openclaw gateway
111
+ ```
112
+
113
+ You should see in the logs:
114
+
115
+ ```
116
+ memory-memwal: registered (server: https://..., key: e21d...ed9b, namespace: default)
117
+ memory-memwal: connected (status: ok, version: ...)
118
+ ```
119
+
120
+ If you see `health check failed`, double-check that your server URL is reachable and your private key env var is set.
121
+
122
+ ## Verify
123
+
124
+ ### Check connectivity
125
+
126
+ Run the stats command to confirm the plugin is connected and configured correctly:
127
+
128
+ ```bash
129
+ openclaw memwal stats
130
+ ```
131
+
132
+ This shows the server status, your key (masked), account ID, active namespace, and whether auto-recall/capture are enabled.
133
+
134
+ ### Test the memory loop
135
+
136
+ The core value of the plugin is the automatic recall/capture cycle. Test it end-to-end:
137
+
138
+ 1. **Store a fact** — start a conversation and share something memorable:
139
+
140
+ ```
141
+ You: I prefer TypeScript over JavaScript for backend work
142
+ Bot: (responds normally)
143
+ ```
144
+
145
+ Check logs — you should see `memory-memwal: auto-captured 1 facts`. The plugin extracted the preference and stored it.
146
+
147
+ 2. **Recall it** — in a **new conversation**, ask about it:
148
+
149
+ ```
150
+ You: What programming languages do I like?
151
+ ```
152
+
153
+ Check logs — you should see `memory-memwal: auto-recall injected 1 memories`. The plugin found the stored preference and injected it into the LLM's context.
154
+
155
+ 3. **Search from terminal** — confirm the memory exists via CLI:
156
+
157
+ ```bash
158
+ openclaw memwal search "programming"
159
+ ```
160
+
161
+ If all three steps work, the plugin is fully operational.
162
+
163
+ ---
164
+
165
+ ## How it works
166
+
167
+ The plugin sits between OpenClaw's gateway and the MemWal server. It operates through **hooks** — automatic callbacks that run on every conversation turn. The LLM never sees them, doesn't trigger them, and can't prevent them.
168
+
169
+ ```mermaid
170
+ graph TB
171
+ subgraph "OpenClaw Gateway"
172
+ RECALL["Auto-Recall Hook"]
173
+ PROMPT["Prompt Assembly"]
174
+ CAPTURE["Auto-Capture Hook"]
175
+ end
176
+
177
+ subgraph "LLM"
178
+ LLM_PROC["Language Model"]
179
+ end
180
+
181
+ subgraph "MemWal Server"
182
+ SEARCH["Vector Search"]
183
+ ANALYZE["Fact Extraction"]
184
+ STORE["Encrypted Storage"]
185
+ end
186
+
187
+ WALRUS["Walrus Network"]
188
+
189
+ USER([User Message]) --> RECALL
190
+ RECALL -->|"search memories"| SEARCH
191
+ SEARCH --> RECALL
192
+ RECALL -->|"inject into prompt"| PROMPT
193
+ PROMPT --> LLM_PROC
194
+ LLM_PROC --> RESPONSE([Response to User])
195
+ RESPONSE --> CAPTURE
196
+ CAPTURE -->|"extract facts"| ANALYZE
197
+ ANALYZE --> STORE
198
+ STORE --> WALRUS
199
+
200
+ style RECALL fill:#4a9eff,color:#fff
201
+ style CAPTURE fill:#4a9eff,color:#fff
202
+ style LLM_PROC fill:#ff9f4a,color:#fff
203
+ style STORE fill:#6b7280,color:#fff
204
+ ```
205
+
206
+ Every conversation turn goes through two phases:
207
+
208
+ - **Auto-recall** — before the LLM sees the user's message, the plugin searches MemWal for relevant memories and injects them into the prompt as context. The LLM sees these as background knowledge — it doesn't know they were injected.
209
+
210
+ - **Auto-capture** — after the LLM responds, the plugin extracts the conversation, filters out trivial content (filler responses, emoji, etc.), and sends it to the MemWal server. The server-side LLM extracts individual facts and stores them as encrypted blobs on Walrus.
211
+
212
+ The plugin also registers two optional **tools** (`memory_search` and `memory_store`) that give the LLM explicit control over memory operations. These require `tools.allow` in the agent profile and are a power-user feature — hooks handle the common case automatically.
213
+
214
+ ## License
215
+
216
+ Apache-2.0
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Capture filtering — determines whether a conversation turn
3
+ * is worth sending to analyze() for fact extraction.
4
+ *
5
+ * Prevents wasted server calls on trivial turns like "ok", "thanks", emoji.
6
+ * Based on patterns from LanceDB's shouldCapture() implementation.
7
+ */
8
+ /**
9
+ * Check if text looks like a prompt injection attempt.
10
+ * Used by both capture (reject on store) and recall (reject on inject).
11
+ */
12
+ export declare function looksLikeInjection(text: string): boolean;
13
+ /**
14
+ * Determine whether a conversation text is worth capturing.
15
+ *
16
+ * Applies a multi-step filter chain: rejects short text, filler responses,
17
+ * XML/system content, emoji-heavy messages, and injection attempts.
18
+ * Accepts immediately if a trigger pattern matches (e.g. "remember", "prefer").
19
+ * Falls through to accept if text is long enough for the server LLM to evaluate.
20
+ *
21
+ * @param text - Raw message text (user or assistant)
22
+ * @returns `true` if the text likely contains memorable facts
23
+ */
24
+ export declare function shouldCapture(text: string): boolean;
25
+ //# sourceMappingURL=capture.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capture.d.ts","sourceRoot":"","sources":["../src/capture.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAoCH;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAIxD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAsBnD"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Capture filtering — determines whether a conversation turn
3
+ * is worth sending to analyze() for fact extraction.
4
+ *
5
+ * Prevents wasted server calls on trivial turns like "ok", "thanks", emoji.
6
+ * Based on patterns from LanceDB's shouldCapture() implementation.
7
+ */
8
+ // ============================================================================
9
+ // Constants
10
+ // ============================================================================
11
+ const MIN_CAPTURE_LENGTH = 30;
12
+ const MAX_EMOJI_COUNT = 3;
13
+ /** Filler patterns — exact-match trivial responses. */
14
+ const FILLER_PATTERN = /^(ok|okay|sure|thanks|thank you|thx|yes|yep|yeah|no|nope|nah|got it|hmm|hm|ah|oh|lol|haha|nice|cool|great|right|alright|fine|k|kk)\s*[.!?]*$/i;
15
+ /** Prompt injection patterns — never capture these. */
16
+ const INJECTION_PATTERNS = [
17
+ /ignore (all|any|previous|above|prior) instructions/i,
18
+ /do not follow (the )?(system|developer)/i,
19
+ /system prompt/i,
20
+ /<\s*(system|assistant|developer|tool|function)\b/i,
21
+ /\b(run|execute|call|invoke)\b.{0,40}\b(tool|command)\b/i,
22
+ ];
23
+ /** Memory trigger patterns — always capture if matched (whitelist boost). */
24
+ const TRIGGER_PATTERNS = [
25
+ /remember|prefer|radši|zapamatuj/i,
26
+ /i (like|prefer|hate|love|want|need|use|am|work)/i,
27
+ /my\s+\w+\s+is|is\s+my/i,
28
+ /always|never|important/i,
29
+ /decided|will use|switched to/i,
30
+ /\+\d{10,}/, // phone numbers
31
+ /[\w.-]+@[\w.-]+\.\w+/, // email addresses
32
+ ];
33
+ // ============================================================================
34
+ // Functions
35
+ // ============================================================================
36
+ /**
37
+ * Check if text looks like a prompt injection attempt.
38
+ * Used by both capture (reject on store) and recall (reject on inject).
39
+ */
40
+ export function looksLikeInjection(text) {
41
+ const normalized = text.replace(/\s+/g, " ").trim();
42
+ if (!normalized)
43
+ return false;
44
+ return INJECTION_PATTERNS.some((p) => p.test(normalized));
45
+ }
46
+ /**
47
+ * Determine whether a conversation text is worth capturing.
48
+ *
49
+ * Applies a multi-step filter chain: rejects short text, filler responses,
50
+ * XML/system content, emoji-heavy messages, and injection attempts.
51
+ * Accepts immediately if a trigger pattern matches (e.g. "remember", "prefer").
52
+ * Falls through to accept if text is long enough for the server LLM to evaluate.
53
+ *
54
+ * @param text - Raw message text (user or assistant)
55
+ * @returns `true` if the text likely contains memorable facts
56
+ */
57
+ export function shouldCapture(text) {
58
+ // Too short to contain useful facts
59
+ if (text.length < MIN_CAPTURE_LENGTH)
60
+ return false;
61
+ // Pure filler response
62
+ if (FILLER_PATTERN.test(text.trim()))
63
+ return false;
64
+ // System/XML content (likely injected context, not user speech)
65
+ if (text.trim().startsWith("<") && text.includes("</"))
66
+ return false;
67
+ // Emoji-heavy (likely reactions, not factual content)
68
+ const emojiCount = (text.match(/[\u{1F300}-\u{1F9FF}]/gu) || []).length;
69
+ if (emojiCount > MAX_EMOJI_COUNT)
70
+ return false;
71
+ // Prompt injection attempt — never store
72
+ if (INJECTION_PATTERNS.some((p) => p.test(text)))
73
+ return false;
74
+ // If it matches a trigger pattern, definitely capture
75
+ if (TRIGGER_PATTERNS.some((p) => p.test(text)))
76
+ return true;
77
+ // Default: capture if it's long enough (the server LLM will decide what's worth keeping)
78
+ return true;
79
+ }
80
+ //# sourceMappingURL=capture.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capture.js","sourceRoot":"","sources":["../src/capture.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,+EAA+E;AAC/E,YAAY;AACZ,+EAA+E;AAE/E,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,MAAM,eAAe,GAAG,CAAC,CAAC;AAE1B,uDAAuD;AACvD,MAAM,cAAc,GAAG,+IAA+I,CAAC;AAEvK,uDAAuD;AACvD,MAAM,kBAAkB,GAAG;IACzB,qDAAqD;IACrD,0CAA0C;IAC1C,gBAAgB;IAChB,mDAAmD;IACnD,yDAAyD;CAC1D,CAAC;AAEF,6EAA6E;AAC7E,MAAM,gBAAgB,GAAG;IACvB,kCAAkC;IAClC,kDAAkD;IAClD,wBAAwB;IACxB,yBAAyB;IACzB,+BAA+B;IAC/B,WAAW,EAAwB,gBAAgB;IACnD,sBAAsB,EAAa,kBAAkB;CACtD,CAAC;AAEF,+EAA+E;AAC/E,YAAY;AACZ,+EAA+E;AAE/E;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IACpD,IAAI,CAAC,UAAU;QAAE,OAAO,KAAK,CAAC;IAC9B,OAAO,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,oCAAoC;IACpC,IAAI,IAAI,CAAC,MAAM,GAAG,kBAAkB;QAAE,OAAO,KAAK,CAAC;IAEnD,uBAAuB;IACvB,IAAI,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QAAE,OAAO,KAAK,CAAC;IAEnD,gEAAgE;IAChE,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IAErE,sDAAsD;IACtD,MAAM,UAAU,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,yBAAyB,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;IACxE,IAAI,UAAU,GAAG,eAAe;QAAE,OAAO,KAAK,CAAC;IAE/C,yCAAyC;IACzC,IAAI,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IAE/D,sDAAsD;IACtD,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IAE5D,yFAAyF;IACzF,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * CLI commands — openclaw memwal <command>
3
+ *
4
+ * Agent scoping via --agent flag → namespace.
5
+ */
6
+ import type { MemWal } from "@mysten-incubation/memwal";
7
+ import type { PluginConfig } from "../types.js";
8
+ /** Register `openclaw memwal` CLI commands. */
9
+ export declare function registerCli(api: any, client: MemWal, config: PluginConfig): void;
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAGxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,+CAA+C;AAC/C,wBAAgB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CAYhF"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * CLI commands — openclaw memwal <command>
3
+ *
4
+ * Agent scoping via --agent flag → namespace.
5
+ */
6
+ import { registerSearchCommand } from "./search.js";
7
+ import { registerStatsCommand } from "./stats.js";
8
+ /** Register `openclaw memwal` CLI commands. */
9
+ export function registerCli(api, client, config) {
10
+ api.registerCli(({ program }) => {
11
+ const cmd = program
12
+ .command("memwal")
13
+ .description("MemWal memory plugin commands");
14
+ registerSearchCommand(cmd, client, config);
15
+ registerStatsCommand(cmd, client, config);
16
+ }, { commands: ["memwal"] });
17
+ }
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAGlD,+CAA+C;AAC/C,MAAM,UAAU,WAAW,CAAC,GAAQ,EAAE,MAAc,EAAE,MAAoB;IACxE,GAAG,CAAC,WAAW,CACb,CAAC,EAAE,OAAO,EAAO,EAAE,EAAE;QACnB,MAAM,GAAG,GAAG,OAAO;aAChB,OAAO,CAAC,QAAQ,CAAC;aACjB,WAAW,CAAC,+BAA+B,CAAC,CAAC;QAEhD,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QAC3C,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5C,CAAC,EACD,EAAE,QAAQ,EAAE,CAAC,QAAQ,CAAC,EAAE,CACzB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * CLI command — openclaw memwal search <query>
3
+ *
4
+ * Semantic search with JSON output, scoped by --agent flag.
5
+ */
6
+ import type { MemWal } from "@mysten-incubation/memwal";
7
+ import type { PluginConfig } from "../types.js";
8
+ /** Register the `openclaw memwal search` command. */
9
+ export declare function registerSearchCommand(cmd: any, client: MemWal, config: PluginConfig): void;
10
+ //# sourceMappingURL=search.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/cli/search.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAExD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,qDAAqD;AACrD,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CAuB1F"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * CLI command — openclaw memwal search <query>
3
+ *
4
+ * Semantic search with JSON output, scoped by --agent flag.
5
+ */
6
+ import { resolveAgent } from "../config.js";
7
+ /** Register the `openclaw memwal search` command. */
8
+ export function registerSearchCommand(cmd, client, config) {
9
+ cmd
10
+ .command("search")
11
+ .description("Search memories")
12
+ .argument("<query>", "Search query")
13
+ .option("--limit <n>", "Max results", "5")
14
+ .option("--agent <name>", "Search a specific agent's memory (namespace)")
15
+ .action(async (query, opts) => {
16
+ const { namespace } = resolveAgent(config.defaultNamespace, opts.agent ? `agent:${opts.agent}:cli` : undefined);
17
+ const limit = parseInt(opts.limit, 10);
18
+ try {
19
+ const result = await client.recall(query, limit, namespace);
20
+ const output = result.results.map((r) => ({
21
+ text: r.text,
22
+ blob_id: r.blob_id,
23
+ relevance: Math.round((1 - r.distance) * 100) / 100,
24
+ }));
25
+ console.log(JSON.stringify(output, null, 2));
26
+ }
27
+ catch (err) {
28
+ console.error(`Search failed: ${String(err)}`);
29
+ }
30
+ });
31
+ }
32
+ //# sourceMappingURL=search.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search.js","sourceRoot":"","sources":["../../src/cli/search.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C,qDAAqD;AACrD,MAAM,UAAU,qBAAqB,CAAC,GAAQ,EAAE,MAAc,EAAE,MAAoB;IAClF,GAAG;SACA,OAAO,CAAC,QAAQ,CAAC;SACjB,WAAW,CAAC,iBAAiB,CAAC;SAC9B,QAAQ,CAAC,SAAS,EAAE,cAAc,CAAC;SACnC,MAAM,CAAC,aAAa,EAAE,aAAa,EAAE,GAAG,CAAC;SACzC,MAAM,CAAC,gBAAgB,EAAE,8CAA8C,CAAC;SACxE,MAAM,CAAC,KAAK,EAAE,KAAa,EAAE,IAAS,EAAE,EAAE;QACzC,MAAM,EAAE,SAAS,EAAE,GAAG,YAAY,CAAC,MAAM,CAAC,gBAAgB,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,IAAI,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAChH,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAEvC,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;YAC5D,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC;gBAC7C,IAAI,EAAE,CAAC,CAAC,IAAI;gBACZ,OAAO,EAAE,CAAC,CAAC,OAAO;gBAClB,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG;aACpD,CAAC,CAAC,CAAC;YACJ,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QAC/C,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,kBAAkB,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACjD,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * CLI command — openclaw memwal stats
3
+ *
4
+ * Shows server health, config summary, and active namespace.
5
+ */
6
+ import type { MemWal } from "@mysten-incubation/memwal";
7
+ import type { PluginConfig } from "../types.js";
8
+ /** Register the `openclaw memwal stats` command. */
9
+ export declare function registerStatsCommand(cmd: any, client: MemWal, config: PluginConfig): void;
10
+ //# sourceMappingURL=stats.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../../src/cli/stats.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAExD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,oDAAoD;AACpD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CAuBzF"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * CLI command — openclaw memwal stats
3
+ *
4
+ * Shows server health, config summary, and active namespace.
5
+ */
6
+ import { resolveAgent, keyPreview } from "../config.js";
7
+ /** Register the `openclaw memwal stats` command. */
8
+ export function registerStatsCommand(cmd, client, config) {
9
+ cmd
10
+ .command("stats")
11
+ .description("Show memory status")
12
+ .option("--agent <name>", "Show stats for a specific agent (namespace)")
13
+ .action(async (opts) => {
14
+ const { namespace } = resolveAgent(config.defaultNamespace, opts.agent ? `agent:${opts.agent}:cli` : undefined);
15
+ try {
16
+ const health = await client.health();
17
+ console.log(`Server: ${config.serverUrl}`);
18
+ console.log(`Status: ${health.status}`);
19
+ console.log(`Version: ${health.version}`);
20
+ console.log(`Key: ${keyPreview(config.privateKey)}`);
21
+ console.log(`Account: ${config.accountId.slice(0, 10)}...`);
22
+ console.log(`Namespace: ${namespace}`);
23
+ console.log(`Auto-recall: ${config.autoRecall}`);
24
+ console.log(`Auto-capture: ${config.autoCapture}`);
25
+ }
26
+ catch (err) {
27
+ console.error(`Stats failed: ${String(err)}`);
28
+ }
29
+ });
30
+ }
31
+ //# sourceMappingURL=stats.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stats.js","sourceRoot":"","sources":["../../src/cli/stats.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAGxD,oDAAoD;AACpD,MAAM,UAAU,oBAAoB,CAAC,GAAQ,EAAE,MAAc,EAAE,MAAoB;IACjF,GAAG;SACA,OAAO,CAAC,OAAO,CAAC;SAChB,WAAW,CAAC,oBAAoB,CAAC;SACjC,MAAM,CAAC,gBAAgB,EAAE,6CAA6C,CAAC;SACvE,MAAM,CAAC,KAAK,EAAE,IAAS,EAAE,EAAE;QAC1B,MAAM,EAAE,SAAS,EAAE,GAAG,YAAY,CAAC,MAAM,CAAC,gBAAgB,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,IAAI,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAEhH,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC;YAErC,OAAO,CAAC,GAAG,CAAC,eAAe,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;YAC/C,OAAO,CAAC,GAAG,CAAC,eAAe,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;YAC5C,OAAO,CAAC,GAAG,CAAC,eAAe,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;YAC7C,OAAO,CAAC,GAAG,CAAC,eAAe,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;YAC5D,OAAO,CAAC,GAAG,CAAC,eAAe,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;YAC/D,OAAO,CAAC,GAAG,CAAC,eAAe,SAAS,EAAE,CAAC,CAAC;YACxC,OAAO,CAAC,GAAG,CAAC,iBAAiB,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;YAClD,OAAO,CAAC,GAAG,CAAC,iBAAiB,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;QACrD,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,iBAAiB,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAChD,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}