Analyze code changes on the current branch and recommend updates to AGENTS.md files that have become stale. Use this skill before creating a PR, when the user a
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-agents-md-sync-f8d5ac558588 ,按照其中的说明把「agents-md-sync」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
Detect when code changes make durable AGENTS.md guidance stale and produce a report with specific recommendations. Treat AGENTS.md files as operating manuals for future agents, not changelogs for recent diffs.
Figure out what changed relative to the base branch. The approach depends on context:
git diff main...HEAD --name-status
git diff main...HEAD
gh pr diff <number>
Each AGENTS.md file "owns" the directory it lives in and all subdirectories (unless a child directory has its own AGENTS.md). Build a list of which AGENTS.md files are relevant by walking up from each changed file to find the nearest AGENTS.md.
Example: a change to src/prefect/server/api/flows.py is owned by src/prefect/server/AGENTS.md (if it exists), otherwise src/prefect/AGENTS.md.
Only analyze AGENTS.md files that have at least one changed file in their territory. Also include parent AGENTS.md files if structural changes (new directories, moved files) affect the directory tree they document.
Before analyzing existing AGENTS.md files, check whether any changed directories should have their own AGENTS.md but don't. New AGENTS.md files should be rare. Recommend one only when the directory has both:
Look at the directories containing changed files. For each one that lacks an AGENTS.md, check:
Directory size and sibling AGENTS.md files can be weak signals, but they are never sufficient on their own. Do not recommend a new AGENTS.md just because a directory has 5+ files, gained a new module, or has sibling directories with AGENTS.md files.
When the case is not high-confidence, do not create the file. Capture the possible update as a recommendation instead, with the missing evidence or question that would make it actionable.
When recommending a new AGENTS.md, use the Explore agent to read the directory's code and draft the file using this template:
# <Module Name>
<One-sentence purpose statement.>
## Purpose & Scope
What this module does. Explicit responsibility boundaries.
What it does NOT do (prevents scope creep).
## Entry Points & Contracts
Key APIs, functions, classes that external consumers use.
Input/output contracts. Invariants that must hold.
## Usage Patterns
Canonical examples of correct usage.
"If you need to do X, here's how."
## Anti-Patterns
What NOT to do. Common mistakes. Each should be a real mistake, not hypothetical.
## Pitfalls
Non-obvious gotchas. Implicit assumptions.
"You'd think X, but actually Y because Z."
The initial content must be concise and durable. Do not include [ASK] placeholders, file lists, changelog context, or speculative guidance. If the hidden knowledge cannot be stated confidently, write a recommendation instead of creating the file.
AGENTS.md files form a hierarchy — when an agent loads any file, all ancestor files load too, creating a T-shaped view (broad context at the top, specific detail where the agent works). This has two implications for the sync check:
Least common ancestor rule: Shared knowledge should live at the shallowest AGENTS.md that covers all paths needing it. If the same fact appears in multiple sibling AGENTS.md files, flag it — it should move to their parent. Conversely, if a parent AGENTS.md contains detail that only applies to one child directory, suggest moving it down.
Upward propagation: When a child AGENTS.md changes (or a new one is created), check whether the parent needs updating — either to add a cross-reference to the new child, or to re-summarize what the child directory does. Parent nodes should summarize their children's responsibilities, not duplicate their details.
For each AGENTS.md in scope, read it fully, then compare its claims against the diff and the current source code. Look for these categories of issues:
Accuracy — claims in AGENTS.md that don't match the actual code, regardless of whether the diff caused the discrepancy:
For claims that are verifiable (specific behaviors, function signatures, which module does what), read the source file and confirm. Don't trust that existing AGENTS.md content was ever correct — it may have been wrong from the start.
Signal density — content that duplicates what's discoverable from code rather than surfacing hidden knowledge:
ls would show — the layering concept or architectural invariant matters, not the enumerationAGENTS.md should capture what's not visible in the code: invariants, hidden contracts, non-obvious failure modes, things that look one way but behave another.
A behavior discovered in one changed function is not AGENTS-worthy by default. Promote it only if it exposes a subsystem-level editing rule, a cross-file contract, or a recurring failure mode future agents need before choosing which implementation to read. Otherwise prefer a code comment, docstring, test name, or no documentation change.
If the same guidance is already present in nearby code comments, docstrings, or tests, AGENTS.md should usually not repeat it.
Missing invariants — implicit contracts the code relies on that aren't documented:
Structural drift — the AGENTS.md describes an ownership boundary, durable package layout, or module responsibility that no longer matches reality:
Command drift — documented commands that may no longer work or are incomplete:
Convention drift — code patterns or conventions described in AGENTS.md that the diff contradicts:
Description drift — prose descriptions that no longer accurately characterize the code:
Hierarchy drift — content living at the wrong level in the AGENTS.md tree:
For each finding, check whether it's actually stale — read the current state of the filesystem (not just the diff) to confirm. A diff showing a new file, helper, flag, or one-off fix doesn't mean AGENTS.md is wrong if AGENTS.md intentionally omits that level of detail.
Only recommend or apply updates for high-confidence, lasting guidance:
Do not document:
Output a concise report grouped by AGENTS.md file. For each file, list findings with:
Format:
## AGENTS.md Sync Report
### New AGENTS.md recommended: `src/prefect/utilities/`
This directory now owns a distinct retry protocol used by multiple callers, and contributors must preserve its ordering invariant. Suggested outline:
- Purpose and ownership boundary
- Ordering invariant that callers rely on
- Failure mode to test when changing it
### `src/prefect/server/AGENTS.md`
1. **[Accuracy]** Lease renewal described as "renews at 75% of duration" but code renews immediately then sleeps 75%
- Caused by: incorrect from initial creation
- Suggested fix: "renews immediately on entry, then sleeps for 75% of `lease_duration` between renewals"
2. **[Signal density]** Full function signatures duplicate the code — remove parameter lists, keep contracts
- Suggested fix: Replace `concurrency(names, occupy=1, ...)` with `concurrency()` and describe the non-obvious behaviors instead
3. **[Missing invariant]** Sync and async implementations must stay in lockstep but this isn't documented
- Suggested fix: Add "Any behavior change to `_asyncio.py` must be mirrored in `_sync.py`"
4. **[Structural]** New directory `src/prefect/server/events/` not listed in directory structure
- Caused by: `src/prefect/server/events/` added in this branch
- Suggested fix: Add `events/` to the directory listing with description
### `./AGENTS.md` (root)
No changes needed.
If nothing is stale, say so clearly — don't manufacture findings.
After presenting the report, offer:
Outside of diff-driven analysis, if during normal development you discover missing context that should be in an AGENTS.md, propose an addition. Signs of missing context:
Propose additions like this:
I discovered that [finding]. This isn't in [path]/AGENTS.md.
Proposed addition to the [section] section:
> [concrete text to add]
Should I add this?
require_* call".