gm-input expansion built from the roadmap (DECISIONS #9's strictness ruling): the GM's line and ask answers expand at ingestion -- @PC/@Package and $vars resolve before the log, an unresolved token refuses the turn with a 400 naming it and nothing appended; the log records the expanded line, keeping continuation carryovers expansion-free by construction; smoke +4 (the $Bogus refusal, the log provably unchanged, a live sigil turn, the expanded line in the log) -- 115/115 all pass; the GM input gains a highlight overlay (the setup editor's stack pattern transplanted): *italics* render italic, **bold** renders bold, @PC/@Package gold, $vars green, every character kept on screen (the asterisks too) so the caret never desyncs, bold/italics matched per-line like the transcript renderer; the box rekeys -- Enter is a plain newline, Ctrl+Space sends, placeholder updated; and a pre-existing bug the live pass caught: failed-action banners were wiped by the render() that follows every action (the runGone trap) -- sendTurn, sendAnswer, and startRun now set the banner after the render; browser-proven end to end: tokens highlight in place, Enter newlines, the refusal loop shows the banner and restores the line un-eaten and still highlighted, the sigil expands in the log, zero console errors; the roadmap item struck as built, DECISIONS #9 amended to same-day-built, README's substitution paragraph and AGENTS' identity-model bullet carry the live-input rule; typecheck green on both programs, check-repo clean
This commit is contained in:
@@ -287,7 +287,7 @@ memory the agent owes itself across sessions.
|
||||
staged or the lint dies on the ghost; the README layout section
|
||||
lives inside a code fence with its own deeper indent -- byte-dump,
|
||||
the read display lies about depth there too. Deferred to ROADMAP:
|
||||
GM-input expansion, save-as-package beyond drafts, the carryover
|
||||
save-as-package beyond drafts, the carryover
|
||||
editor. The lint's blind side (bitten 2026-11-15, commit round): it
|
||||
reads the git INDEX, so UNTRACKED files are invisible to it -- "ALL
|
||||
CLEAN" before a commit does not cover never-staged files, and the
|
||||
@@ -373,7 +373,10 @@ memory the agent owes itself across sessions.
|
||||
(settings pc/name); $TOKENs are prompt-declared template vars
|
||||
(setup inputs -> settings vars). Run ids are anonymous hex --
|
||||
display is always "Package / PC". Any new prompt-side file reader
|
||||
goes through expandVars.
|
||||
goes through expandVars. GM input expands at ingestion too
|
||||
(2026-11-15, DECISIONS #9: strict everywhere, a refused line hands
|
||||
back un-eaten, the log records the expanded line -- continuation
|
||||
carryovers stay expansion-free forever).
|
||||
- Exposure rule (GM, 2026-11-14): everything that enters the bundle
|
||||
is inspectable read-only in the SPA (system.md, invariants.md, the
|
||||
assembled system message in the bundle card); anything that prompts
|
||||
@@ -400,8 +403,8 @@ memory the agent owes itself across sessions.
|
||||
into the server loop.
|
||||
- Open decisions live in QUESTIONS.md -- read it first; the resolved
|
||||
record is DECISIONS.md (the old queue, kept by number). QUESTIONS is
|
||||
open items only now (2026-11-15 split). Remaining: #9 (expandVars
|
||||
strictness), #16 (which model the housekeeper defaults to), #19c
|
||||
open items only now (2026-11-15 split). Remaining: #16 (which model
|
||||
the housekeeper defaults to), #19c
|
||||
(seed voice, GM may revisit -- non-blocking), and the turn-surgery
|
||||
build details.
|
||||
- The tree is usually dirty by design; git status is not an alarm.
|
||||
|
||||
@@ -234,6 +234,19 @@ pen). Absent/empty file = no ride. The reminder is now the experiment:
|
||||
|
||||
## Small / non-blocking
|
||||
|
||||
### 9. Unresolved-token check in expandVars -- RESOLVED (2026-11-15, GM)
|
||||
Added beyond the literal ask: any leftover `$WORD` after substitution
|
||||
fails loudly. Keep, or relax to silent pass-through? (2026-11-12)
|
||||
|
||||
Resolution: strict, everywhere -- the authored carryover's start
|
||||
lint, and live GM input at ingestion (GM-input expansion, built the
|
||||
same day: expansion errors refuse the turn, the failed line is
|
||||
handed back to the GM un-eaten). No silent pass-through anywhere;
|
||||
the model never sees a raw var. What makes strict affordable is the
|
||||
failure UX, ruled with it: the refused prose comes back for editing
|
||||
and resubmit -- the SPA's send path already practiced exactly this
|
||||
for failed sends.
|
||||
|
||||
### 10. Orphan tool messages are silently tolerated -- RESOLVED BY DEFAULT (2026-11-13)
|
||||
Probe finding: a tool result without a preceding tool_calls is accepted
|
||||
by the endpoint and simply ignored -- a desynced pairing won't 400. Should
|
||||
|
||||
+1
-4
@@ -11,13 +11,10 @@ DICTIONARY.md, or the prompts. Tiered by urgency, FIFO within a tier.
|
||||
- calibration package: escape room
|
||||
- calibration package: the detention
|
||||
- user manual
|
||||
- session rewind
|
||||
|
||||
## Open
|
||||
|
||||
### 9. Unresolved-token check in expandVars -- OPEN
|
||||
Added beyond the literal ask: any leftover `$WORD` after substitution
|
||||
fails loudly. Keep, or relax to silent pass-through? (2026-11-12)
|
||||
|
||||
### 16. Housekeeping model configuration -- OPEN (mechanism settled)
|
||||
The housekeeping job runs server-side on a fresh model invocation.
|
||||
Mechanism settled (2026-11-13): `server.json` names one endpoint plus
|
||||
|
||||
@@ -224,7 +224,10 @@ consumes into the log, in one action.
|
||||
holds the answers (a package may ship defaults). Unresolved
|
||||
sigils-of-ours and vars fail loudly before anything is sent; any
|
||||
other `@`-word is the author's own text -- `@` syntax is not owned
|
||||
here -- and passes through untouched. The server
|
||||
here -- and passes through untouched. The GM's live input expands
|
||||
the same way at ingestion: the line resolves before it is logged,
|
||||
an unresolved token refuses the turn, and the line is handed
|
||||
back for editing. The server
|
||||
assembles and logs all of this automatically (until it lands:
|
||||
manual relay).
|
||||
3. **In play:** a line opening with `(` is the out-of-character channel --
|
||||
|
||||
@@ -505,12 +505,6 @@ duplicate handbook cut is the GM's red pen).
|
||||
|
||||
## Deferred tasks (ruled out of the dormant-session rework, 2026-11-15)
|
||||
|
||||
- **GM-input expansion.** Expand sigils (@PC/@Package) and $vars on
|
||||
the GM's input at ingestion, before the turn is sent up; expansion
|
||||
errors refuse the turn; the log records the expanded line (which is
|
||||
what makes continuation carryovers forever expansion-free). Deferred
|
||||
to keep the rework's scope tight; the authored session-1 carryover
|
||||
keeps expansion-at-start in the meantime.
|
||||
- **Save-as-package beyond drafts.** Today it fires only from
|
||||
never-started runs. Opening it to any dormancy raises unanswered
|
||||
questions: which carryover rides (the dormant session's story tail
|
||||
|
||||
+25
-4
@@ -6,14 +6,17 @@
|
||||
// answer call resumes the loop. The status is re-read from the clerk
|
||||
// before every GM turn and rides it as a <status> block; the player's
|
||||
// <lost>/<gained> deltas apply after its final message, and any
|
||||
// conflicts ride the next GM turn as a <conflict> block.
|
||||
// conflicts ride the next GM turn as a <conflict> block. GM input
|
||||
// expands at ingestion (strict, DECISIONS #9): @PC/@Package and $vars
|
||||
// resolve before the line is logged; an expansion error refuses the
|
||||
// turn and the line is handed back for editing.
|
||||
/** @typedef {import('./shapes.mjs').Ctx} Ctx */
|
||||
/** @typedef {import('./shapes.mjs').LiveSession} LiveSession */
|
||||
/** @typedef {import('./shapes.mjs').Actor} Actor */
|
||||
/** @typedef {import('./shapes.mjs').ViewMessage} ViewMessage */
|
||||
|
||||
import { clerkJson } from './clerk.mjs';
|
||||
import { toolList, runTool, assembleReminder } from './bundle.mjs';
|
||||
import { toolList, runTool, assembleReminder, expandVars } from './bundle.mjs';
|
||||
import { renderView } from './session.mjs';
|
||||
import { parseVariants, pickVariant } from './variants.mjs';
|
||||
|
||||
@@ -45,11 +48,21 @@ function needSession(ctx, runId) {
|
||||
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)');
|
||||
// GM-input expansion (strict, DECISIONS #9): the line resolves at
|
||||
// ingestion -- the log records the expanded words, which is what
|
||||
// keeps continuation carryovers expansion-free forever. A refused
|
||||
// turn appends nothing: the client hands the line back for editing.
|
||||
let prose;
|
||||
try {
|
||||
prose = expandVars(runId, line.trim());
|
||||
} catch (e) {
|
||||
throw new HttpError(400, `the line was not sent -- ${e.message}`);
|
||||
}
|
||||
const status = /** @type {string[]} */ (clerkJson(runId, 'status')); // fresh per turn
|
||||
const agenda = /** @type {string[]} */ (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>${status.join(', ')}</status>\n<agenda>${agendaWire}</agenda>`;
|
||||
const content = `${prose}\n\n<status>${status.join(', ')}</status>\n<agenda>${agendaWire}</agenda>`;
|
||||
s.append({ t: 'msg', m: { role: 'user', content } });
|
||||
// the reminder follows the GM's prose as its own system chunk --
|
||||
// every turn, one live copy (older ones elide in the view)
|
||||
@@ -76,11 +89,19 @@ export async function openingCall(ctx, runId, user) {
|
||||
export async function answerAsk(ctx, runId, answer, user) {
|
||||
const s = needSession(ctx, runId);
|
||||
if (!s.pendingAsk) throw new HttpError(409, 'no pending question');
|
||||
// the answer is GM input: same strict expansion, same hand-back --
|
||||
// a refusal leaves the pending question untouched
|
||||
let resolved;
|
||||
try {
|
||||
resolved = expandVars(runId, answer.trim());
|
||||
} catch (e) {
|
||||
throw new HttpError(400, `the answer was not sent -- ${e.message}`);
|
||||
}
|
||||
// execute the paused batch: the ask gets the answer, its siblings
|
||||
// (if any) get dispatched now -- pairing stays whole
|
||||
for (const call of s.pendingAsk.calls) {
|
||||
if (call.id === s.pendingAsk.callId) {
|
||||
s.append({ t: 'tool', ask: true, m: { role: 'tool', tool_call_id: call.id, content: answer } });
|
||||
s.append({ t: 'tool', ask: true, m: { role: 'tool', tool_call_id: call.id, content: resolved } });
|
||||
} else {
|
||||
s.append({ t: 'tool', m: { role: 'tool', tool_call_id: call.id, content: runTool(runId, call) } });
|
||||
}
|
||||
|
||||
@@ -372,6 +372,19 @@ ok('start session 4 after the fix', r.status === 200 && r.data.session === 4, r.
|
||||
r = await call('/packages', { method: 'POST', token: op, body: { from: runId, name: 'Nope' } });
|
||||
ok('save-package refuses a played run', r.status === 400 && /draft act/.test(r.data.error), r.data.error ?? '');
|
||||
|
||||
// 22. GM-input expansion: strict at ingestion, the refused line hands back
|
||||
r = await call(`/runs/${runId}/session`, { token: op });
|
||||
const beforeCount = r.data.entries.length;
|
||||
r = await call(`/runs/${runId}/turn`, { method: 'POST', token: op, body: { line: 'she mutters $Bogus under her breath' } });
|
||||
ok('an unresolved $var refuses the turn', r.status === 400 && /unresolved token/.test(r.data.error), r.data.error ?? '');
|
||||
r = await call(`/runs/${runId}/session`, { token: op });
|
||||
ok('the refused line never landed', r.data.entries.length === beforeCount, `${beforeCount} -> ${r.data.entries.length}`);
|
||||
r = await call(`/runs/${runId}/turn`, { method: 'POST', token: op, body: { line: '*She says her own name out loud: @PC.*' } });
|
||||
ok('a live turn with a sigil sends', r.status === 200, r.data.error ?? '');
|
||||
r = await call(`/runs/${runId}/session`, { token: op });
|
||||
const liveGm = [...r.data.entries].reverse().find((e) => e.t === 'msg' && e.m.role === 'user' && !e.conflictOnly);
|
||||
ok('the log records the expanded line', /name out loud: Smokina/.test(String(liveGm?.m.content ?? '')) && !/@PC\b/.test(String(liveGm?.m.content ?? '')), String(liveGm?.m.content ?? '').slice(0, 90));
|
||||
|
||||
console.log(`\nrun ids: source=${runId} fork=${forkId} second=${secondId} refork=${reforkId}`);
|
||||
writeFileSync(TOKEN_FILE, `${op} ${reforkId} ${secondId}`);
|
||||
console.log(failures ? `\n${failures} FAILURES` : '\nALL PASS');
|
||||
|
||||
+4
-1
@@ -162,7 +162,10 @@
|
||||
</aside>
|
||||
|
||||
<footer>
|
||||
<textarea id="gm-input" rows="2" placeholder="GM line -- Enter sends, Shift+Enter newlines" disabled></textarea>
|
||||
<div id="gm-stack">
|
||||
<pre id="gm-hl" aria-hidden="true"></pre>
|
||||
<textarea id="gm-input" rows="2" placeholder="GM line -- Ctrl+Space sends" disabled></textarea>
|
||||
</div>
|
||||
<span id="busy" hidden>her turn...</span>
|
||||
<button id="gm-send" disabled>send</button>
|
||||
</footer>
|
||||
|
||||
+24
-1
@@ -393,7 +393,30 @@ footer {
|
||||
display: none;
|
||||
}
|
||||
body.play footer { display: flex; }
|
||||
#gm-input { flex: 1; resize: none; }
|
||||
#gm-stack { position: relative; flex: 1; display: grid; min-width: 0; }
|
||||
#gm-stack.off { opacity: 0.4; }
|
||||
/* the highlight overlay: the setup editor's stack pattern -- a pre
|
||||
behind a transparent-text textarea, identical metrics, so the
|
||||
tokens light up in place without moving the caret */
|
||||
#gm-hl, #gm-input {
|
||||
grid-area: 1 / 1;
|
||||
margin: 0;
|
||||
padding: 5px 8px;
|
||||
font: inherit;
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: break-word;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 4px;
|
||||
}
|
||||
#gm-hl { pointer-events: none; overflow: hidden; color: var(--text); border-color: transparent; background: transparent; }
|
||||
#gm-input {
|
||||
background: transparent;
|
||||
color: transparent;
|
||||
caret-color: var(--text);
|
||||
resize: none;
|
||||
overflow-y: auto;
|
||||
}
|
||||
#gm-input::placeholder { color: var(--dim); }
|
||||
#gm-send { padding: 5px 18px; }
|
||||
#busy { color: var(--dim); font-size: 12px; font-style: italic; white-space: nowrap; align-self: center; }
|
||||
|
||||
|
||||
+43
-7
@@ -146,7 +146,7 @@ async function refreshPlay(id, seq) {
|
||||
$('hk-replay').hidden = !((detail.phase === 'live') || (detail.phase === 'dormant' && detail.sessions >= 2));
|
||||
$('hk-override-row').hidden = !(detail.phase === 'dormant' && detail.ready === false);
|
||||
setInput(detail.phase === 'live' && !detail.pendingAsk);
|
||||
/** @type {HTMLInputElement} */ ($('gm-input')).placeholder = 'GM line -- Enter sends, Shift+Enter newlines';
|
||||
/** @type {HTMLInputElement} */ ($('gm-input')).placeholder = 'GM line -- Ctrl+Space sends';
|
||||
|
||||
// models: the owner's per-run overrides
|
||||
$('models-pane').hidden = false;
|
||||
@@ -241,21 +241,25 @@ async function startRun() {
|
||||
const override = /** @type {HTMLInputElement} */ ($('hk-override')).checked;
|
||||
hideBanner();
|
||||
setBusy(true, 'starting...');
|
||||
/** @type {?string} */ let failed = null;
|
||||
let failedCls = undefined;
|
||||
try {
|
||||
const r = await api(`/runs/${state.runId}/sessions`, { method: 'POST', body: { override } });
|
||||
/** @type {HTMLInputElement} */ ($('hk-override')).checked = false;
|
||||
if (r.autoSend) logEvent('nav', 'the carryover ended on a GM turn -- sent automatically as her cue');
|
||||
} catch (e) {
|
||||
if (e.status === 409 && e.detail?.hint) {
|
||||
banner(`${e.message}\n${e.detail.hint}`, 'info');
|
||||
failed = `${e.message}\n${e.detail.hint}`;
|
||||
failedCls = 'info';
|
||||
} else if (e.status === 422 && e.detail?.errors) {
|
||||
banner(`the carryover did not pass the start lint:\n${e.detail.errors.join('\n')}`);
|
||||
failed = `the carryover did not pass the start lint:\n${e.detail.errors.join('\n')}`;
|
||||
} else {
|
||||
banner(e.message);
|
||||
failed = e.message;
|
||||
}
|
||||
}
|
||||
setBusy(false);
|
||||
render();
|
||||
if (failed) banner(failed, failedCls); // render() clears the banner -- set it after
|
||||
}
|
||||
|
||||
/** @param {string} stateText @param {?string} [cls] */
|
||||
@@ -289,6 +293,7 @@ function renderHk(hk) {
|
||||
function setInput(ok) {
|
||||
/** @type {HTMLInputElement} */ ($('gm-input')).disabled = !ok;
|
||||
/** @type {HTMLButtonElement} */ ($('gm-send')).disabled = !ok;
|
||||
$('gm-stack').classList.toggle('off', !ok); // the overlay dims with the box
|
||||
}
|
||||
|
||||
// --- actions -----------------------------------------------------------
|
||||
@@ -298,16 +303,20 @@ async function sendTurn() {
|
||||
const line = /** @type {HTMLInputElement} */ ($('gm-input')).value.trim();
|
||||
if (!line || !state.runId) return;
|
||||
/** @type {HTMLInputElement} */ ($('gm-input')).value = '';
|
||||
renderInputHl();
|
||||
setInput(false);
|
||||
setBusy(true);
|
||||
let failed = null;
|
||||
try {
|
||||
await api(`/runs/${state.runId}/turn`, { method: 'POST', body: { line } });
|
||||
} catch (e) {
|
||||
banner(e.message);
|
||||
failed = e.message;
|
||||
/** @type {HTMLInputElement} */ ($('gm-input')).value = line; // a failed send must not eat the line
|
||||
renderInputHl();
|
||||
}
|
||||
setBusy(false);
|
||||
render();
|
||||
if (failed) banner(failed); // render() clears the banner -- set it after (the runGone lesson)
|
||||
}
|
||||
|
||||
/** @returns {Promise<void>} */
|
||||
@@ -316,14 +325,16 @@ async function sendAnswer() {
|
||||
if (!answer || !state.runId) return;
|
||||
/** @type {HTMLInputElement} */ ($('ask-answer')).value = '';
|
||||
setBusy(true);
|
||||
let failed = null;
|
||||
try {
|
||||
await api(`/runs/${state.runId}/ask`, { method: 'POST', body: { answer } });
|
||||
} catch (e) {
|
||||
banner(e.message);
|
||||
failed = e.message;
|
||||
/** @type {HTMLInputElement} */ ($('ask-answer')).value = answer;
|
||||
}
|
||||
setBusy(false);
|
||||
render();
|
||||
if (failed) banner(failed); // render() clears the banner -- set it after
|
||||
}
|
||||
|
||||
// fork: a copy of this run under you -- any run, anyone's, including
|
||||
@@ -427,9 +438,34 @@ armedButton($('hk-rerun'), {
|
||||
});
|
||||
|
||||
$('gm-send').addEventListener('click', sendTurn);
|
||||
// the GM input: Enter is a plain newline, Ctrl+Space sends (the
|
||||
// button rides for mouse days)
|
||||
$('gm-input').addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); sendTurn(); }
|
||||
if (e.key === ' ' && e.ctrlKey) { e.preventDefault(); sendTurn(); }
|
||||
});
|
||||
|
||||
// the GM input's highlight overlay: the setup editor's stack pattern
|
||||
// -- the pre behind a transparent-text textarea renders the tokens in
|
||||
// place. Every character stays (the asterisks too) so the caret never
|
||||
// desyncs from the visible glyphs: italics and bold style their whole
|
||||
// token, sigils and vars color theirs
|
||||
const SIGIL_RE = /@(PC|Package)\b/g;
|
||||
const VAR_RE = /\$([A-Za-z_][A-Za-z0-9_]*)/g;
|
||||
function renderInputHl() {
|
||||
const ta = /** @type {HTMLTextAreaElement} */ ($('gm-input'));
|
||||
const hl = $('gm-hl');
|
||||
const esc = ta.value.replace(/[&<>]/g, (c) => /** @type {Record<string, string>} */ ({ '&': '&', '<': '<', '>': '>' })[c]);
|
||||
// per-line tokens, matching the transcript's renderer: bold and
|
||||
// italics never span lines
|
||||
hl.innerHTML = esc
|
||||
.replace(/(\*\*[^*\n]+\*\*|\*[^*\n]+\*)/g, (m) => (m.startsWith('**') ? `<strong>${m}</strong>` : `<em>${m}</em>`))
|
||||
.replace(VAR_RE, '<span class="tok-var">$&</span>')
|
||||
.replace(SIGIL_RE, '<span class="tok-sigil">$&</span>');
|
||||
hl.scrollTop = ta.scrollTop;
|
||||
hl.scrollLeft = ta.scrollLeft;
|
||||
}
|
||||
$('gm-input').addEventListener('input', renderInputHl);
|
||||
$('gm-input').addEventListener('scroll', renderInputHl);
|
||||
$('ask-send').addEventListener('click', sendAnswer);
|
||||
$('ask-answer').addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); sendAnswer(); }
|
||||
|
||||
Reference in New Issue
Block a user