feat(managed): add retained metadata overview and pages (#2413)
Add caller-selected managed metadata summaries and original collection pages while preserving complete CLI/MCP defaults and previous-runtime Evidence. Real SDK replies shrink substantially; actual Codex token/latency results remain mixed and are documented without a token-saving claim. Validated focused SDK/domain tests, full static/docs checks, real two-assembly repeated workflows and portable old Evidence, real SQLite WASM, and all exact-head CI checks. Raw experimental artifacts remain private. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
parent
f43fc02475
commit
82cfcee19f
@@ -733,6 +733,14 @@ it("does not match unavailable layout names using a display placeholder", () =>
|
||||
});
|
||||
|
||||
it("rejects unsupported parent operations and incompatible collections", () => {
|
||||
expect(
|
||||
projectAnalysisView(layoutParent(), {
|
||||
kind: "managed",
|
||||
collection: "attributes",
|
||||
offset: 0,
|
||||
limit: 1,
|
||||
}),
|
||||
).toMatchObject({ ok: false, error: { _tag: "AnalysisInputError" } });
|
||||
const unsupported = projectAnalysisView(
|
||||
{
|
||||
evidenceId: `ev_${"d".repeat(64)}`,
|
||||
|
||||
@@ -42,6 +42,13 @@ import {
|
||||
evmSummarySchema,
|
||||
} from "./evmInterfaceView.js";
|
||||
import { projectArtifactInventoryView } from "./artifactInventoryView.js";
|
||||
import {
|
||||
projectManagedArtifactView,
|
||||
managedViewRequestSchema,
|
||||
managedViewItemSchema,
|
||||
managedSummarySchema,
|
||||
managedViewContextSchema,
|
||||
} from "./managedArtifactView.js";
|
||||
import {
|
||||
projectWasmArtifactView,
|
||||
wasmViewRequestSchema,
|
||||
@@ -161,6 +168,7 @@ export const analysisViewRequestSchema = z.discriminatedUnion("kind", [
|
||||
inventoryViewSchema,
|
||||
wasmViewRequestSchema,
|
||||
evmViewRequestSchema,
|
||||
managedViewRequestSchema,
|
||||
apiSurfaceViewSchema,
|
||||
]);
|
||||
|
||||
@@ -274,6 +282,7 @@ const viewResultBase = {
|
||||
"inventory_artifact",
|
||||
"inspect_wasm_artifact",
|
||||
"inspect_evm_interface",
|
||||
"inspect_managed_artifact",
|
||||
]),
|
||||
parent_digest: digestSchema,
|
||||
view_digest: digestSchema,
|
||||
@@ -324,6 +333,13 @@ export const evmInterfaceSummaryViewResultSchema = z.strictObject({
|
||||
summary: evmSummarySchema,
|
||||
});
|
||||
|
||||
/** Exact metadata overview for the managed artifact's selected delivery. */
|
||||
export const managedArtifactSummaryViewResultSchema = z.strictObject({
|
||||
...summaryViewResultBase,
|
||||
parent_operation: z.literal("inspect_managed_artifact"),
|
||||
summary: managedSummarySchema,
|
||||
});
|
||||
|
||||
/** Projected facts for one selected view of retained analysis Evidence. */
|
||||
export const analysisViewResultSchema = z.discriminatedUnion("kind", [
|
||||
z.strictObject({
|
||||
@@ -345,6 +361,7 @@ export const analysisViewResultSchema = z.discriminatedUnion("kind", [
|
||||
inventorySummarySchema,
|
||||
wasmSummarySchema,
|
||||
evmSummarySchema,
|
||||
managedSummarySchema,
|
||||
]),
|
||||
}),
|
||||
z.strictObject({
|
||||
@@ -385,6 +402,14 @@ export const analysisViewResultSchema = z.discriminatedUnion("kind", [
|
||||
...viewResultBase,
|
||||
parent_operation: z.literal("inspect_evm_interface"),
|
||||
}),
|
||||
z.strictObject({
|
||||
kind: z.literal("managed"),
|
||||
view: managedViewRequestSchema,
|
||||
item: managedViewItemSchema,
|
||||
...viewResultBase,
|
||||
...managedViewContextSchema.shape,
|
||||
parent_operation: z.literal("inspect_managed_artifact"),
|
||||
}),
|
||||
z.strictObject({
|
||||
kind: z.literal("inventory"),
|
||||
view: inventoryViewSchema,
|
||||
@@ -451,7 +476,11 @@ export type UnsignedAnalysisView =
|
||||
"view_digest"
|
||||
>
|
||||
| Omit<Extract<AnalysisViewResult, { readonly kind: "wasm" }>, "view_digest">
|
||||
| Omit<Extract<AnalysisViewResult, { readonly kind: "evm" }>, "view_digest">;
|
||||
| Omit<Extract<AnalysisViewResult, { readonly kind: "evm" }>, "view_digest">
|
||||
| Omit<
|
||||
Extract<AnalysisViewResult, { readonly kind: "managed" }>,
|
||||
"view_digest"
|
||||
>;
|
||||
|
||||
/** Attach the content digest that must change when projected bytes change. */
|
||||
export const sealAnalysisView = (
|
||||
@@ -496,7 +525,7 @@ const unsupportedParent = (
|
||||
new AnalysisUnsupportedTargetError(
|
||||
INSPECT_ANALYSIS_VIEW_OPERATION,
|
||||
parentArtifactPath(parent),
|
||||
`Parent Evidence operation ${JSON.stringify(parent.operation)} does not support analysis views. Use completed binary layout, JavaScript application, native function, artifact inventory/inspection, WASM, or web network capture Evidence.`,
|
||||
`Parent Evidence operation ${JSON.stringify(parent.operation)} does not support analysis views. Use completed binary layout, JavaScript application, native function, artifact inventory/inspection, WASM, EVM, managed artifact, or web network capture Evidence.`,
|
||||
);
|
||||
|
||||
const parentArtifactPath = (parent: AnalysisViewParent): string => {
|
||||
@@ -520,6 +549,15 @@ const parentArtifactPath = (parent: AnalysisViewParent): string => {
|
||||
return parent.evidenceId;
|
||||
};
|
||||
|
||||
/** Named source owners for views that need no extra decoder or accumulator. */
|
||||
const retainedViewProjectors = new Map<string, typeof projectWasmArtifactView>([
|
||||
["inspect_wasm_artifact", projectWasmArtifactView],
|
||||
["inspect_evm_interface", projectEvmInterfaceView],
|
||||
["inspect_managed_artifact", projectManagedArtifactView],
|
||||
["inspect_artifact", projectArtifactInventoryView],
|
||||
["inventory_artifact", projectArtifactInventoryView],
|
||||
]);
|
||||
|
||||
/** Project one selected view from authenticated parent analysis Evidence. */
|
||||
export const projectAnalysisView = (
|
||||
parent: AnalysisViewParent,
|
||||
@@ -591,19 +629,9 @@ export const projectAnalysisView = (
|
||||
const projected = projectNativeFunctionView(parent, native.data, view);
|
||||
return projected.ok ? ok(sealAnalysisView(projected.value)) : projected;
|
||||
}
|
||||
if (parent.operation === "inspect_wasm_artifact") {
|
||||
const projected = projectWasmArtifactView(parent, view);
|
||||
return projected.ok ? ok(sealAnalysisView(projected.value)) : projected;
|
||||
}
|
||||
if (parent.operation === "inspect_evm_interface") {
|
||||
const projected = projectEvmInterfaceView(parent, view);
|
||||
return projected.ok ? ok(sealAnalysisView(projected.value)) : projected;
|
||||
}
|
||||
if (
|
||||
parent.operation === "inspect_artifact" ||
|
||||
parent.operation === "inventory_artifact"
|
||||
) {
|
||||
const projected = projectArtifactInventoryView(parent, view);
|
||||
const project = retainedViewProjectors.get(parent.operation);
|
||||
if (project !== undefined) {
|
||||
const projected = project(parent, view);
|
||||
return projected.ok ? ok(sealAnalysisView(projected.value)) : projected;
|
||||
}
|
||||
return err(unsupportedParent(parent));
|
||||
|
||||
@@ -218,6 +218,12 @@ export const projectBinaryLayoutView = (
|
||||
...shared,
|
||||
});
|
||||
}
|
||||
if (view.kind !== "page")
|
||||
return err(
|
||||
layoutIncompatible(
|
||||
"Layout views require summary, facet, item or page selections.",
|
||||
),
|
||||
);
|
||||
if (view.collection === "modules")
|
||||
return err(
|
||||
layoutIncompatible(
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
import { z } from "zod";
|
||||
import type { AnalysisError } from "../analysisErrorBase.js";
|
||||
import { uniqueSorted } from "../canonicalOrdering.js";
|
||||
import { analysisInputErrorFromIssues } from "../inputIssueProjection.js";
|
||||
import {
|
||||
managedArtifactInspectionSchema,
|
||||
managedMemberInspectionSchema,
|
||||
} from "../managed/managedArtifact.js";
|
||||
import { err, ok, type Result } from "../result.js";
|
||||
import {
|
||||
analysisViewInputError,
|
||||
type AnalysisViewParent,
|
||||
type AnalysisViewRequest,
|
||||
type UnsignedAnalysisView,
|
||||
} from "./analysisView.js";
|
||||
import {
|
||||
completeWithinViewCoverage,
|
||||
pageViewCoverage,
|
||||
} from "./analysisViewCoverage.js";
|
||||
|
||||
/** Original metadata rows; offsets count entries in the returned parent collection. */
|
||||
export const managedViewRequestSchema = z.strictObject({
|
||||
kind: z.literal("managed"),
|
||||
collection: z.enum(["references", "resources", "attributes"]),
|
||||
offset: z.number().int().nonnegative().default(0),
|
||||
limit: z.number().int().positive().default(64),
|
||||
});
|
||||
|
||||
export const managedViewItemSchema = z.union([
|
||||
managedArtifactInspectionSchema.shape.references,
|
||||
managedArtifactInspectionSchema.shape.resources,
|
||||
managedArtifactInspectionSchema.shape.attributes,
|
||||
]);
|
||||
|
||||
/** Keep complete classification and coverage; unrequested inventories remain retained. */
|
||||
export const managedSummarySchema = managedArtifactInspectionSchema
|
||||
.omit({ references: true, resources: true, attributes: true })
|
||||
.extend({
|
||||
reported_counts: z.strictObject({
|
||||
references: z.number().int().nonnegative(),
|
||||
resources: z.number().int().nonnegative(),
|
||||
attributes: z.number().int().nonnegative(),
|
||||
}),
|
||||
identity_scope: managedMemberInspectionSchema.shape.identity_scope,
|
||||
});
|
||||
|
||||
export const managedViewContextSchema = z.strictObject({
|
||||
identity_scope: managedMemberInspectionSchema.shape.identity_scope,
|
||||
source_metadata_status:
|
||||
managedArtifactInspectionSchema.shape.metadata.shape.status,
|
||||
source_coverage: managedArtifactInspectionSchema.shape.coverage,
|
||||
});
|
||||
|
||||
/** Project authenticated metadata without reading a path or invoking a provider. */
|
||||
export const projectManagedArtifactView = (
|
||||
parent: AnalysisViewParent,
|
||||
view: AnalysisViewRequest,
|
||||
): Result<UnsignedAnalysisView, AnalysisError> => {
|
||||
if (view.kind !== "summary" && view.kind !== "managed")
|
||||
return err(
|
||||
analysisViewInputError([
|
||||
{
|
||||
path: ["view"],
|
||||
reason: "invalid_value",
|
||||
message:
|
||||
"Managed artifact inspection supports summary and managed views.",
|
||||
},
|
||||
]),
|
||||
);
|
||||
const parsed = managedArtifactInspectionSchema.safeParse(
|
||||
parent.normalizedResult,
|
||||
);
|
||||
if (!parsed.success)
|
||||
return err(
|
||||
analysisInputErrorFromIssues(
|
||||
"inspect_analysis_view",
|
||||
parsed.error.issues.map((issue) => ({
|
||||
...issue,
|
||||
path: ["source", "normalized_result", ...issue.path],
|
||||
})),
|
||||
{ source: { normalized_result: parent.normalizedResult } },
|
||||
{ cause: parsed.error },
|
||||
),
|
||||
);
|
||||
const report = parsed.data;
|
||||
const identity_scope = {
|
||||
token_identity: "build-local" as const,
|
||||
requires_artifact_sha256: report.artifact.sha256,
|
||||
requires_mvid: report.module?.mvid ?? null,
|
||||
};
|
||||
const shared = {
|
||||
parent_evidence_id: parent.evidenceId,
|
||||
parent_operation: "inspect_managed_artifact" as const,
|
||||
parent_digest: parent.evidenceId.slice(3),
|
||||
artifact: { path: report.artifact.path, sha256: report.artifact.sha256 },
|
||||
limitations: uniqueSorted([...parent.limitations, ...report.limitations]),
|
||||
unknowns: [
|
||||
"Collection counts and pages cover producer-returned rows; metadata completeness remains the original metadata status and coverage, not an absence claim about unreturned rows.",
|
||||
"Metadata tokens are build-local coordinates bound to the recorded artifact SHA-256 and module MVID; this view does not load or execute the assembly.",
|
||||
...(parent.subject == null
|
||||
? [
|
||||
"The parent has no recorded subject; its normalized artifact identity cannot be cross-checked against a subject digest.",
|
||||
]
|
||||
: []),
|
||||
...(identity_scope.requires_mvid === null
|
||||
? [
|
||||
"The module MVID is unknown; tokens cannot establish a cross-observation module match.",
|
||||
]
|
||||
: []),
|
||||
],
|
||||
};
|
||||
if (view.kind === "summary") {
|
||||
const { references, resources, attributes, ...summary } = report;
|
||||
const reported_counts = {
|
||||
references: references.length,
|
||||
resources: resources.length,
|
||||
attributes: attributes.length,
|
||||
};
|
||||
const total = references.length + resources.length + attributes.length;
|
||||
return ok({
|
||||
kind: "summary",
|
||||
view,
|
||||
...shared,
|
||||
summary: { ...summary, reported_counts, identity_scope },
|
||||
coverage: completeWithinViewCoverage(total, total),
|
||||
});
|
||||
}
|
||||
const collection = report[view.collection];
|
||||
const item = collection.slice(view.offset, view.offset + view.limit);
|
||||
return ok({
|
||||
kind: "managed",
|
||||
view,
|
||||
item,
|
||||
...shared,
|
||||
identity_scope,
|
||||
source_metadata_status: report.metadata.status,
|
||||
source_coverage: report.coverage,
|
||||
coverage: pageViewCoverage(view.offset, item.length, collection.length),
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user