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
.envfile. - 🔒 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.
-
Get Your API Key: Go to Google AI Studio and create your API key.
-
Create a
.envfile: In the root of your project (or any parent directory from where you'll run the command), create a file named.envand 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.
-
Make your code changes as usual.
-
Add your changes to the Git staging area.
git add .
-
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4da9613224c24a376b3ccb9fecda6e0e85efe8e1d4a9a8c30fd4a63c5eda041
|
|
| MD5 |
c4c8dc3a589883d77364717ff5d850e9
|
|
| BLAKE2b-256 |
191c917b411459f6ccb479f33c4f2e1657d25512e371dba2153777cd3bf393fc
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a45309e49de34e948ed82e74cca0b3af52ab58b426e5c2f1b476557263dd2f5
|
|
| MD5 |
2ee27974185f9b62f0835b67a9d71ea8
|
|
| BLAKE2b-256 |
20dff18469c90c9c0f2808079fe2bde26f908ad088fadef7157366f72ccb17e7
|