Skip to main content

A command-line tool for code analysis.

Project description

py-cogit

Your AI senior software engineer, right in your terminal.

PyPI Link

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.1.tar.gz (5.4 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.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_cogit-0.1.1.tar.gz
  • Upload date:
  • Size: 5.4 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.1.tar.gz
Algorithm Hash digest
SHA256 d4da9613224c24a376b3ccb9fecda6e0e85efe8e1d4a9a8c30fd4a63c5eda041
MD5 c4c8dc3a589883d77364717ff5d850e9
BLAKE2b-256 191c917b411459f6ccb479f33c4f2e1657d25512e371dba2153777cd3bf393fc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_cogit-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4a45309e49de34e948ed82e74cca0b3af52ab58b426e5c2f1b476557263dd2f5
MD5 2ee27974185f9b62f0835b67a9d71ea8
BLAKE2b-256 20dff18469c90c9c0f2808079fe2bde26f908ad088fadef7157366f72ccb17e7

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