Files
rea/src/ghidra/GhidraClientStartup.ts
T
morlutoandGitHub b8a9da0c0f refactor(mcp): make analysis states unrepresentable (#468)
* refactor(config): parse capability settings into exact states

* refactor(runtime): encode replay and process outcomes exactly

* refactor: make analysis states unrepresentable

* refactor(mcp): register canonical schemas with SDK

* fix: preserve capability and catalog invariants

* fix(build): remove stale compiled modules

* fix(replay): update real verifier policy dependency

* fix(package): verify the complete MCP catalog

* fix(test): supply complete replay reload policy

* refactor(contracts): centralize output schema lookup

* refactor(mcp): delegate protocol boundaries to SDK

* fix(browser): approve real source capture

* fix(mcp): preserve catalog guidance
2026-08-10 02:28:11 +08:00

74 lines
2.4 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 cleanup: () => Promise<void>;
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;
await options.cleanup();
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;
await options.cleanup();
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,
});