@air-jam/devtools 0.0.0-stage → 1.0.0-beta.1

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 (256) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +112 -2
  3. package/dist/chunk-2O67AXCU.js +470 -0
  4. package/dist/chunk-2O67AXCU.js.map +1 -0
  5. package/dist/chunk-AO3ZDXF6.js +142 -0
  6. package/dist/chunk-AO3ZDXF6.js.map +1 -0
  7. package/dist/chunk-ART5TEYT.js +472 -0
  8. package/dist/chunk-ART5TEYT.js.map +1 -0
  9. package/dist/chunk-ASC2CK2R.js +77 -0
  10. package/dist/chunk-ASC2CK2R.js.map +1 -0
  11. package/dist/chunk-E3UZZGAV.js +50 -0
  12. package/dist/chunk-E3UZZGAV.js.map +1 -0
  13. package/dist/chunk-EJTE7UKX.js +64 -0
  14. package/dist/chunk-EJTE7UKX.js.map +1 -0
  15. package/dist/chunk-ESFKNN75.js +110 -0
  16. package/dist/chunk-ESFKNN75.js.map +1 -0
  17. package/dist/chunk-EU7A6PXW.js +1339 -0
  18. package/dist/chunk-EU7A6PXW.js.map +1 -0
  19. package/dist/chunk-FN7E6EA7.js +549 -0
  20. package/dist/chunk-FN7E6EA7.js.map +1 -0
  21. package/dist/chunk-GDFAWHGA.js +190 -0
  22. package/dist/chunk-GDFAWHGA.js.map +1 -0
  23. package/dist/chunk-HZUGBH4Y.js +347 -0
  24. package/dist/chunk-HZUGBH4Y.js.map +1 -0
  25. package/dist/chunk-ITKAOEGX.js +93 -0
  26. package/dist/chunk-ITKAOEGX.js.map +1 -0
  27. package/dist/chunk-JBCUTWRI.js +897 -0
  28. package/dist/chunk-JBCUTWRI.js.map +1 -0
  29. package/dist/chunk-JSI5S4WP.js +1174 -0
  30. package/dist/chunk-JSI5S4WP.js.map +1 -0
  31. package/dist/chunk-L4D675BG.js +97 -0
  32. package/dist/chunk-L4D675BG.js.map +1 -0
  33. package/dist/chunk-M6CJ7GQC.js +133 -0
  34. package/dist/chunk-M6CJ7GQC.js.map +1 -0
  35. package/dist/chunk-MEIMOSZC.js +749 -0
  36. package/dist/chunk-MEIMOSZC.js.map +1 -0
  37. package/dist/chunk-O3XG3FNL.js +1014 -0
  38. package/dist/chunk-O3XG3FNL.js.map +1 -0
  39. package/dist/chunk-OM6SCJ7H.js +18 -0
  40. package/dist/chunk-OM6SCJ7H.js.map +1 -0
  41. package/dist/chunk-PKD4WVX5.js +63 -0
  42. package/dist/chunk-PKD4WVX5.js.map +1 -0
  43. package/dist/chunk-PMBLXGFM.js +3384 -0
  44. package/dist/chunk-PMBLXGFM.js.map +1 -0
  45. package/dist/chunk-PMNE5GIN.js +279 -0
  46. package/dist/chunk-PMNE5GIN.js.map +1 -0
  47. package/dist/chunk-QAWI64VR.js +148 -0
  48. package/dist/chunk-QAWI64VR.js.map +1 -0
  49. package/dist/chunk-QGADSPHZ.js +449 -0
  50. package/dist/chunk-QGADSPHZ.js.map +1 -0
  51. package/dist/chunk-SPYN66UV.js +338 -0
  52. package/dist/chunk-SPYN66UV.js.map +1 -0
  53. package/dist/context.d.ts +19 -0
  54. package/dist/context.js +10 -0
  55. package/dist/context.js.map +1 -0
  56. package/dist/controller.d.ts +67 -0
  57. package/dist/controller.js +40 -0
  58. package/dist/controller.js.map +1 -0
  59. package/dist/dependencies.d.ts +44 -0
  60. package/dist/dependencies.js +10 -0
  61. package/dist/dependencies.js.map +1 -0
  62. package/dist/dev.d.ts +21 -0
  63. package/dist/dev.js +19 -0
  64. package/dist/dev.js.map +1 -0
  65. package/dist/game-builds.d.ts +200 -0
  66. package/dist/game-builds.js +16 -0
  67. package/dist/game-builds.js.map +1 -0
  68. package/dist/game-run-watch-CEd_SpAT.d.ts +84 -0
  69. package/dist/game-runs.d.ts +1452 -0
  70. package/dist/game-runs.js +76 -0
  71. package/dist/game-runs.js.map +1 -0
  72. package/dist/game-session-broker-CUvORfMd.d.ts +439 -0
  73. package/dist/game-session-broker.d.ts +4 -0
  74. package/dist/game-session-broker.js +40 -0
  75. package/dist/game-session-broker.js.map +1 -0
  76. package/dist/game-session.d.ts +3934 -0
  77. package/dist/game-session.js +195 -0
  78. package/dist/game-session.js.map +1 -0
  79. package/dist/game-settings.d.ts +16 -0
  80. package/dist/game-settings.js +237 -0
  81. package/dist/game-settings.js.map +1 -0
  82. package/dist/games.d.ts +28 -0
  83. package/dist/games.js +16 -0
  84. package/dist/games.js.map +1 -0
  85. package/dist/harness/visual.d.ts +204 -0
  86. package/dist/harness/visual.js +46 -0
  87. package/dist/harness/visual.js.map +1 -0
  88. package/dist/logs.d.ts +15 -0
  89. package/dist/logs.js +57 -0
  90. package/dist/logs.js.map +1 -0
  91. package/dist/managed-process-scope-BicYi_t9.d.ts +3 -0
  92. package/dist/mcp-config.d.ts +63 -0
  93. package/dist/mcp-config.js +191 -0
  94. package/dist/mcp-config.js.map +1 -0
  95. package/dist/platform-auth.d.ts +9 -0
  96. package/dist/platform-auth.js +45 -0
  97. package/dist/platform-auth.js.map +1 -0
  98. package/dist/platform-game-analytics.d.ts +51 -0
  99. package/dist/platform-game-analytics.js +49 -0
  100. package/dist/platform-game-analytics.js.map +1 -0
  101. package/dist/platform-game-app-id.d.ts +46 -0
  102. package/dist/platform-game-app-id.js +93 -0
  103. package/dist/platform-game-app-id.js.map +1 -0
  104. package/dist/platform-game-media.d.ts +347 -0
  105. package/dist/platform-game-media.js +168 -0
  106. package/dist/platform-game-media.js.map +1 -0
  107. package/dist/platform-games.d.ts +87 -0
  108. package/dist/platform-games.js +183 -0
  109. package/dist/platform-games.js.map +1 -0
  110. package/dist/quality.d.ts +16 -0
  111. package/dist/quality.js +62 -0
  112. package/dist/quality.js.map +1 -0
  113. package/dist/release.d.ts +1304 -0
  114. package/dist/release.js +34 -0
  115. package/dist/release.js.map +1 -0
  116. package/dist/rooms-check.d.ts +90 -0
  117. package/dist/rooms-check.js +717 -0
  118. package/dist/rooms-check.js.map +1 -0
  119. package/dist/source-tree-contract.d.ts +16 -0
  120. package/dist/source-tree-contract.js +13 -0
  121. package/dist/source-tree-contract.js.map +1 -0
  122. package/dist/testing.d.ts +464 -0
  123. package/dist/testing.js +27 -0
  124. package/dist/testing.js.map +1 -0
  125. package/dist/tooling/describe-game.d.ts +2 -0
  126. package/dist/tooling/describe-game.js +54 -0
  127. package/dist/tooling/describe-game.js.map +1 -0
  128. package/dist/tooling/game-session-broker.d.ts +2 -0
  129. package/dist/tooling/game-session-broker.js +28 -0
  130. package/dist/tooling/game-session-broker.js.map +1 -0
  131. package/dist/tooling/hold-runtime-host.d.ts +2 -0
  132. package/dist/tooling/hold-runtime-host.js +931 -0
  133. package/dist/tooling/hold-runtime-host.js.map +1 -0
  134. package/dist/tooling/list-visual-scenarios.d.ts +2 -0
  135. package/dist/tooling/list-visual-scenarios.js +25 -0
  136. package/dist/tooling/list-visual-scenarios.js.map +1 -0
  137. package/dist/tooling/managed-dev-supervisor.d.ts +2 -0
  138. package/dist/tooling/managed-dev-supervisor.js +51 -0
  139. package/dist/tooling/managed-dev-supervisor.js.map +1 -0
  140. package/dist/tooling/process-scope-bootstrap.mjs +24 -0
  141. package/dist/tooling/process-scope-guard.d.ts +2 -0
  142. package/dist/tooling/process-scope-guard.js +388 -0
  143. package/dist/tooling/process-scope-guard.js.map +1 -0
  144. package/dist/tooling/process-scope-windows.ps1 +148 -0
  145. package/dist/tooling/rooms-check-device.d.ts +2 -0
  146. package/dist/tooling/rooms-check-device.js +498 -0
  147. package/dist/tooling/rooms-check-device.js.map +1 -0
  148. package/dist/tooling/run-headless-room.d.ts +2 -0
  149. package/dist/tooling/run-headless-room.js +287 -0
  150. package/dist/tooling/run-headless-room.js.map +1 -0
  151. package/dist/tooling/run-test-profile.d.ts +2 -0
  152. package/dist/tooling/run-test-profile.js +181 -0
  153. package/dist/tooling/run-test-profile.js.map +1 -0
  154. package/dist/tooling/run-visual-capture.d.ts +2 -0
  155. package/dist/tooling/run-visual-capture.js +203 -0
  156. package/dist/tooling/run-visual-capture.js.map +1 -0
  157. package/dist/tooling/seal-game-build.d.ts +2 -0
  158. package/dist/tooling/seal-game-build.js +120 -0
  159. package/dist/tooling/seal-game-build.js.map +1 -0
  160. package/dist/types-CdYrgrG_.d.ts +1036 -0
  161. package/dist/types-DyRD-ym1.d.ts +141 -0
  162. package/dist/visual.d.ts +21 -0
  163. package/dist/visual.js +219 -0
  164. package/dist/visual.js.map +1 -0
  165. package/package.json +150 -3
  166. package/src/bounded-response.ts +28 -0
  167. package/src/built-game-runtime.ts +152 -0
  168. package/src/commands.ts +40 -0
  169. package/src/context.ts +218 -0
  170. package/src/controller-protocol.ts +22 -0
  171. package/src/controller.ts +1526 -0
  172. package/src/current-room-host.ts +166 -0
  173. package/src/decision-provider.ts +102 -0
  174. package/src/dependencies.ts +176 -0
  175. package/src/dependency-install-contract.ts +12 -0
  176. package/src/dev.ts +995 -0
  177. package/src/fs-utils.ts +93 -0
  178. package/src/game-action-observation.ts +106 -0
  179. package/src/game-build-protocol.ts +72 -0
  180. package/src/game-build.ts +483 -0
  181. package/src/game-run-owner.ts +2358 -0
  182. package/src/game-run-protocol.ts +448 -0
  183. package/src/game-run-record.ts +92 -0
  184. package/src/game-run-replay.ts +95 -0
  185. package/src/game-run-watch.ts +155 -0
  186. package/src/game-session-broker.ts +793 -0
  187. package/src/game-session-operations.ts +61 -0
  188. package/src/game-session-protocol.ts +180 -0
  189. package/src/game-session-runtime.ts +861 -0
  190. package/src/game-session.ts +206 -0
  191. package/src/game-settings.ts +295 -0
  192. package/src/games.ts +262 -0
  193. package/src/harness/visual/browser.ts +100 -0
  194. package/src/harness/visual/controller-observation.ts +181 -0
  195. package/src/harness/visual/prefab-contract.ts +29 -0
  196. package/src/harness/visual/prefab-runner.ts +178 -0
  197. package/src/harness/visual/runner.ts +549 -0
  198. package/src/harness/visual/runtime-controller-observations.ts +151 -0
  199. package/src/harness/visual/scenario-contract.ts +8 -0
  200. package/src/harness/visual/scenario-helpers.ts +67 -0
  201. package/src/harness/visual/screencast.ts +155 -0
  202. package/src/harness/visual/session.ts +400 -0
  203. package/src/harness/visual/types.ts +184 -0
  204. package/src/harness/visual.ts +7 -0
  205. package/src/headless-room-protocol.ts +112 -0
  206. package/src/headless-room.ts +222 -0
  207. package/src/helper-channel.ts +229 -0
  208. package/src/helper-scripts.ts +69 -0
  209. package/src/installed-dependencies.ts +74 -0
  210. package/src/logs.ts +67 -0
  211. package/src/managed-process-scope.ts +481 -0
  212. package/src/mcp-config.ts +262 -0
  213. package/src/node-process-environment.ts +10 -0
  214. package/src/platform-auth.ts +594 -0
  215. package/src/platform-game-analytics.ts +50 -0
  216. package/src/platform-game-app-id.ts +99 -0
  217. package/src/platform-game-media.ts +209 -0
  218. package/src/platform-games.ts +217 -0
  219. package/src/policy-artifact-contract.ts +52 -0
  220. package/src/policy-artifacts.ts +134 -0
  221. package/src/process-scope-admission.ts +50 -0
  222. package/src/process-scope-protocol.ts +66 -0
  223. package/src/process-scope.ts +327 -0
  224. package/src/quality.ts +82 -0
  225. package/src/release.ts +1683 -0
  226. package/src/rooms-check-fleet.ts +194 -0
  227. package/src/rooms-check-link.ts +138 -0
  228. package/src/rooms-check-protocol.ts +244 -0
  229. package/src/rooms-check.ts +797 -0
  230. package/src/runtime-owner-protocol.ts +218 -0
  231. package/src/source-tree-contract.ts +70 -0
  232. package/src/source-tree.ts +84 -0
  233. package/src/test-profile-process.ts +153 -0
  234. package/src/test-profile-protocol.ts +116 -0
  235. package/src/testing.ts +430 -0
  236. package/src/tooling/declaration-hook.ts +52 -0
  237. package/src/tooling/describe-game.ts +49 -0
  238. package/src/tooling/game-session-broker.ts +7 -0
  239. package/src/tooling/hold-runtime-host.ts +441 -0
  240. package/src/tooling/list-visual-scenarios.ts +21 -0
  241. package/src/tooling/load-game.ts +79 -0
  242. package/src/tooling/managed-dev-supervisor.ts +71 -0
  243. package/src/tooling/process-scope-bootstrap.mjs +24 -0
  244. package/src/tooling/process-scope-guard.ts +213 -0
  245. package/src/tooling/process-scope-windows.ps1 +148 -0
  246. package/src/tooling/rooms-check-device.ts +493 -0
  247. package/src/tooling/run-headless-room.ts +326 -0
  248. package/src/tooling/run-test-profile.ts +190 -0
  249. package/src/tooling/run-visual-capture.ts +231 -0
  250. package/src/tooling/runtime-owner-actions.ts +65 -0
  251. package/src/tooling/seal-game-build.ts +118 -0
  252. package/src/tooling/visual-pack.ts +11 -0
  253. package/src/types.ts +928 -0
  254. package/src/visual.ts +296 -0
  255. package/src/windows-process-scopes.ts +189 -0
  256. package/src/workspace-contract.ts +32 -0
@@ -0,0 +1,400 @@
1
+ import {
2
+ fixedControllerOrientation,
3
+ type AirJamGameInputModality,
4
+ } from "@air-jam/sdk/metadata";
5
+ import {
6
+ AIR_JAM_RUNTIME_INSPECTION_KEY,
7
+ readRuntimeInspectionContract,
8
+ } from "@air-jam/sdk/runtime-inspection";
9
+ import {
10
+ AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX,
11
+ resolveRuntimeTopology,
12
+ type ResolvedAirJamRuntimeTopology,
13
+ } from "@air-jam/sdk/runtime-topology";
14
+ import {
15
+ type Browser,
16
+ type BrowserContext,
17
+ type Frame,
18
+ type FrameLocator,
19
+ type Page,
20
+ } from "playwright-core";
21
+ import { installHarnessRuntimeTopology } from "./browser.js";
22
+ import type {
23
+ VisualHarnessMode,
24
+ VisualHarnessPageSurface,
25
+ VisualHarnessUrls,
26
+ VisualQuerySurface,
27
+ VisualViewport,
28
+ } from "./types.js";
29
+
30
+ export const DEFAULT_HOST_VIEWPORT: VisualViewport = {
31
+ width: 1440,
32
+ height: 1024,
33
+ };
34
+
35
+ export const DEFAULT_CONTROLLER_VIEWPORT: VisualViewport = {
36
+ width: 390,
37
+ height: 844,
38
+ };
39
+
40
+ const isEmbeddedMode = (mode: VisualHarnessMode): boolean =>
41
+ mode !== "standalone-dev";
42
+
43
+ export const dismissHarnessControllerFullscreenPrompt = async (
44
+ page: Page,
45
+ ): Promise<boolean> => {
46
+ const openPrompt = page.locator(
47
+ '[data-testid="controller-fullscreen-prompt"][data-state="open"]',
48
+ );
49
+ await openPrompt
50
+ .waitFor({ state: "visible", timeout: 5_000 })
51
+ .catch(() => null);
52
+
53
+ if (!(await openPrompt.isVisible().catch(() => false))) {
54
+ return false;
55
+ }
56
+
57
+ await page
58
+ .getByTestId("controller-fullscreen-prompt-dismiss")
59
+ .click({ force: true });
60
+ await openPrompt.waitFor({ state: "hidden", timeout: 10_000 });
61
+ return true;
62
+ };
63
+
64
+ const waitForFrameToLoad = async ({
65
+ page,
66
+ testId,
67
+ timeoutMs = 30_000,
68
+ }: {
69
+ page: Page;
70
+ testId: string;
71
+ timeoutMs?: number;
72
+ }): Promise<FrameLocator> => {
73
+ const iframe = page.getByTestId(testId);
74
+ await iframe.waitFor({ state: "visible", timeout: timeoutMs });
75
+ const iframeHandle = await iframe.elementHandle({ timeout: timeoutMs });
76
+ if (!iframeHandle) {
77
+ throw new Error(`Could not resolve iframe handle for "${testId}".`);
78
+ }
79
+
80
+ const startedAt = Date.now();
81
+ let resolvedFrame: Frame | null = null;
82
+
83
+ while (Date.now() - startedAt < timeoutMs) {
84
+ const nextFrame = await iframeHandle.contentFrame();
85
+ const frameUrl = nextFrame?.url() ?? "";
86
+ if (nextFrame && frameUrl.length > 0 && frameUrl !== "about:blank") {
87
+ resolvedFrame = nextFrame;
88
+ break;
89
+ }
90
+ await page.waitForTimeout(100);
91
+ }
92
+
93
+ if (!resolvedFrame) {
94
+ throw new Error(`Timed out waiting for iframe "${testId}" to resolve.`);
95
+ }
96
+
97
+ await resolvedFrame.waitForLoadState("domcontentloaded", {
98
+ timeout: Math.max(1, timeoutMs - (Date.now() - startedAt)),
99
+ });
100
+ return page.frameLocator(`iframe[data-testid="${testId}"]`);
101
+ };
102
+
103
+ const readRuntimeHref = async ({
104
+ page,
105
+ game,
106
+ embedded,
107
+ }: {
108
+ page: Page;
109
+ game: VisualQuerySurface;
110
+ embedded: boolean;
111
+ }): Promise<string> =>
112
+ embedded
113
+ ? game.locator("body").evaluate(() => window.location.href)
114
+ : page.evaluate(() => window.location.href);
115
+
116
+ const readHostRuntimeInspection = async ({
117
+ page,
118
+ game,
119
+ embedded,
120
+ }: {
121
+ page: Page;
122
+ game: VisualQuerySurface;
123
+ embedded: boolean;
124
+ }) => {
125
+ const rawInspection = embedded
126
+ ? await game
127
+ .locator("body")
128
+ .evaluate(
129
+ (_, key) =>
130
+ (window as unknown as Record<string, unknown>)[key] ?? null,
131
+ AIR_JAM_RUNTIME_INSPECTION_KEY,
132
+ )
133
+ : await page.evaluate(
134
+ (key) => (window as unknown as Record<string, unknown>)[key] ?? null,
135
+ AIR_JAM_RUNTIME_INSPECTION_KEY,
136
+ );
137
+
138
+ const inspection = readRuntimeInspectionContract({
139
+ [AIR_JAM_RUNTIME_INSPECTION_KEY]: rawInspection,
140
+ });
141
+ return inspection?.role === "host" ? inspection : null;
142
+ };
143
+
144
+ export function bindHarnessControllerUrl(
145
+ resolvedJoinUrl: string,
146
+ controllerBaseUrl: string,
147
+ ) {
148
+ const joinUrl = new URL(resolvedJoinUrl);
149
+ const controllerUrl = new URL(controllerBaseUrl);
150
+ joinUrl.protocol = controllerUrl.protocol;
151
+ joinUrl.host = controllerUrl.host;
152
+ for (const [key, value] of controllerUrl.searchParams)
153
+ if (key.startsWith(AIR_JAM_RUNTIME_TOPOLOGY_QUERY_PARAM_PREFIX))
154
+ joinUrl.searchParams.set(key, value);
155
+ return joinUrl.toString();
156
+ }
157
+
158
+ const resolveControllerJoinUrl = async ({
159
+ hostPage,
160
+ hostGame,
161
+ hostEmbedded,
162
+ controllerBaseUrl,
163
+ }: {
164
+ hostPage: Page;
165
+ hostGame: VisualQuerySurface;
166
+ hostEmbedded: boolean;
167
+ controllerBaseUrl: string;
168
+ }): Promise<string> => {
169
+ let resolvedJoinUrl: string | null = null;
170
+
171
+ for (let attempt = 0; attempt < 80; attempt += 1) {
172
+ const inspection = await readHostRuntimeInspection({
173
+ page: hostPage,
174
+ game: hostGame,
175
+ embedded: hostEmbedded,
176
+ });
177
+ if (inspection?.joinUrlStatus === "ready" && inspection.joinUrl) {
178
+ resolvedJoinUrl = inspection.joinUrl;
179
+ }
180
+
181
+ if (!resolvedJoinUrl) {
182
+ const runtimeUrl = new URL(
183
+ await readRuntimeHref({
184
+ page: hostPage,
185
+ game: hostGame,
186
+ embedded: hostEmbedded,
187
+ }),
188
+ );
189
+ resolvedJoinUrl = runtimeUrl.searchParams.get("aj_join_url");
190
+ }
191
+
192
+ if (resolvedJoinUrl) {
193
+ break;
194
+ }
195
+ await hostPage.waitForTimeout(250);
196
+ }
197
+
198
+ if (!resolvedJoinUrl) {
199
+ throw new Error(
200
+ "Could not resolve a controller join URL from the host runtime inspection contract or runtime URL.",
201
+ );
202
+ }
203
+
204
+ return bindHarnessControllerUrl(resolvedJoinUrl, controllerBaseUrl);
205
+ };
206
+
207
+ export type OpenVisualHarnessSessionOptions = {
208
+ browser: Browser;
209
+ inputModalities?: readonly AirJamGameInputModality[];
210
+ runtimeTopology?: ResolvedAirJamRuntimeTopology;
211
+ onDiagnostic?: (message: string) => void;
212
+ urls: Omit<VisualHarnessUrls, "controllerJoinUrl">;
213
+ mode: VisualHarnessMode;
214
+ };
215
+
216
+ export type OpenVisualHarnessHostSessionResult = {
217
+ urls: Omit<VisualHarnessUrls, "controllerJoinUrl"> & {
218
+ controllerJoinUrl: null;
219
+ };
220
+ host: VisualHarnessPageSurface;
221
+ close: () => Promise<void>;
222
+ };
223
+
224
+ export type OpenVisualHarnessControllerSessionResult = {
225
+ urls: VisualHarnessUrls;
226
+ controller: VisualHarnessPageSurface & {
227
+ fullscreenPromptDismissed: boolean;
228
+ };
229
+ close: () => Promise<void>;
230
+ };
231
+
232
+ export type OpenVisualHarnessSessionResult = {
233
+ urls: VisualHarnessUrls;
234
+ host: VisualHarnessPageSurface;
235
+ controller: VisualHarnessPageSurface & {
236
+ fullscreenPromptDismissed: boolean;
237
+ };
238
+ close: () => Promise<void>;
239
+ };
240
+
241
+ export const openVisualHarnessHostSession = async ({
242
+ browser,
243
+ runtimeTopology,
244
+ onDiagnostic,
245
+ urls,
246
+ mode,
247
+ }: OpenVisualHarnessSessionOptions): Promise<OpenVisualHarnessHostSessionResult> => {
248
+ const embedded = isEmbeddedMode(mode);
249
+ const hostContext: BrowserContext = await browser.newContext({
250
+ viewport: DEFAULT_HOST_VIEWPORT,
251
+ });
252
+
253
+ try {
254
+ if (runtimeTopology)
255
+ await installHarnessRuntimeTopology(hostContext, runtimeTopology);
256
+ const hostPage = await hostContext.newPage();
257
+ if (onDiagnostic) {
258
+ hostPage.on("pageerror", (error) =>
259
+ onDiagnostic(`Page error: ${error.message}`),
260
+ );
261
+ hostPage.on("console", (message) => {
262
+ if (message.type() === "error")
263
+ onDiagnostic(`Browser error: ${message.text()}`);
264
+ });
265
+ hostPage.on("requestfailed", (request) => {
266
+ const url = new URL(request.url());
267
+ onDiagnostic(
268
+ `Request failed: ${url.origin}${url.pathname}: ${request.failure()?.errorText}`,
269
+ );
270
+ });
271
+ }
272
+ await hostPage.goto(urls.hostUrl, { waitUntil: "domcontentloaded" });
273
+ const hostGame: VisualQuerySurface = embedded
274
+ ? await waitForFrameToLoad({
275
+ page: hostPage,
276
+ testId: "arcade-host-game-frame",
277
+ })
278
+ : hostPage;
279
+
280
+ return {
281
+ urls: { ...urls, controllerJoinUrl: null },
282
+ host: {
283
+ page: hostPage,
284
+ game: hostGame,
285
+ embedded,
286
+ },
287
+ close: () => hostContext.close(),
288
+ };
289
+ } catch (error) {
290
+ await hostContext.close().catch(() => null);
291
+ throw error;
292
+ }
293
+ };
294
+
295
+ export const openVisualHarnessControllerSession = async ({
296
+ browser,
297
+ inputModalities,
298
+ runtimeTopology,
299
+ urls,
300
+ host,
301
+ }: Omit<OpenVisualHarnessSessionOptions, "mode"> & {
302
+ host: VisualHarnessPageSurface;
303
+ }): Promise<OpenVisualHarnessControllerSessionResult> => {
304
+ const controllerContext = await browser.newContext({
305
+ viewport:
306
+ fixedControllerOrientation(inputModalities ?? []) === "landscape"
307
+ ? {
308
+ width: DEFAULT_CONTROLLER_VIEWPORT.height,
309
+ height: DEFAULT_CONTROLLER_VIEWPORT.width,
310
+ }
311
+ : DEFAULT_CONTROLLER_VIEWPORT,
312
+ });
313
+
314
+ try {
315
+ if (runtimeTopology)
316
+ await installHarnessRuntimeTopology(
317
+ controllerContext,
318
+ resolveRuntimeTopology({
319
+ ...runtimeTopology,
320
+ surfaceRole: "controller",
321
+ }),
322
+ );
323
+ const controllerJoinUrl = await resolveControllerJoinUrl({
324
+ hostPage: host.page,
325
+ hostGame: host.game,
326
+ hostEmbedded: host.embedded,
327
+ controllerBaseUrl: urls.controllerBaseUrl,
328
+ });
329
+ const controllerPage = await controllerContext.newPage();
330
+ await controllerPage.goto(controllerJoinUrl, {
331
+ waitUntil: "domcontentloaded",
332
+ });
333
+ const fullscreenPromptDismissed =
334
+ await dismissHarnessControllerFullscreenPrompt(controllerPage);
335
+ const controllerGame: VisualQuerySurface = host.embedded
336
+ ? await waitForFrameToLoad({
337
+ page: controllerPage,
338
+ testId: "arcade-controller-game-frame",
339
+ })
340
+ : controllerPage;
341
+
342
+ return {
343
+ urls: { ...urls, controllerJoinUrl },
344
+ controller: {
345
+ page: controllerPage,
346
+ game: controllerGame,
347
+ embedded: host.embedded,
348
+ fullscreenPromptDismissed,
349
+ },
350
+ close: () => controllerContext.close(),
351
+ };
352
+ } catch (error) {
353
+ await controllerContext.close().catch(() => null);
354
+ throw error;
355
+ }
356
+ };
357
+
358
+ export const openVisualHarnessSession = async ({
359
+ browser,
360
+ inputModalities,
361
+ runtimeTopology,
362
+ onDiagnostic,
363
+ urls,
364
+ mode,
365
+ }: OpenVisualHarnessSessionOptions): Promise<OpenVisualHarnessSessionResult> => {
366
+ const hostSession = await openVisualHarnessHostSession({
367
+ browser,
368
+ runtimeTopology,
369
+ onDiagnostic,
370
+ urls,
371
+ mode,
372
+ });
373
+
374
+ try {
375
+ const controllerSession = await openVisualHarnessControllerSession({
376
+ browser,
377
+ inputModalities,
378
+ runtimeTopology,
379
+ urls,
380
+ host: hostSession.host,
381
+ });
382
+
383
+ return {
384
+ urls: controllerSession.urls,
385
+ host: hostSession.host,
386
+ controller: controllerSession.controller,
387
+ close: async () => {
388
+ await Promise.allSettled([
389
+ hostSession.close(),
390
+ controllerSession.close(),
391
+ ]);
392
+ },
393
+ };
394
+ } catch (error) {
395
+ await hostSession.close().catch(() => null);
396
+ throw error;
397
+ }
398
+ };
399
+
400
+ export { launchHarnessBrowser } from "./browser.js";
@@ -0,0 +1,184 @@
1
+ import type {
2
+ AirJamAgentContract,
3
+ AnyAirJamAgentContract,
4
+ } from "@air-jam/sdk/core";
5
+ import type { AirJamGameInputModality } from "@air-jam/sdk/metadata";
6
+ import type { Page } from "playwright-core";
7
+
8
+ export type { AnyAirJamAgentContract } from "@air-jam/sdk/core";
9
+
10
+ export type VisualHarnessMode = "standalone-dev" | "arcade-built";
11
+
12
+ export type VisualViewport = {
13
+ width: number;
14
+ height: number;
15
+ };
16
+
17
+ export type VisualScreenshotRecord = {
18
+ surface: "host" | "controller";
19
+ viewportName: string;
20
+ width: number;
21
+ height: number;
22
+ fileName: string;
23
+ filePath: string;
24
+ };
25
+
26
+ export type VisualHarnessUrls = {
27
+ appOrigin: string;
28
+ hostUrl: string;
29
+ controllerBaseUrl: string;
30
+ publicHost: string;
31
+ localBuildUrl: string | null;
32
+ browserBuildUrl: string | null;
33
+ controllerJoinUrl: string;
34
+ };
35
+
36
+ export type VisualQuerySurface = {
37
+ getByLabel: Page["getByLabel"];
38
+ getByRole: Page["getByRole"];
39
+ getByTestId: Page["getByTestId"];
40
+ getByText: Page["getByText"];
41
+ locator: Page["locator"];
42
+ };
43
+
44
+ export type VisualHarnessPageSurface = {
45
+ page: Page;
46
+ game: VisualQuerySurface;
47
+ embedded: boolean;
48
+ };
49
+
50
+ export type InferVisualScenarioSnapshot<TAgent> =
51
+ TAgent extends AirJamAgentContract<infer TSnapshot, infer _TStores>
52
+ ? TSnapshot
53
+ : never;
54
+
55
+ export type VisualScenarioAgentActionDescriptor = {
56
+ actionId: string;
57
+ lane: "player" | "host";
58
+ source: "semantic-game";
59
+ description: string | null;
60
+ availability: string | null;
61
+ payload: {
62
+ kind: "none" | "boolean" | "number" | "string" | "enum" | "json";
63
+ description: string | null;
64
+ allowedValues?: string[];
65
+ };
66
+ resultDescription: string | null;
67
+ };
68
+
69
+ export type VisualScenarioAgentInvocation<TSnapshot = Record<string, unknown>> =
70
+ {
71
+ actionId: string;
72
+ lane: "player" | "host";
73
+ outcome: string | null;
74
+ acknowledgementObservation: string | null;
75
+ snapshotBefore: TSnapshot | null;
76
+ snapshotAfter: TSnapshot | null;
77
+ snapshotAfterStatus:
78
+ | import("../../types.js").InvokeGameActionResult["snapshotAfterStatus"]
79
+ | null;
80
+ };
81
+
82
+ export type VisualScenarioAgent<TSnapshot = Record<string, unknown>> = {
83
+ listActions: () => Promise<readonly VisualScenarioAgentActionDescriptor[]>;
84
+ read: () => Promise<TSnapshot>;
85
+ waitFor: (
86
+ predicate: (snapshot: TSnapshot) => boolean | Promise<boolean>,
87
+ description?: string,
88
+ timeout?: number,
89
+ ) => Promise<TSnapshot>;
90
+ invoke: (
91
+ actionId: string,
92
+ payload?: unknown,
93
+ options?: {
94
+ timeoutMs?: number;
95
+ },
96
+ ) => Promise<VisualScenarioAgentInvocation<TSnapshot>>;
97
+ close: () => Promise<void>;
98
+ };
99
+
100
+ export type VisualScenarioContext<
101
+ TAgent extends AnyAirJamAgentContract = AnyAirJamAgentContract,
102
+ > = {
103
+ gameId: string;
104
+ scenario: VisualScenario<TAgent>;
105
+ scenarioDir: string;
106
+ inputModalities?: readonly AirJamGameInputModality[];
107
+ urls: VisualHarnessUrls;
108
+ host: VisualHarnessPageSurface;
109
+ controller: VisualHarnessPageSurface & {
110
+ fullscreenPromptDismissed: boolean;
111
+ };
112
+ note: (value: string) => void;
113
+ sleep: (ms: number) => Promise<void>;
114
+ ensureControllerInteractive: () => Promise<void>;
115
+ agent: VisualScenarioAgent<InferVisualScenarioSnapshot<TAgent>>;
116
+ captureHost: (
117
+ viewportName: string,
118
+ viewport: VisualViewport,
119
+ ) => Promise<void>;
120
+ captureController: (
121
+ viewportName: string,
122
+ viewport: VisualViewport,
123
+ ) => Promise<void>;
124
+ screenshotRecords: VisualScreenshotRecord[];
125
+ notes: string[];
126
+ close: () => Promise<void>;
127
+ };
128
+
129
+ export type VisualScenario<
130
+ TAgent extends AnyAirJamAgentContract = AnyAirJamAgentContract,
131
+ > = {
132
+ id: string;
133
+ description?: string;
134
+ run: (context: VisualScenarioContext<TAgent>) => Promise<void>;
135
+ };
136
+
137
+ export type VisualScenarioPack<
138
+ TAgent extends AnyAirJamAgentContract = AnyAirJamAgentContract,
139
+ > = {
140
+ scenarios: ReadonlyArray<VisualScenario<TAgent>>;
141
+ };
142
+
143
+ export type VisualCaptureScenarioMetadata = {
144
+ gameId: string;
145
+ scenarioId: string;
146
+ scenarioDescription: string | null;
147
+ runtimeMode: VisualHarnessMode;
148
+ capturedAt: string;
149
+ status: "captured" | "failed";
150
+ urls: Omit<VisualHarnessUrls, "controllerJoinUrl"> | VisualHarnessUrls;
151
+ screenshots: Array<{
152
+ surface: "host" | "controller";
153
+ viewportName: string;
154
+ width: number;
155
+ height: number;
156
+ fileName: string;
157
+ relativePath: string;
158
+ }>;
159
+ notes: string[];
160
+ error: {
161
+ message: string;
162
+ stack: string | null;
163
+ } | null;
164
+ };
165
+
166
+ export type VisualCaptureSummary = {
167
+ gameId: string;
168
+ mode: VisualHarnessMode;
169
+ secure: boolean;
170
+ capturedAt: string;
171
+ scenarios: Array<{
172
+ scenarioId: string;
173
+ status: "captured" | "failed";
174
+ screenshotCount: number;
175
+ relativeDir: string;
176
+ }>;
177
+ };
178
+
179
+ export type RunVisualCaptureCommandOptions = {
180
+ gameId: string;
181
+ scenarioId?: string | null;
182
+ mode?: VisualHarnessMode;
183
+ secure?: boolean;
184
+ };
@@ -0,0 +1,7 @@
1
+ export * from "./visual/prefab-contract.js";
2
+ export * from "./visual/prefab-runner.js";
3
+ export * from "./visual/runner.js";
4
+ export * from "./visual/scenario-contract.js";
5
+ export * from "./visual/scenario-helpers.js";
6
+ export * from "./visual/session.js";
7
+ export * from "./visual/types.js";
@@ -0,0 +1,112 @@
1
+ import { airJamSettingsValuesSchema } from "@air-jam/sdk/core";
2
+ import {
3
+ hostAgentRequestSchema,
4
+ hostAgentResponseSchema,
5
+ } from "@air-jam/sdk/runtime-control";
6
+ import { z } from "zod";
7
+
8
+ export const HEADLESS_ROOM_IPC_MAX_BYTES = 1_000_000;
9
+ /** The longest stretch of game time one request may advance. */
10
+ export const HEADLESS_ROOM_MAX_ADVANCE_MS = 60_000;
11
+
12
+ export const headlessRoomRequestSchema = z.discriminatedUnion("kind", [
13
+ z
14
+ .object({
15
+ kind: z.literal("initialize"),
16
+ id: z.uuid(),
17
+ configPath: z.string().min(1),
18
+ settings: airJamSettingsValuesSchema.optional(),
19
+ seed: z.number().int().min(0).max(0xffff_ffff),
20
+ })
21
+ .strict(),
22
+ z
23
+ .object({
24
+ kind: z.literal("agent"),
25
+ id: z.uuid(),
26
+ request: hostAgentRequestSchema,
27
+ })
28
+ .strict(),
29
+ z
30
+ .object({
31
+ kind: z.literal("advance"),
32
+ id: z.uuid(),
33
+ ms: z.number().positive().max(HEADLESS_ROOM_MAX_ADVANCE_MS),
34
+ })
35
+ .strict(),
36
+ z
37
+ .object({
38
+ kind: z.literal("saveInputLog"),
39
+ id: z.uuid(),
40
+ /** Where the room writes its input log. */
41
+ path: z.string().min(1),
42
+ })
43
+ .strict(),
44
+ z
45
+ .object({
46
+ kind: z.literal("replay"),
47
+ id: z.uuid(),
48
+ configPath: z.string().min(1),
49
+ /** An input log this game recorded; the room plays it with no server. */
50
+ logPath: z.string().min(1),
51
+ })
52
+ .strict(),
53
+ ]);
54
+ export type HeadlessRoomRequest = z.infer<typeof headlessRoomRequestSchema>;
55
+
56
+ export const headlessRoomResponseSchema = z.discriminatedUnion("kind", [
57
+ z.object({ kind: z.literal("ready") }).strict(),
58
+ z
59
+ .object({
60
+ kind: z.literal("initialized"),
61
+ id: z.uuid(),
62
+ gameId: z.string().nullable(),
63
+ roomId: z.string().min(1),
64
+ controllerJoinUrl: z.url(),
65
+ nowMs: z.number().nonnegative(),
66
+ /** Whether the room keeps an input log: its game declares a simulation. */
67
+ recordsInputLog: z.boolean(),
68
+ })
69
+ .strict(),
70
+ z
71
+ .object({
72
+ kind: z.literal("agent"),
73
+ id: z.uuid(),
74
+ response: hostAgentResponseSchema,
75
+ })
76
+ .strict(),
77
+ z
78
+ .object({
79
+ kind: z.literal("advanced"),
80
+ id: z.uuid(),
81
+ nowMs: z.number().nonnegative(),
82
+ })
83
+ .strict(),
84
+ z
85
+ .object({
86
+ kind: z.literal("savedInputLog"),
87
+ id: z.uuid(),
88
+ sha256: z.string().regex(/^[a-f0-9]{64}$/),
89
+ ticks: z.number().int().nonnegative(),
90
+ stepMs: z.number().positive(),
91
+ entries: z.number().int().nonnegative(),
92
+ full: z.boolean(),
93
+ })
94
+ .strict(),
95
+ z
96
+ .object({
97
+ kind: z.literal("replayed"),
98
+ id: z.uuid(),
99
+ gameId: z.string().nullable(),
100
+ roomId: z.string().min(1),
101
+ ticks: z.number().int().nonnegative(),
102
+ })
103
+ .strict(),
104
+ z
105
+ .object({
106
+ kind: z.literal("error"),
107
+ id: z.uuid(),
108
+ message: z.string().max(2000),
109
+ })
110
+ .strict(),
111
+ ]);
112
+ export type HeadlessRoomResponse = z.infer<typeof headlessRoomResponseSchema>;