per-turn reminder: turn-composition protocol as its own system chunk after every GM turn, one live copy elided like the papers; handbook cut follows (short turns)
This commit is contained in:
@@ -102,6 +102,18 @@ export function assembleSystem(runId) {
|
||||
return expandVars(runId, [system, invariants, handbook].join('\n\n'));
|
||||
}
|
||||
|
||||
// the per-turn reminder: the small turn-composition protocol, repo-
|
||||
// shared (never copied into a run), sent after the GM's prose as its
|
||||
// own system chunk every turn. Older copies elide from the view, so
|
||||
// exactly one lives at the freshest position (ROADMAP steal #11).
|
||||
// Absent or empty file = no ride; the feature sleeps until written.
|
||||
export function assembleReminder(runId) {
|
||||
const p = path.join(ROOT, 'reminder.md');
|
||||
if (!fs.existsSync(p)) return null;
|
||||
const text = fs.readFileSync(p, 'utf8').trim();
|
||||
return text ? expandVars(runId, text) : null;
|
||||
}
|
||||
|
||||
// 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) {
|
||||
|
||||
@@ -31,6 +31,7 @@ export function renderTranscript(lines) {
|
||||
const L = [];
|
||||
for (const e of lines) {
|
||||
if (e.t === 'bundle') continue; // context, not exchange — provided as separate inputs
|
||||
if (e.t === 'msg' && e.reminder) continue; // identical every turn — context, not exchange
|
||||
if (e.t === 'msg') {
|
||||
if (e.m.role === 'user' && e.conflictOnly) {
|
||||
L.push('[conflict — answered in-band]', e.m.content.replace(/<\/?conflict>/g, '').trim(), '');
|
||||
|
||||
+5
-1
@@ -10,7 +10,7 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { clerkJson } from './clerk.mjs';
|
||||
import { toolList, runTool, readSettings, runDir, expandVars } from './bundle.mjs';
|
||||
import { toolList, runTool, readSettings, runDir, expandVars, assembleReminder } from './bundle.mjs';
|
||||
import { renderView } from './session.mjs';
|
||||
|
||||
export class HttpError extends Error {
|
||||
@@ -36,6 +36,10 @@ export async function gmTurn(ctx, runId, line, user) {
|
||||
const agendaWire = agenda.map((d, i) => `${i}. ${d}`).join('; ');
|
||||
const content = `${line.trim()}\n\n<status>${paper.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)
|
||||
const reminder = assembleReminder(runId);
|
||||
if (reminder) s.append({ t: 'msg', m: { role: 'system', content: reminder }, reminder: true });
|
||||
return runLoop(ctx, runId, user);
|
||||
}
|
||||
|
||||
|
||||
+11
-7
@@ -267,13 +267,17 @@ route('POST', '/api/packages', async ({ body, user }) => {
|
||||
return { package: JSON.parse(r.out) };
|
||||
});
|
||||
|
||||
// the repo-fed prompts, read-only: per-project opening + guards and
|
||||
// substrate invariants — never copied into a run, so the editor shows
|
||||
// them as context, not as something to edit
|
||||
route('GET', '/api/prompts', async () => ({
|
||||
system: fs.readFileSync(path.join(ROOT, 'system.md'), 'utf8').trim(),
|
||||
invariants: fs.readFileSync(path.join(ROOT, 'invariants.md'), 'utf8').trim(),
|
||||
}));
|
||||
// the repo-fed prompts, read-only: per-project opening + guards,
|
||||
// substrate invariants, and the per-turn reminder — never copied into
|
||||
// a run, so the editor shows them as context, not as something to edit
|
||||
route('GET', '/api/prompts', async () => {
|
||||
const readOpt = (f) => (fs.existsSync(path.join(ROOT, f)) ? fs.readFileSync(path.join(ROOT, f), 'utf8').trim() : null);
|
||||
return {
|
||||
system: readOpt('system.md'),
|
||||
invariants: readOpt('invariants.md'),
|
||||
reminder: readOpt('reminder.md'),
|
||||
};
|
||||
});
|
||||
|
||||
// the clerk's list, enriched with what the server already knows: the
|
||||
// open window, the pending ask, and the housekeeping bookkeeping. A
|
||||
|
||||
+9
-1
@@ -165,18 +165,26 @@ const STRIP_BLOCKS = /\n?<(status|conflict|agenda)>[\s\S]*?<\/\1>\n?/g;
|
||||
|
||||
export function renderView(s, keepToolResults = 4) {
|
||||
const toolIdx = [];
|
||||
const reminderIdx = [];
|
||||
let lastGmIdx = -1;
|
||||
s.lines.forEach((e, i) => {
|
||||
if (e.t === 'tool') toolIdx.push(i);
|
||||
if (e.t === 'msg' && e.m.role === 'user') lastGmIdx = i;
|
||||
if (e.t === 'msg' && e.reminder) reminderIdx.push(i);
|
||||
});
|
||||
const keep = new Set(toolIdx.slice(-keepToolResults));
|
||||
const newestReminder = reminderIdx.length ? reminderIdx[reminderIdx.length - 1] : -1;
|
||||
const msgs = [];
|
||||
for (const [i, e] of s.lines.entries()) {
|
||||
if (e.t === 'bundle') {
|
||||
msgs.push({ role: e.m.role, content: e.m.content });
|
||||
} else if (e.t === 'msg') {
|
||||
if (e.m.role === 'assistant') {
|
||||
if (e.reminder) {
|
||||
// the per-turn reminder: only the newest copy lives in the
|
||||
// context — superseded ones elide (identical content, freshest
|
||||
// position, exactly like the papers)
|
||||
if (i === newestReminder) msgs.push({ role: 'system', content: e.m.content.trim() });
|
||||
} else if (e.m.role === 'assistant') {
|
||||
// thinking never goes back; the log keeps it
|
||||
const m = { role: 'assistant', content: e.m.content ?? null };
|
||||
if (e.m.tool_calls?.length) m.tool_calls = e.m.tool_calls;
|
||||
|
||||
Reference in New Issue
Block a user