opencommit

repository·master·Indexed 27 days ago

https://github.com/di-sukharev/opencommit

An AI-powered tool to automate and standardize commit message generation. It integrates with commitlint to ensure messages follow project-specific rules and provides a CLI (oco) for managing configurations, AI providers (including OpenAI, Anthropic, and local options like Ollama), and Git hooks. Version 3.3.9.

Tokens
4.9K
Snippets
8
Records
37
Agent score
92%

What's inside opencommit

  1. Use the @commitlint module for opencommit

    master

    The @commitlint module allows opencommit to generate commit messages that strictly adhere to your existing commitlint configuration.

    Key features include:

    • Automatic Configuration Loading: It loads your commitlint configuration directly from your project tree.
    • Rule-Based Prompting: It infers specific prompts for each individual commitlint rule to ensure compliance.
    • AI-Driven Consistency: It uses OpenAI to generate commit messages that maintain consistency with the embedded commitlint rules.
    • Smart Execution: The generation process will not run if the commit hash remains the same.
    • Configuration Locality: The module stores its configuration near your existing commitlint configuration files.
    • Prompt Replacement: It replaces the standard conventional-commit prompt with a specialized commitlint prompt to enforce your specific project standards.
  2. Setup local AI with Ollama

    master

    To use Ollama as your provider in OpenCommit, follow these steps:

    1. Install Ollama: Download from https://ollama.ai/download.
    2. Pull a model: Run ollama pull <model_name> (e.g., ollama pull llama3:8b).
    3. Start the server: Run ollama serve.
    4. Configure OpenCommit: Run the setup command and select Ollama as your provider. The wizard will attempt to detect your local models and ask for the Ollama URL (default is http://localhost:11434).
  3. Configure OpenCommit settings via CLI

    master

    You can manage your OpenCommit configuration using the oco config command. The tool supports three modes: set to update configuration values, get to retrieve current settings, and describe to view available options.

    Configuration is stored in a global file at ~/.opencommit (INI format) and can be overridden by a .env file in your current working directory.

    To set a configuration value, use the set command with key-value pairs. For example, to set your API key and provider:

    oco config set OCO_API_KEY=your_key OCO_AI_PROVIDER=openai
  4. Configure commit message templates

    master

    You can use custom message templates by providing an argument that contains the OCO_MESSAGE_TEMPLATE_PLACEHOLDER (defined in your configuration). The tool will replace this placeholder with the AI-generated commit message.

    For example, if your configuration defines a placeholder, you can pass a string like "feat: ${OCO_MESSAGE_TEMPLATE_PLACEHOLDER}" as an extra argument to ensure all generated messages follow a specific prefix pattern.

  5. Configure OpenCommit via environment variables

    master

    The OpenCommit configuration is stored in a global config file. When running the setup wizard, the following configuration keys are populated. You can also use these keys to understand the structure of the configuration:

    KeyDescription
    OCO_AI_PROVIDERThe selected AI provider (e.g., openai, anthropic, ollama, mlx, llamacpp)
    OCO_API_KEYThe API key for your provider (or a placeholder for local providers like ollama)
    OCO_MODELThe specific model name to use (e.g., gpt-4o, llama3:8b)
    OCO_API_URLThe base URL for the provider's API (required for local providers like Ollama or llama.cpp)
  6. Configure OpenCommit hook behavior via config

    master

    The prepareCommitMessageHook behavior is influenced by the following configuration settings:

    • OCO_API_KEY: Required for generating commit messages. If missing, the hook will exit with an error message instructing you to set it via oco config set OCO_API_KEY=<value>.
    • OCO_HOOK_AUTO_UNCOMMENT: Controls how the generated message is written to the commit file.
      • When true, the generated message is written without comment characters (#).
      • When false, the message is commented out with a header/footer block, allowing you to manually edit/uncomment it in your git editor.
  7. Fetch available models for a specific provider

    master

    Use fetchModelsForProvider to retrieve a list of available model IDs from a given AI provider. This function attempts to fetch live data from the provider's API, but falls back to a local cache or a hardcoded list if the request fails or if no API key is provided.

    Supported providers include:

    • openai
    • ollama
    • llamacpp
    • anthropic
    • gemini
    • groq
    • mistral
    • deepseek
    • aimlapi
    • openrouter

    Note: For ollama and llamacpp, you can provide a baseUrl. For providers requiring authentication, you must provide an apiKey to fetch live models instead of the fallback list.

  8. Format Errors for End-Users

    master

    OpenCommit provides utilities to transform raw errors into user-friendly, actionable structures and styled strings.

    formatUserFriendlyError

    Converts an error into a FormattedError object containing a title, message, helpUrl (if applicable), and a suggestion.

    import { formatUserFriendlyError } from './utils/errors';
    
    const formatted = formatUserFriendlyError(error, 'openai');
    // Returns: { title, message, helpUrl, suggestion }

    printFormattedError

    Takes a FormattedError object and returns a string styled with chalk (red for errors, cyan for help, yellow for suggestions) suitable for CLI output.

    import { formatUserFriendlyError, printFormattedError } from './utils/errors';
    
    const formatted = formatUserFriendlyError(error, 'anthropic');
    console.log(printFormattedError(formatted));