Skip to content

Suggest Changes

geoffrey fernald edited this page Jan 28, 2026 · 1 revision

Suggest Changes

Get AI-guided suggestions for fixing pattern violations, security issues, or code quality problems. Returns specific code changes with before/after examples and rationale.

Overview

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.                                        β”‚
β”‚                                                                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

MCP Tool

drift_suggest_changes

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"]
  }
}

Issue-Specific Suggestions

Pattern Outliers

drift_suggest_changes({
  target: "src/api/users.ts",
  issue: "outlier",
  patternId: "api-rest-controller"
})

Suggests changes to align with established patterns.

Security Issues

drift_suggest_changes({
  target: "src/auth/login.ts",
  issue: "security"
})

Suggests security improvements:

  • Input validation
  • SQL injection prevention
  • XSS protection
  • Rate limiting

Error Handling

drift_suggest_changes({
  target: "src/services/payment.ts",
  issue: "error-handling"
})

Suggests:

  • Try-catch blocks
  • Error logging
  • Proper error propagation
  • Circuit breakers

Coupling Issues

drift_suggest_changes({
  target: "src/core/database.ts",
  issue: "coupling"
})

Suggests:

  • Interface extraction
  • Dependency injection
  • Module boundary fixes

Test Coverage

drift_suggest_changes({
  target: "src/services/user.ts",
  issue: "test-coverage"
})

Suggests:

  • Missing test cases
  • Edge cases to cover
  • Mock patterns to use

CLI Usage

Find Outliers First

drift check --detailed

Shows all pattern violations with IDs.

Get Suggestions

drift check --suggest

Includes fix suggestions in output.


Workflow Integration

1. Detect Issues

// 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"
});

2. Get Suggestions

// Get fix suggestions
const suggestions = await drift_suggest_changes({
  target: "src/api/users.ts",
  issue: "outlier",
  patternId: filePatterns.data.outliers[0].patternId
});

3. Apply and Validate

// 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
});

Suggestion Quality

Confidence Scores

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 Levels

Priority Action
critical Should fix immediately
high Should fix before merging
medium Should fix, but not blocking
low Nice to have improvement

Best Practices

1. Review Before Applying

// 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
  }
}

2. Validate After Applying

// After applying suggestions
await drift_validate_change({
  file: "src/api/users.ts",
  content: updatedCode
});

3. Run Tests

// Get affected tests
const tests = await drift_test_topology({
  action: "affected",
  files: ["src/api/users.ts"]
});

// Run them
// npm test -- ${tests.data.testFiles.join(' ')}

4. Use Related Pattern Info

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

Clone this wiki locally