@air-jam/cli 0.0.0-stage → 0.9.3
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/LICENSE +21 -0
- package/README.md +145 -2
- package/bin/airjam.mjs +66 -0
- package/dist/ai-pack.d.ts +44 -0
- package/dist/ai-pack.js +15 -0
- package/dist/ai-pack.js.map +1 -0
- package/dist/chunk-A4V2N4LX.js +938 -0
- package/dist/chunk-A4V2N4LX.js.map +1 -0
- package/dist/chunk-J5MAU4QZ.js +102 -0
- package/dist/chunk-J5MAU4QZ.js.map +1 -0
- package/dist/chunk-N7AI7HZK.js +529 -0
- package/dist/chunk-N7AI7HZK.js.map +1 -0
- package/dist/development.d.ts +98 -0
- package/dist/development.js +33 -0
- package/dist/development.js.map +1 -0
- package/dist/documentation.d.ts +27 -0
- package/dist/documentation.js +7 -0
- package/dist/documentation.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2184 -0
- package/dist/index.js.map +1 -0
- package/dist/scaffold.d.ts +6 -0
- package/dist/scaffold.js +20 -0
- package/dist/scaffold.js.map +1 -0
- package/package.json +78 -3
- package/runtime/local-network.d.mts +8 -0
- package/runtime/local-network.mjs +9 -0
- package/runtime/vite-config.d.mts +42 -0
- package/runtime/vite-config.mjs +130 -0
- package/runtime/vite-https.d.mts +11 -0
- package/runtime/vite-https.mjs +41 -0
- package/template-assets/bootstrap/.claude/launch.json +12 -0
- package/template-assets/bootstrap/AGENTS.md +248 -0
- package/template-assets/bootstrap/CLAUDE.md +63 -0
- package/template-assets/bootstrap/_gitignore +6 -0
- package/template-assets/bootstrap/skills/airjam-docs-workflow/SKILL.md +49 -0
- package/template-assets/bootstrap/skills/airjam-mcp/SKILL.md +56 -0
- package/template-assets/bootstrap/skills/canvas-2d-gameplay/SKILL.md +47 -0
- package/template-assets/bootstrap/skills/controller-ui/SKILL.md +69 -0
- package/template-assets/bootstrap/skills/debug-and-test/SKILL.md +72 -0
- package/template-assets/bootstrap/skills/game-architecture/SKILL.md +58 -0
- package/template-assets/bootstrap/skills/game-state-and-rendering/SKILL.md +44 -0
- package/template-assets/bootstrap/skills/host-surface/SKILL.md +52 -0
- package/template-assets/bootstrap/skills/index.md +36 -0
- package/template-assets/bootstrap/skills/prefab-authoring/SKILL.md +48 -0
- package/template-assets/bootstrap/skills/r3f-3d-scene/SKILL.md +51 -0
- package/template-assets/documentation/for-agents/controller-ui/page.mdx +60 -0
- package/template-assets/documentation/for-agents/page.mdx +98 -0
- package/template-assets/documentation/for-agents/project-structure/page.mdx +172 -0
- package/template-assets/documentation/for-agents/state-and-rendering/page.mdx +79 -0
- package/template-assets/documentation/getting-started/debugging/page.mdx +165 -0
- package/template-assets/documentation/getting-started/dev-logs/page.mdx +171 -0
- package/template-assets/documentation/getting-started/game-ideas/page.mdx +116 -0
- package/template-assets/documentation/getting-started/introduction/page.mdx +183 -0
- package/template-assets/documentation/getting-started/migrating-legacy-games/page.mdx +427 -0
- package/template-assets/documentation/getting-started/quick-start/page.mdx +333 -0
- package/template-assets/documentation/how-it-works/architecture/page.mdx +189 -0
- package/template-assets/documentation/how-it-works/host-system/page.mdx +267 -0
- package/template-assets/documentation/manifest.json +430 -0
- package/template-assets/documentation/sdk/hooks/page.mdx +500 -0
- package/template-assets/documentation/sdk/input-system/page.mdx +270 -0
- package/template-assets/documentation/sdk/networked-state/page.mdx +213 -0
- package/template-assets/documentation/sdk/ui-components/page.mdx +227 -0
- package/template-assets/managed/.airjam/ai-pack.json +191 -0
- package/template-assets/managed/docs/airjam/agent-gold-path.md +67 -0
- package/template-assets/managed/docs/airjam/agent-mcp.md +135 -0
- package/template-assets/managed/docs/airjam/canvas-2d-gameplay.md +82 -0
- package/template-assets/managed/docs/airjam/composition-shell-contract.md +87 -0
- package/template-assets/managed/docs/airjam/debug-and-testing.md +86 -0
- package/template-assets/managed/docs/airjam/development-loop.md +51 -0
- package/template-assets/managed/docs/airjam/docs-index.md +58 -0
- package/template-assets/managed/docs/airjam/generated/architecture.md +178 -0
- package/template-assets/managed/docs/airjam/generated/controller-ui.md +61 -0
- package/template-assets/managed/docs/airjam/generated/debugging-and-logs.md +164 -0
- package/template-assets/managed/docs/airjam/generated/for-agents.md +99 -0
- package/template-assets/managed/docs/airjam/generated/game-ideas.md +107 -0
- package/template-assets/managed/docs/airjam/generated/host-system.md +251 -0
- package/template-assets/managed/docs/airjam/generated/input-system.md +260 -0
- package/template-assets/managed/docs/airjam/generated/introduction.md +175 -0
- package/template-assets/managed/docs/airjam/generated/migrating-legacy-games.md +426 -0
- package/template-assets/managed/docs/airjam/generated/networked-state.md +214 -0
- package/template-assets/managed/docs/airjam/generated/project-structure.md +171 -0
- package/template-assets/managed/docs/airjam/generated/quick-start.md +334 -0
- package/template-assets/managed/docs/airjam/generated/sdk-hooks.md +490 -0
- package/template-assets/managed/docs/airjam/generated/state-and-rendering.md +80 -0
- package/template-assets/managed/docs/airjam/generated/ui-components.md +222 -0
- package/template-assets/managed/docs/airjam/generated/unified-dev-logs.md +170 -0
- package/template-assets/managed/docs/airjam/iconography.md +55 -0
- package/template-assets/managed/docs/airjam/prefab-authoring.md +112 -0
- package/template-assets/managed/docs/airjam/preview-controllers.md +126 -0
- package/template-assets/managed/docs/airjam/r3f-3d-scene.md +97 -0
- package/template-assets/managed/docs/airjam/state-lanes-cookbook.md +106 -0
- package/template-assets/managed/docs/airjam/visual-system.md +103 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,2184 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
runAiPackDiff,
|
|
4
|
+
runAiPackRepair,
|
|
5
|
+
runAiPackStatus,
|
|
6
|
+
runAiPackUpdate
|
|
7
|
+
} from "./chunk-N7AI7HZK.js";
|
|
8
|
+
import {
|
|
9
|
+
DEFAULT_GAME_PORT,
|
|
10
|
+
SECURE_MODE_LOCAL,
|
|
11
|
+
SECURE_MODE_TUNNEL,
|
|
12
|
+
buildSecureGameEnv,
|
|
13
|
+
buildStandaloneGameTopology,
|
|
14
|
+
createProcessGroup,
|
|
15
|
+
detectLocalIpv4,
|
|
16
|
+
formatEnvValidationError,
|
|
17
|
+
getFlagValue,
|
|
18
|
+
hasFlag,
|
|
19
|
+
isEnvValidationError,
|
|
20
|
+
isPortOpen,
|
|
21
|
+
loadCreateAirJamRuntimeEnv,
|
|
22
|
+
loadEnvFile,
|
|
23
|
+
loadSecureDevState,
|
|
24
|
+
parseGameDevArgs,
|
|
25
|
+
resolveLocalBackendOrigin,
|
|
26
|
+
runSecureInitCli,
|
|
27
|
+
serializeResolvedTopology,
|
|
28
|
+
waitForPort
|
|
29
|
+
} from "./chunk-A4V2N4LX.js";
|
|
30
|
+
import {
|
|
31
|
+
readDocumentationSnapshot
|
|
32
|
+
} from "./chunk-J5MAU4QZ.js";
|
|
33
|
+
|
|
34
|
+
// src/index.ts
|
|
35
|
+
import {
|
|
36
|
+
getDevStatus,
|
|
37
|
+
resetLocalDev,
|
|
38
|
+
startDev,
|
|
39
|
+
stopDev
|
|
40
|
+
} from "@air-jam/devtools/dev";
|
|
41
|
+
import {
|
|
42
|
+
AirJamPlatformApiError,
|
|
43
|
+
AirJamStoredPlatformSessionError,
|
|
44
|
+
clearStoredPlatformMachineSession,
|
|
45
|
+
getPlatformAuthStoragePath,
|
|
46
|
+
getPlatformMachineProfile,
|
|
47
|
+
loginPlatformWithDeviceFlow,
|
|
48
|
+
logoutPlatformMachineSession,
|
|
49
|
+
readStoredPlatformMachineSession
|
|
50
|
+
} from "@air-jam/devtools/platform-auth";
|
|
51
|
+
import {
|
|
52
|
+
archivePlatformGameMediaAsset,
|
|
53
|
+
inspectPlatformGameMedia,
|
|
54
|
+
uploadPlatformGameMediaFile
|
|
55
|
+
} from "@air-jam/devtools/platform-game-media";
|
|
56
|
+
import {
|
|
57
|
+
createPlatformGame,
|
|
58
|
+
inspectPlatformGame,
|
|
59
|
+
listPlatformGames,
|
|
60
|
+
readLocalHostedGameDefaults,
|
|
61
|
+
updatePlatformGame
|
|
62
|
+
} from "@air-jam/devtools/platform-games";
|
|
63
|
+
import { runCompleteEvaluation } from "@air-jam/devtools/quality";
|
|
64
|
+
import {
|
|
65
|
+
bundleLocalRelease,
|
|
66
|
+
exportPlatformReleaseGeneration,
|
|
67
|
+
finalizePlatformReleaseGeneration,
|
|
68
|
+
inspectLocalRelease,
|
|
69
|
+
inspectPlatformRelease,
|
|
70
|
+
listPlatformReleaseTargets,
|
|
71
|
+
listPlatformReleases,
|
|
72
|
+
publishPlatformRelease,
|
|
73
|
+
submitPlatformRelease,
|
|
74
|
+
uploadPlatformReleaseGeneration,
|
|
75
|
+
validateLocalRelease
|
|
76
|
+
} from "@air-jam/devtools/release";
|
|
77
|
+
import { AIRJAM_PROJECT_MCP_FILE as AIRJAM_PROJECT_MCP_FILE2 } from "@air-jam/devtools/mcp-config";
|
|
78
|
+
import { Command } from "commander";
|
|
79
|
+
import kleur2 from "kleur";
|
|
80
|
+
import path4 from "path";
|
|
81
|
+
|
|
82
|
+
// runtime/game-dev.mjs
|
|
83
|
+
import crossSpawn from "cross-spawn";
|
|
84
|
+
import { execFileSync } from "child_process";
|
|
85
|
+
import fs from "fs";
|
|
86
|
+
import path from "path";
|
|
87
|
+
var START_TIMEOUT_MS = 2e4;
|
|
88
|
+
var PREVIEW_MANAGED_SERVER_LOG_RELATIVE_PATH = path.join(
|
|
89
|
+
".airjam",
|
|
90
|
+
"preview-managed-server.log"
|
|
91
|
+
);
|
|
92
|
+
var PREVIEW_MANAGED_SERVER_STATE_RELATIVE_PATH = path.join(
|
|
93
|
+
".airjam",
|
|
94
|
+
"preview-managed-server.json"
|
|
95
|
+
);
|
|
96
|
+
var holdProcessOpen = async () => {
|
|
97
|
+
await new Promise(() => {
|
|
98
|
+
setInterval(() => {
|
|
99
|
+
}, 1 << 30);
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
var usage = () => {
|
|
103
|
+
console.log(
|
|
104
|
+
"Usage: airjam dev [--secure] [--secure-mode=local|tunnel] [--preview-managed] [--web-only] [--server-only] [--allow-existing-game]"
|
|
105
|
+
);
|
|
106
|
+
console.log("");
|
|
107
|
+
console.log("Modes:");
|
|
108
|
+
console.log(
|
|
109
|
+
" default Start local server + game (recommended)"
|
|
110
|
+
);
|
|
111
|
+
console.log(" --secure Start secure local game dev");
|
|
112
|
+
console.log(
|
|
113
|
+
" --secure-mode=tunnel Use Cloudflare tunnel fallback instead of local-only secure host"
|
|
114
|
+
);
|
|
115
|
+
console.log(
|
|
116
|
+
" --preview-managed Start background server + foreground Vite for preview/browser launch tools"
|
|
117
|
+
);
|
|
118
|
+
console.log(" --web-only Start only the game app");
|
|
119
|
+
console.log(" --server-only Start only the local Air Jam server");
|
|
120
|
+
console.log(
|
|
121
|
+
" --allow-existing-game Reuse an already-running Vite server on the game port"
|
|
122
|
+
);
|
|
123
|
+
console.log("");
|
|
124
|
+
console.log("Network isolation:");
|
|
125
|
+
console.log(" VITE_PORT Game app port (default: 5173)");
|
|
126
|
+
console.log(" AIR_JAM_SERVER_PORT Local server port (default: 4000)");
|
|
127
|
+
console.log(" VITE_AIR_JAM_PUBLIC_HOST Explicit host/controller origin");
|
|
128
|
+
};
|
|
129
|
+
var getDefaultPublicHost = (env, gamePort) => {
|
|
130
|
+
const explicitPublicHost = env.VITE_AIR_JAM_PUBLIC_HOST;
|
|
131
|
+
if (explicitPublicHost) {
|
|
132
|
+
return explicitPublicHost;
|
|
133
|
+
}
|
|
134
|
+
const detectedIp = detectLocalIpv4();
|
|
135
|
+
if (!detectedIp) {
|
|
136
|
+
console.warn(
|
|
137
|
+
"[dev] Could not detect LAN IP. Falling back to localhost in QR links."
|
|
138
|
+
);
|
|
139
|
+
console.warn(
|
|
140
|
+
"[dev] Set VITE_AIR_JAM_PUBLIC_HOST manually for phone testing."
|
|
141
|
+
);
|
|
142
|
+
return `http://localhost:${gamePort}`;
|
|
143
|
+
}
|
|
144
|
+
return `http://${detectedIp}:${gamePort}`;
|
|
145
|
+
};
|
|
146
|
+
var readListeningPid = (port) => {
|
|
147
|
+
try {
|
|
148
|
+
const output = execFileSync(
|
|
149
|
+
"lsof",
|
|
150
|
+
["-nP", `-tiTCP:${port}`, "-sTCP:LISTEN"],
|
|
151
|
+
{
|
|
152
|
+
encoding: "utf8",
|
|
153
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
154
|
+
}
|
|
155
|
+
).trim().split("\n").find(Boolean);
|
|
156
|
+
const pid = Number.parseInt(output ?? "", 10);
|
|
157
|
+
return Number.isInteger(pid) && pid > 0 ? pid : null;
|
|
158
|
+
} catch {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
var readProcessSummary = (pid) => {
|
|
163
|
+
if (!pid) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
try {
|
|
167
|
+
const command = execFileSync("ps", ["-p", String(pid), "-o", "command="], {
|
|
168
|
+
encoding: "utf8",
|
|
169
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
170
|
+
}).trim();
|
|
171
|
+
const etimesOutput = execFileSync(
|
|
172
|
+
"ps",
|
|
173
|
+
["-p", String(pid), "-o", "etimes="],
|
|
174
|
+
{
|
|
175
|
+
encoding: "utf8",
|
|
176
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
177
|
+
}
|
|
178
|
+
).trim();
|
|
179
|
+
const ageSeconds = Number.parseInt(etimesOutput, 10);
|
|
180
|
+
return {
|
|
181
|
+
pid,
|
|
182
|
+
command: command || null,
|
|
183
|
+
ageSeconds: Number.isFinite(ageSeconds) ? ageSeconds : null
|
|
184
|
+
};
|
|
185
|
+
} catch {
|
|
186
|
+
return { pid, command: null, ageSeconds: null };
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
var formatProcessSummary = (summary) => {
|
|
190
|
+
if (!summary) {
|
|
191
|
+
return "unknown process";
|
|
192
|
+
}
|
|
193
|
+
const age = typeof summary.ageSeconds === "number" ? `, age ${Math.floor(summary.ageSeconds / 60)}m${summary.ageSeconds % 60}s` : "";
|
|
194
|
+
const command = summary.command ? `, command: ${summary.command}` : "";
|
|
195
|
+
return `pid ${summary.pid}${age}${command}`;
|
|
196
|
+
};
|
|
197
|
+
var startServerIfNeeded = async (processGroup, serverPort, env) => {
|
|
198
|
+
const hasExistingServer = await isPortOpen(serverPort);
|
|
199
|
+
if (hasExistingServer) {
|
|
200
|
+
const summary = readProcessSummary(readListeningPid(serverPort));
|
|
201
|
+
console.warn(
|
|
202
|
+
`[dev] Reusing existing server on :${serverPort} (${formatProcessSummary(summary)}). If this looks stale, run "pnpm exec airjam reset local".`
|
|
203
|
+
);
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
processGroup.run("server", "pnpm", ["exec", "air-jam-server"], {
|
|
207
|
+
env: {
|
|
208
|
+
...process.env,
|
|
209
|
+
...env,
|
|
210
|
+
PORT: String(serverPort)
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
await waitForPort(serverPort, START_TIMEOUT_MS);
|
|
214
|
+
return true;
|
|
215
|
+
};
|
|
216
|
+
var startGameIfNeeded = async (processGroup, { gamePort, env, allowExistingGame }) => {
|
|
217
|
+
const hasExistingGame = await isPortOpen(gamePort);
|
|
218
|
+
if (hasExistingGame) {
|
|
219
|
+
if (allowExistingGame) {
|
|
220
|
+
console.log(`[dev] Reusing existing game on :${gamePort}`);
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
throw new Error(
|
|
224
|
+
`Port ${gamePort} is already in use. Stop the existing Vite dev server and retry.`
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
processGroup.run("game", "pnpm", ["exec", "vite"], {
|
|
228
|
+
env: {
|
|
229
|
+
...process.env,
|
|
230
|
+
...env
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
await waitForPort(gamePort, START_TIMEOUT_MS);
|
|
234
|
+
return true;
|
|
235
|
+
};
|
|
236
|
+
var ensurePreviewManagedServer = async ({ cwd, serverPort, env }) => {
|
|
237
|
+
const hasExistingServer = await isPortOpen(serverPort);
|
|
238
|
+
if (hasExistingServer) {
|
|
239
|
+
const summary = readProcessSummary(readListeningPid(serverPort));
|
|
240
|
+
console.warn(
|
|
241
|
+
`[dev] Reusing existing preview-managed server on :${serverPort} (${formatProcessSummary(summary)}). If this looks stale, run "pnpm exec airjam reset local".`
|
|
242
|
+
);
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
const airJamDir = path.join(cwd, ".airjam");
|
|
246
|
+
fs.mkdirSync(airJamDir, { recursive: true });
|
|
247
|
+
const logFile = path.join(cwd, PREVIEW_MANAGED_SERVER_LOG_RELATIVE_PATH);
|
|
248
|
+
const stateFile = path.join(cwd, PREVIEW_MANAGED_SERVER_STATE_RELATIVE_PATH);
|
|
249
|
+
const logFd = fs.openSync(logFile, "a");
|
|
250
|
+
const child = crossSpawn("pnpm", ["exec", "air-jam-server"], {
|
|
251
|
+
cwd,
|
|
252
|
+
env: {
|
|
253
|
+
...process.env,
|
|
254
|
+
...env,
|
|
255
|
+
PORT: String(serverPort)
|
|
256
|
+
},
|
|
257
|
+
detached: true,
|
|
258
|
+
stdio: ["ignore", logFd, logFd]
|
|
259
|
+
});
|
|
260
|
+
child.unref();
|
|
261
|
+
fs.closeSync(logFd);
|
|
262
|
+
fs.writeFileSync(
|
|
263
|
+
stateFile,
|
|
264
|
+
`${JSON.stringify(
|
|
265
|
+
{
|
|
266
|
+
pid: child.pid,
|
|
267
|
+
port: serverPort,
|
|
268
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
269
|
+
logFile
|
|
270
|
+
},
|
|
271
|
+
null,
|
|
272
|
+
2
|
|
273
|
+
)}
|
|
274
|
+
`,
|
|
275
|
+
"utf8"
|
|
276
|
+
);
|
|
277
|
+
console.log(
|
|
278
|
+
`[dev] Started preview-managed background server on :${serverPort}`
|
|
279
|
+
);
|
|
280
|
+
console.log(`[dev] Background server log: ${logFile}`);
|
|
281
|
+
return true;
|
|
282
|
+
};
|
|
283
|
+
var runForegroundGame = ({ cwd, env }) => new Promise((resolve, reject) => {
|
|
284
|
+
const child = crossSpawn("pnpm", ["exec", "vite"], {
|
|
285
|
+
cwd,
|
|
286
|
+
stdio: "inherit",
|
|
287
|
+
env: {
|
|
288
|
+
...process.env,
|
|
289
|
+
...env
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
child.on("error", reject);
|
|
293
|
+
child.on("exit", (code, signal) => {
|
|
294
|
+
if (signal) {
|
|
295
|
+
process.kill(process.pid, signal);
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
resolve(code ?? 0);
|
|
299
|
+
});
|
|
300
|
+
process.on("SIGINT", () => child.kill("SIGINT"));
|
|
301
|
+
process.on("SIGTERM", () => child.kill("SIGTERM"));
|
|
302
|
+
});
|
|
303
|
+
var readPreviewProxyTargetPort = (publicPort) => {
|
|
304
|
+
try {
|
|
305
|
+
const lsofOutput = execFileSync(
|
|
306
|
+
"lsof",
|
|
307
|
+
["-nP", `-iTCP:${publicPort}`, "-sTCP:LISTEN", "-Fp"],
|
|
308
|
+
{
|
|
309
|
+
encoding: "utf8",
|
|
310
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
311
|
+
}
|
|
312
|
+
);
|
|
313
|
+
const pidMatch = lsofOutput.match(/^p(\d+)$/m);
|
|
314
|
+
if (!pidMatch) {
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
317
|
+
const command = execFileSync("ps", ["-p", pidMatch[1], "-o", "command="], {
|
|
318
|
+
encoding: "utf8",
|
|
319
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
320
|
+
}).trim();
|
|
321
|
+
const proxyMatch = command.match(/preview-proxy\.mjs\s+(\d+)\s+(\d+)\b/);
|
|
322
|
+
if (!proxyMatch) {
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
325
|
+
const proxyPublicPort = Number(proxyMatch[1]);
|
|
326
|
+
const proxyTargetPort = Number(proxyMatch[2]);
|
|
327
|
+
if (!Number.isInteger(proxyPublicPort) || !Number.isInteger(proxyTargetPort) || proxyPublicPort !== publicPort) {
|
|
328
|
+
return null;
|
|
329
|
+
}
|
|
330
|
+
return proxyTargetPort;
|
|
331
|
+
} catch {
|
|
332
|
+
return null;
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
var resolvePreviewManagedPorts = async ({ port }) => {
|
|
336
|
+
const publicPort = port;
|
|
337
|
+
const publicPortInUse = await isPortOpen(publicPort);
|
|
338
|
+
if (!publicPortInUse) {
|
|
339
|
+
return {
|
|
340
|
+
publicPort,
|
|
341
|
+
vitePort: publicPort,
|
|
342
|
+
usesPreviewProxy: false
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
const proxyTargetPort = readPreviewProxyTargetPort(publicPort);
|
|
346
|
+
if (!proxyTargetPort) {
|
|
347
|
+
throw new Error(
|
|
348
|
+
`Port ${publicPort} is already in use. Close the existing process or choose a different VITE_PORT before running preview-managed dev.`
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
const targetPortInUse = await isPortOpen(proxyTargetPort);
|
|
352
|
+
if (targetPortInUse) {
|
|
353
|
+
throw new Error(
|
|
354
|
+
`Preview proxy port ${publicPort} is already forwarding to ${proxyTargetPort}, but that target port is also busy. Close the existing preview stack and retry.`
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
return {
|
|
358
|
+
publicPort,
|
|
359
|
+
vitePort: proxyTargetPort,
|
|
360
|
+
usesPreviewProxy: true
|
|
361
|
+
};
|
|
362
|
+
};
|
|
363
|
+
var validateGameDevMode = ({ args }) => {
|
|
364
|
+
if (args.webOnly && args.serverOnly) {
|
|
365
|
+
throw new Error("Cannot combine --web-only and --server-only.");
|
|
366
|
+
}
|
|
367
|
+
if (args.previewManaged && args.webOnly) {
|
|
368
|
+
throw new Error("Cannot combine --preview-managed and --web-only.");
|
|
369
|
+
}
|
|
370
|
+
if (args.previewManaged && args.serverOnly) {
|
|
371
|
+
throw new Error("Cannot combine --preview-managed and --server-only.");
|
|
372
|
+
}
|
|
373
|
+
if (args.previewManaged && args.allowExistingGame) {
|
|
374
|
+
throw new Error(
|
|
375
|
+
"Cannot combine --preview-managed and --allow-existing-game."
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
if (args.previewManaged && args.secure) {
|
|
379
|
+
throw new Error(
|
|
380
|
+
"Preview-managed mode does not support --secure. Use the normal `pnpm run dev` flow instead."
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
var runGameDevCli = async ({
|
|
385
|
+
cwd = process.cwd(),
|
|
386
|
+
argv = process.argv.slice(2),
|
|
387
|
+
env = process.env
|
|
388
|
+
} = {}) => {
|
|
389
|
+
loadEnvFile(path.join(cwd, ".env"), env);
|
|
390
|
+
loadEnvFile(path.join(cwd, ".env.local"), env);
|
|
391
|
+
const runtimeEnv = loadCreateAirJamRuntimeEnv({
|
|
392
|
+
env,
|
|
393
|
+
boundary: "create-airjam.dev"
|
|
394
|
+
});
|
|
395
|
+
const serverPort = runtimeEnv.AIR_JAM_SERVER_PORT;
|
|
396
|
+
const backendOrigin = resolveLocalBackendOrigin(runtimeEnv);
|
|
397
|
+
const secureRootDir = runtimeEnv.AIR_JAM_SECURE_ROOT ? path.resolve(cwd, runtimeEnv.AIR_JAM_SECURE_ROOT) : cwd;
|
|
398
|
+
const help = hasFlag(argv, "--help") || hasFlag(argv, "-h");
|
|
399
|
+
if (help) {
|
|
400
|
+
usage();
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
const args = parseGameDevArgs(argv, runtimeEnv);
|
|
404
|
+
validateGameDevMode({ args });
|
|
405
|
+
const requestedGamePort = args.port || DEFAULT_GAME_PORT;
|
|
406
|
+
const previewManagedPorts = args.previewManaged ? await resolvePreviewManagedPorts({ port: requestedGamePort }) : null;
|
|
407
|
+
const publicGamePort = previewManagedPorts?.publicPort ?? requestedGamePort;
|
|
408
|
+
const viteGamePort = previewManagedPorts?.vitePort ?? requestedGamePort;
|
|
409
|
+
const processGroup = createProcessGroup();
|
|
410
|
+
processGroup.registerSignalHandlers();
|
|
411
|
+
try {
|
|
412
|
+
let secureState = null;
|
|
413
|
+
if (args.secure) {
|
|
414
|
+
secureState = loadSecureDevState({
|
|
415
|
+
cwd: secureRootDir,
|
|
416
|
+
mode: args.secureMode,
|
|
417
|
+
env: runtimeEnv,
|
|
418
|
+
gamePort: args.port
|
|
419
|
+
});
|
|
420
|
+
console.log(`[dev] Secure mode: ${secureState.mode}`);
|
|
421
|
+
console.log(`[dev] Public host: ${secureState.publicHost}`);
|
|
422
|
+
}
|
|
423
|
+
validateGameDevMode({ args });
|
|
424
|
+
const gameEnv = args.secure ? buildSecureGameEnv({
|
|
425
|
+
secureState,
|
|
426
|
+
webOnly: args.webOnly,
|
|
427
|
+
env: runtimeEnv,
|
|
428
|
+
backendOrigin
|
|
429
|
+
}) : {
|
|
430
|
+
VITE_AIR_JAM_RUNTIME_TOPOLOGY: serializeResolvedTopology(
|
|
431
|
+
buildStandaloneGameTopology({
|
|
432
|
+
surfaceRole: "host",
|
|
433
|
+
publicHost: getDefaultPublicHost(env, publicGamePort),
|
|
434
|
+
backendOrigin
|
|
435
|
+
})
|
|
436
|
+
),
|
|
437
|
+
VITE_AIR_JAM_PUBLIC_HOST: getDefaultPublicHost(env, publicGamePort),
|
|
438
|
+
VITE_AIR_JAM_SERVER_URL: backendOrigin,
|
|
439
|
+
AIR_JAM_DEV_PROXY_BACKEND_URL: backendOrigin,
|
|
440
|
+
VITE_PORT: String(viteGamePort),
|
|
441
|
+
...args.webOnly && runtimeEnv.VITE_AIR_JAM_SERVER_URL ? {
|
|
442
|
+
VITE_AIR_JAM_SERVER_URL: runtimeEnv.VITE_AIR_JAM_SERVER_URL
|
|
443
|
+
} : {}
|
|
444
|
+
};
|
|
445
|
+
if (args.previewManaged) {
|
|
446
|
+
await ensurePreviewManagedServer({
|
|
447
|
+
cwd,
|
|
448
|
+
serverPort,
|
|
449
|
+
env: runtimeEnv
|
|
450
|
+
});
|
|
451
|
+
if (previewManagedPorts?.usesPreviewProxy) {
|
|
452
|
+
console.log(
|
|
453
|
+
`[dev] Detected browser preview proxy on :${publicGamePort}; binding Vite to :${viteGamePort} behind it.`
|
|
454
|
+
);
|
|
455
|
+
}
|
|
456
|
+
console.log(
|
|
457
|
+
"[dev] Preview-managed mode: foreground Vite is ready for browser/preview launch tools."
|
|
458
|
+
);
|
|
459
|
+
const exitCode = await runForegroundGame({
|
|
460
|
+
cwd,
|
|
461
|
+
env: gameEnv
|
|
462
|
+
});
|
|
463
|
+
process.exit(exitCode);
|
|
464
|
+
}
|
|
465
|
+
let startedServer = false;
|
|
466
|
+
if (!args.webOnly) {
|
|
467
|
+
startedServer = await startServerIfNeeded(
|
|
468
|
+
processGroup,
|
|
469
|
+
serverPort,
|
|
470
|
+
runtimeEnv
|
|
471
|
+
);
|
|
472
|
+
} else {
|
|
473
|
+
console.log(
|
|
474
|
+
"[dev] Web-only mode: skipping local Air Jam server startup."
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
let startedGame = false;
|
|
478
|
+
if (!args.serverOnly) {
|
|
479
|
+
startedGame = await startGameIfNeeded(processGroup, {
|
|
480
|
+
gamePort: viteGamePort,
|
|
481
|
+
env: gameEnv,
|
|
482
|
+
allowExistingGame: args.allowExistingGame
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
if (args.secure && secureState.mode === SECURE_MODE_TUNNEL) {
|
|
486
|
+
processGroup.run("cloudflared", "cloudflared", [
|
|
487
|
+
"tunnel",
|
|
488
|
+
"--config",
|
|
489
|
+
path.join(secureRootDir, ".cloudflared/config.yml"),
|
|
490
|
+
"run",
|
|
491
|
+
secureState.tunnelName
|
|
492
|
+
]);
|
|
493
|
+
console.log(`Cloudflare tunnel: ${secureState.tunnelName}`);
|
|
494
|
+
}
|
|
495
|
+
if (!startedServer && !startedGame) {
|
|
496
|
+
await holdProcessOpen();
|
|
497
|
+
}
|
|
498
|
+
} catch (error) {
|
|
499
|
+
processGroup.shutdown(1);
|
|
500
|
+
throw error;
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
// runtime/topology.mjs
|
|
505
|
+
import { resolveProjectRuntimeTopology } from "@air-jam/sdk/runtime-topology";
|
|
506
|
+
import path2 from "path";
|
|
507
|
+
var SUPPORTED_MODES = /* @__PURE__ */ new Set([
|
|
508
|
+
"standalone-dev",
|
|
509
|
+
"self-hosted-production",
|
|
510
|
+
"hosted-release"
|
|
511
|
+
]);
|
|
512
|
+
var getDefaultStandalonePublicHost = (env, gamePort) => {
|
|
513
|
+
const explicitPublicHost = env.VITE_AIR_JAM_PUBLIC_HOST;
|
|
514
|
+
if (explicitPublicHost) {
|
|
515
|
+
return explicitPublicHost;
|
|
516
|
+
}
|
|
517
|
+
const detectedIp = detectLocalIpv4();
|
|
518
|
+
if (!detectedIp) {
|
|
519
|
+
return `http://localhost:${gamePort}`;
|
|
520
|
+
}
|
|
521
|
+
return `http://${detectedIp}:${gamePort}`;
|
|
522
|
+
};
|
|
523
|
+
var requireConfiguredAppOrigin = (env, mode) => {
|
|
524
|
+
const appOrigin = env.VITE_AIR_JAM_PUBLIC_HOST || env.NEXT_PUBLIC_APP_URL;
|
|
525
|
+
if (appOrigin) {
|
|
526
|
+
return appOrigin;
|
|
527
|
+
}
|
|
528
|
+
throw new Error(
|
|
529
|
+
`Mode "${mode}" requires VITE_AIR_JAM_PUBLIC_HOST (or NEXT_PUBLIC_APP_URL) to be set.`
|
|
530
|
+
);
|
|
531
|
+
};
|
|
532
|
+
var resolveProjectSurfaceTopology = ({
|
|
533
|
+
runtimeMode,
|
|
534
|
+
secure,
|
|
535
|
+
env,
|
|
536
|
+
surfaceRole,
|
|
537
|
+
cwd
|
|
538
|
+
}) => {
|
|
539
|
+
if (runtimeMode === "standalone-dev") {
|
|
540
|
+
const gamePort = env.VITE_PORT ?? DEFAULT_GAME_PORT;
|
|
541
|
+
const secureState = secure ? loadSecureDevState({
|
|
542
|
+
cwd,
|
|
543
|
+
mode: SECURE_MODE_LOCAL,
|
|
544
|
+
env,
|
|
545
|
+
gamePort
|
|
546
|
+
}) : null;
|
|
547
|
+
const publicHost = secure ? secureState.publicHost : getDefaultStandalonePublicHost(env, gamePort);
|
|
548
|
+
return resolveProjectRuntimeTopology({
|
|
549
|
+
runtimeMode: secure ? "standalone-secure" : "standalone-dev",
|
|
550
|
+
surfaceRole,
|
|
551
|
+
appOrigin: publicHost,
|
|
552
|
+
backendOrigin: resolveLocalBackendOrigin(env),
|
|
553
|
+
publicHost,
|
|
554
|
+
secureTransport: secure
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
const appOrigin = requireConfiguredAppOrigin(env, runtimeMode);
|
|
558
|
+
return resolveProjectRuntimeTopology({
|
|
559
|
+
runtimeMode,
|
|
560
|
+
surfaceRole,
|
|
561
|
+
appOrigin,
|
|
562
|
+
backendOrigin: env.VITE_AIR_JAM_SERVER_URL || appOrigin,
|
|
563
|
+
publicHost: env.VITE_AIR_JAM_PUBLIC_HOST || appOrigin
|
|
564
|
+
});
|
|
565
|
+
};
|
|
566
|
+
var runProjectTopologyCli = async ({
|
|
567
|
+
cwd = process.cwd(),
|
|
568
|
+
argv = process.argv.slice(2),
|
|
569
|
+
env = process.env
|
|
570
|
+
} = {}) => {
|
|
571
|
+
if (hasFlag(argv, "--help") || hasFlag(argv, "-h")) {
|
|
572
|
+
console.log("Usage: airjam topology --mode=<mode> [--secure]");
|
|
573
|
+
console.log("");
|
|
574
|
+
console.log("Modes:");
|
|
575
|
+
console.log(
|
|
576
|
+
" standalone-dev Resolve standalone local game topology"
|
|
577
|
+
);
|
|
578
|
+
console.log(
|
|
579
|
+
" self-hosted-production Resolve self-hosted production topology"
|
|
580
|
+
);
|
|
581
|
+
console.log(
|
|
582
|
+
" hosted-release Resolve hosted Air Jam release topology"
|
|
583
|
+
);
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
loadEnvFile(path2.join(cwd, ".env"), env);
|
|
587
|
+
loadEnvFile(path2.join(cwd, ".env.local"), env);
|
|
588
|
+
const runtimeEnv = loadCreateAirJamRuntimeEnv({
|
|
589
|
+
env,
|
|
590
|
+
boundary: "create-airjam.topology"
|
|
591
|
+
});
|
|
592
|
+
const mode = getFlagValue(argv, "--mode")?.trim();
|
|
593
|
+
if (!mode || !SUPPORTED_MODES.has(mode)) {
|
|
594
|
+
throw new Error(
|
|
595
|
+
"Missing or unsupported --mode. Use standalone-dev, self-hosted-production, or hosted-release."
|
|
596
|
+
);
|
|
597
|
+
}
|
|
598
|
+
const secure = hasFlag(argv, "--secure");
|
|
599
|
+
if (secure && mode !== "standalone-dev") {
|
|
600
|
+
throw new Error(
|
|
601
|
+
`--secure is only supported with --mode=standalone-dev. ${mode} should express transport through its configured URL values.`
|
|
602
|
+
);
|
|
603
|
+
}
|
|
604
|
+
const surfaces = Object.fromEntries(
|
|
605
|
+
["host", "controller"].map((surfaceRole) => [
|
|
606
|
+
surfaceRole,
|
|
607
|
+
resolveProjectSurfaceTopology({
|
|
608
|
+
runtimeMode: mode,
|
|
609
|
+
secure,
|
|
610
|
+
env: runtimeEnv,
|
|
611
|
+
surfaceRole,
|
|
612
|
+
cwd
|
|
613
|
+
})
|
|
614
|
+
])
|
|
615
|
+
);
|
|
616
|
+
process.stdout.write(
|
|
617
|
+
`${JSON.stringify(
|
|
618
|
+
{
|
|
619
|
+
mode,
|
|
620
|
+
secure,
|
|
621
|
+
surfaces
|
|
622
|
+
},
|
|
623
|
+
null,
|
|
624
|
+
2
|
|
625
|
+
)}
|
|
626
|
+
`
|
|
627
|
+
);
|
|
628
|
+
};
|
|
629
|
+
|
|
630
|
+
// src/mcp.ts
|
|
631
|
+
import { inspectProject } from "@air-jam/devtools/context";
|
|
632
|
+
import {
|
|
633
|
+
AIRJAM_PROJECT_MCP_FILE,
|
|
634
|
+
inspectMcpProjectSetup,
|
|
635
|
+
renderMcpClientProfile,
|
|
636
|
+
writeProjectLocalMcpConfig
|
|
637
|
+
} from "@air-jam/devtools/mcp-config";
|
|
638
|
+
import kleur from "kleur";
|
|
639
|
+
var printConfigSnippet = (value) => {
|
|
640
|
+
console.log(JSON.stringify(value, null, 2));
|
|
641
|
+
};
|
|
642
|
+
var runMcpDoctor = async ({
|
|
643
|
+
dir,
|
|
644
|
+
json = false
|
|
645
|
+
}) => {
|
|
646
|
+
const project = await inspectProject({ cwd: dir });
|
|
647
|
+
const setup = await inspectMcpProjectSetup({ cwd: dir });
|
|
648
|
+
if (json) {
|
|
649
|
+
process.stdout.write(
|
|
650
|
+
`${JSON.stringify({ projectMode: project.context.mode, ...setup }, null, 2)}
|
|
651
|
+
`
|
|
652
|
+
);
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
console.log(kleur.cyan("Air Jam MCP doctor\n"));
|
|
656
|
+
console.log(`Project root: ${setup.projectDir}`);
|
|
657
|
+
console.log(`Project mode: ${project.context.mode}`);
|
|
658
|
+
console.log(
|
|
659
|
+
`MCP dependency: ${setup.package.dependencyPresent ? kleur.green("present") : kleur.yellow("missing")}`
|
|
660
|
+
);
|
|
661
|
+
console.log(
|
|
662
|
+
`MCP script: ${setup.package.scriptPresent ? kleur.green("present") : kleur.yellow("missing")}`
|
|
663
|
+
);
|
|
664
|
+
console.log(
|
|
665
|
+
`Portable declaration: ${setup.portableDeclaration.present ? kleur.green(setup.portableDeclaration.configPath) : kleur.yellow(`missing (${AIRJAM_PROJECT_MCP_FILE})`)}`
|
|
666
|
+
);
|
|
667
|
+
console.log(
|
|
668
|
+
`Codex registration: ${setup.clients.codex.registered ? kleur.green("present") : kleur.yellow("missing")}`
|
|
669
|
+
);
|
|
670
|
+
console.log(
|
|
671
|
+
`Claude Desktop registration: ${setup.clients.claudeDesktop.registered ? kleur.green("present") : kleur.yellow("missing")}`
|
|
672
|
+
);
|
|
673
|
+
console.log("");
|
|
674
|
+
console.log("Recommended project-local MCP config:\n");
|
|
675
|
+
printConfigSnippet(setup.recommendedConfig);
|
|
676
|
+
};
|
|
677
|
+
var runMcpInit = async ({
|
|
678
|
+
dir,
|
|
679
|
+
force,
|
|
680
|
+
json = false
|
|
681
|
+
}) => {
|
|
682
|
+
const inspection = await writeProjectLocalMcpConfig({
|
|
683
|
+
cwd: dir,
|
|
684
|
+
force: force === true
|
|
685
|
+
});
|
|
686
|
+
if (json) {
|
|
687
|
+
process.stdout.write(`${JSON.stringify(inspection, null, 2)}
|
|
688
|
+
`);
|
|
689
|
+
} else {
|
|
690
|
+
console.log(
|
|
691
|
+
kleur.green(
|
|
692
|
+
`Wrote portable MCP declaration to ${inspection.portableDeclaration.configPath}`
|
|
693
|
+
)
|
|
694
|
+
);
|
|
695
|
+
}
|
|
696
|
+
};
|
|
697
|
+
var runMcpConfig = async ({
|
|
698
|
+
dir,
|
|
699
|
+
profile = "portable",
|
|
700
|
+
json = false
|
|
701
|
+
}) => {
|
|
702
|
+
if (!["portable", "codex", "claude-desktop"].includes(profile)) {
|
|
703
|
+
throw new Error(
|
|
704
|
+
`Unknown MCP profile "${profile}". Use portable, codex, or claude-desktop.`
|
|
705
|
+
);
|
|
706
|
+
}
|
|
707
|
+
const setup = await inspectMcpProjectSetup({ cwd: dir });
|
|
708
|
+
const rendered = renderMcpClientProfile({
|
|
709
|
+
profile,
|
|
710
|
+
projectDir: setup.projectDir
|
|
711
|
+
});
|
|
712
|
+
process.stdout.write(
|
|
713
|
+
json ? `${JSON.stringify(rendered, null, 2)}
|
|
714
|
+
` : rendered.content
|
|
715
|
+
);
|
|
716
|
+
};
|
|
717
|
+
|
|
718
|
+
// src/session.ts
|
|
719
|
+
import { inspectProject as inspectProject2 } from "@air-jam/devtools/context";
|
|
720
|
+
import {
|
|
721
|
+
readGameSessionBrokerState,
|
|
722
|
+
requestGameSessionBroker,
|
|
723
|
+
resolveGameSessionBrokerStatePath,
|
|
724
|
+
runGameSessionBroker
|
|
725
|
+
} from "@air-jam/devtools/game-session-broker";
|
|
726
|
+
import { spawn } from "child_process";
|
|
727
|
+
import { closeSync, mkdirSync, openSync } from "fs";
|
|
728
|
+
import { unlink } from "fs/promises";
|
|
729
|
+
import path3 from "path";
|
|
730
|
+
var BROKER_START_TIMEOUT_MS = 1e4;
|
|
731
|
+
var resolveProjectDir = async (dir) => {
|
|
732
|
+
const project = await inspectProject2({ cwd: dir });
|
|
733
|
+
return project.context.rootDir;
|
|
734
|
+
};
|
|
735
|
+
var readHealth = async (state) => requestGameSessionBroker({
|
|
736
|
+
state,
|
|
737
|
+
request: { operation: "health" }
|
|
738
|
+
}).catch(() => null);
|
|
739
|
+
var ensureBroker = async (projectDir) => {
|
|
740
|
+
const existing = await readGameSessionBrokerState(projectDir);
|
|
741
|
+
if (existing && await readHealth(existing)) {
|
|
742
|
+
return existing;
|
|
743
|
+
}
|
|
744
|
+
await unlink(resolveGameSessionBrokerStatePath(projectDir)).catch(
|
|
745
|
+
() => void 0
|
|
746
|
+
);
|
|
747
|
+
const entryPath = process.argv[1];
|
|
748
|
+
if (!entryPath) {
|
|
749
|
+
throw new Error("Cannot resolve the current airjam CLI entrypoint.");
|
|
750
|
+
}
|
|
751
|
+
const logDir = path3.join(projectDir, ".airjam", "logs");
|
|
752
|
+
mkdirSync(logDir, { recursive: true });
|
|
753
|
+
const logFd = openSync(
|
|
754
|
+
path3.join(logDir, "game-session-broker.log"),
|
|
755
|
+
"a",
|
|
756
|
+
384
|
|
757
|
+
);
|
|
758
|
+
try {
|
|
759
|
+
const child = spawn(
|
|
760
|
+
process.execPath,
|
|
761
|
+
[entryPath, "__session-broker", "--dir", projectDir],
|
|
762
|
+
{
|
|
763
|
+
cwd: projectDir,
|
|
764
|
+
detached: true,
|
|
765
|
+
stdio: ["ignore", logFd, logFd]
|
|
766
|
+
}
|
|
767
|
+
);
|
|
768
|
+
child.unref();
|
|
769
|
+
} finally {
|
|
770
|
+
closeSync(logFd);
|
|
771
|
+
}
|
|
772
|
+
const startedAt = Date.now();
|
|
773
|
+
while (Date.now() - startedAt < BROKER_START_TIMEOUT_MS) {
|
|
774
|
+
const state = await readGameSessionBrokerState(projectDir);
|
|
775
|
+
if (state && await readHealth(state)) {
|
|
776
|
+
return state;
|
|
777
|
+
}
|
|
778
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
779
|
+
}
|
|
780
|
+
throw new Error(
|
|
781
|
+
`Air Jam game session broker did not start. Inspect ${path3.join(logDir, "game-session-broker.log")}.`
|
|
782
|
+
);
|
|
783
|
+
};
|
|
784
|
+
var request = async ({
|
|
785
|
+
dir,
|
|
786
|
+
operation
|
|
787
|
+
}) => {
|
|
788
|
+
const projectDir = await resolveProjectDir(dir);
|
|
789
|
+
const state = await ensureBroker(projectDir);
|
|
790
|
+
return requestGameSessionBroker({ state, request: operation });
|
|
791
|
+
};
|
|
792
|
+
var parseJsonValue = (value) => {
|
|
793
|
+
try {
|
|
794
|
+
return JSON.parse(value);
|
|
795
|
+
} catch {
|
|
796
|
+
return value;
|
|
797
|
+
}
|
|
798
|
+
};
|
|
799
|
+
var parseJsonObject = (value) => {
|
|
800
|
+
const parsed = JSON.parse(value);
|
|
801
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
802
|
+
throw new Error("Expected a JSON object.");
|
|
803
|
+
}
|
|
804
|
+
return parsed;
|
|
805
|
+
};
|
|
806
|
+
var runSessionBrokerProcess = async (dir) => {
|
|
807
|
+
await runGameSessionBroker({ projectDir: path3.resolve(dir) });
|
|
808
|
+
};
|
|
809
|
+
var runSessionBrokerStatus = async ({
|
|
810
|
+
dir
|
|
811
|
+
}) => {
|
|
812
|
+
const projectDir = await resolveProjectDir(dir);
|
|
813
|
+
const state = await readGameSessionBrokerState(projectDir);
|
|
814
|
+
if (!state) {
|
|
815
|
+
return { running: false, projectDir };
|
|
816
|
+
}
|
|
817
|
+
const health = await readHealth(state);
|
|
818
|
+
return health ? { running: true, ...health } : { running: false, projectDir, staleState: true, pid: state.pid };
|
|
819
|
+
};
|
|
820
|
+
var runSessionBrokerStop = async ({
|
|
821
|
+
dir
|
|
822
|
+
}) => {
|
|
823
|
+
const projectDir = await resolveProjectDir(dir);
|
|
824
|
+
const state = await readGameSessionBrokerState(projectDir);
|
|
825
|
+
if (!state || !await readHealth(state)) {
|
|
826
|
+
await unlink(resolveGameSessionBrokerStatePath(projectDir)).catch(
|
|
827
|
+
() => void 0
|
|
828
|
+
);
|
|
829
|
+
return { stopped: false, running: false, projectDir };
|
|
830
|
+
}
|
|
831
|
+
return requestGameSessionBroker({
|
|
832
|
+
state,
|
|
833
|
+
request: { operation: "shutdown" }
|
|
834
|
+
});
|
|
835
|
+
};
|
|
836
|
+
var openSession = async ({
|
|
837
|
+
dir,
|
|
838
|
+
...input
|
|
839
|
+
}) => request({ dir, operation: { operation: "open", input } });
|
|
840
|
+
var readSession = async ({
|
|
841
|
+
dir,
|
|
842
|
+
gameSessionId,
|
|
843
|
+
requestSync = true,
|
|
844
|
+
timeoutMs
|
|
845
|
+
}) => request({
|
|
846
|
+
dir,
|
|
847
|
+
operation: {
|
|
848
|
+
operation: "read",
|
|
849
|
+
input: { gameSessionId, requestSync, timeoutMs }
|
|
850
|
+
}
|
|
851
|
+
});
|
|
852
|
+
var sendSessionInput = async ({
|
|
853
|
+
dir,
|
|
854
|
+
gameSessionId,
|
|
855
|
+
input
|
|
856
|
+
}) => request({
|
|
857
|
+
dir,
|
|
858
|
+
operation: { operation: "input", input: { gameSessionId, input } }
|
|
859
|
+
});
|
|
860
|
+
var invokeSessionAction = async ({
|
|
861
|
+
dir,
|
|
862
|
+
gameSessionId,
|
|
863
|
+
actionId,
|
|
864
|
+
payload,
|
|
865
|
+
timeoutMs
|
|
866
|
+
}) => request({
|
|
867
|
+
dir,
|
|
868
|
+
operation: {
|
|
869
|
+
operation: "invoke",
|
|
870
|
+
input: { gameSessionId, actionId, payload, timeoutMs }
|
|
871
|
+
}
|
|
872
|
+
});
|
|
873
|
+
var captureSessionVisuals = async ({
|
|
874
|
+
dir,
|
|
875
|
+
gameSessionId,
|
|
876
|
+
timeoutMs
|
|
877
|
+
}) => request({
|
|
878
|
+
dir,
|
|
879
|
+
operation: {
|
|
880
|
+
operation: "capture",
|
|
881
|
+
input: { gameSessionId, timeoutMs }
|
|
882
|
+
}
|
|
883
|
+
});
|
|
884
|
+
var closeSession = async ({
|
|
885
|
+
dir,
|
|
886
|
+
gameSessionId
|
|
887
|
+
}) => request({
|
|
888
|
+
dir,
|
|
889
|
+
operation: { operation: "close", input: { gameSessionId } }
|
|
890
|
+
});
|
|
891
|
+
|
|
892
|
+
// src/version.ts
|
|
893
|
+
import fs2 from "fs";
|
|
894
|
+
var manifest = JSON.parse(
|
|
895
|
+
fs2.readFileSync(new URL("../package.json", import.meta.url), "utf8")
|
|
896
|
+
);
|
|
897
|
+
if (typeof manifest.version !== "string" || manifest.version.length === 0) {
|
|
898
|
+
throw new Error("@air-jam/cli package version is missing.");
|
|
899
|
+
}
|
|
900
|
+
var AIR_JAM_CLI_VERSION = manifest.version;
|
|
901
|
+
|
|
902
|
+
// src/index.ts
|
|
903
|
+
var normalizeRuntimeCliArgv = (argv) => argv.filter((value) => value !== "--");
|
|
904
|
+
var resolveActionOptions = (value) => {
|
|
905
|
+
if (value && typeof value === "object" && "opts" in value && typeof value.opts === "function") {
|
|
906
|
+
return value.opts();
|
|
907
|
+
}
|
|
908
|
+
return value;
|
|
909
|
+
};
|
|
910
|
+
var printReleaseIssues = (issues) => {
|
|
911
|
+
for (const issue of issues) {
|
|
912
|
+
const color = issue.severity === "error" ? kleur2.red : kleur2.yellow;
|
|
913
|
+
const prefix = issue.severity === "error" ? "error" : "warning";
|
|
914
|
+
console.log(color(`- ${prefix}: ${issue.message}`));
|
|
915
|
+
if (issue.path) {
|
|
916
|
+
console.log(kleur2.dim(` path: ${issue.path}`));
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
};
|
|
920
|
+
var printReleaseDoctor = async ({
|
|
921
|
+
dir,
|
|
922
|
+
distDir
|
|
923
|
+
}) => {
|
|
924
|
+
const doctor = await inspectLocalRelease({
|
|
925
|
+
cwd: path4.resolve(dir || process.cwd()),
|
|
926
|
+
distDir
|
|
927
|
+
});
|
|
928
|
+
console.log(
|
|
929
|
+
doctor.canBundle ? kleur2.green("\n\u2713 Hosted release doctor passed\n") : kleur2.red("\n\u2717 Hosted release doctor failed\n")
|
|
930
|
+
);
|
|
931
|
+
console.log(`Project: ${kleur2.cyan(doctor.projectDir)}`);
|
|
932
|
+
console.log(`Dist: ${kleur2.cyan(doctor.distDir)}`);
|
|
933
|
+
console.log(
|
|
934
|
+
`Build script: ${doctor.buildScript ? kleur2.cyan("present") : kleur2.red("missing")}`
|
|
935
|
+
);
|
|
936
|
+
console.log(
|
|
937
|
+
`Metadata export: ${doctor.metadataExportLikely ? kleur2.cyan("present") : kleur2.yellow("missing")}`
|
|
938
|
+
);
|
|
939
|
+
console.log(
|
|
940
|
+
`Hosted contract: ${kleur2.dim(
|
|
941
|
+
`${doctor.hostedContract.hostPath} (host), ${doctor.hostedContract.controllerPath} (controller), ${doctor.hostedContract.manifestPath} manifest`
|
|
942
|
+
)}`
|
|
943
|
+
);
|
|
944
|
+
if (doctor.issues.length > 0) {
|
|
945
|
+
console.log("");
|
|
946
|
+
printReleaseIssues(doctor.issues);
|
|
947
|
+
}
|
|
948
|
+
if (!doctor.canBundle) {
|
|
949
|
+
process.exitCode = 1;
|
|
950
|
+
}
|
|
951
|
+
};
|
|
952
|
+
var runReleaseBundleCommand = async ({
|
|
953
|
+
dir,
|
|
954
|
+
distDir,
|
|
955
|
+
out,
|
|
956
|
+
skipBuild = false
|
|
957
|
+
}) => {
|
|
958
|
+
const result = await bundleLocalRelease({
|
|
959
|
+
cwd: path4.resolve(dir || process.cwd()),
|
|
960
|
+
distDir,
|
|
961
|
+
out,
|
|
962
|
+
skipBuild
|
|
963
|
+
});
|
|
964
|
+
if (result.buildResult?.stdout.trim()) {
|
|
965
|
+
console.log(result.buildResult.stdout.trimEnd());
|
|
966
|
+
}
|
|
967
|
+
if (result.buildResult?.stderr.trim()) {
|
|
968
|
+
console.error(result.buildResult.stderr.trimEnd());
|
|
969
|
+
}
|
|
970
|
+
console.log(kleur2.green("\n\u2713 Hosted release bundle created\n"));
|
|
971
|
+
console.log(`Artifact: ${kleur2.cyan(result.outputFile)}`);
|
|
972
|
+
console.log(
|
|
973
|
+
kleur2.dim(
|
|
974
|
+
`Hosted contract: / (host), /controller (controller), .airjam/release-manifest.json manifest`
|
|
975
|
+
)
|
|
976
|
+
);
|
|
977
|
+
console.log(
|
|
978
|
+
kleur2.dim(
|
|
979
|
+
`Validated ${result.validation.fileCount} files (${result.validation.extractedSizeBytes} bytes extracted)`
|
|
980
|
+
)
|
|
981
|
+
);
|
|
982
|
+
};
|
|
983
|
+
var runReleaseValidateCommand = async ({
|
|
984
|
+
dir,
|
|
985
|
+
distDir,
|
|
986
|
+
bundle,
|
|
987
|
+
skipBuild = false
|
|
988
|
+
}) => {
|
|
989
|
+
const validation = await validateLocalRelease({
|
|
990
|
+
cwd: path4.resolve(dir || process.cwd()),
|
|
991
|
+
distDir,
|
|
992
|
+
bundlePath: bundle,
|
|
993
|
+
skipBuild
|
|
994
|
+
});
|
|
995
|
+
console.log(
|
|
996
|
+
validation.ok ? kleur2.green("\n\u2713 Hosted release validation passed\n") : kleur2.red("\n\u2717 Hosted release validation failed\n")
|
|
997
|
+
);
|
|
998
|
+
if (validation.source.kind === "bundle") {
|
|
999
|
+
console.log(`Bundle: ${kleur2.cyan(validation.source.bundlePath)}`);
|
|
1000
|
+
} else {
|
|
1001
|
+
console.log(`Project: ${kleur2.cyan(validation.source.projectDir)}`);
|
|
1002
|
+
console.log(`Dist: ${kleur2.cyan(validation.source.distDir)}`);
|
|
1003
|
+
}
|
|
1004
|
+
console.log(
|
|
1005
|
+
kleur2.dim(
|
|
1006
|
+
`Validated ${validation.fileCount} files (${validation.extractedSizeBytes} bytes extracted)`
|
|
1007
|
+
)
|
|
1008
|
+
);
|
|
1009
|
+
if (validation.issues.length > 0) {
|
|
1010
|
+
console.log("");
|
|
1011
|
+
printReleaseIssues(validation.issues);
|
|
1012
|
+
}
|
|
1013
|
+
if (!validation.ok) {
|
|
1014
|
+
process.exitCode = 1;
|
|
1015
|
+
}
|
|
1016
|
+
};
|
|
1017
|
+
var runReleaseListCommand = async ({
|
|
1018
|
+
platformUrl,
|
|
1019
|
+
game
|
|
1020
|
+
}) => {
|
|
1021
|
+
if (game?.trim()) {
|
|
1022
|
+
const result2 = await listPlatformReleases({
|
|
1023
|
+
platformUrl,
|
|
1024
|
+
slugOrId: game.trim()
|
|
1025
|
+
});
|
|
1026
|
+
console.log(
|
|
1027
|
+
kleur2.green(
|
|
1028
|
+
`
|
|
1029
|
+
\u2713 Hosted releases for ${result2.game.name}${result2.game.slug ? ` (${result2.game.slug})` : ""}
|
|
1030
|
+
`
|
|
1031
|
+
)
|
|
1032
|
+
);
|
|
1033
|
+
if (result2.releases.length === 0) {
|
|
1034
|
+
console.log(kleur2.dim("No hosted releases found."));
|
|
1035
|
+
return;
|
|
1036
|
+
}
|
|
1037
|
+
for (const release of result2.releases) {
|
|
1038
|
+
console.log(
|
|
1039
|
+
`${kleur2.cyan(release.id)} ${kleur2.yellow(release.status)} ${release.versionLabel ?? "(untitled)"} ${kleur2.dim(release.createdAt)}`
|
|
1040
|
+
);
|
|
1041
|
+
}
|
|
1042
|
+
return;
|
|
1043
|
+
}
|
|
1044
|
+
const result = await listPlatformReleaseTargets({ platformUrl });
|
|
1045
|
+
console.log(kleur2.green("\n\u2713 Hosted release targets\n"));
|
|
1046
|
+
if (result.games.length === 0) {
|
|
1047
|
+
console.log(kleur2.dim("No owned hosted games found."));
|
|
1048
|
+
return;
|
|
1049
|
+
}
|
|
1050
|
+
for (const ownedGame of result.games) {
|
|
1051
|
+
console.log(
|
|
1052
|
+
`${kleur2.cyan(ownedGame.id)} ${ownedGame.slug ? kleur2.yellow(ownedGame.slug) : kleur2.dim("(no slug)")} ${ownedGame.name}`
|
|
1053
|
+
);
|
|
1054
|
+
}
|
|
1055
|
+
};
|
|
1056
|
+
var printHostedGame = ({
|
|
1057
|
+
game,
|
|
1058
|
+
heading
|
|
1059
|
+
}) => {
|
|
1060
|
+
console.log(kleur2.green(`
|
|
1061
|
+
\u2713 ${heading}
|
|
1062
|
+
`));
|
|
1063
|
+
console.log(`ID: ${kleur2.cyan(game.id)}`);
|
|
1064
|
+
console.log(`Name: ${kleur2.cyan(game.name)}`);
|
|
1065
|
+
console.log(`Slug: ${kleur2.cyan(game.slug ?? "(none)")}`);
|
|
1066
|
+
console.log(`Arcade visibility: ${kleur2.cyan(game.arcadeVisibility)}`);
|
|
1067
|
+
console.log(`Description: ${kleur2.cyan(game.description ?? "(none)")}`);
|
|
1068
|
+
console.log(`Preview URL: ${kleur2.cyan(game.url ?? "(none)")}`);
|
|
1069
|
+
console.log(`Source URL: ${kleur2.cyan(game.sourceUrl ?? "(none)")}`);
|
|
1070
|
+
console.log(`Template ID: ${kleur2.cyan(game.templateId ?? "(none)")}`);
|
|
1071
|
+
console.log(`Created: ${kleur2.cyan(game.createdAt)}`);
|
|
1072
|
+
console.log(`Updated: ${kleur2.cyan(game.updatedAt)}`);
|
|
1073
|
+
};
|
|
1074
|
+
var GAME_MEDIA_KIND_LABEL = {
|
|
1075
|
+
thumbnail: "Thumbnail",
|
|
1076
|
+
cover: "Cover",
|
|
1077
|
+
preview_video: "Preview Video"
|
|
1078
|
+
};
|
|
1079
|
+
var formatBytes = (value) => {
|
|
1080
|
+
const units = ["B", "KB", "MB", "GB"];
|
|
1081
|
+
let size = value;
|
|
1082
|
+
let unitIndex = 0;
|
|
1083
|
+
while (size >= 1024 && unitIndex < units.length - 1) {
|
|
1084
|
+
size /= 1024;
|
|
1085
|
+
unitIndex += 1;
|
|
1086
|
+
}
|
|
1087
|
+
return `${size.toFixed(unitIndex === 0 ? 0 : 1)} ${units[unitIndex]}`;
|
|
1088
|
+
};
|
|
1089
|
+
var normalizeGameMediaKind = (value) => {
|
|
1090
|
+
const normalized = value.trim();
|
|
1091
|
+
if (normalized === "thumbnail" || normalized === "cover") {
|
|
1092
|
+
return normalized;
|
|
1093
|
+
}
|
|
1094
|
+
if (normalized === "preview_video" || normalized === "preview-video") {
|
|
1095
|
+
return "preview_video";
|
|
1096
|
+
}
|
|
1097
|
+
throw new Error(
|
|
1098
|
+
`Unsupported media kind "${value}". Use thumbnail, cover, or preview_video.`
|
|
1099
|
+
);
|
|
1100
|
+
};
|
|
1101
|
+
var printHostedGameMedia = ({
|
|
1102
|
+
result,
|
|
1103
|
+
heading
|
|
1104
|
+
}) => {
|
|
1105
|
+
console.log(kleur2.green(`
|
|
1106
|
+
\u2713 ${heading}
|
|
1107
|
+
`));
|
|
1108
|
+
console.log(`Game: ${kleur2.cyan(result.game.name)}`);
|
|
1109
|
+
console.log(`ID: ${kleur2.cyan(result.game.id)}`);
|
|
1110
|
+
console.log(`Slug: ${kleur2.cyan(result.game.slug ?? "(none)")}`);
|
|
1111
|
+
for (const kind of ["thumbnail", "cover", "preview_video"]) {
|
|
1112
|
+
const assets = result.assets.filter((asset) => asset.kind === kind);
|
|
1113
|
+
const activeAsset = assets.find((asset) => asset.isActive) ?? null;
|
|
1114
|
+
console.log("");
|
|
1115
|
+
console.log(kleur2.bold(GAME_MEDIA_KIND_LABEL[kind]));
|
|
1116
|
+
console.log(
|
|
1117
|
+
`Active: ${kleur2.cyan(activeAsset?.id ?? "(none)")}${activeAsset?.publicUrl ? ` ${kleur2.dim(activeAsset.publicUrl)}` : ""}`
|
|
1118
|
+
);
|
|
1119
|
+
if (assets.length === 0) {
|
|
1120
|
+
console.log(kleur2.dim(" No uploaded assets."));
|
|
1121
|
+
continue;
|
|
1122
|
+
}
|
|
1123
|
+
for (const asset of assets) {
|
|
1124
|
+
console.log(
|
|
1125
|
+
` ${asset.isActive ? kleur2.green("\u25CF") : kleur2.dim("\u25CB")} ${kleur2.cyan(asset.id)} ${kleur2.yellow(asset.status)} ${asset.originalFilename} ${kleur2.dim(formatBytes(asset.sizeBytes))}`
|
|
1126
|
+
);
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
};
|
|
1130
|
+
var resolveCreateGameInput = async ({
|
|
1131
|
+
dir,
|
|
1132
|
+
name,
|
|
1133
|
+
slug,
|
|
1134
|
+
description,
|
|
1135
|
+
previewUrl,
|
|
1136
|
+
sourceUrl,
|
|
1137
|
+
templateId,
|
|
1138
|
+
arcadeVisibility
|
|
1139
|
+
}) => {
|
|
1140
|
+
const localDefaults = dir ? await readLocalHostedGameDefaults({
|
|
1141
|
+
cwd: path4.resolve(dir)
|
|
1142
|
+
}) : null;
|
|
1143
|
+
const resolvedName = name?.trim() || localDefaults?.metadata.name || localDefaults?.template.name || null;
|
|
1144
|
+
if (!resolvedName) {
|
|
1145
|
+
throw new Error(
|
|
1146
|
+
"Game name is required. Pass --name or point --dir at a game with declared metadata."
|
|
1147
|
+
);
|
|
1148
|
+
}
|
|
1149
|
+
const resolvedSlug = slug?.trim() || localDefaults?.metadata.slug;
|
|
1150
|
+
const resolvedDescription = description !== void 0 ? description.trim() || void 0 : localDefaults?.metadata.description || localDefaults?.template.description;
|
|
1151
|
+
const resolvedSourceUrl = sourceUrl?.trim() || localDefaults?.sourceUrl;
|
|
1152
|
+
const resolvedTemplateId = templateId?.trim() || localDefaults?.template.id;
|
|
1153
|
+
return {
|
|
1154
|
+
input: {
|
|
1155
|
+
name: resolvedName,
|
|
1156
|
+
...resolvedSlug ? { slug: resolvedSlug } : {},
|
|
1157
|
+
...resolvedDescription ? { description: resolvedDescription } : {},
|
|
1158
|
+
...previewUrl?.trim() ? { url: previewUrl.trim() } : {},
|
|
1159
|
+
...resolvedSourceUrl ? { sourceUrl: resolvedSourceUrl } : {},
|
|
1160
|
+
...resolvedTemplateId ? { templateId: resolvedTemplateId } : {},
|
|
1161
|
+
...arcadeVisibility ? { arcadeVisibility } : {}
|
|
1162
|
+
},
|
|
1163
|
+
localDefaults
|
|
1164
|
+
};
|
|
1165
|
+
};
|
|
1166
|
+
var runGameListCommand = async ({
|
|
1167
|
+
platformUrl
|
|
1168
|
+
}) => {
|
|
1169
|
+
const result = await listPlatformGames({ platformUrl });
|
|
1170
|
+
console.log(kleur2.green("\n\u2713 Hosted games\n"));
|
|
1171
|
+
if (result.games.length === 0) {
|
|
1172
|
+
console.log(kleur2.dim("No owned hosted games found."));
|
|
1173
|
+
return;
|
|
1174
|
+
}
|
|
1175
|
+
for (const game of result.games) {
|
|
1176
|
+
console.log(
|
|
1177
|
+
`${kleur2.cyan(game.id)} ${game.slug ? kleur2.yellow(game.slug) : kleur2.dim("(no slug)")} ${game.name} ${kleur2.dim(game.arcadeVisibility)}`
|
|
1178
|
+
);
|
|
1179
|
+
}
|
|
1180
|
+
};
|
|
1181
|
+
var runGameInspectCommand = async ({
|
|
1182
|
+
platformUrl,
|
|
1183
|
+
game
|
|
1184
|
+
}) => {
|
|
1185
|
+
const result = await inspectPlatformGame({
|
|
1186
|
+
platformUrl,
|
|
1187
|
+
slugOrId: game
|
|
1188
|
+
});
|
|
1189
|
+
printHostedGame({
|
|
1190
|
+
game: result.game,
|
|
1191
|
+
heading: "Hosted game"
|
|
1192
|
+
});
|
|
1193
|
+
};
|
|
1194
|
+
var runGameCreateCommand = async ({
|
|
1195
|
+
platformUrl,
|
|
1196
|
+
dir,
|
|
1197
|
+
name,
|
|
1198
|
+
slug,
|
|
1199
|
+
description,
|
|
1200
|
+
previewUrl,
|
|
1201
|
+
sourceUrl,
|
|
1202
|
+
templateId,
|
|
1203
|
+
arcadeVisibility
|
|
1204
|
+
}) => {
|
|
1205
|
+
const { input } = await resolveCreateGameInput({
|
|
1206
|
+
dir,
|
|
1207
|
+
name,
|
|
1208
|
+
slug,
|
|
1209
|
+
description,
|
|
1210
|
+
previewUrl,
|
|
1211
|
+
sourceUrl,
|
|
1212
|
+
templateId,
|
|
1213
|
+
arcadeVisibility
|
|
1214
|
+
});
|
|
1215
|
+
const result = await createPlatformGame({
|
|
1216
|
+
platformUrl,
|
|
1217
|
+
input
|
|
1218
|
+
});
|
|
1219
|
+
printHostedGame({
|
|
1220
|
+
game: result.game,
|
|
1221
|
+
heading: "Hosted game created"
|
|
1222
|
+
});
|
|
1223
|
+
};
|
|
1224
|
+
var resolveUpdateGamePatch = ({
|
|
1225
|
+
name,
|
|
1226
|
+
slug,
|
|
1227
|
+
description,
|
|
1228
|
+
clearDescription = false,
|
|
1229
|
+
previewUrl,
|
|
1230
|
+
clearPreviewUrl = false,
|
|
1231
|
+
sourceUrl,
|
|
1232
|
+
clearSourceUrl = false,
|
|
1233
|
+
templateId,
|
|
1234
|
+
clearTemplateId = false,
|
|
1235
|
+
arcadeVisibility
|
|
1236
|
+
}) => {
|
|
1237
|
+
if (description !== void 0 && clearDescription) {
|
|
1238
|
+
throw new Error(
|
|
1239
|
+
"Use either --description or --clear-description, not both."
|
|
1240
|
+
);
|
|
1241
|
+
}
|
|
1242
|
+
if (previewUrl !== void 0 && clearPreviewUrl) {
|
|
1243
|
+
throw new Error(
|
|
1244
|
+
"Use either --preview-url or --clear-preview-url, not both."
|
|
1245
|
+
);
|
|
1246
|
+
}
|
|
1247
|
+
if (sourceUrl !== void 0 && clearSourceUrl) {
|
|
1248
|
+
throw new Error("Use either --source-url or --clear-source-url, not both.");
|
|
1249
|
+
}
|
|
1250
|
+
if (templateId !== void 0 && clearTemplateId) {
|
|
1251
|
+
throw new Error(
|
|
1252
|
+
"Use either --template-id or --clear-template-id, not both."
|
|
1253
|
+
);
|
|
1254
|
+
}
|
|
1255
|
+
const patch = {
|
|
1256
|
+
...name?.trim() ? { name: name.trim() } : {},
|
|
1257
|
+
...slug?.trim() ? { slug: slug.trim() } : {},
|
|
1258
|
+
...description !== void 0 ? { description: description.trim() || null } : clearDescription ? { description: null } : {},
|
|
1259
|
+
...previewUrl !== void 0 ? { url: previewUrl.trim() || null } : clearPreviewUrl ? { url: null } : {},
|
|
1260
|
+
...sourceUrl !== void 0 ? { sourceUrl: sourceUrl.trim() || null } : clearSourceUrl ? { sourceUrl: null } : {},
|
|
1261
|
+
...templateId !== void 0 ? { templateId: templateId.trim() || null } : clearTemplateId ? { templateId: null } : {},
|
|
1262
|
+
...arcadeVisibility ? { arcadeVisibility } : {}
|
|
1263
|
+
};
|
|
1264
|
+
if (Object.keys(patch).length === 0) {
|
|
1265
|
+
throw new Error("No hosted game changes were provided.");
|
|
1266
|
+
}
|
|
1267
|
+
return patch;
|
|
1268
|
+
};
|
|
1269
|
+
var runGameUpdateCommand = async ({
|
|
1270
|
+
platformUrl,
|
|
1271
|
+
game,
|
|
1272
|
+
name,
|
|
1273
|
+
slug,
|
|
1274
|
+
description,
|
|
1275
|
+
clearDescription,
|
|
1276
|
+
previewUrl,
|
|
1277
|
+
clearPreviewUrl,
|
|
1278
|
+
sourceUrl,
|
|
1279
|
+
clearSourceUrl,
|
|
1280
|
+
templateId,
|
|
1281
|
+
clearTemplateId,
|
|
1282
|
+
arcadeVisibility
|
|
1283
|
+
}) => {
|
|
1284
|
+
const result = await updatePlatformGame({
|
|
1285
|
+
platformUrl,
|
|
1286
|
+
slugOrId: game,
|
|
1287
|
+
input: resolveUpdateGamePatch({
|
|
1288
|
+
name,
|
|
1289
|
+
slug,
|
|
1290
|
+
description,
|
|
1291
|
+
clearDescription,
|
|
1292
|
+
previewUrl,
|
|
1293
|
+
clearPreviewUrl,
|
|
1294
|
+
sourceUrl,
|
|
1295
|
+
clearSourceUrl,
|
|
1296
|
+
templateId,
|
|
1297
|
+
clearTemplateId,
|
|
1298
|
+
arcadeVisibility
|
|
1299
|
+
})
|
|
1300
|
+
});
|
|
1301
|
+
printHostedGame({
|
|
1302
|
+
game: result.game,
|
|
1303
|
+
heading: "Hosted game updated"
|
|
1304
|
+
});
|
|
1305
|
+
};
|
|
1306
|
+
var runGameMediaInspectCommand = async ({
|
|
1307
|
+
platformUrl,
|
|
1308
|
+
game
|
|
1309
|
+
}) => {
|
|
1310
|
+
const result = await inspectPlatformGameMedia({
|
|
1311
|
+
platformUrl,
|
|
1312
|
+
slugOrId: game
|
|
1313
|
+
});
|
|
1314
|
+
printHostedGameMedia({
|
|
1315
|
+
result,
|
|
1316
|
+
heading: "Hosted game media"
|
|
1317
|
+
});
|
|
1318
|
+
};
|
|
1319
|
+
var runGameMediaUploadCommand = async ({
|
|
1320
|
+
platformUrl,
|
|
1321
|
+
game,
|
|
1322
|
+
thumbnail,
|
|
1323
|
+
cover,
|
|
1324
|
+
previewVideo
|
|
1325
|
+
}) => {
|
|
1326
|
+
const uploads = [
|
|
1327
|
+
...thumbnail ? [{ kind: "thumbnail", filePath: thumbnail }] : [],
|
|
1328
|
+
...cover ? [{ kind: "cover", filePath: cover }] : [],
|
|
1329
|
+
...previewVideo ? [{ kind: "preview_video", filePath: previewVideo }] : []
|
|
1330
|
+
];
|
|
1331
|
+
if (uploads.length === 0) {
|
|
1332
|
+
throw new Error(
|
|
1333
|
+
"No media files were provided. Pass at least one of --thumbnail, --cover, or --preview-video."
|
|
1334
|
+
);
|
|
1335
|
+
}
|
|
1336
|
+
console.log(kleur2.green("\n\u2713 Uploading hosted game media\n"));
|
|
1337
|
+
for (const upload of uploads) {
|
|
1338
|
+
const result = await uploadPlatformGameMediaFile({
|
|
1339
|
+
platformUrl,
|
|
1340
|
+
slugOrId: game,
|
|
1341
|
+
kind: upload.kind,
|
|
1342
|
+
filePath: upload.filePath
|
|
1343
|
+
});
|
|
1344
|
+
console.log(
|
|
1345
|
+
`${kleur2.cyan(GAME_MEDIA_KIND_LABEL[upload.kind])}: ${kleur2.cyan(result.assigned.asset.id)} ${kleur2.dim(result.filePath)}`
|
|
1346
|
+
);
|
|
1347
|
+
}
|
|
1348
|
+
const inspected = await inspectPlatformGameMedia({
|
|
1349
|
+
platformUrl,
|
|
1350
|
+
slugOrId: game
|
|
1351
|
+
});
|
|
1352
|
+
printHostedGameMedia({
|
|
1353
|
+
result: inspected,
|
|
1354
|
+
heading: "Hosted game media updated"
|
|
1355
|
+
});
|
|
1356
|
+
};
|
|
1357
|
+
var runGameMediaClearCommand = async ({
|
|
1358
|
+
platformUrl,
|
|
1359
|
+
game,
|
|
1360
|
+
kind
|
|
1361
|
+
}) => {
|
|
1362
|
+
const current = await inspectPlatformGameMedia({
|
|
1363
|
+
platformUrl,
|
|
1364
|
+
slugOrId: game
|
|
1365
|
+
});
|
|
1366
|
+
const activeAsset = current.assets.find(
|
|
1367
|
+
(asset) => asset.kind === kind && asset.isActive
|
|
1368
|
+
);
|
|
1369
|
+
if (!activeAsset) {
|
|
1370
|
+
console.log(
|
|
1371
|
+
kleur2.yellow(
|
|
1372
|
+
`
|
|
1373
|
+
No active ${GAME_MEDIA_KIND_LABEL[kind].toLowerCase()} to clear.
|
|
1374
|
+
`
|
|
1375
|
+
)
|
|
1376
|
+
);
|
|
1377
|
+
return;
|
|
1378
|
+
}
|
|
1379
|
+
await archivePlatformGameMediaAsset({
|
|
1380
|
+
platformUrl,
|
|
1381
|
+
slugOrId: game,
|
|
1382
|
+
assetId: activeAsset.id
|
|
1383
|
+
});
|
|
1384
|
+
const inspected = await inspectPlatformGameMedia({
|
|
1385
|
+
platformUrl,
|
|
1386
|
+
slugOrId: game
|
|
1387
|
+
});
|
|
1388
|
+
printHostedGameMedia({
|
|
1389
|
+
result: inspected,
|
|
1390
|
+
heading: `${GAME_MEDIA_KIND_LABEL[kind]} cleared`
|
|
1391
|
+
});
|
|
1392
|
+
};
|
|
1393
|
+
var runReleaseInspectCommand = async ({
|
|
1394
|
+
platformUrl,
|
|
1395
|
+
releaseId
|
|
1396
|
+
}) => {
|
|
1397
|
+
const result = await inspectPlatformRelease({
|
|
1398
|
+
platformUrl,
|
|
1399
|
+
releaseId
|
|
1400
|
+
});
|
|
1401
|
+
const release = result.release;
|
|
1402
|
+
console.log(kleur2.green("\n\u2713 Hosted release\n"));
|
|
1403
|
+
console.log(`Release: ${kleur2.cyan(release.id)}`);
|
|
1404
|
+
console.log(`Game: ${kleur2.cyan(release.game.name)}`);
|
|
1405
|
+
console.log(`Status: ${kleur2.cyan(release.status)}`);
|
|
1406
|
+
console.log(`Version: ${kleur2.cyan(release.versionLabel ?? "(untitled)")}`);
|
|
1407
|
+
console.log(`Created: ${kleur2.cyan(release.createdAt)}`);
|
|
1408
|
+
if (release.hostUrl) {
|
|
1409
|
+
console.log(`Host URL: ${kleur2.cyan(release.hostUrl)}`);
|
|
1410
|
+
}
|
|
1411
|
+
if (release.controllerUrl) {
|
|
1412
|
+
console.log(`Controller URL: ${kleur2.cyan(release.controllerUrl)}`);
|
|
1413
|
+
}
|
|
1414
|
+
const formatGeneration = (generation) => `${kleur2.cyan(generation.id)} (#${generation.sequence}, ${kleur2.yellow(generation.status)})`;
|
|
1415
|
+
console.log(
|
|
1416
|
+
`Candidate generation: ${release.candidateGeneration ? formatGeneration(release.candidateGeneration) : kleur2.dim("none")}`
|
|
1417
|
+
);
|
|
1418
|
+
console.log(
|
|
1419
|
+
`Promoted generation: ${release.promotedGeneration ? formatGeneration(release.promotedGeneration) : kleur2.dim("none")}`
|
|
1420
|
+
);
|
|
1421
|
+
if (release.generations.length > 0) {
|
|
1422
|
+
console.log("");
|
|
1423
|
+
console.log(kleur2.dim("Generation history:"));
|
|
1424
|
+
for (const generation of release.generations) {
|
|
1425
|
+
const observedSize = generation.observedSizeBytes ? `, ${generation.observedSizeBytes} bytes observed` : "";
|
|
1426
|
+
console.log(
|
|
1427
|
+
`- ${formatGeneration(generation)}: ${generation.originalFilename} (${generation.declaredSizeBytes} bytes declared${observedSize})`
|
|
1428
|
+
);
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
if (release.checks.length > 0) {
|
|
1432
|
+
console.log("");
|
|
1433
|
+
console.log(kleur2.dim("Checks:"));
|
|
1434
|
+
for (const check of release.checks) {
|
|
1435
|
+
console.log(
|
|
1436
|
+
`- ${check.kind}: ${check.status} [generation ${check.generationId}]${check.summary ? ` (${check.summary})` : ""}`
|
|
1437
|
+
);
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
};
|
|
1441
|
+
var runReleaseSubmitCommand = async ({
|
|
1442
|
+
platformUrl,
|
|
1443
|
+
game,
|
|
1444
|
+
versionLabel,
|
|
1445
|
+
dir,
|
|
1446
|
+
distDir,
|
|
1447
|
+
bundle,
|
|
1448
|
+
skipBuild = false,
|
|
1449
|
+
waitForProcessing = false,
|
|
1450
|
+
processingTimeoutSeconds,
|
|
1451
|
+
publish = false
|
|
1452
|
+
}) => {
|
|
1453
|
+
const resolvedCwd = path4.resolve(dir || process.cwd());
|
|
1454
|
+
if (processingTimeoutSeconds !== void 0 && (!Number.isSafeInteger(processingTimeoutSeconds) || processingTimeoutSeconds < 1)) {
|
|
1455
|
+
throw new Error("--processing-timeout must be a positive integer.");
|
|
1456
|
+
}
|
|
1457
|
+
let result;
|
|
1458
|
+
try {
|
|
1459
|
+
result = await submitPlatformRelease({
|
|
1460
|
+
platformUrl,
|
|
1461
|
+
slugOrId: game,
|
|
1462
|
+
versionLabel,
|
|
1463
|
+
cwd: resolvedCwd,
|
|
1464
|
+
distDir,
|
|
1465
|
+
bundlePath: bundle,
|
|
1466
|
+
skipBuild,
|
|
1467
|
+
waitForProcessing,
|
|
1468
|
+
...processingTimeoutSeconds === void 0 ? {} : { processingTimeoutMs: processingTimeoutSeconds * 1e3 },
|
|
1469
|
+
publish
|
|
1470
|
+
});
|
|
1471
|
+
} catch (error) {
|
|
1472
|
+
if (error instanceof AirJamPlatformApiError && error.code === "not_found") {
|
|
1473
|
+
let createHint = 'Run `airjam game create --name "Your Game" --slug your-game` first.';
|
|
1474
|
+
try {
|
|
1475
|
+
const localDefaults = await readLocalHostedGameDefaults({
|
|
1476
|
+
cwd: resolvedCwd
|
|
1477
|
+
});
|
|
1478
|
+
const hintedSlug = localDefaults.metadata.slug ?? game;
|
|
1479
|
+
createHint = `Run \`airjam game create --dir ${resolvedCwd}${platformUrl ? ` --platform-url ${platformUrl}` : ""}\` to register this local game first, then retry with \`--game ${hintedSlug}\`.`;
|
|
1480
|
+
} catch {
|
|
1481
|
+
}
|
|
1482
|
+
throw new Error(`No owned hosted game matched "${game}". ${createHint}`);
|
|
1483
|
+
}
|
|
1484
|
+
throw error;
|
|
1485
|
+
}
|
|
1486
|
+
console.log(kleur2.green("\n\u2713 Hosted release submitted\n"));
|
|
1487
|
+
console.log(`Bundle: ${kleur2.cyan(result.bundlePath)}`);
|
|
1488
|
+
console.log(`Draft: ${kleur2.cyan(result.createdRelease.id)}`);
|
|
1489
|
+
console.log(
|
|
1490
|
+
`Created generation: ${kleur2.cyan(result.createdGeneration.id)} (#${result.createdGeneration.sequence})`
|
|
1491
|
+
);
|
|
1492
|
+
console.log(
|
|
1493
|
+
`Submitted generation: ${kleur2.cyan(result.submittedGeneration.id)} (${kleur2.yellow(result.submittedGeneration.status)})`
|
|
1494
|
+
);
|
|
1495
|
+
console.log(
|
|
1496
|
+
`Processing job: ${kleur2.cyan(result.processingJob.id)} (${kleur2.yellow(result.processingJob.status)})`
|
|
1497
|
+
);
|
|
1498
|
+
console.log(
|
|
1499
|
+
`Release status: ${kleur2.yellow(result.submittedRelease.status)}`
|
|
1500
|
+
);
|
|
1501
|
+
if (result.processedRelease) {
|
|
1502
|
+
console.log(
|
|
1503
|
+
`Processing complete: ${kleur2.cyan(result.processedRelease.id)} (${kleur2.yellow(result.processedRelease.status)})`
|
|
1504
|
+
);
|
|
1505
|
+
} else {
|
|
1506
|
+
console.log(
|
|
1507
|
+
kleur2.dim(
|
|
1508
|
+
`Inspect with: airjam release inspect --release ${result.submittedRelease.id}`
|
|
1509
|
+
)
|
|
1510
|
+
);
|
|
1511
|
+
}
|
|
1512
|
+
if (result.publishedRelease) {
|
|
1513
|
+
console.log(
|
|
1514
|
+
`Published: ${kleur2.cyan(result.publishedRelease.id)} (${kleur2.yellow(result.publishedRelease.status)})`
|
|
1515
|
+
);
|
|
1516
|
+
}
|
|
1517
|
+
};
|
|
1518
|
+
var runReleaseUploadCommand = async ({
|
|
1519
|
+
platformUrl,
|
|
1520
|
+
releaseId,
|
|
1521
|
+
dir,
|
|
1522
|
+
bundle
|
|
1523
|
+
}) => {
|
|
1524
|
+
const result = await uploadPlatformReleaseGeneration({
|
|
1525
|
+
platformUrl,
|
|
1526
|
+
releaseId,
|
|
1527
|
+
cwd: path4.resolve(dir || process.cwd()),
|
|
1528
|
+
bundlePath: bundle
|
|
1529
|
+
});
|
|
1530
|
+
console.log(kleur2.green("\n\u2713 Hosted release generation uploaded\n"));
|
|
1531
|
+
console.log(`Bundle: ${kleur2.cyan(result.bundlePath)}`);
|
|
1532
|
+
console.log(`Release: ${kleur2.cyan(result.release.id)}`);
|
|
1533
|
+
console.log(
|
|
1534
|
+
`Generation: ${kleur2.cyan(result.generation.id)} (#${result.generation.sequence}, ${kleur2.yellow(result.generation.status)})`
|
|
1535
|
+
);
|
|
1536
|
+
console.log(
|
|
1537
|
+
kleur2.dim(
|
|
1538
|
+
`Resume with: airjam release finalize --release ${result.release.id} --generation ${result.generation.id}`
|
|
1539
|
+
)
|
|
1540
|
+
);
|
|
1541
|
+
};
|
|
1542
|
+
var runReleaseFinalizeCommand = async ({
|
|
1543
|
+
platformUrl,
|
|
1544
|
+
releaseId,
|
|
1545
|
+
generationId
|
|
1546
|
+
}) => {
|
|
1547
|
+
const result = await finalizePlatformReleaseGeneration({
|
|
1548
|
+
platformUrl,
|
|
1549
|
+
releaseId,
|
|
1550
|
+
generationId
|
|
1551
|
+
});
|
|
1552
|
+
console.log(kleur2.green("\n\u2713 Hosted release processing queued\n"));
|
|
1553
|
+
console.log(`Release: ${kleur2.cyan(result.release.id)}`);
|
|
1554
|
+
console.log(`Release status: ${kleur2.yellow(result.release.status)}`);
|
|
1555
|
+
console.log(
|
|
1556
|
+
`Generation: ${kleur2.cyan(result.generation.id)} (${kleur2.yellow(result.generation.status)})`
|
|
1557
|
+
);
|
|
1558
|
+
console.log(
|
|
1559
|
+
`Processing job: ${kleur2.cyan(result.job.id)} (${kleur2.yellow(result.job.status)})`
|
|
1560
|
+
);
|
|
1561
|
+
console.log(
|
|
1562
|
+
kleur2.dim(
|
|
1563
|
+
`Inspect with: airjam release inspect --release ${result.release.id}`
|
|
1564
|
+
)
|
|
1565
|
+
);
|
|
1566
|
+
};
|
|
1567
|
+
var runReleaseExportCommand = async ({
|
|
1568
|
+
platformUrl,
|
|
1569
|
+
releaseId,
|
|
1570
|
+
generationId,
|
|
1571
|
+
dir,
|
|
1572
|
+
out
|
|
1573
|
+
}) => {
|
|
1574
|
+
const result = await exportPlatformReleaseGeneration({
|
|
1575
|
+
platformUrl,
|
|
1576
|
+
releaseId,
|
|
1577
|
+
generationId,
|
|
1578
|
+
cwd: path4.resolve(dir || process.cwd()),
|
|
1579
|
+
out
|
|
1580
|
+
});
|
|
1581
|
+
console.log(kleur2.green("\n\u2713 Hosted release generation exported\n"));
|
|
1582
|
+
console.log(`Release: ${kleur2.cyan(releaseId)}`);
|
|
1583
|
+
console.log(
|
|
1584
|
+
`Generation: ${kleur2.cyan(result.generation.id)} (#${result.generation.sequence})`
|
|
1585
|
+
);
|
|
1586
|
+
console.log(`Archive: ${kleur2.cyan(result.outputFile)}`);
|
|
1587
|
+
console.log(`Size: ${kleur2.cyan(`${result.sizeBytes} bytes`)}`);
|
|
1588
|
+
};
|
|
1589
|
+
var runReleasePublishCommand = async ({
|
|
1590
|
+
platformUrl,
|
|
1591
|
+
releaseId
|
|
1592
|
+
}) => {
|
|
1593
|
+
const result = await publishPlatformRelease({
|
|
1594
|
+
platformUrl,
|
|
1595
|
+
releaseId
|
|
1596
|
+
});
|
|
1597
|
+
console.log(kleur2.green("\n\u2713 Hosted release published\n"));
|
|
1598
|
+
console.log(`Release: ${kleur2.cyan(result.release.id)}`);
|
|
1599
|
+
console.log(`Status: ${kleur2.cyan(result.release.status)}`);
|
|
1600
|
+
if (result.release.hostUrl) {
|
|
1601
|
+
console.log(`Host URL: ${kleur2.cyan(result.release.hostUrl)}`);
|
|
1602
|
+
}
|
|
1603
|
+
};
|
|
1604
|
+
var runAuthLoginCommand = async ({
|
|
1605
|
+
platformUrl,
|
|
1606
|
+
clientName
|
|
1607
|
+
}) => {
|
|
1608
|
+
console.log(kleur2.cyan("\nStarting Air Jam platform login...\n"));
|
|
1609
|
+
const result = await loginPlatformWithDeviceFlow({
|
|
1610
|
+
platformUrl,
|
|
1611
|
+
clientName,
|
|
1612
|
+
onPrompt: async (authorization) => {
|
|
1613
|
+
console.log(
|
|
1614
|
+
`Verification URL: ${kleur2.cyan(authorization.verificationUrl)}`
|
|
1615
|
+
);
|
|
1616
|
+
console.log(`Approval code: ${kleur2.cyan(authorization.userCode)}`);
|
|
1617
|
+
console.log(
|
|
1618
|
+
kleur2.dim(
|
|
1619
|
+
"Sign in on the dashboard, approve the CLI request, and this command will finish automatically.\n"
|
|
1620
|
+
)
|
|
1621
|
+
);
|
|
1622
|
+
}
|
|
1623
|
+
});
|
|
1624
|
+
console.log(kleur2.green("\n\u2713 Logged in to the Air Jam platform\n"));
|
|
1625
|
+
console.log(`Platform: ${kleur2.cyan(result.authenticated.platformBaseUrl)}`);
|
|
1626
|
+
console.log(`User: ${kleur2.cyan(result.authenticated.user.name)}`);
|
|
1627
|
+
console.log(`Email: ${kleur2.cyan(result.authenticated.user.email)}`);
|
|
1628
|
+
console.log(`Session file: ${kleur2.dim(getPlatformAuthStoragePath())}`);
|
|
1629
|
+
};
|
|
1630
|
+
var runAuthWhoAmICommand = async ({
|
|
1631
|
+
platformUrl
|
|
1632
|
+
}) => {
|
|
1633
|
+
const storedSession = await readStoredPlatformMachineSession();
|
|
1634
|
+
if (!storedSession) {
|
|
1635
|
+
console.log(kleur2.red("No stored Air Jam platform session was found."));
|
|
1636
|
+
console.log(kleur2.dim(`Expected at ${getPlatformAuthStoragePath()}`));
|
|
1637
|
+
process.exitCode = 1;
|
|
1638
|
+
return;
|
|
1639
|
+
}
|
|
1640
|
+
const profile = await getPlatformMachineProfile({ platformUrl });
|
|
1641
|
+
console.log(kleur2.green("\n\u2713 Air Jam platform session is valid\n"));
|
|
1642
|
+
console.log(`Platform: ${kleur2.cyan(profile.platformBaseUrl)}`);
|
|
1643
|
+
console.log(`User: ${kleur2.cyan(profile.user.name)}`);
|
|
1644
|
+
console.log(`Email: ${kleur2.cyan(profile.user.email)}`);
|
|
1645
|
+
console.log(`Role: ${kleur2.cyan(profile.user.role)}`);
|
|
1646
|
+
console.log(`Expires: ${kleur2.cyan(profile.session.expiresAt)}`);
|
|
1647
|
+
console.log(`Session file: ${kleur2.dim(getPlatformAuthStoragePath())}`);
|
|
1648
|
+
};
|
|
1649
|
+
var runAuthLogoutCommand = async ({
|
|
1650
|
+
platformUrl
|
|
1651
|
+
}) => {
|
|
1652
|
+
let storedSession;
|
|
1653
|
+
try {
|
|
1654
|
+
storedSession = await readStoredPlatformMachineSession();
|
|
1655
|
+
} catch (error) {
|
|
1656
|
+
if (!(error instanceof AirJamStoredPlatformSessionError)) throw error;
|
|
1657
|
+
await clearStoredPlatformMachineSession();
|
|
1658
|
+
console.log(
|
|
1659
|
+
kleur2.yellow(
|
|
1660
|
+
"Removed an unreadable local Air Jam session. Its remote token could not be revoked."
|
|
1661
|
+
)
|
|
1662
|
+
);
|
|
1663
|
+
return;
|
|
1664
|
+
}
|
|
1665
|
+
if (!storedSession) {
|
|
1666
|
+
console.log(kleur2.yellow("No stored Air Jam platform session was found."));
|
|
1667
|
+
return;
|
|
1668
|
+
}
|
|
1669
|
+
await logoutPlatformMachineSession({ platformUrl });
|
|
1670
|
+
console.log(kleur2.green("\n\u2713 Logged out of the Air Jam platform\n"));
|
|
1671
|
+
};
|
|
1672
|
+
var buildProgram = () => {
|
|
1673
|
+
const program = new Command();
|
|
1674
|
+
program.name("airjam").description("Operate Air Jam game projects").version(AIR_JAM_CLI_VERSION).action(() => {
|
|
1675
|
+
program.outputHelp();
|
|
1676
|
+
});
|
|
1677
|
+
const documentationCommand = program.command("docs").description("Read the installed public creator documentation");
|
|
1678
|
+
documentationCommand.command("list").option("--json", "Print one machine-readable JSON document", false).action(async (options) => {
|
|
1679
|
+
const snapshot = await readDocumentationSnapshot();
|
|
1680
|
+
const documents = snapshot.documents.map(
|
|
1681
|
+
({ content: _content, ...document }) => document
|
|
1682
|
+
);
|
|
1683
|
+
if (options.json)
|
|
1684
|
+
process.stdout.write(
|
|
1685
|
+
`${JSON.stringify({ ...snapshot, documents }, null, 2)}
|
|
1686
|
+
`
|
|
1687
|
+
);
|
|
1688
|
+
else
|
|
1689
|
+
for (const document of documents)
|
|
1690
|
+
console.log(`${document.page.href}: ${document.page.title}`);
|
|
1691
|
+
});
|
|
1692
|
+
documentationCommand.command("read <slug>").option("--json", "Print one machine-readable JSON document", false).action(async (slug, options) => {
|
|
1693
|
+
const snapshot = await readDocumentationSnapshot();
|
|
1694
|
+
const document = snapshot.documents.find(
|
|
1695
|
+
(entry) => entry.page.href === `/docs/${slug}`
|
|
1696
|
+
);
|
|
1697
|
+
if (!document)
|
|
1698
|
+
throw new Error(
|
|
1699
|
+
`Unknown documentation page: ${slug}. Use "airjam docs list".`
|
|
1700
|
+
);
|
|
1701
|
+
process.stdout.write(
|
|
1702
|
+
options.json ? `${JSON.stringify({ packageVersion: snapshot.packageVersion, document }, null, 2)}
|
|
1703
|
+
` : document.content
|
|
1704
|
+
);
|
|
1705
|
+
});
|
|
1706
|
+
const aiPackCommand = program.command("ai-pack").description("Inspect or update provenance-backed AI pack assets");
|
|
1707
|
+
aiPackCommand.command("status").description("Show AI pack status for a project").option("--dir <path>", "Project directory to inspect").option("--json", "Print one machine-readable JSON document", false).action(async (options) => {
|
|
1708
|
+
await runAiPackStatus(
|
|
1709
|
+
resolveActionOptions(options)
|
|
1710
|
+
);
|
|
1711
|
+
});
|
|
1712
|
+
aiPackCommand.command("diff").description("Show AI pack file differences for a project").option("--dir <path>", "Project directory to inspect").option("--json", "Print one machine-readable JSON document", false).action(async (options) => {
|
|
1713
|
+
await runAiPackDiff(
|
|
1714
|
+
resolveActionOptions(options)
|
|
1715
|
+
);
|
|
1716
|
+
});
|
|
1717
|
+
aiPackCommand.command("update").description("Update managed AI pack assets for a project").option("--dir <path>", "Project directory to inspect").option("--json", "Print one machine-readable JSON document", false).action(async (options) => {
|
|
1718
|
+
await runAiPackUpdate(
|
|
1719
|
+
resolveActionOptions(options)
|
|
1720
|
+
);
|
|
1721
|
+
});
|
|
1722
|
+
aiPackCommand.command("repair").description("Restore same-version managed files from the installed CLI").option("--dir <path>", "Project directory to repair").option("--json", "Print one machine-readable JSON document", false).action(async (options) => {
|
|
1723
|
+
await runAiPackRepair(
|
|
1724
|
+
resolveActionOptions(options)
|
|
1725
|
+
);
|
|
1726
|
+
});
|
|
1727
|
+
aiPackCommand.action(() => {
|
|
1728
|
+
aiPackCommand.outputHelp();
|
|
1729
|
+
});
|
|
1730
|
+
program.command("evaluate").description(
|
|
1731
|
+
"Run the complete game evaluation: typecheck, lint, tests, and production build"
|
|
1732
|
+
).option("--dir <path>", "Project directory to evaluate").action(async (options) => {
|
|
1733
|
+
const input = resolveActionOptions(options);
|
|
1734
|
+
const result = await runCompleteEvaluation({ cwd: input.dir });
|
|
1735
|
+
process.stdout.write(`${JSON.stringify(result, null, 2)}
|
|
1736
|
+
`);
|
|
1737
|
+
if (result.status !== "passed") {
|
|
1738
|
+
process.exitCode = 1;
|
|
1739
|
+
}
|
|
1740
|
+
});
|
|
1741
|
+
const gameCommand = program.command("game").description("Manage hosted Air Jam game records on the platform");
|
|
1742
|
+
gameCommand.command("list").description("List owned hosted games").option("--platform-url <url>", "Hosted Air Jam platform base URL").action(async (options) => {
|
|
1743
|
+
await runGameListCommand(
|
|
1744
|
+
resolveActionOptions(options)
|
|
1745
|
+
);
|
|
1746
|
+
});
|
|
1747
|
+
gameCommand.command("inspect").description("Inspect one owned hosted game").requiredOption("--game <slug-or-id>", "Owned hosted game slug or ID").option("--platform-url <url>", "Hosted Air Jam platform base URL").action(async (options) => {
|
|
1748
|
+
const resolved = resolveActionOptions(options);
|
|
1749
|
+
await runGameInspectCommand({
|
|
1750
|
+
platformUrl: resolved.platformUrl,
|
|
1751
|
+
game: resolved.game
|
|
1752
|
+
});
|
|
1753
|
+
});
|
|
1754
|
+
gameCommand.command("create").description("Create a hosted game record for release publishing").option("--platform-url <url>", "Hosted Air Jam platform base URL").option(
|
|
1755
|
+
"--dir <path>",
|
|
1756
|
+
"Local game project directory for metadata defaults"
|
|
1757
|
+
).option("--name <name>", "Hosted game display name").option("--slug <slug>", "Hosted game slug").option("--description <text>", "Catalog description/tagline").option("--preview-url <url>", "Private creator preview URL").option("--source-url <url>", "Source repository URL").option("--template-id <id>", "Template ID shown for developer actions").option(
|
|
1758
|
+
"--arcade-visibility <visibility>",
|
|
1759
|
+
"Initial arcade visibility (hidden or listed)"
|
|
1760
|
+
).action(async (options) => {
|
|
1761
|
+
const resolved = resolveActionOptions(options);
|
|
1762
|
+
await runGameCreateCommand({
|
|
1763
|
+
platformUrl: resolved.platformUrl,
|
|
1764
|
+
dir: resolved.dir,
|
|
1765
|
+
name: resolved.name,
|
|
1766
|
+
slug: resolved.slug,
|
|
1767
|
+
description: resolved.description,
|
|
1768
|
+
previewUrl: resolved.previewUrl,
|
|
1769
|
+
sourceUrl: resolved.sourceUrl,
|
|
1770
|
+
templateId: resolved.templateId,
|
|
1771
|
+
arcadeVisibility: resolved.arcadeVisibility
|
|
1772
|
+
});
|
|
1773
|
+
});
|
|
1774
|
+
gameCommand.command("update").description("Update core hosted game metadata").requiredOption("--game <slug-or-id>", "Owned hosted game slug or ID").option("--platform-url <url>", "Hosted Air Jam platform base URL").option("--name <name>", "Hosted game display name").option("--slug <slug>", "Hosted game slug").option("--description <text>", "Catalog description/tagline").option("--clear-description", "Clear the catalog description", false).option("--preview-url <url>", "Private creator preview URL").option("--clear-preview-url", "Clear the private preview URL", false).option("--source-url <url>", "Source repository URL").option("--clear-source-url", "Clear the source repository URL", false).option("--template-id <id>", "Template ID shown for developer actions").option("--clear-template-id", "Clear the template ID", false).option(
|
|
1775
|
+
"--arcade-visibility <visibility>",
|
|
1776
|
+
"Arcade visibility (hidden or listed)"
|
|
1777
|
+
).action(async (options) => {
|
|
1778
|
+
const resolved = resolveActionOptions(options);
|
|
1779
|
+
await runGameUpdateCommand({
|
|
1780
|
+
platformUrl: resolved.platformUrl,
|
|
1781
|
+
game: resolved.game,
|
|
1782
|
+
name: resolved.name,
|
|
1783
|
+
slug: resolved.slug,
|
|
1784
|
+
description: resolved.description,
|
|
1785
|
+
clearDescription: resolved.clearDescription,
|
|
1786
|
+
previewUrl: resolved.previewUrl,
|
|
1787
|
+
clearPreviewUrl: resolved.clearPreviewUrl,
|
|
1788
|
+
sourceUrl: resolved.sourceUrl,
|
|
1789
|
+
clearSourceUrl: resolved.clearSourceUrl,
|
|
1790
|
+
templateId: resolved.templateId,
|
|
1791
|
+
clearTemplateId: resolved.clearTemplateId,
|
|
1792
|
+
arcadeVisibility: resolved.arcadeVisibility
|
|
1793
|
+
});
|
|
1794
|
+
});
|
|
1795
|
+
const gameMediaCommand = gameCommand.command("media").description("Manage hosted game media assets");
|
|
1796
|
+
gameMediaCommand.command("inspect").description("Inspect hosted media for one owned game").requiredOption("--game <slug-or-id>", "Owned hosted game slug or ID").option("--platform-url <url>", "Hosted Air Jam platform base URL").action(async (options) => {
|
|
1797
|
+
const resolved = resolveActionOptions(options);
|
|
1798
|
+
await runGameMediaInspectCommand({
|
|
1799
|
+
platformUrl: resolved.platformUrl,
|
|
1800
|
+
game: resolved.game
|
|
1801
|
+
});
|
|
1802
|
+
});
|
|
1803
|
+
gameMediaCommand.command("upload").description("Upload and assign hosted media for one owned game").requiredOption("--game <slug-or-id>", "Owned hosted game slug or ID").option("--platform-url <url>", "Hosted Air Jam platform base URL").option("--thumbnail <path>", "Thumbnail image file").option("--cover <path>", "Cover image file").option("--preview-video <path>", "Preview video file").action(async (options) => {
|
|
1804
|
+
const resolved = resolveActionOptions(options);
|
|
1805
|
+
await runGameMediaUploadCommand({
|
|
1806
|
+
platformUrl: resolved.platformUrl,
|
|
1807
|
+
game: resolved.game,
|
|
1808
|
+
thumbnail: resolved.thumbnail,
|
|
1809
|
+
cover: resolved.cover,
|
|
1810
|
+
previewVideo: resolved.previewVideo
|
|
1811
|
+
});
|
|
1812
|
+
});
|
|
1813
|
+
gameMediaCommand.command("clear").description("Archive the currently active hosted media asset for one slot").requiredOption("--game <slug-or-id>", "Owned hosted game slug or ID").requiredOption(
|
|
1814
|
+
"--kind <kind>",
|
|
1815
|
+
"Media slot to clear (thumbnail, cover, or preview_video)"
|
|
1816
|
+
).option("--platform-url <url>", "Hosted Air Jam platform base URL").action(async (options) => {
|
|
1817
|
+
const resolved = resolveActionOptions(options);
|
|
1818
|
+
await runGameMediaClearCommand({
|
|
1819
|
+
platformUrl: resolved.platformUrl,
|
|
1820
|
+
game: resolved.game,
|
|
1821
|
+
kind: normalizeGameMediaKind(resolved.kind)
|
|
1822
|
+
});
|
|
1823
|
+
});
|
|
1824
|
+
gameMediaCommand.action(() => {
|
|
1825
|
+
gameMediaCommand.outputHelp();
|
|
1826
|
+
});
|
|
1827
|
+
gameCommand.action(() => {
|
|
1828
|
+
gameCommand.outputHelp();
|
|
1829
|
+
});
|
|
1830
|
+
const releaseCommand = program.command("release").description("Work with hosted release bundles");
|
|
1831
|
+
releaseCommand.command("doctor").description(
|
|
1832
|
+
"Inspect whether a project is ready for hosted release bundling"
|
|
1833
|
+
).option("--dir <path>", "Project directory to inspect").option("--dist-dir <path>", "Built static output directory").action(async (options) => {
|
|
1834
|
+
await printReleaseDoctor(
|
|
1835
|
+
resolveActionOptions(options)
|
|
1836
|
+
);
|
|
1837
|
+
});
|
|
1838
|
+
releaseCommand.command("bundle").description("Create a hosted release zip from a built game project").option("--dir <path>", "Project directory to bundle").option("--dist-dir <path>", "Built static output directory").option("--out <path>", "Output zip file path").option(
|
|
1839
|
+
"--skip-build",
|
|
1840
|
+
"Reuse the existing dist directory without building",
|
|
1841
|
+
false
|
|
1842
|
+
).action(async (options) => {
|
|
1843
|
+
await runReleaseBundleCommand(
|
|
1844
|
+
resolveActionOptions(options)
|
|
1845
|
+
);
|
|
1846
|
+
});
|
|
1847
|
+
releaseCommand.command("validate").description(
|
|
1848
|
+
"Validate hosted release inputs or an existing hosted release zip"
|
|
1849
|
+
).option("--dir <path>", "Project directory to inspect").option("--dist-dir <path>", "Built static output directory").option("--bundle <path>", "Existing hosted release zip to validate").option(
|
|
1850
|
+
"--skip-build",
|
|
1851
|
+
"Reuse the existing dist directory without building",
|
|
1852
|
+
false
|
|
1853
|
+
).action(async (options) => {
|
|
1854
|
+
await runReleaseValidateCommand(
|
|
1855
|
+
resolveActionOptions(options)
|
|
1856
|
+
);
|
|
1857
|
+
});
|
|
1858
|
+
releaseCommand.command("list").description("List owned hosted games or releases for one hosted game").option("--platform-url <url>", "Hosted Air Jam platform base URL").option("--game <slug-or-id>", "List releases for one owned hosted game").action(async (options) => {
|
|
1859
|
+
await runReleaseListCommand(
|
|
1860
|
+
resolveActionOptions(options)
|
|
1861
|
+
);
|
|
1862
|
+
});
|
|
1863
|
+
releaseCommand.command("inspect").description("Inspect one hosted release from the Air Jam platform").requiredOption("--release <id>", "Hosted release ID to inspect").option("--platform-url <url>", "Hosted Air Jam platform base URL").action(async (options) => {
|
|
1864
|
+
const resolved = resolveActionOptions(options);
|
|
1865
|
+
await runReleaseInspectCommand({
|
|
1866
|
+
platformUrl: resolved.platformUrl,
|
|
1867
|
+
releaseId: resolved.release
|
|
1868
|
+
});
|
|
1869
|
+
});
|
|
1870
|
+
releaseCommand.command("submit").description("Bundle a game and submit it as a hosted release draft").requiredOption("--game <slug-or-id>", "Owned hosted game slug or ID").option("--platform-url <url>", "Hosted Air Jam platform base URL").option("--version-label <label>", "Optional hosted release version label").option("--dir <path>", "Project directory to bundle").option("--dist-dir <path>", "Built static output directory").option("--bundle <path>", "Existing hosted release zip to submit").option(
|
|
1871
|
+
"--skip-build",
|
|
1872
|
+
"Reuse the existing dist directory without building",
|
|
1873
|
+
false
|
|
1874
|
+
).option(
|
|
1875
|
+
"--wait",
|
|
1876
|
+
"Wait for durable processing to reach a terminal generation state",
|
|
1877
|
+
false
|
|
1878
|
+
).option(
|
|
1879
|
+
"--processing-timeout <seconds>",
|
|
1880
|
+
"Maximum processing wait; the durable job continues after a timeout",
|
|
1881
|
+
(value) => Number(value)
|
|
1882
|
+
).option(
|
|
1883
|
+
"--publish",
|
|
1884
|
+
"Wait for successful processing and publish the ready release",
|
|
1885
|
+
false
|
|
1886
|
+
).action(async (options) => {
|
|
1887
|
+
const resolved = resolveActionOptions(options);
|
|
1888
|
+
await runReleaseSubmitCommand({
|
|
1889
|
+
platformUrl: resolved.platformUrl,
|
|
1890
|
+
game: resolved.game,
|
|
1891
|
+
versionLabel: resolved.versionLabel,
|
|
1892
|
+
dir: resolved.dir,
|
|
1893
|
+
distDir: resolved.distDir,
|
|
1894
|
+
bundle: resolved.bundle,
|
|
1895
|
+
skipBuild: resolved.skipBuild,
|
|
1896
|
+
waitForProcessing: resolved.wait,
|
|
1897
|
+
processingTimeoutSeconds: resolved.processingTimeout,
|
|
1898
|
+
publish: resolved.publish
|
|
1899
|
+
});
|
|
1900
|
+
});
|
|
1901
|
+
releaseCommand.command("upload").description("Upload a bundle as a new immutable generation").requiredOption("--release <id>", "Hosted release ID").requiredOption("--bundle <path>", "Existing hosted release zip").option("--dir <path>", "Directory used to resolve the bundle path").option("--platform-url <url>", "Hosted Air Jam platform base URL").action(async (options) => {
|
|
1902
|
+
const resolved = resolveActionOptions(options);
|
|
1903
|
+
await runReleaseUploadCommand({
|
|
1904
|
+
platformUrl: resolved.platformUrl,
|
|
1905
|
+
releaseId: resolved.release,
|
|
1906
|
+
dir: resolved.dir,
|
|
1907
|
+
bundle: resolved.bundle
|
|
1908
|
+
});
|
|
1909
|
+
});
|
|
1910
|
+
releaseCommand.command("finalize").description("Finalize one exact immutable release generation").requiredOption("--release <id>", "Hosted release ID").requiredOption("--generation <id>", "Immutable generation ID").option("--platform-url <url>", "Hosted Air Jam platform base URL").action(async (options) => {
|
|
1911
|
+
const resolved = resolveActionOptions(options);
|
|
1912
|
+
await runReleaseFinalizeCommand({
|
|
1913
|
+
platformUrl: resolved.platformUrl,
|
|
1914
|
+
releaseId: resolved.release,
|
|
1915
|
+
generationId: resolved.generation
|
|
1916
|
+
});
|
|
1917
|
+
});
|
|
1918
|
+
releaseCommand.command("publish").description("Publish one ready hosted release").requiredOption("--release <id>", "Hosted release ID to publish").option("--platform-url <url>", "Hosted Air Jam platform base URL").action(async (options) => {
|
|
1919
|
+
const resolved = resolveActionOptions(options);
|
|
1920
|
+
await runReleasePublishCommand({
|
|
1921
|
+
platformUrl: resolved.platformUrl,
|
|
1922
|
+
releaseId: resolved.release
|
|
1923
|
+
});
|
|
1924
|
+
});
|
|
1925
|
+
releaseCommand.command("export").description("Download one exact immutable hosted release generation").requiredOption("--release <id>", "Hosted release ID").requiredOption("--generation <id>", "Immutable generation ID").option("--dir <path>", "Directory used to resolve the output path").option("--out <path>", "Output archive path; refuses to overwrite").option("--platform-url <url>", "Hosted Air Jam platform base URL").action(async (options) => {
|
|
1926
|
+
const resolved = resolveActionOptions(options);
|
|
1927
|
+
await runReleaseExportCommand({
|
|
1928
|
+
platformUrl: resolved.platformUrl,
|
|
1929
|
+
releaseId: resolved.release,
|
|
1930
|
+
generationId: resolved.generation,
|
|
1931
|
+
dir: resolved.dir,
|
|
1932
|
+
out: resolved.out
|
|
1933
|
+
});
|
|
1934
|
+
});
|
|
1935
|
+
releaseCommand.action(() => {
|
|
1936
|
+
releaseCommand.outputHelp();
|
|
1937
|
+
});
|
|
1938
|
+
const authCommand = program.command("auth").description("Authenticate the local Air Jam CLI with the hosted platform");
|
|
1939
|
+
authCommand.command("login").description("Start browser-assisted Air Jam CLI login").option("--platform-url <url>", "Hosted Air Jam platform base URL").option("--client-name <name>", "Optional machine-readable client label").action(async (options) => {
|
|
1940
|
+
await runAuthLoginCommand(
|
|
1941
|
+
resolveActionOptions(options)
|
|
1942
|
+
);
|
|
1943
|
+
});
|
|
1944
|
+
authCommand.command("whoami").description("Inspect the current stored Air Jam platform session").option("--platform-url <url>", "Hosted Air Jam platform base URL").action(async (options) => {
|
|
1945
|
+
await runAuthWhoAmICommand(
|
|
1946
|
+
resolveActionOptions(options)
|
|
1947
|
+
);
|
|
1948
|
+
});
|
|
1949
|
+
authCommand.command("logout").description("Revoke the current stored Air Jam platform session").option("--platform-url <url>", "Hosted Air Jam platform base URL").action(async (options) => {
|
|
1950
|
+
await runAuthLogoutCommand(
|
|
1951
|
+
resolveActionOptions(options)
|
|
1952
|
+
);
|
|
1953
|
+
});
|
|
1954
|
+
authCommand.action(() => {
|
|
1955
|
+
authCommand.outputHelp();
|
|
1956
|
+
});
|
|
1957
|
+
const mcpCommand = program.command("mcp").description("Inspect or initialize project-local Air Jam MCP setup");
|
|
1958
|
+
mcpCommand.command("doctor").description("Inspect the current project's Air Jam MCP setup").option("--dir <path>", "Project directory to inspect").option("--json", "Print one machine-readable JSON document", false).action(async (options) => {
|
|
1959
|
+
await runMcpDoctor(
|
|
1960
|
+
resolveActionOptions(options)
|
|
1961
|
+
);
|
|
1962
|
+
});
|
|
1963
|
+
mcpCommand.command("init").description(`Write ${AIRJAM_PROJECT_MCP_FILE2} for the current project`).option("--dir <path>", "Project directory to inspect").option("--force", "Overwrite an existing project-local MCP config", false).option("--json", "Print one machine-readable JSON document", false).action(async (options) => {
|
|
1964
|
+
await runMcpInit(
|
|
1965
|
+
resolveActionOptions(options)
|
|
1966
|
+
);
|
|
1967
|
+
});
|
|
1968
|
+
mcpCommand.command("config").description("Render a portable, Codex, or Claude Desktop MCP profile").option("--dir <path>", "Project directory to inspect").option(
|
|
1969
|
+
"--profile <profile>",
|
|
1970
|
+
"Profile to render (portable, codex, or claude-desktop)",
|
|
1971
|
+
"portable"
|
|
1972
|
+
).option("--json", "Print the rendered profile metadata as JSON", false).action(async (options) => {
|
|
1973
|
+
const resolved = resolveActionOptions(options);
|
|
1974
|
+
await runMcpConfig(resolved);
|
|
1975
|
+
});
|
|
1976
|
+
mcpCommand.action(() => {
|
|
1977
|
+
mcpCommand.outputHelp();
|
|
1978
|
+
});
|
|
1979
|
+
const sessionCommand = program.command("session").description(
|
|
1980
|
+
"Operate persistent semantic game sessions through stable JSON contracts"
|
|
1981
|
+
);
|
|
1982
|
+
sessionCommand.command("open").description("Open a persistent semantic game session").option("--dir <path>", "Project directory").option("--game <id>", "Game ID in a monorepo").option(
|
|
1983
|
+
"--mode <mode>",
|
|
1984
|
+
"Dev mode (standalone-dev, arcade-dev, or arcade-test)"
|
|
1985
|
+
).option("--secure", "Use secure local topology", false).option("--room <id>", "Existing room ID").option("--controller-url <url>", "Existing controller join URL").option("--timeout-ms <ms>", "Connection timeout in milliseconds", Number).action(async (options) => {
|
|
1986
|
+
const input = resolveActionOptions(options);
|
|
1987
|
+
const result = await openSession({
|
|
1988
|
+
dir: input.dir,
|
|
1989
|
+
gameId: input.game,
|
|
1990
|
+
mode: input.mode,
|
|
1991
|
+
secure: input.secure,
|
|
1992
|
+
roomId: input.room,
|
|
1993
|
+
controllerJoinUrl: input.controllerUrl,
|
|
1994
|
+
timeoutMs: input.timeoutMs
|
|
1995
|
+
});
|
|
1996
|
+
process.stdout.write(`${JSON.stringify(result, null, 2)}
|
|
1997
|
+
`);
|
|
1998
|
+
});
|
|
1999
|
+
sessionCommand.command("read").description("Read runtime and semantic state from a persistent session").argument("<session-id>", "Game session ID").option("--dir <path>", "Project directory").option("--no-sync", "Read without requesting a fresh semantic snapshot").option("--timeout-ms <ms>", "Snapshot timeout in milliseconds", Number).action(async (sessionId, options) => {
|
|
2000
|
+
const input = resolveActionOptions(options);
|
|
2001
|
+
const result = await readSession({
|
|
2002
|
+
dir: input.dir,
|
|
2003
|
+
gameSessionId: sessionId,
|
|
2004
|
+
requestSync: input.sync,
|
|
2005
|
+
timeoutMs: input.timeoutMs
|
|
2006
|
+
});
|
|
2007
|
+
process.stdout.write(`${JSON.stringify(result, null, 2)}
|
|
2008
|
+
`);
|
|
2009
|
+
});
|
|
2010
|
+
sessionCommand.command("input").description("Send validated controller input through a persistent session").argument("<session-id>", "Game session ID").requiredOption("--input <json>", "Controller input JSON object").option("--dir <path>", "Project directory").action(async (sessionId, options) => {
|
|
2011
|
+
const input = resolveActionOptions(
|
|
2012
|
+
options
|
|
2013
|
+
);
|
|
2014
|
+
const result = await sendSessionInput({
|
|
2015
|
+
dir: input.dir,
|
|
2016
|
+
gameSessionId: sessionId,
|
|
2017
|
+
input: parseJsonObject(input.input)
|
|
2018
|
+
});
|
|
2019
|
+
process.stdout.write(`${JSON.stringify(result, null, 2)}
|
|
2020
|
+
`);
|
|
2021
|
+
});
|
|
2022
|
+
sessionCommand.command("invoke").description("Invoke one published semantic action").argument("<session-id>", "Game session ID").argument("<action-id>", "Published action ID, including its lane prefix").option("--payload <json>", "JSON payload or plain string payload").option("--dir <path>", "Project directory").option("--timeout-ms <ms>", "Action timeout in milliseconds", Number).action(async (sessionId, actionId, options) => {
|
|
2023
|
+
const input = resolveActionOptions(options);
|
|
2024
|
+
const result = await invokeSessionAction({
|
|
2025
|
+
dir: input.dir,
|
|
2026
|
+
gameSessionId: sessionId,
|
|
2027
|
+
actionId,
|
|
2028
|
+
...input.payload !== void 0 ? { payload: parseJsonValue(input.payload) } : {},
|
|
2029
|
+
timeoutMs: input.timeoutMs
|
|
2030
|
+
});
|
|
2031
|
+
process.stdout.write(`${JSON.stringify(result, null, 2)}
|
|
2032
|
+
`);
|
|
2033
|
+
});
|
|
2034
|
+
sessionCommand.command("capture").description(
|
|
2035
|
+
"Capture canonical host and controller screenshots from a persistent session"
|
|
2036
|
+
).argument("<session-id>", "Game session ID").option("--dir <path>", "Project directory").option("--timeout-ms <ms>", "Capture timeout in milliseconds", Number).action(async (sessionId, options) => {
|
|
2037
|
+
const input = resolveActionOptions(options);
|
|
2038
|
+
const result = await captureSessionVisuals({
|
|
2039
|
+
dir: input.dir,
|
|
2040
|
+
gameSessionId: sessionId,
|
|
2041
|
+
timeoutMs: input.timeoutMs
|
|
2042
|
+
});
|
|
2043
|
+
process.stdout.write(`${JSON.stringify(result, null, 2)}
|
|
2044
|
+
`);
|
|
2045
|
+
});
|
|
2046
|
+
sessionCommand.command("close").description("Close a persistent semantic game session").argument("<session-id>", "Game session ID").option("--dir <path>", "Project directory").action(async (sessionId, options) => {
|
|
2047
|
+
const input = resolveActionOptions(options);
|
|
2048
|
+
const result = await closeSession({
|
|
2049
|
+
dir: input.dir,
|
|
2050
|
+
gameSessionId: sessionId
|
|
2051
|
+
});
|
|
2052
|
+
process.stdout.write(`${JSON.stringify(result, null, 2)}
|
|
2053
|
+
`);
|
|
2054
|
+
});
|
|
2055
|
+
const sessionBrokerCommand = sessionCommand.command("broker").description("Inspect or stop the project-local semantic session broker");
|
|
2056
|
+
sessionBrokerCommand.command("status").description("Inspect broker health").option("--dir <path>", "Project directory").action(async (options) => {
|
|
2057
|
+
const result = await runSessionBrokerStatus(
|
|
2058
|
+
resolveActionOptions(options)
|
|
2059
|
+
);
|
|
2060
|
+
process.stdout.write(`${JSON.stringify(result, null, 2)}
|
|
2061
|
+
`);
|
|
2062
|
+
});
|
|
2063
|
+
sessionBrokerCommand.command("stop").description("Close active sessions and stop the broker").option("--dir <path>", "Project directory").action(async (options) => {
|
|
2064
|
+
const result = await runSessionBrokerStop(
|
|
2065
|
+
resolveActionOptions(options)
|
|
2066
|
+
);
|
|
2067
|
+
process.stdout.write(`${JSON.stringify(result, null, 2)}
|
|
2068
|
+
`);
|
|
2069
|
+
});
|
|
2070
|
+
sessionCommand.action(() => sessionCommand.outputHelp());
|
|
2071
|
+
program.command("__session-broker", { hidden: true }).requiredOption("--dir <path>", "Project directory").action(async (options) => {
|
|
2072
|
+
const input = resolveActionOptions(options);
|
|
2073
|
+
await runSessionBrokerProcess(input.dir);
|
|
2074
|
+
});
|
|
2075
|
+
program.command("status").description("Show local Air Jam dev process and known-port status").option("--dir <path>", "Project directory to inspect").action(async (options) => {
|
|
2076
|
+
const input = resolveActionOptions(options);
|
|
2077
|
+
const status = await getDevStatus({ cwd: input.dir });
|
|
2078
|
+
console.log(JSON.stringify(status, null, 2));
|
|
2079
|
+
});
|
|
2080
|
+
const resetCommand = program.command("reset").description("Reset local Air Jam development state");
|
|
2081
|
+
resetCommand.command("local").description(
|
|
2082
|
+
"Stop managed dev processes and stale known-port Air Jam local listeners"
|
|
2083
|
+
).option("--dir <path>", "Project directory to reset").action(async (options) => {
|
|
2084
|
+
const input = resolveActionOptions(options);
|
|
2085
|
+
const result = await resetLocalDev({ cwd: input.dir });
|
|
2086
|
+
console.log(JSON.stringify(result, null, 2));
|
|
2087
|
+
});
|
|
2088
|
+
const devCommand = program.command("dev").description("Run project-local Air Jam game development").argument("[passthrough...]", "Additional runtime flags").allowExcessArguments(true).allowUnknownOption(false).option("--secure", "Start secure local game dev", false).option(
|
|
2089
|
+
"--secure-mode <mode>",
|
|
2090
|
+
"Secure mode to use when --secure is enabled (local or tunnel)"
|
|
2091
|
+
).option(
|
|
2092
|
+
"--preview-managed",
|
|
2093
|
+
"Advanced/internal: start foreground Vite with a background server",
|
|
2094
|
+
false
|
|
2095
|
+
).option("--web-only", "Start only the game app", false).option("--server-only", "Start only the local Air Jam server", false).option(
|
|
2096
|
+
"--allow-existing-game",
|
|
2097
|
+
"Reuse an already-running Vite server on the game port",
|
|
2098
|
+
false
|
|
2099
|
+
).addHelpText(
|
|
2100
|
+
"after",
|
|
2101
|
+
[
|
|
2102
|
+
"",
|
|
2103
|
+
"Network isolation:",
|
|
2104
|
+
" VITE_PORT=<port> Game app port (default: 5173)",
|
|
2105
|
+
" AIR_JAM_SERVER_PORT=<port> Local server port (default: 4000)",
|
|
2106
|
+
" VITE_AIR_JAM_PUBLIC_HOST=<url> Explicit host/controller origin",
|
|
2107
|
+
"",
|
|
2108
|
+
"Set all three when parallel agents or local projects need isolated dev stacks."
|
|
2109
|
+
].join("\n")
|
|
2110
|
+
).action(async () => {
|
|
2111
|
+
await runGameDevCli({
|
|
2112
|
+
argv: normalizeRuntimeCliArgv(process.argv.slice(3))
|
|
2113
|
+
});
|
|
2114
|
+
});
|
|
2115
|
+
devCommand.command("start").description("Start a managed Air Jam dev process and return JSON").option("--dir <path>", "Project directory to start").option("--game <id>", "Game ID in a monorepo").option(
|
|
2116
|
+
"--mode <mode>",
|
|
2117
|
+
"Dev mode (standalone-dev, arcade-dev, or arcade-test)",
|
|
2118
|
+
"standalone-dev"
|
|
2119
|
+
).option("--secure", "Use secure local topology", false).action(async (options) => {
|
|
2120
|
+
const input = resolveActionOptions(options);
|
|
2121
|
+
const result = await startDev({
|
|
2122
|
+
cwd: input.dir,
|
|
2123
|
+
gameId: input.game,
|
|
2124
|
+
mode: input.mode,
|
|
2125
|
+
secure: input.secure
|
|
2126
|
+
});
|
|
2127
|
+
process.stdout.write(`${JSON.stringify(result, null, 2)}
|
|
2128
|
+
`);
|
|
2129
|
+
});
|
|
2130
|
+
devCommand.command("stop").description("Stop managed Air Jam dev processes and return JSON").option("--dir <path>", "Project directory to stop").option("--process <id>", "Managed process ID").option(
|
|
2131
|
+
"--mode <mode>",
|
|
2132
|
+
"Stop only one dev mode (standalone-dev, arcade-dev, or arcade-test)"
|
|
2133
|
+
).action(async (options) => {
|
|
2134
|
+
const input = resolveActionOptions(options);
|
|
2135
|
+
const result = await stopDev({
|
|
2136
|
+
cwd: input.dir,
|
|
2137
|
+
processId: input.process,
|
|
2138
|
+
mode: input.mode
|
|
2139
|
+
});
|
|
2140
|
+
process.stdout.write(`${JSON.stringify(result, null, 2)}
|
|
2141
|
+
`);
|
|
2142
|
+
});
|
|
2143
|
+
program.command("secure:init").description("Initialize local secure Air Jam game development").argument("[passthrough...]", "Additional runtime flags").allowExcessArguments(true).allowUnknownOption(false).option("--mode <mode>", "Secure mode to configure (local or tunnel)").option("--hostname <hostname>", "Tunnel hostname for secure tunnel mode").option("--tunnel <name>", "Cloudflare tunnel name for secure tunnel mode").action(async () => {
|
|
2144
|
+
await runSecureInitCli({
|
|
2145
|
+
argv: normalizeRuntimeCliArgv(process.argv.slice(3))
|
|
2146
|
+
});
|
|
2147
|
+
});
|
|
2148
|
+
program.command("topology").description(
|
|
2149
|
+
"Print the resolved project runtime topology for the current game"
|
|
2150
|
+
).allowUnknownOption(false).requiredOption(
|
|
2151
|
+
"--mode <mode>",
|
|
2152
|
+
"Topology mode to inspect (standalone-dev, self-hosted-production, hosted-release)"
|
|
2153
|
+
).option(
|
|
2154
|
+
"--secure",
|
|
2155
|
+
"Resolve standalone local topology using trusted local HTTPS",
|
|
2156
|
+
false
|
|
2157
|
+
).addHelpText(
|
|
2158
|
+
"after",
|
|
2159
|
+
"\nTopology honors VITE_PORT, AIR_JAM_SERVER_PORT, VITE_AIR_JAM_SERVER_URL, and VITE_AIR_JAM_PUBLIC_HOST.\n"
|
|
2160
|
+
).action(async () => {
|
|
2161
|
+
await runProjectTopologyCli({
|
|
2162
|
+
argv: normalizeRuntimeCliArgv(process.argv.slice(3))
|
|
2163
|
+
});
|
|
2164
|
+
});
|
|
2165
|
+
return program;
|
|
2166
|
+
};
|
|
2167
|
+
async function main() {
|
|
2168
|
+
const program = buildProgram();
|
|
2169
|
+
await program.parseAsync(process.argv);
|
|
2170
|
+
}
|
|
2171
|
+
main().catch((err) => {
|
|
2172
|
+
if (isEnvValidationError(err)) {
|
|
2173
|
+
console.error(
|
|
2174
|
+
formatEnvValidationError(err, {
|
|
2175
|
+
docsHint: "Fix the listed env values in .env.local (or CI/deployment env) and retry."
|
|
2176
|
+
})
|
|
2177
|
+
);
|
|
2178
|
+
process.exit(1);
|
|
2179
|
+
return;
|
|
2180
|
+
}
|
|
2181
|
+
console.error(kleur2.red("Error:"), err);
|
|
2182
|
+
process.exit(1);
|
|
2183
|
+
});
|
|
2184
|
+
//# sourceMappingURL=index.js.map
|