mirror of
https://github.com/morluto/rea
synced 2026-10-28 15:07:26 -04:00
refactor(mcp): share diagnostic evidence handling
This commit is contained in:
@@ -7,13 +7,11 @@ import type { EvidenceLookup } from "../application/EvidenceInputResolver.js";
|
||||
import type { EvidenceWriter } from "../application/investigation/InvestigationRecordPort.js";
|
||||
import { toolContract } from "../contracts/toolContracts.js";
|
||||
import type { Logger } from "pino";
|
||||
import { deliverEvidenceResult } from "./contractToolHandler.js";
|
||||
import { logToolExecution } from "./toolLogging.js";
|
||||
import { runEvidenceToolOperation } from "./contractToolHandler.js";
|
||||
import { applicationToolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { analysisInputErrorFromIssues } from "../domain/inputIssueProjection.js";
|
||||
import { err } from "../domain/result.js";
|
||||
import type { WithAdmittedAnalysis } from "./analysisAdmission.js";
|
||||
import { runAdmittedToolOperation } from "./admittedToolOperation.js";
|
||||
import { registerByteEntropyTool } from "./registerByteEntropyTool.js";
|
||||
|
||||
/** Bind offline layout inspection to its named contract and session Evidence owner. */
|
||||
@@ -58,32 +56,18 @@ export const registerBinaryDiagnosticsTools = (
|
||||
);
|
||||
const { detail, ...request } = parsed.data;
|
||||
const parameters = { detail };
|
||||
return runAdmittedToolOperation(
|
||||
server,
|
||||
withAdmittedAnalysis,
|
||||
contract.name,
|
||||
context.mcpReq.signal,
|
||||
async () => {
|
||||
const result = await logToolExecution(
|
||||
logger,
|
||||
contract.name,
|
||||
async () => {
|
||||
const ready = delivery.preflight(parameters);
|
||||
if (!ready.ok) return ready;
|
||||
const inspected = await service.inspect(request, {
|
||||
signal: context.mcpReq.signal,
|
||||
});
|
||||
return inspected.ok
|
||||
? delivery.projectEvidence(parameters, inspected.value)
|
||||
: inspected;
|
||||
},
|
||||
);
|
||||
return deliverEvidenceResult(
|
||||
server,
|
||||
result,
|
||||
contract,
|
||||
recordEvidence,
|
||||
);
|
||||
return runEvidenceToolOperation(
|
||||
{ server, logger, recordEvidence, withAdmittedAnalysis },
|
||||
contract,
|
||||
undefined,
|
||||
{ input: request, context },
|
||||
async (input, { signal }) => {
|
||||
const ready = delivery.preflight(parameters);
|
||||
if (!ready.ok) return ready;
|
||||
const inspected = await service.inspect(input, { signal });
|
||||
return inspected.ok
|
||||
? delivery.projectEvidence(parameters, inspected.value)
|
||||
: inspected;
|
||||
},
|
||||
);
|
||||
},
|
||||
|
||||
@@ -6,11 +6,9 @@ import type { EvidenceLookup } from "../application/EvidenceInputResolver.js";
|
||||
import type { EvidenceWriter } from "../application/investigation/InvestigationRecordPort.js";
|
||||
import { toolContract } from "../contracts/toolContracts.js";
|
||||
import type { Logger } from "pino";
|
||||
import { deliverEvidenceResult } from "./contractToolHandler.js";
|
||||
import { logToolExecution } from "./toolLogging.js";
|
||||
import { runEvidenceToolOperation } from "./contractToolHandler.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import type { WithAdmittedAnalysis } from "./analysisAdmission.js";
|
||||
import { runAdmittedToolOperation } from "./admittedToolOperation.js";
|
||||
|
||||
/** Reject an unretained byte-entropy summary before reading the selected file. */
|
||||
export const registerByteEntropyTool = (
|
||||
@@ -30,33 +28,19 @@ export const registerByteEntropyTool = (
|
||||
contract.name,
|
||||
toolRegistrationOptions(contract),
|
||||
async ({ detail, ...request }, context) =>
|
||||
runAdmittedToolOperation(
|
||||
server,
|
||||
withAdmittedAnalysis,
|
||||
contract.name,
|
||||
context.mcpReq.signal,
|
||||
async () => {
|
||||
const result = await logToolExecution(
|
||||
logger,
|
||||
contract.name,
|
||||
async () => {
|
||||
const parameters = { detail };
|
||||
const ready = delivery.preflight(parameters);
|
||||
if (!ready.ok) return ready;
|
||||
const inspected = await entropyService.inspect(request, {
|
||||
signal: context.mcpReq.signal,
|
||||
});
|
||||
return inspected.ok
|
||||
? delivery.projectEvidence(parameters, inspected.value)
|
||||
: inspected;
|
||||
},
|
||||
);
|
||||
return deliverEvidenceResult(
|
||||
server,
|
||||
result,
|
||||
contract,
|
||||
recordEvidence,
|
||||
);
|
||||
runEvidenceToolOperation(
|
||||
{ server, logger, recordEvidence, withAdmittedAnalysis },
|
||||
contract,
|
||||
undefined,
|
||||
{ input: request, context },
|
||||
async (input, { signal }) => {
|
||||
const parameters = { detail };
|
||||
const ready = delivery.preflight(parameters);
|
||||
if (!ready.ok) return ready;
|
||||
const inspected = await entropyService.inspect(input, { signal });
|
||||
return inspected.ok
|
||||
? delivery.projectEvidence(parameters, inspected.value)
|
||||
: inspected;
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user