feat(android): add opt-in package summaries and retained manifest views
Add explicit package summary delivery and exact retained manifest pages while preserving complete MCP defaults, one-shot CLI output, provider requests, source identity and session lifetime. Return distinct linked Evidence and preserve partial/null facts; reject unavailable retention before engine work. Validation: 27 relevant SDK/domain/Android boundary checks, focused test-only correction rerun, full supported compiler/lint and docs checks, real NewPipe SDK pairs, authentic old Evidence continuation, four actual Codex trials with failures/regressions retained, and all 39 exact-head CI checks. Package replies shrink 119,527 to 8,659 bytes; no model-token or time gain is established. 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
ca2d15b3ee
commit
f254f5ac2b
@@ -56,6 +56,12 @@ import {
|
||||
wasmSummarySchema,
|
||||
} from "./wasmArtifactView.js";
|
||||
import type { WebNetworkApiSurfaceAccumulator } from "./WebNetworkApiSurfaceAccumulator.js";
|
||||
import {
|
||||
projectAndroidPackageView,
|
||||
androidPackageSummarySchema,
|
||||
androidViewRequestSchema,
|
||||
androidManifestViewItemSchema,
|
||||
} from "./androidPackageView.js";
|
||||
|
||||
/** Public name of the selected-view workflow. */
|
||||
export const INSPECT_ANALYSIS_VIEW_OPERATION = "inspect_analysis_view" as const;
|
||||
@@ -169,6 +175,7 @@ export const analysisViewRequestSchema = z.discriminatedUnion("kind", [
|
||||
wasmViewRequestSchema,
|
||||
evmViewRequestSchema,
|
||||
managedViewRequestSchema,
|
||||
androidViewRequestSchema,
|
||||
apiSurfaceViewSchema,
|
||||
]);
|
||||
|
||||
@@ -283,6 +290,7 @@ const viewResultBase = {
|
||||
"inspect_wasm_artifact",
|
||||
"inspect_evm_interface",
|
||||
"inspect_managed_artifact",
|
||||
"inspect_android_package",
|
||||
]),
|
||||
parent_digest: digestSchema,
|
||||
view_digest: digestSchema,
|
||||
@@ -340,6 +348,13 @@ export const managedArtifactSummaryViewResultSchema = z.strictObject({
|
||||
summary: managedSummarySchema,
|
||||
});
|
||||
|
||||
/** Exact package declarations with retained decoded manifest text. */
|
||||
export const androidPackageSummaryViewResultSchema = z.strictObject({
|
||||
...summaryViewResultBase,
|
||||
parent_operation: z.literal("inspect_android_package"),
|
||||
summary: androidPackageSummarySchema,
|
||||
});
|
||||
|
||||
/** Projected facts for one selected view of retained analysis Evidence. */
|
||||
export const analysisViewResultSchema = z.discriminatedUnion("kind", [
|
||||
z.strictObject({
|
||||
@@ -362,6 +377,7 @@ export const analysisViewResultSchema = z.discriminatedUnion("kind", [
|
||||
wasmSummarySchema,
|
||||
evmSummarySchema,
|
||||
managedSummarySchema,
|
||||
androidPackageSummarySchema,
|
||||
]),
|
||||
}),
|
||||
z.strictObject({
|
||||
@@ -410,6 +426,13 @@ export const analysisViewResultSchema = z.discriminatedUnion("kind", [
|
||||
...managedViewContextSchema.shape,
|
||||
parent_operation: z.literal("inspect_managed_artifact"),
|
||||
}),
|
||||
z.strictObject({
|
||||
kind: z.literal("android"),
|
||||
view: androidViewRequestSchema,
|
||||
item: androidManifestViewItemSchema,
|
||||
...viewResultBase,
|
||||
parent_operation: z.literal("inspect_android_package"),
|
||||
}),
|
||||
z.strictObject({
|
||||
kind: z.literal("inventory"),
|
||||
view: inventoryViewSchema,
|
||||
@@ -480,6 +503,10 @@ export type UnsignedAnalysisView =
|
||||
| Omit<
|
||||
Extract<AnalysisViewResult, { readonly kind: "managed" }>,
|
||||
"view_digest"
|
||||
>
|
||||
| Omit<
|
||||
Extract<AnalysisViewResult, { readonly kind: "android" }>,
|
||||
"view_digest"
|
||||
>;
|
||||
|
||||
/** Attach the content digest that must change when projected bytes change. */
|
||||
@@ -525,7 +552,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, EVM, managed artifact, 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, Android package, or web network capture Evidence.`,
|
||||
);
|
||||
|
||||
const parentArtifactPath = (parent: AnalysisViewParent): string => {
|
||||
@@ -554,6 +581,7 @@ const retainedViewProjectors = new Map<string, typeof projectWasmArtifactView>([
|
||||
["inspect_wasm_artifact", projectWasmArtifactView],
|
||||
["inspect_evm_interface", projectEvmInterfaceView],
|
||||
["inspect_managed_artifact", projectManagedArtifactView],
|
||||
["inspect_android_package", projectAndroidPackageView],
|
||||
["inspect_artifact", projectArtifactInventoryView],
|
||||
["inventory_artifact", projectArtifactInventoryView],
|
||||
]);
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
import { z } from "zod";
|
||||
import type { AnalysisError } from "../analysisErrorBase.js";
|
||||
import { androidResultSchemas } from "../android/androidAnalysis.js";
|
||||
import { analysisInputErrorFromIssues } from "../inputIssueProjection.js";
|
||||
import { err, ok, type Result } from "../result.js";
|
||||
import {
|
||||
analysisViewInputError,
|
||||
type AnalysisViewParent,
|
||||
type AnalysisViewRequest,
|
||||
type UnsignedAnalysisView,
|
||||
} from "./analysisView.js";
|
||||
import { completeWithinViewCoverage } from "./analysisViewCoverage.js";
|
||||
import { analysisTextPage } from "./analysisViewText.js";
|
||||
|
||||
const packageSchema = androidResultSchemas.inspect_android_package;
|
||||
|
||||
/** All package declarations remain inline; decoded manifest text stays retained. */
|
||||
export const androidPackageSummarySchema = packageSchema.extend({
|
||||
manifest: packageSchema.shape.manifest.omit({ text: true }).extend({
|
||||
text_code_units: z.number().int().nonnegative(),
|
||||
text_included: z.literal(false),
|
||||
}),
|
||||
});
|
||||
|
||||
/** Exact decoded text; offsets and limits count UTF-16 code units. */
|
||||
export const androidViewRequestSchema = z.strictObject({
|
||||
kind: z.literal("android"),
|
||||
facet: z.literal("manifest"),
|
||||
offset: z.number().int().nonnegative().default(0),
|
||||
limit: z.number().int().positive(),
|
||||
});
|
||||
|
||||
export const androidManifestViewItemSchema = z.strictObject({
|
||||
text: z.string(),
|
||||
unit: z.literal("utf16-code-units"),
|
||||
source_status: packageSchema.shape.manifest.shape.status,
|
||||
reported_total_bytes: packageSchema.shape.manifest.shape.reported_total_bytes,
|
||||
});
|
||||
|
||||
/** Project an authenticated package record without reopening the APK or engine. */
|
||||
export const projectAndroidPackageView = (
|
||||
parent: AnalysisViewParent,
|
||||
view: AnalysisViewRequest,
|
||||
): Result<UnsignedAnalysisView, AnalysisError> => {
|
||||
if (view.kind !== "summary" && view.kind !== "android")
|
||||
return err(
|
||||
analysisViewInputError([
|
||||
{
|
||||
path: ["view"],
|
||||
reason: "invalid_value",
|
||||
message:
|
||||
"Android package Evidence supports summary and manifest views.",
|
||||
},
|
||||
]),
|
||||
);
|
||||
const parsed = packageSchema.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 },
|
||||
),
|
||||
);
|
||||
// Engine artifact_sha256 identifies the JAR, never the APK. A missing
|
||||
// authenticated APK subject cannot be repaired using the engine identity.
|
||||
if (parent.subject == null)
|
||||
return err(
|
||||
analysisViewInputError([
|
||||
{
|
||||
path: ["source", "subject"],
|
||||
reason: "invalid_value",
|
||||
message:
|
||||
"Android package views require the recorded APK subject identity.",
|
||||
},
|
||||
]),
|
||||
);
|
||||
const report = parsed.data;
|
||||
const shared = {
|
||||
parent_evidence_id: parent.evidenceId,
|
||||
parent_operation: "inspect_android_package" as const,
|
||||
parent_digest: parent.evidenceId.slice(3),
|
||||
artifact: {
|
||||
path: parent.subject.local_path,
|
||||
sha256: parent.subject.digest.sha256,
|
||||
},
|
||||
limitations: [...parent.limitations],
|
||||
unknowns: [
|
||||
"APK signatures were not verified; package declarations do not establish authenticity or runtime behavior.",
|
||||
...(report.manifest.status === "partial"
|
||||
? [
|
||||
"The decoded manifest is partial; exhausting retained text does not establish complete manifest coverage.",
|
||||
]
|
||||
: []),
|
||||
],
|
||||
};
|
||||
if (view.kind === "summary") {
|
||||
const { text, ...manifest } = report.manifest;
|
||||
return ok({
|
||||
kind: "summary",
|
||||
view,
|
||||
...shared,
|
||||
summary: {
|
||||
...report,
|
||||
manifest: {
|
||||
...manifest,
|
||||
text_code_units: text.length,
|
||||
text_included: false,
|
||||
},
|
||||
},
|
||||
coverage: completeWithinViewCoverage(1, 1),
|
||||
});
|
||||
}
|
||||
const page = analysisTextPage(
|
||||
report.manifest.text,
|
||||
view.offset,
|
||||
view.limit,
|
||||
"Manifest",
|
||||
);
|
||||
if (!page.ok) return page;
|
||||
return ok({
|
||||
kind: "android",
|
||||
view,
|
||||
...shared,
|
||||
item: {
|
||||
...page.value.item,
|
||||
source_status: report.manifest.status,
|
||||
reported_total_bytes: report.manifest.reported_total_bytes,
|
||||
},
|
||||
coverage: page.value.coverage,
|
||||
});
|
||||
};
|
||||
@@ -314,7 +314,7 @@ export const projectJavaScriptApplicationView = (
|
||||
...shared,
|
||||
});
|
||||
}
|
||||
if (view.collection !== "modules")
|
||||
if (view.kind !== "page" || view.collection !== "modules")
|
||||
return err(
|
||||
jsIncompatible(
|
||||
"Section and symbol collections apply to inspect_binary_layout Evidence.",
|
||||
|
||||
Reference in New Issue
Block a user