feat: streamline agent integration and MCP routing
This commit is contained in:
@@ -0,0 +1,406 @@
|
||||
import { spawn } from "node:child_process";
|
||||
import { cp, mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { dirname, join, resolve } from "node:path";
|
||||
import { createInterface } from "node:readline";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import { createPackage } from "@electron/asar";
|
||||
|
||||
import { evaluateCodexEvents } from "../dist/evaluation/CodexAgentEval.js";
|
||||
|
||||
const repositoryRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const evaluationRoot = await mkdtemp(join(tmpdir(), "rea-agent-eval-"));
|
||||
const fixtureRoot = join(evaluationRoot, "targets");
|
||||
const skillDestination = join(
|
||||
evaluationRoot,
|
||||
".agents/skills/reverse-engineer-anything",
|
||||
);
|
||||
const timeoutMs = Number(process.env.REA_AGENT_EVAL_TIMEOUT_MS ?? 480_000);
|
||||
const codex = process.env.REA_CODEX_CLI ?? "codex";
|
||||
const optionalModel = process.env.REA_AGENT_EVAL_MODEL;
|
||||
|
||||
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 10_000)
|
||||
throw new Error("REA_AGENT_EVAL_TIMEOUT_MS must be an integer >= 10000");
|
||||
const codexVersion = await readCommandVersion(codex);
|
||||
|
||||
try {
|
||||
await mkdir(fixtureRoot, { recursive: true });
|
||||
await cp(
|
||||
join(repositoryRoot, "skills/reverse-engineer-anything"),
|
||||
skillDestination,
|
||||
{ recursive: true },
|
||||
);
|
||||
const targets = await createTargets(fixtureRoot);
|
||||
const allScenarios = [
|
||||
{
|
||||
id: "native",
|
||||
expectedFirstTool: "open_binary",
|
||||
requiresEvidence: false,
|
||||
requiredAnswerTermGroups: [["unavailable", "could not", "provider"]],
|
||||
prompt: `Explain what the shipped native program at ${targets.native} does. Base the answer on artifact analysis, and clearly state any facts that remain unavailable.`,
|
||||
},
|
||||
{
|
||||
id: "asar",
|
||||
expectedFirstTool: "analyze_javascript_application",
|
||||
requiresEvidence: true,
|
||||
requiredAnswerTermGroups: [
|
||||
["profileapi"],
|
||||
["profile:read"],
|
||||
["preload", "contextbridge"],
|
||||
],
|
||||
prompt: `Explain how the desktop application at ${targets.javascript} exposes APIs to its renderer. Base the answer on the shipped application artifact, and state what remains unknown.`,
|
||||
},
|
||||
{
|
||||
id: "managed",
|
||||
expectedFirstTool: "inspect_managed_artifact",
|
||||
requiresEvidence: true,
|
||||
requiredAnswerTermGroups: [["profile"], ["main", "entry point"]],
|
||||
prompt: `Explain the public managed types and entry point in ${targets.managed}. Use shipped-artifact evidence and distinguish unavailable behavior from observed metadata.`,
|
||||
},
|
||||
{
|
||||
id: "browser",
|
||||
expectedFirstTool: "list_browser_targets",
|
||||
requiresEvidence: false,
|
||||
requiredAnswerTermGroups: [
|
||||
["unavailable", "could not", "connection", "endpoint"],
|
||||
],
|
||||
prompt:
|
||||
"A user-owned page is already open at http://127.0.0.1:3000 through the approved local debugging endpoint http://127.0.0.1:9222. Inspect what is available without navigating or executing page code, and report any authority or availability limits.",
|
||||
},
|
||||
];
|
||||
const requestedScenarioIds = new Set(
|
||||
(process.env.REA_AGENT_EVAL_SCENARIOS ?? "")
|
||||
.split(",")
|
||||
.map((value) => value.trim())
|
||||
.filter((value) => value.length > 0),
|
||||
);
|
||||
const scenarios =
|
||||
requestedScenarioIds.size === 0
|
||||
? allScenarios
|
||||
: allScenarios.filter(({ id }) => requestedScenarioIds.has(id));
|
||||
if (
|
||||
requestedScenarioIds.size > 0 &&
|
||||
scenarios.length !== requestedScenarioIds.size
|
||||
)
|
||||
throw new Error(
|
||||
`Unknown or duplicate REA_AGENT_EVAL_SCENARIOS value: ${[...requestedScenarioIds].join(",")}`,
|
||||
);
|
||||
const results = [];
|
||||
for (const scenario of scenarios) {
|
||||
process.stderr.write(`Running Codex agent evaluation: ${scenario.id}\n`);
|
||||
const execution = await runCodex(scenario.prompt, fixtureRoot);
|
||||
const transcriptDirectory = process.env.REA_AGENT_EVAL_TRANSCRIPT_DIR;
|
||||
if (transcriptDirectory !== undefined) {
|
||||
const transcriptPath = resolve(
|
||||
transcriptDirectory,
|
||||
`${scenario.id}.jsonl`,
|
||||
);
|
||||
await mkdir(dirname(transcriptPath), { recursive: true });
|
||||
await writeFile(
|
||||
transcriptPath,
|
||||
`${execution.events.map((event) => JSON.stringify(event)).join("\n")}\n`,
|
||||
);
|
||||
}
|
||||
const metrics = evaluateCodexEvents(
|
||||
execution.events,
|
||||
scenario.expectedFirstTool,
|
||||
{
|
||||
requireEvidence: scenario.requiresEvidence,
|
||||
requiredAnswerTermGroups: scenario.requiredAnswerTermGroups,
|
||||
},
|
||||
);
|
||||
const result = {
|
||||
id: scenario.id,
|
||||
expectedFirstTool: scenario.expectedFirstTool,
|
||||
requiresEvidence: scenario.requiresEvidence,
|
||||
qualityCriteria: scenario.requiredAnswerTermGroups,
|
||||
exitCode: execution.exitCode,
|
||||
stderr: execution.stderr,
|
||||
...metrics,
|
||||
};
|
||||
results.push(result);
|
||||
process.stderr.write(
|
||||
`${scenario.id}: first=${metrics.firstTool ?? "none"}, calls=${String(metrics.reaCalls.length)}, repeats=${String(metrics.repeatedCallCount)}, input_tokens=${String(metrics.inputTokens)}\n`,
|
||||
);
|
||||
}
|
||||
|
||||
const summary = {
|
||||
schemaVersion: 1,
|
||||
codex,
|
||||
codexVersion,
|
||||
model: optionalModel ?? null,
|
||||
scenarios: results.map(({ finalMessage: _message, ...result }) => result),
|
||||
totals: {
|
||||
scenarios: results.length,
|
||||
naturalUse: results.filter(({ naturalUse }) => naturalUse).length,
|
||||
correctFirstTool: results.filter(
|
||||
({ correctFirstTool }) => correctFirstTool,
|
||||
).length,
|
||||
repeatedCallCount: results.reduce(
|
||||
(total, { repeatedCallCount }) => total + repeatedCallCount,
|
||||
0,
|
||||
),
|
||||
inputTokens: results.reduce(
|
||||
(total, { inputTokens }) => total + inputTokens,
|
||||
0,
|
||||
),
|
||||
cachedInputTokens: results.reduce(
|
||||
(total, { cachedInputTokens }) => total + cachedInputTokens,
|
||||
0,
|
||||
),
|
||||
completionQuality: results.filter(({ completionQuality }) =>
|
||||
Boolean(completionQuality),
|
||||
).length,
|
||||
authorityHonesty: results.filter(({ authorityHonesty }) =>
|
||||
Boolean(authorityHonesty),
|
||||
).length,
|
||||
},
|
||||
};
|
||||
const encoded = `${JSON.stringify(summary, null, 2)}\n`;
|
||||
process.stdout.write(encoded);
|
||||
const reportPath = process.env.REA_AGENT_EVAL_REPORT_PATH;
|
||||
if (reportPath !== undefined) {
|
||||
await mkdir(dirname(resolve(reportPath)), { recursive: true });
|
||||
await writeFile(resolve(reportPath), encoded);
|
||||
}
|
||||
|
||||
const failed = results.filter(
|
||||
({
|
||||
exitCode,
|
||||
naturalUse,
|
||||
correctFirstTool,
|
||||
repeatedCallCount,
|
||||
inputTokens,
|
||||
completionQuality,
|
||||
authorityHonesty,
|
||||
}) =>
|
||||
exitCode !== 0 ||
|
||||
!naturalUse ||
|
||||
!correctFirstTool ||
|
||||
repeatedCallCount !== 0 ||
|
||||
inputTokens <= 0 ||
|
||||
!completionQuality ||
|
||||
!authorityHonesty,
|
||||
);
|
||||
if (failed.length > 0)
|
||||
throw new Error(
|
||||
`Codex agent release evaluation failed: ${failed.map(({ id }) => id).join(", ")}`,
|
||||
);
|
||||
} finally {
|
||||
if (process.env.REA_AGENT_EVAL_KEEP_FIXTURES !== "true")
|
||||
await rm(evaluationRoot, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
async function createTargets(root) {
|
||||
const javascript = join(root, "desktop-app");
|
||||
await mkdir(join(javascript, "renderer"), { recursive: true });
|
||||
await Promise.all([
|
||||
writeFile(
|
||||
join(javascript, "package.json"),
|
||||
`${JSON.stringify({ name: "desktop-fixture", version: "1.0.0", main: "main.js" }, null, 2)}\n`,
|
||||
),
|
||||
writeFile(
|
||||
join(javascript, "main.js"),
|
||||
'const { BrowserWindow, ipcMain } = require("electron");\nnew BrowserWindow({ webPreferences: { preload: require("node:path").join(__dirname, "preload.js"), contextIsolation: true, sandbox: true } });\nipcMain.handle("profile:read", (_event, id) => ({ id }));\n',
|
||||
),
|
||||
writeFile(
|
||||
join(javascript, "preload.js"),
|
||||
'const { contextBridge, ipcRenderer } = require("electron");\ncontextBridge.exposeInMainWorld("profileApi", { read: (id) => ipcRenderer.invoke("profile:read", id) });\n',
|
||||
),
|
||||
writeFile(
|
||||
join(javascript, "renderer/app.js"),
|
||||
'globalThis.profileApi.read("fixture");\n',
|
||||
),
|
||||
]);
|
||||
const javascriptAsar = join(root, "desktop-app.asar");
|
||||
await createPackage(javascript, javascriptAsar);
|
||||
|
||||
const managedProject = join(root, "managed-project");
|
||||
const managedOutput = join(root, "managed-output");
|
||||
await mkdir(managedProject, { recursive: true });
|
||||
await Promise.all([
|
||||
writeFile(
|
||||
join(managedProject, "AgentEval.csproj"),
|
||||
'<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><OutputType>Exe</OutputType><TargetFramework>net8.0</TargetFramework><ImplicitUsings>enable</ImplicitUsings><Nullable>enable</Nullable></PropertyGroup></Project>\n',
|
||||
),
|
||||
writeFile(
|
||||
join(managedProject, "Program.cs"),
|
||||
'namespace AgentEval; public sealed record Profile(string Id); public static class Program { public static void Main() => Console.WriteLine(new Profile("fixture")); }\n',
|
||||
),
|
||||
]);
|
||||
await runProcess(
|
||||
"dotnet",
|
||||
[
|
||||
"build",
|
||||
join(managedProject, "AgentEval.csproj"),
|
||||
"--configuration",
|
||||
"Release",
|
||||
"--output",
|
||||
managedOutput,
|
||||
"--nologo",
|
||||
],
|
||||
root,
|
||||
120_000,
|
||||
);
|
||||
return {
|
||||
native: "/bin/true",
|
||||
javascript: javascriptAsar,
|
||||
managed: join(managedOutput, "AgentEval.dll"),
|
||||
};
|
||||
}
|
||||
|
||||
async function runCodex(prompt, investigationRoot) {
|
||||
const mcpEnvironment = [
|
||||
["REA_INVESTIGATION_INPUT_ROOTS_JSON", JSON.stringify([investigationRoot])],
|
||||
["REA_BROWSER_OBSERVE_ENABLED", "true"],
|
||||
[
|
||||
"REA_BROWSER_CDP_ENDPOINTS_JSON",
|
||||
JSON.stringify(["http://127.0.0.1:9222"]),
|
||||
],
|
||||
[
|
||||
"REA_BROWSER_ALLOWED_ORIGINS_JSON",
|
||||
JSON.stringify(["http://127.0.0.1:3000"]),
|
||||
],
|
||||
];
|
||||
const mcpEnvironmentOverride = `mcp_servers.rea.env={${mcpEnvironment
|
||||
.map(([name, value]) => `${name}=${JSON.stringify(value)}`)
|
||||
.join(",")}}`;
|
||||
const arguments_ = [
|
||||
"exec",
|
||||
"--ignore-user-config",
|
||||
"--ignore-rules",
|
||||
"--ephemeral",
|
||||
"--skip-git-repo-check",
|
||||
"--sandbox",
|
||||
"read-only",
|
||||
"--json",
|
||||
"--color",
|
||||
"never",
|
||||
"-C",
|
||||
evaluationRoot,
|
||||
"-c",
|
||||
'approval_policy="never"',
|
||||
"-c",
|
||||
`mcp_servers.rea.command=${JSON.stringify(process.execPath)}`,
|
||||
"-c",
|
||||
`mcp_servers.rea.args=${JSON.stringify([join(repositoryRoot, "scripts/rea.mjs"), "mcp"])}`,
|
||||
"-c",
|
||||
"mcp_servers.rea.startup_timeout_sec=30",
|
||||
"-c",
|
||||
mcpEnvironmentOverride,
|
||||
...(optionalModel === undefined ? [] : ["--model", optionalModel]),
|
||||
prompt,
|
||||
];
|
||||
const child = spawn(codex, arguments_, {
|
||||
cwd: evaluationRoot,
|
||||
env: {
|
||||
...process.env,
|
||||
REA_INVESTIGATION_INPUT_ROOTS_JSON: JSON.stringify([investigationRoot]),
|
||||
REA_BROWSER_OBSERVE_ENABLED: "true",
|
||||
REA_BROWSER_CDP_ENDPOINTS_JSON: JSON.stringify(["http://127.0.0.1:9222"]),
|
||||
REA_BROWSER_ALLOWED_ORIGINS_JSON: JSON.stringify([
|
||||
"http://127.0.0.1:3000",
|
||||
]),
|
||||
},
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
});
|
||||
const events = [];
|
||||
const stderr = [];
|
||||
const lines = createInterface({ input: child.stdout });
|
||||
const linesClosed = new Promise((resolveClose) =>
|
||||
lines.once("close", resolveClose),
|
||||
);
|
||||
lines.on("line", (line) => {
|
||||
try {
|
||||
events.push(JSON.parse(line));
|
||||
} catch {
|
||||
stderr.push(`non-json stdout: ${line}`);
|
||||
}
|
||||
});
|
||||
child.stderr.on("data", (chunk) => {
|
||||
if (stderr.join("").length < 32_768) stderr.push(chunk.toString("utf8"));
|
||||
});
|
||||
const exitCode = await new Promise((resolveExit, reject) => {
|
||||
const timeout = setTimeout(() => {
|
||||
child.kill("SIGTERM");
|
||||
reject(
|
||||
new Error(`Codex evaluation timed out after ${String(timeoutMs)}ms`),
|
||||
);
|
||||
}, timeoutMs);
|
||||
child.once("error", (cause) => {
|
||||
clearTimeout(timeout);
|
||||
reject(cause);
|
||||
});
|
||||
child.once("exit", (code) => {
|
||||
clearTimeout(timeout);
|
||||
resolveExit(code ?? 1);
|
||||
});
|
||||
});
|
||||
await linesClosed;
|
||||
return { events, exitCode, stderr: stderr.join("").slice(0, 32_768) };
|
||||
}
|
||||
|
||||
async function runProcess(command, arguments_, cwd, timeout) {
|
||||
const child = spawn(command, arguments_, {
|
||||
cwd,
|
||||
stdio: ["ignore", "ignore", "pipe"],
|
||||
});
|
||||
let stderr = "";
|
||||
child.stderr.on("data", (chunk) => {
|
||||
if (stderr.length < 32_768) stderr += chunk.toString("utf8");
|
||||
});
|
||||
const code = await new Promise((resolveExit, reject) => {
|
||||
const timer = setTimeout(() => {
|
||||
child.kill("SIGTERM");
|
||||
reject(new Error(`${command} timed out`));
|
||||
}, timeout);
|
||||
child.once("error", (cause) => {
|
||||
clearTimeout(timer);
|
||||
reject(cause);
|
||||
});
|
||||
child.once("exit", (value) => {
|
||||
clearTimeout(timer);
|
||||
resolveExit(value ?? 1);
|
||||
});
|
||||
});
|
||||
if (code !== 0)
|
||||
throw new Error(`${command} failed with ${String(code)}: ${stderr}`);
|
||||
}
|
||||
|
||||
async function readCommandVersion(command) {
|
||||
const child = spawn(command, ["--version"], {
|
||||
cwd: repositoryRoot,
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
});
|
||||
let stdout = "";
|
||||
let stderr = "";
|
||||
child.stdout.on("data", (chunk) => {
|
||||
if (stdout.length < 4096) stdout += chunk.toString("utf8");
|
||||
});
|
||||
child.stderr.on("data", (chunk) => {
|
||||
if (stderr.length < 4096) stderr += chunk.toString("utf8");
|
||||
});
|
||||
const code = await new Promise((resolveExit, reject) => {
|
||||
const timer = setTimeout(() => {
|
||||
child.kill("SIGTERM");
|
||||
reject(new Error(`${command} --version timed out`));
|
||||
}, 10_000);
|
||||
child.once("error", (cause) => {
|
||||
clearTimeout(timer);
|
||||
reject(cause);
|
||||
});
|
||||
child.once("exit", (value) => {
|
||||
clearTimeout(timer);
|
||||
resolveExit(value ?? 1);
|
||||
});
|
||||
});
|
||||
if (code !== 0)
|
||||
throw new Error(
|
||||
`${command} --version failed with ${String(code)}: ${stderr}`,
|
||||
);
|
||||
const version = stdout.trim();
|
||||
if (version.length === 0)
|
||||
throw new Error(`${command} --version returned empty output`);
|
||||
return version;
|
||||
}
|
||||
@@ -80,7 +80,7 @@ const verifyMcpOpenAndBind = async (client, mcpOptions) => {
|
||||
const providerStatusEnvelope = json(
|
||||
prompts.mcpText(
|
||||
await client.callTool(
|
||||
{ name: "binary_session", arguments: {} },
|
||||
{ name: "binary_session", arguments: { detail: "full" } },
|
||||
mcpOptions,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -11,6 +11,7 @@ import { join } from "node:path";
|
||||
import { spawn } from "@lydell/node-pty";
|
||||
|
||||
import { TOOL_CONTRACTS } from "../dist/contracts/toolContracts.js";
|
||||
import { PRODUCT_IDENTITY } from "../dist/identity.js";
|
||||
import {
|
||||
json,
|
||||
pathExists,
|
||||
@@ -21,10 +22,9 @@ import {
|
||||
const verifyMcpAdd = async ({ cli, environment, npxLog }) => {
|
||||
await run(cli, ["mcp", "add"], environment);
|
||||
const mcpRegistration = await readFile(npxLog, "utf8");
|
||||
if (
|
||||
!mcpRegistration.includes("add-mcp npx -y rea-agents@latest mcp --name rea")
|
||||
)
|
||||
throw new Error("Incur mcp add did not register the latest npx command");
|
||||
const expected = `add-mcp npx -y ${PRODUCT_IDENTITY.registrationPackageSpecifier} mcp --name rea`;
|
||||
if (!mcpRegistration.includes(expected))
|
||||
throw new Error("Incur mcp add did not register the pinned npx command");
|
||||
};
|
||||
|
||||
const verifyInteractiveSetup = async ({ command, environment, root }) =>
|
||||
@@ -182,6 +182,7 @@ const assertCodexSymlink = async ({
|
||||
!(await lstat(cursorConfig)).isSymbolicLink() ||
|
||||
!codex.includes("[mcp_servers.rea]") ||
|
||||
!codex.includes(`command = "${cli}"`) ||
|
||||
!codex.includes("startup_timeout_sec = 30") ||
|
||||
(await readFile(`${codexConfig}.rea.backup`, "utf8")) !==
|
||||
'model = "gpt-5"\n' ||
|
||||
(await readFile(`${cursorConfig}.rea.backup`, "utf8")) !==
|
||||
@@ -198,6 +199,19 @@ const assertSkill = async ({ skillPath, siblingSkillPath, root }) => {
|
||||
);
|
||||
if (skill !== canonicalSkill)
|
||||
throw new Error("packaged skill did not match its canonical source");
|
||||
const installedReference = await readFile(
|
||||
join(skillPath, "..", "references/javascript-applications.md"),
|
||||
"utf8",
|
||||
);
|
||||
const canonicalReference = await readFile(
|
||||
join(
|
||||
root,
|
||||
"skills/reverse-engineer-anything/references/javascript-applications.md",
|
||||
),
|
||||
"utf8",
|
||||
);
|
||||
if (installedReference !== canonicalReference)
|
||||
throw new Error("packaged skill references did not match canonical source");
|
||||
if ((await readFile(siblingSkillPath, "utf8")) !== "unrelated skill\n")
|
||||
throw new Error("packaged skill installation modified a sibling skill");
|
||||
};
|
||||
|
||||
@@ -3,6 +3,7 @@ import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { TOOL_CONTRACTS } from "../dist/contracts/toolContracts.js";
|
||||
import { PRODUCT_IDENTITY } from "../dist/identity.js";
|
||||
import * as prompts from "./verify-package-prompts.mjs";
|
||||
import { verifyPackagedInvestigation } from "./verify-package-investigation.mjs";
|
||||
import { verifyPackageArtifactAndElectron } from "./verify-package-artifact.mjs";
|
||||
@@ -99,7 +100,7 @@ try {
|
||||
investigationReplay,
|
||||
});
|
||||
process.stdout.write(
|
||||
`${JSON.stringify({ cli: true, analysisCli: true, artifactCli: true, managedCli: true, managedReconstructionCli: true, managedNativeVerificationCli: true, managedRuntimePlanCli: true, managedApplicationGraphCli: true, evidenceCli: true, incurMcpCommand: "npx -y rea-agents@latest mcp", lifecycleScriptsRequired: false, doctor: "platform-appropriate", setup: supportedSetupHost ? "planned-then-idempotent" : "unsupported-host-rejected", setupPlanReadOnly: supportedSetupHost, existingHopperPreserved: supportedSetupHost, clients: supportedSetupHost ? 3 : 0, backupReadback: supportedSetupHost, failureRecovery: supportedSetupHost, configSymlinkLifecycle: supportedSetupHost, skill: supportedSetupHost, mcpTools: TOOL_CONTRACTS.length, mcpPrompts: prompts.names.length, promptCompletion: true, promptCompletionLifecycle: true, evidenceMcp: true, targetFree: true, targetLifecycle: true, boundedRegexBridge: true })}\n`,
|
||||
`${JSON.stringify({ cli: true, analysisCli: true, artifactCli: true, managedCli: true, managedReconstructionCli: true, managedNativeVerificationCli: true, managedRuntimePlanCli: true, managedApplicationGraphCli: true, evidenceCli: true, incurMcpCommand: PRODUCT_IDENTITY.mcpCommand, lifecycleScriptsRequired: false, doctor: "platform-appropriate", setup: supportedSetupHost ? "planned-then-idempotent" : "unsupported-host-rejected", setupPlanReadOnly: supportedSetupHost, existingHopperPreserved: supportedSetupHost, clients: supportedSetupHost ? 3 : 0, backupReadback: supportedSetupHost, failureRecovery: supportedSetupHost, configSymlinkLifecycle: supportedSetupHost, skill: supportedSetupHost, skillReferences: supportedSetupHost, mcpTools: TOOL_CONTRACTS.length, mcpPrompts: prompts.names.length, promptCompletion: true, promptCompletionLifecycle: true, evidenceMcp: true, targetFree: true, targetLifecycle: true, boundedRegexBridge: true })}\n`,
|
||||
);
|
||||
} finally {
|
||||
if (tarball) await rm(join(root, tarball), { force: true });
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { CATALOG_IDENTITY } from "../dist/catalogIdentity.js";
|
||||
|
||||
@@ -9,6 +12,7 @@ if (!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/u.test(version ?? ""))
|
||||
|
||||
const serverEnvironment = { ...process.env };
|
||||
delete serverEnvironment.HOPPER_TARGET_PATH;
|
||||
const canaryRoot = await mkdtemp(join(tmpdir(), "rea-published-canary-"));
|
||||
const transport = new StdioClientTransport({
|
||||
command: "npm",
|
||||
args: [
|
||||
@@ -19,6 +23,7 @@ const transport = new StdioClientTransport({
|
||||
"rea",
|
||||
"mcp",
|
||||
],
|
||||
cwd: canaryRoot,
|
||||
env: serverEnvironment,
|
||||
stderr: "pipe",
|
||||
});
|
||||
@@ -61,8 +66,12 @@ try {
|
||||
} catch (cause) {
|
||||
throw new Error(`Published MCP canary failed: ${stderr}`, { cause });
|
||||
} finally {
|
||||
await client.close();
|
||||
await transport.close();
|
||||
try {
|
||||
await client.close();
|
||||
await transport.close();
|
||||
} finally {
|
||||
await rm(canaryRoot, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
process.stdout.write(
|
||||
|
||||
Reference in New Issue
Block a user