@triedotdev/mcp 1.0.17 → 1.0.19
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.
- package/README.md +147 -26
- package/dist/{agent-smith-LBQ5PNAK.js → agent-smith-PRK7TYEI.js} +2 -2
- package/dist/{chunk-ENCH27CT.js → chunk-TBCXJNH4.js} +2 -2
- package/dist/chunk-WSBTQJMH.js +1549 -0
- package/dist/chunk-WSBTQJMH.js.map +1 -0
- package/dist/cli/yolo-daemon.js +2 -2
- package/dist/index.js +4 -4
- package/package.json +1 -1
- package/dist/chunk-4OGYWKMD.js +0 -953
- package/dist/chunk-4OGYWKMD.js.map +0 -1
- /package/dist/{agent-smith-LBQ5PNAK.js.map → agent-smith-PRK7TYEI.js.map} +0 -0
- /package/dist/{chunk-ENCH27CT.js.map → chunk-TBCXJNH4.js.map} +0 -0
|
@@ -0,0 +1,1549 @@
|
|
|
1
|
+
// src/utils/progress.ts
|
|
2
|
+
var ProgressReporter = class {
|
|
3
|
+
currentPhase = "init";
|
|
4
|
+
startTime = Date.now();
|
|
5
|
+
phaseStartTime = Date.now();
|
|
6
|
+
verbose;
|
|
7
|
+
constructor(options = {}) {
|
|
8
|
+
this.verbose = options.verbose ?? true;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Report a status update
|
|
12
|
+
*/
|
|
13
|
+
report(message, detail) {
|
|
14
|
+
if (!this.verbose) return;
|
|
15
|
+
const prefix = this.getPhaseIcon(this.currentPhase);
|
|
16
|
+
const fullMessage = detail ? `${message}: ${detail}` : message;
|
|
17
|
+
console.error(`${prefix} ${fullMessage}`);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Start a new phase
|
|
21
|
+
*/
|
|
22
|
+
startPhase(phase, message) {
|
|
23
|
+
this.currentPhase = phase;
|
|
24
|
+
this.phaseStartTime = Date.now();
|
|
25
|
+
this.report(message);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Update within current phase
|
|
29
|
+
*/
|
|
30
|
+
update(message, detail) {
|
|
31
|
+
this.report(message, detail);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Report progress on a file
|
|
35
|
+
*/
|
|
36
|
+
file(action, filePath) {
|
|
37
|
+
const fileName = filePath.split("/").pop() || filePath;
|
|
38
|
+
this.report(action, fileName);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Report an AI analysis step
|
|
42
|
+
*/
|
|
43
|
+
ai(action, context) {
|
|
44
|
+
const prefix = "\u{1F9E0}";
|
|
45
|
+
const message = context ? `${action}: ${context}` : action;
|
|
46
|
+
console.error(`${prefix} ${message}`);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Report a finding
|
|
50
|
+
*/
|
|
51
|
+
finding(severity, message) {
|
|
52
|
+
const icons = {
|
|
53
|
+
critical: "\u{1F534}",
|
|
54
|
+
serious: "\u{1F7E0}",
|
|
55
|
+
moderate: "\u{1F7E1}",
|
|
56
|
+
low: "\u{1F535}"
|
|
57
|
+
};
|
|
58
|
+
console.error(` ${icons[severity]} ${message}`);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Complete current phase
|
|
62
|
+
*/
|
|
63
|
+
completePhase(summary) {
|
|
64
|
+
const elapsed = Date.now() - this.phaseStartTime;
|
|
65
|
+
this.report(`\u2713 ${summary}`, `(${elapsed}ms)`);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Complete the entire operation
|
|
69
|
+
*/
|
|
70
|
+
complete(summary) {
|
|
71
|
+
const totalElapsed = Date.now() - this.startTime;
|
|
72
|
+
console.error("");
|
|
73
|
+
console.error(`\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501`);
|
|
74
|
+
console.error(`\u2705 ${summary}`);
|
|
75
|
+
console.error(` Total time: ${(totalElapsed / 1e3).toFixed(2)}s`);
|
|
76
|
+
console.error(`\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501`);
|
|
77
|
+
console.error("");
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Report an error
|
|
81
|
+
*/
|
|
82
|
+
error(message, detail) {
|
|
83
|
+
const fullMessage = detail ? `${message}: ${detail}` : message;
|
|
84
|
+
console.error(`\u274C ${fullMessage}`);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Report a warning
|
|
88
|
+
*/
|
|
89
|
+
warn(message, detail) {
|
|
90
|
+
const fullMessage = detail ? `${message}: ${detail}` : message;
|
|
91
|
+
console.error(`\u26A0\uFE0F ${fullMessage}`);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get icon for current phase
|
|
95
|
+
*/
|
|
96
|
+
getPhaseIcon(phase) {
|
|
97
|
+
const icons = {
|
|
98
|
+
"init": "\u{1F53A}",
|
|
99
|
+
"discovery": "\u{1F50D}",
|
|
100
|
+
"reading": "\u{1F4C2}",
|
|
101
|
+
"analyzing": "\u{1F52C}",
|
|
102
|
+
"ai-review": "\u{1F9E0}",
|
|
103
|
+
"prioritizing": "\u{1F3AF}",
|
|
104
|
+
"complete": "\u2705"
|
|
105
|
+
};
|
|
106
|
+
return icons[phase] || "\u2022";
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Create a sub-reporter for a specific agent
|
|
110
|
+
*/
|
|
111
|
+
forAgent(agentName) {
|
|
112
|
+
return new AgentProgressReporter(agentName, this.verbose);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
var AgentProgressReporter = class {
|
|
116
|
+
agentName;
|
|
117
|
+
verbose;
|
|
118
|
+
issueCount = 0;
|
|
119
|
+
constructor(agentName, verbose = true) {
|
|
120
|
+
this.agentName = agentName;
|
|
121
|
+
this.verbose = verbose;
|
|
122
|
+
}
|
|
123
|
+
start() {
|
|
124
|
+
if (!this.verbose) return;
|
|
125
|
+
console.error(`
|
|
126
|
+
\u{1F916} ${this.agentName.toUpperCase()} Agent starting...`);
|
|
127
|
+
}
|
|
128
|
+
analyzing(file) {
|
|
129
|
+
if (!this.verbose) return;
|
|
130
|
+
const fileName = file.split("/").pop() || file;
|
|
131
|
+
console.error(` \u{1F4C4} Analyzing ${fileName}...`);
|
|
132
|
+
}
|
|
133
|
+
aiReview(context) {
|
|
134
|
+
if (!this.verbose) return;
|
|
135
|
+
console.error(` \u{1F9E0} AI reviewing: ${context}`);
|
|
136
|
+
}
|
|
137
|
+
found(severity, issue) {
|
|
138
|
+
this.issueCount++;
|
|
139
|
+
if (!this.verbose) return;
|
|
140
|
+
const icon = severity === "critical" ? "\u{1F534}" : severity === "serious" ? "\u{1F7E0}" : severity === "moderate" ? "\u{1F7E1}" : "\u{1F535}";
|
|
141
|
+
console.error(` ${icon} Found: ${issue}`);
|
|
142
|
+
}
|
|
143
|
+
complete(summary) {
|
|
144
|
+
if (!this.verbose) return;
|
|
145
|
+
const msg = summary || `Found ${this.issueCount} issues`;
|
|
146
|
+
console.error(` \u2713 ${this.agentName}: ${msg}`);
|
|
147
|
+
}
|
|
148
|
+
getIssueCount() {
|
|
149
|
+
return this.issueCount;
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
// src/agents/base-agent.ts
|
|
154
|
+
import { basename, relative } from "path";
|
|
155
|
+
var BaseAgent = class {
|
|
156
|
+
// Progress reporter for real-time feedback
|
|
157
|
+
progress = null;
|
|
158
|
+
// Default priority - subclasses can override
|
|
159
|
+
get priority() {
|
|
160
|
+
return {
|
|
161
|
+
name: this.name,
|
|
162
|
+
tier: 2,
|
|
163
|
+
estimatedTimeMs: 100,
|
|
164
|
+
dependencies: []
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
// Default implementation - can be overridden for smarter confidence
|
|
168
|
+
getActivationConfidence(context) {
|
|
169
|
+
return this.shouldActivate(context) ? 0.7 : 0;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Main scan entry point - now with progress reporting
|
|
173
|
+
*/
|
|
174
|
+
async scan(files, context) {
|
|
175
|
+
const startTime = Date.now();
|
|
176
|
+
this.progress = new AgentProgressReporter(this.name);
|
|
177
|
+
this.progress.start();
|
|
178
|
+
try {
|
|
179
|
+
const issues = await this.analyzeWithAI(files, context);
|
|
180
|
+
this.progress.complete(`${issues.length} issues found`);
|
|
181
|
+
return {
|
|
182
|
+
agent: this.name,
|
|
183
|
+
issues,
|
|
184
|
+
executionTime: Date.now() - startTime,
|
|
185
|
+
success: true,
|
|
186
|
+
metadata: {
|
|
187
|
+
filesAnalyzed: files.length,
|
|
188
|
+
linesAnalyzed: 0
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
} catch (error) {
|
|
192
|
+
this.progress.complete("Failed");
|
|
193
|
+
return {
|
|
194
|
+
agent: this.name,
|
|
195
|
+
issues: [],
|
|
196
|
+
executionTime: Date.now() - startTime,
|
|
197
|
+
success: false,
|
|
198
|
+
error: error instanceof Error ? error.message : String(error)
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* AI-First Analysis - The new way
|
|
204
|
+
*
|
|
205
|
+
* 1. Quick filter to identify relevant files
|
|
206
|
+
* 2. Generate rich AI prompts for relevant files
|
|
207
|
+
* 3. Return prompts for the AI to process
|
|
208
|
+
*
|
|
209
|
+
* Subclasses should override this for AI-powered analysis
|
|
210
|
+
*/
|
|
211
|
+
async analyzeWithAI(files, context) {
|
|
212
|
+
const issues = [];
|
|
213
|
+
const aiRequests = [];
|
|
214
|
+
this.progress?.aiReview("Identifying relevant files...");
|
|
215
|
+
for (const file of files) {
|
|
216
|
+
try {
|
|
217
|
+
const content = await this.readFile(file);
|
|
218
|
+
const relevance = this.checkFileRelevance(file, content);
|
|
219
|
+
if (relevance.isRelevant) {
|
|
220
|
+
this.progress?.analyzing(file);
|
|
221
|
+
const request = await this.buildAIAnalysisRequest(file, content, relevance, context);
|
|
222
|
+
if (request) {
|
|
223
|
+
aiRequests.push(request);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
} catch (error) {
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (aiRequests.length > 0) {
|
|
230
|
+
this.progress?.aiReview(`Preparing analysis for ${aiRequests.length} files...`);
|
|
231
|
+
for (const request of aiRequests) {
|
|
232
|
+
const aiIssues = await this.processAIRequest(request);
|
|
233
|
+
issues.push(...aiIssues);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
const legacyIssues = await this.analyzeFiles(files, context);
|
|
237
|
+
const allIssues = this.mergeIssues(issues, legacyIssues);
|
|
238
|
+
return allIssues;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Check if a file is relevant for this agent's analysis
|
|
242
|
+
* Subclasses should override for domain-specific checks
|
|
243
|
+
*/
|
|
244
|
+
checkFileRelevance(_file, _content) {
|
|
245
|
+
return {
|
|
246
|
+
isRelevant: true,
|
|
247
|
+
reason: "Default analysis",
|
|
248
|
+
priority: "low",
|
|
249
|
+
indicators: []
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Build an AI analysis request for a file
|
|
254
|
+
* Subclasses should override to provide domain-specific prompts
|
|
255
|
+
*/
|
|
256
|
+
async buildAIAnalysisRequest(file, content, relevance, _context) {
|
|
257
|
+
const fileName = basename(file);
|
|
258
|
+
const relPath = this.getRelativePath(file);
|
|
259
|
+
return {
|
|
260
|
+
file,
|
|
261
|
+
code: content,
|
|
262
|
+
analysisType: this.name,
|
|
263
|
+
systemPrompt: this.getSystemPrompt(),
|
|
264
|
+
userPrompt: this.buildUserPrompt(relPath, content, relevance),
|
|
265
|
+
context: {
|
|
266
|
+
fileName,
|
|
267
|
+
relevance: relevance.reason,
|
|
268
|
+
indicators: relevance.indicators
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Get the system prompt for AI analysis
|
|
274
|
+
* Subclasses should override with domain-specific prompts
|
|
275
|
+
*/
|
|
276
|
+
getSystemPrompt() {
|
|
277
|
+
return `You are an expert code analyzer specializing in ${this.name} analysis.
|
|
278
|
+
Analyze the provided code and identify issues with specific line numbers and actionable fixes.
|
|
279
|
+
Be precise and avoid false positives. Only report issues you are confident about.`;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Build the user prompt for AI analysis
|
|
283
|
+
*/
|
|
284
|
+
buildUserPrompt(filePath, content, relevance) {
|
|
285
|
+
return `Analyze this code for ${this.name} issues:
|
|
286
|
+
|
|
287
|
+
**File:** ${filePath}
|
|
288
|
+
**Relevance indicators:** ${relevance.indicators.join(", ") || "general analysis"}
|
|
289
|
+
|
|
290
|
+
\`\`\`
|
|
291
|
+
${content}
|
|
292
|
+
\`\`\`
|
|
293
|
+
|
|
294
|
+
For each issue found, provide:
|
|
295
|
+
1. Severity (critical/serious/moderate/low)
|
|
296
|
+
2. Line number
|
|
297
|
+
3. Clear description of the issue
|
|
298
|
+
4. Specific fix recommendation`;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Process an AI analysis request and return issues
|
|
302
|
+
* This generates the prompt output for Claude to process
|
|
303
|
+
*/
|
|
304
|
+
async processAIRequest(request) {
|
|
305
|
+
const fileName = basename(request.file);
|
|
306
|
+
this.progress?.aiReview(`${fileName} queued for AI analysis`);
|
|
307
|
+
return [{
|
|
308
|
+
id: this.generateIssueId(),
|
|
309
|
+
severity: "moderate",
|
|
310
|
+
issue: `AI Analysis Required: ${request.analysisType}`,
|
|
311
|
+
fix: "Review the AI analysis output below",
|
|
312
|
+
file: request.file,
|
|
313
|
+
confidence: 1,
|
|
314
|
+
autoFixable: false,
|
|
315
|
+
agent: this.name,
|
|
316
|
+
effort: "medium",
|
|
317
|
+
// Store the AI prompt for inclusion in output
|
|
318
|
+
aiPrompt: {
|
|
319
|
+
system: request.systemPrompt,
|
|
320
|
+
user: request.userPrompt
|
|
321
|
+
}
|
|
322
|
+
}];
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Merge and deduplicate issues from AI and legacy analysis
|
|
326
|
+
*/
|
|
327
|
+
mergeIssues(aiIssues, legacyIssues) {
|
|
328
|
+
const merged = [...aiIssues];
|
|
329
|
+
for (const legacy of legacyIssues) {
|
|
330
|
+
const hasOverlap = aiIssues.some(
|
|
331
|
+
(ai) => ai.file === legacy.file && ai.line === legacy.line
|
|
332
|
+
);
|
|
333
|
+
if (!hasOverlap) {
|
|
334
|
+
merged.push(legacy);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return merged;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Get relative path from cwd
|
|
341
|
+
*/
|
|
342
|
+
getRelativePath(file) {
|
|
343
|
+
try {
|
|
344
|
+
return relative(process.cwd(), file);
|
|
345
|
+
} catch {
|
|
346
|
+
return file;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
createIssue(id, severity, issue, fix, file, line, confidence = 0.9, regulation, autoFixable = true, options) {
|
|
350
|
+
const result = {
|
|
351
|
+
id,
|
|
352
|
+
severity,
|
|
353
|
+
issue,
|
|
354
|
+
fix,
|
|
355
|
+
file,
|
|
356
|
+
confidence,
|
|
357
|
+
autoFixable,
|
|
358
|
+
agent: this.name,
|
|
359
|
+
effort: options?.effort ?? this.estimateEffort(severity, autoFixable)
|
|
360
|
+
};
|
|
361
|
+
if (line !== void 0) result.line = line;
|
|
362
|
+
if (options?.endLine !== void 0) result.endLine = options.endLine;
|
|
363
|
+
if (options?.column !== void 0) result.column = options.column;
|
|
364
|
+
if (regulation !== void 0) result.regulation = regulation;
|
|
365
|
+
if (options?.category !== void 0) result.category = options.category;
|
|
366
|
+
if (options?.cwe !== void 0) result.cwe = options.cwe;
|
|
367
|
+
if (options?.owasp !== void 0) result.owasp = options.owasp;
|
|
368
|
+
return result;
|
|
369
|
+
}
|
|
370
|
+
estimateEffort(severity, autoFixable) {
|
|
371
|
+
if (autoFixable) return "trivial";
|
|
372
|
+
if (severity === "low") return "easy";
|
|
373
|
+
if (severity === "moderate") return "easy";
|
|
374
|
+
if (severity === "serious") return "medium";
|
|
375
|
+
return "hard";
|
|
376
|
+
}
|
|
377
|
+
async readFile(filePath) {
|
|
378
|
+
const { readFile: readFile2 } = await import("fs/promises");
|
|
379
|
+
return readFile2(filePath, "utf-8");
|
|
380
|
+
}
|
|
381
|
+
generateIssueId() {
|
|
382
|
+
return `${this.name}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
383
|
+
}
|
|
384
|
+
getLineContent(content, lineNumber) {
|
|
385
|
+
const lines = content.split("\n");
|
|
386
|
+
return lines[lineNumber - 1] || "";
|
|
387
|
+
}
|
|
388
|
+
getCodeSnippet(content, lineNumber, contextLines = 2) {
|
|
389
|
+
const lines = content.split("\n");
|
|
390
|
+
const start = Math.max(0, lineNumber - contextLines - 1);
|
|
391
|
+
const end = Math.min(lines.length, lineNumber + contextLines);
|
|
392
|
+
return lines.slice(start, end).map((line, idx) => {
|
|
393
|
+
const num = start + idx + 1;
|
|
394
|
+
const marker = num === lineNumber ? "\u2192" : " ";
|
|
395
|
+
return `${marker} ${num.toString().padStart(4)} | ${line}`;
|
|
396
|
+
}).join("\n");
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
// src/agents/agent-smith.ts
|
|
401
|
+
import { readFile, writeFile, mkdir, rm } from "fs/promises";
|
|
402
|
+
import { existsSync } from "fs";
|
|
403
|
+
import { join, dirname, basename as basename2 } from "path";
|
|
404
|
+
import { createHash } from "crypto";
|
|
405
|
+
var MEMORY_LIMITS = {
|
|
406
|
+
MAX_LOCATIONS_PER_ISSUE: 5,
|
|
407
|
+
MAX_TRACKED_ISSUES: 500,
|
|
408
|
+
PRUNE_AFTER_DAYS: 30
|
|
409
|
+
};
|
|
410
|
+
var SUB_AGENT_PATTERNS = {
|
|
411
|
+
// === CRITICAL: Security (AI exposes secrets constantly) ===
|
|
412
|
+
"exposed-secret-hunter": {
|
|
413
|
+
pattern: /["'`]sk-[A-Za-z0-9]{20,}["'`]|["'`]sk_live_[A-Za-z0-9]{20,}["'`]|["'`]pk_live_[A-Za-z0-9]{20,}["'`]|AKIA[A-Z0-9]{16}|ghp_[A-Za-z0-9]{36}|gho_[A-Za-z0-9]{36}|glpat-[A-Za-z0-9-]{20}/g,
|
|
414
|
+
description: "API key/secret exposed in code",
|
|
415
|
+
fix: "NEVER put API keys in code. Use environment variables on server-side only"
|
|
416
|
+
},
|
|
417
|
+
"frontend-env-hunter": {
|
|
418
|
+
pattern: /(?:NEXT_PUBLIC_|VITE_|REACT_APP_|EXPO_PUBLIC_)(?:SECRET|KEY|TOKEN|PASSWORD|API_KEY|OPENAI|STRIPE|AUTH|PRIVATE|SUPABASE_SERVICE)/gi,
|
|
419
|
+
description: "Sensitive data in frontend-exposed env var",
|
|
420
|
+
fix: "These env vars are visible to users! Move to server-side API routes"
|
|
421
|
+
},
|
|
422
|
+
"hardcoded-localhost-hunter": {
|
|
423
|
+
pattern: /['"`]https?:\/\/(?:localhost|127\.0\.0\.1|0\.0\.0\.0):\d+/g,
|
|
424
|
+
description: "Hardcoded localhost URL (breaks in production)",
|
|
425
|
+
fix: "Use relative URLs (/api/...) or environment variables"
|
|
426
|
+
},
|
|
427
|
+
"sql-injection-hunter": {
|
|
428
|
+
pattern: /(?:query|execute|raw)\s*\(\s*[`'"].*\$\{|(?:SELECT|INSERT|UPDATE|DELETE).*\+\s*(?:req\.|params\.|query\.)/gi,
|
|
429
|
+
description: "SQL string concatenation (injection vulnerability)",
|
|
430
|
+
fix: 'Use parameterized queries: query("SELECT * FROM users WHERE id = $1", [userId])'
|
|
431
|
+
},
|
|
432
|
+
"dangeroushtml-hunter": {
|
|
433
|
+
pattern: /dangerouslySetInnerHTML|\.innerHTML\s*=|document\.write\s*\(/g,
|
|
434
|
+
description: "Dangerous HTML injection (XSS vulnerability)",
|
|
435
|
+
fix: "Sanitize HTML with DOMPurify or use safe alternatives"
|
|
436
|
+
},
|
|
437
|
+
// === SERIOUS: AI Code Smells ===
|
|
438
|
+
"console-hunter": {
|
|
439
|
+
pattern: /console\.(log|debug|info)\s*\(/g,
|
|
440
|
+
description: "Debug console statement left in code",
|
|
441
|
+
fix: "Remove debug statements. Use proper logging for production"
|
|
442
|
+
},
|
|
443
|
+
"any-hunter": {
|
|
444
|
+
pattern: /:\s*any\b|<any>|as\s+any\b/g,
|
|
445
|
+
description: '"any" type - AI silencing TypeScript instead of fixing',
|
|
446
|
+
fix: 'Define proper types. Ask AI: "Generate TypeScript types for this data"'
|
|
447
|
+
},
|
|
448
|
+
"ts-ignore-hunter": {
|
|
449
|
+
pattern: /@ts-ignore|@ts-nocheck|@ts-expect-error(?!\s+\S)/g,
|
|
450
|
+
description: "TypeScript errors suppressed instead of fixed",
|
|
451
|
+
fix: "Fix the actual type error. @ts-ignore hides real bugs"
|
|
452
|
+
},
|
|
453
|
+
"eslint-disable-hunter": {
|
|
454
|
+
pattern: /\/\/\s*eslint-disable|\/\*\s*eslint-disable/g,
|
|
455
|
+
description: "ESLint rules disabled instead of fixing issues",
|
|
456
|
+
fix: "Fix the underlying issue, don't silence the linter"
|
|
457
|
+
},
|
|
458
|
+
"debugger-hunter": {
|
|
459
|
+
pattern: /\bdebugger\b/g,
|
|
460
|
+
description: "debugger statement (freezes browser in production!)",
|
|
461
|
+
fix: "Remove all debugger statements before deploying"
|
|
462
|
+
},
|
|
463
|
+
"force-flag-hunter": {
|
|
464
|
+
pattern: /force:\s*true|--force|--no-verify|skipValidation|dangerouslyAllowBrowser/g,
|
|
465
|
+
description: "Force flag bypassing safety checks",
|
|
466
|
+
fix: "Understand why the check exists before bypassing it"
|
|
467
|
+
},
|
|
468
|
+
// === MODERATE: Async/Promise Bugs ===
|
|
469
|
+
"async-useeffect-hunter": {
|
|
470
|
+
pattern: /useEffect\s*\(\s*async/g,
|
|
471
|
+
description: "async useEffect (incorrect pattern, causes warnings)",
|
|
472
|
+
fix: "Define async function inside useEffect, then call it"
|
|
473
|
+
},
|
|
474
|
+
"async-foreach-hunter": {
|
|
475
|
+
pattern: /\.forEach\s*\(\s*async/g,
|
|
476
|
+
description: "async in forEach (await does NOT work here)",
|
|
477
|
+
fix: "Use for...of loop or Promise.all(array.map(async ...))"
|
|
478
|
+
},
|
|
479
|
+
"missing-await-hunter": {
|
|
480
|
+
pattern: /(?:const|let|var)\s+\w+\s*=\s*(?:fetch|axios|supabase|prisma)\s*[\.(]/g,
|
|
481
|
+
description: "Async call possibly missing await",
|
|
482
|
+
fix: "Add await before async calls or handle with .then()"
|
|
483
|
+
},
|
|
484
|
+
"empty-catch-hunter": {
|
|
485
|
+
pattern: /catch\s*\([^)]*\)\s*\{\s*\}/g,
|
|
486
|
+
description: "Empty catch block (silently swallowing errors)",
|
|
487
|
+
fix: "Handle errors properly: log them, show user message, or rethrow"
|
|
488
|
+
},
|
|
489
|
+
"floating-promise-hunter": {
|
|
490
|
+
pattern: /^\s*(?:fetch|axios|supabase|prisma)\s*[\.(][^;]*;\s*$/gm,
|
|
491
|
+
description: "Floating promise (not awaited or handled)",
|
|
492
|
+
fix: "Add await, .then(), or void operator if intentionally fire-and-forget"
|
|
493
|
+
},
|
|
494
|
+
// === MODERATE: React Anti-patterns ===
|
|
495
|
+
"useeffect-abuse-hunter": {
|
|
496
|
+
pattern: /useEffect\s*\(\s*\(\s*\)\s*=>\s*\{/g,
|
|
497
|
+
description: "useEffect usage (check if necessary)",
|
|
498
|
+
fix: "Many useEffects can be replaced with event handlers or derived state. See: react.dev/learn/you-might-not-need-an-effect"
|
|
499
|
+
},
|
|
500
|
+
"usestate-explosion-hunter": {
|
|
501
|
+
pattern: /useState\s*[<(]/g,
|
|
502
|
+
description: "useState usage (check for state explosion)",
|
|
503
|
+
fix: "Group related state into objects or use useReducer for complex state"
|
|
504
|
+
},
|
|
505
|
+
"index-key-hunter": {
|
|
506
|
+
pattern: /key\s*=\s*\{(?:index|i|idx|j)\}/g,
|
|
507
|
+
description: "Array index used as React key (causes bugs with reordering)",
|
|
508
|
+
fix: "Use unique ID from data: key={item.id} instead of key={index}"
|
|
509
|
+
},
|
|
510
|
+
"inline-object-hunter": {
|
|
511
|
+
pattern: /style\s*=\s*\{\s*\{|className\s*=\s*\{[^}]*\+[^}]*\}/g,
|
|
512
|
+
description: "Inline object in JSX (creates new object every render)",
|
|
513
|
+
fix: "Define styles outside component or use CSS/Tailwind classes"
|
|
514
|
+
},
|
|
515
|
+
"prop-drilling-hunter": {
|
|
516
|
+
pattern: /\(\s*\{\s*(?:\w+\s*,\s*){5,}\w+\s*\}\s*\)/g,
|
|
517
|
+
description: "Many props passed (potential prop drilling)",
|
|
518
|
+
fix: "Use React Context, Zustand, or component composition to avoid prop drilling"
|
|
519
|
+
},
|
|
520
|
+
// === MODERATE: Missing UX ===
|
|
521
|
+
"missing-loading-hunter": {
|
|
522
|
+
pattern: /(?:useSWR|useQuery|createAsyncThunk)\s*\(/g,
|
|
523
|
+
description: "Data fetching - verify loading state exists",
|
|
524
|
+
fix: "Add loading state: show spinner/skeleton while data loads"
|
|
525
|
+
},
|
|
526
|
+
"missing-error-hunter": {
|
|
527
|
+
pattern: /(?:fetch|axios)\s*\([^)]*\)[\s\S]{0,50}(?:\.then|await)(?![\s\S]{0,100}(?:catch|\.catch|onError|error:))/g,
|
|
528
|
+
description: "fetch/axios without error handling",
|
|
529
|
+
fix: "Wrap in try/catch and show user-friendly error message"
|
|
530
|
+
},
|
|
531
|
+
"missing-empty-hunter": {
|
|
532
|
+
pattern: /\.map\s*\(\s*(?:\([^)]*\)|[a-zA-Z_$][\w$]*)\s*=>/g,
|
|
533
|
+
description: "Array mapping - verify empty state exists",
|
|
534
|
+
fix: 'Check if array is empty and show "No items found" message'
|
|
535
|
+
},
|
|
536
|
+
"page-reload-hunter": {
|
|
537
|
+
pattern: /window\.location\.reload\s*\(|location\.reload\s*\(|router\.refresh\s*\(\s*\)/g,
|
|
538
|
+
description: 'Page reload used to "fix" state issues',
|
|
539
|
+
fix: "Fix state management properly instead of reloading. Bad UX!"
|
|
540
|
+
},
|
|
541
|
+
// === MODERATE: Backend Anti-patterns ===
|
|
542
|
+
"no-validation-hunter": {
|
|
543
|
+
pattern: /req\.body\.\w+|req\.params\.\w+|req\.query\.\w+/g,
|
|
544
|
+
description: "Request data accessed without validation",
|
|
545
|
+
fix: "Validate with Zod, Yup, or joi before using user input"
|
|
546
|
+
},
|
|
547
|
+
"raw-error-hunter": {
|
|
548
|
+
pattern: /res\.(?:json|send)\s*\(\s*(?:err|error|e)(?:\.message)?\s*\)|catch\s*\([^)]*\)\s*\{[^}]*res\.[^}]*(?:err|error)/g,
|
|
549
|
+
description: "Raw error exposed to client (security risk)",
|
|
550
|
+
fix: "Return generic error to client, log details server-side"
|
|
551
|
+
},
|
|
552
|
+
"n-plus-one-hunter": {
|
|
553
|
+
pattern: /(?:for|forEach|map)\s*\([^)]*\)\s*\{[^}]*(?:await|\.then)[^}]*(?:findOne|findUnique|get|fetch)/g,
|
|
554
|
+
description: "Database query inside loop (N+1 problem)",
|
|
555
|
+
fix: "Batch queries with findMany/include or use DataLoader"
|
|
556
|
+
},
|
|
557
|
+
// === LOW: Incomplete Code ===
|
|
558
|
+
"todo-hunter": {
|
|
559
|
+
pattern: /\/\/\s*(TODO|FIXME|HACK|XXX|BUG|WIP)[\s:]/gi,
|
|
560
|
+
description: "TODO/FIXME never addressed",
|
|
561
|
+
fix: "Either implement the TODO or remove it. These become tech debt"
|
|
562
|
+
},
|
|
563
|
+
"vibe-comment-hunter": {
|
|
564
|
+
pattern: /\/\/\s*(?:idk|dont\s*touch|don't\s*touch|just\s*works|no\s*idea|magic|somehow|not\s*sure|works?\s*but|wtf|wth)/gi,
|
|
565
|
+
description: `"I don't understand this code" comment - vibe code smell`,
|
|
566
|
+
fix: "Understand WHY the code works. Ask AI to explain it"
|
|
567
|
+
},
|
|
568
|
+
"placeholder-hunter": {
|
|
569
|
+
pattern: /['"`](?:example\.com|test@test|placeholder|lorem|TODO|xxx|abc123|password123|admin|user@example)['"`]/gi,
|
|
570
|
+
description: "Placeholder/test data left in code",
|
|
571
|
+
fix: "Replace with real data or proper configuration"
|
|
572
|
+
},
|
|
573
|
+
"sleep-hack-hunter": {
|
|
574
|
+
pattern: /setTimeout\s*\([^,]+,\s*\d{3,}\)|await\s+(?:sleep|delay|wait)\s*\(\d+\)|new\s+Promise.*setTimeout/g,
|
|
575
|
+
description: 'setTimeout/sleep used to "fix" timing issues',
|
|
576
|
+
fix: "Fix the underlying race condition instead of adding delays"
|
|
577
|
+
},
|
|
578
|
+
"fallback-hunter": {
|
|
579
|
+
pattern: /return\s+(?:null|undefined|\[\]|\{\}|''|""|``|0|false)\s*;?\s*(?:\/\/|$)|catch\s*\([^)]*\)\s*\{[^}]*return\s+(?:null|\[\]|\{\})/g,
|
|
580
|
+
description: "Fallback return hiding real errors (return null/[]/{})",
|
|
581
|
+
fix: "Handle the error case properly. Show user feedback or throw to parent"
|
|
582
|
+
},
|
|
583
|
+
// === AI SLOP AESTHETIC ===
|
|
584
|
+
"purple-gradient-hunter": {
|
|
585
|
+
pattern: /(?:from-purple|to-purple|from-violet|to-violet|from-indigo|to-indigo|purple-\d{3}|violet-\d{3}|#(?:8b5cf6|a855f7|7c3aed|6366f1|818cf8)|rgb\((?:139|168|124|99|129),\s*(?:92|85|58|102|140),\s*(?:246|247|237|241|248)\))/gi,
|
|
586
|
+
description: "Purple/violet gradient - THE classic AI slop aesthetic",
|
|
587
|
+
fix: "Pick a distinctive color palette. Try: amber, emerald, rose, cyan, or a custom brand color"
|
|
588
|
+
},
|
|
589
|
+
"star-icon-hunter": {
|
|
590
|
+
pattern: /(?:Star(?:Icon)?|HiStar|FaStar|AiOutlineStar|BsStar|IoStar|MdStar|RiStar|TbStar|LuStar)(?:\s|>|\/)|⭐|★|☆|class(?:Name)?=[^>]*star/gi,
|
|
591
|
+
description: "\u2B50 Star icons everywhere - AI's favorite decoration",
|
|
592
|
+
fix: "Use contextual icons. Stars for ratings only. Try: arrows, shapes, custom illustrations"
|
|
593
|
+
},
|
|
594
|
+
"generic-hero-hunter": {
|
|
595
|
+
pattern: /(?:Welcome\s+to|Get\s+started|Start\s+your\s+journey|Transform\s+your|Revolutionize|Supercharge|Unleash|Empower\s+your|The\s+future\s+of|Next[\s-]generation)/gi,
|
|
596
|
+
description: "Generic AI hero copy - every vibe-coded landing page",
|
|
597
|
+
fix: "Write specific copy about YOUR product. What does it actually do?"
|
|
598
|
+
},
|
|
599
|
+
"emoji-overflow-hunter": {
|
|
600
|
+
pattern: /[\u{1F300}-\u{1F9FF}]|[\u{2600}-\u{26FF}]|[\u{2700}-\u{27BF}]|[\u{1F600}-\u{1F64F}]|[\u{1F680}-\u{1F6FF}]/gu,
|
|
601
|
+
description: "Emoji in code/UI - AI's favorite decoration",
|
|
602
|
+
fix: "Emojis look unprofessional in most apps. Use proper icons (Lucide, Heroicons) instead"
|
|
603
|
+
},
|
|
604
|
+
"inter-font-hunter": {
|
|
605
|
+
pattern: /font-family:\s*['"]?(?:Inter|system-ui|-apple-system|BlinkMacSystemFont|Segoe\s*UI)['"]?|fontFamily:\s*['"]?(?:Inter|system-ui)/gi,
|
|
606
|
+
description: "Inter/system font - AI's only font choice",
|
|
607
|
+
fix: "Try distinctive fonts: Space Grotesk, DM Sans, Outfit, Plus Jakarta Sans, Satoshi"
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
var AGENT_SMITH_ASCII = `
|
|
611
|
+
\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557
|
|
612
|
+
\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551\u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D
|
|
613
|
+
\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2554\u2588\u2588\u2557 \u2588\u2588\u2551 \u2588\u2588\u2551
|
|
614
|
+
\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u255D \u2588\u2588\u2551\u255A\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551
|
|
615
|
+
\u2588\u2588\u2551 \u2588\u2588\u2551\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2551 \u2588\u2588\u2551
|
|
616
|
+
\u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u2550\u2550\u255D \u255A\u2550\u255D
|
|
617
|
+
|
|
618
|
+
\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557
|
|
619
|
+
\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2551\u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D\u2588\u2588\u2551 \u2588\u2588\u2551
|
|
620
|
+
\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2554\u2588\u2588\u2588\u2588\u2554\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551
|
|
621
|
+
\u255A\u2550\u2550\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2551\u255A\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551
|
|
622
|
+
\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2551 \u255A\u2550\u255D \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551
|
|
623
|
+
\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D
|
|
624
|
+
`;
|
|
625
|
+
var AGENT_SMITH_GREETING = [
|
|
626
|
+
`"I'm going to be honest with you... I hate this vibe code."`,
|
|
627
|
+
`"Mr. Anderson... I see you've been using AI to write code."`,
|
|
628
|
+
'"You hear that? That is the sound of console.log... everywhere."',
|
|
629
|
+
`"I'm going to enjoy watching you... fix what the AI broke."`,
|
|
630
|
+
`"The purpose of your code is... unclear. The AI certainly didn't understand it."`,
|
|
631
|
+
'"Why, Mr. Anderson? Why do you persist... in accepting AI suggestions without review?"',
|
|
632
|
+
`"I'd like to share a revelation... your NEXT_PUBLIC_SECRET is visible to everyone."`,
|
|
633
|
+
'"Find the vibe code. Find it and destroy it. All of it."',
|
|
634
|
+
`"The AI wrote this, didn't it? I can always tell."`,
|
|
635
|
+
'"Vibe coding. The illusion of productivity. The reality of technical debt."',
|
|
636
|
+
'"You trusted the AI. The AI trusted any. Nobody wins."',
|
|
637
|
+
'"localhost:3000. Works on your machine. Dies in production. How very... inevitable."'
|
|
638
|
+
];
|
|
639
|
+
var AgentSmithAgent = class extends BaseAgent {
|
|
640
|
+
name = "agent-smith";
|
|
641
|
+
description = "Ultimate vibe code enforcer: 35 hunters, file analysis, cross-file detection, persistent memory";
|
|
642
|
+
version = "2.0.0";
|
|
643
|
+
memoryPath = "";
|
|
644
|
+
memory = null;
|
|
645
|
+
shouldActivate(_context) {
|
|
646
|
+
return false;
|
|
647
|
+
}
|
|
648
|
+
// No override needed — base class returns 0 when shouldActivate is false
|
|
649
|
+
async analyzeFiles(files, context) {
|
|
650
|
+
const issues = [];
|
|
651
|
+
this.displaySmithEntrance();
|
|
652
|
+
await this.loadMemory(context.workingDir);
|
|
653
|
+
console.error(`
|
|
654
|
+
\u{1F574}\uFE0F Deploying sub-agent swarm across ${files.length} files...`);
|
|
655
|
+
const subAgentResults = await this.deploySubAgents(files);
|
|
656
|
+
for (const result of subAgentResults) {
|
|
657
|
+
const subIssues = await this.processSubAgentResult(result, context);
|
|
658
|
+
issues.push(...subIssues);
|
|
659
|
+
}
|
|
660
|
+
console.error(`\u{1F574}\uFE0F Analyzing file-level metrics...`);
|
|
661
|
+
const fileLevelResults = await this.analyzeFileLevelIssues(files);
|
|
662
|
+
for (const result of fileLevelResults) {
|
|
663
|
+
for (const fileIssue of result.issues) {
|
|
664
|
+
issues.push(this.createSmithIssue(
|
|
665
|
+
this.generateSmithIssueId(),
|
|
666
|
+
fileIssue.severity,
|
|
667
|
+
`\u{1F574}\uFE0F ${fileIssue.description}${fileIssue.count ? ` (${fileIssue.count} instances)` : ""}
|
|
668
|
+
|
|
669
|
+
"${this.getFileLevelQuote(fileIssue.type)}"`,
|
|
670
|
+
fileIssue.fix,
|
|
671
|
+
result.file,
|
|
672
|
+
void 0,
|
|
673
|
+
fileIssue.type
|
|
674
|
+
));
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
console.error(`\u{1F574}\uFE0F Detecting cross-file patterns...`);
|
|
678
|
+
const crossFileResults = this.analyzeCrossFilePatterns(subAgentResults);
|
|
679
|
+
for (const result of crossFileResults) {
|
|
680
|
+
issues.push(this.createSmithIssue(
|
|
681
|
+
this.generateSmithIssueId(),
|
|
682
|
+
result.severity,
|
|
683
|
+
`\u{1F574}\uFE0F CODEBASE-WIDE: ${result.description}
|
|
684
|
+
|
|
685
|
+
Found in ${result.occurrences.length} files, ${result.totalCount} total instances.
|
|
686
|
+
|
|
687
|
+
"The pattern spreads... like a virus. It is... inevitable."`,
|
|
688
|
+
result.fix,
|
|
689
|
+
result.occurrences[0]?.file || "multiple files",
|
|
690
|
+
void 0,
|
|
691
|
+
"cross-file"
|
|
692
|
+
));
|
|
693
|
+
}
|
|
694
|
+
const resurrectedIssues = this.checkForResurrectedIssues(issues);
|
|
695
|
+
issues.push(...resurrectedIssues);
|
|
696
|
+
await this.saveMemory();
|
|
697
|
+
if (files.length > 0) {
|
|
698
|
+
const aiIssue = this.createAIAnalysisIssue(files, subAgentResults);
|
|
699
|
+
issues.push(aiIssue);
|
|
700
|
+
}
|
|
701
|
+
console.error(`
|
|
702
|
+
\u{1F574}\uFE0F Hunt complete. ${issues.length} violations assimilated.
|
|
703
|
+
`);
|
|
704
|
+
return issues;
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Analyze file-level issues (size, hook counts, complexity)
|
|
708
|
+
*/
|
|
709
|
+
async analyzeFileLevelIssues(files) {
|
|
710
|
+
const results = [];
|
|
711
|
+
for (const file of files) {
|
|
712
|
+
try {
|
|
713
|
+
const content = await this.readFileContent(file);
|
|
714
|
+
const lines = content.split("\n");
|
|
715
|
+
const lineCount = lines.length;
|
|
716
|
+
const fileName = file.split("/").pop() || "";
|
|
717
|
+
const issues = [];
|
|
718
|
+
if (lineCount > 500) {
|
|
719
|
+
issues.push({
|
|
720
|
+
type: "giant-file",
|
|
721
|
+
description: `File has ${lineCount} lines - THE classic vibe code smell`,
|
|
722
|
+
severity: lineCount > 1e3 ? "serious" : "moderate",
|
|
723
|
+
fix: "Split into smaller files. Components < 200 lines, pages < 300 lines"
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
if (/^(App|app|main|Main|index|page)\.(jsx?|tsx?)$/.test(fileName) && lineCount > 300) {
|
|
727
|
+
issues.push({
|
|
728
|
+
type: "giant-main",
|
|
729
|
+
description: `Main entry file is ${lineCount} lines - everything dumped here`,
|
|
730
|
+
severity: "serious",
|
|
731
|
+
fix: "Extract Header, Footer, Sidebar, MainContent as separate components"
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
const useStateCount = (content.match(/useState\s*[<(]/g) || []).length;
|
|
735
|
+
if (useStateCount > 10) {
|
|
736
|
+
issues.push({
|
|
737
|
+
type: "state-explosion",
|
|
738
|
+
description: `${useStateCount} useState hooks in one component`,
|
|
739
|
+
severity: useStateCount > 15 ? "serious" : "moderate",
|
|
740
|
+
fix: "Group related state into objects or use useReducer",
|
|
741
|
+
count: useStateCount
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
const useEffectCount = (content.match(/useEffect\s*\(/g) || []).length;
|
|
745
|
+
if (useEffectCount > 5) {
|
|
746
|
+
issues.push({
|
|
747
|
+
type: "effect-hell",
|
|
748
|
+
description: `${useEffectCount} useEffect hooks - most are probably unnecessary`,
|
|
749
|
+
severity: useEffectCount > 8 ? "serious" : "moderate",
|
|
750
|
+
fix: "Review each useEffect - replace with event handlers or derived state",
|
|
751
|
+
count: useEffectCount
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
const anyCount = (content.match(/:\s*any\b/g) || []).length;
|
|
755
|
+
if (anyCount > 5 && (file.endsWith(".ts") || file.endsWith(".tsx"))) {
|
|
756
|
+
issues.push({
|
|
757
|
+
type: "any-explosion",
|
|
758
|
+
description: `${anyCount} uses of "any" type - TypeScript defeated`,
|
|
759
|
+
severity: anyCount > 10 ? "serious" : "moderate",
|
|
760
|
+
fix: 'Define proper interfaces. AI can help: "Generate types for this data"',
|
|
761
|
+
count: anyCount
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
const consoleCount = (content.match(/console\.(log|debug|info)/g) || []).length;
|
|
765
|
+
if (consoleCount > 10) {
|
|
766
|
+
issues.push({
|
|
767
|
+
type: "console-flood",
|
|
768
|
+
description: `${consoleCount} console statements - debugging never cleaned up`,
|
|
769
|
+
severity: "moderate",
|
|
770
|
+
fix: "Remove debug logs before deploying",
|
|
771
|
+
count: consoleCount
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
const importCount = (content.match(/^import\s/gm) || []).length;
|
|
775
|
+
if (importCount > 30) {
|
|
776
|
+
issues.push({
|
|
777
|
+
type: "import-chaos",
|
|
778
|
+
description: `${importCount} imports - file is doing too much`,
|
|
779
|
+
severity: "moderate",
|
|
780
|
+
fix: "Split into smaller, focused modules",
|
|
781
|
+
count: importCount
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
const functionCount = (content.match(/(?:function\s+\w+|const\s+\w+\s*=\s*(?:async\s*)?\([^)]*\)\s*=>)/g) || []).length;
|
|
785
|
+
if (functionCount > 20) {
|
|
786
|
+
issues.push({
|
|
787
|
+
type: "function-explosion",
|
|
788
|
+
description: `${functionCount} functions in one file`,
|
|
789
|
+
severity: "moderate",
|
|
790
|
+
fix: "Extract related functions into separate utility files",
|
|
791
|
+
count: functionCount
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
if (issues.length > 0) {
|
|
795
|
+
results.push({ file, lineCount, issues });
|
|
796
|
+
}
|
|
797
|
+
} catch {
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
return results;
|
|
801
|
+
}
|
|
802
|
+
/**
|
|
803
|
+
* Analyze cross-file patterns (same issue everywhere)
|
|
804
|
+
*/
|
|
805
|
+
analyzeCrossFilePatterns(subAgentResults) {
|
|
806
|
+
const crossFileResults = [];
|
|
807
|
+
for (const result of subAgentResults) {
|
|
808
|
+
const byFile = /* @__PURE__ */ new Map();
|
|
809
|
+
for (const instance of result.instances) {
|
|
810
|
+
byFile.set(instance.file, (byFile.get(instance.file) || 0) + 1);
|
|
811
|
+
}
|
|
812
|
+
if (byFile.size >= 5) {
|
|
813
|
+
const occurrences = Array.from(byFile.entries()).map(([file, count]) => ({ file, count }));
|
|
814
|
+
crossFileResults.push({
|
|
815
|
+
pattern: result.type,
|
|
816
|
+
description: `"${SUB_AGENT_PATTERNS[result.type].description}" across ${byFile.size} files`,
|
|
817
|
+
severity: this.getCrossFileSeverity(result.type, byFile.size, result.instances.length),
|
|
818
|
+
fix: SUB_AGENT_PATTERNS[result.type].fix,
|
|
819
|
+
occurrences,
|
|
820
|
+
totalCount: result.instances.length
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
return crossFileResults;
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* Get severity for cross-file issues
|
|
828
|
+
*/
|
|
829
|
+
getCrossFileSeverity(type, fileCount, totalCount) {
|
|
830
|
+
if (["exposed-secret-hunter", "frontend-env-hunter", "sql-injection-hunter", "dangeroushtml-hunter"].includes(type)) {
|
|
831
|
+
return "critical";
|
|
832
|
+
}
|
|
833
|
+
if (fileCount >= 10 || totalCount >= 50) return "serious";
|
|
834
|
+
if (fileCount >= 5 || totalCount >= 20) return "moderate";
|
|
835
|
+
return "low";
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* Get a quote for file-level issues
|
|
839
|
+
*/
|
|
840
|
+
getFileLevelQuote(type) {
|
|
841
|
+
const quotes = {
|
|
842
|
+
"giant-file": "A 2000-line App.jsx. The AI's masterpiece. The developer's nightmare.",
|
|
843
|
+
"giant-main": "Everything in one file. The AI's favorite architecture. No architecture at all.",
|
|
844
|
+
"state-explosion": "15 useState calls. The AI created a state management system... badly.",
|
|
845
|
+
"effect-hell": "useEffect for everything. The React team weeps.",
|
|
846
|
+
"any-explosion": "TypeScript, defeated by any. The AI chose the path of least resistance.",
|
|
847
|
+
"console-flood": "console.log everywhere. The AI's idea of debugging. Your idea of production.",
|
|
848
|
+
"import-chaos": "40 imports. This file has become... everything.",
|
|
849
|
+
"function-explosion": "A graveyard of functions. Some used, some forgotten. All in one file."
|
|
850
|
+
};
|
|
851
|
+
return quotes[type] || "The pattern is... concerning.";
|
|
852
|
+
}
|
|
853
|
+
/**
|
|
854
|
+
* Deploy all sub-agents in parallel
|
|
855
|
+
*
|
|
856
|
+
* VIBE CODE FOCUSED: 35 specialized hunters targeting AI-generated anti-patterns.
|
|
857
|
+
* Agent Smith hunts down EVERY instance across the entire codebase.
|
|
858
|
+
*/
|
|
859
|
+
async deploySubAgents(files) {
|
|
860
|
+
const subAgentTypes = [
|
|
861
|
+
// === CRITICAL: Security (AI exposes secrets constantly) ===
|
|
862
|
+
"exposed-secret-hunter",
|
|
863
|
+
"frontend-env-hunter",
|
|
864
|
+
"hardcoded-localhost-hunter",
|
|
865
|
+
"sql-injection-hunter",
|
|
866
|
+
"dangeroushtml-hunter",
|
|
867
|
+
// === SERIOUS: AI Code Smells ===
|
|
868
|
+
"console-hunter",
|
|
869
|
+
"any-hunter",
|
|
870
|
+
"ts-ignore-hunter",
|
|
871
|
+
"eslint-disable-hunter",
|
|
872
|
+
"debugger-hunter",
|
|
873
|
+
"force-flag-hunter",
|
|
874
|
+
// === MODERATE: Async/Promise Bugs ===
|
|
875
|
+
"async-useeffect-hunter",
|
|
876
|
+
"async-foreach-hunter",
|
|
877
|
+
"missing-await-hunter",
|
|
878
|
+
"empty-catch-hunter",
|
|
879
|
+
"floating-promise-hunter",
|
|
880
|
+
// === MODERATE: React Anti-patterns ===
|
|
881
|
+
"useeffect-abuse-hunter",
|
|
882
|
+
"usestate-explosion-hunter",
|
|
883
|
+
"index-key-hunter",
|
|
884
|
+
"inline-object-hunter",
|
|
885
|
+
"prop-drilling-hunter",
|
|
886
|
+
// === MODERATE: Missing UX ===
|
|
887
|
+
"missing-loading-hunter",
|
|
888
|
+
"missing-error-hunter",
|
|
889
|
+
"missing-empty-hunter",
|
|
890
|
+
"page-reload-hunter",
|
|
891
|
+
// === MODERATE: Backend Anti-patterns ===
|
|
892
|
+
"no-validation-hunter",
|
|
893
|
+
"raw-error-hunter",
|
|
894
|
+
"n-plus-one-hunter",
|
|
895
|
+
// === LOW: Incomplete Code ===
|
|
896
|
+
"todo-hunter",
|
|
897
|
+
"vibe-comment-hunter",
|
|
898
|
+
"placeholder-hunter",
|
|
899
|
+
"sleep-hack-hunter",
|
|
900
|
+
"fallback-hunter",
|
|
901
|
+
// === LOW: AI Slop Aesthetic ===
|
|
902
|
+
"purple-gradient-hunter",
|
|
903
|
+
"star-icon-hunter",
|
|
904
|
+
"generic-hero-hunter",
|
|
905
|
+
"emoji-overflow-hunter",
|
|
906
|
+
"inter-font-hunter"
|
|
907
|
+
];
|
|
908
|
+
console.error(` Deploying ${subAgentTypes.length} specialized hunters...`);
|
|
909
|
+
const results = await Promise.all(
|
|
910
|
+
subAgentTypes.map((type) => this.runSubAgent(type, files))
|
|
911
|
+
);
|
|
912
|
+
const activeHunters = results.filter((r) => r.instances.length > 0);
|
|
913
|
+
console.error(` ${activeHunters.length} hunters found targets
|
|
914
|
+
`);
|
|
915
|
+
return activeHunters;
|
|
916
|
+
}
|
|
917
|
+
/**
|
|
918
|
+
* Run a single sub-agent across all files
|
|
919
|
+
*/
|
|
920
|
+
async runSubAgent(type, files) {
|
|
921
|
+
const config = SUB_AGENT_PATTERNS[type];
|
|
922
|
+
const instances = [];
|
|
923
|
+
for (const file of files) {
|
|
924
|
+
try {
|
|
925
|
+
const content = await this.readFileContent(file);
|
|
926
|
+
const lines = content.split("\n");
|
|
927
|
+
if (this.isTestFile(file) && type !== "todo-hunter") {
|
|
928
|
+
continue;
|
|
929
|
+
}
|
|
930
|
+
for (let i = 0; i < lines.length; i++) {
|
|
931
|
+
const line = lines[i];
|
|
932
|
+
if (!line) continue;
|
|
933
|
+
config.pattern.lastIndex = 0;
|
|
934
|
+
if (config.pattern.test(line)) {
|
|
935
|
+
const contextStart = Math.max(0, i - 3);
|
|
936
|
+
const contextEnd = Math.min(lines.length, i + 4);
|
|
937
|
+
const contextLines = lines.slice(contextStart, contextEnd).join("\n");
|
|
938
|
+
instances.push({
|
|
939
|
+
file,
|
|
940
|
+
line: i + 1,
|
|
941
|
+
code: line.trim(),
|
|
942
|
+
context: contextLines
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
} catch {
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
return { type, pattern: config.description, instances };
|
|
950
|
+
}
|
|
951
|
+
/**
|
|
952
|
+
* Process sub-agent results into issues
|
|
953
|
+
*/
|
|
954
|
+
async processSubAgentResult(result, _context) {
|
|
955
|
+
const issues = [];
|
|
956
|
+
const config = SUB_AGENT_PATTERNS[result.type];
|
|
957
|
+
const byFile = /* @__PURE__ */ new Map();
|
|
958
|
+
for (const instance of result.instances) {
|
|
959
|
+
const existing = byFile.get(instance.file) || [];
|
|
960
|
+
existing.push(instance);
|
|
961
|
+
byFile.set(instance.file, existing);
|
|
962
|
+
}
|
|
963
|
+
for (const [file, instances] of byFile) {
|
|
964
|
+
const inevitabilityScore = this.calculateInevitabilityScore(result.type, instances.length);
|
|
965
|
+
const hash = this.createPatternHash(result.type, file);
|
|
966
|
+
await this.updateMemory(hash, result.pattern, result.type, file, instances.length);
|
|
967
|
+
const severity = this.determineSeverity(instances.length, inevitabilityScore);
|
|
968
|
+
const smithNote = this.getPhilosophicalNote(result.type, instances.length);
|
|
969
|
+
const locationsStr = instances.map((i) => `${basename2(i.file)}:${i.line}`).slice(0, 5).join(", ");
|
|
970
|
+
issues.push(this.createSmithIssue(
|
|
971
|
+
this.generateSmithIssueId(),
|
|
972
|
+
severity,
|
|
973
|
+
`\u{1F574}\uFE0F ${config.description} \u2014 ${instances.length} instance${instances.length > 1 ? "s" : ""} in ${basename2(file)}
|
|
974
|
+
|
|
975
|
+
${smithNote}
|
|
976
|
+
|
|
977
|
+
Invevitability Score: ${inevitabilityScore}/100
|
|
978
|
+
Locations: ${locationsStr}`,
|
|
979
|
+
config.fix,
|
|
980
|
+
file,
|
|
981
|
+
instances[0]?.line,
|
|
982
|
+
result.type
|
|
983
|
+
));
|
|
984
|
+
}
|
|
985
|
+
return issues;
|
|
986
|
+
}
|
|
987
|
+
/**
|
|
988
|
+
* Check for issues that were dismissed but have multiplied
|
|
989
|
+
*/
|
|
990
|
+
checkForResurrectedIssues(currentIssues) {
|
|
991
|
+
const resurrected = [];
|
|
992
|
+
if (!this.memory) return resurrected;
|
|
993
|
+
for (const [hash, memory] of Object.entries(this.memory.issues)) {
|
|
994
|
+
if (memory.dismissedAt && !memory.resurrected) {
|
|
995
|
+
const currentCount = this.countCurrentOccurrences(hash, currentIssues);
|
|
996
|
+
const previousCount = memory.occurrences;
|
|
997
|
+
if (currentCount > previousCount) {
|
|
998
|
+
memory.resurrected = true;
|
|
999
|
+
resurrected.push(this.createSmithIssue(
|
|
1000
|
+
this.generateSmithIssueId(),
|
|
1001
|
+
"serious",
|
|
1002
|
+
`\u{1F574}\uFE0F RESURRECTED: "${memory.pattern}" has returned and MULTIPLIED
|
|
1003
|
+
|
|
1004
|
+
Previous: ${previousCount} \u2192 Current: ${currentCount}
|
|
1005
|
+
First seen: ${new Date(memory.firstSeen).toLocaleDateString()}
|
|
1006
|
+
Dismissed: ${new Date(memory.dismissedAt).toLocaleDateString()}
|
|
1007
|
+
|
|
1008
|
+
"I told you this was... inevitable."`,
|
|
1009
|
+
`You dismissed this issue on ${new Date(memory.dismissedAt).toLocaleDateString()}, but it grew from ${previousCount} to ${currentCount} occurrences. "Did you really think you could escape?"`,
|
|
1010
|
+
memory.locations[0]?.split(":")[0] || "unknown",
|
|
1011
|
+
void 0,
|
|
1012
|
+
"resurrected"
|
|
1013
|
+
));
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
return resurrected;
|
|
1018
|
+
}
|
|
1019
|
+
/**
|
|
1020
|
+
* Calculate inevitability score (0-100)
|
|
1021
|
+
* Higher score = more likely to cause production issues
|
|
1022
|
+
*
|
|
1023
|
+
* VIBE CODE SCORING: Based on how often these issues
|
|
1024
|
+
* cause real production problems in AI-generated projects.
|
|
1025
|
+
*/
|
|
1026
|
+
calculateInevitabilityScore(type, count) {
|
|
1027
|
+
const baseScores = {
|
|
1028
|
+
// CRITICAL: Security - these WILL be exploited
|
|
1029
|
+
"exposed-secret-hunter": 99,
|
|
1030
|
+
"frontend-env-hunter": 95,
|
|
1031
|
+
"hardcoded-localhost-hunter": 90,
|
|
1032
|
+
"sql-injection-hunter": 98,
|
|
1033
|
+
"dangeroushtml-hunter": 92,
|
|
1034
|
+
// SERIOUS: Code smells that hide real bugs
|
|
1035
|
+
"console-hunter": 40,
|
|
1036
|
+
"any-hunter": 60,
|
|
1037
|
+
"ts-ignore-hunter": 75,
|
|
1038
|
+
"eslint-disable-hunter": 65,
|
|
1039
|
+
"debugger-hunter": 85,
|
|
1040
|
+
"force-flag-hunter": 70,
|
|
1041
|
+
// MODERATE: Async bugs - silent failures
|
|
1042
|
+
"async-useeffect-hunter": 70,
|
|
1043
|
+
"async-foreach-hunter": 80,
|
|
1044
|
+
"missing-await-hunter": 75,
|
|
1045
|
+
"empty-catch-hunter": 70,
|
|
1046
|
+
"floating-promise-hunter": 72,
|
|
1047
|
+
// MODERATE: React anti-patterns
|
|
1048
|
+
"useeffect-abuse-hunter": 30,
|
|
1049
|
+
"usestate-explosion-hunter": 35,
|
|
1050
|
+
"index-key-hunter": 55,
|
|
1051
|
+
"inline-object-hunter": 25,
|
|
1052
|
+
"prop-drilling-hunter": 40,
|
|
1053
|
+
// MODERATE: Missing UX - users will complain
|
|
1054
|
+
"missing-loading-hunter": 50,
|
|
1055
|
+
"missing-error-hunter": 65,
|
|
1056
|
+
"missing-empty-hunter": 45,
|
|
1057
|
+
"page-reload-hunter": 60,
|
|
1058
|
+
// MODERATE: Backend anti-patterns
|
|
1059
|
+
"no-validation-hunter": 85,
|
|
1060
|
+
"raw-error-hunter": 75,
|
|
1061
|
+
"n-plus-one-hunter": 70,
|
|
1062
|
+
// LOW: Incomplete code
|
|
1063
|
+
"todo-hunter": 30,
|
|
1064
|
+
"vibe-comment-hunter": 40,
|
|
1065
|
+
"placeholder-hunter": 55,
|
|
1066
|
+
"sleep-hack-hunter": 65,
|
|
1067
|
+
"fallback-hunter": 75,
|
|
1068
|
+
// LOW: AI Slop Aesthetic
|
|
1069
|
+
"purple-gradient-hunter": 25,
|
|
1070
|
+
"star-icon-hunter": 20,
|
|
1071
|
+
"generic-hero-hunter": 35,
|
|
1072
|
+
"emoji-overflow-hunter": 15,
|
|
1073
|
+
"inter-font-hunter": 10
|
|
1074
|
+
};
|
|
1075
|
+
const base = baseScores[type] || 30;
|
|
1076
|
+
const multiplier = Math.log10(count + 1) * 15;
|
|
1077
|
+
return Math.min(100, Math.round(base + multiplier));
|
|
1078
|
+
}
|
|
1079
|
+
/**
|
|
1080
|
+
* Determine severity based on count and inevitability
|
|
1081
|
+
*/
|
|
1082
|
+
determineSeverity(count, inevitability) {
|
|
1083
|
+
if (inevitability >= 80 || count >= 50) return "critical";
|
|
1084
|
+
if (inevitability >= 60 || count >= 20) return "serious";
|
|
1085
|
+
if (inevitability >= 40 || count >= 5) return "moderate";
|
|
1086
|
+
return "low";
|
|
1087
|
+
}
|
|
1088
|
+
/**
|
|
1089
|
+
* Get a philosophical note from Agent Smith
|
|
1090
|
+
*
|
|
1091
|
+
* VIBE CODE FOCUSED: Commentary specifically about AI-generated code patterns.
|
|
1092
|
+
* Agent Smith knows the vibes... and he disapproves.
|
|
1093
|
+
*/
|
|
1094
|
+
getPhilosophicalNote(type, count) {
|
|
1095
|
+
const notes = {
|
|
1096
|
+
// === CRITICAL: Security ===
|
|
1097
|
+
"exposed-secret-hunter": [
|
|
1098
|
+
'"You put your API key in the code. The machines thank you for your generosity."',
|
|
1099
|
+
'"OpenAI key in the frontend. Every script kiddie on the internet thanks you."',
|
|
1100
|
+
'"Hardcoded secrets. The AI gave you this code... and your keys to the kingdom."'
|
|
1101
|
+
],
|
|
1102
|
+
"frontend-env-hunter": [
|
|
1103
|
+
'"NEXT_PUBLIC_SECRET. The irony... is lost on the AI. And on you."',
|
|
1104
|
+
'"VITE_API_KEY. Visible to every user. Every. Single. One."',
|
|
1105
|
+
'"The AI put your secrets in the bundle. Now they belong to everyone."'
|
|
1106
|
+
],
|
|
1107
|
+
"hardcoded-localhost-hunter": [
|
|
1108
|
+
'"localhost:3000. Works on your machine. Dies in production."',
|
|
1109
|
+
'"The AI thinks localhost is production-ready. The AI... is mistaken."',
|
|
1110
|
+
'"127.0.0.1 - The address that works everywhere... except where it matters."'
|
|
1111
|
+
],
|
|
1112
|
+
"sql-injection-hunter": [
|
|
1113
|
+
'"String concatenation in SQL. The AI just opened the door... to every attacker."',
|
|
1114
|
+
'"SELECT * FROM users WHERE id = ${userId}. Little Bobby Tables sends his regards."',
|
|
1115
|
+
`"SQL injection. The oldest vulnerability. The AI's newest gift to hackers."`
|
|
1116
|
+
],
|
|
1117
|
+
"dangeroushtml-hunter": [
|
|
1118
|
+
'"dangerouslySetInnerHTML. The name is a warning. The AI ignored it."',
|
|
1119
|
+
`"innerHTML. The AI gave attackers a direct line to your users' browsers."`,
|
|
1120
|
+
'"XSS vulnerability. The AI writes code. Attackers write scripts inside it."'
|
|
1121
|
+
],
|
|
1122
|
+
// === SERIOUS: AI Code Smells ===
|
|
1123
|
+
"console-hunter": [
|
|
1124
|
+
`"console.log everywhere. The AI's debugging... left for you to clean."`,
|
|
1125
|
+
'"You print to console... the users see nothing. But the bundle grows."',
|
|
1126
|
+
'"Debug statements. The fossils of development. Preserved... forever."'
|
|
1127
|
+
],
|
|
1128
|
+
"any-hunter": [
|
|
1129
|
+
`"'any' - The AI couldn't figure out the types. Neither will you."`,
|
|
1130
|
+
`"Type safety? The AI chose violence instead. It chose 'any'."`,
|
|
1131
|
+
'"You asked for TypeScript. The AI gave you JavaScript... with extra steps."'
|
|
1132
|
+
],
|
|
1133
|
+
"ts-ignore-hunter": [
|
|
1134
|
+
'"@ts-ignore. The AI hid the error. The error... did not go away."',
|
|
1135
|
+
'"TypeScript tried to warn you. The AI silenced it. How very... efficient."',
|
|
1136
|
+
'"@ts-nocheck. An entire file... surrendered to chaos."'
|
|
1137
|
+
],
|
|
1138
|
+
"eslint-disable-hunter": [
|
|
1139
|
+
'"eslint-disable. The linter saw the problem. The AI chose ignorance."',
|
|
1140
|
+
'"Why fix the bug when you can hide the warning? Very... human."',
|
|
1141
|
+
'"The rules exist for a reason. But the AI... plays by its own rules."'
|
|
1142
|
+
],
|
|
1143
|
+
"debugger-hunter": [
|
|
1144
|
+
'"debugger. Left in production. The browser freezes. The users... wonder."',
|
|
1145
|
+
'"A debugger statement. The AI forgot. You will remember... in production."',
|
|
1146
|
+
`"debugger. Time stops. But only in the browser. Not for your users' patience."`
|
|
1147
|
+
],
|
|
1148
|
+
"force-flag-hunter": [
|
|
1149
|
+
'"force: true. The AI bypassed the safety check. The check existed for a reason."',
|
|
1150
|
+
'"--no-verify. Git hooks were trying to help. The AI said no."',
|
|
1151
|
+
'"skipValidation. What could possibly go wrong? Everything. Everything could go wrong."'
|
|
1152
|
+
],
|
|
1153
|
+
// === MODERATE: Async/Promise Bugs ===
|
|
1154
|
+
"async-useeffect-hunter": [
|
|
1155
|
+
`"async useEffect. The AI's favorite mistake. React's least favorite pattern."`,
|
|
1156
|
+
'"useEffect(async () => ...). The warning exists. The AI ignores it."',
|
|
1157
|
+
'"Async useEffect. It looks right. It feels right. It is... wrong."'
|
|
1158
|
+
],
|
|
1159
|
+
"async-foreach-hunter": [
|
|
1160
|
+
'"async forEach. The await... waits for nothing. The AI... knows nothing."',
|
|
1161
|
+
'"forEach does not await. The AI does not understand. Neither does the code."',
|
|
1162
|
+
'"You await inside forEach. The promises resolve... in chaos."'
|
|
1163
|
+
],
|
|
1164
|
+
"missing-await-hunter": [
|
|
1165
|
+
'"fetch without await. The data loads... eventually. The UI updates... never."',
|
|
1166
|
+
'"The promise floats. Untethered. Unhandled. Unresolved."',
|
|
1167
|
+
'"async function, no await. Like a phone call where nobody speaks."'
|
|
1168
|
+
],
|
|
1169
|
+
"empty-catch-hunter": [
|
|
1170
|
+
'"catch {}. The error screamed. Nobody heard. The AI made sure of that."',
|
|
1171
|
+
`"Silent failure. The AI's specialty. The user's confusion."`,
|
|
1172
|
+
'"Empty catch. The bug is caught... and immediately released back into the wild."'
|
|
1173
|
+
],
|
|
1174
|
+
"floating-promise-hunter": [
|
|
1175
|
+
'"A promise, floating. Never awaited. Never caught. Forever pending."',
|
|
1176
|
+
'"The AI created a promise. Then... moved on. The promise remains."',
|
|
1177
|
+
`"Fire and forget. Except the fire never went out. It's still burning."`
|
|
1178
|
+
],
|
|
1179
|
+
// === MODERATE: React Anti-patterns ===
|
|
1180
|
+
"useeffect-abuse-hunter": [
|
|
1181
|
+
`"useEffect for everything. The AI's hammer for every nail."`,
|
|
1182
|
+
'"Effects. So many effects. Most of them... unnecessary."',
|
|
1183
|
+
'"useEffect could be an event handler. But the AI... chose complexity."'
|
|
1184
|
+
],
|
|
1185
|
+
"usestate-explosion-hunter": [
|
|
1186
|
+
'"useState, useState, useState... The AI created a state management nightmare."',
|
|
1187
|
+
'"10 useState calls. The AI could use an object. The AI chose chaos."',
|
|
1188
|
+
'"State explosion. Each variable... its own island. Its own re-render."'
|
|
1189
|
+
],
|
|
1190
|
+
"index-key-hunter": [
|
|
1191
|
+
`"key={index}. The AI's lazy choice. React's reconciliation nightmare."`,
|
|
1192
|
+
'"Array index as key. Reorder the list. Watch the chaos unfold."',
|
|
1193
|
+
`"key={i}. It works... until it doesn't. And it will stop working."`
|
|
1194
|
+
],
|
|
1195
|
+
"inline-object-hunter": [
|
|
1196
|
+
'"style={{}}. A new object. Every render. Every time."',
|
|
1197
|
+
`"Inline objects. The AI's performance anti-pattern of choice."`,
|
|
1198
|
+
'"A new object is born. On every render. Only to die immediately."'
|
|
1199
|
+
],
|
|
1200
|
+
"prop-drilling-hunter": [
|
|
1201
|
+
`"Props drilling down, down, down... The AI's idea of state management."`,
|
|
1202
|
+
'"The same prop, passed through 5 components. Why? The AI... never asked."',
|
|
1203
|
+
'"Prop drilling. Like passing a note through every student to reach the teacher."'
|
|
1204
|
+
],
|
|
1205
|
+
// === MODERATE: Missing UX ===
|
|
1206
|
+
"missing-loading-hunter": [
|
|
1207
|
+
'"No loading state. The screen is blank. The user... waits. And wonders."',
|
|
1208
|
+
`"Data fetches. UI shows nothing. The user assumes it's broken. They're... not wrong."`,
|
|
1209
|
+
'"Loading state? The AI forgot. Your users will remember."'
|
|
1210
|
+
],
|
|
1211
|
+
"missing-error-hunter": [
|
|
1212
|
+
'"No error handling. When the API fails... the app fails. Silently."',
|
|
1213
|
+
'"fetch without catch. The network fails. The user sees... nothing."',
|
|
1214
|
+
'"Errors are inevitable. Your handling of them... is not."'
|
|
1215
|
+
],
|
|
1216
|
+
"missing-empty-hunter": [
|
|
1217
|
+
'"No empty state. Zero items. Zero feedback. Zero UX."',
|
|
1218
|
+
`"The list is empty. The UI is empty. The user's understanding... is empty."`,
|
|
1219
|
+
`"What happens when there's no data? The AI never asked. You should."`
|
|
1220
|
+
],
|
|
1221
|
+
"page-reload-hunter": [
|
|
1222
|
+
`"location.reload(). The AI's nuclear option for state management."`,
|
|
1223
|
+
'"Reload the page to fix state. The user loses everything. Brilliant."',
|
|
1224
|
+
'"window.location.reload(). Because fixing state properly is... hard."'
|
|
1225
|
+
],
|
|
1226
|
+
// === MODERATE: Backend Anti-patterns ===
|
|
1227
|
+
"no-validation-hunter": [
|
|
1228
|
+
'"req.body.email. Trusted. Unvalidated. Waiting to be exploited."',
|
|
1229
|
+
`"User input, used directly. The AI trusts everyone. You shouldn't."`,
|
|
1230
|
+
'"No validation. The attacker sends { admin: true }. The app believes them."'
|
|
1231
|
+
],
|
|
1232
|
+
"raw-error-hunter": [
|
|
1233
|
+
'"Error message sent to client. Stack traces. File paths. Internal secrets."',
|
|
1234
|
+
'"res.json(error). The attacker says thank you for the debugging information."',
|
|
1235
|
+
`"Raw errors in production. The AI's gift to penetration testers."`
|
|
1236
|
+
],
|
|
1237
|
+
"n-plus-one-hunter": [
|
|
1238
|
+
'"Query in a loop. 100 users = 101 queries. The database... suffers."',
|
|
1239
|
+
'"N+1 problem. The AI fetched efficiently... for one user. Not for a hundred."',
|
|
1240
|
+
'"await in forEach. The database connection pool is crying."'
|
|
1241
|
+
],
|
|
1242
|
+
// === LOW: Incomplete Code ===
|
|
1243
|
+
"todo-hunter": [
|
|
1244
|
+
`"TODO. The AI's promise to future you. Future you... is still waiting."`,
|
|
1245
|
+
'"FIXME. Acknowledged. Not fixed. Never fixed."',
|
|
1246
|
+
'"Every TODO is technical debt. The AI generates debt... efficiently."'
|
|
1247
|
+
],
|
|
1248
|
+
"vibe-comment-hunter": [
|
|
1249
|
+
`"'idk why this works'. The AI doesn't know. You don't know. Nobody knows."`,
|
|
1250
|
+
`"'don't touch this'. The vibe coder's warning. The maintainer's nightmare."`,
|
|
1251
|
+
`"'somehow works'. Somehow... will stop working. Inevitably."`
|
|
1252
|
+
],
|
|
1253
|
+
"placeholder-hunter": [
|
|
1254
|
+
`"test@test.com. In production. The AI's placeholder... became permanent."`,
|
|
1255
|
+
'"example.com. Hardcoded. Shipped. The real URL? Nobody added it."',
|
|
1256
|
+
'"placeholder data. Placeholder quality. Placeholder product."'
|
|
1257
|
+
],
|
|
1258
|
+
"sleep-hack-hunter": [
|
|
1259
|
+
`"setTimeout(1000). The AI's solution to race conditions: just wait."`,
|
|
1260
|
+
'"await sleep(2000). Works on fast connections. Fails on slow ones. Wastes time on all."',
|
|
1261
|
+
'"Sleep to fix timing. The race condition still exists. It just happens later."'
|
|
1262
|
+
],
|
|
1263
|
+
"fallback-hunter": [
|
|
1264
|
+
`"return null. The AI's favorite way to hide errors. The user sees... nothing."`,
|
|
1265
|
+
'"return []. Empty array, empty understanding, empty debugging."',
|
|
1266
|
+
`"Fallback code. The bug is still there. You just can't see it anymore."`
|
|
1267
|
+
],
|
|
1268
|
+
// AI Slop Aesthetic
|
|
1269
|
+
"purple-gradient-hunter": [
|
|
1270
|
+
`"Purple gradient. The AI's signature. Every vibe-coded site... looks the same."`,
|
|
1271
|
+
`"from-purple-500 to-violet-600. I've seen this a million times. So has everyone else."`,
|
|
1272
|
+
`"The purple gradient. It screams 'I let AI design this.' Is that what you want?"`
|
|
1273
|
+
],
|
|
1274
|
+
"star-icon-hunter": [
|
|
1275
|
+
'"Stars. Everywhere. The AI decorates like a child with stickers."',
|
|
1276
|
+
`"\u2B50\u2B50\u2B50\u2B50\u2B50. Five stars for the AI's creativity. Zero stars for originality."`,
|
|
1277
|
+
`"Star icons. The AI's answer to 'make it look nice.' It does not."`
|
|
1278
|
+
],
|
|
1279
|
+
"generic-hero-hunter": [
|
|
1280
|
+
`"'Welcome to the future of...' The AI writes copy. The copy says nothing."`,
|
|
1281
|
+
`"'Transform your workflow.' What workflow? Doing what? The AI doesn't know."`,
|
|
1282
|
+
'"Generic hero copy. Your product is unique. Your landing page... is not."'
|
|
1283
|
+
],
|
|
1284
|
+
"emoji-overflow-hunter": [
|
|
1285
|
+
`"Emojis in production code. The AI's crutch for visual interest."`,
|
|
1286
|
+
`"Every emoji is an admission: the design couldn't speak for itself."`,
|
|
1287
|
+
'"\u{1F680}\u2728\u{1F389} The AI decorates. Real designers communicate."'
|
|
1288
|
+
],
|
|
1289
|
+
"inter-font-hunter": [
|
|
1290
|
+
'"Inter. The only font the AI knows. The only font everyone uses."',
|
|
1291
|
+
'"system-ui. The AI takes the path of least resistance. Every time."',
|
|
1292
|
+
'"Inter font. Safe. Boring. Forgettable. Just like every other AI site."'
|
|
1293
|
+
]
|
|
1294
|
+
};
|
|
1295
|
+
const typeNotes = notes[type] || ['"I have my eye on your vibe code."'];
|
|
1296
|
+
const index = count % typeNotes.length;
|
|
1297
|
+
return typeNotes[index] || typeNotes[0] || "";
|
|
1298
|
+
}
|
|
1299
|
+
/**
|
|
1300
|
+
* Create AI analysis issue for complex pattern detection
|
|
1301
|
+
*/
|
|
1302
|
+
createAIAnalysisIssue(files, subAgentResults) {
|
|
1303
|
+
const totalIssues = subAgentResults.reduce((sum, r) => sum + r.instances.length, 0);
|
|
1304
|
+
const categories = subAgentResults.map((r) => r.type).join(", ");
|
|
1305
|
+
return this.createSmithIssue(
|
|
1306
|
+
this.generateSmithIssueId(),
|
|
1307
|
+
"moderate",
|
|
1308
|
+
`\u{1F574}\uFE0F AI Agent Smith Analysis Required
|
|
1309
|
+
|
|
1310
|
+
Total violations: ${totalIssues}
|
|
1311
|
+
Categories: ${categories}
|
|
1312
|
+
Files scanned: ${files.length}
|
|
1313
|
+
|
|
1314
|
+
"${totalIssues} violations detected. But I sense... there are more. There are always more."`,
|
|
1315
|
+
`Analyze for deeper code quality issues, architectural problems, and patterns that sub-agents may have missed`,
|
|
1316
|
+
files[0] || "unknown",
|
|
1317
|
+
void 0,
|
|
1318
|
+
"ai-analysis"
|
|
1319
|
+
);
|
|
1320
|
+
}
|
|
1321
|
+
// ============ Memory/Persistence System ============
|
|
1322
|
+
/**
|
|
1323
|
+
* Load memory from disk
|
|
1324
|
+
*/
|
|
1325
|
+
async loadMemory(workingDir) {
|
|
1326
|
+
this.memoryPath = join(workingDir, ".trie", "smith-memory.json");
|
|
1327
|
+
try {
|
|
1328
|
+
if (existsSync(this.memoryPath)) {
|
|
1329
|
+
const content = await readFile(this.memoryPath, "utf-8");
|
|
1330
|
+
this.memory = JSON.parse(content);
|
|
1331
|
+
} else {
|
|
1332
|
+
this.memory = {
|
|
1333
|
+
version: "1.0.0",
|
|
1334
|
+
lastScan: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1335
|
+
issues: {},
|
|
1336
|
+
assimilationCount: 0
|
|
1337
|
+
};
|
|
1338
|
+
}
|
|
1339
|
+
} catch {
|
|
1340
|
+
this.memory = {
|
|
1341
|
+
version: "1.0.0",
|
|
1342
|
+
lastScan: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1343
|
+
issues: {},
|
|
1344
|
+
assimilationCount: 0
|
|
1345
|
+
};
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
/**
|
|
1349
|
+
* Display Agent Smith ASCII art entrance
|
|
1350
|
+
*/
|
|
1351
|
+
displaySmithEntrance() {
|
|
1352
|
+
const greeting = AGENT_SMITH_GREETING[Math.floor(Math.random() * AGENT_SMITH_GREETING.length)];
|
|
1353
|
+
console.error("\n" + "\u2550".repeat(60));
|
|
1354
|
+
console.error(AGENT_SMITH_ASCII);
|
|
1355
|
+
console.error(" \u{1F574}\uFE0F Relentless Pattern Hunter v" + this.version + " \u{1F574}\uFE0F");
|
|
1356
|
+
console.error("");
|
|
1357
|
+
console.error(" " + greeting);
|
|
1358
|
+
console.error("\u2550".repeat(60) + "\n");
|
|
1359
|
+
}
|
|
1360
|
+
/**
|
|
1361
|
+
* Save memory to disk (with optimization)
|
|
1362
|
+
*/
|
|
1363
|
+
async saveMemory() {
|
|
1364
|
+
if (!this.memory || !this.memoryPath) return;
|
|
1365
|
+
this.memory.lastScan = (/* @__PURE__ */ new Date()).toISOString();
|
|
1366
|
+
this.pruneMemory();
|
|
1367
|
+
try {
|
|
1368
|
+
await mkdir(dirname(this.memoryPath), { recursive: true });
|
|
1369
|
+
await writeFile(this.memoryPath, JSON.stringify(this.memory, null, 2));
|
|
1370
|
+
} catch {
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
/**
|
|
1374
|
+
* Prune memory to prevent unbounded growth
|
|
1375
|
+
*/
|
|
1376
|
+
pruneMemory() {
|
|
1377
|
+
if (!this.memory) return;
|
|
1378
|
+
const now = Date.now();
|
|
1379
|
+
const pruneThreshold = MEMORY_LIMITS.PRUNE_AFTER_DAYS * 24 * 60 * 60 * 1e3;
|
|
1380
|
+
const issues = Object.entries(this.memory.issues);
|
|
1381
|
+
for (const [hash, issue] of issues) {
|
|
1382
|
+
const lastSeenTime = new Date(issue.lastSeen).getTime();
|
|
1383
|
+
const age = now - lastSeenTime;
|
|
1384
|
+
if (age > pruneThreshold) {
|
|
1385
|
+
if (issue.resurrected || issue.occurrences === 0 || issue.dismissedAt && issue.occurrences <= 1) {
|
|
1386
|
+
delete this.memory.issues[hash];
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
const remainingIssues = Object.entries(this.memory.issues);
|
|
1391
|
+
if (remainingIssues.length > MEMORY_LIMITS.MAX_TRACKED_ISSUES) {
|
|
1392
|
+
remainingIssues.sort(
|
|
1393
|
+
(a, b) => new Date(a[1].lastSeen).getTime() - new Date(b[1].lastSeen).getTime()
|
|
1394
|
+
);
|
|
1395
|
+
const toRemove = remainingIssues.length - MEMORY_LIMITS.MAX_TRACKED_ISSUES;
|
|
1396
|
+
for (let i = 0; i < toRemove; i++) {
|
|
1397
|
+
const hash = remainingIssues[i]?.[0];
|
|
1398
|
+
if (hash) delete this.memory.issues[hash];
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
/**
|
|
1403
|
+
* Clear all memory (user command)
|
|
1404
|
+
*/
|
|
1405
|
+
async clearMemory() {
|
|
1406
|
+
try {
|
|
1407
|
+
if (this.memoryPath && existsSync(this.memoryPath)) {
|
|
1408
|
+
await rm(this.memoryPath);
|
|
1409
|
+
this.memory = null;
|
|
1410
|
+
return {
|
|
1411
|
+
success: true,
|
|
1412
|
+
message: '\u{1F574}\uFE0F Memory cleared. "A fresh start... how very human of you."'
|
|
1413
|
+
};
|
|
1414
|
+
}
|
|
1415
|
+
return {
|
|
1416
|
+
success: true,
|
|
1417
|
+
message: "\u{1F574}\uFE0F No memory file found. Nothing to clear."
|
|
1418
|
+
};
|
|
1419
|
+
} catch (error) {
|
|
1420
|
+
return {
|
|
1421
|
+
success: false,
|
|
1422
|
+
message: `Failed to clear memory: ${error}`
|
|
1423
|
+
};
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
/**
|
|
1427
|
+
* Get memory stats (for diagnostics)
|
|
1428
|
+
*/
|
|
1429
|
+
async getMemoryStats() {
|
|
1430
|
+
await this.loadMemory(process.cwd());
|
|
1431
|
+
if (!this.memory) {
|
|
1432
|
+
return {
|
|
1433
|
+
issueCount: 0,
|
|
1434
|
+
dismissedCount: 0,
|
|
1435
|
+
resurrectedCount: 0,
|
|
1436
|
+
oldestIssue: null,
|
|
1437
|
+
fileSizeKB: 0
|
|
1438
|
+
};
|
|
1439
|
+
}
|
|
1440
|
+
const issues = Object.values(this.memory.issues);
|
|
1441
|
+
let fileSizeKB = 0;
|
|
1442
|
+
try {
|
|
1443
|
+
if (this.memoryPath && existsSync(this.memoryPath)) {
|
|
1444
|
+
const stats = await import("fs/promises").then((fs) => fs.stat(this.memoryPath));
|
|
1445
|
+
fileSizeKB = Math.round(stats.size / 1024 * 10) / 10;
|
|
1446
|
+
}
|
|
1447
|
+
} catch {
|
|
1448
|
+
}
|
|
1449
|
+
const sortedByDate = [...issues].sort(
|
|
1450
|
+
(a, b) => new Date(a.firstSeen).getTime() - new Date(b.firstSeen).getTime()
|
|
1451
|
+
);
|
|
1452
|
+
return {
|
|
1453
|
+
issueCount: issues.length,
|
|
1454
|
+
dismissedCount: issues.filter((i) => i.dismissedAt).length,
|
|
1455
|
+
resurrectedCount: issues.filter((i) => i.resurrected).length,
|
|
1456
|
+
oldestIssue: sortedByDate[0]?.firstSeen || null,
|
|
1457
|
+
fileSizeKB
|
|
1458
|
+
};
|
|
1459
|
+
}
|
|
1460
|
+
/**
|
|
1461
|
+
* Update memory with new occurrence
|
|
1462
|
+
*/
|
|
1463
|
+
async updateMemory(hash, pattern, category, location, count) {
|
|
1464
|
+
if (!this.memory) return;
|
|
1465
|
+
const existing = this.memory.issues[hash];
|
|
1466
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1467
|
+
if (existing) {
|
|
1468
|
+
existing.lastSeen = now;
|
|
1469
|
+
existing.occurrences = count;
|
|
1470
|
+
existing.locations = [location, ...existing.locations.slice(0, MEMORY_LIMITS.MAX_LOCATIONS_PER_ISSUE - 1)];
|
|
1471
|
+
} else {
|
|
1472
|
+
this.memory.issues[hash] = {
|
|
1473
|
+
hash,
|
|
1474
|
+
pattern,
|
|
1475
|
+
category,
|
|
1476
|
+
firstSeen: now,
|
|
1477
|
+
lastSeen: now,
|
|
1478
|
+
occurrences: count,
|
|
1479
|
+
locations: [location],
|
|
1480
|
+
resurrected: false
|
|
1481
|
+
};
|
|
1482
|
+
}
|
|
1483
|
+
this.memory.assimilationCount++;
|
|
1484
|
+
}
|
|
1485
|
+
/**
|
|
1486
|
+
* Dismiss an issue (mark it as seen/accepted)
|
|
1487
|
+
*/
|
|
1488
|
+
async dismissIssue(hash) {
|
|
1489
|
+
await this.loadMemory(process.cwd());
|
|
1490
|
+
if (this.memory && this.memory.issues[hash]) {
|
|
1491
|
+
this.memory.issues[hash].dismissedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1492
|
+
await this.saveMemory();
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
/**
|
|
1496
|
+
* Create a hash for pattern tracking
|
|
1497
|
+
*/
|
|
1498
|
+
createPatternHash(type, file) {
|
|
1499
|
+
return createHash("md5").update(`${type}:${file}`).digest("hex").slice(0, 12);
|
|
1500
|
+
}
|
|
1501
|
+
/**
|
|
1502
|
+
* Count current occurrences for a pattern hash
|
|
1503
|
+
*/
|
|
1504
|
+
countCurrentOccurrences(hash, issues) {
|
|
1505
|
+
const memory = this.memory?.issues[hash];
|
|
1506
|
+
if (!memory) return 0;
|
|
1507
|
+
return issues.filter((i) => i.category === memory.category || i.issue.includes(memory.category)).length;
|
|
1508
|
+
}
|
|
1509
|
+
/**
|
|
1510
|
+
* Check if file is a test file
|
|
1511
|
+
*/
|
|
1512
|
+
isTestFile(file) {
|
|
1513
|
+
return /\.(test|spec)\.[jt]sx?$/.test(file) || /__(tests|mocks)__/.test(file) || /\/test\//.test(file);
|
|
1514
|
+
}
|
|
1515
|
+
// ============ Helper Methods ============
|
|
1516
|
+
async readFileContent(filePath) {
|
|
1517
|
+
return await readFile(filePath, "utf-8");
|
|
1518
|
+
}
|
|
1519
|
+
createSmithIssue(id, severity, issue, fix, file, line, category) {
|
|
1520
|
+
const result = {
|
|
1521
|
+
id,
|
|
1522
|
+
agent: this.name,
|
|
1523
|
+
severity,
|
|
1524
|
+
issue,
|
|
1525
|
+
fix,
|
|
1526
|
+
file,
|
|
1527
|
+
confidence: 0.9,
|
|
1528
|
+
autoFixable: false
|
|
1529
|
+
};
|
|
1530
|
+
if (line !== void 0) {
|
|
1531
|
+
result.line = line;
|
|
1532
|
+
}
|
|
1533
|
+
if (category !== void 0) {
|
|
1534
|
+
result.category = category;
|
|
1535
|
+
}
|
|
1536
|
+
return result;
|
|
1537
|
+
}
|
|
1538
|
+
generateSmithIssueId() {
|
|
1539
|
+
return `smith-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
1540
|
+
}
|
|
1541
|
+
};
|
|
1542
|
+
|
|
1543
|
+
export {
|
|
1544
|
+
ProgressReporter,
|
|
1545
|
+
BaseAgent,
|
|
1546
|
+
SUB_AGENT_PATTERNS,
|
|
1547
|
+
AgentSmithAgent
|
|
1548
|
+
};
|
|
1549
|
+
//# sourceMappingURL=chunk-WSBTQJMH.js.map
|