variant round: roll retired, chance is variant literature (strict parse, crypto pick on reception, picked-only rendering, /story variance metric); entity round: /story the whole deliverable, /table the play projection, the slidwin carry (smart contwin cutoff, whole exchanges, housekeeper reads session-minus-tail); dormant-session rework: universal session lifecycle (dormant->live->finished, sessions/<n> storage), move-at-stop, start lint + auto-send rule, rebaseable housekeeping, turn-0 -> carryover.jsonl, seed -> memory.json, draft-only save-package; format house rules enforced by the nine-rule check-repo (ascii bytes, no text-mutating css); smoke 105/105 + restart + reminder + browser pass green, irene hand-migrated to the new layout

This commit is contained in:
2026-11-15 14:35:00 +00:00
parent c51d31078e
commit fa3f23b474
51 changed files with 3477 additions and 1719 deletions
+106 -78
View File
@@ -1,5 +1,5 @@
// web/view-play.mjs — the play surface: the transcript, her two
// blocks (the status pane and the agenda pane — one widget, two
// web/view-play.mjs -- the play surface: the transcript, her two
// blocks (the status pane and the agenda pane -- one widget, two
// instances), the GM notepad, housekeeping (close session, the
// dry-run replay), fork, and the input line.
@@ -19,7 +19,7 @@ const statusPane = paneEditor({
section: 'status-pane',
body: 'status',
empty: 'a blank sheet',
placeholder: 'one description per line — empty clears the status',
placeholder: 'one description per line -- empty clears the status',
rows: 5,
format: (items) => items.join(', '), // compact, mirroring the <status> wire format
toText: (items) => items.join('\n'),
@@ -32,10 +32,11 @@ const agendaPane = paneEditor({
section: 'agenda-pane',
body: 'agenda',
empty: 'a clear head',
placeholder: 'one item per line, top first — empty clears the agenda',
placeholder: 'one item per line, top first -- empty clears the agenda',
rows: 4,
// the queue numbered from the top, exactly as the model cites it
format: (items) => items.map((d, i) => `${i}. ${d}`).join('; '),
// the pane renders bullets; the wire keeps the numbered form the
// model cites (drops reference the indexes it was shown)
format: (items) => items.map((d) => `- ${d}`).join('\n'),
toText: (items) => items.join('\n'),
fromText: (text) => text
.split('\n').flatMap((l) => l.replace(/^\s*[-*]\s+\d*[.:)]?\s*/, '').split(','))
@@ -69,55 +70,65 @@ async function refreshPlay(id, seq) {
detail = await api(`/runs/${id}`);
} catch (e) {
if (e.status === 404) return runGone(id, location.pathname);
return banner(`could not reach the server: ${e.message}`); // stay put — transient
return banner(`could not reach the server: ${e.message}`); // stay put -- transient
}
if (seq !== state.seq) return;
const mine = state.me && detail.run.owner === state.me.id;
if (detail.draft) {
if (mine) return navigate(`/runs/${id}/setup`);
// someone else's unstarted run: nothing to read but its existence
setSessionInfo(`${detail.display} — a draft, not yours`);
setSessionInfo(`${detail.display} -- a draft, not yours`);
$('transcript').textContent = '';
$('transcript').appendChild(el('div', 'hint', 'this run is still a draft — fork it to make it yours and edit it'));
$('transcript').appendChild(el('div', 'hint', 'this run is still a draft -- fork it to make it yours and edit it'));
return;
}
setSessionInfo((detail.open
? `${detail.display} — session ${detail.session}${detail.fresh ? ' — fresh' : ''}${detail.pendingAsk ? ' — waiting for your answer' : ''}`
: `${detail.display} — no open session`)
+ (mine ? '' : detail.run.owner == null ? ' — ownerless' : ' — spectating'));
setSessionInfo((detail.phase === 'live'
? `${detail.display} -- session ${detail.session}${detail.pendingAsk ? ' -- waiting for your answer' : ''}`
: `${detail.display} -- session ${detail.sessions} dormant`)
+ (mine ? '' : detail.run.owner == null ? ' -- ownerless' : ' -- spectating'));
renderMeter(detail);
statusPane.set(detail.status);
agendaPane.set(detail.agenda);
$('conflict').hidden = true;
// spectator mode: read everything, mutate nothing — the fork is the
// spectator mode: read everything, mutate nothing -- the fork is the
// way in. Ownerless runs are spectators for everyone alike.
statusPane.setEditable(mine);
agendaPane.setEditable(mine);
$('gm-notes').readOnly = !mine;
let beatNeeded = false;
if (detail.open) {
const session = await api(`/runs/${id}/session`);
if (detail.phase === 'live') {
// the table: the live session's projection -- thinking never
// crosses the wire, variant turns carry only the picked one (the
// raw /session is the audit surface, one fetch away)
const session = await api(`/runs/${id}/table`);
if (seq !== state.seq) return;
renderTranscript(session.entries, { onConflict: showConflict });
beatNeeded = mine && detail.fresh && !session.entries.some((e) => e.t === 'msg' && e.m.role === 'user');
} else if (detail.phase === 'dormant') {
// the review window: the carryover is the preview of the next
// contwin's opening, rendered exactly as the table will hold it
const carry = await api(`/runs/${id}/carryover`).catch(() => null);
if (seq !== state.seq) return;
$('transcript').textContent = '';
if (carry && carry.entries.length) renderTranscript(carry.entries, {});
else $('transcript').appendChild(el('div', 'hint', 'nothing carries -- the next session opens on the bundle alone'));
if (mine) $('transcript').prepend(dormantBar(detail, carry));
} else {
$('transcript').textContent = '';
}
// the opening beat, if start was interrupted or the session was opened directly
if (beatNeeded) await offerBeat(id, seq);
// controls
$('session-open').hidden = detail.open || !mine;
$('hk-run').hidden = !detail.open || !mine;
$('hk-replay').hidden = !detail.lastSession || !mine; // any session log is replayable, by the owner
setInput(detail.open && !detail.pendingAsk && mine);
$('session-open').hidden = detail.phase !== 'dormant' || !mine;
if (!$('session-open').hidden) $('session-open').textContent = `start session ${detail.sessions}`;
$('hk-run').hidden = detail.phase !== 'live' || !mine;
$('hk-rerun').hidden = !(detail.phase === 'dormant' && detail.sessions >= 2) || !mine;
$('hk-replay').hidden = !((detail.phase === 'live') || (detail.phase === 'dormant' && detail.sessions >= 2)) || !mine;
$('hk-override-row').hidden = !(detail.phase === 'dormant' && detail.ready === false) || !mine;
setInput(detail.phase === 'live' && !detail.pendingAsk && mine);
$('gm-input').placeholder = mine
? 'GM line — Enter sends, Shift+Enter newlines'
: 'spectating — fork this run to continue it as yours';
? 'GM line -- Enter sends, Shift+Enter newlines'
: 'spectating -- fork this run to continue it as yours';
// models: the owner's per-run overrides
$('models-pane').hidden = !mine;
@@ -127,7 +138,7 @@ async function refreshPlay(id, seq) {
models.fill(detail.run.models, detail.run.modelDefaults, mlist);
}
// pending ask: the modal re-presents after a refresh — the owner's
// pending ask: the modal re-presents after a refresh -- the owner's
// to answer; a spectator follows the thread in the transcript
if (detail.pendingAsk && mine) {
$('ask-question').textContent = detail.pendingAsk;
@@ -142,10 +153,24 @@ async function refreshPlay(id, seq) {
if (seq !== state.seq) return;
renderHk(hk);
// the GM's notepad — skip the reload if a save failed (dirty wins)
// the GM's notepad -- skip the reload if a save failed (dirty wins)
await loadNotes(id, seq);
}
// the dormant bar: the review window's banner over the carryover
// preview, with the one button that leaves it
function dormantBar(detail, carry) {
const bar = el('div', 'beat');
const ending = carry?.ends === 'gm'
? 'the carryover ends on your turn -- start sends it automatically as her cue'
: 'the table waits for your input once the session is live';
bar.appendChild(el('span', null, `session ${detail.sessions} is dormant -- the review window. ${ending}`));
const b = el('button', 'primary', `start session ${detail.sessions}`);
b.addEventListener('click', startRun);
bar.appendChild(b);
return bar;
}
function showConflict(text) {
const c = $('conflict');
c.textContent = `conflict: ${text}`;
@@ -156,7 +181,7 @@ function showConflict(text) {
//
// A debounced save (1s after the last keystroke, immediate on blur),
// flushed when leaving the play view or switching runs. gm.md never
// reaches any model — this is the GM's own notes.
// reaches any model -- this is the GM's own notes.
let notesTimer = null;
let notesDirty = false;
@@ -189,29 +214,27 @@ async function saveNotes() {
}
}
async function offerBeat(id, seq) {
let hasTurn0 = true;
// start: the dormant session goes live. If the carryover ends on a GM
// turn, the server sends it automatically as her cue.
async function startRun() {
const override = $('hk-override').checked;
hideBanner();
setBusy(true, 'starting...');
try {
const files = await api(`/runs/${id}/files`);
if (seq !== state.seq) return;
hasTurn0 = files.files['turn-0.md']?.exists === true;
} catch { /* try the endpoint anyway */ }
if (!hasTurn0) return;
const bar = el('div', 'beat');
bar.appendChild(el('span', null, 'the session is open; the opening beat has not been sent'));
const b = el('button', 'primary', 'send the opening beat');
b.addEventListener('click', async () => {
setBusy(true);
try {
await api(`/runs/${id}/turn0`, { method: 'POST', body: {} });
} catch (e) {
const r = await api(`/runs/${state.runId}/sessions`, { method: 'POST', body: { override } });
$('hk-override').checked = false;
if (r.autoSend) logEvent('nav', 'the carryover ended on a GM turn -- sent automatically as her cue');
} catch (e) {
if (e.status === 409 && e.detail?.hint) {
banner(`${e.message}\n${e.detail.hint}`, 'info');
} else if (e.status === 422 && e.detail?.errors) {
banner(`the carryover did not pass the start lint:\n${e.detail.errors.join('\n')}`);
} else {
banner(e.message);
}
setBusy(false);
render();
});
bar.appendChild(b);
$('transcript').prepend(bar);
}
setBusy(false);
render();
}
function setHk(stateText, cls) {
@@ -222,16 +245,18 @@ function setHk(stateText, cls) {
function renderHk(hk) {
if (hk.state === 'running') {
setHk('housekeeping…', '');
setHk(hk.phase === 'rerun' ? 're-running housekeeping...' : 'stopping & housekeeping...', '');
startPoll();
return;
}
stopPoll();
if (hk.state === 'applied') {
setHk(`applied — session ${hk.session ?? ''}\nnext session open`, 'applied');
loadLog(); // idempotent — also covers a refresh while applied
setHk(`applied -- session ${hk.session} housekept\nsession ${hk.target} is ready to start`, 'applied');
loadLog(); // idempotent -- also covers a refresh while applied
} else if (hk.state === 'pending') {
setHk(`housekeeping of session ${hk.session} never finished -- re-run it, apply a manifest by hand, or start with the override`, 'rejected');
} else if (hk.state === 'rejected') {
setHk(`rejected — held, nothing applied:\n${hk.reason ?? ''}`, 'rejected');
setHk(`rejected -- held, nothing applied:\n${hk.reason ?? ''}`, 'rejected');
} else {
setHk('idle', '');
}
@@ -275,11 +300,11 @@ async function sendAnswer() {
render();
}
// fork: a copy of this run under you — any run, anyone's, including
// fork: a copy of this run under you -- any run, anyone's, including
// yours. Lands you in the fork.
async function forkRun() {
if (!state.runId) return;
setBusy(true, 'forking…');
setBusy(true, 'forking...');
try {
const r = await api(`/runs/${state.runId}/fork`, { method: 'POST', body: {} });
setBusy(false);
@@ -291,26 +316,10 @@ async function forkRun() {
}
}
async function openSession() {
const override = $('hk-override').checked;
hideBanner();
try {
await api(`/runs/${state.runId}/sessions`, { method: 'POST', body: { override } });
$('hk-override').checked = false;
} catch (e) {
if (e.status === 409 && e.detail?.hint) {
banner(`${e.message}\n${e.detail.hint}`, 'info');
} else {
banner(e.message);
}
}
render();
}
// dry-run: the housekeeper reads the session log, the manifest lands
// in the pane — nothing applied, the session stays open
// in the pane -- nothing applied, the session stays open
async function replayHousekeeping() {
setBusy(true, 'the housekeeper reads…');
setBusy(true, 'the housekeeper reads...');
try {
const r = await api(`/runs/${state.runId}/housekeeping/replay`, { method: 'POST', body: {} });
$('hk-replay-content').textContent = r.parsed
@@ -355,13 +364,31 @@ async function loadLog() {
// --- wiring ---
armedButton($('hk-run'), {
label: 'close session & housekeep',
confirm: 'sure? click again to close & housekeep',
label: 'stop session',
confirm: 'sure? click again to stop, carry & housekeep',
fire: async () => {
hideBanner();
try {
await api(`/runs/${state.runId}/housekeeping`, { method: 'POST', body: {} });
setHk('housekeeping…', '');
setHk('stopping & housekeeping...', '');
startPoll();
} catch (e) {
banner(e.message);
}
render();
},
});
// the re-run: a fresh housekeeping pass over the finished predecessor,
// rebased -- the dormant session's rings are replaced, hand edits and all
armedButton($('hk-rerun'), {
label: 're-run housekeeping',
confirm: 'sure? click again -- the dormant session\'s rings are replaced, hand edits included',
fire: async () => {
hideBanner();
try {
await api(`/runs/${state.runId}/housekeeping`, { method: 'POST', body: {} });
setHk('re-running housekeeping...', '');
startPoll();
} catch (e) {
banner(e.message);
@@ -378,9 +405,10 @@ $('ask-send').addEventListener('click', sendAnswer);
$('ask-answer').addEventListener('keydown', (e) => {
if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); sendAnswer(); }
});
$('session-open').addEventListener('click', openSession);
$('session-open').addEventListener('click', startRun);
$('hk-replay').addEventListener('click', replayHousekeeping);
$('fork-btn').addEventListener('click', forkRun);
$('story-link').addEventListener('click', () => { if (state.runId) navigate(`/runs/${state.runId}/story`); });
$('gm-notes').addEventListener('input', notesInput);
$('gm-notes').addEventListener('blur', saveNotes);
window.addEventListener('pagehide', saveNotes); // tab close / reload mid-debounce