From a7f07dbeeffe968b89e8c4b658f17c8b2b375fc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zo=C3=AB?= Date: Wed, 15 Apr 2026 12:01:40 +0200 Subject: [PATCH] feat(aiCommitExt): add user-suggested commit-message refinement --- AGENTS.md | 22 ++++++++++++++++++++++ package.json | 2 +- src/extension.ts | 14 ++++++++++++-- src/opencodeService.ts | 18 +++++++++++++++++- 4 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 AGENTS.md diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..3afa5c0 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,22 @@ +# AGENTS.md + +## Build & Run + +- **Compile**: `npm run compile` (or `tsc -p ./`) +- **Watch**: `npm run watch` +- **Package extension**: `npm run build` → produces `.vsix` file +- **Test**: Press F5 to launch extension in debug mode + +## Project Structure + +- `src/extension.ts` - Extension entry point, registers `aiCommitExt.generate` command +- `src/opencodeService.ts` - Spawns `opencode run` CLI, parses output for commit message +- `src/gitService.ts` - Uses VS Code Git extension API to get diffs and repo root + +## Key Details + +- Output compiled to `out/` directory +- Extension activates only on command invocation (not on startup) +- OpenCode CLI is required on PATH; checked via `which opencode` +- Generated message written to SCM input box via `repository.inputBox.value` +- Timeout: 120 seconds for OpenCode response \ No newline at end of file diff --git a/package.json b/package.json index 70ee8c6..1c61c86 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "ai-commit-ext", "displayName": "AI Commit Ext", "description": "Generate commit messages using OpenCode AI", - "version": "1.1.0", + "version": "1.2.0", "publisher": "local", "engines": { "vscode": "^1.110.0" diff --git a/src/extension.ts b/src/extension.ts index 6183851..a658cf1 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -88,14 +88,24 @@ async function handleGenerateCommitMessage(): Promise { return; } + const userSuggestion = await vscode.window.showInputBox({ + prompt: "Suggest a commit message (optional)", + placeHolder: "e.g., added login button", + ignoreFocusOut: true, + }); + + if (userSuggestion === undefined) { + return; + } + const commitMessage = await vscode.window.withProgress( { location: vscode.ProgressLocation.Notification, cancellable: false, - title: "Generating commit message...", + title: userSuggestion ? "Improving commit message..." : "Generating commit message...", }, async () => { - return await generateCommitMessage(); + return await generateCommitMessage({ userSuggestion: userSuggestion || undefined }); }, ); diff --git a/src/opencodeService.ts b/src/opencodeService.ts index bb4a5b2..03cceef 100644 --- a/src/opencodeService.ts +++ b/src/opencodeService.ts @@ -5,6 +5,7 @@ import { output } from "./extension"; export interface GenerateOptions { model?: string; + userSuggestion?: string; } let opencodeAvailableCache: boolean | null = null; @@ -47,12 +48,27 @@ export async function generateCommitMessage( const config = vscode.workspace.getConfiguration("aiCommitExt"); const model = options.model || config.get("model", ""); - const prompt = `${DEFAULT_PROMPT} + let prompt: string; + if (options.userSuggestion) { + prompt = `The user suggested: "${options.userSuggestion}" + +Improve this commit message to be concise and follow Conventional Commit format. +Format: (): +Max 72 characters for the subject line. +Types: feat, fix, refactor, docs, style, test, chore, perf, ci, build, revert + +Here are the git changes: +${diff} + +Only output the improved commit message, nothing else.`; + } else { + prompt = `${DEFAULT_PROMPT} Here are the git changes: ${diff} Generate a concise Conventional Commit message for these changes:`; + } const log = `[${Date.now()}]\r\n${prompt}`; output.appendLine(log);