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
This commit is contained in:
@@ -34,10 +34,12 @@ export interface BridgeSession {
|
||||
}
|
||||
|
||||
/** Process handle returned by a bridge launcher. */
|
||||
export interface BridgeLaunch extends ProviderProcessLaunch {
|
||||
/** True when verified process cleanup completes bridge shutdown. */
|
||||
readonly shutdownByCleanup?: boolean;
|
||||
}
|
||||
export type BridgeLaunch =
|
||||
| (ProviderProcessLaunch & { readonly shutdownMode: "bridge-request" })
|
||||
| (Extract<ProviderProcessLaunch, { readonly ownsProcessLifetime: true }> & {
|
||||
readonly shutdownMode: "process-cleanup";
|
||||
readonly cleanup: NonNullable<ProviderProcessLaunch["cleanup"]>;
|
||||
});
|
||||
|
||||
/** Application-owned capability that starts the in-Hopper bridge. */
|
||||
export interface BridgeLauncher {
|
||||
@@ -184,7 +186,9 @@ export class HopperApplicationLauncher implements BridgeLauncher {
|
||||
process: child,
|
||||
ownsProcessLifetime: true,
|
||||
ownership: started.ownership,
|
||||
shutdownByCleanup: ownsProcessLifetime,
|
||||
shutdownMode: ownsProcessLifetime
|
||||
? "process-cleanup"
|
||||
: "bridge-request",
|
||||
cleanup: () => cleanupOwnedProcessGroup(started.ownership),
|
||||
});
|
||||
} catch (cause: unknown) {
|
||||
|
||||
@@ -75,9 +75,9 @@ export const hopperLoaderArgsForTarget = (
|
||||
target: BinaryTarget,
|
||||
): Result<readonly string[], ProviderAdapterError> => {
|
||||
if (target.kind === "database") return ok([]);
|
||||
const architecture = target.architecture;
|
||||
if (architecture === undefined)
|
||||
if (target.kind !== "executable")
|
||||
return err(new ProviderAdapterError("hopper", "resolve_analysis_profile"));
|
||||
const architecture = target.architecture;
|
||||
const flag = hopperArchitectureFlag(architecture);
|
||||
switch (target.format) {
|
||||
case "mach-o":
|
||||
@@ -90,10 +90,6 @@ export const hopperLoaderArgsForTarget = (
|
||||
return ok(["-l", "ELF", flag]);
|
||||
case "pe":
|
||||
return ok(["-l", "WinPE", flag]);
|
||||
default:
|
||||
return err(
|
||||
new ProviderAdapterError("hopper", "resolve_analysis_profile"),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@ interface CleanupState {
|
||||
readonly resources: Set<string>;
|
||||
cleanupResult: ProcessCleanupResult | undefined;
|
||||
shutdownConfirmed: boolean;
|
||||
ownedProcessStopped: boolean;
|
||||
}
|
||||
|
||||
export interface HopperCleanupInput {
|
||||
@@ -59,7 +58,6 @@ export const cleanupHopperSession = async (
|
||||
resources: new Set(),
|
||||
cleanupResult: undefined,
|
||||
shutdownConfirmed: false,
|
||||
ownedProcessStopped: false,
|
||||
};
|
||||
await report(input.progress, 0, "requesting Hopper document shutdown");
|
||||
await requestShutdown(input, state);
|
||||
@@ -97,8 +95,7 @@ const requestShutdown = async (
|
||||
if (
|
||||
shutdown.ok &&
|
||||
isHopperCleanupRequired(shutdown.value) &&
|
||||
input.launch?.shutdownByCleanup === true &&
|
||||
input.launch.cleanup !== undefined
|
||||
input.launch?.shutdownMode === "process-cleanup"
|
||||
) {
|
||||
state.cleanupResult = await input.launch
|
||||
.cleanup()
|
||||
@@ -161,7 +158,11 @@ const stopProcess = async (
|
||||
}
|
||||
input.logger.info(diagnostic, "Owned Hopper launcher shutdown completed");
|
||||
if (stopped.status !== "incomplete") {
|
||||
state.ownedProcessStopped = stopped.status !== "not-owned";
|
||||
if (
|
||||
input.launch?.shutdownMode === "process-cleanup" &&
|
||||
stopped.status !== "not-owned"
|
||||
)
|
||||
state.shutdownConfirmed = true;
|
||||
return;
|
||||
}
|
||||
const processGroupId = supervisor.launch.ownership?.processGroupId;
|
||||
@@ -183,8 +184,7 @@ const recordUnconfirmedDocument = (
|
||||
): void => {
|
||||
if (
|
||||
(input.socket === undefined && input.launch === undefined) ||
|
||||
state.shutdownConfirmed ||
|
||||
state.ownedProcessStopped
|
||||
state.shutdownConfirmed
|
||||
)
|
||||
return;
|
||||
state.resources.add("hopper-document");
|
||||
|
||||
@@ -537,6 +537,6 @@ const isAborted = (signal?: AbortSignal): boolean => signal?.aborted === true;
|
||||
const startupInterruption = (
|
||||
deadline: ProviderStartupDeadline,
|
||||
): HopperCancelledError | HopperTimeoutError =>
|
||||
deadline.cancelled
|
||||
deadline.interruption === "cancelled"
|
||||
? new HopperCancelledError()
|
||||
: new HopperTimeoutError(deadline.timeoutMs);
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import type { HopperDiagnosticType } from "../domain/errors.js";
|
||||
import type { ProcessCleanupResult } from "../process/ProcessOwnership.js";
|
||||
import type { ProviderProcessStopResult } from "../process/ProviderProcess.js";
|
||||
import type { BridgeLaunch } from "./BridgeLauncher.js";
|
||||
import type {
|
||||
ProviderProcessLaunch,
|
||||
ProviderProcessStopResult,
|
||||
} from "../process/ProviderProcess.js";
|
||||
|
||||
/** Sanitized Hopper launcher and owned-shutdown telemetry. */
|
||||
export type HopperDiagnostic =
|
||||
@@ -25,7 +27,7 @@ export type HopperDiagnostic =
|
||||
|
||||
/** Retain actionable ownership coordinates without exposing the run token. */
|
||||
export const createOwnedHopperShutdownDiagnostic = (
|
||||
launch: BridgeLaunch,
|
||||
launch: ProviderProcessLaunch,
|
||||
stopped: ProviderProcessStopResult,
|
||||
cleanup: ProcessCleanupResult | undefined,
|
||||
): Extract<HopperDiagnostic, { readonly type: "owned-shutdown" }> => ({
|
||||
|
||||
@@ -158,20 +158,6 @@ export class HopperProvider implements AnalysisProviderCandidate {
|
||||
reason: null,
|
||||
diagnostics,
|
||||
};
|
||||
if (!["mach-o", "elf", "pe"].includes(target.format))
|
||||
return {
|
||||
status: "unsupported",
|
||||
code: "target_format_unsupported",
|
||||
reason: `Hopper cannot open ${target.format} through this adapter.`,
|
||||
diagnostics,
|
||||
};
|
||||
if (target.architecture === undefined)
|
||||
return {
|
||||
status: "unsupported",
|
||||
code: "architecture_unsupported",
|
||||
reason: "Hopper requires a supported concrete target architecture.",
|
||||
diagnostics,
|
||||
};
|
||||
return {
|
||||
status: "supported",
|
||||
code: null,
|
||||
|
||||
@@ -10,6 +10,7 @@ import { cleanupOwnedProcessGroup } from "../process/ProcessOwnership.js";
|
||||
import {
|
||||
ProviderProcessSupervisor,
|
||||
spawnOwnedProviderProcess,
|
||||
type ProviderProcessLaunch,
|
||||
} from "../process/ProviderProcess.js";
|
||||
import { parseLinuxPrivateDisplayDiagnostic } from "./LinuxPrivateDisplayDiagnostic.js";
|
||||
|
||||
@@ -24,12 +25,11 @@ export type LinuxPrivateDisplayRunnableStrategy = Exclude<
|
||||
>;
|
||||
|
||||
export interface LinuxPrivateDisplayProbeProcessResult {
|
||||
readonly outcome: "exited" | "timed-out" | "cancelled" | "launch-failed";
|
||||
readonly exitCode: number | null | undefined;
|
||||
readonly stderr: string;
|
||||
readonly stderrBytes: number;
|
||||
readonly stderrTruncated: boolean;
|
||||
readonly timedOut: boolean;
|
||||
readonly cancelled: boolean;
|
||||
readonly cleanupIncomplete: boolean;
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ export const selectLinuxPrivateDisplayStrategy = async (options: {
|
||||
export const runLinuxPrivateDisplayProbe: LinuxPrivateDisplayProbeRunner =
|
||||
async (strategy, options) => {
|
||||
if (options.signal?.aborted === true)
|
||||
return emptyProcessResult({ cancelled: true });
|
||||
return emptyProcessResult("cancelled");
|
||||
const command = privateDisplayProbeCommand(options.helperPath, strategy);
|
||||
let started: Awaited<ReturnType<typeof spawnOwnedProviderProcess>>;
|
||||
try {
|
||||
@@ -114,9 +114,9 @@ export const runLinuxPrivateDisplayProbe: LinuxPrivateDisplayProbeRunner =
|
||||
expectedCommand: null,
|
||||
});
|
||||
} catch {
|
||||
return emptyProcessResult();
|
||||
return emptyProcessResult("launch-failed");
|
||||
}
|
||||
const launch = {
|
||||
const launch: ProviderProcessLaunch = {
|
||||
process: started.process,
|
||||
ownsProcessLifetime: true,
|
||||
cleanup: () => cleanupOwnedProcessGroup(started.ownership),
|
||||
@@ -136,12 +136,16 @@ export const runLinuxPrivateDisplayProbe: LinuxPrivateDisplayProbeRunner =
|
||||
} else supervisor.dispose();
|
||||
const snapshot = supervisor.snapshot();
|
||||
return {
|
||||
outcome:
|
||||
outcome === "exit"
|
||||
? "exited"
|
||||
: outcome === "timeout"
|
||||
? "timed-out"
|
||||
: "cancelled",
|
||||
exitCode: snapshot.exitCode,
|
||||
stderr: snapshot.stderr.text,
|
||||
stderrBytes: snapshot.stderr.bytes,
|
||||
stderrTruncated: snapshot.stderr.truncated,
|
||||
timedOut: outcome === "timeout",
|
||||
cancelled: outcome === "cancelled",
|
||||
cleanupIncomplete,
|
||||
};
|
||||
};
|
||||
@@ -204,16 +208,21 @@ const evaluatedProbe = async (
|
||||
diagnostic: syntheticDiagnostic(strategy, "probe_failed"),
|
||||
};
|
||||
}
|
||||
if (processResult.cancelled)
|
||||
if (processResult.outcome === "cancelled")
|
||||
return {
|
||||
ok: false,
|
||||
diagnostic: syntheticDiagnostic(strategy, "cancelled"),
|
||||
};
|
||||
if (processResult.timedOut)
|
||||
if (processResult.outcome === "timed-out")
|
||||
return {
|
||||
ok: false,
|
||||
diagnostic: syntheticDiagnostic(strategy, "probe_timeout"),
|
||||
};
|
||||
if (processResult.outcome === "launch-failed")
|
||||
return {
|
||||
ok: false,
|
||||
diagnostic: syntheticDiagnostic(strategy, "probe_failed"),
|
||||
};
|
||||
if (processResult.cleanupIncomplete)
|
||||
return {
|
||||
ok: false,
|
||||
@@ -288,16 +297,17 @@ const unavailable = (
|
||||
});
|
||||
|
||||
const emptyProcessResult = (
|
||||
overrides: Partial<LinuxPrivateDisplayProbeProcessResult> = {},
|
||||
outcome: Extract<
|
||||
LinuxPrivateDisplayProbeProcessResult["outcome"],
|
||||
"cancelled" | "launch-failed"
|
||||
>,
|
||||
): LinuxPrivateDisplayProbeProcessResult => ({
|
||||
outcome,
|
||||
exitCode: undefined,
|
||||
stderr: "",
|
||||
stderrBytes: 0,
|
||||
stderrTruncated: false,
|
||||
timedOut: false,
|
||||
cancelled: false,
|
||||
cleanupIncomplete: false,
|
||||
...overrides,
|
||||
});
|
||||
|
||||
const waitForProbeExit = async (
|
||||
|
||||
Reference in New Issue
Block a user