()
| 574 | } |
| 575 | |
| 576 | export async function cleanupOldMessageFilesInBackground(): Promise<void> { |
| 577 | // If settings have validation errors but the user explicitly set cleanupPeriodDays, |
| 578 | // skip cleanup entirely rather than falling back to the default (30 days). |
| 579 | // This prevents accidentally deleting files when the user intended a different retention period. |
| 580 | const { errors } = getSettingsWithAllErrors() |
| 581 | if (errors.length > 0 && rawSettingsContainsKey('cleanupPeriodDays')) { |
| 582 | logForDebugging( |
| 583 | 'Skipping cleanup: settings have validation errors but cleanupPeriodDays was explicitly set. Fix settings errors to enable cleanup.', |
| 584 | ) |
| 585 | return |
| 586 | } |
| 587 | |
| 588 | await cleanupOldMessageFiles() |
| 589 | await cleanupOldSessionFiles() |
| 590 | await cleanupOldPlanFiles() |
| 591 | await cleanupOldFileHistoryBackups() |
| 592 | await cleanupOldSessionEnvDirs() |
| 593 | await cleanupOldDebugLogs() |
| 594 | await cleanupOldImageCaches() |
| 595 | await cleanupOldPastes(getCutoffDate()) |
| 596 | const removedWorktrees = await cleanupStaleAgentWorktrees(getCutoffDate()) |
| 597 | if (removedWorktrees > 0) { |
| 598 | logEvent('ncode_worktree_cleanup', { removed: removedWorktrees }) |
| 599 | } |
| 600 | if (isInternalBuild()) { |
| 601 | await cleanupNpmCacheForAnthropicPackages() |
| 602 | } |
| 603 | } |
no test coverage detected