vibedgames 0.0.2 → 0.0.4

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.
@@ -0,0 +1,51 @@
1
+ import { openAsBlob } from "node:fs";
2
+ import { isRecord } from "./types.js";
3
+ /**
4
+ * Upload one local file directly to fal's CDN. The proxy hands us a
5
+ * presigned upload slot (upload_url + file_url) via the `media.forward`
6
+ * storage target; bytes go straight from the client to fal, never
7
+ * through the worker. The returned file_url is a stable fal CDN URL
8
+ * that can be reused across runs without re-uploading.
9
+ */
10
+ export async function uploadFile(client, file) {
11
+ const slot = await client.media.forward.mutate({
12
+ target: "storage",
13
+ method: "POST",
14
+ path: "/storage/upload/initiate",
15
+ body: { content_type: file.contentType, file_name: file.filename },
16
+ });
17
+ const uploadUrl = pickUrl(slot, "upload_url");
18
+ const fileUrl = pickUrl(slot, "file_url");
19
+ const body = await openAsBlob(file.path, { type: file.contentType });
20
+ const res = await fetch(uploadUrl, {
21
+ method: "PUT",
22
+ headers: { "Content-Type": file.contentType },
23
+ body,
24
+ });
25
+ if (!res.ok) {
26
+ const text = await res.text().catch(() => "");
27
+ throw new Error(`Upload failed for ${file.filename}: ${res.status} ${res.statusText} ${text}`);
28
+ }
29
+ return fileUrl;
30
+ }
31
+ function pickUrl(slot, key) {
32
+ if (!isRecord(slot) || typeof slot[key] !== "string" || slot[key].length === 0) {
33
+ throw new Error(`fal storage initiate response missing ${key}.`);
34
+ }
35
+ const value = slot[key];
36
+ // Refuse any non-HTTPS URL even if it comes from a trusted server
37
+ // response — a misconfigured response (or a downgrade attack on the
38
+ // proxy hop) must not silently send user bytes over plain HTTP, and
39
+ // file_url gets passed into later runs where it should stay HTTPS.
40
+ let parsed;
41
+ try {
42
+ parsed = new URL(value);
43
+ }
44
+ catch {
45
+ throw new Error(`fal storage initiate response ${key} is not a valid URL.`);
46
+ }
47
+ if (parsed.protocol !== "https:") {
48
+ throw new Error(`fal storage initiate response ${key} must be HTTPS, got ${parsed.protocol}.`);
49
+ }
50
+ return value;
51
+ }
@@ -0,0 +1,2 @@
1
+ /** Type-guard helpers shared across CLI modules. */
2
+ export declare function isRecord(value: unknown): value is Record<string, unknown>;
@@ -0,0 +1,4 @@
1
+ /** Type-guard helpers shared across CLI modules. */
2
+ export function isRecord(value) {
3
+ return typeof value === "object" && value !== null && !Array.isArray(value);
4
+ }
package/package.json CHANGED
@@ -1,32 +1,36 @@
1
1
  {
2
2
  "name": "vibedgames",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "private": false,
5
- "type": "module",
6
5
  "bin": {
7
6
  "vg": "./dist/index.js"
8
7
  },
9
8
  "files": [
10
9
  "dist"
11
10
  ],
11
+ "type": "module",
12
12
  "dependencies": {
13
- "@trpc/client": "^11.16.0",
14
- "citty": "^0.1.6",
13
+ "@trpc/client": "^11.17.0",
14
+ "citty": "^0.2.2",
15
15
  "consola": "^3.4.2",
16
- "superjson": "^2.2.6"
16
+ "cross-spawn": "^7.0.6",
17
+ "superjson": "^2.2.6",
18
+ "tiged": "^2.12.8"
17
19
  },
18
20
  "devDependencies": {
19
- "@cloudflare/workers-types": "^4.20260408.1",
21
+ "@cloudflare/workers-types": "^4.20260522.1",
20
22
  "@kyh/tsconfig": "^1.1.14",
21
- "@trpc/server": "^11.16.0",
22
- "@types/node": "^25.5.2",
23
- "typescript": "^6.0.2",
23
+ "@trpc/server": "^11.17.0",
24
+ "@types/cross-spawn": "^6.0.6",
25
+ "@types/node": "^25.9.1",
26
+ "typescript": "^6.0.3",
24
27
  "@repo/api": "^0.1.0"
25
28
  },
26
29
  "scripts": {
27
30
  "build": "tsc",
28
31
  "dev": "tsc --watch",
29
32
  "clean": "rm -rf .turbo dist node_modules",
33
+ "test:media": "node --import tsx --test test/media-args.test.ts test/media-download.test.ts test/media-poll.test.ts",
30
34
  "typecheck": "tsc --noEmit"
31
35
  }
32
36
  }
@@ -1 +0,0 @@
1
- export declare const listCommand: import("citty").CommandDef<import("citty").ArgsDef>;
@@ -1,23 +0,0 @@
1
- import { defineCommand } from "citty";
2
- import consola from "consola";
3
- import { createClient } from "../lib/api.js";
4
- export const listCommand = defineCommand({
5
- meta: {
6
- name: "list",
7
- description: "List your games",
8
- },
9
- run: async () => {
10
- const client = createClient();
11
- const { builds } = await client.localGame.listBuilds.query({ limit: 50 });
12
- if (builds.length === 0) {
13
- consola.info("No games found");
14
- return;
15
- }
16
- for (const build of builds) {
17
- const fileCount = build.gameBuildFiles.length;
18
- const updated = new Date(build.updatedAt).toLocaleDateString();
19
- const title = build.title ?? "(untitled)";
20
- consola.log(` ${build.id.slice(0, 8)} ${title} ${fileCount} files ${updated}`);
21
- }
22
- },
23
- });
@@ -1,12 +0,0 @@
1
- export declare const rmCommand: import("citty").CommandDef<{
2
- id: {
3
- type: "positional";
4
- description: string;
5
- required: true;
6
- };
7
- force: {
8
- type: "boolean";
9
- description: string;
10
- default: false;
11
- };
12
- }>;
@@ -1,35 +0,0 @@
1
- import { defineCommand } from "citty";
2
- import consola from "consola";
3
- import { createClient } from "../lib/api.js";
4
- export const rmCommand = defineCommand({
5
- meta: {
6
- name: "rm",
7
- description: "Remove a game",
8
- },
9
- args: {
10
- id: {
11
- type: "positional",
12
- description: "Game build ID to remove",
13
- required: true,
14
- },
15
- force: {
16
- type: "boolean",
17
- description: "Skip confirmation",
18
- default: false,
19
- },
20
- },
21
- run: async ({ args }) => {
22
- if (!args.force) {
23
- const confirmed = await consola.prompt(`Remove game ${args.id}?`, {
24
- type: "confirm",
25
- });
26
- if (!confirmed) {
27
- consola.info("Cancelled");
28
- return;
29
- }
30
- }
31
- const client = createClient();
32
- await client.localGame.deleteBuild.mutate({ buildId: args.id });
33
- consola.success(`Removed ${args.id}`);
34
- },
35
- });
@@ -1,8 +0,0 @@
1
- export declare const skillsCommand: import("citty").CommandDef<{
2
- dir: {
3
- type: "positional";
4
- description: string;
5
- required: false;
6
- default: string;
7
- };
8
- }>;
@@ -1,53 +0,0 @@
1
- import { execSync } from "node:child_process";
2
- import { existsSync, mkdirSync, rmSync } from "node:fs";
3
- import { join } from "node:path";
4
- import { defineCommand } from "citty";
5
- import consola from "consola";
6
- const REPO = "kyh/vibedgames";
7
- const SKILLS_PATH = ".claude/skills";
8
- const BRANCH = "main";
9
- export const skillsCommand = defineCommand({
10
- meta: {
11
- name: "skills",
12
- description: "Install vibedgames Claude Code skills into your project",
13
- },
14
- args: {
15
- dir: {
16
- type: "positional",
17
- description: "Project directory",
18
- required: false,
19
- default: ".",
20
- },
21
- },
22
- run: async ({ args }) => {
23
- const projectDir = args.dir;
24
- const targetDir = join(projectDir, SKILLS_PATH);
25
- const tarballUrl = `https://github.com/${REPO}/archive/refs/heads/${BRANCH}.tar.gz`;
26
- const tmpDir = join(projectDir, ".vg-skills-tmp");
27
- consola.start("Fetching skills from vibedgames...");
28
- try {
29
- // Download and extract just the skills directory
30
- mkdirSync(tmpDir, { recursive: true });
31
- execSync(`curl -sL "${tarballUrl}" | tar xz --strip-components=3 -C "${tmpDir}" "vibedgames-${BRANCH}/${SKILLS_PATH}"`, { stdio: "pipe" });
32
- // Copy to target
33
- mkdirSync(targetDir, { recursive: true });
34
- execSync(`cp -r "${tmpDir}"/* "${targetDir}"/`, { stdio: "pipe" });
35
- // Count skills
36
- const skills = execSync(`ls "${targetDir}"`, { encoding: "utf-8" })
37
- .trim()
38
- .split("\n")
39
- .filter(Boolean);
40
- consola.success(`Installed ${skills.length} skills to ${targetDir}`);
41
- consola.log(` ${skills.join(", ")}`);
42
- }
43
- catch (err) {
44
- consola.error(err instanceof Error ? err.message : String(err));
45
- process.exit(1);
46
- }
47
- finally {
48
- if (existsSync(tmpDir)) {
49
- rmSync(tmpDir, { recursive: true });
50
- }
51
- }
52
- },
53
- });