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
@@ -3,7 +3,7 @@
// Synchronous REST: a POST runs the tool loop and returns. ask_gm
// pauses mid-turn — the whole tool-call batch waits (pairing stays
// sound), the request returns with the pending question, and the
// answer call resumes the loop. The paper is re-read from the clerk
// answer call resumes the loop. The status is re-read from the clerk
// before every GM turn and rides it as a <status> block; the player's
// <lost>/<gained> deltas apply after its final message, and any
// conflicts ride the next GM turn as a <conflict> block.
@@ -23,18 +23,18 @@ export class HttpError extends Error {
function needSession(ctx, runId) {
const s = ctx.sessions.get(runId);
if (!s) throw new HttpError(409, `no open window for run '${runId}' — POST /api/runs/${runId}/windows first`);
if (!s) throw new HttpError(409, `no open session for run '${runId}' — POST /api/runs/${runId}/sessions first`);
return s;
}
export async function gmTurn(ctx, runId, line, user) {
const s = needSession(ctx, runId);
if (s.pendingAsk) throw new HttpError(409, 'a question is pending — answer it first (POST /ask)');
const paper = clerkJson(runId, 'paper'); // fresh per turn
const status = clerkJson(runId, 'status'); // fresh per turn
const agenda = clerkJson(runId, 'agenda'); // fresh per turn
// the wire renders the queue as the model cites it: numbered from the top
const agendaWire = agenda.map((d, i) => `${i}. ${d}`).join('; ');
const content = `${line.trim()}\n\n<status>${paper.join(', ')}</status>\n<agenda>${agendaWire}</agenda>`;
const content = `${line.trim()}\n\n<status>${status.join(', ')}</status>\n<agenda>${agendaWire}</agenda>`;
s.append({ t: 'msg', m: { role: 'user', content } });
// the reminder follows the GM's prose as its own system chunk —
// every turn, one live copy (older ones elide in the view)
@@ -44,9 +44,9 @@ export async function gmTurn(ctx, runId, line, user) {
}
// the opening beat: turn-0 sent as the first GM turn, separate from
// the bundle (start = open window, then this). Its trailing <status>
// block was ingested as her opening paper at window-open — stripped
// here, since the normal ride carries the current paper on every GM
// the bundle (start = open session, then this). Its trailing <status>
// block was ingested as her opening status at session-open — stripped
// here, since the normal ride carries the current status on every GM
// turn, the beat included.
export async function turn0(ctx, runId, user) {
const s = needSession(ctx, runId);
@@ -118,15 +118,15 @@ async function runLoop(ctx, runId, user) {
continue; // let the model see the results before ending its turn
}
// final player message — the paper and agenda deltas ride the turn
// final player message — the status and agenda deltas ride the turn
// text. Same-verb blocks combine into one apply (the clerk's
// collectors gather every block before executing anything), never a
// sequence of applies.
const text = msg.content ?? '';
const carry = [];
if (/<(lost|gained)>/.test(text)) {
const r = clerkJson(runId, 'paper-apply', text);
s.append({ t: 'note', kind: 'paper', applied: { lost: r.lost, gained: r.gained }, conflicts: r.conflicts });
const r = clerkJson(runId, 'status-apply', text);
s.append({ t: 'note', kind: 'status', applied: { lost: r.lost, gained: r.gained }, conflicts: r.conflicts });
carry.push(...(r.conflicts ?? []));
}
if (/<(add|drop)>/.test(text)) {
@@ -157,7 +157,7 @@ function resolveModel(ctx, runId) {
//
// A scripted stand-in that exercises the loop without a key: turn one
// rolls, turn two asks (the pause/resume path), the answer lands with
// paper deltas (the tag transport), everything after is plain prose.
// status deltas (the tag transport), everything after is plain prose.
function mockModel(s, view) {
const call = (name, args, id) => ({
role: 'assistant',