From 80c99d564c85727e4217dc3699b1f0ec91c45a74 Mon Sep 17 00:00:00 2001 From: yangmanqing Date: Sat, 14 Feb 2026 16:35:51 +0800 Subject: [PATCH 1/2] feat: add support for refining existing commit messages The changes enable the AI to improve upon an already-filled commit message rather than generating from scratch, allowing users to iteratively optimize their commit messages. --- src/commands/generateCommitMessage.ts | 9 ++++++++- src/git/gitService.ts | 5 +++++ src/prompt/commitPrompt.ts | 8 +++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/commands/generateCommitMessage.ts b/src/commands/generateCommitMessage.ts index 198a66c..06f7f0a 100644 --- a/src/commands/generateCommitMessage.ts +++ b/src/commands/generateCommitMessage.ts @@ -55,12 +55,19 @@ export async function generateCommitMessage(): Promise { }, async () => { try { + const currentMessage = gitService.getCommitMessage().trim(); const response = await provider.chatCompletion( { model: config.model, messages: [ { role: "system", content: buildSystemPrompt(config.language) }, - { role: "user", content: buildUserPrompt(diff) }, + { + role: "user", + content: buildUserPrompt( + diff, + currentMessage || undefined + ), + }, ], }, config.apiKey, diff --git a/src/git/gitService.ts b/src/git/gitService.ts index d17abe6..3d9feb5 100644 --- a/src/git/gitService.ts +++ b/src/git/gitService.ts @@ -53,6 +53,11 @@ export class GitService { return diff; } + getCommitMessage(): string { + const repo = this.getRepository(); + return repo.inputBox.value; + } + setCommitMessage(message: string): void { const repo = this.getRepository(); repo.inputBox.value = message; diff --git a/src/prompt/commitPrompt.ts b/src/prompt/commitPrompt.ts index f8fdb7f..42380aa 100644 --- a/src/prompt/commitPrompt.ts +++ b/src/prompt/commitPrompt.ts @@ -40,7 +40,13 @@ Available types: Respond with ONLY the commit message, nothing else. No quotes, no markdown, no explanation.`; } -export function buildUserPrompt(diff: string): string { +export function buildUserPrompt( + diff: string, + currentMessage?: string +): string { const truncated = truncateDiff(diff); + if (currentMessage) { + return `The current commit message is:\n\n${currentMessage}\n\nOptimize and refine this commit message based on the staged changes below. Keep the original intent but improve clarity, accuracy, and adherence to Conventional Commits format.\n\n\`\`\`diff\n${truncated}\n\`\`\``; + } return `Generate a commit message for the following staged changes:\n\n\`\`\`diff\n${truncated}\n\`\`\``; } From 002a9ffa7cb701086ae18c74b03623ade3b9449c Mon Sep 17 00:00:00 2001 From: yangmanqing Date: Sat, 14 Feb 2026 16:40:16 +0800 Subject: [PATCH 2/2] docs: add Chinese README translation --- README.md | 3 ++ README_zh.md | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 README_zh.md diff --git a/README.md b/README.md index 711ded6..4c79b88 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Lorebyte +[English](README.md) | [中文](README_zh.md) + AI-powered git commit message generator for VS Code. Lorebyte reads your staged changes, sends the diff to an LLM, and writes a [Conventional Commits](https://www.conventionalcommits.org/) message directly into the Source Control input box — one click, done. @@ -7,6 +9,7 @@ Lorebyte reads your staged changes, sends the diff to an LLM, and writes a [Conv ## Features - **One-click commit messages** — click the Lorebyte icon in the Source Control title bar or run the command from the palette +- **Smart generation** — if the commit input box is empty, generates a message from scratch; if it already contains text, refines and optimizes the existing message based on the staged diff - **Conventional Commits** — generates messages following the `(): ` format - **Chinese / English** — commit messages can be generated in Chinese or English - **Model selection** — browse and switch between available models via API diff --git a/README_zh.md b/README_zh.md new file mode 100644 index 0000000..45ea263 --- /dev/null +++ b/README_zh.md @@ -0,0 +1,94 @@ +# Lorebyte + +[English](README.md) | [中文](README_zh.md) + +基于 AI 的 VS Code Git 提交信息生成器。 + +Lorebyte 读取你的暂存更改,将 diff 发送给 LLM,然后将符合 [Conventional Commits](https://www.conventionalcommits.org/) 规范的提交信息直接写入源代码管理输入框 — 一键搞定。 + +## 功能特性 + +- **一键生成** — 点击源代码管理标题栏中的 Lorebyte 图标,或通过命令面板运行 +- **智能生成** — 输入框为空时从头生成提交信息;已有内容时基于暂存的 diff 优化和完善现有信息 +- **Conventional Commits** — 生成符合 `(): ` 格式的提交信息 +- **中英文支持** — 提交信息可以生成中文或英文 +- **模型选择** — 通过 API 浏览并切换可用模型 +- **可配置的 Provider** — 内置 [OpenCode Zen](https://opencode.ai/docs/zen/) 支持,可通过 Provider 注册表扩展 + +## 快速开始 + +1. 安装扩展 +2. 在设置中配置 API Key:**Lorebyte > Api Key** +3. 在 git 中暂存一些更改 +4. 点击源代码管理标题栏中的 Lorebyte 图标(或在命令面板中运行 `Lorebyte: Generate Commit Message`) + +生成的提交信息会出现在提交输入框中,可以直接提交。 + +## 命令 + +| 命令 | 说明 | +|------|------| +| `Lorebyte: Generate Commit Message` | 根据暂存更改生成提交信息 | +| `Lorebyte: List Available Models` | 浏览远程模型并切换当前使用的模型(需要 API Key) | + +## 设置 + +| 设置项 | 默认值 | 说明 | +|--------|--------|------| +| `lorebyte.provider` | `opencode-zen` | LLM Provider ID | +| `lorebyte.model` | `minimax-m2.5-free` | 用于生成提交信息的模型 ID | +| `lorebyte.apiKey` | — | LLM Provider 的 API Key | +| `lorebyte.apiBaseUrl` | `https://opencode.ai/zen/v1/chat/completions` | API 端点 URL | +| `lorebyte.language` | `English` | 生成提交信息的语言(`English` / `Chinese`) | + +## 开发 + +### 环境要求 + +- Node.js >= 18 +- VS Code >= 1.85.0 + +### 构建 + +```bash +npm install +npm run compile +``` + +### 监听模式 + +```bash +npm run watch +``` + +### 代码检查 + +```bash +npm run lint +``` + +在 VS Code 中按 **F5** 启动扩展开发宿主,加载该扩展进行调试。 + +## 项目结构 + +``` +src/ +├── extension.ts # 入口文件 — 注册命令和 Provider +├── commands/ +│ ├── generateCommitMessage.ts # 核心流程:diff → LLM → 提交信息 +│ └── listModels.ts # 浏览和选择模型 +├── config/ +│ └── configuration.ts # 读取 VS Code 设置 +├── git/ +│ └── gitService.ts # 通过 VS Code Git API 获取暂存 diff 和提交信息 +├── prompt/ +│ └── commitPrompt.ts # 系统提示词和用户提示词构建 +└── providers/ + ├── types.ts # LLMProvider 接口和消息类型 + ├── providerRegistry.ts # Provider 注册表模式 + └── openCodeZenProvider.ts # OpenCode Zen 实现 +``` + +## 许可证 + +MIT