1. Executive Summary
Engramory is a memory protocol for coding agents with a little code
around it. The agent keeps one Markdown file per fact and one index,
MEMORY.md, of one-line pointers that is loaded every
session; a Claude Code hook and a DeepSeek Harness (dsh) plugin refuse
an index write that would grow it past its size cap. Notable: the cap
gate predicts the edited index by simulating each host's own edit
semantics, and refuses only growth, so an over-cap index can always be
compacted. Weak: everything that decides what is true is prose for the
model. A correction overwrites the note with no record of the old text.
On dsh every note in the default global store reaches every project, and
the scope: repo label written to prevent that is read by no
recall path.
The repository is four things. SKILL.md and
rules-snippet.md are the protocol: four types, a write
order (negative scope, dedup, write, index, delete when wrong), a
task-completion checkpoint and a continuity sync before a compaction.
hooks/engramory_index_guard.py is the Claude Code
PreToolUse cap. adapters/dsh/plugin/ is the
npm package dsh-engramory: the same cap on dsh's tool
guard, injection of the index into each step, a runtime skill, a
compaction reminder and a Memory page. tools/ holds a size
check, a store doctor, an installer for other hosts and a transcript
search.
No model is called by any of it, and nothing extracts memory from a session. A note exists because the agent decided to write it.
One mark, negative_eval, on which store's index the dsh
plugin sends a session. Six are withheld (section 9).
Licence. MIT in LICENSE, copyright
Beijing Tinqiao Technology Co., Ltd., with an identical file in the
published plugin and "license": "MIT" in both
package.json files. The brand fonts are SIL OFL 1.1 and are
converted to curves in the committed artwork
(brand/README.md:39). There is no contributor
agreement.
2. Mental Model
A memory is a file the agent wrote, and it is believed from the
moment it is written. There is no candidate state, no status field and
no confidence. The type says how to treat a note, not whether to trust
it: feedback is how to work and must carry
Why: and How to apply:, project
is where the work stands, user is who the person is,
reference is where something lives
(SKILL.md:144-226). Recall is advisory by instruction: the
index the dsh plugin sends is headed as notes, not instructions
that may be stale
(adapters/dsh/plugin/index.js:3438-3444).
A note becomes recallable only through its index line. The model
reads the one-line descriptions and opens the files it judges relevant,
so the description is the whole retrieval system, which the
protocol says in as many words (SKILL.md:106-109).
A note stops being believed in one of three ways, all performed by the agent with ordinary file edits:
- Rewritten in place. Dedup says update the existing
file and bump
updated:rather than add a near-duplicate (SKILL.md:446-448). The prior text is gone. - Deleted. A note that turns out to be false or
obsolete is deleted, or moved to
archive/, and its index line removed (SKILL.md:457-462). - Archived. A note in
archive/is off the index, recall never scans the folder and the doctor skips it, so it is unreachable unless an index line points at a file listing it (SKILL.md:560-569).
Companion mode adds three types with lifecycles of their own. An
upcoming note names a future date, is asked about once the
date passes and is then rewritten as a moment.
moment and self notes are corrected rather
than deleted, and deleted only when the user asks
(SKILL.md:283-313). That is prospective memory written as a
protocol: nothing in the code reads the date in a note's name.
Diagram source
%% caption: the agent writes a note and its pointer; code checks only the index's size, on two hosts and for their file tools; the index reaches the model every session or step, cut at the cap; correction, retirement and deletion are file edits that keep no prior value
flowchart TD
A["Agent learns a fact<br/>rules: not in the repo,<br/>not a secret, no dup"] --> N["Note file<br/>type, description,<br/>created, updated"]
N --> I["Pointer line<br/>in MEMORY.md"]
I --> G{"Index write grows it<br/>past 200 lines<br/>or 25,600 bytes?"}
G -- "yes, via a guarded<br/>file tool" --> R["Refused:<br/>compact first"]
G -- "no, or a<br/>shell write" --> S["Index on disk"]
R --> I
S --> L["Index in context:<br/>dsh next step,<br/>host next session;<br/>cut at the cap"]
L --> O["Model opens notes<br/>whose lines look relevant"]
O --> C{"Wrong or stale?"}
C -- "update" --> U["Rewritten in place,<br/>old text not kept"]
C -- "retire" --> X["archive/: off the index,<br/>not recalled"]
C -- "forget" --> D["File and pointer<br/>deleted"]3. Architecture
Nothing runs as a service. A store is a directory:
MEMORY.md, the notes beside it, and archive/.
Where it lives depends on the host (SKILL.md:33-60):
- Claude Code: the host's own memory directory, which
the host already loads; Engramory adds the rules (pasted into
CLAUDE.md) and the hook. - Codex and OpenClaw:
<project>/.engramory-memory/or a folder the user names, made bytools/engramory_init.py, with a marked rules block inAGENTS.mdand an optional skill copy. - dsh: one global store,
~/.dsh/.engramory-memory/by default, which the Memory page can move; a project may also have its own, which only the user creates (adapters/dsh/plugin/index.js:3566-3590).
The Claude Code hook is a Python script registered with matcher
Edit|Write|MultiEdit
(hooks/settings.snippet.json). The dsh plugin is one ESM
file with no dependencies that registers a tool guard, three
filesystem-intent hooks, a session projection, a pre-step listener,
runtime contexts, a skill and four routes on dsh's own web server
(adapters/dsh/plugin/index.js:102-492). It declares only
tools as a hard dependency, so the cap mounts on a profile
with no skill registry.
Moving dsh's global store copies it beside the new place, checks
every file, switches a pointer file in the dsh home and renames the old
store <name>.backup-<date> beside where it was
(index.js:2422-2631). While it runs, writes through this
dsh's file tools to either place are refused, and a write to an old
place afterwards is turned toward the new one
(index.js:2107-2185).
Deployment and ergonomics
Adoption is a paste and, on Claude Code, a hook entry; on dsh,
dsh plugin add dsh-engramory. Python 3.9 or later runs the
tools; the plugin needs Node 18 and dsh 0.2.1-alpha.5 or later. No API
key, no network and no database are needed, and everything works
offline. The store is plain files a person opens in an editor. The
hook's snippet warns that if the interpreter cannot be spawned, Claude
Code fails open and the cap never fires, and
hooks/INSTALL.md gives a check that a 250-line write is
denied.
4. Essential Implementation Paths
- Claude Code cap.
mainreads the payload as UTF-8 bytes, matches the target byENGRAMORY_INDEX_PATHidentity or by basename of the path or its real path, simulatesEditandMultiEditsub-edits in order on the current text, and denies only when a dimension ends over its cap and grew (hooks/engramory_index_guard.py:188-378,:170-185,:316-355). It never emitsallow; an unreadable index produces a warning, not a deny (:240-298); an unexpected exception exits 0 (:381-389). - dsh cap.
ctx.tools.guard→refuseOversizedIndex→judgeWrite→verdictorbounded(adapters/dsh/plugin/index.js:200-210,:2771-2987). Every path field a call names is judged, a relative path is resolved against the session's directory, andeditis simulated on LF-normalised text and sized as dsh writes it back. - dsh recall.
agent/pre-step→recallFor→indexRecall→projectStore,projectIndex,readIndex,renderIndex(index.js:348-376,:1632-1654,:1685-1830,:2723-2765). TheRECALLprojection folds the seq and SHA-256 of the last index message the session holds, and a compaction that shadows it resets it (:1595-1618). - Compaction reminder.
compactionReminderworks out dsh's compaction point from the engine's ratio, headroom and retention and returns a save it now context from 85% of it (index.js:1427-1538,:3426-3430). - Validation.
engramory_check.pyprints OK, WARN or OVER with exit codes 0, 1, 2;engramory_doctor.pyreports an over-cap index, broken or escaping pointers, orphans, duplicate slugs and schema faults (tools/engramory_doctor.py:1-75,:600-760). Neither runs unless invoked. - Install.
engramory_init.pywrites marked blocks atomically, re-checks symlink containment before each write and never removes a store (tools/engramory_init.py:53-122,:842-1150). - Evidence lookup.
engramory_trace.pygreps Claude Code's JSONL transcripts under~/.claude/projects/, read-only, with injected<system-reminder>blocks stripped (tools/engramory_trace.py:1-60).
5. Memory Data Model
A note's frontmatter is a restricted key: value grammar
the doctor parses without a YAML dependency
(SKILL.md:87-104). Required: name,
description, type, created,
updated; feedback and project
require the two labelled lines, in English or Chinese
(tools/engramory_doctor.py:86-116). Optional:
scope, global or repo.
Times are record dates the agent types. updated
overwrites; there is no validity interval. A project note
may hold settled facts and must not hold current state such as
the tip commit or a test count, and the protocol tells the two apart by
whether time can falsify the value (SKILL.md:184-197).
Provenance is absent by design, and the README lists No
provenance, confidence or expiry fields among its known
limitations. The nearest thing is engramory_trace.py, which
lets a person search the Claude Code transcripts a note came from.
The scope key is stored and never applied.
SKILL.md introduces scope as what keeps a
memory from being recalled somewhere it was never true, then says
to keep it out of the index because it governs curation, not
recall (SKILL.md:228-253). The doctor checks the value
is global or repo and nudges when a
feedback or project note has none
(tools/engramory_doctor.py:685-690, :744-748).
Nothing else reads it.
Scoping is therefore physical: which directory a note sits in. On
dsh, the skill tells the model to file a repo-only fact in a project
store when the user has made one and in the global store otherwise. The
global store is injected into every conversation in every profile of a
dsh home (index.js:3566-3590,
SECURITY.md).
6. Retrieval Mechanics
There is no search: no index over note text, no embedding and no
ranking. The read path is the whole MEMORY.md in context
and the model's choice of which notes to open, which scales to the
number of lines the cap allows.
On dsh, indexRecall decides what a session is sent
(adapters/dsh/plugin/index.js:1685-1757):
- With
indexPathpinned, that index alone. - Otherwise the project store, the nearest
.engramory-memory/MEMORY.mdbetween the session's directory and the nearest.gitancestor, which must be a regular file, not a symlink, and inside that root (:1778-1830); then the global store named by the dsh home's pointer file. - A project store that is the global store under another name is shown once.
- A session directory on another machine is not looked into.
Each index is cut to the longest whole-line prefix within both caps,
and a cut is marked "[Cut here: the index is over the Engramory cap
…]" (index.js:2723-2765, :3449-3452). On
Claude Code the host's own loader reads the first 200 lines or 25 KB
(hooks/engramory_index_guard.py:5-8), and
SKILL.md calls what falls past that silently lost
(SKILL.md:520-522).
Each change to the index adds another full copy to a dsh
conversation. The index goes out as a user message of the
plugin's own kind, appended to the step's messages, whenever its SHA-256
differs from the copy the session last received
(index.js:1632-1654). Earlier copies stay in the
conversation until a compaction takes them out; the header tells the
model the newest replaces any earlier one. The design replaced
dsh's runtime context, which resent the index on any change to any part
of the context: the comment records six copies of a 20 KB index in a
13-step session (index.js:297-303). Now only a changed
index costs a copy, and a session that edits the index k times holds
k+1. Appending after the conversation leaves the cached prefix
intact.
7. Write Mechanics
Writes are the agent's own file edits, made when the protocol says
to: on learning something durable, at the end of a task ("a
judgement, not a write"), and in the continuity sync before a
compaction, clear or new thread (SKILL.md:417-514). Every
rule about what to save is prose: no secrets, not what git or the code
already records, dedup against the index, at most one live
project note per unfinished task. No code checks any of
them before a write lands; the doctor checks the schema afterwards, when
run.
The one gate is size. A write to the index that ends over a cap and
grew is refused with the compaction procedure in the reason; a shrinking
write passes even while still over, so the index can be compacted 210 →
205 → 198 (hooks/engramory_index_guard.py:311-355). A
per-line nudge fires when an edit adds an index line carrying over 200
bytes of prose once its pointers are stripped (:322-336).
On dsh, an edit whose result cannot be simulated is refused
only when the index is already over
(index.js:2863-2876).
Before dsh compacts, the plugin adds a runtime context telling the
model to save anything worth keeping, with no need to tell the user
(index.js:3426-3430).
Operational cost
A write blocks on nothing but the file write and, on two hosts, a
guard that reads the index once. A note is on disk at once. On dsh its
index line reaches the model on the next step, which a committed case
pins (index.test.js:1485-1494); on Claude Code, the host
loads the index at session start. No background pass reads or rewrites
the store. The read cost is bounded by the cap: at most 25,600 bytes of
index per store per session on Claude Code, and on dsh up to two stores'
indexes per copy, one copy per change.
8. Agent Integration
The model holds all the agency. On Claude Code and dsh it writes with
the host's file tools, and the guards only measure. On other hosts the
protocol asks it to run engramory_check.py after each index
write and the doctor now and then. The README argues against an MCP
server: it would be a second write channel past the cap and would turn
recall into a tool the model must remember to call.
engramory_init.py writes for eleven hosts. Codex,
OpenClaw and dsh are write hosts; codex-reader,
claude-reader, dsh-reader and five more are
one writer, many readers wirings that point a host's rules file
at another host's store with a recall-only snippet. Only those three
reader wirings are marked verified against their real hosts; the rest
print an unverified note
(tools/engramory_init.py:18-28, :1072-1077).
"Read-only" there is an instruction to the model.
On dsh the plugin registers a runtime skill whose text names where
the store is now, and re-registers it when another dsh sharing the home
has moved the store (index.js:236-290). Companion mode puts
its rules in a required runtime context, so a persona preset that drops
optional context keeps them (index.js:306-312). A profile
still set to the social mode removed in 2.0 gets no memory at all until
the setting is saved away (index.js:92-100,
index.test.js:2044-2058).
9. Reliability, Safety, and Trust
What the code holds
The two guards are careful about the cases that would silently turn
them off. The Python hook reads the payload as UTF-8 bytes because a
locale decode on a Chinese Windows console either crashed it or inflated
sizes 1.5 times (hooks/engramory_index_guard.py:188-200). A
symlink or 8.3 short name to the index is still the index. A planted
multi-gigabyte index counts as unreadable instead of crashing the guard
open (:247-251). The dsh guard bounds its read of the index
at 16 MB, and committed cases pin that a FIFO named like the index
cannot hang the host and a device behind such a name cannot flood it
(index.js:52-60, index.test.js:1011-1103).
A project store cannot point recall at another file: an index that is
a symlink, or resolves outside the project root, is not read, and an
index once shown and then relinked outward is withdrawn
(index.js:1811-1830, index.test.js:1510-1526,
:1560-1573, :1736-1756).
What it leaves to the model
SECURITY.md states the limits exactly. The caps are
size nudges, not security controls. Shell tools, MCP file
tools, editors and sync clients bypass both guards, as does dsh's
apply_patch, whose paths are inside the patch text. The
store is plain text any local process can alter, and a tampered
feedback note is a stored prompt injection that Engramory
does not authenticate. Writes have no lock, so two writers can lose
updates (SKILL.md:704-707).
A repo-only note in dsh's global store reaches every
project. The default dsh store is global, project stores exist
only where the user made one, and the scope: repo label is
not consulted on the way out (section
5). SKILL.md names this failure itself: "A
repo-only rule left global leaks into other projects, where
it is simply wrong". The README lists it as No project
ID.
A correction keeps nothing. Updating in place
replaces the old text, deletion removes it, and the protocol requires a
store inside a repository to be git-ignored
(SKILL.md:49-52), so git history does not hold it either. A
user who asks why the agent once believed something has the Claude Code
transcripts and engramory_trace.py to search, on that host
only.
Marks
negative_eval— present. Committed cases assert that a store outside the session's project, and the project store when an index is pinned, are absent from a populated recall; others assert that a project index linked outward is never sent.scope_enforced— withheld.scopeis validated and never read on a read path; the project and global stores are separate directories, a physical partition with no key.trust_state— withheld. No status field;archive/is a location, and the seven types are kinds, not states.bitemporal— withheld.createdandupdatedare dates the agent types; anupcomingnote's event date lives in its name and nothing reads it.audit_log— withheld. Nothing records a mutation.engramory_trace.pysearches conversations, not changes to the store.human_review— withheld. The dsh Memory page lists notes, runs a check-up and opens a file in the desktop's editor; editing a note there is authoring after the write.tombstone— withheld. A deleted note leaves no record of its value.
10. Tests, Evals, and Benchmarks
The suites test the code there is: the caps, the recall plumbing, the
installer and the doctor. tests/test_index_guard.py (44
functions) pins the deny table, including incremental compaction, the
boundary at 200 and 201 lines, MultiEdit chains, non-UTF-8
and CJK payloads, and that the hook never emits allow.
tests/test_tools.py (133) covers check, doctor and init.
adapters/dsh/plugin/index.test.js (198 cases) drives the
plugin against mocks of dsh's services. CI runs every Python suite as a
plain script on three operating systems and two Python versions, and
runs the node suite through tests/test_dsh_plugin.py, which
skips where node is absent
(.github/workflows/test.yml).
tests/dsh_e2e/run.py installs real dsh releases into a
temporary prefix, adds the plugin and runs a scripted headless task
against a local fake model (tests/dsh_e2e/fake_llm.py). It
checks that a 260-line write is refused and leaves no file, that an LF
edit of a CRLF index is refused, that the index is injected once, and
that every tool dsh offers is in REVIEWED_TOOLS
(run.py:89-111, :423-429). An unclassified
tool fails the run. results.json holds 524 runs, all
pass and all win32; 8 are for 2.1.1, on four
dsh releases from the repository and from npm.
test_dsh_plugin.py refuses a compatible claim
in package.json without a passing run of the same version
and runtime digest. The harness is not in CI.
Nothing tests memory behaviour above the file layer: whether a model
follows the write order, files a fact under the right type, or recalls
the right note. tests/dsh_e2e/README.md says the harness
checks guard integration, not model judgment and describes
manual spot checks with a real model. No paper was found and no
benchmark result is committed.
Cases to want: a note marked scope: repo in the global
store, asserted absent from a session in another project (it would fail
at this commit); a correction asserted recoverable after the note is
rewritten; two writers racing on one index.
11. For Your Own Build
Steal
- Gate on the predicted result, and refuse only growth. A cap that blocks every write over the limit also blocks the compaction that would fix it; "ends over the cap and grew" lets the agent shrink the index one edit at a time.
- Simulate the host's edit, not your idea of it. Match on the text the host matches on (LF-normalised, BOM dropped), resolve paths against the session's directory, and judge every path field a call names.
- Send a changing context block only when its digest changes, and track what the session holds in a projection that a compaction resets.
- Make the gateway's coverage a test. Enumerate every tool the host offers, classify each, and fail when one appears unclassified.
- Refuse an injected file that a checkout can aim at another file: a symlinked index or one that resolves outside the project is never read into context.
Avoid
- Do not ship a scope label that nothing reads. If a field exists to stop a memory reaching the wrong project, the read path has to filter on it, or the default store has to be per-project.
- Do not make correction an overwrite in a store you also tell people to keep out of git. Keep the prior text somewhere.
- Do not append a full copy of a mutable index on every change when the conversation keeps the old ones; send a diff, or replace in place where the host allows it.
Fit
This is for one person and one agent writing a small, curated set of rules and decisions they want to read and edit by hand, on Claude Code or dsh, where the cap is enforced. It assumes the model follows a long protocol reliably, and the repository's own documentation claims no more than that. Walk away if memory must accrue without the model choosing to write it, if several agents write one store, if a project's notes must stay out of other projects on dsh without the user making a store per project, or if anyone will ask what a note said before it was corrected.
12. Open Questions
- Whether the Claude Code host's own load of
MEMORY.mdstill stops at 200 lines and 25 KB, which the hook's defaults assume and this tree cannot show. - How often a model on a real task files a repo-only fact in the global store.
- Whether a model weighs the newest of several index copies in one dsh conversation as the header asks.
- How the end-to-end harness fares on macOS and Linux, where
pathKeydoes not fold case.
Appendix: File Index
- Protocol:
SKILL.md,rules-snippet.md,PORTING.md,AGENT-SETUP.md,templates/MEMORY.md,templates/example-feedback.md,templates/example-project.md - Claude Code cap:
hooks/engramory_index_guard.py,hooks/settings.snippet.json,hooks/INSTALL.md - dsh plugin:
adapters/dsh/plugin/index.js(guard, recall, skill, routes, store move),adapters/dsh/plugin/client.js(settings and Memory pages),adapters/dsh/plugin/cordis.patch.yml - Tools:
tools/engramory_check.py,tools/engramory_doctor.py,tools/engramory_init.py,tools/engramory_trace.py - Reader wiring:
adapters/reader/README.md,adapters/reader/reader-snippet.md - Tests:
tests/test_index_guard.py,tests/test_tools.py,tests/test_uninstall.py,tests/test_protocol_sync.py,tests/test_dsh_plugin.py,adapters/dsh/plugin/index.test.js,adapters/dsh/plugin/client.test.js - End-to-end:
tests/dsh_e2e/run.py,tests/dsh_e2e/fake_llm.py,tests/dsh_e2e/results.json - Policy:
SECURITY.md,CHANGELOG.md
Recorded searches
Run from the repository root at the pinned commit with
/usr/bin/git grep.
scopeis read only by the doctor.git grep -n -w scope -- adapters/dsh/plugin/index.js hooks toolsreturns the two skill-text linesindex.js:3672,:3807, the doctor's docstring, comment and:685-747, and an unrelated comment inengramory_init.py:541.- No search arm over the store.
git grep -n -i -E 'embedding|vector|bm25|fts5' -- tools hooks adapters/dsh/plugin/index.jsreturns nothing; the controlgit grep -c -i -E 'embedding' -- README.en.mdcounts 1. - No status, trust or confidence key in the doctor.
git grep -n -i -E 'status|trust|confidence|verified' -- tools/engramory_doctor.pyreturns one comment about orphan status (:650). - No audit or journal.
git grep -n -i -E 'audit|journal' -- adapters/dsh/plugin/index.js tools hooksreturns two doctor comments about a filename containingaudit. - No lock in the hook, the tools or the plugin.
git grep -n -i -E 'flock|lockf|O_EXCL|msvcrt\.locking|proper-lockfile' -- hooks tools adapters/dsh/plugin/index.jsreturns nothing; the controlgit grep -c -E 'O_EXCL|wx' -- adapters/dsh/plugin/index.jscounts 2. - Recall never opens
archive/.git grep -n 'ARCHIVE_DIR' -- adapters/dsh/plugin/index.jsreturns:684and lines 1054-1402, all in the Memory page's listing and opener;indexRecallis:1685-1757. - The end-to-end harness is not in CI.
git grep -n 'dsh_e2e' -- .githubreturns nothing; the controlgit grep -n 'test_dsh_plugin' -- .githubreturnstest.yml:46. - Every recorded end-to-end run is on Windows.
python3 -I -c 'import json,sys,collections; r=json.load(open(sys.argv[1]))["runs"]; print(len(r), collections.Counter((x["result"], x.get("platform")) for x in r))' tests/dsh_e2e/results.jsonprints524and('pass', 'win32'): 524. - No submodules, no paper.
.gitmodulesandCITATION.cffare absent;git grep -n -i -E 'arxiv|doi\.org|bibtex|@article|@misc' -- . ':!*.png' ':!*.gif' ':!*.mp4'returns nothing.
History
2026-12-02 — d3b63802….
First reading, read at the user's request from the 2026-12-02 triage
shortlist, from a full clone at the head of master, two
commits after tag v2.1.1. Screened: one auto-run surface
(hooks/, holding INSTALL.md,
engramory_index_guard.py and
settings.snippet.json, which a harness can register), no
build-time execution, nothing inside the cooldown, no unpinned surface;
SECURITY.md read. Nothing was installed, built or run, and
no test was run; one Python one-liner counted the committed
results.json. One mark (section 9).