getAllSessionFiles method
Get all session files from all project directories. Includes both main session files and subagent transcript files.
Implementation
Future<List<String>> getAllSessionFiles() async {
final projectsDir = _getProjectsDir();
final dir = Directory(projectsDir);
if (!await dir.exists()) return [];
final allEntries = await dir.list().toList();
final projectDirs = allEntries
.whereType<Directory>()
.map((d) => d.path)
.toList();
final allFiles = <String>[];
for (final projectDir in projectDirs) {
try {
final entries = await Directory(projectDir).list().toList();
// Main session files (*.jsonl directly in project dir).
final mainFiles = entries
.whereType<File>()
.where((f) => f.path.endsWith('.jsonl'))
.map((f) => f.path)
.toList();
allFiles.addAll(mainFiles);
// Subagent files from session subdirectories.
final sessionDirs = entries.whereType<Directory>();
for (final sessionDir in sessionDirs) {
final subagentsDir = Directory('${sessionDir.path}/subagents');
if (await subagentsDir.exists()) {
final subagentEntries = await subagentsDir.list().toList();
final subagentFiles = subagentEntries
.whereType<File>()
.where(
(f) =>
f.path.endsWith('.jsonl') &&
f.uri.pathSegments.last.startsWith('agent-'),
)
.map((f) => f.path)
.toList();
allFiles.addAll(subagentFiles);
}
}
} catch (_) {
// Failed to read project directory — skip.
}
}
return allFiles;
}