Skip to main content

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.

Metadata

Release files for gitkritik 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gitkritik 0.2.1
File Size Uploaded
gitkritik-0.2.1.tar.gz 35.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gitkritik 0.2.1
File Interpreter ABI Platform
gitkritik-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 88.9 kB

Release files / gitkritik-0.2.1.tar.gz

Download URL gitkritik-0.2.1.tar.gz
Size 35.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c7575c6a8a6b97b804180cf74c269d927ae554835c05ed416df2e4eef9f4a8bd
BLAKE2b-256 checksum
How to use checksums
9fd34cddc2df147431b9fb582aa3cedf8f9a4ef50911d462ff65cac396477439
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.2 CPython/3.13.2 Windows/10

Release files / gitkritik-0.2.1-py3-none-any.whl

Download URL gitkritik-0.2.1-py3-none-any.whl
Size 53.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
baae4d408dccb05643c5db87cc7d5df40d44283e5689707f75bbde016d35ed57
BLAKE2b-256 checksum
How to use checksums
475e181113b882f967be293c2b894449a29560238b8d2159f717f51a142720de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.2 CPython/3.13.2 Windows/10

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page