vibedgames 0.3.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 CHANGED
@@ -22,39 +22,62 @@ vg new <slug> --engine react-r3f # scaffold a React + R3F + drei + Vite + TS sta
22
22
  vg new <slug> --engine none # minimal Vite + TS + canvas (offline; inline)
23
23
  vg new <slug> --template owner/repo # any github degit spec
24
24
  vg new <slug> --here # scaffold into the current directory
25
- vg init [dir] # install Claude Code skills into ./.claude/skills
25
+ vg init [--global] [--agents …] # install/update the vibedgames skills + CLI
26
+ vg update # update the CLI and installed skills to latest
26
27
  vg login # authenticate via browser
27
28
  vg logout # clear credentials
28
29
  vg whoami # show current user
29
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
30
35
 
31
36
  vg generate run <model> [params] # run a generative model (waits for result)
32
37
  vg generate models [query] # search/list available models
33
38
  vg generate schema <model> # fetch a model's input/output schema
34
39
  vg generate pricing <model> # fetch pricing for a model
35
- vg generate status <model> <id> # check an async request
40
+ vg generate status <model> <id> # check an async request (--result, --cancel)
36
41
  vg generate upload <file> # upload an asset, get a URL
37
42
  vg generate docs <query> # search generative-model documentation
38
43
  ```
39
44
 
40
- `vg skills install` is an alias for `vg init`. Most commands support `--json` for machine-readable output.
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.
41
56
 
42
57
  `vg generate` calls the `generate.forward` tRPC proc — the server holds the
43
58
  provider API key, so generation works for any logged-in user with no local keys.
44
59
 
45
- ## Using with Claude Code
60
+ ## Using with a coding agent
46
61
 
47
- Run `vg init` in your project to drop the full set of game-building skills
48
- (Phaser, Three.js, Aseprite, asset generation, deploy, etc.) into `./.claude/skills/`.
49
- Claude picks them up automatically on next session.
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.
50
65
 
51
66
  ## How deploy works
52
67
 
53
- 1. Walks the directory, hashes files, validates `index.html` exists
54
- 2. Calls `deploy.create` API — gets presigned R2 upload URLs
55
- 3. Uploads files to R2 with bounded concurrency
56
- 4. Calls `deploy.finalize` — game goes live at `{slug}.vibedgames.com`
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.
57
77
 
58
78
  ## Auth
59
79
 
60
- Uses a polling flow: CLI generates a code, opens the browser, polls until the user confirms. Token stored at `~/.config/vg/auth.json`.
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,6 @@
1
+ export declare const creditsCommand: import("citty").CommandDef<{
2
+ readonly json: {
3
+ readonly type: "boolean";
4
+ readonly description: "Print structured JSON to stdout.";
5
+ };
6
+ }>;
@@ -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: "Upload a forkable source archive alongside the build (use --no-source to skip).";
16
- readonly default: true;
15
+ readonly description: "Also upload a forkable source archive, letting anyone logged in fork the project.";
16
+ readonly default: false;
17
17
  };
18
18
  }>;
@@ -28,8 +28,8 @@ export const deployCommand = defineCommand({
28
28
  },
29
29
  source: {
30
30
  type: "boolean",
31
- description: "Upload a forkable source archive alongside the build (use --no-source to skip).",
32
- default: true,
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 }) => {
@@ -106,7 +106,7 @@ export const deployCommand = defineCommand({
106
106
  }
107
107
  const totalBytes = manifest.reduce((acc, f) => acc + f.size, 0);
108
108
  consola.info(`Deploying ${config.slug}: ${manifest.length} files, ${formatBytes(totalBytes)}`);
109
- // ---- Pack forkable source (default on; --no-source to skip) -------------
109
+ // ---- Pack forkable source (opt-in: source is a publish, --source) -------
110
110
  let sourceArchive = null;
111
111
  if (args.source) {
112
112
  const root = findProjectRoot(dir);
@@ -241,6 +241,29 @@ const statusCommand = defineCommand({
241
241
  path,
242
242
  query: action === "status" && args.logs ? { logs: "1" } : undefined,
243
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
+ }
244
267
  let downloaded;
245
268
  if (action === "result" && downloadFlag.mode === "on") {
246
269
  const refs = extractMediaRefs(data);
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@
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";
6
7
  import { factoryCommand, runFactory } from "./commands/factory.js";
7
8
  import { forkCommand } from "./commands/fork.js";
@@ -29,6 +30,7 @@ const main = defineCommand({
29
30
  factory: factoryCommand,
30
31
  fork: forkCommand,
31
32
  generate: generateCommand,
33
+ credits: creditsCommand,
32
34
  update: updateCommand,
33
35
  completions: completionsCommand,
34
36
  whoami: whoamiCommand,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vibedgames",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "private": false,
5
5
  "bin": {
6
6
  "vg": "./dist/index.js"
@@ -14,14 +14,14 @@
14
14
  "citty": "^0.2.2",
15
15
  "consola": "^3.4.2",
16
16
  "cross-spawn": "^7.0.6",
17
- "ignore": "^7.0.5",
17
+ "ignore": "^7.0.6",
18
18
  "superjson": "^2.2.6",
19
- "tar": "^7.5.19",
19
+ "tar": "^7.5.22",
20
20
  "tiged": "^2.12.8"
21
21
  },
22
22
  "devDependencies": {
23
- "@cloudflare/workers-types": "^5.20260708.1",
24
- "@kyh/tsconfig": "^1.1.14",
23
+ "@cloudflare/workers-types": "^5.20260724.1",
24
+ "@kyh/tsconfig": "^1.2.0",
25
25
  "@trpc/server": "^11.18.0",
26
26
  "@types/cross-spawn": "^6.0.6",
27
27
  "@types/node": "^26.1.1",
@@ -29,10 +29,10 @@
29
29
  "@repo/api": "^0.1.0"
30
30
  },
31
31
  "scripts": {
32
- "build": "tsc",
32
+ "build": "tsc && chmod +x dist/index.js",
33
33
  "dev": "tsc --watch",
34
34
  "clean": "rm -rf .turbo dist node_modules",
35
- "test:media": "node --import tsx --test test/media-args.test.ts test/media-download.test.ts test/media-poll.test.ts test/codex.test.ts",
35
+ "test": "node --import tsx --test test/media-args.test.ts test/media-download.test.ts test/media-poll.test.ts test/codex.test.ts",
36
36
  "typecheck": "tsc --noEmit"
37
37
  }
38
38
  }