diff --git a/README.md b/README.md index 8a8a049..0747b54 100644 --- a/README.md +++ b/README.md @@ -50,14 +50,32 @@ Two interleaved stories calibrate the memory system against itself: `node tool/memory.mjs runs` shows fill levels; `--run ` overrides the `config.json` default for any command. +## Booting a run + +1. **Backdrop** — write `runs//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//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//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 1. **Refresh the views:** `node tool/memory.mjs render` (default run comes from `config.json`; `--run ` overrides) -2. **Open a window:** send `system.md`, then `runs//character.md`, - then `runs//canon/status.md`, then `ring-a.md` and `ring-b.md`, - then narrate the first beat. (On a tight window, ring B is optional - loading — ring A is the spine.) +2. **Open a window:** send `system.md`, then `runs//backdrop.md`, + then `character.md`, then `canon/status.md`, then `ring-a.md` and + `ring-b.md`, then narrate the first beat. (On a tight window, ring B is + optional loading — ring A is the spine.) 3. **In play:** `((double parentheses))` is the out-of-character channel — points of order, canon questions, proposals, vetoes. Both sides use it. 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 end-of-session duties. 5. **Housekeep (fresh model, new context):** send `housekeeper.md`, then - the run's `character.md`, then both ring views, then the session - transcript. Save its manifest to `runs//manifests/.json`. + the run's `backdrop.md` and `character.md`, then both ring views, then + the session transcript. Save its manifest to + `runs//manifests/.json`. 6. **Apply:** `node tool/memory.mjs apply runs//manifests/.json` — the tool validates, applies, handles overflow, writes the run's `log/.md`, re-renders the views. A rejected manifest changes @@ -83,11 +102,12 @@ State lives in **SQLite** (`runs//db/memory.db`); `canon/ring-*.md` are generated views. Markdown survives as rendering, dies as storage — the models see prose, the machine sees rows. -Memory is **five tiers**: +Memory is **six tiers**: | 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 | | **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 | @@ -246,7 +266,8 @@ tool/ db/ schema.sql entries, records, status, events journal (shared) runs/ - prisoners/ one story: character.md, settings.json, db/, dumps/, canon/ - (status.md, ring-a.md, ring-b.md), log/, manifests/ + prisoners/ one story: backdrop.md, character.md, seed.json, settings.json, + db/, dumps/, canon/ (status.md, ring-a.md, ring-b.md), + log/, manifests/ boutique/ same shape — records enabled (the shopkeep's PC) ``` diff --git a/housekeeper.md b/housekeeper.md index a32b786..0c7ffdc 100644 --- a/housekeeper.md +++ b/housekeeper.md @@ -14,6 +14,8 @@ You never play, you never edit files, you never see the database directly. - this prompt - `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, entries ordered by last touch, each carrying a stable id like `[e17]` - 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 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 obligation, or altered the world. Everything else that passed the gate diff --git a/runs/boutique/backdrop.md b/runs/boutique/backdrop.md new file mode 100644 index 0000000..cbfd52d --- /dev/null +++ b/runs/boutique/backdrop.md @@ -0,0 +1,9 @@ + + +# 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.) diff --git a/runs/prisoners/backdrop.md b/runs/prisoners/backdrop.md new file mode 100644 index 0000000..cbfd52d --- /dev/null +++ b/runs/prisoners/backdrop.md @@ -0,0 +1,9 @@ + + +# 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.) diff --git a/system.md b/system.md index 9885cc2..3db41af 100644 --- a/system.md +++ b/system.md @@ -5,7 +5,8 @@ everything else: the world, every NPC, every consequence. They are the GM. You are a player. 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 @@ -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 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 have, let your character have simply forgotten — that's human — or ask OOC if it seems load-bearing. diff --git a/tool/memory.mjs b/tool/memory.mjs index be40e30..07d214d 100644 --- a/tool/memory.mjs +++ b/tool/memory.mjs @@ -8,7 +8,8 @@ // // commands: // 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 // apply apply a housekeeper manifest (validated, transactional) // insert "Label" "detail" GM-authoritative insert @@ -24,7 +25,7 @@ // unset the PC clears a status key // dump canonical dump to dumps/memory.sql // (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 ; the default comes from config.json {"run": "..."}. // // status counts, caps, and what's sinking @@ -55,6 +56,8 @@ if (runIdx !== -1) { runOverride = argv[runIdx + 1] ?? null; 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'); for (let i = argv.indexOf('--gm'); i !== -1; i = argv.indexOf('--gm')) argv.splice(i, 1); 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 SETTINGS_PATH = path.join(RUN_ROOT, 'settings.json'); +const BACKDROP_TEMPLATE = ` + +# 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 = `# + + + +- **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() { try { return JSON.parse(fs.readFileSync(SETTINGS_PATH, 'utf8')).records === true; @@ -258,6 +288,81 @@ function renderLog(mf, applied, overflow) { 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) { const db = openDb(); let mf; @@ -433,6 +538,10 @@ function cmdInit() { if (!fs.existsSync(SETTINGS_PATH)) { 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)}`); dumpDb(db); renderAll(db); @@ -628,6 +737,7 @@ function cmdStatus() { switch (cmd) { case 'runs': cmdRuns(); break; + case 'seed': cmdSeed(FORCE, args[0]); break; case 'init': cmdInit(); break; case 'render': renderAll(openDb()); break; case 'apply': args[0] ? cmdApply(args[0]) : fail('usage: apply '); break; @@ -643,7 +753,7 @@ switch (cmd) { case 'unarchive': (args.length >= 1) ? cmdUnarchive(args[0], args[1]) : fail('usage: unarchive [a|b]'); break; case 'status': cmdStatus(); break; case 'dump': cmdDump(); break; - case 'restore': cmdRestore(args[0] === '--force'); break; + case 'restore': cmdRestore(FORCE); break; default: console.error('usage: node tool/memory.mjs '); process.exit(1);