the state-scan round: the log is the one truth for status and agenda, the db tiers retired -- scanState (server/session.mjs) derives each kind newest-wins across her emissions (the picked variant's text), the GM's override records, and the boundary state notes; the panes, the run detail, and the stamp all read it, GET /status and detail.status are derived reads, no clerk call, no db copy; the agenda cap is a derivation rule (GM, 2026-11-16: we log all seven items on reception, but the only way to see all seven is the raw event -- at no point an over-cap list can be derived), the reception note still shows the GM what sank; the stamp renders the canonical grammar -- status comma-separated, agenda markdown bullets, matching the line the GM added to invariants; the GM's block edits are overrides (GM, 2026-11-16: mutate during the contwin composition, the logs record the overrides arriving with the GM's turn as they should, the model sees the blocks overwritten with GM's edits attached to her turn, append if empty): the pane editors STAGE (paneEditor reworked -- no save callback, staged state, pending marker, discard), the send attaches them to POST /turn, node logs the override field on the GM turn, the composition renders it as hers -- the log never mutates, her words stay verbatim, the raw surfaces show the record; OOC turns refuse edits client and server both, the out-of-band POST /status and /agenda routes retired; stop writes the boundary state note at the carry head always (the crash-reconcile filters it before comparing), the start gate's n=1 seeding is dead (her authored opening turn IS the seed, the lint keeps requiring it), continuation carryovers are writable in the file editor during dormancy -- the review window's one editing surface, blocks included, no new pane; the clerk lost the tiers wholesale (schema tables, four verbs, canon status/agenda views, dump sections, report fields; the events CHECK keeps the historical op names; old dbs keep dead tables, never read, never dropped -- Irene is hands-off, and by the same day's ruling she is broken and never runs again: logs and db kept as they are, no replay, no continuation, no compatibility designed for her); Chloe hand-migrated to the new protocol -- her most recent turn carries the whole-list blocks applied from her db's exact values, her next context stamps them, her older lost/gained tags stay as history; the mock's agenda blocks went bullet, a new script position for the override turn's reply restates the mind so the boundary assert holds; smoke reworked to the scan battery (+ the 10f override block: the record rides its turn, the composition stamps at her canon point, the log keeps her emission verbatim, the OOC refusal, the boundary note at the carry head, the retired routes 404) -- ALL PASS; restart + reminder + repo checks green; the browser pass caught and fixed two real bugs (the pending marker's display:flex beat the hidden attribute -- any display rule needs a [hidden] override; setEditable(true) never ran the widget sync so the edit button stayed hidden) and proved the whole UX end to end with zero console errors -- staging, send-with-turn, the machinery lines on the table and raw, the OOC gate banner, discard, dormant read-only panes, the boundary note in the dormant preview; typecheck green on both programs; README/DICTIONARY carry the single-truth design, HANDOFF the round record and the Irene rewording, AGENTS the state pointer and the browser lessons
This commit is contained in:
+25
-179
@@ -23,7 +23,7 @@
|
||||
// all; pc never rides; --owner stamps)
|
||||
// init build session one of a fresh run
|
||||
// (the low-level primitive under create)
|
||||
// render write canon/ring-a.md, ring-b.md, status.md
|
||||
// render write canon/ring-a.md, ring-b.md
|
||||
// apply <manifest.json> apply a housekeeper manifest (validated, transactional)
|
||||
// reapply session-0's housekeeping: rebuild session
|
||||
// one's rings from its memory.json over a
|
||||
@@ -39,15 +39,6 @@
|
||||
// discard <rid> "reason" the PC discards a record (--gm likewise)
|
||||
// search <terms...> query the records (max 10; a miss is a miss)
|
||||
// unarchive <rid> [a|b] GM pulls a record back into the rings
|
||||
// status her status, as JSON (the status tier)
|
||||
// status-set "descr" ... whole-status replace -- the GM override
|
||||
// and the player's <status> block alike
|
||||
// (no descrs = clear it)
|
||||
// agenda the agenda, as JSON (the intentions tier)
|
||||
// agenda-set "item" ... whole-queue replace -- the GM override
|
||||
// and the player's <agenda> block alike;
|
||||
// over-cap evicts the bottom, silently
|
||||
// (no items = clear it)
|
||||
// pick "a" "b" "c" ... dice for prose -- uniform random choice
|
||||
// dump canonical dump to dumps/memory.sql
|
||||
// (also auto-written by every mutation)
|
||||
@@ -58,7 +49,11 @@
|
||||
// review window). State is per-deployment and per-session: every
|
||||
// session owns its db, canon views, dumps, and housekeeping logs.
|
||||
//
|
||||
// report counts, caps, the status, what's sinking
|
||||
// report counts, caps, what's sinking
|
||||
//
|
||||
// her status and agenda never lived here in the end: the log is the
|
||||
// one truth (the server's state scan reads her blocks); the clerk
|
||||
// keeps the rings and the records only.
|
||||
|
||||
/** @typedef {import('../server/shapes.mjs').Manifest} Manifest */
|
||||
/** @typedef {import('../server/shapes.mjs').InsertOp} InsertOp */
|
||||
@@ -72,10 +67,6 @@
|
||||
/** @typedef {{ id: number, ring: 'a'|'b'|'cold', type: 'place'|'person'|'fact'|'thread', label: string, detail: string, created: string, last_touched: string }} EntryRow */
|
||||
/** A records table row. */
|
||||
/** @typedef {{ id: number, kind: string, label: string, detail: string, created: string }} RecordRow */
|
||||
/** A status table row. */
|
||||
/** @typedef {{ id: number, descr: string, added: string }} StatusRow */
|
||||
/** An agenda table row. */
|
||||
/** @typedef {{ id: number, descr: string, added: string }} AgendaRow */
|
||||
/** An events table row: the append-only journal, never updated or deleted. */
|
||||
/** @typedef {{ id: number, session: string, op: string, target: string, reason: string, prior: string }} EventRow */
|
||||
|
||||
@@ -112,7 +103,6 @@ const RUNS_DIR = path.join(ROOT, 'runs');
|
||||
// dials -- retune freely
|
||||
/** @type {Record<string, number>} */
|
||||
const CAPS = { a: 500, b: 3000 };
|
||||
const AGENDA_CAP = 5; // dial -- retune freely (invariants.md: "intentionally tiny")
|
||||
const TYPES = ['place', 'person', 'fact', 'thread'];
|
||||
const RINGS = ['a', 'b']; // renderable; 'cold' is beyond the models
|
||||
|
||||
@@ -245,14 +235,13 @@ if (RUN != null && cmd !== 'init') setSessionRoot(resolveSession(sessionOverride
|
||||
|
||||
// the freeze ruling, enforced: which phases each mutating verb may
|
||||
// touch. Ring edits are the dormancy window (live is unnecessary and
|
||||
// dangerous, finished is frozen); the status and agenda are runtime
|
||||
// channels (live) and the dormancy edit surface; apply targets the
|
||||
// dormant session's rings -- the housekeeping write.
|
||||
// dangerous, finished is frozen); the records verbs are runtime
|
||||
// channels (live); apply targets the dormant session's rings -- the
|
||||
// housekeeping write.
|
||||
/** @type {Record<string, string[]>} */
|
||||
const PHASE_RULES = {
|
||||
insert: ['dormant'], delete: ['dormant'], revive: ['dormant'], unarchive: ['dormant'],
|
||||
apply: ['dormant'], reapply: ['dormant'],
|
||||
'status-set': ['dormant', 'live'], 'agenda-set': ['dormant', 'live'],
|
||||
file: ['dormant', 'live'], amend: ['dormant', 'live'], discard: ['dormant', 'live'],
|
||||
};
|
||||
/** @param {string} verb */
|
||||
@@ -408,44 +397,6 @@ function renderRing(db, ring) {
|
||||
return { file, count: rows.length };
|
||||
}
|
||||
|
||||
/** @param {DatabaseSync} db @returns {{ file: string, count: number }} */
|
||||
function renderStatus(db) {
|
||||
const rows = /** @type {StatusRow[]} */ (db.prepare('SELECT * FROM status ORDER BY id').all());
|
||||
const lines = [
|
||||
'# Status',
|
||||
'',
|
||||
'The status is the player\'s -- stances and feelings; facts live in the rings.',
|
||||
'',
|
||||
];
|
||||
if (!rows.length) lines.push('(a blank sheet -- fresh start)');
|
||||
for (const r of rows) lines.push(`- ${r.descr}`);
|
||||
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 };
|
||||
}
|
||||
|
||||
// the agenda view: the queue, top (newest) first, numbered as the wire
|
||||
// renders it -- what the model cites, what the GM reads
|
||||
/** @param {DatabaseSync} db @returns {{ file: string, count: number }} */
|
||||
function renderAgenda(db) {
|
||||
const items = agendaList(db);
|
||||
const lines = [
|
||||
'# Agenda -- what drives her',
|
||||
'',
|
||||
'The queue is the player\'s -- intentions, not facts; facts live in the rings.',
|
||||
'',
|
||||
];
|
||||
if (!items.length) lines.push('(a clear head -- nothing queued)');
|
||||
items.forEach((d, i) => lines.push(`- ${i}. ${d}`));
|
||||
lines.push('');
|
||||
const file = path.join(CANON_DIR, 'agenda.md');
|
||||
fs.mkdirSync(CANON_DIR, { recursive: true });
|
||||
fs.writeFileSync(file, lines.join('\n'));
|
||||
return { file, count: items.length };
|
||||
}
|
||||
|
||||
/** @param {DatabaseSync} db */
|
||||
function renderAll(db) {
|
||||
// --json means stdout carries JSON only; the view paths are human garnish
|
||||
@@ -454,10 +405,6 @@ function renderAll(db) {
|
||||
const { file, count } = renderRing(db, ring);
|
||||
if (talk) console.log(`${rel(file)} -- ${count} entries`);
|
||||
}
|
||||
const { file, count } = renderStatus(db);
|
||||
if (talk) console.log(`${rel(file)} -- ${count} descriptions`);
|
||||
const a = renderAgenda(db);
|
||||
if (talk) console.log(`${rel(a.file)} -- ${a.count} queued`);
|
||||
}
|
||||
|
||||
// canonical serialization: id-ordered, one row per line, restorable SQL.
|
||||
@@ -479,12 +426,6 @@ function dumpDb(db) {
|
||||
for (const r of /** @type {RecordRow[]} */ (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 /** @type {StatusRow[]} */ (db.prepare('SELECT * FROM status ORDER BY id').all())) {
|
||||
L.push(`INSERT INTO status VALUES (${r.id},${q(r.descr)},${q(r.added)});`);
|
||||
}
|
||||
for (const r of /** @type {AgendaRow[]} */ (db.prepare('SELECT * FROM agenda ORDER BY id').all())) {
|
||||
L.push(`INSERT INTO agenda VALUES (${r.id},${q(r.descr)},${q(r.added)});`);
|
||||
}
|
||||
for (const r of /** @type {EventRow[]} */ (db.prepare('SELECT * FROM events ORDER BY id').all())) {
|
||||
L.push(`INSERT INTO events VALUES (${r.id},${q(r.session)},${q(r.op)},${q(r.target)},${q(r.reason)},${q(r.prior)});`);
|
||||
}
|
||||
@@ -1176,8 +1117,10 @@ function cmdRestore(force = false) {
|
||||
// an old dump embeds its own old schema -- normalize before rendering:
|
||||
// the renames first (the schema exec's CREATE IF NOT EXISTS would
|
||||
// collide with a table awaiting rename), then the schema (creates
|
||||
// tables the dump predates, e.g. agenda). Old dumps self-heal
|
||||
// through the same path as openDb.
|
||||
// tables the dump predates). Old dumps self-heal through the same
|
||||
// path as openDb. An old dump's status/agenda tables restore as
|
||||
// dead residue (the tiers are retired): present on disk, never
|
||||
// read, never dropped.
|
||||
migrateStatusNames(db);
|
||||
db.exec(fs.readFileSync(SCHEMA_PATH, 'utf8'));
|
||||
console.log(`restored ${rel(DB_PATH)} from ${rel(dumpFile)}`);
|
||||
@@ -1225,108 +1168,20 @@ function cmdDiscard(ridStr, reason) {
|
||||
// can re-file it exactly (id included, so rid references stay valid)
|
||||
journal(db, AS_GM ? 'gm' : 'pc', 'discard', `r${rid}`, reason ?? 'discarded',
|
||||
JSON.stringify({ id: row.id, kind: row.kind, label: row.label, detail: row.detail, created: row.created }));
|
||||
console.log(`discarded [r${rid}] **${row.label}**`);
|
||||
console.log(`discarded [r${row.id}] **${row.label}**`);
|
||||
dumpDb(db);
|
||||
}
|
||||
|
||||
// --- her status (the status tier) -------------------------------------------------
|
||||
// --- her status and agenda: RETIRED (GM, 2026-11-16) -------------------------------
|
||||
//
|
||||
// Freeform descriptions, no keys, no baselines. The player mutates via
|
||||
// <lost>/<gained> deltas in its own turns -- exact match, non-blocking,
|
||||
// misses relayed back to the model as a <conflict> block by the caller.
|
||||
// The GM overrides out-of-band with status-set. Descriptions never contain
|
||||
// commas: both the delta lists and the <status> block are comma-separated.
|
||||
|
||||
/** @param {DatabaseSync} db @returns {string[]} */
|
||||
const statusList = (db) => /** @type {{ descr: string }[]} */ (db.prepare('SELECT descr FROM status ORDER BY id').all()).map((r) => r.descr);
|
||||
|
||||
function cmdStatus() {
|
||||
console.log(JSON.stringify(statusList(openDb())));
|
||||
}
|
||||
|
||||
// whole-status replace (GM override and the player's <status> block --
|
||||
// the full-block protocol); the journal keeps
|
||||
// the full prior status so turn surgery can compensate mechanically
|
||||
/** @param {DatabaseSync} db @param {string[]} items @param {string} reason @param {string} win @returns {string[]} */
|
||||
function setStatus(db, items, reason, win) {
|
||||
const clean = [...new Set(items.map((s) => String(s ?? '').trim()))].filter(Boolean);
|
||||
const prior = statusList(db);
|
||||
db.exec('BEGIN');
|
||||
try {
|
||||
db.prepare('DELETE FROM status').run();
|
||||
for (const d of clean) {
|
||||
db.prepare('INSERT INTO status (descr, added) VALUES (?, ?)').run(d, today());
|
||||
}
|
||||
journal(db, win, 'status-set', 'p', reason, JSON.stringify(prior));
|
||||
db.exec('COMMIT');
|
||||
} catch (e) {
|
||||
db.exec('ROLLBACK');
|
||||
fail(`status-set failed, rolled back: ${e.message}`);
|
||||
}
|
||||
return clean;
|
||||
}
|
||||
|
||||
/** @param {string[]} items */
|
||||
function cmdStatusSet(items) {
|
||||
const db = openDb();
|
||||
const clean = setStatus(db, items, AS_GM ? 'GM override' : 'status set', AS_GM ? 'gm' : 'pc');
|
||||
console.log(JSON.stringify(clean));
|
||||
renderAll(db);
|
||||
dumpDb(db);
|
||||
}
|
||||
|
||||
// --- the agenda (intentions tier) ---------------------------------------------
|
||||
//
|
||||
// The hot queue of what drives her: goals she is working towards right
|
||||
// now -- intentions, never states (those are the status's). Fixed cap
|
||||
// (a dial); id order IS queue order -- the first item is the top, a
|
||||
// whole-list set lands in written order, over-cap evicts the bottom,
|
||||
// a recency ring buffer for free. The player mutates by restating the
|
||||
// whole <agenda> block in its own turns (the full-block protocol,
|
||||
// 2026-11-16); the GM overrides whole-list with agenda-set.
|
||||
|
||||
/** @param {DatabaseSync} db @returns {string[]} */
|
||||
const agendaList = (db) => /** @type {{ descr: string }[]} */ (db.prepare('SELECT descr FROM agenda ORDER BY id DESC').all()).map((r) => r.descr);
|
||||
|
||||
function cmdAgenda() {
|
||||
console.log(JSON.stringify(agendaList(openDb())));
|
||||
}
|
||||
|
||||
// whole-list replace (GM override and the player's <agenda> block --
|
||||
// the full-block protocol); the journal keeps the prior queue so turn
|
||||
// surgery can compensate mechanically (the saga rule). Over-cap lists
|
||||
// evict from the bottom silently -- ruled a feature (GM, 2026-11-16):
|
||||
// immersive, human-like, fun chaos. Silent to her; the caller surfaces
|
||||
// the evicted to the GM.
|
||||
/** @param {DatabaseSync} db @param {string[]} items @param {string} reason @param {string} win @returns {{ set: string[], evicted: string[] }} */
|
||||
function setAgenda(db, items, reason, win) {
|
||||
const clean = [...new Set(items.map((s) => String(s ?? '').trim()))].filter(Boolean);
|
||||
const set = clean.slice(0, AGENDA_CAP);
|
||||
const evicted = clean.slice(AGENDA_CAP);
|
||||
const prior = agendaList(db);
|
||||
db.exec('BEGIN');
|
||||
try {
|
||||
db.prepare('DELETE FROM agenda').run();
|
||||
for (const d of [...set].reverse()) { // first item = the top of the queue
|
||||
db.prepare('INSERT INTO agenda (descr, added) VALUES (?, ?)').run(d, today());
|
||||
}
|
||||
journal(db, win, 'agenda-set', 'agenda', reason, JSON.stringify(prior));
|
||||
db.exec('COMMIT');
|
||||
} catch (e) {
|
||||
db.exec('ROLLBACK');
|
||||
fail(`agenda-set failed, rolled back: ${e.message}`);
|
||||
}
|
||||
return { set, evicted };
|
||||
}
|
||||
|
||||
/** @param {string[]} items */
|
||||
function cmdAgendaSet(items) {
|
||||
const db = openDb();
|
||||
const r = setAgenda(db, items, AS_GM ? 'GM override' : 'agenda set', AS_GM ? 'gm' : 'pc');
|
||||
console.log(JSON.stringify(r));
|
||||
renderAll(db);
|
||||
dumpDb(db);
|
||||
}
|
||||
// The full-block protocol made her logged blocks the model's only
|
||||
// channel, and a second home in the db was a stale mirror, not a
|
||||
// truth -- the panes and the stamp read the server's state scan of
|
||||
// the log now (server/session.mjs: scanState). The verbs, the
|
||||
// tables, and the canon views are gone; old runs keep their dead
|
||||
// tables on disk, never read, never dropped (Irene is hands-off).
|
||||
// The events journal keeps the historical status-*/agenda-* rows and
|
||||
// the CHECK constraint still names their ops.
|
||||
|
||||
/** @param {string[]} options */
|
||||
function cmdPick(options) {
|
||||
@@ -1370,13 +1225,11 @@ function cmdUnarchive(ridStr, ring = 'b') {
|
||||
function cmdReport() {
|
||||
const db = openDb();
|
||||
if (AS_JSON) {
|
||||
/** @type {{ run: ?string, records: number, recordsEnabled: boolean, status: string[], agenda: string[], events: number, rings: Record<string, number>, sinking: Record<string, { id: number, last_touched: string, label: string }[]> }} */
|
||||
/** @type {{ run: ?string, records: number, recordsEnabled: boolean, events: number, rings: Record<string, number>, sinking: Record<string, { id: number, last_touched: string, label: string }[]> }} */
|
||||
const out = {
|
||||
run: RUN,
|
||||
records: Number(db.prepare('SELECT COUNT(*) AS n FROM records').get()?.n ?? 0),
|
||||
recordsEnabled: recordsEnabled(),
|
||||
status: statusList(db),
|
||||
agenda: agendaList(db),
|
||||
events: Number(db.prepare('SELECT COUNT(*) AS n FROM events').get()?.n ?? 0),
|
||||
rings: {},
|
||||
sinking: {},
|
||||
@@ -1395,9 +1248,6 @@ function cmdReport() {
|
||||
console.log(`run: ${RUN}${recordsEnabled() ? '' : ' (no records)'}`);
|
||||
const nr = Number(db.prepare('SELECT COUNT(*) AS n FROM records').get()?.n ?? 0);
|
||||
console.log(`records: ${nr}`);
|
||||
const status = statusList(db);
|
||||
console.log(`status: ${status.length ? '' : '(a blank sheet)'}`);
|
||||
for (const d of status) console.log(` - ${d}`);
|
||||
for (const ring of ['a', 'b', 'cold']) {
|
||||
const n = Number(db.prepare('SELECT COUNT(*) AS n FROM entries WHERE ring = ?').get(ring)?.n ?? 0);
|
||||
const cap = CAPS[ring] ?? 'none';
|
||||
@@ -1432,10 +1282,6 @@ switch (cmd) {
|
||||
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 'status': cmdStatus(); break;
|
||||
case 'status-set': cmdStatusSet(args); break; // no args = clear the status (a deliberate clear -- the player's empty block or a GM override)
|
||||
case 'agenda': cmdAgenda(); break;
|
||||
case 'agenda-set': cmdAgendaSet(args); break; // no args = clear the agenda
|
||||
case 'pick': cmdPick(args); break;
|
||||
case 'search': cmdSearch(args); break;
|
||||
case 'unarchive': (args.length >= 1) ? cmdUnarchive(args[0], args[1]) : fail('usage: unarchive <rid> [a|b]'); break;
|
||||
@@ -1443,6 +1289,6 @@ switch (cmd) {
|
||||
case 'dump': cmdDump(); break;
|
||||
case 'restore': cmdRestore(FORCE); break;
|
||||
default:
|
||||
console.error('usage: node tool/memory.mjs <packages|runs|create|save-package|init|render|apply|reapply|insert|delete|revive|file|amend|discard|search|unarchive|status|status-set|agenda|agenda-set|pick|dump|restore|report>');
|
||||
console.error('usage: node tool/memory.mjs <packages|runs|create|save-package|init|render|apply|reapply|insert|delete|revive|file|amend|discard|search|unarchive|pick|dump|restore|report>');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user