@imliulian/dsh-zeromem 0.0.0-stage → 0.2.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 +23 -0
- package/LICENSE +661 -0
- package/NOTICE +34 -0
- package/README.md +137 -2
- package/README.zh.md +139 -0
- package/assets/panel.js +2986 -0
- package/bin/dsh-zeromem.mjs +187 -0
- package/cordis.patch.yml +13 -0
- package/lib/config.mjs +469 -0
- package/lib/contracts.mjs +483 -0
- package/lib/expiry.mjs +359 -0
- package/lib/hooks.mjs +284 -0
- package/lib/index.mjs +120 -0
- package/lib/llm.mjs +827 -0
- package/lib/memory.mjs +824 -0
- package/lib/portability.mjs +819 -0
- package/lib/store.mjs +1248 -0
- package/lib/tools.mjs +527 -0
- package/lib/web.mjs +629 -0
- package/package.json +60 -4
package/NOTICE
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
ZeroMem (零忆) DSH Plugin — @imliulian/dsh-zeromem
|
|
2
|
+
Copyright (C) 2026 IMLIULIAN (B站IM榴莲 / ZeroZoneX)
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
|
5
|
+
it under the terms of the GNU Affero General Public License as published by
|
|
6
|
+
the Free Software Foundation, version 3 of the License (AGPL-3.0-only).
|
|
7
|
+
|
|
8
|
+
This program is distributed in the hope that it will be useful,
|
|
9
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11
|
+
GNU Affero General Public License (LICENSE) for more details.
|
|
12
|
+
|
|
13
|
+
This plugin is the official DeepSeek Harness integration for ZeroMem
|
|
14
|
+
(https://github.com/IMLIULIAN/zeromem), sharing its SQLite schema and
|
|
15
|
+
evidence-grounded extraction/admission protocol. Companion local model
|
|
16
|
+
weights Qwen3.5-4B-Memory-V2 (derived from Qwen/Qwen3.5-4B) are distributed
|
|
17
|
+
separately under Apache-2.0.
|
|
18
|
+
|
|
19
|
+
Schema Lineage & Third-Party Ecosystem Compatibility:
|
|
20
|
+
The structured fact-extraction and pre-write admission schema conventions shared
|
|
21
|
+
with ZeroMem (including bank/namespace partitioning, fact types
|
|
22
|
+
"world" / "experience" / "observation", temporal fields occurred_start /
|
|
23
|
+
occurred_end / mentioned_at, and where / entities metadata) are inspired by and
|
|
24
|
+
conceptually compatible with Vectorize Hindsight
|
|
25
|
+
(https://github.com/vectorize-io/hindsight, MIT License). This plugin's
|
|
26
|
+
node:sqlite dual-track FTS5 store, admission/guardrail pipeline, governance and
|
|
27
|
+
lossless restore layer, and DSH integration are independent clean-room
|
|
28
|
+
implementations containing no Hindsight source code.
|
|
29
|
+
|
|
30
|
+
Name Disambiguation:
|
|
31
|
+
ZeroMem (零忆) and @imliulian/dsh-zeromem (by IMLIULIAN / B站IM榴莲 / ZeroZoneX)
|
|
32
|
+
are independent open-source local memory projects and are not affiliated with,
|
|
33
|
+
derived from, or related to the academic paper "Zero-Mem: Zero-Token Memory
|
|
34
|
+
Operations for LLM Agents" (Yilin Xiao et al., arXiv:2607.29377, July 2026).
|
package/README.md
CHANGED
|
@@ -1,3 +1,138 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="right">
|
|
2
|
+
<a href="README.zh.md">简体中文</a> | <strong>English</strong>
|
|
3
|
+
</p>
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
# @imliulian/dsh-zeromem
|
|
6
|
+
|
|
7
|
+
> **ZeroMem (零忆) — Local, Evidence-Grounded Memory System for DeepSeek Harness (DSH)** · AGPL-3.0
|
|
8
|
+
> Author: **IMLIULIAN (B站IM榴莲)** · ZeroZoneX
|
|
9
|
+
|
|
10
|
+
`@imliulian/dsh-zeromem` brings a **self-contained, single-file local memory engine** directly into DeepSeek Harness — no cloud vector database, no Python runtime, no native C++ compilation (`node-gyp` / `better-sqlite3`), and no MCP subprocess overhead.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Why ZeroMem (Core Memory System)
|
|
15
|
+
|
|
16
|
+
1. **Pure Local Single-File Engine (`<1ms` Recall, Zero Native Builds)**
|
|
17
|
+
- Built directly on Node's built-in `node:sqlite` (`Node >= 22.19` / `Node 24`) with **dual-track CJK 2-gram + English FTS5** indexing over both extracted facts and original evidence segments.
|
|
18
|
+
- Zero third-party runtime dependencies and zero `postinstall` build scripts — installs cleanly under `pnpm >= 10`.
|
|
19
|
+
- **100% Fail-Open**: even if Ollama or your cloud API is offline, DSH startup and chat are never blocked and local FTS5 search remains available.
|
|
20
|
+
|
|
21
|
+
2. **Evidence-Grounded Extraction + Pre-Write Admission Verification**
|
|
22
|
+
- Uses a two-stage pipeline (**short-window chunking → structured extraction → 1-round source-grounded admission check → deterministic guard**) tuned for the open-source 4B specialist model **[Qwen3.5-4B-Memory-V2](https://huggingface.co/IMLIULIAN/qwen3.5-4b-memory-v2)** (runs 100% locally via Ollama at $0 cloud cost).
|
|
23
|
+
- Every stored fact remains **hard-bound to original evidence segments** (`evidence_ids`), eliminating black-box drift and allowing instant verification against the source text.
|
|
24
|
+
- **Automatic Pre-Send Credential Redaction**: common secrets (`sk-...`, `ghp_...`, `AKIA...`, `Bearer ...`, etc.) are masked to `[REDACTED]` *before* extraction or storage — including when using external APIs.
|
|
25
|
+
|
|
26
|
+
3. **Long-Horizon Memory Governance & Timeline Evolution (Anti-Decay & Reversible)**
|
|
27
|
+
- **Timeline Evolution & Supersession Lineage (`fact_supersessions`)**: During pre-write admission, ZeroMem recalls relevant active facts in the same namespace via `<1ms` FTS5 and links replacements (`supersedes_fact_id` / `superseded_by`) using Ollama JSON Schema constraints—ranking active facts ahead of superseded history while keeping full auditability.
|
|
28
|
+
- **Event Time Interval Filtering (`occurred_from` / `occurred_to`)**: Filter memories by `YYYY`, `YYYY-MM`, or `YYYY-MM-DD` event windows (`occurred_from`, `occurred_to`, `include_superseded`) across the engine, `zeromem_recall` tool, Web workbench, and CLI.
|
|
29
|
+
- **Time-Expiry Demotion (`until:YYYY-MM-DD`)**: expired temporary rules/plans are strictly calendar-validated and non-destructively demoted to the tail of search results instead of polluting active context.
|
|
30
|
+
- **Adaptive `2–8` Relative-Score Gating**: dynamically trims low-relevance tail noise based on relative BM25 score ratio (`0.35`, toggleable).
|
|
31
|
+
- **Lossless Soft-Eviction & SHA-256 Tamper-Checked Restore**: deleting a memory archives its facts, segments, supersession edges, and canonical SHA-256 fingerprint into the `evicted_records` side table; restoring verifies integrity before atomically rebuilding FTS5 indexes and lineage edges.
|
|
32
|
+
|
|
33
|
+
4. **Read-Only Markdown Export & SQLite Online Safe Backup (Obsidian / Cloud-Drive Friendly)**
|
|
34
|
+
- **100% Read-Only Markdown Export** (`dsh-zeromem export --md` / `GET /dsh-zeromem/api/export.md` / `exportMarkdown()`): opens SQLite read-only (`PRAGMA query_only = ON`) with zero LLM calls, exporting to stdout, a single file (`-o`), or an Obsidian/Git per-namespace vault directory (`--dir` with `INDEX.md`) complete with YAML frontmatter, bound original evidence quotes, supersession links, and `until:` annotations.
|
|
35
|
+
- **WAL-Safe Online Backup** (`dsh-zeromem backup` / `POST /dsh-zeromem/api/backup` / `backupDatabase()`): uses Node's built-in `node:sqlite` Online Backup API to snapshot live WAL databases without locking writers, flattens snapshots to `journal_mode = DELETE` (zero `-wal`/`-shm` sidecars for OneDrive/iCloud/BaiduSyncdisk), verifies `PRAGMA integrity_check == ok`, and optionally writes `.sha256` checksums.
|
|
36
|
+
|
|
37
|
+
5. **Flexible Dual Backend (Local Ollama ↔ OpenAI-Compatible API)**
|
|
38
|
+
- **Local Ollama (Default)**: connects directly to `127.0.0.1:11434` (bypassing system proxy for loopback), auto-detects local Ollama / `Qwen3.5-4B-Memory-V2`, and supports one-click background model pulling (`Q8_0` / `Q4_K_M`) with confirmation.
|
|
39
|
+
- **Cloud / Custom OpenAI-Compatible API**: switch live anytime without restarting DSH — built-in presets for DeepSeek, OpenAI, SiliconFlow, OpenRouter, plus persistent **Custom API** (Base URL + Model ID) for vLLM, LM Studio, or private gateways. API keys stay strictly local (`~/.zeromem/dsh-zeromem.json`, mode `0600`) and are never echoed to the browser.
|
|
40
|
+
|
|
41
|
+
6. **Native DSH Integration, CLI & Cross-Tool Interop**
|
|
42
|
+
- **5 Native DSH Tools** (strict lossless JSON): `zeromem_recall` (with `occurred_from` / `occurred_to` / `include_superseded`), `zeromem_remember` (with `link_supersessions`), `zeromem_stats`, `zeromem_evict`, `zeromem_restore`.
|
|
43
|
+
- **Automatic Session Lifecycle Hooks** (live-toggleable): `agent/pre-step` (`<1ms` recall with anti-loop markers) and `agent/turn-stopping` (non-blocking background extraction, automatically skips subagents).
|
|
44
|
+
- **Shared Database with Python ZeroMem**: reads and writes the exact same `~/.zeromem/memory.db` (`schema_version = 1`, including `fact_supersessions` and `evicted_records`) as [IMLIULIAN/zeromem](https://github.com/IMLIULIAN/zeromem), sharing local memory seamlessly across DSH, Cursor, Claude Code, and Codex.
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Installation
|
|
49
|
+
|
|
50
|
+
### Via DSH CLI
|
|
51
|
+
```bash
|
|
52
|
+
# Install into your web or desktop profile
|
|
53
|
+
dsh plugin --profile web add @imliulian/dsh-zeromem
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Via DSH Plugin Market
|
|
57
|
+
Open **Settings → Plugin Market** in DeepSeek Harness, search `@imliulian/dsh-zeromem` (or `dsh-zeromem`), and click Install.
|
|
58
|
+
|
|
59
|
+
### Isolated Local Development / Testing
|
|
60
|
+
```bash
|
|
61
|
+
dsh plugin --profile zeromem-dev add link:/path/to/dsh-zeromem
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Model Setup
|
|
67
|
+
|
|
68
|
+
### Option A: Local Ollama (Recommended, 100% Offline & Free)
|
|
69
|
+
Pull the companion specialist 4B model (or use any local Ollama model):
|
|
70
|
+
```bash
|
|
71
|
+
# High precision (recommended, ~4.5 GB)
|
|
72
|
+
ollama pull hf.co/IMLIULIAN/qwen3.5-4b-memory-v2:Q8_0
|
|
73
|
+
|
|
74
|
+
# Lightweight (~2.7 GB)
|
|
75
|
+
ollama pull hf.co/IMLIULIAN/qwen3.5-4b-memory-v2:Q4_K_M
|
|
76
|
+
```
|
|
77
|
+
*(You can also trigger detection, silent startup, and versioned pull directly from the plugin's Settings tab.)*
|
|
78
|
+
|
|
79
|
+
### Option B: OpenAI-Compatible API (No Dedicated GPU Required)
|
|
80
|
+
Configure via `~/.zeromem/dsh-zeromem.json`, environment variables, or the Settings tab. Credentials are masked to `[REDACTED]` before requests leave your machine.
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Configuration & Environment Overrides
|
|
85
|
+
|
|
86
|
+
Default config path: `~/.zeromem/dsh-zeromem.json` (`0600` on POSIX). Supports `cordis.patch.yml` overrides under `config:` or environment variables:
|
|
87
|
+
|
|
88
|
+
| Variable | Purpose |
|
|
89
|
+
| :--- | :--- |
|
|
90
|
+
| `ZEROMEM_DB` | Custom SQLite database path (default `~/.zeromem/memory.db`) |
|
|
91
|
+
| `ZEROMEM_DSH_CONFIG` | Custom plugin config JSON path |
|
|
92
|
+
| `ZEROMEM_PROVIDER` | `ollama` (default) or `openai-compatible` |
|
|
93
|
+
| `ZEROMEM_OLLAMA_URL` / `ZEROMEM_MODEL` / `ZEROMEM_NUM_CTX` | Local Ollama endpoint, model tag, and context window |
|
|
94
|
+
| `ZEROMEM_API_BASE_URL` / `ZEROMEM_API_MODEL` / `ZEROMEM_API_KEY` | OpenAI-compatible endpoint, model ID, and key |
|
|
95
|
+
| `ZEROMEM_UNTIL=0` | Disable `until:` expiry demotion |
|
|
96
|
+
| `ZEROMEM_ADAPTIVE_LIMIT_DISABLED=1` | Fall back from adaptive `2–8` gating to fixed top-6 |
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## Bonus: Embedded Web & Desktop Management Workbench
|
|
101
|
+
|
|
102
|
+
As an optional convenience on top of the local memory engine, the plugin injects a lightweight Shadow DOM management panel in DSH Web and DSH Desktop (automatically skipped in headless profiles, protected by loopback + same-origin security fences):
|
|
103
|
+
|
|
104
|
+
- Browse and search local facts, filter by namespace or event date range (`occurred_from` / `occurred_to`), inspect supersession badges (`替代 #N` / `已被 #M 替代`), expand bound original evidence, and highlight `[REDACTED]` tokens.
|
|
105
|
+
- One-click **Export Markdown** (read-only `.md` download) and **Online Backup** (WAL-flattened snapshot in `~/.zeromem/backups/` with `.sha256`).
|
|
106
|
+
- Manually write facts, soft-evict outdated entries (with recycle bin preview & SHA-256 restore), and clear expired `until:` records.
|
|
107
|
+
- Switch Local Ollama / Cloud API live, test connectivity, and optionally toggle light/dark frosted-glass styling or custom wallpaper.
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## CLI (`dsh-zeromem`)
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
# Search with event time range & hide superseded historical facts
|
|
115
|
+
npx @imliulian/dsh-zeromem search "database" --occurred-from 2026-01-01 --hide-superseded
|
|
116
|
+
|
|
117
|
+
# Read-only Markdown export (single file or Obsidian/Git per-namespace directory)
|
|
118
|
+
npx @imliulian/dsh-zeromem export --md -o ./zeromem.md
|
|
119
|
+
npx @imliulian/dsh-zeromem export --md --dir ./obsidian-vault/zeromem
|
|
120
|
+
|
|
121
|
+
# WAL-safe SQLite Online Backup (single file, journal_mode=DELETE, integrity_check=ok)
|
|
122
|
+
npx @imliulian/dsh-zeromem backup ./backups/ --sha256
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## Testing
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
npm run check
|
|
131
|
+
npm test
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## License, Attribution & Disambiguation
|
|
135
|
+
- **License**: **GNU Affero General Public License v3.0 (`AGPL-3.0-only`)** — see [LICENSE](LICENSE) and [NOTICE](NOTICE). Any redistributed modifications or network-accessible deployments derived from this plugin must remain open-source under AGPL-3.0 with original copyright notices preserved.
|
|
136
|
+
- **Author & Companion Projects**: **IMLIULIAN (B站IM榴莲)** · **ZeroZoneX** — [IMLIULIAN/zeromem](https://github.com/IMLIULIAN/zeromem) · [Qwen3.5-4B-Memory-V2 (Hugging Face, separately Apache-2.0)](https://huggingface.co/IMLIULIAN/qwen3.5-4b-memory-v2)
|
|
137
|
+
- **Schema Lineage & Compatibility**: The fact schema conventions shared with ZeroMem (`bank`, `type: world | experience | observation`, `occurred_start` / `occurred_end` / `mentioned_at`, `where`, `entities`) are inspired by and conceptually compatible with [**Vectorize Hindsight**](https://github.com/vectorize-io/hindsight) (MIT License). This plugin's `node:sqlite` + dual-track FTS5 engine, pre-write admission guardrails, governance/restore layer, and DSH UI/hooks are independent implementations containing no Hindsight source code.
|
|
138
|
+
- **Name Disambiguation**: **ZeroMem (零忆)** / `@imliulian/dsh-zeromem` is an independent local memory system and is **not** affiliated with or derived from the academic paper *Zero-Mem: Zero-Token Memory Operations for LLM Agents* (Yilin Xiao et al., [arXiv:2607.29377](https://arxiv.org/abs/2607.29377), July 2026).
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
<p align="right">
|
|
2
|
+
<strong>简体中文</strong> | <a href="README.md">English</a>
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
# @imliulian/dsh-zeromem
|
|
6
|
+
|
|
7
|
+
> **ZeroMem(零忆)—— 面向 DeepSeek Harness(DSH)的纯本地、证据溯源长期记忆系统** · AGPL-3.0
|
|
8
|
+
> 作者:**B站IM榴莲(IMLIULIAN)** · ZeroZoneX
|
|
9
|
+
|
|
10
|
+
`@imliulian/dsh-zeromem` 将一套**单文件、零外部依赖、有据可查的本地记忆引擎**原生集成进 DeepSeek Harness:无需云端向量库、无需 Python 运行环境、无需 `node-gyp` / `better-sqlite3` 原生编译,也无需 MCP 子进程中转。
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## 核心能力(本地记忆系统)
|
|
15
|
+
|
|
16
|
+
1. **纯本地单文件引擎,`<1ms` 检索,零原生编译依赖**
|
|
17
|
+
- 直接基于 Node 内置 `node:sqlite`(`Node >= 22.19` / DSH 内置 `Node 24`)构建,采用**中文 2-gram + 英文双轨 FTS5 全文索引**,同时索引提炼事实与原始证据片段。
|
|
18
|
+
- **零第三方运行时依赖、零 `postinstall` 编译脚本**,完美兼容 `pnpm >= 10` 默认安全策略,秒装即用。
|
|
19
|
+
- **100% Fail-Open 容错**:即使本地 Ollama 或云端 API 离线,也绝不阻塞 DSH 启动与正常对话,历史记忆本地 FTS5 检索始终可用。
|
|
20
|
+
|
|
21
|
+
2. **证据绑定 + 写前原文对照审校(拒绝黑盒幻觉)**
|
|
22
|
+
- 内置**短窗切块 → 结构化抽取 → 1 轮原文对照审校(Admission)→ 确定性规则守卫**双阶段流水线,针对开源 4B 记忆专项微调模型 **[Qwen3.5-4B-Memory-V2](https://huggingface.co/IMLIULIAN/qwen3.5-4b-memory-v2)** 深度打磨(通过 Ollama 100% 离线运行,写入 ¥0 云端费)。
|
|
23
|
+
- 每一条入库事实均**强制绑定原始证据片段**(`evidence_ids`),随时可回溯原文核对,避免摘要漂移与无中生有。
|
|
24
|
+
- **离开本机前自动密钥脱敏**:常见密钥与凭据(`sk-...`、`ghp_...`、`AKIA...`、`Bearer ...` 等)在送往模型与写入数据库前自动替换为 `[REDACTED]`,切换云端 API 时同样受保护。
|
|
25
|
+
|
|
26
|
+
3. **面向长周期演进的时间线演化与记忆治理机制**
|
|
27
|
+
- **时间线演化与替代链(`fact_supersessions`)**:写前自动经 `<1ms` 同空间 FTS5 召回相关活跃旧事实(`prior_facts`),结合 Ollama JSON Schema 约束在单轮审校内安全标出 `supersedes_fact_id`;召回时活跃事实自动优先于被替代历史事实排序,同时完整保留历史可溯源链。
|
|
28
|
+
- **事件时间区间过滤(`occurred_from` / `occurred_to`)**:支持 `YYYY`、`YYYY-MM`、`YYYY-MM-DD` 区间重叠检索与 `include_superseded` 控制,覆盖引擎、`zeromem_recall` 工具、Web 工作台与 CLI。
|
|
29
|
+
- **`until:YYYY-MM-DD` 过期自动后移**:严格日历校验临时规则/阶段性计划,过期记录无损后移至召回尾部并附带结构化过期标记,不污染当前有效记忆。
|
|
30
|
+
- **`2–8` 动态相对分数门槛**:按头名相关性比值(默认 `0.35`,可开关)自动截断尾部低相关噪音,减少无效上下文占用。
|
|
31
|
+
- **无损软淘汰 + `SHA-256` 防篡改原子恢复**:删除的记忆连同原文片段、替代链边与规范化 `SHA-256` 指纹一并归档至同库 `evicted_records` 边表;恢复时先做完整性校验,再原子写回并重建 FTS5 索引与演化边表。
|
|
32
|
+
|
|
33
|
+
4. **只读 Markdown 导出与 SQLite 在线安全备份(适配 Obsidian / Git / 网盘)**
|
|
34
|
+
- **100% 只读 Markdown 导出**(`dsh-zeromem export --md` / `GET /dsh-zeromem/api/export.md` / `exportMarkdown()`):只读模式打开数据库(`PRAGMA query_only = ON`),零 LLM 调用,支持标准输出、单文件(`-o`)及按空间拆分的 Obsidian/Git 目录(`--dir`,附 `INDEX.md`),保留 YAML frontmatter、原文引用块、替代链与 `until:` 过期标注。
|
|
35
|
+
- **WAL 安全在线热备**(`dsh-zeromem backup` / `POST /dsh-zeromem/api/backup` / `backupDatabase()`):直接调用 Node 内置 `node:sqlite` Online Backup API,不阻塞并发读写,自动将快照拍平为 `journal_mode = DELETE`(无 `-wal`/`-shm` 伴生文件,安全适配 OneDrive/百度网盘/iCloud),内置 `PRAGMA integrity_check` 与可选 `.sha256` 校验文件。
|
|
36
|
+
|
|
37
|
+
5. **本地模型 ↔ 云端 API 自由切换(无独显也能用)**
|
|
38
|
+
- **本地模型(Ollama,默认)**:回环地址直连 `127.0.0.1:11434`(自动绕过系统代理),自动检测本机 Ollama 与 `Qwen3.5-4B-Memory-V2`,支持按需一键拉取 `Q8_0` / `Q4_K_M` 版本(均带二次确认)。
|
|
39
|
+
- **云端 / 自定义 OpenAI 兼容 API**:无需重启 DSH 实时切换,内置 DeepSeek / OpenAI / SiliconFlow / OpenRouter 预设,并支持持久化保存**自定义 API**(Base URL + Model ID,适配 vLLM、LM Studio 或私有网关)。API Key 仅保存在本机 `~/.zeromem/dsh-zeromem.json`(POSIX `0600`),绝不向浏览器回显明文。
|
|
40
|
+
|
|
41
|
+
6. **DSH 原生闭环、命令行工具 & 跨工具数据库互通**
|
|
42
|
+
- **5 个原生 DSH 工具**(严格无损 JSON):`zeromem_recall`(支持 `occurred_from` / `occurred_to` / `include_superseded`)、`zeromem_remember`(支持 `link_supersessions`)、`zeromem_stats`、`zeromem_evict`、`zeromem_restore`。
|
|
43
|
+
- **会话生命周期自动闭环**(均支持热开关):`agent/pre-step`(发消息前 `<1ms` 带防回环标记自动召回)与 `agent/turn-stopping`(每轮结束后后台异步沉淀,自动跳过 subagent)。
|
|
44
|
+
- **与 Python 版 ZeroMem 100% 数据互通**:共用同一份 `~/.zeromem/memory.db`(`schema_version = 1`,完整互通 `fact_supersessions` 与 `evicted_records`),与 [IMLIULIAN/zeromem](https://github.com/IMLIULIAN/zeromem) 在 DSH、Cursor、Claude Code、Codex 之间无缝共享同一套本地记忆库。
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## 安装
|
|
49
|
+
|
|
50
|
+
### 方式一:DSH CLI(推荐)
|
|
51
|
+
```bash
|
|
52
|
+
# 安装到 web 或 desktop profile
|
|
53
|
+
dsh plugin --profile web add @imliulian/dsh-zeromem
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### 方式二:DSH 插件市场
|
|
57
|
+
打开 DeepSeek Harness **设置 → 插件市场**,搜索 `@imliulian/dsh-zeromem`(或 `dsh-zeromem`)点击安装。
|
|
58
|
+
|
|
59
|
+
### 本地开发与隔离测试
|
|
60
|
+
```bash
|
|
61
|
+
# 建议使用独立测试 profile,避免与现有记忆插件冲突
|
|
62
|
+
dsh plugin --profile zeromem-dev add link:/path/to/dsh-zeromem
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## 模型配置
|
|
68
|
+
|
|
69
|
+
### 方案 A:本地 Ollama(推荐,完全离线、零云端费)
|
|
70
|
+
拉取配套开源专项 4B 记忆模型(也可在设置中填入任意本机已有 Ollama 模型):
|
|
71
|
+
```bash
|
|
72
|
+
# 高精度推荐版(约 4.5 GB,建议 6–8 GB 以上显存或 Apple Silicon)
|
|
73
|
+
ollama pull hf.co/IMLIULIAN/qwen3.5-4b-memory-v2:Q8_0
|
|
74
|
+
|
|
75
|
+
# 轻量显存版(约 2.7 GB)
|
|
76
|
+
ollama pull hf.co/IMLIULIAN/qwen3.5-4b-memory-v2:Q4_K_M
|
|
77
|
+
```
|
|
78
|
+
> 也可直接在插件设置页点击一键检测、后台静默启动 Ollama 或确认拉取模型。
|
|
79
|
+
|
|
80
|
+
### 方案 B:云端 / OpenAI 兼容 API(无独显 / 轻薄本)
|
|
81
|
+
在 `~/.zeromem/dsh-zeromem.json`、环境变量或插件设置页切换到「云端 API」,选择预设或填写自定义 Base URL 与模型 ID 即可。敏感密钥在离开本机前仍会自动脱敏为 `[REDACTED]`。
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## 配置文件与环境变量
|
|
86
|
+
|
|
87
|
+
默认配置文件位于 `~/.zeromem/dsh-zeromem.json`(POSIX 下权限 `0600`),亦支持在 profile 的 `cordis.patch.yml` 中通过 `config:` 覆盖,或使用以下环境变量:
|
|
88
|
+
|
|
89
|
+
| 环境变量 | 说明 |
|
|
90
|
+
| :--- | :--- |
|
|
91
|
+
| `ZEROMEM_DB` | 自定义 SQLite 数据库路径(默认 `~/.zeromem/memory.db`) |
|
|
92
|
+
| `ZEROMEM_DSH_CONFIG` | 自定义插件配置文件路径 |
|
|
93
|
+
| `ZEROMEM_PROVIDER` | 后端模式:`ollama`(默认)或 `openai-compatible` |
|
|
94
|
+
| `ZEROMEM_OLLAMA_URL` / `ZEROMEM_MODEL` / `ZEROMEM_NUM_CTX` | 本地 Ollama 地址、模型标签与上下文长度 |
|
|
95
|
+
| `ZEROMEM_API_BASE_URL` / `ZEROMEM_API_MODEL` / `ZEROMEM_API_KEY` | OpenAI 兼容 API 地址、模型 ID 与密钥 |
|
|
96
|
+
| `ZEROMEM_UNTIL=0` | 关闭 `until:` 过期后移逻辑 |
|
|
97
|
+
| `ZEROMEM_ADAPTIVE_LIMIT_DISABLED=1` | 关闭 `2–8` 动态门槛,回退固定 Top-6 召回 |
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## 附带加分项:内嵌 Web / 桌面管理面板
|
|
102
|
+
|
|
103
|
+
在本地记忆引擎之上,插件额外附带了一个轻量的 Shadow DOM 内嵌侧滑工作台(仅在带界面的 DSH Web / 桌面端注入,Headless 环境自动跳过,受本机回环 + 同源双层安全栅栏保护),方便可视化日常打理:
|
|
104
|
+
|
|
105
|
+
- 快速检索、按空间或事件日期区间筛选、查看替代链徽章(`替代 #N` / `已被 #M 替代`)、点击记忆展开原始绑定证据、高亮查看 `[REDACTED]` 脱敏标记。
|
|
106
|
+
- 一键**导出只读 Markdown(`.md`)**与**在线安全备份**(自动生成拍平 WAL 的单文件快照及 `.sha256` 至 `~/.zeromem/backups/`)。
|
|
107
|
+
- 手动写入记忆、软淘汰至回收站、按批次预览与 `SHA-256` 校验一键恢复、一键清理已过期 `until:` 记忆。
|
|
108
|
+
- 实时切换本地 Ollama / 云端 API、一键测试连接,附带亮/暗毛玻璃主题与自定义壁纸等轻量交互体验。
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## 命令行工具(`dsh-zeromem`)
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
# 按事件时间区间检索并隐藏被替代的历史事实
|
|
116
|
+
npx @imliulian/dsh-zeromem search "架构方案" --occurred-from 2026-01-01 --hide-superseded
|
|
117
|
+
|
|
118
|
+
# 只读导出为单文件 Markdown 或 Obsidian/Git 分空间目录
|
|
119
|
+
npx @imliulian/dsh-zeromem export --md -o ./zeromem.md
|
|
120
|
+
npx @imliulian/dsh-zeromem export --md --dir ./obsidian-vault/zeromem
|
|
121
|
+
|
|
122
|
+
# WAL 安全在线备份(拍平为无 -wal/-shm 单文件快照 + integrity_check + .sha256)
|
|
123
|
+
npx @imliulian/dsh-zeromem backup ./backups/ --sha256
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## 开发与测试
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
npm run check
|
|
132
|
+
npm test
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## 许可、血缘归属与同名消歧
|
|
136
|
+
- **开源协议**:**GNU Affero General Public License v3.0(`AGPL-3.0-only`)**,详见 [LICENSE](LICENSE) 与 [NOTICE](NOTICE)。任何基于本插件的二次修改分发或网络服务部署均须以 AGPL-3.0 同等开源并保留原作者署名与版权声明。
|
|
137
|
+
- **作者与关联项目**:**B站IM榴莲(IMLIULIAN)** · **ZeroZoneX** — [IMLIULIAN/zeromem](https://github.com/IMLIULIAN/zeromem) · [Qwen3.5-4B-Memory-V2(Hugging Face,模型权重单独采用 Apache-2.0)](https://huggingface.co/IMLIULIAN/qwen3.5-4b-memory-v2)
|
|
138
|
+
- **Schema 血缘与兼容致谢**:本插件与 ZeroMem 共用的结构化事实字段协议(`bank`、`type: world | experience | observation`、`occurred_start` / `occurred_end` / `mentioned_at`、`where`、`entities`)受开源项目 [**Vectorize Hindsight**](https://github.com/vectorize-io/hindsight)(MIT License)启发并保持概念/Schema 兼容;本插件基于 `node:sqlite` 的双轨 FTS5 引擎、写前审校守卫、过期/软淘汰与 SHA-256 恢复机制及 DSH 集成代码均为独立从零实现,不含 Hindsight 源码。
|
|
139
|
+
- **同名论文消歧**:**ZeroMem(零忆)** 与 `@imliulian/dsh-zeromem` 是独立开发的纯本地记忆系统,与学术论文 *Zero-Mem: Zero-Token Memory Operations for LLM Agents*(Yilin Xiao et al., [arXiv:2607.29377](https://arxiv.org/abs/2607.29377), 2026 年 7 月)名称相近,但两者完全独立,无作者、代码、模型或隶属关系。
|