refactor(cli): share runtime between CLI and MCP

This commit is contained in:
morluto
2026-07-12 07:44:21 +08:00
parent d9c9025ffb
commit 97541d8dad
6 changed files with 113 additions and 109 deletions
+28
View File
@@ -0,0 +1,28 @@
import { fileURLToPath } from "node:url";
import type { AppConfig } from "../config.js";
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. */
export const createBinarySession = (config: AppConfig): BinarySession => {
const bridgeScriptPath = fileURLToPath(
new URL("../../bridge/hopper_bridge.py", import.meta.url),
);
return new BinarySession(
(target) =>
new HopperClient({
launcher: new HopperApplicationLauncher({
launcherPath: config.hopperLauncherPath,
targetPath: target.path,
targetKind: target.kind,
loaderArgs:
config.hopperLoaderArgs.length > 0
? config.hopperLoaderArgs
: target.loaderArgs,
bridgeScriptPath,
}),
}),
);
};