()
| 91 | } |
| 92 | |
| 93 | export async function cleanupOldMessageFiles(): Promise<CleanupResult> { |
| 94 | const fsImpl = getFsImplementation() |
| 95 | const cutoffDate = getCutoffDate() |
| 96 | const errorPath = CACHE_PATHS.errors() |
| 97 | const baseCachePath = CACHE_PATHS.baseLogs() |
| 98 | |
| 99 | // Clean up message and error logs |
| 100 | let result = await cleanupOldFilesInDirectory(errorPath, cutoffDate, false) |
| 101 | |
| 102 | // Clean up MCP logs |
| 103 | try { |
| 104 | let dirents |
| 105 | try { |
| 106 | dirents = await fsImpl.readdir(baseCachePath) |
| 107 | } catch { |
| 108 | return result |
| 109 | } |
| 110 | |
| 111 | const mcpLogDirs = dirents |
| 112 | .filter( |
| 113 | dirent => dirent.isDirectory() && dirent.name.startsWith('mcp-logs-'), |
| 114 | ) |
| 115 | .map(dirent => join(baseCachePath, dirent.name)) |
| 116 | |
| 117 | for (const mcpLogDir of mcpLogDirs) { |
| 118 | // Clean up files in MCP log directory |
| 119 | result = addCleanupResults( |
| 120 | result, |
| 121 | await cleanupOldFilesInDirectory(mcpLogDir, cutoffDate, true), |
| 122 | ) |
| 123 | await tryRmdir(mcpLogDir, fsImpl) |
| 124 | } |
| 125 | } catch (error: unknown) { |
| 126 | if (error instanceof Error && 'code' in error && error.code !== 'ENOENT') { |
| 127 | logError(error) |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | return result |
| 132 | } |
| 133 | |
| 134 | async function unlinkIfOld( |
| 135 | filePath: string, |
no test coverage detected