From 53c69ae41e4d118f279e029fb134dc2ace3a23e1 Mon Sep 17 00:00:00 2001 From: mxrain Date: Thu, 12 Feb 2026 14:21:04 +0800 Subject: [PATCH] fix: use cmd /c on Windows for shell command execution The exec tool was hardcoded to use 'sh -c' which doesn't exist on Windows, causing all tool calls to fail silently in gateway mode. --- pkg/tools/shell.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/tools/shell.go b/pkg/tools/shell.go index cddbcdb..9e5d03c 100644 --- a/pkg/tools/shell.go +++ b/pkg/tools/shell.go @@ -8,6 +8,7 @@ import ( "os/exec" "path/filepath" "regexp" + "runtime" "strings" "time" ) @@ -27,7 +28,7 @@ func NewExecTool(workingDir string, restrict bool) *ExecTool { regexp.MustCompile(`\brmdir\s+/s\b`), regexp.MustCompile(`\b(format|mkfs|diskpart)\b\s`), // Match disk wiping commands (must be followed by space/args) regexp.MustCompile(`\bdd\s+if=`), - regexp.MustCompile(`>\s*/dev/sd[a-z]\b`), // Block writes to disk devices (but allow /dev/null) + regexp.MustCompile(`>\s*/dev/sd[a-z]\b`), // Block writes to disk devices (but allow /dev/null) regexp.MustCompile(`\b(shutdown|reboot|poweroff)\b`), regexp.MustCompile(`:\(\)\s*\{.*\};\s*:`), } @@ -91,7 +92,12 @@ func (t *ExecTool) Execute(ctx context.Context, args map[string]interface{}) (st cmdCtx, cancel := context.WithTimeout(ctx, t.timeout) defer cancel() - cmd := exec.CommandContext(cmdCtx, "sh", "-c", command) + var cmd *exec.Cmd + if runtime.GOOS == "windows" { + cmd = exec.CommandContext(cmdCtx, "cmd", "/c", command) + } else { + cmd = exec.CommandContext(cmdCtx, "sh", "-c", command) + } if cwd != "" { cmd.Dir = cwd }