refactor!: enforce canonical evidence and provider boundaries

Deliver complete Evidence directly through MCP with required nullable analysis profiles and immutable per-server delivery settings. Bind selected environments at construction and require typed cleanup outcomes with retained retry ownership.

Remove test-only routing, duplicate session and snapshot metadata, producer-field repairs, and ambiguous provider arguments. Separate artifact byte identity from occurrence classification and retain typed source-map and partial native facts across CLI, MCP, and verifier consumers.

BREAKING CHANGE: obsolete Evidence envelopes, session aliases, incomplete snapshots, and missing normalized producer facts are no longer accepted.
This commit is contained in:
morluto
2026-10-09 20:18:52 +08:00
parent 2a7746998d
commit 63bf91405c
514 changed files with 9296 additions and 5825 deletions
@@ -1,10 +1,12 @@
import type { ToolResultDelivery } from "./toolResult.js";
import type { EvidenceMcpServer } from "./EvidenceMcpServer.js";
import type { EvidenceWriter } from "../application/investigation/InvestigationRecordPort.js";
import {
optionalProviderUnavailable,
type OptionalProviderLoadFailure,
} from "../application/OptionalObservationProviders.js";
import { err } from "../domain/result.js";
import type { McpServer, ServerContext } from "@modelcontextprotocol/server";
import type { ServerContext } from "@modelcontextprotocol/server";
import type { JavaScriptRuntimeObservationPort } from "../application/javascript/JavaScriptRuntimeObservationPort.js";
import {
@@ -19,7 +21,6 @@ import { observeJavaScriptRuntimeInputSchema } from "../domain/javascript/javasc
import type { Logger } from "../logger.js";
import { logToolExecution } from "./toolLogging.js";
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
import { toCallToolResult, toEvidenceToolResult } from "./toolResult.js";
interface RuntimeToolRegistration {
readonly logger: Logger;
@@ -30,9 +31,10 @@ interface RuntimeToolRegistration {
/** Register passive Inspector tools even when policy keeps them unavailable. */
export const registerJavaScriptRuntimeObservationTools = (
server: McpServer,
server: EvidenceMcpServer,
options: RuntimeToolRegistration,
): void => {
const registration = { ...options, delivery: server.delivery };
const listContract = toolContract("list_javascript_runtime_targets");
const observeContract = toolContract("observe_javascript_runtime");
server.registerTool(
@@ -40,7 +42,7 @@ export const registerJavaScriptRuntimeObservationTools = (
toolRegistrationOptions(listContract),
(input, context) =>
runRuntimeTool(
options,
registration,
listContract,
{ input, context },
(parsed, signal) =>
@@ -52,7 +54,7 @@ export const registerJavaScriptRuntimeObservationTools = (
toolRegistrationOptions(observeContract),
(input, context) =>
runRuntimeTool(
options,
registration,
observeContract,
{ input, context },
async (parsed, signal) => {
@@ -64,7 +66,7 @@ export const registerJavaScriptRuntimeObservationTools = (
};
const runRuntimeTool = async <Input>(
options: RuntimeToolRegistration,
options: RuntimeToolRegistration & { readonly delivery: ToolResultDelivery },
contract: ToolContract,
request: { readonly input: Input; readonly context: ServerContext },
execute: (
@@ -74,14 +76,18 @@ const runRuntimeTool = async <Input>(
) => {
const { input, context } = request;
if (options.loadFailure !== undefined)
return toCallToolResult(
return options.delivery.toCallToolResult(
err(optionalProviderUnavailable(options.loadFailure, contract.name)),
contract,
);
const result = await logToolExecution(options.logger, contract.name, () =>
execute(input, context.mcpReq.signal),
);
if (!result.ok) return toCallToolResult(result, contract);
if (!result.ok) return options.delivery.toCallToolResult(result, contract);
const recorded = options.recordEvidence?.(result.value);
return toEvidenceToolResult(result.value, contract, recorded);
return options.delivery.toEvidenceToolResult(
result.value,
contract,
recorded,
);
};