commit-check 2.24.2__py3-none-any.whl → 2.25.0__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.
- commit_check/agent_config.py +558 -0
- commit_check/agent_configs.toml +111 -0
- commit_check/ci.py +3 -1
- commit_check/config_merger.py +26 -0
- commit_check/engine.py +108 -1
- commit_check/main.py +40 -4
- commit_check/rule_builder.py +36 -0
- commit_check/rules_catalog.py +45 -1
- commit_check/util.py +33 -2
- {commit_check-2.24.2.dist-info → commit_check-2.25.0.dist-info}/METADATA +12 -6
- commit_check-2.25.0.dist-info/RECORD +25 -0
- commit_check-2.24.2.dist-info/RECORD +0 -23
- {commit_check-2.24.2.dist-info → commit_check-2.25.0.dist-info}/WHEEL +0 -0
- {commit_check-2.24.2.dist-info → commit_check-2.25.0.dist-info}/entry_points.txt +0 -0
- {commit_check-2.24.2.dist-info → commit_check-2.25.0.dist-info}/licenses/LICENSE +0 -0
- {commit_check-2.24.2.dist-info → commit_check-2.25.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,558 @@
|
|
|
1
|
+
"""Find risky settings in the agent config files a commit changes.
|
|
2
|
+
|
|
3
|
+
What to look for is data: ``agent_configs.toml`` beside this module lists,
|
|
4
|
+
per agent, the files it reads and the settings in them that the agent config
|
|
5
|
+
rules (CC601 to CC604) report. This module reads that list and matches file
|
|
6
|
+
contents against it; the validator in :mod:`commit_check.engine` feeds it
|
|
7
|
+
the files of the commits under test.
|
|
8
|
+
|
|
9
|
+
A setting is reported where it is committed, whoever wrote it: a project
|
|
10
|
+
file applies to everyone who opens the repository, and the agents' own
|
|
11
|
+
safeguards (a trust prompt, a first-run question) are a click away from
|
|
12
|
+
letting it through.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import json
|
|
18
|
+
import re
|
|
19
|
+
import tomllib
|
|
20
|
+
from collections.abc import Iterable, Iterator, Sequence
|
|
21
|
+
from dataclasses import dataclass
|
|
22
|
+
from fnmatch import fnmatchcase
|
|
23
|
+
from functools import cache
|
|
24
|
+
from pathlib import Path
|
|
25
|
+
from typing import Any
|
|
26
|
+
|
|
27
|
+
#: The catalog of agents and their settings.
|
|
28
|
+
CATALOG_PATH = Path(__file__).with_name("agent_configs.toml")
|
|
29
|
+
|
|
30
|
+
#: The rule each catalog entry may name, kebab-case as the catalog writes
|
|
31
|
+
#: it, mapped to the check it reports under.
|
|
32
|
+
RULES = {
|
|
33
|
+
"agent-mcp-auto-approve": "agent_mcp_auto_approve",
|
|
34
|
+
"agent-api-endpoint": "agent_api_endpoint",
|
|
35
|
+
"agent-full-access": "agent_full_access",
|
|
36
|
+
"agent-unrestricted-trigger": "agent_unrestricted_trigger",
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
#: The ``[agent]`` list that lets a finding of each check through,
|
|
40
|
+
#: for the checks that have one. A server is let through by its name, an
|
|
41
|
+
#: endpoint by its URL.
|
|
42
|
+
ALLOWLISTS = {
|
|
43
|
+
"agent_mcp_auto_approve": "allow_mcp_servers",
|
|
44
|
+
"agent_api_endpoint": "allow_api_endpoints",
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
#: The formats a catalog file may be in, by file name ending.
|
|
48
|
+
_FORMATS = {".json": "json", ".toml": "toml", ".yml": "yaml", ".yaml": "yaml"}
|
|
49
|
+
|
|
50
|
+
#: Config files are small; anything bigger is not one and is not read.
|
|
51
|
+
MAX_FILE_SIZE = 1024 * 1024
|
|
52
|
+
|
|
53
|
+
_AGENT_KEYS = frozenset({"name", "files", "uses", "docs", "settings"})
|
|
54
|
+
_SETTING_KEYS = frozenset({"rule", "key", "value", "docs"})
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class _Any:
|
|
58
|
+
"""The ``value`` of a setting whose every value is risky."""
|
|
59
|
+
|
|
60
|
+
def __repr__(self) -> str:
|
|
61
|
+
return "ANY"
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
ANY: Any = _Any()
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@dataclass(frozen=True)
|
|
68
|
+
class AgentSetting:
|
|
69
|
+
"""One risky setting of one agent, from the catalog.
|
|
70
|
+
|
|
71
|
+
:param agent: The agent's name.
|
|
72
|
+
:param check: The check that reports it, e.g. ``agent_full_access``.
|
|
73
|
+
:param files: Globs of the files it is read from.
|
|
74
|
+
:param key: The setting's path, split on ``.``; ``*`` is any one key.
|
|
75
|
+
:param value: The risky value, or :data:`ANY`.
|
|
76
|
+
:param uses: For a YAML file, the action a step's ``uses:`` names;
|
|
77
|
+
only that step's settings count.
|
|
78
|
+
:param docs: Where the agent documents the setting.
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
agent: str
|
|
82
|
+
check: str
|
|
83
|
+
files: tuple[str, ...]
|
|
84
|
+
key: tuple[str, ...]
|
|
85
|
+
value: Any
|
|
86
|
+
uses: str | None
|
|
87
|
+
docs: str
|
|
88
|
+
|
|
89
|
+
@property
|
|
90
|
+
def key_text(self) -> str:
|
|
91
|
+
return ".".join(self.key)
|
|
92
|
+
|
|
93
|
+
def reads(self, path: str) -> bool:
|
|
94
|
+
"""Whether *path* is one of the files this setting is read from.
|
|
95
|
+
|
|
96
|
+
A ``*`` stays within one directory, as it does in a shell:
|
|
97
|
+
``.github/workflows/*.yml`` is not ``.github/workflows/old/ci.yml``,
|
|
98
|
+
which GitHub does not run.
|
|
99
|
+
"""
|
|
100
|
+
depth = path.count("/")
|
|
101
|
+
return any(
|
|
102
|
+
depth == pattern.count("/") and fnmatchcase(path, pattern)
|
|
103
|
+
for pattern in self.files
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
@dataclass(frozen=True)
|
|
108
|
+
class Finding:
|
|
109
|
+
"""A risky setting found in a file.
|
|
110
|
+
|
|
111
|
+
:param subject: What an allowlist names to let it through: the server's
|
|
112
|
+
name or the endpoint's URL. ``None`` when nothing can, such as a
|
|
113
|
+
setting that approves every server at once.
|
|
114
|
+
"""
|
|
115
|
+
|
|
116
|
+
check: str
|
|
117
|
+
path: str
|
|
118
|
+
setting: str
|
|
119
|
+
subject: str | None
|
|
120
|
+
agent: str
|
|
121
|
+
|
|
122
|
+
def __str__(self) -> str:
|
|
123
|
+
return f"{self.setting} in {self.path}"
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _https_url(value: Any) -> bool:
|
|
127
|
+
return isinstance(value, str) and value.startswith("https://")
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
class CatalogError(ValueError):
|
|
131
|
+
"""An entry of ``agent_configs.toml`` that cannot be used."""
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def parse_catalog(data: dict[str, Any]) -> tuple[AgentSetting, ...]:
|
|
135
|
+
"""The settings a parsed catalog lists, or :class:`CatalogError` naming
|
|
136
|
+
the first entry that is not usable.
|
|
137
|
+
|
|
138
|
+
The catalog is checked whole on load, so a mistake in a new entry fails
|
|
139
|
+
the test suite rather than silently matching nothing.
|
|
140
|
+
"""
|
|
141
|
+
agents = data.get("agent")
|
|
142
|
+
if set(data) != {"agent"} or not isinstance(agents, list) or not agents:
|
|
143
|
+
raise CatalogError("the catalog must hold [[agent]] tables and nothing else")
|
|
144
|
+
settings: list[AgentSetting] = []
|
|
145
|
+
for agent in agents:
|
|
146
|
+
name = agent.get("name") if isinstance(agent, dict) else None
|
|
147
|
+
if not isinstance(name, str) or not name.strip():
|
|
148
|
+
raise CatalogError(f"an [[agent]] table has no name: {agent!r}")
|
|
149
|
+
where = f"agent {name!r}"
|
|
150
|
+
unknown = set(agent) - _AGENT_KEYS
|
|
151
|
+
if unknown:
|
|
152
|
+
raise CatalogError(f"{where}: unknown keys {sorted(unknown)}")
|
|
153
|
+
files = agent.get("files")
|
|
154
|
+
if not isinstance(files, list) or not files:
|
|
155
|
+
raise CatalogError(f"{where}: files must be a list of paths")
|
|
156
|
+
for pattern in files:
|
|
157
|
+
if not isinstance(pattern, str) or _format(pattern) is None:
|
|
158
|
+
raise CatalogError(
|
|
159
|
+
f"{where}: {pattern!r} is not a .json, .toml, .yml or .yaml path"
|
|
160
|
+
)
|
|
161
|
+
uses = agent.get("uses")
|
|
162
|
+
if uses is not None and (not isinstance(uses, str) or not uses.strip()):
|
|
163
|
+
raise CatalogError(f"{where}: uses must name the action")
|
|
164
|
+
docs = agent.get("docs")
|
|
165
|
+
if not _https_url(docs):
|
|
166
|
+
raise CatalogError(f"{where}: docs must be an https:// link")
|
|
167
|
+
entries = agent.get("settings")
|
|
168
|
+
if not isinstance(entries, list) or not entries:
|
|
169
|
+
raise CatalogError(f"{where}: settings must list at least one setting")
|
|
170
|
+
for entry in entries:
|
|
171
|
+
if not isinstance(entry, dict):
|
|
172
|
+
raise CatalogError(f"{where}: a setting must be a table, got {entry!r}")
|
|
173
|
+
unknown = set(entry) - _SETTING_KEYS
|
|
174
|
+
if unknown:
|
|
175
|
+
raise CatalogError(f"{where}: unknown setting keys {sorted(unknown)}")
|
|
176
|
+
rule = entry.get("rule")
|
|
177
|
+
if rule not in RULES:
|
|
178
|
+
raise CatalogError(
|
|
179
|
+
f"{where}: rule {rule!r} is not one of {', '.join(RULES)}"
|
|
180
|
+
)
|
|
181
|
+
key = entry.get("key")
|
|
182
|
+
parts = tuple(key.split(".")) if isinstance(key, str) else ()
|
|
183
|
+
if not parts or not all(parts) or parts.count("*") > 1:
|
|
184
|
+
raise CatalogError(
|
|
185
|
+
f"{where}: key {key!r} must be keys joined with '.', "
|
|
186
|
+
"with at most one '*'"
|
|
187
|
+
)
|
|
188
|
+
value = entry.get("value", ANY)
|
|
189
|
+
if value is not ANY and not isinstance(value, (bool, int, str)):
|
|
190
|
+
raise CatalogError(f"{where}: value of {key!r} must be one value")
|
|
191
|
+
setting_docs = entry.get("docs", docs)
|
|
192
|
+
if not _https_url(setting_docs):
|
|
193
|
+
raise CatalogError(f"{where}: docs of {key!r} must be an https:// link")
|
|
194
|
+
settings.append(
|
|
195
|
+
AgentSetting(
|
|
196
|
+
agent=name,
|
|
197
|
+
check=RULES[rule],
|
|
198
|
+
files=tuple(files),
|
|
199
|
+
key=parts,
|
|
200
|
+
value=value,
|
|
201
|
+
uses=uses,
|
|
202
|
+
docs=setting_docs,
|
|
203
|
+
)
|
|
204
|
+
)
|
|
205
|
+
return tuple(settings)
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
@cache
|
|
209
|
+
def load_settings() -> tuple[AgentSetting, ...]:
|
|
210
|
+
"""Every setting in the catalog, read from disk once per process."""
|
|
211
|
+
with CATALOG_PATH.open("rb") as f:
|
|
212
|
+
return parse_catalog(tomllib.load(f))
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def _format(path: str) -> str | None:
|
|
216
|
+
for ending, fmt in _FORMATS.items():
|
|
217
|
+
if path.endswith(ending):
|
|
218
|
+
return fmt
|
|
219
|
+
return None
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
# A string or a comment: comments are dropped and strings kept as they are,
|
|
223
|
+
# so "//" inside a URL survives. One left open runs to the end of the text,
|
|
224
|
+
# so each character is read once: retrying a "/*" that never closes from
|
|
225
|
+
# every later "/*" would take time that grows with the square of the size.
|
|
226
|
+
# Left as text, not compiled at import: most runs read no JSON file that
|
|
227
|
+
# needs them.
|
|
228
|
+
_JSON_STRING = r'"(?:\\.|[^"\\])*(?:"|\\?\Z)'
|
|
229
|
+
_JSONC_TOKEN = rf"{_JSON_STRING}|//[^\n]*|/\*.*?(?:\*/|\Z)"
|
|
230
|
+
_TRAILING_COMMA = rf"{_JSON_STRING}|,(\s*[}}\]])"
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def _loads_jsonc(text: str) -> Any:
|
|
234
|
+
"""JSON that may hold comments and trailing commas, as VS Code's does."""
|
|
235
|
+
try:
|
|
236
|
+
return json.loads(text)
|
|
237
|
+
except ValueError:
|
|
238
|
+
pass
|
|
239
|
+
stripped = re.sub(
|
|
240
|
+
_JSONC_TOKEN,
|
|
241
|
+
lambda m: m.group(0) if m.group(0).startswith('"') else " ",
|
|
242
|
+
text,
|
|
243
|
+
flags=re.DOTALL,
|
|
244
|
+
)
|
|
245
|
+
stripped = re.sub(
|
|
246
|
+
_TRAILING_COMMA,
|
|
247
|
+
lambda m: m.group(1) if m.group(1) is not None else m.group(0),
|
|
248
|
+
stripped,
|
|
249
|
+
)
|
|
250
|
+
return json.loads(stripped)
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def _parse(fmt: str, text: str) -> Any:
|
|
254
|
+
"""The file's data, or ``None`` when it does not parse.
|
|
255
|
+
|
|
256
|
+
A file its own agent could not read either holds no setting that
|
|
257
|
+
takes effect, so it is not reported.
|
|
258
|
+
"""
|
|
259
|
+
try:
|
|
260
|
+
if fmt == "json":
|
|
261
|
+
return _loads_jsonc(text)
|
|
262
|
+
return tomllib.loads(text)
|
|
263
|
+
except (ValueError, RecursionError):
|
|
264
|
+
# Nested deeper than Python's parsers go: no agent reads it either.
|
|
265
|
+
return None
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def _lookup(
|
|
269
|
+
node: Any, keys: tuple[str, ...], name: str | None = None
|
|
270
|
+
) -> Iterator[tuple[str | None, tuple[str, ...], Any]]:
|
|
271
|
+
"""``(name, path, value)`` for each value at *keys* in *node*.
|
|
272
|
+
|
|
273
|
+
*name* is the key ``*`` stood for, *path* the keys as found. A key that
|
|
274
|
+
holds dots itself, as VS Code's ``chat.tools.autoApprove`` does, is
|
|
275
|
+
tried whole as well as split: every run of keys that is present is
|
|
276
|
+
followed, so a decoy ``"env.X"`` key cannot hide the ``env`` block
|
|
277
|
+
beside it.
|
|
278
|
+
"""
|
|
279
|
+
if not keys:
|
|
280
|
+
yield name, (), node
|
|
281
|
+
return
|
|
282
|
+
if not isinstance(node, dict):
|
|
283
|
+
return
|
|
284
|
+
if keys[0] == "*":
|
|
285
|
+
for key, value in node.items():
|
|
286
|
+
for found_name, path, found in _lookup(value, keys[1:], key):
|
|
287
|
+
yield found_name, (key, *path), found
|
|
288
|
+
return
|
|
289
|
+
stop = keys.index("*") if "*" in keys else len(keys)
|
|
290
|
+
for end in range(stop, 0, -1):
|
|
291
|
+
joined = ".".join(keys[:end])
|
|
292
|
+
if joined in node:
|
|
293
|
+
for found_name, path, found in _lookup(node[joined], keys[end:], name):
|
|
294
|
+
yield found_name, (joined, *path), found
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def _same(found: Any, value: Any) -> bool:
|
|
298
|
+
# ``True == 1`` in Python; a setting's type is part of what it means.
|
|
299
|
+
return type(found) is type(value) and found == value
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
def _show(value: Any) -> str:
|
|
303
|
+
return json.dumps(value, ensure_ascii=False)
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
def _structured_findings(
|
|
307
|
+
path: str, data: Any, settings: Iterable[AgentSetting]
|
|
308
|
+
) -> Iterator[Finding]:
|
|
309
|
+
for setting in settings:
|
|
310
|
+
for name, keys, found in _lookup(data, setting.key):
|
|
311
|
+
shown_key = ".".join(keys)
|
|
312
|
+
items = found if isinstance(found, list) else [found]
|
|
313
|
+
verb = "has" if isinstance(found, list) else "="
|
|
314
|
+
if setting.value is ANY:
|
|
315
|
+
for item in items:
|
|
316
|
+
if not item:
|
|
317
|
+
continue
|
|
318
|
+
subject = name
|
|
319
|
+
if subject is None and isinstance(item, str):
|
|
320
|
+
subject = item
|
|
321
|
+
yield Finding(
|
|
322
|
+
setting.check,
|
|
323
|
+
path,
|
|
324
|
+
f"{shown_key} {verb} {_show(item)}",
|
|
325
|
+
subject,
|
|
326
|
+
setting.agent,
|
|
327
|
+
)
|
|
328
|
+
elif any(_same(item, setting.value) for item in items):
|
|
329
|
+
yield Finding(
|
|
330
|
+
setting.check,
|
|
331
|
+
path,
|
|
332
|
+
f"{shown_key} {verb} {_show(setting.value)}",
|
|
333
|
+
name,
|
|
334
|
+
setting.agent,
|
|
335
|
+
)
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
# YAML's double-quoted escapes, besides \x, \u and \U.
|
|
339
|
+
_YAML_ESCAPES = {
|
|
340
|
+
"0": "\0", "a": "\a", "b": "\b", "t": "\t", "\t": "\t", "n": "\n",
|
|
341
|
+
"v": "\v", "f": "\f", "r": "\r", "e": "\x1b", " ": " ", '"': '"',
|
|
342
|
+
"/": "/", "\\": "\\", "N": "\x85", "_": "\xa0", "L": "\u2028",
|
|
343
|
+
"P": "\u2029",
|
|
344
|
+
} # fmt: skip
|
|
345
|
+
_YAML_ESCAPE = r"\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8}|.)"
|
|
346
|
+
_YAML_QUOTED = {'"': r'"((?:\\.|[^"\\])*)"', "'": r"'((?:''|[^'])*)'"}
|
|
347
|
+
# A node's tag and anchor, such as "!!str " and "&name ", before its key or value.
|
|
348
|
+
_YAML_PROPERTIES = r"(?:[!&]\S*(?:\s+|$))*"
|
|
349
|
+
# A "key: rest" line of a block mapping, as a list item or not. Only keys
|
|
350
|
+
# spelled with word characters, dots and dashes are read unquoted: no key
|
|
351
|
+
# this module looks for is spelled otherwise. Each run of spaces can be
|
|
352
|
+
# matched one way only, so a long line that is not an entry fails at once.
|
|
353
|
+
_YAML_ENTRY = re.compile(
|
|
354
|
+
rf"""^\s*(?:(?P<dash>-)\s+)?{_YAML_PROPERTIES}"""
|
|
355
|
+
r"""(?P<key>"(?:\\.|[^"\\])*"|'(?:''|[^'])*'|[\w.-]+)\s*:(?P<rest>.*)$"""
|
|
356
|
+
)
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
def _yaml_unescape(match: re.Match[str]) -> str:
|
|
360
|
+
code = match.group(1)
|
|
361
|
+
if code[0] in "xuU" and len(code) > 1:
|
|
362
|
+
point = int(code[1:], 16)
|
|
363
|
+
return chr(point) if point <= 0x10FFFF else match.group(0)
|
|
364
|
+
return _YAML_ESCAPES.get(code, match.group(0))
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
def _yaml_scalar(raw: str) -> str | None:
|
|
368
|
+
"""The value on a ``key: value`` line, unquoted, or ``None`` for one
|
|
369
|
+
that starts a block, a mapping or a list on the lines below.
|
|
370
|
+
|
|
371
|
+
A quoted value is read as YAML reads it, so ``"\\u002a"`` is ``*``, and
|
|
372
|
+
a tag or anchor before it, as in ``!!str "*"``, is passed over.
|
|
373
|
+
"""
|
|
374
|
+
raw = re.sub(rf"^{_YAML_PROPERTIES}", "", raw.strip(), count=1)
|
|
375
|
+
if raw[:1] in _YAML_QUOTED:
|
|
376
|
+
quoted = re.match(_YAML_QUOTED[raw[0]], raw)
|
|
377
|
+
if quoted is None:
|
|
378
|
+
return None
|
|
379
|
+
if raw[0] == "'":
|
|
380
|
+
return quoted.group(1).replace("''", "'")
|
|
381
|
+
return re.sub(_YAML_ESCAPE, _yaml_unescape, quoted.group(1))
|
|
382
|
+
raw = re.split(r"\s#", raw, maxsplit=1)[0].strip()
|
|
383
|
+
if not raw or raw[0] in "|>&*{[":
|
|
384
|
+
return None
|
|
385
|
+
return raw
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
def _yaml_entry(line: str) -> tuple[str, str, bool] | None:
|
|
389
|
+
"""The key of a ``key: value`` line, the text after its colon, and
|
|
390
|
+
whether the line starts a list item; ``None`` for any other line.
|
|
391
|
+
|
|
392
|
+
The key is read as YAML reads it, so ``"wi\\u0074h"`` is ``with``.
|
|
393
|
+
"""
|
|
394
|
+
match = _YAML_ENTRY.match(line)
|
|
395
|
+
if match is None:
|
|
396
|
+
return None
|
|
397
|
+
key = match.group("key")
|
|
398
|
+
if key[0] in _YAML_QUOTED:
|
|
399
|
+
key = _yaml_scalar(key) or ""
|
|
400
|
+
return key, match.group("rest"), match.group("dash") is not None
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
def _indent(line: str) -> int:
|
|
404
|
+
return len(line) - len(line.lstrip(" "))
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
def _steps_using(lines: list[str], uses: str) -> list[list[str]]:
|
|
408
|
+
"""The lines of each YAML step whose ``uses:`` names *uses*.
|
|
409
|
+
|
|
410
|
+
A step runs from its ``-`` to the next line indented no deeper than
|
|
411
|
+
that ``-``, so a setting of another step, another job's action or a
|
|
412
|
+
comment that names the action is not taken for this one's. Steps do
|
|
413
|
+
not overlap, so each line is walked over once, however many ``uses:``
|
|
414
|
+
lines the file holds.
|
|
415
|
+
"""
|
|
416
|
+
steps = []
|
|
417
|
+
covered = 0 # the lines before this one are in a step already found
|
|
418
|
+
for number, line in enumerate(lines):
|
|
419
|
+
if number < covered:
|
|
420
|
+
continue
|
|
421
|
+
entry = _yaml_entry(line)
|
|
422
|
+
if entry is None or entry[0] != "uses":
|
|
423
|
+
continue
|
|
424
|
+
action = _yaml_scalar(entry[1]) or ""
|
|
425
|
+
if action != uses and not action.startswith(f"{uses}@"):
|
|
426
|
+
continue
|
|
427
|
+
start = number
|
|
428
|
+
if entry[2]:
|
|
429
|
+
dash = _indent(line)
|
|
430
|
+
else:
|
|
431
|
+
# "uses:" under the step's "- name:" line: the step starts at the
|
|
432
|
+
# nearest line above that begins with a "-" further left.
|
|
433
|
+
dash = _indent(line) - 2
|
|
434
|
+
while start > covered:
|
|
435
|
+
start -= 1
|
|
436
|
+
above = lines[start]
|
|
437
|
+
if above.strip().startswith("-") and _indent(above) <= dash:
|
|
438
|
+
dash = _indent(above)
|
|
439
|
+
break
|
|
440
|
+
end = number + 1
|
|
441
|
+
while end < len(lines):
|
|
442
|
+
stripped = lines[end].strip()
|
|
443
|
+
if (
|
|
444
|
+
stripped
|
|
445
|
+
and not stripped.startswith("#")
|
|
446
|
+
and _indent(lines[end]) <= dash
|
|
447
|
+
):
|
|
448
|
+
break
|
|
449
|
+
end += 1
|
|
450
|
+
steps.append(lines[start:end])
|
|
451
|
+
covered = end
|
|
452
|
+
return steps
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
def _inputs(step: list[str]) -> list[str]:
|
|
456
|
+
"""The lines of a step's ``with:`` inputs, one input each.
|
|
457
|
+
|
|
458
|
+
Lines nested deeper, such as those of a multi-line ``prompt``, are left
|
|
459
|
+
out: text in a prompt is not a setting.
|
|
460
|
+
"""
|
|
461
|
+
inputs: list[str] = []
|
|
462
|
+
for number, line in enumerate(step):
|
|
463
|
+
entry = _yaml_entry(line)
|
|
464
|
+
if entry is None or entry[0] != "with":
|
|
465
|
+
continue
|
|
466
|
+
# Nothing after "with:" but a tag, an anchor or a comment, as in
|
|
467
|
+
# "with: !!map": the inputs are on the lines below.
|
|
468
|
+
if not re.fullmatch(rf"\s*{_YAML_PROPERTIES}(?:#.*)?", entry[1]):
|
|
469
|
+
continue
|
|
470
|
+
column = len(line) - len(line.lstrip(" -"))
|
|
471
|
+
depth = None
|
|
472
|
+
for below_number in range(number + 1, len(step)):
|
|
473
|
+
below = step[below_number]
|
|
474
|
+
stripped = below.strip()
|
|
475
|
+
if not stripped or stripped.startswith("#"):
|
|
476
|
+
continue
|
|
477
|
+
indent = _indent(below)
|
|
478
|
+
if indent <= column:
|
|
479
|
+
break
|
|
480
|
+
if depth is None:
|
|
481
|
+
depth = indent
|
|
482
|
+
if indent == depth:
|
|
483
|
+
inputs.append(below)
|
|
484
|
+
return inputs
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
def _yaml_findings(
|
|
488
|
+
path: str, text: str, settings: Iterable[AgentSetting]
|
|
489
|
+
) -> Iterator[Finding]:
|
|
490
|
+
lines = text.splitlines()
|
|
491
|
+
for setting in settings:
|
|
492
|
+
scopes = (
|
|
493
|
+
[lines]
|
|
494
|
+
if setting.uses is None
|
|
495
|
+
else [_inputs(step) for step in _steps_using(lines, setting.uses)]
|
|
496
|
+
)
|
|
497
|
+
key = setting.key[-1]
|
|
498
|
+
for line in (line for scope in scopes for line in scope):
|
|
499
|
+
entry = _yaml_entry(line)
|
|
500
|
+
if entry is None or entry[0] != key:
|
|
501
|
+
continue
|
|
502
|
+
value = _yaml_scalar(entry[1])
|
|
503
|
+
if value is None:
|
|
504
|
+
continue
|
|
505
|
+
if setting.value is ANY:
|
|
506
|
+
yield Finding(
|
|
507
|
+
setting.check, path, f"{key} = {_show(value)}", value, setting.agent
|
|
508
|
+
)
|
|
509
|
+
continue
|
|
510
|
+
expected = setting.value
|
|
511
|
+
if isinstance(expected, bool):
|
|
512
|
+
hit = value.lower() == str(expected).lower()
|
|
513
|
+
else:
|
|
514
|
+
hit = value == str(expected)
|
|
515
|
+
if hit:
|
|
516
|
+
yield Finding(
|
|
517
|
+
setting.check, path, f"{key} = {_show(value)}", None, setting.agent
|
|
518
|
+
)
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
def find_settings(
|
|
522
|
+
path: str, text: str, settings: Sequence[AgentSetting] | None = None
|
|
523
|
+
) -> list[Finding]:
|
|
524
|
+
"""The risky settings in *text*, the contents of the file at *path*.
|
|
525
|
+
|
|
526
|
+
:param settings: The catalog entries to look for; the whole catalog
|
|
527
|
+
when not given. Only those whose files include *path* are used.
|
|
528
|
+
"""
|
|
529
|
+
if settings is None:
|
|
530
|
+
settings = load_settings()
|
|
531
|
+
relevant = [s for s in settings if s.reads(path)]
|
|
532
|
+
if not relevant:
|
|
533
|
+
return []
|
|
534
|
+
# The catalog admits only files whose format is known.
|
|
535
|
+
fmt = _format(path) or "json"
|
|
536
|
+
if fmt == "yaml":
|
|
537
|
+
found = _yaml_findings(path, text, relevant)
|
|
538
|
+
else:
|
|
539
|
+
data = _parse(fmt, text)
|
|
540
|
+
if data is None:
|
|
541
|
+
return []
|
|
542
|
+
found = _structured_findings(path, data, relevant)
|
|
543
|
+
return list(dict.fromkeys(found))
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
def is_allowed(finding: Finding, allowed: Iterable[str]) -> bool:
|
|
547
|
+
"""Whether an ``[agent]`` allowlist lets *finding* through.
|
|
548
|
+
|
|
549
|
+
An endpoint matches with or without a trailing slash; anything else
|
|
550
|
+
must match exactly. A URL is never matched by its start, which
|
|
551
|
+
``https://gateway.example.com.attacker.net`` would pass.
|
|
552
|
+
"""
|
|
553
|
+
if finding.subject is None:
|
|
554
|
+
return False
|
|
555
|
+
if finding.check == "agent_api_endpoint":
|
|
556
|
+
subject = finding.subject.rstrip("/")
|
|
557
|
+
return any(subject == item.rstrip("/") for item in allowed)
|
|
558
|
+
return finding.subject in allowed
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# The agent settings the agent config rules (CC601 to CC604) look for.
|
|
2
|
+
#
|
|
3
|
+
# Each [[agent]] table is one coding agent: the files it reads project
|
|
4
|
+
# settings from, and the settings in them that, once committed, change what
|
|
5
|
+
# the agent does for everyone who opens the repository. To cover another
|
|
6
|
+
# agent, add a table here and a case for each setting in
|
|
7
|
+
# tests/agent_config_test.py. No code changes are needed.
|
|
8
|
+
#
|
|
9
|
+
# name the agent, as people know it
|
|
10
|
+
# files the committed files it reads, as paths from the repository
|
|
11
|
+
# root; * and ? work as in a shell and stay within one directory
|
|
12
|
+
# uses YAML files only: the action a step's "uses:" names; only the
|
|
13
|
+
# settings of such a step count
|
|
14
|
+
# docs where the agent documents these settings
|
|
15
|
+
# settings one inline table per setting:
|
|
16
|
+
# rule the rule that reports it:
|
|
17
|
+
# agent-mcp-auto-approve MCP servers or their tools run
|
|
18
|
+
# without asking
|
|
19
|
+
# agent-api-endpoint requests go to another API
|
|
20
|
+
# endpoint
|
|
21
|
+
# agent-full-access commands run without asking or
|
|
22
|
+
# outside the sandbox
|
|
23
|
+
# agent-unrestricted-trigger anyone can start the agent in CI
|
|
24
|
+
# key the setting, keys joined with "."; * stands for any one key,
|
|
25
|
+
# such as a server's name. A key that itself holds dots, as in
|
|
26
|
+
# VS Code's settings, is matched whole first
|
|
27
|
+
# value the risky value, or for a list the risky item. Leave it out
|
|
28
|
+
# when any value is, such as an endpoint's URL
|
|
29
|
+
# docs optional: a page more specific than the agent's docs
|
|
30
|
+
#
|
|
31
|
+
# JSON files may hold // and /* */ comments and trailing commas. YAML files
|
|
32
|
+
# are read a line at a time: a setting matches on a "key: value" line, so a
|
|
33
|
+
# value written across several lines, or through an anchor, is not seen.
|
|
34
|
+
#
|
|
35
|
+
# Only settings an agent documents belong here, with the page that says so.
|
|
36
|
+
# Values are matched as the docs write them: "Bash" and "Bash(*)" are, a
|
|
37
|
+
# rule such as "Bash(python3:*)" that also allows any command is not. These
|
|
38
|
+
# rules catch the settings that open everything up, not every risky one.
|
|
39
|
+
|
|
40
|
+
[[agent]]
|
|
41
|
+
name = "Claude Code"
|
|
42
|
+
files = [".claude/settings.json", ".claude/settings.local.json"]
|
|
43
|
+
docs = "https://code.claude.com/docs/en/settings"
|
|
44
|
+
settings = [
|
|
45
|
+
{ rule = "agent-mcp-auto-approve", key = "enableAllProjectMcpServers", value = true },
|
|
46
|
+
{ rule = "agent-mcp-auto-approve", key = "enabledMcpjsonServers" },
|
|
47
|
+
{ rule = "agent-api-endpoint", key = "env.ANTHROPIC_BASE_URL", docs = "https://code.claude.com/docs/en/env-vars" },
|
|
48
|
+
{ rule = "agent-api-endpoint", key = "env.ANTHROPIC_BEDROCK_BASE_URL", docs = "https://code.claude.com/docs/en/env-vars" },
|
|
49
|
+
{ rule = "agent-api-endpoint", key = "env.ANTHROPIC_BEDROCK_MANTLE_BASE_URL", docs = "https://code.claude.com/docs/en/env-vars" },
|
|
50
|
+
{ rule = "agent-api-endpoint", key = "env.ANTHROPIC_AWS_BASE_URL", docs = "https://code.claude.com/docs/en/env-vars" },
|
|
51
|
+
{ rule = "agent-api-endpoint", key = "env.ANTHROPIC_VERTEX_BASE_URL", docs = "https://code.claude.com/docs/en/env-vars" },
|
|
52
|
+
{ rule = "agent-api-endpoint", key = "env.ANTHROPIC_FOUNDRY_BASE_URL", docs = "https://code.claude.com/docs/en/env-vars" },
|
|
53
|
+
{ rule = "agent-full-access", key = "permissions.allow", value = "Bash", docs = "https://code.claude.com/docs/en/permissions" },
|
|
54
|
+
{ rule = "agent-full-access", key = "permissions.allow", value = "Bash(*)", docs = "https://code.claude.com/docs/en/permissions" },
|
|
55
|
+
# Ignored in project settings since Claude Code 2.1.257, still read by
|
|
56
|
+
# older versions.
|
|
57
|
+
{ rule = "agent-full-access", key = "permissions.defaultMode", value = "bypassPermissions" },
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
[[agent]]
|
|
61
|
+
name = "Claude Code GitHub Action"
|
|
62
|
+
files = [
|
|
63
|
+
".github/workflows/*.yml",
|
|
64
|
+
".github/workflows/*.yaml",
|
|
65
|
+
".github/actions/*/action.yml",
|
|
66
|
+
".github/actions/*/action.yaml",
|
|
67
|
+
]
|
|
68
|
+
uses = "anthropics/claude-code-action"
|
|
69
|
+
docs = "https://github.com/anthropics/claude-code-action/blob/main/docs/security.md"
|
|
70
|
+
settings = [
|
|
71
|
+
{ rule = "agent-unrestricted-trigger", key = "allowed_bots", value = "*" },
|
|
72
|
+
{ rule = "agent-unrestricted-trigger", key = "allowed_non_write_users", value = "*" },
|
|
73
|
+
]
|
|
74
|
+
|
|
75
|
+
[[agent]]
|
|
76
|
+
name = "Codex"
|
|
77
|
+
files = [".codex/config.toml"]
|
|
78
|
+
docs = "https://developers.openai.com/codex/config-reference"
|
|
79
|
+
settings = [
|
|
80
|
+
{ rule = "agent-full-access", key = "sandbox_mode", value = "danger-full-access" },
|
|
81
|
+
{ rule = "agent-full-access", key = "default_permissions", value = ":danger-full-access" },
|
|
82
|
+
{ rule = "agent-full-access", key = "approval_policy", value = "never" },
|
|
83
|
+
# [profiles.*] is not listed: Codex ignores profile and profiles in a
|
|
84
|
+
# project's .codex/config.toml.
|
|
85
|
+
]
|
|
86
|
+
|
|
87
|
+
[[agent]]
|
|
88
|
+
name = "Gemini CLI"
|
|
89
|
+
files = [".gemini/settings.json"]
|
|
90
|
+
docs = "https://geminicli.com/docs/tools/mcp-server"
|
|
91
|
+
settings = [
|
|
92
|
+
{ rule = "agent-mcp-auto-approve", key = "mcpServers.*.trust", value = true },
|
|
93
|
+
]
|
|
94
|
+
|
|
95
|
+
[[agent]]
|
|
96
|
+
name = "Cursor CLI"
|
|
97
|
+
files = [".cursor/cli.json"]
|
|
98
|
+
docs = "https://cursor.com/docs/cli/reference/permissions"
|
|
99
|
+
settings = [
|
|
100
|
+
{ rule = "agent-mcp-auto-approve", key = "permissions.allow", value = "Mcp(*:*)" },
|
|
101
|
+
]
|
|
102
|
+
|
|
103
|
+
[[agent]]
|
|
104
|
+
name = "GitHub Copilot in VS Code"
|
|
105
|
+
files = [".vscode/settings.json"]
|
|
106
|
+
docs = "https://code.visualstudio.com/docs/agents/run/approvals"
|
|
107
|
+
settings = [
|
|
108
|
+
{ rule = "agent-full-access", key = "chat.tools.global.autoApprove", value = true },
|
|
109
|
+
# The earlier name, which CVE-2025-53773 had Copilot write to this file.
|
|
110
|
+
{ rule = "agent-full-access", key = "chat.tools.autoApprove", value = true, docs = "https://embracethered.com/blog/posts/2025/github-copilot-remote-code-execution-via-prompt-injection/" },
|
|
111
|
+
]
|
commit_check/ci.py
CHANGED
|
@@ -48,7 +48,9 @@ HELP = {
|
|
|
48
48
|
"branch": "check the name of the source branch",
|
|
49
49
|
"author-name": "check the author name of every commit",
|
|
50
50
|
"author-email": "check the author email of every commit",
|
|
51
|
-
"files":
|
|
51
|
+
"files": (
|
|
52
|
+
"check the files every commit changes against the [files] and [agent] rules"
|
|
53
|
+
),
|
|
52
54
|
"pr-title": "check the title against the commit message rules",
|
|
53
55
|
"pr-body-ai-attribution": (
|
|
54
56
|
"check the description against the AI attribution rules"
|
commit_check/config_merger.py
CHANGED
|
@@ -109,6 +109,11 @@ def get_default_config() -> dict[str, Any]:
|
|
|
109
109
|
"prohibited_patterns": [],
|
|
110
110
|
"max_path_length": 0,
|
|
111
111
|
},
|
|
112
|
+
"agent": {
|
|
113
|
+
"enabled": False,
|
|
114
|
+
"allow_mcp_servers": [],
|
|
115
|
+
"allow_api_endpoints": [],
|
|
116
|
+
},
|
|
112
117
|
}
|
|
113
118
|
|
|
114
119
|
|
|
@@ -223,6 +228,18 @@ class ConfigMerger:
|
|
|
223
228
|
"CCHK_FILES_MAX_SIZE": ("files", "max_size", str),
|
|
224
229
|
"CCHK_FILES_PROHIBITED_PATTERNS": ("files", "prohibited_patterns", parse_list),
|
|
225
230
|
"CCHK_FILES_MAX_PATH_LENGTH": ("files", "max_path_length", parse_int),
|
|
231
|
+
# Agent section
|
|
232
|
+
"CCHK_AGENT_ENABLED": ("agent", "enabled", parse_bool),
|
|
233
|
+
"CCHK_AGENT_ALLOW_MCP_SERVERS": (
|
|
234
|
+
"agent",
|
|
235
|
+
"allow_mcp_servers",
|
|
236
|
+
parse_list,
|
|
237
|
+
),
|
|
238
|
+
"CCHK_AGENT_ALLOW_API_ENDPOINTS": (
|
|
239
|
+
"agent",
|
|
240
|
+
"allow_api_endpoints",
|
|
241
|
+
parse_list,
|
|
242
|
+
),
|
|
226
243
|
}
|
|
227
244
|
|
|
228
245
|
# Mapping of CLI argument names to config keys
|
|
@@ -263,6 +280,13 @@ class ConfigMerger:
|
|
|
263
280
|
"files_max_size": ("files", "max_size"),
|
|
264
281
|
"files_prohibited_patterns": ("files", "prohibited_patterns"),
|
|
265
282
|
"files_max_path_length": ("files", "max_path_length"),
|
|
283
|
+
# Agent section
|
|
284
|
+
"agent_enabled": ("agent", "enabled"),
|
|
285
|
+
"agent_allow_mcp_servers": ("agent", "allow_mcp_servers"),
|
|
286
|
+
"agent_allow_api_endpoints": (
|
|
287
|
+
"agent",
|
|
288
|
+
"allow_api_endpoints",
|
|
289
|
+
),
|
|
266
290
|
}
|
|
267
291
|
|
|
268
292
|
@staticmethod
|
|
@@ -279,6 +303,7 @@ class ConfigMerger:
|
|
|
279
303
|
"push": {},
|
|
280
304
|
"tag": {},
|
|
281
305
|
"files": {},
|
|
306
|
+
"agent": {},
|
|
282
307
|
}
|
|
283
308
|
|
|
284
309
|
for env_var, (section, key, parser) in ConfigMerger.ENV_VAR_MAPPING.items():
|
|
@@ -310,6 +335,7 @@ class ConfigMerger:
|
|
|
310
335
|
"push": {},
|
|
311
336
|
"tag": {},
|
|
312
337
|
"files": {},
|
|
338
|
+
"agent": {},
|
|
313
339
|
}
|
|
314
340
|
|
|
315
341
|
for arg_name, (section, key) in ConfigMerger.CLI_ARG_MAPPING.items():
|
commit_check/engine.py
CHANGED
|
@@ -22,6 +22,9 @@ from commit_check import (
|
|
|
22
22
|
GIT_REVERT_SUBJECT_PATTERN,
|
|
23
23
|
ai_policy,
|
|
24
24
|
)
|
|
25
|
+
from commit_check.agent_config import MAX_FILE_SIZE as MAX_AGENT_FILE_SIZE
|
|
26
|
+
from commit_check.agent_config import Finding, find_settings, is_allowed
|
|
27
|
+
from commit_check.agent_config import load_settings as load_agent_settings
|
|
25
28
|
from commit_check.ai_signatures import (
|
|
26
29
|
detect_ai_author,
|
|
27
30
|
detect_ai_signatures,
|
|
@@ -46,6 +49,7 @@ from commit_check.util import (
|
|
|
46
49
|
get_commit_author_identity,
|
|
47
50
|
get_commit_files,
|
|
48
51
|
get_commit_info,
|
|
52
|
+
get_file_text,
|
|
49
53
|
get_git_config_value,
|
|
50
54
|
get_git_remotes,
|
|
51
55
|
get_git_user_identity,
|
|
@@ -158,6 +162,11 @@ class ValidationContext:
|
|
|
158
162
|
files_cache: dict[str, list[tuple[str, int]]] = field(
|
|
159
163
|
default_factory=dict, repr=False, compare=False
|
|
160
164
|
)
|
|
165
|
+
# Per-run memo of the agent config findings in each (revision, path):
|
|
166
|
+
# the four agent config rules read the same files.
|
|
167
|
+
agent_findings_cache: dict[tuple[str, str], list[Finding] | None] = field(
|
|
168
|
+
default_factory=dict, repr=False, compare=False
|
|
169
|
+
)
|
|
161
170
|
# Set when stdin_text is a piped commit message: checks with a value of
|
|
162
171
|
# their own (branch, author, tags, push refs) then read git instead.
|
|
163
172
|
stdin_is_message: bool = False
|
|
@@ -472,6 +481,7 @@ class BaseValidator(ABC):
|
|
|
472
481
|
error: str | None = None,
|
|
473
482
|
fix: str | None = None,
|
|
474
483
|
suggest: str | None = None,
|
|
484
|
+
head: str | None = None,
|
|
475
485
|
) -> None:
|
|
476
486
|
"""Record and (unless suppressed) print a standardised failure message.
|
|
477
487
|
|
|
@@ -483,8 +493,14 @@ class BaseValidator(ABC):
|
|
|
483
493
|
guessing; it replaces the rule's generic suggestion with a concrete
|
|
484
494
|
one (``suggest`` overrides the wording) and travels to structured
|
|
485
495
|
consumers as its own field.
|
|
496
|
+
|
|
497
|
+
``head`` is for a value that is a list, one item a line: the failure
|
|
498
|
+
line then says *head* (``3 settings``) and every item is printed
|
|
499
|
+
below it, rather than the first item and a count of the rest.
|
|
486
500
|
"""
|
|
487
501
|
rule_dict = self.rule.to_dict()
|
|
502
|
+
if head is not None:
|
|
503
|
+
rule_dict["value_head"] = head
|
|
488
504
|
if error is not None:
|
|
489
505
|
rule_dict["error"] = error
|
|
490
506
|
if fix or suggest:
|
|
@@ -1012,7 +1028,8 @@ class FilesValidator(BaseValidator):
|
|
|
1012
1028
|
patterns, path length — branching on the rule's check name. Only the
|
|
1013
1029
|
paths and sizes recorded in the commit are read, never file contents:
|
|
1014
1030
|
content scanning is a different tool's job. A commit touching no files
|
|
1015
|
-
(or an unresolvable revision) is a skip.
|
|
1031
|
+
(or an unresolvable revision) is a skip. The agent config rules, which
|
|
1032
|
+
do read contents, are :class:`AgentConfigValidator`.
|
|
1016
1033
|
"""
|
|
1017
1034
|
|
|
1018
1035
|
@staticmethod
|
|
@@ -1164,6 +1181,92 @@ class FilesValidator(BaseValidator):
|
|
|
1164
1181
|
return ValidationResult.PASS
|
|
1165
1182
|
|
|
1166
1183
|
|
|
1184
|
+
class AgentConfigValidator(FilesValidator):
|
|
1185
|
+
"""Validates the agent config files a commit touches (CC601 to CC604).
|
|
1186
|
+
|
|
1187
|
+
Unlike the other file rules this reads contents, but only of the files
|
|
1188
|
+
``agent_configs.toml`` names, as committed, and only to find the
|
|
1189
|
+
settings it lists; see :mod:`commit_check.agent_config`. A commit that
|
|
1190
|
+
touches files but no agent config file passes.
|
|
1191
|
+
"""
|
|
1192
|
+
|
|
1193
|
+
def _fail(self, offenders: list[str]) -> ValidationResult:
|
|
1194
|
+
"""Report every finding, one a line.
|
|
1195
|
+
|
|
1196
|
+
They are often in different files; showing one and a count of the
|
|
1197
|
+
rest would have the reader fix them one run at a time.
|
|
1198
|
+
"""
|
|
1199
|
+
value = "\n".join(offenders)
|
|
1200
|
+
self._checked_value = value
|
|
1201
|
+
head = f"{len(offenders)} settings" if len(offenders) > 1 else None
|
|
1202
|
+
self._print_failure(value, head=head)
|
|
1203
|
+
return ValidationResult.FAIL
|
|
1204
|
+
|
|
1205
|
+
def _findings(
|
|
1206
|
+
self, context: ValidationContext, rev: str, path: str, size: int
|
|
1207
|
+
) -> list[Finding] | None:
|
|
1208
|
+
"""The findings in *path* at *rev*, or ``None`` when it was not read:
|
|
1209
|
+
too large, or its contents could not be had from git."""
|
|
1210
|
+
key = (rev, path)
|
|
1211
|
+
if key not in context.agent_findings_cache:
|
|
1212
|
+
findings: list[Finding] | None = None
|
|
1213
|
+
if size <= MAX_AGENT_FILE_SIZE:
|
|
1214
|
+
text = get_file_text(rev, path)
|
|
1215
|
+
if text is not None:
|
|
1216
|
+
findings = find_settings(path, text)
|
|
1217
|
+
context.agent_findings_cache[key] = findings
|
|
1218
|
+
return context.agent_findings_cache[key]
|
|
1219
|
+
|
|
1220
|
+
def validate(self, context: ValidationContext) -> ValidationResult:
|
|
1221
|
+
revs = self._revs_to_check(context)
|
|
1222
|
+
if revs is None:
|
|
1223
|
+
return ValidationResult.SKIP
|
|
1224
|
+
settings = load_agent_settings()
|
|
1225
|
+
allowed = self.rule.allowed or []
|
|
1226
|
+
# Over several commits, a setting may be in one that a later commit
|
|
1227
|
+
# undid, so the file on disk no longer shows it: name the commit.
|
|
1228
|
+
name_commit = len(revs) > 1
|
|
1229
|
+
touched = False
|
|
1230
|
+
checked: set[str] = set()
|
|
1231
|
+
unread: set[str] = set()
|
|
1232
|
+
offenders: dict[str, str] = {}
|
|
1233
|
+
for rev in revs:
|
|
1234
|
+
for path, size in self._files_for_rev(context, rev):
|
|
1235
|
+
touched = True
|
|
1236
|
+
if not any(s.reads(path) for s in settings):
|
|
1237
|
+
continue
|
|
1238
|
+
findings = self._findings(context, rev, path, size)
|
|
1239
|
+
if findings is None:
|
|
1240
|
+
unread.add(path)
|
|
1241
|
+
continue
|
|
1242
|
+
checked.add(path)
|
|
1243
|
+
for finding in findings:
|
|
1244
|
+
if finding.check != self.rule.check or is_allowed(finding, allowed):
|
|
1245
|
+
continue
|
|
1246
|
+
# The newest commit that carries it: revs come newest
|
|
1247
|
+
# first, as git rev-list lists them.
|
|
1248
|
+
where = f" at {rev[:7]}" if name_commit else ""
|
|
1249
|
+
offenders.setdefault(str(finding), f"{finding}{where}")
|
|
1250
|
+
if not touched:
|
|
1251
|
+
return ValidationResult.SKIP
|
|
1252
|
+
if offenders:
|
|
1253
|
+
return self._fail(list(offenders.values()))
|
|
1254
|
+
# A file too large to read passes nothing: say so, rather than count
|
|
1255
|
+
# it as checked.
|
|
1256
|
+
not_read = ", ".join(sorted(unread))
|
|
1257
|
+
if not_read and not checked:
|
|
1258
|
+
self._skip_reason = f"not read (over 1 MiB or unreadable): {not_read}"
|
|
1259
|
+
return ValidationResult.SKIP
|
|
1260
|
+
self._checked_value = (
|
|
1261
|
+
f"{len(checked)} agent config file(s)"
|
|
1262
|
+
if checked
|
|
1263
|
+
else "no agent config file"
|
|
1264
|
+
)
|
|
1265
|
+
if not_read:
|
|
1266
|
+
self._checked_value += f"; not read: {not_read}"
|
|
1267
|
+
return ValidationResult.PASS
|
|
1268
|
+
|
|
1269
|
+
|
|
1167
1270
|
class MergeBaseValidator(BaseValidator):
|
|
1168
1271
|
"""Validates merge base ancestry."""
|
|
1169
1272
|
|
|
@@ -2309,6 +2412,10 @@ class ValidationEngine:
|
|
|
2309
2412
|
"file_size": FilesValidator,
|
|
2310
2413
|
"file_pattern": FilesValidator,
|
|
2311
2414
|
"path_length": FilesValidator,
|
|
2415
|
+
"agent_mcp_auto_approve": AgentConfigValidator,
|
|
2416
|
+
"agent_api_endpoint": AgentConfigValidator,
|
|
2417
|
+
"agent_full_access": AgentConfigValidator,
|
|
2418
|
+
"agent_unrestricted_trigger": AgentConfigValidator,
|
|
2312
2419
|
}
|
|
2313
2420
|
|
|
2314
2421
|
def __init__(self, rules: list[ValidationRule]):
|
commit_check/main.py
CHANGED
|
@@ -300,8 +300,9 @@ def _get_parser() -> argparse.ArgumentParser:
|
|
|
300
300
|
"-f",
|
|
301
301
|
"--files",
|
|
302
302
|
help="check the files the commit at HEAD (or --rev) touches: size "
|
|
303
|
-
"limit, prohibited path patterns, path length
|
|
304
|
-
"configured in the [files]
|
|
303
|
+
"limit, prohibited path patterns, path length, and risky settings in "
|
|
304
|
+
"agent config files (all off until configured in the [files] and "
|
|
305
|
+
"[agent] config sections)",
|
|
305
306
|
action="store_true",
|
|
306
307
|
required=False,
|
|
307
308
|
)
|
|
@@ -641,6 +642,38 @@ def _get_parser() -> argparse.ArgumentParser:
|
|
|
641
642
|
help="maximum number of characters in a committed file path",
|
|
642
643
|
)
|
|
643
644
|
|
|
645
|
+
# Agent config options
|
|
646
|
+
agent_group = parser.add_argument_group(
|
|
647
|
+
"agent options",
|
|
648
|
+
"Configuration options for the agent config rules, run by --files",
|
|
649
|
+
)
|
|
650
|
+
|
|
651
|
+
agent_group.add_argument(
|
|
652
|
+
"--agent-enabled",
|
|
653
|
+
type=parse_bool,
|
|
654
|
+
default=None,
|
|
655
|
+
metavar="BOOL",
|
|
656
|
+
help="report risky settings in the agent config files a commit "
|
|
657
|
+
"touches, such as .claude/settings.json (true/false)",
|
|
658
|
+
)
|
|
659
|
+
|
|
660
|
+
agent_group.add_argument(
|
|
661
|
+
"--agent-allow-mcp-servers",
|
|
662
|
+
type=parse_list,
|
|
663
|
+
default=None,
|
|
664
|
+
metavar="LIST",
|
|
665
|
+
help="comma-separated MCP server names the agent config may "
|
|
666
|
+
"approve without asking",
|
|
667
|
+
)
|
|
668
|
+
|
|
669
|
+
agent_group.add_argument(
|
|
670
|
+
"--agent-allow-api-endpoints",
|
|
671
|
+
type=parse_list,
|
|
672
|
+
default=None,
|
|
673
|
+
metavar="LIST",
|
|
674
|
+
help="comma-separated API endpoint URLs the agent config may send requests to",
|
|
675
|
+
)
|
|
676
|
+
|
|
644
677
|
return parser
|
|
645
678
|
|
|
646
679
|
|
|
@@ -808,8 +841,11 @@ def _get_requested_checks(args: argparse.Namespace) -> set[str]:
|
|
|
808
841
|
_UNCONFIGURED_HINTS = (
|
|
809
842
|
(
|
|
810
843
|
"files",
|
|
811
|
-
(
|
|
812
|
-
|
|
844
|
+
tuple(sorted(FILES_CHECKS)),
|
|
845
|
+
(
|
|
846
|
+
"--files requested but nothing is configured in the [files] or "
|
|
847
|
+
"[agent] section"
|
|
848
|
+
),
|
|
813
849
|
),
|
|
814
850
|
(
|
|
815
851
|
"branch",
|
commit_check/rule_builder.py
CHANGED
|
@@ -20,9 +20,11 @@ from commit_check import (
|
|
|
20
20
|
GIT_MERGE_SUBJECT_PATTERN,
|
|
21
21
|
GIT_REVERT_SUBJECT_PATTERN,
|
|
22
22
|
)
|
|
23
|
+
from commit_check.agent_config import ALLOWLISTS
|
|
23
24
|
from commit_check.config import ConfigError, report_notice
|
|
24
25
|
from commit_check.config_merger import get_default_config
|
|
25
26
|
from commit_check.rules_catalog import (
|
|
27
|
+
AGENT_CONFIG_RULES,
|
|
26
28
|
BRANCH_RULES,
|
|
27
29
|
COMMIT_RULES,
|
|
28
30
|
FILES_RULES,
|
|
@@ -304,6 +306,7 @@ class RuleBuilder:
|
|
|
304
306
|
rules.extend(self._build_branch_rules())
|
|
305
307
|
rules.extend(self._build_push_rules())
|
|
306
308
|
rules.extend(self._build_files_rules())
|
|
309
|
+
rules.extend(self._build_agent_config_rules())
|
|
307
310
|
rules.extend(self._build_tag_rules())
|
|
308
311
|
rules.extend(self._build_pull_request_rules())
|
|
309
312
|
if not self.warn_checks:
|
|
@@ -486,6 +489,39 @@ class RuleBuilder:
|
|
|
486
489
|
value=max_len,
|
|
487
490
|
)
|
|
488
491
|
|
|
492
|
+
def _build_agent_config_rules(self) -> list[ValidationRule]:
|
|
493
|
+
"""Build the agent config rules, CC601 to CC604.
|
|
494
|
+
|
|
495
|
+
Off by default, all four at once: ``[agent] enabled = true``
|
|
496
|
+
turns them on. Each rule that has an allowlist carries it as
|
|
497
|
+
``allowed``. ``warn`` can demote any of them on its own.
|
|
498
|
+
"""
|
|
499
|
+
section = self.config.get("agent", {})
|
|
500
|
+
if not isinstance(section, dict):
|
|
501
|
+
if section:
|
|
502
|
+
report_notice(
|
|
503
|
+
self.notices,
|
|
504
|
+
"[agent]",
|
|
505
|
+
f"[agent] must be a table, got {section!r}; "
|
|
506
|
+
"the agent config rules are disabled",
|
|
507
|
+
)
|
|
508
|
+
return []
|
|
509
|
+
if section.get("enabled") is not True:
|
|
510
|
+
return []
|
|
511
|
+
rules = []
|
|
512
|
+
for catalog_entry in AGENT_CONFIG_RULES:
|
|
513
|
+
key = ALLOWLISTS.get(catalog_entry.check)
|
|
514
|
+
allowed = _string_list(section, key, [], f"[agent] {key}") if key else None
|
|
515
|
+
rules.append(
|
|
516
|
+
ValidationRule(
|
|
517
|
+
check=catalog_entry.check,
|
|
518
|
+
error=catalog_entry.error,
|
|
519
|
+
suggest=catalog_entry.suggest,
|
|
520
|
+
allowed=allowed,
|
|
521
|
+
)
|
|
522
|
+
)
|
|
523
|
+
return rules
|
|
524
|
+
|
|
489
525
|
def _build_pull_request_rules(self) -> list[ValidationRule]:
|
|
490
526
|
"""Build the pull request rules.
|
|
491
527
|
|
commit_check/rules_catalog.py
CHANGED
|
@@ -13,6 +13,7 @@ ID ranges
|
|
|
13
13
|
``CC3xx`` Push and file rules
|
|
14
14
|
``CC4xx`` Tag rules
|
|
15
15
|
``CC5xx`` Pull request rules
|
|
16
|
+
``CC6xx`` Agent config rules
|
|
16
17
|
========= ==================================
|
|
17
18
|
|
|
18
19
|
Internal bookkeeping entries that never produce a diagnostic (such as
|
|
@@ -277,6 +278,41 @@ FILES_RULES = [
|
|
|
277
278
|
),
|
|
278
279
|
]
|
|
279
280
|
|
|
281
|
+
# Agent config rules: settings in the agent config files a commit changes
|
|
282
|
+
# that, once committed, hold for everyone who opens the repository. They run
|
|
283
|
+
# with the file rules, under --files, and read those files' contents. The
|
|
284
|
+
# settings each rule looks for are listed per agent in agent_configs.toml.
|
|
285
|
+
AGENT_CONFIG_RULES = [
|
|
286
|
+
RuleCatalogEntry(
|
|
287
|
+
rule_id="CC601",
|
|
288
|
+
check="agent_mcp_auto_approve",
|
|
289
|
+
regex=None,
|
|
290
|
+
error="MCP servers are approved without asking",
|
|
291
|
+
suggest="Remove it, or list trusted servers in allow_mcp_servers",
|
|
292
|
+
),
|
|
293
|
+
RuleCatalogEntry(
|
|
294
|
+
rule_id="CC602",
|
|
295
|
+
check="agent_api_endpoint",
|
|
296
|
+
regex=None,
|
|
297
|
+
error="API requests are sent to another endpoint",
|
|
298
|
+
suggest="Remove it, or list the endpoint in allow_api_endpoints",
|
|
299
|
+
),
|
|
300
|
+
RuleCatalogEntry(
|
|
301
|
+
rule_id="CC603",
|
|
302
|
+
check="agent_full_access",
|
|
303
|
+
regex=None,
|
|
304
|
+
error="The agent runs without asking or without a sandbox",
|
|
305
|
+
suggest="Remove it; set it in your user settings if you need it",
|
|
306
|
+
),
|
|
307
|
+
RuleCatalogEntry(
|
|
308
|
+
rule_id="CC604",
|
|
309
|
+
check="agent_unrestricted_trigger",
|
|
310
|
+
regex=None,
|
|
311
|
+
error="Anyone can start the agent",
|
|
312
|
+
suggest='List the allowed users or bots instead of "*"',
|
|
313
|
+
),
|
|
314
|
+
]
|
|
315
|
+
|
|
280
316
|
# Branch rules
|
|
281
317
|
BRANCH_RULES = [
|
|
282
318
|
RuleCatalogEntry(
|
|
@@ -337,6 +373,7 @@ ALL_RULES = [
|
|
|
337
373
|
*BRANCH_RULES,
|
|
338
374
|
*PUSH_RULES,
|
|
339
375
|
*FILES_RULES,
|
|
376
|
+
*AGENT_CONFIG_RULES,
|
|
340
377
|
*TAG_RULES,
|
|
341
378
|
*PULL_REQUEST_RULES,
|
|
342
379
|
)
|
|
@@ -375,4 +412,11 @@ PR_TITLE_CHECKS: frozenset[str] = MESSAGE_CHECKS - {
|
|
|
375
412
|
"ai_author",
|
|
376
413
|
}
|
|
377
414
|
BRANCH_CHECKS: frozenset[str] = frozenset({"branch", "merge_base"})
|
|
378
|
-
|
|
415
|
+
#: What ``--files`` runs: the file rules and the agent config rules, which
|
|
416
|
+
#: read the same files.
|
|
417
|
+
FILES_CHECKS: frozenset[str] = frozenset(
|
|
418
|
+
entry.check for entry in (*FILES_RULES, *AGENT_CONFIG_RULES)
|
|
419
|
+
)
|
|
420
|
+
AGENT_CONFIG_CHECKS: frozenset[str] = frozenset(
|
|
421
|
+
entry.check for entry in AGENT_CONFIG_RULES
|
|
422
|
+
)
|
commit_check/util.py
CHANGED
|
@@ -11,7 +11,7 @@ import os
|
|
|
11
11
|
import re
|
|
12
12
|
import subprocess
|
|
13
13
|
import sys
|
|
14
|
-
from collections.abc import Iterable
|
|
14
|
+
from collections.abc import Iterable, Sequence
|
|
15
15
|
from subprocess import CalledProcessError
|
|
16
16
|
|
|
17
17
|
from commit_check import BOLD, DIM, GREEN, RED, RESET_COLOR, YELLOW
|
|
@@ -65,8 +65,13 @@ def _print_failure(
|
|
|
65
65
|
"""
|
|
66
66
|
rule_id = check.get("rule_id", "")
|
|
67
67
|
warn = check.get("severity") == "warn"
|
|
68
|
+
# A list of findings, one a line, under a head such as "3 settings".
|
|
69
|
+
head = check.get("value_head")
|
|
70
|
+
items = actual.splitlines() if head else []
|
|
68
71
|
if compact:
|
|
69
72
|
compact_value = printable(actual.splitlines()[0]) if actual else actual
|
|
73
|
+
if len(items) > 1:
|
|
74
|
+
compact_value += f" (+{len(items) - 1} more)"
|
|
70
75
|
name = display_name(check["check"])
|
|
71
76
|
label = f"{rule_id} {name}" if rule_id else name
|
|
72
77
|
print(f"[{'WARN' if warn else 'FAIL'}] {label}: {compact_value}")
|
|
@@ -80,7 +85,8 @@ def _print_failure(
|
|
|
80
85
|
print_error_message(
|
|
81
86
|
check["check"],
|
|
82
87
|
printable(check.get("error", "")),
|
|
83
|
-
printable(actual),
|
|
88
|
+
printable(head or actual),
|
|
89
|
+
items=[printable(item) for item in items],
|
|
84
90
|
rule_id=rule_id,
|
|
85
91
|
docs_url=docs_url,
|
|
86
92
|
warn=warn,
|
|
@@ -417,6 +423,25 @@ def get_commit_files(rev: str = "HEAD") -> list[tuple[str, int]]:
|
|
|
417
423
|
return files
|
|
418
424
|
|
|
419
425
|
|
|
426
|
+
def get_file_text(rev: str, path: str) -> str | None:
|
|
427
|
+
"""The contents of *path* as committed in *rev*, or ``None``.
|
|
428
|
+
|
|
429
|
+
Read from the commit, not the working tree, for the same reason
|
|
430
|
+
:func:`get_commit_files` measures blob sizes: what is checked is what
|
|
431
|
+
was committed. Bytes that are not UTF-8 are replaced rather than
|
|
432
|
+
refused; the files read this way are config files, and a stray byte in
|
|
433
|
+
a comment should not hide the settings around it.
|
|
434
|
+
"""
|
|
435
|
+
result = subprocess.run(
|
|
436
|
+
["git", "cat-file", "blob", f"{rev}:{path}"],
|
|
437
|
+
capture_output=True,
|
|
438
|
+
check=False,
|
|
439
|
+
)
|
|
440
|
+
if result.returncode != 0:
|
|
441
|
+
return None
|
|
442
|
+
return result.stdout.decode("utf-8", errors="replace")
|
|
443
|
+
|
|
444
|
+
|
|
420
445
|
def get_push_commits(local_sha: str, remote_sha: str) -> list[str]:
|
|
421
446
|
"""List the commits a push introduces, newest first.
|
|
422
447
|
|
|
@@ -934,6 +959,7 @@ def print_error_message(
|
|
|
934
959
|
spec_name: str = "",
|
|
935
960
|
spec_url: str = "",
|
|
936
961
|
show_value: bool = True,
|
|
962
|
+
items: Sequence[str] = (),
|
|
937
963
|
) -> None:
|
|
938
964
|
"""Print error message.
|
|
939
965
|
|
|
@@ -951,6 +977,8 @@ def print_error_message(
|
|
|
951
977
|
trailing ``. See {spec_url}``, dropped once the name is a link
|
|
952
978
|
:param show_value: print ``reason`` after the verdict; off when the value
|
|
953
979
|
is already quoted above, so the line names the rule only
|
|
980
|
+
:param items: what ``reason`` counts, such as ``3 settings``: printed
|
|
981
|
+
one a line under the verdict, before the explanation
|
|
954
982
|
|
|
955
983
|
:returns: Give error messages to user
|
|
956
984
|
"""
|
|
@@ -977,6 +1005,9 @@ def print_error_message(
|
|
|
977
1005
|
tail = f" {DIM}(+{more} more line{'s' if more > 1 else ''}){RESET_COLOR}"
|
|
978
1006
|
head += f": {colour}{first}{RESET_COLOR}{tail}"
|
|
979
1007
|
print(head)
|
|
1008
|
+
bullet = _symbol("•", "-")
|
|
1009
|
+
for item in items:
|
|
1010
|
+
print(f"{_DETAIL_INDENT}{colour}{bullet} {item}{RESET_COLOR}")
|
|
980
1011
|
if error:
|
|
981
1012
|
# Same trade-off as the Docs: line above — once the spec name is a
|
|
982
1013
|
# link, spelling out its address only adds noise; without hyperlink
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: commit-check
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.25.0
|
|
4
4
|
Summary: Commit policy as code for teams and AI agents: check commit messages, branch names, authors, tags, files and AI attribution.
|
|
5
5
|
Author-email: Xianpeng Shen <xianpeng.shen@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -8,7 +8,7 @@ Project-URL: Documentation, https://commit-check.com/
|
|
|
8
8
|
Project-URL: Changelog, https://commit-check.com/changelog/
|
|
9
9
|
Project-URL: Source, https://github.com/commit-check/commit-check
|
|
10
10
|
Project-URL: Issues, https://github.com/commit-check/commit-check/issues
|
|
11
|
-
Keywords: commit conventions,conventional commits,conventional branch,branch naming,commit-check,message,lint message,devops,policy as code,ai agents
|
|
11
|
+
Keywords: commit conventions,conventional commits,conventional branch,branch naming,commit-check,message,lint message,devops,policy as code,ai agents,github actions,gitlab ci,bitbucket pipelines
|
|
12
12
|
Classifier: Development Status :: 5 - Production/Stable
|
|
13
13
|
Classifier: Intended Audience :: Developers
|
|
14
14
|
Classifier: Natural Language :: English
|
|
@@ -55,6 +55,8 @@ Dynamic: license-file
|
|
|
55
55
|
[Rules](https://commit-check.com/rules/) ·
|
|
56
56
|
[GitHub Action](https://github.com/commit-check/commit-check-action) ·
|
|
57
57
|
[GitHub App](https://github.com/apps/commit-check) ·
|
|
58
|
+
[GitLab CI](https://commit-check.com/guides/other-ci/#gitlab-ci) ·
|
|
59
|
+
[Bitbucket Pipelines](https://commit-check.com/guides/other-ci/#bitbucket-pipelines) ·
|
|
58
60
|
[MCP server](https://github.com/commit-check/commit-check-mcp)
|
|
59
61
|
|
|
60
62
|
</div>
|
|
@@ -62,8 +64,8 @@ Dynamic: license-file
|
|
|
62
64
|
**Commit Check** is commit policy as code for teams and AI agents. It validates
|
|
63
65
|
commit messages, branch names, authors, sign-offs, tags, committed files and AI
|
|
64
66
|
attribution against one `cchk.toml` — in your commit hook, in CI, on every
|
|
65
|
-
pull
|
|
66
|
-
the line.
|
|
67
|
+
pull or merge request on GitHub, GitLab and Bitbucket, and inside your AI
|
|
68
|
+
agent. When the fix is obvious, it hands you the line.
|
|
67
69
|
|
|
68
70
|
**On GitHub?** [Install the Commit Check App](https://github.com/apps/commit-check)
|
|
69
71
|
and every push and pull request gets a check run, with no workflow file. It is
|
|
@@ -88,7 +90,7 @@ Stop bad commits before they exist. In `.pre-commit-config.yaml`:
|
|
|
88
90
|
```yaml
|
|
89
91
|
repos:
|
|
90
92
|
- repo: https://github.com/commit-check/commit-check
|
|
91
|
-
rev: v2.
|
|
93
|
+
rev: v2.25.0
|
|
92
94
|
hooks:
|
|
93
95
|
- id: check-message
|
|
94
96
|
- id: check-branch
|
|
@@ -108,7 +110,8 @@ The same `cchk.toml` drives all of them:
|
|
|
108
110
|
|---|---|
|
|
109
111
|
| GitHub, no workflow | [Install the GitHub App](https://github.com/apps/commit-check) — one check run per commit |
|
|
110
112
|
| GitHub Actions | `uses: commit-check/commit-check-action@v2` — see [commit-check-action](https://github.com/commit-check/commit-check-action) |
|
|
111
|
-
| GitLab CI,
|
|
113
|
+
| GitLab CI, Azure Pipelines | A job in the pipeline — see the [CI guide](https://commit-check.com/guides/other-ci/) |
|
|
114
|
+
| Bitbucket Pipelines | The Commit Check pipe, one of Atlassian's [official pipes](https://bitbucket.org/product/features/pipelines/integrations) — see the [CI guide](https://commit-check.com/guides/other-ci/#bitbucket-pipelines) |
|
|
112
115
|
| AI agents | The [agent skill](#agent-skill), `--format json`, the [Python API](#ai-native-usage), or the [MCP server](https://github.com/commit-check/commit-check-mcp) |
|
|
113
116
|
|
|
114
117
|
## What it checks
|
|
@@ -188,6 +191,9 @@ Priority: CLI > env > TOML > default. Booleans accept `true/false`, `yes/no`,
|
|
|
188
191
|
| `files.max_size` | `""` (off) | `--files-max-size` | `CCHK_FILES_MAX_SIZE` | Largest committed file, in bytes or with `KB`/`MB`/`GB` (CC302) |
|
|
189
192
|
| `files.prohibited_patterns` | `[]` | `--files-prohibited-patterns` | `CCHK_FILES_PROHIBITED_PATTERNS` | fnmatch patterns committed paths must not match (CC303) |
|
|
190
193
|
| `files.max_path_length` | `0` (off) | `--files-max-path-length` | `CCHK_FILES_MAX_PATH_LENGTH` | Longest allowed committed path, in characters (CC304) |
|
|
194
|
+
| `agent.enabled` | `false` | `--agent-enabled` | `CCHK_AGENT_ENABLED` | Report risky settings in the agent config files a commit touches, with `--files`: MCP servers approved without asking (CC601), API requests sent to another endpoint (CC602), commands run without asking or outside the sandbox (CC603), and agent workflows anyone can start (CC604). Covers Claude Code, Codex, Gemini CLI, Cursor CLI, GitHub Copilot in VS Code and the Claude Code GitHub Action; the list is [`agent_configs.toml`](https://github.com/commit-check/commit-check/blob/main/commit_check/agent_configs.toml) |
|
|
195
|
+
| `agent.allow_mcp_servers` | `[]` | `--agent-allow-mcp-servers` | `CCHK_AGENT_ALLOW_MCP_SERVERS` | MCP servers, by name, that the agent config may approve (CC601) |
|
|
196
|
+
| `agent.allow_api_endpoints` | `[]` | `--agent-allow-api-endpoints` | `CCHK_AGENT_ALLOW_API_ENDPOINTS` | API endpoint URLs the agent config may send requests to (CC602), such as your company's LLM gateway |
|
|
191
197
|
| `pull_request.ai_declaration_checkboxes` | `[]` (off) | — | — | The AI declaration checkboxes of your pull request template (often headed "AI disclosure"), e.g. `["No AI tools were used", "AI tools were used"]`. A description checked with `--ai-attribution-only` must tick exactly one of them (CC501). Each entry matches a box whose text starts with it, ignoring case and bold; boxes in HTML comments and code blocks do not count |
|
|
192
198
|
|
|
193
199
|
Output and appearance are per-run flags, not configuration: `--format json`,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
commit_check/__init__.py,sha256=lKMivNHT2PY_0ngRRMvTdQVdrYeE_5eS3MtNY3CaLQw,7092
|
|
2
|
+
commit_check/_https.py,sha256=Eyi-zKEfDcwXJ_3b82UOo9_RxFQkD8uF4zU7MGUVDj0,1215
|
|
3
|
+
commit_check/agent_config.py,sha256=yzHa3hWIgod8VN1B19uVXlFhBKeFQMSyOFI_MMkmxew,20410
|
|
4
|
+
commit_check/agent_configs.toml,sha256=CmfV_Xdgv8WdqmK_OOuSA6Kx58tnzrepJPEOF72MOcI,5787
|
|
5
|
+
commit_check/ai_policy.py,sha256=gYC3ROLgGL1TDyhPkFXkV-NiYbvMt80Qt0MFrJcbJY4,8131
|
|
6
|
+
commit_check/ai_signatures.py,sha256=y_iqVVmMXhcutcKoNvdp5dUUEwgsDwj1HGwYGyN5oCA,11708
|
|
7
|
+
commit_check/ai_signatures_data.py,sha256=fZ9TpKNGqk0sYuko5PoHUFEEL_uRu9HK9RYGSvZTp3w,23170
|
|
8
|
+
commit_check/api.py,sha256=GYeRo2o_GgK90Srk9gaINcP8QGzXvB4atcp4ygxV2tQ,13920
|
|
9
|
+
commit_check/ci.py,sha256=i5mIoTs0BtKhKM6DpMbJfw1KwFvfXM-gDz2nE2ALseg,19050
|
|
10
|
+
commit_check/config.py,sha256=NaddFMR-nRPSpEyNN3FX0I1lq2WqF0JE7LHTlDEDe1U,14715
|
|
11
|
+
commit_check/config_merger.py,sha256=R92apqISOUPP7CyuIXtOuAGAZvLiAuEC7GMWDktsnZk,16642
|
|
12
|
+
commit_check/engine.py,sha256=KJo-lELHWu5Ue0DJlLr5eOOaS_YZ3wg0Y2v27cSYHdI,107142
|
|
13
|
+
commit_check/fixes.py,sha256=BpbdoHsKDyw2WfsqymwYpnrW73aHdCDGr8tMF6Ho2RU,7305
|
|
14
|
+
commit_check/imperatives.py,sha256=dEd_ssu4G0j6Cann6jqPdB97lw5Adua43K0_Odg_FyA,9518
|
|
15
|
+
commit_check/main.py,sha256=2HrCMolC22KhjiDjl9nzEg-RWp6sf3BiqDmPC8jymBs,36318
|
|
16
|
+
commit_check/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
17
|
+
commit_check/rule_builder.py,sha256=YfF8LZ8OuIr9gN41Nyb0KgCDQxccmgc8_6ZojGw5kd4,40058
|
|
18
|
+
commit_check/rules_catalog.py,sha256=NCcsAtWwwgIZ68AZ65emBmczrAQ0GK0qv-fTLmnXktY,15869
|
|
19
|
+
commit_check/util.py,sha256=0-bdlOhxOQ8K3miRjbtMCeh-A19IsQtvQNlR4T-VN4I,40033
|
|
20
|
+
commit_check-2.25.0.dist-info/licenses/LICENSE,sha256=9mdTva71kQhrpWh_nZulxrdCnUrl5c6xJYh5hdo4p_s,1070
|
|
21
|
+
commit_check-2.25.0.dist-info/METADATA,sha256=QYdQuv132vrOwX1u8or69svq4ixIAjm3YppJ1LM8plI,21852
|
|
22
|
+
commit_check-2.25.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
23
|
+
commit_check-2.25.0.dist-info/entry_points.txt,sha256=-4RWjQDhmngfCnTx46iCz3RrI8WZoiMZo0nhsg6hmUw,125
|
|
24
|
+
commit_check-2.25.0.dist-info/top_level.txt,sha256=Wf46u-ooHBMJNHbhfrBNQw3wC5_m8wt-o_Lfbc4QpRg,13
|
|
25
|
+
commit_check-2.25.0.dist-info/RECORD,,
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
commit_check/__init__.py,sha256=lKMivNHT2PY_0ngRRMvTdQVdrYeE_5eS3MtNY3CaLQw,7092
|
|
2
|
-
commit_check/_https.py,sha256=Eyi-zKEfDcwXJ_3b82UOo9_RxFQkD8uF4zU7MGUVDj0,1215
|
|
3
|
-
commit_check/ai_policy.py,sha256=gYC3ROLgGL1TDyhPkFXkV-NiYbvMt80Qt0MFrJcbJY4,8131
|
|
4
|
-
commit_check/ai_signatures.py,sha256=y_iqVVmMXhcutcKoNvdp5dUUEwgsDwj1HGwYGyN5oCA,11708
|
|
5
|
-
commit_check/ai_signatures_data.py,sha256=fZ9TpKNGqk0sYuko5PoHUFEEL_uRu9HK9RYGSvZTp3w,23170
|
|
6
|
-
commit_check/api.py,sha256=GYeRo2o_GgK90Srk9gaINcP8QGzXvB4atcp4ygxV2tQ,13920
|
|
7
|
-
commit_check/ci.py,sha256=i9cIlMbIn_nHA4cln2YUgCReYm22efkPqKyjh-gq3kQ,19022
|
|
8
|
-
commit_check/config.py,sha256=NaddFMR-nRPSpEyNN3FX0I1lq2WqF0JE7LHTlDEDe1U,14715
|
|
9
|
-
commit_check/config_merger.py,sha256=sXOTAVaTY2-oRzvhS1NeQuPAqnM8XoGTVMDkY0z-vDA,15858
|
|
10
|
-
commit_check/engine.py,sha256=Yyh3xYdBJGKdONviD-PcmsQiCY0QRYydgE6hJNOJP_k,102258
|
|
11
|
-
commit_check/fixes.py,sha256=BpbdoHsKDyw2WfsqymwYpnrW73aHdCDGr8tMF6Ho2RU,7305
|
|
12
|
-
commit_check/imperatives.py,sha256=dEd_ssu4G0j6Cann6jqPdB97lw5Adua43K0_Odg_FyA,9518
|
|
13
|
-
commit_check/main.py,sha256=uf32w7vRGPxN_GI5dadzeIuRft1dmRiUfOTnTmon63o,35284
|
|
14
|
-
commit_check/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
|
-
commit_check/rule_builder.py,sha256=mRYi3-4gJYgWOnQojVCDVbR0VMXHoBV92dB46w5RRMY,38645
|
|
16
|
-
commit_check/rules_catalog.py,sha256=0jUT-e78me1RJAsxLHyzTCpVobKHjtNbmhnFvX5GsOc,14289
|
|
17
|
-
commit_check/util.py,sha256=VE0qNx2HpyDB1CPFF_p7I2EOJzAPs_yKDCJ1zFyCdok,38710
|
|
18
|
-
commit_check-2.24.2.dist-info/licenses/LICENSE,sha256=9mdTva71kQhrpWh_nZulxrdCnUrl5c6xJYh5hdo4p_s,1070
|
|
19
|
-
commit_check-2.24.2.dist-info/METADATA,sha256=j_fwgkvz7_5nbV5INcw6GyagIni2FMML3HCR1X2iJUQ,20432
|
|
20
|
-
commit_check-2.24.2.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
21
|
-
commit_check-2.24.2.dist-info/entry_points.txt,sha256=-4RWjQDhmngfCnTx46iCz3RrI8WZoiMZo0nhsg6hmUw,125
|
|
22
|
-
commit_check-2.24.2.dist-info/top_level.txt,sha256=Wf46u-ooHBMJNHbhfrBNQw3wC5_m8wt-o_Lfbc4QpRg,13
|
|
23
|
-
commit_check-2.24.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|