Files
rea/src/ghidra/GhidraClientStartup.ts
T
morluto 63bf91405c refactor!: enforce canonical evidence and provider boundaries
Deliver complete Evidence directly through MCP with required nullable analysis profiles and immutable per-server delivery settings. Bind selected environments at construction and require typed cleanup outcomes with retained retry ownership.

Remove test-only routing, duplicate session and snapshot metadata, producer-field repairs, and ambiguous provider arguments. Separate artifact byte identity from occurrence classification and retain typed source-map and partial native facts across CLI, MCP, and verifier consumers.

BREAKING CHANGE: obsolete Evidence envelopes, session aliases, incomplete snapshots, and missing normalized producer facts are no longer accepted.
2026-10-09 20:18:52 +08:00

71 lines
2.3 KiB
TypeScript

import type { JsonValue } from "../domain/jsonValue.js";
import { err, type Result } from "../domain/result.js";
import type { ProviderStartupDeadline } from "../process/ProviderDeadline.js";
import type { GhidraRequestOptions } from "./GhidraClientTypes.js";
import type {
GhidraSessionError,
GhidraSessionErrorOptions,
GhidraSessionFailureKind,
} from "./GhidraSessionError.js";
import type { GhidraSessionInfo } from "./GhidraSessionValues.js";
/** Inputs needed to complete the post-connection bridge handshake. */
export interface GhidraStartupHandshakeOptions {
readonly deadline: ProviderStartupDeadline;
readonly request: (
method: string,
params: JsonValue,
options: GhidraRequestOptions,
) => Promise<Result<JsonValue, GhidraSessionError>>;
readonly parseSessionInfo: (
value: JsonValue,
) => Result<GhidraSessionInfo, GhidraSessionError>;
readonly failure: (
kind: GhidraSessionFailureKind,
message: string,
cause?: unknown,
options?: Pick<GhidraSessionErrorOptions, "timeoutMs" | "remoteCode">,
) => GhidraSessionError;
readonly startupTimeoutMs: number;
}
/** Ping and validate the bridge after its socket is attached. */
export async function completeGhidraStartupHandshake(
options: GhidraStartupHandshakeOptions,
): Promise<Result<GhidraSessionInfo, GhidraSessionError>> {
const ping = await options.request(
"ping",
{},
{
signal: options.deadline.signal,
timeoutMs: options.deadline.remainingMs(),
},
);
if (!ping.ok) {
const failure = options.deadline.signal.aborted
? interruptionFailure(options)
: ping.error;
return err(failure);
}
const parsed = options.parseSessionInfo(ping.value);
if (!parsed.ok || parsed.value.analysis_timed_out) {
const failure = parsed.ok
? options.failure(
"analysis_timeout",
"Ghidra auto-analysis reached its per-file deadline",
)
: parsed.error;
return err(failure);
}
return parsed;
}
const interruptionFailure = (
options: GhidraStartupHandshakeOptions,
): GhidraSessionError =>
options.deadline.interruption === "cancelled"
? options.failure("cancelled", "Ghidra startup was cancelled")
: options.failure("timeout", "Ghidra startup deadline elapsed", undefined, {
timeoutMs: options.startupTimeoutMs,
});