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