eslint-plugin-ai-guard 1.4.3 → 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +751 -715
- package/dist/cli/index.js +6605 -1362
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.mts +62 -0
- package/dist/index.d.ts +62 -0
- package/dist/index.js +3268 -512
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3266 -510
- package/dist/index.mjs.map +1 -1
- package/dist/mcp/server.js +5761 -656
- package/dist/mcp/server.js.map +1 -1
- package/package.json +106 -106
package/README.md
CHANGED
|
@@ -1,715 +1,751 @@
|
|
|
1
|
-
<p align="center">
|
|
2
|
-
<a href="https://getaiguard.dev">
|
|
3
|
-
<img src="./assets/logo/ai-guard-logo.png" alt="AI Guard Logo" width="260" />
|
|
4
|
-
</a>
|
|
5
|
-
</p>
|
|
6
|
-
|
|
7
|
-
<h1 align="center">AI Guard</h1>
|
|
8
|
-
|
|
9
|
-
<p align="center">
|
|
10
|
-
<strong>Deterministic AST safety layer and CI guardrails for AI-assisted JavaScript and TypeScript code.</strong>
|
|
11
|
-
</p>
|
|
12
|
-
|
|
13
|
-
<p align="center">
|
|
14
|
-
<a href="https://getaiguard.dev"><strong>Website</strong></a> •
|
|
15
|
-
<a href="https://www.npmjs.com/package/eslint-plugin-ai-guard"><strong>npm Package</strong></a> •
|
|
16
|
-
<a href="https://github.com/ai-guard-dev/eslint-plugin-ai-guard"><strong>GitHub Repository</strong></a> •
|
|
17
|
-
<a href="./docs/rules/"><strong>Rules Catalog</strong></a> •
|
|
18
|
-
<a href="./docs/benchmarks.md"><strong>Benchmarks</strong></a> •
|
|
19
|
-
<a href="./docs/integrations/claude-code.md"><strong>Claude Code</strong></a> •
|
|
20
|
-
<a href="./docs/getting-started.md"><strong>Documentation</strong></a>
|
|
21
|
-
</p>
|
|
22
|
-
|
|
23
|
-
<p align="center">
|
|
24
|
-
<a href="https://www.npmjs.com/package/eslint-plugin-ai-guard"><img src="https://img.shields.io/npm/v/eslint-plugin-ai-guard.svg?style=flat-square&color=0284c7" alt="npm version"></a>
|
|
25
|
-
<a href="https://github.com/ai-guard-dev/eslint-plugin-ai-guard/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/ai-guard-dev/eslint-plugin-ai-guard/ci.yml?style=flat-square&label=CI&color=10b981" alt="CI Status"></a>
|
|
26
|
-
<a href="https://www.npmjs.com/package/eslint-plugin-ai-guard"><img src="https://img.shields.io/npm/dm/eslint-plugin-ai-guard.svg?style=flat-square&color=3b82f6" alt="npm downloads"></a>
|
|
27
|
-
<a href="https://github.com/ai-guard-dev/eslint-plugin-ai-guard/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-64748b?style=flat-square" alt="MIT License"></a>
|
|
28
|
-
<a href="https://github.com/ai-guard-dev/eslint-plugin-ai-guard/blob/main/SECURITY.md"><img src="https://img.shields.io/badge/security-policy-orange?style=flat-square" alt="Security Policy"></a>
|
|
29
|
-
<a href="https://getaiguard.dev"><img src="https://img.shields.io/badge/website-getaiguard.dev-0ea5e9?style=flat-square" alt="Website"></a>
|
|
30
|
-
</p>
|
|
31
|
-
|
|
32
|
-
---
|
|
33
|
-
|
|
34
|
-
## What is AI Guard?
|
|
35
|
-
|
|
36
|
-
**AI Guard** (`eslint-plugin-ai-guard`) provides:
|
|
37
|
-
- **ESLint plugin** with
|
|
38
|
-
- **CLI** (`ai-guard`) for terminal, changed-file, and CI scanning
|
|
39
|
-
- **GitHub Action** with native SARIF 2.1.0 output for GitHub Code Scanning
|
|
40
|
-
- **Check integrity** (`ai-guard integrity`) — detects changes that weaken checks: new suppressions, skipped or removed tests, lowered ESLint/TypeScript/coverage settings, removed CI steps
|
|
41
|
-
- **
|
|
42
|
-
- **
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
>
|
|
52
|
-
> - **AI Guard
|
|
53
|
-
> - **AI Guard
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
|
63
|
-
|
|
|
64
|
-
| **
|
|
65
|
-
| **
|
|
66
|
-
| **
|
|
67
|
-
| **
|
|
68
|
-
| **
|
|
69
|
-
| **
|
|
70
|
-
| **
|
|
71
|
-
| **
|
|
72
|
-
| **
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
G -->
|
|
105
|
-
G -->
|
|
106
|
-
G -->
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
L -->
|
|
113
|
-
L -->
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
|
127
|
-
|
|
|
128
|
-
| [`no-
|
|
129
|
-
| [`no-
|
|
130
|
-
| [`no-
|
|
131
|
-
| [`
|
|
132
|
-
| [`require-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
|
137
|
-
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
|
146
|
-
|
|
|
147
|
-
| [`no-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
|
156
|
-
|
|
|
157
|
-
| [`no-
|
|
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
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
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
|
-
|
|
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
|
-
|
|
434
|
-
|
|
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
|
-
|
|
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
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
###
|
|
509
|
-
|
|
510
|
-
```typescript
|
|
511
|
-
// ❌ BAD:
|
|
512
|
-
async function
|
|
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
|
-
// ✅ GOOD:
|
|
551
|
-
|
|
552
|
-
await
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
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
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
|
661
|
-
|
|
|
662
|
-
| `
|
|
663
|
-
|
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
**
|
|
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
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://getaiguard.dev">
|
|
3
|
+
<img src="./assets/logo/ai-guard-logo.png" alt="AI Guard Logo" width="260" />
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<h1 align="center">AI Guard</h1>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<strong>Deterministic AST safety layer and CI guardrails for AI-assisted JavaScript and TypeScript code.</strong>
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
<p align="center">
|
|
14
|
+
<a href="https://getaiguard.dev"><strong>Website</strong></a> •
|
|
15
|
+
<a href="https://www.npmjs.com/package/eslint-plugin-ai-guard"><strong>npm Package</strong></a> •
|
|
16
|
+
<a href="https://github.com/ai-guard-dev/eslint-plugin-ai-guard"><strong>GitHub Repository</strong></a> •
|
|
17
|
+
<a href="./docs/rules/"><strong>Rules Catalog</strong></a> •
|
|
18
|
+
<a href="./docs/benchmarks.md"><strong>Benchmarks</strong></a> •
|
|
19
|
+
<a href="./docs/integrations/claude-code.md"><strong>Claude Code</strong></a> •
|
|
20
|
+
<a href="./docs/getting-started.md"><strong>Documentation</strong></a>
|
|
21
|
+
</p>
|
|
22
|
+
|
|
23
|
+
<p align="center">
|
|
24
|
+
<a href="https://www.npmjs.com/package/eslint-plugin-ai-guard"><img src="https://img.shields.io/npm/v/eslint-plugin-ai-guard.svg?style=flat-square&color=0284c7" alt="npm version"></a>
|
|
25
|
+
<a href="https://github.com/ai-guard-dev/eslint-plugin-ai-guard/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/ai-guard-dev/eslint-plugin-ai-guard/ci.yml?style=flat-square&label=CI&color=10b981" alt="CI Status"></a>
|
|
26
|
+
<a href="https://www.npmjs.com/package/eslint-plugin-ai-guard"><img src="https://img.shields.io/npm/dm/eslint-plugin-ai-guard.svg?style=flat-square&color=3b82f6" alt="npm downloads"></a>
|
|
27
|
+
<a href="https://github.com/ai-guard-dev/eslint-plugin-ai-guard/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-64748b?style=flat-square" alt="MIT License"></a>
|
|
28
|
+
<a href="https://github.com/ai-guard-dev/eslint-plugin-ai-guard/blob/main/SECURITY.md"><img src="https://img.shields.io/badge/security-policy-orange?style=flat-square" alt="Security Policy"></a>
|
|
29
|
+
<a href="https://getaiguard.dev"><img src="https://img.shields.io/badge/website-getaiguard.dev-0ea5e9?style=flat-square" alt="Website"></a>
|
|
30
|
+
</p>
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## What is AI Guard?
|
|
35
|
+
|
|
36
|
+
**AI Guard** (`eslint-plugin-ai-guard`) provides:
|
|
37
|
+
- **ESLint plugin** with 27 deterministic rules and 4 presets (`recommended`, `strict`, `security`, `agent`)
|
|
38
|
+
- **CLI** (`ai-guard`) for terminal, changed-file, and CI scanning
|
|
39
|
+
- **GitHub Action** with native SARIF 2.1.0 output for GitHub Code Scanning
|
|
40
|
+
- **Check integrity** (`ai-guard integrity`) — detects changes that weaken checks: new suppressions, skipped or removed tests, lowered ESLint/TypeScript/coverage settings, removed CI steps
|
|
41
|
+
- **Agent safety**: `ai-guard verify` (one verdict for a change), `ai-guard scan-agent-config` (hidden text and prompt injection in `CLAUDE.md`, skills and MCP config), and `changed --test-integrity` (weakened tests)
|
|
42
|
+
- **Claude Code integration** with hooks that send findings back to Claude and, when it finishes, block once on weakened checks and on problems the session introduced
|
|
43
|
+
- **MCP server** (`ai-guard-mcp`, 8 tools) for local AI-agent workflows over STDIO
|
|
44
|
+
|
|
45
|
+
It is engineered to detect reliability bugs, async hazards, security vulnerabilities, and code-scaffolding defects frequently introduced during AI-assisted development (GitHub Copilot, Cursor, Claude Code, Gemini Code Assist, etc.).
|
|
46
|
+
|
|
47
|
+
AI Guard analyzes Abstract Syntax Trees (AST) using ESLint's native engine. It runs locally in your editor, in your terminal via the zero-config CLI, and in your CI/CD pipelines via native SARIF 2.1.0 integration with GitHub Code Scanning.
|
|
48
|
+
|
|
49
|
+
### What AI Guard is NOT
|
|
50
|
+
|
|
51
|
+
> [!IMPORTANT]
|
|
52
|
+
> - **AI Guard is NOT an AI detector.** It does not attempt to predict whether code was authored by an LLM or a human.
|
|
53
|
+
> - **AI Guard detects dangerous or fragile code patterns** that LLMs repeatedly introduce due to incomplete context, hallucinated patterns, or probabilistic generation.
|
|
54
|
+
> - **AI Guard does NOT replace ESLint.** It extends ESLint with 27 specialized, high-impact rules that core ESLint and standard configurations omit.
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Why AI Guard?
|
|
59
|
+
|
|
60
|
+
AI coding assistants write code at remarkable velocity, but generated code repeatedly suffers from predictable reliability and security anti-patterns that conventional linters miss:
|
|
61
|
+
|
|
62
|
+
| Pattern | Why AI Assistants Generate It | Real-World Impact |
|
|
63
|
+
| :--- | :--- | :--- |
|
|
64
|
+
| **Floating Promises** | Omits `await`, `return`, or `.catch()` on async calls | Unhandled promise rejections, silent failures in background jobs |
|
|
65
|
+
| **Async Array Iteration** | Passes async callbacks into `array.map()` or `.filter()` | Returns unawaited `Promise[]` instead of resolved values |
|
|
66
|
+
| **Sequential Awaits in Loops** | Loops over items with sequential `await` | Significant latency bottlenecks; blocks event loop execution |
|
|
67
|
+
| **Empty Catch Blocks** | Inserts generic `try { ... } catch (e) {}` blocks | Swallows production exceptions silently without telemetry |
|
|
68
|
+
| **Hardcoded Secrets** | Injects placeholder or real API keys/tokens | Credential leakage in version control and deployment bundles |
|
|
69
|
+
| **Dynamic `eval()`** | Generates dynamic function compilation | Arbitrary code execution and code injection |
|
|
70
|
+
| **Raw SQL Concatenation** | Concatenates query strings with variables | Severe SQL injection vulnerabilities |
|
|
71
|
+
| **Unsafe Deserialization** | Calls `JSON.parse(req.body)` directly without schema checks | Denial of service and unhandled runtime crashes |
|
|
72
|
+
| **Missing Route Auth & Authz** | Emits boilerplate endpoints without auth middleware | Unprotected API endpoints and IDOR privilege escalations |
|
|
73
|
+
| **Dead Branches & Scaffolding** | Leaves `if (true)` or conflicting conditions from prompt iterations | Bloated bundles and dead code paths |
|
|
74
|
+
|
|
75
|
+
AI Guard provides an instantaneous, deterministic feedback loop that catches these issues before they reach pull requests or production.
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## Architecture & Workflow
|
|
80
|
+
|
|
81
|
+
```mermaid
|
|
82
|
+
flowchart TD
|
|
83
|
+
subgraph Dev["1. Development & Prompt Phase"]
|
|
84
|
+
A["Developer + AI Coding Assistant\n(Copilot, Cursor, Claude Code)"] --> B["JavaScript / TypeScript Code"]
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
subgraph ShiftLeft["Shift Left — Context Injection"]
|
|
88
|
+
SL["npx ai-guard init-context"] -.-> CTX["CLAUDE.md\n.cursorrules\ncopilot-instructions.md"]
|
|
89
|
+
CTX -.-> A
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
subgraph Analysis["2. Deterministic AST Analysis"]
|
|
93
|
+
B --> C["ESLint Parser\n(espree / @typescript-eslint/parser)"]
|
|
94
|
+
C --> D["AST Representation"]
|
|
95
|
+
D --> E["AI Guard Rules Engine\n(27 Deterministic Rules)"]
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
subgraph Tiers["3. Classification & Presets"]
|
|
99
|
+
E --> F{"Active Preset\n(recommended | strict | security | agent)"}
|
|
100
|
+
F --> G["Confidence Tiering & AST Filtering"]
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
subgraph Outputs["4. Output & Remediation"]
|
|
104
|
+
G --> H["Local CLI Scanning\n(ai-guard run / changed)"]
|
|
105
|
+
G --> I["Autofix Remediation\n(eslint --fix)"]
|
|
106
|
+
G --> J["HTML Dashboard\n(ai-guard report)"]
|
|
107
|
+
G --> K["SARIF 2.1.0 Artifact\n(ai-guard --sarif)"]
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
subgraph CI["5. GitHub Pull Request & CI/CD"]
|
|
111
|
+
K --> L["GitHub Action\nai-guard-dev/eslint-plugin-ai-guard@v1"]
|
|
112
|
+
L --> M["GitHub Code Scanning Alerts"]
|
|
113
|
+
L --> N["Inline PR Code Annotations"]
|
|
114
|
+
L --> O["PR Status Check (Blocks Merge)"]
|
|
115
|
+
end
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## Rules Catalog
|
|
121
|
+
|
|
122
|
+
AI Guard includes **27 deterministic rules** divided into four specialized categories. Every rule is engineered with low false-positive heuristics and validated against real-world production codebases:
|
|
123
|
+
|
|
124
|
+
### 🔴 Security (10 Rules)
|
|
125
|
+
|
|
126
|
+
| Rule | Recommended | What It Catches | Fixable? |
|
|
127
|
+
| :--- | :---: | :--- | :---: |
|
|
128
|
+
| [`no-hardcoded-secret`](./docs/rules/no-hardcoded-secret.md) | **`error`** | API keys, bearer tokens, passwords, and private keys committed directly in source code. | **Yes** (`process.env.*`) |
|
|
129
|
+
| [`no-eval-dynamic`](./docs/rules/no-eval-dynamic.md) | **`error`** | `eval()`, `new Function()`, and `setTimeout`/`setInterval` with dynamic/non-literal string expressions. | No |
|
|
130
|
+
| [`no-sql-string-concat`](./docs/rules/no-sql-string-concat.md) | `warn` | SQL queries constructed by string concatenation or raw template literals — SQL injection risks. | No |
|
|
131
|
+
| [`no-unsafe-deserialize`](./docs/rules/no-unsafe-deserialize.md) | `warn` | Unchecked `JSON.parse()` called directly on HTTP request inputs (`req.body`, `req.query`, `req.params`). | No |
|
|
132
|
+
| [`require-auth-middleware`](./docs/rules/require-auth-middleware.md) | `warn` | Express and Fastify route definitions exposed without authentication middleware. | No |
|
|
133
|
+
| [`require-authz-check`](./docs/rules/require-authz-check.md) | `warn` | Endpoints accessing sensitive resources or user IDs without tenant/ownership authorization checks. | No |
|
|
134
|
+
| [`no-client-exposed-secret`](./docs/rules/no-client-exposed-secret.md) | **`error`** | Server secrets that reach the browser: `NEXT_PUBLIC_`/`VITE_`/`EXPO_PUBLIC_` prefixes on secret keys, server secrets in `"use client"` files, `dangerouslyAllowBrowser` with the app's own key. | No |
|
|
135
|
+
| [`no-invisible-unicode`](./docs/rules/no-invisible-unicode.md) | **`error`** | Trojan Source bidi overrides, zero-width and Hangul-filler characters, and Unicode tag characters that hide instructions for AI tools (decoded in the message). | **Yes** (escapes in strings, removal in comments) |
|
|
136
|
+
| [`no-unsanitized-html`](./docs/rules/no-unsanitized-html.md) | `warn` | Dynamic values in `innerHTML`, `insertAdjacentHTML`, `document.write` and `dangerouslySetInnerHTML`, with sharper messages for URL input, LLM output, markdown and JSON-LD. | No |
|
|
137
|
+
| [`no-undeclared-import`](./docs/rules/no-undeclared-import.md) | `warn` | Imports of packages missing from package.json: hallucinated names (slopsquatting) and phantom dependencies. Offline and monorepo-aware. | No |
|
|
138
|
+
|
|
139
|
+
### 🟠 Reliability (5 Rules)
|
|
140
|
+
|
|
141
|
+
| Rule | Recommended | What It Catches | Fixable? |
|
|
142
|
+
| :--- | :---: | :--- | :---: |
|
|
143
|
+
| [`no-empty-catch`](./docs/rules/no-empty-catch.md) | **`error`** | Empty `catch (e) {}` blocks that silently swallow exceptions without logging or rethrowing. | **Yes** (inserts `/* TODO: handle error */`) |
|
|
144
|
+
| [`no-broad-exception`](./docs/rules/no-broad-exception.md) | `warn` | Catching broad exception types like `catch (e: any)` that mask system faults and typing. | No |
|
|
145
|
+
| [`no-catch-log-rethrow`](./docs/rules/no-catch-log-rethrow.md) | `off`* | Catch blocks that only log to `console` and rethrow without adding context or diagnostic info. | No |
|
|
146
|
+
| [`no-catch-without-use`](./docs/rules/no-catch-without-use.md) | `off`* | Caught error variables that are declared in catch parameters but never referenced. | No |
|
|
147
|
+
| [`no-silent-fallback`](./docs/rules/no-silent-fallback.md) | `warn` | Secret env vars with hardcoded fallbacks (`process.env.JWT_SECRET \|\| 'secret'`) and `catch { return [] }` around awaited I/O. | No |
|
|
148
|
+
|
|
149
|
+
### 🟡 Async Stability (5 Rules)
|
|
150
|
+
|
|
151
|
+
| Rule | Recommended | What It Catches | Fixable? |
|
|
152
|
+
| :--- | :---: | :--- | :---: |
|
|
153
|
+
| [`no-floating-promise`](./docs/rules/no-floating-promise.md) | **`error`** | Async function invocations without `await`, `.catch()`, or `return` — leading to silent dropped errors. | **Yes** (marks with `void`) |
|
|
154
|
+
| [`no-async-array-callback`](./docs/rules/no-async-array-callback.md) | `warn` | Async callbacks passed to `map()`, `filter()`, `forEach()`, or `reduce()` returning `Promise[]`. | No |
|
|
155
|
+
| [`no-await-in-loop`](./docs/rules/no-await-in-loop.md) | `warn` | Sequential `await` in loops where iterations can be safely executed concurrently with `Promise.all`. | **Yes** (rewrites to `Promise.all`) |
|
|
156
|
+
| [`no-async-without-await`](./docs/rules/no-async-without-await.md) | `warn` | Functions declared `async` that never execute an `await` expression, adding unnecessary Promise overhead. | No |
|
|
157
|
+
| [`no-redundant-await`](./docs/rules/no-redundant-await.md) | `off`* | Redundant `return await` statements outside of `try...catch` blocks. | No |
|
|
158
|
+
|
|
159
|
+
### 🔵 AI Patterns (7 Rules)
|
|
160
|
+
|
|
161
|
+
| Rule | Recommended | What It Catches | Fixable? |
|
|
162
|
+
| :--- | :---: | :--- | :---: |
|
|
163
|
+
| [`no-dead-branch`](./docs/rules/no-dead-branch.md) | `warn` | Unreachable or tautological branches (`if (true)`, `if (false)`, `x && !x`) left behind from LLM code synthesis. | No |
|
|
164
|
+
| [`no-duplicate-logic-block`](./docs/rules/no-duplicate-logic-block.md) | `off`* | Consecutive duplicate code blocks or repeated conditional branches duplicated during AI edits. | No |
|
|
165
|
+
| [`no-console-in-handler`](./docs/rules/no-console-in-handler.md) | `off`* | Unstructured `console.log` statements left in HTTP route handlers instead of production loggers. | No |
|
|
166
|
+
| [`no-placeholder-implementation`](./docs/rules/no-placeholder-implementation.md) | `warn` | Code an agent left unfinished: `// ... rest of the code` elisions that delete code, TODO-only stubs, `throw new Error('Not implemented')` bodies, and mock data served from production code. | No |
|
|
167
|
+
| [`no-tautological-assertion`](./docs/rules/no-tautological-assertion.md) | `warn` | Assertions that always pass: `expect(true).toBe(true)`, `expect(x).toEqual(x)`, `assert.ok(1)`. | No |
|
|
168
|
+
| [`no-assertionless-test`](./docs/rules/no-assertionless-test.md) | `warn` | Test cases with no assertion, which pass whatever the code does. | No |
|
|
169
|
+
| [`no-test-env-branch`](./docs/rules/no-test-env-branch.md) | `warn` | Production code that returns a canned result under a test runner (`if (NODE_ENV === 'test') return true`). | No |
|
|
170
|
+
|
|
171
|
+
*\* Enabled at `error` level in the `strict` preset.*
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## Agent Safety
|
|
176
|
+
|
|
177
|
+
Linting checks the code. These check the agent:
|
|
178
|
+
|
|
179
|
+
| Feature | What it does |
|
|
180
|
+
| :--- | :--- |
|
|
181
|
+
| [`ai-guard verify`](./docs/cli/verify.md) | One verdict for the current change: lint findings it introduced, weakened tests, and agent-config issues. Pre-existing problems never block. |
|
|
182
|
+
| [`ai-guard integrity`](./docs/integrity.md) | Everything that weakens checks vs a base revision: new suppressions, skipped or removed tests, lowered coverage and TypeScript settings, removed CI steps. |
|
|
183
|
+
| [`ai-guard changed --test-integrity`](./docs/cli/test-integrity.md) | A test-focused comparison: focused, skipped, removed or weakened tests, rewritten snapshots, and test commands that can no longer fail. Overlaps with `integrity`; use `integrity` for the full set. |
|
|
184
|
+
| [`ai-guard scan-agent-config`](./docs/cli/scan-agent-config.md) | Scans `CLAUDE.md`, `AGENTS.md`, `.cursorrules`, skills and MCP configs for hidden text, prompt injection, unpinned MCP servers and inline secrets. |
|
|
185
|
+
| [Claude Code hooks](./docs/integrations/claude-code.md) | Findings reach Claude after each edit. When Claude finishes, the whole change is verified; what is still unresolved is shown to you. |
|
|
186
|
+
| [MCP tools](./docs/mcp-server.md) | `ai_guard_scan_file`, `ai_guard_scan_diff`, `ai_guard_scan_project`, `ai_guard_rules`, `ai_guard_check_integrity`, `ai_guard_verify_change`, `ai_guard_scan_agent_config`, and `ai_guard_fix` (a diff, unless `apply` is set). |
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## Presets
|
|
191
|
+
|
|
192
|
+
AI Guard exports four official configurations ready for flat config or legacy setups:
|
|
193
|
+
|
|
194
|
+
| Preset | Description | Configuration Focus |
|
|
195
|
+
| :--- | :--- | :--- |
|
|
196
|
+
| **`recommended`** | **Default.** Balanced adoption preset. Enables 6 high-confidence critical rules at `error`, 16 context-sensitive rules at `warn`, and disables 5 noisy rules. Zero noise on day one. | Production codebases, new teams |
|
|
197
|
+
| **`strict`** | Enforces **all 27 rules at `error`**. Designed for zero-tolerance CI gates, high-assurance software, and mature teams. | Strict CI/CD quality gates |
|
|
198
|
+
| **`security`** | Focuses on the **11 security-relevant rules** (secrets, eval, SQL, client-exposed secrets, invisible Unicode and HTML sinks at `error`; the rest at `warn`). | AppSec auditing & security scans |
|
|
199
|
+
| **`agent`** | **8 high-signal rules at `error`**. Optimized for AI-agent editing workflows where lint feedback runs immediately after each file edit (e.g., PostToolUse hooks). | Claude Code, Cursor, real-time agent loops |
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
## Quick Start & Installation
|
|
204
|
+
|
|
205
|
+
Install the package as a development dependency using your package manager:
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
# npm
|
|
209
|
+
npm install --save-dev eslint-plugin-ai-guard
|
|
210
|
+
|
|
211
|
+
# pnpm
|
|
212
|
+
pnpm add -D eslint-plugin-ai-guard
|
|
213
|
+
|
|
214
|
+
# yarn
|
|
215
|
+
yarn add -D eslint-plugin-ai-guard
|
|
216
|
+
|
|
217
|
+
# bun
|
|
218
|
+
bun add -d eslint-plugin-ai-guard
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Requirements
|
|
222
|
+
|
|
223
|
+
- **Node.js:** `>= 20.0.0`
|
|
224
|
+
- **ESLint:** `>= 8.0.0` (Supports both Flat Config and legacy configs)
|
|
225
|
+
- **TypeScript (optional):** `@typescript-eslint/parser >= 6.0.0` for TypeScript AST parsing
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## ESLint Configuration
|
|
230
|
+
|
|
231
|
+
### 1. Modern Flat Config (`eslint.config.mjs` / `eslint.config.js`)
|
|
232
|
+
|
|
233
|
+
AI Guard exports full native support for modern ESLint Flat Config:
|
|
234
|
+
|
|
235
|
+
```javascript
|
|
236
|
+
// eslint.config.mjs
|
|
237
|
+
import aiGuard from 'eslint-plugin-ai-guard';
|
|
238
|
+
|
|
239
|
+
export default [
|
|
240
|
+
{
|
|
241
|
+
plugins: {
|
|
242
|
+
'ai-guard': aiGuard,
|
|
243
|
+
},
|
|
244
|
+
rules: {
|
|
245
|
+
...aiGuard.configs.recommended.rules,
|
|
246
|
+
// Custom overrides if desired:
|
|
247
|
+
'ai-guard/no-floating-promise': 'error',
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
];
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
To use the `strict` or `security` preset in flat config:
|
|
254
|
+
|
|
255
|
+
```javascript
|
|
256
|
+
// Strict preset — all 27 rules at error
|
|
257
|
+
rules: {
|
|
258
|
+
...aiGuard.configs.strict.rules,
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Security preset — security rules only
|
|
262
|
+
rules: {
|
|
263
|
+
...aiGuard.configs.security.rules,
|
|
264
|
+
}
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### 2. Legacy Config (`.eslintrc.js` / `.eslintrc.json`)
|
|
268
|
+
|
|
269
|
+
```javascript
|
|
270
|
+
// .eslintrc.js
|
|
271
|
+
module.exports = {
|
|
272
|
+
plugins: ['ai-guard'],
|
|
273
|
+
extends: ['plugin:ai-guard/recommended'],
|
|
274
|
+
};
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
---
|
|
278
|
+
|
|
279
|
+
## CLI Reference
|
|
280
|
+
|
|
281
|
+
AI Guard includes a full-featured CLI binary (`ai-guard`) that runs out of the box with zero ESLint configuration files required:
|
|
282
|
+
|
|
283
|
+
```bash
|
|
284
|
+
npx ai-guard <command> [options]
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### Core Commands
|
|
288
|
+
|
|
289
|
+
| Command | Purpose | Common Options |
|
|
290
|
+
| :--- | :--- | :--- |
|
|
291
|
+
| `run` | Scan your workspace using AI Guard AST rules | `--path <dir>`, `--strict`, `--security`, `--json`, `--sarif`, `--fail-on <level>`, `--max-warnings <n>`, `--inline-suppressions <mode>` |
|
|
292
|
+
| `changed` | Fast CI scan — only scans modified files in git | `--pr`, `--staged`, `--base <branch>`, `--baseline [file]`, `--integrity <off\|report\|enforce>`, `--test-integrity`, `--inline-suppressions <mode>`, `--strict`, `--sarif`, `--sarif-output <file>`, `--fail-on <level>` |
|
|
293
|
+
| `verify` | One verdict for the current change ([docs](./docs/cli/verify.md)) | `--base <ref>`, `--staged`, `--preset <name>`, `--strict`, `--json` |
|
|
294
|
+
| `scan-agent-config` | Scan agent instructions and MCP config ([docs](./docs/cli/scan-agent-config.md)) | `--path <dir>`, `--json`, `--sarif`, `--fail-on <level>`, `--update-lock` |
|
|
295
|
+
| `integrity` | Detect changes that weaken checks vs a base revision ([docs](./docs/integrity.md)) | `--base <ref>`, `--pr`, `--staged`, `--enforce`, `--json`, `--sarif`, `--accept <fingerprints\|all>` |
|
|
296
|
+
| `init` | Automatically detect environment & configure ESLint | `--preset <name>`, `--flat`, `--dry-run`, `-y, --yes` |
|
|
297
|
+
| `init-context` | Generate prompt instruction files for AI coding agents | `-a, --all`, `--force`, `--dry-run`, `--rules <categories>` |
|
|
298
|
+
| `doctor` | Diagnose your ESLint, parser, and plugin environment | (No options needed — prints actionable diagnostic report) |
|
|
299
|
+
| `baseline` | Record existing findings, then report only new ones | `create`, `check`, `--fail-on <level>`, `--json`, `--mode <strict\|stable>`, `--preset <name>` |
|
|
300
|
+
| `report` | Generate an interactive standalone HTML audit report | `--path <dir>`, `--preset <name>`, `--output <file>`, `--no-open`, `--json` |
|
|
301
|
+
| `preset` | Interactively select and switch active preset in config | (Interactive prompt with automatic config patch & backup) |
|
|
302
|
+
| `ignore` | Add standard ignore paths (`.next`, `dist`, `build`) to config | (Patches flat config or legacy ignores safely) |
|
|
303
|
+
|
|
304
|
+
**`run` exit codes:** `0` no errors · `1` errors found (or `--max-warnings` exceeded) · `2` scan did not run — the file passed to `--path` matches a built-in ignore pattern (`node_modules/`, `dist/`, `build/`, `generated/`, `vendor/`, …), so nothing was analyzed. Directory scans skip ignored files silently and never exit `2`.
|
|
305
|
+
|
|
306
|
+
### CLI Usage Examples
|
|
307
|
+
|
|
308
|
+
```bash
|
|
309
|
+
# 1. Immediate scan of current directory
|
|
310
|
+
npx ai-guard run
|
|
311
|
+
|
|
312
|
+
# 2. Strict CI scan failing only on high-confidence issues
|
|
313
|
+
npx ai-guard run --strict --fail-on high
|
|
314
|
+
|
|
315
|
+
# 3. Pull Request scan (diffs against PR target branch)
|
|
316
|
+
npx ai-guard changed --pr --sarif --sarif-output results.sarif
|
|
317
|
+
|
|
318
|
+
# 4. Generate AI agent guardrails for Cursor, Claude Code, and Copilot
|
|
319
|
+
npx ai-guard init-context --all
|
|
320
|
+
|
|
321
|
+
# 5. Generate interactive HTML diagnostic report
|
|
322
|
+
npx ai-guard report --output ai-guard-report.html
|
|
323
|
+
|
|
324
|
+
# 6. Save existing issues as baseline and only fail on new regressions
|
|
325
|
+
npx ai-guard baseline create # writes .ai-guard-baseline.json (commit it)
|
|
326
|
+
npx ai-guard baseline check # exit 1 if any new finding
|
|
327
|
+
npx ai-guard baseline check --fail-on high # fail only on new high-confidence findings
|
|
328
|
+
npx ai-guard baseline check --json # machine-readable new findings
|
|
329
|
+
|
|
330
|
+
# 7. Fail a PR that skips tests, adds eslint-disable, or lowers coverage thresholds
|
|
331
|
+
npx ai-guard changed --pr --integrity enforce
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
### Inline suppressions never hide findings silently
|
|
335
|
+
|
|
336
|
+
AI Guard reads `eslint-disable` directives itself; ESLint's own inline config is disabled in AI Guard's private ESLint instance, so a comment cannot make a finding vanish without a trace. `--inline-suppressions` selects the policy:
|
|
337
|
+
|
|
338
|
+
| Mode | Effect |
|
|
339
|
+
|---|---|
|
|
340
|
+
| `allow` (default) | A covering directive hides the finding from totals and exit codes; it is listed under "Hidden by inline directives" (JSON `suppressedIssues`, step summary, SARIF `suppressedFindingsCount`) |
|
|
341
|
+
| `require-reason` | Only directives with a ` -- reason` hide findings (used by the Claude Code hook) |
|
|
342
|
+
| `ignore` | Directives never hide AI Guard findings (always used by the MCP server) |
|
|
343
|
+
|
|
344
|
+
This applies to `ai-guard run`, `changed`, the GitHub Action, the Claude Code hook and MCP. It does not change how your own `eslint .` treats directives. TypeScript comments (`@ts-ignore`, `@ts-nocheck`) never affect AI Guard findings; `ai-guard integrity` reports newly added ones.
|
|
345
|
+
|
|
346
|
+
---
|
|
347
|
+
|
|
348
|
+
## AI Agent Integration (`init-context`)
|
|
349
|
+
|
|
350
|
+
Standard linters only run **after** code has already been written. The `init-context` command shifts your guardrails left by embedding AI Guard's rules directly into the instruction files loaded by your AI coding tools:
|
|
351
|
+
|
|
352
|
+
```bash
|
|
353
|
+
npx ai-guard init-context --all
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
This generates three targeted context files:
|
|
357
|
+
1. **`CLAUDE.md`** — Automatically loaded by **Claude Code**
|
|
358
|
+
2. **`.cursorrules`** — Automatically loaded by **Cursor**
|
|
359
|
+
3. **`.github/copilot-instructions.md`** — Automatically loaded by **GitHub Copilot**
|
|
360
|
+
|
|
361
|
+
### How Shift-Left Works
|
|
362
|
+
|
|
363
|
+
```
|
|
364
|
+
AI Guard (init-context)
|
|
365
|
+
↓
|
|
366
|
+
Generates project guardrail files (CLAUDE.md, .cursorrules, copilot-instructions.md)
|
|
367
|
+
↓
|
|
368
|
+
AI coding assistant reads safety rules before generating code
|
|
369
|
+
↓
|
|
370
|
+
Model avoids floating promises, empty catches, and hardcoded secrets at prompt time
|
|
371
|
+
↓
|
|
372
|
+
AI Guard CLI & GitHub Action deterministically verifies the output in CI
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
This dual-layer defense minimizes review friction and ensures generated code meets your security standard on the first pass.
|
|
376
|
+
|
|
377
|
+
---
|
|
378
|
+
|
|
379
|
+
## Claude Code Integration
|
|
380
|
+
|
|
381
|
+
AI Guard integrates directly with [Claude Code](https://code.claude.com/docs/en/hooks) through hooks:
|
|
382
|
+
|
|
383
|
+
```bash
|
|
384
|
+
# One-command setup
|
|
385
|
+
npx ai-guard init-claude
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
- **PostToolUse** — after each edit, findings from the `agent` preset and newly weakened checks in the edited file are sent back to Claude (`decision: "block"` + `reason`, per the hooks protocol). Earlier versions printed plain stdout, which Claude Code does not show to Claude.
|
|
389
|
+
- **SessionStart + Stop** — before Claude finishes, [check integrity](./docs/integrity.md) runs on everything changed in the session. High-confidence weakenings (a new `.skip`, `eslint-disable`, lowered threshold…) block stopping once per finding set; advisories are shown to you, never block. The same hook then [verifies](./docs/cli/verify.md) lint findings and agent-config issues the session introduced (placeholder code, a canned return under a test runner, a hidden instruction in `CLAUDE.md`), which also block once. Skip both with `--no-stop-hook`.
|
|
390
|
+
- **PreToolUse (Bash)** — `git commit --no-verify` / `HUSKY=0` ask for confirmation.
|
|
391
|
+
|
|
392
|
+
```bash
|
|
393
|
+
# Preview before applying
|
|
394
|
+
npx ai-guard init-claude --dry-run
|
|
395
|
+
|
|
396
|
+
# Use per-machine settings (gitignored)
|
|
397
|
+
npx ai-guard init-claude --local
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
**Agent preset rules (8):** `no-hardcoded-secret`, `no-eval-dynamic`, `no-empty-catch`, `no-sql-string-concat`, `no-floating-promise`, `no-client-exposed-secret`, `no-invisible-unicode`, `no-undeclared-import`
|
|
401
|
+
|
|
402
|
+
→ [Full documentation](./docs/integrations/claude-code.md)
|
|
403
|
+
|
|
404
|
+
---
|
|
405
|
+
|
|
406
|
+
## GitHub Action
|
|
407
|
+
|
|
408
|
+
The official AI Guard GitHub Action runs on PRs, detects changed files, provides step summaries, outputs SARIF 2.1.0, and posts inline PR annotations directly on GitHub:
|
|
409
|
+
|
|
410
|
+
```yaml
|
|
411
|
+
# .github/workflows/ai-guard.yml
|
|
412
|
+
name: AI Guard
|
|
413
|
+
|
|
414
|
+
on:
|
|
415
|
+
pull_request:
|
|
416
|
+
branches: [main, develop]
|
|
417
|
+
push:
|
|
418
|
+
branches: [main]
|
|
419
|
+
|
|
420
|
+
jobs:
|
|
421
|
+
ai-guard-scan:
|
|
422
|
+
name: AI Guard Code Review
|
|
423
|
+
runs-on: ubuntu-latest
|
|
424
|
+
|
|
425
|
+
permissions:
|
|
426
|
+
contents: read
|
|
427
|
+
security-events: write
|
|
428
|
+
actions: read
|
|
429
|
+
|
|
430
|
+
steps:
|
|
431
|
+
- name: Checkout Code
|
|
432
|
+
uses: actions/checkout@v4
|
|
433
|
+
with:
|
|
434
|
+
fetch-depth: 0 # Required for git diff comparison
|
|
435
|
+
|
|
436
|
+
- name: Setup Node.js
|
|
437
|
+
uses: actions/setup-node@v4
|
|
438
|
+
with:
|
|
439
|
+
node-version: 20
|
|
440
|
+
cache: 'npm'
|
|
441
|
+
|
|
442
|
+
- name: Run AI Guard
|
|
443
|
+
uses: ai-guard-dev/eslint-plugin-ai-guard@v1
|
|
444
|
+
with:
|
|
445
|
+
preset: 'recommended'
|
|
446
|
+
fail-on: 'high'
|
|
447
|
+
changed-only: 'true'
|
|
448
|
+
upload-sarif: 'true'
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
### Action Inputs (`action.yml`)
|
|
452
|
+
|
|
453
|
+
| Input | Description | Default |
|
|
454
|
+
| :--- | :--- | :---: |
|
|
455
|
+
| `preset` | Rule preset: `recommended` \| `strict` \| `security` | `'recommended'` |
|
|
456
|
+
| `fail-on` | Severity threshold to fail CI: `high` \| `medium` \| `any` \| `none` | `'high'` |
|
|
457
|
+
| `changed-only` | Scan only files changed in this PR / commit | `'true'` |
|
|
458
|
+
| `path` | Target file or directory to scan | `'.'` |
|
|
459
|
+
| `upload-sarif` | Upload results to GitHub Code Scanning | `'true'` |
|
|
460
|
+
| `github-summary` | Write an execution breakdown to the GitHub Actions Job Summary | `'true'` |
|
|
461
|
+
| `working-directory`| Working directory for scanning (ideal for monorepos) | `'.'` |
|
|
462
|
+
| `package-manager` | Package manager: `auto` \| `npm` \| `pnpm` \| `yarn` | `'auto'` |
|
|
463
|
+
| `sarif-output` | Output filepath for generated SARIF report | `'ai-guard-results.sarif'` |
|
|
464
|
+
| `install-deps` | Install project dependencies prior to scanning | `'true'` |
|
|
465
|
+
| `baseline` | Committed baseline file; with `changed-only`, report only findings not in it | `''` |
|
|
466
|
+
| `integrity` | Check integrity: `off` \| `report` \| `enforce` (needs `changed-only` and `fetch-depth: 0`) | `'off'` |
|
|
467
|
+
| `test-integrity` | With `changed-only`, also flag tests the PR deleted, skipped, focused or weakened (needs `fetch-depth: 0`) | `'false'` |
|
|
468
|
+
| `inline-suppressions` | `allow` \| `require-reason` \| `ignore` for eslint-disable directives covering AI Guard findings | `''` (allow) |
|
|
469
|
+
|
|
470
|
+
### Action Outputs
|
|
471
|
+
|
|
472
|
+
| Output | Description |
|
|
473
|
+
| :--- | :--- |
|
|
474
|
+
| `issues-found` | Total number of issues found across scanned files |
|
|
475
|
+
| `high-confidence-count` | Number of high-confidence issues flagged |
|
|
476
|
+
| `medium-confidence-count` | Number of medium-confidence issues flagged |
|
|
477
|
+
| `files-scanned` | Count of files analyzed during the execution |
|
|
478
|
+
| `integrity-high-count` | High-confidence check-integrity findings (when `integrity` is enabled) |
|
|
479
|
+
| `integrity-advisory-count` | Advisory check-integrity findings (when `integrity` is enabled) |
|
|
480
|
+
| `sarif-file` | Absolute path to the generated SARIF 2.1.0 artifact |
|
|
481
|
+
| `duration-ms` | Total scan execution duration in milliseconds |
|
|
482
|
+
|
|
483
|
+
---
|
|
484
|
+
|
|
485
|
+
## SARIF & GitHub Code Scanning
|
|
486
|
+
|
|
487
|
+
AI Guard natively outputs **SARIF 2.1.0** (`Static Analysis Results Interchange Format`). When uploaded via the GitHub Action or `github/codeql-action/upload-sarif@v3`, findings integrate directly with GitHub Advanced Security:
|
|
488
|
+
|
|
489
|
+
- **Inline PR Annotations:** Direct comments on the exact source lines where flaws exist.
|
|
490
|
+
- **Security Dashboard:** Persistent alerts under your repository's `Security → Code scanning` tab.
|
|
491
|
+
- **Merge Protection:** Block merges automatically when high-confidence security or async bugs are detected.
|
|
492
|
+
|
|
493
|
+
### Visual Previews
|
|
494
|
+
|
|
495
|
+
#### Inline Pull Request Annotations
|
|
496
|
+
<img src="./assets/ss9.jpg" alt="AI Guard PR Inline Annotations" width="1000" />
|
|
497
|
+
|
|
498
|
+
#### GitHub Advanced Security Summary
|
|
499
|
+
<img src="./assets/ss10.jpg" alt="GitHub Advanced Security Summary for AI Guard" width="1000" />
|
|
500
|
+
|
|
501
|
+
#### Persistent Code Scanning Dashboard
|
|
502
|
+
<img src="./assets/ss11.jpg" alt="GitHub Code Scanning Alerts List" width="1000" />
|
|
503
|
+
|
|
504
|
+
---
|
|
505
|
+
|
|
506
|
+
## Rule Examples (Before & After)
|
|
507
|
+
|
|
508
|
+
### 1. `no-floating-promise` (Unhandled Promises)
|
|
509
|
+
|
|
510
|
+
```typescript
|
|
511
|
+
// ❌ BAD: Floating promise. Errors are dropped silently.
|
|
512
|
+
async function syncUserProfile(user: User) {
|
|
513
|
+
sendTelemetryEvent('user_sync', user.id);
|
|
514
|
+
database.save(user);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// ✅ GOOD: Awaited, explicitly handled, or marked with void
|
|
518
|
+
async function syncUserProfile(user: User) {
|
|
519
|
+
await database.save(user);
|
|
520
|
+
void sendTelemetryEvent('user_sync', user.id); // Explicitly unhandled
|
|
521
|
+
}
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
### 2. `no-hardcoded-secret` (Committed Credentials)
|
|
525
|
+
|
|
526
|
+
```typescript
|
|
527
|
+
// ❌ BAD: Secret committed inline
|
|
528
|
+
const client = new PaymentGateway({
|
|
529
|
+
apiKey: 'sk-prod-983427598273498273948273',
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
// ✅ GOOD: Read from environment variable (Autofixable!)
|
|
533
|
+
const client = new PaymentGateway({
|
|
534
|
+
apiKey: process.env.API_KEY,
|
|
535
|
+
});
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
### 3. `no-await-in-loop` (Sequential Latency Trap)
|
|
539
|
+
|
|
540
|
+
```typescript
|
|
541
|
+
// ❌ BAD: Consecutive awaits block each iteration sequentially
|
|
542
|
+
async function fetchAllUsers(ids: string[]) {
|
|
543
|
+
const users = [];
|
|
544
|
+
for (const id of ids) {
|
|
545
|
+
users.push(await fetchUser(id));
|
|
546
|
+
}
|
|
547
|
+
return users;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// ✅ GOOD: Concurrently fetched with Promise.all (Autofixable!)
|
|
551
|
+
async function fetchAllUsers(ids: string[]) {
|
|
552
|
+
return await Promise.all(ids.map((id) => fetchUser(id)));
|
|
553
|
+
}
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
### 4. `no-empty-catch` (Swallowed Errors)
|
|
557
|
+
|
|
558
|
+
```typescript
|
|
559
|
+
// ❌ BAD: Exception swallowed without trace
|
|
560
|
+
try {
|
|
561
|
+
parseConfiguration(rawConfig);
|
|
562
|
+
} catch (e) {}
|
|
563
|
+
|
|
564
|
+
// ✅ GOOD: Logged, rethrown, or documented (Autofixable!)
|
|
565
|
+
try {
|
|
566
|
+
parseConfiguration(rawConfig);
|
|
567
|
+
} catch (e) {
|
|
568
|
+
logger.error('Configuration parsing failed', { error: e });
|
|
569
|
+
throw e;
|
|
570
|
+
}
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
### 5. `no-sql-string-concat` (SQL Injection)
|
|
574
|
+
|
|
575
|
+
```typescript
|
|
576
|
+
// ❌ BAD: Dynamic string interpolation in SQL
|
|
577
|
+
const query = `SELECT * FROM users WHERE organization_id = '${orgId}' AND role = '${role}'`;
|
|
578
|
+
await db.query(query);
|
|
579
|
+
|
|
580
|
+
// ✅ GOOD: Parameterized query binding
|
|
581
|
+
const query = 'SELECT * FROM users WHERE organization_id = $1 AND role = $2';
|
|
582
|
+
await db.query(query, [orgId, role]);
|
|
583
|
+
```
|
|
584
|
+
|
|
585
|
+
---
|
|
586
|
+
|
|
587
|
+
## Automatic Remediation (Autofix)
|
|
588
|
+
|
|
589
|
+
Rules that have deterministic solutions provide automatic autofix handlers. Run ESLint's native `--fix` flag to automatically resolve them:
|
|
590
|
+
|
|
591
|
+
```bash
|
|
592
|
+
npx eslint . --fix
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
| Rule | Automatic Fix Behavior |
|
|
596
|
+
| :--- | :--- |
|
|
597
|
+
| `no-hardcoded-secret` | Replaces hardcoded string literal with `process.env.VARIABLE_NAME` |
|
|
598
|
+
| `no-empty-catch` | Inserts `/* TODO: handle error */` comment to prevent silent swallowing |
|
|
599
|
+
| `no-floating-promise` | Prepends `void ` expression to intentionally unawaited calls |
|
|
600
|
+
| `no-await-in-loop` | Rewrites straightforward sequential loops to `await Promise.all(...)` |
|
|
601
|
+
|
|
602
|
+
---
|
|
603
|
+
|
|
604
|
+
## Benchmarks & Empirical Evaluation
|
|
605
|
+
|
|
606
|
+
AI Guard has been empirically evaluated across multiple benchmarks comparing runtime scan performance, coverage gaps vs. standard tooling, and detection accuracy across real-world codebases.
|
|
607
|
+
|
|
608
|
+
### 1. What AI Guard Catches vs. Conventional Linters
|
|
609
|
+
|
|
610
|
+
Conventional linters either omit AI-specific hazards entirely or require heavyweight TypeScript type-checking (`parserOptions.project`) that significantly slows down CI:
|
|
611
|
+
|
|
612
|
+
| Pattern | AI Guard Rule | ESLint Core | `@typescript-eslint` |
|
|
613
|
+
| :--- | :--- | :---: | :--- |
|
|
614
|
+
| **Floating Promises** (unawaited async call) | [`no-floating-promise`](./docs/rules/no-floating-promise.md) | ❌ None | `@typescript-eslint/no-floating-promises` *(requires type info)* |
|
|
615
|
+
| **Async Array Callbacks** (`.map(async ...)`) | [`no-async-array-callback`](./docs/rules/no-async-array-callback.md) | ❌ None | Partial: `no-misused-promises` *(requires type info)* |
|
|
616
|
+
| **Empty Catch Blocks** (swallowed errors) | [`no-empty-catch`](./docs/rules/no-empty-catch.md) | `no-empty` *(weaker)* | ❌ None |
|
|
617
|
+
| **Hardcoded Secrets / API Tokens** | [`no-hardcoded-secret`](./docs/rules/no-hardcoded-secret.md) | ❌ None | ❌ None |
|
|
618
|
+
| **Raw SQL String Concatenation** | [`no-sql-string-concat`](./docs/rules/no-sql-string-concat.md) | ❌ None | ❌ None |
|
|
619
|
+
| **Missing Route Auth Middleware** | [`require-auth-middleware`](./docs/rules/require-auth-middleware.md) | ❌ None | ❌ None |
|
|
620
|
+
| **Missing Route Authorization Checks** | [`require-authz-check`](./docs/rules/require-authz-check.md) | ❌ None | ❌ None |
|
|
621
|
+
| **Dynamic `eval()` / `new Function()`** | [`no-eval-dynamic`](./docs/rules/no-eval-dynamic.md) | `no-eval` *(blanket ban)* | ❌ None |
|
|
622
|
+
| **Unsafe `JSON.parse(req.body)`** | [`no-unsafe-deserialize`](./docs/rules/no-unsafe-deserialize.md) | ❌ None | ❌ None |
|
|
623
|
+
| **Async Without Await** | [`no-async-without-await`](./docs/rules/no-async-without-await.md) | ❌ None | `require-await` |
|
|
624
|
+
| **Sequential Await in Loop** | [`no-await-in-loop`](./docs/rules/no-await-in-loop.md) | `no-await-in-loop` *(no fix)* | ❌ None |
|
|
625
|
+
| **Dead Code Branches (`if (true)`)** | [`no-dead-branch`](./docs/rules/no-dead-branch.md) | ❌ None | ❌ None |
|
|
626
|
+
| **Secrets exposed to the browser** (`NEXT_PUBLIC_*_SECRET`) | [`no-client-exposed-secret`](./docs/rules/no-client-exposed-secret.md) | ❌ None | ❌ None |
|
|
627
|
+
| **Trojan Source / hidden Unicode instructions** | [`no-invisible-unicode`](./docs/rules/no-invisible-unicode.md) | Partial: `no-irregular-whitespace` *(whitespace only)* | ❌ None |
|
|
628
|
+
| **Hallucinated / undeclared packages** | [`no-undeclared-import`](./docs/rules/no-undeclared-import.md) | ❌ None | ❌ None |
|
|
629
|
+
| **Unsanitized HTML sinks (XSS)** | [`no-unsanitized-html`](./docs/rules/no-unsanitized-html.md) | ❌ None | ❌ None |
|
|
630
|
+
| **Hardcoded secret fallbacks** | [`no-silent-fallback`](./docs/rules/no-silent-fallback.md) | ❌ None | ❌ None |
|
|
631
|
+
| **Elided / stubbed code left by agents** | [`no-placeholder-implementation`](./docs/rules/no-placeholder-implementation.md) | Partial: `no-warning-comments` *(TODO text only)* | ❌ None |
|
|
632
|
+
|
|
633
|
+
> [!TIP]
|
|
634
|
+
> **Minimal Type-Information Dependency:** 26 of 27 AI Guard rules operate in pure syntax/scope-analysis mode without `projectService` or `tsconfig.json`. The `no-floating-promise` rule optionally uses TypeScript parser services for higher recall on cross-module Promise calls, with syntax/scope-based heuristics as a zero-config fallback.
|
|
635
|
+
|
|
636
|
+
---
|
|
637
|
+
|
|
638
|
+
### 2. Runtime Performance
|
|
639
|
+
|
|
640
|
+
Benchmark: scanning 196 TypeScript / JavaScript files (`algorithm-automata-simulator`, Windows 11, Node.js 20, median of 3 runs):
|
|
641
|
+
|
|
642
|
+
| Tool / Mode | Scan Time | Configuration Overhead |
|
|
643
|
+
| :--- | :---: | :--- |
|
|
644
|
+
| **`ai-guard run --strict`** | **~1.8s** | **Zero config** (18 AST heuristic rules, no `tsconfig.json` needed) |
|
|
645
|
+
| `eslint .` (recommended) | ~2.5s | Core syntax rules only (misses floating promises & secrets) |
|
|
646
|
+
| `eslint .` (type-aware `@typescript-eslint`) | **~8–12s** | Requires full TS compiler graph binding (**4x–6x slower**) |
|
|
647
|
+
|
|
648
|
+
AI Guard executes **4x–6x faster** than type-aware linting suites because it leverages deterministic AST heuristics rather than reconstructing the full TypeScript symbol graph.
|
|
649
|
+
|
|
650
|
+
---
|
|
651
|
+
|
|
652
|
+
### 3. Empirical Bug Detection & Precision Study
|
|
653
|
+
|
|
654
|
+
Two comprehensive empirical benchmark evaluations were conducted to measure real-world precision and detection yields:
|
|
655
|
+
|
|
656
|
+
#### A. Accuracy & False Positive Audit (4 Real-World Repositories, 378 Files)
|
|
657
|
+
|
|
658
|
+
| Category | Findings | True Positives | False Positive Rate |
|
|
659
|
+
| :--- | :---: | :---: | :---: |
|
|
660
|
+
| **Security** (`no-hardcoded-secret`, `no-eval-dynamic`, etc.) | 15 | 15 | **0%** |
|
|
661
|
+
| **Reliability** (`no-empty-catch`, broad exceptions) | 53 | 53 | **0%** |
|
|
662
|
+
| **Async Stability** (`no-floating-promise`, async callbacks) | 43 | ~40 | **~7%** |
|
|
663
|
+
| **AI Patterns** (duplicate logic, dead branches) | 58 | 43 | **26%** *(reduced in v1.2.8+)* |
|
|
664
|
+
|
|
665
|
+
#### B. Dual-Mode Detection Study (48 Call Sites & Real Production Target)
|
|
666
|
+
|
|
667
|
+
Audited across a controlled multi-file test corpus (13 files, 48 call sites) and a real-world Express + MongoDB production application (`Truvita New`):
|
|
668
|
+
|
|
669
|
+
- **High Precision:** **100% precision** on type-aware exclusive findings (26 of 26 verified True Positives; 0 false alarms on synchronous controls).
|
|
670
|
+
- **Critical Detection:** Detected **1 critical database startup race condition** in production (`server/index.ts connectDB()`) where an unawaited connection call allowed requests to hit the database before initialization.
|
|
671
|
+
- **Single-File Actionability:** **100%** of findings were resolvable locally at the call site (`await`, `.catch()`, or `void`).
|
|
672
|
+
|
|
673
|
+
For the complete methodology, raw findings, and benchmark harness, see [**`docs/benchmarks.md`**](./docs/benchmarks.md).
|
|
674
|
+
|
|
675
|
+
---
|
|
676
|
+
|
|
677
|
+
## Performance & Philosophy
|
|
678
|
+
|
|
679
|
+
- **Zero LLM Overhead:** AI Guard does not call external APIs, does not incur token costs, and does not add LLM latency. A scan of 100+ files executes in milliseconds.
|
|
680
|
+
- **100% Deterministic:** Every finding is derived strictly from Abstract Syntax Tree analysis. No probabilistic drift, no non-deterministic hallucinated findings.
|
|
681
|
+
- **Low False Positives:** Built with precision-first design. Context-sensitive rules are configured at `warn` or `off` in the recommended preset so developers are never blocked by noise.
|
|
682
|
+
- **Self-Scanning:** AI Guard enforces its own rules on its own codebase in CI using the `strict` preset.
|
|
683
|
+
|
|
684
|
+
---
|
|
685
|
+
|
|
686
|
+
## MCP Server (Model Context Protocol)
|
|
687
|
+
|
|
688
|
+
AI Guard includes a local MCP server that exposes its deterministic analysis engine to MCP-capable AI clients (Claude Code, Claude Desktop, and other MCP-compatible integrations).
|
|
689
|
+
|
|
690
|
+
```bash
|
|
691
|
+
npx --yes --package eslint-plugin-ai-guard ai-guard-mcp
|
|
692
|
+
```
|
|
693
|
+
|
|
694
|
+
**Available tools:**
|
|
695
|
+
|
|
696
|
+
| Tool | Description |
|
|
697
|
+
| :--- | :--- |
|
|
698
|
+
| `ai_guard_scan_file` | Scan a single JS/TS file with structured findings |
|
|
699
|
+
| `ai_guard_scan_diff` | Scan changed files in git diff (including newly created untracked JS/TS files) |
|
|
700
|
+
| `ai_guard_scan_project` | Scan a bounded workspace directory (current source; not yet published) |
|
|
701
|
+
| `ai_guard_rules` | List rules and presets, or look up specific rules (`rules: ["no-floating-promise"]`) with remediation and docs link |
|
|
702
|
+
| `ai_guard_check_integrity` | Report checks weakened by current Git changes (new suppressions, skipped/removed tests, lowered configs, removed CI steps), with `tier` and `hasBlockingFindings` |
|
|
703
|
+
|
|
704
|
+
All tools declare an `outputSchema`; the text content is the same result as compact JSON. Scan tools accept `maxIssues` (default 50, errors first, exact `totalIssues` and `truncated`). The `verify_changes` prompt runs the scan → fix → rescan loop.
|
|
705
|
+
|
|
706
|
+
**Claude Code configuration** (project-root `.mcp.json`):
|
|
707
|
+
|
|
708
|
+
```json
|
|
709
|
+
{
|
|
710
|
+
"mcpServers": {
|
|
711
|
+
"ai-guard": {
|
|
712
|
+
"type": "stdio",
|
|
713
|
+
"command": "node",
|
|
714
|
+
"args": ["/absolute/path/to/ai-guard/dist/mcp/server.js"],
|
|
715
|
+
"env": { "AI_GUARD_WORKSPACE": "/absolute/path/to/project" }
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
```
|
|
720
|
+
|
|
721
|
+
The SDK in-memory and built STDIO integrations are tested, plus a headless Claude Code CLI smoke test (see the MCP guide for scope). Use the built checkout to test unreleased changes. Scan, fix, then rescan; a partial or failed scan is never clean. For setup, result status, limits, and client verification scope, see [**`docs/mcp-server.md`**](./docs/mcp-server.md).
|
|
722
|
+
|
|
723
|
+
---
|
|
724
|
+
|
|
725
|
+
## Learn More & Ecosystem
|
|
726
|
+
|
|
727
|
+
Visit [getaiguard.dev](https://getaiguard.dev) to explore interactive documentation, rule catalogs, benchmarks, and deep-dive engineering articles.
|
|
728
|
+
|
|
729
|
+
### Official Links
|
|
730
|
+
|
|
731
|
+
- **Website:** [https://getaiguard.dev](https://getaiguard.dev)
|
|
732
|
+
- **GitHub Organization:** [https://github.com/ai-guard-dev](https://github.com/ai-guard-dev)
|
|
733
|
+
- **Repository:** [https://github.com/ai-guard-dev/eslint-plugin-ai-guard](https://github.com/ai-guard-dev/eslint-plugin-ai-guard)
|
|
734
|
+
- **npm Registry:** [https://www.npmjs.com/package/eslint-plugin-ai-guard](https://www.npmjs.com/package/eslint-plugin-ai-guard)
|
|
735
|
+
- **GitHub Action:** [ai-guard-dev/eslint-plugin-ai-guard@v1](https://github.com/ai-guard-dev/eslint-plugin-ai-guard)
|
|
736
|
+
|
|
737
|
+
---
|
|
738
|
+
|
|
739
|
+
## Contributing
|
|
740
|
+
|
|
741
|
+
We welcome contributions, new rule ideas, bug reports, and false-positive reports!
|
|
742
|
+
|
|
743
|
+
1. Check out our [Contributing Guide](CONTRIBUTING.md) for local setup and testing standards.
|
|
744
|
+
2. Review our [Security Policy](SECURITY.md) to report vulnerabilities responsibly.
|
|
745
|
+
3. Check open issues or submit new ones on our [Issue Tracker](https://github.com/ai-guard-dev/eslint-plugin-ai-guard/issues).
|
|
746
|
+
|
|
747
|
+
---
|
|
748
|
+
|
|
749
|
+
## License
|
|
750
|
+
|
|
751
|
+
[MIT](LICENSE) © AI Guard Authors. Free and open source forever.
|