@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,749 @@
1
+ import {
2
+ assertSupportedDevMode,
3
+ detectProjectContext,
4
+ inspectGame,
5
+ listGames,
6
+ pathExists,
7
+ readWorkspaceContract,
8
+ runCommandResult
9
+ } from "./chunk-ART5TEYT.js";
10
+ import {
11
+ resolveDevtoolsHelperArgs,
12
+ resolveDevtoolsHelperScript
13
+ } from "./chunk-PKD4WVX5.js";
14
+
15
+ // src/dev.ts
16
+ import {
17
+ parseRuntimeTopology,
18
+ runtimeTopologyToQueryParams
19
+ } from "@air-jam/sdk/runtime-topology";
20
+ import crossSpawn from "cross-spawn";
21
+ import { randomUUID } from "crypto";
22
+ import { closeSync, openSync } from "fs";
23
+ import { mkdir, readFile, rm, writeFile } from "fs/promises";
24
+ import http from "http";
25
+ import https from "https";
26
+ import path from "path";
27
+ var DEVTOOLS_SCHEMA_VERSION = 1;
28
+ var START_TIMEOUT_MS = 12e4;
29
+ var KNOWN_LOCAL_DEV_PORTS = [4e3, 5173];
30
+ var KNOWN_PORTS_ENV = "AIRJAM_DEVTOOLS_KNOWN_PORTS";
31
+ var DEFAULT_CONTROLLER_PATH = "/controller";
32
+ var MANAGED_PROCESS_STOP_TIMEOUT_MS = 1e4;
33
+ var toTopologyMode = (mode) => {
34
+ if (mode === "arcade-dev") {
35
+ return "arcade-live";
36
+ }
37
+ if (mode === "arcade-test") {
38
+ return "arcade-built";
39
+ }
40
+ return "standalone-dev";
41
+ };
42
+ var isKnownProjectMode = (mode) => mode === "monorepo" || mode === "standalone-game";
43
+ var getDevtoolsRoot = (rootDir) => path.join(rootDir, ".airjam", "devtools");
44
+ var getManagedRegistryPath = (rootDir) => path.join(getDevtoolsRoot(rootDir), "managed-processes.json");
45
+ var getManagedProcessLogPath = (rootDir, processId) => path.join(getDevtoolsRoot(rootDir), "processes", `${processId}.log`);
46
+ var isProcessAlive = (pid) => {
47
+ if (!Number.isInteger(pid) || pid <= 0) {
48
+ return false;
49
+ }
50
+ try {
51
+ process.kill(pid, 0);
52
+ return true;
53
+ } catch {
54
+ return false;
55
+ }
56
+ };
57
+ var readCommandOutput = (command, args) => {
58
+ try {
59
+ return runCommandResult({
60
+ command,
61
+ args,
62
+ cwd: process.cwd()
63
+ }).stdout.trim();
64
+ } catch {
65
+ return null;
66
+ }
67
+ };
68
+ var readListeningPidsForPort = (port) => {
69
+ const output = readCommandOutput("lsof", [
70
+ "-nP",
71
+ `-tiTCP:${port}`,
72
+ "-sTCP:LISTEN"
73
+ ]);
74
+ if (!output) {
75
+ return [];
76
+ }
77
+ return output.split(/\r?\n/).map((value) => Number.parseInt(value.trim(), 10)).filter((value) => Number.isInteger(value) && value > 0);
78
+ };
79
+ var readProcessCommand = (pid) => {
80
+ const output = readCommandOutput("ps", ["-p", String(pid), "-o", "command="]);
81
+ return output && output.length > 0 ? output : null;
82
+ };
83
+ var readProcessAgeMs = (pid) => {
84
+ const output = readCommandOutput("ps", ["-p", String(pid), "-o", "etimes="]);
85
+ const seconds = output ? Number.parseInt(output.trim(), 10) : Number.NaN;
86
+ return Number.isFinite(seconds) && seconds >= 0 ? seconds * 1e3 : null;
87
+ };
88
+ var getKnownLocalDevPorts = () => {
89
+ const rawPorts = process.env[KNOWN_PORTS_ENV];
90
+ if (!rawPorts) {
91
+ return [...KNOWN_LOCAL_DEV_PORTS];
92
+ }
93
+ const ports = rawPorts.split(",").map((value) => Number.parseInt(value.trim(), 10)).filter((value) => Number.isInteger(value) && value > 0);
94
+ return ports.length > 0 ? Array.from(new Set(ports)) : [...KNOWN_LOCAL_DEV_PORTS];
95
+ };
96
+ var isLikelyAirJamLocalDevCommand = (command) => {
97
+ if (!command) {
98
+ return false;
99
+ }
100
+ return /(^|\W)(@air-jam\/server|air-jam-server|airjam|vite|create-airjam)(\W|$)/.test(
101
+ command
102
+ );
103
+ };
104
+ var listKnownPortListeners = () => {
105
+ const byPid = /* @__PURE__ */ new Map();
106
+ for (const port of getKnownLocalDevPorts()) {
107
+ for (const pid of readListeningPidsForPort(port)) {
108
+ const ports = byPid.get(pid) ?? /* @__PURE__ */ new Set();
109
+ ports.add(port);
110
+ byPid.set(pid, ports);
111
+ }
112
+ }
113
+ return Array.from(byPid.entries()).map(([pid, ports]) => {
114
+ const ageMs = readProcessAgeMs(pid);
115
+ return {
116
+ pid,
117
+ ports: Array.from(ports).sort((left, right) => left - right),
118
+ command: readProcessCommand(pid),
119
+ startedAt: ageMs !== null ? new Date(Date.now() - ageMs).toISOString() : null,
120
+ ageMs,
121
+ managed: false
122
+ };
123
+ }).sort((left, right) => left.pid - right.pid);
124
+ };
125
+ var waitForProcessExit = async (pid, timeoutMs = MANAGED_PROCESS_STOP_TIMEOUT_MS) => {
126
+ const startedAt = Date.now();
127
+ while (Date.now() - startedAt < timeoutMs) {
128
+ if (!isProcessAlive(pid)) {
129
+ return true;
130
+ }
131
+ await new Promise((resolve) => setTimeout(resolve, 100));
132
+ }
133
+ return !isProcessAlive(pid);
134
+ };
135
+ var terminateManagedProcess = async (pid) => {
136
+ if (!Number.isInteger(pid) || pid <= 0) {
137
+ return;
138
+ }
139
+ if (!isProcessAlive(pid)) {
140
+ return;
141
+ }
142
+ if (process.platform === "win32") {
143
+ runCommandResult({
144
+ command: "taskkill",
145
+ args: ["/PID", String(pid), "/T", "/F"],
146
+ cwd: process.cwd()
147
+ });
148
+ } else {
149
+ try {
150
+ process.kill(-pid, "SIGTERM");
151
+ } catch {
152
+ try {
153
+ process.kill(pid, "SIGTERM");
154
+ } catch {
155
+ }
156
+ }
157
+ }
158
+ if (!await waitForProcessExit(pid)) {
159
+ if (process.platform !== "win32") {
160
+ try {
161
+ process.kill(-pid, "SIGKILL");
162
+ } catch {
163
+ try {
164
+ process.kill(pid, "SIGKILL");
165
+ } catch {
166
+ }
167
+ }
168
+ }
169
+ if (!await waitForProcessExit(pid, 2e3)) {
170
+ throw new Error(`Managed Air Jam dev process ${pid} did not terminate.`);
171
+ }
172
+ }
173
+ };
174
+ var readRegistry = async (rootDir) => {
175
+ const registryPath = getManagedRegistryPath(rootDir);
176
+ if (!await pathExists(registryPath)) {
177
+ return {
178
+ schemaVersion: DEVTOOLS_SCHEMA_VERSION,
179
+ processes: []
180
+ };
181
+ }
182
+ const parsed = JSON.parse(
183
+ await readFile(registryPath, "utf8")
184
+ );
185
+ return {
186
+ schemaVersion: DEVTOOLS_SCHEMA_VERSION,
187
+ processes: Array.isArray(parsed.processes) ? parsed.processes : []
188
+ };
189
+ };
190
+ var writeRegistry = async (rootDir, registry) => {
191
+ const registryPath = getManagedRegistryPath(rootDir);
192
+ await mkdir(path.dirname(registryPath), { recursive: true });
193
+ await writeFile(
194
+ registryPath,
195
+ `${JSON.stringify(registry, null, 2)}
196
+ `,
197
+ "utf8"
198
+ );
199
+ };
200
+ var listManagedProcessesForRoot = async (rootDir) => {
201
+ const registry = await readRegistry(rootDir);
202
+ const aliveProcesses = registry.processes.filter(
203
+ (processInfo) => isProcessAlive(processInfo.pid)
204
+ );
205
+ if (aliveProcesses.length !== registry.processes.length) {
206
+ await writeRegistry(rootDir, {
207
+ schemaVersion: DEVTOOLS_SCHEMA_VERSION,
208
+ processes: aliveProcesses
209
+ });
210
+ }
211
+ return aliveProcesses.sort(
212
+ (left, right) => left.startedAt.localeCompare(right.startedAt)
213
+ );
214
+ };
215
+ var appendArg = (args, flag, value) => {
216
+ if (value === void 0 || value === false || value === "") {
217
+ return;
218
+ }
219
+ if (value === true) {
220
+ args.push(flag);
221
+ return;
222
+ }
223
+ args.push(`${flag}=${value}`);
224
+ };
225
+ var resolveWorkspaceCliPath = (context) => {
226
+ const workspace = readWorkspaceContract(context.packageJson);
227
+ if (!workspace)
228
+ throw new Error(
229
+ "Air Jam workspace must declare airjam.workspace in package.json."
230
+ );
231
+ return path.resolve(context.rootDir, workspace.cli);
232
+ };
233
+ var resolveStartCommand = async ({
234
+ context,
235
+ cwd,
236
+ gameId,
237
+ mode,
238
+ secure
239
+ }) => {
240
+ if (context.mode === "monorepo") {
241
+ if (!gameId) {
242
+ throw new Error("Monorepo dev start requires a game id.");
243
+ }
244
+ const script = mode === "arcade-dev" ? "arcade:dev" : mode === "arcade-test" ? "arcade:test" : "standalone:dev";
245
+ const args2 = [
246
+ resolveWorkspaceCliPath(context),
247
+ "workspace",
248
+ script,
249
+ `--game=${gameId}`
250
+ ];
251
+ appendArg(args2, "--secure", secure);
252
+ return {
253
+ command: process.execPath,
254
+ args: args2,
255
+ topologyMode: toTopologyMode(mode),
256
+ expectedLogPath: path.join(cwd, ".airjam", "logs", "dev-latest.ndjson")
257
+ };
258
+ }
259
+ if (context.mode !== "standalone-game") {
260
+ throw new Error(
261
+ "Air Jam dev start is only available in known project modes."
262
+ );
263
+ }
264
+ const args = context.packageJson?.scripts?.dev !== void 0 ? ["run", "dev"] : ["exec", "airjam", "dev"];
265
+ if (secure) {
266
+ args.push("--", "--secure");
267
+ }
268
+ return {
269
+ command: "pnpm",
270
+ args,
271
+ topologyMode: "standalone-dev",
272
+ expectedLogPath: path.join(cwd, ".airjam", "logs", "dev-latest.ndjson")
273
+ };
274
+ };
275
+ var parseJsonFromCommandOutput = (output) => {
276
+ const startIndex = output.indexOf("{");
277
+ const endIndex = output.lastIndexOf("}");
278
+ if (startIndex === -1 || endIndex === -1 || endIndex < startIndex) {
279
+ throw new Error(`Expected JSON output but received:
280
+ ${output}`);
281
+ }
282
+ return JSON.parse(output.slice(startIndex, endIndex + 1));
283
+ };
284
+ var resolveTopologyCommand = async ({
285
+ context,
286
+ gameId,
287
+ mode,
288
+ secure
289
+ }) => {
290
+ const topologyMode = toTopologyMode(mode);
291
+ if (context.mode === "monorepo") {
292
+ if (!gameId) {
293
+ throw new Error("Monorepo topology inspection requires a game id.");
294
+ }
295
+ const args2 = [
296
+ resolveWorkspaceCliPath(context),
297
+ "workspace",
298
+ "topology",
299
+ `--game=${gameId}`,
300
+ `--mode=${topologyMode}`
301
+ ];
302
+ appendArg(args2, "--secure", secure);
303
+ return {
304
+ command: process.execPath,
305
+ args: args2,
306
+ topologyMode
307
+ };
308
+ }
309
+ if (context.mode !== "standalone-game") {
310
+ throw new Error(
311
+ "Air Jam topology is only available in known project modes."
312
+ );
313
+ }
314
+ const topologyScript = context.packageJson?.scripts?.topology?.trim();
315
+ const topologyScriptUsesAirJamCli = typeof topologyScript === "string" && /\bairjam\s+topology\b/.test(topologyScript);
316
+ const args = topologyScript && !topologyScriptUsesAirJamCli ? ["run", "topology", "--", "--mode=standalone-dev"] : ["exec", "airjam", "topology", "--mode=standalone-dev"];
317
+ appendArg(args, "--secure", secure);
318
+ return {
319
+ command: "pnpm",
320
+ args,
321
+ topologyMode
322
+ };
323
+ };
324
+ var toObject = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
325
+ var toStringOrNull = (value) => typeof value === "string" && value.trim() !== "" ? value : null;
326
+ var joinUrl = (origin, pathname) => {
327
+ if (!origin) {
328
+ return null;
329
+ }
330
+ return new URL(pathname, origin).toString();
331
+ };
332
+ var topologySurfaceUrl = (origin, pathname, surface) => {
333
+ const url = new URL(pathname, origin);
334
+ const topology = parseRuntimeTopology(JSON.stringify(surface));
335
+ for (const [key, value] of Object.entries(
336
+ runtimeTopologyToQueryParams(topology)
337
+ ))
338
+ url.searchParams.set(key, value);
339
+ return url.toString();
340
+ };
341
+ var buildUrlSummary = ({
342
+ mode,
343
+ gameId,
344
+ surfaces,
345
+ controllerPath
346
+ }) => {
347
+ if (mode === "standalone-dev") {
348
+ const hostSurface = toObject(surfaces.host);
349
+ const controllerSurface = toObject(surfaces.controller);
350
+ const hostOrigin = toStringOrNull(hostSurface.appOrigin);
351
+ const controllerOrigin2 = toStringOrNull(controllerSurface.appOrigin) ?? hostOrigin;
352
+ const publicHost2 = toStringOrNull(hostSurface.publicHost) ?? toStringOrNull(controllerSurface.publicHost) ?? hostOrigin;
353
+ return {
354
+ appOrigin: hostOrigin,
355
+ hostUrl: hostOrigin ? topologySurfaceUrl(hostOrigin, "/", hostSurface) : null,
356
+ controllerBaseUrl: controllerOrigin2 ? topologySurfaceUrl(
357
+ controllerOrigin2,
358
+ controllerPath,
359
+ controllerSurface
360
+ ) : null,
361
+ publicHost: publicHost2,
362
+ localBuildUrl: null,
363
+ browserBuildUrl: null
364
+ };
365
+ }
366
+ const platformHost = toObject(surfaces.platformHost);
367
+ const platformController = toObject(surfaces.platformController);
368
+ const embeddedHost = toObject(surfaces.embeddedHost);
369
+ const appOrigin = toStringOrNull(platformHost.appOrigin);
370
+ const controllerOrigin = toStringOrNull(platformController.appOrigin) ?? toStringOrNull(platformHost.publicHost) ?? appOrigin;
371
+ const publicHost = toStringOrNull(platformHost.publicHost) ?? toStringOrNull(platformController.publicHost) ?? controllerOrigin;
372
+ const assetBasePath = toStringOrNull(embeddedHost.assetBasePath);
373
+ return {
374
+ appOrigin,
375
+ hostUrl: appOrigin && gameId ? new URL(`/arcade/local-${gameId}`, appOrigin).toString() : null,
376
+ controllerBaseUrl: joinUrl(controllerOrigin, DEFAULT_CONTROLLER_PATH),
377
+ publicHost,
378
+ localBuildUrl: mode === "arcade-test" && publicHost && assetBasePath ? new URL(assetBasePath, publicHost).toString() : null,
379
+ browserBuildUrl: mode === "arcade-test" && appOrigin && assetBasePath ? new URL(assetBasePath, appOrigin).toString() : null
380
+ };
381
+ };
382
+ var wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
383
+ var checkUrlReady = (targetUrl, secure) => new Promise((resolve) => {
384
+ const parsed = new URL(targetUrl);
385
+ const client = parsed.protocol === "https:" ? https : http;
386
+ const request = client.request(
387
+ parsed,
388
+ {
389
+ method: "GET",
390
+ rejectUnauthorized: secure ? false : void 0
391
+ },
392
+ (response) => {
393
+ response.resume();
394
+ resolve(Boolean(response.statusCode && response.statusCode < 500));
395
+ }
396
+ );
397
+ request.setTimeout(2500, () => {
398
+ request.destroy();
399
+ resolve(false);
400
+ });
401
+ request.on("error", () => resolve(false));
402
+ request.end();
403
+ });
404
+ var waitForTopologyReady = async ({
405
+ topology,
406
+ timeoutMs = START_TIMEOUT_MS
407
+ }) => {
408
+ const urls = [topology.urls.hostUrl, topology.urls.controllerBaseUrl].filter(
409
+ (value) => Boolean(value)
410
+ );
411
+ if (urls.length === 0) {
412
+ return;
413
+ }
414
+ const startedAt = Date.now();
415
+ while (Date.now() - startedAt < timeoutMs) {
416
+ const statuses = await Promise.all(
417
+ urls.map((targetUrl) => checkUrlReady(targetUrl, topology.secure))
418
+ );
419
+ if (statuses.every(Boolean)) {
420
+ return;
421
+ }
422
+ await wait(500);
423
+ }
424
+ throw new Error(
425
+ `Timed out waiting for Air Jam dev endpoints: ${urls.join(", ")}`
426
+ );
427
+ };
428
+ var tryAttachToRunningDev = async ({
429
+ cwd = process.cwd(),
430
+ gameId,
431
+ mode = "standalone-dev",
432
+ secure = false,
433
+ timeoutMs = 2500
434
+ } = {}) => {
435
+ try {
436
+ const topology = await getTopology({
437
+ cwd,
438
+ gameId,
439
+ mode,
440
+ secure
441
+ });
442
+ await waitForTopologyReady({
443
+ topology,
444
+ timeoutMs
445
+ });
446
+ return topology;
447
+ } catch {
448
+ return null;
449
+ }
450
+ };
451
+ var readManagedProcessLogTail = async (logPath, maxLines = 60) => {
452
+ if (!await pathExists(logPath)) {
453
+ return "";
454
+ }
455
+ const contents = await readFile(logPath, "utf8");
456
+ return contents.split(/\r?\n/).filter(Boolean).slice(-maxLines).join("\n");
457
+ };
458
+ var getDevStatus = async ({
459
+ cwd = process.cwd()
460
+ } = {}) => {
461
+ const context = await detectProjectContext({ cwd });
462
+ const managedProcesses = await listManagedProcessesForRoot(context.rootDir);
463
+ const managedPids = new Set(managedProcesses.map((entry) => entry.pid));
464
+ const { getGameSessionBrokerStatus } = await import("./game-session-broker.js");
465
+ return {
466
+ gameSessionBroker: await getGameSessionBrokerStatus(context.rootDir),
467
+ processes: managedProcesses,
468
+ unmanagedProcesses: listKnownPortListeners().filter(
469
+ (entry) => !managedPids.has(entry.pid)
470
+ ),
471
+ knownPorts: getKnownLocalDevPorts()
472
+ };
473
+ };
474
+ var getTopology = async ({
475
+ cwd = process.cwd(),
476
+ gameId,
477
+ mode = "standalone-dev",
478
+ secure = false
479
+ } = {}) => {
480
+ const context = await detectProjectContext({ cwd });
481
+ assertSupportedDevMode(context.packageJson, mode);
482
+ if (!isKnownProjectMode(context.mode)) {
483
+ throw new Error(
484
+ "Air Jam topology is only available in recognized Air Jam projects."
485
+ );
486
+ }
487
+ const game = context.mode === "standalone-game" || gameId ? await inspectGame({ cwd, gameId }) : (await listGames({ cwd }))[0] ?? null;
488
+ const resolvedGameId = game?.id ?? null;
489
+ const controllerPath = game?.declaration.controllerPath ?? DEFAULT_CONTROLLER_PATH;
490
+ const topologyCommand = await resolveTopologyCommand({
491
+ context,
492
+ gameId: resolvedGameId,
493
+ mode,
494
+ secure
495
+ });
496
+ const topologyResult = runCommandResult({
497
+ command: topologyCommand.command,
498
+ args: topologyCommand.args,
499
+ cwd: context.rootDir
500
+ });
501
+ if (!topologyResult.ok) {
502
+ throw new Error(
503
+ `Failed to inspect Air Jam topology.
504
+
505
+ ${topologyResult.stderr || topologyResult.stdout}`
506
+ );
507
+ }
508
+ const parsed = parseJsonFromCommandOutput(
509
+ topologyResult.stdout
510
+ );
511
+ const surfaces = toObject(parsed.surfaces);
512
+ const processes = await listManagedProcessesForRoot(context.rootDir);
513
+ const matchingProcess = processes.find(
514
+ (processInfo) => processInfo.mode === mode && processInfo.secure === secure && processInfo.gameId === resolvedGameId
515
+ ) ?? null;
516
+ return {
517
+ projectMode: context.mode,
518
+ mode,
519
+ topologyMode: topologyCommand.topologyMode,
520
+ gameId: resolvedGameId,
521
+ secure,
522
+ surfaces,
523
+ urls: buildUrlSummary({
524
+ mode,
525
+ gameId: resolvedGameId,
526
+ surfaces,
527
+ controllerPath
528
+ }),
529
+ process: matchingProcess
530
+ };
531
+ };
532
+ var startDev = async ({
533
+ cwd = process.cwd(),
534
+ gameId,
535
+ mode = "standalone-dev",
536
+ secure = false
537
+ } = {}) => {
538
+ const context = await detectProjectContext({ cwd });
539
+ assertSupportedDevMode(context.packageJson, mode);
540
+ if (!isKnownProjectMode(context.mode)) {
541
+ throw new Error(
542
+ "Air Jam dev start is only available in recognized Air Jam projects."
543
+ );
544
+ }
545
+ const topology = await getTopology({
546
+ cwd,
547
+ gameId,
548
+ mode,
549
+ secure
550
+ });
551
+ const resolvedGameId = topology.gameId;
552
+ const existingProcesses = await listManagedProcessesForRoot(context.rootDir);
553
+ const exactMatch = existingProcesses.find(
554
+ (processInfo) => processInfo.mode === mode && processInfo.secure === secure && processInfo.gameId === resolvedGameId
555
+ ) ?? null;
556
+ if (exactMatch) {
557
+ return {
558
+ process: exactMatch,
559
+ reusedExistingProcess: true,
560
+ topology
561
+ };
562
+ }
563
+ if (existingProcesses.length > 0) {
564
+ throw new Error(
565
+ `Air Jam devtools already manages ${existingProcesses.length} running dev process(es) in ${context.rootDir}. Stop them first with airjam.stop_dev.`
566
+ );
567
+ }
568
+ const startCommand = await resolveStartCommand({
569
+ context,
570
+ cwd: context.rootDir,
571
+ gameId: resolvedGameId,
572
+ mode,
573
+ secure
574
+ });
575
+ const processId = randomUUID();
576
+ const logPath = getManagedProcessLogPath(context.rootDir, processId);
577
+ await mkdir(path.dirname(logPath), { recursive: true });
578
+ const logFd = openSync(logPath, "a");
579
+ const supervisorPath = resolveDevtoolsHelperScript(
580
+ "managed-dev-supervisor.ts"
581
+ );
582
+ const supervisorDescriptor = Buffer.from(
583
+ JSON.stringify({
584
+ command: startCommand.command,
585
+ args: startCommand.args,
586
+ cwd: context.rootDir
587
+ }),
588
+ "utf8"
589
+ ).toString("base64url");
590
+ const child = crossSpawn(
591
+ process.execPath,
592
+ [...resolveDevtoolsHelperArgs(supervisorPath), supervisorDescriptor],
593
+ {
594
+ cwd: context.rootDir,
595
+ detached: true,
596
+ stdio: ["ignore", logFd, logFd],
597
+ env: {
598
+ ...process.env,
599
+ CI: process.env.CI ?? "1",
600
+ NO_UPDATE_NOTIFIER: "1"
601
+ }
602
+ }
603
+ );
604
+ const childExited = new Promise((resolve) => {
605
+ child.once("exit", (code, signal) => {
606
+ resolve({ code, signal });
607
+ });
608
+ });
609
+ try {
610
+ await new Promise((resolve, reject) => {
611
+ child.once("spawn", resolve);
612
+ child.once("error", reject);
613
+ });
614
+ } finally {
615
+ closeSync(logFd);
616
+ }
617
+ child.unref();
618
+ const managedProcess = {
619
+ id: processId,
620
+ pid: child.pid ?? 0,
621
+ cwd: context.rootDir,
622
+ projectMode: context.mode,
623
+ mode,
624
+ topologyMode: startCommand.topologyMode,
625
+ secure,
626
+ gameId: resolvedGameId,
627
+ command: startCommand.command,
628
+ args: startCommand.args,
629
+ logPath,
630
+ expectedLogPath: startCommand.expectedLogPath,
631
+ startedAt: (/* @__PURE__ */ new Date()).toISOString()
632
+ };
633
+ await writeRegistry(context.rootDir, {
634
+ schemaVersion: DEVTOOLS_SCHEMA_VERSION,
635
+ processes: [managedProcess]
636
+ });
637
+ try {
638
+ topology.process = managedProcess;
639
+ await Promise.race([
640
+ waitForTopologyReady({ topology }),
641
+ childExited.then(({ code, signal }) => {
642
+ throw new Error(
643
+ signal ? `Managed dev supervisor exited from signal ${signal}.` : `Managed dev supervisor exited with code ${code ?? "unknown"}.`
644
+ );
645
+ })
646
+ ]);
647
+ return {
648
+ process: managedProcess,
649
+ reusedExistingProcess: false,
650
+ topology
651
+ };
652
+ } catch (error) {
653
+ await terminateManagedProcess(managedProcess.pid);
654
+ await writeRegistry(context.rootDir, {
655
+ schemaVersion: DEVTOOLS_SCHEMA_VERSION,
656
+ processes: []
657
+ });
658
+ const logTail = await readManagedProcessLogTail(logPath);
659
+ const message = error instanceof Error ? error.message : String(error ?? "Unknown error");
660
+ throw new Error(
661
+ logTail ? `${message}
662
+
663
+ Managed dev log tail:
664
+ ${logTail}` : message
665
+ );
666
+ }
667
+ };
668
+ var stopDev = async ({
669
+ cwd = process.cwd(),
670
+ processId,
671
+ mode
672
+ } = {}) => {
673
+ const context = await detectProjectContext({ cwd });
674
+ const processes = await listManagedProcessesForRoot(context.rootDir);
675
+ const selected = processes.filter((processInfo) => {
676
+ if (processId) {
677
+ return processInfo.id === processId;
678
+ }
679
+ if (mode) {
680
+ return processInfo.mode === mode;
681
+ }
682
+ return true;
683
+ });
684
+ for (const processInfo of selected) {
685
+ await terminateManagedProcess(processInfo.pid);
686
+ }
687
+ const remaining = processes.filter(
688
+ (processInfo) => !selected.some(
689
+ (selectedProcess) => selectedProcess.id === processInfo.id
690
+ )
691
+ );
692
+ await writeRegistry(context.rootDir, {
693
+ schemaVersion: DEVTOOLS_SCHEMA_VERSION,
694
+ processes: remaining
695
+ });
696
+ return {
697
+ stopped: selected
698
+ };
699
+ };
700
+ var resetLocalDev = async ({
701
+ cwd = process.cwd()
702
+ } = {}) => {
703
+ const context = await detectProjectContext({ cwd });
704
+ const { stopGameSessionBroker } = await import("./game-session-broker.js");
705
+ const gameSessionBroker = await stopGameSessionBroker(context.rootDir);
706
+ const stoppedManaged = (await stopDev({ cwd: context.rootDir })).stopped;
707
+ const managedPids = new Set(stoppedManaged.map((entry) => entry.pid));
708
+ const unmanaged = listKnownPortListeners().filter(
709
+ (entry) => !managedPids.has(entry.pid)
710
+ );
711
+ const stoppedUnmanaged = [];
712
+ for (const processInfo of unmanaged) {
713
+ if (!isLikelyAirJamLocalDevCommand(processInfo.command)) {
714
+ continue;
715
+ }
716
+ await terminateManagedProcess(processInfo.pid);
717
+ stoppedUnmanaged.push(processInfo);
718
+ }
719
+ await rm(
720
+ path.join(context.rootDir, ".airjam", "preview-managed-server.json"),
721
+ {
722
+ force: true
723
+ }
724
+ ).catch(() => void 0);
725
+ const stoppedPids = /* @__PURE__ */ new Set([
726
+ ...stoppedManaged.map((entry) => entry.pid),
727
+ ...stoppedUnmanaged.map((entry) => entry.pid)
728
+ ]);
729
+ const remainingUnmanaged = listKnownPortListeners().filter(
730
+ (entry) => !stoppedPids.has(entry.pid)
731
+ );
732
+ return {
733
+ gameSessionBroker,
734
+ stoppedManaged,
735
+ stoppedUnmanaged,
736
+ remainingUnmanaged,
737
+ knownPorts: getKnownLocalDevPorts()
738
+ };
739
+ };
740
+
741
+ export {
742
+ tryAttachToRunningDev,
743
+ getDevStatus,
744
+ getTopology,
745
+ startDev,
746
+ stopDev,
747
+ resetLocalDev
748
+ };
749
+ //# sourceMappingURL=chunk-MEIMOSZC.js.map