@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,229 @@
|
|
|
1
|
+
import { closeSync, openSync, writeSync } from "node:fs";
|
|
2
|
+
import type { z } from "zod";
|
|
3
|
+
import {
|
|
4
|
+
resolveDevtoolsHelperArgs,
|
|
5
|
+
resolveDevtoolsHelperScript,
|
|
6
|
+
resolveProjectDevtoolsHelperScript,
|
|
7
|
+
} from "./helper-scripts.js";
|
|
8
|
+
import {
|
|
9
|
+
closeAfterProcessFailure,
|
|
10
|
+
closeScopedProcess,
|
|
11
|
+
spawnScopedProcess,
|
|
12
|
+
type ProcessScopeObserver,
|
|
13
|
+
} from "./managed-process-scope.js";
|
|
14
|
+
import { nodeProcessEnvironment } from "./node-process-environment.js";
|
|
15
|
+
import { processScopeAdmissionSchema } from "./process-scope-protocol.js";
|
|
16
|
+
|
|
17
|
+
const environmentKeys = [
|
|
18
|
+
"PATH",
|
|
19
|
+
"HOME",
|
|
20
|
+
"TMPDIR",
|
|
21
|
+
"TEMP",
|
|
22
|
+
"TMP",
|
|
23
|
+
"NODE_EXTRA_CA_CERTS",
|
|
24
|
+
"HTTP_PROXY",
|
|
25
|
+
"HTTPS_PROXY",
|
|
26
|
+
"ALL_PROXY",
|
|
27
|
+
"NO_PROXY",
|
|
28
|
+
"http_proxy",
|
|
29
|
+
"https_proxy",
|
|
30
|
+
"all_proxy",
|
|
31
|
+
"no_proxy",
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
const LOG_BYTES = 1_000_000;
|
|
35
|
+
const STARTUP_MS = 10_000;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* One helper process that runs game code apart from the owner, answering one
|
|
39
|
+
* request at a time over IPC. Its errors start with `<name>_`, such as
|
|
40
|
+
* `policy_timeout`, so callers can tell them apart.
|
|
41
|
+
*/
|
|
42
|
+
export async function startHelperChannel<
|
|
43
|
+
TRequest extends { id: string },
|
|
44
|
+
TResponse extends { kind: string; id?: string },
|
|
45
|
+
>({
|
|
46
|
+
name,
|
|
47
|
+
helper,
|
|
48
|
+
rootDir,
|
|
49
|
+
toolingRootDir,
|
|
50
|
+
onScope,
|
|
51
|
+
startupSignal,
|
|
52
|
+
logPath,
|
|
53
|
+
maxBytes,
|
|
54
|
+
requestSchema,
|
|
55
|
+
responseSchema,
|
|
56
|
+
}: {
|
|
57
|
+
name: string;
|
|
58
|
+
helper: string;
|
|
59
|
+
rootDir: string;
|
|
60
|
+
toolingRootDir?: string;
|
|
61
|
+
onScope?: ProcessScopeObserver;
|
|
62
|
+
startupSignal?: AbortSignal;
|
|
63
|
+
logPath: string;
|
|
64
|
+
maxBytes: number;
|
|
65
|
+
requestSchema: z.ZodType<TRequest>;
|
|
66
|
+
responseSchema: z.ZodType<TResponse>;
|
|
67
|
+
}): Promise<{
|
|
68
|
+
request: (input: TRequest, timeoutMs: number) => Promise<TResponse>;
|
|
69
|
+
busy: () => boolean;
|
|
70
|
+
/** Ends the startup signal's hold once the caller has initialized the helper. */
|
|
71
|
+
started: () => void;
|
|
72
|
+
stop: () => Promise<void>;
|
|
73
|
+
}> {
|
|
74
|
+
startupSignal?.throwIfAborted();
|
|
75
|
+
const script = toolingRootDir
|
|
76
|
+
? resolveProjectDevtoolsHelperScript(toolingRootDir, helper)
|
|
77
|
+
: resolveDevtoolsHelperScript(helper);
|
|
78
|
+
const logDescriptor = openSync(logPath, "w", 0o600);
|
|
79
|
+
const child = await spawnScopedProcess(resolveDevtoolsHelperArgs(script), {
|
|
80
|
+
cwd: rootDir,
|
|
81
|
+
onScope,
|
|
82
|
+
startupSignal,
|
|
83
|
+
env: nodeProcessEnvironment(environmentKeys),
|
|
84
|
+
}).catch((error) => {
|
|
85
|
+
closeSync(logDescriptor);
|
|
86
|
+
if (startupSignal?.aborted)
|
|
87
|
+
throw new Error(`${name}_stopped`, { cause: error });
|
|
88
|
+
throw error;
|
|
89
|
+
});
|
|
90
|
+
let failure: Error | undefined;
|
|
91
|
+
let ready = false;
|
|
92
|
+
let pending:
|
|
93
|
+
| {
|
|
94
|
+
id: string;
|
|
95
|
+
resolve: (value: TResponse) => void;
|
|
96
|
+
reject: (error: Error) => void;
|
|
97
|
+
timer: ReturnType<typeof setTimeout>;
|
|
98
|
+
expired: boolean;
|
|
99
|
+
}
|
|
100
|
+
| undefined;
|
|
101
|
+
let stopping: Promise<void> | undefined;
|
|
102
|
+
let resolveReady: () => void;
|
|
103
|
+
let rejectReady: (error: Error) => void;
|
|
104
|
+
const boot = new Promise<void>((resolve, reject) => {
|
|
105
|
+
resolveReady = resolve;
|
|
106
|
+
rejectReady = reject;
|
|
107
|
+
});
|
|
108
|
+
const fail = (error: Error) => {
|
|
109
|
+
failure ??= error;
|
|
110
|
+
rejectReady(error);
|
|
111
|
+
if (pending) {
|
|
112
|
+
clearTimeout(pending.timer);
|
|
113
|
+
pending.reject(error);
|
|
114
|
+
pending = undefined;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
child.on("error", fail);
|
|
118
|
+
child.once("exit", () => {
|
|
119
|
+
fail(new Error(`${name}_exited: The ${name} process is unavailable.`));
|
|
120
|
+
});
|
|
121
|
+
let logBytes = 0;
|
|
122
|
+
const log = (chunk: Buffer) => {
|
|
123
|
+
const remaining = LOG_BYTES - logBytes;
|
|
124
|
+
if (remaining > 0) {
|
|
125
|
+
const bounded = chunk.subarray(0, remaining);
|
|
126
|
+
try {
|
|
127
|
+
let offset = 0;
|
|
128
|
+
while (offset < bounded.length)
|
|
129
|
+
offset += writeSync(logDescriptor, bounded.subarray(offset));
|
|
130
|
+
} catch (error) {
|
|
131
|
+
fail(error instanceof Error ? error : new Error(String(error)));
|
|
132
|
+
child.kill("SIGKILL");
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
logBytes += chunk.length;
|
|
136
|
+
if (logBytes > LOG_BYTES) {
|
|
137
|
+
fail(
|
|
138
|
+
new Error(
|
|
139
|
+
`${name}_log_limit: The ${name} process exceeded its 1 MB diagnostic log budget.`,
|
|
140
|
+
),
|
|
141
|
+
);
|
|
142
|
+
child.kill("SIGKILL");
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
child.stdout?.on("data", log);
|
|
146
|
+
child.stderr?.on("data", log);
|
|
147
|
+
child.on("message", (message: unknown) => {
|
|
148
|
+
if (message === 0) return;
|
|
149
|
+
if (processScopeAdmissionSchema.safeParse(message).success) return;
|
|
150
|
+
try {
|
|
151
|
+
if (Buffer.byteLength(JSON.stringify(message)) > maxBytes)
|
|
152
|
+
throw new Error(`${name}_protocol: Oversized response.`);
|
|
153
|
+
const result = responseSchema.parse(message);
|
|
154
|
+
if (result.kind === "ready") {
|
|
155
|
+
if (ready) throw new Error(`${name}_protocol: Duplicate startup.`);
|
|
156
|
+
ready = true;
|
|
157
|
+
resolveReady();
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (!pending || result.id !== pending.id)
|
|
161
|
+
throw new Error(`${name}_protocol: Unexpected response ID.`);
|
|
162
|
+
const request = pending;
|
|
163
|
+
pending = undefined;
|
|
164
|
+
clearTimeout(request.timer);
|
|
165
|
+
if (!request.expired) request.resolve(result);
|
|
166
|
+
} catch (error) {
|
|
167
|
+
fail(error instanceof Error ? error : new Error(String(error)));
|
|
168
|
+
child.kill("SIGKILL");
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
const request = (input: TRequest, timeoutMs: number) => {
|
|
172
|
+
if (failure) return Promise.reject(failure);
|
|
173
|
+
if (pending)
|
|
174
|
+
return Promise.reject(
|
|
175
|
+
new Error(`${name}_busy: The previous request has not returned.`),
|
|
176
|
+
);
|
|
177
|
+
const parsed = requestSchema.parse(input);
|
|
178
|
+
if (Buffer.byteLength(JSON.stringify(parsed)) > maxBytes)
|
|
179
|
+
return Promise.reject(
|
|
180
|
+
new Error(`${name}_protocol: Request exceeds its byte budget.`),
|
|
181
|
+
);
|
|
182
|
+
return new Promise<TResponse>((resolve, reject) => {
|
|
183
|
+
const timer = setTimeout(() => {
|
|
184
|
+
if (pending?.id !== parsed.id) return;
|
|
185
|
+
pending.expired = true;
|
|
186
|
+
reject(new Error(`${name}_timeout: Request exceeded its deadline.`));
|
|
187
|
+
}, timeoutMs);
|
|
188
|
+
pending = { id: parsed.id, resolve, reject, timer, expired: false };
|
|
189
|
+
child.send(parsed, (error) => {
|
|
190
|
+
if (error) fail(error);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
const stop = () =>
|
|
195
|
+
(stopping ??= (async () => {
|
|
196
|
+
startupSignal?.removeEventListener("abort", aborted);
|
|
197
|
+
fail(new Error(`${name}_stopped`));
|
|
198
|
+
try {
|
|
199
|
+
await closeScopedProcess(child);
|
|
200
|
+
} finally {
|
|
201
|
+
child.stdout?.destroy();
|
|
202
|
+
child.stderr?.destroy();
|
|
203
|
+
closeSync(logDescriptor);
|
|
204
|
+
}
|
|
205
|
+
})());
|
|
206
|
+
const aborted = () => {
|
|
207
|
+
void stop().catch(() => undefined);
|
|
208
|
+
};
|
|
209
|
+
startupSignal?.addEventListener("abort", aborted, { once: true });
|
|
210
|
+
const bootTimeout = setTimeout(
|
|
211
|
+
() => fail(new Error(`${name}_startup_timeout`)),
|
|
212
|
+
STARTUP_MS,
|
|
213
|
+
);
|
|
214
|
+
try {
|
|
215
|
+
if (startupSignal?.aborted) aborted();
|
|
216
|
+
await boot;
|
|
217
|
+
} catch (error) {
|
|
218
|
+
startupSignal?.removeEventListener("abort", aborted);
|
|
219
|
+
return closeAfterProcessFailure(stop, error);
|
|
220
|
+
} finally {
|
|
221
|
+
clearTimeout(bootTimeout);
|
|
222
|
+
}
|
|
223
|
+
return {
|
|
224
|
+
request,
|
|
225
|
+
busy: () => pending !== undefined,
|
|
226
|
+
started: () => startupSignal?.removeEventListener("abort", aborted),
|
|
227
|
+
stop,
|
|
228
|
+
};
|
|
229
|
+
}
|
package/src/helper-scripts.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
5
5
|
|
|
6
|
-
const require = createRequire(import.meta.url);
|
|
7
6
|
const moduleDir = path.dirname(fileURLToPath(import.meta.url));
|
|
8
7
|
|
|
9
8
|
export const resolveDevtoolsHelperScript = (fileName: string): string => {
|
|
@@ -34,10 +33,9 @@ export const resolveDevtoolsHelperScript = (fileName: string): string => {
|
|
|
34
33
|
|
|
35
34
|
const typescriptExtensions = new Set([".ts", ".tsx", ".mts", ".cts"]);
|
|
36
35
|
const projectTypescriptLoaderHelpers = new Set([
|
|
37
|
-
"agent-contract",
|
|
38
|
-
"inspect-airjam-agent",
|
|
39
36
|
"list-visual-scenarios",
|
|
40
37
|
"run-visual-capture",
|
|
38
|
+
"run-headless-room",
|
|
41
39
|
]);
|
|
42
40
|
|
|
43
41
|
export const resolveDevtoolsHelperArgs = (helperPath: string): string[] =>
|
|
@@ -45,5 +43,27 @@ export const resolveDevtoolsHelperArgs = (helperPath: string): string[] =>
|
|
|
45
43
|
projectTypescriptLoaderHelpers.has(
|
|
46
44
|
path.basename(helperPath, path.extname(helperPath)),
|
|
47
45
|
)
|
|
48
|
-
? [
|
|
46
|
+
? [
|
|
47
|
+
"--import",
|
|
48
|
+
pathToFileURL(createRequire(helperPath).resolve("tsx")).href,
|
|
49
|
+
helperPath,
|
|
50
|
+
]
|
|
49
51
|
: [helperPath];
|
|
52
|
+
|
|
53
|
+
export function resolveProjectDevtoolsHelperScript(
|
|
54
|
+
projectDir: string,
|
|
55
|
+
fileName: string,
|
|
56
|
+
) {
|
|
57
|
+
const projectRequire = createRequire(path.join(projectDir, "package.json"));
|
|
58
|
+
const manifest = projectRequire.resolve("@air-jam/devtools/package.json");
|
|
59
|
+
const helper = path.join(
|
|
60
|
+
path.dirname(manifest),
|
|
61
|
+
"dist/tooling",
|
|
62
|
+
fileName.replace(/\.ts$/, ".js"),
|
|
63
|
+
);
|
|
64
|
+
if (!existsSync(helper))
|
|
65
|
+
throw new Error(
|
|
66
|
+
`The pinned dependency graph is missing its runtime helper: ${fileName}`,
|
|
67
|
+
);
|
|
68
|
+
return helper;
|
|
69
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { lstat, readFile, readdir, readlink, realpath } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
/** Hash installed code, including postinstall output; mutable tool caches are not dependencies. */
|
|
6
|
+
export async function inspectInstalledDependencies(
|
|
7
|
+
rootDir: string,
|
|
8
|
+
liveRoot: string,
|
|
9
|
+
) {
|
|
10
|
+
const directory = path.join(rootDir, "node_modules"),
|
|
11
|
+
hash = createHash("sha256");
|
|
12
|
+
const excluded = new Set([
|
|
13
|
+
".cache",
|
|
14
|
+
".vite",
|
|
15
|
+
".vite-temp",
|
|
16
|
+
".modules.yaml",
|
|
17
|
+
".pnpm/lock.yaml",
|
|
18
|
+
]);
|
|
19
|
+
const originalModules = path.join(liveRoot, "node_modules");
|
|
20
|
+
const inside = (filename: string) => {
|
|
21
|
+
const relative = path.relative(directory, filename);
|
|
22
|
+
return (
|
|
23
|
+
relative !== ".." &&
|
|
24
|
+
!relative.startsWith(`..${path.sep}`) &&
|
|
25
|
+
!path.isAbsolute(relative)
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
if (!inside(await realpath(directory)))
|
|
29
|
+
throw new Error(
|
|
30
|
+
"build_dependencies_external: Dependencies resolve outside the snapshot.",
|
|
31
|
+
);
|
|
32
|
+
async function walk(relative = "") {
|
|
33
|
+
for (const name of (await readdir(path.join(directory, relative))).sort()) {
|
|
34
|
+
const filename = relative ? `${relative}/${name}` : name;
|
|
35
|
+
if (excluded.has(filename)) continue;
|
|
36
|
+
const absolute = path.join(directory, filename),
|
|
37
|
+
stat = await lstat(absolute);
|
|
38
|
+
const kind = stat.isDirectory()
|
|
39
|
+
? "directory"
|
|
40
|
+
: stat.isSymbolicLink()
|
|
41
|
+
? "link"
|
|
42
|
+
: "file";
|
|
43
|
+
hash.update(JSON.stringify([filename, stat.mode & 511, kind]));
|
|
44
|
+
if (stat.isDirectory()) await walk(filename);
|
|
45
|
+
else if (stat.isSymbolicLink()) {
|
|
46
|
+
if (!inside(await realpath(absolute)))
|
|
47
|
+
throw new Error(
|
|
48
|
+
`build_dependencies_external: Dependency link escapes the snapshot: ${filename}`,
|
|
49
|
+
);
|
|
50
|
+
hash.update(await readlink(absolute));
|
|
51
|
+
} else if (stat.isFile()) {
|
|
52
|
+
const content = await readFile(absolute);
|
|
53
|
+
if (
|
|
54
|
+
relative === ".bin" &&
|
|
55
|
+
content.includes(Buffer.from(originalModules))
|
|
56
|
+
)
|
|
57
|
+
throw new Error(
|
|
58
|
+
`build_dependencies_external: A command shim points at the live checkout: ${filename}`,
|
|
59
|
+
);
|
|
60
|
+
hash.update(createHash("sha256").update(content).digest());
|
|
61
|
+
} else
|
|
62
|
+
throw new Error(
|
|
63
|
+
`build_dependencies_invalid: Unsupported installed entry: ${filename}`,
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
await walk();
|
|
68
|
+
return {
|
|
69
|
+
installedTreeHash: hash.digest("hex"),
|
|
70
|
+
installedLockfileHash: createHash("sha256")
|
|
71
|
+
.update(await readFile(path.join(directory, ".pnpm/lock.yaml")))
|
|
72
|
+
.digest("hex"),
|
|
73
|
+
};
|
|
74
|
+
}
|