UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

85 lines (84 loc) • 3.02 kB
import { r as resolvePathViaExistingAncestorSync } from "./boundary-path-C2gXEiXe.mjs"; import { posix } from "node:path"; //#region src/agents/sandbox/bind-spec.ts /** * Parser for Docker-style host:container[:options] bind specs. */ /** Splits a bind spec while preserving Windows drive-letter prefixes in host paths. */ function splitSandboxBindSpec(e, t) { const n = getBindSeparatorIndex(e); if (n === -1) return null; const r = e.slice(0, n); const i = e.slice(n + 1); const a = t?.allowWindowsContainerPath === true ? getBindSeparatorIndex(i) : i.indexOf(":"); if (a === -1) return { host: r, container: i, options: "" }; return { host: r, container: i.slice(0, a), options: i.slice(a + 1) }; } function getBindSeparatorIndex(e) { const t = /^[A-Za-z]:[\\/]/.test(e); return e.indexOf(":", t ? 2 : 0); } //#endregion //#region src/agents/sandbox/host-paths.ts /** * Host path normalization for sandbox mount policy. * * Handles POSIX, Windows drive, and namespace-prefixed paths before policy-key comparison. */ function stripWindowsNamespacePrefix(e) { if (e.startsWith("\\\\?\\")) { const t = e.slice(4); if (t.toUpperCase().startsWith("UNC\\")) return `\\\\${t.slice(4)}`; return t; } if (e.startsWith("//?/")) { const t = e.slice(4); if (t.toUpperCase().startsWith("UNC/")) return `//${t.slice(4)}`; return t; } return e; } function isWindowsDriveAbsolutePath(e) { return /^[A-Za-z]:[\\/]/.test(stripWindowsNamespacePrefix(e)); } function isSandboxHostPathAbsolute(e) { const t = stripWindowsNamespacePrefix(e); return t.startsWith("/") || isWindowsDriveAbsolutePath(t); } /** * Normalize a host path: resolve `.`, `..`, collapse `//`, strip trailing `/`. * Windows drive-letter paths preserve the drive root and uppercase the drive letter. */ function normalizeSandboxHostPath(e) { const t = stripWindowsNamespacePrefix(e); if (!t) return "/"; let n = process.platform === "win32" || isWindowsDriveAbsolutePath(t) || e.startsWith("\\\\") || e.startsWith("//?/") ? t.replaceAll("\\", "/") : t; if (isWindowsDriveAbsolutePath(n)) n = n.charAt(0).toUpperCase() + n.slice(1); const r = posix.normalize(n).replace(/\/+$/, "") || "/"; if (/^[A-Z]:$/.test(r)) return `${r}/`; return r; } function getSandboxHostPathPolicyKey(e) { const t = normalizeSandboxHostPath(e); if (isWindowsDriveAbsolutePath(t)) return t.toLowerCase(); return t; } /** * Resolve a path through the deepest existing ancestor so parent symlinks are honored * even when the final source leaf does not exist yet. */ function resolveSandboxHostPathViaExistingAncestor(e) { if (!isSandboxHostPathAbsolute(e)) return e; if (isWindowsDriveAbsolutePath(e) && process.platform !== "win32") return normalizeSandboxHostPath(e); return normalizeSandboxHostPath(resolvePathViaExistingAncestorSync(e)); } //#endregion export { splitSandboxBindSpec as a, resolveSandboxHostPathViaExistingAncestor as i, isSandboxHostPathAbsolute as n, normalizeSandboxHostPath as r, getSandboxHostPathPolicyKey as t };