Merge branch 'origin/main' into codex/issue-386

This commit is contained in:
morluto
2026-07-22 16:18:40 +00:00
2202 changed files with 499 additions and 112467 deletions
-103
View File
@@ -1,103 +0,0 @@
import { createHash } from "node:crypto";
import { mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
import { join } from "node:path";
const CACHE_DIRECTORY = ["node_modules", ".cache"];
const BUILD_INFO_NAME = "rea-tsconfig-build.tsbuildinfo";
const MANIFEST_NAME = "rea-tsconfig-build-outputs.json";
const isMissing = (cause) =>
typeof cause === "object" &&
cause !== null &&
"code" in cause &&
cause.code === "ENOENT";
const outputFiles = async (root) => {
const sourceRoot = join(root, "src");
const entries = await readdir(sourceRoot, { recursive: true });
return entries
.filter((entry) => entry.endsWith(".ts") && !entry.endsWith(".d.ts"))
.sort()
.map((entry) => {
const output = `${entry.slice(0, -3)}.js`;
return { output, path: join(root, "dist", output) };
});
};
const digest = async (path) =>
createHash("sha256")
.update(await readFile(path))
.digest("hex");
const cachePath = (root, name) => join(root, ...CACHE_DIRECTORY, name);
const invalidate = async (root) => {
await Promise.all([
rm(cachePath(root, BUILD_INFO_NAME), { force: true }),
rm(cachePath(root, MANIFEST_NAME), { force: true }),
]);
};
const readManifest = async (root) => {
try {
const parsed = JSON.parse(
await readFile(cachePath(root, MANIFEST_NAME), "utf8"),
);
if (
typeof parsed !== "object" ||
parsed === null ||
parsed.version !== 1 ||
typeof parsed.outputs !== "object" ||
parsed.outputs === null ||
Array.isArray(parsed.outputs)
)
return undefined;
return parsed.outputs;
} catch (cause) {
if (isMissing(cause) || cause instanceof SyntaxError) return undefined;
throw cause;
}
};
/** Invalidates incremental state when generated JavaScript was removed or changed. */
export const validateBuildCache = async (root) => {
const [files, manifest] = await Promise.all([
outputFiles(root),
readManifest(root),
]);
if (manifest === undefined || Object.keys(manifest).length !== files.length) {
await invalidate(root);
return;
}
const matches = await Promise.all(
files.map(async ({ output, path }) => {
if (typeof manifest[output] !== "string") return false;
try {
return (await digest(path)) === manifest[output];
} catch (cause) {
if (isMissing(cause)) return false;
throw cause;
}
}),
);
if (!matches.every(Boolean)) await invalidate(root);
};
/** Records generated JavaScript so a later incremental build can verify its cache. */
export const recordBuildCache = async (root) => {
const files = await outputFiles(root);
const entries = await Promise.all(
files.map(async ({ output, path }) => [output, await digest(path)]),
);
const source = `${JSON.stringify({ version: 1, outputs: Object.fromEntries(entries) })}\n`;
const directory = join(root, ...CACHE_DIRECTORY);
await mkdir(directory, { recursive: true });
const path = cachePath(root, MANIFEST_NAME);
let existing;
try {
existing = await readFile(path, "utf8");
} catch (cause) {
if (!isMissing(cause)) throw cause;
}
if (existing !== source) await writeFile(path, source, "utf8");
};
-67
View File
@@ -1,67 +0,0 @@
import { execFile } from "node:child_process";
import { createHash } from "node:crypto";
import { mkdtemp, readFile, readdir, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { dirname, join, relative } from "node:path";
import { promisify } from "node:util";
import { fileURLToPath } from "node:url";
const execFileAsync = promisify(execFile);
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
const temporaryRoot = await mkdtemp(join(tmpdir(), "rea-typedoc-check-"));
const generated = join(temporaryRoot, "api");
const files = async (directory) =>
(await readdir(directory, { recursive: true, withFileTypes: true }))
.filter((entry) => entry.isFile())
.map((entry) => relative(directory, join(entry.parentPath, entry.name)))
.sort();
const digest = async (path) =>
createHash("sha256")
.update(await readFile(path))
.digest("hex");
try {
const { stderr } = await execFileAsync(
process.execPath,
[join(root, "node_modules/typedoc/bin/typedoc"), "--out", generated],
{ cwd: root, maxBuffer: 4 * 1024 * 1024 },
);
if (stderr.trim().length > 0) process.stderr.write(stderr);
const committed = join(root, "docs/api");
const [expectedFiles, actualFiles] = await Promise.all([
files(generated),
files(committed),
]);
const expectedSet = new Set(expectedFiles);
const actualSet = new Set(actualFiles);
const missing = expectedFiles.filter((path) => !actualSet.has(path));
const extra = actualFiles.filter((path) => !expectedSet.has(path));
const common = expectedFiles.filter((path) => actualSet.has(path));
const changed = (
await Promise.all(
common.map(async (path) =>
(await digest(join(generated, path))) ===
(await digest(join(committed, path)))
? undefined
: path,
),
)
).filter((path) => path !== undefined);
if (missing.length > 0 || extra.length > 0 || changed.length > 0) {
const summarize = (label, paths) =>
paths.length === 0
? []
: [`${label}:`, ...paths.slice(0, 20).map((path) => ` ${path}`)];
throw new Error(
[
"Committed TypeDoc output is stale. Run `npm run docs:generate`.",
...summarize("Missing", missing),
...summarize("Extra", extra),
...summarize("Changed", changed),
].join("\n"),
);
}
} finally {
await rm(temporaryRoot, { recursive: true, force: true });
}
+1 -3
View File
@@ -2,7 +2,6 @@ import { readFile } from "node:fs/promises";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import { validateBuildCache } from "./build-cache.mjs";
import { ensureGeneratedFile } from "./lib/generated-file.mjs";
const arguments_ = new Set(process.argv.slice(2));
@@ -45,6 +44,5 @@ await ensureGeneratedFile({
path: outputPath,
source,
check: arguments_.has("--check"),
generateCommand: "npm run build",
generateCommand: "npm run metadata:generate",
});
await validateBuildCache(root);
+55
View File
@@ -0,0 +1,55 @@
import { spawnSync } from "node:child_process";
import { access } from "node:fs/promises";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
const pathExists = async (path) => {
try {
await access(path);
return true;
} catch (cause) {
if (
typeof cause === "object" &&
cause !== null &&
"code" in cause &&
cause.code === "ENOENT"
)
return false;
throw cause;
}
};
const run = (command, args) => {
const result = spawnSync(command, args, {
cwd: root,
encoding: "utf8",
maxBuffer: 4 * 1_024 * 1_024,
});
if (result.error !== undefined) throw result.error;
if (result.status !== 0) {
if (result.stdout.length > 0) process.stdout.write(result.stdout);
if (result.stderr.length > 0) process.stderr.write(result.stderr);
throw new Error(
`Prepack command failed with status ${String(result.status)}: ${command} ${args.join(" ")}`,
);
}
};
if (await pathExists(join(root, "src"))) {
const packageManagerPath = process.env.npm_execpath;
if (packageManagerPath === undefined)
throw new Error("Prepack could not resolve the active package manager");
run(process.execPath, [packageManagerPath, "run", "build:cached"]);
run(process.execPath, ["scripts/generate-skill-metadata.mjs", "--check"]);
} else {
for (const path of [
"dist/main.js",
"dist/mcpDoctor.js",
"dist/cli.js",
"dist/cliOutput.js",
"skills/reverse-engineer-anything/SKILL.md",
])
await access(join(root, path));
}
+28
View File
@@ -0,0 +1,28 @@
import { access } from "node:fs/promises";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
const sourceHuskyIsAvailable = async () => {
try {
await access(join(root, "src"));
await access(join(root, "node_modules", "husky", "index.js"));
return true;
} catch (cause) {
if (
typeof cause === "object" &&
cause !== null &&
"code" in cause &&
cause.code === "ENOENT"
)
return false;
throw cause;
}
};
if (process.env.HUSKY !== "0" && (await sourceHuskyIsAvailable())) {
const { default: installHusky } = await import("husky");
const message = installHusky();
if (message.length > 0) process.stdout.write(`${message}\n`);
}
-7
View File
@@ -1,7 +0,0 @@
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import { recordBuildCache } from "./build-cache.mjs";
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
await recordBuildCache(root);
+12
View File
@@ -100,5 +100,17 @@ export async function verifyPackageInstall({
throw new Error(
`packaged CLI did not degrade without the optional PTY binary: ${JSON.stringify(noOptionalCapability)}`,
);
await verifyInstalledPackageCanRepack(prefix, environment);
return { cli, packageRunnerCli };
}
const verifyInstalledPackageCanRepack = async (prefix, environment) => {
const installedPackageRoot = join(prefix, "lib/node_modules/rea-agents");
const repackedTarball = (
await exec("npm", ["pack", "--silent"], {
cwd: installedPackageRoot,
env: environment,
})
).stdout.trim();
await rm(join(installedPackageRoot, repackedTarball), { force: true });
};