ravensight-playtest 0.10.3 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,13 +22,19 @@ import { runEdgePass, edgeFindings, edgeMarkdown, EDGE_HEADING, blankCapabilityN
22
22
  // Tester techniques (./testerLedger.js): a coverage map, the game's own numbers and placeholder text, kept by the runner.
23
23
  import { createTesterLedger, testerFindings, testedMarkdown, TESTED_HEADING } from './testerLedger.js';
24
24
  import { runTesterProbes, probeFindings, probesMarkdown, probeObserver, PROBES_HEADING } from './testerProbes.js';
25
+ import { avoidLinesOf } from './avoid.js';
25
26
  import { runGodotTesterProbes, godotProbesMarkdown } from './godotTesterProbes.js';
26
27
  import { runGodotEdgePass } from './godotEdgePass.js';
27
28
  import { recordingMetadata, saveRecording } from './drivers/recording.js';
28
29
  import { createTranscript } from './transcript.js';
29
30
  import { createUsageLedger, writeUsageFile } from './usage.js';
30
31
  import { fillPlaceholders, fillReportPlaceholders } from './placeholders.js';
31
- import { gateFinding, sweepTurnedAway } from './claimGate.js';
32
+ import { sweepTurnedAway } from './claimGate.js';
33
+ // The claim judge and the hosted runner's own claim words, check questions and event rules.
34
+ import { claimShape, judgeIssue, legacyIssue, impressionOf } from './judge.js';
35
+ import { EVENTS_RULE, eventsBlock, eventsReportLines, eventsUsage, withEventEvidence } from './events.js';
36
+ import { memoryBlock, extractLocalNotes, gameMemoryBody } from './gameMemory.js';
37
+ import { CLAIM_SYSTEM, CLAIM_WIRE, claimText, claimRead, claimMessage } from './claimwords.js';
32
38
  import { captureNotes, createCaptureWatch, rewriteStaleEvidence, staleSentence } from './captureCheck.js';
33
39
  import { gameRefusal } from './gameRefusal.js';
34
40
  import { BUILT_IN_NOISE, expectedNoiseForPrompt, isExpectedNoise } from './noise.js';
@@ -281,7 +287,9 @@ export async function runPersona(args) {
281
287
  onProgress = () => {},
282
288
  log = () => {},
283
289
  recordVideo = false,
284
- viewport
290
+ viewport,
291
+ // The game's playtest memory (./gameMemory.js): `{ save, notes, buildSha256 }`, or null.
292
+ memory = null
285
293
  } = args;
286
294
 
287
295
  const validator = createReportValidator(schemas);
@@ -356,6 +364,8 @@ export async function runPersona(args) {
356
364
  // that rather than still holding `queued`.
357
365
  await advance('launching');
358
366
  if ('traceSecrets' in driver) driver.traceSecrets = secretsOf(localBrief);
367
+ // What the brief asks the run to stay out of: the driver refuses an input on it, whoever chose the input (./avoid.js).
368
+ if (typeof driver.setAvoid === 'function') driver.setAvoid(avoidLinesOf(brief));
359
369
  await driver.launch({ target, runDir: runDirectory, recordVideo, viewport, signal: args.signal });
360
370
  // A web run keeps its inputs, in this process only, so its findings can be replayed after the report.
361
371
  if (driverName === 'playwright_web' && typeof args.replayDriver === 'function' && args.replayFindings !== false) traceWebInputs(driver, { fingerprint: pngFingerprint });
@@ -411,6 +421,7 @@ export async function runPersona(args) {
411
421
  onProgress({ phase: 'reporting', persona: persona.slug });
412
422
 
413
423
  const written = await reportPhase({
424
+ claimGate: args.claimGate === 'legacy' ? 'legacy' : 'judge',
414
425
  client,
415
426
  jobId,
416
427
  runId,
@@ -466,6 +477,17 @@ export async function runPersona(args) {
466
477
  outcome.state = play.budgetExceeded ? 'budget_exceeded' : 'succeeded';
467
478
  outcome.quitReason = play.budgetExceeded ? 'cost_cap' : written.report.quit_reason;
468
479
  outcome.quitDetail = written.report.quit_detail || '';
480
+ // What the game's own events measured, for usage.json (./events.js eventsUsage).
481
+ const eventRun = gameEventsRun(honesty);
482
+ outcome.gameEvents = eventRun ? eventsUsage(eventRun) : null;
483
+ // The notes this run hands on to the next playtest of the game, when the game's memory asked for them (./gameMemory.js).
484
+ if (memory && memory.save === true) {
485
+ const handed = gameMemoryBody(memory, extractLocalNotes({ digest: honesty.anygame ? honesty.anygame.digest() : null, turnedAway: written.turnedAway || [] }));
486
+ if (handed) {
487
+ outcome.gameMemory = handed;
488
+ transcript.write({ kind: 'game_memory', notes: handed.notes.length, kinds: Object.fromEntries([...new Set(handed.notes.map(n => n.kind))].map(kind => [kind, handed.notes.filter(n => n.kind === kind).length])) });
489
+ }
490
+ }
469
491
  return finish(outcome, ledger, runDirectory, transcript, heartbeat);
470
492
  } catch (error) {
471
493
  await driverStop(driver, outcome, log, args.signal?.aborted ? 'canceled' : 'failed');
@@ -743,6 +765,8 @@ async function playLoop({
743
765
  // The observation and action lines of the transcript, kept for the report
744
766
  // step's "Actions you took" list and for a partial report.
745
767
  actionRecords = [],
768
+ // The game's playtest memory (./gameMemory.js), carried in from runPersona's arguments.
769
+ memory: earlierMemory = null,
746
770
  api,
747
771
  controller = 'standard',
748
772
  signal: argsSignal,
@@ -790,6 +814,12 @@ async function playLoop({
790
814
  const briefFields = brief && brief.fields && typeof brief.fields === 'object' ? brief.fields : brief || {};
791
815
  const anyGame = honesty.anygame || (honesty.anygame = createLocalAnyGame({ briefText: briefForPrompt(brief), controls: briefFields.build_notes && typeof briefFields.build_notes.controls === 'string' ? briefFields.build_notes.controls : null, touch: Boolean(driver && driver.touch), driverName: typeof driver.soundSelfTest === 'function' ? '' : driverName }));
792
816
  system.push({ type: 'text', text: anyGame.systemText() });
817
+ // What earlier playtests of this game learned (./gameMemory.js): the same block every request carries, so it is cached.
818
+ const earlier = earlierMemory && earlierMemory.save !== false ? memoryBlock(earlierMemory) : '';
819
+ if (earlier) {
820
+ system.push({ type: 'text', text: earlier });
821
+ transcript.write({ kind: 'game_memory_read', notes: Array.isArray(earlierMemory.notes) ? earlierMemory.notes.length : 0, chars: earlier.length });
822
+ }
793
823
  system.push({ type: 'text', text: PLAY_NOTES });
794
824
  if (typeof driver.soundSelfTest === 'function') anyGame.soundAvailable(await Promise.resolve().then(() => driver.soundSelfTest()).catch(() => null));
795
825
  if (['jev', 'rune'].includes(controller)) system.push({ type: 'text', text: JEV_CONTROLLER_PROMPT });
@@ -911,6 +941,8 @@ async function playLoop({
911
941
  // step and to a time in the video.
912
942
  entry.at = Date.now();
913
943
  entry.actions = actions;
944
+ // The persona's copy of this screen carried the runner's grid and marks (a canvas game): a judgement of how it is drawn is checked on the game's own frame.
945
+ entry.marked = /The picture has a grid drawn on it/.test(String((observation && observation.text) || ''));
914
946
  observations.push(entry);
915
947
  // [tester hook] The screen goes on the coverage map and its text is checked.
916
948
  if (honesty.tester) honesty.tester.observe({ index: observations.length, text: observation && observation.text, title: entry.title, actions });
@@ -1212,6 +1244,8 @@ async function playLoop({
1212
1244
  ? await safeScreenshot(driver, 'noted', screenshots, transcript, observations.length, keeper)
1213
1245
  : null;
1214
1246
  let executed;
1247
+ // The game's own events: the page clock (Godot: the moment) just before this input, so each event is placed at its step.
1248
+ if (ACTION_TOOLS.includes(toolUse.name) && !toolUse.malformed && typeof driver.markGameEvents === 'function') await Promise.resolve().then(() => driver.markGameEvents(actions + 1)).catch(() => null);
1215
1249
  const ranAt = Date.now();
1216
1250
  try {
1217
1251
  executed = await executeTool({
@@ -1452,6 +1486,16 @@ async function playLoop({
1452
1486
  // any-game hook: the play style once, and the notebook when screens have dropped out of context.
1453
1487
  const anyAside = anyGame.aside({ actions, dropped: staleObservationCount(observations.length, keepObservations) });
1454
1488
  if (anyAside) { asides.push(anyAside); transcript.write({ kind: 'any_game_aside', chars: anyAside.length }); }
1489
+ // The game's own analytics events since the last turn, measured and not read off the picture (./events.js): only when there are new ones.
1490
+ const eventLog = driver && driver.gameEvents;
1491
+ if (eventLog && typeof eventLog.pendingForPlan === 'function') {
1492
+ const pending = eventLog.pendingForPlan();
1493
+ if (pending.lines.length > 0) {
1494
+ asides.push(`${EVENTS_RULE}\n${eventsBlock(pending.lines)}`);
1495
+ eventLog.planned(pending.upTo);
1496
+ transcript.write({ kind: 'game_events_aside', lines: pending.lines.length, events: eventLog.size });
1497
+ }
1498
+ }
1455
1499
 
1456
1500
  // The picture goes last, outside the tool results, so the cache
1457
1501
  // breakpoint can sit before it (withPlayCacheBreakpoint).
@@ -1545,12 +1589,14 @@ async function playLoop({
1545
1589
  const met = await Promise.resolve().then(() => driver.capabilityNotes()).catch(() => []);
1546
1590
  for (const note of met || []) if (honesty.capability.add(note)) transcript.write({ kind: 'capability_note', input: note.input, reason: note.reason });
1547
1591
  }
1592
+ // The game's own events: play is over, so what comes now (the probes, the edge checks) is placed after play.
1593
+ if (typeof driver.markGameEvents === 'function') await Promise.resolve().then(() => driver.markGameEvents('end')).catch(() => null);
1548
1594
  // [tester hook] The tester probes (./testerProbes.js): scripted, no model call, on the page play ended on, before the edge
1549
1595
  // behaviour checks reload it. On the same switch as those checks.
1550
1596
  const probing = edgePass && !gameEnded && !canceled && !budgetExceeded && typeof driver.edgeSession === 'function' && driverName === 'playwright_web' && !(argsSignal && argsSignal.aborted);
1551
1597
  if (probing) {
1552
1598
  try {
1553
- honesty.probes = await runTesterProbes({ driver, actionRecords, screenshots, observation: observations.length, signal: argsSignal, log });
1599
+ honesty.probes = await runTesterProbes({ driver, actionRecords, screenshots, observation: observations.length, signal: argsSignal, log, avoid: avoidLinesOf(brief) });
1554
1600
  transcript.write({ kind: 'tester_probes', elapsed_ms: honesty.probes.elapsedMs, checks: honesty.probes.checks.map(check => ({ name: check.name, status: check.status, detail: check.detail })) });
1555
1601
  } catch (error) {
1556
1602
  transcript.write({ kind: 'tester_probes_failed', message: String(error && error.message) });
@@ -1566,7 +1612,7 @@ async function playLoop({
1566
1612
  // has been saved. A canceled run and a game that already ended skip it.
1567
1613
  if (edgePass && !probesStopped && !gameEnded && !canceled && !budgetExceeded && typeof driver.edgeSession === 'function' && !(argsSignal && argsSignal.aborted)) {
1568
1614
  try {
1569
- honesty.edge = await runEdgePass({ driver, actionRecords, screenshots, observation: observations.length, signal: argsSignal, log });
1615
+ honesty.edge = await runEdgePass({ driver, actionRecords, screenshots, observation: observations.length, signal: argsSignal, log, avoid: avoidLinesOf(brief) });
1570
1616
  transcript.write({ kind: 'edge_pass', restored: honesty.edge.restored, elapsed_ms: honesty.edge.elapsedMs, checks: honesty.edge.checks.map(check => ({ name: check.name, status: check.status, detail: check.detail })) });
1571
1617
  for (const finding of edgeFindings(honesty.edge, { actionRecords, action: actions })) honesty.findings.push(finding);
1572
1618
  // A check whose blank screen part could not be told from the start is a limit of the runner, never a finding.
@@ -1583,14 +1629,19 @@ async function playLoop({
1583
1629
  // [tester hook] Input while the page loads: a reload, so it comes after the edge checks have asked their own reload what survived.
1584
1630
  if (probing && honesty.probes) {
1585
1631
  if (!probesStopped) try {
1586
- const loaded = await runTesterProbes({ driver, actionRecords, screenshots, observation: observations.length, signal: argsSignal, log, loading: true });
1632
+ const loaded = await runTesterProbes({ driver, actionRecords, screenshots, observation: observations.length, signal: argsSignal, log, loading: true, avoid: avoidLinesOf(brief) });
1587
1633
  honesty.probes.checks.push(...loaded.checks);
1588
1634
  honesty.probes.suspects.push(...loaded.suspects);
1635
+ honesty.probes.avoided = [...new Set([...(honesty.probes.avoided || []), ...(loaded.avoided || [])])];
1589
1636
  } catch (error) {
1590
1637
  transcript.write({ kind: 'tester_probes_failed', message: String(error && error.message) });
1591
1638
  }
1592
1639
  for (const finding of probeFindings(honesty.probes, { actionRecords, action: actions })) { if (honesty.findings.some(known => known.title === finding.title)) continue; honesty.findings.push(finding); transcript.write({ kind: 'runner_finding', key: finding.runner.key, title: finding.title }); }
1593
1640
  }
1641
+ // What the brief asks the run to stay out of, and what was left alone for it: the persona's own inputs the driver refused,
1642
+ // and the controls the probes and the edge checks did not press (./avoid.js). In the step log and in report.md.
1643
+ honesty.leftAlone = [...new Set([...(typeof driver.avoidedControls === 'function' ? driver.avoidedControls() : []), ...(honesty.probes?.avoided || []), ...(honesty.edge?.avoided || [])])];
1644
+ if (honesty.leftAlone.length) transcript.write({ kind: 'avoided', controls: honesty.leftAlone });
1594
1645
  // [tester hook] The tester probes a keyboard can make on a Godot game (./godotTesterProbes.js), before its edge checks start it a second time.
1595
1646
  if (edgePass && !gameEnded && !canceled && !budgetExceeded && driver.edgeKind === 'godot' && typeof driver.runFor === 'function' && !(argsSignal && argsSignal.aborted)) {
1596
1647
  try {
@@ -1616,6 +1667,13 @@ async function playLoop({
1616
1667
  }
1617
1668
  // [tester hook] What the runner's own ledger saw break a rule during play.
1618
1669
  for (const finding of testerFindings(honesty.tester, { actionRecords })) { if (honesty.findings.some(known => known.title === finding.title)) continue; honesty.findings.push(finding); transcript.write({ kind: 'runner_finding', key: finding.runner.key, title: finding.title }); }
1670
+ // The game's own events: every check after play is done, so the SDK is asked to send what it still holds before the page closes.
1671
+ if (driver && driver.gameEvents) {
1672
+ if (!gameEnded && !canceled && typeof driver.flushGameEvents === 'function') await Promise.resolve().then(() => driver.flushGameEvents()).catch(() => null);
1673
+ honesty.events = driver.gameEvents;
1674
+ const kept = driver.gameEvents.record();
1675
+ if (kept.total > 0) transcript.write({ kind: 'game_events', total: kept.total, kept: kept.kept, clock: kept.clock, names: kept.names });
1676
+ }
1619
1677
  return {
1620
1678
  actionsTaken: actions,
1621
1679
  turns,
@@ -1669,6 +1727,8 @@ async function reportPhase({
1669
1727
  play,
1670
1728
  startedAt,
1671
1729
  endedAt,
1730
+ // 'judge' (the claim judge) or 'legacy' (a run whose findings decide money elsewhere: ./judge.js legacyIssue).
1731
+ claimGate = 'judge',
1672
1732
  log
1673
1733
  }) {
1674
1734
  // The report step never sees the test account: it has nothing to sign in
@@ -1963,16 +2023,22 @@ async function reportPhase({
1963
2023
  // video keeps the screenshot it cites.
1964
2024
  let frames = new Map();
1965
2025
  const placed = new Set();
2026
+ const where = attachWhereToLook(report, { observations, notes, screenshots, video: honesty && honesty.video ? honesty.video : null, anchors: mergedAnchors(honesty) }).index;
1966
2027
  if (honesty && honesty.video) {
1967
- const where = attachWhereToLook(report, { observations, notes, screenshots, video: honesty.video, anchors: mergedAnchors(honesty) }).index;
1968
2028
  frames = await cutFindingFrames({ runDirectory, index: where, video: honesty.video, transcript, viewport: honesty.viewport || null, placed }).catch(() => new Map());
1969
2029
  }
2030
+ // The game's own events, when it sent any through its Ravensight SDK (./events.js): what the judge reads them from.
2031
+ const eventRun = gameEventsRun(honesty);
1970
2032
  let turnedAway = [];
2033
+ let impressions = [];
1971
2034
  if (!shrunk && !play.budgetExceeded) {
1972
- const checked = await checkClaimsAgainstScreenshots({ client, jobId, runId, report, screenshots, runDirectory, ledger, transcript, log, frames, measured: new Set(mergedAnchors(honesty).keys()), observations, notes });
2035
+ const impressionsAllowed = Boolean(reportSchema && reportSchema.properties && reportSchema.properties.impressions);
2036
+ const checked = await checkClaimsAgainstScreenshots({ client, jobId, runId, report, screenshots, runDirectory, ledger, transcript, log, frames, measured: new Set(mergedAnchors(honesty).keys()), observations, notes, index: where, run: eventRun, impressionsAllowed: impressionsAllowed && claimGate !== 'legacy', gate: claimGate });
1973
2037
  report = checked.report;
1974
2038
  turnedAway = checked.turnedAway;
2039
+ impressions = checked.impressions;
1975
2040
  if (turnedAway.length > 0) log(`${turnedAway.length} claim(s) of the playtester are not reported as findings: ${turnedAway.map(entry => `${entry.id} (${entry.outcome})`).join(', ')}; report.md lists them under "Raised by the playtester, not confirmed"`);
2041
+ if (impressions.length > 0) log(`${impressions.length} of the playtester's claims are its impressions, not findings: ${impressions.map(entry => `${entry.finding.id} as ${entry.id} (${entry.kind})`).join(', ')}; report.md lists them under "Playtester impressions"`);
1976
2042
  } else {
1977
2043
  transcript.write({ kind: 'claim_check_skipped', reason: play.budgetExceeded ? 'gameplay stopped for budget; preserving the report budget' : 'the report turn needed a smaller output ceiling to fit the budget' });
1978
2044
  }
@@ -1986,8 +2052,16 @@ async function reportPhase({
1986
2052
  }
1987
2053
  // The uploaded pair agree: report.md says the severity report.json does.
1988
2054
  if (downgradedByRunner.length > 0) markdown = rewriteDowngradedMarkdown(markdown, downgradedByRunner);
1989
- // A claim the checks turned away leaves every part of report.md that stood on it.
1990
- if (turnedAway.length > 0) markdown = sweepTurnedAway(markdown, turnedAway, report.findings || []);
2055
+ // A claim the checks turned away, or kept as an impression, leaves every part of report.md that stood on it as an issue.
2056
+ if (turnedAway.length > 0 || impressions.length > 0) markdown = sweepTurnedAway(markdown, turnedAway, report.findings || [], { impressions });
2057
+ // The playtester's impressions go into report.json beside the findings, never among them.
2058
+ if (impressions.length > 0) report = { ...report, impressions: impressions.map(({ finding, ...impression }) => impression) };
2059
+ // A finding the game's own events confirmed says so, and the report has a section on what they measured.
2060
+ if (eventRun) {
2061
+ withEventEvidence(report.findings || [], eventRun);
2062
+ const lines = eventsReportLines(eventRun, { findings: report.findings || [], turnedAway });
2063
+ if (lines.length > 0) markdown = replaceSection(markdown, EVENTS_HEADING, lines.slice(2).join('\n').replace(/\s+$/, ''));
2064
+ }
1991
2065
  // What a screenshot shows comes from the picture: one taken while the picture lagged the game says so.
1992
2066
  markdown = rewriteStaleEvidence(markdown, (screenshots || []).filter(shot => shot && shot.stale && shot.relativePath));
1993
2067
  if (choiceCheck) {
@@ -2027,7 +2101,21 @@ async function reportPhase({
2027
2101
  report = scrubSecrets(report, secrets);
2028
2102
 
2029
2103
  await writeReportFiles({ runDirectory, markdown, report });
2030
- return { report, markdown, lint, index: honest.index };
2104
+ return { report, markdown, lint, index: honest.index, turnedAway };
2105
+ }
2106
+
2107
+ /** The heading of the report's section on the game's own events, the hosted runner's own. */
2108
+ export const EVENTS_HEADING = '## Measured from the game\'s own events';
2109
+
2110
+ /**
2111
+ * What the claim judge and the report read the game's own events from: one
2112
+ * object per run (the verdicts are kept against it), or null when the driver
2113
+ * kept no event log.
2114
+ */
2115
+ export function gameEventsRun(honesty) {
2116
+ if (!honesty || !honesty.events || typeof honesty.events.record !== 'function') return null;
2117
+ if (!honesty.eventRun) honesty.eventRun = { gameEvents: honesty.events.record() };
2118
+ return honesty.eventRun;
2031
2119
  }
2032
2120
 
2033
2121
  /**
@@ -2084,12 +2172,21 @@ export function writeHonesty({ report: given, markdown, honesty, driverName, not
2084
2172
  }
2085
2173
  // [tester hook] What was and was not tested, from the runner's own ledger.
2086
2174
  if (honesty.probes) text = replaceSection(text, PROBES_HEADING, honesty.probes.godot ? godotProbesMarkdown(honesty.probes) : probesMarkdown(honesty.probes));
2175
+ if (Array.isArray(honesty.leftAlone) && honesty.leftAlone.length) text = replaceSection(text, AVOID_HEADING, avoidMarkdown(honesty.leftAlone));
2087
2176
  if (honesty.tester) text = replaceSection(text, TESTED_HEADING, testedMarkdown(honesty.tester, { edge: honesty.edge, probes: honesty.probes || null }));
2088
2177
  text = writeCapabilitySection(text, driverName, honesty.capability.list());
2089
2178
  if (located.index.length > 0) text = replaceSection(text, EVIDENCE_HEADING, whereToLookMarkdown(located.index, honesty.video));
2090
2179
  return { report: located.report, markdown: text, added, index: located.index };
2091
2180
  }
2092
2181
 
2182
+ /** The heading what the run left alone is written under in report.md. */
2183
+ export const AVOID_HEADING = '## Left alone, as the brief asks (written by the runner)';
2184
+
2185
+ /** What the run left alone because the brief asks to stay out of it, as that section's body. */
2186
+ export function avoidMarkdown(names) {
2187
+ return `No part of this run pressed what the brief asks to stay out of: the persona's own inputs on it were refused before they reached the game, and the scripted checks after play left it alone. Left alone: ${names.map(name => `"${String(name).replace(/"/g, "'")}"`).join(', ')}.`;
2188
+ }
2189
+
2093
2190
  /**
2094
2191
  * The most findings whose picture is checked against the claim: every issue
2095
2192
  * of a run, the most severe first, up to this many (about a third of a cent
@@ -2100,20 +2197,9 @@ export const MAX_CLAIM_CHECKS = 8;
2100
2197
  /** The severities a claim check is made on: every issue, never praise. */
2101
2198
  export const CLAIM_SEVERITIES = Object.freeze(['blocker', 'major', 'minor', 'cosmetic']);
2102
2199
 
2103
- /** Output ceiling for one claim check: the answer is one word. */
2200
+ /** Output ceiling for one claim check: the answer is a few words ("as designed" may quote the game's message). */
2104
2201
  export const CLAIM_CHECK_MAX_TOKENS = 32;
2105
2202
 
2106
- /**
2107
- * The instruction for a claim check. The answer says whether the picture
2108
- * shows what the claim says, not only whether it contradicts it: a claim of
2109
- * fact about the screen is published only when the picture shows it
2110
- * (./claimGate.js).
2111
- */
2112
- export const CLAIM_CHECK_SYSTEM = 'You check playtest findings against their evidence. You are shown one picture of the game at the moment of a claim (a frame of the session video, or a screenshot) and one claim about it. Answer with exactly one word: shows if the picture shows what the claim says (for a claim that something is missing, that it is not there), contradicts if the picture shows otherwise, unclear if the picture cannot settle it.';
2113
-
2114
- /** The question each claim check ends with. */
2115
- export const CLAIM_CHECK_QUESTION = 'Does this picture show what the claim says: shows, contradicts, unclear?';
2116
-
2117
2203
  /**
2118
2204
  * The screenshot a finding's claim is checked against: of those it cites, the
2119
2205
  * one taken nearest after the latest observation it cites (the later of two on
@@ -2146,120 +2232,152 @@ export function citedAfterScreenshot(finding, screenshots) {
2146
2232
  }
2147
2233
 
2148
2234
  /**
2149
- * Read a claim check answer from its first word: `shows`, `contradicts` or
2150
- * `unclear`. Anything else, and an empty answer, is `unclear`: an answer that
2151
- * cannot be read confirms nothing.
2152
- *
2153
- * @param {string} text
2154
- * @returns {'shows'|'contradicts'|'unclear'}
2155
- */
2156
- export function claimCheckAnswer(text) {
2157
- const match = String(text || '').match(/^[^A-Za-z]*(shows?|supports?|confirms?|contradicts?|unclear)\b/i);
2158
- if (!match) return 'unclear';
2159
- const word = match[1].toLowerCase();
2160
- return word.startsWith('contradict') ? 'contradicts' : word === 'unclear' ? 'unclear' : 'shows';
2161
- }
2162
-
2163
- /** How a claim check answer is written in the step log: the words the dashboard reads (yes is "the picture contradicts it"). */
2164
- export const CLAIM_ANSWER_IN_LOG = Object.freeze({ shows: 'no', contradicts: 'yes', unclear: 'unclear' });
2165
-
2166
- /**
2167
- * The bounded verification turn of the report step, and the gate after it.
2168
- * Every issue the report names, the most severe first and at most
2169
- * {@link MAX_CLAIM_CHECKS}, is sent once with the picture of its moment (the
2170
- * frame cut from the video, else the screenshot it cites) and asked whether
2171
- * the picture shows what it claims. Then ./claimGate.js decides: a claim the
2172
- * picture contradicts is never a finding; a claim of fact is one only when
2173
- * the picture shows it; an opinion of taste or difficulty stands when the
2174
- * picture cannot settle it. What the gate turns away leaves the report and is
2175
- * returned with its reason.
2176
- *
2177
- * A finding the runner itself saw happen (`measured`: a crash, a freeze or a
2178
- * blank screen the persona also reported, ./honesty.js) is not a claim and is
2179
- * not asked about.
2180
- *
2181
- * It goes to `persona_playtest.act`, the run's one step that accepts an image
2182
- * (the report step accepts none), with no tools and a one word ceiling, and
2183
- * it is spent from the same run budget the warning at 80 percent keeps for the
2184
- * report step. A refusal ends the checks; a claim it left unchecked is not
2185
- * confirmed by it.
2186
- *
2187
- * @returns {Promise<{report: Object, turnedAway: Array<Object>}>}
2188
- */
2189
- export async function checkClaimsAgainstScreenshots({ client, jobId, runId, report, screenshots, runDirectory, ledger, transcript, log = () => {}, frames = new Map(), measured = new Set(), observations = [], notes = [] }) {
2190
- if (!report || !Array.isArray(report.findings)) return { report, turnedAway: [] };
2191
- const where = new Map(attachWhereToLook(report, { observations, notes, screenshots }).index.filter(entry => entry.screenshot).map(entry => [entry.id, entry.screenshot]));
2192
- // Every issue, the most severe first; what worked is not checked.
2193
- const issues = report.findings.filter(finding => finding && CLAIM_SEVERITIES.includes(finding.severity) && !measured.has(finding.id))
2235
+ * The bounded verification turn of the report step, and the claim judge after
2236
+ * it (./judge.js, the hosted runner's rules). Every issue the report names, the
2237
+ * most severe first and at most {@link MAX_CLAIM_CHECKS}, is asked about once
2238
+ * with the picture of its moment and the hosted runner's own question
2239
+ * (./claimwords.js claimText): a claim of what the game did, or that something
2240
+ * is missing, is asked whether the GAME is at fault ("game at fault", "as
2241
+ * designed", "shows the opposite", "cannot tell"); a matter of taste is asked
2242
+ * whether the frame shows what it rests on; a judgement of how a marked canvas
2243
+ * game is drawn is asked about the game's own frame. A claim that something is
2244
+ * missing is also asked about the screen play was on before it.
2245
+ *
2246
+ * The picture: a judgement made from a look (it cites an observation, a note
2247
+ * made on one, or a screenshot) is checked on the screen that look saw, never
2248
+ * on the screen its next input led to; anything else on the frame cut just
2249
+ * after its moment, else the screenshot it cites.
2250
+ *
2251
+ * Then the judge decides each issue: a finding, a playtester impression (praise,
2252
+ * and taste whose frame shows what it rests on; see ./judge.js on money), or
2253
+ * turned away with its reason. The game's own events (./events.js) contradict
2254
+ * or confirm a claim before any picture does.
2255
+ *
2256
+ * A finding the runner itself saw happen (`measured`) is not a claim and is not
2257
+ * asked about. It goes to `persona_playtest.act`, the run's one step that
2258
+ * accepts an image, with no tools and a short ceiling, spent from the run
2259
+ * budget the report reserve keeps. A refusal ends the checks; a claim it left
2260
+ * unchecked is not confirmed by it.
2261
+ *
2262
+ * @returns {Promise<{report: Object, turnedAway: Array<Object>, impressions: Array<Object>}>}
2263
+ */
2264
+ export async function checkClaimsAgainstScreenshots({ client, jobId, runId, report, screenshots, runDirectory, ledger, transcript, log = () => {}, frames = new Map(), measured = new Set(), observations = [], notes = [], index = null, run = null, impressionsAllowed = true, gate = 'judge' }) {
2265
+ if (!report || !Array.isArray(report.findings)) return { report, turnedAway: [], impressions: [] };
2266
+ const placedIndex = Array.isArray(index) ? index : attachWhereToLook(report, { observations, notes, screenshots }).index;
2267
+ const where = new Map(placedIndex.map(entry => [entry.id, entry]));
2268
+ const judged = report.findings.filter(finding => finding && (CLAIM_SEVERITIES.includes(finding.severity) || finding.severity === 'praise') && !measured.has(finding.id));
2269
+ const shapes = new Map(judged.map(finding => [finding, claimShape(finding, { marked: Boolean(where.get(finding.id)?.marked) })]));
2270
+ // Every issue a question is asked about, the most severe first; praise and a judgement of its own play are not asked.
2271
+ const issues = judged.filter(finding => shapes.get(finding).question !== null || (gate === 'legacy' && shapes.get(finding).cls === 'difficulty'))
2194
2272
  .sort((a, b) => CLAIM_SEVERITIES.indexOf(a.severity) - CLAIM_SEVERITIES.indexOf(b.severity));
2195
2273
  const targets = issues.slice(0, MAX_CLAIM_CHECKS);
2196
2274
  const checks = new Map();
2275
+ const askedOf = question => (question === 'plain' ? {} : { question, ...(question === 'absence' || question === 'layout' ? { designed: true } : {}) });
2197
2276
  const skip = (finding, reason, shot = null, on = {}) => {
2198
- transcript.write({ kind: 'claim_check', id: finding.id, screenshot: shot, ...on, answer: 'skipped', reason });
2199
- checks.set(finding, { answer: 'skipped', reason });
2277
+ const question = shapes.get(finding).question;
2278
+ transcript.write({ kind: 'claim_check', id: finding.id, screenshot: shot, ...on, answer: 'skipped', reason, ...askedOf(question) });
2279
+ checks.set(finding, { answer: 'skipped', reason, ...askedOf(question) });
2200
2280
  };
2201
2281
  for (const finding of issues.slice(MAX_CLAIM_CHECKS)) skip(finding, `the run checks at most ${MAX_CLAIM_CHECKS} findings`);
2282
+ const ordered = (screenshots || []).filter(shot => shot && shot.relativePath && !shot.edge);
2202
2283
  let stopped = null;
2203
2284
  for (const finding of targets) {
2204
2285
  if (stopped) { skip(finding, stopped); continue; }
2205
- // The frame cut from the video at the finding's moment, else the screenshot it cites.
2286
+ const shape = shapes.get(finding);
2287
+ const placed = where.get(finding.id) || {};
2206
2288
  const frame = frames.get(finding.id) || null;
2207
- // Else the screenshot it cites, else the one the runner places at its moment (the one report.md's "Where to look" names).
2208
- const placedShot = where.get(finding.id);
2209
- const shot = frame ? { relativePath: frame.path } : citedAfterScreenshot(finding, screenshots) || (placedShot ? { relativePath: placedShot } : null);
2210
- const on = frame ? { frame: frame.path } : {};
2289
+ // A look's own screenshot, else the frame cut at its moment (for a look, the look's moment), else the screenshot it cites, else the one the runner places.
2290
+ const lookShot = placed.look && placed.look_shot ? { relativePath: placed.look_shot } : null;
2291
+ const shot = lookShot || (frame ? { relativePath: frame.path } : null) || citedAfterScreenshot(finding, screenshots) || (placed.screenshot ? { relativePath: placed.screenshot } : null);
2292
+ const on = !lookShot && frame ? { frame: frame.path } : {};
2211
2293
  if (!shot) { skip(finding, 'no frame of its moment and no cited screenshot'); continue; }
2212
- let data;
2213
- try {
2214
- data = (await readFile(path.join(runDirectory, shot.relativePath))).toString('base64');
2215
- } catch {
2216
- skip(finding, 'the picture could not be read', shot.relativePath, on);
2217
- continue;
2294
+ // A claim that something is missing is asked about the screen play was on before it too.
2295
+ const pictures = [shot.relativePath];
2296
+ if (shape.question === 'absence') {
2297
+ const at = ordered.findIndex(entry => entry.relativePath === shot.relativePath);
2298
+ const before = (at > 0 ? ordered.slice(0, at) : ordered.filter(entry => Number.isFinite(placed.look_observation ?? placed.action) && Number(entry.observation) < Number(placed.look_observation ?? Infinity)))
2299
+ .reverse().find(entry => entry.relativePath !== shot.relativePath);
2300
+ if (before) pictures.push(before.relativePath);
2218
2301
  }
2219
- let answer;
2220
- const askedAt = Date.now();
2221
- try {
2222
- answer = await callStepWithRetry({
2223
- client,
2224
- jobId,
2225
- runId,
2226
- step: STEPS.personaAct,
2227
- system: CLAIM_CHECK_SYSTEM,
2228
- messages: [{
2229
- role: 'user',
2230
- content: [
2231
- { type: 'image', source: { type: 'base64', media_type: /\.jpe?g$/i.test(shot.relativePath) ? 'image/jpeg' : 'image/png', data } },
2232
- { type: 'text', text: `Claim (${finding.severity}): ${finding.title || ''}\n${String(finding.description || '').slice(0, 1200)}\n\n${CLAIM_CHECK_QUESTION}` }
2233
- ]
2234
- }],
2235
- maxTokens: CLAIM_CHECK_MAX_TOKENS,
2236
- escalate: false,
2237
- maxAttempts: 1
2238
- });
2239
- } catch (error) {
2240
- const reason = error instanceof ProxyError && error.isBudget ? 'the run budget is spent' : String(error && error.message ? error.message : error);
2241
- skip(finding, reason, shot.relativePath, on);
2242
- // A refusal ends the checks, and every finding not reached says so; nothing is asked again.
2243
- stopped = reason;
2244
- log(`the screenshot check stopped (${reason}); a claim it did not reach is not confirmed by it.`);
2245
- continue;
2302
+ const question = claimText(finding, { cls: shape.cls === 'difficulty' ? 'other' : shape.cls, fault: shape.question !== null && shape.question !== 'plain' && shape.question !== 'layout' });
2303
+ const answers = [];
2304
+ for (const picture of pictures) {
2305
+ let data;
2306
+ try {
2307
+ data = (await readFile(path.join(runDirectory, picture))).toString('base64');
2308
+ } catch {
2309
+ if (picture === shot.relativePath) { skip(finding, 'the picture could not be read', picture, on); answers.length = 0; break; }
2310
+ continue;
2311
+ }
2312
+ let answer;
2313
+ const askedAt = Date.now();
2314
+ try {
2315
+ answer = await callStepWithRetry({
2316
+ client,
2317
+ jobId,
2318
+ runId,
2319
+ step: STEPS.personaAct,
2320
+ system: CLAIM_SYSTEM,
2321
+ messages: [{ role: 'user', content: [
2322
+ { type: 'image', source: { type: 'base64', media_type: /\.jpe?g$/i.test(picture) ? 'image/jpeg' : 'image/png', data } },
2323
+ { type: 'text', text: question }
2324
+ ] }],
2325
+ maxTokens: CLAIM_CHECK_MAX_TOKENS,
2326
+ escalate: false,
2327
+ maxAttempts: 1
2328
+ });
2329
+ } catch (error) {
2330
+ stopped = error instanceof ProxyError && error.isBudget ? 'the run budget is spent' : String(error && error.message ? error.message : error);
2331
+ log(`the screenshot check stopped (${stopped}); a claim it did not reach is not confirmed by it.`);
2332
+ break;
2333
+ }
2334
+ if (ledger) ledger.record({ model: answer.model, usage: answer.usage, ms: Date.now() - askedAt });
2335
+ const says = claimRead(answer.text) || 'cannot_tell';
2336
+ answers.push({ picture, says, message: says === 'as_designed' ? claimMessage(answer.text) : '' });
2337
+ // The thing it says is missing is on screen, or the game explained it: nothing more to ask.
2338
+ if (says === 'shows_opposite' || says === 'as_designed') break;
2246
2339
  }
2247
- if (ledger) ledger.record({ model: answer.model, usage: answer.usage, ms: Date.now() - askedAt });
2248
- const verdict = claimCheckAnswer(answer.text);
2249
- transcript.write({ kind: 'claim_check', id: finding.id, screenshot: shot.relativePath, ...on, answer: CLAIM_ANSWER_IN_LOG[verdict], question: 'shows' });
2250
- checks.set(finding, { answer: verdict, picture: shot.relativePath });
2340
+ if (checks.has(finding)) continue;
2341
+ if (answers.length === 0) { skip(finding, stopped || 'no picture could be read', shot.relativePath, on); continue; }
2342
+ // "Shows the opposite" on any picture is the opposite; "as designed" on any is the game working; "game at fault" only when every picture asked said so.
2343
+ const says = answers.some(a => a.says === 'shows_opposite') ? 'shows_opposite'
2344
+ : answers.some(a => a.says === 'as_designed') ? 'as_designed'
2345
+ : answers.every(a => a.says === 'at_fault') ? 'at_fault' : answers.find(a => a.says !== 'at_fault').says;
2346
+ const leftOut = says === 'shows_opposite' || says === 'as_designed' ? 0 : pictures.length - answers.length;
2347
+ const message = answers.find(a => a.message)?.message || '';
2348
+ const record = { says, answer: CLAIM_WIRE[says], ...askedOf(shape.question), frames: answers.length, ...(leftOut > 0 ? { left_out: leftOut } : {}), ...(message ? { message } : {}) };
2349
+ transcript.write({ kind: 'claim_check', id: finding.id, screenshot: shot.relativePath, ...on, ...(placed.look ? { look: true } : {}), ...record });
2350
+ checks.set(finding, { ...record, picture: shot.relativePath });
2251
2351
  }
2252
2352
  const turnedAway = [];
2353
+ const impressions = [];
2253
2354
  const findings = [];
2254
2355
  for (const finding of report.findings) {
2255
- if (!finding || !issues.includes(finding)) { findings.push(finding); continue; }
2256
- const gate = gateFinding(finding, checks.get(finding) || null);
2257
- if (gate.publish) { findings.push(finding); continue; }
2258
- const entry = { id: finding.id, severity: finding.severity, title: finding.title, claim: gate.kind, outcome: gate.outcome, reason: gate.reason, finding };
2259
- turnedAway.push(entry);
2260
- transcript.write({ kind: 'finding_not_confirmed', id: finding.id, severity: finding.severity, title: finding.title, claim: gate.kind, outcome: gate.outcome, reason: gate.reason });
2356
+ if (!finding || !shapes.has(finding)) { findings.push(finding); continue; }
2357
+ const placed = where.get(finding.id) || {};
2358
+ const step = Number.isInteger(placed.action) ? placed.action : null;
2359
+ // A run whose findings decide money elsewhere (a fix's verify, a Labs scenario) keeps the gate it had: see ./judge.js legacyIssue.
2360
+ const outcome = gate === 'legacy'
2361
+ ? legacyIssue(finding, { check: checks.get(finding) || null, marked: Boolean(placed.marked) })
2362
+ : judgeIssue(finding, { check: checks.get(finding) || null, run, step, marked: Boolean(placed.marked) });
2363
+ transcript.write({ kind: 'claim_judged', id: finding.id, route: outcome.route, outcome: outcome.outcome, cls: outcome.cls, ...(outcome.basis ? { basis: outcome.basis } : {}), ...(outcome.impression ? { impression: outcome.impression.kind } : {}), ...(outcome.evidence ? { evidence: outcome.evidence } : {}) });
2364
+ if (outcome.route === 'finding') { findings.push(finding); continue; }
2365
+ if (outcome.route === 'impression') {
2366
+ // A server whose report schema has no impressions keeps them as the findings they were: nothing is lost and no count moves.
2367
+ if (!impressionsAllowed) { findings.push(finding); continue; }
2368
+ impressions.push({ finding, outcome, step, placed });
2369
+ continue;
2370
+ }
2371
+ const picture = checks.get(finding)?.picture;
2372
+ const reason = outcome.reason.replace(/^the frame at its moment/, `the picture of its moment${picture ? ` (${picture})` : ''}`);
2373
+ turnedAway.push({ id: finding.id, severity: finding.severity, title: finding.title, claim: outcome.cls, outcome: outcome.outcome, reason, finding });
2374
+ transcript.write({ kind: 'finding_not_confirmed', id: finding.id, severity: finding.severity, title: finding.title, claim: outcome.cls, outcome: outcome.outcome, reason });
2261
2375
  }
2262
- return { report: turnedAway.length > 0 ? { ...report, findings } : report, turnedAway };
2376
+ // In the order the moments happened, the hosted runner's numbering.
2377
+ const list = impressions.map((entry, i) => ({ ...entry, i })).sort((a, b) => (a.step ?? Infinity) - (b.step ?? Infinity) || a.i - b.i)
2378
+ .map((entry, i) => ({ ...impressionOf(entry.finding, entry.outcome.impression, i + 1, entry.step, entry.placed), finding: entry.finding }));
2379
+ const changed = turnedAway.length > 0 || list.length > 0;
2380
+ return { report: changed ? { ...report, findings } : report, turnedAway, impressions: list };
2263
2381
  }
2264
2382
 
2265
2383
  /**
@@ -2769,7 +2887,7 @@ async function finish(outcome, ledger, runDirectory, transcript, heartbeat) {
2769
2887
  }
2770
2888
  outcome.usage = ledger.toReportUsage();
2771
2889
  outcome.duration = ledger.duration();
2772
- await writeUsageFile(runDirectory, ledger);
2890
+ await writeUsageFile(runDirectory, ledger, { gameEvents: outcome.gameEvents || null, gameMemory: outcome.gameMemory || null });
2773
2891
  transcript.write({ kind: 'end', state: outcome.state, quit_reason: outcome.quitReason, actions: outcome.actionsTaken });
2774
2892
  await transcript.close();
2775
2893
  return outcome;