mirror of
https://github.com/morluto/rea.git
synced 2026-11-21 06:04:03 +00:00
refactor(mcp): bind artifact and bundle comparison through a derived binding that acquires under the artifact resource scope (#11554)
* refactor(mcp): bind artifact and bundle comparison through an acquiring derived binding that owns their artifact resource scope compare_artifacts and compare_bundles registered bespoke handlers that read caller-named files under the server's artifact resource scope and then repeated the session-derived delivery. The derived binding kind now takes an optional acquisition with the resource scope it reads under; the table passes the scope, the readers open and release handles in it (failed releases stay owned for retry), and acquisition failures are delivered unchanged. The artifact unknown and the bundle Evidence moved to application owners. * fix(mcp): return a bundle comparison's record-pair failure as a typed Result bundleComparisonExecution declared a Result but let compareBundles throw AnalysisInputError for missing or repeated record pairs. It now returns the typed failure; unexpected errors still propagate.
This commit is contained in:
1 parent
a447161a84
commit
f6df353002
11 files changed
+369
-297
No files matched your search
@@ -33,6 +33,8 @@ import {
|
||||
sameTargetIdentity,
|
||||
unknownTarget,
|
||||
} from "../../domain/targetIdentity.js";
|
||||
import type { RecordUnknownInput } from "../../domain/residualUnknown.js";
|
||||
import type { InvestigationWorkflowExecution } from "../investigation/InvestigationWorkflows.js";
|
||||
|
||||
const OPERATION = "compare_artifacts";
|
||||
|
||||
@@ -199,3 +201,65 @@ const mismatch = (): Result<never, EvidenceIntegrityError> =>
|
||||
`Artifact summary does not match its retained parent inventory. A summary from an earlier Evidence format no longer matches. ${RECREATE_EVIDENCE_GUIDANCE}`,
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Compare resolved inventories for a session: the derived Evidence, both
|
||||
* sources to retain, and the residual question a changed, unknown or
|
||||
* truncated comparison leaves.
|
||||
*/
|
||||
export const artifactComparisonExecution = (
|
||||
sources: ArtifactComparisonSources,
|
||||
): Result<InvestigationWorkflowExecution, AnalysisError> => {
|
||||
const compared = compareArtifactEvidence(sources);
|
||||
if (!compared.ok) return compared;
|
||||
const { left, right } = sources;
|
||||
const { comparison, evidence } = compared.value;
|
||||
return ok({
|
||||
evidence,
|
||||
sources: [left, right],
|
||||
unknown: artifactUnknownInput(
|
||||
left,
|
||||
right,
|
||||
comparison,
|
||||
evidence.evidence_id,
|
||||
),
|
||||
});
|
||||
};
|
||||
|
||||
const artifactUnknownInput = (
|
||||
left: { readonly evidence_id: string },
|
||||
right: { readonly evidence_id: string },
|
||||
comparison: ArtifactComparisonResult,
|
||||
comparisonEvidenceId: string,
|
||||
): RecordUnknownInput | undefined => {
|
||||
const { status } = comparison;
|
||||
if (status === "unchanged") return undefined;
|
||||
const sourceIds = [...new Set([left.evidence_id, right.evidence_id])];
|
||||
const contradictingIds = comparison.integrity_mismatch_evidence_ids ?? [];
|
||||
const contentContradictions =
|
||||
status === "changed" && left.evidence_id !== right.evidence_id
|
||||
? [right.evidence_id]
|
||||
: [];
|
||||
const contradictions =
|
||||
contradictingIds.length > 0 ? contradictingIds : contentContradictions;
|
||||
return {
|
||||
question: `Artifact comparison is ${status} (comparison ${comparisonEvidenceId})`,
|
||||
severity:
|
||||
status === "unknown" || status === "truncated" ? "high" : "medium",
|
||||
domain: "artifact-comparison",
|
||||
supporting_evidence_ids: sourceIds.filter(
|
||||
(id) => !contradictions.includes(id),
|
||||
),
|
||||
contradicting_evidence_ids: contradictions,
|
||||
required_authority: "shipped-artifact",
|
||||
required_confidence: "observed",
|
||||
required_environment: null,
|
||||
recommended_probes: [
|
||||
{
|
||||
operation: "inspect_artifact",
|
||||
rationale: "Inspect both artifacts and compare their complete graphs.",
|
||||
},
|
||||
],
|
||||
relationships: [],
|
||||
};
|
||||
};
|
||||
Reference in new issue
Block a user