Skip to content

Open source AI coding agent. Designed for large projects and real world tasks.

Fix Windows line ending issues for file edits

Dane Schneider10a0a0a42e15
diff --git a/app/cli/lib/context_load.go b/app/cli/lib/context_load.go
index 77fbb983..1d27f8f2 100644
--- a/app/cli/lib/context_load.go
+++ b/app/cli/lib/context_load.go
@@ -538,6 +538,7 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) {
errCh <- fmt.Errorf("failed to read the file %s: %v", path, err)
return
}
+ fileContent = shared.NormalizeEOL(fileContent)
contextMu.Lock()
defer contextMu.Unlock()
diff --git a/app/shared/utils.go b/app/shared/utils.go
index 946253c6..d43e6f8b 100644
--- a/app/shared/utils.go
+++ b/app/shared/utils.go
@@ -1,6 +1,7 @@
package shared
import (
+ "bytes"
"crypto/rand"
"fmt"
"regexp"
@@ -136,3 +137,12 @@ func ReplaceReverse(s, old, new string, n int) string {
}
return res
}
+
+func NormalizeEOL(data []byte) []byte {
+ // CRLF -> LF
+ n := bytes.ReplaceAll(data, []byte{'\r', '\n'}, []byte{'\n'})
+
+ // treat stray CR as newline as well
+ n = bytes.ReplaceAll(n, []byte{'\r'}, []byte{'\n'})
+ return n
+}