vibedgames 0.6.2 → 0.7.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 +14 -9
- package/dist/THIRD_PARTY_NOTICES.txt +383 -0
- package/dist/chunk-2GL2WJZX.js +172 -0
- package/dist/chunk-2QBYTIMH.js +511 -0
- package/dist/chunk-34AHIMX7.js +466 -0
- package/dist/chunk-6FZPPUQH.js +107 -0
- package/dist/chunk-BVVYDSFJ.js +99 -0
- package/dist/chunk-CAKBGDCY.js +47 -0
- package/dist/chunk-CBKOPVU6.js +1780 -0
- package/dist/chunk-CU7UY5YJ.js +1108 -0
- package/dist/chunk-CZPKN32Z.js +257 -0
- package/dist/chunk-DHEXGWJY.js +111 -0
- package/dist/chunk-FL6IFBUF.js +22 -0
- package/dist/chunk-FLUXEHMU.js +1360 -0
- package/dist/chunk-FNYBZNW2.js +165 -0
- package/dist/chunk-G5FRIFA3.js +22 -0
- package/dist/chunk-HCMTSR7E.js +69 -0
- package/dist/chunk-HKA5LBYW.js +159 -0
- package/dist/chunk-I6O4HIDY.js +1063 -0
- package/dist/chunk-J6PKNPI2.js +26 -0
- package/dist/chunk-JT2AU24K.js +759 -0
- package/dist/chunk-MBXCVCC4.js +478 -0
- package/dist/chunk-MJQSHP3Y.js +415 -0
- package/dist/chunk-MYFLYNPO.js +68 -0
- package/dist/chunk-PEUP4MZR.js +59 -0
- package/dist/chunk-PHEDW6C7.js +32 -0
- package/dist/chunk-PQDBCZRT.js +2017 -0
- package/dist/chunk-QGEITHUP.js +395 -0
- package/dist/chunk-QIVCBUYD.js +273 -0
- package/dist/chunk-RYFO3ZPO.js +71 -0
- package/dist/chunk-RZ4DIJQW.js +68 -0
- package/dist/chunk-SAANBZ25.js +118 -0
- package/dist/chunk-VFFOT7KD.js +2980 -0
- package/dist/chunk-Y552BNFZ.js +41 -0
- package/dist/chunk-Z4Z24FWO.js +39 -0
- package/dist/chunk-ZI6PKVXG.js +64 -0
- package/dist/chunk-ZYCSYJWX.js +87 -0
- package/dist/index.js +67 -60
- package/package.json +13 -16
- package/templates/none/_gitignore +3 -0
- package/templates/none/index.html +29 -0
- package/templates/none/package.json +16 -0
- package/templates/none/src/main.ts +16 -0
- package/templates/none/tsconfig.json +18 -0
- package/templates/none/vite.config.ts +8 -0
- package/templates/phaser/_gitignore +3 -0
- package/templates/phaser/index.html +24 -0
- package/templates/phaser/package.json +19 -0
- package/templates/phaser/src/main.ts +16 -0
- package/templates/phaser/src/scenes/game-scene.ts +65 -0
- package/templates/phaser/tsconfig.json +18 -0
- package/templates/phaser/vite.config.ts +8 -0
- package/templates/react-r3f/_gitignore +3 -0
- package/templates/react-r3f/index.html +24 -0
- package/templates/react-r3f/package.json +27 -0
- package/templates/react-r3f/src/app.tsx +33 -0
- package/templates/react-r3f/src/main.tsx +15 -0
- package/templates/react-r3f/tsconfig.json +19 -0
- package/templates/react-r3f/vite.config.ts +10 -0
- package/templates/threejs/_gitignore +3 -0
- package/templates/threejs/index.html +36 -0
- package/templates/threejs/package.json +20 -0
- package/templates/threejs/src/main.ts +44 -0
- package/templates/threejs/tsconfig.json +18 -0
- package/templates/threejs/vite.config.ts +8 -0
- package/dist/commands/completions.d.ts +0 -7
- package/dist/commands/completions.js +0 -145
- package/dist/commands/credits.d.ts +0 -10
- package/dist/commands/credits.js +0 -136
- package/dist/commands/deploy.d.ts +0 -26
- package/dist/commands/deploy.js +0 -257
- package/dist/commands/factory.d.ts +0 -3
- package/dist/commands/factory.js +0 -73
- package/dist/commands/fork.d.ts +0 -29
- package/dist/commands/fork.js +0 -124
- package/dist/commands/generate.d.ts +0 -1
- package/dist/commands/generate.js +0 -565
- package/dist/commands/init.d.ts +0 -20
- package/dist/commands/init.js +0 -105
- package/dist/commands/login.d.ts +0 -1
- package/dist/commands/login.js +0 -45
- package/dist/commands/logout.d.ts +0 -1
- package/dist/commands/logout.js +0 -13
- package/dist/commands/new.d.ts +0 -26
- package/dist/commands/new.js +0 -318
- package/dist/commands/playtest-run.d.ts +0 -66
- package/dist/commands/playtest-run.js +0 -268
- package/dist/commands/playtest.d.ts +0 -76
- package/dist/commands/playtest.js +0 -372
- package/dist/commands/update.d.ts +0 -13
- package/dist/commands/update.js +0 -82
- package/dist/commands/whoami.d.ts +0 -10
- package/dist/commands/whoami.js +0 -44
- package/dist/index.d.ts +0 -2
- package/dist/lib/api.d.ts +0 -18
- package/dist/lib/api.js +0 -27
- package/dist/lib/archive.d.ts +0 -17
- package/dist/lib/archive.js +0 -228
- package/dist/lib/codex.d.ts +0 -117
- package/dist/lib/codex.js +0 -426
- package/dist/lib/config-file.d.ts +0 -16
- package/dist/lib/config-file.js +0 -54
- package/dist/lib/config.d.ts +0 -11
- package/dist/lib/config.js +0 -54
- package/dist/lib/manifest.d.ts +0 -10
- package/dist/lib/manifest.js +0 -91
- package/dist/lib/media-args.d.ts +0 -30
- package/dist/lib/media-args.js +0 -219
- package/dist/lib/media-download.d.ts +0 -37
- package/dist/lib/media-download.js +0 -268
- package/dist/lib/media-poll.d.ts +0 -18
- package/dist/lib/media-poll.js +0 -86
- package/dist/lib/media-upload.d.ts +0 -12
- package/dist/lib/media-upload.js +0 -52
- package/dist/lib/output.d.ts +0 -68
- package/dist/lib/output.js +0 -102
- package/dist/lib/package-manager.d.ts +0 -25
- package/dist/lib/package-manager.js +0 -77
- package/dist/lib/playtest/agent.d.ts +0 -192
- package/dist/lib/playtest/agent.js +0 -652
- package/dist/lib/playtest/browser.d.ts +0 -109
- package/dist/lib/playtest/browser.js +0 -219
- package/dist/lib/playtest/controls.d.ts +0 -47
- package/dist/lib/playtest/controls.js +0 -218
- package/dist/lib/playtest/errors.d.ts +0 -9
- package/dist/lib/playtest/errors.js +0 -12
- package/dist/lib/playtest/keys.d.ts +0 -41
- package/dist/lib/playtest/keys.js +0 -157
- package/dist/lib/playtest/run.d.ts +0 -195
- package/dist/lib/playtest/run.js +0 -409
- package/dist/lib/run.d.ts +0 -19
- package/dist/lib/run.js +0 -23
- package/dist/lib/strict-args.d.ts +0 -27
- package/dist/lib/strict-args.js +0 -78
- package/dist/lib/types.d.ts +0 -16
- package/dist/lib/types.js +0 -10
- package/dist/lib/update.d.ts +0 -10
- package/dist/lib/update.js +0 -110
- package/dist/lib/upload.d.ts +0 -16
- package/dist/lib/upload.js +0 -41
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The playtester's browser: agent-browser, driven directly rather than through
|
|
3
|
-
* `vg playtest`. Each `vg playtest` call is a node start plus a version probe
|
|
4
|
-
* (~230 ms); the binary itself answers an eval in under 10 ms, and a playtester
|
|
5
|
-
* that decides several times a second can't afford the wrapper.
|
|
6
|
-
*
|
|
7
|
-
* The loop itself runs in the page (see agent.ts); this class boots the
|
|
8
|
-
* game, injects the agent, polls it, and reads the result back — and on an
|
|
9
|
-
* early exit tells the agent to stop, so a keydown it holds can't stay stuck
|
|
10
|
-
* in the game and poison the next run against the same daemon.
|
|
11
|
-
*/
|
|
12
|
-
import type { JsonValue } from "../types.js";
|
|
13
|
-
/** What moved during one tracked window. */
|
|
14
|
-
export interface Window {
|
|
15
|
-
path: number;
|
|
16
|
-
peak: number;
|
|
17
|
-
frameBefore: number;
|
|
18
|
-
frame: number;
|
|
19
|
-
scoreBefore: number;
|
|
20
|
-
score: number;
|
|
21
|
-
x: number;
|
|
22
|
-
y: number;
|
|
23
|
-
z: number;
|
|
24
|
-
complete: boolean;
|
|
25
|
-
}
|
|
26
|
-
/** The run's baseline, read the same way the tracker reads. */
|
|
27
|
-
export interface Sample {
|
|
28
|
-
frame: number;
|
|
29
|
-
score: number;
|
|
30
|
-
complete: boolean;
|
|
31
|
-
}
|
|
32
|
-
export interface GpuInfo {
|
|
33
|
-
renderer: string | null;
|
|
34
|
-
softwareRendered: boolean | null;
|
|
35
|
-
vendor: string | null;
|
|
36
|
-
}
|
|
37
|
-
export interface LaunchOptions {
|
|
38
|
-
url: string;
|
|
39
|
-
seed: number;
|
|
40
|
-
headed: boolean;
|
|
41
|
-
}
|
|
42
|
-
export interface Launched {
|
|
43
|
-
before: Sample;
|
|
44
|
-
seedApplied: "hook" | "boot-param";
|
|
45
|
-
/** The game's own `window.__GAME_PLAYTEST__`, if it publishes one. */
|
|
46
|
-
manifest: JsonValue | null;
|
|
47
|
-
}
|
|
48
|
-
interface CommandResult {
|
|
49
|
-
status: number;
|
|
50
|
-
stdout: string;
|
|
51
|
-
stderr: string;
|
|
52
|
-
}
|
|
53
|
-
export declare class GameBrowser {
|
|
54
|
-
private readonly bin;
|
|
55
|
-
private readonly session;
|
|
56
|
-
constructor(bin: string, session: string);
|
|
57
|
-
/** Run one agent-browser command in this session. */
|
|
58
|
-
run(args: string[]): CommandResult;
|
|
59
|
-
/**
|
|
60
|
-
* Read the payload of a `--json` command. agent-browser wraps every JSON
|
|
61
|
-
* response as `{ success, data, error }`, with the command's payload under
|
|
62
|
-
* `data` — `data.result` for `eval`, `data.messages` for `console`.
|
|
63
|
-
* Verified against agent-browser 0.34. A shape this doesn't recognize is a
|
|
64
|
-
* harness failure, not something to guess around.
|
|
65
|
-
*/
|
|
66
|
-
payload(args: string[], key: string): JsonValue;
|
|
67
|
-
evaluate(expression: string): JsonValue;
|
|
68
|
-
/**
|
|
69
|
-
* Navigate and wait for the diagnostics contract. Logs are cleared BEFORE
|
|
70
|
-
* navigating so boot errors belong to this run. Waits for the CONTRACT,
|
|
71
|
-
* not for frames: most games boot into a menu where the loop hasn't
|
|
72
|
-
* started, so frames only advance once setState('active-play') has run.
|
|
73
|
-
*/
|
|
74
|
-
private boot;
|
|
75
|
-
/**
|
|
76
|
-
* Two ways a game can honour a seed: a `seed()` hook that restarts the run,
|
|
77
|
-
* or a `?seed=` boot param for games whose scene is single-start. Calling
|
|
78
|
-
* an absent hook would leave the run unseeded while the report still
|
|
79
|
-
* claimed the seed, so detect which one this game implements.
|
|
80
|
-
*/
|
|
81
|
-
private applySeed;
|
|
82
|
-
/** Open the game, seed it, start a run and wait for the loop to be live. */
|
|
83
|
-
launch({ url, seed, headed }: LaunchOptions): Launched;
|
|
84
|
-
/** Evaluate the injected agent's source in the page. */
|
|
85
|
-
inject(source: string): void;
|
|
86
|
-
/** Whether the agent has finished, and why if it stopped early. Null if the page lost it. */
|
|
87
|
-
agentStatus(): {
|
|
88
|
-
done: boolean;
|
|
89
|
-
error: string | null;
|
|
90
|
-
} | null;
|
|
91
|
-
/** The agent's published result, as JSON. */
|
|
92
|
-
agentResult(): JsonValue;
|
|
93
|
-
/**
|
|
94
|
-
* Best-effort stop on the failure path: raw spawn, no throw. The agent
|
|
95
|
-
* releases whatever it holds and cancels its frame loop.
|
|
96
|
-
*/
|
|
97
|
-
stopAgent(): void;
|
|
98
|
-
/** Console messages at error level — `console` returns every level. */
|
|
99
|
-
consoleErrors(): string[];
|
|
100
|
-
/** Uncaught page errors. */
|
|
101
|
-
pageErrors(): JsonValue[];
|
|
102
|
-
/**
|
|
103
|
-
* Renderer string of the game's own WebGL context, so a SwiftShader run
|
|
104
|
-
* can't pass as performance evidence.
|
|
105
|
-
*/
|
|
106
|
-
gpuInfo(): GpuInfo;
|
|
107
|
-
close(): void;
|
|
108
|
-
}
|
|
109
|
-
export {};
|
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The playtester's browser: agent-browser, driven directly rather than through
|
|
3
|
-
* `vg playtest`. Each `vg playtest` call is a node start plus a version probe
|
|
4
|
-
* (~230 ms); the binary itself answers an eval in under 10 ms, and a playtester
|
|
5
|
-
* that decides several times a second can't afford the wrapper.
|
|
6
|
-
*
|
|
7
|
-
* The loop itself runs in the page (see agent.ts); this class boots the
|
|
8
|
-
* game, injects the agent, polls it, and reads the result back — and on an
|
|
9
|
-
* early exit tells the agent to stop, so a keydown it holds can't stay stuck
|
|
10
|
-
* in the game and poison the next run against the same daemon.
|
|
11
|
-
*/
|
|
12
|
-
import { spawnSync } from "node:child_process";
|
|
13
|
-
import { isJsonObject, isJsonString } from "../types.js";
|
|
14
|
-
import { HarnessError } from "./errors.js";
|
|
15
|
-
/**
|
|
16
|
-
* Read player state the same way at every sample site. All three axes,
|
|
17
|
-
* defaulting to 0, so a game whose travel is on x/z isn't read as motionless.
|
|
18
|
-
*/
|
|
19
|
-
const READ_FN = `const __botRead = () => {
|
|
20
|
-
const d = window.__GAME_DIAGNOSTICS__, p = (d && d.player) || {};
|
|
21
|
-
return { x: p.x ?? 0, y: p.y ?? 0, z: p.z ?? 0, frame: (d && d.frame) ?? 0, score: (d && d.score) ?? 0, complete: !!(d && d.complete) };
|
|
22
|
-
};
|
|
23
|
-
const __botDist = (a, b) => Math.hypot(a.x - b.x, a.y - b.y, a.z - b.z);`;
|
|
24
|
-
const CONTRACT_READY = "window.__GAME_DIAGNOSTICS__ !== undefined && window.__GAME_TEST_HOOKS__ !== undefined";
|
|
25
|
-
const num = (value) => (Number.isFinite(value) ? Number(value) : 0);
|
|
26
|
-
export class GameBrowser {
|
|
27
|
-
bin;
|
|
28
|
-
session;
|
|
29
|
-
constructor(bin, session) {
|
|
30
|
-
this.bin = bin;
|
|
31
|
-
this.session = session;
|
|
32
|
-
}
|
|
33
|
-
/** Run one agent-browser command in this session. */
|
|
34
|
-
run(args) {
|
|
35
|
-
const res = spawnSync(this.bin, ["--session", this.session, ...args], {
|
|
36
|
-
encoding: "utf-8",
|
|
37
|
-
timeout: 120_000,
|
|
38
|
-
});
|
|
39
|
-
if (res.error) {
|
|
40
|
-
throw new HarnessError(`couldn't run the playtest browser (${res.error.message}).`);
|
|
41
|
-
}
|
|
42
|
-
return { status: res.status ?? 1, stderr: res.stderr ?? "", stdout: res.stdout ?? "" };
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Read the payload of a `--json` command. agent-browser wraps every JSON
|
|
46
|
-
* response as `{ success, data, error }`, with the command's payload under
|
|
47
|
-
* `data` — `data.result` for `eval`, `data.messages` for `console`.
|
|
48
|
-
* Verified against agent-browser 0.34. A shape this doesn't recognize is a
|
|
49
|
-
* harness failure, not something to guess around.
|
|
50
|
-
*/
|
|
51
|
-
payload(args, key) {
|
|
52
|
-
const { status, stdout, stderr } = this.run([...args, "--json"]);
|
|
53
|
-
const text = stdout.trim();
|
|
54
|
-
if (status !== 0) {
|
|
55
|
-
throw new HarnessError(`\`${args[0]}\` failed: ${stderr.trim() || text}`);
|
|
56
|
-
}
|
|
57
|
-
let parsed;
|
|
58
|
-
try {
|
|
59
|
-
parsed = JSON.parse(text);
|
|
60
|
-
}
|
|
61
|
-
catch {
|
|
62
|
-
throw new HarnessError(`\`${args[0]} --json\` did not return JSON: ${text.slice(0, 200)}`);
|
|
63
|
-
}
|
|
64
|
-
if (!isJsonObject(parsed)) {
|
|
65
|
-
throw new HarnessError(`unexpected response for \`${args[0]}\`: ${text.slice(0, 200)}`);
|
|
66
|
-
}
|
|
67
|
-
if (parsed.success === false) {
|
|
68
|
-
throw new HarnessError(`\`${args[0]}\` failed: ${JSON.stringify(parsed.error)}`);
|
|
69
|
-
}
|
|
70
|
-
const { data } = parsed;
|
|
71
|
-
if (!isJsonObject(data) || !(key in data)) {
|
|
72
|
-
throw new HarnessError(`unexpected agent-browser response for \`${args[0]}\` (no data.${key}): ${text.slice(0, 200)}`);
|
|
73
|
-
}
|
|
74
|
-
return data[key] ?? null;
|
|
75
|
-
}
|
|
76
|
-
evaluate(expression) {
|
|
77
|
-
return this.payload(["eval", expression], "result");
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Navigate and wait for the diagnostics contract. Logs are cleared BEFORE
|
|
81
|
-
* navigating so boot errors belong to this run. Waits for the CONTRACT,
|
|
82
|
-
* not for frames: most games boot into a menu where the loop hasn't
|
|
83
|
-
* started, so frames only advance once setState('active-play') has run.
|
|
84
|
-
*/
|
|
85
|
-
boot(url, headed, whenAbsent) {
|
|
86
|
-
this.run(["console", "--clear"]);
|
|
87
|
-
this.run(["errors", "--clear"]);
|
|
88
|
-
const open = this.run(["open", url, ...(headed ? ["--headed"] : [])]);
|
|
89
|
-
if (open.status !== 0) {
|
|
90
|
-
throw new HarnessError(`couldn't open the game: ${open.stderr.trim() || open.stdout.trim()}`);
|
|
91
|
-
}
|
|
92
|
-
if (this.run(["wait", "--fn", CONTRACT_READY]).status !== 0) {
|
|
93
|
-
throw new HarnessError(whenAbsent);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Two ways a game can honour a seed: a `seed()` hook that restarts the run,
|
|
98
|
-
* or a `?seed=` boot param for games whose scene is single-start. Calling
|
|
99
|
-
* an absent hook would leave the run unseeded while the report still
|
|
100
|
-
* claimed the seed, so detect which one this game implements.
|
|
101
|
-
*/
|
|
102
|
-
applySeed(seed, headed) {
|
|
103
|
-
const probe = this.evaluate("({ hasSeedHook: typeof window.__GAME_TEST_HOOKS__?.seed === 'function', href: location.href })");
|
|
104
|
-
if (isJsonObject(probe) && probe.hasSeedHook === true) {
|
|
105
|
-
return "hook";
|
|
106
|
-
}
|
|
107
|
-
const href = isJsonObject(probe) ? probe.href : undefined;
|
|
108
|
-
if (!isJsonString(href)) {
|
|
109
|
-
throw new HarnessError("couldn't read location.href to apply the seed.");
|
|
110
|
-
}
|
|
111
|
-
const url = new URL(href);
|
|
112
|
-
url.searchParams.set("seed", String(seed));
|
|
113
|
-
this.boot(url.toString(), headed, "the game stopped publishing diagnostics after the seeded reload.");
|
|
114
|
-
return "boot-param";
|
|
115
|
-
}
|
|
116
|
-
/** Open the game, seed it, start a run and wait for the loop to be live. */
|
|
117
|
-
launch({ url, seed, headed }) {
|
|
118
|
-
this.boot(url, headed, "the game never published window.__GAME_DIAGNOSTICS__ / window.__GAME_TEST_HOOKS__. Either it crashed on boot, or it doesn't implement the diagnostics contract (see the playtest skill's references/autonomous-playtest.md).");
|
|
119
|
-
const seedApplied = this.applySeed(seed, headed);
|
|
120
|
-
// seed() must RESTART the run — frames rendered before it were unseeded.
|
|
121
|
-
// setState('active-play') is what leaves the menu. Stash the frame it
|
|
122
|
-
// left off at so the wait below proves the loop moved *after* the hooks.
|
|
123
|
-
const ack = this.evaluate(`(async () => { const h = window.__GAME_TEST_HOOKS__; h.seed?.(${seed}); const ack = await h.setState?.('active-play'); window.__BOT_F0__ = h && window.__GAME_DIAGNOSTICS__.frame; return ack === undefined ? null : ack; })()`);
|
|
124
|
-
// The ack is optional (void hooks keep working) but asserted when present.
|
|
125
|
-
if (ack !== null && (!isJsonObject(ack) || ack.state !== "active-play")) {
|
|
126
|
-
throw new HarnessError(`setState('active-play') acknowledged ${JSON.stringify(ack)} instead of { state: 'active-play' } — the hook applied a different state or is a no-op.`);
|
|
127
|
-
}
|
|
128
|
-
const live = this.run([
|
|
129
|
-
"wait",
|
|
130
|
-
"--fn",
|
|
131
|
-
"(window.__GAME_DIAGNOSTICS__?.frame ?? 0) > 10 && window.__GAME_DIAGNOSTICS__.frame !== window.__BOT_F0__",
|
|
132
|
-
]);
|
|
133
|
-
if (live.status !== 0) {
|
|
134
|
-
throw new HarnessError("diagnostics are published but the loop never advanced after seed()/setState('active-play') — check they aren't no-ops.");
|
|
135
|
-
}
|
|
136
|
-
const sample = this.evaluate(`(() => { ${READ_FN} return __botRead(); })()`);
|
|
137
|
-
const before = isJsonObject(sample)
|
|
138
|
-
? { complete: sample.complete === true, frame: num(sample.frame), score: num(sample.score) }
|
|
139
|
-
: { complete: false, frame: 0, score: 0 };
|
|
140
|
-
// A reflex is a function and JSON drops it, which would make a move that
|
|
141
|
-
// is nothing BUT a reflex look like one that holds no input. Keep the fact.
|
|
142
|
-
const manifest = this.evaluate("(() => { try { return JSON.parse(JSON.stringify(window.__GAME_PLAYTEST__ ?? null, (key, value) => (key === 'reflex' && typeof value === 'function' ? true : value))); } catch { return null; } })()");
|
|
143
|
-
return { before, manifest, seedApplied };
|
|
144
|
-
}
|
|
145
|
-
/** Evaluate the injected agent's source in the page. */
|
|
146
|
-
inject(source) {
|
|
147
|
-
this.evaluate(source);
|
|
148
|
-
}
|
|
149
|
-
/** Whether the agent has finished, and why if it stopped early. Null if the page lost it. */
|
|
150
|
-
agentStatus() {
|
|
151
|
-
const status = this.evaluate("(() => { const a = window.__PLAYTEST_AGENT__; return a ? { done: a.done === true, error: a.error ?? null } : null; })()");
|
|
152
|
-
if (!isJsonObject(status)) {
|
|
153
|
-
return null;
|
|
154
|
-
}
|
|
155
|
-
return { done: status.done === true, error: isJsonString(status.error) ? status.error : null };
|
|
156
|
-
}
|
|
157
|
-
/** The agent's published result, as JSON. */
|
|
158
|
-
agentResult() {
|
|
159
|
-
return this.evaluate("(() => { try { return JSON.parse(JSON.stringify(window.__PLAYTEST_AGENT__ ?? null)); } catch { return null; } })()");
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Best-effort stop on the failure path: raw spawn, no throw. The agent
|
|
163
|
-
* releases whatever it holds and cancels its frame loop.
|
|
164
|
-
*/
|
|
165
|
-
stopAgent() {
|
|
166
|
-
spawnSync(this.bin, [
|
|
167
|
-
"--session",
|
|
168
|
-
this.session,
|
|
169
|
-
"eval",
|
|
170
|
-
"(() => { window.__PLAYTEST_AGENT__?.stop?.(); return true; })()",
|
|
171
|
-
], { encoding: "utf-8", timeout: 30_000 });
|
|
172
|
-
}
|
|
173
|
-
/** Console messages at error level — `console` returns every level. */
|
|
174
|
-
consoleErrors() {
|
|
175
|
-
const entries = this.payload(["console"], "messages");
|
|
176
|
-
if (!Array.isArray(entries)) {
|
|
177
|
-
throw new HarnessError("`console` returned a non-array `messages`.");
|
|
178
|
-
}
|
|
179
|
-
return entries
|
|
180
|
-
.filter((entry) => isJsonObject(entry) && entry.type === "error")
|
|
181
|
-
.map((entry) => isJsonObject(entry) && isJsonString(entry.text) ? entry.text : JSON.stringify(entry));
|
|
182
|
-
}
|
|
183
|
-
/** Uncaught page errors. */
|
|
184
|
-
pageErrors() {
|
|
185
|
-
const errors = this.payload(["errors"], "errors");
|
|
186
|
-
if (!Array.isArray(errors)) {
|
|
187
|
-
throw new HarnessError("`errors` returned a non-array `errors`.");
|
|
188
|
-
}
|
|
189
|
-
return errors;
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Renderer string of the game's own WebGL context, so a SwiftShader run
|
|
193
|
-
* can't pass as performance evidence.
|
|
194
|
-
*/
|
|
195
|
-
gpuInfo() {
|
|
196
|
-
const info = this.evaluate(`(() => {
|
|
197
|
-
const canvas = document.querySelector("canvas");
|
|
198
|
-
let gl = null;
|
|
199
|
-
try { gl = canvas?.getContext("webgl2") ?? canvas?.getContext("webgl") ?? null; } catch { gl = null; }
|
|
200
|
-
if (!gl) { return null; }
|
|
201
|
-
const debug = gl.getExtension("WEBGL_debug_renderer_info");
|
|
202
|
-
return {
|
|
203
|
-
renderer: debug ? gl.getParameter(debug.UNMASKED_RENDERER_WEBGL) : gl.getParameter(gl.RENDERER),
|
|
204
|
-
vendor: debug ? gl.getParameter(debug.UNMASKED_VENDOR_WEBGL) : gl.getParameter(gl.VENDOR),
|
|
205
|
-
};
|
|
206
|
-
})()`);
|
|
207
|
-
if (!isJsonObject(info) || !isJsonString(info.renderer)) {
|
|
208
|
-
return { renderer: null, softwareRendered: null, vendor: null };
|
|
209
|
-
}
|
|
210
|
-
return {
|
|
211
|
-
renderer: info.renderer,
|
|
212
|
-
softwareRendered: /swiftshader|llvmpipe|software|basic render/iu.test(info.renderer),
|
|
213
|
-
vendor: isJsonString(info.vendor) ? info.vendor : null,
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
close() {
|
|
217
|
-
this.run(["close"]);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* What the playtester can do to a game, and the questions that turn that into a
|
|
3
|
-
* decision. A control scheme is a `move` choice (one option held per tick)
|
|
4
|
-
* plus independent yes/no `actions`, each described in prose — the
|
|
5
|
-
* descriptions are literally the model's criteria, so they carry the game's
|
|
6
|
-
* meaning ("run right, towards the flag"), not just the key name.
|
|
7
|
-
*
|
|
8
|
-
* Schemes come from three places, in precedence order: an explicit
|
|
9
|
-
* `--controls` (preset name or JSON file), the game's own
|
|
10
|
-
* `window.__GAME_PLAYTEST__` manifest, and the `wasd` preset.
|
|
11
|
-
*/
|
|
12
|
-
import type { JsonValue } from "../types.js";
|
|
13
|
-
import type { Pointer } from "./keys.js";
|
|
14
|
-
export interface MoveOption {
|
|
15
|
-
description: string;
|
|
16
|
-
keys: string[];
|
|
17
|
-
pointer: Pointer | null;
|
|
18
|
-
/** The game's manifest carries a per-frame `reflex` for this move (it lives in the page, not here). */
|
|
19
|
-
reflex: boolean;
|
|
20
|
-
}
|
|
21
|
-
export interface ActionOption {
|
|
22
|
-
description: string;
|
|
23
|
-
keys: string[];
|
|
24
|
-
}
|
|
25
|
-
export interface Controls {
|
|
26
|
-
goal: string;
|
|
27
|
-
move: Record<string, MoveOption>;
|
|
28
|
-
actions: Record<string, ActionOption>;
|
|
29
|
-
/**
|
|
30
|
-
* The per-decision movement that proves input reaches the player, in the
|
|
31
|
-
* units of `player.x/y/z`. Null = the pixel-scale default; a game that
|
|
32
|
-
* measures in world units (most 3D games) moves a fraction of that.
|
|
33
|
-
*/
|
|
34
|
-
minDisplacement: number | null;
|
|
35
|
-
}
|
|
36
|
-
export declare const DEFAULT_GOAL = "Play the game well: stay alive, keep moving through the level, raise the score, and avoid whatever the state marks as hazards, enemies or damage.";
|
|
37
|
-
export declare const PRESETS: Map<string, Controls>;
|
|
38
|
-
export declare const DEFAULT_PRESET = "wasd";
|
|
39
|
-
export declare const PRESET_NAMES: string[];
|
|
40
|
-
/**
|
|
41
|
-
* Validate a scheme from JSON (a `--controls` file or the game's
|
|
42
|
-
* `__GAME_PLAYTEST__`). `source` names where it came from in every error, so a
|
|
43
|
-
* game author knows which manifest to fix.
|
|
44
|
-
*/
|
|
45
|
-
export declare const parseControls: (raw: JsonValue, source: string) => Controls;
|
|
46
|
-
/** Resolve `--controls`: a preset name, or a JSON file. */
|
|
47
|
-
export declare const readControlsArg: (value: string) => Controls;
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* What the playtester can do to a game, and the questions that turn that into a
|
|
3
|
-
* decision. A control scheme is a `move` choice (one option held per tick)
|
|
4
|
-
* plus independent yes/no `actions`, each described in prose — the
|
|
5
|
-
* descriptions are literally the model's criteria, so they carry the game's
|
|
6
|
-
* meaning ("run right, towards the flag"), not just the key name.
|
|
7
|
-
*
|
|
8
|
-
* Schemes come from three places, in precedence order: an explicit
|
|
9
|
-
* `--controls` (preset name or JSON file), the game's own
|
|
10
|
-
* `window.__GAME_PLAYTEST__` manifest, and the `wasd` preset.
|
|
11
|
-
*/
|
|
12
|
-
import { readFileSync } from "node:fs";
|
|
13
|
-
import { isJsonObject, isJsonString } from "../types.js";
|
|
14
|
-
import { HarnessError } from "./errors.js";
|
|
15
|
-
import { keyFields } from "./keys.js";
|
|
16
|
-
export const DEFAULT_GOAL = "Play the game well: stay alive, keep moving through the level, raise the score, and avoid whatever the state marks as hazards, enemies or damage.";
|
|
17
|
-
const NONE = {
|
|
18
|
-
description: "Hold no movement input — stay still",
|
|
19
|
-
keys: [],
|
|
20
|
-
pointer: null,
|
|
21
|
-
reflex: false,
|
|
22
|
-
};
|
|
23
|
-
const move = (description, keys) => ({
|
|
24
|
-
description,
|
|
25
|
-
keys,
|
|
26
|
-
pointer: null,
|
|
27
|
-
reflex: false,
|
|
28
|
-
});
|
|
29
|
-
const directions = (up, down, left, right) => ({
|
|
30
|
-
down: move("Move down / backward", [down]),
|
|
31
|
-
down_left: move("Move diagonally down and left", [down, left]),
|
|
32
|
-
down_right: move("Move diagonally down and right", [down, right]),
|
|
33
|
-
left: move("Move left", [left]),
|
|
34
|
-
none: NONE,
|
|
35
|
-
right: move("Move right", [right]),
|
|
36
|
-
up: move("Move up / forward", [up]),
|
|
37
|
-
up_left: move("Move diagonally up and left", [up, left]),
|
|
38
|
-
up_right: move("Move diagonally up and right", [up, right]),
|
|
39
|
-
});
|
|
40
|
-
const ACTION_PRESET = {
|
|
41
|
-
action: { description: "press the action key (jump, fire or confirm)", keys: ["Space"] },
|
|
42
|
-
};
|
|
43
|
-
export const PRESETS = new Map([
|
|
44
|
-
[
|
|
45
|
-
"arrows",
|
|
46
|
-
{
|
|
47
|
-
actions: ACTION_PRESET,
|
|
48
|
-
goal: DEFAULT_GOAL,
|
|
49
|
-
minDisplacement: null,
|
|
50
|
-
move: directions("ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"),
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
|
-
[
|
|
54
|
-
"wasd",
|
|
55
|
-
{
|
|
56
|
-
actions: ACTION_PRESET,
|
|
57
|
-
goal: DEFAULT_GOAL,
|
|
58
|
-
minDisplacement: null,
|
|
59
|
-
move: directions("KeyW", "KeyS", "KeyA", "KeyD"),
|
|
60
|
-
},
|
|
61
|
-
],
|
|
62
|
-
]);
|
|
63
|
-
export const DEFAULT_PRESET = "wasd";
|
|
64
|
-
export const PRESET_NAMES = [...PRESETS.keys()];
|
|
65
|
-
// Annotated on the identifier, not just the arrow: TypeScript only narrows
|
|
66
|
-
// after a never-returning call when the callee's declared type says so.
|
|
67
|
-
const fail = (message) => {
|
|
68
|
-
throw new HarnessError(message);
|
|
69
|
-
};
|
|
70
|
-
const nonEmptyString = (value) => isJsonString(value) && value.trim() !== "";
|
|
71
|
-
const readKeys = (value, where) => {
|
|
72
|
-
if (value === undefined) {
|
|
73
|
-
return [];
|
|
74
|
-
}
|
|
75
|
-
if (!Array.isArray(value) || !value.every(isJsonString)) {
|
|
76
|
-
fail(`${where}: \`keys\` must be an array of KeyboardEvent codes.`);
|
|
77
|
-
}
|
|
78
|
-
for (const code of value) {
|
|
79
|
-
try {
|
|
80
|
-
keyFields(code);
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
// Re-thrown with the scheme's address, so the author knows which
|
|
84
|
-
// manifest to fix, not just which code was wrong.
|
|
85
|
-
fail(`${where}: ${error instanceof Error ? error.message : String(error)}`);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return value;
|
|
89
|
-
};
|
|
90
|
-
/**
|
|
91
|
-
* Check a `pointer` before anything launches. Fractions of the viewport, so a
|
|
92
|
-
* scheme isn't tied to one window size; pixels are the tempting mistake, and
|
|
93
|
-
* they'd silently aim off-screen.
|
|
94
|
-
*/
|
|
95
|
-
const readPointer = (value, where) => {
|
|
96
|
-
if (value === undefined) {
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
if (!isJsonObject(value)) {
|
|
100
|
-
fail(`${where}: \`pointer\` must be an object { x, y, down? }.`);
|
|
101
|
-
}
|
|
102
|
-
const { x, y, down } = value;
|
|
103
|
-
for (const [name, axis] of [
|
|
104
|
-
["x", x],
|
|
105
|
-
["y", y],
|
|
106
|
-
]) {
|
|
107
|
-
if (!Number.isFinite(axis) || Number(axis) < 0 || Number(axis) > 1) {
|
|
108
|
-
fail(`${where}: \`pointer.${name}\` must be a viewport fraction between 0 and 1.`);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
if (down !== undefined && down !== true && down !== false) {
|
|
112
|
-
fail(`${where}: \`pointer.down\` must be a boolean.`);
|
|
113
|
-
}
|
|
114
|
-
return { down: down === true, x: Number(x), y: Number(y) };
|
|
115
|
-
};
|
|
116
|
-
const readDescription = (option, where) => {
|
|
117
|
-
if (!nonEmptyString(option.description)) {
|
|
118
|
-
fail(`${where} needs a non-empty \`description\` — that is what the model decides from.`);
|
|
119
|
-
}
|
|
120
|
-
return option.description;
|
|
121
|
-
};
|
|
122
|
-
const readMoveOption = (value, where) => {
|
|
123
|
-
if (!isJsonObject(value)) {
|
|
124
|
-
fail(`${where} must be an object with a \`description\`.`);
|
|
125
|
-
}
|
|
126
|
-
return {
|
|
127
|
-
description: readDescription(value, where),
|
|
128
|
-
keys: readKeys(value.keys, where),
|
|
129
|
-
pointer: readPointer(value.pointer, where),
|
|
130
|
-
reflex: value.reflex === true,
|
|
131
|
-
};
|
|
132
|
-
};
|
|
133
|
-
const readActionOption = (value, where) => {
|
|
134
|
-
if (!isJsonObject(value)) {
|
|
135
|
-
fail(`${where} must be an object with a \`description\`.`);
|
|
136
|
-
}
|
|
137
|
-
if (value.pointer !== undefined) {
|
|
138
|
-
fail(`${where}: actions are keys only. A pointer belongs in a \`move\` option (aim-and-thrust games put \`down: true\` there).`);
|
|
139
|
-
}
|
|
140
|
-
const keys = readKeys(value.keys, where);
|
|
141
|
-
if (keys.length === 0) {
|
|
142
|
-
fail(`${where} needs a non-empty \`keys\` array.`);
|
|
143
|
-
}
|
|
144
|
-
return { description: readDescription(value, where), keys };
|
|
145
|
-
};
|
|
146
|
-
/**
|
|
147
|
-
* Validate a scheme from JSON (a `--controls` file or the game's
|
|
148
|
-
* `__GAME_PLAYTEST__`). `source` names where it came from in every error, so a
|
|
149
|
-
* game author knows which manifest to fix.
|
|
150
|
-
*/
|
|
151
|
-
export const parseControls = (raw, source) => {
|
|
152
|
-
if (!isJsonObject(raw)) {
|
|
153
|
-
fail(`${source} must be a JSON object with \`move\` (and optionally \`actions\`, \`goal\`).`);
|
|
154
|
-
}
|
|
155
|
-
if (raw.goal !== undefined && !nonEmptyString(raw.goal)) {
|
|
156
|
-
fail(`${source}: \`goal\` must be a non-empty string.`);
|
|
157
|
-
}
|
|
158
|
-
if (!isJsonObject(raw.move) || Object.keys(raw.move).length === 0) {
|
|
159
|
-
fail(`${source}: \`move\` must map at least one option label to { description, keys | pointer }.`);
|
|
160
|
-
}
|
|
161
|
-
const moves = {};
|
|
162
|
-
for (const [label, option] of Object.entries(raw.move)) {
|
|
163
|
-
moves[label] = readMoveOption(option, `${source} move.${label}`);
|
|
164
|
-
}
|
|
165
|
-
if (!Object.values(moves).some((option) => option.keys.length > 0 || option.pointer || option.reflex)) {
|
|
166
|
-
fail(`${source}: no \`move\` option holds any input, so the playtester could never move.`);
|
|
167
|
-
}
|
|
168
|
-
// A choice needs two options, so a one-move scheme gets a no-input partner.
|
|
169
|
-
// Never otherwise: given a state that points nowhere the model takes "hold
|
|
170
|
-
// nothing" at high confidence, so an unasked-for `none` freezes the run and
|
|
171
|
-
// hides how little the diagnostics said. A game where waiting is a real
|
|
172
|
-
// play declares its own.
|
|
173
|
-
if (Object.keys(moves).length < 2 && !Object.hasOwn(moves, "none")) {
|
|
174
|
-
moves.none = NONE;
|
|
175
|
-
}
|
|
176
|
-
const actions = {};
|
|
177
|
-
if (raw.actions !== undefined) {
|
|
178
|
-
if (!isJsonObject(raw.actions)) {
|
|
179
|
-
fail(`${source}: \`actions\` must map option labels to { description, keys }.`);
|
|
180
|
-
}
|
|
181
|
-
for (const [label, option] of Object.entries(raw.actions)) {
|
|
182
|
-
actions[label] = readActionOption(option, `${source} actions.${label}`);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
const { minDisplacement } = raw;
|
|
186
|
-
if (minDisplacement !== undefined &&
|
|
187
|
-
(!Number.isFinite(minDisplacement) || Number(minDisplacement) <= 0)) {
|
|
188
|
-
fail(`${source}: \`minDisplacement\` must be a positive number, in the units of player.x/y.`);
|
|
189
|
-
}
|
|
190
|
-
return {
|
|
191
|
-
actions,
|
|
192
|
-
goal: nonEmptyString(raw.goal) ? raw.goal : DEFAULT_GOAL,
|
|
193
|
-
minDisplacement: minDisplacement === undefined ? null : Number(minDisplacement),
|
|
194
|
-
move: moves,
|
|
195
|
-
};
|
|
196
|
-
};
|
|
197
|
-
/** Resolve `--controls`: a preset name, or a JSON file. */
|
|
198
|
-
export const readControlsArg = (value) => {
|
|
199
|
-
const preset = PRESETS.get(value);
|
|
200
|
-
if (preset) {
|
|
201
|
-
return preset;
|
|
202
|
-
}
|
|
203
|
-
let text;
|
|
204
|
-
try {
|
|
205
|
-
text = readFileSync(value, "utf-8");
|
|
206
|
-
}
|
|
207
|
-
catch {
|
|
208
|
-
fail(`couldn't read --controls ${value} (not a preset — those are ${PRESET_NAMES.join(", ")} — and not a readable file).`);
|
|
209
|
-
}
|
|
210
|
-
let raw;
|
|
211
|
-
try {
|
|
212
|
-
raw = JSON.parse(text);
|
|
213
|
-
}
|
|
214
|
-
catch (error) {
|
|
215
|
-
fail(`--controls ${value} isn't valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
216
|
-
}
|
|
217
|
-
return parseControls(raw, `--controls ${value}`);
|
|
218
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A failure of the playtest harness itself — bad flags, a browser that won't
|
|
3
|
-
* start, a game that never published its contract, a model that can't be
|
|
4
|
-
* reached — as opposed to a game that fails its playtest. `vg playtest run` exits 2
|
|
5
|
-
* on these and 1 on a failed playtest, so an agent can tell them apart.
|
|
6
|
-
*/
|
|
7
|
-
export declare class HarnessError extends Error {
|
|
8
|
-
constructor(message: string);
|
|
9
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A failure of the playtest harness itself — bad flags, a browser that won't
|
|
3
|
-
* start, a game that never published its contract, a model that can't be
|
|
4
|
-
* reached — as opposed to a game that fails its playtest. `vg playtest run` exits 2
|
|
5
|
-
* on these and 1 on a failed playtest, so an agent can tell them apart.
|
|
6
|
-
*/
|
|
7
|
-
export class HarnessError extends Error {
|
|
8
|
-
constructor(message) {
|
|
9
|
-
super(message);
|
|
10
|
-
this.name = "HarnessError";
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Properly-formed held input for a game page: KeyboardEvent inits that carry
|
|
3
|
-
* `code`, `key` and `keyCode`, built here and dispatched by the in-page agent.
|
|
4
|
-
* A port of the playtest skill's `scripts/lib/harness.mjs`, which the
|
|
5
|
-
* scripted bot still uses; the two must agree on what a key looks like.
|
|
6
|
-
*
|
|
7
|
-
* NOT agent-browser's `keydown`/`keyup`: as of 0.34 those dispatch an event
|
|
8
|
-
* with an empty `code` and `keyCode: 0`, which engines that match on keyCode
|
|
9
|
-
* (Phaser among them) silently ignore. `press` populates the event correctly
|
|
10
|
-
* but is a discrete tap, so it can't express a hold. Dispatching the event
|
|
11
|
-
* ourselves is the only way to hold a properly-formed key. The tradeoff is
|
|
12
|
-
* `isTrusted: false`, which matters only for games that check it.
|
|
13
|
-
*/
|
|
14
|
-
export declare const SUPPORTED_KEYS_HINT: string;
|
|
15
|
-
/** `keyCode` and `key` for a KeyboardEvent `code`. Throws naming an unsupported code. */
|
|
16
|
-
export declare const keyFields: (code: string) => [keyCode: number, key: string];
|
|
17
|
-
/** A properly-formed KeyboardEventInit for `code`, with modifier flags. */
|
|
18
|
-
export interface KeyInit {
|
|
19
|
-
code: string;
|
|
20
|
-
key: string;
|
|
21
|
-
keyCode: number;
|
|
22
|
-
which: number;
|
|
23
|
-
altKey: boolean;
|
|
24
|
-
ctrlKey: boolean;
|
|
25
|
-
shiftKey: boolean;
|
|
26
|
-
bubbles: true;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Inits for a set of keys held together. Modifiers held in the same set show
|
|
30
|
-
* up as flags on their companions too, or `Shift+W` arrives as a plain `w`
|
|
31
|
-
* and the binding a scheme was written to exercise never fires.
|
|
32
|
-
*/
|
|
33
|
-
export declare const keyInitsFor: (codes: string[]) => KeyInit[];
|
|
34
|
-
/** Every supported code, each as if pressed alone — for inputs a reflex returns by code. */
|
|
35
|
-
export declare const keyTable: () => Record<string, KeyInit>;
|
|
36
|
-
/** A cursor position in viewport fractions, optionally with the primary button down. */
|
|
37
|
-
export interface Pointer {
|
|
38
|
-
x: number;
|
|
39
|
-
y: number;
|
|
40
|
-
down?: boolean;
|
|
41
|
-
}
|