diff --git a/.agents/skills/create-commit/SKILL.md b/.agents/skills/create-commit/SKILL.md index dd85191fd9..264f870e03 100644 --- a/.agents/skills/create-commit/SKILL.md +++ b/.agents/skills/create-commit/SKILL.md @@ -63,6 +63,8 @@ subject/body limits, and the `AI-assisted-by` trailer. Follow it exactly. - Do not pass `--author`. Author identity comes from the local git config. - Do not amend a commit you did not create in this session, unless explicitly asked. - Do not bypass pre-commit hooks (`--no-verify`) unless explicitly asked. -- Never add a `Co-authored-by:` trailer. It is forbidden and fails `./scripts/check-commit`. +- Add `Co-authored-by:` only for a human co-author. AI providers, agents and + bots are rejected by `./scripts/check-commit`; for AI participation use the + `AI-assisted-by:` trailer. - Do not add untracked files that were not created in this session. - Do not skip the `scripts/check-commit` verification step (Iron Rule 4). diff --git a/.serena/memories/workflow/creating-commits.md b/.serena/memories/workflow/creating-commits.md index cf08358aaf..914ba4f0bc 100644 --- a/.serena/memories/workflow/creating-commits.md +++ b/.serena/memories/workflow/creating-commits.md @@ -43,10 +43,9 @@ that breaks them is wrong, even if the code is right. - For another commit: `./scripts/check-commit -c ` - **NEVER** hand-wave the body as "one long line". If a line exceeds 80, break it at a space. -- **NEVER add a `Co-authored-by:` trailer.** It is forbidden; `scripts/check-commit` fails the commit when any line matches it (case-insensitive). +- **`Co-authored-by:` is for human co-authors only** (`Co-authored-by: Name `). AI providers, agents and bots must not be credited that way; use `AI-assisted-by:` instead. `scripts/check-commit` rejects a trailer value that names an AI provider or agent (`Claude`, `Copilot`, `Cursor`, `Codex`, `Gemini`, `Aider`, `Cline`, `Windsurf`, `DeepSeek`, `OpenCode`, `devin-ai`, `amazon q`, and similar) or carries a bot identity (`[bot]`, `bot@`). `NON_HUMAN_COAUTHOR_PATTERN` is the list; extend it when a new tool starts adding trailers. A person whose own name or email matches one of those tokens (a surname like `Cline`, an address at a provider) is rejected too; amend the trailer or credit them with `Reviewed-by:`. - CI runs `scripts/check-commit` on every new commit (`mem:workflow/creating-commits` is enforced by `.github/workflows/commit-checker.yml`), so a forbidden trailer fails the build. -- Exceptions inside the body (do not wrap these): `Signed-off-by:`, - `AI-assisted-by:` trailers, and lines carrying a URL. +- Exceptions inside the body (do not wrap these): `Signed-off-by:`, `Co-authored-by:`, `AI-assisted-by:` trailers, and lines carrying a URL. **AI-assisted-by trailer rules:** - Use only the model name, e.g. `mimo-v2.5`, `deepseek-v4-flash` diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9b23ae0fa9..83ab63e168 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -225,8 +225,11 @@ Commit messages must follow this format: those prefixes to an existing subject) - **Wrap body lines at 80 characters or fewer** (trailers and URLs excepted) - Separate the subject from the body with a **blank line** -- Never add a `Co-authored-by` trailer — it is forbidden and fails - `./scripts/check-commit` +- Use `Co-authored-by:` only for a human co-author + (`Co-authored-by: Name `). AI providers, agents and bots are not + allowed there; for AI participation add an `AI-assisted-by: ` + trailer instead. `./scripts/check-commit` rejects the trailer when its value + names one of them. You can check a commit against these rules with `./scripts/check-commit`. CI runs the same script on every new commit in diff --git a/scripts/check-commit b/scripts/check-commit index df4672ea59..852bab8240 100755 --- a/scripts/check-commit +++ b/scripts/check-commit @@ -52,11 +52,26 @@ MAX_SUBJECT_LINE = 80 MAX_BODY_LINE = 80 TRAILER_PATTERN = re.compile( - r"^(Signed-off-by|Co-developed-by|Reviewed-by|" + r"^(Signed-off-by|Co-authored-by|Co-developed-by|Reviewed-by|" r"Acked-by|Tested-by|Reported-by|Suggested-by|AI-assisted-by):" ) -FORBIDDEN_TRAILER_PATTERN = re.compile(r"^\s*Co-authored-by\s*:", re.IGNORECASE) +# ── Co-authored-by trailer ─────────────────────────────────────────────────── +# A human co-author may be credited with Co-authored-by. The trailer is +# forbidden when its value names an AI provider, an AI agent, or a bot: for AI +# participation the message uses "AI-assisted-by: " instead. +# Extend this list when a new tool starts adding trailers. +NON_HUMAN_COAUTHOR_PATTERN = re.compile( + r"^\s*co-authored-by\s*:.*(" + r"\b(?:chatgpt|openai|anthropic|claude|copilot|codex|gemini|bard|" + r"deepseek|mistral|qwen|kimi|llama|grok|cursor|" + r"windsurf|cline|aider|codeium|tabnine|amazon\s+q|sourcegraph\s+cody|" + r"roo\s+code|kilo\s+code|opencode)\b" + r"|\bdevin-ai|@devin\.ai" + r"|\[bot\]|\bbot@" + r")", + re.IGNORECASE, +) URL_PATTERN = re.compile(r"https?://\S+") @@ -218,12 +233,12 @@ def check_signed_off_by(message): return True, None -def check_no_co_authored_by(message): - """Check that the forbidden Co-authored-by trailer is absent.""" +def check_co_authored_by(message): + """Co-authored-by is allowed for humans, not for AI providers or bots.""" offenders = [ (line_number, line) for line_number, line in enumerate(message.split("\n"), start=1) - if FORBIDDEN_TRAILER_PATTERN.match(line) + if NON_HUMAN_COAUTHOR_PATTERN.match(line) ] if not offenders: return True, None @@ -232,8 +247,10 @@ def check_no_co_authored_by(message): for line_number, line in offenders ) return False, ( - "The 'Co-authored-by:' trailer is forbidden and must not appear " - "in the commit message. Offending line(s):\n" + details + "The 'Co-authored-by:' trailer is only for human co-authors. This one " + "names an AI provider, an AI agent, or a bot. Offending line(s):\n" + + details + + "\n For AI participation use: AI-assisted-by: " ) @@ -262,7 +279,7 @@ def main(): ("Subject capitalized", check_subject_capitalized), ("Blank line after subject", check_body_blank_line), ("Body wrapped at 80 chars", check_body_line_length), - ("No Co-authored-by trailer", check_no_co_authored_by), + ("Co-authored-by is human only", check_co_authored_by), ] all_ok = True diff --git a/scripts/test_check_commit.py b/scripts/test_check_commit.py index 037bc8fd56..05cc38671d 100644 --- a/scripts/test_check_commit.py +++ b/scripts/test_check_commit.py @@ -6,7 +6,9 @@ Run with: python3 scripts/test_check_commit.py Covers the body line-wrapping validator added to enforce the commit body -wrap rule documented in .serena/memories/workflow/creating-commits.md. +wrap rule documented in .serena/memories/workflow/creating-commits.md, and +the Co-authored-by validator, which allows human co-authors and rejects AI +providers and bots. """ import importlib.machinery @@ -87,6 +89,14 @@ class BodyLineLengthTests(unittest.TestCase): line = "Signed-off-by: Someone With A Long Name " self.assert_ok(":bug: Fix crash\n\nBody.\n\n" + line + "\n") + def test_human_co_author_trailer_passes(self): + line = ( + "Co-authored-by: Someone With A Very Long Name " + "" + ) + self.assertGreater(len(line), 80) + self.assert_ok(":bug: Fix crash\n\nBody.\n\n" + line + "\n") + def test_unbreakable_token_passes(self): line = "a" * 100 # no whitespace to wrap at self.assert_ok(":bug: Fix crash\n\n" + line + "\n") @@ -106,14 +116,16 @@ class BodyLineLengthTests(unittest.TestCase): self.assertIn("line 4", error) -class ForbiddenTrailerTests(unittest.TestCase): +class CoAuthorTrailerTests(unittest.TestCase): + """Co-authored-by is allowed for humans, forbidden for AI providers/bots.""" + def assert_ok(self, message): - ok, error = check_commit.check_no_co_authored_by(message) + ok, error = check_commit.check_co_authored_by(message) self.assertTrue(ok, error) self.assertIsNone(error) def assert_fail(self, message): - ok, error = check_commit.check_no_co_authored_by(message) + ok, error = check_commit.check_co_authored_by(message) self.assertFalse(ok) self.assertIsNotNone(error) return error @@ -121,15 +133,57 @@ class ForbiddenTrailerTests(unittest.TestCase): def test_body_without_trailer_passes(self): self.assert_ok(":bug: Fix crash\n\nBody.\n\nSigned-off-by: Someone \n") - def test_co_authored_by_fails(self): - error = self.assert_fail(":bug: Fix crash\n\nBody.\n\nCo-authored-by: Someone \n") - self.assertIn("Co-authored-by", error) + def test_human_co_author_passes(self): + self.assert_ok(":bug: Fix crash\n\nBody.\n\nCo-authored-by: Jane Doe \n") - def test_co_authored_by_case_insensitive_fails(self): - self.assert_fail(":bug: Fix crash\n\nBody.\n\nco-authored-by: Someone \n") + def test_human_with_github_noreply_email_passes(self): + self.assert_ok( + ":bug: Fix crash\n\nBody.\n\n" + "Co-authored-by: Jane Doe <1234+jane@users.noreply.github.com>\n" + ) + + def test_human_whose_email_ends_with_bot_passes(self): + # "abbot@" must not count as a "bot@" identity. + self.assert_ok( + ":bug: Fix crash\n\nBody.\n\n" + "Co-authored-by: Jane Abbot \n" + ) + + def test_claude_fails(self): + error = self.assert_fail( + ":bug: Fix crash\n\nBody.\n\n" + "Co-authored-by: Claude \n" + ) + self.assertIn("Co-authored-by", error) + self.assertIn("AI-assisted-by", error) + + def test_cursor_fails(self): + self.assert_fail( + ":bug: Fix crash\n\nBody.\n\n" + "Co-authored-by: Cursor Agent \n" + ) + + def test_copilot_fails(self): + self.assert_fail( + ":bug: Fix crash\n\nBody.\n\n" + "Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>\n" + ) + + def test_case_insensitive_fails(self): + self.assert_fail( + ":bug: Fix crash\n\nBody.\n\nco-authored-by: CHATGPT \n" + ) + + def test_bot_identity_fails(self): + self.assert_fail( + ":bug: Fix crash\n\nBody.\n\n" + "Co-authored-by: dependabot[bot] \n" + ) def test_co_authored_by_in_body_fails(self): - self.assert_fail(":bug: Fix crash\n\nCo-authored-by: Someone \nBody.\n") + self.assert_fail( + ":bug: Fix crash\n\nCo-authored-by: Gemini \nBody.\n" + ) def test_similar_trailer_passes(self): self.assert_ok(":bug: Fix crash\n\nBody.\n\nCo-developed-by: Someone \n")