vibedgames 0.1.0 → 0.3.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 +18 -2
- package/dist/.tsbuildinfo +1 -1
- package/dist/commands/completions.js +3 -0
- package/dist/commands/deploy.js +21 -2
- package/dist/commands/factory.d.ts +3 -0
- package/dist/commands/factory.js +70 -0
- package/dist/commands/generate.js +77 -7
- package/dist/commands/init.js +1 -9
- package/dist/commands/login.js +1 -5
- package/dist/commands/new.js +61 -3
- package/dist/commands/update.d.ts +13 -0
- package/dist/commands/update.js +68 -0
- package/dist/commands/whoami.js +18 -14
- package/dist/index.js +18 -1
- package/dist/lib/codex.d.ts +84 -0
- package/dist/lib/codex.js +347 -0
- package/dist/lib/config.d.ts +1 -0
- package/dist/lib/config.js +1 -1
- package/dist/lib/media-args.js +8 -1
- package/dist/lib/media-download.d.ts +1 -0
- package/dist/lib/media-download.js +24 -4
- package/dist/lib/media-poll.d.ts +1 -1
- package/dist/lib/media-poll.js +3 -3
- package/dist/lib/media-upload.d.ts +1 -1
- package/dist/lib/media-upload.js +2 -2
- package/dist/lib/run.d.ts +5 -0
- package/dist/lib/run.js +9 -0
- package/dist/lib/update.d.ts +10 -0
- package/dist/lib/update.js +98 -0
- package/package.json +8 -8
package/dist/commands/deploy.js
CHANGED
|
@@ -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");
|
|
@@ -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,9 +61,14 @@ 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;
|
|
61
|
-
const
|
|
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();
|
|
71
|
+
const submission = await client.generate.forward.mutate({
|
|
62
72
|
target: "queue",
|
|
63
73
|
method: "POST",
|
|
64
74
|
path: `/${endpointPath(endpoint_id)}`,
|
|
@@ -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: {
|
|
@@ -165,7 +235,7 @@ const statusCommand = defineCommand({
|
|
|
165
235
|
: action === "result"
|
|
166
236
|
? `/${ep}/requests/${args.request_id}`
|
|
167
237
|
: `/${ep}/requests/${args.request_id}/status`;
|
|
168
|
-
const data = await client.
|
|
238
|
+
const data = await client.generate.forward.mutate({
|
|
169
239
|
target: "queue",
|
|
170
240
|
method: action === "cancel" ? "PUT" : "GET",
|
|
171
241
|
path,
|
|
@@ -256,7 +326,7 @@ const modelsCommand = defineCommand({
|
|
|
256
326
|
if (expand.length > 0)
|
|
257
327
|
query.expand = expand;
|
|
258
328
|
const client = createClient();
|
|
259
|
-
const data = await client.
|
|
329
|
+
const data = await client.generate.forward.mutate({
|
|
260
330
|
target: "platform",
|
|
261
331
|
method: "GET",
|
|
262
332
|
path: "/v1/models",
|
|
@@ -305,7 +375,7 @@ const schemaCommand = defineCommand({
|
|
|
305
375
|
run: async ({ args }) => {
|
|
306
376
|
const expand = args.format === "openapi" ? ["openapi-3.0"] : [];
|
|
307
377
|
const client = createClient();
|
|
308
|
-
const data = await client.
|
|
378
|
+
const data = await client.generate.forward.mutate({
|
|
309
379
|
target: "platform",
|
|
310
380
|
method: "GET",
|
|
311
381
|
path: "/v1/models",
|
|
@@ -327,7 +397,7 @@ const pricingCommand = defineCommand({
|
|
|
327
397
|
},
|
|
328
398
|
run: async ({ args }) => {
|
|
329
399
|
const client = createClient();
|
|
330
|
-
const data = await client.
|
|
400
|
+
const data = await client.generate.forward.mutate({
|
|
331
401
|
target: "platform",
|
|
332
402
|
method: "GET",
|
|
333
403
|
path: "/v1/models/pricing",
|
|
@@ -345,7 +415,7 @@ const docsCommand = defineCommand({
|
|
|
345
415
|
},
|
|
346
416
|
run: async ({ args }) => {
|
|
347
417
|
const client = createClient();
|
|
348
|
-
const data = await client.
|
|
418
|
+
const data = await client.generate.forward.mutate({
|
|
349
419
|
target: "docs",
|
|
350
420
|
method: "POST",
|
|
351
421
|
path: "/docs/mcp",
|
package/dist/commands/init.js
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
import { defineCommand } from "citty";
|
|
2
2
|
import consola from "consola";
|
|
3
|
-
import
|
|
3
|
+
import { run } from "../lib/run.js";
|
|
4
4
|
const REPO = "kyh/vibedgames";
|
|
5
5
|
const PKG = "vibedgames";
|
|
6
6
|
const DEFAULT_AGENTS = "claude-code,cursor,codex";
|
|
7
7
|
const description = "Install/update vibedgames skills and the vg CLI";
|
|
8
|
-
const run = (cmd, args) => new Promise((resolve) => {
|
|
9
|
-
const chunks = [];
|
|
10
|
-
const child = spawn(cmd, args, { stdio: ["ignore", "pipe", "pipe"] });
|
|
11
|
-
child.stdout?.on("data", (c) => chunks.push(c));
|
|
12
|
-
child.stderr?.on("data", (c) => chunks.push(c));
|
|
13
|
-
child.on("error", (err) => resolve({ code: 1, output: `${err.message}\n` }));
|
|
14
|
-
child.on("close", (code) => resolve({ code: code ?? 1, output: Buffer.concat(chunks).toString("utf8") }));
|
|
15
|
-
});
|
|
16
8
|
const skillsAddArgs = (agents, global, yes) => {
|
|
17
9
|
const args = ["-y", "skills", "add", REPO];
|
|
18
10
|
for (const agent of agents)
|
package/dist/commands/login.js
CHANGED
|
@@ -6,11 +6,7 @@ import { getBaseUrl, saveConfig } from "../lib/config.js";
|
|
|
6
6
|
const POLL_INTERVAL_MS = 2_000;
|
|
7
7
|
const MAX_POLLS = 150; // 5 min at 2s intervals
|
|
8
8
|
function openBrowser(url) {
|
|
9
|
-
const cmd = process.platform === "darwin"
|
|
10
|
-
? "open"
|
|
11
|
-
: process.platform === "win32"
|
|
12
|
-
? "start"
|
|
13
|
-
: "xdg-open";
|
|
9
|
+
const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
|
|
14
10
|
exec(`${cmd} "${url}"`);
|
|
15
11
|
}
|
|
16
12
|
function sleep(ms) {
|
package/dist/commands/new.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
3
|
import { defineCommand } from "citty";
|
|
4
4
|
import consola from "consola";
|
|
@@ -22,6 +22,9 @@ const ENGINES = {
|
|
|
22
22
|
repo: "pachoclo/vite-threejs-ts-template",
|
|
23
23
|
label: "Three.js + Vite + TypeScript (community)",
|
|
24
24
|
skill: "threejs",
|
|
25
|
+
postNotes: [
|
|
26
|
+
"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.",
|
|
27
|
+
],
|
|
25
28
|
},
|
|
26
29
|
// React Three Fiber. Same author as the threejs preset — Vite + TS +
|
|
27
30
|
// React 18 + R3F 8 + drei, with leva and r3f-perf wired up for debug.
|
|
@@ -130,7 +133,11 @@ export const newCommand = defineCommand({
|
|
|
130
133
|
process.exit(1);
|
|
131
134
|
}
|
|
132
135
|
const preset = args.template
|
|
133
|
-
? {
|
|
136
|
+
? {
|
|
137
|
+
repo: args.template,
|
|
138
|
+
label: `custom: ${args.template}`,
|
|
139
|
+
skill: "deploy",
|
|
140
|
+
}
|
|
134
141
|
: ENGINES[args.engine];
|
|
135
142
|
if (!preset) {
|
|
136
143
|
consola.error(`Unknown engine: ${args.engine}. Use one of: ${Object.keys(ENGINES).join(", ")}.`);
|
|
@@ -158,7 +165,13 @@ export const newCommand = defineCommand({
|
|
|
158
165
|
process.exit(1);
|
|
159
166
|
}
|
|
160
167
|
}
|
|
161
|
-
// Post-process: name + vibedgames.json
|
|
168
|
+
// Post-process: strip template-repo artifacts, then name + vibedgames.json
|
|
169
|
+
// + README link to skills.
|
|
170
|
+
if (!("inline" in preset)) {
|
|
171
|
+
cleanTemplateArtifacts(target);
|
|
172
|
+
ensureViteConfig(target);
|
|
173
|
+
ensureTypecheckScript(target);
|
|
174
|
+
}
|
|
162
175
|
rewritePackageName(target, slug);
|
|
163
176
|
writeVibedgamesJson(target, slug);
|
|
164
177
|
writeReadme(target, slug, preset);
|
|
@@ -181,6 +194,51 @@ async function fetchTemplate(repo, target, force) {
|
|
|
181
194
|
const emitter = tiged(repo, { force, verbose: false, mode: "tar" });
|
|
182
195
|
await emitter.clone(target);
|
|
183
196
|
}
|
|
197
|
+
/** Remove template-repo artifacts that never apply to a scaffolded game:
|
|
198
|
+
* the template's own lockfile (wrong for whatever package manager the user
|
|
199
|
+
* runs) and its CI workflows (reference the template repo, fail elsewhere). */
|
|
200
|
+
function cleanTemplateArtifacts(target) {
|
|
201
|
+
for (const f of ["package-lock.json", "yarn.lock", "pnpm-lock.yaml", "bun.lockb", "bun.lock"]) {
|
|
202
|
+
const p = resolve(target, f);
|
|
203
|
+
if (existsSync(p))
|
|
204
|
+
rmSync(p);
|
|
205
|
+
}
|
|
206
|
+
const gh = resolve(target, ".github");
|
|
207
|
+
if (existsSync(gh))
|
|
208
|
+
rmSync(gh, { recursive: true });
|
|
209
|
+
}
|
|
210
|
+
/** Some templates (threejs) ship no vite config at all, which means no
|
|
211
|
+
* relative `base` — write a minimal one so built asset URLs are relative
|
|
212
|
+
* and the bundle works wherever it's hosted. Never touches templates that
|
|
213
|
+
* bring their own config (phaser uses a vite/ config dir wired into its
|
|
214
|
+
* npm scripts). */
|
|
215
|
+
function ensureViteConfig(target) {
|
|
216
|
+
const hasConfig = ["vite.config.ts", "vite.config.js", "vite.config.mjs"].some((f) => existsSync(resolve(target, f))) || existsSync(resolve(target, "vite"));
|
|
217
|
+
if (hasConfig)
|
|
218
|
+
return;
|
|
219
|
+
writeFileSync(resolve(target, "vite.config.ts"), `import { defineConfig } from "vite";\n\nexport default defineConfig({\n base: "./",\n});\n`);
|
|
220
|
+
}
|
|
221
|
+
/** Agents lean on \`npm run typecheck\` to verify changes without a full
|
|
222
|
+
* build — add it when the template doesn't define one. */
|
|
223
|
+
function ensureTypecheckScript(target) {
|
|
224
|
+
const pkgPath = resolve(target, "package.json");
|
|
225
|
+
if (!existsSync(pkgPath))
|
|
226
|
+
return;
|
|
227
|
+
try {
|
|
228
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
229
|
+
const scripts = typeof pkg.scripts === "object" && pkg.scripts !== null
|
|
230
|
+
? pkg.scripts
|
|
231
|
+
: {};
|
|
232
|
+
if (typeof scripts.typecheck === "string")
|
|
233
|
+
return;
|
|
234
|
+
scripts.typecheck = "tsc --noEmit";
|
|
235
|
+
pkg.scripts = scripts;
|
|
236
|
+
writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
|
|
237
|
+
}
|
|
238
|
+
catch {
|
|
239
|
+
// malformed package.json — rewritePackageName will warn about it
|
|
240
|
+
}
|
|
241
|
+
}
|
|
184
242
|
function writeInlineTemplate(target, slug, force) {
|
|
185
243
|
for (const file of NONE_FILES) {
|
|
186
244
|
const path = resolve(target, file.path);
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
readonly auto: {
|
|
9
|
+
readonly type: "boolean";
|
|
10
|
+
readonly description: "(internal) silent background mode: only update when npm has a newer version";
|
|
11
|
+
readonly default: false;
|
|
12
|
+
};
|
|
13
|
+
}>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { defineCommand } from "citty";
|
|
3
|
+
import consola from "consola";
|
|
4
|
+
import { run } from "../lib/run.js";
|
|
5
|
+
import { fetchLatestVersion, isNewerVersion } from "../lib/update.js";
|
|
6
|
+
const PKG = "vibedgames";
|
|
7
|
+
const pkg = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8"));
|
|
8
|
+
const skillsUpdateArgs = (global) => {
|
|
9
|
+
const args = ["-y", "skills", "update", "-y"];
|
|
10
|
+
if (global)
|
|
11
|
+
args.push("-g");
|
|
12
|
+
return args;
|
|
13
|
+
};
|
|
14
|
+
export const updateCommand = defineCommand({
|
|
15
|
+
meta: {
|
|
16
|
+
name: "update",
|
|
17
|
+
description: "Update the vg CLI and vibedgames skills to latest (runs automatically once a day; disable with VG_NO_AUTO_UPDATE=1)",
|
|
18
|
+
},
|
|
19
|
+
args: {
|
|
20
|
+
global: {
|
|
21
|
+
type: "boolean",
|
|
22
|
+
description: "Update skills installed in the user directory instead of the project",
|
|
23
|
+
default: false,
|
|
24
|
+
alias: "g",
|
|
25
|
+
},
|
|
26
|
+
auto: {
|
|
27
|
+
type: "boolean",
|
|
28
|
+
description: "(internal) silent background mode: only update when npm has a newer version",
|
|
29
|
+
default: false,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
run: async ({ args }) => {
|
|
33
|
+
if (args.auto) {
|
|
34
|
+
const latest = await fetchLatestVersion();
|
|
35
|
+
if (!latest || !isNewerVersion(latest, pkg.version))
|
|
36
|
+
return;
|
|
37
|
+
await Promise.all([
|
|
38
|
+
run("npm", ["install", "-g", PKG]),
|
|
39
|
+
run("npx", skillsUpdateArgs(args.global)),
|
|
40
|
+
]);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
consola.start("Updating the vg CLI and vibedgames skills...");
|
|
44
|
+
const [cli, skills] = await Promise.all([
|
|
45
|
+
run("npm", ["install", "-g", PKG]),
|
|
46
|
+
run("npx", skillsUpdateArgs(args.global)),
|
|
47
|
+
]);
|
|
48
|
+
if (cli.code === 0) {
|
|
49
|
+
consola.success("vg CLI updated to latest");
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
if (cli.output.trim())
|
|
53
|
+
consola.warn(cli.output.trim());
|
|
54
|
+
consola.warn(`Couldn't update the vg CLI (npm exit ${cli.code}). Update manually: npm install -g ${PKG}`);
|
|
55
|
+
}
|
|
56
|
+
if (skills.code === 0) {
|
|
57
|
+
consola.success("Skills updated to latest");
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
if (skills.output.trim())
|
|
61
|
+
consola.warn(skills.output.trim());
|
|
62
|
+
consola.warn(`'skills update' exited with code ${skills.code}. If skills aren't installed here yet, run: vg init`);
|
|
63
|
+
}
|
|
64
|
+
if (cli.code !== 0 && skills.code !== 0) {
|
|
65
|
+
throw new Error("update failed for both the CLI and skills");
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
});
|
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
|
@@ -3,19 +3,22 @@ import { readFileSync } from "node:fs";
|
|
|
3
3
|
import { defineCommand, runMain } from "citty";
|
|
4
4
|
import { completionsCommand } from "./commands/completions.js";
|
|
5
5
|
import { deployCommand } from "./commands/deploy.js";
|
|
6
|
+
import { factoryCommand, runFactory } from "./commands/factory.js";
|
|
6
7
|
import { forkCommand } from "./commands/fork.js";
|
|
7
8
|
import { generateCommand } from "./commands/generate.js";
|
|
8
9
|
import { initCommand } from "./commands/init.js";
|
|
9
10
|
import { loginCommand } from "./commands/login.js";
|
|
10
11
|
import { logoutCommand } from "./commands/logout.js";
|
|
11
12
|
import { newCommand } from "./commands/new.js";
|
|
13
|
+
import { updateCommand } from "./commands/update.js";
|
|
12
14
|
import { whoamiCommand } from "./commands/whoami.js";
|
|
15
|
+
import { maybeScheduleAutoUpdate } from "./lib/update.js";
|
|
13
16
|
const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
14
17
|
const main = defineCommand({
|
|
15
18
|
meta: {
|
|
16
19
|
name: "vg",
|
|
17
20
|
version: pkg.version,
|
|
18
|
-
description: "vibedgames CLI",
|
|
21
|
+
description: "vibedgames CLI — agent-native game deploy & asset tooling (use --json for machine-readable output)",
|
|
19
22
|
},
|
|
20
23
|
subCommands: {
|
|
21
24
|
new: newCommand,
|
|
@@ -23,10 +26,24 @@ const main = defineCommand({
|
|
|
23
26
|
login: loginCommand,
|
|
24
27
|
logout: logoutCommand,
|
|
25
28
|
deploy: deployCommand,
|
|
29
|
+
factory: factoryCommand,
|
|
26
30
|
fork: forkCommand,
|
|
27
31
|
generate: generateCommand,
|
|
32
|
+
update: updateCommand,
|
|
28
33
|
completions: completionsCommand,
|
|
29
34
|
whoami: whoamiCommand,
|
|
30
35
|
},
|
|
31
36
|
});
|
|
37
|
+
// Skip for update/init (they already update) and completions (runs in shell
|
|
38
|
+
// startup — must stay side-effect free).
|
|
39
|
+
const subcommand = process.argv[2];
|
|
40
|
+
if (subcommand && !["update", "init", "completions"].includes(subcommand)) {
|
|
41
|
+
maybeScheduleAutoUpdate();
|
|
42
|
+
}
|
|
43
|
+
// `vg factory` is a pure passthrough to the factory plugin binary — route it
|
|
44
|
+
// before citty runs so flags like --help/--version reach the binary instead
|
|
45
|
+
// of being intercepted here. (The registered command keeps it in `vg --help`.)
|
|
46
|
+
if (subcommand === "factory") {
|
|
47
|
+
runFactory(process.argv.slice(3));
|
|
48
|
+
}
|
|
32
49
|
runMain(main);
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export type Provider = "vibedgames" | "codex";
|
|
2
|
+
/**
|
|
3
|
+
* Expected, user-facing failure of the codex provider. Carries a clean
|
|
4
|
+
* message plus any output Codex itself emitted, so the caller can present
|
|
5
|
+
* it directly instead of dumping a stack trace. `notInstalled` flags the
|
|
6
|
+
* "`codex` binary missing" case so callers can suggest a fallback.
|
|
7
|
+
*/
|
|
8
|
+
export declare class CodexError extends Error {
|
|
9
|
+
readonly notInstalled: boolean;
|
|
10
|
+
readonly output: string;
|
|
11
|
+
constructor(message: string, opts?: {
|
|
12
|
+
notInstalled?: boolean;
|
|
13
|
+
output?: string;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Resolve the effective provider from the `--provider` flag, falling back
|
|
18
|
+
* to the `VG_GENERATE_PROVIDER` env var and finally the vibedgames
|
|
19
|
+
* default. Unknown values throw so a typo (`--provider coddex`) fails
|
|
20
|
+
* loudly instead of silently hitting the paid backend.
|
|
21
|
+
*/
|
|
22
|
+
export declare function resolveProvider(flag?: string): Provider;
|
|
23
|
+
export type CodexInput = {
|
|
24
|
+
prompt: string;
|
|
25
|
+
count: number;
|
|
26
|
+
sizeHint?: string;
|
|
27
|
+
/** Raw reference values from the input; may be local paths or URLs. */
|
|
28
|
+
referenceCandidates: string[];
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Pull the fields Codex can act on out of the parsed `run` input. Pure:
|
|
32
|
+
* no filesystem access, so the reference values are returned verbatim and
|
|
33
|
+
* resolved to local files later.
|
|
34
|
+
*/
|
|
35
|
+
export declare function parseCodexInput(input: Record<string, unknown>): CodexInput;
|
|
36
|
+
/**
|
|
37
|
+
* Build the natural-language instruction handed to `codex exec`. We pin
|
|
38
|
+
* exact output filenames and the working directory so the generated
|
|
39
|
+
* files land somewhere we can deterministically collect them.
|
|
40
|
+
*/
|
|
41
|
+
export declare function buildCodexPrompt(input: CodexInput, filenames: string[], hasReferences: boolean): string;
|
|
42
|
+
/**
|
|
43
|
+
* Choose the on-disk destination for a collected Codex output, mirroring
|
|
44
|
+
* the `--download` template semantics used for the vibedgames path
|
|
45
|
+
* ({index}, {ext}, {request_id} placeholders; bare path treated as a
|
|
46
|
+
* directory or a literal file by extension).
|
|
47
|
+
*/
|
|
48
|
+
export declare function renderLocalTarget(template: string | undefined, index: number, ext: string, requestId: string, count: number): string;
|
|
49
|
+
type CodexRun = {
|
|
50
|
+
requestId: string;
|
|
51
|
+
prompt: string;
|
|
52
|
+
/** Absolute paths to the images Codex produced, in a stable order. */
|
|
53
|
+
rawFiles: string[];
|
|
54
|
+
/**
|
|
55
|
+
* Reference inputs that were dropped because they weren't local files
|
|
56
|
+
* (Codex can only attach on-disk references). Surfaced to the caller so
|
|
57
|
+
* it isn't silently lost — especially under --json, where a warning to
|
|
58
|
+
* a suppressed logger would vanish.
|
|
59
|
+
*/
|
|
60
|
+
ignoredReferences: string[];
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Delegate image generation to the local `codex` CLI. Runs
|
|
64
|
+
* `codex exec` in an isolated temp workspace, then collects the produced
|
|
65
|
+
* images from that workspace (and, as a fallback, from Codex's default
|
|
66
|
+
* `generated_images` store). Throws with actionable guidance when Codex
|
|
67
|
+
* is missing, fails, or produces nothing.
|
|
68
|
+
*/
|
|
69
|
+
export declare function generateImagesWithCodex(opts: {
|
|
70
|
+
input: Record<string, unknown>;
|
|
71
|
+
}): Promise<CodexRun>;
|
|
72
|
+
/**
|
|
73
|
+
* Copy Codex's raw outputs to their final destinations per the
|
|
74
|
+
* `--download` template (or default cwd naming). Returns the written
|
|
75
|
+
* paths and any per-file failures.
|
|
76
|
+
*/
|
|
77
|
+
export declare function placeCodexOutputs(rawFiles: string[], template: string | undefined, requestId: string): {
|
|
78
|
+
downloaded: string[];
|
|
79
|
+
failed: {
|
|
80
|
+
url: string;
|
|
81
|
+
error: string;
|
|
82
|
+
}[];
|
|
83
|
+
};
|
|
84
|
+
export {};
|