Skip to content

feat(competitors): show a competitor's pages over time under its comparison (learning C3, part 2) - #1746

Merged
gkhngyk merged 28 commits into
ansvisor:mainfrom
cihan-gyk:feature/competitor-timeline-ui
Oct 29, 2026
Merged

gkhngyk merged 28 commits into
ansvisor:mainfrom
cihan-gyk:feature/competitor-timeline-ui

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Learning roadmap C3, part 2 of 2 (web): a competitor's pages over time, on the Competitors page.

Stacked on #1745 (C3 part 1, which holds migration 00376). Review the last commit; merge after #1745.

  • Competitors › a selected competitor › under the head-to-head: "'s pages over time".
    • The last 12 weeks' weekly mentions of the competitor and the brand, read in pages from insights_*_daily, with a marker on weeks that had an event. The chart follows the Insights trend pattern and loads only in the browser. Colours are Insights' brand and first-competitor colours.
    • Under it the events: "First cited in your tracked answers" and "Changed: now has FAQ schema, Tables · no longer has …". Eight show, the rest open with Show all. With no events yet, the card says what it reads and when changes appear (from the second weekly read, as the first is the baseline).
  • getCompetitorTimeline (lib/actions/competitor.ts) and pure helpers (lib/competitor-timeline.ts). competitor_page_events was added to types/supabase.ts by hand, as prompt_table_views was.
  • Strings are in en.json, colours use theme tokens, and the guide has a new section "A competitor's pages over time".

Deploy: 00376 (part 1) before this web part.

Related issue

None (learning roadmap C3).

Type of change

  • feat — New feature

How to test

  1. With 00376 applied and the night run done, open Competitors and select a competitor. The card shows the 12-week lines and any events.
  2. A competitor with no events: the card explains what it reads.
  3. Check both themes at 1024 px.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • Web: yarn lint (0 errors), yarn typecheck and yarn build pass. yarn test: 558/559 files; _before-publish timed out under load (known; passes alone).
  • Tests added (competitor-timeline.test.ts, _timeline-card.test.tsx, Competitors page)
  • The embed guard from test(web): fail on an embed between twice-joined tables that doesn't name its foreign key #1714 passes on this branch
  • Docs updated
  • Browser check: 00376 is now applied on the dev database, but the card needs a night run's events; it's in the batched local test

🤖 Generated with Claude Code

cihan-gyk and others added 19 commits October 28, 2026 10:15
…y what they have that the brand's page doesn't

Learning C1, part 1 (server). "Analyze competitor content" was a step for
a person: nothing looked at the pages AI engines cite where the brand isn't
named, so "why do they win?" went unanswered.

- competitor-pages.js: from the brand's own tracked answers for the
  action's prompts over 14 days, the competitors' most cited pages, then
  pages cited where the brand isn't named (3 an action), and the brand's
  own page cited there. Each is read free (safe-fetch, public addresses
  only, never Scrape.do) and run through Site Audit's checks that read the
  page alone (15: structure, FAQ, schema, statistics, dates, length…). The
  result: each page's passing checks and the checks at least half the
  competitor pages pass that the brand's page doesn't.
- 00369 cited_page_features: the checks' statuses and word count per brand
  and page, never the page's text; reused for 14 days; a brand reads at
  most 12 pages a day (config competitorPages). Service role only; applied
  on the dev DB.
- The task gets the tool competitor_page_features, so the nightly runner
  carries it out (reading a public page changes nothing, no approval). A
  run with every read for the day spent leaves the task for the next night
  (retryLater: recorded as blocked, task untouched).
- No AI summary, no paid scraping (user decision 2). The guide says so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…etitor pages AI cites have that yours doesn't

Learning C1, part 2 (web). The task now carries what the nightly read found
(part 1); the action drawer shows it when the task is opened.

- Task rows read `output`; Analyze competitor content's is parsed
  defensively (competitor-findings.ts: pages read, the brand's page, the
  gaps, pages left for tomorrow, why nothing was compared).
- TaskDetailView shows "What the pages AI cites instead of yours have":
  each gap as "FAQ schema — on 2 of 3 of their pages, not on yours" (the
  check's name as Site Audit's rubric gives it), the pages read with their
  words and how many answers cited them, the brand's page, and a note that
  only what the checks found is kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… there is nothing to compare, and read every page of an action the same night

Review fixes before the PR (learning C1, server):

- An action that names no prompts (8 of the 9 plans with this task) reads
  its topics' prompts (topicPromptIds, shared with basket-metrics), else
  the brand's tracked prompts (at most 50), instead of ending on
  "no_prompts".
- No prompts, no page cited, or none readable no longer completes the
  task: ReadLaterError carries why as the task's output and retryDays (7);
  runTask keeps it on the open task with retryAfter, and the nightly sweep
  passes the task over until then without it taking a place under the
  ceiling.
- An action's pages are all read the same night or none: with fewer reads
  left than pages to read, nothing is read and the task waits for the next
  night. No more partial runs ("capped" is gone).
- yourPageStatus says whether the brand's page was read, not cited, or
  couldn't be read.
- A page with under 500 characters of text (a consent wall, a page drawn
  by script) is unreadable.
- An unreadable page is kept as { unreadable: true }: it counts against the
  day's reads and isn't read again while fresh. A row that can't be written
  is logged, not counted as unreadable.
- Gaps need at least two competitor pages ("compared"); a check is a gap on
  at least half of them.
- robots.txt: a site whose robots.txt shuts AnsvisorBot (or every crawler)
  out of the whole site isn't read, nor one whose robots.txt can't be read
  (RFC 9309); path rules aren't read yet (robotsGroups).
- 00369: the unreadable row shape in a comment (no schema change).
- The guide: the task is carried out by Ansvisor, not waiting for
  approval; what it reads, the two-page minimum, robots.txt and the weekly
  retry.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…f theirs is too few, or yours couldn't be read

Review fixes before the PR (learning C1, web), after the server's:

- The "N more pages wait for tomorrow's reads" line is gone: an action's
  pages are now read the same night or not at all, so nothing is capped.
- With one competitor page read, the task says it takes at least two to
  compare, instead of "Your page passes…".
- The brand's page that couldn't be read says so, rather than "None of
  your pages was cited".
- "at least half of their pages" in the no-gap line, as the server counts;
  the no-prompts and none-cited reasons say what they now mean.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s without Supabase

FEATURE_CHECKS, pageContext, pageFeatures, featureGaps and
MIN_PAGE_CHARACTERS move from competitor-pages.js to page-features.js,
which reads no database. competitor-pages.js loads the supabase admin
client, whose config exits when the SUPABASE_* env is absent (as in CI),
so a pure module that needs only the checks (the brief, Improve) would
take every test file reaching it down with it. competitor-pages.js
re-exports them, so its imports keep working; their tests move next to
the new module, with no supabase mock.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…page-features

# Conflicts:
#	supabase/schema.sql
…om its other pages (learning C4)

G14 (AI landing pages converting well) and G10 (prompts rising) point at
pages that already work; nothing said what they have that the brand's
other pages don't. A new automatic task, analyze_winning_pages ("Find
what sets your winning pages apart"), compares them through Site Audit's
own checks (page-features.js) with the brand's other pages audited in the
last 90 days:

- winning pages: G14's landing pages (an Analytics path on the brand's
  primary domain), or G10's own pages its prompts' answers cited in the
  last two weeks; at most three;
- the other pages are read from their audits only (audit_signal_results),
  never fetched; at most 30, newest audit first;
- a winning page without a recent audit is read like a page AI answers
  cite: competitor-pages.js's reader, now readPages, shared with C1 and
  within the same perBrandPerDay (12) reads a day;
- the result: the checks most winners pass and most other pages don't,
  widest gap first, and up to five other pages missing the most of them.
  Fewer than three other pages audited: the task stays a person's with
  the reason and tries again after seven days.

The task requires site_audits, so a brand without audits doesn't get it.
G10 and G14 move to version 2: tasks are planned when an action opens,
so actions already open keep theirs and new ones get the task. The task
library holds 63 primitives (the spec's 62 and this one). No migration.
The Action Center drawer shows the findings on the task, as C1's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…when it changed (learning C3, part 1)

A competitor rising in AI answers had no "why" beside it. Each night now
keeps two kinds of dated events for the competitor pages the brand's own
tracked answers cite (competitor_page_events, 00376):

- first_cited: the first day the brand's answers cited the page, read in
  the database from its citations (competitor_cited_urls, service role
  only): no page read. A competitor never read is read back 90 days once,
  the others from a day before their last read (competitor_timeline_scans).
- changed: the brand's 10 competitor pages cited most over two weeks are
  read again once their last read is a week old, within what is left of
  the brand's 12 page reads a day after the night's tasks (C1, C4), and
  compared with the last read's word sketch by the Action Center's page
  checks' rule (task-checks.js: similarity under 0.9 and 80 runs changed);
  the event keeps the Site Audit checks the page gained and lost.

competitor-pages.js readPages now keeps each read's word sketch
(cited_page_features.sketch: hashes of its 4-word runs, never the text)
and hands a page read again what the read before kept. The sweep runs
after the task sweep, brands read longest ago first, at most 200 a night;
on Cloud only brands whose plan is active. Members read the events (RLS);
the server writes them. The Competitors page shows them in part 2.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… page gained and lost (learning C3)

The web has no names for Site Audit's checks: a changed event now keeps
each check gained or lost as { key, label }, the label as the rubric
gives it, as "Analyze competitor content" keeps its gaps.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…arison (learning C3, part 2)

Under a competitor's head-to-head on the Competitors page, a card shows
the answers mentioning the competitor and the brand each week over the
last twelve weeks (the daily rollups, every row read), a marker on each
week something happened to the competitor's pages, and those events
newest first (competitor_page_events, part 1): the day a page was first
cited in the brand's tracked answers, and the days a weekly re-read found
it changed, with the Site Audit checks it gained and lost (by name). Eight
events show, then all on asking; before anything happened the card says
what Ansvisor reads.

getCompetitorTimeline (lib/actions/competitor.ts) reads it as the member
(RLS); lib/competitor-timeline.ts weeks the rows and reads the events
defensively. The chart is loaded on the client only, as the Insights
trend's. competitor_page_events joins the generated types.

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

mintlify Bot commented Oct 29, 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 9d9e638.

Approve preview

@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 29, 2026
A page of tens of thousands of empty elements held the server for a
minute: removing scripts and styles before reading the text spliced
each out of its parent, and readability's block find was quadratic in
the elements it started from. Both are now one walk over the page,
with the same words and blocks as before.
… covers

The nightly timeline read its competitors, its scans and a brand's cited
competitor pages in one request each, so past PostgREST's 1,000-row cap
the rest were left out, and it asked for the pages already recorded in
one filter, which past a few hundred addresses is longer than a request
may be: that brand then failed every night. The reads now go page by
page, and the filters in parts.

@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. This PR's own diff, web only, needs no change. take-1746 (27d762b) is this head 9898b0a with take-1745 merged in, so it carries the timeline fix and #1718's. Merge it after #1745, and only once migration 00376 is applied: the card reads competitor_page_events.

What I checked:

  • Authorization. getCompetitorTimeline checks both ids are uuids and reads with the user's own client. RLS scopes insights_brand_daily, insights_competitor_daily and competitor_page_events (00376's member select policy) to the caller's organization. It's a read, so it needs no assertWritable. subscription-guard-coverage.test.ts passes.
  • Bounded reads. The weekly rollups go page by page (readAllRpcRows, ordered on the full key, so the pages are stable). Events are capped at 50, newest first.
  • Links. parseTimelineEvents keeps an event's URL only when it starts with http(s)://. Labels for gained and lost checks come from the stored keys and labels, rendered as text.
  • Embeds. None.
  • Types. web/src/types/supabase.ts adds competitor_page_events as 00376 makes it.
  • Docs. competitors.mdx matches the behaviour: 12 weeks, first cited (90 days back once), the weekly re-read of the 10 most cited, robots.txt, and the 12 reads a day shared with the tasks.
  • Tests. On main merged with the stack: _timeline-card.test.tsx, competitors/page.test.tsx and competitor-timeline.test.ts pass, and web tsc is clean.
  • Merge. Clean on main 72f602f.

Follow-up:

  1. The docs call the stored sketch "a summary of the page's words". It's a set of hashes of 4-word runs, so "a fingerprint of the page's words" would be closer, and nobody would read "summary" as text kept.

@gkhngyk
gkhngyk merged commit 8f8d3b1 into ansvisor:main Oct 29, 2026
5 of 6 checks passed
@github-actions github-actions Bot removed the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 29, 2026
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.

2 participants