Repository navigation
feat(action-center): keep when a competitor page was first cited and when it changed (learning C3, part 1) - #1745
Merged
Conversation
…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]>
…or-page-features-ui
…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]>
…or-page-features-ui
…page-features # Conflicts: # supabase/schema.sql
…or-page-features-ui
# 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]>
7 of 8 tasks
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.
8 of 12 tasks
gkhngyk
approved these changes
Oct 29, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Looks good with ce2266f: the nightly timeline now reads every competitor, scan and cited page past PostgREST's 1,000-row cap, and asks for the pages already recorded in parts. Branch take-1745: this head 95baa29 with take-1742 merged in (#1718's fix), then the fix. The follow-ups below stay open.
At merge time I also revoked the default anon/authenticated grants on competitor_page_events before granting members select, so members get select and nothing more (dc212bc).
What I changed (server/src/lib/action-center/competitor-timeline.js):
- The
infilter's URL.recordFirstCitationsasked for thefirst_citedevents already kept with one.in('page_key', …)over every competitor page the brand cited since its last read. On the first night that's 90 days back, often hundreds of addresses. PostgREST carriesinvalues in the URL, andchunked-in.jsrecords that about 16 kB already fails at the edge. That brand's read would fail before the scan was saved, so it would read 90 days back and fail again every night. It now goes throughselectInChunks, 30 keys a request. - The 1,000-row cap.
competitor_cited_urlsreturned all of a brand's cited competitor addresses in one call, andmax_rows = 1000cuts a set-returning RPC off too, in no set order. So past 1,000 addresses, first citations were missed, and the weekly re-read's "cited most" was picked from an arbitrary part. The sweep'scompetitorsread (every brand's) andcompetitor_timeline_scansread (one row per competitor) had the same cap: past 1,000 rows, brands were skipped or ordered wrongly. All three now read page by page (allRows: an ordered query read through.range). - The
organizationsread for the plan check now goes throughselectInChunksas well (one uuid per organization with competitors). - Tests: 2,500 cited addresses are all recorded, read in three pages, with no
inover 30 keys. A brand past the first 1,000 competitor rows is reached. The test's mock now honoursrangeand the 1,000-row cap. Without the fix both tests fail.
What I checked:
- Migration 00376.
cited_page_features.sketchis added to 00369's table, which is new (no rewrite of a big table).competitor_page_events: RLS on, oneselectpolicy for members throughbrands↔profiles(the usual organization scoping),grant selectto authenticated, no write policy, so only the service role writes. A partial unique index keeps onefirst_citedper page, and(brand_id, competitor_id, at desc)serves the card.competitor_timeline_scans:revoke allfrom anon and authenticated, service role only.competitor_cited_urls:security definer,search_path = public,revoke allfrom public, anon and authenticated, execute for the service role only. It filters onprc.brand_id = p_brand_idfirst, which the(brand_id, created_at desc) include (url_id, prompt_result_id)index covers. Everything isif not exists/create or replace, and the columns it reads exist on main's schema. No clash: 00376 isn't on main or in any other open PR, and this PR doesn't change 00369. - Reads and cost. The weekly re-read uses #1718's
readPages: safe-fetch, robots.txt, 8 s / 3 MB, within what's left of the brand's 12 reads a day after the tasks. At most 10 pages a brand, 200 brands a night, and no new brand started after 10 minutes. No AI. What's kept is the checks and a hash sketch of 4-word runs, never the text. The sweep runs aftersweepTaskExecutionsettles, so the tasks get the day's reads first. - Change rule.
pageChangereuses the page checks'CHANGED_BELOW/MIN_CHANGED_RUNSand the sketch version, and an unreadable re-read keeps the last sketch. - Embeds.
competitors → brands!innerhas one foreign key (competitors_brand_id_fkey). - Tests. On main 72f602f merged with
take-1724andtake-1746, the full server suite gives 3,823 passed. The 9 failing files are 8 that importframer-api, which my scratchnode_moduleslacks (they fail the same on main), andbilling.test.jsunder load, which passes alone.competitor-timeline.test.jspasses (10). Prettier and eslint are clean on the changed files. - Merge. Clean on main 72f602f,
supabase/schema.sqlincluded.
Follow-ups:
- Grants on
competitor_page_events. Supabase's default privileges give anon and authenticated every grant on a new table. RLS blocks the writes (there's no write policy), butrevoke all … from anon; revoke insert, update, delete … from authenticated;would match 00369's table. like '%.' || host. A competitor domain with_would match one more character as a wildcard. Harmless, butright(u.domain, length(host) + 1) = '.' || hostsays exactly what's meant.- The RPC by pages runs the function once per 1,000 rows. That's fine at today's sizes (see the query below). If a brand ever has many thousands, the
first_citedinsert could move into SQL (insert … on conflict do nothing).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Learning roadmap C3, part 1 of 2 (server): keep when a competitor's page was first cited in the brand's tracked answers and when it changed, so "why did this competitor rise?" gets a dated answer.
Stacked on #1742 (C4, itself on #1720 → #1718); it reuses the page reader C4 shares. Review the last two commits; merge after #1742. The screen is part 2.
cited_page_features.sketch(jsonb): the hashes of 4-word runs that the task checks already use. No page text is stored, and 00369 is untouched.competitor_page_events(first_cited|changed;brand_id,competitor_id,page_key,url,domain,at,detail). Members read it through RLS, only the server writes it, and a partial unique index keeps onefirst_citedper page.competitor_timeline_scans: when each competitor was last scanned. Service role only.competitor_cited_urls(p_brand_id, p_since): the URLs on a competitor's domains (subdomains included) cited in the brand's answers, with first-cited date and answer count. Service role only.competitor-timeline.js:recordFirstCitations: the first time each competitor page was cited, once per page. A new competitor is scanned 90 days back, then from a day before its last scan. It reads existing citations only, so it costs nothing.recordPageChanges: re-reads, once a week, the competitor's 10 most-cited pages of the last 14 days whose last read is over 7 days old. It uses only the reads left in the brand's day (C1 and C4 share the same 12 a day) and obeys robots.txt. A page whose sketch similarity drops below 0.9 with at least 80 runs changed gets achangedevent; its detail names the Site Audit checks the page gained and lost.sweepCompetitorTimelineis chained aftersweepTaskExecutioninserver.js, so C1's and C4's reads go first. It takes the longest-unscanned brands first, at most 200 a night, within 10 minutes. On Cloud, only active plans.readPagesnow keeps each read's sketch and hands a re-read page its previous read asbefore;freshDaysis a parameter. C1's and C4's tests pass unchanged.action-engine.js(competitorTimeline).schema.sqlregenerated.Product decisions (Cihan): weekly re-reads of the 10 most-cited pages per brand, within the daily limit. Adding these events to the C07 action's evidence is a later, separate task.
Deploy: apply 00376 before the web part (the next PR) ships; without it the card says "Couldn't load the timeline" and the rest of the page works.
Related issue
None (learning roadmap C3).
Type of change
feat— New featureHow to test
sweepCompetitorTimelineon a dev server),competitor_page_eventsholdsfirst_citedrows for competitor pages cited in the last 90 days, one per page.freshDays, and run again: achangedrow whose detail lists the gained/lost checks.Checklist
bash supabase/build-schema.shrun,schema.sqlincluded; applied on the dev databasenpm run format,npm run lint,npm testpass (283/283 files, at the top of the stack incl. part 2)competitor-timeline.test.js; C1/C4 reader tests unchanged)docs/guides/competitors.mdx)🤖 Generated with Claude Code