chore: merge main and resolve MCP contract conflicts
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
import { createEvidence } from "../domain/evidence.js";
|
||||
import type { ManagedMemberInspection } from "../domain/managedArtifact.js";
|
||||
import type {
|
||||
ManagedMemberInspection,
|
||||
ManagedNativeBoundaryInspection,
|
||||
} from "../domain/managedArtifact.js";
|
||||
import type { InspectMacho } from "../domain/nativeInspection.js";
|
||||
|
||||
const MANAGED_STATIC_EXAMPLE_PROVIDER = {
|
||||
id: "rea-dotnet-static",
|
||||
@@ -7,6 +11,12 @@ const MANAGED_STATIC_EXAMPLE_PROVIDER = {
|
||||
version: "1",
|
||||
} as const;
|
||||
|
||||
const NATIVE_EXAMPLE_PROVIDER = {
|
||||
id: "native-macos",
|
||||
name: "REA native macOS provider",
|
||||
version: "1",
|
||||
} as const;
|
||||
|
||||
const emptyManagedMembers = (
|
||||
sha256: string,
|
||||
mvid: string,
|
||||
@@ -142,6 +152,159 @@ export const MANAGED_MEMBER_COMPARISON_EXAMPLE = {
|
||||
|
||||
const runtimeExampleEvidence = evidence(runtimeMembers());
|
||||
|
||||
const boundaryEvidence = () => {
|
||||
const result: ManagedNativeBoundaryInspection = {
|
||||
schema_version: 1,
|
||||
artifact: {
|
||||
path: "/examples/ManagedInterop.exe",
|
||||
sha256: "6".repeat(64),
|
||||
byte_length: 8192,
|
||||
format: "pe",
|
||||
},
|
||||
module: {
|
||||
name: "ManagedInterop.exe",
|
||||
generation: 0,
|
||||
mvid: "00112233-4455-4677-8899-aabbccddeeff",
|
||||
enc_id: null,
|
||||
enc_base_id: null,
|
||||
token: "0x00000001",
|
||||
row_offset: 0,
|
||||
},
|
||||
metadata: {
|
||||
status: "complete",
|
||||
version: "v4.0.30319",
|
||||
table_row_counts: {},
|
||||
},
|
||||
identity_scope: {
|
||||
token_identity: "build-local",
|
||||
requires_artifact_sha256: "6".repeat(64),
|
||||
requires_mvid: "00112233-4455-4677-8899-aabbccddeeff",
|
||||
},
|
||||
cli_native: {
|
||||
il_only: true,
|
||||
requires_32bit: false,
|
||||
strong_name_signed: false,
|
||||
native_entry_point: false,
|
||||
ready_to_run_signature: false,
|
||||
managed_native_header_rva: 0,
|
||||
managed_native_header_size: 0,
|
||||
},
|
||||
module_refs: {
|
||||
items: [
|
||||
{
|
||||
token: "0x1a000001",
|
||||
row_offset: 256,
|
||||
name: "nativehelper.dll",
|
||||
},
|
||||
],
|
||||
offset: 0,
|
||||
limit: 100,
|
||||
total: 1,
|
||||
returned: 1,
|
||||
dropped: 0,
|
||||
complete: true,
|
||||
},
|
||||
pinvoke_imports: {
|
||||
items: [
|
||||
{
|
||||
token: "0x1c000001",
|
||||
row_offset: 288,
|
||||
mapping_flags: 0,
|
||||
mapping_flags_hex: "0x0000",
|
||||
member_token: "0x06000001",
|
||||
member_kind: "method",
|
||||
member_name: "OpenNative",
|
||||
import_name: "open_native",
|
||||
import_scope_token: "0x1a000001",
|
||||
import_scope_name: "nativehelper.dll",
|
||||
no_mangle: true,
|
||||
char_set: "not-specified",
|
||||
call_convention: "cdecl",
|
||||
supports_last_error: false,
|
||||
best_fit: "assembly-default",
|
||||
throw_on_unmappable_char: "assembly-default",
|
||||
verification: "managed-declaration-only",
|
||||
},
|
||||
],
|
||||
offset: 0,
|
||||
limit: 100,
|
||||
total: 1,
|
||||
returned: 1,
|
||||
dropped: 0,
|
||||
complete: true,
|
||||
},
|
||||
native_implementations: emptyPage(100),
|
||||
summary: {
|
||||
module_ref_count: 1,
|
||||
pinvoke_import_count: 1,
|
||||
native_implementation_count: 0,
|
||||
ready_to_run: false,
|
||||
mixed_mode_or_native_header: false,
|
||||
},
|
||||
coverage: { state: "complete", issues: [] },
|
||||
limitations: [],
|
||||
};
|
||||
return createEvidence(undefined, MANAGED_STATIC_EXAMPLE_PROVIDER, {
|
||||
operation: "inspect_managed_native_boundaries",
|
||||
parameters: {},
|
||||
result,
|
||||
rawResult: null,
|
||||
limitations: result.limitations,
|
||||
});
|
||||
};
|
||||
|
||||
const nativeExportEvidence = () => {
|
||||
const result: InspectMacho = {
|
||||
format: "mach-o",
|
||||
endian: "little",
|
||||
word_size: 64,
|
||||
file_type: "dylib",
|
||||
flags: [],
|
||||
uuid: null,
|
||||
entrypoints: coverage([]),
|
||||
architectures: coverage([]),
|
||||
build_metadata: coverage([]),
|
||||
load_commands: coverage([]),
|
||||
dependencies: coverage([]),
|
||||
imports: coverage([]),
|
||||
exports: coverage([
|
||||
{
|
||||
name: "open_native",
|
||||
address: "0x1000",
|
||||
weak: false,
|
||||
reexport: false,
|
||||
source: "nm",
|
||||
},
|
||||
]),
|
||||
segments: coverage([]),
|
||||
provenance: [],
|
||||
limitations: [],
|
||||
};
|
||||
return createEvidence(
|
||||
{
|
||||
path: "/examples/nativehelper.dll",
|
||||
sha256: "7".repeat(64),
|
||||
format: "mach-o",
|
||||
architecture: "x86_64",
|
||||
},
|
||||
NATIVE_EXAMPLE_PROVIDER,
|
||||
{
|
||||
operation: "inspect_macho",
|
||||
parameters: {},
|
||||
result,
|
||||
rawResult: null,
|
||||
limitations: result.limitations,
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
const coverage = <Item>(items: readonly Item[]) => ({
|
||||
items: [...items],
|
||||
total: items.length,
|
||||
exhaustive: true,
|
||||
limitations: [],
|
||||
});
|
||||
|
||||
/** Minimal valid managed decompiler reconstruction import request. */
|
||||
export const MANAGED_RECONSTRUCTION_IMPORT_EXAMPLE = {
|
||||
static_members: runtimeExampleEvidence,
|
||||
@@ -172,6 +335,16 @@ export const MANAGED_RECONSTRUCTION_IMPORT_EXAMPLE = {
|
||||
],
|
||||
};
|
||||
|
||||
/** Minimal valid managed/native verification request. */
|
||||
export const MANAGED_NATIVE_VERIFICATION_EXAMPLE = {
|
||||
managed_boundaries: boundaryEvidence(),
|
||||
native_observations: [nativeExportEvidence()],
|
||||
limits: {
|
||||
max_native_observations: 20,
|
||||
max_candidates_per_import: 25,
|
||||
},
|
||||
};
|
||||
|
||||
/** Minimal valid managed runtime-correlation planning request. */
|
||||
export const MANAGED_RUNTIME_CORRELATION_EXAMPLE = {
|
||||
static_members: runtimeExampleEvidence,
|
||||
|
||||
@@ -1,19 +1,29 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { compareManagedMembersInputSchema } from "../domain/managedMemberComparison.js";
|
||||
import { managedNativeVerificationInputSchema } from "../domain/managedNativeVerification.js";
|
||||
import { managedReconstructionImportInputSchema } from "../domain/managedReconstruction.js";
|
||||
import { managedRuntimeCorrelationInputSchema } from "../domain/managedRuntimeCorrelation.js";
|
||||
import type { ToolContract } from "./toolContracts.js";
|
||||
import { managedWorkflowOutputSchemas } from "./toolOutputSchemas.js";
|
||||
import {
|
||||
MANAGED_MEMBER_COMPARISON_EXAMPLE,
|
||||
MANAGED_NATIVE_VERIFICATION_EXAMPLE,
|
||||
MANAGED_RECONSTRUCTION_IMPORT_EXAMPLE,
|
||||
MANAGED_RUNTIME_CORRELATION_EXAMPLE,
|
||||
} from "./managedWorkflowExamples.js";
|
||||
import { toolContractMetadata } from "./toolEffects.js";
|
||||
|
||||
const managedEvidenceIdSchema = z
|
||||
.string()
|
||||
.regex(/^ev_[a-f0-9]{64}$/u)
|
||||
.describe("Session-owned inspect_managed_members Evidence ID");
|
||||
const evidenceIdSchema = z.string().regex(/^ev_[a-f0-9]{64}$/u);
|
||||
const managedEvidenceIdSchema = evidenceIdSchema.describe(
|
||||
"Session-owned inspect_managed_members Evidence ID",
|
||||
);
|
||||
const managedBoundaryEvidenceIdSchema = evidenceIdSchema.describe(
|
||||
"Session-owned inspect_managed_native_boundaries Evidence ID",
|
||||
);
|
||||
const nativeObservationEvidenceIdSchema = evidenceIdSchema.describe(
|
||||
"Session-owned inspect_macho or analyze_function Evidence ID",
|
||||
);
|
||||
|
||||
/** MCP references for comparing two session-owned managed observations. */
|
||||
export const compareManagedMembersReferenceInputSchema = z
|
||||
@@ -45,6 +55,42 @@ export const managedReconstructionReferenceInputSchema =
|
||||
.omit({ static_members: true })
|
||||
.extend({ static_members_evidence_id: managedEvidenceIdSchema });
|
||||
|
||||
/** MCP references for managed/native verification from session Evidence. */
|
||||
export const managedNativeVerificationReferenceInputSchema = z
|
||||
.strictObject({
|
||||
managed_boundaries_evidence_id: managedBoundaryEvidenceIdSchema,
|
||||
native_observation_evidence_ids: z
|
||||
.array(nativeObservationEvidenceIdSchema)
|
||||
.min(1)
|
||||
.max(50)
|
||||
.describe("Unique session-owned native observation Evidence IDs"),
|
||||
limits: managedNativeVerificationInputSchema.shape.limits,
|
||||
unknown_registry_approved:
|
||||
managedNativeVerificationInputSchema.shape.unknown_registry_approved,
|
||||
})
|
||||
.superRefine((input, context) => {
|
||||
const ids = new Set<string>();
|
||||
for (const [
|
||||
index,
|
||||
evidenceId,
|
||||
] of input.native_observation_evidence_ids.entries()) {
|
||||
if (evidenceId === input.managed_boundaries_evidence_id)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: ["native_observation_evidence_ids", index],
|
||||
message:
|
||||
"Native observation Evidence must be distinct from managed boundary Evidence",
|
||||
});
|
||||
if (ids.has(evidenceId))
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: ["native_observation_evidence_ids", index],
|
||||
message: "Native observation Evidence IDs must be unique",
|
||||
});
|
||||
ids.add(evidenceId);
|
||||
}
|
||||
});
|
||||
|
||||
const comparisonOutputSchema =
|
||||
managedWorkflowOutputSchemas.compare_managed_members;
|
||||
if (comparisonOutputSchema === undefined)
|
||||
@@ -63,6 +109,12 @@ if (reconstructionOutputSchema === undefined)
|
||||
throw new Error(
|
||||
"Missing managed workflow output schema for import_managed_reconstruction",
|
||||
);
|
||||
const nativeVerificationOutputSchema =
|
||||
managedWorkflowOutputSchemas.verify_managed_native_boundaries;
|
||||
if (nativeVerificationOutputSchema === undefined)
|
||||
throw new Error(
|
||||
"Missing managed workflow output schema for verify_managed_native_boundaries",
|
||||
);
|
||||
|
||||
/** Provider-neutral managed-code workflow contracts. */
|
||||
export const MANAGED_WORKFLOW_TOOL_CONTRACTS = [
|
||||
@@ -86,6 +138,29 @@ export const MANAGED_WORKFLOW_TOOL_CONTRACTS = [
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "verify_managed_native_boundaries",
|
||||
...toolContractMetadata("verify_managed_native_boundaries"),
|
||||
description:
|
||||
"Verify managed P/Invoke/native-boundary declarations against authenticated native export or function Evidence without executing managed code or translating managed metadata tokens into native addresses. The workflow preserves declaration-only, verified, inferred, contradicted, and unresolved states.",
|
||||
kind: "application",
|
||||
inputSchema: managedNativeVerificationReferenceInputSchema,
|
||||
outputSchema: nativeVerificationOutputSchema,
|
||||
examples: [
|
||||
{
|
||||
title: "Verify a managed P/Invoke declaration against native Evidence",
|
||||
input: {
|
||||
managed_boundaries_evidence_id:
|
||||
MANAGED_NATIVE_VERIFICATION_EXAMPLE.managed_boundaries.evidence_id,
|
||||
native_observation_evidence_ids:
|
||||
MANAGED_NATIVE_VERIFICATION_EXAMPLE.native_observations.map(
|
||||
({ evidence_id: evidenceId }) => evidenceId,
|
||||
),
|
||||
limits: MANAGED_NATIVE_VERIFICATION_EXAMPLE.limits,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "import_managed_reconstruction",
|
||||
...toolContractMetadata("import_managed_reconstruction"),
|
||||
@@ -131,4 +206,3 @@ export const MANAGED_WORKFLOW_TOOL_CONTRACTS = [
|
||||
],
|
||||
},
|
||||
] as const satisfies readonly ToolContract[];
|
||||
import { z } from "zod";
|
||||
|
||||
@@ -98,6 +98,7 @@ export const TOOL_EFFECTS: Readonly<Record<string, ToolEffects>> = {
|
||||
inspect_managed_members: evidence,
|
||||
inspect_managed_native_boundaries: evidence,
|
||||
compare_managed_members: sessionEvidence,
|
||||
verify_managed_native_boundaries: sessionEvidence,
|
||||
import_managed_reconstruction: sessionEvidence,
|
||||
plan_managed_runtime_correlation: sessionEvidence,
|
||||
list_browser_targets: browserEvidence,
|
||||
|
||||
@@ -29,6 +29,7 @@ import {
|
||||
managedNativeBoundaryInspectionSchema,
|
||||
} from "../domain/managedArtifact.js";
|
||||
import { managedMemberComparisonResultSchema } from "../domain/managedMemberComparison.js";
|
||||
import { managedNativeVerificationResultSchema } from "../domain/managedNativeVerification.js";
|
||||
import { managedReconstructionImportResultSchema } from "../domain/managedReconstruction.js";
|
||||
import { managedRuntimeCorrelationResultSchema } from "../domain/managedRuntimeCorrelation.js";
|
||||
import { artifactComparisonResultSchema } from "../domain/artifactComparison.js";
|
||||
@@ -564,6 +565,9 @@ export const managedWorkflowOutputSchemas: Readonly<
|
||||
Record<string, z.ZodObject>
|
||||
> = {
|
||||
compare_managed_members: resultOf(managedMemberComparisonResultSchema),
|
||||
verify_managed_native_boundaries: resultOf(
|
||||
managedNativeVerificationResultSchema,
|
||||
),
|
||||
import_managed_reconstruction: resultOf(
|
||||
managedReconstructionImportResultSchema,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user