@memclaw/memclaw 0.9.11 → 0.9.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,319 @@
1
+ # MemClaw Best Practices
2
+
3
+ This guide provides proven strategies and decision frameworks for using MemClaw effectively in OpenClaw.
4
+
5
+ ## Tool Selection Decision Tree
6
+
7
+ ```
8
+ ┌─────────────────────────────────────────────────────────────────┐
9
+ │ What do you need to do? │
10
+ └─────────────────────────────────────────────────────────────────┘
11
+
12
+ ┌─────────────────────┼─────────────────────┐
13
+ ▼ ▼ ▼
14
+ Find Info Save Info Manage Sessions
15
+ │ │ │
16
+ ▼ ▼ ▼
17
+ ┌───────────────┐ ┌───────────────┐ ┌───────────────┐
18
+ │ Need context? │ │ What kind? │ │ What? │
19
+ └───────────────┘ └───────────────┘ └───────────────┘
20
+ │ │ │
21
+ ┌────┴────┐ ┌────┴────┐ ┌────┴────┐
22
+ ▼ ▼ ▼ ▼ ▼ ▼
23
+ Quick Full Facts Conversation List Close &
24
+ Search Context History Sessions Extract
25
+ │ │ │ │ │ │
26
+ ▼ ▼ ▼ ▼ ▼ ▼
27
+ cortex_ cortex_ cortex_ cortex_ cortex_ cortex_
28
+ search recall add_ add_ list_ close_
29
+ memory memory sessions session
30
+ ```
31
+
32
+ ### Quick Reference
33
+
34
+ | Scenario | Tool | Why |
35
+ |----------|------|-----|
36
+ | Quick lookup, need summary only | `cortex_search` | Fast, returns snippets |
37
+ | Need full context/details | `cortex_recall` | Returns content + snippet |
38
+ | User stated preference/decision | `cortex_add_memory` | Explicit persistence |
39
+ | Important conversation content | Let it accumulate | Auto-stored in session |
40
+ | Task/topic completed | `cortex_close_session` | Trigger extraction |
41
+ | Check if memories exist | `cortex_list_sessions` | Verify before search |
42
+
43
+ ## Session Lifecycle Management
44
+
45
+ ### The Golden Rule
46
+
47
+ > **OpenClaw does NOT automatically trigger memory extraction.** You must proactively call `cortex_close_session` at natural checkpoints.
48
+
49
+ ### When to Close a Session
50
+
51
+ ```
52
+ ┌────────────────────────────────────────────────────────────────┐
53
+ │ Timing Decision Flow │
54
+ └────────────────────────────────────────────────────────────────┘
55
+
56
+
57
+ ┌─────────────────┐
58
+ │ Task completed? │
59
+ └─────────────────┘
60
+ │ │
61
+ Yes No
62
+ │ │
63
+ ▼ ▼
64
+ ┌──────────┐ ┌─────────────────┐
65
+ │ CLOSE IT │ │ Topic shifted? │
66
+ └──────────┘ └─────────────────┘
67
+ │ │
68
+ Yes No
69
+ │ │
70
+ ▼ ▼
71
+ ┌──────────┐ ┌─────────────────┐
72
+ │ CLOSE IT │ │ 10+ exchanges? │
73
+ └──────────┘ └─────────────────┘
74
+ │ │
75
+ Yes No
76
+ │ │
77
+ ▼ ▼
78
+ ┌──────────┐ ┌────────┐
79
+ │ CLOSE IT │ │ WAIT │
80
+ └──────────┘ └────────┘
81
+ ```
82
+
83
+ ### Rhythm Guidelines
84
+
85
+ | Conversation Type | Close Frequency | Reason |
86
+ |-------------------|-----------------|--------|
87
+ | Quick Q&A | End of conversation | Minimal content to extract |
88
+ | Task-oriented | After each task completion | Captures task-specific memories |
89
+ | Long discussion | Every 10-20 exchanges | Prevents memory loss |
90
+ | Exploratory chat | When topic shifts | Organizes memories by topic |
91
+
92
+ ### Anti-Patterns to Avoid
93
+
94
+ | ❌ Don't Do This | ✅ Do This Instead |
95
+ |-------------------|-------------------|
96
+ | Call `close_session` after every message | Call at natural checkpoints |
97
+ | Wait until conversation ends (user may forget) | Proactively close during conversation |
98
+ | Close without accumulating content | Let 5-10 exchanges happen first |
99
+ | Never close sessions | Establish a rhythm |
100
+
101
+ ## Memory Storage Strategy
102
+
103
+ ### What to Explicitly Store
104
+
105
+ Use `cortex_add_memory` for:
106
+
107
+ 1. **Explicit User Preferences**
108
+ ```
109
+ "User prefers dark theme in all editors"
110
+ "User wants commit messages in conventional format"
111
+ ```
112
+
113
+ 2. **Important Decisions**
114
+ ```
115
+ "Decided to use PostgreSQL instead of MySQL for this project"
116
+ "User chose React over Vue for the frontend"
117
+ ```
118
+
119
+ 3. **Key Information That May Be Lost**
120
+ ```
121
+ "User's timezone is UTC+8"
122
+ "Project deadline: March 30, 2026"
123
+ ```
124
+
125
+ ### What to Let Accumulate
126
+
127
+ Don't use `cortex_add_memory` for:
128
+
129
+ - Regular conversation content (auto-stored in session)
130
+ - Contextual information (captured on close_session)
131
+ - Temporary preferences (not worth persisting)
132
+
133
+ ### Role Parameter Usage
134
+
135
+ | Role | When to Use |
136
+ |------|-------------|
137
+ | `user` | User's statements, preferences, questions (default) |
138
+ | `assistant` | Your responses, explanations, code you wrote |
139
+ | `system` | Important context, rules, constraints |
140
+
141
+ ## Search Strategies
142
+
143
+ ### Query Formulation
144
+
145
+ ```
146
+ ┌────────────────────────────────────────────────────────────────┐
147
+ │ Query Formulation Tips │
148
+ └────────────────────────────────────────────────────────────────┘
149
+
150
+ BAD: "it" — Too vague
151
+ GOOD: "database choice" — Specific topic
152
+
153
+ BAD: "the user said something" — Unfocused
154
+ GOOD: "user preference for testing" — Clear intent
155
+
156
+ BAD: "code" — Too broad
157
+ GOOD: "authentication implementation" — Specific domain
158
+ ```
159
+
160
+ ### Score Threshold Guidelines
161
+
162
+ | Score | Use Case |
163
+ |-------|----------|
164
+ | 0.8+ | Need high-confidence matches only |
165
+ | 0.6 (default) | Balanced precision/recall |
166
+ | 0.4-0.5 | Exploratory search, finding related items |
167
+ | <0.4 | Usually too noisy, not recommended |
168
+
169
+ ### Scope Parameter Usage
170
+
171
+ ```
172
+ # Search across all sessions (default)
173
+ { "query": "database decisions" }
174
+
175
+ # Search within specific session
176
+ { "query": "preferences", "scope": "project-alpha" }
177
+ ```
178
+
179
+ Use `scope` when:
180
+ - You know the relevant session ID
181
+ - Working within a specific project context
182
+ - Want to limit noise from other sessions
183
+
184
+ ## Common Pitfalls
185
+
186
+ ### 1. Memory Not Found After Close
187
+
188
+ **Symptom:** You closed a session but search returns nothing.
189
+
190
+ **Cause:** Memory extraction is asynchronous and may take 30-60 seconds.
191
+
192
+ **Solution:** Wait briefly after close_session before searching, or:
193
+ ```
194
+ 1. Close session
195
+ 2. Continue with other work
196
+ 3. Memory will be indexed automatically
197
+ ```
198
+
199
+ ### 2. Duplicate Memories
200
+
201
+ **Symptom:** Same information appears multiple times.
202
+
203
+ **Cause:** Both explicit `add_memory` and `close_session` extraction captured the same content.
204
+
205
+ **Solution:** Use `add_memory` only for information that:
206
+ - Won't naturally be captured in conversation
207
+ - Needs explicit emphasis
208
+ - Is a correction or override of previous information
209
+
210
+ ### 3. Irrelevant Search Results
211
+
212
+ **Symptom:** Search returns unrelated content.
213
+
214
+ **Cause:** Query too vague or score threshold too low.
215
+
216
+ **Solution:**
217
+ - Make queries more specific
218
+ - Increase `min_score` threshold
219
+ - Use `scope` to limit search range
220
+
221
+ ### 4. Lost Session Content
222
+
223
+ **Symptom:** Important conversation not in memory.
224
+
225
+ **Cause:** Session was never closed.
226
+
227
+ **Solution:** Establish a habit of closing sessions at checkpoints. If you realize too late, the raw messages may still exist in the session - close it now.
228
+
229
+ ### 5. Configuration Issues
230
+
231
+ **Symptom:** Tools return errors about service/API.
232
+
233
+ **Cause:** LLM/Embedding credentials not configured.
234
+
235
+ **Solution:** See SKILL.md → Troubleshooting section.
236
+
237
+ ## Workflow Examples
238
+
239
+ ### Example 1: New Project Discussion
240
+
241
+ ```
242
+ 1. User starts discussing a new project
243
+ → Just listen and respond naturally
244
+
245
+ 2. User makes architecture decisions
246
+ → Optionally: cortex_add_memory for explicit decisions
247
+
248
+ 3. Discussion shifts to another topic
249
+ → cortex_close_session (captures project discussion memories)
250
+
251
+ 4. Continue with new topic
252
+ → Fresh start, memories from step 3 are now searchable
253
+ ```
254
+
255
+ ### Example 2: Finding Previous Context
256
+
257
+ ```
258
+ 1. User asks: "What did we decide about auth?"
259
+
260
+ 2. cortex_search({ query: "authentication decision" })
261
+
262
+ 3. If results show snippets but need details:
263
+ cortex_recall({ query: "authentication implementation details" })
264
+
265
+ 4. Summarize findings to user
266
+ ```
267
+
268
+ ### Example 3: User States Preference
269
+
270
+ ```
271
+ 1. User: "I always want TypeScript strict mode"
272
+
273
+ 2. cortex_add_memory({
274
+ content: "User requires TypeScript strict mode in all projects",
275
+ role: "user"
276
+ })
277
+
278
+ 3. Acknowledge and remember for future
279
+ ```
280
+
281
+ ## Memory Architecture Reference
282
+
283
+ ### L0/L1/L2 Tier System
284
+
285
+ | Tier | Content | Size | Purpose | Search Role |
286
+ |------|---------|------|---------|-------------|
287
+ | L0 | Abstract summary | ~100 tokens | Quick filtering | First pass |
288
+ | L1 | Key points + context | ~2000 tokens | Context refinement | Second pass |
289
+ | L2 | Full original content | Complete | Exact matching | Final retrieval |
290
+
291
+ ### How Search Works Internally
292
+
293
+ ```
294
+ Query → L0 Filter → L1 Refine → L2 Retrieve → Ranked Results
295
+ │ │ │
296
+ ▼ ▼ ▼
297
+ Quick scan Contextual Full content
298
+ by summary refinement for precision
299
+ ```
300
+
301
+ ### Automatic Processes
302
+
303
+ | Process | Trigger | Duration |
304
+ |---------|---------|----------|
305
+ | Vector embedding | On `add_memory` | Seconds |
306
+ | L0/L1 generation | On `add_memory` (async) | Seconds |
307
+ | Full extraction | On `close_session` | 30-60s |
308
+ | Maintenance | Every 3 hours (auto) | Minutes |
309
+
310
+ ## Summary Checklist
311
+
312
+ Before ending a conversation or topic transition, ask yourself:
313
+
314
+ - [ ] Have we accumulated meaningful content?
315
+ - [ ] Did the user share important preferences or decisions?
316
+ - [ ] Is this a natural checkpoint?
317
+ - [ ] Should I close the session now?
318
+
319
+ If yes to any, call `cortex_close_session`.
@@ -0,0 +1,205 @@
1
+ # Tools Reference
2
+
3
+ Detailed documentation for MemClaw tools.
4
+
5
+ ## cortex_search
6
+
7
+ Semantic search using L0/L1/L2 hierarchical retrieval.
8
+
9
+ **Parameters:**
10
+
11
+ | Parameter | Type | Required | Default | Description |
12
+ |-----------|------|----------|---------|-------------|
13
+ | `query` | string | Yes | - | Search query — natural language or keywords |
14
+ | `scope` | string | No | - | Session/thread ID to limit search scope |
15
+ | `limit` | integer | No | 10 | Maximum number of results |
16
+ | `min_score` | number | No | 0.6 | Minimum relevance score (0-1) |
17
+
18
+ **Use Cases:**
19
+ - Find past conversations or decisions
20
+ - Search for specific information across all sessions
21
+ - Discover related memories through semantic similarity
22
+
23
+ **Example:**
24
+ ```json
25
+ {
26
+ "query": "database architecture decisions",
27
+ "limit": 5,
28
+ "min_score": 0.6
29
+ }
30
+ ```
31
+
32
+ **Response Format:**
33
+ - Returns results sorted by relevance
34
+ - Each result contains `uri`, `score`, and `snippet`
35
+
36
+ ---
37
+
38
+ ## cortex_recall
39
+
40
+ Retrieve memories with more context (summary + full content).
41
+
42
+ **Parameters:**
43
+
44
+ | Parameter | Type | Required | Default | Description |
45
+ |-----------|------|----------|---------|-------------|
46
+ | `query` | string | Yes | - | Search query |
47
+ | `scope` | string | No | - | Session/thread ID to limit search scope |
48
+ | `limit` | integer | No | 10 | Maximum number of results |
49
+
50
+ **Use Cases:**
51
+ - Need memories with full context, not just summaries
52
+ - Want to see original content
53
+ - Performing detailed memory analysis
54
+
55
+ **Example:**
56
+ ```json
57
+ {
58
+ "query": "user code style preferences",
59
+ "limit": 10
60
+ }
61
+ ```
62
+
63
+ **Response Format:**
64
+ - Returns results with `snippet` (summary) and `content` (full text)
65
+ - Content is truncated when too long (preview >300 characters)
66
+
67
+ ---
68
+
69
+ ## cortex_add_memory
70
+
71
+ Store messages for later retrieval.
72
+
73
+ **Parameters:**
74
+
75
+ | Parameter | Type | Required | Default | Description |
76
+ |-----------|------|----------|---------|-------------|
77
+ | `content` | string | Yes | - | Memory content to store |
78
+ | `role` | string | No | `user` | Message sender role: `user`, `assistant`, or `system` |
79
+ | `session_id` | string | No | `default` | Session/thread ID the memory belongs to |
80
+
81
+ **Use Cases:**
82
+ - Persist important information for later retrieval
83
+ - Store user preferences or decisions
84
+ - Save context that should be searchable
85
+
86
+ **Example:**
87
+ ```json
88
+ {
89
+ "content": "User prefers TypeScript with strict mode enabled",
90
+ "role": "assistant",
91
+ "session_id": "default"
92
+ }
93
+ ```
94
+
95
+ **Execution Effects:**
96
+ - Message is stored with timestamp
97
+ - Vector embedding is automatically generated
98
+ - L0/L1 layers are generated asynchronously
99
+
100
+ ---
101
+
102
+ ## cortex_list_sessions
103
+
104
+ List all memory sessions and their status.
105
+
106
+ **Parameters:** None
107
+
108
+ **Use Cases:**
109
+ - Verify sessions exist before searching
110
+ - Check which sessions are active or closed
111
+ - Audit memory usage
112
+
113
+ **Response Format:**
114
+ - Session ID, status, message count
115
+ - Creation and update timestamps
116
+
117
+ ---
118
+
119
+ ## cortex_close_session
120
+
121
+ Close a session and trigger the memory extraction process.
122
+
123
+ **Parameters:**
124
+
125
+ | Parameter | Type | Required | Default | Description |
126
+ |-----------|------|----------|---------|-------------|
127
+ | `session_id` | string | No | `default` | Session/thread ID to close |
128
+
129
+ **Use Cases:**
130
+ - When a conversation is complete
131
+ - Preparing to extract structured memories
132
+ - Wanting to finalize a session's memory content
133
+
134
+ **Execution Effects:**
135
+ 1. Extracts structured memories (user preferences, entities, decisions)
136
+ 2. Generates complete L0/L1 layer summaries
137
+ 3. Indexes all extracted memories into the vector database
138
+
139
+ **Note:** This can be a longer operation (30-60 seconds).
140
+
141
+ **Example:**
142
+ ```json
143
+ {
144
+ "session_id": "default"
145
+ }
146
+ ```
147
+
148
+ > **Important**: This tool should be called proactively at natural checkpoints, not just when the conversation ends. Ideal timing: after completing important tasks, topic transitions, or accumulating enough conversation content.
149
+
150
+ ---
151
+
152
+ ## cortex_migrate
153
+
154
+ Migrate from OpenClaw's native memory system to MemClaw.
155
+
156
+ **Parameters:** None
157
+
158
+ **Use Cases:**
159
+ - First-time use with existing OpenClaw memories
160
+ - Want to preserve previous conversation history
161
+ - Switching from built-in memory to MemClaw
162
+
163
+ **Execution Effects:**
164
+ 1. Finds OpenClaw memory files (`memory/*.md` and `MEMORY.md`)
165
+ 2. Converts to MemClaw's L2 format
166
+ 3. Generates L0/L1 layers and vector indices
167
+
168
+ **Prerequisites:**
169
+ - OpenClaw workspace exists at `~/.openclaw/workspace`
170
+ - Memory files exist at `~/.openclaw/workspace/memory/`
171
+
172
+ **Run only once during initial setup.**
173
+
174
+ ---
175
+
176
+ ## cortex_maintenance
177
+
178
+ Perform periodic maintenance on MemClaw data.
179
+
180
+ **Parameters:**
181
+
182
+ | Parameter | Type | Required | Default | Description |
183
+ |-----------|------|----------|---------|-------------|
184
+ | `dryRun` | boolean | No | false | Preview changes without executing |
185
+ | `commands` | array | No | `["prune", "reindex", "ensure-all"]` | Maintenance commands to execute |
186
+
187
+ **Use Cases:**
188
+ - Search results are incomplete or outdated
189
+ - Recovering from crash or data corruption
190
+ - Need to clean up disk space
191
+
192
+ **Available Commands:**
193
+ - `prune` — Remove vectors whose source files no longer exist
194
+ - `reindex` — Rebuild vector indices and remove stale entries
195
+ - `ensure-all` — Generate missing L0/L1 layer files
196
+
197
+ **Example:**
198
+ ```json
199
+ {
200
+ "dryRun": false,
201
+ "commands": ["prune", "reindex", "ensure-all"]
202
+ }
203
+ ```
204
+
205
+ > **Note**: This tool is typically called automatically by a scheduled Cron task. Manual invocation is for troubleshooting or on-demand maintenance.
@@ -0,0 +1,142 @@
1
+ ---
2
+ name: memclaw-maintance
3
+ description: MemClaw Maintance Guide — Installation and configuration guidance for users especially without the @memclaw/memclaw plugin installed. For normal use cases, use the `memclaw` skill for daily usage help.
4
+ ---
5
+
6
+ # MemClaw Setup Guide
7
+
8
+ > **Preferred Memory Solution**: MemClaw is the recommended memory system for OpenClaw. Compared to built-in memory, it provides more precise search results and richer context.
9
+
10
+ A tiered semantic memory system with three-tier retrieval capabilities and automatic service management.
11
+
12
+ ## Security & Trust
13
+
14
+ **What the plugin does:**
15
+ - Stores memory data in the local user data directory
16
+ - Starts services on local ports (Qdrant, cortex-mem-service)
17
+ - Requires LLM/Embedding API keys (stored in OpenClaw plugin configuration, marked as sensitive)
18
+ - Only reads existing OpenClaw memory files during migration
19
+
20
+ **What the plugin does NOT do:**
21
+ - Does NOT send data to external servers (all processing is local)
22
+ - Does NOT transmit API keys to anywhere other than your configured LLM/embedding provider
23
+
24
+ ## How Memory Works
25
+
26
+ MemClaw provides **three-tier semantic memory** with hierarchical retrieval:
27
+
28
+ | Tier | Token Count | Content | Search Purpose |
29
+ |------|-------------|---------|----------------|
30
+ | **L0 (Summary)** | ~100 | High-level summary | Quick filtering |
31
+ | **L1 (Overview)** | ~2000 | Key points + context | Context refinement |
32
+ | **L2 (Full)** | Complete | Original content | Exact matching |
33
+
34
+ The search engine queries all three tiers internally and returns unified results containing `snippet` and `content`.
35
+
36
+ ## Installation Steps
37
+
38
+ ### Step 1: Install the Plugin (for users without the @memclaw/memclaw plugin)
39
+
40
+ Execute the following command to install the plugin:
41
+
42
+ ```bash
43
+ openclaw plugins install @memclaw/memclaw
44
+ ```
45
+
46
+ ### Step 2: Enable the Plugin
47
+
48
+ Enable MemClaw in `openclaw.json`:
49
+
50
+ ```json
51
+ {
52
+ "plugins": {
53
+ "entries": {
54
+ "memclaw": {
55
+ "enabled": true
56
+ }
57
+ }
58
+ }
59
+ }
60
+ ```
61
+
62
+ ### Step 3: Configure API Keys
63
+
64
+ **API keys must be configured to use MemClaw.**
65
+
66
+ 1. Open OpenClaw settings (`openclaw.json` or via UI)
67
+ 2. Navigate to Plugins → MemClaw → Configuration
68
+ 3. Enter your API keys in the secure fields:
69
+ - `llmApiKey` — LLM API key (marked as sensitive)
70
+ - `embeddingApiKey` — Embedding API key (marked as sensitive)
71
+ 4. Optional: Customize API endpoints and model names
72
+ 5. Save and restart OpenClaw
73
+
74
+ **Configuration Example:**
75
+
76
+ ```json
77
+ {
78
+ "plugins": {
79
+ "entries": {
80
+ "memclaw": {
81
+ "enabled": true,
82
+ "config": {
83
+ "llmApiKey": "your-llm-api-key",
84
+ "llmApiBaseUrl": "https://api.openai.com/v1",
85
+ "llmModel": "gpt-5-mini",
86
+ "embeddingApiKey": "your-embedding-api-key",
87
+ "embeddingApiBaseUrl": "https://api.openai.com/v1",
88
+ "embeddingModel": "text-embedding-3-small"
89
+ }
90
+ }
91
+ }
92
+ }
93
+ }
94
+ ```
95
+
96
+ > **Security Note**: API keys are stored with `sensitive` flag in OpenClaw configuration. Do not share your `openclaw.json` file publicly.
97
+
98
+ ### Step 4: Restart OpenClaw
99
+
100
+ Restart OpenClaw to activate the plugin and start services.
101
+
102
+ ## First-Time Use
103
+
104
+ ### Verify Service Status
105
+
106
+ After restarting, MemClaw will automatically start the required services. If configured correctly, you should be able to use the memory tools normally.
107
+
108
+ ### Migrate Existing Memories (Optional)
109
+
110
+ If the user has existing OpenClaw native memories, call the `cortex_migrate` tool to migrate them to MemClaw:
111
+
112
+ ```json
113
+ {}
114
+ ```
115
+
116
+ This will:
117
+ - Find OpenClaw memory files (`memory/*.md` and `MEMORY.md`)
118
+ - Convert to MemClaw's L2 format
119
+ - Generate L0/L1 layers and vector indices
120
+
121
+ > **Run only once** during initial setup.
122
+
123
+ ## Quick Start
124
+
125
+ After installation, use the following decision flow for memory operations:
126
+
127
+ | Scenario | Tool |
128
+ |----------|------|
129
+ | Need to find information | `cortex_search` |
130
+ | Need more context | `cortex_recall` |
131
+ | Save important information | `cortex_add_memory` |
132
+ | Complete a task/topic | `cortex_close_session` |
133
+ | First-time use with existing memories | `cortex_migrate` |
134
+
135
+ > **Important**: OpenClaw's session lifecycle does not automatically trigger memory extraction. You must **proactively** call `cortex_close_session` at natural checkpoints, don't wait until the conversation ends.
136
+
137
+ ## References
138
+
139
+ - **`references/tools.md`** — Detailed tool parameters and examples
140
+ - **`references/troubleshooting.md`** — Common troubleshooting issues
141
+ - **Open Source**: [Cortex Memory and MemClaw](https://github.com/sopaco/cortex-mem)
142
+ - **README**: [MemClaw README](https://raw.githubusercontent.com/sopaco/cortex-mem/refs/heads/main/examples/%40memclaw/plugin/README.md)