Skip to main content

A command-line tool for code analysis.

Project description

py-cogit

Your AI senior software engineer, right in your terminal.

py-cogit is a command-line tool that acts as your personal code reviewer. It analyzes your staged changes (git diff --staged), sends them to Google's AI (Gemini), and provides a detailed analysis on best practices, potential bugs, readability, and even suggests a commit message for you.

Stop committing with fix: stuff. Start committing with confidence.

✨ Key Features

  • 🤖 AI-Powered Code Review: Get insights and suggestions from an AI model trained to act as a senior engineer.
  • 💡 Structured Analysis: The output is in JSON format, detailing improvement points, potential risks, and observations per file.
  • commit Automated Commit Messages: Generates a commit message suggestion following the Conventional Commits standard.
  • ⚙️ Highly Configurable: Use the default prompt or completely customize it via a .env file.
  • 🔒 Secure and Local: Your code is sent directly to the Google API. Your API key remains safe on your local machine.

🚀 Installation

Installation is easily done via pip.

pip install py-cogit

🛠️ Setup

Before using py-cogit for the first time, you need to set up your Google API key.

  1. Get Your API Key: Go to Google AI Studio and create your API key.

  2. Create a .env file: In the root of your project (or any parent directory from where you'll run the command), create a file named .env and add the following variables.

    # .env
    
    # Your API key from Google AI Studio
    GOOGLE_API_KEY="PASTE_YOUR_API_KEY_HERE"
    
    # The Gemini model you want to use
    GEMINI_VERSION="gemini-1.5-pro-latest"
    
    # (Optional) You can override the default prompt here
    PROMPT="You are an AI assistant..."
    

Usage

The workflow is simple and integrates seamlessly with Git.

  1. Make your code changes as usual.

  2. Add your changes to the Git staging area.

    git add .
    
  3. Run py-cogit!

    py-cogit
    

📋 Example Output

After running, py-cogit will print a detailed JSON analysis directly to your terminal:

{
  "overall_summary": "This change refactors the script to make the Gemini model version configurable and improves exception handling.",
  "analysis_per_file": [
    {
      "file_name": "main.py",
      "general_observations": [
        "Externalizing the model version to an environment variable is a great practice."
      ],
      "improvement_points": [
        {
          "approximate_line": "22",
          "code_snippet": "model = genai.GenerativeModel(os.getenv(\"GEMINI_VERSION\"))",
          "suggestion": "`os.getenv` will return `None` if the variable is not set, causing an error. Add validation to ensure the variable exists or provide a default value.",
          "category": "Potential Bug",
          "priority": "High"
        }
      ]
    }
  ],
  "potential_risks": [
    "The application now depends on the `GEMINI_VERSION` environment variable. If it is not set, the program will crash."
  ],
  "commit_message_suggestion": {
    "type": "refactor",
    "scope": "main",
    "subject": "configure model version via environment variable"
  }
}

Contributing

Contributions are very welcome! If you have ideas for new features, improvements, or have found a bug, please open an Issue so we can discuss it.

📜 License

This project is licensed under the MIT License. See the LICENSE file for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_cogit-0.1.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_cogit-0.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file py_cogit-0.1.0.tar.gz.

File metadata

  • Download URL: py_cogit-0.1.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for py_cogit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d9473f44451d116cd032b4f8aac31ce84ed0798910ab9fc060b9d88ed0c24e36
MD5 24169a68907a8c3e5c227a7705bd0b67
BLAKE2b-256 996bb94f2f9defcec69efc6aca3f04c2efaf787ea5a33b7a3f6edfec7123e6a1

See more details on using hashes here.

File details

Details for the file py_cogit-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: py_cogit-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for py_cogit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1edfad4f34bb1c7a6eaa9349d1d731cf5aa2bb0e478a364a43809b1f097d855b
MD5 66c24b015c8b975e44f5b271519c3e65
BLAKE2b-256 465ed863d40ec727478a2fd9a965054e253b29aa8ea6580ecb970f3f1cf13907

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page