The store side of the nightly tidy (Dreaming). Tidy takes a plan: merges
of memories that say the same thing, memories to set aside, and a date
before which unreviewed distilled candidates are set aside. What the user
wrote or pinned is never rewritten or set aside; merged with others it is
the one kept, word for word, and two of them are never merged. A merge
across scopes or of a memory no longer in use isn't done. Each change is
returned with the states it replaced, and Untidy puts back only what is
still as Tidy left it; a merged memory the user edited since stays.
Run: mote-run go test -count=1 ./internal/memory: ok.
Broken by hand: dropping the user/pinned guard on stale turns
TestTidyNeverChangesTheUsers red; dropping Untidy's "still archived"
check turns TestUntidyKeepsWhatTheUserChanged red (undo: 3).
Distilling sessions (next) will propose candidates. One the user deletes
or archives is remembered by its text (Dismissed, the last 1000), and a
save from a conversation of the same text is skipped. An agent's own save
of that text is still kept. A memory an agent forgot in a scope isn't
proposed again in that scope.
Run: mote-run go test ./internal/memory (ok).
Broken by hand: Remove without dismiss, and Save without the Dismissed
check, each red in TestDismissedNotProposedAgain; restored, green.
Not tried: the distiller itself, which isn't built yet.
The agents ticked under Library → Instructions get a "## Memory" part in
their instructions: the global memories, the agent's own, and each
project's under the folders it was seen in (memory.Digest), unless
Instructions.NoMemory. The digest changes only when published, so an
agent's instructions (and the prompt cache on them) change mid-session
only then: at once when the user changes memory (PublishMemory(false),
called by the GUI), and once a day from KeepLinked's loop for what
agents saved meanwhile (PublishMemory(true) -> memory.PublishDue).
PublishDue writes nothing while memory has never held anything, so a
user who never uses memory gets no memory.json.
Run (mote-run, whole worktree, with the rest of the memory layer):
- go test ./internal/memory ./internal/library: ok (library 130.9s)
- go vet ./internal/memory ./internal/library ./internal/gui, GOOS
darwin, linux, windows: ok
- gofmt -l: clean
Broken by hand (mote-run -run TestMemoryDigestInInstructions):
- memoryDigest's NoMemory check removed: red. It first stayed green,
since the test switched NoMemory on with memory.json deleted; the test
now gives memory back and sees the part return before switching it off.
- PublishDue's "nothing kept" guard removed: red ("a due publish with
nothing kept wrote memory.json").
Not tried: a real agent reading the digest in its instructions.
The first part of the memory layer: internal/memory keeps memories in
memory.json (lastgood + atomic writes under a file lock; a file that can't
be read is unknown and never written over). Each memory has a scope
(global, project:<git remote key>, agent:<id>), a kind (profile,
preference, rule, reference, fact, procedure, episode), free tags, an
origin and a status. Saving the same text in the same scope merges into
the memory already there; an agent's save never changes the kind or why
of a memory the user wrote or pinned.
A project is keyed by its origin remote, so every clone and worktree of a
repository shares its memories. Search is word-matched with CJK split
into characters and pairs. The digest agents will be given is published
on demand (a user's change, or once a day), never at an agent's save, so
instructions don't change mid-session; its text names no app or vendor.
Nothing uses the package yet: the MCP server, the Library's digest and
the GUI come next.
Run (on mote): go test -tags nogui ./internal/memory, -race -count=3,
TZ=Asia/Shanghai; go vet for darwin, linux, windows; gofmt -l clean.
Broken by hand: an agent's save allowed to change a user's memory
(TestUsersMemoryNotChangedByAnAgentsSave red) and a digest computed live
instead of published (TestDigestChangesOnlyWhenPublished red).