code-refactoring-advisor
Enterprise code refactoring advisor that detects code smells, anti-patterns, and complexity issues with specific refactoring recommendations, test generation, and maintainability metrics
- License 许可
- AGPL-3.0
- 最近更新
- 2026-11-15
- Stars
- ★ 81
- Forks
- 17
01 前言 Front Matter
- name
- code-refactoring-advisor
- tags
- [ "refactoring", "code-quality", "code-smells", "complexity-analysis", "python", "solidity", "enterprise", "static-analysis", "testing" ]
- author
- Sambit Sargam
- scripts
- { "enabled": true, "definitions": [ { "file": "pattern_detector.py", "name": "pattern_detector", "type": "python", "timeout": 30, "confidence": "92%", "description": "Detect code smells and anti-patterns", "requires_auth": false }, { "file": "refactoring_suggester.py", "name": "refactoring_suggester", "type": "python", "timeout": 30, "confidence": "88%", "description": "Generate specific refactoring recommendations", "requires_auth": false }, { "file": "complexity_analyzer.py", "name": "complexity_analyzer", "type": "python", "timeout": 30, "confidence": "90%", "description": "Calculate cyclomatic complexity and maintainability metrics", "requires_auth": false }, { "file": "test_generator.py", "name": "test_generator", "type": "python", "timeout": 30, "confidence": "85%", "description": "Generate unit and integration test cases", "requires_auth": false } ], "working_directory": "./scripts" }
- version
- 1.0.0
- triggers
- [ { "type": "keyword", "keywords": [ "refactor", "code quality", "code smell", "complexity", "maintainability", "pattern", "technical debt", "clean code", "best practices", "code review" ], "priority": 95 }, { "type": "pattern", "patterns": [ "(?i)(refactor|improve|optimize) .*code", "(?i)(analyze|detect|find) .*code .*smell", "(?i)(reduce|lower) .*(complexity|cyclomatic)", "(?i)(what|generate) .*test.*case", "(?i)(code quality|maintainability) .*score" ], "priority": 90 }, { "type": "intent", "priority": 98, "intent_category": "code_refactoring" } ]
- composable
- true
- parameters
- [ { "name": "code_input", "type": "string", "required": true, "description": "Source code to analyze (Python or Solidity)" }, { "name": "language", "type": "string", "default": "python", "required": false, "description": "Programming language (python, solidity, typescript)" }, { "name": "analysis_type", "type": "string", "default": "comprehensive", "required": false, "description": "Type of analysis (smells, complexity, refactoring, testing)" }, { "name": "severity_threshold", "type": "string", "default": "MEDIUM", "required": false, "description": "Minimum severity to report (CRITICAL, HIGH, MEDIUM, LOW)" }, { "name": "include_test_generation", "type": "boolean", "default": true, "required": false, "description": "Generate test cases for refactored code" }, { "name": "focus_areas", "type": "array", "required": false, "description": "Specific areas to focus on (patterns, complexity, security, maintainability)" } ]
- description
- Enterprise code refactoring advisor that detects code smells, anti-patterns, and complexity issues with specific refactoring recommendations, test generation, and maintainability metrics
- cache_enabled
- true
- persist_state
- false
- prerequisites
- { "skills": [], "env_vars": [] }
02 资源文件 8
- 参考文档README.md13.2 KB
- 参考文档requirements.txt38 B
- 脚本scripts/complexity_analyzer.py7.6 KB
- 脚本scripts/pattern_detector.py10.3 KB
- 脚本scripts/refactoring_suggester.py8.5 KB
- 脚本scripts/test_generator.py8.5 KB
- 参考文档SOURCE.md378 B
- 参考文档TRUST.auto.yaml2.1 KB
03 SKILL.md 正文
capabilities:
- python code smell detection (god functions, long parameters, deep nesting, etc.)
- solidity smart contract anti-patterns (reentrancy, unchecked arithmetic, etc.)
- cyclomatic complexity calculation per function
- maintainability index scoring (0-100)
- specific refactoring recommendations with code examples
- automatic unit test generation
- security pattern detection
- test strategy planning
- code quality metrics and reporting
security_considerations:
- Read-only code analysis (no code execution)
- No external file access
- Pattern-based detection only
- Safe AST parsing with error handling
- No sensitive data exposure
- No code modification without user confirmation
- Sandbox analysis environment
Overview
The Code Refactoring Advisor is an enterprise-grade code quality tool that analyzes Python and Solidity code to detect smells, anti-patterns, and complexity issues with actionable refactoring recommendations. It combines pattern detection, complexity metrics, and test generation to improve code quality systematically.
Key capabilities:
- Code Smell Detection: 12+ patterns (god functions, long parameters, deep nesting, etc.)
- Complexity Analysis: Cyclomatic complexity and maintainability index calculation
- Refactoring Recommendations: Specific solutions with code examples and effort estimates
- Test Generation: Automatic unit and integration test case generation
- Security Patterns: Solidity vulnerability detection (reentrancy, arithmetic, etc.)
Module Details
Module 1: Pattern Detector (92% Confidence)
Detects code smells and anti-patterns in Python and Solidity:
- Python: God functions, long parameter lists, deep nesting, bare excepts, global variables, magic numbers
- Solidity: Reentrancy vulnerabilities, unbounded loops, unchecked arithmetic, unclear visibility
- Outputs: Severity levels (CRITICAL/HIGH/MEDIUM/LOW), confidence scores, line numbers
Module 2: Refactoring Suggester (88% Confidence)
Generates specific refactoring solutions:
- Pattern-based recommendations (extract method, parameter object, strategy pattern, etc.)
- Effort estimates (TRIVIAL to LARGE)
- Benefits per refactoring (testability, maintainability, security, etc.)
- Code examples showing before/after
Module 3: Complexity Analyzer (90% Confidence)
Calculates code metrics:
- Cyclomatic complexity per function
- Maintainability Index (0-100)
- Code statistics (lines, comments, ratio)
- Health scoring and improvement recommendations
Module 4: Test Generator (85% Confidence)
Creates test cases for refactored code:
- Unit tests (extracted methods, parameters, guards)
- Integration tests (combined functionality)
- Security tests (reentrancy, edge cases)
- Test templates and strategies
Usage Examples
Detect Code Smells
from scripts.pattern_detector import PatternDetector
detector = PatternDetector()
result = detector.analyze_code(source_code, language="python")
print(f"Smells found: {result['smells_detected']}")
print(f"Code quality: {result['code_quality']}%")
Get Refactoring Recommendations
from scripts.refactoring_suggester import RefactoringSuggester
suggester = RefactoringSuggester()
suggestions = suggester.suggest_refactoring(smell_data)
for suggestion in suggestions['suggestions']:
print(f"{suggestion['smell_type']}: {suggestion['solutions']}")
Analyze Complexity
from scripts.complexity_analyzer import ComplexityAnalyzer
analyzer = ComplexityAnalyzer()
metrics = analyzer.analyze_module(source_code)
print(f"Maintainability: {metrics['maintainability_index']['rating']}")
Generate Tests
from scripts.test_generator import TestGenerator
generator = TestGenerator()
tests = generator.generate_tests(refactoring_suggestions)
for test in tests['test_cases']:
print(f"Test: {test['name']}")
Output Format
All modules return structured JSON:
{
"analysis_type": "string",
"smells_detected": number,
"code_quality_score": 0-100,
"severity_breakdown": { "CRITICAL": n, "HIGH": n, ... },
"refactoring_opportunities": number,
"estimated_effort": "string",
"estimated_quality_improvement": number,
"test_cases_generated": number,
"recommendations": ["array of actionable items"],
"metrics": { "complexity": number, "maintainability": number, ... }
}
Severity Levels
| Level | Meaning | Impact | Action |
|---|---|---|---|
| CRITICAL | Major security/correctness issue | High risk | Fix immediately |
| HIGH | Significant code quality issue | Moderate risk | Fix in this sprint |
| MEDIUM | Maintainability concern | Low-moderate risk | Plan refactoring |
| LOW | Minor improvement opportunity | Low risk | Consider for future |
Version & Support
- Version: 1.0.0
- Released: February 8, 2026
- Status: Production Ready
- Confidence: 90%
Future Enhancements (v1.1.0)
- TypeScript and JavaScript support
- Machine learning-based pattern detection
- Historical complexity tracking
- Custom rule engine
- IDE plugin integration
- Automated refactoring execution
- Performance profiling integration
04 同仓库更多 Skills
troves
Deposit and withdraw from Troves DeFi yield vault strategies on Starknet. View available strategies, check positions, and manage vault deposits. Use this skill when the user mentions Troves, vault, yield vault, DeFi vault, strategy, yield farming, vault deposit, vault withdraw, earning yield through vaults, passive yield strategies, or wants to deposit into or withdraw from a yield strategy — even if they don't say "Troves" explicitly.
trade
Swap tokens on Starknet via Fibrous DEX aggregator. Supports per-provider selection (avnu, ekubo, or auto to race all). Use this skill when the user wants to swap, exchange, trade, convert, buy, or sell one token for another on Starknet. Also use when the user asks about token prices, exchange rates, DEX routing, best swap route, or wants to check how much they would receive for a given amount — even if they don't explicitly say "swap".
staking
Stake, unstake, claim, and compound rewards for STRK, WBTC, tBTC, SolvBTC, and LBTC on Starknet. View validators, pools, and staking positions. Use this skill when the user mentions staking, delegating, validators, staking pools, rewards, compounding, unstaking, earning yield, passive income on crypto, or wants to earn on their STRK or BTC tokens — even if they don't say "stake" explicitly.
send
Send STRK, ETH, or any ERC-20 token to a Starknet address. Supports simulation (dry-run) before execution. Use this skill when the user wants to send, transfer, pay, tip, or move tokens to another wallet address on Starknet. Also trigger when the user mentions sending funds to someone, making a payment, transferring assets, or moving crypto to a specific address — even if they just say "pay 10 STRK to 0x...".
portfolio
View a comprehensive DeFi portfolio dashboard and optimize portfolio allocation via automated rebalancing. Use this skill when the user wants an overview, summary, dashboard, total value, net worth, portfolio rebalancing, target allocation, or wants to see all their DeFi positions across Starknet at once. Also trigger when the user asks "what do I have", "show me everything", "how much am I worth", "my positions", "my investments", "rebalance my portfolio", "I want 50% ETH", "optimize my holdings", or any request for a holistic view of their Starknet holdings — even if they don't explicitly say "portfolio".
multi-swap
Execute multiple token swaps in a single Starknet transaction via Fibrous (default). Supports per-provider selection (avnu, ekubo, or auto to race all). Supports 2-3 swap pairs bundled into one multicall. Use this skill when the user wants to swap multiple token pairs at once, do batch swaps, execute several trades simultaneously, perform parallel swaps, or do bulk trading in one transaction. Also trigger when the user mentions "two swaps", "three swaps", "swap X and Y at the same time", or wants to convert multiple tokens in a single call.