npm package: @heogeon0/lazy-ai
Description: AI-powered commit message generator using Google Gemini API, designed for seamless integration with Lazygit
Author: heogeon0
Latest version: 0.0.2

# lazy-ai

AI-powered commit message generator using Google Gemini API, designed for seamless integration with Lazygit.

## Features

- **AI-Powered**: Generates intelligent commit messages using Google Gemini API
- **Conventional Commits**: Follows standard commit format (feat, fix, chore, docs, etc.)
- **Lazygit Integration**: Works perfectly as a custom command in Lazygit
- **Multiple Suggestions**: Generate multiple commit message options to choose from
- **Multilingual**: Default language is Korean, customizable to other languages
- **Customizable Rules**: Add your own commit message rules

## Prerequisites

- Node.js 18 or higher
- Git repository
- Google Gemini API key ([Get it here](https://ai.google.dev/))
- (Optional) [Lazygit](https://github.com/jesseduffield/lazygit) for UI integration

## Installation

```bash
npm install -g @heogeon0/lazy-ai
```

## Configuration

### 1. Set up API Key and Model

After installation, configure your Gemini API key:

```bash
lazy-ai config
```

You'll be prompted to enter:

- **Gemini API key**: Your Google Gemini API key
- **Model** (optional): Default is `gemini-2.5-flash`

Example:

```
Enter your Google Gemini API key: YOUR_GEMINI_API_KEY_HERE
✓ API key saved
Enter model (default: gemini-2.5-flash):
✓ Model saved

Configuration completed!
```

### 2. Lazygit Integration (Recommended)

Add this custom command to your Lazygit configuration file:

**Config file location:**

- Linux/macOS: `~/.config/lazygit/config.yml`
- Windows: `%APPDATA%\lazygit\config.yml`

**Add this to your config:**

```yaml
customCommands:
  - key: "I"
    description: "AI commit message"
    command: 'git commit -m "{{.Form.Msg}}"'
    context: "files"
    prompts:
      - type: "menuFromCommand"
        title: "AI Commit Messages"
        key: "Msg"
        command: "lazy-ai g"
        filter: '^(?P<number>\d+)\.\s(?P<message>.+)$'
        valueFormat: "{{ .message }}"
        labelFormat: "{{ .number }}: {{ .message | green }}"
    output: log
```

## Usage

### Standalone CLI

1. **Stage your changes:**

   ```bash
   git add .
   ```

2. **Generate commit messages:**

   ```bash
   lazy-ai generate -n 5
   # or use the alias
   lazy-ai g -n 5
   ```

3. **Output example:**
   ```
   1. feat: AI 커밋 메시지 생성기 초기 기능 구현
   2. feat: Gemini API 통합 및 설정 관리자 추가
   3. refactor: 코드 구조 개선 및 타입 안정성 강화
   4. docs: README 및 사용 가이드 작성
   5. chore: 의존성 업데이트 및 빌드 설정
   ```

### With Lazygit

1. **Open Lazygit** in your repository:

   ```bash
   lazygit
   ```

2. **Stage your files** (use space to stage)

3. **Press `I`** (capital i) to trigger the AI commit message generator

4. **Select a commit message** from the generated options

5. **Done!** Your commit is created automatically

## Commands

### `lazy-ai config`

Configure API key and model settings.

### `lazy-ai generate [options]` (alias: `g`)

Generate AI-powered commit messages.

**Options:**

- `-n, --number <count>`: Number of commit messages to generate (default: 5)

**Example:**

```bash
lazy-ai g -n 3
```

## How It Works

```
┌─────────────────────────────────────────────┐
│  1. Stage files (git add)                   │
└────────────┬────────────────────────────────┘
             │
             ▼
┌─────────────────────────────────────────────┐
│  2. Extract git diff (git diff --cached)    │
└────────────┬────────────────────────────────┘
             │
             ▼
┌─────────────────────────────────────────────┐
│  3. Send to Gemini API with prompt rules    │
└────────────┬────────────────────────────────┘
             │
             ▼
┌─────────────────────────────────────────────┐
│  4. Parse AI response                       │
└────────────┬────────────────────────────────┘
             │
             ▼
┌─────────────────────────────────────────────┐
│  5. Display formatted commit messages       │
└─────────────────────────────────────────────┘
```

## Configuration Details

The configuration is stored locally using the `conf` library:

- **macOS**: `~/Library/Application Support/lazy-ai-nodejs/config.json`
- **Linux**: `~/.config/lazy-ai-nodejs/config.json`
- **Windows**: `%APPDATA%\lazy-ai-nodejs\config.json`

**Stored settings:**

- `apiKey`: Your Gemini API key
- `model`: AI model to use (default: `gemini-2.5-flash`)
- `language`: Output language (default: `ko`)
- `customRules`: Additional commit message rules

## Customization

### Change Output Language

Currently, the default language is Korean (`ko`). To use a different language, you can modify the language setting in your config file or add a CLI option for language selection.

### Custom Commit Rules

The tool follows Conventional Commits format by default:

- `feat:` - New feature
- `fix:` - Bug fix
- `chore:` - Maintenance tasks
- `docs:` - Documentation
- `refactor:` - Code refactoring
- `style:` - Code style changes
- `test:` - Adding tests

## Troubleshooting

### "Error: API key not configured"

Run `lazy-ai config` to set up your API key.

### "Error: No staged changes found"

Stage your files first with `git add <files>`.

### Lazygit custom command not working

1. Verify the config file location
2. Check YAML indentation (use spaces, not tabs)
3. Restart Lazygit after configuration changes

## Development

### Project Structure

```
src/
├── cli.ts          # CLI commands and entry point
├── ai.ts           # Gemini API integration
├── git.ts          # Git operations (diff extraction)
├── config.ts       # Configuration management
└── rules/
    └── output.ts   # AI prompt rules and formatting
```

## License

MIT

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

---

**Note**: This tool requires staged changes (`git add`) before generating commit messages. It analyzes the diff to create contextually relevant commit messages.