@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.
- package/LICENSE +21 -0
- package/README.md +112 -2
- package/dist/chunk-2O67AXCU.js +470 -0
- package/dist/chunk-2O67AXCU.js.map +1 -0
- package/dist/chunk-AO3ZDXF6.js +142 -0
- package/dist/chunk-AO3ZDXF6.js.map +1 -0
- package/dist/chunk-ART5TEYT.js +472 -0
- package/dist/chunk-ART5TEYT.js.map +1 -0
- package/dist/chunk-ASC2CK2R.js +77 -0
- package/dist/chunk-ASC2CK2R.js.map +1 -0
- package/dist/chunk-E3UZZGAV.js +50 -0
- package/dist/chunk-E3UZZGAV.js.map +1 -0
- package/dist/chunk-EJTE7UKX.js +64 -0
- package/dist/chunk-EJTE7UKX.js.map +1 -0
- package/dist/chunk-ESFKNN75.js +110 -0
- package/dist/chunk-ESFKNN75.js.map +1 -0
- package/dist/chunk-EU7A6PXW.js +1339 -0
- package/dist/chunk-EU7A6PXW.js.map +1 -0
- package/dist/chunk-FN7E6EA7.js +549 -0
- package/dist/chunk-FN7E6EA7.js.map +1 -0
- package/dist/chunk-GDFAWHGA.js +190 -0
- package/dist/chunk-GDFAWHGA.js.map +1 -0
- package/dist/chunk-HZUGBH4Y.js +347 -0
- package/dist/chunk-HZUGBH4Y.js.map +1 -0
- package/dist/chunk-ITKAOEGX.js +93 -0
- package/dist/chunk-ITKAOEGX.js.map +1 -0
- package/dist/chunk-JBCUTWRI.js +897 -0
- package/dist/chunk-JBCUTWRI.js.map +1 -0
- package/dist/chunk-JSI5S4WP.js +1174 -0
- package/dist/chunk-JSI5S4WP.js.map +1 -0
- package/dist/chunk-L4D675BG.js +97 -0
- package/dist/chunk-L4D675BG.js.map +1 -0
- package/dist/chunk-M6CJ7GQC.js +133 -0
- package/dist/chunk-M6CJ7GQC.js.map +1 -0
- package/dist/chunk-MEIMOSZC.js +749 -0
- package/dist/chunk-MEIMOSZC.js.map +1 -0
- package/dist/chunk-O3XG3FNL.js +1014 -0
- package/dist/chunk-O3XG3FNL.js.map +1 -0
- package/dist/chunk-OM6SCJ7H.js +18 -0
- package/dist/chunk-OM6SCJ7H.js.map +1 -0
- package/dist/chunk-PKD4WVX5.js +63 -0
- package/dist/chunk-PKD4WVX5.js.map +1 -0
- package/dist/chunk-PMBLXGFM.js +3384 -0
- package/dist/chunk-PMBLXGFM.js.map +1 -0
- package/dist/chunk-PMNE5GIN.js +279 -0
- package/dist/chunk-PMNE5GIN.js.map +1 -0
- package/dist/chunk-QAWI64VR.js +148 -0
- package/dist/chunk-QAWI64VR.js.map +1 -0
- package/dist/chunk-QGADSPHZ.js +449 -0
- package/dist/chunk-QGADSPHZ.js.map +1 -0
- package/dist/chunk-SPYN66UV.js +338 -0
- package/dist/chunk-SPYN66UV.js.map +1 -0
- package/dist/context.d.ts +19 -0
- package/dist/context.js +10 -0
- package/dist/context.js.map +1 -0
- package/dist/controller.d.ts +67 -0
- package/dist/controller.js +40 -0
- package/dist/controller.js.map +1 -0
- package/dist/dependencies.d.ts +44 -0
- package/dist/dependencies.js +10 -0
- package/dist/dependencies.js.map +1 -0
- package/dist/dev.d.ts +21 -0
- package/dist/dev.js +19 -0
- package/dist/dev.js.map +1 -0
- package/dist/game-builds.d.ts +200 -0
- package/dist/game-builds.js +16 -0
- package/dist/game-builds.js.map +1 -0
- package/dist/game-run-watch-CEd_SpAT.d.ts +84 -0
- package/dist/game-runs.d.ts +1452 -0
- package/dist/game-runs.js +76 -0
- package/dist/game-runs.js.map +1 -0
- package/dist/game-session-broker-CUvORfMd.d.ts +439 -0
- package/dist/game-session-broker.d.ts +4 -0
- package/dist/game-session-broker.js +40 -0
- package/dist/game-session-broker.js.map +1 -0
- package/dist/game-session.d.ts +3934 -0
- package/dist/game-session.js +195 -0
- package/dist/game-session.js.map +1 -0
- package/dist/game-settings.d.ts +16 -0
- package/dist/game-settings.js +237 -0
- package/dist/game-settings.js.map +1 -0
- package/dist/games.d.ts +28 -0
- package/dist/games.js +16 -0
- package/dist/games.js.map +1 -0
- package/dist/harness/visual.d.ts +204 -0
- package/dist/harness/visual.js +46 -0
- package/dist/harness/visual.js.map +1 -0
- package/dist/logs.d.ts +15 -0
- package/dist/logs.js +57 -0
- package/dist/logs.js.map +1 -0
- package/dist/managed-process-scope-BicYi_t9.d.ts +3 -0
- package/dist/mcp-config.d.ts +63 -0
- package/dist/mcp-config.js +191 -0
- package/dist/mcp-config.js.map +1 -0
- package/dist/platform-auth.d.ts +9 -0
- package/dist/platform-auth.js +45 -0
- package/dist/platform-auth.js.map +1 -0
- package/dist/platform-game-analytics.d.ts +51 -0
- package/dist/platform-game-analytics.js +49 -0
- package/dist/platform-game-analytics.js.map +1 -0
- package/dist/platform-game-app-id.d.ts +46 -0
- package/dist/platform-game-app-id.js +93 -0
- package/dist/platform-game-app-id.js.map +1 -0
- package/dist/platform-game-media.d.ts +347 -0
- package/dist/platform-game-media.js +168 -0
- package/dist/platform-game-media.js.map +1 -0
- package/dist/platform-games.d.ts +87 -0
- package/dist/platform-games.js +183 -0
- package/dist/platform-games.js.map +1 -0
- package/dist/quality.d.ts +16 -0
- package/dist/quality.js +62 -0
- package/dist/quality.js.map +1 -0
- package/dist/release.d.ts +1304 -0
- package/dist/release.js +34 -0
- package/dist/release.js.map +1 -0
- package/dist/rooms-check.d.ts +90 -0
- package/dist/rooms-check.js +717 -0
- package/dist/rooms-check.js.map +1 -0
- package/dist/source-tree-contract.d.ts +16 -0
- package/dist/source-tree-contract.js +13 -0
- package/dist/source-tree-contract.js.map +1 -0
- package/dist/testing.d.ts +464 -0
- package/dist/testing.js +27 -0
- package/dist/testing.js.map +1 -0
- package/dist/tooling/describe-game.d.ts +2 -0
- package/dist/tooling/describe-game.js +54 -0
- package/dist/tooling/describe-game.js.map +1 -0
- package/dist/tooling/game-session-broker.d.ts +2 -0
- package/dist/tooling/game-session-broker.js +28 -0
- package/dist/tooling/game-session-broker.js.map +1 -0
- package/dist/tooling/hold-runtime-host.d.ts +2 -0
- package/dist/tooling/hold-runtime-host.js +931 -0
- package/dist/tooling/hold-runtime-host.js.map +1 -0
- package/dist/tooling/list-visual-scenarios.d.ts +2 -0
- package/dist/tooling/list-visual-scenarios.js +25 -0
- package/dist/tooling/list-visual-scenarios.js.map +1 -0
- package/dist/tooling/managed-dev-supervisor.d.ts +2 -0
- package/dist/tooling/managed-dev-supervisor.js +51 -0
- package/dist/tooling/managed-dev-supervisor.js.map +1 -0
- package/dist/tooling/process-scope-bootstrap.mjs +24 -0
- package/dist/tooling/process-scope-guard.d.ts +2 -0
- package/dist/tooling/process-scope-guard.js +388 -0
- package/dist/tooling/process-scope-guard.js.map +1 -0
- package/dist/tooling/process-scope-windows.ps1 +148 -0
- package/dist/tooling/rooms-check-device.d.ts +2 -0
- package/dist/tooling/rooms-check-device.js +498 -0
- package/dist/tooling/rooms-check-device.js.map +1 -0
- package/dist/tooling/run-headless-room.d.ts +2 -0
- package/dist/tooling/run-headless-room.js +287 -0
- package/dist/tooling/run-headless-room.js.map +1 -0
- package/dist/tooling/run-test-profile.d.ts +2 -0
- package/dist/tooling/run-test-profile.js +181 -0
- package/dist/tooling/run-test-profile.js.map +1 -0
- package/dist/tooling/run-visual-capture.d.ts +2 -0
- package/dist/tooling/run-visual-capture.js +203 -0
- package/dist/tooling/run-visual-capture.js.map +1 -0
- package/dist/tooling/seal-game-build.d.ts +2 -0
- package/dist/tooling/seal-game-build.js +120 -0
- package/dist/tooling/seal-game-build.js.map +1 -0
- package/dist/types-CdYrgrG_.d.ts +1036 -0
- package/dist/types-DyRD-ym1.d.ts +141 -0
- package/dist/visual.d.ts +21 -0
- package/dist/visual.js +219 -0
- package/dist/visual.js.map +1 -0
- package/package.json +150 -3
- package/src/bounded-response.ts +28 -0
- package/src/built-game-runtime.ts +152 -0
- package/src/commands.ts +40 -0
- package/src/context.ts +218 -0
- package/src/controller-protocol.ts +22 -0
- package/src/controller.ts +1526 -0
- package/src/current-room-host.ts +166 -0
- package/src/decision-provider.ts +102 -0
- package/src/dependencies.ts +176 -0
- package/src/dependency-install-contract.ts +12 -0
- package/src/dev.ts +995 -0
- package/src/fs-utils.ts +93 -0
- package/src/game-action-observation.ts +106 -0
- package/src/game-build-protocol.ts +72 -0
- package/src/game-build.ts +483 -0
- package/src/game-run-owner.ts +2358 -0
- package/src/game-run-protocol.ts +448 -0
- package/src/game-run-record.ts +92 -0
- package/src/game-run-replay.ts +95 -0
- package/src/game-run-watch.ts +155 -0
- package/src/game-session-broker.ts +793 -0
- package/src/game-session-operations.ts +61 -0
- package/src/game-session-protocol.ts +180 -0
- package/src/game-session-runtime.ts +861 -0
- package/src/game-session.ts +206 -0
- package/src/game-settings.ts +295 -0
- package/src/games.ts +262 -0
- package/src/harness/visual/browser.ts +100 -0
- package/src/harness/visual/controller-observation.ts +181 -0
- package/src/harness/visual/prefab-contract.ts +29 -0
- package/src/harness/visual/prefab-runner.ts +178 -0
- package/src/harness/visual/runner.ts +549 -0
- package/src/harness/visual/runtime-controller-observations.ts +151 -0
- package/src/harness/visual/scenario-contract.ts +8 -0
- package/src/harness/visual/scenario-helpers.ts +67 -0
- package/src/harness/visual/screencast.ts +155 -0
- package/src/harness/visual/session.ts +400 -0
- package/src/harness/visual/types.ts +184 -0
- package/src/harness/visual.ts +7 -0
- package/src/headless-room-protocol.ts +112 -0
- package/src/headless-room.ts +222 -0
- package/src/helper-channel.ts +229 -0
- package/src/helper-scripts.ts +69 -0
- package/src/installed-dependencies.ts +74 -0
- package/src/logs.ts +67 -0
- package/src/managed-process-scope.ts +481 -0
- package/src/mcp-config.ts +262 -0
- package/src/node-process-environment.ts +10 -0
- package/src/platform-auth.ts +594 -0
- package/src/platform-game-analytics.ts +50 -0
- package/src/platform-game-app-id.ts +99 -0
- package/src/platform-game-media.ts +209 -0
- package/src/platform-games.ts +217 -0
- package/src/policy-artifact-contract.ts +52 -0
- package/src/policy-artifacts.ts +134 -0
- package/src/process-scope-admission.ts +50 -0
- package/src/process-scope-protocol.ts +66 -0
- package/src/process-scope.ts +327 -0
- package/src/quality.ts +82 -0
- package/src/release.ts +1683 -0
- package/src/rooms-check-fleet.ts +194 -0
- package/src/rooms-check-link.ts +138 -0
- package/src/rooms-check-protocol.ts +244 -0
- package/src/rooms-check.ts +797 -0
- package/src/runtime-owner-protocol.ts +218 -0
- package/src/source-tree-contract.ts +70 -0
- package/src/source-tree.ts +84 -0
- package/src/test-profile-process.ts +153 -0
- package/src/test-profile-protocol.ts +116 -0
- package/src/testing.ts +430 -0
- package/src/tooling/declaration-hook.ts +52 -0
- package/src/tooling/describe-game.ts +49 -0
- package/src/tooling/game-session-broker.ts +7 -0
- package/src/tooling/hold-runtime-host.ts +441 -0
- package/src/tooling/list-visual-scenarios.ts +21 -0
- package/src/tooling/load-game.ts +79 -0
- package/src/tooling/managed-dev-supervisor.ts +71 -0
- package/src/tooling/process-scope-bootstrap.mjs +24 -0
- package/src/tooling/process-scope-guard.ts +213 -0
- package/src/tooling/process-scope-windows.ps1 +148 -0
- package/src/tooling/rooms-check-device.ts +493 -0
- package/src/tooling/run-headless-room.ts +326 -0
- package/src/tooling/run-test-profile.ts +190 -0
- package/src/tooling/run-visual-capture.ts +231 -0
- package/src/tooling/runtime-owner-actions.ts +65 -0
- package/src/tooling/seal-game-build.ts +118 -0
- package/src/tooling/visual-pack.ts +11 -0
- package/src/types.ts +928 -0
- package/src/visual.ts +296 -0
- package/src/windows-process-scopes.ts +189 -0
- package/src/workspace-contract.ts +32 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolveRuntimeTopology,
|
|
3
|
+
runtimeTopologyToQueryParams,
|
|
4
|
+
} from "@air-jam/sdk/runtime-topology";
|
|
5
|
+
import { loadServerEnv } from "@air-jam/server";
|
|
6
|
+
import { createRoomServer } from "@air-jam/server/room-server";
|
|
7
|
+
import { createHash } from "node:crypto";
|
|
8
|
+
import { readFile, realpath } from "node:fs/promises";
|
|
9
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import { gameBuildManifestSchema } from "./game-build-protocol.js";
|
|
12
|
+
import { distributionFiles } from "./game-build.js";
|
|
13
|
+
|
|
14
|
+
const CONTENT_TYPES: Record<string, string> = {
|
|
15
|
+
".html": "text/html; charset=utf-8",
|
|
16
|
+
".js": "text/javascript; charset=utf-8",
|
|
17
|
+
".mjs": "text/javascript; charset=utf-8",
|
|
18
|
+
".css": "text/css; charset=utf-8",
|
|
19
|
+
".json": "application/json; charset=utf-8",
|
|
20
|
+
".map": "application/json; charset=utf-8",
|
|
21
|
+
".txt": "text/plain; charset=utf-8",
|
|
22
|
+
".svg": "image/svg+xml",
|
|
23
|
+
".png": "image/png",
|
|
24
|
+
".jpg": "image/jpeg",
|
|
25
|
+
".jpeg": "image/jpeg",
|
|
26
|
+
".gif": "image/gif",
|
|
27
|
+
".webp": "image/webp",
|
|
28
|
+
".avif": "image/avif",
|
|
29
|
+
".ico": "image/x-icon",
|
|
30
|
+
".woff": "font/woff",
|
|
31
|
+
".woff2": "font/woff2",
|
|
32
|
+
".ttf": "font/ttf",
|
|
33
|
+
".otf": "font/otf",
|
|
34
|
+
".mp3": "audio/mpeg",
|
|
35
|
+
".ogg": "audio/ogg",
|
|
36
|
+
".wav": "audio/wav",
|
|
37
|
+
".m4a": "audio/mp4",
|
|
38
|
+
".mp4": "video/mp4",
|
|
39
|
+
".webm": "video/webm",
|
|
40
|
+
".glb": "model/gltf-binary",
|
|
41
|
+
".gltf": "model/gltf+json",
|
|
42
|
+
".wasm": "application/wasm",
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const contentTypeOf = (name: string): string =>
|
|
46
|
+
CONTENT_TYPES[path.extname(name).toLowerCase()] ?? "application/octet-stream";
|
|
47
|
+
|
|
48
|
+
/** One loopback origin serves the pinned assets and their rooms. */
|
|
49
|
+
export async function startBuiltGameRuntime(manifestPath: string) {
|
|
50
|
+
const manifest = gameBuildManifestSchema.parse(
|
|
51
|
+
JSON.parse(await readFile(manifestPath, "utf8")),
|
|
52
|
+
);
|
|
53
|
+
const root = await realpath(
|
|
54
|
+
path.join(path.dirname(manifestPath), "source/dist"),
|
|
55
|
+
);
|
|
56
|
+
const files = await distributionFiles(root);
|
|
57
|
+
if (
|
|
58
|
+
createHash("sha256").update(JSON.stringify(files)).digest("hex") !==
|
|
59
|
+
manifest.distHash
|
|
60
|
+
)
|
|
61
|
+
throw new Error(
|
|
62
|
+
"build_integrity_changed: The distribution changed before host startup.",
|
|
63
|
+
);
|
|
64
|
+
const allowed = new Set(files.map((file) => file.path));
|
|
65
|
+
const serveFile = (request: IncomingMessage, response: ServerResponse) => {
|
|
66
|
+
if (request.method !== "GET" && request.method !== "HEAD") {
|
|
67
|
+
response.writeHead(405).end();
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
let name: string;
|
|
71
|
+
try {
|
|
72
|
+
name = decodeURIComponent(
|
|
73
|
+
new URL(request.url ?? "/", "http://localhost").pathname,
|
|
74
|
+
).slice(1);
|
|
75
|
+
} catch {
|
|
76
|
+
response.writeHead(400).end();
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (
|
|
80
|
+
name === "" ||
|
|
81
|
+
(!allowed.has(name) &&
|
|
82
|
+
request.headers.accept?.includes("text/html") &&
|
|
83
|
+
!name.split("/").some((segment) => segment.includes(".")))
|
|
84
|
+
)
|
|
85
|
+
name = "index.html";
|
|
86
|
+
if (!allowed.has(name)) {
|
|
87
|
+
response.writeHead(404).end();
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
readFile(path.join(root, name)).then(
|
|
91
|
+
(body) => {
|
|
92
|
+
response.writeHead(200, {
|
|
93
|
+
"content-type": contentTypeOf(name),
|
|
94
|
+
"content-length": body.byteLength,
|
|
95
|
+
"x-content-type-options": "nosniff",
|
|
96
|
+
"cache-control": "no-store",
|
|
97
|
+
});
|
|
98
|
+
response.end(request.method === "HEAD" ? undefined : body);
|
|
99
|
+
},
|
|
100
|
+
() => {
|
|
101
|
+
if (!response.headersSent) response.writeHead(404).end();
|
|
102
|
+
},
|
|
103
|
+
);
|
|
104
|
+
};
|
|
105
|
+
const runtime = createRoomServer({
|
|
106
|
+
host: "127.0.0.1",
|
|
107
|
+
port: 0,
|
|
108
|
+
envConfig: loadServerEnv({
|
|
109
|
+
NODE_ENV: "test",
|
|
110
|
+
AIR_JAM_AUTH_MODE: "disabled",
|
|
111
|
+
}),
|
|
112
|
+
otherRequests: serveFile,
|
|
113
|
+
});
|
|
114
|
+
try {
|
|
115
|
+
const origin = `http://127.0.0.1:${await runtime.start()}`;
|
|
116
|
+
const topology = (surfaceRole: "host" | "controller") =>
|
|
117
|
+
resolveRuntimeTopology({
|
|
118
|
+
runtimeMode: "self-hosted-production",
|
|
119
|
+
surfaceRole,
|
|
120
|
+
appOrigin: origin,
|
|
121
|
+
backendOrigin: origin,
|
|
122
|
+
socketOrigin: origin,
|
|
123
|
+
publicHost: origin,
|
|
124
|
+
embedded: false,
|
|
125
|
+
proxyStrategy: "none",
|
|
126
|
+
secureTransport: false,
|
|
127
|
+
});
|
|
128
|
+
const surfaceUrl = (role: "host" | "controller") => {
|
|
129
|
+
const url = new URL(role === "host" ? "/" : "/controller", origin);
|
|
130
|
+
for (const [key, value] of Object.entries(
|
|
131
|
+
runtimeTopologyToQueryParams(topology(role)),
|
|
132
|
+
))
|
|
133
|
+
url.searchParams.set(key, value);
|
|
134
|
+
return url.toString();
|
|
135
|
+
};
|
|
136
|
+
return {
|
|
137
|
+
topology: topology("host"),
|
|
138
|
+
urls: {
|
|
139
|
+
appOrigin: origin,
|
|
140
|
+
hostUrl: surfaceUrl("host"),
|
|
141
|
+
controllerBaseUrl: surfaceUrl("controller"),
|
|
142
|
+
publicHost: origin,
|
|
143
|
+
localBuildUrl: null,
|
|
144
|
+
browserBuildUrl: null,
|
|
145
|
+
},
|
|
146
|
+
close: () => runtime.stop(),
|
|
147
|
+
};
|
|
148
|
+
} catch (error) {
|
|
149
|
+
await runtime.stop();
|
|
150
|
+
throw error;
|
|
151
|
+
}
|
|
152
|
+
}
|
package/src/commands.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import crossSpawn from "cross-spawn";
|
|
2
|
+
import type { CommandResult } from "./types.js";
|
|
3
|
+
|
|
4
|
+
const createBaseEnv = (): NodeJS.ProcessEnv => ({
|
|
5
|
+
...process.env,
|
|
6
|
+
CI: process.env.CI ?? "1",
|
|
7
|
+
NO_UPDATE_NOTIFIER: "1",
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export const runCommandResult = ({
|
|
11
|
+
command,
|
|
12
|
+
args,
|
|
13
|
+
cwd,
|
|
14
|
+
}: {
|
|
15
|
+
command: string;
|
|
16
|
+
args: string[];
|
|
17
|
+
cwd: string;
|
|
18
|
+
}): CommandResult => {
|
|
19
|
+
const startedAt = Date.now();
|
|
20
|
+
const result = crossSpawn.sync(command, args, {
|
|
21
|
+
cwd,
|
|
22
|
+
encoding: "utf8",
|
|
23
|
+
env: createBaseEnv(),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const exitCode = result.status ?? null;
|
|
27
|
+
return {
|
|
28
|
+
command,
|
|
29
|
+
args,
|
|
30
|
+
cwd,
|
|
31
|
+
exitCode,
|
|
32
|
+
signal: result.signal,
|
|
33
|
+
stdout: result.stdout ?? "",
|
|
34
|
+
stderr:
|
|
35
|
+
result.stderr ??
|
|
36
|
+
(result.error instanceof Error ? result.error.message : ""),
|
|
37
|
+
durationMs: Date.now() - startedAt,
|
|
38
|
+
ok: exitCode === 0 && !result.error,
|
|
39
|
+
};
|
|
40
|
+
};
|
package/src/context.ts
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import {
|
|
3
|
+
findUp,
|
|
4
|
+
firstExistingPath,
|
|
5
|
+
pathExists,
|
|
6
|
+
readPackageJson,
|
|
7
|
+
resolveCanonicalPath,
|
|
8
|
+
} from "./fs-utils.js";
|
|
9
|
+
import { AIRJAM_CONFIG_PATH } from "./games.js";
|
|
10
|
+
import type {
|
|
11
|
+
AirJamCapabilityGroup,
|
|
12
|
+
AirJamPackageManager,
|
|
13
|
+
AirJamProjectContext,
|
|
14
|
+
AirJamProjectInspection,
|
|
15
|
+
PackageJson,
|
|
16
|
+
} from "./types.js";
|
|
17
|
+
import { readWorkspaceContract } from "./workspace-contract.js";
|
|
18
|
+
|
|
19
|
+
export type {
|
|
20
|
+
AirJamCapabilityGroup,
|
|
21
|
+
AirJamPackageManager,
|
|
22
|
+
AirJamProjectContext,
|
|
23
|
+
AirJamProjectInspection,
|
|
24
|
+
} from "./types.js";
|
|
25
|
+
|
|
26
|
+
const hasDependency = (
|
|
27
|
+
packageJson: PackageJson,
|
|
28
|
+
packageName: string,
|
|
29
|
+
): boolean =>
|
|
30
|
+
Boolean(
|
|
31
|
+
packageJson.dependencies?.[packageName] ??
|
|
32
|
+
packageJson.devDependencies?.[packageName] ??
|
|
33
|
+
packageJson.peerDependencies?.[packageName],
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const detectPackageManager = async (
|
|
37
|
+
rootDir: string,
|
|
38
|
+
): Promise<AirJamPackageManager> => {
|
|
39
|
+
if (await pathExists(path.join(rootDir, "pnpm-lock.yaml"))) {
|
|
40
|
+
return "pnpm";
|
|
41
|
+
}
|
|
42
|
+
if (await pathExists(path.join(rootDir, "package-lock.json"))) {
|
|
43
|
+
return "npm";
|
|
44
|
+
}
|
|
45
|
+
if (await pathExists(path.join(rootDir, "yarn.lock"))) {
|
|
46
|
+
return "yarn";
|
|
47
|
+
}
|
|
48
|
+
if (
|
|
49
|
+
(await pathExists(path.join(rootDir, "bun.lock"))) ||
|
|
50
|
+
(await pathExists(path.join(rootDir, "bun.lockb")))
|
|
51
|
+
) {
|
|
52
|
+
return "bun";
|
|
53
|
+
}
|
|
54
|
+
return "unknown";
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const findPackageRoot = async (cwd: string): Promise<string> => {
|
|
58
|
+
const packageJsonPath = await findUp(cwd, "package.json");
|
|
59
|
+
return packageJsonPath ? path.dirname(packageJsonPath) : path.resolve(cwd);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const findMonorepoRoot = async (cwd: string): Promise<string | null> => {
|
|
63
|
+
let currentDir = path.resolve(cwd);
|
|
64
|
+
|
|
65
|
+
while (true) {
|
|
66
|
+
const packageJsonResult = await readPackageJson(currentDir);
|
|
67
|
+
const packageJson = packageJsonResult?.value ?? null;
|
|
68
|
+
|
|
69
|
+
if (await isMonorepoRoot(currentDir, packageJson)) {
|
|
70
|
+
return currentDir;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const parent = path.dirname(currentDir);
|
|
74
|
+
if (parent === currentDir) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
currentDir = parent;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const isMonorepoRoot = async (
|
|
82
|
+
rootDir: string,
|
|
83
|
+
packageJson: PackageJson | null,
|
|
84
|
+
): Promise<boolean> => {
|
|
85
|
+
if (!packageJson) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const workspace = readWorkspaceContract(packageJson);
|
|
90
|
+
if (!workspace) return false;
|
|
91
|
+
if (!(await pathExists(path.resolve(rootDir, workspace.cli)))) {
|
|
92
|
+
throw new Error(
|
|
93
|
+
`Declared Air Jam workspace CLI does not exist: ${workspace.cli}`,
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
return true;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const isStandaloneGameRoot = async (
|
|
100
|
+
rootDir: string,
|
|
101
|
+
packageJson: PackageJson | null,
|
|
102
|
+
): Promise<boolean> => {
|
|
103
|
+
if (!packageJson) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (hasDependency(packageJson, "@air-jam/sdk")) {
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return Boolean(await pathExists(path.join(rootDir, AIRJAM_CONFIG_PATH)));
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export const detectProjectContext = async ({
|
|
115
|
+
cwd = process.cwd(),
|
|
116
|
+
}: {
|
|
117
|
+
cwd?: string;
|
|
118
|
+
} = {}): Promise<AirJamProjectContext> => {
|
|
119
|
+
const discoveredMonorepoRoot = await findMonorepoRoot(cwd);
|
|
120
|
+
const discoveredRootDir =
|
|
121
|
+
discoveredMonorepoRoot ?? (await findPackageRoot(cwd));
|
|
122
|
+
const rootDir = await resolveCanonicalPath(discoveredRootDir);
|
|
123
|
+
const monorepoRoot = discoveredMonorepoRoot ? rootDir : null;
|
|
124
|
+
const packageJsonResult = await readPackageJson(rootDir);
|
|
125
|
+
const packageJson = packageJsonResult?.value ?? null;
|
|
126
|
+
const reasons: string[] = [];
|
|
127
|
+
|
|
128
|
+
let workspaceRoot: string | null = null;
|
|
129
|
+
let mode: AirJamProjectContext["mode"] = "unknown";
|
|
130
|
+
|
|
131
|
+
if (monorepoRoot && rootDir === monorepoRoot) {
|
|
132
|
+
mode = "monorepo";
|
|
133
|
+
workspaceRoot = rootDir;
|
|
134
|
+
reasons.push("Detected a declared Air Jam workspace CLI.");
|
|
135
|
+
} else if (await isStandaloneGameRoot(rootDir, packageJson)) {
|
|
136
|
+
mode = "standalone-game";
|
|
137
|
+
reasons.push("Detected Air Jam game package or airjam config.");
|
|
138
|
+
} else {
|
|
139
|
+
reasons.push("No Air Jam monorepo or standalone game markers found.");
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
rootDir,
|
|
144
|
+
mode,
|
|
145
|
+
packageManager: await detectPackageManager(rootDir),
|
|
146
|
+
packageJsonPath: packageJsonResult?.path ?? null,
|
|
147
|
+
packageJson,
|
|
148
|
+
workspaceRoot,
|
|
149
|
+
reasons,
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const collectAirJamPackages = (
|
|
154
|
+
packageJson: PackageJson | null,
|
|
155
|
+
): Record<string, string> => {
|
|
156
|
+
if (!packageJson) {
|
|
157
|
+
return {};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return Object.fromEntries(
|
|
161
|
+
Object.entries({
|
|
162
|
+
...(packageJson.dependencies ?? {}),
|
|
163
|
+
...(packageJson.devDependencies ?? {}),
|
|
164
|
+
...(packageJson.peerDependencies ?? {}),
|
|
165
|
+
}).filter(
|
|
166
|
+
([name]) => name === "create-airjam" || name.startsWith("@air-jam/"),
|
|
167
|
+
),
|
|
168
|
+
);
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const collectCapabilities = (
|
|
172
|
+
context: AirJamProjectContext,
|
|
173
|
+
): AirJamCapabilityGroup[] => {
|
|
174
|
+
if (context.mode === "monorepo") {
|
|
175
|
+
return [
|
|
176
|
+
"project",
|
|
177
|
+
"games",
|
|
178
|
+
"logs",
|
|
179
|
+
"runtime",
|
|
180
|
+
"quality",
|
|
181
|
+
"repo-workspace",
|
|
182
|
+
"ai-pack",
|
|
183
|
+
];
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (context.mode === "standalone-game") {
|
|
187
|
+
return ["project", "games", "logs", "runtime", "quality", "ai-pack"];
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return ["project"];
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
export const inspectProject = async ({
|
|
194
|
+
cwd = process.cwd(),
|
|
195
|
+
}: {
|
|
196
|
+
cwd?: string;
|
|
197
|
+
} = {}): Promise<AirJamProjectInspection> => {
|
|
198
|
+
const context = await detectProjectContext({ cwd });
|
|
199
|
+
const rootDir = context.rootDir;
|
|
200
|
+
|
|
201
|
+
return {
|
|
202
|
+
context,
|
|
203
|
+
capabilities: collectCapabilities(context),
|
|
204
|
+
scripts: context.packageJson?.scripts ?? {},
|
|
205
|
+
airJamPackages: collectAirJamPackages(context.packageJson),
|
|
206
|
+
files: {
|
|
207
|
+
agents: await firstExistingPath([path.join(rootDir, "AGENTS.md")]),
|
|
208
|
+
plan: await firstExistingPath([path.join(rootDir, "plan.md")]),
|
|
209
|
+
suggestions: await firstExistingPath([
|
|
210
|
+
path.join(rootDir, "suggestions.md"),
|
|
211
|
+
path.join(rootDir, "docs", "suggestions.md"),
|
|
212
|
+
]),
|
|
213
|
+
docsIndex: await firstExistingPath([
|
|
214
|
+
path.join(rootDir, "docs", "docs-index.md"),
|
|
215
|
+
]),
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { controllerLeasedControlAckSchema } from "@air-jam/sdk/protocol";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
export const controllerDisconnectionSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
release: z.union([
|
|
7
|
+
controllerLeasedControlAckSchema,
|
|
8
|
+
z.object({ status: z.literal("not-leased") }).strict(),
|
|
9
|
+
]),
|
|
10
|
+
leave: z.discriminatedUnion("status", [
|
|
11
|
+
z.object({ status: z.literal("acknowledged") }).strict(),
|
|
12
|
+
z.object({ status: z.literal("not-connected") }).strict(),
|
|
13
|
+
z.object({ status: z.literal("rejected"), message: z.string() }).strict(),
|
|
14
|
+
z
|
|
15
|
+
.object({ status: z.literal("unconfirmed"), message: z.string() })
|
|
16
|
+
.strict(),
|
|
17
|
+
]),
|
|
18
|
+
})
|
|
19
|
+
.strict();
|
|
20
|
+
export type ControllerDisconnection = z.infer<
|
|
21
|
+
typeof controllerDisconnectionSchema
|
|
22
|
+
>;
|