Living AGENTS.md & Repeatable Guardrails (agents-md)
Core principle:
Give AI explicit rules and deterministic checks, not vague wishlists. AI works best with concrete constraints and repeatable checks (scripts, checklists, schemas, tests). Prose rules can be forgotten; automated checks cannot. Over time,
AGENTS.mdshould get shorter and sharper while repeatable checks do more of the enforcement.
Language Rule: Respond in the user's language, and write/edit the project's AGENTS.md in the language used by that project (or requested by the user).
Auto-Detect Three Modes
Infer the right mode from the user's request and project folder state:
- Mode 1 — Bootstrap (Create or Overhaul): The folder has no
AGENTS.md, or the user asks to write/restructure one. - Mode 2 — Capture a Lesson (Mistake → Rule or Check): AI made a mistake and was corrected, or surfaced a non-obvious high-cost convention ("turn that mistake into a rule in
AGENTS.md"). - Mode 3 — Prune & Graduate (Periodic Audit): Run periodically (e.g., monthly or after a major reorganization) or when
AGENTS.mdfeels bloated/stale, to verify rules against current files/workflows and convert prose into repeatable checks.
Mode 1: Bootstrap (AGENTS.md Creation / Overhaul)
- Inspect the actual project folder first (never invent generic filler):
- Folder structure, canonical source files, output/archive directories, and naming conventions.
- Recurring workflows, scripts, templates, build/test commands, or CI checks (if present).
- High-cost boundaries where AI previously slipped or where silently overwriting/misplacing files hurts.
- Draft only high-signal sections (target under 150 lines total):
- Workspace Map & Recurring Workflows: Where key inputs/outputs live, naming conventions, and exact commands/steps for repeatable tasks.
- Hard Rules & Non-Obvious Red Lines: Forbidden actions, source-of-truth boundaries, and verification rules that aren't obvious from opening one file (e.g., "Never invent unverified numbers; mark missing evidence as TBD", "Always export reports to
outputs/without alteringraw/"). - Repeatable Checks & Templates: Existing checklists, templates, scripts, or linters—plus concrete proposals for any prose rule that can be checked automatically instead.
- Maintaining This Document: Embed the 6-rule charter below.
- Confirm before writing: Present the complete draft (and any suggested script/checklist additions) for explicit user approval before creating or overwriting
AGENTS.md.
Mode 2: Capture a Lesson (5-Gate Filter)
When turning a mistake or hidden convention into a rule, pass the candidate through all five gates before editing:
- Long-term value only: Reject one-off incidents, general common sense, and facts immediately obvious from looking at the folder or files.
- Automate or template first: Ask "Can a quick validation script, linter, schema, template, or pre-flight checklist catch this automatically?" If yes, propose creating that check and keep only a single-line summary plus the path to that check in
AGENTS.md. - Dedupe & resolve conflicts: Read the existing
AGENTS.mdfirst. Merge, tighten, or replace overlapping or conflicting rules rather than appending. - 150-line budget: Check the current line count. If adding the rule would push
AGENTS.mdpast 150 lines, propose specific low-value or stale entries to delete or merge in the same diff. - Confirm before writing (Hard Guardrail): Show the exact proposed diff and wait for user approval—never modify
AGENTS.mdsilently. Double-check that the rule does not over-generalize from an accidental mistake (e.g., banning edits to an entire folder or file just because one edit misfired).
Mode 3: Prune & Graduate (Periodic Audit)
- Cross-check every line against reality: Read the entire
AGENTS.mdalongside the current folder layout, workflow docs/scripts, and referenced paths. - Classify every existing rule into one of four actions:
- Keep: Still true, non-obvious, costly to violate, and not yet automated.
- Delete: Obsolete, contradicted by current files/workflows, one-off, or self-evident.
- Merge / Tighten: Overlapping entries that can be collapsed into a sharper single line.
- Graduate to Repeatable Check: Rules that can now be enforced by a script, checklist, linter, or test—propose the concrete check and shrink the
AGENTS.mdentry to one line + pointer path.
- Present audit + diff: Show a compact summary table of proposed changes and the exact diff (confirming the result stays under 150 lines), then wait for user confirmation before writing.
Canonical Maintenance Charter (Embed in AGENTS.md)
When bootstrapping an AGENTS.md (or adding self-governance to an existing one), include these 6 rules under ## Maintaining This Document (translated into the target AGENTS.md's language):
- When you make a mistake and get corrected, or uncover a convention that isn't obvious from the files but is costly to violate, propose adding a rule to this document.
- Show the proposed addition or edit first and wait for user confirmation before writing—never modify this document silently.
- Record only rules with long-term value; omit one-off issues, general common sense, and anything obvious from reading the files.
- Check for duplicates or conflicts before adding; merge or replace existing entries instead of appending.
- If a rule can be enforced via a script, checklist, lint, or test, prefer proposing an automated check and keep only a single-line summary plus the path to that check here.
- Keep this document under 150 lines; when exceeding the limit, propose removing or merging the least important entries.
Anti-Pattern Guardrails
- Never silently edit
AGENTS.md: User confirmation protects against bad rules generalized from accidental mistakes. - Never turn
AGENTS.mdinto an append-only log or tutorial: If it grows without pruning, signal drowns in noise. - Guard against knee-jerk bans: Distinguish "route X through Y / verify Z before saving" from "never touch folder/module X".