handleClearSession resets the current tab by creating a fresh session in the same working directory.
()
| 1424 | // handleClearSession resets the current tab by creating a fresh session |
| 1425 | // in the same working directory. |
| 1426 | func (m *appModel) handleClearSession() (tea.Model, tea.Cmd) { |
| 1427 | activeID := m.supervisor.ActiveID() |
| 1428 | |
| 1429 | // Cleanup old editor for the active session. |
| 1430 | if ed, ok := m.editors[activeID]; ok { |
| 1431 | ed.Cleanup() |
| 1432 | } |
| 1433 | |
| 1434 | // Create a fresh session in the same app, preserving the working dir. |
| 1435 | m.application.NewSession() |
| 1436 | newSess := m.application.Session() |
| 1437 | |
| 1438 | // Rebuild all per-session UI components. |
| 1439 | m.initSessionComponents(activeID, m.application, newSess) |
| 1440 | m.dialogMgr = dialog.New() |
| 1441 | m.supervisor.SetRunnerTitle(activeID, "") |
| 1442 | m.sessionState.SetSessionTitle("") |
| 1443 | m.sessionState.SetPreviousMessage(nil) |
| 1444 | |
| 1445 | // Update persisted tab to point to the new session. |
| 1446 | if m.tuiStore != nil { |
| 1447 | ctx := m.ctx() |
| 1448 | oldPersistedID := m.persistedSessionID(activeID) |
| 1449 | if err := m.tuiStore.UpdateTabSessionID(ctx, oldPersistedID, newSess.ID); err != nil { |
| 1450 | slog.WarnContext(ctx, "Failed to update tab session ID after clear", "error", err) |
| 1451 | } |
| 1452 | } |
| 1453 | m.persistActiveTab(newSess.ID) |
| 1454 | |
| 1455 | m.reapplyKeyboardEnhancements() |
| 1456 | |
| 1457 | return m, tea.Sequence( |
| 1458 | m.chatPage.Init(), |
| 1459 | m.resizeAll(), |
| 1460 | m.editor.Focus(), |
| 1461 | ) |
| 1462 | } |
| 1463 | |
| 1464 | // handleSpawnSession spawns a new session. |
| 1465 | func (m *appModel) handleSpawnSession(workingDir string) (tea.Model, tea.Cmd) { |
no test coverage detected