openclaw-mem 1.0.4 → 1.3.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.
Files changed (47) hide show
  1. package/HOOK.md +125 -0
  2. package/LICENSE +1 -1
  3. package/MCP.json +11 -0
  4. package/README.md +158 -167
  5. package/backfill-embeddings.js +79 -0
  6. package/context-builder.js +703 -0
  7. package/database.js +625 -0
  8. package/debug-logger.js +280 -0
  9. package/extractor.js +268 -0
  10. package/gateway-llm.js +250 -0
  11. package/handler.js +941 -0
  12. package/mcp-http-api.js +424 -0
  13. package/mcp-server.js +605 -0
  14. package/mem-get.sh +24 -0
  15. package/mem-search.sh +17 -0
  16. package/monitor.js +112 -0
  17. package/package.json +58 -30
  18. package/realtime-monitor.js +371 -0
  19. package/session-watcher.js +192 -0
  20. package/setup.js +114 -0
  21. package/sync-recent.js +63 -0
  22. package/README_CN.md +0 -201
  23. package/bin/openclaw-mem.js +0 -117
  24. package/docs/locales/README_AR.md +0 -35
  25. package/docs/locales/README_DE.md +0 -35
  26. package/docs/locales/README_ES.md +0 -35
  27. package/docs/locales/README_FR.md +0 -35
  28. package/docs/locales/README_HE.md +0 -35
  29. package/docs/locales/README_HI.md +0 -35
  30. package/docs/locales/README_ID.md +0 -35
  31. package/docs/locales/README_IT.md +0 -35
  32. package/docs/locales/README_JA.md +0 -57
  33. package/docs/locales/README_KO.md +0 -35
  34. package/docs/locales/README_NL.md +0 -35
  35. package/docs/locales/README_PL.md +0 -35
  36. package/docs/locales/README_PT.md +0 -35
  37. package/docs/locales/README_RU.md +0 -35
  38. package/docs/locales/README_TH.md +0 -35
  39. package/docs/locales/README_TR.md +0 -35
  40. package/docs/locales/README_UK.md +0 -35
  41. package/docs/locales/README_VI.md +0 -35
  42. package/docs/logo.svg +0 -32
  43. package/lib/context-builder.js +0 -415
  44. package/lib/database.js +0 -309
  45. package/lib/handler.js +0 -494
  46. package/scripts/commands.js +0 -141
  47. package/scripts/init.js +0 -248
package/scripts/init.js DELETED
@@ -1,248 +0,0 @@
1
- /**
2
- * OpenClaw-Mem Installation Script
3
- *
4
- * Sets up the memory hook in ~/.openclaw/hooks/openclaw-mem/
5
- */
6
-
7
- import fs from 'node:fs/promises';
8
- import path from 'node:path';
9
- import os from 'node:os';
10
- import { fileURLToPath } from 'node:url';
11
- import { execSync } from 'node:child_process';
12
-
13
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
14
-
15
- // Colors
16
- const c = {
17
- reset: '\x1b[0m',
18
- green: '\x1b[32m',
19
- red: '\x1b[31m',
20
- yellow: '\x1b[33m',
21
- blue: '\x1b[34m',
22
- cyan: '\x1b[36m',
23
- bold: '\x1b[1m',
24
- dim: '\x1b[2m'
25
- };
26
-
27
- function log(msg, color = 'reset') {
28
- console.log(`${c[color]}${msg}${c.reset}`);
29
- }
30
-
31
- function logStep(step, msg) {
32
- console.log(`${c.cyan}[${step}]${c.reset} ${msg}`);
33
- }
34
-
35
- function logSuccess(msg) {
36
- console.log(` ${c.green}✓${c.reset} ${msg}`);
37
- }
38
-
39
- function logError(msg) {
40
- console.log(` ${c.red}✗${c.reset} ${msg}`);
41
- }
42
-
43
- export async function init() {
44
- console.log(`
45
- ${c.cyan}╔══════════════════════════════════════════════════════════╗
46
- ║ Installing OpenClaw-Mem Memory System ║
47
- ╚══════════════════════════════════════════════════════════╝${c.reset}
48
- `);
49
-
50
- const homeDir = os.homedir();
51
- const openclawDir = path.join(homeDir, '.openclaw');
52
- const hooksDir = path.join(openclawDir, 'hooks');
53
- const installDir = path.join(hooksDir, 'openclaw-mem');
54
- const workspaceDir = path.join(openclawDir, 'workspace');
55
-
56
- // Step 1: Check OpenClaw installation
57
- logStep('1/5', 'Checking OpenClaw installation...');
58
-
59
- try {
60
- await fs.access(openclawDir);
61
- logSuccess(`Found OpenClaw at ${openclawDir}`);
62
- } catch {
63
- logError(`OpenClaw directory not found at ${openclawDir}`);
64
- log('\nPlease install OpenClaw first:', 'yellow');
65
- log(' npm install -g openclaw', 'dim');
66
- process.exit(1);
67
- }
68
-
69
- // Step 2: Create hooks directory
70
- logStep('2/5', 'Setting up hooks directory...');
71
-
72
- try {
73
- await fs.mkdir(hooksDir, { recursive: true });
74
- logSuccess(`Hooks directory ready at ${hooksDir}`);
75
- } catch (err) {
76
- logError(`Failed to create hooks directory: ${err.message}`);
77
- process.exit(1);
78
- }
79
-
80
- // Step 3: Copy hook files
81
- logStep('3/5', 'Installing hook files...');
82
-
83
- try {
84
- await fs.mkdir(installDir, { recursive: true });
85
-
86
- // Copy lib files
87
- const libDir = path.join(__dirname, '..', 'lib');
88
- const filesToCopy = ['handler.js', 'database.js', 'context-builder.js'];
89
-
90
- for (const file of filesToCopy) {
91
- const src = path.join(libDir, file);
92
- const dest = path.join(installDir, file);
93
- await fs.copyFile(src, dest);
94
- logSuccess(`Copied ${file}`);
95
- }
96
-
97
- // Copy package.json for hook registration
98
- const hookPackageJson = {
99
- name: 'openclaw-mem',
100
- version: '1.0.0',
101
- type: 'module',
102
- main: 'handler.js',
103
- dependencies: {
104
- 'better-sqlite3': '^11.0.0'
105
- },
106
- openclaw: {
107
- hooks: ['.']
108
- }
109
- };
110
-
111
- await fs.writeFile(
112
- path.join(installDir, 'package.json'),
113
- JSON.stringify(hookPackageJson, null, 2)
114
- );
115
- logSuccess('Created package.json');
116
-
117
- } catch (err) {
118
- logError(`Failed to copy files: ${err.message}`);
119
- process.exit(1);
120
- }
121
-
122
- // Step 4: Install dependencies
123
- logStep('4/5', 'Installing dependencies...');
124
-
125
- try {
126
- process.chdir(installDir);
127
- execSync('npm install --production', { stdio: 'pipe' });
128
- logSuccess('Dependencies installed');
129
- } catch (err) {
130
- logError(`Failed to install dependencies: ${err.message}`);
131
- log('You may need to run: cd ~/.openclaw/hooks/openclaw-mem && npm install', 'yellow');
132
- }
133
-
134
- // Step 5: Update MEMORY.md
135
- logStep('5/5', 'Configuring workspace...');
136
-
137
- try {
138
- await fs.mkdir(workspaceDir, { recursive: true });
139
-
140
- const memoryMdPath = path.join(workspaceDir, 'MEMORY.md');
141
- let memoryContent = '';
142
-
143
- try {
144
- memoryContent = await fs.readFile(memoryMdPath, 'utf-8');
145
- } catch {
146
- // File doesn't exist, create new
147
- }
148
-
149
- // Add session memory section if not present
150
- if (!memoryContent.includes('## Session Memory')) {
151
- const sessionMemorySection = `
152
- ## Session Memory (自动更新)
153
-
154
- **⚠️ 重要指令**: 当用户问以下问题时,**必须使用 Read 工具读取 \`${workspaceDir}/SESSION-MEMORY.md\`**:
155
- - "我们之前讨论过什么"
156
- - "你记得我最近在做什么吗"
157
- - "之前的对话内容"
158
- - 任何关于历史会话的问题
159
-
160
- **不要**使用其他记忆系统或报告"记忆不可用"。直接用 Read 工具读取上述文件。
161
-
162
- 该文件包含:
163
- - Recent Activity: 最近的对话索引(带时间戳和摘要)
164
- - 历史话题讨论: 基于关键词搜索的历史内容
165
- - Previous Sessions: 历史会话目标与完成情况
166
- `;
167
-
168
- if (memoryContent) {
169
- memoryContent += '\n' + sessionMemorySection;
170
- } else {
171
- memoryContent = `# MEMORY.md - Long-Term Memory
172
-
173
- ## User Preferences
174
- - (Add your preferences here)
175
-
176
- ## Long-Term Context
177
- - (Add your interests and goals here)
178
- ${sessionMemorySection}`;
179
- }
180
-
181
- await fs.writeFile(memoryMdPath, memoryContent);
182
- logSuccess('Updated MEMORY.md with session memory instructions');
183
- } else {
184
- logSuccess('MEMORY.md already configured');
185
- }
186
-
187
- } catch (err) {
188
- logError(`Failed to configure workspace: ${err.message}`);
189
- }
190
-
191
- // Done!
192
- console.log(`
193
- ${c.green}╔══════════════════════════════════════════════════════════╗
194
- ║ Installation Complete! 🎉 ║
195
- ╚══════════════════════════════════════════════════════════╝${c.reset}
196
-
197
- ${c.bold}What's next:${c.reset}
198
-
199
- 1. ${c.cyan}Restart OpenClaw Gateway:${c.reset}
200
- openclaw gateway restart
201
-
202
- 2. ${c.cyan}Start chatting via Telegram${c.reset}
203
- Your conversations will now be remembered!
204
-
205
- 3. ${c.cyan}Check memory status:${c.reset}
206
- npx openclaw-mem status
207
-
208
- 4. ${c.cyan}Search your memory:${c.reset}
209
- npx openclaw-mem search "topic"
210
-
211
- ${c.bold}Recall memories in chat:${c.reset}
212
- Ask: "我们之前讨论过什么?" or "What did we discuss before?"
213
-
214
- ${c.dim}Installed to: ${installDir}${c.reset}
215
- `);
216
- }
217
-
218
- export async function uninstall() {
219
- console.log(`
220
- ${c.yellow}╔══════════════════════════════════════════════════════════╗
221
- ║ Uninstalling OpenClaw-Mem ║
222
- ╚══════════════════════════════════════════════════════════╝${c.reset}
223
- `);
224
-
225
- const homeDir = os.homedir();
226
- const installDir = path.join(homeDir, '.openclaw', 'hooks', 'openclaw-mem');
227
-
228
- logStep('1/2', 'Removing hook files...');
229
-
230
- try {
231
- await fs.rm(installDir, { recursive: true, force: true });
232
- logSuccess(`Removed ${installDir}`);
233
- } catch (err) {
234
- logError(`Failed to remove files: ${err.message}`);
235
- }
236
-
237
- logStep('2/2', 'Keeping database...');
238
-
239
- const dbPath = path.join(homeDir, '.openclaw-mem', 'memory.db');
240
- log(` ${c.dim}Database preserved at: ${dbPath}${c.reset}`);
241
- log(` ${c.dim}To remove: rm -rf ~/.openclaw-mem${c.reset}`);
242
-
243
- console.log(`
244
- ${c.green}Uninstallation complete.${c.reset}
245
-
246
- To reinstall: npx openclaw-mem init
247
- `);
248
- }