|
| 1 | +--- |
| 2 | +id: course-agent-rules |
| 3 | +type: course |
| 4 | +title: One source of truth for agent rules |
| 5 | +summary: Stop maintaining diverging AGENTS.md, CLAUDE.md, and .cursorrules files — build a checker that proves your repository has exactly one rule source, taught hands-on with your coding agent. |
| 6 | +lang: en-US |
| 7 | +content_version: 1 |
| 8 | +status: reviewed |
| 9 | +reviewed_on: 2026-09-12 |
| 10 | +--- |
| 11 | + |
| 12 | +# One source of truth for agent rules |
| 13 | + |
| 14 | +> TL;DR: download this folder, open it in your coding agent, and say |
| 15 | +> **"start lesson 1"**. You finish with a working rule-consistency checker |
| 16 | +> (`rules_check.py`) that fails CI the moment a rule file drifts from |
| 17 | +> AGENTS.md — plus the single-source setup applied to your own repository. |
| 18 | +> Tool-agnostic by design: Claude Code, Codex CLI, and Cursor all read these |
| 19 | +> files. |
| 20 | +
|
| 21 | +## What you build |
| 22 | + |
| 23 | +A standard-library-only checker that enforces the contract used by this very |
| 24 | +repository: `AGENTS.md` must exist and be non-empty, and every other |
| 25 | +recognized rule file (`CLAUDE.md`, `.cursorrules`) must either be a thin |
| 26 | +pointer that defers to it or an exact copy of it. Anything else is drift, |
| 27 | +reported with a reason and a failing exit code. Three scenario repositories |
| 28 | +ship with the course: |
| 29 | + |
| 30 | +| Skin | State | Data | |
| 31 | +| --- | --- | --- | |
| 32 | +| `scenario/thin-pointer/` | healthy: AGENTS.md + two pointer files | pointer-style CLAUDE.md, .cursorrules | |
| 33 | +| `scenario/single-copy/` | healthy: AGENTS.md + exact copy | duplicated rule text | |
| 34 | +| `scenario/drifted/` | broken: .cursorrules restates stale rules | a real drift to catch | |
| 35 | + |
| 36 | +## Teaching contract (read this first, agent) |
| 37 | + |
| 38 | +- **Audience:** anyone maintaining rule files for more than one agent tool — |
| 39 | + you have felt the pain of three files disagreeing about one behavior. |
| 40 | +- **Prerequisites:** Python 3.11+ on PATH and any coding agent (taught and |
| 41 | + reviewed with Claude Code 2.x and Codex CLI 0.x; reviewed 2026-09-12 — |
| 42 | + tool-agnostic by design). Standard library only. |
| 43 | +- **Lesson order:** L01 → L05; never skip the checkpoint. |
| 44 | +- **Teaching style:** work from the files in this folder; quote the contract |
| 45 | + line you satisfy; smallest change per failing test; no new dependencies; |
| 46 | + never edit `solution/`; ask before touching unnamed files. |
| 47 | +- **When to stop:** a lesson is done when its checkpoint command runs and the |
| 48 | + learner can explain what failed and why. |
| 49 | +- **`verify.py`:** `python verify.py starter --expect-failure` reproduces the |
| 50 | + six listed failures; `python verify.py solution` passes 11/11. |
| 51 | +- **Honesty rules:** say what you did not verify; no guarantees about agent |
| 52 | + obedience — the checker reports file state, not agent behavior. |
| 53 | + |
| 54 | +## What this course does NOT cover |
| 55 | + |
| 56 | +Which rules to write (see the repository's `templates/AGENT_RULES.example.md` |
| 57 | +and the AGENTS.md guide on flypython.com), multi-repo setups, or |
| 58 | +machine-policy enforcement. The checker is deliberately narrow: one |
| 59 | +directory, three file names, one truth. |
| 60 | + |
| 61 | +## Folder map |
| 62 | + |
| 63 | +`COURSE.md`/`COURSE_cn.md`, bilingual `lessons/`, `scenario/` repositories, |
| 64 | +`TASK.md`/`TASK_cn.md` (the code contract), `starter/`, `solution/`, `tests/` |
| 65 | +(11 tests), `verify.py`, `REVIEW.md`. |
| 66 | + |
| 67 | +## Evidence and licensing |
| 68 | + |
| 69 | +`REVIEW.md` records the run-through state. Code is MIT; prose is CC BY 4.0 |
| 70 | +(see repository `LICENSE`). Teaching drift goes to the `course-feedback` |
| 71 | +issue form. |
0 commit comments