Introduction¶
DSH accumulates a wealth of experience while executing tasks. If this experience is scattered across individual conversations, it quickly becomes “repeatedly stepping in the same pit.” Current approaches either pile up rules via prompt engineering or maintain a separate knowledge base outside of conversations—the former tends to become stale, while the latter is disconnected from DSH itself. Memorytree (dsh-memorytree-rule) organizes this experience into a local memory system that is searchable, archivable, and auditable, turning “experience” into reusable rules.
What It Is¶
This is a memory plugin for DSH, maintained by ninihao1743. It organizes memory into a “four-branch” hierarchy: Trunk (long-term criteria), Emotional Branch (interaction history), Task Branch (operational procedures), and Judgment Leaf (rules pending verification). Memory is stored in local SQLite; retrieval is performed in-process—no network calls, no LLM invocations, no external services.
Core Features¶
Four-Branch Hierarchy¶
| Branch | What It Holds | Default Scope |
|---|---|---|
| Trunk | Long-term criteria that must be followed every round; the canonical source is AGENTS.md |
Cross-workspace |
| Emotional Branch | Interaction history, emotional conversations, work sentiments; diary entries serve only as indexes | Cross-workspace |
| Task Branch | Procedure cards for plugins/scripts/services/fixed operations; one card per subject | Global (can be explicitly isolated by workspace) |
| Judgment Leaf | Unclassified rules pending verification, parsing notes, and scattered observations | Global (can be explicitly isolated by workspace) |
The Trunk contains criteria where “not knowing them leads to mistakes.” The Task Branch records only paths, commands, parameters, and pitfalls. When a branch/leaf conflicts with the Trunk, modify the branch/leaf; when two Trunk entries conflict, ask the user.
Local Storage & Retrieval¶
- DB location:
<DSH_HOME>/memory-tree/memory.db(WAL mode, single file) - Retrieval method: BM25 + 256-dim hashed character n-grams (feature hashing)
- Retrieval defaults to
scope=all(global:user+ all workspaces); you can also restrict touseronly or the currentworkspace
9 Tools¶
| Tool | Purpose |
|---|---|
memory_search |
Hybrid retrieval; hits include score breakdowns and verbatim evidence; Trunk entries additionally carry source line numbers |
memory_write |
Write a memory entry (one of the four branches); auto-redaction by default, pass redact:false to preserve raw text; trunk entries always go to candidates |
memory_forget |
Forget; archived by default (recoverable), hard requires a reason |
memory_tree |
View the full four-branch overview, candidates, expired items, pending triage, and DB size |
memory_card |
Fetch a task card and related entries by subject or id |
memory_ingest |
sync syncs §1 Trunk from AGENTS.md into the index; migrate migrates an old DB; status shows environment info |
memory_daily |
Daily triage: generate a report (pending leaves, clusters, stale cards, expired items) or submit branch-removal/forget decisions in one go |
memory_admin |
doctor / stats / reindex / export / import / audit / report / diary / placement |
memory_emotion |
Emotional candidate daily review: list / mark / stats / budget / report; only modifies the candidates table, does not write memory directly |
Emotional Candidate Collection¶
The plugin has local candidate collection enabled by default: it locally identifies potentially worthwhile fragments by rule, then redacts, truncates, and scores them before storing in emotion_candidate. Collected items are only “candidates,” not memories: they are auto-purged after 30 days, and actual memories are still written via memory_write.
{
"emotionCapture": true,
"emotionPluginCwdPatterns": ["my-bot-workspace"],
"emotionReviewCostCapCny": 0.3,
"emotionRetentionDays": 30
}
Collection rules:
- Listens to session/event, capturing only text blocks from user/assistant
- Local scoring (emotion, memory, relationship, work frustration, first-person feelings, etc.); score ≥ 35 to enter candidates
- Max 6 entries per session per day, 12 globally
- Body capped at 800 characters, plus 240 characters of context stored separately
- Deduplication via sha1(session_id + role + day + text)
Classification:
- relationship (interaction/emotion/memory in the main session)
- plugin (plugin sessions where cwd matches emotionPluginCwdPatterns)
- work (work retrospectives and general sessions)
Redaction rules:
- Common secrets, Bearer, password/secret/token/api_key = …, email addresses, long digit strings, openid/qq values, visitor nicknames and @mentions
Daily review suggestions:
- Open a new session at a fixed time each day; have the model run memory_emotion stats → budget → list
- Then use memory_write to write 0–6 first-person feelings/stances, followed by mark + report
Dashboard¶
memory_admin action=report or node bin/mt.mjs report --out report.html generates a self-contained HTML file:
- Star map: each of the four branches forms a cluster; each memory is a star, uniform in size, color-coded by branch
- Rule operations: Trunk entries can be manually edited or re-assigned to branches; edits first go to the Judgment Leaf’s “pending write” queue, and only after explicit confirmation are they backed up, written to AGENTS.md, read-back verified, and synced to the index
- Judgment Leaf re-assignment: Trunk assignments must pass five core rule checks; Emotional Branch/Task Branch writes go only to the local memory DB; Task Branch assignments are first evaluated by DSH for the best-fit card, and written only after user confirmation
- Search & filter: in-page search with real-time counting and dimming of non-matching stars; layer color legend allows filtering by branch
- Deep thinking: feeds rule originals and rewrite requirements back into the DSH session for DSH to process
- Print / PDF: print styles remove interactive elements and backgrounds
The dashboard references no external links and makes no network calls; the online dashboard is a same-origin page, while the file:// double-clicked offline snapshot is read-only. Dashboard write operations only accept local loopback, same-origin requests, and the token in dataDir/board-token; the token is consistent with local mode, and old links remain valid after restart.
Scopes¶
user: cross-workspace shared; all four branches default to writing here, so task cards are directly queryable across projectsworkspace:<first 10 chars of sha1 of cwd>: optional isolation scope for project-private task cards/judgment leaves; only written whenscope=workspaceis explicitly passed
memory_search defaults to scope=all (global: user + all workspaces); you can also restrict to user only or the current workspace.
Installation & Enablement¶
Install via DSH’s built-in plugin manager (exact commands vary by DSH version; refer to “Settings → Plugins” or dsh plugin --help). After installation, the 9 memory_* tools are registered, and a “Memory Tree” entry appears in the left sidebar.
After modifying plugin code, fully quit and restart DSH so the host drops the old in-memory module and loads the new code; if you only changed source without reinstalling, node bin/mt.mjs still runs the new code, but the in-plugin tools and dashboard may still use the old module.
First Use¶
- Check whether
<DSH_HOME>/AGENTS.mdalready exists: if not, runnode bin/mt.mjs initin the plugin directory—it automatically copiesexamples/AGENTS.template.mdand syncs. You can also manually copy the template, replace<...>placeholders with real values per the comments, and delete unnecessary entries entirely. If it already exists,initrefuses to overwrite by default and only merges the required sections from the template. - Run
node bin/mt.mjs doctorin the plugin directory to verify paths and DB health; runnode bin/mt.mjs sync --forceto force re-sync, turning §1 Trunk into searchable branch entries. - To see what the four branches look like, run
node bin/mt.mjs demo: it creates a demo DB and dashboard in a temp directory tagged with “example” labels, without touching real memory.
All “example, deletable” entries in the template are illustrations, not actual memories; you can delete them after understanding or replace them with your own experiences. The template is not a rule auto-written by the plugin; the plugin does not generate AGENTS.md for you.
CLI¶
All commands below are executed in the plugin directory (i.e., node_modules/dsh-memorytree-rule); after installing the plugin, tools should prefer memory_admin—no need to type paths manually.
node bin/mt.mjs doctor
node bin/mt.mjs init
node bin/mt.mjs stats
node bin/mt.mjs sync --force
node bin/mt.mjs search "backup path" --limit 5
node bin/mt.mjs daily
node bin/mt.mjs demo
node bin/mt.mjs report --out report.html
demo creates an isolated example DB in a temp directory and does not read/write the real DB; --out can write the demo dashboard to a specified file.
Data & Privacy¶
- Writes are redacted by default: common secrets,
Bearer,password/secret/token/api_key = …, email addresses, long digit strings,openid/qqvalues - Full export:
memory_admin action=export(JSONL) - Audit:
memory_admin action=audit - Diary:
memory_admin action=diary; only writes an index of “what happened in the DB today,” not session body text; hand-written diary entries are not auto-overwritten (requiresforce=true) - Local emotional candidate selection by default: 0 tokens, no network, no external API calls; candidates are redacted first, only excerpts kept, 30-day expiry, not written as memories. Set
emotionCapture: falseto disable; after disabling, session body is no longer read - Trunk canonical source is always
AGENTS.md; only an explicitly confirmed “write to canonical” action in the dashboard modifies it, with backup before and read-back verification after
Explicitly Not Done¶
- No auto-injection: memories are not injected into the system prompt every round, avoiding conflict with “single injection source” principle; recall relies on the model actively calling
memory_search - Defaults to writing candidates only, not auto-writing memories: emotional candidates are enabled by default but only go into
emotion_candidate, not directly modifying memory; after settingemotionCapture: false, ingestion only goes through explicitmemory_writeand daily triage - Not auto memory-writing: candidates must pass daily review; candidates where first-person feelings cannot be articulated are discarded; the plugin does not decide for the user what is “worth remembering”
- No encryption: the DB is plaintext SQLite, relying on redaction and file permissions; use disk encryption or container volumes if encryption is needed
- Not neural/semantic retrieval: character n-grams only boost phrasing-similarity scores; if nothing matches, it honestly reports no results
Use Cases¶
Suitable for DSH developers who need long-term rule maintenance and want to avoid repeated pitfalls. If you want to organize experience into a searchable, archivable, and auditable memory system, Memorytree is a local-first, offline-capable option.
Short Closing¶
Memorytree turns DSH’s experience into reusable rules through four-branch hierarchy and local retrieval. To get started quickly, first run node bin/mt.mjs init and node bin/mt.mjs doctor, then use memory_write to write your own memories.
- Directory page: https://www.skillhub.cn/plugins/ninihao1743/dsh-memorytree-rule
- GitHub: https://github.com/ninihao1743/dsh-memorytree-rule