@air-jam/devtools 0.9.3 → 1.0.0-beta.2
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/README.md +60 -0
- package/dist/{chunk-VKMJO6VN.js → chunk-2O67AXCU.js} +150 -40
- package/dist/chunk-2O67AXCU.js.map +1 -0
- package/dist/chunk-AO3ZDXF6.js +142 -0
- package/dist/chunk-AO3ZDXF6.js.map +1 -0
- package/dist/chunk-ART5TEYT.js +472 -0
- package/dist/chunk-ART5TEYT.js.map +1 -0
- package/dist/chunk-ASC2CK2R.js +77 -0
- package/dist/chunk-ASC2CK2R.js.map +1 -0
- package/dist/chunk-E3UZZGAV.js +50 -0
- package/dist/chunk-E3UZZGAV.js.map +1 -0
- package/dist/chunk-EJTE7UKX.js +64 -0
- package/dist/chunk-EJTE7UKX.js.map +1 -0
- package/dist/chunk-ESFKNN75.js +110 -0
- package/dist/chunk-ESFKNN75.js.map +1 -0
- package/dist/chunk-EU7A6PXW.js +1339 -0
- package/dist/chunk-EU7A6PXW.js.map +1 -0
- package/dist/chunk-FN7E6EA7.js +549 -0
- package/dist/chunk-FN7E6EA7.js.map +1 -0
- package/dist/chunk-GDFAWHGA.js +190 -0
- package/dist/chunk-GDFAWHGA.js.map +1 -0
- package/dist/chunk-HZUGBH4Y.js +347 -0
- package/dist/chunk-HZUGBH4Y.js.map +1 -0
- package/dist/chunk-ITKAOEGX.js +93 -0
- package/dist/chunk-ITKAOEGX.js.map +1 -0
- package/dist/chunk-JBCUTWRI.js +897 -0
- package/dist/chunk-JBCUTWRI.js.map +1 -0
- package/dist/chunk-JSI5S4WP.js +1174 -0
- package/dist/chunk-JSI5S4WP.js.map +1 -0
- package/dist/chunk-L4D675BG.js +97 -0
- package/dist/chunk-L4D675BG.js.map +1 -0
- package/dist/chunk-M6CJ7GQC.js +133 -0
- package/dist/chunk-M6CJ7GQC.js.map +1 -0
- package/dist/{chunk-CKFT2ZJE.js → chunk-MEIMOSZC.js} +53 -105
- package/dist/chunk-MEIMOSZC.js.map +1 -0
- package/dist/{chunk-GUEZP773.js → chunk-O3XG3FNL.js} +204 -41
- package/dist/chunk-O3XG3FNL.js.map +1 -0
- package/dist/chunk-OM6SCJ7H.js +18 -0
- package/dist/chunk-OM6SCJ7H.js.map +1 -0
- package/dist/chunk-PKD4WVX5.js +63 -0
- package/dist/chunk-PKD4WVX5.js.map +1 -0
- package/dist/chunk-PMBLXGFM.js +3384 -0
- package/dist/chunk-PMBLXGFM.js.map +1 -0
- package/dist/chunk-PMNE5GIN.js +279 -0
- package/dist/chunk-PMNE5GIN.js.map +1 -0
- package/dist/chunk-QAWI64VR.js +148 -0
- package/dist/chunk-QAWI64VR.js.map +1 -0
- package/dist/chunk-QGADSPHZ.js +449 -0
- package/dist/chunk-QGADSPHZ.js.map +1 -0
- package/dist/chunk-SPYN66UV.js +338 -0
- package/dist/chunk-SPYN66UV.js.map +1 -0
- package/dist/context.d.ts +9 -3
- package/dist/context.js +2 -1
- package/dist/controller.d.ts +33 -7
- package/dist/controller.js +18 -8
- package/dist/dependencies.d.ts +44 -0
- package/dist/dependencies.js +10 -0
- package/dist/dev.d.ts +9 -3
- package/dist/dev.js +3 -4
- package/dist/game-builds.d.ts +200 -0
- package/dist/game-builds.js +16 -0
- package/dist/game-builds.js.map +1 -0
- package/dist/game-run-watch-CEd_SpAT.d.ts +84 -0
- package/dist/game-runs.d.ts +1452 -0
- package/dist/game-runs.js +76 -0
- package/dist/game-runs.js.map +1 -0
- package/dist/game-session-broker-CUvORfMd.d.ts +439 -0
- package/dist/game-session-broker.d.ts +4 -57
- package/dist/game-session-broker.js +33 -228
- package/dist/game-session-broker.js.map +1 -1
- package/dist/game-session.d.ts +3931 -10
- package/dist/game-session.js +186 -15
- package/dist/game-session.js.map +1 -1
- package/dist/game-settings.d.ts +16 -0
- package/dist/game-settings.js +237 -0
- package/dist/game-settings.js.map +1 -0
- package/dist/games.d.ts +11 -4
- package/dist/games.js +4 -2
- package/dist/harness/visual.d.ts +34 -151
- package/dist/harness/visual.js +6 -1
- package/dist/logs.d.ts +8 -2
- package/dist/logs.js +3 -4
- package/dist/logs.js.map +1 -1
- package/dist/managed-process-scope-BicYi_t9.d.ts +3 -0
- package/dist/mcp-config.js +2 -1
- package/dist/mcp-config.js.map +1 -1
- package/dist/platform-auth.d.ts +8 -111
- package/dist/platform-auth.js +9 -1
- package/dist/platform-game-analytics.d.ts +51 -0
- package/dist/platform-game-analytics.js +49 -0
- package/dist/platform-game-analytics.js.map +1 -0
- package/dist/platform-game-app-id.d.ts +46 -0
- package/dist/platform-game-app-id.js +93 -0
- package/dist/platform-game-app-id.js.map +1 -0
- package/dist/platform-game-media.d.ts +40 -2
- package/dist/platform-game-media.js +1 -1
- package/dist/platform-games.d.ts +24 -2
- package/dist/platform-games.js +16 -84
- package/dist/platform-games.js.map +1 -1
- package/dist/quality.d.ts +9 -3
- package/dist/quality.js +3 -4
- package/dist/quality.js.map +1 -1
- package/dist/release.d.ts +226 -16
- package/dist/release.js +18 -1331
- package/dist/release.js.map +1 -1
- package/dist/rooms-check.d.ts +90 -0
- package/dist/rooms-check.js +717 -0
- package/dist/rooms-check.js.map +1 -0
- package/dist/source-tree-contract.d.ts +16 -0
- package/dist/source-tree-contract.js +13 -0
- package/dist/source-tree-contract.js.map +1 -0
- package/dist/testing.d.ts +464 -0
- package/dist/testing.js +27 -0
- package/dist/testing.js.map +1 -0
- package/dist/tooling/describe-game.js +54 -0
- package/dist/tooling/describe-game.js.map +1 -0
- package/dist/tooling/game-session-broker.js +28 -0
- package/dist/tooling/game-session-broker.js.map +1 -0
- package/dist/tooling/hold-runtime-host.js +769 -67
- package/dist/tooling/hold-runtime-host.js.map +1 -1
- package/dist/tooling/list-visual-scenarios.js +18 -55
- package/dist/tooling/list-visual-scenarios.js.map +1 -1
- package/dist/tooling/process-scope-bootstrap.mjs +24 -0
- package/dist/tooling/process-scope-guard.d.ts +2 -0
- package/dist/tooling/process-scope-guard.js +388 -0
- package/dist/tooling/process-scope-guard.js.map +1 -0
- package/dist/tooling/process-scope-windows.ps1 +148 -0
- package/dist/tooling/rooms-check-device.d.ts +2 -0
- package/dist/tooling/rooms-check-device.js +498 -0
- package/dist/tooling/rooms-check-device.js.map +1 -0
- package/dist/tooling/run-headless-room.d.ts +2 -0
- package/dist/tooling/run-headless-room.js +287 -0
- package/dist/tooling/run-headless-room.js.map +1 -0
- package/dist/tooling/run-test-profile.d.ts +2 -0
- package/dist/tooling/run-test-profile.js +181 -0
- package/dist/tooling/run-test-profile.js.map +1 -0
- package/dist/tooling/run-visual-capture.js +70 -34
- package/dist/tooling/run-visual-capture.js.map +1 -1
- package/dist/tooling/seal-game-build.d.ts +2 -0
- package/dist/tooling/seal-game-build.js +120 -0
- package/dist/tooling/seal-game-build.js.map +1 -0
- package/dist/{types-C6NrHt88.d.ts → types-CdYrgrG_.d.ts} +337 -76
- package/dist/types-DyRD-ym1.d.ts +141 -0
- package/dist/visual.d.ts +9 -3
- package/dist/visual.js +24 -68
- package/dist/visual.js.map +1 -1
- package/package.json +51 -14
- package/src/bounded-response.ts +28 -0
- package/src/built-game-runtime.ts +152 -0
- package/src/context.ts +2 -13
- package/src/controller-protocol.ts +22 -0
- package/src/controller.ts +747 -597
- package/src/current-room-host.ts +166 -0
- package/src/decision-provider.ts +102 -0
- package/src/dependencies.ts +176 -0
- package/src/dependency-install-contract.ts +12 -0
- package/src/dev.ts +46 -50
- package/src/game-action-observation.ts +11 -1
- package/src/game-build-protocol.ts +72 -0
- package/src/game-build.ts +483 -0
- package/src/game-run-owner.ts +2358 -0
- package/src/game-run-protocol.ts +448 -0
- package/src/game-run-record.ts +92 -0
- package/src/game-run-replay.ts +95 -0
- package/src/game-run-watch.ts +155 -0
- package/src/game-session-broker.ts +689 -197
- package/src/game-session-operations.ts +61 -0
- package/src/game-session-protocol.ts +180 -0
- package/src/game-session-runtime.ts +861 -0
- package/src/game-session.ts +164 -417
- package/src/game-settings.ts +295 -0
- package/src/games.ts +88 -92
- package/src/harness/visual/browser.ts +100 -0
- package/src/harness/visual/controller-observation.ts +181 -0
- package/src/harness/visual/runner.ts +24 -21
- package/src/harness/visual/runtime-controller-observations.ts +151 -0
- package/src/harness/visual/scenario-contract.ts +1 -2
- package/src/harness/visual/scenario-helpers.ts +5 -1
- package/src/harness/visual/screencast.ts +155 -0
- package/src/harness/visual/session.ts +72 -41
- package/src/harness/visual/types.ts +8 -5
- package/src/headless-room-protocol.ts +112 -0
- package/src/headless-room.ts +222 -0
- package/src/helper-channel.ts +229 -0
- package/src/helper-scripts.ts +25 -5
- package/src/installed-dependencies.ts +74 -0
- package/src/managed-process-scope.ts +481 -0
- package/src/node-process-environment.ts +10 -0
- package/src/platform-auth.ts +194 -55
- package/src/platform-game-analytics.ts +50 -0
- package/src/platform-game-app-id.ts +99 -0
- package/src/platform-games.ts +13 -111
- package/src/policy-artifact-contract.ts +52 -0
- package/src/policy-artifacts.ts +134 -0
- package/src/process-scope-admission.ts +50 -0
- package/src/process-scope-protocol.ts +66 -0
- package/src/process-scope.ts +327 -0
- package/src/release.ts +28 -42
- package/src/rooms-check-fleet.ts +194 -0
- package/src/rooms-check-link.ts +138 -0
- package/src/rooms-check-protocol.ts +244 -0
- package/src/rooms-check.ts +797 -0
- package/src/runtime-owner-protocol.ts +106 -18
- package/src/source-tree-contract.ts +70 -0
- package/src/source-tree.ts +84 -0
- package/src/test-profile-process.ts +153 -0
- package/src/test-profile-protocol.ts +116 -0
- package/src/testing.ts +430 -0
- package/src/tooling/declaration-hook.ts +52 -0
- package/src/tooling/describe-game.ts +49 -0
- package/src/tooling/game-session-broker.ts +7 -0
- package/src/tooling/hold-runtime-host.ts +255 -38
- package/src/tooling/list-visual-scenarios.ts +19 -62
- package/src/tooling/load-game.ts +79 -0
- package/src/tooling/process-scope-bootstrap.mjs +24 -0
- package/src/tooling/process-scope-guard.ts +213 -0
- package/src/tooling/process-scope-windows.ps1 +148 -0
- package/src/tooling/rooms-check-device.ts +493 -0
- package/src/tooling/run-headless-room.ts +326 -0
- package/src/tooling/run-test-profile.ts +190 -0
- package/src/tooling/run-visual-capture.ts +37 -23
- package/src/tooling/runtime-owner-actions.ts +23 -0
- package/src/tooling/seal-game-build.ts +118 -0
- package/src/tooling/visual-pack.ts +10 -45
- package/src/types.ts +54 -77
- package/src/visual.ts +14 -22
- package/src/windows-process-scopes.ts +189 -0
- package/dist/agent.d.ts +0 -15
- package/dist/agent.js +0 -19
- package/dist/chunk-5YAARMW5.js +0 -36
- package/dist/chunk-5YAARMW5.js.map +0 -1
- package/dist/chunk-6WQODT37.js +0 -1019
- package/dist/chunk-6WQODT37.js.map +0 -1
- package/dist/chunk-CKFT2ZJE.js.map +0 -1
- package/dist/chunk-ER3Q2C4G.js +0 -358
- package/dist/chunk-ER3Q2C4G.js.map +0 -1
- package/dist/chunk-GUEZP773.js.map +0 -1
- package/dist/chunk-HIDNI56E.js +0 -33
- package/dist/chunk-HIDNI56E.js.map +0 -1
- package/dist/chunk-QKXS5D35.js +0 -43
- package/dist/chunk-QKXS5D35.js.map +0 -1
- package/dist/chunk-S4LSCEVE.js +0 -261
- package/dist/chunk-S4LSCEVE.js.map +0 -1
- package/dist/chunk-VKMJO6VN.js.map +0 -1
- package/dist/chunk-WFUR3MXY.js +0 -67
- package/dist/chunk-WFUR3MXY.js.map +0 -1
- package/dist/chunk-XEMR7KUE.js +0 -361
- package/dist/chunk-XEMR7KUE.js.map +0 -1
- package/dist/chunk-ZLPD7FY5.js +0 -191
- package/dist/chunk-ZLPD7FY5.js.map +0 -1
- package/dist/tooling/agent-contract.js +0 -193
- package/dist/tooling/agent-contract.js.map +0 -1
- package/dist/tooling/inspect-airjam-agent.js +0 -37
- package/dist/tooling/inspect-airjam-agent.js.map +0 -1
- package/src/agent.ts +0 -380
- package/src/tooling/agent-contract.ts +0 -232
- package/src/tooling/agent-declaration.ts +0 -36
- package/src/tooling/airjam-agent-inspection.ts +0 -45
- package/src/tooling/airjam-agent.ts +0 -118
- package/src/tooling/inspect-airjam-agent.ts +0 -20
- /package/dist/{agent.js.map → dependencies.js.map} +0 -0
- /package/dist/tooling/{agent-contract.d.ts → describe-game.d.ts} +0 -0
- /package/dist/tooling/{inspect-airjam-agent.d.ts → game-session-broker.d.ts} +0 -0
|
@@ -1,27 +1,38 @@
|
|
|
1
|
+
import { airJamSettingsValuesSchema } from "@air-jam/sdk/core";
|
|
1
2
|
import {
|
|
2
3
|
AIR_JAM_RUNTIME_INSPECTION_KEY,
|
|
3
4
|
readRuntimeInspectionContract,
|
|
4
5
|
} from "@air-jam/sdk/runtime-inspection";
|
|
5
6
|
import { mkdir } from "node:fs/promises";
|
|
6
7
|
import path from "node:path";
|
|
8
|
+
import { startBuiltGameRuntime } from "../built-game-runtime.js";
|
|
9
|
+
import type { GameRunWatchEvent } from "../game-run-watch.js";
|
|
7
10
|
import {
|
|
8
11
|
DEFAULT_CONTROLLER_VIEWPORT,
|
|
9
12
|
DEFAULT_HOST_VIEWPORT,
|
|
10
|
-
launchHarnessBrowser,
|
|
11
|
-
openVisualHarnessControllerSession,
|
|
12
13
|
openVisualHarnessHostSession,
|
|
13
|
-
type OpenVisualHarnessControllerSessionResult,
|
|
14
14
|
type VisualHarnessMode,
|
|
15
15
|
} from "../harness/visual.js";
|
|
16
|
+
import { launchScopedHarnessBrowser } from "../harness/visual/browser.js";
|
|
17
|
+
import { RuntimeControllerObservations } from "../harness/visual/runtime-controller-observations.js";
|
|
18
|
+
import { startGameScreencast } from "../harness/visual/screencast.js";
|
|
19
|
+
import { bindHarnessControllerUrl } from "../harness/visual/session.js";
|
|
16
20
|
import {
|
|
17
21
|
AIR_JAM_RUNTIME_OWNER_ACTION_RESULT,
|
|
18
22
|
AIR_JAM_RUNTIME_OWNER_CAPTURE_RESULT,
|
|
19
23
|
isRuntimeOwnerActionRequest,
|
|
20
24
|
isRuntimeOwnerCaptureRequest,
|
|
21
25
|
resolveProjectRelativeRuntimeCaptureDir,
|
|
26
|
+
runtimeOwnerAgentRequestSchema,
|
|
27
|
+
runtimeOwnerCapturePortSchema,
|
|
28
|
+
runtimeOwnerWatchRequestSchema,
|
|
29
|
+
runtimeOwnerWatchStopSchema,
|
|
22
30
|
type AirJamRuntimeOwnerCaptureResult,
|
|
23
31
|
} from "../runtime-owner-protocol.js";
|
|
24
|
-
import {
|
|
32
|
+
import {
|
|
33
|
+
evaluateOwnedGameContract,
|
|
34
|
+
invokeOwnedHostAction,
|
|
35
|
+
} from "./runtime-owner-actions.js";
|
|
25
36
|
|
|
26
37
|
const getFlagValue = (flag: string): string | null => {
|
|
27
38
|
const inline = process.argv.find((value) => value.startsWith(`${flag}=`));
|
|
@@ -33,10 +44,15 @@ const getFlagValue = (flag: string): string | null => {
|
|
|
33
44
|
return index === -1 ? null : (process.argv[index + 1] ?? null);
|
|
34
45
|
};
|
|
35
46
|
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
47
|
+
const pinnedManifest = getFlagValue("--pinned-build");
|
|
48
|
+
const built = pinnedManifest
|
|
49
|
+
? await startBuiltGameRuntime(pinnedManifest)
|
|
50
|
+
: null;
|
|
51
|
+
const appOrigin = built?.urls.appOrigin ?? getFlagValue("--app-origin");
|
|
52
|
+
const hostUrl = built?.urls.hostUrl ?? getFlagValue("--host-url");
|
|
53
|
+
const controllerBaseUrl =
|
|
54
|
+
built?.urls.controllerBaseUrl ?? getFlagValue("--controller-base-url");
|
|
55
|
+
const publicHost = built?.urls.publicHost ?? getFlagValue("--public-host");
|
|
40
56
|
const localBuildUrl = getFlagValue("--local-build-url");
|
|
41
57
|
const browserBuildUrl = getFlagValue("--browser-build-url");
|
|
42
58
|
const requestedMode = getFlagValue("--mode") ?? "standalone-dev";
|
|
@@ -48,31 +64,185 @@ if (!appOrigin || !hostUrl || !controllerBaseUrl || !publicHost) {
|
|
|
48
64
|
);
|
|
49
65
|
}
|
|
50
66
|
|
|
51
|
-
const
|
|
67
|
+
const initialSettings = getFlagValue("--settings");
|
|
68
|
+
const initialHostUrl = new URL(hostUrl);
|
|
69
|
+
if (initialSettings)
|
|
70
|
+
initialHostUrl.searchParams.set(
|
|
71
|
+
"airjamSettings",
|
|
72
|
+
JSON.stringify(
|
|
73
|
+
airJamSettingsValuesSchema.parse(JSON.parse(initialSettings)),
|
|
74
|
+
),
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
const runtimeBrowser = await launchScopedHarnessBrowser();
|
|
78
|
+
const { browser } = runtimeBrowser;
|
|
79
|
+
let startupDiagnostics = true;
|
|
52
80
|
const session = await openVisualHarnessHostSession({
|
|
53
81
|
browser,
|
|
82
|
+
runtimeTopology: built?.topology,
|
|
83
|
+
onDiagnostic: (message) => {
|
|
84
|
+
if (startupDiagnostics) console.error(message.slice(0, 4000));
|
|
85
|
+
},
|
|
54
86
|
mode: requestedMode as VisualHarnessMode,
|
|
55
87
|
urls: {
|
|
56
88
|
appOrigin,
|
|
57
|
-
hostUrl,
|
|
89
|
+
hostUrl: initialHostUrl.toString(),
|
|
58
90
|
controllerBaseUrl,
|
|
59
91
|
publicHost,
|
|
60
92
|
localBuildUrl,
|
|
61
93
|
browserBuildUrl,
|
|
62
94
|
},
|
|
63
95
|
});
|
|
64
|
-
let
|
|
65
|
-
|
|
96
|
+
let captureRequestId: string | null = null;
|
|
97
|
+
const observations = new RuntimeControllerObservations({
|
|
98
|
+
browser,
|
|
99
|
+
readInspection: () => readInspection(),
|
|
100
|
+
send: (message) => {
|
|
101
|
+
process.send?.(message as Parameters<NonNullable<typeof process.send>>[0]);
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
type RuntimeWatch = {
|
|
105
|
+
opening: Promise<void>;
|
|
106
|
+
stopping: boolean;
|
|
107
|
+
cast?: Awaited<ReturnType<typeof startGameScreencast>>;
|
|
108
|
+
closing?: Promise<void>;
|
|
109
|
+
};
|
|
110
|
+
const watches = new Map<string, RuntimeWatch>();
|
|
111
|
+
const stopWatch = (watchId: string) => {
|
|
112
|
+
const watch = watches.get(watchId);
|
|
113
|
+
if (!watch) return Promise.resolve();
|
|
114
|
+
watch.stopping = true;
|
|
115
|
+
return (watch.closing ??= (async () => {
|
|
116
|
+
const results = await Promise.allSettled([
|
|
117
|
+
observations.close(watchId),
|
|
118
|
+
(async () => {
|
|
119
|
+
await watch.opening.catch(() => undefined);
|
|
120
|
+
await watch.cast?.close();
|
|
121
|
+
})(),
|
|
122
|
+
]);
|
|
123
|
+
const failures = results.filter((result) => result.status === "rejected");
|
|
124
|
+
watches.delete(watchId);
|
|
125
|
+
if (failures.length)
|
|
126
|
+
throw new AggregateError(
|
|
127
|
+
failures.map((result) => result.reason),
|
|
128
|
+
[
|
|
129
|
+
"Run watch cleanup failed.",
|
|
130
|
+
...failures.map(({ reason }) =>
|
|
131
|
+
reason instanceof Error ? reason.message : String(reason),
|
|
132
|
+
),
|
|
133
|
+
]
|
|
134
|
+
.join(" ")
|
|
135
|
+
.slice(0, 4000),
|
|
136
|
+
);
|
|
137
|
+
})());
|
|
138
|
+
};
|
|
66
139
|
const shutdown = async (exitCode = 0) => {
|
|
67
140
|
await Promise.allSettled([
|
|
68
|
-
|
|
141
|
+
...[...watches.keys()].map(stopWatch),
|
|
142
|
+
observations.closeAll(),
|
|
69
143
|
session.close(),
|
|
70
|
-
|
|
144
|
+
runtimeBrowser.close(),
|
|
145
|
+
built?.close(),
|
|
71
146
|
]);
|
|
72
147
|
process.exit(exitCode);
|
|
73
148
|
};
|
|
74
149
|
|
|
75
150
|
process.on("message", (message: unknown) => {
|
|
151
|
+
const agentRequest = runtimeOwnerAgentRequestSchema.safeParse(message);
|
|
152
|
+
if (agentRequest.success) {
|
|
153
|
+
const { requestId, request } = agentRequest.data;
|
|
154
|
+
void (async () => {
|
|
155
|
+
try {
|
|
156
|
+
const result = await evaluateOwnedGameContract(session.host, request);
|
|
157
|
+
process.send?.({
|
|
158
|
+
type: "air-jam-runtime-owner.agent-result/v1",
|
|
159
|
+
requestId,
|
|
160
|
+
ok: true,
|
|
161
|
+
result,
|
|
162
|
+
});
|
|
163
|
+
} catch (error) {
|
|
164
|
+
process.send?.({
|
|
165
|
+
type: "air-jam-runtime-owner.agent-result/v1",
|
|
166
|
+
requestId,
|
|
167
|
+
ok: false,
|
|
168
|
+
error: error instanceof Error ? error.message : String(error),
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
})();
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const captureEvent = runtimeOwnerCapturePortSchema.safeParse(message);
|
|
175
|
+
if (captureEvent.success) {
|
|
176
|
+
observations.deliver(captureEvent.data);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const watchStop = runtimeOwnerWatchStopSchema.safeParse(message);
|
|
180
|
+
if (watchStop.success) {
|
|
181
|
+
void stopWatch(watchStop.data.watchId)
|
|
182
|
+
.then(() => {
|
|
183
|
+
process.send?.({
|
|
184
|
+
type: "air-jam-runtime-owner.watch-event/v1",
|
|
185
|
+
watchId: watchStop.data.watchId,
|
|
186
|
+
event: { type: "closed" },
|
|
187
|
+
});
|
|
188
|
+
})
|
|
189
|
+
.catch((error: unknown) => {
|
|
190
|
+
process.send?.({
|
|
191
|
+
type: "air-jam-runtime-owner.watch-event/v1",
|
|
192
|
+
watchId: watchStop.data.watchId,
|
|
193
|
+
event: { type: "error", message: String(error).slice(0, 4000) },
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const watchRequest = runtimeOwnerWatchRequestSchema.safeParse(message);
|
|
199
|
+
if (watchRequest.success) {
|
|
200
|
+
const request = watchRequest.data;
|
|
201
|
+
if (watches.has(request.watchId)) return;
|
|
202
|
+
const send = (
|
|
203
|
+
event:
|
|
204
|
+
| GameRunWatchEvent
|
|
205
|
+
| { type: "ready"; width: number; height: number },
|
|
206
|
+
sent?: (error: Error | null) => void,
|
|
207
|
+
) => {
|
|
208
|
+
const message = {
|
|
209
|
+
type: "air-jam-runtime-owner.watch-event/v1",
|
|
210
|
+
watchId: request.watchId,
|
|
211
|
+
event,
|
|
212
|
+
};
|
|
213
|
+
if (sent) process.send?.(message, undefined, undefined, sent);
|
|
214
|
+
else process.send?.(message);
|
|
215
|
+
};
|
|
216
|
+
const fail = (error: Error) => {
|
|
217
|
+
if (watches.get(request.watchId)?.stopping) return;
|
|
218
|
+
send({ type: "error", message: error.message.slice(0, 4000) });
|
|
219
|
+
void stopWatch(request.watchId).catch((cleanupError: unknown) =>
|
|
220
|
+
console.error("Run watch cleanup failed:", cleanupError),
|
|
221
|
+
);
|
|
222
|
+
};
|
|
223
|
+
if (watches.size >= 2) {
|
|
224
|
+
send({ type: "error", message: "Run watch producer limit reached." });
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
const watch: RuntimeWatch = { opening: Promise.resolve(), stopping: false };
|
|
228
|
+
watches.set(request.watchId, watch);
|
|
229
|
+
watch.opening = (async () => {
|
|
230
|
+
const page =
|
|
231
|
+
request.surface === "host"
|
|
232
|
+
? session.host.page
|
|
233
|
+
: (await observations.open(request.watchId, request, fail)).page;
|
|
234
|
+
watch.cast = await startGameScreencast({
|
|
235
|
+
page,
|
|
236
|
+
send,
|
|
237
|
+
onError: fail,
|
|
238
|
+
onReady: (dimensions) => send({ type: "ready", ...dimensions }),
|
|
239
|
+
});
|
|
240
|
+
})();
|
|
241
|
+
void watch.opening.catch((error: unknown) =>
|
|
242
|
+
fail(error instanceof Error ? error : new Error(String(error))),
|
|
243
|
+
);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
76
246
|
if (isRuntimeOwnerActionRequest(message)) {
|
|
77
247
|
void (async () => {
|
|
78
248
|
const acknowledgement = await invokeOwnedHostAction(
|
|
@@ -88,6 +258,18 @@ process.on("message", (message: unknown) => {
|
|
|
88
258
|
return;
|
|
89
259
|
}
|
|
90
260
|
if (!isRuntimeOwnerCaptureRequest(message)) return;
|
|
261
|
+
if (captureRequestId) {
|
|
262
|
+
process.send?.({
|
|
263
|
+
type: AIR_JAM_RUNTIME_OWNER_CAPTURE_RESULT,
|
|
264
|
+
requestId: message.requestId,
|
|
265
|
+
ok: false,
|
|
266
|
+
capturedAt: new Date().toISOString(),
|
|
267
|
+
screenshots: [],
|
|
268
|
+
error: "A runtime visual capture is already active.",
|
|
269
|
+
});
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
captureRequestId = message.requestId;
|
|
91
273
|
void (async () => {
|
|
92
274
|
const capturedAt = new Date().toISOString();
|
|
93
275
|
const response: AirJamRuntimeOwnerCaptureResult = {
|
|
@@ -98,23 +280,20 @@ process.on("message", (message: unknown) => {
|
|
|
98
280
|
screenshots: [],
|
|
99
281
|
error: null,
|
|
100
282
|
};
|
|
283
|
+
let observationError: Error | undefined;
|
|
101
284
|
try {
|
|
102
285
|
const captureDir = resolveProjectRelativeRuntimeCaptureDir({
|
|
103
286
|
projectDir: process.cwd(),
|
|
104
287
|
relativeDir: message.relativeDir,
|
|
105
288
|
});
|
|
106
|
-
controllerSession
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
controllerBaseUrl,
|
|
112
|
-
publicHost,
|
|
113
|
-
localBuildUrl,
|
|
114
|
-
browserBuildUrl,
|
|
289
|
+
const controllerSession = await observations.open(
|
|
290
|
+
message.requestId,
|
|
291
|
+
message,
|
|
292
|
+
(error) => {
|
|
293
|
+
observationError = error;
|
|
115
294
|
},
|
|
116
|
-
|
|
117
|
-
|
|
295
|
+
);
|
|
296
|
+
if (observationError) throw observationError;
|
|
118
297
|
await mkdir(captureDir, { recursive: true });
|
|
119
298
|
const captures = [
|
|
120
299
|
{
|
|
@@ -127,7 +306,7 @@ process.on("message", (message: unknown) => {
|
|
|
127
306
|
surface: "controller" as const,
|
|
128
307
|
fileName: "controller-phone.png",
|
|
129
308
|
viewport: DEFAULT_CONTROLLER_VIEWPORT,
|
|
130
|
-
page: controllerSession.
|
|
309
|
+
page: controllerSession.page,
|
|
131
310
|
},
|
|
132
311
|
];
|
|
133
312
|
for (const capture of captures) {
|
|
@@ -144,6 +323,23 @@ process.on("message", (message: unknown) => {
|
|
|
144
323
|
response.ok = true;
|
|
145
324
|
} catch (error) {
|
|
146
325
|
response.error = error instanceof Error ? error.message : String(error);
|
|
326
|
+
} finally {
|
|
327
|
+
captureRequestId = null;
|
|
328
|
+
if (observationError) {
|
|
329
|
+
response.ok = false;
|
|
330
|
+
response.error = observationError.message;
|
|
331
|
+
}
|
|
332
|
+
try {
|
|
333
|
+
await observations.close(message.requestId);
|
|
334
|
+
} catch (error) {
|
|
335
|
+
response.ok = false;
|
|
336
|
+
response.error = [
|
|
337
|
+
response.error,
|
|
338
|
+
error instanceof Error ? error.message : String(error),
|
|
339
|
+
]
|
|
340
|
+
.filter(Boolean)
|
|
341
|
+
.join("; ");
|
|
342
|
+
}
|
|
147
343
|
}
|
|
148
344
|
process.send?.(response);
|
|
149
345
|
})();
|
|
@@ -175,9 +371,20 @@ const readInspection = async () => {
|
|
|
175
371
|
AIR_JAM_RUNTIME_INSPECTION_KEY,
|
|
176
372
|
);
|
|
177
373
|
|
|
178
|
-
|
|
374
|
+
const inspection = readRuntimeInspectionContract({
|
|
179
375
|
[AIR_JAM_RUNTIME_INSPECTION_KEY]: rawValue,
|
|
180
376
|
});
|
|
377
|
+
return built &&
|
|
378
|
+
inspection?.role === "host" &&
|
|
379
|
+
inspection.joinUrlStatus === "ready"
|
|
380
|
+
? {
|
|
381
|
+
...inspection,
|
|
382
|
+
joinUrl: bindHarnessControllerUrl(
|
|
383
|
+
inspection.joinUrl,
|
|
384
|
+
built.urls.controllerBaseUrl,
|
|
385
|
+
),
|
|
386
|
+
}
|
|
387
|
+
: inspection;
|
|
181
388
|
};
|
|
182
389
|
|
|
183
390
|
try {
|
|
@@ -203,17 +410,27 @@ try {
|
|
|
203
410
|
);
|
|
204
411
|
}
|
|
205
412
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
)
|
|
216
|
-
|
|
413
|
+
if (built) {
|
|
414
|
+
const origin = new URL(session.host.page.url()).origin;
|
|
415
|
+
if (
|
|
416
|
+
origin !== appOrigin ||
|
|
417
|
+
(await session.host.page.evaluate(() =>
|
|
418
|
+
performance
|
|
419
|
+
.getEntriesByType("resource")
|
|
420
|
+
.some((entry) => new URL(entry.name).pathname === "/@vite/client"),
|
|
421
|
+
))
|
|
422
|
+
)
|
|
423
|
+
throw new Error(
|
|
424
|
+
"build_runtime_invalid: The owned browser is not running the pinned production origin.",
|
|
425
|
+
);
|
|
426
|
+
}
|
|
427
|
+
startupDiagnostics = false;
|
|
428
|
+
process.send?.({
|
|
429
|
+
type: "air-jam-runtime-owner.ready/v1",
|
|
430
|
+
roomId: inspection.roomId,
|
|
431
|
+
controllerJoinUrl: inspection.joinUrl,
|
|
432
|
+
inspection,
|
|
433
|
+
});
|
|
217
434
|
|
|
218
435
|
await new Promise(() => {
|
|
219
436
|
// Keep the hidden host runtime alive until the parent process disconnects it.
|
|
@@ -1,64 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
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
|
-
|
|
1
|
+
import { loadAirJamGame, loadAirJamTesting } from "./load-game.js";
|
|
2
|
+
const inline = process.argv.find((value) => value.startsWith("--config="));
|
|
3
|
+
const configIndex = process.argv.indexOf("--config");
|
|
4
|
+
const configPath =
|
|
5
|
+
inline?.slice(9) ??
|
|
6
|
+
(configIndex >= 0 ? process.argv[configIndex + 1] : undefined);
|
|
7
|
+
if (!configPath) throw new Error("Missing required --config.");
|
|
8
|
+
const game = await loadAirJamGame(configPath);
|
|
9
|
+
const testing = await loadAirJamTesting(configPath, game);
|
|
48
10
|
process.stdout.write(
|
|
49
|
-
`${JSON.stringify(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
scenarios
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
),
|
|
60
|
-
},
|
|
61
|
-
null,
|
|
62
|
-
2,
|
|
63
|
-
)}\n`,
|
|
11
|
+
`${JSON.stringify({
|
|
12
|
+
hasVisualScenarios: Boolean(testing?.visual),
|
|
13
|
+
gameId: game.metadata.slug,
|
|
14
|
+
scenarios:
|
|
15
|
+
testing?.visual?.scenarios.map((scenario) => ({
|
|
16
|
+
scenarioId: scenario.id,
|
|
17
|
+
description: scenario.description ?? null,
|
|
18
|
+
supportedModes: ["standalone-dev", "arcade-test"],
|
|
19
|
+
})) ?? [],
|
|
20
|
+
})}\n`,
|
|
64
21
|
);
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { isAirJamGame, type AirJamGame } from "@air-jam/sdk/core";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { realpath } from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
import { register as registerTypescript } from "tsx/esm/api";
|
|
7
|
+
import type { defineAirJamTesting } from "../testing.js";
|
|
8
|
+
import { importDeclaration } from "./declaration-hook.js";
|
|
9
|
+
|
|
10
|
+
const registered = new Map<
|
|
11
|
+
string,
|
|
12
|
+
{
|
|
13
|
+
import: (
|
|
14
|
+
specifier: string,
|
|
15
|
+
parent: string,
|
|
16
|
+
) => Promise<Record<string, unknown>>;
|
|
17
|
+
}
|
|
18
|
+
>();
|
|
19
|
+
export async function loadAirJamGame(configPath: string): Promise<AirJamGame> {
|
|
20
|
+
const configUrl = pathToFileURL(await realpath(configPath)).href;
|
|
21
|
+
if (!registered.has(configUrl)) {
|
|
22
|
+
const tsconfig = [
|
|
23
|
+
path.join(path.dirname(configPath), "tsconfig.json"),
|
|
24
|
+
path.resolve(path.dirname(configPath), "../tsconfig.json"),
|
|
25
|
+
].find(existsSync);
|
|
26
|
+
const typescript = registerTypescript({
|
|
27
|
+
namespace: configUrl,
|
|
28
|
+
tsconfig: tsconfig ?? false,
|
|
29
|
+
});
|
|
30
|
+
registered.set(configUrl, typescript);
|
|
31
|
+
}
|
|
32
|
+
const typescript = registered.get(configUrl);
|
|
33
|
+
if (!typescript)
|
|
34
|
+
throw new Error("Declaration TypeScript loader was not registered.");
|
|
35
|
+
const loaded = await importDeclaration(() =>
|
|
36
|
+
typescript.import(configUrl, import.meta.url),
|
|
37
|
+
);
|
|
38
|
+
if (!isAirJamGame(loaded.airjam))
|
|
39
|
+
throw new Error(
|
|
40
|
+
`Air Jam config "${configPath}" must export airjam = defineAirJamGame(...) from @air-jam/sdk/core.`,
|
|
41
|
+
);
|
|
42
|
+
return loaded.airjam;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function loadAirJamTesting(
|
|
46
|
+
configPath: string,
|
|
47
|
+
game: AirJamGame,
|
|
48
|
+
): Promise<ReturnType<typeof defineAirJamTesting> | null> {
|
|
49
|
+
if (!game.testing) return null;
|
|
50
|
+
const root = await realpath(path.resolve(path.dirname(configPath), ".."));
|
|
51
|
+
const modulePath = await realpath(
|
|
52
|
+
path.resolve(path.dirname(configPath), game.testing),
|
|
53
|
+
);
|
|
54
|
+
const relative = path.relative(root, modulePath);
|
|
55
|
+
if (
|
|
56
|
+
relative === ".." ||
|
|
57
|
+
relative.startsWith(`..${path.sep}`) ||
|
|
58
|
+
path.isAbsolute(relative)
|
|
59
|
+
)
|
|
60
|
+
throw new Error("Air Jam testing must live inside the game project.");
|
|
61
|
+
const configUrl = pathToFileURL(await realpath(configPath)).href;
|
|
62
|
+
const typescript = registered.get(configUrl);
|
|
63
|
+
if (!typescript)
|
|
64
|
+
throw new Error("Load the game declaration before its testing module.");
|
|
65
|
+
const loaded = await typescript.import(
|
|
66
|
+
pathToFileURL(modulePath).href,
|
|
67
|
+
import.meta.url,
|
|
68
|
+
);
|
|
69
|
+
if (
|
|
70
|
+
!loaded.testing ||
|
|
71
|
+
typeof loaded.testing !== "object" ||
|
|
72
|
+
!("profiles" in loaded.testing) ||
|
|
73
|
+
!loaded.testing.profiles
|
|
74
|
+
)
|
|
75
|
+
throw new Error(
|
|
76
|
+
`Testing module "${modulePath}" must export testing = defineAirJamTesting(...).`,
|
|
77
|
+
);
|
|
78
|
+
return loaded.testing as ReturnType<typeof defineAirJamTesting>;
|
|
79
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
3
|
+
|
|
4
|
+
const [entry, loader, ...argumentsList] = process.argv.slice(2);
|
|
5
|
+
process.once("disconnect", () => process.exit(1));
|
|
6
|
+
await new Promise((resolve, reject) => {
|
|
7
|
+
process.once("message", (permission) => {
|
|
8
|
+
if (permission === 1) resolve();
|
|
9
|
+
else reject(new Error("Process scope admission was refused."));
|
|
10
|
+
});
|
|
11
|
+
process.send(0);
|
|
12
|
+
});
|
|
13
|
+
process.argv = [process.execPath, entry, ...argumentsList];
|
|
14
|
+
if (loader !== "javascript") {
|
|
15
|
+
const loaderRequire = createRequire(loader);
|
|
16
|
+
const [{ register: registerCommonJs }, { register: registerEsm }] =
|
|
17
|
+
await Promise.all([
|
|
18
|
+
import(pathToFileURL(loaderRequire.resolve("tsx/cjs/api")).href),
|
|
19
|
+
import(pathToFileURL(loaderRequire.resolve("tsx/esm/api")).href),
|
|
20
|
+
]);
|
|
21
|
+
registerCommonJs();
|
|
22
|
+
registerEsm();
|
|
23
|
+
}
|
|
24
|
+
await import(pathToFileURL(entry).href);
|