MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / getSessionFilesWithMtime

Function getSessionFilesWithMtime

src/utils/sessionStorage.ts:4641–4684  ·  view source on GitHub ↗
(
  projectDir: string,
)

Source from the content-addressed store, hash-verified

4639 * Stats are batched via Promise.all to avoid serial syscalls in the hot loop.
4640 */
4641export 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.

Callers 3

getLogsWithoutIndexFunction · 0.85
getSessionFilesLiteFunction · 0.85
scanAllSessionsFunction · 0.85

Calls 6

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

Tested by

no test coverage detected