@air-jam/devtools 0.9.3 → 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.
- 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,6 +1,13 @@
|
|
|
1
1
|
import type { AirJamActionInvocationResult } from "@air-jam/sdk";
|
|
2
|
+
import { airJamActionInvocationResultSchema } from "@air-jam/sdk/protocol";
|
|
2
3
|
import type { HostRuntimeActionRequest } from "@air-jam/sdk/runtime-control";
|
|
4
|
+
import {
|
|
5
|
+
hostAgentRequestSchema,
|
|
6
|
+
hostAgentResponseSchema,
|
|
7
|
+
} from "@air-jam/sdk/runtime-control";
|
|
3
8
|
import path from "node:path";
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import { gameSurfaceWatchEventSchema } from "./game-run-watch.js";
|
|
4
11
|
|
|
5
12
|
export const AIR_JAM_RUNTIME_OWNER_ACTION_REQUEST =
|
|
6
13
|
"air-jam-runtime-owner.invoke-action/v1" as const;
|
|
@@ -30,27 +37,57 @@ export const isRuntimeOwnerActionRequest = (
|
|
|
30
37
|
typeof value.action.actionName === "string" &&
|
|
31
38
|
(value.action.payload === undefined || isRecord(value.action.payload));
|
|
32
39
|
|
|
40
|
+
const runtimeOwnerActionResultSchema = z.object({
|
|
41
|
+
type: z.literal(AIR_JAM_RUNTIME_OWNER_ACTION_RESULT),
|
|
42
|
+
requestId: z.string().min(1),
|
|
43
|
+
acknowledgement: airJamActionInvocationResultSchema,
|
|
44
|
+
});
|
|
33
45
|
export const isRuntimeOwnerActionResult = (
|
|
34
46
|
value: unknown,
|
|
35
47
|
): value is AirJamRuntimeOwnerActionResult =>
|
|
36
|
-
|
|
37
|
-
value.type === AIR_JAM_RUNTIME_OWNER_ACTION_RESULT &&
|
|
38
|
-
typeof value.requestId === "string" &&
|
|
39
|
-
isRecord(value.acknowledgement) &&
|
|
40
|
-
typeof value.acknowledgement.ok === "boolean" &&
|
|
41
|
-
["accepted", "rejected"].includes(String(value.acknowledgement.status)) &&
|
|
42
|
-
["client", "server", "host"].includes(String(value.acknowledgement.source));
|
|
48
|
+
runtimeOwnerActionResultSchema.safeParse(value).success;
|
|
43
49
|
|
|
44
50
|
export const AIR_JAM_RUNTIME_OWNER_CAPTURE_REQUEST =
|
|
45
51
|
"air-jam-runtime-owner.capture-visuals/v1" as const;
|
|
46
52
|
export const AIR_JAM_RUNTIME_OWNER_CAPTURE_RESULT =
|
|
47
53
|
"air-jam-runtime-owner.capture-visuals-result/v1" as const;
|
|
48
54
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
};
|
|
55
|
+
/** Who the observed controller page plays as: the acting phone's harness session and room. */
|
|
56
|
+
export const runtimeOwnerObservedControllerSchema = z.object({
|
|
57
|
+
harnessSessionId: z.uuid(),
|
|
58
|
+
roomId: z.string().min(1),
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const runtimeOwnerCaptureSchema = z.object({
|
|
62
|
+
type: z.literal(AIR_JAM_RUNTIME_OWNER_CAPTURE_REQUEST),
|
|
63
|
+
requestId: z.uuid(),
|
|
64
|
+
relativeDir: z.string().min(1),
|
|
65
|
+
...runtimeOwnerObservedControllerSchema.shape,
|
|
66
|
+
});
|
|
67
|
+
export type AirJamRuntimeOwnerCaptureRequest = z.infer<
|
|
68
|
+
typeof runtimeOwnerCaptureSchema
|
|
69
|
+
>;
|
|
70
|
+
/**
|
|
71
|
+
* The observed controller page's room port, relayed between the owner and
|
|
72
|
+
* the process that holds the acting phone: the page's messages travel as
|
|
73
|
+
* capture frames, the answers as capture port messages.
|
|
74
|
+
*/
|
|
75
|
+
export const AIR_JAM_RUNTIME_OWNER_CAPTURE_PORT =
|
|
76
|
+
"air-jam-runtime-owner.capture-port/v1" as const;
|
|
77
|
+
export const AIR_JAM_RUNTIME_OWNER_CAPTURE_FRAME =
|
|
78
|
+
"air-jam-runtime-owner.capture-frame/v1" as const;
|
|
79
|
+
|
|
80
|
+
export const runtimeOwnerCapturePortSchema = z.object({
|
|
81
|
+
type: z.literal(AIR_JAM_RUNTIME_OWNER_CAPTURE_PORT),
|
|
82
|
+
requestId: z.uuid(),
|
|
83
|
+
message: z.unknown(),
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
export const runtimeOwnerCaptureFrameSchema = z.object({
|
|
87
|
+
type: z.literal(AIR_JAM_RUNTIME_OWNER_CAPTURE_FRAME),
|
|
88
|
+
requestId: z.uuid(),
|
|
89
|
+
message: z.unknown(),
|
|
90
|
+
});
|
|
54
91
|
|
|
55
92
|
export type AirJamRuntimeOwnerScreenshot = {
|
|
56
93
|
surface: "host" | "controller";
|
|
@@ -88,12 +125,7 @@ const isRuntimeOwnerScreenshot = (
|
|
|
88
125
|
export const isRuntimeOwnerCaptureRequest = (
|
|
89
126
|
value: unknown,
|
|
90
127
|
): value is AirJamRuntimeOwnerCaptureRequest =>
|
|
91
|
-
|
|
92
|
-
value.type === AIR_JAM_RUNTIME_OWNER_CAPTURE_REQUEST &&
|
|
93
|
-
typeof value.requestId === "string" &&
|
|
94
|
-
value.requestId.length > 0 &&
|
|
95
|
-
typeof value.relativeDir === "string" &&
|
|
96
|
-
value.relativeDir.length > 0;
|
|
128
|
+
runtimeOwnerCaptureSchema.safeParse(value).success;
|
|
97
129
|
|
|
98
130
|
export const isRuntimeOwnerCaptureResult = (
|
|
99
131
|
value: unknown,
|
|
@@ -128,3 +160,59 @@ export const resolveProjectRelativeRuntimeCaptureDir = ({
|
|
|
128
160
|
}
|
|
129
161
|
return resolved;
|
|
130
162
|
};
|
|
163
|
+
|
|
164
|
+
export const runtimeOwnerAgentRequestSchema = z
|
|
165
|
+
.object({
|
|
166
|
+
type: z.literal("air-jam-runtime-owner.agent/v1"),
|
|
167
|
+
requestId: z.string().uuid(),
|
|
168
|
+
request: hostAgentRequestSchema,
|
|
169
|
+
})
|
|
170
|
+
.strict();
|
|
171
|
+
export const runtimeOwnerAgentResultSchema = z.discriminatedUnion("ok", [
|
|
172
|
+
z.object({
|
|
173
|
+
type: z.literal("air-jam-runtime-owner.agent-result/v1"),
|
|
174
|
+
requestId: z.string().uuid(),
|
|
175
|
+
ok: z.literal(true),
|
|
176
|
+
result: hostAgentResponseSchema,
|
|
177
|
+
}),
|
|
178
|
+
z.object({
|
|
179
|
+
type: z.literal("air-jam-runtime-owner.agent-result/v1"),
|
|
180
|
+
requestId: z.string().uuid(),
|
|
181
|
+
ok: z.literal(false),
|
|
182
|
+
error: z.string(),
|
|
183
|
+
}),
|
|
184
|
+
]);
|
|
185
|
+
|
|
186
|
+
export const runtimeOwnerWatchRequestSchema = z.discriminatedUnion("surface", [
|
|
187
|
+
z
|
|
188
|
+
.object({
|
|
189
|
+
type: z.literal("air-jam-runtime-owner.watch/v1"),
|
|
190
|
+
watchId: z.uuid(),
|
|
191
|
+
surface: z.literal("host"),
|
|
192
|
+
})
|
|
193
|
+
.strict(),
|
|
194
|
+
z
|
|
195
|
+
.object({
|
|
196
|
+
type: z.literal("air-jam-runtime-owner.watch/v1"),
|
|
197
|
+
watchId: z.uuid(),
|
|
198
|
+
surface: z.literal("controller"),
|
|
199
|
+
...runtimeOwnerObservedControllerSchema.shape,
|
|
200
|
+
})
|
|
201
|
+
.strict(),
|
|
202
|
+
]);
|
|
203
|
+
export const runtimeOwnerWatchStopSchema = z
|
|
204
|
+
.object({
|
|
205
|
+
type: z.literal("air-jam-runtime-owner.watch-stop/v1"),
|
|
206
|
+
watchId: z.uuid(),
|
|
207
|
+
})
|
|
208
|
+
.strict();
|
|
209
|
+
export const runtimeOwnerWatchEventSchema = z
|
|
210
|
+
.object({
|
|
211
|
+
type: z.literal("air-jam-runtime-owner.watch-event/v1"),
|
|
212
|
+
watchId: z.uuid(),
|
|
213
|
+
event: z.union([
|
|
214
|
+
gameSurfaceWatchEventSchema,
|
|
215
|
+
z.object({ type: z.literal("closed") }).strict(),
|
|
216
|
+
]),
|
|
217
|
+
})
|
|
218
|
+
.strict();
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/** Source identity also defines the files preserved by Studio recovery. */
|
|
2
|
+
export const SOURCE_EXCLUDES = [
|
|
3
|
+
"node_modules/",
|
|
4
|
+
".airjam/logs/",
|
|
5
|
+
".airjam/devtools/",
|
|
6
|
+
".airjam/artifacts/",
|
|
7
|
+
".airjam/releases/",
|
|
8
|
+
".airjam/auth/",
|
|
9
|
+
".airjam/preview-managed-server.json",
|
|
10
|
+
".airjam/release-manifest.json",
|
|
11
|
+
"/dist",
|
|
12
|
+
"/build",
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
/** Source evidence archives carry the full source tree manifest under this name. */
|
|
16
|
+
export const SOURCE_ARCHIVE_MANIFEST = ".airjam-source.json";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Large static assets (models, audio, video, images, fonts) are recorded in
|
|
20
|
+
* source evidence by size and digest only, so asset-heavy games fit the
|
|
21
|
+
* evidence limit; the manifest keeps every omitted asset pinned.
|
|
22
|
+
*/
|
|
23
|
+
export const isDigestOnlySourceFile = (entry: { path: string; size: number }) =>
|
|
24
|
+
entry.size >= 256 * 1024 &&
|
|
25
|
+
/\.(glb|gltf|bin|fbx|obj|png|jpe?g|webp|gif|avif|ktx2|basis|hdr|exr|mp3|ogg|wav|m4a|aac|flac|mp4|webm|woff2?|ttf|otf)$/i.test(
|
|
26
|
+
entry.path,
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
// Portable so a fresh container can fingerprint before installing game packages.
|
|
30
|
+
// With "fold" it reads a manifest's entries from stdin and prints their hash,
|
|
31
|
+
// so an archive that omits assets can still be checked against its source hash.
|
|
32
|
+
export const SOURCE_TREE_PROGRAM = `
|
|
33
|
+
const { createHash } = require('node:crypto');
|
|
34
|
+
const fs = require('node:fs');
|
|
35
|
+
const path = require('node:path');
|
|
36
|
+
const excluded = ${JSON.stringify(SOURCE_EXCLUDES)}.map(value => value.replace(/^\\/|\\/$/g, ''));
|
|
37
|
+
function walk(directory, entries, relative = '') {
|
|
38
|
+
for (const name of fs.readdirSync(directory).sort()) {
|
|
39
|
+
const filename = relative ? relative + '/' + name : name;
|
|
40
|
+
if (excluded.some(value => filename === value || filename.startsWith(value + '/') || (value === 'node_modules' && name === value))) continue;
|
|
41
|
+
const absolute = path.join(directory, name);
|
|
42
|
+
const stat = fs.lstatSync(absolute);
|
|
43
|
+
const mode = stat.mode & 511;
|
|
44
|
+
if (stat.isDirectory()) {
|
|
45
|
+
entries.push({ path: filename, mode, kind: 'directory' });
|
|
46
|
+
walk(absolute, entries, filename);
|
|
47
|
+
} else if (stat.isSymbolicLink())
|
|
48
|
+
entries.push({ path: filename, mode, kind: 'link', target: fs.readlinkSync(absolute) });
|
|
49
|
+
else if (stat.isFile())
|
|
50
|
+
entries.push({ path: filename, mode, kind: 'file', size: stat.size, sha256: createHash('sha256').update(fs.readFileSync(absolute)).digest('hex') });
|
|
51
|
+
else throw new Error('Unsupported source entry: ' + filename);
|
|
52
|
+
}
|
|
53
|
+
return entries;
|
|
54
|
+
}
|
|
55
|
+
function fold(entries) {
|
|
56
|
+
const hash = createHash('sha256');
|
|
57
|
+
for (const entry of entries) {
|
|
58
|
+
hash.update(JSON.stringify([entry.path, entry.mode, entry.kind]));
|
|
59
|
+
if (entry.kind === 'link') hash.update(entry.target);
|
|
60
|
+
else if (entry.kind === 'file') hash.update(Buffer.from(entry.sha256, 'hex'));
|
|
61
|
+
}
|
|
62
|
+
return hash.digest('hex');
|
|
63
|
+
}
|
|
64
|
+
if (process.argv[2] === 'fold') process.stdout.write(fold(JSON.parse(fs.readFileSync(0, 'utf8')).entries));
|
|
65
|
+
else {
|
|
66
|
+
const entries = walk(process.argv[1], []);
|
|
67
|
+
const result = { hash: fold(entries), entries };
|
|
68
|
+
process.stdout.write(process.argv[2] === 'manifest' ? JSON.stringify(result) : result.hash);
|
|
69
|
+
}
|
|
70
|
+
`;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { chmod, copyFile, mkdir, symlink } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { SOURCE_TREE_PROGRAM } from "./source-tree-contract.js";
|
|
7
|
+
|
|
8
|
+
const entry = z.object({
|
|
9
|
+
path: z.string().min(1),
|
|
10
|
+
mode: z.number().int().min(0).max(511),
|
|
11
|
+
});
|
|
12
|
+
export const sourceTreeSchema = z.object({
|
|
13
|
+
hash: z.string().regex(/^[a-f0-9]{64}$/),
|
|
14
|
+
entries: z
|
|
15
|
+
.array(
|
|
16
|
+
z.discriminatedUnion("kind", [
|
|
17
|
+
entry.extend({ kind: z.literal("directory") }),
|
|
18
|
+
entry.extend({ kind: z.literal("link"), target: z.string() }),
|
|
19
|
+
entry.extend({
|
|
20
|
+
kind: z.literal("file"),
|
|
21
|
+
size: z.number().int().nonnegative(),
|
|
22
|
+
sha256: z.string().regex(/^[a-f0-9]{64}$/),
|
|
23
|
+
}),
|
|
24
|
+
]),
|
|
25
|
+
)
|
|
26
|
+
.max(100_000),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export async function readSourceTree(directory: string) {
|
|
30
|
+
const result = await promisify(execFile)(
|
|
31
|
+
process.execPath,
|
|
32
|
+
["-e", SOURCE_TREE_PROGRAM, directory, "manifest"],
|
|
33
|
+
{ maxBuffer: 32 * 1024 * 1024 },
|
|
34
|
+
);
|
|
35
|
+
return sourceTreeSchema.parse(JSON.parse(result.stdout));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** A copy is accepted only when it matches both reads of the original tree. */
|
|
39
|
+
export async function copySourceTree(source: string, destination: string) {
|
|
40
|
+
const before = await readSourceTree(source);
|
|
41
|
+
const bytes = before.entries.reduce(
|
|
42
|
+
(total, entry) => total + (entry.kind === "file" ? entry.size : 0),
|
|
43
|
+
0,
|
|
44
|
+
);
|
|
45
|
+
if (bytes > 512 * 1024 * 1024)
|
|
46
|
+
throw new Error(
|
|
47
|
+
"build_source_too_large: Source exceeds the 512 MiB build limit.",
|
|
48
|
+
);
|
|
49
|
+
await mkdir(destination, { recursive: true });
|
|
50
|
+
for (const entry of before.entries) {
|
|
51
|
+
const target = path.join(destination, entry.path);
|
|
52
|
+
if (entry.kind === "directory") await mkdir(target);
|
|
53
|
+
else if (entry.kind === "link") {
|
|
54
|
+
const relative = path.relative(
|
|
55
|
+
source,
|
|
56
|
+
path.resolve(path.dirname(path.join(source, entry.path)), entry.target),
|
|
57
|
+
);
|
|
58
|
+
if (
|
|
59
|
+
path.isAbsolute(entry.target) ||
|
|
60
|
+
relative === ".." ||
|
|
61
|
+
relative.startsWith(`..${path.sep}`)
|
|
62
|
+
)
|
|
63
|
+
throw new Error(
|
|
64
|
+
`build_external_link: Source link escapes the project: ${entry.path}`,
|
|
65
|
+
);
|
|
66
|
+
await symlink(entry.target, target);
|
|
67
|
+
} else {
|
|
68
|
+
await copyFile(path.join(source, entry.path), target);
|
|
69
|
+
await chmod(target, entry.mode);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
for (const entry of [...before.entries].reverse())
|
|
73
|
+
if (entry.kind === "directory")
|
|
74
|
+
await chmod(path.join(destination, entry.path), entry.mode);
|
|
75
|
+
const [original, copied] = await Promise.all([
|
|
76
|
+
readSourceTree(source),
|
|
77
|
+
readSourceTree(destination),
|
|
78
|
+
]);
|
|
79
|
+
if (before.hash !== original.hash || before.hash !== copied.hash)
|
|
80
|
+
throw new Error(
|
|
81
|
+
"build_source_changed: Source changed while materializing the build.",
|
|
82
|
+
);
|
|
83
|
+
return copied;
|
|
84
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import type { z } from "zod";
|
|
3
|
+
import { startHelperChannel } from "./helper-channel.js";
|
|
4
|
+
import {
|
|
5
|
+
closeAfterProcessFailure,
|
|
6
|
+
type ProcessScopeObserver,
|
|
7
|
+
} from "./managed-process-scope.js";
|
|
8
|
+
import type { policyArtifactReceiptSchema } from "./policy-artifact-contract.js";
|
|
9
|
+
import {
|
|
10
|
+
TEST_PROFILE_IPC_MAX_BYTES,
|
|
11
|
+
testProfileRequestSchema,
|
|
12
|
+
testProfileResponseSchema,
|
|
13
|
+
type TestProfileRequest,
|
|
14
|
+
} from "./test-profile-protocol.js";
|
|
15
|
+
import type {
|
|
16
|
+
AirJamPolicyDecision,
|
|
17
|
+
AirJamPolicyStep,
|
|
18
|
+
AirJamScenarioSample,
|
|
19
|
+
AirJamScenarioVerdict,
|
|
20
|
+
AirJamTestProfileDescription,
|
|
21
|
+
policyPreparationSchema,
|
|
22
|
+
} from "./testing.js";
|
|
23
|
+
|
|
24
|
+
export async function startTestProfileProcess({
|
|
25
|
+
rootDir,
|
|
26
|
+
configPath,
|
|
27
|
+
profileId,
|
|
28
|
+
runKind = "test",
|
|
29
|
+
policyId,
|
|
30
|
+
seed,
|
|
31
|
+
logPath,
|
|
32
|
+
role,
|
|
33
|
+
toolingRootDir,
|
|
34
|
+
onScope,
|
|
35
|
+
startupSignal,
|
|
36
|
+
initializationDeadline,
|
|
37
|
+
artifacts,
|
|
38
|
+
}: {
|
|
39
|
+
rootDir: string;
|
|
40
|
+
toolingRootDir?: string;
|
|
41
|
+
onScope?: ProcessScopeObserver;
|
|
42
|
+
startupSignal?: AbortSignal;
|
|
43
|
+
initializationDeadline?: number;
|
|
44
|
+
artifacts?: {
|
|
45
|
+
directory: string;
|
|
46
|
+
receipt: z.infer<typeof policyArtifactReceiptSchema>;
|
|
47
|
+
};
|
|
48
|
+
configPath: string;
|
|
49
|
+
runKind?: "test" | "play";
|
|
50
|
+
profileId?: string;
|
|
51
|
+
policyId?: string;
|
|
52
|
+
seed: number;
|
|
53
|
+
logPath: string;
|
|
54
|
+
role: "discover" | "policy" | "evaluator";
|
|
55
|
+
}): Promise<{
|
|
56
|
+
profiles: AirJamTestProfileDescription[];
|
|
57
|
+
preparation: z.infer<typeof policyPreparationSchema>;
|
|
58
|
+
decide: (
|
|
59
|
+
step: AirJamPolicyStep,
|
|
60
|
+
timeoutMs: number,
|
|
61
|
+
) => Promise<AirJamPolicyDecision>;
|
|
62
|
+
evaluate: (
|
|
63
|
+
sample: AirJamScenarioSample,
|
|
64
|
+
timeoutMs: number,
|
|
65
|
+
) => Promise<AirJamScenarioVerdict>;
|
|
66
|
+
busy: () => boolean;
|
|
67
|
+
stop: () => Promise<void>;
|
|
68
|
+
}> {
|
|
69
|
+
startupSignal?.throwIfAborted();
|
|
70
|
+
if (role !== "policy" && initializationDeadline !== undefined)
|
|
71
|
+
throw new Error("Only a policy can use the run's initialization deadline.");
|
|
72
|
+
if (role !== "policy" && artifacts !== undefined)
|
|
73
|
+
throw new Error("Only a policy can receive model artifacts.");
|
|
74
|
+
const channel = await startHelperChannel({
|
|
75
|
+
name: "policy",
|
|
76
|
+
helper: "run-test-profile.ts",
|
|
77
|
+
rootDir,
|
|
78
|
+
toolingRootDir,
|
|
79
|
+
onScope,
|
|
80
|
+
startupSignal,
|
|
81
|
+
logPath,
|
|
82
|
+
maxBytes: TEST_PROFILE_IPC_MAX_BYTES,
|
|
83
|
+
requestSchema: testProfileRequestSchema,
|
|
84
|
+
responseSchema: testProfileResponseSchema,
|
|
85
|
+
});
|
|
86
|
+
const request = (input: TestProfileRequest, timeoutMs: number) =>
|
|
87
|
+
channel.request(input, timeoutMs);
|
|
88
|
+
try {
|
|
89
|
+
const initialized = await request(
|
|
90
|
+
{
|
|
91
|
+
kind: "initialize",
|
|
92
|
+
id: randomUUID(),
|
|
93
|
+
rootDir,
|
|
94
|
+
configPath,
|
|
95
|
+
profileId,
|
|
96
|
+
runKind,
|
|
97
|
+
policyId,
|
|
98
|
+
seed,
|
|
99
|
+
role,
|
|
100
|
+
...(artifacts ? { artifacts } : {}),
|
|
101
|
+
},
|
|
102
|
+
initializationDeadline === undefined
|
|
103
|
+
? 10_000
|
|
104
|
+
: Math.max(1, initializationDeadline - performance.now()),
|
|
105
|
+
);
|
|
106
|
+
if (initialized.kind !== "initialized")
|
|
107
|
+
throw new Error(
|
|
108
|
+
initialized.kind === "error"
|
|
109
|
+
? initialized.message
|
|
110
|
+
: "Invalid policy initialization response.",
|
|
111
|
+
);
|
|
112
|
+
return {
|
|
113
|
+
profiles: initialized.profiles,
|
|
114
|
+
preparation: initialized.preparation,
|
|
115
|
+
busy: channel.busy,
|
|
116
|
+
async decide(step: AirJamPolicyStep, timeoutMs: number) {
|
|
117
|
+
if (role !== "policy")
|
|
118
|
+
throw new Error("Only a policy process can decide.");
|
|
119
|
+
const result = await request(
|
|
120
|
+
{ kind: "decide", id: randomUUID(), step },
|
|
121
|
+
timeoutMs,
|
|
122
|
+
);
|
|
123
|
+
if (result.kind !== "decision")
|
|
124
|
+
throw new Error(
|
|
125
|
+
result.kind === "error"
|
|
126
|
+
? result.message
|
|
127
|
+
: "Invalid policy decision response.",
|
|
128
|
+
);
|
|
129
|
+
return result.decision;
|
|
130
|
+
},
|
|
131
|
+
async evaluate(sample: AirJamScenarioSample, timeoutMs: number) {
|
|
132
|
+
if (role !== "evaluator")
|
|
133
|
+
throw new Error("Only an evaluator process can judge.");
|
|
134
|
+
const result = await request(
|
|
135
|
+
{ kind: "evaluate", id: randomUUID(), sample },
|
|
136
|
+
timeoutMs,
|
|
137
|
+
);
|
|
138
|
+
if (result.kind !== "evaluation")
|
|
139
|
+
throw new Error(
|
|
140
|
+
result.kind === "error"
|
|
141
|
+
? result.message
|
|
142
|
+
: "Invalid scenario evaluation response.",
|
|
143
|
+
);
|
|
144
|
+
return result.verdict;
|
|
145
|
+
},
|
|
146
|
+
stop: channel.stop,
|
|
147
|
+
};
|
|
148
|
+
} catch (error) {
|
|
149
|
+
return closeAfterProcessFailure(channel.stop, error);
|
|
150
|
+
} finally {
|
|
151
|
+
channel.started();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { hostObservationSchema } from "@air-jam/sdk/runtime-control";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { seatIntentSchema } from "./game-run-protocol.js";
|
|
4
|
+
import { policyArtifactReceiptSchema } from "./policy-artifact-contract.js";
|
|
5
|
+
import {
|
|
6
|
+
airJamPolicyDecisionSchema,
|
|
7
|
+
airJamRunReceiptSchema,
|
|
8
|
+
airJamScenarioVerdictSchema,
|
|
9
|
+
airJamTestProfileDescriptionSchema,
|
|
10
|
+
policyPreparationSchema,
|
|
11
|
+
} from "./testing.js";
|
|
12
|
+
|
|
13
|
+
const step = z
|
|
14
|
+
.object({
|
|
15
|
+
observation: hostObservationSchema,
|
|
16
|
+
seatId: z.string(),
|
|
17
|
+
intent: seatIntentSchema.nullable(),
|
|
18
|
+
answer: z
|
|
19
|
+
.object({ choice: z.string(), confidence: z.number() })
|
|
20
|
+
.strict()
|
|
21
|
+
.nullable(),
|
|
22
|
+
step: z.number().int().nonnegative(),
|
|
23
|
+
elapsedMs: z.number().nonnegative(),
|
|
24
|
+
receipts: z.array(airJamRunReceiptSchema).max(128),
|
|
25
|
+
})
|
|
26
|
+
.strict();
|
|
27
|
+
export const testProfileRequestSchema = z.discriminatedUnion("kind", [
|
|
28
|
+
z
|
|
29
|
+
.object({
|
|
30
|
+
kind: z.literal("initialize"),
|
|
31
|
+
id: z.uuid(),
|
|
32
|
+
rootDir: z.string().min(1),
|
|
33
|
+
configPath: z.string().min(1),
|
|
34
|
+
role: z.enum(["discover", "policy", "evaluator"]),
|
|
35
|
+
runKind: z.enum(["test", "play"]).default("test"),
|
|
36
|
+
artifacts: z
|
|
37
|
+
.object({
|
|
38
|
+
directory: z.string().min(1),
|
|
39
|
+
receipt: policyArtifactReceiptSchema,
|
|
40
|
+
})
|
|
41
|
+
.strict()
|
|
42
|
+
.optional(),
|
|
43
|
+
profileId: z.string().optional(),
|
|
44
|
+
policyId: z.string().optional(),
|
|
45
|
+
seed: z.number().int().min(0).max(0xffff_ffff),
|
|
46
|
+
})
|
|
47
|
+
.strict(),
|
|
48
|
+
z.object({ kind: z.literal("decide"), id: z.uuid(), step }).strict(),
|
|
49
|
+
z
|
|
50
|
+
.object({
|
|
51
|
+
kind: z.literal("evaluate"),
|
|
52
|
+
id: z.uuid(),
|
|
53
|
+
sample: z
|
|
54
|
+
.object({
|
|
55
|
+
phase: z.enum(["play", "final"]),
|
|
56
|
+
observation: hostObservationSchema,
|
|
57
|
+
seats: z
|
|
58
|
+
.array(
|
|
59
|
+
z
|
|
60
|
+
.object({ seatId: z.string(), controllerId: z.string() })
|
|
61
|
+
.strict(),
|
|
62
|
+
)
|
|
63
|
+
.min(1)
|
|
64
|
+
.max(8),
|
|
65
|
+
elapsedMs: z.number().nonnegative(),
|
|
66
|
+
receipts: z.array(airJamRunReceiptSchema).max(128),
|
|
67
|
+
})
|
|
68
|
+
.strict(),
|
|
69
|
+
})
|
|
70
|
+
.strict(),
|
|
71
|
+
]);
|
|
72
|
+
export type TestProfileRequest = z.infer<typeof testProfileRequestSchema>;
|
|
73
|
+
export const testProfileResponseSchema = z.discriminatedUnion("kind", [
|
|
74
|
+
z.object({ kind: z.literal("ready") }).strict(),
|
|
75
|
+
z
|
|
76
|
+
.object({
|
|
77
|
+
kind: z.literal("initialized"),
|
|
78
|
+
id: z.uuid(),
|
|
79
|
+
profiles: z.array(airJamTestProfileDescriptionSchema),
|
|
80
|
+
preparation: policyPreparationSchema,
|
|
81
|
+
})
|
|
82
|
+
.strict(),
|
|
83
|
+
z
|
|
84
|
+
.object({
|
|
85
|
+
kind: z.literal("decision"),
|
|
86
|
+
id: z.uuid(),
|
|
87
|
+
decision: airJamPolicyDecisionSchema,
|
|
88
|
+
})
|
|
89
|
+
.strict(),
|
|
90
|
+
z
|
|
91
|
+
.object({
|
|
92
|
+
kind: z.literal("evaluation"),
|
|
93
|
+
id: z.uuid(),
|
|
94
|
+
verdict: airJamScenarioVerdictSchema,
|
|
95
|
+
})
|
|
96
|
+
.strict(),
|
|
97
|
+
z
|
|
98
|
+
.object({
|
|
99
|
+
kind: z.literal("error"),
|
|
100
|
+
id: z.uuid(),
|
|
101
|
+
message: z.string().max(2000),
|
|
102
|
+
})
|
|
103
|
+
.strict(),
|
|
104
|
+
]);
|
|
105
|
+
export type TestProfileResponse = z.infer<typeof testProfileResponseSchema>;
|
|
106
|
+
export const TEST_PROFILE_IPC_MAX_BYTES = 1_500_000;
|
|
107
|
+
|
|
108
|
+
export function createPolicyRandom(seed: number) {
|
|
109
|
+
let state = seed >>> 0;
|
|
110
|
+
return () => {
|
|
111
|
+
state = (state + 0x6d2b79f5) | 0;
|
|
112
|
+
let value = Math.imul(state ^ (state >>> 15), 1 | state);
|
|
113
|
+
value ^= value + Math.imul(value ^ (value >>> 7), 61 | value);
|
|
114
|
+
return ((value ^ (value >>> 14)) >>> 0) / 0x1_0000_0000;
|
|
115
|
+
};
|
|
116
|
+
}
|