runs: per-story state, prisoners and boutique interleaved
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
|||||||
db/memory.db
|
runs/*/db/memory.db
|
||||||
|
|||||||
@@ -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
|
better. Retcons are allowed but discouraged; when they happen they are
|
||||||
explicit and logged.
|
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 <name>` overrides the
|
||||||
|
`config.json` default for any command.
|
||||||
|
|
||||||
## The protocol
|
## The protocol
|
||||||
|
|
||||||
1. **Refresh the views:** `node tool/memory.mjs render`
|
1. **Refresh the views:** `node tool/memory.mjs render` (default run comes
|
||||||
2. **Open a window:** send `system.md`, then `character.md`, then
|
from `config.json`; `--run <name>` overrides)
|
||||||
`canon/ring-a.md`, then `canon/ring-b.md`, then narrate the first beat.
|
2. **Open a window:** send `system.md`, then `runs/<story>/character.md`,
|
||||||
(On a tight window, ring B is optional loading — ring A is the spine.)
|
then `runs/<story>/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 —
|
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
|
||||||
@@ -48,11 +64,12 @@ explicit and logged.
|
|||||||
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
|
||||||
`character.md`, then both ring views, then the session transcript. Save
|
the run's `character.md`, then both ring views, then the session
|
||||||
its manifest to `manifests/<window>.json`.
|
transcript. Save its manifest to `runs/<story>/manifests/<window>.json`.
|
||||||
6. **Apply:** `node tool/memory.mjs apply manifests/<window>.json` — the tool
|
6. **Apply:** `node tool/memory.mjs apply runs/<story>/manifests/<window>.json`
|
||||||
validates, applies, handles overflow, writes `log/<window>.md`, re-renders
|
— the tool validates, applies, handles overflow, writes the run's
|
||||||
the views. A rejected manifest changes nothing and says why.
|
`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
|
7. **Review the log, veto or edit as desired, commit.** GM edits go through
|
||||||
`insert` / `delete` / `revive` commands.
|
`insert` / `delete` / `revive` commands.
|
||||||
|
|
||||||
@@ -141,7 +158,7 @@ minors, gratuitous violence. These live in `system.md`; edit them there.
|
|||||||
## Housekeeping
|
## Housekeeping
|
||||||
|
|
||||||
This directory is a git repo. Every housekeeping pass should end in a commit.
|
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/<story>/dumps/memory.sql`** — the canonical dump:
|
||||||
id-ordered, one row per line, auto-written by every mutation. Because the
|
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,
|
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
|
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.)
|
commit message.)
|
||||||
|
|
||||||
The dump is restorable SQL and the **committed truth**; the binary
|
The dump is restorable SQL and the **committed truth**; the binary
|
||||||
`db/memory.db` is a gitignored local cache — fresh clone:
|
`runs/<story>/db/memory.db` is a gitignored local cache — fresh clone:
|
||||||
`node tool/memory.mjs restore`. The `canon/` views stay committed as
|
`node tool/memory.mjs restore` (per run). The `canon/` views stay committed
|
||||||
provenance — exactly what the models were sent — and `log/` + `manifests/`
|
as provenance — exactly what the models were sent — and `log/` +
|
||||||
remain the human-readable record.
|
`manifests/` remain the human-readable record.
|
||||||
|
|
||||||
The housekeeper may be a different model than the player — cheaper, or more
|
The housekeeper may be a different model than the player — cheaper, or more
|
||||||
pedantic, whatever housekeeping needs. The two prompts are independent.
|
pedantic, whatever housekeeping needs. The two prompts are independent.
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"run": "prisoners"
|
||||||
|
}
|
||||||
@@ -4,5 +4,4 @@
|
|||||||
|
|
||||||
# Ring A — what matters
|
# Ring A — what matters
|
||||||
|
|
||||||
- [e2] [2026-11-12] [place] **The Gull** — a tavern by the fish market, smells of tar
|
(empty — nothing here yet)
|
||||||
- [e1] [2026-11-12] [person] **Marta** — harbormaster; owes the PC silence; warm but transactional
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<!-- GM: fill this in before window one. Five lines is plenty; freeform beats
|
<!-- GM: fill this in before window one. Five lines is plenty; freeform beats
|
||||||
complete. Delete comments as you go. This sheet is the model's too —
|
complete. Delete comments as you go. This sheet is the model's too —
|
||||||
anything written here persists across windows alongside canon. -->
|
anything written here persists across windows alongside the rings. -->
|
||||||
|
|
||||||
- **Concept:** one line
|
- **Concept:** one line
|
||||||
- **Drives:** what they want, generally
|
- **Drives:** what they want, generally
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<!-- GENERATED by tool/memory.mjs render — do not edit by hand. -->
|
||||||
|
<!-- A view of db/memory.db, ring A, ordered by last touch: top = most recent. -->
|
||||||
|
<!-- Policy lives in housekeeper.md; the models never write here. -->
|
||||||
|
|
||||||
|
# Ring A — what matters
|
||||||
|
|
||||||
|
(empty — nothing here yet)
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<!-- GENERATED by tool/memory.mjs render — do not edit by hand. -->
|
||||||
|
<!-- A view of db/memory.db, ring B, ordered by last touch: top = most recent. -->
|
||||||
|
<!-- Policy lives in housekeeper.md; the models never write here. -->
|
||||||
|
|
||||||
|
# Ring B — what stuck anyway
|
||||||
|
|
||||||
|
(empty — nothing here yet)
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
# <name>
|
||||||
|
|
||||||
|
<!-- GM: fill this in before window one. Five lines is plenty; freeform beats
|
||||||
|
complete. Delete comments as you go. This sheet is the model's too —
|
||||||
|
anything written here persists across windows alongside the rings. -->
|
||||||
|
|
||||||
|
- **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:
|
||||||
@@ -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;
|
||||||
+63
-10
@@ -7,7 +7,8 @@
|
|||||||
// canon/ is a generated view (never edit by hand)
|
// canon/ is a generated view (never edit by hand)
|
||||||
//
|
//
|
||||||
// commands:
|
// 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
|
// 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
|
||||||
@@ -16,6 +17,8 @@
|
|||||||
// 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": "..."}.
|
||||||
|
//
|
||||||
// status counts, caps, and what's sinking
|
// status counts, caps, and what's sinking
|
||||||
|
|
||||||
import { DatabaseSync } from 'node:sqlite';
|
import { DatabaseSync } from 'node:sqlite';
|
||||||
@@ -24,11 +27,9 @@ import path from 'node:path';
|
|||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
|
|
||||||
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.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 SCHEMA_PATH = path.join(ROOT, 'db', 'schema.sql');
|
||||||
const CANON_DIR = path.join(ROOT, 'canon');
|
const CONFIG_PATH = path.join(ROOT, 'config.json');
|
||||||
const LOG_DIR = path.join(ROOT, 'log');
|
const RUNS_DIR = path.join(ROOT, 'runs');
|
||||||
const DUMPS_DIR = path.join(ROOT, 'dumps');
|
|
||||||
|
|
||||||
// dials — retune freely
|
// dials — retune freely
|
||||||
const CAPS = { a: 500, b: 3000 };
|
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 fail = (msg) => { console.error(`error: ${msg}`); process.exit(1); };
|
||||||
const rel = (p) => path.relative(ROOT, p).replaceAll('\\', '/');
|
const rel = (p) => path.relative(ROOT, p).replaceAll('\\', '/');
|
||||||
|
|
||||||
|
// run resolution: --run <name> 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 <name> 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() {
|
function openDb() {
|
||||||
if (!fs.existsSync(DB_PATH)) {
|
if (!fs.existsSync(DB_PATH)) {
|
||||||
fail(`no database at ${rel(DB_PATH)} — run: node tool/memory.mjs init`);
|
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.mkdirSync(LOG_DIR, { recursive: true });
|
||||||
fs.writeFileSync(logFile, renderLog(mf, applied, overflow));
|
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.insert.length && `${applied.insert.length} inserted`,
|
||||||
applied.touch.length && `${applied.touch.length} touched`,
|
applied.touch.length && `${applied.touch.length} touched`,
|
||||||
applied.promote.length && `${applied.promote.length} promoted`,
|
applied.promote.length && `${applied.promote.length} promoted`,
|
||||||
@@ -315,11 +348,30 @@ function cmdApply(manifestPath) {
|
|||||||
// --- simple commands ---------------------------------------------------------
|
// --- simple commands ---------------------------------------------------------
|
||||||
|
|
||||||
function cmdInit() {
|
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);
|
const db = new DatabaseSync(DB_PATH);
|
||||||
db.exec(fs.readFileSync(SCHEMA_PATH, 'utf8'));
|
db.exec(fs.readFileSync(SCHEMA_PATH, 'utf8'));
|
||||||
console.log(`initialized ${rel(DB_PATH)}`);
|
console.log(`initialized run '${RUN}': ${rel(DB_PATH)}`);
|
||||||
console.log(`dump: ${rel(dumpDb(db))}`);
|
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); }
|
function today() { return new Date().toISOString().slice(0, 10); }
|
||||||
@@ -388,6 +440,7 @@ function cmdRestore(force = false) {
|
|||||||
|
|
||||||
function cmdStatus() {
|
function cmdStatus() {
|
||||||
const db = openDb();
|
const db = openDb();
|
||||||
|
console.log(`run: ${RUN}`);
|
||||||
for (const ring of ['a', 'b', 'cold']) {
|
for (const ring of ['a', 'b', 'cold']) {
|
||||||
const n = db.prepare('SELECT COUNT(*) AS n FROM entries WHERE ring = ?').get(ring).n;
|
const n = db.prepare('SELECT COUNT(*) AS n FROM entries WHERE ring = ?').get(ring).n;
|
||||||
const cap = CAPS[ring] ?? '∞';
|
const cap = CAPS[ring] ?? '∞';
|
||||||
@@ -403,8 +456,8 @@ function cmdStatus() {
|
|||||||
|
|
||||||
// --- dispatch ----------------------------------------------------------------
|
// --- dispatch ----------------------------------------------------------------
|
||||||
|
|
||||||
const [cmd, ...args] = process.argv.slice(2);
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
|
case 'runs': cmdRuns(); 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;
|
||||||
|
|||||||
Reference in New Issue
Block a user