oclaw/runtime/tools/public/local_run_command_tool.py
2026-04-30 23:18:58 +08:00

39 lines
1.4 KiB
Python

from __future__ import annotations
from typing import Any
from oclaw.runtime.tools.base import ToolSpec
from oclaw.runtime.tools.local_sdk import get_local_adapter
def local_run_command_tool() -> ToolSpec:
def _handler(args: dict[str, Any]) -> dict[str, Any]:
command = str(args.get("command") or "").strip()
if not command:
return {"ok": False, "error_code": "command_required", "error": "command_required"}
cwd = str(args.get("cwd") or "").strip() or None
timeout = int(args.get("timeout") or 30)
return get_local_adapter().run_command(command=command, cwd=cwd, timeout=timeout)
return ToolSpec(
name="local_run_command",
description="Run a shell command via local backend.",
parameters={
"type": "object",
"properties": {
"command": {"type": "string", "description": "Shell command to execute."},
"cwd": {"type": "string", "description": "Optional working directory."},
"timeout": {"type": "integer", "description": "Timeout in seconds.", "default": 30},
},
"required": ["command"],
"additionalProperties": False,
},
handler=_handler,
tags=frozenset({"public", "local", "exec", "workspace"}),
risk_level="high",
timeout_s=90.0,
read_only=False,
)
__all__ = ["local_run_command_tool"]