Skip to content

Commit c6779b8

Browse files
committed
fix: use platform-aware shell detection for Windows compatibility
Replace hardcoded 'sh -c' and '$SHELL' fallbacks with shellpath.DetectShell() in skill command expansion, script_shell tools, post-edit hooks, and the TUI bang command. On Windows this resolves to PowerShell or cmd.exe instead of failing to find /bin/sh. Also aligns the post-edit hook env variable from 'path' to 'file', matching the documented ${file} syntax and avoiding conflict with zsh's special $path parameter (tied to $PATH).
1 parent c5ee4d7 commit c6779b8

File tree

5 files changed

+15
-8
lines changed

5 files changed

+15
-8
lines changed

pkg/app/app.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/docker/docker-agent/pkg/runtime"
2525
"github.com/docker/docker-agent/pkg/session"
2626
"github.com/docker/docker-agent/pkg/sessiontitle"
27+
"github.com/docker/docker-agent/pkg/shellpath"
2728
"github.com/docker/docker-agent/pkg/skills"
2829
"github.com/docker/docker-agent/pkg/tools"
2930
mcptools "github.com/docker/docker-agent/pkg/tools/mcp"
@@ -503,7 +504,8 @@ func (a *App) RunBangCommand(ctx context.Context, command string) {
503504
return
504505
}
505506

506-
out, err := exec.CommandContext(ctx, "/bin/sh", "-c", command).CombinedOutput()
507+
shell, argsPrefix := shellpath.DetectShell()
508+
out, err := exec.CommandContext(ctx, shell, append(argsPrefix, command)...).CombinedOutput()
507509
output := "$ " + command + "\n" + string(out)
508510
if err != nil && len(out) == 0 {
509511
output = "$ " + command + "\nError: " + err.Error()

pkg/skills/expand.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"regexp"
1111
"strings"
1212
"time"
13+
14+
"github.com/docker/docker-agent/pkg/shellpath"
1315
)
1416

1517
// commandTimeout is the maximum time allowed for a single command expansion.
@@ -47,7 +49,8 @@ func runCommand(ctx context.Context, command, workDir string) (string, error) {
4749
ctx, cancel := context.WithTimeout(ctx, commandTimeout)
4850
defer cancel()
4951

50-
cmd := exec.CommandContext(ctx, "sh", "-c", command)
52+
shell, argsPrefix := shellpath.DetectShell()
53+
cmd := exec.CommandContext(ctx, shell, append(argsPrefix, command)...)
5154
cmd.Dir = workDir
5255

5356
var stderr bytes.Buffer

pkg/tools/builtin/filesystem.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717

1818
"github.com/docker/docker-agent/pkg/chat"
1919
"github.com/docker/docker-agent/pkg/fsx"
20+
"github.com/docker/docker-agent/pkg/shellpath"
2021
"github.com/docker/docker-agent/pkg/tools"
2122
)
2223

@@ -354,9 +355,10 @@ func (t *FilesystemTool) executePostEditCommands(ctx context.Context, filePath s
354355
continue
355356
}
356357

357-
cmd := exec.CommandContext(ctx, "/bin/sh", "-c", postEdit.Cmd)
358+
shell, argsPrefix := shellpath.DetectShell()
359+
cmd := exec.CommandContext(ctx, shell, append(argsPrefix, postEdit.Cmd)...)
358360
cmd.Env = cmd.Environ()
359-
cmd.Env = append(cmd.Env, "path="+filePath)
361+
cmd.Env = append(cmd.Env, "file="+filePath)
360362

361363
if err := cmd.Run(); err != nil {
362364
return fmt.Errorf("post-edit command failed for %s: %w", filePath, err)

pkg/tools/builtin/filesystem_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ func main() {
413413
postEditConfigs := []PostEditConfig{
414414
{
415415
Path: "*.go",
416-
Cmd: "touch $path.formatted",
416+
Cmd: "touch $file.formatted",
417417
},
418418
}
419419
tool := NewFilesystemTool(tmpDir, WithPostEditCommands(postEditConfigs))

pkg/tools/builtin/script_shell.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"strings"
1313

1414
"github.com/docker/docker-agent/pkg/config/latest"
15+
"github.com/docker/docker-agent/pkg/shellpath"
1516
"github.com/docker/docker-agent/pkg/tools"
1617
)
1718

@@ -137,10 +138,9 @@ func (t *ScriptShellTool) execute(ctx context.Context, toolConfig *latest.Script
137138
}
138139
}
139140

140-
// Use default shell
141-
shell := cmp.Or(os.Getenv("SHELL"), "/bin/sh")
141+
shell, argsPrefix := shellpath.DetectShell()
142142

143-
cmd := exec.CommandContext(ctx, shell, "-c", toolConfig.Cmd)
143+
cmd := exec.CommandContext(ctx, shell, append(argsPrefix, toolConfig.Cmd)...)
144144
cmd.Dir = toolConfig.WorkingDir
145145
cmd.Env = t.env
146146
for key, value := range params {

0 commit comments

Comments
 (0)