ultra-memory 3.0.2 → 3.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/SKILL.md CHANGED
@@ -205,8 +205,14 @@ python3 <skill_dir>/scripts/mcp-server.js # 通过 MCP 调用 memory_profile
205
205
  - 发现了某个工具/库的使用技巧
206
206
  - 完成了一个可复用的代码模式
207
207
 
208
- **执行方式:**
209
- 追加写入 `~/.ultra-memory/semantic/knowledge_base.jsonl`,每行一条 JSON。
208
+ **执行方式 — 方式 A(MCP 工具,推荐):**
209
+ ```bash
210
+ # 通过 memory_knowledge_add MCP 工具写入
211
+ # 参数:title(必填,100字内)、content(必填,200字内)、project(可选)、tags(可选)
212
+ ```
213
+
214
+ **执行方式 — 方式 B(直接追加):**
215
+ 直接追加写入 `~/.ultra-memory/semantic/knowledge_base.jsonl`,每行一条 JSON。
210
216
 
211
217
  **knowledge_base.jsonl 格式:**
212
218
  ```json
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ultra-memory",
3
- "version": "3.0.2",
3
+ "version": "3.0.3",
4
4
  "description": "超长会话记忆系统 — 5层记忆架构,零外部依赖,支持所有LLM平台(Claude/GPT/Gemini/Qwen等)",
5
5
  "keywords": [
6
6
  "ai",
@@ -45,7 +45,8 @@
45
45
  "ultra-memory-log": "scripts/log_op.py",
46
46
  "ultra-memory-recall": "scripts/recall.py",
47
47
  "ultra-memory-summarize": "scripts/summarize.py",
48
- "ultra-memory-restore": "scripts/restore.py"
48
+ "ultra-memory-restore": "scripts/restore.py",
49
+ "ultra-memory-knowledge": "scripts/log_knowledge.py"
49
50
  },
50
51
  "scripts": {
51
52
  "test": "python3 test_e2e.py",
@@ -263,6 +263,19 @@ def tool_memory_extract_entities(body: dict) -> tuple[bool, str]:
263
263
  return _run_script("extract_entities.py", ["--session", session_id, "--all"])
264
264
 
265
265
 
266
+ def tool_memory_knowledge_add(body: dict) -> tuple[bool, str]:
267
+ title = body.get("title", "")
268
+ content = body.get("content", "")
269
+ if not title or not content:
270
+ return False, "缺少 title 或 content 参数"
271
+ project = body.get("project", "default")
272
+ tags = body.get("tags", [])
273
+ args = ["--title", title, "--content", content, "--project", project]
274
+ if tags:
275
+ args.extend(["--tags", ",".join(tags)])
276
+ return _run_script("log_knowledge.py", args)
277
+
278
+
266
279
  # ── 工具注册表 ────────────────────────────────────────────────────────────
267
280
 
268
281
  TOOL_HANDLERS = {
@@ -275,6 +288,7 @@ TOOL_HANDLERS = {
275
288
  "memory_profile": tool_memory_profile,
276
289
  "memory_entities": tool_memory_entities,
277
290
  "memory_extract_entities": tool_memory_extract_entities,
291
+ "memory_knowledge_add": tool_memory_knowledge_add,
278
292
  }
279
293
 
280
294
  TOOL_DESCRIPTIONS = {
@@ -287,6 +301,7 @@ TOOL_DESCRIPTIONS = {
287
301
  "memory_profile": "读写用户画像(技术栈、偏好)",
288
302
  "memory_entities": "查询结构化实体索引(函数/文件/依赖/决策/错误)",
289
303
  "memory_extract_entities": "对整个 ops.jsonl 全量重提取实体",
304
+ "memory_knowledge_add": "追加知识库条目(bug解决方案、技术选型、工具技巧、可复用代码模式)",
290
305
  }
291
306
 
292
307
 
@@ -171,6 +171,33 @@
171
171
  },
172
172
  "required": ["session_id"]
173
173
  }
174
+ },
175
+ {
176
+ "name": "memory_knowledge_add",
177
+ "description": "Append important information to the knowledge base for future retrieval. Use when: solving a tricky bug, making a key tech decision, discovering a tool usage tip, or completing a reusable code pattern.",
178
+ "parameters": {
179
+ "type": "OBJECT",
180
+ "properties": {
181
+ "title": {
182
+ "type": "STRING",
183
+ "description": "Knowledge title (max 100 chars)"
184
+ },
185
+ "content": {
186
+ "type": "STRING",
187
+ "description": "Knowledge content (max 200 chars)"
188
+ },
189
+ "project": {
190
+ "type": "STRING",
191
+ "description": "Associated project name (default: 'default')"
192
+ },
193
+ "tags": {
194
+ "type": "ARRAY",
195
+ "items": { "type": "STRING" },
196
+ "description": "Tag list (optional)"
197
+ }
198
+ },
199
+ "required": ["title", "content"]
200
+ }
174
201
  }
175
202
  ]
176
203
  }
@@ -203,5 +203,35 @@
203
203
  "required": ["session_id"]
204
204
  }
205
205
  }
206
+ },
207
+ {
208
+ "type": "function",
209
+ "function": {
210
+ "name": "memory_knowledge_add",
211
+ "description": "Append important information to the knowledge base (knowledge_base.jsonl) for future retrieval. Use when: solving a tricky bug (record problem + solution), making a key tech decision (record what was chosen and why), discovering a tool usage tip, or completing a reusable code pattern.",
212
+ "parameters": {
213
+ "type": "object",
214
+ "properties": {
215
+ "title": {
216
+ "type": "string",
217
+ "description": "Knowledge title (max 100 chars)"
218
+ },
219
+ "content": {
220
+ "type": "string",
221
+ "description": "Knowledge content (max 200 chars)"
222
+ },
223
+ "project": {
224
+ "type": "string",
225
+ "description": "Associated project name (default: 'default')"
226
+ },
227
+ "tags": {
228
+ "type": "array",
229
+ "items": { "type": "string" },
230
+ "description": "Tag list (optional)"
231
+ }
232
+ },
233
+ "required": ["title", "content"]
234
+ }
235
+ }
206
236
  }
207
237
  ]
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ ultra-memory: 知识库写入脚本
4
+ 将重要信息追加写入 semantic/knowledge_base.jsonl,供未来相似任务检索。
5
+ """
6
+
7
+ import os
8
+ import sys
9
+ import json
10
+ import argparse
11
+ from datetime import datetime, timezone
12
+ from pathlib import Path
13
+
14
+ if sys.stdout.encoding != "utf-8":
15
+ sys.stdout.reconfigure(encoding="utf-8")
16
+
17
+ ULTRA_MEMORY_HOME = Path(os.environ.get("ULTRA_MEMORY_HOME", Path.home() / ".ultra-memory"))
18
+
19
+
20
+ def log_knowledge(
21
+ title: str,
22
+ content: str,
23
+ project: str = "default",
24
+ tags: list = None,
25
+ ):
26
+ """追加一条知识库条目"""
27
+ semantic_dir = ULTRA_MEMORY_HOME / "semantic"
28
+ semantic_dir.mkdir(parents=True, exist_ok=True)
29
+ kb_file = semantic_dir / "knowledge_base.jsonl"
30
+
31
+ entry = {
32
+ "ts": datetime.now(timezone.utc).isoformat().replace("+00:00", "Z"),
33
+ "project": project,
34
+ "title": title[:100],
35
+ "content": content[:200],
36
+ "tags": tags or [],
37
+ }
38
+
39
+ with open(kb_file, "a", encoding="utf-8") as f:
40
+ f.write(json.dumps(entry, ensure_ascii=False) + "\n")
41
+
42
+ print(f"[ultra-memory] 知识库已写入: {title}")
43
+ return entry
44
+
45
+
46
+ if __name__ == "__main__":
47
+ parser = argparse.ArgumentParser(description="追加知识库条目")
48
+ parser.add_argument("--title", required=True, help="知识标题(100字内)")
49
+ parser.add_argument("--content", required=True, help="知识内容(200字内)")
50
+ parser.add_argument("--project", default="default", help="关联项目名")
51
+ parser.add_argument("--tags", default="", help="逗号分隔的标签")
52
+ args = parser.parse_args()
53
+
54
+ tags = [t.strip() for t in args.tags.split(",") if t.strip()]
55
+ log_knowledge(args.title, args.content, args.project, tags)
@@ -164,6 +164,20 @@ const TOOLS = [
164
164
  },
165
165
  required: ["session_id"]
166
166
  }
167
+ },
168
+ {
169
+ name: "memory_knowledge_add",
170
+ description: "将重要信息追加到知识库(knowledge_base.jsonl),供未来相似任务检索。适用场景:解决了一个棘手的 bug、做出了重要技术选型决策、发现了工具使用技巧、完成了一个可复用的代码模式",
171
+ inputSchema: {
172
+ type: "object",
173
+ properties: {
174
+ title: { type: "string", description: "知识标题(100字内)", maxLength: 100 },
175
+ content: { type: "string", description: "知识内容(200字内)", maxLength: 200 },
176
+ project: { type: "string", description: "关联项目名", default: "default" },
177
+ tags: { type: "array", items: { type: "string" }, description: "标签列表", default: [] }
178
+ },
179
+ required: ["title", "content"]
180
+ }
167
181
  }
168
182
  ];
169
183
 
@@ -291,6 +305,15 @@ function executeTool(name, input) {
291
305
  case "memory_extract_entities": {
292
306
  return runScript("extract_entities.py", ["--session", input.session_id, "--all"]);
293
307
  }
308
+ case "memory_knowledge_add": {
309
+ const args = [
310
+ "--title", input.title,
311
+ "--content", input.content,
312
+ "--project", input.project || "default",
313
+ "--tags", (input.tags || []).join(",")
314
+ ];
315
+ return runScript("log_knowledge.py", args);
316
+ }
294
317
  default:
295
318
  return { success: false, output: `未知工具: ${name}` };
296
319
  }