gm surface: home flow, run identity, full-assembly editor, notepad, wrap replay; sigils and dateless rings
This commit is contained in:
+36
-8
@@ -5,8 +5,8 @@
|
||||
// The bundle rides as GM messages (user role), one per file: backdrop,
|
||||
// character, ring-b, ring-a — identity first, then memory, ring A in
|
||||
// the recency slot; turn-0 opens a fresh run before the GM's first
|
||||
// line. $NAME tokens resolve from the run's settings.json "vars" and
|
||||
// fail loudly when unresolved — the model never sees a raw $NAME.
|
||||
// line. Substitution resolves before sending — the model never sees a
|
||||
// raw sigil.
|
||||
//
|
||||
// The tool list is the capability surface: roll and ask_gm always,
|
||||
// records verbs only when the run's settings allow.
|
||||
@@ -43,13 +43,33 @@ export function readSettings(runId) {
|
||||
}
|
||||
}
|
||||
|
||||
// Substitution has two classes. @ sigils are identity — @PC (the
|
||||
// character's name, settings "pc") and @Package (the display name,
|
||||
// settings "name") — first-class, never user-fillable; these two are
|
||||
// ours, and an unresolved one fails loudly. Any other @-word is the
|
||||
// author's own text — @ syntax is not owned here, users may find
|
||||
// other uses for it — and passes through untouched. $TOKENS are
|
||||
// template vars, declared by the prompts themselves: any $TOKEN found
|
||||
// in a prompt surfaces as an input in setup, and the run's settings
|
||||
// "vars" holds the answers (a package may ship defaults); an
|
||||
// unresolved $TOKEN fails loudly — the model never sees a raw var.
|
||||
function expandVars(runId, s) {
|
||||
const vars = readSettings(runId).vars ?? {};
|
||||
const settings = readSettings(runId);
|
||||
let out = String(s ?? '');
|
||||
for (const [k, v] of Object.entries(vars)) out = out.replaceAll(`$${k}`, String(v));
|
||||
const sigils = { PC: settings.pc, Package: settings.name };
|
||||
out = out.replace(/@(PC|Package)\b/g, (full, name) => {
|
||||
const v = sigils[name];
|
||||
if (v == null || !String(v).trim()) {
|
||||
const err = new Error(`unresolved @${name} — it must be set in the run's settings.json`);
|
||||
err.status = 500;
|
||||
throw err;
|
||||
}
|
||||
return String(v);
|
||||
});
|
||||
for (const [k, v] of Object.entries(settings.vars ?? {})) out = out.replaceAll(`$${k}`, String(v));
|
||||
const unresolved = [...new Set([...out.matchAll(/\$([A-Za-z][A-Za-z0-9_]*)/g)].map((m) => `$${m[1]}`))];
|
||||
if (unresolved.length) {
|
||||
const err = new Error(`unresolved token(s): ${unresolved.join(', ')} — declare them in the run's settings.json "vars"`);
|
||||
const err = new Error(`unresolved token(s): ${unresolved.join(', ')} — fill them in setup; they save to the run's settings.json "vars"`);
|
||||
err.status = 500;
|
||||
throw err;
|
||||
}
|
||||
@@ -57,6 +77,14 @@ function expandVars(runId, s) {
|
||||
}
|
||||
export { expandVars };
|
||||
|
||||
// "La Caramba / Rell" — the run's display name; the anonymous id
|
||||
// never surfaces as a name
|
||||
export function runDisplay(runId) {
|
||||
const s = readSettings(runId);
|
||||
const pkg = runMeta(runId)?.package ?? '?';
|
||||
return s.pc ? `${s.name ?? pkg} / ${s.pc}` : (s.name ?? pkg);
|
||||
}
|
||||
|
||||
const read = (p) => {
|
||||
if (!fs.existsSync(p)) {
|
||||
const err = new Error(`missing bundle file: ${path.relative(ROOT, p)}`);
|
||||
@@ -74,8 +102,9 @@ export function assembleSystem(runId) {
|
||||
return expandVars(runId, [system, invariants, handbook].join('\n\n'));
|
||||
}
|
||||
|
||||
// the bundle: GM messages, one per file. turn-0 only on a fresh run.
|
||||
export function assembleBundle(runId, fresh) {
|
||||
// the bundle: GM messages, one per file. turn-0 never rides it — the
|
||||
// opening beat is a GM turn (sent on start), not context.
|
||||
export function assembleBundle(runId) {
|
||||
const d = runDir(runId);
|
||||
const files = [
|
||||
{ role: 'user', path: path.join(d, 'backdrop.md') },
|
||||
@@ -83,7 +112,6 @@ export function assembleBundle(runId, fresh) {
|
||||
{ role: 'user', path: path.join(d, 'canon', 'ring-b.md') },
|
||||
{ role: 'user', path: path.join(d, 'canon', 'ring-a.md') },
|
||||
];
|
||||
if (fresh) files.push({ role: 'user', path: path.join(d, 'turn-0.md') });
|
||||
return files.map((f) => ({ role: f.role, content: expandVars(runId, read(f.path)) }));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user