Commit Graph
7 Commits
Author SHA1 Message Date
yetone d77eb6d236 memory: search by meaning, on a small model on this computer
A memory search now finds what means the same in other words or another
language ("什么时候上线" finds "Releases go out on Tuesdays"), for the
MCP server's memory_search and the Library's Memory tab alike. It is off
until switched on under Memory → Search by meaning, since it downloads
paraphrase-multilingual-MiniLM-L12-v2 (Xenova's int8 ONNX, ~135 MB,
pinned revision, size and sha256 checked); switched off, the model is
deleted.

- internal/pii/guard: the BERT code runs the embedder too (LoadEmbedder,
  mean pooling; the tokenizer reads 250,002 pieces and WhitespaceSplit).
  Its vectors match ONNX Runtime's int8 to cosine >= 0.995 and are no
  further from fp32 than ORT's own; testdata carries both.
- internal/memembed: the switch, the download, vectors.bin keyed by each
  memory's sha256 (read once, again when the text changes, a cut-short
  file read as none), Keep reading in the backend, the model let go after
  10 minutes unused.
- internal/memory: memory.Semantic fuses the meaning ranking with the word
  ranking by reciprocal rank; a tie goes to the nearer in meaning, since
  a first word hit may hold one common word ("when do we release" had
  "Never delete images when..." first). Near 0.30 / Within 0.15 come from
  97 real memories and 16 queries, half Chinese for English memories:
  12 of 16 sought found with ~4 others each. Rank searches without noting
  memories used.
- GUI: the Search by meaning row (download %, memories read, failures),
  and the tab's search lists what the backend ranked first
  (POST /api/memory/rank), then word matches. zh, zh-TW, ja, de.
- docs/subsystems/memory.md: the section, out of "Not built yet".

Why not multilingual-e5-small, which this was built on first: run for
real, its cosines sat at 0.78-0.89 for everything, and a Chinese search
ranked Chinese memories over the English one it meant. e5-small, e5-base
and MiniLM were compared in ONNX Runtime on the same 97 memories; MiniLM
put the sought one first 9 of 16 and in the top 3 12 of 16, with the
rest at a median cosine of 0.16.

Run before the rebases (mote, on origin/main as of the work):
- gofmt -l internal/ clean; go vet of memembed, memory, pii/..., gui,
  library; GOOS=linux and GOOS=windows vet of memembed and pii/guard.
- MAGPIE_EMBED_DIR=~/models/pml go test -run Embedder ./internal/pii/guard:
  7 texts (CJK, full width, emoji, digits before runs of spaces) at
  0.9962-1.0000 with ORT int8.
- go test memembed, memory, memdistill, pii/..., library, browsermcp.
- Linux (magpie-desktop, -tags nogui, mote's disk was full): go test
  memembed, memory, pii/guard, gui (461s), cli (1228s, past the default
  10m timeout, so -timeout 30m); gateway -run 'MemoryMCP|OwnMCP'.
- Rebased on origin/main 3ebb1ba2c, on mote at this tree: gofmt -l
  internal/ clean; go vet of memembed, memory, pii/..., library, gui,
  gateway, and GOOS=linux and GOOS=windows vet of the first four; go
  test memembed, memory, pii/..., library, browsermcp (Embedder test on
  ~/models/pml); gateway -run 'MemoryMCP|OwnMCP'; cli -run
  'Settings|Parity|Budget'.
- Rebased again on origin/main 5d6935b11 (title bar, cli parity,
  account export, provider catalog): go vet of gui and cli; go test -run
  'Settings|Parity|Budget' of cli and gui, ok with the Bark test fix two
  commits up (TestSettingsSaveKeepsWhatItDoesNotSend, red on main).
- GUI on mote, this commit plus the next (90f4a377b, which fixes
  library-bar-more for #5982): every library-*.test.cjs, i18n-keys and
  i18n-en-no-cjk, BROWSER=chromium and webkit, 701/702 each. The red is
  library-loading's tab list, which has no "Claude plugins" (6af54dc9a)
  and is red alone at origin/main faffb1e95 (#5997). library-bili's
  webkit saved count times out about 1 run in 3, on main too (#6015).
- A real switch-on: the pinned files downloaded from Hugging Face and
  checked in 11s, 5 memories read; 什么时候上线, 端口被占用怎么办, 清理磁盘,
  回复用什么语言 and "when do we release" each find their memory first.
  缩进用什么 finds nothing (0.23 to the tabs memory, under Near).
- Broken by hand: without the tie rule, TestSearchFindsByMeaning's new
  case is red (images first).

Not run: the whole Go suite and the whole GUI suite; go test of
internal/gui and the whole of internal/cli after the rebases (WSL kept
restarting, and they passed on Linux before).
2026-11-11 04:14:58 +08:00
yetone 8a76daf3b2 library: a row's controls share one centre line, the switch too
The Memory tab's "Learn from conversations" and "Tidy up every night"
rows put a 19px switch beside ~30px buttons in .lib-acts, a flex row
with no align-items, so the switch sat at the top, ~3.5px above the
buttons' centre (the owner's screenshot). .lib-acts now centres its
items.

library-memory.test.cjs checks that every control of both rows shares
one centre line, per wrapped line at narrow widths.

Run (wsl-run, magpie-desktop at load ~50; mote refused SSH):
- library-memory.test.cjs: 22 pass, Chromium and WebKit, every
  language, wide and narrow.
- Broken by hand: without align-items the new check is red
  (211.9 vs 215.4).
- All 62 library-*.test.cjs, concurrency 4: 1346 pass, 8 red in 4
  files. Alone, with and without this change:
  - library-mcp-copy-config ja (chromium): red on main too, #5941.
  - library-chip-fan: frame-timing reds at both trees' load (3 of 12
    alone runs); its page has no .lib-acts (probe counted 0). Shapes
    added to #3072.
  - library-items, library-mcp-tool-switch: green alone.
2026-11-10 20:20:55 +08:00
yetone 350856f512 memory: read a backlog of conversations at once, with progress and a Stop (RealZeroP27 on X)
Every run, the hourly one and Read now alike, read at most 10
conversations (PerRun), so a backlog of 400 (All) took 40 hours.

- A run the user asks for reads every conversation due
  (memdistill.ReadAll, through distillNow): switching on, picking a
  model or a longer range, and Read now. Still one request at a time,
  at the picked model and reasoning level.
- The hourly run reads up to 30 (PerRun, was 10), more than a busy
  hour brings, so only a backlog left by a stop or a failure waits for
  it.
- The row shows how far a run has gone ("Reading conversations… 37 of
  400", Progress -> doing/of in GET /api/memory/distill), with a Stop
  (memdistill.Stop, POST /api/memory/distill/stop); switching off stops
  it too. A stop drops the request in flight, which is read next time,
  and isn't an error.
- After a run the row says how many it left unread (State.Left), and
  Read now reads them. All's menu note no longer says "10 an hour".

docs/subsystems/memory.md says all of this.

Run (mote; all at base bb4dd8679, then the Go tests again at this head
on 53280aa08, which touches sessions stats only: ok):
- go test -count=1 ./internal/memdistill ./internal/memory: ok;
  -race -count=3 ./internal/memdistill: ok
- go test -count=1 -run 'Distill|Dream|Budget' ./internal/gui: ok
- node --test library-memory.test.cjs i18n-keys.test.cjs, chromium and
  webkit, 980 and 420 wide, every language: 26 pass, 0 fail
- go vet darwin; GOOS=linux -tags nogui; GOOS=windows (memdistill,
  gui): ok. gofmt -l: clean.

A sandbox backlog: TestBacklogReadAtOnce lists 400 (Listed)
conversations under All; the hourly run reads 30 and leaves 370,
ReadAll reads all 370 with progress 1 of 370 to 370 of 370, and reads
none again.

Broken by hand:
- ReadAll capped at PerRun again: TestBacklogReadAtOnce red (read 30)
- Stop without cancelling the run: TestStopEndsTheRun times out

Not tried: a real run of a 400-conversation backlog against a real
model and account (how long it takes depends on the model; one request
each); the full suite (started after the tag).
2026-11-10 14:01:23 +08:00
yetone 0e68455863 memory: pick how far back conversations are read, and the model's reasoning level (RealZeroP27 on X)
Learn from conversations read the last 7 days only (Back, fixed at
switch-on) and asked its model with no reasoning level. Its row now has
two more pickers, beside the model:

- How far back it reads: 7 days (default), 30, 90, 1 year or All
  (State.Days; 0 stays 7 days, so an existing distill.json keeps its own
  Since until a range is picked). A longer range reads at once. Every
  range reads from the latest 400 conversations (memdistill.Listed) at
  10 an hour (PerRun), so All is ~240 requests a day at most until the
  backlog is read; All's menu note says so.
- Thinking: Default (none sent, as before) or one of the model's own
  levels, fitted and sent with room to think the way Vision and Searcher
  do (gateway.WithSideEffort over sideEffort/replyRoom/withFixedEffort).
  The nightly tidy uses the same level, and its row shows the picker
  when distilling is off.

Fixed on the way, as the longer ranges depend on it: a conversation's
mark was dropped after 30 days while Since stayed put, so anything
older than 30 days inside Since was read again every hour. A mark is now
dropped once it is before Since, or older than 30 days and past the
oldest conversation listed.

POST /api/memory/distill takes effort and days; a bad one is a 400.
docs/subsystems/memory.md says all of this.

Run (mote; first at base 4bfac1268, then memdistill, gui Distill|Dream|Budget and both GUI files again at this head on e697e7ddf: ok, 26 pass):
- go test -count=1 ./internal/memdistill ./internal/memory ./internal/gui: ok
- go test -count=1 -run 'Distill|Dream|Effort' ./internal/gateway: ok
- node --test library-memory.test.cjs i18n-keys.test.cjs, chromium and
  webkit, 980 and 420 wide, every language: 26 pass, 0 fail
- go vet darwin; GOOS=linux -tags nogui; GOOS=windows (memdistill, gui,
  gateway): ok. gofmt -l: clean.
- win-run go test ./internal/memdistill: ok

Broken by hand:
- the old 30-day mark prune: TestOldConversationReadOnce red
- distillComplete without WithSideEffort: TestDistillCompleteThroughGateway
  red (high sent with thinking disabled, max_tokens 4096)

Not tried: a real distill run with a real account at a picked level or
over All; the full suite (started after the tag).
2026-11-10 12:16:51 +08:00
yetone 2c2bd15d71 memory: Tidy up every night, a switch in the Memory tab
The Memory tab gets a second row under Learn from conversations. It is
off by default. Switched on, the first tidy is due at the next 03:00.
Tidy now runs one at once, and Undo puts the last one back. While
distillation is off, the row has its own model picker; both rows share
one model.
Routes: POST /api/memory/dream {on}, /dream/run and /dream/undo.
GET /api/memory/distill carries "dreaming", so a tidy no longer shows
as conversations being read.

The prompt's stale rule is narrower. On the first real run it set aside
two decisions because "the work is done". Now only a note that later
notes contradict, one past its date, or one about a finished one-off
task is stale; a decision, direction or preference stays.
docs/subsystems/memory.md gets a Dreaming section.

Real run: a sandbox memory.json of 62 real distilled memories, 12 active
and one each user-written and pinned, with auto/claude-haiku-5-5 through
the live gateway.
- Before the prompt change: 12 changes in 48s, 10 merges and 2 set aside.
  Both set-aside notes were decisions.
- After: 12 merges in 46s, none set aside. Each merge joins real
  duplicates (three ~/.codex/sessions cleanup rules into one, the
  TestFlight 1.66/1.68 pair). One went into the fixed memory, whose text
  was kept word for word.
- Undo: 25 restored. memory.json's ids and statuses equal the backup
  taken before the run, and every merged memory is gone.

Broken by hand, each red:
- Undo not reloading the list: library-memory 22 failed.
- Ignoring DreamSince: TestDreamsOnceANight.
- A plan applied after an error: TestDreamFailureChangesNothing.
- Tidy's fixed guard and Untidy's status check: their memory tests.

Run on mote at this tree:
- go test internal/memory, memdistill, library: ok.
- internal/gui -run 'Distill|Dream|I18n|Budget': ok.
- library-memory.test.cjs: 22/22 in both engines.
- i18n-keys and i18n-en-no-cjk: 4/4 each.
- go vet (darwin), GOOS=linux -tags nogui, GOOS=windows: ok.
Not run yet: the full suite at this head.
2026-11-10 03:25:45 +08:00
yetone 4d12d44163 memory: Learn from conversations, a switch in the Memory tab
The Memory tab gets a row that reads finished conversations into
candidate memories (To review). It is off until switched on; switched
on it reads at once, then hourly (5 minutes after start, then every
hour), through the gateway this process serves under the agent
"memory", with the automatic model unless one is picked through the
app's menu. Read now runs it again; a run that stopped says why.

- memdistill: Keep (the hourly loop) and Running.
- gui: /api/memory/distill (GET, POST {on, model}), /distill/run;
  distillComplete posts /v1/messages to the served gateway's handler
  with the memory agent's token.
- library client: the row, its poll while a run goes, and the
  memories reloaded when it ends; strings in zh, zh-TW, ja, de.
- docs/subsystems/memory.md: a Distillation section.

Run (mote, at this tree):
- go vet ./internal/gui ./internal/memdistill ./internal/memory; GOOS=linux
  -tags nogui and GOOS=windows vet of gui and memdistill: clean.
- go test ./internal/gui ./internal/memdistill ./internal/memory
  ./internal/library: ok.
- node --test internal/gui/tests/library-memory.test.cjs: 22/22, Chromium
  and WebKit, 5 languages, 980 and 420.

Broken by hand:
- the memories not reloaded after a run: the GUI test is red waiting
  for the proposed memory.
- the token not the memory agent's (earlier): TestDistillCompleteThroughGateway
  red on the Trace's agent.

Not tried yet: a real model's run (next), the whole GUI suite (queued
behind the suite lock on mote), the full Go suite.
2026-11-10 03:25:45 +08:00
yetone 2b2ee49ded gui: the Library's Memory tab
A tab after Instructions lists what the agents remember, in use, to
review (what an agent only guessed) and archived, pinned first then
newest; searches it, narrows it by where it applies, and adds, edits,
pins, keeps, archives and deletes memories (Delete asks with a second
click). Kind and scope are picked from the app's menu, never a <select>.
A card on top switches the digest in the ticked agents' instructions on
or off and names those agents, and offers Magpie Memory while it isn't
in the Library.

/api/memory (GET; POST saves the user's own or edits by id),
/api/memory/remove and /api/memory/digest; a change publishes the digest
at once and its reply carries `problem` when that failed.

Words other code also says (Archived, Pin, Keep, the kinds…) are in core
i18n.js; the rest in the library plugin's, in zh, zh-TW, ja and de.
docs/subsystems/memory.md describes the layer.

Run (mote-run):
- node --test internal/gui/tests/library-memory.test.cjs, Chromium and
  WebKit, 5 languages, 980 and 420 wide: ok
- whole GUI suite: not run at this commit; it is queued on mote for the stack head (034f249af before the rebase)
- go vet ./internal/gui, GOOS darwin, linux, windows: ok
Broken by hand: the pinned sort read `b.pinned - a.pinned` (NaN for an
unpinned one) and the test was red in every language until `!!`.
Looked at: screenshots en light 980, zh dark 980, en 420.
2026-11-10 03:25:44 +08:00