dsh-cross-memory: Cross-Instance Hard Constraints and Memory Anchor Fixing

Introduction

When running multiple instances of DeepSeek Harness (DSH), each instance typically mounts @a9i5k4/dsh-auto-memory independently, and user-level memory is isolated by DSH_HOME. Consequently, there is no single source of truth for “which rules must be followed by all instances”: one must either duplicate them in every instance’s MEMORY.md or rely on the on-demand loading of SKILL.md. The former is truncated at 200 characters by the auto-memory rules layer, while the latter lacks the “mandatory reading every turn” attribute.

Below is an introduction to dsh-cross-memory (GitHub: ShukebtAb/Dsh-Cross-Memory, Community Directory: skillhub entry), released by maintainer ShukebtAb. It is an incremental plugin for auto-memory; it does not replace the base package, nor does it modify the base code or data. It only supplements two capabilities missing from the base: full-text injection of cross-instance rules and repair of memory file anchor structures.

What is this

  • Name: dsh-cross-memory (npm package name matches repository name)
  • Category: Memory
  • Current Version (installation example in material): v0.4.0
  • License: MIT; requires Node.js ≥ 20 to run, peer dependency @deepseek-ai/cordis ^4.0.1
  • Relationship: Does not import, read, or write data from @a9i5k4/dsh-auto-memory. If auto-memory is not installed, the plugin’s injection channel still works, though the significance of the “cross-instance unified constraints” gap diminishes in a single-plugin scenario.

Capability 1: Cross-instance Hard Constraint Injection

Problem Solved

The user-level memory directory of auto-memory is isolated by the instance’s userMemoryDir, meaning sub-instances cannot see the global constraints accumulated in the main instance. This plugin reads a shared rule file from a fixed absolute path and injects the entries between cross:begin and cross:end into the context of every turn—modify once, and all instances with injection enabled will sync immediately.

Rule File Convention

The path is hardcoded as ~/.dsh/memory/cross/RULES.md (unaffected by wsKey and userMemoryDir):

# …Header description (not injected)…

<!-- cross:begin -->
- 【Must Follow】First rule...
- 【Forbidden】Second rule...
<!-- cross:end -->
Convention Description
Active Range Only content between comment markers; header description is not injected
Line Format Starts with - counts as one entry; no marker word whitelist
Entry Length Recommended ≤260 characters (including -); material notes individual exceptions may exist for complete error-negation retention strings
Encoding UTF-8 without BOM, LF

When locating the range, use the full comment string <!-- cross:begin --> to avoid mismatching if the literal text cross:begin appears in the header description.

Differences from Writing to MEMORY.md (Material Measurement)

The material compared the carrier methods under “22 rules, local measurement”: Plugin full-text injection is approx. 3786 characters with complete error-negation retention; writing the same entries scattered across various instances’ MEMORY.md is approx. 4444 characters and the rule segment would be truncated by auto-memory’s rules-layer.js at 200 characters. For long constraints that must enter the model context fully every turn, using this plugin’s injection is one of the paths provided by the material.

Injection Behavior

  • Channel: systemPrompt.context() (user-role, appended to the end of history), does not break DeepSeek prefix caching
  • Order: order: 10001, ranked after auto-memory (SECTION_ORDER = 10000)
  • Caching: Based on file mtimeMs, no re-read if unchanged
  • Failure: Returns silent empty string on missing file, read failure, or missing anchor; no errors, no impact on session
  • Body: No truncation, injected as-is

Capability 2: Anchor Structure Repair Tool

auto-memory uses <!-- memory:mem_<32hex> --> as the unique entry delimiter. Structural corruption may cause the entire file to fail-closed (refuse writes) or prevent new content from entering the injection surface; the base package lacks a tool to “repair anchor structure”. This plugin provides cross_memory_fix_bare_entries.

Three Pathologies

Class Symptom Disposition
A Bare Entry (No Anchor) Entry has no anchor (common in appends when memoryAnchorEnabled=false) Insert anchor line before the corresponding ## line
B Empty Anchor Orphan No non-empty line after anchor; the whole file may permanently refuse writes Append a neutral placeholder line after the anchor line
C Duplicate Anchor Same mem_<32hex> appears multiple times Report only, do not auto-delete

The material emphasizes: B and C are unrelated to the memoryAnchorEnabled switch; manual editing, concurrent writes, or copying paragraphs can all produce them. As long as anchors are still used for separation, this repair pathway is needed.

Parameters and Guarantees

Parameter Description
scope 'workspace' (default) or 'user' (user-level ~/.dsh/memory/MEMORY.md)
memoryFile Required when scope='workspace', absolute path to target MEMORY.md
apply Default false (dry run only); true writes to disk

Hard Guarantees:

  1. Only insert new lines; diff against original text (after filtering anchor lines) must be 0.
  2. When apply=true, retain a .pre-write-<stamp> baseline first, then self-check after writing; if A/B still exist, rollback the entire file and return rolledBack: true.

Idempotency: The second execution on the same file usually returns changed: false.

Typical calls (from README):

cross_memory_fix_bare_entries(
  scope      = 'workspace',
  memoryFile = '<workspace absolute path>\MEMORY.md'
)

cross_memory_fix_bare_entries(..., apply = true)

Tool: cross_memory_status

Outputs JSON containing rulesPath, ok, sha256, bytes, mtimeMs, itemsParsed, injectEnabled, itemsInjected, etc. One of its uses is for the main instance to periodically compare the sha256 of RULES.md—the material points out that this file currently has no write protection, and DSH tools like write/edit can directly overwrite it if permissions allow. Hash verification is an actionable measure on the verification side of the “Location Isolation + SHA256” scheme. auto-memory’s memory_status does not include the cross/RULES.md path.

Installation and Activation

Installation Commands (From Material)

# From GitHub (Recommended, locking commit/tag for reproducibility)
dsh plugin --profile web add github:ShukebtAb/Dsh-Cross-Memory#v0.4.0

# Local development (Example path based on README)
dsh plugin --profile web add file:D:\Study\Product\dsh-cross-memory

After installation, confirm: The package appears in dependencies, and is also listed in dsh.profile.bundles; without the latter, it will not take effect.

inject Switch (Explicitly Declared per Instance)

The plugin does not guess main/sub-instance roles; content fingerprint deduplication is unreliable for “rewritten” RULES.md. Configure in the instance profile’s cordis.patch.yml:

- id: cross-memory
  name: 'dsh-cross-memory'
  config:
    inject: true          # Sub-instance: Inject all cross-instance rules
Role Configuration Effect
Main Instance (Rules segment is the source of truth) inject: false (Default) No injection; still able to use the two tools
Specialized Sub-instance inject: true Inject all cross-instance entries every turn

The material suggests installing this plugin on the main instance as well, to utilize cross_memory_status and cross_memory_fix_bare_entries.

Use Cases and Notes

Who is it for

  • Multi-DSH instances (main + specialized sub-instances) needing a shared set of hard constraints that must be reached every turn.
  • Using auto-memory and encountering structural issues like bare entries, empty anchors, or duplicate anchors in memory files, requiring auditable “insert-only, no-rewrite” repairs.

Notes

  • The plugin runs with the permissions of the current DSH process; please review the repository source code and MIT license before installation.
  • The community directory skillhub.cn is an independent ecosystem site and has no official affiliation with DeepSeek / High-Flyer.
  • Cross-instance rules rely on the local fixed path ~/.dsh/memory/cross/RULES.md; migration or multi-machine sync requires manual management of this file.

Conclusion

dsh-cross-memory adds two narrow but clear pathways outside of auto-memory: full-text injection of shared RULES.md, and three-classification repair of anchor structures. If your pain point is exactly “a unified set of hard constraints for all instances” or “memory files refusing writes due to anchor corruption”, you can install and configure inject as described above, and use the two tools for status verification and structural repair.

  • Community Directory: https://www.skillhub.cn/plugins/ShukebtAb/Dsh-Cross-Memory
  • GitHub: https://github.com/ShukebtAb/Dsh-Cross-Memory
  • Related Base: https://github.com/Aik358/dsh-auto-memory (Reference version 3.2.5 in material)
羽毛球分组比赛记分
小程序二维码

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

Xiaoye