( projectDir: string, )
| 4639 | * Stats are batched via Promise.all to avoid serial syscalls in the hot loop. |
| 4640 | */ |
| 4641 | export async function getSessionFilesWithMtime( |
| 4642 | projectDir: string, |
| 4643 | ): Promise< |
| 4644 | Map<string, { path: string; mtime: number; ctime: number; size: number }> |
| 4645 | > { |
| 4646 | const sessionFilesMap = new Map< |
| 4647 | string, |
| 4648 | { path: string; mtime: number; ctime: number; size: number } |
| 4649 | >() |
| 4650 | |
| 4651 | let dirents: Dirent[] |
| 4652 | try { |
| 4653 | dirents = await readdir(projectDir, { withFileTypes: true }) |
| 4654 | } catch { |
| 4655 | // Directory doesn't exist - return empty map |
| 4656 | return sessionFilesMap |
| 4657 | } |
| 4658 | |
| 4659 | const candidates: Array<{ sessionId: string; filePath: string }> = [] |
| 4660 | for (const dirent of dirents) { |
| 4661 | if (!dirent.isFile() || !dirent.name.endsWith('.jsonl')) continue |
| 4662 | const sessionId = validateUuid(basename(dirent.name, '.jsonl')) |
| 4663 | if (!sessionId) continue |
| 4664 | candidates.push({ sessionId, filePath: join(projectDir, dirent.name) }) |
| 4665 | } |
| 4666 | |
| 4667 | await Promise.all( |
| 4668 | candidates.map(async ({ sessionId, filePath }) => { |
| 4669 | try { |
| 4670 | const st = await stat(filePath) |
| 4671 | sessionFilesMap.set(sessionId, { |
| 4672 | path: filePath, |
| 4673 | mtime: st.mtime.getTime(), |
| 4674 | ctime: st.birthtime.getTime(), |
| 4675 | size: st.size, |
| 4676 | }) |
| 4677 | } catch { |
| 4678 | logForDebugging(`Failed to stat session file: ${filePath}`) |
| 4679 | } |
| 4680 | }), |
| 4681 | ) |
| 4682 | |
| 4683 | return sessionFilesMap |
| 4684 | } |
| 4685 | |
| 4686 | /** |
| 4687 | * Number of sessions to enrich on the initial load of the resume picker. |
no test coverage detected