-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathutils.go
More file actions
59 lines (52 loc) · 1.84 KB
/
utils.go
File metadata and controls
59 lines (52 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package termexec
import (
"strings"
"github.com/coder/agentapi/lib/msgfmt"
)
func calcAmpAnimatedContent(lines []string) (int, bool) {
animatedContentEnd := -1
firstTextEncountered := false
continueRemoving := true
// search for the first 3 consecutive empty lines after the first text encountered.
if len(lines) > 3 {
for i := 0; i < len(lines)-3; i++ {
if !firstTextEncountered && len(strings.Trim(lines[i], " \n")) != 0 {
if strings.HasPrefix(strings.TrimSpace(lines[i]), "┃") {
continueRemoving = false
}
firstTextEncountered = true
}
if firstTextEncountered && len(strings.Trim(lines[i], " \n")) == 0 && len(strings.Trim(lines[i+1], " \n")) == 0 &&
len(strings.Trim(lines[i+2], " \n")) == 0 {
animatedContentEnd = i
break
}
}
}
return animatedContentEnd, continueRemoving
}
func calcOpencodeAnimatedContent(lines []string) (int, bool) {
// Skip header lines for Opencode agent type to avoid false positives
// The header contains dynamic content (token count, context percentage, cost)
// that changes between screens, causing line comparison mismatches:
//
// ┃ # Getting Started with Claude CLI ┃
// ┃ /share to create a shareable link 12.6K/6% ($0.05) ┃
if len(lines) >= 2 {
return 2, true
}
return -1, true
}
func removeAnimatedContent(screen string, agentType msgfmt.AgentType) (string, bool) {
lines := strings.Split(screen, "\n")
animatedContentEnd := -1
var continueRemoving bool
if agentType == msgfmt.AgentTypeAmp {
animatedContentEnd, continueRemoving = calcAmpAnimatedContent(lines)
} else if agentType == msgfmt.AgentTypeOpencode {
animatedContentEnd, continueRemoving = calcOpencodeAnimatedContent(lines)
} else {
continueRemoving = false
}
return strings.Join(lines[animatedContentEnd+1:], "\n"), continueRemoving
}