UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

46 lines (45 loc) 2.21 kB
import { N as normalizeExecutableToken, d as resolveShellWrapperTransportArgv, l as isShellWrapperExecutable, t as POSIX_PARSEABLE_SHELL_WRAPPERS } from "./shell-wrapper-resolution-CIQIf-gP.js"; import { n as explainShellCommand } from "./extract-rgReYDDg.js"; //#region src/infra/command-explainer/format.ts const POSIX_COMMAND_HIGHLIGHT_SHELLS = POSIX_PARSEABLE_SHELL_WRAPPERS; function spanToCommandSpan(span) { if (!Number.isSafeInteger(span.startIndex) || !Number.isSafeInteger(span.endIndex)) return null; if (span.startIndex < 0 || span.endIndex <= span.startIndex) return null; return { startIndex: span.startIndex, endIndex: span.endIndex }; } function isUnsupportedShellWrapperArgv(argv) { const executable = (resolveShellWrapperTransportArgv([...argv]) ?? argv)[0]; if (!executable) return false; const normalizedExecutable = normalizeExecutableToken(executable); return isShellWrapperExecutable(normalizedExecutable) && !POSIX_COMMAND_HIGHLIGHT_SHELLS.has(normalizedExecutable); } function hasUnsupportedShellWrapper(explanation) { return explanation.topLevelCommands.some((command) => isUnsupportedShellWrapperArgv(command.argv)); } /** Converts a parsed command explanation into source spans suitable for approval UI. */ function formatCommandSpans(explanation) { if (hasUnsupportedShellWrapper(explanation)) return []; const commandSpans = []; for (const command of [...explanation.topLevelCommands, ...explanation.nestedCommands]) { const commandSpan = spanToCommandSpan(command.executableSpan); if (commandSpan) commandSpans.push(commandSpan); } return commandSpans; } //#endregion //#region src/agents/bash-tools.exec-approval-request.runtime.ts /** * Lazy runtime for exec approval command highlighting. * Kept separate so importing approval request code does not load the command * explainer until command spans are explicitly requested. */ /** Resolve command spans used to highlight exec approval prompts. */ async function resolveExecApprovalCommandSpans(command) { const commandSpans = formatCommandSpans(await explainShellCommand(command)); return commandSpans.length > 0 ? commandSpans : void 0; } //#endregion export { resolveExecApprovalCommandSpans };