vibedgames 0.4.0 → 0.5.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 +1 -1
- package/dist/commands/credits.js +7 -18
- package/dist/commands/deploy.d.ts +8 -0
- package/dist/commands/deploy.js +58 -31
- package/dist/commands/fork.js +30 -24
- package/dist/commands/generate.js +69 -45
- package/dist/commands/init.js +29 -24
- package/dist/commands/login.js +2 -2
- package/dist/commands/new.d.ts +1 -1
- package/dist/commands/new.js +82 -62
- package/dist/commands/playtest.d.ts +12 -0
- package/dist/commands/playtest.js +36 -2
- package/dist/commands/update.js +19 -14
- package/dist/commands/whoami.d.ts +10 -1
- package/dist/commands/whoami.js +12 -5
- package/dist/index.js +2 -0
- package/dist/lib/api.d.ts +16 -4
- package/dist/lib/api.js +22 -28
- package/dist/lib/archive.js +8 -4
- package/dist/lib/codex.d.ts +3 -2
- package/dist/lib/codex.js +8 -7
- package/dist/lib/config-file.js +6 -5
- package/dist/lib/config.js +11 -1
- package/dist/lib/manifest.js +3 -3
- package/dist/lib/media-args.d.ts +4 -2
- package/dist/lib/media-args.js +6 -5
- package/dist/lib/media-download.d.ts +6 -1
- package/dist/lib/media-download.js +54 -10
- package/dist/lib/media-poll.d.ts +3 -2
- package/dist/lib/media-poll.js +11 -10
- package/dist/lib/media-upload.d.ts +1 -1
- package/dist/lib/media-upload.js +5 -4
- package/dist/lib/output.d.ts +12 -4
- package/dist/lib/output.js +11 -3
- package/dist/lib/package-manager.js +1 -1
- package/dist/lib/run.d.ts +9 -1
- package/dist/lib/run.js +8 -3
- package/dist/lib/strict-args.d.ts +27 -0
- package/dist/lib/strict-args.js +68 -0
- package/dist/lib/types.d.ts +16 -2
- package/dist/lib/types.js +12 -3
- package/dist/lib/update.js +8 -5
- package/package.json +16 -17
- package/LICENSE +0 -21
package/dist/commands/login.js
CHANGED
|
@@ -20,7 +20,7 @@ export const loginCommand = defineCommand({
|
|
|
20
20
|
run: async () => {
|
|
21
21
|
const baseUrl = getBaseUrl();
|
|
22
22
|
const client = createPublicClient(baseUrl);
|
|
23
|
-
const { code } = await client.auth.cliInit
|
|
23
|
+
const { code } = await client.auth.cliInit();
|
|
24
24
|
consola.box(`Code: ${code}`);
|
|
25
25
|
consola.info("Opening browser to complete authentication...");
|
|
26
26
|
const authUrl = `${baseUrl}/auth/cli?code=${code}`;
|
|
@@ -28,7 +28,7 @@ export const loginCommand = defineCommand({
|
|
|
28
28
|
consola.start("Waiting for confirmation...");
|
|
29
29
|
for (let i = 0; i < MAX_POLLS; i++) {
|
|
30
30
|
await sleep(POLL_INTERVAL_MS);
|
|
31
|
-
const result = await client.auth.cliPoll
|
|
31
|
+
const result = await client.auth.cliPoll({ code });
|
|
32
32
|
if (result.status === "confirmed") {
|
|
33
33
|
saveConfig({ token: result.token, baseUrl });
|
|
34
34
|
consola.success("Logged in successfully");
|
package/dist/commands/new.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare const newCommand: import("citty").CommandDef<{
|
|
|
6
6
|
};
|
|
7
7
|
readonly engine: {
|
|
8
8
|
readonly type: "string";
|
|
9
|
-
readonly description:
|
|
9
|
+
readonly description: `Engine preset: ${string} (default: phaser).`;
|
|
10
10
|
readonly default: "phaser";
|
|
11
11
|
};
|
|
12
12
|
readonly template: {
|
package/dist/commands/new.js
CHANGED
|
@@ -4,48 +4,62 @@ import { defineCommand } from "citty";
|
|
|
4
4
|
import consola from "consola";
|
|
5
5
|
import tiged from "tiged";
|
|
6
6
|
import { SLUG_RE } from "../lib/config-file.js";
|
|
7
|
-
|
|
7
|
+
import { assertKnownFlags } from "../lib/strict-args.js";
|
|
8
|
+
import { isJsonObject, isJsonString } from "../lib/types.js";
|
|
9
|
+
const ENGINES = new Map([
|
|
8
10
|
// phaserjs/template-vite-ts is the official Phaser 4 + Vite + TypeScript
|
|
9
11
|
// starter (despite the description still saying "Phaser 3" — package.json
|
|
10
12
|
// pins phaser@^4). Pulled fresh on each `vg new`.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
[
|
|
14
|
+
"phaser",
|
|
15
|
+
{
|
|
16
|
+
repo: "phaserjs/template-vite-ts",
|
|
17
|
+
label: "Phaser 4 + Vite + TypeScript (official)",
|
|
18
|
+
skill: "phaser",
|
|
19
|
+
postNotes: [
|
|
20
|
+
"The phaser template ships a `log.js` telemetry shim and uses `vite/config.*.mjs` for build configs — both are upstream, not vibedgames.",
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
],
|
|
19
24
|
// No officially-blessed Three.js starter exists. Using the most-starred
|
|
20
25
|
// community Vite+TS starter that's been kept current.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
[
|
|
27
|
+
"threejs",
|
|
28
|
+
{
|
|
29
|
+
repo: "pachoclo/vite-threejs-ts-template",
|
|
30
|
+
label: "Three.js + Vite + TypeScript (community)",
|
|
31
|
+
skill: "threejs",
|
|
32
|
+
postNotes: [
|
|
33
|
+
"The demo scene (src/scene.ts) wires lil-gui, stats.js and Drag/OrbitControls as a showcase — replace it with your game and drop the debug deps for production.",
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
],
|
|
29
37
|
// React Three Fiber. Same author as the threejs preset — Vite + TS +
|
|
30
38
|
// React 18 + R3F 8 + drei, with leva and r3f-perf wired up for debug.
|
|
31
39
|
// The pmndrs org doesn't ship an official R3F starter (its templates
|
|
32
40
|
// are all Next.js-based), and the highest-starred R3F template on
|
|
33
41
|
// GitHub is still on CRA + React 17, so this is the cleanest current
|
|
34
42
|
// option for an agent.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
[
|
|
44
|
+
"react-r3f",
|
|
45
|
+
{
|
|
46
|
+
repo: "pachoclo/vite-r3f-ts-template",
|
|
47
|
+
label: "React + React Three Fiber + Vite + TypeScript (community)",
|
|
48
|
+
skill: "threejs",
|
|
49
|
+
},
|
|
50
|
+
],
|
|
40
51
|
// Engine-agnostic fallback for "I'll wire it up myself" / non-canvas
|
|
41
52
|
// games. Stays inline so we don't get blocked on a network fetch when
|
|
42
53
|
// the user explicitly asked for a minimal start.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
54
|
+
[
|
|
55
|
+
"none",
|
|
56
|
+
{
|
|
57
|
+
inline: true,
|
|
58
|
+
label: "minimal Vite + TypeScript canvas",
|
|
59
|
+
skill: "deploy",
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
]);
|
|
49
63
|
const NONE_FILES = [
|
|
50
64
|
{
|
|
51
65
|
path: "package.json",
|
|
@@ -95,38 +109,42 @@ const NONE_FILES = [
|
|
|
95
109
|
},
|
|
96
110
|
{ path: ".gitignore", content: () => `node_modules\ndist\n.DS_Store\n` },
|
|
97
111
|
];
|
|
112
|
+
// Derived so `--help` and the error message can't drift from the presets again.
|
|
113
|
+
const ENGINE_IDS = [...ENGINES.keys()];
|
|
114
|
+
const newArgs = {
|
|
115
|
+
slug: {
|
|
116
|
+
type: "positional",
|
|
117
|
+
description: "Lowercase, hyphenated slug — used as the directory name and deploy subdomain.",
|
|
118
|
+
required: true,
|
|
119
|
+
},
|
|
120
|
+
engine: {
|
|
121
|
+
type: "string",
|
|
122
|
+
description: `Engine preset: ${ENGINE_IDS.join(", ")} (default: phaser).`,
|
|
123
|
+
default: "phaser",
|
|
124
|
+
},
|
|
125
|
+
template: {
|
|
126
|
+
type: "string",
|
|
127
|
+
description: "Override the engine preset and fetch from an arbitrary degit spec (e.g. owner/repo, owner/repo#branch). Skips the engine preset entirely.",
|
|
128
|
+
},
|
|
129
|
+
here: {
|
|
130
|
+
type: "boolean",
|
|
131
|
+
description: "Write into the current directory instead of creating <slug>/.",
|
|
132
|
+
default: false,
|
|
133
|
+
},
|
|
134
|
+
force: {
|
|
135
|
+
type: "boolean",
|
|
136
|
+
description: "Overwrite an existing target directory.",
|
|
137
|
+
default: false,
|
|
138
|
+
},
|
|
139
|
+
};
|
|
98
140
|
export const newCommand = defineCommand({
|
|
99
141
|
meta: {
|
|
100
142
|
name: "new",
|
|
101
|
-
description: "Scaffold a new browser game. Pulls an
|
|
143
|
+
description: "Scaffold a new browser game. Pulls an engine template (phaser, threejs, react-r3f) or generates a minimal canvas starter.",
|
|
102
144
|
},
|
|
103
|
-
args:
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
description: "Lowercase, hyphenated slug — used as the directory name and deploy subdomain.",
|
|
107
|
-
required: true,
|
|
108
|
-
},
|
|
109
|
-
engine: {
|
|
110
|
-
type: "string",
|
|
111
|
-
description: "Engine preset: phaser (default), threejs, or none.",
|
|
112
|
-
default: "phaser",
|
|
113
|
-
},
|
|
114
|
-
template: {
|
|
115
|
-
type: "string",
|
|
116
|
-
description: "Override the engine preset and fetch from an arbitrary degit spec (e.g. owner/repo, owner/repo#branch). Skips the engine preset entirely.",
|
|
117
|
-
},
|
|
118
|
-
here: {
|
|
119
|
-
type: "boolean",
|
|
120
|
-
description: "Write into the current directory instead of creating <slug>/.",
|
|
121
|
-
default: false,
|
|
122
|
-
},
|
|
123
|
-
force: {
|
|
124
|
-
type: "boolean",
|
|
125
|
-
description: "Overwrite an existing target directory.",
|
|
126
|
-
default: false,
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
run: async ({ args }) => {
|
|
145
|
+
args: newArgs,
|
|
146
|
+
run: async ({ args, rawArgs }) => {
|
|
147
|
+
assertKnownFlags(rawArgs, newArgs);
|
|
130
148
|
const slug = args.slug.trim().toLowerCase();
|
|
131
149
|
if (!SLUG_RE.test(slug)) {
|
|
132
150
|
consola.error(`Invalid slug: ${args.slug}\n Use lowercase letters, digits, and hyphens (e.g. "asteroid-belt").`);
|
|
@@ -138,9 +156,9 @@ export const newCommand = defineCommand({
|
|
|
138
156
|
label: `custom: ${args.template}`,
|
|
139
157
|
skill: "deploy",
|
|
140
158
|
}
|
|
141
|
-
: ENGINES
|
|
159
|
+
: ENGINES.get(args.engine);
|
|
142
160
|
if (!preset) {
|
|
143
|
-
consola.error(`Unknown engine: ${args.engine}. Use one of: ${
|
|
161
|
+
consola.error(`Unknown engine: ${args.engine}. Use one of: ${ENGINE_IDS.join(", ")}.`);
|
|
144
162
|
process.exit(1);
|
|
145
163
|
}
|
|
146
164
|
const target = args.here ? process.cwd() : resolve(process.cwd(), slug);
|
|
@@ -226,10 +244,10 @@ function ensureTypecheckScript(target) {
|
|
|
226
244
|
return;
|
|
227
245
|
try {
|
|
228
246
|
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
if (
|
|
247
|
+
if (!isJsonObject(pkg))
|
|
248
|
+
return;
|
|
249
|
+
const scripts = isJsonObject(pkg.scripts) ? pkg.scripts : {};
|
|
250
|
+
if (isJsonString(scripts.typecheck))
|
|
233
251
|
return;
|
|
234
252
|
scripts.typecheck = "tsc --noEmit";
|
|
235
253
|
pkg.scripts = scripts;
|
|
@@ -255,6 +273,8 @@ function rewritePackageName(target, slug) {
|
|
|
255
273
|
try {
|
|
256
274
|
const raw = readFileSync(pkgPath, "utf8");
|
|
257
275
|
const pkg = JSON.parse(raw);
|
|
276
|
+
if (!isJsonObject(pkg))
|
|
277
|
+
throw new Error("package.json is not a JSON object");
|
|
258
278
|
pkg.name = slug;
|
|
259
279
|
delete pkg.repository;
|
|
260
280
|
delete pkg.bugs;
|
|
@@ -23,6 +23,18 @@ declare function resolveGameUrl(slug: string | null): string;
|
|
|
23
23
|
*/
|
|
24
24
|
export declare function bareTokens(args: string[]): string[];
|
|
25
25
|
export declare function expandGameFlag(args: string[], resolveUrl?: typeof resolveGameUrl): string[];
|
|
26
|
+
/**
|
|
27
|
+
* agent-browser's session defaults to the literal name `default`, which is
|
|
28
|
+
* shared by every caller on the machine. Two `vg playtest` runs — two projects
|
|
29
|
+
* in two terminals, or two agents on one box — then drive the SAME browser tab:
|
|
30
|
+
* one navigates away mid-run and the other screenshots its page. Scope the
|
|
31
|
+
* session to the project so concurrent playtests can't collide.
|
|
32
|
+
*
|
|
33
|
+
* Left alone when the caller already chose a session, or set one in the
|
|
34
|
+
* environment, or is asking about sessions themselves (`session list` must see
|
|
35
|
+
* every session, not just this project's).
|
|
36
|
+
*/
|
|
37
|
+
export declare function withScopedSession(args: string[], sessionId: () => string): string[];
|
|
26
38
|
/** Resolve (installing on first use) and exec agent-browser. Never returns. */
|
|
27
39
|
export declare function runPlaytest(rawArgs: string[]): never;
|
|
28
40
|
export declare const playtestCommand: import("citty").CommandDef<import("citty").ArgsDef>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
1
2
|
import { existsSync, mkdirSync, statSync, writeFileSync } from "node:fs";
|
|
2
3
|
import { join } from "node:path";
|
|
3
4
|
import { defineCommand } from "citty";
|
|
@@ -5,7 +6,7 @@ import consola from "consola";
|
|
|
5
6
|
import spawn from "cross-spawn";
|
|
6
7
|
import { getBaseUrl, getConfigDir } from "../lib/config.js";
|
|
7
8
|
import { isNewerVersion } from "../lib/update.js";
|
|
8
|
-
import { SLUG_RE, readProjectConfig } from "../lib/config-file.js";
|
|
9
|
+
import { SLUG_RE, findProjectRoot, readProjectConfig } from "../lib/config-file.js";
|
|
9
10
|
/**
|
|
10
11
|
* `vg playtest` — drive a browser to actually play the game.
|
|
11
12
|
*
|
|
@@ -302,9 +303,42 @@ export function expandGameFlag(args, resolveUrl = resolveGameUrl) {
|
|
|
302
303
|
}
|
|
303
304
|
return out;
|
|
304
305
|
}
|
|
306
|
+
/**
|
|
307
|
+
* agent-browser's session defaults to the literal name `default`, which is
|
|
308
|
+
* shared by every caller on the machine. Two `vg playtest` runs — two projects
|
|
309
|
+
* in two terminals, or two agents on one box — then drive the SAME browser tab:
|
|
310
|
+
* one navigates away mid-run and the other screenshots its page. Scope the
|
|
311
|
+
* session to the project so concurrent playtests can't collide.
|
|
312
|
+
*
|
|
313
|
+
* Left alone when the caller already chose a session, or set one in the
|
|
314
|
+
* environment, or is asking about sessions themselves (`session list` must see
|
|
315
|
+
* every session, not just this project's).
|
|
316
|
+
*/
|
|
317
|
+
export function withScopedSession(args, sessionId) {
|
|
318
|
+
if (args.includes("--session") || args.some((a) => a.startsWith("--session=")))
|
|
319
|
+
return args;
|
|
320
|
+
if (process.env.AGENT_BROWSER_SESSION)
|
|
321
|
+
return args;
|
|
322
|
+
const verb = bareTokens(args)[0];
|
|
323
|
+
// No verb means `--help`/`--version`, and `install`/`session` are machine-wide
|
|
324
|
+
// — `session list` has to see every session, not just this project's.
|
|
325
|
+
if (verb === undefined || verb === "session" || verb === "install")
|
|
326
|
+
return args;
|
|
327
|
+
return ["--session", sessionId(), ...args];
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* A stable per-project session name. Keyed on the project root when there is
|
|
331
|
+
* one so every command run from anywhere inside the project shares a browser,
|
|
332
|
+
* and on the cwd otherwise. Hashed because the name lands in a socket path.
|
|
333
|
+
*/
|
|
334
|
+
function projectSessionId() {
|
|
335
|
+
const root = findProjectRoot(process.cwd()) ?? process.cwd();
|
|
336
|
+
const digest = createHash("sha256").update(root).digest("hex").slice(0, 12);
|
|
337
|
+
return `vg-${digest}`;
|
|
338
|
+
}
|
|
305
339
|
/** Resolve (installing on first use) and exec agent-browser. Never returns. */
|
|
306
340
|
export function runPlaytest(rawArgs) {
|
|
307
|
-
const args = expandGameFlag(rawArgs);
|
|
341
|
+
const args = withScopedSession(expandGameFlag(rawArgs), projectSessionId);
|
|
308
342
|
// Bootstrap covers `install` too: on a fresh machine that's the most natural
|
|
309
343
|
// first command, and re-running the provision step it just did is harmless.
|
|
310
344
|
const resolved = resolveBinary();
|
package/dist/commands/update.js
CHANGED
|
@@ -4,7 +4,10 @@ import { defineCommand } from "citty";
|
|
|
4
4
|
import consola from "consola";
|
|
5
5
|
import { detectPackageManager, globalInstallArgs, globalInstallCommand, } from "../lib/package-manager.js";
|
|
6
6
|
import { isMissingCommand, run } from "../lib/run.js";
|
|
7
|
+
import { assertKnownFlags } from "../lib/strict-args.js";
|
|
7
8
|
import { fetchLatestVersion, isNewerVersion } from "../lib/update.js";
|
|
9
|
+
// SAFETY: this is the CLI's own package.json, shipped alongside dist — npm
|
|
10
|
+
// refuses to publish a package without a string `version`.
|
|
8
11
|
const pkg = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8"));
|
|
9
12
|
const skillsUpdateArgs = (global) => {
|
|
10
13
|
const args = ["-y", "skills", "update", "-y"];
|
|
@@ -12,25 +15,27 @@ const skillsUpdateArgs = (global) => {
|
|
|
12
15
|
args.push("-g");
|
|
13
16
|
return args;
|
|
14
17
|
};
|
|
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
|
+
auto: {
|
|
26
|
+
type: "boolean",
|
|
27
|
+
description: "(internal) silent background mode: only update when the registry has a newer version",
|
|
28
|
+
default: false,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
15
31
|
export const updateCommand = defineCommand({
|
|
16
32
|
meta: {
|
|
17
33
|
name: "update",
|
|
18
34
|
description: "Update the vg CLI and vibedgames skills to latest (runs automatically once a day; disable with VG_NO_AUTO_UPDATE=1)",
|
|
19
35
|
},
|
|
20
|
-
args:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
description: "Update skills installed in the user directory instead of the project",
|
|
24
|
-
default: false,
|
|
25
|
-
alias: "g",
|
|
26
|
-
},
|
|
27
|
-
auto: {
|
|
28
|
-
type: "boolean",
|
|
29
|
-
description: "(internal) silent background mode: only update when the registry has a newer version",
|
|
30
|
-
default: false,
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
run: async ({ args }) => {
|
|
36
|
+
args: updateArgs,
|
|
37
|
+
run: async ({ args, rawArgs }) => {
|
|
38
|
+
assertKnownFlags(rawArgs, updateArgs);
|
|
34
39
|
// Upgrade with whatever installed this CLI: another manager would write a
|
|
35
40
|
// second copy into a different global prefix, leaving the one on PATH stale.
|
|
36
41
|
const manager = detectPackageManager(fileURLToPath(import.meta.url));
|
|
@@ -1 +1,10 @@
|
|
|
1
|
-
export declare const whoamiCommand: import("citty").CommandDef<
|
|
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
|
+
readonly field: {
|
|
7
|
+
readonly type: "string";
|
|
8
|
+
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.";
|
|
9
|
+
};
|
|
10
|
+
}>;
|
package/dist/commands/whoami.js
CHANGED
|
@@ -1,29 +1,36 @@
|
|
|
1
1
|
import { defineCommand } from "citty";
|
|
2
2
|
import consola from "consola";
|
|
3
|
-
import { createClient } from "../lib/api.js";
|
|
3
|
+
import { authErrorCode, createClient } from "../lib/api.js";
|
|
4
4
|
import { getToken } from "../lib/config.js";
|
|
5
|
+
import { outputArgs, writeStructured } from "../lib/output.js";
|
|
6
|
+
import { assertKnownFlags } from "../lib/strict-args.js";
|
|
7
|
+
const whoamiArgs = { ...outputArgs };
|
|
5
8
|
export const whoamiCommand = defineCommand({
|
|
6
9
|
meta: {
|
|
7
10
|
name: "whoami",
|
|
8
11
|
description: "Show the currently authenticated user",
|
|
9
12
|
},
|
|
10
|
-
|
|
13
|
+
args: whoamiArgs,
|
|
14
|
+
run: async ({ args, rawArgs }) => {
|
|
15
|
+
assertKnownFlags(rawArgs, whoamiArgs);
|
|
11
16
|
const token = getToken();
|
|
12
17
|
if (!token) {
|
|
13
18
|
consola.warn("Not logged in. Run `vg login` to authenticate.");
|
|
14
19
|
process.exit(1);
|
|
15
20
|
}
|
|
16
|
-
// Goes through
|
|
21
|
+
// Goes through the API (not the raw better-auth endpoint) so it resolves
|
|
17
22
|
// both session tokens and `vg_…` API keys.
|
|
18
23
|
const client = createClient();
|
|
19
24
|
try {
|
|
20
|
-
const user = await client.auth.me
|
|
25
|
+
const user = await client.auth.me();
|
|
26
|
+
if (writeStructured({ id: user.id, name: user.name, email: user.email }, args))
|
|
27
|
+
return;
|
|
21
28
|
consola.log(`${user.name} (${user.email})`);
|
|
22
29
|
}
|
|
23
30
|
catch (err) {
|
|
24
31
|
// Only an auth error means "log in"; surface network/server failures as
|
|
25
32
|
// themselves so they aren't mistaken for a bad credential.
|
|
26
|
-
const code = err
|
|
33
|
+
const code = authErrorCode(err);
|
|
27
34
|
if (code === "UNAUTHORIZED" || code === "FORBIDDEN") {
|
|
28
35
|
consola.warn("Not authenticated. Run `vg login`, or check your VG_TOKEN / API key.");
|
|
29
36
|
}
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,8 @@ import { playtestCommand, runPlaytest } from "./commands/playtest.js";
|
|
|
15
15
|
import { updateCommand } from "./commands/update.js";
|
|
16
16
|
import { whoamiCommand } from "./commands/whoami.js";
|
|
17
17
|
import { maybeScheduleAutoUpdate } from "./lib/update.js";
|
|
18
|
+
// SAFETY: this is the CLI's own package.json, shipped alongside dist — npm
|
|
19
|
+
// refuses to publish a package without a string `version`.
|
|
18
20
|
const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
19
21
|
const main = defineCommand({
|
|
20
22
|
meta: {
|
package/dist/lib/api.d.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
import type { AppRouter } from "@repo/api";
|
|
2
|
-
import type {
|
|
1
|
+
import type { AppRouter, RouterInputs } from "@repo/api";
|
|
2
|
+
import type { RouterClient } from "@orpc/server";
|
|
3
|
+
import type { JsonValue } from "./types.js";
|
|
3
4
|
/** Authenticated client — requires a saved session token. */
|
|
4
|
-
export declare function createClient():
|
|
5
|
+
export declare function createClient(): RouterClient<AppRouter>;
|
|
6
|
+
/** The oRPC error code on a failed call, or null for non-oRPC failures. */
|
|
7
|
+
export declare function authErrorCode(cause: unknown): string | null;
|
|
8
|
+
type ForwardInput = RouterInputs["generate"]["forward"];
|
|
9
|
+
/**
|
|
10
|
+
* The single boundary where fal payloads enter the CLI. `generate.forward` is
|
|
11
|
+
* deliberately untyped per endpoint — it resolves to bare `JsonValue` — so
|
|
12
|
+
* everything downstream narrows with the guards in `types.ts` rather than
|
|
13
|
+
* asserting a shape at the call site.
|
|
14
|
+
*/
|
|
15
|
+
export declare function forwardJson(client: RouterClient<AppRouter>, input: ForwardInput): Promise<JsonValue>;
|
|
5
16
|
/** Unauthenticated client — for login flow. */
|
|
6
|
-
export declare function createPublicClient(baseUrl: string):
|
|
17
|
+
export declare function createPublicClient(baseUrl: string): RouterClient<AppRouter>;
|
|
18
|
+
export {};
|
package/dist/lib/api.js
CHANGED
|
@@ -1,39 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { createORPCClient, ORPCError } from "@orpc/client";
|
|
2
|
+
import { RPCLink } from "@orpc/client/fetch";
|
|
3
3
|
import { getBaseUrl, getToken } from "./config.js";
|
|
4
|
+
const makeClient = (baseUrl, token) => createORPCClient(new RPCLink({
|
|
5
|
+
origin: baseUrl,
|
|
6
|
+
url: "/api/orpc",
|
|
7
|
+
headers: () => (token ? { Authorization: `Bearer ${token}` } : {}),
|
|
8
|
+
}));
|
|
4
9
|
/** Authenticated client — requires a saved session token. */
|
|
5
10
|
export function createClient() {
|
|
6
11
|
const token = getToken();
|
|
7
12
|
if (!token) {
|
|
8
13
|
throw new Error("Not logged in. Run `vg login` to authenticate.");
|
|
9
14
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
return makeClient(getBaseUrl(), token);
|
|
16
|
+
}
|
|
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
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The single boundary where fal payloads enter the CLI. `generate.forward` is
|
|
23
|
+
* deliberately untyped per endpoint — it resolves to bare `JsonValue` — so
|
|
24
|
+
* everything downstream narrows with the guards in `types.ts` rather than
|
|
25
|
+
* asserting a shape at the call site.
|
|
26
|
+
*/
|
|
27
|
+
export async function forwardJson(client, input) {
|
|
28
|
+
return await client.generate.forward(input);
|
|
24
29
|
}
|
|
25
30
|
/** Unauthenticated client — for login flow. */
|
|
26
31
|
export function createPublicClient(baseUrl) {
|
|
27
|
-
|
|
28
|
-
// batch link is fine here — no need for the splitLink dance the
|
|
29
|
-
// authenticated client uses to keep `media.run` mutations off the
|
|
30
|
-
// batched path.
|
|
31
|
-
return createTRPCClient({
|
|
32
|
-
links: [
|
|
33
|
-
httpBatchLink({
|
|
34
|
-
url: `${baseUrl}/api/trpc`,
|
|
35
|
-
transformer: superjson,
|
|
36
|
-
}),
|
|
37
|
-
],
|
|
38
|
-
});
|
|
32
|
+
return makeClient(baseUrl);
|
|
39
33
|
}
|
package/dist/lib/archive.js
CHANGED
|
@@ -3,6 +3,7 @@ import { copyFileSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFile
|
|
|
3
3
|
import { dirname, join, relative, sep } from "node:path";
|
|
4
4
|
import ignore from "ignore";
|
|
5
5
|
import { create as tarCreate, extract as tarExtract } from "tar";
|
|
6
|
+
import { isJsonObject, isJsonString } from "./types.js";
|
|
6
7
|
/**
|
|
7
8
|
* Patterns ALWAYS excluded from a source archive, regardless of .gitignore —
|
|
8
9
|
* build output, VCS internals, and (critically) secrets. Source upload is a
|
|
@@ -140,13 +141,15 @@ function rewriteWorkspaceProtocols(root) {
|
|
|
140
141
|
catch {
|
|
141
142
|
return null;
|
|
142
143
|
}
|
|
144
|
+
if (!isJsonObject(pkg))
|
|
145
|
+
return null;
|
|
143
146
|
let changed = false;
|
|
144
147
|
for (const field of DEP_FIELDS) {
|
|
145
148
|
const deps = pkg[field];
|
|
146
|
-
if (!deps
|
|
149
|
+
if (!isJsonObject(deps))
|
|
147
150
|
continue;
|
|
148
151
|
for (const [name, spec] of Object.entries(deps)) {
|
|
149
|
-
if (
|
|
152
|
+
if (!isJsonString(spec))
|
|
150
153
|
continue;
|
|
151
154
|
if (!spec.startsWith("workspace:") && !spec.startsWith("catalog:"))
|
|
152
155
|
continue;
|
|
@@ -185,8 +188,9 @@ function installedVersion(root, name) {
|
|
|
185
188
|
const p = join(dir, "node_modules", name, "package.json");
|
|
186
189
|
if (existsSync(p)) {
|
|
187
190
|
try {
|
|
188
|
-
const
|
|
189
|
-
|
|
191
|
+
const pkg = JSON.parse(readFileSync(p, "utf8"));
|
|
192
|
+
const v = isJsonObject(pkg) ? pkg.version : undefined;
|
|
193
|
+
if (isJsonString(v))
|
|
190
194
|
return v;
|
|
191
195
|
}
|
|
192
196
|
catch {
|
package/dist/lib/codex.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type JsonObject } from "./types.js";
|
|
1
2
|
export type Provider = "vibedgames" | "codex";
|
|
2
3
|
/**
|
|
3
4
|
* Expected, user-facing failure of the codex provider. Carries a clean
|
|
@@ -32,7 +33,7 @@ export type CodexInput = {
|
|
|
32
33
|
* no filesystem access, so the reference values are returned verbatim and
|
|
33
34
|
* resolved to local files later.
|
|
34
35
|
*/
|
|
35
|
-
export declare function parseCodexInput(input:
|
|
36
|
+
export declare function parseCodexInput(input: JsonObject): CodexInput;
|
|
36
37
|
/**
|
|
37
38
|
* Build the natural-language instruction handed to `codex exec`. We pin
|
|
38
39
|
* exact output filenames and the working directory so the generated
|
|
@@ -67,7 +68,7 @@ type CodexRun = {
|
|
|
67
68
|
* is missing, fails, or produces nothing.
|
|
68
69
|
*/
|
|
69
70
|
export declare function generateImagesWithCodex(opts: {
|
|
70
|
-
input:
|
|
71
|
+
input: JsonObject;
|
|
71
72
|
}): Promise<CodexRun>;
|
|
72
73
|
/**
|
|
73
74
|
* Copy Codex's raw outputs to their final destinations per the
|
package/dist/lib/codex.js
CHANGED
|
@@ -5,6 +5,7 @@ import { basename, dirname, extname, join, resolve } from "node:path";
|
|
|
5
5
|
import spawn from "cross-spawn";
|
|
6
6
|
import { readExplicitLocalFile } from "./media-args.js";
|
|
7
7
|
import { disambiguateTargets } from "./media-download.js";
|
|
8
|
+
import { isJsonNumber, isJsonString } from "./types.js";
|
|
8
9
|
/**
|
|
9
10
|
* Expected, user-facing failure of the codex provider. Carries a clean
|
|
10
11
|
* message plus any output Codex itself emitted, so the caller can present
|
|
@@ -63,7 +64,7 @@ export function parseCodexInput(input) {
|
|
|
63
64
|
let prompt = "";
|
|
64
65
|
for (const key of PROMPT_KEYS) {
|
|
65
66
|
const v = input[key];
|
|
66
|
-
if (
|
|
67
|
+
if (isJsonString(v) && v.trim().length > 0) {
|
|
67
68
|
prompt = v.trim();
|
|
68
69
|
break;
|
|
69
70
|
}
|
|
@@ -71,7 +72,7 @@ export function parseCodexInput(input) {
|
|
|
71
72
|
let count = 1;
|
|
72
73
|
for (const key of COUNT_KEYS) {
|
|
73
74
|
const v = input[key];
|
|
74
|
-
if (
|
|
75
|
+
if (isJsonNumber(v)) {
|
|
75
76
|
count = Math.max(1, Math.min(MAX_IMAGES, Math.floor(v)));
|
|
76
77
|
break;
|
|
77
78
|
}
|
|
@@ -79,11 +80,11 @@ export function parseCodexInput(input) {
|
|
|
79
80
|
const referenceCandidates = [];
|
|
80
81
|
for (const key of REF_KEYS) {
|
|
81
82
|
const v = input[key];
|
|
82
|
-
if (
|
|
83
|
+
if (isJsonString(v))
|
|
83
84
|
referenceCandidates.push(v);
|
|
84
85
|
else if (Array.isArray(v)) {
|
|
85
86
|
for (const item of v)
|
|
86
|
-
if (
|
|
87
|
+
if (isJsonString(item))
|
|
87
88
|
referenceCandidates.push(item);
|
|
88
89
|
}
|
|
89
90
|
}
|
|
@@ -92,15 +93,15 @@ export function parseCodexInput(input) {
|
|
|
92
93
|
function buildSizeHint(input) {
|
|
93
94
|
const parts = [];
|
|
94
95
|
const size = input.image_size ?? input.size;
|
|
95
|
-
if (
|
|
96
|
+
if (isJsonString(size) && size.trim().length > 0)
|
|
96
97
|
parts.push(size.trim());
|
|
97
98
|
const aspect = input.aspect_ratio;
|
|
98
|
-
if (
|
|
99
|
+
if (isJsonString(aspect) && aspect.trim().length > 0) {
|
|
99
100
|
parts.push(`aspect ratio ${aspect.trim()}`);
|
|
100
101
|
}
|
|
101
102
|
const w = input.width;
|
|
102
103
|
const h = input.height;
|
|
103
|
-
if (
|
|
104
|
+
if (isJsonNumber(w) && isJsonNumber(h))
|
|
104
105
|
parts.push(`${w}x${h}px`);
|
|
105
106
|
return parts.length > 0 ? parts.join(", ") : undefined;
|
|
106
107
|
}
|
package/dist/lib/config-file.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { dirname, join, resolve } from "node:path";
|
|
3
|
+
import { isJsonObject, isJsonString } from "./types.js";
|
|
3
4
|
const FILENAME = "vibedgames.json";
|
|
4
5
|
/**
|
|
5
6
|
* The slug grammar every surface must agree on — it is the deploy target, the
|
|
@@ -34,13 +35,13 @@ export function readProjectConfig(dir) {
|
|
|
34
35
|
return null;
|
|
35
36
|
const raw = readFileSync(path, "utf-8");
|
|
36
37
|
const parsed = JSON.parse(raw);
|
|
37
|
-
if (!parsed ||
|
|
38
|
-
typeof parsed !== "object" ||
|
|
39
|
-
!("slug" in parsed) ||
|
|
40
|
-
typeof parsed.slug !== "string") {
|
|
38
|
+
if (!isJsonObject(parsed) || !isJsonString(parsed.slug)) {
|
|
41
39
|
throw new Error(`${FILENAME} is malformed — missing "slug".`);
|
|
42
40
|
}
|
|
43
|
-
|
|
41
|
+
const config = { slug: parsed.slug };
|
|
42
|
+
if (isJsonString(parsed.name))
|
|
43
|
+
config.name = parsed.name;
|
|
44
|
+
return config;
|
|
44
45
|
}
|
|
45
46
|
export function writeProjectConfig(dir, config) {
|
|
46
47
|
const path = join(dir, FILENAME);
|