{"id":22334830,"url":"https://github.com/zbiljic/kai","last_synced_at":"2026-05-06T07:35:49.694Z","repository":{"id":265207203,"uuid":"893565047","full_name":"zbiljic/kai","owner":"zbiljic","description":"Generate Git commit message using AI","archived":false,"fork":false,"pushed_at":"2025-03-19T04:00:22.000Z","size":38,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-19T05:19:27.506Z","etag":null,"topics":["ai","cli","commit","git","llm"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zbiljic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-24T19:06:09.000Z","updated_at":"2025-03-19T04:00:18.000Z","dependencies_parsed_at":"2025-03-09T11:33:17.386Z","dependency_job_id":null,"html_url":"https://github.com/zbiljic/kai","commit_stats":null,"previous_names":["zbiljic/kai"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbiljic%2Fkai","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbiljic%2Fkai/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbiljic%2Fkai/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbiljic%2Fkai/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zbiljic","download_url":"https://codeload.github.com/zbiljic/kai/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245615004,"owners_count":20644376,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","cli","commit","git","llm"],"created_at":"2024-12-04T05:09:58.140Z","updated_at":"2026-05-06T07:35:49.689Z","avatar_url":"https://github.com/zbiljic.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# kai\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/zbiljic/kai)](https://goreportcard.com/report/github.com/zbiljic/kai)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n`kai` is a command-line interface (CLI) tool that leverages Artificial Intelligence to automatically generate Git commit messages, pull request content, and even reorganize messy commit histories. It aims to streamline your development workflow by providing concise, relevant, and optionally Conventional Commit-formatted messages, allowing you to focus more on coding and less on crafting perfect commit messages or untangling commit history.\n\n## ✨ Features\n\n*   **AI-Powered Commit Message Generation (`gen`)**: Automatically creates commit messages by analyzing the diff of your staged Git changes.\n*   **AI-Powered Pull Request Content Generation (`prgen`)**: Generates titles and descriptions for pull requests by analyzing commits and diffs between branches.\n*   **AI-Powered Commit History Reorganization (`prprepare`)**: Analyzes your branch's full diff and uses AI to suggest and apply a clean, logical sequence of atomic commits, making code reviews easier.\n*   **Intelligent Fixup (`absorb`)**: Automatically creates `fixup!` commits for staged changes, targeting the most appropriate original commits.\n*   **Conventional Commits Support**: Generates commit messages adhering to the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification (e.g., `feat(scope): add new feature`).\n*   **Interactive Workflow**: Provides a selection of generated messages and allows interactive editing before committing. You can also quickly select an option by typing its corresponding number.\n*   **Intelligent Provider Selection**: Automatically detects and prioritizes available LLM providers based on configured API keys, falling back to others if a preferred one isn't configured.\n*   **Automatic Staging**: If no files are staged, `kai` can automatically stage all changes in tracked files before generating a message.\n*   **Contextual Commit History**: Can include previous commit messages for similar files (including those in parent directories) in the prompt, helping the AI generate more consistent and contextually relevant messages.\n*   **Multiple LLM Providers**: Supports various Large Language Model providers for flexibility:\n    *   [Phind](https://www.phind.com/) (Default fallback)\n    *   [OpenAI](https://openai.com/) (GPT-4o Mini, GPT-3.5 Turbo, etc.)\n    *   [Anthropic](https://www.anthropic.com/) (Claude 3 Haiku, etc.)\n    *   [Google AI](https://ai.google.dev/) (Gemini models)\n    *   [OpenRouter](https://openrouter.ai/) (various models, including MistralAI)\n    *   [Groq](https://groq.com/) (Llama models, Mixtral)\n    *   [DeepSeek](https://deepseek.com/) (DeepSeek Chat, DeepSeek Coder, etc.)\n*   **Go-powered**: Built with Go, offering a single, fast binary.\n\n## 🚀 Installation\n\n`kai` is a Go application. You'll need `Go 1.23+` installed on your system.\n\n### Using `go install`\n\nThe easiest way to install `kai` is using `go install`:\n\n```bash\ngo install github.com/zbiljic/kai@latest\n```\n\nEnsure that your `GOBIN` is in your system's `PATH` (e.g., `export PATH=$PATH:$(go env GOBIN)`) to run `kai` directly from your terminal.\n\n### Building from source\n\nAlternatively, you can clone the repository and build `kai` yourself. This method requires `make`.\n\n```bash\ngit clone https://github.com/zbiljic/kai.git\ncd kai\nmake install\n```\nThe `make install` command will compile the `kai` executable and place it in your `GOBIN` directory.\n\n## 💡 Usage\n\n`kai` is designed to be used within a Git repository.\n\n### Generate Commit Message (`gen`)\n\nThis command generates Git commit messages based on your staged changes.\n\n1.  **Stage your changes (or let `kai` do it):**\n    Before running `kai`, you usually stage your changes:\n    ```bash\n    git add .\n    ```\n    However, if you forget to stage, `kai` will automatically stage all changes in tracked files by default (similar to `git add .`) before attempting to generate a message.\n\n    To explicitly stage all changes and then generate a message, use the `--all` or `-a` flag:\n    ```bash\n    kai gen --all\n    # or\n    kai gen -a\n    ```\n\n2.  **Generate a commit message**:\n    Simply run `kai` or `kai gen` in your repository:\n    ```bash\n    kai\n    # or\n    kai gen\n    ```\n    `kai` will analyze your staged changes, automatically detect an available LLM provider, generate potential commit messages, and present them in an interactive prompt:\n\n    ```\n    ◆ Pick a commit message to use: (Ctrl+c to exit)\n      ● [1] feat: add new feature (e to edit)\n      ○ [2] fix: resolve bug\n      ○ [3] chore: update dependencies\n    ```\n\n    You can navigate through the suggestions using arrow keys. Press `Enter` to select a message.\n    It is also possible to quickly pick a message by typing the corresponding number (e.g., `1`, `2`, `3`) instead of using arrow keys.\n\n    Press `e` to edit the currently selected message interactively. If you choose to edit, `kai` will guide you through modifying the type, scope, and message body, especially useful for adhering to Conventional Commits.\n\n3.  **Commit**: Once you select or confirm a message, `kai` will automatically commit your staged changes with the chosen message.\n\n#### `gen` Options\n\n*   **Specify LLM Provider**: Use the `--provider` or `-p` flag to explicitly choose your desired LLM provider, overriding the automatic detection.\n    ```bash\n    kai gen --provider openai\n    kai gen -p googleai\n    ```\n    Available providers: `phind` (default fallback), `openai`, `claude`, `googleai`, `openrouter`, `groq`, `deepseek`.\n\n*   **Specify Model**: Use the `--model` or `-m` flag to explicitly choose a specific model for the selected provider.\n    ```bash\n    kai gen --provider openai --model gpt-4\n    kai gen -p googleai -m gemini-2.5-pro\n    ```\n\n*   **Specify Commit Message Type**: Use the `--type` or `-t` flag to set the desired commit message format.\n    ```bash\n    kai gen --type simple\n    kai gen -t conventional\n    ```\n    Available types: `conventional` (default), `simple`.\n    *   `conventional`: Generates messages adhering to the Conventional Commits specification (e.g., `type(scope): message`).\n    *   `simple`: Generates plain messages like `message`.\n\n*   **Include Previous Commit History**: By default, `kai` includes previous commit messages for relevant files (and their parent directories if no direct file history exists) to provide context to the AI. To disable this, use the `--history=false` flag:\n    ```bash\n    kai gen --history=false\n    ```\n\n*   **Number of Suggestions**: Use the `--count` or `-n` flag to specify how many commit message suggestions to generate (default is 2).\n    ```bash\n    kai gen --count 5\n    ```\n\n*   **Non-interactive Mode**: Use the `--yes` or `-y` flag to automatically use the first generated commit message without an interactive prompt.\n    ```bash\n    kai gen --yes\n    ```\n\n### Generate Pull Request Content (`prgen`)\n\nThe `prgen` command helps you automatically generate a title and description for your pull request (PR) or merge request (MR) by analyzing the commits and changes between your current branch and a specified base branch.\n\n```bash\nkai prgen [options]\n# or\nkai pr [options]\n```\n\nTo use it:\n\n1.  **Switch to your feature branch**: Ensure you are on the branch for which you want to create a PR.\n    ```bash\n    git checkout feature/my-new-feature\n    ```\n2.  **Run `kai prgen`**:\n    ```bash\n    kai prgen\n    ```\n    `kai` will then:\n    *   Compare your current branch with the default base branch (`main`).\n    *   Optionally ask for additional context about your changes.\n    *   Attempt to find and use a PR template in your repository.\n    *   Generate a PR title and description based on the commits and diff.\n    *   Display the generated content directly in your terminal.\n\n#### `prgen` Options\n\n*   **Specify LLM Provider**: Use the `--provider` or `-p` flag to explicitly choose your desired LLM provider, overriding the automatic detection.\n    ```bash\n    kai prgen --provider openai\n    kai prgen -p googleai\n    ```\n    Available providers: `phind` (default fallback), `openai`, `claude`, `googleai`, `openrouter`, `groq`, `deepseek`.\n\n*   **Specify Model**: Use the `--model` or `-m` flag to explicitly choose a specific model for the selected provider.\n    ```bash\n    kai prgen --provider openai --model gpt-4-turbo\n    kai prgen -p googleai -m gemini-pro\n    ```\n\n*   **Specify Base Branch**: Use the `--base` or `-b` flag to compare against a branch other than `main`.\n    ```bash\n    kai prgen --base develop\n    ```\n\n*   **Maximum Diff Size**: Use `--max-diff` to set a limit (in characters) on the size of the code diff sent to the LLM. Larger diffs consume more tokens and might be truncated by some models.\n    ```bash\n    kai prgen --max-diff 5000\n    ```\n    The default is 10000 characters.\n\n*   **No Additional Context Prompt**: Use `--no-context` to skip the interactive prompt for additional business or feature context. The AI will rely solely on the commit messages and code diff.\n    ```bash\n    kai prgen --no-context\n    ```\n\n### Reorganize Commit History (`prprepare`)\n\nThe `prprepare` command uses AI to analyze your current branch's entire diff against a base branch and suggest a reorganized, cleaner commit history. It helps you transform messy, large, or poorly structured commits into logical, atomic units, which significantly improves code review readability and maintainability.\n\n```bash\nkai prprepare [options]\n# or\nkai prp [options]\n```\n\nTo use it:\n\n1.  **Switch to your feature branch**: Ensure you are on the branch whose history you want to reorganize.\n    ```bash\n    git checkout feature/my-complex-feature\n    ```\n2.  **Run `kai prprepare`**:\n    ```bash\n    kai prprepare\n    ```\n    `kai` will then:\n    *   Analyze all changes between your current branch and the default base branch (`main`).\n    *   Parse the diff into individual \"hunks\" of changes.\n    *   Use an LLM to generate a proposed commit plan, detailing new commit messages and which specific hunks belong to each new commit.\n    *   Display the proposed plan for your review.\n    *   If confirmed, it will **reset your branch to the base branch** and then apply the new commits sequentially, rebuilding your history.\n\n    **Important**: This command rewrites your branch's history. It's recommended to have a backup or ensure your work is pushed before running it, especially without `--dry-run`. `kai` will create a temporary backup branch by default before applying changes if `--debug` or `--auto-apply` is not used.\n\n#### `prprepare` Options\n\n*   **Specify LLM Provider**: Use the `--provider` or `-p` flag to explicitly choose your desired LLM provider, overriding the automatic detection.\n    ```bash\n    kai prprepare --provider claude\n    kai prprepare -p deepseek\n    ```\n    Available providers: `phind` (default fallback), `openai`, `claude`, `googleai`, `openrouter`, `groq`, `deepseek`.\n\n*   **Specify Model**: Use the `--model` or `-m` flag to explicitly choose a specific model for the selected provider.\n    ```bash\n    kai prprepare --provider claude --model claude-3-opus-20240229\n    kai prprepare -p groq -m mixtral-8x7b-32768\n    ```\n\n*   **Specify Base Branch**: Use the `--base` or `-b` flag to compare against a branch other than `main`.\n    ```bash\n    kai prprepare --base feature/my-base\n    ```\n\n*   **Maximum Diff Size**: Use `--max-diff` to set a limit (in characters) on the total size of the code diff sent to the LLM for analysis. This helps manage token usage for very large diffs.\n    ```bash\n    kai prprepare --max-diff 20000\n    ```\n    The default is 10000 characters.\n\n*   **Automatically Apply**: Use `--auto-apply` to skip the confirmation prompt and immediately apply the generated commit reorganization plan. **Use with caution!**\n    ```bash\n    kai prprepare --auto-apply\n    ```\n\n*   **Dry Run**: Use `--dry-run` or `-n` to simulate the reorganization without making any actual changes to your repository. It will show the proposed plan and what `git` commands would be executed.\n    ```bash\n    kai prprepare --dry-run\n    ```\n\n*   **Debug Mode**: Use `--debug` to enable detailed logging and write each proposed commit's patch file to `.kai/prprepare/` in your repository. This implies `--dry-run` if used alone. Useful for inspecting the AI's hunk grouping and patch creation.\n    ```bash\n    kai prprepare --debug\n    ```\n    When debug is enabled, you can then manually apply the patches (e.g., `git apply --check --cached .kai/prprepare/001.patch`).\n\n### Absorb Staged Changes (`absorb`)\n\nThe `absorb` command helps you automatically create `fixup!` commits for staged changes, targeting the original commits that introduced those changes. This is useful for splitting out and organizing your work and for making small corrections to previous commits before a final rebase.\n\n```bash\nkai absorb [options]\n```\n\nAfter running `kai absorb`, you can execute `git rebase -i --autosquash` to automatically squash the `fixup!` commits into their respective targets.\n\n*   **Automatically Rebase**: Use `--and-rebase` or `-r` to automatically run `git rebase --autosquash` after creating fixups.\n    ```bash\n    kai absorb --and-rebase\n    ```\n*   **Dry Run**: Use `--dry-run` or `-n` to see what changes `absorb` would make without actually performing them.\n    ```bash\n    kai absorb --dry-run\n    ```\n*   **Backup Branch**: When using `--and-rebase`, use `--backup` or `-b` to create a backup branch (e.g., `backup/your-branch-HH-MM-SS`) before the rebase operation. This helps in recovery if the rebase fails or does not produce expected results. `kai` will check if an up-to-date backup exists and reuse it if possible.\n    ```bash\n    kai absorb --and-rebase --backup\n    ```\n*   **Stage All Changes**: Use `--all` or `-a` to automatically stage all changes in tracked files before analyzing for fixups.\n    ```bash\n    kai absorb --all\n    ```\n*   **Maximum History Lookback**: Use `--max-history` to specify how many commits back `absorb` should look when trying to find the original commit for a modified line (default is 20).\n    ```bash\n    kai absorb --max-history 50\n    ```\n\n## ⚙️ Configuration\n\n`kai` relies on environment variables for API keys to access LLM providers.\n\n**Automatic Provider Selection:** `kai` will automatically detect and prioritize LLM providers based on the presence of their respective API keys in your environment variables. The preferred order of detection (most preferred first) is:\n1.  **Google AI**: Requires `GEMINI_API_KEY`\n2.  **Groq**: Requires `GROQ_API_KEY`\n3.  **OpenRouter**: Requires `OPENROUTER_API_KEY`\n4.  **OpenAI**: Requires `OPENAI_API_KEY`\n5.  **Anthropic Claude**: Requires `ANTHROPIC_API_KEY`\n6.  **DeepSeek**: Requires `DEEPSEEK_API_KEY`\n7.  **Phind**: Does not require an API key (used as a last resort if others aren't configured).\n\nTo configure a provider, set the corresponding environment variable:\n\n*   **Google AI**:\n    ```bash\n    export GEMINI_API_KEY=\"your_google_ai_api_key\"\n    ```\n\n*   **Groq**:\n    ```bash\n    export GROQ_API_KEY=\"your_groq_api_key\"\n    ```\n\n*   **OpenRouter**:\n    ```bash\n    export OPENROUTER_API_KEY=\"your_openrouter_api_key\"\n    ```\n    With OpenRouter, it is also possible to set these for custom attribution in their API logs:\n    ```bash\n    export OPENROUTER_HTTP_REFERER=\"https://github.com/zbiljic/kai\"\n    export OPENROUTER_X_TITLE=\"kai\"\n    ```\n\n*   **OpenAI**:\n    ```bash\n    export OPENAI_API_KEY=\"your_openai_api_key\"\n    ```\n\n*   **Anthropic Claude**:\n    ```bash\n    export ANTHROPIC_API_KEY=\"your_anthropic_api_key\"\n    ```\n\n*   **DeepSeek**:\n    ```bash\n    export DEEPSEEK_API_KEY=\"your_deepseek_api_key\"\n    ```\n\n## 🤝 Contributing\n\nContributions are welcome! If you find a bug, have a feature request, or want to improve the codebase, please feel free to open an issue or submit a pull request.\n\n## 📄 License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## 🙏 Acknowledgements\n\n*   Inspired by other AI-powered commit tools and the need for a simple Go solution that allows easy message modification and robust LLM integration.\n*   Uses [go-clack](https://github.com/orochaa/go-clack) for interactive prompts.\n\n## Similar Projects\n\nHere are some other similar projects that you might find useful:\n\n*   [aicommits](https://github.com/Nutlope/aicommits): A CLI that writes your Git commit messages for you with AI. (TypeScript)\n*   [lumen](https://github.com/jnsahaj/lumen): Instant AI Git Commit message, Git changes summary from the CLI. (Rust)\n*   [prghost](https://github.com/fyvfyv/prghost): Tool that auto-generates PR descriptions from git diffs using AI and project guidelines. (TypeScript)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzbiljic%2Fkai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzbiljic%2Fkai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzbiljic%2Fkai/lists"}