fix(android): report actual provider readiness
This commit is contained in:
@@ -1,10 +1,19 @@
|
||||
import { access, realpath, stat } from "node:fs/promises";
|
||||
import { constants } from "node:fs";
|
||||
import { access, realpath, stat } from "node:fs/promises";
|
||||
import { isAbsolute, join } from "node:path";
|
||||
import { AnalysisCapabilityUnavailableError } from "../domain/analysisErrorCore.js";
|
||||
import type { AndroidOperation } from "../domain/android/androidAnalysis.js";
|
||||
import type { JsonValue } from "../domain/jsonValue.js";
|
||||
import type { ProviderAvailability } from "../application/AnalysisProvider.js";
|
||||
import {
|
||||
execFileOutput,
|
||||
execFileOutputFailure,
|
||||
} from "../process/ExecFileOutput.js";
|
||||
import { JADX_JAR_CONFIGURATION_REMEDIATION } from "./JadxRelease.js";
|
||||
|
||||
const JAVA_MODULE_LISTING_TIMEOUT_MS = 10_000;
|
||||
const JAVA_MODULE_LISTING_MAX_OUTPUT_BYTES = 1024 * 1024;
|
||||
|
||||
/** Caller-supplied tools, resolved only when an Android operation is selected. */
|
||||
export interface JadxConfiguration {
|
||||
readonly jar: string;
|
||||
@@ -12,51 +21,184 @@ export interface JadxConfiguration {
|
||||
readonly jvmArguments: readonly string[];
|
||||
}
|
||||
|
||||
/** Admit explicit local tooling without installing or changing host configuration. */
|
||||
type ConfigurationFailureCode =
|
||||
| "not_configured"
|
||||
| "executable_missing"
|
||||
| "runtime_missing"
|
||||
| "unsupported_host"
|
||||
| "unsupported_version"
|
||||
| "version_unresolved"
|
||||
| "open_options_invalid";
|
||||
|
||||
class JadxConfigurationFailure extends Error {
|
||||
constructor(
|
||||
readonly code: ConfigurationFailureCode,
|
||||
message: string,
|
||||
readonly diagnostics: Readonly<Record<string, JsonValue>>,
|
||||
options?: ErrorOptions,
|
||||
) {
|
||||
super(message, options);
|
||||
}
|
||||
}
|
||||
|
||||
/** Inspect the same JAR and Java prerequisites that gate actual execution. */
|
||||
export const inspectJadxAvailability = async (
|
||||
environment: Readonly<Record<string, string | undefined>>,
|
||||
signal?: AbortSignal,
|
||||
): Promise<ProviderAvailability> => {
|
||||
try {
|
||||
const configuration = await readJadxConfiguration(environment, signal);
|
||||
return {
|
||||
status: "available",
|
||||
code: null,
|
||||
reason: null,
|
||||
diagnostics: {
|
||||
configured: true,
|
||||
java_executable: configuration.java,
|
||||
jdk_compiler: true,
|
||||
jar_path: configuration.jar,
|
||||
},
|
||||
};
|
||||
} catch (cause) {
|
||||
if (signal?.aborted === true) throw cause;
|
||||
if (cause instanceof JadxConfigurationFailure)
|
||||
return {
|
||||
status: "unavailable",
|
||||
code: cause.code,
|
||||
reason: cause.message,
|
||||
diagnostics: cause.diagnostics,
|
||||
};
|
||||
throw cause;
|
||||
}
|
||||
};
|
||||
|
||||
/** Resolve caller-selected tools and preserve the same prerequisite diagnostics. */
|
||||
export const resolveJadxConfiguration = async (
|
||||
environment: Readonly<Record<string, string | undefined>>,
|
||||
operation: AndroidOperation,
|
||||
signal?: AbortSignal,
|
||||
): Promise<JadxConfiguration> => {
|
||||
const unavailable = (reason: string) =>
|
||||
new AnalysisCapabilityUnavailableError("jadx", operation, reason);
|
||||
if (process.platform !== "linux" && process.platform !== "darwin")
|
||||
throw unavailable(
|
||||
`Android JADX subprocess ownership is unsupported on ${process.platform}; use Linux or macOS. The metadata bridge has real-provider verification on macOS arm64.`,
|
||||
try {
|
||||
return await readJadxConfiguration(environment, signal);
|
||||
} catch (cause) {
|
||||
if (signal?.aborted === true) throw cause;
|
||||
if (!(cause instanceof JadxConfigurationFailure)) throw cause;
|
||||
const output = cause.diagnostics;
|
||||
throw new AnalysisCapabilityUnavailableError(
|
||||
"jadx",
|
||||
operation,
|
||||
cause.message,
|
||||
{
|
||||
cause,
|
||||
userMessage: cause.message,
|
||||
...(typeof output.stdout === "string" &&
|
||||
typeof output.stderr === "string"
|
||||
? {
|
||||
capturedOutput: {
|
||||
stdout: output.stdout,
|
||||
stderr: output.stderr,
|
||||
truncated: output.output_truncated === true,
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const readJadxConfiguration = async (
|
||||
environment: Readonly<Record<string, string | undefined>>,
|
||||
signal?: AbortSignal,
|
||||
): Promise<JadxConfiguration> => {
|
||||
requireSupportedHost();
|
||||
const jar = await resolveJar(environment);
|
||||
const java = resolveJava(environment);
|
||||
await requireJavaHomeExecutable(environment.JAVA_HOME, java);
|
||||
const jvmArguments = resolveJvmArguments(environment);
|
||||
await inspectJavaRuntime(java, environment, signal);
|
||||
return { jar, java, jvmArguments };
|
||||
};
|
||||
|
||||
const requireSupportedHost = (): void => {
|
||||
if (process.platform === "linux" || process.platform === "darwin") return;
|
||||
throw configurationFailure(
|
||||
"unsupported_host",
|
||||
`Android JADX subprocess ownership is unsupported on ${process.platform}; use Linux or macOS. The metadata bridge has real-provider verification on macOS arm64.`,
|
||||
{ platform: process.platform },
|
||||
);
|
||||
};
|
||||
|
||||
const resolveJar = async (
|
||||
environment: Readonly<Record<string, string | undefined>>,
|
||||
): Promise<string> => {
|
||||
const jar = environment.REA_JADX_MCP_JAR;
|
||||
if (environment.JAVA_HOME !== undefined && !isAbsolute(environment.JAVA_HOME))
|
||||
throw unavailable(
|
||||
"JAVA_HOME must select an existing JDK by absolute path; omit it to use java on PATH.",
|
||||
);
|
||||
if (jar === undefined || !isAbsolute(jar))
|
||||
throw unavailable(JADX_JAR_CONFIGURATION_REMEDIATION);
|
||||
const java =
|
||||
environment.JAVA_HOME === undefined
|
||||
? "java"
|
||||
: join(environment.JAVA_HOME, "bin", "java");
|
||||
throw configurationFailure(
|
||||
"not_configured",
|
||||
JADX_JAR_CONFIGURATION_REMEDIATION,
|
||||
{ jar_configured: false },
|
||||
);
|
||||
try {
|
||||
await access(jar, constants.R_OK);
|
||||
if (!(await stat(jar)).isFile())
|
||||
throw unavailable(`REA_JADX_MCP_JAR is not a regular file: ${jar}`);
|
||||
throw configurationFailure(
|
||||
"executable_missing",
|
||||
`REA_JADX_MCP_JAR is not a regular file: ${jar}`,
|
||||
{ jar_path: jar },
|
||||
);
|
||||
return await realpath(jar);
|
||||
} catch (cause) {
|
||||
if (cause instanceof AnalysisCapabilityUnavailableError) throw cause;
|
||||
throw unavailable(
|
||||
if (cause instanceof JadxConfigurationFailure) throw cause;
|
||||
throw configurationFailure(
|
||||
"executable_missing",
|
||||
`Cannot read REA_JADX_MCP_JAR ${jar}: ${cause instanceof Error ? cause.message : String(cause)}`,
|
||||
{ jar_path: jar },
|
||||
cause,
|
||||
);
|
||||
}
|
||||
if (environment.JAVA_HOME !== undefined) {
|
||||
try {
|
||||
await access(java, constants.R_OK | constants.X_OK);
|
||||
if (!(await stat(java)).isFile())
|
||||
throw unavailable(`JAVA_HOME java is not a regular file: ${java}`);
|
||||
} catch (cause) {
|
||||
if (cause instanceof AnalysisCapabilityUnavailableError) throw cause;
|
||||
throw unavailable(
|
||||
`Cannot execute JAVA_HOME java ${java}: ${cause instanceof Error ? cause.message : String(cause)}`,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const resolveJava = (
|
||||
environment: Readonly<Record<string, string | undefined>>,
|
||||
): string => {
|
||||
if (environment.JAVA_HOME === undefined) return "java";
|
||||
if (isAbsolute(environment.JAVA_HOME))
|
||||
return join(environment.JAVA_HOME, "bin", "java");
|
||||
throw configurationFailure(
|
||||
"open_options_invalid",
|
||||
"JAVA_HOME must select an existing JDK by absolute path; omit it to use java on PATH.",
|
||||
{ java_home: environment.JAVA_HOME },
|
||||
);
|
||||
};
|
||||
|
||||
const requireJavaHomeExecutable = async (
|
||||
javaHome: string | undefined,
|
||||
java: string,
|
||||
): Promise<void> => {
|
||||
if (javaHome === undefined) return;
|
||||
try {
|
||||
await access(java, constants.R_OK | constants.X_OK);
|
||||
if ((await stat(java)).isFile()) return;
|
||||
throw configurationFailure(
|
||||
"runtime_missing",
|
||||
`JAVA_HOME java is not a regular file: ${java}`,
|
||||
{ java_executable: java },
|
||||
);
|
||||
} catch (cause) {
|
||||
if (cause instanceof JadxConfigurationFailure) throw cause;
|
||||
throw configurationFailure(
|
||||
"runtime_missing",
|
||||
`Cannot execute JAVA_HOME java ${java}: ${cause instanceof Error ? cause.message : String(cause)}`,
|
||||
{ java_executable: java },
|
||||
cause,
|
||||
);
|
||||
}
|
||||
const jvmArguments: string[] = [];
|
||||
};
|
||||
|
||||
const resolveJvmArguments = (
|
||||
environment: Readonly<Record<string, string | undefined>>,
|
||||
): readonly string[] => {
|
||||
const result: string[] = [];
|
||||
for (const [name, prefix, suffix] of [
|
||||
["REA_JADX_HEAP_MIB", "-Xmx", "m"],
|
||||
["REA_JADX_ACTIVE_PROCESSOR_COUNT", "-XX:ActiveProcessorCount=", ""],
|
||||
@@ -64,17 +206,142 @@ export const resolveJadxConfiguration = async (
|
||||
const value = environment[name];
|
||||
if (value === undefined) continue;
|
||||
if (!/^[1-9]\d*$/u.test(value) || !Number.isSafeInteger(Number(value)))
|
||||
throw unavailable(
|
||||
throw configurationFailure(
|
||||
"open_options_invalid",
|
||||
`${name} must be a positive safe integer; received ${value}.`,
|
||||
{ setting: name, value },
|
||||
);
|
||||
if (
|
||||
name === "REA_JADX_ACTIVE_PROCESSOR_COUNT" &&
|
||||
Number(value) > 2_147_483_647
|
||||
)
|
||||
throw unavailable(
|
||||
throw configurationFailure(
|
||||
"open_options_invalid",
|
||||
`${name} exceeds the JVM's signed 32-bit processor-count range.`,
|
||||
{ setting: name, value },
|
||||
);
|
||||
jvmArguments.push(`${prefix}${value}${suffix}`);
|
||||
result.push(`${prefix}${value}${suffix}`);
|
||||
}
|
||||
return { jar: await realpath(jar), java, jvmArguments };
|
||||
return result;
|
||||
};
|
||||
|
||||
const inspectJavaRuntime = async (
|
||||
java: string,
|
||||
environment: Readonly<Record<string, string | undefined>>,
|
||||
signal?: AbortSignal,
|
||||
): Promise<void> => {
|
||||
let stdout: string;
|
||||
let stderr: string;
|
||||
try {
|
||||
({ stdout, stderr } = await execFileOutput(java, ["--list-modules"], {
|
||||
env: { ...environment },
|
||||
timeout: JAVA_MODULE_LISTING_TIMEOUT_MS,
|
||||
maxBuffer: JAVA_MODULE_LISTING_MAX_OUTPUT_BYTES,
|
||||
...(signal === undefined ? {} : { signal }),
|
||||
}));
|
||||
} catch (cause) {
|
||||
if (signal?.aborted === true) throw cause;
|
||||
const output = execFileOutputFailure(cause);
|
||||
if (output === undefined) throw cause;
|
||||
const diagnostics = {
|
||||
java_executable: java,
|
||||
phase: "module-inspection",
|
||||
exit_code: typeof output.code === "number" ? output.code : null,
|
||||
process_error_code:
|
||||
typeof output.code === "string" ? output.code : null,
|
||||
signal: output.signal,
|
||||
killed: output.killed,
|
||||
stdout: output.stdout,
|
||||
stderr: output.stderr,
|
||||
output_truncated: output.outputTruncated,
|
||||
} satisfies Readonly<Record<string, JsonValue>>;
|
||||
if (output.outputTruncated)
|
||||
throw configurationFailure(
|
||||
"version_unresolved",
|
||||
`The selected Java launcher ${java} exceeded the ${JAVA_MODULE_LISTING_MAX_OUTPUT_BYTES / (1024 * 1024)} MiB output budget while listing modules. REA retained partial output but could not establish compiler or version availability. Inspect the selected launcher for verbose or unbounded output; ` +
|
||||
"java --list-modules should return a concise module listing.",
|
||||
{
|
||||
...diagnostics,
|
||||
failure: "output_limit",
|
||||
output_limit_bytes: JAVA_MODULE_LISTING_MAX_OUTPUT_BYTES,
|
||||
},
|
||||
cause,
|
||||
);
|
||||
if (output.killed)
|
||||
throw configurationFailure(
|
||||
"version_unresolved",
|
||||
`The selected Java launcher ${java} was terminated or did not finish the module-listing probe within ${JAVA_MODULE_LISTING_TIMEOUT_MS / 1000} seconds. Inspect the launcher and its startup responsiveness, then verify it returns compiler and version modules with java --list-modules.`,
|
||||
{
|
||||
...diagnostics,
|
||||
failure: "probe_terminated",
|
||||
deadline_ms: JAVA_MODULE_LISTING_TIMEOUT_MS,
|
||||
},
|
||||
cause,
|
||||
);
|
||||
throw configurationFailure(
|
||||
"runtime_missing",
|
||||
`Cannot inspect selected Java runtime ${java}: ${output.stderr.trim() || errorText(cause)}. Select a full JDK including jdk.compiler via JAVA_HOME or PATH; verify it with java --list-modules.`,
|
||||
diagnostics,
|
||||
cause,
|
||||
);
|
||||
}
|
||||
const compiler = /^jdk\.compiler(?:@|$)/mu.test(stdout);
|
||||
if (!compiler)
|
||||
throw configurationFailure(
|
||||
"runtime_missing",
|
||||
`Selected Java runtime ${java} does not provide jdk.compiler. Select a full JDK including jdk.compiler via JAVA_HOME or PATH; verify it with java --list-modules. A JRE cannot compile REA's source bridge.`,
|
||||
{
|
||||
java_executable: java,
|
||||
phase: "module-inspection",
|
||||
jdk_compiler: false,
|
||||
stdout,
|
||||
stderr,
|
||||
output_truncated: false,
|
||||
},
|
||||
);
|
||||
const major = /^java\.base@(\d+)(?:[.+_-]|$)/mu.exec(stdout)?.[1];
|
||||
if (major === undefined)
|
||||
throw configurationFailure(
|
||||
"version_unresolved",
|
||||
`The selected Java launcher ${java} did not report a parseable java.base version in its module listing. Inspect the launcher output and verify it with java --list-modules.`,
|
||||
{
|
||||
java_executable: java,
|
||||
phase: "module-inspection",
|
||||
jdk_compiler: true,
|
||||
java_major: null,
|
||||
stdout,
|
||||
stderr,
|
||||
output_truncated: false,
|
||||
},
|
||||
);
|
||||
if (Number(major) < 17)
|
||||
throw configurationFailure(
|
||||
"unsupported_version",
|
||||
`Selected Java runtime ${java} must be JDK 17 or newer and include jdk.compiler; verify it with java --list-modules.`,
|
||||
{
|
||||
java_executable: java,
|
||||
phase: "module-inspection",
|
||||
jdk_compiler: true,
|
||||
java_major: major ?? null,
|
||||
stdout,
|
||||
stderr,
|
||||
output_truncated: false,
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
const configurationFailure = (
|
||||
code: ConfigurationFailureCode,
|
||||
message: string,
|
||||
diagnostics: Readonly<Record<string, JsonValue>>,
|
||||
cause?: unknown,
|
||||
): JadxConfigurationFailure =>
|
||||
new JadxConfigurationFailure(
|
||||
code,
|
||||
message,
|
||||
diagnostics,
|
||||
cause === undefined ? undefined : { cause },
|
||||
);
|
||||
|
||||
const errorText = (cause: unknown): string =>
|
||||
cause instanceof Error ? cause.message : String(cause);
|
||||
|
||||
@@ -23,7 +23,10 @@ import {
|
||||
hashAndroidFile,
|
||||
snapshotAndroidTarget,
|
||||
} from "./AndroidTargetSnapshot.js";
|
||||
import { resolveJadxConfiguration } from "./JadxConfiguration.js";
|
||||
import {
|
||||
inspectJadxAvailability,
|
||||
resolveJadxConfiguration,
|
||||
} from "./JadxConfiguration.js";
|
||||
import type { JadxLauncher } from "./JadxMcpTransport.js";
|
||||
|
||||
import { JadxSession } from "./JadxSession.js";
|
||||
@@ -175,6 +178,11 @@ export class JadxProvider implements AndroidAnalysisPort {
|
||||
readonly launcher?: JadxLauncher,
|
||||
) {}
|
||||
|
||||
/** Report actual local prerequisites without starting JADX or opening a target. */
|
||||
inspectAvailability(signal?: AbortSignal) {
|
||||
return inspectJadxAvailability(this.environment, signal);
|
||||
}
|
||||
|
||||
/** Serialize expensive work and bind both raw and normalized results to the APK. */
|
||||
async execute(
|
||||
target: BinaryTarget,
|
||||
@@ -267,6 +275,7 @@ export class JadxProvider implements AndroidAnalysisPort {
|
||||
const configuration = await resolveJadxConfiguration(
|
||||
this.environment,
|
||||
request.operation,
|
||||
signal,
|
||||
);
|
||||
signal.throwIfAborted();
|
||||
const jarHash = await hashAndroidFile(configuration.jar);
|
||||
|
||||
@@ -40,6 +40,10 @@ const enabledPolicy: Parameters<typeof buildCapabilityInventory>[1] = {
|
||||
v8InspectorObservationEnabled: true,
|
||||
};
|
||||
|
||||
const availableAndroidAvailability: NonNullable<
|
||||
Parameters<typeof buildCapabilityInventory>[1]["androidAnalysisAvailability"]
|
||||
> = { status: "available", code: null, reason: null, diagnostics: {} };
|
||||
|
||||
const status = (
|
||||
options: {
|
||||
readonly open?: boolean;
|
||||
@@ -110,7 +114,7 @@ describe("capability inventory: provider status", () => {
|
||||
expect(
|
||||
entry("inspect_android_package", status(), {
|
||||
processCaptureEnabled: true,
|
||||
androidAnalysisEnabled: true,
|
||||
androidAnalysisAvailability: availableAndroidAvailability,
|
||||
}),
|
||||
).toMatchObject({
|
||||
available: true,
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
} from "../contracts/toolOutputSchemaPrimitives.js";
|
||||
import type { ToolKind } from "../contracts/toolContractTypes.js";
|
||||
import type { JsonValue } from "../domain/jsonValue.js";
|
||||
import type { ProviderAvailability } from "./AnalysisProvider.js";
|
||||
import { TOOL_CONTRACTS } from "../contracts/toolContracts.js";
|
||||
import {
|
||||
clientRequirementsFor,
|
||||
@@ -38,7 +39,7 @@ export type AvailabilityPolicy = {
|
||||
readonly recordedCrashEnabled?: boolean;
|
||||
readonly firmwareInspectionEnabled?: boolean;
|
||||
readonly firmwareExtractionEnabled?: boolean;
|
||||
readonly androidAnalysisEnabled?: boolean;
|
||||
readonly androidAnalysisAvailability?: ProviderAvailability;
|
||||
readonly javascriptRecoveryEnabled?: boolean;
|
||||
readonly webModuleResolutionEnabled?: boolean;
|
||||
readonly browserObservationEnabled?: boolean;
|
||||
@@ -321,12 +322,16 @@ const workflowAvailabilityFor = ({
|
||||
};
|
||||
}
|
||||
if (kind === "android-provider")
|
||||
return policy.androidAnalysisEnabled === true
|
||||
return policy.androidAnalysisAvailability?.status === "available"
|
||||
? { reason: "available", remediation: null }
|
||||
: {
|
||||
reason: "provider_missing",
|
||||
reason:
|
||||
policy.androidAnalysisAvailability?.code === "unsupported_host"
|
||||
? "unsupported_host"
|
||||
: "provider_missing",
|
||||
remediation:
|
||||
"Set REA_JADX_MCP_JAR to a caller-supplied jadx-headless-mcp 0.7.1 JAR and provide Java on Linux or macOS. Only Linux has real-provider verification.",
|
||||
policy.androidAnalysisAvailability?.reason ??
|
||||
"Set REA_JADX_MCP_JAR to a caller-supplied jadx-headless-mcp 0.7.1 JAR and provide a full JDK on Linux or macOS.",
|
||||
};
|
||||
const browser = browserProviderAvailability(name, kind, policy);
|
||||
if (browser !== null) return browser;
|
||||
|
||||
@@ -6,9 +6,12 @@ import type { AndroidRequest } from "../../domain/android/androidAnalysis.js";
|
||||
import type { BinaryTarget } from "../../domain/binaryTarget.js";
|
||||
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import type { Result } from "../../domain/result.js";
|
||||
import type { ProviderAvailability } from "../AnalysisProvider.js";
|
||||
|
||||
/** Static Android inspection boundary; implementation details belong to the provider. */
|
||||
export interface AndroidAnalysisPort {
|
||||
/** Inspect the selected JAR and Java runtime without opening an APK. */
|
||||
inspectAvailability(signal?: AbortSignal): Promise<ProviderAvailability>;
|
||||
/** Cancel active work and join cleanup of any retained provider resources. */
|
||||
close(): Promise<void>;
|
||||
execute(
|
||||
|
||||
@@ -8,6 +8,38 @@ type ExecFileOutputOptions = Omit<
|
||||
"encoding" | "maxBuffer"
|
||||
> & { readonly maxBuffer?: number };
|
||||
|
||||
/** Captured subprocess output read from an execFileOutput rejection. */
|
||||
export interface ExecFileOutputFailure {
|
||||
readonly stdout: string;
|
||||
readonly stderr: string;
|
||||
readonly code: string | number | null;
|
||||
readonly signal: string | null;
|
||||
readonly killed: boolean;
|
||||
readonly outputTruncated: boolean;
|
||||
}
|
||||
|
||||
/** Read captured output metadata from a failed execFileOutput invocation. */
|
||||
export const execFileOutputFailure = (
|
||||
cause: unknown,
|
||||
): ExecFileOutputFailure | undefined => {
|
||||
if (!(cause instanceof Error)) return undefined;
|
||||
const stdout = Reflect.get(cause, "stdout");
|
||||
const stderr = Reflect.get(cause, "stderr");
|
||||
const code = Reflect.get(cause, "code");
|
||||
const signal = Reflect.get(cause, "signal");
|
||||
const killed = Reflect.get(cause, "killed");
|
||||
if (typeof stdout !== "string" || typeof stderr !== "string")
|
||||
return undefined;
|
||||
return {
|
||||
stdout,
|
||||
stderr,
|
||||
code: typeof code === "string" || typeof code === "number" ? code : null,
|
||||
signal: typeof signal === "string" ? signal : null,
|
||||
killed: killed === true,
|
||||
outputTruncated: code === "ERR_CHILD_PROCESS_STDIO_MAXBUFFER",
|
||||
};
|
||||
};
|
||||
|
||||
/** Run a shell-free command while capturing its complete UTF-8 output. */
|
||||
export const execFileOutput = (
|
||||
command: string,
|
||||
|
||||
@@ -122,10 +122,6 @@ const installSessionToolAvailability = (
|
||||
options.firmwareAnalysis !== undefined ||
|
||||
(process.platform === "linux" &&
|
||||
isAbsolute(process.env.REA_UNBLOB_COMMAND ?? "")),
|
||||
androidAnalysisEnabled:
|
||||
options.androidAnalysis !== undefined ||
|
||||
((process.platform === "linux" || process.platform === "darwin") &&
|
||||
isAbsolute(process.env.REA_JADX_MCP_JAR ?? "")),
|
||||
browserObservationEnabled: options.browserObservation !== undefined,
|
||||
javascriptRecoveryEnabled:
|
||||
options.javascriptRecovery !== undefined ||
|
||||
@@ -176,6 +172,7 @@ export const createServer = (
|
||||
const startedAt = new Date().toISOString();
|
||||
const logger = options.logger ?? silentLogger;
|
||||
const server = createMcpServer(session);
|
||||
const android = options.androidAnalysis ?? createAndroidAnalysisProvider();
|
||||
const availability = installSessionToolAvailability(server, session, options);
|
||||
const toolLogger = logger.child({ layer: "server" });
|
||||
const {
|
||||
@@ -196,7 +193,6 @@ export const createServer = (
|
||||
recordEvidenceWithUnknown,
|
||||
};
|
||||
registerBinaryAnalysisTools(toolContext);
|
||||
const android = options.androidAnalysis ?? createAndroidAnalysisProvider();
|
||||
const previousOnclose = server.server.onclose;
|
||||
server.server.onclose = () => {
|
||||
previousOnclose?.();
|
||||
@@ -285,6 +281,8 @@ export const createServer = (
|
||||
...(availability === undefined
|
||||
? {}
|
||||
: { availabilityPolicy: availability.policy }),
|
||||
androidAnalysisAvailability: (signal) =>
|
||||
android.inspectAvailability(signal),
|
||||
startedAt,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { McpServer } from "@modelcontextprotocol/server";
|
||||
|
||||
import type { BinarySessionPort } from "../application/binary/BinarySession.js";
|
||||
import type { ProviderAvailability } from "../application/AnalysisProvider.js";
|
||||
import { AnalysisCancelledError } from "../domain/analysisErrorCore.js";
|
||||
import { buildCapabilityInventory } from "../application/CapabilityInventory.js";
|
||||
import { toolContract } from "../contracts/toolContracts.js";
|
||||
import type { ClientFeatureAvailability } from "../contracts/toolOutputSchemaPrimitives.js";
|
||||
@@ -10,6 +12,7 @@ import { mcpClientMetadata } from "./mcpClientMetadata.js";
|
||||
import type { SessionAvailability } from "./sessionAvailabilityPolicy.js";
|
||||
import { toolRegistrationOptions } from "./toolRegistrationOptions.js";
|
||||
import { toCallToolResult } from "./toolResult.js";
|
||||
import { err } from "../domain/result.js";
|
||||
|
||||
type ToolAvailability = ReturnType<typeof buildCapabilityInventory>[number];
|
||||
|
||||
@@ -20,24 +23,49 @@ export interface SessionStatusToolOptions {
|
||||
readonly contract: ReturnType<typeof toolContract<"binary_session">>;
|
||||
readonly startedAt: string;
|
||||
readonly availabilityPolicy: () => SessionAvailability;
|
||||
readonly androidAnalysisAvailability: (
|
||||
signal: AbortSignal,
|
||||
) => Promise<ProviderAvailability>;
|
||||
}
|
||||
|
||||
/** Register the read-only provider and target status operation. */
|
||||
export const registerSessionStatusTool = (
|
||||
options: SessionStatusToolOptions,
|
||||
): void => {
|
||||
const { server, session, contract, startedAt, availabilityPolicy } = options;
|
||||
const {
|
||||
server,
|
||||
session,
|
||||
contract,
|
||||
startedAt,
|
||||
availabilityPolicy,
|
||||
androidAnalysisAvailability,
|
||||
} = options;
|
||||
server.registerTool(
|
||||
contract.name,
|
||||
toolRegistrationOptions(contract),
|
||||
(input, context) => {
|
||||
async (input, context) => {
|
||||
const { client, clientFeatures, protocolVersion } =
|
||||
mcpClientMetadata(context);
|
||||
let androidAvailability: ProviderAvailability;
|
||||
try {
|
||||
androidAvailability = await androidAnalysisAvailability(
|
||||
context.mcpReq.signal,
|
||||
);
|
||||
} catch (cause) {
|
||||
if (!context.mcpReq.signal.aborted) throw cause;
|
||||
return toCallToolResult(
|
||||
err(new AnalysisCancelledError("binary_session")),
|
||||
contract,
|
||||
);
|
||||
}
|
||||
const status = session.status();
|
||||
const statusObject = jsonObjectSchema.parse(status);
|
||||
const toolAvailability = buildCapabilityInventory(
|
||||
status,
|
||||
availabilityPolicy(),
|
||||
{
|
||||
...availabilityPolicy(),
|
||||
androidAnalysisAvailability: androidAvailability,
|
||||
},
|
||||
clientFeatures,
|
||||
);
|
||||
const serverIdentity = createServerIdentity({
|
||||
|
||||
@@ -17,6 +17,7 @@ import type { Evidence } from "../domain/evidence.js";
|
||||
import type { ProcessCapture } from "../domain/process/processCapture.js";
|
||||
import { ok, type Result } from "../domain/result.js";
|
||||
import type { Logger } from "../logger.js";
|
||||
import type { ProviderAvailability } from "../application/AnalysisProvider.js";
|
||||
import { mcpProgressReporter } from "./mcpProgress.js";
|
||||
import { registerArtifactComparisonTool } from "./registerArtifactComparisonTool.js";
|
||||
import { registerBundleComparisonTool } from "./registerBundleComparisonTool.js";
|
||||
@@ -136,13 +137,22 @@ export interface LifecycleToolRegistration {
|
||||
readonly statusContract: ReturnType<typeof toolContract<"binary_session">>;
|
||||
readonly startedAt: string;
|
||||
readonly availabilityPolicy: () => SessionAvailability;
|
||||
readonly androidAnalysisAvailability: (
|
||||
signal: AbortSignal,
|
||||
) => Promise<ProviderAvailability>;
|
||||
}
|
||||
|
||||
const registerLifecycleTools = (
|
||||
registration: LifecycleToolRegistration,
|
||||
): void => {
|
||||
const { server, session, statusContract, startedAt, availabilityPolicy } =
|
||||
registration;
|
||||
const {
|
||||
server,
|
||||
session,
|
||||
statusContract,
|
||||
startedAt,
|
||||
availabilityPolicy,
|
||||
androidAnalysisAvailability,
|
||||
} = registration;
|
||||
registerOpenLifecycleTool(registration);
|
||||
registerCloseLifecycleTool(registration);
|
||||
registerSessionStatusTool({
|
||||
@@ -151,6 +161,7 @@ const registerLifecycleTools = (
|
||||
contract: statusContract,
|
||||
startedAt,
|
||||
availabilityPolicy,
|
||||
androidAnalysisAvailability,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -206,6 +217,9 @@ const registerOpenLifecycleTool = ({
|
||||
export interface SessionToolOptions {
|
||||
readonly startedAt?: string;
|
||||
readonly availabilityPolicy?: () => SessionAvailability;
|
||||
readonly androidAnalysisAvailability?: (
|
||||
signal: AbortSignal,
|
||||
) => Promise<ProviderAvailability>;
|
||||
}
|
||||
|
||||
const registerContextTools = (
|
||||
@@ -265,6 +279,8 @@ export const registerSessionTools = (
|
||||
options.availabilityPolicy,
|
||||
{},
|
||||
),
|
||||
androidAnalysisAvailability:
|
||||
options.androidAnalysisAvailability ?? missingAndroidAvailability,
|
||||
});
|
||||
registerEvidenceTools({
|
||||
server,
|
||||
@@ -287,3 +303,11 @@ export const registerSessionTools = (
|
||||
registerUnknownTools({ server, session });
|
||||
registerContextTools(server, session);
|
||||
};
|
||||
|
||||
const missingAndroidAvailability = async (): Promise<ProviderAvailability> => ({
|
||||
status: "unavailable",
|
||||
code: "not_configured",
|
||||
reason:
|
||||
"Set REA_JADX_MCP_JAR to a caller-supplied jadx-headless-mcp 0.7.1 JAR and provide a full JDK on Linux or macOS.",
|
||||
diagnostics: { configured: false },
|
||||
});
|
||||
|
||||
@@ -16,7 +16,6 @@ export interface SessionAvailabilityDefaults {
|
||||
| "electronObservationEnabled"
|
||||
| "electronAutomationEnabled"
|
||||
| "v8InspectorObservationEnabled"
|
||||
| "androidAnalysisEnabled"
|
||||
| "javascriptRecoveryEnabled"
|
||||
| "webModuleResolutionEnabled"
|
||||
| "binaryLayoutEnabled"
|
||||
@@ -45,8 +44,6 @@ export const sessionAvailabilityPolicy = (
|
||||
defaults.optionalFeatures?.firmwareInspectionEnabled ?? false,
|
||||
firmwareExtractionEnabled:
|
||||
defaults.optionalFeatures?.firmwareExtractionEnabled ?? false,
|
||||
androidAnalysisEnabled:
|
||||
defaults.optionalFeatures?.androidAnalysisEnabled ?? false,
|
||||
javascriptRecoveryEnabled:
|
||||
defaults.optionalFeatures?.javascriptRecoveryEnabled ?? false,
|
||||
webModuleResolutionEnabled:
|
||||
|
||||
Reference in New Issue
Block a user