@codebakers/cli 1.6.0 → 2.0.0

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/src/mcp/server.ts CHANGED
@@ -9,6 +9,8 @@ import {
9
9
  McpError,
10
10
  } from '@modelcontextprotocol/sdk/types.js';
11
11
  import { getApiKey, getApiUrl, getExperienceLevel, setExperienceLevel, type ExperienceLevel } from '../config.js';
12
+ import { audit as runAudit } from '../commands/audit.js';
13
+ import { heal as runHeal } from '../commands/heal.js';
12
14
  import * as fs from 'fs';
13
15
  import * as path from 'path';
14
16
  import { execSync } from 'child_process';
@@ -446,6 +448,38 @@ class CodeBakersServer {
446
448
  properties: {},
447
449
  },
448
450
  },
451
+ {
452
+ name: 'run_audit',
453
+ description:
454
+ 'Run automated code quality and security checks on the current project. Checks TypeScript, ESLint, secrets in code, npm vulnerabilities, console.log usage, API validation, error boundaries, and more. Returns a score and list of issues to fix.',
455
+ inputSchema: {
456
+ type: 'object' as const,
457
+ properties: {},
458
+ },
459
+ },
460
+ {
461
+ name: 'heal',
462
+ description:
463
+ 'Run the self-healing system to auto-detect and fix common issues. Scans for TypeScript errors, missing dependencies, environment issues, security vulnerabilities, and database problems. Can automatically apply safe fixes with high confidence.',
464
+ inputSchema: {
465
+ type: 'object' as const,
466
+ properties: {
467
+ auto: {
468
+ type: 'boolean',
469
+ description: 'Automatically apply safe fixes without prompting (default: false)',
470
+ },
471
+ dryRun: {
472
+ type: 'boolean',
473
+ description: 'Show what would be fixed without applying changes (default: false)',
474
+ },
475
+ severity: {
476
+ type: 'string',
477
+ enum: ['critical', 'high', 'medium', 'low'],
478
+ description: 'Filter issues by severity level',
479
+ },
480
+ },
481
+ },
482
+ },
449
483
  ],
450
484
  }));
451
485
 
@@ -494,6 +528,12 @@ class CodeBakersServer {
494
528
  case 'get_status':
495
529
  return this.handleGetStatus();
496
530
 
531
+ case 'run_audit':
532
+ return this.handleRunAudit();
533
+
534
+ case 'heal':
535
+ return this.handleHeal(args as { auto?: boolean; dryRun?: boolean; severity?: string });
536
+
497
537
  default:
498
538
  throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${name}`);
499
539
  }
@@ -1276,6 +1316,126 @@ phase: development
1276
1316
  };
1277
1317
  }
1278
1318
 
1319
+ private async handleRunAudit() {
1320
+ try {
1321
+ const result = await runAudit();
1322
+
1323
+ const passedChecks = result.checks.filter(c => c.passed);
1324
+ const failedChecks = result.checks.filter(c => !c.passed);
1325
+
1326
+ let response = `# 🔍 Code Audit Results\n\n`;
1327
+ response += `**Score:** ${result.score}% (${passedChecks.length}/${result.checks.length} checks passed)\n\n`;
1328
+
1329
+ if (result.passed) {
1330
+ response += `## ✅ Status: PASSED\n\nYour project is in good shape!\n\n`;
1331
+ } else {
1332
+ response += `## ⚠️ Status: NEEDS ATTENTION\n\nSome issues need to be fixed before deployment.\n\n`;
1333
+ }
1334
+
1335
+ // Show passed checks
1336
+ if (passedChecks.length > 0) {
1337
+ response += `### Passed Checks\n`;
1338
+ for (const check of passedChecks) {
1339
+ response += `- ✅ ${check.message}\n`;
1340
+ }
1341
+ response += '\n';
1342
+ }
1343
+
1344
+ // Show failed checks
1345
+ if (failedChecks.length > 0) {
1346
+ response += `### Issues Found\n`;
1347
+ for (const check of failedChecks) {
1348
+ const icon = check.severity === 'error' ? '❌' : '⚠️';
1349
+ response += `- ${icon} **${check.message}**\n`;
1350
+ if (check.details && check.details.length > 0) {
1351
+ for (const detail of check.details.slice(0, 3)) {
1352
+ response += ` - ${detail}\n`;
1353
+ }
1354
+ }
1355
+ }
1356
+ response += '\n';
1357
+ }
1358
+
1359
+ response += `---\n\n*Tip: Run \`/audit\` in Claude for a full 100-point inspection.*`;
1360
+
1361
+ return {
1362
+ content: [{
1363
+ type: 'text' as const,
1364
+ text: response,
1365
+ }],
1366
+ };
1367
+ } catch (error) {
1368
+ const message = error instanceof Error ? error.message : 'Unknown error';
1369
+ return {
1370
+ content: [{
1371
+ type: 'text' as const,
1372
+ text: `# ❌ Audit Failed\n\nError: ${message}`,
1373
+ }],
1374
+ };
1375
+ }
1376
+ }
1377
+
1378
+ private async handleHeal(args: { auto?: boolean; dryRun?: boolean; severity?: string }) {
1379
+ try {
1380
+ const result = await runHeal({
1381
+ auto: args.auto || false,
1382
+ dryRun: args.dryRun || false,
1383
+ severity: args.severity
1384
+ });
1385
+
1386
+ let response = `# 🏥 Self-Healing Results\n\n`;
1387
+
1388
+ if (result.errors.length === 0) {
1389
+ response += `## ✅ No Issues Found\n\nYour project is healthy!\n`;
1390
+ } else {
1391
+ response += `## Found ${result.errors.length} Issue(s)\n\n`;
1392
+ response += `**Fixed:** ${result.fixed} | **Remaining:** ${result.remaining}\n\n`;
1393
+
1394
+ // Group by category
1395
+ const byCategory = new Map<string, typeof result.errors>();
1396
+ for (const error of result.errors) {
1397
+ const cat = error.category;
1398
+ if (!byCategory.has(cat)) byCategory.set(cat, []);
1399
+ byCategory.get(cat)!.push(error);
1400
+ }
1401
+
1402
+ for (const [category, errors] of byCategory) {
1403
+ response += `### ${category.toUpperCase()}\n`;
1404
+ for (const error of errors) {
1405
+ const icon = error.fixed ? '✅' : (error.autoFixable ? '🔧' : '⚠️');
1406
+ response += `- ${icon} ${error.message}\n`;
1407
+ if (error.file) {
1408
+ response += ` - File: ${error.file}${error.line ? `:${error.line}` : ''}\n`;
1409
+ }
1410
+ if (error.suggestedFixes.length > 0 && !error.fixed) {
1411
+ response += ` - Fix: ${error.suggestedFixes[0].description}\n`;
1412
+ }
1413
+ }
1414
+ response += '\n';
1415
+ }
1416
+ }
1417
+
1418
+ if (!args.auto && result.errors.some(e => e.autoFixable && !e.fixed)) {
1419
+ response += `---\n\n*Run with \`auto: true\` to automatically apply safe fixes.*`;
1420
+ }
1421
+
1422
+ return {
1423
+ content: [{
1424
+ type: 'text' as const,
1425
+ text: response,
1426
+ }],
1427
+ };
1428
+ } catch (error) {
1429
+ const message = error instanceof Error ? error.message : 'Unknown error';
1430
+ return {
1431
+ content: [{
1432
+ type: 'text' as const,
1433
+ text: `# ❌ Healing Failed\n\nError: ${message}`,
1434
+ }],
1435
+ };
1436
+ }
1437
+ }
1438
+
1279
1439
  private handleGetStatus() {
1280
1440
  const level = getExperienceLevel();
1281
1441
  const context = this.gatherProjectContext();