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

Function cleanupOldDebugLogs

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

Source from the content-addressed store, hash-verified

395 * and accumulate indefinitely without this cleanup.
396 */
397export async function cleanupOldDebugLogs(): Promise<CleanupResult> {
398 const cutoffDate = getCutoffDate()
399 const result: CleanupResult = { messages: 0, errors: 0 }
400 const fsImpl = getFsImplementation()
401 const debugDir = join(getClaudeConfigHomeDir(), 'debug')
402
403 let dirents
404 try {
405 dirents = await fsImpl.readdir(debugDir)
406 } catch {
407 return result
408 }
409
410 for (const dirent of dirents) {
411 // Preserve the 'latest' symlink
412 if (
413 !dirent.isFile() ||
414 !dirent.name.endsWith('.txt') ||
415 dirent.name === 'latest'
416 ) {
417 continue
418 }
419 try {
420 if (await unlinkIfOld(join(debugDir, dirent.name), cutoffDate, fsImpl)) {
421 result.messages++
422 }
423 } catch {
424 result.errors++
425 }
426 }
427
428 // Intentionally do NOT remove debugDir even if empty — needed for future logs
429 return result
430}
431
432const ONE_DAY_MS = 24 * 60 * 60 * 1000
433

Callers 1

Calls 3

getCutoffDateFunction · 0.85
getFsImplementationFunction · 0.85
unlinkIfOldFunction · 0.85

Tested by

no test coverage detected