@nerviq/cli 1.18.0 → 1.20.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.
Files changed (187) hide show
  1. package/LICENSE +23 -23
  2. package/README.md +2 -2
  3. package/bin/cli.js +131 -130
  4. package/package.json +2 -1
  5. package/src/activity.js +1039 -1039
  6. package/src/adoption-advisor.js +299 -299
  7. package/src/aider/config-parser.js +166 -166
  8. package/src/aider/context.js +158 -158
  9. package/src/aider/deep-review.js +316 -316
  10. package/src/aider/domain-packs.js +303 -303
  11. package/src/aider/freshness.js +93 -93
  12. package/src/aider/governance.js +253 -253
  13. package/src/aider/interactive.js +334 -334
  14. package/src/aider/mcp-packs.js +329 -329
  15. package/src/aider/patch.js +214 -214
  16. package/src/aider/plans.js +186 -186
  17. package/src/aider/premium.js +360 -360
  18. package/src/aider/setup.js +404 -404
  19. package/src/aider/techniques.js +16 -16
  20. package/src/analyze.js +951 -951
  21. package/src/anti-patterns.js +485 -485
  22. package/src/audit/instruction-files.js +180 -180
  23. package/src/audit/recommendations.js +577 -577
  24. package/src/auto-suggest.js +154 -154
  25. package/src/badge.js +13 -13
  26. package/src/behavioral-drift.js +801 -801
  27. package/src/benchmark.js +67 -67
  28. package/src/catalog.js +103 -103
  29. package/src/certification.js +128 -128
  30. package/src/codex/config-parser.js +183 -183
  31. package/src/codex/context.js +223 -223
  32. package/src/codex/deep-review.js +493 -493
  33. package/src/codex/domain-packs.js +394 -394
  34. package/src/codex/freshness.js +84 -84
  35. package/src/codex/governance.js +192 -192
  36. package/src/codex/interactive.js +618 -618
  37. package/src/codex/mcp-packs.js +914 -914
  38. package/src/codex/patch.js +209 -209
  39. package/src/codex/plans.js +251 -251
  40. package/src/codex/premium.js +614 -614
  41. package/src/codex/setup.js +591 -591
  42. package/src/context.js +320 -320
  43. package/src/continuous-ops.js +681 -681
  44. package/src/copilot/activity.js +309 -309
  45. package/src/copilot/deep-review.js +346 -346
  46. package/src/copilot/domain-packs.js +372 -372
  47. package/src/copilot/freshness.js +57 -57
  48. package/src/copilot/governance.js +222 -222
  49. package/src/copilot/interactive.js +406 -406
  50. package/src/copilot/mcp-packs.js +826 -826
  51. package/src/copilot/plans.js +253 -253
  52. package/src/copilot/premium.js +451 -451
  53. package/src/copilot/setup.js +488 -488
  54. package/src/cost-tracking.js +61 -61
  55. package/src/cursor/activity.js +301 -301
  56. package/src/cursor/config-parser.js +265 -265
  57. package/src/cursor/context.js +256 -256
  58. package/src/cursor/deep-review.js +334 -334
  59. package/src/cursor/domain-packs.js +368 -368
  60. package/src/cursor/freshness.js +65 -65
  61. package/src/cursor/governance.js +229 -229
  62. package/src/cursor/interactive.js +391 -391
  63. package/src/cursor/mcp-packs.js +828 -828
  64. package/src/cursor/plans.js +254 -254
  65. package/src/cursor/premium.js +469 -469
  66. package/src/cursor/setup.js +488 -488
  67. package/src/dashboard.js +493 -493
  68. package/src/deep-review.js +428 -428
  69. package/src/deprecation.js +98 -98
  70. package/src/diff-only.js +280 -280
  71. package/src/doctor.js +119 -119
  72. package/src/domain-pack-expansion.js +1033 -1033
  73. package/src/domain-packs.js +387 -387
  74. package/src/feedback.js +178 -178
  75. package/src/fix-engine.js +783 -783
  76. package/src/fix-prompts.js +122 -122
  77. package/src/formatters/sarif.js +115 -115
  78. package/src/freshness.js +74 -74
  79. package/src/gemini/config-parser.js +275 -275
  80. package/src/gemini/context.js +290 -221
  81. package/src/gemini/deep-review.js +559 -559
  82. package/src/gemini/domain-packs.js +393 -393
  83. package/src/gemini/freshness.js +66 -66
  84. package/src/gemini/governance.js +201 -201
  85. package/src/gemini/interactive.js +860 -860
  86. package/src/gemini/mcp-packs.js +915 -915
  87. package/src/gemini/plans.js +269 -269
  88. package/src/gemini/premium.js +760 -760
  89. package/src/gemini/setup.js +692 -692
  90. package/src/gemini/techniques.js +105 -33
  91. package/src/governance.js +72 -72
  92. package/src/harmony/add.js +68 -68
  93. package/src/harmony/advisor.js +333 -333
  94. package/src/harmony/canon.js +565 -565
  95. package/src/harmony/cli.js +591 -591
  96. package/src/harmony/drift.js +401 -401
  97. package/src/harmony/governance.js +313 -313
  98. package/src/harmony/memory.js +239 -239
  99. package/src/harmony/sync.js +475 -475
  100. package/src/harmony/watch.js +370 -370
  101. package/src/hook-validation.js +342 -342
  102. package/src/index.js +271 -271
  103. package/src/init.js +184 -184
  104. package/src/instruction-surfaces.js +185 -185
  105. package/src/integrations.js +144 -144
  106. package/src/interactive.js +118 -118
  107. package/src/locales/en.json +1 -1
  108. package/src/locales/es.json +1 -1
  109. package/src/mcp-packs.js +830 -830
  110. package/src/mcp-server.js +726 -726
  111. package/src/mcp-validation.js +337 -337
  112. package/src/nerviq-sync.json +7 -7
  113. package/src/opencode/config-parser.js +109 -109
  114. package/src/opencode/context.js +247 -247
  115. package/src/opencode/deep-review.js +313 -313
  116. package/src/opencode/domain-packs.js +262 -262
  117. package/src/opencode/freshness.js +66 -66
  118. package/src/opencode/governance.js +159 -159
  119. package/src/opencode/interactive.js +392 -392
  120. package/src/opencode/mcp-packs.js +705 -705
  121. package/src/opencode/patch.js +184 -184
  122. package/src/opencode/plans.js +231 -231
  123. package/src/opencode/premium.js +413 -413
  124. package/src/opencode/setup.js +449 -449
  125. package/src/opencode/techniques.js +27 -27
  126. package/src/operating-profile.js +574 -574
  127. package/src/org.js +152 -152
  128. package/src/permission-rules.js +218 -218
  129. package/src/plans.js +839 -839
  130. package/src/platform-change-manifest.js +86 -86
  131. package/src/plugins.js +110 -110
  132. package/src/policy-layers.js +210 -210
  133. package/src/profiles.js +124 -124
  134. package/src/prompt-injection.js +74 -74
  135. package/src/public-api.js +173 -173
  136. package/src/recommendation-rules.js +84 -84
  137. package/src/repo-archetype.js +386 -386
  138. package/src/secret-patterns.js +39 -39
  139. package/src/server.js +527 -527
  140. package/src/setup/analysis.js +607 -607
  141. package/src/setup/runtime.js +172 -172
  142. package/src/setup.js +677 -677
  143. package/src/shared/capabilities.js +194 -194
  144. package/src/source-urls.js +132 -132
  145. package/src/stack-checks.js +565 -565
  146. package/src/supplemental-checks.js +13 -13
  147. package/src/synergy/adaptive.js +261 -261
  148. package/src/synergy/compensation.js +137 -137
  149. package/src/synergy/evidence.js +193 -193
  150. package/src/synergy/learning.js +199 -199
  151. package/src/synergy/patterns.js +227 -227
  152. package/src/synergy/ranking.js +83 -83
  153. package/src/synergy/report.js +165 -165
  154. package/src/synergy/routing.js +146 -146
  155. package/src/techniques/api.js +407 -407
  156. package/src/techniques/automation.js +316 -316
  157. package/src/techniques/compliance.js +257 -257
  158. package/src/techniques/hygiene.js +294 -294
  159. package/src/techniques/instructions.js +243 -243
  160. package/src/techniques/observability.js +226 -226
  161. package/src/techniques/optimization.js +142 -142
  162. package/src/techniques/quality.js +318 -318
  163. package/src/techniques/security.js +237 -237
  164. package/src/techniques/shared.js +443 -443
  165. package/src/techniques/stacks.js +2294 -2294
  166. package/src/techniques/tools.js +106 -106
  167. package/src/techniques/workflow.js +413 -413
  168. package/src/techniques.js +81 -81
  169. package/src/terminology.js +73 -73
  170. package/src/token-estimate.js +35 -35
  171. package/src/usage-patterns.js +99 -99
  172. package/src/verification-metadata.js +145 -145
  173. package/src/watch.js +247 -247
  174. package/src/windsurf/activity.js +302 -302
  175. package/src/windsurf/config-parser.js +267 -267
  176. package/src/windsurf/context.js +249 -249
  177. package/src/windsurf/deep-review.js +337 -337
  178. package/src/windsurf/domain-packs.js +370 -370
  179. package/src/windsurf/freshness.js +36 -36
  180. package/src/windsurf/governance.js +231 -231
  181. package/src/windsurf/interactive.js +388 -388
  182. package/src/windsurf/mcp-packs.js +792 -792
  183. package/src/windsurf/plans.js +247 -247
  184. package/src/windsurf/premium.js +468 -468
  185. package/src/windsurf/setup.js +471 -471
  186. package/src/windsurf/techniques.js +17 -17
  187. package/src/workspace.js +375 -375
@@ -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
+ };