Memory Management (DSH Edition)
Cross-session long-term memory: L1 index injection (visible every turn) + L2 environment facts + L3 task experience.
Trigger Timing
Reading (When to Look Up Memory)
- At the start of a new task: if the task involves the local environment, tool configuration, specific tech stacks, or similar things done before → first
memory_listto see what's available, thenmemory_readto retrieve relevant entries - When encountering difficulties / hitting obstacles:
memory_readto check if there is a relevant SOP (keyword match againstsops/filenames or facts section) - Memory index in model prompt (
memory:index): L1 existence index visible every turn — when related trigger words are seen, actively callmemory_read/memory_listto get details
Writing (When to Consolidate Memory)
When a task is completed (or a phase is completed) and there is information validated by successful actions, call memory_write:
Can Write (must include evidence):
- Environment-specific facts: paths, configurations, measured parameters, tool behavior (→
entry_type: fact) - Complex task experience: pain points that required multiple retries to succeed, hidden preconditions, stable steps (→
entry_type: sop) - General hard rules (→ also possible via
memory_write sopor directly suggest maintaining [RULES])
Forbidden to Write (writing would be pollution):
- ❌ Information without verification evidence (no action, no memory)
- ❌ Model's inherent knowledge, reasoned guesses, unverified assumptions
- ❌ Ephemeral state: timestamps, PIDs, temporary paths, one-time IDs
- ❌ General common sense, log records, details of reasoning steps
Index Synchronization
memory_writeautomatically syncs the L1 index; manual operation is usually unnecessary- After manually modifying
facts.md/sops/files →memory_indexto rebuild the index - When the index exceeds 30 lines: trim [RULES] (word-level edits, do NOT overwrite the full text)
Storage Layout
<home>/.dsh/memory/
├── memory_management_sop.md L0 meta-rules (how to manage memory)
├── index.txt L1 index (≤30 lines: L2/L3 existence list + RULES)
├── facts.md L2 environment facts (## SECTION)
├── sops/*.md L3 task experience
└── file_access_stats.json read frequency statistics
Tools
| Tool | Purpose |
|---|---|
memory_list | List all memory (facts + sops + index line count) |
memory_read | Read specified memory (index / fact topic / sop filename) |
memory_write | Write memory (fact/sop, evidence required) |
memory_index | Rebuild the L1 index automatic section |
Principles
- Action Verification: No Execution, No Memory. Only write information that has been successfully verified.
- Minimum Sufficiency: Keep content as short as possible; only record information whose forgetting would lead to costly retries.
- Do Not Delete or Alter Verified Facts: You may compress or migrate, but never discard.
- Active Writing: Memory writes are always initiated by the model/user; the system will never automatically modify configurations or install plugins.