mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 14:59:05 +00:00
* fix(setup): name the analysis tool to add when none is ready When no native analysis tool is ready, setup names the one to add for this operating system and links its guide, and automatic provider selection says so plainly. Its recovery lists only providers this host can run, explains each, asks the agent to get the person's agreement before setting one up, and says what REA can still do without one. Fixes #17292 * fix(providers): explain missing tools and ask before setting them up Each external tool's repair for a missing installation now starts with what the tool is and what setting it up installs, from one domain table, and tells the agent to ask the person before installing it. The no-ready-provider recovery skips providers this host refuses or that refused the target, Kuna reports an unsupported host before its unset command, and IDA's repair carries its description in remediationAction. AGENTS.md notes that agents are the primary users, with a person behind them who may not know what is missing. * fix(android): keep JADX release metadata loadable from source Pre-install fixture scripts import JadxRelease.ts directly, so it stays dependency-free. JadxConfiguration adds the tool description where it reports a missing JAR. * fix(pcap): keep the tool refusal reason in the repair action pcapToolUnavailable had set remediationAction to the shared tshark setup text alone, so the projected action dropped the refusal reason while the message kept only the bare steps. adb and apktool still project both as `${reason}. ${toolSetupRemediation(...)}` through providerConfigurationRefusal. The helper now puts that same combined text in userMessage and leaves remediationAction unset, so the projection copies it into the action. The pcap CLI tests assert the reason, the Wireshark steps, and the tshark setup prefix in both fields. * fix(pcap): carry the tool-setup repair on the refusal itself The recovery guide requires each refusal to carry its remediation; shared projection formats those facts and must not fill them in. pcapToolUnavailable had left remediationAction unset so the action was copied from the message. The helper now sets remediationAction to PCAP_TOOL_REMEDIATION and keeps the reason in userMessage. providerConfigurationRefusal, which adb and apktool use, does the same with the configuration's own repair. CLI tests check the reason and the repair separately. * test(android): expect the tool repair in remediation, not the message
161 lines
5.7 KiB
TypeScript
161 lines
5.7 KiB
TypeScript
import type { CapabilityAvailabilityProbes } from "../application/CapabilityAvailability.js";
|
|
import { runtimeNativeMatchingAllowance } from "../config/runtimeAnalysisSettings.js";
|
|
import type { EvidenceMcpServer } from "./EvidenceMcpServer.js";
|
|
import type { ArtifactResourceScope } from "../resources/index.js";
|
|
import type { BinarySessionPort } from "../application/binary/BinarySessionPort.js";
|
|
import { ProcessCaptureResourceScope } from "../process/capture/ProcessCaptureLifecycle.js";
|
|
import { ProcessCaptureError } from "../process/capture/ProcessCaptureError.js";
|
|
import { AnalysisError } from "../domain/analysisErrorBase.js";
|
|
import { err, ok } from "../domain/result.js";
|
|
import type { Logger } from "pino";
|
|
import type { ProviderAvailability } from "../ports/AnalysisProvider.js";
|
|
import { registerServiceTools } from "./serviceToolBindings.js";
|
|
import type { SessionLifecycleOptions } from "./sessionLifecycle.js";
|
|
import type { SessionStatusToolOptions } from "./sessionStatusTool.js";
|
|
import { sessionAvailabilityPolicy } from "./sessionAvailabilityPolicy.js";
|
|
import {
|
|
type AvailabilityPolicy,
|
|
UNCONFIGURED_JADX_REMEDIATION,
|
|
} from "../application/CapabilityInventory.js";
|
|
import { withAdmittedAnalysis } from "./analysisAdmission.js";
|
|
import { errorMessage } from "../kernel/errorMessage.js";
|
|
import type { ArtifactPathInspectionDependencies } from "../application/artifacts/ArtifactPathInspection.js";
|
|
|
|
/** What the lifecycle and status tools of one session need. */
|
|
interface LifecycleToolRegistration
|
|
extends SessionStatusToolOptions, SessionLifecycleOptions {}
|
|
|
|
/** Close, reset and status run outside analysis admission; the session orders them. */
|
|
const registerLifecycleTools = (
|
|
registration: LifecycleToolRegistration,
|
|
): void => {
|
|
registerServiceTools(
|
|
registration.server,
|
|
{ sessionLifecycle: registration, sessionStatus: registration },
|
|
{ logger: registration.logger },
|
|
);
|
|
};
|
|
|
|
/** Register MCP-only target lifecycle operations on a long-lived session. */
|
|
export interface SessionToolOptions extends Partial<CapabilityAvailabilityProbes> {
|
|
readonly artifactResources: ArtifactResourceScope;
|
|
/** Server environment snapshot that process capture resolves and inherits. */
|
|
readonly environment: Readonly<NodeJS.ProcessEnv>;
|
|
/** The host process capture plans for and runs on. */
|
|
readonly platform: NodeJS.Platform;
|
|
readonly startedAt?: string;
|
|
readonly availabilityPolicy?: () => AvailabilityPolicy;
|
|
/** Inventories compare_artifacts path sources. */
|
|
readonly createArtifactPathInspection?: () => Promise<ArtifactPathInspectionDependencies>;
|
|
}
|
|
|
|
export const registerSessionTools = (
|
|
server: EvidenceMcpServer,
|
|
session: BinarySessionPort,
|
|
logger: Logger,
|
|
options: SessionToolOptions,
|
|
): void => {
|
|
const processResources = new ProcessCaptureResourceScope();
|
|
registerLifecycleTools({
|
|
...options,
|
|
server,
|
|
session,
|
|
logger,
|
|
startedAt: options.startedAt ?? new Date().toISOString(),
|
|
availabilityPolicy: sessionAvailabilityPolicy(
|
|
options.availabilityPolicy,
|
|
{},
|
|
options.platform,
|
|
),
|
|
androidAnalysisAvailability:
|
|
options.androidAnalysisAvailability ?? missingAndroidAvailability,
|
|
closeProcessResources: async () => {
|
|
try {
|
|
await processResources.retryCleanup();
|
|
return ok(null);
|
|
} catch (cause: unknown) {
|
|
if (cause instanceof AnalysisError) return err(cause);
|
|
return err(
|
|
new ProcessCaptureError(
|
|
"process capture cleanup remains incomplete",
|
|
{
|
|
cause,
|
|
reason: "cleanup_incomplete",
|
|
cleanup: {
|
|
reason: "process capture cleanup remains incomplete",
|
|
resources: ["process_capture_resources"],
|
|
},
|
|
executionFailure:
|
|
cause instanceof Error
|
|
? cause.message || cause.name
|
|
: String(cause),
|
|
},
|
|
),
|
|
);
|
|
}
|
|
},
|
|
});
|
|
server.registerCloseHook(() => processResources.close(), {
|
|
failureMessage: "REA session cleanup failed",
|
|
alwaysAggregate: true,
|
|
});
|
|
server.registerTransportCloseHook(() => {
|
|
void processResources.close().catch((cause: unknown) => {
|
|
logger.error(
|
|
{ error: errorMessage(cause) },
|
|
"Process capture cleanup failed during server shutdown",
|
|
);
|
|
});
|
|
});
|
|
registerServiceTools(
|
|
server,
|
|
{
|
|
binaryTarget: session,
|
|
analysisContext: {},
|
|
processCapture: {
|
|
session,
|
|
environment: options.environment,
|
|
platform: options.platform,
|
|
resources: processResources,
|
|
},
|
|
sessionDerived: {
|
|
session,
|
|
resources: options.artifactResources,
|
|
createArtifactPathInspection: options.createArtifactPathInspection,
|
|
},
|
|
sessionRecords: { session, resources: options.artifactResources },
|
|
},
|
|
{
|
|
logger,
|
|
withAdmittedAnalysis: withAdmittedAnalysis({ kind: "session", session }),
|
|
},
|
|
);
|
|
// Native matching records in the session itself and reads each accepted
|
|
// call's settings snapshot over the launch value.
|
|
registerServiceTools(
|
|
server,
|
|
{
|
|
nativeFunctionMatching: {
|
|
session,
|
|
allowance: runtimeNativeMatchingAllowance(
|
|
options.environment,
|
|
server.analysisSettings?.read,
|
|
),
|
|
},
|
|
},
|
|
{
|
|
logger,
|
|
recordEvidence: (evidence) => session.recordEvidence(evidence),
|
|
withAdmittedAnalysis: withAdmittedAnalysis({ kind: "session", session }),
|
|
},
|
|
);
|
|
};
|
|
|
|
const missingAndroidAvailability = async (): Promise<ProviderAvailability> => ({
|
|
status: "unavailable",
|
|
code: "not_configured",
|
|
reason: "No Android JADX analysis provider is configured.",
|
|
remediation: UNCONFIGURED_JADX_REMEDIATION,
|
|
diagnostics: { configured: false },
|
|
});
|