Skip to content

Add AI Performance Advisor plugin#2504

Draft
adamsilverstein wants to merge 5 commits into
WordPress:trunkfrom
adamsilverstein:add/ai-performance-advisor
Draft

Add AI Performance Advisor plugin#2504
adamsilverstein wants to merge 5 commits into
WordPress:trunkfrom
adamsilverstein:add/ai-performance-advisor

Conversation

@adamsilverstein
Copy link
Copy Markdown
Member

@adamsilverstein adamsilverstein commented May 29, 2026

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

  • Pluggable context providers (AIPA_Context_Provider + registry, filterable via aipa_context):
    • Environment: active plugins, active theme, WP/PHP/DB versions.
    • Site Health debug data via WP_Debug_Data::debug_data(), with private fields stripped (no keys, salts, or secrets).
    • Results of performance-related Site Health tests (gathered via the site_status_tests filter).
    • A compact PageSpeed Insights (Lighthouse) snapshot of the home page (optional; togglable in settings; free at low volume).
    • An optional Optimization Detective summary when that plugin is active.
  • Analyzer calls wp_ai_client_prompt()->using_system_instruction()->generate_text(), validates the JSON response into a sanitized recommendation list, and caches it.
  • REST endpoint POST ai-performance-advisor/v1/analyze, gated by view_site_health_checks.
  • Settings under General: PageSpeed Insights toggle and optional API key.
  • Graceful degradation: when no text-capable AI provider is connected, the tab shows a notice linking to the connectors settings.

Forward compatibility

Each recommendation carries an optional, currently-inert action.ability field ({ name, args }). When the Abilities API surface for these plugins lands (#2441), the same data model can drive an "Apply" affordance via wp_get_ability()->execute() and, ultimately, wp_ai_client_prompt()->using_abilities(). No abilities are registered in this version and nothing is written.

Requirements

  • WordPress 7.0+ (for the AI Client and Connectors APIs).
  • At least one connected AI provider that supports text generation.

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_context filter. The tab lists exactly which categories of data will be sent before the analysis runs.

Testing

  • Unit tests for helper sanitization/validation, the recommendation schema and its forward-compatible action field, context providers and the registry filter, Site Health tab registration, REST permission gating, and graceful degradation when AI is unavailable.
  • Verified locally via wp-env: single site OK (19 tests, 40 assertions) and multisite OK (19 tests, 40 assertions).
  • composer lint (WPCS) and composer phpstan (level 8) are clean. A PHPStan stub is added for the WP 7.0 AI Client / Abilities symbols, which are not yet present in wordpress-stubs.

Notes

  • Registered in plugins.json, .wp-env.json, phpunit.xml.dist, the composer.json test scripts, and the Performance Lab feature list (as experimental).
  • This is a plugin proposal per the issue labels; happy to adjust scope, naming, or the context set based on review.

Fixes #2485

AI Use

Claude code wrote the code. I prompted and guided Claude. I will review the code and test it manually.

@github-actions
Copy link
Copy Markdown

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: adamsilverstein <adamsilverstein@git.wordpress.org>
Co-authored-by: westonruter <westonruter@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@adamsilverstein adamsilverstein force-pushed the add/ai-performance-advisor branch 2 times, most recently from bf63f84 to 2d65c75 Compare May 29, 2026 17:08
@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

Codecov Report

❌ Patch coverage is 81.93980% with 108 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.20%. Comparing base (f5222f4) to head (b15eccd).

Files with missing lines Patch % Lines
plugins/ai-performance-advisor/load.php 0.00% 20 Missing ⚠️
plugins/ai-performance-advisor/helper.php 87.00% 13 Missing ⚠️
...ers/class-aipa-provider-optimization-detective.php 35.29% 11 Missing ⚠️
...udes/providers/class-aipa-provider-environment.php 72.97% 10 Missing ⚠️
plugins/ai-performance-advisor/settings.php 89.15% 9 Missing ⚠️
...rformance-advisor/includes/class-aipa-analyzer.php 88.88% 8 Missing ⚠️
...udes/providers/class-aipa-provider-site-health.php 82.92% 7 Missing ⚠️
plugins/ai-performance-advisor/hooks.php 70.00% 6 Missing ⚠️
...cludes/providers/class-aipa-provider-pagespeed.php 91.04% 6 Missing ⚠️
...roviders/class-aipa-provider-site-health-tests.php 82.75% 5 Missing ⚠️
... and 5 more
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     
Flag Coverage Δ
multisite 70.20% <81.93%> (+0.90%) ⬆️
single 35.15% <27.25%> (-0.62%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@adamsilverstein adamsilverstein force-pushed the add/ai-performance-advisor branch 5 times, most recently from de8be83 to 318143a Compare May 29, 2026 17:49
@adamsilverstein adamsilverstein marked this pull request as draft May 29, 2026 18:02
@adamsilverstein adamsilverstein self-assigned this May 29, 2026
@adamsilverstein adamsilverstein added the [Type] Plugin Proposal A new plugin proposal label May 29, 2026
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
@adamsilverstein adamsilverstein force-pushed the add/ai-performance-advisor branch from 318143a to d2815c0 Compare May 29, 2026 18:05
@adamsilverstein adamsilverstein added the no milestone PRs that do not have a defined milestone for release label May 29, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no milestone PRs that do not have a defined milestone for release [Type] Plugin Proposal A new plugin proposal

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add AI-based Performance Tuning Recommendations as Site Health Tab (requires WP 7.0)

1 participant