Skip to content

feat(mentions): add the Mentions table and the response drawer - #1117

Merged
gkhngyk merged 15 commits into
ansvisor:mainfrom
cihan-gyk:feature/mentions-table
Oct 17, 2026
Merged

gkhngyk merged 15 commits into
ansvisor:mainfrom
cihan-gyk:feature/mentions-table

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Fourth of six PRs for Mentions & Sentiment: the Mentions tab (MS-07) and the response drawer (MS-08), read-only. Every number on the Overview now has its evidence: the answers that name the brand, each opening to the full stored answer. No LLM call: the excerpt, the name highlights and the drawer all read what tracking stored.

Stacked on #1116 → #1115 → #1114. The diff includes their commits until they merge. Please merge #1114, #1115, #1116, then this one.

The drawer's actions come in the next PR, so this one stays reviewable: Send to Action Center, Suggest content, "Sentiment is wrong" with its override, and the table's multi-select.

Data: migration 00158_mentions_list.sql

mentions_list(brand, from, to, platform, region, topic, search, sentiment, competitor, sort, group, limit, offset) returns jsonb { total, prompts, rows }. It has one row per answer naming the brand (a mention, spec §5).

  • Same window as mentions_overview (00157): the exact instants under two days, whole UTC days otherwise. The table's total is therefore the Overview's "Total mentions" for the same filters.
  • Filters:
    • the page's own: platform, country, topic, and the search over the prompt's text;
    • sentiment, where neutral is every mention that is neither positive nor negative, as in the rollups;
    • co-mentioned: a competitor named in the same answer, or none.
  • Sorts:
    • newest (the default);
    • oldest;
    • most co-mentions;
    • most negative (negative, then neutral, then positive).
  • Groups: by prompt or by platform. Each group's rows come together, the biggest group first, with the group's size on every row.
  • Paging: 100 rows per page (spec §15). Each row carries the prompt and topic, platform and model, country, date, sentiment, position and brands named, and the competitors named, in the order they appear when that is known. It also carries the answer's text, which the server uses for the excerpt and the page never receives.
  • Security: security definer, with the organization check made explicit, as in 00157. A caller outside the organization gets null. chatgpt-shopping stays out.

Web

  • lib/actions/mentions.ts:
    • listMentions reads a page and the brand's name and domains, and cuts each answer to the passage around the brand's first mention. It returns null on PGRST202.
    • getMentionResponse reads one answer's text and citations for the drawer, as the caller (RLS).
  • lib/mention-match.ts: names are matched the way tracking counts them (response-parser.js):
    • a case-insensitive whole word with Unicode boundaries;
    • ChatGPT's entity tags read as names;
    • links read as their labels; bare URLs are dropped.
    • On top of that, the excerpt is cut on whole words, and text is split for highlighting.
  • The table:
    • Columns: Prompt, Platform, Country (only when the brand tracks more than one), Mention context, Sentiment, Position (#n of m), Co-mentioned, Topic, Date.
    • The header and the Prompt column are pinned (the shared Table's sticky options, PROMPT-011).
    • The brand is marked in violet and competitors in grey.
    • The Sentiment, Co-mentioned, Group by and Sort controls live in the URL (sentiment, with, group, sort).
    • "N mentions · M prompts" shows beside the controls, and pages use the shared TablePager.
  • The drawer:
    • Header: platform and model, country, date and time, the prompt, the sentiment pill, position, topic and View prompt.
    • Body:
    • Footer: Copy response.
    • Not included: the spec's "mentions you? yes/no" per citation. Whether a cited page names the brand isn't stored, since cited pages aren't read, so the source type stands in for now.
  • Search: the search box now says it searches prompts. Both tabs match the prompt's text, so their counts agree; searching phrases inside answers can come later.

Related issue

None.

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. Apply 00157 (with its backfill, feat(mentions): add daily mention rollups and the Mentions overview read #1115) and 00158.
  2. Open Mentions → Mentions. The count beside the controls matches the Overview's Total mentions for the same filters.
  3. Click a row. Check that:
    • the drawer shows the excerpt and the competitors named;
    • the full answer has your brand marked in violet and competitors in grey;
    • the citations are typed;
    • Copy response works;
    • View prompt opens the prompt.
  4. Try Group by → Platform with Sort → Most negative. Each group opens with its name and size, negatives first. Use Next for page 2.
  5. Pick a competitor, or No competitor, under Co-mentioned. Reload: the controls come back from the URL.
  6. Check dark mode, and 1024px, where the table scrolls sideways with the Prompt column pinned.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/): no errors; the 7 warnings are in files this PR does not touch
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Also run:

  • yarn test: 914 pass, 22 of them new.

    • lib/mention-match.test.ts:
      • prose for quoting;
      • the excerpt around the first whole-word mention, cut on words and never inside a URL;
      • the fallback to the answer's start;
      • highlight segments, the longer name first.
    • lib/mentions-list.test.ts: the URL controls and the parsing of sparse rows.
    • lib/actions/mentions.test.ts:
      • the call's arguments, including the page offset;
      • the excerpt cut on the server, with no text sent to the page;
      • PGRST202, and the drawer's read.
    • mentions/_mentions-tab.test.tsx:
      • URL controls, rows and marks, group headers;
      • the drawer (header, prompt link, marks inside markdown bold and lists, typed citations);
      • a failed page keeps its place;
      • empty and custom-range states.
  • yarn build passes (with CI's Stripe placeholder).

  • bash supabase/build-schema.sh: regenerated schema.sql.

  • Dev database:

    • Rolled-back dry run, then applied. Over 30 days the total and prompts match mentions_overview (107 and 5, and 2 for the last 24h). Positive + neutral + negative = 107. The per-competitor totals equal the Overview's competitor mentions. Sorts, groups and paging check out, and a stranger gets null.

    • Timing: 30,000 synthetic answers over 90 days (12,064 mentions), as authenticated, rolled back and vacuumed. A hosted dev database, ~70 ms of network included:

      90d, newest, page 1 556 ms cold, 165 ms warm
      90d, most co-mentions 241 ms
      90d, most negative, grouped by prompt 208 ms
      90d, one competitor, page 21 180 ms
      30d 121 ms
      7d 101 ms
      24h 91 ms
  • In the browser, on the demo brand: the table, groups, sorts, paging, empty state and drawer, in light and dark, at 1440 and 1024px.

🤖 Generated with Claude Code

cihan-gyk and others added 4 commits October 17, 2026 09:13
…iment page shell

Mentions & Sentiment (MS-05) gets its sidebar item, "Mentions" with a New
pill and a speech-bubble icon, directly above Citations, its sibling
concept. Once Topics moves into Prompts, it sits between Prompts and
Citations.

/dashboard/mentions has the page's title and description, its V1 tabs
(Overview, Mentions, Perception; Sentiment and Fact-check stay hidden until
built) and the filter bar every tab shares: date range (30 days by default,
as in the mockup), AI platform, country, topic and a search over prompts,
brands and phrases. Tab and filters live in the URL, so a refresh or a
shared link restores the view. The tabs' figures and charts arrive with the
next PRs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The data layer for Mentions & Sentiment (MS-03/04), built from what
tracking already stores on each answer: mention_count, mention_position,
competitor_mentions and the answer's sentiment toward the brand. Opening
the page or changing a filter never calls an LLM.

Migration 00157 adds two daily rollups:
- mentions_prompt_daily (day x prompt x platform x region): answers, the
  answers naming the brand, occurrences, positive and negative mentions,
  and the brand's positions;
- mentions_competitor_daily: answers naming each competitor, and those
  naming the brand too.
refresh_mentions_daily rebuilds them (service role only), and
mentions_overview reads a window and the one before it, filtered by
platform, region, topic and a prompt search: under two days from the
answers, longer windows from whole UTC days. It is security definer with
the organization check made explicit.

The server refreshes the rollups with the Insights and Citations ones,
when a run stamps and in the nightly sweep, and
scripts/backfill-mentions-daily.js fills a brand's history. The web gets
getMentionsOverview, the Overview's metrics (mention rate, the sentiment
split with neutral kept, net sentiment, low sample under 20 mentions,
average position) and the filters-to-query helper.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Overview tab of Mentions & Sentiment (MS-06), as in the mockup:

- a summary line written from the aggregates by a fixed template (net
  sentiment and its change, the platform behind most of it, the
  competitors named beside you), never an LLM;
- KPI cards: Total mentions, Mention rate, Prompts with mentions and Net
  sentiment with its split and n; under 20 responses a rate is a low
  sample and shows no change;
- a daily trend with a Mentions / Mention rate / Net sentiment toggle;
- a by-platform table with the sentiment split, net and its change, and
  a note when platforms disagree;
- competitor framing: mentions, rate and same-answer counts, with
  sentiment for your brand only.

MetricCard is exported from the Insights cards and takes a footer in
place of its sparkline.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Mentions tab of Mentions & Sentiment (MS-07/MS-08, read-only V1):

- migration 00158 adds mentions_list: the answers naming the brand in
  mentions_overview's window, a page of 100 at a time, filtered by
  sentiment and by a competitor named in the same answer (or none),
  sorted newest, oldest, by co-mentions or most negative, and grouped by
  prompt or platform; security definer with the organization check;
- listMentions cuts each answer to the passage around the brand's first
  mention on the server (lib/mention-match.ts matches names as tracking
  does), and getMentionResponse reads one answer for the drawer;
- the table pins its header and Prompt column, marks your brand in
  violet and competitors in grey, and keeps its controls in the URL;
- the drawer shows the prompt, platform and model, country, date,
  sentiment, position and topic, the excerpt, the competitors named,
  the full stored answer with the names marked, and its citations typed
  as on the Citations page, with Copy and View prompt.

The search box now says it searches prompts, as both tabs do.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk the Mentions table and response drawer, the fourth of six Mentions & Sentiment PRs. It is stacked on #1116 → #1115 → #1114; please merge them in that order. On deploy, apply 00158 after 00157 and its backfill. The drawer's actions (Send to Action Center, Suggest content, sentiment override) follow in the next PR.

@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 17, 2026
mentions_list joined the answers to the brand's prompts first, and the
planner walked each prompt's whole history: 8.8 s for 30 days of the
largest brand, past the 8 s timeout, so the table failed on its default
range. It now reads the window's mentions first, through a partial index
on mention_count > 0, then joins the prompts: 1.8 s for 30 days, 2.9 s
for 90.

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

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

Reviewed. Migration 00158 is applied to production. Added one commit: mentions_list joined the answers to the brand's prompts first and the planner walked each prompt's whole history, 8.8 s for 30 days of the largest brand (past the 8 s timeout on the default range). It now reads the window's mentions first through a partial index on mention_count > 0 (built on production with create index concurrently) and joins the prompts after: 24h 0.27 s, 30d 1.8 s, 90d 2.9 s, as an authenticated member; a user of another organization gets null.

@gkhngyk
gkhngyk merged commit 97f29cb into ansvisor:main Oct 17, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants