@yolk_vat-y/dsh-project-memory 0.6.11 → 0.7.0
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 +104 -120
- package/README.md +14 -105
- package/README.zh-CN.md +14 -105
- package/client/client.js +228 -95
- package/client/client.js.map +1 -1
- package/package.json +2 -2
- package/scripts/file-peak.mjs +1 -1
- package/scripts/tool-schema-size.mjs +1 -1
- package/skills/project-memory/SKILL.md +1 -1
- package/skills/project-memory/scripts/pm-digest.mjs +20 -6
- package/src/audit.js +10 -2
- package/src/auto-inject.js +124 -38
- package/src/client/MemoryView.tsx +119 -40
- package/src/client/TaskCommandNode.tsx +6 -4
- package/src/client/TaskComponents.tsx +13 -16
- package/src/client/TaskPanel.tsx +41 -15
- package/src/client/client.ts +4 -7
- package/src/client/paging.js +1 -14
- package/src/client/settings-card.tsx +9 -0
- package/src/client/task-data-store.ts +57 -7
- package/src/client/task-hooks.ts +0 -2
- package/src/client/task-scope.js +16 -1
- package/src/client/task-ui-store.ts +1 -1
- package/src/commands/insight-actions.js +91 -94
- package/src/commands/task-actions.js +7 -5
- package/src/commands/tasks.js +34 -10
- package/src/doc-index.js +3 -1
- package/src/enhancer.js +0 -12
- package/src/index-failures.js +1 -1
- package/src/index-pipeline.js +11 -2
- package/src/index.js +60 -14
- package/src/inject-visible.js +282 -0
- package/src/insight-store.js +133 -68
- package/src/lazy.js +29 -23
- package/src/llm-route.js +1 -1
- package/src/llm.js +1 -8
- package/src/ops.js +18 -5
- package/src/parsers/pdfjs-parser.js +3 -33
- package/src/project-memory-service.js +195 -0
- package/src/project-profile.js +0 -4
- package/src/setup/taskbridge.js +38 -6
- package/src/store.js +639 -147
- package/src/symbols.js +2 -4
- package/src/tools/context.js +14 -0
- package/src/tools/forget.js +7 -17
- package/src/tools/index-doc.js +62 -21
- package/src/tools/index-repo.js +17 -15
- package/src/tools/lesson-tools.js +10 -13
- package/src/tools/output.js +33 -0
- package/src/tools/query-memory.js +7 -12
- package/src/tools/remember.js +8 -18
- package/src/tools/stats.js +4 -9
- package/src/tools/task-tools.js +23 -22
- package/src/tools/watch-repo.js +16 -15
- package/src/util/flush.js +1 -1
- package/src/util/fs.js +135 -20
- package/src/util/insight-fields.js +22 -0
- package/src/util/message-source.js +20 -0
- package/src/util/relative-time.js +24 -0
- package/src/util/search.js +0 -1
- package/src/util/task-view.js +8 -15
- package/src/util/value.js +16 -0
- package/src/vector-index.js +2 -2
- package/src/watch.js +25 -8
- package/client/client.d.ts +0 -27
- package/client/client.d.ts.map +0 -1
- package/client/style.css +0 -395
package/README.md
CHANGED
|
@@ -50,14 +50,12 @@ 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. 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
|
-
|
|
55
53
|
| Tool | Purpose |
|
|
56
54
|
|---|---|
|
|
57
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. |
|
|
58
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 (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
57
|
| `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
|
-
| `
|
|
58
|
+
| `pm_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
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. |
|
|
62
60
|
| `list_tasks` | List task records for the project (archived marked). Call first in a new session before continuing work. |
|
|
63
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. |
|
|
@@ -87,15 +85,13 @@ Project- and task-scope memory is stored per project and follows the codebase: c
|
|
|
87
85
|
|
|
88
86
|
```
|
|
89
87
|
.dsh-project-memory/
|
|
90
|
-
format.json layout marker
|
|
91
|
-
shards/
|
|
88
|
+
format.json layout marker
|
|
89
|
+
shards/ bucket-*.json, ≈32KB each — a write rewrites only the affected bucket(s)
|
|
92
90
|
watch.json watched roots
|
|
93
91
|
tasks.json TaskBridge task entities (cross-session)
|
|
94
92
|
binding.json current session ↔ task binding
|
|
95
93
|
insights.json project-scope memory (lessons / decisions / procedures / experience notes) — one entity
|
|
96
94
|
vectors.json optional semantic index (only when the vector layer runs)
|
|
97
|
-
injection-audit.jsonl one line per real injection (what / why / dropped / budget)
|
|
98
|
-
admission-shadow.jsonl one line per step, all scored candidates + features (offline replay)
|
|
99
95
|
```
|
|
100
96
|
|
|
101
97
|
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.
|
|
@@ -103,21 +99,7 @@ Global-scope entries are not stored under the project: they live in `insight.glo
|
|
|
103
99
|
- **Incremental** — a content hash per file; only changed files are re-extracted.
|
|
104
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.
|
|
105
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.
|
|
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.
|
|
107
|
-
|
|
108
|
-
## Architecture (Task Panel)
|
|
109
|
-
|
|
110
|
-
```
|
|
111
|
-
TaskPanel (Container)
|
|
112
|
-
├── task-data-store (server data, cross-tab sync via BroadcastChannel)
|
|
113
|
-
├── task-ui-store (local UI state, localStorage)
|
|
114
|
-
├── task-hooks (useTaskDrag, useTaskEdit)
|
|
115
|
-
└── TaskComponents (MiniBar, TaskCard — presentational only)
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
The workflow panel is collapsible, adapts to dsh and theme plugin styles, and offers four card styles.
|
|
119
102
|
|
|
120
|
-

|
|
121
103
|
|
|
122
104
|
## Configuration
|
|
123
105
|
|
|
@@ -125,31 +107,20 @@ The workflow panel is collapsible, adapts to dsh and theme plugin styles, and of
|
|
|
125
107
|
|---|---|---|
|
|
126
108
|
| `memoryDir` | `.dsh-project-memory` | store directory inside each indexed root. Must stay a relative path inside the root: `.`, `..`, any `..` segment or an absolute path falls back to the default with one warning (otherwise the store lands outside the root, or on the root itself and self-ignores the whole repository) |
|
|
127
109
|
| `chunkChars` / `maxChunksPerFile` | 3000 / 40 | max chars per document chunk, max chunks per document |
|
|
128
|
-
| `maxFileSizeMb` | 10 | skip documents (incl. PDF) and code files larger than this (MB); entries of an already-indexed file that later grows past the cap are dropped on the next scan / watch pass
|
|
110
|
+
| `maxFileSizeMb` | 10 | skip documents (incl. PDF) and code files larger than this (MB); entries of an already-indexed file that later grows past the cap are dropped on the next scan / watch pass |
|
|
129
111
|
| `maxPdfPages` | 1000 | PDF page cap |
|
|
130
|
-
| `maxOutputChars` | 8000 | cap for `query_memory` result text (chars) |
|
|
131
112
|
| `lazyIndexing` | true | index files the moment the model reads them |
|
|
132
113
|
| `autoIndexOnFirstUse` | false | full scan of the current working directory on plugin load (opt-in) |
|
|
133
114
|
| `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) |
|
|
134
115
|
| `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 |
|
|
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 |
|
|
136
116
|
| `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 |
|
|
137
117
|
| `llmQueryExpansion` / `expansionCount` | false / 6 | expand queries via the LLM before search (off by default to save tokens); max variants |
|
|
138
118
|
| `tsPath` / `enableTypeScript` | (auto) / true | optional absolute path to a specific `typescript` install; set `enableTypeScript: false` to disable the type-aware layer entirely |
|
|
139
119
|
| `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
120
|
| `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
|
-
| `
|
|
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
|
-
| `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
|
-
| `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
|
-
| `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" |
|
|
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 |
|
|
121
|
+
| `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`, `rootNotice` `true` |
|
|
147
122
|
| `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 |
|
|
148
123
|
| `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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
153
124
|
|
|
154
125
|
### Toggling features
|
|
155
126
|
|
|
@@ -159,22 +130,6 @@ The two most relevant switches are `lazyIndexing` (index a file the moment the m
|
|
|
159
130
|
|
|
160
131
|
When the root comes from the working directory, the model gets one notice per session naming it and how to change it; mute with `autoContext.rootNotice: false`. Starting dsh in a container directory such as `~/workspace` therefore makes that directory the root, and memory spans everything beneath it up to the scan limit — start dsh inside the project for one store per project.
|
|
161
132
|
|
|
162
|
-
**Excluded directories.** By default, these are not used as a root, matched exactly (subdirectories are unaffected): the filesystem root, the home directory, temp directories — `os.tmpdir()` and the shared ones (`/tmp`, `/var/tmp`, `%TEMP%`, `%SystemRoot%\Temp`) — and system / package-manager prefixes (`/opt/homebrew` on POSIX; `%SystemRoot%`, `%ProgramFiles%`, `%ProgramData%` on Windows). A session in one of these runs without memory, with one line on stderr.
|
|
163
|
-
|
|
164
|
-
**Custom root lists.** The `roots` block overrides that decision. All three accept `~` / `~/...`; non-absolute entries are ignored with a one-time stderr warning (relative paths would resolve against the host cwd and are unpredictable); Windows is case-insensitive:
|
|
165
|
-
|
|
166
|
-
- `roots.allow` — allow a directory even when it is on the built-in list, matched exactly. The filesystem root is not eligible.
|
|
167
|
-
- `roots.deny` — this directory cannot be a root, matched exactly; its subdirectories can still be roots of their own.
|
|
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.
|
|
169
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
176
|
-
**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.
|
|
177
|
-
|
|
178
133
|
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.
|
|
179
134
|
|
|
180
135
|
Settings live in the plugin's config object. To change them, add an override entry to your profile's `cordis.patch.yml` — for the web profile that is `~/.dsh/profiles/web/cordis.patch.yml`:
|
|
@@ -196,14 +151,11 @@ Settings live in the plugin's config object. To change them, add an override ent
|
|
|
196
151
|
# deny: [/srv/shared] # exact: this directory cannot be a root; children still can
|
|
197
152
|
# exclude: [/srv/monorepo/archive] # subtree prefix: no file under it enters the index
|
|
198
153
|
# tsPath: /custom/path/to/typescript # optional: force specific TS install
|
|
199
|
-
# autoContext: # note: the next two keys live under autoContext, not at the top level
|
|
200
|
-
# budgetLog: once # debugging: log budget drops to stderr (default off = silent)
|
|
201
|
-
# reinjectItemsAfter: 20 # debugging: allow the same insight again after N steps (default 0 = once per session)
|
|
202
154
|
```
|
|
203
155
|
|
|
204
156
|
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
157
|
|
|
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".
|
|
158
|
+
**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". These three are resolved when the plugin is assembled, so **restart dsh once after upgrading** (saving the card itself needs no restart).
|
|
207
159
|
|
|
208
160
|
For a one-off run without editing the profile, pass the override as a CLI patch overlay:
|
|
209
161
|
|
|
@@ -215,35 +167,14 @@ where `config.yml` contains the same override block.
|
|
|
215
167
|
|
|
216
168
|
## Performance
|
|
217
169
|
|
|
218
|
-
|
|
219
|
-
|
|
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.
|
|
221
|
-
|
|
222
|
-
| Corpus | Files / entries | Cold index | Cold load | Query p50 / p95 | Re-index 1 file | Store content / on disk | Heap after load |
|
|
223
|
-
|--------|-----------------|-----------|-----------|-----------------|-----------------|------------------------|-----------------|
|
|
224
|
-
| 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 |
|
|
225
|
-
| 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 |
|
|
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 |
|
|
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 |
|
|
228
|
-
|
|
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`.
|
|
230
|
-
|
|
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.
|
|
232
|
-
|
|
233
|
-
### Synthetic Benchmark (Node 24.19, Linux)
|
|
170
|
+
Synthetic code corpus (≈4–5 symbols per file), Node 24 on Linux, second warm run:
|
|
234
171
|
|
|
235
|
-
|
|
|
236
|
-
|
|
237
|
-
|
|
|
238
|
-
|
|
|
239
|
-
| Hot lazy re-index (single file) | 5k files | p50 2.5 ms / max 6.7 ms |
|
|
240
|
-
| query_memory (cached) | 5k files / 20k entries | p50 2.9 ms / p95 6.0 ms |
|
|
241
|
-
| query_memory (cached) | 1k files / 4k entries | p50 0.5 ms / p95 1.1 ms |
|
|
242
|
-
| Full cold index | 10,000 files / 40k entries | 558 ms avg (p50 540) |
|
|
243
|
-
| Cold load | 10,000 files | 117 ms |
|
|
244
|
-
| Hot lazy re-index (single file) | 10k files | p50 5.5 ms / max 8.4 ms |
|
|
172
|
+
| Corpus | Full index | Cold load | Cached query p50 / p95 | Re-index 1 file |
|
|
173
|
+
|---|---:|---:|---:|---:|
|
|
174
|
+
| 5,000 files / 20k entries | 218 ms | 49 ms | 4.9 / 9.7 ms | 1.6 ms |
|
|
175
|
+
| 10,000 files / 40k entries | 417 ms | 103 ms | 11.4 / 21.9 ms | 3.0 ms |
|
|
245
176
|
|
|
246
|
-
|
|
177
|
+
Cold load is a fresh read of the store; the first query after a write rebuilds the IDF cache (79 ms at 20k entries, 153 ms at 40k), later queries hit it. Re-indexing a changed file is O(file), not O(corpus).
|
|
247
178
|
|
|
248
179
|
### Reproduce it on your own project
|
|
249
180
|
|
|
@@ -255,29 +186,7 @@ npm run bench -- /path/to/your/project
|
|
|
255
186
|
node scripts/bench.mjs /path/to/your/project [--json] [--samples 100] [--no-pdf] [--keep]
|
|
256
187
|
```
|
|
257
188
|
|
|
258
|
-
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.
|
|
259
|
-
|
|
260
|
-
```
|
|
261
|
-
cold index 246 ms (read+hash 8 ms · extract 222 ms · commit 14 ms) ← 2nd, warm-cache run
|
|
262
|
-
store 0.66 MB content · 1.52 MB on disk · 325 bytes/entry · cold load 8 ms
|
|
263
|
-
memory heap 6.3 MB after load → 6.9 MB after the first query (RSS 62 MB)
|
|
264
|
-
hot query p50 0.76 ms · p95 1.4 ms (2,142 entries)
|
|
265
|
-
re-index 1 file p50 0.3 ms
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
Pass `--queries your-queries.json` to run the labeled-set method (hit@5 / hit@10 / MRR) against your own project.
|
|
269
|
-
|
|
270
|
-
## Design tradeoffs
|
|
271
|
-
|
|
272
|
-
- **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.
|
|
273
|
-
- **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.
|
|
274
|
-
- **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.
|
|
275
|
-
- **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**).
|
|
276
|
-
- **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.
|
|
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.
|
|
278
|
-
- **Full entries returned directly** — entries are already compact, so returning them whole is more verifiable and one round-trip cheaper.
|
|
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`.
|
|
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.
|
|
189
|
+
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. Pass `--queries your-queries.json` to run the labeled-set method (hit@5 / hit@10 / MRR) against your own project.
|
|
281
190
|
|
|
282
191
|
## Development (for contributors)
|
|
283
192
|
|
|
@@ -285,7 +194,7 @@ These commands are for **maintaining the plugin code** — regular users do not
|
|
|
285
194
|
|
|
286
195
|
```bash
|
|
287
196
|
npm install
|
|
288
|
-
npm test #
|
|
197
|
+
npm test # 1092 tests
|
|
289
198
|
npm run eval:injection # synthetic pool P/R: precision 0.93 / recall 1.00, + a 3-scenario hint-only group
|
|
290
199
|
npm run eval:injection -- --store .dsh-project-memory/insights.json # replay on YOUR store; control group is a hard gate
|
|
291
200
|
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,12 @@ 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`(含嵌套规则)决定什么会被记忆。隐藏路径(任一段以 `.` 开头)与内置忽略名单(`node_modules`、`dist` …)在两种模式下都跳过;不是 git 工作树的目录退回普通遍历,套用同一套过滤。「读到即索引」只在文件**首次入库**时套用同一判据;已入库的条目后续只刷新内容、不再问 git——等 `.gitignore` 开始排除它时,由 `index_repo` / `watch_repo` 的扫描清理摘掉。显式 `index_doc` 不受 `.gitignore` 与隐藏路径过滤限制,但仍服从 `roots.exclude`、可读性与体积上限,且只要文件还在,它的条目就能活过后续扫描清理。
|
|
52
|
-
|
|
53
51
|
| 工具 | 用途 |
|
|
54
52
|
|---|---|
|
|
55
53
|
| `index_doc file_path` | 索引单个文档(PDF/MD/txt):分块、确定性摘要,带 `路径:行号` 入库。未变更文件自动跳过。 |
|
|
56
54
|
| `index_repo root` | 索引整个项目:文档生成确定性摘要,代码文件生成零 token 符号表。增量更新,store 跟随文件清单:已删除、被忽略或移走的文件会被清理(显式 `index_doc` 的条目只要文件还在就保留);文档与符号交叉链接。根目录不存在或在排除名单上时,会在写入任何内容前拒绝。 |
|
|
57
55
|
| `watch_repo root` | 启用自动刷新:后台轮询检测新增/变更文件,仅重抽这些文件。监听根会记在该项目的 store 里,在该项目下启动 dsh 时恢复监听;不存在或在排除名单上的根目录会被拒绝,已消失的根目录会被丢弃而不是被重新创建。 |
|
|
58
|
-
| `
|
|
56
|
+
| `pm_stats root` | 查看记忆库内容:总量、最近索引时间,以及按时间排序的逐文件清单。后台索引失败(watch / 懒索引,按根记账、最多 50 条)也会一并报出,让「文件一直没进语料」可见。 |
|
|
59
57
|
| `query_memory query` | 对文档、符号、经验与 insight 执行排序检索,可选 LLM 查询扩展。`type` 选择层(`all` / `doc` / `symbol` / `experience` / `insight` / `task`)。返回带相对分数、引用或 insight id、以及文档→符号链接的结果。 |
|
|
60
58
|
| `list_tasks` | 列出本项目任务记录(含归档,带标记)。新会话/续接前先调用。 |
|
|
61
59
|
| `select_task` | 将会话绑定到某任务(此后 todo 清单与读文件同步进该任务)。按 `taskId` 精确绑定,或按 `title` 完全匹配(多个同名返回候选;无则新建)。带 title 可改名;自动解归档。 |
|
|
@@ -85,15 +83,13 @@ dsh plugin --profile web add @yolk_vat-y/dsh-project-memory -w
|
|
|
85
83
|
|
|
86
84
|
```
|
|
87
85
|
.dsh-project-memory/
|
|
88
|
-
format.json
|
|
89
|
-
shards/
|
|
86
|
+
format.json 布局标记
|
|
87
|
+
shards/ bucket-*.json,每桶约 32KB —— 写入只重写受影响的那一个桶
|
|
90
88
|
watch.json 被监听根目录
|
|
91
89
|
tasks.json TaskBridge 任务实体(跨会话)
|
|
92
90
|
binding.json 当前会话 ↔ 任务绑定
|
|
93
91
|
insights.json 项目级记忆(教训 / 决策 / 流程 / 经验笔记)——唯一实体
|
|
94
92
|
vectors.json 可选语义索引(只在向量层启用时存在)
|
|
95
|
-
injection-audit.jsonl 每次真实注入一行(注入了什么 / 为什么 / 丢了什么 / 额度)
|
|
96
|
-
admission-shadow.jsonl 每步一行,全部被评分的候选 + 特征(离线重放)
|
|
97
93
|
```
|
|
98
94
|
|
|
99
95
|
global 级条目不放在项目里:它们在 `insight.globalFile`(默认 `~/.config/dsh-project-memory/global.json`),所有项目共享。
|
|
@@ -101,21 +97,7 @@ global 级条目不放在项目里:它们在 `insight.globalFile`(默认 `~/
|
|
|
101
97
|
- **增量** — 按文件内容哈希,仅重新抽取变更文件。
|
|
102
98
|
- **交叉链接** — `query_memory` 返回文档 chunk 时,按**当前**符号表解算它提到的符号,以 `references` 带出。文档先索引、符号后到也能链上。
|
|
103
99
|
- **查询扩展** — `llmQueryExpansion` 开启时,把查询改写为多个变体(同义词、中英、符号名猜测)再合并分数;关闭时查询完全不碰 LLM。索引本身不调用模型。
|
|
104
|
-
- **一致性** — 事实层跟随代码库(哈希重抽 / 删除即移除);经验条目与其他 insight 走同一套覆盖与 `forget` 机制。写入在跨进程的目录锁(`.write.lock`)内做一次短暂的读改写,因此两个 dsh 实例可以共用一个项目存储:分片按 `indexedAt` 收敛,拿不到锁的保存会延后重试,仍失败则在退出时同步 flush;默认静默(`DSH_PROJECT_MEMORY_DEBUG=1` 才打印一行诊断)。
|
|
105
|
-
|
|
106
|
-
## 架构(任务面板)
|
|
107
|
-
|
|
108
|
-
```
|
|
109
|
-
TaskPanel (Container)
|
|
110
|
-
├── task-data-store (服务端数据,跨标签页 BroadcastChannel 同步)
|
|
111
|
-
├── task-ui-store (本地 UI 状态,localStorage)
|
|
112
|
-
├── task-hooks (useTaskDrag, useTaskEdit)
|
|
113
|
-
└── TaskComponents (MiniBar, TaskCard — 纯展示组件)
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
工作流卡片可收起,自动适应 dsh 及主题插件风格,提供四种卡片风格切换。
|
|
117
100
|
|
|
118
|
-

|
|
119
101
|
|
|
120
102
|
## 配置
|
|
121
103
|
|
|
@@ -123,31 +105,20 @@ TaskPanel (Container)
|
|
|
123
105
|
|---|---|---|
|
|
124
106
|
| `memoryDir` | `.dsh-project-memory` | 每个被索引根目录内的存储目录。必须是根内的相对路径:`.`、`..`、含 `..` 段或绝对路径都会回落到默认目录并告警一次(否则 store 会落到根外,或落到根上并把整个仓库自我忽略掉) |
|
|
125
107
|
| `chunkChars` / `maxChunksPerFile` | 3000 / 40 | 每个文档块最大字符数、每文档最大块数 |
|
|
126
|
-
| `maxFileSizeMb` | 10 | 大于该值(MB)的文档(含 PDF)/代码文件跳过;已经索引过的文件后来涨过阈值,旧条目会在下一轮扫描 / watch
|
|
108
|
+
| `maxFileSizeMb` | 10 | 大于该值(MB)的文档(含 PDF)/代码文件跳过;已经索引过的文件后来涨过阈值,旧条目会在下一轮扫描 / watch 时摘掉 |
|
|
127
109
|
| `maxPdfPages` | 1000 | PDF 页数上限 |
|
|
128
|
-
| `maxOutputChars` | 8000 | `query_memory` 返回文本上限(字符) |
|
|
129
110
|
| `lazyIndexing` | true | 模型读取文件的瞬间即索引 |
|
|
130
111
|
| `autoIndexOnFirstUse` | false | 插件加载时对当前工作目录做全量扫描(可选) |
|
|
131
112
|
| `watch` / `watchInterval` | true / 30 | 后台刷新;基础轮询间隔(秒);回合进行中静默(5 分钟兜底,外部改动仍会自愈),回合结束立刻合并扫一次;空闲时逐步退避到最长 2 分钟,一有变化立即回到该值 |
|
|
132
113
|
| `maxScanFiles` / `maxScanDepth` | 20000 / 12 | 单次扫描的文件数与目录深度硬上限;被截断时会在报告里说明,且不会删除没扫到的条目。**无法取消**:`0` 或任何非法值都回落到默认值 |
|
|
133
|
-
| `allowUnsafeRoots` | false | 放开**内置**排除名单,所有根判定入口(含懒索引、会话审计、任务桥)都生效。它只作用于内置名单——`roots.deny` / `roots.exclude` 仍然优先;只想放开一个目录时用 `roots.allow` |
|
|
134
114
|
| `roots.allow` / `roots.deny` / `roots.exclude` | `[]` / `[]` / `[]` | 自定义根名单(机器/配置档级,CLI 与 web 通用)。`allow` / `deny` 精确匹配目录本身;`exclude` 按路径边界前缀匹配整棵子树(其中的文件一律不进索引)。优先级 `exclude` > `deny` > `allow` > 内置名单,文件系统根永远不能当根。支持 `~`/`~/...`;非绝对路径忽略并在 stderr 告警一次;Windows 下大小写不敏感 |
|
|
135
115
|
| `llmQueryExpansion` / `expansionCount` | false / 6 | 检索前用 LLM 扩展查询(默认关闭,节省 token);扩展变体上限 |
|
|
136
116
|
| `tsPath` / `enableTypeScript` | (自动) / true | 可选:强制指定 `typescript` 安装路径;`enableTypeScript: false` 彻底禁用类型感知层 |
|
|
137
117
|
| `tasklist.enabled` / `tasklist.syncHostOnAdopt` | true / true | TaskBridge 自动同步(由会话 todo 清单与文件读取沉淀任务实体);绑定任务时把其步骤推给宿主任务清单,使 dsh 镜像该任务 |
|
|
138
118
|
| `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
|
-
| `
|
|
140
|
-
| `autoContext.enabled` | true | 静默注入包装(常驻任务卡 + 受门槛约束的条目);宿主无法解析会话 cwd 时完全透传。`maxTokens` `400`(单轮;`0` = 完全关闭注入)、`editedMax` `3`(任务卡显示的最近"编辑中"文件数)、`signalMinRatio` `0.5`(提示至少达到该层最高分的一半)、`skipEchoSelfTodo` `true`、`budgetLog` `off`、`reinjectItemsAfter` `0`(同一条 insight 重复注入的冷却步数)、`rootNotice` `true` |
|
|
141
|
-
| `autoContext.gateCooldownSteps` | 2 | **准入旋钮**:两次*条目*注入之间至少隔几步(常驻任务卡不受限——它是状态快照)。这是"别频繁注入"的主旋钮 |
|
|
142
|
-
| `autoContext.maxItemsPerSession` / `autoContext.maxItemCharsPerSession` | 60 / 24000 | **runaway 保险丝,不是节流阀** —— 按条数与字符计的每会话硬上限:一旦触顶,本会话余下部分条目通道持续沉默 |
|
|
143
|
-
| `autoContext.hintMinCoverage` | 0.45 | 提示通道的**绝对**下限:条目覆盖了查询多少 IDF 加权信息量。只用相对阈值分不出"有信号"和"矮子里拔将军" |
|
|
144
|
-
| `autoContext.hintMinMatched` / `autoContext.hintMinSupport` | 2 / 0.15 | 提示还必须至少共享这么多个词;且查询里能在语料中找到对应的词占比不低于该值时,通道才出声——否则本轮整体沉默 |
|
|
119
|
+
| `autoContext.enabled` | true | 静默注入包装(常驻任务卡 + 受门槛约束的条目);宿主无法解析会话 cwd 时完全透传。`maxTokens` `400`(单轮;`0` = 完全关闭注入)、`editedMax` `3`(任务卡显示的最近"编辑中"文件数)、`signalMinRatio` `0.5`(提示至少达到该层最高分的一半)、`skipEchoSelfTodo` `true`、`rootNotice` `true` |
|
|
145
120
|
| `autoContext.vectorDir` | 未设 | **可选**语义层,只作用于经验/洞察两层;随 `leanvec`(optionalDependency)默认装上并启用(约 85 MB 表、约 +45 MB RSS)。填 `off` 强制纯词法;填路径或用 `DSH_LEANVEC_DIR` 可覆盖。只改排序、返回条数不变;启用时只有**没拿到余弦**的条目才继续按词法命中数筛 |
|
|
146
121
|
| `autoContext.vectorAlpha` | 0.5 | 这两层内 `(1-α)·词法分 + α·余弦` 的权重;`0` 只关闭重排(写入侧去重仍在),`1`(纯向量)实测更差 |
|
|
147
|
-
| `autoContext.vectorDedup` | true | 写入侧近重复检测(余弦 ≥0.9 自动覆盖、≥0.7 近邻提示)。与 `vectorAlpha` 独立;设 `false` 不影响召回排序 |
|
|
148
|
-
| `autoContext.vectorItemMin` / `autoContext.vectorSpeakMin` | 未设 | **实验性**:提示通道的绝对余弦地板(条目级)与通道级语义救援。未标定——不设即关闭,开启前先看 `src/auto-inject.js` 里的实测证据 |
|
|
149
|
-
| `autoContext.auditLog` | true | 每次**真实**注入往 `injection-audit.jsonl` 追加一行(注入了什么、为什么命中、丢了什么、会话额度);超过 `auditMaxBytes`(`262144`)轮转 `.1`。任何 IO 失败都静默 |
|
|
150
|
-
| `autoContext.shadowLog` / `autoContext.shadowMaxBytes` | true / 524288 | **每步**(含什么都没注入的步)往 `admission-shadow.jsonl` 追加一行:被评分候选及其特征,以及每条候选卡在哪一关 —— 它让"换个阈值会怎样"可以离线回答。只写盘、不进 prompt;超过上限轮转,只保留一代 `.1` |
|
|
151
122
|
|
|
152
123
|
### 功能开关
|
|
153
124
|
|
|
@@ -157,22 +128,6 @@ TaskPanel (Container)
|
|
|
157
128
|
|
|
158
129
|
根来自工作目录时,模型每个会话收到一条通告,说明根的位置与改法;`autoContext.rootNotice: false` 关闭。因此在 `~/workspace` 这类容器目录里启动 dsh,该目录就是根,记忆覆盖其下所有项目直到扫描上限——想一个项目一个 store,就在项目目录里启动。
|
|
159
130
|
|
|
160
|
-
**排除名单。** 以下目录不会作为根,精确匹配(子目录不受影响):文件系统根、家目录、临时目录(`os.tmpdir()` 与共享的 `/tmp`、`/var/tmp`、`%TEMP%`、`%SystemRoot%\Temp`),以及系统/包管理器前缀(POSIX 上的 `/opt/homebrew`,Windows 上的 `%SystemRoot%`、`%ProgramFiles%`、`%ProgramData%`)。这些目录下的会话默认不启用记忆,stderr 输出一行说明。
|
|
161
|
-
|
|
162
|
-
**自定义根名单。** 在同一份配置的 `roots` 下可以覆盖上述判定;三项都支持 `~`/`~/...`,非绝对路径会被忽略并在 stderr 告警一次(相对路径按宿主 cwd 解释,不可预测),Windows 下大小写不敏感:
|
|
163
|
-
|
|
164
|
-
- `roots.allow`:即使命中了内置名单也允许作根,精确匹配;文件系统根不在此列。
|
|
165
|
-
- `roots.deny`:这个目录不能当根,精确匹配;它的子目录仍可各自成根。
|
|
166
|
-
- `roots.exclude`:这棵子树里的文件一律不进索引,按路径边界前缀匹配(含子目录);也不能在这里推出新的根。父根的完整扫描会跳过它,并清理该子树里已索引的条目。
|
|
167
|
-
|
|
168
|
-
注意 `deny` 只决定这个目录自己能不能当根:父目录已经是根时,`deny` 的子目录仍会被父根索引——要连文件一起排除请用 `exclude`(或 `.gitignore`,git 仓库里的扫描本来就尊重它)。显式 `index_doc` 也服从 `exclude`,被排除的文件会返回 `Not indexed`。
|
|
169
|
-
|
|
170
|
-
优先级是 `exclude` > `deny` > `allow` > 内置名单。`allowUnsafeRoots: true` 只放开内置名单,`deny` / `exclude` 仍然优先。生效面是同一套判定:显式工具调用、懒索引、watch、会话审计、任务桥。被当前策略拒绝的根会在下次启动时从 `watch.json` 摘掉。配置写在 `- id: project-memory` 的 `config:` 下。
|
|
171
|
-
|
|
172
|
-
**扫描上限。** 单次扫描最多 `maxScanFiles` 个文件(20000)、`maxScanDepth` 层目录(12)。被截断时,`index_repo` 的结果里会说明,watcher 每个根记一行,且不会删除没扫到的条目。**读不到的目录**(如 `EACCES`)同样算一次截断扫描并在结果里点名:读失败不等于被删除。
|
|
173
|
-
|
|
174
|
-
**单文件内存预算。** `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)量级;调大它就按比例抬高这个上限。
|
|
175
|
-
|
|
176
131
|
store 建在被索引的目录树里,并且**自我忽略**:自己目录内的一条 `*` 规则让它不出现在 `git status` / `git add -A` 里,`git clean -fd` 也不会删它。确实想把记忆跟着仓库提交:`git add -f .dsh-project-memory`——已跟踪文件不受忽略规则影响。
|
|
177
132
|
|
|
178
133
|
配置存放在插件的 config 对象中。修改方式:在 profile 的 `cordis.patch.yml` 里加一条覆盖项——web profile 对应 `~/.dsh/profiles/web/cordis.patch.yml`:
|
|
@@ -194,14 +149,11 @@ store 建在被索引的目录树里,并且**自我忽略**:自己目录内
|
|
|
194
149
|
# deny: [/srv/shared] # 精确拒绝这个目录本身;子目录仍可成根
|
|
195
150
|
# exclude: [/srv/monorepo/archive] # 子树前缀:里面的文件一律不进索引
|
|
196
151
|
# tsPath: /custom/path/to/typescript # 可选:强制指定 TS 安装路径
|
|
197
|
-
# autoContext: # 注意:下面两个键在 autoContext 下,不是顶层
|
|
198
|
-
# budgetLog: once # 调试用:注入被预算挤掉时在 stderr 留痕(默认 off 静默)
|
|
199
|
-
# reinjectItemsAfter: 20 # 调试用:同一条 insight 隔 N 步才允许重发(默认 0 = 本会话只发一次)
|
|
200
152
|
```
|
|
201
153
|
|
|
202
154
|
只需列出要改的键,其余键回落到插件默认值。用 `dsh --profile web --dump-config` 验证生效。
|
|
203
155
|
|
|
204
|
-
**web profile 上有三个键同时提供可视化设置。** 位置是**插件 → 项目记忆 → 详情页 → 常用设置**(`plugins.bundle.config`,key 为包名):`autoIndexOnFirstUse`、`watchInterval`(秒)、`llmQueryExpansion`。保存走宿主的 `settings` 接口——卡片始终是上面那份 profile 配置的投影,不另写文件。`watchInterval` 与 `llmQueryExpansion` 立即生效(轮询定时器当场重排,扩展开关每次查询时读取);`autoIndexOnFirstUse` 是一次性启动动作,卡片上写明"下次启动生效"
|
|
156
|
+
**web profile 上有三个键同时提供可视化设置。** 位置是**插件 → 项目记忆 → 详情页 → 常用设置**(`plugins.bundle.config`,key 为包名):`autoIndexOnFirstUse`、`watchInterval`(秒)、`llmQueryExpansion`。保存走宿主的 `settings` 接口——卡片始终是上面那份 profile 配置的投影,不另写文件。`watchInterval` 与 `llmQueryExpansion` 立即生效(轮询定时器当场重排,扩展开关每次查询时读取);`autoIndexOnFirstUse` 是一次性启动动作,卡片上写明"下次启动生效"。这三个键在插件装配期解析,所以**升级后需要重启一次 dsh**(在卡片里保存则无需重启)。
|
|
205
157
|
|
|
206
158
|
不想改 profile 文件、只想临时试一次,可用 CLI 补丁覆盖:
|
|
207
159
|
|
|
@@ -213,35 +165,14 @@ dsh web --patch ./config.yml
|
|
|
213
165
|
|
|
214
166
|
## 性能
|
|
215
167
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
四个语料、同一台 Linux 机器(Node 24.19),每个跑两遍、引用**第二次(页缓存已热)**的数据。「冷索引」= 完整索引一轮(walk + 哈希 + 抽取 + 落盘);「查询」= 线上同一套 scorer 跑 100 条采样;「单文件重索引」= watch 的重索引内核(读 + 抽取 + 落盘),不含懒索引的根解析 / `.gitignore` 固定开销。
|
|
219
|
-
|
|
220
|
-
| 语料 | 文件数 / 条目数 | 冷索引 | 冷加载 | 查询 p50 / p95 | 单文件重索引 | 存储内容 / 落盘 | 加载后堆 |
|
|
221
|
-
|------|----------------|--------|--------|----------------|--------------|----------------|----------|
|
|
222
|
-
| 前端应用(纯代码) | 289 / 2,142 | 246 ms | 8 ms | 0.76 / 1.4 ms | 0.3 ms | 0.66 MB / 1.52 MB | 6.3 MB |
|
|
223
|
-
| 文档工作区(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 |
|
|
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 |
|
|
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 |
|
|
226
|
-
|
|
227
|
-
**扩展形状。** 重索引一个变更文件的成本是 O(文件)、不是 O(语料)——上面每个语料都在 0.3–7.2 ms。冷加载(≈22 µs/文件)、查询(最大语料 ≈0.5 µs/条目)与常驻堆(查询一次后 ≈1.5 KB/条目)随索引规模线性增长,因此小型与中型项目都落在个位数毫秒。重复读一个已索引文件约 0.01 ms:一次 `stat` 加一次缓存命中的记录查询就结束,不读盘、不哈希、也不起 `git check-ignore`。
|
|
228
|
-
|
|
229
|
-
> `read+hash` 受操作系统页缓存影响——12,634 文件时冷缓存 2.3 s、热缓存 0.27 s——上表引用的是热缓存那一遍。
|
|
230
|
-
|
|
231
|
-
### 合成基准测试(Node 24.19,Linux)
|
|
168
|
+
合成代码语料(每文件约 4–5 个符号),Node 24 / Linux,第二遍热缓存:
|
|
232
169
|
|
|
233
|
-
|
|
|
234
|
-
|
|
235
|
-
|
|
|
236
|
-
|
|
|
237
|
-
| 热路径懒记忆 | 单文件重记忆+落盘 | p50 2.5 ms / 最大 6.7 ms (5k) |
|
|
238
|
-
| query_memory (缓存命中) | 5k 文件 / 20k 条目 | p50 2.9 ms / p95 6.0 ms |
|
|
239
|
-
| query_memory (缓存命中) | 1k 文件 / 4k 条目 | p50 0.5 ms / p95 1.1 ms |
|
|
240
|
-
| 批量冷记忆构建 | 10,000 文件 / 40k 条目 | 558 ms 均值(p50 540)|
|
|
241
|
-
| 冷加载 | 10,000 文件 | 117 ms |
|
|
242
|
-
| 热路径懒记忆 | 单文件重记忆+落盘 | p50 5.5 ms / 最大 8.4 ms (10k) |
|
|
170
|
+
| 语料 | 全量索引 | 冷加载 | 缓存查询 p50 / p95 | 单文件重索引 |
|
|
171
|
+
|---|---:|---:|---:|---:|
|
|
172
|
+
| 5,000 文件 / 20k 条目 | 218 ms | 49 ms | 4.9 / 9.7 ms | 1.6 ms |
|
|
173
|
+
| 10,000 文件 / 40k 条目 | 417 ms | 103 ms | 11.4 / 21.9 ms | 3.0 ms |
|
|
243
174
|
|
|
244
|
-
|
|
175
|
+
冷加载是首次读盘;写入后的首次查询会重建 IDF 缓存(20k 条目 79 ms,40k 条目 153 ms),之后命中缓存。重索引一个变更文件是 O(文件),不是 O(语料)。
|
|
245
176
|
|
|
246
177
|
### 自己复现这些数字
|
|
247
178
|
|
|
@@ -253,29 +184,7 @@ npm run bench -- /你的/项目路径
|
|
|
253
184
|
node scripts/bench.mjs /你的/项目路径 [--json] [--samples 100] [--no-pdf] [--keep]
|
|
254
185
|
```
|
|
255
186
|
|
|
256
|
-
输出包含:冷索引(拆成 read+hash / extract / commit 三段)、冷加载、IDF 重建、冷查询与热查询延迟(100 条采样报 p50/p95/max
|
|
257
|
-
|
|
258
|
-
```
|
|
259
|
-
冷索引 246 ms (read+hash 8 ms · extract 222 ms · commit 14 ms)← 第二次、页缓存已热
|
|
260
|
-
存储 内容 0.66 MB · 落盘 1.52 MB · 325 bytes/条目 · 冷加载 8 ms
|
|
261
|
-
内存 加载后堆 6.3 MB → 首次查询后 6.9 MB(RSS 62 MB)
|
|
262
|
-
热查询 p50 0.76 ms · p95 1.4 ms (2,142 条目)
|
|
263
|
-
单文件重索引 p50 0.3 ms
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
带 `--queries 你的查询集.json` 可以在你自己的项目上跑标注集方法(hit@5 / hit@10 / MRR)。
|
|
267
|
-
|
|
268
|
-
## 设计取舍
|
|
269
|
-
|
|
270
|
-
- **短时文件锁,而不是嵌入式数据库** — 每次保存只在读改写期间持有排他的 `.write.lock`(解析在锁外完成),对方忙时最多**同步等 15s**(写路径的正确性靠等到锁,不靠后台重试);仍失败会登记进退出 flush,关 dsh / 卸载插件时再同步写一次。全程**默认不打扰用户**——记忆写入幂等、失败成本低;需要排查时设 `DSH_PROJECT_MEMORY_DEBUG=1` 才会打印一行。锁内容带 `pid` / `host` / `token`:同机持有者活着就绝不抢,release 校验所有权、不删别人的锁;崩溃残留的同机死锁按 pid 立即回收。两个 dsh 实例因此可以共用一个存储。没有 WAL、没有常驻进程、没有原生依赖。
|
|
271
|
-
- **Watch:事务外计算,事务内提交** — 不持锁解析,也不用 `fs.watch`:轮询 + mtime/内容哈希在网络盘、Docker 卷、WSL 上行为一致,没有 `fs.watch` 的重复触发/漏事件问题。
|
|
272
|
-
- **损坏分片隔离,不自动修复** — 解析失败的分片改名、只重索引该文件;不引入 WAL 或嵌入式数据库,那会带来原生依赖、锁竞争与它们自己的新故障模式。
|
|
273
|
-
- **向量只重排,不做排序主力** — 在**改写成不含原词**的查询集上,纯向量替换差于 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**)。
|
|
274
|
-
- **索引确定且不调用模型** — 索引期不调模型、查询期也不翻译:前者会让同一份文档两次索引结果不同,后者有一个硬失败模式(译错 = 零召回);规则 + 符号链接已经覆盖常见情况,且离线可用。
|
|
275
|
-
- **面向模型的记忆:agent 自己写,不把人放进回路** — 记忆的消费方是 agent,而 agent 通常是无头的,只在有人点卡片时才升级的记忆等于永远不会升级。`draft` 是「来源标记 + 佐证门槛」而不是审批队列。
|
|
276
|
-
- **直接返回完整条目** — 条目本就紧凑,完整返回更可核验,也少一轮往返。
|
|
277
|
-
- **`forget` 按关键词激进;精确请用 ID** — 经验笔记低风险、高量,陈旧噪音比误删更伤。精确删用 `query_memory` 输出里的 ID。
|
|
278
|
-
- **TS 增强可选、异步** — 后台执行、不阻塞索引,没有 TS 时回退正则扫描;队列有上界并按内容去重,被丢弃的文件会在报告里给出条数。**默认 lib 不加载**:依赖全局类型(`Promise`/`Array`/DOM)的推导会退化成 `any`/`unknown`,显式标注的类型不受影响。
|
|
187
|
+
输出包含:冷索引(拆成 read+hash / extract / commit 三段)、冷加载、IDF 重建、冷查询与热查询延迟(100 条采样报 p50/p95/max)、单文件热重索引、存储体积、常驻堆与单条目字节数。带 `--queries 你的查询集.json` 可以在你自己的项目上跑标注集方法(hit@5 / hit@10 / MRR)。
|
|
279
188
|
|
|
280
189
|
## 开发(面向贡献者)
|
|
281
190
|
|
|
@@ -283,7 +192,7 @@ node scripts/bench.mjs /你的/项目路径 [--json] [--samples 100] [--no-pdf]
|
|
|
283
192
|
|
|
284
193
|
```bash
|
|
285
194
|
npm install
|
|
286
|
-
npm test #
|
|
195
|
+
npm test # 1092 项测试
|
|
287
196
|
npm run eval:injection # 合成池 P/R:精确率 0.93 / 召回率 1.00,另有 3 个 hint-only 场景
|
|
288
197
|
npm run eval:injection -- --store .dsh-project-memory/insights.json # 用你自己的 store 重放;对照组是硬闸门
|
|
289
198
|
npm run selfcheck:triggers # 哪些条目还推得动、哪些声明是死的(读你本地的 store)
|