feat: add persistent cross-version investigation workspaces
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type { McpServer } from "@modelcontextprotocol/server";
|
||||
|
||||
import type { BinarySessionPort } from "../application/BinarySession.js";
|
||||
import { runCrossVersionInvestigation } from "../application/CrossVersionInvestigation.js";
|
||||
import type { ToolContract } from "../contracts/toolContracts.js";
|
||||
import { buildCallPath, callPathInputSchema } from "../domain/callPath.js";
|
||||
import {
|
||||
@@ -12,10 +13,12 @@ import {
|
||||
verifyReconstruction,
|
||||
} from "../domain/reconstructionVerification.js";
|
||||
import {
|
||||
changedBehaviorResultSchema,
|
||||
changedBehaviorInputSchema,
|
||||
findChangedBehavior,
|
||||
} from "../domain/changedBehavior.js";
|
||||
import { createEvidence, type Evidence } from "../domain/evidence.js";
|
||||
import type { EvidenceFilePolicy } from "../domain/evidenceBundle.js";
|
||||
import { EvidenceIntegrityError } from "../domain/errors.js";
|
||||
import { jsonValueSchema } from "../domain/jsonValue.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
@@ -38,8 +41,9 @@ export const registerInvestigationTools = (
|
||||
ToolContract<"correlate_static_and_runtime">,
|
||||
ToolContract<"verify_reconstruction">,
|
||||
],
|
||||
evidenceFilePolicy: EvidenceFilePolicy,
|
||||
): void => {
|
||||
registerChangedBehavior(server, session, contracts[0]);
|
||||
registerChangedBehavior(server, session, contracts[0], evidenceFilePolicy);
|
||||
registerCallPath(server, session, contracts[1]);
|
||||
registerStaticRuntime(server, session, contracts[2]);
|
||||
registerReconstruction(server, session, contracts[3]);
|
||||
@@ -49,58 +53,98 @@ const registerChangedBehavior = (
|
||||
server: McpServer,
|
||||
session: BinarySessionPort,
|
||||
contract: ToolContract<"find_changed_behavior">,
|
||||
evidenceFilePolicy: EvidenceFilePolicy,
|
||||
): void => {
|
||||
server.registerTool(contract.name, contractOptions(contract), (input) => {
|
||||
const parsed = changedBehaviorInputSchema.parse(input);
|
||||
const closure = evidenceClosure(
|
||||
session,
|
||||
comparisonClosure(parsed.comparisons),
|
||||
);
|
||||
if (!closure.ok) return toCallToolResult(closure, contract);
|
||||
const links = closure.value;
|
||||
const result = findChangedBehavior(
|
||||
parsed.comparisons,
|
||||
parsed.offset,
|
||||
parsed.limit,
|
||||
);
|
||||
const evidence = createEvidence(undefined, CHANGED_BEHAVIOR_PROVIDER, {
|
||||
predicateType: "rea.changed-behavior/v1",
|
||||
operation: contract.name,
|
||||
parameters: {
|
||||
comparison_evidence_ids: parsed.comparisons.map(
|
||||
({ evidence_id: id }) => id,
|
||||
),
|
||||
offset: parsed.offset,
|
||||
limit: parsed.limit,
|
||||
},
|
||||
result: jsonValueSchema.parse(result),
|
||||
confidence: "derived",
|
||||
authority: "analyst-inference",
|
||||
limitations: result.limitations,
|
||||
evidenceLinks: links,
|
||||
});
|
||||
const recorded = recordWorkflowEvidence(
|
||||
session,
|
||||
evidence,
|
||||
parsed.unknown_registry_approved,
|
||||
result.behavior_status === "unknown" ||
|
||||
result.behavior_status === "truncated",
|
||||
{
|
||||
question: `Changed behavior result ${evidence.evidence_id} remains ${result.behavior_status}`,
|
||||
domain: "changed-behavior",
|
||||
requiredAuthority: "controlled-replay",
|
||||
requiredConfidence: "observed",
|
||||
probes: [
|
||||
{
|
||||
operation: "capture_process_scenario",
|
||||
rationale:
|
||||
"Capture both versions under the same bounded scenario and environment.",
|
||||
},
|
||||
],
|
||||
},
|
||||
);
|
||||
return toCallToolResult(recorded, contract);
|
||||
});
|
||||
server.registerTool(
|
||||
contract.name,
|
||||
contractOptions(contract),
|
||||
async (input, context) => {
|
||||
const parsed = changedBehaviorInputSchema.parse(input);
|
||||
if (parsed.investigation_run !== undefined) {
|
||||
const investigated = await runCrossVersionInvestigation(
|
||||
parsed.investigation_run,
|
||||
evidenceFilePolicy,
|
||||
session,
|
||||
context.mcpReq.signal,
|
||||
);
|
||||
if (!investigated.ok) return toCallToolResult(investigated, contract);
|
||||
const result = changedBehaviorResultSchema.parse(
|
||||
investigated.value.evidence.normalized_result,
|
||||
);
|
||||
return toCallToolResult(
|
||||
recordWorkflowEvidence(
|
||||
session,
|
||||
investigated.value.evidence,
|
||||
parsed.unknown_registry_approved,
|
||||
result.behavior_status === "unknown" ||
|
||||
result.behavior_status === "truncated",
|
||||
{
|
||||
question: `Automatic changed behavior run ${result.investigation_run?.run_id ?? "unknown"} remains ${result.behavior_status}`,
|
||||
domain: "changed-behavior",
|
||||
requiredAuthority: "controlled-replay",
|
||||
requiredConfidence: "observed",
|
||||
probes: [
|
||||
{
|
||||
operation: "capture_process_scenario",
|
||||
rationale:
|
||||
"Capture both versions under the same bounded scenario and environment.",
|
||||
},
|
||||
],
|
||||
},
|
||||
),
|
||||
contract,
|
||||
);
|
||||
}
|
||||
const closure = evidenceClosure(
|
||||
session,
|
||||
comparisonClosure(parsed.comparisons),
|
||||
);
|
||||
if (!closure.ok) return toCallToolResult(closure, contract);
|
||||
const links = closure.value;
|
||||
const result = findChangedBehavior(
|
||||
parsed.comparisons,
|
||||
parsed.offset,
|
||||
parsed.limit,
|
||||
);
|
||||
const evidence = createEvidence(undefined, CHANGED_BEHAVIOR_PROVIDER, {
|
||||
predicateType: "rea.changed-behavior/v1",
|
||||
operation: contract.name,
|
||||
parameters: {
|
||||
comparison_evidence_ids: parsed.comparisons.map(
|
||||
({ evidence_id: id }) => id,
|
||||
),
|
||||
offset: parsed.offset,
|
||||
limit: parsed.limit,
|
||||
},
|
||||
result: jsonValueSchema.parse(result),
|
||||
confidence: "derived",
|
||||
authority: "analyst-inference",
|
||||
limitations: result.limitations,
|
||||
evidenceLinks: links,
|
||||
});
|
||||
const recorded = recordWorkflowEvidence(
|
||||
session,
|
||||
evidence,
|
||||
parsed.unknown_registry_approved,
|
||||
result.behavior_status === "unknown" ||
|
||||
result.behavior_status === "truncated",
|
||||
{
|
||||
question: `Changed behavior result ${evidence.evidence_id} remains ${result.behavior_status}`,
|
||||
domain: "changed-behavior",
|
||||
requiredAuthority: "controlled-replay",
|
||||
requiredConfidence: "observed",
|
||||
probes: [
|
||||
{
|
||||
operation: "capture_process_scenario",
|
||||
rationale:
|
||||
"Capture both versions under the same bounded scenario and environment.",
|
||||
},
|
||||
],
|
||||
},
|
||||
);
|
||||
return toCallToolResult(recorded, contract);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
const registerCallPath = (
|
||||
|
||||
@@ -434,12 +434,17 @@ export const registerSessionTools = (
|
||||
registerArtifactComparisonTool(server, session, compareArtifactsContract);
|
||||
registerFunctionComparisonTool(server, session, compareFunctionsContract);
|
||||
registerBundleComparisonTool(server, session, compareBundlesContract);
|
||||
registerInvestigationTools(server, session, [
|
||||
changedBehaviorContract,
|
||||
callPathContract,
|
||||
staticRuntimeContract,
|
||||
reconstructionContract,
|
||||
]);
|
||||
registerInvestigationTools(
|
||||
server,
|
||||
session,
|
||||
[
|
||||
changedBehaviorContract,
|
||||
callPathContract,
|
||||
staticRuntimeContract,
|
||||
reconstructionContract,
|
||||
],
|
||||
evidenceFilePolicy,
|
||||
);
|
||||
registerUnknownTools({
|
||||
server,
|
||||
session,
|
||||
|
||||
@@ -20,52 +20,12 @@ export const DENY_EVIDENCE_FILE_POLICY: EvidenceFilePolicy = {
|
||||
};
|
||||
|
||||
export { PROCESS_PROVIDER } from "../application/ProcessEvidence.js";
|
||||
|
||||
/** Provider identity for deterministic cross-artifact comparisons. */
|
||||
export const ARTIFACT_COMPARISON_PROVIDER = {
|
||||
id: "rea-artifact-comparison",
|
||||
name: "REA artifact comparison",
|
||||
version: "1",
|
||||
} as const;
|
||||
|
||||
/** Provider identity for deterministic cross-function comparisons. */
|
||||
export const FUNCTION_COMPARISON_PROVIDER = {
|
||||
id: "rea-function-comparison",
|
||||
name: "REA function comparison",
|
||||
version: "1",
|
||||
} as const;
|
||||
|
||||
/** Provider identity for deterministic Evidence bundle comparisons. */
|
||||
export const BUNDLE_COMPARISON_PROVIDER = {
|
||||
id: "rea-bundle-comparison",
|
||||
name: "REA Evidence bundle comparison",
|
||||
version: "1",
|
||||
} as const;
|
||||
|
||||
/** Provider identity for comparison-Evidence behavior aggregation. */
|
||||
export const CHANGED_BEHAVIOR_PROVIDER = {
|
||||
id: "rea-changed-behavior",
|
||||
name: "REA changed behavior investigation",
|
||||
version: "1",
|
||||
} as const;
|
||||
|
||||
/** Provider identity for Evidence-backed call-path reconstruction. */
|
||||
export const CALL_PATH_PROVIDER = {
|
||||
id: "rea-call-path",
|
||||
name: "REA call path reconstruction",
|
||||
version: "1",
|
||||
} as const;
|
||||
|
||||
/** Provider identity for explicit static/runtime hypothesis correlation. */
|
||||
export const STATIC_RUNTIME_PROVIDER = {
|
||||
id: "rea-static-runtime-correlation",
|
||||
name: "REA static/runtime correlation",
|
||||
version: "1",
|
||||
} as const;
|
||||
|
||||
/** Provider identity for finite reconstruction specification verification. */
|
||||
export const RECONSTRUCTION_PROVIDER = {
|
||||
id: "rea-reconstruction-verifier",
|
||||
name: "REA reconstruction verifier",
|
||||
version: "1",
|
||||
} as const;
|
||||
export {
|
||||
ARTIFACT_COMPARISON_PROVIDER,
|
||||
BUNDLE_COMPARISON_PROVIDER,
|
||||
CALL_PATH_PROVIDER,
|
||||
CHANGED_BEHAVIOR_PROVIDER,
|
||||
FUNCTION_COMPARISON_PROVIDER,
|
||||
RECONSTRUCTION_PROVIDER,
|
||||
STATIC_RUNTIME_PROVIDER,
|
||||
} from "../application/InvestigationProviders.js";
|
||||
|
||||
Reference in New Issue
Block a user