dsh-verbatim 0.0.0-stage → 0.1.1

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.
Files changed (114) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/LICENSE +21 -0
  3. package/README.en.md +168 -0
  4. package/README.md +167 -2
  5. package/bin/cli.mjs +59 -0
  6. package/bin/mcp-memory.mjs +303 -0
  7. package/client.js +9673 -0
  8. package/cordis.patch.yml +11 -0
  9. package/docs/ARCHITECTURE.md +35 -0
  10. package/docs/TOOLS.md +36 -0
  11. package/docs/banner.png +0 -0
  12. package/icon.svg +14 -0
  13. package/index.js +613 -0
  14. package/locale/en.json +7 -0
  15. package/locale/zh.json +7 -0
  16. package/package.json +94 -4
  17. package/src/config/_test-entry.js +11 -0
  18. package/src/config/exclude-range.js +481 -0
  19. package/src/config/exclude-range.test.js +412 -0
  20. package/src/config/global-config.js +257 -0
  21. package/src/config/package.json +8 -0
  22. package/src/config/session-config.js +415 -0
  23. package/src/config/session-config.test.js +375 -0
  24. package/src/derive/_test-entry.js +18 -0
  25. package/src/derive/beat.js +194 -0
  26. package/src/derive/beat.test.js +323 -0
  27. package/src/derive/fact.js +277 -0
  28. package/src/derive/fact.test.js +389 -0
  29. package/src/derive/gist.js +650 -0
  30. package/src/derive/gist.test.js +294 -0
  31. package/src/derive/package.json +8 -0
  32. package/src/derive/prompts.js +299 -0
  33. package/src/host/config-views.js +184 -0
  34. package/src/host/db-admin.js +766 -0
  35. package/src/host/dsh-llm.js +90 -0
  36. package/src/host/panel-api.js +1109 -0
  37. package/src/host/panel-http.js +322 -0
  38. package/src/host/panel-search.js +236 -0
  39. package/src/host/panel-session-store.js +411 -0
  40. package/src/host/probe.js +262 -0
  41. package/src/host/rebuild.js +601 -0
  42. package/src/host/scene-ops.js +611 -0
  43. package/src/host/session-lock.js +37 -0
  44. package/src/host/session-sync.js +91 -0
  45. package/src/index.js +102 -0
  46. package/src/ingest/cli.js +502 -0
  47. package/src/ingest/export.js +967 -0
  48. package/src/ingest/export.test.js +1162 -0
  49. package/src/ingest/package.json +4 -0
  50. package/src/ingest/reader.js +417 -0
  51. package/src/model/embedding.js +337 -0
  52. package/src/model/llm.js +274 -0
  53. package/src/model/mock.js +193 -0
  54. package/src/model/model.test.js +420 -0
  55. package/src/model/package.json +8 -0
  56. package/src/model/rerank.js +164 -0
  57. package/src/package.json +4 -0
  58. package/src/pipeline.js +868 -0
  59. package/src/scene/link.js +200 -0
  60. package/src/scene/package.json +4 -0
  61. package/src/scene/split.js +675 -0
  62. package/src/scene/split.test.js +575 -0
  63. package/src/scene/verify.js +214 -0
  64. package/src/search/_fixtures.js +107 -0
  65. package/src/search/_test-entry.js +19 -0
  66. package/src/search/bench.js +269 -0
  67. package/src/search/cache-concurrent.test.js +84 -0
  68. package/src/search/cache-contract.test.js +102 -0
  69. package/src/search/chunk.js +228 -0
  70. package/src/search/chunk.test.js +128 -0
  71. package/src/search/dedupe.js +271 -0
  72. package/src/search/indexer.js +889 -0
  73. package/src/search/indexer.test.js +481 -0
  74. package/src/search/note-rank.js +244 -0
  75. package/src/search/package.json +9 -0
  76. package/src/search/regression.test.js +387 -0
  77. package/src/search/rrf.js +365 -0
  78. package/src/search/rrf.test.js +374 -0
  79. package/src/search/scene-fallback.js +12 -0
  80. package/src/search/session-shape.js +88 -0
  81. package/src/search/session-shape.test.js +144 -0
  82. package/src/search/thread.js +300 -0
  83. package/src/search/thread.test.js +116 -0
  84. package/src/search/vector-fallback.js +509 -0
  85. package/src/search/vector-hydrate.js +309 -0
  86. package/src/search/vector-math.js +125 -0
  87. package/src/search/vector-store.js +1065 -0
  88. package/src/search/vector-store.test.js +375 -0
  89. package/src/search/window.js +310 -0
  90. package/src/search/window.test.js +308 -0
  91. package/src/store/db.js +803 -0
  92. package/src/store/note-session-migration.test.js +157 -0
  93. package/src/store/package.json +5 -0
  94. package/src/store/repo-extras-meta.js +430 -0
  95. package/src/store/repo-extras-search.js +580 -0
  96. package/src/store/repo.js +1024 -0
  97. package/src/store/repo.test.js +1081 -0
  98. package/src/store/schema.sql +348 -0
  99. package/src/tools/format.js +594 -0
  100. package/src/tools/index.js +341 -0
  101. package/src/tools/isolation.test.js +405 -0
  102. package/src/tools/memory-forget.js +501 -0
  103. package/src/tools/memory-remember.js +353 -0
  104. package/src/tools/memory-search.js +721 -0
  105. package/src/tools/merge-search.test.js +444 -0
  106. package/src/tools/package.json +5 -0
  107. package/src/tools/refusal-hint.test.js +51 -0
  108. package/src/tools/remember-forget.test.js +461 -0
  109. package/src/tools/scope.js +107 -0
  110. package/src/tools/search-render.js +502 -0
  111. package/src/tools/time-route.js +752 -0
  112. package/src/tools/tools.test.js +968 -0
  113. package/src/tools/vector-gate.test.js +460 -0
  114. package/src/tools/vector-route.js +655 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,35 @@
1
+ # Changelog
2
+
3
+ All notable changes to `dsh-verbatim` are documented here.
4
+
5
+ ## [0.1.1] - 2026-11-25
6
+
7
+ ### Performance & Indexing
8
+ - **CJK 2-Char FTS5 Bigram Index (`msg_cjk2_fts`)**: Added schema v17 FTS5 bigram index for 2-character CJK queries so short Chinese searches avoid full-table `LIKE` scans.
9
+ - **Bounded LRU Streaming Fallback Vectors**: Added per-kind lazy loading and LRU eviction backed by SQLite streaming (`vec_fallback_*`) when `sqlite-vec` is unavailable, preventing unbounded memory growth.
10
+ - **Chunked SQLite Batch Operations**: Chunked `media.byMsgIds` and `window.clearForScenes` to stay safely within `SQLITE_MAX_VARIABLE_NUMBER`.
11
+
12
+ ### Reliability, Security & Bug Fixes
13
+ - **Read-Only SQL Timeout Fuse & RPC Hygiene**: Added execution time bounds to `dbQuery`, fixed `readRequestBody` stream error handling, and suppressed JSON-RPC replies to MCP notifications.
14
+ - **Ingest & Store Hardening**: Fixed SQLite handle leaks on error in `importSession` / `rebuildDerived`, stack overflow in `Math.min(...times)` on large sessions, rewind speaker counters, and atomic note restore + audit logging.
15
+ - **Indexer, Search & Scene Consistency**: Fixed `mergeScene` cascade-deleting windows before vector cleanup, `mergeNotes` stale note vectors, `refineSessionGists` excluded message filtering, chunker infinite-loop/oversized-chunk guards, `AbortError` retry short-circuiting, and `02-29` leap-day parsing.
16
+ - **Client UI & Build**: Enabled project-wide `checkJs` + client scope checks, fixed task polling concurrency races, unmount/sequence guards in `DshLlmPicker` and timeline/search loaders, expanded scene refresh after edits, and reliable blob downloads.
17
+ - **Configurable `aboutLabels`**: Added customizable `me` / `him` / `us` note ownership labels.
18
+
19
+ ## [0.1.0] - 2026-11-23
20
+
21
+ ### Companion-First Memory & Retrieval
22
+ - **Verbatim SQLite Storage**: Persists complete conversation history (including compacted turns) in local SQLite (`node:sqlite`, `FTS5`, optional `sqlite-vec` with cosine fallback) with strict per-session isolation and physical deletion on rewind.
23
+ - **Companion Dual-Granularity Pipeline**: Defaults new and rebuilt sessions to `exchange` → `thread` segmentation with 30-minute settle windows, scene merge/split locking, and timeline cluster folding.
24
+ - **Hybrid Search + Optional Rerank**: Parallel keyword (`FTS5` trigram + 2-char CJK `LIKE`) and multi-granularity vector KNN fused via RRF (`k = 60`), with candidate pool expansion (`perRoute >= 24`) when `/rerank` is enabled.
25
+ - **Media Attachments & Captions**: Extracts attachment metadata (`sha256:` / local path / URL), resolves host attachment paths and user captions directly inside `memory_search` results, and supports inline preview & caption editing in the Library view.
26
+
27
+ ### Agent Tools & Privacy Hardening
28
+ - **3-Tool Minimalist Surface**: Exposes `memory_search`, `memory_remember`, and `memory_forget` returning clean, compact plain-text dialogue blocks (`Speaker: text`).
29
+ - **Strict Exclusion Boundary**: Removed `includeExcluded` from the Agent tool schema and hints; excluded ranges and muted messages are only accessible to the user in the host UI.
30
+ - **Trash Discoverability**: `memory_search(scope='note')` surfaces recoverable trash note IDs so `memory_forget(restore: true)` is reachable.
31
+ - **Live Tool Hot-Reload**: Toggling `tools` in the panel immediately re-registers tools on active host agents without restarting.
32
+
33
+ ### Material 3 Companion UI
34
+ - **6 Sidebar Tabs**: Overview (Hero sanctuary card, tonal KPI tiles, 38px circular Recall Readiness gauge, collapsible diagnostics), Search, Timeline (chat-bubble styling with hover-reveal actions), Notes (color-coded by ownership, duplicate merge, 30-day trash), Verify, and Library (session overview with 2-step delete, data browser with media caption editor, read-only SQL).
35
+ - **5 Global Settings Tabs**: General & Retrieval (with 3-step interactive Setup Guide), Sessions, Embedding (local service auto-probe + dimension detection), Rerank, and optional Summary LLM.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dsh-verbatim contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.en.md ADDED
@@ -0,0 +1,168 @@
1
+ <p align="center">
2
+ <img src="docs/banner.png" alt="dsh-verbatim — Companion-first verbatim long-term memory plugin for DeepSeek Harness" width="100%">
3
+ </p>
4
+
5
+ <h1 align="center">dsh-verbatim</h1>
6
+
7
+ <p align="center">Every word kept intact · Companion-first verbatim long-term memory plugin for DeepSeek Harness.</p>
8
+
9
+ <p align="center">
10
+ <a href="https://www.npmjs.com/package/dsh-verbatim"><img src="https://img.shields.io/npm/v/dsh-verbatim?label=npm&color=CB3837" alt="npm version"></a>
11
+ <a href="https://www.npmjs.com/package/dsh-verbatim"><img src="https://img.shields.io/npm/dt/dsh-verbatim?label=downloads&color=2563EB" alt="npm downloads"></a>
12
+ <img src="https://img.shields.io/badge/node-%3E%3D24-339933?logo=node.js&logoColor=white" alt="Node >=24">
13
+ <img src="https://img.shields.io/badge/storage-node%3Asqlite%20%2B%20FTS5-003B57?logo=sqlite&logoColor=white" alt="node:sqlite + FTS5">
14
+ <a href="https://github.com/saya-ch/dsh-verbatim/actions/workflows/ci.yml"><img src="https://github.com/saya-ch/dsh-verbatim/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
15
+ <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-0F172A" alt="MIT License"></a>
16
+ </p>
17
+
18
+ <p align="center">
19
+ <a href="#what-it-does">What It Does</a> ·
20
+ <a href="#retrieval-example">Example</a> ·
21
+ <a href="#quick-start">Quick Start</a> ·
22
+ <a href="#how-it-works">How It Works</a> ·
23
+ <a href="#privacy--security">Privacy &amp; Security</a> ·
24
+ <a href="#compatibility">Compatibility</a> ·
25
+ <a href="#uninstall">Uninstall</a> ·
26
+ <a href="#documentation">Docs</a> ·
27
+ <a href="#development">Development</a> ·
28
+ <a href="README.md">简体中文</a>
29
+ </p>
30
+
31
+ > `dsh-verbatim` is a community plugin for DeepSeek Harness (also providing a CLI and stdio MCP Server) built for AI companion conversations, without modifying DeepSeek Harness source files.
32
+ >
33
+ > **Current version: 0.1.1**. Powered by Node.js `>=24` built-in `node:sqlite` and FTS5. All verbatim messages, derived indexes, and settings stay local in `$DSH_HOME/verbatim/`.
34
+
35
+ `dsh-verbatim` keeps every conversation message word for word in a local SQLite database, automatically organizes exchanges and micro-topics, and brings back full original context through hybrid keyword + vector retrieval and optional reranking even after context compaction.
36
+
37
+ ## What It Does
38
+
39
+ - **Verbatim source of truth, rebuildable derived layers**: The `msg` table is append-only (rewinds/deletes physically remove the message and its vectors); past conversations remain intact after context compaction.
40
+ - **Companion-first dual granularity (`exchange` → `thread`)**: Automatically segments natural chats into single exchanges and micro-topics, with 30-minute idle scene boundaries, scene merge/split locking, and timeline cluster folding.
41
+ - **Always-hybrid retrieval + optional reranking**: Runs FTS5 trigram / 2-character CJK bigram (`msg_cjk2_fts`) in parallel with multi-granularity vector search (`vec_msg`, `vec_chunk`, `vec_scene`, `vec_note`), fused via RRF with optional `/rerank` rescoring (and automatic fallback).
42
+ - **Image attachments & captions**: Records image attachments and resolved local paths, supports inline preview and caption editing in the sidebar panel, and returns both paths and captions to the model.
43
+ - **Strict session isolation & privacy boundaries**: Settings and data are isolated per `session_id`; user-configured private exclude time ranges and per-message "do not recall" flags are completely invisible to Agent tools and cannot be bypassed via parameters.
44
+ - **Material 3 companion UI**: Includes **6 sidebar views** (Overview, Search, Timeline, Notes, Audit, Library) and **5 global settings tabs** (3-step setup guide, local model probing, session data management, customizable note `aboutLabels`, and timeout-guarded read-only SQL diagnostics).
45
+
46
+ ## Retrieval Example
47
+
48
+ When the model calls `memory_search`, it receives plain-text results with exact time spans, compact dialogue lines, and hit markers (synthetic example below):
49
+
50
+ ```text
51
+ 「周末去公园」— 3 处
52
+
53
+ 11-16 14:10–14:25 · 6轮 · 92字 · 命中 2 处
54
+ 我:周六天气不错,去公园散步吗?
55
+ 他:好呀,顺便去湖边坐坐 kw+vec ←
56
+ 我:记得带上相机和防晒。 kw+vec ←
57
+ 他:"/path/to/dsh_home/attachments/v1/objects/00/0000...png" [图片]
58
+ [图片备注:公园湖边的长椅]
59
+ ```
60
+
61
+ ## Quick Start
62
+
63
+ Make sure **Node.js `>=24`** is installed (uses built-in `node:sqlite`, no native C++ build toolchain required), then mount the plugin in DeepSeek Harness.
64
+
65
+ ### 1. Install & Mount
66
+
67
+ #### Official DSH Desktop
68
+
69
+ Install and enable `dsh-verbatim` from the **Plugins** page in DSH Desktop. Desktop profiles are managed by the app and do not use `--profile web` commands.
70
+
71
+ #### DSH Web
72
+
73
+ If `dsh` is installed globally, run:
74
+
75
+ ```powershell
76
+ dsh plugin --profile web add dsh-verbatim@latest
77
+ dsh --profile web
78
+ ```
79
+
80
+ <details>
81
+ <summary>Mount from source (git clone / pnpm dsh) or run CLI / MCP Server standalone</summary>
82
+
83
+ ```powershell
84
+ git clone https://github.com/saya-ch/dsh-verbatim.git
85
+ cd dsh-verbatim
86
+ npm install --no-audit --no-fund
87
+ ```
88
+
89
+ In a DeepSeek Harness source checkout, you can run `pnpm dsh plugin --profile web add dsh-verbatim@latest` or point directly to this repository (which includes [cordis.patch.yml](cordis.patch.yml) and [package.json](package.json) manifests).
90
+
91
+ You can also use the CLI or run a standard stdio MCP Server standalone (either via global bin or from source):
92
+
93
+ ```powershell
94
+ # CLI tool (ingest, search, stats, verify)
95
+ dsh-verbatim --help # or node bin/cli.mjs --help
96
+
97
+ # Start stdio MCP Server
98
+ dsh-verbatim-mcp # or node bin/mcp-memory.mjs
99
+ ```
100
+
101
+ </details>
102
+
103
+ The database, global config, and per-session switches are stored under `$DSH_HOME/verbatim/` (defaults to `~/.dsh/verbatim/` if `DSH_HOME` is unset):
104
+
105
+ - `memory.db`: SQLite verbatim store and derived indexes
106
+ - `config.json`: Global embedding, rerank, and LLM settings
107
+ - `sessions/<session-id>.json`: Per-session toggles and private exclude ranges
108
+
109
+ ### 2. Three Steps to Enable
110
+
111
+ 1. Open **Settings → Verbatim Memory → Embedding**, choose a local service (Ollama / LM Studio auto-detection supported) or enter an OpenAI-compatible `/v1/embeddings` endpoint and test connectivity.
112
+ 2. *(Optional)* Enable `/rerank` under **Rerank** to improve ranking accuracy on long histories.
113
+ 3. Open the **Verbatim Memory** sidebar panel in any conversation and turn on **Remember new messages** and **Allow recall** (takes effect immediately without restarting).
114
+
115
+ ## How It Works
116
+
117
+ ```mermaid
118
+ flowchart LR
119
+ Chat["DSH Messages & Attachments"] -->|"Verbatim ingest"| Msg["msg table"]
120
+ Msg -->|"Companion split"| Gran["exchange / thread"]
121
+ Gran -->|"Hybrid index"| Index["FTS5 + Multi-granularity Vectors"]
122
+ Index -->|"RRF + Optional Rerank"| Tools["Agent Tools (search / remember / forget)"]
123
+ Tools -->|"Privacy-filtered"| Model["Active Chat Model"]
124
+ ```
125
+
126
+ The plugin registers the ingest pipeline, search service, and 3 Agent tools (`memory_search`, `memory_remember`, `memory_forget`; verbatim conversation rows remain strictly append-only/read-only to all tools) on the Host side, and injects the 6-view sidebar panel and 5-tab settings page on the Client side—without modifying DeepSeek Harness core files. See [Architecture](docs/ARCHITECTURE.md) for schema and lock details.
127
+
128
+ ## Privacy & Security
129
+
130
+ - **Local-first storage**: Except for the embedding (`/v1/embeddings`), rerank (`/rerank`), or optional summary LLM endpoints you configure, all memories, captions, and settings stay local in `$DSH_HOME/verbatim/`.
131
+ - **Hard privacy boundaries**: Excluded time ranges and per-message exclusions are filtered directly at the storage/retrieval layer and cannot be bypassed by Agent tool parameters.
132
+ - **Physical rewind/delete**: Rewinding or deleting messages in DSH physically removes the corresponding rows and vectors from `memory.db`.
133
+ - **Read-only SQL diagnostics**: The SQL diagnostic tab in Settings only allows read-only queries.
134
+
135
+ ## Compatibility
136
+
137
+ - **Node.js**: Requires `>=24` (relies on built-in `node:sqlite`).
138
+ - **`sqlite-vec`**: Listed in `optionalDependencies`. If unavailable on the host platform, vector search automatically falls back to a bounded LRU + streaming SQLite cosine similarity index with equivalent recall results and bounded memory usage.
139
+
140
+ ## Uninstall
141
+
142
+ Removing `dsh-verbatim` from your DeepSeek Harness plugin configuration **does not delete** `$DSH_HOME/verbatim/`. Re-mounting the plugin restores access to your existing memories.
143
+
144
+ To remove all local data permanently, back up `memory.db` or `sessions/*.json` if needed, remove the plugin, and then delete `$DSH_HOME/verbatim/`.
145
+
146
+ ## Documentation
147
+
148
+ - [Architecture](docs/ARCHITECTURE.md): Storage schema, companion dual-granularity splitting, hybrid retrieval, and write locks
149
+ - [Agent Tools & Privacy](docs/TOOLS.md): Complete schemas, output formats, and privacy isolation guarantees
150
+ - [Changelog](CHANGELOG.md): Release notes
151
+ - [Contributing](CONTRIBUTING.md): Development workflow, verification commands, and synthetic test data policy
152
+
153
+ ## Development
154
+
155
+ ```powershell
156
+ # Rebuild client.js from src/client/*.js
157
+ npm run build:client
158
+
159
+ # Bundle consistency, TypeScript check, and syntax checks
160
+ npm run check
161
+
162
+ # Run full unit and frontend rendering test suite
163
+ npm test
164
+ ```
165
+
166
+ ## License
167
+
168
+ [MIT](LICENSE)
package/README.md CHANGED
@@ -1,3 +1,168 @@
1
- # Temporary Holding Version
1
+ <p align="center">
2
+ <img src="docs/banner.png" alt="dsh-verbatim — 为 DeepSeek Harness 打造的陪伴向长期逐字记忆插件" width="100%">
3
+ </p>
2
4
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
5
+ <h1 align="center">dsh-verbatim</h1>
6
+
7
+ <p align="center">Every word kept intact · 为 DeepSeek Harness 打造的陪伴向长期逐字记忆插件。</p>
8
+
9
+ <p align="center">
10
+ <a href="https://www.npmjs.com/package/dsh-verbatim"><img src="https://img.shields.io/npm/v/dsh-verbatim?label=npm&color=CB3837" alt="npm 版本"></a>
11
+ <a href="https://www.npmjs.com/package/dsh-verbatim"><img src="https://img.shields.io/npm/dt/dsh-verbatim?label=downloads&color=2563EB" alt="npm 总下载量"></a>
12
+ <img src="https://img.shields.io/badge/node-%3E%3D24-339933?logo=node.js&logoColor=white" alt="Node >=24">
13
+ <img src="https://img.shields.io/badge/storage-node%3Asqlite%20%2B%20FTS5-003B57?logo=sqlite&logoColor=white" alt="node:sqlite + FTS5">
14
+ <a href="https://github.com/saya-ch/dsh-verbatim/actions/workflows/ci.yml"><img src="https://github.com/saya-ch/dsh-verbatim/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
15
+ <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-0F172A" alt="MIT License"></a>
16
+ </p>
17
+
18
+ <p align="center">
19
+ <a href="#能做什么">能做什么</a> ·
20
+ <a href="#检索返回示例">检索示例</a> ·
21
+ <a href="#快速开始">快速开始</a> ·
22
+ <a href="#工作原理">工作原理</a> ·
23
+ <a href="#隐私与安全">隐私与安全</a> ·
24
+ <a href="#兼容性">兼容性</a> ·
25
+ <a href="#卸载">卸载</a> ·
26
+ <a href="#文档导航">文档</a> ·
27
+ <a href="#开发与验证">开发</a> ·
28
+ <a href="README.en.md">English</a>
29
+ </p>
30
+
31
+ > `dsh-verbatim` 是面向 AI 陪伴场景的 DeepSeek Harness 社区插件(同时提供 CLI 与 MCP Server),不修改 DeepSeek Harness 源码。
32
+ >
33
+ > **当前版本:0.1.1**。基于 Node.js `>=24` 内置 `node:sqlite` 与 FTS5,所有对话原文、索引与设置均保存在本机 `$DSH_HOME/verbatim/`,无外部记忆托管服务。
34
+
35
+ `dsh-verbatim` 把每一次对话的原话一字不改地留存在本地 SQLite 中,按问答与微话题自动组织结构;当上下文被压缩或时间跨度拉长后,模型仍可通过关键词、向量语义与可选精排找回完整原话与当时语境。
36
+
37
+ ## 能做什么
38
+
39
+ - **原文一字不改,派生层随时可重建**:`msg` 表作为单一事实来源只增不改(撤回消息会物理删除原文与对应向量);即使经历多次上下文压缩,过往对话依然完整留存。
40
+ - **陪伴优先的双粒度组织(`exchange` → `thread`)**:面向日常闲聊自动切分单轮问答与微话题,配合 30 分钟静默成场、场景合并/拆分锁定与时间线聚簇折叠,召回连贯而不碎片。
41
+ - **始终混合检索 + 可选精排**:并行执行 FTS5 trigram / 2 字中文 bigram(`msg_cjk2_fts`)与多粒度向量检索(`vec_msg` / `vec_chunk` / `vec_scene` / `vec_note`),经 RRF 融合排序,并支持 `/rerank` 二次精排(异常自动回退)。
42
+ - **图片附件与备注回想**:入库记录对话中的图片附件与本地解析路径,支持在侧栏内联预览与编辑图片备注(`caption`),检索结果会一并把图片路径与备注交还给模型。
43
+ - **严格会话隔离与隐私边界**:开关与数据按 `session_id` 独立隔离;用户设置的「私密排除时段」与单句「暂不回想」对 Agent 工具完全不可见,杜绝任何参数绕过。
44
+ - **Material 3 陪伴向前端**:提供 **6 个侧栏视图**(概览、搜索、时间轴、笔记、核对、库)与 **5 个全局设置页**(含 3 步快速上手引导、本地模型服务探测、会话数据管理、自定义称呼标签 `aboutLabels` 与带超时熔断的只读 SQL 诊断)。
45
+
46
+ ## 检索返回示例
47
+
48
+ 模型调用 `memory_search` 时,会收到带精确时间区间、紧凑对话行与命中标记的纯文本结果(以下为虚构示例):
49
+
50
+ ```text
51
+ 「周末去公园」— 3 处
52
+
53
+ 11-16 14:10–14:25 · 6轮 · 92字 · 命中 2 处
54
+ 我:周六天气不错,去公园散步吗?
55
+ 他:好呀,顺便去湖边坐坐 kw+vec ←
56
+ 我:记得带上相机和防晒。 kw+vec ←
57
+ 他:"/path/to/dsh_home/attachments/v1/objects/00/0000...png" [图片]
58
+ [图片备注:公园湖边的长椅]
59
+ ```
60
+
61
+ ## 快速开始
62
+
63
+ 先确认本机已安装 **Node.js `>=24`**(使用内置 `node:sqlite`,无需额外原生编译工具),再将插件挂载到 DeepSeek Harness。
64
+
65
+ ### 1. 安装与挂载
66
+
67
+ #### 官方 DSH Desktop
68
+
69
+ 在应用的 **插件** 页面中安装并启用 `dsh-verbatim`。Desktop 的 profile 由应用管理,不适用下面的 `--profile web` 命令。
70
+
71
+ #### DSH Web
72
+
73
+ 已安装 `dsh` 命令时,在终端执行:
74
+
75
+ ```powershell
76
+ dsh plugin --profile web add dsh-verbatim@latest
77
+ dsh --profile web
78
+ ```
79
+
80
+ <details>
81
+ <summary>从源码挂载(git clone / pnpm dsh)或独立使用 CLI / MCP Server</summary>
82
+
83
+ ```powershell
84
+ git clone https://github.com/saya-ch/dsh-verbatim.git
85
+ cd dsh-verbatim
86
+ npm install --no-audit --no-fund
87
+ ```
88
+
89
+ 在 DeepSeek Harness 源码目录中可使用 `pnpm dsh plugin --profile web add dsh-verbatim@latest` 或指向本仓库目录挂载(仓库已包含 [cordis.patch.yml](cordis.patch.yml) 与 [package.json](package.json) 声明)。
90
+
91
+ 如果希望脱离插件界面单独使用 CLI 或作为标准 MCP Server(stdio)挂载到其他客户端,全局安装或源码下均可直接运行:
92
+
93
+ ```powershell
94
+ # CLI 工具(导入、检索、统计、校验)
95
+ dsh-verbatim --help # 或 node bin/cli.mjs --help
96
+
97
+ # 启动标准 MCP Server(stdio)
98
+ dsh-verbatim-mcp # 或 node bin/mcp-memory.mjs
99
+ ```
100
+
101
+ </details>
102
+
103
+ 记忆库、全局配置与按会话隔离的开关均保存在 `$DSH_HOME/verbatim/`(未设置 `DSH_HOME` 时默认为 `~/.dsh/verbatim/`):
104
+
105
+ - `memory.db`:SQLite 逐字记忆库与派生索引
106
+ - `config.json`:全局模型与服务配置
107
+ - `sessions/<session-id>.json`:每个会话独立的开关与私密排除规则
108
+
109
+ ### 2. 三步启用陪伴记忆
110
+
111
+ 1. 打开 **设置 → 逐字记忆 → 向量模型**,选择本地服务(支持 Ollama / LM Studio 自动扫描)或填写兼容 OpenAI `/v1/embeddings` 的远程接口并测试连通性。
112
+ 2. (可选)在 **精排模型** 中开启 `/rerank` 精排,提升长记忆场景下的排序准确度。
113
+ 3. 打开任意对话右侧栏的 **逐字记忆** 面板,开启 **记住新对话** 与 **让 TA 随时回想**(热更新立即生效,无需重启)。
114
+
115
+ ## 工作原理
116
+
117
+ ```mermaid
118
+ flowchart LR
119
+ Chat["DSH 对话与附件"] -->|"逐字留存"| Msg["msg 原文表"]
120
+ Msg -->|"陪伴切分"| Gran["exchange / thread"]
121
+ Gran -->|"混合索引"| Index["FTS5 + 多粒度向量"]
122
+ Index -->|"RRF + 可选 Rerank"| Tools["Agent 工具 (search / remember / forget)"]
123
+ Tools -->|"隐私过滤后回传"| Model["当前对话模型"]
124
+ ```
125
+
126
+ 插件通过 Host 服务挂载入库管线、检索服务与 3 个 Agent 工具(`memory_search`、`memory_remember`、`memory_forget`,其中对话原文对所有工具保持只读不可删改),并通过 Client 入口注入侧栏 6 视图与设置页 5 个标签页;不改写 DeepSeek Harness 安装目录中的源码。详细表结构与写入锁设计见 [系统架构说明](docs/ARCHITECTURE.md)。
127
+
128
+ ## 隐私与安全
129
+
130
+ - **数据不出本机**:除你主动配置的向量 `/v1/embeddings` 与精排 `/rerank` 模型接口外,记忆库、附件备注与配置全部留在本地 `$DSH_HOME/verbatim/`。
131
+ - **硬隐私边界**:用户在面板中设置的「私密排除时段」与单句「暂不回想」在检索与工具查询层直接过滤,对 Agent 完全不可见,无法通过工具参数绕过。
132
+ - **物理撤回**:用户在 DSH 中撤回或删除消息时,对应原文与向量索引会从本地库中物理移除。
133
+ - **只读诊断**:设置页提供的 SQL 诊断入口仅允许执行只读查询,不会修改记忆原文。
134
+
135
+ ## 兼容性
136
+
137
+ - **Node.js**:要求 `>=24`(依赖内置 `node:sqlite`)。
138
+ - **`sqlite-vec`**:作为 `optionalDependencies` 安装;若当前平台未加载成功,系统会自动降级为带 LRU 上界流式扫描的 SQLite 余弦检索,功能与召回结果等价,同时控制大库内存占用。
139
+
140
+ ## 卸载
141
+
142
+ 仅从 DeepSeek Harness 插件配置中移除 `dsh-verbatim` **不会删除** `$DSH_HOME/verbatim/` 中的记忆库与配置,重新挂载即可继续使用。
143
+
144
+ 如需彻底清理本机数据,请先备份需要的 `memory.db` 或 `sessions/*.json`,移除插件后再手动删除 `$DSH_HOME/verbatim/` 目录。
145
+
146
+ ## 文档导航
147
+
148
+ - [系统架构说明](docs/ARCHITECTURE.md):存储表结构、陪伴双粒度切分、混合检索与写入锁设计
149
+ - [Agent 工具与隐私边界](docs/TOOLS.md):3 个工具的完整 Schema、返回格式与隐私隔离机制
150
+ - [更新日志](CHANGELOG.md):版本变更记录
151
+ - [贡献指南](CONTRIBUTING.md):本地开发、校验流程与脱敏测试规范
152
+
153
+ ## 开发与验证
154
+
155
+ ```powershell
156
+ # 从 src/client/*.js 重新打包前端产物 client.js
157
+ npm run build:client
158
+
159
+ # 一致性检查、TypeScript 类型检查与语法校验
160
+ npm run check
161
+
162
+ # 运行完整单元测试与前端渲染测试
163
+ npm test
164
+ ```
165
+
166
+ ## License
167
+
168
+ [MIT](LICENSE)
package/bin/cli.mjs ADDED
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env node
2
+ // @ts-check
3
+ /**
4
+ * 命令行入口。日常只做三件事:导入、重建、查库概况。
5
+ *
6
+ * dsh-verbatim import <session.v4.jsonl.zstd> 导入一个会话
7
+ * dsh-verbatim rebuild 从原文重建派生层
8
+ * dsh-verbatim stat 看一眼库里有什么
9
+ */
10
+ import path from 'node:path';
11
+ import fs from 'node:fs';
12
+ import { importSession, rebuildDerived, openPipelineDb } from '../src/pipeline.js';
13
+ import { createRepo, createExtras } from '../src/store/repo.js';
14
+ import { defaultDbPath } from '../src/store/db.js';
15
+
16
+ const [cmd, ...rest] = process.argv.slice(2);
17
+ const dbPath = process.env.VERBATIM_DB || defaultDbPath();
18
+
19
+ function usage() {
20
+ console.log(`dsh-verbatim 0.1.0 —— 一字不改的长期记忆
21
+
22
+ 用法:
23
+ dsh-verbatim import <会话日志> 导入一个会话(幂等,可重复跑)
24
+ dsh-verbatim rebuild 从原文重建场景/索引
25
+ dsh-verbatim stat 看一眼库里有什么
26
+
27
+ 环境变量:
28
+ DSH_HOME 记忆库根目录(默认 ~/.dsh)
29
+ VERBATIM_DB 直接指定库文件路径
30
+ `);
31
+ }
32
+
33
+ if (!cmd || cmd === '-h' || cmd === '--help') {
34
+ usage();
35
+ process.exit(0);
36
+ }
37
+
38
+ if (cmd === 'import') {
39
+ const file = rest[0];
40
+ if (!file || !fs.existsSync(file)) {
41
+ console.error(`找不到会话日志:${file ?? '(未提供)'}`);
42
+ process.exit(1);
43
+ }
44
+ await importSession(path.resolve(file), { dbPath });
45
+ } else if (cmd === 'rebuild') {
46
+ await rebuildDerived({ dbPath });
47
+ } else if (cmd === 'stat') {
48
+ const handle = openPipelineDb({ dbPath, logger: { warn() {} } });
49
+ const extras = createExtras(handle);
50
+ const s = extras.stats.get();
51
+ console.log(`库:${dbPath}`);
52
+ console.log(`消息 ${s.msgs} 条 / ${s.chars} 字 / 场景 ${s.scenes} 场`);
53
+ if (s.excludedMsgs) console.log(`按日期排除 ${s.excludedMsgs} 条 / ${s.excludedChars} 字(入库但检索不到)`);
54
+ handle.close();
55
+ } else {
56
+ console.error(`未知命令:${cmd}`);
57
+ usage();
58
+ process.exit(1);
59
+ }