Repository navigation
feat(action-center): read the competitor pages AI answers cite and say what they have that the brand's page doesn't (learning C1) - #1718
Merged
gkhngyk merged 9 commits intoOct 29, 2026
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]>
… 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]>
…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
# Conflicts: # supabase/schema.sql
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
This was referenced Oct 28, 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.
gkhngyk
approved these changes
Oct 29, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Looks good with 82f1b07: reading a cited page's words and Site Audit's readability blocks now takes one walk over the page, so a page full of empty elements reads in about a second. Branch take-1718, on this PR's head deb569e. The follow-ups below stay open.
What I changed:
page-features.jspageContext. It parsed the page twice and removedscript, style, noscript, template, svgfrom the second parse before reading its text. Cheerio removes each element by splicing it out of its parent's children, so the removal is quadratic in their number. Timed on the 3 MB that safe-fetch allows: a page of empty<style>tags took 75 s (1.5 MB: 21 s). The text now comes from one walk over the first parse that skips those elements (bodyText), with the same words: checked against the old removal on 3,000 generated pages, no difference. Same page now: 0.6 s.audit/signals/readability.jsreadingBlocks.$('body').find('h1, h2, …')is quadratic in the elements directly under the body (css-select'sremoveSubsets): 20,000 short paragraphs took 3 s, 175,000 empty<li>s about 60 s. It also ran aclosest/parentsselector per element. The block elements now come from one walk in document order, and "inside a list item or a cell" is an ancestor walk by tag name. Checked against main's version on 3,000 generated pages: the same blocks. Site Audit and the editor's readability get the same speed-up (their scores don't change).- Tests:
page-features.test.js(the text matches the old removal; 100,000 empty styles and 40,000 empty list items read in seconds) andreadability.test.js(40,000 paragraphs in one pass). Without the fix they take 59 s and 11 s.
What I checked:
- Outbound reads. Only addresses from the brand's own tracked answers are read, never one a request names. Every read goes through
safe-fetch: http(s) on standard ports, no credentials, every resolved address public (checked in the connection's own lookup, so no DNS rebinding), redirects followed by hand and checked each time (at most 5), 8 s per read, 3 MB decompressed, too-deep pages refused. robots.txt is read through the same fetch (512 KiB, truncated). A 4xx means no robots.txt; a 5xx, 429 or timeout keeps the reader out, as RFC 9309 asks. - Cost. No AI and no paid scraper: at most 3 competitor pages and the brand's own page per run, at most 12 new page reads a brand a day, one robots.txt per site per run, and a page read in the last 14 days is reused. Runs come from the nightly task sweep (
maxTaskRunsPerNight). - Page text never stored or sent to a model.
cited_page_featureskeeps the checks' statuses and a word count only. - Migration 00369. New table only: RLS on,
revoke allfrom anon and authenticated, service role only. Unique(brand_id, page_key)serves the upsert, and(brand_id, read_at desc)serves the day's count. No lock on an existing table,if not existsthroughout. No clash: 00369 isn't on main or in any other open PR. - Embeds.
prompts → prompt_sets!innerhas one foreign key (prompts_prompt_set_id_fkey). Theaction_tasksembeds inrun.jsare main's own; this PR only addsretry_after:output->>retryAfterto the select. - Merge.
take-1718merges cleanly on main 72f602f. So does the whole stack. - Tests. I ran main merged with every take branch through the full server suite (results in the stack summary on #1745).
page-features,readability,competitor-pages,runandauditpass on their own. Prettier and eslint are clean on the changed files.
Follow-ups:
- robots.txt paths. Only a whole-site
Disallow: /(foransvisorbotor*) is respected. A rule for a path (Disallow: /blog/) isn't, so a page under it is still read. RFC 9309 path matching would be small (longest match wins,AllowbeatsDisallowon a tie). - Event loop. Even linear, Site Audit's checks over a 3 MB page take 1–4 s of synchronous work (a page full of tables: about 4.7 s, most of it readability's content extraction), and the nightly sweep runs them in the API process. A smaller
maxBytesfor third-party pages (1 MB covers almost every article), or a worker thread, would keep requests answered meanwhile. - The day's cap is counted, then spent. Two runs for one brand at once could both pass the
perBrandPerDaycheck. The nightly sweep runs tasks one at a time, so this only matters if the API ever runs more than one process. retry_afterand the 1,000 tasks read. Tasks waiting to retry are filtered after.limit(1000), so with more than 1,000 waiting the runnable ones behind them aren't read. Filteringoutput->>retryAfterin the query would avoid it.
7 of 8 tasks
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 C1: "Analyze competitor content" reads the competitor pages AI answers cite, and says what they have that the brand's page doesn't.
This is the bottom of a 4-PR chain (C1 → C1 UI → C2 brief → C2 Improve). Migration 00369. This PR's own commits are 73952ca, 380f81d and 7959358, plus the merge of main.
Until now the task was a step for a person: nothing read the pages AI engines cite instead of the brand's. The registry now gives it a tool,
competitor_page_features. It haswritesExternally: false, so the nightly task sweep runs it without approval, as it already runs the AI-traffic report.What it reads
chatgpt-shopping, for the action's prompts. Those are, in order:safe-fetchonly (public addresses only, so no SSRF), with an 8 s timeout.ansvisorbot. A whole-site Disallow for it, or for*, keeps the reader out.Migration 00369,
cited_page_features(brand_id, page_key). Columns:url,domain,own,features jsonbandread_at.featuresis{ words, checks: { key: pass|warn|fail|na } }, or{ unreadable: true[, disallowed: true] }. Never the page's text.anonandauthenticated, and granted toservice_roleonly. Members see the result through the task's output.notify pgrst.schema.sqlis regenerated.Limits (
competitorPagesinconfig/action-engine.js)The result is the task's output:
competitorPages,yourPage,yourPageStatus,gaps,comparedandunreadable.gapslists the checks that at least half of their pages pass and the brand's page doesn't.execution/run.jsretryLater(ReadLaterError). The run is recorded asblocked, and the task stays as it was.retryAfter7 days later. The sweep passes the task over until then, and it doesn't take a place undermaxTaskRunsPerNight. The summary counts these tasks aswaitingToRetry.Smaller changes
basket-metrics.js:topicPromptIds()is moved out ofbasketScope. It's the same query, and now takes several topics.page-features.jsholds the checks without the Supabase client, so C2 and its tests load in CI.Who's affected after merge
maxTaskRunsPerNight(50).Where people see it: Action Center › an action's Tasks. "Analyze competitor content" is done overnight. The next PR (C1 UI) shows what it found in the drawer.
Related issue
Agentic learning report, phase C (C1). No GitHub issue. This follows product decision 2: free reads with
safe-fetch, Site Audit's rule checks, a daily cap per brand, features only, and no paid scraping or AI summary in v1. Nothing here reads another brand's data.Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
00369_cited_page_features.sqlto a dev database.select t.id from action_tasks t join actions a on a.id = t.action_id where t.task_key = 'analyze_competitor_content' and t.status = 'todo' and a.brand_id = '<brand>';cd server && node src/scripts/run-action-task.js <taskId> --dry, then run it again without--dry.select page_key, own, features, read_at from cited_page_features where brand_id = '<brand>';shows checks only, never text.action_tasks.outputholds the findings.cd server && npx vitest run src/lib/action-center/competitor-pages.test.js src/lib/action-center/page-features.test.js src/lib/action-center/execution/run.test.js src/lib/action-center/basket-metrics.test.jsChecklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/): no web changeyarn typecheckpasses (run fromweb/): no web changeyarn format:checkpasses (run fromweb/): no web changeWhat was run:
bash supabase/build-schema.shmatches the committedschema.sql.prettier --checkandeslintpass on the changed server files.npm test). Other heavy checks were running on the same machine.🤖 Generated with Claude Code