feat(application): wire Android and Apple inventory graph tools (#852)
* feat(application): wire Android and Apple inventory graph tools
Expose project_android_application_graph and project_apple_application_graph
through CLI and MCP so authenticated inventory Evidence can be projected
without a provider launch.
* fix(application): use producer root occurrence IDs in graph examples
Catalog examples constructed root occurrence IDs from artifact_id +
logical_path, but inventory validation authenticates "." with
{ root: root_artifact_id }. Align the examples and regenerate catalogs
after rebasing onto main (application family count 11).
---------
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { reconstructionCoverageEvaluationInputSchema } from "../domain/reconstructionCoverageInput.js";
|
||||
import { Cli, z } from "incur";
|
||||
|
||||
import { projectAndroidApplicationEvidence } from "../application/AndroidApplicationService.js";
|
||||
import { projectAppleApplicationEvidence } from "../application/AppleApplicationService.js";
|
||||
import {
|
||||
compareApplicationVersionsEvidenceValidated,
|
||||
compareJavaScriptExportShapesEvidenceValidated,
|
||||
@@ -16,6 +18,8 @@ import { logCliCommand } from "../cliLogging.js";
|
||||
import { AnalysisInputError } from "../domain/analysisErrorCore.js";
|
||||
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
||||
import { type AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import { androidApplicationProjectionInputSchema } from "../domain/androidApplication.js";
|
||||
import { appleApplicationProjectionInputSchema } from "../domain/appleApplication.js";
|
||||
import { jsonValueSchema, type JsonValue } from "../domain/jsonValue.js";
|
||||
import type { Logger } from "../logger.js";
|
||||
import { traceApplicationFeatureInputSchema } from "../domain/javascriptFeatureTraceSchemas.js";
|
||||
@@ -80,6 +84,34 @@ export const registerApplicationCommands = (
|
||||
});
|
||||
registerObligationLedgerCommand(cli, logger);
|
||||
registerCoverageCommand(cli, logger);
|
||||
registerJsonCommand({
|
||||
cli,
|
||||
logger,
|
||||
name: CLI_COMMANDS.projectAndroidApplicationGraph,
|
||||
description:
|
||||
"Project authenticated APK inventory Evidence into an Android application graph",
|
||||
inputSchema: androidApplicationProjectionInputSchema,
|
||||
workflow: (input) => {
|
||||
const result = projectAndroidApplicationEvidence(input);
|
||||
return result.ok
|
||||
? { ok: true, value: jsonValueSchema.parse(result.value) }
|
||||
: result;
|
||||
},
|
||||
});
|
||||
registerJsonCommand({
|
||||
cli,
|
||||
logger,
|
||||
name: CLI_COMMANDS.projectAppleApplicationGraph,
|
||||
description:
|
||||
"Project authenticated IPA inventory Evidence into an Apple application graph",
|
||||
inputSchema: appleApplicationProjectionInputSchema,
|
||||
workflow: (input) => {
|
||||
const result = projectAppleApplicationEvidence(input);
|
||||
return result.ok
|
||||
? { ok: true, value: jsonValueSchema.parse(result.value) }
|
||||
: result;
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const registerObligationLedgerCommand = (
|
||||
|
||||
@@ -82,6 +82,8 @@ export const CLI_COMMANDS = Object.freeze({
|
||||
compareJavaScriptExportShapes: "compare-javascript-export-shapes",
|
||||
buildReconstructionObligationLedger: "build-reconstruction-obligation-ledger",
|
||||
evaluateReconstructionCoverage: "evaluate-reconstruction-coverage",
|
||||
projectAndroidApplicationGraph: "project-android-application-graph",
|
||||
projectAppleApplicationGraph: "project-apple-application-graph",
|
||||
});
|
||||
|
||||
/** Ordered primary CLI inventory; aliases are intentionally excluded. */
|
||||
|
||||
@@ -16,6 +16,14 @@ import {
|
||||
reconstructionObligationLedgerInputSchema,
|
||||
reconstructionObligationLedgerSchema,
|
||||
} from "../domain/reconstructionObligationLedgerSchemas.js";
|
||||
import {
|
||||
androidApplicationProjectionInputSchema,
|
||||
androidApplicationProjectionResultSchema,
|
||||
} from "../domain/androidApplication.js";
|
||||
import {
|
||||
appleApplicationProjectionInputSchema,
|
||||
appleApplicationProjectionResultSchema,
|
||||
} from "../domain/appleApplication.js";
|
||||
import type { ToolContract } from "./toolContracts.js";
|
||||
import { toolContractMetadata } from "./toolEffects.js";
|
||||
import { evidenceResultOf } from "./toolOutputSchemas.js";
|
||||
@@ -25,6 +33,10 @@ import {
|
||||
JAVASCRIPT_FEATURE_TRACE_EXAMPLE,
|
||||
SOURCE_TO_BUNDLE_COMPARISON_EXAMPLE,
|
||||
} from "./javascriptApplicationWorkflowExamples.js";
|
||||
import {
|
||||
ANDROID_APPLICATION_GRAPH_EXAMPLE,
|
||||
APPLE_APPLICATION_GRAPH_EXAMPLE,
|
||||
} from "./mobileApplicationGraphExamples.js";
|
||||
|
||||
const traceOutputSchema = evidenceResultOf(applicationFeatureTraceResultSchema);
|
||||
const semanticTraceOutputSchema = evidenceResultOf(
|
||||
@@ -246,6 +258,37 @@ export const APPLICATION_TOOL_CONTRACTS = [
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "project_android_application_graph",
|
||||
...toolContractMetadata("project_android_application_graph"),
|
||||
description:
|
||||
"Project authenticated APK inventory_artifact Evidence into an execution-free Android application inventory. Reports exact component paths and hashes, runtime-family hints, and path-based bridge hypotheses without decoding DEX, executing the APK, or claiming observed runtime calls.",
|
||||
kind: "application",
|
||||
inputSchema: androidApplicationProjectionInputSchema,
|
||||
outputSchema: evidenceResultOf(androidApplicationProjectionResultSchema),
|
||||
examples: [
|
||||
{
|
||||
title:
|
||||
"Project APK inventory Evidence into an Android application graph",
|
||||
input: ANDROID_APPLICATION_GRAPH_EXAMPLE,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "project_apple_application_graph",
|
||||
...toolContractMetadata("project_apple_application_graph"),
|
||||
description:
|
||||
"Project authenticated IPA inventory_artifact Evidence into an execution-free Apple application inventory. Reports exact component paths and hashes, runtime-family hints, and path-based bridge hypotheses without parsing plist/CMS semantics or claiming observed runtime calls.",
|
||||
kind: "application",
|
||||
inputSchema: appleApplicationProjectionInputSchema,
|
||||
outputSchema: evidenceResultOf(appleApplicationProjectionResultSchema),
|
||||
examples: [
|
||||
{
|
||||
title: "Project IPA inventory Evidence into an Apple application graph",
|
||||
input: APPLE_APPLICATION_GRAPH_EXAMPLE,
|
||||
},
|
||||
],
|
||||
},
|
||||
] as const satisfies readonly ToolContract[];
|
||||
|
||||
/** Resolve one named application contract without relying on array position. */
|
||||
@@ -270,6 +313,12 @@ export function applicationToolContract(
|
||||
export function applicationToolContract(
|
||||
name: "evaluate_reconstruction_coverage",
|
||||
): (typeof APPLICATION_TOOL_CONTRACTS)[6];
|
||||
export function applicationToolContract(
|
||||
name: "project_android_application_graph",
|
||||
): (typeof APPLICATION_TOOL_CONTRACTS)[7];
|
||||
export function applicationToolContract(
|
||||
name: "project_apple_application_graph",
|
||||
): (typeof APPLICATION_TOOL_CONTRACTS)[8];
|
||||
export function applicationToolContract(
|
||||
name: (typeof APPLICATION_TOOL_CONTRACTS)[number]["name"],
|
||||
): (typeof APPLICATION_TOOL_CONTRACTS)[number] {
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
import { canonicalDigest } from "../domain/comparisonSemantics.js";
|
||||
import { createEvidence } from "../domain/evidence.js";
|
||||
import { jsonValueSchema } from "../domain/jsonValue.js";
|
||||
|
||||
const inventory = (format: "apk" | "ipa", digit: string) => {
|
||||
const sha = digit.repeat(64);
|
||||
const artifactId = `art_${canonicalDigest({ sha256: sha }, "Artifact inventory")}`;
|
||||
const occurrenceId = `occ_${canonicalDigest(
|
||||
{ root: artifactId },
|
||||
"Artifact inventory",
|
||||
)}`;
|
||||
const nodes = [
|
||||
{
|
||||
artifact_id: artifactId,
|
||||
kind: "resource",
|
||||
format,
|
||||
sha256: sha,
|
||||
size: 1,
|
||||
media_type: null,
|
||||
architecture: null,
|
||||
executable: false,
|
||||
content_state: "materialized",
|
||||
limitations: [],
|
||||
},
|
||||
];
|
||||
const occurrences = [
|
||||
{
|
||||
occurrence_id: occurrenceId,
|
||||
artifact_id: artifactId,
|
||||
parent_occurrence_id: null,
|
||||
logical_path: ".",
|
||||
entry_kind: "file",
|
||||
declared_size: 1,
|
||||
compressed_size: null,
|
||||
executable: false,
|
||||
encrypted: false,
|
||||
hash_status: "verified",
|
||||
source_location: null,
|
||||
limitations: [],
|
||||
},
|
||||
];
|
||||
const graphSha256 = canonicalDigest(
|
||||
{
|
||||
nodes,
|
||||
occurrences,
|
||||
edges: [],
|
||||
integrity_contradictions: [],
|
||||
},
|
||||
"Artifact inventory",
|
||||
);
|
||||
return jsonValueSchema.parse({
|
||||
manifest: {
|
||||
manifest_id: `agm_${canonicalDigest(
|
||||
{
|
||||
root_artifact_id: artifactId,
|
||||
graph_sha256: graphSha256,
|
||||
},
|
||||
"Artifact inventory",
|
||||
)}`,
|
||||
root_artifact_id: artifactId,
|
||||
root_sha256: sha,
|
||||
root_format: format,
|
||||
graph_sha256: graphSha256,
|
||||
node_count: nodes.length,
|
||||
occurrence_count: occurrences.length,
|
||||
edge_count: 0,
|
||||
},
|
||||
nodes,
|
||||
occurrences,
|
||||
edges: [],
|
||||
provenance: [],
|
||||
limitations: [],
|
||||
});
|
||||
};
|
||||
|
||||
const provider = {
|
||||
id: "rea-artifact-graph",
|
||||
name: "REA safe artifact graph provider",
|
||||
version: "1",
|
||||
} as const;
|
||||
|
||||
/** Catalog example for Android application inventory projection. */
|
||||
export const ANDROID_APPLICATION_GRAPH_EXAMPLE = {
|
||||
inventory_evidence: [
|
||||
createEvidence(
|
||||
{ path: "Fixture.apk", sha256: "a".repeat(64), format: "apk" },
|
||||
provider,
|
||||
{
|
||||
operation: "inventory_artifact",
|
||||
parameters: {},
|
||||
result: inventory("apk", "a"),
|
||||
confidence: "observed",
|
||||
authority: "shipped-artifact",
|
||||
},
|
||||
),
|
||||
],
|
||||
};
|
||||
|
||||
/** Catalog example for Apple application inventory projection. */
|
||||
export const APPLE_APPLICATION_GRAPH_EXAMPLE = {
|
||||
inventory_evidence: [
|
||||
createEvidence(
|
||||
{ path: "Fixture.ipa", sha256: "b".repeat(64), format: "ipa" },
|
||||
provider,
|
||||
{
|
||||
operation: "inventory_artifact",
|
||||
parameters: {},
|
||||
result: inventory("ipa", "b"),
|
||||
confidence: "observed",
|
||||
authority: "shipped-artifact",
|
||||
},
|
||||
),
|
||||
],
|
||||
};
|
||||
@@ -137,6 +137,8 @@ const PUBLISHED_TOOL_NAME_FLOOR = [
|
||||
"procedure_info",
|
||||
"procedure_pseudo_code",
|
||||
"procedure_references",
|
||||
"project_android_application_graph",
|
||||
"project_apple_application_graph",
|
||||
"project_managed_application_graph",
|
||||
"read_bytes",
|
||||
"read_function_instructions",
|
||||
|
||||
@@ -234,6 +234,8 @@ export const TOOL_EFFECTS: Readonly<Record<string, ToolEffects>> = {
|
||||
compare_javascript_export_shapes: evidence,
|
||||
build_reconstruction_obligation_ledger: evidence,
|
||||
evaluate_reconstruction_coverage: effects(),
|
||||
project_android_application_graph: evidence,
|
||||
project_apple_application_graph: evidence,
|
||||
open_binary: effects({ mutatesSession: true, launchesProcess: true }),
|
||||
close_binary: effects({
|
||||
mutatesSession: true,
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -7,6 +7,7 @@ import { registerCompareSourceToBundleTool } from "./registerApplicationTools/co
|
||||
import { registerCompareJavaScriptExportShapesTool } from "./registerApplicationTools/compareExportShapes.js";
|
||||
import { registerCoverageTools } from "./registerApplicationTools/coverage.js";
|
||||
import { registerReconstructionObligationLedgerTool } from "./registerApplicationTools/obligationLedger.js";
|
||||
import { registerProjectMobileApplicationGraphTools } from "./registerApplicationTools/projectMobileApplicationGraph.js";
|
||||
import type { ApplicationToolRegistration } from "./registerApplicationTools/types.js";
|
||||
|
||||
export type { ApplicationToolRegistration };
|
||||
@@ -23,4 +24,5 @@ export const registerApplicationTools = (
|
||||
registerCompareJavaScriptExportShapesTool(server, options);
|
||||
registerReconstructionObligationLedgerTool(server, options);
|
||||
registerCoverageTools(server, options);
|
||||
registerProjectMobileApplicationGraphTools(server, options);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import type { McpServer } from "@modelcontextprotocol/server";
|
||||
|
||||
import { projectAndroidApplicationEvidence } from "../../application/AndroidApplicationService.js";
|
||||
import { projectAppleApplicationEvidence } from "../../application/AppleApplicationService.js";
|
||||
import {
|
||||
APPLICATION_TOOL_CONTRACTS,
|
||||
applicationToolContract,
|
||||
} from "../../contracts/applicationToolContracts.js";
|
||||
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import type { Evidence } from "../../domain/evidence.js";
|
||||
import type { Result } from "../../domain/result.js";
|
||||
import { recordSessionEvidenceSources } from "../sessionEvidence.js";
|
||||
import { logToolExecution } from "../toolLogging.js";
|
||||
import { toolRegistrationOptions } from "../toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "../toolResult.js";
|
||||
import { recordResult } from "./helpers.js";
|
||||
import type { ApplicationToolRegistration } from "./types.js";
|
||||
|
||||
/** Register execution-free Android and Apple inventory projection tools. */
|
||||
export const registerProjectMobileApplicationGraphTools = (
|
||||
server: McpServer,
|
||||
options: ApplicationToolRegistration,
|
||||
): void => {
|
||||
registerProjection({
|
||||
server,
|
||||
options,
|
||||
contract: applicationToolContract("project_android_application_graph"),
|
||||
project: projectAndroidApplicationEvidence,
|
||||
});
|
||||
registerProjection({
|
||||
server,
|
||||
options,
|
||||
contract: applicationToolContract("project_apple_application_graph"),
|
||||
project: projectAppleApplicationEvidence,
|
||||
});
|
||||
};
|
||||
|
||||
const registerProjection = (context: {
|
||||
readonly server: McpServer;
|
||||
readonly options: ApplicationToolRegistration;
|
||||
readonly contract: (typeof APPLICATION_TOOL_CONTRACTS)[number];
|
||||
readonly project: (input: unknown) => Result<Evidence, AnalysisError>;
|
||||
}): void => {
|
||||
const { server, options, contract, project } = context;
|
||||
server.registerTool(
|
||||
contract.name,
|
||||
toolRegistrationOptions(contract),
|
||||
async (input: unknown) => {
|
||||
const result = await logToolExecution(options.logger, contract.name, () =>
|
||||
Promise.resolve(project(input)),
|
||||
);
|
||||
if (!result.ok) return toCallToolResult(result, contract);
|
||||
const recordedSources = recordSessionEvidenceSources(
|
||||
options.recordEvidence,
|
||||
inventoryEvidenceSources(input),
|
||||
);
|
||||
if (!recordedSources.ok)
|
||||
return toCallToolResult(recordedSources, contract);
|
||||
return recordResult(options, contract, result.value);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
const inventoryEvidenceSources = (input: unknown): readonly Evidence[] => {
|
||||
if (
|
||||
typeof input !== "object" ||
|
||||
input === null ||
|
||||
!("inventory_evidence" in input) ||
|
||||
!Array.isArray(input.inventory_evidence)
|
||||
)
|
||||
return [];
|
||||
return input.inventory_evidence as readonly Evidence[];
|
||||
};
|
||||
Reference in New Issue
Block a user