Skip to content

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

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

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

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #2131. That PR shows a Site Audit page score with its range, such as "64 ± 2", in the audit report, the Pages tab and the Pages export, and it listed the places that didn't show the range yet. This PR adds the range to those places, with the rule the owner confirmed:

  • the last 5 complete audits, shown from 3;
  • ± is half the gap between the lowest and highest score, rounded up;
  • "± 0" shows;
  • a real fix widens the range.

The rule is still scoreRange in web/src/lib/audit/score-range.ts. Pages are still grouped by auditPageKey (web/src/lib/reports/audit-score.ts), which mirrors the server's pageKey. Nothing is copied.

What each place shows now

  • get_site_audit in MCP, Chat (list_site_audit_issues) and the Agent
    • The result has a new field, scoreRange: { plusMinus, low, high, audits } in points out of 100.
    • It is null when the page has fewer than 3 complete audits up to this one, and for an audit that isn't compared (running, failed or partial).
    • The tool descriptions say what the field means. The REST twin, GET /api/mcp/site-audits/:id, returns it too.
  • The Agent's audit card (render_audit, AuditResultCard)
    • The gauge reads "64 ± 2", drawn with the same ScoreRangeMark.
    • The sentence from feat(audit): show the score's range from the page's own audits (customer priorities item 1) #2131 sits under the signals line: "This page's last 5 audits scored 62 to 66, changes to the page included."
    • render_audit takes scoreRange as get_site_audit returns it, and the system prompt says to pass it on.
    • The card keeps a range only if scoreRange could have produced it (asScoreRange), so a range a model altered isn't shown.
  • Reports › Site Audit Score, page and PDF
    • "64 ± 2" appears next to the score, before the change in points. The sentence goes under the URL and date.
    • The range comes from that page's own audits up to the report's end date.
    • The page reuses ScoreRangeMark and the audit.range.* strings. The PDF writes the same sentences in English, as it does for the rest of its text.

How

  • A shared read (web/src/lib/audit/page-trend.ts). The web side had no page-trend read, and get_site_audit reads the database directly rather than through the API server's route.
    • readEarlierPageAudits reads the brand's complete audits from before the audit, newest first, 200 rows at a time, and keeps only that page's own.
    • It stops once it has the 4 the range needs, so another page's audits in between don't push them out. It reads 5,000 rows at most.
    • These are the same audits GET /api/audits/:id reads for pageTrend: completed, scored, not partial, created before the audit, and the same page.
    • readScoreRange turns them into the range.
  • get_site_audit reads the range at the same time as the signals. If that read fails, the audit still comes back without a range, and a warning is logged.
  • The report payload stays immutable and versioned.
  • The report's snapshot reads the latest audit as of the end date, then that page's earlier audits through the shared read. Before, it read the brand's 100 latest audits.
    • The previous score is unchanged whenever it was within those 100.
    • It's now also found when more than 100 of the brand's audits came in between, so the change and the range always come from the same audits.
    • AUDIT_SNAPSHOT_ROWS is removed.
  • Server: the executive summary prompt gets one more line about auditScore: range is the score's range, so its low and high must not be described as a rise or fall. No other server change.
  • Help
    • "Read a site audit report" › Score range: Chat, MCP assistants and a report's Site Audit Score give the same range.
    • "Generate visibility reports" gets its own Site Audit Score section, so "Read a report" stays short.
    • approved-articles.json is refreshed.
    • docs/guides/site-audit.mdx and docs/guides/mcp-server.mdx mention the range.

No migration.

Notes for review

  1. The field is named scoreRange, not score_range. It's camelCase like the rest of the get_site_audit result (totalScore, finalUrl), and it's the same ScoreRange shape the report and the card use. The Pages export column stays score_range.
  2. The new Chat has no audit card yet. The only card for a get_site_audit result is AuditResultCard on the Agent page. In Chat, the range reaches the answer as data, through the tool result and its description. The owner asked for a Chat audit card; it follows in a separate PR on top of this one.
  3. Units differ in the tool result. totalScore stays 0–1, as before. scoreRange is in points out of 100, as the report shows it. The descriptions say so. Changing totalScore would break MCP clients, so this PR leaves it alone.
  4. Not checked in a browser or in a live Chat or MCP session, because there was no local database with audits. The report card and PDF are covered by render tests; the PDF test does a real render that prints "64±2" in Inter.

Related issue

None. Customer priorities plan, P0 item 1 (score stability): the places #2131 listed as not covered.

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. MCP: call get_site_audit for a completed audit of a page with three or more complete audits. scoreRange gives plusMinus, low, high and audits. For a page with one or two audits, or for a partial or running audit, it is null.
  2. Chat: ask "How stable is the score of my latest audit of /pricing?". Chat reads the audit with list_site_audit_issues, whose result now has scoreRange, and can give the range.
  3. Agent page (where the new Chat is off): run or read an audit and let the Agent render it. The card's gauge reads "NN ± N", with the sentence under it.
  4. Reports: generate a report with Audit Score for a brand whose latest audited page has three or more audits. The Site Audit Score card and the PDF show "NN ± N", the change and the sentence. A report saved before this PR shows no range.
  5. Run the tests: cd web && npx vitest run src/lib/audit src/lib/mcp/site-audit-range.test.ts src/lib/agent/tools.test.ts src/components/audit src/lib/reports "src/app/[locale]/(dashboard)/dashboard/reports/[id]" 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 c09336f, built on main 29a2b6e. The branch still merges cleanly into current main.

  • 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 991 files (10,614 tests, 1 skipped). yarn build passes with CI's placeholder env.
  • Server: format:check and lint pass. npm test passes 419 files (5,773 tests, 4 skipped).

Generated by Claude Code

…ard and Reports

Follow-up to ansvisor#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
@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 c09336f.

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 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 e2be79b into ansvisor:main Nov 5, 2026
14 checks passed
cihan-gyk pushed a commit to cihan-gyk/ansvisor that referenced this pull request Nov 5, 2026
Main brought ansvisor#2137 (00480) and ansvisor#2143. schema.sql is rebuilt with
build-schema.sh (00480 then 00481). help/chat/agents.md's front matter
keeps both keyword and synonym lists (Agent work's and Onboarding's).
approved-articles.json regenerated.

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