Skip to content

Commit bf63f84

Browse files
Add AI Performance Advisor plugin (#2485)
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 #2485
1 parent f5222f4 commit bf63f84

29 files changed

Lines changed: 2353 additions & 0 deletions

.wp-env.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"$schema": "https://schemas.wp.org/trunk/wp-env.json",
33
"core": null,
44
"plugins": [
5+
"./plugins/ai-performance-advisor",
56
"./plugins/optimization-detective",
67
"./plugins/auto-sizes",
78
"./plugins/dominant-color-images",

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
"WP_MULTISITE=1 php vendor/bin/phpunit --exclude-group=ms-excluded"
102102
],
103103
"test-multisite:plugins": [
104+
"@test-multisite:ai-performance-advisor",
104105
"@test-multisite:auto-sizes",
105106
"@test-multisite:dominant-color-images",
106107
"@test-multisite:embed-optimizer",
@@ -112,6 +113,7 @@
112113
"@test-multisite:web-worker-offloading",
113114
"@test-multisite:webp-uploads"
114115
],
116+
"test-multisite:ai-performance-advisor": "@test-multisite --verbose --testsuite ai-performance-advisor",
115117
"test-multisite:auto-sizes": "@test-multisite --verbose --testsuite auto-sizes",
116118
"test-multisite:dominant-color-images": "@test-multisite --verbose --testsuite dominant-color-images",
117119
"test-multisite:embed-optimizer": "@test-multisite --verbose --testsuite embed-optimizer",
@@ -123,6 +125,7 @@
123125
"test-multisite:web-worker-offloading": "@test-multisite --verbose --testsuite web-worker-offloading",
124126
"test-multisite:webp-uploads": "@test-multisite --verbose --testsuite webp-uploads",
125127
"test:plugins": [
128+
"@test:ai-performance-advisor",
126129
"@test:auto-sizes",
127130
"@test:dominant-color-images",
128131
"@test:embed-optimizer",
@@ -134,6 +137,7 @@
134137
"@test:web-worker-offloading",
135138
"@test:webp-uploads"
136139
],
140+
"test:ai-performance-advisor": "@test --verbose --testsuite ai-performance-advisor",
137141
"test:auto-sizes": "@test --verbose --testsuite auto-sizes",
138142
"test:dominant-color-images": "@test --verbose --testsuite dominant-color-images",
139143
"test:embed-optimizer": "@test --verbose --testsuite embed-optimizer",

phpstan.neon.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ parameters:
1818
- vendor/phpstan/php-8-stubs/stubs/ext/standard/str_contains.php
1919
- vendor/phpstan/php-8-stubs/stubs/ext/standard/str_starts_with.php
2020
- vendor/phpstan/php-8-stubs/stubs/ext/standard/str_ends_with.php
21+
- tools/phpstan/stubs/ai-client.stub
2122
stubFiles:
2223
- tools/phpstan/filtered-functions.stub
2324
dynamicConstantNames:

phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
<testsuite name="performance-lab">
1212
<directory suffix=".php">plugins/performance-lab/tests</directory>
1313
</testsuite>
14+
<testsuite name="ai-performance-advisor">
15+
<directory suffix=".php">plugins/ai-performance-advisor/tests</directory>
16+
</testsuite>
1417
<testsuite name="auto-sizes">
1518
<directory suffix=".php">plugins/auto-sizes/tests</directory>
1619
</testsuite>

plugins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"plugins": [
3+
"ai-performance-advisor",
34
"auto-sizes",
45
"dominant-color-images",
56
"embed-optimizer",
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/**
2+
* AI Performance Advisor - Site Health tab styles.
3+
*
4+
* @since 1.0.0
5+
*/
6+
7+
#aipa-results {
8+
margin-top: 1em;
9+
}
10+
11+
.aipa-card {
12+
background: #fff;
13+
border: 1px solid #c3c4c7;
14+
border-left-width: 4px;
15+
border-radius: 2px;
16+
padding: 12px 16px;
17+
margin-bottom: 12px;
18+
}
19+
20+
.aipa-card.aipa-severity-critical {
21+
border-left-color: #d63638;
22+
}
23+
24+
.aipa-card.aipa-severity-recommended {
25+
border-left-color: #dba617;
26+
}
27+
28+
.aipa-card.aipa-severity-good {
29+
border-left-color: #00a32a;
30+
}
31+
32+
.aipa-card.aipa-severity-info {
33+
border-left-color: #72aee6;
34+
}
35+
36+
.aipa-card-title {
37+
margin: 0 0 0.5em;
38+
font-size: 1.05em;
39+
}
40+
41+
.aipa-badge {
42+
display: inline-block;
43+
font-size: 11px;
44+
line-height: 1.6;
45+
text-transform: uppercase;
46+
letter-spacing: 0.5px;
47+
padding: 0 8px;
48+
border-radius: 9px;
49+
color: #fff;
50+
vertical-align: middle;
51+
}
52+
53+
.aipa-badge-critical {
54+
background: #d63638;
55+
}
56+
57+
.aipa-badge-recommended {
58+
background: #dba617;
59+
}
60+
61+
.aipa-badge-good {
62+
background: #00a32a;
63+
}
64+
65+
.aipa-badge-info {
66+
background: #72aee6;
67+
}
68+
69+
.aipa-card-summary {
70+
margin: 0 0 0.5em;
71+
font-weight: 600;
72+
}
73+
74+
.aipa-card-details {
75+
white-space: pre-wrap;
76+
margin: 0 0 0.5em;
77+
}
78+
79+
.aipa-card-evidence summary {
80+
cursor: pointer;
81+
color: #50575e;
82+
}
83+
84+
.aipa-card-actions {
85+
margin-top: 0.75em;
86+
}
87+
88+
.aipa-card-actions .button {
89+
margin-right: 8px;
90+
}

0 commit comments

Comments
 (0)