vibedgames 0.6.0 → 0.6.2

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.
@@ -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: chooseControls(settings, launched.manifest),
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
  };
@@ -97,6 +97,8 @@ interface CodexRun {
97
97
  * `generated_images` store). Throws with actionable guidance when Codex
98
98
  * is missing, fails, or produces nothing.
99
99
  */
100
+ /** The `codex exec` argv for one image run. */
101
+ export declare const codexExecArgs: (workDir: string, references: string[], prompt: string) => string[];
100
102
  export declare const generateImagesWithCodex: (opts: {
101
103
  input: JsonObject;
102
104
  }) => Promise<CodexRun>;
package/dist/lib/codex.js CHANGED
@@ -179,7 +179,10 @@ export const buildCodexPrompt = (input, filenames, hasReferences) => {
179
179
  `Prompt: ${input.prompt}`,
180
180
  ];
181
181
  if (input.sizeHint) {
182
- lines.push(`Size: ${input.sizeHint}.`);
182
+ // A target, not a contract: the generator picks from a few fixed sizes, and
183
+ // asked for an exact one Codex stops to request permission to resize —
184
+ // which the no-code rule below forbids, so the run ends with no file.
185
+ lines.push(`Size: aim for ${input.sizeHint}. Use the closest size the generator offers and save that as-is — never resize, crop or ask about it.`);
183
186
  }
184
187
  lines.push(`Save the output as PNG into the current working directory using exactly ` +
185
188
  `these filenames: ${filenames.join(", ")}.`, `Do not read, create, or modify any other files, and do not write or run code. $imagegen`);
@@ -214,28 +217,29 @@ export const renderLocalTarget = (template, index, ext, requestId, count) => {
214
217
  return path.resolve(template, `codex-image-${index}.${ext}`);
215
218
  };
216
219
  const codexHome = () => process.env.CODEX_HOME ?? path.join(homedir(), ".codex");
217
- const listImages = (dir) => {
218
- let names;
220
+ /**
221
+ * Image files under `dir`, one level of subdirectories included: Codex files
222
+ * its generated images per session (`generated_images/<session>/<id>.png`),
223
+ * so a flat listing of the store never sees them.
224
+ */
225
+ const listImages = (dir, depth = 1) => {
226
+ let entries;
219
227
  try {
220
- names = readdirSync(dir);
228
+ entries = readdirSync(dir, { withFileTypes: true });
221
229
  }
222
230
  catch {
223
231
  return [];
224
232
  }
225
233
  const out = [];
226
- for (const name of names) {
227
- const ext = path.extname(name).slice(1).toLowerCase();
228
- if (!IMAGE_EXT.has(ext)) {
229
- continue;
230
- }
231
- const full = path.join(dir, name);
232
- try {
233
- if (statSync(full).isFile()) {
234
- out.push(full);
234
+ for (const entry of entries) {
235
+ const full = path.join(dir, entry.name);
236
+ if (entry.isDirectory()) {
237
+ if (depth > 0) {
238
+ out.push(...listImages(full, depth - 1));
235
239
  }
236
240
  }
237
- catch {
238
- // Raced away between readdir and stat; skip.
241
+ else if (entry.isFile() && IMAGE_EXT.has(path.extname(entry.name).slice(1).toLowerCase())) {
242
+ out.push(full);
239
243
  }
240
244
  }
241
245
  return out.toSorted();
@@ -298,6 +302,20 @@ new Promise((resolve) => {
298
302
  * `generated_images` store). Throws with actionable guidance when Codex
299
303
  * is missing, fails, or produces nothing.
300
304
  */
305
+ /** The `codex exec` argv for one image run. */
306
+ export const codexExecArgs = (workDir, references, prompt) => [
307
+ "exec",
308
+ "--skip-git-repo-check",
309
+ "-s",
310
+ "workspace-write",
311
+ "-C",
312
+ workDir,
313
+ ...references.flatMap((r) => ["-i", r]),
314
+ // `-i` is variadic (`--image <FILE>...`): without the separator it
315
+ // swallows the prompt as one more image and codex waits on stdin for one.
316
+ "--",
317
+ prompt,
318
+ ];
301
319
  export const generateImagesWithCodex = async (opts) => {
302
320
  const parsed = parseCodexInput(opts.input);
303
321
  if (!parsed.prompt) {
@@ -322,16 +340,7 @@ export const generateImagesWithCodex = async (opts) => {
322
340
  const filenames = Array.from({ length: parsed.count }, (_, i) => `output-${i}.png`);
323
341
  const prompt = buildCodexPrompt(parsed, filenames, references.length > 0);
324
342
  const bin = process.env.VG_CODEX_BIN ?? "codex";
325
- const args = [
326
- "exec",
327
- "--skip-git-repo-check",
328
- "-s",
329
- "workspace-write",
330
- "-C",
331
- workDir,
332
- ...references.flatMap((r) => ["-i", r]),
333
- prompt,
334
- ];
343
+ const args = codexExecArgs(workDir, references, prompt);
335
344
  // Snapshot Codex's default image store so we can tell which files this
336
345
  // run produced if the model saves there instead of the workspace.
337
346
  const storeDir = path.join(codexHome(), "generated_images");
@@ -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
- if (heldPointer?.down) {
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.keys), current.decision),
429
- pointer: pointerFrom(inputs.pointer),
456
+ keys: withActions(keysFrom(inputs?.keys), current.decision),
457
+ pointer: pointerFrom(inputs?.pointer),
430
458
  });
431
- current.reflexFrames += 1;
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
- const askedToMove = done.reflex === null &&
484
- option !== undefined &&
485
- (option.inits.length > 0 || option.pointer?.down === true);
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 = { appliedAt: env.now(), decision, decisionMs, reflex, reflexFrames: 0, tick };
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/model-playtest.md).");
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;
@@ -83,6 +83,7 @@ export const agentConfig = (opts, session) => {
83
83
  model: opts.model,
84
84
  motionEpsilon: motionEpsilon(opts.controls),
85
85
  move,
86
+ pinMove: opts.pinMove,
86
87
  stuckRun: THRESHOLDS.stuckRun,
87
88
  tickMs: opts.tickMs,
88
89
  ticks: opts.ticks,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vibedgames",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "private": false,
5
5
  "bin": {
6
6
  "vg": "./dist/index.js"