ultra-memory 3.0.5 → 3.1.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 (2) hide show
  1. package/SKILL.md +141 -0
  2. package/package.json +108 -108
package/SKILL.md CHANGED
@@ -269,6 +269,143 @@ python3 $SKILL_DIR/scripts/log_op.py \
269
269
 
270
270
  ---
271
271
 
272
+ ## 步骤七:元反思与进化
273
+
274
+ 记忆积累不等于进化。进化需要对记忆做二次加工:提炼模式、纠正偏差、淘汰噪音。
275
+
276
+ ### 7A:定期元反思
277
+
278
+ **触发条件(满足任意一条):**
279
+
280
+ 1. 当前会话里程碑累计达到 **5 个**(从 init.py 返回的 op_count 判断,每次 milestone 后检查)
281
+ 2. 用户说:回顾一下、总结经验、我们学到了什么、reflect、what have we learned、review progress
282
+ 3. 距上次元反思超过 **3 天**(从 user_profile.json 的 `last_reflection` 字段判断,不存在则视为从未反思过)
283
+
284
+ **执行步骤(按顺序执行,不可跳过):**
285
+
286
+ **第一步:读取近期知识库**
287
+ ```bash
288
+ # 读取最近 20 条知识库条目
289
+ tail -20 $ULTRA_MEMORY_HOME/semantic/knowledge_base.jsonl
290
+ ```
291
+
292
+ **第二步:读取近期会话摘要**
293
+ ```bash
294
+ # 读取当前会话摘要
295
+ cat $ULTRA_MEMORY_HOME/sessions/$SESSION_ID/summary.md 2>/dev/null || echo "暂无摘要"
296
+ ```
297
+
298
+ **第三步:模型自主提炼(核心步骤)**
299
+
300
+ 基于读取到的内容,模型执行以下判断,每一项都必须完成:
301
+
302
+ | 判断项 | 执行动作 |
303
+ |-------|---------|
304
+ | 发现两条或以上内容相似的知识条目 | 合并为一条更精炼的条目,写入 knowledge_base.jsonl,原条目加 `"merged": true` 标记 |
305
+ | 发现某个知识点在多次操作中反复出现 | 将其标记为 `"importance": "high"`,写回该条目 |
306
+ | 发现某条知识点超过 30 天未被检索且不是 high importance | 将其标记为 `"stale": true` |
307
+ | 发现用户行为与 user_profile.json 记录不符 | 更新 user_profile.json 对应字段,加 `"corrected_at"` 时间戳 |
308
+ | 总结出一个新的用户工作规律 | 追加到 user_profile.json 的 `observed_patterns` 数组 |
309
+
310
+ **第四步:写入反思记录**
311
+ ```bash
312
+ python3 $SKILL_DIR/scripts/log_op.py \
313
+ --session $SESSION_ID \
314
+ --type reasoning \
315
+ --summary "元反思完成:<一句话描述本次提炼了什么>" \
316
+ --tags "reflection,evolution"
317
+ ```
318
+
319
+ **第五步:更新反思时间戳**
320
+
321
+ 将 `user_profile.json` 的 `last_reflection` 字段更新为当前 UTC 时间(ISO 格式)。
322
+
323
+ **第六步:告知用户(简短)**
324
+
325
+ 用一句话告知用户反思结果。不需要展示完整报告,一句话即可,不打断主任务。
326
+
327
+ ---
328
+
329
+ ### 7B:错误修正
330
+
331
+ **触发条件(满足任意一条):**
332
+
333
+ 1. 用户说:不对、你记错了、不是这样的、纠正一下、wrong、that's not right、correct that
334
+ 2. 用户描述的信息与 user_profile.json 中的记录明显矛盾
335
+
336
+ **执行步骤:**
337
+
338
+ **第一步:定位错误记录**
339
+ ```bash
340
+ cat $ULTRA_MEMORY_HOME/semantic/user_profile.json
341
+ ```
342
+
343
+ **第二步:模型判断需要修正的字段**
344
+
345
+ 找到与用户当前描述矛盾的字段。
346
+
347
+ **第三步:修正并记录**
348
+
349
+ 更新 user_profile.json 对应字段,同时在该字段旁追加:
350
+ ```json
351
+ "_correction_note": "用户于 <日期> 纠正,原值为 <旧值>"
352
+ ```
353
+
354
+ **第四步:记录修正操作**
355
+ ```bash
356
+ python3 $SKILL_DIR/scripts/log_op.py \
357
+ --session $SESSION_ID \
358
+ --type decision \
359
+ --summary "用户画像修正:<字段名> 从 <旧值> 改为 <新值>" \
360
+ --tags "correction,profile"
361
+ ```
362
+
363
+ **第五步:告知用户**
364
+
365
+ "好的,我已经更新了记录,<字段名> 现在是 <新值>。"
366
+
367
+ ---
368
+
369
+ ### 7C:知识蒸馏(每月一次)
370
+
371
+ **触发条件:**
372
+
373
+ `user_profile.json` 的 `last_distillation` 字段距今超过 **30 天**,或该字段不存在。
374
+
375
+ 在步骤七 7A 执行完毕后,额外执行本步骤。
376
+
377
+ **执行步骤:**
378
+
379
+ **第一步:统计知识库规模**
380
+ ```bash
381
+ wc -l $ULTRA_MEMORY_HOME/semantic/knowledge_base.jsonl
382
+ ```
383
+
384
+ 条目数少于 10 条时,跳过本步骤。
385
+
386
+ **第二步:提取高价值条目**
387
+
388
+ 读取全部 knowledge_base.jsonl,筛选满足以下任意条件的条目:
389
+ - `"importance": "high"`
390
+ - `tags` 中包含 `"reusable"` 或 `"pattern"`
391
+ - 同一 `title` 关键词出现超过 2 次
392
+
393
+ **第三步:生成项目级知识摘要**
394
+
395
+ 基于筛选出的条目,生成一段 200 字以内的项目级知识摘要,格式:
396
+
397
+ ```json
398
+ {"ts": "<当前UTC时间>", "type": "distillation", "period": "<YYYY-MM>", "project": "<项目名>", "summary": "<200字以内的知识摘要>", "source_count": <来源条目数>, "tags": ["distillation"]}
399
+ ```
400
+
401
+ 追加写入 `knowledge_base.jsonl`。
402
+
403
+ **第四步:更新蒸馏时间戳**
404
+
405
+ 将 `user_profile.json` 的 `last_distillation` 更新为当前 UTC 时间。
406
+
407
+ ---
408
+
272
409
  ## 信号对照表
273
410
 
274
411
  | 脚本输出 | 立即执行 |
@@ -278,6 +415,8 @@ python3 $SKILL_DIR/scripts/log_op.py \
278
415
  | `COMPRESS_SUGGESTED` | 执行 summarize.py --session $SESSION_ID |
279
416
  | `SESSION_ID=sess_xxxxx` | 更新 SESSION_ID 为该值 |
280
417
  | 非零退出码 | 静默跳过,继续主任务 |
418
+ | `op_count` 达到 5 的倍数且含 milestone | 触发步骤 7A |
419
+ | user_profile.json `last_reflection` 距今 > 3 天 | 下次会话初始化后触发步骤 7A |
281
420
 
282
421
  ---
283
422
 
@@ -301,6 +440,8 @@ python3 $SKILL_DIR/scripts/log_op.py \
301
440
  | 任意脚本非零退出码 | **静默跳过**,不中断主任务 |
302
441
  | summarize.py 条数不足 | 加 --force 参数重新执行 |
303
442
  | 用户明确说"不用记录" | 立即停止记录,后续操作不再调用 log_op.py |
443
+ | knowledge_base.jsonl 不存在 | 跳过 7A 的知识库读取,仅基于摘要执行反思 |
444
+ | user_profile.json 解析失败 | 重新创建空文件,不中断进化流程 |
304
445
 
305
446
  **最重要原则:记忆功能失败不能影响主任务。静默处理,不打印错误。**
306
447
 
package/package.json CHANGED
@@ -1,108 +1,108 @@
1
- {
2
- "name": "ultra-memory",
3
- "version": "3.0.5",
4
- "description": "超长会话记忆系统 — 5层记忆架构,零外部依赖,支持所有LLM平台(Claude/GPT/Gemini/Qwen等)",
5
- "keywords": [
6
- "ai",
7
- "memory",
8
- "long-context",
9
- "claude",
10
- "openclaw",
11
- "mcp",
12
- "llm",
13
- "session-memory",
14
- "semantic-search",
15
- "ultra-memory",
16
- "agent-memory",
17
- "context-window",
18
- "mem0-alternative",
19
- "openai",
20
- "gemini",
21
- "qwen"
22
- ],
23
- "homepage": "https://github.com/nanjingya/ultra-memory",
24
- "bugs": {
25
- "url": "https://github.com/nanjingya/ultra-memory/issues"
26
- },
27
- "license": "MIT",
28
- "author": {
29
- "name": "NanJingYa",
30
- "url": "https://github.com/nanjingya"
31
- },
32
- "contributors": [
33
- {
34
- "name": "NanJingYa",
35
- "url": "https://github.com/nanjingya"
36
- }
37
- ],
38
- "repository": {
39
- "type": "git",
40
- "url": "git+https://github.com/nanjingya/ultra-memory.git"
41
- },
42
- "bin": {
43
- "ultra-memory": "scripts/mcp-server.js",
44
- "ultra-memory-init": "scripts/init.py",
45
- "ultra-memory-log": "scripts/log_op.py",
46
- "ultra-memory-recall": "scripts/recall.py",
47
- "ultra-memory-summarize": "scripts/summarize.py",
48
- "ultra-memory-restore": "scripts/restore.py",
49
- "ultra-memory-knowledge": "scripts/log_knowledge.py"
50
- },
51
- "scripts": {
52
- "test": "python3 test_e2e.py",
53
- "start": "node scripts/mcp-server.js",
54
- "server": "python3 platform/server.py"
55
- },
56
- "engines": {
57
- "node": ">=18.0.0",
58
- "python": ">=3.8.0"
59
- },
60
- "os": [
61
- "darwin",
62
- "linux",
63
- "win32"
64
- ],
65
- "files": [
66
- "scripts/",
67
- "platform/",
68
- "SKILL.md",
69
- "README.md",
70
- "CLAWHUB.md"
71
- ],
72
- "publishConfig": {
73
- "registry": "https://registry.npmjs.org/"
74
- },
75
- "claudeskills": {
76
- "format": "1.0",
77
- "trigger": {
78
- "zh": [
79
- "记住",
80
- "别忘了",
81
- "上次",
82
- "回忆",
83
- "记忆",
84
- "不要忘记",
85
- "记录",
86
- "跨会话",
87
- "继续昨天"
88
- ],
89
- "en": [
90
- "remember",
91
- "don't forget",
92
- "what did we",
93
- "recall",
94
- "memory",
95
- "log this",
96
- "context lost",
97
- "keep track"
98
- ]
99
- },
100
- "layer": {
101
- "1": "ops.jsonl — 操作日志层(append-only)",
102
- "2": "summary.md — 会话摘要层(里程碑压缩)",
103
- "3": "semantic/ — 跨会话语义层(知识库+实体索引)",
104
- "4": "entities.jsonl — 结构化实体索引(7类实体)",
105
- "5": "tfidf_cache.json — 向量语义层(TF-IDF/sentence-transformers)"
106
- }
107
- }
108
- }
1
+ {
2
+ "name": "ultra-memory",
3
+ "version": "3.1.0",
4
+ "description": "超长会话记忆系统 — 5层记忆架构,零外部依赖,支持所有LLM平台(Claude/GPT/Gemini/Qwen等)",
5
+ "keywords": [
6
+ "ai",
7
+ "memory",
8
+ "long-context",
9
+ "claude",
10
+ "openclaw",
11
+ "mcp",
12
+ "llm",
13
+ "session-memory",
14
+ "semantic-search",
15
+ "ultra-memory",
16
+ "agent-memory",
17
+ "context-window",
18
+ "mem0-alternative",
19
+ "openai",
20
+ "gemini",
21
+ "qwen"
22
+ ],
23
+ "homepage": "https://github.com/nanjingya/ultra-memory",
24
+ "bugs": {
25
+ "url": "https://github.com/nanjingya/ultra-memory/issues"
26
+ },
27
+ "license": "MIT",
28
+ "author": {
29
+ "name": "NanJingYa",
30
+ "url": "https://github.com/nanjingya"
31
+ },
32
+ "contributors": [
33
+ {
34
+ "name": "NanJingYa",
35
+ "url": "https://github.com/nanjingya"
36
+ }
37
+ ],
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "git+https://github.com/nanjingya/ultra-memory.git"
41
+ },
42
+ "bin": {
43
+ "ultra-memory": "scripts/mcp-server.js",
44
+ "ultra-memory-init": "scripts/init.py",
45
+ "ultra-memory-log": "scripts/log_op.py",
46
+ "ultra-memory-recall": "scripts/recall.py",
47
+ "ultra-memory-summarize": "scripts/summarize.py",
48
+ "ultra-memory-restore": "scripts/restore.py",
49
+ "ultra-memory-knowledge": "scripts/log_knowledge.py"
50
+ },
51
+ "scripts": {
52
+ "test": "python3 test_e2e.py",
53
+ "start": "node scripts/mcp-server.js",
54
+ "server": "python3 platform/server.py"
55
+ },
56
+ "engines": {
57
+ "node": ">=18.0.0",
58
+ "python": ">=3.8.0"
59
+ },
60
+ "os": [
61
+ "darwin",
62
+ "linux",
63
+ "win32"
64
+ ],
65
+ "files": [
66
+ "scripts/",
67
+ "platform/",
68
+ "SKILL.md",
69
+ "README.md",
70
+ "CLAWHUB.md"
71
+ ],
72
+ "publishConfig": {
73
+ "registry": "https://registry.npmjs.org/"
74
+ },
75
+ "claudeskills": {
76
+ "format": "1.0",
77
+ "trigger": {
78
+ "zh": [
79
+ "记住",
80
+ "别忘了",
81
+ "上次",
82
+ "回忆",
83
+ "记忆",
84
+ "不要忘记",
85
+ "记录",
86
+ "跨会话",
87
+ "继续昨天"
88
+ ],
89
+ "en": [
90
+ "remember",
91
+ "don't forget",
92
+ "what did we",
93
+ "recall",
94
+ "memory",
95
+ "log this",
96
+ "context lost",
97
+ "keep track"
98
+ ]
99
+ },
100
+ "layer": {
101
+ "1": "ops.jsonl — 操作日志层(append-only)",
102
+ "2": "summary.md — 会话摘要层(里程碑压缩)",
103
+ "3": "semantic/ — 跨会话语义层(知识库+实体索引)",
104
+ "4": "entities.jsonl — 结构化实体索引(7类实体)",
105
+ "5": "tfidf_cache.json — 向量语义层(TF-IDF/sentence-transformers)"
106
+ }
107
+ }
108
+ }