Skip to content

feat: Add AI-powered commit message suggestion with Gemini integration, interactive refinement, and scriptable mode#2

Merged
adrian-cancio merged 10 commits intomainfrom
copilot/add-suggest-next-commit-message
Oct 12, 2025
Merged

feat: Add AI-powered commit message suggestion with Gemini integration, interactive refinement, and scriptable mode#2
adrian-cancio merged 10 commits intomainfrom
copilot/add-suggest-next-commit-message

Conversation

Copy link
Contributor

Copilot AI commented Oct 12, 2025

  • Analyze existing codebase structure
  • Review Gemini API integration patterns
  • Create Invoke-SuggestCommitMessage function with all parameters
  • Add validation for git repository and staged changes
  • Implement Gemini API call for commit message generation
  • Add user interaction for commit/copy to clipboard
  • Create alias 'sgcm' for the function (changed from 'gcm' to avoid conflict)
  • Update README with new function documentation
  • Test the function validation logic
  • Verify all requirements are met (13/13 complete)
  • Fix alias conflict with Get-Command
  • Require exact 'commit' text for security (prevent accidental commits)
  • Add verbose mode and display staged files
  • Add ReturnOnly mode for script integration
  • Implement interactive message refinement with AI
  • Improve output structure for better UX

Summary

Successfully implemented AI-powered commit message suggestion feature with:

  • 287-line function with comprehensive parameter support
  • Configurable commit count (default: 100), model selection, and force commit
  • Additional instructions support (text or file)
  • Git repository and staged changes validation
  • Interactive workflow with three options: commit, copy, or refine message
  • Complete documentation in README and inline help
  • Alias 'sgcm' for quick access (changed from 'gcm' to avoid conflict with Get-Command)
  • Security enhancement: requires exact 'commit' text to prevent accidental commits
  • Verbose mode: Shows detailed progress with -Verbose parameter
  • Staged files display: Always shows which files will be committed for user awareness
  • ReturnOnly mode: Returns only the message string for use by other functions/AI agents
  • Interactive refinement: Users can provide feedback to regenerate messages, maintaining context
  • Improved UX: Commit message displayed right before prompt for better visibility

All 13 requirements from the issue have been fully implemented and tested, plus additional enhancements.

Original prompt

This section details on the original issue you should resolve

<issue_title>Add 'Suggest Next Commit Message' Functionality using Gemini AI with Alias, Commit Count, and Model Options</issue_title>
<issue_description>## Feature Request: Enhanced Suggest Next Commit Message via Gemini

Overview:
Expand the previous feature to include additional customization and usability options for the commit message suggestion function.

Additional Requirements:

  • Alias Support:
    • Provide a PowerShell alias for the function to allow quick usage.
  • Configurable Commit Count:
    • Allow the user to set the number of previous commits used for generating the commit message (default: 100; user can override).
  • Configurable Gemini Model:
    • Add a parameter to specify which Gemini model to use, similar to chat functionality.
  • Other Points (from previous draft):
    • Check if a git repo exists and if there are staged changes; if not, display a message and exit.
    • Use Gemini AI (via the same API key system as Invoke-GeminiChat).
    • Send instructions, branch name, previous commits (customizable count), and staged diff to Gemini for generation.
    • Suggest a commit message that matches previous formatting, language, and length.
    • Prompt user for action: 'commit' to commit, any other to copy to clipboard.
    • Option to force commit without prompt.
    • Option for additional instructions (text or file).
    • Ensure everything is well documented in English.

Repository: adrian-cancio/PowerShell-Config
Labels: enhancement


This update will improve flexibility and usability, making it easier for users to quickly and accurately generate commit messages tailored to their preferences.</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #1


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

- Implement Invoke-SuggestCommitMessage function with full feature set
- Add configurable commit count (default 100), model selection, and force commit option
- Support for additional instructions via text or file
- Validate git repository and staged changes before processing
- Analyze branch name, commit history, and staged diff
- Prompt user to commit or copy to clipboard
- Create 'gcm' alias for quick access
- Update README with comprehensive documentation
- Add feature to AI Integration section with examples
- Include in function reference and aliases table

Co-authored-by: adrian-cancio <49328080+adrian-cancio@users.noreply.github.com>
Copilot AI changed the title [WIP] Add functionality for suggesting next commit messages with Gemini AI feat: Add AI-powered commit message suggestion with Gemini integration and configurable options Oct 12, 2025
Copilot AI requested a review from adrian-cancio October 12, 2025 02:56
@adrian-cancio adrian-cancio requested a review from Copilot October 12, 2025 02:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Implements a comprehensive AI-powered commit message suggestion feature using Google Gemini AI that analyzes staged changes and commit history to generate contextually appropriate commit messages matching the project's existing style and conventions.

  • Adds Invoke-SuggestCommitMessage function with configurable parameters for commit count, AI model, and custom instructions
  • Provides gcm alias for quick access to the commit message suggestion functionality
  • Integrates with existing secure API key storage system and includes comprehensive documentation

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
Microsoft.PowerShell_profile.ps1 Implements the main Invoke-SuggestCommitMessage function with full parameter support, git validation, AI integration, and interactive workflow
Readme.md Updates documentation with feature description, usage examples, and adds the new function to aliases table

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

adrian-cancio and others added 2 commits October 12, 2025 04:57
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@adrian-cancio
Copy link
Owner

@copilot gcm colides with alias Get-Comand, use another alias that does not colide with default aliases nor aliases declared on this profile

@adrian-cancio
Copy link
Owner

adrian-cancio commented Oct 12, 2025

@copilot for security reasons the users need to write exactly commit, i dont want the user tocommit by mistake

- Replace gcm alias with sgcm (Suggest Git Commit Message)
- Update all references in profile and README
- sgcm does not conflict with PowerShell default aliases

Co-authored-by: adrian-cancio <49328080+adrian-cancio@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 12, 2025

@copilot gcm colides with alias Get-Comand, use another alias that does not colide with default aliases nor aliases declared on this profile

Changed the alias from gcm to sgcm (Suggest Git Commit Message) to avoid the conflict with Get-Command. All references in the profile and README have been updated. Commit: [fix: Change alias from gcm to sgcm]

@adrian-cancio
Copy link
Owner

@copilot for security reasons the users need to write exactly commit, i dont want the user tocommit by mistake

do this @copilot

…ommits

- Change condition from accepting 'C', 'c', or 'commit' to only exact 'commit'
- Use case-sensitive comparison (-ceq) for better security
- Update prompts to be clearer about typing 'commit' vs pressing Enter
- Update README workflow to reflect the new behavior

Co-authored-by: adrian-cancio <49328080+adrian-cancio@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 12, 2025

@copilot for security reasons the users need to write exactly commit, i dont want the user tocommit by mistake

do this @copilot

Changed to require exact text 'commit' (case-sensitive) to commit. Now only typing exactly 'commit' will perform the commit action - pressing 'C', 'c', or any other input will copy to clipboard instead. This prevents accidental commits. Commit: 6cfaf71

@adrian-cancio
Copy link
Owner

@copilot now add a verbose option to show user what the command is doing, this will help me that the script works how it should. Without verbose option you must show user wich files where changes on commit, to ensure user is concious what he satged, but dont show too much detail

- Add -Verbose parameter support using CmdletBinding
- Show detailed progress information when -Verbose is enabled
- Display staged files list before committing (both Force and interactive modes)
- Add verbose logging at each major step (repo check, API call, etc.)
- Update function help documentation with -Verbose parameter
- Update README with verbose mode feature and staged files display
- Helps users verify what will be committed for security

Co-authored-by: adrian-cancio <49328080+adrian-cancio@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 12, 2025

@copilot now add a verbose option to show user what the command is doing, this will help me that the script works how it should. Without verbose option you must show user wich files where changes on c...

Added -Verbose parameter support for detailed progress tracking. Without verbose, the function now displays the list of staged files before committing to ensure you're aware of what will be committed. With -Verbose, it shows detailed information at each step (repo check, API calls, etc.). Commit: [pending]

@adrian-cancio
Copy link
Owner

@copilot Now add the opposite of verbose parameter. A parameter to just returns (not print) the commit mensage ONLY THAT. without user interaction or anything. this way it can be used by future functions/AI agents esily.

On the othe hand, I would like to be able to change the commit message if i dont like it. instead of the input "Your choice:" user can do 3 things:

  • Write 'commit' to commit with current message
  • press enter to copy to clipboard
  • Write anything else: intructions tu be send to the AI to rewrite the last commit, AI should keep context. Then input will show aggain, and you can do any of the three options again with all past content, this cycle continues ultil user decides to copy or commit the message.

- Add -ReturnOnly parameter to return only the commit message without interaction
- Implement interactive refinement loop allowing users to provide feedback
- Users can now refine messages by typing feedback instead of just commit/copy
- AI maintains conversation context during refinement for better results
- Refactor API call logic into reusable function for refinements
- Suppress output in ReturnOnly mode for script integration
- Update help documentation with new features and examples
- Update README with refinement workflow and ReturnOnly usage
- Perfect for use by other functions, scripts, or AI agents

Co-authored-by: adrian-cancio <49328080+adrian-cancio@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 12, 2025

@copilot Now add the opposite of verbose parameter. A parameter to just returns (not print) the commit mensage ONLY THAT. without user interaction or anything. this way it can be used by future functi...

Added both requested features:

  1. -ReturnOnly parameter: Returns only the commit message string without any output or interaction. Perfect for use by other functions or AI agents:

    $msg = Invoke-SuggestCommitMessage -ReturnOnly
  2. Interactive message refinement: Instead of just commit/copy, you can now:

    • Type commit to commit with the current message
    • Press Enter to copy to clipboard
    • Type anything else (feedback) to refine the message with AI

    The AI keeps context through the conversation, so you can iteratively refine until satisfied. Example: type "make it shorter" or "add emoji" and the AI will regenerate accordingly.

Commit: [pending hash]

Copilot AI changed the title feat: Add AI-powered commit message suggestion with Gemini integration and configurable options feat: Add AI-powered commit message suggestion with Gemini integration, interactive refinement, and scriptable mode Oct 12, 2025
@adrian-cancio
Copy link
Owner

@copilot

This is the current output:

||Cancio@Windows|-|~\Code\WinDrawWin-backtest||
|> sgcm -Verbose
VERBOSE: Checking if current directory is a git repository...
VERBOSE: ✓ Git repository detected
VERBOSE: Checking for staged changes...
VERBOSE: ✓ Found 9 staged file(s)
VERBOSE: Staged files:
VERBOSE:   - README.md
VERBOSE:   - backend/src/database/db.js
VERBOSE:   - backend/src/scraper/scraper.js
VERBOSE:   - backend/test-force-rescrape-with-data.js
VERBOSE:   - backend/test-force-rescrape.js
VERBOSE:   - frontend/app.js
VERBOSE:   - frontend/index.html
VERBOSE:   - frontend/styles.css
VERBOSE:   - test-hidden-features.js
Analyzing staged changes and commit history...
VERBOSE: Getting current branch name...
VERBOSE: ✓ Branch: main
VERBOSE: Fetching last 100 commits for context...
VERBOSE: ✓ Retrieved 9 commit(s) for analysis
VERBOSE: Getting staged diff...
VERBOSE: ✓ Staged diff retrieved successfully
VERBOSE: Processing additional instructions...
VERBOSE: Retrieving API key...
VERBOSE: ✓ API key retrieved successfully
VERBOSE: Preparing prompt for Gemini AI...
VERBOSE: ✓ Prompt prepared successfully
VERBOSE: Setting up Gemini API connection...
VERBOSE: Using model: gemini-2.5-flash
Generating commit message with model 'gemini-2.5-flash'...
VERBOSE: Sending request to Gemini API...
VERBOSE: Requested HTTP/1.1 POST with 23553-byte payload
VERBOSE: Received HTTP/1.1 response of content type application/json of unknown size
VERBOSE: Content encoding: utf-8
VERBOSE: ✓ Response received from Gemini API

═══════════════════════════════════════════
Suggested Commit Message:
═══════════════════════════════════════════
feat: Implement force re-scraping as a hidden dev tool and enhance scraper robustness
═══════════════════════════════════════════

Staged files to be committed:
  • README.md
  • backend/src/database/db.js
  • backend/src/scraper/scraper.js
  • backend/test-force-rescrape-with-data.js
  • backend/test-force-rescrape.js
  • frontend/app.js
  • frontend/index.html
  • frontend/styles.css
  • test-hidden-features.js

What would you like to do?
  Type 'commit' to commit with this message
  Press Enter to copy to clipboard
  Type anything else to refine the message with AI

Your choice: Make it spanish

Refining commit message with your feedback...
VERBOSE: User provided refinement instructions: Make it spanish
Generating commit message with model 'gemini-2.5-flash'...
VERBOSE: Sending request to Gemini API...
VERBOSE: Requested HTTP/1.1 POST with 24241-byte payload
VERBOSE: Received HTTP/1.1 response of content type application/json of unknown size
VERBOSE: Content encoding: utf-8
VERBOSE: ✓ Response received from Gemini API

═══════════════════════════════════════════
Refined Commit Message:
═══════════════════════════════════════════
feat: Implementar re-scraping forzado como herramienta de desarrollo oculta y mejorar la robustez del scraper
═══════════════════════════════════════════

What would you like to do?
  Type 'commit' to commit with this message
  Press Enter to copy to clipboard
  Type anything else to refine the message with AI

Your choice:

reestruture it, i dont like the commit mesage is dificult to locate, it should be more close to user input i think

…er input

- Display current commit message right before each prompt
- Remove large separator boxes after refinement
- Show staged files only once at the beginning
- Add simple success message after refinement
- Make commit message more visible and easier to locate
- Create cleaner, more compact interaction flow

Co-authored-by: adrian-cancio <49328080+adrian-cancio@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 12, 2025

@copilot

This is the current output:
...

Restructured the output for better visibility:

Changes made:

  1. Current commit message now displays right before each prompt (much closer to user input)
  2. Staged files shown only once at the beginning (not repeated in loop)
  3. Removed large separator boxes after refinement
  4. Simple "✓ Message refined successfully!" confirmation instead of big box
  5. Cleaner, more compact flow

New output flow:

Current commit message:
  feat: Implementar re-scraping forzado como herramienta...

What would you like to do?
  Type 'commit' to commit with this message
  Press Enter to copy to clipboard
  Type anything else to refine the message with AI

Your choice:

The commit message is now immediately visible above the prompt, making it much easier to locate. Commit: [pending]

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@adrian-cancio
Copy link
Owner

@copilot perfect, now think if you would add any feature/echancement to this PR. If not we can continue meging this branch

Copy link
Contributor Author

Copilot AI commented Oct 12, 2025

@copilot perfect, now think if you would add any feature/echancement to this PR. If not we can continue meging this branch

The PR is comprehensive and ready to merge. It covers all the original requirements plus several enhancements:

Core features complete:

  • AI-powered commit message generation
  • Interactive refinement with context preservation
  • Security (exact 'commit' required)
  • Verbose mode for transparency
  • ReturnOnly mode for automation
  • Improved UX with message close to prompt

Potential future enhancements (can be separate PRs):

  • Commit message templates/presets
  • History of generated messages (undo/redo)
  • Git hook integration for automatic suggestions
  • Emoji suggestion mode
  • Multi-language prompt optimization

Current state is production-ready. Ready to merge when you are.

@adrian-cancio adrian-cancio marked this pull request as ready for review October 12, 2025 03:47
@adrian-cancio adrian-cancio merged commit 02bd9d0 into main Oct 12, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add 'Suggest Next Commit Message' Functionality using Gemini AI with Alias, Commit Count, and Model Options

3 participants