eslint-plugin-ai-guard 1.4.7 โ 1.4.9
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 +88 -41
- package/dist/cli/hook.js +5117 -17147
- package/dist/cli/index.js +5445 -31314
- package/dist/index.d.mts +124 -48
- package/dist/index.d.ts +124 -48
- package/dist/index.js +3586 -911
- package/dist/index.mjs +3635 -963
- package/dist/mcp/server.js +5141 -59639
- package/package.json +117 -110
- package/dist/cli/hook.js.map +0 -1
- package/dist/cli/index.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/mcp/server.js.map +0 -1
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
## What is AI Guard?
|
|
35
35
|
|
|
36
36
|
**AI Guard** (`eslint-plugin-ai-guard`) provides:
|
|
37
|
-
- **ESLint plugin** with
|
|
37
|
+
- **ESLint plugin** with 33 deterministic rules and 4 presets (`recommended`, `strict`, `security`, `agent`)
|
|
38
38
|
- **CLI** (`ai-guard`) for terminal, changed-file, and CI scanning
|
|
39
39
|
- **GitHub Action** with native SARIF 2.1.0 output for GitHub Code Scanning
|
|
40
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
|
|
@@ -52,7 +52,7 @@ Measured on 12 November 2026 with 1.4.6. Methods, raw numbers and the commands t
|
|
|
52
52
|
- **0 of 1,361** real dependencies blocked (763 from 15 large open-source projects, 598 from 9 apps)
|
|
53
53
|
- **34 of 36** names from the 2017 crossenv malware campaign blocked
|
|
54
54
|
- **3.0%** of the 5,000 most-downloaded packages had a latest release under a day old, the window the fresh-release check covers
|
|
55
|
-
- **
|
|
55
|
+
- **33 of 33** rules give identical results in ESLint and Oxlint, checked in CI
|
|
56
56
|
|
|
57
57
|
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.).
|
|
58
58
|
|
|
@@ -63,7 +63,7 @@ AI Guard analyzes Abstract Syntax Trees (AST) using ESLint's native engine. It r
|
|
|
63
63
|
> [!IMPORTANT]
|
|
64
64
|
> - **AI Guard is NOT an AI detector.** It does not attempt to predict whether code was authored by an LLM or a human.
|
|
65
65
|
> - **AI Guard detects dangerous or fragile code patterns** that LLMs repeatedly introduce due to incomplete context, hallucinated patterns, or probabilistic generation.
|
|
66
|
-
> - **AI Guard does NOT replace ESLint.** It extends ESLint with
|
|
66
|
+
> - **AI Guard does NOT replace ESLint.** It extends ESLint with 33 specialized, high-impact rules that core ESLint and standard configurations omit.
|
|
67
67
|
|
|
68
68
|
---
|
|
69
69
|
|
|
@@ -104,7 +104,7 @@ flowchart TD
|
|
|
104
104
|
subgraph Analysis["2. Deterministic AST Analysis"]
|
|
105
105
|
B --> C["ESLint Parser\n(espree / @typescript-eslint/parser)"]
|
|
106
106
|
C --> D["AST Representation"]
|
|
107
|
-
D --> E["AI Guard Rules Engine\n(
|
|
107
|
+
D --> E["AI Guard Rules Engine\n(33 Deterministic Rules)"]
|
|
108
108
|
end
|
|
109
109
|
|
|
110
110
|
subgraph Tiers["3. Classification & Presets"]
|
|
@@ -131,9 +131,9 @@ flowchart TD
|
|
|
131
131
|
|
|
132
132
|
## Rules Catalog
|
|
133
133
|
|
|
134
|
-
AI Guard includes **
|
|
134
|
+
AI Guard includes **33 deterministic rules** divided into four specialized categories. Every rule is engineered with low false-positive heuristics and validated against real-world production codebases:
|
|
135
135
|
|
|
136
|
-
### ๐ด Security (
|
|
136
|
+
### ๐ด Security (13 Rules)
|
|
137
137
|
|
|
138
138
|
| Rule | Recommended | What It Catches | Fixable? |
|
|
139
139
|
| :--- | :---: | :--- | :---: |
|
|
@@ -147,8 +147,11 @@ AI Guard includes **27 deterministic rules** divided into four specialized categ
|
|
|
147
147
|
| [`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) |
|
|
148
148
|
| [`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 |
|
|
149
149
|
| [`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 |
|
|
150
|
+
| [`no-insecure-random`](./docs/rules/no-insecure-random.md) | `warn` | `Math.random()` used for tokens, passwords, one-time codes, reset links and other values that must be unguessable. | No |
|
|
151
|
+
| [`no-jwt-decode-as-verify`](./docs/rules/no-jwt-decode-as-verify.md) | `warn` | `jsonwebtoken` `decode()` in a file that never calls `verify()`: the signature is never checked, so tokens can be forged. | No |
|
|
152
|
+
| [`no-permissive-cors`](./docs/rules/no-permissive-cors.md) | `warn` | CORS that accepts every origin (`origin: true`, an allow-all callback, a reflected `Origin` header) while allowing credentials. | No |
|
|
150
153
|
|
|
151
|
-
### ๐ Reliability (
|
|
154
|
+
### ๐ Reliability (6 Rules)
|
|
152
155
|
|
|
153
156
|
| Rule | Recommended | What It Catches | Fixable? |
|
|
154
157
|
| :--- | :---: | :--- | :---: |
|
|
@@ -157,6 +160,7 @@ AI Guard includes **27 deterministic rules** divided into four specialized categ
|
|
|
157
160
|
| [`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 |
|
|
158
161
|
| [`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 |
|
|
159
162
|
| [`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 |
|
|
163
|
+
| [`no-unvalidated-cast`](./docs/rules/no-unvalidated-cast.md) | `off`* | `res.json()`, `JSON.parse()` or `req.body` cast to a type (`as User`) without runtime validation. TypeScript only. | No |
|
|
160
164
|
|
|
161
165
|
### ๐ก Async Stability (5 Rules)
|
|
162
166
|
|
|
@@ -164,11 +168,11 @@ AI Guard includes **27 deterministic rules** divided into four specialized categ
|
|
|
164
168
|
| :--- | :---: | :--- | :---: |
|
|
165
169
|
| [`no-floating-promise`](./docs/rules/no-floating-promise.md) | **`error`** | Async function invocations without `await`, `.catch()`, or `return` โ leading to silent dropped errors. | No (editor suggestions: `await`, or `void` if intended) |
|
|
166
170
|
| [`no-async-array-callback`](./docs/rules/no-async-array-callback.md) | `warn` | Async callbacks passed to `map()`, `filter()`, `forEach()`, or `reduce()` returning `Promise[]`. | No |
|
|
167
|
-
| [`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`. |
|
|
171
|
+
| [`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`. | Suggestion (`Promise.all`) |
|
|
168
172
|
| [`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 |
|
|
169
173
|
| [`no-redundant-await`](./docs/rules/no-redundant-await.md) | `off`* | Redundant `return await` statements outside of `try...catch` blocks. | No |
|
|
170
174
|
|
|
171
|
-
### ๐ต AI Patterns (
|
|
175
|
+
### ๐ต AI Patterns (9 Rules)
|
|
172
176
|
|
|
173
177
|
| Rule | Recommended | What It Catches | Fixable? |
|
|
174
178
|
| :--- | :---: | :--- | :---: |
|
|
@@ -176,6 +180,8 @@ AI Guard includes **27 deterministic rules** divided into four specialized categ
|
|
|
176
180
|
| [`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 |
|
|
177
181
|
| [`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 |
|
|
178
182
|
| [`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 |
|
|
183
|
+
| [`no-unknown-export`](./docs/rules/no-unknown-export.md) | `warn` | Names, subpaths and default imports the installed package does not export: `import { useQueryState } from 'react-router'`. Reports only when the package's full export list is proven (checked against Node's loader and the TypeScript compiler on 400+ packages). Suggests the closest real export. | No |
|
|
184
|
+
| [`no-stale-api`](./docs/rules/no-stale-api.md) | `warn` | APIs the installed package version has removed, which models keep writing from older training data: `ReactDOM.render` on React 19, `useHistory` on React Router 6, the openai v3 client, Express 5 removals. Reads the installed version offline. | No |
|
|
179
185
|
| [`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 |
|
|
180
186
|
| [`no-assertionless-test`](./docs/rules/no-assertionless-test.md) | `warn` | Test cases with no assertion, which pass whatever the code does. | No |
|
|
181
187
|
| [`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 |
|
|
@@ -195,9 +201,11 @@ Linting checks the code. These check the agent:
|
|
|
195
201
|
| [`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. |
|
|
196
202
|
| [`ai-guard verify-deps`](./docs/cli/verify-deps.md) | Checks npm packages before they are installed: names that don't exist (invented by assistants), look-alikes of popular packages, new or rarely used packages, install scripts, deprecations, and releases published in the last day (skipped when the package manager enforces a release cooldown). Also as a pre-install hook for Claude Code, Cursor and Codex (`init-hooks --check-installs`) and the `ai_guard_check_package` MCP tool. Uses the npm registry; private registries are skipped. |
|
|
197
203
|
| [`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. |
|
|
204
|
+
| [`ai-guard duplicates`](./docs/cli/duplicates.md) | Code the change copied from elsewhere in the repository, renamed variables and changed literals included (winnowing over parser tokens; 38โ39 of 40 real copies found in every variant of the validation benchmark, no false reports on unrelated code). Also disclosed by `verify`, so agents are told before they finish. |
|
|
198
205
|
| [Agent hooks: Claude Code, Cursor, Codex](./docs/integrations/agents.md) | `ai-guard init-hooks` sets up every agent a project uses. Findings reach the agent after edits; before it finishes, the whole change is verified once; `git commit --no-verify` and risky installs are caught before they run. |
|
|
199
206
|
| [Pre-commit gate](./docs/integrations/git-hook.md) | `ai-guard init-git-hook` runs `verify --staged` on every commit through husky, lefthook, simple-git-hooks or pre-commit. Only problems the commit introduces block it. |
|
|
200
207
|
| [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`, `ai_guard_check_package`, and `ai_guard_fix` (a diff, unless `apply` is set). |
|
|
208
|
+
| [Kits and shared configs](./docs/integrations/kits.md) | Ship AI Guard rules in your own lint kit or preset: version ranges, what stays stable in 1.x, ESLint and Oxlint setup, and which rules to pick. |
|
|
201
209
|
|
|
202
210
|
---
|
|
203
211
|
|
|
@@ -207,16 +215,32 @@ AI Guard exports four official configurations ready for flat config or legacy se
|
|
|
207
215
|
|
|
208
216
|
| Preset | Description | Configuration Focus |
|
|
209
217
|
| :--- | :--- | :--- |
|
|
210
|
-
| **`recommended`** | **Default.** Balanced adoption preset. Enables 6 high-confidence critical rules at `error`,
|
|
211
|
-
| **`strict`** | Enforces **all
|
|
212
|
-
| **`security`** | Focuses on the **
|
|
218
|
+
| **`recommended`** | **Default.** Balanced adoption preset. Enables 6 high-confidence critical rules at `error`, 21 context-sensitive rules at `warn`, and disables 6 noisy rules. Zero noise on day one. | Production codebases, new teams |
|
|
219
|
+
| **`strict`** | Enforces **all 33 rules at `error`**. Designed for zero-tolerance CI gates, high-assurance software, and mature teams. | Strict CI/CD quality gates |
|
|
220
|
+
| **`security`** | Focuses on the **14 security-relevant rules** (secrets, eval, SQL, client-exposed secrets, invisible Unicode and HTML sinks at `error`; the rest at `warn`). | AppSec auditing & security scans |
|
|
213
221
|
| **`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 |
|
|
214
222
|
|
|
215
223
|
---
|
|
216
224
|
|
|
217
225
|
## Quick Start & Installation
|
|
218
226
|
|
|
219
|
-
|
|
227
|
+
**Try it first, without installing anything or touching your config:**
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
npx eslint-plugin-ai-guard run
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
It scans the current project with the `recommended` preset and changes no files. No ESLint configuration is needed. In a TypeScript project without `@typescript-eslint/parser`, add `-p @typescript-eslint/parser` (`npx -p eslint-plugin-ai-guard -p @typescript-eslint/parser ai-guard run`) so `.ts` files are parsed.
|
|
234
|
+
|
|
235
|
+
**One command sets up everything:**
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
npx eslint-plugin-ai-guard protect
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
It installs AI Guard as a devDependency (plus `@typescript-eslint/parser` in TypeScript projects), adds hooks for the coding agents the project uses (Claude Code, Cursor, Codex), adds a pre-commit gate, checks `CLAUDE.md`, `AGENTS.md` and MCP config, and prints one screen saying what is now protected. Running it again changes nothing. Preview with `--dry-run`; agents can read `--json`. See [protect](./docs/cli/protect.md).
|
|
242
|
+
|
|
243
|
+
Or install the package yourself as a development dependency:
|
|
220
244
|
|
|
221
245
|
```bash
|
|
222
246
|
# npm
|
|
@@ -232,6 +256,17 @@ yarn add -D eslint-plugin-ai-guard
|
|
|
232
256
|
bun add -d eslint-plugin-ai-guard
|
|
233
257
|
```
|
|
234
258
|
|
|
259
|
+
> [!NOTE]
|
|
260
|
+
> Once AI Guard is installed in a project, its CLI is `ai-guard` (`npx ai-guard run`). Before it is installed, use the package name: `npx eslint-plugin-ai-guard run`. A bare `npx ai-guard` in a project without AI Guard fetches a different npm package that happens to be called `ai-guard`.
|
|
261
|
+
|
|
262
|
+
### Add a badge to your README
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
npx eslint-plugin-ai-guard badge
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
It scans the project, writes the result to `.github/ai-guard-badge.json` (a [shields.io endpoint](https://shields.io/badges/endpoint-badge) file) and prints the Markdown for your README. The badge shows what the scan found: `passing`, a warning count or an error count. Commit the file. To keep the badge current, run the command in CI on pushes to your default branch; see [badge](./docs/cli/badge.md). Nothing is sent anywhere: shields.io reads the file from your repository.
|
|
269
|
+
|
|
235
270
|
### Requirements
|
|
236
271
|
|
|
237
272
|
- **Node.js:** `>= 20.0.0`
|
|
@@ -242,43 +277,33 @@ bun add -d eslint-plugin-ai-guard
|
|
|
242
277
|
|
|
243
278
|
## ESLint Configuration
|
|
244
279
|
|
|
245
|
-
### 1.
|
|
280
|
+
### 1. Flat Config (ESLint 9 and 10: `eslint.config.mjs` / `eslint.config.js`)
|
|
246
281
|
|
|
247
|
-
|
|
282
|
+
Each `flat/` preset is a complete flat config that registers the plugin itself:
|
|
248
283
|
|
|
249
284
|
```javascript
|
|
250
285
|
// eslint.config.mjs
|
|
251
286
|
import aiGuard from 'eslint-plugin-ai-guard';
|
|
252
287
|
|
|
288
|
+
export default [aiGuard.configs['flat/recommended']];
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
Use `aiGuard.configs['flat/strict']` (all 33 rules at error), `aiGuard.configs['flat/security']` (security rules only) or `aiGuard.configs['flat/agent']` (8 high-signal rules for agent hooks) the same way. To override a rule, add a config object after the preset:
|
|
292
|
+
|
|
293
|
+
```javascript
|
|
253
294
|
export default [
|
|
295
|
+
aiGuard.configs['flat/recommended'],
|
|
254
296
|
{
|
|
255
|
-
plugins: {
|
|
256
|
-
'ai-guard': aiGuard,
|
|
257
|
-
},
|
|
258
297
|
rules: {
|
|
259
|
-
...aiGuard.configs.recommended.rules,
|
|
260
|
-
// Custom overrides if desired:
|
|
261
298
|
'ai-guard/no-floating-promise': 'error',
|
|
262
299
|
},
|
|
263
300
|
},
|
|
264
301
|
];
|
|
265
302
|
```
|
|
266
303
|
|
|
267
|
-
|
|
304
|
+
Spreading the rules into your own config object (`plugins: { 'ai-guard': aiGuard }, rules: { ...aiGuard.configs.recommended.rules }`) keeps working.
|
|
268
305
|
|
|
269
|
-
|
|
270
|
-
// Strict preset โ all 27 rules at error
|
|
271
|
-
rules: {
|
|
272
|
-
...aiGuard.configs.strict.rules,
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// Security preset โ security rules only
|
|
276
|
-
rules: {
|
|
277
|
-
...aiGuard.configs.security.rules,
|
|
278
|
-
}
|
|
279
|
-
```
|
|
280
|
-
|
|
281
|
-
### 2. Legacy Config (`.eslintrc.js` / `.eslintrc.json`)
|
|
306
|
+
### 2. Legacy Config (ESLint 8, or ESLint 9 with `ESLINT_USE_FLAT_CONFIG=false`)
|
|
282
307
|
|
|
283
308
|
```javascript
|
|
284
309
|
// .eslintrc.js
|
|
@@ -288,6 +313,9 @@ module.exports = {
|
|
|
288
313
|
};
|
|
289
314
|
```
|
|
290
315
|
|
|
316
|
+
> [!NOTE]
|
|
317
|
+
> 2.0 will make the plain preset names (`recommended`, `strict`, `security`, `agent`) flat configs. To be ready, `.eslintrc` files can already use the aliases `plugin:ai-guard/legacy-recommended` (and `legacy-strict`, `legacy-security`, `legacy-agent`), which keep working after that upgrade. ESLint 10 no longer reads `.eslintrc` files at all.
|
|
318
|
+
|
|
291
319
|
---
|
|
292
320
|
|
|
293
321
|
## CLI Reference
|
|
@@ -295,18 +323,21 @@ module.exports = {
|
|
|
295
323
|
AI Guard includes a full-featured CLI binary (`ai-guard`) that runs out of the box with zero ESLint configuration files required:
|
|
296
324
|
|
|
297
325
|
```bash
|
|
298
|
-
npx ai-guard <command> [options]
|
|
326
|
+
npx ai-guard <command> [options] # AI Guard installed in the project
|
|
327
|
+
npx eslint-plugin-ai-guard <command> [options] # not installed (first run, one-off scans)
|
|
299
328
|
```
|
|
300
329
|
|
|
301
330
|
### Core Commands
|
|
302
331
|
|
|
303
332
|
| Command | Purpose | Common Options |
|
|
304
333
|
| :--- | :--- | :--- |
|
|
334
|
+
| `protect` | Set up everything in one step: install, agent hooks, pre-commit gate, agent-config check ([docs](./docs/cli/protect.md)) | `--agent <list>`, `--manager <name>`, `--check-installs`, `--no-install`, `--no-agent-hooks`, `--no-git-hook`, `--dry-run`, `--json` |
|
|
305
335
|
| `run` | Scan your workspace using AI Guard AST rules | `--path <dir>`, `--strict`, `--security`, `--json`, `--sarif`, `--fail-on <level>`, `--max-warnings <n>`, `--inline-suppressions <mode>` |
|
|
306
336
|
| `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>` |
|
|
307
337
|
| `verify` | One verdict for the current change ([docs](./docs/cli/verify.md)) | `--base <ref>`, `--staged`, `--preset <name>`, `--strict`, `--json` |
|
|
308
338
|
| `verify-deps` | Check npm packages before they are installed ([docs](./docs/cli/verify-deps.md)) | `[packages...]`, `--base <ref>`, `--staged`, `--all`, `--json`, `--sarif`, `--fail-on <level>` |
|
|
309
339
|
| `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` |
|
|
340
|
+
| `duplicates` | Report code a change copied from elsewhere in the repository ([docs](./docs/cli/duplicates.md)) | `--base <ref>`, `--staged`, `--all`, `--include-tests`, `--min-tokens <n>`, `--json`, `--sarif`, `--fail-on <level>` |
|
|
310
341
|
| `integrity` | Detect changes that weaken checks vs a base revision ([docs](./docs/integrity.md)) | `--base <ref>`, `--pr`, `--staged`, `--enforce`, `--json`, `--sarif`, `--accept <fingerprints\|all>` |
|
|
311
342
|
| `init` | Automatically detect environment & configure ESLint | `--preset <name>`, `--flat`, `--dry-run`, `-y, --yes` |
|
|
312
343
|
| `init-hooks` | Hooks for Claude Code, Cursor and Codex ([docs](./docs/integrations/agents.md)) | `--agent <list>`, `--check-installs`, `--no-stop-hook`, `--no-bash-guard`, `--dry-run` |
|
|
@@ -315,17 +346,21 @@ npx ai-guard <command> [options]
|
|
|
315
346
|
| `init-context` | Generate prompt instruction files for AI coding agents | `-a, --all`, `--force`, `--dry-run`, `--rules <categories>` |
|
|
316
347
|
| `doctor` | Diagnose your ESLint, parser, and plugin environment | (No options needed โ prints actionable diagnostic report) |
|
|
317
348
|
| `baseline` | Record existing findings, then report only new ones | `create`, `check`, `--fail-on <level>`, `--json`, `--mode <strict\|stable>`, `--preset <name>` |
|
|
349
|
+
| `badge` | Scan and write a README badge with the result ([docs](./docs/cli/badge.md)) | `--path <dir>`, `--preset <name>`, `--output <file>`, `--json` |
|
|
318
350
|
| `report` | Generate an interactive standalone HTML audit report | `--path <dir>`, `--preset <name>`, `--output <file>`, `--no-open`, `--json` |
|
|
319
351
|
| `preset` | Interactively select and switch active preset in config | (Interactive prompt with automatic config patch & backup) |
|
|
320
352
|
| `ignore` | Add standard ignore paths (`.next`, `dist`, `build`) to config | (Patches flat config or legacy ignores safely) |
|
|
321
353
|
|
|
322
|
-
**`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
|
|
354
|
+
**`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, or a file could not be parsed and was not checked (install `@typescript-eslint/parser` for TypeScript; `--fail-on none` exits `0`). Directory scans skip ignored files silently.
|
|
323
355
|
|
|
324
356
|
### CLI Usage Examples
|
|
325
357
|
|
|
326
358
|
```bash
|
|
327
|
-
#
|
|
328
|
-
npx ai-guard
|
|
359
|
+
# 0. Set up hooks, the pre-commit gate and the agent-config check in one step
|
|
360
|
+
npx eslint-plugin-ai-guard protect
|
|
361
|
+
|
|
362
|
+
# 1. Immediate scan of current directory (no install needed)
|
|
363
|
+
npx eslint-plugin-ai-guard run
|
|
329
364
|
|
|
330
365
|
# 2. Strict CI scan failing only on high-confidence issues
|
|
331
366
|
npx ai-guard run --strict --fail-on high
|
|
@@ -583,7 +618,7 @@ async function fetchAllUsers(ids: string[]) {
|
|
|
583
618
|
return users;
|
|
584
619
|
}
|
|
585
620
|
|
|
586
|
-
// โ
GOOD: Concurrently fetched with Promise.all (
|
|
621
|
+
// โ
GOOD: Concurrently fetched with Promise.all (editor suggestion)
|
|
587
622
|
async function fetchAllUsers(ids: string[]) {
|
|
588
623
|
return await Promise.all(ids.map((id) => fetchUser(id)));
|
|
589
624
|
}
|
|
@@ -631,7 +666,8 @@ npx eslint . --fix
|
|
|
631
666
|
| Rule | Automatic Fix Behavior |
|
|
632
667
|
| :--- | :--- |
|
|
633
668
|
| `no-hardcoded-secret` | Replaces hardcoded string literal with `process.env.VARIABLE_NAME` |
|
|
634
|
-
|
|
669
|
+
|
|
670
|
+
`no-await-in-loop` offers `await Promise.all(...)` as an editor suggestion only: running iterations in parallel changes their order and concurrency, so `--fix` never applies it.
|
|
635
671
|
|
|
636
672
|
`no-empty-catch` and `no-floating-promise` have no automatic fix on purpose. A fix that inserted a comment or `void` would make the finding disappear without handling the error, and an agent running `--fix` would do exactly that. Editors offer them as suggestions instead (rethrow; `await`, or `void` for an intended fire-and-forget call), which a person applies one at a time.
|
|
637
673
|
|
|
@@ -667,7 +703,7 @@ Conventional linters either omit AI-specific hazards entirely or require heavywe
|
|
|
667
703
|
| **Elided / stubbed code left by agents** | [`no-placeholder-implementation`](./docs/rules/no-placeholder-implementation.md) | Partial: `no-warning-comments` *(TODO text only)* | โ None |
|
|
668
704
|
|
|
669
705
|
> [!TIP]
|
|
670
|
-
> **Minimal Type-Information Dependency:**
|
|
706
|
+
> **Minimal Type-Information Dependency:** 32 of 33 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.
|
|
671
707
|
|
|
672
708
|
---
|
|
673
709
|
|
|
@@ -736,6 +772,10 @@ npx --yes --package eslint-plugin-ai-guard ai-guard-mcp
|
|
|
736
772
|
| `ai_guard_scan_project` | Scan a bounded workspace directory (at most 500 files; fails instead of truncating) |
|
|
737
773
|
| `ai_guard_rules` | List rules and presets, or look up specific rules (`rules: ["no-floating-promise"]`) with remediation and docs link |
|
|
738
774
|
| `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` |
|
|
775
|
+
| `ai_guard_verify_change` | One verdict before calling work done: introduced lint findings, weakened tests and agent-config issues (`pass`, `blocking`, `disclosures`) |
|
|
776
|
+
| `ai_guard_scan_agent_config` | Check CLAUDE.md, AGENTS.md, skills and MCP config for hidden text and prompt injection |
|
|
777
|
+
| `ai_guard_fix` | Apply deterministic autofixes to one file; returns a diff and writes only with `apply: true` |
|
|
778
|
+
| `ai_guard_check_package` | Check npm packages before installing them: missing names, look-alikes of popular packages, new or rarely used packages, install scripts (the only tool that uses the network: `registry.npmjs.org`) |
|
|
739
779
|
|
|
740
780
|
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.
|
|
741
781
|
|
|
@@ -756,6 +796,13 @@ All tools declare an `outputSchema`; the text content is the same result as comp
|
|
|
756
796
|
|
|
757
797
|
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).
|
|
758
798
|
|
|
799
|
+
### Glama listing
|
|
800
|
+
|
|
801
|
+
<a href="https://glama.ai/mcp/servers/ai-guard-dev/eslint-plugin-ai-guard"><img width="380" src="https://glama.ai/mcp/servers/ai-guard-dev/eslint-plugin-ai-guard/badge" alt="AI Guard MCP server" /></a>
|
|
802
|
+
|
|
803
|
+
AI Guard is listed on [Glama](https://glama.ai/mcp/servers/ai-guard-dev/eslint-plugin-ai-guard). There you can browse the server's tools, check its quality score, and test it online with [MCP Inspector](https://glama.ai/mcp/inspector).
|
|
804
|
+
|
|
805
|
+
|
|
759
806
|
---
|
|
760
807
|
|
|
761
808
|
## Learn More & Ecosystem
|