diff --git a/pkg/providers/openai_compat/provider.go b/pkg/providers/openai_compat/provider.go index 317a49308..8404531f0 100644 --- a/pkg/providers/openai_compat/provider.go +++ b/pkg/providers/openai_compat/provider.go @@ -7,6 +7,7 @@ import ( "encoding/json" "fmt" "io" + "log" "maps" "net/http" "net/url" diff --git a/pkg/tools/fs/filesystem.go b/pkg/tools/fs/filesystem.go index 661fd6caf..adc7fa998 100644 --- a/pkg/tools/fs/filesystem.go +++ b/pkg/tools/fs/filesystem.go @@ -1064,8 +1064,8 @@ func (r *sandboxFs) execute(path string, fn func(root *os.Root, relPath string) return err } - // os.Root api on windows only accept forward slashes (/) - relPath = filepath.ToSlash(relPath) + // os.Root API on Windows only accepts forward slashes (/). + relPath = normalizeRootRelPath(relPath) return fn(root, relPath) } @@ -1230,6 +1230,17 @@ func buildFs(workspace string, restrict bool, patterns []*regexp.Regexp) fileSys return sandbox } +func normalizeRootRelPath(relPath string) string { + return normalizeRootRelPathForSeparator(relPath, os.PathSeparator) +} + +func normalizeRootRelPathForSeparator(relPath string, sep rune) string { + if sep == '\\' { + return strings.ReplaceAll(relPath, `\`, `/`) + } + return relPath +} + // Helper to get a safe relative path for os.Root usage func getSafeRelPath(workspace, path string) (string, error) { if workspace == "" { diff --git a/pkg/tools/fs/filesystem_windows_path_test.go b/pkg/tools/fs/filesystem_windows_path_test.go new file mode 100644 index 000000000..c30146f35 --- /dev/null +++ b/pkg/tools/fs/filesystem_windows_path_test.go @@ -0,0 +1,21 @@ +package fstools + +import "testing" + +func TestNormalizeRootRelPathForWindowsSeparator(t *testing.T) { + got := normalizeRootRelPathForSeparator(`aaa\bbb\file.txt`, '\\') + want := "aaa/bbb/file.txt" + + if got != want { + t.Fatalf("normalizeRootRelPathForSeparator() = %q, want %q", got, want) + } +} + +func TestNormalizeRootRelPathForUnixSeparatorLeavesBackslashUnchanged(t *testing.T) { + input := `aaa\bbb\file.txt` + got := normalizeRootRelPathForSeparator(input, '/') + + if got != input { + t.Fatalf("normalizeRootRelPathForSeparator() = %q, want %q", got, input) + } +}