3 releases

new 0.1.2 Mar 31, 2025
0.1.1 Mar 30, 2025
0.1.0 Mar 29, 2025

#8 in #commit

Download history 56/week @ 2025-03-24

56 downloads per month

MIT license

53KB
1K SLoC

AIC: AI Commit Message Generator

MIT licensed Crates.io codecov

A CLI tool that uses AI to generate meaningful commit messages by analyzing your staged Git changes.

Features

  • 🤖 AI-Powered: Automatically generates detailed and context-aware commit messages
  • ✏️ Interactive Mode: Review and edit generated messages before committing
  • 🔌 Multiple AI Providers: Works with OpenAI and compatible APIs
  • ⚙️ Customizable: Configure prompts, models, and API endpoints

Installation

cargo install aic

Quick Start

  1. Configure your API settings:
# For OpenAI
aic config setup --api-token your_openai_token --api-base-url https://api.openai.com --model gpt-3.5-turbo

# For DeepSeek
aic config setup --api-token your_deepseek_token --api-base-url https://api.deepseek.com --model deepseek-chat

Output:

⚙️  Updating configuration...
 Set api_token to: your•••••
 Set api_base_url to: https://api.openai.com
 Set model to: gpt-3.5-turbo
🎉 Configuration updated successfully!
  1. Verify your configuration:
aic config list

Output:

⚙️  Current Configuration:
┌───────────────┬──────────────────────────────────────┐
│ api_token     │ your•••••                            │
│ api_base_url  │ https://api.openai.com               │
│ model         │ gpt-3.5-turbo                        │
│ system_prompt │ You are an expert at writing...      │
│ user_prompt   │ Here is the git diff of the staged...│
└───────────────┴──────────────────────────────────────┘

📁 Configuration file location:
   /home/user/.config/aic/config.toml
  1. Test your API connection:
aic ping

Output:

🔍 Testing API connection...
🌐 API Base URL: https://api.openai.com
🤖 Model: gpt-3.5-turbo
✅ API connection successful!
✨ Configuration is working correctly.
  1. Generate commit messages:
# Stage changes and generate commit message
aic -a

# Generate and commit automatically
aic -ac

# Generate commit message (with staged changes)
aic

Example output:

╭─────────────────────────────────────╮
│     AI Commit Message Generator     │
╰─────────────────────────────────────╯
📦 Staging all changes...
🔍 Analyzing staged changes...
🤖 Using model: gpt-3.5-turbo
✨ Generating commit message...
📋 Commit command:
git commit -m "feat: add new feature X"

Execute this commit? [Y/m/n]:

Usage

Basic Commands

# Generate commit message (requires staged changes)
aic

# Stage all changes and generate commit message
aic -a

# Generate and commit automatically
aic -c

# Stage all changes and commit automatically
aic -ac

# Test API connection
aic ping

Note: The -a flag will stage ALL changes in your working directory with git add .. The -c flag will commit directly without confirmation. Use these flags with caution, especially in repositories with multiple changes.

Configuration Management

# Quick setup
aic config setup --api-token <TOKEN> --api-base-url https://api.openai.com --model gpt-4-turbo

# View current settings
aic config list

# Get specific setting
aic config get api_token

# Update setting
aic config set model gpt-4-turbo
aic config set default_prompt "Write detailed commit messages"

Configuration Options

  • api_token: Your API authentication token
  • api_base_url: API endpoint (default: OpenAI)
  • model: AI model to use (default: gpt-3.5-turbo)
  • system_prompt: System prompt that defines the AI's role and commit message format
  • user_prompt: User prompt that provides context about the git changes

Environment Variables

  • EDITOR: Preferred editor for modifying commit messages
    • Falls back to: vim → vi → nano

Examples

Basic Usage

# Stage changes and generate commit message
git add .
aic

# Stage and commit automatically
aic -ac

Configuration Examples

# Set up OpenAI
aic config setup --api-token sk-... --model gpt-4-turbo

# Set up DeepSeek
aic config setup --api-token ds-... --api-base-url https://api.deepseek.com --model deepseek-chat

# Customize commit message style
aic config set system_prompt "You are an expert at writing clear and concise commit messages..."
aic config set user_prompt "Here is the git diff of the staged changes. Generate a commit message..."

Troubleshooting

  1. No Changes Detected

    • Ensure changes are staged with git add
    • Check if you're in a git repository
  2. API Errors

    • Verify your API token is set correctly
    • Check API endpoint accessibility
    • Confirm you have sufficient API credits
  3. Editor Issues

    • Set your preferred editor: export EDITOR=vim
    • Ensure the editor is installed and accessible

Contributing

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

License

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

References

Dependencies

~11–23MB
~291K SLoC