openclaw-mem 1.0.3 → 1.2.1
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/HOOK.md +125 -0
- package/LICENSE +1 -1
- package/MCP.json +11 -0
- package/README.md +140 -129
- package/context-builder.js +703 -0
- package/database.js +520 -0
- package/debug-logger.js +280 -0
- package/extractor.js +211 -0
- package/gateway-llm.js +155 -0
- package/handler.js +1122 -0
- package/mcp-http-api.js +356 -0
- package/mcp-server.js +525 -0
- package/mem-get.sh +24 -0
- package/mem-search.sh +17 -0
- package/monitor.js +112 -0
- package/package.json +53 -29
- package/realtime-monitor.js +371 -0
- package/session-watcher.js +192 -0
- package/setup.js +114 -0
- package/sync-recent.js +63 -0
- package/README_CN.md +0 -184
- package/bin/openclaw-mem.js +0 -117
- package/lib/context-builder.js +0 -415
- package/lib/database.js +0 -309
- package/lib/handler.js +0 -494
- package/scripts/commands.js +0 -141
- package/scripts/init.js +0 -248
package/HOOK.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: openclaw-mem
|
|
3
|
+
description: "Persistent memory system - saves session context and injects history into new sessions"
|
|
4
|
+
homepage: https://github.com/openclaw-mem
|
|
5
|
+
metadata:
|
|
6
|
+
{
|
|
7
|
+
"openclaw":
|
|
8
|
+
{
|
|
9
|
+
"emoji": "🧠",
|
|
10
|
+
"events": ["command:new", "gateway:startup", "agent:bootstrap", "agent:response", "agent:stop", "tool:post", "user:prompt", "message"],
|
|
11
|
+
"requires": { "config": ["workspace.dir"] },
|
|
12
|
+
"install": [{ "id": "local", "kind": "local", "label": "Local installation" }],
|
|
13
|
+
},
|
|
14
|
+
}
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
# OpenClaw-Mem: Persistent Memory System
|
|
18
|
+
|
|
19
|
+
A claude-mem inspired memory system for OpenClaw that automatically captures tool usage, generates summaries, and injects relevant context into new sessions.
|
|
20
|
+
|
|
21
|
+
## Features
|
|
22
|
+
|
|
23
|
+
- 🧠 **Persistent Memory** - Context survives across sessions
|
|
24
|
+
- 📊 **Progressive Disclosure** - Shows index first, fetch details on demand
|
|
25
|
+
- 🔍 **Hybrid Search** - Full-text + semantic search
|
|
26
|
+
- 🤖 **AI Compression** - Automatic summarization of observations
|
|
27
|
+
- ⚡ **Token Efficient** - Only loads what's relevant
|
|
28
|
+
- 📡 **Real-time Capture** - Records messages as they happen
|
|
29
|
+
|
|
30
|
+
## Events Captured
|
|
31
|
+
|
|
32
|
+
- `gateway:startup` - Initialize memory system
|
|
33
|
+
- `agent:bootstrap` - Inject historical context
|
|
34
|
+
- `agent:response` - Capture assistant responses in real-time
|
|
35
|
+
- `agent:stop` - Save session summary
|
|
36
|
+
- `command:new` - Save session content before reset
|
|
37
|
+
- `tool:post` - Capture tool usage
|
|
38
|
+
- `user:prompt` - Capture user messages
|
|
39
|
+
- `message` - Capture all messages
|
|
40
|
+
|
|
41
|
+
## Configuration
|
|
42
|
+
|
|
43
|
+
```json
|
|
44
|
+
{
|
|
45
|
+
"hooks": {
|
|
46
|
+
"internal": {
|
|
47
|
+
"entries": {
|
|
48
|
+
"openclaw-mem": {
|
|
49
|
+
"enabled": true,
|
|
50
|
+
"observationLimit": 50,
|
|
51
|
+
"fullDetailCount": 5,
|
|
52
|
+
"compressWithLLM": true
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Storage
|
|
61
|
+
|
|
62
|
+
Data is stored in SQLite at `~/.openclaw-mem/memory.db`:
|
|
63
|
+
- `sessions` - Session records
|
|
64
|
+
- `observations` - Tool call observations
|
|
65
|
+
- `summaries` - Session summaries
|
|
66
|
+
|
|
67
|
+
## Real-time Monitoring
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
node ~/.openclaw/hooks/openclaw-mem/monitor.js
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Usage
|
|
74
|
+
|
|
75
|
+
The memory system works automatically. To search manually:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# Search memory
|
|
79
|
+
openclaw memory search "authentication"
|
|
80
|
+
|
|
81
|
+
# View status
|
|
82
|
+
openclaw memory status
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## MCP Server (Model Context Protocol)
|
|
86
|
+
|
|
87
|
+
OpenClaw-Mem 提供 MCP Server,让 AI 可以按需查询记忆:
|
|
88
|
+
|
|
89
|
+
### MCP 工具
|
|
90
|
+
|
|
91
|
+
| Tool | Description |
|
|
92
|
+
|------|-------------|
|
|
93
|
+
| `__IMPORTANT` | 显示 3 层工作流说明 |
|
|
94
|
+
| `search` | 搜索记忆索引 |
|
|
95
|
+
| `timeline` | 获取某条记录的上下文 |
|
|
96
|
+
| `get_observations` | 获取完整详情 |
|
|
97
|
+
|
|
98
|
+
### 启动 MCP Server
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
# stdio 模式(标准 MCP)
|
|
102
|
+
node ~/.openclaw/hooks/openclaw-mem/mcp-server.js
|
|
103
|
+
|
|
104
|
+
# HTTP API 模式(兼容模式)
|
|
105
|
+
node ~/.openclaw/hooks/openclaw-mem/mcp-http-api.js
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### HTTP API 端点
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
# 搜索
|
|
112
|
+
curl "http://127.0.0.1:18790/search?query=database&limit=10"
|
|
113
|
+
|
|
114
|
+
# Timeline
|
|
115
|
+
curl "http://127.0.0.1:18790/timeline?anchor=123"
|
|
116
|
+
|
|
117
|
+
# 获取详情
|
|
118
|
+
curl -X POST "http://127.0.0.1:18790/get_observations" -d '{"ids":[123,124]}'
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Disabling
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
openclaw hooks disable openclaw-mem
|
|
125
|
+
```
|
package/LICENSE
CHANGED
package/MCP.json
ADDED
package/README.md
CHANGED
|
@@ -1,184 +1,195 @@
|
|
|
1
|
-
# OpenClaw-Mem
|
|
1
|
+
# OpenClaw-Mem
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A persistent memory system for [OpenClaw](https://github.com/openclaw) that automatically captures conversations, generates summaries, and injects relevant context into new sessions.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
## Features
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
- **Persistent Memory** - Context survives across sessions
|
|
8
|
+
- **Progressive Disclosure** - Shows index first, fetch details on demand
|
|
9
|
+
- **Hybrid Search** - Full-text + LIKE search with CJK support
|
|
10
|
+
- **AI Compression** - Automatic summarization of observations
|
|
11
|
+
- **Token Efficient** - Only loads what's relevant
|
|
12
|
+
- **Real-time Capture** - Records messages as they happen
|
|
13
|
+
- **MCP Compatible** - Model Context Protocol server included
|
|
14
|
+
- **HTTP API** - REST API for memory queries
|
|
9
15
|
|
|
10
|
-
|
|
16
|
+
## Installation
|
|
11
17
|
|
|
12
|
-
|
|
18
|
+
### As OpenClaw Hook
|
|
13
19
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
```bash
|
|
21
|
+
# Clone to OpenClaw hooks directory
|
|
22
|
+
git clone https://github.com/wenyupapa-sys/openclaw-mem.git ~/.openclaw/hooks/openclaw-mem
|
|
23
|
+
cd ~/.openclaw/hooks/openclaw-mem
|
|
24
|
+
npm install
|
|
25
|
+
```
|
|
20
26
|
|
|
21
|
-
|
|
27
|
+
### As npm Package
|
|
22
28
|
|
|
23
29
|
```bash
|
|
24
|
-
|
|
25
|
-
npx openclaw-mem init
|
|
26
|
-
|
|
27
|
-
# Restart OpenClaw gateway
|
|
28
|
-
openclaw gateway restart
|
|
30
|
+
npm install openclaw-mem
|
|
29
31
|
```
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
## Quick Start
|
|
32
34
|
|
|
33
|
-
|
|
35
|
+
1. **Install the hook** (see above)
|
|
34
36
|
|
|
35
|
-
|
|
37
|
+
2. **Run setup** - configure your DeepSeek API key (prompted automatically after install)
|
|
38
|
+
```bash
|
|
39
|
+
# Or run manually later
|
|
40
|
+
npm run setup
|
|
41
|
+
# or
|
|
42
|
+
npx openclaw-mem-setup
|
|
43
|
+
```
|
|
36
44
|
|
|
37
|
-
|
|
38
|
-
- "What did we discuss before?"
|
|
39
|
-
- "What were we working on last time?"
|
|
40
|
-
- "Remind me about the authentication issue"
|
|
45
|
+
3. **Restart OpenClaw** to load the hook
|
|
41
46
|
|
|
42
|
-
|
|
47
|
+
4. **Start chatting** - conversations are automatically saved
|
|
43
48
|
|
|
44
|
-
|
|
45
|
-
# Check memory status
|
|
46
|
-
npx openclaw-mem status
|
|
49
|
+
5. **Query memories** - ask "what did we discuss before?" and the AI will search the memory database
|
|
47
50
|
|
|
48
|
-
|
|
49
|
-
npx openclaw-mem search "authentication"
|
|
50
|
-
npx openclaw-mem search "AI memory"
|
|
51
|
+
## Events Captured
|
|
51
52
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
| Event | Description |
|
|
54
|
+
|-------|-------------|
|
|
55
|
+
| `gateway:startup` | Initialize memory system |
|
|
56
|
+
| `agent:bootstrap` | Inject historical context |
|
|
57
|
+
| `agent:response` | Capture assistant responses |
|
|
58
|
+
| `agent:stop` | Save session summary |
|
|
59
|
+
| `command:new` | Save session before reset |
|
|
60
|
+
| `tool:post` | Capture tool usage |
|
|
61
|
+
| `user:prompt` | Capture user messages |
|
|
55
62
|
|
|
56
|
-
##
|
|
63
|
+
## API Reference
|
|
57
64
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
65
|
+
### HTTP API (Port 18790)
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
# Search memories
|
|
69
|
+
curl -s -X POST "http://127.0.0.1:18790/search" \
|
|
70
|
+
-H "Content-Type: application/json" \
|
|
71
|
+
-d '{"query":"keyword","limit":10}'
|
|
72
|
+
|
|
73
|
+
# Get observation details
|
|
74
|
+
curl -s -X POST "http://127.0.0.1:18790/get_observations" \
|
|
75
|
+
-H "Content-Type: application/json" \
|
|
76
|
+
-d '{"ids":[123,124]}'
|
|
77
|
+
|
|
78
|
+
# Get timeline context
|
|
79
|
+
curl -s -X POST "http://127.0.0.1:18790/timeline" \
|
|
80
|
+
-H "Content-Type: application/json" \
|
|
81
|
+
-d '{"anchor":123}'
|
|
82
|
+
|
|
83
|
+
# Health check
|
|
84
|
+
curl "http://127.0.0.1:18790/health"
|
|
76
85
|
```
|
|
77
86
|
|
|
78
|
-
###
|
|
87
|
+
### Shell Scripts
|
|
79
88
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
89
|
+
```bash
|
|
90
|
+
# Search (handles CJK encoding automatically)
|
|
91
|
+
~/.openclaw/hooks/openclaw-mem/mem-search.sh "关键词" 10
|
|
83
92
|
|
|
84
|
-
|
|
93
|
+
# Get details
|
|
94
|
+
~/.openclaw/hooks/openclaw-mem/mem-get.sh 123 124 125
|
|
95
|
+
```
|
|
85
96
|
|
|
86
|
-
|
|
97
|
+
### MCP Server
|
|
87
98
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
| Details | Full content (on demand) | ~High |
|
|
99
|
+
```bash
|
|
100
|
+
# Start MCP server (stdio mode)
|
|
101
|
+
node mcp-server.js
|
|
102
|
+
```
|
|
93
103
|
|
|
94
|
-
|
|
104
|
+
MCP Tools:
|
|
105
|
+
- `search` - Search memory index
|
|
106
|
+
- `timeline` - Get context around an observation
|
|
107
|
+
- `get_observations` - Fetch full details
|
|
95
108
|
|
|
96
|
-
|
|
97
|
-
|------|----------|---------|
|
|
98
|
-
| Database | `~/.openclaw-mem/memory.db` | Persistent storage |
|
|
99
|
-
| Hook | `~/.openclaw/hooks/openclaw-mem/` | Event handlers |
|
|
100
|
-
| Memory Context | `~/.openclaw/workspace/SESSION-MEMORY.md` | Injected context |
|
|
109
|
+
## Configuration
|
|
101
110
|
|
|
102
|
-
|
|
111
|
+
### Environment Variables
|
|
103
112
|
|
|
104
|
-
|
|
113
|
+
```bash
|
|
114
|
+
# Required for AI summarization (optional but recommended)
|
|
115
|
+
export DEEPSEEK_API_KEY="your-deepseek-api-key"
|
|
105
116
|
|
|
106
|
-
|
|
117
|
+
# Optional: Custom DeepSeek endpoint
|
|
118
|
+
export DEEPSEEK_BASE_URL="https://api.deepseek.com/v1"
|
|
107
119
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
- Language: English
|
|
120
|
+
# Optional: Custom model
|
|
121
|
+
export DEEPSEEK_MODEL="deepseek-chat"
|
|
122
|
+
```
|
|
112
123
|
|
|
113
|
-
|
|
114
|
-
- Working on: AI memory systems
|
|
115
|
-
- Interests: Machine learning, distributed systems
|
|
124
|
+
Get your DeepSeek API key at: https://platform.deepseek.com/
|
|
116
125
|
|
|
117
|
-
|
|
118
|
-
- Current project: Building a chat application
|
|
119
|
-
```
|
|
126
|
+
> **Note:** Without `DEEPSEEK_API_KEY`, the system will still work but won't generate AI summaries for sessions.
|
|
120
127
|
|
|
121
|
-
###
|
|
128
|
+
### OpenClaw Config
|
|
122
129
|
|
|
123
|
-
|
|
124
|
-
- Concepts mentioned frequently are detected automatically
|
|
125
|
-
- No hardcoded keywords - everything comes from your data
|
|
126
|
-
- Topics evolve as your discussions change
|
|
130
|
+
Add to your OpenClaw config:
|
|
127
131
|
|
|
128
|
-
|
|
132
|
+
```json
|
|
133
|
+
{
|
|
134
|
+
"hooks": {
|
|
135
|
+
"internal": {
|
|
136
|
+
"entries": {
|
|
137
|
+
"openclaw-mem": {
|
|
138
|
+
"enabled": true,
|
|
139
|
+
"observationLimit": 50,
|
|
140
|
+
"fullDetailCount": 5
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
```
|
|
129
147
|
|
|
130
|
-
|
|
148
|
+
## Storage
|
|
131
149
|
|
|
132
|
-
|
|
133
|
-
```bash
|
|
134
|
-
openclaw gateway restart
|
|
135
|
-
```
|
|
150
|
+
Data is stored in SQLite at `~/.openclaw-mem/memory.db`:
|
|
136
151
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
152
|
+
| Table | Description |
|
|
153
|
+
|-------|-------------|
|
|
154
|
+
| `sessions` | Session records |
|
|
155
|
+
| `observations` | Tool calls and messages |
|
|
156
|
+
| `summaries` | Session summaries |
|
|
157
|
+
| `user_prompts` | User inputs |
|
|
141
158
|
|
|
142
|
-
|
|
143
|
-
```bash
|
|
144
|
-
npx openclaw-mem status
|
|
145
|
-
```
|
|
159
|
+
## Development
|
|
146
160
|
|
|
147
|
-
|
|
161
|
+
```bash
|
|
162
|
+
# Run tests
|
|
163
|
+
npm test
|
|
148
164
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
- Use keywords from the actual conversation
|
|
165
|
+
# Start HTTP API server
|
|
166
|
+
npm run api
|
|
152
167
|
|
|
153
|
-
|
|
168
|
+
# Start MCP server
|
|
169
|
+
npm run mcp
|
|
154
170
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
rm ~/.openclaw-mem/memory.db
|
|
158
|
-
openclaw gateway restart
|
|
171
|
+
# Monitor real-time activity
|
|
172
|
+
node debug-logger.js
|
|
159
173
|
```
|
|
160
174
|
|
|
161
|
-
##
|
|
175
|
+
## 3-Layer Retrieval Workflow
|
|
176
|
+
|
|
177
|
+
For efficient token usage, use progressive disclosure:
|
|
162
178
|
|
|
163
|
-
|
|
179
|
+
1. **Search** → Get index with IDs (~50-100 tokens/result)
|
|
180
|
+
2. **Timeline** → Get context around interesting results
|
|
181
|
+
3. **Get Observations** → Fetch full details ONLY for filtered IDs
|
|
164
182
|
|
|
165
|
-
|
|
166
|
-
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
167
|
-
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
168
|
-
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
169
|
-
5. Open a Pull Request
|
|
183
|
+
This approach saves ~30% tokens compared to fetching everything.
|
|
170
184
|
|
|
171
|
-
##
|
|
185
|
+
## License
|
|
172
186
|
|
|
173
|
-
MIT
|
|
187
|
+
MIT
|
|
174
188
|
|
|
175
|
-
##
|
|
189
|
+
## Contributing
|
|
176
190
|
|
|
177
|
-
|
|
178
|
-
- Built for [OpenClaw](https://openclaw.ai)
|
|
191
|
+
Pull requests welcome! Please ensure tests pass before submitting.
|
|
179
192
|
|
|
180
|
-
|
|
193
|
+
## Credits
|
|
181
194
|
|
|
182
|
-
|
|
183
|
-
Made with ❤️ for the AI community
|
|
184
|
-
</p>
|
|
195
|
+
Inspired by [claude-mem](https://github.com/anthropics/claude-code) plugin architecture.
|