UNPKG

agentsqripts

Version:

Comprehensive static code analysis toolkit for identifying technical debt, security vulnerabilities, performance issues, and code quality problems

110 lines (92 loc) 4.14 kB
#!/usr/bin/env node /** * @file Command-line interface for code complexity analysis and technical debt assessment * @description Single responsibility: Provide interactive CLI for identifying complexity issues and maintainability problems * * This CLI tool serves as the complexity analysis interface for the AgentSqripts platform, * detecting cyclomatic complexity, maintainability index issues, and technical debt patterns * that impact code quality and development velocity. It implements severity-based filtering, * detailed complexity metrics, and actionable recommendations to support code quality improvement. * * Design rationale: * - Complexity-focused analysis enables data-driven refactoring decisions * - Multiple complexity metrics provide comprehensive code quality assessment * - Maintainability index calculation guides architectural improvements * - Technical debt detection identifies systematic quality issues * - Severity filtering enables incremental complexity reduction workflows */ const path = require('path'); const fs = require('fs'); const { analyzeCodeComplexity } = require('../lib/code-complexity/analyzeCodeComplexity'); const { analyzeTechnicalDebt } = require('../lib/code-complexity/technicalDebtAnalyzer'); const qerrors = require('qerrors'); // Import focused modules const { parseComplexityArgs, showComplexityUsage } = require('./lib/complexityCommandParser'); const { outputJson, outputDetailed, outputSummary } = require('./lib/complexityOutputFormatter'); const { analyzeProject } = require('./lib/complexityProjectAnalyzer'); const { checkForIssues } = require('./lib/complexityThresholdChecker'); async function main() { const { getProcessArgs } = require('../lib/utils/processHelpers'); const { shouldShowHelp } = require('../lib/utils/cliHelpers'); const args = getProcessArgs(); if (shouldShowHelp(args)) { showComplexityUsage(); process.exit(0); } try { // Parse command line arguments using dedicated parser const { options, targetPath: rawTargetPath } = parseComplexityArgs(args); // Resolve target path const { resolvePath } = require('../lib/utils/pathUtils'); const targetPath = resolvePath(rawTargetPath); // Auto-detect mode if not specified if (options.mode === 'auto') { const stats = await fs.promises.stat(targetPath); options.mode = stats.isFile() ? 'file' : 'project'; } const { logAnalysisStart, logMode } = require('../lib/utils/consoleHelpers'); logAnalysisStart('Complexity', targetPath); logMode(options.mode); console.log(`🎯 Threshold: ${options.threshold}`); console.log(`💸 Include Debt Analysis: ${options.includeDebt ? 'Yes' : 'No'}\n`); let results = {}; if (options.mode === 'file') { // Single file analysis results.fileAnalysis = await analyzeCodeComplexity(targetPath, options); if (options.includeDebt) { console.log('⚠️ Note: Technical debt analysis requires project mode. Skipping debt analysis.\n'); } } else { // Project analysis using dedicated analyzer results.projectAnalysis = await analyzeProject(targetPath, options); if (options.includeDebt) { // Technical debt analysis requires file content - delegate to project analyzer console.log('⚠️ Note: Technical debt analysis is included in project complexity metrics.\n'); } } // Output results using dedicated formatter switch (options.outputFormat) { case 'json': outputJson(results, options); break; case 'detailed': outputDetailed(results, options); break; case 'summary': default: outputSummary(results, options); break; } // Check if issues exceed threshold using dedicated checker const hasIssues = checkForIssues(results, options); process.exit(hasIssues ? 1 : 0); } catch (error) { qerrors.default(error, 'Failed to analyze code complexity'); process.exit(1); } } // Run the CLI if (require.main === module) { main(); } module.exports = { main };