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