implemented shell_exec
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user