Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix(tooling): 署名门槛只要求本机提交者的智能体署名

longmeidao5fdec91b52ef
diff --git a/.claude/skills/peach-worktree/SKILL.md b/.claude/skills/peach-worktree/SKILL.md
index f4625898d..7e6cca667 100644
--- a/.claude/skills/peach-worktree/SKILL.md
+++ b/.claude/skills/peach-worktree/SKILL.md
@@ -5,7 +5,7 @@ description: Peach 代码任务开工,以及创建、提交、集成或回收
# 工作树与集成交付
-最后复核:2026-10-27
+最后复核:2026-10-28
证据来源:工作树入口、交付门槛、集成与回收事故、用户确认的存量生效判据。
## 开工与职责
@@ -44,7 +44,8 @@ description: Peach 代码任务开工,以及创建、提交、集成或回收
- 逐文件暂存后核对 `git diff --cached --name-status` 与任务边界,不使用目录、glob、`git add .` 或 `git add -A`。实现与对应测试原子提交。
- 主题为 `type(scope): 中文描述`,类型以 `scripts/commit_subject.py` 为准。
-- 每个交付提交带 `Co-Authored-By: 工具 (实际模型版本) <厂商 noreply>`,名单见 `scripts/co_author.py`;接力作者并列,人类共同作者保留姓名与邮箱。
+- 本机提交者自己的交付提交带 `Co-Authored-By: 工具 (实际模型版本) <厂商 noreply>`,名单见 `scripts/co_author.py`;接力作者并列,人类共同作者保留姓名与邮箱。
+- 采纳社区补丁时保留原作者为提交作者,写 `Source-PR`、`Original-Commit`,不替贡献者补 AI 署名;只有智能体改写或补充了代码时,才加它自己的署名。
- 最后提交写唯一 `README-Impact`,需要时带 `README-Reviewed`,按 `docs/README_MAINTENANCE.md` 核对中英文。所有 trailer 连续放末尾同一块,块内无空行,块前空一行。
## 回收与顶层归置
diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md
index 732737e30..4a522d205 100644
--- a/.github/PULL_REQUEST_TEMPLATE.md
+++ b/.github/PULL_REQUEST_TEMPLATE.md
@@ -33,7 +33,7 @@ Refs #
## AI 参与
-<!-- 未使用时写「未使用」;使用时说明方案、代码、测试、文档或 PR 文字的参与范围,以及提交者实际检查的内容。无需提示词或模型名称;提交署名沿用项目约定。 -->
+<!-- 未使用时写「未使用」;使用时说明方案、代码、测试、文档或 PR 文字的参与范围,以及提交者实际检查的内容。无需提示词或模型名称,提交里也不需要加 AI 署名。 -->
- 参与范围:
- 提交者实际检查的内容:
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index c097cc0ab..d530d39db 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -73,7 +73,9 @@ GitHub 的字段与模板机制见 [Issue types](https://docs.github.com/en/issu
### AI 参与与提交责任
-允许 AI 辅助方案、代码、测试、文档和 PR 文字。使用时简短说明参与范围,以及提交者实际检查的内容;不要求提供提示词或模型名称。项目智能体的提交署名仍按工作树交付约定执行。
+允许 AI 辅助方案、代码、测试、文档和 PR 文字。使用时简短说明参与范围,以及提交者实际检查的内容;不要求提供提示词或模型名称,提交里也不需要加 AI 署名。
+
+维护者采纳社区补丁时保留原作者为提交作者,用 `Source-PR`、`Original-Commit` 记录来源,不替贡献者补加 AI 署名。提交里的智能体署名表示维护侧智能体的改写或补充,只在它确实改动了代码时出现,不代表贡献者使用了 AI。署名门槛只检查维护者本机提交者自己的提交,见工作树交付约定。
提交者对最终内容负责,能够解释设计与取舍,并核对代码、说明和验证结果。未运行的测试、跳过项、未取得的样本和待原环境验收的部分在「测试结果」中明确标注,不把推测写成已验证结论。维护者按影响和风险评审,授权与确认边界见 `AGENTS.md`。
diff --git a/scripts/check_commit_message.py b/scripts/check_commit_message.py
index 9bdf531ba..3a755764d 100644
--- a/scripts/check_commit_message.py
+++ b/scripts/check_commit_message.py
@@ -12,9 +12,15 @@ if not __package__:
from . import check_readme_impact, co_author
-def check(repo: Path, message: str) -> list[str]:
+def author_mail(repo: Path) -> str:
+ """这次提交实际采用的作者邮箱,`--author` 与 cherry-pick 保留的原作者都算。"""
+ ident = check_readme_impact.git(repo, "var", "GIT_AUTHOR_IDENT")
+ return ident.partition("<")[2].partition(">")[0]
+
+
+def check(repo: Path, message: str, *, own: bool = True) -> list[str]:
parsed = check_readme_impact.trailers(repo, message)
- problems = co_author.problems("待提交", parsed.get("co-authored-by", []))
+ problems = co_author.problems("待提交", parsed.get("co-authored-by", []), own=own)
for name in ("Co-Authored-By", "README-Impact", "README-Reviewed"):
mentioned = sum(line.partition(":")[0].casefold() == name.casefold()
for line in message.splitlines())
@@ -38,7 +44,8 @@ def main(argv=None) -> int:
merge = check_readme_impact.git(repo, "rev-parse", "--git-path", "MERGE_HEAD").strip()
if not branch.startswith("agent/") or (repo / merge).exists():
return 0
- problems = check(repo, args.message_file.read_text(encoding="utf-8"))
+ own = co_author.is_own(author_mail(repo), co_author.committer_mail(repo))
+ problems = check(repo, args.message_file.read_text(encoding="utf-8"), own=own)
except (OSError, UnicodeError, subprocess.CalledProcessError) as error:
print(f"未取得提交校验结果:{error}", file=sys.stderr)
return 1
diff --git a/scripts/co_author.py b/scripts/co_author.py
index bb3188783..d856c0c4f 100644
--- a/scripts/co_author.py
+++ b/scripts/co_author.py
@@ -3,6 +3,7 @@
from __future__ import annotations
import re
+import subprocess
from pathlib import Path
from .check_readme_impact import git, trailers, unpublished
@@ -28,16 +29,32 @@ def values(repo: Path, head: str = "HEAD") -> list[str]:
return trailers(repo, message).get("co-authored-by", [])
-def commits(repo: Path, base: str, head: str = "HEAD") -> list[tuple[str, str]]:
- """分支自己的提交:(取值用的 hash, 给人看的 `短 hash 主题`),不含合进来的 merge 与已发布到远端的。"""
- output = git(repo, "log", "--no-merges", "--format=%H%x00%h %s", f"{base}..{head}", *unpublished(repo))
- return [(line.partition("\0")[0], line.partition("\0")[2])
- for line in output.splitlines() if line.strip()]
+def commits(repo: Path, base: str, head: str = "HEAD") -> list[tuple[str, str, str]]:
+ """分支自己的提交:(取值用的 hash, 给人看的 `短 hash 主题`, 作者邮箱),不含合进来的 merge 与已发布到远端的。"""
+ output = git(repo, "log", "--no-merges", "--format=%H%x00%h %s%x00%ae", f"{base}..{head}", *unpublished(repo))
+ return [tuple(line.split("\0", 2)) for line in output.splitlines() if line.strip()]
-def problems(label: str, found: list[str]) -> list[str]:
+def committer_mail(repo: Path) -> str:
+ """本机提交者的邮箱;没配置时返回空串,按本机提交处理。"""
+ try:
+ return git(repo, "config", "--get", "user.email").strip()
+ except subprocess.CalledProcessError:
+ return ""
+
+
+def is_own(author_mail: str, local_mail: str) -> bool:
+ """作者就是本机提交者,才算本机智能体路径的产出;取不到本机邮箱时从严处理。"""
+ return not local_mail or author_mail.strip().casefold() == local_mail.strip().casefold()
+
+
+def problems(label: str, found: list[str], *, own: bool = True) -> list[str]:
+ """本机提交须有登记过的智能体署名;采纳的他人提交不要求,自带的署名只核形态。
+
+ 外部贡献者是否用了 AI 由本人在 PR 里说明,门槛不替作者补签,也不卡他用的工具名单。
+ """
if not found:
- return [f"提交「{label}」须有 Co-Authored-By 写明工具与模型,如 {EXAMPLE}"]
+ return [f"提交「{label}」须有 Co-Authored-By 写明工具与模型,如 {EXAMPLE}"] if own else []
problems = []
has_agent = False
for value in found:
@@ -51,30 +68,33 @@ def problems(label: str, found: list[str]) -> list[str]:
problems.append(f"提交「{label}」的署名「{value}」形态不对,须为 工具 (模型 版本) "
f"<厂商 noreply>,如 {EXAMPLE}")
elif parsed["tool"] not in VENDORS:
- problems.append(f"提交「{label}」的署名里,工具「{parsed['tool']}」未登记,"
- "已登记:" + "、".join(VENDORS))
+ if own:
+ problems.append(f"提交「{label}」的署名里,工具「{parsed['tool']}」未登记,"
+ "已登记:" + "、".join(VENDORS))
elif parsed["mail"] != VENDORS[parsed["tool"]]:
problems.append(f"提交「{label}」里 {parsed['tool']} 的署名地址须是 "
f"{VENDORS[parsed['tool']]},不是 {parsed['mail']}")
else:
has_agent = True
- if not problems and not has_agent:
+ if own and not problems and not has_agent:
problems.append(f"提交「{label}」须有 Co-Authored-By 写明工具与模型,如 {EXAMPLE}")
return problems
def check(repo: Path, base: str, head: str = "HEAD") -> list[str]:
- """分支上每个非 merge 提交都要有署名,且每一条都合规。
+ """分支上每个非 merge 提交的署名都要合规;本机提交还要有登记过的智能体署名。
- 署名是事后追责唯一的入手处:出问题的那一行是哪个工具的哪个模型写的,只能从这里看。
- 每个提交须有合规的智能体署名。人类共同作者使用「姓名 <邮箱>」,可以与智能体并列;
- 智能体的模型、工具登记和厂商地址仍逐条检查。
+ 署名是事后追责的入手处:出问题的那一行是哪个工具的哪个模型写的,只能从这里看。
+ 作者是本机提交者的提交,是本机智能体路径的产出,须有合规的智能体署名;人类共同
+ 作者使用「姓名 <邮箱>」,可以与智能体并列。作者是别人的提交(采纳的社区补丁)
+ 不要求智能体署名,自带的署名只核形态与已登记工具的厂商地址。
判据落在每个提交上,不是落在分支尖端:一次交付常常是好几个提交,只看最后一个
等于只要收尾那次签对了,前面写代码的几次签成谁都放行——而要追的恰恰是写出那
一行的提交。合进来的 merge 不算分支自己的产出,跳过。
"""
+ local_mail = committer_mail(repo)
found_problems = []
- for commit, label in commits(repo, base, head):
- found_problems += problems(label, values(repo, commit))
+ for commit, label, author_mail in commits(repo, base, head):
+ found_problems += problems(label, values(repo, commit), own=is_own(author_mail, local_mail))
return found_problems
diff --git a/tests/test_agent_worktree.py b/tests/test_agent_worktree.py
index 37744cf05..6bddb6230 100644
--- a/tests/test_agent_worktree.py
+++ b/tests/test_agent_worktree.py
@@ -781,7 +781,7 @@ class ReadmeImpactTests(unittest.TestCase):
key.assert_not_called()
-from scripts import co_author
+from scripts import check_commit_message, co_author
class CoAuthorTests(unittest.TestCase):
@@ -837,6 +837,39 @@ class CoAuthorTests(unittest.TestCase):
def test_human_coauthor_requires_an_agent_signature(self):
self.assertTrue(self.signed("Co-Authored-By: Contributor <[email protected]>"))
+ def contributed(self, *trailers):
+ """采纳的社区补丁:作者是贡献者本人,不是本机提交者。"""
+ git(self.repo, "commit", "--allow-empty", "-m", "测试", "-m", "\n".join(trailers) or "说明",
+ "--author", "Contributor <[email protected]>")
+ return co_author.check(self.repo, "master")
+
+ def test_a_contributor_commit_is_not_given_an_agent_signature_it_never_had(self):
+ """外部贡献者是否用了 AI 由本人说明;门槛不能逼维护者替他补一行 AI 署名。"""
+ self.assertEqual(self.contributed(), [])
+
+ def test_a_contributor_may_name_a_tool_the_maintainer_has_not_registered(self):
+ """工具名单约束的是本机智能体,贡献者用什么工具是他自己的事。"""
+ self.assertEqual(self.contributed("Co-Authored-By: Qoder (Qwen 3) <[email protected]>"), [])
+
+ def test_a_contributor_signature_still_has_to_be_well_formed(self):
+ self.assertTrue(self.contributed("Co-Authored-By: Codex (GPT-6) <[email protected]>"))
+ self.assertTrue(co_author.problems("测试", ["Codex <[email protected]>"], own=False))
+
+ def test_the_local_committer_signs_even_beside_an_adopted_commit(self):
+ self.contributed()
+ self.assertEqual(len(self.signed()), 1)
+
+ def test_an_unknown_local_identity_is_treated_as_the_local_committer(self):
+ """取不到本机邮箱时无法判断作者是谁,按本机提交从严检查。"""
+ self.assertTrue(co_author.is_own("[email protected]", ""))
+ self.assertFalse(co_author.is_own("[email protected]", "[email protected]"))
+ self.assertTrue(co_author.is_own("[email protected]", "[email protected]"))
+
+ def test_the_commit_hook_reads_the_author_actually_used(self):
+ self.assertEqual(check_commit_message.author_mail(self.repo), "[email protected]")
+ self.assertEqual(check_commit_message.check(self.repo, "测试\n", own=False), [])
+ self.assertTrue(check_commit_message.check(self.repo, "测试\n", own=True))
+
def test_human_coauthor_requires_a_name_and_email(self):
agent = "Co-Authored-By: Codex (GPT-6) <[email protected]>"
for human in ("Contributor", "Contributor <invalid>", "<[email protected]>"):