openclaw-mem 1.0.1 → 1.0.3

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/README.md CHANGED
@@ -5,6 +5,8 @@
5
5
  [![npm version](https://badge.fury.io/js/openclaw-mem.svg)](https://www.npmjs.com/package/openclaw-mem)
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
7
 
8
+ English | [中文](README_CN.md)
9
+
8
10
  OpenClaw-Mem automatically captures your conversations and makes them searchable, allowing your AI assistant to remember what you've discussed across sessions.
9
11
 
10
12
  ## ✨ Features
@@ -34,7 +36,6 @@ That's it! Start chatting and your conversations will be remembered.
34
36
 
35
37
  Ask your AI assistant:
36
38
  - "What did we discuss before?"
37
- - "我们之前讨论过什么?"
38
39
  - "What were we working on last time?"
39
40
  - "Remind me about the authentication issue"
40
41
 
@@ -55,22 +56,23 @@ npx openclaw-mem uninstall
55
56
  ## 🏗️ How It Works
56
57
 
57
58
  ```
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
- └───────────────┘ └──────────────────┘
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
+ +---------------+ +------------------+
74
76
  ```
75
77
 
76
78
  ### Event Flow
@@ -116,12 +118,12 @@ Add your preferences to `~/.openclaw/workspace/MEMORY.md`:
116
118
  - Current project: Building a chat application
117
119
  ```
118
120
 
119
- ### Topic Keywords
121
+ ### Dynamic Topic Detection
120
122
 
121
- The system automatically searches for these topic keywords:
122
- - AI/Machine Learning: `短期记忆`, `长期记忆`, `向量数据库`, `RAG`
123
- - Health/Fitness: `长寿`, `禁食`, `力量训练`, `有氧运动`
124
- - Programming: `Node.js`, `TypeScript`, `微服务`, `架构`
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
125
127
 
126
128
  ## 🔧 Troubleshooting
127
129
 
package/README_CN.md ADDED
@@ -0,0 +1,184 @@
1
+ # OpenClaw-Mem 🧠
2
+
3
+ > 为你的 OpenClaw AI 代理提供持久长期记忆
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
+ [English](README.md) | 中文
9
+
10
+ OpenClaw-Mem 自动捕获你的对话并使其可搜索,让你的 AI 助手能够记住跨会话讨论的内容。
11
+
12
+ ## ✨ 功能特性
13
+
14
+ - **🔄 自动记忆捕获** - 对话自动保存
15
+ - **🔍 全文搜索** - 搜索你的整个对话历史
16
+ - **📊 渐进式披露** - 分层上下文,高效使用 token
17
+ - **🎯 话题检测** - 自动按话题索引讨论内容
18
+ - **💾 本地存储** - 所有数据保存在你的机器上(SQLite)
19
+ - **⚡ 零配置** - 开箱即用
20
+
21
+ ## 🚀 快速开始
22
+
23
+ ```bash
24
+ # 一键安装和设置!
25
+ npx openclaw-mem init
26
+
27
+ # 重启 OpenClaw 网关
28
+ openclaw gateway restart
29
+ ```
30
+
31
+ 就这样!开始聊天,你的对话将被记住。
32
+
33
+ ## 📖 使用方法
34
+
35
+ ### 在聊天中回忆记忆
36
+
37
+ 询问你的 AI 助手:
38
+ - "我们之前讨论过什么?"
39
+ - "上次我们在做什么?"
40
+ - "提醒我关于认证问题的事"
41
+
42
+ ### CLI 命令
43
+
44
+ ```bash
45
+ # 查看记忆状态
46
+ npx openclaw-mem status
47
+
48
+ # 搜索记忆
49
+ npx openclaw-mem search "认证"
50
+ npx openclaw-mem search "AI 记忆"
51
+
52
+ # 卸载(保留数据库)
53
+ npx openclaw-mem uninstall
54
+ ```
55
+
56
+ ## 🏗️ 工作原理
57
+
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
+ | (持久存储) | | (注入上下文) |
75
+ +---------------+ +------------------+
76
+ ```
77
+
78
+ ### 事件流程
79
+
80
+ 1. **`gateway:startup`** - 初始化记忆数据库
81
+ 2. **`agent:bootstrap`** - 向新会话注入历史上下文
82
+ 3. **`command:new`** - 开始新对话时保存会话摘要
83
+
84
+ ### 渐进式披露
85
+
86
+ 为优化 token 使用,记忆按层级组织:
87
+
88
+ | 层级 | 内容 | Token 消耗 |
89
+ |------|------|-----------|
90
+ | 索引 | 所有观察的紧凑表格 | 低 |
91
+ | 话题 | 关键讨论摘要 | 中 |
92
+ | 详情 | 完整内容(按需) | 高 |
93
+
94
+ ## 📁 文件位置
95
+
96
+ | 文件 | 位置 | 用途 |
97
+ |------|------|------|
98
+ | 数据库 | `~/.openclaw-mem/memory.db` | 持久存储 |
99
+ | Hook | `~/.openclaw/hooks/openclaw-mem/` | 事件处理器 |
100
+ | 记忆上下文 | `~/.openclaw/workspace/SESSION-MEMORY.md` | 注入的上下文 |
101
+
102
+ ## ⚙️ 配置
103
+
104
+ ### 自定义 MEMORY.md
105
+
106
+ 在 `~/.openclaw/workspace/MEMORY.md` 中添加你的偏好:
107
+
108
+ ```markdown
109
+ ## 用户偏好
110
+ - 沟通风格:技术性且简洁
111
+ - 语言:中文
112
+
113
+ ## 长期上下文
114
+ - 正在做:AI 记忆系统
115
+ - 兴趣:机器学习、分布式系统
116
+
117
+ ## 当前关注
118
+ - 当前项目:构建聊天应用
119
+ ```
120
+
121
+ ### 动态话题检测
122
+
123
+ 系统自动从你的实际对话中提取话题:
124
+ - 频繁提及的概念会被自动检测
125
+ - 没有硬编码关键词 - 一切来自你的数据
126
+ - 话题随你的讨论内容变化
127
+
128
+ ## 🔧 故障排除
129
+
130
+ ### 记忆没有被回忆?
131
+
132
+ 1. **重启网关:**
133
+ ```bash
134
+ openclaw gateway restart
135
+ ```
136
+
137
+ 2. **检查 hook 是否安装:**
138
+ ```bash
139
+ ls ~/.openclaw/hooks/openclaw-mem/
140
+ ```
141
+
142
+ 3. **验证数据库有内容:**
143
+ ```bash
144
+ npx openclaw-mem status
145
+ ```
146
+
147
+ ### 搜索找不到结果?
148
+
149
+ - 尝试更简单的搜索词
150
+ - 检查拼写错误
151
+ - 使用实际对话中的关键词
152
+
153
+ ### 数据库问题?
154
+
155
+ ```bash
156
+ # 重置数据库(⚠️ 删除所有记忆)
157
+ rm ~/.openclaw-mem/memory.db
158
+ openclaw gateway restart
159
+ ```
160
+
161
+ ## 🤝 贡献
162
+
163
+ 欢迎贡献!请随时提交 Pull Request。
164
+
165
+ 1. Fork 仓库
166
+ 2. 创建你的功能分支 (`git checkout -b feature/amazing-feature`)
167
+ 3. 提交更改 (`git commit -m 'Add amazing feature'`)
168
+ 4. 推送到分支 (`git push origin feature/amazing-feature`)
169
+ 5. 打开 Pull Request
170
+
171
+ ## 📄 许可证
172
+
173
+ MIT 许可证 - 详见 [LICENSE](LICENSE)
174
+
175
+ ## 🙏 致谢
176
+
177
+ - 灵感来自 [claude-mem](https://github.com/anthropics/claude-mem)
178
+ - 为 [OpenClaw](https://openclaw.ai) 构建
179
+
180
+ ---
181
+
182
+ <p align="center">
183
+ 用 ❤️ 为 AI 社区制作
184
+ </p>
@@ -186,49 +186,63 @@ function buildRetrievalInstructions() {
186
186
  }
187
187
 
188
188
  /**
189
- * Build topic summaries from database search
189
+ * Build topic summaries from user's actual recorded concepts
190
+ * Dynamically extracts topics from what the user has discussed
190
191
  */
191
192
  function buildTopicSummaries() {
192
- // Key topics to search for (based on common interests)
193
- const topics = [
194
- { name: 'AI记忆系统', keywords: ['短期记忆', '长期记忆', 'AI记忆', '向量数据库', 'RAG'] },
195
- { name: '长寿与健身', keywords: ['长寿', '禁食', '热量限制', '力量训练', '有氧运动'] },
196
- { name: '编程技术', keywords: ['Node.js', 'TypeScript', '微服务', '架构'] }
197
- ];
198
-
199
- const sections = [];
200
-
201
- for (const topic of topics) {
202
- const topicResults = [];
203
- for (const kw of topic.keywords) {
204
- try {
205
- const results = database.searchObservations(kw, 2);
206
- for (const r of results) {
207
- // Avoid duplicates
208
- if (!topicResults.find(t => t.id === r.id)) {
209
- topicResults.push(r);
210
- }
211
- }
212
- } catch (e) {
213
- // Search might fail, continue
193
+ // Get all recent observations to extract actual concepts
194
+ const recentObs = database.getRecentObservations(null, 100);
195
+
196
+ // Extract and count concepts from user's actual data
197
+ const conceptCounts = {};
198
+ for (const obs of recentObs) {
199
+ if (obs.concepts) {
200
+ const concepts = obs.concepts.split(',').map(c => c.trim()).filter(c => c.length > 1);
201
+ for (const concept of concepts) {
202
+ // Skip generic tool names
203
+ if (['edit', 'bash', 'read', 'grep', 'write', 'glob'].includes(concept.toLowerCase())) continue;
204
+ conceptCounts[concept] = (conceptCounts[concept] || 0) + 1;
214
205
  }
215
206
  }
207
+ }
208
+
209
+ // Get top concepts (mentioned at least twice)
210
+ const topConcepts = Object.entries(conceptCounts)
211
+ .filter(([_, count]) => count >= 2)
212
+ .sort((a, b) => b[1] - a[1])
213
+ .slice(0, 10)
214
+ .map(([concept, _]) => concept);
215
+
216
+ if (topConcepts.length === 0) return '';
216
217
 
217
- if (topicResults.length > 0) {
218
- sections.push(`### ${topic.name}`);
219
- sections.push('');
220
- for (const r of topicResults.slice(0, 3)) {
221
- const summary = r.summary || '';
222
- if (summary.length > 30) {
223
- sections.push(`- **#${r.id}**: ${summary.slice(0, 150)}${summary.length > 150 ? '...' : ''}`);
218
+ const sections = [];
219
+ const seenIds = new Set();
220
+
221
+ // Search for each top concept
222
+ for (const concept of topConcepts.slice(0, 5)) {
223
+ try {
224
+ const results = database.searchObservations(concept, 3);
225
+ const newResults = results.filter(r => !seenIds.has(r.id));
226
+
227
+ if (newResults.length > 0) {
228
+ sections.push(`### ${concept}`);
229
+ sections.push('');
230
+ for (const r of newResults.slice(0, 2)) {
231
+ seenIds.add(r.id);
232
+ const summary = r.summary || '';
233
+ if (summary.length > 20) {
234
+ sections.push(`- **#${r.id}**: ${summary.slice(0, 150)}${summary.length > 150 ? '...' : ''}`);
235
+ }
224
236
  }
237
+ sections.push('');
225
238
  }
226
- sections.push('');
239
+ } catch (e) {
240
+ // Search might fail, continue
227
241
  }
228
242
  }
229
243
 
230
244
  if (sections.length > 0) {
231
- return '## 历史话题讨论\n\n' + sections.join('\n');
245
+ return '## 历史话题讨论\n\n基于您的实际对话自动提取的主题:\n\n' + sections.join('\n');
232
246
  }
233
247
  return '';
234
248
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclaw-mem",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Persistent memory system for OpenClaw - Give your AI agent long-term memory",
5
5
  "type": "module",
6
6
  "main": "lib/handler.js",
@@ -49,6 +49,7 @@
49
49
  "scripts/commands.js",
50
50
  "docs/",
51
51
  "README.md",
52
+ "README_CN.md",
52
53
  "LICENSE"
53
54
  ],
54
55
  "openclaw": {