gm surface: home flow, run identity, full-assembly editor, notepad, wrap replay; sigils and dateless rings
This commit is contained in:
+23
-1
@@ -7,8 +7,10 @@
|
||||
// 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.
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { clerkJson } from './clerk.mjs';
|
||||
import { toolList, runTool, readSettings } from './bundle.mjs';
|
||||
import { toolList, runTool, readSettings, runDir, expandVars } from './bundle.mjs';
|
||||
import { renderView } from './session.mjs';
|
||||
|
||||
export class HttpError extends Error {
|
||||
@@ -38,6 +40,26 @@ export async function gmTurn(ctx, runId, line) {
|
||||
return runLoop(ctx, runId);
|
||||
}
|
||||
|
||||
// the opening beat: turn-0 sent as the first GM turn, separate from
|
||||
// the bundle (start = open window, then this). Its trailing <status>
|
||||
// block was ingested as her opening paper at window-open — stripped
|
||||
// here, since the normal ride carries the current paper on every GM
|
||||
// turn, the beat included.
|
||||
export async function turn0(ctx, runId) {
|
||||
const s = needSession(ctx, runId);
|
||||
if (s.pendingAsk) throw new HttpError(409, 'a question is pending — answer it first (POST /ask)');
|
||||
if (!s.fresh) throw new HttpError(409, 'turn-0 opens a fresh run only');
|
||||
if (s.lines.some((e) => e.t === 'msg' && e.m.role === 'user')) {
|
||||
throw new HttpError(409, 'a GM line already exists — the opening beat was sent, or the GM spoke first');
|
||||
}
|
||||
const file = path.join(runDir(runId), 'turn-0.md');
|
||||
if (!fs.existsSync(file)) throw new HttpError(404, 'this run has no turn-0.md — narrate the opening yourself (POST /turn)');
|
||||
let text = expandVars(runId, fs.readFileSync(file, 'utf8')); // $NAME tokens resolve like every bundle file
|
||||
const sm = text.match(/<status>[\s\S]*?<\/status>/);
|
||||
if (sm) text = text.replace(sm[0], '');
|
||||
return gmTurn(ctx, runId, text.trim());
|
||||
}
|
||||
|
||||
export async function answerAsk(ctx, runId, answer) {
|
||||
const s = needSession(ctx, runId);
|
||||
if (!s.pendingAsk) throw new HttpError(409, 'no pending question');
|
||||
|
||||
Reference in New Issue
Block a user