the 2026-11-16 rounds, the whole day in one commit: model discovery (the two-step op act -- discover scrapes the provider metadata, refine runs the deterministic battery over every id and hands the adjudicated results to the best passing model for the curated registry; state/models.json is the truth of selectable models and gates all model use, a fresh deployment has none; the five named sampling knobs ride run.json params over server.json params, sent only when set; the curator call retries once on the host's network hiccups, its output strictly validated with the machine-list fallback, and the do-not-deliberate line keeps its thinking tokens down); the pick rule reworked on the GM's rulings -- the dv endpoint's 5.2/5.3-max flip was an alias (one model behind both ids), the rank keys on the reasoning bucket not the raw token count (within-bucket differences are sampling noise, the thresholds sit in the endpoint's observed gaps) and full ties settle sort-lex-pick-bottom, with the mock registry carrying a canned tie pair (mock/mock-tie) and the smoke asserting the lex-bottom pick; the play-protocol batch (OOC GM turns carry no cache blocks, memory.json is authored draft applied by the start gate's reapply over a fresh db, /story filters OOC whole, the per-turn raw control on the table); the tunables UX round (web/knobs.mjs: the definitions table with the GM's hint texts and the probed this-endpoint bounds, the per-knob explicit override toggle replacing implicit empty-means-unset diffing, the shared focus-driven hint bar; the run detail and /model responses carry paramDefaults, the deployment layer -- the only default anyone can honestly name); request recording (every provider call lands its resolved model + effective params on the msg event as via, a failed call lands a req event with the failure, both surface on the raw tab and the per-turn raw control on no model-facing surface, a req riding the slidwin tail passes the start lint as conversation machinery; the housekeeping pass log names its model via the clerk's --model flag); the mind verb (<mind> JSON in a player turn sets its sampling for its next turn -- one-shot, max_tokens excluded, a budget not a mind; bounds enforced in KNOB_BOUNDS with the range named in the conflict and the heal restatement the statement that counts; derive() makes a statement live until a player reply consumes it, honest across restarts, session boundaries and forks -- an unconsumed mind rides on); the full-block protocol (the GM rewrote system/invariants/reminder to eliminate the diff verbs: she emits whole <status>/<agenda> at her turn tail, a present block is a whole-list set, absent means unchanged never blank, over-cap agendas evict from the bottom silently -- ruled a feature, silent to her, the note shows the GM; renderView strips every copy and stamps the newest of each kind at the tail of her most recent prose turn, her own emission, so the context reads as the same sequence of events the game had; GM prose goes pure, old logs' composited rides strip, they were never GM words; <mind> is write-only, its tags strip from the view; every turn of hers carries its <model> block -- the params it rode, bare JSON from the via record, the current call included, suppressed when nothing is set, emitting one refused with a pointer at <mind>; the clerk's status-apply/agenda-apply delta verbs RETIRED with their dispatch and collectors, status-set/agenda-set are the player path now; the story strips her blocks, the table chips them; the smoke imports renderView and asserts the view policy directly -- the pattern for testing view-only policy no API exposes); and the opening event RETIRED (the start gate seeds the clerk from her last authored turn's blocks -- the GM moved la-caramba's initial status into her opening turn; old carryovers keep their events as inert history; the event's pre-existing double-landing in every started log, pre-bundle and in-carry, died with the branch); smoke ALL PASS + restart + reminder + repo checks green, browser passes over the knob UX and the new chips and notes with zero console errors, typecheck green on both programs; README and DICTIONARY carry the durable design, HANDOFF trimmed to the map
This commit is contained in:
+115
-20
@@ -105,6 +105,7 @@ function makeSession(runId, n) {
|
||||
file: logFile(runId, n),
|
||||
lines: [],
|
||||
pendingAsk: null, // { callId, question, calls } -- the whole batch pauses
|
||||
mind: null, // the <mind> verb's one-shot layer, rebuilt by derive
|
||||
usage: null, // { promptTokens, completionTokens } from the last response
|
||||
/** @param {LogEvent} entry */
|
||||
append(entry) {
|
||||
@@ -152,6 +153,8 @@ export function loadSession(runId, n) {
|
||||
function derive(s) {
|
||||
/** @type {?PendingAsk} */
|
||||
let pending = null;
|
||||
/** @type {?import('./shapes.mjs').RoleParams} */
|
||||
let mind = null;
|
||||
for (const e of s.lines) {
|
||||
if (e.t === 'msg' && e.m.role === 'assistant' && e.m.tool_calls?.length) {
|
||||
const ask = e.m.tool_calls.find((c) => c.function.name === 'ask_gm');
|
||||
@@ -165,8 +168,19 @@ function derive(s) {
|
||||
} else if (e.t === 'msg' && e.usage) {
|
||||
s.usage = { promptTokens: e.usage.prompt_tokens, completionTokens: e.usage.completion_tokens };
|
||||
}
|
||||
// the mind layer: a statement is live until a player reply
|
||||
// consumes it (a failed request consumed nothing -- the req event
|
||||
// is not a reply). This makes a restart -- and a session
|
||||
// boundary -- honest: her last on-record mind, unconsumed in
|
||||
// this log, rides her next turn. Divergence only when a restart
|
||||
// lands mid-turn (a tool-call message consumes here but only at
|
||||
// turn completion in the live loop); the via records show what
|
||||
// actually rode either way.
|
||||
if (e.t === 'note' && e.kind === 'mind') mind = e.params;
|
||||
else if (e.t === 'msg' && e.m.role === 'assistant') mind = null;
|
||||
}
|
||||
s.pendingAsk = pending;
|
||||
s.mind = mind;
|
||||
// a final variant turn that never got its pick (crash between the
|
||||
// message and its note) resolves at boot: a fresh random pick,
|
||||
// appended as the note it always should have had. Malformed content
|
||||
@@ -185,6 +199,22 @@ function derive(s) {
|
||||
}
|
||||
}
|
||||
|
||||
// split a list of block items: lines and commas as separators, list
|
||||
// markers stripped -- the grammar the pane editors use and the
|
||||
// full-block protocol speaks. A present-but-empty block is a
|
||||
// deliberate clear (an empty list). Shared with the turn loop (the
|
||||
// player's live sets) and the start gate (the authored seed).
|
||||
/** @param {string} text @param {'status'|'agenda'} kind @returns {string[]} */
|
||||
export function blockList(text, kind) {
|
||||
const out = [];
|
||||
for (const m of String(text).matchAll(new RegExp(`<${kind}>([\\s\\S]*?)</${kind}>`, 'g'))) {
|
||||
out.push(...m[1].split('\n')
|
||||
.flatMap((l) => l.replace(/^\s*[-*]\s+\d*[.:)]?\s*/, '').split(','))
|
||||
.map((x) => x.trim()).filter(Boolean));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// --- stop: the manual close ----------------------------------------------------
|
||||
//
|
||||
// (1) move N's tail into the new dormant N+1 as its carryover;
|
||||
@@ -253,9 +283,12 @@ export function findStalledStop(runId) {
|
||||
// --- start: lint, freeze, consume, go live -------------------------------------
|
||||
|
||||
// the authored carryover's event vocabulary: her opening as msg
|
||||
// events (user = the GM, assistant = her), plus at most one opening
|
||||
// event (her opening status). A continuation carryover is real
|
||||
// conversation: msg, tool, and note events, read as recorded.
|
||||
// events (user = the GM, assistant = her). The opening event is
|
||||
// RETIRED (GM, 2026-11-16): old carryovers keep theirs as inert
|
||||
// history -- tolerated here, never applied. A continuation
|
||||
// carryover is real conversation: msg, tool, note, and req events
|
||||
// (a failed request's record is machinery like a note), read as
|
||||
// recorded.
|
||||
// Exported for the file editor's save-time check: only clean
|
||||
// openings land.
|
||||
/** @param {LogEvent[]} lines @param {{ authored: boolean }} opts @returns {string[]} */
|
||||
@@ -287,7 +320,7 @@ export function lintCarryover(lines, { authored }) {
|
||||
} else {
|
||||
errors.push(`${at}: authored events are msg or opening only (got ${JSON.stringify(e.t)})`);
|
||||
}
|
||||
} else if (!['msg', 'tool', 'note'].includes(e.t)) {
|
||||
} else if (!['msg', 'tool', 'note', 'req'].includes(e.t)) {
|
||||
errors.push(`${at}: a carryover holds conversation events only (got ${JSON.stringify(e.t)})`);
|
||||
}
|
||||
// both kinds: a variants message must parse strict -- nothing
|
||||
@@ -302,6 +335,12 @@ export function lintCarryover(lines, { authored }) {
|
||||
}
|
||||
});
|
||||
if (authored && openings > 1) errors.push('at most one opening event');
|
||||
// the full-block protocol (GM, 2026-11-16): the initial status rides
|
||||
// her last turn in the carryover -- an authored carryover without
|
||||
// model turns has no canon point to stamp
|
||||
if (authored && !lines.some((e) => e.t === 'msg' && e.m?.role === 'assistant')) {
|
||||
errors.push('the authored carryover must contain her opening turn (a model turn) -- the initial status rides it');
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
@@ -395,13 +434,33 @@ export function startSession(runId, { override = false } = {}) {
|
||||
}
|
||||
carry = resolvePicks(carry);
|
||||
|
||||
// the opening event: her opening status, set before the first turn
|
||||
// (set semantics, journaled by the clerk)
|
||||
const opening = carry.find((e) => e.t === 'opening');
|
||||
if (opening) {
|
||||
const r = clerkTry(runId, '--session', String(n), 'status-set', ...opening.status);
|
||||
if (r.code !== 0) {
|
||||
throw err(422, `the opening status did not apply: ${(r.err || r.out).split('\n')[0]}`);
|
||||
// session-0's housekeeping: her starting memories are authored
|
||||
// material until this moment -- memory.json applies over a fresh db,
|
||||
// so the draft's edits are the rings she actually gets. The clerk
|
||||
// scratch-validates first (a refusal touches nothing), and a refusal
|
||||
// refuses the start: the draft stays a draft.
|
||||
if (n === 1) {
|
||||
const mr = clerkTry(runId, '--session', '1', 'reapply');
|
||||
if (mr.code !== 0) {
|
||||
throw err(422, 'the starting memories did not pass the manifest checks -- nothing started', {
|
||||
errors: [(mr.err || mr.out || 'reapply failed').split('\n')[0]],
|
||||
});
|
||||
}
|
||||
// the full-block protocol (GM, 2026-11-16): the initial state
|
||||
// rides her last authored turn -- the gate seeds the clerk from
|
||||
// her blocks, so the panes and the stamped view read the same
|
||||
// words. The opening event is retired: old carryovers keep theirs
|
||||
// as inert history (tolerated by the lint, never applied -- and
|
||||
// its old double-landing, pre-bundle and in-carry, dies here)
|
||||
const lastHer = /** @type {?import('./shapes.mjs').MsgEvent} */ ([...carry].reverse().find((e) => e.t === 'msg' && e.m?.role === 'assistant') ?? null);
|
||||
const herText = typeof lastHer?.m?.content === 'string' ? lastHer.m.content : '';
|
||||
if (/<status>/.test(herText)) {
|
||||
const sr = clerkTry(runId, '--session', String(n), 'status-set', ...blockList(herText, 'status'));
|
||||
if (sr.code !== 0) throw err(422, `the opening status did not apply: ${(sr.err || sr.out).split('\n')[0]}`);
|
||||
}
|
||||
if (/<agenda>/.test(herText)) {
|
||||
const ar = clerkTry(runId, '--session', String(n), 'agenda-set', ...blockList(herText, 'agenda'));
|
||||
if (ar.code !== 0) throw err(422, `the opening agenda did not apply: ${(ar.err || ar.out).split('\n')[0]}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -417,7 +476,6 @@ export function startSession(runId, { override = false } = {}) {
|
||||
/** @type {LogEvent[]} */
|
||||
const lines = [
|
||||
{ t: 'note', kind: 'session', n },
|
||||
...(opening ? [opening] : []),
|
||||
{ t: 'bundle', m: system, part: 'system' },
|
||||
...bundle.map((m, i) => /** @type {LogEvent} */ ({ t: 'bundle', m, part: partNames[i] })),
|
||||
...carry,
|
||||
@@ -449,6 +507,11 @@ export function startSession(runId, { override = false } = {}) {
|
||||
// --- the view renderer: log + policy -> per-call context ---------------------
|
||||
|
||||
const STRIP_BLOCKS = /\n?<(status|conflict|agenda)>[\s\S]*?<\/\1>\n?/g;
|
||||
// her own blocks never show inline: status and agenda stamp at the
|
||||
// canon point (the newest value of each kind at her most recent
|
||||
// turn's tail), <mind> is write-only, <model> is display-only -- the
|
||||
// log keeps every copy verbatim, the view is policy
|
||||
const STRIP_HERS = /(?:\n)?<(status|agenda|mind|model)>[\s\S]*?<\/\1>\n?/g;
|
||||
|
||||
/** The renderer reads only these two of a session -- the start path
|
||||
* validates its assembled context with the same policy before going
|
||||
@@ -463,10 +526,29 @@ export function renderView(s, keepToolResults = 4) {
|
||||
/** @type {number[]} */
|
||||
const reminderIdx = [];
|
||||
let lastGmIdx = -1;
|
||||
// the stamping pre-pass (the full-block protocol): the newest
|
||||
// status and agenda values across her turns, and her most recent
|
||||
// prose turn -- the canon point where they stamp. The status is the
|
||||
// game world as of her turn; after it the GM's turn happens, then
|
||||
// her new turn -- the context must read as that same sequence of
|
||||
// events (GM, 2026-11-16)
|
||||
/** @type {?string} */ let lastStatus = null;
|
||||
/** @type {?string} */ let lastAgenda = null;
|
||||
let lastProse = -1;
|
||||
s.lines.forEach((e, i) => {
|
||||
if (e.t === 'tool') toolIdx.push(i);
|
||||
if (e.t === 'msg' && e.m.role === 'user') lastGmIdx = i;
|
||||
if (e.t === 'msg' && e.reminder) reminderIdx.push(i);
|
||||
if (e.t === 'msg' && e.m.role === 'assistant') {
|
||||
const c = eff.has(i) ? eff.get(i) : e.m.content;
|
||||
if (typeof c === 'string') {
|
||||
if (c.trim()) lastProse = i;
|
||||
const sm = c.match(/<status>([\s\S]*?)<\/status>/);
|
||||
if (sm) lastStatus = sm[1];
|
||||
const am = c.match(/<agenda>([\s\S]*?)<\/agenda>/);
|
||||
if (am) lastAgenda = am[1];
|
||||
}
|
||||
}
|
||||
});
|
||||
const keep = new Set(toolIdx.slice(-keepToolResults));
|
||||
const newestReminder = reminderIdx.length ? reminderIdx[reminderIdx.length - 1] : -1;
|
||||
@@ -479,13 +561,28 @@ export function renderView(s, keepToolResults = 4) {
|
||||
if (e.reminder) {
|
||||
// the per-turn reminder: only the newest copy lives in the
|
||||
// context -- superseded ones elide (identical content, freshest
|
||||
// position, exactly like the status/agenda blocks)
|
||||
// position, exactly like the stamped blocks)
|
||||
if (i === newestReminder) msgs.push({ role: 'system', content: String(e.m.content ?? '').trim() });
|
||||
} else if (e.m.role === 'assistant') {
|
||||
// thinking never goes back; the log keeps it. Variant turns
|
||||
// render their picked variant -- the unpicked rest never reach
|
||||
// a model (the log keeps them)
|
||||
const m = /** @type {ViewMessage} */ ({ role: 'assistant', content: eff.has(i) ? eff.get(i) : (e.m.content ?? null) });
|
||||
// a model (the log keeps them). Her blocks strip (STRIP_HERS);
|
||||
// the via record renders as the turn's <model> block when any
|
||||
// params rode; the newest status/agenda stamp at the canon point
|
||||
let content = eff.has(i) ? (eff.get(i) ?? null) : (e.m.content ?? null);
|
||||
if (typeof content === 'string') {
|
||||
content = content.replace(STRIP_HERS, '').trim();
|
||||
if (e.via && Object.keys(e.via.params ?? {}).length) {
|
||||
content = `<model>${JSON.stringify(e.via.params)}</model>\n${content}`;
|
||||
}
|
||||
if (i === lastProse) {
|
||||
/** @type {string[]} */ const stamp = [];
|
||||
if (lastStatus !== null) stamp.push(`<status>${lastStatus}</status>`);
|
||||
if (lastAgenda !== null) stamp.push(`<agenda>${lastAgenda}</agenda>`);
|
||||
if (stamp.length) content = `${content}\n${stamp.join('\n')}`;
|
||||
}
|
||||
}
|
||||
const m = /** @type {ViewMessage} */ ({ role: 'assistant', content });
|
||||
if (e.m.tool_calls?.length) m.tool_calls = e.m.tool_calls;
|
||||
msgs.push(m);
|
||||
} else if (e.conflictOnly) {
|
||||
@@ -493,12 +590,10 @@ export function renderView(s, keepToolResults = 4) {
|
||||
// (the model answers it), elided entirely once the story moves
|
||||
// on -- the log keeps it for provenance
|
||||
if (i === lastGmIdx) msgs.push({ role: e.m.role, content: String(e.m.content ?? '').trim() });
|
||||
} else if (i === lastGmIdx) {
|
||||
// the newest GM turn keeps its blocks as-sent: the current
|
||||
// status and agenda ride it
|
||||
msgs.push({ role: e.m.role, content: String(e.m.content ?? '').trim() });
|
||||
} else {
|
||||
// older GM turns: status/agenda/conflict blocks elide
|
||||
// GM prose goes pure (the full-block protocol): the rides were
|
||||
// server-composited, never GM words -- strip from every GM
|
||||
// turn, old logs included
|
||||
msgs.push({ role: e.m.role, content: String(e.m.content ?? '').replace(STRIP_BLOCKS, '').trim() });
|
||||
}
|
||||
} else if (e.t === 'tool') {
|
||||
|
||||
Reference in New Issue
Block a user