@elsikora/commitizen-plugin-commitlint-ai

中文文档
3.0.1发布于 2026/05/21MITTypeScriptESM + CJS近 30 天下载 1.3万

AI-powered Commitizen adapter with Commitlint integration

原始使用文档
文档目录15 节
  1. 📚 Table of Contents
  2. 📖 Description
  3. 🚀 Features
  4. 🛠 Installation
  5. 💡 Usage
  6. Basic Usage
  7. Quick Start
  8. Configuration Methods
  9. Commit Modes
  10. Advanced Features
  11. Commitlint Integration
  12. Troubleshooting
  13. 🛣 Roadmap
  14. ❓ FAQ
  15. 🔒 License

project-logo

🤖 Commitizen Plugin Commitlint AI

Transform your Git workflow with AI-powered commit messages that follow conventional standards and pass Commitlint validation every time

ElsiKora TypeScript Node.js npm Git OpenAI ESLint Prettier Vitest Rollup

📚 Table of Contents

📖 Description

Commitizen Plugin Commitlint AI revolutionizes the way developers write commit messages by combining the power of artificial intelligence with strict conventional commit standards. Built with clean architecture principles, this plugin seamlessly integrates with your existing Commitizen workflow to generate meaningful, context-aware commit messages that adhere to your project's Commitlint rules.

Whether you're working on a solo project or collaborating in a large team, this tool eliminates the cognitive overhead of crafting perfect commit messages while maintaining a consistent, high-quality Git history. Provider access, model catalogs, credential resolution, and runtime generation are centralized through @elsikora/ai-core.

The plugin intelligently analyzes your staged changes, understands the context of your modifications, and generates commit messages that not only follow the conventional format but also provide meaningful descriptions of the changes. With automatic validation and smart retry mechanisms, it ensures every commit message meets your project's standards.

🚀 Features

  • ✨ 🤖 AI-Powered Generation - Leverage AI-Core providers and model catalogs to create contextually relevant commit messages
  • ✨ ✅ Commitlint Integration - Automatically validates and fixes messages to comply with your project's Commitlint rules
  • ✨ 🔄 Smart Retry Mechanism - Intelligently retries generation and validation with configurable attempts
  • ✨ 🎯 Clean Architecture - Built with SOLID principles, dependency injection, and clear separation of concerns
  • ✨ 🌐 Multi-Provider Support - Choose any provider exposed by @elsikora/ai-core, including OpenAI, Anthropic, Google, Azure, AWS Bedrock, Cerebras, Vercel AI Gateway, or local Ollama models
  • ✨ 🛡️ Type-Safe - Fully typed with TypeScript for enhanced developer experience and reliability
  • ✨ ⚡ Flexible Configuration - Cosmiconfig support for easy setup via JSON, YAML, or JavaScript
  • ✨ 🔐 Secure API Key Handling - Environment variable support with session-based key input options
  • ✨ 📝 Manual Mode Fallback - Seamlessly switch to guided manual entry when needed
  • ✨ 🚀 Breaking Change Detection - Automatically identifies and documents breaking changes

🛠 Installation

# Install the plugin as a dev dependency
npm install --save-dev @elsikora/commitizen-plugin-commitlint-ai

# Initialize Commitizen with this adapter
npx commitizen init @elsikora/commitizen-plugin-commitlint-ai --save-dev --save-exact

# Install Commitlint (if not already installed)
npm install --save-dev @commitlint/cli @commitlint/config-conventional

# Create a commitlint config file
echo "export default { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js

💡 Usage

Basic Usage

Quick Start

# Stage your changes
git add .

# Run the AI-powered commit wizard
git cz
# or
npm run commit

Configuration Methods

The plugin supports multiple configuration approaches:

Credentials are resolved by AI-Core. Use the environment variable for the selected provider:

# .env file
OPENAI_API_KEY=sk-...
# or
ANTHROPIC_API_KEY=sk-ant-...
# or
GOOGLE_API_KEY=AIza...
# or (Azure OpenAI)
AZURE_OPENAI_API_KEY=https://your-resource.openai.azure.com|your-api-key|your-deployment-name
# or (AWS Bedrock)
AWS_BEDROCK_API_KEY=us-east-1|access-key-id|secret-access-key
# or (Ollama)
OLLAMA_API_KEY=localhost:11434|llama3.2
# or (Cerebras)
CEREBRAS_API_KEY=...
# or (Vercel AI Gateway)
AI_GATEWAY_API_KEY=...

2. Configuration File

AI provider/model configuration lives in .elsikora/ai-core.config.js:

export default {
    modules: {
        "commitlint-plugin-commitlint-ai": {
            provider: "openai",
            model: "gpt-4o",
            retries: 3,
            validationRetries: 3,
        },
    },
};

Commit mode and ticket extraction settings stay in .elsikora/commitlint-ai.config.js:

export default {
    mode: "auto",
    maxRetries: 3,
    validationMaxRetries: 3,
    ticket: {
        // auto | branch-lint | pattern | none
        source: "auto",
        // Used in "pattern" mode, and as fallback when configured
        pattern: "[a-z]{2,}-[0-9]+",
        patternFlags: "i",
        // preserve | lower | upper
        normalization: "preserve",
        // fallback | error (only for source: "branch-lint")
        missingBranchLintBehavior: "fallback",
    },
};

Ticket Source Configuration

You can control where ticket IDs are extracted from:

  • source: "branch-lint" - parse ticket by git-branch-lint template (branch-pattern)
  • source: "pattern" - parse ticket by local regex (ticket.pattern)
  • source: "auto" - try git-branch-lint first, then fallback to local regex
  • source: "none" - disable ticket extraction completely

When using source: "branch-lint" and branch-lint config is absent:

  • missingBranchLintBehavior: "fallback" - fallback to local regex
  • missingBranchLintBehavior: "error" - throw an error and stop

3. Package.json

{
    "elsikora": {
        "commitlint-ai": {
            "mode": "auto"
        },
        "ai-core": {
            "modules": {
                "commitlint-plugin-commitlint-ai": {
                    "provider": "anthropic",
                    "model": "claude-sonnet-4-5"
                }
            }
        }
    }
}

Commit Modes

Auto Mode (AI-Powered)

The AI analyzes your changes and generates appropriate commit messages:

$ git cz
✔ Using AI-powered commit mode...
✔ AI generated initial commit message
✔ AI generated commit message successfully!

┌─────────────────────────────────┐
│ Generated commit message:        │
├─────────────────────────────────┤
│ feat(auth): implement OAuth2    │
│                                 │
│ Added OAuth2 authentication     │
│ flow with JWT token support.    │
│ Includes refresh token logic    │
│ and secure session management.  │
│                                 │
│ BREAKING CHANGE: Auth API       │
│ endpoints have been updated     │
└─────────────────────────────────┘

✔ Do you want to proceed with this commit message? (Y/n)

Manual Mode

Guided commit message creation with validation:

$ git cz
✔ Using manual commit mode...
? Select commit type: (Use arrow keys)
❯ feat: A new feature ✨
  fix: A bug fix 🐛
  docs: Documentation only changes 📚
  style: Code style changes 🎨
  refactor: Code refactoring 📦
  perf: Performance improvements 🚀
  test: Adding tests 🚨

? Enter scope (optional): auth
? Enter commit subject: add login functionality
? Enter commit body (optional):
? Is this a breaking change? No

Advanced Features

Retry Configuration

export default {
    maxRetries: 5, // AI generation retries
    validationMaxRetries: 3, // Validation fix attempts
};

Provider-Specific Setup

Azure OpenAI:

AZURE_OPENAI_API_KEY=https://myresource.openai.azure.com|api-key|gpt-4-deployment

AWS Bedrock:

AWS_BEDROCK_API_KEY=us-west-2|AKIAIOSFODNN7EXAMPLE|wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

Ollama (Local):

# Default setup
OLLAMA_API_KEY=localhost:11434

# Custom model
OLLAMA_API_KEY=localhost:11434|codellama

Commitlint Integration

The plugin respects all your Commitlint rules:

// commitlint.config.js
export default {
    extends: ["@commitlint/config-conventional"],
    rules: {
        "type-enum": [2, "always", ["feat", "fix", "docs", "style", "refactor"]],
        "scope-case": [2, "always", "lower-case"],
        "subject-max-length": [2, "always", 72],
        "body-max-line-length": [2, "always", 100],
    },
};

Troubleshooting

Force Manual Mode

# Create manual mode marker
mkdir -p .elsikora
touch .elsikora/manual

Clear Configuration Cache

rm -rf .elsikora/commitlint-ai.config.*
rm -rf .elsikora/ai-core.config.*

🛣 Roadmap

Task / FeatureStatus
Core AI-powered commit generation✅ Done
Multi-provider support through AI-Core✅ Done
Commitlint rule integration✅ Done
Clean architecture implementation✅ Done
Automatic validation and fixing✅ Done
Environment variable support✅ Done
Cosmiconfig integration✅ Done
Interactive mode switching✅ Done
Breaking change detection✅ Done
AWS Bedrock and Azure OpenAI support✅ Done
Local Ollama model support✅ Done
Custom prompt templates🚧 In Progress
Multi-language commit messages🚧 In Progress
Git hook integration🚧 In Progress
VS Code extension🚧 In Progress
Team collaboration features🚧 In Progress
Commit message analytics🚧 In Progress
GitHub Copilot integration🚧 In Progress
Performance optimizations for monorepos🚧 In Progress

❓ FAQ

Q: Which AI providers are supported? A: Provider and model support comes from @elsikora/ai-core. The current AI-Core catalog includes OpenAI, Anthropic, Google, Azure OpenAI, AWS Bedrock, Cerebras, Vercel AI Gateway, and local Ollama models.

Q: How does the AI understand my code changes? A: The plugin analyzes your git diff, staged files, and file paths to understand the context. It then uses this information along with your Commitlint rules to generate appropriate conventional commit messages.

Q: Is my code sent to AI services? A: Only the git diff and file names are sent to generate accurate commit messages. Full source code files are not transmitted unless they appear in the diff. For sensitive projects, consider using Ollama for local processing.

Q: What happens if the AI service is unavailable? A: The plugin has a configurable retry mechanism with real-time status updates. If all retries fail, it automatically falls back to the guided manual mode, ensuring you can always create commits.

Q: Can I customize the commit message format? A: Yes! The plugin fully respects your Commitlint configuration. You can define custom types, scopes, and rules.

Q: How do I switch between AI and manual modes? A: When you run git cz, you'll be prompted to choose your mode. You can also set a default mode in the configuration or create a .elsikora/manual file to force manual mode.

Q: Is it safe to store API keys? A: Credential resolution is handled by AI-Core. Keys are read from provider environment variables or requested for the current session, and are not stored in Commitlint AI configuration files.

Q: Can I use this with my existing Commitizen setup? A: Absolutely! This is a drop-in replacement for other Commitizen adapters. It works seamlessly with your existing Commitlint configuration and Git workflow.

Q: What's the difference between generation and validation retries? A: Generation retries (maxRetries) handle AI service failures, while validation retries (validationMaxRetries) attempt to fix commit messages that don't pass Commitlint rules.

Q: How much does it cost to use? A: The plugin itself is free and open-source. You'll need to pay for API usage with your chosen AI provider, or use free local models with Ollama.

🔒 License

This project is licensed under MIT License - see LICENSE file for details.

版本与发布记录

@elsikora/commitizen-plugin-commitlint-ai 共发布 38 个版本,首次发布于 2025/03/03;过去 12 个月发布了 28 个版本。

版本发布日期距今
3.0.1latest2026/05/215 个月前
3.0.1-dev.1beta2026/05/215 个月前
3.0.0-dev.22026/05/215 个月前
3.0.02026/05/215 个月前
3.0.0-dev.12026/05/215 个月前
2.5.22026/05/205 个月前

关于 @elsikora/commitizen-plugin-commitlint-ai 的常见问题

@elsikora/commitizen-plugin-commitlint-ai 是什么?

AI-powered Commitizen adapter with Commitlint integration

如何安装 @elsikora/commitizen-plugin-commitlint-ai?

在项目目录运行 npm install @elsikora/commitizen-plugin-commitlint-ai,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:commitizen(^4.0.3)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@elsikora/commitizen-plugin-commitlint-ai 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@elsikora/commitizen-plugin-commitlint-ai 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@elsikora/commitizen-plugin-commitlint-ai 可以商用吗?

@elsikora/commitizen-plugin-commitlint-ai 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@elsikora/commitizen-plugin-commitlint-ai 的下载量有多少?

根据 npm 官方下载统计,@elsikora/commitizen-plugin-commitlint-ai 在 2026/10/14 – 2026/11/12 这 30 天内被下载 12,661 次,日均约 422 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@elsikora/commitizen-plugin-commitlint-ai 还在维护吗?

最新版本 3.0.1 发布于 2026/05/21(5 个月前);至今共发布 38 个版本,其中过去 12 个月发布了 28 个;首次发布于 2025/03/03。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。