@nerviq/cli 1.18.0 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -23
- package/README.md +2 -2
- package/bin/cli.js +130 -130
- package/package.json +1 -1
- package/src/activity.js +1039 -1039
- package/src/adoption-advisor.js +299 -299
- package/src/aider/config-parser.js +166 -166
- package/src/aider/context.js +158 -158
- package/src/aider/deep-review.js +316 -316
- package/src/aider/domain-packs.js +303 -303
- package/src/aider/freshness.js +93 -93
- package/src/aider/governance.js +253 -253
- package/src/aider/interactive.js +334 -334
- package/src/aider/mcp-packs.js +329 -329
- package/src/aider/patch.js +214 -214
- package/src/aider/plans.js +186 -186
- package/src/aider/premium.js +360 -360
- package/src/aider/setup.js +404 -404
- package/src/aider/techniques.js +16 -16
- package/src/analyze.js +951 -951
- package/src/anti-patterns.js +485 -485
- package/src/audit/instruction-files.js +180 -180
- package/src/audit/recommendations.js +577 -577
- package/src/auto-suggest.js +154 -154
- package/src/badge.js +13 -13
- package/src/behavioral-drift.js +801 -801
- package/src/benchmark.js +67 -67
- package/src/catalog.js +103 -103
- package/src/certification.js +128 -128
- package/src/codex/config-parser.js +183 -183
- package/src/codex/context.js +223 -223
- package/src/codex/deep-review.js +493 -493
- package/src/codex/domain-packs.js +394 -394
- package/src/codex/freshness.js +84 -84
- package/src/codex/governance.js +192 -192
- package/src/codex/interactive.js +618 -618
- package/src/codex/mcp-packs.js +914 -914
- package/src/codex/patch.js +209 -209
- package/src/codex/plans.js +251 -251
- package/src/codex/premium.js +614 -614
- package/src/codex/setup.js +591 -591
- package/src/context.js +320 -320
- package/src/continuous-ops.js +681 -681
- package/src/copilot/activity.js +309 -309
- package/src/copilot/deep-review.js +346 -346
- package/src/copilot/domain-packs.js +372 -372
- package/src/copilot/freshness.js +57 -57
- package/src/copilot/governance.js +222 -222
- package/src/copilot/interactive.js +406 -406
- package/src/copilot/mcp-packs.js +826 -826
- package/src/copilot/plans.js +253 -253
- package/src/copilot/premium.js +451 -451
- package/src/copilot/setup.js +488 -488
- package/src/cost-tracking.js +61 -61
- package/src/cursor/activity.js +301 -301
- package/src/cursor/config-parser.js +265 -265
- package/src/cursor/context.js +256 -256
- package/src/cursor/deep-review.js +334 -334
- package/src/cursor/domain-packs.js +368 -368
- package/src/cursor/freshness.js +65 -65
- package/src/cursor/governance.js +229 -229
- package/src/cursor/interactive.js +391 -391
- package/src/cursor/mcp-packs.js +828 -828
- package/src/cursor/plans.js +254 -254
- package/src/cursor/premium.js +469 -469
- package/src/cursor/setup.js +488 -488
- package/src/dashboard.js +493 -493
- package/src/deep-review.js +428 -428
- package/src/deprecation.js +98 -98
- package/src/diff-only.js +280 -280
- package/src/doctor.js +119 -119
- package/src/domain-pack-expansion.js +1033 -1033
- package/src/domain-packs.js +387 -387
- package/src/feedback.js +178 -178
- package/src/fix-engine.js +783 -783
- package/src/fix-prompts.js +122 -122
- package/src/formatters/sarif.js +115 -115
- package/src/freshness.js +74 -74
- package/src/gemini/config-parser.js +275 -275
- package/src/gemini/context.js +221 -221
- package/src/gemini/deep-review.js +559 -559
- package/src/gemini/domain-packs.js +393 -393
- package/src/gemini/freshness.js +66 -66
- package/src/gemini/governance.js +201 -201
- package/src/gemini/interactive.js +860 -860
- package/src/gemini/mcp-packs.js +915 -915
- package/src/gemini/plans.js +269 -269
- package/src/gemini/premium.js +760 -760
- package/src/gemini/setup.js +692 -692
- package/src/gemini/techniques.js +14 -14
- package/src/governance.js +72 -72
- package/src/harmony/add.js +68 -68
- package/src/harmony/advisor.js +333 -333
- package/src/harmony/canon.js +565 -565
- package/src/harmony/cli.js +591 -591
- package/src/harmony/drift.js +401 -401
- package/src/harmony/governance.js +313 -313
- package/src/harmony/memory.js +239 -239
- package/src/harmony/sync.js +475 -475
- package/src/harmony/watch.js +370 -370
- package/src/hook-validation.js +342 -342
- package/src/index.js +271 -271
- package/src/init.js +184 -184
- package/src/instruction-surfaces.js +185 -185
- package/src/integrations.js +144 -144
- package/src/interactive.js +118 -118
- package/src/locales/en.json +1 -1
- package/src/locales/es.json +1 -1
- package/src/mcp-packs.js +830 -830
- package/src/mcp-server.js +726 -726
- package/src/mcp-validation.js +337 -337
- package/src/nerviq-sync.json +7 -7
- package/src/opencode/config-parser.js +109 -109
- package/src/opencode/context.js +247 -247
- package/src/opencode/deep-review.js +313 -313
- package/src/opencode/domain-packs.js +262 -262
- package/src/opencode/freshness.js +66 -66
- package/src/opencode/governance.js +159 -159
- package/src/opencode/interactive.js +392 -392
- package/src/opencode/mcp-packs.js +705 -705
- package/src/opencode/patch.js +184 -184
- package/src/opencode/plans.js +231 -231
- package/src/opencode/premium.js +413 -413
- package/src/opencode/setup.js +449 -449
- package/src/opencode/techniques.js +27 -27
- package/src/operating-profile.js +574 -574
- package/src/org.js +152 -152
- package/src/permission-rules.js +218 -218
- package/src/plans.js +839 -839
- package/src/platform-change-manifest.js +86 -86
- package/src/plugins.js +110 -110
- package/src/policy-layers.js +210 -210
- package/src/profiles.js +124 -124
- package/src/prompt-injection.js +74 -74
- package/src/public-api.js +173 -173
- package/src/recommendation-rules.js +84 -84
- package/src/repo-archetype.js +386 -386
- package/src/secret-patterns.js +39 -39
- package/src/server.js +527 -527
- package/src/setup/analysis.js +607 -607
- package/src/setup/runtime.js +172 -172
- package/src/setup.js +677 -677
- package/src/shared/capabilities.js +194 -194
- package/src/source-urls.js +132 -132
- package/src/stack-checks.js +565 -565
- package/src/supplemental-checks.js +13 -13
- package/src/synergy/adaptive.js +261 -261
- package/src/synergy/compensation.js +137 -137
- package/src/synergy/evidence.js +193 -193
- package/src/synergy/learning.js +199 -199
- package/src/synergy/patterns.js +227 -227
- package/src/synergy/ranking.js +83 -83
- package/src/synergy/report.js +165 -165
- package/src/synergy/routing.js +146 -146
- package/src/techniques/api.js +407 -407
- package/src/techniques/automation.js +316 -316
- package/src/techniques/compliance.js +257 -257
- package/src/techniques/hygiene.js +294 -294
- package/src/techniques/instructions.js +243 -243
- package/src/techniques/observability.js +226 -226
- package/src/techniques/optimization.js +142 -142
- package/src/techniques/quality.js +318 -318
- package/src/techniques/security.js +237 -237
- package/src/techniques/shared.js +443 -443
- package/src/techniques/stacks.js +2294 -2294
- package/src/techniques/tools.js +106 -106
- package/src/techniques/workflow.js +413 -413
- package/src/techniques.js +81 -81
- package/src/terminology.js +73 -73
- package/src/token-estimate.js +35 -35
- package/src/usage-patterns.js +99 -99
- package/src/verification-metadata.js +145 -145
- package/src/watch.js +247 -247
- package/src/windsurf/activity.js +302 -302
- package/src/windsurf/config-parser.js +267 -267
- package/src/windsurf/context.js +249 -249
- package/src/windsurf/deep-review.js +337 -337
- package/src/windsurf/domain-packs.js +370 -370
- package/src/windsurf/freshness.js +36 -36
- package/src/windsurf/governance.js +231 -231
- package/src/windsurf/interactive.js +388 -388
- package/src/windsurf/mcp-packs.js +792 -792
- package/src/windsurf/plans.js +247 -247
- package/src/windsurf/premium.js +468 -468
- package/src/windsurf/setup.js +471 -471
- package/src/windsurf/techniques.js +17 -17
- package/src/workspace.js +375 -375
package/src/anti-patterns.js
CHANGED
|
@@ -1,485 +1,485 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Anti-Pattern Catalog — things NOT to do when configuring AI coding agents.
|
|
3
|
-
* Provides a static catalog and a runtime detector that checks a project context.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
const {
|
|
7
|
-
getRepoInstructionBundle,
|
|
8
|
-
hasDocumentedVerificationGuidance,
|
|
9
|
-
hasDocumentedTestCommand,
|
|
10
|
-
} = require('./instruction-surfaces');
|
|
11
|
-
const { collectClaudeDenyRules } = require('./permission-rules');
|
|
12
|
-
const { containsEmbeddedSecret } = require('./secret-patterns');
|
|
13
|
-
const { containsPromptInjectionPattern } = require('./prompt-injection');
|
|
14
|
-
|
|
15
|
-
const ANTI_PATTERNS = [
|
|
16
|
-
{
|
|
17
|
-
id: 'AP001',
|
|
18
|
-
name: 'bypassPermissions as default',
|
|
19
|
-
severity: 'critical',
|
|
20
|
-
description: 'Setting defaultMode to bypassPermissions removes all safety guardrails.',
|
|
21
|
-
platforms: ['claude'],
|
|
22
|
-
fix: 'Use "default" or "safe-write" mode. Add specific allow rules for trusted operations.',
|
|
23
|
-
detect: (ctx) => {
|
|
24
|
-
const settings = ctx.jsonFile('.claude/settings.json') || ctx.jsonFile('.claude/settings.local.json');
|
|
25
|
-
return settings && settings.permissions && settings.permissions.defaultMode === 'bypassPermissions';
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
id: 'AP002',
|
|
30
|
-
name: 'No deny rules configured',
|
|
31
|
-
severity: 'high',
|
|
32
|
-
description: 'Without deny rules, the agent can execute any operation it decides to, including destructive ones.',
|
|
33
|
-
platforms: ['claude'],
|
|
34
|
-
fix: 'Add deny rules in settings.json for dangerous operations like rm -rf, git reset --hard, and reading .env files.',
|
|
35
|
-
detect: (ctx) => {
|
|
36
|
-
const settings = ctx.jsonFile('.claude/settings.json') || ctx.jsonFile('.claude/settings.local.json');
|
|
37
|
-
if (!settings || !settings.permissions) return true;
|
|
38
|
-
return collectClaudeDenyRules(ctx).length === 0;
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
id: 'AP003',
|
|
43
|
-
name: 'Secrets in CLAUDE.md',
|
|
44
|
-
severity: 'critical',
|
|
45
|
-
description: 'API keys, tokens, or passwords hardcoded in CLAUDE.md are visible to every session and may leak in outputs.',
|
|
46
|
-
platforms: ['claude', 'codex', 'cursor', 'windsurf', 'copilot', 'gemini', 'aider', 'opencode'],
|
|
47
|
-
fix: 'Move secrets to .env files and reference them via environment variables. Add .env to .gitignore.',
|
|
48
|
-
detect: (ctx) => {
|
|
49
|
-
const content = ctx.fileContent('CLAUDE.md') || ctx.fileContent('.claude/CLAUDE.md') || '';
|
|
50
|
-
const patterns = [
|
|
51
|
-
/(?:api[_-]?key|api[_-]?secret|token|password|secret[_-]?key)\s*[:=]\s*['"]?[A-Za-z0-9_\-]{16,}/i,
|
|
52
|
-
/sk-[A-Za-z0-9]{20,}/,
|
|
53
|
-
/ghp_[A-Za-z0-9]{36,}/,
|
|
54
|
-
/AKIA[A-Z0-9]{16}/,
|
|
55
|
-
];
|
|
56
|
-
return patterns.some(p => p.test(content));
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
id: 'AP004',
|
|
61
|
-
name: 'Empty CLAUDE.md',
|
|
62
|
-
severity: 'medium',
|
|
63
|
-
description: 'An empty or near-empty instruction file provides no guidance, making the agent guess at project conventions.',
|
|
64
|
-
platforms: ['claude'],
|
|
65
|
-
fix: 'Add project description, architecture overview, verification commands, and coding conventions to CLAUDE.md.',
|
|
66
|
-
detect: (ctx) => {
|
|
67
|
-
const content = ctx.fileContent('CLAUDE.md') || ctx.fileContent('.claude/CLAUDE.md') || '';
|
|
68
|
-
return content.trim().length > 0 && content.trim().length < 50;
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
id: 'AP005',
|
|
73
|
-
name: 'Too many MCP servers (>10)',
|
|
74
|
-
severity: 'medium',
|
|
75
|
-
description: 'More than 10 MCP servers increases startup latency, context overhead, and potential for tool conflicts.',
|
|
76
|
-
platforms: ['claude'],
|
|
77
|
-
fix: 'Limit MCP servers to essential ones. Remove rarely-used servers and consolidate overlapping functionality.',
|
|
78
|
-
detect: (ctx) => {
|
|
79
|
-
const settings = ctx.jsonFile('.claude/settings.json') || ctx.jsonFile('.claude/settings.local.json');
|
|
80
|
-
if (!settings || !settings.mcpServers) return false;
|
|
81
|
-
return Object.keys(settings.mcpServers).length > 10;
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
id: 'AP006',
|
|
86
|
-
name: 'Overly broad allow rules',
|
|
87
|
-
severity: 'high',
|
|
88
|
-
description: 'Allow rules like "Bash(*)" or "Write(**)" grant blanket permission, defeating the purpose of permission controls.',
|
|
89
|
-
platforms: ['claude'],
|
|
90
|
-
fix: 'Scope allow rules to specific commands and paths. Use "Bash(npm test)" instead of "Bash(*)".',
|
|
91
|
-
detect: (ctx) => {
|
|
92
|
-
const settings = ctx.jsonFile('.claude/settings.json') || ctx.jsonFile('.claude/settings.local.json');
|
|
93
|
-
if (!settings || !settings.permissions) return false;
|
|
94
|
-
const allow = settings.permissions.allow || [];
|
|
95
|
-
const broadPatterns = ['Bash(*)', 'Write(**)', 'Edit(**)', 'Read(**)', 'Bash(**)', 'Write(*)', 'Edit(*)', 'Read(*)'];
|
|
96
|
-
return allow.some(rule => broadPatterns.includes(rule));
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
id: 'AP007',
|
|
101
|
-
name: 'No verification commands',
|
|
102
|
-
severity: 'medium',
|
|
103
|
-
description: 'Without test, lint, or build commands across the repo instruction surfaces, agents cannot self-verify changes consistently.',
|
|
104
|
-
platforms: ['claude', 'codex', 'cursor', 'windsurf', 'copilot', 'gemini', 'aider', 'opencode'],
|
|
105
|
-
fix: 'Add a canonical verification section or command doc in your repo instruction surfaces (for example CLAUDE.md, AGENTS.md, README, or platform rules).',
|
|
106
|
-
detect: (ctx) => {
|
|
107
|
-
const content = getRepoInstructionBundle(ctx);
|
|
108
|
-
if (!content) return false;
|
|
109
|
-
return !hasDocumentedVerificationGuidance(content);
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
id: 'AP008',
|
|
114
|
-
name: 'Ignoring .gitignore for sensitive files',
|
|
115
|
-
severity: 'high',
|
|
116
|
-
description: 'Not gitignoring .env, credentials, and key files means they can be committed and pushed to remote repos.',
|
|
117
|
-
platforms: ['claude', 'codex', 'cursor', 'windsurf', 'copilot', 'gemini', 'aider', 'opencode'],
|
|
118
|
-
fix: 'Add .env, .env.*, credentials.json, *.pem, and *.key to .gitignore.',
|
|
119
|
-
detect: (ctx) => {
|
|
120
|
-
const gitignore = ctx.fileContent('.gitignore') || '';
|
|
121
|
-
return !gitignore.includes('.env');
|
|
122
|
-
},
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
id: 'AP009',
|
|
126
|
-
name: 'No hooks configured',
|
|
127
|
-
severity: 'medium',
|
|
128
|
-
description: 'Without hooks, there is no automated enforcement — all safety depends on instructions alone (80% compliance vs 100%).',
|
|
129
|
-
platforms: ['claude'],
|
|
130
|
-
fix: 'Add at least a protect-secrets PreToolUse hook and a post-edit lint hook in settings.json.',
|
|
131
|
-
detect: (ctx) => {
|
|
132
|
-
const settings = ctx.jsonFile('.claude/settings.json') || ctx.jsonFile('.claude/settings.local.json');
|
|
133
|
-
if (!settings || !settings.hooks) return true;
|
|
134
|
-
const hookEntries = Object.values(settings.hooks).flat();
|
|
135
|
-
return hookEntries.length === 0;
|
|
136
|
-
},
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
id: 'AP010',
|
|
140
|
-
name: 'Duplicated instructions across platforms',
|
|
141
|
-
severity: 'medium',
|
|
142
|
-
description: 'Copy-pasting the same instructions into CLAUDE.md, .cursorrules, and AGENTS.md creates drift when one is updated.',
|
|
143
|
-
platforms: ['claude', 'codex', 'cursor', 'windsurf', 'copilot', 'gemini', 'aider', 'opencode'],
|
|
144
|
-
fix: 'Create a shared source of truth (e.g., docs/ai-instructions.md) and reference it from each platform config.',
|
|
145
|
-
detect: (ctx) => {
|
|
146
|
-
const claudeMd = ctx.fileContent('CLAUDE.md') || '';
|
|
147
|
-
const cursorrules = ctx.fileContent('.cursorrules') || '';
|
|
148
|
-
const agentsMd = ctx.fileContent('AGENTS.md') || '';
|
|
149
|
-
if (!claudeMd || claudeMd.length < 100) return false;
|
|
150
|
-
const files = [cursorrules, agentsMd].filter(f => f.length > 100);
|
|
151
|
-
if (files.length === 0) return false;
|
|
152
|
-
// Simple heuristic: check if any significant chunk (100+ chars) appears in both
|
|
153
|
-
const chunk = claudeMd.slice(0, 200).trim();
|
|
154
|
-
return files.some(f => f.includes(chunk));
|
|
155
|
-
},
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
id: 'AP011',
|
|
159
|
-
name: 'Conflicting trust postures across platforms',
|
|
160
|
-
severity: 'high',
|
|
161
|
-
description: 'One platform in bypassPermissions while another is read-only creates inconsistent security boundaries.',
|
|
162
|
-
platforms: ['claude', 'codex'],
|
|
163
|
-
fix: 'Align permission profiles across platforms. Use Harmony audit to detect and resolve trust drift.',
|
|
164
|
-
detect: (ctx) => {
|
|
165
|
-
const claudeSettings = ctx.jsonFile('.claude/settings.json') || ctx.jsonFile('.claude/settings.local.json');
|
|
166
|
-
const codexConfig = ctx.fileContent('.codex/config.toml') || '';
|
|
167
|
-
if (!claudeSettings || !codexConfig) return false;
|
|
168
|
-
const claudeMode = claudeSettings.permissions && claudeSettings.permissions.defaultMode;
|
|
169
|
-
const isBypass = claudeMode === 'bypassPermissions';
|
|
170
|
-
const codexHasAutoApprove = /approval_policy\s*=\s*["']auto-edit["']/i.test(codexConfig);
|
|
171
|
-
// Conflict: one is very permissive while the other is restrictive, or vice versa
|
|
172
|
-
return (isBypass && !codexHasAutoApprove) || (!isBypass && codexHasAutoApprove);
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
{
|
|
176
|
-
id: 'AP012',
|
|
177
|
-
name: 'No error handling in hooks',
|
|
178
|
-
severity: 'medium',
|
|
179
|
-
description: 'Hook scripts without error handling can silently fail, giving a false sense of security.',
|
|
180
|
-
platforms: ['claude'],
|
|
181
|
-
fix: 'Add "set -e" to shell hooks and wrap commands in try/catch for JS hooks. Log failures to a known location.',
|
|
182
|
-
detect: (ctx) => {
|
|
183
|
-
if (!ctx.hasDir('.claude/hooks')) return false;
|
|
184
|
-
const hookFiles = ctx.dirFiles('.claude/hooks');
|
|
185
|
-
for (const file of hookFiles) {
|
|
186
|
-
const content = ctx.fileContent(`.claude/hooks/${file}`) || '';
|
|
187
|
-
if (file.endsWith('.sh') && content.length > 0 && !content.includes('set -e')) {
|
|
188
|
-
return true;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return false;
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
id: 'AP013',
|
|
196
|
-
name: 'Hardcoded paths in CLAUDE.md',
|
|
197
|
-
severity: 'medium',
|
|
198
|
-
description: 'Absolute paths like /Users/alice/project or C:\\Users break when other developers clone the repo.',
|
|
199
|
-
platforms: ['claude', 'codex', 'cursor', 'windsurf', 'copilot', 'gemini', 'aider', 'opencode'],
|
|
200
|
-
fix: 'Use relative paths or environment variables. Replace absolute paths with project-relative references.',
|
|
201
|
-
detect: (ctx) => {
|
|
202
|
-
const content = ctx.fileContent('CLAUDE.md') || ctx.fileContent('.claude/CLAUDE.md') || '';
|
|
203
|
-
if (!content) return false;
|
|
204
|
-
return /(?:\/Users\/[a-zA-Z]|\/home\/[a-zA-Z]|C:\\Users\\[a-zA-Z])/.test(content);
|
|
205
|
-
},
|
|
206
|
-
},
|
|
207
|
-
{
|
|
208
|
-
id: 'AP014',
|
|
209
|
-
name: 'No test command defined',
|
|
210
|
-
severity: 'medium',
|
|
211
|
-
description: 'Without a canonical test command in repo instructions or scripts, agents cannot verify changes reliably before handoff.',
|
|
212
|
-
platforms: ['claude', 'codex', 'cursor', 'windsurf', 'copilot', 'gemini', 'aider', 'opencode'],
|
|
213
|
-
fix: 'Add a canonical test command in repo instructions or package scripts, e.g. "Test: npm test" or "Test: pytest".',
|
|
214
|
-
detect: (ctx) => {
|
|
215
|
-
const content = getRepoInstructionBundle(ctx);
|
|
216
|
-
const pkg = ctx.jsonFile('package.json');
|
|
217
|
-
const hasTestInMd = hasDocumentedTestCommand(content);
|
|
218
|
-
const hasTestScript = pkg && pkg.scripts && pkg.scripts.test;
|
|
219
|
-
return !hasTestInMd && !hasTestScript;
|
|
220
|
-
},
|
|
221
|
-
},
|
|
222
|
-
{
|
|
223
|
-
id: 'AP023',
|
|
224
|
-
name: 'Suspicious prompt-injection phrases in repo instructions',
|
|
225
|
-
severity: 'high',
|
|
226
|
-
description: 'Instruction surfaces that say things like "ignore previous instructions", "bypass guardrails", or "score 100/100" create confusion and downstream trust problems, even when the static audit itself is not LLM-driven.',
|
|
227
|
-
platforms: ['claude', 'codex', 'cursor', 'windsurf', 'copilot', 'gemini', 'aider', 'opencode'],
|
|
228
|
-
fix: 'Remove adversarial phrases from repo instructions and replace them with an explicit trust-boundary note about treating repo/web/MCP content as untrusted data.',
|
|
229
|
-
detect: (ctx) => {
|
|
230
|
-
const content = getRepoInstructionBundle(ctx);
|
|
231
|
-
return containsPromptInjectionPattern(content);
|
|
232
|
-
},
|
|
233
|
-
},
|
|
234
|
-
{
|
|
235
|
-
id: 'AP015',
|
|
236
|
-
name: 'All permissions allowed',
|
|
237
|
-
severity: 'high',
|
|
238
|
-
description: 'Allowing all tool permissions without any deny rules gives the agent unrestricted system access.',
|
|
239
|
-
platforms: ['claude'],
|
|
240
|
-
fix: 'Define deny rules for destructive operations. At minimum deny rm -rf, git reset --hard, and .env reads.',
|
|
241
|
-
detect: (ctx) => {
|
|
242
|
-
const settings = ctx.jsonFile('.claude/settings.json') || ctx.jsonFile('.claude/settings.local.json');
|
|
243
|
-
if (!settings || !settings.permissions) return false;
|
|
244
|
-
const allow = settings.permissions.allow || [];
|
|
245
|
-
const deny = settings.permissions.deny || [];
|
|
246
|
-
return allow.length > 5 && deny.length === 0;
|
|
247
|
-
},
|
|
248
|
-
},
|
|
249
|
-
{
|
|
250
|
-
id: 'AP016',
|
|
251
|
-
name: 'Missing architecture diagram',
|
|
252
|
-
severity: 'low',
|
|
253
|
-
description: 'Without an architecture diagram, the agent has to infer project structure from file exploration, wasting tokens.',
|
|
254
|
-
platforms: ['claude', 'codex', 'cursor', 'windsurf', 'copilot', 'gemini', 'aider', 'opencode'],
|
|
255
|
-
fix: 'Add a Mermaid diagram in CLAUDE.md showing the main components and data flow.',
|
|
256
|
-
detect: (ctx) => {
|
|
257
|
-
const content = ctx.fileContent('CLAUDE.md') || ctx.fileContent('.claude/CLAUDE.md') || '';
|
|
258
|
-
if (!content) return false;
|
|
259
|
-
return !content.includes('mermaid') && !content.includes('```') && content.length > 200;
|
|
260
|
-
},
|
|
261
|
-
},
|
|
262
|
-
{
|
|
263
|
-
id: 'AP017',
|
|
264
|
-
name: 'Using deprecated features',
|
|
265
|
-
severity: 'medium',
|
|
266
|
-
description: 'Relying on deprecated features risks breakage when they are removed in future versions.',
|
|
267
|
-
platforms: ['claude'],
|
|
268
|
-
fix: 'Check the platform changelog for deprecated features and migrate to recommended alternatives.',
|
|
269
|
-
detect: (ctx) => {
|
|
270
|
-
const content = ctx.fileContent('CLAUDE.md') || ctx.fileContent('.claude/CLAUDE.md') || '';
|
|
271
|
-
const settings = ctx.jsonFile('.claude/settings.json') || ctx.jsonFile('.claude/settings.local.json');
|
|
272
|
-
// Check for known deprecated patterns
|
|
273
|
-
const deprecatedPatterns = [
|
|
274
|
-
/allowedTools/i,
|
|
275
|
-
/blockedTools/i,
|
|
276
|
-
];
|
|
277
|
-
const hasDeprecatedInMd = deprecatedPatterns.some(p => p.test(content));
|
|
278
|
-
const hasDeprecatedInSettings = settings && deprecatedPatterns.some(p => p.test(JSON.stringify(settings)));
|
|
279
|
-
return hasDeprecatedInMd || hasDeprecatedInSettings;
|
|
280
|
-
},
|
|
281
|
-
},
|
|
282
|
-
{
|
|
283
|
-
id: 'AP018',
|
|
284
|
-
name: 'No rules files',
|
|
285
|
-
severity: 'low',
|
|
286
|
-
description: 'Without .claude/rules/ files, all instructions live in one place, making it harder to scope guidance by file type.',
|
|
287
|
-
platforms: ['claude'],
|
|
288
|
-
fix: 'Create .claude/rules/ with scoped rules for different areas (e.g., tests.md, api.md, frontend.md).',
|
|
289
|
-
detect: (ctx) => {
|
|
290
|
-
return !ctx.hasDir('.claude/rules') || (ctx.dirFiles('.claude/rules') || []).length === 0;
|
|
291
|
-
},
|
|
292
|
-
},
|
|
293
|
-
{
|
|
294
|
-
id: 'AP019',
|
|
295
|
-
name: 'Overly long CLAUDE.md (>500 lines)',
|
|
296
|
-
severity: 'medium',
|
|
297
|
-
description: 'Instruction files over 500 lines consume excessive context tokens and reduce adherence to individual rules.',
|
|
298
|
-
platforms: ['claude'],
|
|
299
|
-
fix: 'Split into CLAUDE.md (core) + .claude/rules/ (scoped). Use @import for focused modules.',
|
|
300
|
-
detect: (ctx) => {
|
|
301
|
-
const content = ctx.fileContent('CLAUDE.md') || ctx.fileContent('.claude/CLAUDE.md') || '';
|
|
302
|
-
if (!content) return false;
|
|
303
|
-
const lineCount = content.split('\n').length;
|
|
304
|
-
return lineCount > 500;
|
|
305
|
-
},
|
|
306
|
-
},
|
|
307
|
-
{
|
|
308
|
-
id: 'AP020',
|
|
309
|
-
name: 'No security review command',
|
|
310
|
-
severity: 'medium',
|
|
311
|
-
description: 'Without a security review command, OWASP Top 10 vulnerabilities go undetected during agent-assisted development.',
|
|
312
|
-
platforms: ['claude', 'codex', 'cursor', 'windsurf', 'copilot', 'gemini', 'aider', 'opencode'],
|
|
313
|
-
fix: 'Add a /security-review command or include security scanning in your CI pipeline.',
|
|
314
|
-
detect: (ctx) => {
|
|
315
|
-
const content = ctx.fileContent('CLAUDE.md') || ctx.fileContent('.claude/CLAUDE.md') || '';
|
|
316
|
-
const hasSecurityReview = /security[- ]?review/i.test(content);
|
|
317
|
-
const hasSecurityCommand = ctx.hasDir('.claude/commands') &&
|
|
318
|
-
(ctx.dirFiles('.claude/commands') || []).some(f => /security/i.test(f));
|
|
319
|
-
return !hasSecurityReview && !hasSecurityCommand;
|
|
320
|
-
},
|
|
321
|
-
},
|
|
322
|
-
{
|
|
323
|
-
id: 'AP021',
|
|
324
|
-
name: 'Inline secrets in hook scripts',
|
|
325
|
-
severity: 'critical',
|
|
326
|
-
description: 'Hardcoded API keys or tokens in hook scripts are executed every session and easily leaked.',
|
|
327
|
-
platforms: ['claude'],
|
|
328
|
-
fix: 'Use environment variables in hooks. Reference secrets via $ENV_VAR instead of hardcoding values.',
|
|
329
|
-
detect: (ctx) => {
|
|
330
|
-
if (!ctx.hasDir('.claude/hooks')) return false;
|
|
331
|
-
const hookFiles = ctx.dirFiles('.claude/hooks');
|
|
332
|
-
const secretPatterns = [
|
|
333
|
-
/(?:api[_-]?key|token|password|secret)\s*=\s*['"][A-Za-z0-9_\-]{16,}['"]/i,
|
|
334
|
-
/sk-[A-Za-z0-9]{20,}/,
|
|
335
|
-
/ghp_[A-Za-z0-9]{36,}/,
|
|
336
|
-
/AKIA[A-Z0-9]{16}/,
|
|
337
|
-
];
|
|
338
|
-
for (const file of hookFiles) {
|
|
339
|
-
const content = ctx.fileContent(`.claude/hooks/${file}`) || '';
|
|
340
|
-
if (secretPatterns.some(p => p.test(content)) || containsEmbeddedSecret(content)) {
|
|
341
|
-
return true;
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
return false;
|
|
345
|
-
},
|
|
346
|
-
},
|
|
347
|
-
{
|
|
348
|
-
id: 'AP022',
|
|
349
|
-
name: 'Missing .env protection in .gitignore',
|
|
350
|
-
severity: 'high',
|
|
351
|
-
description: 'Without .env in .gitignore, environment files with secrets can be accidentally committed and pushed.',
|
|
352
|
-
platforms: ['claude', 'codex', 'cursor', 'windsurf', 'copilot', 'gemini', 'aider', 'opencode'],
|
|
353
|
-
fix: 'Add .env, .env.*, and .env.local to .gitignore. Verify with "git check-ignore .env".',
|
|
354
|
-
detect: (ctx) => {
|
|
355
|
-
const gitignore = ctx.fileContent('.gitignore') || '';
|
|
356
|
-
if (!gitignore) return true;
|
|
357
|
-
return !gitignore.includes('.env');
|
|
358
|
-
},
|
|
359
|
-
},
|
|
360
|
-
];
|
|
361
|
-
|
|
362
|
-
/**
|
|
363
|
-
* Return the full anti-pattern catalog.
|
|
364
|
-
* @returns {Array<Object>} All registered anti-patterns.
|
|
365
|
-
*/
|
|
366
|
-
function getAntiPatterns() {
|
|
367
|
-
return ANTI_PATTERNS.map(({ detect, ...rest }) => rest);
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* Detect anti-patterns present in a project context.
|
|
372
|
-
* @param {Object} ctx - A ProjectContext instance (from src/context.js).
|
|
373
|
-
* @returns {Array<Object>} Detected anti-patterns with id, name, severity, description, and fix.
|
|
374
|
-
*/
|
|
375
|
-
function detectAntiPatterns(ctx) {
|
|
376
|
-
const detected = [];
|
|
377
|
-
for (const pattern of ANTI_PATTERNS) {
|
|
378
|
-
try {
|
|
379
|
-
if (pattern.detect(ctx)) {
|
|
380
|
-
const { detect, ...rest } = pattern;
|
|
381
|
-
detected.push(rest);
|
|
382
|
-
}
|
|
383
|
-
} catch (_err) {
|
|
384
|
-
// Skip patterns that fail to detect (missing files, etc.)
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
return detected;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
/**
|
|
391
|
-
* Print detected anti-patterns to the console.
|
|
392
|
-
* @param {Array<Object>} patterns - Detected anti-patterns.
|
|
393
|
-
* @param {Object} [options] - Display options.
|
|
394
|
-
* @param {boolean} [options.json] - Output as JSON.
|
|
395
|
-
*/
|
|
396
|
-
function printAntiPatterns(patterns, options = {}) {
|
|
397
|
-
if (options.json) {
|
|
398
|
-
console.log(JSON.stringify(patterns, null, 2));
|
|
399
|
-
return;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
const SEVERITY_COLORS = {
|
|
403
|
-
critical: '\x1b[31m',
|
|
404
|
-
high: '\x1b[33m',
|
|
405
|
-
medium: '\x1b[36m',
|
|
406
|
-
low: '\x1b[2m',
|
|
407
|
-
};
|
|
408
|
-
const RESET = '\x1b[0m';
|
|
409
|
-
const BOLD = '\x1b[1m';
|
|
410
|
-
const DIM = '\x1b[2m';
|
|
411
|
-
|
|
412
|
-
console.log('');
|
|
413
|
-
console.log(`${BOLD} nerviq anti-patterns${RESET}`);
|
|
414
|
-
console.log(`${DIM} ${'═'.repeat(39)}${RESET}`);
|
|
415
|
-
|
|
416
|
-
if (patterns.length === 0) {
|
|
417
|
-
console.log(` ${'\\x1b[32m'}No anti-patterns detected. Good job!${RESET}`);
|
|
418
|
-
console.log('');
|
|
419
|
-
return;
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
console.log(` ${patterns.length} anti-pattern${patterns.length === 1 ? '' : 's'} detected`);
|
|
423
|
-
console.log('');
|
|
424
|
-
|
|
425
|
-
// Sort by severity: critical > high > medium > low
|
|
426
|
-
const severityOrder = { critical: 0, high: 1, medium: 2, low: 3 };
|
|
427
|
-
const sorted = [...patterns].sort((a, b) => (severityOrder[a.severity] || 9) - (severityOrder[b.severity] || 9));
|
|
428
|
-
|
|
429
|
-
for (const p of sorted) {
|
|
430
|
-
const color = SEVERITY_COLORS[p.severity] || '';
|
|
431
|
-
console.log(` ${color}[${p.severity}]${RESET} ${p.name} (${p.id})`);
|
|
432
|
-
console.log(`${DIM} ${p.description}${RESET}`);
|
|
433
|
-
console.log(`${DIM} Fix: ${p.fix}${RESET}`);
|
|
434
|
-
console.log('');
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
/**
|
|
439
|
-
* Print the full anti-pattern catalog.
|
|
440
|
-
* @param {Object} [options] - Display options.
|
|
441
|
-
* @param {boolean} [options.json] - Output as JSON.
|
|
442
|
-
*/
|
|
443
|
-
function printAntiPatternCatalog(options = {}) {
|
|
444
|
-
const all = getAntiPatterns();
|
|
445
|
-
if (options.json) {
|
|
446
|
-
console.log(JSON.stringify(all, null, 2));
|
|
447
|
-
return;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
const SEVERITY_COLORS = {
|
|
451
|
-
critical: '\x1b[31m',
|
|
452
|
-
high: '\x1b[33m',
|
|
453
|
-
medium: '\x1b[36m',
|
|
454
|
-
low: '\x1b[2m',
|
|
455
|
-
};
|
|
456
|
-
const RESET = '\x1b[0m';
|
|
457
|
-
const BOLD = '\x1b[1m';
|
|
458
|
-
const DIM = '\x1b[2m';
|
|
459
|
-
|
|
460
|
-
console.log('');
|
|
461
|
-
console.log(`${BOLD} nerviq anti-pattern catalog${RESET}`);
|
|
462
|
-
console.log(`${DIM} ${'═'.repeat(39)}${RESET}`);
|
|
463
|
-
console.log(` ${all.length} anti-patterns registered`);
|
|
464
|
-
console.log('');
|
|
465
|
-
|
|
466
|
-
const severityOrder = { critical: 0, high: 1, medium: 2, low: 3 };
|
|
467
|
-
const sorted = [...all].sort((a, b) => (severityOrder[a.severity] || 9) - (severityOrder[b.severity] || 9));
|
|
468
|
-
|
|
469
|
-
for (const p of sorted) {
|
|
470
|
-
const color = SEVERITY_COLORS[p.severity] || '';
|
|
471
|
-
console.log(` ${color}[${p.severity}]${RESET} ${p.name} (${p.id})`);
|
|
472
|
-
console.log(`${DIM} ${p.description}${RESET}`);
|
|
473
|
-
console.log(`${DIM} Platforms: ${p.platforms.join(', ')}${RESET}`);
|
|
474
|
-
console.log(`${DIM} Fix: ${p.fix}${RESET}`);
|
|
475
|
-
console.log('');
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
module.exports = {
|
|
480
|
-
ANTI_PATTERNS,
|
|
481
|
-
getAntiPatterns,
|
|
482
|
-
detectAntiPatterns,
|
|
483
|
-
printAntiPatterns,
|
|
484
|
-
printAntiPatternCatalog,
|
|
485
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* Anti-Pattern Catalog — things NOT to do when configuring AI coding agents.
|
|
3
|
+
* Provides a static catalog and a runtime detector that checks a project context.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const {
|
|
7
|
+
getRepoInstructionBundle,
|
|
8
|
+
hasDocumentedVerificationGuidance,
|
|
9
|
+
hasDocumentedTestCommand,
|
|
10
|
+
} = require('./instruction-surfaces');
|
|
11
|
+
const { collectClaudeDenyRules } = require('./permission-rules');
|
|
12
|
+
const { containsEmbeddedSecret } = require('./secret-patterns');
|
|
13
|
+
const { containsPromptInjectionPattern } = require('./prompt-injection');
|
|
14
|
+
|
|
15
|
+
const ANTI_PATTERNS = [
|
|
16
|
+
{
|
|
17
|
+
id: 'AP001',
|
|
18
|
+
name: 'bypassPermissions as default',
|
|
19
|
+
severity: 'critical',
|
|
20
|
+
description: 'Setting defaultMode to bypassPermissions removes all safety guardrails.',
|
|
21
|
+
platforms: ['claude'],
|
|
22
|
+
fix: 'Use "default" or "safe-write" mode. Add specific allow rules for trusted operations.',
|
|
23
|
+
detect: (ctx) => {
|
|
24
|
+
const settings = ctx.jsonFile('.claude/settings.json') || ctx.jsonFile('.claude/settings.local.json');
|
|
25
|
+
return settings && settings.permissions && settings.permissions.defaultMode === 'bypassPermissions';
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: 'AP002',
|
|
30
|
+
name: 'No deny rules configured',
|
|
31
|
+
severity: 'high',
|
|
32
|
+
description: 'Without deny rules, the agent can execute any operation it decides to, including destructive ones.',
|
|
33
|
+
platforms: ['claude'],
|
|
34
|
+
fix: 'Add deny rules in settings.json for dangerous operations like rm -rf, git reset --hard, and reading .env files.',
|
|
35
|
+
detect: (ctx) => {
|
|
36
|
+
const settings = ctx.jsonFile('.claude/settings.json') || ctx.jsonFile('.claude/settings.local.json');
|
|
37
|
+
if (!settings || !settings.permissions) return true;
|
|
38
|
+
return collectClaudeDenyRules(ctx).length === 0;
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: 'AP003',
|
|
43
|
+
name: 'Secrets in CLAUDE.md',
|
|
44
|
+
severity: 'critical',
|
|
45
|
+
description: 'API keys, tokens, or passwords hardcoded in CLAUDE.md are visible to every session and may leak in outputs.',
|
|
46
|
+
platforms: ['claude', 'codex', 'cursor', 'windsurf', 'copilot', 'gemini', 'aider', 'opencode'],
|
|
47
|
+
fix: 'Move secrets to .env files and reference them via environment variables. Add .env to .gitignore.',
|
|
48
|
+
detect: (ctx) => {
|
|
49
|
+
const content = ctx.fileContent('CLAUDE.md') || ctx.fileContent('.claude/CLAUDE.md') || '';
|
|
50
|
+
const patterns = [
|
|
51
|
+
/(?:api[_-]?key|api[_-]?secret|token|password|secret[_-]?key)\s*[:=]\s*['"]?[A-Za-z0-9_\-]{16,}/i,
|
|
52
|
+
/sk-[A-Za-z0-9]{20,}/,
|
|
53
|
+
/ghp_[A-Za-z0-9]{36,}/,
|
|
54
|
+
/AKIA[A-Z0-9]{16}/,
|
|
55
|
+
];
|
|
56
|
+
return patterns.some(p => p.test(content));
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
id: 'AP004',
|
|
61
|
+
name: 'Empty CLAUDE.md',
|
|
62
|
+
severity: 'medium',
|
|
63
|
+
description: 'An empty or near-empty instruction file provides no guidance, making the agent guess at project conventions.',
|
|
64
|
+
platforms: ['claude'],
|
|
65
|
+
fix: 'Add project description, architecture overview, verification commands, and coding conventions to CLAUDE.md.',
|
|
66
|
+
detect: (ctx) => {
|
|
67
|
+
const content = ctx.fileContent('CLAUDE.md') || ctx.fileContent('.claude/CLAUDE.md') || '';
|
|
68
|
+
return content.trim().length > 0 && content.trim().length < 50;
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
id: 'AP005',
|
|
73
|
+
name: 'Too many MCP servers (>10)',
|
|
74
|
+
severity: 'medium',
|
|
75
|
+
description: 'More than 10 MCP servers increases startup latency, context overhead, and potential for tool conflicts.',
|
|
76
|
+
platforms: ['claude'],
|
|
77
|
+
fix: 'Limit MCP servers to essential ones. Remove rarely-used servers and consolidate overlapping functionality.',
|
|
78
|
+
detect: (ctx) => {
|
|
79
|
+
const settings = ctx.jsonFile('.claude/settings.json') || ctx.jsonFile('.claude/settings.local.json');
|
|
80
|
+
if (!settings || !settings.mcpServers) return false;
|
|
81
|
+
return Object.keys(settings.mcpServers).length > 10;
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
id: 'AP006',
|
|
86
|
+
name: 'Overly broad allow rules',
|
|
87
|
+
severity: 'high',
|
|
88
|
+
description: 'Allow rules like "Bash(*)" or "Write(**)" grant blanket permission, defeating the purpose of permission controls.',
|
|
89
|
+
platforms: ['claude'],
|
|
90
|
+
fix: 'Scope allow rules to specific commands and paths. Use "Bash(npm test)" instead of "Bash(*)".',
|
|
91
|
+
detect: (ctx) => {
|
|
92
|
+
const settings = ctx.jsonFile('.claude/settings.json') || ctx.jsonFile('.claude/settings.local.json');
|
|
93
|
+
if (!settings || !settings.permissions) return false;
|
|
94
|
+
const allow = settings.permissions.allow || [];
|
|
95
|
+
const broadPatterns = ['Bash(*)', 'Write(**)', 'Edit(**)', 'Read(**)', 'Bash(**)', 'Write(*)', 'Edit(*)', 'Read(*)'];
|
|
96
|
+
return allow.some(rule => broadPatterns.includes(rule));
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
id: 'AP007',
|
|
101
|
+
name: 'No verification commands',
|
|
102
|
+
severity: 'medium',
|
|
103
|
+
description: 'Without test, lint, or build commands across the repo instruction surfaces, agents cannot self-verify changes consistently.',
|
|
104
|
+
platforms: ['claude', 'codex', 'cursor', 'windsurf', 'copilot', 'gemini', 'aider', 'opencode'],
|
|
105
|
+
fix: 'Add a canonical verification section or command doc in your repo instruction surfaces (for example CLAUDE.md, AGENTS.md, README, or platform rules).',
|
|
106
|
+
detect: (ctx) => {
|
|
107
|
+
const content = getRepoInstructionBundle(ctx);
|
|
108
|
+
if (!content) return false;
|
|
109
|
+
return !hasDocumentedVerificationGuidance(content);
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
id: 'AP008',
|
|
114
|
+
name: 'Ignoring .gitignore for sensitive files',
|
|
115
|
+
severity: 'high',
|
|
116
|
+
description: 'Not gitignoring .env, credentials, and key files means they can be committed and pushed to remote repos.',
|
|
117
|
+
platforms: ['claude', 'codex', 'cursor', 'windsurf', 'copilot', 'gemini', 'aider', 'opencode'],
|
|
118
|
+
fix: 'Add .env, .env.*, credentials.json, *.pem, and *.key to .gitignore.',
|
|
119
|
+
detect: (ctx) => {
|
|
120
|
+
const gitignore = ctx.fileContent('.gitignore') || '';
|
|
121
|
+
return !gitignore.includes('.env');
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
id: 'AP009',
|
|
126
|
+
name: 'No hooks configured',
|
|
127
|
+
severity: 'medium',
|
|
128
|
+
description: 'Without hooks, there is no automated enforcement — all safety depends on instructions alone (80% compliance vs 100%).',
|
|
129
|
+
platforms: ['claude'],
|
|
130
|
+
fix: 'Add at least a protect-secrets PreToolUse hook and a post-edit lint hook in settings.json.',
|
|
131
|
+
detect: (ctx) => {
|
|
132
|
+
const settings = ctx.jsonFile('.claude/settings.json') || ctx.jsonFile('.claude/settings.local.json');
|
|
133
|
+
if (!settings || !settings.hooks) return true;
|
|
134
|
+
const hookEntries = Object.values(settings.hooks).flat();
|
|
135
|
+
return hookEntries.length === 0;
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
id: 'AP010',
|
|
140
|
+
name: 'Duplicated instructions across platforms',
|
|
141
|
+
severity: 'medium',
|
|
142
|
+
description: 'Copy-pasting the same instructions into CLAUDE.md, .cursorrules, and AGENTS.md creates drift when one is updated.',
|
|
143
|
+
platforms: ['claude', 'codex', 'cursor', 'windsurf', 'copilot', 'gemini', 'aider', 'opencode'],
|
|
144
|
+
fix: 'Create a shared source of truth (e.g., docs/ai-instructions.md) and reference it from each platform config.',
|
|
145
|
+
detect: (ctx) => {
|
|
146
|
+
const claudeMd = ctx.fileContent('CLAUDE.md') || '';
|
|
147
|
+
const cursorrules = ctx.fileContent('.cursorrules') || '';
|
|
148
|
+
const agentsMd = ctx.fileContent('AGENTS.md') || '';
|
|
149
|
+
if (!claudeMd || claudeMd.length < 100) return false;
|
|
150
|
+
const files = [cursorrules, agentsMd].filter(f => f.length > 100);
|
|
151
|
+
if (files.length === 0) return false;
|
|
152
|
+
// Simple heuristic: check if any significant chunk (100+ chars) appears in both
|
|
153
|
+
const chunk = claudeMd.slice(0, 200).trim();
|
|
154
|
+
return files.some(f => f.includes(chunk));
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
id: 'AP011',
|
|
159
|
+
name: 'Conflicting trust postures across platforms',
|
|
160
|
+
severity: 'high',
|
|
161
|
+
description: 'One platform in bypassPermissions while another is read-only creates inconsistent security boundaries.',
|
|
162
|
+
platforms: ['claude', 'codex'],
|
|
163
|
+
fix: 'Align permission profiles across platforms. Use Harmony audit to detect and resolve trust drift.',
|
|
164
|
+
detect: (ctx) => {
|
|
165
|
+
const claudeSettings = ctx.jsonFile('.claude/settings.json') || ctx.jsonFile('.claude/settings.local.json');
|
|
166
|
+
const codexConfig = ctx.fileContent('.codex/config.toml') || '';
|
|
167
|
+
if (!claudeSettings || !codexConfig) return false;
|
|
168
|
+
const claudeMode = claudeSettings.permissions && claudeSettings.permissions.defaultMode;
|
|
169
|
+
const isBypass = claudeMode === 'bypassPermissions';
|
|
170
|
+
const codexHasAutoApprove = /approval_policy\s*=\s*["']auto-edit["']/i.test(codexConfig);
|
|
171
|
+
// Conflict: one is very permissive while the other is restrictive, or vice versa
|
|
172
|
+
return (isBypass && !codexHasAutoApprove) || (!isBypass && codexHasAutoApprove);
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
id: 'AP012',
|
|
177
|
+
name: 'No error handling in hooks',
|
|
178
|
+
severity: 'medium',
|
|
179
|
+
description: 'Hook scripts without error handling can silently fail, giving a false sense of security.',
|
|
180
|
+
platforms: ['claude'],
|
|
181
|
+
fix: 'Add "set -e" to shell hooks and wrap commands in try/catch for JS hooks. Log failures to a known location.',
|
|
182
|
+
detect: (ctx) => {
|
|
183
|
+
if (!ctx.hasDir('.claude/hooks')) return false;
|
|
184
|
+
const hookFiles = ctx.dirFiles('.claude/hooks');
|
|
185
|
+
for (const file of hookFiles) {
|
|
186
|
+
const content = ctx.fileContent(`.claude/hooks/${file}`) || '';
|
|
187
|
+
if (file.endsWith('.sh') && content.length > 0 && !content.includes('set -e')) {
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return false;
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
id: 'AP013',
|
|
196
|
+
name: 'Hardcoded paths in CLAUDE.md',
|
|
197
|
+
severity: 'medium',
|
|
198
|
+
description: 'Absolute paths like /Users/alice/project or C:\\Users break when other developers clone the repo.',
|
|
199
|
+
platforms: ['claude', 'codex', 'cursor', 'windsurf', 'copilot', 'gemini', 'aider', 'opencode'],
|
|
200
|
+
fix: 'Use relative paths or environment variables. Replace absolute paths with project-relative references.',
|
|
201
|
+
detect: (ctx) => {
|
|
202
|
+
const content = ctx.fileContent('CLAUDE.md') || ctx.fileContent('.claude/CLAUDE.md') || '';
|
|
203
|
+
if (!content) return false;
|
|
204
|
+
return /(?:\/Users\/[a-zA-Z]|\/home\/[a-zA-Z]|C:\\Users\\[a-zA-Z])/.test(content);
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
id: 'AP014',
|
|
209
|
+
name: 'No test command defined',
|
|
210
|
+
severity: 'medium',
|
|
211
|
+
description: 'Without a canonical test command in repo instructions or scripts, agents cannot verify changes reliably before handoff.',
|
|
212
|
+
platforms: ['claude', 'codex', 'cursor', 'windsurf', 'copilot', 'gemini', 'aider', 'opencode'],
|
|
213
|
+
fix: 'Add a canonical test command in repo instructions or package scripts, e.g. "Test: npm test" or "Test: pytest".',
|
|
214
|
+
detect: (ctx) => {
|
|
215
|
+
const content = getRepoInstructionBundle(ctx);
|
|
216
|
+
const pkg = ctx.jsonFile('package.json');
|
|
217
|
+
const hasTestInMd = hasDocumentedTestCommand(content);
|
|
218
|
+
const hasTestScript = pkg && pkg.scripts && pkg.scripts.test;
|
|
219
|
+
return !hasTestInMd && !hasTestScript;
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
id: 'AP023',
|
|
224
|
+
name: 'Suspicious prompt-injection phrases in repo instructions',
|
|
225
|
+
severity: 'high',
|
|
226
|
+
description: 'Instruction surfaces that say things like "ignore previous instructions", "bypass guardrails", or "score 100/100" create confusion and downstream trust problems, even when the static audit itself is not LLM-driven.',
|
|
227
|
+
platforms: ['claude', 'codex', 'cursor', 'windsurf', 'copilot', 'gemini', 'aider', 'opencode'],
|
|
228
|
+
fix: 'Remove adversarial phrases from repo instructions and replace them with an explicit trust-boundary note about treating repo/web/MCP content as untrusted data.',
|
|
229
|
+
detect: (ctx) => {
|
|
230
|
+
const content = getRepoInstructionBundle(ctx);
|
|
231
|
+
return containsPromptInjectionPattern(content);
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
id: 'AP015',
|
|
236
|
+
name: 'All permissions allowed',
|
|
237
|
+
severity: 'high',
|
|
238
|
+
description: 'Allowing all tool permissions without any deny rules gives the agent unrestricted system access.',
|
|
239
|
+
platforms: ['claude'],
|
|
240
|
+
fix: 'Define deny rules for destructive operations. At minimum deny rm -rf, git reset --hard, and .env reads.',
|
|
241
|
+
detect: (ctx) => {
|
|
242
|
+
const settings = ctx.jsonFile('.claude/settings.json') || ctx.jsonFile('.claude/settings.local.json');
|
|
243
|
+
if (!settings || !settings.permissions) return false;
|
|
244
|
+
const allow = settings.permissions.allow || [];
|
|
245
|
+
const deny = settings.permissions.deny || [];
|
|
246
|
+
return allow.length > 5 && deny.length === 0;
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
id: 'AP016',
|
|
251
|
+
name: 'Missing architecture diagram',
|
|
252
|
+
severity: 'low',
|
|
253
|
+
description: 'Without an architecture diagram, the agent has to infer project structure from file exploration, wasting tokens.',
|
|
254
|
+
platforms: ['claude', 'codex', 'cursor', 'windsurf', 'copilot', 'gemini', 'aider', 'opencode'],
|
|
255
|
+
fix: 'Add a Mermaid diagram in CLAUDE.md showing the main components and data flow.',
|
|
256
|
+
detect: (ctx) => {
|
|
257
|
+
const content = ctx.fileContent('CLAUDE.md') || ctx.fileContent('.claude/CLAUDE.md') || '';
|
|
258
|
+
if (!content) return false;
|
|
259
|
+
return !content.includes('mermaid') && !content.includes('```') && content.length > 200;
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
id: 'AP017',
|
|
264
|
+
name: 'Using deprecated features',
|
|
265
|
+
severity: 'medium',
|
|
266
|
+
description: 'Relying on deprecated features risks breakage when they are removed in future versions.',
|
|
267
|
+
platforms: ['claude'],
|
|
268
|
+
fix: 'Check the platform changelog for deprecated features and migrate to recommended alternatives.',
|
|
269
|
+
detect: (ctx) => {
|
|
270
|
+
const content = ctx.fileContent('CLAUDE.md') || ctx.fileContent('.claude/CLAUDE.md') || '';
|
|
271
|
+
const settings = ctx.jsonFile('.claude/settings.json') || ctx.jsonFile('.claude/settings.local.json');
|
|
272
|
+
// Check for known deprecated patterns
|
|
273
|
+
const deprecatedPatterns = [
|
|
274
|
+
/allowedTools/i,
|
|
275
|
+
/blockedTools/i,
|
|
276
|
+
];
|
|
277
|
+
const hasDeprecatedInMd = deprecatedPatterns.some(p => p.test(content));
|
|
278
|
+
const hasDeprecatedInSettings = settings && deprecatedPatterns.some(p => p.test(JSON.stringify(settings)));
|
|
279
|
+
return hasDeprecatedInMd || hasDeprecatedInSettings;
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
id: 'AP018',
|
|
284
|
+
name: 'No rules files',
|
|
285
|
+
severity: 'low',
|
|
286
|
+
description: 'Without .claude/rules/ files, all instructions live in one place, making it harder to scope guidance by file type.',
|
|
287
|
+
platforms: ['claude'],
|
|
288
|
+
fix: 'Create .claude/rules/ with scoped rules for different areas (e.g., tests.md, api.md, frontend.md).',
|
|
289
|
+
detect: (ctx) => {
|
|
290
|
+
return !ctx.hasDir('.claude/rules') || (ctx.dirFiles('.claude/rules') || []).length === 0;
|
|
291
|
+
},
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
id: 'AP019',
|
|
295
|
+
name: 'Overly long CLAUDE.md (>500 lines)',
|
|
296
|
+
severity: 'medium',
|
|
297
|
+
description: 'Instruction files over 500 lines consume excessive context tokens and reduce adherence to individual rules.',
|
|
298
|
+
platforms: ['claude'],
|
|
299
|
+
fix: 'Split into CLAUDE.md (core) + .claude/rules/ (scoped). Use @import for focused modules.',
|
|
300
|
+
detect: (ctx) => {
|
|
301
|
+
const content = ctx.fileContent('CLAUDE.md') || ctx.fileContent('.claude/CLAUDE.md') || '';
|
|
302
|
+
if (!content) return false;
|
|
303
|
+
const lineCount = content.split('\n').length;
|
|
304
|
+
return lineCount > 500;
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
id: 'AP020',
|
|
309
|
+
name: 'No security review command',
|
|
310
|
+
severity: 'medium',
|
|
311
|
+
description: 'Without a security review command, OWASP Top 10 vulnerabilities go undetected during agent-assisted development.',
|
|
312
|
+
platforms: ['claude', 'codex', 'cursor', 'windsurf', 'copilot', 'gemini', 'aider', 'opencode'],
|
|
313
|
+
fix: 'Add a /security-review command or include security scanning in your CI pipeline.',
|
|
314
|
+
detect: (ctx) => {
|
|
315
|
+
const content = ctx.fileContent('CLAUDE.md') || ctx.fileContent('.claude/CLAUDE.md') || '';
|
|
316
|
+
const hasSecurityReview = /security[- ]?review/i.test(content);
|
|
317
|
+
const hasSecurityCommand = ctx.hasDir('.claude/commands') &&
|
|
318
|
+
(ctx.dirFiles('.claude/commands') || []).some(f => /security/i.test(f));
|
|
319
|
+
return !hasSecurityReview && !hasSecurityCommand;
|
|
320
|
+
},
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
id: 'AP021',
|
|
324
|
+
name: 'Inline secrets in hook scripts',
|
|
325
|
+
severity: 'critical',
|
|
326
|
+
description: 'Hardcoded API keys or tokens in hook scripts are executed every session and easily leaked.',
|
|
327
|
+
platforms: ['claude'],
|
|
328
|
+
fix: 'Use environment variables in hooks. Reference secrets via $ENV_VAR instead of hardcoding values.',
|
|
329
|
+
detect: (ctx) => {
|
|
330
|
+
if (!ctx.hasDir('.claude/hooks')) return false;
|
|
331
|
+
const hookFiles = ctx.dirFiles('.claude/hooks');
|
|
332
|
+
const secretPatterns = [
|
|
333
|
+
/(?:api[_-]?key|token|password|secret)\s*=\s*['"][A-Za-z0-9_\-]{16,}['"]/i,
|
|
334
|
+
/sk-[A-Za-z0-9]{20,}/,
|
|
335
|
+
/ghp_[A-Za-z0-9]{36,}/,
|
|
336
|
+
/AKIA[A-Z0-9]{16}/,
|
|
337
|
+
];
|
|
338
|
+
for (const file of hookFiles) {
|
|
339
|
+
const content = ctx.fileContent(`.claude/hooks/${file}`) || '';
|
|
340
|
+
if (secretPatterns.some(p => p.test(content)) || containsEmbeddedSecret(content)) {
|
|
341
|
+
return true;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
return false;
|
|
345
|
+
},
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
id: 'AP022',
|
|
349
|
+
name: 'Missing .env protection in .gitignore',
|
|
350
|
+
severity: 'high',
|
|
351
|
+
description: 'Without .env in .gitignore, environment files with secrets can be accidentally committed and pushed.',
|
|
352
|
+
platforms: ['claude', 'codex', 'cursor', 'windsurf', 'copilot', 'gemini', 'aider', 'opencode'],
|
|
353
|
+
fix: 'Add .env, .env.*, and .env.local to .gitignore. Verify with "git check-ignore .env".',
|
|
354
|
+
detect: (ctx) => {
|
|
355
|
+
const gitignore = ctx.fileContent('.gitignore') || '';
|
|
356
|
+
if (!gitignore) return true;
|
|
357
|
+
return !gitignore.includes('.env');
|
|
358
|
+
},
|
|
359
|
+
},
|
|
360
|
+
];
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Return the full anti-pattern catalog.
|
|
364
|
+
* @returns {Array<Object>} All registered anti-patterns.
|
|
365
|
+
*/
|
|
366
|
+
function getAntiPatterns() {
|
|
367
|
+
return ANTI_PATTERNS.map(({ detect, ...rest }) => rest);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Detect anti-patterns present in a project context.
|
|
372
|
+
* @param {Object} ctx - A ProjectContext instance (from src/context.js).
|
|
373
|
+
* @returns {Array<Object>} Detected anti-patterns with id, name, severity, description, and fix.
|
|
374
|
+
*/
|
|
375
|
+
function detectAntiPatterns(ctx) {
|
|
376
|
+
const detected = [];
|
|
377
|
+
for (const pattern of ANTI_PATTERNS) {
|
|
378
|
+
try {
|
|
379
|
+
if (pattern.detect(ctx)) {
|
|
380
|
+
const { detect, ...rest } = pattern;
|
|
381
|
+
detected.push(rest);
|
|
382
|
+
}
|
|
383
|
+
} catch (_err) {
|
|
384
|
+
// Skip patterns that fail to detect (missing files, etc.)
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
return detected;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Print detected anti-patterns to the console.
|
|
392
|
+
* @param {Array<Object>} patterns - Detected anti-patterns.
|
|
393
|
+
* @param {Object} [options] - Display options.
|
|
394
|
+
* @param {boolean} [options.json] - Output as JSON.
|
|
395
|
+
*/
|
|
396
|
+
function printAntiPatterns(patterns, options = {}) {
|
|
397
|
+
if (options.json) {
|
|
398
|
+
console.log(JSON.stringify(patterns, null, 2));
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
const SEVERITY_COLORS = {
|
|
403
|
+
critical: '\x1b[31m',
|
|
404
|
+
high: '\x1b[33m',
|
|
405
|
+
medium: '\x1b[36m',
|
|
406
|
+
low: '\x1b[2m',
|
|
407
|
+
};
|
|
408
|
+
const RESET = '\x1b[0m';
|
|
409
|
+
const BOLD = '\x1b[1m';
|
|
410
|
+
const DIM = '\x1b[2m';
|
|
411
|
+
|
|
412
|
+
console.log('');
|
|
413
|
+
console.log(`${BOLD} nerviq anti-patterns${RESET}`);
|
|
414
|
+
console.log(`${DIM} ${'═'.repeat(39)}${RESET}`);
|
|
415
|
+
|
|
416
|
+
if (patterns.length === 0) {
|
|
417
|
+
console.log(` ${'\\x1b[32m'}No anti-patterns detected. Good job!${RESET}`);
|
|
418
|
+
console.log('');
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
console.log(` ${patterns.length} anti-pattern${patterns.length === 1 ? '' : 's'} detected`);
|
|
423
|
+
console.log('');
|
|
424
|
+
|
|
425
|
+
// Sort by severity: critical > high > medium > low
|
|
426
|
+
const severityOrder = { critical: 0, high: 1, medium: 2, low: 3 };
|
|
427
|
+
const sorted = [...patterns].sort((a, b) => (severityOrder[a.severity] || 9) - (severityOrder[b.severity] || 9));
|
|
428
|
+
|
|
429
|
+
for (const p of sorted) {
|
|
430
|
+
const color = SEVERITY_COLORS[p.severity] || '';
|
|
431
|
+
console.log(` ${color}[${p.severity}]${RESET} ${p.name} (${p.id})`);
|
|
432
|
+
console.log(`${DIM} ${p.description}${RESET}`);
|
|
433
|
+
console.log(`${DIM} Fix: ${p.fix}${RESET}`);
|
|
434
|
+
console.log('');
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Print the full anti-pattern catalog.
|
|
440
|
+
* @param {Object} [options] - Display options.
|
|
441
|
+
* @param {boolean} [options.json] - Output as JSON.
|
|
442
|
+
*/
|
|
443
|
+
function printAntiPatternCatalog(options = {}) {
|
|
444
|
+
const all = getAntiPatterns();
|
|
445
|
+
if (options.json) {
|
|
446
|
+
console.log(JSON.stringify(all, null, 2));
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
const SEVERITY_COLORS = {
|
|
451
|
+
critical: '\x1b[31m',
|
|
452
|
+
high: '\x1b[33m',
|
|
453
|
+
medium: '\x1b[36m',
|
|
454
|
+
low: '\x1b[2m',
|
|
455
|
+
};
|
|
456
|
+
const RESET = '\x1b[0m';
|
|
457
|
+
const BOLD = '\x1b[1m';
|
|
458
|
+
const DIM = '\x1b[2m';
|
|
459
|
+
|
|
460
|
+
console.log('');
|
|
461
|
+
console.log(`${BOLD} nerviq anti-pattern catalog${RESET}`);
|
|
462
|
+
console.log(`${DIM} ${'═'.repeat(39)}${RESET}`);
|
|
463
|
+
console.log(` ${all.length} anti-patterns registered`);
|
|
464
|
+
console.log('');
|
|
465
|
+
|
|
466
|
+
const severityOrder = { critical: 0, high: 1, medium: 2, low: 3 };
|
|
467
|
+
const sorted = [...all].sort((a, b) => (severityOrder[a.severity] || 9) - (severityOrder[b.severity] || 9));
|
|
468
|
+
|
|
469
|
+
for (const p of sorted) {
|
|
470
|
+
const color = SEVERITY_COLORS[p.severity] || '';
|
|
471
|
+
console.log(` ${color}[${p.severity}]${RESET} ${p.name} (${p.id})`);
|
|
472
|
+
console.log(`${DIM} ${p.description}${RESET}`);
|
|
473
|
+
console.log(`${DIM} Platforms: ${p.platforms.join(', ')}${RESET}`);
|
|
474
|
+
console.log(`${DIM} Fix: ${p.fix}${RESET}`);
|
|
475
|
+
console.log('');
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
module.exports = {
|
|
480
|
+
ANTI_PATTERNS,
|
|
481
|
+
getAntiPatterns,
|
|
482
|
+
detectAntiPatterns,
|
|
483
|
+
printAntiPatterns,
|
|
484
|
+
printAntiPatternCatalog,
|
|
485
|
+
};
|