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:
+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