ravensight-playtest 0.18.0 → 0.20.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 +202 -17
- package/addons/desktop/RavensightDesktop.swift +367 -0
- package/addons/mobile/UITests/MobileInputTests.swift +67 -1
- package/addons/ravensight_driver/driver.gd +557 -4
- package/docs/ADAPTERS.md +39 -7
- package/docs/DESKTOP.md +161 -0
- package/docs/MOBILE.md +30 -3
- package/docs/UNITY.md +189 -0
- package/docs/UNREAL.md +166 -0
- package/docs/godot-driver.md +109 -1
- package/package.json +15 -5
- package/src/cli.js +44 -11
- package/src/commands/build.js +40 -0
- package/src/commands/feature.js +1 -1
- package/src/commands/hosted.js +78 -9
- package/src/commands/run.js +65 -13
- package/src/commands/validate.js +1 -1
- package/src/hosted/archivePreflight.js +31 -4
- package/src/hosted/buildStatus.js +26 -0
- package/src/hosted/buildUpload.js +24 -9
- package/src/hosted/nativeBuild.js +87 -0
- package/src/hosted/recordedRun.js +15 -3
- package/src/run/anygame/genre.js +110 -25
- package/src/run/anygame/genre2d.js +139 -0
- package/src/run/anygame/index.js +9 -5
- package/src/run/anygame/scene3d.js +562 -0
- package/src/run/anygame/shared-hashes.json +4 -2
- package/src/run/anygame/shared.js +3 -3
- package/src/run/args.js +24 -4
- package/src/run/drivers/desktop/app.js +104 -0
- package/src/run/drivers/desktop/common.js +394 -0
- package/src/run/drivers/desktop/driver.js +455 -0
- package/src/run/drivers/desktop/helper.js +98 -0
- package/src/run/drivers/desktop/keys.js +124 -0
- package/src/run/drivers/desktop/output.js +107 -0
- package/src/run/drivers/desktop/preflight.js +134 -0
- package/src/run/drivers/desktop/runHome.js +158 -0
- package/src/run/drivers/desktop3d.js +106 -0
- package/src/run/drivers/desktopSequence.js +72 -0
- package/src/run/drivers/godot-3d.js +298 -0
- package/src/run/drivers/godot.js +473 -31
- package/src/run/drivers/index.js +6 -0
- package/src/run/drivers/mobile/adb.js +25 -1
- package/src/run/drivers/mobile/frame.js +3 -2
- package/src/run/drivers/mobile/gestures.js +76 -0
- package/src/run/drivers/mobile/lock.js +51 -11
- package/src/run/drivers/mobile/multitouch.js +150 -0
- package/src/run/drivers/mobile/native.js +231 -31
- package/src/run/drivers/mobile/preflight.js +14 -1
- package/src/run/drivers/mobile/target.js +22 -1
- package/src/run/drivers/stdio.js +154 -13
- package/src/run/drivers/unity/app.js +72 -0
- package/src/run/drivers/unity/engine.js +58 -0
- package/src/run/drivers/unity/link.js +108 -0
- package/src/run/drivers/unity/logs.js +76 -0
- package/src/run/drivers/unreal/app.js +40 -0
- package/src/run/drivers/unreal/driver.js +776 -0
- package/src/run/drivers/unreal/frames.js +243 -0
- package/src/run/drivers/unreal/logs.js +276 -0
- package/src/run/drivers/unreal/preflight.js +61 -0
- package/src/run/drivers/web.js +211 -13
- package/src/run/drivers/webdriver.js +81 -12
- package/src/run/endScreen.js +88 -0
- package/src/run/engineErrors.js +16 -0
- package/src/run/featureLoop.js +1 -1
- package/src/run/fingers.js +99 -0
- package/src/run/focusForKeys.js +54 -0
- package/src/run/godotTesterProbes.js +21 -2
- package/src/run/honesty.js +11 -1
- package/src/run/inputs.js +3 -3
- package/src/run/intent.js +12 -0
- package/src/run/launchArgs.js +58 -0
- package/src/run/pauseHook.js +617 -0
- package/src/run/personaLoop.js +164 -10
- package/src/run/pixels.js +22 -10
- package/src/run/planGuard.js +103 -0
- package/src/run/replay.js +7 -1
- package/src/run/reportChecks.js +24 -4
- package/src/run/resume.js +10 -2
- package/src/run/sessions.js +175 -0
- package/src/run/slowMotion.js +151 -0
- package/src/run/startFrom.js +448 -0
- package/src/run/testerProbes.js +36 -5
- package/src/run/tools.js +191 -10
- package/src/run/view3dState.js +125 -0
- package/src/run/web3d.js +375 -0
- package/src/run/world3d.js +164 -0
- package/templates/godot-3d/README.md +3 -2
package/src/run/personaLoop.js
CHANGED
|
@@ -16,7 +16,7 @@ import { createPlayClock, clockStopDetail, timeLeftAside } from './playClock.js'
|
|
|
16
16
|
import { appendNormalisedMarkdown, checkEvidence, createReportValidator, lintMarkdownSections, normaliseEnums, normaliseEvidence, normaliseReproSteps, repairInstruction, REQUIRED_MARKDOWN_SECTIONS, stampReport, stripTrailingToolMarkup, writeReportFiles } from './report.js';
|
|
17
17
|
import { assertNoSecrets, scanForSecrets } from './secretScan.js';
|
|
18
18
|
import { redactText } from './redaction.js';
|
|
19
|
-
import { ACTION_TOOLS, NEW_TOOL_NAMES, REPORT_TOOLS, executeTool, expectationOf, modelFrameOf, toolResult, toolsFor, NEWEST_TOOL_NAMES } from './tools.js';
|
|
19
|
+
import { ACTION_TOOLS, NEW_TOOL_NAMES, REPORT_TOOLS, executeTool, expectationOf, modelFrameOf, toolResult, toolsFor, NEWEST_TOOL_NAMES, SENSOR_TOOL_NAMES } from './tools.js';
|
|
20
20
|
import {
|
|
21
21
|
CAPABILITY_HEADING, DIALOGS_HEADING, EVIDENCE_HEADING, MAX_WIN_CONTINUES, RUNNER_FINDINGS_HEADING, WIN_TEXT,
|
|
22
22
|
addRunnerFindings, attachWhereToLook, uniqueFindingIds, blankFinding, capabilityPrompt, createBlankWatch, createCapabilityLedger, describeInput, dialogNote, gameEndedFinding, gameEndedOf, mergeRunnerDuplicates,
|
|
@@ -28,6 +28,10 @@ import { createTesterLedger, testerFindings, testedMarkdown, TESTED_HEADING } fr
|
|
|
28
28
|
import { runTesterProbes, probeFindings, probesMarkdown, probeObserver, PROBES_HEADING } from './testerProbes.js';
|
|
29
29
|
import { avoidLinesOf } from './avoid.js';
|
|
30
30
|
import { runGodotTesterProbes, godotProbesMarkdown } from './godotTesterProbes.js';
|
|
31
|
+
// [native hooks] Several sessions in one run, and a plan's steps checked one by one (./sessions.js, ./planGuard.js).
|
|
32
|
+
import { createSessions, sessionTurn, notRestartedFinding } from './sessions.js';
|
|
33
|
+
import { createPlanGuard, notPlayedText } from './planGuard.js';
|
|
34
|
+
import { startRecord, startReportLine, withStartLine } from './startFrom.js';
|
|
31
35
|
import { runGodotEdgePass } from './godotEdgePass.js';
|
|
32
36
|
import { recordingMetadata, saveRecording } from './drivers/recording.js';
|
|
33
37
|
import { createTranscript } from './transcript.js';
|
|
@@ -55,6 +59,7 @@ import os from 'node:os';
|
|
|
55
59
|
import { MIN_PASSWORD_CHARS } from '../briefLocal.js';
|
|
56
60
|
// any-game hook: the run's notebook, control learning, language, kind of game and sound (./anygame/index.js).
|
|
57
61
|
import { createLocalAnyGame } from './anygame/index.js';
|
|
62
|
+
import { isActionStyle, speedSentence, withSpeedLine } from './slowMotion.js';
|
|
58
63
|
import { TOOL_TEXT_OTHER, NO_SOUND_OTHER } from './anygame/language.js';
|
|
59
64
|
import { staleObservationCount } from './context.js';
|
|
60
65
|
|
|
@@ -106,6 +111,32 @@ const nextOrder = () => {
|
|
|
106
111
|
* `status: 401`, `statusCode=403`, `401 Unauthorized`. A missing asset or a
|
|
107
112
|
* refused call, not a crash.
|
|
108
113
|
*/
|
|
114
|
+
/** The time a replay of a local Unreal run gets for starting the game, on top of its share of play time, per replay. */
|
|
115
|
+
export const UNREAL_REPLAY_LAUNCH_MS = 30000;
|
|
116
|
+
|
|
117
|
+
/** Drivers whose findings are replayed by launching the build again and playing the recorded inputs with no model (./reportChecks.js replayWebFindings). */
|
|
118
|
+
export const REPLAY_DRIVERS = Object.freeze(['playwright_web', 'unreal_driver', 'unity_driver', 'desktop_driver']);
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The replay's check for a finding the game's own 3D state measured
|
|
122
|
+
* (./world3d.js): the same finding filed again by the replay's own watch by
|
|
123
|
+
* the time its input is replayed. Null for any other finding, which the
|
|
124
|
+
* screen decides.
|
|
125
|
+
*
|
|
126
|
+
* @param {Array<Object>} findings the run's own findings, with their runner keys
|
|
127
|
+
*/
|
|
128
|
+
export function worldStateCheck(findings = []) {
|
|
129
|
+
const measured = new Set(findings.filter(finding => finding && finding.runner && String(finding.runner.key).startsWith('world:')).map(finding => finding.title));
|
|
130
|
+
if (measured.size === 0) return null;
|
|
131
|
+
return (replayDriver, finding) => {
|
|
132
|
+
if (!finding || !measured.has(finding.title) || !replayDriver || typeof replayDriver.worldFindings !== 'function') return null;
|
|
133
|
+
const again = replayDriver.worldFindings({ actionRecords: [] }).some(item => item.title === finding.title);
|
|
134
|
+
return again
|
|
135
|
+
? { verdict: 'match', detail: 'the game\'s own 3D state showed the same thing again when the recorded inputs were replayed' }
|
|
136
|
+
: { verdict: 'no_match', detail: 'the game\'s own 3D state did not show it again when the recorded inputs were replayed' };
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
109
140
|
export const RESOURCE_4XX = /Failed to load resource: the server responded with a status of 4\d\d|\bHTTP 4\d\d\b|status(?:Code)?\s*[:=]?\s*4\d\d\b|\b4\d\d (?:Unauthorized|Forbidden|Not Found|Bad Request)\b/i;
|
|
110
141
|
|
|
111
142
|
/** The screenshots the runner takes on its own, which no persona described. */
|
|
@@ -387,8 +418,15 @@ export async function runPersona(args) {
|
|
|
387
418
|
// What the brief asks the run to stay out of: the driver refuses an input on it, whoever chose the input (./avoid.js).
|
|
388
419
|
if (typeof driver.setAvoid === 'function') driver.setAvoid(avoidLinesOf(brief));
|
|
389
420
|
await driver.launch({ target, runDir: runDirectory, recordVideo, viewport, signal: args.signal });
|
|
421
|
+
// [native hooks] Where the run started (./startFrom.js): what was placed, the spec, and what the game said it loaded.
|
|
422
|
+
const startAnswer = driver.startAnswer || null;
|
|
423
|
+
const startRec = driver.start ? startRecord(driver.start) : startAnswer && startAnswer.record ? startAnswer.record : null;
|
|
424
|
+
if (startRec) {
|
|
425
|
+
honesty.start = { record: startRec, answer: startAnswer };
|
|
426
|
+
transcript.write({ kind: 'start_from', ...startRec, answer: startAnswer ? { ...startAnswer, record: undefined } : null });
|
|
427
|
+
}
|
|
390
428
|
// A web run keeps its inputs, in this process only, so its findings can be replayed after the report.
|
|
391
|
-
if (driverName
|
|
429
|
+
if (REPLAY_DRIVERS.includes(driverName) && typeof args.replayDriver === 'function' && args.replayFindings !== false) traceWebInputs(driver, { fingerprint: pngFingerprint });
|
|
392
430
|
await advance('playing');
|
|
393
431
|
|
|
394
432
|
const play = await playLoop({
|
|
@@ -419,7 +457,9 @@ export async function runPersona(args) {
|
|
|
419
457
|
// When the recording began, read before the driver is stopped: a finding's
|
|
420
458
|
// video time is measured from it.
|
|
421
459
|
const recordingStartedAt = typeof driver.recordingStartedAt === 'function' ? driver.recordingStartedAt() : null;
|
|
422
|
-
await driverStop(driver, outcome, log, play.canceled ? 'canceled' : play.gameEnded ? 'game_crashed' : 'completed');
|
|
460
|
+
await driverStop(driver, outcome, log, play.canceled ? 'canceled' : play.gameEnded ? 'game_crashed' : 'completed', transcript);
|
|
461
|
+
// How fast the game played (./slowMotion.js), for report.md: said only when slow motion was asked for.
|
|
462
|
+
honesty.speedLine = speedSentence(outcome.timeControl || null);
|
|
423
463
|
if (outcome.videoPath && Number.isFinite(recordingStartedAt)) {
|
|
424
464
|
honesty.video = { startedAt: recordingStartedAt, file: path.basename(outcome.videoPath), ...(outcome.recording && Number.isFinite(outcome.recording.durationMs) ? { durationMs: outcome.recording.durationMs } : {}) };
|
|
425
465
|
}
|
|
@@ -502,7 +542,11 @@ export async function runPersona(args) {
|
|
|
502
542
|
// already had watched is written as it was (only the judge's watched claims say nothing happens by their words).
|
|
503
543
|
...(webReplay ? { watch: webReplay.watch } : {}), prior: watchedFor(written.report, watchedStill),
|
|
504
544
|
// [tester hook] The probes that found something are run once more at the end of this one replay (./testerProbes.js probeObserver).
|
|
505
|
-
observer: probeObserver({ probes: honesty.probes, report: written.report, actionRecords, signal: args.signal })
|
|
545
|
+
observer: probeObserver({ probes: honesty.probes, report: written.report, actionRecords, signal: args.signal }),
|
|
546
|
+
// A 3D finding of the game's own state (./world3d.js) is checked against the replay's own watch, not the screen.
|
|
547
|
+
stateCheck: worldStateCheck(honesty.findings),
|
|
548
|
+
// A packaged native game takes seconds to start before its first replayed input.
|
|
549
|
+
...(['unreal_driver', 'unity_driver', 'desktop_driver'].includes(driverName) ? { launchAllowanceMs: UNREAL_REPLAY_LAUNCH_MS } : {}) })
|
|
506
550
|
: replayFindings({ report: written.report, index: written.index || [], traceSteps: honesty.traceSteps, runDirectory, driver, playMs, transcript, signal: args.signal });
|
|
507
551
|
await replayed
|
|
508
552
|
.then(pass => {
|
|
@@ -545,7 +589,7 @@ export async function runPersona(args) {
|
|
|
545
589
|
// screenshots and avoided inputs can be logged without spending an action.
|
|
546
590
|
outcome.actionsTaken = actionRecords.reduce((count, record) => record?.kind === 'action' && Number.isSafeInteger(record.actions)
|
|
547
591
|
? Math.max(count, record.actions) : count, outcome.actionsTaken || 0);
|
|
548
|
-
await driverStop(driver, outcome, log, args.signal?.aborted ? 'canceled' : 'failed');
|
|
592
|
+
await driverStop(driver, outcome, log, args.signal?.aborted ? 'canceled' : 'failed', transcript);
|
|
549
593
|
if (error instanceof ProxyError && error.isBudget) {
|
|
550
594
|
outcome.state = 'budget_exceeded';
|
|
551
595
|
outcome.quitReason = 'cost_cap';
|
|
@@ -920,6 +964,8 @@ async function playLoop({
|
|
|
920
964
|
// The run's clock, for a run sold by the minute (./playClock.js): seconds of
|
|
921
965
|
// play, and the wall clock the server stops serving the run at.
|
|
922
966
|
playClock: clockLimits = null,
|
|
967
|
+
// How many sessions the run is played as, each a launch of the game (./sessions.js).
|
|
968
|
+
sessions: sessionCount = 1,
|
|
923
969
|
log = () => {}
|
|
924
970
|
}) {
|
|
925
971
|
const system = buildSystem({ skill, persona, brief, localBrief, intentNotes, driverName, target, maxActions, runId });
|
|
@@ -930,7 +976,7 @@ async function playLoop({
|
|
|
930
976
|
const noisePatterns = (localBrief && Array.isArray(localBrief.expected_noise)) ? localBrief.expected_noise : [];
|
|
931
977
|
// any-game hook: one notebook a run, on the honesty record so the report step reads the same one.
|
|
932
978
|
const briefFields = brief && brief.fields && typeof brief.fields === 'object' ? brief.fields : brief || {};
|
|
933
|
-
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), reportLanguageHint: briefFields.play && typeof briefFields.play.report_language === 'string' ? briefFields.play.report_language : null, continuousTime: driver?.inputProfile === 'native-mobile' && driver.frozenBetweenActions === false, driverName: typeof driver.soundSelfTest === 'function' ? '' : driverName, selfNotes: Boolean(earlierMemory) && earlierMemory.self !== false }));
|
|
979
|
+
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), reportLanguageHint: briefFields.play && typeof briefFields.play.report_language === 'string' ? briefFields.play.report_language : null, continuousTime: driver?.inputProfile === 'native-mobile' && driver.frozenBetweenActions === false, driverName: typeof driver.soundSelfTest === 'function' ? '' : driverName, selfNotes: Boolean(earlierMemory) && earlierMemory.self !== false, is3d: () => Boolean(driver && driver.scene3d) }));
|
|
934
980
|
system.push({ type: 'text', text: anyGame.systemText() });
|
|
935
981
|
// The intent check (./intent.js): one watch a run, on the honesty record so the report step reads the same one. Every answer,
|
|
936
982
|
// miss and refused repeat is a line of the step log.
|
|
@@ -956,7 +1002,10 @@ async function playLoop({
|
|
|
956
1002
|
// pinch and gamepad are newer still: a server may allow the pointer tools
|
|
957
1003
|
// and not yet these two, so they are given up first, on their own.
|
|
958
1004
|
let newestTools = true;
|
|
959
|
-
|
|
1005
|
+
// tilt is newer again: a server may allow every touch tool and not yet the
|
|
1006
|
+
// device's motion sensor, so it alone is given up first.
|
|
1007
|
+
let sensorTools = true;
|
|
1008
|
+
const toolsNow = () => controllerTools(toolsFor(driver, { newTools, newestTools, sensorTools: newestTools && sensorTools }));
|
|
960
1009
|
// The tools a driver offers can grow during play (the gamepad, once the
|
|
961
1010
|
// page has looked for one): the names it offers now, to notice when.
|
|
962
1011
|
const offeredNow = () => (Array.isArray(driver && driver.pointerTools) ? driver.pointerTools.join(',') : '');
|
|
@@ -992,6 +1041,18 @@ async function playLoop({
|
|
|
992
1041
|
const messages = [];
|
|
993
1042
|
let actions = 0;
|
|
994
1043
|
let turns = 0;
|
|
1044
|
+
// Slow motion (./slowMotion.js): asked of the driver once, when the playtester has settled the game's kind as an
|
|
1045
|
+
// action game. What the driver answered is kept for the step log and the report; it is never a finding.
|
|
1046
|
+
let slowMotion = null;
|
|
1047
|
+
const slowMotionCheck = async () => {
|
|
1048
|
+
if (slowMotion || !driver || typeof driver.slowDown !== 'function' || !anyGame.genre.settled) return;
|
|
1049
|
+
const digest = anyGame.genre.digest();
|
|
1050
|
+
if (!isActionStyle(digest)) return;
|
|
1051
|
+
slowMotion = { status: 'not_supported', reason: 'style', scale: null };
|
|
1052
|
+
try { slowMotion = (await driver.slowDown({ action: actions })) || slowMotion; } catch { /* the run goes on at the game's own speed */ }
|
|
1053
|
+
transcript.write({ kind: 'slow_motion', at_action: actions, kind_of_game: digest.kind, ...(digest.style2d ? { style: digest.style2d } : {}), ...slowMotion });
|
|
1054
|
+
if (slowMotion.status === 'on') log(`the game is an action game, so it runs at ${Math.round(slowMotion.scale * 100)}% of its speed while the playtester decides from action ${actions} on.`);
|
|
1055
|
+
};
|
|
995
1056
|
let quitReason = 'budget_exhausted';
|
|
996
1057
|
let quitDetail = '';
|
|
997
1058
|
let budgetWarned = false;
|
|
@@ -1020,6 +1081,10 @@ async function playLoop({
|
|
|
1020
1081
|
let declinedEnded = false;
|
|
1021
1082
|
// The clock a run sold by the minute stops on; never stops a run with no limit.
|
|
1022
1083
|
const clock = createPlayClock({ ...(clockLimits || {}) });
|
|
1084
|
+
// [native hooks] The sessions share the run's own budget and clock; the plan guard asks no model anything.
|
|
1085
|
+
const sessions = createSessions({ count: sessionCount, maxActions, playSeconds: clockLimits && clockLimits.playSeconds });
|
|
1086
|
+
const planGuard = createPlanGuard();
|
|
1087
|
+
let planScene = null;
|
|
1023
1088
|
let clockStopped = false;
|
|
1024
1089
|
let timeLeftSaid = false;
|
|
1025
1090
|
// Inputs that changed nothing, by the screen they were tried on, so a stuck
|
|
@@ -1110,6 +1175,7 @@ async function playLoop({
|
|
|
1110
1175
|
};
|
|
1111
1176
|
|
|
1112
1177
|
const first = await driver.observe();
|
|
1178
|
+
planScene = first && first.scene ? first.scene : null;
|
|
1113
1179
|
observed(first);
|
|
1114
1180
|
anyGame.seeScreen(first.text);
|
|
1115
1181
|
latestObservation = first.text;
|
|
@@ -1161,6 +1227,7 @@ async function playLoop({
|
|
|
1161
1227
|
}
|
|
1162
1228
|
}
|
|
1163
1229
|
turns += 1;
|
|
1230
|
+
await slowMotionCheck();
|
|
1164
1231
|
if (offeredNow() !== offered) {
|
|
1165
1232
|
// One request writes the conversation to the cache again (the tools are
|
|
1166
1233
|
// ahead of everything); it happens once, when the game first looks for a gamepad.
|
|
@@ -1189,9 +1256,26 @@ async function playLoop({
|
|
|
1189
1256
|
imageBudget = next;
|
|
1190
1257
|
}
|
|
1191
1258
|
});
|
|
1259
|
+
// A server from before tilt: play on without it, and say so. Any other
|
|
1260
|
+
// refusal, or a second one, goes on to the fallbacks below.
|
|
1261
|
+
const askActWithSensors = async () => {
|
|
1262
|
+
try {
|
|
1263
|
+
return await askAct();
|
|
1264
|
+
} catch (error) {
|
|
1265
|
+
const offersSensors = playTools.some(tool => SENSOR_TOOL_NAMES.includes(tool.name));
|
|
1266
|
+
if (completionRepairPending || !(error instanceof ProxyError) || error.code !== 'tool_not_allowed' || !sensorTools || !offersSensors) throw error;
|
|
1267
|
+
sensorTools = false;
|
|
1268
|
+
playTools = toolsNow();
|
|
1269
|
+
const dropped = SENSOR_TOOL_NAMES.filter(name => Array.isArray(driver.pointerTools) && driver.pointerTools.includes(name));
|
|
1270
|
+
for (const name of dropped) honesty.capability.add({ input: name, reason: `the Ravensight server this run used does not yet allow the ${name} tool, so the persona was not offered it` });
|
|
1271
|
+
transcript.write({ kind: 'tools_fallback', dropped, message: String(error.message || '') });
|
|
1272
|
+
log(`the server does not allow ${dropped.join(' or ')} yet (${error.message}); playing on without ${dropped.length === 1 ? 'it' : 'them'}.`);
|
|
1273
|
+
return askAct();
|
|
1274
|
+
}
|
|
1275
|
+
};
|
|
1192
1276
|
try {
|
|
1193
1277
|
try {
|
|
1194
|
-
answer = await
|
|
1278
|
+
answer = await askActWithSensors();
|
|
1195
1279
|
} catch (error) {
|
|
1196
1280
|
// The provider refused the body. Every tool_result is already made
|
|
1197
1281
|
// valid before it is sent (./context.js), so this is a shape nobody
|
|
@@ -1441,9 +1525,16 @@ async function playLoop({
|
|
|
1441
1525
|
let screenChangedThisTurn = false;
|
|
1442
1526
|
// The playtester's answer about its last input is read from this turn's calls until one of them plays an input (./intent.js).
|
|
1443
1527
|
let answerOpen = true;
|
|
1528
|
+
planGuard.begin(answer.toolUses.filter(tool => ACTION_TOOLS.includes(tool.name) && !tool.malformed && (!selection || tool.id === selection.toolId)).length);
|
|
1444
1529
|
for (const toolUse of answer.toolUses) {
|
|
1445
1530
|
if (argsSignal?.aborted || heartbeat?.canceled) { canceled = true; quitReason = 'error'; quitDetail = 'the job was cancelled'; break; }
|
|
1446
1531
|
if (selection && toolUse.id !== selection.toolId) { results.push({ type: 'tool_result', tool_use_id: toolUse.id, content: 'Alternative not selected. No action executed.' }); continue; }
|
|
1532
|
+
// [native hooks] A step of a plan whose earlier step the frame contradicted is not sent (./planGuard.js).
|
|
1533
|
+
if (ACTION_TOOLS.includes(toolUse.name) && planGuard.stopped) {
|
|
1534
|
+
results.push(toolResult(toolUse.id, notPlayedText(planGuard.stopped, planGuard.stopped.after)));
|
|
1535
|
+
transcript.write({ kind: 'action_not_played', tool: toolUse.name, reason: 'plan_stopped', stop: planGuard.stopped.reason });
|
|
1536
|
+
continue;
|
|
1537
|
+
}
|
|
1447
1538
|
// One turn can send many actions, and the budget is a promise to the
|
|
1448
1539
|
// developer about all of them, so it is checked per action. Every tool_use
|
|
1449
1540
|
// still needs its tool_result, or the next message would be refused.
|
|
@@ -1476,6 +1567,7 @@ async function playLoop({
|
|
|
1476
1567
|
}
|
|
1477
1568
|
const notesBefore = notes.length;
|
|
1478
1569
|
const screenBefore = latestObservation;
|
|
1570
|
+
const deathsBefore = Number.isFinite(driver.deaths) ? driver.deaths : null;
|
|
1479
1571
|
// A note about something wrong is about the screen as it is now, before
|
|
1480
1572
|
// this call changes it: that screen is saved, so the finding it becomes
|
|
1481
1573
|
// can cite the moment and not the next screenshot that happened along.
|
|
@@ -1532,6 +1624,12 @@ async function playLoop({
|
|
|
1532
1624
|
if (ACTION_TOOLS.includes(toolUse.name) || toolUse.name === 'wait') clock.ran(Date.now() - ranAt);
|
|
1533
1625
|
results.push(executed.result);
|
|
1534
1626
|
if (executed.spentAction) actions += 1;
|
|
1627
|
+
if (ACTION_TOOLS.includes(toolUse.name) && !toolUse.malformed) {
|
|
1628
|
+
const sceneAfter = executed.observation && executed.observation.scene ? executed.observation.scene : planScene;
|
|
1629
|
+
const stop = planGuard.played({ executed, expected: expectationOf(toolUse.input), sceneBefore: planScene, sceneAfter, deathsBefore, deathsAfter: Number.isFinite(driver.deaths) ? driver.deaths : null });
|
|
1630
|
+
planScene = sceneAfter;
|
|
1631
|
+
if (stop) transcript.write({ kind: 'plan_stop', after_step: stop.after, reason: stop.reason, detail: stop.detail, action: actions });
|
|
1632
|
+
}
|
|
1535
1633
|
if (executed.changed && ACTION_TOOLS.includes(toolUse.name)) screenChangedThisTurn = true;
|
|
1536
1634
|
const actionLine = {
|
|
1537
1635
|
kind: 'action',
|
|
@@ -1560,6 +1658,8 @@ async function playLoop({
|
|
|
1560
1658
|
}
|
|
1561
1659
|
if (honesty.traceSteps && Number.isInteger(actionLine.trace_steps)) honesty.traceSteps.set(actions, actionLine.trace_steps);
|
|
1562
1660
|
if (honesty.tester) honesty.tester.acted(actionLine); // [tester hook]
|
|
1661
|
+
// A 3D game's own state after this input (./world3d.js): the watch learns the input's action number.
|
|
1662
|
+
if (typeof driver.worldActed === 'function') driver.worldActed(actionLine);
|
|
1563
1663
|
if (executed.unsupported && honesty.capability.add(executed.unsupported)) {
|
|
1564
1664
|
transcript.write({ kind: 'capability_note', input: executed.unsupported.input, reason: executed.unsupported.reason });
|
|
1565
1665
|
}
|
|
@@ -1654,6 +1754,25 @@ async function playLoop({
|
|
|
1654
1754
|
onProgress({ phase: 'playing', persona: persona.slug, actions, maxActions, tool: toolUse.name });
|
|
1655
1755
|
}
|
|
1656
1756
|
|
|
1757
|
+
// [native hooks] The end of a session: the game is closed and started again on its own saved data (./sessions.js).
|
|
1758
|
+
const sessionNow = gameEnded || canceled ? {} : await sessionTurn({ sessions, driver, actions, playedSeconds: clock.read().play_seconds, transcript, log });
|
|
1759
|
+
if (sessionNow.failed) {
|
|
1760
|
+
const last = [...screenshots].reverse().find(entry => entry && entry.relativePath);
|
|
1761
|
+
const finding = notRestartedFinding(sessionNow.failed, { actionRecords, screenshot: last ? last.relativePath : null, action: actions, at: Date.now() });
|
|
1762
|
+
honesty.findings.push(finding);
|
|
1763
|
+
transcript.write({ kind: 'runner_finding', key: 'game_not_restarted', title: finding.title, action: actions });
|
|
1764
|
+
quitReason = 'blocker';
|
|
1765
|
+
quitDetail = `the game did not start again for session ${sessions.current + 1}`;
|
|
1766
|
+
break;
|
|
1767
|
+
}
|
|
1768
|
+
if (sessionNow.observation) {
|
|
1769
|
+
observed(sessionNow.observation);
|
|
1770
|
+
latestObservation = sessionNow.observation.text;
|
|
1771
|
+
visualObservation = Boolean(sessionNow.observation.screenshotBase64);
|
|
1772
|
+
planScene = sessionNow.observation.scene || null;
|
|
1773
|
+
transcript.write({ kind: 'observation', step: sessionNow.observation.step, text: sessionNow.observation.text, url: sessionNow.observation.url, ...seenScreen(sessionNow.observation.text, sessionNow.observation.url, false) });
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1657
1776
|
if (gameEnded) {
|
|
1658
1777
|
const errors = typeof driver.consoleErrors === 'function' ? await Promise.resolve().then(() => driver.consoleErrors()).catch(() => []) : [];
|
|
1659
1778
|
// A frozen page can often still be photographed; a crashed one cannot.
|
|
@@ -1737,6 +1856,7 @@ async function playLoop({
|
|
|
1737
1856
|
transcript.write({ kind: 'note', note: scrubSecrets(note, secrets) });
|
|
1738
1857
|
}
|
|
1739
1858
|
|
|
1859
|
+
if (sessionNow.aside && !sessionNow.observation) asides.push(sessionNow.aside);
|
|
1740
1860
|
if (!timeLeftSaid && clock.nearlyDue()) {
|
|
1741
1861
|
timeLeftSaid = true;
|
|
1742
1862
|
asides.push(timeLeftAside(clock.read()));
|
|
@@ -1771,6 +1891,11 @@ async function playLoop({
|
|
|
1771
1891
|
// The picture goes last, outside the tool results, so the cache
|
|
1772
1892
|
// breakpoint can sit before it (withPlayCacheBreakpoint).
|
|
1773
1893
|
const hoisted = hoistImages(results);
|
|
1894
|
+
// [native hooks] After a relaunch the picture is the game as it started again, said with the screen's text.
|
|
1895
|
+
if (sessionNow.observation) {
|
|
1896
|
+
asides.push(`${sessionNow.aside}\nstep ${sessionNow.observation.step}\n${sessionNow.observation.text}`);
|
|
1897
|
+
hoisted.image = sessionNow.observation.screenshotBase64 ? { type: 'image', source: { type: 'base64', media_type: sessionNow.observation.screenshotMediaType || 'image/png', data: sessionNow.observation.screenshotBase64 } } : null;
|
|
1898
|
+
}
|
|
1774
1899
|
messages.push({
|
|
1775
1900
|
role: 'user',
|
|
1776
1901
|
content: [
|
|
@@ -1836,6 +1961,8 @@ async function playLoop({
|
|
|
1836
1961
|
}
|
|
1837
1962
|
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) });
|
|
1838
1963
|
for (const note of captureNotes(pictures)) if (honesty.capability.add(note)) transcript.write({ kind: 'capability_note', input: note.input, reason: note.reason });
|
|
1964
|
+
transcript.write({ kind: 'plan_guard', ...planGuard.summary(), sessions: sessions.total, sessions_played: sessions.current });
|
|
1965
|
+
if (sessions.total > 1) honesty.sessions = { total: sessions.total, played: sessions.current };
|
|
1839
1966
|
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() });
|
|
1840
1967
|
// The last screen as the model is shown it, for the brief choice check.
|
|
1841
1968
|
const finalFrame = brief && !gameEnded ? await modelFrameOf(driver) : null;
|
|
@@ -1931,6 +2058,11 @@ async function playLoop({
|
|
|
1931
2058
|
log(`the edge behaviour checks did not finish: ${String(error && error.message)}`);
|
|
1932
2059
|
}
|
|
1933
2060
|
}
|
|
2061
|
+
// What a 3D game's own state showed in play (./world3d.js): a fall out of the world, a player stuck on geometry, a camera
|
|
2062
|
+
// inside a wall or upside down, moves that got nowhere. Read from the game's numbers, with no model call.
|
|
2063
|
+
if (driver && typeof driver.worldFindings === 'function') {
|
|
2064
|
+
for (const finding of driver.worldFindings({ 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 }); }
|
|
2065
|
+
}
|
|
1934
2066
|
// [tester hook] What the runner's own ledger saw break a rule during play.
|
|
1935
2067
|
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 }); }
|
|
1936
2068
|
// 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.
|
|
@@ -1959,6 +2091,7 @@ async function playLoop({
|
|
|
1959
2091
|
return {
|
|
1960
2092
|
actionsTaken: actions,
|
|
1961
2093
|
turns,
|
|
2094
|
+
...(slowMotion ? { slowMotion } : {}),
|
|
1962
2095
|
distinctScreens: keeper.distinctScreens,
|
|
1963
2096
|
wrapUpTurn: wrappingUp,
|
|
1964
2097
|
gameEnded,
|
|
@@ -2443,6 +2576,11 @@ async function reportPhase({
|
|
|
2443
2576
|
transcript.write({ kind: 'played_scope', line: scope.line });
|
|
2444
2577
|
log(`what was played: ${scope.line}`);
|
|
2445
2578
|
}
|
|
2579
|
+
// [native hooks] Where the run started and how many sessions it played, under the same stamp (./startFrom.js).
|
|
2580
|
+
const startLine = honesty && (honesty.start || honesty.sessions) ? startReportLine({ ...(honesty.start || {}), sessions: honesty.sessions || null }) : null;
|
|
2581
|
+
if (startLine) markdown = withStartLine(markdown, startLine);
|
|
2582
|
+
// The speed the game played at, when slow motion was asked for (./slowMotion.js). A run at the game's own speed says nothing new.
|
|
2583
|
+
if (honesty && honesty.speedLine) markdown = withSpeedLine(markdown, honesty.speedLine);
|
|
2446
2584
|
// The in-character section held to the record: a sentence the record or the frames show otherwise is left out, and the
|
|
2447
2585
|
// record's own fact said instead.
|
|
2448
2586
|
const heldBack = holdInCharacter(markdown, { families: honesty && honesty.intent ? honesty.intent.families() : [], movedAtAll: couldMove(play.records), turnedAway, repeats: repeatsTurnedAway });
|
|
@@ -2539,7 +2677,7 @@ export function scopeForUsage(scope) {
|
|
|
2539
2677
|
*/
|
|
2540
2678
|
export function couldMove(records) {
|
|
2541
2679
|
return (Array.isArray(records) ? records : []).some(record => record && record.kind === 'action' && record.ok
|
|
2542
|
-
&& (movementInput(record.tool, record.input || {}) || ['click', 'hover', 'drag', 'swipe', 'gamepad', 'pinch'].includes(record.tool)));
|
|
2680
|
+
&& (movementInput(record.tool, record.input || {}) || ['click', 'hover', 'drag', 'swipe', 'gamepad', 'pinch', 'touches'].includes(record.tool)));
|
|
2543
2681
|
}
|
|
2544
2682
|
|
|
2545
2683
|
/**
|
|
@@ -3435,10 +3573,26 @@ export async function safeScreenshot(driver, name, screenshots, transcript, obse
|
|
|
3435
3573
|
}
|
|
3436
3574
|
}
|
|
3437
3575
|
|
|
3438
|
-
async function driverStop(driver, outcome, log, reason) {
|
|
3576
|
+
async function driverStop(driver, outcome, log, reason, transcript = null) {
|
|
3439
3577
|
try {
|
|
3440
3578
|
const stopped = await driver.stop({ reason });
|
|
3441
3579
|
if (stopped?.recording) outcome.recording = stopped.recording;
|
|
3580
|
+
// The SDK pause hook (./pauseHook.js): what the game said, never the nonce.
|
|
3581
|
+
// Slow motion asked of a driver with no pause hook channel at all (a bridge that did not opt in) is still said.
|
|
3582
|
+
const timeControl = stopped?.timeControl
|
|
3583
|
+
? stopped.timeControl
|
|
3584
|
+
: outcome.slowMotion ? { hook: false, slow_motion: outcome.slowMotion } : null;
|
|
3585
|
+
if (timeControl) {
|
|
3586
|
+
outcome.timeControl = timeControl;
|
|
3587
|
+
// Into the uploaded step log too, so the report can say whether the game was paused (the summary never holds the nonce).
|
|
3588
|
+
if (transcript && typeof transcript.write === 'function') {
|
|
3589
|
+
try { transcript.write({ kind: 'time_control', ...timeControl }); } catch { /* the step log is closed: the outcome still has it */ }
|
|
3590
|
+
}
|
|
3591
|
+
if (timeControl.used) log(`the game's SDK paused it between decisions (${timeControl.pause_mode}; unscaled time ${String(timeControl.unscaled_time).replace('_', ' ')}${timeControl.auto_resumed ? `; resumed on its own ${timeControl.auto_resumed} times` : ''}${timeControl.auto_resume_refused ? `; the game's own handler refused ${timeControl.auto_resume_refused} of those resumes, so it may have stayed frozen` : ''}).`);
|
|
3592
|
+
else if (timeControl.hook && timeControl.pause_mode === 'none') log("the game's SDK offered the pause hook but the game registered no time handler, so it ran in real time.");
|
|
3593
|
+
const speed = speedSentence(timeControl);
|
|
3594
|
+
if (speed) log(speed);
|
|
3595
|
+
}
|
|
3442
3596
|
if (stopped && stopped.videoPath) outcome.videoPath = stopped.videoPath;
|
|
3443
3597
|
// A default recording that could not be made here is said once, with why.
|
|
3444
3598
|
if (stopped && stopped.recordingSkipped && !stopped.videoPath) {
|
package/src/run/pixels.js
CHANGED
|
@@ -8,9 +8,11 @@
|
|
|
8
8
|
// on both sides: a caret (about 2 by 30 pixels) is neither, one typed character
|
|
9
9
|
// (about 10 by 16) is.
|
|
10
10
|
//
|
|
11
|
-
// The decoder reads the
|
|
12
|
-
//
|
|
13
|
-
// the
|
|
11
|
+
// The decoder reads the non-interlaced RGB and RGBA PNGs that Chromium and
|
|
12
|
+
// Godot write (8 bits a channel) and that Flutter's Impeller writes on macOS
|
|
13
|
+
// (16 bits a channel, read as their high byte: a game's own frame from the
|
|
14
|
+
// Flutter SDK, measured). Anything else answers null, and every caller falls
|
|
15
|
+
// back to the bytes.
|
|
14
16
|
import { createHash } from 'node:crypto';
|
|
15
17
|
import zlib from 'node:zlib';
|
|
16
18
|
|
|
@@ -21,7 +23,8 @@ export const MAX_PIXELS = 4096 * 4096;
|
|
|
21
23
|
|
|
22
24
|
/**
|
|
23
25
|
* @param {Buffer} buf
|
|
24
|
-
* @returns {{width: number, height: number, channels: number, data: Buffer}|null}
|
|
26
|
+
* @returns {{width: number, height: number, channels: number, depth: number, data: Buffer}|null} 8 bits a channel in
|
|
27
|
+
* `data` whatever the PNG's own `depth`
|
|
25
28
|
*/
|
|
26
29
|
export function decodePng(buf) {
|
|
27
30
|
if (!Buffer.isBuffer(buf) || buf.length < 33 || !buf.subarray(0, 8).equals(SIGNATURE)) return null;
|
|
@@ -29,6 +32,7 @@ export function decodePng(buf) {
|
|
|
29
32
|
let width = 0;
|
|
30
33
|
let height = 0;
|
|
31
34
|
let channels = 0;
|
|
35
|
+
let depth = 8;
|
|
32
36
|
const idat = [];
|
|
33
37
|
while (off + 8 <= buf.length) {
|
|
34
38
|
const len = buf.readUInt32BE(off);
|
|
@@ -38,10 +42,10 @@ export function decodePng(buf) {
|
|
|
38
42
|
if (body.length < 13) return null;
|
|
39
43
|
width = body.readUInt32BE(0);
|
|
40
44
|
height = body.readUInt32BE(4);
|
|
41
|
-
|
|
45
|
+
depth = body[8];
|
|
42
46
|
const colour = body[9];
|
|
43
47
|
const interlace = body[12];
|
|
44
|
-
if (depth
|
|
48
|
+
if (![8, 16].includes(depth) || interlace !== 0 || ![2, 6].includes(colour)) return null;
|
|
45
49
|
if (width * height > MAX_PIXELS) return null;
|
|
46
50
|
channels = colour === 6 ? 4 : 3;
|
|
47
51
|
} else if (type === 'IDAT') idat.push(body);
|
|
@@ -55,7 +59,9 @@ export function decodePng(buf) {
|
|
|
55
59
|
} catch {
|
|
56
60
|
return null;
|
|
57
61
|
}
|
|
58
|
-
|
|
62
|
+
// Filters work on bytes, a whole pixel apart: 2 bytes a channel at 16 bits.
|
|
63
|
+
const bpp = channels * (depth / 8);
|
|
64
|
+
const stride = width * bpp;
|
|
59
65
|
if (raw.length < height * (stride + 1)) return null;
|
|
60
66
|
const data = Buffer.alloc(height * stride);
|
|
61
67
|
for (let y = 0; y < height; y += 1) {
|
|
@@ -64,9 +70,9 @@ export function decodePng(buf) {
|
|
|
64
70
|
const out = data.subarray(y * stride, (y + 1) * stride);
|
|
65
71
|
const prev = y ? data.subarray((y - 1) * stride, y * stride) : null;
|
|
66
72
|
for (let x = 0; x < stride; x += 1) {
|
|
67
|
-
const a = x >=
|
|
73
|
+
const a = x >= bpp ? out[x - bpp] : 0;
|
|
68
74
|
const b = prev ? prev[x] : 0;
|
|
69
|
-
const c = prev && x >=
|
|
75
|
+
const c = prev && x >= bpp ? prev[x - bpp] : 0;
|
|
70
76
|
let v = line[x];
|
|
71
77
|
if (filter === 1) v += a;
|
|
72
78
|
else if (filter === 2) v += b;
|
|
@@ -81,7 +87,13 @@ export function decodePng(buf) {
|
|
|
81
87
|
out[x] = v & 0xff;
|
|
82
88
|
}
|
|
83
89
|
}
|
|
84
|
-
|
|
90
|
+
if (depth === 16) {
|
|
91
|
+
// Each channel's high byte: 8 bits a channel from here on.
|
|
92
|
+
const narrow = Buffer.alloc(width * height * channels);
|
|
93
|
+
for (let i = 0; i < narrow.length; i += 1) narrow[i] = data[i * 2];
|
|
94
|
+
return { width, height, channels, depth, data: narrow };
|
|
95
|
+
}
|
|
96
|
+
return { width, height, channels, depth, data };
|
|
85
97
|
}
|
|
86
98
|
|
|
87
99
|
export const BLOCK = 4;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Faster decisions: one model turn plans several inputs, the runner plays
|
|
3
|
+
* them back to back, and each is checked against the frame after it before
|
|
4
|
+
* the next is sent. docs/hosted-direct/NATIVE_GPU_PLAN.md section 4c in the
|
|
5
|
+
* platform repository is the design; this is the local half.
|
|
6
|
+
*
|
|
7
|
+
* A turn that sends several inputs already plays them in order (the persona
|
|
8
|
+
* loop, one model call for all of them), and on a game that stands still
|
|
9
|
+
* between inputs the model's thinking costs no game time. What was missing
|
|
10
|
+
* is the check between them: a plan of "jump, run right, jump" went on
|
|
11
|
+
* running right after the first jump landed the character in a pit, and a
|
|
12
|
+
* click planned for a menu landed on the level that replaced it. This file
|
|
13
|
+
* is that check. It asks no model anything and reads only what the runner
|
|
14
|
+
* measured:
|
|
15
|
+
*
|
|
16
|
+
* failed the step did not reach the game (a target that did not
|
|
17
|
+
* resolve, an input the driver cannot send);
|
|
18
|
+
* unchanged the step said what it expected and the screen did not change
|
|
19
|
+
* at all;
|
|
20
|
+
* scene the game moved to another scene (Godot's current scene file),
|
|
21
|
+
* which no step after it was planned against;
|
|
22
|
+
* death the game's own state counted a death or a lost life
|
|
23
|
+
* (a `deaths` value from a _ravensight_state() hook).
|
|
24
|
+
*
|
|
25
|
+
* The steps after a stop are answered "Not played" and spend nothing, so the
|
|
26
|
+
* next turn plans again from the screen as it is. The record of plans, how
|
|
27
|
+
* many steps each played and why any stopped, is one line of the step log.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/** The reasons a plan stops, in the step log's words. */
|
|
31
|
+
export const STOP_REASONS = Object.freeze(['failed', 'unchanged', 'scene', 'death']);
|
|
32
|
+
|
|
33
|
+
const clip = (value, n) => String(value ?? '').replace(/\s+/g, ' ').trim().slice(0, n);
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Whether the rest of a plan should be played after this step, and why not.
|
|
37
|
+
*
|
|
38
|
+
* @param {Object} step
|
|
39
|
+
* @param {{changed?: boolean, error?: string|null, driverError?: boolean, refused?: string}} step.executed what executeTool answered
|
|
40
|
+
* @param {string|null} [step.expected] what the step said it expected (expect / intent)
|
|
41
|
+
* @param {string|null} [step.sceneBefore]
|
|
42
|
+
* @param {string|null} [step.sceneAfter]
|
|
43
|
+
* @param {number|null} [step.deathsBefore]
|
|
44
|
+
* @param {number|null} [step.deathsAfter]
|
|
45
|
+
* @returns {null|{reason: string, detail: string}}
|
|
46
|
+
*/
|
|
47
|
+
export function planStop({ executed, expected = null, sceneBefore = null, sceneAfter = null, deathsBefore = null, deathsAfter = null } = {}) {
|
|
48
|
+
if (!executed) return null;
|
|
49
|
+
if (executed.refused) return null;
|
|
50
|
+
if (executed.error) return { reason: 'failed', detail: `it did not reach the game (${clip(executed.error, 120)})` };
|
|
51
|
+
if (Number.isFinite(deathsBefore) && Number.isFinite(deathsAfter) && deathsAfter > deathsBefore) return { reason: 'death', detail: 'the game counted a death or a lost life' };
|
|
52
|
+
if (sceneBefore && sceneAfter && sceneBefore !== sceneAfter) return { reason: 'scene', detail: `the game moved to another scene (${clip(sceneAfter, 80)})` };
|
|
53
|
+
if (expected && executed.changed === false) return { reason: 'unchanged', detail: `it was meant to "${clip(expected, 80)}" and the screen did not change` };
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** What the persona reads for a step the stopped plan did not play. */
|
|
58
|
+
export function notPlayedText(stop, stepNumber) {
|
|
59
|
+
return `Not played: the plan stopped after step ${stepNumber} because ${stop.detail}. Nothing was spent on this step. Look at the screen above and plan again from it.`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The run's record of its plans.
|
|
64
|
+
*/
|
|
65
|
+
export function createPlanGuard() {
|
|
66
|
+
const totals = { plans: 0, planned_steps: 0, played_steps: 0, stopped: 0, single_steps: 0, model_turns: 0 };
|
|
67
|
+
const reasons = Object.fromEntries(STOP_REASONS.map(reason => [reason, 0]));
|
|
68
|
+
let turn = null;
|
|
69
|
+
return {
|
|
70
|
+
/** A model turn with this many input steps in it. */
|
|
71
|
+
begin(inputs) {
|
|
72
|
+
totals.model_turns += 1;
|
|
73
|
+
turn = { inputs: Math.max(0, inputs | 0), played: 0, stop: null };
|
|
74
|
+
if (turn.inputs >= 2) { totals.plans += 1; totals.planned_steps += turn.inputs; } else if (turn.inputs === 1) totals.single_steps += 1;
|
|
75
|
+
},
|
|
76
|
+
/** One input step was played; answers the stop when the rest should not be. */
|
|
77
|
+
played(check) {
|
|
78
|
+
if (!turn) return null;
|
|
79
|
+
turn.played += 1;
|
|
80
|
+
if (turn.inputs >= 2) totals.played_steps += 1;
|
|
81
|
+
if (turn.stop || turn.played >= turn.inputs) return null;
|
|
82
|
+
const stop = planStop(check);
|
|
83
|
+
if (stop) {
|
|
84
|
+
turn.stop = { ...stop, after: turn.played };
|
|
85
|
+
totals.stopped += 1;
|
|
86
|
+
reasons[stop.reason] += 1;
|
|
87
|
+
}
|
|
88
|
+
return turn.stop;
|
|
89
|
+
},
|
|
90
|
+
/** The stop in effect for the rest of this turn, or null. */
|
|
91
|
+
get stopped() { return turn && turn.stop ? turn.stop : null; },
|
|
92
|
+
summary() {
|
|
93
|
+
return {
|
|
94
|
+
...totals,
|
|
95
|
+
stop_reasons: { ...reasons },
|
|
96
|
+
// Inputs played per model turn that sent any: what "faster decisions" buys.
|
|
97
|
+
inputs_per_turn: totals.model_turns > 0 ? Number(((totals.played_steps + totals.single_steps) / Math.max(1, totals.plans + totals.single_steps)).toFixed(2)) : 0
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export default { planStop, notPlayedText, createPlanGuard, STOP_REASONS };
|
package/src/run/replay.js
CHANGED
|
@@ -84,7 +84,7 @@ function divergence(step, frame, expected, actual) {
|
|
|
84
84
|
* @param {(options: Object) => Object} [input.makeDriver] - test seam
|
|
85
85
|
* @returns {Promise<Object>} the simulation replay's result shape, plus counts
|
|
86
86
|
*/
|
|
87
|
-
export async function replayTrace({ text, projectDir, godotPath, headless, runDir, signal, env, makeDriver = options => new GodotDriver(options) }) {
|
|
87
|
+
export async function replayTrace({ text, projectDir, godotPath, headless, runDir, signal, env, extraEnv = null, start = null, launchArgs = [], makeDriver = options => new GodotDriver(options) }) {
|
|
88
88
|
const trace = parseTrace(text);
|
|
89
89
|
const { header, boot, steps } = trace;
|
|
90
90
|
const driver = makeDriver({
|
|
@@ -97,6 +97,12 @@ export async function replayTrace({ text, projectDir, godotPath, headless, runDi
|
|
|
97
97
|
seed: header.seed,
|
|
98
98
|
recordTrace: false,
|
|
99
99
|
...(env ? { env } : {}),
|
|
100
|
+
// The variables the run was started with beyond the allowlist are the same game's too.
|
|
101
|
+
...(extraEnv && Object.keys(extraEnv).length ? { extraEnv } : {}),
|
|
102
|
+
// A run that started from a save or a start spec is replayed from the same start.
|
|
103
|
+
...(start ? { start } : {}),
|
|
104
|
+
// The same launch arguments as the run (--launch-arg), or as its trace header kept them.
|
|
105
|
+
...(launchArgs && launchArgs.length ? { launchArgs } : Array.isArray(header.launch_args) && header.launch_args.length ? { launchArgs: header.launch_args.map(String) } : {}),
|
|
100
106
|
});
|
|
101
107
|
const result = {
|
|
102
108
|
matched: true,
|