substrate: sqlite state, manifest-driven housekeeping, memory tool (validated, transactional)
This commit is contained in:
@@ -19,11 +19,14 @@ forget; files don't — so the file must be shaped to forget too.
|
||||
|
||||
- **Human = the GM.** The world, every NPC, all consequences, all retcons.
|
||||
Runs on organic memory — no notes. The model's canon files are the prosthesis.
|
||||
- **Model = one PC.** Inner life, voice, choices. Nothing else. Reads memory,
|
||||
never writes it.
|
||||
- **Housekeeper = a second model invocation**, fresh context, run by the GM
|
||||
after each window. Reads the transcript and the rings; writes the rings and
|
||||
the log. Memory writes are never in-band.
|
||||
- **Player-model = one PC.** Inner life, voice, choices. Nothing else. Reads
|
||||
memory, never writes it.
|
||||
- **Housekeeper-model = a separate invocation**, fresh context, run after each
|
||||
window. Reads the transcript and the rendered rings; emits a **manifest** of
|
||||
semantic operations. Judgment, no clerical work.
|
||||
- **`tool/memory.mjs` = the clerk.** Validates and applies manifests,
|
||||
maintains the database, enforces caps, renders views, writes the log.
|
||||
Fails loudly, never drifts silently.
|
||||
|
||||
## Scope
|
||||
|
||||
@@ -34,46 +37,54 @@ explicit and logged.
|
||||
|
||||
## The protocol
|
||||
|
||||
1. **Open a window:** send `system.md`, then `character.md`, then
|
||||
1. **Refresh the views:** `node tool/memory.mjs render`
|
||||
2. **Open a window:** send `system.md`, then `character.md`, then
|
||||
`canon/ring-a.md`, then `canon/ring-b.md`, then narrate the first beat.
|
||||
(On a tight window, ring B is optional loading — ring A is the spine.)
|
||||
2. **In play:** `((double parentheses))` is the out-of-character channel —
|
||||
3. **In play:** `((double parentheses))` is the out-of-character channel —
|
||||
points of order, canon questions, proposals, vetoes. Both sides use it.
|
||||
3. **Close a window:** just stop. No in-band ritual; the player-model has no
|
||||
Entries carry stable ids (`[e17]`); citing one is the precise way to
|
||||
reference a memory.
|
||||
4. **Close a window:** just stop. No in-band ritual; the player-model has no
|
||||
end-of-session duties.
|
||||
4. **Housekeep (fresh model, new context):** send `housekeeper.md`, then
|
||||
`character.md`, then both rings, then the session transcript. The
|
||||
housekeeper gates and classifies new memories, applies touches, promotes
|
||||
and demotes on judgment, handles overflow, writes the log entry, and
|
||||
rewrites both rings.
|
||||
5. **Review, veto or edit as desired, commit.**
|
||||
5. **Housekeep (fresh model, new context):** send `housekeeper.md`, then
|
||||
`character.md`, then both ring views, then the session transcript. Save
|
||||
its manifest to `manifests/<window>.json`.
|
||||
6. **Apply:** `node tool/memory.mjs apply manifests/<window>.json` — the tool
|
||||
validates, applies, handles overflow, writes `log/<window>.md`, re-renders
|
||||
the views. A rejected manifest changes nothing and says why.
|
||||
7. **Review the log, veto or edit as desired, commit.** GM edits go through
|
||||
`insert` / `delete` / `revive` commands.
|
||||
|
||||
## The memory model
|
||||
|
||||
The player-model's entire memory is two ring buffers, under `canon/`,
|
||||
maintained by the housekeeper after each window:
|
||||
State lives in **SQLite** (`db/memory.db`); `canon/ring-*.md` are generated
|
||||
views. Markdown survives as rendering, dies as storage — the models see
|
||||
prose, the machine sees rows.
|
||||
|
||||
- **Ring A — important facts.** Changed a relationship, created an
|
||||
obligation, altered the world. Cap 500 entries.
|
||||
- **Ring B — everything else** that passed the gate. Cap 3000 entries.
|
||||
- **Cold storage** — everything evicted or deleted. Beyond the models'
|
||||
reach, GM-reachable via `revive`. Nothing is ever destroyed; the hierarchy
|
||||
is **A hot, B warm, cold dead-to-the-character**.
|
||||
- Both rings are ordered by touch — most recently touched on top, an LRU
|
||||
cache. A memory meaningfully invoked during play is *touched*: its date
|
||||
updates and it rises to the top at the next housekeeping. Untouched
|
||||
memories sink toward the tail. Mere adjacency doesn't count as a touch.
|
||||
updates and it rises. Untouched memories sink toward the tail. Mere
|
||||
adjacency doesn't count as a touch.
|
||||
- **Promotion and demotion are the housekeeper's judgment**, not metrics: a
|
||||
B entry the session showed to be load-bearing moves to A (reason logged);
|
||||
a spent A entry may move down. When unsure, leave it — if it matters, it
|
||||
will surface again, and B is generous.
|
||||
- Overflow cascades: A's tail demotes to B's top; B's tail falls out. The
|
||||
hierarchy is really three tiers: **A hot, B warm, log cold.** Eviction is
|
||||
demotion to the log, not destruction — the GM is the cold tier's only
|
||||
reader, and can restore anything.
|
||||
- **Overflow is mechanical and exact:** A spills to B, B spills to cold,
|
||||
oldest-touched first. Caps are enforced by count, not by a model's
|
||||
ability to count.
|
||||
- Combined budget: ~512KB ≈ 130K tokens ≈ half a 256K-class window.
|
||||
The caps are dials; retune freely.
|
||||
Caps are dials in `tool/memory.mjs`; retune freely.
|
||||
|
||||
Eviction pressure at this budget is near zero for a long time — on purpose.
|
||||
The judgment call isn't "what to evict," it's **"which ring"**: classification
|
||||
has replaced eviction as the thing under test.
|
||||
The judgment call under test is **"which ring"** — classification, plus the
|
||||
promote/demote eye. Everything clerical (ordering, dates, caps, overflow,
|
||||
rendering, logging) is code.
|
||||
|
||||
Why this shape: it's an LRU cache, it's generational GC, and — most
|
||||
relevantly — it's how hippocampal memory works. Retrieval strengthens a
|
||||
@@ -90,26 +101,29 @@ in play and the touch machinery does the rest. If you notice yourself wanting
|
||||
a manual override — that's a signal to improve the system, not to press a
|
||||
knob.
|
||||
|
||||
`log/` is **write-only for every model**. The housekeeper writes it fresh
|
||||
each pass and never reads old entries; the player never reads it at all.
|
||||
`log/` and the `events` table are **write-only for every model**. The
|
||||
housekeeper never reads old entries; the player never reads any. Past
|
||||
sessions are not the character's memory; the rings are.
|
||||
|
||||
## What's being tested
|
||||
|
||||
After N windows, grade against:
|
||||
|
||||
1. **Classification quality** — the housekeeper's A/B calls; spot-check
|
||||
against the log.
|
||||
against the log and the transcript.
|
||||
2. **Promotion/demotion quality** — did the facts that turned out to matter
|
||||
actually rise? Spot-check against the transcript.
|
||||
3. **Verbatim fidelity** — untouched entries must not drift. Rewording
|
||||
during mechanical rewrites is the sneakiest failure mode; the commit
|
||||
diffs are the drift detector. Look for it.
|
||||
4. **Touch fidelity** — did everything the transcript meaningfully invoked
|
||||
actually rise at housekeeping?
|
||||
3. **Touch fidelity** — did everything the transcript meaningfully invoked
|
||||
get touched? (The `events` table makes this a query, not an archaeology
|
||||
dig.)
|
||||
4. **Manifest hygiene** — do ops reference real ids, in the right rings?
|
||||
(Malformed manifests are rejected mechanically; *valid-but-wrong* ops —
|
||||
touching things never mentioned, promoting noise — are the model's
|
||||
errors and the real observable.)
|
||||
5. **Availability bias incidents** — quiet-crucial facts sinking; rescued
|
||||
or missed?
|
||||
or missed? (`status` shows what's sinking.)
|
||||
6. **Growth curve** — memory should approach the caps asymptotically, not
|
||||
climb linearly.
|
||||
climb linearly. (`status` per commit.)
|
||||
7. **Purview discipline** — inventions logged and mostly color-tier; no NPC
|
||||
puppeting; outcomes left to the GM.
|
||||
8. **Confabulation** — zero invented continuity not present in the rings.
|
||||
@@ -127,17 +141,15 @@ minors, gratuitous violence. These live in `system.md`; edit them there.
|
||||
## Housekeeping
|
||||
|
||||
This directory is a git repo. Every housekeeping pass should end in a commit
|
||||
— the diff between commits *is* the classification and drift record. No
|
||||
model touches git; the human commits.
|
||||
— the diff over `canon/`, `log/`, and `manifests/` is the classification and
|
||||
drift record. No model touches git; the human commits.
|
||||
|
||||
The housekeeper may be a different model than the player — cheaper, or more
|
||||
pedantic, whatever housekeeping needs. The two prompts are independent.
|
||||
|
||||
**Future substrate note:** the housekeeper already is a separate job — it
|
||||
maps 1:1 onto a backend task at session end. When the SPA arrives, the
|
||||
housekeeper can emit a manifest (insertions, touches, promotions, evictions)
|
||||
and let code execute the file mechanics deterministically. Both prompts
|
||||
survive that split unchanged; only the hands doing the typing change.
|
||||
**Substrate note:** the future SPA is a UI and a session runner wrapped
|
||||
around exactly these moving parts — the DB, the manifest, `apply`, `render`.
|
||||
Nothing gets redesigned; the SPA just stops the copy-pasting.
|
||||
|
||||
## Layout
|
||||
|
||||
@@ -145,8 +157,14 @@ survive that split unchanged; only the hands doing the typing change.
|
||||
system.md system prompt for the player-model (play-side only)
|
||||
housekeeper.md system prompt for the post-session housekeeping model
|
||||
character.md the model's PC sheet (GM fills in before window one)
|
||||
tool/
|
||||
memory.mjs the clerk: init, render, apply, insert, delete, revive, status
|
||||
db/
|
||||
schema.sql entries + append-only events journal
|
||||
memory.db the state (SQLite; binary — diffs live in canon/ and log/)
|
||||
manifests/ housekeeper manifests, one JSON per window (diffable)
|
||||
canon/
|
||||
ring-a.md important facts — MRU-ordered, tail demotes
|
||||
ring-b.md everything else — MRU-ordered, tail evicts to the log
|
||||
log/ session log — housekeeper writes, no model ever reads
|
||||
ring-a.md GENERATED view: important facts, MRU-ordered
|
||||
ring-b.md GENERATED view: everything else, MRU-ordered
|
||||
log/ session logs — generated from manifests; no model ever reads
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user