substrate: server, housekeeping job, spa - the mvp complete
- prompt split, GM's cut: system.md = opening + guards (glossary, purpose, input validation; repo-fed, per-project); invariants.md = substrate (syntax markers, tools, memory, records, the paper + its three-part gate; repo-fed, travels with the code); handbook.md = craft copy (shape of play, thoughts, purview, time skips, continuity, stance, hard limits; copied per run). One system message: system -> invariants -> the run's handbook. OOC is a single open paren, closing optional, match the GM's style; a lone paren is an empty OOC line, skipped by the parser. housekeeper.md aligned: the paper holds acute states, relational shifts are recorded as the facts behind them, and dates are story dates (follow the rings' calendar, never the wall clock - the seed is 2069 now, per canon) - server/ (phase 2, zero-dep node:http): REST spine per the sketch, per-run session machine with ask_gm pause/resume (the whole tool-call batch waits, pairing stays sound), view renderer (thinking-strip, tool-result elision with ask answers exempt, old status/conflict blocks stripped), boot-rebuild from the typed jsonl, lazy seed + turn-0 ingestion at window-open with the unhousekept refuse-and-override guard, usage tracking + context meter, tool-pairing validation, scripted mock model. The clerk gained --json (packages/runs/status); tool/bridge.mjs deleted at mock-parity per the retirement decision - housekeeping job (phase 3, server/housekeeping.mjs): trigger ends the window and runs the chain async - transcript with labeled thinking, run-state injection (records availability; the ring views stay pure memory), housekeeper on a fresh context, manifest saved (raw output too if unparseable), clerk apply (writes the window log, snapshots dumps/<window>.sql), state.json lastHousekeptSession, autorestart. Rejection holds the restart and surfaces why; the apply endpoint is the recovery path and the manual-relay close. Live-proven twice: both manifests sound (ring-B classification, first-person voice, precise touches, story-dated) - spa (phase 4, web/ - no build, vanilla es modules, served at /): three-register transcript per the ruled markers incl. multi-line narration blocks, bundle as a collapsed card with turn-0 as the opening GM turn, paper tags as chips, status pane with conflict surfacing, context meter hot past 85 percent, gm line input, ask modal re-presented from pendingAsk, housekeeping button with two-click arm + poll + inline log. No js alert/confirm (they block the embedded pane) - in-page banner instead. Driven end to end through the ui on a disposable live run - seed: date fixed to the 2069 story calendar (was a real-world date; real dates never surface to the player) - docs: README goal states the mvp is complete, layout covers server/ and web/, protocol and substrate sections rewritten for the server; ROADMAP phases 0-4 done, harness decisions current; QUESTIONS #4 #7 #10 #12 #16-mechanism #19a #20 #21 resolved; HANDOFF is the handoff map; AGENTS carries the working lessons (tokens are free, no screenshots - not multimodal, no js dialogs, external state survives rewinds)
This commit is contained in:
+72
-29
@@ -77,6 +77,8 @@ const AS_GM = argv.includes('--gm');
|
||||
for (let i = argv.indexOf('--gm'); i !== -1; i = argv.indexOf('--gm')) argv.splice(i, 1);
|
||||
const QUIET = argv.includes('--quiet');
|
||||
for (let i = argv.indexOf('--quiet'); i !== -1; i = argv.indexOf('--quiet')) argv.splice(i, 1);
|
||||
const AS_JSON = argv.includes('--json');
|
||||
for (let i = argv.indexOf('--json'); i !== -1; i = argv.indexOf('--json')) argv.splice(i, 1);
|
||||
const [cmd, ...args] = argv;
|
||||
|
||||
// a run is an instance under runs/, created from a package by `create`;
|
||||
@@ -100,22 +102,19 @@ function setRunRoot(dir) {
|
||||
}
|
||||
setRunRoot(path.join(RUNS_DIR, RUN ?? ''));
|
||||
|
||||
const BACKDROP_TEMPLATE = `<!-- The world as everyone in it knows it: public knowledge, general backdrop.
|
||||
Immutable for play purposes — never memory, never forgotten, never
|
||||
enters the rings. The GM may edit (retcons); git versions it. -->
|
||||
|
||||
# Backdrop
|
||||
const BACKDROP_TEMPLATE = `# Backdrop
|
||||
|
||||
(One to three paragraphs: what any inhabitant of this world knows — the
|
||||
place, the era, how things work here. Common knowledge, not what any
|
||||
particular character learned.)
|
||||
particular character learned. Never memory, never forgotten: it never
|
||||
touches the rings and is always in the bundle.)
|
||||
`;
|
||||
|
||||
const CARD_TEMPLATE = `# <name>
|
||||
|
||||
<!-- GM: fill this in before window one. Five lines is plenty; freeform beats
|
||||
complete. Delete comments as you go. Blank fields are the player's to
|
||||
invent through play — the GM ratifies notable inventions afterward. -->
|
||||
(Fill this in before window one. Five lines is plenty; freeform beats
|
||||
complete. Blank fields are the player's to invent through play — the
|
||||
GM ratifies notable inventions afterward.)
|
||||
|
||||
- **Concept:** one line
|
||||
- **Drives:** what they want, generally
|
||||
@@ -160,17 +159,16 @@ const journal = (db, win, op, target, reason, prior = '') =>
|
||||
db.prepare('INSERT INTO events (window, op, target, reason, prior) VALUES (?, ?, ?, ?, ?)')
|
||||
.run(win, op, target, norm(reason), prior);
|
||||
|
||||
// generated views: the ring and status files are machine-written — never
|
||||
// hand-edit them (regenerate with render). The do-not-edit warning lives
|
||||
// here rather than in the output: prose files carry no comments, purpose
|
||||
// text lives in code or README.
|
||||
function renderRing(db, ring) {
|
||||
const rows = db.prepare(
|
||||
'SELECT * FROM entries WHERE ring = ? ORDER BY last_touched DESC, id DESC'
|
||||
).all(ring);
|
||||
const title = ring === 'a' ? 'what matters' : 'what stuck anyway';
|
||||
const lines = [
|
||||
'<!-- 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}`,
|
||||
'',
|
||||
];
|
||||
@@ -188,15 +186,10 @@ function renderRing(db, ring) {
|
||||
function renderStatus(db) {
|
||||
const rows = db.prepare('SELECT * FROM paper ORDER BY id').all();
|
||||
const lines = [
|
||||
'<!-- GENERATED by tool/memory.mjs render — do not edit by hand. -->',
|
||||
"<!-- Her piece of paper: descriptions of her immediate situation (the status tier). -->",
|
||||
'<!-- The player mutates it with <lost>/<gained> deltas in its turns; the GM overrides -->',
|
||||
'<!-- out-of-band. Inspection view only: the paper rides every GM turn as a <status> -->',
|
||||
'<!-- block (re-read per turn), never in the opening bundle. Stances are feelings; -->',
|
||||
'<!-- facts live in the rings. -->',
|
||||
'',
|
||||
'# Status — her paper',
|
||||
'',
|
||||
'The paper 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}`);
|
||||
@@ -518,6 +511,12 @@ function cmdApply(manifestPath) {
|
||||
|
||||
fs.mkdirSync(LOG_DIR, { recursive: true });
|
||||
fs.writeFileSync(logFile, renderLog(mf, applied, overflow));
|
||||
const dumpFile = dumpDb(db);
|
||||
// per-wrap snapshot: the committed-truth successor now that runs are
|
||||
// gitignored — diffing consecutive snapshots reconstructs the window's
|
||||
// operations for async review
|
||||
const snapshot = path.join(DUMPS_DIR, `${mf.window}.sql`);
|
||||
fs.copyFileSync(dumpFile, snapshot);
|
||||
console.log(`applied [${RUN}] ${mf.window}: ` + [
|
||||
applied.insert.length && `${applied.insert.length} inserted`,
|
||||
applied.touch.length && `${applied.touch.length} touched`,
|
||||
@@ -530,7 +529,7 @@ function cmdApply(manifestPath) {
|
||||
].filter(Boolean).join(', '));
|
||||
console.log(`log: ${rel(logFile)}`);
|
||||
renderAll(db);
|
||||
console.log(`dump: ${rel(dumpDb(db))}`);
|
||||
console.log(`dump: ${rel(dumpFile)} | snapshot: ${rel(snapshot)}`);
|
||||
}
|
||||
|
||||
// --- simple commands ---------------------------------------------------------
|
||||
@@ -559,17 +558,29 @@ function cmdInit() {
|
||||
// truth. run.json records the lineage and an optional model override.
|
||||
|
||||
const PACKAGE_FILES = ['backdrop.md', 'turn-0.md', 'character.md', 'seed.json', 'settings.json', 'gm.md'];
|
||||
const SHARED_PROMPTS = ['system.md', 'housekeeper.md'];
|
||||
// battery included, copied per run and then the run's to edit: the craft
|
||||
// tier and the housekeeping prompt. system.md and invariants.md are
|
||||
// repo-fed at assembly (opening+guards, substrate facts) — never copied
|
||||
const SHARED_PROMPTS = ['handbook.md', 'housekeeper.md'];
|
||||
|
||||
function cmdPackages() {
|
||||
if (!fs.existsSync(PACKAGES_DIR)) { console.log('(no packages)'); return; }
|
||||
if (!fs.existsSync(PACKAGES_DIR)) { if (AS_JSON) console.log('[]'); else console.log('(no packages)'); return; }
|
||||
const list = [];
|
||||
for (const d of fs.readdirSync(PACKAGES_DIR, { withFileTypes: true })) {
|
||||
if (!d.isDirectory()) continue;
|
||||
const p = path.join(PACKAGES_DIR, d.name);
|
||||
const has = (f) => fs.existsSync(path.join(p, f));
|
||||
let records = false;
|
||||
try { records = JSON.parse(fs.readFileSync(path.join(p, 'settings.json'), 'utf8')).records === true; } catch {}
|
||||
console.log(`${d.name}: records ${records ? 'on' : 'off'} · turn-0 ${has('turn-0.md') ? 'yes' : 'no'} · seed ${has('seed.json') ? 'yes' : 'no'} · backdrop+card ${has('backdrop.md') && has('character.md') ? 'ok' : 'MISSING'}`);
|
||||
list.push({
|
||||
name: d.name, records,
|
||||
turn0: has('turn-0.md'), seed: has('seed.json'),
|
||||
complete: has('backdrop.md') && has('character.md'),
|
||||
});
|
||||
}
|
||||
if (AS_JSON) { console.log(JSON.stringify(list)); return; }
|
||||
for (const x of list) {
|
||||
console.log(`${x.name}: records ${x.records ? 'on' : 'off'} · turn-0 ${x.turn0 ? 'yes' : 'no'} · seed ${x.seed ? 'yes' : 'no'} · backdrop+card ${x.complete ? 'ok' : 'MISSING'}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -608,7 +619,8 @@ function cmdCreate(pkgName, runId, model) {
|
||||
}
|
||||
|
||||
function cmdRuns() {
|
||||
if (!fs.existsSync(RUNS_DIR)) { console.log('(no runs — create one: create <package> <run-id>)'); return; }
|
||||
if (!fs.existsSync(RUNS_DIR)) { if (AS_JSON) console.log('[]'); else console.log('(no runs — create one: create <package> <run-id>)'); return; }
|
||||
const list = [];
|
||||
let found = 0;
|
||||
for (const d of fs.readdirSync(RUNS_DIR, { withFileTypes: true })) {
|
||||
if (!d.isDirectory()) continue;
|
||||
@@ -616,13 +628,23 @@ function cmdRuns() {
|
||||
if (!fs.existsSync(path.join(runDir, 'run.json'))) continue; // a run is marked by run.json
|
||||
found++;
|
||||
let pkg = '?';
|
||||
try { pkg = JSON.parse(fs.readFileSync(path.join(runDir, 'run.json'), 'utf8')).package ?? '?'; } catch {}
|
||||
let model = null;
|
||||
try {
|
||||
const meta = JSON.parse(fs.readFileSync(path.join(runDir, 'run.json'), 'utf8'));
|
||||
pkg = meta.package ?? '?';
|
||||
model = meta.model ?? null;
|
||||
} catch {}
|
||||
const dbPath = path.join(runDir, 'db', 'memory.db');
|
||||
if (!fs.existsSync(dbPath)) { console.log(`${d.name} [${pkg}]: (not initialized)`); continue; }
|
||||
if (!fs.existsSync(dbPath)) { list.push({ id: d.name, package: pkg, model, initialized: false }); continue; }
|
||||
const db = new DatabaseSync(dbPath);
|
||||
db.exec(fs.readFileSync(SCHEMA_PATH, 'utf8'));
|
||||
const n = (ring) => db.prepare('SELECT COUNT(*) AS n FROM entries WHERE ring = ?').get(ring).n;
|
||||
console.log(`${d.name} [${pkg}]: a ${n('a')}/${CAPS.a} · b ${n('b')}/${CAPS.b} · cold ${n('cold')}`);
|
||||
list.push({ id: d.name, package: pkg, model, initialized: true, fill: { a: n('a'), b: n('b'), cold: n('cold') } });
|
||||
}
|
||||
if (AS_JSON) { console.log(JSON.stringify(list)); return; }
|
||||
for (const x of list) {
|
||||
if (!x.initialized) { console.log(`${x.id} [${x.package}]: (not initialized)`); continue; }
|
||||
console.log(`${x.id} [${x.package}]: a ${x.fill.a}/${CAPS.a} · b ${x.fill.b}/${CAPS.b} · cold ${x.fill.cold}`);
|
||||
}
|
||||
if (!found) console.log('(no runs — create one: create <package> <run-id>)');
|
||||
}
|
||||
@@ -873,6 +895,27 @@ function cmdUnarchive(ridStr, ring = 'b') {
|
||||
|
||||
function cmdStatus() {
|
||||
const db = openDb();
|
||||
if (AS_JSON) {
|
||||
const out = {
|
||||
run: RUN,
|
||||
records: db.prepare('SELECT COUNT(*) AS n FROM records').get().n,
|
||||
recordsEnabled: recordsEnabled(),
|
||||
paper: paperList(db),
|
||||
events: db.prepare('SELECT COUNT(*) AS n FROM events').get().n,
|
||||
rings: {},
|
||||
sinking: {},
|
||||
};
|
||||
for (const ring of ['a', 'b', 'cold']) {
|
||||
out.rings[ring] = db.prepare('SELECT COUNT(*) AS n FROM entries WHERE ring = ?').get(ring).n;
|
||||
if (ring !== 'cold') {
|
||||
out.sinking[ring] = db.prepare(
|
||||
'SELECT id, last_touched, label FROM entries WHERE ring = ? ORDER BY last_touched ASC, id ASC LIMIT 5'
|
||||
).all(ring);
|
||||
}
|
||||
}
|
||||
console.log(JSON.stringify(out));
|
||||
return;
|
||||
}
|
||||
console.log(`run: ${RUN}${recordsEnabled() ? '' : ' (no records)'}`);
|
||||
const nr = db.prepare('SELECT COUNT(*) AS n FROM records').get().n;
|
||||
console.log(`records: ${nr}`);
|
||||
|
||||
Reference in New Issue
Block a user