返回 DeepSeek-Reasonix
strip.go
根目录 / internal / history / strip.go
1 package history
2
3 import (
4 "regexp"
5 "strings"
6 )
7
8 var reComposeBlock = regexp.MustCompile(`(?s)^\s*<(?:memory-update|background-jobs|active-goal|hook-context)(?:\s+[^>]*)?>.*?</(?:memory-update|background-jobs|active-goal|hook-context)>\s*\n`)
9
10 const planModeMarkerPrefix = "[Plan mode"
11
12 func stripComposePrefixes(content string) string {
13 s := content
14 for {
15 next := reComposeBlock.ReplaceAllString(s, "")
16 if next == s {
17 break
18 }
19 s = next
20 }
21 trimmed := strings.TrimSpace(s)
22 if strings.HasPrefix(trimmed, planModeMarkerPrefix) {
23 if _, rest, ok := strings.Cut(trimmed, "]"); ok {
24 return strings.TrimSpace(rest)
25 }
26 }
27 return trimmed
28 }
29
29 lines GO