This tool is designed to analyze and improve the quality of Python code repositories. It uses various linters, static code analysis tools, and AI-powered suggestions to identify and fix potential issues in your codebase.
This code is considered alpha as of 2024-10-23
98% of this code was written by aider
- Python 3.12 or higher
- Git
- Virtual environment (recommended)
- SQLite3
agent_v2.py
: Main agent for processing Python filesaider_runner.py
: Runs Aider to fix code issuescommand_runner.py
: Executes system commands securelyconfig.py
: Configuration management with validationfile_processor.py
: Processes individual filesgit_manager.py
: Handles Git operationsissue_processor.py
: Analyzes and groups code issueslinter_runner.py
: Runs various code linterslogger.py
: Centralized logging systemresource_manager.py
: Manages system resourcessuggestion_db.py
: SQLite database managementsuggestion_api.py
: FastAPI-based suggestion APIsuggestion_cli.py
: CLI interfacesuggestion_web.py
: Flask web interface
- Scans Python files in a git repository
- Runs multiple linters (Pylint, Flake8, Ruff)
- Processes and groups issues by type and function
- Uses AI (via Aider) to suggest and apply fixes
- Provides secure web and CLI interfaces
- Supports running tests to validate fixes
- Allows interrogation of specific files using AI
- Resource monitoring and management
- Rate limiting and error handling
- Secure input validation and sanitization
-
Install aider-chat:
pip install aider-chat==0.60.0
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
- For local development:
pip install -r requirements.txt
- For Docker deployment:
pip install -r requirements.docker.txt
- For local development:
cp config_example.yaml config_local.yaml
cp config_example.yaml config_docker.yaml
REPO_PATH
: Path to Git repositoryVENV_PATH
: Virtual environment pathTEST_COMMAND
: Command to run testsMAX_LINE_LENGTH
: Maximum line length for codeLINTER
: Choice of linter (pylint/flake8/ruff)AIDER_MODEL
: AI model selectionMAX_CODE_LENGTH
: Maximum code sizeMAX_MEMORY_MB
: Memory limitAPI_RATE_LIMIT
: API call limit
- Memory limit: Configurable via MAX_MEMORY_MB
- CPU usage monitoring
- Automatic temp file cleanup
- API rate limiting
- Database connection management
- Request size limits
- Input validation and sanitization
- CSRF protection
- Content Security Policy
- Request size limits
- Secure cookie handling
- XSS protection
- Rate limiting
- Resource monitoring
The application uses SQLite3 for storing:
- Code analysis suggestions
- AI responses
- File metadata
- Timestamps
Database file: suggestions.db
Maintenance: Automatic cleanup based on configured thresholds
Start the web server:
python app.py
Access at http://localhost:8080
Available pages:
/
: Code analysis input/suggestions
: Previous analyses/suggestion/<id>
: Detailed view/analyze
: New analysis
Start the API:
uvicorn suggestion_api:app --host 0.0.0.0 --port 8000
python aider_interrogator.py --file /path/to/file.py --question "Your question"
python suggestion_cli.py [--id <id>] [--delete <id>] [--highlight]
python agent_v2.py [--debug] [--max-workers <n>] [--file <path>]
DOCKER_ENV
: Set to 1 for DockerFLASK_SECRET_KEY
: Flask security keyFLASK_ENV
: development/productionAIDER_API_KEY
: Aider API keyGOOGLE_CLOUD_PROJECT
: GCP project ID
Common errors and solutions:
- Timeout: Reduce code size or increase timeout
- Rate limit: Wait and retry
- Resource limit: Increase limits or reduce load
- Validation: Check input requirements
- Database: Check permissions and space
Automatic retries implemented for:
- API calls
- Database operations
- Command execution
Logs include:
- Timestamp
- Log level
- File and line number
- Message
Log levels:
- INFO: Normal operations
- ERROR: Failures and exceptions
- DEBUG: Detailed debugging (when enabled)
Run tests:
python -m pytest
Test coverage includes:
- Unit tests
- Integration tests
- Resource management tests
- Security tests
docker build -t code-quality-tool .
docker run -p 8080:8080 -p 8000:8000 code-quality-tool
This tool is under active development. Contributions welcome!
- Run tests before commits
- Check resource usage
- Monitor logs
- Review security settings
- Keep dependencies updated
For issues and questions:
- Check logs
- Review configuration
- Verify dependencies
- Check resource usage
- Review documentation