Skip to content

Commit 67f0507

Browse files
authored
docs: strengthen AGENTS.md to reduce recurring agent error patterns (GH#948)
Addresses 4 recurring tool failure modes from issue #948: Quick Session Checklist, expanded do-not-exist table, anti-pattern examples, and expanded webfetch prohibited list. Resolves #948
1 parent 8287501 commit 67f0507

1 file changed

Lines changed: 41 additions & 2 deletions

File tree

AGENTS.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,24 @@ wp db reset --yes && cd ../wordpress && ./reset.sh # full DB + WordPress reset
186186

187187
Recurring error patterns observed in this codebase. Review before starting any session.
188188

189+
### Quick Session Checklist (top 4 recurring failures)
190+
191+
**Before writing a single line of code, verify these four things:**
192+
193+
1. **No webfetch** — never construct or guess a URL. WordPress docs, Stripe/PayPal API docs,
194+
GitHub URLs, PHP manual, npm package docs: all fail. Read the codebase instead (see
195+
[No External URL Fetching](#no-external-url-fetching)).
196+
2. **Verify paths exist before reading** — run `git ls-files '<path>'` first. An empty result
197+
means the file does not exist; do not attempt to read it (see table below).
198+
3. **Read immediately before every edit** — the Edit tool requires a Read call earlier in the
199+
same conversation turn on that exact file. `Read(A) → Edit(A)` is correct. `Read(A) →
200+
Read(B) → Edit(A)` fails if A's content changed, and will always fail on session restart.
201+
Never read multiple files upfront and edit them later.
202+
4. **Check tool prerequisites** — before any lint, test, or analysis command, confirm:
203+
- `ls vendor/autoload.php 2>/dev/null || echo "run: composer install"`
204+
- `ls node_modules/.bin/eslint 2>/dev/null || echo "run: npm install"`
205+
- `ls /tmp/wordpress-tests-lib/includes/bootstrap.php 2>/dev/null || echo "run: bin/install-wp-tests.sh"`
206+
189207
### File Discovery — `.dist` Config Convention
190208

191209
Config files are committed as `.dist` versions; un-suffixed copies are gitignored and may not exist locally:
@@ -229,6 +247,10 @@ read them will produce `read:file_not_found`:
229247
| `lib/` | Does not exist; use `inc/` for PHP code, `assets/` for frontend |
230248
| `languages/` | Does not exist; i18n files are in `lang/` |
231249
| `.env`, `.env.example` | Does not exist; no local env config stored in this repo |
250+
| `inc/functions.php` | Does not exist as a single file; functions live in `inc/functions/*.php` |
251+
| `inc/admin.php` | Does not exist; admin pages live in `inc/admin-pages/` and `inc/admin/` |
252+
| `SECURITY.md` | Does not exist in this repo |
253+
| `coverage-html/**`, `coverage.xml` | Generated by test:coverage run, gitignored, may be absent |
232254

233255
Always verify a file is tracked before reading it with `git ls-files '<path>'`. An empty result means the file does not exist in the repo.
234256

@@ -240,8 +262,8 @@ guessing a docs URL from a package name) account for the majority of `webfetch:o
240262
in this codebase.
241263

242264
Do **not** use webfetch for WordPress documentation, PHP manual pages, Stripe/PayPal API docs,
243-
BerlinDB documentation, npm package docs, or any other developer documentation URLs — these
244-
requests consistently fail.
265+
BerlinDB documentation, WooCommerce docs, npm package docs, WP Plugin Handbook, or any other
266+
developer documentation URLs — these requests consistently fail.
245267

246268
Do **not** use webfetch for GitHub URLs (issues, PRs, raw content, commits). Use the `gh` CLI
247269
instead:
@@ -276,6 +298,23 @@ Do **not** read all files at session start and edit them later. The pattern `Rea
276298

277299
When working on multiple files in the same session: read each file immediately before editing it, not at the start of the session. Reading file A, then file B, then editing file A will fail if A's content changed between your read and your edit.
278300

301+
**Anti-pattern (causes `edit:not_read_first` failure):**
302+
303+
```
304+
Read(inc/models/class-membership.php)
305+
Read(inc/managers/class-membership-manager.php) ← reading a second file resets the "last read" state
306+
Edit(inc/models/class-membership.php) ← FAILS: file not read in this turn
307+
```
308+
309+
**Correct pattern:**
310+
311+
```
312+
Read(inc/models/class-membership.php)
313+
Edit(inc/models/class-membership.php) ← immediate edit after read
314+
Read(inc/managers/class-membership-manager.php)
315+
Edit(inc/managers/class-membership-manager.php) ← immediate edit after read
316+
```
317+
279318
### WP-CLI and Bash Prerequisites
280319

281320
`wp` commands require the dev WordPress install at `../wordpress`. Check it exists before running:

0 commit comments

Comments
 (0)