MCPcopy Create free account
hub / github.com/Noumena-Network/code / getSessionFilesWithMtime

Function getSessionFilesWithMtime

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

Source from the content-addressed store, hash-verified

4792 * Stats are batched via Promise.all to avoid serial syscalls in the hot loop.
4793 */
4794export async function getSessionFilesWithMtime(
4795 projectDir: string,
4796): Promise<
4797 Map<string, { path: string; mtime: number; ctime: number; size: number }>
4798> {
4799 const sessionFilesMap = new Map<
4800 string,
4801 { path: string; mtime: number; ctime: number; size: number }
4802 >()
4803
4804 let dirents: Dirent[]
4805 try {
4806 dirents = await readdir(projectDir, { withFileTypes: true })
4807 } catch {
4808 // Directory doesn't exist - return empty map
4809 return sessionFilesMap
4810 }
4811
4812 const candidates: Array<{ sessionId: string; filePath: string }> = []
4813 for (const dirent of dirents) {
4814 if (!dirent.isFile() || !dirent.name.endsWith('.jsonl')) continue
4815 const sessionId = validateUuid(basename(dirent.name, '.jsonl'))
4816 if (!sessionId) continue
4817 candidates.push({ sessionId, filePath: join(projectDir, dirent.name) })
4818 }
4819
4820 await Promise.all(
4821 candidates.map(async ({ sessionId, filePath }) => {
4822 try {
4823 const st = await stat(filePath)
4824 sessionFilesMap.set(sessionId, {
4825 path: filePath,
4826 mtime: st.mtime.getTime(),
4827 ctime: st.birthtime.getTime(),
4828 size: st.size,
4829 })
4830 } catch {
4831 logForDebugging(`Failed to stat session file: ${filePath}`)
4832 }
4833 }),
4834 )
4835
4836 return sessionFilesMap
4837}
4838
4839/**
4840 * 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
setMethod · 0.80
validateUuidFunction · 0.70
logForDebuggingFunction · 0.70

Tested by

no test coverage detected