Skip to content

navarathinam1803/AutoCommitAI

Repository files navigation

🧠 AutoCommitAI - Git Commit Message Generator

An intelligent Git commit message generator using AI to automatically create clear, conventional commit messages from your staged changes.

📝 Overview

Writing clear and consistent git commit messages is crucial for maintaining readable project history and collaboration. This project solves that by using AI to analyze your code changes and generate standardized, high-quality commit messages automatically.

⚙️ Tech Stack

Category Technology Used
Programming Language Node.js (TypeScript)
Framework NestJS
AI Engine OpenAI GPT-4o / GPT-4o-mini
Environment dotenv
Version Control Git diff output

🚀 Features

  • True Multi-Agent System: Specialized agents working in coordination
  • AI-Powered Analysis: Uses OpenAI's GPT models to understand code changes
  • Conventional Commits: Generates messages following conventional commit format
  • Dynamic Task Allocation: Agents adapt their workload based on complexity
  • Agent Negotiation: Agents can collaborate and refine each other's outputs
  • Rate Limiting: Built-in delays to respect OpenAI API limits
  • Error Handling: Robust error handling with fallback messages
  • Batch Processing: Handles multiple staged files efficiently
  • Comprehensive Logging: Detailed execution tracking and monitoring
  • Unit Testing: Comprehensive test suite for all agents and services
  • Performance Metrics: Processing time and confidence tracking
  • Extensible Architecture: Easy to add new agents and capabilities

🏗️ Architecture

Multi-Agent System (MAS) Design

The project implements a true Multi-Agent System with specialized agents working in coordination:

  1. GitService: Extracts staged changes from git
  2. PreprocessorAgent: Cleans and normalizes git diffs
  3. DiffAnalysisAgent: Analyzes code changes and determines change type
  4. SummaryAgent: Generates human-readable summaries
  5. FormatterAgent: Formats output as conventional commits
  6. MultiAgentService: Orchestrates the entire workflow
  7. OpenAIService: Handles AI model interactions

Agent Workflow

Git Staged Changes → PreprocessorAgent → DiffAnalysisAgent → SummaryAgent → FormatterAgent → Final Commit Message
                                    ↓
                              OpenAI API (for analysis and summary)

Agent Responsibilities

Agent Role Input Output
PreprocessorAgent Input Normalizer Raw git diffs Cleaned, structured diffs
DiffAnalysisAgent Change Analyzer Cleaned diffs Change type and analysis
SummaryAgent Natural Language Generator Analysis Human-readable summary
FormatterAgent Commit Composer Analysis + Summary Conventional commit message

🤖 Why Multi-Agent System?

The Problem with Single-Agent Approaches

Traditional single-agent systems suffer from several critical limitations:

  • Cognitive Overload: One agent must handle all aspects of commit message generation
  • Limited Specialization: No deep expertise in specific domains (preprocessing, analysis, formatting)
  • Brittle Architecture: Single point of failure affects the entire system
  • Poor Scalability: Difficult to add new capabilities or modify existing ones
  • Inconsistent Quality: Output quality varies based on the single agent's current state

MAS Advantages in Commit Message Generation

MAS Principle Application in Commit Generation Business Value
Specialization Each agent masters one aspect (preprocessing, analysis, formatting) Higher quality, more accurate commit messages
Modularity Agents can be updated independently without affecting others Easy maintenance and feature additions
Fault Tolerance If one agent fails, others can still provide partial results Improved system reliability
Scalability New agents can be added for specific needs (security analysis, performance impact) Future-proof architecture
Collaboration Agents can negotiate and refine each other's outputs Better decision-making through collective intelligence
Dynamic Allocation Workload distributed based on complexity and agent capabilities Optimal resource utilization

Real-World Benefits

  1. Quality Assurance: Multiple agents validate and refine outputs
  2. Adaptability: System can handle different types of changes (features, bugs, refactors)
  3. Maintainability: Clear separation of concerns makes debugging easier
  4. Extensibility: Easy to add new agents for specific requirements
  5. Transparency: Clear visibility into each step of the process
  6. Reliability: Redundancy and error handling at multiple levels

MAS vs. Single Agent Comparison

Aspect Single Agent Multi-Agent System
Code Quality Mixed, depends on prompt engineering Consistently high, specialized expertise
Maintainability Monolithic, hard to modify Modular, easy to update individual components
Debugging Difficult to isolate issues Clear agent-level debugging
Scalability Limited by single agent capacity Horizontally scalable
Error Handling Single point of failure Distributed error handling
Future Growth Requires complete rewrites Add new agents incrementally

🧪 Testing

Running Tests

# Run all tests
npm test

# Run only unit tests
npm run test:unit

# Run only agent tests
npm run test:agents

# Run only service tests
npm run test:services

# Run tests with coverage
npm run test:cov

# Run tests in watch mode
npm run test:watch

# Run all tests (unit + e2e)
npm run test:all

Test Coverage

The project includes comprehensive unit tests for:

  • Agent Classes: Individual agent functionality and error handling
  • Service Classes: Multi-agent orchestration and task allocation
  • Error Scenarios: Network failures, invalid inputs, edge cases
  • Integration Points: Agent-to-agent communication and negotiation

Test Structure

test/
├── agents/
│   ├── preprocessor.agent.spec.ts
│   ├── diff-analysis.agent.spec.ts
│   ├── summary.agent.spec.ts
│   └── formatter.agent.spec.ts
├── services/
│   ├── multi-agent.service.spec.ts
│   ├── git.service.spec.ts
│   └── openai.service.spec.ts
└── e2e/
    └── app.e2e-spec.ts

📦 Installation

Prerequisites

  • Node.js v18+ (recommended: v20+ for better performance)
  • npm or yarn package manager
  • Git installed and configured
  • OpenAI API key with sufficient credits
  • Internet connection for API calls
  • Git repository with staged changes

Environment Setup

1. System Requirements

Node.js Configuration:

# Check Node.js version
node --version  # Should be v18+

# Check npm version
npm --version   # Should be v8+

Git Configuration:

# Ensure git is installed and configured
git --version

# Configure git user (if not already done)
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

2. Project Setup

  1. Clone the repository:
git clone <repository-url>
cd AutoCommitAI
  1. Install dependencies:
npm install
# or
yarn install
  1. Environment Configuration: Create a .env file in the root directory:
# Required: OpenAI API Key
OPENAI_API_KEY=sk-your-openai-api-key-here

# Optional: Custom model configuration
OPENAI_MODEL=gpt-4o-mini

# Optional: Rate limiting configuration
RATE_LIMIT_DELAY=2000

# Optional: Debug mode
DEBUG_MODE=false

3. Common Environment Issues

Git Configuration Issues:

# If you get "fatal: not a git repository" error
git init
git add .
git commit -m "Initial commit"

# If you get permission errors
git config --global --unset credential.helper
git config --global credential.helper store

Network Access Issues:

  • Ensure firewall allows outbound HTTPS connections
  • Check corporate proxy settings if applicable
  • Verify OpenAI API access from your network

API Key Issues:

  • Verify API key is valid and has sufficient credits
  • Check API key permissions and rate limits
  • Ensure no extra spaces or characters in the key

Node.js Version Issues:

# If using nvm, switch to correct version
nvm use 20

# If using n, switch to correct version
n 20

🚀 Usage

Multi-Agent System (Recommended)

  1. Stage your changes:
git add .
  1. Run the multi-agent system:
npm run start:multi-agent
  1. Copy the generated message and use it in your commit:
git commit -m "feat: add user authentication with JWT tokens"

Single Agent System (Legacy)

  1. Stage your changes:
git add .
  1. Run the single-agent system:
npm start

Available Scripts

Command Description
npm run start:multi-agent Run the full multi-agent system
npm run start:multi-agent:dev Run multi-agent system in dev mode
npm start Run the legacy single-agent system
npm run start:dev Run single-agent system in development mode
npm run build Build the project
npm run lint Run ESLint
npm test Run tests

📁 Project Structure

src/
├── agents/
│   ├── diff-analysis.agent.ts    # Analyzes code changes
│   ├── formatter.agent.ts        # Formats conventional commits
│   ├── preprocessor.agent.ts     # Cleans and normalizes diffs
│   └── summary.agent.ts          # Generates human-readable summaries
├── services/
│   ├── git.service.ts            # Git operations
│   ├── openai.service.ts         # OpenAI API integration
│   └── multi-agent.service.ts    # Orchestrates the MAS workflow
├── app.module.ts                 # NestJS module configuration
├── main.ts                       # Single-agent entry point
└── main-multi-agent.ts           # Multi-agent system entry point

🧾 Example Output

Input

Staged changes in auth.service.ts and user.controller.ts

Generated Message

feat: add JWT authentication and user profile endpoints

🔧 Configuration

Environment Variables

Variable Description Required
OPENAI_API_KEY Your OpenAI API key Yes

Rate Limiting

The system includes built-in rate limiting with 5-second delays between API calls to respect OpenAI's rate limits.

🚧 Current Limitations

  • OpenAI Dependency: Requires OpenAI API key and internet connection
  • Rate Limits: Built-in delays to prevent API rate limit issues
  • Local LLM Support: Currently only supports OpenAI API (local LLM integration was attempted but removed)

🔮 Future Enhancements

  • Local LLM Support: Add support for local language models to reduce API dependency
  • Custom Templates: Allow project-specific commit message templates
  • GitHub Integration: Direct integration with GitHub for automated PR descriptions
  • Language Support: Multi-language commit message generation
  • Agent Monitoring: Add detailed logging and monitoring for each agent
  • Parallel Processing: Optimize agent execution for better performance
  • Custom Agent Types: Allow users to define custom agent behaviors

🛠️ Development

Running in Development Mode

npm run start:dev

Building for Production

npm run build
npm run start:prod

Linting

npm run lint

📊 Error Handling

The system includes comprehensive error handling:

  • API Errors: Graceful handling of OpenAI API failures
  • Git Errors: Proper error messages for git-related issues
  • Rate Limiting: Automatic delays to prevent API overuse
  • Fallback Messages: Default messages when AI generation fails

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests and linting
  5. Submit a pull request

📄 License

This project is licensed under the UNLICENSED license.

👨‍💻 Author

Navarathinam Cenrayan
Backend Developer (Node.js | NestJS | TypeScript)
Multi-Agent System Evaluation Project


This project was created as part of a multi-agent system evaluation and demonstrates AI-powered automation for developer workflows.

About

Writing clear, consistent, and conventional commit messages is tedious and often neglected. Poor commit messages make it difficult for teams to understand project history and changes.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors