Skip to content

feat(chat): give Chat the page context on every page, the pages of one item included - #2470

Merged
gkhngyk merged 49 commits into
ansvisor:mainfrom
cihan-gyk:fix/chat-context-detail-pages
Nov 18, 2026
Merged

gkhngyk merged 49 commits into
ansvisor:mainfrom
cihan-gyk:fix/chat-context-detail-pages

Conversation

@cihan-gyk

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

Copy link
Copy Markdown
Collaborator

Merged with main (17 Nov): merged #2463 and then main at 3b4d242, which now holds #2465 (fix/chat-today-agents-reads), so #2465 came in with main and not on its own. page-scope.ts keeps this branch's brandless, tab and path filters plus the alias and as_listed. The help keywords and paragraph are combined, under the 150-word section limit. brand-scope.test.ts keeps main's import order, and approved-articles.json is regenerated. git merge-tree against main is clean.

Review fixes (17 Nov)

  • The KPIs read a year at most. getActionCenterKpisFor (web/src/lib/mcp/action-center-reads.ts) used to take a period of any length, such as 2015 to today. A period longer than 365 days (KPI_PERIOD_MAX_DAYS) now keeps its last 365, as the Why read keeps its last 92 days and Prompts its last 90. The result's note says what was asked and what was read, and the Chat tool description says so too (registry/action-center.ts). Tests in web/src/lib/mcp/chat-reads.test.ts: a 10-year request reads 2025-11-17 to 2026-11-16, with the note. 90 days, and exactly 365, are read as asked, with no note.
  • The page-search and /dashboard/prompts fixes from fix(chat): read the page's view: tab, sort, search and the rows on screen #2463 come in with the merge. pageFilterInputs keeps this branch's brandless reads and tab and path filters, plus the alias and as_listed. The order lines for History and Agents now say the app applies the search only where it does (page-order.test.ts).

Merged with main (17 Nov): includes the updated #2463, #2464 and #2465 and main; resolved as union, model-eval rows 38 (competitor losses) and 39 (Today) as in #2465.

Stacked on #2463 (→ #2462 → #2459), #2464 and #2465, merged together with #2466 (now merged into main) in commits 09e0af6d1, d0b388425 and c64dc30ec, on #2463's head 9dc1a518a. Until they land, this diff also shows their commits. This PR's own changes are commits d9ae7f9b2 (the merged base's tests), c81f53eea (step 9: the pages that sent no context) and f4f7d3c16 (the detail pages).

Summary

Step 9, the last step of the "Chat must read everything a page shows" plan (owner, 16 Nov): every page that sent no context now does, the pages of one item (its id in the path) included.

Until now, 13 pages and the Topics tab told the side panel nothing but their menu name and the brand. Chat didn't know the page's dates or filters, which rows were on screen, or which item was open. So "bunlar ne?" on Signals or "bu rakibe karşı nerede kaybediyoruz?" on Competitors was answered from a list read in its own order, or from another competitor.

Now each of these pages calls useChatPageContext the way #2463's 8 pages do. It sends its name, its date chip, its filter chips and its view: tab, sort, search, the rows on screen by the code the page shows (AC-n, S-n), else an id, a domain, an address or a key, plus the list's total and the item it holds open. Every value comes from what the page already holds. Nothing is read again in the browser.

On the server, each new page is wired the way #2459, #2462 and #2463 wired the first 8:

  • its URL keys are whitelisted;
  • its rows keep only the ref kinds a read can look up, and the reader is told which read takes each kind;
  • its filters fill its own list's read;
  • its chosen sort maps to the read's sort input.

Two reads gained the inputs the pages need: list_signals now takes category, impact and source, and get_action_center_kpis takes the period.

Detail pages. The pages of one item told Chat nothing either: a topic's page, a prompt's, a saved report, a Site Audit report, a product's page, a content opportunity's and an AI answer's. So "bu konuda en zayıf promptumuz hangisi?" on a topic's page was answered over every topic. Now each sends its name, its dates where it has them, the item it shows (its id and title) and the rows it lists that a read can look up. The server takes the item from the path, never from the browser's view: "this topic", "this report" or "this product" is the one the URL names, read with the read that takes its id. On a topic's page the topic is the page's topic filter: the app fills topic_id on its brand's reads, as a topic chip does.

Changes

  • Pages (table below): one useChatPageContext each. Where a list keeps its own state (Agents' list, the Products table, the Topics table), it hands its part up with an onChatView callback, as Prompts › Tracked does in fix(chat): read the page's view: tab, sort, search and the rows on screen #2463. Today's Since yesterday and Waiting for you hand up their rows the same way (onSignals, onRows). No rows or total are sent while a list is loading. Library's list computations moved above its "no brand" return, unchanged, so the hook runs on every render.
  • ChatPageContext.view.open (lib/chat/page-view.ts): an item the page holds open outside its URL, { ref?, label }. These are Products' product drawer (a product AI showed, known by its title only), an agent's page, and the competitor's name beside ?competitor=. viewPage() maps /dashboard/agents/<uuid> to /dashboard/agents/[id] for the per-page tables.
  • URL keys (PAGE_QUERY_KEYS): Signals, History, Competitors, Products (tab), Site Audit (tab), Library and Plan (days), as each page writes or reads them. Today, KPIs, Review, Agents and Reports keep no state in the URL.
  • Ref kinds per page (lib/chat/page-view-scope.ts, PAGE_REFS):
    • A row whose ref is a kind no read of that page takes is dropped on the server: an action's code on Signals, a domain on Library, any row of a cited page.
    • The reader's rows rule lists that page's own lookups, e.g. "S- codes with list_signals codes; ids with list_signals ids".
    • A new key ref kind (ai_visibility, citation_gap) is taken only where the page lists it: KPIs and History's Scorecard.
    • The first 8 pages keep fix(chat): read the page's view: tab, sort, search and the rows on screen #2463's rule and kinds.
  • Open items:
    • From the URL: Signals' drawer (?signal= → list_signals ids) and Competitors' competitor (?competitor= → get_competitor_head_to_head competitor_id, with its name).
    • From the view: Products' drawer (→ get_shopping_visibility by product_title) and an agent's page (→ list_agent_runs agent_id).
    • Each is a line in the untrusted block, e.g. open: competitor <id> — Acme CRM, and the note says "this one" is that item.
  • Filters (lib/chat/page-scope.ts):
    • New list filters priority, source and card, applied only on the page's own list, as status and category are.
    • Products' platform (an AI shopping channel) fills only Products' own reads; a cited page's platform fills list_citations' model, as Citations' does.
    • Agents' tab fills list_my_agents' view. That read has no brand, so a brand-less read takes its own page's list filters, never a platform, region or topic.
    • "All agents", "all actions" and "all products" drop the page's search, as "all prompts" does.
  • Order (lib/chat/page-order.ts): Signals, History, Agents and the Topics table. Each read already lists in its page's default order, so the line comes only once a sort or search is chosen:
    • History's Oldest and Priority map to get_action_history's sort, and its search to its search.
    • Agents' search maps to list_my_agents.
    • On Signals, the line says the search is the page's own (rows by code).
    • Topics' columns other than Visibility stay words, and its rows are read by their refs.
  • Reads: list_signals takes category, impact and source (source matches a signal with that source among its sources, as the page's filter does). get_action_center_kpis takes date_from and date_to and reads the KPIs over those whole UTC days, as the KPIs page's range does. Without both, each KPI uses its own timeframe, as before.
  • Help: Chat › "Numbers that match the page" gets one sentence: "This works on every page, from Today and Signals to Products, Site Audit, the Library, Reports and a cited page: Chat knows the page, its dates, its filters and its rows, and "this one" is what you have open, such as a competitor or an agent." The page-search list now names History and Agents. The section is 148 words. Keywords were added and approved-articles.json was regenerated.
  • en.json: chatPanel.pageNames.citedPage ("Cited page"), the cited page's chip.
  • Eval: two scripted scenarios (below), with a new pageOpen check (readOpenItem) and a head-to-head in the eval data.

Detail pages (commit f4f7d3c16):

  • Pages (table below): a topic's page, a prompt's, a saved report, a Site Audit report, a product's page, a content opportunity's (/content/[id]) and an AI answer's (/insights/[id]) each call useChatPageContext with view.open = the item (its id, its title). A content opportunity's page gets the title from OpportunityDetail through a new onOpportunity prop, since the same panel also opens in Content's drawer, whose page sends its own context. The topic page's prompt roll-up moved above its early returns, unchanged.
  • Which page a path is (lib/chat/page-view.ts): viewPage() maps each of these paths to its pattern (/dashboard/prompts/topics/[id]), and a new viewPathId() gives the id. A product's page keeps prompt and platform from its URL (the shelf its "Why not you?" opened on); the others keep no URL state.
  • The open item from the path (lib/chat/page-view-scope.ts, PATH_OPEN): on an item's own page, the open item is the path's id, with the view's title only when the view names that same id. An agent's page moved here too. The note tells the reader the read: get_topics_overview and get_prompt_performance with topic_id; get_prompt_performance with prompt_ids; get_report; list_site_audit_issues; get_product_ai_says; get_content_opportunity; get_mention.
  • Rows per page (PAGE_REFS): a topic's prompts by id (→ get_prompt_performance prompt_ids); a prompt's Top Sources by domain (→ list_citations domains) and its content opportunities by id (→ get_content_opportunity); a Site Audit report's checks that fail or warn, by their keys (→ list_site_audit_issues, its check with that key). A key ref may now hold dashes (json-ld-validity), each word starting with a letter, so ac-12 is still none. A saved report, a product, a content opportunity and an AI answer send no rows.
  • The path's id as a filter (lib/chat/page-scope.ts, PATH_FILTERS): a topic's page is its topic's filter, so its id fills topic_id on every read of the page's brand that takes one, unless the model gave its own or named rows; "all topics" / "tüm konular" drops it.
  • Another brand's page (engine.ts messageScopeOf): a message from an item's page of another brand than the run's keeps the page's pattern for its path, so its item's id reaches neither the reader nor a read.
  • Help: the sentence now reads "This works on every page, from Today and Signals to the page of one product, topic, prompt, report or Site Audit: Chat knows the page, its dates, its filters and its rows, and "this one" is what you have open, such as a competitor or that topic." The section is 149 words. Keywords were added and approved-articles.json was regenerated.
  • en.json: chatPanel.pageNames.prompt, siteAuditReport and aiAnswer, the chips of the pages whose own title is long or none.
  • Eval: a scripted scenario, topic-page-weakest (below). The eval data's get_prompt_performance now takes topic_id and order.

Page by page

Page page name dates filters → read input tab / sort / search rows (ref → read) open item URL keys
Action Center › Today Today – – – Focus cards: AC code; Since yesterday: S- code, else id; Waiting: due actions by AC code, a draft by id; each label starts with its part ("Today's focus: …") → list_action_center_tasks codes, list_signals codes or ids, list_drafts ids – none
Signals Signals 7d / 30d / 90d window category, impact, status, source → list_signals; platform as words search (no read takes it: rows by code) S- code, else id → list_signals ?signal= → list_signals ids range, category, impact, status, source, platform, q, signal
History (+ Scorecard) History 7d / 30d (Scorecard 90d) / all status, Type (as category), priority, source → get_action_history tab actions / scorecard; sort Oldest, Priority → sort; search → search AC code → list_action_center_tasks codes; Scorecard by kind (key) → get_action_scorecard – view, range, status, type, priority, source, sort, by, q
KPIs KPIs 7d / 30d / 90d → get_action_center_kpis category, status as words – KPI key → get_action_center_kpis – none
Review Needs review – – – review id ("AC-12 · title") → list_task_reviews – none
Agents Agents – – tab Mine / Workspace / Paused / Archived → list_my_agents view; search → search agent id → list_agent_runs agent_id – none (state in the page)
An agent (/agents/[id]) its name – – the runs' filter as tab none (runs carry no id a read takes) the agent → list_agent_runs agent_id none
Competitors Competitors 7d / 30d / 90d / all / custom – – competitor id ("Name (domain)") → get_competitor_head_to_head competitor_id; a domain → competitor ?competitor= with its name → get_competitor_head_to_head preset, from, to, competitor
Visibility › Products (/shopping) Product Visibility 7d / 30d / 90d / all (the shopping reads' days) platform → get_shopping_shelf, list_shopping_cards platform (own list); region → region tab shelf / categories / products / readiness / competitors Products tab: catalog product id → get_product_ai_says, list_catalog_products product drawer, by title → get_shopping_visibility tab
Site Audit Site Audit the trend's 7d / 30d / 90d / all – tab pages / opportunities Pages: the audit each row opens; Opportunities: its last audit (not audited yet: left out) → list_site_audit_issues audit_id – tab
Content › Library Library – the tab as status → list_drafts; created, made in, last send, shopping as words tab draft id → list_drafts ids – tab, created, madeIn, sent, shopping, action
Content › Plan Content plan 7 / 30 / 90 days → get_content_plan days card → get_content_plan card; page type as words – opportunity id → get_content_opportunity; else the page's address → its get_content_plan row – days
Reports Reports – – – report id ("title (from – to)") → get_report – none
Prompts › Topics tab (#2463's Prompts context) (#2463's) (#2463's) sort once not Visibility, highest first topic id → get_topics_overview – (#2463's)
Citation URL page Cited page 24h / 7d / 30d / 90d / all / custom platform → list_citations model; region → region – none ?u= → list_citations urls (#2463) (#2463's)
A topic (/prompts/topics/[id]) its name all time, as the page reads it the path's topic → topic_id on every read of its brand that takes one – the prompts it ranks (Top performers, Needs improvement), each once, best first → get_prompt_performance prompt_ids the topic → get_topics_overview, get_prompt_performance topic_id none
A prompt (/prompts/[id]) Prompt 24h / 7d / 30d / 90d / all / custom – – Top Sources (the Domains table's first page): domain → list_citations domains; content opportunities: id → get_content_opportunity the prompt → get_prompt_performance prompt_ids none
A saved report (/reports/[id]) its title the days it covers – – none (a snapshot: get_report reads it whole) the report → get_report none
A Site Audit report (/audit/[id]) Site Audit report – – – checks that fail or warn, in the report's order: key → list_site_audit_issues the audit, named by its page → list_site_audit_issues audit_id none
A product (/shopping/products/[productId]) its title the 30 days it reads – – none the product → get_product_ai_says product_id prompt, platform
A content opportunity (/content/[id]) its title – – – none the opportunity → get_content_opportunity none
An AI answer (/insights/[id]) AI answer – – – none the answer, by its prompt and platform → get_mention id none

Safety

  • The view is untrusted browser data and is never used for authorization. Refs only reach reads the model calls, and every read still checks brandAllowed, filters by brand_id and joins the organization. The new open item goes through the same checks as a row: its ref must be the page's kind, its label is cut, cleaned of hidden text and withheld when it reads like an instruction. It is dropped with the rows when the view comes from another brand's page.
  • On an item's own page the item is the path's id, never the view's: a view naming another id loses its title. The path is browser data too: its id only fills topic_id on reads of the run's own brand (which filter by brand_id), and from another brand's page the path keeps its pattern only, so the id reaches no read and no prompt.
  • The inputs filled from the page are the page's own list filters, tab and search on its own list's reads, as fix(chat): read over the page's dates and filters in the side panel #2459 and fix(chat): read the page's view: tab, sort, search and the rows on screen #2463 fill them. They are checked against each input's schema, never over the model's own input, dropped when the question asks for all, and never on another brand's read. A brand-less read (list_my_agents) takes its own page's list filters only.
  • list_signals' new filters are fixed enums, passed as query values (eq, contains), never as text in a filter string.
  • No row counts to users: totals go to the models only, under fix(chat): read the page's view: tab, sort, search and the rows on screen #2463's writer rule.
  • Performance: no new fetch in the browser. Today's parts hand up what they already read, and every page reuses its own state. No new server read pages prompt_results: list_signals adds three filters to its one query, and the KPI read passes the period to the page's own function.
  • Performance: the detail pages send what they already read. No new fetch in the browser, no new server read.
  • No migration, no new dependency, no lockfile change, no 'use server' file changed. chat-thread-view.tsx, page-pane.tsx, page-open.ts, the content editor folder and the Action Center site-type files (lib/action-center/play.ts, components/action-center/play-section.tsx) are untouched.

How to test

  1. Action Center › Signals, filter Category: Visibility. Open Chat and ask "bunlar ne?". The step reads Signals by the S- codes on screen, and the answer names each signal by its title and code. No other signal is named.
  2. Same page: open a signal's drawer and ask "bu sinyal neden önemli?". Chat reads that signal by its id.
  3. Competitors: pick a competitor, then ask "bu rakibe karşı nerede kaybediyoruz?". Chat reads the head-to-head for that competitor and names the prompts where it is ahead.
  4. Today: ask "Since yesterday'deki değişiklikler ne?". Chat reads the S- codes Since yesterday shows. Then ask "ilk kartım ne?": Today's first focus card (fix(chat): read Today, your agents and their runs, History over a range, and the Signals summary #2465).
  5. History: set Status Completed, Type Recover, Sort Oldest, search "pricing", then ask "Bunlar ne sonuç verdi?". The step reads History with those filters, that sort and that search, and the answer says "matching "pricing", as on the page". Switch to Scorecard and ask "Hangi işler işe yaradı?".
  6. KPIs on Last 7 days: ask "Hedeflerimizi tutturuyor muyuz?". The KPIs are read over the last 7 days.
  7. Agents, Paused tab: ask "Bunlar neden durdu?". Chat reads your paused agents. Open an agent and ask "Son çalışmaları nasıl geçti?". Chat reads that agent's runs.
  8. Visibility › Products, Products tab: ask "Bu ürünlerden hangisi hazır değil?". Without a catalog, open a product's drawer and ask "AI bu ürün hakkında ne diyor?": Chat reads it by its title.
  9. Content › Library, In review tab: ask "Bunlardan hangisi en eski?". Chat reads the drafts in review.
  10. Content › Plan: click Protect and ask "Bunlar neden önemli?". Chat reads the plan's Protect card.
  11. Reports: ask "Ekim raporu ne diyor?". Chat reads that report.
  12. Prompts › Topics: sort by Mentions and ask "İlk 3 konu hangileri?". Chat answers with the table's first three, by their ids.
  13. Citations › URLs: open a cited page and ask "Bu sayfayı hangi promptlar alıntılıyor?". Chat reads that address with the page's period and platform.
  14. A topic's page (Prompts › Topics, click a topic): ask "bu konuda en zayıf promptumuz hangisi?". The step reads get_prompt_performance with that topic's topic_id (the step's scope says it came from the page), and the answer names one of that topic's prompts. Then ask "tüm konularda en zayıf prompt hangisi?": no topic_id.
  15. A prompt's page: ask "bu prompt nasıl gidiyor?". Chat reads it with prompt_ids over the page's range. Switch to 7d and ask again: over 7 days. Ask "bu kaynaklar ne kadar alıntılanıyor?": Chat reads the Top Sources' domains.
  16. A saved report (Reports, open one): ask "bu rapor ne diyor?". Chat reads it with get_report and says its dates.
  17. A Site Audit report: ask "bu sorunları nasıl düzeltirim?". Chat reads that audit with list_site_audit_issues and names the failing checks.
  18. A product's page (Products › Products, open one): ask "AI bu ürün hakkında ne diyor?". Chat reads get_product_ai_says with that product's id.
  19. A content opportunity's page (/dashboard/content/<id>) and an AI answer (a prompt's run › Open full page): ask "bu ne?". Chat reads get_content_opportunity or get_mention with that id.
  20. Another brand: on a topic's page, switch the brand at the top and ask in the same chat: no topic_id from that page.
  21. DevTools: on each page, check the run request's context.view (rows, total, tab, open) and its URL keys.
  22. Optional, real model: cd web && SKILL_EVAL=signals-page-view,competitor-open-losses,topic-page-weakest yarn vitest run src/lib/chat/agent-eval.test.ts.

Checks

  • The merged base: npx tsc --noEmit -p . passed on the base. The check set (below) found 3 failing tests: two period tests from fix(chat): read what the MCP Server already reads, and keep the two in step #2464 and fix(chat): read the Topics table, Query Fan-outs, a competitor head to head, Overview's map and Opportunities, AI bots and Search Console pages #2466 that predate fix(chat): rank and count as the pages do #2462's rolling Prompts and AI Traffic windows, and model-eval's row list after the renumbering. d9ae7f9b2 fixes them; nothing else changed.

  • npx tsc --noEmit -p . passes.

  • Vitest passes: 620 files, 7,952 tests (1 skipped: the real-model eval). The set is src/lib/chat, src/lib/mcp, src/components/chat, src/app/api/chat, src/app/api/mcp, src/components/action-center, src/lib/action-center, src/components/content, src/components/audit, src/lib/help, src/i18n, use-server-exports, subscription-guard-coverage, and every dashboard page's tests (src/app/[locale]/(dashboard)/dashboard, the content editor's included).

  • New and extended tests:

    • Pages: Today (each part's rows by code, labelled by part, none while reading); Signals (new page.test.tsx: window, filters as the reads name them, search, S- codes else ids, none while reading); History (range, filters with Type as category, sort, search, rows by code, Scorecard by kind and none by play); KPIs, Review, Agents' list (tab, debounced search, tab count), an agent's page (open by id, runs' filter), Competitors (period, rows, the open competitor), the Products page and table, Site Audit (Pages by audit id, Opportunities by last audit), Library (tab as status, none for Archived), Plan (days, card, rows by opportunity id or address), Reports, the Topics tab (sort only off the default, rows in the table's order), a cited page (new page.test.tsx).
    • page-view.test.ts: every new route keeps only its keys (token, code, next, utm_source dropped); pages with no URL state keep none; viewPage for an agent's path.
    • page-view-scope.test.ts: ref kinds kept and dropped on each new page; the first 8 unchanged and never taking a key; each page's own lookups in the rows rule; the open items (URL and view), their block lines and notes; a wrong-kind or out-of-place open item dropped; an instruction-like label withheld; another brand's view keeps its tab only.
    • page-scope.test.ts:
      • History's and Signals' filters and search reach their own read only.
      • Library's status reaches list_drafts, Agents' tab and search reach list_my_agents (none for "all my agents", a tab the read lacks, or no brand chip), Products' channel reaches only its own reads, Plan's card reaches get_content_plan, and a cited page's platform maps to model.
      • The model's own input wins, and "all …" drops the page's value.
    • page-order.test.ts: silent at each default; History's sort and search; Signals' search; Agents' search; the Topics columns.
    • Reads: signal-page.test.ts (category, impact, source) and chat-reads.test.ts (the KPI period, and none without both days).
    • Eval: signals-page-view and competitor-open-losses on the scripted model, each with a passing run and a failing one ("these" from the newest page; another competitor's head-to-head); the scenarios' data and the readOpenItem check.
    • Detail pages:
      • Pages: a topic's (new page.test.tsx: open by id, all time, its ranked prompts each once, best first; none while reading or after a failed read), a prompt's (new: open, range and its changes, the first 10 Top Sources and the opportunities; none of them while reading), a saved report's (open, its days, no rows), a Site Audit report's (new: open by its page, failing and warning checks in the report's order; none while it runs), a product's (open, 30 days; none while reading, not in the catalog or without Product Visibility), a content opportunity's (new) and OpportunityDetail's onOpportunity, an AI answer's (new).
      • page-view.test.ts: each item page's pattern and id; lists, words, deeper paths and the Content Editor are none; a product's page keeps prompt and platform, the others no URL key.
      • page-view-scope.test.ts: each item page's open item, block line and note; another id's title dropped and the path's id kept; each page's row kinds and lookups; a key with dashes, never ac-12; another brand's item page keeps its pattern, no open item and no filter.
      • page-scope.test.ts: a topic's page fills topic_id on the reads that take one (not get_topics_overview); never over the model's own topic, a lookup by ids, another brand's read, or "all topics" / "tüm konularda"; a topic chip wins over the path; no other item's page fills anything, so a prompt's page never makes a ranking a lookup.
      • Eval: topic-page-weakest on the scripted model: the model gives no topic, the server fills the path's, and the answer names the topic's weakest prompt; the run that reads another topic fails. Its data: the topic's weakest isn't the brand's.
  • ESLint shows no error on any changed TypeScript file, and no warning on a changed line (one warning stays on the Site Audit report page's existing poll clean-up, line 118, as on main); Prettier is clean.

  • git merge-tree --write-tree HEAD upstream/main (95aa9c4f7, which includes fix(chat): read the Topics table, Query Fan-outs, a competitor head to head, Overview's map and Opportunities, AI bots and Search Console pages #2466 and feat(chat): customers and revenue from AI visits, with the setup each answer needs #2451) has 5 conflicts, the same as before the detail pages, all already present in the stacked PRs:

    This PR adds its scenarios beside fix(chat): read the page's view: tab, sort, search and the rows on screen #2463's in the same files.

  • No migration, no new dependency, no lockfile change, no 'use server' file changed.

Not in this PR

  • Pages with an id in their path that send no context: a brand's own settings pages (/brands/[id]/prompts, /topics, /settings: their id is a brand, which the brand chip already carries), an agent's edit form (/agents/[id]/edit: a form; the agent's page sends it), Chat's own pages (the panel is off there), and the paths that only redirect (/topics/[id], /action-center/actions/[id] and /code/[ref]). /settings/[section] holds no item.
  • Rows a detail page shows that carry no ref a read takes, or that a read would read as today's:
    • a saved report's sections (a snapshot: its prompts read by id would be today's figures, so get_report reads it whole);
    • a product's shelves (questions on a channel: no shopping read takes them; the product is open);
    • a prompt's runs by platform (only the groups opened show them), its Top Sources' URLs and the Top Sources' own filter box (the first page of Domains, unfiltered, is sent).
  • A prompt's page doesn't fill prompt_ids by itself (see Choices made).
  • Filters no read takes stay words; the rows on screen are read by their refs:
    • Signals' platform and search;
    • KPIs' category and status;
    • Library's created, made in, last send and shopping filters;
    • Plan's page type.
  • Rows that carry no ref a read can look up:
    • Products' Shelf, Categories, Readiness and Competitors tabs send their tab only.
    • Site Audit's pages not audited yet are left out of the Opportunities rows.
    • An agent's runs (list_agent_runs gives no run id).
  • Mentions' response drawer (from fix(chat): read the page's view: tab, sort, search and the rows on screen #2463) still isn't known.
  • Conflicts with upstream/main: the stacked PRs already conflict with it (see Checks). They are resolved as each one lands.

Choices made

The owner accepted step 9's choices; the detail pages add the last five. The owner can change any of them:

  • Two reads gained inputs, so the pages' filters are real: list_signals takes category, impact and source, and get_action_center_kpis takes the period. Signals' platform and search stay words: the page matches them on texts it composes in the browser.
  • A key ref, for rows a page names by a key (a KPI, a kind of action). It is taken only on KPIs and History's Scorecard, so a stray word is never a ref on the other pages.
  • view.open, for an item a page holds open outside its URL: Products' drawer by its title, an agent's page, and the open competitor's name.
  • Today's rows carry their part in their label ("Today's focus: …", "Since yesterday: …", "Waiting for you: …"), so "my first card" and "the changes" are told apart.
  • Agents' tab is applied to list_my_agents' view, the way a page's search is applied (dropped for "all my agents"). It is the one brand-less read that takes a page's list filters.
  • History and the Topics table send their sort only once it isn't the page's default, which is already the read's order.
  • The merged base: with fix(chat): rank and count as the pages do #2462's page periods, the reads fix(chat): read what the MCP Server already reads, and keep the two in step #2464 and fix(chat): read the Topics table, Query Fan-outs, a competitor head to head, Overview's map and Opportunities, AI bots and Search Console pages #2466 add on Prompts (locations, the Topics tab) and on AI Referral Traffic (bots, Search Console pages) cut a preset as those pages do: the last N × 24 hours to today. Their tests were updated in d9ae7f9b2, and eval row 38 of fix(chat): read the Topics table, Query Fan-outs, a competitor head to head, Overview's map and Opportunities, AI bots and Search Console pages #2466 is now row 39.
  • An item's own page takes its item from the path, never from the view: the view only adds its title when it names the same id. An agent's page moved to this rule.
  • A topic's page is its topic's filter, as a topic chip: its id fills topic_id on every read of its brand that takes one (prompts, visibility, mentions, citations, competitors), dropped for "all topics". Its prompts are sent best first, each once, without their list's name: with 5 prompts or fewer both lists hold the same ones.
  • A prompt's page doesn't fill prompt_ids: that input makes the read a lookup of that prompt alone, so "our best prompts" asked there would come back with one. The reader is told to read it with prompt_ids.
  • A saved report and a product's page send their dates (the report's days, the product's 30), so a question that names none reads what the page shows; the report itself is read whole with get_report.
  • A Site Audit report's checks are key refs, which may now hold dashes (json-ld-validity): it is the third page that takes keys, beside KPIs and History's Scorecard. Each word starts with a letter, so a code written in lower case (ac-12) is still none.

🤖 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
Stacks step 7 on both open Chat PRs (ansvisor#2459 page period and filters,
ansvisor#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
Step 7 of the "Chat must read everything a page shows" plan: Chat's
numbers and "top" lists equal the screen's.

- Counts past 1,000 answers: the citations scan, the visibility
  summary's raw window and a product's appearances read the window a
  page at a time, newest first, up to 50,000 answers (answer-pages.ts).
  Past that the note says what the counts cover, never a row count.
- Last 24 hours as the page reads it: on Overview and Citations reads,
  the latest completed tracking run's days (the pages' own
  getTrackingWindow, with the service role after brandAllowed); the
  rolling 24 hours before a first run. Prompts and AI Traffic read a
  preset as the last N x 24 hours, as their pages do (page-periods.ts).
- Prompts: get_prompt_performance gives each prompt's AI Visibility
  Score and Coverage, as the Prompts table (the page's own read, or the
  same sums over a platform's answers) and ranks by it by default;
  avg_visibility stays, sorted by "answer_score", and is labelled.
- The page's default order: Actions can read every status, most
  recently updated first (the list's tie-break too); Content
  Opportunities take the page's Sort (newest, score, oldest). The
  models get the page's order beside <page_context>; "what should I do
  first" keeps priority, and the writer says which order a list is in.
- explain_change compares the run's period (the page's, else the
  person's range) with the days before it, as the pages compare a
  change, to yesterday; Last 24 hours keeps its 7 against 7.
- get_visibility_trend returns every day of its period, compact, within
  its share of the run.
- Help: "Numbers that match the page"; "Why a number changed" says its
  new default. approved-articles.json regenerated.
- Eval: prompts-page-top ("What are my top 5 prompts?" on Prompts).

No migration. MCP output is unchanged but for additive fields.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
The side panel now sends what the page shows beyond its chips: the open
tab, the sort and search picked, the rows on screen by the code or id the
page shows, the list's total, and the page's own URL state (whitelisted
per page). The engine checks it again (cut, never refused), keeps it on
the message, and gives it to both models in an untrusted page_view block
with the rule to read those rows by their refs before saying anything.
The page's chosen sort replaces its default in the order line, and a
search goes into the read's search input. send() in chat-thread-view.tsx
posts the view, with the owner's permission for this plan.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
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
The maintainer's review: readAnswerPages paged prompt_results by offset,
four pages at once up to 50,000 rows of jsonb, under the visibility
summary (also the external MCP tool), the citations reads, product
visibility and the prompt scores. It is gone.

- Citations (list_citations and the domain/page lookups): over whole UTC
  days the domains, citations and answers come from the Citations page's
  own daily rollups (00118: citations_domains_daily and
  citations_window_stats_daily). They are security invoker over the rollup
  tables, so the service role runs them after the brand check, by brand.
  Every source's totals come from the same rows. The pages and the prompts
  citing them have no aggregate the service role may run
  (citations_urls_daily and citation_url_occurrences refuse it), so they
  come from one bounded request of the newest answers, never paged; the
  result says what that covers when the window holds more.
- Visibility summary inside a day: the raw aggregates the page reads
  (competitor_aggregates, ai_visibility_aggregates, visible_prompt_stats,
  tracked_prompt_count), no answer rows. Whole days keep the rollups. The
  MCP output keeps its shape.
- Product visibility: the Products page reads cards itself, so one bounded
  request with an exact count: every appearance counted, the breakdowns of
  the newest read, said when cut.
- Prompt scores: always the Prompts page's prompt_visibility_summaries. It
  takes no platform, and the page counts every platform's answers, so the
  plan's platforms no longer send Starter to a raw read.
- Visibility order: the Prompts table's own comparator, a prompt with no
  score counted as 0, an unscored one last.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
# Conflicts:
#	web/src/lib/chat/registry/read-tools.ts
# Conflicts:
#	help/chat/chat.md
#	web/src/lib/help/approved-articles.json
#	web/src/lib/mcp/brand-scope.test.ts
# Conflicts:
#	web/src/lib/chat/registry/tools.test.ts
#	web/src/lib/chat/testing/model-eval.ts
…erge

The merged base runs ansvisor#2462's page periods over the reads ansvisor#2464 and ansvisor#2466
add: Prompts › Tracked's locations, the Topics tab, and AI Referral
Traffic's bots and Search Console pages cut a preset as their pages do (the
last N × 24 hours to today), and the eval set now has rows 38 (Today's first
action) and 39 (losses to a competitor). Their tests say so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
Step 9 of the owner's "Chat must read everything a page shows" plan.
Today, Signals, History (and its Scorecard), KPIs, Review, Agents and an
agent's page, Competitors, Products, Site Audit, Library, Plan, Reports,
the Topics tab and a cited page now tell the side panel their name, date
range, filters and view: tab, sort, search, the rows on screen by the
code each shows (else an id, a domain, an address or a key) with the
list's total, and the item held open. Each from what the page already
holds; no list sends rows while it loads.

The server wires each page as the first 8: its URL keys whitelisted; its
rows kept only for the ref kinds a read looks up, and the reader told
which read takes each; the open item from the URL (?signal=,
?competitor=) or the view (Products' drawer by title, an agent's page);
its list filters (priority, source, card, Products' channel, Agents'
tab) on its own list's read only; its chosen sort mapped to the read's.
list_signals takes category, impact and source, and
get_action_center_kpis the period. Two scripted eval scenarios: "bunlar
ne?" on Signals reads the S- codes on screen; "bu rakibe karşı nerede
kaybediyoruz?" on Competitors reads the open competitor's head-to-head.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
Step 9 of the owner's "Chat must read everything a page shows" plan, for
the pages whose item is in their path: a topic's page, a prompt's, a
saved report, a Site Audit report, a product's page, a content
opportunity's and an AI answer's. Each now sends its name, its dates
where it has them, the item it shows (view.open: its id and title) and
the rows it lists that a read looks up: a topic's ranked prompts by id, a
prompt's Top Sources by domain and its opportunities by id, a Site Audit
report's failing and warning checks by key. Each from what the page
already holds; nothing is read again in the browser.

The server takes the item from the path (viewPathId), never from the
view: "this topic", "this report", "this product" is the one the URL
names, read with the read that takes its id. A topic's page is its
topic's filter: its id fills topic_id on its brand's reads, unless the
model gave its own or the question asks for all topics. A prompt's page
fills no prompt_ids, so a ranking asked there stays one. A message from
another brand's item page keeps the page's pattern only. A key ref may
hold dashes (json-ld-validity), never a lower-case code. Help says
detail pages too. One scripted eval scenario: "bu konuda en zayıf
promptumuz hangisi?" on a topic's page reads that topic's prompts and
names its weakest.

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.

Approving 2470's own commits. Minor: getActionCenterKpisFor (web/src/lib/mcp/action-center-reads.ts) takes any period length, so a model can ask for 2015→today; a ~365-day cap would be cheap. Merges after #2462/#2463.

@cihan-gyk
cihan-gyk dismissed gkhngyk’s stale review November 17, 2026 18:14

The merge-base changed after approval.

getVisibilitySummaryFor read the raw competitor_aggregates whenever a
window started or ended inside a day: on the busiest brand 13 s for 7
days and past 120 s for 90, which external MCP calls with timestamps
reach. Now a window of at most about a day (25 hours of answers, up to
now) is still read to the minute from the raw aggregates; a longer one
is read over the whole UTC days it touches from the daily rollups, and
the result says so (roundedToDays and a note). A bound that isn't a day
or a time is refused with a clear message before any read. Chat's
whole-day windows are unchanged.

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

page-scope.ts takes both imports: the lookups' search words and the
page-route helper.

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
get_prompt_locations (from main) is a read of Prompts › Tracked, so the
app gives it a preset as that page reads it: the last N × 24 hours up to
now (page-periods.ts rollingWindow), as every other Prompts read here.

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

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
With the page's search, list_prompts and list_content_opportunities went
down their lookup path, which reads every status and drops the page's
other filters and the sort, while the scope note said they were taken.
Now the app sets as_listed with the page's search: the search reads the
list as the page lists it (status, impact, type, topic, active state,
archived set aside, the read's sort, paged and counted like the list).
The model's own search on such a read stays a lookup by name in every
status, and then none of the page's filters is filled or said taken.

/dashboard/prompts is Tracked Prompts (page-route.ts), so its search
reaches list_prompts; the view's URL keys, open item and order use the
same helper. The order line says the app applies the page's search, or
leaves out a filter's "all", only where pageFilterInputs does.

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

page-scope.ts keeps both: the brandless reads, tab and path filters of
this branch, and the page-route alias and as_listed search from below.
help/chat/chat.md says both; approved-articles.json regenerated.

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

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
…etail-pages

Both sides' help keywords; the Prompts' Locations test and the
brand-scope imports as below (the same reads, main's order);
approved-articles.json regenerated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
Main now holds ansvisor#2465 (fix/chat-today-agents-reads), so it comes in with
main rather than on its own.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
getActionCenterKpisFor took a period of any length, so a model could ask
for 2015 to today. A period longer than 365 days now keeps its last 365
(as the Why read keeps its last 92 and Prompts its 90), and the result's
note says what was asked and what was read. 90 days, and exactly 365,
are read as asked.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
scope.ts took any search on list_prompts or list_content_opportunities
for named rows and dropped the model's limit. The page's search, as
listed, reads the list, so it keeps them; ids still name rows.

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

mintlify Bot commented Nov 17, 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 a70fb2a.

Approve preview

gkhngyk
gkhngyk previously approved these changes Nov 18, 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.

Looks good.

@cihan-gyk
cihan-gyk dismissed gkhngyk’s stale review November 18, 2026 11:26

The merge-base changed after approval.

@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 aa35772 into ansvisor:main Nov 18, 2026
13 checks passed
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