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/vouch.py ADDED
@@ -0,0 +1,161 @@
1
+ """Standing inputs (src/vouch.js): VOUCHED.td trust lists, commit-pinned `/gitbills vouch <sha>` commands, and the
2
+ owner/repo#N, login and SHA syntax every command checks."""
3
+ from __future__ import annotations
4
+
5
+ import re
6
+
7
+ from .slop import fold
8
+ from .text import fail, is_hidden_code_point, js_trim, utf16_key
9
+
10
+ VOUCH_FILES = ('.github/VOUCHED.td', 'VOUCHED.td')
11
+ VOUCH_MAX_BYTES = 262_144
12
+ _A = re.ASCII
13
+ # \Z, never $: Python's $ also matches before a final newline, which JavaScript's does not.
14
+ _OWNER_RE = re.compile(r'^[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})\Z', _A)
15
+ _NAME_RE = re.compile(r'^[A-Za-z0-9_.-]{1,100}\Z', _A)
16
+ _LOGIN_RE = re.compile(r'^[A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38}\Z', _A)
17
+ # A VOUCHED.td entry: a login, or an app's bot account (dependabot[bot]), listed (or denounced) like anyone else.
18
+ _ENTRY_RE = re.compile(r'^[A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38}(?:\[bot\])?\Z', _A)
19
+ _SHA_RE = re.compile(r'^[0-9a-fA-F]{40}\Z', _A)
20
+ _SHORT_SHA_RE = re.compile(r'^[0-9a-fA-F]{4,39}\Z', _A)
21
+ _PR_URL_RE = re.compile(r'^https://(?:www\.)?(?:github|gitbills)\.com/([^/?#\x00-\x20\x7f]+)/([^/?#\x00-\x20\x7f]+)/pulls?/([0-9]{1,9})(?:[/?#][^\x00-\x20\x7f]*)?\Z', re.I | _A)
22
+ _REPO_URL_RE = re.compile(r'^https://(?:www\.)?(?:github|gitbills)\.com/([^/?#\x00-\x20\x7f]+)/([^/?#\x00-\x20\x7f]+?)(?:\.git)?/?\Z', re.I | _A)
23
+ _PR_REF_RE = re.compile(r'^([^#\x00-\x20\x7f]+)#([0-9]{1,9})\Z', _A)
24
+ # `/gitbills vouch <sha>`, or the older command name gitbills.com receipts still print (written as an escape: that name
25
+ # belongs to another product and stays out of this source).
26
+ _VOUCH_COMMENT_RE = re.compile(r'^/(?:gitbills|\x76alun)[ \t]+vouch[ \t]+([0-9a-fA-F]{40})(?:[ \t]+(--scout))?[ \t]*\Z', _A)
27
+ _REPO_HELP = 'Use OWNER/REPO (or https://github.com/OWNER/REPO): letters, digits, ., _ and -.'
28
+
29
+
30
+ def clean_repo(value) -> str:
31
+ """owner/repo, lowercased, from OWNER/REPO or a github.com / gitbills.com URL. Raises invalid_repo."""
32
+ s = js_trim(value) if isinstance(value, str) else ''
33
+ url = _REPO_URL_RE.search(s)
34
+ if url:
35
+ s = '%s/%s' % (url.group(1), url.group(2))
36
+ parts = s.split('/')
37
+ if (len(parts) != 2 or not _OWNER_RE.search(parts[0]) or not _NAME_RE.search(parts[1]) or parts[1] in ('.', '..')
38
+ or parts[1].endswith('.git')):
39
+ fail('invalid_repo', 'Not a repository: ' + _REPO_HELP)
40
+ return s.lower()
41
+
42
+
43
+ def parse_pr_ref(value) -> tuple:
44
+ """(repo, number) from owner/repo#N or a pull request URL on github.com or gitbills.com. Raises invalid_pr."""
45
+ s = js_trim(value) if isinstance(value, str) else ''
46
+ url = _PR_URL_RE.search(s)
47
+ if url:
48
+ repo, num = '%s/%s' % (url.group(1), url.group(2)), url.group(3)
49
+ else:
50
+ m = _PR_REF_RE.search(s)
51
+ if not m:
52
+ fail('invalid_pr', 'Name the pull request as OWNER/REPO#N or https://github.com/OWNER/REPO/pull/N.')
53
+ repo, num = m.group(1), m.group(2)
54
+ number = int(num)
55
+ if number < 1:
56
+ fail('invalid_pr', 'The pull request number must be 1 or more.')
57
+ return clean_repo(repo), number
58
+
59
+
60
+ def clean_login(value) -> str:
61
+ s = js_trim(value) if isinstance(value, str) else ''
62
+ if s.startswith('@'):
63
+ s = s[1:]
64
+ if not _LOGIN_RE.search(s):
65
+ fail('invalid_login', 'A GitHub login is 1 to 39 letters, digits or single hyphens, not starting or ending with a hyphen.')
66
+ return s
67
+
68
+
69
+ def clean_sha(value) -> str:
70
+ """A full 40-hex commit SHA, lowercased; short prefixes are refused. Raises invalid_sha."""
71
+ s = js_trim(value) if isinstance(value, str) else ''
72
+ if not _SHA_RE.search(s):
73
+ if _SHORT_SHA_RE.search(s):
74
+ fail('invalid_sha', '"%s" is a short SHA: a vouch pins one exact commit, so pass all 40 hex characters (git rev-parse HEAD).' % s)
75
+ fail('invalid_sha', 'Pass the full 40-hex commit SHA of the pull request head (git rev-parse HEAD, or gitbills receipt OWNER/REPO#N).')
76
+ return s.lower()
77
+
78
+
79
+ def vouch_command(sha, scout: bool = False) -> str:
80
+ return '/gitbills vouch %s%s' % (clean_sha(sha), ' --scout' if scout else '')
81
+
82
+
83
+ def parse_vouch_comment(body):
84
+ """{'sha', 'scout'} when the comment's first non-blank line is a vouch command (either name); else None."""
85
+ for raw in ('' if body is None else str(body)).split('\n'):
86
+ line = js_trim(re.sub(r'\r$', '', raw))
87
+ if line:
88
+ m = _VOUCH_COMMENT_RE.search(line)
89
+ return {'sha': m.group(1).lower(), 'scout': m.group(2) is not None} if m else None
90
+ return None
91
+
92
+
93
+ _DASHES_RE = re.compile('[\u2010-\u2015\u2212\ufe58\ufe63\uff0d]')
94
+ _LINE_SPLIT_RE = re.compile('\r\n|[\n\r\v\f\u0085\u2028\u2029]')
95
+ _DENOUNCE_RE = re.compile(r'^-[ \t]*@?([A-Za-z0-9-]{1,39})(?:[ \t]|$)', _A)
96
+ _EDGE_WS_RE = re.compile(r'^[ \t]+|[ \t]+$', _A)
97
+
98
+
99
+ def _unsafe_line(line):
100
+ return any(ord(ch) != 0x09 and is_hidden_code_point(ord(ch)) for ch in line)
101
+
102
+
103
+ def _read_entry(token):
104
+ t = token[1:] if token.startswith('@') else token
105
+ platform = 'github'
106
+ colon = t.find(':')
107
+ if colon >= 0:
108
+ platform = t[:colon].lower()
109
+ t = t[colon + 1:]
110
+ if t.startswith('@'):
111
+ t = t[1:]
112
+ if platform != 'github':
113
+ return {'other': True}
114
+ return {'login': t.lower()} if _ENTRY_RE.search(t) else None
115
+
116
+
117
+ def parse_vouched_td(text) -> dict:
118
+ """A VOUCHED.td list: `login` (or `app[bot]`) vouches, `-login` denounces (a denouncement anywhere wins)."""
119
+ vouched, denounced = set(), set()
120
+ ignored = other = unsafe = 0
121
+ lines = _LINE_SPLIT_RE.split('' if text is None else str(text))[:10_000]
122
+ if lines and lines[0].startswith('\ufeff'):
123
+ lines[0] = lines[0][1:]
124
+ for raw in lines:
125
+ line = _EDGE_WS_RE.sub('', raw)
126
+ if not line or line.startswith('#'):
127
+ continue
128
+ if _unsafe_line(line):
129
+ unsafe += 1
130
+ else:
131
+ deny = line.startswith('-')
132
+ entry = _read_entry(re.split(r'[ \t]', line[1:] if deny else line, maxsplit=1)[0])
133
+ if entry and entry.get('login'):
134
+ (denounced if deny else vouched).add(entry['login'])
135
+ continue
136
+ if entry and entry.get('other'):
137
+ other += 1
138
+ continue
139
+ folded = _DASHES_RE.sub('-', fold(line))
140
+ m = _DENOUNCE_RE.search(folded)
141
+ if m and _LOGIN_RE.search(m.group(1)):
142
+ denounced.add(m.group(1).lower())
143
+ else:
144
+ ignored += 1
145
+ d = sorted(denounced, key=utf16_key)
146
+ v = sorted((x for x in vouched if x not in denounced), key=utf16_key)
147
+ return {'vouched': v, 'denounced': d, 'ignored_lines': ignored, 'other_platform_lines': other, 'unsafe_lines': unsafe}
148
+
149
+
150
+ def lookup_vouched_td(lst, login) -> str:
151
+ """'denounced', 'vouched' or 'unlisted' for a login in a VOUCHED.td text or parse_vouched_td result."""
152
+ parsed = parse_vouched_td(lst) if isinstance(lst, str) else lst
153
+ who = js_trim(login) if isinstance(login, str) else ''
154
+ if who.startswith('@'):
155
+ who = who[1:]
156
+ who = who.lower()
157
+ if not _ENTRY_RE.search(who):
158
+ return 'unlisted'
159
+ if who in parsed['denounced']:
160
+ return 'denounced'
161
+ return 'vouched' if who in parsed['vouched'] else 'unlisted'
@@ -0,0 +1,82 @@
1
+ Metadata-Version: 2.4
2
+ Name: gitbills
3
+ Version: 0.1.2
4
+ Summary: Offline PR security X-Ray (14 rules), anti-slop and AGENTS.md policy preflight, queue triage and contributor standing for GitHub pull requests. Standard library only.
5
+ Author: Fitz Doud
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://gitbills.com
8
+ Project-URL: Repository, https://github.com/fitzss/gitbills
9
+ Project-URL: Issues, https://github.com/fitzss/gitbills/issues
10
+ Keywords: github,pull-requests,security,code-review,agents-md,ai-agents,preflight,triage
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Topic :: Security
18
+ Classifier: Topic :: Software Development :: Quality Assurance
19
+ Classifier: Topic :: Software Development :: Version Control :: Git
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Dynamic: license-file
24
+
25
+ # gitbills
26
+
27
+ **Security X-Ray, AGENTS.md policy, queue triage and contributor standing for GitHub pull requests.**
28
+ A CLI for contributors and their coding agents, a GitHub Action for maintainers. Zero dependencies: Node 18+ or
29
+ Python 3.10+, MIT.
30
+
31
+ ```sh
32
+ npx --yes github:fitzss/gitbills#v0.1.2 preflight # Node
33
+ uvx --from git+https://github.com/fitzss/gitbills@v0.1.2 gitbills preflight # Python: same answers, byte for byte
34
+ ```
35
+
36
+ Both run tag `v0.1.2` straight from GitHub. The `gitbills` names on npm and PyPI are not published yet: never install
37
+ `gitbills` by name until this README says so ([pinned installs](docs/usage.md)).
38
+
39
+ `preflight` reads your branch's diff and the base branch's `AGENTS.md`, decides in about a millisecond and **sends
40
+ nothing**: [14 security rules](docs/rules.md), slop heuristics and the [AGENTS.md policy](docs/agents-md.md). Exit `0`:
41
+ open the pull request. Exit `1`: fix what it lists first. Exit `2`: it could not check (pass `--base`).
42
+
43
+ ## Commands
44
+
45
+ - `gitbills preflight [--base REF | --diff FILE] [--title T] [--body-file F] [--markdown | --json]`: offline.
46
+ - `gitbills policy [PATH | OWNER/REPO] [--init [--write]]`: read, print or add the AGENTS.md policy section.
47
+ - `gitbills triage OWNER/REPO`, `gitbills receipt OWNER/REPO#N`, `gitbills standing LOGIN`: read gitbills.com.
48
+ - `gitbills vouch OWNER/REPO#N SHA [--scout] [--post]`: a vouch for one exact 40-hex commit (`--post` uses `gh`).
49
+
50
+ **Replace hub with bills**: `github.com/OWNER/REPO` -> `gitbills.com/OWNER/REPO`.
51
+
52
+ ## GitHub Action
53
+
54
+ ```yaml
55
+ on:
56
+ pull_request_target: # the workflow comes from the base branch, so a pull request cannot replace the gate
57
+ permissions: {contents: read, pull-requests: write, statuses: write}
58
+ jobs:
59
+ gate:
60
+ runs-on: ubuntu-latest
61
+ steps:
62
+ - uses: fitzss/gitbills@v0.1.2 # pin the release's commit SHA; never add a checkout of the pull request here
63
+ ```
64
+
65
+ No checkout and no pull request code run: [docs/github-action.md](docs/github-action.md).
66
+
67
+ ## Executable AGENTS.md
68
+
69
+ `gitbills policy --init --write` appends rules that people and agents read, and `preflight` and the Action enforce:
70
+
71
+ ```md
72
+ ## Pull requests from agents
73
+ - Preflight: run `npx --yes github:fitzss/gitbills#v0.1.2 preflight --markdown` and paste its receipt into the PR body.
74
+ - Max files changed: 25
75
+ - Max lines changed: 800
76
+ - Tests: required for code changes
77
+ - Protected paths: .github/workflows/, LICENSE
78
+ ```
79
+
80
+ The `agents: ...` block gitbills.com suggests reads the same way, with or without bullets:
81
+ [docs/agents-md.md](docs/agents-md.md). For agents: [SKILL.md](SKILL.md) and a
82
+ [Claude Code hook](integrations/claude-code/gitbills-preflight.md).
@@ -0,0 +1,19 @@
1
+ gitbills/__init__.py,sha256=v8hWMfRwb2Y36yXlfcA37VGq8_ok5TEYOQmzatePihE,2436
2
+ gitbills/__main__.py,sha256=k1ocEWawweo1qCJWNFAAvyxz3tcY13dzvCenHszij30,48
3
+ gitbills/cli.py,sha256=Ftd4CpQfq8wSVaXOskbp45__gTQoB2KEfjrLWkpFrOQ,19768
4
+ gitbills/diff.py,sha256=mUjjvEqACr5Y8iGJGZ2q26JBWzIxkIh2qtFalWtC-V8,10580
5
+ gitbills/local.py,sha256=dkWWqZEg28QvcLm3i3MaiPjqVc2yfsdgB-CT7rryNLw,19278
6
+ gitbills/policy.py,sha256=GUKFnEIlsUUz0w4gj275h_e4P9is35-RKJAUSaAo5mg,22780
7
+ gitbills/preflight.py,sha256=nrglOEXEyLploP0zImcX6CT-H0WQXMQ0KzgWOaGlDoc,12058
8
+ gitbills/remote.py,sha256=1y4AfkYDlxBXNUhDNJGqtp2aEWIhm6ClCb67lekD4kI,31921
9
+ gitbills/scan.py,sha256=P_Y_RS1eD09hFc9lUAkltBHcUgcVJiAmeQ0EqD7xNpk,28329
10
+ gitbills/slop.py,sha256=JdlZOWLDL6FINwJ4ZtVOs_2mKiLGt_8ZTC-cqhN4GL0,23243
11
+ gitbills/text.py,sha256=4Dq7sv9TSZVM1sJa5d_XcLvHGlKSG7MpjYgH3CkyhU4,3540
12
+ gitbills/version.py,sha256=3IUD5KFvPdOl2FiljAyxeJ2XDdEW5fMeiAbQvvJL6bw,289
13
+ gitbills/vouch.py,sha256=QWsh4-lWYIeqbu7yTppflfq9wTupm7vOr2294ripBYU,7196
14
+ gitbills-0.1.2.dist-info/licenses/LICENSE,sha256=P-MI71MFZfZykac083N9pzTmVBCESiNY_TSI2qxVuDI,1066
15
+ gitbills-0.1.2.dist-info/METADATA,sha256=sD7rAj-QPuyz9kUYiSF3Yvr3QYLIve84qjtJGFvPfkE,3761
16
+ gitbills-0.1.2.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
17
+ gitbills-0.1.2.dist-info/entry_points.txt,sha256=fj8xuRUZlcFLJx9puZqGkGf6zZaPIAJrmi5rDYi7s7E,47
18
+ gitbills-0.1.2.dist-info/top_level.txt,sha256=4TPT0e9bgqcpnzQYEf-VcnfhTTrMkejfgFX5_YKObYo,9
19
+ gitbills-0.1.2.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ gitbills = gitbills.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Fitz Doud
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ gitbills