鱼皮AI导航
鱼皮AI导航
  • 主页
  • 社区
  • AI工具
  • AI知识库
  • AI提示词
  • MCP
  • Skills
  • AI学习资源
  • AI资讯
  • GitHub开源
登录/注册

dsh-memory-connect

跨会话记忆插件(v0.6.1,npm 包 @asherliner/dsh-memory-connect):自动提取、SQLite FTS5 索引、RRF 语义召回(每轮注入系统提示词)、定时维护、LLM 智能合并(自动接入 ctx.llm)、上下文爆炸防护、全局身份 Soul(~/.dsh/soul.md)。v0.5.0 新增:时态上下文图谱(valid_from/valid_until/supersedes,reviseMemory 追加式修正)、信任模型(历史记忆作为不可信参考注入,当前指令绝对优先)、轮末自动摘要。v0.6.0 新增:本地语义 embedding(BAAI/bge-small-zh-v1.5,embed_server.py 提供,余弦相似度 + 与 FTS5 的 RRF 融合,纯本地无云端调用,CPU 约 232 条/秒)。v0.6.1 修复 path 配置 ~ 展开。零配置装完即用。

记忆
访问 GitHub
文档README

@asherliner/dsh-memory-connect

跨会话记忆插件 — 让 AI Agent 拥有持久记忆和全局身份
Cross-session memory plugin for DeepSeek Harness (DSH)


English | 中文

Overview

dsh-memory-connect is a cross-session memory sharing plugin for DeepSeek Harness. It automatically extracts, stores, and recalls memories across sessions, giving your AI agent persistent, intelligent memory with context explosion prevention and global Soul identity.

Zero-config — works out of the box with SQLite FTS5 and DSH's built-in LLM.

🚨 v0.4.0 — The "it actually works now" release

v0.3.0 registered the service but never instantiated it (Cordis lazily constructs services — passing the class to ctx.provide() means the constructor never runs), and the "recall" feature wrote a computed context to a field no one ever read. In practice the plugin did nothing.

v0.4.0 fixes the activation chain and wires recall into the system prompt: a systemPrompt.context provider injects ## Related Memories from Previous Sessions on every turn. Zero-config runnable: a bare dsh plugin add used to crash on config.openAt (Cordis passes undefined config when the patch has no config: block) — apply() now fills in full defaults (DB at ~/.dsh/memory.db, openAt: startup). Verified end-to-end on dsh v0.1.1-rc.2 / Node 24: tell session A "my cat is named Mimi", start a fresh session B and ask — the model answers correctly from memory.

See CHANGELOG.md for the full breakdown.

Features

FeatureDescription
🧠 Global SoulPersistent identity across all workspaces via ~/.dsh/soul.md
🔍 Auto ExtractionExtracts facts, preferences, decisions, and context from conversations
🧠 Cross-Session RecallFTS5 keyword recall injected into the system prompt every turn (recency fallback when no query text is available)
🛡️ Context Explosion PreventionToken budget management prevents context window overflow
⏰ Scheduled MaintenanceAutomatic periodic decay and consolidation via built-in scheduler
🤖 LLM ConsolidationIntelligent memory merging using DSH's built-in ctx.llm (zero-config)
📉 Memory DecayOld, unused memories naturally fade; frequently accessed ones persist
🎯 Smart PrioritizationMemory selection based on relevance × recency × frequency
🗜️ Memory CompressionAutomatic compression when approaching token limits
🧭 Temporal Context GraphEvery memory carries valid_from/valid_until; corrections are append-only via reviseMemory() (soft-supersede + successor link), never destructive. History stays queryable; recall only sees current truth.
🛡️ Trust ModelRecalled history is injected as an untrusted reference (explicit warning; current instruction always wins) — prevents memory poisoning and prompt conflicts
📝 Turn-End Summarizationturn/end events auto-generate lightweight summary memories preserving the conversation arc
🔎 Semantic RecallOptional local embedding (BGE-small-zh-v1.5) fuses with FTS5 via RRF — finds memories by meaning even with zero keyword overlap. Opt-in (embeddingEnabled: true).

🧠 Global Soul (Identity)

The Soul feature provides a persistent identity that follows you across all workspaces.

How it works

  1. Create ~/.dsh/soul.md with your identity information
  2. The plugin automatically loads and injects it into every session
  3. Your preferences, tech stack, and coding style are always available

Example Soul file

▼
markdown
复制代码
# 🧠 Soul — Global Identity ## 👤 Identity - GitHub: your-username - Role: Developer/Designer/Product Manager ## 💻 Tech Stack - TypeScript, React, Node.js, DSH/Cordis ## 🎨 Coding Style - Functional programming - ES Modules - Zero-config preferred ## ⚠️ Preferences - No class components - No redundant comments

Installation

✅ Published on npm — install from npm registry (v0.6.1):

▼
bash
复制代码
# 方式 A:dsh plugin add(推荐,自动装入 profile) dsh plugin --profile <你的profile> add @asherliner/dsh-memory-connect # 方式 B:npm 直接安装 npm install @asherliner/dsh-memory-connect # 方式 C:本地源码 link(开发/调试用) git clone https://github.com/Asher-2000/dsh-memory-connect.git cd dsh-memory-connect dsh plugin --profile <你的profile> add link:/path/to/dsh-memory-connect

Add to your DSH composition:

▼
yaml
复制代码
# agent.cordis.yml - id: memory name: '@asherliner/dsh-memory-connect' config: path: ~/.dsh/memory.db enableSoul: true # Enable Soul injection (default: true)

Requirement: the plugin injects systemPrompt (used for the cross-session recall context provider). Any profile that loads this plugin needs the systemPrompt service available (standard in the dsh web/headless profiles).

Configuration

Basic Options

OptionDefaultDescription
path(required)Path to SQLite memory database
openAtstartupWhen to open: startup, first-query, never
maxRecallCount10Max memories to recall per session
decayRate0.02Decay constant (higher = faster decay)
journalModewalSQLite journal mode

Scheduler Options

OptionDefaultDescription
schedulerEnabledtrueEnable periodic maintenance
schedulerDecayIntervalMs3600000Decay interval (ms), default 1h
schedulerConsolidateIntervalMs21600000Consolidation interval (ms), default 6h

Context Explosion Prevention Options

OptionDefaultDescription
maxContextTokens4000Max tokens for memory context injection
smartPrioritizationtrueEnable smart memory prioritization
enableCompressiontrueEnable memory compression

Soul Options

OptionDefaultDescription
enableSoultrueEnable global Soul injection
soulPath~/.dsh/soul.mdCustom Soul file path

Semantic Embedding Options (optional)

OptionDefaultDescription
embeddingEnabledfalseEnable semantic (vector) recall via local embedding server
embeddingUrlhttp://127.0.0.1:8765Embedding server base URL
embeddingModelBAAI/bge-small-zh-v1.5Model name (must match the server)
embeddingWeight0.7RRF fusion weight for semantic results (0–1)

To use semantic recall, start the bundled embedding server first:

▼
bash
复制代码
# one-time: install the Python model pip install sentence-transformers # start the server (keeps the model resident) python3 node_modules/@asherliner/dsh-memory-connect/scripts/embed_server.py --port 8765

Then enable it in the plugin config (embeddingEnabled: true). The plugin degrades gracefully to keyword-only recall if the server is unreachable.

Full configuration example:

▼
yaml
复制代码
- id: memory name: '@asherliner/dsh-memory-connect' config: path: ~/.dsh/memory.db openAt: startup maxRecallCount: 10 decayRate: 0.02 journalMode: wal schedulerEnabled: true maxContextTokens: 4000 smartPrioritization: true enableCompression: true enableSoul: true

API

Search Memories

▼
javascript
复制代码
const memories = await ctx.crossSessionMemory.searchMemories({ query: 'TypeScript configuration', types: ['fact', 'decision'], limit: 5, })

Recall for Session

▼
javascript
复制代码
const memories = await ctx.crossSessionMemory.recallForSession( 'session-123', 'Setting up a new React project', 10 )

Synchronous Recall (for system-prompt providers)

▼
javascript
复制代码
// v0.4.0+ — sync API for prompt-context providers (node:sqlite is synchronous, // so no async needed). Returns a formatted markdown block or ''. const block = ctx.crossSessionMemory.recallSync('session-123', 'React project')

Latest User Text (from dsh session logs)

▼
javascript
复制代码
// v0.4.0+ — extracts the most recent user message text from a dsh Session // (handles {event: ...} wrappers, agent/inbox/spliced, and bare events). const query = ctx.crossSessionMemory.currentUserText(agent.session)

Store Memory

▼
javascript
复制代码
await ctx.crossSessionMemory.storeMemory({ type: 'preference', content: 'User prefers functional programming style', sessionId: 'session-123', tags: ['coding-style', 'preference'], })

Manual Maintenance

▼
javascript
复制代码
// Trigger a full maintenance cycle (decay + consolidation) const result = await ctx.crossSessionMemory.triggerMaintenance() // Or run individually await ctx.crossSessionMemory.runDecay() await ctx.crossSessionMemory.consolidate()

Context Explosion Prevention

How It Works

  1. Token Counting — Estimates tokens for English, Chinese, and mixed text
  2. Smart Prioritization — Ranks memories by: relevance × 50% + recency × 30% + frequency × 20%
  3. Budget Management — Enforces maxContextTokens limit (default: 4000)
  4. Memory Compression — Automatically truncates or summarizes when approaching limits

Output Example

▼
markdown
复制代码
## 🧠 Global Identity (Soul) [Your Soul content here] --- ## Related Memories from Previous Sessions - [preference] User prefers TypeScript - [decision] Chose PostgreSQL over MySQL > 💾 Memory: 2/10 memories + Soul | 250/4000 tokens

Memory Types

TypeDescriptionExample
factObjective information"Project uses TypeScript 5.3"
preferenceUser preferences"Prefers functional components"
contextProject context"E-commerce platform migration"
decisionDecisions made"Chose PostgreSQL over MySQL"
skillLearned patterns"How to configure ESLint"

Development

▼
bash
复制代码
git clone https://github.com/Asher-2000/dsh-memory-connect.git cd dsh-memory-connect npm install npm test

License

MIT


中文

概述

dsh-memory-connect 是 DeepSeek Harness 的跨会话记忆共享插件。它自动从对话中提取、存储和检索记忆,让 AI Agent 拥有持久化的智能记忆能力,并防止上下文爆炸和全局身份。

零配置 — 基于 SQLite FTS5 和 DSH 内置 LLM,开箱即用。

🚨 v0.4.0 — "这次真的能跑"版本

v0.3.0 只注册了服务但从未实例化(Cordis 懒加载机制:把类传给 ctx.provide() 导致构造函数永远不执行),且"召回"功能把计算好的上下文写进了一个无人读取的字段——实际运行中插件什么都不做。

v0.4.0 修复了启动链路,并把召回真正接入了系统提示词:通过 systemPrompt.context 提供者,每轮对话都注入 ## Related Memories from Previous Sessions。零配置即可运行:此前仅执行 dsh plugin add(patch 无 config: 块时 Cordis 传入 undefined 配置)会在 config.openAt 崩溃——现在 apply() 自动填充完整默认值(DB ~/.dsh/memory.db、openAt: startup)。已在 dsh v0.1.1-rc.2 / Node 24 上端到端验证:会话 A 说"我的猫叫咪咪",开新会话 B 问它,模型能正确从记忆中回答。

详见 CHANGELOG.md。

核心功能

功能说明
🧠 全局身份 (Soul)通过 ~/.dsh/soul.md 跨所有工作区持久化身份
🔍 自动提取从对话中提取事实、偏好、决策和上下文
🧠 跨会话召回FTS5 关键词召回,每轮注入系统提示词(无查询文本时按最近记忆兜底)
🛡️ 上下文爆炸防护Token 预算管理,防止上下文窗口溢出
⏰ 定时维护内置调度器自动执行衰减和整合
🤖 LLM 整合使用 DSH 内置 LLM 智能合并相似记忆
📉 记忆衰减旧的、不常用的记忆自然消退
🎯 智能优先级基于相关性 × 时间 × 频率的记忆排序
🗜️ 记忆压缩接近 token 限制时自动压缩
🧭 时态上下文图谱每条记忆带 valid_from/valid_until;修正通过 reviseMemory() 追加而非覆盖(软废弃旧记忆 + 新记忆链接),历史可回溯,召回只见当前有效真相
🛡️ 信任模型召回的历史作为不可信参考注入(显式警告;当前指令绝对优先)— 防止记忆投毒和提示词冲突
📝 轮末自动摘要turn/end 事件自动生成轻量 summary 记忆,保留对话脉络

🧠 全局身份 (Soul)

Soul 功能提供跨所有工作区的持久化身份。

工作原理

  1. 创建 ~/.dsh/soul.md 包含你的身份信息
  2. 插件自动加载并注入到每个会话
  3. 你的偏好、技术栈和编码风格始终可用

Soul 文件示例

▼
markdown
复制代码
# 🧠 Soul — 全局身份 ## 👤 身份 - GitHub: your-username - 角色: 开发者/设计师/产品经理 ## 💻 技术栈 - TypeScript, React, Node.js, DSH/Cordis ## 🎨 编码风格 - 函数式编程 - ES Modules - 零配置优先 ## ⚠️ 偏好 - 不用 class 组件 - 不写冗余注释

快速开始

✅ 已发布到 npm — 从 npm registry 安装 (v0.6.1):

▼
bash
复制代码
# 方式 A:dsh plugin add(推荐,自动装入 profile) dsh plugin --profile <你的profile> add @asherliner/dsh-memory-connect # 方式 B:npm 直接安装 npm install @asherliner/dsh-memory-connect # 方式 C:本地源码 link(开发/调试用) git clone https://github.com/Asher-2000/dsh-memory-connect.git dsh plugin --profile <你的profile> add link:/path/to/dsh-memory-connect

添加到 DSH 配置:

▼
yaml
复制代码
# agent.cordis.yml - id: memory name: '@asherliner/dsh-memory-connect' config: path: ~/.dsh/memory.db enableSoul: true

依赖说明:插件注入 systemPrompt 服务(用于跨会话召回 context 提供者)。所在 profile 需要提供 systemPrompt(dsh web/headless profile 默认都有)。

许可证

MIT

记忆

快捷安装

复制到终端去安装插件

dshplugin--profilewebaddgithub:Asher-2000/dsh-memory-connect

温馨提示

装插件等于在本机跑第三方代码,权限与你相同,能读文件、用凭据、访问网络,工具审批管不到。请只装可信来源,并尽量锁定 commit。

站长:程序员鱼皮 老鱼简历 商务合作 增值电信业务经营许可证
2026 鱼皮AI导航 | 沪ICP备19026706号-6
站长:程序员鱼皮 老鱼简历 商务合作 增值电信业务经营许可证
2026 鱼皮AI导航 | 沪ICP备19026706号-6
🔥热门工具
朱雀AI检测朱雀AI检测
朱雀AI检测助手朱雀AI检测助手
LovartLovart
老鱼简历老鱼简历
WritePass官网WritePass官网
面多多面多多
CursorCursor
星月写作星月写作
零感AI零感AI
墨得问题墨得问题
dsh 插件推荐
dsh-memory-eternal
给 DeepSeek Harness 装上自研「第二大脑」:对话结束自动把值得复用的内容沉淀成本地 Markdown 知识卡(自研去重、CJK 检索、可 git 管理),设置页提供图形化知识库 + 交互式知识图谱(图例过滤、时间维、框选、合并、导入导出)。
dsh-decision-log
DeepSeek Harness 决策日志:通过 decision_log / decision_list / decision_audit 工具把关键决策(选了什么 + 为什么)沉淀为可版本化的 DECISIONS.md,并在后续会话自动注入摘要,让决策可追溯、不重复、不推翻。
dsh-flomo-report
生成 AI 叙事的 DSH 会话报告(日报/周报/月报、任意区间)并同步到 flomo:单一可配置标签(默认
dsh-memory-plugin
为 DeepSeek Harness 提供人工记忆、自动对话保留以及图谱和向量排序召回的持久记忆插件。
dsh-cc-haha-dream
DeepSeek Harness 自动做梦插件:后台定期回顾近期会话与记忆,整合去重、更新过时、删除矛盾、修剪索引,支持 hybrid/volume 自动触发、/dream 手动执行与设置面板配置。