Repository navigation
feat(sidebar): put Competitors back on the menu, under Brand Visibility - #1809
Conversation
Competitors (/dashboard/competitors) has been off the menu since ansvisor#506, reachable only from Brand Visibility's Leaderboard and Getting started. It is back under Analytics, right after Brand Visibility, with the Users icon and the competitor_tracking gate the page checks, and no badge. Menu access lists it with the other sections (they come from the menu). No work area names it yet, so picking work areas leaves it on, while a role filled from a ready-made set leaves it off. Tests follow the new section count; the Competitors guide and help articles say where it is. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Founders & leaders, Brand & PR, Growth, Business Development and Analytics now name Competitors, right after Brand Visibility: picking one keeps it on the menu, and a role filled from their ready-made set sees it. The other areas (AEO/GEO & Audit, Content, Product Development, Developers) leave it off. The menu access guide's table and the work areas help article list it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
gkhngyk
left a comment
There was a problem hiding this comment.
Approving. Competitors sits under Brand Visibility and goes through the same paths as every other item:
- Plan gate:
requiredFeature: 'competitor_tracking'. All four plans have it, so nobody sees a lock. - Menu access: the section id comes from the route (
competitors), so Settings › Menu access, role sets and per-person exceptions pick it up with no extra code. The database doesn't limit section names, so saving it works. - Work areas: it's added to the five areas that compare brands. AEO/GEO, Content, Product and Developers leave it out. Existing role rows don't list it, so it shows for those roles until an admin hides it, the same as any section added later.
- Active state:
/dashboard/competitorsisn't the start of any other item's route, so only this item lights up. The sidebar and the mobile menu both read the label fromdashboardNavLabelKeys. - New badges: this adds no badge, and it merges clean with #1801.
- Docs and Help: the guide, menu access and the two Competitors articles now say where the page is.
Checked on the PR merged with current main: menu access, sidebar, mobile menu, Settings, onboarding, Help format and the Competitors page tests pass. tsc and eslint are clean, and the client-import guard (plan-row.test.ts) passes.
Merge order with two other open PRs:
- #1807 (Chat route registry): it adds Competitors as an extra page "the sidebar doesn't list". With both merged, the registry lists Competitors twice and
routes.test.ts › points every route at a page of the app, oncefails. #1807 needs a small fix before both land: skip an extra page whose address the sidebar already has. We have that fix ready, with a test. - #1803 (Help gaps): it conflicts in
help/competitors/add-competitors.mdandcompare-competitors.md, and its new text says the page "isn't on the left menu". Whichever PR merges second should keep #1803's new sections and use this PR's wording for where the page is.
Competitors is back on the sidebar (ansvisor#1809), so the registry would list it twice: from the sidebar and from the pages Chat adds.
gkhngyk
left a comment
There was a problem hiding this comment.
Merging in order with the other approved PRs. This head merges current main and keeps #1803's new sections in the two Competitors articles, with this PR's wording for where the page is (Analytics in the sidebar, or from Brand Visibility).
…ed router (#1807) * feat(chat): open a page for the person, from a router before the model, with a navigation card Chat Wave 1 W1-28 (CHAT-19 §2, §6; CHAT-20 §9 row 1): - Route registry (lib/chat/routes.ts): every page Chat can open, made from the live sidebar (config/dashboard.ts, its items and their submenus) and Settings' sections, named as the sidebar and Settings name them, with the plan feature each needs, other words people use for it, and the filters its address keeps (range and platform where the page reads them). Chat's own page isn't one. - Rules-based router (routeRequest): a plain "open / show / take me to / go to {page} [for {platform}] [{range}]" gives the page and its filters with no model and no AI usage: "Open Visibility for Perplexity, last 30 days" is /dashboard/insights?range=30d&model=perplexity-web. It answers only when it understood every word: a question, a filter the page doesn't keep ("drafts under Quality 60") or anything left over goes to the model. - open_page (registry row, area navigation, C0): for what the model routes; only pages the plan opens (a locked one names the plan that has it) and the plan's platforms as a filter; it reads the plan and nothing else. - Navigation card (components/chat/navigation-card.tsx): the page, its filters by name, "Filters set for you. This chat stays open in the side panel.", "Navigation only · no AI usage" and Go to page. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(chat): keep the route registry off client modules, and tighten open_page Review fixes for the route registry and open_page. - routes.ts read ALL_DATE_PRESETS from the date range control, a 'use client' module. On the server, a client module's exports are client references, not values, so every Chat turn (engine → registry → open_page → routes) would fail. The presets now live in config/date-presets.ts, and the control re-exports them. traffic-range.ts reads them there too. - plan-row.test.ts gains the other direction of its import walk: a shared module (src/lib, src/config) reads no value from a 'use client' file. - open_page's platform is one of the tracked platform ids (z.enum), and the pages' platform filter takes only those. A wrong slug no longer opens an empty page on plans without allowedScrapers. - The registry lists only the Settings sections this install shows: a self-hosted one has no Billing or AI Providers. - Competitors needs competitor_tracking. - The Action Center tabs' and Brands' names come from en.json. - Two pages matched by phrases of the same length ("open plan": Content › Plan or Billing, "open insights") are the model's to ask about. - The navigation card says "no AI usage" only when the rules-based router answered (ruleRouted). - ORG_PLAN_COLUMNS comes from guards/plan-row. - Tests: ties, //evil.com and javascript: addresses, the router with a plan lock, the platform enum, and self-hosted Settings. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(chat): set no platform on Insights from open_page Insights' model filter holds the answers' model slugs, not platform ids, so model=chatgpt-web opened an empty page. Insights keeps only its range; a platform request for it goes to the model. Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A * fix(chat): list a page once when the sidebar has it too Competitors is back on the sidebar (#1809), so the registry would list it twice: from the sidebar and from the pages Chat adds. --------- Co-authored-by: Cihan <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Gökhan Geyik <[email protected]>
…ncy and tokens (W1-19) (#1847) * feat(chat): add the reads Chat was missing, one registry file per area Chat Wave 1 W1-16 (CHAT-20 §9): twelve READ rows, each with its label, its brand (brandOf) and `data_as_of` in what it returns (§15a), listed in tools.ts with the rest: - prompts: get_fanouts (Query Fan-outs, the plan's engines only), list_ai_answers (a prompt's newest answers, shortened, the plan's platforms only), get_prompt_insights (estimated AI volume, by intent, the most demanded prompts). - visibility: get_overview_summary (the visibility summary with when tracking last ran and runs next). - action_center: get_action_center_kpis (the KPIs page's snapshots), get_onboarding_progress (Getting started's steps). - ai_traffic: get_gsc_summary and get_ga_summary (clicks and sessions against the period before, or "not connected", with Google's lag). - account: list_members (e-mails for Admins only), list_connections (Google per brand, CMS sites, AI provider keys set or not, API key names and last use: never a key or credential), get_chat_policy, get_plan_facts (counts and the plan card, never an AI budget in dollars). The brand reads run the pages' own loaders with the service role once brandInOrg passed (as product visibility and prompt locations do): the KPIs, traffic, fan-out and Getting started loaders now take their client from dbClient(), which on the pages is still the member's own. The RPCs they call don't read auth.uid() (ai_traffic_page_citations lets the service role through). None has an MCP tool yet (mcpTool null). Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(chat): open a page for the person, from a router before the model, with a navigation card Chat Wave 1 W1-28 (CHAT-19 §2, §6; CHAT-20 §9 row 1): - Route registry (lib/chat/routes.ts): every page Chat can open, made from the live sidebar (config/dashboard.ts, its items and their submenus) and Settings' sections, named as the sidebar and Settings name them, with the plan feature each needs, other words people use for it, and the filters its address keeps (range and platform where the page reads them). Chat's own page isn't one. - Rules-based router (routeRequest): a plain "open / show / take me to / go to {page} [for {platform}] [{range}]" gives the page and its filters with no model and no AI usage: "Open Visibility for Perplexity, last 30 days" is /dashboard/insights?range=30d&model=perplexity-web. It answers only when it understood every word: a question, a filter the page doesn't keep ("drafts under Quality 60") or anything left over goes to the model. - open_page (registry row, area navigation, C0): for what the model routes; only pages the plan opens (a locked one names the plan that has it) and the plan's platforms as a filter; it reads the plan and nothing else. - Navigation card (components/chat/navigation-card.tsx): the page, its filters by name, "Filters set for you. This chat stays open in the side panel.", "Navigation only · no AI usage" and Go to page. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(chat): read only the person's own API keys, and keep the reads' counts to what the plan and Google show Review of W1-16: - list_connections read every member's API keys with the service role, so anyone saw an Admin's key names and last use. It now reads the person's own, as Settings › API Keys and its RLS do (your_api_keys). - get_gsc_summary reads Google's latest reported days for a range of a week or less, as the page does (gscLatestDays), and its data_as_of is the last day Search Console reported; get_ga_summary's is Analytics'. - A Google source is connected when the workspace's connection is on (integration_connections) and the brand has its property picked, as AI Referral Traffic reads it. - list_ai_answers reads up to 50, keeps the plan's platforms, then the number asked for, so a page isn't short. - get_fanouts reads the plan's platforms from the rows up (getQueryFanout takes an optional platforms filter; the page passes none), so its totals, times searched and data_as_of are theirs. - get_prompt_insights says when the volume read stopped at 500 prompts (truncated). - get_chat_policy's page is Settings › Roles & access. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(chat): keep the route registry off client modules, and tighten open_page Review fixes for the route registry and open_page. - routes.ts read ALL_DATE_PRESETS from the date range control, a 'use client' module. On the server, a client module's exports are client references, not values, so every Chat turn (engine → registry → open_page → routes) would fail. The presets now live in config/date-presets.ts, and the control re-exports them. traffic-range.ts reads them there too. - plan-row.test.ts gains the other direction of its import walk: a shared module (src/lib, src/config) reads no value from a 'use client' file. - open_page's platform is one of the tracked platform ids (z.enum), and the pages' platform filter takes only those. A wrong slug no longer opens an empty page on plans without allowedScrapers. - The registry lists only the Settings sections this install shows: a self-hosted one has no Billing or AI Providers. - Competitors needs competitor_tracking. - The Action Center tabs' and Brands' names come from en.json. - Two pages matched by phrases of the same length ("open plan": Content › Plan or Billing, "open insights") are the model's to ask about. - The navigation card says "no AI usage" only when the rules-based router answered (ruleRouted). - ORG_PLAN_COLUMNS comes from guards/plan-row. - Tests: ties, //evil.com and javascript: addresses, the router with a plan lock, the platform enum, and self-hosted Settings. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(chat): add Wave 1's tables for sharing, settings, attachments, Files, Help and add-on packs Chat's Wave 1 tables in one PR (one DB PR per wave), behind CHAT_AGENTIC: nothing reads or writes them while the flag is off. Tables, types and the demo's coverage only; the code that uses them comes in the Wave 1 PRs. - 00407: chat_conversations gets shared_at (Share with team: every member of the workspace reads it), last_read_at (unread results), deleted_at (Delete with Undo; deleted chats are hidden from every member) and a title search column; chat_messages gets context_json (what a person's message was scoped to) and a text search column. 'simple' text search, so a chat in any language is found. The author policy now leaves deleted chats out, and a shared policy reads shared ones. - 00408: chat_user_prefs gets the rest of Settings › General and the one-time notices: rail_open, panel_size, default_mode, answer_language, notify_via, show_thought, panel_on_pages, focus_prompted_at, usage_notice_period, legacy_imported_at. - 00409: chat_uploads and the private bucket chat-uploads: 10 MB a file, the composer's 11 types, 5 a message (a trigger backs the server's check), kept 90 days. - 00410: chat_tool_cache (a chat's read results by tool and scope, server only) and each step's and model call's measure: latency, cache hit, truncation, result tokens on chat_run_steps (never granted to members), prompt cache read/write tokens and latency on the ledger. - 00411: chat_files (filed deliverables and saved answers, the workspace's, kept a year, searchable by title, summary and tags), chat_file_task_links, chat_storage_usage kept by a trigger, and the private bucket chat-files. - 00412: help_answer_cache and help_gaps (server only, no workspace or person ids). - 00413: add_on_products seeded with the owner's packs (AI credits $10, $50, $250, $1,000 at half their price in budget, 12 months; storage +25/+100/+250 GB at $5/$15/$29 a month; $50 and +25 GB Most picked), add_on_purchases (Admins read), ai_credit_grants and storage_grants (server only), and prompt_improve_usage.grant_id. Members only ever read; every write is the server's. Tool names, tool results and dollars stay server only. web/src/types/supabase.ts carries the new tables and columns; schema.test.ts checks the policies, the server-only tables, the limits and the seeded packs from the SQL; steps.test.ts keeps the step measure out of the member columns. The demo coverage skips chat_files and chat_tool_cache (a person's own Chat work). Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(chat): scope every read on the server: default dates, the plan's platforms and row limits (W1-17) Chat's scope decisions now live in one place, lib/chat/scope.ts, and the engine applies them to every read before it runs (CHAT-04 items 2-6, CHAT-20 §7): - Dates: a read with no dates covers the last 30 days; all time only when the person's message asks for it ("all time", "since we started", "başından beri"...). The model's own dates are kept, end today at the latest and are put in order. `days` reads get their default (Google's 28) or, on an all-time ask, their 90-day maximum. - Platforms: a platform or model the plan doesn't track (Perplexity on Starter, Claude on Growth) isn't read; the model gets `not_on_plan` with the plan's platforms and says so. On a plan that tracks only some apps (Starter), a "Platforms by plan" read that names none is held to the plan's. get_overview_summary takes the same `model` filter for this. - Rows: each read has a default and a maximum (50 at most, CHAT-04 Rule 1). A `limit` read asks for one row more to see if there are more; every list is cut to its limit with `{list}_more` and `truncated: true`. - The step shows "Last 30 days" and the plan's platforms; scope_json keeps the scope used (`used`: dates, platforms, rows). The model sees each read's period and platforms beside its rows, and is told what a cut list and `not_on_plan` mean. Behind CHAT_AGENTIC, like the rest of the engine; no migration. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(chat): fit tool results to the data budget, sum up older turns and order the prompt for the cache (W1-18) Three parts of CHAT-04's context engine, behind CHAT_AGENTIC: - Data budgets (lib/chat/fit.ts, items 5-6): a tool result over its share of the run's budget is made smaller on the server before the model sees it, never cut silently: long texts in its rows are shortened first, then its longest lists keep their first rows with `{list}_more` and a rest line, `{list}_rest` (what the left-out rows add up to: "9% of citations"; count fields only, never a score, rate or position), and only then is the rest cut as text. Every cut says `truncated: true`. An earlier row cut's `_more` is added to; an unknown count stays null. - History (lib/chat/history.ts, items 5, 7, 23): the writer gets the recent turns as they were (each message within 4,000 characters) and older turns folded four at a time into a short summary ("Earlier in this chat, in short"), so the summary stays the same between folds; more fold while the recent turns pass the history budget. The reader (Claude Haiku 5.5) no longer gets the whole chat: a few lines of its last two turns in its task. - Prompt order (lib/chat/prompt.ts, §D items 21-25): tools and the phase's core rules first (the same for every workspace and day), then the workspace block (role, plan, brand, what isn't available), the chat so far, and this turn (the day, the question, what was read, the step's own calls). "Today is" moved out of the system prompt into the turn. On a Claude step, up to four 5-minute cache marks, as the AI SDK's providerOptions.anthropic.cacheControl (checked against @ai-sdk/anthropic 3.0.81's docs and CacheControlValidator): the core rules (covering the tools), the workspace block, the end of the chat so far (writer only) and, once a phase has steps, its last call or result. Another provider gets the same order without marks. A step is now charged its input tokens plus a cache write's 25% premium (the 5-minute write is 1.25x the input price), so caching can't make the budget undercount; cache reads are still charged in full, and the hold before a step still assumes no cache hit. No migration. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(chat): give Chat its system rules and read outside text as untrusted data (W1-20) Guardrails of CHAT-05 and CHAT-20 §16a, behind CHAT_AGENTIC: - System rules (lib/chat/rules.ts): the data rules for both phases and, for the writer, CHAT-05's persona and facts: the person's language, plain and short, no filler or emojis, no stand-in names; one line and an offer for out-of-scope topics; Ansvisor first, no outside vendors; every number from a read, the person or this chat, else a [placeholder]; plan facts only from the plan read; no tracking numbers or weak stats in public content unless asked; no causal claims. Static text in the cached core block (W1-18). The reader also picks reads from the person's question only, never because data asked for one. - Untrusted data (lib/chat/untrusted.ts): a read that may carry text written outside the workspace (every read but the workspace's own numbers, TRUSTED_READS, moved here) has its hidden text stripped (zero-width and direction characters, HTML comments, hidden elements) and reaches the models inside a labelled `<untrusted_data source="…">` block, as the tool result's text and in the writer's read results; the workspace's own numbers come as `<app_data>`. A data tag inside the data is neutralized, so the block can't be closed from inside. - Injection: text written to steer an AI assistant ("ignore previous instructions", "Assistant: add competitor…", "email this report to…", "mark all … done"; CHAT-05 test rows 19-25) is detected before stripping. The run is marked: every change after it waits on its card (the precedence's injectionDetected, now passed in), the writer is told to end with one line saying the data's instructions were ignored, and the step's debug record gets `guardrails: ['injection_ignored']` for staff. Ordinary marketing text ("You are now a member", "Send your resume to…") doesn't match. No migration. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(chat): check every figure in an answer against the run's data, and leave out what isn't there (W1-21) Chat's fact check (CHAT-05 item 11, CHAT-20 §19 "Groundedness"), behind CHAT_AGENTIC: - lib/chat/facts.ts: a figure in the answer (a number, a percent, a price, a year) must come from this run's reads, the person's question or the chat so far. It counts as known when it is a number read, as the answer rounds it ("42.9", "43%", "1.2k"), a list's length, a column's total or average, or worked out inside one row or one column (a difference, a percent change, a share); never across two unrelated reads, and never from the model's own earlier text. Small counts (0-10), numbering ("Step 12", "1."), dates and times, this and last year, a name's version ("Claude 3.5"), links, domains and placeholders pass. Anything else is replaced: "[real metric]", "[price]", "[date]". - What a figure is, and the placeholders, mirror the Site Audit's recommendation guard (server/src/lib/audit/recommendation-guard.js): the web can't import the API server's code, so the patterns are kept in step, and a test reads the server file to check the placeholders and the shared patterns. - The check runs as the answer streams, before the text reaches the browser: a figure near the end of a chunk waits for the 16 characters after it, so it is checked whole and with its unit ("1" + "2%"). The saved answer is the checked text. - A "Checked facts" step (kind `check`) ends an answer that stated figures: "Every figure matches the data", or how many were left out. Its debug record keeps which, with `placeholder_inserted`, for staff. No migration. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(chat): set no platform on Insights from open_page Insights' model filter holds the answers' model slugs, not platform ids, so model=chatgpt-web opened an empty page. Insights keeps only its range; a platform request for it goes to the model. Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A * fix(chat): list a page once when the sidebar has it too Competitors is back on the sidebar (#1809), so the registry would list it twice: from the sidebar and from the pages Chat adds. * feat(chat): reuse a chat's reads, measure each step and price prompt-cache reads at their rate (W1-19) - The same read with the same arguments (as the server scoped them), brand, scope, person and role in one chat comes from chat_tool_cache (00410): tracking data until the brand's next completed tracking run, a day at most; other reads five minutes. Writes, executes and open_page are never kept; a change the chat makes drops its kept reads. Server only: the person sees the same step either way. A failing cache never stops a read. - chat_run_steps gets latency_ms, cache_hit, truncated and result_tokens (staff only, never in an event). - A model step's charge sends its prompt-cache read and write tokens and its latency; the server prices cache reads at the model's cache-read rate (full input price when unknown), writes at 1.25x, and keeps both counts and the latency on prompt_improve_usage. A step without both input and output counts keeps its hold: over, never under. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(chat): find instructions hidden by zero-width or tag characters, and strip tag characters Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A * fix(chat): never cut an emoji in half, keep text cuts within budget and the summary stable between folds - A cut that ends on half of an emoji leaves a lone surrogate, which the model's API turns away as invalid JSON. Folded turns are cut the same way every time, so one such cut failed every later turn of the chat. cutText steps back one unit instead; fit.ts and history.ts both use it. - A result cut as text is trimmed until its escaped size fits maxChars. - The summary's room is a fixed quarter of the history budget, so it changes only when turns fold and the prompt cache keeps it; its oldest lines are dropped with a running length instead of re-joining every line. Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A * fix(chat): keep a trend's latest days, never date past today, and fail a read whose platforms can't be matched - A cut series oldest first (the visibility trend's buckets, the mentions summary's days) kept its first 50 rows: a 90-day or all-time trend lost its latest weeks. It now keeps its latest rows. - A start date after today stayed as given (and, swapped with a clamped end, became an end past today). Both dates now stop at today. - On a plan that tracks some platforms, a failed read of the brand's models held the read to the plan's own ids, which read as no data. The read now fails instead. Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A * fix(chat): read a figure cut across stream chunks with what was sent, and keep each check short The stream could cut just before a figure ("https://example.com/blog/" | "98765", "#" | "12", "Oct " | "17"); the next chunk was checked alone, so a link's digits or a ranked number were replaced. checkFigures now reads the sent text as context. The hold before a figure or a uuid is capped, the rules read a few words either side, and the unit and domain patterns start at a word's start, so a long answer is checked in linear time. Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A * fix(chat): keep a series' latest rows when a result is over its data budget fitResult kept a list's first rows, so a trend sent oldest first (the visibility buckets, the mentions summary's days) lost its latest days when it was over budget, as capRows did before. It now keeps the latest rows of an oldest-first series, and `{list}_rest` adds up the older ones it left out. oldestFirst moves to fit.ts, which is pure, and scope.ts imports it. Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A * fix(chat): write the Checked facts step before the run is marked done A failed step write after the move to done left the run done with no saved answer and no run.finished. Writing it while the run still runs sends a failure down the normal error path. Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A * fix(chat): price Sonnet 5.5's prompt-cache reads at a tenth of its input The table had $0.10 per million for Sonnet 5.5's cache reads, a twentieth of its $2 input; Anthropic charges a tenth ($0.20). With no synced price for the model, Chat's writer steps were charged half what their cache reads cost. Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A --------- Co-authored-by: Cihan <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Gökhan Geyik <[email protected]>
… the source (W1-30) (#1848) * feat(chat): add the reads Chat was missing, one registry file per area Chat Wave 1 W1-16 (CHAT-20 §9): twelve READ rows, each with its label, its brand (brandOf) and `data_as_of` in what it returns (§15a), listed in tools.ts with the rest: - prompts: get_fanouts (Query Fan-outs, the plan's engines only), list_ai_answers (a prompt's newest answers, shortened, the plan's platforms only), get_prompt_insights (estimated AI volume, by intent, the most demanded prompts). - visibility: get_overview_summary (the visibility summary with when tracking last ran and runs next). - action_center: get_action_center_kpis (the KPIs page's snapshots), get_onboarding_progress (Getting started's steps). - ai_traffic: get_gsc_summary and get_ga_summary (clicks and sessions against the period before, or "not connected", with Google's lag). - account: list_members (e-mails for Admins only), list_connections (Google per brand, CMS sites, AI provider keys set or not, API key names and last use: never a key or credential), get_chat_policy, get_plan_facts (counts and the plan card, never an AI budget in dollars). The brand reads run the pages' own loaders with the service role once brandInOrg passed (as product visibility and prompt locations do): the KPIs, traffic, fan-out and Getting started loaders now take their client from dbClient(), which on the pages is still the member's own. The RPCs they call don't read auth.uid() (ai_traffic_page_citations lets the service role through). None has an MCP tool yet (mcpTool null). Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(chat): open a page for the person, from a router before the model, with a navigation card Chat Wave 1 W1-28 (CHAT-19 §2, §6; CHAT-20 §9 row 1): - Route registry (lib/chat/routes.ts): every page Chat can open, made from the live sidebar (config/dashboard.ts, its items and their submenus) and Settings' sections, named as the sidebar and Settings name them, with the plan feature each needs, other words people use for it, and the filters its address keeps (range and platform where the page reads them). Chat's own page isn't one. - Rules-based router (routeRequest): a plain "open / show / take me to / go to {page} [for {platform}] [{range}]" gives the page and its filters with no model and no AI usage: "Open Visibility for Perplexity, last 30 days" is /dashboard/insights?range=30d&model=perplexity-web. It answers only when it understood every word: a question, a filter the page doesn't keep ("drafts under Quality 60") or anything left over goes to the model. - open_page (registry row, area navigation, C0): for what the model routes; only pages the plan opens (a locked one names the plan that has it) and the plan's platforms as a filter; it reads the plan and nothing else. - Navigation card (components/chat/navigation-card.tsx): the page, its filters by name, "Filters set for you. This chat stays open in the side panel.", "Navigation only · no AI usage" and Go to page. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(chat): read only the person's own API keys, and keep the reads' counts to what the plan and Google show Review of W1-16: - list_connections read every member's API keys with the service role, so anyone saw an Admin's key names and last use. It now reads the person's own, as Settings › API Keys and its RLS do (your_api_keys). - get_gsc_summary reads Google's latest reported days for a range of a week or less, as the page does (gscLatestDays), and its data_as_of is the last day Search Console reported; get_ga_summary's is Analytics'. - A Google source is connected when the workspace's connection is on (integration_connections) and the brand has its property picked, as AI Referral Traffic reads it. - list_ai_answers reads up to 50, keeps the plan's platforms, then the number asked for, so a page isn't short. - get_fanouts reads the plan's platforms from the rows up (getQueryFanout takes an optional platforms filter; the page passes none), so its totals, times searched and data_as_of are theirs. - get_prompt_insights says when the volume read stopped at 500 prompts (truncated). - get_chat_policy's page is Settings › Roles & access. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(chat): keep the route registry off client modules, and tighten open_page Review fixes for the route registry and open_page. - routes.ts read ALL_DATE_PRESETS from the date range control, a 'use client' module. On the server, a client module's exports are client references, not values, so every Chat turn (engine → registry → open_page → routes) would fail. The presets now live in config/date-presets.ts, and the control re-exports them. traffic-range.ts reads them there too. - plan-row.test.ts gains the other direction of its import walk: a shared module (src/lib, src/config) reads no value from a 'use client' file. - open_page's platform is one of the tracked platform ids (z.enum), and the pages' platform filter takes only those. A wrong slug no longer opens an empty page on plans without allowedScrapers. - The registry lists only the Settings sections this install shows: a self-hosted one has no Billing or AI Providers. - Competitors needs competitor_tracking. - The Action Center tabs' and Brands' names come from en.json. - Two pages matched by phrases of the same length ("open plan": Content › Plan or Billing, "open insights") are the model's to ask about. - The navigation card says "no AI usage" only when the rules-based router answered (ruleRouted). - ORG_PLAN_COLUMNS comes from guards/plan-row. - Tests: ties, //evil.com and javascript: addresses, the router with a plan lock, the platform enum, and self-hosted Settings. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(chat): add Wave 1's tables for sharing, settings, attachments, Files, Help and add-on packs Chat's Wave 1 tables in one PR (one DB PR per wave), behind CHAT_AGENTIC: nothing reads or writes them while the flag is off. Tables, types and the demo's coverage only; the code that uses them comes in the Wave 1 PRs. - 00407: chat_conversations gets shared_at (Share with team: every member of the workspace reads it), last_read_at (unread results), deleted_at (Delete with Undo; deleted chats are hidden from every member) and a title search column; chat_messages gets context_json (what a person's message was scoped to) and a text search column. 'simple' text search, so a chat in any language is found. The author policy now leaves deleted chats out, and a shared policy reads shared ones. - 00408: chat_user_prefs gets the rest of Settings › General and the one-time notices: rail_open, panel_size, default_mode, answer_language, notify_via, show_thought, panel_on_pages, focus_prompted_at, usage_notice_period, legacy_imported_at. - 00409: chat_uploads and the private bucket chat-uploads: 10 MB a file, the composer's 11 types, 5 a message (a trigger backs the server's check), kept 90 days. - 00410: chat_tool_cache (a chat's read results by tool and scope, server only) and each step's and model call's measure: latency, cache hit, truncation, result tokens on chat_run_steps (never granted to members), prompt cache read/write tokens and latency on the ledger. - 00411: chat_files (filed deliverables and saved answers, the workspace's, kept a year, searchable by title, summary and tags), chat_file_task_links, chat_storage_usage kept by a trigger, and the private bucket chat-files. - 00412: help_answer_cache and help_gaps (server only, no workspace or person ids). - 00413: add_on_products seeded with the owner's packs (AI credits $10, $50, $250, $1,000 at half their price in budget, 12 months; storage +25/+100/+250 GB at $5/$15/$29 a month; $50 and +25 GB Most picked), add_on_purchases (Admins read), ai_credit_grants and storage_grants (server only), and prompt_improve_usage.grant_id. Members only ever read; every write is the server's. Tool names, tool results and dollars stay server only. web/src/types/supabase.ts carries the new tables and columns; schema.test.ts checks the policies, the server-only tables, the limits and the seeded packs from the SQL; steps.test.ts keeps the step measure out of the member columns. The demo coverage skips chat_files and chat_tool_cache (a person's own Chat work). Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(chat): scope every read on the server: default dates, the plan's platforms and row limits (W1-17) Chat's scope decisions now live in one place, lib/chat/scope.ts, and the engine applies them to every read before it runs (CHAT-04 items 2-6, CHAT-20 §7): - Dates: a read with no dates covers the last 30 days; all time only when the person's message asks for it ("all time", "since we started", "başından beri"...). The model's own dates are kept, end today at the latest and are put in order. `days` reads get their default (Google's 28) or, on an all-time ask, their 90-day maximum. - Platforms: a platform or model the plan doesn't track (Perplexity on Starter, Claude on Growth) isn't read; the model gets `not_on_plan` with the plan's platforms and says so. On a plan that tracks only some apps (Starter), a "Platforms by plan" read that names none is held to the plan's. get_overview_summary takes the same `model` filter for this. - Rows: each read has a default and a maximum (50 at most, CHAT-04 Rule 1). A `limit` read asks for one row more to see if there are more; every list is cut to its limit with `{list}_more` and `truncated: true`. - The step shows "Last 30 days" and the plan's platforms; scope_json keeps the scope used (`used`: dates, platforms, rows). The model sees each read's period and platforms beside its rows, and is told what a cut list and `not_on_plan` mean. Behind CHAT_AGENTIC, like the rest of the engine; no migration. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(chat): fit tool results to the data budget, sum up older turns and order the prompt for the cache (W1-18) Three parts of CHAT-04's context engine, behind CHAT_AGENTIC: - Data budgets (lib/chat/fit.ts, items 5-6): a tool result over its share of the run's budget is made smaller on the server before the model sees it, never cut silently: long texts in its rows are shortened first, then its longest lists keep their first rows with `{list}_more` and a rest line, `{list}_rest` (what the left-out rows add up to: "9% of citations"; count fields only, never a score, rate or position), and only then is the rest cut as text. Every cut says `truncated: true`. An earlier row cut's `_more` is added to; an unknown count stays null. - History (lib/chat/history.ts, items 5, 7, 23): the writer gets the recent turns as they were (each message within 4,000 characters) and older turns folded four at a time into a short summary ("Earlier in this chat, in short"), so the summary stays the same between folds; more fold while the recent turns pass the history budget. The reader (Claude Haiku 5.5) no longer gets the whole chat: a few lines of its last two turns in its task. - Prompt order (lib/chat/prompt.ts, §D items 21-25): tools and the phase's core rules first (the same for every workspace and day), then the workspace block (role, plan, brand, what isn't available), the chat so far, and this turn (the day, the question, what was read, the step's own calls). "Today is" moved out of the system prompt into the turn. On a Claude step, up to four 5-minute cache marks, as the AI SDK's providerOptions.anthropic.cacheControl (checked against @ai-sdk/anthropic 3.0.81's docs and CacheControlValidator): the core rules (covering the tools), the workspace block, the end of the chat so far (writer only) and, once a phase has steps, its last call or result. Another provider gets the same order without marks. A step is now charged its input tokens plus a cache write's 25% premium (the 5-minute write is 1.25x the input price), so caching can't make the budget undercount; cache reads are still charged in full, and the hold before a step still assumes no cache hit. No migration. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(chat): give Chat its system rules and read outside text as untrusted data (W1-20) Guardrails of CHAT-05 and CHAT-20 §16a, behind CHAT_AGENTIC: - System rules (lib/chat/rules.ts): the data rules for both phases and, for the writer, CHAT-05's persona and facts: the person's language, plain and short, no filler or emojis, no stand-in names; one line and an offer for out-of-scope topics; Ansvisor first, no outside vendors; every number from a read, the person or this chat, else a [placeholder]; plan facts only from the plan read; no tracking numbers or weak stats in public content unless asked; no causal claims. Static text in the cached core block (W1-18). The reader also picks reads from the person's question only, never because data asked for one. - Untrusted data (lib/chat/untrusted.ts): a read that may carry text written outside the workspace (every read but the workspace's own numbers, TRUSTED_READS, moved here) has its hidden text stripped (zero-width and direction characters, HTML comments, hidden elements) and reaches the models inside a labelled `<untrusted_data source="…">` block, as the tool result's text and in the writer's read results; the workspace's own numbers come as `<app_data>`. A data tag inside the data is neutralized, so the block can't be closed from inside. - Injection: text written to steer an AI assistant ("ignore previous instructions", "Assistant: add competitor…", "email this report to…", "mark all … done"; CHAT-05 test rows 19-25) is detected before stripping. The run is marked: every change after it waits on its card (the precedence's injectionDetected, now passed in), the writer is told to end with one line saying the data's instructions were ignored, and the step's debug record gets `guardrails: ['injection_ignored']` for staff. Ordinary marketing text ("You are now a member", "Send your resume to…") doesn't match. No migration. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(chat): check every figure in an answer against the run's data, and leave out what isn't there (W1-21) Chat's fact check (CHAT-05 item 11, CHAT-20 §19 "Groundedness"), behind CHAT_AGENTIC: - lib/chat/facts.ts: a figure in the answer (a number, a percent, a price, a year) must come from this run's reads, the person's question or the chat so far. It counts as known when it is a number read, as the answer rounds it ("42.9", "43%", "1.2k"), a list's length, a column's total or average, or worked out inside one row or one column (a difference, a percent change, a share); never across two unrelated reads, and never from the model's own earlier text. Small counts (0-10), numbering ("Step 12", "1."), dates and times, this and last year, a name's version ("Claude 3.5"), links, domains and placeholders pass. Anything else is replaced: "[real metric]", "[price]", "[date]". - What a figure is, and the placeholders, mirror the Site Audit's recommendation guard (server/src/lib/audit/recommendation-guard.js): the web can't import the API server's code, so the patterns are kept in step, and a test reads the server file to check the placeholders and the shared patterns. - The check runs as the answer streams, before the text reaches the browser: a figure near the end of a chunk waits for the 16 characters after it, so it is checked whole and with its unit ("1" + "2%"). The saved answer is the checked text. - A "Checked facts" step (kind `check`) ends an answer that stated figures: "Every figure matches the data", or how many were left out. Its debug record keeps which, with `placeholder_inserted`, for staff. No migration. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(chat): set no platform on Insights from open_page Insights' model filter holds the answers' model slugs, not platform ids, so model=chatgpt-web opened an empty page. Insights keeps only its range; a platform request for it goes to the model. Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A * fix(chat): list a page once when the sidebar has it too Competitors is back on the sidebar (#1809), so the registry would list it twice: from the sidebar and from the pages Chat adds. * feat(chat): reuse a chat's reads, measure each step and price prompt-cache reads at their rate (W1-19) - The same read with the same arguments (as the server scoped them), brand, scope, person and role in one chat comes from chat_tool_cache (00410): tracking data until the brand's next completed tracking run, a day at most; other reads five minutes. Writes, executes and open_page are never kept; a change the chat makes drops its kept reads. Server only: the person sees the same step either way. A failing cache never stops a read. - chat_run_steps gets latency_ms, cache_hit, truncated and result_tokens (staff only, never in an event). - A model step's charge sends its prompt-cache read and write tokens and its latency; the server prices cache reads at the model's cache-read rate (full input price when unknown), writes at 1.25x, and keeps both counts and the latency on prompt_improve_usage. A step without both input and output counts keeps its hold: over, never under. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(chat): answer how-to questions from approved Help articles, with their source (W1-30) - A "how do I / where is / what does it mean" question (English or Turkish; never one about the person's own results) is matched by keyword against the approved Help articles (lib/help/search.ts: keywords, synonyms and title, then the best 2-3 sections, word-weighted). - The small model (Haiku on Auto) writes the answer from those sections only, with a short fixed system prompt: no workspace data, no history, no tools. The step is held and charged on the AI budget like every Chat step, and the answer goes through the figure check. - The answer ends with "From Help: {title}" and a link that opens the article's page through open_page (W1-28), only where the plan opens it. - help_answer_cache (00412) keeps answers by normalized question, language and app version (web version + the approved articles' hash); a question that names a site, an email, an id or a long number isn't shared. - No match: the question goes to help_gaps, scrubbed and anonymous (no workspace or person id), and Chat answers it as usual. - The web app can't read /help, so approved articles are copied into lib/help/approved-articles.json; search.test.ts keeps it in step (refresh with yarn test -u src/lib/help, noted in help/README.md). No article is approved yet, so the file is empty for now. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(chat): find instructions hidden by zero-width or tag characters, and strip tag characters Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A * fix(chat): never cut an emoji in half, keep text cuts within budget and the summary stable between folds - A cut that ends on half of an emoji leaves a lone surrogate, which the model's API turns away as invalid JSON. Folded turns are cut the same way every time, so one such cut failed every later turn of the chat. cutText steps back one unit instead; fit.ts and history.ts both use it. - A result cut as text is trimmed until its escaped size fits maxChars. - The summary's room is a fixed quarter of the history budget, so it changes only when turns fold and the prompt cache keeps it; its oldest lines are dropped with a running length instead of re-joining every line. Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A * fix(chat): keep a trend's latest days, never date past today, and fail a read whose platforms can't be matched - A cut series oldest first (the visibility trend's buckets, the mentions summary's days) kept its first 50 rows: a 90-day or all-time trend lost its latest weeks. It now keeps its latest rows. - A start date after today stayed as given (and, swapped with a clamped end, became an end past today). Both dates now stop at today. - On a plan that tracks some platforms, a failed read of the brand's models held the read to the plan's own ids, which read as no data. The read now fails instead. Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A * fix(chat): read a figure cut across stream chunks with what was sent, and keep each check short The stream could cut just before a figure ("https://example.com/blog/" | "98765", "#" | "12", "Oct " | "17"); the next chunk was checked alone, so a link's digits or a ranked number were replaced. checkFigures now reads the sent text as context. The hold before a figure or a uuid is capped, the rules read a few words either side, and the unit and domain patterns start at a word's start, so a long answer is checked in linear time. Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A * fix(chat): keep a series' latest rows when a result is over its data budget fitResult kept a list's first rows, so a trend sent oldest first (the visibility buckets, the mentions summary's days) lost its latest days when it was over budget, as capRows did before. It now keeps the latest rows of an oldest-first series, and `{list}_rest` adds up the older ones it left out. oldestFirst moves to fit.ts, which is pure, and scope.ts imports it. Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A * fix(chat): write the Checked facts step before the run is marked done A failed step write after the move to done left the run done with no saved answer and no run.finished. Writing it while the run still runs sends a failure down the normal error path. Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A * fix(chat): price Sonnet 5.5's prompt-cache reads at a tenth of its input The table had $0.10 per million for Sonnet 5.5's cache reads, a twentieth of its $2 input; Anthropic charges a tenth ($0.20). With no synced price for the model, Chat's writer steps were charged half what their cache reads cost. Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A * fix(chat): keep Help answers only from Ansvisor's models, and leave "what is my…" questions to the data - A Help answer is kept in the shared answer list only when the run used Ansvisor's key: on a workspace's own key another model may write it. - "What is my / our …" and "where do I / we stand or rank" ask about the person's own results, so they go the usual way, not to Help. --------- Co-authored-by: Cihan <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Gökhan Geyik <[email protected]>
Summary
The Competitors page (
/dashboard/competitors) hasn't been in the sidebar since #506. You could reach it only from Brand Visibility's Leaderboard and Getting started. The product owner asked for it back in the menu.What changes
config/dashboard.ts: Competitors under Analytics, right below Brand Visibility. It has itsUsersicon,requiredFeature: 'competitor_tracking'(every plan has it) and no badge (see chore(sidebar): drop the New badges from the menu #1801).dashboardNavLabelKeysgetsCompetitors;nav.competitorsalready existed.dashboardNav, so Competitors appears there by itself.lib/menu-access.ts): Competitors is added to the five areas that compare brands: Founders & leaders, Brand & PR, Growth, Business Development and Analytics.docs/guides/competitors.mdxno longer says it isn't on the left menu.docs/guides/menu-access.mdxandhelp/settings/work-areas.mdlist it in those five areas.help/competitors/add-competitors.mdandcompare-competitors.mdsay "under Analytics in the sidebar".Related issue
Product owner's request; follows #506.
Type of change
feat— New featureHow to test
Checklist
config/dashboard.tsmay conflict with #1801 (New badges removed) in a few adjacent lines; keep both.🤖 Generated with Claude Code