@@ -994,6 +994,9 @@ func (m *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
994 m.bangCancel = nil
994 m.bangCancel = nil
996 // Complete the pending shell item if it exists, otherwise create a new one.
996 // Complete the pending shell item if it exists, otherwise create a new one.
997+ // During session creation the pending item lives in m.pendingShellItem
998+ // rather than the chat list, so check both locations.
997 if msg.PendingID != "" {
1000 if msg.PendingID != "" {
998 if item := m.chat.MessageItem(msg.PendingID); item != nil {
1001 if item := m.chat.MessageItem(msg.PendingID); item != nil {
999 if shellItem, ok := item.(*chat.ShellItem); ok {
1002 if shellItem, ok := item.(*chat.ShellItem); ok {
@@ -1001,14 +1004,29 @@ func (m *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
1001 if cmd := m.chat.ScrollToBottomAndAnimate(); cmd != nil {
1004 if cmd := m.chat.ScrollToBottomAndAnimate(); cmd != nil {
1002 cmds = append(cmds, cmd)
1005 cmds = append(cmds, cmd)
1004− break
1007+ completed = true
1010+ if !completed && m.pendingShellItem != nil && m.pendingShellItem.ID() == msg.PendingID {
1011+ m.pendingShellItem.Complete(msg.Output, msg.ExitCode)
1012+ // The item is still stashed; it will be appended when the
1013+ // session load handler fires. Append it now so the result
1014+ // is visible immediately and clear the stash to prevent
1015+ // a duplicate append later.
1016+ m.chat.AppendMessages(m.pendingShellItem)
1017+ if cmd := m.chat.ScrollToBottomAndAnimate(); cmd != nil {
1018+ cmds = append(cmds, cmd)
1020+ m.pendingShellItem = nil
1008− item := chat.NewShellItem(m.com.Styles, msg.Command, msg.Output, msg.ExitCode)
1025+ item := chat.NewShellItem(m.com.Styles, msg.Command, msg.Output, msg.ExitCode)
1009− m.chat.AppendMessages(item)
1026+ m.chat.AppendMessages(item)
1010− if cmd := m.chat.ScrollToBottomAndAnimate(); cmd != nil {
1027+ if cmd := m.chat.ScrollToBottomAndAnimate(); cmd != nil {
1011− cmds = append(cmds, cmd)
1028+ cmds = append(cmds, cmd)
1013 case hyperRefreshDoneMsg:
1031 case hyperRefreshDoneMsg:
1014 if cmd := m.handleSelectModel(msg.action); cmd != nil {
1032 if cmd := m.handleSelectModel(msg.action); cmd != nil {