Skip to content

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.

License

Notifications You must be signed in to change notification settings

sylvester-francis/CodexAgent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

21 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CodexAgent

Python Version Code style: black Ruff License: MIT YouTube Channel

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.

✨ Features

  • 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

πŸŽ₯ Watch & Learn

Check out our YouTube channel for tutorials and demos:

Watch on YouTube

πŸ†• Recent Updates

  • 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

πŸš€ Getting Started

Prerequisites

Installation

  1. Clone the repository

    git clone https://github.com/sylvester-francis/CodexAgent.git
    cd CodexAgent
  2. 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
  3. Configure environment variables

    cp .env.example .env
    # Edit .env and add your Gemini API key

πŸ› οΈ Usage

Basic Commands

Show help:

python cli.py --help

Get version:

python cli.py --version

πŸ” Code Analysis

Analyze code quality and get suggestions:

python cli.py analyze /path/to/your/code

Documentation Generation

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

Code Refactoring

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

Repository Summary

Generate a summary of a code repository:

python cli.py summarize run /path/to/your/repo --output summary.md

Summarize a Repository

python cli.py summarize run /path/to/your/repo

Generate Documentation

Single file:

python cli.py docgen file /path/to/your/file.py

Directory:

python cli.py docgen dir /path/to/your/directory

Refactor Code

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

πŸ§ͺ Testing & Quality

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 .

πŸ—οΈ Architecture

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
Loading

Component Overview

  1. CLI Commands

    • Entry point for user interaction
    • Command parsing and validation
    • Rich terminal output formatting
  2. Agents Layer

    • Documentation Generator: Creates comprehensive code documentation
    • Code Refactoring: Analyzes and improves code quality
    • Code Summarizer: Generates high-level code summaries
  3. LLM Integration

    • Google Gemini API integration
    • Handles AI model interactions
    • Manages API rate limiting and retries
  4. Utilities

    • Configuration management
    • Logging and error handling
    • File I/O operations
    • Input validation and sanitization

Data Flow

  1. User invokes a command through the CLI
  2. CLI parses arguments and routes to the appropriate agent
  3. Agent processes the request using utility functions
  4. For AI-powered features, the agent communicates with the Gemini API
  5. Results are formatted and displayed to the user
  6. Output is saved to disk if specified`

Component Interactions:

  1. CLI Commands: Entry point for user interactions (summarize, docgen, refactor)
  2. Agents: Core business logic for different functionalities
  3. LLM Backend: Google Gemini API integration for AI capabilities
  4. Output Formatters: Format results for console/file output
  5. Utilities: Shared helper functions and common utilities

Project Structure

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

🧹 Linting and Formatting

# Run flake8
flake8 app tests

# Run ruff
ruff check .
ruff format --check .

# Auto-fix with ruff
ruff check --fix .
ruff format .

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published