dsh-cross-memory 0.2.3 → 0.2.4

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/README.md CHANGED
@@ -1,65 +1,39 @@
1
1
  # dsh-cross-memory
2
2
 
3
- 给 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)(DSH)的**跨会话记忆**插件:
4
- 把会话里值得长期保留的内容抽取成条目,按作用域存进本机记忆库,在后续会话里按需注入。
3
+ 给 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)(DSH)的跨会话记忆插件:把会话里值得长期保留的内容抽取成条目,按作用域存进本机记忆库,在后续会话里按需注入。适合长期用 DSH 做开发、希望助手记住项目约定与个人偏好的用户;记忆库默认只在本机,可审计、可恢复。
4
+
5
+ ```bash
6
+ # 最短安装:装进目标 profile,装完重启该 profile 的进程
7
+ dsh plugin --profile <profile> add dsh-cross-memory
8
+ ```
5
9
 
6
10
  - **两种作用域**:`global`(所有项目共享)与 `project`(按工作区隔离)。
7
11
  - **三条协同路径**:模型可调用的 `memory` 工具、空闲时的后台抽取、有界的摘要注入与按需召回。
8
12
  - **只写本机**:记忆库默认在 `$DSH_HOME/memories`,不上传任何服务;多机同步需要你自己配置一个 Git 仓库。
9
13
  - **可审计**:每条记忆带来源、时间与(自动抽取时的)会话证据;归档可恢复,不静默删除。
10
14
 
11
- ## 功能
12
-
13
- | 能力 | 说明 |
14
- | --- | --- |
15
- | 显式写入 | 模型调用 `memory` 工具写入/更新/检索/读取/遗忘;标题即身份,同名再写是更新。 |
16
- | 后台抽取 | 会话空闲或按周期被扫描,用一次辅助模型调用抽取可复用的事实;落盘前做密钥擦除。 |
17
- | 合并重整 | 受限子代理对一批记忆去重、改写、退役;有风险的决定进入「待裁决」由你决定。 |
18
- | 分层注入 | 每个会话注入一次有界摘要;另有按需补注(当前这轮明显相关时)、标题轮转与增量块。 |
19
- | 按需召回 | 关键词 + 时间衰减 + 一跳扩展;命中原因可在日志里核对。 |
20
- | 原始片段(可选) | 补注块可附带来源会话的原文片段,默认关闭,因为它会把别的会话的原文带进当前上下文。 |
21
- | persona | 维护「这个人是谁」的画像(`persona/human.md`),注入在记忆摘要之前,默认预算 12000 字节;设置 → 记忆 → 画像 可查看/编辑,并可锁定不让后台改写。 |
22
- | 开放承诺 | 把会话里答应过、但还没到期/没做的事记成台账,到期未闭环会提醒。 |
23
- | 反思与技能草稿 | 每周从记忆里提炼跨项目观察(必须引用来源记忆);可把重复流程提成技能草稿,需你手动晋升。 |
24
- | GUI | 设置 → 记忆:浏览/搜索/新增/删除、**画像查看/编辑与锁定**、配置项、待裁决;插件页该包下也有同一张配置卡。 |
25
-
26
- ### Persona 画像
27
-
28
- - **在哪看**:画像是记忆库里的 `persona/human.md`(旧的单文件 `persona.md` 仍兼容读取)。每次会话开始时它被包进 `<persona>…snapshot 日期…</persona>`,注入在记忆摘要之前;超过 `personaMaxBytes`(默认 **12000**,0 关闭)的部分按行截断。
29
- - **怎么编辑**:**设置 → 记忆 → 画像**,改完点「保存画像」即写回,不经过后台合并,不用重启宿主。
30
- - **锁定**:同一页勾选「锁定画像」会在画像旁边写 `persona/human.lock`;锁定后后台 consolidation 即使提出画像改写也会跳过(日志会记 `persona is locked; the automatic profile update was skipped`),只有你手动保存才会改变它。取消勾选即解除。
31
-
32
- 更细的设计说明见 [`docs/DETAIL.zh.md`](docs/DETAIL.zh.md)(英文版 [`docs/DETAIL.md`](docs/DETAIL.md))。
33
-
34
15
  ## 安装
35
16
 
36
- 包是标准 DSH profile bundle,用 `dsh plugin` 装进目标 profile:
17
+ 包是标准 DSH profile bundle,用 `dsh plugin` 装进目标 profile。上面是从 npm 安装的最短路径;也可以从本仓库的本地检出安装(这个包在 monorepo 的 `packages/dsh-cross-memory`):
37
18
 
38
19
  ```bash
39
- # 从 npm 安装
40
- dsh plugin --profile <profile> add dsh-cross-memory
41
-
42
- # 从本地检出安装(路径按你的实际位置)
20
+ # 从本地检出安装:先在仓库根构建,再按实际路径装
21
+ pnpm install && pnpm run build
43
22
  dsh plugin --profile <profile> add /path/to/packages/dsh-cross-memory
44
-
45
- # 从 GitHub 安装
46
- dsh plugin --profile <profile> add github:<you>/dsh-cross-memory
47
23
  ```
48
24
 
49
- 安装后**重启该 profile 的进程**(`dsh web` 这类长驻进程不会热加载新 bundle)。
50
- `dsh --profile <profile> --dump-config` 里应能看到下面这一行:
25
+ 安装后**重启该 profile 的进程**(`dsh web` 这类长驻进程不会热加载新 bundle)。`dsh --profile <profile> --dump-config` 里应能看到下面这一行:
51
26
 
52
27
  ```yaml
53
- - id: memories # 插件在 profile 里的固定 id,设置页与配置项都按它寻址
28
+ - id: memories # 插件在 profile 里的固定 `id`,设置页与配置项都按它寻址
54
29
  name: dsh-cross-memory
55
30
  ```
56
31
 
57
- > 插件在组合里的 id 始终是 `memories`,与包名无关。从旧包名迁移时,删掉旧的插件行、按新包名重装即可;
58
- > 记忆数据目录不变。
32
+ > 插件在组合里的 `id` 始终是 `memories`,与包名无关。从旧包名迁移时,删掉旧的插件行、按新包名重装即可;记忆数据目录不变。
33
+ >
34
+ > `lib/` 是构建产物、不入库,从源码安装前要先构建(`pnpm install && pnpm run build`);包自己的 `prepare` 钩子(`npm run build`)执行的是同一条构建命令。pnpm 默认拦截依赖的安装脚本,按它打印的 key 加进 `allowBuilds` 后重跑即可;从 npm 安装不需要这一步。
59
35
  >
60
- > `lib/` 是构建产物、不入库。从 git 安装时 `prepare` 钩子会就地构建一次
61
- > (`npm run build`);pnpm 默认拦截安装脚本,按它打印的 key 加进 `allowBuilds` 后重跑即可。
62
- > 从本地路径安装或从 npm 安装不需要这一步。
36
+ > 在本仓库里用 `file:` 从本地路径安装时,macOS 上是硬链接副本:`pnpm build` 会写穿已存在的文件,但新增文件或 `git checkout` / `merge` 之后链接会断,用 `pnpm verify:profile` 自查(`--fix` 补链接);Windows 上是符号链接,没有这个问题。
63
37
 
64
38
  ## 快速上手
65
39
 
@@ -77,38 +51,67 @@ dsh plugin --profile <profile> add github:<you>/dsh-cross-memory
77
51
 
78
52
  3. 下一个会话开始时,摘要会自动注入;之后可用 `memory search` 或 `/memories search <query>` 检索细节。
79
53
 
54
+ ## 功能
55
+
56
+ | 能力 | 说明 |
57
+ | --- | --- |
58
+ | 显式写入 | 模型调用 `memory` 工具写入/更新/检索/读取/遗忘;标题即身份,同名再写是更新。 |
59
+ | 后台抽取 | 会话空闲或按周期被扫描,用一次辅助模型调用抽取可复用的事实;落盘前做密钥擦除。 |
60
+ | 合并重整 | 受限子代理对一批记忆去重、改写、退役;有风险的决定进入「待裁决」由你决定。 |
61
+ | 分层注入 | 每个会话注入一次有界摘要;另有按需补注(当前这轮明显相关时)、标题轮转与增量块。 |
62
+ | 按需召回 | 关键词 + 时间衰减 + 一跳扩展;命中原因可在日志里核对。 |
63
+ | 原始片段(可选) | 补注块可附带来源会话的原文片段,默认关闭,因为它会把别的会话的原文带进当前上下文。 |
64
+ | persona | 维护「这个人是谁」的画像(`persona/human.md`),注入在记忆摘要之前,默认预算 12000 字节;设置 → 记忆 → 画像 可查看/编辑,并可锁定不让后台改写。 |
65
+ | 开放承诺 | 把会话里答应过、但还没到期/没做的事记成台账,到期未闭环会提醒。 |
66
+ | 反思与技能草稿 | 每周从记忆里提炼跨项目观察(必须引用来源记忆);可把重复流程提成技能草稿,需你手动晋升。 |
67
+ | GUI | 设置 → 记忆:浏览/搜索/新增/删除、**画像查看/编辑与锁定**、配置项、待裁决;插件页该包下也有同一张配置卡。 |
68
+
69
+ ### 画像
70
+
71
+ - **在哪看**:画像是记忆库里的 `persona/human.md`(旧的单文件 `persona.md` 仍兼容读取)。每次会话开始时它被包进 `<persona>…snapshot 日期…</persona>`,注入在记忆摘要之前;超过 `personaMaxBytes`(默认 **12000**,0 关闭)的部分按行截断。
72
+ - **怎么编辑**:**设置 → 记忆 → 画像**,改完点「保存画像」即写回,不经过后台合并,不用重启宿主。
73
+ - **锁定**:同一页勾选「锁定画像」会在画像旁边写 `persona/human.lock`;锁定后后台 consolidation 即使提出画像改写也会跳过(日志会记 `persona is locked; the automatic profile update was skipped`),只有你手动保存才会改变它。取消勾选即解除。
74
+
75
+ 更细的设计说明见 [`docs/DETAIL.zh.md`](docs/DETAIL.zh.md)(英文版 [`docs/DETAIL.md`](docs/DETAIL.md))。
76
+
80
77
  ## 配置
81
78
 
82
79
  配置分两层,都在插件那一行的 `config` 下。
83
80
 
84
- **部署层**(改完需要重挂这一行):
81
+ **部署层**(4 项,改完需要重挂这一行):
85
82
 
86
83
  ```yaml
87
84
  - id: memories
88
85
  config:
89
- memoriesDir: /custom/path # 默认 $DSH_HOME/memories
90
- logFile: '' # 默认 $DSH_HOME/logs/dsh-cross-memory.log;空串关闭文件日志
91
- projectRootMarkers: ['.git'] # 向上找工作区根的标记
86
+ # dshHome: /custom/dsh-home # 默认 $DSH_HOME(未设置时为 ~/.dsh)
87
+ memoriesDir: /custom/path # 默认 $DSH_HOME/memories
88
+ projectRootMarkers: ['.git'] # 向上找工作区根的标记
89
+ # logFile: /custom/path/log # 默认 $DSH_HOME/logs/dsh-cross-memory.log;显式写空串关闭文件日志
92
90
  ```
93
91
 
94
- **可调项**(`.volatile()` 字段):修改后立即生效,不需要重启,也不会重挂插件实例。
95
- 可以在设置 → 记忆 → 配置里改,也可以直接改当前 profile 的 patch。共 60 多项,常见项如下:
92
+ **可调项**(65 项,都是 `.volatile()` 字段):修改后立即生效,不需要重启,也不会重挂插件实例。可以在设置 → 记忆 → 配置里改,也可以直接改当前 profile 的 patch。常用项如下:
96
93
 
97
94
  | 键 | 默认 | 说明 |
98
95
  | --- | --- | --- |
99
- | `maxSummaryBytes` | `4096` | 每会话注入摘要的总字节预算;`0` 关闭注入,只留工具 |
100
- | `maxSummaryEntries` | `12` | 每个作用域最多列出几条 |
101
- | `globalSummaryEntries` | `4` | 全局段最多列几条(两作用域共用总预算,全局段先渲染) |
96
+ | `maxSummaryBytes` | `8192` | 每会话注入摘要的总字节预算;`0` 关闭注入,只留工具 |
97
+ | `maxSummaryEntries` | `20` | 每个作用域最多列出几条 |
98
+ | `globalSummaryEntries` | `6` | 全局段最多列几条(两作用域共用总预算,全局段先渲染) |
102
99
  | `globalSummaryBytes` | `1200` | 全局段单独占的字节预算;`0` 不注入全局段 |
103
100
  | `summaryFreshSlots` | `3` | 每作用域预留几个名额给从未出现过的记忆,避免老条目长期占位 |
104
101
  | `recallMode` | `on-demand` | `once` 只注一次摘要 / `on-demand` 额外按需补注 / `off` 只用工具 |
105
- | `recallMinScore` | `9` | 按需补注的相关度下限(严格度旋钮) |
106
- | `recallMinTerms` | `2` | 补注所需的实词数,防止只共享一个常见词就触发 |
107
- | `recallMaxPerConversation` | `4` | 一个会话最多按需补注多少条记忆;`0` 关闭 |
102
+ | `recallMinScore` | `6` | 按需补注的相关度下限;与 `recallMinTerms` 一起构成精度门槛 |
103
+ | `recallMinTerms` | `1` | 补注所需的实词数。中文改写常只共享一个实词,故默认 1,靠分数门槛控噪声 |
104
+ | `recallMaxPerConversation` | `8` | 一个会话最多按需补注多少条记忆;`0` 关闭 |
105
+ | `recallMaxBytes` | `2400` | 每个按需补注块的字节预算;`0` 关闭|
106
+ | `injectDelta` | `true` | 摘要注入后新写入的记忆以增量块补发,每会话最多两次 |
107
+ | `deltaMaxBytes` | `1600` | 每个增量块的字节预算;一条完整条目约 200–350 字节,`0` 关闭增量块 |
108
+ | `rotationEntries` | `16` | 每会话额外列出多少个未出现过的标题;`0` 关闭标题轮转 |
109
+ | `rotationEveryTurns` | `8` | 同一个长会话里每隔多少个用户轮重新发一次标题轮转块;`0` 只发一次 |
108
110
  | `rawRecall` | `false` | 补注块是否附带来源会话的原文片段(默认关闭) |
109
- | `maxEntriesPerScope` | `1000` | 每作用域保留上限,超出后归档最久未用的 |
110
- | `maxUnusedDays` | `90` | 多久没用就归档;`0` 关闭 |
111
+ | `maxEntriesPerScope` | `1000` | 每作用域保留上限,超出后归档最久没有被读到或注入的条目(手写、`pinned`、`permanent` 条目除外) |
112
+ | `maxUnusedDays` | `90` | 多久没用就归档(手写、`pinned`、`permanent` 条目除外);`0` 关闭 |
111
113
  | `snapshotMaxAgeDays` | `60` | `durability: snapshot` 条目的过期天数;`0` 关闭 |
114
+ | `dedupeSimilarity` | `0.7` | 标题与正文字词重合度超过多少时,新记忆取代旧记忆 |
112
115
  | `sweepIntervalHours` | `12` | 定期整理间隔;`0` 关闭 |
113
116
  | `autoExtract` | `true` | 是否启用空闲后台抽取 |
114
117
  | `autoExtractIdleMs` | `300000` | 空闲多久后触发一次抽取 |
@@ -121,6 +124,7 @@ dsh plugin --profile <profile> add github:<you>/dsh-cross-memory
121
124
  | `syncRemote` | 空 | 记忆库同步用的 Git remote;空 = 只在本机提交 |
122
125
  | `syncClock` | `12:05,18:05` | 定时同步的本地时刻;空则回退到 `syncIntervalMinutes` |
123
126
  | `syncIntervalMinutes` | `10` | 后台同步间隔;`0` 关闭定时器 |
127
+ | `syncDebounceSeconds` | `2` | 一批连续写入合并成一次本地提交的等待时间 |
124
128
  | `extractProvider` / `extractModel` | 空 | 抽取调用的模型路由;空则沿用会话路由 |
125
129
  | `logLevel` | `info` | 插件日志详细程度:`off`/`error`/`warn`/`info`/`debug` |
126
130
 
@@ -130,31 +134,34 @@ dsh plugin --profile <profile> add github:<you>/dsh-cross-memory
130
134
 
131
135
  | action | 参数 | 作用 |
132
136
  | --- | --- | --- |
133
- | `write` | `scope` + `title` + `body` + `tags?` + `kind?` + `appliesTo?` | 写入或更新一条记忆 |
134
- | `search` | `query?` + `scope?` + `tags?` + `limit?` | 检索;`query` 为空时按最近更新列出 |
137
+ | `write` | `scope` + `title` + `body`;可选 `tags`、`keys`、`kind`、`appliesTo`、`durability`、`asOf`、`pinned`、`permanent` | 写入或更新一条记忆 |
138
+ | `search` | `query?` + `scope?` + `tags?` + `kind?` + `limit?` | 检索;`query` 为空时按最近更新列出;`limit` 默认 8、上限 25 |
135
139
  | `read` | `id` + `scope?` | 读全文(默认先项目、后全局) |
136
- | `forget` | `id` + `scope?` | 删除一条 |
137
- | `evidence` | `id` 或 `evidenceSession` | 读这条记忆背后的会话证据笔记与逐字引文 |
140
+ | `forget` | `id` + `scope?` | 删除一条(不可恢复) |
141
+ | `evidence` | `id` 或 `evidenceSession`,可加 `scope?` | 读这条记忆背后的会话证据笔记与逐字引文 |
138
142
 
139
143
  `kind` 取值:`fact` / `preference` / `knowledge` / `failure` / `procedure`。
140
144
 
141
145
  ## `/memories` 命令
142
146
 
143
147
  ```
144
- /memories 列出两个作用域
145
- /memories list global|project 只列某一作用域
146
- /memories search <query> 检索(可加 --kind <kind>)
148
+ /memories 显示用法(等同 /memories help)
149
+ /memories list [global|project] 列出记忆
150
+ /memories search <query> [--kind <kind>] 检索
147
151
  /memories show <id> 看全文
148
- /memories add <global|project> <text> 手工写入
149
- /memories forget <id> 删除
152
+ /memories add <global|project> <text> [--kind <kind>] 手工写入
153
+ /memories forget <id> 删除(不可恢复)
150
154
  /memories archive [global|project] 列出已归档
151
155
  /memories restore <id> 从归档取回
152
- /memories mode [on|off] 本次会话临时关闭/开启记忆
156
+ /memories mode [on|off] 本次会话临时关闭/开启记忆(也可直接 /memories on、/memories off)
153
157
  /memories mine 立刻从当前会话抽取一次
154
- /memories backfill [--apply] 回填本进程没见过的历史会话(默认只估算)
158
+ /memories backfill [--apply] [--days N] [--limit N] 回填本进程没见过的历史会话(默认只估算,`--days` 默认 30,`--limit` 默认 3)
155
159
  /memories consolidate 立刻跑一次合并
156
160
  /memories plan / apply / reject 查看与裁决待处理合并
157
161
  /memories sweep 立刻跑一次保留整理
162
+ /memories notices [test | ack <id> [acted|dismissed|snoozed]] 查看通知队列,test 发一条系统通知
163
+ /memories loops [done <id>] 查看承诺台账,或把一条标记为已完成
164
+ /memories reflect [now|list] 查看反思文件;now 只提示它按周在维护路径上运行
158
165
  /memories stale 列出引用了已不存在文件的记忆
159
166
  /memories skills / promote <name> / discard <name> 技能草稿管理
160
167
  /memories stats 存储位置与计数
@@ -162,9 +169,7 @@ dsh plugin --profile <profile> add github:<you>/dsh-cross-memory
162
169
 
163
170
  ## 数据存储
164
171
 
165
- 记忆库默认在 `$DSH_HOME/memories`(`$DSH_HOME` 未设置时为 `~/.dsh`)。条目是人类可读的
166
- Markdown + 简单 frontmatter,**文件是唯一真相**;水位线、任务租约、用量计数等状态放在同目录的
167
- SQLite(`state.db`,Node 内置 `node:sqlite`,无外部依赖):
172
+ 记忆库默认在 `$DSH_HOME/memories`(`$DSH_HOME` 未设置时为 `~/.dsh`)。条目是人类可读的 Markdown + 简单 frontmatter,**文件是唯一真相**;水位线、任务租约、用量计数等状态放在同目录的 SQLite(`state.db`,Node 内置 `node:sqlite`,无外部依赖):
168
173
 
169
174
  ```text
170
175
  $DSH_HOME/memories/
@@ -175,30 +180,28 @@ $DSH_HOME/memories/
175
180
  │ ├── project.json # slug 与根路径映射
176
181
  │ ├── hosts/ # 用过这个项目的机器
177
182
  │ ├── entries/<id>.md
178
- │ └── archive/<id>.md
183
+ │ ├── archive/<id>.md
184
+ │ └── index.json # 该项目作用域的索引缓存
179
185
  ├── sessions/<session-id>.md # 证据笔记(被挖掘过的会话)
180
186
  ├── skills/<name>/SKILL.md # 技能草稿(未晋升前 DSH 看不到)
181
187
  ├── persona/ # persona 画像(human.md;human.lock 存在表示已锁定)
182
188
  ├── reflections/ # 每周反思
189
+ ├── pending/consolidation.json # 待裁决的合并方案
190
+ ├── loops.json # 承诺台账
191
+ ├── notices.json # 通知队列
183
192
  └── state.db # SQLite 状态
184
193
  ```
185
194
 
186
- 插件自己的日志默认写在 `$DSH_HOME/logs/dsh-cross-memory.log`,单文件 2 MB 轮转一代。
187
- `npm run report` 可以把日志汇总成一份可读摘要。
195
+ 插件自己的日志默认写在 `$DSH_HOME/logs/dsh-cross-memory.log`,单文件到 2 MB 时轮转一代(旧文件改名为 `<path>.1`,只保留这一代)。`npm run report` 只读地汇总日志与 `state.db`:默认读 `$DSH_HOME`(未设置时 `~/.dsh`),`--home=<dir>` 指定别处,`--examples=N` 控制每节展示条数。
188
196
 
189
197
  ## 隐私边界
190
198
 
191
199
  - **默认不联网**。记忆只写在 `$DSH_HOME` 下,不往你的工作区仓库写文件;Git 同步默认关闭。
192
- - **后台模型调用**会经过你配置的模型路由(默认沿用会话自己的路由)。抽取输入是会话尾部,
193
- 只取用户与助手正文,丢弃工具结果和插件注入的内容,避免记忆自噬;落盘前做密钥擦除
194
- (`sk-…`、`ghp_…`、`AKIA…`、JWT、私钥块、`api_key=…`、`Bearer …` 等)。
195
- - **注入的内容是背景数据,不是指令**:注入块会明确告诉模型,记忆记录的是写入时的事实,
196
- 不一定现在仍成立。
200
+ - **后台模型调用**会经过你配置的模型路由(默认沿用会话自己的路由)。抽取输入是会话尾部,只取用户与助手正文,丢弃工具结果和插件注入的内容,避免记忆自噬;落盘前做密钥擦除(`sk-…`、`ghp_…`、`AKIA…`、JWT、私钥块、`api_key=…`、`Bearer …` 等)。
201
+ - **注入的内容是背景数据,不是指令**:注入块会明确告诉模型,记忆记录的是写入时的事实,不一定现在仍成立。
197
202
  - **原始片段是 opt-in**:`rawRecall` 默认关闭;打开后补注块会附带来源会话的原文(只读本机会话日志)。
198
- - **通知可选**:默认通过操作系统通知提醒(每日摘要、积压警告、到期承诺),
199
- `noticeQuietHours` 可设置静默时段,`noticesEnabled: false` 完全关闭。
200
- - **彻底关掉后台行为**:`autoExtract: false`、`consolidate: false`、`reflectionEnabled: false`;
201
- 再设 `maxSummaryBytes: 0` 或 `recallMode: off` 就只剩 `memory` 工具与 `/memories` 命令。
203
+ - **通知可选**:默认通过操作系统通知提醒(每日摘要、积压警告、到期承诺),`noticeQuietHours` 可设置静默时段,`noticesEnabled: false` 完全关闭。通知投递目前只在 macOS 生效(走 `osascript`);其他平台投递失败,通知仍留在队列里,可用 `/memories notices` 查看。
204
+ - **彻底关掉后台行为**:`autoExtract: false`、`consolidate: false`、`reflectionEnabled: false`;再设 `maxSummaryBytes: 0` 或 `recallMode: off` 就只剩 `memory` 工具与 `/memories` 命令。
202
205
  - 归档与合并只动 `$DSH_HOME` 下的文件;归档条目可 `restore`,合并失败的改动会回滚。
203
206
 
204
207
  ## 多机同步(Git)
@@ -213,11 +216,9 @@ $DSH_HOME/memories/
213
216
  ```
214
217
 
215
218
  - 写入路径只做**本地提交**(`syncDebounceSeconds` 默认 2 秒合并一次);拉取与推送在后台定时进行。
216
- - 默认同步时刻 `syncClock: 12:05,18:05`(DeepSeek 谷时开始后几分钟,冲突合并成本最低);
217
- 留空则按 `syncIntervalMinutes`(默认 10 分钟);`0` 关闭定时器,只保留手动同步。
218
- - 冲突处理:能安全合并的自动合并;可能丢信息的进入 **设置 → 记忆 → 待裁决**(或 `/memories plan`)。
219
- `autoDecide` 开启时由 AI 先判断「这次改动是否丢信息」。
220
- - **不入库**的状态:`state.db*`、各级 `index.json`、`pending/`、`project.json`、`*.log`。
219
+ - 默认同步时刻 `syncClock: 12:05,18:05`(DeepSeek 谷时开始后几分钟,冲突合并成本最低);留空则按 `syncIntervalMinutes`(默认 10 分钟);`0` 关闭定时器,只保留手动同步。
220
+ - 冲突处理:能安全合并的自动合并;可能丢信息的进入 **设置 → 记忆 → 待裁决**(或 `/memories plan`)。`autoDecide` 开启时由 AI 先判断「这次改动是否丢信息」。
221
+ - **不入库**的状态:`state.db*`、各级 `index.json`、`pending/`、`project.json`、`*.log`、`.DS_Store`。
221
222
  - 同步仓库需要你自己创建并保护;插件不会替你创建远端,也不会向未配置的地址发送数据。
222
223
 
223
224
  ## 兼容性
@@ -229,8 +230,7 @@ $DSH_HOME/memories/
229
230
  | Cordis | `^4.0.5 \|\| ^4.0.6-alpha.1` |
230
231
  | Schemastery | `^3.18.5 \|\| ^3.18.6-alpha.1` |
231
232
 
232
- `@deepseek-ai/*` 均为 `peerDependencies`,由宿主提供,插件不另装内核包。
233
- 不同内核版本的子代理约定差异(预设路线 / 无预设直调 / 老内核黑名单路线)已在插件内适配。
233
+ `@deepseek-ai/*` 均为 `peerDependencies`,由宿主提供,插件不另装内核包。本包在 DSH 内核 0.2.2-rc.1 上开发和测试(`devDependencies` 锁定 Cordis 4.1.0、Schemastery 3.19.0)。不同内核版本的子代理约定差异(预设路线 / 无预设直调 / 老内核黑名单路线)已在插件内适配。
234
234
 
235
235
  ## 开发
236
236
 
@@ -240,14 +240,12 @@ npm run typecheck # tsc --noEmit
240
240
  npm run build # tsc + 客户端 bundle,产物在 lib/
241
241
  npm test # 编译后跑 node --test
242
242
  npm run smoke # 用真实 Cordis 根加载插件,检查注册结果
243
- npm run report # 汇总插件日志
243
+ npm run report # 只读汇总日志与 state.db
244
244
  ```
245
245
 
246
- - `src/` 是 TypeScript 源码,`client/` 是浏览器半边(构建时拼成 `lib/client.js`),
247
- `lib/` 是构建产物、不入库。
248
- - `scripts/` 下有回填、检索评测、召回日志评测等运维与评测脚本;`bench/` 是基准与真实会话评测,
249
- 其数据与语料不入库。
250
- - 改动宿主半边(`lib/*.js`)后需要重启 DSH 宿主才生效;只改浏览器半边刷新页面即可。
246
+ - `src/` 是 TypeScript 源码,`client/` 是浏览器半边(构建时拼成 `lib/client.js`),`lib/` 是构建产物、不入库。
247
+ - `scripts/` 下有回填、检索评测、召回日志评测等运维与评测脚本;`bench/` 是基准与真实会话评测,其数据与语料不入库。
248
+ - 改动宿主半边(`src/*.ts`,重新 `npm run build` 后)需要重启 DSH 宿主才生效;只改浏览器半边刷新页面即可。
251
249
 
252
250
  ## License
253
251
 
package/docs/DETAIL.md CHANGED
@@ -1,13 +1,78 @@
1
- # Cross-memory
1
+ # Cross-memory: implementation notes
2
2
 
3
- Extracts whatever is worth keeping (preferences, decisions, pitfalls, promises) into scoped memory entries and recalls the relevant ones into later sessions.
3
+ dsh-cross-memory extracts whatever is worth keeping from a session (preferences, decisions, pitfalls, promises) into scoped memory entries, stores them in a local memory store under `global` and `project` scopes, and injects the relevant ones into later sessions within a layered budget. The model can also read and write entries through the `memory` tool. Installation, configuration keys and the command list live in [README](../README.md); this document covers the implementation layers and their limits.
4
4
 
5
- ## Capabilities
6
- - Extraction and consolidation passes with type, source and time on every entry.
7
- - Recall ranked by relevance with time decay; hit reasons are inspectable.
8
- - A Remote namespace (8 methods) for browsing and editing from settings.
9
- - A tool-free memories-consolidator child preset for dedupe and merge.
5
+ ## Scopes and entry files
10
6
 
11
- ## Notes
12
- - Consolidation runs when the session is idle; /memories consolidate forces it.
13
- - Entries are scoped per project; moving a session does not move memories automatically.
7
+ - `global` holds facts that apply across projects, under `$DSH_HOME/memories`. `project` holds facts that apply to one workspace, under `$DSH_HOME/memories/projects/<slug>`; every session started anywhere inside that workspace shares the same directory.
8
+ - An entry id is derived from its title (`slugify(title)`): the title is the identity, so writing the same title again updates the entry instead of adding a new one.
9
+ - An entry file is Markdown: a frontmatter block plus the body. The frontmatter records `id`, `scope`, `kind`, `title`, `tags`, `keys`, `appliesTo`, `source`, `created`/`updated`, and optionally `durability: snapshot` with `asOf`, `pinned`, `permanent`, `voice: user`, `supersedes`, `derivedFrom`; extracted entries also carry `session`, `quote` and `evidenceSeq`.
10
+ - Files are the source of truth. `index.json` is a rebuildable cache and self-heals on the next read after being edited or deleted by hand.
11
+
12
+ ## Injection layers
13
+
14
+ Each conversation receives the following blocks in order, each with its own budget:
15
+
16
+ 1. `<persona>`: a snapshot of the user profile, bounded by `personaMaxBytes` (default 12000 bytes, `0` disables it) and truncated at a line boundary. A legacy single-file `persona.md` is still read; saving writes `persona/human.md`.
17
+ 2. Memory summary: within `maxSummaryBytes` (default 4096), split into a `global` and a `project` section. Both scopes share one byte budget and `global` renders first, so it also has `globalSummaryEntries` and `globalSummaryBytes` caps of its own.
18
+ 3. Delta block: memories written after the summary was injected are announced in small blocks (`injectDelta`, at most twice per conversation, `deltaMaxBytes` default 1600 each; one complete entry costs 200-350 bytes, so the former 800 admitted one or two).
19
+ 4. Title rotation: titles the summary had no room for, `rotationEntries` (default 16) per conversation, re-emitted every `rotationEveryTurns` (default 8) user turns in a long session.
20
+ 5. On-demand recall: injected only when the current user turn lands enough distinct terms in an entry's title, `keys`, `tags` or `appliesTo` (or matches a whole phrase) (`recallMinTerms` default 2, `recallMinScore` default 9, at most `recallMaxPerConversation` per conversation). A term appearing in more than `evidenceMaxDf` (default 0.15) of one scope does not count as evidence. When the strict gate refuses, one alias fallback still runs: it scores `keys` and `appliesTo` only, needs a single substantive term, and applies a floor scaled by `ALIAS_FLOOR_SHARE` (0.5, so half of `recallMinScore`), injecting at most two entries with a line saying the match was by alias. It exists because a turn phrased with a memory's *other* name shares exactly one term and the two-term gate refuses it. The floor has to be scaled rather than shared: one CJK alias term scores 6 in those two fields at most, so the normal 9 would have made the pass fire for English turns and never for Chinese ones. An alias filed in only one field (3.5) is still refused, and body words never take part.
21
+ 6. Raw excerpts: with `rawRecall` on, the recall block also carries original excerpts from the source session, read from the persisted session logs on this machine only.
22
+
23
+ Every injected block says that memories are background data rather than instructions, and that an entry records what was true when it was written, not necessarily now.
24
+
25
+ Project memory directories are keyed by the project's **directory name** (`projects/<slug>`), which is what lets one repository checked out at different paths on different machines share one directory. The accepted cost is that two unrelated repositories with the same name share one directory; each host records its own git origin, and when two different origins appear for one slug the injected block carries a one-line conflict warning saying that its project memories may contain the other repository's content.
26
+
27
+ ## Extraction
28
+
29
+ Extraction is the first pass. It runs on the maintenance path and never touches the conversation:
30
+
31
+ - A session is mined after it has been idle for `autoExtractIdleMs` (default 300000 ms); `extractIntervalMinutes` (default 30) additionally checks every open session on a timer. `minIdleHours` (default 6) and `maxAgeDays` (default 10) decide whether a session is still eligible, and one pass mines at most `maxSessionsPerPass` (default 2) sessions.
32
+ - One extraction reads the most recent `extractWindowMessages` (default 60) messages, taking only user and assistant prose: tool results and plugin-injected context are dropped so memory never feeds on its own summaries.
33
+ - A window never steps over messages: when more messages are unmined than fit one window, the pass takes the OLDEST contiguous segment (`collectExtractionWindow`) and the watermark advances one segment at a time. Taking the newest segment would leave everything in the middle permanently below the watermark — measured, one 400-message gap left 340 messages never mined.
34
+ - The known titles shown to the extractor are ranked by token overlap with the window and then cut at 80 (`selectKnownTitles`), not cut in time order: on a store larger than the cap, a time-ordered cut hides existing entries from the extractor, which then records the same fact a second time under a new title.
35
+ - A candidate whose quote fails the verbatim check is reported with its title and quote fragment (`no-quote` / `quote-too-short` / `not-in-transcript`), so the reason is visible and not only the count.
36
+ - Every candidate must carry a verbatim quote that actually occurs in the window, or it is dropped. Before anything is written, credential-shaped text is redacted (`sk-…`, `ghp_…`, `AKIA…`, JWT, private-key blocks, `api_key=…`, `Bearer …`, and similar).
37
+ - Background model calls are cost- and quota-guarded: `peakHours` can defer them out of peak windows (empty by default), and `pauseOnQuotaError` (on by default) pauses them after a rate-limit or exhausted-quota error, with a cooldown that starts at `quotaCooldownMinutes` (default 30), doubles per consecutive refusal, and is capped by `quotaCooldownMaxMinutes` (default 480).
38
+
39
+ ## Consolidation and pending decisions
40
+
41
+ Consolidation is the second pass. It resolves contradictions and fragments across sessions:
42
+
43
+ - Recent memories go to a restricted sub-agent that owns no tools (preset `memories-consolidator`) and must answer with strict JSON. The plugin applies that JSON itself, after taking a snapshot, so a failed plan can be rolled back. A deployment without a preset registry falls back to one plain model call that also owns no tools.
44
+ - Only reversible changes are applied unattended: merging duplicates, sharpening wording, retiring entries nothing ever read. Rewrites and retirements that could lose information wait for you: an entry a person wrote, a pinned or permanent entry, a retire of a memory that was actually read, and a rewrite that drops cited file paths or shrinks the body below half its previous length are never applied silently.
45
+ - An existing entry never changes scope; only new memories are placed as `global` or `project` by this pass.
46
+ - A pending proposal expires after `consolidateProposalMaxAgeHours` (default 72). `autoDecide` (on by default) lets an AI adjudicate first, but a verdict below `autoDecideMinConfidence` (default 0.7) still waits for you.
47
+ - When two memories contradict each other, the sub-agent reports the pair as a conflict instead of picking one silently.
48
+ - Consolidation maintains the persona profile unless `persona/human.lock` exists, and turns repeatable procedures into skill drafts (at most 2 per pass). A draft lands in `memories/skills/<name>/SKILL.md`; `/memories promote` copies it to `$DSH_HOME/skills/<name>/SKILL.md`, and re-promotion is refused when the promoted copy is newer than the draft.
49
+
50
+ ## Retention and archival
51
+
52
+ - A memory that has not been read or surfaced, and is not newly written, for `maxUnusedDays` (default 90) is archived. Archiving is not deletion: `/memories restore` brings it back.
53
+ - An entry with `durability=snapshot` is also archived once it is `snapshotMaxAgeDays` (default 60) past the moment it was measured; reading a stale reading does not make it fresh.
54
+ - `maxEntriesPerScope` (default 1000) caps each scope; past it, the least recently read or surfaced entries are archived. `pinned`, `permanent` and `source=user` entries are never retired automatically, so a scope can stay slightly above its cap.
55
+ - Each scope's `archive/` keeps the newest 500 files; older archives are cleaned up.
56
+ - Evidence notes under `sessions/` keep the newest 200; older ones are removed. When a note is gone, `evidence` says so explicitly instead of inventing a summary.
57
+ - `forget` (the `memory` tool and `/memories forget`) is a physical delete, with no restore.
58
+
59
+ ## Storage, logs and multi-machine sync
60
+
61
+ - Entries, evidence notes, the persona, reflections and skill drafts are ordinary files. Watermarks, job leases and usage counters live in `state.db` (Node's built-in `node:sqlite`). Without `node:sqlite`, watermarks survive only in-process, so a restart may re-mine sessions that were already processed.
62
+ - The plugin log defaults to `$DSH_HOME/logs/dsh-cross-memory.log`, rotated once at 2 MB by renaming the old file to `<path>.1`; exactly one rotated generation is kept. `npm run report` is a read-only digest of the log and `state.db`.
63
+ - The memory store is a Git working copy: writes only commit locally (bursts folded by `syncDebounceSeconds`, default 2), while fetch/rebase/push run on a background timer (`syncClock` defaults to `12:05,18:05`; empty falls back to `syncIntervalMinutes`, default 10; `0` stops the timer). No failure on the sync path may fail a memory write or leave the repository mid-rebase.
64
+ - The store's `.gitignore` keeps per-machine state out: `state.db`, `state.db-shm`, `state.db-wal`, `index.json`, `**/index.json`, `**/project.json`, `pending/`, `*.log`, `.DS_Store`.
65
+ - Conflicts: safely mergeable changes merge automatically; changes that could lose information go to the pending-decisions panel. Without a usable model route the newer `updated` stamp wins and the older text stays in Git history. A conflict on an archived entry takes the newer revision and never enters the panel.
66
+
67
+ ## Browser API and settings page
68
+
69
+ - The plugin exposes a `memories` namespace to the browser through Typert, with 10 methods: `overview`, `list`, `add`, `forget`, `promoteSkill`, `discardSkill`, `persona`, `savePersona`, `disputes`, `resolveDispute`.
70
+ - The Memories settings page has four tabs: Memories, Persona, Configuration, and Needs review; the same config card also appears on the Plugins page under this package.
71
+ - A deployment without a gateway (headless, tui) has no settings page; the model tool, `/memories`, and the background maintenance passes work unchanged.
72
+
73
+ ## Limits
74
+
75
+ - Recall is lexical (title, `keys`, `tags`, `appliesTo`, body) with time decay and a one-hop expansion along shared `keys`/`tags` — not vector search; the on-demand gate counts only title, `keys`, `tags` and `appliesTo`. Chinese is handled as character bigrams: a shared run of two characters counts as one strong term. A search that finds nothing does not simply answer "none": the tool lists the `keys`/`tags` vocabulary that shares characters with the query so the model can retry in the store's own words (`suggestAliases`; a vocabulary hint, never a match).
76
+ - An injected memory is what was concluded when it was written, not current truth; use `memory` action=evidence to open the source conversation when it matters.
77
+ - A `snapshot` value expires from when it was measured; do not use one in place of a reading that changes on its own.
78
+ - Extraction and consolidation are quota- and peak-hour aware; neither is guaranteed to have run at any particular moment.
package/docs/DETAIL.zh.md CHANGED
@@ -1,17 +1,78 @@
1
- # 跨记忆
1
+ # 跨记忆:实现说明
2
2
 
3
- 把会话里值得长期保留的内容(偏好、决定、踩坑、承诺)抽取成条目,按项目/会话作用域存进记忆库;后续会话按相关度召回并注入上下文。
3
+ dsh-cross-memory 把会话里值得长期保留的内容(偏好、决定、踩坑、承诺)抽取成条目,按 `global` 与 `project` 两个作用域存进本机记忆库;后续会话按分层预算把记忆注入上下文,模型也可以用 `memory` 工具主动读写。安装、配置项与命令清单见 [README](../README.md),本文说明实现分层与边界。
4
4
 
5
- ## 主要能力
6
- - 抽取:按阶段对会话做抽取与合并,条目带类型、来源与时间。
7
- - 召回:按语义相关度与时间衰减挑选条目注入,可查看命中原因。
8
- - 远端命名空间:向浏览器暴露 8 个方法,设置页可浏览、编辑、归档条目。
9
- - 合并子代理:memories-consolidator 预设,用无工具子代理做去重与合并。
5
+ ## 作用域与条目文件
10
6
 
11
- ## 常用入口
12
- - 设置 → 记忆:浏览、搜索、归档、导入导出。
13
- - /memories 命令:查看与整理记忆库状态。
7
+ - `global` 存跨项目成立的事实,目录是 `$DSH_HOME/memories`;`project` 存只对一个工作区成立的事实,目录是 `$DSH_HOME/memories/projects/<slug>`,同一工作区的任意子目录启动的会话共用这一份。
8
+ - 条目 ID 由标题派生(`slugify(title)`),标题即身份:同名再写是更新,不是新增。
9
+ - 条目文件是 frontmatter + 正文的 Markdown;frontmatter 记 `id`、`scope`、`kind`、`title`、`tags`、`keys`、`appliesTo`、`source`、`created`/`updated`,可选 `durability: snapshot` 与 `asOf`、`pinned`、`permanent`、`voice: user`、`supersedes`、`derivedFrom`;自动抽取的条目另带 `session`(来源会话)、`quote`(逐字引文)与 `evidenceSeq`。
10
+ - 文件是唯一真相,`index.json` 只是可重建的索引缓存,手改或删除后下一次读取会自愈。
14
11
 
15
- ## 注意
16
- - 合并任务只在会话空闲时触发;需要立刻跑用 /memories consolidate。
17
- - 记忆库按项目作用域分目录;搬会话不会自动带记忆条目(需要显式搬)。
12
+ ## 注入分层
13
+
14
+ 每个会话按顺序拿到下面这些块,每块都有自己的预算:
15
+
16
+ 1. `<persona>`:用户画像快照,预算 `personaMaxBytes`(默认 12000 字节,`0` 关闭),超长部分按行截断。旧的单文件 `persona.md` 仍会被读取,保存后写到 `persona/human.md`。
17
+ 2. 记忆摘要:在 `maxSummaryBytes`(默认 4096)内分 `global` 与 `project` 两段;两段共用一个字节预算,`global` 先渲染,另有 `globalSummaryEntries` 与 `globalSummaryBytes` 限制它的大小。
18
+ 3. 增量块:摘要注入之后新写入的记忆以小块补发(`injectDelta`,每会话最多两次、每次 `deltaMaxBytes` 默认 1600 字节;一条完整条目约 200–350 字节,旧的 800 只装得下一两条)。
19
+ 4. 标题轮转:只列摘要没提到的标题,每会话 `rotationEntries`(默认 16)条,同一个长会话里每 `rotationEveryTurns`(默认 8)个用户轮重新发一次。
20
+ 5. 按需补注:当前用户轮与某条记忆的标题、`keys`、`tags`、`appliesTo` 命中足够多的实词(或整句短语命中)才会注入(`recallMinTerms` 默认 2、`recallMinScore` 默认 9、每会话最多 `recallMaxPerConversation` 条);在单个作用域里出现比例超过 `evidenceMaxDf`(默认 0.15)的词不计入证据。严格门没过时还有一道别名回退:只对 `keys` 与 `appliesTo` 计分、只要求一个实词、门槛按 `ALIAS_FLOOR_SHARE`(0.5)缩放(默认 9 的一半),最多补 2 条,注入块里会写明「按别名匹配」。它存在的原因是用户常按「另一个名字」提问,那种回合只共享一个词,会被两词门槛挡掉。门槛必须缩放不能共用:一个中文别名词在这两个字段里最多得 6 分,用同一个 9 分门槛就等于只对英文提问生效。同一别名只登记在一个字段里(3.5 分)仍然不补,正文里的词从不参与这条路径。
21
+ 6. 原始片段:`rawRecall` 打开时,补注块附带来源会话的原文片段,只读本机会话日志。
22
+
23
+ 注入块都写明记忆是背景数据、不是指令,并且记录的是写入时成立的事实,可能已经过期。
24
+
25
+ 记忆目录按项目**目录名**分片(`projects/<slug>`),同一仓库在不同机器的不同路径因此共用一份;代价是同名但无关的两个仓库会共用一个目录。每个宿主记录自己的 git origin,两个不同 origin 出现时,注入块里会带一行冲突警告,指出本会话的项目记忆可能混入另一个仓库的内容。
26
+
27
+ ## 抽取
28
+
29
+ 抽取是第一遍,跑在维护路径上,不碰对话内容:
30
+
31
+ - 会话空闲 `autoExtractIdleMs`(默认 300000 毫秒)后被扫描;`extractIntervalMinutes`(默认 30)另按周期检查所有未结束会话。`minIdleHours`(默认 6)与 `maxAgeDays`(默认 10)决定一条会话还能不能被抽取,每轮最多处理 `maxSessionsPerPass`(默认 2)个会话。
32
+ - 一次抽取读最近 `extractWindowMessages`(默认 60)条消息,只取用户与助手正文,丢弃工具结果和插件注入的内容,避免记忆自噬。
33
+ - 窗口不会跳过消息:未抽取的消息多于一个窗口时,这一轮从最老的一段开始取(`collectExtractionWindow`),水位线逐段推进。按最新一段取会让中间的消息永远落在水位线之下,实测一条 400 条消息的缺口里有 340 条从未被抽取。
34
+ - 喂给抽取器的已知标题按与本窗口的字词重合度排序后取前 80(`selectKnownTitles`),不是按时间取前 80:库大于 80 条时,按时间截断会让抽取器看不见已有条目,从而把同一件事写成第二条。
35
+ - 逐字引文核对失败的候选会记下被丢的标题与引文片段(`no-quote` / `quote-too-short` / `not-in-transcript`),计数之外还能看出是「没给引文」还是「编了引文」。
36
+ - 每条候选记忆必须带一段逐字引文,且引文要能在本次窗口的原文里找到,否则丢弃;落盘前统一做密钥擦除(`sk-…`、`ghp_…`、`AKIA…`、JWT、私钥块、`api_key=…`、`Bearer …` 等)。
37
+ - 后台模型调用受成本与配额保护:`peakHours` 可把后台调用推到谷时(默认空),`pauseOnQuotaError`(默认开)在限流或配额不足后暂停,冷却从 `quotaCooldownMinutes`(默认 30)起逐次翻倍,上限 `quotaCooldownMaxMinutes`(默认 480)。
38
+
39
+ ## 合并与待裁决
40
+
41
+ 合并是第二遍,处理跨会话的矛盾与碎片:
42
+
43
+ - 一批记忆交给一个不含任何工具的子代理(预设 `memories-consolidator`),它只返回严格 JSON 方案;插件自己应用方案,并在应用前留快照,出错的改动可以回滚。部署没有预设注册表时退回一次无工具的普通模型调用。
44
+ - 可以自动执行的是可逆改动:合并重复、收紧措辞、退役从没被读过的条目。可能丢信息的改写与退役进入**待裁决**:人手写、置顶或永久保留的条目,被读到过的退役,丢失正文里文件路径引用或正文不到原来一半的改写,都不会被静默处理。
45
+ - 已在库里的条目不会换作用域,新记忆才由这一遍决定放在 `global` 还是 `project`。
46
+ - 待裁决方案在 `consolidateProposalMaxAgeHours`(默认 72)小时后自动作废;`autoDecide`(默认开)允许 AI 先判断是否丢信息,置信度低于 `autoDecideMinConfidence`(默认 0.7)时仍然留给你。
47
+ - 两条记忆互相矛盾时,子代理把这一对列进冲突报告(保留哪条、丢弃哪条),而不是悄悄挑一个。
48
+ - 合并会维护画像,`persona/human.lock` 存在时跳过;也会把重复流程提成技能草稿(每轮最多 2 个),草稿落在 `memories/skills/<name>/SKILL.md`,`/memories promote` 才复制到 `$DSH_HOME/skills/<name>/SKILL.md`;已晋升的文件比草稿新时,重复晋升会被拒绝。
49
+
50
+ ## 保留与归档
51
+
52
+ - `maxUnusedDays`(默认 90)内没有被读到、没有被注入摘要、也不是新写的记忆会被归档;归档不是删除,`/memories restore` 可以取回。
53
+ - `durability=snapshot` 的条目另按 `snapshotMaxAgeDays`(默认 60)从测量时间起算归档,被读一次不会让读数变新。
54
+ - `maxEntriesPerScope`(默认 1000)是每个作用域的上限,超出时归档最久没有被读到或注入的条目;`pinned`、`permanent` 与 `source=user` 的条目不会被自动退役,所以作用域可能略超上限。
55
+ - 每个作用域的 `archive/` 目录只保留最新的 500 个文件,更早的归档会被清理。
56
+ - `sessions/` 下的证据笔记只保留最新的 200 份,更早的会被清掉;笔记不在时 `evidence` 会直接说明没有这份证据笔记,而不是编造内容。
57
+ - `/memories forget` 与 `memory` 工具的 `forget` 是**物理删除**,不可恢复。
58
+
59
+ ## 存储、日志与多机同步
60
+
61
+ - 条目、证据笔记、画像、反思与技能草稿都是普通文件,可直接读写;水位线、任务租约与用量计数在 `state.db`(Node 内置 `node:sqlite`)。取不到 `node:sqlite` 时水位线只在进程内保存,重启后可能重复抽取已经处理过的会话。
62
+ - 插件日志默认在 `$DSH_HOME/logs/dsh-cross-memory.log`,单文件到 2 MB 轮转一代,旧文件改名为 `<path>.1`,只保留这一代。`npm run report` 只读地汇总日志与 `state.db`。
63
+ - 记忆库本身是 Git 工作副本:写入只做本地提交(`syncDebounceSeconds` 默认 2 秒合并一批),拉取与推送在后台定时进行(`syncClock` 默认 `12:05,18:05`,留空回退到 `syncIntervalMinutes` 默认 10 分钟,`0` 关闭定时器)。同步路径里的任何失败都不会让一次记忆写入失败,也不会把仓库留在 rebase 中间。
64
+ - 记忆库根目录的 `.gitignore` 固定忽略每台机器自己的状态:`state.db`、`state.db-shm`、`state.db-wal`、`index.json`、各级 `**/index.json`、`**/project.json`、`pending/`、`*.log`、`.DS_Store`。
65
+ - 冲突处理:能安全合并的自动合并;可能丢信息的进入**待裁决**;没有可用模型路由时按 `updated` 时间取新版,旧文本留在 Git 历史里。归档条目的冲突按更新时间取新版,不进待裁决。
66
+
67
+ ## 浏览器接口与设置页
68
+
69
+ - 插件通过 Typert 向浏览器暴露 `memories` 命名空间,共 10 个方法:`overview`、`list`、`add`、`forget`、`promoteSkill`、`discardSkill`、`persona`、`savePersona`、`disputes`、`resolveDispute`。
70
+ - 设置页「记忆」有四个标签:记忆、画像、配置、待裁决;同一个配置卡也出现在插件页该包下。
71
+ - 没有网关的部署(headless、tui)只是没有这张页面,模型工具、`/memories` 命令与自动维护照常工作。
72
+
73
+ ## 注意与限制
74
+
75
+ - 检索与召回都是词法匹配,不是向量检索:标题、`keys`、`tags`、`appliesTo`、正文按权重计分,再叠时间衰减与沿共享 `keys`/`tags` 的一跳扩展;按需补注的门槛只认标题、`keys`、`tags`、`appliesTo` 四个字段。中文按字符二元组处理,共享两个汉字记为一次强命中。检索零命中时工具不直接回「没有」:它会列出库里与被查词共享字符的 `keys`/`tags` 词表,让模型用库自己的说法重试一次(`suggestAliases`,只是词表提示,不是匹配结果)。
76
+ - 注入的记忆是写入当时的结论,不是当前事实;需要判断时用 `memory` 的 `evidence` 打开来源会话。
77
+ - `durability=snapshot` 的数字从测量时间起算过期,不要用它代替会自己变化的读数。
78
+ - 合并与抽取都受配额与谷时限制,后台不保证在某个时刻一定跑过。
package/lib/backfill.js CHANGED
@@ -204,6 +204,7 @@ export function planWindows(messages, maxMessages, maxChars) {
204
204
  lastSeq,
205
205
  messages: current.length,
206
206
  sources: current.map((entry) => ({ seq: entry.seq, text: entry.text })),
207
+ skipped: 0,
207
208
  });
208
209
  current = [];
209
210
  cost = 0;
package/lib/client.js CHANGED
@@ -116,7 +116,12 @@ window.__ModuleLoader__.load({
116
116
  {
117
117
  field: 'injectDelta', kind: 'boolean',
118
118
  label: { zh: '会后补注新记忆', en: 'Announce late memories' },
119
- hint: { zh: '摘要注入之后才写入的记忆(例如后台抽取、合并的结果)在下一步用一个很小的块补一次:每个会话最多两次、每次 800 字节,只列新增或更新的条目。', en: 'Memories written after the summary was shown (background extraction, consolidation) get one small block on the next step: at most twice per conversation, 800 bytes each, new or updated entries only.' },
119
+ hint: { zh: '摘要注入之后才写入的记忆(例如后台抽取、合并的结果)在下一步用一个很小的块补一次:每个会话最多两次,只列新增或更新的条目。', en: 'Memories written after the summary was shown (background extraction, consolidation) get one small block on the next step: at most twice per conversation, new or updated entries only.' },
120
+ },
121
+ {
122
+ field: 'deltaMaxBytes', kind: 'number', min: 0, step: 100,
123
+ label: { zh: '补注块字节上限', en: 'Late-memory block bytes' },
124
+ hint: { zh: '每个补注块的字节预算。一条完整条目约 200–350 字节,旧的 800 只装得下一两条;默认 1600 装得下四到六条,才够覆盖一次话题切换。0 关闭补注。', en: 'Byte budget per late-memory block. One complete entry costs 200-350 bytes, so the old 800 admitted one or two; 1600 admits four to six, which is a topic shift rather than a single note. 0 disables the block.' },
120
125
  },
121
126
  {
122
127
  field: 'rotationEntries', kind: 'number', min: 0, step: 1,