agenda: the player's second paper (add/drop deltas, cap-5 recency queue); conflicts self-heal as their own turn; same-verb blocks combine; per-run model selection; substrate-tag syntax rule

This commit is contained in:
2026-11-14 21:15:32 +00:00
parent 711634cc38
commit 5956e44f7a
15 changed files with 627 additions and 71 deletions
+51 -4
View File
@@ -154,7 +154,8 @@ function serveStatic(pathname, res) {
// among invitees, not with the world.
route('GET', '/api/session', async ({ user }) => ({
user, // null when signed out or the token is stale
// the public shape only — the stored row (token hash) never leaves
user: user ? { id: user.id, name: user.name, superuser: user.superuser === 1 } : null,
fresh: users.userCount() === 0,
}), { public: true });
@@ -332,7 +333,8 @@ route('GET', '/api/runs/:id', async ({ params }) => {
forked: meta?.forked ?? null,
owner,
ownerName: owner == null ? null : users.userName(owner),
model: meta?.model ?? null,
models: meta?.models ?? {},
modelDefaults: ctx.cfg.models ?? {},
},
display: bundle.runDisplay(id),
open: !!s,
@@ -341,6 +343,7 @@ route('GET', '/api/runs/:id', async ({ params }) => {
window: s?.stamp ?? null,
fresh: s?.fresh ?? false,
paper: st.paper,
agenda: st.agenda,
records: st.records,
fill: st.rings,
events: st.events,
@@ -417,6 +420,33 @@ route('POST', '/api/runs/:id/vars', async ({ params, body, user }) => {
return { ok: true, vars: settings.vars };
});
// the run's models: per-run overrides of the deployment defaults
// (server.json), selected from the upstream listing (GET /api/models).
// Owner-only, changeable at any time — every call resolves fresh, so a
// mid-window switch simply takes the next turn. null clears a role
// back to its deployment default.
route('POST', '/api/runs/:id/model', async ({ params, body, user }) => {
const id = params.id;
bundle.requireRun(id);
requireOwner(user, id);
for (const k of Object.keys(body)) {
if (k !== 'player' && k !== 'housekeeper') throw new HttpError(400, `unknown model role: ${k} — player and housekeeper`);
}
const meta = bundle.runMeta(id) ?? {};
const models = meta.models ?? {};
for (const role of ['player', 'housekeeper']) {
if (body[role] === undefined) continue;
if (body[role] === null) { delete models[role]; continue; }
const m = String(body[role]).trim();
if (!m) throw new HttpError(400, `${role}: a model name, or null to fall back to the deployment default`);
models[role] = m;
}
if (Object.keys(models).length) meta.models = models;
else delete meta.models;
fs.writeFileSync(path.join(bundle.runDir(id), 'run.json'), JSON.stringify(meta, null, 2) + '\n');
return { ok: true, models: meta.models ?? {}, defaults: ctx.cfg.models ?? {} };
});
// the GM's notepad: the run's gm.md — always editable in the SPA,
// never in any bundle, never sent to any model (no assembly path
// reads it). Seeded from the package at creation, the GM's to keep.
@@ -504,8 +534,7 @@ route('POST', '/api/runs/:id/fork', async ({ params, user }) => {
route('GET', '/api/runs/:id/status', async ({ params }) => {
bundle.requireRun(params.id);
const s = ctx.sessions.get(params.id);
return { paper: clerkJson(params.id, 'paper'), conflict: s?.conflict ?? null };
return { paper: clerkJson(params.id, 'paper'), agenda: clerkJson(params.id, 'agenda') };
});
// the GM's out-of-band paper override: whole-paper replace via the
@@ -526,6 +555,24 @@ route('POST', '/api/runs/:id/paper', async ({ params, body, user }) => {
return { ok: true, paper };
});
// the GM's out-of-band agenda override: whole-queue replace via the
// clerk (journaled). Items land in written order, first = top; an
// empty array clears it. Commas are the add transport's separator —
// an item containing one is a 400, not a silent split later.
route('POST', '/api/runs/:id/agenda', async ({ params, body, user }) => {
const id = params.id;
bundle.requireRun(id);
requireOwner(user, id);
const items = body.items;
if (!Array.isArray(items)) throw new HttpError(400, 'items (an array of descriptions) is required — an empty array clears the agenda');
for (const it of items) {
if (typeof it !== 'string' || !it.trim()) throw new HttpError(400, 'every item must be a non-empty string');
if (it.includes(',')) throw new HttpError(400, `items never contain commas (the add transport is comma-separated): ${JSON.stringify(it)}`);
}
const agenda = clerkJson(id, '--gm', 'agenda-set', ...items);
return { ok: true, agenda };
});
route('POST', '/api/runs/:id/housekeeping', async ({ params, user }) => {
// ends the window and kicks the async chain; poll GET for the outcome
requireOwner(user, params.id);