mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 05:32:44 +00:00
* fix(mcp): preserve caller-selected binary session paths * test(mcp): verify caller paths across snapshot replay * test(mcp): separate session alias and snapshot replay coverage * fix(evidence): preserve selected paths across binary workflows * fix(evidence): retain authentication admission for caller aliases
76 lines
2.6 KiB
TypeScript
76 lines
2.6 KiB
TypeScript
import { parseAnalysisInput } from "./AnalysisInput.js";
|
|
import type {
|
|
AnalysisOperationPort,
|
|
ExecutionOptions,
|
|
} from "../ports/AnalysisProvider.js";
|
|
import { nativeProcedureInputSchema } from "../domain/native/nativeProcedureInput.js";
|
|
import type { BinaryTarget } from "../domain/binaryTargetTypes.js";
|
|
import { createAnalysisExecutionEvidence } from "../domain/analysisObservation.js";
|
|
import { parseFunctionDossier } from "../domain/native/functionDossier.js";
|
|
import type { JsonValue } from "../domain/jsonValue.js";
|
|
import { completeProviderEvidence } from "./ProviderOperationExecution.js";
|
|
import type { Evidence } from "../domain/evidence.js";
|
|
import { EvidenceLedger } from "./investigation/EvidenceLedger.js";
|
|
import {
|
|
recordEvidenceSources,
|
|
withEvidenceSources,
|
|
type AnalysisResultWithSources,
|
|
} from "./investigation/recordEvidenceSources.js";
|
|
|
|
/**
|
|
* Preserve the provider's observations when presenting a validated function
|
|
* dossier. Parameters are the provider input only: adapters separate delivery
|
|
* options such as MCP detail before calling.
|
|
*/
|
|
export const executeFunctionAnalysisEvidence = async (
|
|
analysis: AnalysisOperationPort,
|
|
parameters: Readonly<Record<string, JsonValue>>,
|
|
target: BinaryTarget | undefined,
|
|
options?: ExecutionOptions,
|
|
): Promise<AnalysisResultWithSources<Evidence>> => {
|
|
const input = parseAnalysisInput(
|
|
"analyze_function",
|
|
parameters,
|
|
nativeProcedureInputSchema,
|
|
options?.signal,
|
|
);
|
|
if (!input.ok) return input;
|
|
const arguments_ = input.value;
|
|
const execution = await analysis.execute(
|
|
"analyze_function",
|
|
arguments_,
|
|
options,
|
|
);
|
|
if (!execution.ok) return execution;
|
|
const sourceLedger = new EvidenceLedger();
|
|
const recorded = recordEvidenceSources(
|
|
(source) => sourceLedger.record(source),
|
|
execution.value.sourceEvidence ?? [],
|
|
);
|
|
const sources = sourceLedger.recordsForAnalysis();
|
|
if (!recorded.ok) return withEvidenceSources(recorded, sources);
|
|
const observation = {
|
|
...execution.value,
|
|
sourceEvidence: sources,
|
|
...(execution.value.subject === undefined && target !== undefined
|
|
? { subject: target }
|
|
: {}),
|
|
};
|
|
const dossier = parseFunctionDossier(execution.value.result);
|
|
const evidence = createAnalysisExecutionEvidence(
|
|
"analyze_function",
|
|
arguments_,
|
|
dossier.ok ? { ...observation, result: dossier.value } : observation,
|
|
"observed",
|
|
{ callerTarget: target },
|
|
);
|
|
if (!dossier.ok) {
|
|
dossier.error.retainPartialObservation(evidence);
|
|
return withEvidenceSources(dossier, sources);
|
|
}
|
|
return withEvidenceSources(
|
|
completeProviderEvidence(evidence, options?.signal),
|
|
sources,
|
|
);
|
|
};
|