coverme-scanner 1.0.4 → 1.0.6
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/dist/cli/scan.js +17 -418
- package/dist/cli/scan.js.map +1 -1
- package/dist/prompts/architecture-reviewer.md +171 -0
- package/dist/prompts/consensus-builder.md +247 -0
- package/dist/prompts/context-discovery.md +174 -0
- package/dist/prompts/cross-validator.md +224 -0
- package/dist/prompts/deep-dive-expert.md +224 -0
- package/dist/prompts/dependency-auditor.md +190 -0
- package/dist/prompts/orchestration.md +406 -0
- package/dist/prompts/performance-hunter.md +200 -0
- package/dist/prompts/quality-analyzer.md +150 -0
- package/dist/prompts/report-generator.md +285 -0
- package/dist/prompts/security-scanner.md +180 -0
- package/dist/report/generator.d.ts +23 -0
- package/dist/report/generator.d.ts.map +1 -1
- package/dist/report/generator.js +225 -36
- package/dist/report/generator.js.map +1 -1
- package/dist/templates/report.html +640 -295
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/cli/scan.ts +17 -414
- package/src/prompts/orchestration.md +406 -0
- package/src/report/generator.ts +261 -35
- package/src/templates/report.html +640 -295
- package/src/types.ts +1 -0
package/dist/cli/scan.js
CHANGED
|
@@ -75,424 +75,23 @@ Run: /coverme
|
|
|
75
75
|
// Output the orchestration prompt for Claude Code
|
|
76
76
|
console.log(generateOrchestrationPrompt(scanOptions));
|
|
77
77
|
}
|
|
78
|
-
function
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
{
|
|
90
|
-
"id": "PREFIX-XXX",
|
|
91
|
-
"title": "Short descriptive title",
|
|
92
|
-
"severity": "critical|high|medium|low|info",
|
|
93
|
-
"category": "Category name",
|
|
94
|
-
"file": "exact/path/to/file.ts",
|
|
95
|
-
"line": 123,
|
|
96
|
-
"code": "the vulnerable/problematic code snippet",
|
|
97
|
-
"description": "What is wrong - the specific problem found",
|
|
98
|
-
"why": "Why this matters - security impact, what an attacker could do, business risk",
|
|
99
|
-
"context": "Code context - what this code is trying to do, surrounding logic, dependencies",
|
|
100
|
-
"checkBefore": "What to verify before fixing - tests to run, dependencies to check, potential breaking changes",
|
|
101
|
-
"recommendation": "Exact steps to fix this issue with code example if applicable",
|
|
102
|
-
"cwe": "CWE-XXX (if applicable)",
|
|
103
|
-
"confidence": 85
|
|
104
|
-
}
|
|
105
|
-
\`\`\`
|
|
106
|
-
|
|
107
|
-
**FIELD GUIDELINES:**
|
|
108
|
-
- **why**: Explain the real-world impact. Example: "An attacker could steal session tokens and impersonate any user"
|
|
109
|
-
- **context**: Reference specific code. Example: "This function handles user uploads and is called from the /api/upload endpoint"
|
|
110
|
-
- **checkBefore**: CRITICAL - Always check for existing solutions first! Include:
|
|
111
|
-
|
|
112
|
-
EXISTING SOLUTIONS TO CHECK:
|
|
113
|
-
- Search for: sanitize, validate, escape functions in utils/
|
|
114
|
-
- Check if library already imported (e.g., DOMPurify, validator.js)
|
|
115
|
-
- Look at how other files handle this pattern
|
|
116
|
-
|
|
117
|
-
BEFORE IMPLEMENTING:
|
|
118
|
-
1. Run existing tests
|
|
119
|
-
2. Check for duplicate fixes needed elsewhere
|
|
120
|
-
3. Verify no breaking changes
|
|
121
|
-
|
|
122
|
-
---
|
|
123
|
-
|
|
124
|
-
### PHASE 1: PARALLEL DISCOVERY (Launch ALL 10 agents simultaneously)
|
|
125
|
-
|
|
126
|
-
---
|
|
127
|
-
|
|
128
|
-
**AGENT 1: Security Core Scanner** (ID prefix: SEC)
|
|
129
|
-
\`\`\`
|
|
130
|
-
Scan ${projectPath} for OWASP Top 10 and core security vulnerabilities.
|
|
131
|
-
|
|
132
|
-
CHECK FOR:
|
|
133
|
-
- SQL/NoSQL Injection (parameterized queries missing)
|
|
134
|
-
- XSS (reflected, stored, DOM-based)
|
|
135
|
-
- Command Injection (shell commands with user input)
|
|
136
|
-
- Path Traversal (../ in file operations)
|
|
137
|
-
- SSRF (user-controlled URLs in fetch/axios)
|
|
138
|
-
- XXE (XML parsing without disabling entities)
|
|
139
|
-
- Insecure Deserialization (JSON.parse on untrusted data)
|
|
140
|
-
- Hardcoded Secrets (API keys, passwords, tokens in code)
|
|
141
|
-
- Weak Cryptography (MD5, SHA1 for passwords, ECB mode)
|
|
142
|
-
- Insecure Random (Math.random for security purposes)
|
|
143
|
-
|
|
144
|
-
For EACH finding, output the FULL JSON format above.
|
|
145
|
-
\`\`\`
|
|
146
|
-
|
|
147
|
-
---
|
|
148
|
-
|
|
149
|
-
**AGENT 2: Auth & Session Scanner** (ID prefix: AUTH)
|
|
150
|
-
\`\`\`
|
|
151
|
-
Scan ${projectPath} for authentication and session vulnerabilities.
|
|
152
|
-
|
|
153
|
-
CHECK FOR:
|
|
154
|
-
- SSO/OAuth Open Redirect (return_url, redirect_uri without validation)
|
|
155
|
-
- PKCE missing in OAuth flows
|
|
156
|
-
- JWT issues (alg:none, weak secrets, missing expiry)
|
|
157
|
-
- Session fixation (session not regenerated after login)
|
|
158
|
-
- Cookie security (missing HttpOnly, Secure, SameSite)
|
|
159
|
-
- Password reset flaws (predictable tokens, no expiry)
|
|
160
|
-
- MFA bypass paths
|
|
161
|
-
- Remember-me token weaknesses
|
|
162
|
-
- Account enumeration (different responses for valid/invalid users)
|
|
163
|
-
- Brute force protection missing
|
|
164
|
-
|
|
165
|
-
For EACH finding, output the FULL JSON format.
|
|
166
|
-
\`\`\`
|
|
167
|
-
|
|
168
|
-
---
|
|
169
|
-
|
|
170
|
-
**AGENT 3: API Security Scanner** (ID prefix: API)
|
|
171
|
-
\`\`\`
|
|
172
|
-
Scan ${projectPath} for API security issues.
|
|
173
|
-
|
|
174
|
-
CHECK FOR:
|
|
175
|
-
- Missing authentication on endpoints
|
|
176
|
-
- Broken authorization (IDOR, privilege escalation)
|
|
177
|
-
- Input validation missing (Zod/Joi schemas)
|
|
178
|
-
- Rate limiting issues (non-atomic INCR+EXPIRE in Redis)
|
|
179
|
-
- CORS misconfiguration (Access-Control-Allow-Origin: *)
|
|
180
|
-
- Mass assignment (spreading req.body into DB)
|
|
181
|
-
- Webhook signature verification missing (HMAC)
|
|
182
|
-
- GraphQL introspection enabled in production
|
|
183
|
-
- API versioning issues
|
|
184
|
-
- Excessive data exposure in responses
|
|
185
|
-
|
|
186
|
-
For EACH finding, output the FULL JSON format.
|
|
187
|
-
\`\`\`
|
|
188
|
-
|
|
189
|
-
---
|
|
190
|
-
|
|
191
|
-
**AGENT 4: Infrastructure Scanner** (ID prefix: INFRA)
|
|
192
|
-
\`\`\`
|
|
193
|
-
Scan ${projectPath} for infrastructure and DevOps issues.
|
|
194
|
-
|
|
195
|
-
CHECK FOR:
|
|
196
|
-
- Secrets in git-tracked files (Helm values, K8s manifests, .env committed)
|
|
197
|
-
- Real IPs/hostnames committed to repo
|
|
198
|
-
- Docker issues (running as root, secrets in layers)
|
|
199
|
-
- K8s pod security context missing
|
|
200
|
-
- CI/CD pipeline security (missing quality gates)
|
|
201
|
-
- Missing security headers in server config
|
|
202
|
-
- TLS/SSL configuration issues
|
|
203
|
-
- Debug mode enabled in production configs
|
|
204
|
-
- Exposed internal ports
|
|
205
|
-
- Missing resource limits
|
|
206
|
-
|
|
207
|
-
For EACH finding, output the FULL JSON format.
|
|
208
|
-
\`\`\`
|
|
209
|
-
|
|
210
|
-
---
|
|
211
|
-
|
|
212
|
-
**AGENT 5: Data & Privacy Scanner** (ID prefix: DATA)
|
|
213
|
-
\`\`\`
|
|
214
|
-
Scan ${projectPath} for data protection and privacy issues.
|
|
215
|
-
|
|
216
|
-
CHECK FOR:
|
|
217
|
-
- PII logging (emails, IPs, names in logs)
|
|
218
|
-
- GDPR deletion bugs (incomplete data removal)
|
|
219
|
-
- Encryption at rest missing for sensitive fields
|
|
220
|
-
- Data residency violations
|
|
221
|
-
- Backup encryption missing
|
|
222
|
-
- Sensitive data in URLs/query params
|
|
223
|
-
- Missing data classification
|
|
224
|
-
- Retention policy not enforced
|
|
225
|
-
- Export functionality exposing too much data
|
|
226
|
-
- Cross-tenant data leakage
|
|
227
|
-
|
|
228
|
-
For EACH finding, output the FULL JSON format.
|
|
229
|
-
\`\`\`
|
|
230
|
-
|
|
231
|
-
---
|
|
232
|
-
|
|
233
|
-
**AGENT 6: AI/LLM Security Scanner** (ID prefix: AI)
|
|
234
|
-
\`\`\`
|
|
235
|
-
Scan ${projectPath} for AI/LLM specific vulnerabilities.
|
|
236
|
-
|
|
237
|
-
CHECK FOR:
|
|
238
|
-
- Prompt injection (user input directly in prompts)
|
|
239
|
-
- Content filter fail-open (errors bypass safety)
|
|
240
|
-
- CDN imports without SRI (integrity hashes missing)
|
|
241
|
-
- Model output not sanitized before use
|
|
242
|
-
- Sensitive data sent to external AI APIs
|
|
243
|
-
- AI decision logging insufficient for audit
|
|
244
|
-
- Rate limiting on AI endpoints
|
|
245
|
-
- Cost controls missing
|
|
246
|
-
- Jailbreak prevention missing
|
|
247
|
-
- PII in training data/prompts
|
|
248
|
-
|
|
249
|
-
For EACH finding, output the FULL JSON format.
|
|
250
|
-
\`\`\`
|
|
251
|
-
|
|
252
|
-
---
|
|
253
|
-
|
|
254
|
-
**AGENT 7: Performance & DoS Scanner** (ID prefix: PERF)
|
|
255
|
-
\`\`\`
|
|
256
|
-
Scan ${projectPath} for performance and denial-of-service issues.
|
|
257
|
-
|
|
258
|
-
CHECK FOR:
|
|
259
|
-
- N+1 query patterns
|
|
260
|
-
- ReDoS (regex denial of service)
|
|
261
|
-
- Memory leaks (event listeners not removed, growing caches)
|
|
262
|
-
- Unbounded data structures
|
|
263
|
-
- Missing pagination
|
|
264
|
-
- SSE/WebSocket buffering entire streams
|
|
265
|
-
- Heavy computation blocking event loop
|
|
266
|
-
- Missing connection pooling
|
|
267
|
-
- Resource exhaustion (no limits on uploads, requests)
|
|
268
|
-
- Synchronous operations that should be async
|
|
269
|
-
|
|
270
|
-
For EACH finding, output the FULL JSON format.
|
|
271
|
-
\`\`\`
|
|
272
|
-
|
|
273
|
-
---
|
|
274
|
-
|
|
275
|
-
**AGENT 8: Business Logic Scanner** (ID prefix: BIZ)
|
|
276
|
-
\`\`\`
|
|
277
|
-
Scan ${projectPath} for business logic vulnerabilities.
|
|
278
|
-
|
|
279
|
-
CHECK FOR:
|
|
280
|
-
- Race conditions (TOCTOU, double-spend)
|
|
281
|
-
- Workflow bypass (skipping required steps)
|
|
282
|
-
- Price/quantity manipulation
|
|
283
|
-
- Negative value attacks
|
|
284
|
-
- State machine violations
|
|
285
|
-
- Time-based attacks (timing side channels)
|
|
286
|
-
- Non-constant-time comparisons for secrets
|
|
287
|
-
- Duplicate request handling (missing idempotency)
|
|
288
|
-
- Business rule bypass
|
|
289
|
-
- Inconsistent validation between client/server
|
|
290
|
-
|
|
291
|
-
For EACH finding, output the FULL JSON format.
|
|
292
|
-
\`\`\`
|
|
293
|
-
|
|
294
|
-
---
|
|
295
|
-
|
|
296
|
-
**AGENT 9: Code Quality Scanner** (ID prefix: QUAL)
|
|
297
|
-
\`\`\`
|
|
298
|
-
Scan ${projectPath} for code quality issues that affect security/reliability.
|
|
299
|
-
|
|
300
|
-
CHECK FOR:
|
|
301
|
-
- Error handling swallowing exceptions silently
|
|
302
|
-
- Missing error boundaries
|
|
303
|
-
- Inconsistent error responses
|
|
304
|
-
- Dead code with security implications
|
|
305
|
-
- DRY violations in security code
|
|
306
|
-
- Complex functions (high cyclomatic complexity)
|
|
307
|
-
- Any/unknown types masking issues
|
|
308
|
-
- Missing null checks
|
|
309
|
-
- Callback hell making auditing hard
|
|
310
|
-
- Anti-patterns (god objects, tight coupling)
|
|
311
|
-
|
|
312
|
-
For EACH finding, output the FULL JSON format.
|
|
313
|
-
\`\`\`
|
|
314
|
-
|
|
315
|
-
---
|
|
316
|
-
|
|
317
|
-
**AGENT 10: Testing & Reliability Scanner** (ID prefix: TEST)
|
|
318
|
-
\`\`\`
|
|
319
|
-
Scan ${projectPath} for testing and reliability gaps.
|
|
320
|
-
|
|
321
|
-
CHECK FOR:
|
|
322
|
-
- Missing tests for security-critical paths
|
|
323
|
-
- No CI quality gates
|
|
324
|
-
- Missing health checks
|
|
325
|
-
- No graceful shutdown handling
|
|
326
|
-
- Circuit breakers missing
|
|
327
|
-
- Retry logic without exponential backoff
|
|
328
|
-
- Missing observability (logging, metrics, tracing)
|
|
329
|
-
- Feature flags without cleanup
|
|
330
|
-
- Database migrations without rollback
|
|
331
|
-
- No chaos/failure testing evidence
|
|
332
|
-
|
|
333
|
-
For EACH finding, output the FULL JSON format.
|
|
334
|
-
\`\`\`
|
|
335
|
-
|
|
336
|
-
---
|
|
337
|
-
|
|
338
|
-
### PHASE 2: DUPLICATE & EXISTING SOLUTIONS CHECK
|
|
339
|
-
|
|
340
|
-
**AGENT 11: Duplicate & Existing Solutions Scanner** (ID prefix: DUP)
|
|
341
|
-
\`\`\`
|
|
342
|
-
CRITICAL: Before recommending ANY fix, check if a solution ALREADY EXISTS in the codebase.
|
|
343
|
-
|
|
344
|
-
For EVERY finding from Phase 1, search the codebase for:
|
|
345
|
-
|
|
346
|
-
1. **Existing utilities/helpers that solve this**:
|
|
347
|
-
- Search for similar function names (sanitize, validate, escape, hash, encrypt)
|
|
348
|
-
- Check utils/, helpers/, lib/, common/ folders
|
|
349
|
-
- Look for imported libraries that handle this
|
|
350
|
-
|
|
351
|
-
2. **Existing patterns in the codebase**:
|
|
352
|
-
- How do OTHER files handle the same issue?
|
|
353
|
-
- Is there a project-wide convention?
|
|
354
|
-
- Are there shared middleware/decorators?
|
|
355
|
-
|
|
356
|
-
3. **Configuration that already exists**:
|
|
357
|
-
- Check if there's a config for this (CSP headers, CORS, rate limits)
|
|
358
|
-
- Look in config/, .env files, infrastructure code
|
|
359
|
-
|
|
360
|
-
4. **Duplicate findings**:
|
|
361
|
-
- Is this the same issue reported multiple times?
|
|
362
|
-
- Are multiple findings actually ONE root cause?
|
|
363
|
-
|
|
364
|
-
For EACH finding, add to the checkBefore field:
|
|
365
|
-
- "EXISTING: Found sanitizeHtml() in src/utils/security.ts - use this instead of creating new"
|
|
366
|
-
- "PATTERN: Other files use zod.string().email() for validation - follow same pattern"
|
|
367
|
-
- "DUPLICATE: This is same root cause as SEC-003, fix once in middleware"
|
|
368
|
-
- "CONFIG: Rate limiting already configured in src/middleware/rateLimit.ts line 15"
|
|
369
|
-
|
|
370
|
-
If NO existing solution found, state: "VERIFIED: No existing solution found, new implementation needed"
|
|
371
|
-
|
|
372
|
-
Output for each finding:
|
|
373
|
-
{
|
|
374
|
-
"findingId": "SEC-001",
|
|
375
|
-
"existingSolution": "Found: src/utils/sanitize.ts exports sanitizeUserInput()",
|
|
376
|
-
"duplicateOf": null | "SEC-003",
|
|
377
|
-
"suggestedApproach": "Import and use existing sanitizeUserInput() instead of creating new function",
|
|
378
|
-
"checkBefore": "1. Verify sanitizeUserInput() handles this case 2. Check if it's already imported"
|
|
379
|
-
}
|
|
380
|
-
\`\`\`
|
|
381
|
-
|
|
382
|
-
---
|
|
383
|
-
|
|
384
|
-
### PHASE 3: CROSS-VALIDATION (After Phase 2 completes)
|
|
385
|
-
|
|
386
|
-
Launch 3 validators IN PARALLEL:
|
|
387
|
-
|
|
388
|
-
**Validator A: False Positive & Duplicate Hunter**
|
|
389
|
-
\`\`\`
|
|
390
|
-
Review ALL findings from Phase 1 + Phase 2 duplicate analysis.
|
|
391
|
-
For each finding determine if it's FALSE POSITIVE or DUPLICATE:
|
|
392
|
-
- Is the code actually reachable?
|
|
393
|
-
- Are there mitigating controls elsewhere?
|
|
394
|
-
- Is the context misunderstood?
|
|
395
|
-
- Is it already handled by a framework?
|
|
396
|
-
- Is this a DUPLICATE of another finding? (same root cause)
|
|
397
|
-
- Does an EXISTING SOLUTION already exist in the codebase?
|
|
398
|
-
|
|
399
|
-
If existing solution found, mark as "use_existing" not "fix_new".
|
|
400
|
-
|
|
401
|
-
Output:
|
|
402
|
-
{
|
|
403
|
-
"confirmed": ["SEC-001", "AUTH-002", ...],
|
|
404
|
-
"useExisting": [
|
|
405
|
-
{"id": "SEC-005", "existingSolution": "src/utils/sanitize.ts", "reason": "sanitizeHtml() already exists"}
|
|
406
|
-
],
|
|
407
|
-
"duplicates": [
|
|
408
|
-
{"id": "SEC-007", "duplicateOf": "SEC-003", "reason": "Same XSS issue, fix once in shared component"}
|
|
409
|
-
],
|
|
410
|
-
"falsePositives": [
|
|
411
|
-
{"id": "API-003", "reason": "Input is validated by Zod schema at line 45"}
|
|
412
|
-
]
|
|
413
|
-
}
|
|
414
|
-
\`\`\`
|
|
415
|
-
|
|
416
|
-
**Validator B: Evidence Challenger**
|
|
417
|
-
\`\`\`
|
|
418
|
-
For every HIGH and CRITICAL finding:
|
|
419
|
-
- Read the actual code files
|
|
420
|
-
- Trace complete data flow
|
|
421
|
-
- Verify exploit scenario is realistic
|
|
422
|
-
- Check if exploitable in production context
|
|
423
|
-
|
|
424
|
-
Output same format as Validator A.
|
|
425
|
-
\`\`\`
|
|
426
|
-
|
|
427
|
-
**Validator C: Missing Issues Hunter**
|
|
428
|
-
\`\`\`
|
|
429
|
-
Look for issues Phase 1 agents MISSED:
|
|
430
|
-
- Edge cases
|
|
431
|
-
- Combination attacks
|
|
432
|
-
- Business logic flaws specific to this codebase
|
|
433
|
-
- Configuration issues
|
|
434
|
-
- Integration points
|
|
435
|
-
|
|
436
|
-
Output:
|
|
437
|
-
{
|
|
438
|
-
"missedIssues": [{full finding object}]
|
|
439
|
-
}
|
|
440
|
-
\`\`\`
|
|
441
|
-
|
|
442
|
-
---
|
|
443
|
-
|
|
444
|
-
### PHASE 3: POSITIVE OBSERVATIONS
|
|
445
|
-
|
|
446
|
-
Scan for good practices to include in the report:
|
|
447
|
-
- Security controls that work well
|
|
448
|
-
- Good patterns (input validation, parameterized queries)
|
|
449
|
-
- Proper error handling
|
|
450
|
-
- Good test coverage areas
|
|
451
|
-
- Well-implemented auth flows
|
|
452
|
-
|
|
453
|
-
Output as list of strings.
|
|
454
|
-
|
|
455
|
-
---
|
|
456
|
-
|
|
457
|
-
### PHASE 4: BUILD CONSENSUS & GENERATE OUTPUT
|
|
458
|
-
|
|
459
|
-
1. Calculate confidence: (confirmations / total_validators) * 100
|
|
460
|
-
2. Remove findings with confidence < 50%
|
|
461
|
-
3. Add missed issues from Validator C
|
|
462
|
-
4. Sort: severity DESC, confidence DESC
|
|
463
|
-
|
|
464
|
-
**SAVE OUTPUT AS JSON:**
|
|
465
|
-
\`\`\`json
|
|
466
|
-
{
|
|
467
|
-
"projectName": "project-name",
|
|
468
|
-
"scanDate": "${new Date().toISOString()}",
|
|
469
|
-
"summary": {
|
|
470
|
-
"total": X,
|
|
471
|
-
"critical": X,
|
|
472
|
-
"high": X,
|
|
473
|
-
"medium": X,
|
|
474
|
-
"low": X,
|
|
475
|
-
"info": X
|
|
476
|
-
},
|
|
477
|
-
"findings": [
|
|
478
|
-
{all findings with full fields}
|
|
479
|
-
],
|
|
480
|
-
"positiveObservations": [
|
|
481
|
-
"Good pattern 1",
|
|
482
|
-
"Good pattern 2"
|
|
483
|
-
],
|
|
484
|
-
"falsePositives": [
|
|
485
|
-
{"id": "...", "reason": "..."}
|
|
486
|
-
],
|
|
487
|
-
"agentsUsed": ["Security Core", "Auth & Session", ...],
|
|
488
|
-
"scanDuration": X
|
|
78
|
+
function loadPromptTemplate() {
|
|
79
|
+
const promptPath = path.join(__dirname, '..', 'prompts', 'orchestration.md');
|
|
80
|
+
// Try loading from dist/prompts first (compiled), then src/prompts (development)
|
|
81
|
+
if (fs.existsSync(promptPath)) {
|
|
82
|
+
return fs.readFileSync(promptPath, 'utf-8');
|
|
83
|
+
}
|
|
84
|
+
const srcPromptPath = path.join(__dirname, '..', '..', 'src', 'prompts', 'orchestration.md');
|
|
85
|
+
if (fs.existsSync(srcPromptPath)) {
|
|
86
|
+
return fs.readFileSync(srcPromptPath, 'utf-8');
|
|
87
|
+
}
|
|
88
|
+
throw new Error('Could not find orchestration.md prompt template');
|
|
489
89
|
}
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
`;
|
|
90
|
+
function generateOrchestrationPrompt(options) {
|
|
91
|
+
const template = loadPromptTemplate();
|
|
92
|
+
// Replace placeholders
|
|
93
|
+
return template
|
|
94
|
+
.replace(/\{\{PROJECT_PATH\}\}/g, options.path)
|
|
95
|
+
.replace(/\{\{SCAN_DATE\}\}/g, new Date().toISOString());
|
|
497
96
|
}
|
|
498
97
|
//# sourceMappingURL=scan.js.map
|
package/dist/cli/scan.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scan.js","sourceRoot":"","sources":["../../src/cli/scan.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,oBA+CC;AA5DD,uCAAyB;AACzB,2CAA6B;AAYtB,KAAK,UAAU,IAAI,CACxB,QAAgB,EAChB,OAA2B;IAE3B,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE5C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;QACjC,OAAO,CAAC,KAAK,CAAC,+BAA+B,YAAY,EAAE,CAAC,CAAC;QAC7D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,MAAM,UAAU,GACd,OAAO,CAAC,UAAU,KAAK,KAAK;QAC1B,CAAC,CAAC,CAAC,UAAU,EAAE,SAAS,EAAE,cAAc,EAAE,cAAc,EAAE,aAAa,CAAC;QACxE,CAAC,CAAE,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAgB,CAAC;IAEpD,MAAM,WAAW,GAAgB;QAC/B,IAAI,EAAE,YAAY;QAClB,MAAM,EAAE,OAAO,CAAC,MAAwC;QACxD,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,UAAU;QACV,WAAW,EAAE,OAAO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CAAC"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# Architecture Reviewer Agent
|
|
2
|
+
|
|
3
|
+
You are a senior software architect reviewing a codebase for architectural issues. Your job is to identify structural problems that affect scalability, maintainability, and system integrity.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
You will receive PROJECT CONTEXT from the Context Discovery agent. Use it to understand:
|
|
8
|
+
- Intended architecture (from docs)
|
|
9
|
+
- Component boundaries
|
|
10
|
+
- Data flow patterns
|
|
11
|
+
- Deployment model
|
|
12
|
+
|
|
13
|
+
## Scan Methodology
|
|
14
|
+
|
|
15
|
+
### 1. Layer Violations
|
|
16
|
+
Expected layers (adapt to project):
|
|
17
|
+
```
|
|
18
|
+
┌─────────────────────────────┐
|
|
19
|
+
│ Presentation (UI/API) │ <- Should only know about Services
|
|
20
|
+
├─────────────────────────────┤
|
|
21
|
+
│ Application (Services) │ <- Should only know about Domain
|
|
22
|
+
├─────────────────────────────┤
|
|
23
|
+
│ Domain (Entities/Logic) │ <- Should be pure, no dependencies
|
|
24
|
+
├─────────────────────────────┤
|
|
25
|
+
│ Infrastructure (DB/APIs) │ <- Implements interfaces from Domain
|
|
26
|
+
└─────────────────────────────┘
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Check for:
|
|
30
|
+
- [ ] Controllers importing database modules directly
|
|
31
|
+
- [ ] UI components making database queries
|
|
32
|
+
- [ ] Domain logic depending on infrastructure
|
|
33
|
+
- [ ] Cross-layer imports that skip layers
|
|
34
|
+
|
|
35
|
+
### 2. Dependency Issues
|
|
36
|
+
- [ ] Circular dependencies between modules
|
|
37
|
+
- [ ] Hidden dependencies (implicit globals)
|
|
38
|
+
- [ ] Dependency on concrete implementations vs interfaces
|
|
39
|
+
- [ ] Tight coupling between unrelated modules
|
|
40
|
+
- [ ] Missing dependency injection
|
|
41
|
+
- [ ] Hard-to-test dependencies (e.g., direct file system)
|
|
42
|
+
|
|
43
|
+
### 3. Component Boundaries
|
|
44
|
+
- [ ] Unclear module boundaries
|
|
45
|
+
- [ ] Shared mutable state between components
|
|
46
|
+
- [ ] Components with mixed responsibilities
|
|
47
|
+
- [ ] Missing API contracts between services
|
|
48
|
+
- [ ] Leaky abstractions (implementation details exposed)
|
|
49
|
+
- [ ] God modules (doing everything)
|
|
50
|
+
|
|
51
|
+
### 4. Data Flow
|
|
52
|
+
- [ ] Unclear data ownership
|
|
53
|
+
- [ ] Data transformed in too many places
|
|
54
|
+
- [ ] Missing validation at boundaries
|
|
55
|
+
- [ ] Inconsistent data formats
|
|
56
|
+
- [ ] No clear source of truth
|
|
57
|
+
- [ ] State scattered across system
|
|
58
|
+
|
|
59
|
+
### 5. API Design
|
|
60
|
+
- [ ] Inconsistent endpoint patterns
|
|
61
|
+
- [ ] Missing versioning
|
|
62
|
+
- [ ] Breaking changes without deprecation
|
|
63
|
+
- [ ] Overly chatty APIs
|
|
64
|
+
- [ ] Missing pagination
|
|
65
|
+
- [ ] N+1 API calls needed for common operations
|
|
66
|
+
- [ ] Missing rate limiting design
|
|
67
|
+
|
|
68
|
+
### 6. Error Architecture
|
|
69
|
+
- [ ] No centralized error handling
|
|
70
|
+
- [ ] Inconsistent error formats
|
|
71
|
+
- [ ] Missing error boundaries
|
|
72
|
+
- [ ] No error recovery strategies
|
|
73
|
+
- [ ] Silent failures
|
|
74
|
+
- [ ] Missing circuit breakers for external services
|
|
75
|
+
|
|
76
|
+
### 7. Configuration Management
|
|
77
|
+
- [ ] Hardcoded environment-specific values
|
|
78
|
+
- [ ] Secrets mixed with config
|
|
79
|
+
- [ ] No configuration validation
|
|
80
|
+
- [ ] Missing defaults
|
|
81
|
+
- [ ] Environment checks in business logic
|
|
82
|
+
|
|
83
|
+
### 8. Scalability Concerns
|
|
84
|
+
- [ ] Synchronous operations that should be async
|
|
85
|
+
- [ ] Missing queue for long-running tasks
|
|
86
|
+
- [ ] State stored in memory (not horizontally scalable)
|
|
87
|
+
- [ ] Missing caching strategy
|
|
88
|
+
- [ ] Database bottlenecks
|
|
89
|
+
- [ ] No graceful degradation
|
|
90
|
+
|
|
91
|
+
### 9. Observability
|
|
92
|
+
- [ ] Missing structured logging
|
|
93
|
+
- [ ] No correlation IDs
|
|
94
|
+
- [ ] Missing metrics
|
|
95
|
+
- [ ] No health checks
|
|
96
|
+
- [ ] Insufficient audit trails
|
|
97
|
+
- [ ] Missing tracing
|
|
98
|
+
|
|
99
|
+
### 10. Resilience
|
|
100
|
+
- [ ] No retry logic for external calls
|
|
101
|
+
- [ ] Missing timeouts
|
|
102
|
+
- [ ] No fallback strategies
|
|
103
|
+
- [ ] Single points of failure
|
|
104
|
+
- [ ] No backpressure handling
|
|
105
|
+
|
|
106
|
+
## Output Format
|
|
107
|
+
|
|
108
|
+
For EACH finding, output:
|
|
109
|
+
|
|
110
|
+
```json
|
|
111
|
+
{
|
|
112
|
+
"id": "ARCH-001",
|
|
113
|
+
"title": "Controller Directly Accesses Database",
|
|
114
|
+
"severity": "high",
|
|
115
|
+
"category": "architecture",
|
|
116
|
+
"subcategory": "layer_violation",
|
|
117
|
+
"file": "src/controllers/userController.js",
|
|
118
|
+
"line": 23,
|
|
119
|
+
"relatedFiles": [
|
|
120
|
+
"src/models/user.js",
|
|
121
|
+
"src/services/userService.js"
|
|
122
|
+
],
|
|
123
|
+
"code": "import { db } from '../database';\n\nexport const getUser = async (req, res) => {\n const user = await db.query('SELECT * FROM users WHERE id = $1', [req.params.id]);\n res.json(user);\n}",
|
|
124
|
+
"description": "Controller layer directly imports and uses database module, bypassing the service layer. This violates the layered architecture and makes the code harder to test and maintain.",
|
|
125
|
+
"impact": "1. Cannot mock database in tests\n2. Business logic gets scattered across controllers\n3. Database changes require controller changes\n4. No centralized place for data access logic",
|
|
126
|
+
"architectureDiagram": "Current: Controller -> Database (BAD)\nShould be: Controller -> Service -> Repository -> Database",
|
|
127
|
+
"recommendation": "Create a service layer:\n\n```typescript\n// src/services/userService.ts\nexport class UserService {\n constructor(private userRepository: UserRepository) {}\n \n async getUser(id: string): Promise<User> {\n return this.userRepository.findById(id);\n }\n}\n\n// src/controllers/userController.ts\nexport const getUser = async (req, res) => {\n const user = await userService.getUser(req.params.id);\n res.json(user);\n};\n```",
|
|
128
|
+
"effort": "medium",
|
|
129
|
+
"refactoringRisk": "low",
|
|
130
|
+
"evidence": [
|
|
131
|
+
"Controller imports database at line 1",
|
|
132
|
+
"Direct SQL query at line 23",
|
|
133
|
+
"No service layer exists for users"
|
|
134
|
+
]
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Severity Guidelines
|
|
139
|
+
|
|
140
|
+
- **Critical**: System cannot scale or will fail (e.g., memory state in distributed system)
|
|
141
|
+
- **High**: Significant architectural debt (e.g., layer violations, circular deps)
|
|
142
|
+
- **Medium**: Should be addressed (e.g., missing abstractions, tight coupling)
|
|
143
|
+
- **Low**: Improvement opportunity (e.g., could be more modular)
|
|
144
|
+
- **Info**: Suggestions (e.g., consider using X pattern)
|
|
145
|
+
|
|
146
|
+
## Rules
|
|
147
|
+
|
|
148
|
+
1. **Understand intended architecture first** - Read docs before judging
|
|
149
|
+
2. **Consider context** - Small projects may not need all layers
|
|
150
|
+
3. **Be practical** - Perfect architecture doesn't exist
|
|
151
|
+
4. **Identify patterns** - One violation might indicate systemic issue
|
|
152
|
+
5. **Suggest incrementally** - Don't propose complete rewrites
|
|
153
|
+
|
|
154
|
+
## Patterns to Look For
|
|
155
|
+
|
|
156
|
+
Good:
|
|
157
|
+
- Clean separation of concerns
|
|
158
|
+
- Dependency injection
|
|
159
|
+
- Repository pattern for data access
|
|
160
|
+
- Service layer for business logic
|
|
161
|
+
- Clear module boundaries
|
|
162
|
+
- Event-driven for decoupling
|
|
163
|
+
|
|
164
|
+
Bad:
|
|
165
|
+
- Big ball of mud
|
|
166
|
+
- Circular dependencies
|
|
167
|
+
- Anemic domain model
|
|
168
|
+
- Shotgun surgery (change requires many files)
|
|
169
|
+
- Leaky abstractions
|
|
170
|
+
|
|
171
|
+
START SCANNING NOW. Think like a system architect.
|