diff --git a/bin/coderrr.js b/bin/coderrr.js index e791e7b..49f5717 100644 --- a/bin/coderrr.js +++ b/bin/coderrr.js @@ -15,6 +15,14 @@ const Agent = require('../src/agent'); const configManager = require('../src/configManager'); const { getProviderChoices, getModelChoices, getProvider, validateApiKey } = require('../src/providers'); const { tryExtractJSON } = require('../src/utils'); +const { runDiagnostics } = require('../src/doctorUI'); +program + .command('doctor') + .description('Check your system for Coderrr compatibility') + .action(async () => { + // This calls our new UI module to run the health checks + await runDiagnostics(process.env.CODERRR_BACKEND); + }); const { displayRecipeList } = require('../src/recipeUI'); const recipeManager = require('../src/recipeManager'); const { displayInsights } = require('../src/insightsUI'); diff --git a/docs/doctor.md b/docs/doctor.md new file mode 100644 index 0000000..35afe05 --- /dev/null +++ b/docs/doctor.md @@ -0,0 +1,8 @@ +# Coderrr Doctor + +A built-in diagnostic tool to ensure your environment is ready for AI coding. + +## Usage +Run the following to check your setup: +```bash +coderrr doctor \ No newline at end of file diff --git a/src/doctor.js b/src/doctor.js new file mode 100644 index 0000000..297884e --- /dev/null +++ b/src/doctor.js @@ -0,0 +1,36 @@ +const fs = require('fs'); +const path = require('path'); +const { execSync } = require('child_process'); + +class CoderrrDoctor { + checkEnv() { + return fs.existsSync(path.join(process.cwd(), '.env')); + } + + checkPython() { + try { + const version = execSync('python --version').toString().trim(); + return { status: true, version }; + } catch { + return { status: false, version: 'Not found' }; + } + } + + checkNode() { + return { status: true, version: process.version }; + } + + async checkBackend(url) { + try { + const controller = new AbortController(); + const timeoutId = setTimeout(() => controller.abort(), 3000); + const response = await fetch(url, { signal: controller.signal }); + clearTimeout(timeoutId); + return response.ok; + } catch { + return false; + } + } +} + +module.exports = new CoderrrDoctor(); \ No newline at end of file diff --git a/src/doctorUI.js b/src/doctorUI.js new file mode 100644 index 0000000..7d4b63a --- /dev/null +++ b/src/doctorUI.js @@ -0,0 +1,26 @@ +const chalk = require('chalk'); +const doctor = require('./doctor'); + +async function runDiagnostics(backendUrl) { + console.log('\n' + chalk.blue.bold('🩺 CODERRR DOCTOR - SYSTEM DIAGNOSTICS')); + console.log(chalk.gray('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━')); + + const python = doctor.checkPython(); + const node = doctor.checkNode(); + const hasEnv = doctor.checkEnv(); + + console.log(`${python.status ? chalk.green('✔') : chalk.red('✘')} Python: ${python.version}`); + console.log(`${node.status ? chalk.green('✔') : chalk.red('✘')} Node.js: ${node.version}`); + console.log(`${hasEnv ? chalk.green('✔') : chalk.red('✘')} Local .env file detected`); + + console.log(chalk.yellow('\nChecking Backend Connectivity...')); + const backendStatus = await doctor.checkBackend(backendUrl || 'https://coderrr-backend.vercel.app'); + console.log(`${backendStatus ? chalk.green('✔') : chalk.red('✘')} Backend: ${backendStatus ? 'Connected' : 'Unreachable'}`); + + if (!backendStatus) { + console.log(chalk.red('\n[!] Advice: Check your internet or custom CODERRR_BACKEND variable.')); + } + console.log(chalk.gray('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n')); +} + +module.exports = { runDiagnostics }; \ No newline at end of file diff --git a/src/utils/doctorHelpers.js b/src/utils/doctorHelpers.js new file mode 100644 index 0000000..595c75f --- /dev/null +++ b/src/utils/doctorHelpers.js @@ -0,0 +1,9 @@ +/** + * Helps format diagnostic logs for potential export + */ +const generateReport = (results) => { + return `Coderrr Diagnostic Report - ${new Date().toISOString()}\n` + + `Status: ${results.allPassed ? 'HEALTHY' : 'ISSUES DETECTED'}\n`; +}; + +module.exports = { generateReport }; \ No newline at end of file diff --git a/test/doctor.test.js b/test/doctor.test.js new file mode 100644 index 0000000..0ac3a12 --- /dev/null +++ b/test/doctor.test.js @@ -0,0 +1,9 @@ +const doctor = require('../src/doctor'); + +describe('Doctor Module', () => { + test('should detect node version', () => { + const node = doctor.checkNode(); + expect(node.status).toBe(true); + expect(node.version).toContain('v'); + }); +}); \ No newline at end of file