UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

59 lines (58 loc) 3.35 kB
import { P as resolveExecApprovalsFromFile, f as loadExecApprovals } from "./exec-approvals-C6M6SGY3.js"; import path from "node:path"; //#region src/agents/bash-tools.descriptions.ts /** * Tool descriptions for bash exec and process-control tools. * Descriptions include platform-specific guidance and approved executable * hints that are safe to show to the model. */ /** * Show the exact approved token in hints. Absolute paths stay absolute so the * hint cannot imply an equivalent PATH lookup that resolves to a different binary. */ function deriveExecShortName(fullPath) { if (path.isAbsolute(fullPath)) return fullPath; const base = path.basename(fullPath); return base.replace(/\.exe$/i, "") || base; } /** Builds the model-facing exec tool description for the current platform/config. */ function describeExecTool(params) { const base = [ "Execute shell commands with background continuation for work that starts now.", "Use yieldMs/background to continue later via process tool.", "For long-running work started now, rely on automatic completion wake when it is enabled and the command emits output or fails; otherwise use process to confirm completion. Use process whenever you need logs, status, input, or intervention.", params?.hasCronTool ? "Do not use exec sleep or delay loops for reminders or deferred follow-ups; use cron instead." : void 0, "Use pty=true for TTY-required commands (terminal UIs, coding agents)." ].filter(Boolean).join(" "); if (process.platform !== "win32") return base; const lines = [base]; lines.push("IMPORTANT (Windows): Run executables directly; do NOT wrap commands in `cmd /c`, `powershell -Command`, `& ` prefix, or WSL. Use backslash paths (C:\\path), not forward slashes. Use short executable names (e.g. `node`, `python3`) instead of full paths."); try { const allowlist = resolveExecApprovalsFromFile({ file: loadExecApprovals(), agentId: params?.agentId }).allowlist.filter((entry) => { const pattern = entry.pattern?.trim() ?? ""; return pattern.length > 0 && pattern !== "*" && !pattern.startsWith("=command:") && (pattern.includes("/") || pattern.includes("\\") || pattern.includes("~")); }); if (allowlist.length > 0) { lines.push("Pre-approved executables (exact arguments are enforced at runtime; no approval prompt needed when args match):"); for (const entry of allowlist.slice(0, 10)) { const shortName = deriveExecShortName(entry.pattern); const argNote = entry.argPattern ? "(restricted args)" : "(any arguments)"; lines.push(` ${shortName} ${argNote}`); } } } catch {} return lines.join("\n"); } /** Builds the model-facing process-control tool description. */ function describeProcessTool(params) { return [ "Manage running exec sessions for commands already started: list, poll, log, write, send-keys, submit, paste, kill.", "Use poll/log when you need status, logs, quiet-success confirmation, or completion confirmation when automatic completion wake is unavailable. Use poll/log also for input-wait hints. Use write/send-keys/submit/paste/kill for input or intervention.", params?.hasCronTool ? "Do not use process polling to emulate timers or reminders; use cron for scheduled follow-ups." : void 0 ].filter(Boolean).join(" "); } //#endregion export { describeProcessTool as n, describeExecTool as t };