Skip to content

fix(chat): read over the page's dates and filters in the side panel - #2459

Merged
gkhngyk merged 10 commits into
ansvisor:mainfrom
cihan-gyk:fix/chat-page-period-filters
Nov 18, 2026
Merged

gkhngyk merged 10 commits into
ansvisor:mainfrom
cihan-gyk:fix/chat-page-period-filters

Conversation

@cihan-gyk

@cihan-gyk cihan-gyk commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Merged with main (17 Nov): brought up to date with main at 3b4d242 (#2464, #2465, #2467, #2468, #2471–#2476, #2479–#2483) with normal merge commits. help/chat/chat.md keeps both sides' keywords, approved-articles.json is regenerated, and git merge-tree against main is clean. Adds page-route.ts, the /dashboard/prompts alias that #2463's review asked for.

Merged with main (17 Nov): brought in #2451, #2460/#2461, #2466 and the onboarding PRs; the eval files are a union (citations page-scope next to the ai-revenue scenarios, conversions_off workspace, page checks plus scenario checks).

Review fixes (16 Nov):

Summary

Step 5 of the "Chat must read everything a page shows" plan (owner, 16 Nov).

Chat beside a page now reads over the page's dates and with the page's filters, unless the question asks for something else. Before, it ignored both:

  • Dates (G1). Every read took the period named in the message, else the person's saved default (often 30 days). Overview, Citations, Prompts and AI Traffic open on 24 hours, so Chat's numbers didn't match the screen.
  • Filters (G2). Filter chips went to the model as text only. The reader rule even said to set a platform only when the person names one.

Now the server applies both, and the answer says once what it covers: "Last 24 hours, ChatGPT, as on the page: citation counts for all sources, lists for Brand sources".

The second commit applies the owner's two decisions from this PR's review: Citations' counts over every source beside its Sources-filtered lists, and Ads' period only on Ads.

Changes

  • The page's period (engine.ts runRange, range.ts pageDatesOf).
    • Order: a period in the message (or a short range like "last 7d") → the page's date chip → the saved default → the app's 30 days.
    • A page on All time reads all time, as if the person had asked for it.
    • Parts of a job read the same period, because they copy the message's scope.
  • The range card. On a page with its own dates, Chat no longer asks. It reads the page's range and keeps nothing as the person's default. A page with no date chip asks as before.
  • The composer. The person's own range chip is hidden while the page's date chip is in the box, so two different ranges never show side by side. Removing the page's date chip brings it back.
  • Ads (scope.ts, ScopeFacts.rangeFrom: message, page or default).
    • On the Ads page, get_ads_opportunities takes the page's period (7d, 30d or 90d).
    • A period the message names ("last 90 days") applies anywhere.
    • Anywhere else it reads its own 30 days, as the Ads page opens. It never takes the person's default range or another page's range.
  • The page's filters (new plain module lib/chat/page-scope.ts, called from scopeRead).
    • Platform, region and topic apply to every read of the page's brand that takes them.
    • A list's own filters (status, category, impact, type, Sources, prompt) apply only to the read of that page's list. The tool's route must be the page's route. Actions' "In progress" is not Content's "In progress".
    • Each value is checked against the input's schema. A value the read doesn't take is skipped (for example Actions' "Stale"). A chip with no matching input stays text (for example priority, or AI Traffic's platform).
    • Platform values differ by page. Visibility and Citations send model slugs (model). Mentions sends a platform id (platform). AI Traffic sends the visit's source, which no read takes. A platform chip on any other page is not mapped.
    • Citations' Sources maps own → owned, competitors → competitor, third_party → external.
  • Citations: lists by Sources, counts over every source (new plain module lib/chat/citation-totals.ts, called from the engine's read).
    • On the page, the domain and URL tables follow Sources, and so does the Unique Domains card. Total Citations and Avg citations per result count every source.
    • When list_citations took Sources from the page, the engine sets allSourcesTotals on the read's context. The read counts every source's citations in the same pass that builds the filtered lists, and puts them next to those lists as all_sources_totals (citations, avg_citations_per_result). One read, one scan.
    • The filtered lists and their totals stay as they were, so the domain and page counts match the table.
    • The person sees one read step.
    • Sources the person names themselves ("only our own sites") get no all_sources_totals, as before.
    • MCP output is the same: listCitationsFor adds all_sources_totals only when its caller asks (allSourcesTotals), and the MCP tool never does.
  • The person's words win.
    • An input the model gave stays. "" for platform, model or region means all of them.
    • A question that asks for all of a filter ("all platforms", "every region", "tüm konular") drops that chip.
    • A read that names its rows (codes, ids, domains, urls) takes no page filter.
  • Brands.
    • Page filters apply only to reads whose brand_id is the page's brand (the brand chip, which the server already sets to the run's brand).
    • If the page's posted brand isn't the run's brand, the filter chips keep their labels but lose their values (messageScopeOf), so no read gets another brand's topic.
    • The page's platform still goes through the plan check, like one the person named.
    • Every read is still scoped by brandAllowed, as before.
  • Rules.
    • Reader: the app sets the period from the page's dates, else the person's range, and applies the page's filters. The model gives a filter only when the message names one.
    • Writer: each read's scope has from_page (period, platform, sources…). The writer says once what the answer covers, as the page names it. It also names any page filter no read took ("all regions"), and never mentions row counts.
    • Writer, Citations: with all_sources_totals, citation counts and the average per answer come from it, lists from the filtered read, and the line says so ("citation counts for all sources, lists for Brand sources").
    • The <page_context> line now says the app reads over its date range and applies its filters.
  • Help. Chat › "What the panel looks at": "Chat answers for the page's dates and filters unless you ask otherwise." (148 words). "The date range Chat reads" and "Change the date range" now describe the page's range. approved-articles.json is regenerated. Ads › "Ask Chat about Ads" (119 words): Chat reads the page's period there, and 30 days elsewhere unless you name another period. That article is not approved yet, so the JSON doesn't change for it.
  • Eval. New scenario citations-page-scope: on Citations (24 hours, ChatGPT, Brand), "What are my top cited domains?".
    • It must read list_citations over the last 24 hours with model: chatgpt-web and source_filter: owned.
    • The answer must say "as on the page", and that counts are for all sources.

Page by page

Page Period it sends Filters mapped Filters left as text
Actions none (no change) category, status → list_action_center_tasks priority; status Stale
Content › Opportunities none (no change) type, impact, status → list_content_opportunities —
Prompts (all tabs) 24h by default, 7d, 30d, 90d, custom location → region on every read that takes it —
AI Traffic 24h by default, 7d, 30d, 90d, All time, custom — platform (the visit's source; no read takes it)
Mentions 30d by default, 24h, 7d, 90d, custom platform → platform; region; topic → topic_id —
Citations 24h by default, 7d, 30d, 90d, All time, custom platform → model; region; topic → topic_id; Sources → source_filter on list_citations lists, with all_sources_totals beside them prompt (no Citations read takes a prompt yet; it applies once one does)
Visibility › Overview 24h by default, 7d, 30d, 90d, All time, custom platform → model; region; topic → topic_id —
Ads (flag) 30d by default, 7d, 90d → period, on Ads only (elsewhere 30d) — —

A read that doesn't take an input keeps the chip as text. For example, get_overview_summary has no region, so on Overview the answer says "all regions".

How to test

  1. Open Visibility › Citations on its default view (Last 24 hours, Brand), pick ChatGPT, and open Chat beside it.
  2. Ask "What are my top cited domains?".
    • No date range card.
    • The read step says "Last 24 hours" and ChatGPT.
    • The answer starts with one line like "Last 24 hours, ChatGPT, as on the page: citation counts for all sources, lists for Brand sources", and its domains match the table.
    • Ask "How many citations do we have?". The number is the Total Citations card's, which counts every source, not only Brand.
  3. Ask "What are my top cited domains in the last 30 days on all platforms?". The step says "Last 30 days", with no platform.
  4. Clear your Chat date range in Settings › General. Open Visibility › Overview on Last 7 days and ask "How is my visibility?". Chat doesn't ask for a range and reads 7 days. Then open Action Center › Actions and ask the same: the range card appears as before.
  5. On Action Center › Actions, filter Category = Growth and Status = In progress, then ask "What should I do first?". Chat reads Growth, In progress actions and says so. Ask "What content opportunities do I have?": that read is not filtered by the Actions status.
  6. On Mentions with ChatGPT and a topic picked, ask "How often are we mentioned?". The read takes ChatGPT and the topic.
  7. In the panel on a page with a date chip, the "Last 30 days" range chip above the box is hidden. Remove the page's date chip (×) and it shows again.
  8. With Ads on (ADS_ENABLED=true), set your Chat range to Last 7 days. On Ads with the period on 90 days, ask "Which prompts should we pay for?": the read covers 90 days. Ask the same from Chat's own page or beside Citations: it covers 30 days. Ask "… in the last 90 days?" anywhere: 90 days.
  9. Optional, real model: cd web && SKILL_EVAL=citations-page-scope yarn vitest run src/lib/chat/agent-eval.test.ts

Checks

  • npx tsc --noEmit -p .: passes.
  • Vitest on src/lib/chat (all), src/lib/mcp, src/components/chat, src/app/api/chat, src/app/api/mcp, src/lib/help, src/i18n, use-server-exports and subscription-guard-coverage: 355 files, 4,679 tests, all pass (1 skipped: the real-model eval).
  • New tests cover:
    • each of the 8 pages' real chips: what is mapped, what stays text, and values the read doesn't take (page-scope.test.ts);
    • the model's own input winning, "" for all, and "all platforms" or "tüm konular" dropping a chip;
    • no filters on a read of another brand, with the brand chip removed, or on a lookup by codes, and filters posted from another brand's page losing their values;
    • the page's platform still checked against the plan;
    • the period order: a period in the message, the page's, the saved default; the page's custom range and All time; no range card on a page with dates; the card still shown on a page without;
    • Ads' period: the page's on Ads, a period the message names anywhere, and 30 days elsewhere even with a 7d or 90d default or another page's range;
    • Citations on one fixture, read as Chat does and as the page does (getCitationsOverview): one read and one scan of the answers; the lists equal the table's Brand rows, totals.domains equals Unique Domains, and all_sources_totals equals Total Citations and the average per answer (6 and 1.5, while the Brand-only total is 3); no all_sources_totals when nobody asked or the read is over every source;
    • the engine making one read of a page-filtered list_citations and asking it for every source's totals, not when the person named Sources, and the writer getting all_sources_totals and the scope-line rule;
    • from_page in each read's scope, and the reader, writer and <page_context> texts;
    • the composer hiding the person's range chip beside the page's date chip;
    • the eval scenario passing a read with the page's scope and a scope line, and failing one without its platform or scope line.
  • ESLint and Prettier are clean on the changed TypeScript files.
  • git merge-tree --write-tree HEAD upstream/main: clean.
  • No migration, new dependency, lockfile change or new server action. NAMED_ROWS is untouched. read-tools.ts and lib/mcp/data.ts change only for the opt-in all_sources_totals.

Known differences (fixed in #2462, which ships with this PR)

  • Citations' "Last 24 hours". The page reads it as the latest completed tracking run's day or days, from its daily rollups. On its own, this PR reads the rolling last 24 hours, so on 24h the two windows can differ. fix(chat): rank and count as the pages do #2462 reads the latest run's days.
  • Answers read for citations. On its own, list_citations aggregates the window's answers in one query, which returns at most 1,000 rows (the database API's row limit), so on a busy brand Chat's citation counts can be lower than the page's cards. fix(chat): rank and count as the pages do #2462 reads the domains and totals from the page's daily rollups instead.

Owner decisions (approved 16 Nov)

  • Citations' Sources: match the screen in both places. The domain and page lists follow Sources, as the table does. Citation counts and the average per answer count every source, as the KPI cards do. The answer says which is which.
  • Ads' period: on the Ads page only. There, get_ads_opportunities takes the page's period. Elsewhere it reads Ads' own 30 days, never the person's default range.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9

Chat beside a page now reads what the page shows (the owner's rule,
2026-11-16; step 5 of the page-data plan, gaps G1 and G2).

- Period: a period the message names wins, then the page's date chip,
  then the person's default. A page on All time reads all time. On a
  page with its own dates the range card isn't shown and nothing is
  kept as the default; the composer hides the person's range chip
  beside the page's. A read with a period input (Ads) takes the range
  when it is one of its periods.
- Filters (lib/chat/page-scope.ts, from scopeRead): platform, region
  and topic fill the reads of the page's brand that take them; a
  list's own filters (status, category, impact, type, Sources, prompt)
  only the read of that page's list. Values are checked against each
  input's schema; a chip no read takes the same way stays text. The
  model's own input wins, "" reads all, and a question that asks for
  all of a filter drops that chip. A page of another brand than the
  run's keeps its filters as words only.
- Rules: the reader is told the page's dates and filters apply; each
  read's scope has from_page, and the writer says once what the
  answer covers, as on the page, never row counts.
- Help: Chat answers for the page's dates and filters unless you ask
  otherwise.
- Eval: citations-page-scope (24 hours, ChatGPT, Brand sources).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
The owner's decisions on ansvisor#2459 (16 Nov):

- Citations: the domain and page lists follow the page's Sources, as
  its table does, and the citations and their average per answer count
  every source, as its cards do. When list_citations took Sources from
  the page, the engine runs the same read over every source beside it
  (one row, same filters and window) and puts its totals next to the
  filtered lists as all_sources_totals (lib/chat/citation-totals.ts).
  The person's own Sources read once, as before. The writer says
  counts are for all sources and lists for the chosen Sources. No
  change to lib/mcp or the read's registry row.
- Ads: get_ads_opportunities takes the page's period only on Ads, and
  a period the message names anywhere; elsewhere it reads its own 30
  days, never the person's default or another page's range
  (ScopeFacts.rangeFrom: message, page or default).
- Lookups by domains or urls take no page filter, as codes and ids.
- Help: Ads' Chat line says the period it reads.
- Eval: the Citations scenario checks the answer says its scope.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
@cihan-gyk
cihan-gyk marked this pull request as ready for review November 16, 2026 19:14

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

runRead runs list_citations twice in parallel when Sources come from the page (allSourcesInput, limit 1), but limit 1 doesn't shrink the work: readCitationAggregates still scans every prompt_results row of the window. Count the all-source totals in the same pass. Also on its own this reads Citations' 24h as a rolling now−24h while the page uses the latest run's days (#2462 fixes that), so it should ship with that fix.

cihan-gyk pushed a commit to cihan-gyk/ansvisor that referenced this pull request Nov 16, 2026
The page's search (from its view) now fills `search` on the reads of the
page's own list that take one, as ansvisor#2459 fills its list filters: as
ansvisor#2460's capped lookup words, never over the model's own search, ids or
codes, not for another brand's page, and dropped when the question asks
for all. The read's scope names it (from_page.search) and the writer
says it. In the models' page_view block every row and ref stay, each
label cut to 80 characters; the stored view's cap is now a safety net
that every 100-row view fits under.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
When Sources came from the Citations page, the engine ran list_citations
twice in parallel: the filtered read and the same read over every source
(limit 1) for the cards' totals. Limit 1 didn't shrink the work, so every
such question scanned the window's answers twice. The read now counts every
source's citations in the same pass that builds the Sources-filtered domain
and page lists, and returns them as all_sources_totals when the engine asks
(ChatToolContext.allSourcesTotals): one read, one scan. The writer's rule
and the result's shape stay as they were.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
gkhngyk
gkhngyk previously approved these changes Nov 17, 2026

@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, thanks for the fix.

gkhngyk
gkhngyk previously approved these changes Nov 17, 2026

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

Re-approving after the main merge: the PR's own changes are unchanged (numstat matches; the tools.test.ts resolution keeps both sides).

The page's own-list filters (and, above, its search) reach a read only
when the read's route is the page's. The Prompts area's base path opens
on Tracked Prompts (next.config.ts redirects it there), but it never
matched list_prompts' /dashboard/prompts/tracked. One alias map in
page-route.ts (pageRoute, samePage) now decides it for the page's
filters (page-scope.ts) and its period (scope.ts).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
help/chat/chat.md keeps both sides' keywords; approved-articles.json
regenerated from the help files.

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

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

Looks good.

@gkhngyk
gkhngyk merged commit a4dc414 into ansvisor:main Nov 18, 2026
12 checks passed
gkhngyk pushed a commit that referenced this pull request Nov 18, 2026
Stacks step 7 on both open Chat PRs (#2459 page period and filters,
#2460 lookups by name). Their eval scenarios, eval data, eval tests and
Chat help keywords are kept as a union; approved-articles.json is
regenerated.

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