-
Notifications
You must be signed in to change notification settings - Fork 59
Validate Change
geoffrey fernald edited this page Jan 28, 2026
·
1 revision
Validate proposed code changes against codebase patterns before committing. Catches pattern violations, constraint breaches, and inconsistencies early.
Before committing code, validate it matches your codebase conventions:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β VALIDATION RESULT β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β File: src/api/users.ts β
β Status: β οΈ WARNINGS (2) β
β β
β Compliance Score: 78/100 β
β β
β β
PASSED β
β β’ REST Controller Pattern β
β β’ Error Handling Pattern β
β β’ Logging Pattern β
β β
β β οΈ WARNINGS β
β β’ Response envelope missing meta.requestId β
β β’ Missing rate limiting middleware β
β β
β π‘ SUGGESTIONS β
β β’ Add requestId to response meta for tracing β
β β’ Consider adding @RateLimit decorator β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Validate complete file content:
drift_validate_change({
file: "src/api/users.ts",
content: `
@Controller('/api/users')
export class UsersController {
@Get('/:id')
async getUser(@Param('id') id: string) {
const user = await this.userService.findById(id);
return { data: user };
}
}
`,
strictMode: false
})Or validate a diff:
drift_validate_change({
file: "src/api/users.ts",
diff: `
--- a/src/api/users.ts
+++ b/src/api/users.ts
@@ -10,6 +10,10 @@ export class UsersController {
+ @Post('/')
+ async createUser(@Body() dto: CreateUserDto) {
+ return this.userService.create(dto);
+ }
`,
strictMode: true
})Response:
{
"summary": "β οΈ Code has 2 warning(s) (78% compliance)",
"data": {
"summary": "β οΈ Code has 2 warning(s) (78% compliance)",
"file": "src/api/users.ts",
"overallScore": 78,
"status": "warn",
"violations": [
{
"patternId": "api-response-envelope",
"patternName": "Response Envelope Pattern",
"severity": "warning",
"message": "Response envelope missing meta.requestId",
"line": 8,
"suggestion": "Add requestId: req.id to meta object",
"confidence": 0.85
},
{
"patternId": "semantic-sensitive-data",
"patternName": "Sensitive Data Access",
"severity": "info",
"message": "Accessing sensitive fields: password_hash",
"line": 12,
"suggestion": "Ensure proper authorization and audit logging for sensitive data access",
"confidence": 0.9
}
],
"compliance": [
{
"patternId": "api-rest-controller",
"patternName": "REST Controller Pattern",
"status": "compliant",
"score": 100,
"details": "1/1 semantic checks passed"
},
{
"patternId": "error-handling-try-catch",
"patternName": "Error Handling Pattern",
"status": "compliant",
"score": 100,
"details": "1/1 semantic checks passed"
}
],
"semanticValidation": {
"functions": {
"total": 0,
"withErrorHandling": 0,
"async": 0,
"exported": 0
},
"dataAccess": {
"total": 2,
"rawSql": 0,
"sensitiveFields": 1
},
"imports": {
"total": 0,
"external": 0
}
},
"suggestions": [
"Review sensitive data access for proper authorization",
"Add requestId: req.id to meta object"
],
"stats": {
"patternsChecked": 4,
"compliant": 2,
"violations": 0,
"warnings": 2
}
},
"hints": {
"nextActions": [
"Review violations and apply suggested fixes",
"Use drift_suggest_changes for detailed fix suggestions",
"Use drift_code_examples to see correct implementations"
],
"relatedTools": ["drift_suggest_changes", "drift_code_examples", "drift_pattern_get"]
}
}Quick validation before writing code (lighter weight):
drift_prevalidate({
code: `
async function createUser(data: CreateUserDto) {
return await prisma.user.create({ data });
}
`,
targetFile: "src/services/user.ts",
kind: "function"
})Kind Options:
| Kind | Description |
|---|---|
function |
Single function |
class |
Class definition |
component |
React/Vue component |
test |
Test file |
full-file |
Complete file |
Response:
{
"summary": "Code looks good! Score: 85/100. Matches expected patterns.",
"data": {
"valid": true,
"score": 85,
"violations": [],
"expectedPatterns": ["data-access-prisma", "async-await", "dto-patterns"],
"suggestions": [
"Wrap async operations in try/catch"
]
},
"hints": {
"nextActions": [
"Code is ready to write",
"Use drift_imports to add correct imports"
],
"relatedTools": ["drift_code_examples", "drift_imports", "drift_similar"]
}
}drift check --stagedValidates all staged files before commit.
drift check src/api/users.ts src/services/user.tsdrift check --staged --fail-on warningFails on any warning (not just errors).
drift_validate_change({
file: "src/api/users.ts",
content: code,
strictMode: false // Default
})- Errors block merge
- Warnings are advisory
- Suggestions are informational
drift_validate_change({
file: "src/api/users.ts",
content: code,
strictMode: true
})- Errors block merge
- Warnings block merge
- Used for main/release branches
Does the code follow established patterns?
{
"compliance": [
{
"patternId": "api-rest-controller",
"patternName": "REST Controller Pattern",
"status": "compliant",
"score": 100,
"details": "1/1 semantic checks passed"
}
],
"violations": [
{
"patternId": "error-handling",
"patternName": "Error Handling Pattern",
"severity": "warning",
"message": "Missing try-catch",
"suggestion": "Add try/catch or use Result<T> pattern"
}
]
}Analyzes data access patterns and security concerns:
{
"semanticValidation": {
"functions": { "total": 3, "withErrorHandling": 2, "async": 3, "exported": 2 },
"dataAccess": { "total": 2, "rawSql": 0, "sensitiveFields": 1 },
"imports": { "total": 5, "external": 3 }
}
}Are there security concerns?
{
"violations": [
{
"patternId": "semantic-raw-sql",
"patternName": "Raw SQL Detection",
"severity": "warning",
"message": "Raw SQL query detected accessing \"users\"",
"line": 23,
"suggestion": "Use parameterized queries or ORM methods to prevent SQL injection"
}
]
}# .husky/pre-commit
drift check --staged --fail-on error# GitHub Actions
- name: Validate Changes
run: drift check --ci --format github// 1. Generate code
const generatedCode = await generateCode(prompt);
// 2. Validate before writing
const validation = await drift_validate_change({
file: targetFile,
content: generatedCode
});
// 3. If issues, get suggestions
if (validation.data.status !== 'passed') {
const suggestions = await drift_suggest_changes({
target: targetFile,
issue: 'pattern-violation'
});
// 4. Apply suggestions and re-validate
}
// 5. Write validated codeThe overall score combines pattern compliance and semantic validation:
| Factor | Weight |
|---|---|
| Pattern compliance | 50% |
| Semantic validation (no raw SQL, etc.) | 50% |
Penalties are applied for:
- Raw SQL queries: -20 points
- Sensitive data access without protection: -10 points
- Pattern violations: varies by severity
| Score | Status | Action |
|---|---|---|
| 90-100 | pass |
Good to merge |
| 70-89 | warn |
Review warnings |
| 50-69 | warn |
Address issues |
| <50 | fail |
Significant rework needed |
// Validate before writing to file
const validation = await drift_prevalidate({
code: generatedCode,
targetFile: "src/api/users.ts",
kind: "function"
});
if (!validation.data.valid) {
// Fix issues before writing
}// Feature branches: standard mode
drift_validate_change({ strictMode: false })
// Main branch: strict mode
drift_validate_change({ strictMode: true })Even if validation passes, address warnings:
if (validation.data.warnings.length > 0) {
const suggestions = await drift_suggest_changes({
target: file,
issue: 'pattern-violation'
});
}// After validation passes
const tests = await drift_test_topology({
action: 'affected',
files: [file]
});
// Run affected tests- Quality Gates β CI/CD integration
- Suggest Changes β Get fix suggestions
- Git Hooks β Pre-commit setup
- 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