MCPcopy Create free account
hub / github.com/EvoMap/evolver / run

Function run

src/ops/cleanup.js:20–72  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18}
19
20function run() {
21 var evoDir = getEvolutionDir();
22 if (!fs.existsSync(evoDir)) return;
23
24 var files = fs.readdirSync(evoDir)
25 .filter(function(f) { return /^gep_prompt_.*\.(json|txt)$/.test(f); })
26 .map(function(f) {
27 var full = path.join(evoDir, f);
28 var stat = fs.statSync(full);
29 return { name: f, path: full, mtime: stat.mtimeMs };
30 })
31 .sort(function(a, b) { return b.mtime - a.mtime; }); // newest first
32
33 var now = Date.now();
34 var deleted = 0;
35
36 // Phase 1: Age-based cleanup (keep at least MIN_KEEP)
37 var filesToDelete = [];
38 for (var i = MIN_KEEP; i < files.length; i++) {
39 if (now - files[i].mtime > MAX_AGE_MS) {
40 filesToDelete.push(files[i].path);
41 }
42 }
43
44 if (filesToDelete.length > 0) {
45 deleted += safeBatchDelete(filesToDelete);
46 }
47
48 // Phase 2: Size-based safety cap (keep max 10 files total)
49 try {
50 var remainingFiles = fs.readdirSync(evoDir)
51 .filter(function(f) { return /^gep_prompt_.*\.(json|txt)$/.test(f); })
52 .map(function(f) {
53 var full = path.join(evoDir, f);
54 var stat = fs.statSync(full);
55 return { name: f, path: full, mtime: stat.mtimeMs };
56 })
57 .sort(function(a, b) { return b.mtime - a.mtime; }); // newest first
58
59 var MAX_FILES = require('../config').CLEANUP_MAX_FILES;
60 if (remainingFiles.length > MAX_FILES) {
61 var toDelete = remainingFiles.slice(MAX_FILES).map(function(f) { return f.path; });
62 deleted += safeBatchDelete(toDelete);
63 }
64 } catch (e) {
65 console.warn('[Cleanup] Phase 2 failed:', e.message);
66 }
67
68 if (deleted > 0) {
69 console.log('[Cleanup] Deleted ' + deleted + ' old GEP artifacts.');
70 }
71 return deleted;
72}
73
74if (require.main === module) {
75 console.log('[Cleanup] Scanning for old artifacts...');

Callers 9

cleanup.jsFile · 0.70
withServerFunction · 0.50
withServerFunction · 0.50
withServerFunction · 0.50
withServerFunction · 0.50
withServerFunction · 0.50
withServerFunction · 0.50
ops.test.jsFile · 0.50
withTempHomeFunction · 0.50

Calls 2

getEvolutionDirFunction · 0.85
safeBatchDeleteFunction · 0.85

Tested by 7

withServerFunction · 0.40
withServerFunction · 0.40
withServerFunction · 0.40
withServerFunction · 0.40
withServerFunction · 0.40
withServerFunction · 0.40
withTempHomeFunction · 0.40