@air-jam/devtools 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.
Files changed (135) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +52 -2
  3. package/dist/agent.d.ts +15 -0
  4. package/dist/agent.js +19 -0
  5. package/dist/agent.js.map +1 -0
  6. package/dist/chunk-5YAARMW5.js +36 -0
  7. package/dist/chunk-5YAARMW5.js.map +1 -0
  8. package/dist/chunk-6WQODT37.js +1019 -0
  9. package/dist/chunk-6WQODT37.js.map +1 -0
  10. package/dist/chunk-CKFT2ZJE.js +801 -0
  11. package/dist/chunk-CKFT2ZJE.js.map +1 -0
  12. package/dist/chunk-ER3Q2C4G.js +358 -0
  13. package/dist/chunk-ER3Q2C4G.js.map +1 -0
  14. package/dist/chunk-GUEZP773.js +851 -0
  15. package/dist/chunk-GUEZP773.js.map +1 -0
  16. package/dist/chunk-HIDNI56E.js +33 -0
  17. package/dist/chunk-HIDNI56E.js.map +1 -0
  18. package/dist/chunk-QKXS5D35.js +43 -0
  19. package/dist/chunk-QKXS5D35.js.map +1 -0
  20. package/dist/chunk-S4LSCEVE.js +261 -0
  21. package/dist/chunk-S4LSCEVE.js.map +1 -0
  22. package/dist/chunk-VKMJO6VN.js +360 -0
  23. package/dist/chunk-VKMJO6VN.js.map +1 -0
  24. package/dist/chunk-WFUR3MXY.js +67 -0
  25. package/dist/chunk-WFUR3MXY.js.map +1 -0
  26. package/dist/chunk-XEMR7KUE.js +361 -0
  27. package/dist/chunk-XEMR7KUE.js.map +1 -0
  28. package/dist/chunk-ZLPD7FY5.js +191 -0
  29. package/dist/chunk-ZLPD7FY5.js.map +1 -0
  30. package/dist/context.d.ts +13 -0
  31. package/dist/context.js +9 -0
  32. package/dist/context.js.map +1 -0
  33. package/dist/controller.d.ts +41 -0
  34. package/dist/controller.js +30 -0
  35. package/dist/controller.js.map +1 -0
  36. package/dist/dev.d.ts +15 -0
  37. package/dist/dev.js +20 -0
  38. package/dist/dev.js.map +1 -0
  39. package/dist/game-session-broker.d.ts +57 -0
  40. package/dist/game-session-broker.js +235 -0
  41. package/dist/game-session-broker.js.map +1 -0
  42. package/dist/game-session.d.ts +13 -0
  43. package/dist/game-session.js +24 -0
  44. package/dist/game-session.js.map +1 -0
  45. package/dist/games.d.ts +21 -0
  46. package/dist/games.js +14 -0
  47. package/dist/games.js.map +1 -0
  48. package/dist/harness/visual.d.ts +321 -0
  49. package/dist/harness/visual.js +41 -0
  50. package/dist/harness/visual.js.map +1 -0
  51. package/dist/logs.d.ts +9 -0
  52. package/dist/logs.js +58 -0
  53. package/dist/logs.js.map +1 -0
  54. package/dist/mcp-config.d.ts +63 -0
  55. package/dist/mcp-config.js +190 -0
  56. package/dist/mcp-config.js.map +1 -0
  57. package/dist/platform-auth.d.ts +112 -0
  58. package/dist/platform-auth.js +37 -0
  59. package/dist/platform-auth.js.map +1 -0
  60. package/dist/platform-game-media.d.ts +309 -0
  61. package/dist/platform-game-media.js +168 -0
  62. package/dist/platform-game-media.js.map +1 -0
  63. package/dist/platform-games.d.ts +65 -0
  64. package/dist/platform-games.js +251 -0
  65. package/dist/platform-games.js.map +1 -0
  66. package/dist/quality.d.ts +10 -0
  67. package/dist/quality.js +63 -0
  68. package/dist/quality.js.map +1 -0
  69. package/dist/release.d.ts +1094 -0
  70. package/dist/release.js +1347 -0
  71. package/dist/release.js.map +1 -0
  72. package/dist/tooling/agent-contract.d.ts +2 -0
  73. package/dist/tooling/agent-contract.js +193 -0
  74. package/dist/tooling/agent-contract.js.map +1 -0
  75. package/dist/tooling/hold-runtime-host.d.ts +2 -0
  76. package/dist/tooling/hold-runtime-host.js +229 -0
  77. package/dist/tooling/hold-runtime-host.js.map +1 -0
  78. package/dist/tooling/inspect-airjam-agent.d.ts +2 -0
  79. package/dist/tooling/inspect-airjam-agent.js +37 -0
  80. package/dist/tooling/inspect-airjam-agent.js.map +1 -0
  81. package/dist/tooling/list-visual-scenarios.d.ts +2 -0
  82. package/dist/tooling/list-visual-scenarios.js +62 -0
  83. package/dist/tooling/list-visual-scenarios.js.map +1 -0
  84. package/dist/tooling/managed-dev-supervisor.d.ts +2 -0
  85. package/dist/tooling/managed-dev-supervisor.js +51 -0
  86. package/dist/tooling/managed-dev-supervisor.js.map +1 -0
  87. package/dist/tooling/run-visual-capture.d.ts +2 -0
  88. package/dist/tooling/run-visual-capture.js +167 -0
  89. package/dist/tooling/run-visual-capture.js.map +1 -0
  90. package/dist/types-C6NrHt88.d.ts +775 -0
  91. package/dist/visual.d.ts +15 -0
  92. package/dist/visual.js +263 -0
  93. package/dist/visual.js.map +1 -0
  94. package/package.json +113 -3
  95. package/src/agent.ts +380 -0
  96. package/src/commands.ts +40 -0
  97. package/src/context.ts +229 -0
  98. package/src/controller.ts +1376 -0
  99. package/src/dev.ts +999 -0
  100. package/src/fs-utils.ts +93 -0
  101. package/src/game-action-observation.ts +96 -0
  102. package/src/game-session-broker.ts +301 -0
  103. package/src/game-session.ts +459 -0
  104. package/src/games.ts +266 -0
  105. package/src/harness/visual/prefab-contract.ts +29 -0
  106. package/src/harness/visual/prefab-runner.ts +178 -0
  107. package/src/harness/visual/runner.ts +546 -0
  108. package/src/harness/visual/scenario-contract.ts +9 -0
  109. package/src/harness/visual/scenario-helpers.ts +63 -0
  110. package/src/harness/visual/session.ts +369 -0
  111. package/src/harness/visual/types.ts +181 -0
  112. package/src/harness/visual.ts +7 -0
  113. package/src/helper-scripts.ts +49 -0
  114. package/src/logs.ts +67 -0
  115. package/src/mcp-config.ts +262 -0
  116. package/src/platform-auth.ts +455 -0
  117. package/src/platform-game-media.ts +209 -0
  118. package/src/platform-games.ts +315 -0
  119. package/src/quality.ts +82 -0
  120. package/src/release.ts +1697 -0
  121. package/src/runtime-owner-protocol.ts +130 -0
  122. package/src/tooling/agent-contract.ts +232 -0
  123. package/src/tooling/agent-declaration.ts +36 -0
  124. package/src/tooling/airjam-agent-inspection.ts +45 -0
  125. package/src/tooling/airjam-agent.ts +118 -0
  126. package/src/tooling/hold-runtime-host.ts +224 -0
  127. package/src/tooling/inspect-airjam-agent.ts +20 -0
  128. package/src/tooling/list-visual-scenarios.ts +64 -0
  129. package/src/tooling/managed-dev-supervisor.ts +71 -0
  130. package/src/tooling/run-visual-capture.ts +217 -0
  131. package/src/tooling/runtime-owner-actions.ts +42 -0
  132. package/src/tooling/visual-pack.ts +46 -0
  133. package/src/types.ts +951 -0
  134. package/src/visual.ts +304 -0
  135. package/src/workspace-contract.ts +32 -0
package/src/visual.ts ADDED
@@ -0,0 +1,304 @@
1
+ import path from "node:path";
2
+ import { z } from "zod";
3
+ import { runCommandResult } from "./commands.js";
4
+ import {
5
+ getTopology,
6
+ startDev,
7
+ stopDev,
8
+ tryAttachToRunningDev,
9
+ } from "./dev.js";
10
+ import { pathExists, readJsonFile } from "./fs-utils.js";
11
+ import { inspectGame } from "./games.js";
12
+ import {
13
+ resolveDevtoolsHelperArgs,
14
+ resolveDevtoolsHelperScript,
15
+ } from "./helper-scripts.js";
16
+ import { inspectAirJamAgentConfig } from "./tooling/airjam-agent-inspection.js";
17
+ import type {
18
+ AirJamSurfaceUrlSummary,
19
+ AirJamVisualArtifactMode,
20
+ AirJamVisualCaptureInspection,
21
+ AirJamVisualCaptureSummary,
22
+ AirJamVisualScenarioList,
23
+ AirJamVisualScenarioMetadata,
24
+ CaptureVisualsOptions,
25
+ CaptureVisualsResult,
26
+ ListVisualScenariosOptions,
27
+ } from "./types.js";
28
+
29
+ export type {
30
+ AirJamVisualArtifactMode,
31
+ AirJamVisualCaptureInspection,
32
+ AirJamVisualCaptureSummary,
33
+ AirJamVisualScenarioList,
34
+ AirJamVisualScenarioMetadata,
35
+ CaptureVisualsOptions,
36
+ CaptureVisualsResult,
37
+ ListVisualScenariosOptions,
38
+ } from "./types.js";
39
+
40
+ type ResolvedVisualSource = {
41
+ configPath: string;
42
+ scenarioModulePath: string;
43
+ };
44
+
45
+ const captureUrlsSchema = z.object({
46
+ appOrigin: z.url(),
47
+ hostUrl: z.url(),
48
+ controllerBaseUrl: z.url(),
49
+ publicHost: z.url(),
50
+ localBuildUrl: z.url().nullable(),
51
+ browserBuildUrl: z.url().nullable(),
52
+ });
53
+
54
+ export type CaptureVisualsAtRuntimeOptions = Pick<
55
+ CaptureVisualsOptions,
56
+ "cwd" | "gameId" | "scenarioId" | "secure"
57
+ > & {
58
+ mode: AirJamVisualArtifactMode;
59
+ urls: AirJamSurfaceUrlSummary;
60
+ artifactRoot: string;
61
+ };
62
+
63
+ const resolveVisualArtifactRoot = (rootDir: string): string =>
64
+ path.join(rootDir, ".airjam", "artifacts", "visual");
65
+
66
+ const parseHelperJson = <T>(output: string): T => {
67
+ const startIndex = output.indexOf("{");
68
+ const endIndex = output.lastIndexOf("}");
69
+ if (startIndex === -1 || endIndex === -1 || endIndex < startIndex) {
70
+ throw new Error(`Expected JSON helper output but received:\n${output}`);
71
+ }
72
+
73
+ return JSON.parse(output.slice(startIndex, endIndex + 1)) as T;
74
+ };
75
+
76
+ const runTsxHelper = <T>({
77
+ helperFile,
78
+ args,
79
+ cwd,
80
+ }: {
81
+ helperFile: string;
82
+ args: string[];
83
+ cwd: string;
84
+ }): T => {
85
+ const result = runCommandResult({
86
+ command: process.execPath,
87
+ args: [...resolveDevtoolsHelperArgs(helperFile), ...args],
88
+ cwd,
89
+ });
90
+ if (!result.ok) {
91
+ throw new Error(
92
+ `Air Jam visual helper failed.\n\n${result.stderr || result.stdout}`,
93
+ );
94
+ }
95
+
96
+ return parseHelperJson<T>(result.stdout);
97
+ };
98
+
99
+ const resolveVisualSource = async (
100
+ configPath: string | null,
101
+ ): Promise<ResolvedVisualSource | null> => {
102
+ if (!configPath) {
103
+ return null;
104
+ }
105
+
106
+ const scenarioModulePath = await inspectAirJamAgentConfig(configPath).then(
107
+ (inspection) => inspection.visualScenariosModulePath,
108
+ );
109
+ return scenarioModulePath ? { configPath, scenarioModulePath } : null;
110
+ };
111
+
112
+ const readScenarioMetadata = async ({
113
+ artifactRoot,
114
+ summary,
115
+ }: {
116
+ artifactRoot: string;
117
+ summary: AirJamVisualCaptureInspection["summary"];
118
+ }): Promise<AirJamVisualScenarioMetadata[]> => {
119
+ const entries = await Promise.all(
120
+ summary.scenarios.map(async (scenario) => {
121
+ const metadataPath = path.join(
122
+ artifactRoot,
123
+ scenario.relativeDir,
124
+ "metadata.json",
125
+ );
126
+ return (await pathExists(metadataPath))
127
+ ? readJsonFile<AirJamVisualScenarioMetadata>(metadataPath)
128
+ : null;
129
+ }),
130
+ );
131
+
132
+ return entries.filter(
133
+ (entry): entry is AirJamVisualScenarioMetadata => entry !== null,
134
+ );
135
+ };
136
+
137
+ export const listVisualScenarios = async ({
138
+ cwd = process.cwd(),
139
+ gameId,
140
+ }: ListVisualScenariosOptions = {}): Promise<AirJamVisualScenarioList> => {
141
+ const game = await inspectGame({ cwd, gameId });
142
+ const source = await resolveVisualSource(game.configPath);
143
+ if (!source) {
144
+ throw new Error(
145
+ `No visual scenarios published for "${game.id}" in ${game.rootDir}.`,
146
+ );
147
+ }
148
+
149
+ const result = runTsxHelper<{
150
+ gameId: string;
151
+ scenarios: AirJamVisualScenarioList["scenarios"];
152
+ }>({
153
+ helperFile: resolveDevtoolsHelperScript("list-visual-scenarios.ts"),
154
+ cwd: game.rootDir,
155
+ args: [`--config=${source.configPath}`],
156
+ });
157
+ return {
158
+ gameId: result.gameId,
159
+ scenarioModulePath: source.scenarioModulePath,
160
+ scenarios: result.scenarios,
161
+ };
162
+ };
163
+
164
+ const withVisualSession = async <T>({
165
+ cwd = process.cwd(),
166
+ gameId,
167
+ mode = "standalone-dev",
168
+ secure = false,
169
+ run,
170
+ }: {
171
+ cwd?: string;
172
+ gameId?: string;
173
+ mode?: "standalone-dev" | "arcade-dev" | "arcade-test";
174
+ secure?: boolean;
175
+ run: (input: {
176
+ game: Awaited<ReturnType<typeof inspectGame>>;
177
+ visualSource: ResolvedVisualSource;
178
+ topology: Awaited<ReturnType<typeof getTopology>>;
179
+ }) => Promise<T>;
180
+ }): Promise<T> => {
181
+ const game = await inspectGame({ cwd, gameId });
182
+ const visualSource = await resolveVisualSource(game.configPath);
183
+ if (!visualSource) {
184
+ throw new Error(
185
+ `No visual scenarios published for "${game.id}" in ${game.rootDir}.`,
186
+ );
187
+ }
188
+
189
+ const attachedTopology = await tryAttachToRunningDev({
190
+ cwd,
191
+ gameId: game.id,
192
+ mode,
193
+ secure,
194
+ });
195
+ const session = attachedTopology
196
+ ? {
197
+ topology: attachedTopology,
198
+ reusedExistingProcess: true,
199
+ managedProcessId: attachedTopology.process?.id ?? null,
200
+ }
201
+ : await startDev({ cwd, gameId: game.id, mode, secure }).then(
202
+ (started) => ({
203
+ topology: started.topology,
204
+ reusedExistingProcess: started.reusedExistingProcess,
205
+ managedProcessId: started.process.id,
206
+ }),
207
+ );
208
+
209
+ try {
210
+ return await run({ game, visualSource, topology: session.topology });
211
+ } finally {
212
+ if (!session.reusedExistingProcess && session.managedProcessId) {
213
+ await stopDev({ cwd, processId: session.managedProcessId });
214
+ }
215
+ }
216
+ };
217
+
218
+ const captureGameAtRuntime = async ({
219
+ game,
220
+ visualSource,
221
+ scenarioId,
222
+ mode,
223
+ secure,
224
+ urls,
225
+ artifactRoot,
226
+ }: Omit<CaptureVisualsAtRuntimeOptions, "cwd" | "gameId"> & {
227
+ game: Awaited<ReturnType<typeof inspectGame>>;
228
+ visualSource: ResolvedVisualSource;
229
+ }): Promise<CaptureVisualsResult> => {
230
+ const resolvedUrls = captureUrlsSchema.parse(urls);
231
+ runTsxHelper<AirJamVisualCaptureSummary>({
232
+ helperFile: resolveDevtoolsHelperScript("run-visual-capture.ts"),
233
+ cwd: game.rootDir,
234
+ args: [
235
+ `--game-id=${game.id}`,
236
+ `--config=${visualSource.configPath}`,
237
+ `--module-path=${visualSource.scenarioModulePath}`,
238
+ `--artifact-root=${artifactRoot}`,
239
+ `--mode=${mode === "arcade-built" ? "arcade-test" : "standalone-dev"}`,
240
+ `--app-origin=${resolvedUrls.appOrigin}`,
241
+ `--host-url=${resolvedUrls.hostUrl}`,
242
+ `--controller-base-url=${resolvedUrls.controllerBaseUrl}`,
243
+ `--public-host=${resolvedUrls.publicHost}`,
244
+ ...(resolvedUrls.localBuildUrl
245
+ ? [`--local-build-url=${resolvedUrls.localBuildUrl}`]
246
+ : []),
247
+ ...(resolvedUrls.browserBuildUrl
248
+ ? [`--browser-build-url=${resolvedUrls.browserBuildUrl}`]
249
+ : []),
250
+ ...(scenarioId ? [`--scenario-id=${scenarioId}`] : []),
251
+ ...(secure ? ["--secure"] : []),
252
+ ],
253
+ });
254
+ const summaryPath = path.join(artifactRoot, game.id, "capture-summary.json");
255
+ const summary = await readJsonFile<AirJamVisualCaptureSummary>(summaryPath);
256
+ return {
257
+ gameId: game.id,
258
+ artifactRoot,
259
+ summaryPath,
260
+ summary,
261
+ scenarios: await readScenarioMetadata({ artifactRoot, summary }),
262
+ };
263
+ };
264
+
265
+ export const captureVisualsAtRuntime = async ({
266
+ cwd = process.cwd(),
267
+ gameId,
268
+ ...runtime
269
+ }: CaptureVisualsAtRuntimeOptions): Promise<CaptureVisualsResult> => {
270
+ const game = await inspectGame({ cwd, gameId });
271
+ const visualSource = await resolveVisualSource(game.configPath);
272
+ if (!visualSource) {
273
+ throw new Error(
274
+ `No visual scenarios published for "${game.id}" in ${game.rootDir}.`,
275
+ );
276
+ }
277
+ return captureGameAtRuntime({ game, visualSource, ...runtime });
278
+ };
279
+
280
+ export const captureVisuals = async ({
281
+ cwd = process.cwd(),
282
+ gameId,
283
+ scenarioId,
284
+ mode = "standalone-dev",
285
+ secure = false,
286
+ }: CaptureVisualsOptions = {}): Promise<CaptureVisualsResult> =>
287
+ withVisualSession({
288
+ cwd,
289
+ gameId,
290
+ mode,
291
+ secure,
292
+ run: ({ game, visualSource, topology }) =>
293
+ captureGameAtRuntime({
294
+ game,
295
+ visualSource,
296
+ scenarioId,
297
+ mode: mode === "arcade-test" ? "arcade-built" : "standalone-dev",
298
+ secure,
299
+ urls: topology.urls,
300
+ artifactRoot: resolveVisualArtifactRoot(
301
+ topology.process?.cwd ?? game.rootDir,
302
+ ),
303
+ }),
304
+ });
@@ -0,0 +1,32 @@
1
+ import { z } from "zod";
2
+ import type { AirJamDevMode, PackageJson } from "./types.js";
3
+
4
+ const workspaceSchema = z
5
+ .object({
6
+ cli: z.string().min(1),
7
+ modes: z
8
+ .array(z.enum(["standalone-dev", "arcade-dev", "arcade-test"]))
9
+ .min(1),
10
+ })
11
+ .strict();
12
+
13
+ export const readWorkspaceContract = (packageJson: PackageJson | null) => {
14
+ const declaration = z
15
+ .object({ workspace: workspaceSchema.optional() })
16
+ .passthrough()
17
+ .parse(packageJson?.airjam ?? {});
18
+ return declaration.workspace ?? null;
19
+ };
20
+
21
+ export const assertSupportedDevMode = (
22
+ packageJson: PackageJson | null,
23
+ mode: AirJamDevMode,
24
+ ) => {
25
+ const workspace = readWorkspaceContract(packageJson);
26
+ const supportedModes = workspace?.modes ?? ["standalone-dev"];
27
+ if (!supportedModes.includes(mode)) {
28
+ throw new Error(
29
+ `Mode "${mode}" is not supported by this project. Supported modes: ${supportedModes.join(", ")}.`,
30
+ );
31
+ }
32
+ };