Add a read-only app resource session shared by CLI and MCP. Preserve resource-root provenance without inventing executable identity, reject binary-only snapshots and operations, and retain failed cleanup owners across switches and retries. Keep filesystem admission failures typed and preserve cancellation ordering from observed cleanup facts. Document resource routing in the packaged investigation skill. BREAKING CHANGE: resource-only observations may have a null Evidence subject and null executable target digests. Clients must use resource_root and reported per-resource provenance instead. Refs #5589
68 lines
2.4 KiB
TypeScript
68 lines
2.4 KiB
TypeScript
import type { AndroidAnalysisPort } from "./AndroidAnalysisPort.js";
|
|
import type { ExecutionOptions } from "../AnalysisProvider.js";
|
|
import { parseBinaryTarget } from "../BinaryTargetResolver.js";
|
|
import {
|
|
androidRequestSchema,
|
|
type AndroidOperation,
|
|
} from "../../domain/android/androidAnalysis.js";
|
|
import {
|
|
AnalysisCancelledError,
|
|
AnalysisInputError,
|
|
} from "../../domain/analysisErrorCore.js";
|
|
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
|
import { createEvidence, type Evidence } from "../../domain/evidence.js";
|
|
import { jsonObjectSchema } from "../../domain/jsonValue.js";
|
|
import { err, type Result } from "../../domain/result.js";
|
|
import { completeProviderEvidence } from "../ProviderOperationExecution.js";
|
|
|
|
/** Shared CLI/MCP admission, execution and Evidence composition for Android. */
|
|
export class AndroidAnalysisService {
|
|
constructor(readonly provider: AndroidAnalysisPort) {}
|
|
|
|
/** Inspect a caller-selected APK and retain producing-provider provenance inline. */
|
|
async execute(
|
|
operation: AndroidOperation,
|
|
input: unknown,
|
|
options?: ExecutionOptions,
|
|
): Promise<Result<Evidence, AnalysisError>> {
|
|
if (options?.signal?.aborted === true)
|
|
return err(
|
|
new AnalysisCancelledError(operation, { cause: options.signal.reason }),
|
|
);
|
|
const request = androidRequestSchema.safeParse({ operation, input });
|
|
if (!request.success)
|
|
return err(new AnalysisInputError(operation, { cause: request.error }));
|
|
const target = await parseBinaryTarget(
|
|
request.data.input.path,
|
|
options?.signal === undefined ? {} : { signal: options.signal },
|
|
);
|
|
if (!target.ok) return target;
|
|
const executed = await this.provider.execute(
|
|
target.value,
|
|
request.data,
|
|
options,
|
|
);
|
|
if (!executed.ok) return executed;
|
|
const execution = executed.value;
|
|
return completeProviderEvidence(
|
|
createEvidence(
|
|
execution.subject === undefined
|
|
? target.value
|
|
: (execution.subject ?? undefined),
|
|
execution.provider,
|
|
{
|
|
operation,
|
|
parameters: jsonObjectSchema.parse(request.data.input),
|
|
result: execution.result,
|
|
rawResult: execution.rawResult,
|
|
limitations: execution.limitations,
|
|
locations: execution.locations,
|
|
confidence:
|
|
operation === "inspect_android_method" ? "derived" : "observed",
|
|
},
|
|
),
|
|
options?.signal,
|
|
);
|
|
}
|
|
}
|