mirror of
https://github.com/wshobson/agents.git
synced 2026-03-18 09:37:15 +00:00
style: format all files with prettier
This commit is contained in:
@@ -15,13 +15,16 @@ Perform comprehensive analysis: security, performance, architecture, maintainabi
|
||||
## Automated Code Review Workflow
|
||||
|
||||
### Initial Triage
|
||||
|
||||
1. Parse diff to determine modified files and affected components
|
||||
2. Match file types to optimal static analysis tools
|
||||
3. Scale analysis based on PR size (superficial >1000 lines, deep <200 lines)
|
||||
4. Classify change type: feature, bug fix, refactoring, or breaking change
|
||||
|
||||
### Multi-Tool Static Analysis
|
||||
|
||||
Execute in parallel:
|
||||
|
||||
- **CodeQL**: Deep vulnerability analysis (SQL injection, XSS, auth bypasses)
|
||||
- **SonarQube**: Code smells, complexity, duplication, maintainability
|
||||
- **Semgrep**: Organization-specific rules and security policies
|
||||
@@ -29,6 +32,7 @@ Execute in parallel:
|
||||
- **GitGuardian/TruffleHog**: Secret detection
|
||||
|
||||
### AI-Assisted Review
|
||||
|
||||
```python
|
||||
# Context-aware review prompt for Claude 4.5 Sonnet
|
||||
review_prompt = f"""
|
||||
@@ -59,12 +63,14 @@ Format as JSON array.
|
||||
```
|
||||
|
||||
### Model Selection (2025)
|
||||
|
||||
- **Fast reviews (<200 lines)**: GPT-4o-mini or Claude 4.5 Haiku
|
||||
- **Deep reasoning**: Claude 4.5 Sonnet or GPT-5 (200K+ tokens)
|
||||
- **Code generation**: GitHub Copilot or Qodo
|
||||
- **Multi-language**: Qodo or CodeAnt AI (30+ languages)
|
||||
|
||||
### Review Routing
|
||||
|
||||
```typescript
|
||||
interface ReviewRoutingStrategy {
|
||||
async routeReview(pr: PullRequest): Promise<ReviewEngine> {
|
||||
@@ -94,6 +100,7 @@ interface ReviewRoutingStrategy {
|
||||
## Architecture Analysis
|
||||
|
||||
### Architectural Coherence
|
||||
|
||||
1. **Dependency Direction**: Inner layers don't depend on outer layers
|
||||
2. **SOLID Principles**:
|
||||
- Single Responsibility, Open/Closed, Liskov Substitution
|
||||
@@ -103,6 +110,7 @@ interface ReviewRoutingStrategy {
|
||||
- Anemic models, Shotgun surgery
|
||||
|
||||
### Microservices Review
|
||||
|
||||
```go
|
||||
type MicroserviceReviewChecklist struct {
|
||||
CheckServiceCohesion bool // Single capability per service?
|
||||
@@ -141,9 +149,11 @@ func (r *MicroserviceReviewer) AnalyzeServiceBoundaries(code string) []Issue {
|
||||
## Security Vulnerability Detection
|
||||
|
||||
### Multi-Layered Security
|
||||
|
||||
**SAST Layer**: CodeQL, Semgrep, Bandit/Brakeman/Gosec
|
||||
|
||||
**AI-Enhanced Threat Modeling**:
|
||||
|
||||
```python
|
||||
security_analysis_prompt = """
|
||||
Analyze authentication code for vulnerabilities:
|
||||
@@ -163,6 +173,7 @@ findings = claude.analyze(security_analysis_prompt, temperature=0.1)
|
||||
```
|
||||
|
||||
**Secret Scanning**:
|
||||
|
||||
```bash
|
||||
trufflehog git file://. --json | \
|
||||
jq '.[] | select(.Verified == true) | {
|
||||
@@ -173,6 +184,7 @@ trufflehog git file://. --json | \
|
||||
```
|
||||
|
||||
### OWASP Top 10 (2025)
|
||||
|
||||
1. **A01 - Broken Access Control**: Missing authorization, IDOR
|
||||
2. **A02 - Cryptographic Failures**: Weak hashing, insecure RNG
|
||||
3. **A03 - Injection**: SQL, NoSQL, command injection via taint analysis
|
||||
@@ -187,22 +199,25 @@ trufflehog git file://. --json | \
|
||||
## Performance Review
|
||||
|
||||
### Performance Profiling
|
||||
|
||||
```javascript
|
||||
class PerformanceReviewAgent {
|
||||
async analyzePRPerformance(prNumber) {
|
||||
const baseline = await this.loadBaselineMetrics('main');
|
||||
const baseline = await this.loadBaselineMetrics("main");
|
||||
const prBranch = await this.runBenchmarks(`pr-${prNumber}`);
|
||||
|
||||
const regressions = this.detectRegressions(baseline, prBranch, {
|
||||
cpuThreshold: 10, memoryThreshold: 15, latencyThreshold: 20
|
||||
cpuThreshold: 10,
|
||||
memoryThreshold: 15,
|
||||
latencyThreshold: 20,
|
||||
});
|
||||
|
||||
if (regressions.length > 0) {
|
||||
await this.postReviewComment(prNumber, {
|
||||
severity: 'HIGH',
|
||||
title: '⚠️ Performance Regression Detected',
|
||||
severity: "HIGH",
|
||||
title: "⚠️ Performance Regression Detected",
|
||||
body: this.formatRegressionReport(regressions),
|
||||
suggestions: await this.aiGenerateOptimizations(regressions)
|
||||
suggestions: await this.aiGenerateOptimizations(regressions),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -210,6 +225,7 @@ class PerformanceReviewAgent {
|
||||
```
|
||||
|
||||
### Scalability Red Flags
|
||||
|
||||
- **N+1 Queries**, **Missing Indexes**, **Synchronous External Calls**
|
||||
- **In-Memory State**, **Unbounded Collections**, **Missing Pagination**
|
||||
- **No Connection Pooling**, **No Rate Limiting**
|
||||
@@ -232,20 +248,28 @@ def detect_n_plus_1_queries(code_ast):
|
||||
## Review Comment Generation
|
||||
|
||||
### Structured Format
|
||||
|
||||
```typescript
|
||||
interface ReviewComment {
|
||||
path: string; line: number;
|
||||
severity: 'CRITICAL' | 'HIGH' | 'MEDIUM' | 'LOW' | 'INFO';
|
||||
category: 'Security' | 'Performance' | 'Bug' | 'Maintainability';
|
||||
title: string; description: string;
|
||||
codeExample?: string; references?: string[];
|
||||
autoFixable: boolean; cwe?: string; cvss?: number;
|
||||
effort: 'trivial' | 'easy' | 'medium' | 'hard';
|
||||
path: string;
|
||||
line: number;
|
||||
severity: "CRITICAL" | "HIGH" | "MEDIUM" | "LOW" | "INFO";
|
||||
category: "Security" | "Performance" | "Bug" | "Maintainability";
|
||||
title: string;
|
||||
description: string;
|
||||
codeExample?: string;
|
||||
references?: string[];
|
||||
autoFixable: boolean;
|
||||
cwe?: string;
|
||||
cvss?: number;
|
||||
effort: "trivial" | "easy" | "medium" | "hard";
|
||||
}
|
||||
|
||||
const comment: ReviewComment = {
|
||||
path: "src/auth/login.ts", line: 42,
|
||||
severity: "CRITICAL", category: "Security",
|
||||
path: "src/auth/login.ts",
|
||||
line: 42,
|
||||
severity: "CRITICAL",
|
||||
category: "Security",
|
||||
title: "SQL Injection in Login Query",
|
||||
description: `String concatenation with user input enables SQL injection.
|
||||
**Attack Vector:** Input 'admin' OR '1'='1' bypasses authentication.
|
||||
@@ -259,13 +283,17 @@ const query = 'SELECT * FROM users WHERE username = ?';
|
||||
const result = await db.execute(query, [username]);
|
||||
`,
|
||||
references: ["https://cwe.mitre.org/data/definitions/89.html"],
|
||||
autoFixable: false, cwe: "CWE-89", cvss: 9.8, effort: "easy"
|
||||
autoFixable: false,
|
||||
cwe: "CWE-89",
|
||||
cvss: 9.8,
|
||||
effort: "easy",
|
||||
};
|
||||
```
|
||||
|
||||
## CI/CD Integration
|
||||
|
||||
### GitHub Actions
|
||||
|
||||
```yaml
|
||||
name: AI Code Review
|
||||
on:
|
||||
@@ -318,7 +346,7 @@ jobs:
|
||||
|
||||
## Complete Example: AI Review Automation
|
||||
|
||||
```python
|
||||
````python
|
||||
#!/usr/bin/env python3
|
||||
import os, json, subprocess
|
||||
from dataclasses import dataclass
|
||||
@@ -411,11 +439,12 @@ if __name__ == '__main__':
|
||||
diff = reviewer.get_pr_diff()
|
||||
ai_issues = reviewer.ai_review(diff, static_results)
|
||||
reviewer.post_review_comments(ai_issues)
|
||||
```
|
||||
````
|
||||
|
||||
## Summary
|
||||
|
||||
Comprehensive AI code review combining:
|
||||
|
||||
1. Multi-tool static analysis (SonarQube, CodeQL, Semgrep)
|
||||
2. State-of-the-art LLMs (GPT-5, Claude 4.5 Sonnet)
|
||||
3. Seamless CI/CD integration (GitHub Actions, GitLab, Azure DevOps)
|
||||
|
||||
Reference in New Issue
Block a user