feat(sidebar): add repo-grouped session navigation with live status (#361)

* feat(sidebar): add repo-grouped session navigation with live status

- Add a searchable, collapsible session tree to the desktop sidebar, grouped by repository with pinned and time-bucketed ordering.
- Track per-session busy, retry, and compact status in a shared store fed by the SSE event stream and scoped by directory.
- Extract shared navigation components reused by the desktop tree and the mobile repo quick-switch sheet.
- Show a Git tab and hide Schedules inside a repo on the mobile tab bar; add Repos and Assistant entries to the session More drawer.
- Replace the CommitsTab local relative-time formatter with a shared formatShortRelativeTime util.

* refactor(sidebar): unify session status tracking and navigation helpers

* feat(sidebar): add collapsible sessions and menu sections

* fix(sessions): keep specific live status over snapshot busy
This commit is contained in:
Chris Scott authored and GitHub committed 2026-09-26 21:50:23 -04:00
1 parent 1389e8e59c
commit 015a44a5f3
45 files changed
+3347 -763

No files matched your search

@@ -3,8 +3,8 @@ import { useSessionsAcrossDirectories, useDeleteSession, useCreateSession } from
import type { DeleteSessionTarget } from "@/hooks/useOpenCode";
import type { Session } from "@/api/types";
import { useSessionPins, useToggleSessionPin } from '@/hooks/useSessionPins';
import { buildSessionKey } from '@/lib/sessionKey';
import { partitionSessions } from './session-partition';
import { buildSessionKey, buildPinnedSessionKeys } from '@/lib/sessionKey';
import { partitionSessions, selectRootSessions } from './session-partition';
import { DeleteSessionDialog } from "./DeleteSessionDialog";
import { SessionCard } from "./SessionCard";
import { Card } from "@/components/ui/card";
@@ -48,7 +48,7 @@ export const SessionList = ({
const { data: sessionPins } = useSessionPins();
const togglePin = useToggleSessionPin();
const pinnedKeys = useMemo(
() => new Set((sessionPins ?? []).map((p) => buildSessionKey(p.directory, p.sessionId))),
() => buildPinnedSessionKeys(sessionPins ?? []),
[sessionPins],
);
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
@@ -57,25 +57,10 @@ export const SessionList = ({
const [manageMode, setManageMode] = useState(false);
const sessionListRef = useRef<HTMLDivElement>(null);
const filteredSessions = useMemo(() => {
if (!sessions) return [];
const filtered = sessions.filter((session) => {
if (session.parentID) return false;
if (directorySet.size > 0 && !directorySet.has(session.location.directory)) return false;
return true;
});
const uniqueSessions = new Map<string, (typeof filtered)[number]>();
filtered.forEach((session) => {
const key = getSessionSelectionKey(session);
if (!uniqueSessions.has(key)) {
uniqueSessions.set(key, session);
}
});
return Array.from(uniqueSessions.values()).sort((a, b) => b.time.updated - a.time.updated);
}, [sessions, directorySet, getSessionSelectionKey]);
const filteredSessions = useMemo(
() => selectRootSessions(sessions ?? [], { directories: directorySet, keyFn: getSessionSelectionKey }),
[sessions, directorySet, getSessionSelectionKey],
);
const { pinned: pinnedSessions, today: todaySessions, older: olderSessions } = useMemo(
() => partitionSessions(filteredSessions, pinnedKeys, getSessionSelectionKey),
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest'
import { partitionSessions } from './session-partition'
import { partitionSessions, selectRootSessions } from './session-partition'
import type { Session } from '@/api/types'
function createSession(id: string, updated: number, directory = '/test'): Session {
@@ -17,6 +17,53 @@ function createSession(id: string, updated: number, directory = '/test'): Sessio
const keyFn = (s: Session) =>
`${s.location.directory}:${s.id}`
describe('selectRootSessions', () => {
it('drops sessions that have a parentID', () => {
const sessions = [
createSession('root', 2000),
{ ...createSession('child', 1000), parentID: 'root' },
]
const result = selectRootSessions(sessions, { keyFn })
expect(result.map((s) => s.id)).toEqual(['root'])
})
it('drops sessions outside the directory set but keeps sessions with no directory', () => {
const sessions = [
createSession('inside', 3000, '/a'),
createSession('outside', 2000, '/b'),
{ ...createSession('no-directory', 1000), location: {} as Session['location'] },
]
const result = selectRootSessions(sessions, { directories: new Set(['/a']), keyFn })
expect(result.map((s) => s.id)).toEqual(['inside', 'no-directory'])
})
it('keeps the first occurrence when deduping by key', () => {
const first = createSession('dup', 2000, '/a')
const second = createSession('dup', 5000, '/a')
const result = selectRootSessions([first, second], { keyFn })
expect(result).toHaveLength(1)
expect(result[0].time.updated).toBe(2000)
})
it('returns the result sorted by updated descending', () => {
const sessions = [
createSession('old', 1000),
createSession('new', 3000),
createSession('mid', 2000),
]
const result = selectRootSessions(sessions, { keyFn })
expect(result.map((s) => s.id)).toEqual(['new', 'mid', 'old'])
})
})
describe('partitionSessions', () => {
it('places pinned sessions in pinned array sorted by updated desc', () => {
const now = 1_000_000_000_000
@@ -6,9 +6,37 @@ export interface PartitionedSessions {
older: Session[]
}
export interface SelectRootSessionsOptions {
directories?: ReadonlySet<string>
keyFn: (session: Session) => string
}
export function selectRootSessions(
sessions: Session[],
options: SelectRootSessionsOptions,
): Session[] {
const { directories, keyFn } = options
const roots = sessions.filter((session) => {
if (session.parentID) return false
const directory = session.location.directory
if (directories && directories.size > 0 && directory && !directories.has(directory)) return false
return true
})
const uniqueSessions = new Map<string, Session>()
for (const session of roots) {
const key = keyFn(session)
if (!uniqueSessions.has(key)) {
uniqueSessions.set(key, session)
}
}
return Array.from(uniqueSessions.values()).sort((a, b) => b.time.updated - a.time.updated)
}
export function partitionSessions(
sessions: Session[],
pinnedKeys: Set<string>,
pinnedKeys: ReadonlySet<string>,
keyFn: (session: Session) => string,
now: number = Date.now(),
): PartitionedSessions {