Bundle
dsh-shared-memory
跨对话记忆系统 v2:分层记忆(MEMORY.md + USER.md 常驻注入 + topics/ 主题库按需加载),memory 工具(target 支持 topic) + 可视化记忆面板(笔记/画像/主题库)
- Source
- futongxu9-maker
- stars
- 1 stars
- License
- MIT
- Updated
- Updated 2 days ago
Readme
# dsh-shared-memory · 跨对话记忆(Shared Memory)
**DeepSeek Harness 的跨对话记忆系统**(Hermes 式):把**持久化记忆**注入每个会话的系统提示词,并提供 `memory` 工具 + 可视化记忆面板(GUI),让新对话自动知道旧对话沉淀的内容。
> Cross-conversation memory for DeepSeek Harness, Hermes-style: durable memory injected into every session's system prompt, with a `memory` maintenance tool and a GUI panel.
## 功能 / Features
- **分层记忆(索引 + 主题库)**:
- `MEMORY.md`(agent 高频笔记,上限 8000 字符)+ `USER.md`(用户画像,上限 4000 字符)**常驻注入**每个新会话
- `topics/<name>.md`(主题文件,如 `feishu.md` / `projects.md`,默认上限 12000 字符)**不常驻注入**——只在 `MEMORY.md` 文末生成一行主题索引(文件名 + 字符数 + 首条摘要),agent 需要时用 `read` 按需加载
- **memory 工具**:`add` / `replace` / `remove` / `list` 维护记忆条目;`target` 支持 `memory` / `user` / `topic:<文件名>`;写入自检规则引导只存「原则 / 工作数据 / 持久事实」
- **记忆面板 GUI**:侧边栏「记忆」按钮打开面板——**笔记 / 画像 / 主题库**三个标签页,浏览、编辑、添加、删除条目,实时显示容量(`N 条 · X/上限 字符`)
- **条目格式**:`§` 分隔,推荐 `[发现]/[决策]/[偏好]/[纠正]` 分类前缀
- **容量可控**:环境变量 `DSH_MEMORY_CHAR_LIMIT` / `DSH_MEMORY_USER_CHAR_LIMIT` / `DSH_MEMORY_TOPIC_CHAR_LIMIT` 可调
## 要求 / Requirements
- DeepSeek Harness rc.6+(`dsh web`)
- Windows / macOS / Linux 通用(纯 Node ESM + 浏览器端)
## 安装 / Install
### 方式一:dsh 插件命令(推荐)
```bash
dsh plugin --profile web add github:futongxu9-maker/dsh-shared-memory
```
### 方式二:手动
1. 把 `dsh-shared-memory` 目录复制到 `~/.dsh/profiles/web/node_modules/dsh-shared-memory/`
2. 在 `~/.dsh/profiles/web/cordis.patch.yml` 追加:
```yaml
- insert:
- id: shared-memory
name: 'dsh-shared-memory'
```
3. 刷新页面(或重启服务)
## 使用 / Usage
- **模型侧**:每个会话的系统提示词自动带上 `MEMORY.md` + `USER.md` + 主题索引(每个主题文件一行摘要);agent 用 `memory` 工具维护(`add` 新条目、`replace` 更新、`remove` 删除、`list` 查看用量、`target='topic:<名>'` 写主题文件)
- **用户侧**:点击侧边栏底部的「记忆」按钮 → 面板里查看/编辑三个标签页(支持增删改、容量提示)
- 记忆文件位置:`~/.dsh/memories/MEMORY.md`、`USER.md`、`topics/*.md`(均可直接手动编辑)
## 架构 / Architecture
```
浏览器 (Client) Node (Host)
┌──────────────────────────┐ ┌──────────────────────────────┐
│ @local/dsh-memory-ui │ GET/POST │ shared-memory.mjs │
│ 侧边栏「记忆」按钮 + 面板 │──/api/──────▶│ · system-prompt section(注入)│
│(笔记/画像/主题库 3 标签) │ shared-memory│ · memory 工具(model-visible)│
└──────────────────────────┘ │ · /api/shared-memory 路由 │
└──────────────────────────────┘
```
- **Host**(`shared-memory.mjs`):注册系统提示词 section(注入常驻记忆 + 主题索引)、`memory` 工具(add/replace/remove/list + target 支持 topic + 容量自检)、HTTP API `/api/shared-memory`(GET 返回 memory/user/topics,POST 按 target 写入,供 GUI 用)
- **Client**(`@local/dsh-memory-ui`):通过 `dsh.client` 协议注入侧边栏按钮 + overlay 面板,fetch 同源 API 读写记忆
## 记忆写入自检规则(内置在 memory 工具里)
只写三类:①用户的原则/偏好/决策方式/纠正;②工作数据(Base ID、账号、链接、路径);③环境与项目的持久事实。禁止一次性/临时内容与实现细节;拿不准不写。
## License
MIT
Install
dsh plugin --profile web add github:futongxu9-maker/dsh-shared-memory#589c037f42a8b7ed0d1258176c4215860dcf82c9
Profile: web
With the hub plugin installed, ask your agent to install it by name — it resolves the same plan shown here.
dsh plugin --profile web add github:stvlynn/dsh.fish#path:packages/dsh-plugin-hub
install dsh-shared-memory from the hub