@@ -23,7 +23,8 @@ func (m Model) handleLLMUser(msg llmUserMsg) (tea.Model, tea.Cmd) {
2323 // handleUserMsg records a user message in the conversation display.
2424 func (m *Model) handleUserMsg(msg llmUserMsg) (Model, tea.Cmd) {
2525 now := time.Now()
26- userMsg := provider.Message{Role: "user", Content: msg.content, CreatedAt: now}
26+ llmMsg := provider.Message{Role: "user", Content: msg.content, CreatedAt: now}
27+ storeMsg := provider.Message{Role: "user", Content: msg.display, CreatedAt: now}
2728
2829 convIdx := len(m.convEntries)
2930
@@ -39,7 +40,7 @@ func (m *Model) handleUserMsg(msg llmUserMsg) (Model, tea.Cmd) {
3940 })
4041
4142 m.appendText("")
42- m.appendText(highlightMarkdown(msg.content, m.styles.Text)...)
43+ m.appendText(highlightMarkdown(msg.display, m.styles.Text)...)
4344 wasBottom := m.appendText("")
4445 m.turnInputTokens = 0
4546 m.turnOutputTokens = 0
@@ -47,24 +48,24 @@ func (m *Model) handleUserMsg(msg llmUserMsg) (Model, tea.Cmd) {
4748 if wasBottom {
4849 m.scrollOffset = 0
4950 }
50- cmd := m.saveUserMessageCmd(userMsg, convIdx)
51+ cmd := m.saveUserMessageCmd(llmMsg, storeMsg, convIdx)
5152 return *m, cmd
5253 }
5354
54-func (m *Model) saveUserMessageCmd(userMsg provider.Message, convIdx int) tea.Cmd {
55+func (m *Model) saveUserMessageCmd(llmMsg, storeMsg provider.Message, convIdx int) tea.Cmd {
5556 store := m.store
5657 sessionID := m.sessionID
5758 if store == nil {
5859 return func() tea.Msg {
59- return userMsgSavedMsg{convIdx: convIdx, dbMsgID: 0, userMsg: userMsg}
60+ return userMsgSavedMsg{convIdx: convIdx, dbMsgID: 0, userMsg: llmMsg}
6061 }
6162 }
6263 return func() tea.Msg {
63- id, err := store.SaveMessageSync(sessionID, messageToStore(userMsg))
64+ id, err := store.SaveMessageSync(sessionID, messageToStore(storeMsg))
6465 if err != nil {
65- return userMsgSavedMsg{convIdx: convIdx, dbMsgID: 0, userMsg: userMsg, err: err}
66+ return userMsgSavedMsg{convIdx: convIdx, dbMsgID: 0, userMsg: llmMsg, err: err}
6667 }
67- return userMsgSavedMsg{convIdx: convIdx, dbMsgID: id, userMsg: userMsg}
68+ return userMsgSavedMsg{convIdx: convIdx, dbMsgID: id, userMsg: llmMsg}
6869 }
6970 }
7071
@@ -84,10 +85,11 @@ func (m Model) handleUserMsgSaved(msg userMsgSavedMsg) (tea.Model, tea.Cmd) {
8485 }
8586 m.llmInFlight = true
8687 m.turnCtx, m.turnCancel = context.WithCancel(context.Background())
87- var extra []provider.Message
88- if msg.dbMsgID == 0 {
89- extra = append(extra, msg.userMsg)
90- }
88+ // Always supply the current user message via extra so the LLM receives the
89+ // expanded form (@ mentions replaced with file content). When the store is
90+ // present the display form was saved to DB; we need to exclude it from the
91+ // loaded history to avoid sending a duplicate.
92+ extra := []provider.Message{msg.userMsg}
9193 return m, tea.Batch(m.processLLMWithExtra(extra), m.waitForLLMUpdate())
9294 }
9395