@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
@@ -0,0 +1,224 @@
1
+ import {
2
+ AIR_JAM_RUNTIME_INSPECTION_KEY,
3
+ readRuntimeInspectionContract,
4
+ } from "@air-jam/sdk/runtime-inspection";
5
+ import { mkdir } from "node:fs/promises";
6
+ import path from "node:path";
7
+ import {
8
+ DEFAULT_CONTROLLER_VIEWPORT,
9
+ DEFAULT_HOST_VIEWPORT,
10
+ launchHarnessBrowser,
11
+ openVisualHarnessControllerSession,
12
+ openVisualHarnessHostSession,
13
+ type OpenVisualHarnessControllerSessionResult,
14
+ type VisualHarnessMode,
15
+ } from "../harness/visual.js";
16
+ import {
17
+ AIR_JAM_RUNTIME_OWNER_ACTION_RESULT,
18
+ AIR_JAM_RUNTIME_OWNER_CAPTURE_RESULT,
19
+ isRuntimeOwnerActionRequest,
20
+ isRuntimeOwnerCaptureRequest,
21
+ resolveProjectRelativeRuntimeCaptureDir,
22
+ type AirJamRuntimeOwnerCaptureResult,
23
+ } from "../runtime-owner-protocol.js";
24
+ import { invokeOwnedHostAction } from "./runtime-owner-actions.js";
25
+
26
+ const getFlagValue = (flag: string): string | null => {
27
+ const inline = process.argv.find((value) => value.startsWith(`${flag}=`));
28
+ if (inline) {
29
+ return inline.slice(flag.length + 1);
30
+ }
31
+
32
+ const index = process.argv.indexOf(flag);
33
+ return index === -1 ? null : (process.argv[index + 1] ?? null);
34
+ };
35
+
36
+ const appOrigin = getFlagValue("--app-origin");
37
+ const hostUrl = getFlagValue("--host-url");
38
+ const controllerBaseUrl = getFlagValue("--controller-base-url");
39
+ const publicHost = getFlagValue("--public-host");
40
+ const localBuildUrl = getFlagValue("--local-build-url");
41
+ const browserBuildUrl = getFlagValue("--browser-build-url");
42
+ const requestedMode = getFlagValue("--mode") ?? "standalone-dev";
43
+ const timeoutMs = Number(getFlagValue("--timeout-ms") ?? "15000");
44
+
45
+ if (!appOrigin || !hostUrl || !controllerBaseUrl || !publicHost) {
46
+ throw new Error(
47
+ "Missing required isolated runtime host inputs. Expected resolved topology URLs.",
48
+ );
49
+ }
50
+
51
+ const browser = await launchHarnessBrowser();
52
+ const session = await openVisualHarnessHostSession({
53
+ browser,
54
+ mode: requestedMode as VisualHarnessMode,
55
+ urls: {
56
+ appOrigin,
57
+ hostUrl,
58
+ controllerBaseUrl,
59
+ publicHost,
60
+ localBuildUrl,
61
+ browserBuildUrl,
62
+ },
63
+ });
64
+ let controllerSession: OpenVisualHarnessControllerSessionResult | null = null;
65
+
66
+ const shutdown = async (exitCode = 0) => {
67
+ await Promise.allSettled([
68
+ controllerSession?.close(),
69
+ session.close(),
70
+ browser.close(),
71
+ ]);
72
+ process.exit(exitCode);
73
+ };
74
+
75
+ process.on("message", (message: unknown) => {
76
+ if (isRuntimeOwnerActionRequest(message)) {
77
+ void (async () => {
78
+ const acknowledgement = await invokeOwnedHostAction(
79
+ session.host,
80
+ message.action,
81
+ );
82
+ process.send?.({
83
+ type: AIR_JAM_RUNTIME_OWNER_ACTION_RESULT,
84
+ requestId: message.requestId,
85
+ acknowledgement,
86
+ });
87
+ })();
88
+ return;
89
+ }
90
+ if (!isRuntimeOwnerCaptureRequest(message)) return;
91
+ void (async () => {
92
+ const capturedAt = new Date().toISOString();
93
+ const response: AirJamRuntimeOwnerCaptureResult = {
94
+ type: AIR_JAM_RUNTIME_OWNER_CAPTURE_RESULT,
95
+ requestId: message.requestId,
96
+ ok: false,
97
+ capturedAt,
98
+ screenshots: [],
99
+ error: null,
100
+ };
101
+ try {
102
+ const captureDir = resolveProjectRelativeRuntimeCaptureDir({
103
+ projectDir: process.cwd(),
104
+ relativeDir: message.relativeDir,
105
+ });
106
+ controllerSession ??= await openVisualHarnessControllerSession({
107
+ browser,
108
+ urls: {
109
+ appOrigin,
110
+ hostUrl,
111
+ controllerBaseUrl,
112
+ publicHost,
113
+ localBuildUrl,
114
+ browserBuildUrl,
115
+ },
116
+ host: session.host,
117
+ });
118
+ await mkdir(captureDir, { recursive: true });
119
+ const captures = [
120
+ {
121
+ surface: "host" as const,
122
+ fileName: "host-desktop.png",
123
+ viewport: DEFAULT_HOST_VIEWPORT,
124
+ page: session.host.page,
125
+ },
126
+ {
127
+ surface: "controller" as const,
128
+ fileName: "controller-phone.png",
129
+ viewport: DEFAULT_CONTROLLER_VIEWPORT,
130
+ page: controllerSession.controller.page,
131
+ },
132
+ ];
133
+ for (const capture of captures) {
134
+ await capture.page.waitForTimeout(300);
135
+ const filePath = path.join(captureDir, capture.fileName);
136
+ await capture.page.screenshot({ path: filePath });
137
+ response.screenshots.push({
138
+ surface: capture.surface,
139
+ width: capture.viewport.width,
140
+ height: capture.viewport.height,
141
+ relativePath: path.relative(process.cwd(), filePath),
142
+ });
143
+ }
144
+ response.ok = true;
145
+ } catch (error) {
146
+ response.error = error instanceof Error ? error.message : String(error);
147
+ }
148
+ process.send?.(response);
149
+ })();
150
+ });
151
+
152
+ process.on("SIGTERM", () => {
153
+ void shutdown(0);
154
+ });
155
+
156
+ process.on("SIGINT", () => {
157
+ void shutdown(0);
158
+ });
159
+
160
+ process.once("disconnect", () => {
161
+ void shutdown(0);
162
+ });
163
+
164
+ const readInspection = async () => {
165
+ const rawValue = session.host.embedded
166
+ ? await session.host.game
167
+ .locator("body")
168
+ .evaluate(
169
+ (_, key) =>
170
+ (window as unknown as Record<string, unknown>)[key] ?? null,
171
+ AIR_JAM_RUNTIME_INSPECTION_KEY,
172
+ )
173
+ : await session.host.page.evaluate(
174
+ (key) => (window as unknown as Record<string, unknown>)[key] ?? null,
175
+ AIR_JAM_RUNTIME_INSPECTION_KEY,
176
+ );
177
+
178
+ return readRuntimeInspectionContract({
179
+ [AIR_JAM_RUNTIME_INSPECTION_KEY]: rawValue,
180
+ });
181
+ };
182
+
183
+ try {
184
+ const startedAt = Date.now();
185
+ let inspection = null;
186
+
187
+ while (Date.now() - startedAt < timeoutMs) {
188
+ const nextInspection = await readInspection();
189
+ if (
190
+ nextInspection?.role === "host" &&
191
+ nextInspection.joinUrlStatus === "ready"
192
+ ) {
193
+ inspection = nextInspection;
194
+ break;
195
+ }
196
+
197
+ await session.host.page.waitForTimeout(250);
198
+ }
199
+
200
+ if (!inspection || inspection.role !== "host") {
201
+ throw new Error(
202
+ "Timed out waiting for a published host runtime inspection contract.",
203
+ );
204
+ }
205
+
206
+ process.stdout.write(
207
+ `${JSON.stringify(
208
+ {
209
+ roomId: inspection.roomId,
210
+ controllerJoinUrl: inspection.joinUrl,
211
+ inspection,
212
+ },
213
+ null,
214
+ 2,
215
+ )}\n`,
216
+ );
217
+
218
+ await new Promise(() => {
219
+ // Keep the hidden host runtime alive until the parent process disconnects it.
220
+ });
221
+ } catch (error) {
222
+ console.error(error instanceof Error ? error.message : String(error));
223
+ await shutdown(1);
224
+ }
@@ -0,0 +1,20 @@
1
+ import { inspectAirJamAgentDeclaration } from "./agent-declaration.js";
2
+
3
+ const getFlagValue = (flag: string): string | null => {
4
+ const inline = process.argv.find((value) => value.startsWith(`${flag}=`));
5
+ if (inline) {
6
+ return inline.slice(flag.length + 1);
7
+ }
8
+
9
+ const index = process.argv.indexOf(flag);
10
+ return index === -1 ? null : (process.argv[index + 1] ?? null);
11
+ };
12
+
13
+ const configPath = getFlagValue("--config");
14
+
15
+ if (!configPath) {
16
+ throw new Error("Missing required --config input for Air Jam agent helper.");
17
+ }
18
+
19
+ const inspection = await inspectAirJamAgentDeclaration(configPath);
20
+ process.stdout.write(`${JSON.stringify(inspection, null, 2)}\n`);
@@ -0,0 +1,64 @@
1
+ import {
2
+ loadAirJamAppConfig,
3
+ resolveAirJamConfigGameId,
4
+ resolveVisualScenarioModulePathFromConfig,
5
+ } from "./airjam-agent.js";
6
+ import { loadVisualScenarioPackFromModuleOrConfig } from "./visual-pack.js";
7
+
8
+ const getFlagValue = (flag: string): string | null => {
9
+ const inline = process.argv.find((value) => value.startsWith(`${flag}=`));
10
+ if (inline) {
11
+ return inline.slice(flag.length + 1);
12
+ }
13
+
14
+ const index = process.argv.indexOf(flag);
15
+ return index === -1 ? null : (process.argv[index + 1] ?? null);
16
+ };
17
+
18
+ const modulePath = getFlagValue("--module-path");
19
+ const configPath = getFlagValue("--config");
20
+ if (!modulePath && !configPath) {
21
+ throw new Error("Missing required --config or --module-path.");
22
+ }
23
+
24
+ if (configPath) {
25
+ if (!(await resolveVisualScenarioModulePathFromConfig(configPath))) {
26
+ process.stdout.write(
27
+ `${JSON.stringify(
28
+ {
29
+ hasVisualScenarios: false,
30
+ },
31
+ null,
32
+ 2,
33
+ )}\n`,
34
+ );
35
+ process.exit(0);
36
+ }
37
+ }
38
+
39
+ const scenarioPack = await loadVisualScenarioPackFromModuleOrConfig({
40
+ modulePath,
41
+ configPath,
42
+ });
43
+ const effectiveGameId =
44
+ (configPath
45
+ ? resolveAirJamConfigGameId(await loadAirJamAppConfig(configPath))
46
+ : null) ?? "unknown-game";
47
+
48
+ process.stdout.write(
49
+ `${JSON.stringify(
50
+ {
51
+ hasVisualScenarios: true,
52
+ gameId: effectiveGameId,
53
+ scenarios: scenarioPack.scenarios.map(
54
+ (scenario: { id: string; description?: string }) => ({
55
+ scenarioId: scenario.id,
56
+ description: scenario.description ?? null,
57
+ supportedModes: ["standalone-dev", "arcade-test"],
58
+ }),
59
+ ),
60
+ },
61
+ null,
62
+ 2,
63
+ )}\n`,
64
+ );
@@ -0,0 +1,71 @@
1
+ import crossSpawn from "cross-spawn";
2
+
3
+ type ManagedDevCommand = {
4
+ command: string;
5
+ args: string[];
6
+ cwd: string;
7
+ };
8
+
9
+ const decodeCommand = (encoded: string | undefined): ManagedDevCommand => {
10
+ if (!encoded) {
11
+ throw new Error("Managed dev supervisor requires one command descriptor.");
12
+ }
13
+
14
+ const parsed = JSON.parse(
15
+ Buffer.from(encoded, "base64url").toString("utf8"),
16
+ ) as Partial<ManagedDevCommand>;
17
+ if (
18
+ typeof parsed.command !== "string" ||
19
+ parsed.command.trim() === "" ||
20
+ !Array.isArray(parsed.args) ||
21
+ parsed.args.some((entry) => typeof entry !== "string") ||
22
+ typeof parsed.cwd !== "string" ||
23
+ parsed.cwd.trim() === ""
24
+ ) {
25
+ throw new Error("Managed dev supervisor received an invalid descriptor.");
26
+ }
27
+
28
+ return {
29
+ command: parsed.command,
30
+ args: parsed.args,
31
+ cwd: parsed.cwd,
32
+ };
33
+ };
34
+
35
+ const descriptor = decodeCommand(process.argv[2]);
36
+ const child = crossSpawn(descriptor.command, descriptor.args, {
37
+ cwd: descriptor.cwd,
38
+ env: process.env,
39
+ stdio: "inherit",
40
+ });
41
+
42
+ let terminal = false;
43
+ const exitOnce = (code: number): void => {
44
+ if (terminal) {
45
+ return;
46
+ }
47
+ terminal = true;
48
+ process.exit(code);
49
+ };
50
+
51
+ child.once("error", (error) => {
52
+ console.error(`[airjam-dev-supervisor] ${error.message}`);
53
+ exitOnce(1);
54
+ });
55
+
56
+ child.once("exit", (code, signal) => {
57
+ if (signal) {
58
+ exitOnce(1);
59
+ return;
60
+ }
61
+ exitOnce(code ?? 1);
62
+ });
63
+
64
+ const forwardSignal = (signal: NodeJS.Signals): void => {
65
+ if (!child.killed) {
66
+ child.kill(signal);
67
+ }
68
+ };
69
+
70
+ process.once("SIGINT", () => forwardSignal("SIGINT"));
71
+ process.once("SIGTERM", () => forwardSignal("SIGTERM"));
@@ -0,0 +1,217 @@
1
+ import {
2
+ closeGameSession,
3
+ invokeGameSessionAction,
4
+ openGameSession,
5
+ readGameSession,
6
+ } from "../game-session.js";
7
+ import type {
8
+ AnyAirJamAgentContract,
9
+ VisualHarnessMode,
10
+ VisualScenarioAgent,
11
+ VisualScenarioAgentInvocation,
12
+ VisualScenarioPack,
13
+ } from "../harness/visual.js";
14
+ import { runVisualHarness } from "../harness/visual.js";
15
+ import { loadVisualScenarioPackFromModuleOrConfig } from "./visual-pack.js";
16
+
17
+ const getFlagValue = (flag: string): string | null => {
18
+ const inline = process.argv.find((value) => value.startsWith(`${flag}=`));
19
+ if (inline) {
20
+ return inline.slice(flag.length + 1);
21
+ }
22
+
23
+ const index = process.argv.indexOf(flag);
24
+ return index === -1 ? null : (process.argv[index + 1] ?? null);
25
+ };
26
+
27
+ const modulePath = getFlagValue("--module-path");
28
+ const configPath = getFlagValue("--config");
29
+ const artifactRoot = getFlagValue("--artifact-root");
30
+ const hostUrl = getFlagValue("--host-url");
31
+ const appOrigin = getFlagValue("--app-origin");
32
+ const controllerBaseUrl = getFlagValue("--controller-base-url");
33
+ const publicHost = getFlagValue("--public-host");
34
+ const localBuildUrl = getFlagValue("--local-build-url");
35
+ const browserBuildUrl = getFlagValue("--browser-build-url");
36
+ const scenarioId = getFlagValue("--scenario-id");
37
+ const requestedMode = getFlagValue("--mode") ?? "standalone-dev";
38
+ const gameId = getFlagValue("--game-id");
39
+ const secure = process.argv.includes("--secure");
40
+
41
+ if (
42
+ (!modulePath && !configPath) ||
43
+ !artifactRoot ||
44
+ !hostUrl ||
45
+ !appOrigin ||
46
+ !controllerBaseUrl ||
47
+ !publicHost ||
48
+ !gameId
49
+ ) {
50
+ throw new Error(
51
+ "Missing required visual capture inputs. Expected game id, module path, artifact root, and resolved topology URLs.",
52
+ );
53
+ }
54
+
55
+ const scenarioPack = (await loadVisualScenarioPackFromModuleOrConfig({
56
+ modulePath,
57
+ configPath,
58
+ })) as VisualScenarioPack<AnyAirJamAgentContract>;
59
+ const mode =
60
+ requestedMode === "arcade-test" ? "arcade-built" : "standalone-dev";
61
+
62
+ const asSnapshotRecord = (snapshot: unknown): Record<string, unknown> | null =>
63
+ snapshot && typeof snapshot === "object" && !Array.isArray(snapshot)
64
+ ? (snapshot as Record<string, unknown>)
65
+ : null;
66
+
67
+ const createScenarioAgentSession = async ({
68
+ gameId,
69
+ urls,
70
+ mode,
71
+ secure,
72
+ }: {
73
+ gameId: string;
74
+ mode: VisualHarnessMode;
75
+ secure: boolean;
76
+ urls: {
77
+ controllerJoinUrl: string;
78
+ };
79
+ }): Promise<VisualScenarioAgent> => {
80
+ const opened = await openGameSession({
81
+ cwd: process.cwd(),
82
+ gameId,
83
+ mode: mode === "arcade-built" ? "arcade-test" : "standalone-dev",
84
+ secure,
85
+ controllerJoinUrl: urls.controllerJoinUrl,
86
+ });
87
+
88
+ const read = async (): Promise<Record<string, unknown>> => {
89
+ const inspection = await readGameSession({
90
+ gameSessionId: opened.gameSessionId,
91
+ requestSync: true,
92
+ });
93
+ if (!inspection.gameSnapshot?.snapshot) {
94
+ throw new Error(
95
+ `Visual scenario agent session for "${gameId}" did not expose a semantic game snapshot.`,
96
+ );
97
+ }
98
+ return {
99
+ ...inspection.gameSnapshot.snapshot,
100
+ };
101
+ };
102
+
103
+ return {
104
+ listActions: async () => {
105
+ const inspection = await readGameSession({
106
+ gameSessionId: opened.gameSessionId,
107
+ requestSync: true,
108
+ });
109
+ return inspection.actions;
110
+ },
111
+ read,
112
+ waitFor: async (
113
+ predicate: (
114
+ snapshot: Record<string, unknown>,
115
+ ) => boolean | Promise<boolean>,
116
+ description = "agent snapshot",
117
+ timeout = 30_000,
118
+ ): Promise<Record<string, unknown>> => {
119
+ const startedAt = Date.now();
120
+
121
+ while (Date.now() - startedAt < timeout) {
122
+ const snapshot = await read();
123
+ if (await predicate(snapshot)) {
124
+ return snapshot;
125
+ }
126
+
127
+ await new Promise((resolve) => setTimeout(resolve, 200));
128
+ }
129
+
130
+ throw new Error(`Timed out waiting for ${description}.`);
131
+ },
132
+ invoke: async (
133
+ actionId: string,
134
+ payload?: unknown,
135
+ options?: {
136
+ timeoutMs?: number;
137
+ },
138
+ ): Promise<VisualScenarioAgentInvocation> => {
139
+ const result = await invokeGameSessionAction({
140
+ gameSessionId: opened.gameSessionId,
141
+ actionId,
142
+ payload,
143
+ timeoutMs: options?.timeoutMs,
144
+ });
145
+ const invocation = result.invocation;
146
+
147
+ return {
148
+ actionId: result.actionId,
149
+ lane: result.lane,
150
+ outcome: "outcome" in invocation ? invocation.outcome : null,
151
+ acknowledgementObservation:
152
+ "acknowledgementObservation" in invocation
153
+ ? invocation.acknowledgementObservation
154
+ : null,
155
+ snapshotBefore:
156
+ "snapshotBefore" in invocation
157
+ ? asSnapshotRecord(
158
+ invocation.snapshotBefore?.snapshot ??
159
+ invocation.snapshotBefore,
160
+ )
161
+ : null,
162
+ snapshotAfter:
163
+ "snapshotAfter" in invocation
164
+ ? asSnapshotRecord(
165
+ invocation.snapshotAfter?.snapshot ?? invocation.snapshotAfter,
166
+ )
167
+ : null,
168
+ snapshotAfterStatus:
169
+ "snapshotAfterStatus" in invocation
170
+ ? invocation.snapshotAfterStatus
171
+ : null,
172
+ };
173
+ },
174
+ close: async () => {
175
+ await closeGameSession({
176
+ gameSessionId: opened.gameSessionId,
177
+ }).catch(() => null);
178
+ },
179
+ };
180
+ };
181
+
182
+ try {
183
+ const summary = await runVisualHarness({
184
+ gameId,
185
+ scenarioId: scenarioId ?? null,
186
+ mode,
187
+ secure,
188
+ artifactRoot,
189
+ loadScenarioPack: async () => scenarioPack,
190
+ createAgentSession: async ({ gameId: activeGameId, urls, mode, secure }) =>
191
+ createScenarioAgentSession({
192
+ gameId: activeGameId,
193
+ urls,
194
+ mode,
195
+ secure,
196
+ }),
197
+ startStack: async () => ({
198
+ urls: {
199
+ appOrigin,
200
+ hostUrl,
201
+ controllerBaseUrl,
202
+ publicHost,
203
+ localBuildUrl,
204
+ browserBuildUrl,
205
+ },
206
+ shutdown: async () => {},
207
+ }),
208
+ });
209
+
210
+ process.stdout.write(`${JSON.stringify(summary, null, 2)}\n`);
211
+ process.exit(0);
212
+ } catch (error) {
213
+ const message =
214
+ error instanceof Error ? (error.stack ?? error.message) : String(error);
215
+ process.stderr.write(`${message}\n`);
216
+ process.exit(1);
217
+ }
@@ -0,0 +1,42 @@
1
+ import type { AirJamActionInvocationResult } from "@air-jam/sdk";
2
+ import {
3
+ AIR_JAM_RUNTIME_CONTROL_KEY,
4
+ type HostRuntimeActionRequest,
5
+ type HostRuntimeControl,
6
+ } from "@air-jam/sdk/runtime-control";
7
+ import type { VisualHarnessPageSurface } from "../harness/visual.js";
8
+
9
+ /** Execute only in the game realm held by this browser owner, never its shell. */
10
+ export const invokeOwnedHostAction = async (
11
+ host: VisualHarnessPageSurface,
12
+ action: HostRuntimeActionRequest,
13
+ ): Promise<AirJamActionInvocationResult> => {
14
+ try {
15
+ return await host.game.locator("body").evaluate(
16
+ async (_, { key, request }) => {
17
+ const control = (
18
+ window as unknown as Record<string, HostRuntimeControl | undefined>
19
+ )[key];
20
+ return control
21
+ ? await control.invoke(request)
22
+ : {
23
+ ok: false,
24
+ status: "rejected",
25
+ source: "client",
26
+ reason: "host_runtime_unavailable",
27
+ message: "The owned game has no active host control binding.",
28
+ };
29
+ },
30
+ { key: AIR_JAM_RUNTIME_CONTROL_KEY, request: action },
31
+ );
32
+ } catch {
33
+ return {
34
+ ok: false,
35
+ status: "rejected",
36
+ source: "client",
37
+ reason: "host_ack_missing",
38
+ message:
39
+ "The owned game frame became unavailable before its acknowledgement was observed.",
40
+ };
41
+ }
42
+ };
@@ -0,0 +1,46 @@
1
+ import { pathToFileURL } from "node:url";
2
+ import type {
3
+ AnyAirJamAgentContract,
4
+ VisualScenarioPack,
5
+ } from "../harness/visual.js";
6
+ import { loadVisualScenarioPackFromConfig } from "./airjam-agent.js";
7
+
8
+ export const loadVisualScenarioPack = async (
9
+ modulePath: string,
10
+ ): Promise<VisualScenarioPack<AnyAirJamAgentContract>> => {
11
+ const loaded = (await import(pathToFileURL(modulePath).href)) as {
12
+ visualScenarios?: VisualScenarioPack<AnyAirJamAgentContract>;
13
+ };
14
+
15
+ const scenarioPack = loaded.visualScenarios ?? null;
16
+
17
+ if (
18
+ !scenarioPack ||
19
+ !scenarioPack.agent ||
20
+ !Array.isArray(scenarioPack.scenarios)
21
+ ) {
22
+ throw new Error(`Invalid Air Jam visual scenario pack at ${modulePath}.`);
23
+ }
24
+
25
+ return scenarioPack;
26
+ };
27
+
28
+ export const loadVisualScenarioPackFromModuleOrConfig = async ({
29
+ modulePath,
30
+ configPath,
31
+ }: {
32
+ modulePath?: string | null;
33
+ configPath?: string | null;
34
+ }): Promise<VisualScenarioPack<AnyAirJamAgentContract>> => {
35
+ if (configPath) {
36
+ return loadVisualScenarioPackFromConfig(configPath);
37
+ }
38
+
39
+ if (modulePath) {
40
+ return loadVisualScenarioPack(modulePath);
41
+ }
42
+
43
+ throw new Error(
44
+ "Missing visual scenario source. Expected --config or --module-path.",
45
+ );
46
+ };