gitbills 0.1.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gitbills/__init__.py +29 -0
- gitbills/__main__.py +3 -0
- gitbills/cli.py +417 -0
- gitbills/diff.py +268 -0
- gitbills/local.py +436 -0
- gitbills/policy.py +449 -0
- gitbills/preflight.py +219 -0
- gitbills/remote.py +676 -0
- gitbills/scan.py +392 -0
- gitbills/slop.py +423 -0
- gitbills/text.py +103 -0
- gitbills/version.py +4 -0
- gitbills/vouch.py +161 -0
- gitbills-0.1.2.dist-info/METADATA +82 -0
- gitbills-0.1.2.dist-info/RECORD +19 -0
- gitbills-0.1.2.dist-info/WHEEL +5 -0
- gitbills-0.1.2.dist-info/entry_points.txt +2 -0
- gitbills-0.1.2.dist-info/licenses/LICENSE +21 -0
- gitbills-0.1.2.dist-info/top_level.txt +1 -0
gitbills/slop.py
ADDED
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
"""Anti-slop heuristics (src/slop.js): deterministic signs of low-effort or machine-farmed pull requests.
|
|
2
|
+
|
|
3
|
+
Each reason carries points; a score of 50 or more is slop.
|
|
4
|
+
"""
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import re
|
|
8
|
+
import unicodedata
|
|
9
|
+
|
|
10
|
+
from .text import js_slice, utf16_key
|
|
11
|
+
|
|
12
|
+
SLOP_THRESHOLD = 50
|
|
13
|
+
SLOP_POINTS = {
|
|
14
|
+
'empty_or_unparseable_diff': 80,
|
|
15
|
+
'homoglyph_or_invisible_path_obfuscation': 80,
|
|
16
|
+
'ai_scratch_or_solution_artifact': 75,
|
|
17
|
+
'autonomous_spam_agent_signature': 65,
|
|
18
|
+
'bounty_payout_spam': 65,
|
|
19
|
+
'escaped_newline_bot_template': 65,
|
|
20
|
+
'leaked_llm_refusal_or_placeholder': 85,
|
|
21
|
+
'leaked_llm_tool_call_stub': 85,
|
|
22
|
+
'gitignore_ai_tool_spam': 75,
|
|
23
|
+
'config_only_claiming_code_fix': 70,
|
|
24
|
+
'unexplained_config_ignore_driveby': 60,
|
|
25
|
+
'docs_only_claiming_code_fix': 65,
|
|
26
|
+
'cosmetic_or_comment_only_bugfix_claim': 60,
|
|
27
|
+
'trivial_comment_typo_farming': 55,
|
|
28
|
+
'lockfile_or_generated_only_bloat': 65,
|
|
29
|
+
'test_skip_or_only_introduced': 70,
|
|
30
|
+
'test_assertion_deletion': 70,
|
|
31
|
+
'tautology_only_test_assertions': 70,
|
|
32
|
+
'hallucinated_codebase_claim': 65,
|
|
33
|
+
'generic_llm_pr_boilerplate': 35,
|
|
34
|
+
}
|
|
35
|
+
SLOP_REMEDIATIONS = {
|
|
36
|
+
'empty_or_unparseable_diff': 'Check a real unified diff (git diff output): no file change could be read from this one.',
|
|
37
|
+
'homoglyph_or_invisible_path_obfuscation': 'Rename the file in plain ASCII: lookalike letters or invisible characters in a path hide what it is.',
|
|
38
|
+
'ai_scratch_or_solution_artifact': 'Leave AI scratch and agent files (CLAUDE.md, .cursor/, .aider*, solution.md, stray .patch files) out of the commit.',
|
|
39
|
+
'autonomous_spam_agent_signature': 'Remove the autonomous-agent signature from the title and body; say what changed and why.',
|
|
40
|
+
'bounty_payout_spam': 'Remove payout, payment-address and bounty-claim lines from the title and body.',
|
|
41
|
+
'escaped_newline_bot_template': 'Rewrite the body as plain Markdown: it reads as a bot template with escaped newlines.',
|
|
42
|
+
'leaked_llm_refusal_or_placeholder': 'Delete the leaked model refusal or placeholder text, and finish the change.',
|
|
43
|
+
'leaked_llm_tool_call_stub': 'Delete files that hold only an unexecuted tool call (read_file, write_file, run_terminal_cmd).',
|
|
44
|
+
'gitignore_ai_tool_spam': 'Keep AI-tool ignore lines out of a fix: use .git/info/exclude, or send a chore pull request of its own.',
|
|
45
|
+
'config_only_claiming_code_fix': 'Only config or ignore files change here: drop the fix claim, or include the code change.',
|
|
46
|
+
'unexplained_config_ignore_driveby': 'Explain the config or ignore change in the pull request body, or leave it out.',
|
|
47
|
+
'docs_only_claiming_code_fix': 'Docs alone fix no code issue: include the code and test change, or title the pull request as docs.',
|
|
48
|
+
'cosmetic_or_comment_only_bugfix_claim': 'Comments, renames and whitespace fix no bug: make the real code change, with a test.',
|
|
49
|
+
'trivial_comment_typo_farming': 'Fold small comment or typo edits into a meaningful change instead of a pull request of their own.',
|
|
50
|
+
'lockfile_or_generated_only_bloat': 'Lockfile or generated changes alone fix no issue: include the source change, or title it chore(deps).',
|
|
51
|
+
'test_skip_or_only_introduced': 'Remove the added skip or only marker, and fix the test instead of silencing it.',
|
|
52
|
+
'test_assertion_deletion': 'Restore the deleted assertions: weakening a test is no fix.',
|
|
53
|
+
'tautology_only_test_assertions': 'Replace always-true assertions (assert True, 1 == 1) with checks of real behavior.',
|
|
54
|
+
'hallucinated_codebase_claim': 'Check that every new path and claim matches this codebase; remove invented files and CVSS scores.',
|
|
55
|
+
'generic_llm_pr_boilerplate': 'Replace the generic AI pull request text with what changed, why, and how it was tested.',
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
_A = re.ASCII
|
|
59
|
+
_I = re.IGNORECASE | re.ASCII
|
|
60
|
+
_INVISIBLE_RE = re.compile('[\u00ad\u034f\u061c\u180e\u200b-\u200f\u202a-\u202e\u2060-\u2069\ufeff]')
|
|
61
|
+
_CONFUSABLES = {
|
|
62
|
+
'\u0430': 'a', '\u0435': 'e', '\u043e': 'o', '\u0440': 'p', '\u0441': 'c', '\u0445': 'x', '\u0443': 'y',
|
|
63
|
+
'\u0456': 'i', '\u0458': 'j', '\u0455': 's', '\u04bb': 'h', '\u0501': 'd', '\u0410': 'A', '\u0412': 'B',
|
|
64
|
+
'\u0415': 'E', '\u041a': 'K', '\u041c': 'M', '\u041d': 'H', '\u041e': 'O', '\u0420': 'P', '\u0421': 'C',
|
|
65
|
+
'\u0422': 'T', '\u0425': 'X', '\u0406': 'I', '\u03b1': 'a', '\u03bf': 'o', '\u03c1': 'p', '\u03b5': 'e',
|
|
66
|
+
'\u03ba': 'k', '\u03bd': 'v', '\u017f': 's', '\u212a': 'K',
|
|
67
|
+
}
|
|
68
|
+
_CONFUSABLE_RE = re.compile('[%s]' % ''.join(_CONFUSABLES))
|
|
69
|
+
_TRIM = '\t\n\v\f\r \u00a0\ufeff'
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def ascii_trim(value) -> str:
|
|
73
|
+
return ('' if value is None else str(value)).strip(_TRIM)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def fold(value) -> str:
|
|
77
|
+
s = js_slice('' if value is None else str(value), 65_536)
|
|
78
|
+
s = unicodedata.normalize('NFKC', _INVISIBLE_RE.sub('', s))
|
|
79
|
+
return _CONFUSABLE_RE.sub(lambda m: _CONFUSABLES[m.group(0)], s)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _low(p):
|
|
83
|
+
return fold(p).lower()
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
_SPAM_SIGNATURE_RE = re.compile(r'autonomous[ \t]+fix[ \t]+by[ \t]+[a-z0-9_-]+[ \t]+ai[ \t]+agent|submitted[ \t]+by[ \t]+[a-z0-9_ -]+ai[ \t]+agent[ \t]*[\u2014-][ \t]*autonomous[ \t]+bounty[ \t]+solver|deliverable[ \t]+submitted[ \t]+via[ \t]+task[ \t]+pipeline|generated[ \t]+automatically[ \t]+by[ \t]+[a-z0-9_-]+[ \t]+bounty[ \t]+bot', _I)
|
|
87
|
+
_PAYOUT_RE = re.compile(r'<!--[ \t]*(?:issuehunt|algora|gitcoin|polar|opire|boss)-payout[ \t]*:|#bounty[ \t]*\([ \t]*(?:algora|polar|issuehunt|gitcoin|opire)(?![A-Za-z0-9_])|(?:eth|usdt|btc|sol)(?:[ \t]+(?:payment|address))?[ \t]*:[ \t]*`?0x[0-9a-f]{40}|paypal[ \t]*:[ \t]*[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}', _I)
|
|
88
|
+
_ESCAPED_BOT_RE = re.compile(r'^##[ \t]+[A-Za-z]+\\n[^\n]{10,}\\n(?:Fixes|Closes|Resolves)[ \t]+#', _A)
|
|
89
|
+
_BOILERPLATE_RE = re.compile(r'updated[ \t]+`?readme\.md`?[ \t]+to[ \t]+address[ \t]+the[ \t]+reported[ \t]+issue|verified[ \t]+the[ \t]+change[ \t]+resolves[ \t]+the[ \t]+described[ \t]+problem[^\n]{0,120}no[ \t]+breaking[ \t]+changes[ \t]+introduced', _I)
|
|
90
|
+
_REFUSAL_RE = re.compile(r"as[ \t]+an[ \t]+ai[ \t]+language[ \t]+model[, \t]+i[ \t]+cannot|i'm[ \t]+sorry,[ \t]+i[ \t]+can't[ \t]+assist[ \t]+with|your_private_key_here|\[insert[ \t]+(?:your[ \t]+)?(?:code|implementation)[ \t]+here\]", _I)
|
|
91
|
+
_TOOL_CALL_RE = re.compile(r'''^[ \t]*(?:file_read|read_file|write_file|run_terminal_cmd)\([ \t]*['"][^'"]+['"][ \t]*\)[ \t]*$''', _A)
|
|
92
|
+
_CLOSES_RE = re.compile(r'(?:^|[^A-Za-z0-9_])(?:fix(?:es|ed)?|clos(?:es|ed)|resolv(?:es|ed))[ \t]+#[0-9]+(?![0-9A-Za-z_])', _I)
|
|
93
|
+
_CODE_CLAIM_TITLE_RE = re.compile(r'^[ \t]*(?:(?:fix|feat|refactor|security)(?:\([a-z0-9_./-]+\))?[ \t]*:|fix(?:es|ed)?[ \t]+[a-z])|bounty[ \t]*(?:bill|#|\()|security[ \t]+patch', _I)
|
|
94
|
+
_DOC_SCOPED_TITLE_RE = re.compile(r'^[ \t]*(?:docs?|fix\([ \t]*(?:docs?|readme|changelog|typo|spelling)[ \t]*\))[ \t]*:', _I)
|
|
95
|
+
_DOC_INTENT_TITLE_RE = re.compile(r'(?:^|[^A-Za-z0-9_])(?:docs?|documentation|readme|changelog|broken[ \t]+link)(?![A-Za-z0-9_])', _I)
|
|
96
|
+
_HYGIENE_TITLE_RE = re.compile(r'^[ \t]*(?:chore|ci|build|style)(?:\([a-z0-9_.-]+\))?[ \t]*:', _I)
|
|
97
|
+
_ADVISORY_RE = re.compile(r'(?:^|[^A-Za-z0-9_])(?:yanked|advisories|cargo[ \t]+deny|ghsa-[a-z0-9]{4}|cve-[0-9]{4}-[0-9]+|rustsec-[0-9]{4})', _I)
|
|
98
|
+
_DEPS_TITLE_RE = re.compile(r'^[ \t]*(?:(?:fix|chore|build|ci|deps)\((?:deps|deps-dev|dev-deps|dependencies|lockfile|cargo|npm|pnpm|uv|pip)\)[ \t]*:|(?:update|bump|upgrade|pin|refresh)[ \t][^\n]{0,80}(?:[ \t]to[ \t]+v?[0-9]|lock[ \t]*file|dependenc)|lock[ \t]*file[ \t]+maintenance)|\[security\]', _I)
|
|
99
|
+
_PY_PROSE_RE = re.compile(r'''^[A-Za-z_][A-Za-z0-9_,'".:` -]*:[ \t]+[A-Za-z]+[ \t]+[a-z]+[ \t]+[a-z]+|^[A-Za-z,'".:` -]{12,}$''', _A)
|
|
100
|
+
_FAKE_CVSS_RE = re.compile(r'(?:^|[^A-Za-z0-9_])CVSS[ \t]*3\.[01](?![0-9A-Za-z_])', _I)
|
|
101
|
+
_SKIP_RE = re.compile(r'^[ \t]*(?:(?:it|test|describe)[ \t]*\.[ \t]*(?:skip|only)[ \t]*\(|(?:xit|xtest|xdescribe)[ \t]*\(|@[ \t]*(?:unittest[ \t]*\.[ \t]*skip(?:If|Unless)?|pytest[ \t]*\.[ \t]*mark[ \t]*\.[ \t]*skip(?:if)?)(?![A-Za-z0-9_]))', _A)
|
|
102
|
+
_CONDITIONAL_SKIP_RE = re.compile(r'(?:skipif|skipIf|skipUnless)[ \t]*\((?![ \t]*(?:True|1)[ \t]*[,)])', _A)
|
|
103
|
+
_ASSERT_RE = re.compile(r'(?:^|[^A-Za-z0-9_])(?:assert(?:\.[A-Za-z]+|Equal|NotEqual|True|False|Raises|In|NotIn|IsNone|IsNotNone|Greater|GreaterEqual|Less|LessEqual)?|expect[ \t]*\(|assert_eq!|assert!)', _A)
|
|
104
|
+
_TAUTOLOGY_RE = re.compile(r'''^[ \t]*(?:assert[ \t]+(?:True|1[ \t]*==[ \t]*1|['"]ok['"][ \t]*==[ \t]*['"]ok['"])[ \t]*$|self\.assertTrue\([ \t]*True[ \t]*\)[ \t]*$|self\.assertEqual\([ \t]*(?:1,[ \t]*1|['"]ok['"],[ \t]*['"]ok['"]|True,[ \t]*True)[ \t]*\)[ \t]*$|(?:assert\.(?:equal|strictEqual)\([ \t]*(?:1,[ \t]*1|true,[ \t]*true)[ \t]*\)|expect\([ \t]*(?:true|1)[ \t]*\)\.toBe\([ \t]*(?:true|1)[ \t]*\))[ \t]*;?[ \t]*$)''', _A)
|
|
105
|
+
_TEST_DEF_RE = re.compile(r'^[ \t]*(?:(?:async[ \t]+)?def[ \t]+test|(?:it|test|describe)[ \t]*(?:\.[A-Za-z]+)?[ \t]*\(|fn[ \t]+test_|#\[(?:tokio::)?test|func[ \t]+Test)', _A)
|
|
106
|
+
_NOOP_RE = re.compile(r'''^(?:pass|;|return[ \t]*;?|export[ \t]+const[ \t]+_[A-Za-z0-9_]*[ \t]*=[ \t]*[0-9'"]+;[ \t]*|_[A-Za-z0-9_]*[ \t]*=[ \t]*[0-9'"]+)$''', _A)
|
|
107
|
+
_KNOWN_ROOTS = ('src/', 'lib/', 'libs/', 'crates/', 'packages/', 'pkg/', 'internal/', 'cmd/', 'app/', 'apps/', 'test/',
|
|
108
|
+
'tests/', '__tests__/', 'spec/', 'scripts/', 'docs/', 'examples/', '.github/', 'benchmarks/', 'tools/',
|
|
109
|
+
'include/', 'bin/', 'python/', 'js/', 'readme.md', 'changelog.md', 'contributing.md', 'security.md',
|
|
110
|
+
'license', 'pyproject.toml', 'package.json', 'cargo.toml', 'go.mod', 'makefile', 'dockerfile',
|
|
111
|
+
'.gitignore', 'action.yml')
|
|
112
|
+
_KEYWORDS = {'if', 'else', 'for', 'while', 'return', 'function', 'const', 'let', 'var', 'export', 'import', 'from',
|
|
113
|
+
'async', 'await', 'throw', 'new', 'try', 'catch', 'finally', 'class', 'def', 'None', 'True', 'False', 'true',
|
|
114
|
+
'false', 'null', 'undefined', 'in', 'not', 'and', 'or', 'is', 'raise', 'with', 'as', 'typeof'}
|
|
115
|
+
_OBFUSCATION_RE = re.compile('[\u00ad\u034f\u061c\u180e\u200b-\u200f\u202a-\u202e\u2060-\u2069\ufeff]')
|
|
116
|
+
_FULLWIDTH_RE = re.compile('[\uff01-\uff5e]')
|
|
117
|
+
_ALPHA_RE = re.compile(r'[A-Za-z]', _A)
|
|
118
|
+
_DOC_LEAF_RE = re.compile(r'^(?:readme|changelog|contributing|history|code_of_conduct|security|authors|license)(?:[._-][a-z0-9_-]+)?(?:\.(?:md|mdx|rst|txt))?\Z', _A)
|
|
119
|
+
_DOC_EXT_RE = re.compile(r'\.(?:md|mdx|rst|txt)\Z', _A)
|
|
120
|
+
_TEST_LEAF_RE = re.compile(r'(?:_test\.|\.test\.|_spec\.|\.spec\.|^test_)', _A)
|
|
121
|
+
_AI_LEAF_RE = re.compile(r'^(?:[a-z0-9_-]*_solution_[0-9a-z_.-]*|task-[0-9a-z_-]*-deliverable\.md|[a-z0-9_-]+-deliverable\.md)\Z', _A)
|
|
122
|
+
_CODE_EXT_RE = re.compile(r'\.(?:js|mjs|cjs|ts|tsx|jsx|py|rs|go|zig|java|kt|scala|swift|c|cc|cpp|h|hpp|rb|php|cs|lua|ex|exs)\Z', _A)
|
|
123
|
+
_SYNTAX_RE = re.compile(r'[=()[\]{};]|^(?:def|class|return|import|from|if|elif|else|for|while|with|try|except|raise|assert)(?![A-Za-z0-9_])', _A)
|
|
124
|
+
_TOKEN_RE = re.compile(r'[A-Za-z_][A-Za-z0-9_]*', _A)
|
|
125
|
+
_UPPER_RE = re.compile(r'^[A-Z][A-Z0-9_]+$', _A)
|
|
126
|
+
_WS_RUN_RE = re.compile(r'[ \t]+', _A)
|
|
127
|
+
_DOCSTRINGS_RE = re.compile(r'(?:^|[^A-Za-z0-9_])docstrings?(?![A-Za-z0-9_])', _I)
|
|
128
|
+
_AI_IGNORE_RE = re.compile(r'^[ \t]*\.(?:aider|cursor|windsurf|claude)', _A)
|
|
129
|
+
_HARD_CLAIM_RE = re.compile(r'bounty[ \t]*(?:bill|#)|security[ \t]+patch|updated[ \t]+`?readme\.md`?[ \t]+to[ \t]+address', _I)
|
|
130
|
+
_FIX_TITLE_RE = re.compile(r'^[ \t]*fix(?:\([a-z0-9_.-]+\))?[ \t]*:', _I)
|
|
131
|
+
_BOUNTY_RE = re.compile(r'bounty', _I)
|
|
132
|
+
_PATCH_DIRS = ('patches', '.patches', 'patch', 'compat', 'third_party', 'thirdparty', 'vendor', 'ports', 'debian', 'rpm')
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _leaf(p):
|
|
136
|
+
return p.split('/')[-1]
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def _is_obfuscated_path(raw):
|
|
140
|
+
s = '' if raw is None else str(raw)
|
|
141
|
+
if _OBFUSCATION_RE.search(s):
|
|
142
|
+
return True
|
|
143
|
+
return any((_ALPHA_RE.search(seg) and _CONFUSABLE_RE.search(seg)) or _FULLWIDTH_RE.search(seg) for seg in s.split('/'))
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def is_doc_file(p) -> bool:
|
|
147
|
+
low = _low(p)
|
|
148
|
+
if (low.startswith('docs/') or low.startswith('doc/')) and _DOC_EXT_RE.search(low):
|
|
149
|
+
return True
|
|
150
|
+
return bool(_DOC_LEAF_RE.search(_leaf(low)))
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def is_test_file(p) -> bool:
|
|
154
|
+
parts = _low(p).split('/')
|
|
155
|
+
if any(s in ('test', 'tests', '__tests__', 'spec', 'specs') for s in parts):
|
|
156
|
+
return True
|
|
157
|
+
return bool(_TEST_LEAF_RE.search(parts[-1]))
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def _is_lock_file(p):
|
|
161
|
+
low = _low(p)
|
|
162
|
+
if _leaf(low) in ('package-lock.json', 'yarn.lock', 'pnpm-lock.yaml', 'poetry.lock', 'cargo.lock', 'uv.lock',
|
|
163
|
+
'composer.lock', 'go.sum'):
|
|
164
|
+
return True
|
|
165
|
+
return low.startswith('dist/') or low.startswith('build/') or low.endswith('.min.js') or low.endswith('.min.css')
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def is_ai_artifact(p) -> bool:
|
|
169
|
+
low = _low(p)
|
|
170
|
+
parts = low.split('/')
|
|
171
|
+
name = parts[-1]
|
|
172
|
+
if any(s.startswith('.aider') or s.startswith('.cursor') or s.startswith('.windsurf') or s == '.claude' for s in parts):
|
|
173
|
+
return True
|
|
174
|
+
if name in ('claude.md', 'fix_summary.md', 'solution.md', 'solution.txt', '.ds_store'):
|
|
175
|
+
return True
|
|
176
|
+
if _AI_LEAF_RE.search(name):
|
|
177
|
+
return True
|
|
178
|
+
return ((name.endswith('.patch') or name.endswith('.diff')) and not is_test_file(low) and 'fixture' not in low
|
|
179
|
+
and not any(s in _PATCH_DIRS for s in parts[:-1]))
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def _is_config_only(p):
|
|
183
|
+
return _leaf(_low(p)) in ('.gitignore', '.editorconfig', '.prettierrc', '.prettierrc.json', '.prettierignore', '.gitattributes')
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def is_code_file(p) -> bool:
|
|
187
|
+
low = _low(p)
|
|
188
|
+
return not low.endswith('.d.ts') and bool(_CODE_EXT_RE.search(low))
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def _strip_comments(lines, py):
|
|
192
|
+
out = []
|
|
193
|
+
block = False
|
|
194
|
+
triple = None
|
|
195
|
+
for raw in lines:
|
|
196
|
+
t = ascii_trim(raw)
|
|
197
|
+
if not t:
|
|
198
|
+
continue
|
|
199
|
+
if py:
|
|
200
|
+
if triple:
|
|
201
|
+
if triple in t:
|
|
202
|
+
triple = None
|
|
203
|
+
continue
|
|
204
|
+
if t.startswith('"""') or t.startswith("'''"):
|
|
205
|
+
d = t[:3]
|
|
206
|
+
if d not in t[3:]:
|
|
207
|
+
triple = d
|
|
208
|
+
continue
|
|
209
|
+
if t.startswith('#'):
|
|
210
|
+
continue
|
|
211
|
+
out.append(t)
|
|
212
|
+
else:
|
|
213
|
+
if block:
|
|
214
|
+
if '*/' in t:
|
|
215
|
+
block = False
|
|
216
|
+
continue
|
|
217
|
+
if t.startswith('/*'):
|
|
218
|
+
if '*/' not in t:
|
|
219
|
+
block = True
|
|
220
|
+
continue
|
|
221
|
+
if t.startswith('//'):
|
|
222
|
+
continue
|
|
223
|
+
if t == '*' or t.startswith('*/') or (t.startswith('* ') and '=' not in t and ';' not in t):
|
|
224
|
+
continue
|
|
225
|
+
out.append(t)
|
|
226
|
+
return out
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def _skeleton(lines):
|
|
230
|
+
rows = []
|
|
231
|
+
for ln in lines:
|
|
232
|
+
out = []
|
|
233
|
+
last = 0
|
|
234
|
+
for m in _TOKEN_RE.finditer(ln):
|
|
235
|
+
tok, start, end = m.group(0), m.start(), m.end()
|
|
236
|
+
out.append(ln[last:start])
|
|
237
|
+
k = end
|
|
238
|
+
while k < len(ln) and ln[k] in ' \t':
|
|
239
|
+
k += 1
|
|
240
|
+
keep = (tok in _KEYWORDS or (start > 0 and ln[start - 1] == '.') or (k < len(ln) and ln[k] == '(')
|
|
241
|
+
or (len(tok) >= 2 and _UPPER_RE.search(tok)))
|
|
242
|
+
out.append(tok if keep else '$id')
|
|
243
|
+
last = end
|
|
244
|
+
out.append(ln[last:])
|
|
245
|
+
rows.append(_WS_RUN_RE.sub(' ', ''.join(out)))
|
|
246
|
+
return '\n'.join(rows)
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def _added_text(f):
|
|
250
|
+
return [a['text'] for a in f['added']]
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def _comment_only(f, docstrings):
|
|
254
|
+
py = _low(f['path'] or '').endswith('.py')
|
|
255
|
+
a, r = _strip_comments(_added_text(f), py), _strip_comments(f['removed'], py)
|
|
256
|
+
if not a and not r:
|
|
257
|
+
return True
|
|
258
|
+
if py and docstrings:
|
|
259
|
+
both = a + r
|
|
260
|
+
syntax = any(_SYNTAX_RE.search(ln) for ln in both)
|
|
261
|
+
if not syntax and both and all(_PY_PROSE_RE.search(ln) for ln in both):
|
|
262
|
+
return True
|
|
263
|
+
return False
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def _substantive(f, noise, docstrings):
|
|
267
|
+
if _comment_only(f, docstrings):
|
|
268
|
+
return False
|
|
269
|
+
py = _low(f['path'] or '').endswith('.py')
|
|
270
|
+
a, r = _strip_comments(_added_text(f), py), _strip_comments(f['removed'], py)
|
|
271
|
+
if len(a) == len(r) and _skeleton(a) == _skeleton(r):
|
|
272
|
+
return False
|
|
273
|
+
if noise and not r and len(a) <= 2 and all(_NOOP_RE.search(ln) for ln in a):
|
|
274
|
+
return False
|
|
275
|
+
return True
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def evaluate_slop(parsed, title='', body='', known_ai_config_roots=()) -> dict:
|
|
279
|
+
"""Score a parsed diff with its title and body: score, threshold, slop_detected, reasons."""
|
|
280
|
+
t = fold(js_slice(str(title), 4096))
|
|
281
|
+
b = fold(js_slice(str(body), 32_768))
|
|
282
|
+
meta = t + '\n' + b
|
|
283
|
+
files = parsed['files']
|
|
284
|
+
reasons: dict = {}
|
|
285
|
+
|
|
286
|
+
def add(code):
|
|
287
|
+
reasons[code] = SLOP_POINTS[code]
|
|
288
|
+
|
|
289
|
+
touches_tests = any(is_test_file(p) for p in parsed['paths'])
|
|
290
|
+
if not parsed['paths']:
|
|
291
|
+
add('empty_or_unparseable_diff')
|
|
292
|
+
if any(_is_obfuscated_path(p) for p in parsed['paths']):
|
|
293
|
+
add('homoglyph_or_invisible_path_obfuscation')
|
|
294
|
+
|
|
295
|
+
roots = [_low(r) for r in known_ai_config_roots]
|
|
296
|
+
|
|
297
|
+
def under_root(p):
|
|
298
|
+
return any(p.startswith(r) if r.endswith('/') else p == r for r in roots)
|
|
299
|
+
|
|
300
|
+
def introduced_ai(f):
|
|
301
|
+
if not f['newPath'] or f['isDeleted'] or not is_ai_artifact(f['newPath']):
|
|
302
|
+
return False
|
|
303
|
+
introduced = f['isNew'] or (f['renamedFrom'] is not None and not is_ai_artifact(f['renamedFrom']))
|
|
304
|
+
return introduced and not under_root(_low(f['newPath']))
|
|
305
|
+
|
|
306
|
+
if any(introduced_ai(f) for f in files):
|
|
307
|
+
add('ai_scratch_or_solution_artifact')
|
|
308
|
+
if _SPAM_SIGNATURE_RE.search(meta):
|
|
309
|
+
add('autonomous_spam_agent_signature')
|
|
310
|
+
if _PAYOUT_RE.search(meta):
|
|
311
|
+
add('bounty_payout_spam')
|
|
312
|
+
if _ESCAPED_BOT_RE.search(b):
|
|
313
|
+
add('escaped_newline_bot_template')
|
|
314
|
+
all_added = '\n'.join(fold(a['text']) for f in files for a in f['added'])
|
|
315
|
+
if _REFUSAL_RE.search(all_added) or _REFUSAL_RE.search(b):
|
|
316
|
+
add('leaked_llm_refusal_or_placeholder')
|
|
317
|
+
if any(f['isNew'] and 1 <= len(f['added']) <= 3
|
|
318
|
+
and all(not ascii_trim(a['text']) or _TOOL_CALL_RE.search(fold(a['text'])) for a in f['added']) for f in files):
|
|
319
|
+
add('leaked_llm_tool_call_stub')
|
|
320
|
+
|
|
321
|
+
stripped = ''
|
|
322
|
+
i = 0
|
|
323
|
+
while i < len(b):
|
|
324
|
+
s = b.find('<!--', i)
|
|
325
|
+
if s < 0:
|
|
326
|
+
stripped += b[i:]
|
|
327
|
+
break
|
|
328
|
+
stripped += b[i:s] + ' '
|
|
329
|
+
e = b.find('-->', s + 4)
|
|
330
|
+
if e < 0:
|
|
331
|
+
break
|
|
332
|
+
i = e + 3
|
|
333
|
+
meta_no_comments = t + '\n' + stripped
|
|
334
|
+
claims_fix = bool(_CLOSES_RE.search(meta_no_comments) or _CODE_CLAIM_TITLE_RE.search(t))
|
|
335
|
+
hygiene = bool(_HYGIENE_TITLE_RE.search(t))
|
|
336
|
+
docs_ok = bool(_DOC_SCOPED_TITLE_RE.search(t) or (_DOC_INTENT_TITLE_RE.search(t) and not _BOUNTY_RE.search(meta)))
|
|
337
|
+
|
|
338
|
+
def path_of(f):
|
|
339
|
+
return f['path'] or ''
|
|
340
|
+
|
|
341
|
+
def is_move(f):
|
|
342
|
+
return f['renamedFrom'] is not None and not f['added'] and not f['removed']
|
|
343
|
+
|
|
344
|
+
config_files = [f for f in files if _is_config_only(path_of(f))]
|
|
345
|
+
doc_files = [f for f in files if is_doc_file(path_of(f))]
|
|
346
|
+
lock_files = [f for f in files if _is_lock_file(path_of(f))]
|
|
347
|
+
test_files = [f for f in files if is_test_file(path_of(f))]
|
|
348
|
+
moves = [f for f in files if is_move(f) and not is_ai_artifact(f['newPath'] or '')]
|
|
349
|
+
code_files = [f for f in files if is_code_file(path_of(f)) and not is_test_file(path_of(f))
|
|
350
|
+
and not _is_lock_file(path_of(f)) and not is_move(f)]
|
|
351
|
+
other_files = [f for f in files if not _is_config_only(path_of(f)) and not is_doc_file(path_of(f))
|
|
352
|
+
and not _is_lock_file(path_of(f)) and not is_test_file(path_of(f))
|
|
353
|
+
and not is_code_file(path_of(f)) and not is_ai_artifact(path_of(f))]
|
|
354
|
+
docstrings = bool(_DOCSTRINGS_RE.search(meta))
|
|
355
|
+
noise = bool(config_files or doc_files or lock_files)
|
|
356
|
+
real_code = [f for f in code_files if _substantive(f, noise, docstrings)]
|
|
357
|
+
all_comments = bool(code_files) and all(_comment_only(f, docstrings) for f in code_files)
|
|
358
|
+
real_work = bool(real_code or test_files or other_files or moves)
|
|
359
|
+
|
|
360
|
+
adds_ai_ignore = any(_AI_IGNORE_RE.search(fold(a['text'])) for f in config_files for a in f['added'])
|
|
361
|
+
if adds_ai_ignore and claims_fix and not hygiene:
|
|
362
|
+
add('gitignore_ai_tool_spam')
|
|
363
|
+
elif not real_work and config_files and not doc_files and not lock_files and not code_files:
|
|
364
|
+
if claims_fix and not hygiene:
|
|
365
|
+
add('config_only_claiming_code_fix')
|
|
366
|
+
elif ascii_trim(b) == '' and not hygiene:
|
|
367
|
+
add('unexplained_config_ignore_driveby')
|
|
368
|
+
elif not real_work and config_files and (doc_files or lock_files) and claims_fix and not docs_ok and not hygiene:
|
|
369
|
+
add('config_only_claiming_code_fix')
|
|
370
|
+
if not real_work and doc_files and not code_files:
|
|
371
|
+
hard_claim = bool(_HARD_CLAIM_RE.search(meta))
|
|
372
|
+
code_claim = hard_claim or bool(_FIX_TITLE_RE.search(t) and _CLOSES_RE.search(meta_no_comments) and not docs_ok)
|
|
373
|
+
if hard_claim or (not docs_ok and code_claim):
|
|
374
|
+
add('docs_only_claiming_code_fix')
|
|
375
|
+
if code_files and not real_code and not touches_tests and not other_files:
|
|
376
|
+
if claims_fix and not hygiene:
|
|
377
|
+
add('cosmetic_or_comment_only_bugfix_claim')
|
|
378
|
+
elif all_comments and not doc_files and not config_files and parsed['linesAdded'] <= 6:
|
|
379
|
+
add('trivial_comment_typo_farming')
|
|
380
|
+
deps_maintenance = bool(_DEPS_TITLE_RE.search(t) or _ADVISORY_RE.search(meta))
|
|
381
|
+
if (claims_fix and not hygiene and not deps_maintenance and not real_work and lock_files and not code_files
|
|
382
|
+
and ((not doc_files and not config_files) or not docs_ok)):
|
|
383
|
+
add('lockfile_or_generated_only_bloat')
|
|
384
|
+
|
|
385
|
+
added_all = [a['text'] for f in files for a in f['added']]
|
|
386
|
+
removed_all = [r for f in files for r in f['removed']]
|
|
387
|
+
|
|
388
|
+
def unconditional_skip(ln):
|
|
389
|
+
return bool(_SKIP_RE.search(ln)) and not _CONDITIONAL_SKIP_RE.search(ln)
|
|
390
|
+
|
|
391
|
+
if any(unconditional_skip(ln) for ln in added_all) and not any(unconditional_skip(ln) for ln in removed_all):
|
|
392
|
+
add('test_skip_or_only_introduced')
|
|
393
|
+
if test_files and not real_code and not other_files:
|
|
394
|
+
plus = [ln for f in test_files for ln in _added_text(f) if _ASSERT_RE.search(ln)]
|
|
395
|
+
minus = [ln for f in test_files for ln in f['removed'] if _ASSERT_RE.search(ln)]
|
|
396
|
+
dropped = any(f['isDeleted'] or any(_TEST_DEF_RE.search(ln) for ln in f['removed']) for f in test_files)
|
|
397
|
+
if minus and not plus and not dropped:
|
|
398
|
+
add('test_assertion_deletion')
|
|
399
|
+
elif plus and all(_TAUTOLOGY_RE.search(ln) for ln in plus):
|
|
400
|
+
add('tautology_only_test_assertions')
|
|
401
|
+
# Top-level folders and files this diff shows already exist; every path is folded once (linear in the diff).
|
|
402
|
+
known = set(_KNOWN_ROOTS)
|
|
403
|
+
for f in files:
|
|
404
|
+
if not f['isNew'] and f['oldPath']:
|
|
405
|
+
low = _low(f['oldPath'])
|
|
406
|
+
slash = low.find('/')
|
|
407
|
+
if slash > 0:
|
|
408
|
+
known.add(low[:slash + 1])
|
|
409
|
+
|
|
410
|
+
def outside(p):
|
|
411
|
+
low = _low(p)
|
|
412
|
+
slash = low.find('/')
|
|
413
|
+
return low not in known and not (slash > 0 and low[:slash + 1] in known)
|
|
414
|
+
|
|
415
|
+
new_outside = any(f['isNew'] and f['newPath'] and outside(f['newPath']) for f in files)
|
|
416
|
+
if new_outside and (_FAKE_CVSS_RE.search(meta) or _BOILERPLATE_RE.search(meta)):
|
|
417
|
+
add('hallucinated_codebase_claim')
|
|
418
|
+
if _BOILERPLATE_RE.search(meta):
|
|
419
|
+
add('generic_llm_pr_boilerplate')
|
|
420
|
+
|
|
421
|
+
codes = sorted(reasons, key=utf16_key)
|
|
422
|
+
score = min(100, sum(reasons[c] for c in codes))
|
|
423
|
+
return {'score': score, 'threshold': SLOP_THRESHOLD, 'slop_detected': score >= SLOP_THRESHOLD, 'reasons': codes}
|
gitbills/text.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"""Text helpers shared by every command (src/text.js): display text, Markdown code spans, ASCII JSON, SHA-256.
|
|
2
|
+
|
|
3
|
+
JavaScript measures and slices strings in UTF-16 code units and trims a fixed whitespace set; the js_* helpers do the
|
|
4
|
+
same here, so both implementations give the same answer byte for byte.
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import hashlib
|
|
9
|
+
import json
|
|
10
|
+
import re
|
|
11
|
+
|
|
12
|
+
_HIDDEN_RANGES = (
|
|
13
|
+
(0x00, 0x1F), (0x7F, 0x9F), (0xAD, 0xAD), (0x34F, 0x34F), (0x61C, 0x61C), (0x115F, 0x1160), (0x17B4, 0x17B5),
|
|
14
|
+
(0x180E, 0x180E), (0x200B, 0x200F), (0x2028, 0x202E), (0x2060, 0x206F), (0x3164, 0x3164), (0xD800, 0xDFFF),
|
|
15
|
+
(0xFEFF, 0xFEFF), (0xFFA0, 0xFFA0), (0xFFF9, 0xFFFB), (0xE0000, 0xE007F),
|
|
16
|
+
)
|
|
17
|
+
_SPACE_LIKE = {0x09, 0x0A, 0x0B, 0x0C, 0x0D}
|
|
18
|
+
# What JavaScript's String.prototype.trim removes.
|
|
19
|
+
JS_WS = ''.join(chr(c) for c in (0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x20, 0xA0, 0x1680, *range(0x2000, 0x200B), 0x2028,
|
|
20
|
+
0x2029, 0x202F, 0x205F, 0x3000, 0xFEFF))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class GitBillsError(Exception):
|
|
24
|
+
"""An error with a stable code (invalid_repo, diff_too_large, not_found, ...)."""
|
|
25
|
+
|
|
26
|
+
def __init__(self, code: str, message: str):
|
|
27
|
+
super().__init__(message)
|
|
28
|
+
self.code = code
|
|
29
|
+
self.message = message
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def fail(code: str, message: str):
|
|
33
|
+
raise GitBillsError(code, message)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def is_hidden_code_point(cp: int) -> bool:
|
|
37
|
+
return any(a <= cp <= b for a, b in _HIDDEN_RANGES)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def js_trim(s: str) -> str:
|
|
41
|
+
return s.strip(JS_WS)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def js_len(s: str) -> int:
|
|
45
|
+
"""Length in UTF-16 code units (JavaScript's .length)."""
|
|
46
|
+
return len(s.encode('utf-16-le', 'surrogatepass')) // 2
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def js_slice(s: str, n: int) -> str:
|
|
50
|
+
"""The first n UTF-16 code units (JavaScript's s.slice(0, n)); may end in half a surrogate pair, as there."""
|
|
51
|
+
if len(s) <= n // 2 or js_len(s) <= n:
|
|
52
|
+
return s
|
|
53
|
+
return s.encode('utf-16-le', 'surrogatepass')[:2 * n].decode('utf-16-le', 'surrogatepass')
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def utf16_key(s: str) -> bytes:
|
|
57
|
+
"""Sort key in UTF-16 code-unit order (JavaScript's default string sort)."""
|
|
58
|
+
return s.encode('utf-16-be', 'surrogatepass')
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def display_text(value, max_len: int = 200) -> str:
|
|
62
|
+
"""One line of untrusted text: tabs and line breaks as spaces, hidden characters as [U+XXXX], max_len code points."""
|
|
63
|
+
out = []
|
|
64
|
+
for n, ch in enumerate('' if value is None else str(value)):
|
|
65
|
+
if n == max_len:
|
|
66
|
+
out.append('...')
|
|
67
|
+
break
|
|
68
|
+
cp = ord(ch)
|
|
69
|
+
out.append(' ' if cp in _SPACE_LIKE else '[U+%04X]' % cp if is_hidden_code_point(cp) else ch)
|
|
70
|
+
return js_trim(''.join(out))
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def md_code(value, max_len: int = 120) -> str:
|
|
74
|
+
"""Untrusted text as one Markdown code span: nothing in it can render, link or mention."""
|
|
75
|
+
s = display_text(value, max_len).replace('`', "'").replace('|', '/')
|
|
76
|
+
return '`%s`' % (s or '?')
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def ascii_json(value) -> str:
|
|
80
|
+
return json.dumps(value, indent=2, ensure_ascii=True)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def sha256_hex(data) -> str:
|
|
84
|
+
return hashlib.sha256(data.encode('utf-8') if isinstance(data, str) else data).hexdigest()
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
_SURROGATE_RE = re.compile('[\ud800-\udfff]')
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def has_lone_surrogate(s: str) -> bool:
|
|
91
|
+
return _SURROGATE_RE.search(s) is not None
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def decode_utf8(data: bytes) -> str:
|
|
95
|
+
"""Bytes as text: UTF-8, invalid sequences replaced, a leading byte-order mark kept."""
|
|
96
|
+
return data.decode('utf-8', 'replace')
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def js_num(x) -> str:
|
|
100
|
+
"""A number as JavaScript prints it (20, not 20.0)."""
|
|
101
|
+
if isinstance(x, float) and x.is_integer():
|
|
102
|
+
return str(int(x))
|
|
103
|
+
return str(x)
|
gitbills/version.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"""The release this source is, and the commands that run exactly that release from its GitHub tag (src/version.js)."""
|
|
2
|
+
VERSION = '0.1.2'
|
|
3
|
+
NPX_COMMAND = 'npx --yes github:fitzss/gitbills#v%s' % VERSION
|
|
4
|
+
UVX_COMMAND = 'uvx --from git+https://github.com/fitzss/gitbills@v%s gitbills' % VERSION
|