Skip to content

feat(chat): show a Site Audit Chat reads as a card with its score gauge and "64 ± 2" - #2149

Merged
gkhngyk merged 4 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-audit-card
Nov 5, 2026
Merged

gkhngyk merged 4 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-audit-card

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #2143, now merged. main is merged into this branch, so the diff shows only this PR's own commit (a2e0d9d).

#2143 gave Chat the score's range through list_site_audit_issues, but the new Chat answered in text only. The owner asked for a card. When Chat reads a Site Audit, a card now shows under the answer with:

  • The page: where it ended up, or else the address asked for.
  • Its score, on the audit report's gauge (ScoreGauge with ScoreRangeMark): "64 ± 2".
  • The range sentence, when scoreRange isn't null. It uses feat(audit): show the score's range from the page's own audits (customer priorities item 1) #2131's audit.range.* strings: "This page's last 5 audits scored 62 to 66, changes to the page included."
  • When it ran and what changed: "Audited Oct 30, 2026", in the time zone the answer was shown in. Next to it, the change since the page's previous audit ("+3 since Oct 21"), with the report's audit.scoreChange badge.
  • Open report, which opens the audit's report in Site Audit.

Other audit states:

  • Partial: the card shows the score with the report's note ("The AI checks couldn't run this time…"), and no range or change.
  • Still running, failed or unscored: no card.

How

  • The card comes from the read's own result, never from the model's words.
    • After a list_site_audit_issues read, the engine builds the card from the result (auditCard in web/src/lib/chat/audit-card.ts) and emits a new event, audit.ready.
    • This is the same path What's new (whats_new.ready) and Why (why.ready) use: the browser applies the event (run-state.ts), a reloaded chat reads it back from chat_run_events (thread.ts), and ChatThreadView draws it with the run's other cards.
    • Chat's main page, the side panel, the editor's chat and a suggestion's chat all show it.
  • A range is kept only if the rule could have produced it (asScoreRange) and the score shown falls inside it. The browser checks again, so a range a model or an older event altered isn't shown.
  • One card per audit. An audit read twice keeps one card, the newer. One answer shows at most 3, the first read, as What's new does.
  • The event carries no id. The audit's id appears only in the Open report link (href), which chatEvent already allows.
  • The card's look. It uses Chat's own card look, like the output and Action Center cards, rather than copying the Agent page's AuditResultCard. It leaves out the category breakdown and the recommendations; Open report has them.

get_site_audit gets three fields, so the card's change comes from the result, as the report's does:

  • previousScore (0–1, like totalScore) and previousCreatedAt: the page's previous audit, named as in GET /api/audits/:id. Both are null for a page audited once, and for an audit that isn't compared.
  • partial.

They come from the read the range already does (readPageComparison in web/src/lib/audit/page-trend.ts, which readScoreRange now uses), so there's no extra query. If that read fails, the audit still comes back, without them. MCP's get_site_audit, the REST twin and the Agent get them as well. The MCP and Chat tool descriptions explain them. Chat's description also tells the model that the card shows the numbers, so the answer doesn't repeat them.

Help

  • "Use Chat" gets a new section, A Site Audit in Chat, plus a few keywords.
  • "Read a site audit report" › Score range now says Chat shows the range on the audit's card.
  • approved-articles.json is refreshed.
  • docs/guides/site-audit.mdx and docs/guides/mcp-server.mdx mention the card and the new fields.

No migration: chat_run_events.type takes any event type.

Notes for review

  1. get_site_audit grows by three fields. The result had no previous score, so the card couldn't show the change the report shows. This PR adds it from the same read instead of leaving the change out. The fields are additive, so MCP clients aren't affected; the owner is fine with that.
  2. At most 3 audit cards per answer. Without a cap, a run that reads many audits (an agent going through a site) would stack one gauge per audit. The cap is MAX_AUDIT_CARDS, easy to change.
  3. Not checked in a browser or in a live Chat, since there was no local database with audits. The card, the event, the reload and the engine's emit are covered by tests.

Related issue

None. Follow-up to #2131 and #2143 (customer priorities plan, P0 item 1, score stability): the owner decided to give the new Chat an audit card.

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. In Chat, ask "How did my latest audit of /pricing go?" for a page with three or more complete audits. Under the answer, the card shows:
    • the page;
    • the gauge with "NN ± N", and the range sentence;
    • "Audited …" with "+N since …";
    • Open report, which opens the audit's report.
  2. Ask about a page with one or two audits. The card shows the score with no range. A page audited once has no change either.
  3. Ask about a partial audit. The card shows the score with the note that the AI checks couldn't run, and no range or change.
  4. Reload the chat: the cards are the same. Open the chat in the side panel: the card fits.
  5. Ask about an audit that is still running. There's no card, only the answer.
  6. MCP: get_site_audit returns partial, previousScore and previousCreatedAt.
  7. Tests: cd web && npx vitest run src/components/chat/run/audit-card.test.tsx src/lib/chat/audit-card.test.ts src/lib/chat/events.test.ts src/lib/chat/thread.test.ts src/lib/chat/engine.test.ts src/lib/audit src/lib/mcp/site-audit-range.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

The full web checks ran on a2e0d9d's tree, which is also the pushed head's tree (a092e10). The merge of main only adds #2143's squash, which the branch already had. It still merges cleanly into current main.

  • Web:
    • format changed nothing; format:check and typecheck pass.
    • lint: 0 errors. Its 7 warnings are old ones in files this PR doesn't touch.
    • yarn test: 994 files pass (10,652 tests, 1 skipped).
    • yarn build passes with CI's placeholder env.
  • Server: not touched; its tree is the same as main's.

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
…ge and range

The owner asked for a Site Audit card in the new Chat, on top of ansvisor#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
…card

main now has ansvisor#2143 squashed (e2be79b), which this branch was stacked
on; its tree matched the branch's base, so every conflict keeps the
branch's side.

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 a092e10.

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 12e5e7b 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#2146, ansvisor#2148 and ansvisor#2149. help/chat/agents.md's front matter
keeps both keyword and synonym lists; approved-articles.json regenerated;
schema.sql rebuilt.

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