dsh-plain-memory 1.1.0 → 1.1.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.
package/README.en.md CHANGED
@@ -5,27 +5,32 @@
5
5
 
6
6
  [中文](README.md) | English
7
7
 
8
- Plain memory for DeepSeek Harness. **Remove it and DSH is unchanged; install it and DSH remembers you and recalls what matters.**
8
+ Plain memory for DeepSeek Harness. **Remove it and DSH is unchanged; install it and DSH keeps what you told it, and can look it up when asked.**
9
9
 
10
- Memory is plain Markdown in your own Git repository. The plugin is 1,141 lines, imports only Node built-ins, calls no model, and runs no periodic timer.
10
+ Memory is plain Markdown in your own Git repository. The plugin is 1,423 lines (blank lines included), imports only Node built-ins, calls no model, and runs no periodic timer.
11
11
 
12
12
  ## What it does
13
13
 
14
- 1. **Asset** — memory lives as Markdown in your private repo; the plugin pulls at session start, commits each write immediately, and pushes in a detached process.
15
- 2. **Multiple windows (experimental, off by default)** — enable with `cards: true`; sessions then exchange a short delta when their cues match. Off by default because a stale card from an already-closed window was observed being pushed back.
16
- 3. **Recall** — each memory carries cue words; every turn matches the user message locally (BM25 over Chinese bigrams plus a small hand-written concept bridge) and injects at most three entries, only above threshold.
14
+ Three things, nothing more:
15
+
16
+ 1. **Asset** — memory lives as Markdown in your own repo; the plugin pulls at session start, commits each write immediately, and pushes in a detached process.
17
+ 2. **Query** — four tools; `memory_recall` reads memory by keyword. This is the default path: **nothing is injected on any turn.** The model calls it when the user refers to earlier work, another window, "last time", or "before".
18
+ 3. **Optional auto-recall** — set `autoRecall: true` and each turn matches the user message locally (BM25 over Chinese bigrams plus a small hand-written concept bridge), injecting at most three entries above threshold. **Off by default; why, below.**
19
+
20
+ **Experimental: multi-window status cards (off by default, `cards: true`)** — sessions exchange a short delta when their cues match. Off by default because a stale card from an already-closed window was observed being pushed back.
17
21
 
18
22
  ## Measured properties
19
23
 
20
24
  | Property | Value |
21
25
  |---|---|
22
- | Plugin source | **1,045 lines** (excluding tests) |
26
+ | Plugin source | **1,423 lines** including blank lines (excluding tests) |
23
27
  | Runtime dependencies | **0** |
24
28
  | Model calls inside the plugin | **0** |
25
29
  | Periodic timers / resident processes | **0** |
26
- | Fixed per-session injection | **≈596 tokens** (four tool schemas) |
30
+ | Fixed per-session injection | **≈487 tokens** (four tool schemas; measured on 1.0.1, schema unchanged since) |
31
+ | Injection per turn by default | **0 entries** (`autoRecall` is off) |
27
32
  | Injection when nothing matches | **zero** |
28
- | One recalled entry | **≈124 tokens** |
33
+ | One recalled entry (only with `autoRecall`) | **≈124 tokens** |
29
34
  | Uninstall | DSH boots normally; the memory repo is untouched byte for byte |
30
35
 
31
36
  Measured against a real `headless` profile with a scripted mock model server, from the actual `/v1/messages` request bodies. See `test/e2e/measure.mjs`. Token counts are estimates, not a provider tokenizer.
@@ -33,10 +38,15 @@ Measured against a real `headless` profile with a scripted mock model server, fr
33
38
  ## Verification
34
39
 
35
40
  - **Prompt cache**: over three consecutive turns in one session, turn 2's message array is a byte-identical prefix of turn 3's; injection only appends.
36
- - **Cross-domain recall**: 5/5 probes hit, 0 false recalls on 6 unrelated questions — note that probes and concept bridge share an author, so this is not independent validation.
37
41
  - **Git does not block**: with an unreachable remote the turn takes 3,051 ms vs 2,989 ms baseline (−62 ms); push runs in a detached child.
38
42
  - **Concurrency**: two processes writing ten entries each land 20/20, one commit, clean tree.
39
43
 
44
+ ### Auto-recall, when you enable it
45
+
46
+ Offline replay over 40 days of real queries: injected items 192 → 24, zero-injection turns 29% → 87%, one repeated deadline entry 15 hits → 1. Then 20 injected memories were hand-labelled: **precision 7/20**. At that precision a default-on injection is a net negative, which is why it ships off.
47
+
48
+ With auto-recall on, the cross-domain probe (5 "experience in one vocabulary, ask in another" pairs) hit 5/5 with 0 false recalls on 6 unrelated questions — but the probes and the concept bridge share an author, so this is **not** independent validation, and that run used the older `minCues=1` default (2 since 1.1.0).
49
+
40
50
  ## Install
41
51
 
42
52
  ```sh
@@ -74,3 +84,4 @@ Restart DSH. **Rollback**: delete that row, `dsh plugin --profile desktop remove
74
84
 
75
85
  MIT
76
86
 
87
+
package/README.md CHANGED
@@ -7,16 +7,19 @@
7
7
 
8
8
  DSH 原生的轻记忆。**拔掉它,DSH 一点没变;装上它,DSH 记得你、需要时想得起来。**
9
9
 
10
- 记忆是纯 Markdown,放在你自己的 Git 仓库里。插件本体 1,141 行,只 import Node 内置模块,不调用任何模型,不起任何周期定时器。插件页显示名为「原味记忆」(`locale/zh.json`),包名与仓库名仍是 `dsh-plain-memory`。
10
+ 记忆是纯 Markdown,放在你自己的 Git 仓库里。插件本体 1,423 行(含空行;`index.js` 819 + `memory.js` 418 + `git.js` 120 + `cards.js` 70),只 import Node 内置模块,不调用任何模型,不起任何周期定时器。插件页显示名为「原味记忆」(`locale/zh.json`),包名与仓库名仍是 `dsh-plain-memory`。
11
11
 
12
12
  当前进度、生产实测数据与已知缺陷见 [PROGRESS.md](PROGRESS.md)(2026-11-18 快照)。
13
13
 
14
- ## 为什么又做一个记忆插件
14
+ **反馈入口**:[GitHub Issues](https://github.com/simin-yuan/dsh-plain-memory/issues) — 装上遇到问题、或者觉得某条记忆该被想起却没想起,都直接开 issue,附上提问原文和当时的上下文。
15
15
 
16
- 我读过主流的一批 DSH 记忆插件(只读、未安装)。它们大多在往「更重」的方向走:几万行代码、内置模型调用、后台巩固、SQLite 或向量库。而这里做的是**减法**——留两件核心事,外加一个实验功能,其余全部留给 DSH 自己:
16
+ ## 这里只做三件事
17
+
18
+ 其余全部留给 DSH 自己:
17
19
 
18
20
  1. **资产**:记忆是纯 Markdown,存在你自己的 Git 仓库;会话开头自动 pull,写入当场提交,推送在后台,不挡对话。
19
- 2. **唤起**:写记忆时顺手写线索词;之后用用户消息在本地做 BM25 匹配,命中才注入。
21
+ 2. **查询**:四个工具,其中 `memory_recall` 按关键词读记忆全文——用户提到以前的工作、其他窗口、「上次」「之前」时,模型先调它。**这是默认的记忆入口,每轮不注入任何东西。**
22
+ 3. **自动注入(可选,默认关闭)**:配 `autoRecall: true` 打开,按线索词在本地匹配,最多 3 条追加在消息末尾。为什么默认关,见「自动注入默认关闭」一节。
20
23
 
21
24
  **实验功能:多窗口状态卡(默认关闭,`cards: true` 才开)**——每个会话写一张状态卡,别的窗口用同一套线索匹配去查,过阈值才推 1–2 行增量。卡 24 小时过期。已知问题见「边界」,默认不开。
22
25
 
@@ -24,32 +27,32 @@ DSH 原生的轻记忆。**拔掉它,DSH 一点没变;装上它,DSH 记得
24
27
 
25
28
  | 指标 | 实测 |
26
29
  |---|---|
27
- | 插件源码 | **1,141 行**(`index.js` 634 + `memory.js` 347 + `git.js` 101 + `cards.js` 59,不含测试);统计命令见文末 |
30
+ | 插件源码 | **1,423 行**(含空行:`index.js` 819 + `memory.js` 418 + `git.js` 120 + `cards.js` 70,不含测试);统计命令见文末 |
28
31
  | 运行时依赖 | **0**(只 import `node:fs` / `node:path` / `node:os` / `node:crypto` / `node:child_process` / `node:url`) |
29
32
  | 插件内模型调用 | **0**(全仓无 LLM 客户端、无 `fetch`、无 API 调用) |
30
33
  | 周期定时器 / 常驻进程 | **0**(只有 `index.lock` 退避时的一次性 sleep;push 是分离子进程,不是常驻) |
31
- | 每会话固定注入 | **≈487 token**(4 个工具 schema,约为单轮请求的 2.8%) |
32
- | 自我层 | 取决于你自己的条目:实测 4 条约 347 token(约 2.0%) |
34
+ | 每会话固定注入 | **≈487 token**(4 个工具 schema;1.0.1 实测,之后工具 schema 未变) |
35
+ | 默认每轮注入 | **0 条**(`autoRecall` 默认关;开着也只在命中时注入) |
36
+ | 自我层 | 取决于条目;写入时按 400 token 把关,超过拒绝写入并提示合并 |
33
37
  | 无相关内容时 | **零注入**(空记忆仓、无窗口更新时,请求体里没有任何注入消息) |
34
- | 单次召回注入 | 1 条实测 **≈124 token**;上限 3 条,整块裁剪到 700 token 以内 |
38
+ | 单次召回注入(仅在打开 `autoRecall` 后) | 1 条实测 **≈124 token**;上限 3 条,整块裁剪到 700 token 以内 |
35
39
  | 卸载 | 去掉 patch 后正常启动,记忆仓一个字节不变 |
36
40
 
37
41
  测量方法:真 DSH `headless` profile + 真 agent loop + 脚本化的假模型服务器(零 token 成本),从实际发出的 `/v1/messages` 请求体里量。见 `test/e2e/measure.mjs`。token 数是估算(中文按 1 字 1 token、ASCII 按 4 字符 1 token),不是提供方分词器。
38
42
 
39
- ## 四项验证
43
+ ## 两项验证(与注入无关的那两项)
40
44
 
41
45
  | 验证 | 结果 |
42
46
  |---|---|
43
47
  | **提示缓存**:同一会话连续 3 轮,比较请求里的消息数组 | 第二轮 3 条是第三轮 5 条的**逐字节前缀**;注入只追加在末尾,历史一条不改 |
44
- | **跨领域唤起**:5 组「经历一套词、提问另一套词」 | **5/5 命中**,6 条无关提问**误召回 0**。注意:用例与概念桥是同一作者写的,**不是**独立验证;且这组实测跑在 `minCues=1` 的旧默认下(1.1.0 起默认 2) |
45
48
  | **git 卡死**:远端指向不可达地址(TEST-NET-1) | 基线 3,051 ms / 不可达远端 2,989 ms(差 −62 ms);回合照常结束,push 不挡对话 |
46
49
  | **并发写入**:两个进程同时各写 10 条 | **20/20 落盘**,无报错,1 个提交覆盖两边,工作区干净 |
47
50
 
48
- 命令:`node test/e2e/cache.mjs`、`cross-domain.mjs`、`git-block.mjs`、`concurrency.mjs`(前两个需要 `DSH_APP_HOME`)。
51
+ 命令:`node test/e2e/cache.mjs`、`git-block.mjs`、`concurrency.mjs`(第一个需要 `DSH_APP_HOME`)。跨领域唤起那一组实测见「自动注入默认关闭」。
49
52
 
50
53
  ## 它怎么工作
51
54
 
52
- **注入方式**:每轮只往消息末尾**追加**一条 user message(`agent/pre-step` 瀑布),不改 system prompt、不改历史前缀,所以提供方的提示缓存不整段失效。非首步不重复注入;没命中就什么都不加;同一条记忆在同一窗口只注入一次。
55
+ **注入方式**(1.1.2 起默认关闭,见「自动注入默认关闭」):每轮只往消息末尾**追加**一条 user message(`agent/pre-step` 瀑布),不改 system prompt、不改历史前缀,所以提供方的提示缓存不整段失效。非首步不重复注入;没命中就什么都不加;同一条记忆在同一窗口只注入一次。
53
56
 
54
57
  **自我层**:`self.md` 的内容同步进 `$DSH_HOME/AGENTS.md` 里一段带标记的托管块,DSH 原生在每个会话开始加载它,所以「你是谁、你的偏好」开局就在,不需要先命中一次。托管块只改标记之间那一段,`AGENTS.md` 里你自己的内容不会被碰。
55
58
 
@@ -57,7 +60,7 @@ DSH 原生的轻记忆。**拔掉它,DSH 一点没变;装上它,DSH 记得
57
60
 
58
61
  > 为什么默认关闭:2026-11-14 的真机实测里,B 窗口问「另一个窗口的报价说明写到哪了?」,实际收到的是**上一次测试遗留的同句卡片**(回声),而不是 A 窗口的工作卡——A 的卡对这句话只重合「报价说明」一个概念,分数不够。回声过滤能挡住逐字重复,挡不住「已关闭窗口留下的过时卡」。「不打扰」是最核心的承诺,所以这一项默认不开。
59
62
 
60
- **跨领域唤起**:写记忆时写 `cues`(线索词),巩固时把它们写得更抽象。之后每轮用用户消息做本地匹配:中文二元组 + 停用词,0–1 归一分,默认阈值 0.3,且**至少要 2 个独立线索**(`minCues` 默认 2)。自动注入**不按句切开**——切句会让「三个字的一段刚好碰上一个词」拿到接近 1.0 的分,是噪声的主要来源;按句切分只留给主动查询 `memory_recall`。23 组手写概念桥(评委/评审、转圈/卡住)也只在主动查询里生效。
63
+ **跨领域唤起(仅在打开 `autoRecall` 后)**:写记忆时写 `cues`(线索词),巩固时把它们写得更抽象。打开后每轮用用户消息做本地匹配:中文二元组 + 停用词,0–1 归一分,默认阈值 0.3,且**至少要 2 个独立线索**(`minCues` 默认 2)。自动注入**不按句切开**——切句会让「三个字的一段刚好碰上一个词」拿到接近 1.0 的分,是噪声的主要来源;按句切分只留给主动查询 `memory_recall`。23 组手写概念桥(评委/评审、转圈/卡住)也只在主动查询里生效。
61
64
 
62
65
  **日期会过期**:记忆可以带 `- expires: YYYY-MM-DD`。只有带明确截止日期的事(截止/交稿/deadline)才自动填,观察日期(某天实测)不填。过期后整条不再参与召回,不用等人来清理。
63
66
 
@@ -81,10 +84,25 @@ dsh plugin --profile desktop add <本仓库路径或 git URL>
81
84
  name: 'dsh-plain-memory'
82
85
  config:
83
86
  repoPath: 'C:/Users/you/memory-repo' # 你的记忆仓本地 clone
87
+ # autoRecall: true # 想开自动注入再加这一行(默认关闭,原因见下)
84
88
  ```
85
89
 
86
90
  重启 DSH。插件会在 `repoPath` 不存在时创建最小骨架(`README.md` + `self.md`),但**不会**替你建仓库或加远端。
87
91
 
92
+ ### 自动注入默认关闭(1.1.2 起)
93
+
94
+ **默认 `autoRecall: false`:每轮不注入任何东西,记忆靠 `memory_recall` 主动查。** 自我层照常进 `AGENTS.md`,跨窗口共享照常。
95
+
96
+ 为什么默认关:我们拿 40 天真实使用日志做过离线重放,把噪声压到原来的 1/8 之后,抽样 20 条"被注入的记忆"人工判,**注入精度是 7/20**(两条边界项按最宽算也只有 9/20)。这个精度下,"不用主动查"的便利是负价值——每 20 次注入里有 13 次是噪声,用户第一感觉会是"乱塞东西"。所以默认安静,把开关留给想要的人。
97
+
98
+ 打开方式:上面 `config` 里加 `autoRecall: true`。打开后每轮按线索词召回最多 `maxRecall`(默认 3)条,追加在消息末尾,不改历史。
99
+
100
+ 重放数据(同一批 173 条真实提问):注入 192 → 24 条,零注入轮次 29% → 87%,某条过期截止日记忆 15 → 1 次。
101
+
102
+ 开回自动注入之后,跨领域唤起那组用例(5 组「经历一套词、提问另一套词」)是 **5/5 命中、6 条无关提问 0 误召回**——但注意:用例与概念桥同一个作者写的,**不是**独立验证;且那组实测跑在 `minCues=1` 的旧默认下(1.1.0 起默认 2)。
103
+
104
+ ## 记忆仓
105
+
88
106
  **回滚**:从 `cordis.patch.yml` 删掉 `id: plain-memory` 那一行,再 `dsh plugin --profile desktop remove dsh-plain-memory`,重启。记忆仓保留,DSH 行为与装之前完全一致。
89
107
 
90
108
  ## 记忆仓
@@ -153,3 +171,4 @@ node -e "const fs=require('fs');for(const f of ['index.js','memory.js','git.js',
153
171
 
154
172
  MIT
155
173
 
174
+
package/index.js CHANGED
@@ -50,6 +50,9 @@ export function normalizeConfig(config = {}) {
50
50
  maxRecall: Math.min(5, positive(config.maxRecall, 3)),
51
51
  minScore: positive(config.minScore, 0.3),
52
52
  cardScore: positive(config.cardScore, 0.3),
53
+ // 自动注入默认关闭(1.1.1 起):验收实测注入精度 7/20,开着等于每 20 次注入 13 次噪声。
54
+ // 打开 = 每轮按线索召回最多 maxRecall 条;关闭 = 每轮零注入,靠 memory_recall 主动查。
55
+ autoRecall: config.autoRecall === true,
53
56
  // 多窗口状态卡默认关闭(实验性):只写卡、不推送时,/state 里不会多出任何注入
54
57
  cards: config.cards === true,
55
58
  // 默认 2:至少两个独立线索才算想起来(与 memory.js 的 MIN_MATCHED_TERMS 一致)。
@@ -606,8 +609,8 @@ export function apply(ctx, config = {}) {
606
609
  auditInjection(st)
607
610
  finalizeUsed(st)
608
611
  touchCard(st)
609
- const recalled = await recallLines(st, text)
610
- const cards = opts.cards ? cardLines(st, text) : []
612
+ const recalled = opts.autoRecall ? await recallLines(st, text) : { lines: [], hits: [] }
613
+ const cards = opts.autoRecall && opts.cards ? cardLines(st, text) : []
611
614
  const lines = [...recalled.lines, ...cards]
612
615
  if (lines.length === 0) return decision
613
616
  st.injected += 1
@@ -780,7 +783,7 @@ export function apply(ctx, config = {}) {
780
783
 
781
784
  ctx.tools.register({
782
785
  name: 'memory_recall',
783
- description: '按关键词读记忆全文(只读)。注入被截断时用它。',
786
+ description: '按关键词读记忆全文(只读)。用户提到以前的工作、其他窗口、「上次」「之前」时,先调用它。自动注入默认关闭,所以它是记忆的主要入口。',
784
787
  parameters: {
785
788
  type: 'object',
786
789
  additionalProperties: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plain-memory",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "原味记忆(plain memory):DSH 原生的轻记忆。记忆是纯 Markdown,放在你自己的 Git 仓库;多窗口状态卡(实验性,默认关闭);需要时想得起来。零运行时依赖、零模型调用、零周期定时器。",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -47,3 +47,5 @@
47
47
  "license": "MIT"
48
48
  }
49
49
 
50
+
51
+