Skip to content

Commit b97af8c

Browse files
feat: halstead metrics and maintainability index for code health scoring
Add formal code health metrics per function: Halstead volume, difficulty, effort, bugs estimate, LOC/SLOC, and the industry-standard Maintainability Index (MI) normalized to 0-100 (Microsoft convention). MI below 20 flags functions needing refactoring attention. - DB migration v9: 14 new columns on function_complexity table - HALSTEAD_RULES registry for JS/TS/TSX operator/operand classification - computeHalsteadMetrics(), computeLOCMetrics(), computeMaintainabilityIndex() - complexity command: MI column in default view, --health flag for full Halstead view, --sort mi|volume|effort|bugs|loc options - stats/context/explain commands surface MI per function - MCP tool schema updated with new sort values and health property - Config: maintainabilityIndex threshold { warn: 20, fail: null } - 29 new tests (18 unit + 11 integration) Impact: 16 functions changed, 30 affected Impact: 16 functions changed, 30 affected
1 parent 5a7d039 commit b97af8c

9 files changed

Lines changed: 786 additions & 38 deletions

File tree

src/cli.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,11 +714,16 @@ program
714714

715715
program
716716
.command('complexity [target]')
717-
.description('Show per-function complexity metrics (cognitive, cyclomatic, nesting depth)')
717+
.description('Show per-function complexity metrics (cognitive, cyclomatic, nesting depth, MI)')
718718
.option('-d, --db <path>', 'Path to graph.db')
719719
.option('-n, --limit <number>', 'Max results', '20')
720-
.option('--sort <metric>', 'Sort by: cognitive | cyclomatic | nesting', 'cognitive')
720+
.option(
721+
'--sort <metric>',
722+
'Sort by: cognitive | cyclomatic | nesting | mi | volume | effort | bugs | loc',
723+
'cognitive',
724+
)
721725
.option('--above-threshold', 'Only functions exceeding warn thresholds')
726+
.option('--health', 'Show health metrics (Halstead, MI) columns')
722727
.option('-f, --file <path>', 'Scope to file (partial match)')
723728
.option('-k, --kind <kind>', 'Filter by symbol kind')
724729
.option('-T, --no-tests', 'Exclude test/spec files from results')
@@ -735,6 +740,7 @@ program
735740
limit: parseInt(opts.limit, 10),
736741
sort: opts.sort,
737742
aboveThreshold: opts.aboveThreshold,
743+
health: opts.health,
738744
file: opts.file,
739745
kind: opts.kind,
740746
noTests: resolveNoTests(opts),

0 commit comments

Comments
 (0)