dsh-memorytree-rule 0.0.0-stage → 1.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.
package/client.js ADDED
@@ -0,0 +1,227 @@
1
+ // dsh-memorytree-rule 的客户端半边:在 DSH 左侧栏加一个「记忆树」入口,
2
+ // 点开后在主区域用同源 iframe 打开插件的星图看板(写按钮仍走 /memory-tree/action)。
3
+ //
4
+ // 为什么用 iframe:看板本身是自包含 HTML(星图/主题/抽屉/按钮都在页内),
5
+ // 直接复用同一份 /memory-tree/board 产物,避免把 170 KB 的页面逻辑再翻译成 React;
6
+ // iframe 与宿主同源,看板里的令牌与写请求都照常工作。页面本身不调 LLM。
7
+
8
+ window.__ModuleLoader__.load({
9
+ id: "dsh-memorytree-rule",
10
+ factory(require) {
11
+ const React = require("react");
12
+ const h = React.createElement;
13
+ const { useEffect, useRef, useState } = React;
14
+
15
+ const PANEL_ID = "memory-tree";
16
+ const BOARD_PATH = "/memory-tree/board?panel=1";
17
+ const HEALTH_PATH = "/memory-tree/health";
18
+
19
+ function MemoryTreeIcon({ size = 18 }) {
20
+ const s = typeof size === "number" ? size : 18;
21
+ return h(
22
+ "svg",
23
+ {
24
+ viewBox: "0 0 24 24",
25
+ width: s,
26
+ height: s,
27
+ fill: "none",
28
+ stroke: "currentColor",
29
+ strokeWidth: 1.6,
30
+ strokeLinecap: "round",
31
+ strokeLinejoin: "round",
32
+ "aria-hidden": true,
33
+ style: { display: "block", flex: "none" },
34
+ },
35
+ h("path", { d: "M12 20v-7" }),
36
+ h("path", { d: "M12 13 6.5 8.8M12 13l5.5-4.2" }),
37
+ h("circle", { cx: 12, cy: 4.2, r: 1.7 }),
38
+ h("circle", { cx: 5.2, cy: 7.4, r: 1.5 }),
39
+ h("circle", { cx: 18.8, cy: 7.4, r: 1.5 }),
40
+ h("circle", { cx: 12, cy: 13, r: 1.8, fill: "currentColor", stroke: "none" }),
41
+ );
42
+ }
43
+
44
+ function ShellMessage({ title, detail }) {
45
+ return h(
46
+ "div",
47
+ {
48
+ style: {
49
+ height: "100%",
50
+ display: "flex",
51
+ alignItems: "center",
52
+ justifyContent: "center",
53
+ padding: 32,
54
+ color: "var(--dsw-alias-label-primary, #e8ecf5)",
55
+ background: "var(--dsw-alias-bg-base, #0b1020)",
56
+ font: "13px/1.7 system-ui, -apple-system, 'Segoe UI', sans-serif",
57
+ },
58
+ },
59
+ h(
60
+ "div",
61
+ { style: { maxWidth: 520 } },
62
+ h("div", { style: { fontSize: 16, fontWeight: 600, marginBottom: 8 } }, title),
63
+ h("div", { style: { color: "var(--dsw-alias-label-secondary, #9aa4b8)" } }, detail),
64
+ h(
65
+ "a",
66
+ {
67
+ href: BOARD_PATH,
68
+ target: "_blank",
69
+ rel: "noreferrer",
70
+ style: { display: "inline-block", marginTop: 16, color: "var(--dsw-alias-brand-primary, #6fb6ff)" },
71
+ },
72
+ "在新标签打开看板",
73
+ ),
74
+ ),
75
+ );
76
+ }
77
+
78
+ function MemoryTreePage() {
79
+ const [health, setHealth] = useState({ state: "checking" });
80
+ const [nonce, setNonce] = useState(0);
81
+ const wrapRef = useRef(null);
82
+
83
+ // DSH 主区域会把非当前面板留在 DOM 里;只 mount 一次的 iframe 会一直显示打开时的旧快照。
84
+ // 每次从隐藏变为可见时重载 iframe,保证「点开记忆树」看到的是当前库。
85
+ useEffect(() => {
86
+ const el = wrapRef.current;
87
+ if (!el || typeof IntersectionObserver === "undefined") return;
88
+ let first = true;
89
+ let visible = false;
90
+ const io = new IntersectionObserver(
91
+ (entries) => {
92
+ const now = entries.some((e) => e.isIntersecting);
93
+ if (now && !visible) {
94
+ if (!first) setNonce((n) => n + 1);
95
+ first = false;
96
+ }
97
+ visible = now;
98
+ },
99
+ { threshold: 0.01 },
100
+ );
101
+ io.observe(el);
102
+ return () => io.disconnect();
103
+ }, []);
104
+
105
+ useEffect(() => {
106
+ let alive = true;
107
+ let baseline = null;
108
+ let timer = null;
109
+
110
+ const check = () => {
111
+ fetch(HEALTH_PATH, { cache: "no-store" })
112
+ .then((res) => (res.ok ? res.json() : Promise.reject(new Error("HTTP " + res.status))))
113
+ .then((data) => {
114
+ if (!alive) return;
115
+ if (!data || data.ok !== true) {
116
+ setHealth({ state: "error", detail: "看板路由返回了异常状态。" });
117
+ return;
118
+ }
119
+ setHealth({ state: "ok" });
120
+ const version = data.indexVersion ?? data.total;
121
+ if (version === null || version === undefined) return;
122
+ if (baseline === null) {
123
+ baseline = version;
124
+ return;
125
+ }
126
+ if (version !== baseline) {
127
+ baseline = version;
128
+ setNonce((n) => n + 1);
129
+ }
130
+ })
131
+ .catch((err) => {
132
+ if (alive) setHealth({ state: "error", detail: String((err && err.message) || err) });
133
+ });
134
+ };
135
+
136
+ check();
137
+ timer = window.setInterval(check, 15000);
138
+ return () => {
139
+ alive = false;
140
+ if (timer) window.clearInterval(timer);
141
+ };
142
+ }, []);
143
+
144
+ if (health.state === "error") {
145
+ return h(ShellMessage, {
146
+ title: "记忆树看板暂不可用",
147
+ detail:
148
+ "没有连上本机的 /memory-tree 路由:" +
149
+ health.detail +
150
+ "。确认 dsh-memorytree-rule 插件已启用,然后重新加载 DSH 页面。",
151
+ });
152
+ }
153
+
154
+ return h(
155
+ "div",
156
+ {
157
+ ref: wrapRef,
158
+ style: {
159
+ position: "relative",
160
+ height: "100%",
161
+ minHeight: 0,
162
+ display: "flex",
163
+ background: "var(--dsw-alias-bg-base, #0b1020)",
164
+ },
165
+ },
166
+ health.state === "checking"
167
+ ? h(
168
+ "div",
169
+ {
170
+ style: {
171
+ position: "absolute",
172
+ inset: 0,
173
+ display: "flex",
174
+ alignItems: "center",
175
+ justifyContent: "center",
176
+ color: "var(--dsw-alias-label-secondary, #9aa4b8)",
177
+ font: "12px/1.5 system-ui, sans-serif",
178
+ pointerEvents: "none",
179
+ },
180
+ },
181
+ "正在打开记忆树看板…",
182
+ )
183
+ : null,
184
+ h("iframe", {
185
+ key: nonce,
186
+ src: BOARD_PATH + "&_=" + nonce,
187
+ title: "记忆树看板",
188
+ onLoad: function (e) {
189
+ // 主区域是常驻 iframe;从别处切回来时浏览器可能恢复上次滚动位置。
190
+ try {
191
+ e.currentTarget.contentWindow.scrollTo(0, 0);
192
+ } catch {
193
+ /* 同源失败时保持原样 */
194
+ }
195
+ },
196
+ style: {
197
+ flex: "1 1 auto",
198
+ width: "100%",
199
+ height: "100%",
200
+ border: 0,
201
+ display: "block",
202
+ background: "#0b1020",
203
+ },
204
+ }),
205
+ );
206
+ }
207
+
208
+ function apply(ctx) {
209
+ ctx.slots.inject("main", () =>
210
+ ctx.slots.register({ name: "main", key: PANEL_ID }, MemoryTreePage),
211
+ );
212
+ ctx.slots.inject("sidebar.panellist", () =>
213
+ ctx.slots.register(
214
+ {
215
+ name: "sidebar.panellist",
216
+ id: PANEL_ID,
217
+ order: 30,
218
+ label: () => "记忆树",
219
+ },
220
+ MemoryTreeIcon,
221
+ ),
222
+ );
223
+ }
224
+
225
+ return { inject: ["slots"], apply };
226
+ },
227
+ });
@@ -0,0 +1,16 @@
1
+ # Memorytree 插件(dsh-memorytree-rule)的加载行。
2
+ # id 与 name 是公开版的稳定标识,发布后不要改。
3
+ - insert:
4
+ - id: memorytree-rule
5
+ name: dsh-memorytree-rule
6
+ config:
7
+ # 数据目录;留空 = <DSH_HOME>/memory-tree
8
+ dataDir: ''
9
+ # 主干正本;留空 = <DSH_HOME>/AGENTS.md
10
+ agentsPath: ''
11
+ # 写入前做敏感串脱敏(sk-*/Bearer/密码赋值/邮箱/11 位以上数字)
12
+ redact: true
13
+ # 每次检索/查看树之前,若 AGENTS.md 变了就重新同步 §1 主干(15 秒节流)。
14
+ autoSync: true
15
+ # 本地情感候选采集(默认开启);设为 false 关闭,重启 DSH 生效。
16
+ emotionCapture: true
package/docs/DETAIL.md ADDED
@@ -0,0 +1,69 @@
1
+ # 记忆树
2
+
3
+ ![记忆树四枝星图](DETAIL.svg)
4
+
5
+ 把「主干、情感枝、任务枝、判断叶」放进 DSH 的本地记忆插件:规则以 `AGENTS.md` 为正本,经历、任务卡和待分拣观察落在本地 SQLite,检索在进程内完成。不联网、不调 LLM、不起外部服务。
6
+
7
+ ## 四枝各管什么
8
+
9
+ | 枝 | 放什么 | 默认作用域 |
10
+ |---|---|---|
11
+ | 主干 | 每轮都要遵守的长期判据;正本是 `AGENTS.md` | 跨工作区 |
12
+ | 情感枝 | 相处经历、情绪对话、工作感受;日记只是索引 | 跨工作区 |
13
+ | 任务枝 | 插件/脚本/服务/固定操作的做法卡;一个 subject 一张 | 全库(可显式 `workspace` 隔离) |
14
+ | 判断叶 | 还没归类、待验证的规则、解析和零散观察 | 全库(可显式 `workspace` 隔离) |
15
+
16
+ 主干写明「不知道就会做错」的判据;任务枝只写路径、命令、参数和坑;枝叶与主干冲突时改枝叶,主干之间冲突时问用户。
17
+
18
+ ## 第一次使用
19
+
20
+ 1. 在 DSH 里安装插件;安装后左侧栏出现「记忆树」入口。
21
+ 2. 看 `<DSH_HOME>/AGENTS.md` 是否已经存在:没有,就在插件目录运行 `node bin/mt.mjs init` 自动复制模板并同步;也可以手动复制 `examples/AGENTS.template.md`,按注释替换 `<...>` 占位。已经存在时 `init` 默认拒绝覆盖,只合并需要的段落。
22
+ 3. 在插件目录运行 `node bin/mt.mjs doctor` 看路径与库是否正常;需要强制重同步时运行 `node bin/mt.mjs sync --force`。
23
+ 4. 想看四枝长什么样,运行 `node bin/mt.mjs demo`:它在临时目录里建一套带「示例」标签的演示库和看板,不碰真实记忆。
24
+
25
+ 模板里的「示例,可删除」都是案例,不是实际记忆;看懂后可以删,也可以改成你自己的经历。
26
+
27
+ ## 9 个工具
28
+
29
+ - `memory_search`:混合检索;命中带分数分解与逐字证据,主干条目另有来源行号;没命中就明确说没有。
30
+ - `memory_write`:写一条记忆;默认脱敏,可传 `redact:false` 保留原文;`trunk` 一律落候选,不会冒充规则。
31
+ - `memory_forget`:默认归档可恢复;物理删除需显式 `hard` 与原因。
32
+ - `memory_tree`:看四枝全貌、候选、过期、待分拣和库大小。
33
+ - `memory_card`:按 `subject` 或 `id` 取任务卡及相关条目。
34
+ - `memory_ingest`:`sync` 同步 `AGENTS.md` §1;`migrate` 迁移旧库;`status` 看环境。
35
+ - `memory_daily`:生成待分拣报告,或一次提交去枝/遗忘决定。
36
+ - `memory_admin`:`doctor` / `stats` / `reindex` / `export` / `import` / `audit` / `report` / `diary` / `placement`。
37
+ - `memory_emotion`:情感候选日结(`list` / `mark` / `stats` / `budget` / `report`);采集默认开启(可配 `emotionCapture: false` 关闭),只动候选表,不直接写记忆。
38
+
39
+ ## 看板与命令行
40
+
41
+ `memory_admin action=report` 或 `node bin/mt.mjs report --out report.html` 生成自包含 HTML:四枝星图、检索、详情抽屉、规则归枝、待确定写入、日记索引与打印。看板不引用外链;「深度思考」按钮只把请求投回 DSH 会话,由 DSH 处理。
42
+
43
+ 常用命令:
44
+
45
+ ```text
46
+ node bin/mt.mjs doctor
47
+ node bin/mt.mjs init
48
+ node bin/mt.mjs stats
49
+ node bin/mt.mjs sync --force
50
+ node bin/mt.mjs search "备份 路径" --limit 5
51
+ node bin/mt.mjs daily
52
+ node bin/mt.mjs demo
53
+ node bin/mt.mjs report --out report.html
54
+ ```
55
+
56
+ ## 数据与隐私
57
+
58
+ - 库在 `<DSH_HOME>/memory-tree/memory.db`,WAL 单文件,可整体备份。
59
+ - 写入默认脱敏:常见密钥、`Bearer`、`password/secret/token/api_key = …`、邮箱、长数字串、`openid`/`qq` 值。
60
+ - 默认在本地按规则挑情感候选:0 token、不联网、不调 LLM;候选先脱敏、只留节选、30 天过期,不写记忆。插件 cwd 用 `emotionPluginCwdPatterns` 配置,不内置具体平台;设 `emotionCapture: false` 关闭。
61
+ - 情感采集默认开启;关闭方法、候选字段、日结流程见 [EMOTION.md](./EMOTION.md)。
62
+ - 主干正本始终是 `AGENTS.md`;只有看板里显式确认的「写入正本」才会改它,改前备份、改后回读校验。
63
+
64
+ ## 边界
65
+
66
+ - 不做自动注入:不会每轮把记忆塞进系统提示,召回靠主动调用 `memory_search`。
67
+ - 情感候选默认采集,但只落候选表,不直接改记忆;设 `emotionCapture: false` 关闭后,入库走显式 `memory_write` 与每日分拣。
68
+ - 向量检索是字符 n-gram 特征哈希,只用于措辞相近加分,不是神经语义模型;没命中不会编造。
69
+ - 看板是快照,实时数据仍以 `memory.db` 为准。
@@ -0,0 +1,85 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 300" width="640" height="300" role="img" aria-label="记忆树四枝星图">
2
+ <defs>
3
+ <radialGradient id="bg" cx="50%" cy="42%" r="72%">
4
+ <stop offset="0" stop-color="#18222c"/>
5
+ <stop offset="1" stop-color="#0a0e12"/>
6
+ </radialGradient>
7
+ <linearGradient id="trunk" x1="0" y1="1" x2="0" y2="0">
8
+ <stop offset="0" stop-color="#c9a227" stop-opacity=".18"/>
9
+ <stop offset="1" stop-color="#e8c766" stop-opacity=".75"/>
10
+ </linearGradient>
11
+ <filter id="glow" x="-80%" y="-80%" width="260%" height="260%">
12
+ <feGaussianBlur stdDeviation="4" result="b"/>
13
+ <feMerge><feMergeNode in="b"/><feMergeNode in="SourceGraphic"/></feMerge>
14
+ </filter>
15
+ </defs>
16
+ <rect width="640" height="300" fill="url(#bg)"/>
17
+ <path d="M320 262 C318 214 316 176 320 138 C324 100 320 72 322 40" fill="none" stroke="url(#trunk)" stroke-width="2.2"/>
18
+ <path d="M320 196 C280 178 246 164 206 150" fill="none" stroke="#e8c766" stroke-opacity=".22" stroke-width="1.3"/>
19
+ <path d="M320 180 C362 162 396 150 436 136" fill="none" stroke="#e8c766" stroke-opacity=".22" stroke-width="1.3"/>
20
+ <path d="M320 220 C282 226 250 238 214 250" fill="none" stroke="#e8c766" stroke-opacity=".22" stroke-width="1.3"/>
21
+ <g fill="#e8c766" filter="url(#glow)">
22
+ <circle cx="322" cy="44" r="4.2"/>
23
+ <circle cx="306" cy="58" r="2.4"/>
24
+ <circle cx="338" cy="62" r="2.1"/>
25
+ <circle cx="318" cy="78" r="2.8"/>
26
+ <circle cx="334" cy="94" r="1.9"/>
27
+ <circle cx="306" cy="96" r="1.8"/>
28
+ <circle cx="320" cy="112" r="2.6"/>
29
+ <circle cx="340" cy="124" r="1.7"/>
30
+ <circle cx="302" cy="126" r="1.6"/>
31
+ <circle cx="322" cy="144" r="2.2"/>
32
+ <circle cx="318" cy="164" r="1.8"/>
33
+ <circle cx="324" cy="186" r="2.0"/>
34
+ <circle cx="320" cy="210" r="1.7"/>
35
+ <circle cx="321" cy="236" r="2.3"/>
36
+ <circle cx="319" cy="258" r="3.0"/>
37
+ </g>
38
+ <g fill="#d98ca8" filter="url(#glow)">
39
+ <circle cx="198" cy="148" r="4.0"/>
40
+ <circle cx="176" cy="158" r="2.5"/>
41
+ <circle cx="214" cy="166" r="2.2"/>
42
+ <circle cx="158" cy="140" r="2.0"/>
43
+ <circle cx="186" cy="132" r="1.8"/>
44
+ <circle cx="146" cy="158" r="1.6"/>
45
+ <circle cx="224" cy="146" r="1.8"/>
46
+ <circle cx="166" cy="176" r="1.7"/>
47
+ <circle cx="206" cy="184" r="1.5"/>
48
+ <circle cx="132" cy="146" r="1.4"/>
49
+ <circle cx="238" cy="156" r="1.4"/>
50
+ <circle cx="190" cy="118" r="1.4"/>
51
+ </g>
52
+ <g fill="#7fb3c9" filter="url(#glow)">
53
+ <circle cx="444" cy="134" r="4.0"/>
54
+ <circle cx="468" cy="124" r="2.4"/>
55
+ <circle cx="426" cy="120" r="2.2"/>
56
+ <circle cx="486" cy="140" r="2.0"/>
57
+ <circle cx="454" cy="112" r="1.8"/>
58
+ <circle cx="502" cy="128" r="1.6"/>
59
+ <circle cx="414" cy="146" r="1.7"/>
60
+ <circle cx="472" cy="156" r="1.6"/>
61
+ <circle cx="438" cy="158" r="1.5"/>
62
+ <circle cx="514" cy="144" r="1.4"/>
63
+ <circle cx="400" cy="132" r="1.4"/>
64
+ <circle cx="494" cy="112" r="1.3"/>
65
+ </g>
66
+ <g fill="#8fbf7f" filter="url(#glow)">
67
+ <circle cx="206" cy="252" r="3.8"/>
68
+ <circle cx="232" cy="240" r="2.3"/>
69
+ <circle cx="184" cy="238" r="2.1"/>
70
+ <circle cx="252" cy="252" r="1.9"/>
71
+ <circle cx="172" cy="254" r="1.7"/>
72
+ <circle cx="222" cy="264" r="1.6"/>
73
+ <circle cx="264" cy="236" r="1.5"/>
74
+ <circle cx="192" cy="224" r="1.4"/>
75
+ <circle cx="148" cy="244" r="1.4"/>
76
+ <circle cx="248" cy="222" r="1.3"/>
77
+ <circle cx="278" cy="248" r="1.3"/>
78
+ <circle cx="164" cy="224" r="1.2"/>
79
+ </g>
80
+ <g fill="none" stroke="#ffffff" stroke-opacity=".06">
81
+ <circle cx="320" cy="150" r="118"/>
82
+ <circle cx="320" cy="150" r="178"/>
83
+ <circle cx="320" cy="150" r="238"/>
84
+ </g>
85
+ </svg>
@@ -0,0 +1,101 @@
1
+ # 情感候选采集(默认开启,可关闭)
2
+
3
+ 这个功能不是「自动写记忆」,而是给情感枝加一个**本地候选池**:插件在会话事件里按规则挑出可能值得回顾的片段,先脱敏、截断、打分,存进 `emotion_candidate`;真正写不写、写成什么,仍由你在日结时用 `memory_write` 决定。
4
+
5
+ 默认开启。不想用就在配置里设 `emotionCapture: false`,重启 DSH 后不再采集。
6
+
7
+ ## 为什么默认开启
8
+
9
+ - 装上就能用:不用先翻文档、改配置才知道插件有这项能力。
10
+ - 采集全程在本机:0 token、0 网络请求、不调 LLM;候选先脱敏、只留节选、30 天自动清理,不写记忆。
11
+ - 默认开启不等于自动写记忆:候选只是线索,写不写、写成什么仍由日结时的 `memory_write` 决定;插件不会自动建日结任务,不建就没有模型成本。
12
+ - 代价说清:会读本地会话的 text 块,并在 `emotion_candidate` 里留下节选;不能接受时设 `emotionCapture: false`,重启后不再采集。
13
+
14
+ ## 配置
15
+
16
+ 在 DSH 的插件配置里给 `dsh-memorytree-rule` 加(具体层级以你的 DSH 配置格式为准):
17
+
18
+ ```yaml
19
+ # 默认开启;设为 false 关闭
20
+ emotionCapture: true
21
+ emotionMinScore: 35
22
+ emotionPluginCwdPatterns:
23
+ - "my-bot-workspace"
24
+ emotionReviewCostCapCny: 0.3
25
+ emotionRetentionDays: 30
26
+ ```
27
+
28
+ | 配置 | 默认 | 说明 |
29
+ |---|---|---|
30
+ | `emotionCapture` | `true` | 默认采集;设 `false` 关闭(其它非 `true` 值也按关闭处理)。 |
31
+ | `emotionMinScore` | `35` | 候选入池的最低分;调高更严,调低更松。 |
32
+ | `emotionPluginCwdPatterns` | `[]` | 插件会话的 cwd 子串列表;命中才把候选归为 `plugin`。不内置任何平台名。 |
33
+ | `emotionReviewCostCapCny` | `0.3` | 日结预算上限(元);`memory_emotion budget` 用。 |
34
+ | `emotionRetentionDays` | `30` | 候选保留天数;过期在采集时顺手清理。 |
35
+
36
+ 改完配置后完全退出并重启 DSH,宿主才会把新配置交给插件。
37
+
38
+ ## 采集什么
39
+
40
+ 监听 `session/event`,只取消息里的 text 块(跳过工具调用、代码围栏、运行时上下文、系统提醒、调度包装等噪声):
41
+
42
+ - **user 消息**:`source.kind === "user"` 才是用户本人;其它来源(调度、插件注入)归 `work`,不冒充 `plugin`。
43
+ - **assistant 消息**:取助手回复的 text 块。
44
+ - **打分**:本地关键词/规则打分,≥35 分才入候选;不是语义模型,会漏也会误收。
45
+ - **分类**:
46
+ - `relationship`:主会话里的相处、情绪、回忆、约定、第一次。
47
+ - `plugin`:cwd 命中 `emotionPluginCwdPatterns` 的插件会话。
48
+ - `work`:工作复盘、普通会话、调度注入。
49
+ - **上限**:每会话每天 6 条、全局 12 条、`plugin` 类别 4 条;同一会话内按分数取前几条。
50
+ - **截断**:正文最多 800 字,另存 240 字上下文;不保存整段会话。
51
+ - **去重**:`sha1(session_id + role + day + text)`,同一天同一条消息只入一次。
52
+ - **脱敏**:候选正文先过本地脱敏(密钥、`Bearer`、邮箱、长数字、`openid`/`qq` 值、访客昵称与 @ 提及)。脱敏是尽力而为,不保证覆盖所有敏感格式;如果环境里可能有人查看本机库,自行评估要不要保留采集。
53
+
54
+ ## 候选长什么样
55
+
56
+ `emotion_candidate` 一行大致包含:`day`、`session_id`、`role`、`category`、`score`、`reasons`、`text`、`context`、`sha1`、`status`(pending/accepted/dismissed)、`node_id`、`created_at`、`expires_at`。
57
+
58
+ 候选不是记忆:它不会进 `memory_search`,不会被注入系统提示,也不会自动出现在情感枝;只有 `memory_write` 写进去的才算。
59
+
60
+ ## 日结流程
61
+
62
+ 建议每天固定一个时间,开一个新会话,按这个顺序做:
63
+
64
+ 1. `memory_emotion stats`:看今天有多少候选、分类和状态。
65
+ 2. `memory_emotion budget`:看今日总花费、本会话花费、是否超过 `emotionReviewCostCapCny`。
66
+ 3. `memory_emotion list`:读候选(默认 pending,最多 50 条)。
67
+ 4. `memory_write`:写 0–6 条。每条必须有**第一人称感受/立场**;写不出感受的候选宁可跳过,不要写成「今天发生了什么」的事件汇报。建议 `layer: "emotion"`,`source: "daily-review@YYYY-MM-DD"`。
68
+ 5. `memory_emotion mark`:把写过的标 `accepted` 并填 `nodeIds`,没写的标 `dismissed`。
69
+ 6. `memory_emotion report`:记下候选数、写入数、丢弃数、花费;不写也能结束,但 `report` 让下一次知道预算。
70
+
71
+ 候选不足就少写,甚至 0 条;不要为了「每天都有记录」硬凑。
72
+
73
+ 插件**不会自动创建**这个 23:30 的定时任务。需要的话,在 DSH 里自己建一个每天固定时间的会话任务,提示词就是上面 6 步;不建也不影响插件其它功能。
74
+
75
+ ## 成本
76
+
77
+ - 采集:0 token、0 网络请求、不调 LLM;只在本地 SQLite 写候选。
78
+ - 日结:模型读候选 + 写记忆的 token,按你自己的模型价格算;`budget` 会读本机 DSH 成本账本(如果存在),读不到就明确说「账本未读到」,不编造数字。
79
+ - 硬上限:`emotionReviewCostCapCny` 只是 `budget` 的提示,不会自动阻止模型调用;要真正停,把 `emotionCapture` 设为 `false`,或不要建日结任务。
80
+
81
+ ## 关闭与清理
82
+
83
+ - 关闭:`emotionCapture: false`,重启 DSH;之后不再采集。
84
+ - 已采集的候选:`memory_emotion mark ids=... status=dismissed` 只是标记;候选会在 `emotionRetentionDays` 天后由采集时的清理逻辑删除。
85
+ - 想立刻清空:关闭采集后,直接删 `memory.db` 里的 `emotion_candidate` / `emotion_review` 行(先备份库),或等过期。
86
+ - 卸载插件不会自动删库;库在 `<DSH_HOME>/memory-tree/memory.db`,按你的备份/删除策略处理。
87
+
88
+ ## 边界
89
+
90
+ - 打分是本地启发式,不是语义理解;会漏掉含蓄的表达,也会把工作抱怨误收成情感候选。
91
+ - 只处理 text 块;图片、语音、工具结果不采集。
92
+ - 不自动写记忆、不自动归枝、不自动改 `AGENTS.md`。
93
+ - 不做跨会话拼接;每条候选只带 240 字上下文。
94
+ - 脱敏是尽力而为;默认开启只在本机库留节选,不能接受时设 `emotionCapture: false` 关闭。
95
+
96
+ ## 排障
97
+
98
+ - 工具没出现:先看 `/memory-tree/health` 的 `tools` 是否含 `memory_emotion`;当前会话的工具清单可能是旧的,新会话才会拿到。
99
+ - 有候选但日结看不到:确认 `emotionCapture` 已重启生效、`memory_emotion list` 的 `day` 是本地日期。
100
+ - 候选太多噪声:调高 `emotionMinScore`(如果版本支持)或收紧 `emotionPluginCwdPatterns`;也可以在日结里直接 dismiss。
101
+ - 预算读不到:`budget` 会返回 `ledger:false`,这是正常的;不代表采集失败。
@@ -0,0 +1,22 @@
1
+ # AGENTS.md(Memorytree 演示用,不是你的真实规则)
2
+
3
+ > 这份文件只给 `mt demo` 用:它会被复制进一个临时目录,演示主干规则如何同步。
4
+ > 里面的名字、路径、规则都是示例;看完可以删,不要直接当正式 `AGENTS.md` 使用。
5
+
6
+ ## §1 主干
7
+
8
+ - **§1-1-1 我是谁**:
9
+ 我是 DSH(示例名,可改成你自己的名字)。每次新会话先读本文件与任务清单,再接当前任务。
10
+
11
+ - **§1-1-6 记忆树逻辑**:
12
+ `AGENTS.md` 是主干正本,`memory-tree/memory.db` 是枝与叶;其他记忆机制并入这棵树,不另建并行存储。
13
+
14
+ - **§1-4-1 DSH 的表达形式**:
15
+ 先给结论,再给依据;能验证的事写清验证方式,验证不了就直说。
16
+
17
+ - **§1-5-1 环境事实**:
18
+ 环境事实以实测为准,不写猜测值;实测与本文件冲突时先汇报。
19
+
20
+ ### 变更记录
21
+
22
+ - `YYYY-MM-DD HH:MM`|演示文件建立:仅用于 `mt demo`,不是真实记忆。