openclaw-mem 1.0.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/LICENSE +21 -0
- package/README.md +182 -0
- package/bin/openclaw-mem.js +117 -0
- package/lib/context-builder.js +401 -0
- package/lib/database.js +309 -0
- package/lib/handler.js +494 -0
- package/package.json +57 -0
- package/scripts/commands.js +141 -0
- package/scripts/init.js +248 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 OpenClaw Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# OpenClaw-Mem ๐ง
|
|
2
|
+
|
|
3
|
+
> Give your OpenClaw AI agent persistent long-term memory
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/openclaw-mem)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
OpenClaw-Mem automatically captures your conversations and makes them searchable, allowing your AI assistant to remember what you've discussed across sessions.
|
|
9
|
+
|
|
10
|
+
## โจ Features
|
|
11
|
+
|
|
12
|
+
- **๐ Automatic Memory Capture** - Conversations are saved automatically
|
|
13
|
+
- **๐ Full-Text Search** - Search through your entire conversation history
|
|
14
|
+
- **๐ Progressive Disclosure** - Efficient token usage with layered context
|
|
15
|
+
- **๐ฏ Topic Detection** - Automatically indexes discussions by topic
|
|
16
|
+
- **๐พ Local Storage** - All data stays on your machine (SQLite)
|
|
17
|
+
- **โก Zero Config** - Works out of the box
|
|
18
|
+
|
|
19
|
+
## ๐ Quick Start
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# Install and setup (one command!)
|
|
23
|
+
npx openclaw-mem init
|
|
24
|
+
|
|
25
|
+
# Restart OpenClaw gateway
|
|
26
|
+
openclaw gateway restart
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
That's it! Start chatting and your conversations will be remembered.
|
|
30
|
+
|
|
31
|
+
## ๐ Usage
|
|
32
|
+
|
|
33
|
+
### Recalling Memories in Chat
|
|
34
|
+
|
|
35
|
+
Ask your AI assistant:
|
|
36
|
+
- "What did we discuss before?"
|
|
37
|
+
- "ๆไปฌไนๅ่ฎจ่ฎบ่ฟไปไน๏ผ"
|
|
38
|
+
- "What were we working on last time?"
|
|
39
|
+
- "Remind me about the authentication issue"
|
|
40
|
+
|
|
41
|
+
### CLI Commands
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
# Check memory status
|
|
45
|
+
npx openclaw-mem status
|
|
46
|
+
|
|
47
|
+
# Search your memory
|
|
48
|
+
npx openclaw-mem search "authentication"
|
|
49
|
+
npx openclaw-mem search "AI memory"
|
|
50
|
+
|
|
51
|
+
# Remove (keeps database)
|
|
52
|
+
npx openclaw-mem uninstall
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## ๐๏ธ How It Works
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
|
|
59
|
+
โ Telegram โโโโโโถโ OpenClaw Gateway โโโโโโถโ AI Agent โ
|
|
60
|
+
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
|
|
61
|
+
โ โ
|
|
62
|
+
โผ โผ
|
|
63
|
+
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
|
|
64
|
+
โ openclaw-mem โ โ Read Tool โ
|
|
65
|
+
โ hook โ โโโโโโโโโโโโโโโ
|
|
66
|
+
โโโโโโโโโโโโโโโโ โ
|
|
67
|
+
โ โผ
|
|
68
|
+
โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
69
|
+
โผ โผ
|
|
70
|
+
โโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
|
|
71
|
+
โ SQLite DB โ โ SESSION-MEMORY.md โ
|
|
72
|
+
โ (persistent) โ โ (injected) โ
|
|
73
|
+
โโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Event Flow
|
|
77
|
+
|
|
78
|
+
1. **`gateway:startup`** - Initializes the memory database
|
|
79
|
+
2. **`agent:bootstrap`** - Injects historical context into new sessions
|
|
80
|
+
3. **`command:new`** - Saves session summary when you start fresh
|
|
81
|
+
|
|
82
|
+
### Progressive Disclosure
|
|
83
|
+
|
|
84
|
+
To optimize token usage, memories are organized in layers:
|
|
85
|
+
|
|
86
|
+
| Layer | Content | Tokens |
|
|
87
|
+
|-------|---------|--------|
|
|
88
|
+
| Index | Compact table of all observations | ~Low |
|
|
89
|
+
| Topics | Key discussion summaries | ~Medium |
|
|
90
|
+
| Details | Full content (on demand) | ~High |
|
|
91
|
+
|
|
92
|
+
## ๐ File Locations
|
|
93
|
+
|
|
94
|
+
| File | Location | Purpose |
|
|
95
|
+
|------|----------|---------|
|
|
96
|
+
| Database | `~/.openclaw-mem/memory.db` | Persistent storage |
|
|
97
|
+
| Hook | `~/.openclaw/hooks/openclaw-mem/` | Event handlers |
|
|
98
|
+
| Memory Context | `~/.openclaw/workspace/SESSION-MEMORY.md` | Injected context |
|
|
99
|
+
|
|
100
|
+
## โ๏ธ Configuration
|
|
101
|
+
|
|
102
|
+
### Customize MEMORY.md
|
|
103
|
+
|
|
104
|
+
Add your preferences to `~/.openclaw/workspace/MEMORY.md`:
|
|
105
|
+
|
|
106
|
+
```markdown
|
|
107
|
+
## User Preferences
|
|
108
|
+
- Communication style: Technical and concise
|
|
109
|
+
- Language: English
|
|
110
|
+
|
|
111
|
+
## Long-Term Context
|
|
112
|
+
- Working on: AI memory systems
|
|
113
|
+
- Interests: Machine learning, distributed systems
|
|
114
|
+
|
|
115
|
+
## Ongoing Focus
|
|
116
|
+
- Current project: Building a chat application
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Topic Keywords
|
|
120
|
+
|
|
121
|
+
The system automatically searches for these topic keywords:
|
|
122
|
+
- AI/Machine Learning: `็ญๆ่ฎฐๅฟ`, `้ฟๆ่ฎฐๅฟ`, `ๅ้ๆฐๆฎๅบ`, `RAG`
|
|
123
|
+
- Health/Fitness: `้ฟๅฏฟ`, `็ฆ้ฃ`, `ๅ้่ฎญ็ป`, `ๆๆฐง่ฟๅจ`
|
|
124
|
+
- Programming: `Node.js`, `TypeScript`, `ๅพฎๆๅก`, `ๆถๆ`
|
|
125
|
+
|
|
126
|
+
## ๐ง Troubleshooting
|
|
127
|
+
|
|
128
|
+
### Memory not being recalled?
|
|
129
|
+
|
|
130
|
+
1. **Restart the gateway:**
|
|
131
|
+
```bash
|
|
132
|
+
openclaw gateway restart
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
2. **Check hook is installed:**
|
|
136
|
+
```bash
|
|
137
|
+
ls ~/.openclaw/hooks/openclaw-mem/
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
3. **Verify database has content:**
|
|
141
|
+
```bash
|
|
142
|
+
npx openclaw-mem status
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Search not finding results?
|
|
146
|
+
|
|
147
|
+
- Try simpler search terms
|
|
148
|
+
- Check for typos
|
|
149
|
+
- Use keywords from the actual conversation
|
|
150
|
+
|
|
151
|
+
### Database issues?
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
# Reset database (โ ๏ธ deletes all memories)
|
|
155
|
+
rm ~/.openclaw-mem/memory.db
|
|
156
|
+
openclaw gateway restart
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## ๐ค Contributing
|
|
160
|
+
|
|
161
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
162
|
+
|
|
163
|
+
1. Fork the repository
|
|
164
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
165
|
+
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
166
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
167
|
+
5. Open a Pull Request
|
|
168
|
+
|
|
169
|
+
## ๐ License
|
|
170
|
+
|
|
171
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
172
|
+
|
|
173
|
+
## ๐ Acknowledgments
|
|
174
|
+
|
|
175
|
+
- Inspired by [claude-mem](https://github.com/anthropics/claude-mem)
|
|
176
|
+
- Built for [OpenClaw](https://openclaw.ai)
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
<p align="center">
|
|
181
|
+
Made with โค๏ธ for the AI community
|
|
182
|
+
</p>
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* OpenClaw-Mem CLI
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* npx openclaw-mem init - Install hook to OpenClaw
|
|
7
|
+
* npx openclaw-mem status - Show memory statistics
|
|
8
|
+
* npx openclaw-mem search - Search memory
|
|
9
|
+
* npx openclaw-mem uninstall - Remove hook
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
import fs from 'node:fs';
|
|
15
|
+
|
|
16
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
17
|
+
const args = process.argv.slice(2);
|
|
18
|
+
const command = args[0];
|
|
19
|
+
|
|
20
|
+
// Colors for terminal output
|
|
21
|
+
const c = {
|
|
22
|
+
reset: '\x1b[0m',
|
|
23
|
+
green: '\x1b[32m',
|
|
24
|
+
red: '\x1b[31m',
|
|
25
|
+
yellow: '\x1b[33m',
|
|
26
|
+
blue: '\x1b[34m',
|
|
27
|
+
cyan: '\x1b[36m',
|
|
28
|
+
bold: '\x1b[1m',
|
|
29
|
+
dim: '\x1b[2m'
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
function log(msg, color = 'reset') {
|
|
33
|
+
console.log(`${c[color]}${msg}${c.reset}`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function printBanner() {
|
|
37
|
+
console.log(`
|
|
38
|
+
${c.cyan}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
39
|
+
โ โ
|
|
40
|
+
โ ${c.bold}OpenClaw-Mem${c.reset}${c.cyan} - Persistent Memory for OpenClaw โ
|
|
41
|
+
โ โ
|
|
42
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${c.reset}
|
|
43
|
+
`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function printUsage() {
|
|
47
|
+
console.log(`
|
|
48
|
+
${c.bold}Usage:${c.reset}
|
|
49
|
+
npx openclaw-mem <command>
|
|
50
|
+
|
|
51
|
+
${c.bold}Commands:${c.reset}
|
|
52
|
+
${c.green}init${c.reset} Install openclaw-mem hook to your OpenClaw setup
|
|
53
|
+
${c.green}status${c.reset} Show memory database statistics
|
|
54
|
+
${c.green}search${c.reset} Search your memory (e.g., npx openclaw-mem search "topic")
|
|
55
|
+
${c.green}uninstall${c.reset} Remove openclaw-mem from OpenClaw
|
|
56
|
+
${c.green}help${c.reset} Show this help message
|
|
57
|
+
|
|
58
|
+
${c.bold}Examples:${c.reset}
|
|
59
|
+
${c.dim}# First time setup${c.reset}
|
|
60
|
+
npx openclaw-mem init
|
|
61
|
+
|
|
62
|
+
${c.dim}# Check what's stored${c.reset}
|
|
63
|
+
npx openclaw-mem status
|
|
64
|
+
|
|
65
|
+
${c.dim}# Search for conversations about AI${c.reset}
|
|
66
|
+
npx openclaw-mem search "AI memory"
|
|
67
|
+
|
|
68
|
+
${c.bold}Learn more:${c.reset}
|
|
69
|
+
https://github.com/anthropics/openclaw-mem
|
|
70
|
+
`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function main() {
|
|
74
|
+
if (!command || command === 'help' || command === '--help' || command === '-h') {
|
|
75
|
+
printBanner();
|
|
76
|
+
printUsage();
|
|
77
|
+
process.exit(0);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
switch (command) {
|
|
81
|
+
case 'init': {
|
|
82
|
+
const { init } = await import('../scripts/init.js');
|
|
83
|
+
await init();
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
case 'status': {
|
|
87
|
+
const { status } = await import('../scripts/commands.js');
|
|
88
|
+
await status();
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
case 'search': {
|
|
92
|
+
const query = args.slice(1).join(' ');
|
|
93
|
+
if (!query) {
|
|
94
|
+
log('Error: Please provide a search query', 'red');
|
|
95
|
+
log('Usage: npx openclaw-mem search "your query"', 'dim');
|
|
96
|
+
process.exit(1);
|
|
97
|
+
}
|
|
98
|
+
const { search } = await import('../scripts/commands.js');
|
|
99
|
+
await search(query);
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
case 'uninstall': {
|
|
103
|
+
const { uninstall } = await import('../scripts/init.js');
|
|
104
|
+
await uninstall();
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
default:
|
|
108
|
+
log(`Unknown command: ${command}`, 'red');
|
|
109
|
+
printUsage();
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
main().catch(err => {
|
|
115
|
+
log(`Error: ${err.message}`, 'red');
|
|
116
|
+
process.exit(1);
|
|
117
|
+
});
|