The open source coding agent.
TypeScript
chore: messages cleanup
adamdotdevin9f5b59f3362c
diff --git a/packages/tui/internal/components/chat/cache.go b/packages/tui/internal/components/chat/cache.goindex ab034c411a8..454f1a5a942 100644--- a/packages/tui/internal/components/chat/cache.go+++ b/packages/tui/internal/components/chat/cache.go@@ -7,21 +7,21 @@ import ("sync")-// MessageCache caches rendered messages to avoid re-rendering-type MessageCache struct {+// PartCache caches rendered messages to avoid re-rendering+type PartCache struct {mu sync.RWMutexcache map[string]string}-// NewMessageCache creates a new message cache-func NewMessageCache() *MessageCache {- return &MessageCache{+// NewPartCache creates a new message cache+func NewPartCache() *PartCache {+ return &PartCache{cache: make(map[string]string),}}// generateKey creates a unique key for a message based on its content and rendering parameters-func (c *MessageCache) GenerateKey(params ...any) string {+func (c *PartCache) GenerateKey(params ...any) string {h := fnv.New64a()for _, param := range params {h.Write(fmt.Appendf(nil, ":%v", param))@@ -30,7 +30,7 @@ func (c *MessageCache) GenerateKey(params ...any) string {}// Get retrieves a cached rendered message-func (c *MessageCache) Get(key string) (string, bool) {+func (c *PartCache) Get(key string) (string, bool) {c.mu.RLock()defer c.mu.RUnlock()@@ -39,14 +39,14 @@ func (c *MessageCache) Get(key string) (string, bool) {}// Set stores a rendered message in the cache-func (c *MessageCache) Set(key string, content string) {+func (c *PartCache) Set(key string, content string) {c.mu.Lock()defer c.mu.Unlock()c.cache[key] = content}// Clear removes all entries from the cache-func (c *MessageCache) Clear() {+func (c *PartCache) Clear() {c.mu.Lock()defer c.mu.Unlock()@@ -54,7 +54,7 @@ func (c *MessageCache) Clear() {}// Size returns the number of cached entries-func (c *MessageCache) Size() int {+func (c *PartCache) Size() int {c.mu.RLock()defer c.mu.RUnlock()diff --git a/packages/tui/internal/components/chat/messages.go b/packages/tui/internal/components/chat/messages.goindex 9ee0a348ad6..436bf7107b1 100644--- a/packages/tui/internal/components/chat/messages.go+++ b/packages/tui/internal/components/chat/messages.go@@ -35,7 +35,7 @@ type messagesComponent struct {width intapp *app.Appviewport viewport.Model- cache *MessageCache+ cache *PartCacherendering boolshowToolDetails booltail bool@@ -128,10 +128,12 @@ func (m *messagesComponent) renderView(width int) {switch casted := message.Info.(type) {case opencode.UserMessage:- userLoop:for partIndex, part := range message.Parts {switch part := part.(type) {case opencode.TextPart:+ if part.Synthetic {+ continue+ }remainingParts := message.Parts[partIndex+1:]fileParts := make([]opencode.FilePart, 0)for _, part := range remainingParts {@@ -190,8 +192,6 @@ func (m *messagesComponent) renderView(width int) {m.lineCount += lipgloss.Height(content) + 1blocks = append(blocks, content)}- // Only render the first text part- break userLoop}}@@ -574,7 +574,7 @@ func NewMessagesComponent(app *app.App) MessagesComponent {app: app,viewport: vp,showToolDetails: true,- cache: NewMessageCache(),+ cache: NewPartCache(),tail: true,}}