vibedgames 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -13
- package/dist/commands/credits.d.ts +6 -0
- package/dist/commands/credits.js +143 -0
- package/dist/commands/deploy.d.ts +2 -2
- package/dist/commands/deploy.js +24 -5
- package/dist/commands/factory.d.ts +3 -0
- package/dist/commands/factory.js +70 -0
- package/dist/commands/generate.js +94 -1
- package/dist/commands/whoami.js +18 -14
- package/dist/index.js +11 -1
- package/dist/lib/codex.d.ts +84 -0
- package/dist/lib/codex.js +347 -0
- package/dist/lib/media-args.js +8 -1
- package/dist/lib/media-download.d.ts +1 -0
- package/dist/lib/media-download.js +3 -1
- package/package.json +11 -11
- package/dist/.tsbuildinfo +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
# vibedgames (CLI)
|
|
2
2
|
|
|
3
|
-
CLI
|
|
3
|
+
The `vg` CLI is designed to be driven by a coding agent, not a human. A human
|
|
4
|
+
prompts their agent ("build me a bomberman game"); the agent runs `vg` + the
|
|
5
|
+
bundled skills to scaffold, generate assets, add multiplayer, and deploy.
|
|
6
|
+
Machine-readable output (`--json`), deterministic exit codes, and self-describing
|
|
7
|
+
errors are first-class — optimised so an agent never gets stuck on friction a
|
|
8
|
+
human would tolerate.
|
|
4
9
|
|
|
5
10
|
## Install
|
|
6
11
|
|
|
@@ -17,39 +22,62 @@ vg new <slug> --engine react-r3f # scaffold a React + R3F + drei + Vite + TS sta
|
|
|
17
22
|
vg new <slug> --engine none # minimal Vite + TS + canvas (offline; inline)
|
|
18
23
|
vg new <slug> --template owner/repo # any github degit spec
|
|
19
24
|
vg new <slug> --here # scaffold into the current directory
|
|
20
|
-
vg init [
|
|
25
|
+
vg init [--global] [--agents …] # install/update the vibedgames skills + CLI
|
|
26
|
+
vg update # update the CLI and installed skills to latest
|
|
21
27
|
vg login # authenticate via browser
|
|
22
28
|
vg logout # clear credentials
|
|
23
29
|
vg whoami # show current user
|
|
24
30
|
vg deploy [dir] # deploy a game directory (reads vibedgames.json or --slug)
|
|
31
|
+
vg fork <slug> [target] # fork a project's shipped source under a new slug
|
|
32
|
+
vg credits # credit balance + recent usage
|
|
33
|
+
vg factory [args…] # autonomous game agent (optional plugin, installs on first use)
|
|
34
|
+
vg completions <bash|zsh|fish> # print shell completions
|
|
25
35
|
|
|
26
36
|
vg generate run <model> [params] # run a generative model (waits for result)
|
|
27
37
|
vg generate models [query] # search/list available models
|
|
28
38
|
vg generate schema <model> # fetch a model's input/output schema
|
|
29
39
|
vg generate pricing <model> # fetch pricing for a model
|
|
30
|
-
vg generate status <model> <id> # check an async request
|
|
40
|
+
vg generate status <model> <id> # check an async request (--result, --cancel)
|
|
31
41
|
vg generate upload <file> # upload an asset, get a URL
|
|
32
42
|
vg generate docs <query> # search generative-model documentation
|
|
33
43
|
```
|
|
34
44
|
|
|
35
|
-
|
|
45
|
+
Most commands support `--json` for machine-readable output.
|
|
46
|
+
|
|
47
|
+
`vg init` shells out to `npx skills add kyh/vibedgames` and installs for Claude
|
|
48
|
+
Code, Cursor and Codex by default (symlinked from a shared `.agents/skills/`);
|
|
49
|
+
`--agents` narrows or widens that, `--global` targets the user directory instead
|
|
50
|
+
of the project. `vg update` runs automatically once a day — disable with
|
|
51
|
+
`VG_NO_AUTO_UPDATE=1`.
|
|
52
|
+
|
|
53
|
+
`vg factory` is a pure passthrough to the [factory](../factory) binary, which is
|
|
54
|
+
installed as a platform-specific optional package on first use — the CLI itself
|
|
55
|
+
carries none of it.
|
|
36
56
|
|
|
37
57
|
`vg generate` calls the `generate.forward` tRPC proc — the server holds the
|
|
38
58
|
provider API key, so generation works for any logged-in user with no local keys.
|
|
39
59
|
|
|
40
|
-
## Using with
|
|
60
|
+
## Using with a coding agent
|
|
41
61
|
|
|
42
|
-
Run `vg init` in your project to
|
|
43
|
-
(Phaser, Three.js,
|
|
44
|
-
|
|
62
|
+
Run `vg init` in your project to install the full set of game-building skills
|
|
63
|
+
(design, Phaser, Three.js, asset generation, multiplayer, deploy — see
|
|
64
|
+
[`plugins/`](../../plugins)). The agent picks them up on its next session.
|
|
45
65
|
|
|
46
66
|
## How deploy works
|
|
47
67
|
|
|
48
|
-
1.
|
|
49
|
-
2.
|
|
50
|
-
3.
|
|
51
|
-
4.
|
|
68
|
+
1. Picks the build output (`dist`/`build`/`out`) when the directory is a project root
|
|
69
|
+
2. Walks the directory, hashes files, validates `index.html` exists
|
|
70
|
+
3. Calls `deploy.create` API — gets presigned R2 upload URLs
|
|
71
|
+
4. Uploads files to R2 with bounded concurrency
|
|
72
|
+
5. Calls `deploy.finalize` — game goes live at `{slug}.vibedgames.com`
|
|
73
|
+
|
|
74
|
+
Passing `--source` also uploads a forkable source archive, which is what
|
|
75
|
+
`vg fork <slug>` downloads. It is off by default: the archive is readable by
|
|
76
|
+
any logged-in user, so shipping it is a publish and should be a deliberate act.
|
|
52
77
|
|
|
53
78
|
## Auth
|
|
54
79
|
|
|
55
|
-
Uses a polling flow: CLI generates a code, opens the browser,
|
|
80
|
+
Uses a device-code polling flow: CLI generates a 6-char code, opens the browser,
|
|
81
|
+
polls until the user confirms. Token stored at `~/.config/vg/auth.json`.
|
|
82
|
+
`VG_TOKEN` overrides it (for CI and headless agents) and `VG_API_URL` points the
|
|
83
|
+
CLI at a non-production API.
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { defineCommand } from "citty";
|
|
2
|
+
import consola from "consola";
|
|
3
|
+
import { createClient } from "../lib/api.js";
|
|
4
|
+
import { getToken } from "../lib/config.js";
|
|
5
|
+
const MICRO_PER_USD = 1_000_000;
|
|
6
|
+
const SUB_CENT_MICRO = MICRO_PER_USD / 100;
|
|
7
|
+
const MAX_ENTRIES_SHOWN = 15;
|
|
8
|
+
function isJsonOutput(args) {
|
|
9
|
+
return Boolean(args.json) || process.env.VG_JSON_OUTPUT === "1";
|
|
10
|
+
}
|
|
11
|
+
function writeJson(value) {
|
|
12
|
+
process.stdout.write(JSON.stringify(value, null, 2) + "\n");
|
|
13
|
+
}
|
|
14
|
+
// Dollars from integer micro-USD. Two decimals normally; four when the
|
|
15
|
+
// magnitude is sub-cent so small generation charges don't render as $0.00.
|
|
16
|
+
function formatUsd(micro) {
|
|
17
|
+
const abs = Math.abs(micro);
|
|
18
|
+
const decimals = abs > 0 && abs < SUB_CENT_MICRO ? 4 : 2;
|
|
19
|
+
const base = `$${(abs / MICRO_PER_USD).toFixed(decimals)}`;
|
|
20
|
+
return micro < 0 ? `-${base}` : base;
|
|
21
|
+
}
|
|
22
|
+
function formatSignedUsd(micro) {
|
|
23
|
+
return micro < 0 ? formatUsd(micro) : `+${formatUsd(micro)}`;
|
|
24
|
+
}
|
|
25
|
+
function kindLabel(kind, deltaMicro) {
|
|
26
|
+
switch (kind) {
|
|
27
|
+
case "signup_grant":
|
|
28
|
+
return "Welcome credits";
|
|
29
|
+
case "admin_grant":
|
|
30
|
+
return deltaMicro < 0 ? "Adjustment" : "Credit grant";
|
|
31
|
+
case "generation_hold":
|
|
32
|
+
return "Generation";
|
|
33
|
+
case "generation_settle":
|
|
34
|
+
return "Usage adjustment";
|
|
35
|
+
case "generation_release":
|
|
36
|
+
return "Refund — failed generation";
|
|
37
|
+
default:
|
|
38
|
+
return kind;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// Relative for the last week, short date beyond that.
|
|
42
|
+
function formatWhen(date, now) {
|
|
43
|
+
const minutes = Math.floor((now.getTime() - date.getTime()) / 60_000);
|
|
44
|
+
if (minutes < 1)
|
|
45
|
+
return "just now";
|
|
46
|
+
if (minutes < 60)
|
|
47
|
+
return `${minutes}m ago`;
|
|
48
|
+
const hours = Math.floor(minutes / 60);
|
|
49
|
+
if (hours < 24)
|
|
50
|
+
return `${hours}h ago`;
|
|
51
|
+
const days = Math.floor(hours / 24);
|
|
52
|
+
if (days < 7)
|
|
53
|
+
return `${days}d ago`;
|
|
54
|
+
const opts = { month: "short", day: "numeric" };
|
|
55
|
+
if (date.getFullYear() !== now.getFullYear())
|
|
56
|
+
opts.year = "numeric";
|
|
57
|
+
return date.toLocaleDateString("en-US", opts);
|
|
58
|
+
}
|
|
59
|
+
function authErrorCode(err) {
|
|
60
|
+
if (typeof err === "object" && err !== null && "data" in err) {
|
|
61
|
+
const data = err.data;
|
|
62
|
+
if (typeof data === "object" &&
|
|
63
|
+
data !== null &&
|
|
64
|
+
"code" in data &&
|
|
65
|
+
typeof data.code === "string") {
|
|
66
|
+
return data.code;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
export const creditsCommand = defineCommand({
|
|
72
|
+
meta: {
|
|
73
|
+
name: "credits",
|
|
74
|
+
description: "Show your credit balance and recent usage.",
|
|
75
|
+
},
|
|
76
|
+
args: {
|
|
77
|
+
json: { type: "boolean", description: "Print structured JSON to stdout." },
|
|
78
|
+
},
|
|
79
|
+
run: async ({ args }) => {
|
|
80
|
+
const token = getToken();
|
|
81
|
+
if (!token) {
|
|
82
|
+
consola.warn("Not logged in. Run `vg login` to authenticate.");
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
const client = createClient();
|
|
86
|
+
try {
|
|
87
|
+
const { balanceMicro, entries } = await client.credits.me.query();
|
|
88
|
+
if (isJsonOutput(args)) {
|
|
89
|
+
writeJson({
|
|
90
|
+
balance_micro: balanceMicro,
|
|
91
|
+
balance_usd: balanceMicro / MICRO_PER_USD,
|
|
92
|
+
entries: entries.map((e) => ({
|
|
93
|
+
id: e.id,
|
|
94
|
+
delta_micro: e.deltaMicro,
|
|
95
|
+
kind: e.kind,
|
|
96
|
+
request_id: e.requestId,
|
|
97
|
+
endpoint_id: e.endpointId,
|
|
98
|
+
note: e.note,
|
|
99
|
+
created_at: e.createdAt.toISOString(),
|
|
100
|
+
})),
|
|
101
|
+
});
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
consola.log(`Balance: ${formatUsd(balanceMicro)}`);
|
|
105
|
+
if (entries.length === 0) {
|
|
106
|
+
consola.log("No activity yet.");
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const now = new Date();
|
|
110
|
+
const rows = entries.slice(0, MAX_ENTRIES_SHOWN).map((e) => ({
|
|
111
|
+
amount: formatSignedUsd(e.deltaMicro),
|
|
112
|
+
label: kindLabel(e.kind, e.deltaMicro),
|
|
113
|
+
endpoint: e.endpointId ?? "",
|
|
114
|
+
when: formatWhen(e.createdAt, now),
|
|
115
|
+
}));
|
|
116
|
+
const amountWidth = Math.max(...rows.map((r) => r.amount.length));
|
|
117
|
+
const labelWidth = Math.max(...rows.map((r) => r.label.length));
|
|
118
|
+
const endpointWidth = Math.max(...rows.map((r) => r.endpoint.length));
|
|
119
|
+
consola.log("");
|
|
120
|
+
for (const r of rows) {
|
|
121
|
+
const line = [
|
|
122
|
+
` ${r.amount.padStart(amountWidth)}`,
|
|
123
|
+
r.label.padEnd(labelWidth),
|
|
124
|
+
r.endpoint.padEnd(endpointWidth),
|
|
125
|
+
r.when,
|
|
126
|
+
].join(" ");
|
|
127
|
+
consola.log(line.trimEnd());
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
catch (err) {
|
|
131
|
+
// Only an auth error means "log in"; surface network/server failures as
|
|
132
|
+
// themselves so they aren't mistaken for a bad credential.
|
|
133
|
+
const code = authErrorCode(err);
|
|
134
|
+
if (code === "UNAUTHORIZED" || code === "FORBIDDEN") {
|
|
135
|
+
consola.warn("Not authenticated. Run `vg login`, or check your VG_TOKEN / API key.");
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
consola.error(`Failed to fetch credits: ${err instanceof Error ? err.message : String(err)}`);
|
|
139
|
+
}
|
|
140
|
+
process.exit(1);
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
});
|
|
@@ -12,7 +12,7 @@ export declare const deployCommand: import("citty").CommandDef<{
|
|
|
12
12
|
};
|
|
13
13
|
readonly source: {
|
|
14
14
|
readonly type: "boolean";
|
|
15
|
-
readonly description: "
|
|
16
|
-
readonly default:
|
|
15
|
+
readonly description: "Also upload a forkable source archive, letting anyone logged in fork the project.";
|
|
16
|
+
readonly default: false;
|
|
17
17
|
};
|
|
18
18
|
}>;
|
package/dist/commands/deploy.js
CHANGED
|
@@ -28,8 +28,8 @@ export const deployCommand = defineCommand({
|
|
|
28
28
|
},
|
|
29
29
|
source: {
|
|
30
30
|
type: "boolean",
|
|
31
|
-
description: "
|
|
32
|
-
default:
|
|
31
|
+
description: "Also upload a forkable source archive, letting anyone logged in fork the project.",
|
|
32
|
+
default: false,
|
|
33
33
|
},
|
|
34
34
|
},
|
|
35
35
|
run: async ({ args }) => {
|
|
@@ -38,6 +38,25 @@ export const deployCommand = defineCommand({
|
|
|
38
38
|
consola.error(`Directory does not exist: ${dir}`);
|
|
39
39
|
process.exit(1);
|
|
40
40
|
}
|
|
41
|
+
// Build-tool projects (package.json present): the root index.html is the
|
|
42
|
+
// source template, the playable game lives in the build output. Deploying
|
|
43
|
+
// the root uploads the whole source tree — wrong content and usually over
|
|
44
|
+
// the file caps — so prefer a build directory when one exists. Checked in
|
|
45
|
+
// popularity order: Vite/Rollup/Parcel → CRA/Preact → Next export/esbuild.
|
|
46
|
+
let deployDir = dir;
|
|
47
|
+
if (existsSync(join(dir, "package.json"))) {
|
|
48
|
+
for (const name of ["dist", "build", "out"]) {
|
|
49
|
+
if (existsSync(join(dir, name, "index.html"))) {
|
|
50
|
+
deployDir = join(dir, name);
|
|
51
|
+
consola.info(`Project root detected — deploying its build output ${name}/ instead.`);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (deployDir === dir) {
|
|
56
|
+
consola.warn("This looks like an unbuilt project (package.json, no dist/build/out) — " +
|
|
57
|
+
"run the build first, or the deployed index.html will reference missing source files.");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
41
60
|
// ---- Resolve project config ---------------------------------------------
|
|
42
61
|
let config = null;
|
|
43
62
|
try {
|
|
@@ -75,9 +94,9 @@ export const deployCommand = defineCommand({
|
|
|
75
94
|
process.exit(1);
|
|
76
95
|
}
|
|
77
96
|
// ---- Walk files ---------------------------------------------------------
|
|
78
|
-
const manifest = buildManifest(
|
|
97
|
+
const manifest = buildManifest(deployDir);
|
|
79
98
|
if (manifest.length === 0) {
|
|
80
|
-
consola.error(`No files found in ${
|
|
99
|
+
consola.error(`No files found in ${deployDir}`);
|
|
81
100
|
process.exit(1);
|
|
82
101
|
}
|
|
83
102
|
const hasIndex = manifest.some((f) => f.path === "index.html");
|
|
@@ -87,7 +106,7 @@ export const deployCommand = defineCommand({
|
|
|
87
106
|
}
|
|
88
107
|
const totalBytes = manifest.reduce((acc, f) => acc + f.size, 0);
|
|
89
108
|
consola.info(`Deploying ${config.slug}: ${manifest.length} files, ${formatBytes(totalBytes)}`);
|
|
90
|
-
// ---- Pack forkable source (
|
|
109
|
+
// ---- Pack forkable source (opt-in: source is a publish, --source) -------
|
|
91
110
|
let sourceArchive = null;
|
|
92
111
|
if (args.source) {
|
|
93
112
|
const root = findProjectRoot(dir);
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { defineCommand } from "citty";
|
|
5
|
+
import consola from "consola";
|
|
6
|
+
/**
|
|
7
|
+
* `vg factory` — the autonomous game factory, shipped as an optional plugin.
|
|
8
|
+
* The vg CLI carries none of it: the factory lives in a per-platform npm
|
|
9
|
+
* package (a bun-compiled standalone binary) that gets installed globally on
|
|
10
|
+
* first use, then every invocation just execs it with the args passed
|
|
11
|
+
* through. index.ts routes `vg factory …` here BEFORE citty parses anything,
|
|
12
|
+
* so even `--help`/`--version` reach the binary untouched; the citty command
|
|
13
|
+
* below exists only so `vg --help` lists the subcommand.
|
|
14
|
+
*/
|
|
15
|
+
const PKG = `@vibedgames/factory-${process.platform}-${process.arch}`;
|
|
16
|
+
const BIN = process.platform === "win32" ? "vg-factory.exe" : "vg-factory";
|
|
17
|
+
function npmGlobalRoot() {
|
|
18
|
+
try {
|
|
19
|
+
const res = spawnSync("npm", ["root", "-g"], { encoding: "utf8", timeout: 30_000 });
|
|
20
|
+
if (res.status !== 0 || res.error !== undefined)
|
|
21
|
+
return null;
|
|
22
|
+
const root = res.stdout.trim();
|
|
23
|
+
return root || null;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** The installed factory binary, or null. VG_FACTORY_BIN overrides (dev). */
|
|
30
|
+
function findBinary() {
|
|
31
|
+
const override = process.env.VG_FACTORY_BIN;
|
|
32
|
+
if (override)
|
|
33
|
+
return existsSync(override) ? override : null;
|
|
34
|
+
const root = npmGlobalRoot();
|
|
35
|
+
if (!root)
|
|
36
|
+
return null;
|
|
37
|
+
const path = join(root, PKG, "bin", BIN);
|
|
38
|
+
return existsSync(path) ? path : null;
|
|
39
|
+
}
|
|
40
|
+
/** Resolve (installing on first use) and exec the factory. Never returns. */
|
|
41
|
+
export function runFactory(args) {
|
|
42
|
+
let bin = findBinary();
|
|
43
|
+
if (!bin) {
|
|
44
|
+
consola.start(`Installing the factory (${PKG})…`);
|
|
45
|
+
const install = spawnSync("npm", ["install", "-g", PKG], { stdio: "inherit" });
|
|
46
|
+
if (install.status !== 0 || install.error !== undefined) {
|
|
47
|
+
consola.error(`Couldn't install the factory. Try manually: npm install -g ${PKG}`);
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
bin = findBinary();
|
|
51
|
+
if (!bin) {
|
|
52
|
+
consola.error(`Installed ${PKG} but couldn't find its binary under npm's global root. Check \`npm root -g\`.`);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
consola.success("Factory installed.");
|
|
56
|
+
}
|
|
57
|
+
const result = spawnSync(bin, args, { stdio: "inherit" });
|
|
58
|
+
process.exit(result.status ?? 1);
|
|
59
|
+
}
|
|
60
|
+
export const factoryCommand = defineCommand({
|
|
61
|
+
meta: {
|
|
62
|
+
name: "factory",
|
|
63
|
+
description: "Run the vibedgames factory — an autonomous agent that builds a browser game and evolves it like a studio (optional plugin; installs on first use). All arguments are passed through: `vg factory` opens the dashboard, `vg factory start <slug>` resumes a game.",
|
|
64
|
+
},
|
|
65
|
+
run: ({ rawArgs }) => {
|
|
66
|
+
// Normally unreachable (index.ts routes `vg factory` before citty), but
|
|
67
|
+
// keeps the command functional if invoked programmatically.
|
|
68
|
+
runFactory(rawArgs);
|
|
69
|
+
},
|
|
70
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { defineCommand } from "citty";
|
|
2
2
|
import consola from "consola";
|
|
3
3
|
import { createClient } from "../lib/api.js";
|
|
4
|
+
import { CodexError, generateImagesWithCodex, placeCodexOutputs, resolveProvider, } from "../lib/codex.js";
|
|
4
5
|
import { parseDownloadFlag, parseRunInput, readExplicitLocalFile } from "../lib/media-args.js";
|
|
5
6
|
import { downloadMedia, extractMediaRefs } from "../lib/media-download.js";
|
|
6
7
|
import { endpointPath, queueAppId, waitForCompletion } from "../lib/media-poll.js";
|
|
@@ -44,6 +45,10 @@ const runCommand = defineCommand({
|
|
|
44
45
|
type: "boolean",
|
|
45
46
|
description: "Submit to queue and return request_id without waiting.",
|
|
46
47
|
},
|
|
48
|
+
provider: {
|
|
49
|
+
type: "string",
|
|
50
|
+
description: "Execution backend: vibedgames (default) or codex (delegate image generation to the local Codex CLI / your Codex plan). Also settable via VG_GENERATE_PROVIDER.",
|
|
51
|
+
},
|
|
47
52
|
download: {
|
|
48
53
|
type: "string",
|
|
49
54
|
description: "Download media from result. Optional value is a path or template with {index},{name},{ext},{request_id}.",
|
|
@@ -56,8 +61,13 @@ const runCommand = defineCommand({
|
|
|
56
61
|
// parseRunInput already skips non-`--` tokens, so the positional
|
|
57
62
|
// endpoint_id and any subcommand name in argv are no-ops.
|
|
58
63
|
const finalInput = parseRunInput(rawArgs);
|
|
59
|
-
const client = createClient();
|
|
60
64
|
const endpoint_id = args.endpoint_id;
|
|
65
|
+
const provider = resolveProvider(args.provider);
|
|
66
|
+
if (provider === "codex") {
|
|
67
|
+
await runViaCodex({ args, finalInput, downloadFlag, endpoint_id });
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const client = createClient();
|
|
61
71
|
const submission = await client.generate.forward.mutate({
|
|
62
72
|
target: "queue",
|
|
63
73
|
method: "POST",
|
|
@@ -128,6 +138,66 @@ const runCommand = defineCommand({
|
|
|
128
138
|
}
|
|
129
139
|
},
|
|
130
140
|
});
|
|
141
|
+
// Delegate image generation to the local Codex CLI instead of the
|
|
142
|
+
// vibedgames model runner. Produces local files directly (Codex writes
|
|
143
|
+
// to disk), so there's no queue, no request polling, and no vibedgames
|
|
144
|
+
// backend call. The `--download` template still controls output naming;
|
|
145
|
+
// without it we default to cwd.
|
|
146
|
+
async function runViaCodex(opts) {
|
|
147
|
+
const { args, finalInput, downloadFlag, endpoint_id } = opts;
|
|
148
|
+
if (args.async) {
|
|
149
|
+
consola.error("--async is not supported with --provider codex (Codex runs synchronously).");
|
|
150
|
+
process.exit(1);
|
|
151
|
+
}
|
|
152
|
+
let result;
|
|
153
|
+
try {
|
|
154
|
+
result = await generateImagesWithCodex({ input: finalInput });
|
|
155
|
+
}
|
|
156
|
+
catch (err) {
|
|
157
|
+
if (err instanceof CodexError) {
|
|
158
|
+
// Expected, user-facing failure (codex missing / declined / exec
|
|
159
|
+
// error). Present it cleanly with a deterministic exit code instead
|
|
160
|
+
// of an unhandled stack trace — consola.error goes to stderr, so it
|
|
161
|
+
// never corrupts a --json consumer's stdout. Codex's own output
|
|
162
|
+
// already streamed straight to stderr as it ran (and the message
|
|
163
|
+
// already names the vibedgames fallback), so we don't reprint here.
|
|
164
|
+
consola.error(err.message);
|
|
165
|
+
process.exit(1);
|
|
166
|
+
}
|
|
167
|
+
throw err;
|
|
168
|
+
}
|
|
169
|
+
const { requestId, rawFiles, prompt, ignoredReferences } = result;
|
|
170
|
+
// Warn about dropped (non-local) references on stderr regardless of
|
|
171
|
+
// --json/--quiet — stderr never corrupts the JSON payload — and also
|
|
172
|
+
// record them in the JSON so an agent parsing stdout sees the signal.
|
|
173
|
+
for (const ref of ignoredReferences) {
|
|
174
|
+
consola.warn(`Ignored non-local reference (codex needs a local file path): ${ref}`);
|
|
175
|
+
}
|
|
176
|
+
const template = downloadFlag.mode === "on" ? downloadFlag.template : undefined;
|
|
177
|
+
const { downloaded, failed } = placeCodexOutputs(rawFiles, template, requestId);
|
|
178
|
+
const payload = {
|
|
179
|
+
status: "completed",
|
|
180
|
+
provider: "codex",
|
|
181
|
+
endpoint_id,
|
|
182
|
+
request_id: requestId,
|
|
183
|
+
result: { provider: "codex", prompt, images: downloaded.map((path) => ({ path })) },
|
|
184
|
+
downloaded_files: downloaded,
|
|
185
|
+
...(failed.length > 0 ? { download_failures: failed } : {}),
|
|
186
|
+
...(ignoredReferences.length > 0 ? { ignored_references: ignoredReferences } : {}),
|
|
187
|
+
};
|
|
188
|
+
if (isJsonOutput(args)) {
|
|
189
|
+
writeJson(payload);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
consola.success(`Codex generated ${downloaded.length} image(s) (${requestId})`);
|
|
193
|
+
for (const path of downloaded)
|
|
194
|
+
consola.log(` ${path}`);
|
|
195
|
+
for (const f of failed)
|
|
196
|
+
consola.warn(` failed: ${f.url} (${f.error})`);
|
|
197
|
+
}
|
|
198
|
+
if (failed.length > 0 && downloaded.length === 0)
|
|
199
|
+
process.exit(1);
|
|
200
|
+
}
|
|
131
201
|
// ---- status -----------------------------------------------------------------
|
|
132
202
|
const statusCommand = defineCommand({
|
|
133
203
|
meta: {
|
|
@@ -171,6 +241,29 @@ const statusCommand = defineCommand({
|
|
|
171
241
|
path,
|
|
172
242
|
query: action === "status" && args.logs ? { logs: "1" } : undefined,
|
|
173
243
|
});
|
|
244
|
+
// Cancellation is confirmed asynchronously, and the platform refunds a
|
|
245
|
+
// cancelled job's credit hold when a status poll reports the terminal
|
|
246
|
+
// state — so confirm with a few polls instead of leaving the refund to
|
|
247
|
+
// whenever the user next checks. Best-effort: a miss just defers it.
|
|
248
|
+
if (action === "cancel") {
|
|
249
|
+
const statusPath = `/${ep}/requests/${args.request_id}/status`;
|
|
250
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
251
|
+
await new Promise((resolve) => setTimeout(resolve, 1_000));
|
|
252
|
+
try {
|
|
253
|
+
const poll = await client.generate.forward.mutate({
|
|
254
|
+
target: "queue",
|
|
255
|
+
method: "GET",
|
|
256
|
+
path: statusPath,
|
|
257
|
+
});
|
|
258
|
+
const status = isRecord(poll) && typeof poll.status === "string" ? poll.status.toUpperCase() : "";
|
|
259
|
+
if (["CANCELLED", "FAILED", "COMPLETED"].includes(status))
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
catch {
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
174
267
|
let downloaded;
|
|
175
268
|
if (action === "result" && downloadFlag.mode === "on") {
|
|
176
269
|
const refs = extractMediaRefs(data);
|
package/dist/commands/whoami.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { defineCommand } from "citty";
|
|
2
2
|
import consola from "consola";
|
|
3
|
-
import {
|
|
3
|
+
import { createClient } from "../lib/api.js";
|
|
4
|
+
import { getToken } from "../lib/config.js";
|
|
4
5
|
export const whoamiCommand = defineCommand({
|
|
5
6
|
meta: {
|
|
6
7
|
name: "whoami",
|
|
@@ -12,21 +13,24 @@ export const whoamiCommand = defineCommand({
|
|
|
12
13
|
consola.warn("Not logged in. Run `vg login` to authenticate.");
|
|
13
14
|
process.exit(1);
|
|
14
15
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (!res.ok) {
|
|
22
|
-
consola.error("Failed to fetch session. Try `vg login` again.");
|
|
23
|
-
process.exit(1);
|
|
16
|
+
// Goes through tRPC (not the raw better-auth endpoint) so it resolves
|
|
17
|
+
// both session tokens and `vg_…` API keys.
|
|
18
|
+
const client = createClient();
|
|
19
|
+
try {
|
|
20
|
+
const user = await client.auth.me.query();
|
|
21
|
+
consola.log(`${user.name} (${user.email})`);
|
|
24
22
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
catch (err) {
|
|
24
|
+
// Only an auth error means "log in"; surface network/server failures as
|
|
25
|
+
// themselves so they aren't mistaken for a bad credential.
|
|
26
|
+
const code = err?.data?.code;
|
|
27
|
+
if (code === "UNAUTHORIZED" || code === "FORBIDDEN") {
|
|
28
|
+
consola.warn("Not authenticated. Run `vg login`, or check your VG_TOKEN / API key.");
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
consola.error(`Failed to fetch current user: ${err instanceof Error ? err.message : String(err)}`);
|
|
32
|
+
}
|
|
28
33
|
process.exit(1);
|
|
29
34
|
}
|
|
30
|
-
consola.log(`${data.user.name} (${data.user.email})`);
|
|
31
35
|
},
|
|
32
36
|
});
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
3
|
import { defineCommand, runMain } from "citty";
|
|
4
4
|
import { completionsCommand } from "./commands/completions.js";
|
|
5
|
+
import { creditsCommand } from "./commands/credits.js";
|
|
5
6
|
import { deployCommand } from "./commands/deploy.js";
|
|
7
|
+
import { factoryCommand, runFactory } from "./commands/factory.js";
|
|
6
8
|
import { forkCommand } from "./commands/fork.js";
|
|
7
9
|
import { generateCommand } from "./commands/generate.js";
|
|
8
10
|
import { initCommand } from "./commands/init.js";
|
|
@@ -17,7 +19,7 @@ const main = defineCommand({
|
|
|
17
19
|
meta: {
|
|
18
20
|
name: "vg",
|
|
19
21
|
version: pkg.version,
|
|
20
|
-
description: "vibedgames CLI",
|
|
22
|
+
description: "vibedgames CLI — agent-native game deploy & asset tooling (use --json for machine-readable output)",
|
|
21
23
|
},
|
|
22
24
|
subCommands: {
|
|
23
25
|
new: newCommand,
|
|
@@ -25,8 +27,10 @@ const main = defineCommand({
|
|
|
25
27
|
login: loginCommand,
|
|
26
28
|
logout: logoutCommand,
|
|
27
29
|
deploy: deployCommand,
|
|
30
|
+
factory: factoryCommand,
|
|
28
31
|
fork: forkCommand,
|
|
29
32
|
generate: generateCommand,
|
|
33
|
+
credits: creditsCommand,
|
|
30
34
|
update: updateCommand,
|
|
31
35
|
completions: completionsCommand,
|
|
32
36
|
whoami: whoamiCommand,
|
|
@@ -38,4 +42,10 @@ const subcommand = process.argv[2];
|
|
|
38
42
|
if (subcommand && !["update", "init", "completions"].includes(subcommand)) {
|
|
39
43
|
maybeScheduleAutoUpdate();
|
|
40
44
|
}
|
|
45
|
+
// `vg factory` is a pure passthrough to the factory plugin binary — route it
|
|
46
|
+
// before citty runs so flags like --help/--version reach the binary instead
|
|
47
|
+
// of being intercepted here. (The registered command keeps it in `vg --help`.)
|
|
48
|
+
if (subcommand === "factory") {
|
|
49
|
+
runFactory(process.argv.slice(3));
|
|
50
|
+
}
|
|
41
51
|
runMain(main);
|