the sheet round: the GM's ledger of arbitrated run state -- the second state channel, split from status and agenda by truth model (GM, 2026-11-17). The rulings first: status and agenda are narrative self-report (their truth is "she said so", the scan caches her latest words); the sheet is actual run state (its truth is "the GM set so", the record IS the truth event -- nothing cached from anyone's words). The override channel promoted to a standing section, and that precedent decided the presentation: the sheet renders as its OWN authoritative system chunk at the freshest end, never a canon-point stamp, which would read as her words -- the same reason the override composes as hers and the sheet never does. Schemaless JSON in the tag (the mind-verb philosophy: the substrate teaches the channel, the package teaches the vocabulary -- the invariants rule the GM wrote is one universal paragraph with deliberately non-box examples, clothes and grades, and the propose-additions line as her schema-evolution channel); details learnt in-place; NO package gating -- the channel is universal and "optional, if given" makes the invariant forward-compatible in every bundle that never sets one. The build: a sheet record rides the GM turn like the override (readSheet: object-ness is the route's only law, 400 loud on arrays and scalars, nothing appended; OOC turns refuse it exactly like block edits); scanState derives newest-wins whole-set -- an absent key drops, never keeps, and {} is a live empty ledger (a truthy check, never falsy); the boundary state note carries it across stops and the dormant read path serves it; renderView appends the chunk once per assembly so one live copy holds by construction; the guard is the <model> sibling (an emitted <sheet> conflicts with "the GM's ledger -- propose changes in prose", healed in-turn, cap 3, and her emission never applies -- the scan holds the GM's record); every strip surface learned the tag (the view's STRIP_HERS, the story's verbs, the table's chip regex -- the standing grep-every-strip-list lesson, applied); and the web gains sheetEditor, the paneEditor's JSON sibling in widgets.mjs (same stage/pending/discard pattern, bad JSON refuses at the stage), the third pane in the aside, the send attaching body.sheet, and [sheet] machinery lines on both table and raw walks. The mock's sheet-guard branch is CUE-KEYED, not position-keyed: the carried tail shifts the script's counts (session 4's log starts the script over -- the battery's first attempt landed on the ask position and crashed renderView on the unpaired call; the battery now answers the script ask and moves on), while a marked GM turn is immune to every shift -- mockModel reads the view, the marked turn earns the emission, the conflict it earns earns the plain-prose heal. check-reminder is sheet-aware (the chunk is a legitimate third system surface; the count and freshest-end assertions tolerate exactly one, and the freshest-end check now allows her latest reply and/or the chunk to follow the reminder). Verified: smoke ALL PASS with +15 sheet assertions (newest-wins, whole-set semantics, the chunk one-live-copy -- ANCHORED with startsWith because the invariants bundle itself mentions the tag and a bare regex matches it twice, an honest test bug caught by an honest test), the guard's conflict and heal with her emission kept verbatim in the raw log and never applied, the view and story strips, the empty ledger rendering its chunk, the boundary note carrying the sheet, the dormant read deriving it, and session 5 deriving it from the carried note end to end), restart + reminder checks green, typecheck green on both programs, check-repo clean (it caught the round's own prose twice: "window" is a retired term in README, the contwin vocabulary wins), and a browser pass over the pane end to end with zero console errors -- staging, the pending marker, the ride, the scan re-render, and both machinery lines on the table. Docs: README's protocol passage carries the sheet with the numbers-live-on-the-sheet line (prose numbers die with the contwin; sheet numbers ride the scan forever) -- NOT in the memory tiers table, where the first draft wrongly put it (the GM's ruling: the sheet belongs in neither memories nor records); the identity tier lost its loose "character sheet" name now that the term is technical; DICTIONARY gains the sheet entry with the history line (dice retired into variant literature, sheets arrived as the state machinery -- the tabletop metaphor completing while its realism stays advisory, players hold their own pencils in the real thing and we don't, for drift); ROADMAP parks the bookkeeper extension (the housekeeper's arithmetic sibling: reads the setting's rules prose and the latest turns, computes the ledger delta from a purchase in her prose, lands it as a STAGED edit -- applied on the GM's next turn or discarded; sheet-only authority, curator fallback, per-package opt-in because an agent cannot bookkeep what is not arithmetic). The GM's prompt-side edits ride the same commit: invariants' "Character's sheet" section (the universal rule, the trailing-clause flag taken in review), the reminder's inventory line gaining "the sheet (optional)", and la caramba's gm.md lore updates. The box package (the first consumer) and detention stay untracked WIP, untouched. The 2026-11-17 roadmap audit rides the same commit (GM: "done items can retire"): retired outright -- the SPA-vs-bridge and voice-examples decisions (long resolved) and steal items #1, #3, #4, #8, #11 (done, or in #8's case never work -- the housekeeper model is per-run selection, built); retired with tombstones -- the multiuser section (built 2026-11-14, the rulings live in DECISIONS #22-31 and README, the lifecycle tail kept visible) and the SPA v1 section (all four phases done, the API sketch superseded by README's living API docs, the substrate doctrine in README), with the one unbuilt design it held -- the turn-surgery saga rule -- surviving as its own bullet cross-referenced at steal #2; amended in place, dated -- seed.json (dead, successors named: the authored carryover and memory.json), turn-0.md (dead: her authored opening turn), the upstream model listing (never queried in play since discovery), the delta-tag transport (the full-block protocol, the sheet named), the service step (multiuser built, hosting remains), the carryover editor (the raw file-editor surface exists, the purpose-built UI stays deferred); kept -- the operator's queue, the landscape and receipts, the live constraints, the open steals with numbering preserved so cross-references resolve, the deferred tasks, the distant points, the rejections, the notes. 582 lines to 338; the first deletion pass duplicated the steal-list header and the verification re-read caught it
This commit is contained in:
+25
-3
@@ -53,9 +53,10 @@ function needSession(ctx, runId) {
|
||||
/**
|
||||
* @param {Ctx} ctx @param {string} runId @param {string} line @param {?Actor} user
|
||||
* @param {?{ status?: string[], agenda?: string[] }} [override]
|
||||
* @param {?Record<string, unknown>} [sheet]
|
||||
* @returns {Promise<TurnOut>}
|
||||
*/
|
||||
export async function gmTurn(ctx, runId, line, user, override = null) {
|
||||
export async function gmTurn(ctx, runId, line, user, override = null, sheet = null) {
|
||||
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
|
||||
@@ -71,8 +72,10 @@ export async function gmTurn(ctx, runId, line, user, override = null) {
|
||||
// GM prose goes pure: no cache blocks ride any turn. A block edit,
|
||||
// when given, rides this turn as the override record -- the
|
||||
// composition overwrites her newest blocks with it (the scan reads
|
||||
// it newest-wins), the log keeps her words verbatim
|
||||
s.append({ t: 'msg', m: { role: 'user', content: prose }, ...(override ? { override } : {}) });
|
||||
// it newest-wins), the log keeps her words verbatim. The sheet
|
||||
// record rides the same way: the GM's ledger, a whole set, the scan
|
||||
// reads it newest-wins, the log never mutates
|
||||
s.append({ t: 'msg', m: { role: 'user', content: prose }, ...(override ? { override } : {}), ...(sheet ? { sheet } : {}) });
|
||||
// the reminder follows the GM's prose as its own system chunk --
|
||||
// every turn, one live copy (older ones elide in the view)
|
||||
const reminder = assembleReminder(runId);
|
||||
@@ -256,6 +259,11 @@ async function runLoop(ctx, runId, user) {
|
||||
if (/<model>/.test(text)) {
|
||||
carry.push('the <model> block is a read-only display of your active parameters -- state them in a <mind> block');
|
||||
}
|
||||
// the <sheet> block is display-only the same way: the GM's ledger,
|
||||
// read-only for her (GM, 2026-11-17) -- changes propose in prose
|
||||
if (/<sheet>/.test(text)) {
|
||||
carry.push('the <sheet> block is the GM\'s ledger -- propose changes in prose');
|
||||
}
|
||||
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
|
||||
@@ -444,6 +452,20 @@ function mockModel(s, view) {
|
||||
content: null,
|
||||
tool_calls: [{ id, type: 'function', function: { name, arguments: JSON.stringify(args) } }],
|
||||
});
|
||||
// the sheet guard's cue (position-independent -- the carried tail
|
||||
// shifts counts, a cue does not shift): the marked GM turn gets the
|
||||
// emission, the conflict it earns gets the plain-prose heal. The
|
||||
// view carries the conflict as its raw text (the log field does not
|
||||
// ride), so the check reads the tags
|
||||
const lastMsg = view[view.length - 1];
|
||||
const lastGm = [...view].reverse().find((m) => m.role === 'user' && !/^<conflict>/.test(String(m.content ?? '')));
|
||||
if (lastGm && /the floating numbers/.test(String(lastGm.content ?? ''))) {
|
||||
if (lastMsg && /^<conflict>/.test(String(lastMsg.content ?? ''))) {
|
||||
// the heal: plain prose, no blocks -- she proposes in prose
|
||||
return { role: 'assistant', content: 'Mock: *She shakes the numbers out of her head and asks for the change out loud instead.*' };
|
||||
}
|
||||
return { role: 'assistant', content: 'Mock: *She squints at the ledger floating in her mind.*\n<sheet>{"gp": 99}</sheet>' };
|
||||
}
|
||||
let inExchange = false;
|
||||
let count = 0;
|
||||
for (const e of s.lines) {
|
||||
|
||||
+23
-6
@@ -473,6 +473,7 @@ route('GET', '/api/runs/:id', async ({ params, user }) => {
|
||||
ready: sm.ready ?? null,
|
||||
status: state.status,
|
||||
agenda: state.agenda,
|
||||
sheet: state.sheet,
|
||||
records: st.records,
|
||||
fill: st.rings,
|
||||
events: st.events,
|
||||
@@ -839,7 +840,7 @@ route('GET', '/api/runs/:id/table', async ({ params, user }) => {
|
||||
route('GET', '/api/runs/:id/story', async ({ params }) => {
|
||||
bundle.requireRun(params.id);
|
||||
const rides = /<(status|agenda|conflict)>[\s\S]*?<\/\1>/g;
|
||||
const verbs = /<(lost|gained|add|drop|mind|model|status|agenda)>[\s\S]*?<\/\1>/g;
|
||||
const verbs = /<(lost|gained|add|drop|mind|model|status|agenda|sheet)>[\s\S]*?<\/\1>/g;
|
||||
const project = (/** @type {import('./shapes.mjs').LogEvent[]} */ lines) => {
|
||||
const eff = effectiveContents(lines);
|
||||
/** @type {{ who: string, text: string }[]} */
|
||||
@@ -920,15 +921,31 @@ function readOverride(body) {
|
||||
return override;
|
||||
}
|
||||
|
||||
// The sheet record (GM, 2026-11-17): the GM's ledger of arbitrated run
|
||||
// state, riding the GM turn like the override. Schemaless by ruling --
|
||||
// a plain JSON object, any fields, semantics living in the setting's
|
||||
// prose; the route's only law is object-ness (an array or a scalar is
|
||||
// a 400, nothing appended). Absent key on the turn means no edit; an
|
||||
// empty object is a deliberate empty ledger.
|
||||
/** @param {Record<string, unknown>} body @returns {?Record<string, unknown>} */
|
||||
function readSheet(body) {
|
||||
if (body.sheet === undefined || body.sheet === null) return null;
|
||||
if (typeof body.sheet !== 'object' || Array.isArray(body.sheet)) {
|
||||
throw new HttpError(400, 'sheet must be a JSON object -- the GM\'s ledger record');
|
||||
}
|
||||
return /** @type {Record<string, unknown>} */ (body.sheet);
|
||||
}
|
||||
|
||||
route('POST', '/api/runs/:id/turn', async ({ params, body, user }) => {
|
||||
const line = String(body.line ?? '').trim();
|
||||
if (!line) throw new HttpError(400, 'line is required');
|
||||
const override = readOverride(body);
|
||||
if (override && line.startsWith('(')) {
|
||||
const sheet = readSheet(body);
|
||||
if ((override || sheet) && line.startsWith('(')) {
|
||||
throw new HttpError(400, 'a block edit cannot ride an OOC turn -- overrides arrive with a non-OOC GM turn');
|
||||
}
|
||||
requireOwner(user, params.id);
|
||||
return { ok: true, ...(await ctx.enqueue(params.id, async () => gmTurn(ctx, params.id, line, user, override))) };
|
||||
return { ok: true, ...(await ctx.enqueue(params.id, async () => gmTurn(ctx, params.id, line, user, override, sheet))) };
|
||||
});
|
||||
|
||||
route('POST', '/api/runs/:id/ask', async ({ params, body, user }) => {
|
||||
@@ -981,11 +998,11 @@ route('POST', '/api/runs/:id/fork', async ({ params, user }) => {
|
||||
// db holds no copy). The latest session's log is the whole story
|
||||
// since its start; during dormancy the carryover is the live edge
|
||||
// and rides along. A run with no sessions derives nothing.
|
||||
/** @param {string} runId @returns {{ status: string[], agenda: string[] }} */
|
||||
/** @param {string} runId @returns {{ status: string[], agenda: string[], sheet: ?Record<string, unknown> }} */
|
||||
function derivedState(runId) {
|
||||
const live = ctx.sessions.get(runId);
|
||||
const latest = session.latestSession(runId);
|
||||
if (latest == null) return { status: [], agenda: [] };
|
||||
if (latest == null) return { status: [], agenda: [], sheet: null };
|
||||
const n = live?.n ?? latest;
|
||||
const dir = session.sessionDir(runId, n);
|
||||
/** @type {import('./shapes.mjs').LogEvent[]} */ const lines = [];
|
||||
@@ -1003,7 +1020,7 @@ function derivedState(runId) {
|
||||
}
|
||||
}
|
||||
const st = session.scanState(lines);
|
||||
return { status: st.status ?? [], agenda: st.agenda ?? [] };
|
||||
return { status: st.status ?? [], agenda: st.agenda ?? [], sheet: st.sheet };
|
||||
}
|
||||
|
||||
route('GET', '/api/runs/:id/status', async ({ params, user }) => {
|
||||
|
||||
+25
-5
@@ -248,11 +248,19 @@ export function cleanBlockList(text, kind) {
|
||||
return cleanList(blockList(text, kind));
|
||||
}
|
||||
|
||||
/** @param {LogEvent[]} lines @returns {{ status: ?string[], agenda: ?string[] }} */
|
||||
/** The state scan: newest-wins across her emissions (the picked
|
||||
* variant's text), the GM's records, and the boundary note. The sheet
|
||||
* (GM, 2026-11-17) is the second channel: arbitrated run state, never
|
||||
* her words -- its sources are the GM's turn records and the note,
|
||||
* each record a whole set (absent key means dropped, never kept), and
|
||||
* it never caps, never cleans: the GM's ledger is exactly what the GM
|
||||
* last set.
|
||||
* @param {LogEvent[]} lines @returns {{ status: ?string[], agenda: ?string[], sheet: ?Record<string, unknown> }} */
|
||||
export function scanState(lines) {
|
||||
const eff = effectiveContents(lines);
|
||||
/** @type {?string[]} */ let status = null;
|
||||
/** @type {?string[]} */ let agenda = null;
|
||||
/** @type {?Record<string, unknown>} */ let sheet = null;
|
||||
for (const [i, e] of lines.entries()) {
|
||||
if (e.t === 'msg' && e.m.role === 'assistant' && !e.m.tool_calls?.length) {
|
||||
const c = eff.has(i) ? eff.get(i) : e.m.content;
|
||||
@@ -263,13 +271,16 @@ export function scanState(lines) {
|
||||
} else if (e.t === 'msg' && e.m.role === 'user' && e.override) {
|
||||
if (e.override.status) status = cleanList(e.override.status);
|
||||
if (e.override.agenda) agenda = cleanList(e.override.agenda);
|
||||
} else if (e.t === 'msg' && e.m.role === 'user' && e.sheet) {
|
||||
sheet = e.sheet;
|
||||
} else if (e.t === 'note' && e.kind === 'state') {
|
||||
if (e.status) status = cleanList(e.status);
|
||||
if (e.agenda) agenda = cleanList(e.agenda);
|
||||
if (e.sheet) sheet = e.sheet;
|
||||
}
|
||||
}
|
||||
if (agenda !== null && agenda.length > AGENDA_CAP) agenda = agenda.slice(0, AGENDA_CAP);
|
||||
return { status, agenda };
|
||||
return { status, agenda, sheet };
|
||||
}
|
||||
|
||||
// --- stop: the manual close ----------------------------------------------------
|
||||
@@ -316,8 +327,8 @@ export function stopSession(runId, N) {
|
||||
// position, so it is safe to write always
|
||||
const st = scanState(lines);
|
||||
/** @type {LogEvent[]} */ let head = [];
|
||||
if (st.status !== null || st.agenda !== null) {
|
||||
head = [{ t: 'note', kind: 'state', ...(st.status !== null ? { status: st.status } : {}), ...(st.agenda !== null ? { agenda: st.agenda } : {}) }];
|
||||
if (st.status !== null || st.agenda !== null || st.sheet !== null) {
|
||||
head = [{ t: 'note', kind: 'state', ...(st.status !== null ? { status: st.status } : {}), ...(st.agenda !== null ? { agenda: st.agenda } : {}), ...(st.sheet !== null ? { sheet: st.sheet } : {}) }];
|
||||
}
|
||||
const moved = [...head, ...lines.slice(start)];
|
||||
fs.writeFileSync(carry, moved.map((e) => JSON.stringify(e)).join('\n') + (moved.length ? '\n' : ''));
|
||||
@@ -598,7 +609,7 @@ const STRIP_BLOCKS = /\n?<(status|conflict|agenda)>[\s\S]*?<\/\1>\n?/g;
|
||||
// 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;
|
||||
const STRIP_HERS = /(?:\n)?<(status|agenda|mind|model|sheet)>[\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
|
||||
@@ -698,6 +709,15 @@ export function renderView(s, keepToolResults = 4) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// the sheet chunk (GM, 2026-11-17): arbitrated run state renders as
|
||||
// its OWN authoritative system chunk at the freshest end -- never a
|
||||
// canon-point stamp, which would read as her words. One live copy by
|
||||
// construction (assembled once per view, not logged per turn). An
|
||||
// empty object renders too: the channel exists, nothing tracked.
|
||||
// She reads it, never writes it -- the guard conflicts an emission.
|
||||
if (st.sheet != null) {
|
||||
msgs.push({ role: 'system', content: `<sheet>${JSON.stringify(st.sheet)}</sheet>` });
|
||||
}
|
||||
validatePairing(msgs, s.pendingAsk?.callId);
|
||||
return msgs;
|
||||
}
|
||||
|
||||
+2
-2
@@ -34,7 +34,7 @@ export {};
|
||||
* arriving with a non-OOC GM turn: the log's record of it. The
|
||||
* composition overwrites her newest blocks with these values (the
|
||||
* scan reads it newest-wins); the log itself never changes. */
|
||||
/** @typedef {{ t: 'msg', m: WireMessage, reminder?: boolean, conflictOnly?: boolean, usage?: Usage, via?: { model: string, params: RoleParams }, override?: { status?: string[], agenda?: string[] } }} MsgEvent */
|
||||
/** @typedef {{ t: 'msg', m: WireMessage, reminder?: boolean, conflictOnly?: boolean, usage?: Usage, via?: { model: string, params: RoleParams }, override?: { status?: string[], agenda?: string[] }, sheet?: Record<string, unknown> }} MsgEvent */
|
||||
|
||||
/** req: a failed provider request -- the resolved model, the
|
||||
* effective params, and the failure. No message resulted (the turn
|
||||
@@ -62,7 +62,7 @@ export {};
|
||||
* the slidwin tail. Machinery like every note: never rendered, the
|
||||
* scan reads it newest-wins (it loses to any emission inside the
|
||||
* tail by position). */
|
||||
/** @typedef {{ t: 'note', kind: 'state', status?: string[], agenda?: string[] }} StateNote */
|
||||
/** @typedef {{ t: 'note', kind: 'state', status?: string[], agenda?: string[], sheet?: Record<string, unknown> }} StateNote */
|
||||
/** @typedef {SessionNote|AskNote|PickNote|StatusNote|AgendaNote|MindNote|StateNote} NoteEvent */
|
||||
|
||||
/** bundle: one frozen prompt part (system, backdrop, character, rings). */
|
||||
|
||||
Reference in New Issue
Block a user