MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / getSessionFilesWithMtime

Function getSessionFilesWithMtime

source code/utils/sessionStorage.ts:4528–4571  ·  view source on GitHub ↗
(
  projectDir: string,
)

Source from the content-addressed store, hash-verified

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

Callers 3

getLogsWithoutIndexFunction · 0.85
getSessionFilesLiteFunction · 0.85
scanAllSessionsFunction · 0.85

Calls 5

readdirFunction · 0.85
statFunction · 0.85
logForDebuggingFunction · 0.85
setMethod · 0.80
validateUuidFunction · 0.70

Tested by

no test coverage detected