@hy-sde-org/dsh-memory

中文文档
0.2.1-rc.5发布于 2026/11/01MITTypeScriptES Module

Agent-curated long-horizon memory (ctx.memory) for DeepSeek Harness: durable project-scoped memory banks with a provider registry and a shipped local backend — a standalone plugin with no upstream harness changes required.

原始使用文档
文档目录8 节
  1. Install
  2. Direct from npm (published)
  3. From the git checkout (pre-publish / development)
  4. Layout
  5. Service API
  6. memory:// internal URLs
  7. Config (the memory row)
  8. Tests

@hy-sde-org/dsh-memory

Agent-curated long-horizon memory for DeepSeek Harness — the ctx.memory service and its provider registry, ported from the @oh-my-pi coding-agent memory surface (the port lives in the hy-sde fork). Memory is durable, project-scoped data the agent curates itself with the retain/recall/reflect/memory_edit/learn tools (shipped by @hy-sde-org/dsh-tool-memory), and it is reloaded at the start of the next session through prompt injection. It complements DSH's session-query and compaction instead of overlapping them: those replay conversation history, this bank answers "what did we decide / prefer / learn here?" across sessions.

This is a standalone plugin build: the harness integration (the host-plane memory row) ships in cordis.patch.yml, and the agent-plane tools live in @hy-sde-org/dsh-tool-memory. Nothing in the upstream DeepSeek Harness (dsh-v0.2.0-rc.2 and later) needs to change.

Only the local backend ships. The registry keeps the seam open for Hindsight/Mnemopi-style providers later — a future provider registers one MemoryBackend and the same tools work unchanged.

Install

pnpm install --global @deepseek-ai/dsh

Direct from npm (published)

Both packages are published on the npm registry under the hy-sde-org organization (@hy-sde-org/dsh-memory and @hy-sde-org/dsh-tool-memory, version 0.2.0-rc.2). Add the service, then mount the tools via a preset:

# one command; the tool package comes in as a transitive dependency
dsh plugin --profile web add @hy-sde-org/dsh-memory @hy-sde-org/dsh-tool-memory

Then copy examples/agent-preset/ from the installed package (or this repo) to ~/.dsh/.agent-presets/<id>/ and select it in the Web UI preset picker (or dsh agent). The preset row uses @hy-sde-org/dsh-tool-memory.

From the git checkout (pre-publish / development)

git clone [email protected]:hy-sde/dsh-plugins.git
cd dsh-plugins
pnpm install
pnpm --filter @hy-sde-org/dsh-memory build

MEMORY_TGZ="$(cd dsh-memory/packages/memory && pnpm pack --pack-destination /tmp | tail -n 1)"
TOOLMEMORY_TGZ="$(cd dsh-memory/packages/tool-memory && pnpm pack --pack-destination /tmp | tail -n 1)"
dsh plugin --profile web add "$MEMORY_TGZ" "$TOOLMEMORY_TGZ"

Layout

The service is host-plane: the store is durable project data that crosses sessions, so cordis.patch.yml inserts one row into the profile; the per-session tools resolve it. Data lives under <harness home>/memories/<project>/ where <project> is an encoded absolute cwd — one memory root per project, shared by every session and tool on it.

Each project root holds three artifacts:

  • bank.jsonl.zstd — editable working entries written by retain (id, content, context, source, importance, timestamps, active flag). Backs memory_edit. On-disk container is the same zstd frame format the harness session logs use: each save batch is one checksummed Zstandard frame (concatenated, append-only, self-healing). The pre-rename plaintext bank.jsonl is still read and is migrated on the first write; set compression: 'none' in LocalMemoryConfig for the original line-append format. The codec ships inside this package (/frame-codec subpath, node:zlib-only).
  • learned.md — newest-first, deduped, capped (100) lesson bullets written by learn; the same format and normalization omp keeps. Survives consolidation; learn writes are injection-neutralized and secret-redacted.
  • memory_summary.md — optional consolidated summary (hand- or tool-maintained) that recall, reflect, and prompt injection surface.

Service API

const memory = ctx.memory                       // MemoryService
await memory.save({ cwd }, { content, context, source, importance })
await memory.learn({ cwd }, { content, context })
await memory.search({ cwd }, 'query', { limit: 10 })
await memory.edit({ cwd }, 'update' | 'forget' | 'invalidate', { id, content, importance, replacementId })
await memory.summaries({ cwd })                 // { summary?, learned?, block }
await memory.status({ cwd })
await memory.clear({ cwd })

Backends register into the service: memory.register(backend) returns a disposer, and memory.resolve() returns the configured (default: first) backend. Mutations emit memory/change ({ cwd }) so in-process consumers can invalidate caches.

A MemoryBackend is a dozen methods over @hy-sde-org/dsh-memory/types; the shipped one, LocalMemoryBackend, is pure-node (node:fs) with an in-process per-file write chain so concurrent saves from sibling sessions can never drop each other's writes.

memory:// internal URLs

When the host composition mounts @hy-sde-org/dsh-internal-urls (the shared registry behind the read/grep tools), this plugin registers a memory:// scheme in ctx.internalUrls — once per process, via ctx.inject, and it is a graceful no-op in compositions without the registry. Every resolved resource is immutable: true: agents never rewrite durable memory through a file-shaped URL; memory_edit is the mutation surface.

Two URL forms:

  • memory://root — the project's consolidated memory overview (summary + learned lessons + working bank, the same block prompt injection uses). An empty project reads a "Project memory is empty" pointer instead.
  • memory://<id> — one stored entry in full, with a metadata header (id, source, importance, timestamp, readonly). Ids are the same ones recall/reflect surface: bank rows by their m_* id, lessons as lesson_<hash> (read-only), and the consolidated summary as summary_0 (read-only). Reads are scoped to the calling session's project (cwd).

Corrective errors, following the upstream oh-my-pi (coding-agent/src/internal-urls/memory-protocol.ts) HINDSIGHT_UNADDRESSABLE pattern:

  • not addressable — the selected backend has no readEntry (a non-addressable store): "The … memory backend is not addressable via memory://<id>", pointing back at recall/reflect.
  • not found — the id does not exist in this project (or was retired): "Memory … does not exist in this project", pointing at recall/memory_edit.
  • a missing namespace, a missing cwd, an unregistered backend, and paths under root/an id all get their own corrective messages.

Completions: complete() returns root plus every addressable entry id (listEntries, newest first, capped at 50) with a one-line content preview; a backend that only implements readEntry falls back to a <id> placeholder, and one with neither completes only root. The memory:// scheme never takes a path (backend-shaped, not file-shaped).

Config (the memory row)

KeyDefaultMeaning
root<harness home>/memoriesMemory root (~/$HOME expand).
backendfirst registeredBackend id the service delegates to.
defaultImportance0.7Baseline importance when a save omits it.
searchLimit10Default result cap for one search.

Per-entry caps: bank content 4000 chars, bank context 800, lesson content 2000, lesson context 400, lessons capped at 100 newest-first. All stored text passes injection-neutralization (control chars, </backticks, ~~~ fences) then secret-redaction, on write and on read.

Tests

pnpm -r --filter @hy-sde-org/dsh-memory test

版本与发布记录

@hy-sde-org/dsh-memory 共发布 11 个版本,首次发布于 2026/08/26;过去 12 个月发布了 11 个版本。

版本发布日期距今
0.2.1-rc.5latest2026/11/012 天前
0.2.1-rc.32026/10/259 天前
0.2.1-alpha.42026/10/1618 天前
0.2.1-alpha.22026/10/1321 天前
0.2.0-rc.22026/10/031 个月前
0.1.7-rc.22026/09/291 个月前

关于 @hy-sde-org/dsh-memory 的常见问题

@hy-sde-org/dsh-memory 是什么?

用于DeepSeek Harness的代理管理的长期内存(ctx.memory):持久的项目范围内的内存库,具有提供者注册表和已交付的本地后端-一个独立的插件,不需要更改上游的Harness。

如何安装 @hy-sde-org/dsh-memory?

在项目目录运行 npm install @hy-sde-org/dsh-memory,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@deepseek-ai/cordis(~4.0.5)、@hy-sde-org/dsh-internal-urls(^0.2.1-rc.5)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@hy-sde-org/dsh-memory 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@hy-sde-org/dsh-memory 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@hy-sde-org/dsh-memory 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.19.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@hy-sde-org/dsh-memory 可以商用吗?

@hy-sde-org/dsh-memory 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@hy-sde-org/dsh-memory 还在维护吗?

最新版本 0.2.1-rc.5 发布于 2026/11/01(2 天前);至今共发布 11 个版本,其中过去 12 个月发布了 11 个;首次发布于 2026/08/26。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。