@yolk_vat-y/dsh-project-memory 0.6.3 → 0.6.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/CHANGELOG.md +140 -8
- package/README.md +26 -23
- package/README.zh-CN.md +24 -21
- package/client/client.js +272 -138
- package/client/client.js.map +1 -1
- package/package.json +3 -2
- package/scripts/bench-synthetic.mjs +22 -11
- package/src/audit.js +36 -32
- package/src/auto-inject.js +44 -23
- package/src/client/MemoryView.tsx +72 -4
- package/src/client/ShowTaskPanelNode.tsx +8 -5
- package/src/client/TaskCommandNode.tsx +22 -17
- package/src/client/TaskComponents.tsx +18 -3
- package/src/client/TaskPanel.tsx +50 -85
- package/src/client/client.ts +26 -6
- package/src/client/commands.ts +67 -0
- package/src/client/task-ui-store.ts +15 -2
- package/src/commands/task-actions.js +56 -2
- package/src/index.js +12 -0
- package/src/insight-store.js +200 -78
- package/src/lazy.js +3 -1
- package/src/ops.js +1 -1
- package/src/readiness.js +1 -1
- package/src/recall.js +76 -30
- package/src/setup/taskbridge.js +34 -3
- package/src/store.js +315 -44
- package/src/tools/forget.js +11 -8
- package/src/tools/index-doc.js +3 -5
- package/src/tools/index-repo.js +10 -11
- package/src/tools/lesson-tools.js +25 -35
- package/src/tools/query-memory.js +81 -28
- package/src/tools/remember.js +14 -11
- package/src/tools/stats.js +26 -3
- package/src/tools/task-tools.js +11 -12
- package/src/tools/watch-repo.js +3 -5
- package/src/types.js +9 -4
- package/src/util/fs.js +128 -1
- package/src/util/search.js +6 -27
- package/src/vector-index.js +175 -22
- package/src/watch.js +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,135 @@
|
|
|
1
|
+
## 0.6.4 (2026-10-23)
|
|
2
|
+
|
|
3
|
+
**0.6.3 之后的收口**:11 个提交全部是修复与内部整理,没有新增工具、没有删除配置项。用户能感觉到的变化集中在三处——语料开始跟随 `.gitignore`、几个"设成 0 本该关闭"的旋钮真的关闭了、面板里改一步不再整份回写。**升级前请读第一条与「向量层」那条**。
|
|
4
|
+
|
|
5
|
+
### 修改:索引语料改走 git 清单,`.gitignore` 与嵌套规则生效
|
|
6
|
+
|
|
7
|
+
**问题**:`walkDir` 是纯文件系统遍历,`.gitignore` 里写着的构建产物、内部文档、私有笔记一律进语料——用户 `index_repo` 之后才发现"这东西不该被记住"。
|
|
8
|
+
|
|
9
|
+
**改法**:
|
|
10
|
+
|
|
11
|
+
- 新增 `listProjectFiles()`:git 工作树走 `git ls-files -z --cached --others --exclude-standard`(已跟踪文件 + 未被忽略的未跟踪文件),嵌套 `.gitignore` 一并生效;非 git 目录回退 `walkDir`(忽略规则不生效,与旧版一致);之后再叠 `DEFAULT_IGNORE` 段名与 `maxScanFiles` / `maxScanDepth` 上限。
|
|
12
|
+
- 子模块只以 gitlink 出现,`statSync().isFile()` 为假直接丢弃;已删除但未暂存的路径也不会因此复活。
|
|
13
|
+
- 「读到即索引」对单个文件用 `git check-ignore -q` 判一次;显式 `index_doc` 不受此限。
|
|
14
|
+
- 扫描被截断(`capped`)时照旧**不清理**未见文件:没扫到 ≠ 被删了。
|
|
15
|
+
|
|
16
|
+
**升级注意**:老 store 里以前从被忽略路径索引进来的文件、以及子模块里的内容,会在升级后第一次**完整**索引时计入 `removed` 并删掉——那是派生索引,把文件重新纳入跟踪或显式 `index_doc` 即可重建。`index_repo` 的报告措辞也从 `code symbols updated` 改为 `code files updated`。
|
|
17
|
+
|
|
18
|
+
### 修复:两个进程同时写同一份 store 会互相覆盖
|
|
19
|
+
|
|
20
|
+
**问题**:`save()` 的"读—改—写"没有跨进程保护,后写的一方整段覆盖先写的一方:`insights.json` / `tasks.json` / `binding.json` 的改动直接丢。分片撞车时旧实现还会"跳过写入但内存以为写了",进程内与磁盘长期分叉。
|
|
21
|
+
|
|
22
|
+
**改法**:
|
|
23
|
+
|
|
24
|
+
- `acquireDirLock()`:在 store 目录下用 `openSync('wx')` 原子建 `.write.lock` 并写入 pid;2 秒内每 10 ms 重试一次,锁文件 mtime 超过 10 秒判为 stale 直接删;拿不到锁就**保留脏状态**、100 ms 间隔最多再试 3 次,只警告一次,而不是让工具调用失败。
|
|
25
|
+
- 锁内先 `_mergeAuxFromDisk()`:`insights` / `tasks` / `binding` / watchlist 按 `updatedAt`(任务用 `updatedAt || lastActiveAt`)取较新的一侧,平局取本地;本地删除用墓碑集合防复活;watchlist 取并集减墓碑。
|
|
26
|
+
- 分片冲突以"加载时 sha"为基线:磁盘 sha 既不是基线也不是本次写入 → 按 `indexedAt` 收敛(本地更新则覆盖,磁盘更新则读回内存),并只提示一次。
|
|
27
|
+
- 缓存逐出前先 `hasDirty()` 再 `save()`:延迟落盘之后,LRU 逐出不能把还没 flush 的任务热点直接扔掉。
|
|
28
|
+
|
|
29
|
+
**代价**:重试耗尽、或进程在 flush 前退出,仍可能丢掉这一回合尚未落盘的热点计数(正文写入同样依赖这次 flush)。
|
|
30
|
+
|
|
31
|
+
### 修复:经验层与洞察层各用一套打分器,`save_lesson` 写出的条目恒 0 分
|
|
32
|
+
|
|
33
|
+
**问题**:`save_lesson` 写出的 experience 条目没有 `problem` / `solution`,而旧 `rankExperienceScored` 拼给 BM25 的文档是三个字面量 `undefined` → 该条目**恒 0 分**;洞察桶又按 kind 排除了 experience,于是两条召回路径同时断掉:条目在库里,查不到,`query_memory` 还会印出 `Problem: undefined`。同一处还有两个连带问题:只给 `pattern` 的 lesson,`vectorText` 只认 title/problem/body,空串让 `vectorNear` 返回 null,0.9 自动覆盖与 0.7 近邻提示整体失效;只给 `choice` 的 decision,标题落成 `(untitled)`。影子审计里 `rel` 的分子是 BM25 分、分母却是融合 top,实测能到 5.925。
|
|
34
|
+
|
|
35
|
+
**改法**:经验层改用洞察层同一个 `insightToEntry` + `rankEntriesMergedScored`,命中后用 `byId` 换回原条目,`rankExperience(Scored)` 删除;`normalizeInsight` 的标题链补 `choice`;`vectorText` 用同一条链(title → pattern → problem → choice → topic → body)并截 200 字符;影子记录新增 `lexTop`,`rel = 词法分 / lexTop`,真实排序判据仍用融合分;渲染侧 problem→title、solution→fix→choice→body 兜底。
|
|
36
|
+
|
|
37
|
+
**影响**:experience 恢复可召回(短语加分、同义词展开都生效),不再输出 `undefined`。影子 `rel` 从"可以大于 1"变成"≤ 1"——按旧刻度做过的离线重放需要重标定。
|
|
38
|
+
|
|
39
|
+
### 修复:相关性闸门被整条关掉;缺向量分的条目按本轮均值补
|
|
40
|
+
|
|
41
|
+
**问题**:`matchedFloor` 的旧签名带 `hasVector`,只要 `Boolean(rerank)` 为真就整条通道不再筛。于是"装了 `leanvec` 但本轮给不出余弦"(查询编码失败、`embed` 抛异常、返回空 Map)时,单片段就 3.13 分的那种弱命中全漏进来——注释承诺的"逐字段退回纯词法"从来没成立过。另一头,缺向量分的条目按 `score = rel` 排序,等价于隐式补了一个 `α·0.5`;真实 store 里 7381 对余弦的中位数只有 0.28,查询→标题的 top-1 多在 0.51–0.63,于是"低余弦"条目反而被"完全没有向量"的压住。
|
|
42
|
+
|
|
43
|
+
**改法**:`matchedFloor(scored, queries)` 去掉 `hasVector`,改判 `typeof r.vector === 'number' || (r.matched ?? 0) >= need`(`need = min(2, 查询词数)`);顺序改为 融合 → 逐条闸门 → 截断 `limit`,经验层与洞察层同序;一条余弦都没有时 `fuseVectorHits` 原样返回未归一化的 `scored`,闸门对全体生效;缺分按 `neutral = 本轮已有余弦的均值` 补:`score = (1-α)·rel + α·(v ?? neutral)`。
|
|
44
|
+
|
|
45
|
+
**影响**:向量层开着但部分条目无分时,这两层单轮可能**少于** `limit` 条(旧行为是整条通道不筛);全量编码失败时与纯词法逐字段一致;低余弦条目不再被无分条目反超。
|
|
46
|
+
|
|
47
|
+
### 修复:`vectorAlpha: 0` 连带关掉写入去重,`autoMergeCos` / `hintCos: 0` 的语义反了
|
|
48
|
+
|
|
49
|
+
**问题**(四个都是"以为自己关了、其实全开或全关"):
|
|
50
|
+
|
|
51
|
+
- `forget` 只删条目,`vectors.json` 里那行 256 维均值池化还在——"真删"名不副实,下个进程还会把它复用回来。
|
|
52
|
+
- 写入侧的去重复用了召回侧的重排器,而后者 `alpha === 0` 直接返回 null:`vectorAlpha: 0`(只想关重排)会静默停掉 0.9 自动覆盖与 0.7 近邻提示。
|
|
53
|
+
- `autoMergeCos: 0` / `hintCos: 0` 在旧代码里是 `top1 >= 0` 恒真:设 0 等于"每条写入都覆盖最近一条 / 每次都给提示",而设 0 恰恰是关闭它最自然的写法。
|
|
54
|
+
- `vectorDir` 拼错和"没装 `leanvec`"在输出上毫无区别。
|
|
55
|
+
|
|
56
|
+
**改法**:
|
|
57
|
+
|
|
58
|
+
- 新增 `autoContext.vectorDedup`(默认 `true`),写入侧去重与 `vectorAlpha` 解耦;`createVectorCosine` 独立于 alpha。
|
|
59
|
+
- `autoMergeCos` / `hintCos` 设 0 现在是**关闭**(`!(cos > 0) → null`)。
|
|
60
|
+
- `forget` 同步清向量行:内存索引同时删 `usable` 快照与 `entryMap`(只删后者会被下次打分复活),磁盘 `vectors.json` 按 stride 重写;不加载模型,异常吞掉。
|
|
61
|
+
- `memory_stats` 多两行:向量层状态(`off` / `re-rank alpha` / `write-dedup`)与索引统计(rows / live / stale / KB / model / updated),`vectorDir` 配错不再静默。
|
|
62
|
+
- 新增实验性 `vectorItemMin` / `vectorSpeakMin`(绝对余弦闸门,不设即关,未标定)。
|
|
63
|
+
|
|
64
|
+
**影响**:`vectorAlpha: 0` 只关重排,写入去重默认仍开(会加载模型);`forget` 之后 `vectors.json` 会缩行、条目不再复活。`vectors.json` 格式未变(version 1 + ids / hashes / blob)。
|
|
65
|
+
|
|
66
|
+
### 修复:自动覆盖的绝对阈值在密集语料里会改错条目
|
|
67
|
+
|
|
68
|
+
**问题**:0.9 只对"当前语料 + 当前模型"成立。语料一模板化(大量同句式条目),池内最近邻余弦整体抬到 0.9 附近,0.9 就会去覆盖**不同**的知识;换模型、换向量表也会整体平移尺度。而自动覆盖是破坏性写入——直接改写既有条目正文,误合并等于静默丢数据。
|
|
69
|
+
|
|
70
|
+
**改法**:`vectorNear` 顺路累计有限余弦的 n / Σv / Σv²,返回 `mu` / `sigma` / `n`;μ 与 σ **排除候选自己**(`restN = n - 1`、`restSum = sum - top1`、`restSumSq = sumSq - top1²`,`restN > 1` 才算总体标准差);`autoMergeTarget` 的门槛改成 `floor = max(autoMergeCos, mu + 3σ)`,仍要求 `top1 - top2 >= autoMergeMargin`。`AUTO_MERGE_SIGMA = 3`:池 ≤300 时随机撞上的最大余弦约在 μ+2.9σ。只收紧不放宽——真实 store(122 条 / 7381 对)mean 0.281、sd 0.104 → μ+3σ ≈ 0.59 < 0.9,行为不变。
|
|
71
|
+
|
|
72
|
+
**影响**:密集语料里 0.92 不再自动覆盖(宁可多存一条,不改错一条);稀疏与中等密度池逐字段不变,`hintCos` 的 0.7 提示带不受影响。
|
|
73
|
+
|
|
74
|
+
### 修复:`query_memory` 的分节按固定顺序,最相关的常常落在最后
|
|
75
|
+
|
|
76
|
+
**问题**:结果按写死的分节顺序拼(Memory → Insights → Experience),分节内部有排序、分节之间没有。最相关的那条落在第三节时,被前面几节的弱结果挤到 4k 字符之后——分数明明是它最高。
|
|
77
|
+
|
|
78
|
+
**改法**:每个分节取一个 `bestHint`(最佳条目的 `rel × 层先验`:insight 1.15、doc/symbol 1.0、experience 0.9,与 `recallItems` 的 `flat.hint` 同口径),按它降序排段后再拼输出;稳定排序,同分保原序。只决定段落先后,不参与打分、不改任何条目自己的 `score`。
|
|
79
|
+
|
|
80
|
+
**影响**:同一查询的输出分节顺序会变(doc-only 查询仍 Memory 在前);条目分数、数量与 token 总量不变。
|
|
81
|
+
|
|
82
|
+
### 修复:符号的一行声明落盘了却不参与检索
|
|
83
|
+
|
|
84
|
+
**问题**:符号条目存了 `text`(签名 / 重载 / 类型体),但 `weightedFieldText` 只拼 title、keywords、summary、terms——于是"哪些函数收 union 类型""谁返回 `Promise<void>`"这类只能从签名回答的问题,检索侧完全看不到。顺带修掉 `query_memory` 里符号标题缺失时输出的 `- undefined`。
|
|
85
|
+
|
|
86
|
+
**改法**:`weightedFieldText` 并入 `entry.text`(只落盘不检索等于白存);渲染侧用 `text || title` 兜底。符号仍是每个一行、不新增字段,落盘体积不变;标题仍保留 5 倍权重,名字命中不会被签名盖过。
|
|
87
|
+
|
|
88
|
+
**影响**:带参数、返回类型或类型体的查询能命中符号;`query_memory` 的符号段会显示一行声明。
|
|
89
|
+
|
|
90
|
+
### 修改:工具 schema 压到约 5.4k 字符,并加了预算守卫
|
|
91
|
+
|
|
92
|
+
**问题**:工具描述与参数 schema 每次请求都要随上下文带上,是固定成本;0.6.x 期间它逐条膨胀到约 9100 字符。
|
|
93
|
+
|
|
94
|
+
**改法**:12 个工具的描述收敛成一句、参数说明去掉重复语义(`enum` / `required` 保留),`index_repo` / `query_memory` / `save_lesson` 等逐个重写;新增 `test/tool-schema-size.test.mjs`,把"描述 + 参数 schema"的总长钉在 5600 字符以内(当前 **5367** 字符 / 12 个工具,含工具名约 5493)。
|
|
95
|
+
|
|
96
|
+
**影响**:每轮固定开销降约 43%;工具行为与参数契约不变。
|
|
97
|
+
|
|
98
|
+
### 整理:审计写入器归一、global store 单例、`steps` 纳入密钥检测
|
|
99
|
+
|
|
100
|
+
- 影子审计与主审计共用一份配置归一(`cfgSideLog()`:默认开、只认显式 `false`、非法上限退回默认值)与一个写入器;两者只剩文件名与默认上限不同(审计 256 KB、影子 512 KB,各留一代 `.1`)。日志名、字段、轮转行为全不变。
|
|
101
|
+
- `GlobalStore` 按文件路径复用实例(与 project store 的 `storeCache` 同语义):两个工具 / 会话交错读写同一份 `global.json`,不再后写覆盖先写。
|
|
102
|
+
- 向量缓存的键加上模型指纹;taskbridge 的会话 Map 改成有界并在 `disposed` 时清理。
|
|
103
|
+
- `remember` 的 `source_file` 走 `normalizeCitationFiles()`:项目外的路径丢弃并回报,不再把任意绝对路径写进记忆。
|
|
104
|
+
- `containsSecretFields` 的默认字段加上 `steps`:流程类条目此前只查前八个字段,`steps` 数组里的密钥 / token 形态逃过检测。
|
|
105
|
+
- `index_repo` 透传 `allowUnsafe`,与其它工具对排除名单的处理保持一致。
|
|
106
|
+
|
|
107
|
+
### 修复:面板改一步要回写整份 steps;草稿会污染 project/global;切页把命令写进会话
|
|
108
|
+
|
|
109
|
+
**问题**(这一批的症状都在"看不见的写放大"上):
|
|
110
|
+
|
|
111
|
+
- 改一步状态就 `todos` 回写整份 `steps`:两个动作并发时互相覆盖,步数一多还带上整个数组。
|
|
112
|
+
- 反思草稿(`draft` / `source: reflect`)参与 project/global 的自动合并与自动提升——LLM 草稿能改写手写知识。
|
|
113
|
+
- 每切一次记忆页就发 `/tasks insight list`,会话里堆一串命令节点,历史被这些噪声占满。
|
|
114
|
+
- 文件工具每次调用写一次 `tasks.json`;拖动每 `mousemove` 写一次 localStorage,小窗口下卡片还能被拖出视口;"编辑中"的行不进去重指纹,写文件后模型一直看到旧的文件列表。
|
|
115
|
+
- 归档后 `binding.json` 仍指着那个任务;`_pruneBindings` 遇到畸形 JSON 直接抛错。
|
|
116
|
+
|
|
117
|
+
**改法**:
|
|
118
|
+
|
|
119
|
+
- 新增三个原子子命令 `/tasks step <i> <status>`、`/tasks step-text <i> <json>`、`/tasks step-move <from> <to>`(落点由服务端按拖拽语义算),RPC 收进 `src/client/commands.ts`(15 秒 AbortController、信封与错误归一);拖动只进本地 state,`mouseup` 才写 UI store,位置 clamp 在视口内;卡片头从 `button` 改成 `div[role=button]` 并补键盘处理。
|
|
120
|
+
- 草稿或 `source: reflect` 的条目跳过 project/global 合并与跨任务提升;跨任务池过滤 draft;显式编辑即转正(无变化也算确认)。
|
|
121
|
+
- 切页命中 30 秒缓存(键 `session|root|scope|boundTaskId`,换项目、换绑都会失效),列表型命令节点不再渲染;面板只在打开 / 切回任务页时补数据。
|
|
122
|
+
- 文件热点延迟落盘(`commit(..., { save: false })`),`turn/end` 与 `session/disposed` 统一 flush;缓存逐出前先落盘。
|
|
123
|
+
- 归档与 `load()` 时清理绑定;`_pruneBindings` 加形状防御。
|
|
124
|
+
|
|
125
|
+
**影响**:切页不再在对话里留行;换项目 / 换绑任务不串列表;`tasks.json` 写入频次明显下降。**已有草稿不再自动提升**,需要显式确认才进入 project/global。
|
|
126
|
+
|
|
127
|
+
### 整理:示例与文档里的专名中性化
|
|
128
|
+
|
|
129
|
+
README 双语与 CHANGELOG 里的具体框架名(`Vue`)、硬件与机器信息(`20 vCPU` / `本机` / 具体月份)、内部文件名(`PLAN-*` / `RELEASE-NOTES-*` / `de-TODO`)换成中性写法;测试夹具里的内部文件名改成 `notes.md` 这类占位。零运行时行为变化。
|
|
130
|
+
|
|
131
|
+
**测试**:`npm test` 720 → **756 项 / 44 个文件**(新增 `gitignore-index` / `store-concurrent` / `tool-schema-size`;`insight-store`、`recall`、`recall-vector-fusion`、`vector-index`、`auto-inject`、`client-toolview`、`client-task-sync` 等在既有 `ok` 块内补断言);`npm run typecheck` 通过;`npm run build:client` 重建与提交产物零差异。
|
|
132
|
+
|
|
1
133
|
## 0.6.3 (2026-10-20)
|
|
2
134
|
|
|
3
135
|
### 新增:删除留痕——`forget` 仍真删,但最近 5 条可从 `deleted.json` 找回
|
|
@@ -37,7 +169,7 @@
|
|
|
37
169
|
|
|
38
170
|
**测试**:`npm test` 705 → **720 项 / 41 个文件**(新增 `client-task-sync`;`insight-store` +1、`host-contract` +1、`taskbridge` +1、`root-guards` +8,其余在既有 `ok` 块内补断言),`npm run typecheck` 通过。
|
|
39
171
|
|
|
40
|
-
|
|
172
|
+
## 0.6.2 (2026-10-17)
|
|
41
173
|
|
|
42
174
|
`npm test` **705 项 / 40 个文件**;`npm run typecheck` 通过。
|
|
43
175
|
|
|
@@ -179,13 +311,13 @@
|
|
|
179
311
|
|
|
180
312
|
- 同一个进程里再 load 第二个大 root 时仍会结算一次——那正是预算可能被撞上的情形。`bench --json` 现在把两个口径分开:`coldLoadMs` 只记空进程冷启动,`secondStoreLoadMs` 记同进程第二个 store;合成基准的冷加载也改成独立进程量(同进程连 load 5 份副本会攒下 5 个 store,既绕不开结算也不是"冷启动")。
|
|
181
313
|
- `test/store-cache.test.mjs` 34 → **43** 项:新增"预算宽裕时不精确计量(无版本戳)""上界 ≥ 精确值且不超 8 倍""写进来的条目计入上界""同一文件重写是替换而非累加"。
|
|
182
|
-
- README
|
|
314
|
+
- README 双语的性能表按新口径重测(冷加载:前端语料 8 ms、文档工作区 10 ms、3k 切片 70 ms、整棵树 278 ms)。
|
|
183
315
|
|
|
184
316
|
### 测试与修复
|
|
185
317
|
|
|
186
318
|
- 新增 **5 个自然语言对照**与 **3 个 hint-only 场景**(提示通道召回 0/3、精度 1.00,只报告不设门);其中 1 条对照在基线上就注入一条无关经验,属**已知缺陷并钉住上界**。
|
|
187
319
|
- 新增 `test/recall-vector-fusion.test.mjs`(13 项)与 `test/vector-index.test.mjs`(10 项),都不需要 leanvec。
|
|
188
|
-
- `test/run-test.mjs`
|
|
320
|
+
- `test/run-test.mjs` 读真实的全局 insight store,导致 `no-hit query shows store overview` 随经验条数变红(乱码查询被 `no` 片段命中)。现在 globalFile 指向临时文件,测试**密闭**。
|
|
189
321
|
|
|
190
322
|
## 0.5.16 (2026-10-11)
|
|
191
323
|
|
|
@@ -448,7 +580,7 @@ id 前缀规则 `replace(/[\\/:\s]/g, '_')` 曾在**三处各写一份**(`doc-
|
|
|
448
580
|
- 结论:**旧的 50 MB 允许单个文件把宿主进程推到 ~1.2 GB RSS**(还有一次最长 12.5 s 的同步解析),
|
|
449
581
|
这正是 issue #5 那类 OOM 的形状。原先文档与计划里写的「峰值是它的 2–4 倍」**低了 5 倍**。
|
|
450
582
|
- 默认值改为 **10 MB**:最坏情况单文件增量 ≈ **+300 MB RSS**(20.6 × 10)。误伤面实测很小 ——
|
|
451
|
-
|
|
583
|
+
实测多个真实项目里只有 1 个文件超过 10 MB(一个 28.7 MB 的生成物,
|
|
452
584
|
也正是最该跳过的那类:生成的、符号密集、索引收益低而内存最贵)。旋钮仍可调高,
|
|
453
585
|
双语 README 的配置表与「单文件内存预算」一节都写明了各自系数。
|
|
454
586
|
- 口径提醒:heap 峰值受 GC 时序影响会**非单调**(同一档符号密集语料,32 MB 量出 625 MB、
|
|
@@ -1161,7 +1293,7 @@ git 会读取工作区里任意目录下的 `.gitignore`,`*` 连这个文件
|
|
|
1161
1293
|
- 索引逻辑收敛为 `src/index-pipeline.js`;auto-inject 会话状态收敛为 `InjectionSessions`
|
|
1162
1294
|
- 命令处理器共用 `invocationContext` / `fencedJson`
|
|
1163
1295
|
|
|
1164
|
-
|
|
1296
|
+
未修的低优先级发现见当期的发布笔记。
|
|
1165
1297
|
|
|
1166
1298
|
## 0.5.6 (2026-09-16) — injection admission (lessons/decisions/procedures stop arriving by coincidence)
|
|
1167
1299
|
|
|
@@ -1217,7 +1349,7 @@ git 会读取工作区里任意目录下的 `.gitignore`,`*` 连这个文件
|
|
|
1217
1349
|
- **The READMEs now point at it** (`Performance → Reproduce it on your own project`, plus the Development block) instead of asking readers to trust the tables. The labeled-set figures in Design tradeoff #4 are scoped to their internal corpus, with the method shipped; the docs also state the two caveats found while building it — `read+hash` is OS-page-cache sensitive, and real projects score slower than the synthetic corpus.
|
|
1218
1350
|
- **Retired the local-only harnesses it replaces** (`test/ablation*.mjs`, `test/doc-coverage*.mjs`, `test/gen-queries.mjs`, `test/simulate-agent.mjs`, `test/queries.json`) together with the dead `.gitignore` entries for them and for the August debug scaffolding.
|
|
1219
1351
|
- **The synthetic harness ships too.** `bench/microbench.mjs` moved to `scripts/bench-synthetic.mjs` (`npm run bench:synthetic -- 5000`), so the synthetic table is reproducible as well; `bench/` itself stays local-only.
|
|
1220
|
-
- **Every published number re-measured on 2026-09-14** (Node 24.19
|
|
1352
|
+
- **Every published number re-measured on 2026-09-14** (Node 24.19): 5k-file cold index 269 ms avg (p50 267), cold load 40 ms, cached query over 20k entries p50 2.6 / p95 5.4 ms, hot single-file re-index p50 2.4 ms, 10k-file cold index 551 ms avg, cold load 90 ms, IDF rebuild 106 ms at 40k entries (57 ms at 20k, 12 ms at 4k), symbol scan 12.9–19.2 µs/file. Table captions now name the environment and the reproduce command; the real-project example quotes the warm-cache run and states the cold-cache first run (787 ms vs 253 ms) instead of hiding it. `README.md`, `README.zh-CN.md` and the local notes were updated together so no two documents quote different numbers.
|
|
1221
1353
|
|
|
1222
1354
|
### Docs (README realigned with shipped behaviour)
|
|
1223
1355
|
|
|
@@ -1343,7 +1475,7 @@ git 会读取工作区里任意目录下的 `.gitignore`,`*` 连这个文件
|
|
|
1343
1475
|
|
|
1344
1476
|
### Changed (cold-index I/O)
|
|
1345
1477
|
|
|
1346
|
-
- **Single-read indexing — cold index ~4× faster**: every indexing path read each file twice (`await sha256OfFile()` for the hash, then `readFileSync()` for the body) and paid a per-file `async readFile` thread-pool round-trip. New `readFileForIndex()` does one synchronous read and hands the same buffer to both `createHash('sha256')` and `toString('utf8')`; `index_repo`, `watch`, and lazy read-on-observe all use it. Unchanged files are still hashed without decoding. Synthetic 5,000-file corpus (
|
|
1478
|
+
- **Single-read indexing — cold index ~4× faster**: every indexing path read each file twice (`await sha256OfFile()` for the hash, then `readFileSync()` for the body) and paid a per-file `async readFile` thread-pool round-trip. New `readFileForIndex()` does one synchronous read and hands the same buffer to both `createHash('sha256')` and `toString('utf8')`; `index_repo`, `watch`, and lazy read-on-observe all use it. Unchanged files are still hashed without decoding. Synthetic 5,000-file corpus (Node 24): cold index 1,093 ms → 272 ms (4.0×); the `read+hash` phase drops from 70% to 11% of the pipeline. Tests green.
|
|
1347
1479
|
|
|
1348
1480
|
### Fixed (host-contract + watch robustness)
|
|
1349
1481
|
|
|
@@ -1399,7 +1531,7 @@ git 会读取工作区里任意目录下的 `.gitignore`,`*` 连这个文件
|
|
|
1399
1531
|
- Tests: insight-store 11 / reflection-pipeline 5 / auto-inject 9 / insight-actions 7 (total 209, exit 0)
|
|
1400
1532
|
|
|
1401
1533
|
### Notes
|
|
1402
|
-
- Design rationale, deviations (non-destructive migration; reflection triggers subset; auto-inject host verification) and the live-verification checklist live in
|
|
1534
|
+
- Design rationale, deviations (non-destructive migration; reflection triggers subset; auto-inject host verification) and the live-verification checklist live in the internal design notes.
|
|
1403
1535
|
- Requires a dsh web restart to load the new server code and rebuilt client bundle.
|
|
1404
1536
|
|
|
1405
1537
|
### Fixed
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# dsh-project-memory
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> If this plugin saves you an hour of debugging, a star would be appreciated.
|
|
4
4
|
|
|
5
5
|
[English](README.md) | [简体中文](README.zh-CN.md)
|
|
6
6
|
|
|
@@ -22,7 +22,7 @@ A persistent **project development memory** for [DeepSeek Harness](https://githu
|
|
|
22
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.
|
|
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
|
-
- **Experience notes** — problems → solutions, deduplicated by overlap rather than repeated, bounded by project size, and
|
|
25
|
+
- **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
26
|
- **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
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
28
|
|
|
@@ -48,10 +48,12 @@ Each indexed project has its own store at `<root>/.dsh-project-memory/`. It keep
|
|
|
48
48
|
|
|
49
49
|
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
50
|
|
|
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.
|
|
52
|
+
|
|
51
53
|
| Tool | Purpose |
|
|
52
54
|
|---|---|
|
|
53
55
|
| `index_doc file_path` | Index one document (PDF/MD/txt): chunk, summarize deterministically, and store with a `path:line` citation. Unchanged files are skipped. |
|
|
54
|
-
| `index_repo root` | Index a whole project: documents get deterministic summaries, code files get a token-free symbol table. Incremental,
|
|
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. |
|
|
55
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. |
|
|
56
58
|
| `memory_stats root` | Show what the store contains: totals, last index time, and the per-file list sorted by recency. |
|
|
57
59
|
| `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. |
|
|
@@ -59,9 +61,9 @@ The tools below are **invoked by the agent**, not typed by the user. In the chat
|
|
|
59
61
|
| `select_task` | Bind the session to a task so its todo list and file reads sync into it. Exact `taskId`, or exact `title` (multiple matches return candidates; no match creates a new task). Pass `title` with `taskId` to rename. Auto-unarchives. |
|
|
60
62
|
| `archive_task` | Archive a task (hide from default views, exclude from capacity, stop syncing). `select_task` restores it. |
|
|
61
63
|
| `show_task_panel` | Show the task panel in the UI. Call when the user asks to see the task list or when you want to display the panel. |
|
|
62
|
-
| `/tasks` (typed by the user, not the model) | The only user command: shows the task stack and drives the workflow card. Every other action is a **sub-verb** invoked by card buttons: `switch` / `archive` / `unbind` / `rename` / `todos …` for tasks, `insight list [offset] [limit]` / `confirm` / `promote` / `demote` / `archive` / `restore` / `delete` / `save` / `edit` for memory. |
|
|
64
|
+
| `/tasks` (typed by the user, not the model) | The only user command: shows the task stack and drives the workflow card. Every other action is a **sub-verb** invoked by card buttons: `switch` / `archive` / `unbind` / `rename` / `todos …` / `step` / `step-move` / `step-text` for tasks, `insight list [scope] [offset] [limit]` / `confirm` / `promote` / `demote` / `archive` / `restore` / `delete` / `save` / `edit` for memory. |
|
|
63
65
|
| `remember problem solution` | Save an experience note. It is a `kind: 'experience'` insight — same store, same dedup and same delete path as lessons / decisions / procedures. Similar problems merge or overwrite instead of duplicating. |
|
|
64
|
-
| `forget id_or_query` | Delete memories — lessons / decisions / procedures and
|
|
66
|
+
| `forget id_or_query` | Delete memories — lessons / decisions / procedures and experience notes alike, across task / project / global in one call, without knowing which layer the entry lives in. An exact id deletes that one entry; keywords match by **query-side coverage** (matched query terms ÷ query terms). Real deletion, no undo; when keywords match more than the cap (default 10) it deletes nothing and only lists the candidates. The **5** most recently deleted entries are kept as full entries in that layer's `deleted.json` next to its store (`<root>/.dsh-project-memory/deleted.json` for the project layer, beside the global file for global), and the deletion result prints that path — read it and save again to recover a mis-delete. |
|
|
65
67
|
| `save_lesson` | Save a lesson / decision / procedure at task, project or global scope; passing `id` **overwrites that entry in place** (only the fields you pass, the previous values stay in `prev` — write them back with the same id). Before writing it compares against existing memory: cosine ≥ 0.9 auto-overwrites that entry, ≥ 0.7 reports the nearest id in the result; without `leanvec` it falls back to lexical overlap ≥ 0.7 merge / 0.65–0.7 reinforce. Two tasks hitting the same insight promote it task → project, three or more → global. Key params: `id`, `title`, `kind`, `scope`, the content (`pattern`/`fix`, `choice`/`reason` or `steps`), and `trigger` (`when` is the only trigger surface, `guard` narrows it, `prevents` records what breaks without it). |
|
|
66
68
|
|
|
67
69
|
`/tasks` appears in the web `/` menu inside an icon-bearing **Workflow** group, with three view entries — Tasks / Project Memory / Global Memory (labelled in the UI language). It is the plugin's only registered command; every other action rides it as a sub-verb driven by card buttons.
|
|
@@ -72,12 +74,12 @@ The design follows four principles:
|
|
|
72
74
|
|
|
73
75
|
- **Volatility** — context is ephemeral; it is lost when a session is compacted.
|
|
74
76
|
- **Persistence** — the **memory** is stored on disk and survives compaction and new sessions.
|
|
75
|
-
- **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
|
|
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**.
|
|
76
78
|
- **Verifiability** — **recalls** carry a `path:line` citation where applicable, so the agent can confirm details against the source.
|
|
77
79
|
|
|
78
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.
|
|
79
81
|
|
|
80
|
-
The store is per-project and follows the codebase: changed files are re-extracted by content hash, deleted files are removed. Experience notes are
|
|
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.
|
|
81
83
|
|
|
82
84
|
## Design
|
|
83
85
|
|
|
@@ -85,7 +87,6 @@ The store is per-project and follows the codebase: changed files are re-extracte
|
|
|
85
87
|
.dsh-project-memory/
|
|
86
88
|
format.json layout marker (v2, sharded)
|
|
87
89
|
shards/ one self-describing JSON per indexed source file — writes touch only dirty shards
|
|
88
|
-
experience.json.migrated read-only archive of v0.4 notes (imported into insights.json on first load)
|
|
89
90
|
watch.json watched roots
|
|
90
91
|
tasks.json TaskBridge task entities (cross-session)
|
|
91
92
|
binding.json current session ↔ task binding
|
|
@@ -98,7 +99,7 @@ The store is per-project and follows the codebase: changed files are re-extracte
|
|
|
98
99
|
- **Incremental** — a content hash per file; only changed files are re-extracted.
|
|
99
100
|
- **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.
|
|
100
101
|
- **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.
|
|
101
|
-
- **Consistency** — the fact layer follows the codebase (hash re-extract / remove-on-delete); the experience layer is retrieval-only with supersede and `forget`.
|
|
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.
|
|
102
103
|
|
|
103
104
|
## Architecture (Task Panel)
|
|
104
105
|
|
|
@@ -131,16 +132,18 @@ The workflow panel is collapsible, adapts to dsh and theme plugin styles, and of
|
|
|
131
132
|
| `llmQueryExpansion` / `expansionCount` | false / 6 | expand queries via the LLM before search (off by default to save tokens); max variants |
|
|
132
133
|
| `tsPath` / `enableTypeScript` | (auto) / true | optional absolute path to a specific `typescript` install; set `enableTypeScript: false` to disable the type-aware layer entirely |
|
|
133
134
|
| `tasklist.enabled` / `tasklist.syncHostOnAdopt` | true / true | TaskBridge auto-sync (task entities from the session todo list and file reads); push a bound task's steps to the host task list so dsh mirrors it |
|
|
134
|
-
| `insight.*` | dedupOverlap `0.7` · reinforceBand `0.65` · autoMergeCos `0.9` · autoMergeMargin `0.05` · hintCos `0.7` · maxForgetMatches `10` · maxProject `100` · maxGlobalProcedures `200` · promoteConfidence `0.7` · globalPromoteTasks `3` · decayDays `90` · `globalFile` (auto) | insight dedupe / auto-overwrite / near-neighbour hint / delete cap / reinforce / promotion / capacity / archive settings |
|
|
135
|
+
| `insight.*` | dedupOverlap `0.7` · reinforceBand `0.65` · autoMergeCos `0.9` · autoMergeMargin `0.05` · hintCos `0.7` · maxForgetMatches `10` · maxProject `100` · maxGlobalProcedures `200` · promoteConfidence `0.7` · globalPromoteTasks `3` · decayDays `90` · `globalFile` (auto) | insight dedupe / auto-overwrite / near-neighbour hint / delete cap / reinforce / promotion / capacity / archive settings. `autoMergeCos` / `hintCos` = `0` turns that band **off** |
|
|
135
136
|
| `reflection.enabled` | false | LLM reflection, **draft-only at task level** (fires on task switch-away / archive). `cooldownMs` `1800000`, `maxLessonsPerReflect` `3`, `maxDecisionsPerReflect` `2` |
|
|
136
137
|
| `autoContext.enabled` | true | silent injection wrapper (resident task card + gated items); inert until the host exposes a resolvable session cwd. `maxTokens` `400` (per step), `editedMax` `3` (recently written files shown on the task card), `signalMinRatio` `0.5` (a hint must reach half of its layer's top score), `skipEchoSelfTodo` `true`, `budgetLog` `off`, `reinjectItemsAfter` `0` (steps before the same insight may be injected again), `rootNotice` `true` |
|
|
137
138
|
| `autoContext.gateCooldownSteps` | 2 | minimum number of pre-steps between two *item* injections (the resident task card is exempt — it is a state snapshot). This is the main "don't inject often" dial |
|
|
138
139
|
| `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 |
|
|
139
140
|
| `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" |
|
|
140
141
|
| `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 |
|
|
141
|
-
| `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
|
|
142
|
-
| `autoContext.vectorAlpha` | 0.5 | weight of `(1-α)·lexical + α·cosine` in those layers; `0` disables
|
|
143
|
-
| `autoContext.
|
|
142
|
+
| `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 |
|
|
143
|
+
| `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 |
|
|
144
|
+
| `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 |
|
|
145
|
+
| `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 |
|
|
146
|
+
| `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 |
|
|
144
147
|
| `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 |
|
|
145
148
|
| `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 |
|
|
146
149
|
|
|
@@ -156,7 +159,7 @@ When the root comes from the working directory, the model gets one notice per se
|
|
|
156
159
|
|
|
157
160
|
**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.
|
|
158
161
|
|
|
159
|
-
**Per-file memory budget.** `maxFileSizeMb` is a memory gate, not a disk-space preference. Indexing a file first materializes it — the whole buffer plus decoded text for code, or every PDF page's text plus the joined markdown for documents — and the peak scales with the file's size. Measured on this machine with `npm run bench:peak` (peak RSS fitted against disk size over a 1–50 MB ladder, one fresh process per point): **≈10×** for typical source code (1 declaration per ~1.4 KB), **≈22×** for symbol-dense code (1 per 220 B) and **≈20×** for a text-heavy PDF, on top of a ~52 MB process baseline plus a one-off ≈175 MB the first time a PDF is parsed. The 10 MB default therefore keeps a single file at roughly **+300 MB RSS** for code and **+370 MB** for a PDF; raising the cap raises that ceiling proportionally.
|
|
162
|
+
**Per-file memory budget.** `maxFileSizeMb` is a memory gate, not a disk-space preference. Indexing a file first materializes it — the whole buffer plus decoded text for code, or every PDF page's text plus the joined markdown for documents — and the peak scales with the file's size. Measured on this machine with `npm run bench:peak` (peak RSS fitted against disk size over a 1–50 MB ladder, one fresh process per point): **≈10×** for typical source code (1 declaration per ~1.4 KB), **≈22×** for symbol-dense code (1 per 220 B) and **≈20×** for a text-heavy PDF, on top of a ~52 MB process baseline plus a one-off ≈175 MB the first time a PDF is parsed. The 10 MB default therefore keeps a single file at roughly **+300 MB RSS** for code and **+370 MB** for a PDF; raising the cap raises that ceiling proportionally.
|
|
160
163
|
|
|
161
164
|
The store lives in the tree it indexes and **ignores itself**: a `*` rule inside the store keeps it out of `git status` and `git add -A`, and means `git clean -fd` leaves it alone. To commit project memory deliberately, `git add -f .dsh-project-memory` — tracked files are not affected by ignore rules.
|
|
162
165
|
|
|
@@ -194,11 +197,11 @@ where `config.yml` contains the same override block.
|
|
|
194
197
|
|
|
195
198
|
### Measured on real projects (2026-10-13)
|
|
196
199
|
|
|
197
|
-
Four corpora, one machine (Node 24.19
|
|
200
|
+
Four corpora, one Linux machine (Node 24.19), each run twice with the **second, warm-cache run** quoted. "Cold index" is a full index pass (walk + hash + extract + commit); "query" runs the shipped scorer over 100 sampled queries; "re-index 1 file" is the watch/lazy hot path.
|
|
198
201
|
|
|
199
202
|
| Corpus | Files / entries | Cold index | Cold load | Query p50 / p95 | Re-index 1 file | Store content / on disk | Heap after load |
|
|
200
203
|
|--------|-----------------|-----------|-----------|-----------------|-----------------|------------------------|-----------------|
|
|
201
|
-
|
|
|
204
|
+
| Frontend app (code only) | 289 / 2,142 | 246 ms | 8 ms | 0.76 / 1.4 ms | 0.3 ms | 0.66 MB / 1.52 MB | 6.3 MB |
|
|
202
205
|
| Docs workspace (Markdown + PDFs) | 249 / 977 | 705 ms | 10 ms | 1.8 / 5.5 ms | 0.4 ms | 1.31 MB / 1.84 MB | 6.8 MB |
|
|
203
206
|
| TypeScript monorepo, 3,000-file slice | 3,000 / 17,576 | 1.9 s | 70 ms | 9.2 / 18.9 ms | 1.9 ms | 10.9 MB / 18.9 MB | 22.7 MB |
|
|
204
207
|
| TypeScript monorepo, whole tree | 12,634 / 80,231 | 7.8 s | 278 ms | 40.6 / 74.8 ms | 7.2 ms | 42.0 MB / 75.7 MB | 75.2 MB |
|
|
@@ -207,7 +210,7 @@ Four corpora, one machine (Node 24.19, 20 vCPU, Linux file system), each run twi
|
|
|
207
210
|
|
|
208
211
|
> `read+hash` depends on the OS page cache — 2.3 s cold vs 0.27 s warm on the 12,634-file tree — so the table quotes the warm figure.
|
|
209
212
|
|
|
210
|
-
### Synthetic Benchmark (Node 24.19,
|
|
213
|
+
### Synthetic Benchmark (Node 24.19, Linux)
|
|
211
214
|
|
|
212
215
|
| Scenario | Scale | Measured |
|
|
213
216
|
|----------|-------|----------|
|
|
@@ -232,7 +235,7 @@ npm run bench -- /path/to/your/project
|
|
|
232
235
|
node scripts/bench.mjs /path/to/your/project [--json] [--samples 100] [--no-pdf] [--keep]
|
|
233
236
|
```
|
|
234
237
|
|
|
235
|
-
It reports the cold index split into read+hash / extract / commit, cold load, IDF rebuild, cold and hot query latency (p50/p95/max over 100 sampled queries through the shipped scorer), single-file hot re-index, store size, resident heap and bytes per entry. Example — the
|
|
238
|
+
It reports the cold index split into read+hash / extract / commit, cold load, IDF rebuild, cold and hot query latency (p50/p95/max over 100 sampled queries through the shipped scorer), single-file hot re-index, store size, resident heap and bytes per entry. Example — the frontend app row above:
|
|
236
239
|
|
|
237
240
|
```
|
|
238
241
|
cold index 246 ms (read+hash 8 ms · extract 222 ms · commit 14 ms) ← 2nd, warm-cache run
|
|
@@ -246,16 +249,16 @@ Pass `--queries your-queries.json` to run the labeled-set method (hit@5 / hit@10
|
|
|
246
249
|
|
|
247
250
|
## Design tradeoffs
|
|
248
251
|
|
|
249
|
-
- **
|
|
252
|
+
- **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.
|
|
250
253
|
- **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.
|
|
251
254
|
- **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.
|
|
252
|
-
- **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
|
|
255
|
+
- **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**).
|
|
253
256
|
- **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.
|
|
254
257
|
- **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.
|
|
255
258
|
- **Full entries returned directly** — entries are already compact, so returning them whole is more verifiable and one round-trip cheaper.
|
|
256
259
|
- **`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`.
|
|
257
260
|
- **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.
|
|
258
|
-
- **Subagent sessions are out of scope
|
|
261
|
+
- **Subagent sessions are out of scope**
|
|
259
262
|
|
|
260
263
|
## Development (for contributors)
|
|
261
264
|
|
|
@@ -263,8 +266,8 @@ These commands are for **maintaining the plugin code** — regular users do not
|
|
|
263
266
|
|
|
264
267
|
```bash
|
|
265
268
|
npm install
|
|
266
|
-
npm test #
|
|
267
|
-
npm run eval:injection # synthetic pool P/R: precision 0.
|
|
269
|
+
npm test # 756 tests
|
|
270
|
+
npm run eval:injection # synthetic pool P/R: precision 0.93 / recall 1.00, + a 3-scenario hint-only group
|
|
268
271
|
npm run eval:injection -- --store .dsh-project-memory/insights.json # replay on YOUR store; control group is a hard gate
|
|
269
272
|
npm run selfcheck:triggers # which entries can still push, which declarations are dead (reads your local store)
|
|
270
273
|
npm run bench -- /path/to/project # index/query performance on any project — no dsh needed
|
package/README.zh-CN.md
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
- **读到即记忆、变更即刷新** — 文件在模型实际读取的瞬间被记忆,记忆是正常工作的副产品,而不是额外的一次全量扫描;从未读过的文件不会被记忆。后台轮询只重记变更过的文件。
|
|
22
22
|
- **文档 ↔ 代码交叉链接** — 文档提及的符号,在查询该符号时一并带出。链接按**当前**符号表解算,不会过期。
|
|
23
23
|
- **混合召回** — 对文档、符号、经验笔记与 insight 排序召回,可选 LLM 查询扩展。`leanvec` 是 optionalDependency:默认装上并按余弦重排经验/洞察两层,没装或 `vectorDir: 'off'` 则退回纯词法。针对 CJK 增强:短语加分、同义词表,以及文档↔符号链接的词边界处理。
|
|
24
|
-
- **经验笔记** — 记录问题 →
|
|
24
|
+
- **经验笔记** — 记录问题 → 方案;相似问题覆盖而不重复,数量随项目规模有界,与教训走同一条注入通道:检索与自动注入都能带出。
|
|
25
25
|
- **分层 insight 记忆(教训 / 决策 / 流程)** — 同一实体贯穿任务、项目、全局三级。近重复合并或强化;提升是更换归属而非复制。被使用会记账,因此衰减与容量按活跃度排序,而不是只按时间。面板提供分级的记忆视图用于审核与编辑;列表按新→旧排列并增量加载——每页 30 条,滚到底前就预取下一页,离屏行不参与渲染,记忆变多也不卡。
|
|
26
26
|
- **触发式注入** — insight 可携带 authored trigger:只有 `when` 能触发,`guard` 只能收窄,`prevents` 记下没有它会坏在哪。语料正文永远不能触发注入;统计通道另有独立门槛,默认沉默。
|
|
27
27
|
|
|
@@ -47,10 +47,12 @@ dsh plugin --profile web add @yolk_vat-y/dsh-project-memory -w
|
|
|
47
47
|
|
|
48
48
|
以下工具由 **agent 自动调用**,无需用户手动输入。在对话中直接说自然语言即可——例如「给这个项目建个索引」或「auth 模块是干嘛的」,或者正常开发即可——agent 会自动调用对应工具。默认开启「读到即索引」:模型读哪个文件,就顺便索引哪个文件,记忆在你干活的过程中自然积累。`watch_repo` 让显式监听的根目录在后台保持新鲜;`index_repo` 强制对项目做一次全量回填(未变更文件自动跳过)。
|
|
49
49
|
|
|
50
|
+
在 git 工作树里,语料就是 `git ls-files --cached --others --exclude-standard` 的清单——已跟踪文件,加上未被忽略的未跟踪文件——因此 `.gitignore`(含嵌套规则)决定什么会被记忆。不是 git 工作树的目录退回普通遍历(不套忽略规则)。「读到即索引」对单个文件套用同一判据;显式 `index_doc` 则总是索引你指定的文件。
|
|
51
|
+
|
|
50
52
|
| 工具 | 用途 |
|
|
51
53
|
|---|---|
|
|
52
54
|
| `index_doc file_path` | 索引单个文档(PDF/MD/txt):分块、确定性摘要,带 `路径:行号` 入库。未变更文件自动跳过。 |
|
|
53
|
-
| `index_repo root` | 索引整个项目:文档生成确定性摘要,代码文件生成零 token
|
|
55
|
+
| `index_repo root` | 索引整个项目:文档生成确定性摘要,代码文件生成零 token 符号表。增量更新,store 跟随文件清单:已删除、被忽略或移走的文件会被清理;文档与符号交叉链接。根目录不存在或在排除名单上时,会在写入任何内容前拒绝。 |
|
|
54
56
|
| `watch_repo root` | 启用自动刷新:后台轮询检测新增/变更文件,仅重抽这些文件。监听的项目在插件重启后自动恢复;不存在或在排除名单上的根目录会被拒绝,已消失的根目录会被丢弃而不是被重新创建。 |
|
|
55
57
|
| `memory_stats root` | 查看记忆库内容:总量、最近索引时间,以及按时间排序的逐文件清单。 |
|
|
56
58
|
| `query_memory query` | 对文档、符号、经验与 insight 执行排序检索,可选 LLM 查询扩展。`type` 选择层(`all` / `doc` / `symbol` / `experience` / `insight` / `task`)。返回带相对分数、引用或 insight id、以及文档→符号链接的结果。 |
|
|
@@ -58,9 +60,9 @@ dsh plugin --profile web add @yolk_vat-y/dsh-project-memory -w
|
|
|
58
60
|
| `select_task` | 将会话绑定到某任务(此后 todo 清单与读文件同步进该任务)。按 `taskId` 精确绑定,或按 `title` 完全匹配(多个同名返回候选;无则新建)。带 title 可改名;自动解归档。 |
|
|
59
61
|
| `archive_task` | 归档任务(隐藏默认视图、不占容量、停止同步)。`select_task` 可恢复。 |
|
|
60
62
|
| `show_task_panel` | 在 UI 中打开任务面板。用户要求查看任务列表或你想展示面板时调用。 |
|
|
61
|
-
| `/tasks`(用户输入,不经模型) | 唯一的用户命令:展示任务栈并驱动工作流卡片。其余动作是它的**子动词**,由卡片按钮调用:`switch` / `archive` / `unbind` / `rename` / `todos …` 为任务动作,`insight list [offset] [limit]` / `confirm` / `promote` / `demote` / `archive` / `restore` / `delete` / `save` / `edit` 为记忆动作。 |
|
|
63
|
+
| `/tasks`(用户输入,不经模型) | 唯一的用户命令:展示任务栈并驱动工作流卡片。其余动作是它的**子动词**,由卡片按钮调用:`switch` / `archive` / `unbind` / `rename` / `todos …` / `step` / `step-move` / `step-text` 为任务动作,`insight list [scope] [offset] [limit]` / `confirm` / `promote` / `demote` / `archive` / `restore` / `delete` / `save` / `edit` 为记忆动作。 |
|
|
62
64
|
| `remember problem solution` | 保存经验笔记。它就是 `kind: 'experience'` 的 insight——与教训 / 决策 / 流程同库、同去重、同删除入口。相似问题合并或覆盖而非重复。 |
|
|
63
|
-
| `forget id_or_query` | 删除记忆——教训 / 决策 / 流程与经验笔记一视同仁,task / project / global 全层一次搞定,不必先知道它在哪一层。精确 id
|
|
65
|
+
| `forget id_or_query` | 删除记忆——教训 / 决策 / 流程与经验笔记一视同仁,task / project / global 全层一次搞定,不必先知道它在哪一层。精确 id 删那一条;关键词按**查询侧覆盖率**匹配(命中词 ÷ 查询词数)。真删、无撤销;关键词命中超过上限(默认 10)时**一条都不删**,只列出候选。最近删除的 **5 条**会以完整条目留在该层 store 同目录的 `deleted.json`(项目层 `<root>/.dsh-project-memory/deleted.json`,global 层在 global 文件旁),删除回报里给出真实路径——删错时读它、重新保存一次即可找回。 |
|
|
64
66
|
| `save_lesson` | 在 task/project/global 任一作用域保存教训 / 决策 / 流程;带 `id` 就是**就地覆盖**既有条目(只改本次显式传的字段,旧值留在 `prev`,用同一个 id 再写一次即可写回)。写入前与既有记忆比对:余弦 ≥ 0.9 自动覆盖那一条,≥ 0.7 在返回里提示近邻 id;`leanvec` 不在时退回词法 overlap ≥ 0.7 合并、0.65–0.7 强化。同一 insight 被 2+ 任务命中自动 task→project、3+ → global。主要参数:`id`、`title`、`kind`、`scope`、正文(`pattern`/`fix`、`choice`/`reason` 或 `steps`)、`trigger`(`when` 是唯一触发面,`guard` 只能收窄,`prevents` 记下没有它会坏在哪)。 |
|
|
65
67
|
|
|
66
68
|
`/tasks` 在 web 的 `/` 菜单里以带图标的**「工作流」**组呈现 —— 三个视图入口:任务 / 项目记忆 / 全局记忆(标题随界面语言切换)。它是插件唯一注册的命令,其余动作全部作为它的子动词由卡片按钮驱动。
|
|
@@ -71,12 +73,12 @@ dsh plugin --profile web add @yolk_vat-y/dsh-project-memory -w
|
|
|
71
73
|
|
|
72
74
|
- **易失性** — 上下文是临时的,会话压缩即丢失。
|
|
73
75
|
- **持久性** — **记忆**存于磁盘,跨压缩与会话保留。
|
|
74
|
-
- **紧凑性** — 代码层每个符号只存一行有界声明,文档层每个 chunk 保留 ≤300 字符的摘要与有界词项。**派生数据一律不落盘**:doc→symbol 链接在读取期计算。最终体积取决于符号密度与 chunk 长度,下面是特定语料的实测值(2026-10-13
|
|
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/条目**。
|
|
75
77
|
- **可核验性** — **召回**在适用时携带 `路径:行号` 引用,agent 可对照源文件核实。
|
|
76
78
|
|
|
77
79
|
构建**记忆**无需预先全量扫描:文件在模型读取时被记忆,**记忆**恰好覆盖实际处理过的内容。未变更的文件重读是空操作,因此持续维护开销很低。
|
|
78
80
|
|
|
79
|
-
|
|
81
|
+
存储按项目独立存放,并跟随代码库变化:文件变更按内容哈希重新抽取,文件删除则同步移除。经验笔记是 `insights.json` 里 `kind: 'experience'` 的条目,仅检索、累积不影响上下文。
|
|
80
82
|
|
|
81
83
|
## 设计
|
|
82
84
|
|
|
@@ -84,7 +86,6 @@ dsh plugin --profile web add @yolk_vat-y/dsh-project-memory -w
|
|
|
84
86
|
.dsh-project-memory/
|
|
85
87
|
format.json 布局标记(v2,分片式)
|
|
86
88
|
shards/ 每个被索引源文件一个自描述 JSON —— 写入只落脏分片
|
|
87
|
-
experience.json.migrated v0.4 经验笔记的只读归档(首次加载已导入 insights.json)
|
|
88
89
|
watch.json 被监听根目录
|
|
89
90
|
tasks.json TaskBridge 任务实体(跨会话)
|
|
90
91
|
binding.json 当前会话 ↔ 任务绑定
|
|
@@ -97,7 +98,7 @@ dsh plugin --profile web add @yolk_vat-y/dsh-project-memory -w
|
|
|
97
98
|
- **增量** — 按文件内容哈希,仅重新抽取变更文件。
|
|
98
99
|
- **交叉链接** — `query_memory` 返回文档 chunk 时,按**当前**符号表解算它提到的符号,以 `references` 带出。文档先索引、符号后到也能链上。
|
|
99
100
|
- **查询扩展** — `llmQueryExpansion` 开启时,把查询改写为多个变体(同义词、中英、符号名猜测)再合并分数;关闭时查询完全不碰 LLM。索引本身不调用模型。
|
|
100
|
-
- **一致性** — 事实层跟随代码库(哈希重抽 / 删除即移除);经验层仅检索,配合覆盖与 `forget`
|
|
101
|
+
- **一致性** — 事实层跟随代码库(哈希重抽 / 删除即移除);经验层仅检索,配合覆盖与 `forget` 机制。写入在跨进程的目录锁(`.write.lock`)内做一次短暂的读改写,因此两个 dsh 实例可以共用一个项目存储:分片按 `indexedAt` 收敛,拿不到锁的那次保存会延后重试。
|
|
101
102
|
|
|
102
103
|
## 架构(任务面板)
|
|
103
104
|
|
|
@@ -130,16 +131,18 @@ TaskPanel (Container)
|
|
|
130
131
|
| `llmQueryExpansion` / `expansionCount` | false / 6 | 检索前用 LLM 扩展查询(默认关闭,节省 token);扩展变体上限 |
|
|
131
132
|
| `tsPath` / `enableTypeScript` | (自动) / true | 可选:强制指定 `typescript` 安装路径;`enableTypeScript: false` 彻底禁用类型感知层 |
|
|
132
133
|
| `tasklist.enabled` / `tasklist.syncHostOnAdopt` | true / true | TaskBridge 自动同步(由会话 todo 清单与文件读取沉淀任务实体);绑定任务时把其步骤推给宿主任务清单,使 dsh 镜像该任务 |
|
|
133
|
-
| `insight.*` | dedupOverlap `0.7` · reinforceBand `0.65` · autoMergeCos `0.9` · autoMergeMargin `0.05` · hintCos `0.7` · maxForgetMatches `10` · maxProject `100` · maxGlobalProcedures `200` · promoteConfidence `0.7` · globalPromoteTasks `3` · decayDays `90` · `globalFile`(自动) | insight 去重 / 自动覆盖 / 近邻提示 / 删除上限 / 强化 / 提升 / 容量 /
|
|
134
|
+
| `insight.*` | dedupOverlap `0.7` · reinforceBand `0.65` · autoMergeCos `0.9` · autoMergeMargin `0.05` · hintCos `0.7` · maxForgetMatches `10` · maxProject `100` · maxGlobalProcedures `200` · promoteConfidence `0.7` · globalPromoteTasks `3` · decayDays `90` · `globalFile`(自动) | insight 去重 / 自动覆盖 / 近邻提示 / 删除上限 / 强化 / 提升 / 容量 / 归档设置。`autoMergeCos` / `hintCos` 设 `0` 表示**关闭**那条带 |
|
|
134
135
|
| `reflection.enabled` | false | LLM 反思,**只写任务级草稿**(触发于任务切走 / 归档)。`cooldownMs` `1800000`、`maxLessonsPerReflect` `3`、`maxDecisionsPerReflect` `2` |
|
|
135
136
|
| `autoContext.enabled` | true | 静默注入包装(常驻任务卡 + 受门槛约束的条目);宿主无法解析会话 cwd 时完全透传。`maxTokens` `400`(单轮)、`editedMax` `3`(任务卡显示的最近"编辑中"文件数)、`signalMinRatio` `0.5`(提示至少达到该层最高分的一半)、`skipEchoSelfTodo` `true`、`budgetLog` `off`、`reinjectItemsAfter` `0`(同一条 insight 重复注入的冷却步数)、`rootNotice` `true` |
|
|
136
137
|
| `autoContext.gateCooldownSteps` | 2 | **准入旋钮**:两次*条目*注入之间至少隔几步(常驻任务卡不受限——它是状态快照)。这是"别频繁注入"的主旋钮 |
|
|
137
138
|
| `autoContext.maxItemsPerSession` / `autoContext.maxItemCharsPerSession` | 60 / 24000 | **runaway 保险丝,不是节流阀** —— 按条数与字符计的每会话硬上限:一旦触顶,本会话余下部分条目通道持续沉默 |
|
|
138
139
|
| `autoContext.hintMinCoverage` | 0.45 | 提示通道的**绝对**下限:条目覆盖了查询多少 IDF 加权信息量。只用相对阈值分不出"有信号"和"矮子里拔将军" |
|
|
139
140
|
| `autoContext.hintMinMatched` / `autoContext.hintMinSupport` | 2 / 0.15 | 提示还必须至少共享这么多个词;且查询里能在语料中找到对应的词占比不低于该值时,通道才出声——否则本轮整体沉默 |
|
|
140
|
-
| `autoContext.vectorDir` | 未设 | **可选**语义层,只作用于经验/洞察两层;随 `leanvec`(optionalDependency)默认装上并启用(79 MB、约 +130 MB RSS)。填 `off` 强制纯词法;填路径或用 `DSH_LEANVEC_DIR`
|
|
141
|
-
| `autoContext.vectorAlpha` | 0.5 | 这两层内 `(1-α)·词法分 + α·余弦` 的权重;`0`
|
|
142
|
-
| `autoContext.
|
|
141
|
+
| `autoContext.vectorDir` | 未设 | **可选**语义层,只作用于经验/洞察两层;随 `leanvec`(optionalDependency)默认装上并启用(79 MB、约 +130 MB RSS)。填 `off` 强制纯词法;填路径或用 `DSH_LEANVEC_DIR` 可覆盖。只改排序、返回条数不变;启用时只有**没拿到余弦**的条目才继续按词法命中数筛 |
|
|
142
|
+
| `autoContext.vectorAlpha` | 0.5 | 这两层内 `(1-α)·词法分 + α·余弦` 的权重;`0` 只关闭重排(写入侧去重仍在),`1`(纯向量)实测更差 |
|
|
143
|
+
| `autoContext.vectorDedup` | true | 写入侧近重复检测(余弦 ≥0.9 自动覆盖、≥0.7 近邻提示)。与 `vectorAlpha` 独立;设 `false` 不影响召回排序 |
|
|
144
|
+
| `autoContext.vectorItemMin` / `autoContext.vectorSpeakMin` | 未设 | **实验性**:提示通道的绝对余弦地板(条目级)与通道级语义救援。未标定——不设即关闭,开启前先看 `src/auto-inject.js` 里的实测证据 |
|
|
145
|
+
| `autoContext.legacyScope` | `ignore` | 旧 `trigger.scope` 的处理:默认 `ignore`,不拿它当过滤条件;`filter` 拿它当过滤条件。`npm run selfcheck:triggers` 会列出仍带 scope 的条目 |
|
|
143
146
|
| `autoContext.auditLog` | true | 每次**真实**注入往 `injection-audit.jsonl` 追加一行(注入了什么、为什么命中、丢了什么、会话额度);超过 `auditMaxBytes`(`262144`)轮转 `.1`。任何 IO 失败都静默 |
|
|
144
147
|
| `autoContext.shadowLog` / `autoContext.shadowMaxBytes` | true / 524288 | **每步**(含什么都没注入的步)往 `admission-shadow.jsonl` 追加一行:被评分候选及其特征,以及每条候选卡在哪一关 —— 它让"换个阈值会怎样"可以离线回答。只写盘、不进 prompt;超过上限轮转,只保留一代 `.1` |
|
|
145
148
|
|
|
@@ -155,7 +158,7 @@ TaskPanel (Container)
|
|
|
155
158
|
|
|
156
159
|
**扫描上限。** 单次扫描最多 `maxScanFiles` 个文件(20000)、`maxScanDepth` 层目录(12)。被截断时,`index_repo` 的结果里会说明,watcher 每个根记一行,且不会删除没扫到的条目。**读不到的目录**(如 `EACCES`)同样算一次截断扫描并在结果里点名:读失败不等于被删除。
|
|
157
160
|
|
|
158
|
-
**单文件内存预算。** `maxFileSizeMb` 管的是内存而不是磁盘偏好。索引一个文件要先把它整个物化——代码是整个 buffer 加解码后的正文,文档是逐页正文再加拼出来的 markdown
|
|
161
|
+
**单文件内存预算。** `maxFileSizeMb` 管的是内存而不是磁盘偏好。索引一个文件要先把它整个物化——代码是整个 buffer 加解码后的正文,文档是逐页正文再加拼出来的 markdown——峰值随文件大小线性走。用 `npm run bench:peak` 实测(1–50 MB 阶梯,每档一个独立进程,对「峰值 RSS = a + b × 磁盘 MB」做最小二乘):典型源码(约 1 个声明 / 1.4 KB)**≈10×**,符号密集的代码(1 个 / 220 B)**≈22×**,文本型 PDF **≈20×**;此外还有约 52 MB 的进程基线,以及首次解析 PDF 一次性约 175 MB 的底座。默认 10 MB 因此把单个文件的增量压在 **+300 MB RSS**(代码)/ **+370 MB**(PDF)量级;调大它就按比例抬高这个上限。
|
|
159
162
|
|
|
160
163
|
store 建在被索引的目录树里,并且**自我忽略**:自己目录内的一条 `*` 规则让它不出现在 `git status` / `git add -A` 里,`git clean -fd` 也不会删它。确实想把记忆跟着仓库提交:`git add -f .dsh-project-memory`——已跟踪文件不受忽略规则影响。
|
|
161
164
|
|
|
@@ -193,11 +196,11 @@ dsh web --patch ./config.yml
|
|
|
193
196
|
|
|
194
197
|
### 真实项目实测(2026-10-13)
|
|
195
198
|
|
|
196
|
-
|
|
199
|
+
四个语料、同一台 Linux 机器(Node 24.19),每个跑两遍、引用**第二次(页缓存已热)**的数据。「冷索引」= 完整索引一轮(walk + 哈希 + 抽取 + 落盘);「查询」= 线上同一套 scorer 跑 100 条采样;「单文件重索引」= watch / 懒索引热路径。
|
|
197
200
|
|
|
198
201
|
| 语料 | 文件数 / 条目数 | 冷索引 | 冷加载 | 查询 p50 / p95 | 单文件重索引 | 存储内容 / 落盘 | 加载后堆 |
|
|
199
202
|
|------|----------------|--------|--------|----------------|--------------|----------------|----------|
|
|
200
|
-
|
|
|
203
|
+
| 前端应用(纯代码) | 289 / 2,142 | 246 ms | 8 ms | 0.76 / 1.4 ms | 0.3 ms | 0.66 MB / 1.52 MB | 6.3 MB |
|
|
201
204
|
| 文档工作区(Markdown + PDF) | 249 / 977 | 705 ms | 10 ms | 1.8 / 5.5 ms | 0.4 ms | 1.31 MB / 1.84 MB | 6.8 MB |
|
|
202
205
|
| TypeScript monorepo,3,000 文件切片 | 3,000 / 17,576 | 1.9 s | 70 ms | 9.2 / 18.9 ms | 1.9 ms | 10.9 MB / 18.9 MB | 22.7 MB |
|
|
203
206
|
| TypeScript monorepo,整棵树 | 12,634 / 80,231 | 7.8 s | 278 ms | 40.6 / 74.8 ms | 7.2 ms | 42.0 MB / 75.7 MB | 75.2 MB |
|
|
@@ -206,7 +209,7 @@ dsh web --patch ./config.yml
|
|
|
206
209
|
|
|
207
210
|
> `read+hash` 受操作系统页缓存影响——12,634 文件时冷缓存 2.3 s、热缓存 0.27 s——上表引用的是热缓存那一遍。
|
|
208
211
|
|
|
209
|
-
### 合成基准测试(Node 24.19,
|
|
212
|
+
### 合成基准测试(Node 24.19,Linux)
|
|
210
213
|
|
|
211
214
|
| 场景 | 规模 | 实测 |
|
|
212
215
|
|------|------|------|
|
|
@@ -231,7 +234,7 @@ npm run bench -- /你的/项目路径
|
|
|
231
234
|
node scripts/bench.mjs /你的/项目路径 [--json] [--samples 100] [--no-pdf] [--keep]
|
|
232
235
|
```
|
|
233
236
|
|
|
234
|
-
输出包含:冷索引(拆成 read+hash / extract / commit 三段)、冷加载、IDF 重建、冷查询与热查询延迟(100 条采样报 p50/p95/max
|
|
237
|
+
输出包含:冷索引(拆成 read+hash / extract / commit 三段)、冷加载、IDF 重建、冷查询与热查询延迟(100 条采样报 p50/p95/max)、单文件热重索引、存储体积、常驻堆与单条目字节数。示例——上表里的前端应用:
|
|
235
238
|
|
|
236
239
|
```
|
|
237
240
|
冷索引 246 ms (read+hash 8 ms · extract 222 ms · commit 14 ms)← 第二次、页缓存已热
|
|
@@ -245,10 +248,10 @@ node scripts/bench.mjs /你的/项目路径 [--json] [--samples 100] [--no-pdf]
|
|
|
245
248
|
|
|
246
249
|
## 设计取舍
|
|
247
250
|
|
|
248
|
-
-
|
|
251
|
+
- **短时文件锁,而不是嵌入式数据库** — 每次保存只在读改写期间持有排他的 `.write.lock`(解析在锁外完成),最多等 2 秒;对方忙时这次保存延后重试。两个 dsh 实例因此可以共用一个存储。没有 WAL、没有常驻进程、没有原生依赖。
|
|
249
252
|
- **Watch:事务外计算,事务内提交** — 不持锁解析,也不用 `fs.watch`:轮询 + mtime/内容哈希在网络盘、Docker 卷、WSL 上行为一致,没有 `fs.watch` 的重复触发/漏事件问题。
|
|
250
253
|
- **损坏分片隔离,不自动修复** — 解析失败的分片改名、只重索引该文件;不引入 WAL 或嵌入式数据库,那会带来原生依赖、锁竞争与它们自己的新故障模式。
|
|
251
|
-
- **向量只重排,不做排序主力** — 在**改写成不含原词**的查询集上,纯向量替换差于 BM25(hit@10 **53% vs 69%**),加权融合只在**小 k** 上更好(hit@3 **53% vs 50
|
|
254
|
+
- **向量只重排,不做排序主力** — 在**改写成不含原词**的查询集上,纯向量替换差于 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**)。
|
|
252
255
|
- **索引确定且不调用模型** — 索引期不调模型、查询期也不翻译:前者会让同一份文档两次索引结果不同,后者有一个硬失败模式(译错 = 零召回);规则 + 符号链接已经覆盖常见情况,且离线可用。
|
|
253
256
|
- **面向模型的记忆:agent 自己写,不把人放进回路** — 记忆的消费方是 agent,而 agent 通常是无头的,只在有人点卡片时才升级的记忆等于永远不会升级。`draft` 是「来源标记 + 佐证门槛」而不是审批队列。
|
|
254
257
|
- **直接返回完整条目** — 条目本就紧凑,完整返回更可核验,也少一轮往返。
|
|
@@ -262,8 +265,8 @@ node scripts/bench.mjs /你的/项目路径 [--json] [--samples 100] [--no-pdf]
|
|
|
262
265
|
|
|
263
266
|
```bash
|
|
264
267
|
npm install
|
|
265
|
-
npm test #
|
|
266
|
-
npm run eval:injection # 合成池 P/R:精确率 0.
|
|
268
|
+
npm test # 756 项测试
|
|
269
|
+
npm run eval:injection # 合成池 P/R:精确率 0.93 / 召回率 1.00,另有 3 个 hint-only 场景
|
|
267
270
|
npm run eval:injection -- --store .dsh-project-memory/insights.json # 用你自己的 store 重放;对照组是硬闸门
|
|
268
271
|
npm run selfcheck:triggers # 哪些条目还推得动、哪些声明是死的(读你本地的 store)
|
|
269
272
|
npm run bench -- /你的/项目路径 # 对任意项目量索引/查询性能,不需要 dsh
|