diff --git a/components/SessionSidebar-chrome.tsx b/components/SessionSidebar-chrome.tsx index ed9f90df2..2dde5a106 100644 --- a/components/SessionSidebar-chrome.tsx +++ b/components/SessionSidebar-chrome.tsx @@ -4,7 +4,7 @@ import { useCallback, useEffect, useLayoutEffect, useRef, useState, type CSSProp import { createPortal } from "react-dom"; import { useI18n } from "@/lib/i18n"; import { usePrefersReducedMotion } from "@/hooks/usePrefersReducedMotion"; -import { AlertTriangle } from "lucide-react"; +import { AlertTriangle, Check } from "lucide-react"; import OmpWebLogo from "./OmpWebLogo"; /** * Path label that ellipsizes on the LEFT, keeping the (most relevant) trailing @@ -417,6 +417,27 @@ function ExitedSessionIndicator({ title, size = 14 }: { title: string; size?: nu ); } +function RecentlyCompletedIndicator({ size = 12 }: { size?: number }) { + const { t } = useI18n(); + return ( + + + ); +} + function UnreadSessionIndicator({ size = 14 }: { size?: number }) { const { t } = useI18n(); @@ -452,6 +473,7 @@ export { PathLabel, ExitedSessionIndicator, RunningSessionIndicator, + RecentlyCompletedIndicator, SIDEBAR_BUTTON_TRANSITION, SidebarIconButton, SidebarPortalMenu, diff --git a/components/SessionSidebar-rows.tsx b/components/SessionSidebar-rows.tsx index 50ace82d0..326c5d991 100644 --- a/components/SessionSidebar-rows.tsx +++ b/components/SessionSidebar-rows.tsx @@ -17,6 +17,7 @@ import { } from "./SessionSidebar-helpers"; import { ExitedSessionIndicator, + RecentlyCompletedIndicator, RunningSessionIndicator, SIDEBAR_BUTTON_TRANSITION, SidebarPortalMenu, @@ -43,6 +44,7 @@ interface ProjectRowProps { selectedSessionId: string | null; runningSessionIds: Set; unreadSessionIds: Set; + recentlyCompletedIds?: Set; exitedSessions: Map; relativeTimeNow: number; onActivate: (path: string) => void; @@ -76,6 +78,7 @@ function ProjectRow({ selectedSessionId, runningSessionIds, unreadSessionIds, + recentlyCompletedIds, exitedSessions, relativeTimeNow, onActivate, @@ -398,6 +401,7 @@ function ProjectRow({ runningSessionIds={runningSessionIds} unreadSessionIds={unreadSessionIds} exitedSessions={exitedSessions} + recentlyCompletedIds={recentlyCompletedIds} relativeTimeNow={relativeTimeNow} onSelectSession={onSelectSession} onRenamed={onRenamed} @@ -448,6 +452,7 @@ const SessionTreeItem = memo(function SessionTreeItem({ runningSessionIds, unreadSessionIds, exitedSessions, + recentlyCompletedIds, relativeTimeNow, onSelectSession, onRenamed, @@ -459,6 +464,7 @@ const SessionTreeItem = memo(function SessionTreeItem({ runningSessionIds: Set; unreadSessionIds: Set; exitedSessions: Map; + recentlyCompletedIds?: Set; relativeTimeNow: number; onSelectSession: (s: SessionInfo) => void; onRenamed?: () => void; @@ -474,6 +480,7 @@ const SessionTreeItem = memo(function SessionTreeItem({ const isSelected = sessionId === selectedSessionId; const isRunning = runningSessionIds.has(sessionId); const isUnread = unreadSessionIds.has(sessionId); + const isRecentlyCompleted = !isRunning && (recentlyCompletedIds?.has(sessionId) ?? false); const exited = exitedSessions.get(sessionId); // Stable callbacks: depend only on primitives / stable parent callbacks so @@ -508,6 +515,7 @@ const SessionTreeItem = memo(function SessionTreeItem({ isRunning={isRunning} isUnread={isUnread} exited={exited} + isRecentlyCompleted={isRecentlyCompleted} relativeTimeNow={relativeTimeNow} onClick={handleClick} onRenamed={onRenamed} @@ -528,6 +536,7 @@ const SessionTreeItem = memo(function SessionTreeItem({ runningSessionIds={runningSessionIds} unreadSessionIds={unreadSessionIds} exitedSessions={exitedSessions} + recentlyCompletedIds={recentlyCompletedIds} relativeTimeNow={relativeTimeNow} onSelectSession={onSelectSession} onRenamed={onRenamed} @@ -551,6 +560,10 @@ const SessionTreeItem = memo(function SessionTreeItem({ const id = prev.node.session.id; if (prev.runningSessionIds.has(id) !== next.runningSessionIds.has(id)) return false; } + if (prev.recentlyCompletedIds !== next.recentlyCompletedIds) { + const id = prev.node.session.id; + if ((prev.recentlyCompletedIds?.has(id) ?? false) !== (next.recentlyCompletedIds?.has(id) ?? false)) return false; + } if (prev.unreadSessionIds !== next.unreadSessionIds) { const id = prev.node.session.id; if (prev.unreadSessionIds.has(id) !== next.unreadSessionIds.has(id)) return false; @@ -568,6 +581,7 @@ const SessionItem = memo(function SessionItem({ isRunning, isUnread, exited, + isRecentlyCompleted, onClick, onRenamed, onDeleted, @@ -582,6 +596,7 @@ const SessionItem = memo(function SessionItem({ isRunning?: boolean; isUnread?: boolean; exited?: ExitedRpcSession; + isRecentlyCompleted?: boolean; onClick: () => void; onRenamed?: () => void; onDeleted?: (id: string) => void; @@ -743,13 +758,15 @@ const SessionItem = memo(function SessionItem({ {session.worktreeBranch && } {hasChildren && }
- {(isRunning || exited || isUnread) && ( + {(isRunning || exited || isRecentlyCompleted || isUnread) && ( {isRunning ? : exited ? - : } + : isRecentlyCompleted + ? + : } )}
diff --git a/components/SessionSidebar.tsx b/components/SessionSidebar.tsx index 07a10653c..5d37da060 100644 --- a/components/SessionSidebar.tsx +++ b/components/SessionSidebar.tsx @@ -16,6 +16,15 @@ import { compileSearchQuery, FIRST_MESSAGE_WEIGHT, scoreSearchFields, searchFiel import { Archive, ArrowDownUp, ArrowLeft, ArrowRight, Check, ChevronRight, FileUp, Loader2, Plus, RefreshCw, Search, Settings2, SlidersHorizontal, X } from "lucide-react"; import { publishSessionsChanged } from "@/lib/session-change-bus"; import { openEventStream } from "@/lib/event-stream"; +import { + loadRecentRuns, + recordCompletedRun, + removeActiveFromCompleted, + saveRecentRuns, + seedRecentRuns, + type RecentRunEntry, +} from "@/lib/recent-runs"; +import { useRecentRunsLimit } from "@/hooks/useRecentRunsLimit"; import { EMPTY_PROJECT_SET, INITIAL_RESTORE_MAX_ATTEMPTS, @@ -130,7 +139,38 @@ export const SessionSidebar = memo(function SessionSidebar({ selectedSessionId, const [runningSessionCwds, setRunningSessionCwds] = useState>({}); const [exitedSessions, setExitedSessions] = useState>(() => new Map()); const knownRunningCwdsRef = useRef>(new Map()); + const { limit: recentRunsLimit } = useRecentRunsLimit(); const [unreadSessionIds, setUnreadSessionIds] = useState>(() => loadUnreadSessionIds()); + const [recentCompletedRuns, setRecentCompletedRuns] = useState(() => loadRecentRuns()); + const effectiveRecentCompletedSet = useMemo(() => { + const timestampMap = new Map(); + + // 1. Live and persisted recent completed runs + for (const r of recentCompletedRuns) { + if (!runningSessionIds.has(r.sessionId)) { + timestampMap.set(r.sessionId, r.completedAt); + } + } + + // 2. On-disk active sessions (fallback & recency backfill) + for (const s of allSessions) { + if (runningSessionIds.has(s.id)) continue; + const isValid = (s.firstMessage && s.firstMessage !== "(no messages)") || s.messageCount > 0 || Boolean(s.name); + if (!isValid) continue; + const ts = new Date(s.modified).getTime(); + const existing = timestampMap.get(s.id); + if (existing === undefined || ts > existing) { + timestampMap.set(s.id, ts); + } + } + + // Sort by latest timestamp descending, pick top dynamic limit + const sorted = [...timestampMap.entries()] + .sort((a, b) => b[1] - a[1]) + .slice(0, recentRunsLimit); + + return new Set(sorted.map(([id]) => id)); + }, [recentCompletedRuns, allSessions, runningSessionIds, recentRunsLimit]); const previousRunningSessionIdsRef = useRef>(new Set()); // Relative session times must age while the sidebar stays open; one shared // minute clock avoids a timer per session row. @@ -265,6 +305,24 @@ export const SessionSidebar = memo(function SessionSidebar({ selectedSessionId, useEffect(() => { saveUnreadSessionIds(unreadSessionIds); }, [unreadSessionIds]); + useEffect(() => { + saveRecentRuns(recentCompletedRuns, undefined, recentRunsLimit); + }, [recentCompletedRuns, recentRunsLimit]); + + useEffect(() => { + if (allSessions.length === 0) return; + setRecentCompletedRuns((prev) => { + const seeded = seedRecentRuns(allSessions, recentRunsLimit); + if (prev.length === 0) return seeded; + const newestPrev = Math.max(...prev.map((p) => p.completedAt), 0); + const newestSeeded = Math.max(...seeded.map((s) => s.completedAt), 0); + if (newestSeeded > newestPrev) { + return seeded; + } + return prev; + }); + }, [allSessions, recentRunsLimit]); + // Debounce refresh bursts (agent_start + session_info_update + file-appear signal can fire within 250ms) const pendingRefreshRef = useRef | null>(null); @@ -350,9 +408,23 @@ export const SessionSidebar = memo(function SessionSidebar({ selectedSessionId, useEffect(() => { const previous = previousRunningSessionIdsRef.current; - const completedInBackground = [...previous].filter((id) => !runningSessionIds.has(id) && id !== selectedSessionId); + const allCompleted = [...previous].filter((id) => !runningSessionIds.has(id)); + const completedInBackground = allCompleted.filter((id) => id !== selectedSessionId); const newlyRunning = [...runningSessionIds].filter((id) => !previous.has(id)); + if (allCompleted.length > 0 || newlyRunning.length > 0) { + setRecentCompletedRuns((prev) => { + let updated = prev; + if (newlyRunning.length > 0) { + updated = removeActiveFromCompleted(updated, runningSessionIds); + } + for (const id of allCompleted) { + updated = recordCompletedRun(updated, id, undefined, recentRunsLimit); + } + return updated; + }); + } + if (completedInBackground.length > 0 || newlyRunning.length > 0) { setUnreadSessionIds((prev) => { const next = new Set(prev); @@ -371,7 +443,7 @@ export const SessionSidebar = memo(function SessionSidebar({ selectedSessionId, } previousRunningSessionIdsRef.current = runningSessionIds; - }, [runningSessionIds, selectedSessionId, loadSessions]); + }, [runningSessionIds, selectedSessionId, loadSessions, recentRunsLimit]); useEffect(() => { if (!selectedSessionId) return; @@ -775,7 +847,7 @@ export const SessionSidebar = memo(function SessionSidebar({ selectedSessionId, const entries: { project: ManagedProject; sessions: SessionInfo[]; scores?: Map; rank: number }[] = []; for (const project of sortedProjects) { let list = sessionsByProject.get(project.path) ?? []; - if (runningOnly) list = list.filter((s) => runningSessionIds.has(s.id)); + if (runningOnly) list = list.filter((s) => runningSessionIds.has(s.id) || effectiveRecentCompletedSet.has(s.id)); if (!query) { if (list.length === 0 && runningOnly) continue; entries.push({ project, sessions: list, rank: 0 }); @@ -799,7 +871,7 @@ export const SessionSidebar = memo(function SessionSidebar({ selectedSessionId, // Best match first; ties keep the workspace order (stable sort). if (query) entries.sort((a, b) => b.rank - a.rank); return entries; - }, [sortedProjects, sessionsByProject, runningOnly, trimmedSearchQuery, currentTranscriptSearch, runningSessionIds]); + }, [sortedProjects, sessionsByProject, runningOnly, trimmedSearchQuery, currentTranscriptSearch, runningSessionIds, effectiveRecentCompletedSet]); const treesByProject = useMemo(() => { const m = new Map>(); @@ -1445,7 +1517,7 @@ export const SessionSidebar = memo(function SessionSidebar({ selectedSessionId, setRunningOnly((v) => !v)} > @@ -1575,6 +1647,7 @@ export const SessionSidebar = memo(function SessionSidebar({ selectedSessionId, runningSessionIds={runningSessionIds} unreadSessionIds={unreadSessionIds} exitedSessions={exitedSessions} + recentlyCompletedIds={effectiveRecentCompletedSet} relativeTimeNow={relativeTimeNow} onActivate={activateProject} onToggleExpand={toggleProjectExpanded} diff --git a/components/SettingsConfig.tsx b/components/SettingsConfig.tsx index 02688217b..dedc4b43f 100644 --- a/components/SettingsConfig.tsx +++ b/components/SettingsConfig.tsx @@ -17,6 +17,7 @@ import type { AppUpdateInfo } from "./AppUpdateDialog"; import { useFontSize, type FontSizePreference } from "@/hooks/useFontSize"; import { useUiScale, type UiScalePreference } from "@/hooks/useUiScale"; import { useTouchTargets, type TouchTargetsPreference } from "@/hooks/useTouchTargets"; +import { useRecentRunsLimit, type RecentRunsLimitPreset } from "@/hooks/useRecentRunsLimit"; import { useSpeechSynthesis } from "@/hooks/useSpeechSynthesis"; import { useNotificationPrefs } from "@/hooks/useNotifications"; import { NOTIFICATION_TYPES, renderNotification, type NotificationType } from "@/lib/notification-events"; @@ -843,6 +844,12 @@ export function SettingsConfig({ activeTab, toolCallsDefaultCollapsed, onToolCal const { fontSize, setFontSize } = useFontSize(); const { uiScale, setUiScale } = useUiScale(); const { touchTargets, setTouchTargets } = useTouchTargets(); + const { + preset: recentRunsPreset, + customValue: recentRunsCustomValue, + setPreset: setRecentRunsPreset, + setCustomValue: setRecentRunsCustomValue, + } = useRecentRunsLimit(); const { isSupported: ttsSupported, autoPlayEnabled: ttsAutoPlay, @@ -1363,6 +1370,40 @@ export function SettingsConfig({ activeTab, toolCallsDefaultCollapsed, onToolCal + +
+ + {recentRunsPreset === "custom" && ( + setRecentRunsCustomValue(Number(e.target.value))} + style={{ + width: 80, + height: "var(--control-height)", + padding: "0 10px", + border: "1px solid var(--border)", + borderRadius: "var(--radius-control)", + background: "var(--bg)", + color: "var(--text)", + fontSize: "var(--text-sm)", + }} + placeholder={t("settingsConfig.recentRunsCustomPlaceholder")} + /> + )} +
+