Files
openclaw/extensions/mxc/src/binary-resolver.ts
Paul Campbell 008f04a656 feat(mxc): add Windows MXC sandbox backend (#97086)
* feat(mxc): add Windows MXC sandbox backend

Add the official MXC sandbox plugin package with Windows ProcessContainer execution, plugin-owned MXC SDK dependency packaging, host-backed filesystem bridge support, and configured MXC policy file loading via mxcPolicyPaths.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(mxc): preserve Windows binary override paths

* fix: remove stray sandbox barrel export

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 9ea19539-b8ca-44fb-93bd-b8496e3deb2c

* fix(mxc): address sandbox review feedback

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(mxc): satisfy test type checks

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(mxc): clarify protected skill enforcement

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(mxc): align fail-closed expectations

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(mxc): satisfy extension lint

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(plugin-sdk): narrow fs-safe remove surface

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(mxc): repair rebased CI failures

* fix(scripts): declare shrinkwrap override normalizer

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Gio Della-Libera <235387111+giodl73-repo@users.noreply.github.com>
Co-authored-by: Dallin Romney <dallinromney@gmail.com>
2026-07-12 23:07:25 -07:00

75 lines
2.2 KiB
TypeScript

import * as fs from "node:fs";
import { createRequire } from "node:module";
import * as path from "node:path";
/**
* Resolve the bin/ directory inside the installed @microsoft/mxc-sdk package.
* Returns the arch-specific subdirectory (x64 or arm64) if available.
*/
function resolveSdkBinDir(): string | null {
try {
const require = createRequire(import.meta.url);
const sdkPkgPath = require.resolve("@microsoft/mxc-sdk/package.json");
const sdkRoot = path.dirname(sdkPkgPath);
const arch = process.arch === "arm64" ? "arm64" : "x64";
const archBin = path.join(sdkRoot, "bin", arch);
if (fs.existsSync(archBin)) {
return archBin;
}
// Fallback to flat bin/ if no arch subdirectory
const flatBin = path.join(sdkRoot, "bin");
if (fs.existsSync(flatBin)) {
return flatBin;
}
} catch {
// SDK not installed; skip.
}
return null;
}
function buildSearchPaths(binary: string, sdkBinDir: string | null): string[] {
return sdkBinDir ? [path.join(sdkBinDir, binary)] : [];
}
/** SDK-owned search paths for wxc-exec on Windows. */
function wxcSearchPaths(): string[] {
return buildSearchPaths("wxc-exec.exe", resolveSdkBinDir());
}
function findBinary(searchPaths: string[]): string | null {
for (const p of searchPaths) {
if (fs.existsSync(p)) {
return p;
}
}
return null;
}
/**
* Resolves the MXC executor binary path.
* @param configOverride Optional user-configured path override.
* @returns Absolute path to the binary.
* @throws If the binary cannot be found.
*/
export function resolveMxcBinaryPath(configOverride?: string): string {
if (configOverride) {
const resolvedOverride = path.win32.isAbsolute(configOverride)
? configOverride
: path.resolve(configOverride);
if (!fs.existsSync(resolvedOverride)) {
throw new Error(`MXC binary not found at configured path: ${configOverride}`);
}
return resolvedOverride;
}
const binaryName = "wxc-exec.exe";
const found = findBinary(wxcSearchPaths());
if (!found) {
throw new Error(
`MXC executor "${binaryName}" not found. Install @microsoft/mxc-sdk or set mxcBinaryPath in config.`,
);
}
return found;
}