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