Skip to content

feat(audit): show the score's range from the page's own audits (customer priorities item 1) - #2131

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:feature/audit-score-range
Nov 5, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:feature/audit-score-range

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Customer priorities plan, P0 item 1 (score stability), PR 2 of 2: the range. Part 1 (#1919) pinned the model and kept each AI verdict by its input, so an unchanged page keeps its score. This PR shows the score with a range worked out from the page's own audits, such as "64 ± 2". It makes no AI call and no extra query.

The plan (Customer Priorities › CUSTOMER-PRIORITIES-plan.md, item 1) says: "Show a range next to the score (e.g. "64 ± 2"), worked out from that page's own audit history. This is free, with no extra AI calls." The owner's decision of 2026-10-31 says the same: "The score is shown with its parts and a range." The plan doesn't say how to work out the range, so this PR uses the simplest rule. The numbers sit in one constant, SCORE_RANGE in web/src/lib/audit/score-range.ts.

The rule

  • It reads the page's latest 5 complete audits, including the audit whose score is shown. Five audits is a month of auto-audits (days 1, 7, 14, 21 and 28).
  • ± is half the gap between the lowest and highest score, in whole points as shown, rounded up. For example, 62, 66 and 63 give "63 ± 2".
  • The range shows from 3 complete audits. With 1 or 2, the score shows no range.
  • When the audits scored the same, it shows "± 0" ("This page's last 5 audits all scored 64.").
  • "The page" means what it means on the Pages list: the host without www, the path without a trailing slash, and the final URL after a redirect.

Where it shows

  • Report: the gauge reads "64 ± 2". A line beside it says "This page's last 5 audits scored 62 to 66, changes to the page included." The report of an older audit reads only the audits up to that one.
  • Pages tab: the current score shows "± 2" before the change since the first audit. Hovering shows the same sentence, and screen readers read it.
  • Export: a new last column, score_range / "Range (±)". It's empty when the page has too few audits. The columns before it keep their places.

How

  • Server: GET /api/audits/:id now sends pageTrend. These are the page's complete scores up to the audit, oldest first, the same shape as a Pages row's trend.
    • They come from the history the route already reads for the previous score, so there's no new query.
    • findPreviousCompletedAudit and the new pageTrendUpTo share one walk of the history (comparableAuditsUpTo).
  • Web: scoreRange(trend) works out the range from either trend, and ScoreRangeMark draws it.
  • i18n: audit.range.* and audit.export.scoreRange in en.json.
  • Help:
    • "Read a site audit report" gets a new section, "Score range".
    • "Site Audit scores, opportunities and pages" mentions the range on the Pages tab and in the export.
    • approved-articles.json is refreshed.

No migration.

Open points for the owner

  1. The rule's numbers are a proposal. The plan doesn't set them: 5 audits, shown from 3, ± half the gap between the lowest and highest score, rounded up. They're all in SCORE_RANGE / scoreRange.
  2. A real change widens the range. Say a fix lifts a page from 45 to 70. The next audits show "70 ± 13" until 45 drops out of the last five. The sentence says "changes to the page included". Two alternatives:
  3. "± 0" shows when a page's audits scored the same, which after fix(audit): keep each AI verdict by its input so an unchanged page keeps its score (00430) #1919 is most unchanged pages. It tells people the score held. Hide it instead?
  4. Outliers: none are dropped. The plan doesn't mention them.
  5. "Use the impact ledger's wording: correlation, not causation" is in the same plan item, but it's not clear which screen it belongs on. This PR doesn't add it.
  6. Places that don't show the range yet:
    • Chat's and MCP's get_site_audit, and the Agent's audit card. They read the audit straight from the database, without the page's history or the previous score.
    • The Site Audit Score section in Reports. It shows the brand's latest audit of any page, not one page's history.
    • Side finding: that Reports section prints total_score on its 0–1 scale, rounded to one decimal ("0.6" for 64). Its "previous" score can also be another page's. This PR doesn't touch it.
  7. The screens aren't approved yet. The plan asks for an approved mockup before code, and none was made for this PR. It also wasn't checked in a browser, because there was no local database with audits. Please check the report gauge at 1024px and on a phone, in light and dark.

Related issue

None. Customer priorities plan, P0 item 1 (score stability), part 2. Part 1 is #1919.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. Open the report of a page with three or more complete audits. The gauge shows "NN ± N", and the line beside it gives the lowest and highest score of the last five audits.
  2. A page with one or two audits shows no range, and neither does a partial audit.
  3. On the Pages tab, a page with three or more audits shows "± N" after its current score. Hover it to see the sentence.
  4. Export › CSV: the last column is score_range.
  5. Run the tests:
    • cd server && npx vitest run src/lib/audit/history.test.js src/routes/audits-pages.test.js
    • cd web && npx vitest run src/lib/audit src/components/audit/audit-report.test.tsx "src/app/[locale]/(dashboard)/dashboard/audit/_pages-table.test.tsx" src/lib/audit-export.test.ts src/lib/help

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR
  • Help article updated under help/ (or no user-visible change) — see help/README.md

Full checks on this branch (34b2a86), built on main 8be573d:

  • Web: format:check and typecheck pass. lint has 0 errors; its 7 warnings are old ones in files this PR doesn't touch. yarn test passes 975 files (10,407 tests, 1 skipped). yarn build passes with CI's placeholder env.
  • Server: format:check and lint pass. npm test passes 415 files (5,712 tests, 4 skipped).

Generated by Claude Code

…mer priorities item 1)

Customer priorities plan, item 1, part 2 (part 1: ansvisor#1919). A Site Audit
score now shows its range, such as "64 ± 2". It's worked out from the
page's latest 5 complete audits: half the gap between the lowest and
highest score, in whole points, rounded up. It shows from 3 audits.
Partial audits aren't counted. The rule sits in SCORE_RANGE
(web/src/lib/audit/score-range.ts).

- Report: the gauge reads "64 ± 2", and a line beside it gives the
  lowest and highest score. GET /api/audits/:id sends the page's trend
  up to the audit (pageTrend) from the history it already reads, so
  there's no new query. findPreviousCompletedAudit and pageTrendUpTo
  share one walk of that history.
- Pages tab: "± 2" after the current score, from the row's trend, with
  the same sentence on hover and for screen readers.
- Pages export: a last column, score_range.
- Help: "Read a site audit report" gets "Score range"; the overview
  article mentions it on the Pages tab and in the export.
  approved-articles.json refreshed. docs/guides/site-audit.mdx updated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
@mintlify

mintlify Bot commented Nov 5, 2026

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 34b2a86.

Approve preview

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@gkhngyk
gkhngyk merged commit c8f0b75 into ansvisor:main Nov 5, 2026
14 checks passed
gkhngyk pushed a commit that referenced this pull request Nov 5, 2026
…ard and Reports (#2143)

Follow-up to #2131: the places it listed as not showing the range now
do, by the same rule (scoreRange) and page grouping (auditPageKey).

- get_site_audit (MCP, Chat's list_site_audit_issues, the Agent, and
  GET /api/mcp/site-audits/:id) returns scoreRange: { plusMinus, low,
  high, audits } in points, or null with fewer than 3 complete audits
  or for an audit that isn't compared. It's read alongside the signals;
  a failed read leaves it null.
- A shared read, lib/audit/page-trend.ts, reads the page's complete
  audits before an audit from the brand's, newest first, a slice at a
  time, until it has the 4 the range needs: the audits GET
  /api/audits/:id reads for pageTrend.
- The Agent's audit card shows "64 ± 2" with ScoreRangeMark and the
  audit.range sentence. render_audit takes scoreRange; asScoreRange
  keeps only a range the rule could give.
- Reports › Site Audit Score, page and PDF: the range from the page's
  audits up to the end date, as a new optional payload field (range).
  Older reports show none. The snapshot reads the page's earlier audits
  with the shared read instead of the brand's latest 100, so the
  previous score and the range come from the same audits. The summary
  prompt says what auditScore.range is.
- Help: Score range (read an audit report) and a Site Audit Score
  section in Generate visibility reports; approved-articles.json
  refreshed. docs/guides/site-audit.mdx and mcp-server.mdx updated.


Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9

Co-authored-by: Claude <[email protected]>
gkhngyk pushed a commit that referenced this pull request Nov 5, 2026
…ge and "64 ± 2" (#2149)

* feat(audit): show the score's range in Chat, MCP, the Agent's audit card and Reports

Follow-up to #2131: the places it listed as not showing the range now
do, by the same rule (scoreRange) and page grouping (auditPageKey).

- get_site_audit (MCP, Chat's list_site_audit_issues, the Agent, and
  GET /api/mcp/site-audits/:id) returns scoreRange: { plusMinus, low,
  high, audits } in points, or null with fewer than 3 complete audits
  or for an audit that isn't compared. It's read alongside the signals;
  a failed read leaves it null.
- A shared read, lib/audit/page-trend.ts, reads the page's complete
  audits before an audit from the brand's, newest first, a slice at a
  time, until it has the 4 the range needs: the audits GET
  /api/audits/:id reads for pageTrend.
- The Agent's audit card shows "64 ± 2" with ScoreRangeMark and the
  audit.range sentence. render_audit takes scoreRange; asScoreRange
  keeps only a range the rule could give.
- Reports › Site Audit Score, page and PDF: the range from the page's
  audits up to the end date, as a new optional payload field (range).
  Older reports show none. The snapshot reads the page's earlier audits
  with the shared read instead of the brand's latest 100, so the
  previous score and the range come from the same audits. The summary
  prompt says what auditScore.range is.
- Help: Score range (read an audit report) and a Site Audit Score
  section in Generate visibility reports; approved-articles.json
  refreshed. docs/guides/site-audit.mdx and mcp-server.mdx updated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9

* feat(chat): show a Site Audit Chat reads as a card with its score gauge and range

The owner asked for a Site Audit card in the new Chat, on top of #2143's
scoreRange. After a list_site_audit_issues read, the engine builds the
card from the read's own result and emits audit.ready, as What's new and
Why do: the run state applies it, a reloaded chat reads it back from
chat_run_events, and ChatThreadView draws it with the run's other cards.

- The card: the page, its score on the report's ScoreGauge with
  ScoreRangeMark ("64 ± 2") and the audit.range sentence when scoreRange
  isn't null, "Audited …" with the change since the page's audit before
  (audit.scoreChange), and Open report. A partial audit shows the
  report's note and no range or change; a running, failed or unscored
  audit shows no card.
- Never the model's numbers: a range is kept only if asScoreRange
  accepts it and the score is in it, on the server and again in the
  browser. One card per audit, 3 at most per answer. No id in the event
  but the report link.
- get_site_audit (MCP, Chat, the Agent, the REST twin) returns partial,
  previousScore and previousCreatedAt, from the read the range already
  does (readPageComparison). The tool descriptions say what they mean.
- Help: "A Site Audit in Chat" in Use Chat, and Score range in Read a
  site audit report; approved-articles.json refreshed. The Site Audit
  and MCP guides mention the card and the new fields.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9

---------

Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants