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