-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat: add generate commit message feature for staged changes #8862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Add generateCommitMessage command to package.json with SCM menu integration - Implement git utility functions to get staged diff and files - Create command handler that uses AI to generate conventional commit messages - Add localization support for the new command - Add sparkle icon to the SCM title bar for easy access This feature allows users to generate AI-powered commit messages based on their staged changes, following conventional commit format.
Code Review SummaryI've reviewed the PR and identified several architectural issues that need to be addressed: Issues Found
RecommendationRefactor to use the API handler directly with |
| generateCommitMessage: async () => { | ||
| const cwd = getWorkspacePath() | ||
| if (!cwd) { | ||
| vscode.window.showErrorMessage("No workspace folder open") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
User‐facing strings (e.g. error and info messages) are hard‐coded. Consider wrapping these messages with the i18n function t() so that they are localizable.
| vscode.window.showErrorMessage("No workspace folder open") | |
| vscode.window.showErrorMessage(t("No workspace folder open")) |
This comment was generated because it violated a code review rule: irule_C0ez7Rji6ANcGkkX.
| Please provide ONLY the commit message, without any additional explanation or formatting. The message should be on a single line unless a body is needed for complex changes.` | ||
|
|
||
| // Create a task and wait for the response | ||
| const task = await visibleProvider.createTask(prompt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating a full task instance for generating a commit message is inappropriate and causes resource leaks. The task system is designed for interactive, multi-step user operations, not one-off API calls. This approach: (1) adds the task to the provider's task stack without proper cleanup, (2) creates unnecessary state and event listeners, (3) persists the task to disk unnecessarily. Consider using the API handler directly with buildApiHandler(apiConfiguration).createMessage() instead of createTask().
| await new Promise<void>((resolve) => { | ||
| let checkCount = 0 | ||
| const maxChecks = 300 // 30 seconds with 100ms intervals | ||
|
|
||
| const checkInterval = setInterval(() => { | ||
| checkCount++ | ||
| const messages = task.clineMessages | ||
|
|
||
| // Look for a message with type "say" and say "completion_result" | ||
| const completionMessage = messages.find( | ||
| (msg) => msg.type === "say" && msg.say === "completion_result", | ||
| ) | ||
|
|
||
| if (completionMessage || checkCount >= maxChecks) { | ||
| clearInterval(checkInterval) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This polling mechanism is fragile and prone to race conditions. It checks task messages every 100ms for up to 30 seconds, but there's no guarantee the message structure will be as expected when using createTask(). The check relies on internal task message format (type === 'say' && say === 'completion_result') which could change or be missing. If the task fails, times out, or produces unexpected message format, this will silently fail after 30 seconds without proper error handling.
| } | ||
|
|
||
| // Clear the task | ||
| visibleProvider.clearTask() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The task created for commit message generation is never properly cleaned up. After extracting the commit message, visibleProvider.clearTask() is called, but this only removes the task from the stack without proper disposal. The task will remain in task history, pollute the UI with unnecessary entries, and leak resources (event listeners, file watchers, etc.). Consider calling task.dispose() explicitly or better yet, avoid creating a task entirely for this use case.
Summary
This PR implements Issue #8861 by adding a feature to generate AI-powered commit messages for staged changes in VSCode.
Changes
generateCommitMessagecommand that appears as a sparkle icon button in the SCM title barHow it works
git addTesting
Screenshots
The sparkle icon appears in the SCM title bar when git is the active SCM provider and provides one-click commit message generation.
Closes #8861
Important
Adds AI-powered commit message generation for staged changes in VSCode with a new
generateCommitMessagecommand.generateCommitMessagecommand inregisterCommands.tsfor AI-powered commit message generation.getStagedDiffandgetStagedFilesingit.tsto retrieve staged changes.package.nls.json.package.jsonto include the new command and its icon.This description was created by
for 4d29f89. You can customize this summary. It will automatically update as commits are pushed.