How afonsoneto/ai-commit-message works
Project Type & Purpose
• This is a CLI-based Ruby gem aimed at enhancing git commits by analyzing staged changes, recent commit history, and the current branch name, before sending this context to an AI model for generating commit messages.
• Its primary function is to automate and improve git commit messaging using AI.
Key Components
a. Command-Line Interface (CLI):
• Represented by the executable script (bin/ai-commit-message) that serves as the entry point.
• It captures user commands like “commit” and “config”, and routes them to appropriate modules.
b. Library Modules:
• lib/ai-commit-message/cli.rb: Handles the command-line parsing and initiates the main workflow.
• lib/ai-commit-message/config_manager.rb: Manages configurations (reading from ~/.ai-commit-message.conf or interactive configuration updates).
• lib/ai-commit-message/suggester.rb: Implements the logic for gathering git status (staged changes, commit history, branch name), interfacing with the external AI model, and generating the commit message.
c. External Components:
• Git Infrastructure: The gem interacts with the Git environment (e.g., using “git diff --cached” to capture changes and reading the commit history).
• AI Model API: This external service (could be running locally via Ollama or a remote OpenAI-compatible endpoint) receives the contextual information and returns a commit message.
Relationships & Data Flow
• User invokes the gem through the CLI.
• The CLI layer (lib/ai-commit-message/cli.rb) parses the command and hands off processing.
• The Config Manager is consulted to load or update settings (API URL, model name).
• The Suggester module gathers all necessary git data (staged changes, commit history, branch name) then sends it to the external AI Model API.
• The AI Model API returns a commit message which is then displayed to the user via the CLI.
Architectural Patterns & Design Principles
• Separation of Concerns: Each module (CLI, Config Manager, Suggester) handles specific responsibilities.
• Modularity: Clear separation between configuration management, user interface, and business logic.
• External Integration: Dedicated pathway for communication with the external AI model.
Relevant Technologies & Frameworks
• Ruby (with Ruby 3.0+ as a requirement)
• Git (as the version control tool the gem enhances)
• External AI APIs (e.g., Ollama, OpenAI-compatible endpoints)
Summary
• Clear labels for “CLI Interface”, “Configuration Manager”, “Suggester Module”, “Git Interaction”, and “External AI API”.
• Optionally, include a note about using standard Ruby libraries and git commands for backend processes.