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
+40 -9
View File
@@ -31,11 +31,10 @@ 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
let content = `${line.trim()}\n\n<status>${paper.join(', ')}</status>`;
if (s.conflict) {
content += `\n<conflict>${s.conflict}</conflict>`;
s.conflict = null;
}
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>`;
s.append({ t: 'msg', m: { role: 'user', content } });
return runLoop(ctx, runId, user);
}
@@ -80,6 +79,7 @@ async function runLoop(ctx, runId, user) {
const s = ctx.sessions.get(runId);
const tools = toolList(runId);
const out = { tools: [] };
let heals = 0;
for (;;) {
const view = renderView(s);
let msg;
@@ -114,13 +114,31 @@ async function runLoop(ctx, runId, user) {
continue; // let the model see the results before ending its turn
}
// final player message — paper deltas ride the turn text itself
// final player message — the paper 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 });
if (r.conflicts?.length) s.conflict = r.conflicts.join('; ');
carry.push(...(r.conflicts ?? []));
}
if (/<(add|drop)>/.test(text)) {
const r = clerkJson(runId, 'agenda-apply', text);
s.append({ t: 'note', kind: 'agenda', applied: { added: r.added, dropped: r.dropped, evicted: r.evicted }, conflicts: r.conflicts });
carry.push(...(r.conflicts ?? []));
}
if (carry.length && heals < 3) {
// a conflict answers for itself: it goes back as its own message,
// not attached to a GM turn — clean of prose, easy to read, easy
// to heal. Capped so a confused model cannot ping-pong forever.
heals++;
s.append({ t: 'msg', m: { role: 'user', content: `<conflict>${carry.join('; ')}</conflict>` }, conflictOnly: true });
continue;
}
if (carry.length) out.conflicts = carry; // healing gave up — the transcript shows it
out.player = text;
return out;
}
@@ -128,7 +146,7 @@ async function runLoop(ctx, runId, user) {
function resolveModel(ctx, runId) {
const meta = ctx.runMeta(runId) ?? {};
return meta.model ?? ctx.cfg.models?.player ?? null;
return meta.models?.player ?? ctx.cfg.models?.player ?? null;
}
// --- the mock model ----------------------------------------------------------
@@ -154,7 +172,20 @@ function mockModel(s, view) {
return call('ask_gm', { question: 'From where she stands, does the deck look clear toward the bow?' }, `mock-ask-${s.lines.length}`);
}
if (assistantCount === 3) {
return { role: 'assistant', content: 'Mock: good to know. *She exhales and lets her shoulders drop.*\n<lost>worried</lost>\n<gained>settled</gained>' };
// two <gained> and two <add> blocks on one turn: same-verb blocks
// combine into one apply, never a sequence — the smoke asserts the
// merged, order-preserving result
return { role: 'assistant', content: 'Mock: good to know. *She exhales and lets her shoulders drop.*\n<lost>worried</lost>\n<gained>settled</gained>\n<gained>curious about the clicking</gained>\n<add>find fresh water</add>\n<add>signal any passing ship, build a shelter</add>' };
}
if (assistantCount === 4) {
return { role: 'assistant', content: 'Mock: *She settles on the first task and starts walking.*\n<drop>0</drop>' };
}
if (assistantCount === 5) {
return { role: 'assistant', content: 'Mock: *She squints at the horizon.*\n<drop>9</drop>' };
}
if (assistantCount === 6) {
// the self-heal: this fires in answer to the conflict-only message
return { role: 'assistant', content: 'Mock: *She shakes her head — no such thing on the list.*\n<drop>0, 1</drop>' };
}
return { role: 'assistant', content: 'Mock: *She watches the water and waits for the world to move.*' };
}