# Ai Commit **Repository Path**: wangshuyu/ai-commit ## Basic Information - **Project Name**: Ai Commit - **Description**: 使用大模型AI自动写git提交备注 - **Primary Language**: NodeJS - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-09-28 - **Last Updated**: 2026-10-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # AI Commit (shuyu - AI Commit) A lightweight VS Code extension that automatically analyzes your local Git changes using Large Language Models (LLMs) and generates standardized Chinese Conventional Commits messages directly into the Source Control input box (**fill only, never auto-commit**). **Repository**: [https://gitee.com/wangshuyu/ai-commit](https://gitee.com/wangshuyu/ai-commit) --- ## 💡 Code Workflow & Mechanics Based strictly on [src/extension.ts](file:///e:/Gitee/ai-commit/src/extension.ts): 1. **Git Integration**: Leverages VS Code's built-in Git extension (`vscode.git`) to access the active workspace repository. 2. **Two-Stage Diff Extraction**: - **Working Tree First**: Runs `repo.diff(false)` to capture unstaged modifications directly; - **Staged Fallback**: If unstaged changes are empty, checks `repo.diff(true)` for staged changes; - **Truncation Safety**: Slices diff to the first 6,000 characters to prevent context overflow. 3. **Prompt Specification**: - Output language: Simplified Chinese; - Follows **Conventional Commits** format (`feat: ...`, `fix: ...`, `refactor: ...`); - Returns commit text only, without markdown fences or pleasantries. 4. **State & Request Handling**: - Sets context `gitAiCommit.isGenerating = true` to replace the action button with a spinning spinner (`$(loading~spin)`) during generation; - Sends standard OpenAI-compatible `/chat/completions` request (`temperature: 0.1`); - Automatically injects OpenRouter headers if `openrouter.ai` is detected in the endpoint; - Sets `repo.inputBox.value = message` and resets status in `finally`. --- ## ⚙️ Configuration Search `gitAiCommit` (or `AI Commit`) in VS Code Settings: | Key | Type | Default | Description | | :--- | :--- | :--- | :--- | | `gitAiCommit.apiUrl` | `string` | `https://api.openai.com/v1/chat/completions` | Full endpoint URL (OpenAI-compatible) | | `gitAiCommit.apiKey` | `string` | `""` | API Key (can be empty for `localhost` / `127.0.0.1`) | | `gitAiCommit.model` | `string` | `""` | Model name (e.g. `gpt-4o-mini`, `deepseek-chat`, `Qwen/Qwen2.5-Coder-7B-Instruct`) | | `gitAiCommit.prompt` | `string` | Built-in Chinese Conventional Commits template | Custom prompt template. Supports `{diff}` placeholder (appends diff if omitted). | --- ## 📦 Installation & Usage ### Install via VSIX 1. Package or obtain `shuyu-ai-commit-1.0.6.vsix`; 2. Open VS Code, press `Ctrl + Shift + P` -> choose **`Extensions: Install from VSIX...`**; 3. Select `shuyu-ai-commit-1.0.6.vsix` to install. ### Usage 1. Make code changes in your workspace; 2. Open the **Source Control** panel; 3. Click the **✨ (AI Generate Commit Message)** button above the input box; 4. Review the generated message and commit manually.