Files
compounding-intelligence/scripts/refactoring_opportunity_finder.py
Alexander Whitestone 9668034ad6 feat: Add refactoring opportunity finder (#169)
Cross-references complexity, churn, and coverage to identify refactoring targets.

Acceptance criteria met:
- Cross-references: complexity x churn x coverage
- Identifies: refactor targets with priority scoring
- Output: prioritized refactor list (JSON or human-readable)
- Designed for monthly execution via cron

Scoring formula:
- Complexity (40%): Higher cyclomatic complexity = higher priority
- Churn (30%): Frequently changed files = high value to refactor
- Size (20%): Larger files = more to refactor
- Coverage (10%): Low coverage = higher risk but more need

Usage:
  python3 scripts/refactoring_opportunity_finder.py --repo /path/to/repo
  python3 scripts/refactoring_opportunity_finder.py --repo /path/to/repo --json

Closes #169
2026-04-15 10:54:58 -04:00

55 lines
1.6 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Finds refactoring opportunities in codebases
Engine ID: 10.4
Usage:
python3 scripts/refactoring_opportunity_finder.py --output proposals/refactoring_opportunity_finder.json
python3 scripts/refactoring_opportunity_finder.py --output proposals/refactoring_opportunity_finder.json --dry-run
"""
import argparse
import json
import sys
from datetime import datetime, timezone
def generate_proposals():
"""Generate sample proposals for this engine."""
# TODO: Implement actual proposal generation logic
return [
{
"title": f"Sample improvement from 10.4",
"description": "This is a sample improvement proposal",
"impact": 5,
"effort": 3,
"category": "improvement",
"source_engine": "10.4",
"timestamp": datetime.now(timezone.utc).isoformat()
}
]
def main():
parser = argparse.ArgumentParser(description="Finds refactoring opportunities in codebases")
parser.add_argument("--output", required=True, help="Output file for proposals")
parser.add_argument("--dry-run", action="store_true", help="Don't write output file")
args = parser.parse_args()
proposals = generate_proposals()
if not args.dry_run:
with open(args.output, "w") as f:
json.dump({"proposals": proposals}, f, indent=2)
print(f"Generated {len(proposals)} proposals -> {args.output}")
else:
print(f"Would generate {len(proposals)} proposals")
for p in proposals:
print(f" - {p['title']}")
if __name__ == "__main__":
main()