본문으로 건너뛰기
L

dsh-memory-domains

lmx494/dsh-memory-domains

Human-curated agent memory library for DeepSeek Harness, organized as domain-scoped knowledge cards. Session trajectories are distilled by the AI into draft memory cards; a human then reviews and approves each one before it is stored, and the AI never writes to the store on its own. Entry types are mistake, fact, skill and pref; every card keeps its source, reviewer and status, and the memory_search tool serves them back on demand. Its HTTP routes have no DSH access check, so a web page open in your browser could call them.

설치

dsh plugin --profile web add github:lmx494/dsh-memory-domains

README

dsh-memory-domains

中文文档

本项目授权 DSH Plugin 收录本仓库,并在该站展示插件信息。

Install this and your agent stops forgetting what it already learned — a human-curated memory library where every entry is a domain card you can search, revise, and retire. Nothing enters the store without your approval.

A human-curated agent memory library — a local plugin for DeepSeek Harness (DSH), organized as a domain-centric knowledge base.

Core discipline: the AI never writes memories on its own. Organizing, promoting, and archiving are all triggered by explicit user actions; the AI only drafts, and nothing enters the store until a human approves it.

What it is

Manages "context memories" (memories injected into context) across four types:

TypeContentExample
mistake lessonNegative knowledge: what not to do"Baud rate must be 115200; 9600 garbles output"
fact factDomain knowledge"MCU register base address 0x4000_0000"
skill skillProcess/template"Five-step procedure for integrating a new sensor"
pref preferenceUser conventions"Reply in Chinese, conclusion first"

Each memory also carries a priority priority: high (★ high — pitfalls / hard constraints / strong preferences) or default normal. The AI suggests it when drafting and humans can change it (in the accept picker, the edit form, or via the toggle on stored cards); memory_search applies a ×1.5 ranking boost to high entries.

Three-level organization:

  • Domains (primary unit): domains/<slug>.jsonl + a domains.json registry. Domains are created manually by the user — name + description are required; the description is the signpost agents read during retrieval (what it covers / typical keywords / what it doesn't cover), and can be AI-drafted then human-confirmed. A memory belongs to exactly one domain.
  • Global memories: global.jsonl — cross-domain knowledge plus hand-picked promotions from domains (copy + provenance, original kept)
  • Sessions: demoted to a source role — trajectories → AI drafts → human picks a domain or global on acceptance; session cards serve as the "organize" entry point and a provenance view of "which memories this session contributed"

Lifecycle: draft candidates (staged in candidates/) → human review (editable; AI suggests a domain based on existing domains) → accept into a domain or global → archive / restore / delete while in use. "Don't remember what's useless" is a manual human act — the AI only nominates, never decides.

Features

  • Domain card wall: domain cards (name + description + entry count) + a global-library card + "+ New domain"; the session section below is the organize entry; the search box filters both domain names and session titles
  • Create/edit domains: name + description required; "✨ AI draft description" expands a name into a standardized description
  • Organize memories: the AI reviews session trajectories (including tool calls/errors) and drafts memory cards into the review area; the prompt includes the domain list so the AI can suggest an owning slug
  • Human review flow: drafts are editable → on ✓ accept, pick a target domain or global (AI suggestion preselected) / ✗ discard
  • Promote to global: one-click copy of a domain entry into the global library with promoted_from provenance; scope=all searches deduplicate automatically
  • memory_search tool: agent-facing read-only memory retrieval — BM25 ranking + CJK bigram recall, results include a domain map (slug/name/description), scope=domain&domain=<slug> for focused search
  • 🔍 Discover projects: one-click GitHub search per domain from the domain detail page — the AI distills the domain name+description into 3–5 queries, hits the GitHub repo search (stars-sorted, deduplicated), results are clickable cards; on-demand only, githubToken/GITHUB_TOKEN raises rate limits

Architecture

index.js          host half: apply(ctx) → memory_search tool + /memory/api/* routes
client.js         frontend half: ModuleLoader bundle, zero-build hand-written React
  ├── conversation.composer.dock  "🧠 记忆库" button above the input box
  └── sidebar.footer.action       sidebar entry
lib/
  ├── session-log.js  DSH session-log decoding (multi-frame zstd, tool/call+result extraction)
  ├── store.js        jsonl storage: domains/global/candidates + domain registry + migration + search
  ├── llm.js          OpenAI-compatible gateway call (dsh-our-free-model built-in openai-gateway)
  └── review.js       trajectory → AI-drafted memory cards (domain list injected for ownership hints)
cordis.patch.yml   bundle patch: inserts the plugin into the profile roster + generic default config

Data directory ~/.dsh/memory-domains/:

domains.json              domain registry [{slug,name,desc,created_at}]
domains/<slug>.jsonl      domain memories
global.jsonl              global memories
candidates/<sid>.jsonl    pending drafts
sessions/<sid>.jsonl      legacy session memories (migration source only; auto-migrated at startup, no longer written)
session-meta.json         session title/message-count cache (background warm-up, speeds up listing)
settings.json             per-machine config overrides (not committed, see below)

Directory migration: the legacy data directory ~/.dsh/memory-book/ is renamed wholesale to ~/.dsh/memory-domains/ (including settings.json) on first startup — runs once.

Data migration: on first startup, legacy sessions/*.jsonl entries are migrated automatically — entries with a domain tag join the same-named domain (placeholder description to fill in), untagged entries go global; idempotent, runs once.

Install

Option 1: dshmarket marketplace / dsh plugin (recommended)

The plugin is published on npm. In the app's Settings → Plugins → Discover, search dsh-memory-domains for one-click install; or via CLI:

dsh plugin --profile desktop add dsh-memory-domains

You can also install straight from GitHub:

dsh plugin --profile desktop add github:lmx494/dsh-memory-domains

Option 2: link local development

Add the dependency to the DSH profile's package.json and list it in dsh.profile.bundles:

"dependencies": { "dsh-memory-domains": "link:<repo path>" },
"dsh": { "profile": { "bundles": ["dsh-memory-domains"] } }

and create a junction/symlink in node_modules/ pointing at this directory. After restarting DSH, the "🧠 记忆库" button appears above the input box.

Two-minute start

  1. Install it (command above) and restart DSH. The "🧠 记忆库" button appears above the input box.
  2. Open it and create one domain — its description is a signpost, so write it as "does this task belong here?" (e.g. "STM32 firmware bring-up and motor control"). Domains are the retrieval unit.
  3. Finish a session that taught you something. Click organize on that session: the AI drafts memory cards from the trajectory, and nothing is stored until you approve each card.
  4. When a future session needs it, memory_search serves the cards back — the agent gets the lesson without re-reading the whole transcript.

That is the whole loop: one session → draft → you approve → the next session benefits. The AI never writes to the store on its own.

Configuration

cordis.patch.yml carries only generic defaults. Memory organizing goes through an OpenAI-compatible gateway — by default the dsh-our-free-model built-in channel-pack openai-gateway (127.0.0.1:8326, whose model pool is that plugin's models); any OpenAI-compatible endpoint works. Per-machine overrides go to ~/.dsh/memory-domains/settings.json (highest priority, not committed):

{
  "baseUrl": "http://127.0.0.1:8326/v1",
  "apiKeyFile": "C:/Users/<you>/.dsh/openai-gateway/api-key",
  "reviewModel": "<model supported by your gateway>",
  "reviewTimeoutMs": 180000
}

All keys are optional and fall back to code defaults; apiKey can replace apiKeyFile with an inline key (do not commit it anywhere). githubToken (or the GITHUB_TOKEN env var) raises the rate limit for "Discover projects" GitHub search — anonymous works too, just more throttled.

API

Same-origin /memory/api/* (the host mounts the prefix under the /api/ namespace; non-GET/HEAD requests are checked for same-origin Origin + loopback Host to block cross-site browser writes):

MethodPathDescription
GET/api/sessionsSession list (pending>0 means titles are still warming up in background)
GET/POST/api/domains*Domain list / create / update / delete
POST/api/domains/draftAI-draft a domain description {name} → {desc}
POST/api/discoverDomain profile → GitHub project discovery {domain: slug} → {queries, repos, errors}
GET/api/memories?scope=&domain=&session=scope=domain&domain=<slug> / global / all; session= filters by source session
GET/POST/api/candidates*Draft list / accept(with target) / reject / update
POST/api/reviewAsync organize {session} → {job}
GET/api/review/status?job=Job status polling
POST/api/promote /api/archive /api/delete /api/createEntry operations

Design boundaries

  • Humans manage memories; the AI only drafts: every write path (organize/accept/promote/archive/delete/create-domain) is triggered by a UI button or explicit user action; memory_search is read-only
  • Domains are the knowledge unit: one memory, one domain; cross-domain general knowledge goes global, avoiding multi-copy drift
  • Domain description is the signpost: required, written for the judgment "does this task belong to this domain"; retrieval relies on the domain map + keywords, no vector search
  • File-backed and auditable: plain-text jsonl — diffable, hand-editable, version-controllable; no vector DB, no embedding service
  • Fail-open: any frontend failure never affects the main DSH flow

Relationship to workflow-engine

workflow-engine's mistakes.jsonl + learn.js is the same idea applied to one domain (judge critique → AI draft → human accept). This plugin generalizes it into a universal agent memory layer: the trajectory source changes from "engine run archives" to "any DSH session", the organization upgrades from "session/global two-level" to a "domain/global" knowledge base, and retrieval changes from "pack tools" to memory_search. The two jsonl formats are isomorphic and can be migrated between each other.


中文文档

本项目授权 DSH Plugin 收录本仓库,并在该站展示插件信息。

装上它,agent 就不会再重复犯已经学过的错——人审策展的记忆库,每条都是一张可检索、可修改、可归档的领域卡;没有人点头,任何东西都进不了库。

人审策展的 agent 记忆库 —— DeepSeek Harness (DSH) 本地插件,领域中心的知识库形态。

核心纪律:AI 绝不自主写入记忆。整理、升级、归档全部由人点按钮触发;AI 只负责起草,人审后才入库。

它是什么

管理"注入上下文的记忆"(上下文记忆),覆盖四种类型:

类型内容例子
mistake 教训负知识:什么不能做"波特率必须用 115200,9600 会乱码"
fact 事实领域知识"MCU 寄存器基址 0x4000_0000"
skill 技能流程/模板"接新传感器的五步流程"
pref 偏好用户约定"输出用中文,先给结论"

每条还带优先级 priority:high(★高,踩坑/硬约束/强偏好)或缺省 normal。AI 起草时建议、人审时可改(入库选择器/编辑表单/入库后卡片上的开关都能调);memory_search 对 high 条目 ×1.5 加权排序。

三级组织:

  • 领域(主单元):domains/<slug>.jsonl + domains.json 注册表。领域由用户手动创建,名称+描述必填——描述是 agent 检索时的路标(覆盖什么/典型关键词/不覆盖什么),可点「✨ AI 起草」让 AI 扩写后人工确认。一条记忆只归一个领域。
  • 全局记忆:global.jsonl —— 跨领域通用知识 + 从领域手动「升级全局」的精选(复制+溯源,不删原件)
  • 会话:退居来源角色——轨迹 → AI 起草 → 人审时选领域或全局入库;会话卡片用于「整理」入口和"本会话贡献了哪些记忆"的溯源浏览

生命周期:整理草稿(candidates/ 暂存)→ 人审(可编辑,AI 会按已有领域建议归属)→ 选领域/全局入库 → 使用中可归档/恢复/删除。"没用的就不要记住"由人手动执行,AI 只提名不决策。

功能

  • 领域卡片墙:领域卡(名称+描述+条目数)+ 全局库卡 + 「+ 新建领域」;下方会话区是整理入口;搜索框同时过滤领域名和会话标题
  • 新建/编辑领域:名称+描述必填;「✨ AI 起草描述」按名称自动生成规范描述
  • 整理记忆:AI 回顾会话轨迹(含工具调用/报错),起草记忆卡到待审区;prompt 里附领域清单,AI 会建议归属 slug
  • 人审流:草稿可编辑 → ✓入库时选择目标领域或全局(默认选中 AI 建议)/ ✗丢弃
  • 升级全局:领域条目一键复制进全局库,带 promoted_from 溯源;scope=all 检索自动去重
  • memory_search 工具:agent 检索记忆(只读),BM25 排序 + CJK bigram 召回,结果附领域地图(slug/名称/描述),可用 scope=domain&domain=<slug> 精搜
  • 🔍 发现项目:领域详情页一键按领域画像搜 GitHub——AI 把领域名称+描述蒸馏成 3~5 个检索词,走 GitHub repo 搜索(stars 排序、去重),结果卡片可点;按需触发不打扰,配 githubToken/GITHUB_TOKEN 可提额

架构

index.js          host 半区:apply(ctx) → memory_search 工具 + /memory/api/* 路由
client.js         前端半区:ModuleLoader bundle,零构建手写 React
  ├── conversation.composer.dock  输入框上方「🧠 记忆库」按钮
  └── sidebar.footer.action       侧栏入口
lib/
  ├── session-log.js  DSH 会话日志解码(多帧 zstd,含 tool/call+result 提取)
  ├── store.js        jsonl 存储:domains/global/candidates + 领域注册表 + 迁移 + 检索
  ├── llm.js          OpenAI 兼容网关调用(dsh-our-free-model 内置 openai-gateway)
  └── review.js       轨迹→AI起草记忆卡(注入领域清单供归属建议)
cordis.patch.yml   bundle patch:把插件插进 profile 名册 + 通用默认 config

数据目录 ~/.dsh/memory-domains/:

domains.json              领域注册表 [{slug,name,desc,created_at}]
domains/<slug>.jsonl      领域记忆
global.jsonl              全局记忆
candidates/<sid>.jsonl    待审草稿
sessions/<sid>.jsonl      存量会话记忆(仅迁移来源,启动时自动迁移后不再写入)
session-meta.json         会话标题/消息数缓存(后台预热,落盘加速)
settings.json             本机覆盖配置(不进 git,见下)

目录迁移:旧版数据目录 ~/.dsh/memory-book/ 在首次启动时自动整体改名为 ~/.dsh/memory-domains/(含 settings.json),只跑一次。

存量迁移:首次启动自动把旧版 sessions/*.jsonl 条目迁移——带 domain 标签的归入同名领域(描述占位待补),无标签的进全局;幂等,只跑一次。

安装

方式一:dshmarket 市场 / dsh plugin(推荐)

插件已发布 npm。在 App 的 Settings → Plugins → Discover 搜 dsh-memory-domains 一键安装;或命令行:

dsh plugin --profile desktop add dsh-memory-domains

也可以直接从 GitHub 源安装:

dsh plugin --profile desktop add github:lmx494/dsh-memory-domains

方式二:link 本地开发

DSH profile 的 package.json 加依赖并列入 dsh.profile.bundles:

"dependencies": { "dsh-memory-domains": "link:<本仓库路径>" },
"dsh": { "profile": { "bundles": ["dsh-memory-domains"] } }

并在 node_modules/ 建 junction/symlink 指向本目录。重启 DSH 后输入框上方出现「🧠 记忆库」。

两分钟上手

  1. 装上(上面的命令),重启 DSH。输入框上方出现「🧠 记忆库」。
  2. 打开它,建一个领域——领域描述是路标,按「这个任务归不归这里」来写(比如「STM32 固件上电与电机控制」)。领域是检索的单位。
  3. 跑完一个学到了东西的会话,在该会话上点整理:AI 从轨迹起草记忆卡,你不逐条点头就一条都不入库。
  4. 以后遇到相关会话,memory_search 把这些卡喂回给 agent——它拿到教训,不必重读整段对话。

循环就这么多:一个会话 → 起草 → 你点头 → 下一个会话受益。AI 绝不自主写入。

配置

cordis.patch.yml 只带通用默认值。整理记忆走 OpenAI 兼容网关——默认对准 dsh-our-free-model 内置的 channel-pack openai-gateway(127.0.0.1:8326,模型池即该插件的模型);也可指向任何 OpenAI 兼容端点。本机差异配置写到 ~/.dsh/memory-domains/settings.json(优先级最高、不进 git):

{
  "baseUrl": "http://127.0.0.1:8326/v1",
  "apiKeyFile": "C:/Users/<you>/.dsh/openai-gateway/api-key",
  "reviewModel": "<你的网关支持的模型>",
  "reviewTimeoutMs": 180000
}

所有键都可省略走代码默认值;apiKey 可代替 apiKeyFile 直接内联密钥(不建议提交进任何 git)。githubToken(或环境变量 GITHUB_TOKEN)给「发现项目」的 GitHub 搜索提额,匿名也能用只是限流低。

API

同源 /memory/api/*(宿主把前缀路由挂在 /api/ 命名空间下;非 GET/HEAD 校验 Origin 同源 + Host loopback,防浏览器跨站写入):

方法路径说明
GET/api/sessions会话清单(pending>0 表示标题还在后台预热)
GET/POST/api/domains*领域列表 / 创建 / update / delete
POST/api/domains/draftAI 起草领域描述 {name} → {desc}
POST/api/discover领域画像 → GitHub 项目发现 {domain: slug} → {queries, repos, errors}
GET/api/memories?scope=&domain=&session=scope=domain&domain=<slug> / global / all;session= 按来源会话过滤
GET/POST/api/candidates*草稿列表 / accept(带目标) / reject / update
POST/api/review异步整理 {session} → {job}
GET/api/review/status?job=job 状态轮询
POST/api/promote /api/archive /api/delete /api/create条目操作

设计边界

  • 人管记忆,AI 只起草:所有写入路径(整理/入库/升级/归档/删除/建领域)都由 UI 按钮或用户显式调用触发;memory_search 只读
  • 领域是知识库单元:一条记忆单归属;跨领域通用的走全局,避免多副本不同步
  • 领域描述即路标:描述必填且面向"任务是否属于此领域"的判断来写;AI 检索靠领域地图+关键词,不做向量检索
  • 文件化可审计:jsonl 纯文本、可 diff、可手改、可版本控制;无向量库、无嵌入服务
  • fail-open:前端任何环节失败都不影响 DSH 主流程

与 workflow-engine 的关系

workflow-engine 的 mistakes.jsonl + learn.js 是同一思想的领域实例(裁判 critique → AI 起草 → 人审入库)。本插件把它泛化成通用 agent 记忆层:轨迹源从"engine run 存档"换成"任意 DSH 会话",组织从"会话/全局两级"升级为"领域/全局"知识库,检索从"pack 工具"换成"memory_search"。两者的 jsonl 格式同构,可互相迁移。

관련 플러그인