From d6c34a740cfc664306a1ef448d3499300c4f3674 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 15 May 2026 22:23:01 +0000 Subject: [PATCH] Handle Cursor co-author trailer format in commit hook Agent-Logs-Url: https://github.com/BenjaminMichaelis/Config/sessions/adad97af-2dd9-4d6a-ad35-a3499ee102c2 Co-authored-by: BenjaminMichaelis <22186029+BenjaminMichaelis@users.noreply.github.com> --- git-hooks/commit-msg | 4 ++-- git-hooks/commit-msg.ps1 | 4 ++-- git-hooks/tests/commit-msg.Tests.ps1 | 13 +++++++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/git-hooks/commit-msg b/git-hooks/commit-msg index eff9d7c..f5555c0 100755 --- a/git-hooks/commit-msg +++ b/git-hooks/commit-msg @@ -19,10 +19,10 @@ MARKER_PATTERN='^[[:space:]]*(made-with|generated-by|suggested-by)[[:space:]]*:' # 2. Co-authored-by lines where the author name starts with a known AI tool # The trailing ([[:space:]]|<|$) ensures we match whole words (e.g. "Claude" # but also "Claude Opus 4.6" while not matching a hypothetical "Claudette"). -AI_NAMES_PATTERN='^[[:space:]]*co-authored?-by[[:space:]]*:[[:space:]]*(github[[:space:]]+copilot|copilot|claude|amazon[[:space:]]+q|amazon[[:space:]]+codewhisperer|codewhisperer|gemini|chatgpt|gpt-?[[:digit:]]+|codeium|tabnine|windsurf|opencode)([[:space:]]|<|$)' +AI_NAMES_PATTERN='^[[:space:]]*co-authored?-by[[:space:]]*:[[:space:]]*(github[[:space:]]+copilot|copilot|claude|amazon[[:space:]]+q|amazon[[:space:]]+codewhisperer|codewhisperer|gemini|chatgpt|gpt-?[[:digit:]]+|cursor|codeium|tabnine|windsurf|opencode)([[:space:]]|<|$)' # 3. Co-authored-by lines whose email domain belongs to a known AI provider -AI_EMAIL_PATTERN='^[[:space:]]*co-authored?-by[[:space:]]*:.*<[^>]*@(anthropic\.com|cursor\.sh|codeium\.com|cognition\.ai)[^>]*>' +AI_EMAIL_PATTERN='^[[:space:]]*co-authored?-by[[:space:]]*:.*[:space:]]*@(anthropic\.com|cursor\.sh|cursor\.com|codeium\.com|cognition\.ai)[^>[:space:]]*>?' tmp=$(mktemp) || exit 1 trap 'rm -f "$tmp"' EXIT diff --git a/git-hooks/commit-msg.ps1 b/git-hooks/commit-msg.ps1 index 6ad44de..4b0b982 100644 --- a/git-hooks/commit-msg.ps1 +++ b/git-hooks/commit-msg.ps1 @@ -30,10 +30,10 @@ function Remove-AITrailers { # 2. Co-authored-by where the name starts with a known AI tool # The trailing (\s|<|$) keeps whole-word matching so "Claude" still # matches "Claude Opus 4.6" but won't silently drop "Claudette Smith". - $aiNamesPattern = '^\s*co-authored?-by\s*:\s*(github\s+copilot|copilot|claude|amazon\s+q|amazon\s+codewhisperer|codewhisperer|gemini|chatgpt|gpt-?\d+|codeium|tabnine|windsurf|opencode)(\s|<|$)' + $aiNamesPattern = '^\s*co-authored?-by\s*:\s*(github\s+copilot|copilot|claude|amazon\s+q|amazon\s+codewhisperer|codewhisperer|gemini|chatgpt|gpt-?\d+|cursor|codeium|tabnine|windsurf|opencode)(\s|<|$)' # 3. Co-authored-by whose email domain belongs to a known AI provider - $aiEmailPattern = '^\s*co-authored?-by\s*:.*<[^>]*@(anthropic\.com|cursor\.sh|codeium\.com|cognition\.ai)[^>]*>' + $aiEmailPattern = '^\s*co-authored?-by\s*:.*\s]*@(anthropic\.com|cursor\.sh|cursor\.com|codeium\.com|cognition\.ai)[^>\s]*>?' $filtered = [System.Collections.Generic.List[string]]::new() foreach ($line in $Lines) { diff --git a/git-hooks/tests/commit-msg.Tests.ps1 b/git-hooks/tests/commit-msg.Tests.ps1 index 76958ea..a49ce82 100644 --- a/git-hooks/tests/commit-msg.Tests.ps1 +++ b/git-hooks/tests/commit-msg.Tests.ps1 @@ -183,6 +183,12 @@ Describe 'Remove-AITrailers' { $result = Remove-AITrailers -Lines $lines $result | Should -Not -Match 'cursor\.sh' } + + It 'removes Co-authored-by: Cursor cursoragent@cursor.com' { + $lines = @('Fix bug', '', 'Co-authored-by: Cursor cursoragent@cursor.com') + $result = Remove-AITrailers -Lines $lines + $result | Should -Not -Match 'cursoragent@cursor\.com' + } } Context 'Codeium Co-authored-by is removed' { @@ -418,6 +424,13 @@ Describe 'commit-msg bash hook (end-to-end)' -Skip:($IsWindows -or -not (Get-Com $result | Should -Match 'Alice Smith' } + It 'removes Cursor co-author without angle brackets' { + $content = "Fix bug`n`nCo-authored-by: Cursor cursoragent@cursor.com`n" + $result = Invoke-BashHook $content + $result | Should -Not -Match 'cursoragent@cursor\.com' + $result.Trim() | Should -Be 'Fix bug' + } + It 'removes AI and preserves human in mixed message' { $content = "Fix bug`n`nCo-authored-by: Alice Smith `nCo-authored-by: GitHub Copilot `n" $result = Invoke-BashHook $content