CodexAgent is an AI-powered command-line tool for code analysis, documentation generation, and refactoring. It uses Google's Gemini AI to provide intelligent code analysis and suggestions.
- Code Summarization: Generate high-level summaries of code repositories
- Documentation Generation: Automatically generate documentation for Python code with multiple style support (numpy, google, rest)
- Code Refactoring: Get AI-powered refactoring suggestions and apply them with a single command
- Code Analysis: Detect code quality issues and get improvement suggestions
- Linting & Formatting: Integrated with flake8, ruff, and black for code quality
- Testing: Comprehensive test suite with pytest
- CI/CD: GitHub Actions workflow for testing and linting
- Modern CLI: User-friendly command-line interface with rich output
Check out our YouTube channel for tutorials and demos:
- Enhanced Documentation Generation: Added support for multiple docstring styles
- Improved Code Analysis: Better detection of code quality issues
- Refactoring Tools: More reliable code refactoring with detailed reports
- Bug Fixes: Fixed various linting and formatting issues
- Improved Error Handling: Better error messages and user feedback
- Python 3.8+
- Poetry (recommended) or pip
- Google Gemini API Key
-
Clone the repository
git clone https://github.com/sylvester-francis/CodexAgent.git cd CodexAgent
-
Set up the environment
# Using Poetry (recommended) poetry install poetry shell # Or using pip python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -r requirements.txt pip install -r requirements-dev.txt # For development
-
Configure environment variables
cp .env.example .env # Edit .env and add your Gemini API key
Show help:
python cli.py --help
Get version:
python cli.py --version
Analyze code quality and get suggestions:
python cli.py analyze /path/to/your/code
Single file with specific style (numpy/google/rest):
python cli.py docgen file /path/to/your/file.py --style numpy
Directory with custom output:
python cli.py docgen dir /path/to/your/directory --output-dir ./docs
Analyze without changes:
python cli.py refactor file /path/to/your/file.py
Apply refactoring with backup:
python cli.py refactor file /path/to/your/file.py --apply --output-dir ./refactored
Generate a summary of a code repository:
python cli.py summarize run /path/to/your/repo --output summary.md
python cli.py summarize run /path/to/your/repo
Single file:
python cli.py docgen file /path/to/your/file.py
Directory:
python cli.py docgen dir /path/to/your/directory
Analyze a file:
python cli.py refactor file /path/to/your/file.py
Apply refactoring:
python cli.py refactor file /path/to/your/file.py --apply --output-dir ./refactored
Run the complete test suite:
# Run all tests with coverage
pytest --cov=app --cov-report=term-missing
# Run specific test file with verbose output
pytest tests/test_summarize.py -v
# Run all tests in parallel (requires pytest-xdist)
pytest -n auto
# Run linters
flake8 app tests
ruff check .
# Auto-fix linting issues
ruff check --fix .
ruff format .
graph TD
subgraph CodexAgent[CodexAgent CLI Tool]
CLI[CLI Commands] -->|Parse & Validate| Agents[Agents]
subgraph Agents[Agents Layer]
direction TB
DocGen[Documentation Generator] -->|Generate| DocOutput[Documentation]
Refactor[Code Refactoring] -->|Analyze/Modify| CodeOutput[Refactored Code]
Summarizer[Code Summarizer] -->|Generate| SummaryOutput[Summaries]
end
subgraph LLM[LLM Integration]
direction LR
Gemini[Google Gemini API] -->|Process| Agents
Agents -->|Send Requests| Gemini
end
subgraph Utils[Utilities]
direction TB
Config[Configuration]
Logging[Logging]
FileIO[File I/O]
Validators[Input Validation]
end
CLI -->|Use| Utils
Agents -->|Use| Utils
end
style CLI fill:#f9f,stroke:#333,stroke-width:2px
style Agents fill:#bbf,stroke:#333,stroke-width:2px
style LLM fill:#f96,stroke:#333,stroke-width:2px
style Utils fill:#9f9,stroke:#333,stroke-width:2px
-
CLI Commands
- Entry point for user interaction
- Command parsing and validation
- Rich terminal output formatting
-
Agents Layer
- Documentation Generator: Creates comprehensive code documentation
- Code Refactoring: Analyzes and improves code quality
- Code Summarizer: Generates high-level code summaries
-
LLM Integration
- Google Gemini API integration
- Handles AI model interactions
- Manages API rate limiting and retries
-
Utilities
- Configuration management
- Logging and error handling
- File I/O operations
- Input validation and sanitization
- User invokes a command through the CLI
- CLI parses arguments and routes to the appropriate agent
- Agent processes the request using utility functions
- For AI-powered features, the agent communicates with the Gemini API
- Results are formatted and displayed to the user
- Output is saved to disk if specified`
- CLI Commands: Entry point for user interactions (summarize, docgen, refactor)
- Agents: Core business logic for different functionalities
- LLM Backend: Google Gemini API integration for AI capabilities
- Output Formatters: Format results for console/file output
- Utilities: Shared helper functions and common utilities
CodexAgent/
βββ app/ # Main application package
β βββ agents/ # AI agents for different tasks
β β βββ docgen_agent.py # Documentation generation
β β βββ refactor_agent.py # Code refactoring
β β βββ summarize_agent.py # Code summarization
β βββ commands/ # CLI command implementations
β βββ llm/ # Language model integrations
β βββ utils/ # Utility functions
βββ tests/ # Test suite
βββ .github/workflows/ # GitHub Actions workflows
βββ .flake8 # Flake8 configuration
βββ .pre-commit-config.yaml # Pre-commit hooks
βββ pyproject.toml # Project metadata and dependencies
βββ README.md # This file
# Run flake8
flake8 app tests
# Run ruff
ruff check .
ruff format --check .
# Auto-fix with ruff
ruff check --fix .
ruff format .
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Google Gemini - For the powerful AI models
- Typer - For the CLI framework
- Pytest - For testing framework