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

Function cleanupOldFileHistoryBackups

src/utils/cleanup.ts:306–349  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

304}
305
306export async function cleanupOldFileHistoryBackups(): Promise<CleanupResult> {
307 const cutoffDate = getCutoffDate()
308 const result: CleanupResult = { messages: 0, errors: 0 }
309 const fsImpl = getFsImplementation()
310
311 try {
312 const configDir = getClaudeConfigHomeDir()
313 const fileHistoryStorageDir = join(configDir, 'file-history')
314
315 let dirents
316 try {
317 dirents = await fsImpl.readdir(fileHistoryStorageDir)
318 } catch {
319 return result
320 }
321
322 const fileHistorySessionsDirs = dirents
323 .filter(dirent => dirent.isDirectory())
324 .map(dirent => join(fileHistoryStorageDir, dirent.name))
325
326 await Promise.all(
327 fileHistorySessionsDirs.map(async fileHistorySessionDir => {
328 try {
329 const stats = await fsImpl.stat(fileHistorySessionDir)
330 if (stats.mtime < cutoffDate) {
331 await fsImpl.rm(fileHistorySessionDir, {
332 recursive: true,
333 force: true,
334 })
335 result.messages++
336 }
337 } catch {
338 result.errors++
339 }
340 }),
341 )
342
343 await tryRmdir(fileHistoryStorageDir, fsImpl)
344 } catch (error) {
345 logError(error as Error)
346 }
347
348 return result
349}
350
351export async function cleanupOldSessionEnvDirs(): Promise<CleanupResult> {
352 const cutoffDate = getCutoffDate()

Callers 1

Calls 4

getCutoffDateFunction · 0.85
getFsImplementationFunction · 0.85
tryRmdirFunction · 0.85
logErrorFunction · 0.70

Tested by

no test coverage detected