vibedgames 0.5.0 → 0.6.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.
Files changed (74) 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-run.d.ts +62 -0
  20. package/dist/commands/playtest-run.js +258 -0
  21. package/dist/commands/playtest.d.ts +41 -6
  22. package/dist/commands/playtest.js +114 -101
  23. package/dist/commands/update.d.ts +7 -7
  24. package/dist/commands/update.js +20 -17
  25. package/dist/commands/whoami.d.ts +5 -5
  26. package/dist/commands/whoami.js +8 -7
  27. package/dist/index.js +21 -11
  28. package/dist/lib/api.d.ts +4 -4
  29. package/dist/lib/api.js +6 -12
  30. package/dist/lib/archive.d.ts +4 -4
  31. package/dist/lib/archive.js +121 -104
  32. package/dist/lib/codex.d.ts +45 -15
  33. package/dist/lib/codex.js +175 -106
  34. package/dist/lib/config-file.d.ts +6 -6
  35. package/dist/lib/config-file.js +28 -26
  36. package/dist/lib/config.d.ts +8 -8
  37. package/dist/lib/config.js +31 -33
  38. package/dist/lib/manifest.d.ts +3 -3
  39. package/dist/lib/manifest.js +42 -38
  40. package/dist/lib/media-args.d.ts +7 -7
  41. package/dist/lib/media-args.js +113 -95
  42. package/dist/lib/media-download.d.ts +9 -9
  43. package/dist/lib/media-download.js +148 -134
  44. package/dist/lib/media-poll.d.ts +8 -8
  45. package/dist/lib/media-poll.js +32 -27
  46. package/dist/lib/media-upload.d.ts +2 -2
  47. package/dist/lib/media-upload.js +27 -27
  48. package/dist/lib/output.d.ts +27 -12
  49. package/dist/lib/output.js +26 -26
  50. package/dist/lib/package-manager.d.ts +3 -3
  51. package/dist/lib/package-manager.js +27 -22
  52. package/dist/lib/playtest/agent.d.ts +188 -0
  53. package/dist/lib/playtest/agent.js +610 -0
  54. package/dist/lib/playtest/browser.d.ts +109 -0
  55. package/dist/lib/playtest/browser.js +219 -0
  56. package/dist/lib/playtest/controls.d.ts +47 -0
  57. package/dist/lib/playtest/controls.js +218 -0
  58. package/dist/lib/playtest/errors.d.ts +9 -0
  59. package/dist/lib/playtest/errors.js +12 -0
  60. package/dist/lib/playtest/keys.d.ts +41 -0
  61. package/dist/lib/playtest/keys.js +157 -0
  62. package/dist/lib/playtest/run.d.ts +193 -0
  63. package/dist/lib/playtest/run.js +408 -0
  64. package/dist/lib/run.d.ts +4 -4
  65. package/dist/lib/run.js +7 -4
  66. package/dist/lib/strict-args.d.ts +4 -4
  67. package/dist/lib/strict-args.js +28 -18
  68. package/dist/lib/types.d.ts +5 -5
  69. package/dist/lib/types.js +9 -12
  70. package/dist/lib/update.d.ts +4 -4
  71. package/dist/lib/update.js +41 -32
  72. package/dist/lib/upload.d.ts +4 -4
  73. package/dist/lib/upload.js +14 -9
  74. package/package.json +16 -16
@@ -2,91 +2,100 @@ import { spawn } from "node:child_process";
2
2
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
3
  import { getConfigDir } from "./config.js";
4
4
  import { isJsonNumber, isJsonObject, isJsonString } from "./types.js";
5
- import { join } from "node:path";
5
+ import path from "node:path";
6
6
  const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;
7
- const VERSION_RE = /^\d+\.\d+\.\d+$/;
8
- function getCachePath() {
9
- return join(getConfigDir(), "update-check.json");
10
- }
11
- function getLastCheckedAt() {
12
- const path = getCachePath();
13
- if (!existsSync(path))
7
+ const VERSION_RE = /^\d+\.\d+\.\d+$/u;
8
+ const getCachePath = () => path.join(getConfigDir(), "update-check.json");
9
+ const getLastCheckedAt = () => {
10
+ const cache = getCachePath();
11
+ if (!existsSync(cache)) {
14
12
  return 0;
13
+ }
15
14
  try {
16
- const data = JSON.parse(readFileSync(path, "utf-8"));
15
+ const data = JSON.parse(readFileSync(cache, "utf-8"));
17
16
  if (isJsonObject(data)) {
18
17
  const ts = data.lastCheckedAt;
19
- if (isJsonNumber(ts))
18
+ if (isJsonNumber(ts)) {
20
19
  return ts;
20
+ }
21
21
  }
22
22
  }
23
23
  catch {
24
24
  // corrupt cache — treat as never checked
25
25
  }
26
26
  return 0;
27
- }
28
- export function markUpdateChecked() {
27
+ };
28
+ export const markUpdateChecked = () => {
29
29
  const dir = getConfigDir();
30
30
  try {
31
- if (!existsSync(dir))
32
- mkdirSync(dir, { recursive: true, mode: 0o700 });
31
+ if (!existsSync(dir)) {
32
+ mkdirSync(dir, { mode: 0o700, recursive: true });
33
+ }
33
34
  writeFileSync(getCachePath(), JSON.stringify({ lastCheckedAt: Date.now() }, null, 2));
34
35
  }
35
36
  catch {
36
37
  // best-effort; worst case we check again next run
37
38
  }
38
- }
39
- export function isNewerVersion(latest, current) {
40
- if (!VERSION_RE.test(latest) || !VERSION_RE.test(current))
39
+ };
40
+ export const isNewerVersion = (latest, current) => {
41
+ if (!VERSION_RE.test(latest) || !VERSION_RE.test(current)) {
41
42
  return false;
43
+ }
42
44
  const a = latest.split(".").map(Number);
43
45
  const b = current.split(".").map(Number);
44
- for (let i = 0; i < 3; i++) {
46
+ for (let i = 0; i < 3; i += 1) {
45
47
  const left = a[i] ?? 0;
46
48
  const right = b[i] ?? 0;
47
- if (left > right)
49
+ if (left > right) {
48
50
  return true;
49
- if (left < right)
51
+ }
52
+ if (left < right) {
50
53
  return false;
54
+ }
51
55
  }
52
56
  return false;
53
- }
54
- export async function fetchLatestVersion() {
57
+ };
58
+ export const fetchLatestVersion = async () => {
55
59
  const registry = process.env.VG_REGISTRY_URL ?? "https://registry.npmjs.org";
56
60
  try {
57
61
  const res = await fetch(`${registry}/vibedgames/latest`, {
58
62
  signal: AbortSignal.timeout(5000),
59
63
  });
60
- if (!res.ok)
64
+ if (!res.ok) {
61
65
  return null;
66
+ }
62
67
  // SAFETY: res.json() is JSON.parse of the response body, which is
63
68
  // structurally JsonValue.
64
69
  const data = (await res.json());
65
70
  if (isJsonObject(data)) {
66
- const version = data.version;
67
- if (isJsonString(version))
71
+ const { version } = data;
72
+ if (isJsonString(version)) {
68
73
  return version;
74
+ }
69
75
  }
70
76
  }
71
77
  catch {
72
78
  // offline or registry down — skip this round
73
79
  }
74
80
  return null;
75
- }
81
+ };
76
82
  /**
77
83
  * Fire-and-forget background update: at most once per day (and never in CI
78
84
  * or with VG_NO_AUTO_UPDATE set), re-invoke this CLI as a detached
79
85
  * `vg update --auto`, which only applies anything when npm has a newer
80
86
  * version. The foreground command pays no latency and prints nothing.
81
87
  */
82
- export function maybeScheduleAutoUpdate() {
83
- if (process.env.VG_NO_AUTO_UPDATE || process.env.CI)
88
+ export const maybeScheduleAutoUpdate = () => {
89
+ if (process.env.VG_NO_AUTO_UPDATE || process.env.CI) {
84
90
  return;
85
- const script = process.argv[1];
86
- if (!script)
91
+ }
92
+ const [, script] = process.argv;
93
+ if (!script) {
87
94
  return;
88
- if (Date.now() - getLastCheckedAt() < CHECK_INTERVAL_MS)
95
+ }
96
+ if (Date.now() - getLastCheckedAt() < CHECK_INTERVAL_MS) {
89
97
  return;
98
+ }
90
99
  markUpdateChecked();
91
100
  try {
92
101
  const child = spawn(process.execPath, [script, "update", "--auto"], {
@@ -98,4 +107,4 @@ export function maybeScheduleAutoUpdate() {
98
107
  catch {
99
108
  // best-effort; worst case we try again next run
100
109
  }
101
- }
110
+ };
@@ -1,16 +1,16 @@
1
1
  import type { ManifestFile } from "./manifest.js";
2
- export type UploadTarget = {
2
+ export interface UploadTarget {
3
3
  path: string;
4
4
  url: string;
5
5
  headers: Record<string, string>;
6
- };
6
+ }
7
7
  /**
8
8
  * Upload all files to their presigned PUT URLs with bounded concurrency.
9
9
  * Throws on the first non-2xx response.
10
10
  */
11
- export declare function uploadAll({ files, uploads, concurrency, onProgress, }: {
11
+ export declare const uploadAll: ({ files, uploads, concurrency, onProgress, }: {
12
12
  files: ManifestFile[];
13
13
  uploads: UploadTarget[];
14
14
  concurrency?: number;
15
15
  onProgress?: (done: number, total: number) => void;
16
- }): Promise<void>;
16
+ }) => Promise<void>;
@@ -3,34 +3,39 @@ import { readFileSync } from "node:fs";
3
3
  * Upload all files to their presigned PUT URLs with bounded concurrency.
4
4
  * Throws on the first non-2xx response.
5
5
  */
6
- export async function uploadAll({ files, uploads, concurrency = 6, onProgress, }) {
6
+ export const uploadAll = async ({ files, uploads, concurrency = 6, onProgress, }) => {
7
7
  const byPath = new Map(files.map((f) => [f.path, f]));
8
8
  let done = 0;
9
9
  let cursor = 0;
10
- async function worker() {
10
+ const worker = async () => {
11
11
  while (true) {
12
- const idx = cursor++;
13
- if (idx >= uploads.length)
12
+ const idx = cursor;
13
+ cursor += 1;
14
+ if (idx >= uploads.length) {
14
15
  return;
16
+ }
15
17
  const upload = uploads[idx];
18
+ if (!upload) {
19
+ return;
20
+ }
16
21
  const file = byPath.get(upload.path);
17
22
  if (!file) {
18
23
  throw new Error(`Missing file for upload target: ${upload.path}`);
19
24
  }
20
25
  const body = readFileSync(file.absolutePath);
21
26
  const res = await fetch(upload.url, {
22
- method: "PUT",
23
- headers: upload.headers,
24
27
  body,
28
+ headers: upload.headers,
29
+ method: "PUT",
25
30
  });
26
31
  if (!res.ok) {
27
32
  const text = await res.text().catch(() => "");
28
33
  throw new Error(`Upload failed for ${upload.path}: ${res.status} ${res.statusText} ${text}`);
29
34
  }
30
- done++;
35
+ done += 1;
31
36
  onProgress?.(done, uploads.length);
32
37
  }
33
- }
38
+ };
34
39
  const workers = Array.from({ length: Math.min(concurrency, uploads.length) }, () => worker());
35
40
  await Promise.all(workers);
36
- }
41
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vibedgames",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "private": false,
5
5
  "bin": {
6
6
  "vg": "./dist/index.js"
@@ -9,15 +9,8 @@
9
9
  "dist"
10
10
  ],
11
11
  "type": "module",
12
- "scripts": {
13
- "build": "tsc && chmod +x dist/index.js",
14
- "dev": "tsc --watch",
15
- "clean": "rm -rf .turbo dist node_modules",
16
- "test": "node --import tsx --test test/*.test.ts",
17
- "typecheck": "tsc --noEmit"
18
- },
19
12
  "dependencies": {
20
- "@orpc/client": "catalog:",
13
+ "@orpc/client": "2.0.0-beta.31",
21
14
  "citty": "^0.2.2",
22
15
  "consola": "^3.4.2",
23
16
  "cross-spawn": "^7.0.6",
@@ -26,12 +19,19 @@
26
19
  "tiged": "^2.12.8"
27
20
  },
28
21
  "devDependencies": {
29
- "@cloudflare/workers-types": "catalog:",
30
- "@kyh/tsconfig": "catalog:",
31
- "@orpc/server": "catalog:",
32
- "@repo/api": "workspace:^",
22
+ "@cloudflare/workers-types": "^5.20260829.1",
23
+ "@kyh/tsconfig": "^1.2.0",
24
+ "@orpc/server": "2.0.0-beta.31",
25
+ "@repo/api": "^0.1.0",
33
26
  "@types/cross-spawn": "^6.0.6",
34
- "@types/node": "catalog:",
35
- "typescript": "catalog:"
27
+ "@types/node": "^26.4.0",
28
+ "typescript": "^7.0.2"
29
+ },
30
+ "scripts": {
31
+ "build": "tsc && chmod +x dist/index.js",
32
+ "dev": "tsc --watch",
33
+ "clean": "rm -rf .turbo dist node_modules",
34
+ "test": "node --import tsx --test test/*.test.ts",
35
+ "typecheck": "tsc --noEmit"
36
36
  }
37
- }
37
+ }