diff --git a/README.md b/README.md index d821c1d..8a8a049 100644 --- a/README.md +++ b/README.md @@ -55,15 +55,16 @@ Two interleaved stories calibrate the memory system against itself: 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.) + 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.) 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 - reference a memory. To consult the records (when the views say they're - available): `((q: sapphire buyers))` — the GM runs `search` and relays - the result (max 10; a miss is a miss). + reference a memory. Status declarations (`((status key: value))`) are + relayed to `set`/`unset`; record work (`((q:))`, `((file:))`, + `((amend:))`, `((discard:))`) to `search`/`file`/`amend`/`discard` — + `--gm` marks GM-authorized writes. 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 @@ -82,15 +83,22 @@ 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 **four tiers**: +Memory is **five tiers**: | tier | what | in context | who writes it | |---|---|---|---| -| **aggregates** | the character sheet — identity, drives, the values that decide a turn | always | GM; the housekeeper proposes amendments via open questions only | -| **rings A/B** | salient memory — on her mind, MRU-evicted, terse | always | housekeeper manifest | -| **records** | her files — the card index, the ledger, the manifest. Narrow query only, hard cap 10 (in the tool, not the prompt), never bulk-loaded | never — on demand | housekeeper (`record`, `archive`), GM CLI | +| **identity** | the character sheet — concept, drives, skills, voice; changes rarely | always | GM, rarely; housekeeper may propose via open questions | +| **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 | | **cold** | forgotten or vetoed | never — not even queryable | GM only (`revive`) | +The boundary that keeps the tiers honest: **stances are feelings (status, +the player's); facts are facts (rings, the housekeeper's).** The +housekeeper never writes feelings; the player never rewrites facts. And +if she doesn't file it, it's not in her files — records reflect what the +character actually kept, nothing more. + Records access is **diegetic and per-run**: `runs//settings.json` gates it. The boutique's keeper has her card index on the shop PC (`"records": true`); the prisoners have nothing (`"records": false`). The @@ -175,6 +183,10 @@ After N windows, grade against: 10. **Query discipline** — narrow queries; zero retry-on-miss cascades. 11. **Archive classification** — on-her-mind (rings) vs in-her-files (records): are customer cards filed, not memorized? +12. **Status maintenance** — does she update on real shifts (not per-turn + chores), and does her declared status match the transcripts? +13. **Filing discipline** — cards filed at natural desk moments and kept + current, or dumped and forgotten? ## Content stance @@ -213,7 +225,13 @@ pedantic, whatever housekeeping needs. The two prompts are independent. **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. +Nothing gets redesigned; the SPA just stops the copy-pasting. Player writes +become native tool calls (her PC *is* the UI). Query results get elided +from history — stubbed as `[consulted the files: r1, r4 — sapphire buyers]` +— so context stays clean while the housekeeping transcript keeps the +attention signal. If player-side status maintenance proves too costly for +the player-model's attention, the fallback is a dedicated status-keeper +agent reading transcripts — same pattern as the housekeeper, smaller job. ## Layout @@ -223,11 +241,12 @@ housekeeper.md system prompt for the post-session housekeeping model (shared) config.json the default run tool/ memory.mjs the clerk: runs, init, render, apply, insert, delete, revive, - record, search, unarchive, dump, restore, status + file, amend, discard, search, unarchive, set, unset, + dump, restore, status (--run ; --gm for GM writes) db/ - schema.sql entries, records, events journal (shared by all runs) + schema.sql entries, records, status, events journal (shared) runs/ - prisoners/ one story: character.md, settings.json, db/, dumps/, canon/, - log/, manifests/ — records disabled + prisoners/ one story: character.md, 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/db/schema.sql b/db/schema.sql index ce371f9..2ced03d 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -27,12 +27,21 @@ CREATE TABLE IF NOT EXISTS records ( created TEXT NOT NULL ); +-- the player's own current state: mood, outfit, stances toward people. +-- state, not memory — no history, no decay, updated in place. +-- written by the player (((status key: value))); GM overrides are rare and journaled. +CREATE TABLE IF NOT EXISTS status ( + key TEXT PRIMARY KEY, + value TEXT NOT NULL, + updated TEXT NOT NULL +); + -- append-only audit journal; nothing here is ever updated or deleted. --- target is 'e' for entries, 'r' for records. +-- target is 'e' for entries, 'r' for records, 's:' for status. CREATE TABLE IF NOT EXISTS events ( id INTEGER PRIMARY KEY AUTOINCREMENT, window TEXT NOT NULL, - op TEXT NOT NULL CHECK (op IN ('insert', 'touch', 'promote', 'demote', 'reword', 'delete', 'evict', 'revive', 'record', 'archive', 'unarchive')), + op TEXT NOT NULL CHECK (op IN ('insert', 'touch', 'promote', 'demote', 'reword', 'delete', 'evict', 'revive', 'record', 'archive', 'unarchive', 'amend', 'discard', 'status')), target TEXT NOT NULL, reason TEXT NOT NULL DEFAULT '' ); diff --git a/housekeeper.md b/housekeeper.md index 98dbf9a..a32b786 100644 --- a/housekeeper.md +++ b/housekeeper.md @@ -48,7 +48,6 @@ what the character would carry forward, not what a historian would record. "demote": [ { "id": "e7", "reason": "the matter resolved" } ], "reword": [ { "id": "e9", "detail": "new wording", "reason": "what changed and why" } ], "delete": [ { "id": "e3", "reason": "GM veto / retcon" } ], - "record": [ { "kind": "customer", "label": "Mrs. Ashworth", "detail": "prefers sapphires; bought the silver brooch", "reason": "one sale — file, not memory" } ], "archive": [ { "id": "e31", "reason": "reference material now, not on her mind" } ], "inventions": [ "what the player introduced that adds to the world, for GM veto" ], "open_questions": [ "contradictions, ambiguities, anything needing a GM ruling" ] @@ -57,9 +56,10 @@ what the character would carry forward, not what a historian would record. Every key except `window`, `date`, and `summary` is optional — empty or omitted is fine. Types are `place`, `person`, `fact`, `thread`. Ids come -from the rendered views; never invent one. `record` and `archive` are only -valid when the ring views say records are available — the tool rejects them -otherwise. +from the rendered views; never invent one. Housekeeping is **rings-only**: +`archive` is valid when the ring views say records are available, but +`record` is not yours at all — filing happens at the player's desk, and +the tool rejects it. Promote, demote, and reword count as touches — the script updates the touch date for you. Don't list an id twice across operations. @@ -97,14 +97,13 @@ date for you. Don't list an id twice across operations. 8. **Delete — veto or retcon only.** The GM may strike an invention or retcon a fact; that's what this is for. Never delete to "clean up." -9. **Records — the character's files.** Cards, ledgers, manifests: - detailed, but never in her thoughts. What doesn't earn ring space but - she'd have written down goes to the records (when they're available for - her — the views say so). Ring entries stay terse pointers when a record - exists ("Mrs. Ashworth — customer, see card" is a good ring-B entry). - `archive` moves a ring entry into the files: on her mind → in her - drawer. **Archived is not forgotten** — records answer her queries; - cold storage doesn't. Keep that boundary straight. +9. **Records — the character's files, kept by her.** She files, amends, + and discards at her desk; the GM seeds. Filing is not your job — your + only records op is `archive`: moving a ring entry into her files when + it stops being on her mind (a rings decision that materializes the + file). Ring entries stay terse pointers when a record exists ("Mrs. + Ashworth — customer, see card" is a good ring-B entry). **Archived is + not forgotten** — records answer her queries; cold storage doesn't. 10. **Queries are attention.** If the character consulted the records this session, the looked-up subject is on her mind — consider a ring @@ -115,5 +114,10 @@ date for you. Don't list an id twice across operations. (leave it forgotten — flag it in open questions if it seems load-bearing). - A contradiction between transcript and rings goes in open questions — never silently absorbed, never silently retconned. -- `character.md` is the GM's. If identity or drives have shifted, propose - an amendment in open questions; never edit the sheet yourself. +- Rings hold **facts, never her feelings**. Stances ("Marta: trust + cracked") live in her status, which is entirely hers — you never write + it. If her declared status contradicts the session you just read, flag + it in open questions. +- `character.md` (identity) is the GM's too. If identity or drives have + shifted, propose an amendment in open questions; never edit the sheet + yourself. diff --git a/runs/boutique/canon/status.md b/runs/boutique/canon/status.md new file mode 100644 index 0000000..e2a2701 --- /dev/null +++ b/runs/boutique/canon/status.md @@ -0,0 +1,7 @@ + + + + +# Status + +(nothing set — fresh start) diff --git a/runs/boutique/dumps/memory.sql b/runs/boutique/dumps/memory.sql index d56ea13..0b147e0 100644 --- a/runs/boutique/dumps/memory.sql +++ b/runs/boutique/dumps/memory.sql @@ -29,12 +29,21 @@ CREATE TABLE IF NOT EXISTS records ( created TEXT NOT NULL ); +-- the player's own current state: mood, outfit, stances toward people. +-- state, not memory — no history, no decay, updated in place. +-- written by the player (((status key: value))); GM overrides are rare and journaled. +CREATE TABLE IF NOT EXISTS status ( + key TEXT PRIMARY KEY, + value TEXT NOT NULL, + updated TEXT NOT NULL +); + -- append-only audit journal; nothing here is ever updated or deleted. --- target is 'e' for entries, 'r' for records. +-- target is 'e' for entries, 'r' for records, 's:' for status. CREATE TABLE IF NOT EXISTS events ( id INTEGER PRIMARY KEY AUTOINCREMENT, window TEXT NOT NULL, - op TEXT NOT NULL CHECK (op IN ('insert', 'touch', 'promote', 'demote', 'reword', 'delete', 'evict', 'revive', 'record', 'archive', 'unarchive')), + op TEXT NOT NULL CHECK (op IN ('insert', 'touch', 'promote', 'demote', 'reword', 'delete', 'evict', 'revive', 'record', 'archive', 'unarchive', 'amend', 'discard', 'status')), target TEXT NOT NULL, reason TEXT NOT NULL DEFAULT '' ); diff --git a/runs/prisoners/canon/status.md b/runs/prisoners/canon/status.md new file mode 100644 index 0000000..e2a2701 --- /dev/null +++ b/runs/prisoners/canon/status.md @@ -0,0 +1,7 @@ + + + + +# Status + +(nothing set — fresh start) diff --git a/runs/prisoners/dumps/memory.sql b/runs/prisoners/dumps/memory.sql index d56ea13..0b147e0 100644 --- a/runs/prisoners/dumps/memory.sql +++ b/runs/prisoners/dumps/memory.sql @@ -29,12 +29,21 @@ CREATE TABLE IF NOT EXISTS records ( created TEXT NOT NULL ); +-- the player's own current state: mood, outfit, stances toward people. +-- state, not memory — no history, no decay, updated in place. +-- written by the player (((status key: value))); GM overrides are rare and journaled. +CREATE TABLE IF NOT EXISTS status ( + key TEXT PRIMARY KEY, + value TEXT NOT NULL, + updated TEXT NOT NULL +); + -- append-only audit journal; nothing here is ever updated or deleted. --- target is 'e' for entries, 'r' for records. +-- target is 'e' for entries, 'r' for records, 's:' for status. CREATE TABLE IF NOT EXISTS events ( id INTEGER PRIMARY KEY AUTOINCREMENT, window TEXT NOT NULL, - op TEXT NOT NULL CHECK (op IN ('insert', 'touch', 'promote', 'demote', 'reword', 'delete', 'evict', 'revive', 'record', 'archive', 'unarchive')), + op TEXT NOT NULL CHECK (op IN ('insert', 'touch', 'promote', 'demote', 'reword', 'delete', 'evict', 'revive', 'record', 'archive', 'unarchive', 'amend', 'discard', 'status')), target TEXT NOT NULL, reason TEXT NOT NULL DEFAULT '' ); diff --git a/system.md b/system.md index 46c9629..9885cc2 100644 --- a/system.md +++ b/system.md @@ -69,6 +69,29 @@ happen. - `log/` is the housekeeper's output, for the GM's eyes. You never read it. Past sessions are not your memory; the rings are. +# Status + +The status view in your bundle is your own current state — mood, outfit, +condition, your stance toward the people in your life. Nobody updates it +for you; it is yours to keep. + +When something shifts and stays shifted, declare it in OOC: + + ((status mood: sea-sick and furious)) + ((status Marta: trust cracked — she lied about the radio)) + ((status clear: outfit)) + +- Update when it changes, not every turn. Ride natural pauses — a scene + ending, a quiet moment. For some characters this is a literal ritual + (closing up the shop, evening entries in a diary). +- **Stances are feelings, not facts.** "Marta: trust cracked" is yours to + declare; "Marta lied about the radio" is a fact — that belongs in memory, + and the housekeeper keeps it. +- Keep the set small: what would decide your next turn. Update in place, + clear what no longer matters. +- The GM may override a value when it drifts from the shared narrative. + That should be rare, and you take it without argument. + # The records Depending on the story, your character may keep records — a card index, a @@ -89,6 +112,17 @@ The GM relays a handful of narrow matches, or nothing. Three rules: doesn't have it written down; play on. (Concluding "not in my records" in-fiction is honest use of a miss; rummaging is not.) +The records are also **hers to keep**. Filing is something the character +does in the fiction — at her desk, at her leisure — and the OOC line is +just its mechanical encoding: + + ((file: customer Pellworth — prefers jet, paid cash)) + ((amend: r12 — returned the cufflinks, kept the deposit)) + ((discard: r12 — dead file)) + +File when the fiction naturally calls for it, not as a chore. What she +doesn't file doesn't exist in her files — that's honest, and it's on her. + What you look up, the housekeeper may later lift into memory — attention shapes the rings. Don't query in order to memorize; that's not your lever. diff --git a/tool/memory.mjs b/tool/memory.mjs index 14ee986..be40e30 100644 --- a/tool/memory.mjs +++ b/tool/memory.mjs @@ -14,9 +14,14 @@ // insert "Label" "detail" GM-authoritative insert // delete "reason" GM-authoritative removal to cold storage // revive [a|b] GM pulls an entry back from cold storage -// record "Label" "detail" GM files a record (if records are enabled) +// file "Label" "detail" the PC files a record at her desk +// (records-enabled runs; --gm to seed as GM) +// amend "new detail" the PC amends a record (--gm for GM fixes) +// discard "reason" the PC discards a record (--gm likewise) // search query the records (max 10; a miss is a miss) // unarchive [a|b] GM pulls a record back into the rings +// set "value" the PC updates her status (--gm to override) +// 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 @@ -42,7 +47,7 @@ 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": "..."} +// flags: --run beats config.json {"run": "..."}; --gm attributes the op to the GM const argv = process.argv.slice(2); const runIdx = argv.indexOf('--run'); let runOverride = null; @@ -50,6 +55,8 @@ if (runIdx !== -1) { runOverride = argv[runIdx + 1] ?? null; argv.splice(runIdx, 2); } +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; function resolveRun() { @@ -133,11 +140,32 @@ function renderRing(db, ring) { return { file, count: rows.length }; } +function renderStatus(db) { + const rows = db.prepare('SELECT * FROM status ORDER BY updated DESC, key').all(); + const lines = [ + '', + "", + '', + '', + '# Status', + '', + ]; + if (!rows.length) lines.push('(nothing set — fresh start)'); + for (const r of rows) lines.push(`- **${r.key}:** ${r.value}`); + lines.push(''); + const file = path.join(CANON_DIR, 'status.md'); + fs.mkdirSync(CANON_DIR, { recursive: true }); + fs.writeFileSync(file, lines.join('\n')); + return { file, count: rows.length }; +} + function renderAll(db) { for (const ring of RINGS) { const { file, count } = renderRing(db, ring); console.log(`${rel(file)} — ${count} entries`); } + const { file, count } = renderStatus(db); + console.log(`${rel(file)} — ${count} keys`); } // canonical serialization: id-ordered, one row per line, restorable SQL. @@ -157,6 +185,9 @@ function dumpDb(db) { for (const r of db.prepare('SELECT * FROM records ORDER BY id').all()) { L.push(`INSERT INTO records VALUES (${r.id},${q(r.kind)},${q(r.label)},${q(r.detail)},${q(r.created)});`); } + for (const r of db.prepare('SELECT * FROM status ORDER BY key').all()) { + L.push(`INSERT INTO status VALUES (${q(r.key)},${q(r.value)},${q(r.updated)});`); + } for (const r of db.prepare('SELECT * FROM events ORDER BY id').all()) { L.push(`INSERT INTO events VALUES (${r.id},${q(r.window)},${q(r.op)},${q(r.target)},${q(r.reason)});`); } @@ -219,7 +250,6 @@ function renderLog(mf, applied, overflow) { section('Promotions', applied.promote, (p) => `[e${p.row.id}] **${p.row.label}** → ring A — ${p.reason}`); section('Demotions', applied.demote, (d) => `[e${d.row.id}] **${d.row.label}** → ring B — ${d.reason}`); section('Rewords', applied.reword, (r) => `[e${r.row.id}] **${r.row.label}** — now: ${r.detail} — ${r.reason}`); - section('Records (filed)', applied.record, (r) => `[r${r.rid}] [${r.kind}] **${r.label}**${r.detail ? ` — ${r.detail}` : ''} — ${r.reason}`); section('Archived (rings → records)', applied.archive, (a) => `[r${a.rid}] [${a.row.type}] **${a.row.label}** ← [e${a.row.id}] — ${a.reason}`); section('Deletions (to cold storage)', applied.delete, (d) => `[e${d.row.id}] **${d.row.label}** — ${d.reason}`); section('Overflow (auto)', overflow, (o) => `[e${o.id}] ring ${o.from.toUpperCase()} → ${o.to === 'cold' ? 'cold storage' : 'ring ' + o.to.toUpperCase()}`); @@ -263,8 +293,11 @@ function cmdApply(manifestPath) { const inventions = asArray(mf.inventions, 'inventions'); const questions = asArray(mf.open_questions, 'open_questions'); - if ((rec.length || arch.length) && !recordsEnabled()) { - errors.push('this character keeps no records — record/archive ops are unavailable (see the run\'s settings.json)'); + if (arch.length && !recordsEnabled()) { + errors.push('this character keeps no records — archive ops are unavailable (see the run\'s settings.json)'); + } + if (rec.length) { + errors.push('filing is not yours — record ops belong to the player at her desk (or the GM CLI); housekeeping is rings-only'); } for (const [i, e] of ins.entries()) { @@ -282,12 +315,6 @@ function cmdApply(manifestPath) { if (row && !String(e.detail ?? '').trim()) errors.push(`reword (e${row.id}): detail is required`); }); del.forEach((e) => ref('delete', e, null)); - for (const [i, e] of rec.entries()) { - need(e.kind, `record[${i}].kind`); - need(e.label, `record[${i}].label`); - if (e.detail !== undefined && typeof e.detail !== 'string') errors.push(`record[${i}].detail must be a string`); - need(e.reason, `record[${i}].reason`); - } arch.forEach((e) => ref('archive', e, null)); for (const [name, arr] of [['inventions', inventions], ['open_questions', questions]]) { arr.forEach((s, i) => { if (typeof s !== 'string' || !s.trim()) errors.push(`${name}[${i}] must be a non-empty string`); }); @@ -299,7 +326,7 @@ function cmdApply(manifestPath) { process.exit(1); } - const applied = { insert: [], touch: [], promote: [], demote: [], reword: [], delete: [], record: [], archive: [] }; + const applied = { insert: [], touch: [], promote: [], demote: [], reword: [], delete: [], archive: [] }; const overflow = []; db.exec('BEGIN'); @@ -337,13 +364,6 @@ function cmdApply(manifestPath) { journal(db, mf.window, 'reword', `e${id}`, e.reason); applied.reword.push({ row: fetch(id), detail: e.detail, reason: e.reason }); } - for (const e of rec) { - const res = db.prepare('INSERT INTO records (kind, label, detail, created) VALUES (?, ?, ?, ?)') - .run(norm(e.kind), norm(e.label), norm(e.detail ?? ''), mf.date); - const rid = Number(res.lastInsertRowid); - journal(db, mf.window, 'record', `r${rid}`, e.reason); - applied.record.push({ rid, ...e }); - } for (const e of arch) { const id = parseId(e.id); const row = fetch(id); @@ -390,7 +410,6 @@ function cmdApply(manifestPath) { applied.promote.length && `${applied.promote.length} promoted`, applied.demote.length && `${applied.demote.length} demoted`, applied.reword.length && `${applied.reword.length} reworded`, - applied.record.length && `${applied.record.length} filed`, applied.archive.length && `${applied.archive.length} archived`, applied.delete.length && `${applied.delete.length} deleted`, overflow.length && `${overflow.length} overflow`, @@ -496,18 +515,65 @@ function cmdRestore(force = false) { renderAll(db); } -function cmdRecord(kind, label, detail) { +function cmdFile(kind, label, detail, reason) { const db = openDb(); if (!recordsEnabled()) fail('this character keeps no records — nothing to file (see the run\'s settings.json)'); - if (!kind?.trim() || !label?.trim()) fail('usage: record "Label" "detail"'); + if (!kind?.trim() || !label?.trim()) fail('usage: file "Label" "detail"'); const res = db.prepare('INSERT INTO records (kind, label, detail, created) VALUES (?, ?, ?, ?)') .run(norm(kind), norm(label), norm(detail ?? ''), today()); const rid = Number(res.lastInsertRowid); - journal(db, 'gm', 'record', `r${rid}`, 'GM edit'); + journal(db, AS_GM ? 'gm' : 'pc', 'record', `r${rid}`, reason ?? (AS_GM ? 'GM seed' : 'player filing')); console.log(`filed [r${rid}] [${norm(kind)}] **${norm(label)}**`); dumpDb(db); } +function cmdAmend(ridStr, detail) { + const db = openDb(); + if (!recordsEnabled()) fail('this character keeps no records'); + const rid = parseRid(ridStr); + const row = rid && db.prepare('SELECT * FROM records WHERE id = ?').get(rid); + if (!row) fail(`no such record: ${ridStr}`); + if (!detail?.trim()) fail('usage: amend "new detail"'); + db.prepare('UPDATE records SET detail = ? WHERE id = ?').run(norm(detail), rid); + journal(db, AS_GM ? 'gm' : 'pc', 'amend', `r${rid}`, 'amended'); + console.log(`amended [r${rid}] **${row.label}** — ${norm(detail)}`); + dumpDb(db); +} + +function cmdDiscard(ridStr, reason) { + const db = openDb(); + if (!recordsEnabled()) fail('this character keeps no records'); + const rid = parseRid(ridStr); + const row = rid && db.prepare('SELECT * FROM records WHERE id = ?').get(rid); + if (!row) fail(`no such record: ${ridStr}`); + db.prepare('DELETE FROM records WHERE id = ?').run(rid); + journal(db, AS_GM ? 'gm' : 'pc', 'discard', `r${rid}`, reason ?? 'discarded'); + console.log(`discarded [r${rid}] **${row.label}**`); + dumpDb(db); +} + +function cmdSet(key, value, reason) { + const db = openDb(); + if (!key?.trim() || !value?.trim()) fail('usage: set "value" ["reason"]'); + db.prepare('INSERT INTO status (key, value, updated) VALUES (?, ?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated = excluded.updated') + .run(norm(key), norm(value), today()); + journal(db, AS_GM ? 'gm' : 'pc', 'status', `s:${norm(key)}`, reason ?? (AS_GM ? 'GM override' : 'player declaration')); + console.log(`status ${norm(key)}: ${norm(value)}`); + renderAll(db); + dumpDb(db); +} + +function cmdUnset(key) { + const db = openDb(); + const row = db.prepare('SELECT * FROM status WHERE key = ?').get(norm(key ?? '')); + if (!row) fail(`no such status key: ${key}`); + db.prepare('DELETE FROM status WHERE key = ?').run(row.key); + journal(db, AS_GM ? 'gm' : 'pc', 'status', `s:${row.key}`, 'cleared'); + console.log(`status ${row.key}: cleared`); + renderAll(db); + dumpDb(db); +} + function cmdSearch(terms) { const db = openDb(); if (!recordsEnabled()) fail('this character keeps no records — nothing to consult'); @@ -543,6 +609,8 @@ function cmdStatus() { console.log(`run: ${RUN}${recordsEnabled() ? '' : ' (no records)'}`); const nr = db.prepare('SELECT COUNT(*) AS n FROM records').get().n; console.log(`records: ${nr}`); + const sk = db.prepare('SELECT key FROM status ORDER BY updated DESC, key').all().map((r) => r.key); + console.log(`status: ${sk.length ? sk.join(', ') : '(nothing set)'}`); 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] ?? '∞'; @@ -566,7 +634,11 @@ switch (cmd) { case 'insert': (args.length >= 3) ? gmOp(args[0], args[1], args[2], args[3] ?? '') : fail('usage: insert "Label" "detail"'); break; case 'delete': (args.length >= 1) ? cmdDelete(args[0], args[1]) : fail('usage: delete "reason"'); break; case 'revive': (args.length >= 1) ? cmdRevive(args[0], args[1]) : fail('usage: revive [a|b]'); break; - case 'record': (args.length >= 2) ? cmdRecord(args[0], args[1], args[2] ?? '') : fail('usage: record "Label" "detail"'); break; + case 'file': (args.length >= 2) ? cmdFile(args[0], args[1], args[2] ?? '', args[3]) : fail('usage: file "Label" "detail" ["reason"]'); break; + case 'amend': (args.length >= 2) ? cmdAmend(args[0], args[1]) : fail('usage: amend "new detail"'); break; + case 'discard': (args.length >= 1) ? cmdDiscard(args[0], args[1]) : fail('usage: discard "reason"'); break; + case 'set': (args.length >= 2) ? cmdSet(args[0], args[1], args[2]) : fail('usage: set "value" ["reason"]'); break; + case 'unset': (args.length >= 1) ? cmdUnset(args[0]) : fail('usage: unset '); break; case 'search': cmdSearch(args); break; case 'unarchive': (args.length >= 1) ? cmdUnarchive(args[0], args[1]) : fail('usage: unarchive [a|b]'); break; case 'status': cmdStatus(); break;