@air-jam/devtools 0.0.0-stage → 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.
Files changed (256) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +112 -2
  3. package/dist/chunk-2O67AXCU.js +470 -0
  4. package/dist/chunk-2O67AXCU.js.map +1 -0
  5. package/dist/chunk-AO3ZDXF6.js +142 -0
  6. package/dist/chunk-AO3ZDXF6.js.map +1 -0
  7. package/dist/chunk-ART5TEYT.js +472 -0
  8. package/dist/chunk-ART5TEYT.js.map +1 -0
  9. package/dist/chunk-ASC2CK2R.js +77 -0
  10. package/dist/chunk-ASC2CK2R.js.map +1 -0
  11. package/dist/chunk-E3UZZGAV.js +50 -0
  12. package/dist/chunk-E3UZZGAV.js.map +1 -0
  13. package/dist/chunk-EJTE7UKX.js +64 -0
  14. package/dist/chunk-EJTE7UKX.js.map +1 -0
  15. package/dist/chunk-ESFKNN75.js +110 -0
  16. package/dist/chunk-ESFKNN75.js.map +1 -0
  17. package/dist/chunk-EU7A6PXW.js +1339 -0
  18. package/dist/chunk-EU7A6PXW.js.map +1 -0
  19. package/dist/chunk-FN7E6EA7.js +549 -0
  20. package/dist/chunk-FN7E6EA7.js.map +1 -0
  21. package/dist/chunk-GDFAWHGA.js +190 -0
  22. package/dist/chunk-GDFAWHGA.js.map +1 -0
  23. package/dist/chunk-HZUGBH4Y.js +347 -0
  24. package/dist/chunk-HZUGBH4Y.js.map +1 -0
  25. package/dist/chunk-ITKAOEGX.js +93 -0
  26. package/dist/chunk-ITKAOEGX.js.map +1 -0
  27. package/dist/chunk-JBCUTWRI.js +897 -0
  28. package/dist/chunk-JBCUTWRI.js.map +1 -0
  29. package/dist/chunk-JSI5S4WP.js +1174 -0
  30. package/dist/chunk-JSI5S4WP.js.map +1 -0
  31. package/dist/chunk-L4D675BG.js +97 -0
  32. package/dist/chunk-L4D675BG.js.map +1 -0
  33. package/dist/chunk-M6CJ7GQC.js +133 -0
  34. package/dist/chunk-M6CJ7GQC.js.map +1 -0
  35. package/dist/chunk-MEIMOSZC.js +749 -0
  36. package/dist/chunk-MEIMOSZC.js.map +1 -0
  37. package/dist/chunk-O3XG3FNL.js +1014 -0
  38. package/dist/chunk-O3XG3FNL.js.map +1 -0
  39. package/dist/chunk-OM6SCJ7H.js +18 -0
  40. package/dist/chunk-OM6SCJ7H.js.map +1 -0
  41. package/dist/chunk-PKD4WVX5.js +63 -0
  42. package/dist/chunk-PKD4WVX5.js.map +1 -0
  43. package/dist/chunk-PMBLXGFM.js +3384 -0
  44. package/dist/chunk-PMBLXGFM.js.map +1 -0
  45. package/dist/chunk-PMNE5GIN.js +279 -0
  46. package/dist/chunk-PMNE5GIN.js.map +1 -0
  47. package/dist/chunk-QAWI64VR.js +148 -0
  48. package/dist/chunk-QAWI64VR.js.map +1 -0
  49. package/dist/chunk-QGADSPHZ.js +449 -0
  50. package/dist/chunk-QGADSPHZ.js.map +1 -0
  51. package/dist/chunk-SPYN66UV.js +338 -0
  52. package/dist/chunk-SPYN66UV.js.map +1 -0
  53. package/dist/context.d.ts +19 -0
  54. package/dist/context.js +10 -0
  55. package/dist/context.js.map +1 -0
  56. package/dist/controller.d.ts +67 -0
  57. package/dist/controller.js +40 -0
  58. package/dist/controller.js.map +1 -0
  59. package/dist/dependencies.d.ts +44 -0
  60. package/dist/dependencies.js +10 -0
  61. package/dist/dependencies.js.map +1 -0
  62. package/dist/dev.d.ts +21 -0
  63. package/dist/dev.js +19 -0
  64. package/dist/dev.js.map +1 -0
  65. package/dist/game-builds.d.ts +200 -0
  66. package/dist/game-builds.js +16 -0
  67. package/dist/game-builds.js.map +1 -0
  68. package/dist/game-run-watch-CEd_SpAT.d.ts +84 -0
  69. package/dist/game-runs.d.ts +1452 -0
  70. package/dist/game-runs.js +76 -0
  71. package/dist/game-runs.js.map +1 -0
  72. package/dist/game-session-broker-CUvORfMd.d.ts +439 -0
  73. package/dist/game-session-broker.d.ts +4 -0
  74. package/dist/game-session-broker.js +40 -0
  75. package/dist/game-session-broker.js.map +1 -0
  76. package/dist/game-session.d.ts +3934 -0
  77. package/dist/game-session.js +195 -0
  78. package/dist/game-session.js.map +1 -0
  79. package/dist/game-settings.d.ts +16 -0
  80. package/dist/game-settings.js +237 -0
  81. package/dist/game-settings.js.map +1 -0
  82. package/dist/games.d.ts +28 -0
  83. package/dist/games.js +16 -0
  84. package/dist/games.js.map +1 -0
  85. package/dist/harness/visual.d.ts +204 -0
  86. package/dist/harness/visual.js +46 -0
  87. package/dist/harness/visual.js.map +1 -0
  88. package/dist/logs.d.ts +15 -0
  89. package/dist/logs.js +57 -0
  90. package/dist/logs.js.map +1 -0
  91. package/dist/managed-process-scope-BicYi_t9.d.ts +3 -0
  92. package/dist/mcp-config.d.ts +63 -0
  93. package/dist/mcp-config.js +191 -0
  94. package/dist/mcp-config.js.map +1 -0
  95. package/dist/platform-auth.d.ts +9 -0
  96. package/dist/platform-auth.js +45 -0
  97. package/dist/platform-auth.js.map +1 -0
  98. package/dist/platform-game-analytics.d.ts +51 -0
  99. package/dist/platform-game-analytics.js +49 -0
  100. package/dist/platform-game-analytics.js.map +1 -0
  101. package/dist/platform-game-app-id.d.ts +46 -0
  102. package/dist/platform-game-app-id.js +93 -0
  103. package/dist/platform-game-app-id.js.map +1 -0
  104. package/dist/platform-game-media.d.ts +347 -0
  105. package/dist/platform-game-media.js +168 -0
  106. package/dist/platform-game-media.js.map +1 -0
  107. package/dist/platform-games.d.ts +87 -0
  108. package/dist/platform-games.js +183 -0
  109. package/dist/platform-games.js.map +1 -0
  110. package/dist/quality.d.ts +16 -0
  111. package/dist/quality.js +62 -0
  112. package/dist/quality.js.map +1 -0
  113. package/dist/release.d.ts +1304 -0
  114. package/dist/release.js +34 -0
  115. package/dist/release.js.map +1 -0
  116. package/dist/rooms-check.d.ts +90 -0
  117. package/dist/rooms-check.js +717 -0
  118. package/dist/rooms-check.js.map +1 -0
  119. package/dist/source-tree-contract.d.ts +16 -0
  120. package/dist/source-tree-contract.js +13 -0
  121. package/dist/source-tree-contract.js.map +1 -0
  122. package/dist/testing.d.ts +464 -0
  123. package/dist/testing.js +27 -0
  124. package/dist/testing.js.map +1 -0
  125. package/dist/tooling/describe-game.d.ts +2 -0
  126. package/dist/tooling/describe-game.js +54 -0
  127. package/dist/tooling/describe-game.js.map +1 -0
  128. package/dist/tooling/game-session-broker.d.ts +2 -0
  129. package/dist/tooling/game-session-broker.js +28 -0
  130. package/dist/tooling/game-session-broker.js.map +1 -0
  131. package/dist/tooling/hold-runtime-host.d.ts +2 -0
  132. package/dist/tooling/hold-runtime-host.js +931 -0
  133. package/dist/tooling/hold-runtime-host.js.map +1 -0
  134. package/dist/tooling/list-visual-scenarios.d.ts +2 -0
  135. package/dist/tooling/list-visual-scenarios.js +25 -0
  136. package/dist/tooling/list-visual-scenarios.js.map +1 -0
  137. package/dist/tooling/managed-dev-supervisor.d.ts +2 -0
  138. package/dist/tooling/managed-dev-supervisor.js +51 -0
  139. package/dist/tooling/managed-dev-supervisor.js.map +1 -0
  140. package/dist/tooling/process-scope-bootstrap.mjs +24 -0
  141. package/dist/tooling/process-scope-guard.d.ts +2 -0
  142. package/dist/tooling/process-scope-guard.js +388 -0
  143. package/dist/tooling/process-scope-guard.js.map +1 -0
  144. package/dist/tooling/process-scope-windows.ps1 +148 -0
  145. package/dist/tooling/rooms-check-device.d.ts +2 -0
  146. package/dist/tooling/rooms-check-device.js +498 -0
  147. package/dist/tooling/rooms-check-device.js.map +1 -0
  148. package/dist/tooling/run-headless-room.d.ts +2 -0
  149. package/dist/tooling/run-headless-room.js +287 -0
  150. package/dist/tooling/run-headless-room.js.map +1 -0
  151. package/dist/tooling/run-test-profile.d.ts +2 -0
  152. package/dist/tooling/run-test-profile.js +181 -0
  153. package/dist/tooling/run-test-profile.js.map +1 -0
  154. package/dist/tooling/run-visual-capture.d.ts +2 -0
  155. package/dist/tooling/run-visual-capture.js +203 -0
  156. package/dist/tooling/run-visual-capture.js.map +1 -0
  157. package/dist/tooling/seal-game-build.d.ts +2 -0
  158. package/dist/tooling/seal-game-build.js +120 -0
  159. package/dist/tooling/seal-game-build.js.map +1 -0
  160. package/dist/types-CdYrgrG_.d.ts +1036 -0
  161. package/dist/types-DyRD-ym1.d.ts +141 -0
  162. package/dist/visual.d.ts +21 -0
  163. package/dist/visual.js +219 -0
  164. package/dist/visual.js.map +1 -0
  165. package/package.json +150 -3
  166. package/src/bounded-response.ts +28 -0
  167. package/src/built-game-runtime.ts +152 -0
  168. package/src/commands.ts +40 -0
  169. package/src/context.ts +218 -0
  170. package/src/controller-protocol.ts +22 -0
  171. package/src/controller.ts +1526 -0
  172. package/src/current-room-host.ts +166 -0
  173. package/src/decision-provider.ts +102 -0
  174. package/src/dependencies.ts +176 -0
  175. package/src/dependency-install-contract.ts +12 -0
  176. package/src/dev.ts +995 -0
  177. package/src/fs-utils.ts +93 -0
  178. package/src/game-action-observation.ts +106 -0
  179. package/src/game-build-protocol.ts +72 -0
  180. package/src/game-build.ts +483 -0
  181. package/src/game-run-owner.ts +2358 -0
  182. package/src/game-run-protocol.ts +448 -0
  183. package/src/game-run-record.ts +92 -0
  184. package/src/game-run-replay.ts +95 -0
  185. package/src/game-run-watch.ts +155 -0
  186. package/src/game-session-broker.ts +793 -0
  187. package/src/game-session-operations.ts +61 -0
  188. package/src/game-session-protocol.ts +180 -0
  189. package/src/game-session-runtime.ts +861 -0
  190. package/src/game-session.ts +206 -0
  191. package/src/game-settings.ts +295 -0
  192. package/src/games.ts +262 -0
  193. package/src/harness/visual/browser.ts +100 -0
  194. package/src/harness/visual/controller-observation.ts +181 -0
  195. package/src/harness/visual/prefab-contract.ts +29 -0
  196. package/src/harness/visual/prefab-runner.ts +178 -0
  197. package/src/harness/visual/runner.ts +549 -0
  198. package/src/harness/visual/runtime-controller-observations.ts +151 -0
  199. package/src/harness/visual/scenario-contract.ts +8 -0
  200. package/src/harness/visual/scenario-helpers.ts +67 -0
  201. package/src/harness/visual/screencast.ts +155 -0
  202. package/src/harness/visual/session.ts +400 -0
  203. package/src/harness/visual/types.ts +184 -0
  204. package/src/harness/visual.ts +7 -0
  205. package/src/headless-room-protocol.ts +112 -0
  206. package/src/headless-room.ts +222 -0
  207. package/src/helper-channel.ts +229 -0
  208. package/src/helper-scripts.ts +69 -0
  209. package/src/installed-dependencies.ts +74 -0
  210. package/src/logs.ts +67 -0
  211. package/src/managed-process-scope.ts +481 -0
  212. package/src/mcp-config.ts +262 -0
  213. package/src/node-process-environment.ts +10 -0
  214. package/src/platform-auth.ts +594 -0
  215. package/src/platform-game-analytics.ts +50 -0
  216. package/src/platform-game-app-id.ts +99 -0
  217. package/src/platform-game-media.ts +209 -0
  218. package/src/platform-games.ts +217 -0
  219. package/src/policy-artifact-contract.ts +52 -0
  220. package/src/policy-artifacts.ts +134 -0
  221. package/src/process-scope-admission.ts +50 -0
  222. package/src/process-scope-protocol.ts +66 -0
  223. package/src/process-scope.ts +327 -0
  224. package/src/quality.ts +82 -0
  225. package/src/release.ts +1683 -0
  226. package/src/rooms-check-fleet.ts +194 -0
  227. package/src/rooms-check-link.ts +138 -0
  228. package/src/rooms-check-protocol.ts +244 -0
  229. package/src/rooms-check.ts +797 -0
  230. package/src/runtime-owner-protocol.ts +218 -0
  231. package/src/source-tree-contract.ts +70 -0
  232. package/src/source-tree.ts +84 -0
  233. package/src/test-profile-process.ts +153 -0
  234. package/src/test-profile-protocol.ts +116 -0
  235. package/src/testing.ts +430 -0
  236. package/src/tooling/declaration-hook.ts +52 -0
  237. package/src/tooling/describe-game.ts +49 -0
  238. package/src/tooling/game-session-broker.ts +7 -0
  239. package/src/tooling/hold-runtime-host.ts +441 -0
  240. package/src/tooling/list-visual-scenarios.ts +21 -0
  241. package/src/tooling/load-game.ts +79 -0
  242. package/src/tooling/managed-dev-supervisor.ts +71 -0
  243. package/src/tooling/process-scope-bootstrap.mjs +24 -0
  244. package/src/tooling/process-scope-guard.ts +213 -0
  245. package/src/tooling/process-scope-windows.ps1 +148 -0
  246. package/src/tooling/rooms-check-device.ts +493 -0
  247. package/src/tooling/run-headless-room.ts +326 -0
  248. package/src/tooling/run-test-profile.ts +190 -0
  249. package/src/tooling/run-visual-capture.ts +231 -0
  250. package/src/tooling/runtime-owner-actions.ts +65 -0
  251. package/src/tooling/seal-game-build.ts +118 -0
  252. package/src/tooling/visual-pack.ts +11 -0
  253. package/src/types.ts +928 -0
  254. package/src/visual.ts +296 -0
  255. package/src/windows-process-scopes.ts +189 -0
  256. package/src/workspace-contract.ts +32 -0
@@ -0,0 +1,99 @@
1
+ import {
2
+ platformMachineGameAppIdOriginsInputSchema,
3
+ platformMachineGameAppIdRegenerateInputSchema,
4
+ platformMachineGameAppIdSchema,
5
+ platformMachineGameSlugAvailabilityInputSchema,
6
+ platformMachineGameSlugAvailabilitySchema,
7
+ } from "@air-jam/sdk/platform-machine";
8
+ import {
9
+ requestPlatformMachineApi,
10
+ resolvePlatformMachineAuth,
11
+ } from "./platform-auth.js";
12
+
13
+ type GameAppIdOptions = {
14
+ platformUrl?: string;
15
+ token?: string;
16
+ slugOrId: string;
17
+ };
18
+
19
+ export const inspectPlatformGameAppId = async ({
20
+ platformUrl,
21
+ token,
22
+ slugOrId,
23
+ }: GameAppIdOptions) => {
24
+ const resolved = await resolvePlatformMachineAuth({ platformUrl, token });
25
+ return requestPlatformMachineApi({
26
+ baseUrl: resolved.baseUrl,
27
+ pathname: `/api/cli/games/${encodeURIComponent(slugOrId)}/app-id`,
28
+ token: resolved.token,
29
+ schema: platformMachineGameAppIdSchema,
30
+ });
31
+ };
32
+
33
+ export const updatePlatformGameAppIdOrigins = async ({
34
+ platformUrl,
35
+ token,
36
+ slugOrId,
37
+ allowedOrigins,
38
+ }: GameAppIdOptions & { allowedOrigins: string[] }) => {
39
+ const input = platformMachineGameAppIdOriginsInputSchema.parse({
40
+ allowedOrigins,
41
+ });
42
+ const resolved = await resolvePlatformMachineAuth({ platformUrl, token });
43
+ return requestPlatformMachineApi({
44
+ baseUrl: resolved.baseUrl,
45
+ pathname: `/api/cli/games/${encodeURIComponent(slugOrId)}/app-id/origins`,
46
+ method: "POST",
47
+ token: resolved.token,
48
+ body: input,
49
+ schema: platformMachineGameAppIdSchema,
50
+ });
51
+ };
52
+
53
+ export const regeneratePlatformGameAppId = async ({
54
+ platformUrl,
55
+ token,
56
+ slugOrId,
57
+ yes,
58
+ }: GameAppIdOptions & { yes?: boolean }) => {
59
+ if (!yes)
60
+ throw new Error(
61
+ "Regenerating the App ID breaks deployed games. Pass --yes to confirm.",
62
+ );
63
+ const input = platformMachineGameAppIdRegenerateInputSchema.parse({ yes });
64
+ const resolved = await resolvePlatformMachineAuth({ platformUrl, token });
65
+ return requestPlatformMachineApi({
66
+ baseUrl: resolved.baseUrl,
67
+ pathname: `/api/cli/games/${encodeURIComponent(slugOrId)}/app-id/regenerate`,
68
+ method: "POST",
69
+ token: resolved.token,
70
+ body: input,
71
+ schema: platformMachineGameAppIdSchema,
72
+ });
73
+ };
74
+
75
+ export const checkPlatformGameSlugAvailability = async ({
76
+ platformUrl,
77
+ token,
78
+ slug,
79
+ game,
80
+ }: {
81
+ platformUrl?: string;
82
+ token?: string;
83
+ slug: string;
84
+ game?: string;
85
+ }) => {
86
+ const input = platformMachineGameSlugAvailabilityInputSchema.parse({
87
+ slug,
88
+ game,
89
+ });
90
+ const query = new URLSearchParams({ slug: input.slug });
91
+ if (input.game !== undefined) query.set("game", input.game);
92
+ const resolved = await resolvePlatformMachineAuth({ platformUrl, token });
93
+ return requestPlatformMachineApi({
94
+ baseUrl: resolved.baseUrl,
95
+ pathname: `/api/cli/games/slug-availability?${query}`,
96
+ token: resolved.token,
97
+ schema: platformMachineGameSlugAvailabilitySchema,
98
+ });
99
+ };
@@ -0,0 +1,209 @@
1
+ import {
2
+ platformMachineGetOwnedGameMediaResultSchema,
3
+ platformMachineMutateOwnedGameMediaAssetResultSchema,
4
+ platformMachineRequestOwnedGameMediaUploadTargetResultSchema,
5
+ } from "@air-jam/sdk/platform-machine";
6
+ import { readFile, stat } from "node:fs/promises";
7
+ import path from "node:path";
8
+ import {
9
+ requestPlatformMachineApi,
10
+ resolvePlatformMachineAuth,
11
+ } from "./platform-auth.js";
12
+ import type {
13
+ InspectPlatformGameMediaOptions,
14
+ MutatePlatformGameMediaAssetOptions,
15
+ RequestPlatformGameMediaUploadTargetOptions,
16
+ UploadPlatformGameMediaFileOptions,
17
+ } from "./types.js";
18
+
19
+ export type {
20
+ InspectPlatformGameMediaOptions,
21
+ MutatePlatformGameMediaAssetOptions,
22
+ RequestPlatformGameMediaUploadTargetOptions,
23
+ UploadPlatformGameMediaFileOptions,
24
+ } from "./types.js";
25
+
26
+ const MEDIA_FILE_CONTENT_TYPES: Record<
27
+ "thumbnail" | "cover" | "preview_video",
28
+ Record<string, string>
29
+ > = {
30
+ thumbnail: {
31
+ ".jpg": "image/jpeg",
32
+ ".jpeg": "image/jpeg",
33
+ ".png": "image/png",
34
+ ".webp": "image/webp",
35
+ },
36
+ cover: {
37
+ ".jpg": "image/jpeg",
38
+ ".jpeg": "image/jpeg",
39
+ ".png": "image/png",
40
+ ".webp": "image/webp",
41
+ },
42
+ preview_video: {
43
+ ".mp4": "video/mp4",
44
+ ".webm": "video/webm",
45
+ },
46
+ };
47
+
48
+ const inferMediaContentType = ({
49
+ kind,
50
+ filePath,
51
+ }: {
52
+ kind: "thumbnail" | "cover" | "preview_video";
53
+ filePath: string;
54
+ }): string => {
55
+ const extension = path.extname(filePath).toLowerCase();
56
+ const contentType = MEDIA_FILE_CONTENT_TYPES[kind][extension];
57
+
58
+ if (!contentType) {
59
+ throw new Error(
60
+ `Unsupported file extension for ${kind.replaceAll("_", " ")}: ${extension || "(none)"}`,
61
+ );
62
+ }
63
+
64
+ return contentType;
65
+ };
66
+
67
+ export const inspectPlatformGameMedia = async ({
68
+ platformUrl,
69
+ token,
70
+ slugOrId,
71
+ }: InspectPlatformGameMediaOptions) => {
72
+ const resolved = await resolvePlatformMachineAuth({ platformUrl, token });
73
+
74
+ return requestPlatformMachineApi({
75
+ baseUrl: resolved.baseUrl,
76
+ pathname: `/api/cli/games/${encodeURIComponent(slugOrId)}/media`,
77
+ token: resolved.token,
78
+ schema: platformMachineGetOwnedGameMediaResultSchema,
79
+ });
80
+ };
81
+
82
+ export const requestPlatformGameMediaUploadTarget = async ({
83
+ platformUrl,
84
+ token,
85
+ slugOrId,
86
+ input,
87
+ }: RequestPlatformGameMediaUploadTargetOptions) => {
88
+ const resolved = await resolvePlatformMachineAuth({ platformUrl, token });
89
+
90
+ return requestPlatformMachineApi({
91
+ baseUrl: resolved.baseUrl,
92
+ pathname: `/api/cli/games/${encodeURIComponent(slugOrId)}/media`,
93
+ method: "POST",
94
+ token: resolved.token,
95
+ body: input,
96
+ schema: platformMachineRequestOwnedGameMediaUploadTargetResultSchema,
97
+ });
98
+ };
99
+
100
+ const mutatePlatformGameMediaAsset = async ({
101
+ platformUrl,
102
+ token,
103
+ slugOrId,
104
+ assetId,
105
+ action,
106
+ }: MutatePlatformGameMediaAssetOptions & {
107
+ action: "finalize" | "assign" | "archive";
108
+ }) => {
109
+ const resolved = await resolvePlatformMachineAuth({ platformUrl, token });
110
+
111
+ return requestPlatformMachineApi({
112
+ baseUrl: resolved.baseUrl,
113
+ pathname: `/api/cli/games/${encodeURIComponent(slugOrId)}/media/${encodeURIComponent(assetId)}/${action}`,
114
+ method: "POST",
115
+ token: resolved.token,
116
+ schema: platformMachineMutateOwnedGameMediaAssetResultSchema,
117
+ });
118
+ };
119
+
120
+ export const finalizePlatformGameMediaUpload = (
121
+ options: MutatePlatformGameMediaAssetOptions,
122
+ ) =>
123
+ mutatePlatformGameMediaAsset({
124
+ ...options,
125
+ action: "finalize",
126
+ });
127
+
128
+ export const assignPlatformGameMediaAsset = (
129
+ options: MutatePlatformGameMediaAssetOptions,
130
+ ) =>
131
+ mutatePlatformGameMediaAsset({
132
+ ...options,
133
+ action: "assign",
134
+ });
135
+
136
+ export const archivePlatformGameMediaAsset = (
137
+ options: MutatePlatformGameMediaAssetOptions,
138
+ ) =>
139
+ mutatePlatformGameMediaAsset({
140
+ ...options,
141
+ action: "archive",
142
+ });
143
+
144
+ export const uploadPlatformGameMediaFile = async ({
145
+ platformUrl,
146
+ token,
147
+ slugOrId,
148
+ kind,
149
+ filePath,
150
+ }: UploadPlatformGameMediaFileOptions) => {
151
+ const resolvedFilePath = path.resolve(filePath);
152
+ const fileStats = await stat(resolvedFilePath);
153
+
154
+ if (!fileStats.isFile()) {
155
+ throw new Error(`Media path is not a file: ${resolvedFilePath}`);
156
+ }
157
+
158
+ const contentType = inferMediaContentType({
159
+ kind,
160
+ filePath: resolvedFilePath,
161
+ });
162
+
163
+ const created = await requestPlatformGameMediaUploadTarget({
164
+ platformUrl,
165
+ token,
166
+ slugOrId,
167
+ input: {
168
+ kind,
169
+ originalFilename: path.basename(resolvedFilePath),
170
+ contentType,
171
+ sizeBytes: fileStats.size,
172
+ },
173
+ });
174
+
175
+ const uploadResponse = await fetch(created.upload.url, {
176
+ method: created.upload.method,
177
+ headers: created.upload.headers,
178
+ body: await readFile(resolvedFilePath),
179
+ });
180
+
181
+ if (!uploadResponse.ok) {
182
+ throw new Error(
183
+ `Media upload failed with status ${uploadResponse.status}.`,
184
+ );
185
+ }
186
+
187
+ const finalized = await finalizePlatformGameMediaUpload({
188
+ platformUrl,
189
+ token,
190
+ slugOrId,
191
+ assetId: created.asset.id,
192
+ });
193
+
194
+ const assigned = await assignPlatformGameMediaAsset({
195
+ platformUrl,
196
+ token,
197
+ slugOrId,
198
+ assetId: created.asset.id,
199
+ });
200
+
201
+ return {
202
+ requested: created,
203
+ finalized,
204
+ assigned,
205
+ filePath: resolvedFilePath,
206
+ sizeBytes: fileStats.size,
207
+ contentType,
208
+ };
209
+ };
@@ -0,0 +1,217 @@
1
+ import {
2
+ platformMachineCreateOwnedGameResultSchema,
3
+ platformMachineGetOwnedGameResultSchema,
4
+ platformMachineListOwnedGamesResultSchema,
5
+ platformMachineUpdateOwnedGameResultSchema,
6
+ } from "@air-jam/sdk/platform-machine";
7
+ import { readFile } from "node:fs/promises";
8
+ import path from "node:path";
9
+ import { findUp, pathExists, readPackageJson } from "./fs-utils.js";
10
+ import { inspectGame } from "./games.js";
11
+ import {
12
+ requestPlatformMachineApi,
13
+ resolvePlatformMachineAuth,
14
+ } from "./platform-auth.js";
15
+ import type {
16
+ AirJamLocalHostedGameDefaults,
17
+ CreatePlatformGameOptions,
18
+ InspectPlatformGameOptions,
19
+ ListPlatformGamesOptions,
20
+ UpdatePlatformGameOptions,
21
+ } from "./types.js";
22
+
23
+ export type {
24
+ AirJamLocalHostedGameDefaults,
25
+ CreatePlatformGameOptions,
26
+ InspectPlatformGameOptions,
27
+ ListPlatformGamesOptions,
28
+ UpdatePlatformGameOptions,
29
+ } from "./types.js";
30
+
31
+ const normalizeGithubRemoteUrl = (value: string): string | null => {
32
+ const trimmed = value.trim();
33
+ if (!trimmed) {
34
+ return null;
35
+ }
36
+
37
+ if (trimmed.startsWith("git@github.com:")) {
38
+ const repoPath = trimmed
39
+ .slice("git@github.com:".length)
40
+ .replace(/\.git$/, "");
41
+ return repoPath ? `https://github.com/${repoPath}` : null;
42
+ }
43
+
44
+ try {
45
+ const url = new URL(trimmed);
46
+ if (url.hostname !== "github.com") {
47
+ return null;
48
+ }
49
+
50
+ return `https://github.com${url.pathname.replace(/\.git$/, "")}`.replace(
51
+ /\/$/,
52
+ "",
53
+ );
54
+ } catch {
55
+ return null;
56
+ }
57
+ };
58
+
59
+ const readGitRemoteFromConfig = async (
60
+ gitDirOrFilePath: string,
61
+ ): Promise<string | null> => {
62
+ let configPath: string | null = null;
63
+
64
+ const statsFile = await readFile(gitDirOrFilePath, "utf8").catch(() => null);
65
+ if (statsFile?.startsWith("gitdir:")) {
66
+ const relativeGitDir = statsFile.slice("gitdir:".length).trim();
67
+ const resolvedGitDir = path.resolve(
68
+ path.dirname(gitDirOrFilePath),
69
+ relativeGitDir,
70
+ );
71
+ configPath = path.join(resolvedGitDir, "config");
72
+ } else {
73
+ configPath = path.join(gitDirOrFilePath, "config");
74
+ }
75
+
76
+ if (!(await pathExists(configPath))) {
77
+ return null;
78
+ }
79
+
80
+ const config = await readFile(configPath, "utf8");
81
+ const remoteBlockMatch = config.match(
82
+ /\[remote "origin"\][\s\S]*?(?:\n\[|$)/,
83
+ );
84
+ if (!remoteBlockMatch) {
85
+ return null;
86
+ }
87
+
88
+ const urlMatch = remoteBlockMatch[0].match(/^\s*url\s*=\s*(.+)$/m);
89
+ return urlMatch?.[1]?.trim() || null;
90
+ };
91
+
92
+ const resolveRepoSourceUrl = async ({
93
+ projectDir,
94
+ }: {
95
+ projectDir: string;
96
+ }): Promise<string | null> => {
97
+ const gitMarkerPath = await findUp(projectDir, ".git");
98
+ if (!gitMarkerPath) {
99
+ return null;
100
+ }
101
+
102
+ const repoRoot = path.dirname(gitMarkerPath);
103
+ const remoteUrl = await readGitRemoteFromConfig(gitMarkerPath);
104
+ const normalizedRemoteUrl = remoteUrl
105
+ ? normalizeGithubRemoteUrl(remoteUrl)
106
+ : null;
107
+
108
+ if (!normalizedRemoteUrl) {
109
+ return null;
110
+ }
111
+
112
+ const relativeProjectPath = path.relative(repoRoot, projectDir);
113
+ if (!relativeProjectPath || relativeProjectPath.startsWith("..")) {
114
+ return null;
115
+ }
116
+
117
+ return `${normalizedRemoteUrl}/tree/main/${relativeProjectPath.replaceAll(path.sep, "/")}`;
118
+ };
119
+
120
+ export const readLocalHostedGameDefaults = async ({
121
+ cwd = process.cwd(),
122
+ }: {
123
+ cwd?: string;
124
+ } = {}): Promise<AirJamLocalHostedGameDefaults> => {
125
+ const game = await inspectGame({ cwd });
126
+ const [packageJson, sourceUrl] = await Promise.all([
127
+ readPackageJson(game.rootDir),
128
+ resolveRepoSourceUrl({ projectDir: game.rootDir }),
129
+ ]);
130
+
131
+ const metadata = game.declaration.metadata;
132
+ return {
133
+ projectDir: game.rootDir,
134
+ configPath: game.configPath,
135
+ manifestPath: game.manifestPath,
136
+ packageJsonPath: packageJson?.path ?? null,
137
+ packageName: game.packageName,
138
+ sourceUrl,
139
+ metadata: {
140
+ name: metadata.name,
141
+ slug: metadata.slug,
142
+ description: metadata.tagline,
143
+ category: metadata.category,
144
+ tags: [...(metadata.tags ?? [])],
145
+ },
146
+ template: {
147
+ id: metadata.slug,
148
+ name: metadata.name,
149
+ description: metadata.tagline,
150
+ category: metadata.category,
151
+ },
152
+ };
153
+ };
154
+
155
+ export const listPlatformGames = async ({
156
+ platformUrl,
157
+ token,
158
+ }: ListPlatformGamesOptions = {}) => {
159
+ const resolved = await resolvePlatformMachineAuth({ platformUrl, token });
160
+
161
+ return requestPlatformMachineApi({
162
+ baseUrl: resolved.baseUrl,
163
+ pathname: "/api/cli/games",
164
+ token: resolved.token,
165
+ schema: platformMachineListOwnedGamesResultSchema,
166
+ });
167
+ };
168
+
169
+ export const inspectPlatformGame = async ({
170
+ platformUrl,
171
+ token,
172
+ slugOrId,
173
+ }: InspectPlatformGameOptions) => {
174
+ const resolved = await resolvePlatformMachineAuth({ platformUrl, token });
175
+
176
+ return requestPlatformMachineApi({
177
+ baseUrl: resolved.baseUrl,
178
+ pathname: `/api/cli/games/${encodeURIComponent(slugOrId)}`,
179
+ token: resolved.token,
180
+ schema: platformMachineGetOwnedGameResultSchema,
181
+ });
182
+ };
183
+
184
+ export const createPlatformGame = async ({
185
+ platformUrl,
186
+ token,
187
+ input,
188
+ }: CreatePlatformGameOptions) => {
189
+ const resolved = await resolvePlatformMachineAuth({ platformUrl, token });
190
+
191
+ return requestPlatformMachineApi({
192
+ baseUrl: resolved.baseUrl,
193
+ pathname: "/api/cli/games",
194
+ method: "POST",
195
+ token: resolved.token,
196
+ body: input,
197
+ schema: platformMachineCreateOwnedGameResultSchema,
198
+ });
199
+ };
200
+
201
+ export const updatePlatformGame = async ({
202
+ platformUrl,
203
+ token,
204
+ slugOrId,
205
+ input,
206
+ }: UpdatePlatformGameOptions) => {
207
+ const resolved = await resolvePlatformMachineAuth({ platformUrl, token });
208
+
209
+ return requestPlatformMachineApi({
210
+ baseUrl: resolved.baseUrl,
211
+ pathname: `/api/cli/games/${encodeURIComponent(slugOrId)}`,
212
+ method: "PATCH",
213
+ token: resolved.token,
214
+ body: input,
215
+ schema: platformMachineUpdateOwnedGameResultSchema,
216
+ });
217
+ };
@@ -0,0 +1,52 @@
1
+ import { z } from "zod";
2
+
3
+ export const policyArtifactPathSchema = z
4
+ .string()
5
+ .min(1)
6
+ .max(240)
7
+ .refine(
8
+ (value) =>
9
+ !value.includes("\\") &&
10
+ !value.startsWith("/") &&
11
+ value
12
+ .split("/")
13
+ .every((part) => part !== "" && part !== "." && part !== ".."),
14
+ "Artifacts require canonical relative paths.",
15
+ );
16
+ export const policyArtifactManifestSchema = z
17
+ .object({
18
+ version: z.literal(1),
19
+ provenance: z.record(z.string().min(1).max(80), z.json()),
20
+ files: z
21
+ .array(
22
+ z
23
+ .object({
24
+ path: policyArtifactPathSchema,
25
+ bytes: z
26
+ .number()
27
+ .int()
28
+ .positive()
29
+ .max(4 * 1024 ** 3),
30
+ sha256: z.string().regex(/^[a-f0-9]{64}$/),
31
+ })
32
+ .strict(),
33
+ )
34
+ .min(1)
35
+ .max(32),
36
+ })
37
+ .strict()
38
+ .refine(
39
+ (value) =>
40
+ new Set(value.files.map((file) => file.path)).size ===
41
+ value.files.length &&
42
+ value.files.reduce((bytes, file) => bytes + file.bytes, 0) <=
43
+ 4 * 1024 ** 3,
44
+ "Artifact files must be unique and fit the 4 GiB bundle allowance.",
45
+ );
46
+ export const policyArtifactReceiptSchema = z
47
+ .object({
48
+ manifestSha256: z.string().regex(/^[a-f0-9]{64}$/),
49
+ manifest: policyArtifactManifestSchema,
50
+ verifyMs: z.number().finite().nonnegative(),
51
+ })
52
+ .strict();
@@ -0,0 +1,134 @@
1
+ import { createHash } from "node:crypto";
2
+ import { constants, createReadStream } from "node:fs";
3
+ import { access, lstat, readFile, readdir, realpath } from "node:fs/promises";
4
+ import path from "node:path";
5
+ import type { z } from "zod";
6
+ import {
7
+ policyArtifactManifestSchema,
8
+ policyArtifactReceiptSchema,
9
+ } from "./policy-artifact-contract.js";
10
+
11
+ async function assertProtectedEntry(target: string, directory: boolean) {
12
+ const information = await lstat(target);
13
+ if (directory ? !information.isDirectory() : !information.isFile())
14
+ throw new Error(
15
+ "policy_artifact_invalid: Expected a regular artifact entry, without symlinks.",
16
+ );
17
+ if (
18
+ !process.getuid ||
19
+ process.getuid() === 0 ||
20
+ information.uid === process.getuid()
21
+ )
22
+ throw new Error(
23
+ "policy_artifact_writable: Artifacts require an independent filesystem owner and a non-root policy.",
24
+ );
25
+ try {
26
+ await access(target, constants.W_OK);
27
+ } catch (error) {
28
+ if (error instanceof Error && "code" in error && error.code === "EACCES")
29
+ return;
30
+ throw error;
31
+ }
32
+ throw new Error(
33
+ "policy_artifact_writable: Policy artifacts must be read-only to the workload.",
34
+ );
35
+ }
36
+
37
+ /** This validates public, independently provisioned files; it does not download or run models. */
38
+ export async function verifyPolicyArtifacts(options: {
39
+ projectDir: string;
40
+ manifestPath: string;
41
+ artifactRootDir?: string;
42
+ signal?: AbortSignal;
43
+ }): Promise<{
44
+ directory: string;
45
+ receipt: z.infer<typeof policyArtifactReceiptSchema>;
46
+ }> {
47
+ const started = performance.now();
48
+ options.signal?.throwIfAborted();
49
+ if (!options.artifactRootDir || !path.isAbsolute(options.artifactRootDir))
50
+ throw new Error(
51
+ "policy_artifacts_missing: Configure an absolute AIRJAM_TEST_ARTIFACTS_DIR for this policy.",
52
+ );
53
+ const project = await realpath(options.projectDir);
54
+ const manifestPath = await realpath(options.manifestPath);
55
+ const relative = path.relative(project, manifestPath);
56
+ if (
57
+ !relative ||
58
+ relative === ".." ||
59
+ relative.startsWith(`..${path.sep}`) ||
60
+ path.isAbsolute(relative)
61
+ )
62
+ throw new Error(
63
+ "policy_artifact_invalid: The manifest must be pinned inside the project source.",
64
+ );
65
+ if ((await lstat(manifestPath)).size > 64 * 1024)
66
+ throw new Error("policy_artifact_invalid: Manifest exceeds 64 KiB.");
67
+ const content = await readFile(manifestPath, { signal: options.signal });
68
+ const manifest = policyArtifactManifestSchema.parse(
69
+ JSON.parse(content.toString("utf8")),
70
+ );
71
+ const manifestSha256 = createHash("sha256").update(content).digest("hex");
72
+ const directory = path.join(options.artifactRootDir, manifestSha256);
73
+ const directories = new Set<string>();
74
+ let ancestor = directory;
75
+ while (true) {
76
+ directories.add(ancestor);
77
+ const parent = path.dirname(ancestor);
78
+ if (parent === ancestor) break;
79
+ ancestor = parent;
80
+ }
81
+ for (const file of manifest.files) {
82
+ let parent = path.dirname(path.join(directory, file.path));
83
+ while (parent !== directory) {
84
+ directories.add(parent);
85
+ parent = path.dirname(parent);
86
+ }
87
+ }
88
+ for (const parent of directories) await assertProtectedEntry(parent, true);
89
+ const expected = new Set(manifest.files.map((file) => file.path));
90
+ const pending = [""];
91
+ for (const relative of pending) {
92
+ options.signal?.throwIfAborted();
93
+ for (const entry of await readdir(path.join(directory, relative), {
94
+ withFileTypes: true,
95
+ })) {
96
+ const name = relative ? `${relative}/${entry.name}` : entry.name;
97
+ if (
98
+ entry.isDirectory() &&
99
+ [...expected].some((file) => file.startsWith(name + "/"))
100
+ )
101
+ pending.push(name);
102
+ else if (!entry.isFile() || !expected.has(name))
103
+ throw new Error(
104
+ `policy_artifact_invalid: Unlisted artifact entry: ${name}.`,
105
+ );
106
+ }
107
+ }
108
+ for (const file of manifest.files) {
109
+ options.signal?.throwIfAborted();
110
+ const target = path.join(directory, file.path);
111
+ await assertProtectedEntry(target, false);
112
+ if ((await lstat(target)).size !== file.bytes)
113
+ throw new Error(
114
+ `policy_artifact_invalid: Size differs for ${file.path}.`,
115
+ );
116
+ const hash = createHash("sha256");
117
+ for await (const chunk of createReadStream(target, {
118
+ signal: options.signal,
119
+ }))
120
+ hash.update(chunk);
121
+ if (hash.digest("hex") !== file.sha256)
122
+ throw new Error(
123
+ `policy_artifact_invalid: Digest differs for ${file.path}.`,
124
+ );
125
+ }
126
+ return {
127
+ directory,
128
+ receipt: policyArtifactReceiptSchema.parse({
129
+ manifestSha256,
130
+ manifest,
131
+ verifyMs: performance.now() - started,
132
+ }),
133
+ };
134
+ }