mirror of
https://github.com/morluto/rea.git
synced 2026-11-29 01:46:39 +00:00
refactor(cli): share compiled runtime checks with the session worker (#14557)
This commit is contained in:
1 parent
825fd0a19a
commit
0bbdbeaedf
8 files changed
+72
-91
No files matched your search
@@ -78,6 +78,7 @@
|
||||
"bridge/agentenv/solve.py",
|
||||
"bridge/agentenv/solve_cleanup.py",
|
||||
"scripts/rea.mjs",
|
||||
"scripts/lib/cli-compiled-runtime.mjs",
|
||||
"scripts/lib/cli-process-environment.mjs",
|
||||
"scripts/lib/runtime-admission.mjs",
|
||||
"scripts/rea-android-workspace-guardian.mjs",
|
||||
|
||||
+10
-8
@@ -23,6 +23,14 @@ const CAPTURE_SHARED_INPUTS = [
|
||||
const UBUNTU_ARCHIVE_ACTION =
|
||||
".github/actions/ubuntu-archive/action.{yml,yaml}";
|
||||
|
||||
const CLI_LAUNCHER_INPUTS = [
|
||||
"scripts/rea.mjs",
|
||||
"scripts/lib/cli-compiled-runtime.mjs",
|
||||
"scripts/lib/cli-process-environment.mjs",
|
||||
"scripts/lib/runtime-admission.mjs",
|
||||
"scripts/lib/runtime-admission.d.mts",
|
||||
];
|
||||
|
||||
// Ownership of the native-host, real-provider and website verification lanes.
|
||||
// Shared build inputs are classified once in plan.mjs rather than repeated in
|
||||
// every workflow.
|
||||
@@ -270,10 +278,7 @@ const PATH_SCOPES = {
|
||||
"scripts/lib/release-pull-request.mjs",
|
||||
"patches/release-please+17.11.2.patch",
|
||||
"tests/boundary/filesystem/releaseProposal.test.ts",
|
||||
"scripts/rea.mjs",
|
||||
"scripts/lib/cli-process-environment.mjs",
|
||||
"scripts/lib/runtime-admission.mjs",
|
||||
"scripts/lib/runtime-admission.d.mts",
|
||||
...CLI_LAUNCHER_INPUTS,
|
||||
"install.sh",
|
||||
"src/config/**",
|
||||
"src/hopperPaths/**",
|
||||
@@ -546,10 +551,7 @@ const PATH_SCOPES = {
|
||||
"src/contracts/cliCommandNames.ts",
|
||||
"src/contracts/toolContracts.ts",
|
||||
"src/contracts/toolEffects.ts",
|
||||
"scripts/rea.mjs",
|
||||
"scripts/lib/cli-process-environment.mjs",
|
||||
"scripts/lib/runtime-admission.mjs",
|
||||
"scripts/lib/runtime-admission.d.mts",
|
||||
...CLI_LAUNCHER_INPUTS,
|
||||
"src/process/**",
|
||||
"src/resources/SafeOutputTree.ts",
|
||||
"scripts/verify/javascript/recovery.mjs",
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { access } from "node:fs/promises";
|
||||
import { resolve } from "node:path";
|
||||
|
||||
/**
|
||||
* @param {string} packageRoot
|
||||
* @param {readonly string[]} paths
|
||||
*/
|
||||
export async function compiledRuntimeExists(packageRoot, paths) {
|
||||
for (const path of paths) {
|
||||
try {
|
||||
await access(resolve(packageRoot, path));
|
||||
} catch (cause) {
|
||||
if (
|
||||
typeof cause === "object" &&
|
||||
cause !== null &&
|
||||
"code" in cause &&
|
||||
cause.code === "ENOENT"
|
||||
)
|
||||
return false;
|
||||
throw cause;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** @param {string} packageRoot */
|
||||
export const missingCompiledRuntimeMessage = (packageRoot) =>
|
||||
`REA's compiled runtime is missing. Run \`npm ci && npm run build:cached\` in ${packageRoot} to install dependencies and build REA, then restart it. If this is an installed package, reinstall rea-agents.\n`;
|
||||
@@ -49,6 +49,7 @@ if (await pathExists(join(root, "src"))) {
|
||||
]);
|
||||
} else {
|
||||
for (const path of [
|
||||
"scripts/lib/cli-compiled-runtime.mjs",
|
||||
"scripts/lib/cli-process-environment.mjs",
|
||||
"scripts/lib/runtime-admission.mjs",
|
||||
"dist/main.js",
|
||||
|
||||
+9
-27
@@ -1,9 +1,12 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { access } from "node:fs/promises";
|
||||
import { dirname, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import {
|
||||
compiledRuntimeExists,
|
||||
missingCompiledRuntimeMessage,
|
||||
} from "./lib/cli-compiled-runtime.mjs";
|
||||
import { prepareCliProcessEnvironment } from "./lib/cli-process-environment.mjs";
|
||||
import { unsupportedRuntimeMessage } from "./lib/runtime-admission.mjs";
|
||||
|
||||
@@ -34,7 +37,9 @@ prepareCliProcessEnvironment(
|
||||
);
|
||||
const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const builtinArgumentRuntime = "dist/cli-runtime/cliBuiltinArguments.js";
|
||||
const builtinArguments = (await compiledRuntimeExists([builtinArgumentRuntime]))
|
||||
const builtinArguments = (await compiledRuntimeExists(packageRoot, [
|
||||
builtinArgumentRuntime,
|
||||
]))
|
||||
? await import("../dist/cli-runtime/cliBuiltinArguments.js")
|
||||
: undefined;
|
||||
const entry = builtinArguments?.classifyCliEntrypoint(args, process.env);
|
||||
@@ -57,10 +62,8 @@ const runtimeFiles = [
|
||||
]),
|
||||
];
|
||||
|
||||
if (!(await compiledRuntimeExists(runtimeFiles))) {
|
||||
process.stderr.write(
|
||||
`REA's compiled runtime is missing. Run \`npm ci && npm run build:cached\` in ${packageRoot} to install dependencies and build REA, then restart it. If this is an installed package, reinstall rea-agents.\n`,
|
||||
);
|
||||
if (!(await compiledRuntimeExists(packageRoot, runtimeFiles))) {
|
||||
process.stderr.write(missingCompiledRuntimeMessage(packageRoot));
|
||||
process.exitCode = 1;
|
||||
} else if (entry?.kind === "mcp-stdio") {
|
||||
const { runEntrypoint } = await import("../dist/mcp/main.js");
|
||||
@@ -226,24 +229,3 @@ function isClosedReaderFailure(cause) {
|
||||
function writeStdout(output) {
|
||||
if (!stdoutClosed) process.stdout.write(output);
|
||||
}
|
||||
|
||||
async function compiledRuntimeExists(paths) {
|
||||
for (const path of paths) {
|
||||
try {
|
||||
await access(resolve(packageRoot, path));
|
||||
} catch (cause) {
|
||||
if (isMissing(cause)) return false;
|
||||
throw cause;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function isMissing(cause) {
|
||||
return (
|
||||
typeof cause === "object" &&
|
||||
cause !== null &&
|
||||
"code" in cause &&
|
||||
cause.code === "ENOENT"
|
||||
);
|
||||
}
|
||||
@@ -212,6 +212,8 @@ export async function verifyPackagePack({ root, workspace, commands }) {
|
||||
packedManifest.bin?.["rea-agents"] !== "scripts/rea.mjs"
|
||||
)
|
||||
throw new Error("package did not expose both rea command entry points");
|
||||
if (!packedFiles.includes("package/scripts/lib/cli-compiled-runtime.mjs"))
|
||||
throw new Error("package omitted the compiled CLI runtime check");
|
||||
if (!packedFiles.includes("package/scripts/lib/cli-process-environment.mjs"))
|
||||
throw new Error("package omitted the CLI process environment owner");
|
||||
if (!packedFiles.includes("package/scripts/lib/runtime-admission.mjs"))
|
||||
|
||||
@@ -2090,36 +2090,6 @@ it.each([
|
||||
package: false,
|
||||
},
|
||||
],
|
||||
[
|
||||
"scripts/lib/cli-process-environment.mjs",
|
||||
{
|
||||
code: true,
|
||||
package: true,
|
||||
runtime: true,
|
||||
javascript_recovery: true,
|
||||
readiness: false,
|
||||
},
|
||||
],
|
||||
[
|
||||
"scripts/lib/runtime-admission.mjs",
|
||||
{
|
||||
code: true,
|
||||
package: true,
|
||||
runtime: true,
|
||||
javascript_recovery: true,
|
||||
readiness: false,
|
||||
},
|
||||
],
|
||||
[
|
||||
"scripts/lib/runtime-admission.d.mts",
|
||||
{
|
||||
code: true,
|
||||
package: true,
|
||||
runtime: true,
|
||||
javascript_recovery: true,
|
||||
readiness: false,
|
||||
},
|
||||
],
|
||||
[
|
||||
"tests/conformance/readiness/report/reconstructionReadiness.ts",
|
||||
{
|
||||
@@ -2152,6 +2122,21 @@ it.each([
|
||||
expect(await classifyPaths([path])).toMatchObject(expected);
|
||||
});
|
||||
|
||||
it.each([
|
||||
"scripts/lib/cli-compiled-runtime.mjs",
|
||||
"scripts/lib/cli-process-environment.mjs",
|
||||
"scripts/lib/runtime-admission.mjs",
|
||||
"scripts/lib/runtime-admission.d.mts",
|
||||
])("selects packaged CLI runtime checks for %s", async (path) => {
|
||||
expect(await classifyPaths([path])).toMatchObject({
|
||||
code: true,
|
||||
package: true,
|
||||
runtime: true,
|
||||
javascript_recovery: true,
|
||||
readiness: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("unions provider scopes across mixed changes and deletions", async () => {
|
||||
const { directory } = await fixture();
|
||||
const base = await change(directory, ["src/evm/client.ts"]);
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { Readable, Writable } from "node:stream";
|
||||
import { access } from "node:fs/promises";
|
||||
import { dirname, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import {
|
||||
compiledRuntimeExists,
|
||||
missingCompiledRuntimeMessage,
|
||||
} from "../../../scripts/lib/cli-compiled-runtime.mjs";
|
||||
import { prepareCliProcessEnvironment } from "../../../scripts/lib/cli-process-environment.mjs";
|
||||
import { withVerifierCleanup } from "../../../scripts/lib/verifier-cleanup.mjs";
|
||||
import {
|
||||
@@ -35,10 +38,8 @@ prepareCliProcessEnvironment(
|
||||
process.platform,
|
||||
packageJson.version,
|
||||
);
|
||||
if (!(await compiledRuntimeExists(runtimeFiles))) {
|
||||
process.stderr.write(
|
||||
`REA's compiled runtime is missing. Run \`npm ci && npm run build:cached\` in ${packageRoot} to install dependencies and build REA, then restart it. If this is an installed package, reinstall rea-agents.\n`,
|
||||
);
|
||||
if (!(await compiledRuntimeExists(packageRoot, runtimeFiles))) {
|
||||
process.stderr.write(missingCompiledRuntimeMessage(packageRoot));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
@@ -253,24 +254,3 @@ function captureWrite(chunks) {
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
async function compiledRuntimeExists(paths) {
|
||||
for (const path of paths) {
|
||||
try {
|
||||
await access(resolve(packageRoot, path));
|
||||
} catch (cause) {
|
||||
if (isMissing(cause)) return false;
|
||||
throw cause;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function isMissing(cause) {
|
||||
return (
|
||||
typeof cause === "object" &&
|
||||
cause !== null &&
|
||||
"code" in cause &&
|
||||
cause.code === "ENOENT"
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user