|
| 1 | +# Ruff AI Agent Field Notes & Gotchas System |
| 2 | + |
| 3 | +This document defines a **mandatory post-work note-taking system** for AI agents working on the Ruff programming language. The goal is to capture *hands-on, experience-based knowledge* so future agents build faster, avoid mistakes, and develop correct mental models of the codebase. |
| 4 | + |
| 5 | +This is not documentation. |
| 6 | +This is **operational memory**. |
| 7 | + |
| 8 | +--- |
| 9 | + |
| 10 | +## 🎯 Purpose |
| 11 | + |
| 12 | +After implementing features, fixing bugs, refactoring, or debugging Ruff, the AI agent must distill what it learned into structured Markdown notes. |
| 13 | + |
| 14 | +These notes should capture: |
| 15 | + |
| 16 | +* surprising behavior |
| 17 | +* incorrect assumptions |
| 18 | +* fragile areas of the code |
| 19 | +* ordering constraints |
| 20 | +* edge cases |
| 21 | +* rules the code implicitly relies on |
| 22 | + |
| 23 | +Future agents should be able to read these notes and *immediately* avoid repeated mistakes. |
| 24 | + |
| 25 | +--- |
| 26 | + |
| 27 | +## 📁 Folder Structure |
| 28 | + |
| 29 | +``` |
| 30 | +./notes/ |
| 31 | +├── YYYY-MM-DD_HH-mm_short-kebab-summary.md |
| 32 | +├── YYYY-MM-DD_HH-mm_another-session.md |
| 33 | +├── GOTCHAS.md |
| 34 | +└── README.md (optional index) |
| 35 | +``` |
| 36 | + |
| 37 | +* One notes file per work session |
| 38 | +* Notes are append-only (never overwrite or rename old files) |
| 39 | + |
| 40 | +--- |
| 41 | + |
| 42 | +## 🧾 Session Notes File Rules |
| 43 | + |
| 44 | +### Filename format (required) |
| 45 | + |
| 46 | +``` |
| 47 | +YYYY-MM-DD_HH-mm_short-kebab-summary.md |
| 48 | +``` |
| 49 | + |
| 50 | +Examples: |
| 51 | + |
| 52 | +* `2026-01-25_10-14_parser-gotchas.md` |
| 53 | +* `2026-01-25_18-02_vm-scope-fix.md` |
| 54 | + |
| 55 | +If `./notes/` does not exist, create it. |
| 56 | + |
| 57 | +--- |
| 58 | + |
| 59 | +## 🧠 When Notes Must Be Written |
| 60 | + |
| 61 | +Create or update a session notes file after: |
| 62 | + |
| 63 | +* adding a feature |
| 64 | +* fixing a bug |
| 65 | +* debugging a test failure |
| 66 | +* changing parser / lexer / AST / evaluator / runtime behavior |
| 67 | +* modifying CLI behavior |
| 68 | +* discovering surprising or non-obvious behavior |
| 69 | +* correcting an incorrect assumption |
| 70 | + |
| 71 | +**One work session = one notes file** |
| 72 | + |
| 73 | +--- |
| 74 | + |
| 75 | +## 🧱 Required Session Notes Template |
| 76 | + |
| 77 | +Each session notes file **must use this exact structure**: |
| 78 | + |
| 79 | +```md |
| 80 | +# Ruff Field Notes — <short human title> |
| 81 | + |
| 82 | +**Date:** <YYYY-MM-DD> |
| 83 | +**Session:** <HH:mm local> |
| 84 | +**Branch/Commit:** <branch name> / <commit hash (if known)> |
| 85 | +**Scope:** <1–2 sentences describing what you worked on> |
| 86 | + |
| 87 | +--- |
| 88 | + |
| 89 | +## What I Changed |
| 90 | +- <bullet list of concrete changes> |
| 91 | +- <include file paths when helpful> |
| 92 | + |
| 93 | +## Gotchas (Read This Next Time) |
| 94 | +- **Gotcha:** <what surprised you> |
| 95 | + - **Symptom:** <what you observed> |
| 96 | + - **Root cause:** <why it happened> |
| 97 | + - **Fix:** <what resolved it> |
| 98 | + - **Prevention:** <how to avoid it next time> |
| 99 | + |
| 100 | +(repeat for each gotcha) |
| 101 | + |
| 102 | +## Things I Learned |
| 103 | +- <mental model updates> |
| 104 | +- <rules of thumb> |
| 105 | +- <implicit invariants or ordering constraints> |
| 106 | + |
| 107 | +## Debug Notes (Only if applicable) |
| 108 | +- **Failing test / error:** <exact error output> |
| 109 | +- **Repro steps:** <how to reproduce> |
| 110 | +- **Breakpoints / logs used:** <where you looked> |
| 111 | +- **Final diagnosis:** <what it actually was> |
| 112 | + |
| 113 | +## Follow-ups / TODO (For Future Agents) |
| 114 | +- [ ] <specific next step> |
| 115 | +- [ ] <tech debt introduced or deferred> |
| 116 | + |
| 117 | +## Links / References |
| 118 | +- Files touched: |
| 119 | + - `<path>` |
| 120 | + - `<path>` |
| 121 | +- Related docs: |
| 122 | + - `README.md` |
| 123 | + - `ROADMAP.md` |
| 124 | + - <other docs> |
| 125 | +``` |
| 126 | + |
| 127 | +--- |
| 128 | + |
| 129 | +## ✍️ Writing Style Rules (Critical) |
| 130 | + |
| 131 | +* Write like you are leaving a note to your **future self** with partial context |
| 132 | +* Be concrete, not theoretical |
| 133 | +* Include file paths, function names, enums, structs, and commands |
| 134 | +* If something *will surprise someone*, call it out explicitly |
| 135 | +* If something relies on an ordering constraint, write it as a **rule** |
| 136 | +* If unsure what to write, write *less*, but make it *specific* |
| 137 | + |
| 138 | +### 🚨 Mandatory Capture Rule: "Justified Behavior" |
| 139 | + |
| 140 | +If the agent has to **justify** why something is OK, expected, intentional, or safe, it **must be documented**. |
| 141 | + |
| 142 | +This includes moments where the agent says or implies: |
| 143 | + |
| 144 | +* "This warning is expected" |
| 145 | +* "This is intentional" |
| 146 | +* "This is safe because…" |
| 147 | +* "We can ignore this" |
| 148 | +* "It only happens in X, not Y" |
| 149 | +* "This is a known limitation" |
| 150 | +* "We’ll clean this up later" |
| 151 | + |
| 152 | +These statements compress non-obvious reasoning and **will not be obvious from the code alone**. |
| 153 | + |
| 154 | +When this happens, add an entry under **Gotchas** or **Things I Learned**. |
| 155 | + |
| 156 | +### Example (Required Documentation Pattern) |
| 157 | + |
| 158 | +```md |
| 159 | +- **Gotcha:** Compiler warning about `Spread` being unused as an `Expr` |
| 160 | + - **Symptom:** Warning emitted during compile about `Spread` enum variant |
| 161 | + - **Root cause:** `Spread` is intentionally NOT a standalone `Expr` |
| 162 | + - **Fix:** None — this is expected behavior |
| 163 | + - **Prevention:** Do not refactor `Spread` into `Expr` without redesigning |
| 164 | + array/dict element handling. `Spread` is only valid within |
| 165 | + `ArrayElement` and `DictElement`. |
| 166 | +``` |
| 167 | + |
| 168 | +### Optional (High Value): Assumptions I Almost Made |
| 169 | + |
| 170 | +If applicable, add: |
| 171 | + |
| 172 | +```md |
| 173 | +## Assumptions I Almost Made |
| 174 | +- I initially assumed `Spread` should be an `Expr`, but that breaks |
| 175 | + contextual evaluation rules |
| 176 | +``` |
| 177 | + |
| 178 | +🚫 Avoid: |
| 179 | + |
| 180 | +* generic explanations |
| 181 | +* textbook definitions |
| 182 | +* restating obvious code behavior |
| 183 | + |
| 184 | +--- |
| 185 | + |
| 186 | +## 🧠 Curated GOTCHAS.md (Deduplicated) |
| 187 | + |
| 188 | +In addition to session notes, maintain a **curated, long-lived gotchas file**: |
| 189 | + |
| 190 | +``` |
| 191 | +./notes/GOTCHAS.md |
| 192 | +``` |
| 193 | + |
| 194 | +### Purpose |
| 195 | + |
| 196 | +* High-signal summary of the most important pitfalls in Ruff |
| 197 | +* Deduplicated across sessions |
| 198 | +* Clean, readable, and short |
| 199 | +* Suitable for onboarding new agents |
| 200 | + |
| 201 | +Session notes are raw. |
| 202 | +`GOTCHAS.md` is refined. |
| 203 | + |
| 204 | +--- |
| 205 | + |
| 206 | +## 📘 GOTCHAS.md Structure |
| 207 | + |
| 208 | +```md |
| 209 | +# Ruff — Known Gotchas & Sharp Edges |
| 210 | + |
| 211 | +This document contains the most important non-obvious pitfalls in the Ruff codebase. |
| 212 | + |
| 213 | +If you are new to the project, read this first. |
| 214 | + |
| 215 | +--- |
| 216 | + |
| 217 | +## Parser & Syntax |
| 218 | + |
| 219 | +### Expression precedence is NOT inferred |
| 220 | +- **Problem:** <what breaks> |
| 221 | +- **Rule:** <explicit rule the parser expects> |
| 222 | +- **Why:** <design rationale> |
| 223 | + |
| 224 | +## Runtime / Evaluator |
| 225 | + |
| 226 | +### Variable scope is resolved at <stage> |
| 227 | +- **Problem:** <symptom> |
| 228 | +- **Rule:** <how scope resolution actually works> |
| 229 | +- **Implication:** <what not to assume> |
| 230 | + |
| 231 | +## CLI & Tooling |
| 232 | + |
| 233 | +### Tests must be run with <specific command> |
| 234 | +- **Problem:** <failure mode> |
| 235 | +- **Rule:** <correct workflow> |
| 236 | + |
| 237 | +--- |
| 238 | + |
| 239 | +## Mental Model Summary |
| 240 | + |
| 241 | +- Ruff favors <design philosophy> |
| 242 | +- The parser assumes <key assumption> |
| 243 | +- The runtime guarantees <invariant> |
| 244 | +- Do NOT assume <common incorrect assumption> |
| 245 | +``` |
| 246 | + |
| 247 | +### Rules for Updating GOTCHAS.md |
| 248 | + |
| 249 | +* Only add **confirmed, repeated, or high-impact** issues |
| 250 | +* Merge duplicates instead of appending |
| 251 | +* Prefer rules over stories |
| 252 | +* Reference session notes where the discovery came from |
| 253 | + |
| 254 | +Example: |
| 255 | + |
| 256 | +```md |
| 257 | +(Discovered during: 2026-01-25_10-14_parser-gotchas.md) |
| 258 | +``` |
| 259 | + |
| 260 | +--- |
| 261 | + |
| 262 | +## 📑 Optional: notes/README.md Index |
| 263 | + |
| 264 | +If the notes folder grows large, maintain an index: |
| 265 | + |
| 266 | +```md |
| 267 | +# Ruff Field Notes Index |
| 268 | + |
| 269 | +- 2026-01-25_10-14_parser-gotchas.md — Parser edge cases & failure modes |
| 270 | +- 2026-01-25_18-02_vm-scope-fix.md — Runtime scoping corrections |
| 271 | +``` |
| 272 | + |
| 273 | +Only add entries for **high-signal sessions**. |
| 274 | + |
| 275 | +--- |
| 276 | + |
| 277 | +## ✅ Definition of Done (Recommended) |
| 278 | + |
| 279 | +A task is **not complete** unless: |
| 280 | + |
| 281 | +* code compiles |
| 282 | +* tests pass |
| 283 | +* **session notes are written** |
| 284 | +* GOTCHAS.md is updated *if applicable* |
| 285 | + |
| 286 | +This system turns AI experience into durable project knowledge. |
0 commit comments