implemented shell_exec

This commit is contained in:
Luxferre
2026-03-21 17:11:17 +02:00
parent a2af89e61f
commit 6e2294cb48
6 changed files with 101 additions and 2 deletions
+35
View File
@@ -3,6 +3,7 @@ package sidekick
import (
"fmt"
"os"
"os/exec"
"regexp"
"strings"
)
@@ -69,9 +70,43 @@ func DefaultInternalTools() map[string]ToolDefinition {
Internal: true,
Handler: editFileHandler,
},
"shell_exec": {
Name: "shell_exec",
Description: "Run a POSIX shell command and return its combined stdout and stderr.",
Parameters: map[string]interface{}{
"type": "object",
"properties": map[string]interface{}{
"command": map[string]interface{}{"type": "string"},
},
"required": []string{"command"},
},
Internal: true,
Handler: shellExecHandler,
},
}
}
func shellExecHandler(args map[string]interface{}) (string, error) {
cmdStr, ok := args["command"].(string)
if !ok {
return "", fmt.Errorf("command is required")
}
cmd := exec.Command("sh", "-c", cmdStr)
output, err := cmd.CombinedOutput()
result := string(output)
if err != nil {
result = fmt.Sprintf("%s\nError: %v", result, err)
}
if result == "" {
return "(empty output)", nil
}
return result, nil
}
func readFileHandler(args map[string]interface{}) (string, error) {
path, ok := args["path"].(string)
if !ok {