Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 6 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,27 @@ Lorebyte reads your staged changes, sends the diff to an LLM, and writes a [Conv
## Quick Start

1. Install the extension
2. Set your API key in Settings: **Lorebyte > Api Key**
3. Stage some changes in git
4. Click the Lorebyte icon in the Source Control title bar (or run `Lorebyte: Generate Commit Message` from the Command Palette)
2. Stage some changes in git
3. Click the Lorebyte icon in the Source Control title bar (or run `Lorebyte: Generate Commit Message` from the Command Palette)

The generated message appears in the commit input box, ready to commit.

> **No API key needed to get started.** Lorebyte ships with a built-in free key so you can use it immediately. To unlock all available models, set your own API key in Settings: **Lorebyte > Api Key**.

## Commands

| Command | Description |
|---------|-------------|
| `Lorebyte: Generate Commit Message` | Generate a commit message from staged changes |
| `Lorebyte: List Available Models` | Browse remote models and switch the active model (requires API key) |
| `Lorebyte: List Available Models` | Browse remote models and switch the active model (requires a personal API key) |

## Settings

| Setting | Default | Description |
|---------|---------|-------------|
| `lorebyte.provider` | `opencode-zen` | LLM provider ID |
| `lorebyte.model` | `minimax-m2.5-free` | Model ID for generating commit messages |
| `lorebyte.apiKey` | — | API key for the LLM provider |
| `lorebyte.apiKey` | — | Your personal API key. Leave empty to use the built-in free key (default model only). |
| `lorebyte.apiBaseUrl` | `https://opencode.ai/zen/v1/chat/completions` | API endpoint URL |
| `lorebyte.language` | `English` | Language for generated commit messages (`English` / `Chinese`) |

Expand Down Expand Up @@ -69,26 +70,6 @@ npm run lint

Press **F5** in VS Code to launch an Extension Development Host with the extension loaded.

## Project Structure

```
src/
├── extension.ts # Entry point — registers commands & providers
├── commands/
│ ├── generateCommitMessage.ts # Core workflow: diff → LLM → commit message
│ └── listModels.ts # Browse and select models
├── config/
│ └── configuration.ts # Reads VS Code settings
├── git/
│ └── gitService.ts # Staged diff & commit message via VS Code Git API
├── prompt/
│ └── commitPrompt.ts # System & user prompt construction
└── providers/
├── types.ts # LLMProvider interface & message types
├── providerRegistry.ts # Registry pattern for providers
└── openCodeZenProvider.ts # OpenCode Zen implementation
```

## License

MIT
31 changes: 6 additions & 25 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,27 @@ Lorebyte 读取你的暂存更改,将 diff 发送给 LLM,然后将符合 [Co
## 快速开始

1. 安装扩展
2. 在设置中配置 API Key:**Lorebyte > Api Key**
3. 在 git 中暂存一些更改
4. 点击源代码管理标题栏中的 Lorebyte 图标(或在命令面板中运行 `Lorebyte: Generate Commit Message`)
2. 在 git 中暂存一些更改
3. 点击源代码管理标题栏中的 Lorebyte 图标(或在命令面板中运行 `Lorebyte: Generate Commit Message`)

生成的提交信息会出现在提交输入框中,可以直接提交。

> **无需配置即可上手。** Lorebyte 内置了免费 key,安装后可直接使用。如需切换其他模型,请在设置中填入自己的 API Key:**Lorebyte > Api Key**。

## 命令

| 命令 | 说明 |
|------|------|
| `Lorebyte: Generate Commit Message` | 根据暂存更改生成提交信息 |
| `Lorebyte: List Available Models` | 浏览远程模型并切换当前使用的模型(需要 API Key) |
| `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.apiKey` | — | 你的个人 API Key,留空时使用内置免费 key(仅限默认模型)。 |
| `lorebyte.apiBaseUrl` | `https://opencode.ai/zen/v1/chat/completions` | API 端点 URL |
| `lorebyte.language` | `English` | 生成提交信息的语言(`English` / `Chinese`) |

Expand Down Expand Up @@ -69,26 +70,6 @@ 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
7 changes: 6 additions & 1 deletion src/commands/generateCommitMessage.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import * as vscode from "vscode";
import { GitService } from "../git/gitService";
import { providerRegistry } from "../providers/providerRegistry";
import { getConfig } from "../config/configuration";
import { getConfig, DEFAULT_MODEL } from "../config/configuration";
import { buildSystemPrompt, buildUserPrompt } from "../prompt/commitPrompt";

export async function generateCommitMessage(): Promise<void> {
const config = getConfig();

// When the built-in fallback key is active, lock to the default model.
if (config.isUsingDefaultKey) {
config.model = DEFAULT_MODEL;
}

const provider = providerRegistry.get(config.provider);
if (!provider) {
vscode.window.showErrorMessage(
Expand Down
10 changes: 7 additions & 3 deletions src/commands/listModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ export async function listModels(): Promise<void> {
return;
}

if (!config.apiKey) {
vscode.window.showErrorMessage(
"Lorebyte: API key is required to list models."
if (config.isUsingDefaultKey) {
const action = await vscode.window.showInformationMessage(
"Lorebyte: You're using the built-in free key, which is locked to the default model. Set your own API key in Settings to browse and switch models.",
"Open Settings"
);
if (action === "Open Settings") {
vscode.commands.executeCommand("workbench.action.openSettings", "lorebyte.apiKey");
}
return;
}

Expand Down
19 changes: 17 additions & 2 deletions src/config/configuration.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
import * as vscode from "vscode";

export const DEFAULT_MODEL = "minimax-m2.5-free";

// Built-in fallback key — allows zero-config usage with the default model.
// Split to avoid plain-text exposure in the bundle.
const _bk = [
"sk-fCVRgReDWw38yQ",
"OirUZdOzLQmRfOzSCHKeW3vfl5a",
"6IJa7EWfTsJK0KRVcuCzMhA",
].join("");

export interface LorebyteConfig {
provider: string;
model: string;
apiKey: string;
apiBaseUrl: string;
language: string;
/** True when the built-in fallback key is in use (no user-configured key). */
isUsingDefaultKey: boolean;
}

export function getConfig(): LorebyteConfig {
const cfg = vscode.workspace.getConfiguration("lorebyte");
const userKey = cfg.get<string>("apiKey", "").trim();
const isUsingDefaultKey = !userKey;
return {
provider: cfg.get<string>("provider", "opencode-zen"),
model: cfg.get<string>("model", "minimax-m2.5-free"),
apiKey: cfg.get<string>("apiKey", ""),
model: cfg.get<string>("model", DEFAULT_MODEL),
apiKey: userKey || _bk,
apiBaseUrl: cfg.get<string>(
"apiBaseUrl",
"https://opencode.ai/zen/v1/chat/completions"
),
language: cfg.get<string>("language", "English"),
isUsingDefaultKey,
};
}