Treat missing, partial, unknown, and unresolved call coverage as insufficient for call-set equality. Combine IDA caller/callee coverage without losing either explanation and recheck source coverage when verifying historical comparisons. Scope generated function-comparison unknowns with optional typed comparison/dimension facts, preserving legacy IDs and revision digests when absent. Keep unrelated dimensions conclusive, explicit dependencies applicable, and ambiguous function identity unknown. A confirmed change for matched functions remains a failure even if calls are incomplete. Validation: function/reconstruction/residual-unknown and bundle tests, recorded IDA protocol regression, public MCP comparison/verification, and advertised SDK JSON Schema checks. Real IDA provider execution was not verified. Fixes #2222
150 lines
4.8 KiB
TypeScript
150 lines
4.8 KiB
TypeScript
import { uniqueSorted } from "./canonicalOrdering.js";
|
|
import {
|
|
compareUnicodeCodePoints,
|
|
compositeKey,
|
|
} from "./unicodeCodePointOrder.js";
|
|
import type {
|
|
ReconstructionClaim,
|
|
ReconstructionClaimResult,
|
|
ReconstructionVerificationResult,
|
|
} from "./reconstructionVerificationSchemas.js";
|
|
import type { ResidualUnknown } from "./residualUnknown.js";
|
|
|
|
/** Select the latest revision of each residual unknown. */
|
|
export const reconstructionUnknownHeads = (
|
|
revisions: readonly ResidualUnknown[],
|
|
): ReadonlyMap<string, ResidualUnknown> => {
|
|
const heads = new Map<string, ResidualUnknown>();
|
|
for (const item of revisions) {
|
|
const current = heads.get(item.unknown_id);
|
|
if (current === undefined || current.revision < item.revision)
|
|
heads.set(item.unknown_id, item);
|
|
}
|
|
return heads;
|
|
};
|
|
|
|
/** Find active unknowns that affect a comparison or one of its sources. */
|
|
export const reconstructionClaimUnknowns = (
|
|
heads: ReadonlyMap<string, ResidualUnknown>,
|
|
comparisonId: string,
|
|
sourceIds: readonly string[],
|
|
dimension?: string,
|
|
): ResidualUnknown[] => {
|
|
const appliesToClaim = (item: ResidualUnknown): boolean => {
|
|
const scope = item.comparison_conclusion_scope;
|
|
return (
|
|
scope === undefined ||
|
|
(scope.comparison_evidence_id === comparisonId &&
|
|
(dimension === undefined ||
|
|
scope.dimensions.some(
|
|
(scopedDimension) => scopedDimension === dimension,
|
|
)))
|
|
);
|
|
};
|
|
const evidenceIds = new Set([comparisonId, ...sourceIds]);
|
|
const relevantIds = new Set(
|
|
[...heads.values()]
|
|
.filter(
|
|
(item) =>
|
|
item.status !== "resolved" &&
|
|
appliesToClaim(item) &&
|
|
[
|
|
...item.supporting_evidence_ids,
|
|
...item.contradicting_evidence_ids,
|
|
].some((id) => evidenceIds.has(id)),
|
|
)
|
|
.map(({ unknown_id: id }) => id),
|
|
);
|
|
const pending = [...relevantIds];
|
|
while (pending.length > 0) {
|
|
const currentId = pending.pop();
|
|
if (currentId === undefined) continue;
|
|
const current = heads.get(currentId);
|
|
if (current === undefined) continue;
|
|
for (const relationship of current.relationships) {
|
|
if (relationship.type === "related-to") continue;
|
|
const dependency = heads.get(relationship.unknown_id);
|
|
if (
|
|
dependency === undefined ||
|
|
dependency.status === "resolved" ||
|
|
relevantIds.has(dependency.unknown_id)
|
|
)
|
|
continue;
|
|
relevantIds.add(dependency.unknown_id);
|
|
pending.push(dependency.unknown_id);
|
|
}
|
|
}
|
|
return [...relevantIds]
|
|
.flatMap((id) => {
|
|
const unknown = heads.get(id);
|
|
return unknown === undefined ? [] : [unknown];
|
|
})
|
|
.sort((left, right) =>
|
|
compareUnicodeCodePoints(left.unknown_id, right.unknown_id),
|
|
);
|
|
};
|
|
|
|
/** Aggregate deterministic probes for unresolved claims. */
|
|
export const reconstructionProbes = (
|
|
results: readonly ReconstructionClaimResult[],
|
|
heads: ReadonlyMap<string, ResidualUnknown>,
|
|
): ReconstructionVerificationResult["recommended_probes"] => {
|
|
const output = new Map<
|
|
string,
|
|
{
|
|
operation: string;
|
|
rationale: string;
|
|
claim_ids: string[];
|
|
unknown_ids: string[];
|
|
}
|
|
>();
|
|
for (const result of results.filter(({ status }) => status === "unknown")) {
|
|
const unknowns = result.unknown_ids.flatMap((id) => {
|
|
const item = heads.get(id);
|
|
return item === undefined ? [] : [item];
|
|
});
|
|
const probes = unknowns.flatMap(({ recommended_probes: items }) => items);
|
|
const candidates = probes.length > 0 ? probes : [defaultProbe(result.kind)];
|
|
for (const probe of candidates) {
|
|
const key = compositeKey([probe.operation, probe.rationale]);
|
|
const current = output.get(key) ?? {
|
|
...probe,
|
|
claim_ids: [],
|
|
unknown_ids: [],
|
|
};
|
|
current.claim_ids = uniqueSorted([...current.claim_ids, result.claim_id]);
|
|
current.unknown_ids = uniqueSorted([
|
|
...current.unknown_ids,
|
|
...result.unknown_ids,
|
|
]);
|
|
output.set(key, current);
|
|
}
|
|
}
|
|
const sorted = [...output.values()].sort((left, right) =>
|
|
compareUnicodeCodePoints(
|
|
compositeKey([left.operation, left.rationale]),
|
|
compositeKey([right.operation, right.rationale]),
|
|
),
|
|
);
|
|
return sorted;
|
|
};
|
|
|
|
const defaultProbe = (
|
|
kind: ReconstructionClaim["kind"],
|
|
): { operation: string; rationale: string } =>
|
|
kind === "behavioral"
|
|
? {
|
|
operation: "capture_process_scenario",
|
|
rationale: "Repeat both scenarios under one controlled environment.",
|
|
}
|
|
: kind === "structural-function"
|
|
? {
|
|
operation: "analyze_function",
|
|
rationale: "Capture complete function dossiers under equal limits.",
|
|
}
|
|
: {
|
|
operation: "inspect_artifact",
|
|
rationale:
|
|
"Capture complete artifact inventories under equal limits.",
|
|
};
|