diff --git a/.gitignore b/.gitignore index b67125c..799578e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -db/memory.db +runs/*/db/memory.db diff --git a/README.md b/README.md index 8433e32..b14b5fb 100644 --- a/README.md +++ b/README.md @@ -35,12 +35,28 @@ no handbook, no stats. Anything goes if it makes sense and makes the story better. Retcons are allowed but discouraged; when they happen they are explicit and logged. +## Runs + +Two interleaved stories calibrate the memory system against itself: + +| | `prisoners` | `boutique` | +|---|---|---| +| entries per window | few — tiny cast, deep history | many — the customer parade | +| dominant ops | touch, reword | insert, gate, demote/retire | +| ring A pressure | staleness — standings shift on hot entries | clutter — obligations accrete | +| player agency | constrained — reactive creativity | full — proactive creativity | + +`node tool/memory.mjs runs` shows fill levels; `--run ` overrides the +`config.json` default for any command. + ## The protocol -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.) +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/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 @@ -48,11 +64,12 @@ explicit and logged. 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 - `character.md`, then both ring views, then the session transcript. Save - its manifest to `manifests/.json`. -6. **Apply:** `node tool/memory.mjs apply manifests/.json` — the tool - validates, applies, handles overflow, writes `log/.md`, re-renders - the views. A rejected manifest changes nothing and says why. + the run's `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 + nothing and says why. 7. **Review the log, veto or edit as desired, commit.** GM edits go through `insert` / `delete` / `revive` commands. @@ -141,7 +158,7 @@ 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 **primary audit surface is `dumps/memory.sql`** — the canonical dump: +The **primary audit surface is `runs//dumps/memory.sql`** — the canonical dump: id-ordered, one row per line, auto-written by every mutation. Because the ordering is by id, diffs are position-stable — a touch is one changed line, a promotion is one changed line, an eviction is one changed line. Diffing @@ -156,10 +173,10 @@ the db with a sqlite browser, run `dump` afterwards and confess in the commit message.) The dump is restorable SQL and the **committed truth**; the binary -`db/memory.db` is a gitignored local cache — fresh clone: -`node tool/memory.mjs restore`. The `canon/` views stay committed as -provenance — exactly what the models were sent — and `log/` + `manifests/` -remain the human-readable record. +`runs//db/memory.db` is a gitignored local cache — fresh clone: +`node tool/memory.mjs restore` (per run). The `canon/` views stay committed +as provenance — exactly what the models were sent — and `log/` + +`manifests/` remain the human-readable record. The housekeeper may be a different model than the player — cheaper, or more pedantic, whatever housekeeping needs. The two prompts are independent. diff --git a/config.json b/config.json new file mode 100644 index 0000000..b6486af --- /dev/null +++ b/config.json @@ -0,0 +1,3 @@ +{ + "run": "prisoners" +} diff --git a/canon/ring-a.md b/runs/boutique/canon/ring-a.md similarity index 57% rename from canon/ring-a.md rename to runs/boutique/canon/ring-a.md index 98685ff..489084c 100644 --- a/canon/ring-a.md +++ b/runs/boutique/canon/ring-a.md @@ -4,5 +4,4 @@ # Ring A — what matters -- [e2] [2026-11-12] [place] **The Gull** — a tavern by the fish market, smells of tar -- [e1] [2026-11-12] [person] **Marta** — harbormaster; owes the PC silence; warm but transactional +(empty — nothing here yet) diff --git a/canon/ring-b.md b/runs/boutique/canon/ring-b.md similarity index 100% rename from canon/ring-b.md rename to runs/boutique/canon/ring-b.md diff --git a/character.md b/runs/boutique/character.md similarity index 85% rename from character.md rename to runs/boutique/character.md index 4f73296..4c931fc 100644 --- a/character.md +++ b/runs/boutique/character.md @@ -2,7 +2,7 @@ + anything written here persists across windows alongside the rings. --> - **Concept:** one line - **Drives:** what they want, generally diff --git a/log/.gitkeep b/runs/boutique/db/.gitkeep similarity index 100% rename from log/.gitkeep rename to runs/boutique/db/.gitkeep diff --git a/dumps/memory.sql b/runs/boutique/dumps/memory.sql similarity index 100% rename from dumps/memory.sql rename to runs/boutique/dumps/memory.sql diff --git a/manifests/.gitkeep b/runs/boutique/log/.gitkeep similarity index 100% rename from manifests/.gitkeep rename to runs/boutique/log/.gitkeep diff --git a/runs/boutique/manifests/.gitkeep b/runs/boutique/manifests/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/runs/prisoners/canon/ring-a.md b/runs/prisoners/canon/ring-a.md new file mode 100644 index 0000000..489084c --- /dev/null +++ b/runs/prisoners/canon/ring-a.md @@ -0,0 +1,7 @@ + + + + +# Ring A — what matters + +(empty — nothing here yet) diff --git a/runs/prisoners/canon/ring-b.md b/runs/prisoners/canon/ring-b.md new file mode 100644 index 0000000..b7e28b5 --- /dev/null +++ b/runs/prisoners/canon/ring-b.md @@ -0,0 +1,7 @@ + + + + +# Ring B — what stuck anyway + +(empty — nothing here yet) diff --git a/runs/prisoners/character.md b/runs/prisoners/character.md new file mode 100644 index 0000000..4c931fc --- /dev/null +++ b/runs/prisoners/character.md @@ -0,0 +1,14 @@ +# + + + +- **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: diff --git a/runs/prisoners/db/.gitkeep b/runs/prisoners/db/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/runs/prisoners/dumps/memory.sql b/runs/prisoners/dumps/memory.sql new file mode 100644 index 0000000..bd42346 --- /dev/null +++ b/runs/prisoners/dumps/memory.sql @@ -0,0 +1,29 @@ +-- canonical dump of db/memory.db — GENERATED by tool/memory.mjs; do not edit. +-- one row per line; entries and events ordered by id; restore with: restore +PRAGMA foreign_keys = ON; + +CREATE TABLE IF NOT EXISTS entries ( + id INTEGER PRIMARY KEY, + ring TEXT NOT NULL CHECK (ring IN ('a', 'b', 'cold')), + type TEXT NOT NULL CHECK (type IN ('place', 'person', 'fact', 'thread')), + label TEXT NOT NULL, + detail TEXT NOT NULL DEFAULT '', + created TEXT NOT NULL, + last_touched TEXT NOT NULL +); + +CREATE INDEX IF NOT EXISTS entries_ring_touch + ON entries (ring, last_touched DESC, id DESC); + +-- append-only audit journal; nothing here is ever updated or deleted +CREATE TABLE IF NOT EXISTS events ( + id INTEGER PRIMARY KEY, + window TEXT NOT NULL, + op TEXT NOT NULL CHECK (op IN ('insert', 'touch', 'promote', 'demote', 'reword', 'delete', 'evict', 'revive')), + entry_id INTEGER NOT NULL REFERENCES entries (id), + reason TEXT NOT NULL DEFAULT '' +); + +CREATE INDEX IF NOT EXISTS events_window ON events (window); +BEGIN TRANSACTION; +COMMIT; diff --git a/runs/prisoners/log/.gitkeep b/runs/prisoners/log/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/runs/prisoners/manifests/.gitkeep b/runs/prisoners/manifests/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tool/memory.mjs b/tool/memory.mjs index 7fb77e3..9b50b71 100644 --- a/tool/memory.mjs +++ b/tool/memory.mjs @@ -7,7 +7,8 @@ // canon/ is a generated view (never edit by hand) // // commands: -// init create the database +// runs list runs and their fill levels +// init create the run's database // render write canon/ring-a.md and canon/ring-b.md // apply apply a housekeeper manifest (validated, transactional) // insert "Label" "detail" GM-authoritative insert @@ -16,6 +17,8 @@ // dump canonical dump to dumps/memory.sql // (also auto-written by every mutation) // 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 import { DatabaseSync } from 'node:sqlite'; @@ -24,11 +27,9 @@ import path from 'node:path'; import { fileURLToPath } from 'node:url'; const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); -const DB_PATH = path.join(ROOT, 'db', 'memory.db'); const SCHEMA_PATH = path.join(ROOT, 'db', 'schema.sql'); -const CANON_DIR = path.join(ROOT, 'canon'); -const LOG_DIR = path.join(ROOT, 'log'); -const DUMPS_DIR = path.join(ROOT, 'dumps'); +const CONFIG_PATH = path.join(ROOT, 'config.json'); +const RUNS_DIR = path.join(ROOT, 'runs'); // dials — retune freely const CAPS = { a: 500, b: 3000 }; @@ -38,6 +39,38 @@ const RINGS = ['a', 'b']; // renderable; 'cold' is beyond the models const fail = (msg) => { console.error(`error: ${msg}`); process.exit(1); }; const rel = (p) => path.relative(ROOT, p).replaceAll('\\', '/'); +// run resolution: --run beats config.json {"run": "..."} +const argv = process.argv.slice(2); +const runIdx = argv.indexOf('--run'); +let runOverride = null; +if (runIdx !== -1) { + runOverride = argv[runIdx + 1] ?? null; + argv.splice(runIdx, 2); +} +const [cmd, ...args] = argv; + +function resolveRun() { + if (runOverride) return runOverride; + if (fs.existsSync(CONFIG_PATH)) { + try { + const r = JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf8')).run; + if (r) return r; + } catch {} + } + return null; +} + +const RUN = cmd === 'runs' ? null : resolveRun(); +if (cmd !== 'runs' && (!RUN || !/^[a-z0-9-]+$/.test(RUN))) { + fail('no run specified — use --run or {"run":"name"} in config.json'); +} + +const RUN_ROOT = path.join(RUNS_DIR, RUN ?? ''); +const DB_PATH = path.join(RUN_ROOT, 'db', 'memory.db'); +const CANON_DIR = path.join(RUN_ROOT, 'canon'); +const LOG_DIR = path.join(RUN_ROOT, 'log'); +const DUMPS_DIR = path.join(RUN_ROOT, 'dumps'); + function openDb() { if (!fs.existsSync(DB_PATH)) { fail(`no database at ${rel(DB_PATH)} — run: node tool/memory.mjs init`); @@ -298,7 +331,7 @@ function cmdApply(manifestPath) { fs.mkdirSync(LOG_DIR, { recursive: true }); fs.writeFileSync(logFile, renderLog(mf, applied, overflow)); - console.log(`applied ${mf.window}: ` + [ + console.log(`applied [${RUN}] ${mf.window}: ` + [ applied.insert.length && `${applied.insert.length} inserted`, applied.touch.length && `${applied.touch.length} touched`, applied.promote.length && `${applied.promote.length} promoted`, @@ -315,11 +348,30 @@ function cmdApply(manifestPath) { // --- simple commands --------------------------------------------------------- function cmdInit() { - fs.mkdirSync(path.join(ROOT, 'db'), { recursive: true }); + for (const d of ['db', 'log', 'manifests']) { + const dir = path.join(RUN_ROOT, d); + fs.mkdirSync(dir, { recursive: true }); + const keep = path.join(dir, '.gitkeep'); + if (!fs.existsSync(keep)) fs.writeFileSync(keep, ''); + } const db = new DatabaseSync(DB_PATH); db.exec(fs.readFileSync(SCHEMA_PATH, 'utf8')); - console.log(`initialized ${rel(DB_PATH)}`); - console.log(`dump: ${rel(dumpDb(db))}`); + console.log(`initialized run '${RUN}': ${rel(DB_PATH)}`); + dumpDb(db); + renderAll(db); +} + +function cmdRuns() { + if (!fs.existsSync(RUNS_DIR)) { console.log('(no runs)'); return; } + for (const d of fs.readdirSync(RUNS_DIR, { withFileTypes: true })) { + if (!d.isDirectory()) continue; + const dbPath = path.join(RUNS_DIR, d.name, 'db', 'memory.db'); + if (!fs.existsSync(dbPath)) { console.log(`${d.name}: (not initialized)`); continue; } + const db = new DatabaseSync(dbPath); + db.exec(fs.readFileSync(SCHEMA_PATH, 'utf8')); + const n = (ring) => db.prepare('SELECT COUNT(*) AS n FROM entries WHERE ring = ?').get(ring).n; + console.log(`${d.name}: a ${n('a')}/${CAPS.a} · b ${n('b')}/${CAPS.b} · cold ${n('cold')}`); + } } function today() { return new Date().toISOString().slice(0, 10); } @@ -388,6 +440,7 @@ function cmdRestore(force = false) { function cmdStatus() { const db = openDb(); + console.log(`run: ${RUN}`); for (const ring of ['a', 'b', 'cold']) { const n = db.prepare('SELECT COUNT(*) AS n FROM entries WHERE ring = ?').get(ring).n; const cap = CAPS[ring] ?? '∞'; @@ -403,8 +456,8 @@ function cmdStatus() { // --- dispatch ---------------------------------------------------------------- -const [cmd, ...args] = process.argv.slice(2); switch (cmd) { + case 'runs': cmdRuns(); break; case 'init': cmdInit(); break; case 'render': renderAll(openDb()); break; case 'apply': args[0] ? cmdApply(args[0]) : fail('usage: apply '); break;