Import ducklm runtime
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from app.core.contracts import ToolResult, UserTask
|
||||
from app.tools.base import BaseTool
|
||||
from app.tools.sandbox import ToolSandbox
|
||||
|
||||
|
||||
class Tool(BaseTool):
|
||||
name = "file_write"
|
||||
description = "Write content to file"
|
||||
|
||||
def __init__(self, sandbox: ToolSandbox) -> None:
|
||||
self._sandbox = sandbox
|
||||
|
||||
def execute(self, task: UserTask, args: dict[str, object]) -> ToolResult:
|
||||
path = args.get("path")
|
||||
content = str(args.get("content", ""))
|
||||
if not path:
|
||||
return ToolResult(tool=self.name, ok=False, error="Missing path")
|
||||
try:
|
||||
resolved = self._sandbox.ensure_path_allowed(str(path))
|
||||
resolved.parent.mkdir(parents=True, exist_ok=True)
|
||||
resolved.write_text(content, encoding="utf-8")
|
||||
return ToolResult(
|
||||
tool=self.name,
|
||||
ok=True,
|
||||
output=f"Wrote {len(content)} bytes",
|
||||
metadata={"path": str(resolved), "size": len(content)},
|
||||
)
|
||||
except PermissionError as e:
|
||||
return ToolResult(tool=self.name, ok=False, error=f"Access denied: {e}")
|
||||
except Exception as e:
|
||||
return ToolResult(tool=self.name, ok=False, error=f"Error: {e}")
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "file_write",
|
||||
"version": "1.0",
|
||||
"entrypoint": "Tool",
|
||||
"description": "Write content to file",
|
||||
"args_schema": {
|
||||
"path": {"type": "string", "required": true, "description": "File path to write"},
|
||||
"content": {"type": "string", "required": true, "description": "Content to write"}
|
||||
},
|
||||
"requires_permission": true
|
||||
}
|
||||
Reference in New Issue
Block a user