Enha: more shell tools

This commit is contained in:
Grail Finder
2025-11-27 12:22:32 +03:00
parent 05cf4b8749
commit 4d3935c28b

View File

@@ -500,25 +500,27 @@ func executeCommand(args map[string]string) []byte {
func isCommandAllowed(command string) bool { func isCommandAllowed(command string) bool {
allowedCommands := map[string]bool{ allowedCommands := map[string]bool{
"grep": true, "grep": true,
"sed": true, "sed": true,
"awk": true, "awk": true,
"find": true, "find": true,
"cat": true, "cat": true,
"head": true, "head": true,
"tail": true, "tail": true,
"sort": true, "sort": true,
"uniq": true, "uniq": true,
"wc": true, "wc": true,
"ls": true, "ls": true,
"echo": true, "echo": true,
"cut": true, "cut": true,
"tr": true, "tr": true,
"cp": true, "cp": true,
"mv": true, "mv": true,
"rm": true, "rm": true,
"mkdir": true, "mkdir": true,
"rmdir": true, "rmdir": true,
"pwd": true,
"realpath": true,
} }
return allowedCommands[command] return allowedCommands[command]
} }
@@ -776,18 +778,18 @@ var baseTools = []models.Tool{
Type: "function", Type: "function",
Function: models.ToolFunc{ Function: models.ToolFunc{
Name: "execute_command", Name: "execute_command",
Description: "Execute a shell command safely. Use when you need to run system commands like grep sed awk find cat head tail sort uniq wc ls echo cut tr cp mv rm mkdir rmdir", Description: "Execute a shell command safely. Use when you need to run system commands like grep sed awk find cat head tail sort uniq wc ls echo cut tr cp mv rm mkdir rmdir pwd realpath",
Parameters: models.ToolFuncParams{ Parameters: models.ToolFuncParams{
Type: "object", Type: "object",
Required: []string{"command"}, Required: []string{"command"},
Properties: map[string]models.ToolArgProps{ Properties: map[string]models.ToolArgProps{
"command": models.ToolArgProps{ "command": models.ToolArgProps{
Type: "string", Type: "string",
Description: "command to execute (only commands from whitelist are allowed: grep sed awk find cat head tail sort uniq wc ls echo cut tr cp mv rm mkdir rmdir", Description: "command to execute (only commands from whitelist are allowed: grep sed awk find cat head tail sort uniq wc ls echo cut tr cp mv rm mkdir rmdir pwd realpath",
}, },
"args": models.ToolArgProps{ "args": models.ToolArgProps{
Type: "string", Type: "string",
Description: "command arguments as a single string (e.g., 'pattern file.txt')", Description: "command arguments as a single string (e.g., '-la {path}')",
}, },
}, },
}, },