vibecheck-mcp-server 2.0.1

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.
@@ -0,0 +1,428 @@
1
+ /**
2
+ * MCP Tool Interface for Repo Hygiene + Debt Radar
3
+ *
4
+ * Provides composable MCP methods for:
5
+ * - repo.hygiene.scan - Full hygiene scan
6
+ * - repo.hygiene.duplicates - Duplicate detection
7
+ * - repo.hygiene.unused - Unused file analysis
8
+ * - repo.hygiene.errors - Error collection
9
+ * - repo.hygiene.rootCleanup - Root directory cleanup
10
+ */
11
+
12
+ const fs = require("fs");
13
+ const path = require("path");
14
+ const {
15
+ findDuplicates,
16
+ findUnusedFiles,
17
+ collectAllErrors,
18
+ analyzeRootDirectory,
19
+ generateHygieneReport,
20
+ calculateHygieneScore,
21
+ generateRootCleanupPlan,
22
+ } = require("../scripts/hygiene");
23
+
24
+ /**
25
+ * Full hygiene scan
26
+ */
27
+ async function hygieneFullScan({
28
+ projectPath = ".",
29
+ mode = "report",
30
+ saveArtifacts = true,
31
+ }) {
32
+ const resolvedPath = path.resolve(projectPath);
33
+
34
+ const results = {
35
+ projectPath: resolvedPath,
36
+ mode,
37
+ timestamp: new Date().toISOString(),
38
+ duplicates: findDuplicates(resolvedPath),
39
+ unused: findUnusedFiles(resolvedPath),
40
+ errors: collectAllErrors(resolvedPath),
41
+ rootCleanup: analyzeRootDirectory(resolvedPath),
42
+ };
43
+
44
+ results.score = calculateHygieneScore(results);
45
+
46
+ if (saveArtifacts) {
47
+ const reportDir = path.join(resolvedPath, ".guardrail");
48
+ if (!fs.existsSync(reportDir)) fs.mkdirSync(reportDir, { recursive: true });
49
+
50
+ fs.writeFileSync(
51
+ path.join(reportDir, "hygiene-report.md"),
52
+ generateHygieneReport(results),
53
+ );
54
+ fs.writeFileSync(
55
+ path.join(reportDir, "duplicates.json"),
56
+ JSON.stringify(results.duplicates, null, 2),
57
+ );
58
+ fs.writeFileSync(
59
+ path.join(reportDir, "unused-files.json"),
60
+ JSON.stringify(results.unused, null, 2),
61
+ );
62
+ fs.writeFileSync(
63
+ path.join(reportDir, "errors.json"),
64
+ JSON.stringify(results.errors, null, 2),
65
+ );
66
+ fs.writeFileSync(
67
+ path.join(reportDir, "root-cleanup-plan.md"),
68
+ generateRootCleanupPlan(results.rootCleanup),
69
+ );
70
+ fs.writeFileSync(
71
+ path.join(reportDir, "hygiene-score.json"),
72
+ JSON.stringify(results.score, null, 2),
73
+ );
74
+ }
75
+
76
+ return {
77
+ success: true,
78
+ score: results.score,
79
+ summary: {
80
+ duplicates: {
81
+ exact: results.duplicates.exact.length,
82
+ near: results.duplicates.near.length,
83
+ copyPaste: results.duplicates.copyPaste.length,
84
+ },
85
+ unused: {
86
+ definitelyUnused: results.unused.unused.definitelyUnused.length,
87
+ probablyUnused: results.unused.unused.probablyUnused.length,
88
+ special: results.unused.unused.special.length,
89
+ },
90
+ errors: results.errors.summary,
91
+ rootCleanup: {
92
+ junkFiles: results.rootCleanup.junkFiles.length,
93
+ missingStandards: results.rootCleanup.missingStandards.length,
94
+ },
95
+ },
96
+ artifacts: saveArtifacts
97
+ ? [
98
+ ".guardrail/hygiene-report.md",
99
+ ".guardrail/duplicates.json",
100
+ ".guardrail/unused-files.json",
101
+ ".guardrail/errors.json",
102
+ ".guardrail/root-cleanup-plan.md",
103
+ ".guardrail/hygiene-score.json",
104
+ ]
105
+ : [],
106
+ };
107
+ }
108
+
109
+ /**
110
+ * Duplicate detection only
111
+ */
112
+ async function hygieneDuplicates({ projectPath = ".", threshold = 0.85 }) {
113
+ const resolvedPath = path.resolve(projectPath);
114
+ const duplicates = findDuplicates(resolvedPath);
115
+
116
+ return {
117
+ success: true,
118
+ exact: duplicates.exact,
119
+ near: duplicates.near,
120
+ copyPaste: duplicates.copyPaste,
121
+ summary: {
122
+ exactCount: duplicates.exact.length,
123
+ nearCount: duplicates.near.length,
124
+ copyPasteCount: duplicates.copyPaste.length,
125
+ totalWastedBytes: duplicates.exact.reduce(
126
+ (sum, g) => sum + g.totalWastedBytes,
127
+ 0,
128
+ ),
129
+ },
130
+ };
131
+ }
132
+
133
+ /**
134
+ * Unused file analysis only
135
+ */
136
+ async function hygieneUnused({ projectPath = ".", scope = "all" }) {
137
+ const resolvedPath = path.resolve(projectPath);
138
+ const result = findUnusedFiles(resolvedPath);
139
+
140
+ let filtered = result.unused;
141
+ if (scope === "prod") {
142
+ filtered = {
143
+ definitelyUnused: result.unused.definitelyUnused,
144
+ probablyUnused: result.unused.probablyUnused,
145
+ special: [],
146
+ testOnly: [],
147
+ };
148
+ } else if (scope === "test") {
149
+ filtered = {
150
+ definitelyUnused: [],
151
+ probablyUnused: [],
152
+ special: [],
153
+ testOnly: result.unused.testOnly,
154
+ };
155
+ }
156
+
157
+ return {
158
+ success: true,
159
+ unused: filtered,
160
+ stats: result.stats,
161
+ safeToDelete: filtered.definitelyUnused.map((f) => f.file),
162
+ reviewFirst: filtered.probablyUnused.map((f) => f.file),
163
+ };
164
+ }
165
+
166
+ /**
167
+ * Error collection only
168
+ */
169
+ async function hygieneErrors({
170
+ projectPath = ".",
171
+ eslint = true,
172
+ tsc = true,
173
+ imports = true,
174
+ syntax = true,
175
+ }) {
176
+ const resolvedPath = path.resolve(projectPath);
177
+ const result = collectAllErrors(resolvedPath);
178
+
179
+ // Filter based on options
180
+ const filtered = {
181
+ typescript: tsc ? result.typescript : [],
182
+ eslint: eslint ? result.eslint : [],
183
+ syntax: syntax ? result.syntax : [],
184
+ imports: imports ? result.imports : [],
185
+ };
186
+
187
+ const allFiltered = [
188
+ ...filtered.typescript,
189
+ ...filtered.eslint,
190
+ ...filtered.syntax,
191
+ ...filtered.imports,
192
+ ];
193
+
194
+ return {
195
+ success: true,
196
+ errors: filtered,
197
+ summary: {
198
+ total: allFiltered.length,
199
+ byCategory: {
200
+ typescript: filtered.typescript.length,
201
+ eslint: filtered.eslint.length,
202
+ syntax: filtered.syntax.length,
203
+ imports: filtered.imports.length,
204
+ },
205
+ bySeverity: {
206
+ error: allFiltered.filter((e) => e.severity === "error").length,
207
+ warning: allFiltered.filter((e) => e.severity === "warning").length,
208
+ },
209
+ autoFixable: allFiltered.filter((e) => e.fixable).length,
210
+ },
211
+ topOffenders: result.topOffenders,
212
+ };
213
+ }
214
+
215
+ /**
216
+ * Root cleanup analysis only
217
+ */
218
+ async function hygieneRootCleanup({ projectPath = ".", ruleset = "default" }) {
219
+ const resolvedPath = path.resolve(projectPath);
220
+ const result = analyzeRootDirectory(resolvedPath);
221
+
222
+ return {
223
+ success: true,
224
+ junkFiles: result.junkFiles,
225
+ missingStandards: result.missingStandards,
226
+ duplicateConfigs: result.duplicateConfigs,
227
+ misplacedFiles: result.misplacedFiles,
228
+ suggestions: result.suggestions,
229
+ cleanupPlan: generateRootCleanupPlan(result),
230
+ };
231
+ }
232
+
233
+ /**
234
+ * Get deletion plan (safe files to delete)
235
+ */
236
+ async function hygieneDeletionPlan({
237
+ projectPath = ".",
238
+ includeReview = false,
239
+ }) {
240
+ const resolvedPath = path.resolve(projectPath);
241
+
242
+ const duplicates = findDuplicates(resolvedPath);
243
+ const unused = findUnusedFiles(resolvedPath);
244
+
245
+ const safeToDelete = [];
246
+ const reviewFirst = [];
247
+
248
+ // Add duplicate files (keep first, delete rest)
249
+ for (const group of duplicates.exact) {
250
+ const [keep, ...remove] = group.files;
251
+ safeToDelete.push(
252
+ ...remove.map((f) => ({
253
+ file: f.path,
254
+ reason: `Exact duplicate of ${keep.path}`,
255
+ category: "duplicate",
256
+ })),
257
+ );
258
+ }
259
+
260
+ // Add definitely unused
261
+ safeToDelete.push(
262
+ ...unused.unused.definitelyUnused.map((f) => ({
263
+ file: f.file,
264
+ reason: f.reason,
265
+ category: "unused",
266
+ })),
267
+ );
268
+
269
+ // Add probably unused to review
270
+ reviewFirst.push(
271
+ ...unused.unused.probablyUnused.map((f) => ({
272
+ file: f.file,
273
+ reason: f.reason,
274
+ category: "unused",
275
+ })),
276
+ );
277
+
278
+ return {
279
+ success: true,
280
+ safeToDelete,
281
+ reviewFirst: includeReview ? reviewFirst : [],
282
+ summary: {
283
+ safeCount: safeToDelete.length,
284
+ reviewCount: reviewFirst.length,
285
+ },
286
+ };
287
+ }
288
+
289
+ // MCP Tool Definitions
290
+ const hygieneTools = [
291
+ {
292
+ name: "repo_hygiene_scan",
293
+ description:
294
+ "Run a full repository hygiene scan including duplicates, unused files, errors, and root cleanup. Generates comprehensive reports.",
295
+ inputSchema: {
296
+ type: "object",
297
+ properties: {
298
+ projectPath: {
299
+ type: "string",
300
+ description: "Path to project root",
301
+ default: ".",
302
+ },
303
+ mode: {
304
+ type: "string",
305
+ enum: ["report", "safe-fix", "hard-fix"],
306
+ default: "report",
307
+ },
308
+ saveArtifacts: {
309
+ type: "boolean",
310
+ description: "Save reports to .guardrail/",
311
+ default: true,
312
+ },
313
+ },
314
+ },
315
+ handler: hygieneFullScan,
316
+ },
317
+ {
318
+ name: "repo_hygiene_duplicates",
319
+ description:
320
+ "Find duplicate files: exact duplicates (same hash), near-duplicates (85%+ similar), and copy-pasted code blocks.",
321
+ inputSchema: {
322
+ type: "object",
323
+ properties: {
324
+ projectPath: { type: "string", default: "." },
325
+ threshold: {
326
+ type: "number",
327
+ description: "Similarity threshold for near-duplicates",
328
+ default: 0.85,
329
+ },
330
+ },
331
+ },
332
+ handler: hygieneDuplicates,
333
+ },
334
+ {
335
+ name: "repo_hygiene_unused",
336
+ description:
337
+ "Find unused files by building an import graph from entrypoints. Classifies files by deletion safety.",
338
+ inputSchema: {
339
+ type: "object",
340
+ properties: {
341
+ projectPath: { type: "string", default: "." },
342
+ scope: {
343
+ type: "string",
344
+ enum: ["all", "prod", "test"],
345
+ description: "Filter scope",
346
+ default: "all",
347
+ },
348
+ },
349
+ },
350
+ handler: hygieneUnused,
351
+ },
352
+ {
353
+ name: "repo_hygiene_errors",
354
+ description:
355
+ "Collect all lint, type, import, and syntax errors in a unified format. CI-friendly with counts and top offenders.",
356
+ inputSchema: {
357
+ type: "object",
358
+ properties: {
359
+ projectPath: { type: "string", default: "." },
360
+ eslint: {
361
+ type: "boolean",
362
+ description: "Include ESLint errors",
363
+ default: true,
364
+ },
365
+ tsc: {
366
+ type: "boolean",
367
+ description: "Include TypeScript errors",
368
+ default: true,
369
+ },
370
+ imports: {
371
+ type: "boolean",
372
+ description: "Include import resolution errors",
373
+ default: true,
374
+ },
375
+ syntax: {
376
+ type: "boolean",
377
+ description: "Include syntax errors",
378
+ default: true,
379
+ },
380
+ },
381
+ },
382
+ handler: hygieneErrors,
383
+ },
384
+ {
385
+ name: "repo_hygiene_root_cleanup",
386
+ description:
387
+ "Analyze root directory for junk files, missing standards, duplicate configs, and misplaced files.",
388
+ inputSchema: {
389
+ type: "object",
390
+ properties: {
391
+ projectPath: { type: "string", default: "." },
392
+ ruleset: {
393
+ type: "string",
394
+ description: "Cleanup ruleset to use",
395
+ default: "default",
396
+ },
397
+ },
398
+ },
399
+ handler: hygieneRootCleanup,
400
+ },
401
+ {
402
+ name: "repo_hygiene_deletion_plan",
403
+ description:
404
+ "Generate a safe deletion plan for duplicate and unused files. Never deletes automatically.",
405
+ inputSchema: {
406
+ type: "object",
407
+ properties: {
408
+ projectPath: { type: "string", default: "." },
409
+ includeReview: {
410
+ type: "boolean",
411
+ description: "Include files that need review",
412
+ default: false,
413
+ },
414
+ },
415
+ },
416
+ handler: hygieneDeletionPlan,
417
+ },
418
+ ];
419
+
420
+ module.exports = {
421
+ hygieneTools,
422
+ hygieneFullScan,
423
+ hygieneDuplicates,
424
+ hygieneUnused,
425
+ hygieneErrors,
426
+ hygieneRootCleanup,
427
+ hygieneDeletionPlan,
428
+ };