-
Notifications
You must be signed in to change notification settings - Fork 59
Suggest Changes
geoffrey fernald edited this page Jan 28, 2026
·
1 revision
Get AI-guided suggestions for fixing pattern violations, security issues, or code quality problems. Returns specific code changes with before/after examples and rationale.
When Drift detects issues, drift_suggest_changes provides actionable fixes:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β SUGGESTED CHANGES β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β Issue: Pattern violation in src/api/users.ts β
β Pattern: api-rest-controller β
β β
β BEFORE: β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β app.get('/users/:id', async (req, res) => { β β
β β const user = await db.users.findById(req.params.id); β β
β β res.json(user); // β Missing response envelope β β
β β }); β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β AFTER: β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β app.get('/users/:id', async (req, res) => { β β
β β const user = await db.users.findById(req.params.id); β β
β β res.json({ β β
β β data: user, β β
β β meta: { timestamp: Date.now() } β β
β β }); // β
Matches response envelope pattern β β
β β }); β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β Rationale: Your codebase uses a consistent response envelope β
β pattern with { data, meta } structure. This change aligns β
β with 23 other endpoints. β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
drift_suggest_changes({
target: "src/api/users.ts", // File or function
issue: "outlier", // Type of issue
patternId: "api-rest-controller", // Specific pattern (for outliers)
maxSuggestions: 3 // Max suggestions to return
})Issue Types:
| Issue | Description |
|---|---|
outlier |
Pattern violation (code doesn't match established pattern) |
security |
Security vulnerability or concern |
coupling |
High coupling or dependency issue |
error-handling |
Missing or improper error handling |
test-coverage |
Missing test coverage |
pattern-violation |
General pattern non-compliance |
Response:
{
"summary": "Found 2 issue(s) in src/api/users.ts. 2 suggestion(s) provided.",
"data": {
"summary": "Found 2 issue(s) in src/api/users.ts. 2 suggestion(s) provided.",
"target": "src/api/users.ts",
"issueType": "outlier",
"suggestions": [
{
"id": "outlier-api-rest-controller-48",
"title": "Pattern violation: REST Controller Pattern",
"description": "This code deviates from the established \"REST Controller Pattern\" pattern used 23 times in the codebase.",
"priority": "high",
"category": "outlier",
"location": {
"file": "src/api/users.ts",
"startLine": 48,
"endLine": 53
},
"before": "res.json(user);",
"after": "// See src/api/orders.ts:34 for the correct pattern",
"rationale": "The \"REST Controller Pattern\" pattern has 23 consistent implementations with 92% confidence. This outlier should be refactored to match.",
"relatedPattern": {
"id": "api-rest-controller",
"name": "REST Controller Pattern",
"confidence": 0.92
},
"effort": "small",
"impact": "Improves consistency and maintainability"
},
{
"id": "error-no-try-catch-47",
"title": "Error handling gap: no try catch",
"description": "Missing error handling for database query",
"priority": "medium",
"category": "error-handling",
"location": {
"file": "src/api/users.ts",
"startLine": 47,
"endLine": 50
},
"before": "// getUser at line 47",
"after": "try {\n // existing code\n} catch (error) {\n logger.error('Operation failed', { error });\n throw error;\n}",
"rationale": "Proper error handling improves reliability and debuggability.",
"effort": "small",
"impact": "Improves error visibility and application reliability"
}
],
"stats": {
"totalIssues": 2,
"bySeverity": { "high": 1, "medium": 1 },
"estimatedEffort": "minimal"
}
},
"hints": {
"nextActions": [
"Review suggestions and apply changes",
"Use drift_validate_change to verify fixes"
],
"relatedTools": ["drift_validate_change", "drift_code_examples", "drift_impact_analysis"]
}
}drift_suggest_changes({
target: "src/api/users.ts",
issue: "outlier",
patternId: "api-rest-controller"
})Suggests changes to align with established patterns.
drift_suggest_changes({
target: "src/auth/login.ts",
issue: "security"
})Suggests security improvements:
- Input validation
- SQL injection prevention
- XSS protection
- Rate limiting
drift_suggest_changes({
target: "src/services/payment.ts",
issue: "error-handling"
})Suggests:
- Try-catch blocks
- Error logging
- Proper error propagation
- Circuit breakers
drift_suggest_changes({
target: "src/core/database.ts",
issue: "coupling"
})Suggests:
- Interface extraction
- Dependency injection
- Module boundary fixes
drift_suggest_changes({
target: "src/services/user.ts",
issue: "test-coverage"
})Suggests:
- Missing test cases
- Edge cases to cover
- Mock patterns to use
drift check --detailedShows all pattern violations with IDs.
drift check --suggestIncludes fix suggestions in output.
// Find pattern violations
const patterns = await drift_patterns_list({
status: "discovered"
});
// Check for outliers
const filePatterns = await drift_file_patterns({
file: "src/api/users.ts"
});// Get fix suggestions
const suggestions = await drift_suggest_changes({
target: "src/api/users.ts",
issue: "outlier",
patternId: filePatterns.data.outliers[0].patternId
});// Apply suggestion (manually or via AI)
const newCode = applySuggestion(suggestions.data.suggestions[0]);
// Validate the change
const validation = await drift_validate_change({
file: "src/api/users.ts",
content: newCode
});Suggestions include a relatedPattern with confidence when applicable:
| Score | Meaning |
|---|---|
| 0.9+ | High confidence, safe to apply |
| 0.7-0.9 | Good suggestion, review before applying |
| 0.5-0.7 | Possible improvement, needs careful review |
| <0.5 | Low confidence, manual review required |
| Priority | Action |
|---|---|
critical |
Should fix immediately |
high |
Should fix before merging |
medium |
Should fix, but not blocking |
low |
Nice to have improvement |
// Always review suggestions
const suggestions = await drift_suggest_changes({
target: file,
issue: "outlier"
});
// Check confidence and rationale
for (const suggestion of suggestions.data.suggestions) {
if (suggestion.confidence > 0.8) {
// Safe to apply
} else {
// Review manually
}
}// After applying suggestions
await drift_validate_change({
file: "src/api/users.ts",
content: updatedCode
});// Get affected tests
const tests = await drift_test_topology({
action: "affected",
files: ["src/api/users.ts"]
});
// Run them
// npm test -- ${tests.data.testFiles.join(' ')}Suggestions include relatedPattern when addressing pattern violations β use this to understand the pattern:
{
"relatedPattern": {
"id": "api-rest-controller",
"name": "REST Controller Pattern",
"confidence": 0.92
}
}Use drift_code_examples with the pattern ID to see correct implementations.
---
## Next Steps
- [Validate Change](Validate-Change) β Verify code compliance
- [Code Examples](Code-Examples) β See pattern implementations
- [Quality Gates](Quality-Gates) β CI/CD integration
- Cortex V2 Overview
- Memory Setup Wizard
- Memory CLI
- Universal Memory Types
- Learning System
- Token Efficiency
- Causal Graphs
- Code Generation
- Predictive Retrieval
- Architecture
- Call Graph Analysis
- Impact Analysis
- Security Analysis
- Data Boundaries
- Test Topology
- Coupling Analysis
- Error Handling Analysis
- Wrappers Detection
- Environment Variables
- Constants Analysis
- Styling DNA
- Constraints
- Contracts
- Decision Mining
- Speculative Execution
- Watch Mode
- Trends Analysis
- Projects Management
- Package Context
- Monorepo Support
- Reports & Export
- Dashboard
- 10 Languages
- 21 Frameworks
- 16 ORMs
- 400+ Detectors
- 50+ MCP Tools
- 60+ CLI Commands
- 23 Memory Types