@@ -177,6 +177,10 @@ func (m *UI) Init() tea.Cmd {
177177 return tea.Batch(cmds...)
178178}
179179
180+// sessionLoadedDoneMsg indicates that session loading and message appending is
181+// done.
182+type sessionLoadedDoneMsg struct{}
183+
180184// Update handles updates to the UI model.
181185func (m *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
182186 var cmds []tea.Cmd
@@ -194,7 +198,15 @@ func (m *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
194198 for _, message := range msgs {
195199 m.chat.AppendMessage(message)
196200 }
201+ // Notify that session loading is done to scroll to bottom. This is
202+ // needed because we need to draw the chat list first before we can
203+ // scroll to bottom.
204+ cmds = append(cmds, func() tea.Msg {
205+ return sessionLoadedDoneMsg{}
206+ })
207+ case sessionLoadedDoneMsg:
197208 m.chat.ScrollToBottom()
209+ m.chat.SelectLast()
198210 case sessionFilesLoadedMsg:
199211 m.sessionFiles = msg.files
200212 case pubsub.Event[history.File]: