Add AI Performance Advisor plugin#2504
Conversation
|
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. |
bf63f84 to
2d65c75
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## trunk #2504 +/- ##
==========================================
+ Coverage 69.29% 70.20% +0.90%
==========================================
Files 90 105 +15
Lines 7723 8321 +598
==========================================
+ Hits 5352 5842 +490
- Misses 2371 2479 +108
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
de8be83 to
318143a
Compare
Introduce a new standalone feature plugin that surfaces actionable, AI-generated performance recommendations in a dedicated Site Health tab. The plugin gathers bounded site context through a pluggable provider registry (environment, Site Health debug data with private fields removed, plugin Site Health test results, a compact PageSpeed Insights snapshot, and an optional Optimization Detective summary), sends it to the WordPress 7.0 AI Client API, and renders the returned recommendations as prioritized cards. Analysis is on demand via an authenticated REST endpoint and the result is cached in a transient to control token cost. This initial version is suggest-only: it never changes site configuration. The recommendation data model includes an optional, currently-inert action.ability field so a future version can apply changes through the Abilities API as that surface matures. Includes unit tests (single site and multisite), registration in the monorepo tooling and the Performance Lab feature list, and a PHPStan stub for the WordPress 7.0 AI Client and Abilities APIs that are not yet present in wordpress-stubs. Fixes WordPress#2485
318143a to
d2815c0
Compare
The initial test files carried no @Covers annotations, so under the project's strict coverage-metadata setting their coverage was discarded and Codecov reported 0.67% patch coverage. Annotate every test and greatly expand the suite to exercise the helper functions, the analyzer (cache, parsing, and error paths via mocked seams), all five context providers (including PageSpeed Insights HTTP mocking), the registry, the settings, the REST endpoint, and the Site Health tab renderer. Add two filters as testability seams: aipa_pre_is_ai_available (force the availability result) and aipa_pre_generate_text (short-circuit the model call). These let the AI-dependent paths be tested deterministically and also let integrators force availability or route the request through their own client.
The crate-ci/typos spell check flags 'unparseable' as a misspelling of 'unparsable'. Rename the two affected test methods.
The php-test-plugins workflow builds a --coverage-clover report from an explicit per-plugin list, and ai-performance-advisor was absent from both the single-site and multisite lists. The plugin's tests therefore ran (via the non-coverage 'else' branch's test:plugins) but produced no coverage report, so Codecov showed every file at 0%. Add the plugin to both coverage lists. Also add tests for the admin asset enqueueing in hooks.php, which was the last uncovered file.
The php-test-plugins coverage matrix leg invokes 'npm run test-php:ai-performance-advisor' and the multisite variant, but those wrapper scripts were never added to package.json (only the composer test:ai-performance-advisor script existed). The leg therefore failed with 'Missing script'. Add both npm wrappers, matching the other plugins.
Summary
Implements #2485 by adding a new standalone feature plugin, AI Performance Advisor, that surfaces actionable, AI-generated performance tuning recommendations in a dedicated Site Health tab.
When the site administrator clicks Analyze my site, the plugin gathers bounded context about the site, sends it to the WordPress 7.0 AI Client API, and renders the returned recommendations as prioritized cards. Analysis is on demand (never automatic) and the result is cached in a transient to control token cost.
This initial version is suggest-only: it never changes site configuration. The design is forward-looking so a future version can offer to apply changes for the user as the Abilities API matures.
How it works
AIPA_Context_Provider+ registry, filterable viaaipa_context):WP_Debug_Data::debug_data(), withprivatefields stripped (no keys, salts, or secrets).site_status_testsfilter).wp_ai_client_prompt()->using_system_instruction()->generate_text(), validates the JSON response into a sanitized recommendation list, and caches it.POST ai-performance-advisor/v1/analyze, gated byview_site_health_checks.Forward compatibility
Each recommendation carries an optional, currently-inert
action.abilityfield ({ name, args }). When the Abilities API surface for these plugins lands (#2441), the same data model can drive an "Apply" affordance viawp_get_ability()->execute()and, ultimately,wp_ai_client_prompt()->using_abilities(). No abilities are registered in this version and nothing is written.Requirements
Privacy
Nothing is sent anywhere until the admin explicitly starts an analysis. Private Site Health fields are excluded, and the full payload can be redacted or extended via the
aipa_contextfilter. The tab lists exactly which categories of data will be sent before the analysis runs.Testing
wp-env: single site OK (19 tests, 40 assertions) and multisite OK (19 tests, 40 assertions).composer lint(WPCS) andcomposer phpstan(level 8) are clean. A PHPStan stub is added for the WP 7.0 AI Client / Abilities symbols, which are not yet present inwordpress-stubs.Notes
plugins.json,.wp-env.json,phpunit.xml.dist, thecomposer.jsontest scripts, and the Performance Lab feature list (as experimental).Fixes #2485
AI Use
Claude code wrote the code. I prompted and guided Claude. I will review the code and test it manually.