ownership: player keeps own status and records; housekeeping rings-only

This commit is contained in:
2026-11-11 18:44:58 +00:00
parent b77a0de527
commit f5aa09c686
9 changed files with 229 additions and 59 deletions
+34 -15
View File
@@ -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 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>/character.md`,
then `runs/<story>/canon/ring-a.md` and `ring-b.md`, then narrate the then `runs/<story>/canon/status.md`, then `ring-a.md` and `ring-b.md`,
first beat. (On a tight window, ring B is optional loading — ring A is then narrate the first beat. (On a tight window, ring B is optional
the spine.) 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
reference a memory. To consult the records (when the views say they're reference a memory. Status declarations (`((status key: value))`) are
available): `((q: sapphire buyers))` — the GM runs `search` and relays relayed to `set`/`unset`; record work (`((q:))`, `((file:))`,
the result (max 10; a miss is a miss). `((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 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
@@ -82,15 +83,22 @@ 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 **four tiers**: Memory is **five tiers**:
| tier | what | in context | who writes it | | 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 | | **identity** | the character sheet — concept, drives, skills, voice; changes rarely | always | GM, rarely; housekeeper may propose via open questions |
| **rings A/B** | salient memory — on her mind, MRU-evicted, terse | always | housekeeper manifest | | **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 |
| **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 | | **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`) | | **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/<story>/settings.json` Records access is **diegetic and per-run**: `runs/<story>/settings.json`
gates it. The boutique's keeper has her card index on the shop PC gates it. The boutique's keeper has her card index on the shop PC
(`"records": true`); the prisoners have nothing (`"records": false`). The (`"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. 10. **Query discipline** — narrow queries; zero retry-on-miss cascades.
11. **Archive classification** — on-her-mind (rings) vs in-her-files 11. **Archive classification** — on-her-mind (rings) vs in-her-files
(records): are customer cards filed, not memorized? (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 ## 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 **Substrate note:** the future SPA is a UI and a session runner wrapped
around exactly these moving parts — the DB, the manifest, `apply`, `render`. 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 ## Layout
@@ -223,11 +241,12 @@ housekeeper.md system prompt for the post-session housekeeping model (shared)
config.json the default run config.json the default run
tool/ tool/
memory.mjs the clerk: runs, init, render, apply, insert, delete, revive, 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 <name>; --gm for GM writes)
db/ db/
schema.sql entries, records, events journal (shared by all runs) schema.sql entries, records, status, events journal (shared)
runs/ runs/
prisoners/ one story: character.md, settings.json, db/, dumps/, canon/, prisoners/ one story: character.md, settings.json, db/, dumps/, canon/
log/, manifests/ — records disabled (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)
``` ```
+11 -2
View File
@@ -27,12 +27,21 @@ CREATE TABLE IF NOT EXISTS records (
created TEXT NOT NULL 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. -- append-only audit journal; nothing here is ever updated or deleted.
-- target is 'e<id>' for entries, 'r<id>' for records. -- target is 'e<id>' for entries, 'r<id>' for records, 's:<key>' for status.
CREATE TABLE IF NOT EXISTS events ( CREATE TABLE IF NOT EXISTS events (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
window TEXT NOT NULL, 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, target TEXT NOT NULL,
reason TEXT NOT NULL DEFAULT '' reason TEXT NOT NULL DEFAULT ''
); );
+18 -14
View File
@@ -48,7 +48,6 @@ what the character would carry forward, not what a historian would record.
"demote": [ { "id": "e7", "reason": "the matter resolved" } ], "demote": [ { "id": "e7", "reason": "the matter resolved" } ],
"reword": [ { "id": "e9", "detail": "new wording", "reason": "what changed and why" } ], "reword": [ { "id": "e9", "detail": "new wording", "reason": "what changed and why" } ],
"delete": [ { "id": "e3", "reason": "GM veto / retcon" } ], "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" } ], "archive": [ { "id": "e31", "reason": "reference material now, not on her mind" } ],
"inventions": [ "what the player introduced that adds to the world, for GM veto" ], "inventions": [ "what the player introduced that adds to the world, for GM veto" ],
"open_questions": [ "contradictions, ambiguities, anything needing a GM ruling" ] "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 Every key except `window`, `date`, and `summary` is optional — empty or
omitted is fine. Types are `place`, `person`, `fact`, `thread`. Ids come omitted is fine. Types are `place`, `person`, `fact`, `thread`. Ids come
from the rendered views; never invent one. `record` and `archive` are only from the rendered views; never invent one. Housekeeping is **rings-only**:
valid when the ring views say records are available — the tool rejects them `archive` is valid when the ring views say records are available, but
otherwise. `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 Promote, demote, and reword count as touches — the script updates the touch
date for you. Don't list an id twice across operations. 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 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." retcon a fact; that's what this is for. Never delete to "clean up."
9. **Records — the character's files.** Cards, ledgers, manifests: 9. **Records — the character's files, kept by her.** She files, amends,
detailed, but never in her thoughts. What doesn't earn ring space but and discards at her desk; the GM seeds. Filing is not your job — your
she'd have written down goes to the records (when they're available for only records op is `archive`: moving a ring entry into her files when
her — the views say so). Ring entries stay terse pointers when a record it stops being on her mind (a rings decision that materializes the
exists ("Mrs. Ashworth — customer, see card" is a good ring-B entry). file). Ring entries stay terse pointers when a record exists ("Mrs.
`archive` moves a ring entry into the files: on her mind → in her Ashworth — customer, see card" is a good ring-B entry). **Archived is
drawer. **Archived is not forgotten** — records answer her queries; not forgotten** — records answer her queries; cold storage doesn't.
cold storage doesn't. Keep that boundary straight.
10. **Queries are attention.** If the character consulted the records this 10. **Queries are attention.** If the character consulted the records this
session, the looked-up subject is on her mind — consider a ring 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). (leave it forgotten — flag it in open questions if it seems load-bearing).
- A contradiction between transcript and rings goes in open questions — - A contradiction between transcript and rings goes in open questions —
never silently absorbed, never silently retconned. never silently absorbed, never silently retconned.
- `character.md` is the GM's. If identity or drives have shifted, propose - Rings hold **facts, never her feelings**. Stances ("Marta: trust
an amendment in open questions; never edit the sheet yourself. 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.
+7
View File
@@ -0,0 +1,7 @@
<!-- GENERATED by tool/memory.mjs render — do not edit by hand. -->
<!-- The player's own current state, maintained via ((status key: value)) in OOC. -->
<!-- Stances are feelings; facts live in the rings. GM overrides are rare and journaled. -->
# Status
(nothing set — fresh start)
+11 -2
View File
@@ -29,12 +29,21 @@ CREATE TABLE IF NOT EXISTS records (
created TEXT NOT NULL 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. -- append-only audit journal; nothing here is ever updated or deleted.
-- target is 'e<id>' for entries, 'r<id>' for records. -- target is 'e<id>' for entries, 'r<id>' for records, 's:<key>' for status.
CREATE TABLE IF NOT EXISTS events ( CREATE TABLE IF NOT EXISTS events (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
window TEXT NOT NULL, 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, target TEXT NOT NULL,
reason TEXT NOT NULL DEFAULT '' reason TEXT NOT NULL DEFAULT ''
); );
+7
View File
@@ -0,0 +1,7 @@
<!-- GENERATED by tool/memory.mjs render — do not edit by hand. -->
<!-- The player's own current state, maintained via ((status key: value)) in OOC. -->
<!-- Stances are feelings; facts live in the rings. GM overrides are rare and journaled. -->
# Status
(nothing set — fresh start)
+11 -2
View File
@@ -29,12 +29,21 @@ CREATE TABLE IF NOT EXISTS records (
created TEXT NOT NULL 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. -- append-only audit journal; nothing here is ever updated or deleted.
-- target is 'e<id>' for entries, 'r<id>' for records. -- target is 'e<id>' for entries, 'r<id>' for records, 's:<key>' for status.
CREATE TABLE IF NOT EXISTS events ( CREATE TABLE IF NOT EXISTS events (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
window TEXT NOT NULL, 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, target TEXT NOT NULL,
reason TEXT NOT NULL DEFAULT '' reason TEXT NOT NULL DEFAULT ''
); );
+34
View File
@@ -69,6 +69,29 @@ happen.
- `log/` is the housekeeper's output, for the GM's eyes. You never read it. - `log/` is the housekeeper's output, for the GM's eyes. You never read it.
Past sessions are not your memory; the rings are. 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 # The records
Depending on the story, your character may keep records — a card index, a 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" doesn't have it written down; play on. (Concluding "not in my records"
in-fiction is honest use of a miss; rummaging is not.) 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 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. shapes the rings. Don't query in order to memorize; that's not your lever.
+96 -24
View File
@@ -14,9 +14,14 @@
// insert <ring> <type> "Label" "detail" GM-authoritative insert // insert <ring> <type> "Label" "detail" GM-authoritative insert
// delete <id> "reason" GM-authoritative removal to cold storage // delete <id> "reason" GM-authoritative removal to cold storage
// revive <id> [a|b] GM pulls an entry back from cold storage // revive <id> [a|b] GM pulls an entry back from cold storage
// record <kind> "Label" "detail" GM files a record (if records are enabled) // file <kind> "Label" "detail" the PC files a record at her desk
// (records-enabled runs; --gm to seed as GM)
// amend <rid> "new detail" the PC amends a record (--gm for GM fixes)
// discard <rid> "reason" the PC discards a record (--gm likewise)
// search <terms...> query the records (max 10; a miss is a miss) // search <terms...> query the records (max 10; a miss is a miss)
// unarchive <rid> [a|b] GM pulls a record back into the rings // unarchive <rid> [a|b] GM pulls a record back into the rings
// set <key> "value" the PC updates her status (--gm to override)
// 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
@@ -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 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": "..."} // flags: --run <name> beats config.json {"run": "..."}; --gm attributes the op to the GM
const argv = process.argv.slice(2); const argv = process.argv.slice(2);
const runIdx = argv.indexOf('--run'); const runIdx = argv.indexOf('--run');
let runOverride = null; let runOverride = null;
@@ -50,6 +55,8 @@ if (runIdx !== -1) {
runOverride = argv[runIdx + 1] ?? null; runOverride = argv[runIdx + 1] ?? null;
argv.splice(runIdx, 2); 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; const [cmd, ...args] = argv;
function resolveRun() { function resolveRun() {
@@ -133,11 +140,32 @@ function renderRing(db, ring) {
return { file, count: rows.length }; return { file, count: rows.length };
} }
function renderStatus(db) {
const rows = db.prepare('SELECT * FROM status ORDER BY updated DESC, key').all();
const lines = [
'<!-- GENERATED by tool/memory.mjs render — do not edit by hand. -->',
"<!-- The player's own current state, maintained via ((status key: value)) in OOC. -->",
'<!-- Stances are feelings; facts live in the rings. GM overrides are rare and journaled. -->',
'',
'# 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) { function renderAll(db) {
for (const ring of RINGS) { for (const ring of RINGS) {
const { file, count } = renderRing(db, ring); const { file, count } = renderRing(db, ring);
console.log(`${rel(file)} — ${count} entries`); 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. // 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()) { 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)});`); 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()) { 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)});`); 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('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('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('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('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('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()}`); 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 inventions = asArray(mf.inventions, 'inventions');
const questions = asArray(mf.open_questions, 'open_questions'); const questions = asArray(mf.open_questions, 'open_questions');
if ((rec.length || arch.length) && !recordsEnabled()) { if (arch.length && !recordsEnabled()) {
errors.push('this character keeps no records — record/archive ops are unavailable (see the run\'s settings.json)'); 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()) { 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`); if (row && !String(e.detail ?? '').trim()) errors.push(`reword (e${row.id}): detail is required`);
}); });
del.forEach((e) => ref('delete', e, null)); 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)); arch.forEach((e) => ref('archive', e, null));
for (const [name, arr] of [['inventions', inventions], ['open_questions', questions]]) { 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`); }); 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); process.exit(1);
} }
const applied = { insert: [], touch: [], promote: [], demote: [], reword: [], delete: [], record: [], archive: [] }; const applied = { insert: [], touch: [], promote: [], demote: [], reword: [], delete: [], archive: [] };
const overflow = []; const overflow = [];
db.exec('BEGIN'); db.exec('BEGIN');
@@ -337,13 +364,6 @@ function cmdApply(manifestPath) {
journal(db, mf.window, 'reword', `e${id}`, e.reason); journal(db, mf.window, 'reword', `e${id}`, e.reason);
applied.reword.push({ row: fetch(id), detail: e.detail, reason: 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) { for (const e of arch) {
const id = parseId(e.id); const id = parseId(e.id);
const row = fetch(id); const row = fetch(id);
@@ -390,7 +410,6 @@ function cmdApply(manifestPath) {
applied.promote.length && `${applied.promote.length} promoted`, applied.promote.length && `${applied.promote.length} promoted`,
applied.demote.length && `${applied.demote.length} demoted`, applied.demote.length && `${applied.demote.length} demoted`,
applied.reword.length && `${applied.reword.length} reworded`, applied.reword.length && `${applied.reword.length} reworded`,
applied.record.length && `${applied.record.length} filed`,
applied.archive.length && `${applied.archive.length} archived`, applied.archive.length && `${applied.archive.length} archived`,
applied.delete.length && `${applied.delete.length} deleted`, applied.delete.length && `${applied.delete.length} deleted`,
overflow.length && `${overflow.length} overflow`, overflow.length && `${overflow.length} overflow`,
@@ -496,18 +515,65 @@ function cmdRestore(force = false) {
renderAll(db); renderAll(db);
} }
function cmdRecord(kind, label, detail) { function cmdFile(kind, label, detail, reason) {
const db = openDb(); const db = openDb();
if (!recordsEnabled()) fail('this character keeps no records — nothing to file (see the run\'s settings.json)'); 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 <kind> "Label" "detail"'); if (!kind?.trim() || !label?.trim()) fail('usage: file <kind> "Label" "detail"');
const res = db.prepare('INSERT INTO records (kind, label, detail, created) VALUES (?, ?, ?, ?)') const res = db.prepare('INSERT INTO records (kind, label, detail, created) VALUES (?, ?, ?, ?)')
.run(norm(kind), norm(label), norm(detail ?? ''), today()); .run(norm(kind), norm(label), norm(detail ?? ''), today());
const rid = Number(res.lastInsertRowid); 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)}**`); console.log(`filed [r${rid}] [${norm(kind)}] **${norm(label)}**`);
dumpDb(db); 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 <rid> "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 <key> "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) { function cmdSearch(terms) {
const db = openDb(); const db = openDb();
if (!recordsEnabled()) fail('this character keeps no records — nothing to consult'); if (!recordsEnabled()) fail('this character keeps no records — nothing to consult');
@@ -543,6 +609,8 @@ function cmdStatus() {
console.log(`run: ${RUN}${recordsEnabled() ? '' : ' (no records)'}`); console.log(`run: ${RUN}${recordsEnabled() ? '' : ' (no records)'}`);
const nr = db.prepare('SELECT COUNT(*) AS n FROM records').get().n; const nr = db.prepare('SELECT COUNT(*) AS n FROM records').get().n;
console.log(`records: ${nr}`); 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']) { 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] ?? '∞';
@@ -566,7 +634,11 @@ switch (cmd) {
case 'insert': (args.length >= 3) ? gmOp(args[0], args[1], args[2], args[3] ?? '') : fail('usage: insert <a|b> <type> "Label" "detail"'); break; case 'insert': (args.length >= 3) ? gmOp(args[0], args[1], args[2], args[3] ?? '') : fail('usage: insert <a|b> <type> "Label" "detail"'); break;
case 'delete': (args.length >= 1) ? cmdDelete(args[0], args[1]) : fail('usage: delete <id> "reason"'); break; case 'delete': (args.length >= 1) ? cmdDelete(args[0], args[1]) : fail('usage: delete <id> "reason"'); break;
case 'revive': (args.length >= 1) ? cmdRevive(args[0], args[1]) : fail('usage: revive <id> [a|b]'); break; case 'revive': (args.length >= 1) ? cmdRevive(args[0], args[1]) : fail('usage: revive <id> [a|b]'); break;
case 'record': (args.length >= 2) ? cmdRecord(args[0], args[1], args[2] ?? '') : fail('usage: record <kind> "Label" "detail"'); break; case 'file': (args.length >= 2) ? cmdFile(args[0], args[1], args[2] ?? '', args[3]) : fail('usage: file <kind> "Label" "detail" ["reason"]'); break;
case 'amend': (args.length >= 2) ? cmdAmend(args[0], args[1]) : fail('usage: amend <rid> "new detail"'); break;
case 'discard': (args.length >= 1) ? cmdDiscard(args[0], args[1]) : fail('usage: discard <rid> "reason"'); break;
case 'set': (args.length >= 2) ? cmdSet(args[0], args[1], args[2]) : fail('usage: set <key> "value" ["reason"]'); break;
case 'unset': (args.length >= 1) ? cmdUnset(args[0]) : fail('usage: unset <key>'); break;
case 'search': cmdSearch(args); break; case 'search': cmdSearch(args); break;
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;