Repository navigation
Expand file tree
/
Copy pathattribution_contributing.go
More file actions
44 lines (41 loc) · 3.06 KB
/
Copy pathattribution_contributing.go
File metadata and controls
44 lines (41 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package exec
import (
"regexp"
"strings"
)
var contributingSentence = regexp.MustCompile(`[.!?;]\s+|\n+`)
var contributingDottedAI = regexp.MustCompile(`\ba\.i\.`)
var contributingAttribution = regexp.MustCompile(`\b(?:trailer\w*|attribution\w*|co-authored-by|co-authored|coauthored|co-author\w*|assisted-by|generated-by|generated with|generated by|footer\w*)\b`)
var contributingAI = regexp.MustCompile(`(?:\ba\.i\.|\b(?:ai|ai-generated|ai-assisted|llm\w*|assistant\w*|agent\w*|bots?|copilot|claude|chatgpt|gpt\w*|codeaf|machine-generated|assisted-by|generated-by)\b)`)
var contributingProhibition = regexp.MustCompile(`\b(?:do not|don't|dont|never|must not|mustn't|should not|shouldn't|may not|cannot|can't|not allowed|not permitted|not accepted|forbid\w*|prohibit\w*|bans?|banned|refrain|avoid|remove|strip|omit|delete|drop|edit out|take out|reject\w*)\b`)
var contributingRequirement = regexp.MustCompile(`\b(?:without|with no|missing|lack\w*|must include|must add|must contain|must have|must carry|required|require|requires|mandatory|please add|please include|should include|should add|always add|always include|keep|preserve|retain|leave\b[^.!?;\n]*\bin place)\b`)
var contributingNegatedRemoval = regexp.MustCompile(`\b(?:do not|don't|dont|never|must not|mustn't|should not|shouldn't|may not|cannot|can't)(?:\s+[\w-]+){0,2}\s+(?:remove|strip|omit|delete|drop|edit out|take out)\b`)
var contributingNegatedKeeping = regexp.MustCompile(`\b(?:do not|don't|dont|never|must not|mustn't|should not|shouldn't|may not|cannot|can't)(?:\s+[\w-]+){0,2}\s+(?:keep|preserve|retain|leave\b[^.!?;\n]*\bin place)\b`)
var contributingNo = regexp.MustCompile(`\bno(?:\s+[\w-]+){0,2}\s+(?:trailers?|attributions?|co-authored-by|co-authored|coauthored|co-authors?|assisted-by|generated-by|generated|footers?|ai|a\.i\.|llms?|assistants?|agents?|bots?|copilot|claude|chatgpt|gpt[\w-]*|codeaf|machine-generated)\b`)
// ContributingRefusesTrailers conservatively reads a repository's own ban on
// AI attribution. A requirement to add or keep a trailer wins over negative
// wording such as "do not submit code without one" or "do not remove it" in
// the same sentence: neither asks the harness to omit attribution.
func ContributingRefusesTrailers(text string) bool {
// Keep A.I. together before periods followed by spaces separate sentences.
text = contributingDottedAI.ReplaceAllString(strings.ToLower(text), "ai")
for _, sentence := range contributingSentence.Split(text, -1) {
sentence = strings.Map(func(r rune) rune {
if strings.ContainsRune("*_`~", r) {
return -1
}
return r
}, sentence)
// A negated keeping verb is itself a ban, while a negated removal
// verb asks that attribution stay on the work.
if contributingNegatedRemoval.MatchString(sentence) ||
(contributingRequirement.MatchString(sentence) && !contributingNegatedKeeping.MatchString(sentence)) {
continue
}
if contributingAttribution.MatchString(sentence) && contributingAI.MatchString(sentence) &&
(contributingProhibition.MatchString(sentence) || contributingNo.MatchString(sentence)) {
return true
}
}
return false
}