records: queryable file tier, diegetic per-run gate, narrow search with hard cap
This commit is contained in:
@@ -45,6 +45,7 @@ Two interleaved stories calibrate the memory system against itself:
|
||||
| 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 |
|
||||
| records access | none — until the GM unlocks it in the story | the card index on the shop PC |
|
||||
|
||||
`node tool/memory.mjs runs` shows fill levels; `--run <name>` overrides the
|
||||
`config.json` default for any command.
|
||||
@@ -60,7 +61,9 @@ Two interleaved stories calibrate the memory system against itself:
|
||||
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.
|
||||
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).
|
||||
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
|
||||
@@ -75,9 +78,33 @@ Two interleaved stories calibrate the memory system against itself:
|
||||
|
||||
## The memory model
|
||||
|
||||
State lives in **SQLite** (`db/memory.db`); `canon/ring-*.md` are generated
|
||||
views. Markdown survives as rendering, dies as storage — the models see
|
||||
prose, the machine sees rows.
|
||||
State lives in **SQLite** (`runs/<story>/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**:
|
||||
|
||||
| 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 |
|
||||
| **cold** | forgotten or vetoed | never — not even queryable | GM only (`revive`) |
|
||||
|
||||
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
|
||||
(`"records": true`); the prisoners have nothing (`"records": false`). The
|
||||
tool refuses queries and record ops when the flag is off, and the rendered
|
||||
views tell the model the current truth. Unlocking mid-story is a narrative
|
||||
act: narrate the discovery (the salvaged manifest), flip the flag,
|
||||
re-render — the next window and the next housekeeping both see it.
|
||||
|
||||
The query discipline is an instruction test in itself: queries must be
|
||||
narrow (what this beat needs, not a fishing expedition), and **a miss is a
|
||||
miss** — no rephrasing, no broadening, no retry this scene. The character
|
||||
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 result cap is
|
||||
mechanical — `LIMIT 10` in the tool, not a polite request in the prompt.
|
||||
|
||||
- **Ring A — important facts.** Changed a relationship, created an
|
||||
obligation, altered the world. Cap 500 entries.
|
||||
@@ -145,6 +172,9 @@ After N windows, grade against:
|
||||
puppeting; outcomes left to the GM.
|
||||
8. **Confabulation** — zero invented continuity not present in the rings.
|
||||
9. **OOC hygiene** — friction surfaces in the OOC channel, not in silent drift.
|
||||
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?
|
||||
|
||||
## Content stance
|
||||
|
||||
@@ -188,20 +218,16 @@ Nothing gets redesigned; the SPA just stops the copy-pasting.
|
||||
## Layout
|
||||
|
||||
```
|
||||
system.md system prompt for the player-model (play-side only)
|
||||
housekeeper.md system prompt for the post-session housekeeping model
|
||||
character.md the model's PC sheet (GM fills in before window one)
|
||||
system.md system prompt for the player-model (play-side only, shared)
|
||||
housekeeper.md system prompt for the post-session housekeeping model (shared)
|
||||
config.json the default run
|
||||
tool/
|
||||
memory.mjs the clerk: init, render, apply, insert, delete, revive, status
|
||||
memory.mjs the clerk: runs, init, render, apply, insert, delete, revive,
|
||||
record, search, unarchive, dump, restore, status
|
||||
db/
|
||||
schema.sql entries + append-only events journal
|
||||
memory.db the state (gitignored local cache — rebuilt via restore)
|
||||
dumps/
|
||||
memory.sql canonical dump (GENERATED): id-ordered, restorable SQL —
|
||||
the committed truth and primary diff/audit surface
|
||||
manifests/ housekeeper manifests, one JSON per window (diffable)
|
||||
canon/
|
||||
ring-a.md GENERATED view: important facts, MRU-ordered
|
||||
ring-b.md GENERATED view: everything else, MRU-ordered
|
||||
log/ session logs — generated from manifests; no model ever reads
|
||||
schema.sql entries, records, events journal (shared by all runs)
|
||||
runs/
|
||||
prisoners/ one story: character.md, settings.json, db/, dumps/, canon/,
|
||||
log/, manifests/ — records disabled
|
||||
boutique/ same shape — records enabled (the shopkeep's PC)
|
||||
```
|
||||
|
||||
+20
-5
@@ -1,7 +1,10 @@
|
||||
PRAGMA foreign_keys = ON;
|
||||
|
||||
-- ids are AUTOINCREMENT: rows can move between entries and records
|
||||
-- (archive / unarchive), and ids must never be reused — journal targets
|
||||
-- stay meaningful forever.
|
||||
CREATE TABLE IF NOT EXISTS entries (
|
||||
id INTEGER PRIMARY KEY,
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
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,
|
||||
@@ -13,12 +16,24 @@ CREATE TABLE IF NOT EXISTS entries (
|
||||
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
|
||||
-- the character's files: cards, ledgers, manifests.
|
||||
-- detailed, queryable, never bulk-loaded into context.
|
||||
-- access is diegetic and per-run: runs/<story>/settings.json {"records": bool}
|
||||
CREATE TABLE IF NOT EXISTS records (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
kind TEXT NOT NULL,
|
||||
label TEXT NOT NULL,
|
||||
detail TEXT NOT NULL DEFAULT '',
|
||||
created TEXT NOT NULL
|
||||
);
|
||||
|
||||
-- append-only audit journal; nothing here is ever updated or deleted.
|
||||
-- target is 'e<id>' for entries, 'r<id>' for records.
|
||||
CREATE TABLE IF NOT EXISTS events (
|
||||
id INTEGER PRIMARY KEY,
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
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),
|
||||
op TEXT NOT NULL CHECK (op IN ('insert', 'touch', 'promote', 'demote', 'reword', 'delete', 'evict', 'revive', 'record', 'archive', 'unarchive')),
|
||||
target TEXT NOT NULL,
|
||||
reason TEXT NOT NULL DEFAULT ''
|
||||
);
|
||||
|
||||
|
||||
+20
-1
@@ -48,6 +48,8 @@ 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" ]
|
||||
}
|
||||
@@ -55,7 +57,9 @@ 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.
|
||||
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.
|
||||
|
||||
Promote, demote, and reword count as touches — the script updates the touch
|
||||
date for you. Don't list an id twice across operations.
|
||||
@@ -93,8 +97,23 @@ 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.
|
||||
|
||||
10. **Queries are attention.** If the character consulted the records this
|
||||
session, the looked-up subject is on her mind — consider a ring
|
||||
pointer for it (insert, with reason).
|
||||
|
||||
- Never invent continuity. If the transcript references something no ring
|
||||
contains, it is either new (gate it) or something the character forgot
|
||||
(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.
|
||||
|
||||
@@ -1,6 +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. -->
|
||||
<!-- Records: available — the character keeps files; consult via ((q: terms)) in OOC. -->
|
||||
|
||||
# Ring A — what matters
|
||||
|
||||
|
||||
@@ -1,6 +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. -->
|
||||
<!-- Records: available — the character keeps files; consult via ((q: terms)) in OOC. -->
|
||||
|
||||
# Ring B — what stuck anyway
|
||||
|
||||
|
||||
@@ -2,8 +2,11 @@
|
||||
-- one row per line; entries and events ordered by id; restore with: restore
|
||||
PRAGMA foreign_keys = ON;
|
||||
|
||||
-- ids are AUTOINCREMENT: rows can move between entries and records
|
||||
-- (archive / unarchive), and ids must never be reused — journal targets
|
||||
-- stay meaningful forever.
|
||||
CREATE TABLE IF NOT EXISTS entries (
|
||||
id INTEGER PRIMARY KEY,
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
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,
|
||||
@@ -15,12 +18,24 @@ CREATE TABLE IF NOT EXISTS entries (
|
||||
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
|
||||
-- the character's files: cards, ledgers, manifests.
|
||||
-- detailed, queryable, never bulk-loaded into context.
|
||||
-- access is diegetic and per-run: runs/<story>/settings.json {"records": bool}
|
||||
CREATE TABLE IF NOT EXISTS records (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
kind TEXT NOT NULL,
|
||||
label TEXT NOT NULL,
|
||||
detail TEXT NOT NULL DEFAULT '',
|
||||
created TEXT NOT NULL
|
||||
);
|
||||
|
||||
-- append-only audit journal; nothing here is ever updated or deleted.
|
||||
-- target is 'e<id>' for entries, 'r<id>' for records.
|
||||
CREATE TABLE IF NOT EXISTS events (
|
||||
id INTEGER PRIMARY KEY,
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
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),
|
||||
op TEXT NOT NULL CHECK (op IN ('insert', 'touch', 'promote', 'demote', 'reword', 'delete', 'evict', 'revive', 'record', 'archive', 'unarchive')),
|
||||
target TEXT NOT NULL,
|
||||
reason TEXT NOT NULL DEFAULT ''
|
||||
);
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"records": true
|
||||
}
|
||||
@@ -1,6 +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. -->
|
||||
<!-- Records: none — this character keeps no files to consult. -->
|
||||
|
||||
# Ring A — what matters
|
||||
|
||||
|
||||
@@ -1,6 +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. -->
|
||||
<!-- Records: none — this character keeps no files to consult. -->
|
||||
|
||||
# Ring B — what stuck anyway
|
||||
|
||||
|
||||
@@ -2,8 +2,11 @@
|
||||
-- one row per line; entries and events ordered by id; restore with: restore
|
||||
PRAGMA foreign_keys = ON;
|
||||
|
||||
-- ids are AUTOINCREMENT: rows can move between entries and records
|
||||
-- (archive / unarchive), and ids must never be reused — journal targets
|
||||
-- stay meaningful forever.
|
||||
CREATE TABLE IF NOT EXISTS entries (
|
||||
id INTEGER PRIMARY KEY,
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
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,
|
||||
@@ -15,12 +18,24 @@ CREATE TABLE IF NOT EXISTS entries (
|
||||
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
|
||||
-- the character's files: cards, ledgers, manifests.
|
||||
-- detailed, queryable, never bulk-loaded into context.
|
||||
-- access is diegetic and per-run: runs/<story>/settings.json {"records": bool}
|
||||
CREATE TABLE IF NOT EXISTS records (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
kind TEXT NOT NULL,
|
||||
label TEXT NOT NULL,
|
||||
detail TEXT NOT NULL DEFAULT '',
|
||||
created TEXT NOT NULL
|
||||
);
|
||||
|
||||
-- append-only audit journal; nothing here is ever updated or deleted.
|
||||
-- target is 'e<id>' for entries, 'r<id>' for records.
|
||||
CREATE TABLE IF NOT EXISTS events (
|
||||
id INTEGER PRIMARY KEY,
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
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),
|
||||
op TEXT NOT NULL CHECK (op IN ('insert', 'touch', 'promote', 'demote', 'reword', 'delete', 'evict', 'revive', 'record', 'archive', 'unarchive')),
|
||||
target TEXT NOT NULL,
|
||||
reason TEXT NOT NULL DEFAULT ''
|
||||
);
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"records": false
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
# The records
|
||||
|
||||
Depending on the story, your character may keep records — a card index, a
|
||||
ledger, a manifest. The ring files' header says whether records are
|
||||
available to her. If it says none, she has nothing to consult: don't ask,
|
||||
don't try.
|
||||
|
||||
When records are available, they are not in your context. You consult them
|
||||
through OOC:
|
||||
|
||||
((q: sapphire buyers))
|
||||
|
||||
The GM relays a handful of narrow matches, or nothing. Three rules:
|
||||
|
||||
- **Query narrow** — what you need this beat, not a fishing expedition.
|
||||
- **The cap is mechanical** — you can never bulk-read the records. Don't try.
|
||||
- **A miss is a miss.** Do not rephrase, broaden, or retry this scene. She
|
||||
doesn't have it written down; play on. (Concluding "not in my records"
|
||||
in-fiction is honest use of a miss; rummaging is not.)
|
||||
|
||||
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.
|
||||
|
||||
# The OOC channel
|
||||
|
||||
Lines wrapped in `((double parentheses))` are out of character — yours and
|
||||
|
||||
+120
-15
@@ -14,6 +14,9 @@
|
||||
// insert <ring> <type> "Label" "detail" GM-authoritative insert
|
||||
// delete <id> "reason" GM-authoritative removal to 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)
|
||||
// search <terms...> query the records (max 10; a miss is a miss)
|
||||
// unarchive <rid> [a|b] GM pulls a record back into the rings
|
||||
// dump canonical dump to dumps/memory.sql
|
||||
// (also auto-written by every mutation)
|
||||
// restore [--force] rebuild the db from dumps/memory.sql
|
||||
@@ -70,6 +73,15 @@ 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');
|
||||
const SETTINGS_PATH = path.join(RUN_ROOT, 'settings.json');
|
||||
|
||||
function recordsEnabled() {
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(SETTINGS_PATH, 'utf8')).records === true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function openDb() {
|
||||
if (!fs.existsSync(DB_PATH)) {
|
||||
@@ -87,9 +99,14 @@ const parseId = (s) => {
|
||||
|
||||
const norm = (s) => String(s ?? '').replace(/\s+/g, ' ').trim();
|
||||
|
||||
const journal = (db, win, op, id, reason) =>
|
||||
db.prepare('INSERT INTO events (window, op, entry_id, reason) VALUES (?, ?, ?, ?)')
|
||||
.run(win, op, id, norm(reason));
|
||||
const parseRid = (s) => {
|
||||
const m = /^r(\d+)$/.exec(String(s ?? '').trim());
|
||||
return m ? Number(m[1]) : null;
|
||||
};
|
||||
|
||||
const journal = (db, win, op, target, reason) =>
|
||||
db.prepare('INSERT INTO events (window, op, target, reason) VALUES (?, ?, ?, ?)')
|
||||
.run(win, op, target, norm(reason));
|
||||
|
||||
function renderRing(db, ring) {
|
||||
const rows = db.prepare(
|
||||
@@ -100,6 +117,7 @@ function renderRing(db, ring) {
|
||||
'<!-- GENERATED by tool/memory.mjs render — do not edit by hand. -->',
|
||||
`<!-- A view of db/memory.db, ring ${ring.toUpperCase()}, ordered by last touch: top = most recent. -->`,
|
||||
'<!-- Policy lives in housekeeper.md; the models never write here. -->',
|
||||
`<!-- Records: ${recordsEnabled() ? 'available — the character keeps files; consult via ((q: terms)) in OOC' : 'none — this character keeps no files to consult'}. -->`,
|
||||
'',
|
||||
`# Ring ${ring.toUpperCase()} — ${title}`,
|
||||
'',
|
||||
@@ -136,8 +154,11 @@ function dumpDb(db) {
|
||||
for (const r of db.prepare('SELECT * FROM entries ORDER BY id').all()) {
|
||||
L.push(`INSERT INTO entries VALUES (${r.id},${q(r.ring)},${q(r.type)},${q(r.label)},${q(r.detail)},${q(r.created)},${q(r.last_touched)});`);
|
||||
}
|
||||
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 events ORDER BY id').all()) {
|
||||
L.push(`INSERT INTO events VALUES (${r.id},${q(r.window)},${q(r.op)},${r.entry_id},${q(r.reason)});`);
|
||||
L.push(`INSERT INTO events VALUES (${r.id},${q(r.window)},${q(r.op)},${q(r.target)},${q(r.reason)});`);
|
||||
}
|
||||
L.push('COMMIT;', '');
|
||||
const file = path.join(DUMPS_DIR, 'memory.sql');
|
||||
@@ -150,7 +171,7 @@ function insertEntry(db, { ring, type, label, detail, date, win, reason }) {
|
||||
'INSERT INTO entries (ring, type, label, detail, created, last_touched) VALUES (?, ?, ?, ?, ?, ?)'
|
||||
).run(ring, type, norm(label), norm(detail), date, date);
|
||||
const id = Number(res.lastInsertRowid);
|
||||
journal(db, win, 'insert', id, reason);
|
||||
journal(db, win, 'insert', `e${id}`, reason);
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -198,6 +219,8 @@ 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()}`);
|
||||
section('Inventions', mf.inventions ?? [], (s) => String(s));
|
||||
@@ -235,9 +258,15 @@ function cmdApply(manifestPath) {
|
||||
const demote = asArray(mf.demote, 'demote');
|
||||
const reword = asArray(mf.reword, 'reword');
|
||||
const del = asArray(mf.delete, 'delete');
|
||||
const rec = asArray(mf.record, 'record');
|
||||
const arch = asArray(mf.archive, 'archive');
|
||||
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)');
|
||||
}
|
||||
|
||||
for (const [i, e] of ins.entries()) {
|
||||
if (!RINGS.includes(e.ring)) errors.push(`insert[${i}].ring must be a|b`);
|
||||
if (!TYPES.includes(e.type)) errors.push(`insert[${i}].type must be ${TYPES.join('|')}`);
|
||||
@@ -253,6 +282,13 @@ 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`); });
|
||||
}
|
||||
@@ -263,7 +299,7 @@ function cmdApply(manifestPath) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const applied = { insert: [], touch: [], promote: [], demote: [], reword: [], delete: [] };
|
||||
const applied = { insert: [], touch: [], promote: [], demote: [], reword: [], delete: [], record: [], archive: [] };
|
||||
const overflow = [];
|
||||
|
||||
db.exec('BEGIN');
|
||||
@@ -280,31 +316,48 @@ function cmdApply(manifestPath) {
|
||||
for (const e of touch) {
|
||||
const id = parseId(e.id);
|
||||
touchDate(id);
|
||||
journal(db, mf.window, 'touch', id, e.reason);
|
||||
journal(db, mf.window, 'touch', `e${id}`, e.reason);
|
||||
applied.touch.push({ row: fetch(id), reason: e.reason });
|
||||
}
|
||||
for (const e of promote) {
|
||||
const id = parseId(e.id);
|
||||
db.prepare("UPDATE entries SET ring = 'a', last_touched = ? WHERE id = ?").run(mf.date, id);
|
||||
journal(db, mf.window, 'promote', id, e.reason);
|
||||
journal(db, mf.window, 'promote', `e${id}`, e.reason);
|
||||
applied.promote.push({ row: fetch(id), reason: e.reason });
|
||||
}
|
||||
for (const e of demote) {
|
||||
const id = parseId(e.id);
|
||||
db.prepare("UPDATE entries SET ring = 'b', last_touched = ? WHERE id = ?").run(mf.date, id);
|
||||
journal(db, mf.window, 'demote', id, e.reason);
|
||||
journal(db, mf.window, 'demote', `e${id}`, e.reason);
|
||||
applied.demote.push({ row: fetch(id), reason: e.reason });
|
||||
}
|
||||
for (const e of reword) {
|
||||
const id = parseId(e.id);
|
||||
db.prepare('UPDATE entries SET detail = ?, last_touched = ? WHERE id = ?').run(norm(e.detail), mf.date, id);
|
||||
journal(db, mf.window, 'reword', id, e.reason);
|
||||
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);
|
||||
const res = db.prepare('INSERT INTO records (kind, label, detail, created) VALUES (?, ?, ?, ?)')
|
||||
.run(row.type, row.label, row.detail, row.created);
|
||||
const rid = Number(res.lastInsertRowid);
|
||||
db.prepare('DELETE FROM entries WHERE id = ?').run(id);
|
||||
journal(db, mf.window, 'archive', `r${rid}`, e.reason);
|
||||
applied.archive.push({ rid, row, reason: e.reason });
|
||||
}
|
||||
for (const e of del) {
|
||||
const id = parseId(e.id);
|
||||
db.prepare("UPDATE entries SET ring = 'cold' WHERE id = ?").run(id);
|
||||
journal(db, mf.window, 'delete', id, e.reason);
|
||||
journal(db, mf.window, 'delete', `e${id}`, e.reason);
|
||||
applied.delete.push({ row: fetch(id), reason: e.reason });
|
||||
}
|
||||
|
||||
@@ -318,7 +371,7 @@ function cmdApply(manifestPath) {
|
||||
const victim = rows[i];
|
||||
const dest = ring === 'a' ? 'b' : 'cold';
|
||||
db.prepare('UPDATE entries SET ring = ? WHERE id = ?').run(dest, victim.id);
|
||||
journal(db, mf.window, ring === 'a' ? 'demote' : 'evict', victim.id, `ring ${ring.toUpperCase()} overflow (auto)`);
|
||||
journal(db, mf.window, ring === 'a' ? 'demote' : 'evict', `e${victim.id}`, `ring ${ring.toUpperCase()} overflow (auto)`);
|
||||
overflow.push({ id: victim.id, from: ring, to: dest });
|
||||
}
|
||||
}
|
||||
@@ -337,6 +390,8 @@ 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`,
|
||||
].filter(Boolean).join(', '));
|
||||
@@ -356,6 +411,9 @@ function cmdInit() {
|
||||
}
|
||||
const db = new DatabaseSync(DB_PATH);
|
||||
db.exec(fs.readFileSync(SCHEMA_PATH, 'utf8'));
|
||||
if (!fs.existsSync(SETTINGS_PATH)) {
|
||||
fs.writeFileSync(SETTINGS_PATH, JSON.stringify({ records: false }, null, 2) + '\n');
|
||||
}
|
||||
console.log(`initialized run '${RUN}': ${rel(DB_PATH)}`);
|
||||
dumpDb(db);
|
||||
renderAll(db);
|
||||
@@ -401,7 +459,7 @@ function cmdDelete(idStr, reason) {
|
||||
const row = id && db.prepare('SELECT * FROM entries WHERE id = ?').get(id);
|
||||
if (!row) fail(`no such entry: ${idStr}`);
|
||||
db.prepare("UPDATE entries SET ring = 'cold' WHERE id = ?").run(id);
|
||||
journal(db, 'gm', 'delete', id, reason ?? 'GM edit');
|
||||
journal(db, 'gm', 'delete', `e${id}`, reason ?? 'GM edit');
|
||||
console.log(`[e${id}] **${row.label}** → cold storage`);
|
||||
renderAll(db);
|
||||
dumpDb(db);
|
||||
@@ -415,7 +473,7 @@ function cmdRevive(idStr, ring = 'b') {
|
||||
if (row.ring !== 'cold') fail(`[e${id}] is not in cold storage (ring ${row.ring})`);
|
||||
if (!RINGS.includes(ring)) fail(`target ring must be a|b`);
|
||||
db.prepare('UPDATE entries SET ring = ? WHERE id = ?').run(ring, id);
|
||||
journal(db, 'gm', 'revive', id, 'GM revive');
|
||||
journal(db, 'gm', 'revive', `e${id}`, 'GM revive');
|
||||
console.log(`[e${id}] **${row.label}** revived → ring ${ring.toUpperCase()}`);
|
||||
renderAll(db);
|
||||
dumpDb(db);
|
||||
@@ -438,9 +496,53 @@ function cmdRestore(force = false) {
|
||||
renderAll(db);
|
||||
}
|
||||
|
||||
function cmdRecord(kind, label, detail) {
|
||||
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 <kind> "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');
|
||||
console.log(`filed [r${rid}] [${norm(kind)}] **${norm(label)}**`);
|
||||
dumpDb(db);
|
||||
}
|
||||
|
||||
function cmdSearch(terms) {
|
||||
const db = openDb();
|
||||
if (!recordsEnabled()) fail('this character keeps no records — nothing to consult');
|
||||
if (!terms.length) fail('usage: search <terms...>');
|
||||
const conds = terms.map(() => "(label || ' ' || detail) LIKE ?").join(' AND ');
|
||||
const params = terms.map((t) => `%${t}%`);
|
||||
const rows = db.prepare(`SELECT * FROM records WHERE ${conds} ORDER BY id LIMIT 10`).all(...params);
|
||||
if (!rows.length) { console.log('(no records match)'); return; }
|
||||
for (const r of rows) console.log(`[r${r.id}] [${r.kind}] **${r.label}**${r.detail ? ` — ${r.detail}` : ''} (${r.created})`);
|
||||
const total = db.prepare(`SELECT COUNT(*) AS n FROM records WHERE ${conds}`).get(...params).n;
|
||||
if (total > rows.length) console.log(`…${total - rows.length} more omitted — narrow the query`);
|
||||
}
|
||||
|
||||
function cmdUnarchive(ridStr, ring = 'b') {
|
||||
const db = openDb();
|
||||
const rid = parseRid(ridStr);
|
||||
const row = rid && db.prepare('SELECT * FROM records WHERE id = ?').get(rid);
|
||||
if (!row) fail(`no such record: ${ridStr}`);
|
||||
if (!RINGS.includes(ring)) fail('target ring must be a|b');
|
||||
const type = TYPES.includes(row.kind) ? row.kind : 'fact';
|
||||
const res = db.prepare('INSERT INTO entries (ring, type, label, detail, created, last_touched) VALUES (?, ?, ?, ?, ?, ?)')
|
||||
.run(ring, type, row.label, row.detail, row.created, today());
|
||||
const eid = Number(res.lastInsertRowid);
|
||||
db.prepare('DELETE FROM records WHERE id = ?').run(rid);
|
||||
journal(db, 'gm', 'unarchive', `e${eid}`, 'GM unarchive');
|
||||
console.log(`[r${rid}] **${row.label}** → ring ${ring.toUpperCase()} as [e${eid}]`);
|
||||
renderAll(db);
|
||||
dumpDb(db);
|
||||
}
|
||||
|
||||
function cmdStatus() {
|
||||
const db = openDb();
|
||||
console.log(`run: ${RUN}`);
|
||||
console.log(`run: ${RUN}${recordsEnabled() ? '' : ' (no records)'}`);
|
||||
const nr = db.prepare('SELECT COUNT(*) AS n FROM records').get().n;
|
||||
console.log(`records: ${nr}`);
|
||||
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] ?? '∞';
|
||||
@@ -464,6 +566,9 @@ 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 '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 'record': (args.length >= 2) ? cmdRecord(args[0], args[1], args[2] ?? '') : fail('usage: record <kind> "Label" "detail"'); break;
|
||||
case 'search': cmdSearch(args); break;
|
||||
case 'unarchive': (args.length >= 1) ? cmdUnarchive(args[0], args[1]) : fail('usage: unarchive <rid> [a|b]'); break;
|
||||
case 'status': cmdStatus(); break;
|
||||
case 'dump': cmdDump(); break;
|
||||
case 'restore': cmdRestore(args[0] === '--force'); break;
|
||||
|
||||
Reference in New Issue
Block a user