Commit Graph
5 Commits
Author SHA1 Message Date
yetone 73ecef0b36 memory: each memory is a Markdown file of its own
memory.json held every memory in one JSON file, which grew without
bound, was hard to read or fix by hand, and was rewritten whole on every
change. Memory is now a folder, `memory/` beside where memory.json was:

- `<id>.md` is the memory: YAML front matter (kind, scope, status,
  origin, pinned, tags, why, sources, times) and the text as the body.
  The file is the source of truth.
- `meta.json` holds what isn't one memory's: projects, the digest,
  dismissed texts, deletions, declined suggestions, when a search last
  returned each memory (so a search never rewrites a memory's file), and
  the hash of each file as magpie last wrote it.
- `index.json` is a cache of the parsed files by size and mtime only:
  deleted or garbled, memory reads the same.
- `journal.json` holds a change to more than one file (a merge, a sync)
  before any is written; the next read finishes one cut off halfway.

A file whose hash isn't the one magpie wrote was edited or added by hand:
it is the user's (origin user, Edited), so a tidy leaves it and an
agent's change synced from another computer never writes over it. A file
with no front matter is a global fact named by its file. A write leaves
any file that changed on disk since it was read (a hand edit made
meanwhile), and so does a remove. A file that can't be parsed is left
out and never written over nor removed, sync included; meta.json that
can't be read is unknown (an error), as memory.json was.

memory.json is moved in on the first read, all under one journal, and
kept as memory.json.migrated. One that can't be read is an error and
nothing is written.

The scope of a hand-written file keeps its case (a project's holds a
path); "global" in any case is global.

Ran at this head (rebased on origin/main 50d88f17c), on mote:
- go test -count=1 ./internal/memory ./internal/memdistill
  ./internal/memembed ./internal/backup ./internal/library ./internal/gui:
  ./internal/davsync ./internal/appdir: ok; go vet ./internal/...: ok;
  go test -run 'Memory|memory|Doc|Subsystem' ./internal/...: 98 ok
- go vet ./... and GOOS=windows go vet ./... (before the rebase, whose
  three commits touch no memory code): ok; gofmt -l: clean
- win-run go test ./internal/memory ./internal/backup: ok
- wsl-run go vet of memory, backup, library, memdistill, memembed,
  davsync and go test of memory, backup, memdistill: ok
- A copy of the real memory.json (206 memories) migrated in a sandbox:
  every field of every memory the same on the first read, from the
  index, and with the index rebuilt; no memory read as the user's.

Broken by hand, each red, green restored:
- no journal: TestCutOffChangeIsFinished
- no on-disk hash check on write: TestHandEditDuringAChangeStays
- no on-disk hash check on remove: TestHandEditDuringARemoveStays
- broken files written: TestBrokenFileIsLeftAsItIs
- no hand-edit detection: TestHandEditIsTheUsers
- scope lowercased: TestEachMemoryIsAMarkdownFile (and memdistill's
  TestReadsQuietSessionsOnce, which found it)

Not tried: the full go test ./... (mote and mica both over their cores);
the live app's own memory moved in (a sandbox copy only);
`go vet ./...` on Linux (the WSL box has no gtk4 headers for Wails);
a hand edit through a sync service's own conflict copies.
2026-11-14 14:27:01 +08:00
yetone af212c9454 tests: memory's date test holds its own zone, not time.Local
TestMemorySearchDatesInLocalTime (4028687b8) set time.Local to +08:00.
time.Local is read by every time.Now, so the swap raced an http conn
goroutine an earlier test (serveMTLSGateway) left finishing: main's Test
run 43194740198 at 727e23637 went red on macOS -race with a DATA RACE
on time.Local, memory_mcp_test.go:262 against net/http setState.

Now no test touches time.Local here:
- memoryStamp writes in memoryZone(), time.Local by default, a variable
  the gateway test sets.
- The half that checked a new save keeps its zone moved to memory's own
  TestSaveKeepsTheLocalZone, which holds memory's clock (now) at 04:30
  +08:00 and reads "+08:00" back from memory.json.

Run on mote: go vet ./internal/memory ./internal/gateway, linux nogui
and windows vet of both; go test ./internal/memory ok;
go test -race -count=3 -run ^TestMemory ./internal/gateway ok; gofmt -l
empty. Broken by hand, each red: Save's now() as now().UTC() fails
TestSaveKeepsTheLocalZone; memoryStamp in time.UTC fails
TestMemorySearchDatesInLocalTime ("2026-11-10T20:30Z").
Not run: the full gateway package (the race needs a leftover goroutine
from another test, so it isn't reproduced on demand; the swap that it
raced on is gone). Same class still open: #2949 (TestHeldClock) and
#4360 (testenv.Zone's cleanup), which swap time.Local too.
2026-11-12 18:58:43 +08:00
yetone 6a253f8af7 memory: pick several memories and keep, archive or delete them at once (RealZeroP27 on X)
Library -> Memory reviewed one memory at a time: To review held
candidates that had to be opened and kept or deleted one by one.

- Select (beside the filters, shown when two or more are listed) puts a
  box on each memory. A click picks one, Shift-click the range from the
  last one clicked, up/down move between the boxes (Shift picks as it
  goes), Cmd/Ctrl+A picks all shown, Escape ends it. A search or filter
  unpicks what it hides.
- The bar under the list (the library's lib-pickbar, as Skills' Select)
  keeps (To review), archives (In use) or restores (Archived) the picked
  ones, and deletes them on a second click.
- POST /api/memory/status {ids, status}: memory.SetStatus changes them in
  one write, each as Edit by the user (an archived inferred memory is
  dismissed, so it isn't proposed again). Unknown ids are skipped; none
  found, or a bad status, is a 400 and changes nothing.
  Delete reuses POST /api/memory/remove {ids}.

Run (mote, at this head):
- go test ./internal/memory ./internal/memdistill ./internal/library: ok
- go test -run 'Memory|Distill|Dream' ./internal/gui: ok
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
  ./..., and the three builds: ok. gofmt -l: clean.
- library-memory-select.test.cjs (new): 22/22, chromium and webkit,
  en/zh/zh-TW/ja/de at 980 and 420 wide (no native select, no sideways
  overflow).
- Every library-*, i18n-* and gui-* GUI file (67), both engines: 1309 of 1309 pass.
- Rebased on 2219fdd49: i18n-keys, library-memory, library-memory-select
  and library-bili 132/132; go test ./internal/memory and -run Memory
  ./internal/gui ok (at d374168d0; only a
  client_icons test changed in those packages since).

Broken by hand:
- SetStatus without editIn: TestSetStatusOfSome red ("after keeping two:
  candidate candidate candidate candidate"), and
  TestMemoryStatusRouteActsOnSome red.
- memPick with no Shift range: the GUI test red (got [c1, c4], wanted
  c1..c4).

Not tried: the real app with a real memory.json, the WebKitGTK Linux app,
Windows' WebView2.
2026-11-10 16:00:30 +08:00
yetone d61171d245 memory: a distilled memory the user threw away isn't proposed again
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.
2026-11-10 03:25:45 +08:00
yetone 4f0c587306 memory: a store of what agents learn about the user, shared by every agent
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).
2026-11-10 03:25:44 +08:00