Skip to main content

🤖 AI-powered git commit message generator with repository context awareness

Project description

Smart Commit 🤖

An AI-powered git commit message generator with repository context awareness, built with Python and Typer.

Features

  • 🧠 AI-Powered: Uses OpenAI GPT models to generate meaningful commit messages
  • 📁 Repository Context: Analyzes your repo structure, tech stack, and recent commits
  • ⚙️ Configurable: Global and local configuration with conventional commit support
  • 🖥️ CLI Interface: Rich, interactive command-line interface with Typer
  • 🔧 MCP Agent: Model Context Protocol support for integration with AI assistants
  • 🎯 Smart Filtering: Ignore patterns and custom rules per repository
  • 📝 Interactive Editing: Edit generated messages before committing

Installation

Using uv (Recommended)

# Install uv if you haven't already
curl -LsSf https://astral.sh/uv/install.sh | sh

# Install and run as a tool (system-wide install)
uv tool install smart-commit-ai

# Use the tool in any repository
sc generate

Using pip

pip install smart-commit-ai

Quick Setup

# Quick setup with OpenAI
smart-commit setup --provider openai --model gpt-4o

# Or use the short alias
sc setup --provider openai --model gpt-4o

Usage

Generate Commit Messages

# Generate commit message for staged changes
smart-commit generate

# Add additional context
smart-commit generate --message "Fixes issue with user authentication"

# Auto-commit without confirmation
smart-commit generate --auto

# Dry run (generate message only)
smart-commit generate --dry-run

# Non-interactive mode
smart-commit generate --no-interactive

Configuration Management

# Initialize configuration
smart-commit config --init

# Edit configuration
smart-commit config --edit

# Show current configuration
smart-commit config --show

# Local repository configuration
smart-commit config --init --local

Repository Analysis

# Analyze current repository
smart-commit context

# Analyze specific repository
smart-commit context /path/to/repo

Configuration

Smart-commit supports both global and local configurations:

  • Global: ~/.config/smart-commit/config.toml
  • Local: .smart-commit.toml in your repository

Example Configuration

[ai]
provider = "openai"
model = "gpt-4o"
api_key = "your-api-key"
max_tokens = 500
temperature = 0.1

[template]
max_subject_length = 50
include_body = true
include_reasoning = true
conventional_commits = true

[template.custom_prefixes]
hotfix = "hotfix:"
wip = "wip:"

[repositories.my-project]
name = "my-project"
description = "My awesome project"
tech_stack = ["python", "react", "docker"]
ignore_patterns = ["*.log", "node_modules/**"]
context_files = ["README.md", "CHANGELOG.md"]

[repositories.my-project.commit_conventions]
breaking = "Use BREAKING CHANGE in footer for breaking changes"
scope = "Use scope in parentheses: feat(auth): add login"

Repository Context Features

Smart-commit automatically detects:

  • 📊 Technology Stack: Languages, frameworks, and tools
  • 🌿 Branch Information: Active branches and current branch
  • 📝 Recent Commits: Recent commit patterns for consistency
  • 📁 File Structure: Repository organization
  • 🔍 Project Metadata: README descriptions and project info

MCP Agent Integration

Smart-commit includes MCP (Model Context Protocol) support for integration with AI assistants:

from smart_commit.mcp import SmartCommitMCP

# Create MCP agent
agent = SmartCommitMCP()

# Get available tools
tools = agent.get_tools()

# Execute tools
response = agent.execute_tool("generate_commit_message", {
    "additional_context": "Fix critical security issue"
})

Available MCP Tools

  • analyze_repository: Analyze repository structure and context
  • generate_commit_message: Generate AI-powered commit messages
  • get_staged_changes: Get current staged changes
  • configure_smart_commit: Update configuration settings

Advanced Features

Custom Ignore Patterns

Add patterns to ignore specific files or changes:

[repositories.my-project]
ignore_patterns = [
    "*.log",
    "node_modules/**",
    "dist/**",
    "*.generated.*"
]

Context Files

Include specific files for additional context:

[repositories.my-project]
context_files = [
    "README.md",
    "CHANGELOG.md", 
    "docs/contributing.md"
]

Custom Commit Types

Define project-specific commit types:

[template.custom_prefixes]
hotfix = "hotfix:"
security = "security:"
deps = "deps:"

Examples

Basic Usage

# Stage your changes
git add .

# Generate commit message
smart-commit generate

With Context

# Generate with additional context
smart-commit generate -m "Resolves GitHub issue #123"

# Auto-commit
smart-commit generate --auto

# Verbose output
smart-commit generate --verbose

Repository Setup

# Initialize local config for your project
smart-commit config --init --local

# Analyze your repository
smart-commit context

Environment Variables

  • EDITOR: Preferred editor for interactive message editing (default: nano)

Development

# Install development dependencies
uv pip install -e ".[dev]"

# Run tests
pytest

# Format code
black smart_commit/
isort smart_commit/

# Type checking
mypy smart_commit/

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Run the test suite
  6. Create a pull request

License

MIT License - see LICENSE file for details.

Roadmap

  • Support for more AI providers (Anthropic Claude, etc.)
  • Plugin system for custom commit message formats
  • Integration with popular Git GUIs
  • Commit message templates and presets
  • Team/organization shared configurations
  • Webhook support for CI/CD integration
  • VS Code extension
  • Git hooks integration

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

smart_commit_ai-0.1.4.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

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

smart_commit_ai-0.1.4-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file smart_commit_ai-0.1.4.tar.gz.

File metadata

  • Download URL: smart_commit_ai-0.1.4.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for smart_commit_ai-0.1.4.tar.gz
Algorithm Hash digest
SHA256 66c70c284c3855b9019a344d9ffd7ec71754d96e3f158adca7744d809869f913
MD5 d0237878d4221768cf05488871dcb56c
BLAKE2b-256 1d89e561d35790b32023fca1ca15ad5cbe23c9750577db988c633746806e1437

See more details on using hashes here.

File details

Details for the file smart_commit_ai-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for smart_commit_ai-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d1790fe25285494beb833b6cd85b99ba19e68fd91cba8857ddbef3e812546dd3
MD5 fb5e1d35d1e417a6e2fda1514cb80ee9
BLAKE2b-256 3540aa080c7ec6dc7e0bddfd43a76319d71dc40dab042779bf09d54956f0fcf9

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