mirror of
https://github.com/morluto/rea.git
synced 2026-10-30 03:15:54 +00:00
Record the first transport failure before SDK teardown, then capture terminal stderr after owned retirement. Preserve exact opaque cancellation reasons and keep foreign cleanup ownership separate through retries. Validation: 119 focused tests across eight files; five selected baseline regressions; check:fast, docs:check, test discovery; nine real CLI and nine real MCP tiny-APK inspections. Native Windows/Linux startup failures and actual JVM OOM remain unverified. Closes #4844
62 lines
2.3 KiB
TypeScript
62 lines
2.3 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 ?? target.value, 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,
|
|
);
|
|
}
|
|
}
|