ravensight-playtest 0.12.0 → 0.13.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 +82 -0
- package/docs/MOBILE.md +1 -1
- package/package.json +3 -3
- package/src/api/client.js +10 -1
- package/src/cli.js +29 -2
- package/src/commands/hosted.js +15 -0
- package/src/commands/run.js +89 -8
- package/src/run/anygame/index.js +1 -1
- package/src/run/args.js +24 -0
- package/src/run/budgetReserve.js +70 -8
- package/src/run/choiceCheck.js +26 -7
- package/src/run/drivers/web.js +118 -5
- package/src/run/livesite/browser.js +316 -0
- package/src/run/livesite/hosts.js +107 -0
- package/src/run/livesite/network.js +117 -0
- package/src/run/livesite/options.js +167 -0
- package/src/run/livesite/resolver.js +78 -0
- package/src/run/livesite/run.js +113 -0
- package/src/run/personaLoop.js +207 -24
- package/src/run/proxyClient.js +5 -1
- package/src/run/redaction.js +191 -0
- package/src/run/report.js +5 -2
- package/src/run/resume.js +30 -3
- package/src/run/state.js +3 -1
- package/src/run/tooFast.js +116 -0
- package/src/run/transcript.js +3 -1
- package/src/run/usage.js +3 -1
package/README.md
CHANGED
|
@@ -1196,6 +1196,88 @@ optional job id.
|
|
|
1196
1196
|
Opens the dashboard page for a job, or for the game. Takes `--game <gameId>` and
|
|
1197
1197
|
an optional job id.
|
|
1198
1198
|
|
|
1199
|
+
## Playtest a live URL
|
|
1200
|
+
|
|
1201
|
+
`run --url` points a playtest at your web game where it already runs: a staging
|
|
1202
|
+
or production address, or a dev server on this machine. It plays in the same
|
|
1203
|
+
browser driver as `--build-url`, and can sign in as a test account first.
|
|
1204
|
+
|
|
1205
|
+
```sh
|
|
1206
|
+
export TEST_ACCOUNT_PASSWORD='...'
|
|
1207
|
+
ravensight-playtest run --url https://play.example.com/ \
|
|
1208
|
+
--login-email tester@example.com --login-password-env TEST_ACCOUNT_PASSWORD
|
|
1209
|
+
```
|
|
1210
|
+
|
|
1211
|
+
**Which addresses.** A public host has to be verified for the game before a
|
|
1212
|
+
playtest can reach it. Add it on the Playtest page, under Test a live URL, and
|
|
1213
|
+
put the TXT record shown there on the host. `run` asks the server whether the
|
|
1214
|
+
host is verified before anything is priced; a host that is not refuses the run
|
|
1215
|
+
with the record to add, and nothing is charged. `localhost`, `127.0.0.1`, a
|
|
1216
|
+
private address and names under `.localhost`, `.local` or `.test` are a dev
|
|
1217
|
+
server on this machine and need no record. A public address must be `https`.
|
|
1218
|
+
|
|
1219
|
+
**What the browser can reach.** Only the start URL's host (and, for a dev
|
|
1220
|
+
server, other local addresses), plus your game's own Ravensight analytics
|
|
1221
|
+
calls (`/api/v1/settings`, `/api/v1/session`, `/api/v1/track` and
|
|
1222
|
+
`/api/v1/track/batch`). Every session the game opens carries the run's
|
|
1223
|
+
playtest mark, so a playtest never counts as a real player. Any other
|
|
1224
|
+
Ravensight call (website pageviews, forms, the player API) is refused in the
|
|
1225
|
+
browser and never sent. Every other host is blocked and listed in the report,
|
|
1226
|
+
for example "Not a verified host: fonts.example.net (12 requests). Verify it
|
|
1227
|
+
to let playtests load it." A dev server that loads fonts or scripts from
|
|
1228
|
+
elsewhere plays without them. The browser can also look up only those names:
|
|
1229
|
+
a verified host is pinned to a public address found just before the run (a
|
|
1230
|
+
host that answers only private addresses is refused before anything is
|
|
1231
|
+
charged), and a dev server resolves only `localhost`, `127.0.0.1` and its own
|
|
1232
|
+
host. So a redirect or a WebSocket to another host finds nothing either.
|
|
1233
|
+
|
|
1234
|
+
**Signing in.** Choose one way:
|
|
1235
|
+
|
|
1236
|
+
- `--login-email` and `--login-password-env NAME`: the password is read from
|
|
1237
|
+
the environment variable you name, never from the command line (`run`
|
|
1238
|
+
refuses `--password` and `--login-password`). It must be at least 6
|
|
1239
|
+
characters. `--sign-in-url` names the page with the form when it is not the
|
|
1240
|
+
start page, and `--sign-in-selectors` names its fields when they are not
|
|
1241
|
+
found on their own, as JSON with any of `email`, `password`, `submit` and
|
|
1242
|
+
`signedIn` (CSS or `text=`). A sign-in counts as done when `signedIn` shows,
|
|
1243
|
+
or when the password field is gone and the address changed, so a sign-in
|
|
1244
|
+
that stays on the same address needs `signedIn`.
|
|
1245
|
+
- `--session-cookie-env NAME`: a test user's `Cookie` header value
|
|
1246
|
+
(`name=value; name2=value2`), set for the start host only.
|
|
1247
|
+
- `--session-header-env NAME`: one header, `Authorization` or a name starting
|
|
1248
|
+
`X-`, as `Name: value`, sent to the start host only.
|
|
1249
|
+
|
|
1250
|
+
The sign-in happens before the first model call, in a separate browser with
|
|
1251
|
+
no video, no screenshots and no step log. Play starts from the signed-in
|
|
1252
|
+
cookies and storage, so the recording never shows the form. If the sign-in
|
|
1253
|
+
fails or the site does not load, nothing is played and no model is asked: the
|
|
1254
|
+
run ends failed with a report that says what happened and what to change.
|
|
1255
|
+
|
|
1256
|
+
| Report says | What happened |
|
|
1257
|
+
| --- | --- |
|
|
1258
|
+
| `sign_in_fields_not_found` | no email and password field on the sign-in page |
|
|
1259
|
+
| `sign_in_refused` | the site kept its form, or showed an error, after the details were sent |
|
|
1260
|
+
| `sign_in_timeout` | no signed-in page within 30 seconds, twice |
|
|
1261
|
+
| `sign_in_left_verified_hosts` | signing in went to another host, such as an outside sign-in service; use a session instead |
|
|
1262
|
+
| `site_unreachable` | the start page did not load (no answer, a certificate error, a server error) |
|
|
1263
|
+
|
|
1264
|
+
**Your test account stays on this machine.** The email, password, cookie
|
|
1265
|
+
values and header value are never sent to Ravensight and never written to the
|
|
1266
|
+
run folder, the job journal or a log. Each one, and its URL-encoded and base64
|
|
1267
|
+
forms, is replaced with `[redacted]` in every line the CLI prints or writes
|
|
1268
|
+
and in every model request, as the last step before it leaves; the run folder
|
|
1269
|
+
is scanned again before upload and `usage.json` records how many were caught
|
|
1270
|
+
(`signIn.redactions`), with the sign-in method, outcome and time, never a
|
|
1271
|
+
value. On screen the account's email reads "test account" and its password six
|
|
1272
|
+
dots, in text, fields and labels. Text a site draws into a canvas or an image
|
|
1273
|
+
is not rewritten, so use a test account whose address is not sensitive.
|
|
1274
|
+
|
|
1275
|
+
Your own server's analytics for the test account do not pass through the
|
|
1276
|
+
browser; send them with the playtest flag the page exposes
|
|
1277
|
+
(`window.__RAVENSIGHT_PLAYTEST__`) or leave the test account out of them.
|
|
1278
|
+
|
|
1279
|
+
`resume` of a live URL job asks for the same sign-in flags again.
|
|
1280
|
+
|
|
1199
1281
|
## Playing a Godot game
|
|
1200
1282
|
|
|
1201
1283
|
`--driver godot_driver` launches your own Godot binary against your own project,
|
package/docs/MOBILE.md
CHANGED
|
@@ -73,7 +73,7 @@ One run at a time uses a device: a run holds its device from the first check unt
|
|
|
73
73
|
|
|
74
74
|
## How a native run plays
|
|
75
75
|
|
|
76
|
-
- The game runs in real time, also while the playtester thinks. A short timer can run out before the next input arrives; a timer challenge it did not finish is not, by itself, a defect in the game.
|
|
76
|
+
- The game runs in real time, also while the playtester thinks. A short timer can run out before the next input arrives; a timer challenge it did not finish is not, by itself, a defect in the game. A finding or note that a game timer ran out, or left too little time, is moved out of the findings into a `[too_fast]` line under "What this run didn't cover", with how long the playtester took a turn, and `run` says what to add before the next run.
|
|
77
77
|
- Inputs use the coordinates of the screenshot the playtester was shown, with no crop. On Android the runner waits 700 milliseconds after an input before it captures the next screen.
|
|
78
78
|
- Taps, double taps, long presses and straight drags work on both platforms. Android text accepts printable ASCII without percent signs; iOS text goes to the focused keyboard. Pinch, held keys, drags with waypoints and pausing the game are refused as runner limits, never reported as defects in the game.
|
|
79
79
|
- Android's system Back (`key Back`) works even when the game draws no Back button; it may close a layer, go back or leave the app. iOS has no system Back through this runner, so the playtester uses the game's own buttons.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ravensight-playtest",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Local AI playtests and seeded game simulations with reports in Ravensight.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://ravensight.io/docs/playtest/",
|
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
"./api": "./src/api/index.js"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
|
-
"test": "node --test --test-reporter=spec 'src/**/!(godot-real|godot-draw.real|godot-inputs.real|godot-replay.real|godot-tester.real|web.e2e|web.containment.e2e|web.inputs.e2e|web.honesty.e2e|web.followups.e2e|web.replay.e2e|web.anygame.e2e|web.events.e2e|web.tester.e2e|scaffold.godot|template3d.godot).test.js'",
|
|
52
|
+
"test": "node --test --test-reporter=spec 'src/**/!(godot-real|godot-draw.real|godot-inputs.real|godot-replay.real|godot-tester.real|web.e2e|web.containment.e2e|web.inputs.e2e|web.honesty.e2e|web.followups.e2e|web.replay.e2e|web.anygame.e2e|web.events.e2e|web.tester.e2e|web.livesite.e2e|web.urlrun.e2e|scaffold.godot|template3d.godot).test.js'",
|
|
53
53
|
"test:godot": "node scripts/gated-test.mjs RAVENSIGHT_RECORDING_E2E some -- --test --test-concurrency=1 --test-reporter=spec src/run/drivers/godot-real.test.js src/run/drivers/godot-draw.real.test.js src/run/drivers/godot-inputs.real.test.js src/run/drivers/godot-replay.real.test.js src/run/drivers/godot-tester.real.test.js src/create/scaffold.godot.test.js src/create/template3d.godot.test.js",
|
|
54
|
-
"test:e2e": "node scripts/gated-test.mjs RAVENSIGHT_E2E all -- --test --test-reporter=spec src/run/drivers/web.e2e.test.js src/run/drivers/web.containment.e2e.test.js src/run/drivers/web.inputs.e2e.test.js src/run/drivers/web.honesty.e2e.test.js src/run/drivers/web.followups.e2e.test.js src/run/drivers/web.tester.e2e.test.js src/run/drivers/web.replay.e2e.test.js src/run/drivers/web.anygame.e2e.test.js src/run/drivers/web.events.e2e.test.js",
|
|
54
|
+
"test:e2e": "node scripts/gated-test.mjs RAVENSIGHT_E2E all -- --test --test-reporter=spec src/run/drivers/web.e2e.test.js src/run/drivers/web.containment.e2e.test.js src/run/drivers/web.inputs.e2e.test.js src/run/drivers/web.honesty.e2e.test.js src/run/drivers/web.followups.e2e.test.js src/run/drivers/web.tester.e2e.test.js src/run/drivers/web.replay.e2e.test.js src/run/drivers/web.anygame.e2e.test.js src/run/drivers/web.events.e2e.test.js src/run/drivers/web.livesite.e2e.test.js src/commands/run.urlrun.e2e.test.js",
|
|
55
55
|
"lint": "node scripts/no-dashes.mjs",
|
|
56
56
|
"audit:honesty": "node --test --test-reporter=spec src/run/honestyCorpus.test.js",
|
|
57
57
|
"test:android": "node scripts/gated-test.mjs RAVENSIGHT_ANDROID_E2E all -- --test --test-timeout=240000 --test-concurrency=1 src/run/drivers/mobile/native-real.test.js",
|
package/src/api/client.js
CHANGED
|
@@ -500,5 +500,14 @@ export function createClient(options = {}) {
|
|
|
500
500
|
runNotes: (gameId, buildSha256) => get(`${gameBase(gameId)}/memory/run-notes`, { query: { build_sha256: buildSha256 } })
|
|
501
501
|
};
|
|
502
502
|
|
|
503
|
-
|
|
503
|
+
/**
|
|
504
|
+
* Live URL playtests: whether a host is verified for the game (stored state,
|
|
505
|
+
* then a fresh DNS check), asked before a local run against a public host.
|
|
506
|
+
* Answers `{ host, verified, domainId, code }`.
|
|
507
|
+
*/
|
|
508
|
+
const url = {
|
|
509
|
+
checkDomain: (gameId, host) => get(`${gameBase(gameId)}/url/domains/check`, { query: { host } })
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
return { apiUrl, token, cliVersion, request, cli, packs, brief, jobs, runs, labs, hosted, memory, url };
|
|
504
513
|
}
|
package/src/cli.js
CHANGED
|
@@ -70,6 +70,26 @@ Run options (parsed by the runner, see src/run/args.js):
|
|
|
70
70
|
For a game made for touch; the report says when a game wanted touch and the
|
|
71
71
|
run was played with a mouse
|
|
72
72
|
--build-url <url> the web build to play
|
|
73
|
+
--url <url> playtest a live web game by its address (staging or production) on this machine. A
|
|
74
|
+
public host must be verified for the game first (a TXT record, from the Playtest page,
|
|
75
|
+
Test a live URL); localhost and private addresses are a local dev server and need none.
|
|
76
|
+
The browser reaches only that host and the game's own Ravensight analytics; other
|
|
77
|
+
hosts are blocked and listed in the report
|
|
78
|
+
--login-email <email> sign in as this test account before play, in a separate unrecorded browser; the
|
|
79
|
+
playtester never sees the form, and the email shows as "test account" on screen
|
|
80
|
+
--login-password-env <NAME>
|
|
81
|
+
the environment variable that holds the test account's password (at least 6
|
|
82
|
+
characters). A password is never taken on the command line
|
|
83
|
+
--session-cookie-env <NAME>
|
|
84
|
+
instead of a password: the environment variable holding a test user's Cookie header
|
|
85
|
+
value (name=value; name2=value2), set for the start host only
|
|
86
|
+
--session-header-env <NAME>
|
|
87
|
+
instead of a password: the environment variable holding one header, Authorization or
|
|
88
|
+
X-..., as Name: value, sent to the start host only
|
|
89
|
+
--sign-in-url <url> the page with the sign-in form, on the same host (default the --url page)
|
|
90
|
+
--sign-in-selectors <json>
|
|
91
|
+
the sign-in form's fields when they are not found on their own, as JSON with any of
|
|
92
|
+
email, password, submit and signedIn, such as {"signedIn": "text=Sign out"}
|
|
73
93
|
--build-dir <dir> a web export folder to serve from this machine and play: index.html or its one
|
|
74
94
|
.html page, with wasm, Brotli and gzip engine files and threaded builds served right
|
|
75
95
|
--build-entry <file> the page to open inside --build-dir, when it has more than one .html file
|
|
@@ -216,8 +236,12 @@ export function buildProgram() {
|
|
|
216
236
|
.option('--game <id>', 'game id, overriding this repo’s configuration')
|
|
217
237
|
.addOption(new Option('--geri-provider <name>', "Geri's model provider: primary or alternate (ravensight.io/legal/subprocessors names both); unavailable choices are refused").choices(['primary', 'alternate']))
|
|
218
238
|
.option('--video', 'include hosted gameplay video in this quote')
|
|
239
|
+
// Never a URL: a live URL reaches the cloud only as a verified target, by its id (hosted.js HOSTED_URL_REFUSAL).
|
|
240
|
+
.addOption(new Option('--url <url>').hideHelp())
|
|
241
|
+
.addOption(new Option('--build-url <url>').hideHelp())
|
|
219
242
|
.action(capture(slot, async (options, command) => {
|
|
220
|
-
const { hostedQuote } = await import('./commands/hosted.js');
|
|
243
|
+
const { hostedQuote, HOSTED_URL_REFUSAL } = await import('./commands/hosted.js');
|
|
244
|
+
if (options.url !== undefined || options.buildUrl !== undefined) throw new CliError(HOSTED_URL_REFUSAL, ExitCode.ENVIRONMENT);
|
|
221
245
|
return hostedQuote(flagsFrom(command.optsWithGlobals(), { build: options.build, profile: options.profile,
|
|
222
246
|
persona: options.persona, personas: options.personas, tier: options.tier, minutes: options.minutes, start: options.start, focus: options.focus, avoid: options.avoid, save: options.save, saveTarget: options.saveTarget, output: options.output, game: options.game,
|
|
223
247
|
geriProvider: options.geriProvider,
|
|
@@ -242,8 +266,11 @@ export function buildProgram() {
|
|
|
242
266
|
// Hidden: the server now queues a funded run instead of refusing it for
|
|
243
267
|
// capacity. Kept so an older server's busy answer can still be waited out.
|
|
244
268
|
.addOption(new Option('--wait-for-capacity [minutes]', 'when hosted capacity is busy, ask again about once a minute and start when there is room, for up to this many minutes (default 60)').hideHelp())
|
|
269
|
+
.addOption(new Option('--url <url>').hideHelp())
|
|
270
|
+
.addOption(new Option('--build-url <url>').hideHelp())
|
|
245
271
|
.action(capture(slot, async (filename, options, command) => {
|
|
246
|
-
const { hostedRun, hostedRunDirect } = await import('./commands/hosted.js');
|
|
272
|
+
const { hostedRun, hostedRunDirect, HOSTED_URL_REFUSAL } = await import('./commands/hosted.js');
|
|
273
|
+
if (options.url !== undefined || options.buildUrl !== undefined) throw new CliError(HOSTED_URL_REFUSAL, ExitCode.ENVIRONMENT);
|
|
247
274
|
if (filename) {
|
|
248
275
|
const extra = ['build', 'persona', 'personas', 'tier', 'minutes', 'start', 'save', 'saveTarget', 'game', 'video'].filter(name => options[name] !== undefined).concat(['focus', 'avoid'].filter(name => options[name]?.length));
|
|
249
276
|
if (extra.length) throw new CliError(`A saved quote already fixes its build, personas and options. Drop --${extra.join(', --')}, or run "hosted run" without a quote file.`);
|
package/src/commands/hosted.js
CHANGED
|
@@ -41,7 +41,21 @@ export function personasFrom(flags = {}) {
|
|
|
41
41
|
return hostedPersonas(named);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
* A cloud playtest plays an uploaded build or a verified live URL target, both by
|
|
46
|
+
* their id. Never a URL given here or a config's build ref: there is no
|
|
47
|
+
* unverified path to a cloud machine browsing a public host (owner, 2026-11-19).
|
|
48
|
+
*/
|
|
49
|
+
export const HOSTED_URL_REFUSAL = 'A cloud playtest plays an uploaded build or a verified live URL target, by its id (pt_build_...). '
|
|
50
|
+
+ 'To playtest a live URL in the cloud, verify its domain and add the URL as a target on the Playtest page, Test a live URL, then pass the target\'s id with --build. '
|
|
51
|
+
+ 'To play a URL on this machine instead: ravensight-playtest run --url <url>. Nothing was charged.';
|
|
52
|
+
export function assertHostedBuildId(build) {
|
|
53
|
+
if (build === undefined || build === null) return;
|
|
54
|
+
if (typeof build !== 'string' || !/^pt_build_[A-Za-z0-9-]{1,100}$/.test(build)) throw new CliError(HOSTED_URL_REFUSAL, ExitCode.ENVIRONMENT);
|
|
55
|
+
}
|
|
56
|
+
|
|
44
57
|
export async function hostedQuote(flags = {}, deps = {}) {
|
|
58
|
+
assertHostedBuildId(flags.build);
|
|
45
59
|
const context = deps.context || await createContext({ apiUrl: flags.apiUrl, repoRoot: flags.repoRoot, requireAuth: true });
|
|
46
60
|
// The same personas as "hosted run", so a quote and a run of the same build
|
|
47
61
|
// match: fresh-eyes always, plus any named.
|
|
@@ -197,6 +211,7 @@ function admittedLines(admitted, now) {
|
|
|
197
211
|
* admission. The admission keeps the saved-quote path's journal and never retries.
|
|
198
212
|
*/
|
|
199
213
|
export async function hostedRunDirect(flags = {}, deps = {}) {
|
|
214
|
+
assertHostedBuildId(flags.build);
|
|
200
215
|
if (flags.json && !flags.yes && !deps.confirm) throw new CliError('A hosted run charges prepaid funds. Use --yes with --json. Nothing was charged.');
|
|
201
216
|
const maxWaitMs = capacityWaitMs(flags.waitForCapacity);
|
|
202
217
|
const context = deps.context || await createContext({ apiUrl: flags.apiUrl, repoRoot: flags.repoRoot, requireAuth: true });
|
package/src/commands/run.js
CHANGED
|
@@ -42,6 +42,9 @@ import * as stateFile from '../run/state.js';
|
|
|
42
42
|
import { emitRunEvents } from '../run/synthetic.js';
|
|
43
43
|
import { serveBuildDir } from '../run/serveBuild.js';
|
|
44
44
|
import { stepLogSetting, stepLogUploadsLine } from '../config.js';
|
|
45
|
+
import { readLiveSite } from '../run/livesite/options.js';
|
|
46
|
+
import { domainCheckRefusal, finishLiveSiteRun, pinRefusal } from '../run/livesite/run.js';
|
|
47
|
+
import { redactingLog, redactValue } from '../run/redaction.js';
|
|
45
48
|
|
|
46
49
|
/**
|
|
47
50
|
* `ravensight-playtest run`: register a job, play it, upload it, finish it.
|
|
@@ -83,7 +86,8 @@ export const DEFAULT_CONCURRENCY = 2;
|
|
|
83
86
|
export async function runCommand(flags = {}, injected = {}) {
|
|
84
87
|
injected = { ...injected };
|
|
85
88
|
const deps = injected.deps || (await getDeps());
|
|
86
|
-
|
|
89
|
+
// A live URL run's sign-in secrets never reach a printed line (../run/redaction.js).
|
|
90
|
+
const log = redactingLog(injected.log || logger(deps));
|
|
87
91
|
try {
|
|
88
92
|
return await run(flags, injected, deps, log);
|
|
89
93
|
} catch (error) {
|
|
@@ -160,10 +164,23 @@ async function run(flags, injected, deps, log) {
|
|
|
160
164
|
return EXIT.ENVIRONMENT;
|
|
161
165
|
}
|
|
162
166
|
for (const line of unusedFlagWarnings(options)) log(line);
|
|
167
|
+
// --url and its sign-in (../run/livesite/options.js): read first, so a missing variable or a
|
|
168
|
+
// refused flag costs nothing, and the secrets are on the redaction list before any other use.
|
|
169
|
+
const live = readLiveSite(options, injected.env || process.env);
|
|
170
|
+
if (live.error) {
|
|
171
|
+
log(`${live.error} Nothing was registered or charged.`);
|
|
172
|
+
return EXIT.ENVIRONMENT;
|
|
173
|
+
}
|
|
174
|
+
if (live.liveSite) {
|
|
175
|
+
options.liveSite = live.liveSite;
|
|
176
|
+
options.buildUrl = live.liveSite.startUrl;
|
|
177
|
+
}
|
|
163
178
|
|
|
164
179
|
const setup = await resolveSetup(deps, options, log);
|
|
165
180
|
if (setup.code !== undefined) return setup.code;
|
|
166
181
|
const { context, gameId, repoRoot, apiUrl, cliVersion, api } = setup;
|
|
182
|
+
// The API this CLI talks to is a Ravensight origin too, held to the same ingest rules as ours.
|
|
183
|
+
if (options.liveSite) options.liveSite.ravensightOrigins = ravensightOrigins(apiUrl);
|
|
167
184
|
// The step log uploads unless it is turned off; everything after this reads the one answer (the job journal keeps it for a resume).
|
|
168
185
|
const stepLog = stepLogDecision(options, context.config);
|
|
169
186
|
options.uploadTranscript = stepLog.upload;
|
|
@@ -181,6 +198,20 @@ async function run(flags, injected, deps, log) {
|
|
|
181
198
|
const keyModifier = resolveKeyModifier(options.keyModifier);
|
|
182
199
|
if (keyModifier.error) { log(keyModifier.error); return EXIT.ENVIRONMENT; }
|
|
183
200
|
const driverName = options.driver || (context.config && context.config.driver) || 'playwright_web';
|
|
201
|
+
if (options.liveSite && driverName !== 'playwright_web') {
|
|
202
|
+
log(`--url plays a web page in the browser, so it uses the playwright_web driver, not ${driverName}. Nothing was registered or charged.`);
|
|
203
|
+
return EXIT.ENVIRONMENT;
|
|
204
|
+
}
|
|
205
|
+
// A public host must be verified for the game before anything is priced; a local dev server needs no check.
|
|
206
|
+
if (options.liveSite && !options.liveSite.local) {
|
|
207
|
+
const refusal = await domainCheckRefusal({ api, gameId, host: options.liveSite.startHost })
|
|
208
|
+
// Then a fresh lookup: the browser is pinned to a public address of the host and resolves nothing else.
|
|
209
|
+
|| await pinRefusal(options.liveSite, { lookup: injected.lookup });
|
|
210
|
+
if (refusal) {
|
|
211
|
+
for (const line of refusal) log(line);
|
|
212
|
+
return EXIT.ENVIRONMENT;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
184
215
|
try { options.nativePlan = nativeTarget(options, context.config, driverName, repoRoot); }
|
|
185
216
|
catch (error) { log(error.message); return EXIT.ENVIRONMENT; }
|
|
186
217
|
options.driverMode = options.nativePlan ? 'native' : 'webdriver';
|
|
@@ -257,7 +288,9 @@ async function run(flags, injected, deps, log) {
|
|
|
257
288
|
// Snowball round paid for a run against an API that was down.
|
|
258
289
|
if (!options.skipPreflight) {
|
|
259
290
|
const health = await healthPreflight({ config: context.config, driverName, target, fetchImpl: injected.fetch, log });
|
|
260
|
-
|
|
291
|
+
// A live site that signs in may answer its start page 401 or 403 until it is signed in: it is up.
|
|
292
|
+
const signedOut = options.liveSite && options.liveSite.signIn.method !== 'none' && health && [401, 403].includes(health.status);
|
|
293
|
+
if (health && !health.ok && !signedOut) {
|
|
261
294
|
log(`Preflight failed: ${health.detail}.`);
|
|
262
295
|
log('No job was registered and nothing was reserved. Start the build or its API and run this again, or pass --skip-preflight to register anyway.');
|
|
263
296
|
return EXIT.FAILED;
|
|
@@ -427,7 +460,9 @@ async function run(flags, injected, deps, log) {
|
|
|
427
460
|
recordVideo: recordingMode(options, driverName),
|
|
428
461
|
concurrency: options.concurrency ?? DEFAULT_CONCURRENCY,
|
|
429
462
|
uploadVideo: Boolean(options.uploadVideo),
|
|
430
|
-
uploadTranscript: Boolean(options.uploadTranscript)
|
|
463
|
+
uploadTranscript: Boolean(options.uploadTranscript),
|
|
464
|
+
// A live site run: where it starts and how it signs in, never a secret (resume asks for the same flags).
|
|
465
|
+
...(options.liveSite ? { liveUrl: liveSiteRecord(options.liveSite) } : {})
|
|
431
466
|
}
|
|
432
467
|
});
|
|
433
468
|
for (const entry of registered.runs || []) {
|
|
@@ -857,7 +892,7 @@ export async function playPersonaRun({
|
|
|
857
892
|
const runTarget = entry.target || target;
|
|
858
893
|
let driver;
|
|
859
894
|
try {
|
|
860
|
-
driver = await makeDriver(driverName, driverOptions({ headless, driverName, target: runTarget, directory, entry, jobId, keyModifier: options.keyModifier, godotPath: options.godotPath, realtime: options.realtime, phone: options.phone, native: options.nativePlan, mode: options.driverMode, nativeLock }));
|
|
895
|
+
driver = await makeDriver(driverName, driverOptions({ headless, driverName, target: runTarget, directory, entry, jobId, keyModifier: options.keyModifier, godotPath: options.godotPath, realtime: options.realtime, phone: options.phone, native: options.nativePlan, mode: options.driverMode, nativeLock, liveSite: options.liveSite || null }));
|
|
861
896
|
} catch (error) {
|
|
862
897
|
// A driver that cannot even be built (the browser package missing, say) is
|
|
863
898
|
// what a new machine hits first. The run is completed as failed now, with
|
|
@@ -943,7 +978,7 @@ export async function playPersonaRun({
|
|
|
943
978
|
edgePass: options.noEdgePass !== true,
|
|
944
979
|
replayFindings: options.noReplay !== true,
|
|
945
980
|
// A web run's findings are replayed in a second browser of the same kind, on the same target, with no recording.
|
|
946
|
-
...(driverName === 'playwright_web' ? { replayDriver: () => makeDriver(driverName, driverOptions({ headless, driverName, target: runTarget, directory, entry, jobId, keyModifier: options.keyModifier, godotPath: options.godotPath, realtime: options.realtime, phone: options.phone, native: options.nativePlan, mode: options.driverMode, nativeLock })) } : {}),
|
|
981
|
+
...(driverName === 'playwright_web' ? { replayDriver: () => makeDriver(driverName, driverOptions({ headless, driverName, target: runTarget, directory, entry, jobId, keyModifier: options.keyModifier, godotPath: options.godotPath, realtime: options.realtime, phone: options.phone, native: options.nativePlan, mode: options.driverMode, nativeLock, liveSite: options.liveSite || null })) } : {}),
|
|
947
982
|
// A run sold by the minute stops on the clock (../run/playClock.js).
|
|
948
983
|
playClock: playClockFor(options, entry),
|
|
949
984
|
...(options.phone === true && driverName === 'playwright_web' ? { viewport: PHONE_VIEWPORT } : {}),
|
|
@@ -973,7 +1008,10 @@ export async function playPersonaRun({
|
|
|
973
1008
|
// so the reason also says what to do about it.
|
|
974
1009
|
const failed = {
|
|
975
1010
|
...crashed,
|
|
976
|
-
|
|
1011
|
+
// A live site that did not load or sign in says so in its own words, not as a browser that could not start.
|
|
1012
|
+
quitDetail: error && error.liveSite
|
|
1013
|
+
? failureReason(error, { detail: crashed.quitDetail })
|
|
1014
|
+
: crashed.reachedState === 'launching'
|
|
977
1015
|
? driverStartReason(driverName, error, { detail: crashed.quitDetail, browserFix: BROWSER_FIX })
|
|
978
1016
|
: failureReason(error, { detail: crashed.quitDetail })
|
|
979
1017
|
};
|
|
@@ -987,8 +1025,19 @@ export async function playPersonaRun({
|
|
|
987
1025
|
...(failed.budgetWarned ? { budget_warned: true } : {}),
|
|
988
1026
|
report_written: Boolean(failed.report && !failed.report.partial)
|
|
989
1027
|
});
|
|
1028
|
+
// A live site run's report, step log and usage are scanned for its sign-in secrets before anything is sent.
|
|
1029
|
+
await finishLiveSiteRun({ directory, driver, outcome: failed, liveSite: options.liveSite || null });
|
|
990
1030
|
const delivery = {};
|
|
991
1031
|
const answer = await deliver({ deps, api, gameId, jobId, runId, directory, outcome: failed, options, log, repoRoot, delivery });
|
|
1032
|
+
// The server finishes a run that played past the proof bar and then reached
|
|
1033
|
+
// its cap, whether in play or in the report step: it stopped at its budget.
|
|
1034
|
+
// It is then a finished run here too, so the job is not told it ran out.
|
|
1035
|
+
const serverState = answer ? (answer.run ? answer.run.state : answer.state) : null;
|
|
1036
|
+
if (failed.state === 'budget_exceeded' && serverState === 'succeeded' && !delivery.reportRefused && failed.report) {
|
|
1037
|
+
await stateFile.patchRun(repoRoot, journal, runId, { uploaded: true, completed: true, state: 'succeeded' });
|
|
1038
|
+
log(`run ${runId} (${persona.slug}): ${reportBudgetMessage(answer)}`);
|
|
1039
|
+
return { runId, persona: persona.slug, state: 'succeeded', quitReason: failed.quitReason, stoppedAtBudget: true };
|
|
1040
|
+
}
|
|
992
1041
|
if (isReportStepBudget(failed)) {
|
|
993
1042
|
// The money ran out while the report was being written. The partial
|
|
994
1043
|
// report went up and the run is completed as budget_exceeded from
|
|
@@ -1038,6 +1087,8 @@ export async function playPersonaRun({
|
|
|
1038
1087
|
return { runId, persona: persona.slug, state: 'interrupted' };
|
|
1039
1088
|
}
|
|
1040
1089
|
if (inFlight) inFlight.delete(runId);
|
|
1090
|
+
// A live site run's report, step log and usage are scanned for its sign-in secrets before anything is sent.
|
|
1091
|
+
await finishLiveSiteRun({ directory, driver, outcome, liveSite: options.liveSite || null });
|
|
1041
1092
|
|
|
1042
1093
|
await stateFile.patchRun(repoRoot, journal, runId, {
|
|
1043
1094
|
state: outcome.state,
|
|
@@ -1048,7 +1099,7 @@ export async function playPersonaRun({
|
|
|
1048
1099
|
});
|
|
1049
1100
|
|
|
1050
1101
|
const delivered = {};
|
|
1051
|
-
await deliver({ deps, api, gameId, jobId, runId, directory, outcome, options, log, journal, repoRoot, delivery: delivered, extraBody: { ...validationBody(entry, outcome), ...(Number.isInteger(entry.report_scenario) ? { feature_scenario: entry.report_scenario } : {}) } });
|
|
1102
|
+
const answer = await deliver({ deps, api, gameId, jobId, runId, directory, outcome, options, log, journal, repoRoot, delivery: delivered, extraBody: { ...validationBody(entry, outcome), ...(Number.isInteger(entry.report_scenario) ? { feature_scenario: entry.report_scenario } : {}) } });
|
|
1052
1103
|
|
|
1053
1104
|
if (delivered.reportInvalid) {
|
|
1054
1105
|
// No synthetic telemetry for findings the server does not hold, and no
|
|
@@ -1073,6 +1124,15 @@ export async function playPersonaRun({
|
|
|
1073
1124
|
if (emitted.reason) log(`run ${runId}: ${emitted.reason}`);
|
|
1074
1125
|
}
|
|
1075
1126
|
|
|
1127
|
+
// Out of budget while playing, but past the proof bar with its report kept:
|
|
1128
|
+
// the server stores it finished (stopped at its budget), and so does this.
|
|
1129
|
+
const serverState = answer ? (answer.run ? answer.run.state : answer.state) : null;
|
|
1130
|
+
if (outcome.state === 'budget_exceeded' && serverState === 'succeeded' && outcome.report) {
|
|
1131
|
+
await stateFile.patchRun(repoRoot, journal, runId, { state: 'succeeded' });
|
|
1132
|
+
log(`run ${runId} (${persona.slug}): ${reportBudgetMessage(answer)}`);
|
|
1133
|
+
return { runId, persona: persona.slug, state: 'succeeded', quitReason: outcome.quitReason, stoppedAtBudget: true };
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1076
1136
|
log(`run ${runId} (${persona.slug}) ${outcome.state}: ${outcome.actionsTaken} actions, ${outcome.quitReason}.`);
|
|
1077
1137
|
return { runId, persona: persona.slug, state: outcome.state, quitReason: outcome.quitReason };
|
|
1078
1138
|
}
|
|
@@ -1188,6 +1248,8 @@ export async function deliver({ deps, api, gameId, jobId, runId, directory, outc
|
|
|
1188
1248
|
// sending it means `report_lint` is silently empty on every run, which reads
|
|
1189
1249
|
// as "the markdown is fine" rather than "nobody looked".
|
|
1190
1250
|
if (outcome.reportMarkdown) body.report_md = outcome.reportMarkdown;
|
|
1251
|
+
// A live site run's sign-in secrets never reach the API, whatever carried them this far.
|
|
1252
|
+
Object.assign(body, redactValue(body));
|
|
1191
1253
|
|
|
1192
1254
|
if (options.dryUpload) {
|
|
1193
1255
|
const listing = await listUploadable(directory, options);
|
|
@@ -1337,6 +1399,12 @@ export function reportBudgetMessage(answer) {
|
|
|
1337
1399
|
if (answer[name] !== undefined) return answer[name];
|
|
1338
1400
|
return answer.run ? answer.run[name] : undefined;
|
|
1339
1401
|
};
|
|
1402
|
+
// A run that played past the proof bar and then reached its cap is finished
|
|
1403
|
+
// on the server: it stopped at its budget, which is not running out.
|
|
1404
|
+
if (read('state') === 'succeeded') {
|
|
1405
|
+
const actions = read('actions_taken');
|
|
1406
|
+
return Number.isInteger(actions) ? `Run stopped at its budget after ${actions} actions; its report was uploaded` : 'Run stopped at its budget; its report was uploaded';
|
|
1407
|
+
}
|
|
1340
1408
|
const prefix = 'Run ran out of budget; the partial report was uploaded and';
|
|
1341
1409
|
if (read('refunded') === true) return `${prefix} the run was refunded`;
|
|
1342
1410
|
if (read('refund_expected') === true) {
|
|
@@ -1719,7 +1787,7 @@ export async function resolveSetup(deps, options, log) {
|
|
|
1719
1787
|
*
|
|
1720
1788
|
* @returns {Object}
|
|
1721
1789
|
*/
|
|
1722
|
-
export function driverOptions({ headless, driverName, target, directory, entry, jobId, keyModifier, godotPath, realtime, phone = false, native = null, mode = 'webdriver', nativeLock }) {
|
|
1790
|
+
export function driverOptions({ headless, driverName, target, directory, entry, jobId, keyModifier, godotPath, realtime, phone = false, native = null, mode = 'webdriver', nativeLock, liveSite = null }) {
|
|
1723
1791
|
// Only the browser driver sends key chords with a modifier.
|
|
1724
1792
|
const modifier = driverName === 'playwright_web' ? resolveKeyModifier(keyModifier).modifier : null;
|
|
1725
1793
|
const godot = driverName === 'godot_driver'
|
|
@@ -1736,6 +1804,8 @@ export function driverOptions({ headless, driverName, target, directory, entry,
|
|
|
1736
1804
|
...(driverName === 'playwright_web' && realtime === true ? { freezeTime: false } : {}),
|
|
1737
1805
|
// A phone sized screen played with touch (--phone).
|
|
1738
1806
|
...(driverName === 'playwright_web' && phone === true ? { touch: true } : {}),
|
|
1807
|
+
// A live URL run (../run/livesite/): its network rules, sign-in and masking.
|
|
1808
|
+
...(driverName === 'playwright_web' && liveSite ? { liveSite } : {}),
|
|
1739
1809
|
...godot,
|
|
1740
1810
|
playtest: {
|
|
1741
1811
|
token: entry.playtest_token || null,
|
|
@@ -2115,6 +2185,17 @@ export function resolveMaxActions(options, persona, pack, run = null) {
|
|
|
2115
2185
|
return candidates.length > 0 ? Math.min(...candidates) : DEFAULT_MAX_ACTIONS * factor;
|
|
2116
2186
|
}
|
|
2117
2187
|
|
|
2188
|
+
/** The Ravensight origins a live site's ingest rules cover: ours, and the API this CLI talks to. */
|
|
2189
|
+
export function ravensightOrigins(apiUrl) {
|
|
2190
|
+
try { return [new URL(apiUrl).origin]; } catch { return []; }
|
|
2191
|
+
}
|
|
2192
|
+
|
|
2193
|
+
/** What the job journal keeps of a live site: where it starts and how it signs in, never a secret. */
|
|
2194
|
+
export function liveSiteRecord(liveSite) {
|
|
2195
|
+
const { method, kind, signInUrl, selectors } = liveSite.signIn || {};
|
|
2196
|
+
return { startUrl: liveSite.startUrl, local: liveSite.local, signIn: { method: method || 'none', kind: kind || null, signInUrl: signInUrl || null, selectors: selectors || null } };
|
|
2197
|
+
}
|
|
2198
|
+
|
|
2118
2199
|
export function resolveTarget(options, config, driverName, repoRoot = null) {
|
|
2119
2200
|
const native = nativeTarget(options, config, driverName, repoRoot || process.cwd());
|
|
2120
2201
|
if (native) return native.build;
|
package/src/run/anygame/index.js
CHANGED
|
@@ -116,7 +116,7 @@ export function createLocalAnyGame({ briefText = '', controls = null, touch = fa
|
|
|
116
116
|
? '- Controls: the brief gives the controls. In your first actions inside the game itself, try each of them once, saying what you expect, so the runner has measured them; write a note only if one does not do what the brief says.'
|
|
117
117
|
: `- Controls: you do not yet know this game's controls. Read any control prompt or tutorial on screen and keep it with a "tutorial:" note. In your first actions inside the game itself, try the likely inputs one at a time, saying what you expect of each (${touch ? 'a tap, a swipe each way, a long press, a pinch' : 'the arrows, W A S D, Space, Enter, a click, a drag'}). The runner measures what each did and gives it back to you in the notebook. On a menu, or once the notebook shows the controls, just play.`);
|
|
118
118
|
lines.push(`- When the game itself is on screen, write one reaction note "kind: <one of ${KIND_IDS.join(', ')}>" (${KIND_IDS.filter(k => k !== 'unknown').map(k => `${k}: ${KINDS[k].examples}`).join('; ')}). The runner answers once with how that kind of game is best played.`);
|
|
119
|
-
if (continuousTime) lines.push('- Timing: this native driver does not pause the game between inputs or while you think. A genre label never establishes that time is stopped. Watch visible countdowns and respond promptly to timed choices; an untimed menu or turn can still be considered at your own pace.');
|
|
119
|
+
if (continuousTime) lines.push('- Timing: this native driver does not pause the game between inputs or while you think. A genre label never establishes that time is stopped. Watch visible countdowns and respond promptly to timed choices; an untimed menu or turn can still be considered at your own pace. A countdown that runs out while you are still deciding is a limit of this runner ([too_fast]), not a fault of the game: write it as a reaction note, never a bug.');
|
|
120
120
|
lines.push('- The game may be written in any language. Read its text as written and act on what it says. When the brief names something to pick, find the option on screen that means the same in the game\'s language, and say in a "choice:" note which on-screen label you took for which words of the brief.');
|
|
121
121
|
if (report.code !== 'en') lines.push(`- The brief is written in ${report.name}. Write your notes, your expectations and the prose of the report in ${report.name}, because ${report.why}. Keep the report's required section headings and its JSON keys exactly as they are given.`);
|
|
122
122
|
return lines.join('\n');
|
package/src/run/args.js
CHANGED
|
@@ -22,6 +22,15 @@ const VALUED = new Map([
|
|
|
22
22
|
['--controller', 'controller'],
|
|
23
23
|
['--compare-with', 'compareWith'],
|
|
24
24
|
['--build-url', 'buildUrl'],
|
|
25
|
+
// A live URL playtest (../livesite/options.js): the start URL, and how to sign in. Every secret
|
|
26
|
+
// comes from an environment variable whose NAME is given here, never its value.
|
|
27
|
+
['--url', 'url'],
|
|
28
|
+
['--login-email', 'loginEmail'],
|
|
29
|
+
['--login-password-env', 'loginPasswordEnv'],
|
|
30
|
+
['--session-cookie-env', 'sessionCookieEnv'],
|
|
31
|
+
['--session-header-env', 'sessionHeaderEnv'],
|
|
32
|
+
['--sign-in-url', 'signInUrl'],
|
|
33
|
+
['--sign-in-selectors', 'signInSelectors'],
|
|
25
34
|
['--build-dir', 'buildDir'],
|
|
26
35
|
// The page to open inside --build-dir when it has several .html files.
|
|
27
36
|
['--build-entry', 'buildEntry'],
|
|
@@ -115,6 +124,13 @@ export function parseRunArgv(argv = []) {
|
|
|
115
124
|
const name = split === -1 ? token : token.slice(0, split);
|
|
116
125
|
const inline = split === -1 ? null : token.slice(split + 1);
|
|
117
126
|
|
|
127
|
+
if (isPasswordFlag(name)) {
|
|
128
|
+
// Refused (see unknownOptionNotes), and its value is skipped so it is never read or echoed as another option.
|
|
129
|
+
unknown.push(name);
|
|
130
|
+
const next = argv[i + 1];
|
|
131
|
+
if (inline === null && next !== undefined && !(BOOLEAN.has(String(next)) || VALUED.has(String(next).split('=')[0]) || REPEATED.has(String(next).split('=')[0]))) i += 1;
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
118
134
|
if (BOOLEAN.has(name)) {
|
|
119
135
|
options[BOOLEAN.get(name)] = inline === null ? true : inline !== 'false';
|
|
120
136
|
continue;
|
|
@@ -152,12 +168,20 @@ export function parseRunArgv(argv = []) {
|
|
|
152
168
|
*/
|
|
153
169
|
export function unknownOptionNotes(unknown = []) {
|
|
154
170
|
const notes = [];
|
|
171
|
+
if (unknown.some(isPasswordFlag)) {
|
|
172
|
+
notes.push('A password is never taken on the command line, where the shell history and the process list keep it. Put it in an environment variable and pass the variable\'s name: --login-password-env NAME.');
|
|
173
|
+
}
|
|
155
174
|
if (unknown.includes('--budget-usd')) {
|
|
156
175
|
notes.push('--budget-usd was removed: the model budget is set by the server for each run, from what the job was charged, and enforced at the proxy.');
|
|
157
176
|
}
|
|
158
177
|
return notes;
|
|
159
178
|
}
|
|
160
179
|
|
|
180
|
+
/** A flag that looks like it carries a password, other than the one that names its environment variable. */
|
|
181
|
+
export function isPasswordFlag(name) {
|
|
182
|
+
return /password/i.test(String(name)) && String(name) !== '--login-password-env';
|
|
183
|
+
}
|
|
184
|
+
|
|
161
185
|
/**
|
|
162
186
|
* Merge the flags cli-core parsed with the ones this file parsed, flags
|
|
163
187
|
* winning, and normalise the two names for the repository root.
|
package/src/run/budgetReserve.js
CHANGED
|
@@ -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
|
|
17
|
-
* from the requests themselves (the act turn about to
|
|
18
|
-
*
|
|
19
|
-
* one unit has actually cost this run
|
|
20
|
-
* weighted tokens, ./usage.js). No price
|
|
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
|
|
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
|
};
|