@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
package/src/testing.ts ADDED
@@ -0,0 +1,430 @@
1
+ import {
2
+ controllerLeasedControlAckSchema,
3
+ leasedControlRequestSchema,
4
+ participantActionOperationSchema,
5
+ participantInputOperationSchema,
6
+ participantReleaseOperationSchema,
7
+ } from "@air-jam/sdk/protocol";
8
+ import type { HostObservation } from "@air-jam/sdk/runtime-control";
9
+ import { z } from "zod";
10
+ import type { policyArtifactReceiptSchema } from "./policy-artifact-contract.js";
11
+ import { policyArtifactPathSchema } from "./policy-artifact-contract.js";
12
+
13
+ const id = z.string().regex(/^[a-z][a-z0-9_-]{0,63}$/);
14
+ const profileStepSchema = z.discriminatedUnion("lane", [
15
+ z
16
+ .object({
17
+ lane: z.literal("host"),
18
+ actionId: participantActionOperationSchema.shape.actionId,
19
+ input: z.json().optional(),
20
+ })
21
+ .strict(),
22
+ z
23
+ .object({
24
+ lane: z.literal("participant"),
25
+ seatId: id,
26
+ actionId: participantActionOperationSchema.shape.actionId,
27
+ input: z.json().optional(),
28
+ })
29
+ .strict(),
30
+ ]);
31
+ export const airJamTestProfileDescriptionSchema = z
32
+ .object({
33
+ id,
34
+ label: z.string().min(1).max(120),
35
+ seats: z
36
+ .array(z.object({ id, label: z.string().min(1).max(80) }).strict())
37
+ .min(1)
38
+ .max(8),
39
+ setup: z.array(profileStepSchema).max(32),
40
+ /**
41
+ * The steps that return the creator's room to where people pick up after a
42
+ * test, usually the lobby, run once play ends and before the run's players
43
+ * leave. Only rooms that outlive the run need them; an empty list says the
44
+ * room needs nothing.
45
+ */
46
+ handBack: z.array(profileStepSchema).max(32).optional(),
47
+ actions: z.array(participantActionOperationSchema.shape.actionId).max(64),
48
+ scope: z.enum(["player", "diagnostic"]),
49
+ includeImage: z.boolean(),
50
+ timing: z
51
+ .object({
52
+ intervalMs: z.number().int().min(20).max(5000),
53
+ decisionMs: z.number().int().min(50).max(1500),
54
+ inputTtlMs: participantInputOperationSchema.shape.ttlMs,
55
+ })
56
+ .strict(),
57
+ policies: z
58
+ .array(
59
+ z
60
+ .object({
61
+ id,
62
+ label: z.string().min(1).max(120),
63
+ artifacts: policyArtifactPathSchema.optional(),
64
+ })
65
+ .strict(),
66
+ )
67
+ .min(1)
68
+ .max(16),
69
+ metrics: z
70
+ .array(z.object({ id, label: z.string().min(1).max(120) }).strict())
71
+ .max(16),
72
+ })
73
+ .strict();
74
+ export type AirJamTestProfileDescription = z.infer<
75
+ typeof airJamTestProfileDescriptionSchema
76
+ >;
77
+
78
+ export const PLAY_RUN_PLAYER = {
79
+ seats: [{ id: "player", label: "Player" }],
80
+ scope: "player",
81
+ includeImage: false,
82
+ timing: { intervalMs: 100, decisionMs: 1200, inputTtlMs: 1500 },
83
+ } satisfies AirJamRunPlayers;
84
+ export type AirJamRunPlayers = Pick<
85
+ AirJamTestProfileDescription,
86
+ "seats" | "scope" | "includeImage" | "timing"
87
+ >;
88
+
89
+ const byteLength = (value: unknown) =>
90
+ new TextEncoder().encode(JSON.stringify(value)).byteLength;
91
+ const policyDiagnosticsSchema = z
92
+ .record(id, z.union([z.string().max(160), z.number().finite(), z.boolean()]))
93
+ .refine(
94
+ (value) => Object.keys(value).length <= 16 && byteLength(value) <= 1024,
95
+ "Policy diagnostics exceed 1 KiB or 16 entries.",
96
+ );
97
+ const playControlSchema = z.discriminatedUnion("kind", [
98
+ participantReleaseOperationSchema,
99
+ participantInputOperationSchema.omit({ deadlineMs: true, ttlMs: true }),
100
+ participantActionOperationSchema.omit({ deadlineMs: true }),
101
+ ]);
102
+ export type AirJamPlayControl = z.infer<typeof playControlSchema>;
103
+
104
+ const QUESTION_STATE_LINES = 32;
105
+ /** A turn's own lines, leaving room for the brief and a goal line. */
106
+ const TURN_STATE_LINES = QUESTION_STATE_LINES - 2;
107
+
108
+ /**
109
+ * A turn resolved by the run owner, asking its decision model only when there
110
+ * is more than one option. Every option is an ordinary
111
+ * play control (an input, an action, or doing nothing), so the model can only
112
+ * ever pick among controls the game already accepts. The size bound keeps the
113
+ * question inside the fast context of current typed decision models.
114
+ */
115
+ export const airJamDecisionQuestionSchema = z
116
+ .object({
117
+ state: z
118
+ .array(z.string().min(1).max(8000))
119
+ .min(1)
120
+ .max(QUESTION_STATE_LINES),
121
+ question: z.string().min(1).max(1000),
122
+ options: z
123
+ .record(
124
+ z.string().min(1, "A decision option key must not be empty."),
125
+ z
126
+ .object({
127
+ when: z.string().min(1).max(500),
128
+ control: playControlSchema,
129
+ })
130
+ .strict(),
131
+ )
132
+ .refine((options) => {
133
+ const count = Object.keys(options).length;
134
+ return count >= 1 && count <= 16;
135
+ }, "A decision offers between 1 and 16 options."),
136
+ })
137
+ .strict();
138
+ export type AirJamDecisionQuestion = z.infer<
139
+ typeof airJamDecisionQuestionSchema
140
+ >;
141
+
142
+ export const airJamPolicyDecisionSchema = z.union([
143
+ z
144
+ .object({
145
+ diagnostics: policyDiagnosticsSchema.optional(),
146
+ control: playControlSchema,
147
+ })
148
+ .strict()
149
+ .refine(
150
+ (value) => byteLength(value) <= 16_000,
151
+ "Policy decision exceeds 16 KB.",
152
+ ),
153
+ z
154
+ .object({
155
+ diagnostics: policyDiagnosticsSchema.optional(),
156
+ ask: airJamDecisionQuestionSchema,
157
+ })
158
+ .strict()
159
+ .refine(
160
+ (value) => byteLength(value) <= 32_000,
161
+ "Decision question exceeds 32 KB.",
162
+ ),
163
+ ]);
164
+ export type AirJamPolicyDecision = z.infer<typeof airJamPolicyDecisionSchema>;
165
+
166
+ export const airJamRunReceiptSchema = z
167
+ .object({
168
+ index: z.number().int().positive(),
169
+ seatId: z.string(),
170
+ phase: z.enum(["setup", "play", "cleanup"]),
171
+ sequence: z.number().int().positive(),
172
+ attempts: z.union([z.literal(1), z.literal(2)]),
173
+ operation: leasedControlRequestSchema.shape.operation,
174
+ acknowledgement: controllerLeasedControlAckSchema,
175
+ })
176
+ .strict();
177
+ export type AirJamRunReceipt = z.infer<typeof airJamRunReceiptSchema>;
178
+
179
+ export const airJamScenarioVerdictSchema = z
180
+ .object({
181
+ status: z.enum(["pending", "passed", "failed"]),
182
+ message: z.string().min(1).max(1000).optional(),
183
+ metrics: z.record(id, z.number().finite()).optional(),
184
+ })
185
+ .strict();
186
+ export type AirJamScenarioVerdict = z.infer<typeof airJamScenarioVerdictSchema>;
187
+ export type AirJamScenarioSample = {
188
+ phase: "play" | "final";
189
+ observation: HostObservation;
190
+ seats: Array<{ seatId: string; controllerId: string }>;
191
+ receipts: AirJamRunReceipt[];
192
+ elapsedMs: number;
193
+ };
194
+
195
+ export type AirJamPolicyStep = {
196
+ observation: HostObservation;
197
+ seatId: string;
198
+ /** What this seat is currently trying to do, if anyone has said. */
199
+ intent: string | null;
200
+ /** The decision model's answer to this seat's latest question, if any. */
201
+ answer: { choice: string; confidence: number } | null;
202
+ step: number;
203
+ elapsedMs: number;
204
+ receipts: AirJamRunReceipt[];
205
+ };
206
+ export type AirJamPolicyDecider = {
207
+ decide: (
208
+ step: AirJamPolicyStep,
209
+ ) => AirJamPolicyDecision | Promise<AirJamPolicyDecision>;
210
+ };
211
+ export type AirJamTestPolicy = {
212
+ label: string;
213
+ artifacts?: string;
214
+ create: (context: {
215
+ seatId: string;
216
+ random: () => number;
217
+ artifacts?: {
218
+ directory: string;
219
+ receipt: z.infer<typeof policyArtifactReceiptSchema>;
220
+ };
221
+ }) => AirJamPolicyDecider | Promise<AirJamPolicyDecider>;
222
+ };
223
+ export const policyPreparationSchema = z
224
+ .array(
225
+ z
226
+ .object({
227
+ seatId: z.string(),
228
+ prepareMs: z.number().finite().nonnegative(),
229
+ })
230
+ .strict(),
231
+ )
232
+ .max(8);
233
+ export type AirJamTestProfile = Omit<
234
+ AirJamTestProfileDescription,
235
+ "id" | "policies"
236
+ > & {
237
+ policies: Record<string, AirJamTestPolicy>;
238
+ evaluator: {
239
+ create: (context: { seats: readonly string[] }) => {
240
+ evaluate: (sample: AirJamScenarioSample) => AirJamScenarioVerdict;
241
+ };
242
+ };
243
+ };
244
+
245
+ export function describeAirJamTestProfiles(
246
+ profiles: Record<string, AirJamTestProfile>,
247
+ ) {
248
+ return Object.entries(profiles).map(([profileId, profile]) => {
249
+ const { evaluator, ...metadata } = profile;
250
+ if (typeof evaluator?.create !== "function")
251
+ throw new Error("A scenario must create an independent evaluator.");
252
+ for (const policy of Object.values(profile.policies)) {
253
+ if (typeof policy.create !== "function")
254
+ throw new Error("A test policy must create a decision function.");
255
+ }
256
+ const description = airJamTestProfileDescriptionSchema.parse({
257
+ ...metadata,
258
+ id: profileId,
259
+ policies: Object.entries(profile.policies).map(([policyId, policy]) => ({
260
+ id: policyId,
261
+ label: policy.label,
262
+ ...(policy.artifacts === undefined
263
+ ? {}
264
+ : { artifacts: policy.artifacts }),
265
+ })),
266
+ });
267
+ const seats = new Set(description.seats.map((seat) => seat.id));
268
+ if (seats.size !== description.seats.length)
269
+ throw new Error(`Duplicate seats in profile ${profileId}.`);
270
+ if (
271
+ new Set(description.metrics.map((metric) => metric.id)).size !==
272
+ description.metrics.length
273
+ )
274
+ throw new Error(`Duplicate metrics in profile ${profileId}.`);
275
+ if (description.timing.inputTtlMs < description.timing.intervalMs)
276
+ throw new Error("Input lifetime must cover the round interval.");
277
+ for (const step of [
278
+ ...description.setup,
279
+ ...(description.handBack ?? []),
280
+ ]) {
281
+ if (step.lane === "participant" && !seats.has(step.seatId))
282
+ throw new Error(`Unknown seat ${step.seatId} in profile ${profileId}.`);
283
+ }
284
+ return description;
285
+ });
286
+ }
287
+
288
+ export function defineAirJamTestProfiles<
289
+ const T extends Record<string, AirJamTestProfile>,
290
+ >(profiles: T): T {
291
+ describeAirJamTestProfiles(profiles);
292
+ return profiles;
293
+ }
294
+
295
+ /**
296
+ * How a game is played by a typed decision model, written by whoever writes the
297
+ * game. The brief explains the game to a reader who has never seen it; each
298
+ * turn describes the current state in words and offers choices that resolve to
299
+ * the game's own inputs or actions. A seat with nothing to decide returns null.
300
+ */
301
+ export type AirJamPlayerContract = {
302
+ brief: string;
303
+ turn: (context: {
304
+ observation: HostObservation;
305
+ seatId: string;
306
+ /** The seat's seeded randomness, so a run replays the same choices. */
307
+ random: () => number;
308
+ /** Play time so far: game time in a headless room. */
309
+ elapsedMs: number;
310
+ }) => AirJamDecisionQuestion | null;
311
+ /**
312
+ * For games that need control faster than a model answers. Between
313
+ * questions the seat keeps acting on the model's last choice at the run's
314
+ * step rate, for `rethinkMs` after the answer arrives, and is asked again
315
+ * sooner when its goal changes or that choice is no longer offered.
316
+ * `create` runs once per seat, so a seat can keep state such as a pilot.
317
+ */
318
+ act?: {
319
+ rethinkMs: number;
320
+ create: (context: { random: () => number }) => {
321
+ control: (context: {
322
+ observation: HostObservation;
323
+ seatId: string;
324
+ choice: string;
325
+ elapsedMs: number;
326
+ }) => AirJamPlayControl | null;
327
+ };
328
+ };
329
+ };
330
+
331
+ /**
332
+ * A test policy that plays every seat through the run's decision model. The
333
+ * brief and any seat intent lead every question, so a turn may describe at
334
+ * most 30 state lines.
335
+ */
336
+ export function createAirJamPlayerPolicy(
337
+ contract: AirJamPlayerContract,
338
+ ): AirJamTestPolicy {
339
+ airJamDecisionQuestionSchema.shape.state.element.parse(contract.brief);
340
+ if (typeof contract.turn !== "function")
341
+ throw new Error("A player contract must describe each turn.");
342
+ const act = contract.act;
343
+ if (
344
+ act &&
345
+ (!Number.isInteger(act.rethinkMs) ||
346
+ act.rethinkMs < 1 ||
347
+ typeof act.create !== "function")
348
+ )
349
+ throw new Error(
350
+ "A player contract's act needs a positive whole rethinkMs and create.",
351
+ );
352
+ return {
353
+ label: "Decision model",
354
+ create: ({ random }) => {
355
+ const actor = act?.create({ random });
356
+ let asked: { intent: string | null; answeredAtMs?: number } | undefined;
357
+ return {
358
+ decide: ({ observation, seatId, intent, answer, elapsedMs }) => {
359
+ const turn = contract.turn({
360
+ observation,
361
+ seatId,
362
+ random,
363
+ elapsedMs,
364
+ });
365
+ if (!turn) return { control: { kind: "release" } };
366
+ if (turn.state.length > TURN_STATE_LINES)
367
+ throw new Error(
368
+ `A player contract turn may describe at most ${TURN_STATE_LINES} state lines, so it still fits once the seat is given a goal.`,
369
+ );
370
+ if (
371
+ act &&
372
+ actor &&
373
+ asked &&
374
+ answer &&
375
+ Object.hasOwn(turn.options, answer.choice) &&
376
+ asked.intent === intent
377
+ ) {
378
+ asked.answeredAtMs ??= elapsedMs;
379
+ if (elapsedMs - asked.answeredAtMs < act.rethinkMs)
380
+ return {
381
+ control: actor.control({
382
+ observation,
383
+ seatId,
384
+ choice: answer.choice,
385
+ elapsedMs,
386
+ }) ?? { kind: "release" },
387
+ };
388
+ }
389
+ asked = { intent };
390
+ return {
391
+ ask: {
392
+ ...turn,
393
+ state: [
394
+ contract.brief,
395
+ ...(intent ? [`My goal right now: ${intent}`] : []),
396
+ ...turn.state,
397
+ ],
398
+ },
399
+ };
400
+ },
401
+ };
402
+ },
403
+ };
404
+ }
405
+
406
+ export function defineAirJamTesting(declaration: {
407
+ player?: AirJamPlayerContract;
408
+ profiles: Record<string, AirJamTestProfile>;
409
+ visual?: import("./harness/visual.js").VisualScenarioPack;
410
+ }) {
411
+ const model =
412
+ declaration.player && createAirJamPlayerPolicy(declaration.player);
413
+ const profiles = Object.fromEntries(
414
+ Object.entries(declaration.profiles).map(([id, profile]) => {
415
+ if (Object.hasOwn(profile.policies, "model"))
416
+ throw new Error(
417
+ `AJ_TEST_POLICY_RESERVED: Profile "${id}" must declare its player in defineAirJamTesting.player, not a model policy.`,
418
+ );
419
+ return [
420
+ id,
421
+ {
422
+ ...profile,
423
+ policies: { ...profile.policies, ...(model ? { model } : {}) },
424
+ },
425
+ ];
426
+ }),
427
+ );
428
+ describeAirJamTestProfiles(profiles);
429
+ return { ...declaration, profiles };
430
+ }
@@ -0,0 +1,52 @@
1
+ import * as module from "node:module";
2
+
3
+ let activeLoads = 0;
4
+ let registered = false;
5
+ let pending: Promise<unknown> = Promise.resolve();
6
+
7
+ export function importDeclaration<T>(load: () => Promise<T>): Promise<T> {
8
+ if (typeof module.registerHooks !== "function")
9
+ throw new Error("Air Jam authoring requires Node.js 22.15 or newer.");
10
+ if (!registered) {
11
+ module.registerHooks({
12
+ resolve(specifier, context, nextResolve) {
13
+ if (
14
+ activeLoads > 0 &&
15
+ (specifier === "@air-jam/sdk" ||
16
+ /^(react|react-dom)(\/|$)/.test(specifier))
17
+ )
18
+ throw new Error(
19
+ `AJ_DECLARATION_NOT_FRAMEWORK_FREE: ${context.parentURL ?? specifier} imports ${specifier}. Move browser bindings to app.tsx and import declarations from @air-jam/sdk/core.`,
20
+ );
21
+ const result = nextResolve(specifier, context);
22
+ if (activeLoads > 0 && /\.(tsx|css)(\?|$)/.test(result.url))
23
+ throw new Error(
24
+ `AJ_DECLARATION_NOT_FRAMEWORK_FREE: ${context.parentURL ?? specifier} imports ${result.url}. Keep the declaration framework-free.`,
25
+ );
26
+ return result;
27
+ },
28
+ load(url, context, nextLoad) {
29
+ return nextLoad(
30
+ url,
31
+ activeLoads > 0 && /\.ts(?:\?|$)/.test(url)
32
+ ? { ...context, format: "module" }
33
+ : context,
34
+ );
35
+ },
36
+ });
37
+ registered = true;
38
+ }
39
+ const loaded = pending.then(async () => {
40
+ activeLoads++;
41
+ try {
42
+ return await load();
43
+ } finally {
44
+ activeLoads--;
45
+ }
46
+ });
47
+ pending = loaded.then(
48
+ () => undefined,
49
+ () => undefined,
50
+ );
51
+ return loaded;
52
+ }
@@ -0,0 +1,49 @@
1
+ import {
2
+ airJamGameDescriptionSchema,
3
+ describeAirJamGame,
4
+ } from "@air-jam/sdk/core";
5
+ import { stat } from "node:fs/promises";
6
+ import path from "node:path";
7
+ import { loadAirJamGame } from "./load-game.js";
8
+
9
+ const configs: string[] = [];
10
+ for (let index = 2; index < process.argv.length; index++) {
11
+ const argument = process.argv[index];
12
+ if (argument === "--config") {
13
+ const value = process.argv[++index];
14
+ if (!value) throw new Error("--config requires a path.");
15
+ configs.push(value);
16
+ } else if (argument.startsWith("--config=")) configs.push(argument.slice(9));
17
+ else throw new Error(`Unknown describe-game argument: ${argument}`);
18
+ }
19
+ if (!configs.length)
20
+ throw new Error("describe-game requires at least one --config path.");
21
+ const descriptions = [];
22
+ for (const config of configs) {
23
+ const description = airJamGameDescriptionSchema.parse(
24
+ describeAirJamGame(await loadAirJamGame(config)),
25
+ );
26
+ const publicDirectory = path.resolve(path.dirname(config), "../public");
27
+ for (const [kind, assets] of Object.entries(description.assets)) {
28
+ for (const [id, asset] of Object.entries(assets)) {
29
+ const sources = Array.isArray(asset.src) ? asset.src : [asset.src];
30
+ for (const source of sources) {
31
+ const file = path.join(publicDirectory, source);
32
+ const exists = await stat(file).then(
33
+ (status) => status.isFile(),
34
+ (error) => {
35
+ if (error.code === "ENOENT" || error.code === "ENOTDIR")
36
+ return false;
37
+ throw error;
38
+ },
39
+ );
40
+ if (!exists)
41
+ throw new Error(
42
+ `AJ_ASSET_MISSING: ${description.metadata.slug} ${kind}.${id} declares ${source}, missing from ${publicDirectory}.`,
43
+ );
44
+ }
45
+ }
46
+ }
47
+ descriptions.push(description);
48
+ }
49
+ process.stdout.write(`${JSON.stringify(descriptions)}\n`);
@@ -0,0 +1,7 @@
1
+ import path from "node:path";
2
+ import { runGameSessionBroker } from "../game-session-broker.js";
3
+
4
+ const projectDir = process.argv[2];
5
+ if (!projectDir)
6
+ throw new Error("Game session owner requires a project directory.");
7
+ await runGameSessionBroker({ projectDir: path.resolve(projectDir) });