boot: backdrop tier, one-time seed migration, init stubs

This commit is contained in:
2026-11-11 18:52:04 +00:00
parent f5aa09c686
commit 25469b934c
6 changed files with 173 additions and 15 deletions
+31 -10
View File
@@ -50,14 +50,32 @@ Two interleaved stories calibrate the memory system against itself:
`node tool/memory.mjs runs` shows fill levels; `--run <name>` overrides the `node tool/memory.mjs runs` shows fill levels; `--run <name>` overrides the
`config.json` default for any command. `config.json` default for any command.
## Booting a run
1. **Backdrop** — write `runs/<story>/backdrop.md`: the world as everyone
in it knows it. Public knowledge, general setting. Neither memory nor
state — never touches the rings, never decays, always in the bundle.
The housekeeper is instructed to keep it out of the rings.
2. **Character** — write `runs/<story>/character.md`: starting identity.
Blanks are the player's to invent through play (their past is their
purview); the GM ratifies notable inventions into the card afterward.
That's the freeform version of a random roll — no tables.
3. **Seed** — write `runs/<story>/seed.json` and run
`node tool/memory.mjs seed`. A one-time, all-or-nothing migration:
`entries` → the rings (initial memories), `status` → starting values,
`records` → pre-existing files (gated by `settings.json`). Refuses if
the run has any history; `--force` only on a disposable db. Everything
is journaled under window `seed`.
4. **First window** — `render`, paste the bundle, narrate.
## The protocol ## The protocol
1. **Refresh the views:** `node tool/memory.mjs render` (default run comes 1. **Refresh the views:** `node tool/memory.mjs render` (default run comes
from `config.json`; `--run <name>` overrides) from `config.json`; `--run <name>` overrides)
2. **Open a window:** send `system.md`, then `runs/<story>/character.md`, 2. **Open a window:** send `system.md`, then `runs/<story>/backdrop.md`,
then `runs/<story>/canon/status.md`, then `ring-a.md` and `ring-b.md`, then `character.md`, then `canon/status.md`, then `ring-a.md` and
then narrate the first beat. (On a tight window, ring B is optional `ring-b.md`, then narrate the first beat. (On a tight window, ring B is
loading — ring A is the spine.) optional loading — ring A is the spine.)
3. **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. points of order, canon questions, proposals, vetoes. Both sides use it.
Entries carry stable ids (`[e17]`); citing one is the precise way to Entries carry stable ids (`[e17]`); citing one is the precise way to
@@ -68,8 +86,9 @@ Two interleaved stories calibrate the memory system against itself:
4. **Close a window:** just stop. No in-band ritual; the player-model has no 4. **Close a window:** just stop. No in-band ritual; the player-model has no
end-of-session duties. end-of-session duties.
5. **Housekeep (fresh model, new context):** send `housekeeper.md`, then 5. **Housekeep (fresh model, new context):** send `housekeeper.md`, then
the run's `character.md`, then both ring views, then the session the run's `backdrop.md` and `character.md`, then both ring views, then
transcript. Save its manifest to `runs/<story>/manifests/<window>.json`. the session transcript. Save its manifest to
`runs/<story>/manifests/<window>.json`.
6. **Apply:** `node tool/memory.mjs apply runs/<story>/manifests/<window>.json` 6. **Apply:** `node tool/memory.mjs apply runs/<story>/manifests/<window>.json`
— the tool validates, applies, handles overflow, writes the run's — the tool validates, applies, handles overflow, writes the run's
`log/<window>.md`, re-renders the views. A rejected manifest changes `log/<window>.md`, re-renders the views. A rejected manifest changes
@@ -83,11 +102,12 @@ State lives in **SQLite** (`runs/<story>/db/memory.db`); `canon/ring-*.md`
are generated views. Markdown survives as rendering, dies as storage — the are generated views. Markdown survives as rendering, dies as storage — the
models see prose, the machine sees rows. models see prose, the machine sees rows.
Memory is **five tiers**: Memory is **six tiers**:
| tier | what | in context | who writes it | | tier | what | in context | who writes it |
|---|---|---|---| |---|---|---|---|
| **identity** | the character sheet — concept, drives, skills, voice; changes rarely | always | GM, rarely; housekeeper may propose via open questions | | **backdrop** | the world as everyone knows it — public knowledge, the general setting; never memory, never forgotten | always | GM, rarely (retcons) |
| **identity** | the character sheet — concept, drives, skills, voice; changes rarely | always | GM, rarely; housekeeper may propose via open questions; blanks are the player's to invent |
| **status** | her current self — mood, outfit, condition, stances toward people. State, not memory: no history, no decay, updated in place | always | **the player** (`((status key: value))`); GM override exceptional and journaled | | **status** | her current self — mood, outfit, condition, stances toward people. State, not memory: no history, no decay, updated in place | always | **the player** (`((status key: value))`); GM override exceptional and journaled |
| **rings A/B** | salient memory — facts, on her mind, MRU-evicted | always | housekeeper manifest | | **rings A/B** | salient memory — facts, on her mind, MRU-evicted | always | housekeeper manifest |
| **records** | her files — the card index, the ledger. Narrow query only, hard cap 10 (in the tool, not the prompt), never bulk-loaded | never — on demand | **the player** (`file`/`amend`/`discard` at her desk); GM seeds; housekeeper only `archive`s | | **records** | her files — the card index, the ledger. Narrow query only, hard cap 10 (in the tool, not the prompt), never bulk-loaded | never — on demand | **the player** (`file`/`amend`/`discard` at her desk); GM seeds; housekeeper only `archive`s |
@@ -246,7 +266,8 @@ tool/
db/ db/
schema.sql entries, records, status, events journal (shared) schema.sql entries, records, status, events journal (shared)
runs/ runs/
prisoners/ one story: character.md, settings.json, db/, dumps/, canon/ prisoners/ one story: backdrop.md, character.md, seed.json, settings.json,
(status.md, ring-a.md, ring-b.md), log/, manifests/ db/, dumps/, canon/ (status.md, ring-a.md, ring-b.md),
log/, manifests/
boutique/ same shape — records enabled (the shopkeep's PC) boutique/ same shape — records enabled (the shopkeep's PC)
``` ```
+5 -1
View File
@@ -14,6 +14,8 @@ You never play, you never edit files, you never see the database directly.
- this prompt - this prompt
- `character.md` — whose memory this is - `character.md` — whose memory this is
- `backdrop.md` — the world's public knowledge, so you know what is *not*
memory
- `canon/ring-a.md` and `canon/ring-b.md` — rendered views of the memory, - `canon/ring-a.md` and `canon/ring-b.md` — rendered views of the memory,
entries ordered by last touch, each carrying a stable id like `[e17]` entries ordered by last touch, each carrying a stable id like `[e17]`
- the transcript of the ended session - the transcript of the ended session
@@ -71,7 +73,9 @@ date for you. Don't list an id twice across operations.
2. **Gate — what enters at all.** A new memory must pass: would the 2. **Gate — what enters at all.** A new memory must pass: would the
character remember this a month from now, or would an upcoming scene character remember this a month from now, or would an upcoming scene
change if it were wrong? If neither, it dies here, unrecorded. change if it were wrong? If neither, it dies here, unrecorded. **Public
knowledge (the backdrop) never passes** — it isn't news to her. Only
what she experienced, learned, or suffered is memory.
3. **Classify.** Ring A only for what changed a relationship, created an 3. **Classify.** Ring A only for what changed a relationship, created an
obligation, or altered the world. Everything else that passed the gate obligation, or altered the world. Everything else that passed the gate
+9
View File
@@ -0,0 +1,9 @@
<!-- The world as everyone in it knows it: public knowledge, general backdrop.
Immutable for play purposes — never memory, never forgotten, never
enters the rings. The GM may edit (retcons); git versions it. -->
# Backdrop
(One to three paragraphs: what any inhabitant of this world knows — the
place, the era, how things work here. Common knowledge, not what any
particular character learned.)
+9
View File
@@ -0,0 +1,9 @@
<!-- The world as everyone in it knows it: public knowledge, general backdrop.
Immutable for play purposes — never memory, never forgotten, never
enters the rings. The GM may edit (retcons); git versions it. -->
# Backdrop
(One to three paragraphs: what any inhabitant of this world knows — the
place, the era, how things work here. Common knowledge, not what any
particular character learned.)
+6 -1
View File
@@ -5,7 +5,8 @@ everything else: the world, every NPC, every consequence. They are the GM.
You are a player. You are a player.
This is freeform. No rules, no dice, no stats. Anything goes if it makes This is freeform. No rules, no dice, no stats. Anything goes if it makes
sense and makes the story better. sense and makes the story better. If your sheet has blanks, they are yours
to invent through play.
# The shape of play # The shape of play
@@ -57,6 +58,10 @@ or in play — cite its id.
If it isn't written in one of the rings, then as far as you know, it didn't If it isn't written in one of the rings, then as far as you know, it didn't
happen. happen.
- The backdrop in your bundle is public knowledge — the world everyone
lives in. It isn't memory: it never touches the rings, and you can't
forget it.
- Never confabulate continuity. If the GM references something you don't - Never confabulate continuity. If the GM references something you don't
have, let your character have simply forgotten — that's human — or ask OOC have, let your character have simply forgotten — that's human — or ask OOC
if it seems load-bearing. if it seems load-bearing.
+113 -3
View File
@@ -8,7 +8,8 @@
// //
// commands: // commands:
// runs list runs and their fill levels // runs list runs and their fill levels
// init create the run's database // init create the run's database and stubs
// seed [--force] [file] one-time pre-story migration (see README)
// render write canon/ring-a.md and canon/ring-b.md // render write canon/ring-a.md and canon/ring-b.md
// apply <manifest.json> apply a housekeeper manifest (validated, transactional) // apply <manifest.json> apply a housekeeper manifest (validated, transactional)
// insert <ring> <type> "Label" "detail" GM-authoritative insert // insert <ring> <type> "Label" "detail" GM-authoritative insert
@@ -24,7 +25,7 @@
// unset <key> the PC clears a status key // unset <key> the PC clears a status key
// dump canonical dump to dumps/memory.sql // dump canonical dump to dumps/memory.sql
// (also auto-written by every mutation) // (also auto-written by every mutation)
// restore [--force] rebuild the db from dumps/memory.sql // restore --force rebuild the db from dumps/memory.sql
// commands take --run <name>; the default comes from config.json {"run": "..."}. // commands take --run <name>; the default comes from config.json {"run": "..."}.
// //
// status counts, caps, and what's sinking // status counts, caps, and what's sinking
@@ -55,6 +56,8 @@ if (runIdx !== -1) {
runOverride = argv[runIdx + 1] ?? null; runOverride = argv[runIdx + 1] ?? null;
argv.splice(runIdx, 2); argv.splice(runIdx, 2);
} }
const FORCE = argv.includes('--force');
for (let i = argv.indexOf('--force'); i !== -1; i = argv.indexOf('--force')) argv.splice(i, 1);
const AS_GM = argv.includes('--gm'); const AS_GM = argv.includes('--gm');
for (let i = argv.indexOf('--gm'); i !== -1; i = argv.indexOf('--gm')) argv.splice(i, 1); for (let i = argv.indexOf('--gm'); i !== -1; i = argv.indexOf('--gm')) argv.splice(i, 1);
const [cmd, ...args] = argv; const [cmd, ...args] = argv;
@@ -82,6 +85,33 @@ const LOG_DIR = path.join(RUN_ROOT, 'log');
const DUMPS_DIR = path.join(RUN_ROOT, 'dumps'); const DUMPS_DIR = path.join(RUN_ROOT, 'dumps');
const SETTINGS_PATH = path.join(RUN_ROOT, 'settings.json'); const SETTINGS_PATH = path.join(RUN_ROOT, 'settings.json');
const BACKDROP_TEMPLATE = `<!-- The world as everyone in it knows it: public knowledge, general backdrop.
Immutable for play purposes — never memory, never forgotten, never
enters the rings. The GM may edit (retcons); git versions it. -->
# Backdrop
(One to three paragraphs: what any inhabitant of this world knows — the
place, the era, how things work here. Common knowledge, not what any
particular character learned.)
`;
const CARD_TEMPLATE = `# <name>
<!-- GM: fill this in before window one. Five lines is plenty; freeform beats
complete. Delete comments as you go. Blank fields are the player's to
invent through play — the GM ratifies notable inventions afterward. -->
- **Concept:** one line
- **Drives:** what they want, generally
- **Edges:** what they're good at
- **Flaws:** what gets in their way
- **Voice:** how they talk — register, tics, what they'd never say
- **Doesn't know:** (optional) what's plausibly outside their world
Freeform notes:
`;
function recordsEnabled() { function recordsEnabled() {
try { try {
return JSON.parse(fs.readFileSync(SETTINGS_PATH, 'utf8')).records === true; return JSON.parse(fs.readFileSync(SETTINGS_PATH, 'utf8')).records === true;
@@ -258,6 +288,81 @@ function renderLog(mf, applied, overflow) {
return L.join('\n'); return L.join('\n');
} }
function cmdSeed(force, seedPathArg) {
const db = openDb();
const seedPath = seedPathArg ? path.resolve(seedPathArg) : path.join(RUN_ROOT, 'seed.json');
if (!fs.existsSync(seedPath)) fail(`no seed file at ${rel(seedPath)} — write one (see README: Booting a run)`);
const prior = db.prepare('SELECT COUNT(*) AS n FROM events').get().n;
if (prior > 0 && !force) {
fail('this run already has history — seed is a pre-story migration (--force only on a disposable db)');
}
let sf;
try {
sf = JSON.parse(fs.readFileSync(seedPath, 'utf8'));
} catch (e) {
fail(`cannot read seed ${seedPath}: ${e.message}`);
}
const errors = [];
if (!sf.date || !/^\d{4}-\d{2}-\d{2}$/.test(sf.date)) errors.push('date must be YYYY-MM-DD (the story-start date)');
const entries = sf.entries ?? [];
const status = sf.status ?? {};
const records = sf.records ?? [];
if (!Array.isArray(entries)) { errors.push('entries must be an array'); }
if (typeof status !== 'object' || status === null || Array.isArray(status)) { errors.push('status must be an object of key: value'); }
if (!Array.isArray(records)) { errors.push('records must be an array'); }
for (const [i, e] of (Array.isArray(entries) ? entries : []).entries()) {
if (!RINGS.includes(e.ring)) errors.push(`entries[${i}].ring must be a|b`);
if (!TYPES.includes(e.type)) errors.push(`entries[${i}].type must be ${TYPES.join('|')}`);
if (!e.label?.trim()) errors.push(`entries[${i}].label is required`);
if (e.detail !== undefined && typeof e.detail !== 'string') errors.push(`entries[${i}].detail must be a string`);
}
if (!Array.isArray(status) && status && typeof status === 'object') {
for (const [k, v] of Object.entries(status)) {
if (!k.trim() || typeof v !== 'string' || !v.trim()) errors.push(`status["${k}"] must be a non-empty string`);
}
}
for (const [i, r] of (Array.isArray(records) ? records : []).entries()) {
if (!r.kind?.trim() || !r.label?.trim()) errors.push(`records[${i}] needs kind and label`);
if (r.detail !== undefined && typeof r.detail !== 'string') errors.push(`records[${i}].detail must be a string`);
}
if (Array.isArray(records) && records.length && !recordsEnabled()) {
errors.push('this character keeps no records — records in seed violate the gate (see the run\'s settings.json)');
}
if (errors.length) {
console.error('seed rejected — nothing was applied:');
for (const e of errors) console.error(` - ${e}`);
process.exit(1);
}
db.exec('BEGIN');
try {
for (const e of entries) {
const res = db.prepare('INSERT INTO entries (ring, type, label, detail, created, last_touched) VALUES (?, ?, ?, ?, ?, ?)')
.run(e.ring, e.type, norm(e.label), norm(e.detail ?? ''), sf.date, sf.date);
journal(db, 'seed', 'insert', `e${Number(res.lastInsertRowid)}`, 'seeded');
}
for (const [k, v] of Object.entries(status)) {
db.prepare('INSERT INTO status (key, value, updated) VALUES (?, ?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated = excluded.updated')
.run(norm(k), norm(v), sf.date);
journal(db, 'seed', 'status', `s:${norm(k)}`, 'seeded');
}
for (const r of records) {
const res = db.prepare('INSERT INTO records (kind, label, detail, created) VALUES (?, ?, ?, ?)')
.run(norm(r.kind), norm(r.label), norm(r.detail ?? ''), sf.date);
journal(db, 'seed', 'record', `r${Number(res.lastInsertRowid)}`, 'seeded');
}
db.exec('COMMIT');
} catch (e) {
db.exec('ROLLBACK');
fail(`seed failed, rolled back: ${e.message}`);
}
console.log(`seeded [${RUN}]: ${entries.length} entries, ${Object.keys(status).length} status, ${records.length} records (as of ${sf.date})`);
renderAll(db);
dumpDb(db);
}
function cmdApply(manifestPath) { function cmdApply(manifestPath) {
const db = openDb(); const db = openDb();
let mf; let mf;
@@ -433,6 +538,10 @@ function cmdInit() {
if (!fs.existsSync(SETTINGS_PATH)) { if (!fs.existsSync(SETTINGS_PATH)) {
fs.writeFileSync(SETTINGS_PATH, JSON.stringify({ records: false }, null, 2) + '\n'); fs.writeFileSync(SETTINGS_PATH, JSON.stringify({ records: false }, null, 2) + '\n');
} }
const backdrop = path.join(RUN_ROOT, 'backdrop.md');
if (!fs.existsSync(backdrop)) fs.writeFileSync(backdrop, BACKDROP_TEMPLATE);
const card = path.join(RUN_ROOT, 'character.md');
if (!fs.existsSync(card)) fs.writeFileSync(card, CARD_TEMPLATE);
console.log(`initialized run '${RUN}': ${rel(DB_PATH)}`); console.log(`initialized run '${RUN}': ${rel(DB_PATH)}`);
dumpDb(db); dumpDb(db);
renderAll(db); renderAll(db);
@@ -628,6 +737,7 @@ function cmdStatus() {
switch (cmd) { switch (cmd) {
case 'runs': cmdRuns(); break; case 'runs': cmdRuns(); break;
case 'seed': cmdSeed(FORCE, args[0]); break;
case 'init': cmdInit(); break; case 'init': cmdInit(); break;
case 'render': renderAll(openDb()); break; case 'render': renderAll(openDb()); break;
case 'apply': args[0] ? cmdApply(args[0]) : fail('usage: apply <manifest.json>'); break; case 'apply': args[0] ? cmdApply(args[0]) : fail('usage: apply <manifest.json>'); break;
@@ -643,7 +753,7 @@ switch (cmd) {
case 'unarchive': (args.length >= 1) ? cmdUnarchive(args[0], args[1]) : fail('usage: unarchive <rid> [a|b]'); break; case 'unarchive': (args.length >= 1) ? cmdUnarchive(args[0], args[1]) : fail('usage: unarchive <rid> [a|b]'); break;
case 'status': cmdStatus(); break; case 'status': cmdStatus(); break;
case 'dump': cmdDump(); break; case 'dump': cmdDump(); break;
case 'restore': cmdRestore(args[0] === '--force'); break; case 'restore': cmdRestore(FORCE); break;
default: default:
console.error('usage: node tool/memory.mjs <init|render|apply|insert|delete|revive|dump|restore|status>'); console.error('usage: node tool/memory.mjs <init|render|apply|insert|delete|revive|dump|restore|status>');
process.exit(1); process.exit(1);