diff --git a/ui/desktop/src/components/SessionPills.tsx b/ui/desktop/src/components/SessionPills.tsx index c95eb01f9..085583f3e 100644 --- a/ui/desktop/src/components/SessionPills.tsx +++ b/ui/desktop/src/components/SessionPills.tsx @@ -16,38 +16,45 @@ const useCombinedSessions = (workingDir: string) => { const getCombinedSessions = () => { if (sessions.length === 0 && latestSessions.length === 0) { - return []; + return { currentDirSessions: [], otherLocationSessions: [] }; } - const combinedSessions = []; + const currentDirSessions = []; + const otherLocationSessions = []; const seenNames = new Set(); - // Add at least one latest session if available - if (latestSessions.length > 0) { - const latest = latestSessions[0]; - combinedSessions.push({ ...latest, isLatest: true }); - seenNames.add(latest.name); - } - - // Add remaining latest sessions (up to 5 total) - for (let i = 1; i < latestSessions.length && combinedSessions.length < 5; i++) { - const session = latestSessions[i]; + // Process latest sessions first + for (const session of latestSessions) { if (!seenNames.has(session.name)) { - combinedSessions.push({ ...session, isLatest: true }); + if (session.directory === workingDir) { + currentDirSessions.push({ ...session, isLatest: true }); + } else { + otherLocationSessions.push({ ...session, isLatest: true }); + } seenNames.add(session.name); } } - // Fill remaining slots with regular sessions (up to 5 total) + // Process regular sessions for (const session of sessions) { - if (combinedSessions.length >= 5) break; if (!seenNames.has(session.name)) { - combinedSessions.push({ ...session, isLatest: false }); + if (session.directory === workingDir) { + currentDirSessions.push({ ...session, isLatest: false }); + } else { + otherLocationSessions.push({ ...session, isLatest: false }); + } seenNames.add(session.name); } } - return combinedSessions; + // Sort sessions by name + currentDirSessions.sort((a, b) => a.name.localeCompare(b.name)); + otherLocationSessions.sort((a, b) => a.name.localeCompare(b.name)); + + return { + currentDirSessions: currentDirSessions.slice(0, 5), + otherLocationSessions: otherLocationSessions.slice(0, 5) + }; }; return getCombinedSessions(); @@ -55,31 +62,52 @@ const useCombinedSessions = (workingDir: string) => { export default function SessionPills() { const workingDir = window.appConfig.get("GOOSE_WORKING_DIR"); - const combinedSessions = useCombinedSessions(workingDir); + const { currentDirSessions, otherLocationSessions } = useCombinedSessions(workingDir); - if (combinedSessions.length === 0) { + if (currentDirSessions.length === 0 && otherLocationSessions.length === 0) { return null; } + const SessionPill = ({ session }) => ( +