lm-memory: Local-First Long-Term Memory for Agents

Introduction

Switching to a new session or a new host, and the AI forgets everything. This transience causes massive redundant work in multi-turn conversations and long-term project collaboration, and can even lead to critical information loss. The DSH plugin lm-memory provides these AIs with a shared, retrievable, correctable, and forgettable memory layer. It focuses on resolving three commonly overlooked failure modes: memory loss due to network jitter, incorrect overwriting of new tasks during session resumption, and erroneous memories surviving through repeated exposure.

Plugin Overview

lm-memory is a local-first long-term memory system for Agents, comprising an MCP server and an optional DSH collection plugin. It implements memory storage using SQLite + FTS5 + bilingual local embeddings (56 MB), while distillation and summarization call remote LLMs. Both storage and embeddings run on the local machine; setting allowRemote: false completely disables any outbound data transmission.

Core Features

Unified Write Entry Point

The three write paths—MCP, collection card, and distillation candidates—all go through the same transaction function commitMemoryTx: credential interception → deduplication → transaction → embedding → indexing → graph → hot stream. The distillation process has no database write permissions whatsoever.

Task State Machine

The full lifecycle of a distillation task is persisted in the database (extract_jobs table), so you can check the table to see whether anything was missed:

  1. Registered as pending
  2. Atomic claim (conditional UPDATE to seize owner + lease; a second server cannot claim it)
  3. Helper execution (LLM failure / truncation / bad output / missing key → task retained, non-zero exit)
  4. Candidate consumption (failed candidates enter the retry queue; the task is not marked complete)
  5. Receipt settlement (all candidate EIDs in the receipt must be resolved before the task is marked done; zero candidates is also a definitive terminal state)
  6. Claim count exceeds 5 → archived as failed

Candidate IDs are deterministically generated via hash(sessionId · rev · kind · content), so re-running the same task does not produce a new identity.

Forgetting Mechanism

Usage-feedback TTL + type-specific grace periods (TODO: 45 days, sessions: 60 days, facts & experiences: 120 days, preferences: 240 days). Expired entries transition to dormant with reduced visibility; they can be awakened, and pinned entries are exempt.

Retrieval Capabilities

FTS5 trigram lexical search + bge-small-zh/en bilingual semantic search, routed by query language, fused via RRF. Zero hits will prompt the user that other memories exist in the dormant archive.

Security Safeguards

The credential defense line is managed by a single module server/guards.mjs across three entry points (patterns: sk-…, api_key=…, ghp/xox/AKIA prefixes): MCP writes are directly rejected; collection is sanitized before hitting disk; a final filter runs before data enters a remote prompt, and messages tagged “don’t remember” are removed entirely.

Installation & Setup

Node.js ≥ 22.16 (with built-in node:sqlite; 24+ recommended).

npm Install

npm install -g dsh-lm-memory

Claude Code or Any stdio MCP Host (git method)

git clone https://github.com/hrrrb408/lm-memory.git
claude mcp add lm_memory -s user -- node /path/to/lm-memory/server/memory-server.mjs

DSH Installation

Official release 0.19.8. First verify that your DSH version satisfies >=0.2.2-rc.3 <0.3.0. In an isolated environment, open Plugins → Add Plugin, enter file: followed by the absolute path to the downloaded dsh-lm-memory-0.19.8.tgz (Windows example: file:C:/LM-Test/dsh-lm-memory-0.19.8.tgz), and restart as prompted by the host.

The package contains only the plugin; installing dependencies may require network access, and the plugin still requires a standalone Node.js ≥ 22.16.

Plugin Configuration

llm:
  model: glm-5.3
  # baseURL: ""         # Only needed when switching providers
  # apiKeyEnv: ZAI_CODING_CN_API_KEY
allowRemote: true       # false = system-level outbound ban
memoryDir: ""           # Custom data directory
refresh: true           # Change hot-stream injection
extract: true           # Automatic distillation

Feature Toggles

In Settings → Memory Library, you can toggle: project memory, confirmed-conclusion storage, allow outbound distillation, and task candidate hints (including authorized session IDs). Changes are written to <memoryDir>/settings.json and take effect after restarting DSH.

Typical Usage

MCP Tool List

Tool Description
memory_remember Write. Accepts an explicit event_date; credential patterns are directly rejected
memory_recall Lexical + semantic fused retrieval; expand: true includes one-hop graph expansion
memory_correct Correction; requires expected_version; new version inherits pin status and event anchor
memory_forget Default logical deletion; hard: true physically deletes by ID regardless of state
memory_list List recent memories by kind
memory_pin Pin / unpin / awaken dormant entries
memory_sleep Manually run a dormancy sweep + conflict scan
memory_feedback {id, useful: true} updates lease-renewal statistics
memory_source Look up the original source of an auto-entry (sanitized window + message sequence)
memory_batch_remember Batch write (≤50 entries), each passing through the full defense line

Project Memory (Optional)

Isolates memories by Git repository; disabled by default:

projectMemory: true      # Project store isolated by real Git root; personal store in a separate namespace
confirmedOutcomes: true  # Allows "Confirmed conclusion:" / "Confirmed fix:" to store the previous assistant turn as a project fact/experience
allowRemote: true        # Allows project-mode distillation job submission

Once enabled, tools are split into mcp__lm_personal__memory_* (personal general) and mcp__lm_project__memory_* (current repository).

Use Cases & Notes

Suitable for DSH users who need long-term memory and cross-session collaboration. The plugin runs with the current dsh process privileges; review the source code and license before installing.

Summary

lm-memory builds a local memory layer using SQLite + FTS5 + bilingual embeddings, ensuring reliability and privacy through a task state machine, forgetting mechanism, and security defense line. It is well-suited for DSH users who need persistent long-term memory.

References

  • Plugin directory page: https://www.skillhub.cn/plugins/hrrrb408/lm-memory
  • GitHub: https://github.com/hrrrb408/lm-memory
羽毛球分组比赛记分
小程序二维码

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

Xiaoye