fix(analysis): preserve relationship coverage across evidence and replay

Separate observed relationship coverage from general provider caveats. Authenticate and replay coverage without changing legacy Evidence IDs; expose unknown and capped relationship sets through CLI/MCP graphs and traces.

Validated focused domain, snapshot, IDA/Ghidra boundary, MCP, schema, package and static checks. Provider fixtures establish contract behavior; licensed engine behavior was not reverified.
This commit is contained in:
morluto
2026-10-12 05:57:35 +08:00
parent f1924cf9c1
commit 9c8511409c
24 changed files with 469 additions and 55 deletions
+31 -14
View File
@@ -42,6 +42,10 @@ import { prefixedDigestSchema } from "./../domain/digests.js";
import { canonicalJsonDigestSteps } from "./canonicalJsonDigestSteps.js";
import { freezeJsonSnapshot } from "./immutableJson.js";
import { rawBinaryEntryPointSchema } from "./rawBinary.js";
import {
relationshipCoverageSchema,
type RelationshipCoverage,
} from "./relationshipCoverage.js";
const architectureSchema = z.enum(BINARY_ARCHITECTURES);
const formatSchema = z.enum([
@@ -125,6 +129,7 @@ const entrySchema = z.object({
raw_result: jsonValueSchema.nullable(),
provider: committedProviderSchema,
limitations: z.array(z.string()),
relationship_coverage: relationshipCoverageSchema.nullable().default(null),
locations: z.array(evidenceLocationSchema),
subject: subjectSchema.nullable(),
}),
@@ -139,6 +144,7 @@ const workflowEntrySchema = z.object({
provider: committedProviderSchema,
analysis_profile: analysisProfileSchema,
limitations: z.array(z.string()),
relationship_coverage: relationshipCoverageSchema.nullable().default(null),
locations: z.array(evidenceLocationSchema),
subject: subjectSchema.nullable(),
}),
@@ -268,7 +274,7 @@ const snapshotContentDigest = (
rawResult: JsonValue | null,
execution: Pick<
AnalysisSnapshotEntry["execution"],
"limitations" | "locations" | "subject"
"limitations" | "locations" | "subject" | "relationship_coverage"
>,
): string => {
const metadata = jsonObjectSchema.parse({
@@ -283,6 +289,9 @@ const snapshotContentDigest = (
format: execution.subject.format,
architecture: execution.subject.architecture,
},
...(execution.relationship_coverage === null
? {}
: { relationship_coverage: execution.relationship_coverage }),
});
return contentDigest({
...metadata,
@@ -309,6 +318,7 @@ interface SnapshotExecution {
};
readonly analysisProfile?: AnalysisProfileCommitment;
readonly limitations: readonly string[];
readonly relationshipCoverage?: RelationshipCoverage | null | undefined;
readonly locations: readonly EvidenceLocation[];
readonly subject: EvidenceSubjectTarget | null;
}
@@ -460,6 +470,7 @@ export const createAnalysisSnapshotWorkflowEntry = (input: {
provider: execution.analysisProfile.provider,
analysis_profile: execution.analysisProfile,
limitations: [...execution.limitations],
relationship_coverage: execution.relationshipCoverage ?? null,
locations: [...execution.locations],
subject:
execution.subject === null
@@ -522,6 +533,7 @@ export const createAnalysisSnapshotEntry = (input: {
raw_result: execution.rawResult,
provider: binding.provider,
limitations: [...execution.limitations],
relationship_coverage: execution.relationshipCoverage ?? null,
locations: [...execution.locations],
subject:
execution.subject === null
@@ -838,19 +850,24 @@ const evidenceMatchesWorkflowEntry = (
evidenceContentDigest(evidence),
]) === workflowEntryEvidenceKey(entry);
const evidenceContentMetadata = (evidence: Evidence) => ({
limitations: evidence.limitations,
locations: evidence.locations,
subject:
evidence.subject === null
? null
: {
local_path: evidence.subject.local_path,
sha256: evidence.subject.digest.sha256,
format: evidence.subject.format,
architecture: evidence.subject.architecture,
},
});
const evidenceContentMetadata = (evidence: Evidence) => {
return {
limitations: evidence.limitations,
...(evidence.relationship_coverage === null
? {}
: { relationship_coverage: evidence.relationship_coverage }),
locations: evidence.locations,
subject:
evidence.subject === null
? null
: {
local_path: evidence.subject.local_path,
sha256: evidence.subject.digest.sha256,
format: evidence.subject.format,
architecture: evidence.subject.architecture,
},
};
};
/** Serialize a validated snapshot with byte-stable canonical entry ordering. */
export const serializeAnalysisSnapshot = (snapshot: AnalysisSnapshot): string =>