🧠 Cortex

AI code reviewer that learns from your preferences through reinforcement learning.

Go Version License Tests

Cortex is a privacy-first code reviewer that runs entirely on your machine. Unlike cloud-based tools, it learns YOUR coding style through reinforcement learning and gets smarter with every commit.


✨ Features

  • 🔒 Privacy-First: All analysis happens locally, code never leaves your machine
  • 🧠 Adaptive Learning: Uses RL to learn from your accept/reject decisions
  • ⚡ Fast: Sub-2-second reviews with quantized local models
  • đŸŽ¯ Context-Aware: Understands your project structure and patterns
  • đŸ› ī¸ Git Integration: Seamlessly works with your existing workflow
  • 📊 Multi-Language: Supports Go, Python, JavaScript, TypeScript, and more

🚀 Quick Start

Installation

# Clone repository
git clone https://github.com/AdeshDeshmukh/cortex.git
cd cortex

# Build
make build

# Install system-wide (optional)
make install

Usage

# Navigate to your project
cd ~/projects/myapp

# Install git hook
cortex install

# Make code changes
echo "func test() {}" >> main.go
git add main.go

# Commit (Cortex reviews automatically)
git commit -m "Add test function"

Output:

🧠 Cortex Review

📊 Summary:
   Files changed:  1
   Lines added:    +1
   Lines removed:  -0
   Languages:      go (1)

📁 Files:
   1. main.go (go)
      +1 -0 lines

âŗ Analysis pipeline:
   ✅ Diff parsing complete
   âšī¸  Static analysis (coming soon)
   âšī¸  LLM suggestions (coming soon)

📖 Commands

Command Description
cortex install Install pre-commit hook in current repo
cortex install --force Overwrite existing hook
cortex install --uninstall Remove hook
cortex review Manually review staged changes
cortex review --hook Run in hook mode (internal)
cortex --help Show all commands

đŸ—ī¸ Architecture

┌─────────────────────────────────────────────┐
│           USER COMMITS CODE                 │
└──────────────â”Ŧ──────────────────────────────┘
               │
               â–ŧ
┌──────────────────────────────────────────────┐
│         GIT PRE-COMMIT HOOK                  │
│  Triggers: cortex review --hook              │
└──────────────â”Ŧ───────────────────────────────┘
               │
               â–ŧ
┌──────────────────────────────────────────────┐
│         DIFF PARSER (Go)                     │
│  Converts git diff → structured data         │
└──────────────â”Ŧ───────────────────────────────┘
               │
               â–ŧ
┌──────────────────────────────────────────────┐
│         ANALYZER PIPELINE                    │
│  1. Static analysis (regex, AST)             │
│  2. LLM inference (local model)              │
│  3. Ranking (RL policy)                      │
└──────────────â”Ŧ───────────────────────────────┘
               │
               â–ŧ
┌──────────────────────────────────────────────┐
│         INTERACTIVE UI                       │
│  User accepts/rejects suggestions            │
└──────────────â”Ŧ───────────────────────────────┘
               │
               â–ŧ
┌──────────────────────────────────────────────┐
│         FEEDBACK LOOP (Python)               │
│  Trains model on user preferences            │
└──────────────────────────────────────────────┘

đŸ› ī¸ Development

Prerequisites

  • Go 1.21+
  • Git
  • Python 3.10+ (for ML features)

Setup

# Clone repo
git clone https://github.com/AdeshDeshmukh/cortex.git
cd cortex

# Install dependencies
go mod download

# Run tests
make test

# Build
make build

# Run locally
./cortex --help

Testing

# Run all tests
make test

# Run with coverage
make coverage

# Run specific package
go test ./internal/git/

📁 Project Structure

cortex/
├── cmd/cortex/              # CLI entry point
│   ├── main.go
│   └── commands/            # Cobra commands
│       ├── root.go
│       ├── install.go
│       └── review.go
├── internal/                # Private application code
│   └── git/                 # Git integration
│       ├── hooks.go         # Hook management
│       ├── diff.go          # Diff parsing
│       └── *_test.go        # Tests
├── pkg/                     # Public libraries
│   └── types/               # Type definitions
│       └── types.go
├── go.mod                   # Go dependencies
├── Makefile                 # Build automation
└── README.md                # This file

đŸŽ¯ Roadmap

✅ Phase 1: Foundation (Current)

  • Git hook installation
  • Diff parsing
  • CLI framework
  • Test infrastructure

🚧 Phase 2: Intelligence (In Progress)

  • Static code analysis
  • LLM integration (local inference)
  • Prompt engineering
  • Suggestion generation

📅 Phase 3: Learning (Planned)

  • Feedback collection system
  • SQLite storage
  • RL training pipeline (DPO)
  • Model personalization

🔮 Phase 4: Advanced (Future)

  • Multi-language support expansion
  • IDE integration (VS Code, IntelliJ)
  • Team-wide model sharing
  • Custom rule definitions

🤝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'feat: add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Commit Convention

We follow Conventional Commits:

feat: New feature
fix: Bug fix
docs: Documentation changes
test: Test additions/changes
refactor: Code refactoring
chore: Maintenance tasks

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


🙏 Acknowledgments

  • Built with Cobra for CLI
  • Inspired by first-principles thinking
  • Part of ongoing learning journey in AI/ML systems

đŸ“Ŧ Contact

Adesh Deshmukh

⭐ If you find this project useful, please consider giving it a star! // test hook

Share this project:

Updates