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 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
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 OpenClaw Contributors
3
+ Copyright (c) 2026 Aaron
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/MCP.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "mcpServers": {
3
+ "openclaw-mem-search": {
4
+ "type": "stdio",
5
+ "command": "node",
6
+ "args": ["mcp-server.js"],
7
+ "cwd": "${HOOK_ROOT}",
8
+ "description": "Memory search tools for OpenClaw-Mem"
9
+ }
10
+ }
11
+ }
package/README.md CHANGED
@@ -1,184 +1,195 @@
1
- # OpenClaw-Mem 🧠
1
+ # OpenClaw-Mem
2
2
 
3
- > Give your OpenClaw AI agent persistent long-term memory
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
- [![npm version](https://badge.fury.io/js/openclaw-mem.svg)](https://www.npmjs.com/package/openclaw-mem)
6
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ ## Features
7
6
 
8
- English | [中文](README_CN.md)
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
- OpenClaw-Mem automatically captures your conversations and makes them searchable, allowing your AI assistant to remember what you've discussed across sessions.
16
+ ## Installation
11
17
 
12
- ## Features
18
+ ### As OpenClaw Hook
13
19
 
14
- - **🔄 Automatic Memory Capture** - Conversations are saved automatically
15
- - **🔍 Full-Text Search** - Search through your entire conversation history
16
- - **📊 Progressive Disclosure** - Efficient token usage with layered context
17
- - **🎯 Topic Detection** - Automatically indexes discussions by topic
18
- - **💾 Local Storage** - All data stays on your machine (SQLite)
19
- - **⚡ Zero Config** - Works out of the box
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
- ## 🚀 Quick Start
27
+ ### As npm Package
22
28
 
23
29
  ```bash
24
- # Install and setup (one command!)
25
- npx openclaw-mem init
26
-
27
- # Restart OpenClaw gateway
28
- openclaw gateway restart
30
+ npm install openclaw-mem
29
31
  ```
30
32
 
31
- That's it! Start chatting and your conversations will be remembered.
33
+ ## Quick Start
32
34
 
33
- ## 📖 Usage
35
+ 1. **Install the hook** (see above)
34
36
 
35
- ### Recalling Memories in Chat
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
- Ask your AI assistant:
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
- ### CLI Commands
47
+ 4. **Start chatting** - conversations are automatically saved
43
48
 
44
- ```bash
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
- # Search your memory
49
- npx openclaw-mem search "authentication"
50
- npx openclaw-mem search "AI memory"
51
+ ## Events Captured
51
52
 
52
- # Remove (keeps database)
53
- npx openclaw-mem uninstall
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
- ## 🏗️ How It Works
63
+ ## API Reference
57
64
 
58
- ```
59
- +-------------+ +------------------+ +------------+
60
- | Telegram | --> | OpenClaw Gateway | --> | AI Agent |
61
- +-------------+ +------------------+ +------------+
62
- | |
63
- v v
64
- +--------------+ +------------+
65
- | openclaw-mem | | Read Tool |
66
- | hook | +------------+
67
- +--------------+ |
68
- | v
69
- +-------------------+----------------------+
70
- | |
71
- v v
72
- +---------------+ +------------------+
73
- | SQLite DB | | SESSION-MEMORY.md|
74
- | (persistent) | | (injected) |
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
- ### Event Flow
87
+ ### Shell Scripts
79
88
 
80
- 1. **`gateway:startup`** - Initializes the memory database
81
- 2. **`agent:bootstrap`** - Injects historical context into new sessions
82
- 3. **`command:new`** - Saves session summary when you start fresh
89
+ ```bash
90
+ # Search (handles CJK encoding automatically)
91
+ ~/.openclaw/hooks/openclaw-mem/mem-search.sh "关键词" 10
83
92
 
84
- ### Progressive Disclosure
93
+ # Get details
94
+ ~/.openclaw/hooks/openclaw-mem/mem-get.sh 123 124 125
95
+ ```
85
96
 
86
- To optimize token usage, memories are organized in layers:
97
+ ### MCP Server
87
98
 
88
- | Layer | Content | Tokens |
89
- |-------|---------|--------|
90
- | Index | Compact table of all observations | ~Low |
91
- | Topics | Key discussion summaries | ~Medium |
92
- | Details | Full content (on demand) | ~High |
99
+ ```bash
100
+ # Start MCP server (stdio mode)
101
+ node mcp-server.js
102
+ ```
93
103
 
94
- ## 📁 File Locations
104
+ MCP Tools:
105
+ - `search` - Search memory index
106
+ - `timeline` - Get context around an observation
107
+ - `get_observations` - Fetch full details
95
108
 
96
- | File | Location | Purpose |
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
- ## ⚙️ Configuration
111
+ ### Environment Variables
103
112
 
104
- ### Customize MEMORY.md
113
+ ```bash
114
+ # Required for AI summarization (optional but recommended)
115
+ export DEEPSEEK_API_KEY="your-deepseek-api-key"
105
116
 
106
- Add your preferences to `~/.openclaw/workspace/MEMORY.md`:
117
+ # Optional: Custom DeepSeek endpoint
118
+ export DEEPSEEK_BASE_URL="https://api.deepseek.com/v1"
107
119
 
108
- ```markdown
109
- ## User Preferences
110
- - Communication style: Technical and concise
111
- - Language: English
120
+ # Optional: Custom model
121
+ export DEEPSEEK_MODEL="deepseek-chat"
122
+ ```
112
123
 
113
- ## Long-Term Context
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
- ## Ongoing Focus
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
- ### Dynamic Topic Detection
128
+ ### OpenClaw Config
122
129
 
123
- The system automatically extracts topics from your actual conversations:
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
- ## 🔧 Troubleshooting
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
- ### Memory not being recalled?
148
+ ## Storage
131
149
 
132
- 1. **Restart the gateway:**
133
- ```bash
134
- openclaw gateway restart
135
- ```
150
+ Data is stored in SQLite at `~/.openclaw-mem/memory.db`:
136
151
 
137
- 2. **Check hook is installed:**
138
- ```bash
139
- ls ~/.openclaw/hooks/openclaw-mem/
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
- 3. **Verify database has content:**
143
- ```bash
144
- npx openclaw-mem status
145
- ```
159
+ ## Development
146
160
 
147
- ### Search not finding results?
161
+ ```bash
162
+ # Run tests
163
+ npm test
148
164
 
149
- - Try simpler search terms
150
- - Check for typos
151
- - Use keywords from the actual conversation
165
+ # Start HTTP API server
166
+ npm run api
152
167
 
153
- ### Database issues?
168
+ # Start MCP server
169
+ npm run mcp
154
170
 
155
- ```bash
156
- # Reset database (⚠️ deletes all memories)
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
- ## 🤝 Contributing
175
+ ## 3-Layer Retrieval Workflow
176
+
177
+ For efficient token usage, use progressive disclosure:
162
178
 
163
- Contributions are welcome! Please feel free to submit a Pull Request.
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
- 1. Fork the repository
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
- ## 📄 License
185
+ ## License
172
186
 
173
- MIT License - see [LICENSE](LICENSE) for details.
187
+ MIT
174
188
 
175
- ## 🙏 Acknowledgments
189
+ ## Contributing
176
190
 
177
- - Inspired by [claude-mem](https://github.com/anthropics/claude-mem)
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
- <p align="center">
183
- Made with ❤️ for the AI community
184
- </p>
195
+ Inspired by [claude-mem](https://github.com/anthropics/claude-code) plugin architecture.