ravensight-playtest 0.10.0 → 0.10.2
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 +34 -10
- package/addons/ravensight_driver/driver.gd +41 -3
- package/docs/godot-driver.md +9 -0
- package/package.json +3 -3
- package/src/cli.js +51 -0
- package/src/commands/check.js +50 -9
- package/src/commands/fakeCore.js +14 -2
- package/src/commands/run.js +29 -1
- package/src/run/captureCheck.js +161 -0
- package/src/run/claimGate.js +236 -0
- package/src/run/honesty.js +104 -6
- package/src/run/personaLoop.js +150 -63
- package/src/run/reportChecks.js +22 -7
package/src/run/personaLoop.js
CHANGED
|
@@ -15,7 +15,7 @@ import { assertNoSecrets, scanForSecrets } from './secretScan.js';
|
|
|
15
15
|
import { ACTION_TOOLS, NEW_TOOL_NAMES, REPORT_TOOLS, executeTool, expectationOf, modelFrameOf, toolResult, toolsFor, NEWEST_TOOL_NAMES } from './tools.js';
|
|
16
16
|
import {
|
|
17
17
|
CAPABILITY_HEADING, DIALOGS_HEADING, EVIDENCE_HEADING, MAX_WIN_CONTINUES, RUNNER_FINDINGS_HEADING, WIN_TEXT,
|
|
18
|
-
addRunnerFindings, attachWhereToLook, blankFinding, capabilityPrompt, createBlankWatch, createCapabilityLedger, describeInput, dialogNote, gameEndedFinding, gameEndedOf,
|
|
18
|
+
addRunnerFindings, attachWhereToLook, blankFinding, capabilityPrompt, createBlankWatch, createCapabilityLedger, describeInput, dialogNote, gameEndedFinding, gameEndedOf, mergeRunnerDuplicates,
|
|
19
19
|
playOnText, replaceSection, runnerFinding, runnerFindingsMarkdown, stepsBefore, whereToLookMarkdown, writeCapabilitySection
|
|
20
20
|
} from './honesty.js';
|
|
21
21
|
import { runEdgePass, edgeFindings, edgeMarkdown, EDGE_HEADING, blankCapabilityNote } from './edgePass.js';
|
|
@@ -28,6 +28,8 @@ import { recordingMetadata, saveRecording } from './drivers/recording.js';
|
|
|
28
28
|
import { createTranscript } from './transcript.js';
|
|
29
29
|
import { createUsageLedger, writeUsageFile } from './usage.js';
|
|
30
30
|
import { fillPlaceholders, fillReportPlaceholders } from './placeholders.js';
|
|
31
|
+
import { gateFinding, sweepTurnedAway } from './claimGate.js';
|
|
32
|
+
import { captureNotes, createCaptureWatch, rewriteStaleEvidence, staleSentence } from './captureCheck.js';
|
|
31
33
|
import { gameRefusal } from './gameRefusal.js';
|
|
32
34
|
import { BUILT_IN_NOISE, expectedNoiseForPrompt, isExpectedNoise } from './noise.js';
|
|
33
35
|
import { cutFindingFrames, moodOf, replayCapabilityNote, replayFindings, replayWebFindings, screenOf, traceWebInputs } from './reportChecks.js';
|
|
@@ -820,7 +822,10 @@ async function playLoop({
|
|
|
820
822
|
// What a driver has to say about how this run is played (touch on a phone screen).
|
|
821
823
|
if (driver && typeof driver.playNote === 'string' && driver.playNote) system.push({ type: 'text', text: driver.playNote });
|
|
822
824
|
const blankWatch = createBlankWatch();
|
|
825
|
+
// Whether the pictures keep up with the game (./captureCheck.js).
|
|
826
|
+
const capture = createCaptureWatch();
|
|
823
827
|
let gameEnded = null;
|
|
828
|
+
let gameEndedAt = null;
|
|
824
829
|
let winContinues = 0;
|
|
825
830
|
const recentActions = [];
|
|
826
831
|
let latestObservation = '';
|
|
@@ -1240,6 +1245,9 @@ async function playLoop({
|
|
|
1240
1245
|
const ended = await gameEndedOf(driver, error);
|
|
1241
1246
|
if (!ended) throw error;
|
|
1242
1247
|
const line = { kind: 'action', tool: toolUse.name, input: redactToolInput(toolUse, secrets), thought: null, ok: false, error: ended.message, changed: false, actions: actions + (ACTION_TOOLS.includes(toolUse.name) ? 1 : 0) };
|
|
1248
|
+
// The moment the game ended is this input's line in the step log: the
|
|
1249
|
+
// dashboard places the finding there, so report.md does too.
|
|
1250
|
+
gameEndedAt = Date.now();
|
|
1243
1251
|
transcript.write(line);
|
|
1244
1252
|
actionRecords.push(line);
|
|
1245
1253
|
if (ACTION_TOOLS.includes(toolUse.name)) actions += 1;
|
|
@@ -1326,6 +1334,7 @@ async function playLoop({
|
|
|
1326
1334
|
// through the next inputs is a blank screen, found by the runner.
|
|
1327
1335
|
if (executed.observation && !executed.observation.dialog && (ACTION_TOOLS.includes(toolUse.name) || toolUse.name === 'wait') && typeof driver.screenProbe === 'function') {
|
|
1328
1336
|
const probe = await Promise.resolve().then(() => driver.screenProbe()).catch(() => null);
|
|
1337
|
+
capture.after({ action: actions, observation: observations.length, changed: executed.changed, png: probe, text: executed.observation.text });
|
|
1329
1338
|
const label = describeInput({ tool: toolUse.name, input: redactToolInput(toolUse, secrets) });
|
|
1330
1339
|
if (blankWatch.check(probe, { action: actions, label }) === 'confirmed') {
|
|
1331
1340
|
const shot = await safeScreenshot(driver, 'blank-screen', screenshots, transcript, observations.length, keeper);
|
|
@@ -1351,7 +1360,7 @@ async function playLoop({
|
|
|
1351
1360
|
const shot = gameEnded.kind === 'frozen' ? await safeScreenshot(driver, 'frozen', screenshots, transcript, observations.length, keeper) : null;
|
|
1352
1361
|
const last = [...screenshots].reverse().find(entry => entry && entry.relativePath);
|
|
1353
1362
|
if (gameEnded.kind !== 'exited') {
|
|
1354
|
-
const finding = gameEndedFinding(gameEnded, { actionRecords, screenshot: shot ? shot.relativePath : last ? last.relativePath : null, action: actions, errors });
|
|
1363
|
+
const finding = gameEndedFinding(gameEnded, { actionRecords, screenshot: shot ? shot.relativePath : last ? last.relativePath : null, action: actions, errors, at: gameEndedAt });
|
|
1355
1364
|
honesty.findings.push(finding);
|
|
1356
1365
|
transcript.write({ kind: 'runner_finding', key: `game_${gameEnded.kind}`, title: finding.title, action: actions });
|
|
1357
1366
|
}
|
|
@@ -1502,7 +1511,17 @@ async function playLoop({
|
|
|
1502
1511
|
}
|
|
1503
1512
|
|
|
1504
1513
|
const final = gameEnded ? null : await safeScreenshot(driver, 'final', screenshots, transcript, observations.length, keeper);
|
|
1505
|
-
|
|
1514
|
+
// The pictures of the run, counted by what they show, and every stretch in
|
|
1515
|
+
// which the game moved on and its picture did not: limits of the runner, and
|
|
1516
|
+
// a screenshot taken in one is said to be of the earlier moment it shows.
|
|
1517
|
+
const pictures = capture.summary();
|
|
1518
|
+
for (const shot of screenshots) {
|
|
1519
|
+
const stale = Number.isInteger(shot.observation) ? capture.staleAt(shot.observation) : null;
|
|
1520
|
+
if (stale) shot.stale = stale;
|
|
1521
|
+
}
|
|
1522
|
+
transcript.write({ kind: 'capture_check', inputs: pictures.inputs, pictures: pictures.pictures, stale: pictures.stretches.map(stretch => ({ from: stretch.from, to: stretch.to, inputs: stretch.inputs, shows_action: stretch.freshAction })), stale_screenshots: screenshots.filter(shot => shot.stale).map(shot => shot.relativePath) });
|
|
1523
|
+
for (const note of captureNotes(pictures)) if (honesty.capability.add(note)) transcript.write({ kind: 'capability_note', input: note.input, reason: note.reason });
|
|
1524
|
+
transcript.write({ kind: 'play_summary', actions, turns, observations: observations.length, screenshots: screenshots.length, distinct_screens: keeper.distinctScreens, distinct_pictures: pictures.pictures, scenes: keeper.scenes, model_declined: declined, clock: clock.read() });
|
|
1506
1525
|
// The last screen as the model is shown it, for the brief choice check.
|
|
1507
1526
|
const finalFrame = brief && !gameEnded ? await modelFrameOf(driver) : null;
|
|
1508
1527
|
|
|
@@ -1930,22 +1949,25 @@ async function reportPhase({
|
|
|
1930
1949
|
// after the report is settled, so a refusal can cost the check and never
|
|
1931
1950
|
// the report.
|
|
1932
1951
|
report = scrubSecrets(report, secrets);
|
|
1952
|
+
// A crash, a freeze or a blank screen the runner saw and the report also
|
|
1953
|
+
// names is one finding, counted once, at the moment it happened.
|
|
1954
|
+
report = mergeRunnerTwins({ report, honesty, observations, transcript, log });
|
|
1933
1955
|
// A frame for each finding, cut from the session video at the finding's own
|
|
1934
1956
|
// moment: it is what the claim check looks at, and what the report in the
|
|
1935
1957
|
// dashboard shows. No model call; a finding the run cannot place in the
|
|
1936
1958
|
// video keeps the screenshot it cites.
|
|
1937
1959
|
let frames = new Map();
|
|
1960
|
+
const placed = new Set();
|
|
1938
1961
|
if (honesty && honesty.video) {
|
|
1939
|
-
const where = attachWhereToLook(report, { observations, notes, screenshots, video: honesty.video }).index;
|
|
1940
|
-
frames = await cutFindingFrames({ runDirectory, index: where, video: honesty.video, transcript, viewport: honesty.viewport || null }).catch(() => new Map());
|
|
1962
|
+
const where = attachWhereToLook(report, { observations, notes, screenshots, video: honesty.video, anchors: mergedAnchors(honesty) }).index;
|
|
1963
|
+
frames = await cutFindingFrames({ runDirectory, index: where, video: honesty.video, transcript, viewport: honesty.viewport || null, placed }).catch(() => new Map());
|
|
1941
1964
|
}
|
|
1965
|
+
let turnedAway = [];
|
|
1942
1966
|
if (!shrunk && !play.budgetExceeded) {
|
|
1943
|
-
const checked = await checkClaimsAgainstScreenshots({ client, jobId, runId, report, screenshots, runDirectory, ledger, transcript, log, frames });
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
log(`downgraded ${checked.downgraded.length} finding(s) their own screenshot contradicts: ${checked.downgraded.map(entry => `${entry.id} (${entry.from} to ${entry.to}, ${entry.screenshot})`).join(', ')}`);
|
|
1948
|
-
}
|
|
1967
|
+
const checked = await checkClaimsAgainstScreenshots({ client, jobId, runId, report, screenshots, runDirectory, ledger, transcript, log, frames, measured: new Set(mergedAnchors(honesty).keys()), observations, notes });
|
|
1968
|
+
report = checked.report;
|
|
1969
|
+
turnedAway = checked.turnedAway;
|
|
1970
|
+
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"`);
|
|
1949
1971
|
} else {
|
|
1950
1972
|
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' });
|
|
1951
1973
|
}
|
|
@@ -1959,6 +1981,10 @@ async function reportPhase({
|
|
|
1959
1981
|
}
|
|
1960
1982
|
// The uploaded pair agree: report.md says the severity report.json does.
|
|
1961
1983
|
if (downgradedByRunner.length > 0) markdown = rewriteDowngradedMarkdown(markdown, downgradedByRunner);
|
|
1984
|
+
// A claim the checks turned away leaves every part of report.md that stood on it.
|
|
1985
|
+
if (turnedAway.length > 0) markdown = sweepTurnedAway(markdown, turnedAway, report.findings || []);
|
|
1986
|
+
// What a screenshot shows comes from the picture: one taken while the picture lagged the game says so.
|
|
1987
|
+
markdown = rewriteStaleEvidence(markdown, (screenshots || []).filter(shot => shot && shot.stale && shot.relativePath));
|
|
1962
1988
|
if (choiceCheck) {
|
|
1963
1989
|
markdown = writeChoiceIntoMarkdown(markdown, choiceCheck);
|
|
1964
1990
|
await writeFile(path.join(runDirectory, CHOICE_CHECK_FILE), `${JSON.stringify(choiceCheck, null, 2)}\n`, 'utf8');
|
|
@@ -1990,7 +2016,7 @@ async function reportPhase({
|
|
|
1990
2016
|
if (honest.added.length > 0) log(`the runner added ${honest.added.length} finding(s) of its own: ${honest.added.map(finding => `${finding.id} (${finding.title})`).join(', ')}`);
|
|
1991
2017
|
if (honest.index.length > 0) transcript.write({ kind: 'where_to_look', findings: honest.index });
|
|
1992
2018
|
// The runner's own findings were added just now: each gets its frame too.
|
|
1993
|
-
if (honesty && honesty.video) await cutFindingFrames({ runDirectory, index: honest.index.filter(entry => !frames.has(entry.id)), video: honesty.video, transcript, viewport: honesty.viewport || null }).catch(() => null);
|
|
2019
|
+
if (honesty && honesty.video) await cutFindingFrames({ runDirectory, index: honest.index.filter(entry => !frames.has(entry.id)), video: honesty.video, transcript, viewport: honesty.viewport || null, placed }).catch(() => null);
|
|
1994
2020
|
// Whatever the model wrote, the password does not leave in a report.
|
|
1995
2021
|
markdown = scrubSecrets(markdown, secrets);
|
|
1996
2022
|
report = scrubSecrets(report, secrets);
|
|
@@ -1999,6 +2025,32 @@ async function reportPhase({
|
|
|
1999
2025
|
return { report, markdown, lint, index: honest.index };
|
|
2000
2026
|
}
|
|
2001
2027
|
|
|
2028
|
+
/**
|
|
2029
|
+
* Fold each runner finding the report also names into the report's own
|
|
2030
|
+
* (./honesty.js mergeRunnerDuplicates), once per run: the runner's list keeps
|
|
2031
|
+
* only what the report did not name, and `honesty.merged` says which ids now
|
|
2032
|
+
* carry the runner's evidence and moment.
|
|
2033
|
+
*
|
|
2034
|
+
* @returns {Object} the report
|
|
2035
|
+
*/
|
|
2036
|
+
export function mergeRunnerTwins({ report, honesty, observations = [], transcript = null, log = () => {} }) {
|
|
2037
|
+
if (!honesty || !report || !Array.isArray(honesty.findings) || honesty.findings.length === 0) return report;
|
|
2038
|
+
const result = mergeRunnerDuplicates(report, honesty.findings, { observations });
|
|
2039
|
+
if (result.merged.length === 0) return report;
|
|
2040
|
+
honesty.findings = result.rest;
|
|
2041
|
+
honesty.merged = [...(honesty.merged || []), ...result.merged];
|
|
2042
|
+
for (const entry of result.merged) {
|
|
2043
|
+
if (transcript) transcript.write({ kind: 'finding_merged', id: entry.id, runner: entry.key, action: Number.isInteger(entry.anchor.action) ? entry.anchor.action : null, from: entry.from, severity: entry.severity });
|
|
2044
|
+
log(`${entry.id} and the runner's own finding are the same event (${entry.key}); they are one finding, ${entry.severity}`);
|
|
2045
|
+
}
|
|
2046
|
+
return result.report;
|
|
2047
|
+
}
|
|
2048
|
+
|
|
2049
|
+
/** The moments of the report's findings that are also the runner's, by id. */
|
|
2050
|
+
export function mergedAnchors(honesty) {
|
|
2051
|
+
return new Map(((honesty && honesty.merged) || []).map(entry => [entry.id, entry.anchor]));
|
|
2052
|
+
}
|
|
2053
|
+
|
|
2002
2054
|
/**
|
|
2003
2055
|
* Write what the runner itself knows into a finished report: its own findings
|
|
2004
2056
|
* (after the report's), for every finding the step, a screenshot and a video
|
|
@@ -2007,14 +2059,20 @@ async function reportPhase({
|
|
|
2007
2059
|
* @param {Object} args
|
|
2008
2060
|
* @returns {{report: Object, markdown: string, added: Array<Object>, index: Array<Object>}}
|
|
2009
2061
|
*/
|
|
2010
|
-
export function writeHonesty({ report, markdown, honesty, driverName, notes = [], screenshots = [], observations = [] }) {
|
|
2011
|
-
if (!honesty || !
|
|
2062
|
+
export function writeHonesty({ report: given, markdown, honesty, driverName, notes = [], screenshots = [], observations = [] }) {
|
|
2063
|
+
if (!honesty || !given) return { report: given, markdown, added: [], index: [] };
|
|
2064
|
+
// A report that did not pass through the claim checks (a fallback report) is merged here.
|
|
2065
|
+
const report = mergeRunnerTwins({ report: given, honesty, observations });
|
|
2012
2066
|
const merged = addRunnerFindings(report, honesty.findings);
|
|
2067
|
+
for (const [id, anchor] of mergedAnchors(honesty)) merged.anchors.set(id, anchor);
|
|
2013
2068
|
const located = attachWhereToLook(merged.report, { observations, notes, screenshots, video: honesty.video, anchors: merged.anchors });
|
|
2014
2069
|
let text = markdown;
|
|
2015
|
-
// The findings as they now stand, with the evidence the pass attached
|
|
2016
|
-
|
|
2017
|
-
|
|
2070
|
+
// The findings as they now stand, with the evidence the pass attached: the
|
|
2071
|
+
// ones the persona also reported first, each said once.
|
|
2072
|
+
const twins = new Set((honesty.merged || []).map(entry => entry.id));
|
|
2073
|
+
const added = [...twins].map(id => located.report.findings.find(entry => entry.id === id)).filter(Boolean)
|
|
2074
|
+
.concat(merged.added.map(finding => located.report.findings.find(entry => entry.id === finding.id) || finding));
|
|
2075
|
+
if (added.length > 0) text = replaceSection(text, RUNNER_FINDINGS_HEADING, runnerFindingsMarkdown(added, twins));
|
|
2018
2076
|
if (honesty.edge) text = replaceSection(text, EDGE_HEADING, edgeMarkdown(honesty.edge));
|
|
2019
2077
|
if (honesty.dialogs.length > 0) {
|
|
2020
2078
|
text = replaceSection(text, DIALOGS_HEADING, honesty.dialogs.map(event => `- ${event.type}: ${JSON.stringify(String(event.message || '').slice(0, 300))} was answered ${event.answer === 'accepted' ? 'OK' : 'Cancel'}${event.text !== undefined ? ` with ${JSON.stringify(String(event.text))}` : ''}${event.automatic ? ' by the runner' : ' by the persona'}${Number.isInteger(event.action) ? ` (around action ${event.action}${event.during ? `, during the ${event.during}` : ''})` : ''}.`).join('\n'));
|
|
@@ -2040,8 +2098,16 @@ export const CLAIM_SEVERITIES = Object.freeze(['blocker', 'major', 'minor', 'cos
|
|
|
2040
2098
|
/** Output ceiling for one claim check: the answer is one word. */
|
|
2041
2099
|
export const CLAIM_CHECK_MAX_TOKENS = 32;
|
|
2042
2100
|
|
|
2043
|
-
/**
|
|
2044
|
-
|
|
2101
|
+
/**
|
|
2102
|
+
* The instruction for a claim check. The answer says whether the picture
|
|
2103
|
+
* shows what the claim says, not only whether it contradicts it: a claim of
|
|
2104
|
+
* fact about the screen is published only when the picture shows it
|
|
2105
|
+
* (./claimGate.js).
|
|
2106
|
+
*/
|
|
2107
|
+
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.';
|
|
2108
|
+
|
|
2109
|
+
/** The question each claim check ends with. */
|
|
2110
|
+
export const CLAIM_CHECK_QUESTION = 'Does this picture show what the claim says: shows, contradicts, unclear?';
|
|
2045
2111
|
|
|
2046
2112
|
/**
|
|
2047
2113
|
* The screenshot a finding's claim is checked against: of those it cites, the
|
|
@@ -2075,55 +2141,74 @@ export function citedAfterScreenshot(finding, screenshots) {
|
|
|
2075
2141
|
}
|
|
2076
2142
|
|
|
2077
2143
|
/**
|
|
2078
|
-
* Read a claim check answer
|
|
2144
|
+
* Read a claim check answer from its first word: `shows`, `contradicts` or
|
|
2145
|
+
* `unclear`. Anything else, and an empty answer, is `unclear`: an answer that
|
|
2146
|
+
* cannot be read confirms nothing.
|
|
2079
2147
|
*
|
|
2080
2148
|
* @param {string} text
|
|
2081
|
-
* @returns {'
|
|
2149
|
+
* @returns {'shows'|'contradicts'|'unclear'}
|
|
2082
2150
|
*/
|
|
2083
2151
|
export function claimCheckAnswer(text) {
|
|
2084
|
-
const match = String(text || '').match(/^[^A-Za-z]*(
|
|
2085
|
-
|
|
2152
|
+
const match = String(text || '').match(/^[^A-Za-z]*(shows?|supports?|confirms?|contradicts?|unclear)\b/i);
|
|
2153
|
+
if (!match) return 'unclear';
|
|
2154
|
+
const word = match[1].toLowerCase();
|
|
2155
|
+
return word.startsWith('contradict') ? 'contradicts' : word === 'unclear' ? 'unclear' : 'shows';
|
|
2086
2156
|
}
|
|
2087
2157
|
|
|
2158
|
+
/** How a claim check answer is written in the step log: the words the dashboard reads (yes is "the picture contradicts it"). */
|
|
2159
|
+
export const CLAIM_ANSWER_IN_LOG = Object.freeze({ shows: 'no', contradicts: 'yes', unclear: 'unclear' });
|
|
2160
|
+
|
|
2088
2161
|
/**
|
|
2089
|
-
* The bounded verification turn of the report step
|
|
2090
|
-
*
|
|
2091
|
-
*
|
|
2092
|
-
*
|
|
2093
|
-
*
|
|
2094
|
-
*
|
|
2162
|
+
* The bounded verification turn of the report step, and the gate after it.
|
|
2163
|
+
* Every issue the report names, the most severe first and at most
|
|
2164
|
+
* {@link MAX_CLAIM_CHECKS}, is sent once with the picture of its moment (the
|
|
2165
|
+
* frame cut from the video, else the screenshot it cites) and asked whether
|
|
2166
|
+
* the picture shows what it claims. Then ./claimGate.js decides: a claim the
|
|
2167
|
+
* picture contradicts is never a finding; a claim of fact is one only when
|
|
2168
|
+
* the picture shows it; an opinion of taste or difficulty stands when the
|
|
2169
|
+
* picture cannot settle it. What the gate turns away leaves the report and is
|
|
2170
|
+
* returned with its reason.
|
|
2171
|
+
*
|
|
2172
|
+
* A finding the runner itself saw happen (`measured`: a crash, a freeze or a
|
|
2173
|
+
* blank screen the persona also reported, ./honesty.js) is not a claim and is
|
|
2174
|
+
* not asked about.
|
|
2095
2175
|
*
|
|
2096
2176
|
* It goes to `persona_playtest.act`, the run's one step that accepts an image
|
|
2097
2177
|
* (the report step accepts none), with no tools and a one word ceiling, and
|
|
2098
2178
|
* it is spent from the same run budget the warning at 80 percent keeps for the
|
|
2099
|
-
* report step. A
|
|
2100
|
-
*
|
|
2179
|
+
* report step. A refusal ends the checks; a claim it left unchecked is not
|
|
2180
|
+
* confirmed by it.
|
|
2101
2181
|
*
|
|
2102
|
-
* @returns {Promise<{report: Object,
|
|
2182
|
+
* @returns {Promise<{report: Object, turnedAway: Array<Object>}>}
|
|
2103
2183
|
*/
|
|
2104
|
-
export async function checkClaimsAgainstScreenshots({ client, jobId, runId, report, screenshots, runDirectory, ledger, transcript, log = () => {}, frames = new Map() }) {
|
|
2105
|
-
if (!report || !Array.isArray(report.findings)) return { report,
|
|
2184
|
+
export async function checkClaimsAgainstScreenshots({ client, jobId, runId, report, screenshots, runDirectory, ledger, transcript, log = () => {}, frames = new Map(), measured = new Set(), observations = [], notes = [] }) {
|
|
2185
|
+
if (!report || !Array.isArray(report.findings)) return { report, turnedAway: [] };
|
|
2186
|
+
const where = new Map(attachWhereToLook(report, { observations, notes, screenshots }).index.filter(entry => entry.screenshot).map(entry => [entry.id, entry.screenshot]));
|
|
2106
2187
|
// Every issue, the most severe first; what worked is not checked.
|
|
2107
|
-
const issues = report.findings.filter(finding => finding && CLAIM_SEVERITIES.includes(finding.severity))
|
|
2188
|
+
const issues = report.findings.filter(finding => finding && CLAIM_SEVERITIES.includes(finding.severity) && !measured.has(finding.id))
|
|
2108
2189
|
.sort((a, b) => CLAIM_SEVERITIES.indexOf(a.severity) - CLAIM_SEVERITIES.indexOf(b.severity));
|
|
2109
2190
|
const targets = issues.slice(0, MAX_CLAIM_CHECKS);
|
|
2110
|
-
|
|
2111
|
-
const
|
|
2112
|
-
|
|
2191
|
+
const checks = new Map();
|
|
2192
|
+
const skip = (finding, reason, shot = null, on = {}) => {
|
|
2193
|
+
transcript.write({ kind: 'claim_check', id: finding.id, screenshot: shot, ...on, answer: 'skipped', reason });
|
|
2194
|
+
checks.set(finding, { answer: 'skipped', reason });
|
|
2195
|
+
};
|
|
2196
|
+
for (const finding of issues.slice(MAX_CLAIM_CHECKS)) skip(finding, `the run checks at most ${MAX_CLAIM_CHECKS} findings`);
|
|
2197
|
+
let stopped = null;
|
|
2113
2198
|
for (const finding of targets) {
|
|
2199
|
+
if (stopped) { skip(finding, stopped); continue; }
|
|
2114
2200
|
// The frame cut from the video at the finding's moment, else the screenshot it cites.
|
|
2115
2201
|
const frame = frames.get(finding.id) || null;
|
|
2116
|
-
|
|
2202
|
+
// Else the screenshot it cites, else the one the runner places at its moment (the one report.md's "Where to look" names).
|
|
2203
|
+
const placedShot = where.get(finding.id);
|
|
2204
|
+
const shot = frame ? { relativePath: frame.path } : citedAfterScreenshot(finding, screenshots) || (placedShot ? { relativePath: placedShot } : null);
|
|
2117
2205
|
const on = frame ? { frame: frame.path } : {};
|
|
2118
|
-
if (!shot) {
|
|
2119
|
-
transcript.write({ kind: 'claim_check', id: finding.id, screenshot: null, answer: 'skipped', reason: 'no frame of its moment and no cited screenshot' });
|
|
2120
|
-
continue;
|
|
2121
|
-
}
|
|
2206
|
+
if (!shot) { skip(finding, 'no frame of its moment and no cited screenshot'); continue; }
|
|
2122
2207
|
let data;
|
|
2123
2208
|
try {
|
|
2124
2209
|
data = (await readFile(path.join(runDirectory, shot.relativePath))).toString('base64');
|
|
2125
2210
|
} catch {
|
|
2126
|
-
|
|
2211
|
+
skip(finding, 'the picture could not be read', shot.relativePath, on);
|
|
2127
2212
|
continue;
|
|
2128
2213
|
}
|
|
2129
2214
|
let answer;
|
|
@@ -2139,7 +2224,7 @@ export async function checkClaimsAgainstScreenshots({ client, jobId, runId, repo
|
|
|
2139
2224
|
role: 'user',
|
|
2140
2225
|
content: [
|
|
2141
2226
|
{ type: 'image', source: { type: 'base64', media_type: /\.jpe?g$/i.test(shot.relativePath) ? 'image/jpeg' : 'image/png', data } },
|
|
2142
|
-
{ type: 'text', text: `Claim (${finding.severity}): ${finding.title || ''}\n${String(finding.description || '').slice(0, 1200)}\n\
|
|
2227
|
+
{ type: 'text', text: `Claim (${finding.severity}): ${finding.title || ''}\n${String(finding.description || '').slice(0, 1200)}\n\n${CLAIM_CHECK_QUESTION}` }
|
|
2143
2228
|
]
|
|
2144
2229
|
}],
|
|
2145
2230
|
maxTokens: CLAIM_CHECK_MAX_TOKENS,
|
|
@@ -2148,28 +2233,28 @@ export async function checkClaimsAgainstScreenshots({ client, jobId, runId, repo
|
|
|
2148
2233
|
});
|
|
2149
2234
|
} catch (error) {
|
|
2150
2235
|
const reason = error instanceof ProxyError && error.isBudget ? 'the run budget is spent' : String(error && error.message ? error.message : error);
|
|
2151
|
-
|
|
2236
|
+
skip(finding, reason, shot.relativePath, on);
|
|
2152
2237
|
// A refusal ends the checks, and every finding not reached says so; nothing is asked again.
|
|
2153
|
-
|
|
2154
|
-
log(`the screenshot check stopped (${reason});
|
|
2155
|
-
|
|
2238
|
+
stopped = reason;
|
|
2239
|
+
log(`the screenshot check stopped (${reason}); a claim it did not reach is not confirmed by it.`);
|
|
2240
|
+
continue;
|
|
2156
2241
|
}
|
|
2157
2242
|
if (ledger) ledger.record({ model: answer.model, usage: answer.usage, ms: Date.now() - askedAt });
|
|
2158
2243
|
const verdict = claimCheckAnswer(answer.text);
|
|
2159
|
-
transcript.write({ kind: 'claim_check', id: finding.id, screenshot: shot.relativePath, ...on, answer: verdict });
|
|
2160
|
-
|
|
2244
|
+
transcript.write({ kind: 'claim_check', id: finding.id, screenshot: shot.relativePath, ...on, answer: CLAIM_ANSWER_IN_LOG[verdict], question: 'shows' });
|
|
2245
|
+
checks.set(finding, { answer: verdict, picture: shot.relativePath });
|
|
2161
2246
|
}
|
|
2162
|
-
|
|
2163
|
-
const findings =
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
const
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
}
|
|
2172
|
-
return { report: { ...report, findings },
|
|
2247
|
+
const turnedAway = [];
|
|
2248
|
+
const findings = [];
|
|
2249
|
+
for (const finding of report.findings) {
|
|
2250
|
+
if (!finding || !issues.includes(finding)) { findings.push(finding); continue; }
|
|
2251
|
+
const gate = gateFinding(finding, checks.get(finding) || null);
|
|
2252
|
+
if (gate.publish) { findings.push(finding); continue; }
|
|
2253
|
+
const entry = { id: finding.id, severity: finding.severity, title: finding.title, claim: gate.kind, outcome: gate.outcome, reason: gate.reason, finding };
|
|
2254
|
+
turnedAway.push(entry);
|
|
2255
|
+
transcript.write({ kind: 'finding_not_confirmed', id: finding.id, severity: finding.severity, title: finding.title, claim: gate.kind, outcome: gate.outcome, reason: gate.reason });
|
|
2256
|
+
}
|
|
2257
|
+
return { report: turnedAway.length > 0 ? { ...report, findings } : report, turnedAway };
|
|
2173
2258
|
}
|
|
2174
2259
|
|
|
2175
2260
|
/**
|
|
@@ -3037,7 +3122,9 @@ export function screenshotLine(shot) {
|
|
|
3037
3122
|
Number.isInteger(shot.observation) && shot.observation > 0
|
|
3038
3123
|
? `after observation ${shot.observation}${Number.isInteger(shot.observationUntil) && shot.observationUntil > shot.observation ? `, and the screen was the same again after observation ${shot.observationUntil}` : ''}`
|
|
3039
3124
|
: null,
|
|
3040
|
-
shot.reason ? String(shot.reason) : null
|
|
3125
|
+
shot.reason ? String(shot.reason) : null,
|
|
3126
|
+
// Measured by the runner: say what the picture shows, never what the state says.
|
|
3127
|
+
shot.stale ? `CAPTURE PROBLEM: ${staleSentence(shot.stale)}; describe this picture as that earlier screen, and never as evidence of the state` : null
|
|
3041
3128
|
].filter(Boolean);
|
|
3042
3129
|
return `- ${shot.relativePath}${tags.length > 0 ? ` (${tags.join('; ')})` : ''}`;
|
|
3043
3130
|
}
|
package/src/run/reportChecks.js
CHANGED
|
@@ -97,6 +97,8 @@ export function screenOf(text, url) {
|
|
|
97
97
|
|
|
98
98
|
/** The frame is taken this long after the finding's moment, so the result of the input is on screen. */
|
|
99
99
|
export const FRAME_AFTER_MS = 600;
|
|
100
|
+
/** How far back a second try at a frame goes when the first could not be cut. */
|
|
101
|
+
export const FRAME_RETRY_BACK_MS = 1000;
|
|
100
102
|
export const FRAME_WIDTH = 960;
|
|
101
103
|
export const FRAME_TIMEOUT_MS = 20000;
|
|
102
104
|
/** Frames cut for one run at most. */
|
|
@@ -145,9 +147,9 @@ export async function cutFrame({ ffmpeg, video, atMs, out, width = FRAME_WIDTH,
|
|
|
145
147
|
* @param {{width: number, height: number}|null} [args.viewport] the size of the view the inputs were made in
|
|
146
148
|
* @returns {Promise<Map<string, {path: string, video_ms: number}>>}
|
|
147
149
|
*/
|
|
148
|
-
export async function cutFindingFrames({ runDirectory, index = [], video = null, transcript, viewport = null, detect = detectFfmpeg, cut = cutFrame }) {
|
|
150
|
+
export async function cutFindingFrames({ runDirectory, index = [], video = null, transcript, viewport = null, detect = detectFfmpeg, cut = cutFrame, placed = new Set() }) {
|
|
149
151
|
const frames = new Map();
|
|
150
|
-
const wanted = index.filter(entry => entry && typeof entry.id === 'string' && Number.isFinite(entry.video_ms)).slice(0, MAX_FRAMES);
|
|
152
|
+
const wanted = index.filter(entry => entry && typeof entry.id === 'string' && Number.isFinite(entry.video_ms) && !placed.has(entry.id)).slice(0, MAX_FRAMES);
|
|
151
153
|
if (!video || !video.file || wanted.length === 0) return frames;
|
|
152
154
|
let ffmpeg = null;
|
|
153
155
|
try { ffmpeg = (await detect())?.path || null; } catch { ffmpeg = null; }
|
|
@@ -158,13 +160,26 @@ export async function cutFindingFrames({ runDirectory, index = [], video = null,
|
|
|
158
160
|
const file = path.join(runDirectory, video.file);
|
|
159
161
|
const end = Number.isFinite(video.durationMs) && video.durationMs > 0 ? Math.max(0, video.durationMs - 200) : Infinity;
|
|
160
162
|
for (const entry of wanted) {
|
|
161
|
-
const at = Math.round(Math.min(entry.video_ms + FRAME_AFTER_MS, end));
|
|
162
163
|
const relative = framePath(entry.id);
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
164
|
+
const step = Number.isInteger(entry.action) ? { action: entry.action } : {};
|
|
165
|
+
placed.add(entry.id);
|
|
166
|
+
// The moment itself, and a second further back: a frame asked for in the
|
|
167
|
+
// last moments of a recording that ended under a freeze is often past
|
|
168
|
+
// the last frame the file can seek to.
|
|
169
|
+
let at = null;
|
|
170
|
+
for (const candidate of [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))]) {
|
|
171
|
+
let ok = false;
|
|
172
|
+
try { ok = await cut({ ffmpeg, video: file, atMs: candidate, out: path.join(runDirectory, relative) }); } catch { ok = false; }
|
|
173
|
+
if (ok) { at = candidate; break; }
|
|
174
|
+
}
|
|
175
|
+
if (at === null) {
|
|
176
|
+
// No picture, but the moment stands: the dashboard places the finding
|
|
177
|
+
// 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.video_ms), ...step });
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
166
181
|
frames.set(entry.id, { path: relative, video_ms: at });
|
|
167
|
-
transcript.write({ kind: 'finding_frame', id: entry.id, path: relative, source: 'video', 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 } } : {}) });
|
|
168
183
|
}
|
|
169
184
|
return frames;
|
|
170
185
|
}
|