Skip to content

feat(prompts): show Improve what the cited competitor pages have that the brand's page doesn't (learning C2) - #1724

Merged
gkhngyk merged 43 commits into
ansvisor:mainfrom
cihan-gyk:feature/improve-competitor-features
Oct 29, 2026
Merged

gkhngyk merged 43 commits into
ansvisor:mainfrom
cihan-gyk:feature/improve-competitor-features

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Learning C2, part 2: Improve's suggestions see what the cited competitor pages have that the brand's page doesn't.

Stacked on #1723 (itself on #1720 and #1718). Review the last 6 commits: 00ff5eb, 7600733, 668de10, e68f2cd, 475f1a6 and 4427bf1. Merge order: #1718 → #1720 → #1723 → this PR. There's no migration of its own.

What changes

withPageChecks adds two lines to each platform's evidence:

  • the checks each cited page passes, by name, marked "(brand)" for the brand's page;
  • the checks at least half of the competitor pages pass and the brand's doesn't. It uses featureGaps and takes at least 2 competitor pages.
  • A page cited under two addresses counts once (e68f2cd).

Code layout

  • prompt-improve.js stays free of database reads: it imports page-features.js, not competitor-pages.js.
  • The task writer's tests load it without SUPABASE_* env, as in CI (668de10, 7600733).
  • Why this is safe: the model gets check names and counts only, never text from a competitor page. The suggestions are still checked against the evidence as before.
  • The number of AI calls doesn't change. The prompt grows by up to two lines per platform.

Where people see it: Prompts › a prompt's Positions panel › Improve tab. Generated suggestions can now point at what the cited pages have, once "Analyze competitor content" has read pages for that prompt. Nothing new is drawn on screen.

Related issue

Agentic learning report, phase C (C2). No GitHub issue. Only the brand's own reads are used (4427bf1 pins the brand_id and 28-day filters).

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. Run "Analyze competitor content" for an action on the prompt (see 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's steps), so cited_page_features has rows for pages cited in its answers.
  2. Open the prompt's Positions panel › Improve, and generate.
    • The suggestions can now name what the cited competitor pages have.
    • prompt-improve.test.js pins the two new evidence lines.
  3. cd server && npx vitest run src/lib/action-center/competitor-pages.test.js src/lib/prompt-improve.test.js src/routes/prompts-improve-page-checks.test.js src/routes/prompts-improve-generate.test.js src/routes/prompts-improve-read.test.js src/routes/prompts-improve-send.test.js src/lib/action-center/task-writer/index.test.js src/lib/action-center/from-prompt-improve.test.js

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/): no web change of its own
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/): no web change of its own
  • Changes are focused — one concern per PR

What was run:

  • Main (ce9a3dc) is merged in, through the chain, with no conflicts.
  • yarn typecheck passes on this tip (the chain's top).
  • Tests: the 8 test files above pass (97 tests). They cover Improve's route, its read, send and generate paths, and the task writer. The embed-hint guard test (the follow-up to 62eb7b7) passes.
  • prettier --check and eslint pass on the changed server files.
  • Not run in this round: the full server suite and the build. Other heavy checks were running on the same machine.

🤖 Generated with Claude Code

cihan-gyk and others added 30 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]>
…ite toward it

Learning C2, part 1 (brief). The brief's rebuild already reads a few of the
pages AI cited for the draft's prompts to measure their length (CE-030),
then threw the rest of what it read away: the writer guessed what those
pages have.

- content-cited-length.js: the same read also runs Site Audit's page checks
  (competitor-pages.js, C1) and citedFeatures keeps the checks at least
  half the pages read pass (two pages at least), with how many. No new
  read, nothing stored but the brief.
- The brief keeps them as citedFeatures beside citedLength.
- The writer's brief (briefText) says "What the pages AI cites for these
  prompts have (Site Audit's checks, 4 pages read): FAQ schema on 3;
  Tables on 2. Give the page these where they serve its readers."
- The Brief tab shows "Cited pages have: FAQ schema (3 of 3) · Tables
  (2 of 3)" under Length. The guide says so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… the brand's page doesn't

Learning C2, part 2 (Improve). Improve listed the competitor URLs cited for
a prompt but knew nothing of those pages, so its model guessed why they win.

- competitor-pages.js storedFeatures: the checks found on pages already
  read for the brand (cited_page_features, C1) in the last 28 days, by page
  key; a row that couldn't be read is left out. Nothing is read here.
- prompt-improve.js withPageChecks: each platform's cited competitor URLs
  and brand pages with their passing checks by name, and the checks most of
  the competitor pages pass that the brand's cited page doesn't; the
  evidence block says so. Unchanged when none was read.
- POST /:promptId/improve reads them once for every platform's pages; a
  failed read leaves the suggestions as they were. Docs say 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]>
…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]>
…ove-competitor-features

# Conflicts:
#	server/src/lib/action-center/competitor-pages.test.js
…d compare over two competitor pages

prompt-improve.js now reads the page checks' gaps from competitor-pages.js,
which reaches the supabase admin client at import time; its config
hard-exits without the SUPABASE_* env, as in CI, so the file failed there.
It mocks the client, as the other tests do. The gaps need two competitor
pages since C1's review, so the test reads two.

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]>
The brief's read of the cited pages needs only Site Audit's page checks,
which now live in page-features.js; it no longer goes through
competitor-pages.js and the Action Center's database reads for them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…f's benchmark

The brief's rebuild deduplicated the Sources' cited pages by their exact
address, so one page cited as www and without, or with tracking
parameters, was read twice and counted as two of the cited pages: in the
median length, and toward "at least half the pages" for what they have.
It now keeps the first address of each page, by the same key that leaves
the draft's own page out.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…a page's body can carry

The writer's brief listed every check the cited pages pass, FAQ schema,
JSON-LD, date markup and freshness among them, though the writer only
writes the page's body HTML: the site's template or CMS sets those, and a
byline would name a person the writer doesn't know. The brief's line now
names only the checks the body can give (WRITER_CHECKS), and none at all
when that leaves nothing. The Brief tab still shows them all; the guide
says so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lf of them pass

citedFeatures keeps a check that at least half the pages read pass, not
"most of them".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…riter's tests run in CI

prompt-improve.js read the page checks' gaps from competitor-pages.js,
which loads the supabase admin client; its config exits when the
SUPABASE_* env is absent, as in CI. Every test reaching prompt-improve.js
went down with it: task-writer/evidence.test.js, task-writer/quality.test.js
and tasks/templates.test.js (evidence.js imports it). It now reads them
from page-features.js, which reads no database, so the module is pure
again, as its header says, and prompt-improve.test.js needs no supabase
mock.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…in Improve's checks

collectEvidence groups cited URLs by their exact address, so one page cited
with and without www, or with tracking parameters, came twice into
withPageChecks: twice in the checks line, and twice in the competitor pages
featureGaps compares, enough on its own for the two pages it asks for.
withPageChecks now keeps each page key's first address.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The build already went on without the page checks when their read failed,
but said nothing: a broken read of cited_page_features would look like no
page read lately. It now logs a warning with the error and the prompt.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…own, read in the last 28 days

storedFeatures' test read the rows back but not the read's bounds: it
now checks the brand_id filter, the page keys and the read_at bound two
freshDays (28 days) back, which the mock now records.

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

# Conflicts:
#	supabase/schema.sql
…titor-features

# Conflicts:
#	docs/guides/prompts.mdx
@mintlify

mintlify Bot commented Oct 28, 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 865ee7a.

Approve preview

@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label 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 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 needs no change. take-1724 (3640f12) is this head 6e90033 with take-1723 merged in. Merge it after #1723.

What I checked:

  • Stored checks only. storedFeatures reads cited_page_features for the brand alone (.eq('brand_id', brandId), service role), from the last 28 days. It never fetches anything. Unreadable rows are dropped. The page keys come from the evidence's cited URLs, a handful per platform, so the in filter stays short. A failed read is logged, and Improve goes on without the checks, as before.
  • Prompt. What's added to the evidence block is the cited URLs (already in the prompt before this PR), our own check labels, and the gap labels from featureGaps. There's no page text. The answer excerpt is still the only quoted text, as before. One page cited under two addresses counts once (opportunityKey), so featureGaps' two-page minimum can't be met by one page.
  • Cost. One small indexed read per Improve call, and a few hundred more prompt tokens at most.
  • Tests. prompt-improve.test.js, prompts-improve-page-checks.test.js and competitor-pages.test.js pass in the full server run on main merged with the stack. Both load without the Supabase env, as CI needs.
  • Merge. Clean on main 72f602f.

@gkhngyk
gkhngyk merged commit 0ae7830 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