ultra-memory 3.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/CLAWHUB.md +190 -0
- package/LICENSE +21 -0
- package/README.md +195 -0
- package/SKILL.md +383 -0
- package/package.json +107 -0
- package/platform/SYSTEM_PROMPT.md +184 -0
- package/platform/__pycache__/server.cpython-313.pyc +0 -0
- package/platform/openapi.yaml +305 -0
- package/platform/server.py +454 -0
- package/platform/tools_gemini.json +176 -0
- package/platform/tools_openai.json +207 -0
- package/scripts/__pycache__/cleanup.cpython-313.pyc +0 -0
- package/scripts/__pycache__/export.cpython-313.pyc +0 -0
- package/scripts/__pycache__/extract_entities.cpython-313.pyc +0 -0
- package/scripts/__pycache__/init.cpython-313.pyc +0 -0
- package/scripts/__pycache__/log_op.cpython-313.pyc +0 -0
- package/scripts/__pycache__/recall.cpython-313.pyc +0 -0
- package/scripts/__pycache__/restore.cpython-313.pyc +0 -0
- package/scripts/__pycache__/summarize.cpython-313.pyc +0 -0
- package/scripts/cleanup.py +156 -0
- package/scripts/export.py +158 -0
- package/scripts/extract_entities.py +289 -0
- package/scripts/init.py +243 -0
- package/scripts/log_op.py +328 -0
- package/scripts/mcp-server.js +341 -0
- package/scripts/recall.py +683 -0
- package/scripts/restore.py +267 -0
- package/scripts/summarize.py +389 -0
package/CLAWHUB.md
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# ClawHub 提交指南
|
|
2
|
+
|
|
3
|
+
> ultra-memory v3.0.0 — 超长会话记忆 Skill for OpenClaw / Claude Code / 所有 LLM 平台
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 快速安装
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx clawhub@latest install ultra-memory
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
安装完成后 OpenClaw 会自动识别 `SKILL.md`,无需额外配置。
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## 发布到 npm(ClawHub 自动索引)
|
|
18
|
+
|
|
19
|
+
### 前提条件
|
|
20
|
+
|
|
21
|
+
- Node.js 18+
|
|
22
|
+
- npm account(免费):https://www.npmjs.com/signup
|
|
23
|
+
|
|
24
|
+
### 发布步骤
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# 1. 进入项目目录
|
|
28
|
+
cd ultra-memory
|
|
29
|
+
|
|
30
|
+
# 2. 登录 npm
|
|
31
|
+
npm login
|
|
32
|
+
# 输入用户名、密码、邮箱
|
|
33
|
+
|
|
34
|
+
# 3. 发布(首次发布用 latest,后续用 patch/minor/major)
|
|
35
|
+
npm publish
|
|
36
|
+
|
|
37
|
+
# 4. 验证发布成功
|
|
38
|
+
npm view ultra-memory
|
|
39
|
+
|
|
40
|
+
# 5. ClawHub 大约 5-10 分钟后自动索引
|
|
41
|
+
npx clawhub@latest install ultra-memory
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 发布后验证
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# 检查版本
|
|
48
|
+
npm view ultra-memory version
|
|
49
|
+
|
|
50
|
+
# 检查文件是否完整
|
|
51
|
+
npm pack ultra-memory
|
|
52
|
+
tar -tzf ultra-memory-*.tgz | head -20
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## 提交信息
|
|
58
|
+
|
|
59
|
+
### ClawHub 标题
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
ultra-memory — 超长会话记忆系统
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### 简短描述(≤ 120 字符)
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
5层记忆架构 · 零外部依赖 · 自动提取函数/决策/错误 · 跨语言检索 · 支持所有LLM平台
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 完整描述
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
ultra-memory 给 AI Agent 提供不遗忘、可检索、跨会话持久化的记忆能力。
|
|
75
|
+
|
|
76
|
+
核心功能:
|
|
77
|
+
• 5层记忆架构:操作日志 → 摘要 → 语义 → 实体索引 → 向量语义
|
|
78
|
+
• 零外部依赖:纯 Python stdlib,可选 sentence-transformers 增强
|
|
79
|
+
• 结构化实体:自动提取函数、文件、依赖、决策、错误、类
|
|
80
|
+
• 分层压缩:O(log n) 上下文增长,永不爆 context window
|
|
81
|
+
• 跨语言检索:中英文同义词双向映射("数据清洗" ↔ "clean_df")
|
|
82
|
+
• 全平台支持:MCP Server / REST API / Claude Code Skill / OpenClaw
|
|
83
|
+
|
|
84
|
+
适用场景:长编码任务、写长篇小说、跨天继续工作、精确回忆操作细节
|
|
85
|
+
开发者:NanJingYa
|
|
86
|
+
许可:MIT
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 关键词(npm keywords)
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
ai memory long-context claude openclaw mcp llm session-memory
|
|
93
|
+
semantic-search ultra-memory agent-memory context-window
|
|
94
|
+
mem0-alternative openai gemini qwen
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## ClawHub 平台信息
|
|
100
|
+
|
|
101
|
+
| 字段 | 内容 |
|
|
102
|
+
|------|------|
|
|
103
|
+
| **名称** | ultra-memory |
|
|
104
|
+
| **版本** | 3.0.0 |
|
|
105
|
+
| **格式** | AgentSkill Bundle(SKILL.md + scripts/) |
|
|
106
|
+
| **安装命令** | `npx clawhub@latest install ultra-memory` |
|
|
107
|
+
| **npm 包** | https://www.npmjs.com/package/ultra-memory |
|
|
108
|
+
| **源码** | https://github.com/nanjingya/ultra-memory |
|
|
109
|
+
| **开发者** | NanJingYa |
|
|
110
|
+
| **许可** | MIT |
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## 触发词(中英文双语)
|
|
115
|
+
|
|
116
|
+
**必须触发的场景:**
|
|
117
|
+
- "记住" / "别忘了" / "上次我们做了什么" / "回忆"
|
|
118
|
+
- "don't forget" / "remember this" / "what did we do" / "recall"
|
|
119
|
+
- "继续昨天的任务" / "接着上次做" / "跨会话"
|
|
120
|
+
- 操作数超过 30 条,context 使用率逼近阈值
|
|
121
|
+
|
|
122
|
+
**不触发场景:**
|
|
123
|
+
- 单次简短问答("帮我写个正则")
|
|
124
|
+
- 纯代码补全、文件格式转换等无状态任务
|
|
125
|
+
- 用户明确说"不用记录"
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## 技术规格
|
|
130
|
+
|
|
131
|
+
| 项目 | 值 |
|
|
132
|
+
|------|------|
|
|
133
|
+
| Python 版本 | ≥ 3.8 |
|
|
134
|
+
| Node.js 版本 | ≥ 18(仅 MCP Server 模式需要) |
|
|
135
|
+
| 依赖 | **零硬性依赖**(纯 stdlib) |
|
|
136
|
+
| 可选依赖 | sklearn(TF-IDF 增强)、sentence-transformers(向量语义) |
|
|
137
|
+
| 存储格式 | JSONL + Markdown + JSON |
|
|
138
|
+
| 默认存储 | `~/.ultra-memory/` |
|
|
139
|
+
| MCP 工具数 | 9 个 |
|
|
140
|
+
| 记忆层数 | 5 层 |
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## ClawHub 平台要求确认清单
|
|
145
|
+
|
|
146
|
+
- [x] `package.json` 存在,包含 name/version/description/author
|
|
147
|
+
- [x] `SKILL.md` 存在,包含 YAML frontmatter (name + description)
|
|
148
|
+
- [x] 触发词已在 SKILL.md frontmatter 的 description 中声明
|
|
149
|
+
- [x] README.md 存在,说明安装和使用方式
|
|
150
|
+
- [x] npm publish 后 ClawHub 自动索引(无需额外提交到 ClawHub 平台)
|
|
151
|
+
- [x] 开发者信息:NanJingYa(无其他贡献者)
|
|
152
|
+
- [x] MIT License 文件存在或 package.json 中声明
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## 维护指南
|
|
157
|
+
|
|
158
|
+
### 发布新版本
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
# 1. 更新版本号
|
|
162
|
+
# patch: bug修复 → npm version patch
|
|
163
|
+
# minor: 新功能 → npm version minor
|
|
164
|
+
# major: 破坏性变更 → npm version major
|
|
165
|
+
npm version patch
|
|
166
|
+
|
|
167
|
+
# 2. 发布
|
|
168
|
+
npm publish
|
|
169
|
+
|
|
170
|
+
# 3. ClawHub 自动更新(通常 5-10 分钟)
|
|
171
|
+
npx clawhub@latest install ultra-memory
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### 版本号规范
|
|
175
|
+
|
|
176
|
+
遵循 [Semantic Versioning](https://semver.org/):
|
|
177
|
+
- **3.0.0** — 初始正式版(MCP + REST + 5层架构 + TF-IDF)
|
|
178
|
+
- 未来:3.1.0(bug修复)、4.0.0(破坏性变更)
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## 联系开发者
|
|
183
|
+
|
|
184
|
+
- GitHub Issues: https://github.com/nanjingya/ultra-memory/issues
|
|
185
|
+
- 源码:https://github.com/nanjingya/ultra-memory
|
|
186
|
+
- 开发者:NanJingYa
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
*本文件供 ClawHub 提交参考,npm 发布后 ClawHub 会自动索引,无需额外操作。*
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 NanJingYa
|
|
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,195 @@
|
|
|
1
|
+
# ultra-memory
|
|
2
|
+
|
|
3
|
+
> **超长会话记忆系统** — 给 AI Agent 提供不遗忘、可检索、跨会话持久化的记忆能力。
|
|
4
|
+
> 零外部依赖,支持所有 LLM 平台:Claude Code、OpenClaw、GPT-4、Gemini、Qwen 等。
|
|
5
|
+
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
[](https://www.python.org/)
|
|
8
|
+
[](https://nodejs.org/)
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 核心特性
|
|
13
|
+
|
|
14
|
+
| 特性 | 说明 |
|
|
15
|
+
|------|------|
|
|
16
|
+
| **5 层记忆架构** | ops 日志 → 摘要 → 语义 → 实体索引 → 向量语义 |
|
|
17
|
+
| **零外部依赖** | 纯 Python stdlib + 可选增强 |
|
|
18
|
+
| **结构化实体** | 自动提取函数/文件/依赖/决策/错误/类,精确召回 |
|
|
19
|
+
| **分层压缩** | O(log n) 上下文增长,永不爆 context |
|
|
20
|
+
| **跨语言检索** | 中英文同义词双向映射("数据清洗" ↔ "clean_df") |
|
|
21
|
+
| **全平台支持** | MCP Server / REST API / Claude Code Skill |
|
|
22
|
+
| **自动时间权重** | 越新的记忆权重越高,24h 半衰期 |
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## 安装
|
|
27
|
+
|
|
28
|
+
### OpenClaw(推荐)
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npx clawhub@latest install ultra-memory
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
或在 OpenClaw Settings → MCP Servers 添加:
|
|
35
|
+
|
|
36
|
+
```json
|
|
37
|
+
{
|
|
38
|
+
"mcpServers": {
|
|
39
|
+
"ultra-memory": {
|
|
40
|
+
"command": "node",
|
|
41
|
+
"args": ["$(npm root -g)/ultra-memory/scripts/mcp-server.js"]
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Claude Code
|
|
48
|
+
|
|
49
|
+
将 `SKILL.md` 内容复制到项目根目录,或配置 skill 路径。
|
|
50
|
+
|
|
51
|
+
### 任意 LLM 平台(REST API)
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
# 启动 REST 服务器
|
|
55
|
+
py -3 platform/server.py --port 3200
|
|
56
|
+
|
|
57
|
+
# 验证
|
|
58
|
+
curl http://127.0.0.1:3200/health
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
加载 `platform/tools_openai.json` 工具定义,工具调用转发到 `POST http://127.0.0.1:3200/tools/{name}`。
|
|
62
|
+
|
|
63
|
+
### npm 安装
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
npm install -g ultra-memory
|
|
67
|
+
ultra-memory # 启动 MCP Server
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## 架构:5 层记忆模型
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
┌─────────────────────────────────────────────────────────┐
|
|
76
|
+
│ Layer 5: 向量语义层 (TF-IDF / sentence-transformers) │
|
|
77
|
+
│ 模糊召回:"找情感相似的段落" │
|
|
78
|
+
├─────────────────────────────────────────────────────────┤
|
|
79
|
+
│ Layer 4: 结构化实体索引 (entities.jsonl) │
|
|
80
|
+
│ 精确召回:"用过的函数"、"做过的决策"、"报过的错" │
|
|
81
|
+
├─────────────────────────────────────────────────────────┤
|
|
82
|
+
│ Layer 3: 跨会话语义层 (semantic/) │
|
|
83
|
+
│ 知识库 · 用户偏好 · 项目索引 │
|
|
84
|
+
├─────────────────────────────────────────────────────────┤
|
|
85
|
+
│ Layer 2: 会话摘要层 (summary.md) │
|
|
86
|
+
│ 里程碑 · 关键决策 · 进行中任务 │
|
|
87
|
+
├─────────────────────────────────────────────────────────┤
|
|
88
|
+
│ Layer 1: 操作日志层 (ops.jsonl) ← 核心差异化 │
|
|
89
|
+
│ 每步操作append-only · 时间权重 · 上下文窗口 │
|
|
90
|
+
└─────────────────────────────────────────────────────────┘
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## 工具接口
|
|
96
|
+
|
|
97
|
+
| 工具 | 功能 |
|
|
98
|
+
|------|------|
|
|
99
|
+
| `memory_init` | 初始化会话,创建三层记忆结构 |
|
|
100
|
+
| `memory_log` | 记录操作(自动提取实体) |
|
|
101
|
+
| `memory_recall` | 5 层统一检索 |
|
|
102
|
+
| `memory_summarize` | 触发摘要压缩(含元压缩) |
|
|
103
|
+
| `memory_restore` | 恢复上次会话上下文 |
|
|
104
|
+
| `memory_profile` | 读写用户画像 |
|
|
105
|
+
| `memory_status` | 查询会话状态与 context 压力 |
|
|
106
|
+
| `memory_entities` | 查询结构化实体索引 |
|
|
107
|
+
| `memory_extract_entities` | 全量重提取实体 |
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## 使用示例
|
|
112
|
+
|
|
113
|
+
### 场景 1:长编码任务不丢失上下文
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
用户: 帮我开发一个 Python 数据清洗工具
|
|
117
|
+
|
|
118
|
+
Claude: [ultra-memory] 会话已创建,开始记录每次操作...
|
|
119
|
+
你之前做过 ai-data-qa 项目,我们可以复用那里的评分逻辑。
|
|
120
|
+
...(50条操作后)...
|
|
121
|
+
Claude: [自动摘要压缩] 已完成:数据加载、清洗函数、单元测试。
|
|
122
|
+
当前进行中:导出模块。context 已优化,继续...
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### 场景 2:跨天继续任务
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
用户(第二天): 继续昨天的工作
|
|
129
|
+
|
|
130
|
+
Claude: [记忆恢复] 你昨天在开发数据清洗工具:
|
|
131
|
+
✅ 已完成:加载模块、clean_df()、基础测试
|
|
132
|
+
🔄 进行中:导出模块,写到一半
|
|
133
|
+
💡 下一步:继续 export.py 的 to_csv() 方法
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### 场景 3:精确回忆操作细节
|
|
137
|
+
|
|
138
|
+
```
|
|
139
|
+
用户: 之前那个处理空值的逻辑是怎么写的?
|
|
140
|
+
|
|
141
|
+
Claude: [检索 ops #23] 在 src/cleaner.py 的 clean_df() 中:
|
|
142
|
+
空值处理:字符串列填充 "",数值列填充 0。
|
|
143
|
+
代码在第 45-52 行。要展示吗?
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## 存储结构
|
|
149
|
+
|
|
150
|
+
```
|
|
151
|
+
~/.ultra-memory/ # 默认存储目录(可配置)
|
|
152
|
+
├── sessions/
|
|
153
|
+
│ └── <session_id>/
|
|
154
|
+
│ ├── ops.jsonl # Layer 1: 操作日志(append-only)
|
|
155
|
+
│ ├── summary.md # Layer 2: 会话摘要
|
|
156
|
+
│ ├── meta.json # 元数据
|
|
157
|
+
│ ├── tfidf_cache.json # Layer 5: TF-IDF 索引缓存
|
|
158
|
+
│ └── embed_cache.json # Layer 5: sentence-transformers 缓存
|
|
159
|
+
├── semantic/
|
|
160
|
+
│ ├── entities.jsonl # Layer 4: 结构化实体
|
|
161
|
+
│ ├── knowledge_base.jsonl # Layer 3: 知识库
|
|
162
|
+
│ ├── user_profile.json # 用户画像
|
|
163
|
+
│ └── session_index.json # 会话索引
|
|
164
|
+
└── archive/ # 归档会话(可配置)
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## 与主流方案对比
|
|
170
|
+
|
|
171
|
+
| 能力 | Claude Code | mem0 | MemGPT | ultra-memory |
|
|
172
|
+
|------|:-----------:|:----:|:------:|:-----------:|
|
|
173
|
+
| 零外部依赖 | ✅ | ❌ | ❌ | **✅** |
|
|
174
|
+
| 结构化实体 | ❌ | 部分 | ❌ | **✅** |
|
|
175
|
+
| 分层压缩 O(log n) | 实验性 | ❌ | 固定层 | **✅** |
|
|
176
|
+
| 向量语义搜索 | ❌ | ✅ | ❌ | **✅**(可选) |
|
|
177
|
+
| 跨语言检索 | ❌ | ⚠️ | ❌ | **✅** |
|
|
178
|
+
| 全平台支持 | ❌ | ⚠️ | ⚠️ | **✅** |
|
|
179
|
+
| Context 注入可控 | ❌ | ❌ | ❌ | **✅** top-K |
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## 开发者
|
|
184
|
+
|
|
185
|
+
**NanJingYa** — https://github.com/nanjingya
|
|
186
|
+
|
|
187
|
+
GitHub: https://github.com/nanjingya/ultra-memory
|
|
188
|
+
|
|
189
|
+
Issues: https://github.com/nanjingya/ultra-memory/issues
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## 许可
|
|
194
|
+
|
|
195
|
+
MIT License
|