feat(javascript): compare source with shipped bundles
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import type { McpServer } from "@modelcontextprotocol/server";
|
||||
|
||||
import { compareSourceToBundleEvidenceValidated } from "../../application/JavaScriptApplicationWorkflowService.js";
|
||||
import { resolveCompareSourceToBundleRequestValidated } from "../../application/ApplicationWorkflowEvidenceResolver.js";
|
||||
import { applicationToolContract } from "../../contracts/applicationToolContracts.js";
|
||||
import { compareSourceToBundleRequestSchema } from "../../contracts/applicationWorkflowInputContracts.js";
|
||||
import { sourceToBundleComparisonResultSchema } from "../../domain/sourceToBundleComparisonSchemas.js";
|
||||
import { logToolExecution } from "../toolLogging.js";
|
||||
import { safeParseToolInput } from "../toolInputValidation.js";
|
||||
import { toolRegistrationOptions } from "../toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "../toolResult.js";
|
||||
import { recordResult, recordSources } from "./helpers.js";
|
||||
import type { ApplicationToolRegistration } from "./types.js";
|
||||
|
||||
const contract = applicationToolContract("compare_source_to_bundle");
|
||||
|
||||
/** Register conservative historical-source to bundle comparison. */
|
||||
export const registerCompareSourceToBundleTool = (
|
||||
server: McpServer,
|
||||
options: ApplicationToolRegistration,
|
||||
): void => {
|
||||
server.registerTool(
|
||||
contract.name,
|
||||
toolRegistrationOptions(contract),
|
||||
async (input) => {
|
||||
const parsedInput = safeParseToolInput(
|
||||
compareSourceToBundleRequestSchema,
|
||||
input,
|
||||
contract.name,
|
||||
);
|
||||
if (!parsedInput.ok) return toCallToolResult(parsedInput, contract);
|
||||
const resolved = resolveCompareSourceToBundleRequestValidated(
|
||||
parsedInput.value,
|
||||
options.evidenceLookup,
|
||||
);
|
||||
if (!resolved.ok) return toCallToolResult(resolved, contract);
|
||||
const result = await logToolExecution(options.logger, contract.name, () =>
|
||||
Promise.resolve(compareSourceToBundleEvidenceValidated(resolved.value)),
|
||||
);
|
||||
if (!result.ok) return toCallToolResult(result, contract);
|
||||
const recorded = recordSources(options.recordEvidence, [
|
||||
resolved.value.application,
|
||||
]);
|
||||
if (!recorded.ok) return toCallToolResult(recorded, contract);
|
||||
const comparison = sourceToBundleComparisonResultSchema.parse(
|
||||
result.value.normalized_result,
|
||||
);
|
||||
return recordResult(
|
||||
options,
|
||||
contract,
|
||||
result.value,
|
||||
resolved.value.unknown_registry_approved === true &&
|
||||
comparison.summary.unknown > 0
|
||||
? "source-to-bundle-comparison"
|
||||
: undefined,
|
||||
);
|
||||
},
|
||||
);
|
||||
};
|
||||
@@ -24,7 +24,10 @@ export const recordResult = (
|
||||
options: ApplicationToolRegistration,
|
||||
contract: (typeof APPLICATION_TOOL_CONTRACTS)[number],
|
||||
evidence: Evidence,
|
||||
unknownKind?: "application-version-comparison" | "javascript-export-shape",
|
||||
unknownKind?:
|
||||
| "application-version-comparison"
|
||||
| "javascript-export-shape"
|
||||
| "source-to-bundle-comparison",
|
||||
) => {
|
||||
const recorded =
|
||||
unknownKind === undefined
|
||||
@@ -42,13 +45,18 @@ export const recordResult = (
|
||||
|
||||
const unknownRegistration = (
|
||||
evidence: Evidence,
|
||||
kind: "application-version-comparison" | "javascript-export-shape",
|
||||
kind:
|
||||
| "application-version-comparison"
|
||||
| "javascript-export-shape"
|
||||
| "source-to-bundle-comparison",
|
||||
) => ({
|
||||
approved: true as const,
|
||||
question:
|
||||
kind === "application-version-comparison"
|
||||
? "Which application entities remain unmatched or ambiguous across these versions?"
|
||||
: "Which selected JavaScript export return shapes remain dynamic, incomplete, or ambiguously paired?",
|
||||
: kind === "source-to-bundle-comparison"
|
||||
? "Which historical source files remain unmatched or ambiguously mapped to the shipped bundle?"
|
||||
: "Which selected JavaScript export return shapes remain dynamic, incomplete, or ambiguously paired?",
|
||||
severity: "medium" as const,
|
||||
domain: kind,
|
||||
supporting_evidence_ids: [evidence.evidence_id],
|
||||
@@ -70,13 +78,15 @@ const unknownRegistration = (
|
||||
"Add approved passive runtime Evidence without promoting it to static fact.",
|
||||
},
|
||||
]
|
||||
: [
|
||||
{
|
||||
operation: "run_controlled_replay",
|
||||
rationale:
|
||||
"Validate exact approved module behavior separately when runtime semantics are required.",
|
||||
},
|
||||
]),
|
||||
: kind === "source-to-bundle-comparison"
|
||||
? []
|
||||
: [
|
||||
{
|
||||
operation: "run_controlled_replay",
|
||||
rationale:
|
||||
"Validate exact approved module behavior separately when runtime semantics are required.",
|
||||
},
|
||||
]),
|
||||
],
|
||||
relationships: [],
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user