dsh-memory-eternal 0.4.2 → 0.4.3

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/README.md CHANGED
@@ -1,13 +1,34 @@
1
- # 记忆核心(dsh-memory-eternal
1
+ # 🧠 记忆核心(dsh-memory-eternal)— 给 DeepSeek Harness 装上「第二大脑」
2
2
 
3
3
  <p align="center">
4
4
  <img src="https://img.shields.io/badge/DeepSeek%20Harness-plugin-3B82F6" alt="DSH plugin" />
5
5
  <img src="https://img.shields.io/npm/v/dsh-memory-eternal" alt="npm version" />
6
6
  <img src="https://img.shields.io/github/stars/EternalNight996/dsh-memory-eternal?style=flat" alt="GitHub stars" />
7
7
  <img src="https://img.shields.io/github/license/EternalNight996/dsh-memory-eternal" alt="license" />
8
+ <img src="https://img.shields.io/badge/%E6%99%BA%E8%83%BD%E5%8E%BB%E9%87%8D-CJK%E6%A3%80%E7%B4%A2-10B981" alt="self-built" />
8
9
  </p>
9
10
 
10
- > 🧠 **给 DeepSeek Harness 装上「第二大脑」**:一款**自研独立**的 DSH 记忆插件,为任意 DeepSeek Harness 提供对话级长期记忆——对话结束后**自动**把值得长期复用的内容压缩成知识卡,写入本地 Markdown Vault(自研去重、自研 CJK 检索、可 git 管理);设置页提供**图形化知识库**:统计概览、CJK 检索、知识卡网格、自研知识图谱。Agent 通过 `memory_recall` 工具按需召回历史上下文。**一条命令安装,零人工干预,不改 dsh 源码。**
11
+ > 🧠 **对话结束自动沉淀、跨会话真实不失忆;召回只取相关小块,省 token、少噪音。** 全自研、零第三方记忆框架、不改 DSH 源码、一条命令安装——**为你装一个自己说了算的、可 git 管理的本地记忆库。**
12
+
13
+ <p align="center">
14
+ <strong>自研·去重·CJK 检索·知识图谱·双语·本地优先</strong> — ⭐ 觉得好用就点个 Star,让更多 DSH 用户用上这份「第二大脑」
15
+ </p>
16
+
17
+ <details>
18
+ <summary><b>⭐ 为什么值得 Star(30 秒看懂)</b></summary>
19
+
20
+ | 一句话 | 为什么打动你 |
21
+ | --- | --- |
22
+ | 🤖 **全自动,零人工** | 每轮对话结束自动判定+压缩成知识卡,不用点保存 |
23
+ | 🧬 **全自研,不抄框架** | 去重/CJK 检索/图谱/界面全部本仓库独立实现,逻辑可逐行核对 |
24
+ | 📚 **本地 Markdown Vault** | 普通 `.md`,可读、可编辑、可 git 版本管理、不被锁进私有库 |
25
+ | 🚫 **双层去重** | 词法 Jaccard + 语义去重,对 LLM 改写免疫,不堆重复卡 |
26
+ | 🔍 **CJK 感知检索** | 中文整词+字符 bigram,短查询也能命中长文 |
27
+ | 🕸 **秒级知识图谱** | 力导向/径向布局 + 图例过滤/时间维/框选/删除/合并,几千节点不卡 |
28
+ | 💾 **一键备份迁移** | 记忆库 MD/JSON 导出导入,异地迁移随便走 |
29
+ | ⚙️ **一条命令安装** | `dsh plugin --profile web add dsh-memory-eternal` |
30
+
31
+ </details>
11
32
 
12
33
  ---
13
34
 
@@ -228,6 +249,7 @@ dsh-memory-eternal/
228
249
 
229
250
  ## 📦 发布记录
230
251
 
252
+ - **v0.4.3**(待发布):记忆侧**省 token / 提质量**——**沉淀预筛**:turn-stopping 先做启发式「可复用信号」判定(结构化标记/决策/代码/事实关键词/列表密度),纯闲聊或无可复用内容**直接跳过、不触发 LLM**(省掉每轮昂贵的判定调用);**召回相关性 + 精简**:`memory_recall` 现按 `minScore` 过滤弱命中(降噪声)、注入片段截断到 130 字(降体积),召回更准、更省。
231
253
  - **v0.4.2**(已发布):修复 GitHub/npm 顶部产品演示 GIF 无法显示——压缩至 GitHub README 10MB 渲染阈值以下(8MB)。
232
254
  - **v0.4.1**(已发布):**Marketplace 收录标准**落地——声明 `package.json#dsh.marketplace`(`profiles:["web"]` 等),README 收录规则表对齐 dsh-marketplace / dsh-find-plugin / dsh-plugin-marketplace 的**自动扫描**机制;产品展示头部 GIF(`assets/screen/dsh-memory-eternal.gif`)置顶。
233
255
  - **v0.4.0**(已发布):图谱交互全面增强——**图例过滤**、**时间维着色**、**右键菜单**、**Shift 框选多选**、**单删/批量删除**、**多卡合并**、**一键导出 PNG**(预览:下载/另存为/复制/全屏);知识卡——**Markdown 渲染**、**长卡折叠**、**新卡角标**、**搜索命中高亮**、**卡片行删除**、**无限滚动懒加载**、最近/标题/热点排序、自定义滚动条;**相似度关联建议**(similar 边);**记忆库导出/导入**(MD/JSON 备份,导出可选**自选位置**);操作**顶部醒目绿/红 toast**(反馈结果 + 导出位置/文件名);默认视图与节点调大。
package/index.js CHANGED
@@ -188,11 +188,12 @@ export function apply(ctx, config) {
188
188
  const query = String(args.query || '').trim()
189
189
  if (!query) return '(未提供检索词)'
190
190
  const limit = Math.min(Math.max(Number(args.limit) || 5, 1), 20)
191
- const hits = await search(vaultDir(), query, { limit })
191
+ const hits = await search(vaultDir(), query, { limit, minScore: 2 })
192
192
  if (hits.length === 0) return `记忆库中没有与「${query}」相关的内容。`
193
193
  const lines = hits.map((h, i) => {
194
194
  const tags = h.tags.length ? ` [${h.tags.join(', ')}]` : ''
195
- return `### ${i + 1}. ${h.title}${tags}\n路径:${h.path}\n${h.summary || ''}`
195
+ const snippet = String(h.summary || '').replace(/\s+/g, ' ').trim().slice(0, 130)
196
+ return `### ${i + 1}. ${h.title}${tags}\n路径:${h.path}\n${snippet}`
196
197
  })
197
198
  return `从记忆核心检索到 ${hits.length} 条相关卡片:\n\n${lines.join('\n\n')}`
198
199
  },
package/lib/capture.js CHANGED
@@ -19,6 +19,19 @@ export const DEDUP_THRESHOLD = 0.62
19
19
  /** 参与语义去重的近邻卡片数上限(控制 token)。 */
20
20
  export const DEDUP_NEIGHBORS = 8
21
21
 
22
+ // 沉淀预筛:仅当对话含「可复用」信号时才调用 LLM,避免对纯闲聊/寒暄发起昂贵的 LLM 判定。
23
+ const DURABLE_SIGNALS = /(#{1,3}\s|```|\[\[|\]|\(https?:|\.(md|ts|js|py|json|yml|yaml|sh|sql)\b|`|\b\d{2,}\b|选择|决定|采用|方案|结论|原因|根因|问题|解决|修复|报错|错误|教训|架构|设计|配置|部署|流程|步骤|算法|原理|函数|接口|参数|命令|依赖|版本|坑|踩|优化|性能|数据库|索引|模型|token|推荐|偏好|约定|规范)/
24
+
25
+ /** 判断一段对话是否值得送 LLM 判定(省 token 的启发式预筛)。 */
26
+ export function looksDurable(text) {
27
+ const t = String(text || '')
28
+ if (t.trim().length < 120) return false
29
+ if (DURABLE_SIGNALS.test(t)) return true
30
+ // 列表/编号密度:≥2 个列表项且有一定长度 => 大概率是结构化知识
31
+ const items = (t.match(/(^|\n)\s*[-*]\s+/gm) || []).length + (t.match(/(^|\n)\s*\d+[.、)]\s+/gm) || []).length
32
+ return items >= 2 && t.trim().length >= 160
33
+ }
34
+
22
35
  /**
23
36
  * 用当前模型把一段对话压缩成知识卡(或判定不值得保存 / 应追加到已有卡)。
24
37
  * @param llm - dsh 的 llm 服务(ctx.get('llm'))
@@ -30,6 +43,7 @@ export const DEDUP_NEIGHBORS = 8
30
43
  export async function summarizeTurn(llm, route, conversation, opts = {}) {
31
44
  const text = String(conversation || '').trim()
32
45
  if (text.length < 120) return null // 太短,没有沉淀价值
46
+ if (!looksDurable(text)) return null // 启发式预筛:无可复用信号则跳过 LLM 判定(省 token)
33
47
 
34
48
  const existing = Array.isArray(opts.existing) ? opts.existing.slice(0, DEDUP_NEIGHBORS) : []
35
49
  const existingBlock = existing.length
package/lib/vault.js CHANGED
@@ -270,8 +270,8 @@ export async function appendUpdate(root, rel, updateText, { threshold = 0.62 } =
270
270
  return { ok: true, path: rel, kind: meta.kind || 'knowledge', updated: now }
271
271
  }
272
272
 
273
- /** 检索:整词/中文 bigram 命中 path + 正文。返回卡片摘要(带命中度)。 */
274
- export async function search(root, query, { limit = 30 } = {}) {
273
+ /** 检索:整词/中文 bigram 命中 path + 正文。返回卡片摘要(带命中度)。minScore 过滤弱命中。 */
274
+ export async function search(root, query, { limit = 30, minScore = 0 } = {}) {
275
275
  const q = String(query || '').trim()
276
276
  if (!q) return []
277
277
  const cards = await listCards(root)
@@ -290,7 +290,7 @@ export async function search(root, query, { limit = 30 } = {}) {
290
290
  for (const term of wanted) {
291
291
  if (haystack.includes(term.toLowerCase())) score += 1
292
292
  }
293
- if (score > 0) {
293
+ if (score > 0 && score >= minScore) {
294
294
  out.push({ ...card, score })
295
295
  }
296
296
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-memory-eternal",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "记忆核心(Memory Eternal):自研的 DeepSeek Harness 记忆插件,不移植任何既有记忆框架——对话结束后自动沉淀知识卡到本地 Markdown Vault(自研去重、自研 CJK 检索、可 git 管理),设置页提供图形化知识库(统计 / 搜索 / 知识图谱 + 侧边栏一键弹窗),Agent 通过 memory_recall 工具按需召回历史上下文。零人工干预。",
5
5
  "license": "MIT",
6
6
  "repository": {