vibedgames 0.5.0 → 0.6.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 (74) hide show
  1. package/LICENSE +21 -0
  2. package/dist/commands/completions.d.ts +1 -1
  3. package/dist/commands/completions.js +21 -20
  4. package/dist/commands/credits.d.ts +5 -5
  5. package/dist/commands/credits.js +43 -33
  6. package/dist/commands/deploy.d.ts +10 -10
  7. package/dist/commands/deploy.js +155 -139
  8. package/dist/commands/factory.d.ts +1 -1
  9. package/dist/commands/factory.js +18 -15
  10. package/dist/commands/fork.d.ts +14 -14
  11. package/dist/commands/fork.js +51 -46
  12. package/dist/commands/generate.js +318 -264
  13. package/dist/commands/init.d.ts +8 -8
  14. package/dist/commands/init.js +31 -24
  15. package/dist/commands/login.js +12 -12
  16. package/dist/commands/logout.js +2 -2
  17. package/dist/commands/new.d.ts +16 -16
  18. package/dist/commands/new.js +153 -142
  19. package/dist/commands/playtest-run.d.ts +62 -0
  20. package/dist/commands/playtest-run.js +258 -0
  21. package/dist/commands/playtest.d.ts +41 -6
  22. package/dist/commands/playtest.js +114 -101
  23. package/dist/commands/update.d.ts +7 -7
  24. package/dist/commands/update.js +20 -17
  25. package/dist/commands/whoami.d.ts +5 -5
  26. package/dist/commands/whoami.js +8 -7
  27. package/dist/index.js +21 -11
  28. package/dist/lib/api.d.ts +4 -4
  29. package/dist/lib/api.js +6 -12
  30. package/dist/lib/archive.d.ts +4 -4
  31. package/dist/lib/archive.js +121 -104
  32. package/dist/lib/codex.d.ts +45 -15
  33. package/dist/lib/codex.js +175 -106
  34. package/dist/lib/config-file.d.ts +6 -6
  35. package/dist/lib/config-file.js +28 -26
  36. package/dist/lib/config.d.ts +8 -8
  37. package/dist/lib/config.js +31 -33
  38. package/dist/lib/manifest.d.ts +3 -3
  39. package/dist/lib/manifest.js +42 -38
  40. package/dist/lib/media-args.d.ts +7 -7
  41. package/dist/lib/media-args.js +113 -95
  42. package/dist/lib/media-download.d.ts +9 -9
  43. package/dist/lib/media-download.js +148 -134
  44. package/dist/lib/media-poll.d.ts +8 -8
  45. package/dist/lib/media-poll.js +32 -27
  46. package/dist/lib/media-upload.d.ts +2 -2
  47. package/dist/lib/media-upload.js +27 -27
  48. package/dist/lib/output.d.ts +27 -12
  49. package/dist/lib/output.js +26 -26
  50. package/dist/lib/package-manager.d.ts +3 -3
  51. package/dist/lib/package-manager.js +27 -22
  52. package/dist/lib/playtest/agent.d.ts +188 -0
  53. package/dist/lib/playtest/agent.js +610 -0
  54. package/dist/lib/playtest/browser.d.ts +109 -0
  55. package/dist/lib/playtest/browser.js +219 -0
  56. package/dist/lib/playtest/controls.d.ts +47 -0
  57. package/dist/lib/playtest/controls.js +218 -0
  58. package/dist/lib/playtest/errors.d.ts +9 -0
  59. package/dist/lib/playtest/errors.js +12 -0
  60. package/dist/lib/playtest/keys.d.ts +41 -0
  61. package/dist/lib/playtest/keys.js +157 -0
  62. package/dist/lib/playtest/run.d.ts +193 -0
  63. package/dist/lib/playtest/run.js +408 -0
  64. package/dist/lib/run.d.ts +4 -4
  65. package/dist/lib/run.js +7 -4
  66. package/dist/lib/strict-args.d.ts +4 -4
  67. package/dist/lib/strict-args.js +28 -18
  68. package/dist/lib/types.d.ts +5 -5
  69. package/dist/lib/types.js +9 -12
  70. package/dist/lib/update.d.ts +4 -4
  71. package/dist/lib/update.js +41 -32
  72. package/dist/lib/upload.d.ts +4 -4
  73. package/dist/lib/upload.js +14 -9
  74. package/package.json +16 -16
@@ -1,8 +1,8 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { existsSync, mkdirSync, statSync, writeFileSync } from "node:fs";
3
- import { join } from "node:path";
3
+ import path from "node:path";
4
4
  import { defineCommand } from "citty";
5
- import consola from "consola";
5
+ import { consola } from "consola";
6
6
  import spawn from "cross-spawn";
7
7
  import { getBaseUrl, getConfigDir } from "../lib/config.js";
8
8
  import { isNewerVersion } from "../lib/update.js";
@@ -48,15 +48,16 @@ const KNOWN_VERBS = new Set([...URL_TAKING, "diff"]);
48
48
  * Doubles as the "is it installed?" probe: a version we can read is proof the
49
49
  * binary works, which a bare exit code isn't.
50
50
  */
51
- function installedVersion(bin) {
51
+ const installedVersion = (bin) => {
52
52
  // cross-spawn's sync sets `error` to null on success (node's spawnSync leaves
53
53
  // it undefined), so test truthiness rather than comparing against undefined.
54
- const res = spawn.sync(bin, ["--version"], { encoding: "utf8", timeout: 30_000 });
55
- if (res.status !== 0 || res.error)
54
+ const res = spawn.sync(bin, ["--version"], { encoding: "utf-8", timeout: 30_000 });
55
+ if (res.status !== 0 || res.error) {
56
56
  return null;
57
- const match = /(\d+)\.(\d+)\.(\d+)/.exec(res.stdout ?? "");
57
+ }
58
+ const match = /\d+\.\d+\.\d+/u.exec(res.stdout ?? "");
58
59
  return match ? match[0] : UNKNOWN_VERSION;
59
- }
60
+ };
60
61
  /**
61
62
  * Whether a version is new enough for the playtest skill.
62
63
  *
@@ -69,26 +70,35 @@ function installedVersion(bin) {
69
70
  * that isn't `x.y.z` — because a binary from brew or cargo may not report a
70
71
  * semver at all, and blocking it would be worse than trusting it.
71
72
  */
72
- function meetsMinimum(version) {
73
- return !isNewerVersion(MIN_VERSION, version);
74
- }
73
+ const meetsMinimum = (version) => !isNewerVersion(MIN_VERSION, version);
75
74
  /** The agent-browser binary to use. VG_AGENT_BROWSER_BIN overrides (dev). */
76
- function resolveBinary() {
75
+ export const resolveBinary = () => {
77
76
  const override = process.env.VG_AGENT_BROWSER_BIN;
78
77
  // A dev-pointed binary is taken on trust — it is typically a local build with
79
78
  // no npm version to read, and `meetsMinimum` waves an unparseable one through.
80
- if (override)
79
+ if (override) {
81
80
  return existsSync(override) ? { bin: override, version: UNKNOWN_VERSION } : null;
81
+ }
82
82
  const version = installedVersion(PKG);
83
83
  return version === null ? null : { bin: PKG, version };
84
- }
84
+ };
85
+ /** `npm install -g` the pinned spec, then re-resolve. Null if either step fails. */
86
+ const installGlobal = () => {
87
+ // Bounded so a wedged registry or install script can't hang `vg playtest`
88
+ // forever; generous enough not to cut off a slow but working download.
89
+ const res = spawn.sync("npm", ["install", "-g", PKG_SPEC], {
90
+ stdio: "inherit",
91
+ timeout: 10 * 60_000,
92
+ });
93
+ return res.status === 0 && !res.error ? resolveBinary() : null;
94
+ };
85
95
  /**
86
96
  * Install agent-browser globally, then provision its browser. Upstream ships
87
97
  * these as two steps (`npm i -g` puts the Rust binary in place; `install`
88
98
  * fetches Chrome for Testing and reuses an existing Chrome/Brave/Playwright
89
99
  * install when it finds one), so a first run pays for both.
90
100
  */
91
- function bootstrap() {
101
+ export const bootstrap = () => {
92
102
  consola.start(`Installing the playtest browser (${PKG})…`);
93
103
  const resolved = installGlobal();
94
104
  if (!resolved) {
@@ -103,7 +113,21 @@ function bootstrap() {
103
113
  }
104
114
  consola.success("Playtest browser ready.");
105
115
  return resolved;
106
- }
116
+ };
117
+ /**
118
+ * Whether an upgrade was already tried recently. Time-boxed rather than
119
+ * permanent: the usual reason one fails is being offline, and a machine that is
120
+ * online tomorrow should get the upgrade rather than stay pinned by a stamp it
121
+ * wrote once.
122
+ */
123
+ const recentlyFailed = (stamp) => {
124
+ try {
125
+ return Date.now() - statSync(stamp).mtimeMs < UPGRADE_RETRY_MS;
126
+ }
127
+ catch {
128
+ return false;
129
+ }
130
+ };
107
131
  /**
108
132
  * Bring an agent-browser older than the minimum up to it.
109
133
  *
@@ -113,24 +137,26 @@ function bootstrap() {
113
137
  * leave an older global install — already on PATH from some earlier project —
114
138
  * driving every run, which is how a documented contract silently stops holding.
115
139
  */
116
- function ensureMinimum(resolved) {
117
- if (meetsMinimum(resolved.version))
140
+ export const ensureMinimum = (resolved) => {
141
+ if (meetsMinimum(resolved.version)) {
118
142
  return resolved;
143
+ }
119
144
  // The bot script runs `vg playtest` once per step, so an upgrade that cannot
120
145
  // stick — read-only npm prefix, offline, locked-down CI — would otherwise
121
146
  // retry its npm round-trip on every one of them. Recorded per user rather
122
147
  // than in a shared /tmp, where one account's stamp would silently suppress
123
148
  // everyone else's upgrade.
124
- const stamp = join(getConfigDir(), `${PKG}-upgrade-failed-${resolved.version}`);
125
- if (recentlyFailed(stamp))
149
+ const stamp = path.join(getConfigDir(), `${PKG}-upgrade-failed-${resolved.version}`);
150
+ if (recentlyFailed(stamp)) {
126
151
  return resolved;
152
+ }
127
153
  consola.warn(`Found ${PKG} ${resolved.version}, but the playtest skill needs at least ${MIN_VERSION}. Upgrading…`);
128
154
  const upgraded = installGlobal();
129
155
  if (!upgraded || !meetsMinimum(upgraded.version)) {
130
156
  // Continue anyway: an older binary handles most commands fine, and failing
131
157
  // outright would strand anyone who can't write to npm's global prefix.
132
158
  try {
133
- mkdirSync(getConfigDir(), { recursive: true, mode: 0o700 });
159
+ mkdirSync(getConfigDir(), { mode: 0o700, recursive: true });
134
160
  writeFileSync(stamp, "");
135
161
  }
136
162
  catch {
@@ -140,38 +166,30 @@ function ensureMinimum(resolved) {
140
166
  return resolved;
141
167
  }
142
168
  return upgraded;
143
- }
144
- /**
145
- * Whether an upgrade was already tried recently. Time-boxed rather than
146
- * permanent: the usual reason one fails is being offline, and a machine that is
147
- * online tomorrow should get the upgrade rather than stay pinned by a stamp it
148
- * wrote once.
149
- */
150
- function recentlyFailed(stamp) {
169
+ };
170
+ /** The current project's slug, from the nearest vibedgames.json. */
171
+ const projectSlug = () => {
172
+ let config = null;
151
173
  try {
152
- return Date.now() - statSync(stamp).mtimeMs < UPGRADE_RETRY_MS;
174
+ config = readProjectConfig(process.cwd());
153
175
  }
154
- catch {
155
- return false;
176
+ catch (error) {
177
+ consola.error(error instanceof Error ? error.message : String(error));
178
+ process.exit(1);
156
179
  }
157
- }
158
- /** `npm install -g` the pinned spec, then re-resolve. Null if either step fails. */
159
- function installGlobal() {
160
- // Bounded so a wedged registry or install script can't hang `vg playtest`
161
- // forever; generous enough not to cut off a slow but working download.
162
- const res = spawn.sync("npm", ["install", "-g", PKG_SPEC], {
163
- stdio: "inherit",
164
- timeout: 10 * 60_000,
165
- });
166
- return res.status === 0 && !res.error ? resolveBinary() : null;
167
- }
180
+ if (!config) {
181
+ consola.error("`--game` with no slug reads vibedgames.json, and none was found here. Pass a slug (`vg playtest --game my-game`) or run from a deployed project.");
182
+ process.exit(1);
183
+ }
184
+ return config.slug;
185
+ };
168
186
  /**
169
187
  * The URL a game is served at: a per-slug subdomain of whatever host this CLI
170
188
  * is pointed at, so `VG_API_URL=…staging vg playtest --game x` playtests
171
189
  * staging rather than silently hitting production the way a hardcoded apex
172
190
  * would. Mirrors the derivation the deploy router does server-side.
173
191
  */
174
- function resolveGameUrl(slug) {
192
+ export const resolveGameUrl = (slug) => {
175
193
  const resolved = slug ?? projectSlug();
176
194
  // The slug lands in the host, so anything outside the deploy grammar could
177
195
  // steer the browser off `*.vibedgames.com` entirely — `../`, an embedded
@@ -186,23 +204,7 @@ function resolveGameUrl(slug) {
186
204
  process.exit(1);
187
205
  }
188
206
  return `${base.protocol}//${resolved}.${base.host}`;
189
- }
190
- /** The current project's slug, from the nearest vibedgames.json. */
191
- function projectSlug() {
192
- let config = null;
193
- try {
194
- config = readProjectConfig(process.cwd());
195
- }
196
- catch (err) {
197
- consola.error(err instanceof Error ? err.message : String(err));
198
- process.exit(1);
199
- }
200
- if (!config) {
201
- consola.error("`--game` with no slug reads vibedgames.json, and none was found here. Pass a slug (`vg playtest --game my-game`) or run from a deployed project.");
202
- process.exit(1);
203
- }
204
- return config.slug;
205
- }
207
+ };
206
208
  /**
207
209
  * The tokens in `args` that aren't flags or flag values — agent-browser's verb
208
210
  * and its positional arguments, in order.
@@ -219,31 +221,32 @@ function projectSlug() {
219
221
  * a grammar that moves every release. This catches the shapes people actually
220
222
  * type; anything past it reaches agent-browser as before.
221
223
  */
222
- export function bareTokens(args) {
223
- return args.filter((arg, index) => {
224
- if (arg.startsWith("-"))
225
- return false;
226
- // A token that IS a known verb is one, whatever precedes it. "Preceded by a
227
- // flag" can't tell a boolean flag from a valued one, so `--headed open`
228
- // would otherwise read `open` as `--headed`'s value, see no verb at all,
229
- // and insert a second one — agent-browser then navigates to the literal
230
- // string "open" and lands on chrome-error://.
231
- //
232
- // The cost is a session or profile named exactly after a verb
233
- // (`--session open`), which is now read as the verb. That is the rarer
234
- // input by a wide margin, and it fails loudly instead of silently going
235
- // somewhere wrong.
236
- // `--game`'s own value is exempt: that flag is ours, so we know it takes a
237
- // value, and a game may legitimately be called `open` or `diff`.
238
- const previous = args[index - 1];
239
- if (KNOWN_VERBS.has(arg) && previous !== "--game")
240
- return true;
241
- return !(previous !== undefined && previous.startsWith("-") && !previous.includes("="));
242
- });
243
- }
244
- export function expandGameFlag(args, resolveUrl = resolveGameUrl) {
245
- if (!args.includes("--game"))
224
+ export const bareTokens = (args) => args.filter((arg, index) => {
225
+ if (arg.startsWith("-")) {
226
+ return false;
227
+ }
228
+ // A token that IS a known verb is one, whatever precedes it. "Preceded by a
229
+ // flag" can't tell a boolean flag from a valued one, so `--headed open`
230
+ // would otherwise read `open` as `--headed`'s value, see no verb at all,
231
+ // and insert a second one — agent-browser then navigates to the literal
232
+ // string "open" and lands on chrome-error://.
233
+ //
234
+ // The cost is a session or profile named exactly after a verb
235
+ // (`--session open`), which is now read as the verb. That is the rarer
236
+ // input by a wide margin, and it fails loudly instead of silently going
237
+ // somewhere wrong.
238
+ // `--game`'s own value is exempt: that flag is ours, so we know it takes a
239
+ // value, and a game may legitimately be called `open` or `diff`.
240
+ const previous = args[index - 1];
241
+ if (KNOWN_VERBS.has(arg) && previous !== "--game") {
242
+ return true;
243
+ }
244
+ return !(previous !== undefined && previous.startsWith("-") && !previous.includes("="));
245
+ });
246
+ export const expandGameFlag = (args, resolveUrl = resolveGameUrl) => {
247
+ if (!args.includes("--game")) {
246
248
  return args;
249
+ }
247
250
  // Catch `vg playtest snapshot --game x`, where the URL has nowhere to go —
248
251
  // agent-browser silently runs the snapshot and ignores the stray URL, so
249
252
  // leaving it to upstream costs a wrong answer rather than an error. Skipped
@@ -258,7 +261,7 @@ export function expandGameFlag(args, resolveUrl = resolveGameUrl) {
258
261
  // argument answer for the command: `click open --game x` would pass the guard
259
262
  // on the selector named `open` and click the current page.
260
263
  const bare = bareTokens(args);
261
- const verb = bare[0];
264
+ const [verb] = bare;
262
265
  const hasUrlVerb = verb !== undefined &&
263
266
  (URL_TAKING.has(verb) || (verb === "diff" && bare[1] !== undefined && URL_TAKING.has(bare[1])));
264
267
  // A verb that only appears AFTER the flag can't receive the URL: substituting
@@ -302,7 +305,7 @@ export function expandGameFlag(args, resolveUrl = resolveGameUrl) {
302
305
  out.push(resolveUrl(slug));
303
306
  }
304
307
  return out;
305
- }
308
+ };
306
309
  /**
307
310
  * agent-browser's session defaults to the literal name `default`, which is
308
311
  * shared by every caller on the machine. Two `vg playtest` runs — two projects
@@ -314,42 +317,52 @@ export function expandGameFlag(args, resolveUrl = resolveGameUrl) {
314
317
  * environment, or is asking about sessions themselves (`session list` must see
315
318
  * every session, not just this project's).
316
319
  */
317
- export function withScopedSession(args, sessionId) {
318
- if (args.includes("--session") || args.some((a) => a.startsWith("--session=")))
320
+ export const withScopedSession = (args, sessionId) => {
321
+ if (args.includes("--session") || args.some((a) => a.startsWith("--session="))) {
319
322
  return args;
320
- if (process.env.AGENT_BROWSER_SESSION)
323
+ }
324
+ if (process.env.AGENT_BROWSER_SESSION) {
321
325
  return args;
322
- const verb = bareTokens(args)[0];
326
+ }
327
+ const [verb] = bareTokens(args);
323
328
  // No verb means `--help`/`--version`, and `install`/`session` are machine-wide
324
329
  // — `session list` has to see every session, not just this project's.
325
- if (verb === undefined || verb === "session" || verb === "install")
330
+ if (verb === undefined || verb === "session" || verb === "install") {
326
331
  return args;
332
+ }
327
333
  return ["--session", sessionId(), ...args];
328
- }
334
+ };
329
335
  /**
330
336
  * A stable per-project session name. Keyed on the project root when there is
331
337
  * one so every command run from anywhere inside the project shares a browser,
332
338
  * and on the cwd otherwise. Hashed because the name lands in a socket path.
333
339
  */
334
- function projectSessionId() {
340
+ export const projectSessionId = () => {
335
341
  const root = findProjectRoot(process.cwd()) ?? process.cwd();
336
342
  const digest = createHash("sha256").update(root).digest("hex").slice(0, 12);
337
343
  return `vg-${digest}`;
338
- }
344
+ };
345
+ /**
346
+ * The agent-browser to drive: installed on first use, upgraded to the floor
347
+ * when older. Bootstrap covers `install` too: on a fresh machine that's the
348
+ * most natural first command, and re-running the provision step it just did
349
+ * is harmless.
350
+ */
351
+ export const ensureAgentBrowser = () => {
352
+ const resolved = resolveBinary();
353
+ return resolved ? ensureMinimum(resolved) : bootstrap();
354
+ };
339
355
  /** Resolve (installing on first use) and exec agent-browser. Never returns. */
340
- export function runPlaytest(rawArgs) {
356
+ export const runPlaytest = (rawArgs) => {
341
357
  const args = withScopedSession(expandGameFlag(rawArgs), projectSessionId);
342
- // Bootstrap covers `install` too: on a fresh machine that's the most natural
343
- // first command, and re-running the provision step it just did is harmless.
344
- const resolved = resolveBinary();
345
- const { bin } = resolved ? ensureMinimum(resolved) : bootstrap();
358
+ const { bin } = ensureAgentBrowser();
346
359
  const result = spawn.sync(bin, args, { stdio: "inherit" });
347
360
  process.exit(result.status ?? 1);
348
- }
361
+ };
349
362
  export const playtestCommand = defineCommand({
350
363
  meta: {
364
+ description: "Drive a real browser to play a game — snapshot, click, hold keys, read state, screenshot, diff (installs the browser on first use). All arguments pass through: `vg playtest open <url>`, `vg playtest --game <slug>` to open a deployed game, `vg playtest --help` for the full command surface. `vg playtest run` is the exception: a model plays the game and reports (`vg playtest run --help`).",
351
365
  name: "playtest",
352
- description: "Drive a real browser to play a game — snapshot, click, hold keys, read state, screenshot, diff (installs the browser on first use). All arguments pass through: `vg playtest open <url>`, `vg playtest --game <slug>` to open a deployed game, `vg playtest --help` for the full command surface.",
353
366
  },
354
367
  run: ({ rawArgs }) => {
355
368
  // Normally unreachable (index.ts routes `vg playtest` before citty), but
@@ -1,13 +1,13 @@
1
1
  export declare const updateCommand: import("citty").CommandDef<{
2
- readonly global: {
3
- readonly type: "boolean";
4
- readonly description: "Update skills installed in the user directory instead of the project";
5
- readonly default: false;
6
- readonly alias: "g";
7
- };
8
2
  readonly auto: {
9
- readonly type: "boolean";
3
+ readonly default: false;
10
4
  readonly description: "(internal) silent background mode: only update when the registry has a newer version";
5
+ readonly type: "boolean";
6
+ };
7
+ readonly global: {
8
+ readonly alias: "g";
11
9
  readonly default: false;
10
+ readonly description: "Update skills installed in the user directory instead of the project";
11
+ readonly type: "boolean";
12
12
  };
13
13
  }>;
@@ -1,48 +1,49 @@
1
1
  import { readFileSync } from "node:fs";
2
- import { fileURLToPath } from "node:url";
3
2
  import { defineCommand } from "citty";
4
- import consola from "consola";
3
+ import { consola } from "consola";
5
4
  import { detectPackageManager, globalInstallArgs, globalInstallCommand, } from "../lib/package-manager.js";
6
5
  import { isMissingCommand, run } from "../lib/run.js";
7
6
  import { assertKnownFlags } from "../lib/strict-args.js";
8
7
  import { fetchLatestVersion, isNewerVersion } from "../lib/update.js";
9
8
  // SAFETY: this is the CLI's own package.json, shipped alongside dist — npm
10
9
  // refuses to publish a package without a string `version`.
11
- const pkg = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8"));
10
+ const pkg = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf-8"));
12
11
  const skillsUpdateArgs = (global) => {
13
12
  const args = ["-y", "skills", "update", "-y"];
14
- if (global)
13
+ if (global) {
15
14
  args.push("-g");
15
+ }
16
16
  return args;
17
17
  };
18
18
  const updateArgs = {
19
- global: {
20
- type: "boolean",
21
- description: "Update skills installed in the user directory instead of the project",
22
- default: false,
23
- alias: "g",
24
- },
25
19
  auto: {
26
- type: "boolean",
20
+ default: false,
27
21
  description: "(internal) silent background mode: only update when the registry has a newer version",
22
+ type: "boolean",
23
+ },
24
+ global: {
25
+ alias: "g",
28
26
  default: false,
27
+ description: "Update skills installed in the user directory instead of the project",
28
+ type: "boolean",
29
29
  },
30
30
  };
31
31
  export const updateCommand = defineCommand({
32
+ args: updateArgs,
32
33
  meta: {
33
- name: "update",
34
34
  description: "Update the vg CLI and vibedgames skills to latest (runs automatically once a day; disable with VG_NO_AUTO_UPDATE=1)",
35
+ name: "update",
35
36
  },
36
- args: updateArgs,
37
37
  run: async ({ args, rawArgs }) => {
38
38
  assertKnownFlags(rawArgs, updateArgs);
39
39
  // Upgrade with whatever installed this CLI: another manager would write a
40
40
  // second copy into a different global prefix, leaving the one on PATH stale.
41
- const manager = detectPackageManager(fileURLToPath(import.meta.url));
41
+ const manager = detectPackageManager(import.meta.filename);
42
42
  if (args.auto) {
43
43
  const latest = await fetchLatestVersion();
44
- if (!latest || !isNewerVersion(latest, pkg.version))
44
+ if (!latest || !isNewerVersion(latest, pkg.version)) {
45
45
  return;
46
+ }
46
47
  await Promise.all([
47
48
  run(manager, globalInstallArgs(manager)),
48
49
  run("npx", skillsUpdateArgs(args.global)),
@@ -58,8 +59,9 @@ export const updateCommand = defineCommand({
58
59
  consola.success(`vg CLI updated to latest with ${manager}`);
59
60
  }
60
61
  else {
61
- if (cli.output.trim() && !isMissingCommand(cli))
62
+ if (cli.output.trim() && !isMissingCommand(cli)) {
62
63
  consola.warn(cli.output.trim());
64
+ }
63
65
  consola.warn(isMissingCommand(cli)
64
66
  ? `Couldn't find ${manager} to update the vg CLI. Update manually: ${globalInstallCommand(manager)}`
65
67
  : `Couldn't update the vg CLI (${manager} exit ${cli.code}). Update manually: ${globalInstallCommand(manager)}`);
@@ -68,8 +70,9 @@ export const updateCommand = defineCommand({
68
70
  consola.success("Skills updated to latest");
69
71
  }
70
72
  else {
71
- if (skills.output.trim())
73
+ if (skills.output.trim()) {
72
74
  consola.warn(skills.output.trim());
75
+ }
73
76
  consola.warn(`'skills update' exited with code ${skills.code}. If skills aren't installed here yet, run: vg init`);
74
77
  }
75
78
  if (cli.code !== 0 && skills.code !== 0) {
@@ -1,10 +1,10 @@
1
1
  export declare const whoamiCommand: import("citty").CommandDef<{
2
- readonly json: {
3
- readonly type: "boolean";
4
- readonly description: "Print structured JSON to stdout.";
5
- };
6
2
  readonly field: {
7
- readonly type: "string";
8
3
  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.";
4
+ readonly type: "string";
5
+ };
6
+ readonly json: {
7
+ readonly description: "Print structured JSON to stdout.";
8
+ readonly type: "boolean";
9
9
  };
10
10
  }>;
@@ -1,16 +1,16 @@
1
1
  import { defineCommand } from "citty";
2
- import consola from "consola";
2
+ import { consola } from "consola";
3
3
  import { authErrorCode, createClient } from "../lib/api.js";
4
4
  import { getToken } from "../lib/config.js";
5
5
  import { outputArgs, writeStructured } from "../lib/output.js";
6
6
  import { assertKnownFlags } from "../lib/strict-args.js";
7
7
  const whoamiArgs = { ...outputArgs };
8
8
  export const whoamiCommand = defineCommand({
9
+ args: whoamiArgs,
9
10
  meta: {
10
- name: "whoami",
11
11
  description: "Show the currently authenticated user",
12
+ name: "whoami",
12
13
  },
13
- args: whoamiArgs,
14
14
  run: async ({ args, rawArgs }) => {
15
15
  assertKnownFlags(rawArgs, whoamiArgs);
16
16
  const token = getToken();
@@ -23,19 +23,20 @@ export const whoamiCommand = defineCommand({
23
23
  const client = createClient();
24
24
  try {
25
25
  const user = await client.auth.me();
26
- if (writeStructured({ id: user.id, name: user.name, email: user.email }, args))
26
+ if (writeStructured({ email: user.email, id: user.id, name: user.name }, args)) {
27
27
  return;
28
+ }
28
29
  consola.log(`${user.name} (${user.email})`);
29
30
  }
30
- catch (err) {
31
+ catch (error) {
31
32
  // Only an auth error means "log in"; surface network/server failures as
32
33
  // themselves so they aren't mistaken for a bad credential.
33
- const code = authErrorCode(err);
34
+ const code = authErrorCode(error);
34
35
  if (code === "UNAUTHORIZED" || code === "FORBIDDEN") {
35
36
  consola.warn("Not authenticated. Run `vg login`, or check your VG_TOKEN / API key.");
36
37
  }
37
38
  else {
38
- consola.error(`Failed to fetch current user: ${err instanceof Error ? err.message : String(err)}`);
39
+ consola.error(`Failed to fetch current user: ${error instanceof Error ? error.message : String(error)}`);
39
40
  }
40
41
  process.exit(1);
41
42
  }
package/dist/index.js CHANGED
@@ -11,38 +11,48 @@ import { initCommand } from "./commands/init.js";
11
11
  import { loginCommand } from "./commands/login.js";
12
12
  import { logoutCommand } from "./commands/logout.js";
13
13
  import { newCommand } from "./commands/new.js";
14
+ import { playtestRunCommand } from "./commands/playtest-run.js";
14
15
  import { playtestCommand, runPlaytest } from "./commands/playtest.js";
15
16
  import { updateCommand } from "./commands/update.js";
16
17
  import { whoamiCommand } from "./commands/whoami.js";
17
18
  import { maybeScheduleAutoUpdate } from "./lib/update.js";
18
19
  // SAFETY: this is the CLI's own package.json, shipped alongside dist — npm
19
20
  // refuses to publish a package without a string `version`.
20
- const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
21
+ const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf-8"));
21
22
  const main = defineCommand({
22
23
  meta: {
24
+ description: "vibedgames CLI — agent-native game deploy & asset tooling (use --json for machine-readable output)",
23
25
  name: "vg",
24
26
  version: pkg.version,
25
- description: "vibedgames CLI — agent-native game deploy & asset tooling (use --json for machine-readable output)",
26
27
  },
27
28
  subCommands: {
28
- new: newCommand,
29
- init: initCommand,
30
- login: loginCommand,
31
- logout: logoutCommand,
29
+ completions: completionsCommand,
30
+ credits: creditsCommand,
32
31
  deploy: deployCommand,
33
- playtest: playtestCommand,
34
32
  factory: factoryCommand,
35
33
  fork: forkCommand,
36
34
  generate: generateCommand,
37
- credits: creditsCommand,
35
+ init: initCommand,
36
+ login: loginCommand,
37
+ logout: logoutCommand,
38
+ new: newCommand,
39
+ // `run` is the one `vg playtest` verb that is ours rather than
40
+ // agent-browser's: the model-driven playtest. index.ts routes every other
41
+ // `vg playtest …` straight to the binary below. Only the meta is reused:
42
+ // citty runs a parent's `run` AFTER its subcommand, so carrying the
43
+ // passthrough here would forward `run …` to agent-browser once the
44
+ // playtest had finished and turn every passing run into an exit 1.
45
+ playtest: defineCommand({
46
+ meta: playtestCommand.meta,
47
+ subCommands: { run: playtestRunCommand },
48
+ }),
38
49
  update: updateCommand,
39
- completions: completionsCommand,
40
50
  whoami: whoamiCommand,
41
51
  },
42
52
  });
43
53
  // Skip for update/init (they already update) and completions (runs in shell
44
54
  // startup — must stay side-effect free).
45
- const subcommand = process.argv[2];
55
+ const subcommand = process.argv.at(2);
46
56
  if (subcommand && !["update", "init", "completions"].includes(subcommand)) {
47
57
  maybeScheduleAutoUpdate();
48
58
  }
@@ -53,7 +63,7 @@ if (subcommand && !["update", "init", "completions"].includes(subcommand)) {
53
63
  if (subcommand === "factory") {
54
64
  runFactory(process.argv.slice(3));
55
65
  }
56
- if (subcommand === "playtest") {
66
+ if (subcommand === "playtest" && process.argv.at(3) !== "run") {
57
67
  runPlaytest(process.argv.slice(3));
58
68
  }
59
69
  runMain(main);
package/dist/lib/api.d.ts CHANGED
@@ -2,9 +2,9 @@ import type { AppRouter, RouterInputs } from "@repo/api";
2
2
  import type { RouterClient } from "@orpc/server";
3
3
  import type { JsonValue } from "./types.js";
4
4
  /** Authenticated client — requires a saved session token. */
5
- export declare function createClient(): RouterClient<AppRouter>;
5
+ export declare const createClient: () => RouterClient<AppRouter>;
6
6
  /** The oRPC error code on a failed call, or null for non-oRPC failures. */
7
- export declare function authErrorCode(cause: unknown): string | null;
7
+ export declare const authErrorCode: (cause: unknown) => string | null;
8
8
  type ForwardInput = RouterInputs["generate"]["forward"];
9
9
  /**
10
10
  * The single boundary where fal payloads enter the CLI. `generate.forward` is
@@ -12,7 +12,7 @@ type ForwardInput = RouterInputs["generate"]["forward"];
12
12
  * everything downstream narrows with the guards in `types.ts` rather than
13
13
  * asserting a shape at the call site.
14
14
  */
15
- export declare function forwardJson(client: RouterClient<AppRouter>, input: ForwardInput): Promise<JsonValue>;
15
+ export declare const forwardJson: (client: RouterClient<AppRouter>, input: ForwardInput) => Promise<JsonValue>;
16
16
  /** Unauthenticated client — for login flow. */
17
- export declare function createPublicClient(baseUrl: string): RouterClient<AppRouter>;
17
+ export declare const createPublicClient: (baseUrl: string) => RouterClient<AppRouter>;
18
18
  export {};
package/dist/lib/api.js CHANGED
@@ -2,32 +2,26 @@ import { createORPCClient, ORPCError } from "@orpc/client";
2
2
  import { RPCLink } from "@orpc/client/fetch";
3
3
  import { getBaseUrl, getToken } from "./config.js";
4
4
  const makeClient = (baseUrl, token) => createORPCClient(new RPCLink({
5
+ headers: () => (token ? { Authorization: `Bearer ${token}` } : {}),
5
6
  origin: baseUrl,
6
7
  url: "/api/orpc",
7
- headers: () => (token ? { Authorization: `Bearer ${token}` } : {}),
8
8
  }));
9
9
  /** Authenticated client — requires a saved session token. */
10
- export function createClient() {
10
+ export const createClient = () => {
11
11
  const token = getToken();
12
12
  if (!token) {
13
13
  throw new Error("Not logged in. Run `vg login` to authenticate.");
14
14
  }
15
15
  return makeClient(getBaseUrl(), token);
16
- }
16
+ };
17
17
  /** The oRPC error code on a failed call, or null for non-oRPC failures. */
18
- export function authErrorCode(cause) {
19
- return cause instanceof ORPCError ? cause.code : null;
20
- }
18
+ export const authErrorCode = (cause) => cause instanceof ORPCError ? cause.code : null;
21
19
  /**
22
20
  * The single boundary where fal payloads enter the CLI. `generate.forward` is
23
21
  * deliberately untyped per endpoint — it resolves to bare `JsonValue` — so
24
22
  * everything downstream narrows with the guards in `types.ts` rather than
25
23
  * asserting a shape at the call site.
26
24
  */
27
- export async function forwardJson(client, input) {
28
- return await client.generate.forward(input);
29
- }
25
+ export const forwardJson = async (client, input) => await client.generate.forward(input);
30
26
  /** Unauthenticated client — for login flow. */
31
- export function createPublicClient(baseUrl) {
32
- return makeClient(baseUrl);
33
- }
27
+ export const createPublicClient = (baseUrl) => makeClient(baseUrl);