-
Notifications
You must be signed in to change notification settings - Fork 95
feat(termexec): handle agent animations #145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
3d3c7f8
f9036c1
dbbc9ca
8fc86c6
ba9f6db
33fdf77
11d2850
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,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 | ||
35C4n0r marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code is largely the same, but the continue removing variable seems new, perhaps we should ensure we've covered the new behavior with tests? |
||
| } | ||
|
|
||
| func removeAnimatedContent(screen string, agentType msgfmt.AgentType) (string, bool) { | ||
| lines := strings.Split(screen, "\n") | ||
| animatedContentEnd := -1 | ||
| var continueRemoving bool | ||
| if agentType == msgfmt.AgentTypeAmp { | ||
35C4n0r marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| animatedContentEnd, continueRemoving = calcAmpAnimatedContent(lines) | ||
| } else if agentType == msgfmt.AgentTypeOpencode { | ||
| animatedContentEnd, continueRemoving = calcOpencodeAnimatedContent(lines) | ||
| } else { | ||
| continueRemoving = false | ||
35C4n0r marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| return strings.Join(lines[animatedContentEnd+1:], "\n"), continueRemoving | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.