dsh-ai-memory: Natively Integrating DeepSeek Harness with ai-memory

Introduction

DeepSeek Harness (DSH) supports capability extension via plugins. ai-memory is a local memory system that natively supports capturing session lifecycle, tool calls, compaction, and session handoff through hooks. The official DSH integration provided by ai-memory is implemented via @deepseek-ai/dsh-hooks-claude-code through DSH’s Claude Code bridge hooks. This path has several hard defects, including: inability to capture SessionEnd, SessionStart hangs in the hook causing handoff to not be declared by ai-memory, lack of re-anchoring after PreCompact, configuration and MCP bridge failure on Windows due to PowerShell quoting and \\?\ paths, MCP requiring manual patch-line merging and a persistently running bridge process per configuration file.

dsh-ai-memory is a DSH plugin that natively connects ai-memory hooks to DSH, replacing the Claude Code bridge with DSH’s native extension points, thereby addressing the above defects and unifying behavior across Windows, macOS, and Linux — all without going through a Shell.

What It Is

  • Plugin name: dsh-ai-memory
  • Maintainer: frederico-kluser
  • Repository: https://github.com/frederico-kluser/dsh-ai-memory
  • Category: Memory
  • Description: A DeepSeek Harness plugin that natively integrates ai-memory into DSH: full lifecycle capture, session handoff and post-compaction anchor injection, and ai-memory tools for the model; no Shell, cross-platform.

Core Capabilities

1. Event Mapping & Capture

Each ai-memory event is forwarded via the native ai-memory hook --agent dsh command to the corresponding DSH extension point:

ai-memory Event DSH Extension Point
SessionStart (including handoff declaration) agent/created (serial, awaited before the first step)
UserPromptSubmit agent/pre-step (operator-input text only)
PreToolUse / PostToolUse tools/pre-execute / tools/result (frozen final result)
Stop session/event turn/end (completed, failed, or interrupted turns)
PreCompact (including anchor) session/event compaction/start / compaction/end
SubagentStart / SubagentStop subagent/start / subagent/end
SessionEnd agent/disposed (on plugin teardown)

Capture ordering is maintained by a per-session serial queue. Each hook run has a timeout, the startup handoff declaration has a 6-second budget, and it will never block the Agent.

2. Session Handoff

  • Handoff is declared at the agent/created stage; DSH awaits declaration completion before the first step.
  • Handoff content is visible via ai-memory call memory_handoff_list '{}'.
  • In a new session, injected handoff content is presented as a 📥 ai-memory: pending handoff block, allowing the model to answer “where did we leave off.”

3. Compaction Anchor

  • After compaction/end, the operator’s prompt is injected as an anchor.
  • The anchor is wrapped in ai-memory’s own <!-- ai-memory:untrusted-history --> tag with a security notice; stored text cannot prematurely close the tag.

4. Tool Registration

ai-memory tools are registered as native DSH tools, with each invocation scoped to the current session’s project:

  • core: 7 core tools (memory_query, memory_read_page, memory_handoff_begin, memory_handoff_accept, memory_handoff_list, memory_read_session_observations, memory_write_page) plus memory_call to invoke the remaining 20 tools.
  • all: all 27 tools (~20k tokens of Schema).
  • Configurable to none or a list of tool names.

5. Cross-Platform & Security

  • No Shell: ai-memory is launched with shell: false and an argv array, hiding the console window on Windows. Avoids parsing quotes, escapes, or special characters in prompts, paths, or JSON arguments.
  • Credentials and routing are handled by ai-memory itself: all tool calls, handoff declarations, and anchors are executed via ai-memory call <tool> in the session’s working directory; the plugin does not read Bearer Tokens.
  • Untrusted history is fenced: injected handoff and anchors use ai-memory’s own security tags and security notices.
  • Windows directory spelling normalization: session directories are normalized (backslashes, no \\?\, uppercase drive letter), facilitating matching with handoffs written by other Agents.
  • Fail-open: missing executables, stopped services, or slow hooks only log once; the session continues, and the plugin never blocks DSH startup or turn execution.

Installation & Activation

Prerequisites:

  • ai-memory ≥ 3.5, with the service running (check via ai-memory status).
  • DSH 0.2.x.

Execute under the target Profile:

dsh plugin --profile web add github:frederico-kluser/dsh-ai-memory

The plugin is declared as a DSH bundle; dsh plugin add mounts it automatically — no manual - insert: line needed. Restart or reload the Profile. Repeat the above steps to activate for each Profile in use (e.g., headless, tui).

Once activated, the Profile log (e.g., ~/.dsh/logs/dsh-web.log) will show:

[dsh-ai-memory] active — using <path to ai-memory>

Warning logs use the same prefix. These logs are only emitted to stderr when redirected to a file or pipe; they do not overwrite the interactive terminal UI. Controlled via environment variables: DSH_AI_MEMORY_VERBOSE=1 forces log display, DSH_AI_MEMORY_QUIET=1 silences logs.

When installing from a local checkout, you can point to the build entry in the Profile patch:

# $DSH_HOME/profiles/web/cordis.patch.yml
- insert:
    - id: dsh-ai-memory
      name: '/path/to/dsh-ai-memory/lib/index.js'

Note: in this case, do not also install the package in the Profile.

Migrating from the Hooks Bridge

If you previously configured hooks bridge lines via the ai-memory installer, remove the following lines to avoid duplicate event capture:

  • - id: ai-memory-hooks (@deepseek-ai/dsh-hooks-claude-code)
  • Optional: the - id: 'ai-memory' MCP-client line (@deepseek-ai/dsh-mcp-client). If retained, set tools: none on that line to prevent the model from seeing duplicate tools.

Configuration Options

All options are optional. Add a config: block to the plugin entry in the Profile’s cordis.patch.yml to override defaults:

- id: dsh-ai-memory
  config:
    tools: all

Common options:

Option Default Description
binary discovered Path to the ai-memory executable. Discovery order: AI_MEMORY_BIN, PATH, then %LOCALAPPDATA%\Programs\ai-memory on Windows, ~/.local/bin, ~/.cargo/bin, /opt/homebrew/bin, /usr/local/bin, /usr/bin on macOS/Linux
dataDir ai-memory’s Passed via --data-dir (also available via AI_MEMORY_DATA_DIR)
serverUrl install-time value Hook server URL override
agent dsh Agent label recorded on the session
capture true Capture lifecycle events
captureTools true Capture tool calls
captureSubagents true Report subagent start/stop edges
captureSubagentSessions false Whether to also capture subagent sub-sessions as independent sessions
handoff true Declare and inject handoff at session start
handoffSources ['startup', 'clear'] Session start sources used for handoff declaration (resume is excluded, so reopening an old conversation does not consume the handoff)
anchor true Inject post-compaction anchor
tools core Tool scope: core, all, none, or a list of tool names
instructions true Add brief ai-memory usage notes to the system prompt
hookTimeoutMs 15000 Timeout for a single capture hook
startupTimeoutMs 6000 Budget for the startup handoff declaration
toolTimeoutMs 60000 Timeout for a single tool call

Typical Usage

After completing a DSH session in a project, you can query via ai-memory:

ai-memory call memory_briefing '{"recent_sessions_limit": 3}'   # agent is "dsh", ended: true
ai-memory call memory_handoff_list '{}'                         # view handoffs auto-written by ai-memory

Start a new session in the same project and ask the model “where did we leave off.” The model will answer based on the injected 📥 ai-memory: pending handoff block.

Use Cases & Notes

  • Suited for: developers who need ai-memory in DSH and want full lifecycle capture, automatic handoff and compaction anchors, native tool integration, with a focus on cross-platform consistency and security.
  • Permissions & source: the plugin runs with the current DSH process permissions; it is recommended to review the source code and license (MIT) before installing.
  • Dependency: requires ai-memory ≥ 3.5 service to be installed and running.

Summary

dsh-ai-memory natively connects ai-memory hooks to DSH, filling the gaps in the hooks bridge path regarding lifecycle, handoff, compaction anchors, cross-platform behavior, and tool integration, providing DSH sessions with complete memory capabilities. For more details, visit the plugin directory page or the GitHub repository.

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

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

Xiaoye