vibedgames 0.6.0 → 0.6.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.
- package/dist/commands/playtest-run.d.ts +4 -0
- package/dist/commands/playtest-run.js +11 -1
- package/dist/lib/playtest/agent.d.ts +4 -0
- package/dist/lib/playtest/agent.js +55 -13
- package/dist/lib/playtest/browser.js +1 -1
- package/dist/lib/playtest/run.d.ts +2 -0
- package/dist/lib/playtest/run.js +1 -0
- package/package.json +1 -1
|
@@ -40,6 +40,10 @@ export declare const playtestRunCommand: import("citty").CommandDef<{
|
|
|
40
40
|
readonly description: "Decision model id.";
|
|
41
41
|
readonly type: "string";
|
|
42
42
|
};
|
|
43
|
+
readonly pinMove: {
|
|
44
|
+
readonly description: "Hold this one move for the whole run and never call the model — for tuning a reflex deterministically, for free. The report's decisions are then yours, not the model's.";
|
|
45
|
+
readonly type: "string";
|
|
46
|
+
};
|
|
43
47
|
readonly seed: {
|
|
44
48
|
readonly default: "12345";
|
|
45
49
|
readonly description: "Seed for the game's RNG.";
|
|
@@ -55,6 +55,10 @@ const runArgs = {
|
|
|
55
55
|
type: "string",
|
|
56
56
|
},
|
|
57
57
|
model: { default: "jev-latest", description: "Decision model id.", type: "string" },
|
|
58
|
+
pinMove: {
|
|
59
|
+
description: "Hold this one move for the whole run and never call the model — for tuning a reflex deterministically, for free. The report's decisions are then yours, not the model's.",
|
|
60
|
+
type: "string",
|
|
61
|
+
},
|
|
58
62
|
seed: { default: "12345", description: "Seed for the game's RNG.", type: "string" },
|
|
59
63
|
tickMs: {
|
|
60
64
|
default: String(DEFAULT_TICK_MS),
|
|
@@ -99,6 +103,7 @@ const settingsFrom = (args) => {
|
|
|
99
103
|
? null
|
|
100
104
|
: numberArg(args.minDisplacement, "--min-displacement", (n) => Number.isFinite(n) && n > 0, "a positive number"),
|
|
101
105
|
model: args.model,
|
|
106
|
+
pinMove: args.pinMove ?? null,
|
|
102
107
|
seed: numberArg(args.seed, "--seed", Number.isFinite, "a finite number"),
|
|
103
108
|
target: args.game ? `game:${args.game}` : (args.url ?? ""),
|
|
104
109
|
tickMs: numberArg(args.tickMs, "--tick-ms", (n) => Number.isFinite(n) && n >= 0 && n <= 5000, "between 0 and 5000 milliseconds"),
|
|
@@ -219,10 +224,15 @@ export const playtestRunCommand = defineCommand({
|
|
|
219
224
|
seed: settings.seed,
|
|
220
225
|
url: settings.url,
|
|
221
226
|
});
|
|
227
|
+
const controls = chooseControls(settings, launched.manifest);
|
|
228
|
+
if (settings.pinMove !== null && !Object.hasOwn(controls.move, settings.pinMove)) {
|
|
229
|
+
throw new HarnessError(`--pin-move ${settings.pinMove} is not a move in this scheme — those are ${Object.keys(controls.move).join(", ")}.`);
|
|
230
|
+
}
|
|
222
231
|
opts = {
|
|
223
|
-
controls
|
|
232
|
+
controls,
|
|
224
233
|
expectProgress: settings.expectProgress,
|
|
225
234
|
model: settings.model,
|
|
235
|
+
pinMove: settings.pinMove,
|
|
226
236
|
tickMs: settings.tickMs,
|
|
227
237
|
ticks: settings.ticks,
|
|
228
238
|
};
|
|
@@ -54,6 +54,8 @@ export interface AgentConfig {
|
|
|
54
54
|
decideUrl: string;
|
|
55
55
|
token: string;
|
|
56
56
|
model: string;
|
|
57
|
+
/** Hold this move for the whole run and never call the model — for tuning a reflex. */
|
|
58
|
+
pinMove: string | null;
|
|
57
59
|
goal: string;
|
|
58
60
|
move: Record<string, AgentMove>;
|
|
59
61
|
actions: Record<string, AgentAction>;
|
|
@@ -148,6 +150,8 @@ export interface ReflexInputs {
|
|
|
148
150
|
y: number;
|
|
149
151
|
down?: boolean;
|
|
150
152
|
} | null;
|
|
153
|
+
/** The reflex is trying to move and getting nowhere; see `settle`. */
|
|
154
|
+
stuck?: boolean;
|
|
151
155
|
}
|
|
152
156
|
export type Reflex = (game: Diagnostics | null) => ReflexInputs | null | undefined;
|
|
153
157
|
export interface AgentResponse {
|
|
@@ -43,6 +43,9 @@ export const browserEnv = () => {
|
|
|
43
43
|
}
|
|
44
44
|
return type === "pointerdown" ? "mousedown" : "mouseup";
|
|
45
45
|
};
|
|
46
|
+
// Relative-look games steer from `movementX/Y`, which a synthetic event
|
|
47
|
+
// leaves at 0 unless told otherwise — so each move carries its real delta.
|
|
48
|
+
let lastPointer = null;
|
|
46
49
|
const isFunction = (value) => Object.prototype.toString.call(value) === "[object Function]";
|
|
47
50
|
return {
|
|
48
51
|
caf: (id) => window.cancelAnimationFrame(id),
|
|
@@ -61,6 +64,12 @@ export const browserEnv = () => {
|
|
|
61
64
|
const cx = Math.round(window.innerWidth * pointer.x);
|
|
62
65
|
const cy = Math.round(window.innerHeight * pointer.y);
|
|
63
66
|
const pressed = type === "pointerdown" || (type === "pointermove" && pointer.down);
|
|
67
|
+
const moved = type === "pointermove" && lastPointer !== null;
|
|
68
|
+
const movementX = moved && lastPointer ? cx - lastPointer.x : 0;
|
|
69
|
+
const movementY = moved && lastPointer ? cy - lastPointer.y : 0;
|
|
70
|
+
if (type === "pointermove") {
|
|
71
|
+
lastPointer = { x: cx, y: cy };
|
|
72
|
+
}
|
|
64
73
|
const init = {
|
|
65
74
|
bubbles: true,
|
|
66
75
|
button: 0,
|
|
@@ -70,6 +79,8 @@ export const browserEnv = () => {
|
|
|
70
79
|
clientY: cy,
|
|
71
80
|
composed: true,
|
|
72
81
|
isPrimary: true,
|
|
82
|
+
movementX,
|
|
83
|
+
movementY,
|
|
73
84
|
pointerId: 1,
|
|
74
85
|
pointerType: "mouse",
|
|
75
86
|
screenX: cx,
|
|
@@ -127,12 +138,17 @@ export const inPageAgent = (config, env) => {
|
|
|
127
138
|
/** Switch the held inputs, dispatching only the changes. */
|
|
128
139
|
const hold = (next) => {
|
|
129
140
|
if (!samePointer(heldPointer, next.pointer)) {
|
|
130
|
-
|
|
141
|
+
// A button that stays down while the cursor moves is a drag: one
|
|
142
|
+
// press, moves, one release. Releasing and re-pressing per move would
|
|
143
|
+
// re-fire every click-edge verb 60 times a second under a reflex.
|
|
144
|
+
const wasDown = heldPointer?.down === true;
|
|
145
|
+
const staysDown = wasDown && next.pointer?.down === true;
|
|
146
|
+
if (heldPointer && wasDown && !staysDown) {
|
|
131
147
|
env.dispatchPointer(heldPointer, "pointerup");
|
|
132
148
|
}
|
|
133
149
|
if (next.pointer) {
|
|
134
150
|
env.dispatchPointer(next.pointer, "pointermove");
|
|
135
|
-
if (next.pointer.down) {
|
|
151
|
+
if (next.pointer.down && !staysDown) {
|
|
136
152
|
env.dispatchPointer(next.pointer, "pointerdown");
|
|
137
153
|
}
|
|
138
154
|
}
|
|
@@ -329,6 +345,19 @@ export const inPageAgent = (config, env) => {
|
|
|
329
345
|
};
|
|
330
346
|
/** One decision, with a short backoff on a rate limit, an upstream fault or a dropped connection. */
|
|
331
347
|
const decide = async (state) => {
|
|
348
|
+
if (config.pinMove !== null) {
|
|
349
|
+
// One frame, so the loop still yields to the game between decisions.
|
|
350
|
+
await env.delay(0);
|
|
351
|
+
return {
|
|
352
|
+
actionProbabilities: {},
|
|
353
|
+
actions: [],
|
|
354
|
+
confidence: null,
|
|
355
|
+
inputTokens: 0,
|
|
356
|
+
move: config.pinMove,
|
|
357
|
+
outputTokens: 0,
|
|
358
|
+
progress: null,
|
|
359
|
+
};
|
|
360
|
+
}
|
|
332
361
|
const offered = offeredMoves(state.tick.index);
|
|
333
362
|
const body = JSON.stringify({ model: config.model, questions: questions(offered), state });
|
|
334
363
|
for (let attempt = 0;; attempt += 1) {
|
|
@@ -420,15 +449,17 @@ export const inPageAgent = (config, env) => {
|
|
|
420
449
|
catch {
|
|
421
450
|
inputs = null;
|
|
422
451
|
}
|
|
423
|
-
if (!inputs) {
|
|
424
|
-
return;
|
|
425
|
-
}
|
|
426
452
|
// Actions the model chose stay held alongside whatever the reflex wants.
|
|
453
|
+
// A reflex that returns nothing (or throws) holds nothing: leaving the
|
|
454
|
+
// last frame's keys down would turn a tap into a press that never ends.
|
|
427
455
|
hold({
|
|
428
|
-
keys: withActions(keysFrom(inputs
|
|
429
|
-
pointer: pointerFrom(inputs
|
|
456
|
+
keys: withActions(keysFrom(inputs?.keys), current.decision),
|
|
457
|
+
pointer: pointerFrom(inputs?.pointer),
|
|
430
458
|
});
|
|
431
|
-
|
|
459
|
+
if (inputs) {
|
|
460
|
+
current.reflexFrames += 1;
|
|
461
|
+
current.reflexStuck ||= inputs.stuck === true;
|
|
462
|
+
}
|
|
432
463
|
};
|
|
433
464
|
const frame = () => {
|
|
434
465
|
if (stopped) {
|
|
@@ -479,10 +510,13 @@ export const inPageAgent = (config, env) => {
|
|
|
479
510
|
const settle = (done, measured) => {
|
|
480
511
|
const option = config.move[done.decision.move];
|
|
481
512
|
// Only a held direction can be "stuck". A parked pointer that has arrived
|
|
482
|
-
// and a reflex that has converged are both still because they worked
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
513
|
+
// and a reflex that has converged are both still because they worked —
|
|
514
|
+
// the agent cannot tell a reflex holding position from one wedged in
|
|
515
|
+
// geometry, so a reflex says so itself (`stuck: true`), and then its
|
|
516
|
+
// still windows count like any other.
|
|
517
|
+
const askedToMove = done.reflex
|
|
518
|
+
? done.reflexStuck
|
|
519
|
+
: option !== undefined && (option.inits.length > 0 || option.pointer?.down === true);
|
|
486
520
|
const progressed = measured.score > measured.scoreBefore;
|
|
487
521
|
let stuck = false;
|
|
488
522
|
if (askedToMove) {
|
|
@@ -568,7 +602,15 @@ export const inPageAgent = (config, env) => {
|
|
|
568
602
|
if (pending) {
|
|
569
603
|
settle(pending, measured);
|
|
570
604
|
}
|
|
571
|
-
pending = {
|
|
605
|
+
pending = {
|
|
606
|
+
appliedAt: env.now(),
|
|
607
|
+
decision,
|
|
608
|
+
decisionMs,
|
|
609
|
+
reflex,
|
|
610
|
+
reflexFrames: 0,
|
|
611
|
+
reflexStuck: false,
|
|
612
|
+
tick,
|
|
613
|
+
};
|
|
572
614
|
game = env.snapshot();
|
|
573
615
|
if (measured.complete) {
|
|
574
616
|
// The game ended under the previous decision's inputs; this one
|
|
@@ -115,7 +115,7 @@ export class GameBrowser {
|
|
|
115
115
|
}
|
|
116
116
|
/** Open the game, seed it, start a run and wait for the loop to be live. */
|
|
117
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/
|
|
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
119
|
const seedApplied = this.applySeed(seed, headed);
|
|
120
120
|
// seed() must RESTART the run — frames rendered before it were unseeded.
|
|
121
121
|
// setState('active-play') is what leaves the menu. Stash the frame it
|
|
@@ -44,6 +44,8 @@ export declare const displacementGate: (controls: Controls) => number;
|
|
|
44
44
|
export declare const ACTION_THRESHOLD = 0.5;
|
|
45
45
|
export interface RunOptions {
|
|
46
46
|
controls: Controls;
|
|
47
|
+
/** A move to hold for the whole run without calling the model, or null. */
|
|
48
|
+
pinMove: string | null;
|
|
47
49
|
expectProgress: boolean;
|
|
48
50
|
model: string;
|
|
49
51
|
tickMs: number;
|
package/dist/lib/playtest/run.js
CHANGED