From 00b77572f06e2839e97ec6087fab1711b0bd52d3 Mon Sep 17 00:00:00 2001 From: John Henry Rudden Date: Fri, 25 Jul 2025 17:03:12 -0500 Subject: [PATCH] fix: deduplicate attachments by path --- .../tui/internal/components/chat/editor.go | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/tui/internal/components/chat/editor.go b/packages/tui/internal/components/chat/editor.go index 4311a4ca7..638d9d65f 100644 --- a/packages/tui/internal/components/chat/editor.go +++ b/packages/tui/internal/components/chat/editor.go @@ -440,7 +440,27 @@ func (m *editorComponent) Submit() (tea.Model, tea.Cmd) { var cmds []tea.Cmd attachments := m.textarea.GetAttachments() - prompt := app.Prompt{Text: value, Attachments: attachments} + // Deduplicate by path + seen := make(map[string]bool) + deduped := make([]*attachment.Attachment, 0, len(attachments)) + for _, att := range attachments { + var path string + if fs, ok := att.GetFileSource(); ok { + path = fs.Path + } else if ss, ok := att.GetSymbolSource(); ok { + path = ss.Path + } else { + // Not a file or symbol source, just add it + deduped = append(deduped, att) + continue + } + + if path != "" && !seen[path] { + seen[path] = true + deduped = append(deduped, att) + } + } + prompt := app.Prompt{Text: value, Attachments: deduped} m.app.State.AddPromptToHistory(prompt) cmds = append(cmds, m.app.SaveState())