vibedgames 0.5.0 → 0.5.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.
Files changed (60) hide show
  1. package/LICENSE +21 -0
  2. package/dist/commands/completions.d.ts +1 -1
  3. package/dist/commands/completions.js +21 -20
  4. package/dist/commands/credits.d.ts +5 -5
  5. package/dist/commands/credits.js +43 -33
  6. package/dist/commands/deploy.d.ts +10 -10
  7. package/dist/commands/deploy.js +155 -139
  8. package/dist/commands/factory.d.ts +1 -1
  9. package/dist/commands/factory.js +18 -15
  10. package/dist/commands/fork.d.ts +14 -14
  11. package/dist/commands/fork.js +51 -46
  12. package/dist/commands/generate.js +318 -264
  13. package/dist/commands/init.d.ts +8 -8
  14. package/dist/commands/init.js +31 -24
  15. package/dist/commands/login.js +12 -12
  16. package/dist/commands/logout.js +2 -2
  17. package/dist/commands/new.d.ts +16 -16
  18. package/dist/commands/new.js +153 -142
  19. package/dist/commands/playtest.d.ts +5 -5
  20. package/dist/commands/playtest.js +103 -97
  21. package/dist/commands/update.d.ts +7 -7
  22. package/dist/commands/update.js +20 -17
  23. package/dist/commands/whoami.d.ts +5 -5
  24. package/dist/commands/whoami.js +8 -7
  25. package/dist/index.js +10 -10
  26. package/dist/lib/api.d.ts +4 -4
  27. package/dist/lib/api.js +6 -12
  28. package/dist/lib/archive.d.ts +4 -4
  29. package/dist/lib/archive.js +121 -104
  30. package/dist/lib/codex.d.ts +45 -15
  31. package/dist/lib/codex.js +175 -106
  32. package/dist/lib/config-file.d.ts +6 -6
  33. package/dist/lib/config-file.js +28 -26
  34. package/dist/lib/config.d.ts +8 -8
  35. package/dist/lib/config.js +31 -33
  36. package/dist/lib/manifest.d.ts +3 -3
  37. package/dist/lib/manifest.js +42 -38
  38. package/dist/lib/media-args.d.ts +7 -7
  39. package/dist/lib/media-args.js +113 -95
  40. package/dist/lib/media-download.d.ts +9 -9
  41. package/dist/lib/media-download.js +148 -134
  42. package/dist/lib/media-poll.d.ts +8 -8
  43. package/dist/lib/media-poll.js +32 -27
  44. package/dist/lib/media-upload.d.ts +2 -2
  45. package/dist/lib/media-upload.js +27 -27
  46. package/dist/lib/output.d.ts +27 -12
  47. package/dist/lib/output.js +26 -26
  48. package/dist/lib/package-manager.d.ts +3 -3
  49. package/dist/lib/package-manager.js +27 -22
  50. package/dist/lib/run.d.ts +4 -4
  51. package/dist/lib/run.js +7 -4
  52. package/dist/lib/strict-args.d.ts +4 -4
  53. package/dist/lib/strict-args.js +28 -18
  54. package/dist/lib/types.d.ts +5 -5
  55. package/dist/lib/types.js +9 -12
  56. package/dist/lib/update.d.ts +4 -4
  57. package/dist/lib/update.js +41 -32
  58. package/dist/lib/upload.d.ts +4 -4
  59. package/dist/lib/upload.js +14 -9
  60. package/package.json +16 -16
@@ -1,17 +1,17 @@
1
- export type SourceArchive = {
1
+ export interface SourceArchive {
2
2
  /** absolute path to the temp .tgz */
3
3
  path: string;
4
4
  sha256: string;
5
5
  bytes: number;
6
6
  /** posix relative paths included, for display */
7
7
  files: string[];
8
- };
8
+ }
9
9
  /**
10
10
  * Create a gzipped tar of `root`'s source (respecting .gitignore +
11
11
  * HARD_EXCLUDES) at a temp path. Returns the archive path, its sha256, byte
12
12
  * size, and the list of included files.
13
13
  */
14
- export declare function packSource(root: string, tmpDir: string): Promise<SourceArchive>;
14
+ export declare const packSource: (root: string, tmpDir: string) => Promise<SourceArchive>;
15
15
  /** Extract a gzipped tar into `destDir` (created if needed). tar strips
16
16
  * leading slashes and rejects `..` paths, so extraction stays inside dest. */
17
- export declare function extractSource(archivePath: string, destDir: string): Promise<void>;
17
+ export declare const extractSource: (archivePath: string, destDir: string) => Promise<void>;
@@ -1,6 +1,6 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { copyFileSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync, } from "node:fs";
3
- import { dirname, join, relative, sep } from "node:path";
3
+ import path from "node:path";
4
4
  import ignore from "ignore";
5
5
  import { create as tarCreate, extract as tarExtract } from "tar";
6
6
  import { isJsonObject, isJsonString } from "./types.js";
@@ -45,87 +45,95 @@ const HARD_EXCLUDES = [
45
45
  * negation like `!.env` in a user ignore file can NOT un-exclude a secret.
46
46
  * A path is excluded if EITHER matcher says so.
47
47
  */
48
- function buildIgnorer(root) {
48
+ const buildIgnorer = (root) => {
49
49
  const hard = ignore().add(HARD_EXCLUDES);
50
50
  const user = ignore();
51
51
  for (const name of [".gitignore", ".vibedgamesignore"]) {
52
- const p = join(root, name);
53
- if (existsSync(p))
54
- user.add(readFileSync(p, "utf8"));
52
+ const p = path.join(root, name);
53
+ if (existsSync(p)) {
54
+ user.add(readFileSync(p, "utf-8"));
55
+ }
55
56
  }
56
57
  return (rel) => hard.ignores(rel) || user.ignores(rel);
57
- }
58
+ };
58
59
  /** Walk `root`, returning posix relative paths of files not ignored. Ignored
59
60
  * directories are pruned (not descended into) for speed. */
60
- function collectFiles(root, ignored) {
61
+ const collectFiles = (root, ignored) => {
61
62
  const out = [];
62
63
  const walk = (dir) => {
63
64
  for (const entry of readdirSync(dir, { withFileTypes: true })) {
64
- const abs = join(dir, entry.name);
65
- const rel = relative(root, abs).split(sep).join("/");
66
- if (!rel)
65
+ const abs = path.join(dir, entry.name);
66
+ const rel = path.relative(root, abs).split(path.sep).join("/");
67
+ if (!rel) {
67
68
  continue;
69
+ }
68
70
  // `ignore` matches dirs via a trailing slash; test both forms.
69
71
  if (entry.isDirectory()) {
70
- if (ignored(`${rel}/`) || ignored(rel))
72
+ if (ignored(`${rel}/`) || ignored(rel)) {
71
73
  continue;
74
+ }
72
75
  walk(abs);
73
76
  }
74
77
  else if (entry.isFile()) {
75
- if (ignored(rel))
78
+ if (ignored(rel)) {
76
79
  continue;
80
+ }
77
81
  out.push(rel);
78
82
  }
79
83
  }
80
84
  };
81
85
  walk(root);
82
- return out.sort();
83
- }
84
- /**
85
- * Create a gzipped tar of `root`'s source (respecting .gitignore +
86
- * HARD_EXCLUDES) at a temp path. Returns the archive path, its sha256, byte
87
- * size, and the list of included files.
88
- */
89
- export async function packSource(root, tmpDir) {
90
- const ignored = buildIgnorer(root);
91
- const files = collectFiles(root, ignored);
92
- if (files.length === 0) {
93
- throw new Error("No source files to archive (everything was ignored?).");
94
- }
95
- mkdirSync(tmpDir, { recursive: true });
96
- // If package.json uses pnpm-only protocols (workspace:/catalog:), a forked
97
- // copy wouldn't `npm install` standalone. Rewrite them to concrete installed
98
- // versions in the ARCHIVED package.json only (disk untouched) by staging the
99
- // file list into a temp dir. No protocols → no staging (fast path).
100
- const rewritten = files.includes("package.json") ? rewriteWorkspaceProtocols(root) : null;
101
- let cwd = root;
102
- let stage = null;
103
- if (rewritten) {
104
- stage = mkdtempSync(join(tmpDir, "stage-"));
105
- for (const f of files) {
106
- const dest = join(stage, f);
107
- mkdirSync(dirname(dest), { recursive: true });
108
- copyFileSync(join(root, f), dest);
86
+ return out.toSorted();
87
+ };
88
+ /** Version of an installed dependency, searching node_modules up the tree. */
89
+ const installedVersion = (root, name) => {
90
+ let dir = root;
91
+ while (true) {
92
+ const p = path.join(dir, "node_modules", name, "package.json");
93
+ if (existsSync(p)) {
94
+ try {
95
+ const pkg = JSON.parse(readFileSync(p, "utf-8"));
96
+ const v = isJsonObject(pkg) ? pkg.version : undefined;
97
+ if (isJsonString(v)) {
98
+ return v;
99
+ }
100
+ }
101
+ catch {
102
+ /* fall through to parent */
103
+ }
109
104
  }
110
- writeFileSync(join(stage, "package.json"), rewritten);
111
- cwd = stage;
112
- }
113
- const path = join(tmpDir, `vg-source-${process.pid}-${files.length}.tgz`);
114
- try {
115
- await tarCreate({ gzip: true, file: path, cwd, portable: true }, files);
105
+ const parent = path.dirname(dir);
106
+ if (parent === dir) {
107
+ return null;
108
+ }
109
+ dir = parent;
116
110
  }
117
- finally {
118
- if (stage)
119
- rmSync(stage, { recursive: true, force: true });
111
+ };
112
+ const resolveSpec = (root, name, spec) => {
113
+ if (spec.startsWith("workspace:")) {
114
+ const range = spec.slice("workspace:".length);
115
+ // Explicit range (e.g. workspace:^1.2.3) — keep the literal range.
116
+ if (/\d/u.test(range)) {
117
+ return range;
118
+ }
119
+ const v = installedVersion(root, name);
120
+ if (!v) {
121
+ return null;
122
+ }
123
+ if (range === "~") {
124
+ return `~${v}`;
125
+ }
126
+ if (range === "*") {
127
+ return v;
128
+ // exact pin
129
+ }
130
+ // "" or "^"
131
+ return `^${v}`;
120
132
  }
121
- const buf = readFileSync(path);
122
- return {
123
- path,
124
- sha256: createHash("sha256").update(buf).digest("hex"),
125
- bytes: statSync(path).size,
126
- files,
127
- };
128
- }
133
+ // catalog: / catalog:<name> — resolve to the installed version, caret-pinned.
134
+ const v = installedVersion(root, name);
135
+ return v ? `^${v}` : null;
136
+ };
129
137
  const DEP_FIELDS = ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"];
130
138
  /**
131
139
  * Rewrite `workspace:` / `catalog:` dep specs in package.json to the concrete
@@ -133,26 +141,30 @@ const DEP_FIELDS = ["dependencies", "devDependencies", "peerDependencies", "opti
133
141
  * does — so the forked project installs from npm. Returns the rewritten JSON
134
142
  * string, or null if there's nothing to change (the common standalone case).
135
143
  */
136
- function rewriteWorkspaceProtocols(root) {
144
+ const rewriteWorkspaceProtocols = (root) => {
137
145
  let pkg;
138
146
  try {
139
- pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
147
+ pkg = JSON.parse(readFileSync(path.join(root, "package.json"), "utf-8"));
140
148
  }
141
149
  catch {
142
150
  return null;
143
151
  }
144
- if (!isJsonObject(pkg))
152
+ if (!isJsonObject(pkg)) {
145
153
  return null;
154
+ }
146
155
  let changed = false;
147
156
  for (const field of DEP_FIELDS) {
148
157
  const deps = pkg[field];
149
- if (!isJsonObject(deps))
158
+ if (!isJsonObject(deps)) {
150
159
  continue;
160
+ }
151
161
  for (const [name, spec] of Object.entries(deps)) {
152
- if (!isJsonString(spec))
162
+ if (!isJsonString(spec)) {
153
163
  continue;
154
- if (!spec.startsWith("workspace:") && !spec.startsWith("catalog:"))
164
+ }
165
+ if (!spec.startsWith("workspace:") && !spec.startsWith("catalog:")) {
155
166
  continue;
167
+ }
156
168
  const resolved = resolveSpec(root, name, spec);
157
169
  if (resolved && resolved !== spec) {
158
170
  deps[name] = resolved;
@@ -161,51 +173,56 @@ function rewriteWorkspaceProtocols(root) {
161
173
  }
162
174
  }
163
175
  return changed ? `${JSON.stringify(pkg, null, 2)}\n` : null;
164
- }
165
- function resolveSpec(root, name, spec) {
166
- if (spec.startsWith("workspace:")) {
167
- const range = spec.slice("workspace:".length);
168
- // Explicit range (e.g. workspace:^1.2.3) — keep the literal range.
169
- if (/\d/.test(range))
170
- return range;
171
- const v = installedVersion(root, name);
172
- if (!v)
173
- return null;
174
- if (range === "~")
175
- return `~${v}`;
176
- if (range === "*")
177
- return v; // exact pin
178
- return `^${v}`; // "" or "^"
176
+ };
177
+ /**
178
+ * Create a gzipped tar of `root`'s source (respecting .gitignore +
179
+ * HARD_EXCLUDES) at a temp path. Returns the archive path, its sha256, byte
180
+ * size, and the list of included files.
181
+ */
182
+ export const packSource = async (root, tmpDir) => {
183
+ const ignored = buildIgnorer(root);
184
+ const files = collectFiles(root, ignored);
185
+ if (files.length === 0) {
186
+ throw new Error("No source files to archive (everything was ignored?).");
179
187
  }
180
- // catalog: / catalog:<name> — resolve to the installed version, caret-pinned.
181
- const v = installedVersion(root, name);
182
- return v ? `^${v}` : null;
183
- }
184
- /** Version of an installed dependency, searching node_modules up the tree. */
185
- function installedVersion(root, name) {
186
- let dir = root;
187
- while (true) {
188
- const p = join(dir, "node_modules", name, "package.json");
189
- if (existsSync(p)) {
190
- try {
191
- const pkg = JSON.parse(readFileSync(p, "utf8"));
192
- const v = isJsonObject(pkg) ? pkg.version : undefined;
193
- if (isJsonString(v))
194
- return v;
195
- }
196
- catch {
197
- /* fall through to parent */
198
- }
188
+ mkdirSync(tmpDir, { recursive: true });
189
+ // If package.json uses pnpm-only protocols (workspace:/catalog:), a forked
190
+ // copy wouldn't `npm install` standalone. Rewrite them to concrete installed
191
+ // versions in the ARCHIVED package.json only (disk untouched) by staging the
192
+ // file list into a temp dir. No protocols → no staging (fast path).
193
+ const rewritten = files.includes("package.json") ? rewriteWorkspaceProtocols(root) : null;
194
+ let cwd = root;
195
+ let stage = null;
196
+ if (rewritten) {
197
+ stage = mkdtempSync(path.join(tmpDir, "stage-"));
198
+ for (const f of files) {
199
+ const dest = path.join(stage, f);
200
+ mkdirSync(path.dirname(dest), { recursive: true });
201
+ copyFileSync(path.join(root, f), dest);
199
202
  }
200
- const parent = dirname(dir);
201
- if (parent === dir)
202
- return null;
203
- dir = parent;
203
+ writeFileSync(path.join(stage, "package.json"), rewritten);
204
+ cwd = stage;
205
+ }
206
+ const tarball = path.join(tmpDir, `vg-source-${process.pid}-${files.length}.tgz`);
207
+ try {
208
+ await tarCreate({ cwd, file: tarball, gzip: true, portable: true }, files);
204
209
  }
205
- }
210
+ finally {
211
+ if (stage) {
212
+ rmSync(stage, { force: true, recursive: true });
213
+ }
214
+ }
215
+ const buf = readFileSync(tarball);
216
+ return {
217
+ bytes: statSync(tarball).size,
218
+ files,
219
+ path: tarball,
220
+ sha256: createHash("sha256").update(buf).digest("hex"),
221
+ };
222
+ };
206
223
  /** Extract a gzipped tar into `destDir` (created if needed). tar strips
207
224
  * leading slashes and rejects `..` paths, so extraction stays inside dest. */
208
- export async function extractSource(archivePath, destDir) {
225
+ export const extractSource = async (archivePath, destDir) => {
209
226
  mkdirSync(destDir, { recursive: true });
210
- await tarExtract({ file: archivePath, cwd: destDir });
211
- }
227
+ await tarExtract({ cwd: destDir, file: archivePath });
228
+ };
@@ -1,4 +1,4 @@
1
- import { type JsonObject } from "./types.js";
1
+ import type { JsonObject } from "./types.js";
2
2
  export type Provider = "vibedgames" | "codex";
3
3
  /**
4
4
  * Expected, user-facing failure of the codex provider. Carries a clean
@@ -15,39 +15,69 @@ export declare class CodexError extends Error {
15
15
  });
16
16
  }
17
17
  /**
18
- * Resolve the effective provider from the `--provider` flag, falling back
19
- * to the `VG_GENERATE_PROVIDER` env var and finally the vibedgames
18
+ * Resolve an explicitly named provider from the `--provider` flag, falling
19
+ * back to the `VG_GENERATE_PROVIDER` env var and finally the vibedgames
20
20
  * default. Unknown values throw so a typo (`--provider coddex`) fails
21
- * loudly instead of silently hitting the paid backend.
21
+ * loudly instead of silently hitting the paid backend. `chooseProvider`
22
+ * layers the automatic Codex routing on top of this.
22
23
  */
23
- export declare function resolveProvider(flag?: string): Provider;
24
- export type CodexInput = {
24
+ export declare const resolveProvider: (flag?: string) => Provider;
25
+ /** The OpenAI image family — the models a signed-in Codex plan serves itself. */
26
+ export declare const isOpenAiImageEndpoint: (endpointId: string) => boolean;
27
+ /**
28
+ * The `codex` binary this machine would run: `VG_CODEX_BIN` when set (and
29
+ * present), else the first `codex` on PATH. Null when there is none — the
30
+ * signal that keeps automatic routing on the vibedgames runner.
31
+ */
32
+ export declare const findCodexBinary: (env?: NodeJS.ProcessEnv) => string | null;
33
+ export interface CodexInput {
25
34
  prompt: string;
26
35
  count: number;
27
36
  sizeHint?: string;
28
37
  /** Raw reference values from the input; may be local paths or URLs. */
29
38
  referenceCandidates: string[];
30
- };
39
+ }
31
40
  /**
32
41
  * Pull the fields Codex can act on out of the parsed `run` input. Pure:
33
42
  * no filesystem access, so the reference values are returned verbatim and
34
43
  * resolved to local files later.
35
44
  */
36
- export declare function parseCodexInput(input: JsonObject): CodexInput;
45
+ export declare const parseCodexInput: (input: JsonObject) => CodexInput;
46
+ export interface AutoRouteContext {
47
+ endpointId: string;
48
+ async: boolean;
49
+ input: JsonObject;
50
+ codexInstalled: boolean;
51
+ }
52
+ export interface ProviderChoice {
53
+ provider: Provider;
54
+ /** True when nothing named the provider and Codex was picked for it. */
55
+ auto: boolean;
56
+ }
57
+ /**
58
+ * Pick the backend for one `run`. An explicit `--provider` or
59
+ * `VG_GENERATE_PROVIDER` always wins. Left unset, an OpenAI image endpoint
60
+ * goes to a locally installed Codex CLI — the same model family on the
61
+ * user's own plan, nothing billed to vibedgames — whenever Codex can honour
62
+ * the request (synchronous, local references only). Everything else stays
63
+ * on the vibedgames runner, so video/audio and non-OpenAI image models are
64
+ * unaffected by having Codex installed.
65
+ */
66
+ export declare const chooseProvider: (flag: string | undefined, ctx: AutoRouteContext) => ProviderChoice;
37
67
  /**
38
68
  * Build the natural-language instruction handed to `codex exec`. We pin
39
69
  * exact output filenames and the working directory so the generated
40
70
  * files land somewhere we can deterministically collect them.
41
71
  */
42
- export declare function buildCodexPrompt(input: CodexInput, filenames: string[], hasReferences: boolean): string;
72
+ export declare const buildCodexPrompt: (input: CodexInput, filenames: string[], hasReferences: boolean) => string;
43
73
  /**
44
74
  * Choose the on-disk destination for a collected Codex output, mirroring
45
75
  * the `--download` template semantics used for the vibedgames path
46
76
  * ({index}, {ext}, {request_id} placeholders; bare path treated as a
47
77
  * directory or a literal file by extension).
48
78
  */
49
- export declare function renderLocalTarget(template: string | undefined, index: number, ext: string, requestId: string, count: number): string;
50
- type CodexRun = {
79
+ export declare const renderLocalTarget: (template: string | undefined, index: number, ext: string, requestId: string, count: number) => string;
80
+ interface CodexRun {
51
81
  requestId: string;
52
82
  prompt: string;
53
83
  /** Absolute paths to the images Codex produced, in a stable order. */
@@ -59,7 +89,7 @@ type CodexRun = {
59
89
  * a suppressed logger would vanish.
60
90
  */
61
91
  ignoredReferences: string[];
62
- };
92
+ }
63
93
  /**
64
94
  * Delegate image generation to the local `codex` CLI. Runs
65
95
  * `codex exec` in an isolated temp workspace, then collects the produced
@@ -67,15 +97,15 @@ type CodexRun = {
67
97
  * `generated_images` store). Throws with actionable guidance when Codex
68
98
  * is missing, fails, or produces nothing.
69
99
  */
70
- export declare function generateImagesWithCodex(opts: {
100
+ export declare const generateImagesWithCodex: (opts: {
71
101
  input: JsonObject;
72
- }): Promise<CodexRun>;
102
+ }) => Promise<CodexRun>;
73
103
  /**
74
104
  * Copy Codex's raw outputs to their final destinations per the
75
105
  * `--download` template (or default cwd naming). Returns the written
76
106
  * paths and any per-file failures.
77
107
  */
78
- export declare function placeCodexOutputs(rawFiles: string[], template: string | undefined, requestId: string): {
108
+ export declare const placeCodexOutputs: (rawFiles: string[], template: string | undefined, requestId: string) => {
79
109
  downloaded: string[];
80
110
  failed: {
81
111
  url: string;