commit e8bab6bc627a1bca591de9e4f862f75607244410
parent 49c7c02ccd62715d532f6d7023415e8921594c50
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Fri, 16 Oct 2026 01:41:15 -0400
common: the frame derivation's highlight events, each by a named rule with its evidence and a confidence — hero pots (`log-pot`: BIG_POT_BB = 25 named, a pot line read again within three minutes at a size within 1% is one pot, `confirmed` when the kept stack after it is above the stack before), all-ins (`all-in`: the hero's in the log or the action text, or an unnamed one / the model's banner only with the hero's cards shown and the stack read 0; one per minute; the outcome — doubled, won, lost, busted, unclear, unknown — from the kept stack within ALL_IN_OUTCOME_WINDOW_S, flagged points left out), level-ups (`log-blinds`: each new big blind once per tournament, a logged line a later one undercuts is a misread and makes no event and is set aside in the big-blind series too; "INFO"/"Dealer:" prefixes read), and players-left milestones (`players-left-milestone`: PLAYERS_LEFT_MILESTONES 100/50/27/18 and FINAL_TABLE, once each per tournament, at the first kept unflagged point after the LAST point over it, the lowest when one point crosses several); the model's all-in banner is no longer an event on its own; the test kit's syntheticPokerHighlights
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
8 files changed, 478 insertions(+), 21 deletions(-)
diff --git a/common/lib/frames/poker.test.ts b/common/lib/frames/poker.test.ts
@@ -108,8 +108,13 @@ test("a win: one player left and the hero with chips", () => {
});
test("frame events are one per run: the same banner for a minute is one moment", () => {
- const d = derive([table(0, 1000, {}, { event: "all-in" }), table(10, 1000, {}, { event: "all-in" }), table(100, 1000, {}, { event: "all-in" })]);
+ // Release 31: an all-in banner is the hero's only with the hero's chips in
+ // the middle (the cards shown, the stack read 0); with chips in front of
+ // the hero it is another player's shove.
+ const shove = (t: number): R => ({ t, phase: "table", hero: { stack: 0, cards: ["As", "Kd"] }, event: "all-in" });
+ const d = derive([table(-10, 1000), shove(0), shove(10), table(20, 1000), shove(100), table(110, 1000), table(120, 1000, {}, { event: "all-in" })]);
assert.deepEqual(d.events.filter((e) => e.kind === "all-in").map((e) => e.t), [0, 100]);
+ assert.deepEqual(d.events.filter((e) => e.kind === "eliminated").map((e) => e.t), []);
});
test("phase segments: a one-frame blip between two of another phase is absorbed", () => {
@@ -217,7 +222,7 @@ test("a knockout and a bust from the log; the blinds from 'Blinds are now' when
const d = derivePoker(rs, [], { everySeconds: 10, hero: "SynthHero" });
assert.deepEqual(d.tournaments[0].series.bigBlind, [[0, 3600]]);
assert.deepEqual(d.tournaments[0].series.stackBB, [[0, 13.9], [10, 25], [20, 0]]);
- assert.deepEqual(d.events.filter((e) => e.source === "log").map((e) => [e.t, e.kind]), [[10, "knockout"], [20, "bust"]]);
+ assert.deepEqual(d.events.filter((e) => e.source === "log" && e.kind !== "level-up").map((e) => [e.t, e.kind]), [[10, "knockout"], [20, "bust"]]);
});
test("after the hero is out, the next table with chips is another tournament, whatever its name", () => {
diff --git a/common/lib/frames/poker.ts b/common/lib/frames/poker.ts
@@ -231,7 +231,23 @@ const SPOKEN_AGREE: Record<string, AgreeRule> = {
// Spoken fields that are series; the rest are facts.
const SPOKEN_SERIES = new Set(["stack", "stackBB", "playersLeft", "level", "position", "averageStack", "bigBlind"]);
const SPOKEN_WINDOW_S = 90;
-const FINAL_TABLE = 9;
+/** Players left at or under which the hero is at the final table. */
+export const FINAL_TABLE = 9;
+/**
+ * The players-left milestones (release 31), crossed once each per
+ * tournament: the first header reading at or under one after the LAST
+ * reading over it (players left never rise, so a reading over it later
+ * means the earlier crossing was a misread). The final table is the last.
+ */
+export const PLAYERS_LEFT_MILESTONES = [100, 50, 27, 18] as const;
+/** A pot the hero takes of this many big blinds or more is a `big-pot`. */
+export const BIG_POT_BB = 25;
+/** A hero pot line within this window, its size within SAME_POT_RATIO of an earlier one, is that line misread. */
+const SAME_POT = { windowS: 180, ratio: 1.01 };
+/** How long after an all-in the stack readings are looked at for its outcome. */
+export const ALL_IN_OUTCOME_WINDOW_S = 180;
+/** All-in signals this close together are one all-in (the same hand). */
+const ALL_IN_SAME_HAND_S = 60;
const normName = (s: string) => s.toLowerCase().replace(/[^a-z0-9$]+/g, " ").trim();
const squash = (s: string) => normName(s).replace(/ /g, "");
@@ -471,11 +487,19 @@ export function derivePoker(readingsIn: readonly R[], spoken: readonly SpokenRea
// Blinds only go up within a tournament: before the log has said any, a
// read lower than the last one kept, or higher than the first the log
// will say, is a misread (an ante or a small blind read as the big).
+ // A logged big blind that a LATER line puts lower is that line misread
+ // (blinds only go up; release 31): set aside, the last good one held.
+ const read = list.map(logBlindsOf);
+ const lines = read.map((b, j) => (b && read.slice(j + 1).some((x) => x !== null && x.bb < b.bb) ? null : b));
+ // Recorded once per run of the line (it scrolls on the next readings).
+ read.forEach((b, j) => {
+ if (b && !lines[j] && read[j - 1]?.bb !== b.bb) misreads.push({ t: list[j].t, field: "bigBlind", value: b.bb });
+ });
let logged: { sb: number; bb: number } | null = null;
- const firstLogged = list.map(logBlindsOf).find((b) => b !== null)?.bb;
+ const firstLogged = lines.find((b) => b !== null)?.bb;
let lastRead = 0;
- for (const r of list) {
- logged = logBlindsOf(r) ?? logged;
+ for (const [j, r] of list.entries()) {
+ logged = lines[j] ?? logged;
const read = r.tournament?.blinds?.bb;
if (logged) {
if (read !== undefined && ratioOf(read, logged.bb) > 2) misreads.push({ t: r.t, field: "bigBlind", value: read });
@@ -552,7 +576,10 @@ export function derivePoker(readingsIn: readonly R[], spoken: readonly SpokenRea
const events = [
...frameEvents(rs, keys, full),
...seriesEvents(tournaments, full, flagged),
+ ...milestoneEvents(tournaments, full, flagged),
...logEvents(rs, keys, full, o.hero),
+ ...levelEvents(rs, keys, full),
+ ...allInEvents(rs, keys, full, flagged, o.hero),
...spokenEvents(spoken),
].sort((a, b) => a.t - b.t || a.kind.localeCompare(b.kind));
return { tournaments, events, segments, flags, misreads: misreads.sort((a, b) => a.t - b.t || a.field.localeCompare(b.field)) };
@@ -590,7 +617,9 @@ function frameEvents(rs: readonly R[], keys: readonly (string | null)[], full: R
const headerLeft = [...full.values()].flatMap((p) => p.playersLeft ?? []);
rs.forEach((r, i) => {
const kind = r.event;
- if (!kind || kind === "won") return;
+ // `all-in` is judged with the log and the action text (allInEvents): the
+ // model says it for any player's shove, as it says `won`.
+ if (!kind || kind === "won" || kind === "all-in") return;
if ((kind === "bust" || kind === "eliminated") && rs.some((x) => x.t > r.t && x.t - r.t <= 120 && x.phase === "table" && (x.hero?.stack ?? 0) > 0)) return;
if (kind === "final-table" && !headerLeft.some((p) => Math.abs(p.t - r.t) <= 120 && p.v <= FINAL_TABLE)) return;
const prev = out.filter((e) => e.kind === kind).pop();
@@ -607,9 +636,8 @@ function frameEvents(rs: readonly R[], keys: readonly (string | null)[], full: R
// - a double-up (×1.8 or more) or a big loss (half or more gone), its new
// level held by the reading after it (two readings at least);
// - a bust (the stack at 0 and no later chips in that tournament);
-// - the final table: players left first at 9 or fewer (not 1) after a
-// reading of more than 9 EARLIER in the tournament;
// - a win: one player left, the hero with chips.
+// (The final table is a players-left milestone since release 31: below.)
function seriesEvents(tournaments: readonly DerivedTournament[], full: ReadonlyMap<string, Record<string, Pt[]>>, flagged: ReadonlySet<string>): DerivedEvent[] {
const out: DerivedEvent[] = [];
const ok = (field: string) => (p: Pt) => !flagged.has(`${field}@${p.t}`);
@@ -633,8 +661,6 @@ function seriesEvents(tournaments: readonly DerivedTournament[], full: ReadonlyM
out.push({ t: stack[zero].t, kind: "bust", detail: before ? `out from ${fmtNum(before.v)} chips` : "out", source: "series", tournament: tour.key });
}
const left = (full.get(tour.key)?.playersLeft ?? []).filter(ok("playersLeft"));
- const ftIdx = left.findIndex((p, i) => p.v <= FINAL_TABLE && p.v > 1 && left.slice(0, i).some((q) => q.v > FINAL_TABLE));
- if (ftIdx >= 0) out.push({ t: left[ftIdx].t, kind: "final-table", detail: `${left[ftIdx].v} players left`, source: "series", tournament: tour.key });
const one = left.find((p) => p.v === 1);
const lastStack = stack[stack.length - 1];
if (one && lastStack && lastStack.v > 0 && lastStack.t >= one.t - 120) out.push({ t: one.t, kind: "won", detail: "one player left", source: "series", tournament: tour.key });
@@ -645,22 +671,34 @@ function seriesEvents(tournaments: readonly DerivedTournament[], full: ReadonlyM
// ─── The client's log ───
const digits = (s: string) => Number(s.replace(/,/g, ""));
-const BLINDS_LINE = /^blinds are now ([\d,]+)\s*\/\s*([\d,]+)/i;
+// An "INFO" or "Dealer:" prefix the client puts before the line is allowed.
+const BLINDS_LINE = /^(?:(?:info|dealer):?\s*)?blinds are now ([\d,]+)\s*\/\s*([\d,]+)/i;
const POT_LINE = /^dealer:\s*(.+?) takes the (?:(main|side) )?pot ([\d,]+)(?: with (.+?))?\.?$/i;
const FINISHED_LINE = /\bhas finished the tournament in (\d+)(?:st|nd|rd|th)?\b/i;
+const ALL_IN = /\ball[\s-]?in\b/i;
const sameName = (a: string, b: string) => a.trim().toLowerCase() === b.trim().toLowerCase();
-
-// The hero's moments in the log, each line once: a line seen again within
-// three minutes is the same line scrolling, not a second pot. A pot the hero
-// takes is `pot`, or `big-pot` at 25 big blinds or more; a line naming the
+const withoutDealer = (line: string) => line.replace(/^dealer:\s*/i, "");
+
+// The kept stack points of a tournament, flagged ones left out.
+const stackOf = (full: ReadonlyMap<string, Record<string, Pt[]>>, key: string | undefined, flagged: ReadonlySet<string> = new Set()) =>
+ (key ? (full.get(key)?.stack ?? []) : []).filter((p) => !flagged.has(`stack@${p.t}`));
+
+// The hero's moments in the log (rule `log-pot`, `log-knockout`,
+// `log-bust`), each line once: a line seen again within three minutes is the
+// same line scrolling, not a second pot, and a hero pot line within three
+// minutes of an earlier one whose size is within 1% of it is that line
+// misread ("60,025" then "60,026"). A pot the hero takes is `pot`, or
+// `big-pot` at BIG_POT_BB big blinds or more; it is `confirmed` when the
+// hero's kept stack after it is above the stack before it. A line naming the
// hero beside a knockout word is a `knockout` (the hero knocked someone out)
// or a `bust` (someone knocked the hero out, or the hero finished).
function logEvents(rs: readonly R[], keys: readonly (string | null)[], full: ReadonlyMap<string, Record<string, Pt[]>>, hero?: string): DerivedEvent[] {
if (!hero) return [];
const out: DerivedEvent[] = [];
const seen = new Map<string, number>();
+ const pots: { t: number; v: number }[] = [];
rs.forEach((r, i) => {
for (const line of r.log ?? []) {
const at = seen.get(line);
@@ -671,17 +709,222 @@ function logEvents(rs: readonly R[], keys: readonly (string | null)[], full: Rea
if (pot) {
if (!sameName(pot[1], hero)) continue;
const v = digits(pot[3]);
+ if (pots.some((p) => r.t - p.t <= SAME_POT.windowS && ratioOf(p.v, v) <= SAME_POT.ratio)) continue;
+ pots.push({ t: r.t, v });
const bb = key ? nearestBefore(full.get(key)?.bigBlind ?? [], r.t) : null;
- const big = bb ? v >= 25 * bb : false;
- out.push({ t: r.t, kind: big ? "big-pot" : "pot", detail: `takes the ${pot[2] ? `${pot[2]} ` : ""}pot ${fmtNum(v)}${bb ? ` (${Math.round(v / bb)} BB)` : ""}${pot[4] ? ` with ${pot[4]}` : ""}`, source: "log", ...(key ? { tournament: key } : {}) });
+ const potBB = bb ? Math.round((v / bb) * 10) / 10 : null;
+ const big = potBB !== null && potBB >= BIG_POT_BB;
+ const stack = stackOf(full, key);
+ const before = [...stack].reverse().find((p) => p.t < r.t);
+ const after = stack.find((p) => p.t >= r.t && p.t - r.t <= 120);
+ const evidence: Record<string, number | string> = { pot: v, line };
+ if (bb) evidence.bigBlind = bb;
+ if (potBB !== null) evidence.potBB = potBB;
+ if (before) evidence.stackBefore = before.v;
+ if (after) evidence.stackAfter = after.v;
+ out.push({
+ t: r.t,
+ kind: big ? "big-pot" : "pot",
+ detail: `takes the ${pot[2] ? `${pot[2]} ` : ""}pot ${fmtNum(v)}${bb ? ` (${Math.round(v / bb)} BB)` : ""}${pot[4] ? ` with ${pot[4]}` : ""}`,
+ source: "log",
+ ...(key ? { tournament: key } : {}),
+ rule: "log-pot",
+ evidence,
+ confidence: before && after && after.v > before.v ? "confirmed" : "unconfirmed",
+ });
continue;
}
if (!/\b(knocked out|knocks out|eliminated|eliminates|busted|finished|bounty)\b/i.test(line) || !line.toLowerCase().includes(hero.toLowerCase())) continue;
- const heroFirst = line.toLowerCase().replace(/^dealer:\s*/, "").startsWith(hero.toLowerCase());
+ const heroFirst = withoutDealer(line).toLowerCase().startsWith(hero.toLowerCase());
const kind = heroFirst && !/\bfinished\b|\bbusted\b|\bis eliminated\b|\bwas eliminated\b|\bhas been eliminated\b/i.test(line) ? "knockout" : "bust";
- out.push({ t: r.t, kind, detail: line, source: "log", ...(key ? { tournament: key } : {}) });
+ out.push({ t: r.t, kind, detail: line, source: "log", ...(key ? { tournament: key } : {}), rule: `log-${kind}`, evidence: { line } });
+ }
+ });
+ return out;
+}
+
+// LEVEL-UPS (rule `log-blinds`): the log's "Blinds are now a/b", once per new
+// big blind per tournament, at the first reading that shows it. A logged big
+// blind that a LATER line in the same tournament puts lower is a misread of
+// that line and makes no event (blinds only go up). It is `confirmed` when the
+// big blind before it — the last line's, else the last read off the table —
+// is lower; with nothing before it to compare, `unconfirmed`. The level's
+// number rides along when a reading within two minutes shows one.
+function levelEvents(rs: readonly R[], keys: readonly (string | null)[], full: ReadonlyMap<string, Record<string, Pt[]>>): DerivedEvent[] {
+ const byKey = new Map<string, { t: number; sb: number; bb: number; line: string }[]>();
+ rs.forEach((r, i) => {
+ const key = keys[i];
+ if (!key) return;
+ for (let j = (r.log?.length ?? 0) - 1; j >= 0; j--) {
+ const m = BLINDS_LINE.exec(r.log![j]);
+ if (!m) continue;
+ const sb = digits(m[1]);
+ const bb = digits(m[2]);
+ if (sb > 0 && bb >= sb) {
+ const list = byKey.get(key) ?? [];
+ if (list[list.length - 1]?.bb !== bb) list.push({ t: r.t, sb, bb, line: r.log![j] });
+ byKey.set(key, list);
+ }
+ break;
+ }
+ });
+ const out: DerivedEvent[] = [];
+ for (const [key, lines] of byKey) {
+ // Kept: a line no later line undercuts; then each new big blind once.
+ const kept = lines.filter((l, i) => !lines.slice(i + 1).some((x) => x.bb < l.bb));
+ const seen = new Set<number>();
+ let prev: number | null = null;
+ const reads = full.get(key)?.bigBlind ?? [];
+ const levels = full.get(key)?.level ?? [];
+ for (const l of kept) {
+ if (seen.has(l.bb)) continue;
+ seen.add(l.bb);
+ // Before the first line, the big blind read off the table (the series' last point before it).
+ const from = prev ?? [...reads].reverse().find((p) => p.t < l.t && p.v !== l.bb)?.v ?? null;
+ prev = l.bb;
+ if (from !== null && from >= l.bb) continue;
+ const level = levels.find((p) => Math.abs(p.t - l.t) <= 120)?.v;
+ const evidence: Record<string, number | string> = { smallBlind: l.sb, bigBlind: l.bb, line: l.line };
+ if (from !== null) evidence.from = from;
+ if (level !== undefined) evidence.level = level;
+ out.push({
+ t: l.t,
+ kind: "level-up",
+ detail: `blinds ${fmtNum(l.sb)}/${fmtNum(l.bb)}${from !== null ? ` (from ${fmtNum(from)})` : ""}${level !== undefined ? `, level ${fmtNum(level)}` : ""}`,
+ source: "log",
+ tournament: key,
+ rule: "log-blinds",
+ evidence,
+ confidence: from !== null ? "confirmed" : "unconfirmed",
+ });
+ }
+ }
+ return out;
+}
+
+// PLAYERS-LEFT MILESTONES (rule `players-left-milestone`), on the kept
+// players-left points (the stats header, or the log's finishing places —
+// never a table's seats, never a spoken number) with flagged points left
+// out: each of PLAYERS_LEFT_MILESTONES and the final table crossed once per
+// tournament, at the first point after the LAST point over it (players left
+// never rise: a point over it later means an earlier crossing was a misread).
+// A point that crosses several at once is one event, the lowest. The final
+// table is its own kind (`final-table`, not at 1 left); the rest are
+// `players-left`. `confirmed` when the next point holds it.
+function milestoneEvents(tournaments: readonly DerivedTournament[], full: ReadonlyMap<string, Record<string, Pt[]>>, flagged: ReadonlySet<string>): DerivedEvent[] {
+ const out: DerivedEvent[] = [];
+ for (const tour of tournaments) {
+ const left = (full.get(tour.key)?.playersLeft ?? []).filter((p) => !flagged.has(`playersLeft@${p.t}`));
+ const at = new Map<number, number>();
+ for (const x of [...PLAYERS_LEFT_MILESTONES, FINAL_TABLE]) {
+ let last = -1;
+ left.forEach((p, i) => {
+ if (p.v > x) last = i;
+ });
+ const i = last + 1;
+ if (last < 0 || i >= left.length) continue;
+ if (x === FINAL_TABLE && left[i].v <= 1) continue;
+ // The lowest milestone a point crosses names it.
+ if (!at.has(i) || x < at.get(i)!) at.set(i, x);
}
+ for (const [i, x] of [...at].sort((a, b) => a[0] - b[0])) {
+ const p = left[i];
+ const before = left[i - 1];
+ const next = left[i + 1];
+ const ft = x === FINAL_TABLE;
+ out.push({
+ t: p.t,
+ kind: ft ? "final-table" : "players-left",
+ detail: ft ? `${p.v} players left` : `${p.v} players left (under ${x})`,
+ source: "series",
+ tournament: tour.key,
+ rule: "players-left-milestone",
+ evidence: { milestone: x, playersLeft: p.v, before: before.v, beforeT: before.t },
+ confidence: next && next.v <= x ? "confirmed" : "unconfirmed",
+ });
+ }
+ }
+ return out;
+}
+
+// ALL-INS (rule `all-in`): the hero's, from what was read —
+// - a log line naming the hero first with "all in" (a call when it says
+// "call"; else the hero shoved);
+// - the action text naming the hero with "all in";
+// - the action text or the model's all-in banner with no name, only when
+// the same reading shows the hero's cards and the hero's stack read as 0
+// (every chip in the middle). The model says "all-in" for any player's
+// shove, so a banner with the hero's chips still in front of them is not
+// the hero's.
+// Signals within a minute are one all-in. Its OUTCOME is read off the kept
+// stack (flagged points left out) within ALL_IN_OUTCOME_WINDOW_S after it,
+// against the last kept stack before it: `busted` (a bust event of the series
+// or the log follows within the window, or the stack reads 0 and stays),
+// `doubled` (×1.8 or more), `won` (×1.1 or more), `lost` (under ×0.9),
+// `unclear` (about level), `unknown` (no reading). `confirmed` with an
+// outcome other than unclear/unknown.
+const ALL_IN_OUTCOME: Record<string, string> = { doubled: "doubles up", won: "wins it", lost: "loses chips", busted: "busts", unclear: "no clear change", unknown: "outcome not read" };
+
+function allInEvents(rs: readonly R[], keys: readonly (string | null)[], full: ReadonlyMap<string, Record<string, Pt[]>>, flagged: ReadonlySet<string>, hero?: string): DerivedEvent[] {
+ const signals: { t: number; i: number; via: string; role: "shove" | "call"; text: string }[] = [];
+ const names = (text: string) => !!hero && withoutDealer(text).toLowerCase().startsWith(hero.toLowerCase());
+ const mentions = (text: string) => !!hero && text.toLowerCase().includes(hero.toLowerCase());
+ const chipsIn = (r: R) => r.phase === "table" && r.hero?.stack === 0 && (r.hero?.cards?.length ?? 0) > 0;
+ const roleOf = (text: string): "shove" | "call" => (/\bcall(?:s|ed)?\b/i.test(text) ? "call" : "shove");
+ // "Villain is all in, SynthHero calls": the hero called an all-in.
+ const heroCalls = hero ? new RegExp(`\\b${hero.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")} call(?:s|ed)\\b`, "i") : null;
+ rs.forEach((r, i) => {
+ for (const line of r.log ?? []) {
+ if (ALL_IN.test(line) && (names(line) || heroCalls?.test(line))) signals.push({ t: r.t, i, via: "log", role: roleOf(line), text: line });
+ }
+ const action = r.hand?.action;
+ if (action && ALL_IN.test(action) && (mentions(action) || chipsIn(r))) signals.push({ t: r.t, i, via: "action", role: roleOf(action), text: action });
+ if (r.event === "all-in" && chipsIn(r)) signals.push({ t: r.t, i, via: "banner", role: "shove", text: "all-in shown on screen" });
});
+ signals.sort((a, b) => a.t - b.t);
+ // The hero out in the log: "<hero> has finished…", "<hero> is eliminated", "<someone> knocked out <hero>".
+ const outLine = (l: string) =>
+ mentions(l) &&
+ ((names(l) && /\b(has finished the tournament|is eliminated|was eliminated|has been eliminated|busted)\b/i.test(l)) ||
+ (!names(l) && /\b(knocked out|knocks out|eliminates|eliminated)\b/i.test(l)));
+ const out: DerivedEvent[] = [];
+ let lastT = -Infinity;
+ for (const s of signals) {
+ if (s.t - lastT <= ALL_IN_SAME_HAND_S) continue;
+ lastT = s.t;
+ const key = keys[s.i] ?? undefined;
+ const stack = stackOf(full, key, flagged);
+ const before = [...stack].reverse().find((p) => p.t < s.t && p.v > 0);
+ const after = stack.filter((p) => p.t > s.t && p.t - s.t <= ALL_IN_OUTCOME_WINDOW_S);
+ const firstAfter = after.find((p) => p.v > 0) ?? after[0];
+ const zeroStays = after.length > 0 && after[after.length - 1].v === 0 && !stack.some((p) => p.t > s.t && p.v > 0);
+ const heroOut = rs.some((r) => r.t >= s.t && r.t - s.t <= ALL_IN_OUTCOME_WINDOW_S && (r.log ?? []).some(outLine));
+ let outcome: string;
+ if (zeroStays || heroOut) outcome = "busted";
+ else if (!before || !firstAfter) outcome = "unknown";
+ else if (firstAfter.v >= before.v * 1.8) outcome = "doubled";
+ else if (firstAfter.v >= before.v * 1.1) outcome = "won";
+ // A 0 with chips again later (past the window) is a dip, not a result.
+ else if (firstAfter.v === 0) outcome = "unknown";
+ else if (firstAfter.v < before.v * 0.9) outcome = "lost";
+ else outcome = "unclear";
+ const evidence: Record<string, number | string> = { via: s.via, role: s.role, text: s.text, outcome };
+ if (before) evidence.stackBefore = before.v;
+ if (firstAfter) {
+ evidence.stackAfter = firstAfter.v;
+ evidence.afterT = firstAfter.t;
+ }
+ out.push({
+ t: s.t,
+ kind: "all-in",
+ detail: `${s.role === "call" ? "calls all in" : "all in"}${before ? ` with ${fmtNum(before.v)}` : ""}: ${ALL_IN_OUTCOME[outcome]}${firstAfter && ["doubled", "won", "lost"].includes(outcome) ? ` (${fmtNum(firstAfter.v)})` : ""}`,
+ source: s.via === "log" ? "log" : "frame",
+ ...(key ? { tournament: key } : {}),
+ rule: "all-in",
+ evidence,
+ confidence: outcome === "unknown" || outcome === "unclear" ? "unconfirmed" : "confirmed",
+ });
+ }
return out;
}
diff --git a/common/lib/frames/pokerDerive.test.ts b/common/lib/frames/pokerDerive.test.ts
@@ -109,7 +109,7 @@ test("the model's 'won' is not an event; an 'eliminated' with chips after it is
assert.deepEqual(kinds("eliminated"), [650]);
assert.deepEqual(kinds("bust"), [650]);
// The hero's pot from the log (60,000 at 2,000: 30 BB).
- assert.deepEqual(d.events.filter((e) => e.source === "log").map((e) => [e.t, e.kind]), [[540, "big-pot"]]);
+ assert.deepEqual(d.events.filter((e) => e.source === "log" && e.kind !== "level-up").map((e) => [e.t, e.kind]), [[540, "big-pot"]]);
});
test("rederiveRecord: derived worked out again from the stored readings, no model, the rest kept", () => {
diff --git a/common/lib/frames/pokerEvents.test.ts b/common/lib/frames/pokerEvents.test.ts
@@ -0,0 +1,114 @@
+// The derivation's highlight events (release 31, lane P3) against the test
+// kit's synthetic highlights (testing/frames/pokerReadings.mjs): hero pots,
+// all-ins with their outcome, level-ups from the log, players-left
+// milestones — each made by a named rule, its evidence on the event, and the
+// P2 guarantees kept (a flagged reading makes no event; one tournament).
+
+import { test } from "node:test";
+import assert from "node:assert/strict";
+import { syntheticPokerHighlights, SYNTH_MAIN } from "../../testing/frames/pokerReadings.mjs";
+import { BIG_POT_BB, derivePoker, FINAL_TABLE, PLAYERS_LEFT_MILESTONES, type PokerReading } from "./poker";
+import type { DerivedEvent } from "./types";
+
+type R = PokerReading & { t: number };
+const fx = syntheticPokerHighlights();
+const d = derivePoker(fx.readings as R[], fx.spoken, { everySeconds: 10, hero: fx.hero });
+const of = (k: string) => d.events.filter((e) => e.kind === k);
+const ts = (k: string) => of(k).map((e) => e.t);
+
+test("the named constants", () => {
+ assert.equal(BIG_POT_BB, 25);
+ assert.deepEqual([...PLAYERS_LEFT_MILESTONES], [100, 50, 27, 18]);
+ assert.equal(FINAL_TABLE, 9);
+});
+
+test("one tournament, named; the derivation's P2 events still there", () => {
+ assert.equal(d.tournaments.length, 1);
+ assert.equal(d.tournaments[0].name, SYNTH_MAIN);
+ assert.deepEqual(ts("double-up"), [1010]);
+ assert.deepEqual(ts("bust"), [2900]);
+ assert.deepEqual(ts("eliminated"), [2910]);
+});
+
+test("hero pots: big at 25 BB or more, the line read again as a near size is one pot, confirmed by the stack", () => {
+ assert.deepEqual(ts("big-pot"), fx.expect["big-pot"]);
+ assert.deepEqual(ts("pot"), fx.expect.pot);
+ const big = of("big-pot")[0];
+ assert.equal(big.rule, "log-pot");
+ assert.deepEqual(big.evidence, { pot: 40000, line: "Dealer: SynthHero takes the pot 40,000.", bigBlind: 1200, potBB: 33.3, stackBefore: 50000, stackAfter: 80000 });
+ assert.equal(big.confidence, "confirmed");
+ assert.equal(big.detail, "takes the pot 40,000 (33 BB)");
+ // The small pot is measured against the log's 1,200, not the misread 16,000.
+ assert.equal(of("pot")[0].evidence?.potBB, 2.5);
+});
+
+test("all-ins: the hero's only, one per hand, with the outcome the next stack readings show", () => {
+ assert.deepEqual(of("all-in").map((e) => [e.t, e.evidence?.outcome]), fx.expect["all-in"]);
+ const [doubled, lost, busted] = of("all-in");
+ assert.deepEqual(doubled.evidence, { via: "log", role: "shove", text: "SynthHero raises 81,500 and is all-in", outcome: "doubled", stackBefore: 81500, stackAfter: 170000, afterT: 1010 });
+ assert.equal(doubled.detail, "all in with 81,500: doubles up (170,000)");
+ assert.equal(doubled.source, "log");
+ assert.equal(lost.evidence?.role, "call");
+ assert.equal(lost.evidence?.via, "action");
+ assert.equal(busted.evidence?.via, "action");
+ assert.equal(busted.detail, "all in with 120,000: busts");
+ for (const e of of("all-in")) assert.equal(e.confidence, "confirmed");
+ // The model's banner at 1,100 (another player's shove) is not the hero's.
+ assert.ok(!ts("all-in").includes(1100));
+});
+
+test("an all-in with no stack read after it is unconfirmed, its outcome unknown", () => {
+ const rs: R[] = [
+ { t: 0, phase: "table", hero: { stack: 5000 } },
+ { t: 10, phase: "table", hero: { stack: 5000 }, log: ["Villain bets 4,000, SynthHero calls and is all in"] },
+ { t: 20, phase: "other" },
+ ];
+ const x = derivePoker(rs, [], { everySeconds: 10, hero: "SynthHero" });
+ const e = x.events.find((ev) => ev.kind === "all-in")!;
+ assert.equal(e.evidence?.role, "call");
+ assert.equal(e.evidence?.outcome, "unknown");
+ assert.equal(e.confidence, "unconfirmed");
+ // Another player's line is not the hero's.
+ const other = derivePoker([{ t: 0, phase: "table", hero: { stack: 5000 }, log: ["Villain is all-in"] }], [], { everySeconds: 10, hero: "SynthHero" });
+ assert.deepEqual(other.events.filter((ev) => ev.kind === "all-in"), []);
+});
+
+test("level-ups from the log: each new big blind once, the misread line undercut by a later one makes none", () => {
+ assert.deepEqual(ts("level-up"), fx.expect["level-up"]);
+ const [first, second, third, fourth] = of("level-up");
+ assert.equal(first.confidence, "unconfirmed");
+ assert.deepEqual(second.evidence, { smallBlind: 600, bigBlind: 1200, line: "Blinds are now 600/1,200", from: 1000, level: 2 });
+ assert.equal(second.detail, "blinds 600/1,200 (from 1,000), level 2");
+ assert.equal(third.evidence?.from, 1200);
+ assert.equal(fourth.evidence?.line, "INFO Blinds are now 1,000/2,000");
+ for (const e of [second, third, fourth]) assert.equal(e.confidence, "confirmed");
+ // The 16,000 is a misread in the series too: set aside, the big blind held.
+ assert.ok(d.misreads.some((m) => m.field === "bigBlind" && m.value === 16000 && m.t === 600));
+ assert.equal(d.misreads.filter((m) => m.field === "bigBlind" && m.value === 16000).length, 1);
+ assert.ok(!d.tournaments[0].series.bigBlind.some(([, v]) => v === 16000), JSON.stringify(d.tournaments[0].series.bigBlind));
+});
+
+test("players-left milestones from the header, once each; a flagged reading crosses nothing", () => {
+ assert.deepEqual(of("players-left").map((e) => [e.t, e.evidence?.milestone]), fx.expect["players-left"]);
+ assert.deepEqual(ts("final-table"), fx.expect["final-table"]);
+ const fifty = of("players-left").find((e) => e.evidence?.milestone === 50)!;
+ assert.deepEqual(fifty.evidence, { milestone: 50, playersLeft: 45, before: 60, beforeT: 1000 });
+ assert.equal(fifty.rule, "players-left-milestone");
+ assert.equal(fifty.confidence, "confirmed");
+ assert.equal(of("final-table")[0].confidence, "confirmed");
+ assert.equal(d.flags.length, 1);
+});
+
+test("milestones: never rising (a later reading over it moves the crossing), the lowest at one point, none from below", () => {
+ const h = (t: number, left: number): R => ({ t, phase: "table", tournament: { playersLeft: left, position: 1 }, hero: { stack: 1000 } });
+ const ms = (rs: R[]) => derivePoker(rs, [], { everySeconds: 10 }).events.filter((e: DerivedEvent) => e.kind === "players-left" || e.kind === "final-table").map((e) => [e.t, e.kind, e.evidence?.milestone]);
+ // 105 → 99 → 103 → 98: the crossing of 100 is at the 98.
+ assert.deepEqual(ms([h(0, 105), h(10, 99), h(20, 103), h(30, 98), h(40, 97)]), [[30, "players-left", 100]]);
+ // 52 → 26 crosses 50 and 27 at once: one event, the lower.
+ assert.deepEqual(ms([h(0, 55), h(10, 52), h(20, 26), h(30, 25)]), [[20, "players-left", 27]]);
+ // A field that starts under a milestone never crosses it.
+ assert.deepEqual(ms([h(0, 40), h(10, 30)]), []);
+ // The last point: unconfirmed (nothing holds it).
+ const last = derivePoker([h(0, 30), h(10, 17)], [], { everySeconds: 10 }).events.find((e) => e.kind === "players-left")!;
+ assert.equal(last.confidence, "unconfirmed");
+});
diff --git a/common/lib/frames/scan.test.ts b/common/lib/frames/scan.test.ts
@@ -132,6 +132,8 @@ test("a scan on the API: images as JPEG blocks, readings, the derived timeline,
const d = r.derived;
const events = d.events.map((e) => [e.t, e.kind]);
assert.deepEqual(events.filter(([, k]) => k !== "buy-in"), [
+ // Release 31: the lobby's 120 left, then the table header's 85 — under 100.
+ [30, "players-left"],
[90, "double-up"],
[120, "big-loss"],
// No final table at 120: the frames' 9 left is flagged against the spoken
diff --git a/common/lib/frames/types.ts b/common/lib/frames/types.ts
@@ -37,6 +37,13 @@ export type DerivedEvent = {
// client's log as a frame showed it, or the transcript.
source: "frame" | "series" | "log" | "spoken";
tournament?: string;
+ // Release 31 (lane P3): the named rule that made the event, what it read
+ // (the evidence: numbers and the line as shown), and whether a second
+ // reading backs it ("confirmed") or it rests on one ("unconfirmed"). A
+ // flagged reading still makes no event at all.
+ rule?: string;
+ evidence?: Record<string, number | string>;
+ confidence?: "confirmed" | "unconfirmed";
};
export type DerivedSegment = { from: number; to: number; phase: string; tournament?: string };
diff --git a/common/testing/frames/pokerReadings.d.mts b/common/testing/frames/pokerReadings.d.mts
@@ -1,8 +1,23 @@
export const SYNTH_HERO: string;
export const SYNTH_TITLE: string;
+export const SYNTH_MAIN: string;
export function syntheticPokerReadings(): {
readings: ({ t: number; phase: string } & Record<string, unknown>)[];
spoken: { t: number; field: string; value: number; text: string }[];
hero: string;
title: string;
};
+export function syntheticPokerHighlights(): {
+ readings: ({ t: number; phase: string } & Record<string, unknown>)[];
+ spoken: { t: number; field: string; value: number; text: string }[];
+ hero: string;
+ title: string;
+ expect: {
+ "level-up": number[];
+ "big-pot": number[];
+ pot: number[];
+ "all-in": [number, string][];
+ "players-left": [number, number][];
+ "final-table": number[];
+ };
+};
diff --git a/common/testing/frames/pokerReadings.mjs b/common/testing/frames/pokerReadings.mjs
@@ -68,3 +68,74 @@ export function syntheticPokerReadings() {
title: SYNTH_TITLE,
};
}
+
+// ─── Release 31 (lane P3): the HIGHLIGHTS a supercut is cut from ───
+//
+// One tournament ("SYNTH MAIN", the hero SynthHero), every rule's evidence and
+// every trap beside it — synthetic values and names, none of a stream's:
+//
+// - the log's blinds: 1,000, 1,200 (the line scrolling on the next reading),
+// a misread "8,000/16,000" a later line undercuts, 1,600, then 2,000 behind
+// an "INFO" prefix; the level read near three of them;
+// - the stats header every 200 s, the field falling 120 → 8 through 100, 50,
+// 27, 18 and the final table; the 49 at 1,200 FLAGGED by a spoken "eighty
+// players left" beside it, so the 50 is crossed at 1,400 instead;
+// - the hero's pots: a big one (40,000 at 1,200: 33 BB) whose line is read
+// again as "40,001" two minutes later (one pot), and a small one;
+// - all-ins: the hero's shove in the log, doubled (the 0 mid-hand set
+// aside); another player's shove as the model's banner with the hero's
+// chips in front of them (not the hero's); the hero calling an all-in in
+// the action text, lost; and the last shove, an unnamed "ALL IN" with the
+// hero's cards and a 0 stack, busted.
+//
+// `syntheticPokerHighlights()` → { readings, spoken, hero, title, expect }.
+
+export const SYNTH_MAIN = "SYNTH MAIN";
+
+export function syntheticPokerHighlights() {
+ const H = SYNTH_HERO;
+ const left = [[0, 120], [200, 105], [400, 100], [600, 96], [800, 80], [1000, 60], [1200, 49], [1400, 45], [1600, 30], [1800, 26], [2000, 20], [2200, 17], [2400, 12], [2600, 9], [2800, 8]];
+ const blinds = { 0: "Blinds are now 500/1,000", 300: "Blinds are now 600/1,200", 310: "Blinds are now 600/1,200", 600: "Blinds are now 8,000/16,000", 610: "Blinds are now 8,000/16,000", 900: "Blinds are now 800/1,600", 1500: "INFO Blinds are now 1,000/2,000" };
+ const levels = { 310: 2, 900: 3, 1510: 4 };
+ const stackAt = (t) => (t < 500 ? 50000 : t < 700 ? 80000 : t < 1000 ? 81500 : t < 1300 ? 170000 : 120000);
+ const rs = [];
+ for (let t = 0; t < 2900; t += 10) {
+ const r = { t, phase: "table", hero: { stack: stackAt(t) } };
+ const tour = {};
+ if (t === 0 || t === 1700) tour.name = SYNTH_MAIN;
+ const hdr = left.find(([at]) => at === t);
+ if (hdr) Object.assign(tour, { playersLeft: hdr[1], position: Math.ceil(hdr[1] / 2) });
+ if (levels[t]) tour.level = levels[t];
+ if (Object.keys(tour).length) r.tournament = tour;
+ const log = [];
+ if (blinds[t]) log.push(blinds[t]);
+ if (t === 500 || t === 510) log.push(`Dealer: ${H} takes the pot 40,000.`);
+ if (t === 640) log.push(`Dealer: ${H} takes the pot 40,001.`);
+ if (t === 700) log.push(`Dealer: ${H} takes the pot 3,000.`);
+ if (t === 1000) log.push(`${H} raises 81,500 and is all-in`);
+ if (log.length) r.log = log;
+ // The shove: every chip in the middle on the frame that shows it.
+ if (t === 1000) r.hero = { stack: 0, cards: ["As", "Ks"] };
+ // Another player's shove, the hero's chips in front of the hero.
+ if (t === 1100) r.event = "all-in";
+ if (t === 1300) r.hand = { action: `${H} calls all-in` };
+ rs.push(r);
+ }
+ rs.push({ t: 2900, phase: "table", hero: { stack: 0, cards: ["7c", "2d"] }, hand: { action: "ALL IN" } });
+ rs.push({ t: 2910, phase: "table", hero: { stack: 0 }, event: "eliminated" });
+ rs.push({ t: 2920, phase: "break" });
+ return {
+ readings: rs,
+ spoken: [{ t: 1205, field: "playersLeft", value: 80, text: "eighty players left" }],
+ hero: H,
+ title: SYNTH_MAIN,
+ expect: {
+ "level-up": [0, 300, 900, 1500],
+ "big-pot": [500],
+ pot: [700],
+ "all-in": [[1000, "doubled"], [1300, "lost"], [2900, "busted"]],
+ "players-left": [[400, 100], [1400, 50], [1800, 27], [2200, 18]],
+ "final-table": [2600],
+ },
+ };
+}