@air-jam/devtools 0.9.3 → 1.0.0-beta.10

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 (263) hide show
  1. package/README.md +60 -0
  2. package/dist/{chunk-VKMJO6VN.js → chunk-2O67AXCU.js} +150 -40
  3. package/dist/chunk-2O67AXCU.js.map +1 -0
  4. package/dist/chunk-AO3ZDXF6.js +142 -0
  5. package/dist/chunk-AO3ZDXF6.js.map +1 -0
  6. package/dist/chunk-ART5TEYT.js +472 -0
  7. package/dist/chunk-ART5TEYT.js.map +1 -0
  8. package/dist/chunk-ASC2CK2R.js +77 -0
  9. package/dist/chunk-ASC2CK2R.js.map +1 -0
  10. package/dist/chunk-E3UZZGAV.js +50 -0
  11. package/dist/chunk-E3UZZGAV.js.map +1 -0
  12. package/dist/chunk-EJTE7UKX.js +64 -0
  13. package/dist/chunk-EJTE7UKX.js.map +1 -0
  14. package/dist/chunk-ESFKNN75.js +110 -0
  15. package/dist/chunk-ESFKNN75.js.map +1 -0
  16. package/dist/chunk-EU7A6PXW.js +1339 -0
  17. package/dist/chunk-EU7A6PXW.js.map +1 -0
  18. package/dist/chunk-FN7E6EA7.js +549 -0
  19. package/dist/chunk-FN7E6EA7.js.map +1 -0
  20. package/dist/chunk-GDFAWHGA.js +190 -0
  21. package/dist/chunk-GDFAWHGA.js.map +1 -0
  22. package/dist/chunk-HZUGBH4Y.js +347 -0
  23. package/dist/chunk-HZUGBH4Y.js.map +1 -0
  24. package/dist/chunk-ITKAOEGX.js +93 -0
  25. package/dist/chunk-ITKAOEGX.js.map +1 -0
  26. package/dist/chunk-JBCUTWRI.js +897 -0
  27. package/dist/chunk-JBCUTWRI.js.map +1 -0
  28. package/dist/chunk-JSI5S4WP.js +1174 -0
  29. package/dist/chunk-JSI5S4WP.js.map +1 -0
  30. package/dist/chunk-L4D675BG.js +97 -0
  31. package/dist/chunk-L4D675BG.js.map +1 -0
  32. package/dist/{chunk-GUEZP773.js → chunk-LB3Y64P5.js} +206 -60
  33. package/dist/chunk-LB3Y64P5.js.map +1 -0
  34. package/dist/chunk-M6CJ7GQC.js +133 -0
  35. package/dist/chunk-M6CJ7GQC.js.map +1 -0
  36. package/dist/{chunk-CKFT2ZJE.js → chunk-MEIMOSZC.js} +53 -105
  37. package/dist/chunk-MEIMOSZC.js.map +1 -0
  38. package/dist/chunk-OM6SCJ7H.js +18 -0
  39. package/dist/chunk-OM6SCJ7H.js.map +1 -0
  40. package/dist/chunk-PKD4WVX5.js +63 -0
  41. package/dist/chunk-PKD4WVX5.js.map +1 -0
  42. package/dist/chunk-PMBLXGFM.js +3384 -0
  43. package/dist/chunk-PMBLXGFM.js.map +1 -0
  44. package/dist/chunk-PMNE5GIN.js +279 -0
  45. package/dist/chunk-PMNE5GIN.js.map +1 -0
  46. package/dist/chunk-QAWI64VR.js +148 -0
  47. package/dist/chunk-QAWI64VR.js.map +1 -0
  48. package/dist/chunk-QGADSPHZ.js +449 -0
  49. package/dist/chunk-QGADSPHZ.js.map +1 -0
  50. package/dist/chunk-SPYN66UV.js +338 -0
  51. package/dist/chunk-SPYN66UV.js.map +1 -0
  52. package/dist/context.d.ts +9 -3
  53. package/dist/context.js +2 -1
  54. package/dist/controller.d.ts +33 -7
  55. package/dist/controller.js +18 -8
  56. package/dist/dependencies.d.ts +44 -0
  57. package/dist/dependencies.js +10 -0
  58. package/dist/dev.d.ts +9 -3
  59. package/dist/dev.js +3 -4
  60. package/dist/game-builds.d.ts +200 -0
  61. package/dist/game-builds.js +16 -0
  62. package/dist/game-builds.js.map +1 -0
  63. package/dist/game-run-watch-CEd_SpAT.d.ts +84 -0
  64. package/dist/game-runs.d.ts +1452 -0
  65. package/dist/game-runs.js +76 -0
  66. package/dist/game-runs.js.map +1 -0
  67. package/dist/game-session-broker-CUvORfMd.d.ts +439 -0
  68. package/dist/game-session-broker.d.ts +4 -57
  69. package/dist/game-session-broker.js +33 -228
  70. package/dist/game-session-broker.js.map +1 -1
  71. package/dist/game-session.d.ts +3931 -10
  72. package/dist/game-session.js +186 -15
  73. package/dist/game-session.js.map +1 -1
  74. package/dist/game-settings.d.ts +16 -0
  75. package/dist/game-settings.js +237 -0
  76. package/dist/game-settings.js.map +1 -0
  77. package/dist/games.d.ts +11 -4
  78. package/dist/games.js +4 -2
  79. package/dist/harness/visual.d.ts +34 -151
  80. package/dist/harness/visual.js +6 -1
  81. package/dist/logs.d.ts +8 -2
  82. package/dist/logs.js +3 -4
  83. package/dist/logs.js.map +1 -1
  84. package/dist/managed-process-scope-BicYi_t9.d.ts +3 -0
  85. package/dist/mcp-config.js +2 -1
  86. package/dist/mcp-config.js.map +1 -1
  87. package/dist/platform-auth.d.ts +8 -111
  88. package/dist/platform-auth.js +9 -1
  89. package/dist/platform-game-analytics.d.ts +51 -0
  90. package/dist/platform-game-analytics.js +49 -0
  91. package/dist/platform-game-analytics.js.map +1 -0
  92. package/dist/platform-game-app-id.d.ts +46 -0
  93. package/dist/platform-game-app-id.js +93 -0
  94. package/dist/platform-game-app-id.js.map +1 -0
  95. package/dist/platform-game-media.d.ts +40 -2
  96. package/dist/platform-game-media.js +1 -1
  97. package/dist/platform-games.d.ts +24 -2
  98. package/dist/platform-games.js +16 -84
  99. package/dist/platform-games.js.map +1 -1
  100. package/dist/quality.d.ts +9 -3
  101. package/dist/quality.js +3 -4
  102. package/dist/quality.js.map +1 -1
  103. package/dist/release.d.ts +226 -16
  104. package/dist/release.js +18 -1331
  105. package/dist/release.js.map +1 -1
  106. package/dist/rooms-check.d.ts +90 -0
  107. package/dist/rooms-check.js +717 -0
  108. package/dist/rooms-check.js.map +1 -0
  109. package/dist/source-tree-contract.d.ts +16 -0
  110. package/dist/source-tree-contract.js +13 -0
  111. package/dist/source-tree-contract.js.map +1 -0
  112. package/dist/testing.d.ts +464 -0
  113. package/dist/testing.js +27 -0
  114. package/dist/testing.js.map +1 -0
  115. package/dist/tooling/describe-game.js +54 -0
  116. package/dist/tooling/describe-game.js.map +1 -0
  117. package/dist/tooling/game-session-broker.js +28 -0
  118. package/dist/tooling/game-session-broker.js.map +1 -0
  119. package/dist/tooling/hold-runtime-host.js +770 -68
  120. package/dist/tooling/hold-runtime-host.js.map +1 -1
  121. package/dist/tooling/list-visual-scenarios.js +18 -55
  122. package/dist/tooling/list-visual-scenarios.js.map +1 -1
  123. package/dist/tooling/process-scope-bootstrap.mjs +24 -0
  124. package/dist/tooling/process-scope-guard.d.ts +2 -0
  125. package/dist/tooling/process-scope-guard.js +388 -0
  126. package/dist/tooling/process-scope-guard.js.map +1 -0
  127. package/dist/tooling/process-scope-windows.ps1 +148 -0
  128. package/dist/tooling/rooms-check-device.d.ts +2 -0
  129. package/dist/tooling/rooms-check-device.js +498 -0
  130. package/dist/tooling/rooms-check-device.js.map +1 -0
  131. package/dist/tooling/run-headless-room.d.ts +2 -0
  132. package/dist/tooling/run-headless-room.js +288 -0
  133. package/dist/tooling/run-headless-room.js.map +1 -0
  134. package/dist/tooling/run-test-profile.d.ts +2 -0
  135. package/dist/tooling/run-test-profile.js +181 -0
  136. package/dist/tooling/run-test-profile.js.map +1 -0
  137. package/dist/tooling/run-visual-capture.js +70 -34
  138. package/dist/tooling/run-visual-capture.js.map +1 -1
  139. package/dist/tooling/seal-game-build.d.ts +2 -0
  140. package/dist/tooling/seal-game-build.js +120 -0
  141. package/dist/tooling/seal-game-build.js.map +1 -0
  142. package/dist/{types-C6NrHt88.d.ts → types-CdYrgrG_.d.ts} +337 -76
  143. package/dist/types-DyRD-ym1.d.ts +141 -0
  144. package/dist/visual.d.ts +9 -3
  145. package/dist/visual.js +24 -68
  146. package/dist/visual.js.map +1 -1
  147. package/package.json +51 -14
  148. package/src/bounded-response.ts +28 -0
  149. package/src/built-game-runtime.ts +152 -0
  150. package/src/context.ts +2 -13
  151. package/src/controller-protocol.ts +22 -0
  152. package/src/controller.ts +747 -597
  153. package/src/current-room-host.ts +166 -0
  154. package/src/decision-provider.ts +102 -0
  155. package/src/dependencies.ts +176 -0
  156. package/src/dependency-install-contract.ts +12 -0
  157. package/src/dev.ts +46 -50
  158. package/src/game-action-observation.ts +11 -1
  159. package/src/game-build-protocol.ts +72 -0
  160. package/src/game-build.ts +483 -0
  161. package/src/game-run-owner.ts +2358 -0
  162. package/src/game-run-protocol.ts +448 -0
  163. package/src/game-run-record.ts +92 -0
  164. package/src/game-run-replay.ts +95 -0
  165. package/src/game-run-watch.ts +155 -0
  166. package/src/game-session-broker.ts +689 -197
  167. package/src/game-session-operations.ts +61 -0
  168. package/src/game-session-protocol.ts +180 -0
  169. package/src/game-session-runtime.ts +861 -0
  170. package/src/game-session.ts +164 -417
  171. package/src/game-settings.ts +295 -0
  172. package/src/games.ts +88 -92
  173. package/src/harness/visual/browser.ts +100 -0
  174. package/src/harness/visual/controller-observation.ts +181 -0
  175. package/src/harness/visual/runner.ts +24 -21
  176. package/src/harness/visual/runtime-controller-observations.ts +151 -0
  177. package/src/harness/visual/scenario-contract.ts +1 -2
  178. package/src/harness/visual/scenario-helpers.ts +5 -1
  179. package/src/harness/visual/screencast.ts +155 -0
  180. package/src/harness/visual/session.ts +74 -69
  181. package/src/harness/visual/types.ts +8 -5
  182. package/src/headless-room-protocol.ts +112 -0
  183. package/src/headless-room.ts +222 -0
  184. package/src/helper-channel.ts +229 -0
  185. package/src/helper-scripts.ts +25 -5
  186. package/src/installed-dependencies.ts +74 -0
  187. package/src/managed-process-scope.ts +481 -0
  188. package/src/node-process-environment.ts +10 -0
  189. package/src/platform-auth.ts +194 -55
  190. package/src/platform-game-analytics.ts +50 -0
  191. package/src/platform-game-app-id.ts +99 -0
  192. package/src/platform-games.ts +13 -111
  193. package/src/policy-artifact-contract.ts +52 -0
  194. package/src/policy-artifacts.ts +134 -0
  195. package/src/process-scope-admission.ts +50 -0
  196. package/src/process-scope-protocol.ts +66 -0
  197. package/src/process-scope.ts +327 -0
  198. package/src/release.ts +28 -42
  199. package/src/rooms-check-fleet.ts +194 -0
  200. package/src/rooms-check-link.ts +138 -0
  201. package/src/rooms-check-protocol.ts +244 -0
  202. package/src/rooms-check.ts +797 -0
  203. package/src/runtime-owner-protocol.ts +106 -18
  204. package/src/source-tree-contract.ts +70 -0
  205. package/src/source-tree.ts +84 -0
  206. package/src/test-profile-process.ts +153 -0
  207. package/src/test-profile-protocol.ts +116 -0
  208. package/src/testing.ts +430 -0
  209. package/src/tooling/declaration-hook.ts +52 -0
  210. package/src/tooling/describe-game.ts +49 -0
  211. package/src/tooling/game-session-broker.ts +7 -0
  212. package/src/tooling/hold-runtime-host.ts +254 -42
  213. package/src/tooling/list-visual-scenarios.ts +19 -62
  214. package/src/tooling/load-game.ts +79 -0
  215. package/src/tooling/process-scope-bootstrap.mjs +24 -0
  216. package/src/tooling/process-scope-guard.ts +213 -0
  217. package/src/tooling/process-scope-windows.ps1 +148 -0
  218. package/src/tooling/rooms-check-device.ts +493 -0
  219. package/src/tooling/run-headless-room.ts +329 -0
  220. package/src/tooling/run-test-profile.ts +190 -0
  221. package/src/tooling/run-visual-capture.ts +37 -23
  222. package/src/tooling/runtime-owner-actions.ts +23 -0
  223. package/src/tooling/seal-game-build.ts +118 -0
  224. package/src/tooling/visual-pack.ts +10 -45
  225. package/src/types.ts +54 -77
  226. package/src/visual.ts +14 -22
  227. package/src/windows-process-scopes.ts +189 -0
  228. package/dist/agent.d.ts +0 -15
  229. package/dist/agent.js +0 -19
  230. package/dist/chunk-5YAARMW5.js +0 -36
  231. package/dist/chunk-5YAARMW5.js.map +0 -1
  232. package/dist/chunk-6WQODT37.js +0 -1019
  233. package/dist/chunk-6WQODT37.js.map +0 -1
  234. package/dist/chunk-CKFT2ZJE.js.map +0 -1
  235. package/dist/chunk-ER3Q2C4G.js +0 -358
  236. package/dist/chunk-ER3Q2C4G.js.map +0 -1
  237. package/dist/chunk-GUEZP773.js.map +0 -1
  238. package/dist/chunk-HIDNI56E.js +0 -33
  239. package/dist/chunk-HIDNI56E.js.map +0 -1
  240. package/dist/chunk-QKXS5D35.js +0 -43
  241. package/dist/chunk-QKXS5D35.js.map +0 -1
  242. package/dist/chunk-S4LSCEVE.js +0 -261
  243. package/dist/chunk-S4LSCEVE.js.map +0 -1
  244. package/dist/chunk-VKMJO6VN.js.map +0 -1
  245. package/dist/chunk-WFUR3MXY.js +0 -67
  246. package/dist/chunk-WFUR3MXY.js.map +0 -1
  247. package/dist/chunk-XEMR7KUE.js +0 -361
  248. package/dist/chunk-XEMR7KUE.js.map +0 -1
  249. package/dist/chunk-ZLPD7FY5.js +0 -191
  250. package/dist/chunk-ZLPD7FY5.js.map +0 -1
  251. package/dist/tooling/agent-contract.js +0 -193
  252. package/dist/tooling/agent-contract.js.map +0 -1
  253. package/dist/tooling/inspect-airjam-agent.js +0 -37
  254. package/dist/tooling/inspect-airjam-agent.js.map +0 -1
  255. package/src/agent.ts +0 -380
  256. package/src/tooling/agent-contract.ts +0 -232
  257. package/src/tooling/agent-declaration.ts +0 -36
  258. package/src/tooling/airjam-agent-inspection.ts +0 -45
  259. package/src/tooling/airjam-agent.ts +0 -118
  260. package/src/tooling/inspect-airjam-agent.ts +0 -20
  261. /package/dist/{agent.js.map → dependencies.js.map} +0 -0
  262. /package/dist/tooling/{agent-contract.d.ts → describe-game.d.ts} +0 -0
  263. /package/dist/tooling/{inspect-airjam-agent.d.ts → game-session-broker.d.ts} +0 -0
@@ -0,0 +1,448 @@
1
+ import { airJamSettingsValuesSchema } from "@air-jam/sdk/core";
2
+ import { controllerLeasedControlAckSchema } from "@air-jam/sdk/protocol";
3
+ import { seatIdSchema } from "@air-jam/sdk/room-protocol";
4
+ import {
5
+ clipNotCapturedReasonSchema,
6
+ hostAgentRequestSchema,
7
+ hostObservationIdentitySchema,
8
+ hostRuntimeFaultSchema,
9
+ inputLogNotReplayableReasonSchema,
10
+ } from "@air-jam/sdk/runtime-control";
11
+ import { z } from "zod";
12
+ import { controllerDisconnectionSchema } from "./controller-protocol.js";
13
+ import { gameBuildIdentitySchema } from "./game-build-protocol.js";
14
+ import { policyArtifactReceiptSchema } from "./policy-artifact-contract.js";
15
+ import {
16
+ airJamScenarioVerdictSchema,
17
+ airJamTestProfileDescriptionSchema,
18
+ policyPreparationSchema,
19
+ } from "./testing.js";
20
+ export const GAME_RUN_PROTOCOL_VERSION = 5;
21
+ export const MAXIMUM_GAME_RUN_BUILD_LOG_BYTES = 1_048_576;
22
+ export const gameRunBuildLogSchema = z.object({
23
+ path: z.string().min(1),
24
+ sha256: z.string().regex(/^[a-f0-9]{64}$/),
25
+ bytes: z.number().int().nonnegative().max(MAXIMUM_GAME_RUN_BUILD_LOG_BYTES),
26
+ truncated: z.boolean(),
27
+ });
28
+ export type AirJamGameRunBuildLog = z.infer<typeof gameRunBuildLogSchema>;
29
+ export const MAXIMUM_GAME_RUN_MS = 600_000;
30
+ export const MAXIMUM_GAME_RUN_TRACE_BYTES = 16 * 1024 * 1024;
31
+ export const MAXIMUM_GAME_RUN_STEERING_CHANGES = 64;
32
+ export const GAME_SESSION_BROKER_STATE_FILE =
33
+ ".airjam/devtools/game-session-broker.json";
34
+ const attachmentUrlSchema = z
35
+ .url()
36
+ .max(4096)
37
+ .refine((value) => {
38
+ const url = new URL(value);
39
+ return (
40
+ ["http:", "https:"].includes(url.protocol) &&
41
+ !url.username &&
42
+ !url.password
43
+ );
44
+ }, "An attachment requires an HTTP(S) URL without embedded credentials.");
45
+ /** The most players one run can seat in a creator's room. */
46
+ export const MAXIMUM_CURRENT_ROOM_SEATS = 8;
47
+ export const currentRoomAttachmentSchema = z
48
+ .object({
49
+ controllerJoinUrl: attachmentUrlSchema.refine(
50
+ (value) => Boolean(new URL(value).searchParams.get("room")),
51
+ "A controller attachment requires a room.",
52
+ ),
53
+ /**
54
+ * How many seats the run may claim in the creator's room. The room
55
+ * assigns seat ids, so each player joins first and then claims its seat.
56
+ */
57
+ seats: z.number().int().min(1).max(MAXIMUM_CURRENT_ROOM_SEATS),
58
+ host: z
59
+ .object({
60
+ endpoint: attachmentUrlSchema,
61
+ targetId: z.string().min(1).max(128),
62
+ })
63
+ .strict(),
64
+ })
65
+ .strict();
66
+ export type CurrentRoomAttachment = z.infer<typeof currentRoomAttachmentSchema>;
67
+ /** A request to the creator's host, answered through the editor that granted the room. */
68
+ export const currentRoomHostRequestSchema = z
69
+ .object({
70
+ targetId: currentRoomAttachmentSchema.shape.host.shape.targetId,
71
+ ownerInstanceId: z.uuid(),
72
+ request: hostAgentRequestSchema,
73
+ })
74
+ .strict();
75
+
76
+ /**
77
+ * A run's claim on a seat one of its players holds in the creator's room,
78
+ * made through the editor that granted the room. A claim names the room
79
+ * instance, since seat ids are unique only within one.
80
+ */
81
+ export const currentRoomSeatClaimSchema = z
82
+ .object({
83
+ targetId: currentRoomAttachmentSchema.shape.host.shape.targetId,
84
+ ownerInstanceId: z.uuid(),
85
+ claim: z
86
+ .object({ instance: z.string().min(1).max(64), seat: seatIdSchema })
87
+ .strict(),
88
+ })
89
+ .strict();
90
+ export type CurrentRoomSeatClaim = z.infer<
91
+ typeof currentRoomSeatClaimSchema
92
+ >["claim"];
93
+
94
+ /** What a seat is trying to do, in words its decision model reads. */
95
+ export const seatIntentSchema = z.string().trim().min(1).max(500);
96
+ export const steeringSourceSchema = z.enum(["creator", "agent", "operator"]);
97
+
98
+ const gameRunStartBaseSchema = z
99
+ .object({
100
+ cwd: z.string().min(1).optional(),
101
+ runId: z.uuid(),
102
+ gameId: z.string().min(1).optional(),
103
+ target: z.discriminatedUnion("kind", [
104
+ z.object({ kind: z.literal("owned") }).strict(),
105
+ z.object({ kind: z.literal("current") }).strict(),
106
+ /** Plays in a room with no page, on game time, as fast as the host runs. */
107
+ z.object({ kind: z.literal("headless") }).strict(),
108
+ ]),
109
+
110
+ settings: airJamSettingsValuesSchema.optional(),
111
+ seed: z.number().int().min(0).max(0xffff_ffff).default(0),
112
+ })
113
+ .strict();
114
+ export const startTestGameRunSchema = gameRunStartBaseSchema
115
+ .extend({
116
+ kind: z.literal("test").default("test"),
117
+ profileId: z.string().min(1).max(64),
118
+ policyId: z.string().min(1).max(64),
119
+ budget: z
120
+ .object({
121
+ durationMs: z.number().int().min(1000).max(MAXIMUM_GAME_RUN_MS),
122
+ steps: z.number().int().min(1).max(10_000),
123
+ })
124
+ .strict(),
125
+ intents: z.record(z.string().min(1).max(64), seatIntentSchema).optional(),
126
+ })
127
+ .refine(
128
+ (request) =>
129
+ request.settings === undefined || request.target.kind !== "current",
130
+ {
131
+ message:
132
+ "Initial settings require a new owned or headless room; use settings-update for an existing room.",
133
+ path: ["settings"],
134
+ },
135
+ );
136
+ export const startPlayGameRunSchema = gameRunStartBaseSchema
137
+ .omit({ settings: true })
138
+ .extend({
139
+ kind: z.literal("play"),
140
+ target: z.object({ kind: z.literal("current") }).strict(),
141
+ intent: seatIntentSchema.optional(),
142
+ });
143
+ export const startGameRunSchema = z.union([
144
+ startTestGameRunSchema,
145
+ startPlayGameRunSchema,
146
+ ]);
147
+ export type StartGameRunOptions = z.input<typeof startGameRunSchema>;
148
+ export const gameRunAddressSchema = z
149
+ .object({ cwd: z.string().min(1).optional(), runId: z.uuid() })
150
+ .strict();
151
+ export const gameRunSteerSchema = gameRunAddressSchema
152
+ .extend({
153
+ seatId: z.string().min(1).max(64),
154
+ intent: seatIntentSchema.nullable(),
155
+ source: steeringSourceSchema.default("operator"),
156
+ })
157
+ .strict();
158
+ export type GameRunSteerOptions = z.input<typeof gameRunSteerSchema>;
159
+ export const gameRunWaitSchema = gameRunAddressSchema.extend({
160
+ timeoutMs: z.number().int().min(1).max(30_000).default(25_000),
161
+ });
162
+ export const gameRunDiscoverySchema = z
163
+ .object({
164
+ cwd: z.string().min(1).optional(),
165
+ gameId: z.string().min(1).optional(),
166
+ })
167
+ .strict();
168
+
169
+ export const gameRunEndReasonSchema = z.enum([
170
+ "completed",
171
+ "failed",
172
+ "budget",
173
+ "safety_deadline",
174
+ "stopped",
175
+ "owner_stopping",
176
+ "owner_lost",
177
+ "session_expired",
178
+ "runtime_replaced",
179
+ "policy_unresponsive",
180
+ "decision_latency",
181
+ "host_not_advancing",
182
+ "seat_replaced",
183
+ "untested_seat",
184
+ "evaluator_unresponsive",
185
+ "trace_budget",
186
+ "error",
187
+ ]);
188
+ export const gameRunSessionIdentitySchema = z.object({
189
+ gameSessionId: z.uuid(),
190
+ gameId: z.string().nullable(),
191
+ roomId: z.string().min(1),
192
+ controllerId: z.string().min(1),
193
+ semanticAccess: z.enum(["owned-host", "delegated-host", "participant-only"]),
194
+ connected: z.boolean(),
195
+ });
196
+ export const gameRunRecordSchema = z
197
+ .object({
198
+ version: z.literal(1),
199
+ runId: z.uuid(),
200
+ ownerInstanceId: z.uuid(),
201
+ request: startGameRunSchema,
202
+ state: z.enum(["starting", "setup", "playing", "stopping", "ended"]),
203
+ startedAt: z.iso.datetime(),
204
+ endedAt: z.iso.datetime().optional(),
205
+ stopRequestedAt: z.iso.datetime().optional(),
206
+ abortedAt: z.iso.datetime().optional(),
207
+ lastInputAt: z.iso.datetime().optional(),
208
+ releaseAcknowledgedAt: z.iso.datetime().optional(),
209
+ rosterJoinedAt: z.iso.datetime().optional(),
210
+ /** When play began, after setup; play ends at `abortedAt`. */
211
+ playStartedAt: z.iso.datetime().optional(),
212
+ watched: z.literal(true).optional(),
213
+ profile: airJamTestProfileDescriptionSchema.optional(),
214
+ policyPreparation: policyPreparationSchema.optional(),
215
+ policyInitializationMs: z.number().finite().nonnegative().optional(),
216
+ policyArtifacts: policyArtifactReceiptSchema.optional(),
217
+ decisionModel: z.string().min(1).max(200).optional(),
218
+ build: gameBuildIdentitySchema
219
+ .extend({ integrity: z.enum(["sealed", "verified", "changed"]) })
220
+ .optional(),
221
+ session: gameRunSessionIdentitySchema.optional(),
222
+ expected: hostObservationIdentitySchema.optional(),
223
+ seats: z
224
+ .array(
225
+ z
226
+ .object({
227
+ seatId: z.string(),
228
+ controllerId: z.string(),
229
+ expected: hostObservationIdentitySchema.optional(),
230
+ counters: z
231
+ .object({
232
+ decisions: z.number().int().nonnegative(),
233
+ applied: z.number().int().nonnegative(),
234
+ rejected: z.number().int().nonnegative(),
235
+ unconfirmed: z.number().int().nonnegative(),
236
+ timeout: z.number().int().nonnegative(),
237
+ blocked: z.number().int().nonnegative(),
238
+ effects: z.number().int().nonnegative(),
239
+ })
240
+ .strict(),
241
+ intent: seatIntentSchema.nullable().default(null),
242
+ answers: z
243
+ .object({
244
+ asked: z.number().int().nonnegative(),
245
+ answered: z.number().int().nonnegative(),
246
+ automatic: z.number().int().nonnegative().optional(),
247
+ missed: z.number().int().nonnegative(),
248
+ lowConfidence: z.number().int().nonnegative(),
249
+ lowConfidenceStretches: z.number().int().nonnegative(),
250
+ choices: z.record(z.string(), z.number().int().nonnegative()),
251
+ })
252
+ .strict()
253
+ .optional(),
254
+ })
255
+ .strict(),
256
+ )
257
+ .max(8)
258
+ .default([]),
259
+ /** The host's frame rate and simulation speed during play (1 = real time). */
260
+ hostPace: z
261
+ .object({
262
+ framesPerSecond: z.number().nonnegative(),
263
+ simulationSpeed: z.number().nonnegative(),
264
+ })
265
+ .strict()
266
+ .optional(),
267
+ steering: z
268
+ .array(
269
+ z
270
+ .object({
271
+ at: z.iso.datetime(),
272
+ seatId: z.string(),
273
+ intent: seatIntentSchema.nullable(),
274
+ source: steeringSourceSchema,
275
+ })
276
+ .strict(),
277
+ )
278
+ .max(MAXIMUM_GAME_RUN_STEERING_CHANGES)
279
+ .optional(),
280
+ evaluation: z
281
+ .object({
282
+ play: airJamScenarioVerdictSchema.optional(),
283
+ final: airJamScenarioVerdictSchema.optional(),
284
+ })
285
+ .strict()
286
+ .optional(),
287
+ counters: z
288
+ .object({
289
+ steps: z.number().int().nonnegative(),
290
+ applied: z.number().int().nonnegative(),
291
+ rejected: z.number().int().nonnegative(),
292
+ unconfirmed: z.number().int().nonnegative(),
293
+ missed: z.number().int().nonnegative(),
294
+ })
295
+ .strict(),
296
+ end: z
297
+ .object({
298
+ reason: gameRunEndReasonSchema,
299
+ outcome: z.enum(["passed", "failed", "inconclusive"]).optional(),
300
+ message: z.string(),
301
+ hostFault: hostRuntimeFaultSchema.optional(),
302
+ })
303
+ .strict()
304
+ .optional(),
305
+ cleanup: z
306
+ .object({
307
+ participantsClosed: z.boolean(),
308
+ processesClosed: z.boolean().optional(),
309
+ seats: z
310
+ .array(
311
+ z
312
+ .object({
313
+ seatId: z.string(),
314
+ release: controllerLeasedControlAckSchema.optional(),
315
+ disconnection: controllerDisconnectionSchema.optional(),
316
+ })
317
+ .strict(),
318
+ )
319
+ .max(8),
320
+ close: z
321
+ .object({
322
+ closed: z.boolean(),
323
+ disconnection: controllerDisconnectionSchema,
324
+ })
325
+ .strict()
326
+ .optional(),
327
+ forced: z.literal(true).optional(),
328
+ /**
329
+ * Whether a test in the creator's room returned it through its
330
+ * profile's hand-back steps, had none to run, or failed (see errors).
331
+ */
332
+ handBack: z.enum(["returned", "undeclared", "failed"]).optional(),
333
+ errors: z.array(z.string()),
334
+ })
335
+ .strict()
336
+ .optional(),
337
+ evidence: z
338
+ .object({
339
+ clip: z
340
+ .discriminatedUnion("status", [
341
+ z
342
+ .object({
343
+ status: z.literal("captured"),
344
+ path: z.string().min(1),
345
+ sha256: z.string().regex(/^[a-f0-9]{64}$/),
346
+ bytes: z.number().int().positive(),
347
+ frames: z.number().int().min(1).max(150),
348
+ durationMs: z.number().nonnegative(),
349
+ })
350
+ .strict(),
351
+ z
352
+ .object({
353
+ status: z.literal("not-captured"),
354
+ reason: clipNotCapturedReasonSchema,
355
+ })
356
+ .strict(),
357
+ ])
358
+ .optional(),
359
+ buildLog: gameRunBuildLogSchema.optional(),
360
+ trace: z
361
+ .object({
362
+ path: z.string().min(1),
363
+ sha256: z.string().regex(/^[a-f0-9]{64}$/),
364
+ bytes: z
365
+ .number()
366
+ .int()
367
+ .nonnegative()
368
+ .max(MAXIMUM_GAME_RUN_TRACE_BYTES),
369
+ truncated: z.boolean(),
370
+ })
371
+ .strict()
372
+ .optional(),
373
+ observation: z
374
+ .object({
375
+ path: z.string().min(1),
376
+ sha256: z.string().regex(/^[a-f0-9]{64}$/),
377
+ })
378
+ .strict()
379
+ .nullable(),
380
+ replay: z
381
+ .object({
382
+ reason: inputLogNotReplayableReasonSchema,
383
+ message: z.string(),
384
+ })
385
+ .strict()
386
+ .optional(),
387
+ /** The match input log paired with the final observation. */
388
+ inputLog: z
389
+ .object({
390
+ path: z.string().min(1),
391
+ sha256: z.string().regex(/^[a-f0-9]{64}$/),
392
+ ticks: z.number().int().nonnegative(),
393
+ stepMs: z.number().positive(),
394
+ entries: z.number().int().nonnegative(),
395
+ fromTick: z.number().int().nonnegative(),
396
+ full: z.boolean(),
397
+ })
398
+ .strict()
399
+ .optional(),
400
+ error: z.string().nullable(),
401
+ })
402
+ .strict()
403
+ .optional(),
404
+ })
405
+ .strict()
406
+ .refine(
407
+ (record) =>
408
+ record.request.kind !== "play" ||
409
+ (record.profile === undefined &&
410
+ record.evaluation === undefined &&
411
+ record.end?.outcome === undefined),
412
+ "Play records have no authored profile, evaluation or verdict.",
413
+ )
414
+ .refine(
415
+ (record) =>
416
+ record.request.kind !== "test" ||
417
+ record.end === undefined ||
418
+ record.end.outcome !== undefined,
419
+ "Finished test records require a verdict.",
420
+ );
421
+ export type AirJamGameRunRecord = z.infer<typeof gameRunRecordSchema>;
422
+ export const gameRunCancellationSchema = z
423
+ .object({
424
+ runId: z.uuid(),
425
+ ownerInstanceId: z.uuid(),
426
+ fenced: z.literal(true),
427
+ record: gameRunRecordSchema.nullable(),
428
+ })
429
+ .strict();
430
+ export type AirJamGameRunCancellation = z.infer<
431
+ typeof gameRunCancellationSchema
432
+ >;
433
+
434
+ export {
435
+ formatGameRunWatchSurface,
436
+ GAME_WATCH_HEARTBEAT_MS,
437
+ gameRunWatchEventSchema,
438
+ gameRunWatchRequestSchema,
439
+ gameRunWatchSurfaceSchema,
440
+ GameRunWatchWriter,
441
+ MAXIMUM_GAME_WATCH_FRAME_BASE64,
442
+ parseGameRunWatchSurface,
443
+ readGameRunWatchStream,
444
+ } from "./game-run-watch.js";
445
+ export type {
446
+ GameRunWatchEvent,
447
+ GameRunWatchSurface,
448
+ } from "./game-run-watch.js";
@@ -0,0 +1,92 @@
1
+ import { constants } from "node:fs";
2
+ import { lstat, open, realpath } from "node:fs/promises";
3
+ import path from "node:path";
4
+ import {
5
+ gameRunAddressSchema,
6
+ gameRunRecordSchema,
7
+ type AirJamGameRunRecord,
8
+ } from "./game-run-protocol.js";
9
+
10
+ export async function readGameRunArtifact(
11
+ projectDir: string,
12
+ runId: string,
13
+ name: "record.json" | "trace.ndjson",
14
+ maximumBytes: number,
15
+ ) {
16
+ gameRunAddressSchema.parse({ runId });
17
+ const filename = path.join(
18
+ await realpath(projectDir),
19
+ ".airjam",
20
+ "artifacts",
21
+ "runs",
22
+ runId,
23
+ name,
24
+ );
25
+ const file = await open(
26
+ filename,
27
+ constants.O_RDONLY | constants.O_NOFOLLOW,
28
+ ).catch((error: NodeJS.ErrnoException) => {
29
+ if (error.code === "ENOENT") return null;
30
+ throw error;
31
+ });
32
+ if (!file) return null;
33
+ try {
34
+ const stat = await file.stat();
35
+ if (!stat.isFile() || stat.size > maximumBytes)
36
+ throw new Error(
37
+ "run_receipt_invalid: Retained record exceeds its limit.",
38
+ );
39
+ const validatePath = async () => {
40
+ const current = await lstat(filename);
41
+ if ((await realpath(filename)) !== filename)
42
+ throw new Error("run_receipt_invalid: Retained record path changed.");
43
+ if (current.ino !== stat.ino || current.dev !== stat.dev) {
44
+ // Live records are replaced atomically; a changing record is not an offline terminal receipt.
45
+ if (name === "record.json" && current.isFile()) return false;
46
+ throw new Error("run_receipt_invalid: Retained record path changed.");
47
+ }
48
+ return true;
49
+ };
50
+ if (!(await validatePath())) return null;
51
+ const buffer = Buffer.alloc(stat.size + 1);
52
+ let size = 0;
53
+ while (size < buffer.length) {
54
+ const { bytesRead } = await file.read(buffer, size, buffer.length - size);
55
+ if (bytesRead === 0) break;
56
+ size += bytesRead;
57
+ }
58
+ if (!(await validatePath())) return null;
59
+ if (size !== stat.size)
60
+ throw new Error(
61
+ "run_receipt_invalid: Retained record changed during read.",
62
+ );
63
+ return buffer.subarray(0, size);
64
+ } finally {
65
+ await file.close();
66
+ }
67
+ }
68
+
69
+ /** Completed evidence remains readable without reviving a session owner. */
70
+ export async function readTerminalGameRun(
71
+ projectDir: string,
72
+ runId: string,
73
+ ): Promise<AirJamGameRunRecord | null> {
74
+ const bytes = await readGameRunArtifact(
75
+ projectDir,
76
+ runId,
77
+ "record.json",
78
+ 1_048_576,
79
+ );
80
+ if (!bytes) return null;
81
+ const record = gameRunRecordSchema.parse(JSON.parse(bytes.toString("utf8")));
82
+ if (
83
+ record.runId !== runId ||
84
+ record.request.runId !== runId ||
85
+ record.request.cwd !== projectDir
86
+ )
87
+ throw new Error("run_receipt_invalid: Retained record identity differs.");
88
+ if (record.state !== "ended") return null;
89
+ if (!record.endedAt || !record.end)
90
+ throw new Error("run_receipt_invalid: Terminal receipt is incomplete.");
91
+ return record;
92
+ }
@@ -0,0 +1,95 @@
1
+ import type { HostObservation } from "@air-jam/sdk/runtime-control";
2
+ import { createHash } from "node:crypto";
3
+ import { readFile, realpath } from "node:fs/promises";
4
+ import path from "node:path";
5
+ import { isDeepStrictEqual } from "node:util";
6
+ import { readTerminalGameRun } from "./game-run-record.js";
7
+ import { inspectGame } from "./games.js";
8
+ import { replayInputLog } from "./headless-room.js";
9
+
10
+ const OBSERVE_TIMEOUT_MS = 10_000;
11
+
12
+ /** What decides a match: the game's agent view, its simulation and its step. */
13
+ const outcome = (observation: HostObservation) => ({
14
+ snapshot: observation.snapshot,
15
+ runtime: observation.runtime,
16
+ tick: observation.ticks.after,
17
+ });
18
+
19
+ /**
20
+ * Replays an ended headless run from its input log on a fresh copy of the
21
+ * game, and compares where the replay ends with the run's final observation.
22
+ */
23
+ export async function replayGameRun({
24
+ cwd,
25
+ runId,
26
+ }: {
27
+ cwd?: string;
28
+ runId: string;
29
+ }) {
30
+ const projectDir = await realpath(cwd ?? process.cwd());
31
+ const record = await readTerminalGameRun(projectDir, runId);
32
+ if (!record)
33
+ throw new Error("run_not_ended: Replay a run once it has ended.");
34
+ const evidence = record.evidence;
35
+ if (!evidence?.inputLog || !evidence.observation)
36
+ throw new Error(
37
+ "no_input_log: Only headless runs of games with a simulation keep an input log.",
38
+ );
39
+ const game = await inspectGame({
40
+ cwd: projectDir,
41
+ gameId: record.request.gameId,
42
+ });
43
+ if (!game?.configPath)
44
+ throw new Error("game_not_found: The run's game is no longer here.");
45
+ const runDirectory = path.join(
46
+ projectDir,
47
+ ".airjam",
48
+ "artifacts",
49
+ "runs",
50
+ runId,
51
+ );
52
+ const inputLogPath = path.join(runDirectory, "input-log.json");
53
+ const source = await readFile(inputLogPath);
54
+ if (
55
+ createHash("sha256").update(source).digest("hex") !==
56
+ evidence.inputLog.sha256
57
+ )
58
+ throw new Error("run_receipt_invalid: The input log changed.");
59
+ const recorded = JSON.parse(
60
+ await readFile(path.join(runDirectory, "final-observation.json"), "utf8"),
61
+ ) as HostObservation;
62
+
63
+ const replay = await replayInputLog({
64
+ rootDir: game.rootDir,
65
+ configPath: game.configPath,
66
+ inputLogPath,
67
+ logPath: path.join(runDirectory, "replay.log"),
68
+ });
69
+ try {
70
+ const response = await replay.requestHost(
71
+ {
72
+ operation: "observe",
73
+ roomId: replay.roomId,
74
+ controllerId: recorded.controllerId,
75
+ scope: recorded.scope,
76
+ includeImage: false,
77
+ },
78
+ OBSERVE_TIMEOUT_MS,
79
+ );
80
+ if (response.operation !== "observe")
81
+ throw new Error("invalid_runtime_response: Expected an observation.");
82
+ const replayed = outcome(response.observation);
83
+ const original = outcome(recorded);
84
+ return {
85
+ runId,
86
+ gameId: replay.gameId,
87
+ ticks: replay.ticks,
88
+ reproduced: isDeepStrictEqual(replayed, original),
89
+ replayed,
90
+ recorded: original,
91
+ };
92
+ } finally {
93
+ await replay.stop();
94
+ }
95
+ }