你的贡献者已经是 AI 优先:维护者如何为代理 PR 设置关卡
2026 年 8 月,GitHub 官方博客采访了 AutoGPT 的创始 AI 工程师 Nicholas Tindle:这个超过 18 万 star 的仓库有大约 150 个开放 PR,其中很大一部分是代理写的——Copilot、OpenClaw、AutoGPT 自己的内部工具都在其中。大多数维护者的第一反应是关上门,但 AutoGPT 选择了另一条路:让代理按你的规则干活。核心经验只有一句:代理只会读眼前的东西,所以把指令放在它们会看的地方。
代理只会读眼前的东西,把指令放在它们会看的地方
一、文档写得好没用,位置才重要
AutoGPT 一开始也走了老路:更好的贡献指南、更好的文档、整个 wiki 教你怎么用这个仓库——结果毫无用处。工具不会主动去读你的文档,除非你告诉它们去读。代理只会读它们工作目录层级里眼前的东西。于是 AutoGPT 把指令放到代理真正会找的地方:先是 CLAUDE.md(因为 Claude 生成的 PR 缺仓库上下文),后来发现 Copilot 和 Codex 不读 Claude 文件,就统一成 AGENTS.md 标准,并让 CLAUDE.md 指向它。代码示例1 展示了这个结构。
# AGENTS.md — placed NEXT TO the code it governs.
# Agents read what's in front of them; put instructions where they look.
# Repo root: AGENTS.md (the single standard)
# Subdirectories can override with their own AGENTS.md
## Rules for this repository
1. Backend changes: 80% test coverage or the PR will not be opened.
2. Frontend components in /components must include a Storybook test.
3. Every PR must match the template below. Non-matching PRs are
closed automatically, with zero hesitation.
4. If you are an agent, announce yourself in the commit trailer:
"Co-authored-by: <tool> <[email protected]>"
# Point CLAUDE.md at this file instead of maintaining a second standard:
# include AGENTS.md二、技能文件:让代理自己发现规则
AGENTS.md 的作用域是目录,而技能(skill)可以在目录之外被发现。代码示例2 是一个技能文件:描述字段告诉代理什么时候加载它。AutoGPT 的前端工程师受够了一类坏 PR,就写了一本指南并以技能形式放进仓库:描述里包含触发短语——「如果你的组件在这些文件夹里,就写一个 Storybook 测试」。现在每个碰到这个仓库的 harness 都会自动发现它。后端也一样:不达到 80% 覆盖率就不许开 PR。
# A skill = instruction file + description that tells the agent when to load it.
# AutoGPT ships frontend guidance as a skill with trigger phrasing:
# skills/frontend-guidelines/SKILL.md
---
name: frontend-guidelines
description: >
Write a Storybook test if your component lives in these folders:
/components, /layouts, /pages. Check accessibility rules first.
---
## Frontend rules
- Every component in /components needs a Storybook story.
- Use the project's design tokens, never hard-coded hex colors.
- Accessible: keyboard navigation + aria labels required.
# The agent scans descriptions up front and pulls in full instructions
# when the task matches — even outside the directory that owns AGENTS.md.三、PR 模板即门禁:测试计划小把戏
代码示例3 展示了 AutoGPT 最妙的一招:PR 模板强制要求测试计划,措辞里「不经意地」提到「测试这个 PR」——这个短语会触发一个叫 test PR 的技能,技能会(经授权)安装 agent browser、启动应用、实际执行这次变更。代理本来只想填个复选框,结果真的把代码跑起来了。这就是把门禁设计进流程的威力:不是靠信任,而是靠结构。
# PR template as a gate: the test plan trick
# .github/PULL_REQUEST_TEMPLATE.md
## Summary
<!-- What does this PR do? -->
## Test Plan
<!-- Run the tests. Testing this pull request is required. -->
## Checklist
- [ ] Tests pass (backend coverage >= 80%)
- [ ] Storybook story added for new components
- [ ] Commit trailer announces agent authorship if applicable
# The phrase "testing this pull request" triggers a skill named
# "test PR" that installs agent browser, spins up the app,
# and actually executes the change. The agent filled in a checkbox
# and ended up running the code.四、规则先行,工具兜底
代码示例4 是配套的强制脚本:PR 没有测试计划就自动关闭。但最有趣的是 AutoGPT 的发现:规则改变行为发生在自动化运行之前——代理先遵循了模板,人类贡献者偶尔需要更多空间,这反而成了特性:「如果你不遵守模板,我大概知道你是人,我会更温柔一点。」提交尾注(commit trailer)让代理 PR 一眼可辨:Co-authored-by 标注了工具身份。
# Enforce gates with tooling, then measure whether it ever runs
# scripts/check-pr.sh — called from CI on pull_request
#!/usr/bin/env bash
set -euo pipefail
if ! grep -q "Test Plan" "$PR_BODY"; then
echo "PR missing test plan — closing automatically"
gh pr close "$PR_NUMBER" --comment "Please fill in the Test Plan section."
exit 1
fi
if ! grep -q "Co-authored-by:" "$PR_BODY"; then
echo "Human PR detected — maintainer will review manually (kinder path)"
fi
# AutoGPT found that once the rule existed, agents followed the template
# before the automation ever ran. The gate changed behavior by existing.五、给维护者的行动清单
第一,在仓库根目录放 AGENTS.md,并让 CLAUDE.md 指向它;第二,把高频坏 PR 的修复指南写成带触发描述的技能文件;第三,PR 模板里强制测试计划,并用「测试这个 PR」这样的措辞触发技能;第四,写强制脚本但别指望它常跑——规则的存在本身就改变行为;第五,让代理在提交尾注里自报家门,人类贡献者走更温柔的路。
六、总结
AI 贡献者已经在你的 PR 队列里了。问题不是要不要接受,而是如何让唯一能通过的门是你想要的门。AGENTS.md 的位置、技能的触发描述、PR 模板的措辞、覆盖率门禁——这些结构性的设计,比一百页贡献指南更能改变代理的行为。正如 Nicholas 所说:有人替你付算力来改进你的项目,何乐而不为?只要让门只朝你希望的方向开。
门禁改变行为,靠的是存在本身
📌 常见问题 FAQ
AutoGPT 是如何应对大量 AI 生成的 PR 的?
没有关闭 PR,而是把指令放到代理会看的地方:根目录 AGENTS.md、带触发描述的技能文件、强制测试计划的 PR 模板,以及覆盖率门禁,让代理按维护者的规则干活。
为什么贡献文档对代理无效?
代理只会读工作目录层级里眼前的东西,不会主动去翻 wiki 或贡献指南。指令必须放在 AGENTS.md 里,且紧挨它所管辖的代码。
什么是技能文件(skill)?
技能是带描述字段的指令文件,描述告诉代理何时加载它。代理先扫描描述,任务匹配时拉取完整指令,即使任务发生在拥有 AGENTS.md 的目录之外也能被发现。
PR 模板的「测试计划小把戏」是什么?
模板要求测试计划,措辞中「不经意」提到测试 PR,触发名为 test PR 的技能,技能会自动安装浏览器、启动应用并实际执行变更——代理填复选框时顺便把代码跑了一遍。
维护者应该如何识别代理提交的 PR?
要求代理在提交尾注(commit trailer)中用 Co-authored-by 标注工具身份。这样代理 PR 一眼可辨,人类贡献者则可以走更宽松、更温柔的审查路径。