返回 DeepSeek-Reasonix
fork.go
1 // Package sessiontitle contains title transforms shared by conversation hosts.
2 package sessiontitle
3
4 import (
5 "math/big"
6 "regexp"
7 "strings"
8 )
9
10 var (
11 asciiForkSuffix = regexp.MustCompile(`^(.*) \(([0-9]+)\)$`)
12 fullwidthForkSuffix = regexp.MustCompile(`^(.*)(([0-9]+))$`)
13 )
14
15 // IncreaseFork returns the DeepSeek Harness-style title for an independent
16 // child conversation. Existing ASCII and fullwidth numeric suffixes are
17 // incremented without changing the source title's punctuation style.
18 func IncreaseFork(title string) string {
19 base := strings.TrimSpace(title)
20 if base == "" {
21 return ""
22 }
23 if next, ok := increaseSuffix(base, asciiForkSuffix, " (", ")"); ok {
24 return next
25 }
26 if next, ok := increaseSuffix(base, fullwidthForkSuffix, "(", ")"); ok {
27 return next
28 }
29 return base + " (1)"
30 }
31
32 func increaseSuffix(title string, pattern *regexp.Regexp, open, close string) (string, bool) {
33 match := pattern.FindStringSubmatch(title)
34 if len(match) != 3 {
35 return "", false
36 }
37 n, ok := new(big.Int).SetString(match[2], 10)
38 if !ok {
39 return "", false
40 }
41 n.Add(n, big.NewInt(1))
42 return match[1] + open + n.String() + close, true
43 }
44
44 lines GO