git-ai 1.1.3

Git AI: Automates commit messages using ChatGPT. Stage your files, and Git AI generates the messages.
Documentation
# Git AI Process Flow Diagram

## High-Level Process Overview

```
┌─────────────────────────────────────────────────────────────────────────────────┐
│                           GIT AI COMMIT MESSAGE GENERATION                        │
├─────────────────────────────────────────────────────────────────────────────────┤
│                                                                                   │
│  ┌─────────────┐    ┌──────────────┐    ┌───────────────┐    ┌───────────────┐ │
│  │ git commit  │───▶│ Hook Trigger │───▶│ Diff Analysis │───▶│ AI Processing │ │
│  └─────────────┘    └──────────────┘    └───────────────┘    └───────────────┘ │
│         │                   │                    │                      │        │
│         ▼                   ▼                    ▼                      ▼        │
│  ┌─────────────┐    ┌──────────────┐    ┌───────────────┐    ┌───────────────┐ │
│  │   No Msg?   │    │ Parse Args   │    │ Parse Files   │    │ Multi-Step    │ │
│  │   Check     │    │ Load Config  │    │ Count Lines   │    │   Analysis    │ │
│  └─────────────┘    └──────────────┘    └───────────────┘    └───────────────┘ │
│                                                                         │        │
│                                                                         ▼        │
│  ┌─────────────────────────────────────────────────────────────────────────┐   │
│  │                          COMMIT MESSAGE GENERATED                        │   │
│  └─────────────────────────────────────────────────────────────────────────┘   │
│                                                                                   │
└─────────────────────────────────────────────────────────────────────────────────┘
```

## Detailed Multi-Step Analysis Flow

```
┌─────────────────────────────────────────────────────────────────────────────────┐
│                              MULTI-STEP ANALYSIS                                 │
├─────────────────────────────────────────────────────────────────────────────────┤
│                                                                                   │
│  Step 1: Parse Diff                                                              │
│  ┌─────────────────────────────────────────────────────────────────────────┐   │
│  │  diff --git a/src/auth.rs b/src/auth.rs                                 │   │
│  │  ┌──────────┐    ┌──────────┐    ┌──────────┐    ┌──────────┐         │   │
│  │  │  File 1  │    │  File 2  │    │  File 3  │    │  File N  │         │   │
│  │  │ auth.rs  │    │ test.rs  │    │ main.rs  │    │   ...    │         │   │
│  │  └──────────┘    └──────────┘    └──────────┘    └──────────┘         │   │
│  └─────────────────────────────────────────────────────────────────────────┘   │
│                                      │                                            │
│                                      ▼                                            │
│  Step 2: Analyze Each File                                                       │
│  ┌─────────────────────────────────────────────────────────────────────────┐   │
│  │  ┌────────────────┐  ┌────────────────┐  ┌────────────────┐            │   │
│  │  │   auth.rs      │  │   test.rs      │  │   main.rs      │            │   │
│  │  │ +89 -12 lines  │  │ +45 -0 lines   │  │ +5 -3 lines    │            │   │
│  │  │ category:source│  │ category:test  │  │ category:source│            │   │
│  │  │ summary: Add   │  │ summary: Add   │  │ summary: Update│            │   │
│  │  │ JWT auth       │  │ auth tests     │  │ imports        │            │   │
│  │  └────────────────┘  └────────────────┘  └────────────────┘            │   │
│  └─────────────────────────────────────────────────────────────────────────┘   │
│                                      │                                            │
│                                      ▼                                            │
│  Step 3: Calculate Impact Scores                                                 │
│  ┌─────────────────────────────────────────────────────────────────────────┐   │
│  │  File Impact Calculation:                                                │   │
│  │  ┌─────────────────────────────────────────────────────────────┐       │   │
│  │  │ auth.rs:  operation(0.3) + category(0.4) + lines(0.25) = 0.95│       │   │
│  │  │ test.rs:  operation(0.3) + category(0.2) + lines(0.15) = 0.65│       │   │
│  │  │ main.rs:  operation(0.2) + category(0.4) + lines(0.02) = 0.62│       │   │
│  │  └─────────────────────────────────────────────────────────────┘       │   │
│  └─────────────────────────────────────────────────────────────────────────┘   │
│                                      │                                            │
│                                      ▼                                            │
│  Step 4: Generate Candidates                                                     │
│  ┌─────────────────────────────────────────────────────────────────────────┐   │
│  │  Based on highest impact (auth.rs @ 0.95):                              │   │
│  │  ┌─────────────────────────────────────────────────────────────┐       │   │
│  │  │ 1. "Add JWT authentication system"          (Action-focused) │       │   │
│  │  │ 2. "auth: implement JWT token handling"     (Component)      │       │   │
│  │  │ 3. "New feature for authentication support" (Impact)         │       │   │
│  │  └─────────────────────────────────────────────────────────────┘       │   │
│  └─────────────────────────────────────────────────────────────────────────┘   │
│                                      │                                            │
│                                      ▼                                            │
│  Step 5: Select Best Candidate                                                   │
│  ┌─────────────────────────────────────────────────────────────────────────┐   │
│  │  Selected: "Add JWT authentication system"                               │   │
│  │  Reasoning: Source changes have highest impact (0.95) affecting core    │   │
│  │  security functionality. Total 3 files changed with 134 lines modified. │   │
│  └─────────────────────────────────────────────────────────────────────────┘   │
│                                                                                   │
└─────────────────────────────────────────────────────────────────────────────────┘
```

## Fallback Strategy Flow

```
┌─────────────────────────────────────────────────────────────────────────────────┐
│                              FALLBACK STRATEGY                                    │
├─────────────────────────────────────────────────────────────────────────────────┤
│                                                                                   │
│  ┌───────────────────┐                                                          │
│  │ Multi-Step OpenAI │                                                          │
│  │   (Primary)       │                                                          │
│  └─────────┬─────────┘                                                          │
│            │                                                                      │
│            ▼                                                                      │
│  ┌─────────────────┐     Success    ┌─────────────────┐                        │
│  │   API Call?     ├───────────────▶│ Generate Message│                        │
│  └────────┬────────┘                └─────────────────┘                        │
│           │ Fail                                                                 │
│           ▼                                                                      │
│  ┌───────────────────┐                                                          │
│  │ Local Multi-Step  │                                                          │
│  │  (Fallback 1)     │                                                          │
│  └─────────┬─────────┘                                                          │
│            │                                                                      │
│            ▼                                                                      │
│  ┌─────────────────┐     Success    ┌─────────────────┐                        │
│  │ Local Analysis? ├───────────────▶│ Generate Message│                        │
│  └────────┬────────┘                └─────────────────┘                        │
│           │ Fail                                                                 │
│           ▼                                                                      │
│  ┌───────────────────┐                                                          │
│  │ Single-Step API   │                                                          │
│  │  (Fallback 2)     │                                                          │
│  └─────────┬─────────┘                                                          │
│            │                                                                      │
│            ▼                                                                      │
│  ┌─────────────────┐     Success    ┌─────────────────┐                        │
│  │  Final Try?     ├───────────────▶│ Generate Message│                        │
│  └────────┬────────┘                └─────────────────┘                        │
│           │ Fail                                                                 │
│           ▼                                                                      │
│  ┌─────────────────┐                                                            │
│  │   Error Exit    │                                                            │
│  └─────────────────┘                                                            │
│                                                                                   │
└─────────────────────────────────────────────────────────────────────────────────┘
```

## File Category Impact Weights

```
┌─────────────────────────────────────────────────────────────────────────────────┐
│                           FILE CATEGORY WEIGHTS                                   │
├─────────────────────────────────────────────────────────────────────────────────┤
│                                                                                   │
│  source   ████████████████████████████████████████████████████████  1.0         │
│  config   ████████████████████████████████████████████             0.8         │
│  build    ███████████████████████████████████████                  0.7         │
│  test     ██████████████████████████████                           0.6         │
│  docs     ████████████████████                                     0.4         │
│  binary   █████                                                     0.1         │
│                                                                                   │
│  Operation Type Weights:                                                          │
│  added    ███████████████  0.3                                                  │
│  deleted  ████████████     0.25                                                 │
│  modified ██████████       0.2                                                  │
│  renamed  █████            0.1                                                  │
│  binary   ██               0.05                                                 │
│                                                                                   │
└─────────────────────────────────────────────────────────────────────────────────┘
```

## Performance Timeline

```
┌─────────────────────────────────────────────────────────────────────────────────┐
│                           EXECUTION TIMELINE                                      │
├─────────────────────────────────────────────────────────────────────────────────┤
│                                                                                   │
│  0ms     100ms    200ms    300ms    400ms    500ms    600ms    700ms    800ms  │
│  │        │        │        │        │        │        │        │        │      │
│  ├────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┤      │
│  │                                                                         │      │
│  │▓▓▓│ Hook Init (50ms)                                                   │      │
│  │   │▓▓▓▓▓│ Parse Diff (80ms)                                           │      │
│  │         │▓▓▓▓▓▓▓▓▓▓│ File Analysis (150ms)                           │      │
│  │                     │▓▓▓▓│ Score Calc (60ms)                         │      │
│  │                          │▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓│ API Call (250ms)        │      │
│  │                                             │▓▓│ Write (30ms)         │      │
│  │                                                │                      │      │
│  │                                                                         │      │
│  Total: 620ms                                                             │      │
│                                                                                   │
└─────────────────────────────────────────────────────────────────────────────────┘
```

## Data Flow Through Components

```
┌─────────────────────────────────────────────────────────────────────────────────┐
│                              DATA FLOW                                            │
├─────────────────────────────────────────────────────────────────────────────────┤
│                                                                                   │
│  Git Diff Input                                                                  │
│  ┌─────────────┐                                                                │
│  │ Raw Diff    │                                                                │
│  │ Text        │                                                                │
│  └──────┬──────┘                                                                │
│         │                                                                         │
│         ▼                                                                         │
│  ┌─────────────┐     ParsedFile struct                                         │
│  │ Diff Parser ├────────────────────┐                                          │
│  └─────────────┘                    │                                          │
│                                      ▼                                          │
│                              ┌───────────────┐                                  │
│                              │ path: String  │                                  │
│                              │ operation: Op │                                  │
│                              │ diff: String  │                                  │
│                              └───────┬───────┘                                  │
│                                      │                                          │
│         ┌────────────────────────────┼────────────────────────────┐            │
│         ▼                            ▼                            ▼            │
│  ┌─────────────┐            ┌─────────────┐              ┌─────────────┐      │
│  │  Analyzer   │            │   Scorer    │              │  Generator  │      │
│  └──────┬──────┘            └──────┬──────┘              └──────┬──────┘      │
│         │                           │                             │             │
│         ▼                           ▼                             ▼             │
│  FileAnalysisResult          FileWithScore               CommitCandidate       │
│  ┌───────────────┐          ┌───────────────┐           ┌───────────────┐     │
│  │ lines_added   │          │ impact_score  │           │ message: str  │     │
│  │ lines_removed │          │ file_category │           │ reasoning: str│     │
│  │ file_category │          │ summary       │           │ score: f32    │     │
│  │ summary       │          └───────────────┘           └───────────────┘     │
│  └───────────────┘                                                             │
│                                                                                   │
└─────────────────────────────────────────────────────────────────────────────────┘
```