@yolk_vat-y/dsh-project-memory 0.6.5 → 0.6.7

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/CHANGELOG.md CHANGED
@@ -1,3 +1,197 @@
1
+ ## 0.6.7 (2026-10-28)
2
+
3
+ **兼容**:无新增配置键,也没有破坏性的 store 变更——条目上只多一个可选的 `explicit` 标记(旧条目缺省即按非显式处理)。一处判据语义变化:原生 Windows 壳现在签 `windows` 而不是 `wsl`,写了 `guard.hosts: ['wsl']` 又想覆盖原生 Windows 命令的条目要改成 `windows`。老 profile 与旧 store 直接升级。
4
+
5
+ ### 修复:Windows 上重启后的残留写锁把写入永久挡死(且默认静默)
6
+
7
+ 锁的"pid 复用"判定只读 `/proc/<pid>`(Linux-only),Windows 上 `processStartMs()` 恒为 `null`;而 `lockIsStale()` 对"同机 + pid 存活"是绝不回收。于是崩在写盘途中、或断电/强杀留下的 `.write.lock`,在重启后一旦旧 pid 被系统服务复用,就永远被当成"活锁":`save()` 每次返回 `false`(`lastSaveOk=false`,但按设计默认不打印),重试 5 次(≈20s)后放弃,退出 flush 也拿不到锁——记忆静默丢失,只能手删 `.write.lock` 或重启 dsh。现在锁内容多一个 `boot`(`Date.now() - os.uptime()*1000`);`at`/`boot` 早于本次开机即判残留。**这条只对同机锁生效**:跨机锁仍只按 mtime 判(网络盘上另一台机器的 `at` 早于本机开机是常态,套用会抢掉真正在写的机器——原作者"宁可等也不能双写"的取舍保留)。另加 `acquireDirLock({ maxHoldMs })` 兜"同一次启动内 pid 被复用":`save()` 传 10 分钟,默认 `0` 表示不设上限、维持原契约。
8
+
9
+ ### 修复:`when.writes` / `guard.paths` 在 Windows 路径上永不命中
10
+
11
+ 写入期 `normalizeCitationFiles()` 把 `writes` 归成项目相对、`/` 分隔;匹配侧却只比"整串相等"与"basename",于是候选是 `D:\proj\src\a.ts`(工具参数)或 `src\util\fs.js`(模型的常见写法)时,带目录的判据一个都不命中——能命中的只有裸文件名。现在两侧都先把 `\` 归一成 `/`,判据除整串相等外再按**路径分段边界**匹配后缀(`(?:^|/)…$`);`notlib/a.ts` 仍不会被 `lib/a.ts` 命中,`src/*.ts` 这类 glob 对绝对候选也成立。路径 token 抽取(`util/path-token`)同样认两种分隔符并统一输出 `/`,`intentText()` 剥引用时也不再漏掉反斜杠写法。
12
+
13
+ ### 修复:动作面认不出 Windows 命令形态
14
+
15
+ `npm.cmd run bench`、`node scripts\bench.mjs`、`del`/`copy`/`move`/`Set-Content`、`pwsh -Command "git push"`、`cmd /c npm publish`、`"C:\Program Files\nodejs\npm.cmd" publish` 全部退化成兜底 op `shell-run`:`trigger.when.ops` 里的 `run-bench` / `file-delete` / `git-push` / `npm-publish` 因此永不触发,反而落进 `shell-run` 的误召面。现在命令头剥两种分隔符与 `.exe/.cmd/.bat/.com/.ps1`,`pwsh|powershell|cmd` 进外壳递归(认 `-c` / `-command` / `/c`),补一组 Windows 写盘命令,`bench`/`render` 的路径类正则也认 `\`,`2>nul` 不再当成写文件。
16
+
17
+ ### 修复:原生 Windows 壳被标成 `hosts: ['wsl']`
18
+
19
+ `pwsh.exe` / `cmd.exe` 的命令文本被当成 WSL 签名,于是 `guard.hosts: ['wsl']` 的条目在原生 Windows 上会被放行(它本该只在 WSL 里生效)。现在原生壳签 `windows`,只有 `/mnt/c/…` 这类路径才签 `wsl`。**已存条目**若写了 `hosts: ['wsl']` 却想覆盖原生 Windows 命令,需要改成 `windows`;WSL 签名的含义没变。
20
+
21
+ ### 修复:同一个 store 因大小写不同建出两份实例
22
+
23
+ `storeCache` 用 `path.resolve(dir)` 当键:`D:\proj\.dsh-project-memory` 与 `d:\PROJ\.DSH-PROJECT-MEMORY` 在 Windows/macOS 上是同一个目录、字符串却不同,于是并存两个实例——双份内存,且一边未落盘的条目另一边看不见(`load()` 从盘上读)。现在多一层 `storeKey()` 别名表做命中,缓存键本身仍是真实解析路径(告警与诊断输出里的路径不变形),逐出时别名一起删。
24
+
25
+ ### 修复:`git` 子进程在 Windows GUI 宿主里闪控制台窗
26
+
27
+ `execFileSync('git', …)` 没传 `windowsHide: true`。Electron 打包的 dsh 没有控制台时,每次 `index_repo`(`git ls-files`)与 `isGitIgnored()`(`git check-ignore`)都可能闪一个窗口。
28
+
29
+ ### 修复:带 UTF-8 BOM 的 SKILL.md 解析不出 frontmatter
30
+
31
+ 记事本保存的 `SKILL.md` 以 `\uFEFF` 开头,`^---` 匹配不上,frontmatter 整段被忽略,skill 的 name / description 静默回落默认值。现在解析前先剥掉 BOM。
32
+
33
+ ### 修复:`when.writes` 里的 `?` 让整个 pre-step 注入静默失效
34
+
35
+ glob 只支持 `*`,但 `?` 没转义;模式以 `?` 开头(`?.md`)时 `new RegExp('^?…')` 抛 `SyntaxError`,而它在每步的 `collectTriggered` 里,异常被 pre-step 兜住后 trigger + 提示 + 任务卡全部不注入。现在 `?` 按字面量转义。
36
+
37
+ ### 修复:长中文消息在 `intentText` 里回溯爆炸
38
+
39
+ 非 ASCII 文件名的正则用两条 `\S*` 夹字符类;无空格、无 ASCII 点的长中文串(4000 字实测 12s)会把一步 pre-step 卡住。改成按 token 判断,线性。
40
+
41
+ ### 修复:`guard.paths` / `not_paths` 不认人类消息里的写意图
42
+
43
+ `when.writes` 用「已观察写调用 ∪ 人类消息路径」,guard 只看前者:人类说"改 `src/x.js`"时,带 `guard.paths: ['src/x.js']` 的条目永远不放行,`not_paths` 也挡不住。两处现在共用同一份写目标。
44
+
45
+ ### 修复:超大文档先整份读入再拒绝
46
+
47
+ `planFileIndex` 的体积闸门只对代码文件生效,文档的检查在 `extractTextFromFile` 里——那时 `readFileForIndex` 已经把整份文件读进内存(300 MB 实测 +300 MB RSS),watch 每轮重付一次。现在按 size 在读盘前统一判 `OVERSIZE`。
48
+
49
+ ### 修复:显式 `index_doc` 的 .gitignored 文件被下一轮扫描删掉
50
+
51
+ 扫描清单来自 `git ls-files`(不含被忽略的文件),清理把"没扫到"当成"已删除",于是显式索引的文档活不过下一轮 watch / index_repo。现在 `index_doc` 在记录上打 `explicit`;清理时,显式索引且文件仍在盘上的条目跳过,文件真被删了仍会清。
52
+
53
+ ### 修复:非锁原因的写盘失败没反映到状态与退出 flush
54
+
55
+ `save()` / `GlobalStore.commit()` 的写事务只有 `finally`:EISDIR / ENOSPC 等异常直接抛出,`lastSaveOk` 仍为 true,脏 store 也不在退出 flush 的登记表里。现在异常路径置失败标志并登记,故障消失后同一份脏数据会补写。
56
+
57
+ ### 修复:锁文件不可读时 `acquireDirLock` 忙等
58
+
59
+ 锁文件存在但读不出来(EACCES、或该路径是个目录)时,抢锁循环既不 sleep 也不看 deadline,会把事件循环按住直到它变得可读。现在按 10ms 间隔重试,到 deadline 返回 `null`(调用方按"这次没拿到锁"处理)。
60
+
61
+ ### 修复:watch 的 mtime 快照不清理已删除的文件
62
+
63
+ `pollRoot` 只往 `state.snapshot` 里写、从不删,删掉或改名的文件会一直留在里面;文件若以同样的 `mtime:size` 回来,就会被当成"未变"而永远不重建。现在扫全的轮次里同步剪掉本轮没见到的键(截断轮不剪,与 store 的 `unseen` 同一口径)。
64
+
65
+ ### 修复:`npm run bench` 不算 `run-bench`;全局 flag 之后的子命令不识别
66
+
67
+ 只认 `scripts/bench.mjs` 这类带路径的参数,README 里的 `npm run bench` / `npm run bench:peak` 全部漏召(`when.ops: ['run-bench']` 的条目永不触发)。现在 npm script 名本身也算;`pnpm -C x run bench` / `npm --prefix . publish` 这类"全局 flag 在子命令之前"的写法也一样识别。顺带:`bash -lc` / `sh -ec` 的合并短选项也会递归解析。
68
+
69
+ ### 修复:非 Node 项目的 projectTags 缓存永不命中
70
+
71
+ 缓存用 `package.json` 的 mtime 做键,没有这个文件时 `stat` 抛错,于是每次调用都重读 go.mod / Cargo.toml。现在键是三份清单的 mtime(缺失记 `-`),Go / Rust 项目也能命中缓存,清单变化仍会失效。
72
+
73
+ ### 修复:俄语查询在 insight / experience 层被重复词干
74
+
75
+ Snowball 词干不幂等(`память → памя → пам`)。`recallItems()` 先把查询 tokenize 成词干、打分器又 tokenize 一次,导致俄语 lesson / decision / experience 的单字/多字查询大量查不到(doc 层不受影响)。现在 `gatedQueryText()` 用 `tokenizeRaw(..., { stem: false })` 只做过滤,真正的打分器词干一次。回归直接走 `recallItems()` 的 insight 与 experience 两个桶。
76
+
77
+ ### 修复:store 目录 / `.gitignore` 被外部删除后不自愈
78
+
79
+ `_storeDirReady` 缓存把“上次写过”当成“这次还在”,目录被 `git clean -fdx` / 用户清理后锁永远拿不到,写盘一直失败;`_selfIgnoreReady` 同理会把 store 留在 git 可提交状态。现在 dirty save 命中缓存时补一次目录 stat,失配就重建并让 shards / format / ignore 三处状态失效;`acquireDirLock(ensureDir:false)` 也在 `ENOENT` 上补建一次。自我忽略不再缓存“已存在”。
80
+
81
+ ### 修复:向量运行时并发加载 / 目录切换互相 close
82
+
83
+ 新增 `runtimeLoading` 单飞:同一 `(dir, fingerprint)` 的冷启动只 `loadLeanvec()` 一次。换运行时前先清掉引用旧 `lv` 的 indexCache,再 close 旧 fd;索引缓存 key 带上运行时目录,避免用旧闭包服务新目录。并发 injection + 写入去重、或同一模型内容从两个路径加载,都不会再静默退化成空向量。
84
+
85
+ ### 修复:多实例下任务级条目合并丢更新
86
+
87
+ 任务级 insight 的增删/编辑不 bump `task.updatedAt`,按整条任务时间戳选一侧会丢另一边的新增。现在用上次成功落盘时的 insight id 基线做三方合并:新增补写、本地删除不复活、同 id 取 `updatedAt` 新者。整条任务删除的墓碑逻辑不变。
88
+
89
+ ### 修复:watch 异步轮询的定时器重复 / stop 后扫描
90
+
91
+ 异步 `poll()` 期间 `setSessionActive()` 会先排一个定时器,`_tick()` 结束又排一个并覆盖句柄,导致待触发定时器翻倍、`stop()` 只能清掉一个。现在 `_tick()` 只在没有待触发定时器时续排,入口与结束都检查 `_stopped`;`start()` 在轮询中不重复排。
92
+
93
+ ### 修复:旧 source 形状的自注入被当成人类消息
94
+
95
+ `isOwnInjection()` 认迁移前 `{ plugin: 'dsh-project-memory' }` 形状,但 `installCallObserver()` 只判 `source.kind`,于是自己的注入块进入 `humanText`,下一步拿它当 query(自激)。现在 observer 与 `lastUserText()` 共用同一个自注入判据。
96
+
97
+ ### 修复:俄语意图词未归一 ё / 词形
98
+
99
+ `isIntentWord()` 会归一,`matchIntent()` 却拿原文做字面匹配:`ёлка`/`елка`、`миграция`/`миграции` 都不命中。现在两侧先 `normalizeRuWord()` 做词边界精确匹配,未命中再按 Snowball 词干比对词形;`город` 仍不命中 `городской`(词干不同)。
100
+
101
+ ### 修复:global store 退出 flush 计数
102
+
103
+ `GlobalStore.flushPending()` 返回 `commit()` 的 `fn` 返回值(通常 undefined),`flushDirtyStores()` 把已成功落盘的 global store 计成 0。现在显式返回 `lastCommitOk`。
104
+
105
+ **测试**:`npm test` **885 项 / 50 个文件**全绿;`npm run typecheck` 通过。新增 `test/windows-compat.test.mjs`(11 项:跨开机残留锁、跨机锁不被误伤、`maxHoldMs`、反斜杠/绝对路径的 `writes` 与 `guard`、Windows 命令形态、`hosts`、路径 token、store 缓存键、BOM;判据都在字符串/时间层面,Linux CI 同样能跑,"同实例"那条按 `win32/darwin` 分支断言)与俄语词干固定样例 `test/fixtures/ru-stems.json`(200 个词形,与 snowballstemmer 3.1.1 一致)。
106
+
107
+ ## 0.6.6 (2026-10-27)
108
+
109
+ **升级注意**:这是一次**行为变更**——注入会变少。没有新增配置键、没有 store 格式变更,老 profile 直接升级。变化只在"什么时候允许全文注入":子代理提示词、其它工具的参数、后台任务 / 子代理通知,以及人类消息里的删除 / 清理 / 渲染 / 基准类词,不再触发全文注入。
110
+
111
+ ### 修复:注入的"这一步在做什么"取错了来源
112
+
113
+ **证据**(用插件自己的审计日志复盘一次真实会话——作者在插件仓库里跑 30–40 分钟审计,含 4 个子代理):17 次注入 / 8,654 字符,可判定与本步任务无关 **6.2k(72%)**。其中:
114
+
115
+ - `find src client test scripts bench docs -type f` → `run-bench`(只是目录名 `bench`),4 条基准 procedure、1,777 字符;
116
+ - 子代理提示词里的"删除后的悬空状态""版本迁移" → 父会话 `file-delete` / `migrate` 连续 8 步;
117
+ - 子代理报告里的"发布 / 渲染" → `intent:release`(1,050 字符)/ `intent:渲染`(1,200 字符);
118
+ - 旧一代 shadow 日志 386 行里只有 **31 步(8%)**有非空 query:会话中段根本没有真人消息。
119
+
120
+ **根因与改法**:
121
+
122
+ 1. `agent/pre-step` 的 `messages` 是宿主的 claimed **delta**,不是完整历史。旧实现把 delta 里最后一条 user 消息当"人的话",于是 `agent-message`(子代理报告)/ `subagent-settled` / `tool-jobs` / `time-context` 都成了查询。现在 `lastUserText` 只认 `source.kind === 'user'` 或无 source 的老宿主;每会话缓存最后一条真人消息(`session/event` + `user/message`),delta 里没有就回退到它。shadow 新增 `querySource: delta|session|none`。
123
+ 2. 动作面只从**结构化工具调用**归一(`activityFromCalls`);`injectForStep` 不再把全部 observed 调用拼成 `actionText`。`subagent` / `remember` / `save_lesson` 的参数不再变成父会话的动作。
124
+ 3. `classifyShellCommand` 改成**分段 + 命令头匹配**:剥 heredoc、跳过 `sudo` / `env` 包装、引号内的 `>` 不算重定向、`bash -c` 递归一层。目录名、grep pattern、`node -e` 正文里的词不再是动作。
125
+ 4. 人类消息里的动作词分级:只有不可逆外部动作(`git-commit` / `git-push` / `npm-publish` / `release` / `deploy` / `go-public`)允许先发;`删除 / 清理 / 渲染 / 基准 / 取网页` 只记进 `opsIntent`(shadow 可见),不触发全文。观察到的 `rm` 仍然触发。
126
+ 5. `buildReadinessContext` 不再被二次归一:`buildInjection` 收到已构建的上下文时只补 tags,避免第一遍的 `actions` 输出在第二遍被当成"调用方声明的动作"重新信任(否则散文里的 `file-delete` 会绕过过滤)。
127
+
128
+ **已知残留**(下一版,单独提交):legacy trigger 的 `keywords` 被归一成 `when.intents` 后仍会匹配散文("清理一下 README 的措辞"可能命中一条 `keywords:['清理']` 的条目)。把"legacy 派生词 → hint-only"需要重标 `readiness-eval` 与 `eval:injection` 基线。
129
+
130
+ ### 修复:跨进程写的三条数据安全问题(多开 dsh)
131
+
132
+ **背景**:审计给出三条可复现缺陷,全部发生在"两个 dsh 实例共用一个 store"这个插件明确支持的场景里。
133
+
134
+ 1. **锁可被抢,release 无所有权校验**。旧锁只有 mtime:持锁超过 10s 就被第二个进程当成死锁抢走;原持有者到点 release 又无条件 unlink,把对方的锁删掉,第三个进程随即进入——实测三者同时"持锁"。
135
+ 现在锁内容带 `{pid, host, token, at}`:同机 pid 活着就绝不回收(Linux 上再用 `/proc/<pid>` 的启动时刻识别 pid 复用);release 校验 token,不删别人的锁。
136
+ 2. **崩溃残留锁 + 重试预算 < staleMs → save 静默跳过,工具仍报成功**。旧逻辑 3 次重试 ≈ 8.3s,永远够不到 staleMs=10s;失败只 `console.error`,工具照样返回 "Saved …"(实测 `insights.json` 根本没生成)。
137
+ 现在同机死 pid 的锁**立即回收**;`save()` / `GlobalStore.commit()` 返回失败并置 `lastSaveOk` / `lastCommitOk`,但**默认静默**——记忆写入是幂等的、失败成本低,终端与回复里的提示已经够多。**正确性不靠重试**:写路径默认同步等锁最多 **15s**(另一个进程的写通常只有毫秒级);仍失败才进入后台重试,并且进程退出 / 插件卸载时还有一次同步 flush(`src/util/flush.js`)——用户结束对话就会关 dsh,不会等 20s 的重试。需要排查时设 `DSH_PROJECT_MEMORY_DEBUG=1` 才打印一行(每个 store 每进程一次)。
138
+ 3. **跨进程删除被复活**。A 加载后持有旧快照,B `forget` 落盘,A 下一次 save 把"磁盘没有但内存有"当成"本地新增"写回——"真删、无撤销"的承诺失效(任务同形;global 层同形)。
139
+ 现在合并规则是:磁盘缺失的条目只有**本进程新建**的才补写,否则视为对方已删、从内存里丢掉。顺带修掉一个更直接的变体:`tasks` 合并从不清理 `_deletedTaskIds`,删任务会在**同一次 save 里**被自己刚读到的磁盘副本写回来。
140
+
141
+ **测试**:新增 `test/store-lock.test.mjs`(10 条,含两个真子进程的删除复活回归、同步等锁与退出 flush)。`npm test` **835 项 / 48 个文件**全绿。
142
+
143
+ ### 新增:把用法做成宿主 skill
144
+
145
+ `skills/project-memory/`:`SKILL.md`(唯一事实源,frontmatter 提供 name / description,注册时剥掉)+ `scripts/pm-digest.mjs`(零依赖体检:store 大小、insight / 任务计数、trigger 覆盖、绑定数)。`apply()` 用 `ctx.inject(['skills'], …)` 注册,`resourceBase` 指向包内目录;没有 `skills` 服务的宿主静默跳过。`package.json files` 加 `skills`。
146
+
147
+ **测试**:`npm test` **825 项 / 48 个文件**全绿;`npm run typecheck` 通过。新增 `test/signal-source.test.mjs`(端到端:通知不算人话 / 回退会话缓存、subagent 参数不产 op、目录名不产 `run-bench`、散文删除只记录)与 `test/skill.test.mjs`。
148
+
149
+ ### 性能:Windows / NTFS 上大量小文件(不 OOM,但会被"每次 save 的文件操作数"拖慢)
150
+
151
+ **实测**:同一份 400 个小文件,`WSL 挂 /mnt/c`(9p,NTFS 的**悲观**代理)与 ext4 对照:
152
+
153
+ | 指标 | 修复前 | 修复后 |
154
+ |---|---|---|
155
+ | 首次索引 400 文件 | 11.4 s(28.4 ms/文件) | 8.2–9.5 s(20–24 ms/文件) |
156
+ | 单文件"改 → 懒索引" p50 | 178 ms | 46 ms(−74%) |
157
+ | 同上,ext4 | 1 ms | 1 ms |
158
+ | `findProjectRoot`(每次懒索引都走) | 119 ms | 14 ms |
159
+ | watch 对 400 文件做 stat | 843 ms,事件循环被按住 834 ms | 74 ms,最大卡顿 1 ms |
160
+ | 3k / 10k 小文件索引峰值 RSS | — | 83–85 MB / 112 MB |
161
+
162
+ **改了什么**:
163
+
164
+ - `findProjectRoot`:每层祖先从"11 个 marker × 2 组标记各做一次 `existsSync`"改成**一次 readdir + 一趟向上遍历**(VCS 仍优先于 PROJECT;`a marker above the cwd still wins` 的契约由 root-guards 87 项守住)。
165
+ - 每次 save 里不必要的文件操作:`shards/` 的 `.tmp` 清扫 60 s 一次(store 根目录仍每次扫,崩溃残留立刻收);`.gitignore` 存在性只查一次;store / shards 目录 mkdir 只在首次执行;分片/辅助文件的原子写不再每次 mkdir(目录被外部删掉时按 ENOENT 补建重试)。
166
+ - `writeJsonAtomic`:`EPERM` / `EBUSY` / `EACCES` 重试 3 次(Windows 上杀毒软件与搜索索引器会瞬时占用 rename 目标)。
167
+ - watch 轮询:同步 `statSync` 循环改成 `fs/promises.stat` + 16 并发。**这是"卡"的主因**——同步循环会把整个 dsh 事件循环按住(400 文件 843 ms;12k 文件按比例是几十秒),异步后主线程只等 I/O。
168
+ - 新增 `npm run bench:edits`(`scripts/bench-edits.mjs`):任意目录跑首次索引 + M 次单文件更新,报 p50/p90/峰值 RSS。Windows 原生请 `--dir C:\Temp\xxx` 量真实数字;上面的 9p 数字是上界。
169
+
170
+ **OOM**:大量小文件不是 OOM 面(3k 文件峰值 ~85 MB、10k ~112 MB,线性 ~3 MB/1k 文件)。OOM 面仍是**单个大文件**(`maxFileSizeMb: 10` → 最坏 +300 MB RSS)与 PDF 首次解析的 ~175 MB 底座,见 README「单文件内存预算」。
171
+
172
+ **没做**:分片打包(仍是一文件一 shard:12k 文件在 NTFS 上就是 12k 个 4 KB 块 + 12k 次 write+rename,这是下一档结构性优化);watch 每轮仍用同步 `git ls-files` 子进程。
173
+
174
+ ### 修复:非拉丁文字(俄语 / 西里尔)检索完全失效(issue #9)
175
+
176
+ **症状**:整句俄文查询切不出任何 token → 候选集恒为 0,提示通道与 `query_memory` 永不命中;俄文条目即使进了 store 也不可检索、不参与去重。阈值怎么调都没用,因为闸门前面没有输入。
177
+
178
+ **根因**:`tokenizeRaw` 只认 `[a-z0-9_]+` 与 CJK,西里尔在循环里不产生 token——"是不是词"被绑死成了"是不是这两种书写系统"。
179
+
180
+ **改法**:
181
+
182
+ - `src/util/ru.js`(新):切词 + 俄语虚词表 + **Snowball Russian 词干**。词干是逐句移植参考实现,并用 snowballstemmer 3.1.1 做了 8,354 个词形(含 6,000 个随机词)的逐词一致性对照。≤3 字符不词干(否则 `ИИ → и`)。
183
+ - `tokenizeRaw` 接入西里尔分支;**拉丁与 CJK 的输出逐字节不变**(老阈值不在这次重标定)。
184
+ - 闸门按文字系统分派:`gatedQueryText` 不再把 2 字母俄文当"短拉丁噪声";`isIntentWord` / `matchIntent` 改用 Unicode 词边界(`город` 不再命中 `городской`),长度门槛 ≥3。
185
+ - 索引迁移:`TOKENIZER_VERSION = 2` + doc 条目 `termsVersion`。旧 store 的 doc `terms` 会**一次性回填**(内容哈希未变也重抽),否则旧索引里的俄文永远补不上。
186
+ - leanvec `0.2.0`(optionalDependency 同步到 `^0.2.0`):词表**纯追加** 8,000 个西里尔行(77.0 → 84.8 MiB),并修了"只剩词边界 `▁` 时仍返回向量"的缺陷——未覆盖文字现在返回 `null`,不再出现"任意两条同脚本文字余弦恒为 1.0"进而被向量去重误覆盖。同版本把嵌入表改成**按行懒加载**:向量层常驻内存从约 126 MB 降到约 41 MB,加载耗时 119 → 46 ms(`src/vector-index.js` 传 8 MB 行缓存并在换模型时 `close()` 旧 fd)。
187
+
188
+ **升级注意**:
189
+
190
+ - 升级后首次索引/巡检会对旧 doc 条目做一次 `terms` 重抽(一次性 CPU 尖峰,文件内容不变);中文 / 英文的检索分数与行为不变。
191
+ - 俄文条目从此参与去重(`dedupOverlap` 是同一把尺子)。若老 store 里积了多条同义俄文笔记,升级后可能被合并/提示——这是修好的表现,不是新 bug。
192
+ - 未覆盖的文字(希腊 / 希伯来 / 阿拉伯 / 泰文)仍是纯词法,向量层对它们返回 `null`(明确降级,不猜)。
193
+ - **发布顺序**:leanvec `0.2.0` 必须先于本版发布。本版把 optionalDependency 提到 `^0.2.0`,若环境里仍是 `0.1.0`,俄文标题会被编码成同一个常量向量,向量去重可能误覆盖(正是 0.2.0 修掉的缺陷);词法检索不受影响。
194
+
1
195
  ## 0.6.5 (2026-10-24)
2
196
 
3
197
  **升级注意**:`allowUnsafeRoots: true` 的作用面比 0.6.4 大。此前它只放开**显式**工具调用与 `autoIndexOnFirstUse`,懒索引、会话审计与 TaskBridge 即使开着也始终不动;现在它放开内置名单的**所有**根判定入口,这三条链路会在放行的目录里建 store、写审计。只想放开某个目录时用 `roots.allow`(精确匹配,不影响 `deny` / `exclude`);家目录、系统目录如非必要仍建议保持 `false`。
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![ci](https://github.com/00080000/dsh-project-memory/actions/workflows/ci.yml/badge.svg)](https://github.com/00080000/dsh-project-memory/actions/workflows/ci.yml) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) [![npm](https://img.shields.io/npm/v/@yolk_vat-y/dsh-project-memory)](https://www.npmjs.com/package/@yolk_vat-y/dsh-project-memory) [![npm downloads](https://img.shields.io/npm/dm/%40yolk_vat-y%2Fdsh-project-memory?style=flat-square&color=orange)](https://www.npmjs.com/package/@yolk_vat-y/dsh-project-memory) [![Listed on dsh-plugin.org](https://dsh-plugin.org/badges/listed.svg)](https://dsh-plugin.org/plugins/00080000/dsh-project-memory) [![Awesome](https://awesome-dsh-plugin.com/badge.svg)](https://awesome-dsh-plugin.com)
8
8
 
9
9
 
10
- A persistent **project development memory** for [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) (dsh) agents. Built specifically for project development, natively integrated with dsh's task system: task lists and files read during a session are automatically persisted as cross-session task records, with tasks ↔ files linked — workflows can be switched and resumed, no need to re-scope the whole project, solving context loss. Documents (PDF/Markdown/txt) and code symbols are stored separately per workspace; documents are automatically cross-linked to the code symbols they mention. Experience notes (problem → solution) are automatically deduplicated, preventing repeated mistakes. All data is stored per project on disk, survives session compaction and handover; recalls include `path:line` citations for source verification. No native builds, no vector database. A 79 MB local embedding table (`leanvec`) installs and runs by default; without it, recall falls back to pure lexical.
10
+ A persistent **project development memory** for [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) (dsh) agents. Built specifically for project development, natively integrated with dsh's task system: task lists and files read during a session are automatically persisted as cross-session task records, with tasks ↔ files linked — workflows can be switched and resumed, no need to re-scope the whole project, solving context loss. Underneath sits a **hybrid index**: document chunks, code symbols, experience notes and insights each form a layer, scored per layer and merged into one ranking. Documents (PDF/Markdown/txt) and code symbols are stored separately per workspace; documents are automatically cross-linked to the code symbols they mention. Experience notes (problem → solution) are automatically deduplicated, preventing repeated mistakes. Data survives session compaction and handover; recalls include `path:line` citations for source verification.
11
11
 
12
12
  > The plugin keeps a compact project **memory** on disk, with every entry pointing to a concrete file and line — the agent can reorient quickly instead of re-reading the whole project.
13
13
 
@@ -18,13 +18,15 @@ A persistent **project development memory** for [DeepSeek Harness](https://githu
18
18
  - **TaskBridge: cross-session development tasks** — the session's todo list and the files it touches are persisted as per-project task entities, so a workflow can be switched and resumed without re-scoping the project. Associated files stay in recency-weighted order (a read never outranks a written file), so a resumed session sees where to look first. New sessions continue with `list_tasks` → `select_task`. Work delegated to subagents creates no task. On hosts without session events the task tools still work as a plain record list.
19
19
  - **Task panel and editing** — draggable cards show a task's steps and files, and can collapse to a mini-bar or be hidden. Title, steps and status can be edited inline, writing back through the same path as model updates; four visual themes change material, geometry, typeface and density only, and colours follow the host. The panel stays hidden until summoned, syncs in the background on session switch, never reopens itself after a refresh, and a render failure cannot take down the host.
20
20
  - **Document memory** — PDF, Markdown and plain text are chunked and summarized without a model call. Each entry keeps a short summary for injection, a bounded term set for recall, and a citation back to the source.
21
- - **Code symbol memory** — a dependency-free scanner extracts functions, classes, methods, interfaces and type aliases with full signatures across 8 languages. Where `typescript` is installed, an optional second layer adds inferred return types, generics and interface shapes; it runs in the background and never blocks indexing.
22
- - **Automatic, read-time memorization** — a file is memorized the moment the model reads it, so memory is a byproduct of normal work rather than an upfront scan, and files nobody reads are never indexed. A background poll re-memorizes changed files only.
21
+ - **Code symbol memory** — a dependency-free scanner extracts functions, classes, methods, interfaces and type aliases with signatures; covered languages are JavaScript/TypeScript, Python, Go, Rust, C/C++/C#, Java and shell. Where `typescript` is installed, an optional second layer adds inferred return types, generics and interface shapes; it runs in the background and never blocks indexing.
22
+ - **Automatic, read-time memorization** — with lazy indexing (default), a file is memorized the moment the model reads it, so memory grows as a byproduct of normal work rather than an upfront scan. `index_repo` or a watched root can cover the rest of the tree; a background poll only re-indexes files that changed.
23
23
  - **Doc ↔ code cross-linking** — a document that mentions a symbol is surfaced when that symbol is queried. Links are resolved against the current symbol table, so they cannot go stale.
24
24
  - **Hybrid recall** — ranked search over documents, symbols, experience notes and insights, with optional LLM query expansion. The experience/insight layers are re-ordered by cosine when `leanvec` is present — installed by default, absent ⇒ pure lexical. Tuned for CJK: phrase boost, a synonym table, and CJK-aware boundaries for doc↔symbol linking.
25
+ Russian (Cyrillic) is supported too: word splitting, a stopword list and Snowball stemming, so Russian queries hit Russian notes and take part in dedup.
25
26
  - **Experience notes** — problems → solutions, deduplicated by overlap rather than repeated, bounded by project size, and surfaced both by search and by the same injection path as lessons.
26
27
  - **Tiered insight memory (lessons / decisions / procedures)** — one entity across task, project and global scope. Near-duplicates merge or reinforce, and promotion moves an entry between scopes instead of copying it. Use is recorded, so decay and capacity rank by activity rather than age alone. The panel exposes a per-scope view for reviewing and editing entries. That list is ordered newest-first and loaded incrementally: 30 entries at a time, with the next page prefetched before the reader reaches the bottom and off-screen rows skipped by the renderer, so a large memory stays responsive.
27
- - **Triggered injection** — an insight may carry an authored trigger: only `when` triggers, `guard` narrows it, and `prevents` records what breaks without the entry. Corpus text can never trigger an injection; the statistical channel is gated separately and silent by default.
28
+ - **Triggered injection** — an insight may carry an authored trigger: only `when` triggers, `guard` narrows it, and `prevents` records what breaks without the entry. Corpus text can never trigger an injection; the statistical channel is gated separately and silent by default. **Evidence is graded by source**: only host facts (structured tool calls, `fs`/`todo` events) and irreversible actions named by the human (commit / publish / release / push / deploy / go public) can inject full text; prose mentions of delete / clean up / render / benchmark only feed the hint channel, and subagent prompts plus notice-shaped messages never count as actions.
29
+ - **Usage is a skill too** — it registers `project-memory` into the host `skills` registry (a directory bundle with `scripts/pm-digest.mjs`, `resourceBase` pointing inside the package). The model loads the query/write workflow on demand instead of carrying it in every prompt; hosts without a `skills` service skip it silently.
28
30
 
29
31
  ## Installation
30
32
 
@@ -42,19 +44,19 @@ The plugin is also published on npm as a scoped package:
42
44
  dsh plugin --profile web add @yolk_vat-y/dsh-project-memory -w
43
45
  ```
44
46
 
45
- Each indexed project has its own store at `<root>/.dsh-project-memory/`. It keeps itself out of git by default — there is nothing to add to your `.gitignore`.
47
+ Each indexed project has its own store at `<root>/.dsh-project-memory/`. It keeps itself out of git by default — there is nothing to add to your `.gitignore`. Global-scope entries are kept outside the project in `~/.config/dsh-project-memory/global.json`; point `insight.globalFile` elsewhere to move it.
46
48
 
47
49
  ## Usage
48
50
 
49
51
  The tools below are **invoked by the agent**, not typed by the user. In the chat, just ask naturally — e.g. "index this project" or "what does the auth module do?" — or simply keep working, and the agent calls the matching tool automatically. By default files are indexed the moment the model reads them, so memory fills in while you work. `watch_repo` keeps explicitly-watched roots fresh in the background; `index_repo` forces a full backfill (unchanged files are skipped).
50
52
 
51
- In a git work tree the corpus is whatever `git ls-files --cached --others --exclude-standard` lists — tracked files plus untracked files that are not ignored — so `.gitignore`, nested rules included, decides what gets remembered. A directory that is not a git work tree falls back to a plain walk (no ignore rules). Lazy indexing applies the same check per file; an explicit `index_doc` always indexes what you point it at.
53
+ In a git work tree the corpus is whatever `git ls-files --cached --others --exclude-standard` lists — tracked files plus untracked files that are not ignored — so `.gitignore`, nested rules included, decides what gets remembered. A directory that is not a git work tree falls back to a plain walk (no ignore rules). Lazy indexing applies the same check per file; an explicit `index_doc` bypasses `.gitignore`, but still respects `roots.exclude`, readability and the size limit, and its entry survives later scan passes for as long as the file exists.
52
54
 
53
55
  | Tool | Purpose |
54
56
  |---|---|
55
57
  | `index_doc file_path` | Index one document (PDF/MD/txt): chunk, summarize deterministically, and store with a `path:line` citation. Unchanged files are skipped. |
56
- | `index_repo root` | Index a whole project: documents get deterministic summaries, code files get a token-free symbol table. Incremental and self-healing: the store follows the file listing, so deleted, ignored or moved files are dropped, and documents are cross-linked to symbols. A non-existent or excluded root is rejected before anything is written. |
57
- | `watch_repo root` | Enable automatic refresh: a background poll detects new and changed files and re-indexes only those. Watched roots persist across restarts; a non-existent or excluded root is refused, roots that disappear are dropped rather than re-created. |
58
+ | `index_repo root` | Index a whole project: documents get deterministic summaries, code files get a token-free symbol table. Incremental and self-healing: the store follows the file listing, so deleted, ignored or moved files are dropped (an entry created by an explicit `index_doc` is kept while its file still exists), and documents are cross-linked to symbols. A non-existent or excluded root is rejected before anything is written. |
59
+ | `watch_repo root` | Enable automatic refresh: a background poll detects new and changed files and re-indexes only those. A watched root is recorded in that project's store, so it resumes when dsh starts there; a non-existent or excluded root is refused, roots that disappear are dropped rather than re-created. |
58
60
  | `memory_stats root` | Show what the store contains: totals, last index time, and the per-file list sorted by recency. |
59
61
  | `query_memory query` | Ranked search over documents, symbols, experience and insights, optionally query-expanded by the LLM. `type` selects a layer (`all` / `doc` / `symbol` / `experience` / `insight` / `task`). Returns hits with relative scores, sources or insight ids, and doc→symbol references. |
60
62
  | `list_tasks` | List task records for the project (archived marked). Call first in a new session before continuing work. |
@@ -74,12 +76,12 @@ The design follows four principles:
74
76
 
75
77
  - **Volatility** — context is ephemeral; it is lost when a session is compacted.
76
78
  - **Persistence** — the **memory** is stored on disk and survives compaction and new sessions.
77
- - **Compactness** — one bounded declaration line per symbol, and a ≤300-char summary plus a bounded term set per document chunk. Derived data is never stored: doc→symbol links are computed at read time. Index size depends on symbol density and chunk length, so treat these as measurements of specific corpora (2026-10-13), not guarantees: a code-only frontend app (289 files) lands at **325 bytes/entry ≈ 21% of source**, a symbol-dense TypeScript monorepo (12,634 files / 107 MB of code + 14 MB of docs) at **22% of source for the code layer (549 bytes/entry overall)** and **127% for the document layer**, and a document-heavy workspace (Markdown + PDFs) at **1,401 bytes/entry**.
79
+ - **Compactness** — one bounded declaration line per symbol, and a ≤300-char summary plus a bounded term set per document chunk. Doc→symbol links are not stored; they are computed at read time.
78
80
  - **Verifiability** — **recalls** carry a `path:line` citation where applicable, so the agent can confirm details against the source.
79
81
 
80
- Building the **memory** does not require an upfront scan: files are memorized as the model reads them, so the **memory** grows to cover exactly what has been worked with. Re-reading an unchanged file is a no-op, so the **memory** stays fresh with minimal ongoing overhead.
82
+ With default lazy indexing, building the **memory** does not require an upfront scan: files are memorized as the model reads them, so the **memory** grows to cover what has been worked with; `index_repo` or a watched root can cover the rest. Re-reading an unchanged file is a no-op, so the **memory** stays fresh with minimal ongoing overhead.
81
83
 
82
- The store is per-project and follows the codebase: changed files are re-extracted by content hash, deleted files are removed. Experience notes are `kind: 'experience'` entries in `insights.json` — retrieval-only, so accumulation does not affect context.
84
+ Project- and task-scope memory is stored per project and follows the codebase: changed files are re-extracted by content hash, deleted files are removed. Experience notes are ordinary `kind: 'experience'` entries in `insights.json`: recallable, deduplicated, and eligible for the same gated hint channel as lessons.
83
85
 
84
86
  ## Design
85
87
 
@@ -96,10 +98,12 @@ The store is per-project and follows the codebase: changed files are re-extracte
96
98
  admission-shadow.jsonl one line per step, all scored candidates + features (offline replay)
97
99
  ```
98
100
 
101
+ Global-scope entries are not stored under the project: they live in `insight.globalFile` (default `~/.config/dsh-project-memory/global.json`) so every project sees them.
102
+
99
103
  - **Incremental** — a content hash per file; only changed files are re-extracted.
100
104
  - **Cross-linking** — a returned document chunk resolves the symbols it mentions against the **current** symbol table and appends them as `references`, so a doc indexed before its symbols still links correctly.
101
105
  - **Query expansion** — when enabled, `query_memory` asks the LLM to rewrite the query into several variants (synonyms, EN/CN, identifier guesses) and merges the scores; when off, queries never touch the LLM. Indexing itself is model-free.
102
- - **Consistency** — the fact layer follows the codebase (hash re-extract / remove-on-delete); the experience layer is retrieval-only with supersede and `forget`. Writes take a cross-process directory lock (`.write.lock`) around a short read-modify-write, so two dsh instances can share one project store: shards converge by `indexedAt`, and a save that cannot get the lock is deferred and retried.
106
+ - **Consistency** — the fact layer follows the codebase (hash re-extract / remove-on-delete); experience entries are updated through the same supersede and `forget` paths as other insights. Writes take a cross-process directory lock (`.write.lock`) around a short read-modify-write, so two dsh instances can share one project store: shards converge by `indexedAt`, a save that cannot get the lock is retried and flushed again at exit, failures stay silent by default (`DSH_PROJECT_MEMORY_DEBUG=1` prints one diagnostic line), and entries deleted by another process are not resurrected by a stale in-memory snapshot.
103
107
 
104
108
  ## Architecture (Task Panel)
105
109
 
@@ -128,7 +132,7 @@ The workflow panel is collapsible, adapts to dsh and theme plugin styles, and of
128
132
  | `autoIndexOnFirstUse` | false | full scan of the current working directory on plugin load (opt-in) |
129
133
  | `watch` / `watchInterval` | true / 30 | background refresh; base poll interval in seconds (polls stay quiet while a turn is running — a 5-minute fallback keeps external edits fresh — and one merged scan runs at turn end; idle polls back off up to 2 minutes and reset on any change) |
130
134
  | `maxScanFiles` / `maxScanDepth` | 20000 / 12 | per-scan caps on files and directory depth; a truncated pass is reported and never removes what it did not reach. Cannot be disabled: `0` or any invalid value falls back to the default |
131
- | `allowUnsafeRoots` | false | compatibility switch that releases the **built-in** excluded list for every root decision (including lazy indexing, session audit and TaskBridge). It only applies to the built-in list — `roots.deny` / `roots.exclude` still win; to release a single directory, prefer an exact `roots.allow` entry |
135
+ | `allowUnsafeRoots` | false | releases the **built-in** excluded list for every root decision (including lazy indexing, session audit and TaskBridge). It only applies to the built-in list — `roots.deny` / `roots.exclude` still win; to release a single directory, prefer an exact `roots.allow` entry |
132
136
  | `roots.allow` / `roots.deny` / `roots.exclude` | `[]` / `[]` / `[]` | custom root lists (machine/profile level, CLI and web alike). `allow` / `deny` match the directory itself exactly; `exclude` is a path-boundary prefix and covers the whole subtree (no file under it enters the index). Priority: `exclude` > `deny` > `allow` > built-in list; the filesystem root can never be a root. `~` / `~/...` expansion, non-absolute entries are ignored with a one-time stderr warning, Windows is case-insensitive |
133
137
  | `llmQueryExpansion` / `expansionCount` | false / 6 | expand queries via the LLM before search (off by default to save tokens); max variants |
134
138
  | `tsPath` / `enableTypeScript` | (auto) / true | optional absolute path to a specific `typescript` install; set `enableTypeScript: false` to disable the type-aware layer entirely |
@@ -140,11 +144,10 @@ The workflow panel is collapsible, adapts to dsh and theme plugin styles, and of
140
144
  | `autoContext.maxItemsPerSession` / `autoContext.maxItemCharsPerSession` | 60 / 24000 | **runaway fuse, not a throttle** — a hard per-session ceiling by count and characters; once reached, the item channel stays silent for the rest of the session |
141
145
  | `autoContext.hintMinCoverage` | 0.45 | **absolute** floor for the statistical channel: the IDF-weighted share of the query's information mass the entry covers. A ratio-only threshold cannot tell signal from "best of a bad lot" |
142
146
  | `autoContext.hintMinMatched` / `autoContext.hintMinSupport` | 2 / 0.15 | a hint must share at least this many terms with the query, and at least this share of the query's terms must exist in the corpus at all — otherwise the channel stays silent this round |
143
- | `autoContext.vectorDir` | unset | **optional** semantic layer over the experience/insight layers, on by default via the `leanvec` optionalDependency (79 MB, ≈+130 MB RSS). `off` forces pure lexical; a path or `DSH_LEANVEC_DIR` overrides it. Re-orders only, returned counts unchanged; while it is active only entries that got **no** cosine are still filtered by lexical match count |
147
+ | `autoContext.vectorDir` | unset | **optional** semantic layer over the experience/insight layers, on by default via the `leanvec` optionalDependency (≈85 MB table, ≈+45 MB RSS). `off` forces pure lexical; a path or `DSH_LEANVEC_DIR` overrides it. Re-orders only, returned counts unchanged; while it is active only entries that got **no** cosine are still filtered by lexical match count |
144
148
  | `autoContext.vectorAlpha` | 0.5 | weight of `(1-α)·lexical + α·cosine` in those layers; `0` disables re-ranking only (write-side dedup stays on), `1` (pure vector) measured worse |
145
149
  | `autoContext.vectorDedup` | true | write-side near-duplicate detection (cosine ≥ 0.9 auto-overwrite, ≥ 0.7 near-neighbour hint). Independent of `vectorAlpha`; `false` keeps recall ranking untouched |
146
150
  | `autoContext.vectorItemMin` / `autoContext.vectorSpeakMin` | unset | **experimental** absolute-cosine gates for the hint channel (per-entry floor / channel-level semantic rescue). Uncalibrated — unset means off; see the evidence in `src/auto-inject.js` before enabling |
147
- | `autoContext.legacyScope` | `ignore` | how a legacy `trigger.scope` is treated: `ignore` (default) does not use it as a filter; `filter` applies it as a filter. `npm run selfcheck:triggers` lists entries that still carry a scope |
148
151
  | `autoContext.auditLog` | true | append one JSONL line per **actual** injection to `injection-audit.jsonl` (what / why / dropped / budget); rotates to `.1` past `auditMaxBytes` (`262144`). Silent on I/O errors |
149
152
  | `autoContext.shadowLog` / `autoContext.shadowMaxBytes` | true / 524288 | append one JSONL line **per step** (including steps that injected nothing) to `admission-shadow.jsonl`: scored candidates with their features and the gate that rejected each one — what makes a threshold change answerable offline. Disk only, never in the prompt; rotates keeping one `.1` generation |
150
153
 
@@ -162,11 +165,11 @@ When the root comes from the working directory, the model gets one notice per se
162
165
 
163
166
  - `roots.allow` — allow a directory even when it is on the built-in list, matched exactly. The filesystem root is not eligible.
164
167
  - `roots.deny` — this directory cannot be a root, matched exactly; its subdirectories can still be roots of their own.
165
- - `roots.exclude` — no file in this subtree enters the index, matched by path-boundary prefix (subdirectories included); no new root is inferred inside it either. A complete scan of a parent root skips it and removes previously indexed entries under it.
168
+ - `roots.exclude` — no file in this subtree enters the index, matched by path-boundary prefix (subdirectories included); no new root is inferred inside it either. A complete scan of a parent root skips it and removes entries already indexed under it.
166
169
 
167
170
  `deny` only decides whether the directory itself can be a root: when a parent is already a root, files under a denied child are still indexed by that parent — use `exclude` (or `.gitignore`, which the git-aware scan already honours) to drop the files too. Explicit `index_doc` also respects `exclude` and returns `Not indexed` for a file under it.
168
171
 
169
- Priority is `exclude` > `deny` > `allow` > built-in list. `allowUnsafeRoots: true` remains as a compatibility switch that only releases the built-in list; `deny` / `exclude` still win. The same verdict is shared by explicit tool calls, lazy indexing, watch, the session audit trail and TaskBridge. After adding a `deny` / `exclude` entry, roots already persisted in `watch.json` are dropped on the next startup. Configure under `config:` of `- id: project-memory` (CLI and web alike); the web UI does not expose a dedicated settings page yet.
172
+ Priority is `exclude` > `deny` > `allow` > built-in list. `allowUnsafeRoots: true` only releases the built-in list; `deny` / `exclude` still win. The same verdict is shared by explicit tool calls, lazy indexing, watch, the session audit trail and TaskBridge. Roots refused by the current policy are dropped from `watch.json` on startup. Configure under `config:` of `- id: project-memory` (CLI and web alike); the web UI has no dedicated settings page, so edit the profile.
170
173
 
171
174
  **Scan limits.** One pass covers at most `maxScanFiles` files (20000) and `maxScanDepth` directory levels (12). A truncated pass is reported in the `index_repo` result and logged once per root by the watcher, and it does not remove entries it did not reach. A directory that cannot be read (e.g. `EACCES`) counts as a truncated pass too and is named in the result: a read failure is not a deletion.
172
175
 
@@ -187,7 +190,7 @@ Settings live in the plugin's config object. To change them, add an override ent
187
190
  maxScanFiles: 20000 # per-scan file cap (truncation is reported, never deletes)
188
191
  maxScanDepth: 12 # per-scan directory-depth cap
189
192
  enableTypeScript: true # on: type-aware enhancement when TS is installed (default)
190
- # allowUnsafeRoots: false # compatibility switch: built-in list only; prefer roots.allow below
193
+ # allowUnsafeRoots: false # release the built-in list; prefer roots.allow below
191
194
  # roots: # custom root lists (empty by default)
192
195
  # allow: [/srv/projects/demo] # exact release of a built-in directory (filesystem root excluded)
193
196
  # deny: [/srv/shared] # exact: this directory cannot be a root; children still can
@@ -264,14 +267,14 @@ Pass `--queries your-queries.json` to run the labeled-set method (hit@5 / hit@10
264
267
 
265
268
  ## Design tradeoffs
266
269
 
267
- - **A short filesystem lock, not an embedded database** — each save holds an exclusive `.write.lock` only for the read-modify-write (parsing stays outside it), waits at most 2 s for a busy peer and then retries. Two dsh instances can share one store. No WAL, no daemon, no native dependency.
270
+ - **A short filesystem lock, not an embedded database** — each save holds an exclusive `.write.lock` only for the read-modify-write (parsing stays outside it) and waits synchronously for up to 15 s for a busy peer (correctness comes from acquiring the lock, not from background retries); a write that still cannot land is registered for a synchronous flush when the process exits or the plugin is disposed, **without interrupting the user** — memory writes are idempotent and cheap to redo; set `DSH_PROJECT_MEMORY_DEBUG=1` for a one-line diagnostic. The lock carries `pid` / `host` / `token`: a live same-host holder is never preempted, release verifies ownership, and a crashed same-host lock is reclaimed immediately. Two dsh instances can share one store. No WAL, no daemon, no native dependency.
268
271
  - **Watch: compute outside, commit inside** — no lock is held during parsing, and polling with mtime + content hash is used instead of `fs.watch`: it behaves identically on network drives, Docker volumes and WSL, without duplicate-trigger or missed-event failure modes.
269
272
  - **Corrupt shards are quarantined, not repaired** — a shard that fails to parse is renamed and only that file is re-indexed, so there is no WAL or embedded database adding native dependencies, lock contention and failure modes of their own.
270
273
  - **Vectors re-rank, they do not rank** — on a paraphrased-query set, pure vector replacement is worse than BM25 (hit@10 **53% vs 69%**) while weighted fusion helps at small k (hit@3 **53% vs 50%**), so the optional layer only re-orders the experience/insight layers and never gates. Lexical retrieval still answers the queries this plugin targets: on a real project with 29 labelled queries, file-level hit@5 is **96.6%**, and whole-chunk terms raise document term coverage from **27.3% to 100%** with MRR unchanged (**0.958** vs **0.955**).
271
274
  - **Indexing is deterministic and model-free** — a model at index time would make two indexings of one document differ, and a wrong translation at query time means zero recall; rules plus symbol links cover the common cases and work offline.
272
275
  - **Model-facing memory: the agent writes, no human in the loop** — the consumer is the agent, usually headless, so memory that only promotes when someone clicks a card would never promote at all. `draft` is a provenance marker plus an evidence threshold, not an approval queue.
273
276
  - **Full entries returned directly** — entries are already compact, so returning them whole is more verifiable and one round-trip cheaper.
274
- - **`forget` by query is aggressive; use IDs for precision** — experience notes are low-risk, high-volume and retrieval-only, so stale noise hurts more than an over-broad delete. For exact deletion use the ID shown by `query_memory`.
277
+ - **`forget` by query is aggressive; use IDs for precision** — experience notes are low-risk and high-volume, so stale noise hurts more than an over-broad delete. For exact deletion use the ID shown by `query_memory`.
275
278
  - **TypeScript enhancement is optional, lazy and cached** — it runs in the background, never blocks indexing, and falls back to the regex scanner; its queue is bounded, and any dropped files are reported. The **default lib is not loaded**: inference that depends on global types (`Promise`/`Array`/DOM) degrades to `any`/`unknown`, while explicit annotations are unaffected.
276
279
  - **Subagent sessions are out of scope**
277
280
 
@@ -281,7 +284,7 @@ These commands are for **maintaining the plugin code** — regular users do not
281
284
 
282
285
  ```bash
283
286
  npm install
284
- npm test # 810 tests
287
+ npm test # 885 tests
285
288
  npm run eval:injection # synthetic pool P/R: precision 0.93 / recall 1.00, + a 3-scenario hint-only group
286
289
  npm run eval:injection -- --store .dsh-project-memory/insights.json # replay on YOUR store; control group is a hard gate
287
290
  npm run selfcheck:triggers # which entries can still push, which declarations are dead (reads your local store)
package/README.zh-CN.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  [![ci](https://github.com/00080000/dsh-project-memory/actions/workflows/ci.yml/badge.svg)](https://github.com/00080000/dsh-project-memory/actions/workflows/ci.yml) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) [![npm](https://img.shields.io/npm/v/@yolk_vat-y/dsh-project-memory)](https://www.npmjs.com/package/@yolk_vat-y/dsh-project-memory) [![npm downloads](https://img.shields.io/npm/dm/%40yolk_vat-y%2Fdsh-project-memory?style=flat-square&color=orange)](https://www.npmjs.com/package/@yolk_vat-y/dsh-project-memory) [![Listed on dsh-plugin.org](https://dsh-plugin.org/badges/listed.svg)](https://dsh-plugin.org/plugins/00080000/dsh-project-memory) [![Awesome](https://awesome-dsh-plugin.com/badge.svg)](https://awesome-dsh-plugin.com)
8
8
 
9
- 为 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)(dsh)agent 提供持久化的 **项目开发记忆**。专门针对项目开发,原生融合 dsh 任务系统,会话内任务清单与读过的文件自动沉淀为跨会话任务记录,任务↔文件自动关联——开发工作流可切换、可续接,无需重复梳理整个项目,解决上下文失效;文档(PDF/Markdown/txt)与代码符号写入工作区独立存储,文档自动交叉链接至所提及的代码符号;经验笔记(问题 → 方案)自动去重,避免重复踩坑。所有数据按项目落盘,跨会话压缩与交接保留,召回附带 `路径:行号` 可回源核实。无原生构建、无向量数据库。79 MB 的本地嵌入表 `leanvec` 随安装默认启用;它不在时自动退回纯词法。
9
+ 为 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)(dsh)agent 提供持久化的 **项目开发记忆**。专门针对项目开发,原生融合 dsh 任务系统,会话内任务清单与读过的文件自动沉淀为跨会话任务记录,任务↔文件自动关联——开发工作流可切换、可续接,无需重复梳理整个项目,解决上下文失效。底层是一套**混合索引**:文档块、代码符号、经验笔记与洞察各占一层,召回时分层打分再合并排序。文档(PDF/Markdown/txt)与代码符号写入工作区独立存储,文档自动交叉链接至所提及的代码符号;经验笔记(问题 → 方案)自动去重,避免重复踩坑。数据跨会话压缩与交接保留,召回附带 `路径:行号` 可回源核实。
10
10
 
11
11
 
12
12
  > 插件在磁盘上维护一份精简的项目**记忆**,每条记录指向具体的文件与行号;agent 需要快速了解项目时先查**记忆**,无需重读整个项目。
@@ -14,16 +14,17 @@
14
14
 
15
15
  ## 特性
16
16
 
17
- - **TaskBridge:跨会话开发任务** — 会话内的任务清单与触碰过的文件持久化为项目任务实体,工作流可以随时切走再续接,不必重新界定项目范围。关联文件按最近活跃排序(读取永远不越过写过的文件),续接时一眼看到该先看哪些。新会话通过 `list_tasks` → `select_task` 续接。委派给子代理的工作不会建档。旧宿主下降级为纯记录。
17
+ - **TaskBridge:跨会话开发任务** — 会话内的任务清单与触碰过的文件持久化为项目任务实体,工作流可以随时切走再续接,不必重新界定项目范围。关联文件按最近活跃排序(读取永远不越过写过的文件),续接时一眼看到该先看哪些。新会话通过 `list_tasks` → `select_task` 续接。委派给子代理的工作不会建档。宿主不提供会话事件时,任务工具仍可作为普通记录列表使用。
18
18
  - **任务面板与编辑** — 卡片可拖拽,展示任务步骤与涉及文件,可折叠为迷你条或彻底隐藏;标题、步骤与状态支持行内编辑,与模型更新走同一条写回路径;四档外观风格只改材质、几何、字型与密度,颜色跟随宿主。面板默认隐藏,仅在显式唤起后出现;会话切换只后台同步,刷新页面不会自行打开;渲染错误有边界兜底,面板崩溃不会拖垮宿主。
19
19
  - **文档记忆** — PDF、Markdown 与纯文本按块切分并生成摘要,索引期不调用模型。每条保留一段简短摘要供注入、一个有界的检索词集合,以及回源引用。
20
- - **代码符号记忆** — 零依赖扫描器提取函数、类、方法、接口与类型别名及其完整签名,覆盖 8 种语言。项目装了 `typescript` 时,可选第二层补推导返回类型、泛型与接口,后台执行、不阻塞索引。
21
- - **读到即记忆、变更即刷新** — 文件在模型实际读取的瞬间被记忆,记忆是正常工作的副产品,而不是额外的一次全量扫描;从未读过的文件不会被记忆。后台轮询只重记变更过的文件。
20
+ - **代码符号记忆** — 零依赖扫描器提取函数、类、方法、接口与类型别名及其签名,覆盖 JavaScript/TypeScript、Python、Go、Rust、C/C++/C#、Java 与 shell。项目装了 `typescript` 时,可选第二层补推导返回类型、泛型与接口,后台执行、不阻塞索引。
21
+ - **读到即记忆、变更即刷新** — 默认开启懒索引:文件在模型实际读取的瞬间被记忆,记忆是正常工作的副产品,而不是额外的一次全量扫描。`index_repo` 或监听根目录可以覆盖其余文件;后台轮询只重记变更过的文件。
22
22
  - **文档 ↔ 代码交叉链接** — 文档提及的符号,在查询该符号时一并带出。链接按**当前**符号表解算,不会过期。
23
- - **混合召回** — 对文档、符号、经验笔记与 insight 排序召回,可选 LLM 查询扩展。`leanvec` 是 optionalDependency:默认装上并按余弦重排经验/洞察两层,没装或 `vectorDir: 'off'` 则退回纯词法。针对 CJK 增强:短语加分、同义词表,以及文档↔符号链接的词边界处理。
23
+ - **混合召回** — 对文档、符号、经验笔记与 insight 排序召回,可选 LLM 查询扩展。`leanvec` 是 optionalDependency:默认装上并按余弦重排经验/洞察两层,没装或 `vectorDir: 'off'` 则退回纯词法。针对 CJK 增强:短语加分、同义词表,以及文档↔符号链接的词边界处理。俄语(西里尔)同样支持:切词 + 虚词表 + Snowball 词干,俄文查询能命中俄文条目,也参与去重。
24
24
  - **经验笔记** — 记录问题 → 方案;相似问题覆盖而不重复,数量随项目规模有界,与教训走同一条注入通道:检索与自动注入都能带出。
25
25
  - **分层 insight 记忆(教训 / 决策 / 流程)** — 同一实体贯穿任务、项目、全局三级。近重复合并或强化;提升是更换归属而非复制。被使用会记账,因此衰减与容量按活跃度排序,而不是只按时间。面板提供分级的记忆视图用于审核与编辑;列表按新→旧排列并增量加载——每页 30 条,滚到底前就预取下一页,离屏行不参与渲染,记忆变多也不卡。
26
- - **触发式注入** — insight 可携带 authored trigger:只有 `when` 能触发,`guard` 只能收窄,`prevents` 记下没有它会坏在哪。语料正文永远不能触发注入;统计通道另有独立门槛,默认沉默。
26
+ - **触发式注入** — insight 可携带 authored trigger:只有 `when` 能触发,`guard` 只能收窄,`prevents` 记下没有它会坏在哪。语料正文永远不能触发注入;统计通道另有独立门槛,默认沉默。**证据来源分级**:只有宿主事实(结构化工具调用、`fs`/`todo` 事件)与真人消息里的不可逆外部动作(提交 / 发布 / 发版 / 推送 / 部署 / 公开)能触发全文注入;散文里的"删除 / 清理 / 渲染 / 基准"只进提示通道,子代理提示词与通知类消息不参与动作判定。
27
+ - **用法也是一个 skill** — 向宿主 `skills` 注册 `project-memory`(目录 bundle,含 `scripts/pm-digest.mjs`,`resourceBase` 指向包内目录)。模型按需加载查询 / 写入流程,不占常驻提示;没有 `skills` 服务的宿主静默跳过。
27
28
 
28
29
  ## 安装
29
30
 
@@ -41,19 +42,19 @@ cd dsh-project-memory && dsh plugin --profile web add . -w
41
42
  dsh plugin --profile web add @yolk_vat-y/dsh-project-memory -w
42
43
  ```
43
44
 
44
- 每个被索引的项目在 `<root>/.dsh-project-memory/` 下有独立存储;它默认就把自己排除在 git 之外,`.gitignore` 无需任何添加。
45
+ 每个被索引的项目在 `<root>/.dsh-project-memory/` 下有独立存储;它默认就把自己排除在 git 之外,`.gitignore` 无需任何添加。global 级条目单独存放于 `~/.config/dsh-project-memory/global.json`;可用 `insight.globalFile` 改到别处。
45
46
 
46
47
  ## 用法
47
48
 
48
49
  以下工具由 **agent 自动调用**,无需用户手动输入。在对话中直接说自然语言即可——例如「给这个项目建个索引」或「auth 模块是干嘛的」,或者正常开发即可——agent 会自动调用对应工具。默认开启「读到即索引」:模型读哪个文件,就顺便索引哪个文件,记忆在你干活的过程中自然积累。`watch_repo` 让显式监听的根目录在后台保持新鲜;`index_repo` 强制对项目做一次全量回填(未变更文件自动跳过)。
49
50
 
50
- 在 git 工作树里,语料就是 `git ls-files --cached --others --exclude-standard` 的清单——已跟踪文件,加上未被忽略的未跟踪文件——因此 `.gitignore`(含嵌套规则)决定什么会被记忆。不是 git 工作树的目录退回普通遍历(不套忽略规则)。「读到即索引」对单个文件套用同一判据;显式 `index_doc` 则总是索引你指定的文件。
51
+ 在 git 工作树里,语料就是 `git ls-files --cached --others --exclude-standard` 的清单——已跟踪文件,加上未被忽略的未跟踪文件——因此 `.gitignore`(含嵌套规则)决定什么会被记忆。不是 git 工作树的目录退回普通遍历(不套忽略规则)。「读到即索引」对单个文件套用同一判据;显式 `index_doc` 不受 `.gitignore` 限制,但仍服从 `roots.exclude`、可读性与体积上限,且只要文件还在,它的条目就能活过后续扫描清理。
51
52
 
52
53
  | 工具 | 用途 |
53
54
  |---|---|
54
55
  | `index_doc file_path` | 索引单个文档(PDF/MD/txt):分块、确定性摘要,带 `路径:行号` 入库。未变更文件自动跳过。 |
55
- | `index_repo root` | 索引整个项目:文档生成确定性摘要,代码文件生成零 token 符号表。增量更新,store 跟随文件清单:已删除、被忽略或移走的文件会被清理;文档与符号交叉链接。根目录不存在或在排除名单上时,会在写入任何内容前拒绝。 |
56
- | `watch_repo root` | 启用自动刷新:后台轮询检测新增/变更文件,仅重抽这些文件。监听的项目在插件重启后自动恢复;不存在或在排除名单上的根目录会被拒绝,已消失的根目录会被丢弃而不是被重新创建。 |
56
+ | `index_repo root` | 索引整个项目:文档生成确定性摘要,代码文件生成零 token 符号表。增量更新,store 跟随文件清单:已删除、被忽略或移走的文件会被清理(显式 `index_doc` 的条目只要文件还在就保留);文档与符号交叉链接。根目录不存在或在排除名单上时,会在写入任何内容前拒绝。 |
57
+ | `watch_repo root` | 启用自动刷新:后台轮询检测新增/变更文件,仅重抽这些文件。监听根会记在该项目的 store 里,在该项目下启动 dsh 时恢复监听;不存在或在排除名单上的根目录会被拒绝,已消失的根目录会被丢弃而不是被重新创建。 |
57
58
  | `memory_stats root` | 查看记忆库内容:总量、最近索引时间,以及按时间排序的逐文件清单。 |
58
59
  | `query_memory query` | 对文档、符号、经验与 insight 执行排序检索,可选 LLM 查询扩展。`type` 选择层(`all` / `doc` / `symbol` / `experience` / `insight` / `task`)。返回带相对分数、引用或 insight id、以及文档→符号链接的结果。 |
59
60
  | `list_tasks` | 列出本项目任务记录(含归档,带标记)。新会话/续接前先调用。 |
@@ -73,12 +74,12 @@ dsh plugin --profile web add @yolk_vat-y/dsh-project-memory -w
73
74
 
74
75
  - **易失性** — 上下文是临时的,会话压缩即丢失。
75
76
  - **持久性** — **记忆**存于磁盘,跨压缩与会话保留。
76
- - **紧凑性** — 代码层每个符号只存一行有界声明,文档层每个 chunk 保留 ≤300 字符的摘要与有界词项。**派生数据一律不落盘**:doc→symbol 链接在读取期计算。最终体积取决于符号密度与 chunk 长度,下面是特定语料的实测值(2026-10-13),不是承诺:纯代码的前端应用(289 文件)实测 **325 bytes/条目 ≈ 源码 21%**;符号密集的 TypeScript monorepo(12,634 文件 / 代码 107 MB + 文档 14 MB)实测代码层 **占源码 22%**(整库 549 bytes/条目)、文档层 **占其源码 127%**;文档占比高的语料单条目最大,一个文档为主的工作区(Markdown + PDF)实测 **1,401 bytes/条目**。
77
+ - **紧凑性** — 代码层每个符号只存一行有界声明,文档层每个 chunk 保留 ≤300 字符的摘要与有界词项。doc→symbol 链接不落盘,读取期计算。
77
78
  - **可核验性** — **召回**在适用时携带 `路径:行号` 引用,agent 可对照源文件核实。
78
79
 
79
- 构建**记忆**无需预先全量扫描:文件在模型读取时被记忆,**记忆**恰好覆盖实际处理过的内容。未变更的文件重读是空操作,因此持续维护开销很低。
80
+ 默认开启懒索引时,构建**记忆**无需预先全量扫描:文件在模型读取时被记忆,**记忆**恰好覆盖实际处理过的内容;`index_repo` 或监听根可以覆盖其余文件。未变更的文件重读是空操作,因此持续维护开销很低。
80
81
 
81
- 存储按项目独立存放,并跟随代码库变化:文件变更按内容哈希重新抽取,文件删除则同步移除。经验笔记是 `insights.json` 里 `kind: 'experience'` 的条目,仅检索、累积不影响上下文。
82
+ 项目级与任务级记忆按项目保存,并跟随代码库变化:文件变更按内容哈希重新抽取,文件删除则同步移除。经验笔记是 `insights.json` 里普通的 `kind: 'experience'` 条目:可检索、参与去重,也能进入与教训相同的受门槛约束的提示通道。
82
83
 
83
84
  ## 设计
84
85
 
@@ -95,10 +96,12 @@ dsh plugin --profile web add @yolk_vat-y/dsh-project-memory -w
95
96
  admission-shadow.jsonl 每步一行,全部被评分的候选 + 特征(离线重放)
96
97
  ```
97
98
 
99
+ global 级条目不放在项目里:它们在 `insight.globalFile`(默认 `~/.config/dsh-project-memory/global.json`),所有项目共享。
100
+
98
101
  - **增量** — 按文件内容哈希,仅重新抽取变更文件。
99
102
  - **交叉链接** — `query_memory` 返回文档 chunk 时,按**当前**符号表解算它提到的符号,以 `references` 带出。文档先索引、符号后到也能链上。
100
103
  - **查询扩展** — `llmQueryExpansion` 开启时,把查询改写为多个变体(同义词、中英、符号名猜测)再合并分数;关闭时查询完全不碰 LLM。索引本身不调用模型。
101
- - **一致性** — 事实层跟随代码库(哈希重抽 / 删除即移除);经验层仅检索,配合覆盖与 `forget` 机制。写入在跨进程的目录锁(`.write.lock`)内做一次短暂的读改写,因此两个 dsh 实例可以共用一个项目存储:分片按 `indexedAt` 收敛,拿不到锁的那次保存会延后重试。
104
+ - **一致性** — 事实层跟随代码库(哈希重抽 / 删除即移除);经验条目与其他 insight 走同一套覆盖与 `forget` 机制。写入在跨进程的目录锁(`.write.lock`)内做一次短暂的读改写,因此两个 dsh 实例可以共用一个项目存储:分片按 `indexedAt` 收敛,拿不到锁的保存会延后重试,仍失败则在退出时同步 flush;默认静默(`DSH_PROJECT_MEMORY_DEBUG=1` 才打印一行诊断)。
102
105
 
103
106
  ## 架构(任务面板)
104
107
 
@@ -127,7 +130,7 @@ TaskPanel (Container)
127
130
  | `autoIndexOnFirstUse` | false | 插件加载时对当前工作目录做全量扫描(可选) |
128
131
  | `watch` / `watchInterval` | true / 30 | 后台刷新;基础轮询间隔(秒);回合进行中静默(5 分钟兜底,外部改动仍会自愈),回合结束立刻合并扫一次;空闲时逐步退避到最长 2 分钟,一有变化立即回到该值 |
129
132
  | `maxScanFiles` / `maxScanDepth` | 20000 / 12 | 单次扫描的文件数与目录深度硬上限;被截断时会在报告里说明,且不会删除没扫到的条目。**无法取消**:`0` 或任何非法值都回落到默认值 |
130
- | `allowUnsafeRoots` | false | 兼容开关:放开**内置**排除名单,所有根判定入口(含懒索引、会话审计、任务桥)都生效。它只作用于内置名单——`roots.deny` / `roots.exclude` 仍然优先;只想放开一个目录时用 `roots.allow` |
133
+ | `allowUnsafeRoots` | false | 放开**内置**排除名单,所有根判定入口(含懒索引、会话审计、任务桥)都生效。它只作用于内置名单——`roots.deny` / `roots.exclude` 仍然优先;只想放开一个目录时用 `roots.allow` |
131
134
  | `roots.allow` / `roots.deny` / `roots.exclude` | `[]` / `[]` / `[]` | 自定义根名单(机器/配置档级,CLI 与 web 通用)。`allow` / `deny` 精确匹配目录本身;`exclude` 按路径边界前缀匹配整棵子树(其中的文件一律不进索引)。优先级 `exclude` > `deny` > `allow` > 内置名单,文件系统根永远不能当根。支持 `~`/`~/...`;非绝对路径忽略并在 stderr 告警一次;Windows 下大小写不敏感 |
132
135
  | `llmQueryExpansion` / `expansionCount` | false / 6 | 检索前用 LLM 扩展查询(默认关闭,节省 token);扩展变体上限 |
133
136
  | `tsPath` / `enableTypeScript` | (自动) / true | 可选:强制指定 `typescript` 安装路径;`enableTypeScript: false` 彻底禁用类型感知层 |
@@ -139,11 +142,10 @@ TaskPanel (Container)
139
142
  | `autoContext.maxItemsPerSession` / `autoContext.maxItemCharsPerSession` | 60 / 24000 | **runaway 保险丝,不是节流阀** —— 按条数与字符计的每会话硬上限:一旦触顶,本会话余下部分条目通道持续沉默 |
140
143
  | `autoContext.hintMinCoverage` | 0.45 | 提示通道的**绝对**下限:条目覆盖了查询多少 IDF 加权信息量。只用相对阈值分不出"有信号"和"矮子里拔将军" |
141
144
  | `autoContext.hintMinMatched` / `autoContext.hintMinSupport` | 2 / 0.15 | 提示还必须至少共享这么多个词;且查询里能在语料中找到对应的词占比不低于该值时,通道才出声——否则本轮整体沉默 |
142
- | `autoContext.vectorDir` | 未设 | **可选**语义层,只作用于经验/洞察两层;随 `leanvec`(optionalDependency)默认装上并启用(79 MB、约 +130 MB RSS)。填 `off` 强制纯词法;填路径或用 `DSH_LEANVEC_DIR` 可覆盖。只改排序、返回条数不变;启用时只有**没拿到余弦**的条目才继续按词法命中数筛 |
145
+ | `autoContext.vectorDir` | 未设 | **可选**语义层,只作用于经验/洞察两层;随 `leanvec`(optionalDependency)默认装上并启用(约 85 MB 表、约 +45 MB RSS)。填 `off` 强制纯词法;填路径或用 `DSH_LEANVEC_DIR` 可覆盖。只改排序、返回条数不变;启用时只有**没拿到余弦**的条目才继续按词法命中数筛 |
143
146
  | `autoContext.vectorAlpha` | 0.5 | 这两层内 `(1-α)·词法分 + α·余弦` 的权重;`0` 只关闭重排(写入侧去重仍在),`1`(纯向量)实测更差 |
144
147
  | `autoContext.vectorDedup` | true | 写入侧近重复检测(余弦 ≥0.9 自动覆盖、≥0.7 近邻提示)。与 `vectorAlpha` 独立;设 `false` 不影响召回排序 |
145
148
  | `autoContext.vectorItemMin` / `autoContext.vectorSpeakMin` | 未设 | **实验性**:提示通道的绝对余弦地板(条目级)与通道级语义救援。未标定——不设即关闭,开启前先看 `src/auto-inject.js` 里的实测证据 |
146
- | `autoContext.legacyScope` | `ignore` | 旧 `trigger.scope` 的处理:默认 `ignore`,不拿它当过滤条件;`filter` 拿它当过滤条件。`npm run selfcheck:triggers` 会列出仍带 scope 的条目 |
147
149
  | `autoContext.auditLog` | true | 每次**真实**注入往 `injection-audit.jsonl` 追加一行(注入了什么、为什么命中、丢了什么、会话额度);超过 `auditMaxBytes`(`262144`)轮转 `.1`。任何 IO 失败都静默 |
148
150
  | `autoContext.shadowLog` / `autoContext.shadowMaxBytes` | true / 524288 | **每步**(含什么都没注入的步)往 `admission-shadow.jsonl` 追加一行:被评分候选及其特征,以及每条候选卡在哪一关 —— 它让"换个阈值会怎样"可以离线回答。只写盘、不进 prompt;超过上限轮转,只保留一代 `.1` |
149
151
 
@@ -161,11 +163,11 @@ TaskPanel (Container)
161
163
 
162
164
  - `roots.allow`:即使命中了内置名单也允许作根,精确匹配;文件系统根不在此列。
163
165
  - `roots.deny`:这个目录不能当根,精确匹配;它的子目录仍可各自成根。
164
- - `roots.exclude`:这棵子树里的文件一律不进索引,按路径边界前缀匹配(含子目录);也不能在这里推出新的根。父根的完整扫描会跳过它,之前索引过的条目会在下一次完整扫描时清理。
166
+ - `roots.exclude`:这棵子树里的文件一律不进索引,按路径边界前缀匹配(含子目录);也不能在这里推出新的根。父根的完整扫描会跳过它,并清理该子树里已索引的条目。
165
167
 
166
168
  注意 `deny` 只决定这个目录自己能不能当根:父目录已经是根时,`deny` 的子目录仍会被父根索引——要连文件一起排除请用 `exclude`(或 `.gitignore`,git 仓库里的扫描本来就尊重它)。显式 `index_doc` 也服从 `exclude`,被排除的文件会返回 `Not indexed`。
167
169
 
168
- 优先级是 `exclude` > `deny` > `allow` > 内置名单。`allowUnsafeRoots: true` 保留为兼容,只放开内置名单,`deny` / `exclude` 仍然优先。生效面是同一套判定:显式工具调用、懒索引、watch、会话审计、任务桥。新增 `deny` / `exclude` 后,已登记在 `watch.json` 里的根会在下次启动自动摘掉。配置写在 `- id: project-memory` 的 `config:` 下(CLI 与 web 都适用);Web 端暂未提供正式配置页。
170
+ 优先级是 `exclude` > `deny` > `allow` > 内置名单。`allowUnsafeRoots: true` 只放开内置名单,`deny` / `exclude` 仍然优先。生效面是同一套判定:显式工具调用、懒索引、watch、会话审计、任务桥。被当前策略拒绝的根会在下次启动时从 `watch.json` 摘掉。配置写在 `- id: project-memory` 的 `config:` 下(CLI 与 web 都适用);Web 端没有独立配置页,直接改 profile。
169
171
 
170
172
  **扫描上限。** 单次扫描最多 `maxScanFiles` 个文件(20000)、`maxScanDepth` 层目录(12)。被截断时,`index_repo` 的结果里会说明,watcher 每个根记一行,且不会删除没扫到的条目。**读不到的目录**(如 `EACCES`)同样算一次截断扫描并在结果里点名:读失败不等于被删除。
171
173
 
@@ -186,7 +188,7 @@ store 建在被索引的目录树里,并且**自我忽略**:自己目录内
186
188
  maxScanFiles: 20000 # 单次扫描文件上限(截断会报告,且不会误删旧条目)
187
189
  maxScanDepth: 12 # 单次扫描目录深度上限
188
190
  enableTypeScript: true # 开启:装了 TS 时启用类型感知增强(默认)
189
- # allowUnsafeRoots: false # 兼容开关:只放开内置名单;优先改用下面的 roots.allow
191
+ # allowUnsafeRoots: false # 放开内置名单;优先改用下面的 roots.allow
190
192
  # roots: # 自定义根名单(默认全空)
191
193
  # allow: [/srv/projects/demo] # 精确放行内置名单里的目录(文件系统根不可放行)
192
194
  # deny: [/srv/shared] # 精确拒绝这个目录本身;子目录仍可成根
@@ -263,14 +265,14 @@ node scripts/bench.mjs /你的/项目路径 [--json] [--samples 100] [--no-pdf]
263
265
 
264
266
  ## 设计取舍
265
267
 
266
- - **短时文件锁,而不是嵌入式数据库** — 每次保存只在读改写期间持有排他的 `.write.lock`(解析在锁外完成),最多等 2 秒;对方忙时这次保存延后重试。两个 dsh 实例因此可以共用一个存储。没有 WAL、没有常驻进程、没有原生依赖。
268
+ - **短时文件锁,而不是嵌入式数据库** — 每次保存只在读改写期间持有排他的 `.write.lock`(解析在锁外完成),对方忙时最多**同步等 15s**(写路径的正确性靠等到锁,不靠后台重试);仍失败会登记进退出 flush,关 dsh / 卸载插件时再同步写一次。全程**默认不打扰用户**——记忆写入幂等、失败成本低;需要排查时设 `DSH_PROJECT_MEMORY_DEBUG=1` 才会打印一行。锁内容带 `pid` / `host` / `token`:同机持有者活着就绝不抢,release 校验所有权、不删别人的锁;崩溃残留的同机死锁按 pid 立即回收。两个 dsh 实例因此可以共用一个存储。没有 WAL、没有常驻进程、没有原生依赖。
267
269
  - **Watch:事务外计算,事务内提交** — 不持锁解析,也不用 `fs.watch`:轮询 + mtime/内容哈希在网络盘、Docker 卷、WSL 上行为一致,没有 `fs.watch` 的重复触发/漏事件问题。
268
270
  - **损坏分片隔离,不自动修复** — 解析失败的分片改名、只重索引该文件;不引入 WAL 或嵌入式数据库,那会带来原生依赖、锁竞争与它们自己的新故障模式。
269
271
  - **向量只重排,不做排序主力** — 在**改写成不含原词**的查询集上,纯向量替换差于 BM25(hit@10 **53% vs 69%**),加权融合只在**小 k** 上更好(hit@3 **53% vs 50%**),所以可选层只重排经验/洞察两层、绝不参与闸门。词法检索在本插件针对的查询上依然够用:真实项目 29 条标注查询的文件级 hit@5 为 **96.6%**,整 chunk 词项把文档词项覆盖从 **27.3% 提到 100%** 且 MRR 不变(**0.958** vs **0.955**)。
270
272
  - **索引确定且不调用模型** — 索引期不调模型、查询期也不翻译:前者会让同一份文档两次索引结果不同,后者有一个硬失败模式(译错 = 零召回);规则 + 符号链接已经覆盖常见情况,且离线可用。
271
273
  - **面向模型的记忆:agent 自己写,不把人放进回路** — 记忆的消费方是 agent,而 agent 通常是无头的,只在有人点卡片时才升级的记忆等于永远不会升级。`draft` 是「来源标记 + 佐证门槛」而不是审批队列。
272
274
  - **直接返回完整条目** — 条目本就紧凑,完整返回更可核验,也少一轮往返。
273
- - **`forget` 按关键词激进;精确请用 ID** — 经验笔记低风险、高量、仅用于检索,陈旧噪音比误删更伤。精确删用 `query_memory` 输出里的 ID。
275
+ - **`forget` 按关键词激进;精确请用 ID** — 经验笔记低风险、高量,陈旧噪音比误删更伤。精确删用 `query_memory` 输出里的 ID。
274
276
  - **TS 增强可选、异步、缓存** — 后台执行、不阻塞索引,没有 TS 时回退正则扫描;队列有上界,被丢弃的文件会在报告里给出条数。**默认 lib 不加载**:依赖全局类型(`Promise`/`Array`/DOM)的推导会退化成 `any`/`unknown`,显式标注的类型不受影响。
275
277
  - **子代理会话暂不纳入(以后可能做)**
276
278
 
@@ -280,7 +282,7 @@ node scripts/bench.mjs /你的/项目路径 [--json] [--samples 100] [--no-pdf]
280
282
 
281
283
  ```bash
282
284
  npm install
283
- npm test # 810 项测试
285
+ npm test # 885 项测试
284
286
  npm run eval:injection # 合成池 P/R:精确率 0.93 / 召回率 1.00,另有 3 个 hint-only 场景
285
287
  npm run eval:injection -- --store .dsh-project-memory/insights.json # 用你自己的 store 重放;对照组是硬闸门
286
288
  npm run selfcheck:triggers # 哪些条目还推得动、哪些声明是死的(读你本地的 store)