ravensight-playtest 0.10.4 → 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.
- package/README.md +55 -17
- package/package.json +5 -4
- package/src/api/client.js +17 -1
- package/src/cli.js +4 -0
- package/src/commands/create.js +38 -4
- package/src/commands/fakeCore.js +2 -0
- package/src/commands/feature.js +14 -1
- package/src/commands/fix.js +2 -0
- package/src/commands/hosted.js +7 -3
- package/src/commands/run.js +34 -0
- package/src/hosted/recordedRun.js +42 -7
- package/src/run/anygame/gamenotes.js +208 -0
- package/src/run/anygame/shared-hashes.json +6 -2
- package/src/run/anygame/shared.js +8 -3
- package/src/run/claimGate.js +25 -73
- package/src/run/claimwords.js +242 -0
- package/src/run/drivers/godot.js +37 -1
- package/src/run/drivers/web.js +40 -0
- package/src/run/eventclaims.js +246 -0
- package/src/run/events.js +354 -0
- package/src/run/gameMemory.js +148 -0
- package/src/run/honesty.js +27 -1
- package/src/run/judge.js +229 -0
- package/src/run/personaLoop.js +217 -116
- package/src/run/reportChecks.js +13 -5
- package/src/run/usage.js +5 -2
package/src/run/personaLoop.js
CHANGED
|
@@ -29,7 +29,12 @@ import { recordingMetadata, saveRecording } from './drivers/recording.js';
|
|
|
29
29
|
import { createTranscript } from './transcript.js';
|
|
30
30
|
import { createUsageLedger, writeUsageFile } from './usage.js';
|
|
31
31
|
import { fillPlaceholders, fillReportPlaceholders } from './placeholders.js';
|
|
32
|
-
import {
|
|
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';
|
|
33
38
|
import { captureNotes, createCaptureWatch, rewriteStaleEvidence, staleSentence } from './captureCheck.js';
|
|
34
39
|
import { gameRefusal } from './gameRefusal.js';
|
|
35
40
|
import { BUILT_IN_NOISE, expectedNoiseForPrompt, isExpectedNoise } from './noise.js';
|
|
@@ -282,7 +287,9 @@ export async function runPersona(args) {
|
|
|
282
287
|
onProgress = () => {},
|
|
283
288
|
log = () => {},
|
|
284
289
|
recordVideo = false,
|
|
285
|
-
viewport
|
|
290
|
+
viewport,
|
|
291
|
+
// The game's playtest memory (./gameMemory.js): `{ save, notes, buildSha256 }`, or null.
|
|
292
|
+
memory = null
|
|
286
293
|
} = args;
|
|
287
294
|
|
|
288
295
|
const validator = createReportValidator(schemas);
|
|
@@ -414,6 +421,7 @@ export async function runPersona(args) {
|
|
|
414
421
|
onProgress({ phase: 'reporting', persona: persona.slug });
|
|
415
422
|
|
|
416
423
|
const written = await reportPhase({
|
|
424
|
+
claimGate: args.claimGate === 'legacy' ? 'legacy' : 'judge',
|
|
417
425
|
client,
|
|
418
426
|
jobId,
|
|
419
427
|
runId,
|
|
@@ -469,6 +477,17 @@ export async function runPersona(args) {
|
|
|
469
477
|
outcome.state = play.budgetExceeded ? 'budget_exceeded' : 'succeeded';
|
|
470
478
|
outcome.quitReason = play.budgetExceeded ? 'cost_cap' : written.report.quit_reason;
|
|
471
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
|
+
}
|
|
472
491
|
return finish(outcome, ledger, runDirectory, transcript, heartbeat);
|
|
473
492
|
} catch (error) {
|
|
474
493
|
await driverStop(driver, outcome, log, args.signal?.aborted ? 'canceled' : 'failed');
|
|
@@ -746,6 +765,8 @@ async function playLoop({
|
|
|
746
765
|
// The observation and action lines of the transcript, kept for the report
|
|
747
766
|
// step's "Actions you took" list and for a partial report.
|
|
748
767
|
actionRecords = [],
|
|
768
|
+
// The game's playtest memory (./gameMemory.js), carried in from runPersona's arguments.
|
|
769
|
+
memory: earlierMemory = null,
|
|
749
770
|
api,
|
|
750
771
|
controller = 'standard',
|
|
751
772
|
signal: argsSignal,
|
|
@@ -793,6 +814,12 @@ async function playLoop({
|
|
|
793
814
|
const briefFields = brief && brief.fields && typeof brief.fields === 'object' ? brief.fields : brief || {};
|
|
794
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 }));
|
|
795
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
|
+
}
|
|
796
823
|
system.push({ type: 'text', text: PLAY_NOTES });
|
|
797
824
|
if (typeof driver.soundSelfTest === 'function') anyGame.soundAvailable(await Promise.resolve().then(() => driver.soundSelfTest()).catch(() => null));
|
|
798
825
|
if (['jev', 'rune'].includes(controller)) system.push({ type: 'text', text: JEV_CONTROLLER_PROMPT });
|
|
@@ -914,6 +941,8 @@ async function playLoop({
|
|
|
914
941
|
// step and to a time in the video.
|
|
915
942
|
entry.at = Date.now();
|
|
916
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) || ''));
|
|
917
946
|
observations.push(entry);
|
|
918
947
|
// [tester hook] The screen goes on the coverage map and its text is checked.
|
|
919
948
|
if (honesty.tester) honesty.tester.observe({ index: observations.length, text: observation && observation.text, title: entry.title, actions });
|
|
@@ -1215,6 +1244,8 @@ async function playLoop({
|
|
|
1215
1244
|
? await safeScreenshot(driver, 'noted', screenshots, transcript, observations.length, keeper)
|
|
1216
1245
|
: null;
|
|
1217
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);
|
|
1218
1249
|
const ranAt = Date.now();
|
|
1219
1250
|
try {
|
|
1220
1251
|
executed = await executeTool({
|
|
@@ -1455,6 +1486,16 @@ async function playLoop({
|
|
|
1455
1486
|
// any-game hook: the play style once, and the notebook when screens have dropped out of context.
|
|
1456
1487
|
const anyAside = anyGame.aside({ actions, dropped: staleObservationCount(observations.length, keepObservations) });
|
|
1457
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
|
+
}
|
|
1458
1499
|
|
|
1459
1500
|
// The picture goes last, outside the tool results, so the cache
|
|
1460
1501
|
// breakpoint can sit before it (withPlayCacheBreakpoint).
|
|
@@ -1548,6 +1589,8 @@ async function playLoop({
|
|
|
1548
1589
|
const met = await Promise.resolve().then(() => driver.capabilityNotes()).catch(() => []);
|
|
1549
1590
|
for (const note of met || []) if (honesty.capability.add(note)) transcript.write({ kind: 'capability_note', input: note.input, reason: note.reason });
|
|
1550
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);
|
|
1551
1594
|
// [tester hook] The tester probes (./testerProbes.js): scripted, no model call, on the page play ended on, before the edge
|
|
1552
1595
|
// behaviour checks reload it. On the same switch as those checks.
|
|
1553
1596
|
const probing = edgePass && !gameEnded && !canceled && !budgetExceeded && typeof driver.edgeSession === 'function' && driverName === 'playwright_web' && !(argsSignal && argsSignal.aborted);
|
|
@@ -1624,6 +1667,13 @@ async function playLoop({
|
|
|
1624
1667
|
}
|
|
1625
1668
|
// [tester hook] What the runner's own ledger saw break a rule during play.
|
|
1626
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
|
+
}
|
|
1627
1677
|
return {
|
|
1628
1678
|
actionsTaken: actions,
|
|
1629
1679
|
turns,
|
|
@@ -1677,6 +1727,8 @@ async function reportPhase({
|
|
|
1677
1727
|
play,
|
|
1678
1728
|
startedAt,
|
|
1679
1729
|
endedAt,
|
|
1730
|
+
// 'judge' (the claim judge) or 'legacy' (a run whose findings decide money elsewhere: ./judge.js legacyIssue).
|
|
1731
|
+
claimGate = 'judge',
|
|
1680
1732
|
log
|
|
1681
1733
|
}) {
|
|
1682
1734
|
// The report step never sees the test account: it has nothing to sign in
|
|
@@ -1971,16 +2023,22 @@ async function reportPhase({
|
|
|
1971
2023
|
// video keeps the screenshot it cites.
|
|
1972
2024
|
let frames = new Map();
|
|
1973
2025
|
const placed = new Set();
|
|
2026
|
+
const where = attachWhereToLook(report, { observations, notes, screenshots, video: honesty && honesty.video ? honesty.video : null, anchors: mergedAnchors(honesty) }).index;
|
|
1974
2027
|
if (honesty && honesty.video) {
|
|
1975
|
-
const where = attachWhereToLook(report, { observations, notes, screenshots, video: honesty.video, anchors: mergedAnchors(honesty) }).index;
|
|
1976
2028
|
frames = await cutFindingFrames({ runDirectory, index: where, video: honesty.video, transcript, viewport: honesty.viewport || null, placed }).catch(() => new Map());
|
|
1977
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);
|
|
1978
2032
|
let turnedAway = [];
|
|
2033
|
+
let impressions = [];
|
|
1979
2034
|
if (!shrunk && !play.budgetExceeded) {
|
|
1980
|
-
const
|
|
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 });
|
|
1981
2037
|
report = checked.report;
|
|
1982
2038
|
turnedAway = checked.turnedAway;
|
|
2039
|
+
impressions = checked.impressions;
|
|
1983
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"`);
|
|
1984
2042
|
} else {
|
|
1985
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' });
|
|
1986
2044
|
}
|
|
@@ -1994,8 +2052,16 @@ async function reportPhase({
|
|
|
1994
2052
|
}
|
|
1995
2053
|
// The uploaded pair agree: report.md says the severity report.json does.
|
|
1996
2054
|
if (downgradedByRunner.length > 0) markdown = rewriteDowngradedMarkdown(markdown, downgradedByRunner);
|
|
1997
|
-
// A claim the checks turned away leaves every part of report.md that stood on it.
|
|
1998
|
-
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
|
+
}
|
|
1999
2065
|
// What a screenshot shows comes from the picture: one taken while the picture lagged the game says so.
|
|
2000
2066
|
markdown = rewriteStaleEvidence(markdown, (screenshots || []).filter(shot => shot && shot.stale && shot.relativePath));
|
|
2001
2067
|
if (choiceCheck) {
|
|
@@ -2035,7 +2101,21 @@ async function reportPhase({
|
|
|
2035
2101
|
report = scrubSecrets(report, secrets);
|
|
2036
2102
|
|
|
2037
2103
|
await writeReportFiles({ runDirectory, markdown, report });
|
|
2038
|
-
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;
|
|
2039
2119
|
}
|
|
2040
2120
|
|
|
2041
2121
|
/**
|
|
@@ -2117,20 +2197,9 @@ export const MAX_CLAIM_CHECKS = 8;
|
|
|
2117
2197
|
/** The severities a claim check is made on: every issue, never praise. */
|
|
2118
2198
|
export const CLAIM_SEVERITIES = Object.freeze(['blocker', 'major', 'minor', 'cosmetic']);
|
|
2119
2199
|
|
|
2120
|
-
/** Output ceiling for one claim check: the answer is
|
|
2200
|
+
/** Output ceiling for one claim check: the answer is a few words ("as designed" may quote the game's message). */
|
|
2121
2201
|
export const CLAIM_CHECK_MAX_TOKENS = 32;
|
|
2122
2202
|
|
|
2123
|
-
/**
|
|
2124
|
-
* The instruction for a claim check. The answer says whether the picture
|
|
2125
|
-
* shows what the claim says, not only whether it contradicts it: a claim of
|
|
2126
|
-
* fact about the screen is published only when the picture shows it
|
|
2127
|
-
* (./claimGate.js).
|
|
2128
|
-
*/
|
|
2129
|
-
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.';
|
|
2130
|
-
|
|
2131
|
-
/** The question each claim check ends with. */
|
|
2132
|
-
export const CLAIM_CHECK_QUESTION = 'Does this picture show what the claim says: shows, contradicts, unclear?';
|
|
2133
|
-
|
|
2134
2203
|
/**
|
|
2135
2204
|
* The screenshot a finding's claim is checked against: of those it cites, the
|
|
2136
2205
|
* one taken nearest after the latest observation it cites (the later of two on
|
|
@@ -2163,120 +2232,152 @@ export function citedAfterScreenshot(finding, screenshots) {
|
|
|
2163
2232
|
}
|
|
2164
2233
|
|
|
2165
2234
|
/**
|
|
2166
|
-
*
|
|
2167
|
-
*
|
|
2168
|
-
*
|
|
2169
|
-
*
|
|
2170
|
-
*
|
|
2171
|
-
*
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
*
|
|
2185
|
-
*
|
|
2186
|
-
*
|
|
2187
|
-
*
|
|
2188
|
-
*
|
|
2189
|
-
*
|
|
2190
|
-
* the
|
|
2191
|
-
*
|
|
2192
|
-
*
|
|
2193
|
-
*
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
*
|
|
2204
|
-
* @returns {Promise<{report: Object, turnedAway: Array<Object>}>}
|
|
2205
|
-
*/
|
|
2206
|
-
export async function checkClaimsAgainstScreenshots({ client, jobId, runId, report, screenshots, runDirectory, ledger, transcript, log = () => {}, frames = new Map(), measured = new Set(), observations = [], notes = [] }) {
|
|
2207
|
-
if (!report || !Array.isArray(report.findings)) return { report, turnedAway: [] };
|
|
2208
|
-
const where = new Map(attachWhereToLook(report, { observations, notes, screenshots }).index.filter(entry => entry.screenshot).map(entry => [entry.id, entry.screenshot]));
|
|
2209
|
-
// Every issue, the most severe first; what worked is not checked.
|
|
2210
|
-
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'))
|
|
2211
2272
|
.sort((a, b) => CLAIM_SEVERITIES.indexOf(a.severity) - CLAIM_SEVERITIES.indexOf(b.severity));
|
|
2212
2273
|
const targets = issues.slice(0, MAX_CLAIM_CHECKS);
|
|
2213
2274
|
const checks = new Map();
|
|
2275
|
+
const askedOf = question => (question === 'plain' ? {} : { question, ...(question === 'absence' || question === 'layout' ? { designed: true } : {}) });
|
|
2214
2276
|
const skip = (finding, reason, shot = null, on = {}) => {
|
|
2215
|
-
|
|
2216
|
-
|
|
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) });
|
|
2217
2280
|
};
|
|
2218
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);
|
|
2219
2283
|
let stopped = null;
|
|
2220
2284
|
for (const finding of targets) {
|
|
2221
2285
|
if (stopped) { skip(finding, stopped); continue; }
|
|
2222
|
-
|
|
2286
|
+
const shape = shapes.get(finding);
|
|
2287
|
+
const placed = where.get(finding.id) || {};
|
|
2223
2288
|
const frame = frames.get(finding.id) || null;
|
|
2224
|
-
//
|
|
2225
|
-
const
|
|
2226
|
-
const shot = frame ? { relativePath: frame.path } : citedAfterScreenshot(finding, screenshots) || (
|
|
2227
|
-
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 } : {};
|
|
2228
2293
|
if (!shot) { skip(finding, 'no frame of its moment and no cited screenshot'); continue; }
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
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);
|
|
2235
2301
|
}
|
|
2236
|
-
|
|
2237
|
-
const
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
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;
|
|
2263
2339
|
}
|
|
2264
|
-
if (
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
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 });
|
|
2268
2351
|
}
|
|
2269
2352
|
const turnedAway = [];
|
|
2353
|
+
const impressions = [];
|
|
2270
2354
|
const findings = [];
|
|
2271
2355
|
for (const finding of report.findings) {
|
|
2272
|
-
if (!finding || !
|
|
2273
|
-
const
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
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 });
|
|
2278
2375
|
}
|
|
2279
|
-
|
|
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 };
|
|
2280
2381
|
}
|
|
2281
2382
|
|
|
2282
2383
|
/**
|
|
@@ -2786,7 +2887,7 @@ async function finish(outcome, ledger, runDirectory, transcript, heartbeat) {
|
|
|
2786
2887
|
}
|
|
2787
2888
|
outcome.usage = ledger.toReportUsage();
|
|
2788
2889
|
outcome.duration = ledger.duration();
|
|
2789
|
-
await writeUsageFile(runDirectory, ledger);
|
|
2890
|
+
await writeUsageFile(runDirectory, ledger, { gameEvents: outcome.gameEvents || null, gameMemory: outcome.gameMemory || null });
|
|
2790
2891
|
transcript.write({ kind: 'end', state: outcome.state, quit_reason: outcome.quitReason, actions: outcome.actionsTaken });
|
|
2791
2892
|
await transcript.close();
|
|
2792
2893
|
return outcome;
|
package/src/run/reportChecks.js
CHANGED
|
@@ -99,6 +99,8 @@ export function screenOf(text, url) {
|
|
|
99
99
|
export const FRAME_AFTER_MS = 600;
|
|
100
100
|
/** How far back a second try at a frame goes when the first could not be cut. */
|
|
101
101
|
export const FRAME_RETRY_BACK_MS = 1000;
|
|
102
|
+
/** A look's frame, when its own moment cannot be cut, is tried this much earlier: the screen it saw had stood since its last input settled. */
|
|
103
|
+
export const LOOK_RETRY_BACK_MS = 300;
|
|
102
104
|
export const FRAME_WIDTH = 960;
|
|
103
105
|
export const FRAME_TIMEOUT_MS = 20000;
|
|
104
106
|
/** Frames cut for one run at most. */
|
|
@@ -149,7 +151,9 @@ export async function cutFrame({ ffmpeg, video, atMs, out, width = FRAME_WIDTH,
|
|
|
149
151
|
*/
|
|
150
152
|
export async function cutFindingFrames({ runDirectory, index = [], video = null, transcript, viewport = null, detect = detectFfmpeg, cut = cutFrame, placed = new Set() }) {
|
|
151
153
|
const frames = new Map();
|
|
152
|
-
|
|
154
|
+
// A judgement made from a look is cut at the look's own moment: the screen the playtester saw, before the next input.
|
|
155
|
+
const momentOf = entry => (entry.look && Number.isFinite(entry.look_ms) ? entry.look_ms : entry.video_ms);
|
|
156
|
+
const wanted = index.filter(entry => entry && typeof entry.id === 'string' && Number.isFinite(momentOf(entry)) && !placed.has(entry.id)).slice(0, MAX_FRAMES);
|
|
153
157
|
if (!video || !video.file || wanted.length === 0) return frames;
|
|
154
158
|
let ffmpeg = null;
|
|
155
159
|
try { ffmpeg = (await detect())?.path || null; } catch { ffmpeg = null; }
|
|
@@ -167,7 +171,11 @@ export async function cutFindingFrames({ runDirectory, index = [], video = null,
|
|
|
167
171
|
// last moments of a recording that ended under a freeze is often past
|
|
168
172
|
// the last frame the file can seek to.
|
|
169
173
|
let at = null;
|
|
170
|
-
|
|
174
|
+
const looked = entry.look && Number.isFinite(entry.look_ms);
|
|
175
|
+
const candidates = looked
|
|
176
|
+
? [Math.round(Math.min(entry.look_ms, end)), Math.round(Math.max(0, Math.min(entry.look_ms, end) - LOOK_RETRY_BACK_MS))]
|
|
177
|
+
: [Math.round(Math.min(entry.video_ms + FRAME_AFTER_MS, end)), Math.round(Math.max(0, Math.min(entry.video_ms, end) - FRAME_RETRY_BACK_MS))];
|
|
178
|
+
for (const candidate of candidates) {
|
|
171
179
|
let ok = false;
|
|
172
180
|
try { ok = await cut({ ffmpeg, video: file, atMs: candidate, out: path.join(runDirectory, relative) }); } catch { ok = false; }
|
|
173
181
|
if (ok) { at = candidate; break; }
|
|
@@ -175,11 +183,11 @@ export async function cutFindingFrames({ runDirectory, index = [], video = null,
|
|
|
175
183
|
if (at === null) {
|
|
176
184
|
// No picture, but the moment stands: the dashboard places the finding
|
|
177
185
|
// at this step rather than at whatever screenshot it happens to cite.
|
|
178
|
-
transcript.write({ kind: 'finding_frame', id: entry.id, path: null, source: 'none', reason: 'no frame could be cut from the video at this moment', video_ms: Math.round(entry
|
|
186
|
+
transcript.write({ kind: 'finding_frame', id: entry.id, path: null, source: 'none', reason: 'no frame could be cut from the video at this moment', video_ms: Math.round(momentOf(entry)), ...step, ...(looked ? { look: true } : {}) });
|
|
179
187
|
continue;
|
|
180
188
|
}
|
|
181
|
-
frames.set(entry.id, { path: relative, video_ms: at });
|
|
182
|
-
transcript.write({ kind: 'finding_frame', id: entry.id, path: relative, source: 'video', video_ms: at, ...step, ...(viewport && viewport.width > 0 && viewport.height > 0 ? { viewport: { width: viewport.width, height: viewport.height } } : {}) });
|
|
189
|
+
frames.set(entry.id, { path: relative, video_ms: at, ...(looked ? { look: true } : {}) });
|
|
190
|
+
transcript.write({ kind: 'finding_frame', id: entry.id, path: relative, source: 'video', video_ms: at, ...step, ...(looked ? { look: true } : {}), ...(viewport && viewport.width > 0 && viewport.height > 0 ? { viewport: { width: viewport.width, height: viewport.height } } : {}) });
|
|
183
191
|
}
|
|
184
192
|
return frames;
|
|
185
193
|
}
|
package/src/run/usage.js
CHANGED
|
@@ -173,9 +173,12 @@ export function weightedUnits(usage = {}) {
|
|
|
173
173
|
* @param {ReturnType<typeof createUsageLedger>} ledger
|
|
174
174
|
* @returns {Promise<string>} the path written
|
|
175
175
|
*/
|
|
176
|
-
export async function writeUsageFile(runDirectory, ledger) {
|
|
176
|
+
export async function writeUsageFile(runDirectory, ledger, extra = {}) {
|
|
177
177
|
const target = path.join(runDirectory, RUN_FILES.usageJson);
|
|
178
|
-
|
|
178
|
+
// What the run measured beside its spend, as the hosted runner's usage.json carries it: the game's own events
|
|
179
|
+
// (`gameEvents`) and the notes it hands on to the next playtest of the game (`gameMemory`). Absent when there are none.
|
|
180
|
+
const more = Object.fromEntries(Object.entries(extra || {}).filter(([, value]) => value !== null && value !== undefined));
|
|
181
|
+
const body = `${JSON.stringify({ ...ledger.toUsageFile(), ...more }, null, 2)}\n`;
|
|
179
182
|
// Token counts and model ids should never look secret shaped, and that is
|
|
180
183
|
// the point of checking: this file is uploaded by default, so anything
|
|
181
184
|
// unexpected in it is refused rather than shipped.
|