mirror of
https://github.com/multica-ai/multica.git
synced 2026-06-17 03:38:32 +02:00
41 lines
802 B
Go
41 lines
802 B
Go
package daemon
|
|
|
|
import "strings"
|
|
|
|
const codexThreadNameMaxRunes = 120
|
|
|
|
func deriveTaskThreadName(task Task) string {
|
|
candidates := []string{
|
|
task.ThreadName,
|
|
task.AutopilotTitle,
|
|
task.QuickCreatePrompt,
|
|
task.ChatMessage,
|
|
task.TriggerCommentContent,
|
|
}
|
|
for _, candidate := range candidates {
|
|
if name := normalizeThreadName(candidate, codexThreadNameMaxRunes); name != "" {
|
|
return name
|
|
}
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func normalizeThreadName(s string, maxRunes int) string {
|
|
fields := strings.Fields(s)
|
|
if len(fields) == 0 {
|
|
return ""
|
|
}
|
|
normalized := strings.Join(fields, " ")
|
|
if maxRunes <= 0 {
|
|
return normalized
|
|
}
|
|
rs := []rune(normalized)
|
|
if len(rs) <= maxRunes {
|
|
return normalized
|
|
}
|
|
if maxRunes <= 3 {
|
|
return string(rs[:maxRunes])
|
|
}
|
|
return string(rs[:maxRunes-3]) + "..."
|
|
}
|