eslint-plugin-ai-guard 1.4.6 → 1.4.8
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 +98 -43
- package/dist/cli/hook.js +5116 -17146
- package/dist/cli/index.js +5449 -31314
- package/dist/index.d.mts +126 -50
- package/dist/index.d.ts +126 -50
- package/dist/index.js +3250 -892
- package/dist/index.mjs +3241 -886
- package/dist/mcp/server.js +5140 -59638
- package/package.json +112 -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
|
|
@@ -42,8 +42,18 @@
|
|
|
42
42
|
- **Hooks for Claude Code, Cursor and Codex** (`ai-guard init-hooks`): findings go back to the agent as it works, and it is stopped once before finishing on weakened checks or problems it introduced
|
|
43
43
|
- **A pre-commit gate** (`ai-guard init-git-hook`) that checks every commit, whichever agent or person wrote it
|
|
44
44
|
- **Works with Oxlint** as a JS plugin, with identical results checked in CI (`ai-guard init-oxlint`)
|
|
45
|
+
- **Package checks** (`ai-guard verify-deps`, an opt-in pre-install hook, and the `ai_guard_check_package` MCP tool): names that do not exist on npm, typosquats and npm security placeholders are blocked; install scripts, deprecations and releases from the last day are flagged
|
|
45
46
|
- **MCP server** (`ai-guard-mcp`, 9 tools) for local AI-agent workflows over STDIO
|
|
46
47
|
|
|
48
|
+
### Results on real projects
|
|
49
|
+
|
|
50
|
+
Measured on 12 November 2026 with 1.4.6. Methods, raw numbers and the commands to reproduce them: [docs/evidence.md](./docs/evidence.md).
|
|
51
|
+
|
|
52
|
+
- **0 of 1,361** real dependencies blocked (763 from 15 large open-source projects, 598 from 9 apps)
|
|
53
|
+
- **34 of 36** names from the 2017 crossenv malware campaign blocked
|
|
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
|
+
- **27 of 27** rules give identical results in ESLint and Oxlint, checked in CI
|
|
56
|
+
|
|
47
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.).
|
|
48
58
|
|
|
49
59
|
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.
|
|
@@ -53,7 +63,7 @@ AI Guard analyzes Abstract Syntax Trees (AST) using ESLint's native engine. It r
|
|
|
53
63
|
> [!IMPORTANT]
|
|
54
64
|
> - **AI Guard is NOT an AI detector.** It does not attempt to predict whether code was authored by an LLM or a human.
|
|
55
65
|
> - **AI Guard detects dangerous or fragile code patterns** that LLMs repeatedly introduce due to incomplete context, hallucinated patterns, or probabilistic generation.
|
|
56
|
-
> - **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.
|
|
57
67
|
|
|
58
68
|
---
|
|
59
69
|
|
|
@@ -94,7 +104,7 @@ flowchart TD
|
|
|
94
104
|
subgraph Analysis["2. Deterministic AST Analysis"]
|
|
95
105
|
B --> C["ESLint Parser\n(espree / @typescript-eslint/parser)"]
|
|
96
106
|
C --> D["AST Representation"]
|
|
97
|
-
D --> E["AI Guard Rules Engine\n(
|
|
107
|
+
D --> E["AI Guard Rules Engine\n(33 Deterministic Rules)"]
|
|
98
108
|
end
|
|
99
109
|
|
|
100
110
|
subgraph Tiers["3. Classification & Presets"]
|
|
@@ -121,9 +131,9 @@ flowchart TD
|
|
|
121
131
|
|
|
122
132
|
## Rules Catalog
|
|
123
133
|
|
|
124
|
-
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:
|
|
125
135
|
|
|
126
|
-
### 🔴 Security (
|
|
136
|
+
### 🔴 Security (13 Rules)
|
|
127
137
|
|
|
128
138
|
| Rule | Recommended | What It Catches | Fixable? |
|
|
129
139
|
| :--- | :---: | :--- | :---: |
|
|
@@ -137,28 +147,32 @@ AI Guard includes **27 deterministic rules** divided into four specialized categ
|
|
|
137
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) |
|
|
138
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 |
|
|
139
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 |
|
|
140
153
|
|
|
141
|
-
### 🟠 Reliability (
|
|
154
|
+
### 🟠 Reliability (6 Rules)
|
|
142
155
|
|
|
143
156
|
| Rule | Recommended | What It Catches | Fixable? |
|
|
144
157
|
| :--- | :---: | :--- | :---: |
|
|
145
|
-
| [`no-empty-catch`](./docs/rules/no-empty-catch.md) | **`error`** | Empty `catch (e) {}` blocks that silently swallow exceptions without logging or rethrowing. |
|
|
158
|
+
| [`no-empty-catch`](./docs/rules/no-empty-catch.md) | **`error`** | Empty `catch (e) {}` blocks that silently swallow exceptions without logging or rethrowing. | No (editor suggestion: rethrow) |
|
|
146
159
|
| [`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 |
|
|
147
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 |
|
|
148
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 |
|
|
149
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 |
|
|
150
164
|
|
|
151
165
|
### 🟡 Async Stability (5 Rules)
|
|
152
166
|
|
|
153
167
|
| Rule | Recommended | What It Catches | Fixable? |
|
|
154
168
|
| :--- | :---: | :--- | :---: |
|
|
155
|
-
| [`no-floating-promise`](./docs/rules/no-floating-promise.md) | **`error`** | Async function invocations without `await`, `.catch()`, or `return` — leading to silent dropped errors. |
|
|
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) |
|
|
156
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 |
|
|
157
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`. | **Yes** (rewrites to `Promise.all`) |
|
|
158
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 |
|
|
159
173
|
| [`no-redundant-await`](./docs/rules/no-redundant-await.md) | `off`* | Redundant `return await` statements outside of `try...catch` blocks. | No |
|
|
160
174
|
|
|
161
|
-
### 🔵 AI Patterns (
|
|
175
|
+
### 🔵 AI Patterns (9 Rules)
|
|
162
176
|
|
|
163
177
|
| Rule | Recommended | What It Catches | Fixable? |
|
|
164
178
|
| :--- | :---: | :--- | :---: |
|
|
@@ -166,6 +180,8 @@ AI Guard includes **27 deterministic rules** divided into four specialized categ
|
|
|
166
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 |
|
|
167
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 |
|
|
168
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 |
|
|
169
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 |
|
|
170
186
|
| [`no-assertionless-test`](./docs/rules/no-assertionless-test.md) | `warn` | Test cases with no assertion, which pass whatever the code does. | No |
|
|
171
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 |
|
|
@@ -185,6 +201,7 @@ Linting checks the code. These check the agent:
|
|
|
185
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. |
|
|
186
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. |
|
|
187
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. |
|
|
188
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. |
|
|
189
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. |
|
|
190
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). |
|
|
@@ -197,16 +214,32 @@ AI Guard exports four official configurations ready for flat config or legacy se
|
|
|
197
214
|
|
|
198
215
|
| Preset | Description | Configuration Focus |
|
|
199
216
|
| :--- | :--- | :--- |
|
|
200
|
-
| **`recommended`** | **Default.** Balanced adoption preset. Enables 6 high-confidence critical rules at `error`,
|
|
201
|
-
| **`strict`** | Enforces **all
|
|
202
|
-
| **`security`** | Focuses on the **
|
|
217
|
+
| **`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 |
|
|
218
|
+
| **`strict`** | Enforces **all 33 rules at `error`**. Designed for zero-tolerance CI gates, high-assurance software, and mature teams. | Strict CI/CD quality gates |
|
|
219
|
+
| **`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 |
|
|
203
220
|
| **`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 |
|
|
204
221
|
|
|
205
222
|
---
|
|
206
223
|
|
|
207
224
|
## Quick Start & Installation
|
|
208
225
|
|
|
209
|
-
|
|
226
|
+
**Try it first, without installing anything or touching your config:**
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
npx eslint-plugin-ai-guard run
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
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.
|
|
233
|
+
|
|
234
|
+
**One command sets up everything:**
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
npx eslint-plugin-ai-guard protect
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
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).
|
|
241
|
+
|
|
242
|
+
Or install the package yourself as a development dependency:
|
|
210
243
|
|
|
211
244
|
```bash
|
|
212
245
|
# npm
|
|
@@ -222,6 +255,17 @@ yarn add -D eslint-plugin-ai-guard
|
|
|
222
255
|
bun add -d eslint-plugin-ai-guard
|
|
223
256
|
```
|
|
224
257
|
|
|
258
|
+
> [!NOTE]
|
|
259
|
+
> 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`.
|
|
260
|
+
|
|
261
|
+
### Add a badge to your README
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
npx eslint-plugin-ai-guard badge
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
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.
|
|
268
|
+
|
|
225
269
|
### Requirements
|
|
226
270
|
|
|
227
271
|
- **Node.js:** `>= 20.0.0`
|
|
@@ -232,43 +276,33 @@ bun add -d eslint-plugin-ai-guard
|
|
|
232
276
|
|
|
233
277
|
## ESLint Configuration
|
|
234
278
|
|
|
235
|
-
### 1.
|
|
279
|
+
### 1. Flat Config (ESLint 9 and 10: `eslint.config.mjs` / `eslint.config.js`)
|
|
236
280
|
|
|
237
|
-
|
|
281
|
+
Each `flat/` preset is a complete flat config that registers the plugin itself:
|
|
238
282
|
|
|
239
283
|
```javascript
|
|
240
284
|
// eslint.config.mjs
|
|
241
285
|
import aiGuard from 'eslint-plugin-ai-guard';
|
|
242
286
|
|
|
287
|
+
export default [aiGuard.configs['flat/recommended']];
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
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:
|
|
291
|
+
|
|
292
|
+
```javascript
|
|
243
293
|
export default [
|
|
294
|
+
aiGuard.configs['flat/recommended'],
|
|
244
295
|
{
|
|
245
|
-
plugins: {
|
|
246
|
-
'ai-guard': aiGuard,
|
|
247
|
-
},
|
|
248
296
|
rules: {
|
|
249
|
-
...aiGuard.configs.recommended.rules,
|
|
250
|
-
// Custom overrides if desired:
|
|
251
297
|
'ai-guard/no-floating-promise': 'error',
|
|
252
298
|
},
|
|
253
299
|
},
|
|
254
300
|
];
|
|
255
301
|
```
|
|
256
302
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
```javascript
|
|
260
|
-
// Strict preset — all 27 rules at error
|
|
261
|
-
rules: {
|
|
262
|
-
...aiGuard.configs.strict.rules,
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// Security preset — security rules only
|
|
266
|
-
rules: {
|
|
267
|
-
...aiGuard.configs.security.rules,
|
|
268
|
-
}
|
|
269
|
-
```
|
|
303
|
+
Spreading the rules into your own config object (`plugins: { 'ai-guard': aiGuard }, rules: { ...aiGuard.configs.recommended.rules }`) keeps working.
|
|
270
304
|
|
|
271
|
-
### 2. Legacy Config (
|
|
305
|
+
### 2. Legacy Config (ESLint 8, or ESLint 9 with `ESLINT_USE_FLAT_CONFIG=false`)
|
|
272
306
|
|
|
273
307
|
```javascript
|
|
274
308
|
// .eslintrc.js
|
|
@@ -278,6 +312,9 @@ module.exports = {
|
|
|
278
312
|
};
|
|
279
313
|
```
|
|
280
314
|
|
|
315
|
+
> [!NOTE]
|
|
316
|
+
> 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.
|
|
317
|
+
|
|
281
318
|
---
|
|
282
319
|
|
|
283
320
|
## CLI Reference
|
|
@@ -285,18 +322,21 @@ module.exports = {
|
|
|
285
322
|
AI Guard includes a full-featured CLI binary (`ai-guard`) that runs out of the box with zero ESLint configuration files required:
|
|
286
323
|
|
|
287
324
|
```bash
|
|
288
|
-
npx ai-guard <command> [options]
|
|
325
|
+
npx ai-guard <command> [options] # AI Guard installed in the project
|
|
326
|
+
npx eslint-plugin-ai-guard <command> [options] # not installed (first run, one-off scans)
|
|
289
327
|
```
|
|
290
328
|
|
|
291
329
|
### Core Commands
|
|
292
330
|
|
|
293
331
|
| Command | Purpose | Common Options |
|
|
294
332
|
| :--- | :--- | :--- |
|
|
333
|
+
| `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` |
|
|
295
334
|
| `run` | Scan your workspace using AI Guard AST rules | `--path <dir>`, `--strict`, `--security`, `--json`, `--sarif`, `--fail-on <level>`, `--max-warnings <n>`, `--inline-suppressions <mode>` |
|
|
296
335
|
| `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>` |
|
|
297
336
|
| `verify` | One verdict for the current change ([docs](./docs/cli/verify.md)) | `--base <ref>`, `--staged`, `--preset <name>`, `--strict`, `--json` |
|
|
298
337
|
| `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>` |
|
|
299
338
|
| `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` |
|
|
339
|
+
| `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>` |
|
|
300
340
|
| `integrity` | Detect changes that weaken checks vs a base revision ([docs](./docs/integrity.md)) | `--base <ref>`, `--pr`, `--staged`, `--enforce`, `--json`, `--sarif`, `--accept <fingerprints\|all>` |
|
|
301
341
|
| `init` | Automatically detect environment & configure ESLint | `--preset <name>`, `--flat`, `--dry-run`, `-y, --yes` |
|
|
302
342
|
| `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` |
|
|
@@ -305,6 +345,7 @@ npx ai-guard <command> [options]
|
|
|
305
345
|
| `init-context` | Generate prompt instruction files for AI coding agents | `-a, --all`, `--force`, `--dry-run`, `--rules <categories>` |
|
|
306
346
|
| `doctor` | Diagnose your ESLint, parser, and plugin environment | (No options needed — prints actionable diagnostic report) |
|
|
307
347
|
| `baseline` | Record existing findings, then report only new ones | `create`, `check`, `--fail-on <level>`, `--json`, `--mode <strict\|stable>`, `--preset <name>` |
|
|
348
|
+
| `badge` | Scan and write a README badge with the result ([docs](./docs/cli/badge.md)) | `--path <dir>`, `--preset <name>`, `--output <file>`, `--json` |
|
|
308
349
|
| `report` | Generate an interactive standalone HTML audit report | `--path <dir>`, `--preset <name>`, `--output <file>`, `--no-open`, `--json` |
|
|
309
350
|
| `preset` | Interactively select and switch active preset in config | (Interactive prompt with automatic config patch & backup) |
|
|
310
351
|
| `ignore` | Add standard ignore paths (`.next`, `dist`, `build`) to config | (Patches flat config or legacy ignores safely) |
|
|
@@ -314,8 +355,11 @@ npx ai-guard <command> [options]
|
|
|
314
355
|
### CLI Usage Examples
|
|
315
356
|
|
|
316
357
|
```bash
|
|
317
|
-
#
|
|
318
|
-
npx ai-guard
|
|
358
|
+
# 0. Set up hooks, the pre-commit gate and the agent-config check in one step
|
|
359
|
+
npx eslint-plugin-ai-guard protect
|
|
360
|
+
|
|
361
|
+
# 1. Immediate scan of current directory (no install needed)
|
|
362
|
+
npx eslint-plugin-ai-guard run
|
|
319
363
|
|
|
320
364
|
# 2. Strict CI scan failing only on high-confidence issues
|
|
321
365
|
npx ai-guard run --strict --fail-on high
|
|
@@ -455,14 +499,25 @@ jobs:
|
|
|
455
499
|
cache: 'npm'
|
|
456
500
|
|
|
457
501
|
- name: Run AI Guard
|
|
502
|
+
id: aiguard
|
|
458
503
|
uses: ai-guard-dev/eslint-plugin-ai-guard@v1
|
|
459
504
|
with:
|
|
460
505
|
preset: 'recommended'
|
|
461
506
|
fail-on: 'high'
|
|
462
507
|
changed-only: 'true'
|
|
463
|
-
|
|
508
|
+
|
|
509
|
+
# The Action writes SARIF; this step sends it to Code Scanning.
|
|
510
|
+
# if: always() uploads it even when the scan step fails the job.
|
|
511
|
+
- name: Upload to GitHub Code Scanning
|
|
512
|
+
if: always()
|
|
513
|
+
uses: github/codeql-action/upload-sarif@v3
|
|
514
|
+
with:
|
|
515
|
+
sarif_file: ${{ steps.aiguard.outputs.sarif-file }}
|
|
516
|
+
category: ai-guard
|
|
464
517
|
```
|
|
465
518
|
|
|
519
|
+
The Action annotates the pull request and writes the job summary by itself. Alerts in **Security → Code scanning** need the upload step.
|
|
520
|
+
|
|
466
521
|
### Action Inputs (`action.yml`)
|
|
467
522
|
|
|
468
523
|
| Input | Description | Default |
|
|
@@ -471,7 +526,7 @@ jobs:
|
|
|
471
526
|
| `fail-on` | Severity threshold to fail CI: `high` \| `medium` \| `any` \| `none` | `'high'` |
|
|
472
527
|
| `changed-only` | Scan only files changed in this PR / commit | `'true'` |
|
|
473
528
|
| `path` | Target file or directory to scan | `'.'` |
|
|
474
|
-
| `upload-sarif` |
|
|
529
|
+
| `upload-sarif` | Always write the SARIF file (`sarif-file` output) for an `upload-sarif` step, even when the scan produced none. The Action does not upload to Code Scanning by itself | `'true'` |
|
|
475
530
|
| `github-summary` | Write an execution breakdown to the GitHub Actions Job Summary | `'true'` |
|
|
476
531
|
| `working-directory`| Working directory for scanning (ideal for monorepos) | `'.'` |
|
|
477
532
|
| `package-manager` | Package manager: `auto` \| `npm` \| `pnpm` \| `yarn` | `'auto'` |
|
|
@@ -610,10 +665,10 @@ npx eslint . --fix
|
|
|
610
665
|
| Rule | Automatic Fix Behavior |
|
|
611
666
|
| :--- | :--- |
|
|
612
667
|
| `no-hardcoded-secret` | Replaces hardcoded string literal with `process.env.VARIABLE_NAME` |
|
|
613
|
-
| `no-empty-catch` | Inserts `/* TODO: handle error */` comment to prevent silent swallowing |
|
|
614
|
-
| `no-floating-promise` | Prepends `void ` expression to intentionally unawaited calls |
|
|
615
668
|
| `no-await-in-loop` | Rewrites straightforward sequential loops to `await Promise.all(...)` |
|
|
616
669
|
|
|
670
|
+
`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.
|
|
671
|
+
|
|
617
672
|
---
|
|
618
673
|
|
|
619
674
|
## Benchmarks & Empirical Evaluation
|
|
@@ -646,7 +701,7 @@ Conventional linters either omit AI-specific hazards entirely or require heavywe
|
|
|
646
701
|
| **Elided / stubbed code left by agents** | [`no-placeholder-implementation`](./docs/rules/no-placeholder-implementation.md) | Partial: `no-warning-comments` *(TODO text only)* | ❌ None |
|
|
647
702
|
|
|
648
703
|
> [!TIP]
|
|
649
|
-
> **Minimal Type-Information Dependency:**
|
|
704
|
+
> **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.
|
|
650
705
|
|
|
651
706
|
---
|
|
652
707
|
|
|
@@ -712,7 +767,7 @@ npx --yes --package eslint-plugin-ai-guard ai-guard-mcp
|
|
|
712
767
|
| :--- | :--- |
|
|
713
768
|
| `ai_guard_scan_file` | Scan a single JS/TS file with structured findings |
|
|
714
769
|
| `ai_guard_scan_diff` | Scan changed files in git diff (including newly created untracked JS/TS files) |
|
|
715
|
-
| `ai_guard_scan_project` | Scan a bounded workspace directory (
|
|
770
|
+
| `ai_guard_scan_project` | Scan a bounded workspace directory (at most 500 files; fails instead of truncating) |
|
|
716
771
|
| `ai_guard_rules` | List rules and presets, or look up specific rules (`rules: ["no-floating-promise"]`) with remediation and docs link |
|
|
717
772
|
| `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` |
|
|
718
773
|
|