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 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
+ [![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)
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
+ });