dsh-memory-delta: Cross-Session Long-Term Memory with Automatic Injection and Only Pushing Changes

Preface

When starting a new session with DSH or a similar AI coding assistant, background, preferences, and already-decided conclusions often need to be re-explained. Occasionally writing key points into one or two Markdown files leads to ever-growing files, where every round incurs context costs, and outdated conclusions are hard to retire.

Spec-driven tools like OpenSpec address the problem of “code deviating from the plan,” but they are pull: the model has to be reminded to read the spec, and new sessions don’t automatically carry memory. dsh-memory-delta takes the push approach: at the start of a session, it distills what the model needs to know and feeds it in, and tries to push only the increment relative to the previous round; details remain available for on-demand retrieval. Below we introduce what it is, how to install it, and how to use it.

What Is This

dsh-memory-delta is a plugin for DeepSeek Harness (DSH) that also provides a zero-dependency standalone CLI mem. The maintainer’s repository on GitHub is lpf20200901/dsh-memory-delta (Gitee is a read-only mirror). The design borrows the spec / change / archive discipline from OpenSpec, but in the opposite direction: memory is pushed into the session rather than waiting for the agent to pull it.

The plugin is categorized as “memory” in community catalogs like SkillHub; the DSH ecosystem is “everything is a plugin,” and community sites have no official affiliation with DeepSeek / High-Flyer.

Storage Hierarchy and Write Rules

The memory store (default <session cwd>/memory, can be overridden via config or $DSH_MEMORY_ROOT) is organized by process stage and content type:

Directory Stage Content Who can write Injected?
inbox/ Candidate Conclusions the model thinks are worth keeping Model only (memory_write) No
facts/ Active Pitfalls and workarounds: environment constraints, tool behavior, real failures and fixes Human promote only Yes
decisions/ Active Conventions and choices with rationale Human promote only Yes
archive/ Archived Superseded or no-longer-applicable entries Archive operation No (searchable, restorable)

Main flow: model writes to inbox only → human promotes to facts or decisions → retired to archive. When unsure which side to put something: if “it no longer holds if the world changes tomorrow,” lean toward facts/; if only you can overturn it, lean toward decisions/.

mem init generates README.md, memory.config.json, index.md, journal.md, etc., in the memory directory and explains the meaning of each layer. Entries are Markdown with frontmatter, and status includes active / superseded / expired; only one active entry per scope+key is allowed, and updates require explicit --supersedes, to prevent incorrect conclusions from entering the permanent injection layer.

Core Capabilities

Differential Injection and Byte Budget

The injection layer has a hard byte budget (determined by the store’s memory.config.json#injectBudget, commonly defaulting to around 3072). Each standing entry carries a 12-character content hash; the plugin remembers the previous round’s state in a side-car file <harness home>/storages/dsh-memory-delta/inject-state/<session-id>.json, and thereafter only pushes additions, updates, and deletions; when there are no changes, no content is injected. The README compares this with instructions-style plugins that lack diff, which repeatedly inject the entire file after multiple small edits, wasting tokens.

The first round injects all active entries as the baseline; subsequent rounds only push the delta. The diff state is stored in a side-car, not stuffed into the session message’s source, to comply with the DSH session-format whitelist.

DSH-Side Tools and Interface

Capability Description
memory_search Relevance-ranked retrieval over facts / decisions / inbox / archive / journal etc.; Chinese matched by bigram; results returned to the model as the tool’s render text
memory_write Writes only to inbox, cannot modify the standing layer
Distillation reminder After a session has proceeded for several steps and memory is already up to date, reminds the user to record conclusions via memory_write; once per session, and carries no state that would pollute the diff
Due review When verify_when is due, reminds the human to review; the model can only write new conclusions to inbox
Bundled skill Registers /dsh-memory-delta when skill: true by default; can be disabled with skill: false
Sidebar “Memory” Requires integration with something like dsh-better-sidebar; provides grouping, search, promote / archive, etc. (via POST /dsh-memory-delta/action, can disable write operations with allowWrite: false)

The plugin directly imports the store module shared with the CLI and does not spawn mem inside DSH (the sandbox has restrictions on named pipes).

CLI mem

Shares the same store and sorting logic as the plugin. Typical commands (excerpt):

mem init --root ./memory --scope "workspace:/path/to/project"

mem new --type fact --id win-update-cache --key disk-cleanup \
        --conclusion "Cleaning the update cache reclaimed nothing measurable" \
        --reason "Directory emptied but free space did not move" --tags windows,disk

mem promote win-update-cache
mem promote win-update-cache-v2 --supersedes win-update-cache

mem recall <keywords> [--where all|facts|decisions|inbox|archive|journal|sessions|index]
mem validate [--fix]
mem inject [--json] [--budget 3072]
mem due [--within N] [--json]

Globally install the CLI:

npm i -g dsh-memory-delta

Requires Node.js >= 20. The package’s current version is 1.3.4, license MIT.

Installation and Activation

The README emphasizes two common misconfigurations that silently fail: putting the package into dsh.profile.bundles in package.json (which gets overwritten by the marketplace registry at startup); writing bare entries in cordis.patch.yml without wrapping them under - insert:.

Install from npm / DSH Command

The plugin is published to npm, and DSH can install it from the registry:

cd ~/.dsh && dsh plugin --profile web add dsh-memory-delta

The community plugin marketplace entry is lpf20200901/dsh-memory-delta; installing from the marketplace uses the bundled patch included in the package; this patch intentionally does not set maxBytes, and the injection limit is determined by the store’s memory.config.json.

Local Development / Manual Installation

DSH_HOME on desktop is commonly %APPDATA%\dsh-desktop\harness (on Linux etc., use the actual harness home; resolution chain: config.stateDir → ctx.dshHomePath → $DSH_HOME → ~/.dsh).

  1. Copy the package into the profile’s node_modules, e.g.:
   <DSH_HOME>\profiles\web\node_modules\dsh-memory-delta\
       package.json
       bin\mem.mjs
       src\plugin.mjs  src\hook.mjs  src\planner.mjs
  1. Append to <DSH_HOME>\profiles\web\cordis.patch.yml:
   - insert:
       - id: dsh-memory-delta
         name: dsh-memory-delta
         config:
           root: ''
           enabled: true
           dueWithin: 0
           panel: true
           allowWrite: true
           skill: true
  1. After saving, the patch layer is watched and hot-loaded, no restart needed.

Uninstall: delete the - insert: block above and delete node_modules\dsh-memory-delta.

Known risk (observed 2026-10-08): When installing or uninstalling other plugins via the marketplace, the profile’s cordis.patch.yml may be rewritten, and hand-written - insert: blocks (including comments) may be lost, manifested as the file still being in node_modules but no longer injected. After installation, confirm that the file still contains - id: dsh-memory-delta.

Typical Usage

  1. Run mem init under the project, or rely on the plugin’s default root: '' (i.e., memory under the session working directory).
  2. During the session, the model uses memory_write to write candidate conclusions to inbox; after human confirmation, mem promote or the sidebar promotes them into facts / decisions.
  3. When needing to update the same semantic key, use --supersedes to explicitly supersede the old entry, and the old content goes to archive.
  4. Use mem inject [--json] when debugging the injection payload; use mem validate [--fix] to check store health.

Applicable Scenarios and Caveats

Suitable for: Developers who long-term maintain the same repository or workspace, want new sessions to automatically carry concise and non-expiring conventions and pitfall records, and are willing to do human review via promote / supersede.

Caveats:

  • The plugin reads and writes the memory directory and side-car with the current DSH process permissions; before installing, you should read the source code and license to confirm the paths and write permissions meet expectations.
  • If an incorrect conclusion is promoted to the standing layer, it will persist in every round of injection; be sure to adhere to “model writes to inbox only.”
  • Depends on peer packages like @deepseek-ai/cordis, which need to be compatible with the DSH kernel version you are using; the README documents requirements such as session-format v4 on the injection message’s source.kind.
  • The sidebar Memory tab and skill registration are optional capabilities; without the Web sidebar, differential injection and CLI can still be used together.

After the above steps, you can make cross-session memory in DSH into a reviewable, diffable, archivable Markdown store, and only pay incremental context costs at the start of each session.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye