docs: record runtime and release constraints
This commit is contained in:
@@ -13,10 +13,17 @@ import type { HopperToolPort } from "./HopperToolPort.js";
|
||||
export interface BinaryClient extends HopperToolPort {
|
||||
close(): Promise<void>;
|
||||
}
|
||||
/** Production seam for creating a target-scoped Hopper client. */
|
||||
/** Production seam for creating one unstarted client for a parsed target. */
|
||||
export type BinaryClientFactory = (target: BinaryTarget) => BinaryClient;
|
||||
|
||||
/** Serializes target transitions while allowing calls within the active session. */
|
||||
/**
|
||||
* Owns the single active target shared by CLI and MCP adapters.
|
||||
*
|
||||
* Target transitions are serialized because each client dispatches Hopper API
|
||||
* work on its dedicated Python thread, and switching targets tears that bridge
|
||||
* down. A failed switch recreates the previous target instead of retaining a
|
||||
* client whose bridge was already shut down.
|
||||
*/
|
||||
export class BinarySession implements HopperToolPort {
|
||||
#active:
|
||||
| { readonly target: BinaryTarget; readonly client: BinaryClient }
|
||||
@@ -25,7 +32,10 @@ export class BinarySession implements HopperToolPort {
|
||||
readonly #calls = new Set<Promise<unknown>>();
|
||||
constructor(readonly createClient: BinaryClientFactory) {}
|
||||
|
||||
/** Open or switch to a target, retaining the old session when the new one fails. */
|
||||
/**
|
||||
* Open or switch targets after draining calls against the current target.
|
||||
* Returns the switch failure even if best-effort restoration also fails.
|
||||
*/
|
||||
open(
|
||||
path: string,
|
||||
options: { readonly signal?: AbortSignal } = {},
|
||||
@@ -82,7 +92,11 @@ export class BinarySession implements HopperToolPort {
|
||||
};
|
||||
}
|
||||
|
||||
/** Invoke a Hopper tool against the active target. */
|
||||
/**
|
||||
* Invoke a Hopper tool against the active target.
|
||||
* Calls may overlap, but a pending target transition prevents new calls from
|
||||
* entering until the transition has settled.
|
||||
*/
|
||||
async callTool(
|
||||
name: string,
|
||||
arguments_: Readonly<Record<string, JsonValue>>,
|
||||
|
||||
@@ -2,7 +2,11 @@ import { parseConfig } from "../config.js";
|
||||
import type { JsonValue } from "../hopper/protocol.js";
|
||||
import { createBinarySession } from "./runtime.js";
|
||||
|
||||
/** Open one binary, execute one tool, and always release the target session. */
|
||||
/**
|
||||
* Open one binary, execute one tool, and always release the bridge session.
|
||||
* Unlike MCP mode, every CLI invocation is intentionally isolated and does not
|
||||
* retain a target or bridge resources for a subsequent command.
|
||||
*/
|
||||
export const runDirectAnalysis = async (
|
||||
path: string,
|
||||
tool: "binary_overview" | "procedure_pseudo_code",
|
||||
|
||||
@@ -19,7 +19,7 @@ export interface DoctorCheck {
|
||||
readonly detail?: string;
|
||||
readonly remediation?: string;
|
||||
}
|
||||
/** Host facts and effects required by diagnostics. */
|
||||
/** Read-only host capabilities required by diagnostics. */
|
||||
export interface DoctorHost {
|
||||
readonly platform: NodeJS.Platform;
|
||||
readonly nodeVersion: string;
|
||||
@@ -30,7 +30,11 @@ export interface DoctorHost {
|
||||
manualHopperPaths(): Promise<readonly string[]>;
|
||||
}
|
||||
|
||||
/** Check requirements and an optional target without mutating the host. */
|
||||
/**
|
||||
* Check requirements and an optional target without mutating the host.
|
||||
* Every failed check includes remediation suitable for either the one-shot CLI
|
||||
* or an agent consuming the structured result.
|
||||
*/
|
||||
export const runDoctor = async (
|
||||
target?: string,
|
||||
host: DoctorHost = systemDoctorHost(),
|
||||
|
||||
@@ -21,11 +21,15 @@ import type { JsonValue } from "../hopper/protocol.js";
|
||||
|
||||
type EnhancedResult = Promise<Result<JsonValue, HopperError>>;
|
||||
|
||||
/** Application services composing official Hopper operations into eight RE tools. */
|
||||
/**
|
||||
* Composes official Hopper operations into bounded reverse-engineering tools.
|
||||
* Inputs are parsed again at this application boundary even though MCP normally
|
||||
* validates them, allowing direct callers to use the same service safely.
|
||||
*/
|
||||
export class EnhancedTools {
|
||||
constructor(private readonly hopper: HopperToolPort) {}
|
||||
|
||||
/** Parse and dispatch one enhanced tool call. */
|
||||
/** Parse inputs again at the direct-call boundary, then dispatch exhaustively. */
|
||||
execute(
|
||||
name: EnhancedToolName,
|
||||
input: unknown,
|
||||
|
||||
@@ -4,6 +4,11 @@ import type { JsonValue } from "../hopper/protocol.js";
|
||||
|
||||
/** Application-owned capability for invoking one official Hopper tool. */
|
||||
export interface HopperToolPort {
|
||||
/**
|
||||
* Invoke a declared bridge operation with JSON-safe arguments.
|
||||
* Implementations return expected Hopper, timeout, and cancellation failures
|
||||
* as values and must honor an already-aborted signal.
|
||||
*/
|
||||
callTool(
|
||||
name: string,
|
||||
arguments_: Readonly<Record<string, JsonValue>>,
|
||||
|
||||
@@ -34,7 +34,11 @@ export type ClientConfigurationResult =
|
||||
readonly status: "failed";
|
||||
readonly reason: "backup" | "write" | "readback";
|
||||
};
|
||||
/** Effects required by the idempotent setup workflow. */
|
||||
/**
|
||||
* Effects required by the idempotent setup workflow.
|
||||
* Implementations report interrupted installers as values: setup must not wait
|
||||
* indefinitely for stdin or a GUI response in an unattended agent invocation.
|
||||
*/
|
||||
export interface SetupHost {
|
||||
readonly platform: NodeJS.Platform;
|
||||
readonly nodeVersion: string;
|
||||
@@ -48,7 +52,11 @@ export interface SetupHost {
|
||||
installSkill(): Promise<"installed" | "unchanged" | "failed">;
|
||||
doctor(): Promise<Awaited<ReturnType<typeof runDoctor>>>;
|
||||
}
|
||||
/** Structured setup outcome with actionable partial progress. */
|
||||
/**
|
||||
* Structured setup outcome intended to travel back through an agent to a human.
|
||||
* `needs_human` carries remediation text instead of initiating an interactive
|
||||
* prompt, avoiding deadlocks in stdio and other unattended environments.
|
||||
*/
|
||||
export interface SetupResult {
|
||||
readonly status: "ready" | "needs_human";
|
||||
readonly actions: readonly string[];
|
||||
@@ -57,7 +65,11 @@ export interface SetupResult {
|
||||
readonly remediation?: string;
|
||||
}
|
||||
|
||||
/** Install prerequisites and configure every detected supported client idempotently. */
|
||||
/**
|
||||
* Install prerequisites and configure detected clients idempotently.
|
||||
* With `yes` false, mutations requiring consent are reported as `needs_human`;
|
||||
* with `yes` true, external installers still fail closed if they require UI.
|
||||
*/
|
||||
export const runSetup = async (
|
||||
yes: boolean,
|
||||
host: SetupHost = systemSetupHost(),
|
||||
|
||||
@@ -5,7 +5,11 @@ export const HOMEBREW_COMMANDS = [
|
||||
"/usr/local/bin/brew",
|
||||
] as const;
|
||||
|
||||
/** Return the first successful result from the standard Homebrew executables. */
|
||||
/**
|
||||
* Return the first defined result from standard Homebrew executables.
|
||||
* A probe returning `undefined` means that location was unavailable or failed;
|
||||
* other falsy values are successful results and stop discovery.
|
||||
*/
|
||||
export const probeHomebrew = async <T>(
|
||||
probe: (command: string) => Promise<T | undefined>,
|
||||
): Promise<T | undefined> => {
|
||||
|
||||
@@ -5,7 +5,11 @@ import { BinarySession } from "./BinarySession.js";
|
||||
import { HopperApplicationLauncher } from "../hopper/BridgeLauncher.js";
|
||||
import { HopperClient } from "../hopper/HopperClient.js";
|
||||
|
||||
/** Create the target-switching session used by both the CLI and MCP adapters. */
|
||||
/**
|
||||
* Compose the target-switching runtime shared directly by CLI and MCP adapters.
|
||||
* This is the sole production wiring point for Hopper so neither adapter shells
|
||||
* out to the other and both retain identical loader and bridge semantics.
|
||||
*/
|
||||
export const createBinarySession = (config: AppConfig): BinarySession => {
|
||||
const bridgeScriptPath = fileURLToPath(
|
||||
new URL("../../bridge/hopper_bridge.py", import.meta.url),
|
||||
|
||||
+5
-1
@@ -6,7 +6,11 @@ import { runDirectAnalysis } from "./application/DirectAnalysis.js";
|
||||
import { runSetup } from "./application/Setup.js";
|
||||
import { PRODUCT_IDENTITY } from "./identity.js";
|
||||
|
||||
/** Build the Incur command tree for the non-MCP CLI commands. */
|
||||
/**
|
||||
* Build the one-shot Incur CLI without starting Hopper at import time.
|
||||
* Analysis commands acquire and close their own sessions; bare `mcp` and
|
||||
* `--mcp` are intercepted by the executable dispatcher before this module loads.
|
||||
*/
|
||||
export const createCli = (): ReturnType<typeof Cli.create> => {
|
||||
const cli = Cli.create(PRODUCT_IDENTITY.cliBinary, {
|
||||
version: "0.1.0",
|
||||
|
||||
+6
-1
@@ -20,7 +20,12 @@ const environmentSchema = z.object({
|
||||
HOPPER_LOADER_ARGS_JSON: z.string().optional(),
|
||||
});
|
||||
|
||||
/** Parse Hopper launcher configuration once at the composition root. */
|
||||
/**
|
||||
* Parse Hopper launcher configuration once at the composition root.
|
||||
* Explicit loader arguments override REA's header-derived defaults for a
|
||||
* supported target, allowing callers to refine Hopper's loader behavior without
|
||||
* bypassing REA's path and executable-header checks.
|
||||
*/
|
||||
export const parseConfig = (
|
||||
environment: Readonly<Record<string, string | undefined>>,
|
||||
): Result<AppConfig, ConfigurationError> => {
|
||||
|
||||
@@ -12,10 +12,10 @@ const caseSensitive = z
|
||||
.default(false)
|
||||
.describe("Whether to match case");
|
||||
|
||||
/** The architectural owner of a tool implementation. */
|
||||
/** Adapter family responsible for implementing a public MCP tool. */
|
||||
export type ToolKind = "official-proxy" | "enhanced" | "session";
|
||||
|
||||
/** Stable caller-visible contract retained across the Python-to-TypeScript migration. */
|
||||
/** Single source of truth for a public tool's name, description, and input. */
|
||||
export interface ToolContract {
|
||||
readonly name: string;
|
||||
readonly description: string;
|
||||
@@ -41,7 +41,7 @@ const session = (
|
||||
inputSchema: z.ZodObject,
|
||||
): ToolContract => ({ name, description, kind: "session", inputSchema });
|
||||
|
||||
/** All 31 tools forwarded unchanged to Hopper's official MCP server. */
|
||||
/** Bridge operations exposed without additional application composition. */
|
||||
export const OFFICIAL_TOOL_CONTRACTS = [
|
||||
official(
|
||||
"address_name",
|
||||
@@ -180,7 +180,7 @@ export const OFFICIAL_TOOL_CONTRACTS = [
|
||||
),
|
||||
] as const satisfies readonly ToolContract[];
|
||||
|
||||
/** All 8 reverse-engineering tools implemented by REA. */
|
||||
/** Bounded workflows composed from one or more bridge operations. */
|
||||
export const ENHANCED_TOOL_CONTRACTS = [
|
||||
enhanced(
|
||||
"swift_classes",
|
||||
@@ -224,7 +224,7 @@ export const ENHANCED_TOOL_CONTRACTS = [
|
||||
),
|
||||
] as const satisfies readonly ToolContract[];
|
||||
|
||||
/** Binary lifecycle tools available before Hopper is launched. */
|
||||
/** Target lifecycle tools available only on the long-lived MCP adapter. */
|
||||
export const SESSION_TOOL_CONTRACTS = [
|
||||
session(
|
||||
"open_binary",
|
||||
@@ -235,7 +235,11 @@ export const SESSION_TOOL_CONTRACTS = [
|
||||
session("binary_session", "Describe the active binary session", z.object({})),
|
||||
] as const satisfies readonly ToolContract[];
|
||||
|
||||
/** Complete caller-visible tool inventory. */
|
||||
/**
|
||||
* Complete ordered public inventory used by registration and verification.
|
||||
* Keep this collection at 42 tools unless a deliberate contract change updates
|
||||
* snapshots, package verification, and real-Hopper verification together.
|
||||
*/
|
||||
export const TOOL_CONTRACTS = [
|
||||
...OFFICIAL_TOOL_CONTRACTS,
|
||||
...ENHANCED_TOOL_CONTRACTS,
|
||||
|
||||
@@ -7,7 +7,11 @@ import { err, ok, type Result } from "./result.js";
|
||||
|
||||
/** CPU families understood by the supported executable loaders. */
|
||||
export type BinaryArchitecture = "x86" | "x86_64" | "arm" | "arm64";
|
||||
/** A parsed binary target and the Hopper launcher arguments it requires. */
|
||||
/**
|
||||
* A canonical local target plus deterministic Hopper loader arguments.
|
||||
* Explicit loader and architecture flags prevent Hopper from presenting modal
|
||||
* format or FAT-architecture selection dialogs during agent-driven analysis.
|
||||
*/
|
||||
export interface BinaryTarget {
|
||||
readonly path: string;
|
||||
readonly kind: "executable" | "database";
|
||||
@@ -17,7 +21,11 @@ export interface BinaryTarget {
|
||||
readonly loaderArgs: readonly string[];
|
||||
}
|
||||
|
||||
/** Resolve, read, and classify a local binary path, including its architecture metadata. */
|
||||
/**
|
||||
* Resolve and classify a readable local target before Hopper is launched.
|
||||
* FAT Mach-O inputs select only a host-compatible architecture so setup remains
|
||||
* non-interactive; unsupported or ambiguous inputs are returned as typed errors.
|
||||
*/
|
||||
export const parseBinaryTarget = async (
|
||||
input: string,
|
||||
cwd = process.cwd(),
|
||||
@@ -53,7 +61,11 @@ type ExecutableMetadata = Pick<
|
||||
"format" | "architecture" | "availableArchitectures" | "loaderArgs"
|
||||
>;
|
||||
|
||||
/** Parse supported executable headers without performing I/O. */
|
||||
/**
|
||||
* Parse supported executable headers without I/O and derive explicit Hopper
|
||||
* loader arguments. The caller must supply the host architecture used for FAT
|
||||
* Mach-O slice selection.
|
||||
*/
|
||||
export const parseExecutableHeader = (
|
||||
bytes: Buffer,
|
||||
hostArchitecture: NodeJS.Architecture,
|
||||
|
||||
@@ -38,7 +38,19 @@ export interface HopperApplicationLauncherOptions {
|
||||
readonly bridgeScriptPath: string;
|
||||
}
|
||||
|
||||
/** Launches Hopper through its documented CLI and injects only the owned bridge script. */
|
||||
/**
|
||||
* Launches Hopper through its documented CLI and injects only REA's owned bridge.
|
||||
*
|
||||
* Hopper's `hopper` helper internally issues an AppleScript `activate` command.
|
||||
* Consequently, opening a target may bring Hopper to the foreground even though
|
||||
* REA first asks macOS to start the application hidden and in the background.
|
||||
* REA cannot reliably suppress that activation without replacing Hopper's
|
||||
* supported launcher; callers must treat possible foreground UI as an upstream
|
||||
* Hopper constraint, not as evidence that analysis failed.
|
||||
*
|
||||
* The returned process is the short-lived launcher helper, not the Hopper app,
|
||||
* so REA does not claim ownership of the application's lifetime.
|
||||
*/
|
||||
export class HopperApplicationLauncher implements BridgeLauncher {
|
||||
constructor(readonly options: HopperApplicationLauncherOptions) {}
|
||||
|
||||
@@ -103,6 +115,8 @@ const prepareHopperApplication = async (
|
||||
if (appBundle === undefined) return;
|
||||
const executablePath = join(appBundle, "Contents/MacOS/Hopper Disassembler");
|
||||
if (await processIsRunning(executablePath)) return;
|
||||
// This reduces activation when Hopper is cold, but the vendor launcher that
|
||||
// follows may still activate its window. See HopperApplicationLauncher.
|
||||
await execFileAsync("/usr/bin/open", [
|
||||
"--hide",
|
||||
"--background",
|
||||
|
||||
+5
-1
@@ -1,4 +1,8 @@
|
||||
/** Public REA identifiers kept together for consistent packaging and setup. */
|
||||
/**
|
||||
* Canonical public identity shared by packaging, setup, MCP, and skill install.
|
||||
* Centralization prevents persistent client registrations from drifting from
|
||||
* the npm package or executable exposed in package.json.
|
||||
*/
|
||||
export const PRODUCT_IDENTITY = {
|
||||
displayName: "REA",
|
||||
packageName: "@morluto/rea",
|
||||
|
||||
+5
-1
@@ -12,7 +12,11 @@ import { parseConfig } from "./config.js";
|
||||
import { createBinarySession } from "./application/runtime.js";
|
||||
import { createServer } from "./server/createServer.js";
|
||||
|
||||
/** Start the production stdio server and install owned shutdown handlers. */
|
||||
/**
|
||||
* Start the long-lived MCP adapter and install idempotent shutdown handlers.
|
||||
* The adapter owns its BinarySession for the process lifetime; EOF and process
|
||||
* signals close bridge resources without assuming ownership of the Hopper app.
|
||||
*/
|
||||
export const run = async (): Promise<number> => {
|
||||
const config = parseConfig(process.env);
|
||||
if (!config.ok) {
|
||||
|
||||
@@ -7,7 +7,11 @@ import { registerEnhancedTools } from "./registerEnhancedTools.js";
|
||||
import { registerOfficialTools } from "./registerOfficialTools.js";
|
||||
import { registerSessionTools } from "./registerSessionTools.js";
|
||||
|
||||
/** Construct one MCP server instance without acquiring subprocess resources. */
|
||||
/**
|
||||
* Construct one MCP server without acquiring subprocess resources.
|
||||
* Supplying a session adds target lifecycle tools; omitting it retains the
|
||||
* fixed-target seam used by focused tests and embedders.
|
||||
*/
|
||||
export const createServer = (
|
||||
hopper: HopperToolPort,
|
||||
session?: BinarySession,
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
} from "../contracts/toolContracts.js";
|
||||
import { toCallToolResult } from "./toolResult.js";
|
||||
|
||||
/** Register all eight enhanced reverse-engineering tools. */
|
||||
/** Register composed workflows against the same port as direct bridge tools. */
|
||||
export const registerEnhancedTools = (
|
||||
server: McpServer,
|
||||
hopper: HopperToolPort,
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
import { jsonValueSchema, type JsonValue } from "../hopper/protocol.js";
|
||||
import { toCallToolResult } from "./toolResult.js";
|
||||
|
||||
/** Register every official Hopper proxy contract on one MCP server. */
|
||||
/** Register direct bridge proxies, preserving MCP cancellation and typed errors. */
|
||||
export const registerOfficialTools = (
|
||||
server: McpServer,
|
||||
hopper: HopperToolPort,
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { BinarySession } from "../application/BinarySession.js";
|
||||
import { SESSION_TOOL_CONTRACTS } from "../contracts/toolContracts.js";
|
||||
import { toCallToolResult } from "./toolResult.js";
|
||||
|
||||
/** Register binary lifecycle management tools. */
|
||||
/** Register MCP-only target lifecycle operations on a long-lived session. */
|
||||
export const registerSessionTools = (
|
||||
server: McpServer,
|
||||
session: BinarySession,
|
||||
|
||||
@@ -4,7 +4,11 @@ import type { HopperError } from "../domain/errors.js";
|
||||
import type { Result } from "../domain/result.js";
|
||||
import type { JsonValue } from "../hopper/protocol.js";
|
||||
|
||||
/** Translate an application result into caller-visible MCP content. */
|
||||
/**
|
||||
* Translate an application result into MCP text content.
|
||||
* Error tags and safe messages remain visible while underlying causes, process
|
||||
* output, and other potentially sensitive details stay private.
|
||||
*/
|
||||
export const toCallToolResult = (
|
||||
result: Result<JsonValue, HopperError>,
|
||||
): CallToolResult =>
|
||||
|
||||
Reference in New Issue
Block a user