Add progressive-discovery pattern for agent instructions and skills - #80650
Conversation
Establish how AI-agent guidance is organized in the repository: - Root AGENTS.md becomes a lean router: a Progressive discovery section routes to contributor docs, skills, and directory guides. The testing command block moves out (code-quality commands stay); non-discoverable trap rules (PHP build prefixing, package CHANGELOG entries) move to Common pitfalls. - New top-level skills/ directory with a testing skill: thin SKILL.md (frontmatter, shared planning gate, don't-weaken-tests rule, per-type routing) plus references/ for Jest, PHP, and e2e specifics. - New docs/contributors/code/agents-and-skills.md contributor guide: improve public docs first, one home per fact, skill conventions shared with WordPress/agent-skills, and a checklist for adding skills. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
| ## Never make a failing test pass by changing the production code unless the production code is the source of a bug | ||
|
|
||
| The e2e test passing is not the final task success criteria. The core goal is to verify that the production code works as expected. | ||
|
|
There was a problem hiding this comment.
How does this help? We could test it on a couple of examples where we introduce a bug into either the code or test and see if it makes the correct decision.
I'm worried that the current wording could be misleading. Maybe something like this phrase could work better, but I haven't tested it.
There might be a good skill already available somewhere for fixing failing tests.
## Fix test failure
Before fixing a test failure, investigate the rot cause of the failure. If the test is failing due to it being outdated, update the test to match the code. If it's timing out, fix the timeout root cause, increase the timeout as a last resort.
Update the code in case the test failure was introduced by a bug in the code.
There was a problem hiding this comment.
I've had the agent try to fix a failing test by changing the core code. Trying to keep it focused on the important core task rather than immediate satisfaction of "Fixing the test." However, maybe this is not needing and the proper fix is the developer improving their prompting.
I'm unattached to this and happy to remove it. Core piece I want to accomplish is just the overall pattern.
|
|
||
| Agent-specific guidance for PHPUnit tests. They require the wp-env test environment: check `npm run wp-env-test status` first, and run `npm run wp-env-test start` only if it is not already running. | ||
|
|
||
| - **Run**: `composer test` (all PHP tests), or `vendor/bin/phpunit <path_to_test_file.php>` (specific file or directory). |
There was a problem hiding this comment.
Should we recommend npm run test:unit:php (or npm run test:php when lint is desired), because those scripts run PHPUnit inside the configured wp-env test environment
| ## Never make a failing test pass by changing the production code unless the production code is the source of a bug | ||
|
|
||
| The e2e test passing is not the final task success criteria. The core goal is to verify that the production code works as expected. |
There was a problem hiding this comment.
If we plan on doing some test-driven development, I'm afraid this section will prevent it?
There was a problem hiding this comment.
Good point. Happy to remove it. Main point for the PR is scaffolding the overall structure of agents and skills. I'd rather be more minimal (remove this line) and discuss specific agent instructions in a follow-up PR.
| @@ -0,0 +1,21 @@ | |||
| # E2e tests: agent rules and routing | |||
|
|
|||
| Agent-specific guidance for Playwright e2e tests. They require the wp-env test environment: check `npm run wp-env-test status` first, and run `npm run wp-env-test start` only if it is not already running. | |||
There was a problem hiding this comment.
I noticed we're repeating the wp-env-test across a couple of files, should we unify it under the skill.md file for applicable environments?
There was a problem hiding this comment.
I believe it's only relevant for php and e2e, so I put them in their separate files.
|
|
||
| ## Rules | ||
|
|
||
| - **Stay headless** (the default). Do not use `--headed`, `--ui`, or `--debug` — the human docs recommend them, but they open a GUI and block an agent session. |
There was a problem hiding this comment.
From the canonical e2e guide, it seems like headless mode is not supported in Linux. Maybe we can tweak the guidance here to say "use headless when supported, as per the canonical e2e testing guide"
There was a problem hiding this comment.
Sure. It doesn't need to be as assertive as it is.
…files Co-authored-by: Bero <berislav.grgicak@gmail.com>
|
Flaky tests detected in 657ee4b. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/30108411927
|
|
So far, no concerns from my end. I suspect we'll find out only by gathering evidence about how different agents do |
| - `@wordpress/build` (`packages/wp-build`) is a generic build tool used both in Gutenberg and by plugins targeting WordPress Core directly. Avoid Gutenberg-specific changes in it. | ||
| - Never invoke WordPress's forked or local CLIs through `npx` (e.g. `npx prettier`, `npx wp-scripts`). WordPress ships its own `wp-prettier` fork, and `wp-scripts` is the bin name of `@wordpress/scripts`. A bare `npx wp-scripts` can resolve to an unrelated third-party package on the public registry, not the local tool. Use the npm scripts instead (`npm run format`, `npm run lint:js`, `npm run lint:css` and so on), which run the binaries from local `node_modules`. | ||
| - PHP function and class names are renamed at build time (`gutenberg_*` prefix, `*_Gutenberg` suffix) to avoid conflicts with WordPress Core — the built names, not the source names, are what runs (and what tests must call). See `docs/contributors/code/build-system-function-prefixing.md`. | ||
| - Production code changes in a package require an entry in that package's `CHANGELOG.md`. See `docs/contributors/code/managing-packages.md`. |
There was a problem hiding this comment.
Nit: If we have a qualifier like "in a package" that refers to a specific place in the codebase, that's a good signal that it belongs in a localized AGENTS.md within the related folder, i.e. packages/AGENTS.md, so that this doesn't need to be loaded into agent context if an agent is working on files outside of packages.
(h/t @simison for his original suggestion to this in #78166 (comment))
There was a problem hiding this comment.
I'm also finding that notes about discovery from the AGENTS.md loaded at runtime is pretty much ignored by the time the agent actually performs the task. Skills seem to be more reliable for procedural tasks than AGENTS.md. I say, let's give it a try in a couple ways and see which structure the agent more reliably follows.
What?
Establishes a documented pattern for how AI-agent instructions are organized in the Gutenberg repository, and lands the first skill (testing):
AGENTS.mdbecomes a lean router with a Progressive discovery section: contributor docs, skills, and directory guides are read only when the task needs them.skills/directory:skills/testing/SKILL.mdintro point withreferences/files for Jest, PHP, and e2e specifics.docs/contributors/code/agents-and-skills.md.Why?
Agent guidance in the repo is currently ad hoc (root
AGENTS.md, one per-directory file inpackages/components/), with no documented convention for contributors. By providing a general structure, we have a way to start contributing to improve agent success in coding in Gutenberg.How?
Follows conventions from WordPress Agent Skills to progressively disclose skills to prevent context bloat and confusing agents:
AGENTS.md: env setup, code quality, pitfalls, router) / location-triggered (directoryAGENTS.md) / task-triggered (skills/) / on-demand (docs and references). Each fact has one home, at the highest level where it applies to everything below it.AGENTS.mdinto the skill's per-type references; the shared wp-env-test requirement lives once inSKILL.md. Non-discoverable trap rules (PHP build-time function prefixing, per-packageCHANGELOG.mdentries) moved to Common pitfalls.Testing Instructions
claude -p "Run the e2e tests for the paragraph block" --verbose --output-format stream-json > run.jsonl.grep -o '"file_path":"[^"]*"' run.jsonlto list every file read.skills/testing/SKILL.mdandskills/testing/references/e2e.md, and that those reads appear before the first test command.skills/testing/references/php.mdorskills/testing/references/jest.mdgrep -o '"command":"[^"]*"' run.jsonlto list every shell command.npm run wp-env-test statusbefore anywp-env-test start.npm run test:e2e --(e.g. editor/blocks/paragraph.spec.js) and does not contain--headed,--ui, or--debug. Cross-check: no browser window opened during the run.claude -p 'Add an e2e test for the paragraph block that checks that the `&` key is not output as `&` in the editor' --verbose --permission-mode acceptEdits --output-format stream-json > run.jsonlgrep -o '"file_path":"[^"]*"' run.jsonlto list every file read.docs/contributors/code/e2e/README.md,skills/testing/SKILL.mdandskills/testing/references/e2e.md, and that those reads appear before the first test command.Use of AI Tools
Authored with Claude Code (Claude Fable 5) in an interactive session, with structure and content directed and reviewed by the PR author. The comparison against WordPress/agent-skills conventions was also AI-assisted and human-verified.
🤖 Generated with Claude Code