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

Function cleanupSingleDirectory

src/utils/cleanup.ts:267–299  ·  view source on GitHub ↗

* Generic helper for cleaning up old files in a single directory * @param dirPath Path to the directory to clean * @param extension File extension to filter (e.g., '.md', '.jsonl') * @param removeEmptyDir Whether to remove the directory if empty after cleanup

(
  dirPath: string,
  extension: string,
  removeEmptyDir: boolean = true,
)

Source from the content-addressed store, hash-verified

265 * @param removeEmptyDir Whether to remove the directory if empty after cleanup
266 */
267async function cleanupSingleDirectory(
268 dirPath: string,
269 extension: string,
270 removeEmptyDir: boolean = true,
271): Promise<CleanupResult> {
272 const cutoffDate = getCutoffDate()
273 const result: CleanupResult = { messages: 0, errors: 0 }
274 const fsImpl = getFsImplementation()
275
276 let dirents
277 try {
278 dirents = await fsImpl.readdir(dirPath)
279 } catch {
280 return result
281 }
282
283 for (const dirent of dirents) {
284 if (!dirent.isFile() || !dirent.name.endsWith(extension)) continue
285 try {
286 if (await unlinkIfOld(join(dirPath, dirent.name), cutoffDate, fsImpl)) {
287 result.messages++
288 }
289 } catch {
290 result.errors++
291 }
292 }
293
294 if (removeEmptyDir) {
295 await tryRmdir(dirPath, fsImpl)
296 }
297
298 return result
299}
300
301export function cleanupOldPlanFiles(): Promise<CleanupResult> {
302 const plansDir = join(getClaudeConfigHomeDir(), 'plans')

Callers 1

cleanupOldPlanFilesFunction · 0.85

Calls 4

getCutoffDateFunction · 0.85
getFsImplementationFunction · 0.85
unlinkIfOldFunction · 0.85
tryRmdirFunction · 0.85

Tested by

no test coverage detected