gm-input expansion built from the roadmap (DECISIONS #9's strictness ruling): the GM's line and ask answers expand at ingestion -- @PC/@Package and $vars resolve before the log, an unresolved token refuses the turn with a 400 naming it and nothing appended; the log records the expanded line, keeping continuation carryovers expansion-free by construction; smoke +4 (the $Bogus refusal, the log provably unchanged, a live sigil turn, the expanded line in the log) -- 115/115 all pass; the GM input gains a highlight overlay (the setup editor's stack pattern transplanted): *italics* render italic, **bold** renders bold, @PC/@Package gold, $vars green, every character kept on screen (the asterisks too) so the caret never desyncs, bold/italics matched per-line like the transcript renderer; the box rekeys -- Enter is a plain newline, Ctrl+Space sends, placeholder updated; and a pre-existing bug the live pass caught: failed-action banners were wiped by the render() that follows every action (the runGone trap) -- sendTurn, sendAnswer, and startRun now set the banner after the render; browser-proven end to end: tokens highlight in place, Enter newlines, the refusal loop shows the banner and restores the line un-eaten and still highlighted, the sigil expands in the log, zero console errors; the roadmap item struck as built, DECISIONS #9 amended to same-day-built, README's substitution paragraph and AGENTS' identity-model bullet carry the live-input rule; typecheck green on both programs, check-repo clean

This commit is contained in:
2026-11-15 23:45:15 +00:00
parent 951213239f
commit 193dc336be
10 changed files with 134 additions and 28 deletions
+25 -4
View File
@@ -6,14 +6,17 @@
// 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.
// conflicts ride the next GM turn as a <conflict> block. GM input
// expands at ingestion (strict, DECISIONS #9): @PC/@Package and $vars
// resolve before the line is logged; an expansion error refuses the
// turn and the line is handed back for editing.
/** @typedef {import('./shapes.mjs').Ctx} Ctx */
/** @typedef {import('./shapes.mjs').LiveSession} LiveSession */
/** @typedef {import('./shapes.mjs').Actor} Actor */
/** @typedef {import('./shapes.mjs').ViewMessage} ViewMessage */
import { clerkJson } from './clerk.mjs';
import { toolList, runTool, assembleReminder } from './bundle.mjs';
import { toolList, runTool, assembleReminder, expandVars } from './bundle.mjs';
import { renderView } from './session.mjs';
import { parseVariants, pickVariant } from './variants.mjs';
@@ -45,11 +48,21 @@ function needSession(ctx, runId) {
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)');
// GM-input expansion (strict, DECISIONS #9): the line resolves at
// ingestion -- the log records the expanded words, which is what
// keeps continuation carryovers expansion-free forever. A refused
// turn appends nothing: the client hands the line back for editing.
let prose;
try {
prose = expandVars(runId, line.trim());
} catch (e) {
throw new HttpError(400, `the line was not sent -- ${e.message}`);
}
const status = /** @type {string[]} */ (clerkJson(runId, 'status')); // fresh per turn
const agenda = /** @type {string[]} */ (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>${status.join(', ')}</status>\n<agenda>${agendaWire}</agenda>`;
const content = `${prose}\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)
@@ -76,11 +89,19 @@ export async function openingCall(ctx, runId, user) {
export async function answerAsk(ctx, runId, answer, user) {
const s = needSession(ctx, runId);
if (!s.pendingAsk) throw new HttpError(409, 'no pending question');
// the answer is GM input: same strict expansion, same hand-back --
// a refusal leaves the pending question untouched
let resolved;
try {
resolved = expandVars(runId, answer.trim());
} catch (e) {
throw new HttpError(400, `the answer was not sent -- ${e.message}`);
}
// execute the paused batch: the ask gets the answer, its siblings
// (if any) get dispatched now -- pairing stays whole
for (const call of s.pendingAsk.calls) {
if (call.id === s.pendingAsk.callId) {
s.append({ t: 'tool', ask: true, m: { role: 'tool', tool_call_id: call.id, content: answer } });
s.append({ t: 'tool', ask: true, m: { role: 'tool', tool_call_id: call.id, content: resolved } });
} else {
s.append({ t: 'tool', m: { role: 'tool', tool_call_id: call.id, content: runTool(runId, call) } });
}