From f133f928dab2b58cadfbcd1f19b232a92243a0d9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 12 Oct 2025 02:42:17 +0000 Subject: [PATCH 01/10] Initial plan From c0d3bf1a7ca9e8822447c8467f8a1575b12d2664 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 12 Oct 2025 02:50:43 +0000 Subject: [PATCH 02/10] feat: Add AI-powered commit message suggestion with Gemini integration - 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> --- Microsoft.PowerShell_profile.ps1 | 287 +++++++++++++++++++++++++++++++ Readme.md | 56 +++++- 2 files changed, 341 insertions(+), 2 deletions(-) diff --git a/Microsoft.PowerShell_profile.ps1 b/Microsoft.PowerShell_profile.ps1 index 8a245cd..caf920d 100644 --- a/Microsoft.PowerShell_profile.ps1 +++ b/Microsoft.PowerShell_profile.ps1 @@ -842,6 +842,7 @@ Set-Alias -Name wrh -Value Write-Host Set-Alias -Name cpwd -Value Set-PWDClipboard Set-Alias -Name tree -Value Show-DirectoryTree Set-Alias -Name gemini -Value Invoke-GeminiChat +Set-Alias -Name gcm -Value Invoke-SuggestCommitMessage # Create aliases only if the original commands exist if ($Global:OriginalPipPath -and (Test-Path $Global:OriginalPipPath)) { @@ -1915,3 +1916,289 @@ Remember: Terminal users value SPEED and CLARITY over detailed explanations. Mak Write-Host "" # Add a final blank line before exit message Write-Host "Ending chat." -ForegroundColor Cyan } + +<# +.SYNOPSIS +Suggests a commit message using Gemini AI based on staged changes and commit history. + +.DESCRIPTION +This function analyzes your git repository's staged changes, branch name, and commit history +to generate an appropriate commit message using Google Gemini AI. It checks if a git repository +exists and if there are staged changes before proceeding. + +The generated message matches the formatting, language, and style of previous commits. + +.PARAMETER CommitCount +Number of previous commits to analyze for style and context. Defaults to 100. + +.PARAMETER Model +The Gemini model to use for generating the commit message. Defaults to 'gemini-2.5-flash'. + +.PARAMETER Force +If specified, automatically commits with the suggested message without prompting for confirmation. + +.PARAMETER AdditionalInstructions +Additional instructions to guide the commit message generation (text string). + +.PARAMETER InstructionsFile +Path to a file containing additional instructions for commit message generation. + +.PARAMETER ResetApiKey +Forces the function to ask for a new API key, replacing the stored one. + +.EXAMPLE +Invoke-SuggestCommitMessage +# Generates a commit message based on staged changes and prompts for action + +.EXAMPLE +Invoke-SuggestCommitMessage -CommitCount 50 -Model "gemini-2.5-flash" +# Uses the last 50 commits and specified model + +.EXAMPLE +Invoke-SuggestCommitMessage -Force +# Automatically commits with the suggested message + +.EXAMPLE +Invoke-SuggestCommitMessage -AdditionalInstructions "Use conventional commits format" +# Adds specific instructions for message generation + +.EXAMPLE +gcm +# Uses the alias to suggest a commit message +#> +function Invoke-SuggestCommitMessage { + [CmdletBinding()] + param( + [int]$CommitCount = 100, + + [string]$Model = "gemini-2.5-flash", + + [switch]$Force, + + [string]$AdditionalInstructions = "", + + [string]$InstructionsFile = "", + + [switch]$ResetApiKey + ) + + # --- Check if we're in a git repository --- + try { + $gitCheck = git rev-parse --is-inside-work-tree 2>&1 + if ($LASTEXITCODE -ne 0) { + Write-Host "Error: Not in a git repository." -ForegroundColor Red + return + } + } + catch { + Write-Host "Error: Git is not available or not in a git repository." -ForegroundColor Red + return + } + + # --- Check for staged changes --- + $stagedFiles = git diff --cached --name-only + if ([string]::IsNullOrWhiteSpace($stagedFiles)) { + Write-Host "Error: No staged changes found. Use 'git add' to stage files first." -ForegroundColor Yellow + return + } + + Write-Host "Analyzing staged changes and commit history..." -ForegroundColor Cyan + + # --- Get branch name --- + $branchName = git rev-parse --abbrev-ref HEAD 2>&1 + if ($LASTEXITCODE -ne 0) { + $branchName = "unknown" + } + + # --- Get commit history --- + $commitHistory = git --no-pager log --oneline -n $CommitCount 2>&1 + if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($commitHistory)) { + $commitHistory = "No previous commits available (new repository)" + } + + # --- Get staged diff --- + $stagedDiff = git diff --cached + if ([string]::IsNullOrWhiteSpace($stagedDiff)) { + Write-Host "Error: Unable to get staged diff." -ForegroundColor Red + return + } + + # --- Load additional instructions from file if provided --- + $additionalInstructionsText = $AdditionalInstructions + if (-not [string]::IsNullOrWhiteSpace($InstructionsFile)) { + if (Test-Path $InstructionsFile) { + $fileContent = Get-Content -Path $InstructionsFile -Raw + $additionalInstructionsText = if ([string]::IsNullOrWhiteSpace($additionalInstructionsText)) { + $fileContent + } else { + "$additionalInstructionsText`n`n$fileContent" + } + } + else { + Write-Warning "Instructions file not found: $InstructionsFile" + } + } + + # --- Get or Set API Key --- + $apiKey = $null + + if ($ResetApiKey.IsPresent) { + Write-Host "Resetting API key..." -ForegroundColor Yellow + $apiKey = $null + } + else { + $apiKey = Get-SecureApiKey -KeyName "GeminiAPI" + } + + if ([string]::IsNullOrEmpty($apiKey)) { + Write-Host "Google Gemini API key not found or reset requested." -ForegroundColor Yellow + Write-Host "Please enter your Google Gemini API key:" -ForegroundColor Cyan + $inputApiKey = Read-Host -AsSecureString + + # Convert secure string to plain text for this session + $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($inputApiKey) + $apiKey = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) + [System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($BSTR) + + if ([string]::IsNullOrEmpty($apiKey)) { + Write-Error "API key cannot be empty." + return + } + + # Store the API key securely + Set-SecureApiKey -ApiKey $apiKey -KeyName "GeminiAPI" + } + + # --- Prepare the prompt for Gemini --- + $promptText = @" +You are a git commit message expert. Your task is to analyze the provided information and generate a concise, meaningful commit message. + +CONTEXT: +- Branch: $branchName +- Staged files: $($stagedFiles.Count) file(s) + +PREVIOUS COMMITS (last $CommitCount): +$commitHistory + +STAGED CHANGES (diff): +$stagedDiff + +INSTRUCTIONS: +1. Analyze the staged changes to understand what was modified +2. Review the previous commits to match their style, format, language, and length +3. Generate a commit message that: + - Accurately describes the changes + - Matches the language used in previous commits (English, Spanish, etc.) + - Follows the same formatting style as previous commits + - Is concise but descriptive + - Uses appropriate prefixes if the project uses them (feat:, fix:, docs:, etc.) + +$(if (-not [string]::IsNullOrWhiteSpace($additionalInstructionsText)) { "ADDITIONAL INSTRUCTIONS:`n$additionalInstructionsText`n" } else { "" }) +Please provide ONLY the commit message, without any explanations or additional text. +"@ + + # --- API Setup --- + $uri = "https://generativelanguage.googleapis.com/v1beta/models/$($Model):generateContent" + + $headers = @{ + "Content-Type" = "application/json" + "X-goog-api-key" = $apiKey + } + + $body = @{ + contents = @( + @{ + role = "user" + parts = @(@{ text = $promptText }) + } + ) + } | ConvertTo-Json -Depth 10 + + # --- API Call --- + try { + Write-Host "Generating commit message with model '$Model'..." -ForegroundColor Cyan + + $response = Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -Body $body -ContentType "application/json" + + if ($null -eq $response.candidates) { + Write-Error "The API did not return a valid response. The content may have been blocked." + return + } + + $suggestedMessage = $response.candidates[0].content.parts[0].text.Trim() + + # Remove any markdown code block markers if present + $suggestedMessage = $suggestedMessage -replace '^```.*\n', '' -replace '\n```$', '' + $suggestedMessage = $suggestedMessage.Trim() + + } + catch { + Write-Error "An error occurred while contacting the Gemini API: $($_.Exception.Message)" + if ($_.Exception.Response) { + $errorBody = $_.Exception.Response.GetResponseStream() | ForEach-Object { (New-Object System.IO.StreamReader($_)).ReadToEnd() } + Write-Host "Error body: $errorBody" -ForegroundColor Red + } + return + } + + # --- Display the suggested message --- + Write-Host "`n" -NoNewline + Write-Host "═══════════════════════════════════════════" -ForegroundColor Cyan + Write-Host "Suggested Commit Message:" -ForegroundColor Green + Write-Host "═══════════════════════════════════════════" -ForegroundColor Cyan + Write-Host $suggestedMessage -ForegroundColor White + Write-Host "═══════════════════════════════════════════" -ForegroundColor Cyan + Write-Host "" + + # --- Handle user action --- + if ($Force.IsPresent) { + # Auto-commit without prompting + try { + git commit -m $suggestedMessage + if ($LASTEXITCODE -eq 0) { + Write-Host "✓ Changes committed successfully!" -ForegroundColor Green + } + else { + Write-Error "Failed to commit changes." + } + } + catch { + Write-Error "Error during commit: $($_.Exception.Message)" + } + } + else { + # Prompt for action + Write-Host "What would you like to do?" -ForegroundColor Yellow + Write-Host " [C] Commit with this message" -ForegroundColor White + Write-Host " [Any other key] Copy to clipboard" -ForegroundColor White + Write-Host "" + + $action = Read-Host "Your choice" + + if ($action -eq 'C' -or $action -eq 'c' -or $action -eq 'commit') { + try { + git commit -m $suggestedMessage + if ($LASTEXITCODE -eq 0) { + Write-Host "✓ Changes committed successfully!" -ForegroundColor Green + } + else { + Write-Error "Failed to commit changes." + } + } + catch { + Write-Error "Error during commit: $($_.Exception.Message)" + } + } + else { + # Copy to clipboard + try { + Set-Clipboard -Value $suggestedMessage + Write-Host "✓ Commit message copied to clipboard!" -ForegroundColor Green + } + catch { + Write-Warning "Failed to copy to clipboard. Here's the message to copy manually:" + Write-Host $suggestedMessage -ForegroundColor White + } + } + } +} diff --git a/Readme.md b/Readme.md index d672979..12bdb34 100644 --- a/Readme.md +++ b/Readme.md @@ -10,9 +10,10 @@ A powerful, cross-platform PowerShell profile that enhances your terminal experi - 🎨 **Customizable Prompt**: 11 different color schemes including dynamic themes - 🤖 **AI Integration**: Google Gemini chat with terminal-optimized responses +- 💬 **Smart Commit Messages**: AI-powered commit message suggestions based on staged changes - 🧮 **Mathematical Functions**: Complete set of trigonometric and mathematical operations -- � **Smart Pip Wrappers**: Intelligent warnings for global package installations -- �🐙 **GitHub Copilot**: Built-in command suggestions and explanations +- 🐍 **Smart Pip Wrappers**: Intelligent warnings for global package installations +- 🐙 **GitHub Copilot**: Built-in command suggestions and explanations - 🔒 **Secure Storage**: Cross-platform encrypted API key management - 📁 **Smart File Operations**: Directory trees with .gitignore support - ⚙️ **JSON Configuration**: Persistent settings with easy customization @@ -86,6 +87,15 @@ pip install package-name --global # Skips warning # Start Gemini chat (English) gemini "how to find large files in PowerShell" +# Suggest commit message based on staged changes +gcm # or Invoke-SuggestCommitMessage +# Analyzes staged changes and previous commits to generate a commit message + +# Use with custom options +Invoke-SuggestCommitMessage -CommitCount 50 -Model "gemini-2.5-flash" +Invoke-SuggestCommitMessage -Force # Auto-commit without prompting +Invoke-SuggestCommitMessage -AdditionalInstructions "Use conventional commits format" + # GitHub Copilot suggestions ghcs "compress a folder" @@ -225,6 +235,46 @@ Show-DirectoryTree -Path "C:\Projects" -IncludeFiles -RespectGitIgnore Get-ContentRecursiveIgnore -Path "C:\Projects" -UseMarkdownFence $true ``` +### AI-Powered Git Commit Messages + +The profile includes an intelligent commit message generator using Gemini AI: + +```powershell +# Basic usage - analyzes staged changes and suggests a commit message +gcm +# or +Invoke-SuggestCommitMessage + +# Customize the number of previous commits to analyze (default: 100) +Invoke-SuggestCommitMessage -CommitCount 50 + +# Use a specific Gemini model +Invoke-SuggestCommitMessage -Model "gemini-2.5-flash" + +# Auto-commit without prompting for confirmation +Invoke-SuggestCommitMessage -Force + +# Add specific instructions for the commit message +Invoke-SuggestCommitMessage -AdditionalInstructions "Use conventional commits format with emoji" + +# Load instructions from a file +Invoke-SuggestCommitMessage -InstructionsFile "commit-guidelines.txt" +``` + +**Features:** +- 🔍 **Analyzes staged changes**: Examines git diff to understand modifications +- 📚 **Learns from history**: Reviews previous commits to match style and language +- 🌐 **Language detection**: Generates messages in the same language as your commit history +- 🎯 **Smart formatting**: Matches existing commit message patterns and conventions +- ⚡ **Quick workflow**: Choose to commit immediately or copy to clipboard +- 🎨 **Customizable**: Supports additional instructions and different AI models + +**Workflow:** +1. Stage your changes: `git add .` +2. Run: `gcm` +3. Review the AI-generated commit message +4. Choose action: Press `C` to commit or any other key to copy to clipboard + ## 🛠️ System Requirements ### Core Requirements @@ -284,6 +334,7 @@ Get-ContentRecursiveIgnore -Path "C:\Projects" -UseMarkdownFence $true ### AI Integration Functions - `Invoke-GeminiChat` (`gemini`) - Google Gemini AI chat +- `Invoke-SuggestCommitMessage` (`gcm`) - AI-powered commit message suggestions - `Format-GeminiText` - Process Gemini formatting commands - `Test-PowerShellCodeRisk` - Analyze code for security risks - `Invoke-SafePowerShellCode` - Execute code with safety checks @@ -301,6 +352,7 @@ Get-ContentRecursiveIgnore -Path "C:\Projects" -UseMarkdownFence $true | `cpwd` | `Set-PWDClipboard` | Copy working directory | | `tree` | `Show-DirectoryTree` | Directory tree display | | `gemini` | `Invoke-GeminiChat` | AI chat | +| `gcm` | `Invoke-SuggestCommitMessage` | AI commit message suggestions | | `wrh` | `Write-Host` | Write to host | ## 🤝 Contributing From 2f7625b90bbf5cb03b1d0f7c3726c790b85d8289 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Cancio?= <49328080+adrian-cancio@users.noreply.github.com> Date: Sun, 12 Oct 2025 04:57:39 +0200 Subject: [PATCH 03/10] Update Microsoft.PowerShell_profile.ps1 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- Microsoft.PowerShell_profile.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Microsoft.PowerShell_profile.ps1 b/Microsoft.PowerShell_profile.ps1 index caf920d..e3484d0 100644 --- a/Microsoft.PowerShell_profile.ps1 +++ b/Microsoft.PowerShell_profile.ps1 @@ -2075,7 +2075,7 @@ You are a git commit message expert. Your task is to analyze the provided inform CONTEXT: - Branch: $branchName -- Staged files: $($stagedFiles.Count) file(s) +- Staged files: $((($stagedFiles -split '\n' | Where-Object { $_ }).Count)) file(s) PREVIOUS COMMITS (last $CommitCount): $commitHistory From 01f98f6991d4bfc92675f8bf49d3778913c603fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Cancio?= <49328080+adrian-cancio@users.noreply.github.com> Date: Sun, 12 Oct 2025 04:58:28 +0200 Subject: [PATCH 04/10] Update Microsoft.PowerShell_profile.ps1 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- Microsoft.PowerShell_profile.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Microsoft.PowerShell_profile.ps1 b/Microsoft.PowerShell_profile.ps1 index e3484d0..b924875 100644 --- a/Microsoft.PowerShell_profile.ps1 +++ b/Microsoft.PowerShell_profile.ps1 @@ -2175,7 +2175,7 @@ Please provide ONLY the commit message, without any explanations or additional t $action = Read-Host "Your choice" - if ($action -eq 'C' -or $action -eq 'c' -or $action -eq 'commit') { + if ($action -eq 'C' -or $action -eq 'c') { try { git commit -m $suggestedMessage if ($LASTEXITCODE -eq 0) { From 6cfaf715fac2b0f0817528dbad8518a9c26d0b5c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 12 Oct 2025 03:07:27 +0000 Subject: [PATCH 05/10] fix: Change alias from gcm to sgcm to avoid conflict with Get-Command - 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> --- Microsoft.PowerShell_profile.ps1 | 4 ++-- Readme.md | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Microsoft.PowerShell_profile.ps1 b/Microsoft.PowerShell_profile.ps1 index b924875..8710e8f 100644 --- a/Microsoft.PowerShell_profile.ps1 +++ b/Microsoft.PowerShell_profile.ps1 @@ -842,7 +842,7 @@ Set-Alias -Name wrh -Value Write-Host Set-Alias -Name cpwd -Value Set-PWDClipboard Set-Alias -Name tree -Value Show-DirectoryTree Set-Alias -Name gemini -Value Invoke-GeminiChat -Set-Alias -Name gcm -Value Invoke-SuggestCommitMessage +Set-Alias -Name sgcm -Value Invoke-SuggestCommitMessage # Create aliases only if the original commands exist if ($Global:OriginalPipPath -and (Test-Path $Global:OriginalPipPath)) { @@ -1963,7 +1963,7 @@ Invoke-SuggestCommitMessage -AdditionalInstructions "Use conventional commits fo # Adds specific instructions for message generation .EXAMPLE -gcm +sgcm # Uses the alias to suggest a commit message #> function Invoke-SuggestCommitMessage { diff --git a/Readme.md b/Readme.md index 12bdb34..385f154 100644 --- a/Readme.md +++ b/Readme.md @@ -88,7 +88,7 @@ pip install package-name --global # Skips warning gemini "how to find large files in PowerShell" # Suggest commit message based on staged changes -gcm # or Invoke-SuggestCommitMessage +sgcm # or Invoke-SuggestCommitMessage # Analyzes staged changes and previous commits to generate a commit message # Use with custom options @@ -241,7 +241,7 @@ The profile includes an intelligent commit message generator using Gemini AI: ```powershell # Basic usage - analyzes staged changes and suggests a commit message -gcm +sgcm # or Invoke-SuggestCommitMessage @@ -271,7 +271,7 @@ Invoke-SuggestCommitMessage -InstructionsFile "commit-guidelines.txt" **Workflow:** 1. Stage your changes: `git add .` -2. Run: `gcm` +2. Run: `sgcm` 3. Review the AI-generated commit message 4. Choose action: Press `C` to commit or any other key to copy to clipboard @@ -334,7 +334,7 @@ Invoke-SuggestCommitMessage -InstructionsFile "commit-guidelines.txt" ### AI Integration Functions - `Invoke-GeminiChat` (`gemini`) - Google Gemini AI chat -- `Invoke-SuggestCommitMessage` (`gcm`) - AI-powered commit message suggestions +- `Invoke-SuggestCommitMessage` (`sgcm`) - AI-powered commit message suggestions - `Format-GeminiText` - Process Gemini formatting commands - `Test-PowerShellCodeRisk` - Analyze code for security risks - `Invoke-SafePowerShellCode` - Execute code with safety checks @@ -352,7 +352,7 @@ Invoke-SuggestCommitMessage -InstructionsFile "commit-guidelines.txt" | `cpwd` | `Set-PWDClipboard` | Copy working directory | | `tree` | `Show-DirectoryTree` | Directory tree display | | `gemini` | `Invoke-GeminiChat` | AI chat | -| `gcm` | `Invoke-SuggestCommitMessage` | AI commit message suggestions | +| `sgcm` | `Invoke-SuggestCommitMessage` | AI commit message suggestions | | `wrh` | `Write-Host` | Write to host | ## 🤝 Contributing From 0c5a371083d3f90f5d9a8e711c5d5d8f3db1460a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 12 Oct 2025 03:13:31 +0000 Subject: [PATCH 06/10] fix: Require exact 'commit' text for security to prevent accidental commits - 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> --- Microsoft.PowerShell_profile.ps1 | 6 +++--- Readme.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Microsoft.PowerShell_profile.ps1 b/Microsoft.PowerShell_profile.ps1 index 8710e8f..b697e76 100644 --- a/Microsoft.PowerShell_profile.ps1 +++ b/Microsoft.PowerShell_profile.ps1 @@ -2169,13 +2169,13 @@ Please provide ONLY the commit message, without any explanations or additional t else { # Prompt for action Write-Host "What would you like to do?" -ForegroundColor Yellow - Write-Host " [C] Commit with this message" -ForegroundColor White - Write-Host " [Any other key] Copy to clipboard" -ForegroundColor White + Write-Host " Type 'commit' to commit with this message" -ForegroundColor White + Write-Host " Press Enter (or any other input) to copy to clipboard" -ForegroundColor White Write-Host "" $action = Read-Host "Your choice" - if ($action -eq 'C' -or $action -eq 'c') { + if ($action -ceq 'commit') { try { git commit -m $suggestedMessage if ($LASTEXITCODE -eq 0) { diff --git a/Readme.md b/Readme.md index 385f154..71d94d0 100644 --- a/Readme.md +++ b/Readme.md @@ -273,7 +273,7 @@ Invoke-SuggestCommitMessage -InstructionsFile "commit-guidelines.txt" 1. Stage your changes: `git add .` 2. Run: `sgcm` 3. Review the AI-generated commit message -4. Choose action: Press `C` to commit or any other key to copy to clipboard +4. Choose action: Type `commit` to commit or press Enter to copy to clipboard ## 🛠️ System Requirements From f3c0d60f653c6c521bf6e44c795504b006e074d2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 12 Oct 2025 03:21:21 +0000 Subject: [PATCH 07/10] feat: Add verbose mode and display staged files before commit - 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> --- Microsoft.PowerShell_profile.ps1 | 67 +++++++++++++++++++++++++++++++- Readme.md | 5 +++ 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/Microsoft.PowerShell_profile.ps1 b/Microsoft.PowerShell_profile.ps1 index b697e76..ffcee98 100644 --- a/Microsoft.PowerShell_profile.ps1 +++ b/Microsoft.PowerShell_profile.ps1 @@ -1928,6 +1928,9 @@ exists and if there are staged changes before proceeding. The generated message matches the formatting, language, and style of previous commits. +Before committing, the function displays the list of staged files to ensure you are aware +of what will be committed. + .PARAMETER CommitCount Number of previous commits to analyze for style and context. Defaults to 100. @@ -1946,6 +1949,9 @@ Path to a file containing additional instructions for commit message generation. .PARAMETER ResetApiKey Forces the function to ask for a new API key, replacing the stored one. +.PARAMETER Verbose +Shows detailed information about what the function is doing at each step. Use -Verbose to enable. + .EXAMPLE Invoke-SuggestCommitMessage # Generates a commit message based on staged changes and prompts for action @@ -1962,12 +1968,16 @@ Invoke-SuggestCommitMessage -Force Invoke-SuggestCommitMessage -AdditionalInstructions "Use conventional commits format" # Adds specific instructions for message generation +.EXAMPLE +Invoke-SuggestCommitMessage -Verbose +# Shows detailed progress information + .EXAMPLE sgcm # Uses the alias to suggest a commit message #> function Invoke-SuggestCommitMessage { - [CmdletBinding()] + [CmdletBinding(SupportsShouldProcess)] param( [int]$CommitCount = 100, @@ -1983,12 +1993,14 @@ function Invoke-SuggestCommitMessage { ) # --- Check if we're in a git repository --- + Write-Verbose "Checking if current directory is a git repository..." try { $gitCheck = git rev-parse --is-inside-work-tree 2>&1 if ($LASTEXITCODE -ne 0) { Write-Host "Error: Not in a git repository." -ForegroundColor Red return } + Write-Verbose "✓ Git repository detected" } catch { Write-Host "Error: Git is not available or not in a git repository." -ForegroundColor Red @@ -1996,36 +2008,59 @@ function Invoke-SuggestCommitMessage { } # --- Check for staged changes --- + Write-Verbose "Checking for staged changes..." $stagedFiles = git diff --cached --name-only if ([string]::IsNullOrWhiteSpace($stagedFiles)) { Write-Host "Error: No staged changes found. Use 'git add' to stage files first." -ForegroundColor Yellow return } + + $stagedFilesArray = $stagedFiles -split "`n" | Where-Object { $_ } + Write-Verbose "✓ Found $($stagedFilesArray.Count) staged file(s)" + + if ($VerbosePreference -eq 'Continue') { + Write-Verbose "Staged files:" + foreach ($file in $stagedFilesArray) { + Write-Verbose " - $file" + } + } Write-Host "Analyzing staged changes and commit history..." -ForegroundColor Cyan # --- Get branch name --- + Write-Verbose "Getting current branch name..." $branchName = git rev-parse --abbrev-ref HEAD 2>&1 if ($LASTEXITCODE -ne 0) { $branchName = "unknown" } + Write-Verbose "✓ Branch: $branchName" # --- Get commit history --- + Write-Verbose "Fetching last $CommitCount commits for context..." $commitHistory = git --no-pager log --oneline -n $CommitCount 2>&1 if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($commitHistory)) { $commitHistory = "No previous commits available (new repository)" + Write-Verbose "! No previous commits found (new repository)" + } + else { + $commitCount = ($commitHistory -split "`n").Count + Write-Verbose "✓ Retrieved $commitCount commit(s) for analysis" } # --- Get staged diff --- + Write-Verbose "Getting staged diff..." $stagedDiff = git diff --cached if ([string]::IsNullOrWhiteSpace($stagedDiff)) { Write-Host "Error: Unable to get staged diff." -ForegroundColor Red return } + Write-Verbose "✓ Staged diff retrieved successfully" # --- Load additional instructions from file if provided --- + Write-Verbose "Processing additional instructions..." $additionalInstructionsText = $AdditionalInstructions if (-not [string]::IsNullOrWhiteSpace($InstructionsFile)) { + Write-Verbose "Loading instructions from file: $InstructionsFile" if (Test-Path $InstructionsFile) { $fileContent = Get-Content -Path $InstructionsFile -Raw $additionalInstructionsText = if ([string]::IsNullOrWhiteSpace($additionalInstructionsText)) { @@ -2033,6 +2068,7 @@ function Invoke-SuggestCommitMessage { } else { "$additionalInstructionsText`n`n$fileContent" } + Write-Verbose "✓ Instructions loaded from file" } else { Write-Warning "Instructions file not found: $InstructionsFile" @@ -2040,6 +2076,7 @@ function Invoke-SuggestCommitMessage { } # --- Get or Set API Key --- + Write-Verbose "Retrieving API key..." $apiKey = $null if ($ResetApiKey.IsPresent) { @@ -2067,9 +2104,14 @@ function Invoke-SuggestCommitMessage { # Store the API key securely Set-SecureApiKey -ApiKey $apiKey -KeyName "GeminiAPI" + Write-Verbose "✓ API key stored securely" + } + else { + Write-Verbose "✓ API key retrieved successfully" } # --- Prepare the prompt for Gemini --- + Write-Verbose "Preparing prompt for Gemini AI..." $promptText = @" You are a git commit message expert. Your task is to analyze the provided information and generate a concise, meaningful commit message. @@ -2096,9 +2138,12 @@ INSTRUCTIONS: $(if (-not [string]::IsNullOrWhiteSpace($additionalInstructionsText)) { "ADDITIONAL INSTRUCTIONS:`n$additionalInstructionsText`n" } else { "" }) Please provide ONLY the commit message, without any explanations or additional text. "@ + Write-Verbose "✓ Prompt prepared successfully" # --- API Setup --- + Write-Verbose "Setting up Gemini API connection..." $uri = "https://generativelanguage.googleapis.com/v1beta/models/$($Model):generateContent" + Write-Verbose "Using model: $Model" $headers = @{ "Content-Type" = "application/json" @@ -2117,9 +2162,12 @@ Please provide ONLY the commit message, without any explanations or additional t # --- API Call --- try { Write-Host "Generating commit message with model '$Model'..." -ForegroundColor Cyan + Write-Verbose "Sending request to Gemini API..." $response = Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -Body $body -ContentType "application/json" + Write-Verbose "✓ Response received from Gemini API" + if ($null -eq $response.candidates) { Write-Error "The API did not return a valid response. The content may have been blocked." return @@ -2152,7 +2200,15 @@ Please provide ONLY the commit message, without any explanations or additional t # --- Handle user action --- if ($Force.IsPresent) { + # Show staged files before auto-commit + Write-Host "Staged files to be committed:" -ForegroundColor Yellow + foreach ($file in $stagedFilesArray) { + Write-Host " • $file" -ForegroundColor Gray + } + Write-Host "" + # Auto-commit without prompting + Write-Verbose "Force mode enabled - committing automatically..." try { git commit -m $suggestedMessage if ($LASTEXITCODE -eq 0) { @@ -2167,6 +2223,13 @@ Please provide ONLY the commit message, without any explanations or additional t } } else { + # Show staged files before prompting + Write-Host "Staged files to be committed:" -ForegroundColor Yellow + foreach ($file in $stagedFilesArray) { + Write-Host " • $file" -ForegroundColor Gray + } + Write-Host "" + # Prompt for action Write-Host "What would you like to do?" -ForegroundColor Yellow Write-Host " Type 'commit' to commit with this message" -ForegroundColor White @@ -2176,6 +2239,7 @@ Please provide ONLY the commit message, without any explanations or additional t $action = Read-Host "Your choice" if ($action -ceq 'commit') { + Write-Verbose "User chose to commit - executing git commit..." try { git commit -m $suggestedMessage if ($LASTEXITCODE -eq 0) { @@ -2191,6 +2255,7 @@ Please provide ONLY the commit message, without any explanations or additional t } else { # Copy to clipboard + Write-Verbose "User chose to copy to clipboard..." try { Set-Clipboard -Value $suggestedMessage Write-Host "✓ Commit message copied to clipboard!" -ForegroundColor Green diff --git a/Readme.md b/Readme.md index 71d94d0..3a578e9 100644 --- a/Readme.md +++ b/Readme.md @@ -259,6 +259,9 @@ Invoke-SuggestCommitMessage -AdditionalInstructions "Use conventional commits fo # Load instructions from a file Invoke-SuggestCommitMessage -InstructionsFile "commit-guidelines.txt" + +# Show detailed progress information +Invoke-SuggestCommitMessage -Verbose ``` **Features:** @@ -268,6 +271,8 @@ Invoke-SuggestCommitMessage -InstructionsFile "commit-guidelines.txt" - 🎯 **Smart formatting**: Matches existing commit message patterns and conventions - ⚡ **Quick workflow**: Choose to commit immediately or copy to clipboard - 🎨 **Customizable**: Supports additional instructions and different AI models +- 📋 **Shows staged files**: Displays files to be committed before taking action +- 🔬 **Verbose mode**: Detailed progress tracking with -Verbose parameter **Workflow:** 1. Stage your changes: `git add .` From 6155f98e17606511ff35cee8eec66993186ca3dc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 12 Oct 2025 03:32:37 +0000 Subject: [PATCH 08/10] feat: Add ReturnOnly mode and interactive message refinement - 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> --- Microsoft.PowerShell_profile.ps1 | 243 ++++++++++++++++++++++++------- Readme.md | 10 +- 2 files changed, 197 insertions(+), 56 deletions(-) diff --git a/Microsoft.PowerShell_profile.ps1 b/Microsoft.PowerShell_profile.ps1 index ffcee98..a535901 100644 --- a/Microsoft.PowerShell_profile.ps1 +++ b/Microsoft.PowerShell_profile.ps1 @@ -1928,8 +1928,9 @@ exists and if there are staged changes before proceeding. The generated message matches the formatting, language, and style of previous commits. -Before committing, the function displays the list of staged files to ensure you are aware -of what will be committed. +In interactive mode, you can refine the message by providing feedback to the AI, which will +regenerate the message while maintaining context. Before committing, the function displays +the list of staged files to ensure you are aware of what will be committed. .PARAMETER CommitCount Number of previous commits to analyze for style and context. Defaults to 100. @@ -1952,9 +1953,13 @@ Forces the function to ask for a new API key, replacing the stored one. .PARAMETER Verbose Shows detailed information about what the function is doing at each step. Use -Verbose to enable. +.PARAMETER ReturnOnly +Returns only the commit message string without any user interaction or output. Useful for +integration with other functions or AI agents. + .EXAMPLE Invoke-SuggestCommitMessage -# Generates a commit message based on staged changes and prompts for action +# Generates a commit message, allows refinement, and prompts for action .EXAMPLE Invoke-SuggestCommitMessage -CommitCount 50 -Model "gemini-2.5-flash" @@ -1972,9 +1977,13 @@ Invoke-SuggestCommitMessage -AdditionalInstructions "Use conventional commits fo Invoke-SuggestCommitMessage -Verbose # Shows detailed progress information +.EXAMPLE +$msg = Invoke-SuggestCommitMessage -ReturnOnly +# Returns just the message string for use in scripts + .EXAMPLE sgcm -# Uses the alias to suggest a commit message +# Uses the alias to suggest a commit message interactively #> function Invoke-SuggestCommitMessage { [CmdletBinding(SupportsShouldProcess)] @@ -1989,7 +1998,9 @@ function Invoke-SuggestCommitMessage { [string]$InstructionsFile = "", - [switch]$ResetApiKey + [switch]$ResetApiKey, + + [switch]$ReturnOnly ) # --- Check if we're in a git repository --- @@ -1997,13 +2008,17 @@ function Invoke-SuggestCommitMessage { try { $gitCheck = git rev-parse --is-inside-work-tree 2>&1 if ($LASTEXITCODE -ne 0) { - Write-Host "Error: Not in a git repository." -ForegroundColor Red + if (-not $ReturnOnly) { + Write-Host "Error: Not in a git repository." -ForegroundColor Red + } return } Write-Verbose "✓ Git repository detected" } catch { - Write-Host "Error: Git is not available or not in a git repository." -ForegroundColor Red + if (-not $ReturnOnly) { + Write-Host "Error: Git is not available or not in a git repository." -ForegroundColor Red + } return } @@ -2011,7 +2026,9 @@ function Invoke-SuggestCommitMessage { Write-Verbose "Checking for staged changes..." $stagedFiles = git diff --cached --name-only if ([string]::IsNullOrWhiteSpace($stagedFiles)) { - Write-Host "Error: No staged changes found. Use 'git add' to stage files first." -ForegroundColor Yellow + if (-not $ReturnOnly) { + Write-Host "Error: No staged changes found. Use 'git add' to stage files first." -ForegroundColor Yellow + } return } @@ -2025,7 +2042,9 @@ function Invoke-SuggestCommitMessage { } } - Write-Host "Analyzing staged changes and commit history..." -ForegroundColor Cyan + if (-not $ReturnOnly) { + Write-Host "Analyzing staged changes and commit history..." -ForegroundColor Cyan + } # --- Get branch name --- Write-Verbose "Getting current branch name..." @@ -2150,37 +2169,82 @@ Please provide ONLY the commit message, without any explanations or additional t "X-goog-api-key" = $apiKey } - $body = @{ - contents = @( - @{ - role = "user" - parts = @(@{ text = $promptText }) - } - ) - } | ConvertTo-Json -Depth 10 - # --- API Call --- - try { - Write-Host "Generating commit message with model '$Model'..." -ForegroundColor Cyan + $chatHistory = @() + + # Function to call Gemini API (reusable for refinements) + function Invoke-GeminiForCommit { + param( + [string]$PromptText, + [array]$History = @() + ) + + $bodyContents = @() + + # Add history if exists + if ($History.Count -gt 0) { + $bodyContents += $History + } + + # Add current user message + $bodyContents += @{ + role = "user" + parts = @(@{ text = $PromptText }) + } + + $requestBody = @{ + contents = $bodyContents + } | ConvertTo-Json -Depth 10 + + if (-not $ReturnOnly) { + Write-Host "Generating commit message with model '$Model'..." -ForegroundColor Cyan + } Write-Verbose "Sending request to Gemini API..." - $response = Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -Body $body -ContentType "application/json" + $apiResponse = Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -Body $requestBody -ContentType "application/json" Write-Verbose "✓ Response received from Gemini API" - if ($null -eq $response.candidates) { + if ($null -eq $apiResponse.candidates) { + if ($ReturnOnly) { + return $null + } Write-Error "The API did not return a valid response. The content may have been blocked." - return + return $null } - $suggestedMessage = $response.candidates[0].content.parts[0].text.Trim() + $message = $apiResponse.candidates[0].content.parts[0].text.Trim() # Remove any markdown code block markers if present - $suggestedMessage = $suggestedMessage -replace '^```.*\n', '' -replace '\n```$', '' - $suggestedMessage = $suggestedMessage.Trim() + $message = $message -replace '^```.*\n', '' -replace '\n```$', '' + $message = $message.Trim() + + return $message + } + + # Initial API call + try { + $suggestedMessage = Invoke-GeminiForCommit -PromptText $promptText -History $chatHistory + + if ($null -eq $suggestedMessage) { + return + } + + # Add to chat history + $chatHistory += @{ + role = "user" + parts = @(@{ text = $promptText }) + } + $chatHistory += @{ + role = "model" + parts = @(@{ text = $suggestedMessage }) + } } catch { + if ($ReturnOnly) { + return $null + } Write-Error "An error occurred while contacting the Gemini API: $($_.Exception.Message)" if ($_.Exception.Response) { $errorBody = $_.Exception.Response.GetResponseStream() | ForEach-Object { (New-Object System.IO.StreamReader($_)).ReadToEnd() } @@ -2188,6 +2252,11 @@ Please provide ONLY the commit message, without any explanations or additional t } return } + + # --- ReturnOnly mode: just return the message --- + if ($ReturnOnly.IsPresent) { + return $suggestedMessage + } # --- Display the suggested message --- Write-Host "`n" -NoNewline @@ -2230,39 +2299,103 @@ Please provide ONLY the commit message, without any explanations or additional t } Write-Host "" - # Prompt for action - Write-Host "What would you like to do?" -ForegroundColor Yellow - Write-Host " Type 'commit' to commit with this message" -ForegroundColor White - Write-Host " Press Enter (or any other input) to copy to clipboard" -ForegroundColor White - Write-Host "" - - $action = Read-Host "Your choice" - - if ($action -ceq 'commit') { - Write-Verbose "User chose to commit - executing git commit..." - try { - git commit -m $suggestedMessage - if ($LASTEXITCODE -eq 0) { - Write-Host "✓ Changes committed successfully!" -ForegroundColor Green + # Interactive loop with refinement capability + $continueLoop = $true + while ($continueLoop) { + # Prompt for action + Write-Host "What would you like to do?" -ForegroundColor Yellow + Write-Host " Type 'commit' to commit with this message" -ForegroundColor White + Write-Host " Press Enter to copy to clipboard" -ForegroundColor White + Write-Host " Type anything else to refine the message with AI" -ForegroundColor White + Write-Host "" + + $action = Read-Host "Your choice" + + if ($action -ceq 'commit') { + # Commit with current message + Write-Verbose "User chose to commit - executing git commit..." + try { + git commit -m $suggestedMessage + if ($LASTEXITCODE -eq 0) { + Write-Host "✓ Changes committed successfully!" -ForegroundColor Green + $continueLoop = $false + } + else { + Write-Error "Failed to commit changes." + $continueLoop = $false + } } - else { - Write-Error "Failed to commit changes." + catch { + Write-Error "Error during commit: $($_.Exception.Message)" + $continueLoop = $false } } - catch { - Write-Error "Error during commit: $($_.Exception.Message)" - } - } - else { - # Copy to clipboard - Write-Verbose "User chose to copy to clipboard..." - try { - Set-Clipboard -Value $suggestedMessage - Write-Host "✓ Commit message copied to clipboard!" -ForegroundColor Green + elseif ([string]::IsNullOrWhiteSpace($action)) { + # Copy to clipboard + Write-Verbose "User chose to copy to clipboard..." + try { + Set-Clipboard -Value $suggestedMessage + Write-Host "✓ Commit message copied to clipboard!" -ForegroundColor Green + $continueLoop = $false + } + catch { + Write-Warning "Failed to copy to clipboard. Here's the message to copy manually:" + Write-Host $suggestedMessage -ForegroundColor White + $continueLoop = $false + } } - catch { - Write-Warning "Failed to copy to clipboard. Here's the message to copy manually:" - Write-Host $suggestedMessage -ForegroundColor White + else { + # Refine the message with AI + Write-Host "`nRefining commit message with your feedback..." -ForegroundColor Cyan + Write-Verbose "User provided refinement instructions: $action" + + # Build refinement prompt + $refinementPrompt = @" +The user wants to refine the commit message. Their feedback is: +"$action" + +Please generate an improved commit message based on this feedback while still: +- Accurately describing the staged changes +- Matching the language and style of previous commits +- Being concise but descriptive + +Provide ONLY the refined commit message, without any explanations. +"@ + + try { + # Call API with conversation history + $refinedMessage = Invoke-GeminiForCommit -PromptText $refinementPrompt -History $chatHistory + + if ($null -ne $refinedMessage) { + # Update message and history + $suggestedMessage = $refinedMessage + + $chatHistory += @{ + role = "user" + parts = @(@{ text = $refinementPrompt }) + } + $chatHistory += @{ + role = "model" + parts = @(@{ text = $refinedMessage }) + } + + # Display refined message + Write-Host "`n" -NoNewline + Write-Host "═══════════════════════════════════════════" -ForegroundColor Cyan + Write-Host "Refined Commit Message:" -ForegroundColor Green + Write-Host "═══════════════════════════════════════════" -ForegroundColor Cyan + Write-Host $suggestedMessage -ForegroundColor White + Write-Host "═══════════════════════════════════════════" -ForegroundColor Cyan + Write-Host "" + } + else { + Write-Warning "Failed to refine message. Keeping current message." + } + } + catch { + Write-Warning "Error during refinement: $($_.Exception.Message)" + Write-Host "Keeping current message." -ForegroundColor Yellow + } } } } diff --git a/Readme.md b/Readme.md index 3a578e9..3d78372 100644 --- a/Readme.md +++ b/Readme.md @@ -262,6 +262,9 @@ Invoke-SuggestCommitMessage -InstructionsFile "commit-guidelines.txt" # Show detailed progress information Invoke-SuggestCommitMessage -Verbose + +# Get just the message for use in scripts/automation +$commitMsg = Invoke-SuggestCommitMessage -ReturnOnly ``` **Features:** @@ -273,12 +276,17 @@ Invoke-SuggestCommitMessage -Verbose - 🎨 **Customizable**: Supports additional instructions and different AI models - 📋 **Shows staged files**: Displays files to be committed before taking action - 🔬 **Verbose mode**: Detailed progress tracking with -Verbose parameter +- 🔄 **Message refinement**: Provide feedback to regenerate the message with AI +- 🤖 **Scriptable**: Use -ReturnOnly for integration with other tools **Workflow:** 1. Stage your changes: `git add .` 2. Run: `sgcm` 3. Review the AI-generated commit message -4. Choose action: Type `commit` to commit or press Enter to copy to clipboard +4. Choose action: + - Type `commit` to commit with the message + - Press Enter to copy to clipboard + - Type feedback to refine the message (e.g., "make it shorter", "add emoji") ## 🛠️ System Requirements From b8929c9e019d0ab5552f68cc0f7bfa1ca414b009 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 12 Oct 2025 03:40:43 +0000 Subject: [PATCH 09/10] refactor: Improve output structure - show commit message closer to user 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> --- Microsoft.PowerShell_profile.ps1 | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Microsoft.PowerShell_profile.ps1 b/Microsoft.PowerShell_profile.ps1 index a535901..4d6c954 100644 --- a/Microsoft.PowerShell_profile.ps1 +++ b/Microsoft.PowerShell_profile.ps1 @@ -2292,7 +2292,7 @@ Please provide ONLY the commit message, without any explanations or additional t } } else { - # Show staged files before prompting + # Show staged files once at the beginning Write-Host "Staged files to be committed:" -ForegroundColor Yellow foreach ($file in $stagedFilesArray) { Write-Host " • $file" -ForegroundColor Gray @@ -2302,6 +2302,11 @@ Please provide ONLY the commit message, without any explanations or additional t # Interactive loop with refinement capability $continueLoop = $true while ($continueLoop) { + # Display current commit message right before prompting + Write-Host "Current commit message:" -ForegroundColor Cyan + Write-Host " $suggestedMessage" -ForegroundColor White + Write-Host "" + # Prompt for action Write-Host "What would you like to do?" -ForegroundColor Yellow Write-Host " Type 'commit' to commit with this message" -ForegroundColor White @@ -2379,13 +2384,7 @@ Provide ONLY the refined commit message, without any explanations. parts = @(@{ text = $refinedMessage }) } - # Display refined message - Write-Host "`n" -NoNewline - Write-Host "═══════════════════════════════════════════" -ForegroundColor Cyan - Write-Host "Refined Commit Message:" -ForegroundColor Green - Write-Host "═══════════════════════════════════════════" -ForegroundColor Cyan - Write-Host $suggestedMessage -ForegroundColor White - Write-Host "═══════════════════════════════════════════" -ForegroundColor Cyan + Write-Host "✓ Message refined successfully!" -ForegroundColor Green Write-Host "" } else { From 4451942c50b6a9e7909540fd70083e173bdcdae1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Cancio?= <49328080+adrian-cancio@users.noreply.github.com> Date: Sun, 12 Oct 2025 05:44:19 +0200 Subject: [PATCH 10/10] Update Microsoft.PowerShell_profile.ps1 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- Microsoft.PowerShell_profile.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Microsoft.PowerShell_profile.ps1 b/Microsoft.PowerShell_profile.ps1 index 4d6c954..9888dbc 100644 --- a/Microsoft.PowerShell_profile.ps1 +++ b/Microsoft.PowerShell_profile.ps1 @@ -2131,12 +2131,13 @@ function Invoke-SuggestCommitMessage { # --- Prepare the prompt for Gemini --- Write-Verbose "Preparing prompt for Gemini AI..." + $stagedFileCount = ($stagedFiles -split '\n' | Where-Object { $_ }).Count $promptText = @" You are a git commit message expert. Your task is to analyze the provided information and generate a concise, meaningful commit message. CONTEXT: - Branch: $branchName -- Staged files: $((($stagedFiles -split '\n' | Where-Object { $_ }).Count)) file(s) +- Staged files: $stagedFileCount file(s) PREVIOUS COMMITS (last $CommitCount): $commitHistory