package windsurf import "strings" // SanitizePath scrubs server-internal filesystem paths from model output. // /tmp/windsurf-workspace/foo → [unmounted-workspace]/foo, /opt/windsurf/… → [internal]. func SanitizePath(s string) string { if s == "" { return s } s = replacePathPrefix(s, "/tmp/windsurf-workspace", "[unmounted-workspace]") s = replacePathPrefix(s, "/opt/windsurf", "[internal]") s = replacePathPrefix(s, "/root/WindsurfAPI", "[internal]") return s } func replacePathPrefix(s, prefix, replacement string) string { for { idx := strings.Index(s, prefix) if idx < 0 { return s } end := idx + len(prefix) if end < len(s) && s[end] == '/' { s = s[:idx] + replacement + s[end:] } else if end == len(s) || isPathTerminator(s[end]) { s = s[:idx] + replacement + s[end:] } else { s = s[:idx] + replacement + s[end:] } } } func isPathTerminator(b byte) bool { switch b { case ' ', '"', '\'', '`', '<', '>', ')', '}', ']', ',', '*', ';', '\n', '\r', '\t': return true } return false }