# lazym

lazym is an AI-powered tool that automatically generates meaningful commit messages for your Git repositories.

*lazym is inspired by [jen-Ya/commitgpt](https://github.com/jen-Ya/commitgpt)*

## Features

- Generates commit messages based on staged changes
- Without the risk of leaking code snippets to external LLM services
- Integrates seamlessly with your Git workflow
- Uses advanced language models for intelligent message generation

## Requirements

- [Ollama](https://ollama.ai/) with [Llama 3.1:8b](https://ollama.com/library/llama3.1:8b) model
- Git (version 2.0 or higher)
- Python 3.7 or above

Command to pull Llama 3.1:8b model for Ollama:

```
$ ollama run llama3.1:8b
```

## Installation
To install lazym, follow these steps:

1. Ensure you have Python 3.7+ and pip installed on your system.
2. Install lazym using pip:

   ```
   pip install lazym
   ```

3. After installation, navigate to any Git repository and run the following command to set up the Git hook:

   ```
   lazym install
   ```

   This will install the necessary Git hook to enable automatic commit message generation.

## Usage

Once installed and set up, lazym works in two ways:

1. Automatically when you make a commit:
   Simply stage your changes as usual and run `git commit`. lazym will generate a commit message based on your staged changes.

2. Manually by running `lazym ci "<hints for LLM>"`:
   This command allows you to generate a commit message with additional context provided to the LLM.

After generating the commit message, you'll be presented with three options:

1. Accept and commit: Use the generated message as-is and commit.
2. Edit message: Modify the generated message before committing.
3. Cancel commit: Abort the commit process.

This allows you to benefit from the AI-generated suggestions while maintaining full control over your commit messages. When editing, you can start with the AI-generated message and make any necessary adjustments.

## Commands

- `lazym install`: Install the prepare-commit-msg hook in the current Git repository.
- `lazym uninstall`: Uninstall the prepare-commit-msg hook from the current Git repository.
- `lazym ci "<optional hints>"`: Generate a commit message with optional additional context.

## Configuration

lazym can be configured using a `config.ini` file located at `~/.config/lazym/config.ini`. The following options are available:

### [DEFAULT]

- `model`: The AI model to use for generating commit messages. 
  - Default: `"llama3.1:8b"`
  - Options:
    - Ollama models: Use the model name directly (e.g., `"llama3.1:8b"`, `"codellama:7b"`)
    - Groq models: Prefix with `"groq:"` (e.g., `"groq:mixtral-8x7b-32768"`, `"groq:llama2-70b-4096"`)

> [!NOTE]
> To use Groq models, you need to:
> 1. Sign up at [groq.com](https://groq.com) to get an API key
> 2. Set the `GROQ_API_KEY` environment variable with your API key

Example configurations:

```ini
[DEFAULT]
# Using local Ollama model
model = llama3.1:8b

# Using Groq for faster generation
model = groq:mixtral-8x7b-32768
```

- `message_format`: The format to apply to the generated commit message.
  - Default: `"lowercase"`
  - Options: 
    - `"lowercase"`: Converts the first character of the message to lowercase.
    - `"sentence case"`: Capitalizes the first character of each sentence.
    - Any other value will keep the original format as generated by the AI.

- `prompt`: The prompt template used to generate commit messages.
  - Must include the `{diff}` placeholder where the code changes should be inserted
  - Default: empty (uses built-in prompt)
  - You can customize this to match your team's commit message style

### Customizing Prompts

You can customize how lazym generates commit messages by providing your own prompt template. There are two ways to do this:

1. **Using `config.ini`:** Suitable for simple, one-line prompts. Specify the `prompt` option in your `config.ini` file. This method is ideal for straightforward prompts that don't require complex formatting or multiple lines.

   Example:
   ```ini
   [DEFAULT]
   prompt = "Generate a concise commit message for the following changes: {diff}"
   ```

2. **Using `prompt.txt`:** Suitable for more complex, multi-line prompts. Create a `prompt.txt` file in the `~/.config/lazym/` directory. If this file exists, its contents will override the `prompt` setting in `config.ini`. This method is ideal for detailed prompts that require specific formatting or guidelines.

   Example `prompt.txt`:
   ```
   Generate a conventional commit message for these changes.
   Format: <type>(<scope>): <description>
   Types: feat, fix, docs, style, refactor, test, chore
   Keep the message under 72 chars.

   Changes:
   {diff}
   ```

If no prompt is specified in either `config.ini` or `prompt.txt`, lazym will use its built-in prompt template that follows general Git best practices.
