- windsurf_gateway_service: 添加上游延迟/TTFT/错误上下文记录 - endpoint: DeriveUpstreamEndpoint 添加 PlatformWindsurf 分支 - ops_error_logger: guessPlatformFromPath 添加 /windsurf/ 识别
41 lines
1.0 KiB
Go
41 lines
1.0 KiB
Go
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
|
|
}
|