feat(perf): add CrUX field data and PageSpeed Insights tools#27
Open
feat(perf): add CrUX field data and PageSpeed Insights tools#27
Conversation
Adds two new performance research tools: - `research_crux` — Chrome UX Report API for real-user field data. Returns LCP/INP/CLS/FCP/TTFB p75 percentiles and histogram distributions (good/needs-improvement/poor) as 28-day rolling averages. Includes 25-week history with improving/stable/degrading trend classification. This is THE source of truth for Core Web Vitals pass/fail (SEO ranking signal). - `research_pagespeed` — Google PageSpeed Insights (hosted Lighthouse). Alternative to the Browserless-backed lighthouse_audit: runs on Google's infrastructure, no token needed. Returns 0-100 performance score, lab CWV metrics, and prioritized opportunities with estimated ms/KB savings. Both use a single Google Cloud API key via GOOGLE_PAGESPEED_API_KEY. Updates Phase 2 of the diagnostic flow to spawn these in parallel with existing tools, and extends the Performance health-score rubric (0-20) to weight field CWV data when available (lab-only as fallback for low-traffic sites without CrUX data). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
site-diagnostics | 3c733bd | Apr 18 2026, 06:38 PM |
There was a problem hiding this comment.
1 issue found across 5 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="api/tools/research-crux.ts">
<violation number="1" location="api/tools/research-crux.ts:144">
P2: Guard against `olderAvg === 0` before computing percent change; the current formula can produce `Infinity`/`NaN` trend output.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| if (older.length === 0) continue; | ||
| const recentAvg = recent.reduce((s, v) => s + v, 0) / recent.length; | ||
| const olderAvg = older.reduce((s, v) => s + v, 0) / older.length; | ||
| const change = ((recentAvg - olderAvg) / olderAvg) * 100; |
There was a problem hiding this comment.
P2: Guard against olderAvg === 0 before computing percent change; the current formula can produce Infinity/NaN trend output.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At api/tools/research-crux.ts, line 144:
<comment>Guard against `olderAvg === 0` before computing percent change; the current formula can produce `Infinity`/`NaN` trend output.</comment>
<file context>
@@ -0,0 +1,251 @@
+ if (older.length === 0) continue;
+ const recentAvg = recent.reduce((s, v) => s + v, 0) / recent.length;
+ const olderAvg = older.reduce((s, v) => s + v, 0) / older.length;
+ const change = ((recentAvg - olderAvg) / olderAvg) * 100;
+ let direction: string;
+ if (Math.abs(change) < 3) direction = "stable";
</file context>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds real-user performance data to site-diagnostics via two new research tools, closing the gap between what Lighthouse measures in a lab and what actual users experience in the wild. Both share a single Google Cloud API key (
GOOGLE_PAGESPEED_API_KEY).Why
lighthouse_auditgives us a lab simulation — a snapshot from a clean environment on Google's servers. But Core Web Vitals pass/fail (an SEO ranking signal) is decided by real user data from Chrome UX Report. Without CrUX, our Performance health score was inferring user experience from a single synthetic run. Now we have both lenses.What's new
1.
research_crux— Chrome UX Report (real-user field data)hasData: false)cwvAssessment— authoritative CWV pass/fail + per-metric ratings2.
research_pagespeed— Google PageSpeed Insightslighthouse_auditwhen Browserless is unavailable or as a second opinion3. Updated Phase 2 execution
New tools spawned in parallel with existing deep-analysis work (no added latency).
4. Updated Performance health-score rubric (0-20)
research_crux— 10 if passes CWV, 7 if 2/3 good, 4 if 1/3 good, 0 if all poorFiles changed
api/lib/pagespeed.ts(new) — Shared CrUX + PSI clients, CWV thresholds, rating helpersapi/tools/research-crux.ts(new) — Tool definitionapi/tools/research-pagespeed.ts(new) — Tool definitionapi/tools/index.ts— Register new toolsshared/diagnostics.ts— Tool catalog, Phase 2 execution, Performance rubricEnvironment
Set one env var:
Enable these APIs on the key: Chrome UX Report API, PageSpeed Insights API.
Test plan
bun install && bunx tsc --noEmitpassesdiagnoseon a high-traffic site (e.g. bagaggio.com.br) — verify CrUX data appears and trend analysis shows updiagnoseon a low-traffic site — verify graceful fallback withhasData: falsenote in the reportresearch_pagespeedworks withoutBROWSERLESS_TOKENset (uses Google's hosted Lighthouse)🤖 Generated with Claude Code
Summary by cubic
Add real-user performance data with CrUX and a hosted Lighthouse option via PageSpeed Insights, and integrate both into diagnostics and the Performance score. This adds authoritative CWV pass/fail and PSI opportunities without needing
BROWSERLESS_TOKEN.New Features
research_crux: p75 LCP/INP/CLS/FCP/TTFB (28-day), distributions, optional 25-week trends, origin or URL scope, CWV pass/fail; graceful fallback for low-traffic sites.research_pagespeed: hosted Lighthouse via Google; returns 0–100 score, lab CWV, and prioritized opportunities; noBROWSERLESS_TOKENrequired.research_crux+ Technical (0–10); falls back to lab-only when CrUX is unavailable.Migration
GOOGLE_PAGESPEED_API_KEY.Written for commit 3c733bd. Summary will update on new commits.