ravensight-playtest 0.12.0 → 0.13.1

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.
@@ -13,11 +13,26 @@ import { CACHE_WRITE_WEIGHT, OUTPUT_WEIGHT } from './usage.js';
13
13
  * report that followed did not fit either.
14
14
  *
15
15
  * So before every act turn the loop asks this module whether, after that
16
- * turn, the report call would still be admitted. Both projections are sized
17
- * from the requests themselves (the act turn about to be sent and the report
18
- * prompt as it would be built now), in input-token units, and priced at what
19
- * one unit has actually cost this run (the server's spend over the ledger's
20
- * weighted tokens, ./usage.js). No price is held here.
16
+ * turn, every call of the report phase would still be admitted. The
17
+ * projections are sized from the requests themselves (the act turn about to
18
+ * be sent and the report phase's requests as they would be built now), in
19
+ * input-token units, and priced at what one unit has actually cost this run
20
+ * (the server's spend over the ledger's weighted tokens, ./usage.js). No price
21
+ * is held here.
22
+ *
23
+ * The report phase is more than one call. Up to 0.12.0 the reserve held the
24
+ * report turn alone, and A1 of the November 19 mobile proofs
25
+ * (pt_run_c0605d330084a582db91) showed what that costs: its wrap-up turn was
26
+ * granted on that figure, then the brief choice check, a report turn that
27
+ * wrote report.md and a second turn for report.json came after it, the second
28
+ * was refused, and a run charged in full ended with a partial report and no
29
+ * claim checked. So the reserve now holds each call the report phase makes, at
30
+ * what the proxy projects for it ({@link reportPhaseUnits}): the choice check
31
+ * when the brief has text to check, the report.md turn, the report.json turn
32
+ * (the same request again with the first turn's output in it), and one claim
33
+ * check for each issue the report can be expected to name. A call's projection
34
+ * is the most it can cost, so the sum is enough for all of them to be admitted
35
+ * in turn.
21
36
  */
22
37
 
23
38
  /** Characters per input token, the proxy's own projection rule. */
@@ -61,6 +76,45 @@ export function requestBytes(body) {
61
76
  return Buffer.byteLength(JSON.stringify(body));
62
77
  }
63
78
 
79
+ /**
80
+ * What one output token of the report.md turn weighs, in UTF-8 bytes, when the
81
+ * report.json turn sends it back as input. Prose and markdown are about four
82
+ * bytes a token (A1's report.md was 7,642 bytes of JSON-quoted text); the
83
+ * report margin is on top.
84
+ */
85
+ export const ECHO_BYTES_PER_TOKEN = 4;
86
+
87
+ /**
88
+ * The report phase in input-token units: each call it makes, at the proxy's
89
+ * projection of its request.
90
+ *
91
+ * - `choice`: the brief choice check (./choiceCheck.js), `null` when the run
92
+ * has no brief text for it to check.
93
+ * - the report.md turn: the report request, with REPORT_RESERVE_MARGIN for
94
+ * the play still to come and a dearer tier.
95
+ * - the report.json turn: a model that writes report.md first is asked once
96
+ * more for report.json, with the same request and its own report.md turn in
97
+ * it, at most `reportMaxTokens` of output at ECHO_BYTES_PER_TOKEN.
98
+ * - `claims`: `count` claim checks, each one picture and one claim.
99
+ *
100
+ * @param {Object} args
101
+ * @param {number} args.reportChars the report request's UTF-8 JSON length
102
+ * @param {number} args.reportMaxTokens
103
+ * @param {{chars: number, imageUnits?: number, maxTokens: number}|null} [args.choice]
104
+ * @param {{count: number, chars: number, imageUnits?: number, maxTokens: number}|null} [args.claims]
105
+ * @returns {{choice: number, markdown: number, json: number, claims: number, total: number}}
106
+ */
107
+ export function reportPhaseUnits({ reportChars, reportMaxTokens, choice = null, claims = null }) {
108
+ const outputCeiling = Math.max(0, Number(reportMaxTokens) || 0);
109
+ const reportBytes = Math.max(0, Number(reportChars) || 0);
110
+ const markdown = projectionUnits(reportBytes, outputCeiling) * REPORT_RESERVE_MARGIN;
111
+ const json = projectionUnits(reportBytes + outputCeiling * ECHO_BYTES_PER_TOKEN, outputCeiling) * REPORT_RESERVE_MARGIN;
112
+ const check = choice ? projectionUnits(choice.chars, choice.maxTokens, choice.imageUnits) : 0;
113
+ const count = claims ? Math.max(0, Math.floor(Number(claims.count) || 0)) : 0;
114
+ const claimUnits = count > 0 ? count * projectionUnits(claims.chars, claims.maxTokens, claims.imageUnits) : 0;
115
+ return { choice: check, markdown, json, claims: claimUnits, total: check + markdown + json + claimUnits };
116
+ }
117
+
64
118
  /**
65
119
  * Whether play has to stop now so the report still fits.
66
120
  *
@@ -74,9 +128,11 @@ export function requestBytes(body) {
74
128
  * (its tools differ), so it costs its whole projection, not a recent cached turn
75
129
  * @param {number} args.reportChars the report request's JSON length if it were sent now
76
130
  * @param {number} args.reportMaxTokens
131
+ * @param {{chars: number, imageUnits?: number, maxTokens: number}|null} [args.choice] the brief choice check, see reportPhaseUnits
132
+ * @param {{count: number, chars: number, imageUnits?: number, maxTokens: number}|null} [args.claims] the claim checks, see reportPhaseUnits
77
133
  * @returns {{stop: boolean, known: boolean, figures: Object}}
78
134
  */
79
- export function reserveDecision({ usdMax, spend, actChars, actImageUnits = 0, actMaxTokens, actCostUnits, actUncached = false, reportChars, reportMaxTokens }) {
135
+ export function reserveDecision({ usdMax, spend, actChars, actImageUnits = 0, actMaxTokens, actCostUnits, actUncached = false, reportChars, reportMaxTokens, choice = null, claims = null }) {
80
136
  const max = Number(usdMax);
81
137
  if (!Number.isFinite(max) || max <= 0 || !spend || !Number.isFinite(spend.usdPerUnit) || spend.usdPerUnit <= 0) {
82
138
  return { stop: false, known: false, figures: {} };
@@ -85,9 +141,10 @@ export function reserveDecision({ usdMax, spend, actChars, actImageUnits = 0, ac
85
141
  const actProjected = price * projectionUnits(actChars, actMaxTokens, actImageUnits);
86
142
  const recentCost = price * Math.max(0, Number(actCostUnits) || 0) * ACT_COST_MARGIN;
87
143
  const actCost = actUncached ? Math.max(recentCost, actProjected) : recentCost;
88
- const reportProjected = price * projectionUnits(reportChars, reportMaxTokens) * REPORT_RESERVE_MARGIN;
144
+ const phase = reportPhaseUnits({ reportChars, reportMaxTokens, choice, claims });
145
+ const reportProjected = price * phase.total;
89
146
  const flat = max * FLAT_MARGIN_RATIO;
90
- // The act turn itself has to be admitted, and after it the report has to be.
147
+ // The act turn itself has to be admitted, and after it every call of the report phase has to be.
91
148
  const actFits = spend.usd + actProjected <= max;
92
149
  const reportFitsAfter = spend.usd + actCost + reportProjected + flat <= max;
93
150
  const round = value => Math.round(value * 1e6) / 1e6;
@@ -103,6 +160,11 @@ export function reserveDecision({ usdMax, spend, actChars, actImageUnits = 0, ac
103
160
  act_projected_usd: round(actProjected),
104
161
  act_cost_usd: round(actCost),
105
162
  report_reserve_usd: round(reportProjected),
163
+ choice_check_usd: round(price * phase.choice),
164
+ report_md_usd: round(price * phase.markdown),
165
+ report_json_usd: round(price * phase.json),
166
+ claim_checks_usd: round(price * phase.claims),
167
+ claim_checks: claims ? Math.max(0, Math.floor(Number(claims.count) || 0)) : 0,
106
168
  margin_usd: round(flat)
107
169
  }
108
170
  };
@@ -234,17 +234,18 @@ export function insertUnderHeading(markdown, heading, line) {
234
234
  }
235
235
 
236
236
  /**
237
- * Ask the one question.
237
+ * The check's request, or null when there is no brief to check: what
238
+ * {@link checkBriefChoice} sends, and what the run's budget reserve sizes
239
+ * during play (./budgetReserve.js), so the two are the same request.
238
240
  *
239
241
  * @param {Object} args
240
242
  * @param {string} args.briefText the brief as the persona was shown it
241
243
  * @param {string} args.actionText the numbered action list the report step was given
242
244
  * @param {Array<Object>} args.records transcript observation and action lines
243
245
  * @param {{data: string, mediaType: string}|null} [args.frame] the last screen, as the model is shown it
244
- * @returns {Promise<{choice: string, result: string, shown: string}|null>} null
245
- * when the brief names no choice, or the check could not be made
246
+ * @returns {{system: string, messages: Array<Object>}|null}
246
247
  */
247
- export async function checkBriefChoice({ client, jobId, runId, briefText, actionText, records, frame = null, ledger = null, transcript = null, log = () => {} }) {
248
+ export function choiceCheckRequest({ briefText, actionText, records, frame = null }) {
248
249
  const brief = String(briefText == null ? '' : briefText).trim();
249
250
  if (!brief || brief === '(none)' || brief === 'null') return null;
250
251
  const screens = screensForCheck(records);
@@ -265,6 +266,24 @@ export async function checkBriefChoice({ client, jobId, runId, briefText, action
265
266
  'Your one line:'
266
267
  ].join('\n')
267
268
  });
269
+ return { system: CHOICE_CHECK_SYSTEM, messages: [{ role: 'user', content }] };
270
+ }
271
+
272
+ /**
273
+ * Ask the one question.
274
+ *
275
+ * @param {Object} args
276
+ * @param {string} args.briefText the brief as the persona was shown it
277
+ * @param {string} args.actionText the numbered action list the report step was given
278
+ * @param {Array<Object>} args.records transcript observation and action lines
279
+ * @param {{data: string, mediaType: string}|null} [args.frame] the last screen, as the model is shown it
280
+ * @returns {Promise<{choice: string, result: string, shown: string}|null>} null
281
+ * when the brief names no choice, or the check could not be made
282
+ */
283
+ export async function checkBriefChoice({ client, jobId, runId, briefText, actionText, records, frame = null, ledger = null, transcript = null, log = () => {} }) {
284
+ const request = choiceCheckRequest({ briefText, actionText, records, frame });
285
+ if (!request) return null;
286
+ const brief = String(briefText).trim();
268
287
  let answer;
269
288
  const askedAt = Date.now();
270
289
  try {
@@ -273,8 +292,8 @@ export async function checkBriefChoice({ client, jobId, runId, briefText, action
273
292
  jobId,
274
293
  runId,
275
294
  step: STEPS.personaAct,
276
- system: CHOICE_CHECK_SYSTEM,
277
- messages: [{ role: 'user', content }],
295
+ system: request.system,
296
+ messages: request.messages,
278
297
  maxTokens: CHOICE_CHECK_MAX_TOKENS,
279
298
  escalate: false,
280
299
  maxAttempts: 1
@@ -309,4 +328,4 @@ export async function checkBriefChoice({ client, jobId, runId, briefText, action
309
328
  return check;
310
329
  }
311
330
 
312
- export default { checkBriefChoice, choiceNamedInBrief, parseChoiceAnswer, choiceLine, choiceFromMarkdown, writeChoiceIntoMarkdown, screensForCheck, visibleText };
331
+ export default { checkBriefChoice, choiceCheckRequest, choiceNamedInBrief, parseChoiceAnswer, choiceLine, choiceFromMarkdown, writeChoiceIntoMarkdown, screensForCheck, visibleText };
@@ -3,6 +3,7 @@ import { pngFingerprint, screenDelta, significant } from '../pixels.js';
3
3
  import { findRegions } from '../regions.js';
4
4
  import { createMarker, isMarkTarget, marksFor, marksText, resolveMark } from '../marks.js';
5
5
  import { gameTime, timeFreezeInit } from '../timeFreeze.js';
6
+ import { createSdkSessions, sdkSessionAnswer } from '../sdkSession.js';
6
7
  import { STRIP_MIN_MS, stripNote, stripTimes, stripTokens } from '../strip.js';
7
8
  import { GAMEPAD_BUTTONS, gamepadState, virtualGamepadInit } from '../gamepad.js';
8
9
  // any-game hook: sound as measured evidence (../anygame/sound.js).
@@ -16,6 +17,9 @@ import { recordingLimits, recordingViewport, recordingDirectory, recordingMetada
16
17
  import path from 'node:path';
17
18
  import { gameRefusal, runnerGone } from '../gameRefusal.js';
18
19
  import { createAvoidGuard } from '../avoid.js';
20
+ import { classifyRequest, createSafetyCounts, networkRules } from '../livesite/network.js';
21
+ import { hostResolverRules, ravensightHosts } from '../livesite/resolver.js';
22
+ import { LiveSiteError, MASKED_EMAIL, MASKED_PASSWORD, maskSecretsInit, outcomeMessage, performSignIn } from '../livesite/browser.js';
19
23
  import {
20
24
  DEFAULT_DRAG_MS, DOUBLE_CLICK_GAP_MS, KEY_REPEAT_DELAY_MS, KEY_REPEAT_INTERVAL_MS, MAX_DRAG_MS, MAX_HOLD_MS,
21
25
  dragPath, mouseButton, sequenceEvents, webKeyName, wheelNotches
@@ -1208,6 +1212,22 @@ export function tapSdkEvents(request, log) {
1208
1212
 
1209
1213
  export const CHECK_PLAYTEST_IDENTITY = Object.freeze({ token: 'check', runId: null, jobId: null, persona: 'check' });
1210
1214
 
1215
+ /**
1216
+ * Chromium's arguments. A recorded run is muted; a live site run can resolve
1217
+ * only the names its rules allow (../livesite/resolver.js), because the route
1218
+ * never sees a redirect's next hop or a WebSocket.
1219
+ *
1220
+ * @param {{video: boolean, liveSite: Object|null}} args
1221
+ * @returns {Array<string>}
1222
+ */
1223
+ export function browserLaunchArgs({ video, liveSite }) {
1224
+ const args = video ? ['--mute-audio'] : [];
1225
+ if (liveSite) {
1226
+ args.push(`--host-resolver-rules=${hostResolverRules({ startHost: liveSite.startHost, local: liveSite.local, addresses: liveSite.addresses || [], ravensightHosts: ravensightHosts(liveSite.ravensightOrigins || []) })}`);
1227
+ }
1228
+ return args;
1229
+ }
1230
+
1211
1231
  /**
1212
1232
  * @param {Object} opts
1213
1233
  * @param {(specifier: string) => Promise<any>} [opts.importer] test seam
@@ -1412,7 +1432,7 @@ export async function needsFrame(page, text) {
1412
1432
  try { return (await page.evaluate(pageHasLargeCanvas, LARGE_CANVAS_SHARE)) === true; } catch { return false; }
1413
1433
  }
1414
1434
 
1415
- export function createWebDriver({ importer, headless = true, playtest = null, platform = process.platform, modifier = null, recording = {}, now = () => Date.now(), inspectVideo = probeVideo, freezeTime = true, touch = false, frameStrip = true } = {}) {
1435
+ export function createWebDriver({ importer, headless = true, playtest = null, platform = process.platform, modifier = null, recording = {}, now = () => Date.now(), inspectVideo = probeVideo, freezeTime = true, touch = false, frameStrip = true, liveSite = null } = {}) {
1416
1436
  const editModifier = modifier === 'Meta' || modifier === 'Control' ? modifier : platformModifier(platform);
1417
1437
  // What the brief asks the run to stay out of (../avoid.js): an input on such a control is never sent (setAvoid).
1418
1438
  let avoidGuard = createAvoidGuard([]);
@@ -1421,6 +1441,9 @@ export function createWebDriver({ importer, headless = true, playtest = null, pl
1421
1441
  let page = null;
1422
1442
  // The game's own Ravensight SDK events, read from the track calls the page makes (read only: every call goes out unchanged).
1423
1443
  const gameEvents = createGameEvents();
1444
+ // The game's own SDK opening its session: each answer, so a refusal that leaves the run with no game events is said plainly (../sdkSession.js).
1445
+ const sdkSessions = createSdkSessions();
1446
+ const sdkSessionReads = new Set();
1424
1447
  let target = null;
1425
1448
  let runDirectory = null;
1426
1449
  let videoRequested = false;
@@ -1498,6 +1521,65 @@ export function createWebDriver({ importer, headless = true, playtest = null, pl
1498
1521
  let soundTest = null;
1499
1522
  // Inputs the page did not take that are the runner's limit, for the notes.
1500
1523
  const inputLimits = [];
1524
+ // A live URL playtest (../livesite/): the network rules every request is held to, what they kept
1525
+ // from the site, the sign-in's outcome (never a value), and a session header for the start host.
1526
+ const liveRules = liveSite ? networkRules({ startUrl: liveSite.startUrl, local: liveSite.local, extraOrigins: liveSite.ravensightOrigins || [] }) : null;
1527
+ const liveSafety = createSafetyCounts();
1528
+ let liveSignIn = null;
1529
+ const sessionHeader = liveSite && liveSite.signIn && liveSite.signIn.kind === 'header' ? liveSite.signIn.credential().header : null;
1530
+
1531
+ /**
1532
+ * The one route of a live site run (CONTRACT.md 6.1), for the sign-in
1533
+ * context and the play context. In the play context a request it lets
1534
+ * through falls back to the build guard below, so a top-level navigation off
1535
+ * the start address is still answered 204 and noted for the persona.
1536
+ *
1537
+ * @param {any} route
1538
+ * @param {{onBlocked?: (host: string) => void, play?: boolean}} hooks
1539
+ */
1540
+ function liveRoute(route, { onBlocked = null, play = false } = {}) {
1541
+ const request = route.request();
1542
+ const decision = classifyRequest(liveRules, { url: request.url(), method: request.method() });
1543
+ if (decision.action === 'ingest') {
1544
+ const headers = { ...request.headers() };
1545
+ if (decision.playtestHeader && playtest && playtest.token) headers['x-ravensight-playtest'] = String(playtest.token);
1546
+ return route.continue({ headers });
1547
+ }
1548
+ if (decision.action === 'refuse') {
1549
+ liveSafety.refuse(decision.path);
1550
+ return route.fulfill({ status: 403, contentType: 'application/json', body: '{"error":"sandbox_refused"}' });
1551
+ }
1552
+ if (decision.action === 'block') {
1553
+ liveSafety.block(decision.host);
1554
+ if (onBlocked) onBlocked(decision.host);
1555
+ const topLevel = request.isNavigationRequest() ? isTopLevel(request) : false;
1556
+ if (topLevel !== false) {
1557
+ if (play && guardArmed) recordOffSite(request.url(), topLevel === null ? 'new window' : 'navigation');
1558
+ return route.fulfill({ status: 204, body: '' });
1559
+ }
1560
+ return route.abort('blockedbyclient');
1561
+ }
1562
+ const overrides = decision.startHost && sessionHeader ? { headers: { ...request.headers(), [sessionHeader.name.toLowerCase()]: sessionHeader.value } } : undefined;
1563
+ return play ? route.fallback(overrides) : route.continue(overrides);
1564
+ }
1565
+
1566
+ /** The live route and the page's playtest identity on the sign-in context. */
1567
+ async function prepareSignInContext(signInContext, { onBlocked }) {
1568
+ await signInContext.route('**/*', route => liveRoute(route, { onBlocked }));
1569
+ // A redirect hop is not routed: a top-level one off the site's hosts is still the sign-in leaving them.
1570
+ signInContext.on('request', request => {
1571
+ try {
1572
+ if (!request.isNavigationRequest() || !request.redirectedFrom()) return;
1573
+ const decision = classifyRequest(liveRules, { url: request.url(), method: request.method() });
1574
+ if (decision.action === 'block') { liveSafety.block(decision.host); onBlocked(decision.host); }
1575
+ } catch {
1576
+ // A request that cannot be read is not a sign-in leaving the site.
1577
+ }
1578
+ });
1579
+ if (playtest && playtest.token) {
1580
+ await signInContext.addInitScript(injectPlaytestIdentity, { token: playtest.token, runId: playtest.runId || null, jobId: playtest.jobId || null, persona: playtest.persona || null });
1581
+ }
1582
+ }
1501
1583
 
1502
1584
  /** @param {string} candidate */
1503
1585
  function onBuild(candidate) {
@@ -2805,10 +2887,25 @@ export function createWebDriver({ importer, headless = true, playtest = null, pl
2805
2887
  try {
2806
2888
  const playwright = await loadPlaywright(importer);
2807
2889
  await mkdir(runDir, { recursive: true });
2808
- browser = await playwright.chromium.launch({ headless, ...(videoRequested ? { args: ['--mute-audio'] } : {}) });
2890
+ const launchArgs = browserLaunchArgs({ video: videoRequested, liveSite });
2891
+ browser = await playwright.chromium.launch({ headless, ...(launchArgs.length ? { args: launchArgs } : {}) });
2892
+ const contextBase = { viewport, ...(touch ? { hasTouch: true, isMobile: true, deviceScaleFactor: 1, userAgent: PHONE_USER_AGENT } : {}) };
2893
+ // A live site's sign-in happens first, in a context of its own with no recording of any kind; the
2894
+ // recorded context starts from its cookies and storage, so it never shows the form being filled.
2895
+ let storageState = null;
2896
+ if (liveSite && liveSite.signIn && liveSite.signIn.method !== 'none') {
2897
+ try {
2898
+ const signed = await performSignIn({ browser, contextOptions: contextBase, prepareContext: prepareSignInContext, liveSite, rules: liveRules, ...(liveSite.timing || {}) });
2899
+ liveSignIn = signed.outcome;
2900
+ storageState = signed.storageState;
2901
+ } catch (error) {
2902
+ if (error && error.liveSite) liveSignIn = error.signIn;
2903
+ throw error;
2904
+ }
2905
+ }
2809
2906
  context = await browser.newContext({
2810
- viewport,
2811
- ...(touch ? { hasTouch: true, isMobile: true, deviceScaleFactor: 1, userAgent: PHONE_USER_AGENT } : {}),
2907
+ ...contextBase,
2908
+ ...(storageState ? { storageState } : {}),
2812
2909
  ...(videoRequested ? { recordVideo: { dir: captureDirectory, size: viewport }, permissions: [] } : {})
2813
2910
  });
2814
2911
  // The playtest identity goes in as an init script, not as
@@ -2823,6 +2920,11 @@ export function createWebDriver({ importer, headless = true, playtest = null, pl
2823
2920
  persona: playtest.persona || null
2824
2921
  });
2825
2922
  }
2923
+ // A live site's test account never shows as page text: its email reads "test account" and its password six dots.
2924
+ if (liveSite && liveSite.signIn && liveSite.signIn.method === 'password') {
2925
+ const { email, password } = liveSite.signIn.credential();
2926
+ await context.addInitScript(maskSecretsInit, { email, password, emailLabel: MASKED_EMAIL, passwordLabel: MASKED_PASSWORD });
2927
+ }
2826
2928
  // any-game hook: the sound probe goes in before the time gate, so its sampler keeps real time. It only listens; it is read once the self test has passed.
2827
2929
  if (typeof context.addInitScript === 'function') await context.addInitScript(soundProbeInit);
2828
2930
  // One token per document: set again by every new document, kept by
@@ -2835,6 +2937,14 @@ export function createWebDriver({ importer, headless = true, playtest = null, pl
2835
2937
  if (typeof context.addInitScript === 'function') await context.addInitScript(capabilitySignalsInit);
2836
2938
  // The game's own SDK events: its track calls are read as they leave the page, never held, changed or answered here.
2837
2939
  if (typeof context.on === 'function') context.on('request', request => tapSdkEvents(request, gameEvents));
2940
+ // And the answer to its session request, read only: the status, the key's kind, the error code; never the key or the token.
2941
+ if (typeof context.on === 'function') {
2942
+ context.on('response', response => {
2943
+ const read = sdkSessionAnswer(response).then(answer => sdkSessions.record(answer), () => {});
2944
+ sdkSessionReads.add(read);
2945
+ read.finally(() => sdkSessionReads.delete(read));
2946
+ });
2947
+ }
2838
2948
  // The page never leaves the build, recording or not. A top-level
2839
2949
  // navigation off it (a clicked link, a form, a script) is answered with
2840
2950
  // an empty 204, which a browser treats as "stay where you are": the
@@ -2856,6 +2966,8 @@ export function createWebDriver({ importer, headless = true, playtest = null, pl
2856
2966
  return route.fulfill({ status: 204, body: '' });
2857
2967
  });
2858
2968
  }
2969
+ // Registered after the build guard, so it decides first and hands what it allows back to the guard.
2970
+ if (liveSite && typeof context.route === 'function') await context.route('**/*', route => liveRoute(route, { play: true }));
2859
2971
  captureStartedAt = videoRequested ? now() : null;
2860
2972
  page = await context.newPage();
2861
2973
  // A new window that did get a document (one on the build, or a blank
@@ -2977,7 +3089,14 @@ export function createWebDriver({ importer, headless = true, playtest = null, pl
2977
3089
  }
2978
3090
  });
2979
3091
 
2980
- const response = await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 30000 });
3092
+ let response;
3093
+ try {
3094
+ response = await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 30000 });
3095
+ } catch (error) {
3096
+ if (!liveSite) throw error;
3097
+ throw new LiveSiteError('site_unreachable', outcomeMessage('site_unreachable', { url, detail: String((error && error.message) || error).split('\n')[0].replace(/^page\.goto:\s*/, '').slice(0, 160) }));
3098
+ }
3099
+ if (liveSite && response && response.status() >= 500) throw new LiveSiteError('site_unreachable', outcomeMessage('site_unreachable', { url, detail: `it answered ${response.status()}` }));
2981
3100
  // A 404 is not something to guess around: the build is not there, and
2982
3101
  // guessing URLs is exactly what spec 03 forbids.
2983
3102
  if (response && response.status() >= 400) {
@@ -3152,6 +3271,12 @@ export function createWebDriver({ importer, headless = true, playtest = null, pl
3152
3271
  /** The brief's avoid lines for this run (../avoid.js): an input on a control they name is refused before the page. */
3153
3272
  setAvoid(lines) { avoidGuard = createAvoidGuard(lines); },
3154
3273
 
3274
+ /** A live site run's sign-in outcome (`{ method, ok, code, seconds }`, never a value), or null. */
3275
+ signInOutcome() { return liveSignIn ? { ...liveSignIn } : null; },
3276
+
3277
+ /** A live site run's blocked hosts and refused Ravensight paths, or null for any other run. */
3278
+ liveSiteSafety() { return liveSite ? liveSafety.toJSON() : null; },
3279
+
3155
3280
  /** The controls an input was refused on because the brief asks to stay out of them, by name. */
3156
3281
  avoidedControls() { return avoidGuard.list(); },
3157
3282
 
@@ -3207,6 +3332,12 @@ export function createWebDriver({ importer, headless = true, playtest = null, pl
3207
3332
  */
3208
3333
  /** The game's own SDK events this run (../events.js): marked at each input, flushed before the page closes, read by the report. */
3209
3334
  gameEvents,
3335
+ /** The game's own SDK's session answers: how many opened, and each refusal (../sdkSession.js). */
3336
+ async sdkSessions() {
3337
+ // An answer still being read (its body) is waited for, briefly, so a refusal at the end of play is not missed.
3338
+ if (sdkSessionReads.size > 0) await Promise.race([Promise.allSettled([...sdkSessionReads]), new Promise(resolve => setTimeout(resolve, 2000))]);
3339
+ return sdkSessions.summary();
3340
+ },
3210
3341
  /** Mark the page clock just before input `step` (or 'end' after play), so each event is placed at the step it happened. */
3211
3342
  async markGameEvents(step) {
3212
3343
  if (!page || pendingDialog || gameGone) { gameEvents.mark(step, null); return; }
package/src/run/judge.js CHANGED
@@ -19,9 +19,14 @@
19
19
  // runner's own file (./claimwords.js), and so are the rules on what the
20
20
  // game's events say about a claim (./eventclaims.js): one rule set, two paths.
21
21
  //
22
- // What a local run cannot do the way a hosted one does, and so is turned away
23
- // rather than published: a claim that nothing happens needs a replay that
24
- // watched game time run with no input (the runner's own freeze watch is a
22
+ // A claim that nothing happens is held to the hosted gate's own evidence
23
+ // (lib/claims.mjs gateClaim, the stuck branch): a replay that played the
24
+ // recorded inputs again and watched the screen while game time ran for
25
+ // STILL_MIN_GAME_MS with no input, and saw nothing change (./stillWatch.js).
26
+ // A local web run makes that watch only for a claim the run measured: the
27
+ // same named control pressed again and again, changing nothing every time
28
+ // and answering at no other moment. Anything less is turned away, as before:
29
+ // one still frame cannot settle it (the runner's own freeze watch is a
25
30
  // measurement, and is not judged here).
26
31
  //
27
32
  // MONEY (owner, 2026-11-14). Taste its check could not settle, and a judgement of difficulty from the
@@ -32,6 +37,7 @@
32
37
  // as hosted money does. With the switch off, both would be kept as `opinion` impressions instead.
33
38
  import { claimClass, claimBasis, checkSaid, praiseClaim } from './claimwords.js';
34
39
  import { eventsVerdict, eventsConfirmed, contradictedReason } from './eventclaims.js';
40
+ import { STILL_MIN_GAME_MS } from './stillWatch.js';
35
41
 
36
42
  /** Turn away unsettled taste and own-play difficulty, as the hosted judge does. See MONEY above: the owner's call. */
37
43
  export const TURN_AWAY_UNSETTLED = true;
@@ -88,9 +94,10 @@ const designedWords = check => {
88
94
  * @param {number|null} [opts.step] the action the issue belongs to
89
95
  * @param {boolean} [opts.marked]
90
96
  * @param {boolean} [opts.turnAwayUnsettled]
97
+ * @param {{measured: Object|null, replay: Object|null}|null} [opts.still] for a claim that nothing happens: what the run measured of its input (./stillWatch.js noEffectTries) and the replay that watched it (./reportChecks.js replayWebFindings)
91
98
  * @returns {{route: string, outcome: string|null, reason: string|null, cls: string, basis: string|null, impression?: {kind: string, check: string|null, note: string}, evidence?: string, events?: Array}}
92
99
  */
93
- export function judgeIssue(finding, { check = null, run = null, step = null, marked = false, turnAwayUnsettled = TURN_AWAY_UNSETTLED } = {}) {
100
+ export function judgeIssue(finding, { check = null, run = null, step = null, marked = false, turnAwayUnsettled = TURN_AWAY_UNSETTLED, still = null } = {}) {
94
101
  const { cls, basis } = claimShape(finding, { marked });
95
102
  const base = { cls, basis };
96
103
  const finding_ = extra => ({ ...base, route: 'finding', outcome: null, reason: null, ...extra });
@@ -126,7 +133,14 @@ export function judgeIssue(finding, { check = null, run = null, step = null, mar
126
133
  if (cls === 'stuck') {
127
134
  if (said === 'opposite') return away('contradicted', 'the frame at its moment contradicts it');
128
135
  if (designed) return designed;
129
- return away('unconfirmed', 'a claim that nothing happens is confirmed only by watching the screen while game time runs with no input, which this local run did not do for it; one still frame cannot settle it');
136
+ if (!still || !still.measured) return away('unconfirmed', 'a claim that nothing happens is confirmed only by watching the screen while game time runs with no input, and the run did not press the same control again and again with nothing changing; one still frame cannot settle it');
137
+ // The hosted gate's stuck rule, word for word: reproduced counts only from a watch, since the same screen following the same input says nothing about stillness.
138
+ const replay = still.replay || null;
139
+ const detail = replay && replay.detail ? ` (${text(replay.detail)})` : '';
140
+ if (replay?.state === 'reproduced' && Number(replay.watched_ms) >= STILL_MIN_GAME_MS) return finding_({ evidence: 'still_watch' });
141
+ if (replay?.state === 'reproduced') return away('unconfirmed', 'the replay reached the same screen but did not watch it while game time ran, so it could not test a claim that nothing happens');
142
+ if (replay?.state === 'not_reproduced') return away('not_reproduced', `it did not come back when the recorded inputs were played again${detail}`);
143
+ return away('unconfirmed', `a claim that nothing happens is confirmed only by watching the screen while game time runs for ${STILL_MIN_GAME_MS / 1000} seconds with no input, and that could not be done${detail}; one still frame cannot settle it`);
130
144
  }
131
145
  if (cls === 'absence') {
132
146
  if (said === 'opposite') return away('contradicted', 'the frames nearest its moment show the thing it says is missing');