diff --git a/lib/httpapi/server.go b/lib/httpapi/server.go index b97f8da..f425b54 100644 --- a/lib/httpapi/server.go +++ b/lib/httpapi/server.go @@ -326,6 +326,16 @@ func (s *Server) StartSnapshotLoop(ctx context.Context) { // Send initial prompt when agent becomes stable for the first time if !s.conversation.InitialPromptSent && convertStatus(currentStatus) == AgentStatusStable { + + // If agent type is opencode + if s.agentType == mf.AgentTypeOpencode { + time.Sleep(5 * time.Second) + // If we still have it as stable, go ahead. + if convertStatus(s.conversation.Status()) != AgentStatusStable { + continue + } + } + if err := s.conversation.SendMessage(FormatMessage(s.agentType, s.conversation.InitialPrompt)...); err != nil { s.logger.Error("Failed to send initial prompt", "error", err) } else { diff --git a/lib/msgfmt/message_box.go b/lib/msgfmt/message_box.go index ce4eeee..32aa55d 100644 --- a/lib/msgfmt/message_box.go +++ b/lib/msgfmt/message_box.go @@ -70,8 +70,8 @@ func removeOpencodeMessageBox(msg string) string { // ┃ ┃ // We only check for the first ┃ and then an empty line above it - as sometimes the full input block does not load within a snapshot, // this leads to displaying a bunch of newlines. - for i := len(lines) - 1; i >= 1; i-- { - if strings.TrimSpace(lines[i-1]) == "" && + for i := len(lines) - 1; i >= 2; i-- { + if strings.ReplaceAll(lines[i-2], " ", "") != "┃┃" && strings.ReplaceAll(lines[i], " ", "") == "┃┃" { lines = lines[:i-1] break diff --git a/lib/msgfmt/msgfmt.go b/lib/msgfmt/msgfmt.go index 0cf1ca8..6660a63 100644 --- a/lib/msgfmt/msgfmt.go +++ b/lib/msgfmt/msgfmt.go @@ -262,6 +262,7 @@ func formatCodexMessage(message string, userInput string) string { } func formatOpencodeMessage(message string, userInput string) string { + message = RemoveUserInput(message, userInput, AgentTypeOpencode) message = removeOpencodeMessageBox(message) message = trimEmptyLines(message)