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:
+127
-5
@@ -113,14 +113,17 @@ function renderContent(el, text, { extract }) {
|
||||
let body = String(text ?? '');
|
||||
let status = null;
|
||||
let conflict = null;
|
||||
let agenda = null;
|
||||
if (extract) {
|
||||
const sm = body.match(/<status>([\s\S]*?)<\/status>/);
|
||||
if (sm) { status = sm[1]; body = body.replace(sm[0], ''); }
|
||||
const cm = body.match(/<conflict>([\s\S]*?)<\/conflict>/);
|
||||
if (cm) { conflict = cm[1]; body = body.replace(cm[0], ''); }
|
||||
const am = body.match(/<agenda>([\s\S]*?)<\/agenda>/);
|
||||
if (am) { agenda = am[1]; body = body.replace(am[0], ''); }
|
||||
}
|
||||
const tags = [];
|
||||
for (const m of body.matchAll(/<(lost|gained)>([\s\S]*?)<\/\1>/g)) {
|
||||
for (const m of body.matchAll(/<(lost|gained|add|drop)>([\s\S]*?)<\/\1>/g)) {
|
||||
tags.push({ kind: m[1], items: m[2].split('\n').flatMap((l) => l.split(',')).map((x) => x.trim()).filter(Boolean) });
|
||||
}
|
||||
for (const t of tags) body = body.replace(new RegExp(`<${t.kind}>[\\s\\S]*?</${t.kind}>`), '');
|
||||
@@ -137,6 +140,16 @@ function renderContent(el, text, { extract }) {
|
||||
el.appendChild(d);
|
||||
continue;
|
||||
}
|
||||
if (t.startsWith('<')) {
|
||||
// substrate lines: an opening <tag> is always OOC (invariants.md).
|
||||
// Known blocks were extracted above; whatever remains is an
|
||||
// unknown or unbalanced tag — keep it visible, styled as OOC
|
||||
const d = document.createElement('div');
|
||||
d.className = 'line ooc';
|
||||
d.textContent = t;
|
||||
el.appendChild(d);
|
||||
continue;
|
||||
}
|
||||
const stars = (line.match(/\*/g) ?? []).length;
|
||||
if (!narr && stars % 2 === 0) {
|
||||
// balanced: spans carry the registers — mixed lines
|
||||
@@ -183,7 +196,7 @@ function renderContent(el, text, { extract }) {
|
||||
}
|
||||
el.appendChild(wrap);
|
||||
}
|
||||
return { status, conflict };
|
||||
return { status, conflict, agenda };
|
||||
}
|
||||
|
||||
// --- transcript ---------------------------------------------------------------
|
||||
@@ -222,6 +235,11 @@ function renderTranscript(entries) {
|
||||
}
|
||||
flushBundle();
|
||||
if (e.t === 'msg') {
|
||||
if (e.m.role === 'user' && e.conflictOnly) {
|
||||
// the self-heal message: error traffic on its own, never GM prose
|
||||
t.appendChild(el('div', 'machinery', `[conflict] ${String(e.m.content).replace(/<\/?conflict>/g, '').trim()}`));
|
||||
continue;
|
||||
}
|
||||
if (e.m.role === 'user') gmTurn(e.m.content, 'GM');
|
||||
else if (e.m.role === 'assistant') playerTurn(e);
|
||||
continue;
|
||||
@@ -281,6 +299,47 @@ function renderPaper(paper) {
|
||||
p.textContent = state.paper.join(', '); // compact, mirroring the <status> wire format
|
||||
}
|
||||
|
||||
// the agenda pane mirrors the wire: the queue numbered from the top,
|
||||
// exactly as the model cites it
|
||||
function renderAgenda(agenda) {
|
||||
state.agenda = agenda ?? [];
|
||||
const a = $('agenda');
|
||||
if (!state.agenda.length) {
|
||||
a.textContent = 'a clear head';
|
||||
a.classList.add('empty');
|
||||
return;
|
||||
}
|
||||
a.classList.remove('empty');
|
||||
a.textContent = state.agenda.map((d, i) => `${i}. ${d}`).join('; ');
|
||||
}
|
||||
|
||||
// the GM's out-of-band agenda override: whole-queue replace via agenda-set
|
||||
function editAgenda() {
|
||||
$('agenda-edit-area').value = state.agenda.join('\n');
|
||||
$('agenda').hidden = true;
|
||||
$('agenda-edit').hidden = true;
|
||||
$('agenda-editor').hidden = false;
|
||||
$('agenda-edit-area').focus();
|
||||
}
|
||||
function cancelAgendaEdit() {
|
||||
$('agenda-editor').hidden = true;
|
||||
$('agenda').hidden = false;
|
||||
$('agenda-edit').hidden = false;
|
||||
}
|
||||
async function saveAgenda() {
|
||||
const items = $('agenda-edit-area').value
|
||||
.split('\n').flatMap((l) => l.replace(/^\s*[-*]\s+\d*[.:)]?\s*/, '').split(','))
|
||||
.map((x) => x.trim()).filter(Boolean);
|
||||
try {
|
||||
await api(`/runs/${state.runId}/agenda`, { method: 'POST', body: { items } });
|
||||
} catch (e) {
|
||||
banner(e.message);
|
||||
return; // stay in the editor — nothing was changed
|
||||
}
|
||||
cancelAgendaEdit();
|
||||
render();
|
||||
}
|
||||
|
||||
// the GM's out-of-band override: whole-paper replace via paper-set
|
||||
function editPaper() {
|
||||
$('paper-edit-area').value = state.paper.join('\n');
|
||||
@@ -386,6 +445,7 @@ function show(view) {
|
||||
$('conflict').hidden = true;
|
||||
renderMeter(null);
|
||||
cancelPaperEdit(); // a stale open editor must never leave the pane hidden
|
||||
cancelAgendaEdit();
|
||||
if (view !== 'play') $('ask-modal').close();
|
||||
}
|
||||
|
||||
@@ -421,7 +481,7 @@ async function viewHome(seq) {
|
||||
// the name carries the content facts plus the ownership garnish;
|
||||
// started-or-forked rides the meta — chrome, never model-facing
|
||||
card.appendChild(el('span', 'card-name', `${r.display ?? r.id}${ownershipTag(r, mine)}`));
|
||||
card.appendChild(el('span', 'card-meta', `${r.package} · ${r.forked ? `forked ${fmtUnix(r.forked)}` : `started ${r.created ?? '?'}`} · ring A ${r.fill?.a ?? 0} / B ${r.fill?.b ?? 0} · ${r.id}${r.model ? ` · ${r.model}` : ''}`));
|
||||
card.appendChild(el('span', 'card-meta', `${r.package} · ${r.forked ? `forked ${fmtUnix(r.forked)}` : `started ${r.created ?? '?'}`} · ring A ${r.fill?.a ?? 0} / B ${r.fill?.b ?? 0} · ${r.id}${r.models?.player ? ` · ${r.models.player}` : ''}`));
|
||||
card.appendChild(el('span', `card-state ${runStateClass(r)}`, runStateText(r)));
|
||||
// another user's draft is read-only: the play view says so; your own opens the editor
|
||||
card.addEventListener('click', () => navigate(r.lastSession || !mine ? `/runs/${r.id}` : `/runs/${r.id}/setup`));
|
||||
@@ -543,6 +603,46 @@ async function pickPackage(p) {
|
||||
if ($('create-pc').value === '' && roll?.name) $('create-pc').value = roll.name;
|
||||
}
|
||||
|
||||
// --- models: per-run overrides of the deployment defaults --------------------
|
||||
//
|
||||
// The upstream listing is fetched once per session (a live /models
|
||||
// call every render would hammer the endpoint for a list that rarely
|
||||
// changes). A select's "" value means "deployment default"; a current
|
||||
// override missing from the listing stays selectable, so a stale pick
|
||||
// never silently rewrites itself.
|
||||
|
||||
async function modelList() {
|
||||
if (!state.modelList) state.modelList = await api('/models').catch(() => []);
|
||||
return state.modelList;
|
||||
}
|
||||
|
||||
function fillModelSelect(sel, current, list, def) {
|
||||
sel.textContent = '';
|
||||
const mk = (v, label) => {
|
||||
const o = el('option', null, label);
|
||||
o.value = v;
|
||||
sel.appendChild(o);
|
||||
};
|
||||
mk('', `deployment default${def ? ` — ${def}` : ' (unset)'}`);
|
||||
const opts = [...list];
|
||||
if (current && !opts.includes(current)) opts.push(current);
|
||||
for (const m of opts) mk(m, m);
|
||||
sel.value = current ?? '';
|
||||
}
|
||||
|
||||
async function saveModels(playerSel, housekeeperSel, stateEl) {
|
||||
try {
|
||||
await api(`/runs/${state.runId}/model`, {
|
||||
method: 'POST',
|
||||
body: { player: playerSel.value || null, housekeeper: housekeeperSel.value || null },
|
||||
});
|
||||
stateEl.textContent = 'saved';
|
||||
} catch (e) {
|
||||
banner(e.message);
|
||||
stateEl.textContent = 'not saved';
|
||||
}
|
||||
}
|
||||
|
||||
// --- setup: the editor + start -----------------------------------------------------
|
||||
|
||||
// one list, in bundle-assembly order: the repo-fed system message
|
||||
@@ -603,8 +703,7 @@ async function viewSetup(id, seq) {
|
||||
api(`/runs/${id}/files`),
|
||||
api('/prompts'),
|
||||
]);
|
||||
} catch (e) {
|
||||
if (e.status === 404) {
|
||||
} catch (e) { if (e.status === 404) {
|
||||
const from = location.pathname;
|
||||
navigate('/'); // render() clears the banner first — set it after
|
||||
banner(`run ${id} is gone — deleted?`);
|
||||
@@ -641,6 +740,13 @@ async function viewSetup(id, seq) {
|
||||
varsList.appendChild(row);
|
||||
}
|
||||
|
||||
// models: per-run overrides, selected from the upstream listing
|
||||
const mlist = await modelList();
|
||||
if (seq !== state.seq) return;
|
||||
fillModelSelect($('model-player'), detail.run.models?.player ?? null, mlist, detail.run.modelDefaults?.player);
|
||||
fillModelSelect($('model-housekeeper'), detail.run.models?.housekeeper ?? null, mlist, detail.run.modelDefaults?.housekeeper);
|
||||
$('models-state').textContent = '';
|
||||
|
||||
const nav = $('setup-files');
|
||||
nav.textContent = '';
|
||||
state.fileSpecs = {};
|
||||
@@ -871,11 +977,13 @@ async function refreshPlay(id, seq) {
|
||||
+ (mine ? '' : detail.run.owner == null ? ' — ownerless' : ' — spectating');
|
||||
renderMeter(detail);
|
||||
renderPaper(detail.paper);
|
||||
renderAgenda(detail.agenda);
|
||||
$('conflict').hidden = true;
|
||||
|
||||
// spectator mode: read everything, mutate nothing — the fork is the
|
||||
// way in. Ownerless runs are spectators for everyone alike.
|
||||
$('paper-edit').hidden = !mine;
|
||||
$('agenda-edit').hidden = !mine;
|
||||
$('gm-notes').readOnly = !mine;
|
||||
|
||||
let beatNeeded = false;
|
||||
@@ -900,6 +1008,15 @@ async function refreshPlay(id, seq) {
|
||||
? 'GM line — Enter sends, Shift+Enter newlines'
|
||||
: 'spectating — fork this run to continue it as yours';
|
||||
|
||||
// models: the owner's per-run overrides
|
||||
$('models-pane').hidden = !mine;
|
||||
if (mine) {
|
||||
const mlist = await modelList();
|
||||
if (seq !== state.seq) return;
|
||||
fillModelSelect($('pm-player'), detail.run.models?.player ?? null, mlist, detail.run.modelDefaults?.player);
|
||||
fillModelSelect($('pm-housekeeper'), detail.run.models?.housekeeper ?? null, mlist, detail.run.modelDefaults?.housekeeper);
|
||||
}
|
||||
|
||||
// pending ask: the modal re-presents after a refresh — the owner's
|
||||
// to answer; a spectator follows the thread in the transcript
|
||||
if (detail.pendingAsk && mine) {
|
||||
@@ -1188,6 +1305,8 @@ $('setup-vars-save').addEventListener('click', async () => {
|
||||
}
|
||||
});
|
||||
$('setup-save').addEventListener('click', saveFile);
|
||||
$('models-save').addEventListener('click', () => saveModels($('model-player'), $('model-housekeeper'), $('models-state')));
|
||||
$('pm-save').addEventListener('click', () => saveModels($('pm-player'), $('pm-housekeeper'), $('pm-state')));
|
||||
$('setup-delete').addEventListener('click', deleteDraft);
|
||||
$('setup-edit').addEventListener('input', () => {
|
||||
if (state.currentFile) stashDraft(state.currentFile);
|
||||
@@ -1215,6 +1334,9 @@ $('hk-replay').addEventListener('click', replayWrap);
|
||||
$('paper-edit').addEventListener('click', editPaper);
|
||||
$('paper-cancel').addEventListener('click', cancelPaperEdit);
|
||||
$('paper-save').addEventListener('click', savePaper);
|
||||
$('agenda-edit').addEventListener('click', editAgenda);
|
||||
$('agenda-cancel').addEventListener('click', cancelAgendaEdit);
|
||||
$('agenda-save').addEventListener('click', saveAgenda);
|
||||
$('gm-notes').addEventListener('input', notesInput);
|
||||
$('gm-notes').addEventListener('blur', saveNotes);
|
||||
window.addEventListener('pagehide', saveNotes); // tab close / reload mid-debounce
|
||||
|
||||
Reference in New Issue
Block a user