tribunal-kit 5.7.0 → 5.8.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.
Files changed (56) hide show
  1. package/.agent/ARCHITECTURE.md +6 -7
  2. package/.agent/agents/frontend-reviewer.md +13 -0
  3. package/.agent/agents/frontend-specialist.md +14 -0
  4. package/.agent/agents/logic-reviewer.md +11 -0
  5. package/.agent/agents/orchestrator.md +15 -0
  6. package/.agent/agents/security-auditor.md +13 -0
  7. package/.agent/agents/ui-ux-auditor.md +7 -31
  8. package/.agent/history/memory/.memory.idx +766 -0
  9. package/.agent/history/memory/MEMORY.md +62 -0
  10. package/.agent/routing_index.json +694 -714
  11. package/.agent/rules/GEMINI.md +58 -8
  12. package/.agent/scripts/_colors.js +131 -89
  13. package/.agent/scripts/_utils.js +163 -128
  14. package/.agent/scripts/auto_preview.js +207 -197
  15. package/.agent/scripts/bundle_analyzer.js +227 -192
  16. package/.agent/scripts/case_law_manager.js +991 -689
  17. package/.agent/scripts/checklist.js +233 -190
  18. package/.agent/scripts/context_broker.js +930 -605
  19. package/.agent/scripts/dependency_analyzer.js +275 -184
  20. package/.agent/scripts/graph_builder.js +412 -341
  21. package/.agent/scripts/graph_visualizer.js +392 -390
  22. package/.agent/scripts/graph_zoom.js +198 -156
  23. package/.agent/scripts/inner_loop_validator.js +523 -445
  24. package/.agent/scripts/lint_runner.js +199 -157
  25. package/.agent/scripts/marathon_harness.js +819 -661
  26. package/.agent/scripts/minify_context.js +115 -100
  27. package/.agent/scripts/mutation_runner.js +321 -280
  28. package/.agent/scripts/prompt_compiler.js +62 -42
  29. package/.agent/scripts/schema_validator.js +373 -280
  30. package/.agent/scripts/security_scan.js +333 -190
  31. package/.agent/scripts/session_manager.js +306 -270
  32. package/.agent/scripts/skill_evolution.js +810 -637
  33. package/.agent/scripts/skill_integrator.js +327 -307
  34. package/.agent/scripts/strengthen_skills.js +203 -193
  35. package/.agent/scripts/swarm_dispatcher.js +558 -457
  36. package/.agent/scripts/test_runner.js +178 -152
  37. package/.agent/scripts/verify_all.js +200 -168
  38. package/.agent/skills/fabel-protocol/SKILL.md +235 -0
  39. package/.agent/skills/thinking-protocol/SKILL.md +27 -0
  40. package/.agent/workflows/generate.md +1 -1
  41. package/.agent/workflows/tribunal-speed.md +1 -1
  42. package/README.md +53 -53
  43. package/bin/mcp-server.js +460 -175
  44. package/bin/tribunal-kit.js +1245 -987
  45. package/bin/wrapper.js +104 -74
  46. package/dist/cli.js +31 -0
  47. package/dist/commands/case.js +23 -0
  48. package/dist/commands/compile.js +84 -0
  49. package/dist/commands/init.js +42 -0
  50. package/dist/commands/learn.js +57 -0
  51. package/dist/commands/memory.js +456 -0
  52. package/package.json +2 -2
  53. package/scripts/benchmark.js +162 -125
  54. package/scripts/changelog.js +196 -168
  55. package/scripts/sync-version.js +94 -81
  56. package/scripts/validate-payload.js +85 -78
@@ -22,70 +22,190 @@
22
22
  * node .agent/scripts/security_scan.js . --files src/auth.ts src/db.ts
23
23
  */
24
24
 
25
- 'use strict';
25
+ "use strict";
26
26
 
27
- const fs = require('fs');
28
- const path = require('path');
27
+ const fs = require("fs");
28
+ const path = require("path");
29
29
 
30
30
  const {
31
- RED, GREEN, YELLOW, BLUE, MAGENTA, BOLD, DIM, CYAN, RESET,
32
- banner, sectionHeader, timer, formatMs,
33
- } = require('./_colors');
34
-
35
- const { walkDir, SOURCE_EXTENSIONS } = require('./_utils');
31
+ RED,
32
+ GREEN,
33
+ YELLOW,
34
+ BLUE,
35
+ MAGENTA,
36
+ BOLD,
37
+ DIM,
38
+ CYAN,
39
+ RESET,
40
+ banner,
41
+ timer,
42
+ formatMs,
43
+ } = require("./_colors");
44
+
45
+ const { walkDir, SOURCE_EXTENSIONS } = require("./_utils");
36
46
 
37
47
  // ── Security-specific source extensions (broader than default) ──────────────
38
- const SCAN_EXTENSIONS = new Set([...SOURCE_EXTENSIONS, '.py', '.go', '.java', '.rb']);
48
+ const SCAN_EXTENSIONS = new Set([
49
+ ...SOURCE_EXTENSIONS,
50
+ ".py",
51
+ ".go",
52
+ ".java",
53
+ ".rb",
54
+ ]);
39
55
 
40
56
  const SEVERITY_COLORS = {
41
- critical: RED + BOLD,
42
- high: RED,
43
- medium: YELLOW,
44
- low: BLUE,
57
+ critical: RED + BOLD,
58
+ high: RED,
59
+ medium: YELLOW,
60
+ low: BLUE,
45
61
  };
46
62
 
47
63
  const SEVERITY_RANK = { critical: 0, high: 1, medium: 2, low: 3 };
48
64
 
49
65
  // Pattern definitions: [regex, severity, category, message]
50
66
  const PATTERNS = [
51
- // Secrets
52
- [/(?:password|passwd|pwd)\s*=\s*["'][^"']+["']/i, 'critical', 'Hardcoded Secret', 'Hardcoded password detected'],
53
- [/(?:api_key|apikey|api_secret)\s*=\s*["'][^"']+["']/i, 'critical', 'Hardcoded Secret', 'Hardcoded API key detected'],
54
- [/(?:secret|token|auth_token)\s*=\s*["'][A-Za-z0-9+/=]{16,}["']/i, 'critical', 'Hardcoded Secret', 'Hardcoded secret/token detected'],
55
- [/(?:PRIVATE_KEY|private_key)\s*=\s*["']/i, 'critical', 'Hardcoded Secret', 'Hardcoded private key detected'],
56
-
57
- // SQL Injection
58
- [/(?:query|execute|raw)\s*\(\s*[`"'].*\$\{/i, 'high', 'SQL Injection', 'String interpolation in SQL query — use parameterized queries'],
59
- [/(?:query|execute|raw)\s*\(\s*["'].*\+\s*(?:req|input|params|body)/i, 'high', 'SQL Injection', 'String concatenation with user input in SQL'],
60
- [/\.raw\s*\(\s*`/, 'medium', 'SQL Injection', 'Raw query with template literal — verify inputs are sanitized'],
61
-
62
- // XSS
63
- [/\.innerHTML\s*=/, 'high', 'XSS', 'Direct innerHTML assignment — use textContent or a sanitizer'],
64
- [/dangerouslySetInnerHTML/, 'medium', 'XSS', 'dangerouslySetInnerHTML used — ensure input is sanitized'],
65
- [/document\.write\s*\(/, 'high', 'XSS', 'document.write() is an XSS vector'],
66
-
67
- // Insecure Functions
68
- [/\beval\s*\(/, 'high', 'Code Injection', 'eval() is a code injection vector — avoid entirely'],
69
- [/new\s+Function\s*\(/, 'high', 'Code Injection', 'new Function() is equivalent to eval()'],
70
- [/child_process\.exec\s*\(/, 'medium', 'Command Injection', 'exec() with unsanitized input is a command injection vector'],
71
- [/subprocess\.call\s*\(\s*[^,\]]*\bshell\s*=\s*True/, 'high', 'Command Injection', 'subprocess with shell=True — use shell=False and pass args as list'],
72
-
73
- // Crypto
74
- [/createHash\s*\(\s*["']md5["']/, 'medium', 'Weak Crypto', 'MD5 is cryptographically broken — use SHA-256+'],
75
- [/createHash\s*\(\s*["']sha1["']/, 'medium', 'Weak Crypto', 'SHA-1 is deprecated — use SHA-256+'],
76
- [/Math\.random\s*\(/, 'low', 'Weak Randomness', 'Math.random() is not cryptographically secure — use crypto.randomBytes()'],
77
-
78
- // Auth Issues
79
- [/algorithms\s*:\s*\[\s*["']none["']/, 'critical', 'Auth Bypass', "JWT 'none' algorithm allows auth bypass"],
80
- [/verify\s*:\s*false/, 'high', 'Auth Bypass', 'SSL/TLS verification disabled'],
81
- [/rejectUnauthorized\s*:\s*false/, 'high', 'Auth Bypass', 'TLS certificate validation disabled'],
82
-
83
- // Information Disclosure
84
- [/console\.log\s*\(.*(?:password|secret|token|key)/i, 'medium', 'Info Disclosure', 'Sensitive data logged to console'],
85
- [/\.env(?:\.local|\.production)/, 'low', 'Info Disclosure', 'Env file reference — ensure not committed to git'],
67
+ // Secrets
68
+ [
69
+ /(?:password|passwd|pwd)\s*=\s*["'][^"']+["']/i,
70
+ "critical",
71
+ "Hardcoded Secret",
72
+ "Hardcoded password detected",
73
+ ],
74
+ [
75
+ /(?:api_key|apikey|api_secret)\s*=\s*["'][^"']+["']/i,
76
+ "critical",
77
+ "Hardcoded Secret",
78
+ "Hardcoded API key detected",
79
+ ],
80
+ [
81
+ /(?:secret|token|auth_token)\s*=\s*["'][A-Za-z0-9+/=]{16,}["']/i,
82
+ "critical",
83
+ "Hardcoded Secret",
84
+ "Hardcoded secret/token detected",
85
+ ],
86
+ [
87
+ /(?:PRIVATE_KEY|private_key)\s*=\s*["']/i,
88
+ "critical",
89
+ "Hardcoded Secret",
90
+ "Hardcoded private key detected",
91
+ ],
92
+
93
+ // SQL Injection
94
+ [
95
+ /(?:query|execute|raw)\s*\(\s*[`"'].*\$\{/i,
96
+ "high",
97
+ "SQL Injection",
98
+ "String interpolation in SQL query — use parameterized queries",
99
+ ],
100
+ [
101
+ /(?:query|execute|raw)\s*\(\s*["'].*\+\s*(?:req|input|params|body)/i,
102
+ "high",
103
+ "SQL Injection",
104
+ "String concatenation with user input in SQL",
105
+ ],
106
+ [
107
+ /\.raw\s*\(\s*`/,
108
+ "medium",
109
+ "SQL Injection",
110
+ "Raw query with template literal — verify inputs are sanitized",
111
+ ],
112
+
113
+ // XSS
114
+ [
115
+ /\.innerHTML\s*=/,
116
+ "high",
117
+ "XSS",
118
+ "Direct innerHTML assignment — use textContent or a sanitizer",
119
+ ],
120
+ [
121
+ /dangerouslySetInnerHTML/,
122
+ "medium",
123
+ "XSS",
124
+ "dangerouslySetInnerHTML used — ensure input is sanitized",
125
+ ],
126
+ [/document\.write\s*\(/, "high", "XSS", "document.write() is an XSS vector"],
127
+
128
+ // Insecure Functions
129
+ [
130
+ /\beval\s*\(/,
131
+ "high",
132
+ "Code Injection",
133
+ "eval() is a code injection vector — avoid entirely",
134
+ ],
135
+ [
136
+ /new\s+Function\s*\(/,
137
+ "high",
138
+ "Code Injection",
139
+ "new Function() is equivalent to eval()",
140
+ ],
141
+ [
142
+ /child_process\.exec\s*\(/,
143
+ "medium",
144
+ "Command Injection",
145
+ "exec() with unsanitized input is a command injection vector",
146
+ ],
147
+ [
148
+ /subprocess\.call\s*\(\s*[^,\]]*\bshell\s*=\s*True/,
149
+ "high",
150
+ "Command Injection",
151
+ "subprocess with shell=True — use shell=False and pass args as list",
152
+ ],
153
+
154
+ // Crypto
155
+ [
156
+ /createHash\s*\(\s*["']md5["']/,
157
+ "medium",
158
+ "Weak Crypto",
159
+ "MD5 is cryptographically broken — use SHA-256+",
160
+ ],
161
+ [
162
+ /createHash\s*\(\s*["']sha1["']/,
163
+ "medium",
164
+ "Weak Crypto",
165
+ "SHA-1 is deprecated — use SHA-256+",
166
+ ],
167
+ [
168
+ /Math\.random\s*\(/,
169
+ "low",
170
+ "Weak Randomness",
171
+ "Math.random() is not cryptographically secure — use crypto.randomBytes()",
172
+ ],
173
+
174
+ // Auth Issues
175
+ [
176
+ /algorithms\s*:\s*\[\s*["']none["']/,
177
+ "critical",
178
+ "Auth Bypass",
179
+ "JWT 'none' algorithm allows auth bypass",
180
+ ],
181
+ [
182
+ /verify\s*:\s*false/,
183
+ "high",
184
+ "Auth Bypass",
185
+ "SSL/TLS verification disabled",
186
+ ],
187
+ [
188
+ /rejectUnauthorized\s*:\s*false/,
189
+ "high",
190
+ "Auth Bypass",
191
+ "TLS certificate validation disabled",
192
+ ],
193
+
194
+ // Information Disclosure
195
+ [
196
+ /console\.log\s*\(.*(?:password|secret|token|key)/i,
197
+ "medium",
198
+ "Info Disclosure",
199
+ "Sensitive data logged to console",
200
+ ],
201
+ [
202
+ /\.env(?:\.local|\.production)/,
203
+ "low",
204
+ "Info Disclosure",
205
+ "Env file reference — ensure not committed to git",
206
+ ],
86
207
  ];
87
208
 
88
-
89
209
  /**
90
210
  * Scan a single file for security patterns.
91
211
  * @param {string} filepath - Absolute path to the file.
@@ -93,42 +213,45 @@ const PATTERNS = [
93
213
  * @returns {Array<{severity:string, category:string, file:string, line:number, message:string, snippet:string}>}
94
214
  */
95
215
  function scanFile(filepath, projectRoot) {
96
- const findings = [];
97
- const relPath = path.relative(projectRoot, filepath);
98
-
99
- let content;
100
- try {
101
- content = fs.readFileSync(filepath, 'utf8');
102
- } catch {
103
- return findings;
216
+ const findings = [];
217
+ const relPath = path.relative(projectRoot, filepath);
218
+
219
+ let content;
220
+ try {
221
+ content = fs.readFileSync(filepath, "utf8");
222
+ } catch {
223
+ return findings;
224
+ }
225
+
226
+ const lines = content.split("\n");
227
+ for (let i = 0; i < lines.length; i++) {
228
+ const stripped = lines[i].trim();
229
+ // Skip comments
230
+ if (
231
+ stripped.startsWith("//") ||
232
+ stripped.startsWith("#") ||
233
+ stripped.startsWith("*")
234
+ ) {
235
+ continue;
104
236
  }
105
237
 
106
- const lines = content.split('\n');
107
- for (let i = 0; i < lines.length; i++) {
108
- const stripped = lines[i].trim();
109
- // Skip comments
110
- if (stripped.startsWith('//') || stripped.startsWith('#') || stripped.startsWith('*')) {
111
- continue;
112
- }
113
-
114
- for (const [pattern, severity, category, message] of PATTERNS) {
115
- if (pattern.test(stripped)) {
116
- findings.push({
117
- severity,
118
- category,
119
- file: relPath,
120
- line: i + 1,
121
- message,
122
- snippet: stripped.slice(0, 120),
123
- });
124
- }
125
- }
238
+ for (const [pattern, severity, category, message] of PATTERNS) {
239
+ if (pattern.test(stripped)) {
240
+ findings.push({
241
+ severity,
242
+ category,
243
+ file: relPath,
244
+ line: i + 1,
245
+ message,
246
+ snippet: stripped.slice(0, 120),
247
+ });
248
+ }
126
249
  }
250
+ }
127
251
 
128
- return findings;
252
+ return findings;
129
253
  }
130
254
 
131
-
132
255
  /**
133
256
  * Scan all source files in a directory.
134
257
  * PERFORMANCE FIX: Uses shared walkDir from _utils.js and pushes findings
@@ -139,138 +262,158 @@ function scanFile(filepath, projectRoot) {
139
262
  * @returns {Array} Array of finding objects.
140
263
  */
141
264
  function scanDirectory(projectRoot, targetFiles) {
142
- const allFindings = [];
143
-
144
- if (targetFiles && targetFiles.length > 0) {
145
- for (const fpath of targetFiles) {
146
- const absPath = path.isAbsolute(fpath) ? fpath : path.join(projectRoot, fpath);
147
- if (fs.existsSync(absPath) && fs.statSync(absPath).isFile()) {
148
- // FIX: Push individually instead of spread to avoid O(n²)
149
- const fileFindings = scanFile(absPath, projectRoot);
150
- for (const f of fileFindings) allFindings.push(f);
151
- }
152
- }
153
- return allFindings;
154
- }
155
-
156
- const files = walkDir(projectRoot, { extensions: SCAN_EXTENSIONS });
157
-
158
- for (const filepath of files) {
265
+ const allFindings = [];
266
+
267
+ if (targetFiles && targetFiles.length > 0) {
268
+ for (const fpath of targetFiles) {
269
+ const absPath = path.isAbsolute(fpath)
270
+ ? fpath
271
+ : path.join(projectRoot, fpath);
272
+ if (fs.existsSync(absPath) && fs.statSync(absPath).isFile()) {
159
273
  // FIX: Push individually instead of spread to avoid O(n²)
160
- const fileFindings = scanFile(filepath, projectRoot);
274
+ const fileFindings = scanFile(absPath, projectRoot);
161
275
  for (const f of fileFindings) allFindings.push(f);
276
+ }
162
277
  }
163
-
164
278
  return allFindings;
165
- }
279
+ }
280
+
281
+ const files = walkDir(projectRoot, { extensions: SCAN_EXTENSIONS });
282
+
283
+ for (const filepath of files) {
284
+ // FIX: Push individually instead of spread to avoid O(n²)
285
+ const fileFindings = scanFile(filepath, projectRoot);
286
+ for (const f of fileFindings) allFindings.push(f);
287
+ }
166
288
 
289
+ return allFindings;
290
+ }
167
291
 
168
292
  /**
169
293
  * Print findings filtered by minimum severity. Returns count of displayed findings.
170
294
  */
171
295
  function printFindings(findings, minSeverity) {
172
- const minRank = SEVERITY_RANK[minSeverity] ?? 3;
173
- const filtered = findings
174
- .filter(f => (SEVERITY_RANK[f.severity] ?? 3) <= minRank)
175
- .sort((a, b) => (SEVERITY_RANK[a.severity] ?? 3) - (SEVERITY_RANK[b.severity] ?? 3));
176
-
177
- if (filtered.length === 0) {
178
- console.log(`\n ${GREEN}✅ No security issues found at severity '${minSeverity}' or above${RESET}`);
179
- return 0;
180
- }
181
-
182
- let currentCategory = '';
183
- for (const finding of filtered) {
184
- if (finding.category !== currentCategory) {
185
- currentCategory = finding.category;
186
- console.log(`\n ${BOLD}${currentCategory}${RESET}`);
187
- }
188
- const color = SEVERITY_COLORS[finding.severity] || '';
189
- console.log(` ${color}[${finding.severity.toUpperCase()}]${RESET} ${finding.file}:${finding.line}`);
190
- console.log(` ${finding.message}`);
191
- console.log(` ${MAGENTA}${finding.snippet}${RESET}`);
296
+ const minRank = SEVERITY_RANK[minSeverity] ?? 3;
297
+ const filtered = findings
298
+ .filter((f) => (SEVERITY_RANK[f.severity] ?? 3) <= minRank)
299
+ .sort(
300
+ (a, b) =>
301
+ (SEVERITY_RANK[a.severity] ?? 3) - (SEVERITY_RANK[b.severity] ?? 3),
302
+ );
303
+
304
+ if (filtered.length === 0) {
305
+ console.log(
306
+ `\n ${GREEN}✅ No security issues found at severity '${minSeverity}' or above${RESET}`,
307
+ );
308
+ return 0;
309
+ }
310
+
311
+ let currentCategory = "";
312
+ for (const finding of filtered) {
313
+ if (finding.category !== currentCategory) {
314
+ currentCategory = finding.category;
315
+ console.log(`\n ${BOLD}${currentCategory}${RESET}`);
192
316
  }
193
-
194
- return filtered.length;
317
+ const color = SEVERITY_COLORS[finding.severity] || "";
318
+ console.log(
319
+ ` ${color}[${finding.severity.toUpperCase()}]${RESET} ${finding.file}:${finding.line}`,
320
+ );
321
+ console.log(` ${finding.message}`);
322
+ console.log(` ${MAGENTA}→ ${finding.snippet}${RESET}`);
323
+ }
324
+
325
+ return filtered.length;
195
326
  }
196
327
 
197
-
198
328
  function main() {
199
- const args = { path: null, severity: 'low', files: null };
200
- const raw = process.argv.slice(2);
201
-
202
- for (let i = 0; i < raw.length; i++) {
203
- if (raw[i] === '--severity' && raw[i + 1]) {
204
- args.severity = raw[++i];
205
- } else if (raw[i] === '--files') {
206
- args.files = [];
207
- while (i + 1 < raw.length && !raw[i + 1].startsWith('--')) {
208
- args.files.push(raw[++i]);
209
- }
210
- } else if (!raw[i].startsWith('--') && !args.path) {
211
- args.path = raw[i];
212
- }
329
+ const args = { path: null, severity: "low", files: null };
330
+ const raw = process.argv.slice(2);
331
+
332
+ for (let i = 0; i < raw.length; i++) {
333
+ if (raw[i] === "--severity" && raw[i + 1]) {
334
+ args.severity = raw[++i];
335
+ } else if (raw[i] === "--files") {
336
+ args.files = [];
337
+ while (i + 1 < raw.length && !raw[i + 1].startsWith("--")) {
338
+ args.files.push(raw[++i]);
339
+ }
340
+ } else if (!raw[i].startsWith("--") && !args.path) {
341
+ args.path = raw[i];
213
342
  }
214
-
215
- if (!args.path) {
216
- console.error(`Usage: node security_scan.js <path> [--severity critical|high|medium|low] [--files ...]`);
217
- process.exit(1);
343
+ }
344
+
345
+ if (!args.path) {
346
+ console.error(
347
+ `Usage: node security_scan.js <path> [--severity critical|high|medium|low] [--files ...]`,
348
+ );
349
+ process.exit(1);
350
+ }
351
+
352
+ const projectRoot = path.resolve(args.path);
353
+ if (!fs.existsSync(projectRoot) || !fs.statSync(projectRoot).isDirectory()) {
354
+ console.error(` ${RED}❌ Directory not found: ${projectRoot}${RESET}`);
355
+ process.exit(1);
356
+ }
357
+
358
+ console.log(
359
+ banner("security_scan.js", {
360
+ Project: projectRoot,
361
+ Severity: `${args.severity}+`,
362
+ }),
363
+ );
364
+
365
+ const elapsed = timer();
366
+ const findings = scanDirectory(projectRoot, args.files);
367
+ const scanMs = elapsed();
368
+
369
+ const count = printFindings(findings, args.severity);
370
+
371
+ // ━━━ Summary ━━━
372
+ console.log(`\n${BOLD}${CYAN}━━━ Security Scan Summary ━━━${RESET}`);
373
+
374
+ const bySeverity = {};
375
+ for (const f of findings) {
376
+ bySeverity[f.severity] = (bySeverity[f.severity] || 0) + 1;
377
+ }
378
+
379
+ const uniqueFiles = new Set(findings.map((f) => f.file)).size;
380
+
381
+ for (const sev of ["critical", "high", "medium", "low"]) {
382
+ const c = bySeverity[sev] || 0;
383
+ if (c > 0) {
384
+ const color = SEVERITY_COLORS[sev] || "";
385
+ console.log(` ${color}${sev.toUpperCase()}: ${c}${RESET}`);
218
386
  }
219
-
220
- const projectRoot = path.resolve(args.path);
221
- if (!fs.existsSync(projectRoot) || !fs.statSync(projectRoot).isDirectory()) {
222
- console.error(` ${RED} Directory not found: ${projectRoot}${RESET}`);
223
- process.exit(1);
224
- }
225
-
226
- console.log(banner('security_scan.js', {
227
- Project: projectRoot,
228
- Severity: `${args.severity}+`,
229
- }));
230
-
231
- const elapsed = timer();
232
- const findings = scanDirectory(projectRoot, args.files);
233
- const scanMs = elapsed();
234
-
235
- const count = printFindings(findings, args.severity);
236
-
237
- // ━━━ Summary ━━━
238
- console.log(`\n${BOLD}${CYAN}━━━ Security Scan Summary ━━━${RESET}`);
239
-
240
- const bySeverity = {};
241
- for (const f of findings) {
242
- bySeverity[f.severity] = (bySeverity[f.severity] || 0) + 1;
387
+ }
388
+
389
+ console.log(
390
+ `\n ${DIM}Scanned in ${formatMs(scanMs)} ${findings.length} findings across ${uniqueFiles} file(s)${RESET}`,
391
+ );
392
+
393
+ if (count === 0) {
394
+ console.log(` ${GREEN}✅ No issues found — scan passed${RESET}`);
395
+ } else {
396
+ const criticalHigh = (bySeverity.critical || 0) + (bySeverity.high || 0);
397
+ if (criticalHigh > 0) {
398
+ console.log(
399
+ `\n ${RED}${BOLD}⚠️ ${criticalHigh} critical/high issue(s) require immediate attention${RESET}`,
400
+ );
243
401
  }
402
+ }
403
+ console.log();
244
404
 
245
- const uniqueFiles = new Set(findings.map(f => f.file)).size;
246
-
247
- for (const sev of ['critical', 'high', 'medium', 'low']) {
248
- const c = bySeverity[sev] || 0;
249
- if (c > 0) {
250
- const color = SEVERITY_COLORS[sev] || '';
251
- console.log(` ${color}${sev.toUpperCase()}: ${c}${RESET}`);
252
- }
253
- }
254
-
255
- console.log(`\n ${DIM}Scanned in ${formatMs(scanMs)} — ${findings.length} findings across ${uniqueFiles} file(s)${RESET}`);
256
-
257
- if (count === 0) {
258
- console.log(` ${GREEN}✅ No issues found — scan passed${RESET}`);
259
- } else {
260
- const criticalHigh = (bySeverity.critical || 0) + (bySeverity.high || 0);
261
- if (criticalHigh > 0) {
262
- console.log(`\n ${RED}${BOLD}⚠️ ${criticalHigh} critical/high issue(s) require immediate attention${RESET}`);
263
- }
264
- }
265
- console.log();
266
-
267
- process.exit((bySeverity.critical || 0) > 0 ? 1 : 0);
405
+ process.exit((bySeverity.critical || 0) > 0 ? 1 : 0);
268
406
  }
269
407
 
270
-
271
408
  // ━━━ Exports for testing & programmatic use ━━━
272
- module.exports = { scanFile, scanDirectory, printFindings, PATTERNS, SEVERITY_RANK };
409
+ module.exports = {
410
+ scanFile,
411
+ scanDirectory,
412
+ printFindings,
413
+ PATTERNS,
414
+ SEVERITY_RANK,
415
+ };
273
416
 
274
417
  if (require.main === module) {
275
- main();
418
+ main();
276
419
  }