Introduction

The core philosophy of DeepSeek Harness (DSH) is “everything is a plugin.” When building agents based on DSH, cross-session persistent memory is a common pain point. Traditional vector-retrieval solutions often rely on external databases or require additional model calls, which increases system complexity and latency.

The dsh-long-term-memory plugin aims to solve this problem. It provides DSH with hierarchical and deterministic long-term memory capabilities. It stores data in JSONL files, uses a CJK-aware BM25 algorithm for deterministic recall, and automatically injects memory summaries before each request assembly. The plugin does not depend on vector databases, does not require additional model calls, and does not require a self-hosted SQLite instance or external server. It is fully composed based on existing DSH extension points.

Core Features

This plugin provides the following core capabilities:

  1. Three-tier hierarchical storage: Memory is divided into three scopes, each using one JSONL file.
    • user: User profile information (name, role, preferences).
    • global: Cross-project facts and decisions.
    • workspace: Project-specific memory.
  2. Deterministic recall: Retrieval uses the BM25 algorithm. Chinese is matched by character bigrams; Japanese and Korean follow a similar approach; English is matched by words. Results are explainable and replayable.
  3. Automatic injection and calibration: Before each request assembly, memory summaries are injected via systemPrompt.context(). The injected block is wrapped with <long_term_memory> tags, clearly stating the source and uncertainty, guiding the model to judge relevance and ignore irrelevant content.
  4. Safety mechanisms:
    • Threat scanning: Lightweight pattern detection is applied to written content and injection snapshots. If a threat is detected, the write is rejected or replaced with a placeholder.
    • Write guardrails: Atomic writes are performed using temporary files plus rename, combined with cross-process file locks to prevent data corruption.
  5. Correction loop: A memory_correct tool is provided to correct outdated facts. Old records are marked as superseded and are automatically excluded from subsequent recall and injection.

Installation and Enabling

Run the following commands in the plugin directory:

cd dsh-long-term-memory
dsh plugin --profile web add .

After installation, dsh web needs to be restarted.

⚠️ Note: The dsh plugin add command has previously broken relative paths in link: (causing related plugins to be moved out of bundles). This plugin has been fixed using an absolute path link:/Users/.... Do not rely on relative paths for new plugins.

Usage

The plugin provides two types of usage entry points: model tools and slash commands.

Model Tools

The model can read and write memory through registered tools:

  • memory_write(content, scope?, tags?): Write a memory entry. scope can be user/global/workspace, defaulting to workspace.
  • memory_recall(query, scope?, limit?): BM25 retrieval, returning scored matching records.
  • memory_list(scope?, limit?): List recent memories by update time.
  • memory_get(id): View a single memory entry.
  • memory_forget(id, scope?): Delete a memory entry by ID.
  • memory_correct(claim, truth, evidence?): Record a factual correction.

Slash Commands

Users can directly use slash commands in the input box (without going through the model):

  • /memory list [user|global|workspace|all]: List recent memories.
  • /memory search <query>: BM25 retrieval.
  • /memory get <id>: View a single memory entry.
  • /memory forget <id>: Delete a single memory entry.
  • /memory export [|markdown]: Export the memory bundle.

Configuration

Behavior can be controlled by overriding cordis.patch.yml or settings.yaml. Below are the key configuration items:

  • Injection strategy (injectContext):
    • recent (default): Inject a few of the most recent memory entries from each scope per turn.
    • full: Inject all memories (subject to the character budget).
    • off: Disable automatic injection.
  • Tag filtering (injectTags): In recent mode, inject only memories that carry specified tags (such as decision, constraint), filtering out trivial entries.
  • Write approval (requireApprovalForWrite): Optional. When enabled, writes require human confirmation through the DSH approval extension point before completion.
  • Threat scanning (scanThreatsOnWrite): Enabled by default. Performs lightweight threat pattern detection on written content.
  • Character budget (charLimit): The maximum number of characters per scope. When exceeded, automatic compression is attempted first, and the write is rejected if it still fails.

Technical Details and Cautions

  1. Synchronous injection: The DSH prompt assembler calls relevant functions synchronously. If injection rendering follows an asynchronous path (returning a Promise), it will cause a crash. The plugin has changed all injection rendering to a synchronous path (with asynchronous store prewarming before the first assembly).
  2. Zero external dependencies: The plugin internally implements the BM25 tokenizer and JSONL read/write logic, and does not depend on external vector databases.
  3. Conservative threat scanning: The scanning patterns are intentionally narrowed to detect only instruction override/system prompt leakage/role hijacking/markup injection, avoiding false positives on normal notes. Injection snapshots use placeholders rather than directly deleting the original content, preserving it for user handling.
  4. Storage paths:
    • user: $DSH_HOME/dsh-memory/user.jsonl
    • global: $DSH_HOME/dsh-memory/global.jsonl
    • workspace: <workspaceRoot>/.dsh/memory.jsonl

Appropriate Scenarios

This plugin is suitable for scenarios that require cross-session memory, user preference management, historical decision tracing, and strict data safety controls in DSH agents.

  • Memory accumulation: During conversations, the model uses memory_write to persist important information.
  • Deterministic recall: When the model needs to query historical constraints or facts, it uses memory_recall to obtain highly relevant results.
  • Knowledge base management: Use /memory list and tag filtering to organize project documentation or user profiles.