@air-jam/devtools 0.9.3 → 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/README.md +60 -0
- package/dist/{chunk-VKMJO6VN.js → chunk-2O67AXCU.js} +150 -40
- 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-CKFT2ZJE.js → chunk-MEIMOSZC.js} +53 -105
- package/dist/chunk-MEIMOSZC.js.map +1 -0
- package/dist/{chunk-GUEZP773.js → chunk-O3XG3FNL.js} +204 -41
- 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 +9 -3
- package/dist/context.js +2 -1
- package/dist/controller.d.ts +33 -7
- package/dist/controller.js +18 -8
- package/dist/dependencies.d.ts +44 -0
- package/dist/dependencies.js +10 -0
- package/dist/dev.d.ts +9 -3
- package/dist/dev.js +3 -4
- 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 -57
- package/dist/game-session-broker.js +33 -228
- package/dist/game-session-broker.js.map +1 -1
- package/dist/game-session.d.ts +3931 -10
- package/dist/game-session.js +186 -15
- package/dist/game-session.js.map +1 -1
- 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 +11 -4
- package/dist/games.js +4 -2
- package/dist/harness/visual.d.ts +34 -151
- package/dist/harness/visual.js +6 -1
- package/dist/logs.d.ts +8 -2
- package/dist/logs.js +3 -4
- package/dist/logs.js.map +1 -1
- package/dist/managed-process-scope-BicYi_t9.d.ts +3 -0
- package/dist/mcp-config.js +2 -1
- package/dist/mcp-config.js.map +1 -1
- package/dist/platform-auth.d.ts +8 -111
- package/dist/platform-auth.js +9 -1
- 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 +40 -2
- package/dist/platform-game-media.js +1 -1
- package/dist/platform-games.d.ts +24 -2
- package/dist/platform-games.js +16 -84
- package/dist/platform-games.js.map +1 -1
- package/dist/quality.d.ts +9 -3
- package/dist/quality.js +3 -4
- package/dist/quality.js.map +1 -1
- package/dist/release.d.ts +226 -16
- package/dist/release.js +18 -1331
- package/dist/release.js.map +1 -1
- 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.js +54 -0
- package/dist/tooling/describe-game.js.map +1 -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.js +769 -67
- package/dist/tooling/hold-runtime-host.js.map +1 -1
- package/dist/tooling/list-visual-scenarios.js +18 -55
- package/dist/tooling/list-visual-scenarios.js.map +1 -1
- 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.js +70 -34
- package/dist/tooling/run-visual-capture.js.map +1 -1
- 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-C6NrHt88.d.ts → types-CdYrgrG_.d.ts} +337 -76
- package/dist/types-DyRD-ym1.d.ts +141 -0
- package/dist/visual.d.ts +9 -3
- package/dist/visual.js +24 -68
- package/dist/visual.js.map +1 -1
- package/package.json +51 -14
- package/src/bounded-response.ts +28 -0
- package/src/built-game-runtime.ts +152 -0
- package/src/context.ts +2 -13
- package/src/controller-protocol.ts +22 -0
- package/src/controller.ts +747 -597
- 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 +46 -50
- package/src/game-action-observation.ts +11 -1
- 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 +689 -197
- 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 +164 -417
- package/src/game-settings.ts +295 -0
- package/src/games.ts +88 -92
- package/src/harness/visual/browser.ts +100 -0
- package/src/harness/visual/controller-observation.ts +181 -0
- package/src/harness/visual/runner.ts +24 -21
- package/src/harness/visual/runtime-controller-observations.ts +151 -0
- package/src/harness/visual/scenario-contract.ts +1 -2
- package/src/harness/visual/scenario-helpers.ts +5 -1
- package/src/harness/visual/screencast.ts +155 -0
- package/src/harness/visual/session.ts +72 -41
- package/src/harness/visual/types.ts +8 -5
- 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 +25 -5
- package/src/installed-dependencies.ts +74 -0
- package/src/managed-process-scope.ts +481 -0
- package/src/node-process-environment.ts +10 -0
- package/src/platform-auth.ts +194 -55
- package/src/platform-game-analytics.ts +50 -0
- package/src/platform-game-app-id.ts +99 -0
- package/src/platform-games.ts +13 -111
- 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/release.ts +28 -42
- 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 +106 -18
- 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 +255 -38
- package/src/tooling/list-visual-scenarios.ts +19 -62
- package/src/tooling/load-game.ts +79 -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 +37 -23
- package/src/tooling/runtime-owner-actions.ts +23 -0
- package/src/tooling/seal-game-build.ts +118 -0
- package/src/tooling/visual-pack.ts +10 -45
- package/src/types.ts +54 -77
- package/src/visual.ts +14 -22
- package/src/windows-process-scopes.ts +189 -0
- package/dist/agent.d.ts +0 -15
- package/dist/agent.js +0 -19
- package/dist/chunk-5YAARMW5.js +0 -36
- package/dist/chunk-5YAARMW5.js.map +0 -1
- package/dist/chunk-6WQODT37.js +0 -1019
- package/dist/chunk-6WQODT37.js.map +0 -1
- package/dist/chunk-CKFT2ZJE.js.map +0 -1
- package/dist/chunk-ER3Q2C4G.js +0 -358
- package/dist/chunk-ER3Q2C4G.js.map +0 -1
- package/dist/chunk-GUEZP773.js.map +0 -1
- package/dist/chunk-HIDNI56E.js +0 -33
- package/dist/chunk-HIDNI56E.js.map +0 -1
- package/dist/chunk-QKXS5D35.js +0 -43
- package/dist/chunk-QKXS5D35.js.map +0 -1
- package/dist/chunk-S4LSCEVE.js +0 -261
- package/dist/chunk-S4LSCEVE.js.map +0 -1
- package/dist/chunk-VKMJO6VN.js.map +0 -1
- package/dist/chunk-WFUR3MXY.js +0 -67
- package/dist/chunk-WFUR3MXY.js.map +0 -1
- package/dist/chunk-XEMR7KUE.js +0 -361
- package/dist/chunk-XEMR7KUE.js.map +0 -1
- package/dist/chunk-ZLPD7FY5.js +0 -191
- package/dist/chunk-ZLPD7FY5.js.map +0 -1
- package/dist/tooling/agent-contract.js +0 -193
- package/dist/tooling/agent-contract.js.map +0 -1
- package/dist/tooling/inspect-airjam-agent.js +0 -37
- package/dist/tooling/inspect-airjam-agent.js.map +0 -1
- package/src/agent.ts +0 -380
- package/src/tooling/agent-contract.ts +0 -232
- package/src/tooling/agent-declaration.ts +0 -36
- package/src/tooling/airjam-agent-inspection.ts +0 -45
- package/src/tooling/airjam-agent.ts +0 -118
- package/src/tooling/inspect-airjam-agent.ts +0 -20
- /package/dist/{agent.js.map → dependencies.js.map} +0 -0
- /package/dist/tooling/{agent-contract.d.ts → describe-game.d.ts} +0 -0
- /package/dist/tooling/{inspect-airjam-agent.d.ts → game-session-broker.d.ts} +0 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { dependencyInstallObservationSchema } from "./dependency-install-contract.js";
|
|
3
|
+
|
|
4
|
+
const digest = z.string().regex(/^[a-f0-9]{64}$/);
|
|
5
|
+
export const gameBuildManifestSchema = z.object({
|
|
6
|
+
version: z.literal(1),
|
|
7
|
+
buildKey: digest,
|
|
8
|
+
sourceHash: digest,
|
|
9
|
+
lockfileHash: digest,
|
|
10
|
+
distHash: digest,
|
|
11
|
+
toolchain: z.object({
|
|
12
|
+
node: z.string(),
|
|
13
|
+
pnpm: z.string(),
|
|
14
|
+
devtools: z.string(),
|
|
15
|
+
platform: z.string(),
|
|
16
|
+
architecture: z.string(),
|
|
17
|
+
implementationHash: digest,
|
|
18
|
+
environmentHash: digest,
|
|
19
|
+
projectRoot: z.string().min(1),
|
|
20
|
+
nodeAbi: z.string(),
|
|
21
|
+
}),
|
|
22
|
+
dependencies: z.object({
|
|
23
|
+
installedTreeHash: digest,
|
|
24
|
+
installedLockfileHash: digest,
|
|
25
|
+
installation: dependencyInstallObservationSchema,
|
|
26
|
+
}),
|
|
27
|
+
createdAt: z.iso.datetime(),
|
|
28
|
+
files: z
|
|
29
|
+
.array(
|
|
30
|
+
z.object({
|
|
31
|
+
path: z.string().min(1),
|
|
32
|
+
bytes: z.number().int().nonnegative(),
|
|
33
|
+
sha256: digest,
|
|
34
|
+
}),
|
|
35
|
+
)
|
|
36
|
+
.min(1)
|
|
37
|
+
.max(100_000),
|
|
38
|
+
sourceArchive: z.object({
|
|
39
|
+
bytes: z.number().int().nonnegative(),
|
|
40
|
+
sha256: digest,
|
|
41
|
+
}),
|
|
42
|
+
});
|
|
43
|
+
export const gameBuildIdentitySchema = gameBuildManifestSchema.omit({
|
|
44
|
+
files: true,
|
|
45
|
+
sourceArchive: true,
|
|
46
|
+
});
|
|
47
|
+
export const pinnedGameBuildSchema = z.object({
|
|
48
|
+
rootDir: z.string().min(1),
|
|
49
|
+
distDir: z.string().min(1),
|
|
50
|
+
configPath: z.string().min(1),
|
|
51
|
+
manifestPath: z.string().min(1),
|
|
52
|
+
sourceArchivePath: z.string().min(1),
|
|
53
|
+
manifest: gameBuildManifestSchema,
|
|
54
|
+
reused: z.boolean(),
|
|
55
|
+
});
|
|
56
|
+
export type PinnedGameBuild = z.infer<typeof pinnedGameBuildSchema>;
|
|
57
|
+
export const gameBuildResultSchema = z.discriminatedUnion("ok", [
|
|
58
|
+
z.object({
|
|
59
|
+
type: z.literal("air-jam-game-build/v1"),
|
|
60
|
+
ok: z.literal(true),
|
|
61
|
+
build: pinnedGameBuildSchema,
|
|
62
|
+
}),
|
|
63
|
+
z.object({
|
|
64
|
+
type: z.literal("air-jam-game-build/v1"),
|
|
65
|
+
ok: z.literal(false),
|
|
66
|
+
error: z.string(),
|
|
67
|
+
}),
|
|
68
|
+
]);
|
|
69
|
+
|
|
70
|
+
export const gameBuildMarkerSchema = z
|
|
71
|
+
.object({ buildKey: digest, projectRoot: z.string().min(1) })
|
|
72
|
+
.strict();
|
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
import type { ChildProcess } from "node:child_process";
|
|
2
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
3
|
+
import { closeSync, createWriteStream, openSync, writeSync } from "node:fs";
|
|
4
|
+
import {
|
|
5
|
+
copyFile,
|
|
6
|
+
lstat,
|
|
7
|
+
mkdir,
|
|
8
|
+
readdir,
|
|
9
|
+
readFile,
|
|
10
|
+
rename,
|
|
11
|
+
rm,
|
|
12
|
+
stat,
|
|
13
|
+
writeFile,
|
|
14
|
+
} from "node:fs/promises";
|
|
15
|
+
import path from "node:path";
|
|
16
|
+
import { finished, pipeline } from "node:stream/promises";
|
|
17
|
+
import { ZipFile } from "yazl";
|
|
18
|
+
import type { installDependencies } from "./dependencies.js";
|
|
19
|
+
import {
|
|
20
|
+
gameBuildManifestSchema,
|
|
21
|
+
gameBuildMarkerSchema,
|
|
22
|
+
gameBuildResultSchema,
|
|
23
|
+
type PinnedGameBuild,
|
|
24
|
+
} from "./game-build-protocol.js";
|
|
25
|
+
import {
|
|
26
|
+
MAXIMUM_GAME_RUN_BUILD_LOG_BYTES,
|
|
27
|
+
type AirJamGameRunBuildLog,
|
|
28
|
+
} from "./game-run-protocol.js";
|
|
29
|
+
import {
|
|
30
|
+
resolveDevtoolsHelperArgs,
|
|
31
|
+
resolveDevtoolsHelperScript,
|
|
32
|
+
} from "./helper-scripts.js";
|
|
33
|
+
import { inspectInstalledDependencies } from "./installed-dependencies.js";
|
|
34
|
+
import {
|
|
35
|
+
closeAfterProcessFailure,
|
|
36
|
+
closeScopedProcess,
|
|
37
|
+
spawnScopedProcess,
|
|
38
|
+
type ProcessScopeObserver,
|
|
39
|
+
} from "./managed-process-scope.js";
|
|
40
|
+
import {
|
|
41
|
+
isDigestOnlySourceFile,
|
|
42
|
+
SOURCE_ARCHIVE_MANIFEST,
|
|
43
|
+
} from "./source-tree-contract.js";
|
|
44
|
+
import { copySourceTree, readSourceTree } from "./source-tree.js";
|
|
45
|
+
|
|
46
|
+
const digest = (value: string | Buffer) =>
|
|
47
|
+
createHash("sha256").update(value).digest("hex");
|
|
48
|
+
|
|
49
|
+
export const GAME_BUILD_CACHE_MAXIMUM_BYTES = 2 * 1024 * 1024 * 1024;
|
|
50
|
+
const GAME_BUILD_CACHE_MAXIMUM_ENTRIES = 3;
|
|
51
|
+
|
|
52
|
+
async function directoryBytes(directory: string): Promise<number> {
|
|
53
|
+
let bytes = 0;
|
|
54
|
+
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
55
|
+
const target = path.join(directory, entry.name);
|
|
56
|
+
bytes += entry.isDirectory()
|
|
57
|
+
? await directoryBytes(target)
|
|
58
|
+
: (await lstat(target)).size;
|
|
59
|
+
}
|
|
60
|
+
return bytes;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Logical bytes include dependencies and evidence, without following package symlinks. */
|
|
64
|
+
export async function enforceGameBuildCacheLimits(
|
|
65
|
+
cache: string,
|
|
66
|
+
currentKey: string,
|
|
67
|
+
) {
|
|
68
|
+
const currentBytes = await directoryBytes(path.join(cache, currentKey));
|
|
69
|
+
if (currentBytes > GAME_BUILD_CACHE_MAXIMUM_BYTES)
|
|
70
|
+
throw new Error(
|
|
71
|
+
"build_cache_too_large: A sealed game exceeds the 2 GiB cache allowance.",
|
|
72
|
+
);
|
|
73
|
+
const older = (
|
|
74
|
+
await Promise.all(
|
|
75
|
+
(await readdir(cache))
|
|
76
|
+
.filter((name) => /^[a-f0-9]{64}$/.test(name) && name !== currentKey)
|
|
77
|
+
.map(async (name) => ({
|
|
78
|
+
name,
|
|
79
|
+
time: (await stat(path.join(cache, name))).mtimeMs,
|
|
80
|
+
bytes: await directoryBytes(path.join(cache, name)),
|
|
81
|
+
})),
|
|
82
|
+
)
|
|
83
|
+
).sort(
|
|
84
|
+
(left, right) =>
|
|
85
|
+
left.time - right.time || left.name.localeCompare(right.name),
|
|
86
|
+
);
|
|
87
|
+
let bytes =
|
|
88
|
+
currentBytes + older.reduce((total, entry) => total + entry.bytes, 0);
|
|
89
|
+
let entries = older.length + 1;
|
|
90
|
+
for (const entry of older) {
|
|
91
|
+
if (
|
|
92
|
+
entries <= GAME_BUILD_CACHE_MAXIMUM_ENTRIES &&
|
|
93
|
+
bytes <= GAME_BUILD_CACHE_MAXIMUM_BYTES
|
|
94
|
+
)
|
|
95
|
+
break;
|
|
96
|
+
await rm(path.join(cache, entry.name), { recursive: true });
|
|
97
|
+
bytes -= entry.bytes;
|
|
98
|
+
entries--;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export async function distributionFiles(
|
|
103
|
+
directory: string,
|
|
104
|
+
relative = "",
|
|
105
|
+
): Promise<PinnedGameBuild["manifest"]["files"]> {
|
|
106
|
+
const files: PinnedGameBuild["manifest"]["files"] = [];
|
|
107
|
+
for (const entry of (
|
|
108
|
+
await readdir(path.join(directory, relative), { withFileTypes: true })
|
|
109
|
+
).sort((left, right) => left.name.localeCompare(right.name, "en"))) {
|
|
110
|
+
const name = relative ? `${relative}/${entry.name}` : entry.name;
|
|
111
|
+
if (entry.isDirectory())
|
|
112
|
+
files.push(...(await distributionFiles(directory, name)));
|
|
113
|
+
else if (entry.isFile()) {
|
|
114
|
+
const content = await readFile(path.join(directory, name));
|
|
115
|
+
files.push({
|
|
116
|
+
path: name,
|
|
117
|
+
bytes: content.length,
|
|
118
|
+
sha256: digest(content),
|
|
119
|
+
});
|
|
120
|
+
} else
|
|
121
|
+
throw new Error(`build_invalid_distribution: Unsupported entry: ${name}`);
|
|
122
|
+
}
|
|
123
|
+
return files;
|
|
124
|
+
}
|
|
125
|
+
export async function verifyPinnedGameBuild(build: PinnedGameBuild) {
|
|
126
|
+
const installed = await inspectInstalledDependencies(
|
|
127
|
+
build.rootDir,
|
|
128
|
+
build.manifest.toolchain.projectRoot,
|
|
129
|
+
);
|
|
130
|
+
if (
|
|
131
|
+
installed.installedTreeHash !==
|
|
132
|
+
build.manifest.dependencies.installedTreeHash ||
|
|
133
|
+
installed.installedLockfileHash !== build.manifest.lockfileHash
|
|
134
|
+
)
|
|
135
|
+
throw new Error(
|
|
136
|
+
"build_integrity_changed: Installed dependencies were modified.",
|
|
137
|
+
);
|
|
138
|
+
if ((await readSourceTree(build.rootDir)).hash !== build.manifest.sourceHash)
|
|
139
|
+
throw new Error("build_integrity_changed: The pinned source was modified.");
|
|
140
|
+
if (
|
|
141
|
+
digest(JSON.stringify(await distributionFiles(build.distDir))) !==
|
|
142
|
+
build.manifest.distHash
|
|
143
|
+
)
|
|
144
|
+
throw new Error(
|
|
145
|
+
"build_integrity_changed: The pinned distribution was modified.",
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Archives the pinned tree itself, so its manifest reproduces the run's source hash by construction. */
|
|
150
|
+
async function archiveSource(
|
|
151
|
+
rootDir: string,
|
|
152
|
+
source: Awaited<ReturnType<typeof readSourceTree>>,
|
|
153
|
+
target: string,
|
|
154
|
+
) {
|
|
155
|
+
const archive = new ZipFile();
|
|
156
|
+
const writing = pipeline(
|
|
157
|
+
archive.outputStream,
|
|
158
|
+
createWriteStream(target, { flags: "wx", mode: 0o600 }),
|
|
159
|
+
);
|
|
160
|
+
const mtime = new Date("2000-01-01T00:00:00Z");
|
|
161
|
+
for (const entry of source.entries) {
|
|
162
|
+
if (entry.kind === "directory")
|
|
163
|
+
archive.addEmptyDirectory(entry.path, {
|
|
164
|
+
mode: 0o40000 | entry.mode,
|
|
165
|
+
mtime,
|
|
166
|
+
});
|
|
167
|
+
else if (entry.kind === "link")
|
|
168
|
+
archive.addBuffer(Buffer.from(entry.target), entry.path, {
|
|
169
|
+
mode: 0o120000 | entry.mode,
|
|
170
|
+
mtime,
|
|
171
|
+
});
|
|
172
|
+
else if (!isDigestOnlySourceFile(entry))
|
|
173
|
+
archive.addFile(path.join(rootDir, entry.path), entry.path, {
|
|
174
|
+
mode: 0o100000 | entry.mode,
|
|
175
|
+
mtime,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
archive.addBuffer(
|
|
179
|
+
Buffer.from(JSON.stringify(source)),
|
|
180
|
+
SOURCE_ARCHIVE_MANIFEST,
|
|
181
|
+
{
|
|
182
|
+
mode: 0o100600,
|
|
183
|
+
mtime,
|
|
184
|
+
},
|
|
185
|
+
);
|
|
186
|
+
archive.end();
|
|
187
|
+
await writing;
|
|
188
|
+
const content = await readFile(target);
|
|
189
|
+
if (content.length > 16 * 1024 * 1024)
|
|
190
|
+
throw new Error(
|
|
191
|
+
"build_source_archive_too_large: Compressed source exceeds the 16 MiB evidence limit.",
|
|
192
|
+
);
|
|
193
|
+
return { bytes: content.length, sha256: digest(content) };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** Called inside the admitted build scope; IO and arbitrary build scripts stay contained. */
|
|
197
|
+
export async function materializeGameBuild(options: {
|
|
198
|
+
projectDir: string;
|
|
199
|
+
configRelative: string;
|
|
200
|
+
toolchain: PinnedGameBuild["manifest"]["toolchain"];
|
|
201
|
+
install: (rootDir: string) => ReturnType<typeof installDependencies>;
|
|
202
|
+
build: (rootDir: string) => Promise<void>;
|
|
203
|
+
}): Promise<PinnedGameBuild> {
|
|
204
|
+
const cache = path.join(options.projectDir, ".airjam/devtools/game-builds");
|
|
205
|
+
await mkdir(cache, { recursive: true });
|
|
206
|
+
// The broker admits one project run; its process guardian has closed any previous build scope.
|
|
207
|
+
for (const name of await readdir(cache)) {
|
|
208
|
+
if (/^\.building-[a-f0-9-]{36}$/.test(name))
|
|
209
|
+
await rm(path.join(cache, name), { recursive: true, force: true });
|
|
210
|
+
else if (/^[a-f0-9]{64}$/.test(name)) {
|
|
211
|
+
try {
|
|
212
|
+
await readFile(path.join(cache, name, "build.json"));
|
|
213
|
+
} catch (error) {
|
|
214
|
+
if (
|
|
215
|
+
!(error instanceof Error) ||
|
|
216
|
+
!("code" in error) ||
|
|
217
|
+
error.code !== "ENOENT"
|
|
218
|
+
)
|
|
219
|
+
throw error;
|
|
220
|
+
const marker = gameBuildMarkerSchema.parse(
|
|
221
|
+
JSON.parse(
|
|
222
|
+
await readFile(path.join(cache, name, "building.json"), "utf8"),
|
|
223
|
+
),
|
|
224
|
+
);
|
|
225
|
+
if (
|
|
226
|
+
marker.buildKey !== name ||
|
|
227
|
+
marker.projectRoot !== options.projectDir
|
|
228
|
+
)
|
|
229
|
+
throw new Error(
|
|
230
|
+
"build_cache_invalid: Unknown incomplete cache owner.",
|
|
231
|
+
);
|
|
232
|
+
await rm(path.join(cache, name), { recursive: true });
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
const temporary = path.join(cache, `.building-${randomUUID()}`);
|
|
237
|
+
await mkdir(temporary);
|
|
238
|
+
let completed = false;
|
|
239
|
+
let ownedDirectory: string | undefined;
|
|
240
|
+
try {
|
|
241
|
+
let rootDir = path.join(temporary, "source");
|
|
242
|
+
const source = await copySourceTree(options.projectDir, rootDir);
|
|
243
|
+
if (source.entries.some((entry) => entry.path === SOURCE_ARCHIVE_MANIFEST))
|
|
244
|
+
throw new Error(
|
|
245
|
+
`build_source_invalid: ${SOURCE_ARCHIVE_MANIFEST} is reserved for source evidence.`,
|
|
246
|
+
);
|
|
247
|
+
const lockfileHash = digest(
|
|
248
|
+
await readFile(path.join(rootDir, "pnpm-lock.yaml")),
|
|
249
|
+
);
|
|
250
|
+
const key = digest(
|
|
251
|
+
JSON.stringify({
|
|
252
|
+
sourceHash: source.hash,
|
|
253
|
+
lockfileHash,
|
|
254
|
+
configRelative: options.configRelative,
|
|
255
|
+
toolchain: options.toolchain,
|
|
256
|
+
}),
|
|
257
|
+
);
|
|
258
|
+
const directory = path.join(cache, key);
|
|
259
|
+
const paths = (base: string) => ({
|
|
260
|
+
rootDir: path.join(base, "source"),
|
|
261
|
+
distDir: path.join(base, "source/dist"),
|
|
262
|
+
configPath: path.join(base, "source", options.configRelative),
|
|
263
|
+
manifestPath: path.join(base, "build.json"),
|
|
264
|
+
sourceArchivePath: path.join(base, "source.zip"),
|
|
265
|
+
});
|
|
266
|
+
let cached: string;
|
|
267
|
+
try {
|
|
268
|
+
cached = await readFile(path.join(directory, "build.json"), "utf8");
|
|
269
|
+
} catch (error) {
|
|
270
|
+
if (
|
|
271
|
+
!(error instanceof Error) ||
|
|
272
|
+
!("code" in error) ||
|
|
273
|
+
error.code !== "ENOENT"
|
|
274
|
+
)
|
|
275
|
+
throw error;
|
|
276
|
+
cached = "";
|
|
277
|
+
}
|
|
278
|
+
if (cached) {
|
|
279
|
+
const manifest = gameBuildManifestSchema.parse(JSON.parse(cached));
|
|
280
|
+
if (manifest.buildKey !== key || manifest.sourceHash !== source.hash)
|
|
281
|
+
throw new Error(
|
|
282
|
+
"build_cache_invalid: Cache identity does not match its key.",
|
|
283
|
+
);
|
|
284
|
+
const result = { ...paths(directory), manifest, reused: true };
|
|
285
|
+
await verifyPinnedGameBuild(result);
|
|
286
|
+
const archive = await readFile(result.sourceArchivePath);
|
|
287
|
+
if (
|
|
288
|
+
digest(archive) !== manifest.sourceArchive.sha256 ||
|
|
289
|
+
archive.length !== manifest.sourceArchive.bytes
|
|
290
|
+
)
|
|
291
|
+
throw new Error(
|
|
292
|
+
"build_cache_invalid: The original source archive was modified.",
|
|
293
|
+
);
|
|
294
|
+
await enforceGameBuildCacheLimits(cache, key);
|
|
295
|
+
return result;
|
|
296
|
+
}
|
|
297
|
+
// Install at the final stable path: pnpm command shims contain absolute paths.
|
|
298
|
+
await writeFile(
|
|
299
|
+
path.join(temporary, "building.json"),
|
|
300
|
+
JSON.stringify({ buildKey: key, projectRoot: options.projectDir }),
|
|
301
|
+
{ flag: "wx", mode: 0o600 },
|
|
302
|
+
);
|
|
303
|
+
await rename(temporary, directory);
|
|
304
|
+
ownedDirectory = directory;
|
|
305
|
+
rootDir = paths(directory).rootDir;
|
|
306
|
+
const installation = await options.install(rootDir);
|
|
307
|
+
const dependencies = {
|
|
308
|
+
...(await inspectInstalledDependencies(rootDir, options.projectDir)),
|
|
309
|
+
installation,
|
|
310
|
+
};
|
|
311
|
+
if (dependencies.installedLockfileHash !== lockfileHash)
|
|
312
|
+
throw new Error(
|
|
313
|
+
"build_dependencies_invalid: The installed lockfile differs from the pinned graph.",
|
|
314
|
+
);
|
|
315
|
+
await options.build(rootDir);
|
|
316
|
+
if ((await readSourceTree(rootDir)).hash !== source.hash)
|
|
317
|
+
throw new Error(
|
|
318
|
+
"build_source_changed: Installation or build changed the pinned source.",
|
|
319
|
+
);
|
|
320
|
+
const files = await distributionFiles(path.join(rootDir, "dist"));
|
|
321
|
+
const manifest = gameBuildManifestSchema.parse({
|
|
322
|
+
version: 1,
|
|
323
|
+
buildKey: key,
|
|
324
|
+
sourceHash: source.hash,
|
|
325
|
+
lockfileHash,
|
|
326
|
+
distHash: digest(JSON.stringify(files)),
|
|
327
|
+
toolchain: options.toolchain,
|
|
328
|
+
dependencies,
|
|
329
|
+
createdAt: new Date().toISOString(),
|
|
330
|
+
files,
|
|
331
|
+
sourceArchive: await archiveSource(
|
|
332
|
+
rootDir,
|
|
333
|
+
source,
|
|
334
|
+
path.join(directory, "source.zip"),
|
|
335
|
+
),
|
|
336
|
+
});
|
|
337
|
+
await writeFile(
|
|
338
|
+
path.join(directory, "build.pending.json"),
|
|
339
|
+
JSON.stringify(manifest, null, 2),
|
|
340
|
+
{ flag: "wx", mode: 0o600 },
|
|
341
|
+
);
|
|
342
|
+
await verifyPinnedGameBuild({
|
|
343
|
+
...paths(directory),
|
|
344
|
+
manifest,
|
|
345
|
+
reused: false,
|
|
346
|
+
});
|
|
347
|
+
await enforceGameBuildCacheLimits(cache, key);
|
|
348
|
+
await rename(
|
|
349
|
+
path.join(directory, "build.pending.json"),
|
|
350
|
+
path.join(directory, "build.json"),
|
|
351
|
+
);
|
|
352
|
+
completed = true;
|
|
353
|
+
return { ...paths(directory), manifest, reused: false };
|
|
354
|
+
} finally {
|
|
355
|
+
await rm(temporary, { recursive: true, force: true });
|
|
356
|
+
if (!completed && ownedDirectory)
|
|
357
|
+
await rm(ownedDirectory, { recursive: true, force: true });
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
export async function sealGameBuild(options: {
|
|
362
|
+
projectDir: string;
|
|
363
|
+
configRelative: string;
|
|
364
|
+
runDirectory: string;
|
|
365
|
+
signal: AbortSignal;
|
|
366
|
+
onScope?: ProcessScopeObserver;
|
|
367
|
+
onBuildLog?: (receipt: Omit<AirJamGameRunBuildLog, "path">) => void;
|
|
368
|
+
}) {
|
|
369
|
+
options.signal.throwIfAborted();
|
|
370
|
+
const helper = resolveDevtoolsHelperScript("seal-game-build.ts");
|
|
371
|
+
const logPath = path.join(options.runDirectory, "build.log");
|
|
372
|
+
const descriptor = openSync(logPath, "wx", 0o600);
|
|
373
|
+
const closeBuildProcess = async (child: ChildProcess) => {
|
|
374
|
+
await closeScopedProcess(child);
|
|
375
|
+
await Promise.all(
|
|
376
|
+
[child.stdout, child.stderr].map((stream) =>
|
|
377
|
+
stream
|
|
378
|
+
? finished(stream, { readable: true, writable: false, cleanup: true })
|
|
379
|
+
: undefined,
|
|
380
|
+
),
|
|
381
|
+
);
|
|
382
|
+
};
|
|
383
|
+
let child: ChildProcess | null = null;
|
|
384
|
+
let cancel = () => {};
|
|
385
|
+
let bytesWritten = 0;
|
|
386
|
+
let truncated = false;
|
|
387
|
+
let receiveLog: ((value: Buffer | string) => void) | undefined;
|
|
388
|
+
try {
|
|
389
|
+
child = await spawnScopedProcess(
|
|
390
|
+
[
|
|
391
|
+
...resolveDevtoolsHelperArgs(helper),
|
|
392
|
+
JSON.stringify({
|
|
393
|
+
projectDir: options.projectDir,
|
|
394
|
+
configRelative: options.configRelative,
|
|
395
|
+
}),
|
|
396
|
+
],
|
|
397
|
+
{
|
|
398
|
+
cwd: options.projectDir,
|
|
399
|
+
onScope: options.onScope,
|
|
400
|
+
startupSignal: options.signal,
|
|
401
|
+
},
|
|
402
|
+
);
|
|
403
|
+
const ownedChild = child;
|
|
404
|
+
const build = await new Promise<PinnedGameBuild>((resolve, reject) => {
|
|
405
|
+
let logFailed = false;
|
|
406
|
+
receiveLog = (value) => {
|
|
407
|
+
if (logFailed) return;
|
|
408
|
+
try {
|
|
409
|
+
const bytes = Buffer.isBuffer(value) ? value : Buffer.from(value);
|
|
410
|
+
const remaining = Math.max(
|
|
411
|
+
0,
|
|
412
|
+
MAXIMUM_GAME_RUN_BUILD_LOG_BYTES - bytesWritten,
|
|
413
|
+
);
|
|
414
|
+
const length = Math.min(remaining, bytes.length);
|
|
415
|
+
let offset = 0;
|
|
416
|
+
while (offset < length)
|
|
417
|
+
offset += writeSync(descriptor, bytes, offset, length - offset);
|
|
418
|
+
bytesWritten += length;
|
|
419
|
+
truncated ||= length < bytes.length;
|
|
420
|
+
} catch (error) {
|
|
421
|
+
logFailed = true;
|
|
422
|
+
reject(error);
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
ownedChild.stdout?.on("data", receiveLog);
|
|
426
|
+
ownedChild.stderr?.on("data", receiveLog);
|
|
427
|
+
ownedChild.on("message", (value: unknown) => {
|
|
428
|
+
const result = gameBuildResultSchema.safeParse(value);
|
|
429
|
+
if (!result.success) return;
|
|
430
|
+
if (result.data.ok) resolve(result.data.build);
|
|
431
|
+
else reject(new Error(result.data.error));
|
|
432
|
+
});
|
|
433
|
+
ownedChild.once("error", reject);
|
|
434
|
+
ownedChild.once("exit", () =>
|
|
435
|
+
reject(
|
|
436
|
+
new Error(
|
|
437
|
+
"build_process_ended: The build scope ended without a sealed result.",
|
|
438
|
+
),
|
|
439
|
+
),
|
|
440
|
+
);
|
|
441
|
+
cancel = () => reject(options.signal.reason);
|
|
442
|
+
options.signal.addEventListener("abort", cancel, { once: true });
|
|
443
|
+
if (options.signal.aborted) cancel();
|
|
444
|
+
});
|
|
445
|
+
await closeBuildProcess(ownedChild);
|
|
446
|
+
await verifyPinnedGameBuild(build);
|
|
447
|
+
await Promise.all([
|
|
448
|
+
copyFile(
|
|
449
|
+
build.manifestPath,
|
|
450
|
+
path.join(options.runDirectory, "build.json"),
|
|
451
|
+
),
|
|
452
|
+
copyFile(
|
|
453
|
+
build.sourceArchivePath,
|
|
454
|
+
path.join(options.runDirectory, "source.zip"),
|
|
455
|
+
),
|
|
456
|
+
]);
|
|
457
|
+
return build;
|
|
458
|
+
} catch (error) {
|
|
459
|
+
if (child) {
|
|
460
|
+
const failedChild = child;
|
|
461
|
+
return await closeAfterProcessFailure(
|
|
462
|
+
() => closeBuildProcess(failedChild),
|
|
463
|
+
error,
|
|
464
|
+
);
|
|
465
|
+
}
|
|
466
|
+
throw error;
|
|
467
|
+
} finally {
|
|
468
|
+
options.signal.removeEventListener("abort", cancel);
|
|
469
|
+
if (receiveLog) {
|
|
470
|
+
child?.stdout?.off("data", receiveLog);
|
|
471
|
+
child?.stderr?.off("data", receiveLog);
|
|
472
|
+
}
|
|
473
|
+
child?.stdout?.resume();
|
|
474
|
+
child?.stderr?.resume();
|
|
475
|
+
closeSync(descriptor);
|
|
476
|
+
const bytes = await readFile(logPath);
|
|
477
|
+
options.onBuildLog?.({
|
|
478
|
+
sha256: digest(bytes),
|
|
479
|
+
bytes: bytes.length,
|
|
480
|
+
truncated,
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
}
|