variant round: roll retired, chance is variant literature (strict parse, crypto pick on reception, picked-only rendering, /story variance metric); entity round: /story the whole deliverable, /table the play projection, the slidwin carry (smart contwin cutoff, whole exchanges, housekeeper reads session-minus-tail); dormant-session rework: universal session lifecycle (dormant->live->finished, sessions/<n> storage), move-at-stop, start lint + auto-send rule, rebaseable housekeeping, turn-0 -> carryover.jsonl, seed -> memory.json, draft-only save-package; format house rules enforced by the nine-rule check-repo (ascii bytes, no text-mutating css); smoke 105/105 + restart + reminder + browser pass green, irene hand-migrated to the new layout
This commit is contained in:
+59
-43
@@ -1,21 +1,23 @@
|
||||
// web/view-setup.mjs — the draft editor: the full assembly in bundle
|
||||
// order (the repo-fed prompts read-only, the run's craft editable,
|
||||
// config read-only), the prompt-declared $TOKEN inputs, per-run
|
||||
// models, and the two exits — save as package (publishes it) or
|
||||
// start (opens the session, sends turn-0).
|
||||
// web/view-setup.mjs -- the dormancy editor: the full assembly in
|
||||
// bundle order (the repo-fed prompts read-only, the session's craft
|
||||
// editable while dormant), the prompt-declared $TOKEN inputs, per-run
|
||||
// models, and the exits -- save as package (a draft act, publishes
|
||||
// it) or start (the dormant session goes live; a carryover ending on
|
||||
// a GM turn sends automatically as her cue).
|
||||
|
||||
import { $, el } from './dom.mjs';
|
||||
import { api } from './client.mjs';
|
||||
import { state } from './state.mjs';
|
||||
import { banner } from './chrome.mjs';
|
||||
import { navigate, runGone } from './router.mjs';
|
||||
import { logEvent } from './log.mjs';
|
||||
import { armedButton, modelList, modelsBox } from './widgets.mjs';
|
||||
|
||||
// one list, in bundle-assembly order: the repo-fed system message
|
||||
// parts (read-only — the user should understand how the model is
|
||||
// prompted), the craft tail and GM messages (editable), then the
|
||||
// initial state, then run config (read-only). Everything the run
|
||||
// sends, nothing it doesn't.
|
||||
// parts (read-only -- the user should understand how the model is
|
||||
// prompted), the craft tail and GM messages (editable while the
|
||||
// session is dormant), then the opening material, then run config
|
||||
// (read-only). Everything the session sends, nothing it doesn't.
|
||||
const EDIT_LIST = [
|
||||
{ name: 'system.md', mode: 'ro', source: 'repo' },
|
||||
{ name: 'invariants.md', mode: 'ro', source: 'repo' },
|
||||
@@ -23,20 +25,20 @@ const EDIT_LIST = [
|
||||
{ name: 'handbook.md', mode: 'rw', source: 'run' },
|
||||
{ name: 'backdrop.md', mode: 'rw', source: 'run' },
|
||||
{ name: 'character.md', mode: 'rw', source: 'run' },
|
||||
{ name: 'seed.json', mode: 'rw', source: 'run' }, // the rings it seeds — turn-0 wakes into them
|
||||
{ name: 'turn-0.md', mode: 'rw', source: 'run' },
|
||||
{ name: 'memory.json', mode: 'ro', source: 'run' }, // the session-0 manifest, applied at creation -- provenance
|
||||
{ name: 'carryover.jsonl', mode: 'rw', source: 'run' }, // the opening log -- raw events, linted on save
|
||||
{ name: 'settings.json', mode: 'ro', source: 'run' },
|
||||
{ name: 'run.json', mode: 'ro', source: 'run' },
|
||||
];
|
||||
|
||||
// the editor's working set — module-local, reset on every enter
|
||||
// the editor's working set -- module-local, reset on every enter
|
||||
let files = null; // { name: { content, exists } }
|
||||
let drafts = {}; // unsaved edits by file name
|
||||
let currentFile = null;
|
||||
let fileSpecs = {};
|
||||
let repoPrompts = {};
|
||||
|
||||
const models = modelsBox('setup-models', { title: 'models — per-run, over the deployment defaults' });
|
||||
const models = modelsBox('setup-models', { title: 'models -- per-run, over the deployment defaults' });
|
||||
|
||||
export async function enter(id, seq) {
|
||||
state.runId = id;
|
||||
@@ -51,11 +53,11 @@ export async function enter(id, seq) {
|
||||
]);
|
||||
} catch (e) {
|
||||
if (e.status === 404) return runGone(id, location.pathname);
|
||||
return banner(`could not reach the server: ${e.message}`); // stay put — transient
|
||||
return banner(`could not reach the server: ${e.message}`); // stay put -- transient
|
||||
}
|
||||
if (seq !== state.seq) return;
|
||||
if (!detail.draft) return navigate(`/runs/${id}`); // started runs live in play
|
||||
if (detail.run.owner !== state.me.id) return navigate(`/runs/${id}`); // not yours: read-only — fork to edit
|
||||
if (detail.phase !== 'dormant') return navigate(`/runs/${id}`); // live sessions live in play
|
||||
if (detail.run.owner !== state.me.id) return navigate(`/runs/${id}`); // not yours: read-only -- fork to edit
|
||||
|
||||
files = filesResp.files;
|
||||
repoPrompts = {
|
||||
@@ -64,14 +66,20 @@ export async function enter(id, seq) {
|
||||
'reminder.md': prompts.reminder ?? '',
|
||||
};
|
||||
$('setup-title').textContent = detail.display;
|
||||
$('setup-state').textContent = `${detail.run.package} · ${id} — draft; edits land when the session opens`;
|
||||
$('setup-state').textContent = detail.draft
|
||||
? `${detail.run.package} \u00b7 ${id} -- draft; edits land when the session starts`
|
||||
: `${detail.run.package} \u00b7 ${id} -- session ${detail.sessions} dormant, the review window`;
|
||||
$('setup-start').disabled = false;
|
||||
$('setup-start').textContent = 'start';
|
||||
$('setup-start').textContent = `start session ${detail.sessions}`;
|
||||
// draft-only affordances: deletion and save-as-package (a package is
|
||||
// a starting point, never a snapshot)
|
||||
$('setup-delete').hidden = !detail.draft;
|
||||
$('setup-savepkg').hidden = !detail.draft;
|
||||
|
||||
// prompt vars: the $TOKENS the prompts declare, filled per run
|
||||
const vars = scanVars(prompts, files);
|
||||
let currentVars = {};
|
||||
try { currentVars = JSON.parse(files['settings.json']?.content ?? '{}').vars ?? {}; } catch { /* unreadable settings — empty vars */ }
|
||||
try { currentVars = JSON.parse(files['settings.json']?.content ?? '{}').vars ?? {}; } catch { /* unreadable settings -- empty vars */ }
|
||||
const varsList = $('setup-vars-list');
|
||||
varsList.textContent = '';
|
||||
$('setup-vars').hidden = !vars.length;
|
||||
@@ -97,11 +105,14 @@ export async function enter(id, seq) {
|
||||
const runFile = files[e.name];
|
||||
const spec = {
|
||||
...e,
|
||||
// the API carries the phase's truth: rw only while dormant, and
|
||||
// a continuation carryover is conversation -- read-only
|
||||
mode: e.source === 'repo' ? 'ro' : (runFile?.mode ?? e.mode),
|
||||
exists: e.source === 'repo' ? true : !!runFile?.exists,
|
||||
content: e.source === 'repo' ? repoPrompts[e.name] : (runFile?.content ?? ''),
|
||||
};
|
||||
fileSpecs[e.name] = spec;
|
||||
const item = el('button', `file-item${e.mode === 'ro' ? ' ro' : ''}${spec.exists ? '' : ' absent'}`);
|
||||
const item = el('button', `file-item${spec.mode === 'ro' ? ' ro' : ''}${spec.exists ? '' : ' absent'}`);
|
||||
item.appendChild(el('span', 'file-name', e.name + (spec.exists ? '' : ' (new)')));
|
||||
item.appendChild(el('span', 'file-dirty', ''));
|
||||
item.addEventListener('click', () => selectFile(e.name));
|
||||
@@ -113,12 +124,14 @@ export async function enter(id, seq) {
|
||||
}
|
||||
|
||||
// the prompts declare their own inputs: every $TOKEN in any prompt
|
||||
// file (repo-fed or run copy) becomes a fillable input in setup
|
||||
// file (repo-fed or the session's own, the carryover included -- it
|
||||
// expands at start like every authored surface) becomes a fillable
|
||||
// input in setup
|
||||
function scanVars(prompts, files) {
|
||||
const texts = [
|
||||
prompts.system, prompts.invariants, prompts.reminder,
|
||||
files['handbook.md']?.content,
|
||||
files['backdrop.md']?.content, files['character.md']?.content, files['turn-0.md']?.content,
|
||||
files['backdrop.md']?.content, files['character.md']?.content, files['carryover.jsonl']?.content,
|
||||
];
|
||||
const found = new Set();
|
||||
for (const t of texts) {
|
||||
@@ -160,7 +173,7 @@ function selectFile(f) {
|
||||
|
||||
// the highlight overlay: known sigils (gold) and every $VAR (green)
|
||||
// light up in place; unknown @-words are the author's own text and
|
||||
// stay plain — @ syntax is not owned here
|
||||
// stay plain -- @ syntax is not owned here
|
||||
const SIGIL_RE = /@(PC|Package)\b/g;
|
||||
const VAR_RE = /\$([A-Za-z_][A-Za-z0-9_]*)/g;
|
||||
function renderHighlight() {
|
||||
@@ -187,7 +200,11 @@ function markNav() {
|
||||
const items = $('setup-files').children;
|
||||
for (const item of items) {
|
||||
const name = item.querySelector('.file-name').textContent.replace(' (new)', '');
|
||||
item.classList.toggle('dirty', drafts[name] !== undefined);
|
||||
const dirty = drafts[name] !== undefined;
|
||||
item.classList.toggle('dirty', dirty);
|
||||
// the dirty marker is authored text, never css-generated -- the
|
||||
// rendered text must match the source (house rule, 2026-11-15)
|
||||
item.querySelector('.file-dirty').textContent = dirty ? '*' : '';
|
||||
item.classList.toggle('current', name === currentFile);
|
||||
}
|
||||
}
|
||||
@@ -221,18 +238,18 @@ async function saveDirty() {
|
||||
markNav();
|
||||
}
|
||||
|
||||
// save the run's craft as a new user package — published to every user
|
||||
// save the run's craft as a new user package -- published to every user
|
||||
// of the deployment, gm.md included. Saves what the run has saved:
|
||||
// drafts flush first. The display name is the save's one decision.
|
||||
async function saveAsPackage() {
|
||||
const name = $('savepkg-name').value.trim();
|
||||
if (!name) return banner('the package needs a display name');
|
||||
$('savepkg-btn').disabled = true;
|
||||
$('savepkg-state').textContent = 'saving…';
|
||||
$('savepkg-state').textContent = 'saving...';
|
||||
try {
|
||||
await saveDirty();
|
||||
const r = await api('/packages', { method: 'POST', body: { from: state.runId, name } });
|
||||
$('savepkg-state').textContent = `saved — ${r.package.id}`;
|
||||
$('savepkg-state').textContent = `saved -- ${r.package.id}`;
|
||||
$('savepkg-name').value = '';
|
||||
} catch (e) {
|
||||
banner(e.message);
|
||||
@@ -244,38 +261,37 @@ async function saveAsPackage() {
|
||||
async function startRun() {
|
||||
const id = state.runId;
|
||||
const btn = $('setup-start');
|
||||
// the prompts' own inputs must be filled — the guard at session-open
|
||||
// is the backstop, not the first line of defense
|
||||
// the prompts' own inputs must be filled -- the guard at start is
|
||||
// the backstop, not the first line of defense
|
||||
for (const [tok, v] of Object.entries(collectVars())) {
|
||||
if (!v) {
|
||||
banner(`$${tok} is unfilled — a prompt declares it, the run needs it`);
|
||||
banner(`$${tok} is unfilled -- a prompt declares it, the run needs it`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
btn.disabled = true;
|
||||
btn.textContent = 'starting…';
|
||||
btn.textContent = 'starting...';
|
||||
try {
|
||||
await saveVars();
|
||||
await saveDirty();
|
||||
} catch (e) {
|
||||
banner(`did not start — ${e.message}`);
|
||||
banner(`did not start -- ${e.message}`);
|
||||
btn.disabled = false;
|
||||
btn.textContent = 'start';
|
||||
return;
|
||||
}
|
||||
let opened = false;
|
||||
try {
|
||||
await api(`/runs/${id}/sessions`, { method: 'POST', body: {} });
|
||||
opened = true;
|
||||
const r = await api(`/runs/${id}/sessions`, { method: 'POST', body: {} });
|
||||
if (r.autoSend) logEvent('nav', 'the carryover ended on a GM turn -- sent automatically as her cue');
|
||||
} catch (e) {
|
||||
banner(e.message);
|
||||
}
|
||||
if (opened && files['turn-0.md']?.exists) {
|
||||
try {
|
||||
await api(`/runs/${id}/turn0`, { method: 'POST', body: {} });
|
||||
} catch (e) {
|
||||
banner(`${e.message} — the beat can be sent from the play view`);
|
||||
if (e.status === 422 && e.detail?.errors) {
|
||||
banner(`the carryover did not pass the start lint:\n${e.detail.errors.join('\n')}`);
|
||||
} else {
|
||||
banner(e.message);
|
||||
}
|
||||
btn.disabled = false;
|
||||
btn.textContent = 'start';
|
||||
return;
|
||||
}
|
||||
navigate(`/runs/${id}`);
|
||||
}
|
||||
@@ -283,7 +299,7 @@ async function startRun() {
|
||||
// --- wiring ---
|
||||
|
||||
// delete this draft: two-click armed (destructive), then home.
|
||||
// A played run refuses server-side — stories are deleted by hand.
|
||||
// A played run refuses server-side -- stories are deleted by hand.
|
||||
armedButton($('setup-delete'), {
|
||||
label: 'delete draft',
|
||||
confirm: 'sure? click again to delete',
|
||||
|
||||
Reference in New Issue
Block a user