Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

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

morlutob394903b884a
diff --cc scripts/verify-package-prompts.mjs
index 47af4fc5c,000000000..079f925ba
mode 100644,000000..100644
--- a/scripts/verify-package-prompts.mjs
+++ b/scripts/verify-package-prompts.mjs
@@@ -1,66 -1,0 +1,62 @@@
++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;
+ if (typeof value !== "string") throw new Error("MCP result omitted text");
+ return value;
+};
+
+/** 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)) !==
+ JSON.stringify(expectedNames)
+ )
+ throw new Error("packaged MCP prompt inventory diverged from contracts");
+ const guided = await client.getPrompt(
+ {
+ name: "investigate_feature",
+ arguments: { feature: "fixture behavior" },
+ },
+ options,
+ );
+ const guidedText = guided.messages.find(
+ ({ content }) => content.type === "text",
+ )?.content;
+ if (
+ guidedText?.type !== "text" ||
+ !guidedText.text.includes("`trace_feature`") ||
+ !guidedText.text.includes("Observations") ||
+ !guidedText.text.includes("Unknowns")
+ )
+ throw new Error("packaged MCP guided prompt rendering failed");
+};
+
+/** 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 = [
+ {
+ ref: { type: "ref/prompt", name: "investigate_feature" },
+ argument: { name: "document", value: "fix" },
+ },
+ {
+ ref: { type: "ref/prompt", name: "investigate_feature" },
+ argument: { name: "procedure", value: "fix" },
+ context: { arguments: { document: "fixture" } },
+ },
+ ];
+ for (const request of requests) {
+ const result = await client.complete(request, options);
+ if (
+ JSON.stringify(result.completion.values) !== JSON.stringify(expected) ||
+ result.completion.total !== expected.length ||
+ result.completion.hasMore !== false
+ )
+ throw new Error("packaged MCP prompt completion lifecycle failed");
+ }
+};
diff --cc scripts/verify-package.mjs
index fe432b794,648f7e074..7e5cedbe5
--- a/scripts/verify-package.mjs
+++ b/scripts/verify-package.mjs
@@@ -14,19 -14,14 +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";
-
- const expectedToolCount = TOOL_CONTRACTS.length;
- const expectedPromptNames = PROMPT_CONTRACTS.map(({ name }) => name);
++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;
-
--// 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-"));
@@@ -426,11 -426,9 +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 -441,20 +440,21 @@@
);
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(text(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(text(batch)).normalized_result;
++ const batchResult = json(prompts.mcpText(batch)).normalized_result;
if (
batch.isError === true ||
batchResult?.total !== 1 ||
@@@ -473,7 -470,6 +470,7 @@@
);
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 -491,7 +492,7 @@@
}
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: expectedToolCount, evidenceMcp: true, targetFree: true, targetLifecycle: true, boundedRegexBridge: 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 });