@codebakers/cli 3.9.40 → 3.9.42
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/commands/install-precommit.js +1106 -926
- package/dist/mcp/server.js +154 -0
- package/package.json +1 -1
- package/src/commands/install-precommit.ts +1205 -1024
- package/src/mcp/server.ts +170 -0
package/dist/mcp/server.js
CHANGED
|
@@ -62,6 +62,28 @@ class CodeBakersServer {
|
|
|
62
62
|
lastUpdateCheck = 0;
|
|
63
63
|
updateCheckInterval = 60 * 60 * 1000; // Check every hour
|
|
64
64
|
currentSessionToken = null; // v6.19: Server-side enforcement session
|
|
65
|
+
// Check for pre-commit violations
|
|
66
|
+
checkForViolations() {
|
|
67
|
+
const cwd = process.cwd();
|
|
68
|
+
const violationsPath = path.join(cwd, '.codebakers', 'violations.json');
|
|
69
|
+
if (!fs.existsSync(violationsPath)) {
|
|
70
|
+
return { hasViolations: false, violations: null, message: null };
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
const data = JSON.parse(fs.readFileSync(violationsPath, 'utf-8'));
|
|
74
|
+
if (data.violations && data.violations.length > 0) {
|
|
75
|
+
return {
|
|
76
|
+
hasViolations: true,
|
|
77
|
+
violations: data.violations,
|
|
78
|
+
message: `⚠️ ${data.count} pre-commit violation(s) found! Call heal_violations() to auto-fix.`
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
// Ignore parse errors
|
|
84
|
+
}
|
|
85
|
+
return { hasViolations: false, violations: null, message: null };
|
|
86
|
+
}
|
|
65
87
|
constructor() {
|
|
66
88
|
this.apiKey = (0, config_js_1.getApiKey)();
|
|
67
89
|
this.apiUrl = (0, config_js_1.getApiUrl)();
|
|
@@ -1527,6 +1549,20 @@ class CodeBakersServer {
|
|
|
1527
1549
|
},
|
|
1528
1550
|
},
|
|
1529
1551
|
},
|
|
1552
|
+
// Pre-commit violation healing tool
|
|
1553
|
+
{
|
|
1554
|
+
name: 'heal_violations',
|
|
1555
|
+
description: 'Auto-fix pre-commit hook violations. Call this when you see a violation warning in tool responses. Reads .codebakers/violations.json and provides fixes using CodeBakers patterns. After fixing, clears the violations file.',
|
|
1556
|
+
inputSchema: {
|
|
1557
|
+
type: 'object',
|
|
1558
|
+
properties: {
|
|
1559
|
+
autoFix: {
|
|
1560
|
+
type: 'boolean',
|
|
1561
|
+
description: 'Automatically apply fixes (default: true). Set to false to just see the issues.',
|
|
1562
|
+
},
|
|
1563
|
+
},
|
|
1564
|
+
},
|
|
1565
|
+
},
|
|
1530
1566
|
// Engineering workflow tools
|
|
1531
1567
|
...engineering_tools_js_1.ENGINEERING_TOOLS,
|
|
1532
1568
|
],
|
|
@@ -1665,6 +1701,8 @@ class CodeBakersServer {
|
|
|
1665
1701
|
return this.handleResumeSession(args);
|
|
1666
1702
|
case 'setup_services':
|
|
1667
1703
|
return this.handleSetupServices(args);
|
|
1704
|
+
case 'heal_violations':
|
|
1705
|
+
return this.handleHealViolations(args);
|
|
1668
1706
|
// Engineering workflow tools
|
|
1669
1707
|
case 'engineering_start':
|
|
1670
1708
|
case 'engineering_scope':
|
|
@@ -3914,6 +3952,106 @@ If you want AI features and prefer Claude over GPT (or want both as fallback).`,
|
|
|
3914
3952
|
}],
|
|
3915
3953
|
};
|
|
3916
3954
|
}
|
|
3955
|
+
handleHealViolations(args) {
|
|
3956
|
+
const { autoFix = true } = args;
|
|
3957
|
+
const cwd = process.cwd();
|
|
3958
|
+
const violationsPath = path.join(cwd, '.codebakers', 'violations.json');
|
|
3959
|
+
// Check if violations file exists
|
|
3960
|
+
if (!fs.existsSync(violationsPath)) {
|
|
3961
|
+
return {
|
|
3962
|
+
content: [{
|
|
3963
|
+
type: 'text',
|
|
3964
|
+
text: `✅ **No violations found!**\n\nThe \`.codebakers/violations.json\` file doesn't exist, which means:\n- No pre-commit violations have been detected\n- Or they were already fixed\n\nYou're good to commit!`,
|
|
3965
|
+
}],
|
|
3966
|
+
};
|
|
3967
|
+
}
|
|
3968
|
+
// Read violations
|
|
3969
|
+
let data;
|
|
3970
|
+
try {
|
|
3971
|
+
data = JSON.parse(fs.readFileSync(violationsPath, 'utf-8'));
|
|
3972
|
+
}
|
|
3973
|
+
catch {
|
|
3974
|
+
return {
|
|
3975
|
+
content: [{
|
|
3976
|
+
type: 'text',
|
|
3977
|
+
text: `⚠️ **Could not parse violations file**\n\nThe violations.json file exists but couldn't be read. Try running \`git commit\` again to regenerate it.`,
|
|
3978
|
+
}],
|
|
3979
|
+
};
|
|
3980
|
+
}
|
|
3981
|
+
if (!data.violations || data.violations.length === 0) {
|
|
3982
|
+
// Clean up empty violations file
|
|
3983
|
+
fs.unlinkSync(violationsPath);
|
|
3984
|
+
return {
|
|
3985
|
+
content: [{
|
|
3986
|
+
type: 'text',
|
|
3987
|
+
text: `✅ **No violations to fix!**\n\nThe violations file was empty. Cleaned it up for you.`,
|
|
3988
|
+
}],
|
|
3989
|
+
};
|
|
3990
|
+
}
|
|
3991
|
+
// Group violations by file
|
|
3992
|
+
const byFile = {};
|
|
3993
|
+
for (const v of data.violations) {
|
|
3994
|
+
if (!byFile[v.file])
|
|
3995
|
+
byFile[v.file] = [];
|
|
3996
|
+
byFile[v.file].push(v);
|
|
3997
|
+
}
|
|
3998
|
+
// Build response with fix instructions
|
|
3999
|
+
let response = `# 🔧 Pre-Commit Violations Found\n\n`;
|
|
4000
|
+
response += `**${data.count} violation(s)** detected at ${data.timestamp}\n\n`;
|
|
4001
|
+
// Category fixes mapping
|
|
4002
|
+
const categoryFixes = {
|
|
4003
|
+
security: 'Use parameterized queries, escape user input, avoid eval()',
|
|
4004
|
+
errors: 'Add try/catch blocks, handle Promise rejections, use Result types',
|
|
4005
|
+
validation: 'Add Zod schemas at API boundaries, validate inputs before use',
|
|
4006
|
+
quality: 'Remove console.log, add explicit types, avoid any',
|
|
4007
|
+
typescript: 'Add proper type annotations, avoid type assertions',
|
|
4008
|
+
react: 'Add key props, wrap handlers in useCallback, handle loading states',
|
|
4009
|
+
accessibility: 'Add alt text, aria-labels, ensure keyboard navigation',
|
|
4010
|
+
performance: 'Use proper React hooks dependencies, memoize expensive operations',
|
|
4011
|
+
api: 'Use NextResponse for API routes, add rate limiting',
|
|
4012
|
+
imports: 'Fix import order, remove unused imports',
|
|
4013
|
+
};
|
|
4014
|
+
for (const [file, violations] of Object.entries(byFile)) {
|
|
4015
|
+
response += `## 📄 ${file}\n\n`;
|
|
4016
|
+
for (const v of violations) {
|
|
4017
|
+
response += `### ❌ ${v.check}\n`;
|
|
4018
|
+
response += `- **Category:** ${v.category}\n`;
|
|
4019
|
+
response += `- **Issue:** ${v.message}\n`;
|
|
4020
|
+
if (v.line)
|
|
4021
|
+
response += `- **Line:** ${v.line}\n`;
|
|
4022
|
+
if (v.code)
|
|
4023
|
+
response += `- **Code:** \`${v.code.substring(0, 100)}${v.code.length > 100 ? '...' : ''}\`\n`;
|
|
4024
|
+
// Add fix suggestion
|
|
4025
|
+
const fix = categoryFixes[v.category] || 'Review the code and apply best practices';
|
|
4026
|
+
response += `- **Fix:** ${fix}\n\n`;
|
|
4027
|
+
}
|
|
4028
|
+
}
|
|
4029
|
+
if (autoFix) {
|
|
4030
|
+
response += `---\n\n`;
|
|
4031
|
+
response += `## 🛠️ Auto-Fix Instructions\n\n`;
|
|
4032
|
+
response += `I'll now fix these violations. For each file:\n\n`;
|
|
4033
|
+
for (const [file, violations] of Object.entries(byFile)) {
|
|
4034
|
+
response += `**${file}:**\n`;
|
|
4035
|
+
for (const v of violations) {
|
|
4036
|
+
response += `- Fix: ${v.check} (${v.category})\n`;
|
|
4037
|
+
}
|
|
4038
|
+
response += `\n`;
|
|
4039
|
+
}
|
|
4040
|
+
response += `After fixing, run \`git add .\` and \`git commit\` again.\n\n`;
|
|
4041
|
+
response += `---\n\n`;
|
|
4042
|
+
response += `**⚠️ IMPORTANT:** Read each file and apply the fixes according to CodeBakers patterns. Load the relevant pattern module for each category (e.g., \`00-core.md\` for types, \`02-auth.md\` for security, \`03-api.md\` for API routes).\n`;
|
|
4043
|
+
}
|
|
4044
|
+
else {
|
|
4045
|
+
response += `---\n\n`;
|
|
4046
|
+
response += `Run \`heal_violations({ autoFix: true })\` to get fix instructions, or fix manually and commit again.\n`;
|
|
4047
|
+
}
|
|
4048
|
+
return {
|
|
4049
|
+
content: [{
|
|
4050
|
+
type: 'text',
|
|
4051
|
+
text: response,
|
|
4052
|
+
}],
|
|
4053
|
+
};
|
|
4054
|
+
}
|
|
3917
4055
|
handleRunTests(args) {
|
|
3918
4056
|
const { filter, watch = false } = args;
|
|
3919
4057
|
const cwd = process.cwd();
|
|
@@ -4549,6 +4687,14 @@ If you want AI features and prefer Claude over GPT (or want both as fallback).`,
|
|
|
4549
4687
|
responseText += `## ❌ Feature is NOT COMPLETE\n\n`;
|
|
4550
4688
|
responseText += `**${result.nextSteps || 'Fix the issues above and try again.'}**\n`;
|
|
4551
4689
|
}
|
|
4690
|
+
// Check for pre-commit violations
|
|
4691
|
+
const violations = this.checkForViolations();
|
|
4692
|
+
if (violations.hasViolations) {
|
|
4693
|
+
responseText += `\n---\n\n`;
|
|
4694
|
+
responseText += `## 🚨 PRE-COMMIT VIOLATIONS DETECTED\n\n`;
|
|
4695
|
+
responseText += violations.message + `\n\n`;
|
|
4696
|
+
responseText += `**IMPORTANT:** These violations will block your commit. Call \`heal_violations()\` to fix them.\n`;
|
|
4697
|
+
}
|
|
4552
4698
|
return {
|
|
4553
4699
|
content: [{
|
|
4554
4700
|
type: 'text',
|
|
@@ -4890,6 +5036,14 @@ If you want AI features and prefer Claude over GPT (or want both as fallback).`,
|
|
|
4890
5036
|
responseText += `4. TypeScript must compile - validation fails on errors\n`;
|
|
4891
5037
|
responseText += `5. Pre-commit hook blocks commits without passed validation\n\n`;
|
|
4892
5038
|
responseText += `**Server is tracking this session. Compliance is enforced.**`;
|
|
5039
|
+
// Check for pre-commit violations
|
|
5040
|
+
const violations = this.checkForViolations();
|
|
5041
|
+
if (violations.hasViolations) {
|
|
5042
|
+
responseText += `\n\n---\n\n`;
|
|
5043
|
+
responseText += `## 🚨 PRE-COMMIT VIOLATIONS DETECTED\n\n`;
|
|
5044
|
+
responseText += violations.message + `\n\n`;
|
|
5045
|
+
responseText += `**Fix these violations BEFORE writing new code.** Call \`heal_violations()\` to see details and fixes.\n`;
|
|
5046
|
+
}
|
|
4893
5047
|
return {
|
|
4894
5048
|
content: [{
|
|
4895
5049
|
type: 'text',
|