sortSessionsCurrentFolderFirst function

List<SessionMetadata> sortSessionsCurrentFolderFirst(
  1. List<SessionMetadata> sessions,
  2. String? currentCwd
)

Orders sessions for display (issue #83): sessions from the currentCwd folder first, then sessions from every other folder; each group newest-activity first. JsonlSessionRepo.list stays plain activity order so /resume keeps its most-recent-anywhere semantics.

Implementation

List<SessionMetadata> sortSessionsCurrentFolderFirst(
  List<SessionMetadata> sessions,
  String? currentCwd,
) {
  final sorted = [...sessions]..sort(compareSessionActivity);
  if (currentCwd == null || currentCwd.isEmpty) return sorted;
  return [
    ...sorted.where((m) => m.cwd == currentCwd),
    ...sorted.where((m) => m.cwd != currentCwd),
  ];
}