diff --git a/internal/ui/model/ui.go b/internal/ui/model/ui.go index 70edceb6e715aa99e686faaa9fd69a776fe89505..a24417ecc04c06579a1753d8ab521bf4a1c5831a 100644 --- a/internal/ui/model/ui.go +++ b/internal/ui/model/ui.go @@ -387,6 +387,15 @@ func (m *UI) handleKeyPressMsg(msg tea.KeyPressMsg) (cmds []tea.Cmd) { switch m.state { case uiChat: switch { + case key.Matches(msg, m.keyMap.Chat.NewSession): + if m.com.App.AgentCoordinator == nil { + return cmds + } + if m.com.App.AgentCoordinator.IsBusy() { + // TODO: Show warning message once we have a message/toast system + return cmds + } + cmds = append(cmds, m.newSession()) case key.Matches(msg, m.keyMap.Tab): if m.focus == uiFocusMain { m.focus = uiFocusEditor @@ -1115,6 +1124,20 @@ func (m *UI) loadNestedToolCalls(msgID, toolCallID string) []chat.ToolCallContex return nestedContexts } +// newSession clears the current session and resets the UI to a fresh state. +func (m *UI) newSession() tea.Cmd { + if m.session == nil || m.session.ID == "" { + return nil + } + + m.session = nil + m.state = uiLanding + m.focus = uiFocusEditor + m.chat.SetMessages() + m.sessionFiles = nil + return m.textarea.Focus() +} + // renderLogo renders the Crush logo with the given styles and dimensions. func renderLogo(t *styles.Styles, compact bool, width int) string { return logo.Render(version.Version, compact, logo.Opts{