vibedgames 0.6.3 → 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.
Files changed (140) hide show
  1. package/README.md +14 -9
  2. package/dist/THIRD_PARTY_NOTICES.txt +383 -0
  3. package/dist/chunk-2GL2WJZX.js +172 -0
  4. package/dist/chunk-2QBYTIMH.js +511 -0
  5. package/dist/chunk-34AHIMX7.js +466 -0
  6. package/dist/chunk-6FZPPUQH.js +107 -0
  7. package/dist/chunk-BVVYDSFJ.js +99 -0
  8. package/dist/chunk-CAKBGDCY.js +47 -0
  9. package/dist/chunk-CBKOPVU6.js +1780 -0
  10. package/dist/chunk-CU7UY5YJ.js +1108 -0
  11. package/dist/chunk-CZPKN32Z.js +257 -0
  12. package/dist/chunk-DHEXGWJY.js +111 -0
  13. package/dist/chunk-FL6IFBUF.js +22 -0
  14. package/dist/chunk-FLUXEHMU.js +1360 -0
  15. package/dist/chunk-FNYBZNW2.js +165 -0
  16. package/dist/chunk-G5FRIFA3.js +22 -0
  17. package/dist/chunk-HCMTSR7E.js +69 -0
  18. package/dist/chunk-HKA5LBYW.js +159 -0
  19. package/dist/chunk-I6O4HIDY.js +1063 -0
  20. package/dist/chunk-J6PKNPI2.js +26 -0
  21. package/dist/chunk-JT2AU24K.js +759 -0
  22. package/dist/chunk-MBXCVCC4.js +478 -0
  23. package/dist/chunk-MJQSHP3Y.js +415 -0
  24. package/dist/chunk-MYFLYNPO.js +68 -0
  25. package/dist/chunk-PEUP4MZR.js +59 -0
  26. package/dist/chunk-PHEDW6C7.js +32 -0
  27. package/dist/chunk-PQDBCZRT.js +2017 -0
  28. package/dist/chunk-QGEITHUP.js +395 -0
  29. package/dist/chunk-QIVCBUYD.js +273 -0
  30. package/dist/chunk-RYFO3ZPO.js +71 -0
  31. package/dist/chunk-RZ4DIJQW.js +68 -0
  32. package/dist/chunk-SAANBZ25.js +118 -0
  33. package/dist/chunk-VFFOT7KD.js +2980 -0
  34. package/dist/chunk-Y552BNFZ.js +41 -0
  35. package/dist/chunk-Z4Z24FWO.js +39 -0
  36. package/dist/chunk-ZI6PKVXG.js +64 -0
  37. package/dist/chunk-ZYCSYJWX.js +87 -0
  38. package/dist/index.js +67 -60
  39. package/package.json +13 -16
  40. package/templates/none/_gitignore +3 -0
  41. package/templates/none/index.html +29 -0
  42. package/templates/none/package.json +16 -0
  43. package/templates/none/src/main.ts +16 -0
  44. package/templates/none/tsconfig.json +18 -0
  45. package/templates/none/vite.config.ts +8 -0
  46. package/templates/phaser/_gitignore +3 -0
  47. package/templates/phaser/index.html +24 -0
  48. package/templates/phaser/package.json +19 -0
  49. package/templates/phaser/src/main.ts +16 -0
  50. package/templates/phaser/src/scenes/game-scene.ts +65 -0
  51. package/templates/phaser/tsconfig.json +18 -0
  52. package/templates/phaser/vite.config.ts +8 -0
  53. package/templates/react-r3f/_gitignore +3 -0
  54. package/templates/react-r3f/index.html +24 -0
  55. package/templates/react-r3f/package.json +27 -0
  56. package/templates/react-r3f/src/app.tsx +33 -0
  57. package/templates/react-r3f/src/main.tsx +15 -0
  58. package/templates/react-r3f/tsconfig.json +19 -0
  59. package/templates/react-r3f/vite.config.ts +10 -0
  60. package/templates/threejs/_gitignore +3 -0
  61. package/templates/threejs/index.html +36 -0
  62. package/templates/threejs/package.json +20 -0
  63. package/templates/threejs/src/main.ts +44 -0
  64. package/templates/threejs/tsconfig.json +18 -0
  65. package/templates/threejs/vite.config.ts +8 -0
  66. package/dist/commands/completions.d.ts +0 -7
  67. package/dist/commands/completions.js +0 -145
  68. package/dist/commands/credits.d.ts +0 -10
  69. package/dist/commands/credits.js +0 -136
  70. package/dist/commands/deploy.d.ts +0 -26
  71. package/dist/commands/deploy.js +0 -257
  72. package/dist/commands/factory.d.ts +0 -3
  73. package/dist/commands/factory.js +0 -73
  74. package/dist/commands/fork.d.ts +0 -29
  75. package/dist/commands/fork.js +0 -124
  76. package/dist/commands/generate.d.ts +0 -1
  77. package/dist/commands/generate.js +0 -565
  78. package/dist/commands/init.d.ts +0 -20
  79. package/dist/commands/init.js +0 -105
  80. package/dist/commands/login.d.ts +0 -1
  81. package/dist/commands/login.js +0 -45
  82. package/dist/commands/logout.d.ts +0 -1
  83. package/dist/commands/logout.js +0 -13
  84. package/dist/commands/new.d.ts +0 -26
  85. package/dist/commands/new.js +0 -318
  86. package/dist/commands/playtest-run.d.ts +0 -66
  87. package/dist/commands/playtest-run.js +0 -268
  88. package/dist/commands/playtest.d.ts +0 -76
  89. package/dist/commands/playtest.js +0 -372
  90. package/dist/commands/update.d.ts +0 -13
  91. package/dist/commands/update.js +0 -82
  92. package/dist/commands/whoami.d.ts +0 -10
  93. package/dist/commands/whoami.js +0 -44
  94. package/dist/index.d.ts +0 -2
  95. package/dist/lib/api.d.ts +0 -18
  96. package/dist/lib/api.js +0 -27
  97. package/dist/lib/archive.d.ts +0 -17
  98. package/dist/lib/archive.js +0 -228
  99. package/dist/lib/codex.d.ts +0 -117
  100. package/dist/lib/codex.js +0 -426
  101. package/dist/lib/config-file.d.ts +0 -16
  102. package/dist/lib/config-file.js +0 -54
  103. package/dist/lib/config.d.ts +0 -11
  104. package/dist/lib/config.js +0 -54
  105. package/dist/lib/manifest.d.ts +0 -10
  106. package/dist/lib/manifest.js +0 -91
  107. package/dist/lib/media-args.d.ts +0 -30
  108. package/dist/lib/media-args.js +0 -219
  109. package/dist/lib/media-download.d.ts +0 -37
  110. package/dist/lib/media-download.js +0 -268
  111. package/dist/lib/media-poll.d.ts +0 -18
  112. package/dist/lib/media-poll.js +0 -86
  113. package/dist/lib/media-upload.d.ts +0 -12
  114. package/dist/lib/media-upload.js +0 -52
  115. package/dist/lib/output.d.ts +0 -68
  116. package/dist/lib/output.js +0 -102
  117. package/dist/lib/package-manager.d.ts +0 -25
  118. package/dist/lib/package-manager.js +0 -77
  119. package/dist/lib/playtest/agent.d.ts +0 -192
  120. package/dist/lib/playtest/agent.js +0 -652
  121. package/dist/lib/playtest/browser.d.ts +0 -109
  122. package/dist/lib/playtest/browser.js +0 -219
  123. package/dist/lib/playtest/controls.d.ts +0 -47
  124. package/dist/lib/playtest/controls.js +0 -218
  125. package/dist/lib/playtest/errors.d.ts +0 -9
  126. package/dist/lib/playtest/errors.js +0 -12
  127. package/dist/lib/playtest/keys.d.ts +0 -41
  128. package/dist/lib/playtest/keys.js +0 -157
  129. package/dist/lib/playtest/run.d.ts +0 -195
  130. package/dist/lib/playtest/run.js +0 -409
  131. package/dist/lib/run.d.ts +0 -19
  132. package/dist/lib/run.js +0 -23
  133. package/dist/lib/strict-args.d.ts +0 -27
  134. package/dist/lib/strict-args.js +0 -78
  135. package/dist/lib/types.d.ts +0 -16
  136. package/dist/lib/types.js +0 -10
  137. package/dist/lib/update.d.ts +0 -10
  138. package/dist/lib/update.js +0 -110
  139. package/dist/lib/upload.d.ts +0 -16
  140. package/dist/lib/upload.js +0 -41
@@ -1,52 +0,0 @@
1
- import { openAsBlob } from "node:fs";
2
- import { forwardJson } from "./api.js";
3
- import { isJsonObject, isJsonString } from "./types.js";
4
- const pickUrl = (slot, key) => {
5
- const value = isJsonObject(slot) ? slot[key] : undefined;
6
- if (!isJsonString(value) || value.length === 0) {
7
- throw new Error(`fal storage initiate response missing ${key}.`);
8
- }
9
- // Refuse any non-HTTPS URL even if it comes from a trusted server
10
- // response — a misconfigured response (or a downgrade attack on the
11
- // proxy hop) must not silently send user bytes over plain HTTP, and
12
- // file_url gets passed into later runs where it should stay HTTPS.
13
- let parsed;
14
- try {
15
- parsed = new URL(value);
16
- }
17
- catch {
18
- throw new Error(`fal storage initiate response ${key} is not a valid URL.`);
19
- }
20
- if (parsed.protocol !== "https:") {
21
- throw new Error(`fal storage initiate response ${key} must be HTTPS, got ${parsed.protocol}.`);
22
- }
23
- return value;
24
- };
25
- /**
26
- * Upload one local file directly to fal's CDN. The proxy hands us a
27
- * presigned upload slot (upload_url + file_url) via the `generate.forward`
28
- * storage target; bytes go straight from the client to fal, never
29
- * through the worker. The returned file_url is a stable fal CDN URL
30
- * that can be reused across runs without re-uploading.
31
- */
32
- export const uploadFile = async (client, file) => {
33
- const slot = await forwardJson(client, {
34
- body: { content_type: file.contentType, file_name: file.filename },
35
- method: "POST",
36
- path: "/storage/upload/initiate",
37
- target: "storage",
38
- });
39
- const uploadUrl = pickUrl(slot, "upload_url");
40
- const fileUrl = pickUrl(slot, "file_url");
41
- const body = await openAsBlob(file.path, { type: file.contentType });
42
- const res = await fetch(uploadUrl, {
43
- body,
44
- headers: { "Content-Type": file.contentType },
45
- method: "PUT",
46
- });
47
- if (!res.ok) {
48
- const text = await res.text().catch(() => "");
49
- throw new Error(`Upload failed for ${file.filename}: ${res.status} ${res.statusText} ${text}`);
50
- }
51
- return fileUrl;
52
- };
@@ -1,68 +0,0 @@
1
- /**
2
- * Shared stdout helpers for machine-readable output.
3
- *
4
- * The skills are written for an agent, so nearly every command grew a
5
- * `--json` flag and the docs then piped it through `jq` to pull out a single
6
- * value. That made `jq` a hard prerequisite for following the generate
7
- * skill at all. `--field` removes it: the CLI does the selection itself and
8
- * prints a bare scalar that a shell can capture directly.
9
- */
10
- export interface OutputArgs {
11
- json?: boolean;
12
- field?: string;
13
- }
14
- /**
15
- * What the commands hand to stdout: JSON, plus `undefined` so payload types
16
- * can carry optional members (JSON.stringify drops them, and `--field`
17
- * reports them as missing).
18
- */
19
- export type OutputValue = string | number | boolean | null | undefined | OutputValue[] | {
20
- [key: string]: OutputValue;
21
- };
22
- /**
23
- * What a command may hand to `writeStructured`: a JSON value, or a payload
24
- * type declared member by member.
25
- *
26
- * The second arm exists because TypeScript grants an implicit index signature
27
- * only to a type alias, never to an interface — declaration merging could add
28
- * members later, so an interface's keys are never assumed and it is not
29
- * assignable to `OutputValue`'s object arm. Mapping the payload's own keys
30
- * checks each one against `OutputValue` instead, which still rejects a `Date`
31
- * or a method where `[key: string]: unknown` on every payload would not.
32
- */
33
- type OutputPayload<T> = OutputValue | {
34
- [K in keyof T]: OutputValue;
35
- };
36
- export declare const isJsonOutput: (args: OutputArgs) => boolean;
37
- export declare const writeJson: (value: OutputValue) => void;
38
- /**
39
- * Resolve a dotted path against a decoded JSON value. Supports array indexing
40
- * in both `items[0]` and `items.0` spellings, since agents write both.
41
- * Returns `undefined` for any path that doesn't resolve.
42
- */
43
- export declare const selectField: (value: OutputValue, path: string) => OutputValue;
44
- /**
45
- * Render one selected value for shell capture. Scalars print bare so
46
- * `$(vg ... --field url)` needs no unquoting; arrays of scalars print one per
47
- * line so they can be looped over; anything structural falls back to JSON.
48
- */
49
- export declare const formatField: (value: OutputValue) => string;
50
- /**
51
- * The standard exit path for a command that produced structured data.
52
- * `--field` wins over `--json` when both are passed, since asking for one
53
- * value is the more specific request. Returns false when neither flag was
54
- * given, so the caller can fall through to its human-readable rendering.
55
- */
56
- export declare const writeStructured: <T extends OutputPayload<T>>(value: T, args: OutputArgs) => boolean;
57
- /** The `--json`/`--field` arg pair, for spreading into a citty `args` block. */
58
- export declare const outputArgs: {
59
- readonly field: {
60
- readonly description: "Print a single value from the JSON result, e.g. --field request_id or --field images[0].url. Prints scalars bare for shell capture.";
61
- readonly type: "string";
62
- };
63
- readonly json: {
64
- readonly description: "Print structured JSON to stdout.";
65
- readonly type: "boolean";
66
- };
67
- };
68
- export {};
@@ -1,102 +0,0 @@
1
- /**
2
- * Shared stdout helpers for machine-readable output.
3
- *
4
- * The skills are written for an agent, so nearly every command grew a
5
- * `--json` flag and the docs then piped it through `jq` to pull out a single
6
- * value. That made `jq` a hard prerequisite for following the generate
7
- * skill at all. `--field` removes it: the CLI does the selection itself and
8
- * prints a bare scalar that a shell can capture directly.
9
- */
10
- const isOutputObject = (value) =>
11
- // Object() is the identity only on objects; arrays are split off explicitly.
12
- Object(value) === value && !Array.isArray(value);
13
- export const isJsonOutput = (args) => Boolean(args.json) || process.env.VG_JSON_OUTPUT === "1";
14
- export const writeJson = (value) => {
15
- process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
16
- };
17
- /**
18
- * Resolve a dotted path against a decoded JSON value. Supports array indexing
19
- * in both `items[0]` and `items.0` spellings, since agents write both.
20
- * Returns `undefined` for any path that doesn't resolve.
21
- */
22
- export const selectField = (value, path) => {
23
- const segments = path
24
- .replaceAll(/\[(?<index>-?\d+)\]/gu, ".$<index>")
25
- .split(".")
26
- .filter(Boolean);
27
- let current = value;
28
- for (const segment of segments) {
29
- if (current === null || current === undefined) {
30
- return undefined;
31
- }
32
- if (Array.isArray(current)) {
33
- const index = Number(segment);
34
- if (!Number.isInteger(index)) {
35
- return undefined;
36
- }
37
- // Negative indices count from the end, which is handy for "the last
38
- // frame" style selections.
39
- current = current.at(index);
40
- continue;
41
- }
42
- if (!isOutputObject(current)) {
43
- return undefined;
44
- }
45
- current = current[segment];
46
- }
47
- return current;
48
- };
49
- // A value that prints as one bare token: null or a primitive.
50
- const isScalarEntry = (value) => value === null || (value !== undefined && Object(value) !== value);
51
- /**
52
- * Render one selected value for shell capture. Scalars print bare so
53
- * `$(vg ... --field url)` needs no unquoting; arrays of scalars print one per
54
- * line so they can be looped over; anything structural falls back to JSON.
55
- */
56
- export const formatField = (value) => {
57
- if (value === null || value === undefined) {
58
- return "";
59
- }
60
- if (Array.isArray(value)) {
61
- if (value.every(isScalarEntry)) {
62
- return value.map((v) => (v === null ? "" : String(v))).join("\n");
63
- }
64
- return JSON.stringify(value, null, 2);
65
- }
66
- if (isOutputObject(value)) {
67
- return JSON.stringify(value, null, 2);
68
- }
69
- return String(value);
70
- };
71
- /**
72
- * The standard exit path for a command that produced structured data.
73
- * `--field` wins over `--json` when both are passed, since asking for one
74
- * value is the more specific request. Returns false when neither flag was
75
- * given, so the caller can fall through to its human-readable rendering.
76
- */
77
- export const writeStructured = (value, args) => {
78
- if (args.field) {
79
- const selected = selectField(value, args.field);
80
- if (selected === undefined) {
81
- // Silence here would look like an empty result rather than a typo, and
82
- // an agent would happily carry the empty string forward.
83
- process.stderr.write(`No such field: ${args.field}\n`);
84
- process.exit(1);
85
- }
86
- process.stdout.write(`${formatField(selected)}\n`);
87
- return true;
88
- }
89
- if (isJsonOutput(args)) {
90
- writeJson(value);
91
- return true;
92
- }
93
- return false;
94
- };
95
- /** The `--json`/`--field` arg pair, for spreading into a citty `args` block. */
96
- export const outputArgs = {
97
- field: {
98
- description: "Print a single value from the JSON result, e.g. --field request_id or --field images[0].url. Prints scalars bare for shell capture.",
99
- type: "string",
100
- },
101
- json: { description: "Print structured JSON to stdout.", type: "boolean" },
102
- };
@@ -1,25 +0,0 @@
1
- /**
2
- * Work out which package manager installed this CLI, so a self-update uses it.
3
- *
4
- * `vg init` and `vg update` both used to shell out to `npm install -g
5
- * vibedgames` unconditionally. On a machine where the CLI came from pnpm, bun
6
- * or yarn, that is wrong twice over: npm may not be installed at all, and if it
7
- * is, it installs a *second* copy into a different global prefix — so the
8
- * update silently lands somewhere the shell isn't looking and `vg --version`
9
- * doesn't move.
10
- *
11
- * The install path is the evidence. Each manager puts globals somewhere
12
- * recognisable, so the directory this file was loaded from names the manager
13
- * that put it there.
14
- */
15
- export type PackageManager = "npm" | "pnpm" | "yarn" | "bun";
16
- export declare const PKG_NAME = "vibedgames";
17
- /**
18
- * `installPath` is where the CLI is installed — normally the directory this
19
- * module resolves from. Bun's own runtime is a signal in its own right.
20
- */
21
- export declare const detectPackageManager: (installPath: string, env?: NodeJS.ProcessEnv) => PackageManager;
22
- /** The argv that installs or upgrades a package globally, per manager. */
23
- export declare const globalInstallArgs: (manager: PackageManager, pkg?: string) => string[];
24
- /** The command a user can copy-paste when the automatic update can't run. */
25
- export declare const globalInstallCommand: (manager: PackageManager, pkg?: string) => string;
@@ -1,77 +0,0 @@
1
- /**
2
- * Work out which package manager installed this CLI, so a self-update uses it.
3
- *
4
- * `vg init` and `vg update` both used to shell out to `npm install -g
5
- * vibedgames` unconditionally. On a machine where the CLI came from pnpm, bun
6
- * or yarn, that is wrong twice over: npm may not be installed at all, and if it
7
- * is, it installs a *second* copy into a different global prefix — so the
8
- * update silently lands somewhere the shell isn't looking and `vg --version`
9
- * doesn't move.
10
- *
11
- * The install path is the evidence. Each manager puts globals somewhere
12
- * recognisable, so the directory this file was loaded from names the manager
13
- * that put it there.
14
- */
15
- export const PKG_NAME = "vibedgames";
16
- /**
17
- * Global install directory fingerprints, most specific first.
18
- *
19
- * The npm entries come last because they are the loosest: `lib/node_modules`
20
- * is npm's global prefix on unix and `npm\node_modules` is its Windows one,
21
- * but neither is distinctive enough to check before the managers that have a
22
- * directory named after them.
23
- */
24
- const SIGNATURES = [
25
- ["bun", /[/\\]\.bun[/\\]/u],
26
- // pnpm's global store, not a project-local `node_modules/.pnpm`.
27
- ["pnpm", /[/\\](?:pnpm[/\\]global|\.pnpm-global|Library[/\\]pnpm)[/\\]/u],
28
- ["yarn", /[/\\](?:\.yarn|yarn[/\\]global|\.config[/\\]yarn)[/\\]/u],
29
- ["npm", /[/\\]lib[/\\]node_modules[/\\]/u],
30
- ["npm", /[/\\]npm[/\\]node_modules[/\\]/u],
31
- ];
32
- /**
33
- * `npm_config_user_agent` is set by whichever manager is running us — reliable
34
- * when `vg` was invoked through a script (`pnpm vg …`), absent otherwise.
35
- */
36
- const fromUserAgent = (userAgent) => {
37
- if (!userAgent) {
38
- return null;
39
- }
40
- const [name] = userAgent.split("/");
41
- return name === "npm" || name === "pnpm" || name === "yarn" || name === "bun" ? name : null;
42
- };
43
- /**
44
- * `installPath` is where the CLI is installed — normally the directory this
45
- * module resolves from. Bun's own runtime is a signal in its own right.
46
- */
47
- export const detectPackageManager = (installPath, env = process.env) => {
48
- for (const [manager, signature] of SIGNATURES) {
49
- if (signature.test(installPath)) {
50
- return manager;
51
- }
52
- }
53
- // Bun reports itself in versions; running under it means `bun add` works.
54
- if ("Bun" in globalThis) {
55
- return "bun";
56
- }
57
- return fromUserAgent(env.npm_config_user_agent) ?? "npm";
58
- };
59
- /** The argv that installs or upgrades a package globally, per manager. */
60
- export const globalInstallArgs = (manager, pkg = PKG_NAME) => {
61
- switch (manager) {
62
- case "pnpm": {
63
- return ["add", "-g", pkg];
64
- }
65
- case "yarn": {
66
- return ["global", "add", pkg];
67
- }
68
- case "bun": {
69
- return ["add", "-g", pkg];
70
- }
71
- default: {
72
- return ["install", "-g", pkg];
73
- }
74
- }
75
- };
76
- /** The command a user can copy-paste when the automatic update can't run. */
77
- export const globalInstallCommand = (manager, pkg = PKG_NAME) => `${manager} ${globalInstallArgs(manager, pkg).join(" ")}`;
@@ -1,192 +0,0 @@
1
- /**
2
- * The in-page playtester.
3
- *
4
- * `vg playtest run` injects this function's SOURCE into the game's page and
5
- * calls it there, so the whole decide → apply → measure loop runs inside the
6
- * browser: no CLI round trip per decision, and a per-frame reflex layer that
7
- * a subprocess could never keep up with. The CLI's only jobs are to mint the
8
- * token, inject, poll `window.__PLAYTEST_AGENT__.done`, and read the
9
- * records back.
10
- *
11
- * Rules that follow from being stringified: `inPageAgent` and `browserEnv`
12
- * must be entirely self-contained — no imports, no module-scope references
13
- * (the `declare`d globals below are erased and resolve to the page's own) —
14
- * which is why every helper lives inside them. The agent talks to the page
15
- * only through `env`, the real browser in production and a fake in tests.
16
- *
17
- * The decision is the hold: the previous inputs stay down while the model
18
- * answers, so the game runs continuously and the loop decides at the
19
- * model's latency, with `tickMs` as a floor. A move option in the game's
20
- * `__GAME_PLAYTEST__` may carry a `reflex(game)` function; while that option
21
- * is the current intent, the reflex runs every frame and its returned inputs
22
- * are what is held — the model sets intent a few times a second, the reflex
23
- * turns it into input at 60 fps.
24
- */
25
- /** A parsed JSON document — the shape of everything that crosses the page boundary. */
26
- type Json = string | number | boolean | null | Json[] | {
27
- [key: string]: Json;
28
- };
29
- export interface AgentKeyInit {
30
- code: string;
31
- key: string;
32
- keyCode: number;
33
- which: number;
34
- altKey: boolean;
35
- ctrlKey: boolean;
36
- shiftKey: boolean;
37
- bubbles: true;
38
- }
39
- export interface AgentPointer {
40
- x: number;
41
- y: number;
42
- down: boolean;
43
- }
44
- export interface AgentMove {
45
- description: string;
46
- inits: AgentKeyInit[];
47
- pointer: AgentPointer | null;
48
- }
49
- export interface AgentAction {
50
- description: string;
51
- inits: AgentKeyInit[];
52
- }
53
- export interface AgentConfig {
54
- decideUrl: string;
55
- token: string;
56
- model: string;
57
- /** Hold this move for the whole run and never call the model — for tuning a reflex. */
58
- pinMove: string | null;
59
- goal: string;
60
- move: Record<string, AgentMove>;
61
- actions: Record<string, AgentAction>;
62
- /** Every supported KeyboardEvent code, for inputs a reflex returns. */
63
- keyTable: Record<string, AgentKeyInit>;
64
- ticks: number;
65
- tickMs: number;
66
- finalHoldMs: number;
67
- actionThreshold: number;
68
- motionEpsilon: number;
69
- stuckRun: number;
70
- /** Decisions in a row of holding nothing, going nowhere, before the no-input option is rested. */
71
- idleRun: number;
72
- /** How many decisions a rested no-input option stays out of the question. */
73
- idleRestTicks: number;
74
- trailLength: number;
75
- decisionRetries: number;
76
- decisionTimeoutMs: number;
77
- }
78
- export interface AgentSample {
79
- x: number;
80
- y: number;
81
- z: number;
82
- frame: number;
83
- score: number;
84
- complete: boolean;
85
- }
86
- export interface AgentWindow {
87
- path: number;
88
- peak: number;
89
- frameBefore: number;
90
- frame: number;
91
- scoreBefore: number;
92
- score: number;
93
- x: number;
94
- y: number;
95
- z: number;
96
- complete: boolean;
97
- }
98
- export interface AgentRecord {
99
- tick: number;
100
- move: string;
101
- actions: string[];
102
- actionProbabilities: Record<string, number>;
103
- confidence: number | null;
104
- decisionMs: number;
105
- inputTokens: number;
106
- outputTokens: number;
107
- /** Frames on which the option's reflex produced the held input. */
108
- reflexFrames: number;
109
- /**
110
- * The model's own read of how close the player is to `goal`, 0–1, from the
111
- * `progress` score question; null when it gave none.
112
- */
113
- progress: number | null;
114
- /** Whether the move asked the player to move at all, so a still window can count as stuck. */
115
- askedToMove: boolean;
116
- window: AgentWindow;
117
- }
118
- export interface AgentUsage {
119
- calls: number;
120
- inputTokens: number;
121
- outputTokens: number;
122
- totalDecisionMs: number;
123
- maxDecisionMs: number;
124
- }
125
- export interface AgentResult {
126
- done: boolean;
127
- error: string | null;
128
- records: AgentRecord[];
129
- usage: AgentUsage;
130
- wallMs: number;
131
- completedAtTick: number | null;
132
- stop: () => void;
133
- }
134
- /** The game's diagnostics, as far as the agent reads them. */
135
- export interface Diagnostics {
136
- frame?: number;
137
- score?: number;
138
- complete?: boolean;
139
- player?: {
140
- x?: number;
141
- y?: number;
142
- z?: number;
143
- };
144
- }
145
- /** What a reflex may hand back: key codes to hold and/or a pointer position. */
146
- export interface ReflexInputs {
147
- keys?: string[];
148
- pointer?: {
149
- x: number;
150
- y: number;
151
- down?: boolean;
152
- } | null;
153
- /** The reflex is trying to move and getting nowhere; see `settle`. */
154
- stuck?: boolean;
155
- }
156
- export type Reflex = (game: Diagnostics | null) => ReflexInputs | null | undefined;
157
- export interface AgentResponse {
158
- ok: boolean;
159
- status: number;
160
- text: () => Promise<string>;
161
- }
162
- export interface AgentRequest {
163
- method: string;
164
- headers: Record<string, string>;
165
- body: string;
166
- }
167
- /** The page, as the agent sees it. */
168
- export interface AgentEnv {
169
- now: () => number;
170
- fetch: (url: string, init: AgentRequest) => Promise<AgentResponse>;
171
- raf: (frame: () => void) => number;
172
- caf: (id: number) => void;
173
- delay: (ms: number) => Promise<void>;
174
- read: () => AgentSample;
175
- /** A JSON-safe copy of the diagnostics, for the model. */
176
- snapshot: () => Json;
177
- /** The live diagnostics object, for a reflex. */
178
- live: () => Diagnostics | null;
179
- dispatchKey: (type: "keydown" | "keyup", init: AgentKeyInit) => void;
180
- dispatchPointer: (pointer: AgentPointer, type: "pointermove" | "pointerdown" | "pointerup") => void;
181
- reflexFor: (label: string) => Reflex | null;
182
- publish: (result: AgentResult) => void;
183
- }
184
- /** The real page as an AgentEnv. Only ever runs in the browser; injected beside the agent. */
185
- export declare const browserEnv: () => AgentEnv;
186
- /**
187
- * Run the playtest inside the page. Returns the live result object, which is
188
- * also published as `window.__PLAYTEST_AGENT__`; `done` flips when the run
189
- * ends, `error` says why if it ended early.
190
- */
191
- export declare const inPageAgent: (config: AgentConfig, env: AgentEnv) => AgentResult;
192
- export {};