-
Notifications
You must be signed in to change notification settings - Fork 2
Add support to detect Assisted-By trailer #33
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
Open
omkar-foss
wants to merge
1
commit into
chaoss:main
Choose a base branch
from
omkar-foss:support-assistedby-trailer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+288
−15
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package assistedby | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "regexp" | ||
| "strings" | ||
|
|
||
| "github.com/chaoss/ai-detection-action/detection" | ||
| ) | ||
|
|
||
| var assistedByPattern = regexp.MustCompile(`(?im)^assisted-by\s*:\s*([^\r\n]+?)\s*$`) | ||
| var toolLineReplacePattern = regexp.MustCompile(`\s*<[^>]+>`) | ||
|
|
||
| func getMatchedTools(toolLine string) []string { | ||
| toolLine = strings.TrimSpace(toolLine) | ||
| if toolLine == "" { | ||
| return nil | ||
| } | ||
| toolLine = toolLineReplacePattern.ReplaceAllString(toolLine, "") | ||
| parts := strings.Split(toolLine, "\n") | ||
| var tools []string | ||
| for _, p := range parts { | ||
| p = strings.TrimSpace(strings.Split(strings.TrimSpace(p), "(")[0]) | ||
| if p == "" { | ||
| continue | ||
| } | ||
| words := strings.Fields(p) | ||
| for i, w := range words { | ||
| if len(w) > 0 { | ||
| words[i] = strings.ToUpper(w[:1]) + w[1:] | ||
| } | ||
| } | ||
| tools = append(tools, strings.Join(words, " ")) | ||
| } | ||
| return tools | ||
| } | ||
|
|
||
| type Detector struct{} | ||
|
|
||
| func (d *Detector) Name() string { return "assistedby" } | ||
|
|
||
| func (d *Detector) Detect(input detection.Input) []detection.Finding { | ||
| if input.CommitMessage == "" { | ||
| return nil | ||
| } | ||
|
|
||
| matches := assistedByPattern.FindAllStringSubmatch( | ||
| input.CommitMessage, | ||
| -1, | ||
| ) | ||
|
|
||
| if len(matches) == 0 { | ||
| return nil | ||
| } | ||
|
|
||
| var findings []detection.Finding | ||
|
|
||
| for _, match := range matches { | ||
| if len(match) < 2 { | ||
| continue | ||
| } | ||
|
|
||
| for _, matchedTool := range getMatchedTools(match[1]) { | ||
| findings = append(findings, detection.Finding{ | ||
| Detector: d.Name(), | ||
| Tool: matchedTool, | ||
| Confidence: detection.ConfidenceHigh, | ||
| Detail: fmt.Sprintf( | ||
| "Assisted-By trailer with tool %s", | ||
| matchedTool, | ||
| ), | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| return findings | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| package assistedby | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/chaoss/ai-detection-action/detection" | ||
| ) | ||
|
|
||
| func TestDetect(t *testing.T) { | ||
| d := &Detector{} | ||
| tests := []struct { | ||
| name string | ||
| message string | ||
| wantTools []string | ||
| }{ | ||
| { | ||
| name: "Claude trailer with Opus model", | ||
| message: "fix: update handler\n\nAssisted-By: Claude Opus 4 <noreply@anthropic.com>", | ||
| wantTools: []string{"Claude Opus 4"}, | ||
| }, | ||
| { | ||
| name: "Claude trailer with Sonnet model", | ||
| message: "fix: update handler\n\nAssisted-By: Claude Sonnet 4 <noreply@anthropic.com>", | ||
| wantTools: []string{"Claude Sonnet 4"}, | ||
| }, | ||
| { | ||
| name: "Cursor trailer", | ||
| message: "refactor: extract method\n\nAssisted-By: Cursor <cursoragent@cursor.com>", | ||
| wantTools: []string{"Cursor"}, | ||
| }, | ||
| { | ||
| name: "Aider trailer with model name", | ||
| message: "feat: add endpoint\n\nAssisted-By: aider (gpt-4o) <noreply@aider.chat>", | ||
| wantTools: []string{"Aider"}, | ||
| }, | ||
| { | ||
| name: "Aider trailer with different model", | ||
| message: "feat: add endpoint\n\nAssisted-By: aider (claude-4.7-opus) <noreply@aider.chat>", | ||
| wantTools: []string{"Aider"}, | ||
| }, | ||
| { | ||
| name: "multiple trailers with Claude and human", | ||
| message: "fix: bug\n\nAssisted-By: Claude Opus 4 <noreply@anthropic.com>", | ||
| wantTools: []string{"Claude Opus 4"}, | ||
| }, | ||
| { | ||
| name: "multiple AI trailers", | ||
| message: "fix: bug\n\nAssisted-By: Claude Opus 4 <noreply@anthropic.com>\nAssisted-By: aider (gpt-4o) <noreply@aider.chat>", | ||
| wantTools: []string{"Claude Opus 4", "Aider"}, | ||
| }, | ||
| { | ||
| name: "case variation", | ||
| message: "fix: something\n\nassisted-by: Claude <noreply@anthropic.com>", | ||
| wantTools: []string{"Claude"}, | ||
| }, | ||
| { | ||
| name: "ASSISTED-BY uppercase", | ||
| message: "fix: something\n\nASSISTED-BY: Claude <noreply@anthropic.com>", | ||
| wantTools: []string{"Claude"}, | ||
| }, | ||
| { | ||
| name: "Assisted-By trailer in commit message", | ||
| message: "this is a commit message with\nAssisted-By: Claude Code", | ||
| wantTools: []string{"Claude Code"}, | ||
| }, | ||
| { | ||
| name: "Another Assisted-By trailer in commit message 1", | ||
| message: "this is a commit message with\nAssisted-By: Gemini", | ||
| wantTools: []string{"Gemini"}, | ||
| }, | ||
| { | ||
| name: "Another Assisted-By trailer in commit message 2", | ||
| message: "this is a commit message with\nAssisted-By: Kimi K2.6", | ||
| wantTools: []string{"Kimi K2.6"}, | ||
| }, | ||
| { | ||
| name: "Multiple Assisted-By trailer in commit message", | ||
| message: "this is a commit message with\nAssisted-By: Claude Code\nAssisted-By: Gemini", | ||
| wantTools: []string{"Claude Code", "Gemini"}, | ||
| }, | ||
| { | ||
| name: "Multiple Assisted-By trailers (with purpose brackets) in commit message", | ||
| message: ` | ||
| this is a commit message | ||
|
|
||
| Co-Authored-By: Cursor <cursoragent@cursor.com> | ||
|
|
||
| Assisted-by: Claude 4.7 Opus | ||
| (logic optimization and design fixes) | ||
| Assisted-by: Kimi K2.6 (unit tests, integration tests) | ||
| Assisted-by: ChatGPT (documentation review) | ||
| Assisted-by: Gemini (documentation) | ||
| `, | ||
| wantTools: []string{"Claude 4.7 Opus", "Kimi K2.6", "ChatGPT", "Gemini"}, | ||
| }, | ||
| { | ||
| name: "Assisted-By trailer in commit message in lower case", | ||
| message: "this is a commit message with\nassisted-by: Claude Code", | ||
| wantTools: []string{"Claude Code"}, | ||
| }, | ||
| { | ||
| name: "Two different attributions (assistedby and coauthor) both with email address", | ||
| message: "Fix bug\n\nAssisted-By: Claude Sonnet 4 <noreply@anthropic.com>\nCo-Authored-By: Copilot <copilot@github.com>", | ||
| wantTools: []string{"Claude Sonnet 4"}, | ||
| }, | ||
| { | ||
| name: "Two different attributions (assistedby and coauthor) one with model name, other with email address", | ||
| message: "Add validation logic\n\nCo-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>\nAssisted-by: GitHub Copilot", | ||
| wantTools: []string{"GitHub Copilot"}, | ||
| }, | ||
| { | ||
| name: "Claude Opus model attribution trailer", | ||
| message: "Fix bug\n\nAssisted-by: Claude Opus 4 <noreply@anthropic.com>", | ||
| wantTools: []string{"Claude Opus 4"}, | ||
| }, | ||
| { | ||
| name: "no trailers", | ||
| message: "just a normal commit message", | ||
| wantTools: nil, | ||
| }, | ||
| { | ||
| name: "empty message", | ||
| message: "", | ||
| wantTools: nil, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| findings := d.Detect(detection.Input{CommitMessage: tt.message}) | ||
| gotTools := make([]string, len(findings)) | ||
| for i, f := range findings { | ||
| gotTools[i] = f.Tool | ||
| if f.Confidence != detection.ConfidenceHigh { | ||
| t.Errorf("confidence = %d, want %d", f.Confidence, detection.ConfidenceHigh) | ||
| } | ||
| if f.Detector != "assistedby" { | ||
| t.Errorf("detector = %q, want %q", f.Detector, "assistedby") | ||
| } | ||
| } | ||
|
|
||
| if len(gotTools) == 0 { | ||
| gotTools = nil | ||
| } | ||
|
|
||
| if len(gotTools) != len(tt.wantTools) { | ||
| t.Errorf("tools = %v, want %v", gotTools, tt.wantTools) | ||
| return | ||
| } | ||
| for i := range gotTools { | ||
| if gotTools[i] != tt.wantTools[i] { | ||
| t.Errorf("tools = %v, want %v", gotTools, tt.wantTools) | ||
| return | ||
| } | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Tool has been changed to Cursor here as commit 4 (instead of 2) is being read now, see this updated test commit which has both Co-Authored-By and multiple Assisted-By.