variant round: roll retired, chance is variant literature (strict parse, crypto pick on reception, picked-only rendering, /story variance metric); entity round: /story the whole deliverable, /table the play projection, the slidwin carry (smart contwin cutoff, whole exchanges, housekeeper reads session-minus-tail); dormant-session rework: universal session lifecycle (dormant->live->finished, sessions/<n> storage), move-at-stop, start lint + auto-send rule, rebaseable housekeeping, turn-0 -> carryover.jsonl, seed -> memory.json, draft-only save-package; format house rules enforced by the nine-rule check-repo (ascii bytes, no text-mutating css); smoke 105/105 + restart + reminder + browser pass green, irene hand-migrated to the new layout
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
// server/carry.mjs -- the slidwin: the migrating live range across
|
||||
// session boundaries.
|
||||
//
|
||||
// At stop, the closing session's tail MOVES into the next dormant
|
||||
// session's carryover -- contiguous raw lines from the end, whole
|
||||
// exchanges, nothing filtered (thinking, notes, draft variants all
|
||||
// ride along; each line exists in exactly one jsonl, ever, no
|
||||
// markers). At start the carryover is consumed into the new log
|
||||
// behind the bundle; the model's view renders it as ordinary history
|
||||
// under the standing policy, so the fresh contwin reads as the old
|
||||
// one continuing and the seam is invisible from inside. The
|
||||
// housekeeper of the closing session reads its log as it was left --
|
||||
// the truncation at stop is the bound -- so the rings never overlap
|
||||
// the carried prose.
|
||||
//
|
||||
// The walk is mechanically dumb while the cutoff is smart: only the
|
||||
// prose the model will see in the new contwin counts against the
|
||||
// budget. Invisible events stay in the carry but cost nothing.
|
||||
|
||||
import { effectiveContents } from './variants.mjs';
|
||||
|
||||
// ~10% of a 256K-class contwin in token terms, grounded on Irene's
|
||||
// session (84KB of turn content at ~23K prompt tokens). Substrate
|
||||
// policy, not deployment taste: a constant, not config.
|
||||
export const CARRY_BUDGET = 96 * 1024;
|
||||
|
||||
const STRIP_BLOCKS = /<(status|agenda|conflict)>[\s\S]*?<\/\1>/g;
|
||||
|
||||
// the prose the model will see for one log line in the new contwin
|
||||
function visibleBytes(lines, eff, i) {
|
||||
const e = lines[i];
|
||||
if (e.t === 'msg') {
|
||||
if (e.reminder) return String(e.m.content ?? '').length;
|
||||
if (e.m.role === 'user' && !e.conflictOnly) {
|
||||
// old GM turns elide their rides in the view
|
||||
return String(e.m.content ?? '').replace(STRIP_BLOCKS, '').length;
|
||||
}
|
||||
if (e.m.role === 'assistant') {
|
||||
// variant turns count only the chosen variant; drafts are
|
||||
// invisible and cost nothing; thinking rides in the message
|
||||
// and never renders
|
||||
const c = eff.has(i) ? eff.get(i) : e.m.content;
|
||||
return String(c ?? '').length;
|
||||
}
|
||||
return 0; // conflict-only traffic elides once the story moves on
|
||||
}
|
||||
if (e.t === 'tool') return String(e.m.content ?? '').length; // conservative: the full result, never the stub
|
||||
return 0; // notes and bundle: machinery, never model prose
|
||||
}
|
||||
|
||||
// The tail's start index: lines[start..] are the carryover, the head
|
||||
// [0..start) stays in the log for the housekeeper. Whole exchanges
|
||||
// from the end, most recent first, added while they fit the budget.
|
||||
// A dangling GM turn (the session stopped before her reply) rides in
|
||||
// the carry whenever any exchange does -- it is contiguous with the
|
||||
// tail and costs nothing -- and that is load-bearing: a carryover
|
||||
// ending on a GM turn auto-sends at start, so the exchange continues
|
||||
// instead of leaving her cue behind in the dead log. When nothing
|
||||
// fits (the degenerate empty tail) it stays behind and files
|
||||
// normally.
|
||||
export function tailStart(lines) {
|
||||
const eff = effectiveContents(lines);
|
||||
const exchanges = [];
|
||||
let i = lines.length - 1;
|
||||
while (i >= 0) {
|
||||
const e = lines[i];
|
||||
if (e.t === 'msg' && e.m?.role === 'assistant' && !e.m.tool_calls?.length) {
|
||||
// the exchange opens at the preceding real GM turn (a
|
||||
// conflict heal belongs to the exchange it healed)
|
||||
let j = i - 1;
|
||||
while (j >= 0) {
|
||||
const u = lines[j];
|
||||
if (u.t === 'msg' && u.m?.role === 'user' && !u.conflictOnly && !u.reminder) break;
|
||||
j--;
|
||||
}
|
||||
if (j >= 0) {
|
||||
exchanges.push([j, i]);
|
||||
i = j;
|
||||
}
|
||||
}
|
||||
i--;
|
||||
}
|
||||
let bytes = 0;
|
||||
let start = lines.length; // the empty tail is a valid degenerate case
|
||||
for (const [a, b] of exchanges) {
|
||||
let cost = 0;
|
||||
for (let k = a; k <= b; k++) cost += visibleBytes(lines, eff, k);
|
||||
if (bytes + cost > CARRY_BUDGET) break;
|
||||
bytes += cost;
|
||||
start = a;
|
||||
}
|
||||
return start;
|
||||
}
|
||||
Reference in New Issue
Block a user