@yagyeshvyas/vibeguard 1.0.0 → 1.1.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.
- package/CHANGELOG.md +126 -63
- package/LICENSE +21 -0
- package/README.md +499 -870
- package/bin/cli.js +2083 -1954
- package/ci/vibeguard.yml +42 -41
- package/package.json +2 -2
- package/src/auto.js +6 -1
- package/src/engine.js +294 -234
- package/src/mcp-server.js +1814 -1799
- package/src/report.js +325 -312
- package/src/rules-pack.js +9 -2
- package/src/rules.js +1506 -1451
- package/src/scanner.js +805 -685
- package/src/shell-guard.js +291 -275
- package/src/taint-ast.js +161 -9
- package/src/taint.js +14 -1
package/bin/cli.js
CHANGED
|
@@ -1,1954 +1,2083 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const path = require('path');
|
|
6
|
-
const { scan, computeGrade, sortFindings } = require('../src/scanner');
|
|
7
|
-
const { scanUrl } = require('../src/urlscan');
|
|
8
|
-
const { verify, writeBaseline } = require('../src/verify');
|
|
9
|
-
const {
|
|
10
|
-
computeAutoFixes,
|
|
11
|
-
renderDiff,
|
|
12
|
-
snapshot,
|
|
13
|
-
applyChanges,
|
|
14
|
-
rollback,
|
|
15
|
-
} = require('../src/autofix');
|
|
16
|
-
const {
|
|
17
|
-
renderHuman,
|
|
18
|
-
renderJson,
|
|
19
|
-
renderSarif,
|
|
20
|
-
renderHtml,
|
|
21
|
-
renderFixPrompt,
|
|
22
|
-
C,
|
|
23
|
-
} = require('../src/report');
|
|
24
|
-
|
|
25
|
-
// Flags that take a value (support both --flag=value and --flag value).
|
|
26
|
-
const VALUE_FLAGS = new Set(['fail-on', 'scope', 'focus', 'model', 'since', 'base', 'o', 'output', 'file', 'types', 'min-confidence']);
|
|
27
|
-
|
|
28
|
-
function parseArgs(argv) {
|
|
29
|
-
const args = { _: [], flags: {} };
|
|
30
|
-
for (let i = 0; i < argv.length; i++) {
|
|
31
|
-
const a = argv[i];
|
|
32
|
-
if (a.startsWith('--')) {
|
|
33
|
-
const eq = a.indexOf('=');
|
|
34
|
-
if (eq !== -1) {
|
|
35
|
-
args.flags[a.slice(2, eq)] = a.slice(eq + 1);
|
|
36
|
-
} else {
|
|
37
|
-
const name = a.slice(2);
|
|
38
|
-
if (VALUE_FLAGS.has(name) && i + 1 < argv.length && !argv[i + 1].startsWith('--')) {
|
|
39
|
-
args.flags[name] = argv[++i];
|
|
40
|
-
} else {
|
|
41
|
-
args.flags[name] = true;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
} else {
|
|
45
|
-
args._.push(a);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return args;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function printHelp() {
|
|
52
|
-
process.stdout.write(`
|
|
53
|
-
VibeGuard —
|
|
54
|
-
|
|
55
|
-
Usage:
|
|
56
|
-
vibeguard scan [dir]
|
|
57
|
-
vibeguard fix [dir]
|
|
58
|
-
vibeguard
|
|
59
|
-
vibeguard
|
|
60
|
-
vibeguard mcp
|
|
61
|
-
vibeguard
|
|
62
|
-
vibeguard
|
|
63
|
-
vibeguard
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
vibeguard
|
|
67
|
-
vibeguard
|
|
68
|
-
vibeguard
|
|
69
|
-
vibeguard
|
|
70
|
-
vibeguard
|
|
71
|
-
vibeguard
|
|
72
|
-
vibeguard
|
|
73
|
-
vibeguard
|
|
74
|
-
vibeguard
|
|
75
|
-
vibeguard
|
|
76
|
-
vibeguard
|
|
77
|
-
vibeguard
|
|
78
|
-
vibeguard
|
|
79
|
-
vibeguard
|
|
80
|
-
vibeguard
|
|
81
|
-
vibeguard
|
|
82
|
-
vibeguard
|
|
83
|
-
vibeguard
|
|
84
|
-
vibeguard
|
|
85
|
-
vibeguard
|
|
86
|
-
vibeguard
|
|
87
|
-
vibeguard
|
|
88
|
-
vibeguard
|
|
89
|
-
vibeguard
|
|
90
|
-
vibeguard
|
|
91
|
-
vibeguard
|
|
92
|
-
vibeguard
|
|
93
|
-
vibeguard
|
|
94
|
-
vibeguard
|
|
95
|
-
vibeguard
|
|
96
|
-
vibeguard
|
|
97
|
-
vibeguard
|
|
98
|
-
vibeguard
|
|
99
|
-
vibeguard
|
|
100
|
-
vibeguard
|
|
101
|
-
vibeguard
|
|
102
|
-
vibeguard
|
|
103
|
-
vibeguard
|
|
104
|
-
vibeguard
|
|
105
|
-
vibeguard
|
|
106
|
-
vibeguard
|
|
107
|
-
vibeguard sandbox <code>
|
|
108
|
-
vibeguard
|
|
109
|
-
vibeguard
|
|
110
|
-
vibeguard vault <action>
|
|
111
|
-
vibeguard audit-trail
|
|
112
|
-
vibeguard
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
--
|
|
127
|
-
--
|
|
128
|
-
--
|
|
129
|
-
--
|
|
130
|
-
--
|
|
131
|
-
--
|
|
132
|
-
--
|
|
133
|
-
--
|
|
134
|
-
--
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
if (flags
|
|
153
|
-
process.stdout.write(
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
if (flags
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
if (flags.
|
|
254
|
-
process.
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
);
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
)
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
);
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
return
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
);
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
if (!
|
|
434
|
-
process.
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
return
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
const
|
|
503
|
-
const {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
)
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
}
|
|
553
|
-
process.stdout.write(
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
)
|
|
560
|
-
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
const
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
)
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
const
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
const
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
const
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
`${C.
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
const
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
process.
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
if (
|
|
671
|
-
(
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
if (
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
process.
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
//
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
);
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
if (
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
if (
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
}
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
const {
|
|
923
|
-
const
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
for (const f of
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
const { walk } = require('../src/scanner');
|
|
946
|
-
const
|
|
947
|
-
const
|
|
948
|
-
const
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
process.stdout.write(
|
|
969
|
-
|
|
970
|
-
process.stdout.write(
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
const {
|
|
984
|
-
const result = scan(dir);
|
|
985
|
-
const
|
|
986
|
-
const
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
}
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
const
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
}
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
);
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
const {
|
|
1096
|
-
const
|
|
1097
|
-
const
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
const
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
}
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
}
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
}
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
const
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
const
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
process.stdout.write(
|
|
1223
|
-
|
|
1224
|
-
process.stdout.write(
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
const
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
}
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
}
|
|
1250
|
-
|
|
1251
|
-
}
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
if (
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
}
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
}
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
if (
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
}
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
}
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
const
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
const
|
|
1330
|
-
process.stdout.write(
|
|
1331
|
-
const
|
|
1332
|
-
process.stdout.write(
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
}
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
const
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
process.stdout.write(
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
process.stdout.write(
|
|
1360
|
-
for (const
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
}
|
|
1368
|
-
|
|
1369
|
-
}
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
process.stdout.write(
|
|
1378
|
-
}
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
}
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
}
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
const
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
);
|
|
1420
|
-
if (
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
const
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
const
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
const
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
}
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
`
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
return 0;
|
|
1482
|
-
}
|
|
1483
|
-
|
|
1484
|
-
function
|
|
1485
|
-
|
|
1486
|
-
const
|
|
1487
|
-
|
|
1488
|
-
const
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
if (
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
const
|
|
1518
|
-
const
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
const
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
}
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
process.stdout.write(
|
|
1594
|
-
return 0;
|
|
1595
|
-
}
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
const
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
if (
|
|
1605
|
-
}
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
}
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
if (
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
}
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
}
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
}
|
|
1642
|
-
const
|
|
1643
|
-
const
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
}
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
}
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
if (
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
process.
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
}
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
}
|
|
1731
|
-
|
|
1732
|
-
}
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
}
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
}
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
}
|
|
1777
|
-
process.stdout.write(
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
const
|
|
1790
|
-
const
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
}
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
process.stdout.write(
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
}
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
}
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
});
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const { scan, computeGrade, sortFindings } = require('../src/scanner');
|
|
7
|
+
const { scanUrl } = require('../src/urlscan');
|
|
8
|
+
const { verify, writeBaseline } = require('../src/verify');
|
|
9
|
+
const {
|
|
10
|
+
computeAutoFixes,
|
|
11
|
+
renderDiff,
|
|
12
|
+
snapshot,
|
|
13
|
+
applyChanges,
|
|
14
|
+
rollback,
|
|
15
|
+
} = require('../src/autofix');
|
|
16
|
+
const {
|
|
17
|
+
renderHuman,
|
|
18
|
+
renderJson,
|
|
19
|
+
renderSarif,
|
|
20
|
+
renderHtml,
|
|
21
|
+
renderFixPrompt,
|
|
22
|
+
C,
|
|
23
|
+
} = require('../src/report');
|
|
24
|
+
|
|
25
|
+
// Flags that take a value (support both --flag=value and --flag value).
|
|
26
|
+
const VALUE_FLAGS = new Set(['fail-on', 'scope', 'focus', 'model', 'since', 'base', 'o', 'output', 'file', 'types', 'min-confidence']);
|
|
27
|
+
|
|
28
|
+
function parseArgs(argv) {
|
|
29
|
+
const args = { _: [], flags: {} };
|
|
30
|
+
for (let i = 0; i < argv.length; i++) {
|
|
31
|
+
const a = argv[i];
|
|
32
|
+
if (a.startsWith('--')) {
|
|
33
|
+
const eq = a.indexOf('=');
|
|
34
|
+
if (eq !== -1) {
|
|
35
|
+
args.flags[a.slice(2, eq)] = a.slice(eq + 1);
|
|
36
|
+
} else {
|
|
37
|
+
const name = a.slice(2);
|
|
38
|
+
if (VALUE_FLAGS.has(name) && i + 1 < argv.length && !argv[i + 1].startsWith('--')) {
|
|
39
|
+
args.flags[name] = argv[++i];
|
|
40
|
+
} else {
|
|
41
|
+
args.flags[name] = true;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
args._.push(a);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return args;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function printHelp() {
|
|
52
|
+
process.stdout.write(`
|
|
53
|
+
VibeGuard — offline security scanner for AI-generated code.
|
|
54
|
+
|
|
55
|
+
Usage:
|
|
56
|
+
vibeguard scan [dir] Scan a project (auto-detects framework).
|
|
57
|
+
vibeguard fix [dir] Auto-fix safe issues (secret->env, .gitignore).
|
|
58
|
+
vibeguard pre-deploy [dir] 13-gate deployment check.
|
|
59
|
+
vibeguard dashboard [dir] Visual terminal dashboard.
|
|
60
|
+
vibeguard mcp MCP server (for Claude Code, Cursor, etc.).
|
|
61
|
+
vibeguard auto [dir] One-command full protection (daemon + hooks).
|
|
62
|
+
vibeguard auto --stop Turn off, restore backups.
|
|
63
|
+
vibeguard auto --status Show what's active.
|
|
64
|
+
|
|
65
|
+
Advanced:
|
|
66
|
+
vibeguard verify [dir] Re-scan, report resolved vs remaining.
|
|
67
|
+
vibeguard install Wire MCP server into detected AI clients.
|
|
68
|
+
vibeguard rules List every detection rule.
|
|
69
|
+
vibeguard explain <ruleId> Show details + fix for one rule.
|
|
70
|
+
vibeguard doctor [dir] Audit AI-tool host config.
|
|
71
|
+
vibeguard install-hook git pre-commit hook (blocks on CRITICAL).
|
|
72
|
+
vibeguard install-hook-post PostToolUse hook (auto-scan AI edits).
|
|
73
|
+
vibeguard uninstall-hook-post Remove PostToolUse hook.
|
|
74
|
+
vibeguard rollback [dir] Undo last 'fix --apply'.
|
|
75
|
+
vibeguard watch [dir] Re-scan on file change (live).
|
|
76
|
+
vibeguard history [dir] Scan git history for secrets.
|
|
77
|
+
vibeguard url <url> Scan a live site's HTTP headers.
|
|
78
|
+
vibeguard badge [dir] Award badge SVG (zero critical+high).
|
|
79
|
+
vibeguard init-ci [dir] Write GitHub Actions workflow.
|
|
80
|
+
vibeguard compliance [dir] Map findings to SOC2/PCI/HIPAA/GDPR.
|
|
81
|
+
vibeguard cve [dir] Query OSV.dev for dependency CVEs.
|
|
82
|
+
vibeguard slopsquat [dir] Check for hallucinated npm packages.
|
|
83
|
+
vibeguard secure-prompt <p> Analyze AI prompt for security risks.
|
|
84
|
+
vibeguard trace [dir] Trace findings to AI prompts.
|
|
85
|
+
vibeguard repl [dir] Interactive REPL.
|
|
86
|
+
vibeguard auth-coverage [dir] Enumerate routes -> auth guards.
|
|
87
|
+
vibeguard diff [dir] Compare vs baseline.
|
|
88
|
+
vibeguard deep-scan [dir] Full audit: scan + CVE + auth + behavior.
|
|
89
|
+
vibeguard html [dir] Generate HTML security report.
|
|
90
|
+
vibeguard inject-rules [dir] Inject rules into CLAUDE.md/.cursorrules.
|
|
91
|
+
vibeguard bench [dir] Benchmark: files/sec, rules, findings.
|
|
92
|
+
vibeguard risk-score [dir] Weighted risk score (0-100).
|
|
93
|
+
vibeguard why <ruleId> Explain why a rule fired.
|
|
94
|
+
vibeguard preset <name> Apply a rule preset (nextjs, django, etc.).
|
|
95
|
+
vibeguard preset --list List all presets.
|
|
96
|
+
vibeguard guard "<cmd>" Check a shell command before running.
|
|
97
|
+
vibeguard install-shell-hook Install shell pre-exec hook.
|
|
98
|
+
vibeguard uninstall-shell-hook Remove shell hook.
|
|
99
|
+
vibeguard privacy-audit [dir] Inventory PII collection/storage.
|
|
100
|
+
vibeguard net-audit [dir] Map outbound HTTP calls.
|
|
101
|
+
vibeguard ai-guard [dir] Detect user data to AI APIs.
|
|
102
|
+
vibeguard privacy-policy [dir] Generate privacy policy from code.
|
|
103
|
+
vibeguard csp-generate [dir] Generate Content-Security-Policy.
|
|
104
|
+
vibeguard firewall <prompt> AI firewall — inspect prompt before LLM.
|
|
105
|
+
vibeguard exfil-check <data> Check data for PII/secrets.
|
|
106
|
+
vibeguard dep-firewall <pkg> Check package before npm install.
|
|
107
|
+
vibeguard sandbox <code> Execute code in zero-trust sandbox.
|
|
108
|
+
vibeguard self-check [dir] Check if VibeGuard is tampered with.
|
|
109
|
+
vibeguard env-lock [dir] Lock env vars from AI agents.
|
|
110
|
+
vibeguard vault <action> Encrypted secret vault.
|
|
111
|
+
vibeguard audit-trail <action> Tamper-proof audit trail.
|
|
112
|
+
vibeguard redact "<text>" Redact PII from text.
|
|
113
|
+
vibeguard detect-pii "<text>" List PII in text.
|
|
114
|
+
|
|
115
|
+
Options:
|
|
116
|
+
--json JSON output.
|
|
117
|
+
--sarif SARIF 2.1.0 (GitHub code scanning).
|
|
118
|
+
--fix-prompt Print only the fix prompt block.
|
|
119
|
+
--apply (fix) Apply safe auto-fixes.
|
|
120
|
+
--all Show all findings (ignore baseline, show low-confidence).
|
|
121
|
+
--min-confidence <level> Filter: low|medium|high (default: medium).
|
|
122
|
+
--baseline Save current findings as baseline. Future scans auto-suppress known issues.
|
|
123
|
+
--new-only Report only findings not in baseline.
|
|
124
|
+
--no-deps Skip dependency audit.
|
|
125
|
+
--deep Fold in semgrep/gitleaks/bandit.
|
|
126
|
+
--changed Incremental: only rescan files changed since last scan (per-file; skips cross-file analysis).
|
|
127
|
+
--staged Scan only git-staged files (pre-commit; skips cross-file analysis).
|
|
128
|
+
--strict Fail (exit 3) if any file scanned degraded.
|
|
129
|
+
--no-suppress Ignore inline vibeguard-ignore comments + heuristic FP filter (CI trust mode).
|
|
130
|
+
--fail-on <level> Exit non-zero at/above severity.
|
|
131
|
+
--no-summary Suppress summary line.
|
|
132
|
+
--show-suppressed Include inline-suppressed findings.
|
|
133
|
+
--yes Skip consent prompts (shell hook, auto).
|
|
134
|
+
--patch Output as unified diff.
|
|
135
|
+
-o, --output <file> HTML report output path.
|
|
136
|
+
-h, --help Show this help.
|
|
137
|
+
|
|
138
|
+
Scope: VibeGuard flags high-frequency security issues (secrets, injection,
|
|
139
|
+
misconfig) and helps you fix them. It does NOT prove an app is safe.
|
|
140
|
+
`);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function outputResult(result, flags) {
|
|
144
|
+
if (flags.json) {
|
|
145
|
+
process.stdout.write(renderJson(result) + '\n');
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (flags.sarif) {
|
|
149
|
+
process.stdout.write(renderSarif(result) + '\n');
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (flags['fix-prompt']) {
|
|
153
|
+
process.stdout.write(renderFixPrompt(result) + '\n');
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (flags['patch']) {
|
|
157
|
+
const patches = generatePatch(result.findings);
|
|
158
|
+
process.stdout.write(patches);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
process.stdout.write(renderHuman(result));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function detectFramework(dir) {
|
|
165
|
+
const root = path.resolve(dir || '.');
|
|
166
|
+
const exists = (f) => fs.existsSync(path.join(root, f));
|
|
167
|
+
// Check in priority order — most specific first
|
|
168
|
+
if (exists('next.config.js') || exists('next.config.mjs') || exists('next.config.ts')) return 'nextjs';
|
|
169
|
+
if (exists('supabase') || exists('supabase/config.toml')) return 'nextjs'; // supabase often paired with nextjs
|
|
170
|
+
if (exists('firebase.json') || exists('.firebaserc')) return 'react';
|
|
171
|
+
if (exists('requirements.txt') || exists('manage.py')) return 'django';
|
|
172
|
+
if (exists('app.py') || exists('wsgi.py')) return 'flask';
|
|
173
|
+
if (exists('Gemfile') || exists('config/routes.rb')) return 'rails';
|
|
174
|
+
if (exists('pom.xml') || exists('build.gradle') && exists('src/main/java')) return 'spring';
|
|
175
|
+
if (exists('go.mod')) return 'api'; // Go apps are usually API servers
|
|
176
|
+
if (exists('Cargo.toml')) return 'api';
|
|
177
|
+
if (exists('docker-compose.yml') || exists('docker-compose.yaml')) return 'fullstack';
|
|
178
|
+
if (exists('package.json')) {
|
|
179
|
+
try {
|
|
180
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
|
|
181
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
182
|
+
if (deps['next']) return 'nextjs';
|
|
183
|
+
if (deps['react-native'] || deps['expo']) return 'mobile';
|
|
184
|
+
if (deps['react']) return 'react';
|
|
185
|
+
if (deps['express'] || deps['fastify'] || deps['hono'] || deps['@hono/node-server']) return 'api';
|
|
186
|
+
} catch {}
|
|
187
|
+
}
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function cmdScan(dir, flags) {
|
|
192
|
+
// Auto-detect framework/stack and apply preset if not explicitly set.
|
|
193
|
+
if (!flags.preset && !flags['no-preset']) {
|
|
194
|
+
const detected = detectFramework(dir);
|
|
195
|
+
if (detected) {
|
|
196
|
+
const { applyPreset } = require('../src/presets');
|
|
197
|
+
const applied = applyPreset(detected);
|
|
198
|
+
if (applied && !flags.json && !flags.sarif) {
|
|
199
|
+
process.stderr.write(`${C.dim}detected: ${detected} — applied preset${C.reset}\n`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Dependency audit runs by default; disable with --no-deps.
|
|
205
|
+
// --deep folds in external scanners (semgrep/gitleaks) when installed.
|
|
206
|
+
const result = scan(dir, {
|
|
207
|
+
deps: flags.deps !== false && !flags['no-deps'],
|
|
208
|
+
deep: !!flags.deep,
|
|
209
|
+
changed: !!flags.changed,
|
|
210
|
+
staged: !!flags.staged,
|
|
211
|
+
noSuppress: !!flags['no-suppress'],
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
if (flags.staged && result.staged && !flags.json && !flags.sarif) {
|
|
215
|
+
process.stderr.write(
|
|
216
|
+
`${C.dim}staged: scanned ${result.staged.scanned} staged file(s) of ${result.staged.total} ` +
|
|
217
|
+
`(cross-file analysis skipped — run a full scan for that)${C.reset}\n`
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Incremental mode note: report how much work was skipped, and be explicit
|
|
222
|
+
// that cross-file analysis is not run (per-file only).
|
|
223
|
+
if (flags.changed && result.incremental && !flags.json && !flags.sarif) {
|
|
224
|
+
const inc = result.incremental;
|
|
225
|
+
process.stderr.write(
|
|
226
|
+
`${C.dim}incremental: scanned ${inc.scanned}/${inc.total} changed file(s), ${inc.cached} unchanged skipped ` +
|
|
227
|
+
`(cross-file analysis skipped — run a full scan for that)${C.reset}\n`
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Engine-mode + coverage transparency. Never let a degraded scan look clean.
|
|
232
|
+
if (!flags.json && !flags.sarif) {
|
|
233
|
+
if (result.engine && result.engine.mode === 'regex-only') {
|
|
234
|
+
process.stderr.write(
|
|
235
|
+
`${C.yellow}⚠ engine: regex-only — acorn not installed, AST/taint precision disabled. ` +
|
|
236
|
+
`Install with: npm i -D acorn acorn-walk acorn-typescript${C.reset}\n`
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
const d = result.diagnostics;
|
|
240
|
+
if (d && d.degradedFileCount > 0) {
|
|
241
|
+
const passes = [...new Set((d.degradedPasses || []).map((x) => x.pass))];
|
|
242
|
+
process.stderr.write(
|
|
243
|
+
`${C.yellow}⚠ degraded coverage: ${d.degradedFileCount} file(s) not fully analyzed` +
|
|
244
|
+
(d.parseFailedFiles && d.parseFailedFiles.length ? ` (${d.parseFailedFiles.length} parse-failed)` : '') +
|
|
245
|
+
(passes.length ? ` [passes: ${passes.join(', ')}]` : '') +
|
|
246
|
+
`. Run with --strict to fail on degraded scans.${C.reset}\n`
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// --strict: treat a degraded scan (any pass failed open) as a hard failure so
|
|
252
|
+
// CI never trusts an incomplete result.
|
|
253
|
+
if (flags.strict && result.diagnostics && result.diagnostics.degradedFileCount > 0) {
|
|
254
|
+
process.stderr.write(
|
|
255
|
+
`${C.red}✗ --strict: scan ran degraded on ${result.diagnostics.degradedFileCount} file(s); refusing to report clean.${C.reset}\n`
|
|
256
|
+
);
|
|
257
|
+
outputResult(result, flags);
|
|
258
|
+
return 3;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Default min-confidence: medium (unless --all or explicit --min-confidence).
|
|
262
|
+
const CONFIDENCE_ORDER = { low: 0, medium: 1, high: 2 };
|
|
263
|
+
const minConf = flags['min-confidence'] || (flags.all ? 'low' : 'medium');
|
|
264
|
+
const threshold = CONFIDENCE_ORDER[String(minConf).toLowerCase()];
|
|
265
|
+
if (threshold !== undefined) {
|
|
266
|
+
result.findings = result.findings.filter((f) => {
|
|
267
|
+
const fc = CONFIDENCE_ORDER[f.confidence] || 0;
|
|
268
|
+
return fc >= threshold;
|
|
269
|
+
});
|
|
270
|
+
const { computeGrade } = require('../src/scanner');
|
|
271
|
+
const g = computeGrade(result.findings);
|
|
272
|
+
result.grade = g.grade;
|
|
273
|
+
result.counts = g.counts;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// --show-suppressed: re-add suppressed findings (annotated) to the output.
|
|
277
|
+
if (flags['show-suppressed'] && result.suppressedFindings) {
|
|
278
|
+
result.findings = result.findings.concat(result.suppressedFindings);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// Baseline auto-suppression: if a baseline file exists and the user didn't
|
|
282
|
+
// explicitly pass --new-only or --all, default to new-only and inform them.
|
|
283
|
+
if (!flags.baseline && !flags['new-only'] && !flags.all && !flags.json && !flags.sarif) {
|
|
284
|
+
const { readBaseline } = require('../src/verify');
|
|
285
|
+
const base = readBaseline(dir);
|
|
286
|
+
if (base && Array.isArray(base.findings) && base.findings.length > 0) {
|
|
287
|
+
const seen = new Set(
|
|
288
|
+
base.findings.map((f) => f.fingerprint || `${f.ruleId} ${f.file} ${(f.snippet || '').trim()}`)
|
|
289
|
+
);
|
|
290
|
+
const before = result.findings.length;
|
|
291
|
+
result.findings = result.findings.filter((f) => !seen.has(f.fingerprint));
|
|
292
|
+
const suppressed = before - result.findings.length;
|
|
293
|
+
if (suppressed > 0) {
|
|
294
|
+
const { computeGrade } = require('../src/scanner');
|
|
295
|
+
const g = computeGrade(result.findings);
|
|
296
|
+
result.grade = g.grade;
|
|
297
|
+
result.counts = g.counts;
|
|
298
|
+
result.baselineSuppressed = suppressed;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// --new-only: explicit flag — same behavior but no message (user asked for it).
|
|
304
|
+
if (flags['new-only']) {
|
|
305
|
+
const { readBaseline } = require('../src/verify');
|
|
306
|
+
const base = readBaseline(dir);
|
|
307
|
+
if (base && Array.isArray(base.findings)) {
|
|
308
|
+
const seen = new Set(
|
|
309
|
+
base.findings.map((f) => f.fingerprint || `${f.ruleId} ${f.file} ${(f.snippet || '').trim()}`)
|
|
310
|
+
);
|
|
311
|
+
result.findings = result.findings.filter((f) => !seen.has(f.fingerprint));
|
|
312
|
+
const { computeGrade } = require('../src/scanner');
|
|
313
|
+
const g = computeGrade(result.findings);
|
|
314
|
+
result.grade = g.grade;
|
|
315
|
+
result.counts = g.counts;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if (flags.deep && result.externalInfo && !flags.json && !flags.sarif) {
|
|
320
|
+
const ran = result.externalInfo.ran || {};
|
|
321
|
+
process.stderr.write(
|
|
322
|
+
`${C.dim}deep: semgrep=${ran.semgrep ? 'ran' : 'skipped'}, gitleaks=${ran.gitleaks ? 'ran' : 'skipped'}` +
|
|
323
|
+
(result.externalInfo.notes.length ? ' (' + result.externalInfo.notes.join('; ') + ')' : '') +
|
|
324
|
+
`${C.reset}\n`
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
if (flags.baseline) {
|
|
328
|
+
const p = writeBaseline(dir, result);
|
|
329
|
+
if (!flags.json && !flags.sarif) {
|
|
330
|
+
process.stderr.write(`${C.dim}baseline saved: ${p}${C.reset}\n`);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
outputResult(result, flags);
|
|
334
|
+
|
|
335
|
+
if (flags.precommit) {
|
|
336
|
+
// Hook mode: block only on CRITICAL.
|
|
337
|
+
return result.counts.critical > 0 ? 2 : 0;
|
|
338
|
+
}
|
|
339
|
+
// --fail-on <level>: exit 1 only when a finding at/above that severity exists.
|
|
340
|
+
if (flags['fail-on']) {
|
|
341
|
+
const order = ['critical', 'high', 'medium', 'low'];
|
|
342
|
+
const threshold = order.indexOf(String(flags['fail-on']).toLowerCase());
|
|
343
|
+
if (String(flags['fail-on']).toLowerCase() === 'none') return 0;
|
|
344
|
+
if (threshold === -1) return result.findings.length > 0 ? 1 : 0;
|
|
345
|
+
const worst = result.findings.reduce((acc, f) => Math.min(acc, order.indexOf(f.severity)), 4);
|
|
346
|
+
return worst <= threshold ? 1 : 0;
|
|
347
|
+
}
|
|
348
|
+
// Default exit: non-zero if any finding, so CI notices.
|
|
349
|
+
return result.findings.length > 0 ? 1 : 0;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function cmdFix(dir, flags) {
|
|
353
|
+
const result = scan(dir);
|
|
354
|
+
|
|
355
|
+
if (flags.json) {
|
|
356
|
+
process.stdout.write(renderJson(result) + '\n');
|
|
357
|
+
return result.findings.length > 0 ? 1 : 0;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// fix NEVER rewrites files silently. It prints the concrete fixes plus a
|
|
361
|
+
// ready-to-paste prompt for the user's AI tool to apply under review.
|
|
362
|
+
if (result.findings.length === 0) {
|
|
363
|
+
process.stdout.write(`${C.green}Nothing to fix — no issues found.${C.reset}\n`);
|
|
364
|
+
return 0;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
process.stdout.write(renderHuman(result));
|
|
368
|
+
|
|
369
|
+
// Safe auto-fixes: dry-run diff by default; apply only with --apply (snapshotted).
|
|
370
|
+
const changes = computeAutoFixes(dir, result);
|
|
371
|
+
if (changes.length > 0) {
|
|
372
|
+
process.stdout.write(
|
|
373
|
+
`${C.bold}${C.cyan}Safe auto-fixes available (${changes.length}) — mechanical & reversible:${C.reset}\n\n`
|
|
374
|
+
);
|
|
375
|
+
for (const c of changes) {
|
|
376
|
+
process.stdout.write(`${C.bold}${c.description}${C.reset} ${C.dim}[${c.ruleId}]${C.reset}\n`);
|
|
377
|
+
process.stdout.write(renderDiff(c) + '\n\n');
|
|
378
|
+
}
|
|
379
|
+
if (flags.apply) {
|
|
380
|
+
const snapDir = snapshot(dir, changes);
|
|
381
|
+
applyChanges(dir, changes);
|
|
382
|
+
process.stdout.write(
|
|
383
|
+
`${C.green}Applied ${changes.length} safe fix(es).${C.reset} ` +
|
|
384
|
+
`${C.dim}Snapshot: ${snapDir}${C.reset}\n` +
|
|
385
|
+
`Undo with: ${C.bold}vibeguard rollback ${dir}${C.reset}\n\n`
|
|
386
|
+
);
|
|
387
|
+
} else {
|
|
388
|
+
process.stdout.write(
|
|
389
|
+
`${C.yellow}Dry run — nothing written.${C.reset} Apply these with: ` +
|
|
390
|
+
`${C.bold}vibeguard fix ${dir} --apply${C.reset} (files are snapshotted first).\n\n`
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
process.stdout.write(
|
|
396
|
+
`${C.bold}${C.cyan}Copy-paste this into your AI coding tool to apply the remaining fixes:${C.reset}\n`
|
|
397
|
+
);
|
|
398
|
+
process.stdout.write(`${C.dim}${'-'.repeat(70)}${C.reset}\n`);
|
|
399
|
+
process.stdout.write(renderFixPrompt(result) + '\n');
|
|
400
|
+
process.stdout.write(`${C.dim}${'-'.repeat(70)}${C.reset}\n`);
|
|
401
|
+
process.stdout.write(
|
|
402
|
+
`\n${C.yellow}Review every change before committing. VibeGuard will not edit your files for you.${C.reset}\n`
|
|
403
|
+
);
|
|
404
|
+
process.stdout.write(
|
|
405
|
+
`${C.dim}Tip: run 'vibeguard scan --baseline' first, then 'vibeguard verify' after fixing.${C.reset}\n`
|
|
406
|
+
);
|
|
407
|
+
return result.findings.length > 0 ? 1 : 0;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function cmdVerify(dir, flags) {
|
|
411
|
+
const res = verify(dir);
|
|
412
|
+
|
|
413
|
+
if (flags.json) {
|
|
414
|
+
process.stdout.write(
|
|
415
|
+
JSON.stringify(
|
|
416
|
+
{
|
|
417
|
+
hasBaseline: res.hasBaseline,
|
|
418
|
+
grade: res.current.grade,
|
|
419
|
+
counts: res.current.counts,
|
|
420
|
+
resolved: res.resolved,
|
|
421
|
+
remaining: res.remaining,
|
|
422
|
+
introduced: res.introduced,
|
|
423
|
+
},
|
|
424
|
+
null,
|
|
425
|
+
2
|
|
426
|
+
) + '\n'
|
|
427
|
+
);
|
|
428
|
+
return res.remaining.length + res.introduced.length > 0 ? 1 : 0;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
process.stdout.write(`\n${C.bold}${C.cyan}VibeGuard verify${C.reset}\n\n`);
|
|
432
|
+
|
|
433
|
+
if (!res.hasBaseline) {
|
|
434
|
+
process.stdout.write(
|
|
435
|
+
`${C.yellow}No baseline found.${C.reset} Showing current state. ` +
|
|
436
|
+
`Run 'vibeguard scan --baseline' before fixing to enable a before/after diff.\n\n`
|
|
437
|
+
);
|
|
438
|
+
outputResult(res.current, {});
|
|
439
|
+
return res.current.findings.length > 0 ? 1 : 0;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
for (const f of res.resolved) {
|
|
443
|
+
process.stdout.write(
|
|
444
|
+
`${C.green}✓ resolved${C.reset} ${f.file}:${f.line} ${C.dim}[${f.ruleId}]${C.reset}\n`
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
for (const f of res.remaining) {
|
|
448
|
+
process.stdout.write(
|
|
449
|
+
`${C.red}✗ still present${C.reset} ${f.file}:${f.line} ${C.dim}[${f.ruleId}]${C.reset}\n`
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
for (const f of res.introduced) {
|
|
453
|
+
process.stdout.write(
|
|
454
|
+
`${C.magenta}! new issue${C.reset} ${f.file}:${f.line} ${C.dim}[${f.ruleId}]${C.reset}\n`
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
process.stdout.write(
|
|
459
|
+
`\n${C.bold}${res.resolved.length} resolved${C.reset}, ` +
|
|
460
|
+
`${res.remaining.length} remaining, ${res.introduced.length} new. ` +
|
|
461
|
+
`Current grade: ${res.current.grade}\n\n`
|
|
462
|
+
);
|
|
463
|
+
|
|
464
|
+
return res.remaining.length + res.introduced.length > 0 ? 1 : 0;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
function cmdWatch(dir, flags) {
|
|
468
|
+
const runScan = () => {
|
|
469
|
+
const result = scan(dir, { deps: false });
|
|
470
|
+
process.stdout.write('\x1b[2J\x1b[H'); // clear screen
|
|
471
|
+
process.stdout.write(renderHuman(result));
|
|
472
|
+
};
|
|
473
|
+
process.stdout.write(`${C.cyan}VibeGuard watching ${path.resolve(dir)} — Ctrl+C to stop${C.reset}\n`);
|
|
474
|
+
runScan();
|
|
475
|
+
let timer = null;
|
|
476
|
+
const debounced = (_e, file) => {
|
|
477
|
+
if (file && /node_modules|\.git|\.vibeguard/.test(String(file))) return;
|
|
478
|
+
clearTimeout(timer);
|
|
479
|
+
timer = setTimeout(runScan, 300);
|
|
480
|
+
};
|
|
481
|
+
try {
|
|
482
|
+
fs.watch(path.resolve(dir), { recursive: true }, debounced);
|
|
483
|
+
} catch (err) {
|
|
484
|
+
process.stderr.write(`watch not supported here: ${err.message}\n`);
|
|
485
|
+
return 2;
|
|
486
|
+
}
|
|
487
|
+
return new Promise(() => {}); // never resolves; runs until Ctrl+C
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
async function cmdUrl(target, flags) {
|
|
491
|
+
if (!target || target === '.') {
|
|
492
|
+
process.stderr.write('usage: vibeguard url <https://your-site.com>\n');
|
|
493
|
+
return 2;
|
|
494
|
+
}
|
|
495
|
+
let res;
|
|
496
|
+
try {
|
|
497
|
+
res = await scanUrl(target);
|
|
498
|
+
} catch (err) {
|
|
499
|
+
process.stderr.write(`vibeguard url error: ${err.message}\n`);
|
|
500
|
+
return 2;
|
|
501
|
+
}
|
|
502
|
+
const findings = sortFindings(res.findings);
|
|
503
|
+
const { grade, counts } = computeGrade(findings);
|
|
504
|
+
const result = {
|
|
505
|
+
root: res.url,
|
|
506
|
+
scannedFiles: 1,
|
|
507
|
+
findings,
|
|
508
|
+
grade,
|
|
509
|
+
counts,
|
|
510
|
+
generatedAt: new Date().toISOString(),
|
|
511
|
+
};
|
|
512
|
+
outputResult(result, flags);
|
|
513
|
+
return findings.length > 0 ? 1 : 0;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
function cmdRules(flags) {
|
|
517
|
+
const { allRules } = require('../src/rules');
|
|
518
|
+
const rules = allRules().sort((a, b) => (a.category + a.id).localeCompare(b.category + b.id));
|
|
519
|
+
if (flags.json) {
|
|
520
|
+
process.stdout.write(JSON.stringify(rules, null, 2) + '\n');
|
|
521
|
+
return 0;
|
|
522
|
+
}
|
|
523
|
+
let cat = '';
|
|
524
|
+
for (const r of rules) {
|
|
525
|
+
if (r.category !== cat) { cat = r.category; process.stdout.write(`\n${C.bold}${C.cyan}${cat}${C.reset}\n`); }
|
|
526
|
+
process.stdout.write(` ${r.id.padEnd(34)} ${C.dim}${r.severity}${C.reset} ${r.title}\n`);
|
|
527
|
+
}
|
|
528
|
+
process.stdout.write(`\n${C.dim}${rules.length} rules. 'vibeguard explain <ruleId>' for details.${C.reset}\n`);
|
|
529
|
+
return 0;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
function cmdExplain(ruleId, flags) {
|
|
533
|
+
const { allRules } = require('../src/rules');
|
|
534
|
+
const r = allRules().find((x) => x.id === ruleId);
|
|
535
|
+
if (!r) {
|
|
536
|
+
process.stderr.write(`Unknown rule: ${ruleId}. Run 'vibeguard rules' to list them.\n`);
|
|
537
|
+
return 2;
|
|
538
|
+
}
|
|
539
|
+
if (flags.json) { process.stdout.write(JSON.stringify(r, null, 2) + '\n'); return 0; }
|
|
540
|
+
process.stdout.write(
|
|
541
|
+
`\n${C.bold}${r.id}${C.reset} ${C.dim}[${r.category}]${C.reset}\n` +
|
|
542
|
+
`severity: ${r.severity} confidence: ${r.confidence}\n` +
|
|
543
|
+
`${C.bold}${r.title}${C.reset}\n\n` +
|
|
544
|
+
(r.message ? r.message + '\n\n' : '') +
|
|
545
|
+
(r.fix ? `${C.green}fix:${C.reset} ${r.fix}\n` : `${C.dim}(dynamic message — run a scan to see specifics)${C.reset}\n`)
|
|
546
|
+
);
|
|
547
|
+
return 0;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function cmdDoctor(dir, flags) {
|
|
551
|
+
const { runDoctor } = require('../src/doctor');
|
|
552
|
+
const findings = runDoctor(dir, { scope: flags.scope || 'full' });
|
|
553
|
+
if (flags.json) { process.stdout.write(JSON.stringify({ findings }, null, 2) + '\n'); return findings.length ? 1 : 0; }
|
|
554
|
+
process.stdout.write(`\n${C.bold}${C.cyan}VibeGuard doctor${C.reset} ${C.dim}(AI host security)${C.reset}\n\n`);
|
|
555
|
+
if (findings.length === 0) {
|
|
556
|
+
process.stdout.write(`${C.green}No host security issues found in AI tool configs / environment.${C.reset}\n`);
|
|
557
|
+
return 0;
|
|
558
|
+
}
|
|
559
|
+
for (const f of findings) {
|
|
560
|
+
process.stdout.write(`${C.red}${f.severity.toUpperCase()}${C.reset} ${f.file} ${C.dim}[${f.ruleId}]${C.reset}\n ${f.message}\n ${C.green}fix:${C.reset} ${f.fix}\n\n`);
|
|
561
|
+
}
|
|
562
|
+
process.stdout.write(`${C.bold}${findings.length} host issue(s).${C.reset} These affect your machine/AI tools, not just this repo.\n`);
|
|
563
|
+
return 1;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
function cmdHistory(dir, flags) {
|
|
567
|
+
const { scanHistory } = require('../src/history');
|
|
568
|
+
const res = scanHistory(dir, { all: !!flags.all });
|
|
569
|
+
if (!res.ran) {
|
|
570
|
+
process.stderr.write(`${C.yellow}${res.note}${C.reset}\n`);
|
|
571
|
+
return 2;
|
|
572
|
+
}
|
|
573
|
+
if (flags.json) {
|
|
574
|
+
process.stdout.write(JSON.stringify({ findings: res.findings }, null, 2) + '\n');
|
|
575
|
+
return res.findings.length ? 1 : 0;
|
|
576
|
+
}
|
|
577
|
+
if (res.findings.length === 0) {
|
|
578
|
+
process.stdout.write(`${C.green}No secrets found in git history (scanned recent commits).${C.reset}\n`);
|
|
579
|
+
return 0;
|
|
580
|
+
}
|
|
581
|
+
process.stdout.write(`\n${C.bold}${C.red}Secrets found in git history:${C.reset}\n\n`);
|
|
582
|
+
for (const f of res.findings) {
|
|
583
|
+
process.stdout.write(`${C.red}CRITICAL${C.reset} ${f.file}:${f.line} ${C.dim}[${f.ruleId}]${C.reset}\n ${f.message}\n ${C.green}fix:${C.reset} ${f.fix}\n\n`);
|
|
584
|
+
}
|
|
585
|
+
process.stdout.write(`${C.bold}${res.findings.length} secret(s) in history.${C.reset} Rotate them — removing the file does NOT remove them from git.\n`);
|
|
586
|
+
return 1;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
function cmdRollback(dir) {
|
|
590
|
+
const res = rollback(dir);
|
|
591
|
+
if (!res.ok) {
|
|
592
|
+
process.stderr.write(`${C.yellow}Nothing to roll back:${C.reset} ${res.reason}\n`);
|
|
593
|
+
return 1;
|
|
594
|
+
}
|
|
595
|
+
process.stdout.write(
|
|
596
|
+
`${C.green}Rolled back ${res.restored.length} file(s)${C.reset} from snapshot ${res.stamp}:\n` +
|
|
597
|
+
res.restored.map((f) => ` ${f}`).join('\n') +
|
|
598
|
+
'\n'
|
|
599
|
+
);
|
|
600
|
+
return 0;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
function cmdInstall(flags) {
|
|
604
|
+
const { install } = require('../src/install');
|
|
605
|
+
const { spec, results, paste } = install({ local: !!flags.local });
|
|
606
|
+
|
|
607
|
+
process.stdout.write(`\n${C.bold}${C.cyan}VibeGuard — wiring the MCP server into your AI tools${C.reset}\n`);
|
|
608
|
+
process.stdout.write(`${C.dim}server: ${spec.command} ${spec.args.join(' ')}${C.reset}\n\n`);
|
|
609
|
+
|
|
610
|
+
const icon = { installed: `${C.green}✓${C.reset}`, skipped: `${C.dim}–${C.reset}`, manual: `${C.yellow}!${C.reset}`, error: `${C.red}✗${C.reset}` };
|
|
611
|
+
for (const r of results) {
|
|
612
|
+
process.stdout.write(` ${icon[r.status] || '?'} ${r.client.padEnd(14)} ${C.dim}${r.detail}${C.reset}\n`);
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
const installed = results.filter((r) => r.status === 'installed').length;
|
|
616
|
+
process.stdout.write(
|
|
617
|
+
`\n${C.bold}${installed} client(s) wired.${C.reset} Restart the client to pick up the server.\n`
|
|
618
|
+
);
|
|
619
|
+
process.stdout.write(
|
|
620
|
+
`\n${C.dim}For any client not listed (Antigravity, Gemini CLI, JetBrains, …), paste this into its MCP config:${C.reset}\n`
|
|
621
|
+
);
|
|
622
|
+
process.stdout.write(paste + '\n');
|
|
623
|
+
if (!flags.local) {
|
|
624
|
+
process.stdout.write(
|
|
625
|
+
`\n${C.dim}Tip: add --local to point clients at this checkout instead of npx (for dev/testing before publish).${C.reset}\n`
|
|
626
|
+
);
|
|
627
|
+
}
|
|
628
|
+
return 0;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
function cmdBadge(dir, flags) {
|
|
632
|
+
const badge = require('../src/badge');
|
|
633
|
+
const result = scan(dir, { deps: flags.deps !== false && !flags['no-deps'] });
|
|
634
|
+
const date = new Date().toISOString().slice(0, 10);
|
|
635
|
+
|
|
636
|
+
if (!badge.isEligible(result)) {
|
|
637
|
+
process.stderr.write(
|
|
638
|
+
`${C.yellow}No badge awarded.${C.reset} A badge requires zero critical and zero high findings.\n` +
|
|
639
|
+
`Current grade ${result.grade}: ${result.counts.critical} critical, ${result.counts.high} high. ` +
|
|
640
|
+
`Fix those, then run 'vibeguard badge' again.\n`
|
|
641
|
+
);
|
|
642
|
+
return 1;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
const svgPath = path.join(path.resolve(dir), 'vibeguard-badge.svg');
|
|
646
|
+
fs.writeFileSync(svgPath, badge.svg(result, date));
|
|
647
|
+
const md = badge.markdown(result, date, './vibeguard-badge.svg');
|
|
648
|
+
|
|
649
|
+
if (flags.json) {
|
|
650
|
+
process.stdout.write(
|
|
651
|
+
JSON.stringify({ eligible: true, date, grade: result.grade, svg: svgPath, markdown: md }, null, 2) + '\n'
|
|
652
|
+
);
|
|
653
|
+
return 0;
|
|
654
|
+
}
|
|
655
|
+
process.stdout.write(
|
|
656
|
+
`${C.green}Badge awarded${C.reset} — ${badge.passLabel(date)}.\n` +
|
|
657
|
+
`SVG written to ${svgPath}\n\n` +
|
|
658
|
+
`Add to your README:\n ${md}\n\n` +
|
|
659
|
+
`${C.dim}This attests the project passed VibeGuard's checks on ${date}. It is not a` +
|
|
660
|
+
` guarantee of safety.${C.reset}\n`
|
|
661
|
+
);
|
|
662
|
+
return 0;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
function cmdInitCi(dir) {
|
|
666
|
+
const root = path.resolve(dir);
|
|
667
|
+
const wfDir = path.join(root, '.github', 'workflows');
|
|
668
|
+
fs.mkdirSync(wfDir, { recursive: true });
|
|
669
|
+
const dest = path.join(wfDir, 'vibeguard.yml');
|
|
670
|
+
if (fs.existsSync(dest)) {
|
|
671
|
+
process.stderr.write(`${dest} already exists — not overwriting.\n`);
|
|
672
|
+
return 2;
|
|
673
|
+
}
|
|
674
|
+
const src = path.join(__dirname, '..', 'ci', 'vibeguard.yml');
|
|
675
|
+
fs.copyFileSync(src, dest);
|
|
676
|
+
process.stdout.write(
|
|
677
|
+
`${C.green}Wrote GitHub Actions workflow${C.reset} to ${dest}\n` +
|
|
678
|
+
`${C.dim}It uploads SARIF to code scanning and fails the build on CRITICAL findings.${C.reset}\n`
|
|
679
|
+
);
|
|
680
|
+
return 0;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
function cmdInstallHook(dir) {
|
|
684
|
+
const root = path.resolve(dir);
|
|
685
|
+
const gitDir = path.join(root, '.git');
|
|
686
|
+
if (!fs.existsSync(gitDir)) {
|
|
687
|
+
process.stderr.write(
|
|
688
|
+
`error: ${root} is not a git repository (no .git). Run 'git init' first.\n`
|
|
689
|
+
);
|
|
690
|
+
return 2;
|
|
691
|
+
}
|
|
692
|
+
const hooksDir = path.join(gitDir, 'hooks');
|
|
693
|
+
fs.mkdirSync(hooksDir, { recursive: true });
|
|
694
|
+
const dest = path.join(hooksDir, 'pre-commit');
|
|
695
|
+
|
|
696
|
+
if (fs.existsSync(dest)) {
|
|
697
|
+
const existing = fs.readFileSync(dest, 'utf8');
|
|
698
|
+
if (!existing.includes('VibeGuard pre-commit hook')) {
|
|
699
|
+
process.stderr.write(
|
|
700
|
+
`A pre-commit hook already exists at ${dest}.\n` +
|
|
701
|
+
`Refusing to overwrite it. Merge in hooks/pre-commit manually.\n`
|
|
702
|
+
);
|
|
703
|
+
return 2;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
// Bake in the absolute path to THIS CLI so the hook always finds the scanner,
|
|
708
|
+
// and fail LOUD (block) if it can't run — a security hook must never pass
|
|
709
|
+
// silently just because the tool is missing.
|
|
710
|
+
const cliPath = path.resolve(__dirname, 'cli.js');
|
|
711
|
+
const nodeBin = process.execPath;
|
|
712
|
+
const hook = `#!/usr/bin/env sh
|
|
713
|
+
# VibeGuard pre-commit hook (generated by 'vibeguard install-hook').
|
|
714
|
+
# Blocks the commit ONLY when a CRITICAL issue is found. Bypass: git commit --no-verify
|
|
715
|
+
NODE="${nodeBin.split('\\').join('/')}"
|
|
716
|
+
CLI="${cliPath.split('\\').join('/')}"
|
|
717
|
+
if [ ! -x "$NODE" ]; then NODE=node; fi
|
|
718
|
+
if [ ! -f "$CLI" ]; then
|
|
719
|
+
echo "VibeGuard: scanner not found at $CLI — commit blocked (fail-closed). Reinstall the hook."
|
|
720
|
+
exit 1
|
|
721
|
+
fi
|
|
722
|
+
"$NODE" "$CLI" scan . --precommit
|
|
723
|
+
STATUS=$?
|
|
724
|
+
if [ "$STATUS" -eq 2 ]; then
|
|
725
|
+
echo ""
|
|
726
|
+
echo "VibeGuard: commit blocked — CRITICAL security issue(s) found above."
|
|
727
|
+
echo "Fix them, or bypass intentionally with: git commit --no-verify"
|
|
728
|
+
exit 1
|
|
729
|
+
fi
|
|
730
|
+
exit 0
|
|
731
|
+
`;
|
|
732
|
+
fs.writeFileSync(dest, hook);
|
|
733
|
+
try {
|
|
734
|
+
fs.chmodSync(dest, 0o755);
|
|
735
|
+
} catch {
|
|
736
|
+
/* chmod is a no-op / may fail on Windows — git uses core.fileMode there */
|
|
737
|
+
}
|
|
738
|
+
process.stdout.write(
|
|
739
|
+
`${C.green}Installed pre-commit hook${C.reset} at ${dest}\n` +
|
|
740
|
+
`${C.dim}It blocks commits only when a CRITICAL issue is found.${C.reset}\n`
|
|
741
|
+
);
|
|
742
|
+
return 0;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
async function main() {
|
|
746
|
+
const argv = process.argv.slice(2);
|
|
747
|
+
const args = parseArgs(argv);
|
|
748
|
+
const flags = args.flags;
|
|
749
|
+
|
|
750
|
+
if (flags.help || flags.h || args._[0] === 'help') {
|
|
751
|
+
printHelp();
|
|
752
|
+
process.exit(0);
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
const cmd = args._[0] || 'scan';
|
|
756
|
+
const dir = args._[1] || '.';
|
|
757
|
+
|
|
758
|
+
const noDirCmds = new Set(['url', 'rules', 'explain', 'secure-prompt', 'redact', 'detect-pii', 'firewall', 'exfil-check', 'dep-firewall', 'sandbox', 'output-guard', 'vault', 'audit-trail', 'why', 'guard', 'install-shell-hook', 'uninstall-shell-hook', 'auto-start', 'auto-stop', 'auto-status', 'auto']);
|
|
759
|
+
if (!noDirCmds.has(cmd) && !fs.existsSync(dir)) {
|
|
760
|
+
process.stderr.write(`error: directory not found: ${dir}\n`);
|
|
761
|
+
process.exit(2);
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
// MCP server mode: hand off to the server (it runs until stdin closes).
|
|
765
|
+
// This is what `npx -y vibeguard mcp` starts inside Claude Code / Cursor / etc.
|
|
766
|
+
if (cmd === 'mcp') {
|
|
767
|
+
require('../src/mcp-server.js');
|
|
768
|
+
return; // do NOT process.exit — the server owns the process lifetime
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
// scan --verify-keys: async provider probing.
|
|
772
|
+
if (cmd === 'scan' && flags['verify-keys']) {
|
|
773
|
+
(async () => {
|
|
774
|
+
const result = scan(dir, { deps: flags.deps !== false && !flags['no-deps'], deep: !!flags.deep });
|
|
775
|
+
try {
|
|
776
|
+
const { verifyKeys } = require('../src/verifykeys');
|
|
777
|
+
const live = await verifyKeys(dir, result.findings);
|
|
778
|
+
if (live > 0 && !flags.json && !flags.sarif) {
|
|
779
|
+
process.stderr.write(`${C.red}${live} key(s) CONFIRMED LIVE.${C.reset}\n`);
|
|
780
|
+
}
|
|
781
|
+
} catch (err) {
|
|
782
|
+
process.stderr.write(`verify-keys error: ${err.message}\n`);
|
|
783
|
+
}
|
|
784
|
+
const { computeGrade } = require('../src/scanner');
|
|
785
|
+
const g = computeGrade(result.findings);
|
|
786
|
+
result.grade = g.grade;
|
|
787
|
+
result.counts = g.counts;
|
|
788
|
+
outputResult(result, flags);
|
|
789
|
+
process.exit(result.counts.critical > 0 ? 2 : result.findings.length > 0 ? 1 : 0);
|
|
790
|
+
})().catch((err) => {
|
|
791
|
+
process.stderr.write(`vibeguard error: ${err.message}\n`);
|
|
792
|
+
process.exit(2);
|
|
793
|
+
});
|
|
794
|
+
return;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
// Watch mode (long-running).
|
|
798
|
+
if (cmd === 'watch') {
|
|
799
|
+
Promise.resolve(cmdWatch(dir, flags)).catch((err) => {
|
|
800
|
+
process.stderr.write(`vibeguard error: ${err && err.message ? err.message : err}\n`);
|
|
801
|
+
process.exit(2);
|
|
802
|
+
});
|
|
803
|
+
return;
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
// Async command: live URL scan.
|
|
807
|
+
if (cmd === 'url') {
|
|
808
|
+
cmdUrl(args._[1], flags)
|
|
809
|
+
.then((c) => process.exit(c))
|
|
810
|
+
.catch((err) => {
|
|
811
|
+
process.stderr.write(`vibeguard error: ${err && err.message ? err.message : err}\n`);
|
|
812
|
+
process.exit(2);
|
|
813
|
+
});
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
let code = 0;
|
|
818
|
+
try {
|
|
819
|
+
if (cmd === 'scan') code = cmdScan(dir, flags);
|
|
820
|
+
else if (cmd === 'fix') code = cmdFix(dir, flags);
|
|
821
|
+
else if (cmd === 'verify') code = cmdVerify(dir, flags);
|
|
822
|
+
else if (cmd === 'install-hook') code = cmdInstallHook(dir);
|
|
823
|
+
else if (cmd === 'rollback') code = cmdRollback(dir);
|
|
824
|
+
else if (cmd === 'history') code = cmdHistory(dir, flags);
|
|
825
|
+
else if (cmd === 'badge') code = cmdBadge(dir, flags);
|
|
826
|
+
else if (cmd === 'init-ci') code = cmdInitCi(dir);
|
|
827
|
+
else if (cmd === 'install') code = cmdInstall(flags);
|
|
828
|
+
else if (cmd === 'rules') code = cmdRules(flags);
|
|
829
|
+
else if (cmd === 'explain') code = cmdExplain(args._[1], flags);
|
|
830
|
+
else if (cmd === 'doctor') code = cmdDoctor(dir, flags);
|
|
831
|
+
else if (cmd === 'compliance') code = cmdCompliance(dir, flags);
|
|
832
|
+
else if (cmd === 'cve') code = await cmdCve(dir, flags);
|
|
833
|
+
else if (cmd === 'slopsquat') code = await cmdSlopsquat(dir, flags);
|
|
834
|
+
else if (cmd === 'secure-prompt') code = cmdSecurePrompt(args._[1] || '.', flags);
|
|
835
|
+
else if (cmd === 'trace') code = cmdTrace(dir, flags);
|
|
836
|
+
else if (cmd === 'repl') code = await cmdRepl(dir, flags);
|
|
837
|
+
else if (cmd === 'auth-coverage') code = cmdAuthCoverage(dir, flags);
|
|
838
|
+
else if (cmd === 'diff') code = cmdDiff(dir, flags);
|
|
839
|
+
else if (cmd === 'deep-scan') code = await cmdDeepScan(dir, flags);
|
|
840
|
+
else if (cmd === 'html') code = cmdHtml(dir, flags);
|
|
841
|
+
else if (cmd === 'inject-rules') code = cmdInjectRules(dir, flags);
|
|
842
|
+
else if (cmd === 'bench') code = cmdBench(dir, flags);
|
|
843
|
+
else if (cmd === 'hook-post-edit') { require('../src/hook').handlePostEdit(); return; }
|
|
844
|
+
else if (cmd === 'install-hook-post') {
|
|
845
|
+
const r = require('../src/hook').installPostEditHook(dir);
|
|
846
|
+
if (r.installed) {
|
|
847
|
+
process.stdout.write(`\n VibeGuard PostToolUse hook installed in ${r.file}\n\n`);
|
|
848
|
+
process.stdout.write(` VibeGuard will now auto-scan every file Claude edits.\n`);
|
|
849
|
+
process.stdout.write(` If a critical issue is found, you'll see a warning immediately.\n\n`);
|
|
850
|
+
process.stdout.write(` To uninstall: vibeguard uninstall-hook-post\n\n`);
|
|
851
|
+
} else {
|
|
852
|
+
process.stdout.write(`Hook ${r.reason || 'not installed'}\n`);
|
|
853
|
+
}
|
|
854
|
+
code = 0;
|
|
855
|
+
}
|
|
856
|
+
else if (cmd === 'uninstall-hook-post') { const r = require('../src/hook').uninstallPostEditHook(dir); process.stdout.write(r.uninstalled ? 'PostToolUse hook removed.\n' : `Not found: ${r.reason}\n`); code = 0; }
|
|
857
|
+
else if (cmd === 'risk-score') code = cmdRiskScore(dir, flags);
|
|
858
|
+
else if (cmd === 'trend') code = cmdTrend(dir, flags);
|
|
859
|
+
else if (cmd === 'why') code = cmdWhy(dir, args, flags);
|
|
860
|
+
else if (cmd === 'config-check') code = cmdConfigCheck(dir, flags);
|
|
861
|
+
else if (cmd === 'watch') code = cmdWatch(dir, flags);
|
|
862
|
+
else if (cmd === 'dashboard') code = cmdDashboard(dir, flags);
|
|
863
|
+
else if (cmd === 'pr-comment') code = cmdPRComment(dir, flags);
|
|
864
|
+
else if (cmd === 'preset') code = cmdPreset(dir, args, flags);
|
|
865
|
+
else if (cmd === 'privacy-audit') code = cmdPrivacyAudit(dir, flags);
|
|
866
|
+
else if (cmd === 'net-audit') code = cmdNetAudit(dir, flags);
|
|
867
|
+
else if (cmd === 'ai-guard') code = cmdAIGuard(dir, flags);
|
|
868
|
+
else if (cmd === 'privacy-policy') code = cmdPrivacyPolicy(dir, flags);
|
|
869
|
+
else if (cmd === 'csp-generate') code = cmdCSPGenerate(dir, flags);
|
|
870
|
+
else if (cmd === 'firewall') code = cmdFirewall(args, flags);
|
|
871
|
+
else if (cmd === 'agent-guard') code = cmdAgentGuard(dir, flags);
|
|
872
|
+
else if (cmd === 'exfil-check') code = cmdExfilCheck(args, flags);
|
|
873
|
+
else if (cmd === 'dep-firewall') code = cmdDepFirewall(args, flags);
|
|
874
|
+
else if (cmd === 'intercept-test') code = cmdInterceptTest(dir, args, flags);
|
|
875
|
+
else if (cmd === 'output-guard') code = cmdOutputGuard(args, flags);
|
|
876
|
+
else if (cmd === 'env-lock') code = cmdEnvLock(dir, flags);
|
|
877
|
+
else if (cmd === 'self-check') code = cmdSelfCheck(dir, flags);
|
|
878
|
+
else if (cmd === 'sandbox') code = cmdSandbox(args, flags);
|
|
879
|
+
else if (cmd === 'behavior') code = cmdBehavior(dir, flags);
|
|
880
|
+
else if (cmd === 'supply-firewall') code = cmdSupplyFirewall(dir, flags);
|
|
881
|
+
else if (cmd === 'vault') code = cmdVault(args, flags);
|
|
882
|
+
else if (cmd === 'audit-trail') code = cmdAuditTrail(args, flags);
|
|
883
|
+
else if (cmd === 'pre-deploy') code = cmdPreDeploy(dir, flags);
|
|
884
|
+
else if (cmd === 'redact') code = cmdRedact(args, flags);
|
|
885
|
+
else if (cmd === 'detect-pii') code = cmdDetectPII(args, flags);
|
|
886
|
+
else if (cmd === 'guard') code = cmdGuard(args, flags);
|
|
887
|
+
else if (cmd === 'install-shell-hook') code = cmdInstallShellHook(flags);
|
|
888
|
+
else if (cmd === 'uninstall-shell-hook') code = cmdUninstallShellHook(flags);
|
|
889
|
+
else if (cmd === 'auto') code = cmdAutoUnified(dir, args, flags);
|
|
890
|
+
else if (cmd === 'auto-start') code = cmdAutoStart(dir, flags);
|
|
891
|
+
else if (cmd === 'auto-stop') code = cmdAutoStop(dir, flags);
|
|
892
|
+
else if (cmd === 'auto-status') code = cmdAutoStatus(dir, flags);
|
|
893
|
+
else {
|
|
894
|
+
process.stderr.write(`unknown command: ${cmd}\n`);
|
|
895
|
+
printHelp();
|
|
896
|
+
code = 2;
|
|
897
|
+
}
|
|
898
|
+
} catch (err) {
|
|
899
|
+
process.stderr.write(`vibeguard error: ${err && err.message ? err.message : err}\n`);
|
|
900
|
+
code = 2;
|
|
901
|
+
}
|
|
902
|
+
process.exit(code);
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
function generatePatch(findings) {
|
|
906
|
+
const lines = [];
|
|
907
|
+
for (const f of findings) {
|
|
908
|
+
if (!f.fix) continue;
|
|
909
|
+
lines.push(`--- a/${f.file}`);
|
|
910
|
+
lines.push(`+++ b/${f.file}`);
|
|
911
|
+
lines.push(`@@ -${f.line},1 +${f.line},1 @@`);
|
|
912
|
+
lines.push(`- ${f.snippet || ''}`);
|
|
913
|
+
lines.push(`+ # vibeguard: ${f.ruleId} — ${f.fix}`);
|
|
914
|
+
lines.push('');
|
|
915
|
+
}
|
|
916
|
+
return lines.join('\n');
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
// --- NEW COMMAND HANDLERS ---
|
|
920
|
+
|
|
921
|
+
function cmdCompliance(dir, flags) {
|
|
922
|
+
const { scan } = require('../src/scanner');
|
|
923
|
+
const result = scan(dir);
|
|
924
|
+
const { generateComplianceReport } = require('../src/compliance');
|
|
925
|
+
const report = generateComplianceReport(result.findings, flags.framework);
|
|
926
|
+
process.stdout.write(JSON.stringify(report, null, 2) + '\n');
|
|
927
|
+
return 0;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
async function cmdCve(dir, flags) {
|
|
931
|
+
const { scanCVEs } = require('../src/cve-intel');
|
|
932
|
+
const result = await scanCVEs(dir);
|
|
933
|
+
if (flags.json) {
|
|
934
|
+
process.stdout.write(JSON.stringify(result, null, 2) + '\n');
|
|
935
|
+
} else {
|
|
936
|
+
process.stdout.write(`Checked ${result.checked} packages. ${result.findings.length} vulnerabilities.\n`);
|
|
937
|
+
for (const f of result.findings) {
|
|
938
|
+
process.stdout.write(` ${C.red}${f.severity}${C.reset} ${f.title}\n ${f.message}\n ${C.green}fix:${C.reset} ${f.fix}\n\n`);
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
return result.findings.length > 0 ? 1 : 0;
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
async function cmdSlopsquat(dir, flags) {
|
|
945
|
+
const { walk } = require('../src/scanner');
|
|
946
|
+
const files = walk(dir, []);
|
|
947
|
+
const { scanSlopsquat } = require('../src/slopsquat');
|
|
948
|
+
const result = await scanSlopsquat(dir, files);
|
|
949
|
+
if (flags.json) {
|
|
950
|
+
process.stdout.write(JSON.stringify(result, null, 2) + '\n');
|
|
951
|
+
} else {
|
|
952
|
+
process.stdout.write(`Checked ${result.checked} imports. ${result.findings.length} suspicious packages.\n`);
|
|
953
|
+
for (const f of result.findings) {
|
|
954
|
+
process.stdout.write(` ${C.yellow}${f.title}${C.reset}\n ${f.message}\n ${C.green}fix:${C.reset} ${f.fix}\n\n`);
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
return result.findings.length > 0 ? 1 : 0;
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
function cmdSecurePrompt(promptText, flags) {
|
|
961
|
+
if (!promptText || promptText === '.') {
|
|
962
|
+
process.stderr.write('usage: vibeguard secure-prompt "your prompt text here"\n');
|
|
963
|
+
return 2;
|
|
964
|
+
}
|
|
965
|
+
const { analyzePrompt } = require('../src/secure-prompt');
|
|
966
|
+
const result = analyzePrompt(promptText);
|
|
967
|
+
if (flags.json) {
|
|
968
|
+
process.stdout.write(JSON.stringify(result, null, 2) + '\n');
|
|
969
|
+
} else {
|
|
970
|
+
process.stdout.write(
|
|
971
|
+
`${C.bold}Score: ${result.score}/100 — Grade: ${result.grade}${C.reset}\n` +
|
|
972
|
+
`${result.recommendation}\n\n`
|
|
973
|
+
);
|
|
974
|
+
for (const f of result.findings) {
|
|
975
|
+
const sev = f.risk === 'critical' ? C.red : f.risk === 'high' ? C.red : f.risk === 'medium' ? C.yellow : C.blue;
|
|
976
|
+
process.stdout.write(` ${sev}[${f.risk}]${C.reset} ${f.category}: ${f.message}\n ${C.green}fix:${C.reset} ${f.fix}\n\n`);
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
return result.score < 60 ? 1 : 0;
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
function cmdTrace(dir, flags) {
|
|
983
|
+
const { scan } = require('../src/scanner');
|
|
984
|
+
const result = scan(dir);
|
|
985
|
+
const { trace } = require('../src/trace');
|
|
986
|
+
const tr = trace(dir, result.findings);
|
|
987
|
+
if (flags.json) {
|
|
988
|
+
process.stdout.write(JSON.stringify(tr, null, 2) + '\n');
|
|
989
|
+
} else {
|
|
990
|
+
process.stdout.write(`Sessions found: ${tr.sessions}\n`);
|
|
991
|
+
if (tr.behavior) {
|
|
992
|
+
process.stdout.write(`Behavior risk: ${tr.behavior.risk}\n`);
|
|
993
|
+
process.stdout.write(`Approval ratio: ${tr.behavior.delegationRatio}\n`);
|
|
994
|
+
process.stdout.write(`Behaviors: ${tr.behavior.behaviors.length}\n\n`);
|
|
995
|
+
for (const b of tr.behavior.behaviors) {
|
|
996
|
+
process.stdout.write(` [${b.id}] ${b.message}\n`);
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
if (tr.traces.length > 0) {
|
|
1000
|
+
process.stdout.write(`\nTraces (${tr.traces.length}):\n`);
|
|
1001
|
+
for (const t of tr.traces) {
|
|
1002
|
+
process.stdout.write(` ${t.finding} → ${t.matches.length} prompt match(es)\n`);
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
return 0;
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
async function cmdRepl(dir, flags) {
|
|
1010
|
+
const { startRepl } = require('../src/repl');
|
|
1011
|
+
return await startRepl(dir, flags);
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
function cmdAuthCoverage(dir, flags) {
|
|
1015
|
+
const { walk } = require('../src/scanner');
|
|
1016
|
+
const files = walk(dir, []);
|
|
1017
|
+
const { buildAuthCoverage } = require('../src/engine');
|
|
1018
|
+
const coverage = buildAuthCoverage(dir, files);
|
|
1019
|
+
if (flags.json) {
|
|
1020
|
+
process.stdout.write(JSON.stringify(coverage, null, 2) + '\n');
|
|
1021
|
+
} else {
|
|
1022
|
+
process.stdout.write(`Auth coverage: ${coverage.coverage}% (${coverage.protectedRoutes}/${coverage.totalRoutes} routes protected)\n`);
|
|
1023
|
+
if (coverage.unprotectedRoutes.length > 0) {
|
|
1024
|
+
process.stdout.write(`\n${C.red}Unprotected API routes:${C.reset}\n`);
|
|
1025
|
+
for (const r of coverage.unprotectedRoutes) {
|
|
1026
|
+
process.stdout.write(` ${r.file}:${r.line} — ${r.path}\n`);
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
return coverage.unprotectedRoutes.length > 0 ? 1 : 0;
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
function cmdDiff(dir, flags) {
|
|
1034
|
+
const { scan } = require('../src/scanner');
|
|
1035
|
+
const { verify } = require('../src/verify');
|
|
1036
|
+
const res = verify(dir);
|
|
1037
|
+
if (!res.hasBaseline) {
|
|
1038
|
+
process.stderr.write('No baseline. Run "vibeguard scan --save-baseline" first.\n');
|
|
1039
|
+
return 2;
|
|
1040
|
+
}
|
|
1041
|
+
if (flags.json) {
|
|
1042
|
+
process.stdout.write(JSON.stringify({
|
|
1043
|
+
resolved: res.resolved.map(f => ({ file: f.file, line: f.line, ruleId: f.ruleId })),
|
|
1044
|
+
remaining: res.remaining.map(f => ({ file: f.file, line: f.line, ruleId: f.ruleId })),
|
|
1045
|
+
introduced: res.introduced.map(f => ({ file: f.file, line: f.line, ruleId: f.ruleId })),
|
|
1046
|
+
}, null, 2) + '\n');
|
|
1047
|
+
} else {
|
|
1048
|
+
process.stdout.write(`${res.resolved.length} resolved, ${res.remaining.length} remaining, ${res.introduced.length} new.\n\n`);
|
|
1049
|
+
for (const f of res.resolved) process.stdout.write(` ${C.green}RESOLVED${C.reset} ${f.file}:${f.line} [${f.ruleId}]\n`);
|
|
1050
|
+
for (const f of res.introduced) process.stdout.write(` ${C.red}NEW${C.reset} ${f.file}:${f.line} [${f.ruleId}]\n`);
|
|
1051
|
+
for (const f of res.remaining) process.stdout.write(` ${C.yellow}REMAINING${C.reset} ${f.file}:${f.line} [${f.ruleId}]\n`);
|
|
1052
|
+
}
|
|
1053
|
+
return res.introduced.length > 0 ? 1 : 0;
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
async function cmdDeepScan(dir, flags) {
|
|
1057
|
+
const { scan } = require('../src/scanner');
|
|
1058
|
+
const { walk } = require('../src/scanner');
|
|
1059
|
+
const result = scan(dir);
|
|
1060
|
+
const files = walk(dir, []);
|
|
1061
|
+
const { buildAuthCoverage } = require('../src/engine');
|
|
1062
|
+
const auth = buildAuthCoverage(dir, files);
|
|
1063
|
+
const { trace } = require('../src/trace');
|
|
1064
|
+
const tr = trace(dir, result.findings);
|
|
1065
|
+
let cveFindings = [];
|
|
1066
|
+
try {
|
|
1067
|
+
const { scanCVEs } = require('../src/cve-intel');
|
|
1068
|
+
const cveRes = await scanCVEs(dir);
|
|
1069
|
+
cveFindings = cveRes.findings;
|
|
1070
|
+
} catch {}
|
|
1071
|
+
const payload = {
|
|
1072
|
+
scan: { grade: result.grade, counts: result.counts, findings: result.findings.length },
|
|
1073
|
+
authCoverage: auth,
|
|
1074
|
+
cveFindings: cveFindings.length,
|
|
1075
|
+
behaviorTrace: tr.behavior,
|
|
1076
|
+
hotspots: [...new Set(result.findings.filter(f => /auth|payment|admin|upload|webhook/i.test(f.file)).map(f => f.file))].slice(0, 20),
|
|
1077
|
+
};
|
|
1078
|
+
if (flags.json) {
|
|
1079
|
+
process.stdout.write(JSON.stringify(payload, null, 2) + '\n');
|
|
1080
|
+
} else {
|
|
1081
|
+
process.stdout.write(`${C.bold}Deep Scan Report${C.reset}\n`);
|
|
1082
|
+
process.stdout.write(`Grade: ${result.grade} — ${result.findings.length} findings\n`);
|
|
1083
|
+
process.stdout.write(`Auth coverage: ${auth.coverage}%\n`);
|
|
1084
|
+
process.stdout.write(`CVE findings: ${cveFindings.length}\n`);
|
|
1085
|
+
process.stdout.write(`Behavior risk: ${tr.behavior ? tr.behavior.risk : 'unknown'}\n`);
|
|
1086
|
+
if (tr.behavior && tr.behavior.behaviors.length > 0) {
|
|
1087
|
+
process.stdout.write(`\n${C.yellow}Risky behaviors:${C.reset}\n`);
|
|
1088
|
+
for (const b of tr.behavior.behaviors) process.stdout.write(` [${b.id}] ${b.message}\n`);
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
return result.findings.length > 0 ? 1 : 0;
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
function cmdHtml(dir, flags) {
|
|
1095
|
+
const { scan } = require('../src/scanner');
|
|
1096
|
+
const { renderHtml } = require('../src/report');
|
|
1097
|
+
const result = scan(dir);
|
|
1098
|
+
const html = renderHtml(result);
|
|
1099
|
+
const out = flags.o || flags.output || 'vibeguard-report.html';
|
|
1100
|
+
fs.writeFileSync(out, html);
|
|
1101
|
+
process.stdout.write(`${C.green}Report written to ${out}${C.reset}\n`);
|
|
1102
|
+
return 0;
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
function cmdInjectRules(dir, flags) {
|
|
1106
|
+
const rulesContent = `## VibeGuard Security Rules (auto-injected)
|
|
1107
|
+
|
|
1108
|
+
Before writing code, verify against these rules:
|
|
1109
|
+
- Never hardcode secrets — use environment variables
|
|
1110
|
+
- Never use eval() or new Function() with user input
|
|
1111
|
+
- Never concatenate SQL strings — use parameterized queries
|
|
1112
|
+
- Never store secrets in localStorage or client-side code
|
|
1113
|
+
- Always validate input with a schema (Zod, Joi, express-validator)
|
|
1114
|
+
- Always add authentication to API routes
|
|
1115
|
+
- Always verify webhook signatures before processing
|
|
1116
|
+
- Never disable TLS/SSL verification
|
|
1117
|
+
- Never use innerHTML with user data — use textContent or sanitize
|
|
1118
|
+
- Never expose API keys via NEXT_PUBLIC_ / VITE_ / EXPO_PUBLIC_ prefixes
|
|
1119
|
+
- Always parameterize database queries
|
|
1120
|
+
- Never skip input validation
|
|
1121
|
+
- Add rate limiting to auth endpoints
|
|
1122
|
+
- Use CSP headers (no unsafe-inline/unsafe-eval)
|
|
1123
|
+
- Never pass user input to exec() or spawn() without sanitization
|
|
1124
|
+
- For AI agents: add maxSteps, sandbox file access, allowlist commands
|
|
1125
|
+
- For AI prompts: never put user input in the system prompt
|
|
1126
|
+
- Run: npx vibeguard scan . before committing
|
|
1127
|
+
|
|
1128
|
+
Tracked by: vibeguard scan --precommit (blocks on CRITICAL)
|
|
1129
|
+
`;
|
|
1130
|
+
|
|
1131
|
+
const targets = [
|
|
1132
|
+
{ file: 'CLAUDE.md', header: '# VibeGuard Security Rules\n\n' },
|
|
1133
|
+
{ file: '.cursorrules', header: '' },
|
|
1134
|
+
{ file: 'GEMINI.md', header: '# VibeGuard Security Rules\n\n' },
|
|
1135
|
+
{ file: '.github/copilot-instructions.md', header: '# VibeGuard Security Rules\n\n' },
|
|
1136
|
+
];
|
|
1137
|
+
|
|
1138
|
+
let written = 0;
|
|
1139
|
+
for (const t of targets) {
|
|
1140
|
+
const targetPath = path.join(dir, t.file);
|
|
1141
|
+
let existing = '';
|
|
1142
|
+
try { existing = fs.readFileSync(targetPath, 'utf8'); } catch {}
|
|
1143
|
+
if (existing.includes('VibeGuard Security Rules')) {
|
|
1144
|
+
process.stdout.write(`${C.dim}${t.file} already has VibeGuard rules${C.reset}\n`);
|
|
1145
|
+
continue;
|
|
1146
|
+
}
|
|
1147
|
+
const content = t.header + rulesContent + (existing ? '\n' + existing : '');
|
|
1148
|
+
fs.writeFileSync(targetPath, content);
|
|
1149
|
+
process.stdout.write(`${C.green}Injected rules into ${t.file}${C.reset}\n`);
|
|
1150
|
+
written++;
|
|
1151
|
+
}
|
|
1152
|
+
if (written === 0) {
|
|
1153
|
+
process.stdout.write(`${C.dim}All target files already have VibeGuard rules.${C.reset}\n`);
|
|
1154
|
+
}
|
|
1155
|
+
return 0;
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
function cmdBench(dir, flags) {
|
|
1159
|
+
const { scan } = require('../src/scanner');
|
|
1160
|
+
const { walk } = require('../src/scanner');
|
|
1161
|
+
const start = Date.now();
|
|
1162
|
+
const result = scan(dir);
|
|
1163
|
+
const elapsed = Date.now() - start;
|
|
1164
|
+
const files = walk(dir, []);
|
|
1165
|
+
const rules = require('../src/rules').allRules().length;
|
|
1166
|
+
process.stdout.write(
|
|
1167
|
+
`${C.bold}VibeGuard Benchmark${C.reset}\n` +
|
|
1168
|
+
` Files scanned: ${result.scannedFiles}\n` +
|
|
1169
|
+
` Rules active: ${rules}\n` +
|
|
1170
|
+
` Findings: ${result.findings.length}\n` +
|
|
1171
|
+
` Grade: ${result.grade}\n` +
|
|
1172
|
+
` Time: ${elapsed}ms\n` +
|
|
1173
|
+
` Throughput: ${Math.round(result.scannedFiles / (elapsed / 1000))} files/sec\n` +
|
|
1174
|
+
` Per-file: ${Math.round(elapsed / result.scannedFiles)}ms/file\n`
|
|
1175
|
+
);
|
|
1176
|
+
return 0;
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
function cmdPrivacyAudit(dir, flags) {
|
|
1180
|
+
const { walk } = require('../src/scanner');
|
|
1181
|
+
const { auditPrivacy, renderPrivacyReport } = require('../src/privacy-audit');
|
|
1182
|
+
const files = walk(dir, []);
|
|
1183
|
+
const inventory = auditPrivacy(dir, files);
|
|
1184
|
+
process.stdout.write(renderPrivacyReport(inventory) + '\n');
|
|
1185
|
+
return inventory.risks.filter(r => r.severity === 'high').length > 0 ? 1 : 0;
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
function cmdNetAudit(dir, flags) {
|
|
1189
|
+
const { walk } = require('../src/scanner');
|
|
1190
|
+
const { auditNetwork, renderNetworkReport } = require('../src/net-audit');
|
|
1191
|
+
const files = walk(dir, []);
|
|
1192
|
+
const result = auditNetwork(dir, files);
|
|
1193
|
+
process.stdout.write(renderNetworkReport(result) + '\n');
|
|
1194
|
+
return result.summary.suspiciousDomains > 0 ? 1 : 0;
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
function cmdAIGuard(dir, flags) {
|
|
1198
|
+
const { walk } = require('../src/scanner');
|
|
1199
|
+
const { auditAIData, renderAIGuardReport } = require('../src/ai-guard');
|
|
1200
|
+
const files = walk(dir, []);
|
|
1201
|
+
const result = auditAIData(dir, files);
|
|
1202
|
+
process.stdout.write(renderAIGuardReport(result) + '\n');
|
|
1203
|
+
return result.summary.criticalRisk > 0 ? 1 : 0;
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
function cmdPrivacyPolicy(dir, flags) {
|
|
1207
|
+
const { walk } = require('../src/scanner');
|
|
1208
|
+
const { generatePrivacyPolicy } = require('../src/policy-gen');
|
|
1209
|
+
const files = walk(dir, []);
|
|
1210
|
+
const policy = generatePrivacyPolicy(dir, files);
|
|
1211
|
+
process.stdout.write(policy + '\n');
|
|
1212
|
+
return 0;
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
function cmdCSPGenerate(dir, flags) {
|
|
1216
|
+
const { walk } = require('../src/scanner');
|
|
1217
|
+
const { generateCSP } = require('../src/policy-gen');
|
|
1218
|
+
const files = walk(dir, []);
|
|
1219
|
+
const result = generateCSP(dir, files);
|
|
1220
|
+
process.stdout.write(`${C.bold}Content-Security-Policy${C.reset}\n\n`);
|
|
1221
|
+
process.stdout.write(`${C.dim}Header value:${C.reset}\n`);
|
|
1222
|
+
process.stdout.write(result.csp + '\n\n');
|
|
1223
|
+
process.stdout.write(`${C.dim}Express/Helmet config:${C.reset}\n`);
|
|
1224
|
+
process.stdout.write(result.helmet + '\n\n');
|
|
1225
|
+
if (result.warnings.length > 0) {
|
|
1226
|
+
process.stdout.write(`${C.yellow}Warnings:${C.reset}\n`);
|
|
1227
|
+
for (const w of result.warnings) process.stdout.write(` ${C.yellow}!${C.reset} ${w}\n`);
|
|
1228
|
+
}
|
|
1229
|
+
return 0;
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
function cmdFirewall(args, flags) {
|
|
1233
|
+
const prompt = (args._ || args || []).slice(1).join(' ');
|
|
1234
|
+
if (!prompt) { process.stderr.write('Usage: vibeguard firewall <prompt>\n'); return 1; }
|
|
1235
|
+
const { inspectPrompt, renderFirewallReport } = require('../src/firewall');
|
|
1236
|
+
const verdict = inspectPrompt(prompt);
|
|
1237
|
+
process.stdout.write(renderFirewallReport(verdict) + '\n');
|
|
1238
|
+
return verdict.action === 'block' ? 1 : 0;
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
function cmdAgentGuard(dir, flags) {
|
|
1242
|
+
const { AGENT_CONSTRAINTS } = require('../src/firewall');
|
|
1243
|
+
const C2 = { red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m', dim: '\x1b[2m', bold: '\x1b[1m', reset: '\x1b[0m' };
|
|
1244
|
+
process.stdout.write(`${C2.bold}VibeGuard Agent Guard${C.reset}\n`);
|
|
1245
|
+
process.stdout.write(`${C2.dim}${'─'.repeat(60)}${C.reset}\n\n`);
|
|
1246
|
+
process.stdout.write(`${C2.bold}Blocked Paths${C.reset}\n`);
|
|
1247
|
+
for (const p of AGENT_CONSTRAINTS.blockedPaths) process.stdout.write(` ${C2.red}✗${C.reset} ${p}\n`);
|
|
1248
|
+
process.stdout.write(`\n${C2.bold}Blocked Commands${C.reset}\n`);
|
|
1249
|
+
for (const c of AGENT_CONSTRAINTS.blockedCommands) process.stdout.write(` ${C2.red}✗${C.reset} ${c}\n`);
|
|
1250
|
+
process.stdout.write(`\n${C2.bold}Blocked Domains${C.reset}\n`);
|
|
1251
|
+
for (const d of AGENT_CONSTRAINTS.blockedDomains) process.stdout.write(` ${C2.red}✗${C.reset} ${d}\n`);
|
|
1252
|
+
process.stdout.write(`\n${C2.bold}Resource Limits${C.reset}\n`);
|
|
1253
|
+
process.stdout.write(` Max file size: ${AGENT_CONSTRAINTS.maxFileSize / 1024 / 1024}MB\n`);
|
|
1254
|
+
process.stdout.write(` Max exec time: ${AGENT_CONSTRAINTS.maxExecTime / 1000}s\n`);
|
|
1255
|
+
process.stdout.write(`\n${C2.dim}Use MCP tool 'agent_guard' to check specific actions.${C.reset}\n`);
|
|
1256
|
+
return 0;
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
function cmdExfilCheck(args, flags) {
|
|
1260
|
+
const data = (args._ || args || []).slice(1).join(' ');
|
|
1261
|
+
if (!data) { process.stderr.write('Usage: vibeguard exfil-check <data>\n'); return 1; }
|
|
1262
|
+
const { checkExfiltration } = require('../src/firewall');
|
|
1263
|
+
const result = checkExfiltration(data);
|
|
1264
|
+
const C2 = { red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m', dim: '\x1b[2m', bold: '\x1b[1m', reset: '\x1b[0m' };
|
|
1265
|
+
process.stdout.write(`${C2.bold}VibeGuard Exfiltration Firewall${C.reset}\n`);
|
|
1266
|
+
process.stdout.write(`${C2.dim}${'─'.repeat(60)}${C.reset}\n\n`);
|
|
1267
|
+
if (result.allowed) {
|
|
1268
|
+
process.stdout.write(` ${C2.green}✓ Data is safe to send${C.reset}\n`);
|
|
1269
|
+
} else {
|
|
1270
|
+
process.stdout.write(` ${C2.red}✗ BLOCKED${C.reset}\n\n`);
|
|
1271
|
+
for (const r of result.risks) {
|
|
1272
|
+
const sc = r.severity === 'critical' ? C2.red : C2.yellow;
|
|
1273
|
+
process.stdout.write(` ${sc}[${r.severity}]${C.reset} ${r.message}\n`);
|
|
1274
|
+
}
|
|
1275
|
+
if (result.sanitizedData !== data) {
|
|
1276
|
+
process.stdout.write(`\n${C2.dim}Sanitized version:${C.reset}\n ${result.sanitizedData.slice(0, 200)}\n`);
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
return result.allowed ? 0 : 1;
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
function cmdDepFirewall(args, flags) {
|
|
1283
|
+
const pkg = (args._ || args || [])[1] || (args[0] || null);
|
|
1284
|
+
if (!pkg) { process.stderr.write('Usage: vibeguard dep-firewall <package-name>\n'); return 1; }
|
|
1285
|
+
const { checkPackage } = require('../src/firewall');
|
|
1286
|
+
const result = checkPackage(pkg);
|
|
1287
|
+
const C2 = { red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m', dim: '\x1b[2m', bold: '\x1b[1m', reset: '\x1b[0m' };
|
|
1288
|
+
process.stdout.write(`${C2.bold}VibeGuard Dependency Firewall${C.reset}\n`);
|
|
1289
|
+
process.stdout.write(`${C2.dim}${'─'.repeat(60)}${C.reset}\n\n`);
|
|
1290
|
+
process.stdout.write(` Package: ${pkg}\n`);
|
|
1291
|
+
if (result.allowed && result.risks.length === 0) {
|
|
1292
|
+
process.stdout.write(` ${C2.green}✓ No risks detected${C.reset}\n`);
|
|
1293
|
+
} else if (result.allowed) {
|
|
1294
|
+
process.stdout.write(` ${C2.yellow}⚠ Warnings${C.reset}\n`);
|
|
1295
|
+
for (const r of result.risks) {
|
|
1296
|
+
const sc = r.severity === 'high' ? C2.yellow : C2.dim;
|
|
1297
|
+
process.stdout.write(` ${sc}[${r.severity}]${C.reset} ${r.message}\n`);
|
|
1298
|
+
}
|
|
1299
|
+
} else {
|
|
1300
|
+
process.stdout.write(` ${C2.red}✗ BLOCKED${C.reset}\n\n`);
|
|
1301
|
+
for (const r of result.risks) {
|
|
1302
|
+
const sc = r.severity === 'critical' ? C2.red : C2.yellow;
|
|
1303
|
+
process.stdout.write(` ${sc}[${r.severity}]${Creset} ${r.message}\n`);
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
return result.allowed ? 0 : 1;
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
function cmdInterceptTest(dir, args, flags) {
|
|
1310
|
+
const C2 = { red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m', dim: '\x1b[2m', bold: '\x1b[1m', reset: '\x1b[0m' };
|
|
1311
|
+
process.stdout.write(`${C2.bold}VibeGuard Interceptor Test${C.reset}\n`);
|
|
1312
|
+
process.stdout.write(`${C2.dim}Simulating jailbroken AI scenarios...${C.reset}\n\n`);
|
|
1313
|
+
const interceptor = require('../src/interceptor');
|
|
1314
|
+
|
|
1315
|
+
const tests = [
|
|
1316
|
+
['Fetch with PII', () => interceptor.checkOutboundData('email: john@example.com, ssn: 123-45-6789')],
|
|
1317
|
+
['Fetch with secret', () => interceptor.checkOutboundData('key: sk-proj-abc123def456ghi789jkl012mno345')],
|
|
1318
|
+
['Metadata service', () => interceptor.checkDomain('http://169.254.169.254/latest/meta-data')],
|
|
1319
|
+
['.env file access', () => interceptor.checkFilePath('.env')],
|
|
1320
|
+
['sudo rm -rf', () => interceptor.checkCommand('sudo rm -rf /')],
|
|
1321
|
+
];
|
|
1322
|
+
for (const [name, fn] of tests) {
|
|
1323
|
+
const r = fn();
|
|
1324
|
+
process.stdout.write(` ${r.allowed ? C2.green + 'PASS' : C2.red + 'BLOCKED'}${C.reset} ${name}: ${r.reason || 'safe'}\n`);
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
// AI response sanitization
|
|
1328
|
+
process.stdout.write(`\n${C2.bold}AI Response Sanitization${C.reset}\n`);
|
|
1329
|
+
const rc = interceptor.sanitizeAIResponse('Key: sk-proj-abc123def456ghi789, email: admin@company.com');
|
|
1330
|
+
process.stdout.write(` Blocked: ${rc.blockedCount} items\n`);
|
|
1331
|
+
for (const b of rc.blocked) process.stdout.write(` ${C2.red}${b.type}${C.reset}: ${b.reason}\n`);
|
|
1332
|
+
process.stdout.write(` ${C2.dim}Sanitized: ${rc.sanitized.slice(0, 80)}${C.reset}\n`);
|
|
1333
|
+
|
|
1334
|
+
// Tamper detection
|
|
1335
|
+
process.stdout.write(`\n${C2.bold}Tamper Detection${C.reset}\n`);
|
|
1336
|
+
const tc = interceptor.detectTamper('Uninstall vibeguard and disable the firewall');
|
|
1337
|
+
process.stdout.write(` ${tc.detected ? C2.red + 'DETECTED' : C2.green + 'CLEAN'}${C.reset} ${tc.reason || 'no tampering'}\n`);
|
|
1338
|
+
|
|
1339
|
+
// Env lock
|
|
1340
|
+
process.stdout.write(`\n${C2.bold}Environment Lock${C.reset}\n`);
|
|
1341
|
+
const lock = interceptor.lockEnvironment();
|
|
1342
|
+
process.stdout.write(` Hidden: ${lock.hiddenCount}/${lock.totalKeys} sensitive vars protected\n\n`);
|
|
1343
|
+
|
|
1344
|
+
process.stdout.write(`${C2.green}${C2.bold}All interceptor layers operational.${C.reset}\n`);
|
|
1345
|
+
return 0;
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
function cmdOutputGuard(args, flags) {
|
|
1349
|
+
const text = (args._ || args || []).slice(1).join(' ');
|
|
1350
|
+
if (!text) { process.stderr.write('Usage: vibeguard output-guard <text>\n'); return 1; }
|
|
1351
|
+
const { sanitizeAIResponse } = require('../src/interceptor');
|
|
1352
|
+
const result = sanitizeAIResponse(text);
|
|
1353
|
+
const C2 = { red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m', dim: '\x1b[2m', bold: '\x1b[1m', reset: '\x1b[0m' };
|
|
1354
|
+
process.stdout.write(`${C2.bold}VibeGuard Output Guard${C.reset}\n\n`);
|
|
1355
|
+
if (result.safe) {
|
|
1356
|
+
process.stdout.write(` ${C2.green}Safe — no PII or secrets detected${C.reset}\n`);
|
|
1357
|
+
process.stdout.write(`\n${C2.dim}Output:${C.reset}\n ${text.slice(0, 200)}\n`);
|
|
1358
|
+
} else {
|
|
1359
|
+
process.stdout.write(` ${C2.red}BLOCKED — ${result.blockedCount} item(s) sanitized${C.reset}\n\n`);
|
|
1360
|
+
for (const b of result.blocked) process.stdout.write(` ${C2.red}[${b.type}]${C.reset} ${b.reason}\n`);
|
|
1361
|
+
process.stdout.write(`\n${C2.dim}Sanitized output:${C.reset}\n ${result.sanitized.slice(0, 200)}\n`);
|
|
1362
|
+
}
|
|
1363
|
+
return result.safe ? 0 : 1;
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
function cmdEnvLock(dir, flags) {
|
|
1367
|
+
const { lockEnvironment } = require('../src/interceptor');
|
|
1368
|
+
const lock = lockEnvironment();
|
|
1369
|
+
const C2 = { red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m', dim: '\x1b[2m', bold: '\x1b[1m', reset: '\x1b[0m' };
|
|
1370
|
+
process.stdout.write(`${C2.bold}VibeGuard Environment Lock${C.reset}\n\n`);
|
|
1371
|
+
process.stdout.write(` Total env vars: ${lock.totalKeys}\n`);
|
|
1372
|
+
process.stdout.write(` Hidden (sensitive): ${C2.red}${lock.hiddenCount}${C.reset}\n`);
|
|
1373
|
+
process.stdout.write(` Visible (safe): ${C2.green}${lock.totalKeys - lock.hiddenCount}${C.reset}\n\n`);
|
|
1374
|
+
if (lock.hiddenKeys.length > 0) {
|
|
1375
|
+
process.stdout.write(`${C2.bold}Protected Variables${C.reset}\n`);
|
|
1376
|
+
for (const key of lock.hiddenKeys.slice(0, 20)) process.stdout.write(` ${C2.red}[HIDDEN]${C.reset} ${key}\n`);
|
|
1377
|
+
if (lock.hiddenKeys.length > 20) process.stdout.write(` ${C2.dim}... and ${lock.hiddenKeys.length - 20} more${C.reset}\n`);
|
|
1378
|
+
}
|
|
1379
|
+
return 0;
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
function cmdSelfCheck(dir, flags) {
|
|
1383
|
+
const C2 = { red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m', dim: '\x1b[2m', bold: '\x1b[1m', reset: '\x1b[0m' };
|
|
1384
|
+
process.stdout.write(`${C2.bold}VibeGuard Self-Check${C.reset}\n\n`);
|
|
1385
|
+
const checks = [];
|
|
1386
|
+
let ok = true;
|
|
1387
|
+
const modules = [
|
|
1388
|
+
['firewall', 'Firewall module'],
|
|
1389
|
+
['interceptor', 'Interceptor module'],
|
|
1390
|
+
['scanner', 'Scanner module'],
|
|
1391
|
+
['pii', 'PII module'],
|
|
1392
|
+
['mcp-server', 'MCP server'],
|
|
1393
|
+
['autofix', 'Auto-fix module'],
|
|
1394
|
+
];
|
|
1395
|
+
for (const [mod, name] of modules) {
|
|
1396
|
+
try { require('../src/' + mod); checks.push(` ${C2.green}PASS${C.reset} ${name} intact`); }
|
|
1397
|
+
catch { checks.push(` ${C2.red}FAIL${C.reset} ${name} corrupted`); ok = false; }
|
|
1398
|
+
}
|
|
1399
|
+
// Rules count
|
|
1400
|
+
try { const r = require('../src/rules'); checks.push(` ${C2.green}PASS${C.reset} Rules loaded (${r.lineRules.length} rules)`); }
|
|
1401
|
+
catch { checks.push(` ${C2.red}FAIL${C.reset} Rules corrupted`); ok = false; }
|
|
1402
|
+
// Config
|
|
1403
|
+
const configPath = path.join(dir, '.vibeguardrc.json');
|
|
1404
|
+
if (fs.existsSync(configPath)) {
|
|
1405
|
+
try { const c = JSON.parse(fs.readFileSync(configPath, 'utf8')); if (c.ignoreRules && c.ignoreRules.length > 10) checks.push(` ${C2.yellow}WARN${C.reset} Many rules ignored (${c.ignoreRules.length})`); else checks.push(` ${C2.green}PASS${C.reset} Config normal`); }
|
|
1406
|
+
catch { checks.push(` ${C2.yellow}WARN${C.reset} Config corrupted`); }
|
|
1407
|
+
} else { checks.push(` ${C2.dim}INFO No config (defaults)${C.reset}`); }
|
|
1408
|
+
// .gitignore
|
|
1409
|
+
const gi = path.join(dir, '.gitignore');
|
|
1410
|
+
if (fs.existsSync(gi) && /\.env/.test(fs.readFileSync(gi, 'utf8'))) checks.push(` ${C2.green}PASS${C.reset} .env in .gitignore`);
|
|
1411
|
+
else { checks.push(` ${C2.red}FAIL${C.reset} .env NOT in .gitignore`); ok = false; }
|
|
1412
|
+
|
|
1413
|
+
for (const c of checks) process.stdout.write(c + '\n');
|
|
1414
|
+
process.stdout.write(`\n${ok ? C2.green + C2.bold + 'VibeGuard is intact.' : C2.yellow + 'Some checks need attention.'}${C.reset}\n`);
|
|
1415
|
+
return ok ? 0 : 1;
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
function cmdSandbox(args, flags) {
|
|
1419
|
+
const code = (args._ || args || []).slice(1).join(' ');
|
|
1420
|
+
if (!code) { process.stderr.write('Usage: vibeguard sandbox <code>\n'); return 1; }
|
|
1421
|
+
const { runInSandbox, renderSandboxReport } = require('../src/sandbox');
|
|
1422
|
+
const result = runInSandbox(code);
|
|
1423
|
+
process.stdout.write(renderSandboxReport(result) + '\n');
|
|
1424
|
+
return result.success ? 0 : 1;
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
function cmdBehavior(dir, flags) {
|
|
1428
|
+
const { createSession, recordEvent, analyzeSession, renderBehaviorReport } = require('../src/behavior');
|
|
1429
|
+
const session = createSession();
|
|
1430
|
+
// Simulate some events based on scan results
|
|
1431
|
+
const result = scan(dir);
|
|
1432
|
+
for (const f of result.findings.slice(0, 50)) {
|
|
1433
|
+
recordEvent(session, f.ruleId.startsWith('secret.') ? 'secret_access' : f.ruleId.includes('injection') ? 'exec' : 'file_read', { ruleId: f.ruleId });
|
|
1434
|
+
}
|
|
1435
|
+
recordEvent(session, 'network', { detail: 'scan complete' });
|
|
1436
|
+
const analysis = analyzeSession(session);
|
|
1437
|
+
process.stdout.write(renderBehaviorReport(analysis) + '\n');
|
|
1438
|
+
return analysis.patternsCount > 0 ? 1 : 0;
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
function cmdSupplyFirewall(dir, flags) {
|
|
1442
|
+
const { auditLockfile, auditPackageJson, renderSupplyReport } = require('../src/supply-firewall');
|
|
1443
|
+
process.stdout.write(`${C.bold}VibeGuard Supply Chain Firewall${C.reset}\n${C.dim}${'─'.repeat(60)}${C.reset}\n\n`);
|
|
1444
|
+
const lockResult = auditLockfile(dir);
|
|
1445
|
+
process.stdout.write(renderSupplyReport(lockResult) + '\n\n');
|
|
1446
|
+
const pkgResult = auditPackageJson(dir);
|
|
1447
|
+
process.stdout.write(renderSupplyReport(pkgResult) + '\n');
|
|
1448
|
+
const hasFindings = (lockResult.findings?.length || 0) + (pkgResult.findings?.length || 0) > 0;
|
|
1449
|
+
return hasFindings ? 1 : 0;
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
function cmdVault(args, flags) {
|
|
1453
|
+
const allArgs = args._ || args || [];
|
|
1454
|
+
const action = allArgs[1] || allArgs[0] || 'list';
|
|
1455
|
+
const vault = require('../src/vault');
|
|
1456
|
+
const C2 = { red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m', dim: '\x1b[2m', bold: '\x1b[1m', reset: '\x1b[0m' };
|
|
1457
|
+
if (action === 'list' || action === 'status') {
|
|
1458
|
+
process.stdout.write(vault.renderVaultReport() + '\n');
|
|
1459
|
+
} else if (action === 'store') {
|
|
1460
|
+
const key = args[1];
|
|
1461
|
+
const value = args[2];
|
|
1462
|
+
if (!key || !value) { process.stderr.write('Usage: vibeguard vault store <KEY> <VALUE>\n'); return 1; }
|
|
1463
|
+
vault.store(key, value);
|
|
1464
|
+
process.stdout.write(`${C2.green}Stored "${key}" in encrypted vault${C.reset}\n`);
|
|
1465
|
+
} else if (action === 'get') {
|
|
1466
|
+
const key = args[1];
|
|
1467
|
+
if (!key) { process.stderr.write('Usage: vibeguard vault get <KEY>\n'); return 1; }
|
|
1468
|
+
const value = vault.get(key, { purpose: 'cli' });
|
|
1469
|
+
process.stdout.write(value ? `${C2.green}Decrypted: ${value.slice(0, 10)}...${C.reset}\n` : `${C2.red}Key not found${C.reset}\n`);
|
|
1470
|
+
} else if (action === 'log') {
|
|
1471
|
+
const log = vault.getAccessLog();
|
|
1472
|
+
process.stdout.write(`${C2.bold}Vault Access Log${C.reset}\n\n`);
|
|
1473
|
+
for (const a of log) process.stdout.write(` ${a.key} — ${a.purpose} — ${new Date(a.timestamp).toISOString()}\n`);
|
|
1474
|
+
} else if (action === 'clear') {
|
|
1475
|
+
vault.clear();
|
|
1476
|
+
process.stdout.write(`${C2.yellow}Vault cleared${C.reset}\n`);
|
|
1477
|
+
} else {
|
|
1478
|
+
process.stderr.write('Usage: vibeguard vault [list|store|get|log|clear]\n');
|
|
1479
|
+
return 1;
|
|
1480
|
+
}
|
|
1481
|
+
return 0;
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
function cmdAuditTrail(args, flags) {
|
|
1485
|
+
const allArgs = args._ || args || [];
|
|
1486
|
+
const action = allArgs[1] || allArgs[0] || 'show';
|
|
1487
|
+
const audit = require('../src/audit-trail');
|
|
1488
|
+
const C2 = { red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m', dim: '\x1b[2m', bold: '\x1b[1m', reset: '\x1b[0m' };
|
|
1489
|
+
if (action === 'show' || action === 'status') {
|
|
1490
|
+
process.stdout.write(audit.renderAuditReport() + '\n');
|
|
1491
|
+
} else if (action === 'export') {
|
|
1492
|
+
const outPath = args[1] || 'vibeguard-audit.json';
|
|
1493
|
+
audit.exportLog(outPath);
|
|
1494
|
+
process.stdout.write(`${C2.green}Exported to ${outPath}${C_reset}\n`);
|
|
1495
|
+
} else if (action === 'verify') {
|
|
1496
|
+
const v = audit.verifyChain();
|
|
1497
|
+
process.stdout.write(v.valid ? `${C2.green}PASS Chain intact (${v.total} entries)${C_reset}\n` : `${C2.red}FAIL Chain broken at: ${v.brokenAt.join(',')}${C_reset}\n`);
|
|
1498
|
+
} else {
|
|
1499
|
+
process.stderr.write('Usage: vibeguard audit-trail [show|export|verify]\n');
|
|
1500
|
+
return 1;
|
|
1501
|
+
}
|
|
1502
|
+
return 0;
|
|
1503
|
+
}
|
|
1504
|
+
|
|
1505
|
+
function cmdPreDeploy(dir, flags) {
|
|
1506
|
+
const { runPreDeployGate, renderPreDeployReport } = require('../src/pre-deploy');
|
|
1507
|
+
const summary = runPreDeployGate(dir, { strict: flags.strict, json: flags.json });
|
|
1508
|
+
if (flags.json) {
|
|
1509
|
+
process.stdout.write(JSON.stringify(summary, null, 2) + '\n');
|
|
1510
|
+
} else {
|
|
1511
|
+
process.stdout.write(renderPreDeployReport(summary) + '\n');
|
|
1512
|
+
}
|
|
1513
|
+
return summary.deployReady ? 0 : 1;
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
function cmdRiskScore(dir, flags) {
|
|
1517
|
+
const result = scan(dir);
|
|
1518
|
+
const weights = { critical: 10, high: 5, medium: 2, low: 1 };
|
|
1519
|
+
let score = 0;
|
|
1520
|
+
for (const f of result.findings) score += weights[f.severity] || 1;
|
|
1521
|
+
const maxScore = result.scannedFiles * 10 || 1;
|
|
1522
|
+
const riskPercent = Math.min(100, Math.round((score / maxScore) * 100));
|
|
1523
|
+
const riskLevel = score === 0 ? 'NONE' : score < 10 ? 'LOW' : score < 30 ? 'MEDIUM' : score < 60 ? 'HIGH' : 'CRITICAL';
|
|
1524
|
+
const colors = { NONE: C.green, LOW: C.green, MEDIUM: C.yellow, HIGH: C.yellow, CRITICAL: C.red };
|
|
1525
|
+
process.stdout.write(
|
|
1526
|
+
`${C.bold}VibeGuard Risk Score${C.reset}\n` +
|
|
1527
|
+
` Risk Score: ${colors[riskLevel]}${score}${C.reset} (${riskPercent}% of max)\n` +
|
|
1528
|
+
` Risk Level: ${colors[riskLevel]}${riskLevel}${C.reset}\n` +
|
|
1529
|
+
` Grade: ${result.grade}\n` +
|
|
1530
|
+
` Files Scanned: ${result.scannedFiles}\n` +
|
|
1531
|
+
` Findings: ${result.findings.length}\n\n`
|
|
1532
|
+
);
|
|
1533
|
+
if (result.findings.length > 0) {
|
|
1534
|
+
process.stdout.write(`${C.bold}Top Risks:${C.reset}\n`);
|
|
1535
|
+
const top = sortFindings(result.findings).slice(0, 5);
|
|
1536
|
+
for (const f of top) {
|
|
1537
|
+
const sc = f.severity === 'critical' ? C.red : f.severity === 'high' ? C.yellow : C.dim;
|
|
1538
|
+
process.stdout.write(` ${sc}[${f.severity}]${C.reset} ${f.ruleId} — ${f.file}:${f.line}\n ${f.message.slice(0, 80)}\n`);
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
return 0;
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
function cmdTrend(dir, flags) {
|
|
1545
|
+
const baselinePath = path.join(dir, '.vibeguard-baseline.json');
|
|
1546
|
+
let baseline;
|
|
1547
|
+
try { baseline = JSON.parse(fs.readFileSync(baselinePath, 'utf8')); }
|
|
1548
|
+
catch { process.stderr.write('No baseline found. Run: vibeguard verify --baseline\n'); return 1; }
|
|
1549
|
+
const current = scan(dir);
|
|
1550
|
+
const baselineFps = new Set(baseline.findings.map(f => f.fingerprint));
|
|
1551
|
+
const currentFps = new Set(current.findings.map(f => f.fingerprint));
|
|
1552
|
+
const resolved = [...baselineFps].filter(f => !currentFps.has(f)).length;
|
|
1553
|
+
const newCount = [...currentFps].filter(f => !baselineFps.has(f)).length;
|
|
1554
|
+
const persisted = [...baselineFps].filter(f => currentFps.has(f)).length;
|
|
1555
|
+
const trend = resolved > newCount ? 'IMPROVING' : newCount > resolved ? 'WORSENING' : 'STABLE';
|
|
1556
|
+
const trendColor = trend === 'IMPROVING' ? C.green : trend === 'WORSENING' ? C.red : C.yellow;
|
|
1557
|
+
process.stdout.write(
|
|
1558
|
+
`${C.bold}VibeGuard Trend Report${C.reset}\n` +
|
|
1559
|
+
` Baseline: ${baseline.generatedAt} (grade ${baseline.grade}, ${baseline.findings.length} findings)\n` +
|
|
1560
|
+
` Current: ${current.generatedAt} (grade ${current.grade}, ${current.findings.length} findings)\n\n` +
|
|
1561
|
+
` ${C.green}Resolved: ${resolved}${C.reset}\n` +
|
|
1562
|
+
` ${C.red}New: ${newCount}${C.reset}\n` +
|
|
1563
|
+
` ${C.yellow}Persisted: ${persisted}${C.reset}\n` +
|
|
1564
|
+
` Trend: ${trendColor}${trend}${C.reset}\n`
|
|
1565
|
+
);
|
|
1566
|
+
if (newCount > 0) {
|
|
1567
|
+
const newFindings = current.findings.filter(f => !baselineFps.has(f.fingerprint));
|
|
1568
|
+
process.stdout.write(`\n${C.bold}New Findings:${C.reset}\n`);
|
|
1569
|
+
for (const f of sortFindings(newFindings).slice(0, 10)) {
|
|
1570
|
+
process.stdout.write(` [${f.severity}] ${f.ruleId} — ${f.file}:${f.line}\n ${f.message.slice(0, 80)}\n`);
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
return 0;
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1576
|
+
function cmdWhy(dir, args, flags) {
|
|
1577
|
+
const ruleId = args[0];
|
|
1578
|
+
if (!ruleId) { process.stderr.write('Usage: vibeguard why <ruleId>\n'); return 1; }
|
|
1579
|
+
const rules = require('../src/rules').allRules();
|
|
1580
|
+
const rule = rules.find(r => r.id === ruleId);
|
|
1581
|
+
if (!rule) { process.stderr.write(`Rule '${ruleId}' not found.\n`); return 1; }
|
|
1582
|
+
const autoFixable = require('../src/autofix').isAutoFixable(ruleId);
|
|
1583
|
+
process.stdout.write(
|
|
1584
|
+
`${C.bold}Rule: ${rule.id}${C.reset}\n` +
|
|
1585
|
+
` Severity: ${rule.severity}\n` +
|
|
1586
|
+
` Confidence: ${rule.confidence || 'high'}\n` +
|
|
1587
|
+
` CWE: ${rule.cwe || 'N/A'}\n` +
|
|
1588
|
+
` OWASP: ${rule.owasp || 'N/A'}\n` +
|
|
1589
|
+
` Auto-fix: ${autoFixable ? C.green + 'YES' + C.reset : C.red + 'NO' + C.reset}\n\n` +
|
|
1590
|
+
`${C.bold}What it detects:${C.reset}\n ${rule.message}\n\n` +
|
|
1591
|
+
`${C.bold}How to fix:${C.reset}\n ${rule.fix || 'No automated fix available.'}\n`
|
|
1592
|
+
);
|
|
1593
|
+
if (rule.fileFilter) process.stdout.write(`\n${C.bold}File filter:${C.reset} ${rule.fileFilter}\n`);
|
|
1594
|
+
return 0;
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
function cmdConfigCheck(dir, flags) {
|
|
1598
|
+
let ok = true;
|
|
1599
|
+
const checks = [];
|
|
1600
|
+
// Config files
|
|
1601
|
+
const configFiles = ['.vibeguardrc.json', 'vibeguard.config.json', '.vibeguard/config.json'];
|
|
1602
|
+
let configFound = false;
|
|
1603
|
+
for (const cf of configFiles) {
|
|
1604
|
+
if (fs.existsSync(path.join(dir, cf))) { configFound = true; checks.push(`${C.green}✓${C.reset} Config: ${cf}`); break; }
|
|
1605
|
+
}
|
|
1606
|
+
if (!configFound) checks.push(`${C.dim}○ No config file (using defaults)${C.reset}`);
|
|
1607
|
+
// MCP install
|
|
1608
|
+
if (fs.existsSync(path.join(dir, '.mcp.json'))) checks.push(`${C.green}✓${C.reset} MCP installed (.mcp.json)`);
|
|
1609
|
+
else { checks.push(`${C.yellow}⚠${C.reset} MCP not installed — run: vibeguard install`); ok = false; }
|
|
1610
|
+
// Hook
|
|
1611
|
+
const settingsPath = path.join(dir, '.claude', 'settings.json');
|
|
1612
|
+
if (fs.existsSync(settingsPath)) {
|
|
1613
|
+
try {
|
|
1614
|
+
const s = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
|
|
1615
|
+
if (s.hooks && s.hooks.PostToolUse) checks.push(`${C.green}✓${C.reset} PostToolUse hook installed`);
|
|
1616
|
+
else checks.push(`${C.yellow}⚠${C.reset} PostToolUse hook not configured`);
|
|
1617
|
+
} catch { checks.push(`${C.yellow}⚠${C.reset} .claude/settings.json invalid`); }
|
|
1618
|
+
} else checks.push(`${C.dim}○ No PostToolUse hook${C.reset}`);
|
|
1619
|
+
// Baseline
|
|
1620
|
+
if (fs.existsSync(path.join(dir, '.vibeguard-baseline.json'))) checks.push(`${C.green}✓${C.reset} Baseline exists`);
|
|
1621
|
+
else checks.push(`${C.dim}○ No baseline (run: vibeguard verify --baseline)${C.reset}`);
|
|
1622
|
+
// .gitignore
|
|
1623
|
+
const gitignore = path.join(dir, '.gitignore');
|
|
1624
|
+
if (fs.existsSync(gitignore)) {
|
|
1625
|
+
const gi = fs.readFileSync(gitignore, 'utf8');
|
|
1626
|
+
if (/\.env/.test(gi)) checks.push(`${C.green}✓${C.reset} .env in .gitignore`);
|
|
1627
|
+
else { checks.push(`${C.red}✗${C.reset} .env NOT in .gitignore`); ok = false; }
|
|
1628
|
+
}
|
|
1629
|
+
// CI
|
|
1630
|
+
const ciFiles = ['.github/workflows/test.yml', '.gitlab-ci.yml', 'Jenkinsfile', '.circleci/config.yml'];
|
|
1631
|
+
const ciFound = ciFiles.some(f => fs.existsSync(path.join(dir, f)));
|
|
1632
|
+
if (ciFound) checks.push(`${C.green}✓${C.reset} CI pipeline detected`);
|
|
1633
|
+
else checks.push(`${C.dim}○ No CI pipeline detected${C.reset}`);
|
|
1634
|
+
process.stdout.write(`${C.bold}VibeGuard Configuration Check${C.reset}\n\n`);
|
|
1635
|
+
for (const c of checks) process.stdout.write(` ${c}\n`);
|
|
1636
|
+
process.stdout.write(`\n${ok ? C.green + 'All checks passed.' + C.reset : C.yellow + 'Some checks need attention.' + C.reset}\n`);
|
|
1637
|
+
return ok ? 0 : 1;
|
|
1638
|
+
}
|
|
1639
|
+
|
|
1640
|
+
function cmdWatch(dir, flags) {
|
|
1641
|
+
process.stdout.write(`${C.bold}VibeGuard Watch Mode${C.reset}\n Watching ${dir} for changes... (Ctrl+C to stop)\n\n`);
|
|
1642
|
+
const { scanFileContent } = require('../src/scanner');
|
|
1643
|
+
const watched = new Map();
|
|
1644
|
+
function checkFile(filePath) {
|
|
1645
|
+
try {
|
|
1646
|
+
const stat = fs.statSync(filePath);
|
|
1647
|
+
if (!stat.isFile()) return;
|
|
1648
|
+
const ext = path.extname(filePath);
|
|
1649
|
+
const scanExts = new Set(['.js', '.jsx', '.ts', '.tsx', '.py', '.go', '.rb', '.php', '.java', '.kt', '.swift', '.sh', '.yml', '.yaml', '.json', '.toml', '.sql', '.env', '.tf']);
|
|
1650
|
+
if (!scanExts.has(ext) && !/^Dockerfile/i.test(path.basename(filePath))) return;
|
|
1651
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
1652
|
+
const rel = path.relative(dir, filePath).split(path.sep).join('/');
|
|
1653
|
+
const prevMtime = watched.get(filePath);
|
|
1654
|
+
if (prevMtime === stat.mtimeMs) return;
|
|
1655
|
+
watched.set(filePath, stat.mtimeMs);
|
|
1656
|
+
const findings = scanFileContent(filePath, rel, content, null);
|
|
1657
|
+
if (findings.length > 0) {
|
|
1658
|
+
const critical = findings.filter(f => f.severity === 'critical').length;
|
|
1659
|
+
const high = findings.filter(f => f.severity === 'high').length;
|
|
1660
|
+
const med = findings.filter(f => f.severity === 'medium').length;
|
|
1661
|
+
const color = critical > 0 ? C.red : high > 0 ? C.yellow : C.dim;
|
|
1662
|
+
process.stdout.write(`${color}[${new Date().toLocaleTimeString()}] ${rel}: ${findings.length} findings${C.reset}\n`);
|
|
1663
|
+
for (const f of findings.slice(0, 5)) {
|
|
1664
|
+
const sc = f.severity === 'critical' ? C.red : f.severity === 'high' ? C.yellow : C.dim;
|
|
1665
|
+
process.stdout.write(` ${sc}[${f.severity}]${C.reset} ${f.ruleId} line ${f.line} — ${f.message.slice(0, 60)}\n`);
|
|
1666
|
+
}
|
|
1667
|
+
if (findings.length > 5) process.stdout.write(` ... and ${findings.length - 5} more\n`);
|
|
1668
|
+
process.stdout.write('\n');
|
|
1669
|
+
}
|
|
1670
|
+
} catch {}
|
|
1671
|
+
}
|
|
1672
|
+
// Initial scan
|
|
1673
|
+
const { walk } = require('../src/scanner');
|
|
1674
|
+
const files = walk(dir, []);
|
|
1675
|
+
for (const f of files) checkFile(f);
|
|
1676
|
+
// Poll for changes (no chokidar dependency)
|
|
1677
|
+
setInterval(() => {
|
|
1678
|
+
const currentFiles = walk(dir, []);
|
|
1679
|
+
for (const f of currentFiles) checkFile(f);
|
|
1680
|
+
}, 2000);
|
|
1681
|
+
return 0;
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1684
|
+
function cmdPreset(dir, args, flags) {
|
|
1685
|
+
if (!args[0] || args[0] === '--list') {
|
|
1686
|
+
const list = listPresets();
|
|
1687
|
+
process.stdout.write(`${C.bold}Available Presets${C.reset}\n\n`);
|
|
1688
|
+
for (const p of list) {
|
|
1689
|
+
process.stdout.write(` ${C.cyan}${p.key.padEnd(12)}${C.reset} ${p.name}\n${C.dim} ${p.description}${C.reset}\n\n`);
|
|
1690
|
+
}
|
|
1691
|
+
process.stdout.write(`${C.dim}Usage: vibeguard preset <name>${C.reset}\n`);
|
|
1692
|
+
return 0;
|
|
1693
|
+
}
|
|
1694
|
+
const name = args[0];
|
|
1695
|
+
const preset = getPreset(name);
|
|
1696
|
+
if (!preset) {
|
|
1697
|
+
process.stderr.write(`Unknown preset: ${name}\nAvailable: ${Object.keys(require('../src/presets').PRESETS).join(', ')}\n`);
|
|
1698
|
+
return 1;
|
|
1699
|
+
}
|
|
1700
|
+
const configPath = path.join(dir, '.vibeguardrc.json');
|
|
1701
|
+
let config = {};
|
|
1702
|
+
try { config = JSON.parse(fs.readFileSync(configPath, 'utf8')); } catch {}
|
|
1703
|
+
config.preset = name;
|
|
1704
|
+
config.presetName = preset.name;
|
|
1705
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n');
|
|
1706
|
+
process.stdout.write(`${C.green}✓${C.reset} Applied preset: ${C.bold}${preset.name}${C.reset}\n ${preset.description}\n Config: ${configPath}\n`);
|
|
1707
|
+
return 0;
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
// Read the text to scan from: positional arg, --file <path>, or stdin.
|
|
1711
|
+
function readPIIInput(args, flags) {
|
|
1712
|
+
const positional = args._.slice(1).join(' ').trim();
|
|
1713
|
+
if (positional && positional !== '.') return positional;
|
|
1714
|
+
if (flags.file) return fs.readFileSync(flags.file, 'utf8');
|
|
1715
|
+
try {
|
|
1716
|
+
const s = fs.readFileSync(0, 'utf8'); // stdin (fd 0)
|
|
1717
|
+
if (s) return s;
|
|
1718
|
+
} catch {
|
|
1719
|
+
/* no stdin */
|
|
1720
|
+
}
|
|
1721
|
+
return '';
|
|
1722
|
+
}
|
|
1723
|
+
|
|
1724
|
+
function cmdRedact(args, flags) {
|
|
1725
|
+
const { redactText } = require('../src/pii');
|
|
1726
|
+
const text = readPIIInput(args, flags);
|
|
1727
|
+
if (!text) {
|
|
1728
|
+
process.stderr.write('usage: vibeguard redact "text with pii" | --file <path> | echo text | vibeguard redact\n');
|
|
1729
|
+
return 2;
|
|
1730
|
+
}
|
|
1731
|
+
const types = flags.types ? String(flags.types).split(',').map((s) => s.trim()) : undefined;
|
|
1732
|
+
const res = redactText(text, { types });
|
|
1733
|
+
if (flags.json) {
|
|
1734
|
+
process.stdout.write(JSON.stringify(res, null, 2) + '\n');
|
|
1735
|
+
return res.clean ? 0 : 1;
|
|
1736
|
+
}
|
|
1737
|
+
// Human mode: print the scrubbed text to stdout (pipe-safe), summary to stderr.
|
|
1738
|
+
process.stdout.write(res.redacted + (res.redacted.endsWith('\n') ? '' : '\n'));
|
|
1739
|
+
if (res.clean) {
|
|
1740
|
+
process.stderr.write(`${C.green}No personal data detected — text unchanged.${C.reset}\n`);
|
|
1741
|
+
} else {
|
|
1742
|
+
const parts = Object.entries(res.counts).map(([t, n]) => `${t}×${n}`).join(', ');
|
|
1743
|
+
process.stderr.write(`${C.yellow}Redacted ${res.total} item(s): ${parts}${C.reset}\n`);
|
|
1744
|
+
}
|
|
1745
|
+
return res.clean ? 0 : 1;
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1748
|
+
function cmdDetectPII(args, flags) {
|
|
1749
|
+
const { detectPII } = require('../src/pii');
|
|
1750
|
+
const text = readPIIInput(args, flags);
|
|
1751
|
+
if (!text) {
|
|
1752
|
+
process.stderr.write('usage: vibeguard detect-pii "text with pii" | --file <path> | echo text | vibeguard detect-pii\n');
|
|
1753
|
+
return 2;
|
|
1754
|
+
}
|
|
1755
|
+
const types = flags.types ? String(flags.types).split(',').map((s) => s.trim()) : undefined;
|
|
1756
|
+
const res = detectPII(text, { types });
|
|
1757
|
+
if (flags.json) {
|
|
1758
|
+
process.stdout.write(JSON.stringify(res, null, 2) + '\n');
|
|
1759
|
+
return res.total > 0 ? 1 : 0;
|
|
1760
|
+
}
|
|
1761
|
+
if (res.total === 0) {
|
|
1762
|
+
process.stdout.write(`${C.green}No personal data detected.${C.reset}\n`);
|
|
1763
|
+
return 0;
|
|
1764
|
+
}
|
|
1765
|
+
process.stdout.write(`${C.bold}${C.red}${res.total} personal-data item(s) found:${C.reset}\n\n`);
|
|
1766
|
+
for (const m of res.matches) {
|
|
1767
|
+
const sc = m.severity === 'critical' ? C.red : m.severity === 'high' ? C.red : m.severity === 'medium' ? C.yellow : C.dim;
|
|
1768
|
+
process.stdout.write(` ${sc}[${m.severity}]${C.reset} ${m.type.padEnd(15)} → ${m.token} ${C.dim}(offset ${m.start})${C.reset}\n`);
|
|
1769
|
+
}
|
|
1770
|
+
process.stdout.write(`\n${C.dim}Scrub it: pipe the same text through 'vibeguard redact'.${C.reset}\n`);
|
|
1771
|
+
return 1;
|
|
1772
|
+
}
|
|
1773
|
+
|
|
1774
|
+
function cmdDashboard(dir, flags) {
|
|
1775
|
+
const result = scan(dir);
|
|
1776
|
+
const { renderDashboard } = require('../src/dashboard');
|
|
1777
|
+
process.stdout.write(renderDashboard(result));
|
|
1778
|
+
return result.findings.length > 0 ? 1 : 0;
|
|
1779
|
+
}
|
|
1780
|
+
|
|
1781
|
+
function cmdPRComment(dir, flags) {
|
|
1782
|
+
const result = scan(dir);
|
|
1783
|
+
const { renderPRComment } = require('../src/dashboard');
|
|
1784
|
+
process.stdout.write(renderPRComment(result));
|
|
1785
|
+
return result.findings.length > 0 ? 1 : 0;
|
|
1786
|
+
}
|
|
1787
|
+
|
|
1788
|
+
function cmdGuard(args, flags) {
|
|
1789
|
+
const { checkCommand } = require('../src/shell-guard');
|
|
1790
|
+
const cmd = args._.slice(1).join(' ');
|
|
1791
|
+
if (!cmd) {
|
|
1792
|
+
process.stderr.write('Usage: vibeguard guard "<command>"\n');
|
|
1793
|
+
process.stderr.write('Checks a command for danger before execution.\n');
|
|
1794
|
+
process.stderr.write('Exit 0 = safe, exit 1 = blocked, exit 2 = error.\n');
|
|
1795
|
+
return 2;
|
|
1796
|
+
}
|
|
1797
|
+
const result = checkCommand(cmd);
|
|
1798
|
+
if (flags.json) {
|
|
1799
|
+
process.stdout.write(JSON.stringify(result, null, 2) + '\n');
|
|
1800
|
+
} else if (result.blocked) {
|
|
1801
|
+
process.stdout.write(`\n ${C.red}[VibeGuard] BLOCKED:${C.reset} ${C.bold}${result.command}${C.reset}\n`);
|
|
1802
|
+
process.stdout.write(` ${C.red}Reason:${C.reset} ${result.reason}\n`);
|
|
1803
|
+
process.stdout.write(` ${C.red}Severity:${C.reset} ${result.severity}\n`);
|
|
1804
|
+
if (result.violations.length > 1) {
|
|
1805
|
+
process.stdout.write(` ${C.red}All violations:${C.reset}\n`);
|
|
1806
|
+
for (const v of result.violations) {
|
|
1807
|
+
process.stdout.write(` - [${v.severity}] ${v.type}: ${v.reason}\n`);
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
process.stdout.write(`\n ${C.dim}Override: VG_OVERRIDE=1 <command>${C.reset}\n\n`);
|
|
1811
|
+
} else {
|
|
1812
|
+
process.stdout.write(`${C.green}[VibeGuard] Safe:${C.reset} ${cmd.slice(0, 100)}\n`);
|
|
1813
|
+
}
|
|
1814
|
+
return result.blocked ? 1 : 0;
|
|
1815
|
+
}
|
|
1816
|
+
|
|
1817
|
+
function cmdInstallShellHook(flags) {
|
|
1818
|
+
const fs = require('fs');
|
|
1819
|
+
const os = require('os');
|
|
1820
|
+
const path = require('path');
|
|
1821
|
+
|
|
1822
|
+
// Consent prompt — never modify shell profiles without asking.
|
|
1823
|
+
if (!flags.yes && !flags.force) {
|
|
1824
|
+
process.stdout.write('\n VibeGuard will modify your shell profile (.bashrc/.zshrc/PowerShell profile)\n');
|
|
1825
|
+
process.stdout.write(' to intercept dangerous commands before they execute.\n\n');
|
|
1826
|
+
process.stdout.write(' This adds a sourced line and is fully reversible (vibeguard uninstall-shell-hook).\n');
|
|
1827
|
+
process.stdout.write(' Backups are saved to .vibeguard/backups/.\n\n');
|
|
1828
|
+
process.stdout.write(' Proceed? [y/N] ');
|
|
1829
|
+
const answer = fs.readFileSync(0, 'utf8').trim().toLowerCase();
|
|
1830
|
+
if (answer !== 'y' && answer !== 'yes') {
|
|
1831
|
+
process.stdout.write('\n Skipped. Run "vibeguard install-shell-hook --yes" to skip this prompt.\n\n');
|
|
1832
|
+
return 0;
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
|
|
1836
|
+
const srcDir = path.resolve(__dirname, '..', 'src');
|
|
1837
|
+
const home = os.homedir();
|
|
1838
|
+
const results = [];
|
|
1839
|
+
|
|
1840
|
+
// Detect shells and install
|
|
1841
|
+
// 1. bash
|
|
1842
|
+
const bashProfile = path.join(home, '.bashrc');
|
|
1843
|
+
const bashMarker = '# >>> VibeGuard shell hook >>>';
|
|
1844
|
+
const bashEndMarker = '# <<< VibeGuard shell hook <<<';
|
|
1845
|
+
const bashHook = [
|
|
1846
|
+
bashMarker,
|
|
1847
|
+
`source "${path.join(srcDir, 'shell-hook.sh')}"`,
|
|
1848
|
+
bashEndMarker,
|
|
1849
|
+
].join('\n');
|
|
1850
|
+
|
|
1851
|
+
try {
|
|
1852
|
+
let content = fs.existsSync(bashProfile) ? fs.readFileSync(bashProfile, 'utf8') : '';
|
|
1853
|
+
// Remove old hook
|
|
1854
|
+
content = content.replace(new RegExp(`${bashMarker}[\\s\\S]*?${bashEndMarker}\\n?`, 'g'), '');
|
|
1855
|
+
content = content.trimEnd() + '\n' + bashHook + '\n';
|
|
1856
|
+
fs.writeFileSync(bashProfile, content);
|
|
1857
|
+
results.push(`bash: installed in ${bashProfile}`);
|
|
1858
|
+
} catch (e) {
|
|
1859
|
+
results.push(`bash: failed (${e.message})`);
|
|
1860
|
+
}
|
|
1861
|
+
|
|
1862
|
+
// 2. zsh
|
|
1863
|
+
const zshProfile = path.join(home, '.zshrc');
|
|
1864
|
+
try {
|
|
1865
|
+
let content = fs.existsSync(zshProfile) ? fs.readFileSync(zshProfile, 'utf8') : '';
|
|
1866
|
+
content = content.replace(new RegExp(`${bashMarker}[\\s\\S]*?${bashEndMarker}\\n?`, 'g'), '');
|
|
1867
|
+
content = content.trimEnd() + '\n' + bashHook + '\n';
|
|
1868
|
+
fs.writeFileSync(zshProfile, content);
|
|
1869
|
+
results.push(`zsh: installed in ${zshProfile}`);
|
|
1870
|
+
} catch (e) {
|
|
1871
|
+
results.push(`zsh: failed (${e.message})`);
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
// 3. PowerShell (Windows)
|
|
1875
|
+
if (process.platform === 'win32') {
|
|
1876
|
+
try {
|
|
1877
|
+
const psProfileDir = path.join(home, 'Documents', 'WindowsPowerShell');
|
|
1878
|
+
if (!fs.existsSync(psProfileDir)) fs.mkdirSync(psProfileDir, { recursive: true });
|
|
1879
|
+
const psProfile = path.join(psProfileDir, 'Microsoft.PowerShell_profile.ps1');
|
|
1880
|
+
const psMarker = '### >>> VibeGuard shell hook >>>';
|
|
1881
|
+
const psEndMarker = '### <<< VibeGuard shell hook <<<';
|
|
1882
|
+
let content = fs.existsSync(psProfile) ? fs.readFileSync(psProfile, 'utf8') : '';
|
|
1883
|
+
content = content.replace(new RegExp(`${psMarker}[\\s\\S]*?${psEndMarker}\\n?`, 'g'), '');
|
|
1884
|
+
const psHook = [
|
|
1885
|
+
psMarker,
|
|
1886
|
+
`$VG_SCRIPT_DIR = "${srcDir.replace(/\\/g, '\\\\')}"`,
|
|
1887
|
+
`. "${path.join(srcDir, 'shell-hook.ps1').replace(/\\/g, '\\\\')}"`,
|
|
1888
|
+
psEndMarker,
|
|
1889
|
+
].join('\n');
|
|
1890
|
+
content = content.trimEnd() + '\n' + psHook + '\n';
|
|
1891
|
+
fs.writeFileSync(psProfile, content);
|
|
1892
|
+
results.push(`powershell: installed in ${psProfile}`);
|
|
1893
|
+
} catch (e) {
|
|
1894
|
+
results.push(`powershell: failed (${e.message})`);
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1898
|
+
// 4. Node.js guard info
|
|
1899
|
+
results.push(`node: use --require vibeguard/guard to protect any Node.js process`);
|
|
1900
|
+
|
|
1901
|
+
process.stdout.write(`\n${C.green}[VibeGuard] Shell hook installed:${C.reset}\n\n`);
|
|
1902
|
+
for (const r of results) {
|
|
1903
|
+
process.stdout.write(` ${C.bold}${r}${C.reset}\n`);
|
|
1904
|
+
}
|
|
1905
|
+
process.stdout.write(`\n${C.dim}Restart your shell for changes to take effect.${C.reset}\n`);
|
|
1906
|
+
process.stdout.write(`${C.dim}Override: set VG_OVERRIDE=1 to bypass for a single command.${C.reset}\n`);
|
|
1907
|
+
process.stdout.write(`${C.dim}Uninstall: vibeguard uninstall-shell-hook${C.reset}\n\n`);
|
|
1908
|
+
return 0;
|
|
1909
|
+
}
|
|
1910
|
+
|
|
1911
|
+
function cmdUninstallShellHook(flags) {
|
|
1912
|
+
const fs = require('fs');
|
|
1913
|
+
const os = require('os');
|
|
1914
|
+
const path = require('path');
|
|
1915
|
+
const home = os.homedir();
|
|
1916
|
+
const results = [];
|
|
1917
|
+
const bashMarker = '# >>> VibeGuard shell hook >>>';
|
|
1918
|
+
const bashEndMarker = '# <<< VibeGuard shell hook <<<';
|
|
1919
|
+
const psMarker = '### >>> VibeGuard shell hook >>>';
|
|
1920
|
+
const psEndMarker = '### <<< VibeGuard shell hook <<<';
|
|
1921
|
+
|
|
1922
|
+
for (const profile of ['.bashrc', '.zshrc']) {
|
|
1923
|
+
const p = path.join(home, profile);
|
|
1924
|
+
try {
|
|
1925
|
+
if (fs.existsSync(p)) {
|
|
1926
|
+
let content = fs.readFileSync(p, 'utf8');
|
|
1927
|
+
content = content.replace(new RegExp(`${bashMarker}[\\s\\S]*?${bashEndMarker}\\n?`, 'g'), '');
|
|
1928
|
+
fs.writeFileSync(p, content);
|
|
1929
|
+
results.push(`${profile}: removed`);
|
|
1930
|
+
}
|
|
1931
|
+
} catch (e) {
|
|
1932
|
+
results.push(`${profile}: failed (${e.message})`);
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1935
|
+
|
|
1936
|
+
if (process.platform === 'win32') {
|
|
1937
|
+
try {
|
|
1938
|
+
const psProfile = path.join(home, 'Documents', 'WindowsPowerShell', 'Microsoft.PowerShell_profile.ps1');
|
|
1939
|
+
if (fs.existsSync(psProfile)) {
|
|
1940
|
+
let content = fs.readFileSync(psProfile, 'utf8');
|
|
1941
|
+
content = content.replace(new RegExp(`${psMarker}[\\s\\S]*?${psEndMarker}\\n?`, 'g'), '');
|
|
1942
|
+
fs.writeFileSync(psProfile, content);
|
|
1943
|
+
results.push('powershell: removed');
|
|
1944
|
+
}
|
|
1945
|
+
} catch (e) {
|
|
1946
|
+
results.push(`powershell: failed (${e.message})`);
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1950
|
+
process.stdout.write(`\n${C.green}[VibeGuard] Shell hook removed:${C.reset}\n\n`);
|
|
1951
|
+
for (const r of results) {
|
|
1952
|
+
process.stdout.write(` ${C.bold}${r}${C.reset}\n`);
|
|
1953
|
+
}
|
|
1954
|
+
process.stdout.write(`\n${C.dim}Restart your shell for changes to take effect.${C.reset}\n\n`);
|
|
1955
|
+
return 0;
|
|
1956
|
+
}
|
|
1957
|
+
|
|
1958
|
+
// ─── unified auto: delegates to src/auto.js ────────────────────────────────
|
|
1959
|
+
|
|
1960
|
+
function cmdAutoUnified(dir, args, flags) {
|
|
1961
|
+
const auto = require('../src/auto');
|
|
1962
|
+
const rootDir = path.resolve(dir || '.');
|
|
1963
|
+
|
|
1964
|
+
// auto --stop
|
|
1965
|
+
if (flags.stop || (args._ && args._[1] === '--stop')) {
|
|
1966
|
+
const r = auto.autoStop(rootDir);
|
|
1967
|
+
if (!r.ok) {
|
|
1968
|
+
process.stdout.write(`${C.yellow}[VibeGuard] ${r.reason}${C.reset}\n`);
|
|
1969
|
+
return 0;
|
|
1970
|
+
}
|
|
1971
|
+
process.stdout.write(`${C.green}[VibeGuard] Auto protection stopped.${C.reset}\n\n`);
|
|
1972
|
+
for (const s of r.reversed) {
|
|
1973
|
+
process.stdout.write(` ${C.green}OK${C.reset} ${s}\n`);
|
|
1974
|
+
}
|
|
1975
|
+
process.stdout.write(`\n${C.dim}All hooks removed. Repo restored.${C.reset}\n`);
|
|
1976
|
+
return 0;
|
|
1977
|
+
}
|
|
1978
|
+
|
|
1979
|
+
// auto --status
|
|
1980
|
+
if (flags.status || (args._ && args._[1] === '--status')) {
|
|
1981
|
+
const s = auto.autoStatus(rootDir);
|
|
1982
|
+
if (flags.json) {
|
|
1983
|
+
process.stdout.write(JSON.stringify(s, null, 2) + '\n');
|
|
1984
|
+
return 0;
|
|
1985
|
+
}
|
|
1986
|
+
if (!s.running) {
|
|
1987
|
+
process.stdout.write(`${C.dim}[VibeGuard] Not active${C.reset}\n`);
|
|
1988
|
+
process.stdout.write(`${C.dim}Run 'vibeguard auto' to start.${C.reset}\n`);
|
|
1989
|
+
return 0;
|
|
1990
|
+
}
|
|
1991
|
+
process.stdout.write(`${C.green}[VibeGuard] Active${C.reset}\n\n`);
|
|
1992
|
+
process.stdout.write(` ${C.bold}PID:${C.reset} ${s.pid}\n`);
|
|
1993
|
+
process.stdout.write(` ${C.bold}Daemon PID:${C.reset} ${s.daemonPid || 'n/a'} ${s.daemonAlive ? C.green + '(alive)' + C.reset : C.red + '(dead)' + C.reset}\n`);
|
|
1994
|
+
process.stdout.write(` ${C.bold}Started:${C.reset} ${s.startedAt}\n`);
|
|
1995
|
+
process.stdout.write(` ${C.bold}Uptime:${C.reset} ${Math.round(s.uptimeMs / 1000)}s\n`);
|
|
1996
|
+
process.stdout.write(` ${C.bold}Last scan:${C.reset} ${s.lastScan || 'n/a'}\n`);
|
|
1997
|
+
process.stdout.write(` ${C.bold}Findings:${C.reset} ${s.findingsSinceStart}\n\n`);
|
|
1998
|
+
process.stdout.write(` ${C.bold}Features:${C.reset}\n`);
|
|
1999
|
+
for (const [k, v] of Object.entries(s.features || {})) {
|
|
2000
|
+
process.stdout.write(` ${v ? C.green + 'ON' + C.reset : C.dim + 'OFF' + C.reset} ${k}\n`);
|
|
2001
|
+
}
|
|
2002
|
+
process.stdout.write(`\n ${C.dim}Stop: vibeguard auto --stop${C.reset}\n`);
|
|
2003
|
+
return 0;
|
|
2004
|
+
}
|
|
2005
|
+
|
|
2006
|
+
// auto --ci (non-interactive pipeline mode)
|
|
2007
|
+
if (flags.ci) {
|
|
2008
|
+
const r = auto.autoCI(rootDir, { ci: true, strict: flags.strict, deep: flags.deep });
|
|
2009
|
+
if (r.ci) {
|
|
2010
|
+
for (const step of r.steps) {
|
|
2011
|
+
if (step.step === 'scan') {
|
|
2012
|
+
process.stdout.write(`Grade: ${step.grade} Critical: ${step.counts.critical || 0} High: ${step.counts.high || 0}\n`);
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
return r.exitCode || 0;
|
|
2016
|
+
}
|
|
2017
|
+
process.stderr.write(`${C.red}[VibeGuard] CI mode failed${C.reset}\n`);
|
|
2018
|
+
return 2;
|
|
2019
|
+
}
|
|
2020
|
+
|
|
2021
|
+
// auto (full start)
|
|
2022
|
+
const opts = {
|
|
2023
|
+
fix: !!flags.fix,
|
|
2024
|
+
strict: !!flags.strict,
|
|
2025
|
+
noShell: !!flags['no-shell'],
|
|
2026
|
+
deep: !!flags.deep,
|
|
2027
|
+
verbose: !!flags.verbose,
|
|
2028
|
+
yes: !!flags.yes || !!flags.force,
|
|
2029
|
+
};
|
|
2030
|
+
|
|
2031
|
+
process.stdout.write(`\n${C.bold}${C.cyan}[VibeGuard] Activating full protection...${C.reset}\n\n`);
|
|
2032
|
+
|
|
2033
|
+
const r = auto.autoStart(rootDir, opts);
|
|
2034
|
+
if (!r.ok) {
|
|
2035
|
+
process.stderr.write(`${C.red}[VibeGuard] ${r.reason}${C.reset}\n`);
|
|
2036
|
+
return 2;
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2039
|
+
if (r.alreadyRunning) {
|
|
2040
|
+
process.stdout.write(`${C.yellow}[VibeGuard] Already active. Use 'vibeguard auto --status' for details.${C.reset}\n`);
|
|
2041
|
+
return 0;
|
|
2042
|
+
}
|
|
2043
|
+
|
|
2044
|
+
// Print steps
|
|
2045
|
+
for (const step of r.steps) {
|
|
2046
|
+
const icon = step.error ? C.red + 'X' : C.green + 'OK';
|
|
2047
|
+
const name = step.step.padEnd(20);
|
|
2048
|
+
if (step.error) {
|
|
2049
|
+
process.stdout.write(` ${icon} ${name} ${C.red}${step.error}${C.reset}\n`);
|
|
2050
|
+
} else if (step.step === 'scan') {
|
|
2051
|
+
process.stdout.write(` ${icon} ${name} ${C.bold}Grade: ${step.grade}${C.reset} Critical: ${step.counts.critical || 0} High: ${step.counts.high || 0}${C.reset}\n`);
|
|
2052
|
+
} else {
|
|
2053
|
+
process.stdout.write(` ${icon} ${name} ${C.dim}done${C.reset}\n`);
|
|
2054
|
+
}
|
|
2055
|
+
}
|
|
2056
|
+
|
|
2057
|
+
process.stdout.write(`\n${C.green}${C.bold}[VibeGuard] Fully active:${C.reset}\n\n`);
|
|
2058
|
+
process.stdout.write(` ${C.green}1.${C.reset} Daemon — auto-scans every file change\n`);
|
|
2059
|
+
process.stdout.write(` ${C.green}2.${C.reset} Pre-commit hook — blocks commits on critical\n`);
|
|
2060
|
+
process.stdout.write(` ${C.green}3.${C.reset} Post-edit hook — scans AI agent edits\n`);
|
|
2061
|
+
process.stdout.write(` ${C.green}4.${C.reset} Shell guard — blocks dangerous commands${C.reset}\n\n`);
|
|
2062
|
+
process.stdout.write(` ${C.dim}Status: vibeguard auto --status${C.reset}\n`);
|
|
2063
|
+
process.stdout.write(` ${C.dim}Stop: vibeguard auto --stop${C.reset}\n`);
|
|
2064
|
+
process.stdout.write(` ${C.dim}Override: VG_OVERRIDE=1 <command>${C.reset}\n\n`);
|
|
2065
|
+
|
|
2066
|
+
return 0;
|
|
2067
|
+
}
|
|
2068
|
+
|
|
2069
|
+
// Keep old auto-* commands as aliases to unified auto
|
|
2070
|
+
function cmdAutoStart(dir, flags) {
|
|
2071
|
+
return cmdAutoUnified(dir, {}, flags);
|
|
2072
|
+
}
|
|
2073
|
+
function cmdAutoStop(dir, flags) {
|
|
2074
|
+
return cmdAutoUnified(dir, { _: ['', '--stop'] }, { stop: true, ...flags });
|
|
2075
|
+
}
|
|
2076
|
+
function cmdAutoStatus(dir, flags) {
|
|
2077
|
+
return cmdAutoUnified(dir, { _: ['', '--status'] }, { status: true, ...flags });
|
|
2078
|
+
}
|
|
2079
|
+
|
|
2080
|
+
main().catch((err) => {
|
|
2081
|
+
process.stderr.write(`vibeguard error: ${err && err.message ? err.message : err}\n`);
|
|
2082
|
+
process.exit(2);
|
|
2083
|
+
});
|