spa modules and terminology: app.mjs split into flat es modules (router lifecycle, shared widgets, views own their state), mock smoke in test/; DICTIONARY.md rules the terms, four renames swept clean through the machinery - paper->status (run summary command is report now), window->session, wrap->housekeeping, context window->contwin; no dual-accepts by ruling, old data migrates once in the clerk (restore self-heals old dumps)

This commit is contained in:
2026-11-14 23:48:27 +00:00
parent 89a2c161b3
commit c51d31078e
36 changed files with 2643 additions and 1779 deletions
+11 -11
View File
@@ -1,4 +1,4 @@
// server/session.mjs — a window's live state.
// server/session.mjs — a session's live state.
//
// The append-only jsonl is the truth; the in-memory context is a view
// rebuilt from it on boot. Entries are typed (bundle / msg / tool /
@@ -6,7 +6,7 @@
// without a format migration. The view renderer is pure policy over
// the log: thinking never goes back, old tool results elide to stubs
// (the last few and every ask_gm answer stay), old GM-side
// <status>/<conflict> blocks elide — the current paper rides the
// <status>/<conflict> blocks elide — the current status rides the
// newest GM turn.
import fs from 'node:fs';
import path from 'node:path';
@@ -62,16 +62,16 @@ function makeSession(runId, st) {
};
}
// --- open a window -----------------------------------------------------------
// --- open a session -----------------------------------------------------------
// The #21 guard: opening over an unhousekept session means that
// transcript never reaches the rings — refuse and name it, unless the
// caller explicitly overrides (the deliberate skip).
export function openWindow(runId, override = false) {
export function openSession(runId, override = false) {
requireRun(runId);
const latest = latestSession(runId);
if (latest && latest !== (readState(runId).lastHousekeptSession ?? null) && !override) {
const err = new Error(`the previous window (${latest}) was never housekept — its transcript would never reach the rings`);
const err = new Error(`the previous session (${latest}) was never housekept — its transcript would never reach the rings`);
err.status = 409;
err.detail = { session: latest, hint: 'housekeep it first, or POST with {"override": true} to deliberately skip it' };
throw err;
@@ -80,7 +80,7 @@ export function openWindow(runId, override = false) {
const notes = [];
const fresh = latest === null;
if (fresh) {
// lazy seed: applies at the first window-open, before render and
// lazy seed: applies at the first session-open, before render and
// assembly, so the bundle sees populated rings. The clerk refuses
// on history (a hand-prepped run), which is the opt-out.
if (fs.existsSync(path.join(runDir(runId), 'seed.json'))) {
@@ -88,7 +88,7 @@ export function openWindow(runId, override = false) {
notes.push({ kind: 'seed', ok: r.code === 0, detail: (r.code === 0 ? r.out : r.err).split('\n')[0] });
}
if (fs.existsSync(path.join(runDir(runId), 'turn-0.md'))) {
const r = clerkTry(runId, 'paper-ingest', path.join(runDir(runId), 'turn-0.md'));
const r = clerkTry(runId, 'status-ingest', path.join(runDir(runId), 'turn-0.md'));
notes.push({ kind: 'ingest', ok: r.code === 0, detail: (r.code === 0 ? r.out : r.err).split('\n')[0] });
}
}
@@ -107,7 +107,7 @@ export function openWindow(runId, override = false) {
const s = makeSession(runId, stamp());
s.fresh = fresh;
fs.mkdirSync(sessionsDir(runId), { recursive: true });
s.append({ t: 'note', kind: 'window', at: s.stamp, fresh });
s.append({ t: 'note', kind: 'session', at: s.stamp, fresh });
for (const n of notes) s.append({ t: 'note', kind: n.kind, ok: n.ok, detail: n.detail });
s.append({ t: 'bundle', m: system, part: 'system' });
for (let i = 0; i < bundle.length; i++) s.append({ t: 'bundle', m: bundle[i], part: partNames[i] });
@@ -132,7 +132,7 @@ export function loadSession(runId, st) {
}
}
derive(s);
// fresh survives a restart: this window is the run's first iff no
// fresh survives a restart: this session is the run's first iff no
// earlier session log exists (derive() can't know — it sees one log)
const files = fs.readdirSync(sessionsDir(runId)).filter((f) => f.endsWith('.jsonl')).sort();
s.fresh = files.length === 1 && files[0] === `${st}.jsonl`;
@@ -182,7 +182,7 @@ export function renderView(s, keepToolResults = 4) {
if (e.reminder) {
// the per-turn reminder: only the newest copy lives in the
// context — superseded ones elide (identical content, freshest
// position, exactly like the papers)
// position, exactly like the status/agenda blocks)
if (i === newestReminder) msgs.push({ role: 'system', content: e.m.content.trim() });
} else if (e.m.role === 'assistant') {
// thinking never goes back; the log keeps it
@@ -196,7 +196,7 @@ export function renderView(s, keepToolResults = 4) {
if (i === lastGmIdx) msgs.push({ role: e.m.role, content: e.m.content.trim() });
} else if (i === lastGmIdx) {
// the newest GM turn keeps its blocks as-sent: the current
// paper and agenda ride it
// status and agenda ride it
msgs.push({ role: e.m.role, content: e.m.content.trim() });
} else {
// older GM turns: status/agenda/conflict blocks elide