@replaystage/cli 0.2.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/dist/index.js CHANGED
@@ -35,7 +35,6 @@ async function uploadGameBundle(options) {
35
35
  formData.append("title", options.title);
36
36
  formData.append("tagline", options.tagline);
37
37
  if (options.description) formData.append("description", options.description);
38
- formData.append("ai_tool", options.aiTool);
39
38
  if (options.category) formData.append("category", options.category);
40
39
  formData.append("submission_type", options.submissionType || "maker");
41
40
  if (options.makerName) formData.append("maker_name", options.makerName);
@@ -48,6 +47,22 @@ async function uploadGameBundle(options) {
48
47
  formData.append("supportedPlatforms", options.supportedPlatforms);
49
48
  formData.append("supported_platforms", options.supportedPlatforms);
50
49
  }
50
+ if (options.aiModel) {
51
+ formData.append("ai_model", options.aiModel);
52
+ formData.append("aiModel", options.aiModel);
53
+ }
54
+ if (options.aiTool) {
55
+ formData.append("ai_tool", options.aiTool);
56
+ formData.append("aiTool", options.aiTool);
57
+ }
58
+ if (options.coverBuffer) {
59
+ const uint82 = new Uint8Array(options.coverBuffer);
60
+ const fileName = options.coverFileName || "cover.png";
61
+ const lower = fileName.toLowerCase();
62
+ const mimeType = lower.endsWith(".png") ? "image/png" : lower.endsWith(".webp") ? "image/webp" : lower.endsWith(".gif") ? "image/gif" : "image/jpeg";
63
+ const blob2 = new Blob([uint82], { type: mimeType });
64
+ formData.append("cover", blob2, fileName);
65
+ }
51
66
  const headers = {
52
67
  ...options.extraHeaders
53
68
  };
@@ -102,6 +117,22 @@ async function updateGameBundle(slug, options) {
102
117
  formData.append("supportedPlatforms", options.supportedPlatforms);
103
118
  formData.append("supported_platforms", options.supportedPlatforms);
104
119
  }
120
+ if (options.aiModel) {
121
+ formData.append("ai_model", options.aiModel);
122
+ formData.append("aiModel", options.aiModel);
123
+ }
124
+ if (options.aiTool) {
125
+ formData.append("ai_tool", options.aiTool);
126
+ formData.append("aiTool", options.aiTool);
127
+ }
128
+ if (options.coverBuffer) {
129
+ const uint8 = new Uint8Array(options.coverBuffer);
130
+ const fileName = options.coverFileName || "cover.png";
131
+ const lower = fileName.toLowerCase();
132
+ const mimeType = lower.endsWith(".png") ? "image/png" : lower.endsWith(".webp") ? "image/webp" : lower.endsWith(".gif") ? "image/gif" : "image/jpeg";
133
+ const blob = new Blob([uint8], { type: mimeType });
134
+ formData.append("cover", blob, fileName);
135
+ }
105
136
  const headers = {
106
137
  ...options.extraHeaders
107
138
  };
@@ -158,22 +189,117 @@ async function fetchWhoami(apiUrl, token) {
158
189
  }
159
190
 
160
191
  // src/config.ts
161
- import fs from "fs";
162
- import os from "os";
163
- import path from "path";
192
+ import fs2 from "fs";
193
+ import os2 from "os";
194
+ import path2 from "path";
195
+
196
+ // src/project.ts
197
+ import * as fs from "fs";
198
+ import * as os from "os";
199
+ import * as path from "path";
200
+ function resolveProjectDirectory(targetPath) {
201
+ try {
202
+ const resolved = path.resolve(targetPath);
203
+ if (resolved.toLowerCase().endsWith(".zip")) {
204
+ return null;
205
+ }
206
+ if (resolved.includes("seed-games")) {
207
+ return null;
208
+ }
209
+ if (fs.existsSync(resolved) && fs.statSync(resolved).isDirectory()) {
210
+ if (resolved === path.resolve(os.tmpdir())) {
211
+ return null;
212
+ }
213
+ return resolved;
214
+ }
215
+ if (fs.existsSync(resolved) && fs.statSync(resolved).isFile()) {
216
+ const parentDir = path.dirname(resolved);
217
+ if (parentDir === path.resolve(os.tmpdir())) {
218
+ return null;
219
+ }
220
+ return parentDir;
221
+ }
222
+ return resolved;
223
+ } catch {
224
+ return path.resolve(targetPath);
225
+ }
226
+ }
227
+ function getProjectConfigPath(targetDir) {
228
+ const dir = resolveProjectDirectory(targetDir);
229
+ return dir ? path.join(dir, ".replaystage.json") : null;
230
+ }
231
+ function readProjectConfig(targetDir) {
232
+ const configPath = getProjectConfigPath(targetDir);
233
+ if (!configPath || !fs.existsSync(configPath)) {
234
+ return null;
235
+ }
236
+ try {
237
+ const raw = fs.readFileSync(configPath, "utf-8");
238
+ const parsed = JSON.parse(raw);
239
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
240
+ return null;
241
+ }
242
+ if ("slug" in parsed) {
243
+ if (typeof parsed.slug !== "string" || !parsed.slug.trim()) {
244
+ return null;
245
+ }
246
+ }
247
+ const hasValidKey = typeof parsed.slug === "string" && parsed.slug.trim().length > 0 || typeof parsed.supportedPlatforms === "string" || typeof parsed.platforms === "string" || typeof parsed.aspectRatio === "string" || typeof parsed.aiModel === "string" || typeof parsed.aiTool === "string";
248
+ if (!hasValidKey) {
249
+ return null;
250
+ }
251
+ return parsed;
252
+ } catch {
253
+ return null;
254
+ }
255
+ }
256
+ function writeProjectConfig(targetDir, config) {
257
+ const configPath = getProjectConfigPath(targetDir);
258
+ if (!configPath) {
259
+ return;
260
+ }
261
+ const dir = path.dirname(configPath);
262
+ if (!fs.existsSync(dir)) {
263
+ fs.mkdirSync(dir, { recursive: true });
264
+ }
265
+ fs.writeFileSync(configPath, `${JSON.stringify(config, null, 2)}
266
+ `, "utf-8");
267
+ }
268
+ function incrementVersion(currentVersion) {
269
+ if (!currentVersion || typeof currentVersion !== "string") return "0.2.0";
270
+ const sanitized = currentVersion.trim().replace(/^v/i, "");
271
+ const parts = sanitized.split(".").map((n) => Number.parseInt(n, 10));
272
+ if (parts.length === 3 && !parts.some(Number.isNaN)) {
273
+ return `${parts[0]}.${parts[1] + 1}.0`;
274
+ }
275
+ if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1])) {
276
+ return `${parts[0]}.${parts[1] + 1}.0`;
277
+ }
278
+ return "0.2.0";
279
+ }
280
+ function promoteDraftVersion(currentVersion) {
281
+ if (!currentVersion || typeof currentVersion !== "string") return "1.0.0";
282
+ const sanitized = currentVersion.trim().replace(/^v/i, "");
283
+ if (sanitized.startsWith("0.")) {
284
+ return "1.0.0";
285
+ }
286
+ return incrementVersion(currentVersion);
287
+ }
288
+
289
+ // src/config.ts
164
290
  function getConfigDir() {
165
- return process.env.REPLAYSTAGE_CONFIG_DIR || path.join(os.homedir(), ".replaystage");
291
+ return process.env.REPLAYSTAGE_CONFIG_DIR || path2.join(os2.homedir(), ".replaystage");
166
292
  }
167
293
  function getConfigPath() {
168
- return path.join(getConfigDir(), "config.json");
294
+ return path2.join(getConfigDir(), "config.json");
169
295
  }
170
296
  function readConfig() {
171
297
  const dir = getConfigDir();
172
298
  for (const filename of ["config.json", "credentials.json"]) {
173
- const file = path.join(dir, filename);
174
- if (fs.existsSync(file)) {
299
+ const file = path2.join(dir, filename);
300
+ if (fs2.existsSync(file)) {
175
301
  try {
176
- const raw = fs.readFileSync(file, "utf-8");
302
+ const raw = fs2.readFileSync(file, "utf-8");
177
303
  return JSON.parse(raw);
178
304
  } catch {
179
305
  }
@@ -183,24 +309,24 @@ function readConfig() {
183
309
  }
184
310
  function writeConfig(config) {
185
311
  const dir = getConfigDir();
186
- fs.mkdirSync(dir, { recursive: true, mode: 448 });
312
+ fs2.mkdirSync(dir, { recursive: true, mode: 448 });
187
313
  const target = getConfigPath();
188
- fs.writeFileSync(target, JSON.stringify(config, null, 2), {
314
+ fs2.writeFileSync(target, JSON.stringify(config, null, 2), {
189
315
  encoding: "utf-8",
190
316
  mode: 384
191
317
  });
192
318
  try {
193
- fs.chmodSync(target, 384);
319
+ fs2.chmodSync(target, 384);
194
320
  } catch {
195
321
  }
196
322
  }
197
323
  function clearConfig() {
198
324
  const dir = getConfigDir();
199
325
  for (const filename of ["config.json", "credentials.json"]) {
200
- const file = path.join(dir, filename);
201
- if (fs.existsSync(file)) {
326
+ const file = path2.join(dir, filename);
327
+ if (fs2.existsSync(file)) {
202
328
  try {
203
- fs.unlinkSync(file);
329
+ fs2.unlinkSync(file);
204
330
  } catch {
205
331
  }
206
332
  }
@@ -460,18 +586,158 @@ async function handleLogout(options = {}) {
460
586
  }
461
587
 
462
588
  // src/commands/publish.ts
589
+ import fs5 from "fs";
463
590
  import path5 from "path";
464
591
 
465
592
  // ../shared/src/constants.ts
466
593
  var AI_TOOL_KEYS = [
467
- "claude",
468
- "gemini",
594
+ "claude-code",
469
595
  "antigravity",
470
596
  "cursor",
597
+ "codex",
598
+ "claude",
599
+ "gemini",
471
600
  "chatgpt",
472
601
  "v0",
602
+ "windsurf",
603
+ "lovable",
604
+ "bolt",
473
605
  "other"
474
606
  ];
607
+ var AI_TOOLS = {
608
+ "claude-code": {
609
+ id: "claude-code",
610
+ name: "Claude Code",
611
+ fullName: "Anthropic Claude Code",
612
+ slug: "claude-code",
613
+ description: "Terminal-based agentic coding and game generation by Anthropic",
614
+ badgeColor: "#D97706",
615
+ badgeBg: "bg-amber-100 text-amber-900 border-amber-300 dark:bg-amber-950/60 dark:text-amber-200 dark:border-amber-700",
616
+ icon: "terminal",
617
+ website: "https://claude.ai/code"
618
+ },
619
+ antigravity: {
620
+ id: "antigravity",
621
+ name: "Antigravity",
622
+ fullName: "Antigravity Agent Platform",
623
+ slug: "antigravity",
624
+ description: "Autonomous multi-agent game productions orchestrated by Antigravity",
625
+ badgeColor: "#7C3AED",
626
+ badgeBg: "bg-purple-100 text-purple-900 border-purple-300 dark:bg-purple-950/60 dark:text-purple-200 dark:border-purple-700",
627
+ icon: "orbit",
628
+ website: "https://github.com/google-gemini/antigravity"
629
+ },
630
+ cursor: {
631
+ id: "cursor",
632
+ name: "Cursor",
633
+ fullName: "Cursor Composer & Agent",
634
+ slug: "cursor",
635
+ description: "Web games generated and iterated through Cursor AI Composer",
636
+ badgeColor: "#0F172A",
637
+ badgeBg: "bg-slate-100 text-slate-900 border-slate-300 dark:bg-slate-900 dark:text-slate-200 dark:border-slate-700",
638
+ icon: "mouse-pointer-click",
639
+ website: "https://cursor.com"
640
+ },
641
+ codex: {
642
+ id: "codex",
643
+ name: "Codex",
644
+ fullName: "OpenAI Codex",
645
+ slug: "codex",
646
+ description: "AI code generation and interactive canvas mechanics synthesized by Codex",
647
+ badgeColor: "#10A37F",
648
+ badgeBg: "bg-emerald-100 text-emerald-900 border-emerald-300 dark:bg-emerald-950/60 dark:text-emerald-200 dark:border-emerald-700",
649
+ icon: "code",
650
+ website: "https://openai.com"
651
+ },
652
+ claude: {
653
+ id: "claude",
654
+ name: "Claude",
655
+ fullName: "Anthropic Claude",
656
+ slug: "claude",
657
+ description: "Games designed and crafted with Anthropic Claude",
658
+ badgeColor: "#D97706",
659
+ badgeBg: "bg-amber-100 text-amber-900 border-amber-300 dark:bg-amber-950/60 dark:text-amber-200 dark:border-amber-700",
660
+ icon: "sparkles",
661
+ website: "https://anthropic.com/claude"
662
+ },
663
+ gemini: {
664
+ id: "gemini",
665
+ name: "Gemini",
666
+ fullName: "Google Gemini",
667
+ slug: "gemini",
668
+ description: "Ultra-fast web games generated with Google Gemini models",
669
+ badgeColor: "#2563EB",
670
+ badgeBg: "bg-blue-100 text-blue-900 border-blue-300 dark:bg-blue-950/60 dark:text-blue-200 dark:border-blue-700",
671
+ icon: "atom",
672
+ website: "https://gemini.google.com"
673
+ },
674
+ chatgpt: {
675
+ id: "chatgpt",
676
+ name: "ChatGPT",
677
+ fullName: "OpenAI ChatGPT & Canvas",
678
+ slug: "chatgpt",
679
+ description: "Games built in interactive canvas sessions with OpenAI ChatGPT",
680
+ badgeColor: "#10A37F",
681
+ badgeBg: "bg-emerald-100 text-emerald-900 border-emerald-300 dark:bg-emerald-950/60 dark:text-emerald-200 dark:border-emerald-700",
682
+ icon: "bot",
683
+ website: "https://chatgpt.com"
684
+ },
685
+ v0: {
686
+ id: "v0",
687
+ name: "v0",
688
+ fullName: "v0 by Vercel",
689
+ slug: "v0",
690
+ description: "Generative interactive UI and canvas components synthesized by v0",
691
+ badgeColor: "#18181B",
692
+ badgeBg: "bg-zinc-100 text-zinc-900 border-zinc-300 dark:bg-zinc-800 dark:text-zinc-200 dark:border-zinc-700",
693
+ icon: "layers",
694
+ website: "https://v0.dev"
695
+ },
696
+ windsurf: {
697
+ id: "windsurf",
698
+ name: "Windsurf",
699
+ fullName: "Codeium Windsurf",
700
+ slug: "windsurf",
701
+ description: "Agentic flow and web games developed with Codeium Windsurf",
702
+ badgeColor: "#0284C7",
703
+ badgeBg: "bg-sky-100 text-sky-900 border-sky-300 dark:bg-sky-950/60 dark:text-sky-200 dark:border-sky-700",
704
+ icon: "wind",
705
+ website: "https://codeium.com/windsurf"
706
+ },
707
+ lovable: {
708
+ id: "lovable",
709
+ name: "Lovable",
710
+ fullName: "Lovable AI",
711
+ slug: "lovable",
712
+ description: "Full-stack web applications and games engineered with Lovable",
713
+ badgeColor: "#EC4899",
714
+ badgeBg: "bg-pink-100 text-pink-900 border-pink-300 dark:bg-pink-950/60 dark:text-pink-200 dark:border-pink-700",
715
+ icon: "heart",
716
+ website: "https://lovable.dev"
717
+ },
718
+ bolt: {
719
+ id: "bolt",
720
+ name: "Bolt",
721
+ fullName: "Bolt.new by StackBlitz",
722
+ slug: "bolt",
723
+ description: "In-browser full-stack sandbox games generated with Bolt.new",
724
+ badgeColor: "#EAB308",
725
+ badgeBg: "bg-yellow-100 text-yellow-900 border-yellow-300 dark:bg-yellow-950/60 dark:text-yellow-200 dark:border-yellow-700",
726
+ icon: "zap",
727
+ website: "https://bolt.new"
728
+ },
729
+ other: {
730
+ id: "other",
731
+ name: "Other AI",
732
+ fullName: "Other / Custom AI Engine",
733
+ slug: "other",
734
+ description: "Games created with custom agents, local LLMs, or custom fine-tunes",
735
+ badgeColor: "#64748B",
736
+ badgeBg: "bg-neutral-100 text-neutral-800 border-neutral-300 dark:bg-neutral-800 dark:text-neutral-300 dark:border-neutral-700",
737
+ icon: "cpu",
738
+ website: "https://replaystage.com"
739
+ }
740
+ };
475
741
  var GAME_CATEGORY_KEYS = [
476
742
  "arcade",
477
743
  "action",
@@ -489,6 +755,8 @@ var MAX_GAME_DESCRIPTION_LENGTH = 2e3;
489
755
  var MAX_TAGS_COUNT = 6;
490
756
  var MAX_TAG_LENGTH = 20;
491
757
  var MAX_PROMPT_LENGTH = 4e3;
758
+ var MAX_AI_TOOL_LENGTH = 64;
759
+ var MAX_AI_MODEL_LENGTH = 80;
492
760
  var CLAIM_TOKEN_EXPIRY_DAYS = 7;
493
761
  var CLAIM_TOKEN_EXPIRY_MS = CLAIM_TOKEN_EXPIRY_DAYS * 24 * 60 * 60 * 1e3;
494
762
  var PROHIBITED_EXTENSIONS = [
@@ -4891,6 +5159,27 @@ var supportedPlatformsSchema = external_exports.preprocess((val) => {
4891
5159
  });
4892
5160
  }
4893
5161
  }).transform((val) => normalizeSupportedPlatforms(val).normalized);
5162
+ var aiToolSchema = external_exports.preprocess(
5163
+ (val) => {
5164
+ if (val === null || val === void 0 || val === false || typeof val === "string" && val.trim() === "") {
5165
+ return "other";
5166
+ }
5167
+ if (typeof val === "string") {
5168
+ return val.trim();
5169
+ }
5170
+ return val;
5171
+ },
5172
+ external_exports.string({ errorMap: () => ({ message: "Invalid AI tool selection" }) }).min(1, "AI tool cannot be empty").max(MAX_AI_TOOL_LENGTH, `AI tool must be ${MAX_AI_TOOL_LENGTH} characters or less`)
5173
+ );
5174
+ var aiModelSchema = external_exports.preprocess((val) => {
5175
+ if (val === null || typeof val === "string" && val.trim() === "") {
5176
+ return null;
5177
+ }
5178
+ if (typeof val === "string") {
5179
+ return val.trim();
5180
+ }
5181
+ return val;
5182
+ }, external_exports.string().max(MAX_AI_MODEL_LENGTH, `AI model must be ${MAX_AI_MODEL_LENGTH} characters or less`).nullable().optional());
4894
5183
  var baseGameUploadObject = external_exports.object({
4895
5184
  title: external_exports.string().trim().min(2, "Title must be at least 2 characters").max(MAX_GAME_TITLE_LENGTH, `Title must be ${MAX_GAME_TITLE_LENGTH} characters or less`),
4896
5185
  tagline: external_exports.string({ required_error: "Tagline is required" }).trim().max(
@@ -4901,9 +5190,8 @@ var baseGameUploadObject = external_exports.object({
4901
5190
  MAX_GAME_DESCRIPTION_LENGTH,
4902
5191
  `Description must be ${MAX_GAME_DESCRIPTION_LENGTH} characters or less`
4903
5192
  ).default(""),
4904
- aiTool: external_exports.enum(AI_TOOL_KEYS, {
4905
- errorMap: () => ({ message: "Invalid AI tool selection" })
4906
- }),
5193
+ aiTool: aiToolSchema.default("other"),
5194
+ aiModel: aiModelSchema.optional().nullable(),
4907
5195
  primaryCategory: external_exports.enum(GAME_CATEGORY_KEYS, {
4908
5196
  errorMap: () => ({ message: "Invalid game category selection" })
4909
5197
  }),
@@ -4967,9 +5255,8 @@ var gameUpdateSchema = external_exports.object({
4967
5255
  MAX_GAME_DESCRIPTION_LENGTH,
4968
5256
  `Description must be ${MAX_GAME_DESCRIPTION_LENGTH} characters or less`
4969
5257
  ).optional(),
4970
- aiTool: external_exports.enum(AI_TOOL_KEYS, {
4971
- errorMap: () => ({ message: "Invalid AI tool selection" })
4972
- }).optional(),
5258
+ aiTool: aiToolSchema.optional(),
5259
+ aiModel: aiModelSchema.optional().nullable(),
4973
5260
  primaryCategory: external_exports.enum(GAME_CATEGORY_KEYS, {
4974
5261
  errorMap: () => ({ message: "Invalid game category selection" })
4975
5262
  }).optional(),
@@ -5084,6 +5371,33 @@ async function sha256(input) {
5084
5371
  return hashArray.map((byte) => byte.toString(16).padStart(2, "0")).join("");
5085
5372
  }
5086
5373
 
5374
+ // ../shared/src/model.ts
5375
+ function extractRawAiModelFromHtml(html) {
5376
+ if (!html || typeof html !== "string") return null;
5377
+ const cleanHtml = html.replace(/<!--[\s\S]*?-->/g, "");
5378
+ const metaTagRegex = /<meta\b([^>]*)>/gi;
5379
+ for (const match of cleanHtml.matchAll(metaTagRegex)) {
5380
+ const attrs = match[1];
5381
+ const isModelMeta = /(?:^|\s)name\s*=\s*(["']?)replaystage:models?\1(?:\s|$|\/)/i.test(attrs);
5382
+ if (!isModelMeta) continue;
5383
+ const contentMatch = /(?:^|\s)content\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i.exec(attrs);
5384
+ if (contentMatch) {
5385
+ const content = contentMatch[1] ?? contentMatch[2] ?? contentMatch[3] ?? "";
5386
+ const trimmed = content.trim();
5387
+ return trimmed.length > 0 ? trimmed : null;
5388
+ }
5389
+ }
5390
+ return null;
5391
+ }
5392
+ function extractAiModelFromHtml(html) {
5393
+ const raw = extractRawAiModelFromHtml(html);
5394
+ if (!raw) return null;
5395
+ const truncated = raw.slice(0, MAX_AI_MODEL_LENGTH);
5396
+ const parsed = aiModelSchema.safeParse(truncated);
5397
+ if (!parsed.success || !parsed.data) return null;
5398
+ return parsed.data;
5399
+ }
5400
+
5087
5401
  // ../shared/src/sanitizer.ts
5088
5402
  var FORBIDDEN_SEGMENT_EXACT = /* @__PURE__ */ new Set([
5089
5403
  ".replaystage.json",
@@ -5164,6 +5478,30 @@ function isIgnoredZipEntry(entryPath) {
5164
5478
  return normalized.startsWith("__MACOSX/") || normalized.includes("/__MACOSX/") || normalized.endsWith(".DS_Store") || normalized.endsWith("Thumbs.db") || normalized.startsWith("._") || normalized.includes("/._");
5165
5479
  }
5166
5480
  var MAX_COVER_IMAGE_BYTES = 2 * 1024 * 1024;
5481
+ function validateCoverImageBytes(bytes) {
5482
+ if (!bytes || bytes.byteLength < 12) {
5483
+ return { valid: false, error: "Cover image is empty or truncated" };
5484
+ }
5485
+ if (bytes.byteLength > MAX_COVER_IMAGE_BYTES) {
5486
+ return { valid: false, error: "Cover image exceeds the 2 MB maximum limit" };
5487
+ }
5488
+ if (bytes[0] === 137 && bytes[1] === 80 && bytes[2] === 78 && bytes[3] === 71 && bytes[4] === 13 && bytes[5] === 10 && bytes[6] === 26 && bytes[7] === 10) {
5489
+ return { valid: true, mimeType: "image/png", ext: "png" };
5490
+ }
5491
+ if (bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255) {
5492
+ return { valid: true, mimeType: "image/jpeg", ext: "jpg" };
5493
+ }
5494
+ if (bytes[0] === 82 && bytes[1] === 73 && bytes[2] === 70 && bytes[3] === 70 && bytes[8] === 87 && bytes[9] === 69 && bytes[10] === 66 && bytes[11] === 80) {
5495
+ return { valid: true, mimeType: "image/webp", ext: "webp" };
5496
+ }
5497
+ if (bytes[0] === 71 && bytes[1] === 73 && bytes[2] === 70 && bytes[3] === 56 && (bytes[4] === 55 || bytes[4] === 57) && bytes[5] === 97) {
5498
+ return { valid: true, mimeType: "image/gif", ext: "gif" };
5499
+ }
5500
+ return {
5501
+ valid: false,
5502
+ error: "Unsupported cover image format (must be PNG, JPEG, WebP, or GIF)"
5503
+ };
5504
+ }
5167
5505
  function findEntryHtmlFile(paths) {
5168
5506
  const cleanPaths = paths.filter((p) => !isIgnoredZipEntry(p)).map((p) => p.replace(/\\/g, "/").replace(/^\.?\//, ""));
5169
5507
  if (cleanPaths.includes("index.html")) {
@@ -5224,9 +5562,94 @@ import pc3 from "picocolors";
5224
5562
 
5225
5563
  // src/packager.ts
5226
5564
  import crypto from "crypto";
5227
- import fs2 from "fs";
5228
- import path2 from "path";
5565
+ import fs3 from "fs";
5566
+ import path3 from "path";
5229
5567
  import * as fflate from "fflate";
5568
+ var COVER_PRECEDENCE_FILES = [
5569
+ "cover.png",
5570
+ "cover.jpg",
5571
+ "cover.jpeg",
5572
+ "cover.webp",
5573
+ "cover.gif"
5574
+ ];
5575
+ function detectSiblingCover(targetPath) {
5576
+ const resolved = path3.resolve(process.cwd(), targetPath || ".");
5577
+ if (!fs3.existsSync(resolved)) return null;
5578
+ const stat = fs3.statSync(resolved);
5579
+ if (stat.isFile()) {
5580
+ const ext = path3.extname(resolved).toLowerCase();
5581
+ if (ext === ".html" || ext === ".htm") {
5582
+ return scanDirectoryForCover(path3.dirname(resolved), "sibling");
5583
+ }
5584
+ if (ext === ".zip") {
5585
+ try {
5586
+ const zipContent = fs3.readFileSync(resolved);
5587
+ const unzipped = fflate.unzipSync(new Uint8Array(zipContent));
5588
+ const entryPaths = Object.keys(unzipped);
5589
+ const lookup = /* @__PURE__ */ new Map();
5590
+ for (const ep of entryPaths) {
5591
+ if (isIgnoredZipEntry(ep)) continue;
5592
+ const clean = ep.replace(/\\/g, "/").replace(/^\.?\//, "");
5593
+ lookup.set(clean.toLowerCase(), ep);
5594
+ }
5595
+ for (const candidate of COVER_PRECEDENCE_FILES) {
5596
+ const matchedKey = lookup.get(candidate);
5597
+ if (matchedKey) {
5598
+ const rawBytes = unzipped[matchedKey];
5599
+ const check = validateCoverImageBytes(rawBytes);
5600
+ if (check.valid && check.ext && check.mimeType) {
5601
+ return {
5602
+ source: "bundle",
5603
+ fileName: path3.basename(matchedKey),
5604
+ buffer: Buffer.from(rawBytes),
5605
+ ext: check.ext,
5606
+ mimeType: check.mimeType
5607
+ };
5608
+ }
5609
+ }
5610
+ }
5611
+ } catch {
5612
+ }
5613
+ return scanDirectoryForCover(path3.dirname(resolved), "sibling");
5614
+ }
5615
+ return null;
5616
+ }
5617
+ if (stat.isDirectory()) {
5618
+ return scanDirectoryForCover(resolved, "bundle");
5619
+ }
5620
+ return null;
5621
+ }
5622
+ function scanDirectoryForCover(dirPath, source) {
5623
+ try {
5624
+ const entries = fs3.readdirSync(dirPath, { withFileTypes: true });
5625
+ const entryMap = /* @__PURE__ */ new Map();
5626
+ for (const entry of entries) {
5627
+ if (entry.isFile()) {
5628
+ entryMap.set(entry.name.toLowerCase(), entry);
5629
+ }
5630
+ }
5631
+ for (const candidate of COVER_PRECEDENCE_FILES) {
5632
+ const match = entryMap.get(candidate);
5633
+ if (match) {
5634
+ const fullPath = path3.join(dirPath, match.name);
5635
+ const buf = fs3.readFileSync(fullPath);
5636
+ const check = validateCoverImageBytes(new Uint8Array(buf));
5637
+ if (check.valid && check.ext && check.mimeType) {
5638
+ return {
5639
+ source,
5640
+ fileName: match.name,
5641
+ filePath: fullPath,
5642
+ buffer: buf,
5643
+ ext: check.ext,
5644
+ mimeType: check.mimeType
5645
+ };
5646
+ }
5647
+ }
5648
+ }
5649
+ } catch {
5650
+ }
5651
+ return null;
5652
+ }
5230
5653
  function extractHtmlMetadata(html) {
5231
5654
  let title;
5232
5655
  let tagline;
@@ -5240,11 +5663,13 @@ function extractHtmlMetadata(html) {
5240
5663
  }
5241
5664
  const rawAspect = extractRawAspectRatioFromHtml(html);
5242
5665
  const aspectNorm = rawAspect ? normalizeAspectRatio(rawAspect) : null;
5666
+ const model = extractAiModelFromHtml(html);
5243
5667
  return {
5244
5668
  title,
5245
5669
  tagline,
5246
5670
  rawAspectRatio: rawAspect ?? void 0,
5247
- aspectRatio: aspectNorm?.valid ? aspectNorm.normalized : void 0
5671
+ aspectRatio: aspectNorm?.valid ? aspectNorm.normalized : void 0,
5672
+ model: model ?? null
5248
5673
  };
5249
5674
  }
5250
5675
  function computeSha256(buf) {
@@ -5260,40 +5685,46 @@ function createZipFromFiles(fileMap) {
5260
5685
  return Buffer.from(zipped);
5261
5686
  }
5262
5687
  async function packageGame(targetPath) {
5263
- const resolved = path2.resolve(process.cwd(), targetPath || ".");
5264
- if (!fs2.existsSync(resolved)) {
5688
+ const resolved = path3.resolve(process.cwd(), targetPath || ".");
5689
+ if (!fs3.existsSync(resolved)) {
5265
5690
  throw new Error(`Target path does not exist: ${resolved}`);
5266
5691
  }
5267
- const stat = fs2.statSync(resolved);
5692
+ const stat = fs3.statSync(resolved);
5268
5693
  if (stat.isFile()) {
5269
- const ext = path2.extname(resolved).toLowerCase();
5694
+ const ext = path3.extname(resolved).toLowerCase();
5270
5695
  if (ext === ".html" || ext === ".htm") {
5271
- const content = fs2.readFileSync(resolved);
5696
+ const content = fs3.readFileSync(resolved);
5272
5697
  if (content.length > MAX_HTML_SIZE_BYTES) {
5273
5698
  throw new Error(
5274
5699
  `Single HTML file exceeds maximum allowed size of 5MB (${(content.length / (1024 * 1024)).toFixed(2)} MB)`
5275
5700
  );
5276
5701
  }
5277
5702
  const meta = extractHtmlMetadata(content.toString("utf-8"));
5278
- const zipBuffer = createZipFromFiles({ "index.html": content });
5703
+ const files = { "index.html": content };
5704
+ const detectedCover = detectSiblingCover(resolved);
5705
+ if (detectedCover && detectedCover.buffer) {
5706
+ files[detectedCover.fileName] = detectedCover.buffer;
5707
+ }
5708
+ const zipBuffer = createZipFromFiles(files);
5279
5709
  const fileHash = computeSha256(zipBuffer);
5280
5710
  return {
5281
5711
  format: "single-html",
5282
5712
  entryPoint: "index.html",
5283
- fileCount: 1,
5713
+ fileCount: Object.keys(files).length,
5284
5714
  totalBytes: content.length,
5285
- totalSizeBytes: content.length,
5715
+ totalSizeBytes: Object.values(files).reduce((acc, b) => acc + b.length, 0),
5286
5716
  buffer: zipBuffer,
5287
5717
  bundleBuffer: zipBuffer,
5288
5718
  fileHash,
5289
- files: ["index.html"],
5719
+ files: Object.keys(files),
5290
5720
  extractedTitle: meta.title,
5291
5721
  extractedTagline: meta.tagline,
5292
- extractedAspectRatio: meta.aspectRatio
5722
+ extractedAspectRatio: meta.aspectRatio,
5723
+ extractedModel: meta.model ?? null
5293
5724
  };
5294
5725
  }
5295
5726
  if (ext === ".zip") {
5296
- const content = fs2.readFileSync(resolved);
5727
+ const content = fs3.readFileSync(resolved);
5297
5728
  if (content.length > MAX_BUNDLE_SIZE_BYTES) {
5298
5729
  throw new Error(
5299
5730
  `Zip archive exceeds maximum allowed size of 25MB (${(content.length / (1024 * 1024)).toFixed(2)} MB)`
@@ -5329,6 +5760,7 @@ async function packageGame(targetPath) {
5329
5760
  let extractedTitle;
5330
5761
  let extractedTagline;
5331
5762
  let extractedAspectRatio;
5763
+ let extractedModel;
5332
5764
  if (unzipped[entryRes.entryPath]) {
5333
5765
  const meta = extractHtmlMetadata(
5334
5766
  Buffer.from(unzipped[entryRes.entryPath]).toString("utf-8")
@@ -5336,6 +5768,7 @@ async function packageGame(targetPath) {
5336
5768
  extractedTitle = meta.title;
5337
5769
  extractedTagline = meta.tagline;
5338
5770
  extractedAspectRatio = meta.aspectRatio;
5771
+ extractedModel = meta.model;
5339
5772
  }
5340
5773
  return {
5341
5774
  format: "zip",
@@ -5349,7 +5782,8 @@ async function packageGame(targetPath) {
5349
5782
  files: filteredFiles,
5350
5783
  extractedTitle,
5351
5784
  extractedTagline,
5352
- extractedAspectRatio
5785
+ extractedAspectRatio,
5786
+ extractedModel: extractedModel ?? null
5353
5787
  };
5354
5788
  }
5355
5789
  throw new Error(
@@ -5358,13 +5792,13 @@ async function packageGame(targetPath) {
5358
5792
  }
5359
5793
  if (stat.isDirectory()) {
5360
5794
  let walk2 = function(currentDir, relDir) {
5361
- const dirEntries = fs2.readdirSync(currentDir, { withFileTypes: true });
5795
+ const dirEntries = fs3.readdirSync(currentDir, { withFileTypes: true });
5362
5796
  for (const entry of dirEntries) {
5363
5797
  const name = entry.name;
5364
5798
  if (name.startsWith(".") || name === ".replaystage.json" || name.startsWith(".replaystage") || name === "node_modules" || name === "__MACOSX" || name === "Thumbs.db" || isIgnoredZipEntry(name)) {
5365
5799
  continue;
5366
5800
  }
5367
- const fullPath = path2.join(currentDir, name);
5801
+ const fullPath = path3.join(currentDir, name);
5368
5802
  const relPath = relDir ? `${relDir}/${name}` : name;
5369
5803
  const normalizedRelPath = relPath.replace(/\\/g, "/");
5370
5804
  if (isIgnoredZipEntry(normalizedRelPath)) {
@@ -5382,14 +5816,14 @@ async function packageGame(targetPath) {
5382
5816
  if (!validation.valid) {
5383
5817
  throw new Error(`Invalid file path in directory: ${validation.error}`);
5384
5818
  }
5385
- const fileStat = fs2.statSync(fullPath);
5819
+ const fileStat = fs3.statSync(fullPath);
5386
5820
  totalSizeBytes += fileStat.size;
5387
5821
  if (totalSizeBytes > MAX_BUNDLE_SIZE_BYTES) {
5388
5822
  throw new Error(
5389
5823
  `Game bundle exceeds maximum allowed size of 25MB (${(totalSizeBytes / (1024 * 1024)).toFixed(2)} MB).`
5390
5824
  );
5391
5825
  }
5392
- const buf = fs2.readFileSync(fullPath);
5826
+ const buf = fs3.readFileSync(fullPath);
5393
5827
  fileEntries[normalizedRelPath] = buf;
5394
5828
  filesList.push(normalizedRelPath);
5395
5829
  }
@@ -5413,12 +5847,14 @@ async function packageGame(targetPath) {
5413
5847
  let extractedTitle;
5414
5848
  let extractedTagline;
5415
5849
  let extractedAspectRatio;
5850
+ let extractedModel;
5416
5851
  const entryBuf = fileEntries[entryResolution.entryPath];
5417
5852
  if (entryBuf) {
5418
5853
  const meta = extractHtmlMetadata(entryBuf.toString("utf-8"));
5419
5854
  extractedTitle = meta.title;
5420
5855
  extractedTagline = meta.tagline;
5421
5856
  extractedAspectRatio = meta.aspectRatio;
5857
+ extractedModel = meta.model;
5422
5858
  }
5423
5859
  const zipBuffer = createZipFromFiles(fileEntries);
5424
5860
  const fileHash = computeSha256(zipBuffer);
@@ -5434,105 +5870,13 @@ async function packageGame(targetPath) {
5434
5870
  files: filesList,
5435
5871
  extractedTitle,
5436
5872
  extractedTagline,
5437
- extractedAspectRatio
5873
+ extractedAspectRatio,
5874
+ extractedModel: extractedModel ?? null
5438
5875
  };
5439
5876
  }
5440
5877
  throw new Error(`Invalid target path: '${targetPath}' is neither a file nor a directory.`);
5441
5878
  }
5442
5879
 
5443
- // src/project.ts
5444
- import * as fs3 from "fs";
5445
- import * as os2 from "os";
5446
- import * as path3 from "path";
5447
- function resolveProjectDirectory(targetPath) {
5448
- try {
5449
- const resolved = path3.resolve(targetPath);
5450
- if (resolved.toLowerCase().endsWith(".zip")) {
5451
- return null;
5452
- }
5453
- if (resolved.includes("seed-games")) {
5454
- return null;
5455
- }
5456
- if (fs3.existsSync(resolved) && fs3.statSync(resolved).isDirectory()) {
5457
- if (resolved === path3.resolve(os2.tmpdir())) {
5458
- return null;
5459
- }
5460
- return resolved;
5461
- }
5462
- if (fs3.existsSync(resolved) && fs3.statSync(resolved).isFile()) {
5463
- const parentDir = path3.dirname(resolved);
5464
- if (parentDir === path3.resolve(os2.tmpdir())) {
5465
- return null;
5466
- }
5467
- return parentDir;
5468
- }
5469
- return resolved;
5470
- } catch {
5471
- return path3.resolve(targetPath);
5472
- }
5473
- }
5474
- function getProjectConfigPath(targetDir) {
5475
- const dir = resolveProjectDirectory(targetDir);
5476
- return dir ? path3.join(dir, ".replaystage.json") : null;
5477
- }
5478
- function readProjectConfig(targetDir) {
5479
- const configPath = getProjectConfigPath(targetDir);
5480
- if (!configPath || !fs3.existsSync(configPath)) {
5481
- return null;
5482
- }
5483
- try {
5484
- const raw = fs3.readFileSync(configPath, "utf-8");
5485
- const parsed = JSON.parse(raw);
5486
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
5487
- return null;
5488
- }
5489
- if ("slug" in parsed) {
5490
- if (typeof parsed.slug !== "string" || !parsed.slug.trim()) {
5491
- return null;
5492
- }
5493
- }
5494
- const hasValidKey = typeof parsed.slug === "string" && parsed.slug.trim().length > 0 || typeof parsed.supportedPlatforms === "string" || typeof parsed.platforms === "string" || typeof parsed.aspectRatio === "string";
5495
- if (!hasValidKey) {
5496
- return null;
5497
- }
5498
- return parsed;
5499
- } catch {
5500
- return null;
5501
- }
5502
- }
5503
- function writeProjectConfig(targetDir, config) {
5504
- const configPath = getProjectConfigPath(targetDir);
5505
- if (!configPath) {
5506
- return;
5507
- }
5508
- const dir = path3.dirname(configPath);
5509
- if (!fs3.existsSync(dir)) {
5510
- fs3.mkdirSync(dir, { recursive: true });
5511
- }
5512
- fs3.writeFileSync(configPath, `${JSON.stringify(config, null, 2)}
5513
- `, "utf-8");
5514
- }
5515
- function incrementVersion(currentVersion) {
5516
- if (!currentVersion || typeof currentVersion !== "string") return "0.2.0";
5517
- const sanitized = currentVersion.trim().replace(/^v/i, "");
5518
- const parts = sanitized.split(".").map((n) => Number.parseInt(n, 10));
5519
- if (parts.length === 3 && !parts.some(Number.isNaN)) {
5520
- return `${parts[0]}.${parts[1] + 1}.0`;
5521
- }
5522
- if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1])) {
5523
- return `${parts[0]}.${parts[1] + 1}.0`;
5524
- }
5525
- return "0.2.0";
5526
- }
5527
- function promoteDraftVersion(currentVersion) {
5528
- if (!currentVersion || typeof currentVersion !== "string") return "1.0.0";
5529
- const sanitized = currentVersion.trim().replace(/^v/i, "");
5530
- if (sanitized.startsWith("0.")) {
5531
- return "1.0.0";
5532
- }
5533
- return incrementVersion(currentVersion);
5534
- }
5535
-
5536
5880
  // src/validation.ts
5537
5881
  import crypto2 from "crypto";
5538
5882
  import fs4 from "fs";
@@ -5573,11 +5917,13 @@ async function validateGamePackage(targetPath) {
5573
5917
  let detectedAspectRatio = "auto";
5574
5918
  let detectedPlatforms = DEFAULT_SUPPORTED_PLATFORMS;
5575
5919
  let hasPlatformMeta = false;
5920
+ let detectedModel = null;
5576
5921
  if (!fs4.existsSync(resolved)) {
5577
5922
  return {
5578
5923
  valid: false,
5579
5924
  targetPath,
5580
5925
  aspectRatio: detectedAspectRatio,
5926
+ aiModel: detectedModel,
5581
5927
  supportedPlatforms: detectedPlatforms,
5582
5928
  platforms: detectedPlatforms,
5583
5929
  hasPlatformMeta,
@@ -5600,6 +5946,7 @@ async function validateGamePackage(targetPath) {
5600
5946
  if (!depCheck.valid) {
5601
5947
  errors.push(...depCheck.errors);
5602
5948
  }
5949
+ detectedModel = extractAiModelFromHtml(htmlStr);
5603
5950
  const rawMeta = extractRawAspectRatioFromHtml(htmlStr);
5604
5951
  if (rawMeta) {
5605
5952
  const norm = normalizeAspectRatio(rawMeta);
@@ -5638,6 +5985,7 @@ async function validateGamePackage(targetPath) {
5638
5985
  if (!depCheck.valid) {
5639
5986
  errors.push(...depCheck.errors);
5640
5987
  }
5988
+ detectedModel = extractAiModelFromHtml(htmlContent);
5641
5989
  const rawMeta = extractRawAspectRatioFromHtml(htmlContent);
5642
5990
  if (rawMeta) {
5643
5991
  const norm = normalizeAspectRatio(rawMeta);
@@ -5739,6 +6087,7 @@ async function validateGamePackage(targetPath) {
5739
6087
  if (!depCheck.valid) {
5740
6088
  errors.push(...depCheck.errors);
5741
6089
  }
6090
+ detectedModel = extractAiModelFromHtml(htmlContent);
5742
6091
  const rawMeta = extractRawAspectRatioFromHtml(htmlContent);
5743
6092
  if (rawMeta) {
5744
6093
  const norm = normalizeAspectRatio(rawMeta);
@@ -5782,6 +6131,7 @@ async function validateGamePackage(targetPath) {
5782
6131
  valid: false,
5783
6132
  targetPath,
5784
6133
  aspectRatio: detectedAspectRatio,
6134
+ aiModel: detectedModel,
5785
6135
  supportedPlatforms: detectedPlatforms,
5786
6136
  platforms: detectedPlatforms,
5787
6137
  hasPlatformMeta,
@@ -5809,6 +6159,7 @@ async function validateGamePackage(targetPath) {
5809
6159
  fileHash: deterministicHash,
5810
6160
  files: pkg.files,
5811
6161
  aspectRatio: detectedAspectRatio !== "auto" ? detectedAspectRatio : pkg.extractedAspectRatio ?? detectedAspectRatio,
6162
+ aiModel: detectedModel || pkg.extractedModel || null,
5812
6163
  supportedPlatforms: detectedPlatforms,
5813
6164
  platforms: detectedPlatforms,
5814
6165
  hasPlatformMeta,
@@ -5820,6 +6171,7 @@ async function validateGamePackage(targetPath) {
5820
6171
  valid: false,
5821
6172
  targetPath,
5822
6173
  aspectRatio: detectedAspectRatio,
6174
+ aiModel: detectedModel,
5823
6175
  supportedPlatforms: detectedPlatforms,
5824
6176
  platforms: detectedPlatforms,
5825
6177
  hasPlatformMeta,
@@ -5893,10 +6245,6 @@ async function handlePublish(targetPath = ".", options = {}) {
5893
6245
  }
5894
6246
  if (tagline.length < 3) tagline = "An arcade game on ReplayStage";
5895
6247
  if (tagline.length > 120) tagline = tagline.slice(0, 120);
5896
- let aiTool = (options.tool || "other").toLowerCase().trim();
5897
- if (!AI_TOOL_KEYS.includes(aiTool)) {
5898
- aiTool = "other";
5899
- }
5900
6248
  let category = options.category?.toLowerCase().trim();
5901
6249
  if (category && !GAME_CATEGORY_KEYS.includes(category)) {
5902
6250
  category = void 0;
@@ -5904,6 +6252,110 @@ async function handlePublish(targetPath = ".", options = {}) {
5904
6252
  const token = options.anonymous ? null : resolveToken(options.token);
5905
6253
  const apiUrl = resolveApiUrl(options.apiUrl);
5906
6254
  const existingConfig = !options.fresh ? readProjectConfig(resolvedPath) : null;
6255
+ let aiTool = "other";
6256
+ if (options.tool !== void 0) {
6257
+ const parsedTool = aiToolSchema.safeParse(options.tool);
6258
+ if (!parsedTool.success) {
6259
+ const errorMsg = parsedTool.error.errors[0]?.message || `Invalid AI tool: ${options.tool}`;
6260
+ if (isJson) {
6261
+ printErrorJson("INVALID_OPTIONS", errorMsg, 1);
6262
+ } else {
6263
+ console.error(pc3.red(`
6264
+ \u2716 Invalid option: ${errorMsg}
6265
+ `));
6266
+ }
6267
+ process.exit(1);
6268
+ }
6269
+ const rawTool = parsedTool.data;
6270
+ const matchedPreset = AI_TOOL_KEYS.find(
6271
+ (key) => key.toLowerCase() === rawTool.toLowerCase() || AI_TOOLS[key] && AI_TOOLS[key].name.toLowerCase() === rawTool.toLowerCase()
6272
+ );
6273
+ aiTool = matchedPreset ? matchedPreset : rawTool;
6274
+ } else if (existingConfig?.aiTool) {
6275
+ aiTool = existingConfig.aiTool;
6276
+ }
6277
+ let resolvedModel = null;
6278
+ if (options.model !== void 0) {
6279
+ const parsedModel = aiModelSchema.safeParse(options.model);
6280
+ if (!parsedModel.success) {
6281
+ const errorMsg = parsedModel.error.errors[0]?.message || `Invalid AI model: ${options.model}`;
6282
+ if (isJson) {
6283
+ printErrorJson("INVALID_OPTIONS", errorMsg, 1);
6284
+ } else {
6285
+ console.error(pc3.red(`
6286
+ \u2716 Invalid option: ${errorMsg}
6287
+ `));
6288
+ }
6289
+ process.exit(1);
6290
+ }
6291
+ resolvedModel = parsedModel.data ?? null;
6292
+ } else if (bundle.extractedModel) {
6293
+ resolvedModel = bundle.extractedModel;
6294
+ } else if (existingConfig?.aiModel) {
6295
+ resolvedModel = existingConfig.aiModel;
6296
+ }
6297
+ let coverBuffer;
6298
+ let coverFileName;
6299
+ if (options.cover !== void 0 && options.cover !== "") {
6300
+ const resolvedCoverPath = path5.resolve(process.cwd(), options.cover);
6301
+ if (!fs5.existsSync(resolvedCoverPath)) {
6302
+ const errorMsg = `Cover image file does not exist: ${resolvedCoverPath}`;
6303
+ if (isJson) {
6304
+ printErrorJson("INVALID_OPTIONS", errorMsg, 1);
6305
+ } else {
6306
+ console.error(pc3.red(`
6307
+ \u2716 Invalid option: ${errorMsg}
6308
+ `));
6309
+ }
6310
+ process.exit(1);
6311
+ }
6312
+ const stat = fs5.statSync(resolvedCoverPath);
6313
+ if (!stat.isFile()) {
6314
+ const errorMsg = `Specified cover path is not a file: ${resolvedCoverPath}`;
6315
+ if (isJson) {
6316
+ printErrorJson("INVALID_OPTIONS", errorMsg, 1);
6317
+ } else {
6318
+ console.error(pc3.red(`
6319
+ \u2716 Invalid option: ${errorMsg}
6320
+ `));
6321
+ }
6322
+ process.exit(1);
6323
+ }
6324
+ const ext = path5.extname(resolvedCoverPath).toLowerCase().replace(".", "");
6325
+ const allowedExts = ["png", "jpg", "jpeg", "webp", "gif"];
6326
+ if (!allowedExts.includes(ext)) {
6327
+ const errorMsg = `Unsupported cover image format: '.${ext}'. Supported formats are PNG, JPG, JPEG, WebP, GIF.`;
6328
+ if (isJson) {
6329
+ printErrorJson("INVALID_OPTIONS", errorMsg, 1);
6330
+ } else {
6331
+ console.error(pc3.red(`
6332
+ \u2716 Invalid option: ${errorMsg}
6333
+ `));
6334
+ }
6335
+ process.exit(1);
6336
+ }
6337
+ const rawCoverBytes = fs5.readFileSync(resolvedCoverPath);
6338
+ const coverValidation = validateCoverImageBytes(new Uint8Array(rawCoverBytes));
6339
+ if (!coverValidation.valid) {
6340
+ const errorMsg = `Invalid cover image: ${coverValidation.error || "Corrupted image file"}`;
6341
+ if (isJson) {
6342
+ printErrorJson("INVALID_OPTIONS", errorMsg, 1);
6343
+ } else {
6344
+ console.error(pc3.red(`
6345
+ \u2716 Invalid option: ${errorMsg}
6346
+ `));
6347
+ }
6348
+ process.exit(1);
6349
+ }
6350
+ coverBuffer = rawCoverBytes;
6351
+ coverFileName = path5.basename(resolvedCoverPath);
6352
+ } else {
6353
+ const detected = detectSiblingCover(resolvedPath);
6354
+ if (detected) {
6355
+ coverBuffer = detected.buffer;
6356
+ coverFileName = detected.fileName;
6357
+ }
6358
+ }
5907
6359
  let resolvedAspectRatio = "auto";
5908
6360
  if (options.aspectRatio) {
5909
6361
  const norm = normalizeAspectRatio(options.aspectRatio);
@@ -5967,6 +6419,10 @@ async function handlePublish(targetPath = ".", options = {}) {
5967
6419
  supportedPlatforms: resolvedPlatforms,
5968
6420
  manageToken: existingConfig.manageToken,
5969
6421
  token,
6422
+ aiModel: resolvedModel,
6423
+ aiTool,
6424
+ coverBuffer,
6425
+ coverFileName,
5970
6426
  errorMsgFallback: "Failed to update stage"
5971
6427
  });
5972
6428
  const resolvedVis = updateResult.visibility || visibility || existingConfig.visibility;
@@ -5981,7 +6437,9 @@ async function handlePublish(targetPath = ".", options = {}) {
5981
6437
  visibility: resolvedVis,
5982
6438
  aspectRatio: resolvedAspectRatio,
5983
6439
  supportedPlatforms: resolvedPlatforms,
5984
- platforms: resolvedPlatforms
6440
+ platforms: resolvedPlatforms,
6441
+ aiModel: resolvedModel !== void 0 ? resolvedModel : existingConfig.aiModel ?? null,
6442
+ aiTool: aiTool || existingConfig.aiTool
5985
6443
  };
5986
6444
  writeProjectConfig(resolvedPath, updatedConfig);
5987
6445
  if (isJson) {
@@ -5997,6 +6455,8 @@ async function handlePublish(targetPath = ".", options = {}) {
5997
6455
  aspectRatio: updatedConfig.aspectRatio,
5998
6456
  supportedPlatforms: resolvedPlatforms,
5999
6457
  platforms: resolvedPlatforms,
6458
+ aiModel: updatedConfig.aiModel,
6459
+ aiTool: updatedConfig.aiTool,
6000
6460
  promotedToPublic: updateResult.promotedToPublic,
6001
6461
  fileHash: updateResult.fileHash || bundle.fileHash,
6002
6462
  updated: true
@@ -6054,6 +6514,9 @@ async function handlePublish(targetPath = ".", options = {}) {
6054
6514
  tagline,
6055
6515
  description: options.description,
6056
6516
  aiTool,
6517
+ aiModel: resolvedModel,
6518
+ coverBuffer,
6519
+ coverFileName,
6057
6520
  category,
6058
6521
  token,
6059
6522
  fileHash: bundle.fileHash,
@@ -6077,7 +6540,9 @@ async function handlePublish(targetPath = ".", options = {}) {
6077
6540
  visibility: initialVisibility,
6078
6541
  aspectRatio: resolvedAspectRatio,
6079
6542
  supportedPlatforms: resolvedPlatforms,
6080
- platforms: resolvedPlatforms
6543
+ platforms: resolvedPlatforms,
6544
+ aiModel: resolvedModel,
6545
+ aiTool
6081
6546
  });
6082
6547
  if (isJson) {
6083
6548
  printJson({
@@ -6096,7 +6561,9 @@ async function handlePublish(targetPath = ".", options = {}) {
6096
6561
  visibility: initialVisibility,
6097
6562
  aspectRatio: resolvedAspectRatio,
6098
6563
  supportedPlatforms: resolvedPlatforms,
6099
- platforms: resolvedPlatforms
6564
+ platforms: resolvedPlatforms,
6565
+ aiModel: resolvedModel,
6566
+ aiTool
6100
6567
  });
6101
6568
  } else {
6102
6569
  printPublishSuccess({
@@ -6170,7 +6637,7 @@ async function handleValidate(targetPath = ".", options = {}) {
6170
6637
 
6171
6638
  // src/fingerprint.ts
6172
6639
  import crypto3 from "crypto";
6173
- import fs5 from "fs";
6640
+ import fs6 from "fs";
6174
6641
  async function computeFingerprint(input) {
6175
6642
  if (typeof input === "string") {
6176
6643
  return sha256(input);
@@ -6180,17 +6647,23 @@ async function computeFingerprint(input) {
6180
6647
  return hash.digest("hex").toLowerCase();
6181
6648
  }
6182
6649
  async function computeFileFingerprint(filePath) {
6183
- const content = fs5.readFileSync(filePath);
6650
+ const content = fs6.readFileSync(filePath);
6184
6651
  return computeFingerprint(content);
6185
6652
  }
6186
6653
 
6187
6654
  // src/index.ts
6188
6655
  function createProgram() {
6189
6656
  const program = new Command();
6190
- program.name("replaystage").description("ReplayStage CLI: Deploy and share web games from command line and AI agents").version("0.2.0");
6657
+ program.name("replaystage").description("ReplayStage CLI: Deploy and share web games from command line and AI agents").version("0.3.0");
6191
6658
  program.command("publish [path]").description("Package and deploy a web game to ReplayStage").option("-t, --title <title>", "Game title (2-60 characters)").option("-g, --tagline <tagline>", "Catchy one-line arcade tagline (3-120 characters)").option("-d, --description <desc>", "Gameplay instructions or description").option(
6192
6659
  "--tool <tool>",
6193
6660
  "AI tool used to generate the game (claude, gemini, antigravity, cursor, etc.)"
6661
+ ).option(
6662
+ "-m, --model <model>",
6663
+ "AI model used to synthesize the game (e.g., claude-3-7-sonnet, gpt-4o, gemini-2.5-pro)"
6664
+ ).option(
6665
+ "--cover <path>",
6666
+ "Path to custom cartridge cover image (PNG, JPG, WebP, GIF, max 2MB)"
6194
6667
  ).option(
6195
6668
  "--category <category>",
6196
6669
  "Game category (arcade, action, puzzle, racing, 3d, retro, chill)"
@@ -6243,6 +6716,7 @@ if (isDirectCliExecution) {
6243
6716
  void runCli(process.argv);
6244
6717
  }
6245
6718
  export {
6719
+ COVER_PRECEDENCE_FILES,
6246
6720
  checkHtmlDependencies,
6247
6721
  clearConfig,
6248
6722
  clearToken,
@@ -6251,6 +6725,7 @@ export {
6251
6725
  computeSha256,
6252
6726
  createProgram,
6253
6727
  createZipFromFiles,
6728
+ detectSiblingCover,
6254
6729
  extractHtmlMetadata,
6255
6730
  fetchWhoami,
6256
6731
  getConfigDir,
@@ -6273,6 +6748,7 @@ export {
6273
6748
  resolveProjectDirectory,
6274
6749
  resolveToken,
6275
6750
  runCli,
6751
+ writeProjectConfig as saveProjectConfig,
6276
6752
  setToken,
6277
6753
  updateGame,
6278
6754
  updateGameBundle,