Compare commits
2 Commits
cecec8bf23
...
1.0.1
| Author | SHA1 | Date | |
|---|---|---|---|
| 55df24e0fd | |||
| fd4fd87ea8 |
1140
package-lock.json
generated
1140
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,7 @@
|
|||||||
"name": "ai-commit-ext",
|
"name": "ai-commit-ext",
|
||||||
"displayName": "AI Commit Ext",
|
"displayName": "AI Commit Ext",
|
||||||
"description": "Generate commit messages using OpenCode AI",
|
"description": "Generate commit messages using OpenCode AI",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"publisher": "local",
|
"publisher": "local",
|
||||||
"engines": {
|
"engines": {
|
||||||
"vscode": "^1.110.0"
|
"vscode": "^1.110.0"
|
||||||
|
|||||||
@@ -41,7 +41,11 @@ async function handleGenerateCommitMessage(): Promise<void> {
|
|||||||
const showNotification = config.get<boolean>("showNotification", true);
|
const showNotification = config.get<boolean>("showNotification", true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const opencodeAvailable = await isOpenCodeAvailable();
|
const [opencodeAvailable, gitExtension] = await Promise.all([
|
||||||
|
isOpenCodeAvailable(),
|
||||||
|
vscode.extensions.getExtension<GitExtension>("vscode.git"),
|
||||||
|
]);
|
||||||
|
|
||||||
if (!opencodeAvailable) {
|
if (!opencodeAvailable) {
|
||||||
if (showNotification) {
|
if (showNotification) {
|
||||||
vscode.window.showErrorMessage(
|
vscode.window.showErrorMessage(
|
||||||
@@ -51,8 +55,6 @@ async function handleGenerateCommitMessage(): Promise<void> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const gitExtension =
|
|
||||||
vscode.extensions.getExtension<GitExtension>("vscode.git");
|
|
||||||
if (!gitExtension) {
|
if (!gitExtension) {
|
||||||
if (showNotification) {
|
if (showNotification) {
|
||||||
vscode.window.showErrorMessage("Git extension not found");
|
vscode.window.showErrorMessage("Git extension not found");
|
||||||
@@ -114,3 +116,5 @@ async function handleGenerateCommitMessage(): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function deactivate(): void {}
|
export function deactivate(): void {}
|
||||||
|
|
||||||
|
export const output = vscode.window.createOutputChannel("ai-commit-ext");
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
import { exec, spawn, ExecException } from "child_process";
|
import { exec, spawn, ExecException } from "child_process";
|
||||||
import * as vscode from "vscode";
|
import * as vscode from "vscode";
|
||||||
import { getGitDiff, getRepositoryRoot } from "./gitService";
|
import { getGitDiff, getRepositoryRoot } from "./gitService";
|
||||||
|
import { output } from "./extension";
|
||||||
|
|
||||||
export interface GenerateOptions {
|
export interface GenerateOptions {
|
||||||
model?: string;
|
model?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let opencodeAvailableCache: boolean | null = null;
|
||||||
|
|
||||||
const DEFAULT_PROMPT = `You are a helpful assistant that generates git commit messages.
|
const DEFAULT_PROMPT = `You are a helpful assistant that generates git commit messages.
|
||||||
Generate a concise Conventional Commit message (max 72 characters for the subject line).
|
Generate a concise Conventional Commit message (max 72 characters for the subject line).
|
||||||
Format: <type>(<scope>): <description>
|
Format: <type>(<scope>): <description>
|
||||||
@@ -15,9 +18,13 @@ Types: feat, fix, refactor, docs, style, test, chore, perf, ci, build, revert
|
|||||||
Only output the commit message, nothing else.`;
|
Only output the commit message, nothing else.`;
|
||||||
|
|
||||||
export async function isOpenCodeAvailable(): Promise<boolean> {
|
export async function isOpenCodeAvailable(): Promise<boolean> {
|
||||||
|
if (opencodeAvailableCache !== null) {
|
||||||
|
return opencodeAvailableCache;
|
||||||
|
}
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
exec("which opencode", (error: ExecException | null) => {
|
exec("which opencode", (error: ExecException | null) => {
|
||||||
resolve(!error);
|
opencodeAvailableCache = !error;
|
||||||
|
resolve(opencodeAvailableCache);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -32,8 +39,10 @@ export async function generateCommitMessage(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const diff = await getGitDiff();
|
const [diff, repoRoot] = await Promise.all([
|
||||||
const repoRoot = await getRepositoryRoot();
|
getGitDiff(),
|
||||||
|
getRepositoryRoot(),
|
||||||
|
]);
|
||||||
|
|
||||||
const config = vscode.workspace.getConfiguration("aiCommitExt");
|
const config = vscode.workspace.getConfiguration("aiCommitExt");
|
||||||
const model = options.model || config.get<string>("model", "");
|
const model = options.model || config.get<string>("model", "");
|
||||||
@@ -45,8 +54,17 @@ ${diff}
|
|||||||
|
|
||||||
Generate a concise Conventional Commit message for these changes:`;
|
Generate a concise Conventional Commit message for these changes:`;
|
||||||
|
|
||||||
|
const log = `[${Date.now()}]\r\n${prompt}`;
|
||||||
|
output.appendLine(log);
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const args: string[] = ["run", "--format", "default"];
|
const args: string[] = [
|
||||||
|
"run",
|
||||||
|
"--format",
|
||||||
|
"default",
|
||||||
|
"--variant",
|
||||||
|
"minimal",
|
||||||
|
];
|
||||||
|
|
||||||
if (model) {
|
if (model) {
|
||||||
args.push("--model", model);
|
args.push("--model", model);
|
||||||
|
|||||||
Reference in New Issue
Block a user