Files
boxmaker/docs/plans/M5a/08-memoryd-index.md
T
kyleandClaude Opus 5.5 de1032157b Plan M5a: local memory in 15 tasks
memoryd (files, the check, edits, journal, index, recall, serving),
the memory tools and built-in grants in brokerd, the memory block in
loopd, bxctl reindex and memory, and the device checks with memoryd.

Each task was built as a reference and gated. Each was replayed on its
own at its end state (854 to 936 tests) and mutation-checked. Each
skeleton compiles and fails its tests. Every todo comment was read
beside its signature.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 15:32:54 -07:00

2.2 KiB

M5a task 08: the index

Branch: m5a (run git switch m5a; git status --short must be empty, otherwise stop) Commit subject: memoryd: the FTS5 index over session logs and notes, with labels

Goal

index/memory.sqlite3 (M5a spec, section 6): an SQLite FTS5 table of text and a table of where each came from. Indexed: the owner's messages, the assistant's replies, and each tool call by name and arguments; never a tool's result. Each record is labelled with the session's label at that point in its log (the highest class of any earlier tool result, and whether any was untrusted). Records above [index] max_class are left out. It keeps, per log, how many records it has read, so it only reads what is new; and it can be rebuilt whole into a new file renamed over the old one.

The rusqlite calls you need, checked on docs.rs for 0.40.2: Connection::open(path), conn.execute_batch(sql), conn.execute(sql, params![..]), conn.query_row(sql, params![..], |row| row.get(0)), conn.last_insert_rowid(). u64 and usize are not SQL types in rusqlite: pass i64 (the skeleton's int does that).

Files

  • Copy (skeleton): crates/memoryd/src/index.rs
  • Copy (tests): crates/memoryd/tests/index.rs, crates/memoryd/tests/support/logs.rs
  • Modify: crates/memoryd/src/lib.rs (pub mod index; after pub mod files;), docs/implementer-log.md

The skeleton

Written: SCHEMA, Source, Counts, Index, db, class_name, class_of, int, and Index::conn. Fill: open, progress, add, set_progress, index_record, index_log, index_notes, catch_up, logs, rebuild.

Steps

  • 1. Copy the three files; edit lib.rs.
  • 2. See it fail. cargo test -p memoryd --test index: 6 failed.
  • 3. Fill the functions in the order listed. cargo fmt --all.
  • 4. See it pass. The same command, three times: 6 passed each time.
  • 5. Run the gate. make gate: gate: ok, 6 more tests than before (about 906).
  • 6. Log and commit. git add -A crates/memoryd docs/implementer-log.md Cargo.lock && git commit

Done when

  • make gate prints gate: ok.

Stop and report if

  • A test fails after the functions follow their comments exactly. Do not edit a test.