AI-powered code debt fixing tool with intelligent test generation
Project description
๐ง Codebase Intelligence System
A RAG-based code analysis tool that understands your codebase and provides intelligent suggestions for improvement.
๐ฏ What This Project Does
This tool uses Retrieval-Augmented Generation (RAG) to analyze codebases and provide intelligent insights:
- ๐ Code Parsing: Parses Python, JavaScript, TypeScript files with AST analysis
- ๐ง Vector Database: Stores code embeddings for semantic search
- ๐ Code Insights: Analyzes functions, classes, complexity, and dependencies
- ๐ Duplicate Detection: Finds similar code patterns across files
- ๐ฏ Refactoring Suggestions: Identifies cross-file refactoring opportunities
- ๐งช Test Generation: Creates context-aware tests based on your codebase
- ๐ค AI Integration: Provides intelligent code improvement suggestions
๐ Quick Start
Installation
# Clone the repository
git clone <repository-url>
cd fix-code-debt
# Install dependencies
pip install -r requirements.txt
Basic Usage
# Initialize intelligence system
python3 -m iterate.cli . --intelligence
# Get codebase insights
python3 -m iterate.cli . --codebase-insights
# Find duplicate code patterns
python3 -m iterate.cli . --find-duplicates
# Analyze cross-file refactoring opportunities
python3 -m iterate.cli . --cross-file-refactor
๐ Available Commands
Core Features
# Initialize the intelligence system
python3 -m iterate.cli <directory> --intelligence
# Get comprehensive codebase insights
python3 -m iterate.cli <directory> --codebase-insights
# Find duplicate code patterns
python3 -m iterate.cli <directory> --find-duplicates
# Suggest cross-file refactoring opportunities
python3 -m iterate.cli <directory> --cross-file-refactor
# Generate intelligent refactoring suggestions for a specific file
python3 -m iterate.cli <directory> --intelligent-refactor <file_path>
# Generate context-aware tests for a file
python3 -m iterate.cli <directory> --context-aware-tests <file_path>
# Update context when a file changes
python3 -m iterate.cli <directory> --update-context <file_path>
Traditional File Scanning
# Basic directory scan
python3 -m iterate.cli <directory>
# Non-recursive scan
python3 -m iterate.cli <directory> --no-recursive
# Limit scan depth
python3 -m iterate.cli <directory> --max-depth 3
# Monitor directory for changes
python3 -m iterate.cli <directory> --monitor
# Verbose output
python3 -m iterate.cli <directory> -v
๐ What You'll See
Intelligence Initialization
๐ง Initializing Intelligent Codebase Features...
๐ Initializing codebase intelligence system...
๐ Loading embedding model...
๐๏ธ Setting up vector database...
โ
Codebase Intelligence initialized successfully!
Codebase Insights
๐ Getting codebase insights...
๐ Total chunks: 45
๐ Unique files: 12
๐ง Functions: 23
๐๏ธ Classes: 8
๐ฆ Imports: 14
๐ Average complexity: 3.2
โ ๏ธ High complexity functions: 3
๐ Duplicates found: 2
๐ฏ Cross-file opportunities: 5
Duplicate Detection
๐ Finding duplicate code patterns...
๐ฏ Found 2 duplicate patterns:
๐ Function: validate_input
Occurrences: 3
Files: utils.py, helpers.py, main.py
Suggestion: Consider extracting 'validate_input' into a shared utility function
๐๏ธ Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ RAG System Architecture โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โ โ File Parser โ โ AST Analyzer โ โ Chunking โ โ
โ โ โ โ โ โ โ โ
โ โ โข Python AST โ โ โข Functions โ โ โข Functions โ โ
โ โ โข JS Regex โ โ โข Classes โ โ โข Classes โ โ
โ โ โข Multi-lang โ โ โข Imports โ โ โข Modules โ โ
โ โโโโโโโโโโโโโโโโโโโ โ โข Complexity โ โ โข Imports โ โ
โ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โ โ Embeddings โ โ Vector DB โ โ Query โ โ
โ โ โ โ โ โ โ โ
โ โ โข Sentence โ โ โข ChromaDB โ โ โข Semantic โ โ
โ โ Transformers โ โ โข Persistent โ โ โข Similarityโ โ
โ โ โข all-MiniLM โ โ โข Collections โ โ โข Context โ โ
โ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Project Structure
fix-code-debt/
โโโ iterate/
โ โโโ cli.py # Main CLI interface
โ โโโ core/
โ โ โโโ codebase_intelligence.py # RAG system core
โ โ โโโ intelligent_ai_generator.py # AI integration
โ โ โโโ ai_code_generator.py # AI code generation
โ โ โโโ dependency_mapper.py # Dependency analysis
โ โ โโโ test_generator.py # Test generation
โ โ โโโ ... (other core modules)
โ โโโ utils/ # Utility functions
โ โโโ integrations/ # External integrations
โโโ tests/ # Test files
โโโ README.md # This file
๐ฏ Use Cases
For Developers
- Code Review: Quickly identify complex functions and potential issues
- Refactoring: Find duplicate code and cross-file refactoring opportunities
- Testing: Generate context-aware tests for your functions
- Documentation: Understand codebase structure and dependencies
For Teams
- Code Quality: Monitor complexity and maintainability metrics
- Knowledge Sharing: Understand how different parts of the codebase relate
- Onboarding: Help new developers understand the codebase structure
For Projects
- Technical Debt: Identify areas that need refactoring
- Architecture: Analyze dependencies and coupling between modules
- Maintenance: Track code changes and their impact across files
๐ง Dependencies
- sentence-transformers: For code embeddings
- chromadb: For vector database storage
- numpy: For numerical operations
- ast: For Python code parsing
- re: For regex-based parsing
- python-dotenv: For environment variable management
- openai: For AI-powered code generation
๐ Environment Setup
Required Environment Variables
The tool requires certain environment variables to be set for full functionality:
# OpenAI API key (required for AI features)
OPENAI_API_KEY=your_openai_api_key_here
# Optional environment variables
CHROMA_DB_PATH=./.iterate_cache/chromadb
LOG_LEVEL=INFO
Setting Up Environment Variables
Option 1: Use the helper script (recommended)
python3 create_env.py
Option 2: Create .env file manually
Create a .env file in your project root:
echo "OPENAI_API_KEY=your_actual_api_key" > .env
Option 3: Set system environment variables
export OPENAI_API_KEY=your_actual_api_key
The tool automatically loads environment variables from .env files using python-dotenv.
Note: The
.envfile is automatically ignored by git for security.
๐ Future Features
- Real-time Updates: File watchers for live code analysis
- Enhanced AI: Context-aware code generation and refactoring
- Multi-language Support: More programming languages
- IDE Integration: Plugin for popular IDEs
- Team Analytics: Code quality metrics and trends
๐ Examples
Analyze a Python Project
python3 -m iterate.cli /path/to/python/project --intelligence --codebase-insights
Find Duplicates in JavaScript Project
python3 -m iterate.cli /path/to/js/project --find-duplicates
Generate Tests for Specific File
python3 -m iterate.cli . --context-aware-tests src/main.py
Monitor Changes
python3 -m iterate.cli . --monitor --duration 300
๐ค Contributing
This project is designed to be a smart code analysis tool that helps developers understand and improve their codebases. Contributions are welcome!
๐ License
[Add your license information here]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file iterate_code_debt-0.1.0.tar.gz.
File metadata
- Download URL: iterate_code_debt-0.1.0.tar.gz
- Upload date:
- Size: 55.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
271659242ba409f4cdfdf1c9cf9d4071ac4095f1afa4597338423d245b445698
|
|
| MD5 |
db48421ab17799673d75d0dada870784
|
|
| BLAKE2b-256 |
865114abc154d4b128b4e57663a875b664b2c17f27c9569854d13dacd7505671
|
File details
Details for the file iterate_code_debt-0.1.0-py3-none-any.whl.
File metadata
- Download URL: iterate_code_debt-0.1.0-py3-none-any.whl
- Upload date:
- Size: 62.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45570b4a3b3f5dab71cd2e27a08c8ffe5cf0e595a643b74e2349064a6d6adf75
|
|
| MD5 |
b622210f0b4ea08afc21c90122e69f96
|
|
| BLAKE2b-256 |
146c8bb3f6a2b8230bd6f642d2ae1ce03b6d0226f1abf7c44579c4a75eea6bc2
|