( projectDir: string, )
| 4524 | * Stats are batched via Promise.all to avoid serial syscalls in the hot loop. |
| 4525 | */ |
| 4526 | export async function getSessionFilesWithMtime( |
| 4527 | projectDir: string, |
| 4528 | ): Promise< |
| 4529 | Map<string, { path: string; mtime: number; ctime: number; size: number }> |
| 4530 | > { |
| 4531 | const sessionFilesMap = new Map< |
| 4532 | string, |
| 4533 | { path: string; mtime: number; ctime: number; size: number } |
| 4534 | >() |
| 4535 | |
| 4536 | let dirents: Dirent[] |
| 4537 | try { |
| 4538 | dirents = await readdir(projectDir, { withFileTypes: true }) |
| 4539 | } catch { |
| 4540 | // Directory doesn't exist - return empty map |
| 4541 | return sessionFilesMap |
| 4542 | } |
| 4543 | |
| 4544 | const candidates: Array<{ sessionId: string; filePath: string }> = [] |
| 4545 | for (const dirent of dirents) { |
| 4546 | if (!dirent.isFile() || !dirent.name.endsWith('.jsonl')) continue |
| 4547 | const sessionId = validateUuid(basename(dirent.name, '.jsonl')) |
| 4548 | if (!sessionId) continue |
| 4549 | candidates.push({ sessionId, filePath: join(projectDir, dirent.name) }) |
| 4550 | } |
| 4551 | |
| 4552 | await Promise.all( |
| 4553 | candidates.map(async ({ sessionId, filePath }) => { |
| 4554 | try { |
| 4555 | const st = await stat(filePath) |
| 4556 | sessionFilesMap.set(sessionId, { |
| 4557 | path: filePath, |
| 4558 | mtime: st.mtime.getTime(), |
| 4559 | ctime: st.birthtime.getTime(), |
| 4560 | size: st.size, |
| 4561 | }) |
| 4562 | } catch { |
| 4563 | logForDebugging(`Failed to stat session file: ${filePath}`) |
| 4564 | } |
| 4565 | }), |
| 4566 | ) |
| 4567 | |
| 4568 | return sessionFilesMap |
| 4569 | } |
| 4570 | |
| 4571 | /** |
| 4572 | * Number of sessions to enrich on the initial load of the resume picker. |
no test coverage detected