Skip to main content

AI-powered code review CLI and CI agent for Git, using Langchain and LangGraph.

Project description

GitKritik2

AI-powered, context-aware code review CLI and CI agent for Git. Built on LangGraph, GitKritik brings multi-agent reasoning to your code changes, understanding symbols defined in other files (currently Python-only via Jedi) to provide deeper insights. It runs directly from your terminal or integrates into your CI pipeline.


🚀 Features

  • Native Git Integration: Use directly via git kritik.
  • 🧠 Multi-Agent Architecture: Modular agents for Style, Bugs, Design/Architecture, Context Gathering (ReAct), and Summarization.
  • 🐍 Python Context Awareness: ReAct agent uses Jedi to fetch definitions of imported Python symbols from other project files, informing bug/design analysis.
  • 🤖 Broad LLM Support: Works with OpenAI (GPT models), Anthropic (Claude models), Google (Gemini models), and local LLMs via Ollama.
  • 🖥️ Rich CLI Output: Uses rich for formatted diffs and inline comments directly in your terminal, highlighting agent contributions.
  • ⚙️ CI Integration: Seamlessly integrates with GitHub Actions & GitLab CI to post inline and summary comments on PRs/MRs.
  • 🛡️ Robust Configuration: Configure via .kritikrc.yaml and .env, with environment variables taking precedence.
  • 📦 Reproducible & Extensible: Built with Poetry for dependency management, Pydantic for data validation, and LangGraph for workflow orchestration.
  • 🔍 Observability: Easily integrate with LangSmith for tracing and debugging agent behavior.

🧰 Installation & Reproducibility

Requires Python 3.10+. We use Poetry for dependency management to ensure reproducible environments.

  1. Clone the Repository:

    git clone https://github.com/preslaff/gitkritik2.git # Use your actual repo URL
    cd gitkritik2
    
  2. Install Dependencies using Poetry:

    # Install Poetry if you haven't already (https://python-poetry.org/docs/#installation)
    pipx install poetry
    
    # Install project dependencies locked in poetry.lock
    poetry install --no-root
    

    Using poetry install guarantees you install the exact versions of dependencies specified in poetry.lock, ensuring others can reproduce your environment.

  3. (Optional) Activate Virtual Environment:

    poetry shell
    

    This activates the virtual environment managed by Poetry, making the kritik command directly available.

This makes the git kritik command available either directly (if using poetry shell) or via poetry run kritik. The installation via Poetry handles the creation of the necessary command-line entry points.


🧑‍💻 Usage

Ensure you are inside your target Git repository.

🔍 Local Review

Review changes locally before committing or pushing.

# Activate environment (if not already done)
# poetry shell

# Review only unstaged changes vs the index
git kritik -u

# Review only staged changes vs the merge-base with origin/main
# (This is the default if no flags are given and staged files exist)
git kritik

# Review all local changes (staged + unstaged) vs HEAD
git kritik -a

# Show inline comments in the terminal output (in addition to summary)
git kritik -i

# Combine flags (e.g., review unstaged with inline comments)
git kritik -u -i

(Note: Side-by-side view (-s) is currently experimental and may fall back to unified view).

🤖 In CI (GitHub Actions Example)

Add this to your .github/workflows/your_workflow.yml:

name: AI Code Review

on:
  pull_request:

jobs:
  ai_review:
    runs-on: ubuntu-latest
    permissions:
      contents: read # Need read access to checkout
      pull-requests: write # Need write access to post comments/reviews
    steps:
      - name: Checkout Code
        uses: actions/checkout@v4
        # Fetch full history for accurate diffing against merge-base
        with:
          fetch-depth: 0

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.11' # Match your project's requirement

      - name: Install Poetry
        run: pipx install poetry

      - name: Install Dependencies
        # Use --sync if you want to ensure only lock file deps are present
        run: poetry install --no-root --sync

      - name: Run GitKritik Review
        # --ci enables CI mode (env var detection)
        # --inline enables posting inline comments to the PR/MR
        run: poetry run kritik --ci --inline
        env:
          # Required for posting comments/reviews
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          # Required API keys for your configured LLM provider
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
          GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
          # Optional: LangSmith tracing
          LANGCHAIN_TRACING_V2: "true"
          LANGCHAIN_API_KEY: ${{ secrets.LANGSMITH_API_KEY }}
          LANGCHAIN_PROJECT: "GitKritik-${{ github.repository }}" # Example project name

This configuration ensures a consistent environment using Poetry and posts review comments directly to the GitHub Pull Request.

(GitLab CI setup is similar, ensure GITLAB_TOKEN or CI_JOB_TOKEN is available).


⚙️ Configuration

Configure GitKritik via .kritikrc.yaml and .env files in your project root. Environment variables always override file settings. See example files in the repository.

  • .kritikrc.yaml: Configure platform, strategy, llm_provider, model, temperature, max_tokens.
  • .env: Store sensitive API keys (OPENAI_API_KEY, ANTHROPIC_API_KEY, GEMINI_API_KEY) and platform tokens (GITHUB_TOKEN, GITLAB_TOKEN). Do not commit .env!

🧠 Architecture (Using LangGraph)

GitKritik employs a stateful graph architecture orchestrated by LangGraph:

  1. Setup: Initialize state, resolve Git/CI context.
  2. Diffing: Detect changed files and prepare context (diffs, file content).
  3. Context Agent (ReAct): Analyzes Python code changes, uses Jedi to find definitions of imported project symbols, enriching the context.
  4. Review Agents: Specialized agents (Bug, Design, Style) analyze changes using the enriched context and LLM calls. Comments are filtered to match added lines in the diff.
  5. Summarization: An agent generates a high-level summary.
  6. Output: Results are merged, formatted, and either displayed locally via rich or posted to the configured platform (GitHub/GitLab).

🛠️ Future Work & Enhancements

  • Multi-Language Context Agent (LSP):
    • Implement a new LangChain tool leveraging the Language Server Protocol (LSP).
    • Integrate with standard LSP servers (e.g., gopls, typescript-language-server, clangd, jdtls, OmniSharp, solargraph).
    • This will enable context-aware analysis (get_symbol_definition) for languages beyond Python (Go, TS/JS, C/C++, Java, C#, Ruby).
    • Requires user installation of relevant LSP servers and potentially configuration within GitKritik.
  • Improved ReAct Tool Calling: Enhance the reliability of the ReAct agent's ability to format tool inputs correctly, potentially by using native LLM tool-calling features (e.g., OpenAI Functions/Tools) instead of text parsing.
  • More Robust Diff Parsing: Ensure maximum accuracy in mapping LLM comments to specific changed lines using libraries like unidiff.
  • Configuration Validation: Add stricter validation for .kritikrc.yaml contents.
  • Agent Tuning: Fine-tune prompts and logic for specific agent types.
  • Additional Agents: Explore agents for security vulnerabilities, documentation consistency, etc.
  • Caching: Implement caching for LLM calls or fetched definitions to improve performance and reduce costs.

🤝 Contributing

Contributions are highly welcome! Please see CONTRIBUTING.md (if available) or open an issue/PR to discuss improvements. Using Poetry for development is recommended for consistency.


📄 License

MIT © 2024 Preslav Apostolov preslaff@gmail.com


**Key Updates:**

*   Clarified the Python-only context awareness (Jedi).
*   Added a dedicated "Installation & Reproducibility" section emphasizing Poetry.
*   Updated the CI example with Poetry usage and clearer env var explanations.
*   Explicitly listed the LSP integration under "Future Work & Enhancements", detailing the goal and requirements.
*   Added other potential future work items like improved ReAct, caching, etc.
*   Slightly refined the Architecture description.
*   Updated license owner and year.

This README provides a clearer picture of the current state, installation process, and future direction, including the significant LSP enhancement plan.

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

gitkritik-0.2.1.tar.gz (35.8 kB view details)

Uploaded Source

Built Distribution

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

gitkritik-0.2.1-py3-none-any.whl (53.1 kB view details)

Uploaded Python 3

File details

Details for the file gitkritik-0.2.1.tar.gz.

File metadata

  • Download URL: gitkritik-0.2.1.tar.gz
  • Upload date:
  • Size: 35.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.13.2 Windows/10

File hashes

Hashes for gitkritik-0.2.1.tar.gz
Algorithm Hash digest
SHA256 c7575c6a8a6b97b804180cf74c269d927ae554835c05ed416df2e4eef9f4a8bd
MD5 ce3c0579ec10ee216962580798ae082a
BLAKE2b-256 9fd34cddc2df147431b9fb582aa3cedf8f9a4ef50911d462ff65cac396477439

See more details on using hashes here.

File details

Details for the file gitkritik-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: gitkritik-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 53.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.13.2 Windows/10

File hashes

Hashes for gitkritik-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 baae4d408dccb05643c5db87cc7d5df40d44283e5689707f75bbde016d35ed57
MD5 e97f355f188dad34acb0881557f56966
BLAKE2b-256 475e181113b882f967be293c2b894449a29560238b8d2159f717f51a142720de

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