vacumify-mcp 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,98 +1,634 @@
1
1
  #!/usr/bin/env node
2
+ 'use strict';
2
3
 
3
- const { spawn, execSync } = require('child_process');
4
4
  const fs = require('fs');
5
5
  const path = require('path');
6
+ const readline = require('readline');
7
+ const scanner = require('../lib/scanner');
6
8
 
7
- function findVacumifyExecutable() {
8
- // 1. Explicit env variable
9
- if (process.env.VACUMIFY_PATH && fs.existsSync(process.env.VACUMIFY_PATH)) {
10
- return process.env.VACUMIFY_PATH;
11
- }
12
-
13
- // 2. Relative paths within the Vacumify repo
14
- const candidates = [
15
- path.resolve(__dirname, '../../StorageCleaner/StorageCleaner/bin/Release/net10.0-windows/win-x64/publish/Vacumify.exe'),
16
- path.resolve(__dirname, '../../StorageCleaner/StorageCleaner/bin/Release/net10.0-windows/win-x64/Vacumify.exe'),
17
- path.resolve(__dirname, '../../StorageCleaner/StorageCleaner/bin/Debug/net10.0-windows/Vacumify.exe'),
18
- path.resolve(process.cwd(), 'Vacumify.exe')
19
- ];
9
+ const SERVER_NAME = 'vacumify';
10
+ const SERVER_VERSION = '1.2.0';
11
+ const PROTOCOL_VERSION = '2024-11-05';
12
+ const MS_PER_DAY = 24 * 60 * 60 * 1000;
20
13
 
21
- for (const cand of candidates) {
22
- if (fs.existsSync(cand)) return cand;
14
+ const TOOLS = [
15
+ {
16
+ name: 'vacumify_scan',
17
+ description:
18
+ 'Scan a local folder to identify large files, duplicate file groups, forgotten files, and developer caches with Active/Dormant/Abandoned project context. Read-only operation.',
19
+ inputSchema: {
20
+ type: 'object',
21
+ properties: {
22
+ path: {
23
+ type: 'string',
24
+ description: 'Directory path to scan (e.g. C:\\Users\\Name\\Downloads or /home/user/Projects).'
25
+ },
26
+ includeHidden: {
27
+ type: 'boolean',
28
+ description: 'Include hidden files and folders (default: false).'
29
+ },
30
+ minDuplicateBytes: {
31
+ type: 'integer',
32
+ description: 'Minimum file size in bytes for duplicate detection (default: 102400 = 100 KB).'
33
+ },
34
+ minLargeFileBytes: {
35
+ type: 'integer',
36
+ description: 'Minimum file size in bytes to flag as a large file (default: 104857600 = 100 MB).'
37
+ },
38
+ forgottenDays: {
39
+ type: 'integer',
40
+ description: 'Days since last access/modification to flag a file as forgotten (default: 90).'
41
+ }
42
+ },
43
+ required: ['path']
44
+ }
45
+ },
46
+ {
47
+ name: 'vacumify_get_dev_caches',
48
+ description:
49
+ 'Scan a workspace or Projects directory specifically for reclaimable developer caches (node_modules, .NET bin/obj, .venv, Rust/Maven target, __pycache__, Gradle, .next, dist, build) with Active/Dormant/Abandoned git activity status.',
50
+ inputSchema: {
51
+ type: 'object',
52
+ properties: {
53
+ path: {
54
+ type: 'string',
55
+ description: 'Root workspace or Projects directory path to scan.'
56
+ },
57
+ olderThanDays: {
58
+ type: 'integer',
59
+ description: 'Optional filter: only return caches in projects untouched for at least N days.'
60
+ }
61
+ },
62
+ required: ['path']
63
+ }
64
+ },
65
+ {
66
+ name: 'vacumify_get_safe_junk',
67
+ description:
68
+ 'Identify safe-to-delete junk candidates in a folder: redundant duplicate copies (preserving original) and obsolete installers (.msi/.exe/.dmp/old .log untouched >30 days).',
69
+ inputSchema: {
70
+ type: 'object',
71
+ properties: {
72
+ path: {
73
+ type: 'string',
74
+ description: 'Directory path to analyze.'
75
+ }
76
+ },
77
+ required: ['path']
78
+ }
79
+ },
80
+ {
81
+ name: 'vacumify_recycle_items',
82
+ description:
83
+ 'Safely move specified files or folders into the OS Recycle Bin / System Trash. NEVER permanently deletes files, and blocks critical OS/system paths.',
84
+ inputSchema: {
85
+ type: 'object',
86
+ properties: {
87
+ paths: {
88
+ type: 'array',
89
+ items: { type: 'string' },
90
+ description: 'List of absolute file or directory paths to move to Recycle Bin / Trash.'
91
+ },
92
+ dryRun: {
93
+ type: 'boolean',
94
+ description: 'If true, preview what would be recycled without moving any files (default: false).'
95
+ }
96
+ },
97
+ required: ['paths']
98
+ }
23
99
  }
100
+ ];
24
101
 
25
- // 3. Check ~/.vacumify auto-install directory
26
- const userHome = process.env.USERPROFILE || process.env.HOME || '';
27
- const autoInstallDir = path.join(userHome, '.vacumify');
28
- const autoInstallExe = path.join(autoInstallDir, 'Vacumify.exe');
29
- if (fs.existsSync(autoInstallExe)) return autoInstallExe;
30
-
31
- // 4. Search PATH on Windows
32
- if (process.platform === 'win32') {
33
- try {
34
- const stdout = execSync('where.exe Vacumify.exe', { stdio: ['pipe', 'pipe', 'ignore'], encoding: 'utf8' });
35
- const firstLine = stdout.trim().split(/\r?\n/)[0];
36
- if (firstLine && fs.existsSync(firstLine)) return firstLine;
37
- } catch (_) {}
102
+ const PROMPTS = [
103
+ {
104
+ name: 'audit-storage',
105
+ description: 'Comprehensive storage audit covering dev caches, duplicates, forgotten files, and large files.',
106
+ arguments: [
107
+ {
108
+ name: 'path',
109
+ description: 'Directory path to audit (optional; defaults to asking or current workspace).',
110
+ required: false
111
+ }
112
+ ]
113
+ },
114
+ {
115
+ name: 'duplicates',
116
+ description: 'Find duplicate file groups and safely recycle redundant copies.',
117
+ arguments: [
118
+ {
119
+ name: 'path',
120
+ description: 'Directory path to scan for duplicates (optional).',
121
+ required: false
122
+ }
123
+ ]
124
+ },
125
+ {
126
+ name: 'forgotten-files',
127
+ description: 'Find untouched/forgotten files older than a configurable day threshold (default 90 days).',
128
+ arguments: [
129
+ {
130
+ name: 'path',
131
+ description: 'Directory path to inspect (optional).',
132
+ required: false
133
+ },
134
+ {
135
+ name: 'days',
136
+ description: 'Inactivity threshold in days (default: 90).',
137
+ required: false
138
+ }
139
+ ]
140
+ },
141
+ {
142
+ name: 'large-files',
143
+ description: 'Find oversized files exceeding a size threshold (default 100 MB).',
144
+ arguments: [
145
+ {
146
+ name: 'path',
147
+ description: 'Directory path to inspect (optional).',
148
+ required: false
149
+ },
150
+ {
151
+ name: 'minSizeMb',
152
+ description: 'Minimum file size in MB (default: 100).',
153
+ required: false
154
+ }
155
+ ]
156
+ },
157
+ {
158
+ name: 'dev-caches',
159
+ description: 'Scan workspace for bloated developer caches scored by Active/Dormant/Abandoned project activity.',
160
+ arguments: [
161
+ {
162
+ name: 'path',
163
+ description: 'Workspace or Projects directory path (optional).',
164
+ required: false
165
+ },
166
+ {
167
+ name: 'olderThanDays',
168
+ description: 'Optional minimum days untouched filter.',
169
+ required: false
170
+ }
171
+ ]
38
172
  }
173
+ ];
39
174
 
40
- return null;
175
+ function sendMessage(msg) {
176
+ process.stdout.write(JSON.stringify(msg) + '\n');
41
177
  }
42
178
 
43
- function downloadAndExtractRelease() {
44
- if (process.platform !== 'win32') {
45
- console.error('[vacumify-mcp] Vacumify currently supports Windows (x64).');
46
- process.exit(1);
179
+ function sendResult(id, result) {
180
+ sendMessage({ jsonrpc: '2.0', id, result });
181
+ }
182
+
183
+ function sendError(id, code, message, data) {
184
+ const err = { code, message };
185
+ if (data !== undefined) err.data = data;
186
+ sendMessage({ jsonrpc: '2.0', id, error: err });
187
+ }
188
+
189
+ function toolTextResult(payload, isError = false) {
190
+ return {
191
+ content: [
192
+ {
193
+ type: 'text',
194
+ text: typeof payload === 'string' ? payload : JSON.stringify(payload, null, 2)
195
+ }
196
+ ],
197
+ ...(isError ? { isError: true } : {})
198
+ };
199
+ }
200
+
201
+ function resolveValidDir(inputPath) {
202
+ if (!inputPath || typeof inputPath !== 'string' || !inputPath.trim()) {
203
+ throw new Error('Missing required "path" argument.');
204
+ }
205
+ const resolved = path.resolve(inputPath.trim());
206
+ if (!fs.existsSync(resolved)) {
207
+ throw new Error(`Directory not found: ${resolved}`);
47
208
  }
209
+ const stat = fs.statSync(resolved);
210
+ if (!stat.isDirectory()) {
211
+ throw new Error(`Path is not a directory: ${resolved}`);
212
+ }
213
+ return resolved;
214
+ }
48
215
 
49
- const userHome = process.env.USERPROFILE || process.env.HOME || '';
50
- const autoInstallDir = path.join(userHome, '.vacumify');
51
- const autoInstallExe = path.join(autoInstallDir, 'Vacumify.exe');
52
- const url = 'https://github.com/kuroi17/Vacumify/releases/latest/download/Vacumify-win-x64.zip';
216
+ function enrichActivity(targetPath, fallbackMs) {
217
+ const act = scanner.getProjectActivity(targetPath, fallbackMs);
218
+ return {
219
+ activityStatus: act.status,
220
+ daysUntouched: act.daysUntouched
221
+ };
222
+ }
53
223
 
54
- console.error('[vacumify-mcp] Vacumify.exe not found locally. Downloading latest release from GitHub...');
224
+ async function handleVacumifyScan(args) {
225
+ const targetPath = resolveValidDir(args.path);
226
+ const includeHidden = Boolean(args.includeHidden);
227
+ const minDuplicateBytes = Number.isFinite(args.minDuplicateBytes)
228
+ ? Math.max(1, Number(args.minDuplicateBytes))
229
+ : 100 * 1024;
230
+ const minLargeFileBytes = Number.isFinite(args.minLargeFileBytes)
231
+ ? Math.max(1, Number(args.minLargeFileBytes))
232
+ : 100 * 1024 * 1024;
233
+ const forgottenDays = Number.isFinite(args.forgottenDays)
234
+ ? Math.max(1, Number(args.forgottenDays))
235
+ : 90;
55
236
 
56
- try {
57
- if (!fs.existsSync(autoInstallDir)) fs.mkdirSync(autoInstallDir, { recursive: true });
58
- const zipPath = path.join(autoInstallDir, 'Vacumify-win-x64.zip');
237
+ const result = await scanner.scanDirectory(targetPath, {
238
+ includeHidden,
239
+ minDuplicateBytes,
240
+ fastLargeSampling: true
241
+ });
59
242
 
60
- execSync(`powershell -Command "Invoke-WebRequest -Uri '${url}' -OutFile '${zipPath}'; Expand-Archive -Path '${zipPath}' -DestinationPath '${autoInstallDir}' -Force; Remove-Item '${zipPath}'"`, {
61
- stdio: ['ignore', 'inherit', 'inherit']
243
+ const nowMs = Date.now();
244
+ const forgottenCutoffMs = nowMs - forgottenDays * MS_PER_DAY;
245
+
246
+ const topLargeFiles = result.files
247
+ .filter((f) => f.size >= minLargeFileBytes)
248
+ .sort((a, b) => b.size - a.size)
249
+ .slice(0, 25)
250
+ .map((f) => ({
251
+ path: f.path,
252
+ name: f.name,
253
+ size: f.size,
254
+ sizeFormatted: scanner.formatBytes(f.size),
255
+ lastWrite: scanner.formatDate(f.lastWriteMs),
256
+ lastAccess: scanner.formatDate(f.lastAccessMs),
257
+ ...enrichActivity(f.path, f.lastWriteMs)
258
+ }));
259
+
260
+ const forgottenAll = result.files.filter(
261
+ (f) => Math.max(f.lastAccessMs || 0, f.lastWriteMs || 0) < forgottenCutoffMs
262
+ );
263
+ const topForgottenFiles = forgottenAll
264
+ .sort((a, b) => b.size - a.size)
265
+ .slice(0, 25)
266
+ .map((f) => {
267
+ const lastTouchMs = Math.max(f.lastAccessMs || 0, f.lastWriteMs || 0);
268
+ const daysIdle = Math.max(0, Math.floor((nowMs - lastTouchMs) / MS_PER_DAY));
269
+ return {
270
+ path: f.path,
271
+ name: f.name,
272
+ size: f.size,
273
+ sizeFormatted: scanner.formatBytes(f.size),
274
+ daysIdle,
275
+ lastAccess: scanner.formatDate(f.lastAccessMs),
276
+ lastWrite: scanner.formatDate(f.lastWriteMs),
277
+ ...enrichActivity(f.path, f.lastWriteMs)
278
+ };
62
279
  });
63
280
 
64
- if (fs.existsSync(autoInstallExe)) {
65
- console.error('[vacumify-mcp] Successfully installed Vacumify to ' + autoInstallDir);
66
- return autoInstallExe;
281
+ const groupsMap = new Map();
282
+ for (const f of result.files) {
283
+ if (!f.duplicateGroupId) continue;
284
+ let list = groupsMap.get(f.duplicateGroupId);
285
+ if (!list) {
286
+ list = [];
287
+ groupsMap.set(f.duplicateGroupId, list);
67
288
  }
68
- } catch (err) {
69
- console.error('[vacumify-mcp] Auto-download failed: ' + err.message);
289
+ list.push(f);
290
+ }
291
+
292
+ const topDuplicateGroups = Array.from(groupsMap.entries())
293
+ .map(([groupId, items]) => {
294
+ const sorted = items.slice().sort((a, b) => (a.lastWriteMs || 0) - (b.lastWriteMs || 0));
295
+ const unitSize = sorted[0]?.size || 0;
296
+ const reclaimableBytes = unitSize * Math.max(0, sorted.length - 1);
297
+ const anchor = sorted[0];
298
+ return {
299
+ groupId,
300
+ fileCount: sorted.length,
301
+ unitSize,
302
+ reclaimableBytes,
303
+ reclaimableFormatted: scanner.formatBytes(reclaimableBytes),
304
+ ...enrichActivity(anchor.path, anchor.lastWriteMs),
305
+ paths: sorted.map((x) => x.path)
306
+ };
307
+ })
308
+ .sort((a, b) => b.reclaimableBytes - a.reclaimableBytes)
309
+ .slice(0, 20);
310
+
311
+ const devCaches = result.devCaches
312
+ .slice()
313
+ .sort((a, b) => b.size - a.size)
314
+ .slice(0, 30)
315
+ .map((c) => ({
316
+ path: c.path,
317
+ projectName: c.projectName,
318
+ cacheType: c.cacheType,
319
+ size: c.size,
320
+ sizeFormatted: scanner.formatBytes(c.size),
321
+ lastModified: scanner.formatDate(c.lastModifiedMs),
322
+ ...enrichActivity(c.path, c.lastModifiedMs)
323
+ }));
324
+
325
+ return {
326
+ scannedPath: targetPath,
327
+ totalFiles: result.files.length,
328
+ totalBytes: result.bytesScanned,
329
+ totalFormatted: scanner.formatBytes(result.bytesScanned),
330
+ conditions: {
331
+ forgottenDays,
332
+ minLargeFileBytes,
333
+ minDuplicateBytes,
334
+ includeHidden
335
+ },
336
+ reclaimableDuplicateBytes: result.reclaimableDuplicateBytes,
337
+ reclaimableDuplicateFormatted: scanner.formatBytes(result.reclaimableDuplicateBytes),
338
+ duplicateGroupCount: groupsMap.size,
339
+ forgottenFilesCount: forgottenAll.length,
340
+ devCacheCount: result.devCaches.length,
341
+ devCacheTotalBytes: result.devCaches.reduce((acc, c) => acc + c.size, 0),
342
+ devCacheTotalFormatted: scanner.formatBytes(result.devCaches.reduce((acc, c) => acc + c.size, 0)),
343
+ topLargeFiles,
344
+ topForgottenFiles,
345
+ topDuplicateGroups,
346
+ devCaches,
347
+ errorsCount: result.errors.length
348
+ };
349
+ }
350
+
351
+ async function handleGetDevCaches(args) {
352
+ const targetPath = resolveValidDir(args.path);
353
+ const olderThanDays =
354
+ args.olderThanDays !== undefined && args.olderThanDays !== null
355
+ ? Math.max(0, Number(args.olderThanDays))
356
+ : null;
357
+
358
+ const result = await scanner.scanDirectory(targetPath, {
359
+ includeHidden: false,
360
+ minDuplicateBytes: 100 * 1024,
361
+ fastLargeSampling: true
362
+ });
363
+
364
+ let caches = result.devCaches.map((c) => {
365
+ const activity = scanner.getProjectActivity(c.path, c.lastModifiedMs);
366
+ return {
367
+ path: c.path,
368
+ projectName: c.projectName,
369
+ cacheType: c.cacheType,
370
+ size: c.size,
371
+ sizeFormatted: scanner.formatBytes(c.size),
372
+ lastModified: scanner.formatDate(c.lastModifiedMs),
373
+ activityStatus: activity.status,
374
+ daysUntouched: activity.daysUntouched,
375
+ projectRoot: activity.projectRoot
376
+ };
377
+ });
378
+
379
+ if (olderThanDays !== null && Number.isFinite(olderThanDays)) {
380
+ caches = caches.filter((c) => c.daysUntouched >= olderThanDays);
70
381
  }
71
- return null;
382
+
383
+ caches.sort((a, b) => b.size - a.size);
384
+ const totalBytes = caches.reduce((acc, c) => acc + c.size, 0);
385
+
386
+ return {
387
+ scannedPath: targetPath,
388
+ olderThanDays,
389
+ cacheCount: caches.length,
390
+ totalBytes,
391
+ totalFormatted: scanner.formatBytes(totalBytes),
392
+ caches
393
+ };
72
394
  }
73
395
 
74
- let exePath = findVacumifyExecutable() || downloadAndExtractRelease();
396
+ async function handleGetSafeJunk(args) {
397
+ const targetPath = resolveValidDir(args.path);
398
+ const result = await scanner.scanDirectory(targetPath, {
399
+ includeHidden: false,
400
+ minDuplicateBytes: 100 * 1024,
401
+ fastLargeSampling: true
402
+ });
403
+
404
+ const junk = scanner.identifySafeJunk(result.files);
405
+ const totalBytes = junk.reduce((acc, f) => acc + f.size, 0);
75
406
 
76
- if (!exePath) {
77
- console.error('[vacumify-mcp] Error: Vacumify.exe not found.');
78
- console.error('[vacumify-mcp] Please either:');
79
- console.error(' 1. Set VACUMIFY_PATH environment variable to the path of Vacumify.exe');
80
- console.error(' 2. Place Vacumify.exe in your PATH');
81
- console.error(' 3. Or build the project: dotnet publish StorageCleaner/StorageCleaner/StorageCleaner.csproj -c Release -r win-x64 --self-contained true');
82
- process.exit(1);
407
+ return {
408
+ scannedPath: targetPath,
409
+ candidateCount: junk.length,
410
+ totalBytes,
411
+ totalFormatted: scanner.formatBytes(totalBytes),
412
+ candidates: junk
413
+ .slice()
414
+ .sort((a, b) => b.size - a.size)
415
+ .slice(0, 100)
416
+ .map((f) => ({
417
+ path: f.path,
418
+ name: f.name,
419
+ size: f.size,
420
+ sizeFormatted: scanner.formatBytes(f.size),
421
+ reason: f.duplicateGroupId ? 'redundant_duplicate' : 'obsolete_installer_or_dump',
422
+ lastWrite: scanner.formatDate(f.lastWriteMs)
423
+ }))
424
+ };
83
425
  }
84
426
 
85
- const child = spawn(exePath, ['--mcp'], {
86
- stdio: 'inherit',
87
- windowsHide: true
88
- });
427
+ async function handleRecycleItems(args) {
428
+ if (!Array.isArray(args.paths) || args.paths.length === 0) {
429
+ throw new Error('Argument "paths" must be a non-empty array of absolute file/folder paths.');
430
+ }
431
+ const dryRun = Boolean(args.dryRun);
432
+ return await scanner.recycleItems(args.paths, dryRun);
433
+ }
89
434
 
90
- child.on('error', (err) => {
91
- console.error(`[vacumify-mcp] Failed to spawn Vacumify: ${err.message}`);
92
- process.exit(1);
93
- });
435
+ function getPromptResponse(name, args = {}) {
436
+ const target = args.path ? `"${args.path}"` : 'the target folder (ask the user if not specified)';
437
+ switch (name) {
438
+ case 'audit-storage':
439
+ return {
440
+ description: 'Comprehensive storage audit using Vacumify MCP tools.',
441
+ messages: [
442
+ {
443
+ role: 'user',
444
+ content: {
445
+ type: 'text',
446
+ text:
447
+ `Run a full storage audit on ${target} using \`vacumify_scan\` and \`vacumify_get_dev_caches\`.\n` +
448
+ 'Summarize reclaimed-space opportunities across four buckets:\n' +
449
+ '1. Developer caches (node_modules, .NET bin/obj, .venv, target, etc.) grouped by project activity (ACTIVE / DORMANT / ABANDONED).\n' +
450
+ '2. Redundant duplicate file groups (keep oldest original, list redundant copies).\n' +
451
+ '3. Forgotten files untouched for 90+ days (`forgottenDays`).\n' +
452
+ '4. Large files exceeding 100 MB (`minLargeFileBytes`).\n' +
453
+ 'Do NOT recycle anything without explicit user confirmation. When approved, always move items via `vacumify_recycle_items` (Recycle Bin / System Trash, never permanent delete).'
454
+ }
455
+ }
456
+ ]
457
+ };
458
+ case 'duplicates':
459
+ return {
460
+ description: 'Find duplicate file groups and safely recycle redundant copies.',
461
+ messages: [
462
+ {
463
+ role: 'user',
464
+ content: {
465
+ type: 'text',
466
+ text:
467
+ `Scan ${target} for duplicate files using \`vacumify_scan\` (respecting \`minDuplicateBytes\`, default 100 KB) and \`vacumify_get_safe_junk\`.\n` +
468
+ 'Present each duplicate group clearly with the preserved original copy and redundant copies, sorted by reclaimable size.\n' +
469
+ 'Ask the user before calling `vacumify_recycle_items` so redundant copies go safely to Recycle Bin / System Trash.'
470
+ }
471
+ }
472
+ ]
473
+ };
474
+ case 'forgotten-files': {
475
+ const days = args.days || '90';
476
+ return {
477
+ description: 'Find untouched files exceeding a day threshold.',
478
+ messages: [
479
+ {
480
+ role: 'user',
481
+ content: {
482
+ type: 'text',
483
+ text:
484
+ `Scan ${target} using \`vacumify_scan\` with \`forgottenDays: ${days}\`.\n` +
485
+ `List the top forgotten files untouched for at least ${days} days, including their size, last-accessed date, and project activity status.\n` +
486
+ 'Confirm with the user before recycling any files via `vacumify_recycle_items`.'
487
+ }
488
+ }
489
+ ]
490
+ };
491
+ }
492
+ case 'large-files': {
493
+ const minMb = args.minSizeMb || '100';
494
+ const minBytes = Math.max(1, Number(minMb) || 100) * 1024 * 1024;
495
+ return {
496
+ description: 'Find oversized files above a configurable MB threshold.',
497
+ messages: [
498
+ {
499
+ role: 'user',
500
+ content: {
501
+ type: 'text',
502
+ text:
503
+ `Scan ${target} using \`vacumify_scan\` with \`minLargeFileBytes: ${minBytes}\` (${minMb} MB).\n` +
504
+ 'Rank the largest files with sizes, last modified dates, and activity context.\n' +
505
+ 'Confirm with the user before recycling any files via `vacumify_recycle_items`.'
506
+ }
507
+ }
508
+ ]
509
+ };
510
+ }
511
+ case 'dev-caches': {
512
+ const olderClause = args.olderThanDays
513
+ ? ` with \`olderThanDays: ${args.olderThanDays}\``
514
+ : '';
515
+ return {
516
+ description: 'Find bloated developer caches with Active/Dormant/Abandoned context.',
517
+ messages: [
518
+ {
519
+ role: 'user',
520
+ content: {
521
+ type: 'text',
522
+ text:
523
+ `Scan ${target} using \`vacumify_get_dev_caches\`${olderClause}.\n` +
524
+ 'Highlight ABANDONED and DORMANT project caches first while warning against deleting ACTIVE workspace dependencies unless the user confirms.\n' +
525
+ 'Always use `vacumify_recycle_items` (Recycle Bin / System Trash) when cleaning approved caches.'
526
+ }
527
+ }
528
+ ]
529
+ };
530
+ }
531
+ default:
532
+ return null;
533
+ }
534
+ }
94
535
 
95
- child.on('exit', (code, signal) => {
96
- process.exit(code ?? (signal ? 1 : 0));
536
+ async function handleRequest(msg) {
537
+ const { id, method, params } = msg;
538
+ const isNotification = id === undefined || id === null;
539
+
540
+ try {
541
+ switch (method) {
542
+ case 'initialize': {
543
+ sendResult(id, {
544
+ protocolVersion: PROTOCOL_VERSION,
545
+ capabilities: {
546
+ tools: {},
547
+ prompts: {}
548
+ },
549
+ serverInfo: {
550
+ name: SERVER_NAME,
551
+ version: SERVER_VERSION
552
+ }
553
+ });
554
+ return;
555
+ }
556
+ case 'notifications/initialized':
557
+ case 'initialized':
558
+ return;
559
+ case 'ping': {
560
+ if (!isNotification) sendResult(id, {});
561
+ return;
562
+ }
563
+ case 'tools/list': {
564
+ sendResult(id, { tools: TOOLS });
565
+ return;
566
+ }
567
+ case 'tools/call': {
568
+ const toolName = params?.name;
569
+ const args = params?.arguments || {};
570
+ try {
571
+ let data;
572
+ if (toolName === 'vacumify_scan') {
573
+ data = await handleVacumifyScan(args);
574
+ } else if (toolName === 'vacumify_get_dev_caches') {
575
+ data = await handleGetDevCaches(args);
576
+ } else if (toolName === 'vacumify_get_safe_junk') {
577
+ data = await handleGetSafeJunk(args);
578
+ } else if (toolName === 'vacumify_recycle_items') {
579
+ data = await handleRecycleItems(args);
580
+ } else {
581
+ sendError(id, -32601, `Unknown tool: ${toolName}`);
582
+ return;
583
+ }
584
+ sendResult(id, toolTextResult(data));
585
+ } catch (toolErr) {
586
+ sendResult(id, toolTextResult({ error: toolErr.message || String(toolErr) }, true));
587
+ }
588
+ return;
589
+ }
590
+ case 'prompts/list': {
591
+ sendResult(id, { prompts: PROMPTS });
592
+ return;
593
+ }
594
+ case 'prompts/get': {
595
+ const promptName = params?.name;
596
+ const promptRes = getPromptResponse(promptName, params?.arguments || {});
597
+ if (!promptRes) {
598
+ sendError(id, -32602, `Unknown prompt: ${promptName}`);
599
+ return;
600
+ }
601
+ sendResult(id, promptRes);
602
+ return;
603
+ }
604
+ default: {
605
+ if (!isNotification) {
606
+ sendError(id, -32601, `Method not found: ${method}`);
607
+ }
608
+ }
609
+ }
610
+ } catch (err) {
611
+ if (!isNotification) {
612
+ sendError(id, -32603, err?.message || 'Internal error');
613
+ }
614
+ }
615
+ }
616
+
617
+ const rl = readline.createInterface({
618
+ input: process.stdin,
619
+ crlfDelay: Infinity
97
620
  });
98
621
 
622
+ let pending = Promise.resolve();
623
+ rl.on('line', (line) => {
624
+ const trimmed = line.trim();
625
+ if (!trimmed) return;
626
+ let parsed;
627
+ try {
628
+ parsed = JSON.parse(trimmed);
629
+ } catch (e) {
630
+ sendError(null, -32700, 'Parse error');
631
+ return;
632
+ }
633
+ pending = pending.then(() => handleRequest(parsed));
634
+ });