Repository navigation
feat(audit): audit top-priority pages automatically each billing week - #1139
Conversation
SA-004 of the Site Audit v2 spec, first sources: audits were only of the URLs someone typed, with nothing suggesting which pages to audit (F5, F7). - GET /api/audits/opportunities builds the inbox (lib/audit/opportunities.js): Google Analytics' open "no AI traffic" pages (page_opportunities: valuable pages AI engines send no visitors to) and the site's pages (site_pages) never audited or audited more than auditMaxAgeDays (90) ago. One row per page across spellings, with why (chips), its last audit and its AI visits over 30 days (Analytics where it has the page, else the snippet). Pinned pages come first; excluded ones are listed apart; checkout-like paths stay out. Until the priority score (SA-005) rows follow GA value, then never audited, then citations and sessions. - Migration 00164 adds site_audit_page_prefs (pinned / excluded per page), written through PUT /api/audits/opportunities/prefs. - The hub gets Opportunities and Pages tabs; Opportunities opens when it lists pages. Select pages to Audit selected (the bulk audit, within the quota), Pin / Unpin or Exclude (with Undo); excluded pages can be restored from the list under the table. The bulk bar takes each table's own audit label and actions. Competitor-cited pages and Search Console sources come in later PRs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t Opportunities
SA-004's citation source: prompts where a competitor's page is cited and
the brand's never is point to the brand page closest to them, as a page
worth auditing.
- Migration 00165 adds audit_competitor_cited_prompts (service role only):
per active prompt over a window, answers citing a competitor's domain,
answers citing the brand's own, and the competitor domains cited, read
from prompt_result_citations (domains match with their subdomains).
- competitorGapPages (lib/audit/opportunities.js) keeps the prompts the
brand was never cited on and maps each to its target URL, else the best
site_pages match (candidatePages, as Content opportunities use), one row
per page with its prompts and competitor names.
- GET /api/audits/opportunities adds them as a competitor_cited reason over
the last 30 days; without competitor domains it asks nothing, and on a
database without 00165 (PGRST202) the other sources still list. Until
the priority score (SA-005) these pages rank after GA's valuable pages and
before pages never audited.
- The Opportunities table shows them as "Crema Club cited on 3 prompts"
("+N" for more competitors).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
main took 00164 (insights topic rollups), so this branch's migration moves to 00165_site_audit_page_prefs.sql; schema.sql rebuilt. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nities-competitors
main took 00164 (insights topic rollups) and the Opportunities prefs migration moved to 00165, so this one follows as 00166; schema.sql rebuilt. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each page in the Opportunities inbox gets a 0-100 priority: its value to the business x the opportunity an audit can win x how easy it is to fix, each 0-1, shown as the cube root of the product (SA-005). Pinned pages stay on top; the rest are ordered by priority. The table shows the score in a pill (dark from 80) with its parts on hover. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Site Audit's auto-audit (SA-006): 25% of the monthly quota audits the
Opportunities inbox's top pages by itself, in five runs of 5% (at least
one page) on days 1, 7, 14, 21 and 28 of the billing month. A daily sweep
after the GA sync claims each org's due run once, picks pinned pages
first and then the highest priority across its brands, skipping pages
audited or tried in the last 30 days, and runs them in their own pool.
The runs still to come keep their slots out of the user's pool; a run's
unused slots return when it is recorded.
Settings (admins and managers): auto-audit on/off for the organization
(on by default with a monthly quota, off without one), an e-mail after
each run, the brand's exclude patterns and its pinned pages. The Site
Audit page shows the latest run ("3 pages audited · 6 critical issues ·
next run Oct 21") and the quota card what auto-audit keeps.
Migration 00167 adds the settings and run tables and a source column on
site_audits and site_audit_usage.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # server/src/lib/audit/opportunities.js # server/src/lib/audit/opportunities.test.js # server/src/routes/audits-opportunities.test.js # server/src/routes/audits.js # supabase/migrations/00166_audit_competitor_cited_prompts.sql # supabase/schema.sql # web/src/app/[locale]/(dashboard)/dashboard/audit/page.tsx # web/src/lib/actions/audits.ts
|
@gkhngyk This is SA-006: auto-audit runs 5% of the quota on billing days 1/7/14/21/28 on the inbox's top pages, keeps the runs still to come out of the user's pool, and adds a Settings dialog and a run notice. Migration 00167 (applied on the dev DB) must be applied before the server deploys, since the quota reads its tables; Starter/Growth orgs have it on by default, so the current week's run happens at the first daily job. It's on main (merged after #1138, with your 00166 perf commit). Locally the audits fail without the Scrape.do/model keys, so could you try a real run with |
supabase/schema.sql regenerated with build-schema.sh. Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A
gkhngyk
left a comment
There was a problem hiding this comment.
Rebuilt on main with schema.sql regenerated (00167 sits next to #1144's 00168). Your earlier merge of main carried no other changes and kept 00166's faster read.
Tested on the stack's tip over main:
- Server: 1590/1590 pass.
- Web: all tests pass, run locally with the Excel writer stubbed (CI's web job doesn't run tests).
- CI is green.
00167 is applied on production. The three new tables have RLS with member select only, so settings and runs are written by the server alone, and source defaults to user on the existing 105 audits and 146 usage rows.
One thing to know before the server deploy: with no settings row, auto-audit is on for every plan with a monthly quota. From the deploy on, the runs still to come hold their 25% out of each org's pool. The quota message points to the setting to turn it off.
Summary
Site Audit now audits the top-priority pages by itself. This is task SA-006 of the Site Audit v2 spec (§4.3, §13).
floor(quota × 5%), at least one page.Migration
00167_site_audit_auto.sqlsite_audit_settings(per organization):auto_auditandemail_after_run. No row, or a nullauto_audit, follows the plan: on with a monthly quota, off without one (Self-hosted, Enterprise without a contract limit).site_audit_brand_settings: a brand'sexclude_patterns(/careers/*).site_audit_auto_runs: one row per organization, billing period and run day.source(user|auto, defaultuser) onsite_auditsandsite_audit_usage. It lets the quota card (SA-019) tell auto use from the user's.Server
lib/audit/auto-audit.js(pure):pickRunPages, which picks:lib/audit/auto-audit-sweep.js:routes/audits.jsas arguments, so the module imports no route.runDailyTracking: runs the sweep after the GA sync and page-opportunity detection, so a run audits what this week's data ranks highest.plan-guard.js:source: 'auto') can.getSiteAuditQuotaStatusnow returnsauto: enabled, per run, reserved, used, the five runs withdone, the next run, and the due run.remainingis the user's pool.routes/audits.js:auditPool, shared with the bulk pool of 3).startAutoAuditsstarts a brand's run audits and returns when they're done.readOpportunityInboxis the inbox read the GET route used, now exported and applying the brand's exclude patterns.GET/PUT /api/audits/settings: the dialog's data. Changing it needs admin or manager, as for Daily Pulse settings. Patterns are normalized (lowercased path, no trailing slash) and refused when they aren't a path.GET /api/audits/auto-runs/latest: the latest run (last 30 days) that audited this brand's pages. It returns its pages, completed, running, and critical issues (the signals those audits failed).lib/audit/auto-audit-email.js: "Site Audit: 25 pages audited · 6 critical issues · next run Oct 28", per brand when the run covered several. Sent through Resend; a no-op where it isn't configured.src/scripts/run-auto-audits.js: runs the sweep now.AUTO_AUDIT_ORGlimits it to one org;AUTO_AUDIT_NOWtakes another time as now.Web
en.jsonunderaudit.settings,audit.autoRunandaudit.overview.Deploy
get_site_audit_quota(MCP) now also returns theautoobject. A docs follow-up for the skills can come separately.Known limits
runningwithout its e-mail. Its audits time out as failed after 2 h (AUDIT_RUN_TIMEOUT_MS), as any audit does.Related issue
None. Site Audit v2 spec, task SA-006.
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
IS_CLOUD=true AUTO_AUDIT_ORG=<org id> node src/scripts/run-auto-audits.jsfromserver/./guides/*to excluded pages: those pages leave Opportunities.PUT /api/audits/settingsanswers 403.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/): no errors; the 7 warnings are in files this PR does not touchyarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Also run:
server:npm run format,npm run lintandnpm test(1563) pass. New and updated tests:lib/audit/auto-audit.test.js: share per run, defaults, schedule (afternoon renewals, short periods), due run, pending runs, page picking.lib/audit/auto-audit-sweep.test.js: claim, pages across brands, quota cap, empty run, e-mail, every org started before any finishes, tried pages skipped.lib/audit/auto-audit-email.test.js: subject, summary, per-brand lines, escaping.lib/plan-guard-site-audit.test.js: reserved slots out of the user's pool, a run using them, the empty-pool message, unlimited plans.routes/audits-settings.test.js: GET/PUT settings, roles, pattern validation, latest run.routes/audits-pages.test.js: run audits marked auto in their own pool.routes/audits-opportunities.test.js: exclude patterns in the inbox.lib/audit/opportunities.test.js: pattern normalization and matching.web:yarn test(1342) andyarn buildpass. Tests cover the settings dialog, the run notice and the card's sub-line.bash supabase/build-schema.sh: regeneratedschema.sql.🤖 Generated with Claude Code