@yolk_vat-y/dsh-project-memory 0.6.7 → 0.6.9
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 +56 -0
- package/README.md +10 -9
- package/README.zh-CN.md +10 -9
- package/client/client.js +518 -144
- package/client/client.js.map +1 -1
- package/cordis.patch.yml +4 -0
- package/package.json +4 -4
- package/src/auto-inject.js +4 -2
- package/src/client/SettingsCard.module.css +185 -0
- package/src/client/client.ts +4 -1
- package/src/client/locales.ts +31 -0
- package/src/client/settings-card.tsx +346 -0
- package/src/enhancer.js +7 -3
- package/src/index-failures.js +46 -0
- package/src/index-pipeline.js +26 -7
- package/src/index.js +36 -11
- package/src/insight-store.js +6 -1
- package/src/lazy.js +208 -43
- package/src/parsers/pdfjs-parser.js +33 -4
- package/src/setup/taskbridge.js +5 -2
- package/src/store.js +211 -80
- package/src/tools/index-doc.js +24 -4
- package/src/tools/index-repo.js +18 -6
- package/src/tools/query-memory.js +20 -8
- package/src/tools/stats.js +8 -0
- package/src/tools/watch-repo.js +10 -7
- package/src/util/config.js +65 -0
- package/src/util/fs.js +144 -23
- package/src/watch.js +81 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,59 @@
|
|
|
1
|
+
## 0.6.9 (2026-11-02)
|
|
2
|
+
|
|
3
|
+
**兼容**:无新增配置键,无 store 格式变更(启动时会顺手把 `watch.json` 里大小写重复的根条目合并成一条;文件格式不变)。三个既有键——`watchInterval` / `autoIndexOnFirstUse` / `llmQueryExpansion`——在 `Config` 里标成 `.volatile()`:这是宿主设置表单的准入条件(只有 volatile 字段能被 settings 接口写入),也让它们在运行中原地更新而不重启插件。profile / 命令行的写法完全不变。插件内部读取统一走 `cfgValue()`:volatile 字段在运行时是 ref(`.get()`),直接把 ref 当布尔会读错。升级后**需要重启一次 dsh**——volatile 元数据只在装配期解析。两处**行为变化**:① 扫描与懒索引都跳过隐藏路径(任一段以 `.` 开头,如 `.env` / `.github/**`),显式 `index_doc` 仍可索引(已存在的隐藏路径条目会在下一次完整扫描被清理);② `autoContext.maxTokens: 0` 现在真的零注入(此前被 `|| 400` 顶回默认值)。
|
|
4
|
+
|
|
5
|
+
### 新增:插件页上的可视化设置(web)
|
|
6
|
+
|
|
7
|
+
- 座位是 `plugins.bundle.config`(key = 包名):**插件 → 项目记忆 → 详情页**,在描述与行列表之间出现「常用设置」卡片。
|
|
8
|
+
- 三个手调旋钮:启动时全量索引(`autoIndexOnFirstUse`,下次启动生效)、刷新间隔(`watchInterval`,秒)、检索时扩展查询(`llmQueryExpansion`)。后台监视**刻意不给开关**:关掉只会让记忆越来越旧,不是一个"偏好";`lazyIndexing` / `enableTypeScript` 属于内部取舍,也留在 profile。
|
|
9
|
+
- 卡片默认收起(与宿主的插件卡片同构:标题 + 说明 + 箭头),展开后三行、底部右对齐保存;未保存时标题旁有一个"未保存"标记。保存走宿主 `settings` 接口(Config 校验 + revision fence),不另写配置文件——卡片始终是宿主那份配置的投影。
|
|
10
|
+
- 立即生效:`watchInterval` 由 `applyWatchSettings()` 按新值重排定时器;`llmQueryExpansion` 每次查询时读取。`autoIndexOnFirstUse` 是一次性启动动作,卡片上写明"下次启动生效"。
|
|
11
|
+
- 门控是**两层**且都是软依赖:客户端只在宿主同时提供 `slots` / `configForms` / `locale`、且 `project-memory` 命名空间已被提供时才注册;旧宿主(ui-primitives 没有对应控件)上零注册,并打一条点名原因的告警而不是静默消失。组件存在性判定必须接受 `forwardRef` 返回的**对象**(宿主的 `Button` 就是对象)——用 `typeof x === 'function'` 会把真实组件当成不存在,卡片整块消失。
|
|
12
|
+
- 其余旋钮(`memoryDir`、`roots.*`、扫描上限、insight / 反思 / 自动注入)**不进卡片**:它们要么一改就换数据位置,要么需要理解上下文,仍写 profile。
|
|
13
|
+
|
|
14
|
+
### 修复
|
|
15
|
+
|
|
16
|
+
- **watch 设置保存 / 回合结束不再停摆或误退避**:`start()` 先复位 `_stopped` 再判断进行中的轮询(设置页走 `stop() → start()`,否则那一轮结束后永久不再排下一轮);回合结束只在没有在飞 poll 时补扫,避免把"本轮无变化"误记成退避。
|
|
17
|
+
- **删除分片失败不再被当成"已经没了"**:`unlink` 对 Windows 的 EPERM/EBUSY 重试,仍失败则保留删除意图、下次 save 继续删(否则下一次 load 会把旧分片复活)。锁释放失败时把锁内容改成死进程,避免自己堵自己 10 分钟。
|
|
18
|
+
- **`explicit` 标记在重新索引时保留**:`applyFileUpdate()` 从旧记录继承 `explicit`,否则显式 `index_doc` 的 .gitignored 文件活不过下一轮扫描清理。
|
|
19
|
+
- **`experience.json` 迁移放进跨进程目录锁**:锁内重读磁盘再决定是否导入,两个 dsh 同时升级同一个旧 store 时不再互相覆盖。
|
|
20
|
+
- **畸形 store 容错**:`insights.items` / `tasks` / `watchlist` 里的 null 与非数组形状不再让全局召回或容量裁剪整段抛错;任务缺 `files` / `fileMeta` 在 `load()` 时归一(此前每次文件工具调用都会在 `touchTaskFile()` 抛错,热点追踪静默失效)。
|
|
21
|
+
- **增强队列的孤儿符号**:文件在排队增强期间被删除时,不再写一条没有 `files` 记录的孤儿符号(`unseen` 清理看不到它,查询却会一直命中)。
|
|
22
|
+
- **相对 `root` 按会话工作目录解析**:`resolveIndexRoot()` / `resolveSafeIndexRoot()` 以及 `index_repo` / `watch_repo` / `index_doc` 的显式 root 不再用宿主 `process.cwd()` 解析相对路径——web profile 下一个进程服务多个会话,cd 之后两者不是一回事。
|
|
23
|
+
- **扫描跳过隐藏路径的口径统一**:git 清单分支与 `walkDir` 回退都跳过任一段以 `.` 开头的路径(`.env`、`.github/**`、`.claude/**`),同一棵树 `git init` 前后语料一致;显式 `index_doc` 仍可索引隐藏文件。
|
|
24
|
+
- **`autoContext.maxTokens: 0` 真正零注入**:不再被 `cfg.maxTokens || 400` 顶回默认值(任务卡与条目都静默)。
|
|
25
|
+
- **`GlobalStore.markDirty()` 登记退出 flush**:`query_memory` 只改内存的 global 命中记账/派生 trigger 回填不会在进程退出时丢失(project store 有下一次 save 兜底,global 没有周期性 save 点)。
|
|
26
|
+
- **后台索引失败不再静默**:watch 的失败过去只写一行日志、懒索引的单文件失败被 `catch {}` 吞掉,用户看不到"有文件一直没进语料"。现在失败按根记进进程内账本(最多 50 条,成功即清),并随 `index_repo` / `memory_stats` 的输出一起报出。
|
|
27
|
+
- **Electron 宿主里 PDF 索引全灭(issue #10)**:pdf.js 只在 `isNodeJS` 为真时兜底 `workerSrc`,而宿主进程是 Electron 且 `process.type !== 'browser'` → 默认值整块跳过,每次解析都抛 `No "GlobalWorkerOptions.workerSrc" specified`。现在 `loadPdfjs()` 在 worker 未配置时用 `import.meta.resolve`(老 Node 退回 `createRequire`)解析 `pdf.worker.mjs` 的 `file://` URL 兜底;显式 `configurePdfjsWorker()` 与 pdf.js 自己的默认值仍优先。原实现里的 `configuredWorkerSrc` 分支因无人调用恒为假,纯 Node 测试里 `isNodeJS` 又恰好为真,所以这个洞从首版起一直没人发现(0.6.3 与 0.6.8 上都能复现),且失败只写一条 W 级日志。
|
|
28
|
+
- **大小写不同的同一目录不再被登记两次**:`watch_repo` 先以 `D:\proj`、后以 `d:\PROJ` 登记时,`watch.json` 会留两条、watch 每轮扫两遍,而 `watch_repo({watch:false})` 只删得掉其中一条(另一条下次启动复活)。`WatchManager` 与 watchlist 现在按 `storeKey()` 归一(保留第一次出现的写法;加载时顺手把老 store 里的重复条目合并)。
|
|
29
|
+
|
|
30
|
+
**测试**:新增 `test/pdfjs-host.test.mjs`(2 项:纯 Node 对照组;子进程里把 `process.type` / `process.versions.electron` 改成 Electron 宿主形态后解析 PDF,并断言正文命中——只断言"没抛错"会放过空正文的假成功)。新增 `test/settings-card.test.mjs`(10 项:三个 volatile 键与默认值(并断言其余键不进命名空间)、`cfgValue()` 的 ref/普通值双形状、空路径 `[[]]` 读成"全部重读"、watch 关停/改间隔即重排、整份 `apply()` 在 ref 形状 Config 上装配、槽位注册的 key 与命名空间、默认收起与展开后 3 行、`Button` 以 forwardRef 对象形状参与注册、命名空间未提供与缺 settings 控件两种零注册)。本轮另补 7 项回归:`maxTokens: 0` 零注入、相对 root 按会话 cwd 解析、git / walk 两种扫描的隐藏路径口径一致、懒索引也跳过隐藏路径、畸形任务缺 `files` 的归一、`GlobalStore.markDirty()` 进入退出 flush、watch 根与 watch.json 的大小写归一(2 项)。新增 `test/index-failures.test.mjs`(3 项:账本按根隔离与上限、懒索引失败登记与成功清除、`index_repo` 报出后台失败)。`npm test` **930 项 / 54 个文件**全绿、`npm run typecheck` 通过;`npm run build:client` 后 `client/` 零 diff(CI 也会复核产物与源码一致)。
|
|
31
|
+
|
|
32
|
+
## 0.6.8 (2026-10-30)
|
|
33
|
+
|
|
34
|
+
**兼容**:条目上多一个可选的 `mtimeMs`(旧条目缺省时按老行为整读 + 哈希)。无新增配置键,无破坏性 store 变更。懒索引不再对已有记录的文件问 gitignore,新文件仍问。
|
|
35
|
+
|
|
36
|
+
### 性能:懒索引去掉每文件的固定开销
|
|
37
|
+
|
|
38
|
+
- `planFileIndex`:mtime + size 未变直接返回,不读盘、不哈希。
|
|
39
|
+
- 新增 `refreshMtime()`:内容未变但 mtime 变了(touch / checkout 还原)时记回新 mtime。
|
|
40
|
+
- `indexFile` 拆成规划与落盘两段,新增 `indexObservedBatch()`:一次 flush 每个 store 只 commit 一次。
|
|
41
|
+
- 项目根按目录缓存 5s,但只缓存**由标记推出**的根:会话根兜底是"这一带还没有标记"的推断,不入缓存——`git init` / `npm init` 在子目录里建出项目时,缓存会让文件先落进会话根的 store(真根出现后就多一份重复条目)。无标记目录因此仍按次走一遍祖先(与加缓存前一致)。
|
|
42
|
+
- 新增 `isGitIgnoredBatch()`:一条 `git check-ignore --stdin -z` 判一批;gitignore 判定挪到确认有变化之后。
|
|
43
|
+
- `watch` / `index_repo` / `index_doc` 也记录 `mtimeMs`。
|
|
44
|
+
- 新增 `test/lazy-batch.test.mjs`。
|
|
45
|
+
|
|
46
|
+
**实测**(同会话旧 vs 新):12k 文件 / 48k 条目的 store、WSL 挂 `/mnt/c`(NTFS 悲观代理)下,重复读 66.0 → 0.9 ms p50、改一个文件后单独索引 96.5 → 32.7 ms p50;本机 ext4(200 文件 git 仓库)重复读 1.4 → 0.007 ms、改文件 1.7 → 0.19 ms。四个真实语料(vue / voice / harness 3k / 全树)同会话 A/B 的冷索引、查询与 watch 内核重索引都在 ±5% 噪声内(小语料冷加载本身抖动大,vue 7–11 ms)。
|
|
47
|
+
|
|
48
|
+
### 修复
|
|
49
|
+
|
|
50
|
+
- 构建:产物改为跨平台确定。lightningcss 的 `[hash]` 会把 `filename` 算进类名,此前传的是绝对路径,换台机器构建就整套换类名;现改用相对 POSIX 路径。`.gitattributes` 统一 LF(sourcemap 的 `sourcesContent` 会原样嵌入源文件行尾),CI 增加产物一致性校验。
|
|
51
|
+
- `test/lazy-batch.test.mjs`:不再用 `utimes()` 还原 mtime(Windows 上无法逐位还原),改为直接改写记录里的 mtime。
|
|
52
|
+
- `index_doc`:先 stat 再读正文,记录里的 mtime 不会比内容新。
|
|
53
|
+
- 懒索引的根缓存:会话根兜底不再入缓存(判据是 `findProjectRootWithSource()` 的 `source`,不靠 `root === sessionRoot` 猜)——子目录里 5s 内新建的 `.git` / `package.json` 立刻生效。
|
|
54
|
+
|
|
55
|
+
**测试**:`npm test` **892 项 / 51 个文件**全绿;`npm run typecheck` 通过。新增 `test/lazy-batch.test.mjs`(7 项:mtime 快路径、touch 后回填 mtime、批内一次 save、批量 gitignore 与逐个判定一致、会话根兜底不缓存)。
|
|
56
|
+
|
|
1
57
|
## 0.6.7 (2026-10-28)
|
|
2
58
|
|
|
3
59
|
**兼容**:无新增配置键,也没有破坏性的 store 变更——条目上只多一个可选的 `explicit` 标记(旧条目缺省即按非显式处理)。一处判据语义变化:原生 Windows 壳现在签 `windows` 而不是 `wsl`,写了 `guard.hosts: ['wsl']` 又想覆盖原生 Windows 命令的条目要改成 `windows`。老 profile 与旧 store 直接升级。
|
package/README.md
CHANGED
|
@@ -50,14 +50,14 @@ Each indexed project has its own store at `<root>/.dsh-project-memory/`. It keep
|
|
|
50
50
|
|
|
51
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).
|
|
52
52
|
|
|
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.
|
|
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. Hidden paths (any path segment starting with `.`) and the built-in ignore list (`node_modules`, `dist`, …) are skipped in both modes; a directory that is not a git work tree falls back to a plain walk with the same filter. Lazy indexing applies the same check when a file first enters the store; a file that is already indexed is refreshed on later reads without asking git again — if `.gitignore` starts excluding it, the `index_repo` / `watch_repo` scan drops it. An explicit `index_doc` bypasses both `.gitignore` and the hidden-path filter, but still respects `roots.exclude`, readability and the size limit, and its entry survives later scan passes for as long as the file exists.
|
|
54
54
|
|
|
55
55
|
| Tool | Purpose |
|
|
56
56
|
|---|---|
|
|
57
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. |
|
|
58
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
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. |
|
|
60
|
-
| `memory_stats root` | Show what the store contains: totals, last index time, and the per-file list sorted by recency. |
|
|
60
|
+
| `memory_stats root` | Show what the store contains: totals, last index time, and the per-file list sorted by recency. Background index failures (watch or lazy, per root, most recent 50) are reported alongside, so a file that never made it into the corpus stays visible. |
|
|
61
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. |
|
|
62
62
|
| `list_tasks` | List task records for the project (archived marked). Call first in a new session before continuing work. |
|
|
63
63
|
| `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. |
|
|
@@ -139,7 +139,7 @@ The workflow panel is collapsible, adapts to dsh and theme plugin styles, and of
|
|
|
139
139
|
| `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 |
|
|
140
140
|
| `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** |
|
|
141
141
|
| `reflection.enabled` | false | LLM reflection, **draft-only at task level** (fires on task switch-away / archive). `cooldownMs` `1800000`, `maxLessonsPerReflect` `3`, `maxDecisionsPerReflect` `2` |
|
|
142
|
-
| `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` |
|
|
142
|
+
| `autoContext.enabled` | true | silent injection wrapper (resident task card + gated items); inert until the host exposes a resolvable session cwd. `maxTokens` `400` (per step; `0` turns injection off entirely), `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` |
|
|
143
143
|
| `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 |
|
|
144
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 |
|
|
145
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" |
|
|
@@ -169,7 +169,7 @@ When the root comes from the working directory, the model gets one notice per se
|
|
|
169
169
|
|
|
170
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.
|
|
171
171
|
|
|
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
|
|
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`.
|
|
173
173
|
|
|
174
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.
|
|
175
175
|
|
|
@@ -203,6 +203,8 @@ Settings live in the plugin's config object. To change them, add an override ent
|
|
|
203
203
|
|
|
204
204
|
Only list the keys you want to change; the rest fall back to the plugin defaults. Verify the result with `dsh --profile web --dump-config`.
|
|
205
205
|
|
|
206
|
+
**On the web profile, three of these keys also have a visual card.** It sits at **Plugins → Project memory → detail page → Common settings** (`plugins.bundle.config`, keyed by package name): `autoIndexOnFirstUse`, `watchInterval` (seconds) and `llmQueryExpansion`. Saving goes through the host's `settings` interface — the card is a projection of the same config the profile override above feeds, not a separate file. `watchInterval` and `llmQueryExpansion` take effect immediately (the poll timer is re-armed, the expansion flag is read per query); `autoIndexOnFirstUse` is a one-off startup action, so the card says "effective next start". Everything else — `memoryDir`, `roots.*`, scan caps, insight / reflection / autoContext — deliberately stays in the profile: those either move the store or need context a three-row card cannot carry, and there is no switch for background watching (turning it off only lets memory go stale). On a host that does not offer the `slots` / `configForms` / `locale` services the card registers nothing and logs one warning naming the missing piece, rather than disappearing silently. These three are resolved when the plugin is assembled, so **restart dsh once after upgrading** (saving the card itself needs no restart).
|
|
207
|
+
|
|
206
208
|
For a one-off run without editing the profile, pass the override as a CLI patch overlay:
|
|
207
209
|
|
|
208
210
|
```bash
|
|
@@ -215,7 +217,7 @@ where `config.yml` contains the same override block.
|
|
|
215
217
|
|
|
216
218
|
### Measured on real projects (2026-10-13)
|
|
217
219
|
|
|
218
|
-
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
|
|
220
|
+
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 re-index core (read + extract + commit), which excludes the lazy path's root-resolution / `.gitignore` overhead.
|
|
219
221
|
|
|
220
222
|
| Corpus | Files / entries | Cold index | Cold load | Query p50 / p95 | Re-index 1 file | Store content / on disk | Heap after load |
|
|
221
223
|
|--------|-----------------|-----------|-----------|-----------------|-----------------|------------------------|-----------------|
|
|
@@ -224,7 +226,7 @@ Four corpora, one Linux machine (Node 24.19), each run twice with the **second,
|
|
|
224
226
|
| 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 |
|
|
225
227
|
| 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 |
|
|
226
228
|
|
|
227
|
-
**How it scales.** Re-indexing a changed file costs O(file), not O(corpus) — 0.3–7.2 ms across every corpus above. Cold load (≈22 µs/file), query (≈0.5 µs/entry on the largest corpus) and resident heap (≈1.5 KB/entry once queried) grow linearly with the index, which keeps small and mid-size projects in the single-digit-millisecond range.
|
|
229
|
+
**How it scales.** Re-indexing a changed file costs O(file), not O(corpus) — 0.3–7.2 ms across every corpus above. Cold load (≈22 µs/file), query (≈0.5 µs/entry on the largest corpus) and resident heap (≈1.5 KB/entry once queried) grow linearly with the index, which keeps small and mid-size projects in the single-digit-millisecond range. Re-reading a file that is already indexed costs ≈0.01 ms: it stops after one `stat` plus a cached record lookup, with no read, no hash and no `git check-ignore`.
|
|
228
230
|
|
|
229
231
|
> `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.
|
|
230
232
|
|
|
@@ -275,8 +277,7 @@ Pass `--queries your-queries.json` to run the labeled-set method (hit@5 / hit@10
|
|
|
275
277
|
- **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.
|
|
276
278
|
- **Full entries returned directly** — entries are already compact, so returning them whole is more verifiable and one round-trip cheaper.
|
|
277
279
|
- **`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`.
|
|
278
|
-
- **TypeScript enhancement is optional
|
|
279
|
-
- **Subagent sessions are out of scope**
|
|
280
|
+
- **TypeScript enhancement is optional and lazy** — it runs in the background, never blocks indexing, and falls back to the regex scanner; its queue is bounded and deduplicated by content, 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.
|
|
280
281
|
|
|
281
282
|
## Development (for contributors)
|
|
282
283
|
|
|
@@ -284,7 +285,7 @@ These commands are for **maintaining the plugin code** — regular users do not
|
|
|
284
285
|
|
|
285
286
|
```bash
|
|
286
287
|
npm install
|
|
287
|
-
npm test #
|
|
288
|
+
npm test # 930 tests
|
|
288
289
|
npm run eval:injection # synthetic pool P/R: precision 0.93 / recall 1.00, + a 3-scenario hint-only group
|
|
289
290
|
npm run eval:injection -- --store .dsh-project-memory/insights.json # replay on YOUR store; control group is a hard gate
|
|
290
291
|
npm run selfcheck:triggers # which entries can still push, which declarations are dead (reads your local store)
|
package/README.zh-CN.md
CHANGED
|
@@ -48,14 +48,14 @@ dsh plugin --profile web add @yolk_vat-y/dsh-project-memory -w
|
|
|
48
48
|
|
|
49
49
|
以下工具由 **agent 自动调用**,无需用户手动输入。在对话中直接说自然语言即可——例如「给这个项目建个索引」或「auth 模块是干嘛的」,或者正常开发即可——agent 会自动调用对应工具。默认开启「读到即索引」:模型读哪个文件,就顺便索引哪个文件,记忆在你干活的过程中自然积累。`watch_repo` 让显式监听的根目录在后台保持新鲜;`index_repo` 强制对项目做一次全量回填(未变更文件自动跳过)。
|
|
50
50
|
|
|
51
|
-
在 git 工作树里,语料就是 `git ls-files --cached --others --exclude-standard` 的清单——已跟踪文件,加上未被忽略的未跟踪文件——因此 `.gitignore
|
|
51
|
+
在 git 工作树里,语料就是 `git ls-files --cached --others --exclude-standard` 的清单——已跟踪文件,加上未被忽略的未跟踪文件——因此 `.gitignore`(含嵌套规则)决定什么会被记忆。隐藏路径(任一段以 `.` 开头)与内置忽略名单(`node_modules`、`dist` …)在两种模式下都跳过;不是 git 工作树的目录退回普通遍历,套用同一套过滤。「读到即索引」只在文件**首次入库**时套用同一判据;已入库的条目后续只刷新内容、不再问 git——等 `.gitignore` 开始排除它时,由 `index_repo` / `watch_repo` 的扫描清理摘掉。显式 `index_doc` 不受 `.gitignore` 与隐藏路径过滤限制,但仍服从 `roots.exclude`、可读性与体积上限,且只要文件还在,它的条目就能活过后续扫描清理。
|
|
52
52
|
|
|
53
53
|
| 工具 | 用途 |
|
|
54
54
|
|---|---|
|
|
55
55
|
| `index_doc file_path` | 索引单个文档(PDF/MD/txt):分块、确定性摘要,带 `路径:行号` 入库。未变更文件自动跳过。 |
|
|
56
56
|
| `index_repo root` | 索引整个项目:文档生成确定性摘要,代码文件生成零 token 符号表。增量更新,store 跟随文件清单:已删除、被忽略或移走的文件会被清理(显式 `index_doc` 的条目只要文件还在就保留);文档与符号交叉链接。根目录不存在或在排除名单上时,会在写入任何内容前拒绝。 |
|
|
57
57
|
| `watch_repo root` | 启用自动刷新:后台轮询检测新增/变更文件,仅重抽这些文件。监听根会记在该项目的 store 里,在该项目下启动 dsh 时恢复监听;不存在或在排除名单上的根目录会被拒绝,已消失的根目录会被丢弃而不是被重新创建。 |
|
|
58
|
-
| `memory_stats root` |
|
|
58
|
+
| `memory_stats root` | 查看记忆库内容:总量、最近索引时间,以及按时间排序的逐文件清单。后台索引失败(watch / 懒索引,按根记账、最多 50 条)也会一并报出,让「文件一直没进语料」可见。 |
|
|
59
59
|
| `query_memory query` | 对文档、符号、经验与 insight 执行排序检索,可选 LLM 查询扩展。`type` 选择层(`all` / `doc` / `symbol` / `experience` / `insight` / `task`)。返回带相对分数、引用或 insight id、以及文档→符号链接的结果。 |
|
|
60
60
|
| `list_tasks` | 列出本项目任务记录(含归档,带标记)。新会话/续接前先调用。 |
|
|
61
61
|
| `select_task` | 将会话绑定到某任务(此后 todo 清单与读文件同步进该任务)。按 `taskId` 精确绑定,或按 `title` 完全匹配(多个同名返回候选;无则新建)。带 title 可改名;自动解归档。 |
|
|
@@ -137,7 +137,7 @@ TaskPanel (Container)
|
|
|
137
137
|
| `tasklist.enabled` / `tasklist.syncHostOnAdopt` | true / true | TaskBridge 自动同步(由会话 todo 清单与文件读取沉淀任务实体);绑定任务时把其步骤推给宿主任务清单,使 dsh 镜像该任务 |
|
|
138
138
|
| `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` 表示**关闭**那条带 |
|
|
139
139
|
| `reflection.enabled` | false | LLM 反思,**只写任务级草稿**(触发于任务切走 / 归档)。`cooldownMs` `1800000`、`maxLessonsPerReflect` `3`、`maxDecisionsPerReflect` `2` |
|
|
140
|
-
| `autoContext.enabled` | true | 静默注入包装(常驻任务卡 + 受门槛约束的条目);宿主无法解析会话 cwd 时完全透传。`maxTokens` `400
|
|
140
|
+
| `autoContext.enabled` | true | 静默注入包装(常驻任务卡 + 受门槛约束的条目);宿主无法解析会话 cwd 时完全透传。`maxTokens` `400`(单轮;`0` = 完全关闭注入)、`editedMax` `3`(任务卡显示的最近"编辑中"文件数)、`signalMinRatio` `0.5`(提示至少达到该层最高分的一半)、`skipEchoSelfTodo` `true`、`budgetLog` `off`、`reinjectItemsAfter` `0`(同一条 insight 重复注入的冷却步数)、`rootNotice` `true` |
|
|
141
141
|
| `autoContext.gateCooldownSteps` | 2 | **准入旋钮**:两次*条目*注入之间至少隔几步(常驻任务卡不受限——它是状态快照)。这是"别频繁注入"的主旋钮 |
|
|
142
142
|
| `autoContext.maxItemsPerSession` / `autoContext.maxItemCharsPerSession` | 60 / 24000 | **runaway 保险丝,不是节流阀** —— 按条数与字符计的每会话硬上限:一旦触顶,本会话余下部分条目通道持续沉默 |
|
|
143
143
|
| `autoContext.hintMinCoverage` | 0.45 | 提示通道的**绝对**下限:条目覆盖了查询多少 IDF 加权信息量。只用相对阈值分不出"有信号"和"矮子里拔将军" |
|
|
@@ -167,7 +167,7 @@ TaskPanel (Container)
|
|
|
167
167
|
|
|
168
168
|
注意 `deny` 只决定这个目录自己能不能当根:父目录已经是根时,`deny` 的子目录仍会被父根索引——要连文件一起排除请用 `exclude`(或 `.gitignore`,git 仓库里的扫描本来就尊重它)。显式 `index_doc` 也服从 `exclude`,被排除的文件会返回 `Not indexed`。
|
|
169
169
|
|
|
170
|
-
优先级是 `exclude` > `deny` > `allow` > 内置名单。`allowUnsafeRoots: true` 只放开内置名单,`deny` / `exclude` 仍然优先。生效面是同一套判定:显式工具调用、懒索引、watch、会话审计、任务桥。被当前策略拒绝的根会在下次启动时从 `watch.json` 摘掉。配置写在 `- id: project-memory` 的 `config:`
|
|
170
|
+
优先级是 `exclude` > `deny` > `allow` > 内置名单。`allowUnsafeRoots: true` 只放开内置名单,`deny` / `exclude` 仍然优先。生效面是同一套判定:显式工具调用、懒索引、watch、会话审计、任务桥。被当前策略拒绝的根会在下次启动时从 `watch.json` 摘掉。配置写在 `- id: project-memory` 的 `config:` 下。
|
|
171
171
|
|
|
172
172
|
**扫描上限。** 单次扫描最多 `maxScanFiles` 个文件(20000)、`maxScanDepth` 层目录(12)。被截断时,`index_repo` 的结果里会说明,watcher 每个根记一行,且不会删除没扫到的条目。**读不到的目录**(如 `EACCES`)同样算一次截断扫描并在结果里点名:读失败不等于被删除。
|
|
173
173
|
|
|
@@ -201,6 +201,8 @@ store 建在被索引的目录树里,并且**自我忽略**:自己目录内
|
|
|
201
201
|
|
|
202
202
|
只需列出要改的键,其余键回落到插件默认值。用 `dsh --profile web --dump-config` 验证生效。
|
|
203
203
|
|
|
204
|
+
**web profile 上有三个键同时提供可视化设置。** 位置是**插件 → 项目记忆 → 详情页 → 常用设置**(`plugins.bundle.config`,key 为包名):`autoIndexOnFirstUse`、`watchInterval`(秒)、`llmQueryExpansion`。保存走宿主的 `settings` 接口——卡片始终是上面那份 profile 配置的投影,不另写文件。`watchInterval` 与 `llmQueryExpansion` 立即生效(轮询定时器当场重排,扩展开关每次查询时读取);`autoIndexOnFirstUse` 是一次性启动动作,卡片上写明"下次启动生效"。其余旋钮——`memoryDir`、`roots.*`、扫描上限、insight / 反思 / 自动注入——**刻意留在 profile**:它们要么一改就换数据位置,要么需要理解上下文,三行卡片承载不了;后台监视也**不给开关**(关掉只会让记忆越来越旧)。宿主不提供 `slots` / `configForms` / `locale` 时卡片零注册,并打一条点名原因的告警,而不是静默消失。这三个键在插件装配期解析,所以**升级后需要重启一次 dsh**(在卡片里保存则无需重启)。
|
|
205
|
+
|
|
204
206
|
不想改 profile 文件、只想临时试一次,可用 CLI 补丁覆盖:
|
|
205
207
|
|
|
206
208
|
```bash
|
|
@@ -213,7 +215,7 @@ dsh web --patch ./config.yml
|
|
|
213
215
|
|
|
214
216
|
### 真实项目实测(2026-10-13)
|
|
215
217
|
|
|
216
|
-
四个语料、同一台 Linux 机器(Node 24.19),每个跑两遍、引用**第二次(页缓存已热)**的数据。「冷索引」= 完整索引一轮(walk + 哈希 + 抽取 + 落盘);「查询」= 线上同一套 scorer 跑 100 条采样;「单文件重索引」= watch /
|
|
218
|
+
四个语料、同一台 Linux 机器(Node 24.19),每个跑两遍、引用**第二次(页缓存已热)**的数据。「冷索引」= 完整索引一轮(walk + 哈希 + 抽取 + 落盘);「查询」= 线上同一套 scorer 跑 100 条采样;「单文件重索引」= watch 的重索引内核(读 + 抽取 + 落盘),不含懒索引的根解析 / `.gitignore` 固定开销。
|
|
217
219
|
|
|
218
220
|
| 语料 | 文件数 / 条目数 | 冷索引 | 冷加载 | 查询 p50 / p95 | 单文件重索引 | 存储内容 / 落盘 | 加载后堆 |
|
|
219
221
|
|------|----------------|--------|--------|----------------|--------------|----------------|----------|
|
|
@@ -222,7 +224,7 @@ dsh web --patch ./config.yml
|
|
|
222
224
|
| 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 |
|
|
223
225
|
| 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 |
|
|
224
226
|
|
|
225
|
-
**扩展形状。** 重索引一个变更文件的成本是 O(文件)、不是 O(语料)——上面每个语料都在 0.3–7.2 ms。冷加载(≈22 µs/文件)、查询(最大语料 ≈0.5 µs/条目)与常驻堆(查询一次后 ≈1.5 KB
|
|
227
|
+
**扩展形状。** 重索引一个变更文件的成本是 O(文件)、不是 O(语料)——上面每个语料都在 0.3–7.2 ms。冷加载(≈22 µs/文件)、查询(最大语料 ≈0.5 µs/条目)与常驻堆(查询一次后 ≈1.5 KB/条目)随索引规模线性增长,因此小型与中型项目都落在个位数毫秒。重复读一个已索引文件约 0.01 ms:一次 `stat` 加一次缓存命中的记录查询就结束,不读盘、不哈希、也不起 `git check-ignore`。
|
|
226
228
|
|
|
227
229
|
> `read+hash` 受操作系统页缓存影响——12,634 文件时冷缓存 2.3 s、热缓存 0.27 s——上表引用的是热缓存那一遍。
|
|
228
230
|
|
|
@@ -273,8 +275,7 @@ node scripts/bench.mjs /你的/项目路径 [--json] [--samples 100] [--no-pdf]
|
|
|
273
275
|
- **面向模型的记忆:agent 自己写,不把人放进回路** — 记忆的消费方是 agent,而 agent 通常是无头的,只在有人点卡片时才升级的记忆等于永远不会升级。`draft` 是「来源标记 + 佐证门槛」而不是审批队列。
|
|
274
276
|
- **直接返回完整条目** — 条目本就紧凑,完整返回更可核验,也少一轮往返。
|
|
275
277
|
- **`forget` 按关键词激进;精确请用 ID** — 经验笔记低风险、高量,陈旧噪音比误删更伤。精确删用 `query_memory` 输出里的 ID。
|
|
276
|
-
- **TS
|
|
277
|
-
- **子代理会话暂不纳入(以后可能做)**
|
|
278
|
+
- **TS 增强可选、异步** — 后台执行、不阻塞索引,没有 TS 时回退正则扫描;队列有上界并按内容去重,被丢弃的文件会在报告里给出条数。**默认 lib 不加载**:依赖全局类型(`Promise`/`Array`/DOM)的推导会退化成 `any`/`unknown`,显式标注的类型不受影响。
|
|
278
279
|
|
|
279
280
|
## 开发(面向贡献者)
|
|
280
281
|
|
|
@@ -282,7 +283,7 @@ node scripts/bench.mjs /你的/项目路径 [--json] [--samples 100] [--no-pdf]
|
|
|
282
283
|
|
|
283
284
|
```bash
|
|
284
285
|
npm install
|
|
285
|
-
npm test #
|
|
286
|
+
npm test # 930 项测试
|
|
286
287
|
npm run eval:injection # 合成池 P/R:精确率 0.93 / 召回率 1.00,另有 3 个 hint-only 场景
|
|
287
288
|
npm run eval:injection -- --store .dsh-project-memory/insights.json # 用你自己的 store 重放;对照组是硬闸门
|
|
288
289
|
npm run selfcheck:triggers # 哪些条目还推得动、哪些声明是死的(读你本地的 store)
|