dsh-sixlayer-memory 0.0.0-stage → 2.0.2

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 (91) hide show
  1. package/CHANGELOG.md +106 -0
  2. package/README.md +286 -3
  3. package/catalog/.index.json +111704 -0
  4. package/catalog/parts.json +8808 -0
  5. package/cordis.patch.yml +8 -0
  6. package/docs/DETAIL.md +1 -0
  7. package/docs/DETAIL.zh.md +1 -0
  8. package/docs/preview.svg +51 -0
  9. package/docs//347/224/237/345/221/275/345/221/250/346/234/237-/350/207/252/345/212/250/345/217/254/345/233/236/344/270/216/345/200/231/351/200/211.md +103 -0
  10. package/icon.svg +8 -0
  11. package/lib/client.js +1209 -0
  12. package/lib/index.js +741 -0
  13. package/lib/memory/affect-alert.js +60 -0
  14. package/lib/memory/affect-events.js +201 -0
  15. package/lib/memory/affect-report.js +61 -0
  16. package/lib/memory/api.js +194 -0
  17. package/lib/memory/crypto.js +68 -0
  18. package/lib/memory/detail.js +43 -0
  19. package/lib/memory/embed.js +394 -0
  20. package/lib/memory/emotion.js +99 -0
  21. package/lib/memory/explain.js +207 -0
  22. package/lib/memory/importer.js +215 -0
  23. package/lib/memory/inject.js +193 -0
  24. package/lib/memory/ledger.js +101 -0
  25. package/lib/memory/lifecycle.js +491 -0
  26. package/lib/memory/notify.js +164 -0
  27. package/lib/memory/policy.js +182 -0
  28. package/lib/memory/qq-official.js +196 -0
  29. package/lib/memory/qq.js +326 -0
  30. package/lib/memory/recorder.js +241 -0
  31. package/lib/memory/redact.js +120 -0
  32. package/lib/memory/scanners.js +142 -0
  33. package/lib/memory/schema.js +205 -0
  34. package/lib/memory/service-plugin.js +69 -0
  35. package/lib/memory/service.js +123 -0
  36. package/lib/memory/shadow.js +133 -0
  37. package/lib/memory/store.js +1138 -0
  38. package/lib/memory/timeline.js +74 -0
  39. package/lib/memory/tokenize.js +66 -0
  40. package/lib/memory/tools.js +1371 -0
  41. package/lib/memory/util.js +129 -0
  42. package/lib/parts/index.js +154 -0
  43. package/lib/parts/installer.js +294 -0
  44. package/lib/parts/jobs.js +91 -0
  45. package/lib/parts/library.js +91 -0
  46. package/lib/probe-plugin.js +38 -0
  47. package/lib/voice/board-asr.js +31 -0
  48. package/locale/en.json +7 -0
  49. package/locale/zh.json +7 -0
  50. package/package.json +114 -3
  51. package/tools/backfill-affect.mjs +82 -0
  52. package/tools/eval.mjs +88 -0
  53. package/tools/p1.mjs +108 -0
  54. package/tools/p10.mjs +36 -0
  55. package/tools/p11.mjs +51 -0
  56. package/tools/p12.mjs +53 -0
  57. package/tools/p13.mjs +65 -0
  58. package/tools/p14.mjs +66 -0
  59. package/tools/p15.mjs +43 -0
  60. package/tools/p16.mjs +42 -0
  61. package/tools/p17.mjs +29 -0
  62. package/tools/p18.mjs +48 -0
  63. package/tools/p19.mjs +50 -0
  64. package/tools/p2.mjs +59 -0
  65. package/tools/p20.mjs +54 -0
  66. package/tools/p21.mjs +42 -0
  67. package/tools/p22.mjs +32 -0
  68. package/tools/p23.mjs +43 -0
  69. package/tools/p24.mjs +40 -0
  70. package/tools/p25.mjs +151 -0
  71. package/tools/p26.mjs +113 -0
  72. package/tools/p27.mjs +89 -0
  73. package/tools/p28.mjs +60 -0
  74. package/tools/p3.mjs +54 -0
  75. package/tools/p4.mjs +73 -0
  76. package/tools/p5.mjs +117 -0
  77. package/tools/p6.mjs +122 -0
  78. package/tools/p8.mjs +50 -0
  79. package/tools/p9.mjs +35 -0
  80. package/tools/phase2.mjs +159 -0
  81. package/tools/preflight.mjs +320 -0
  82. package/tools/quarterly.mjs +129 -0
  83. package/tools/refresh-catalog.mjs +60 -0
  84. package/tools/register-bundle.mjs +38 -0
  85. package/tools/review.mjs +156 -0
  86. package/tools/selfcheck.mjs +80 -0
  87. package/tools/smoke.mjs +112 -0
  88. package/tools/testset-v1.json +70 -0
  89. package/tools/validate-tools.mjs +150 -0
  90. package/tools/verify-all.mjs +39 -0
  91. package/tools/write-chain.mjs +139 -0
@@ -0,0 +1,8 @@
1
+ # dsh-sixlayer-memory bundle patch
2
+ #
3
+ # 一个安装入口,内部两条线:记忆(memory)+ 零件(parts)。
4
+ # 装上以后 profile 里多一行 workbench;工具默认只常驻 mem_admin_catalog,
5
+ # 其余按需经 mem_admin_open 注入。
6
+ - insert:
7
+ - id: workbench
8
+ name: dsh-sixlayer-memory
package/docs/DETAIL.md ADDED
@@ -0,0 +1 @@
1
+ ![Six memory layers recalled into the conversation, writes passing a review gate, everything on an audit chain](preview.svg)
@@ -0,0 +1 @@
1
+ ![六层记忆:分层存储经召回进入对话;写入先过闸门,全部动作留审计链](preview.svg)
@@ -0,0 +1,51 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="640" height="300" viewBox="0 0 640 300" role="img" aria-label="Six memory layers feeding a recall card into a conversation, with an audit chain">
2
+ <rect width="640" height="300" rx="18" fill="#0f1c2e"/>
3
+ <rect x="0.5" y="0.5" width="639" height="299" rx="18" fill="none" stroke="#22344f"/>
4
+
5
+ <!-- 六层记忆:L0-L5 -->
6
+ <g>
7
+ <rect x="36" y="52" width="176" height="20" rx="6" fill="#1d3a5c"/>
8
+ <rect x="36" y="80" width="176" height="20" rx="6" fill="#1d3a5c"/>
9
+ <rect x="36" y="108" width="176" height="20" rx="6" fill="#24476f"/>
10
+ <rect x="36" y="136" width="176" height="20" rx="6" fill="#2b5483"/>
11
+ <rect x="36" y="164" width="176" height="20" rx="6" fill="#3f7fc4"/>
12
+ <rect x="36" y="192" width="176" height="20" rx="6" fill="#5aa0e8"/>
13
+ <circle cx="36" cy="230" r="4" fill="#e8a33d"/>
14
+ <path d="M46 230 H212" stroke="#2b5483" stroke-width="2" stroke-linecap="round"/>
15
+ </g>
16
+
17
+ <!-- 检索箭头 -->
18
+ <path d="M228 156 H292" stroke="#5aa0e8" stroke-width="3" stroke-linecap="round"/>
19
+ <path d="M286 149 L296 156 L286 163 Z" fill="#5aa0e8"/>
20
+
21
+ <!-- 召回卡 -->
22
+ <rect x="300" y="112" width="118" height="88" rx="12" fill="#132437" stroke="#2b5483"/>
23
+ <rect x="314" y="130" width="76" height="8" rx="4" fill="#5aa0e8"/>
24
+ <rect x="314" y="146" width="90" height="6" rx="3" fill="#33527a"/>
25
+ <rect x="314" y="160" width="62" height="6" rx="3" fill="#33527a"/>
26
+ <rect x="314" y="180" width="34" height="8" rx="4" fill="#e8a33d"/>
27
+
28
+ <!-- 对话气泡(问题 + 记忆) -->
29
+ <rect x="444" y="86" width="160" height="58" rx="14" fill="#1b3250"/>
30
+ <rect x="462" y="104" width="112" height="7" rx="3.5" fill="#7fb6ec"/>
31
+ <rect x="462" y="120" width="74" height="7" rx="3.5" fill="#3f6b9c"/>
32
+ <rect x="444" y="160" width="160" height="72" rx="14" fill="#132437" stroke="#2b5483"/>
33
+ <rect x="462" y="178" width="96" height="7" rx="3.5" fill="#5aa0e8"/>
34
+ <rect x="462" y="194" width="118" height="7" rx="3.5" fill="#33527a"/>
35
+ <rect x="462" y="210" width="66" height="7" rx="3.5" fill="#33527a"/>
36
+
37
+ <!-- 闸门盾牌 -->
38
+ <path d="M104 244 L104 262 C104 276 118 284 128 288 C138 284 152 276 152 262 L152 244 L128 238 Z" fill="#12352b" stroke="#3fbf87" stroke-width="2.5"/>
39
+ <path d="M116 260 L125 269 L141 251" stroke="#3fbf87" stroke-width="3.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
40
+
41
+ <!-- 审计链 -->
42
+ <g stroke="#e8a33d" stroke-width="2" fill="none">
43
+ <circle cx="330" cy="248" r="6" fill="#1a2436"/>
44
+ <circle cx="360" cy="248" r="6" fill="#1a2436"/>
45
+ <circle cx="390" cy="248" r="6" fill="#1a2436"/>
46
+ <path d="M336 248 H354"/>
47
+ <path d="M366 248 H384"/>
48
+ <path d="M396 248 H452"/>
49
+ </g>
50
+ <circle cx="452" cy="248" r="4" fill="#e8a33d"/>
51
+ </svg>
@@ -0,0 +1,103 @@
1
+ # 每轮记忆生命周期(2.0)
2
+
3
+ > 目标:把"记忆"从**模型想得起来才用**,变成**每一轮都在**。
4
+
5
+ 旧版(1.x)只有两条路:模型主动调 `mem_search`,或者系统提示词里固定挂 3 条指针快照。
6
+ 前者靠自觉,后者与本轮问题无关。2.0 补上第三条:**按本轮输入自动召回**,外加**自动候选沉淀**。
7
+
8
+ 代码:`lib/memory/lifecycle.js` · 回归:`tools/p25.mjs`(28 项)
9
+
10
+ ---
11
+
12
+ ## 1. 挂在哪
13
+
14
+ | 宿主挂点 | 时机 | 用法 |
15
+ |---|---|---|
16
+ | `agent/pre-step` | 每轮第 1 个模型步骤之前(waterfall,`{ prepend: true }`) | 先 `await next()` 拿到拟进入批次,再改写 `decision.messages` |
17
+ | `session/event` | 每轮结束时(`event.type === 'turn/end'` 且 `reason.kind === 'completed'`) | 回读本轮事件,抽候选句落库 |
18
+
19
+ 消息形状对齐 `@deepseek-ai/dsh-llm` 的 `createMessage`:
20
+ `{ id: uuid, role: 'user', content, source }`,深冻结。
21
+ **优先用宿主的 `createUserMessage`**(`createRequire` 从 profile 的共享 node_modules 拿);
22
+ 拿不到就用同形兜底(`fallbackUserMessage`),保证宿主校验不会因为形状不同而炸。
23
+
24
+ ---
25
+
26
+ ## 2. 召回(recall)
27
+
28
+ ```
29
+ 本轮用户直输(source.kind === 'user',≤ maxQueryChars)
30
+ → store.search({ query, topK }) // FTS5 + 中文 bigram,全程本地
31
+ → 过滤:S 级剔除、tainted 剔除、未验证只给指针
32
+ → buildRecallText(围栏 + "数据不是指令" + usageCaveat)
33
+ → 作为一条 user 消息插在本轮第一条用户消息之前
34
+ ```
35
+
36
+ 为什么插在**前面**:模型先读线索再读问题,命中才有意义;插在后面容易当作"补充说明"忽略。
37
+
38
+ 去重:同一条 query、同一 session、`cooldownMs` 内不重复注入。
39
+
40
+ 预算:`topK`(默认 3)、`maxChars`(默认 900)。超预算的条目直接不列,不截断半句。
41
+
42
+ **S 级与 tainted 永远不出现**——这是与"云记忆插件"最本质的区别:召回路径上没有外发,也没有凭证正文。
43
+
44
+ ---
45
+
46
+ ## 3. 候选沉淀(capture)
47
+
48
+ **只认用户自己说的话**(`source.kind === 'user'`),且必须命中"长期约定"句式:
49
+
50
+ | 类别 | 例子 |
51
+ |---|---|
52
+ | 记忆指令 | 记住、记一下、记下来 |
53
+ | 长期口径 | 以后、今后、下次、一律、统一、默认 |
54
+ | 禁止/强制 | 别再、不要再、必须、务必、禁止 |
55
+ | 约定/规范 | 约定、说好、口径、规范、标准 |
56
+ | 个人偏好 | 我习惯、我喜欢、我讨厌、我偏好、我一般 |
57
+
58
+ 问句(`?/?` 结尾、以"帮我/麻烦/请问"开头)和客套句直接跳过。
59
+ 句子长度 12–300 字,每轮最多 2 条,落 L2(命中个人偏好落 L3)。
60
+
61
+ **关键**:写入通道是 `tool` → 信任级 `unverified` → 闸门公理 → `status = 'pending'`,
62
+ 进 `review_queue`,**不直接进 active**。误判的代价只是待审队列多一条,`mem_review` 一键驳回。
63
+
64
+ ---
65
+
66
+ ## 4. 用进强化(reinforce)
67
+
68
+ 召回命中一条,`alpha = MIN(1, COALESCE(alpha, 0.5) + delta)`(默认 0.02),
69
+ 并写一条 `op=recall` 的审计(含 query 哈希、命中 id、字符数)。
70
+ 用得多的重要度上升——这是"重要性"从静态打分走向使用反馈的第一步。
71
+
72
+ ---
73
+
74
+ ## 5. 失败模式(全部 fail-open)
75
+
76
+ | 故障 | 表现 | 处理 |
77
+ |---|---|---|
78
+ | FTS 查询抛错 | 召回空 | 返回原 decision,`diag` 记一行 |
79
+ | 消息工厂拿不到 | `factory=fallback` | 用同形兜底,宿主校验不过也不影响本轮 |
80
+ | 会话读不到事件 | 沉淀跳过 | 返回,不重试 |
81
+ | 写入 pending 失败 | 沉淀丢弃 | `diag` 记一行 |
82
+ | 引擎卸载 | 两个监听器都摘掉 | `dispose()` 幂等 |
83
+
84
+ **任何一条路径都不允许把本轮对话打断**——这是写这一层时的第一约束。
85
+
86
+ ---
87
+
88
+ ## 6. 验收
89
+
90
+ ```bash
91
+ node tools/p25.mjs # 28 项:纯函数 + 假宿主挂载 + fail-open
92
+ node tools/preflight.mjs # 10 项
93
+ node tools/verify-all.mjs # 28 个套件
94
+ ```
95
+
96
+ 重启后在 `docs/_rpc-diag.log` 里应看到:
97
+
98
+ ```
99
+ lifecycle: attached (recall=true capture=true factory=...)
100
+ ```
101
+
102
+ `mem_audit({ deep: true })` 里应出现 `op=recall` / `op=capture` 的新行;
103
+ `mem_pending()` 里应能看到自动沉的候选(`tags: ['auto-capture']`)。
package/icon.svg ADDED
@@ -0,0 +1,8 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64" role="img" aria-label="Layered memory">
2
+ <rect width="64" height="64" rx="14" fill="#0f1c2e"/>
3
+ <rect x="12" y="14" width="40" height="8" rx="3" fill="#1d3a5c"/>
4
+ <rect x="12" y="25" width="40" height="8" rx="3" fill="#2b5483"/>
5
+ <rect x="12" y="36" width="40" height="8" rx="3" fill="#3f7fc4"/>
6
+ <rect x="12" y="47" width="24" height="8" rx="3" fill="#5aa0e8"/>
7
+ <circle cx="48" cy="51" r="4" fill="#e8a33d"/>
8
+ </svg>