We'll use a dense block of badges to show off the stack and the project's health.
Automated Code Governance. This assistant uses AST analysis and LLMs to identify technical debt, suggest refactors, and verify them in a safe sandbox before they ever touch your main branch.
- Static Analysis: Uses
ast_analyzer.pyto find complex/messy functions locally (saving tokens). - AI Refactoring: Sends problematic snippets to GPT-4o with context-aware prompts.
- Sandbox Verification: Runs your existing
pytestsuite against the new code in an isolated environment. - GitHub Integration: Posts a clean
diffreport directly to your Pull Request.
- Clone the Repo
git clone [https://github.com/Gitdigital-products/-AI-powered-code-refactoring-assistant.git](https://github.com/Gitdigital-products/-AI-powered-code-refactoring-assistant.git) cd -AI-powered-code-refactoring-assistant
-
Setup Environment python -m venv venv source venv/bin/activate pip install -r requirements.txt
-
Configure API Keys Create a .env file: OPENAI_API_KEY=your_key_here
🤖 Usage Local CLI Refactor a specific file and see the diff locally: python main.py --file src/engine/messy_code.py
GitHub Action Simply comment /refactor on any Pull Request, and the bot will:
- Analyze the changes.
- Verify the logic in the sandbox.
- Reply with a suggested diff. 🏛️ Governance & Compliance Designed for GitDigital standards, this tool ensures that refactors adhere to:
- Dry Principles: Reducing code duplication.
- Security: Avoiding common sinkholes in Web3/Solana (Anchor) logic.
- Readability: Maintaining a clean codebase for decentralized teams. 🤝 Contributing Feel free to open an issue or submit a PR. Let's build the future of automated code quality together!
src/engine/ast_analyzer.py: ✅ Donesrc/engine/refactor_engine.py: ✅ Donesrc/engine/sandbox.py: ✅ Donesrc/utils/diff_tool.py: ✅ Done.github/workflows/refactor-bot.yml: ✅ Donerequirements.txt&README.md: ✅ Done
AI-powered code refactoring assistant: A bot that automatically suggests and applies code refactors based on best practices and performance improvements. AI-Powered Code Refactoring Assistant 🤖
An intelligent bot that automatically suggests and applies code refactoring improvements based on best practices, performance metrics, and maintainability standards. This tool leverages machine learning to analyze code patterns and provide context-aware recommendations.
Features
· Automated Code Analysis: Scans your codebase for anti-patterns and improvement opportunities · Context-Aware Suggestions: Provides language-specific recommendations based on best practices · Safe Refactoring: Applies changes with built-in safety checks and backup systems · Multi-Language Support: Works across multiple programming languages · Customizable Rules: Configure refactoring rules to match your team's standards · Version Control Integration: Works seamlessly with Git and other VCS
Supported Languages
· Python · JavaScript/TypeScript · Java · C# · Go · Ruby · PHP · And more through extensible architecture
Installation
# Clone the repository
git clone https://github.com/RickCreator87/ai-refactoring-assistant.git
# Install dependencies
cd ai-refactoring-assistant
pip install -r requirements.txtUsage
# Analyze code without applying changes
refactor analyze --path /your/code/path
# Apply suggested refactoring
refactor apply --path /your/code/path
# Custom rules configuration
refactor --config ./custom_rules.yamlExample
Before:
def calculate(a,b):
x = a + b
y = x * 2
return yAfter Refactoring:
def calculate_double_sum(a: int, b: int) -> int:
"""Calculate the double of the sum of two integers."""
return 2 * (a + b)Configuration
Create a .refactorrc file to customize behavior:
rules:
- complexity
- performance
- naming
- documentation
ignore:
- tests/
- vendor/
language: python
strict: falseContributing
We welcome contributions! Please see our Contributing Guidelines for details.
License
MIT License - see LICENSE file for details.
Roadmap
· Add plugin system for custom rules · Integrate with popular IDEs · Add CI/CD integration · Support for additional languages · Interactive refactoring mode
For the gist language selection: Python would be an excellent choice as it's widely used in AI/ML projects and has strong ecosystem support for code analysis tools. Alternatively, TypeScript would be great if you're focusing on web development ecosystems.