When agents invent APIs — make grep-first a merge gate
说明与用途
代理经常在未检查代码库的情况下发明新的公共 API。实施 grep-first 合并门槛迫使它们搜索现有符号、引用命中,并在未获批准的情况下阻止新共享导出,从而减少错误并加速审查。
问题
Agents often create new shared APIs or duplicate existing ones without checking the repository, leading to unnecessary code churn and review overhead.
结果
Implementing a grep-first merge gate reduced the number of PRs with invented APIs, improved code quality, and streamlined the review process.
工作流
- 1. Agent searches the repo for the intended symbol using rg or IDE search.
- 2. Agent cites at least one real file path and a one-line snippet proving existence.
- 3. If no match, agent stops and lists alternatives (reuse nearby pattern, extend existing module, or request human approval).
- 4. PR is rejected if it introduces new exports under shared/lib/hooks/api directories without a REVIEW_OK comment.
- 5. Reviewers enforce checklist: grepped imports, no new shared files, no parallel hooks, private helpers unexported, CI/bot checks for new exports.
证据
I keep catching agent PRs that call helpers that do not exist.
The fix that stuck for me is boring: grep-first as a merge gate.
In the prompt (and later in CI), I require: Search before invent – rg / IDE search for the intended symbol, path, or behavior.
Prompts alone drift. I also fail the PR when the diff introduces new exports under shared folders without a checklist comment.
- 记录日期: 2026-11-02T12:14:14.988Z