Merge remote-tracking branch 'origin/main' into feat/mcp-prompts-completion

# Conflicts:
#	scripts/verify-package.mjs
This commit is contained in:
morluto
2026-07-14 04:55:38 +08:00
197 changed files with 8459 additions and 1120 deletions
+6 -3
View File
@@ -11,9 +11,12 @@ const isMcpMode =
args[0] === "--mcp" || (args.length === 1 && args[0] === "mcp");
if (isMcpMode) {
const { run } = await import("../dist/main.js");
process.exitCode = await run();
const { runEntrypoint } = await import("../dist/main.js");
await runEntrypoint();
} else {
const { createCli } = await import("../dist/cli.js");
await createCli().serve(args);
const { sanitizeCliOutput } = await import("../dist/cliOutput.js");
await createCli().serve(args, {
stdout: (output) => process.stdout.write(sanitizeCliOutput(output)),
});
}
+45
View File
@@ -0,0 +1,45 @@
import { execFile } from "node:child_process";
import { readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { promisify } from "node:util";
import { TextReader, Uint8ArrayWriter, ZipWriter } from "@zip.js/zip.js";
const exec = promisify(execFile);
/** Verify the packed CLI's persistent investigation and idempotent reuse. */
export async function verifyPackagedInvestigation(input) {
const artifactArchiveV2 = join(input.workspace, "artifact-v2.zip");
const writer = new ZipWriter(new Uint8ArrayWriter());
await writer.add("app/main.js", new TextReader("main(2);"));
await writer.add("app/new.js", new TextReader("feature();"));
await writeFile(artifactArchiveV2, await writer.close());
const workspacePath = join(input.evidenceRoot, "versions.json");
const args = [
"investigate-versions",
input.artifactArchive,
artifactArchiveV2,
workspacePath,
"--workspace-name",
"package-versions",
"--yes",
"--json",
];
const investigated = await runJson(input.cli, args, input.environment);
const reused = await runJson(input.cli, args, input.environment);
const persisted = JSON.parse(await readFile(workspacePath, "utf8"));
if (
investigated.operation !== "find_changed_behavior" ||
investigated.normalized_result?.behavior_status !== "unknown" ||
investigated.normalized_result?.investigation_run?.run_id === undefined ||
reused.evidence_id !== investigated.evidence_id ||
persisted.revision !== 3 ||
persisted.runs?.[0]?.status !== "complete"
)
throw new Error("packaged persistent investigation CLI failed");
}
async function runJson(command, args, environment) {
const output = await exec(command, args, { env: environment });
return JSON.parse(output.stdout);
}
+6 -10
View File
@@ -1,3 +1,7 @@
import { PROMPT_CONTRACTS } from "../dist/contracts/promptContracts.js";
export const names = PROMPT_CONTRACTS.map(({ name }) => name);
/** Extract the text payload used by packaged MCP smoke assertions. */
export const mcpText = (result) => {
const value = result.content?.find((item) => item.type === "text")?.text;
@@ -6,11 +10,7 @@ export const mcpText = (result) => {
};
/** Verify packaged prompt discovery and rendering through the public client. */
export const verifyPackagedPromptCatalog = async (
client,
options,
expectedNames,
) => {
export const verifyPromptCatalog = async (client, options, expectedNames) => {
const prompts = await client.listPrompts(undefined, options);
if (
JSON.stringify(prompts.prompts.map(({ name }) => name)) !==
@@ -37,11 +37,7 @@ export const verifyPackagedPromptCatalog = async (
};
/** Verify live completion through each installed stdio target state. */
export const verifyPackagedPromptCompletion = async (
client,
options,
targetOpen,
) => {
export const verifyPromptCompletion = async (client, options, targetOpen) => {
const expected = targetOpen ? ["fixture"] : [];
const requests = [
{
+16 -19
View File
@@ -14,19 +14,11 @@ import { promisify } from "node:util";
import { Client } from "@modelcontextprotocol/client";
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
import { TextReader, Uint8ArrayWriter, ZipWriter } from "@zip.js/zip.js";
import { PROMPT_CONTRACTS } from "../dist/contracts/promptContracts.js";
import { TOOL_CONTRACTS } from "../dist/contracts/toolContracts.js";
import {
mcpText,
verifyPackagedPromptCatalog,
verifyPackagedPromptCompletion,
} from "./verify-package-prompts.mjs";
import * as prompts from "./verify-package-prompts.mjs";
import { verifyPackagedInvestigation } from "./verify-package-investigation.mjs";
import { verifyPackedBridge } from "./verify-packed-bridge.mjs";
const expectedToolCount = TOOL_CONTRACTS.length;
const expectedPromptNames = PROMPT_CONTRACTS.map(({ name }) => name);
// Exercise the packed artifact in isolated HOME and prefix directories so the
// verifier cannot mutate real MCP registrations or rely on checkout-only files.
const exec = promisify(execFile);
const root = process.cwd();
const workspace = await mkdtemp(join(tmpdir(), "rea-package-"));
@@ -48,6 +40,7 @@ try {
) {
throw new Error("package contained generated Python bytecode");
}
await verifyPackedBridge({ root, workspace, tarball, packedFiles });
const prefix = join(workspace, "prefix");
const home = join(workspace, "home");
const fakeBin = join(workspace, "bin");
@@ -109,6 +102,7 @@ try {
]),
REA_NPX_LOG: npxLog,
REA_EVIDENCE_ROOTS_JSON: JSON.stringify([evidenceRoot]),
REA_INVESTIGATION_INPUT_ROOTS_JSON: JSON.stringify([workspace]),
REA_REFERENCE_ROOTS_JSON: JSON.stringify([referenceRoot]),
REA_REFERENCE_SECRET_PATTERNS_JSON: JSON.stringify([".env"]),
};
@@ -129,6 +123,7 @@ try {
!help.includes("upgrade") ||
!help.includes("inventory-artifact") ||
!help.includes("extract-artifact") ||
!help.includes("investigate-versions") ||
!help.includes("import-reference-source") ||
!help.includes("compare") ||
!llms.includes("decompile") ||
@@ -163,6 +158,8 @@ try {
artifactInventory.normalized_result?.manifest?.root_format !== "zip"
)
throw new Error("packaged artifact inventory CLI failed");
// prettier-ignore
await verifyPackagedInvestigation({ cli, workspace, evidenceRoot, artifactArchive, environment });
const overview = json(
await run(cli, ["analyze", process.execPath, "--json"], environment),
);
@@ -426,11 +423,11 @@ try {
const mcpOptions = { timeout: 15_000 };
if (
(await client.listTools(undefined, mcpOptions)).tools.length !==
expectedToolCount
TOOL_CONTRACTS.length
)
throw new Error("packaged MCP tool inventory diverged from contracts");
await verifyPackagedPromptCatalog(client, mcpOptions, expectedPromptNames);
await verifyPackagedPromptCompletion(client, mcpOptions, false);
await prompts.verifyPromptCatalog(client, mcpOptions, prompts.names);
await prompts.verifyPromptCompletion(client, mcpOptions, false);
const result = await client.callTool(
{ name: "current_document", arguments: {} },
mcpOptions,
@@ -443,21 +440,21 @@ try {
);
if (opened.isError === true)
throw new Error("packaged MCP could not open a binary");
await verifyPackagedPromptCompletion(client, mcpOptions, true);
await prompts.verifyPromptCompletion(client, mcpOptions, true);
const current = await client.callTool(
{ name: "current_document", arguments: {} },
mcpOptions,
);
if (
current.isError === true ||
json(mcpText(current)).normalized_result !== "fixture"
json(prompts.mcpText(current)).normalized_result !== "fixture"
)
throw new Error("packaged MCP bridge call failed");
const batch = await client.callTool(
{ name: "batch_decompile", arguments: { addresses: ["0x1000"] } },
mcpOptions,
);
const batchResult = json(mcpText(batch)).normalized_result;
const batchResult = json(prompts.mcpText(batch)).normalized_result;
if (
batch.isError === true ||
batchResult?.total !== 1 ||
@@ -473,7 +470,7 @@ try {
);
if (closed.isError === true)
throw new Error("packaged MCP could not close its binary");
await verifyPackagedPromptCompletion(client, mcpOptions, false);
await prompts.verifyPromptCompletion(client, mcpOptions, false);
const mcpBundlePath = join(evidenceRoot, "mcp.json");
const mcpExport = await client.callTool(
{ name: "export_evidence_bundle", arguments: { path: mcpBundlePath } },
@@ -495,7 +492,7 @@ try {
}
process.stdout.write(
`${JSON.stringify({ cli: true, analysisCli: true, artifactCli: true, evidenceCli: true, incurMcpCommand: "npx -y rea-agents mcp", doctor: "platform-appropriate", setup: supportedSetupHost ? "planned-then-idempotent" : "unsupported-host-rejected", setupPlanReadOnly: supportedSetupHost, existingHopperPreserved: supportedSetupHost, clients: supportedSetupHost ? 2 : 0, backupReadback: supportedSetupHost, failureRecovery: supportedSetupHost, skill: supportedSetupHost, mcpTools: expectedToolCount, mcpPrompts: expectedPromptNames.length, promptCompletion: true, promptCompletionLifecycle: true, evidenceMcp: true, targetFree: true, targetLifecycle: true })}\n`,
`${JSON.stringify({ cli: true, analysisCli: true, artifactCli: true, evidenceCli: true, incurMcpCommand: "npx -y rea-agents mcp", doctor: "platform-appropriate", setup: supportedSetupHost ? "planned-then-idempotent" : "unsupported-host-rejected", setupPlanReadOnly: supportedSetupHost, existingHopperPreserved: supportedSetupHost, clients: supportedSetupHost ? 2 : 0, backupReadback: supportedSetupHost, failureRecovery: supportedSetupHost, skill: 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 });
+40
View File
@@ -0,0 +1,40 @@
import { execFile } from "node:child_process";
import { join } from "node:path";
import { promisify } from "node:util";
const exec = promisify(execFile);
const packedBridge = "package/bridge/hopper_bridge.py";
/** Verify that the packed production bridge rejects a catastrophic regex. */
export async function verifyPackedBridge({
root,
workspace,
tarball,
packedFiles,
}) {
if (!packedFiles.includes(packedBridge))
throw new Error("package omitted the Hopper bridge");
await exec("tar", ["-xf", join(root, tarball), "-C", workspace]);
const probe = JSON.parse(
(
await exec("python3", [
join(root, "tests/fixtures/bridgeRegexProbe.py"),
join(workspace, packedBridge),
JSON.stringify({
action: "match",
pattern: "(a|aa){1,35}b",
value: "a".repeat(35),
case_sensitive: true,
}),
])
).stdout,
);
if (
probe.ok !== false ||
probe.diagnostic_type !== "invalid_request" ||
probe.message !== "Regex exceeds the 10000-path backtracking budget"
)
throw new Error(
`packaged Hopper bridge omitted regex bounds: ${JSON.stringify(probe)}`,
);
}