Skip to content

feat(demo): fill the demo brand's Site Audit, AI traffic, catalog and fan-out intents (demo brand, part 3) - #1736

Merged
gkhngyk merged 48 commits into
ansvisor:mainfrom
cihan-gyk:feature/demo-brand-site
Oct 29, 2026
Merged

gkhngyk merged 48 commits into
ansvisor:mainfrom
cihan-gyk:feature/demo-brand-site

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Demo brand, part 3 of 7 (server). The demo brand's Site Audit, AI Referral Traffic, product catalog and fan-out intents. The demo moves to DEMO_VERSION = 3, so every demo brand is rebuilt on its next visit.

  • Site Audit (lib/demo/site.js, site-html.js, site-world.js): audits, the page inventory, site trust and brand facts.
    • Each of Brewline's pages is real HTML, parsed by auditContextOf and scored by runSignals and scoreAudit, as a fetched page is.
    • Only what a model or an outside lookup would say is written by hand, in the shapes those steps store: the LLM-judged signals, Wikidata's entity and the fix recommendations.
    • audit/context.js: refactor only. A page already fetched can be read into the audit context with auditContextOf; behaviour unchanged.
  • AI Referral Traffic (traffic.js), over 90 days: snippet visits and journeys, AI crawler hits, and what Google Analytics and Search Console report.
    • Rows go through the live mappers: GA4 rows through ga-sync.js, Search Console rows through gsc-sync.js, events through eventRow, sources through ai-sources.js.
    • Page opportunities are page-opportunities.js's own findings over them.
  • Product catalog (catalog.js) for Product Visibility, the Content Editor's shopping path and category pages.
    • It comes from a product feed in Google's XML, through the feed parser and the catalog sync's catalogRecords.
    • The products in the demo's AI shopping cards are the same products.
    • No product images: the demo loads nothing from outside.
  • Fan-out intents (fanout-intents.js): the intent of the demo's fan-out searches is written ahead into the shared cache (fanout_query_intents), so Query Fan-out never waits on a model for the demo.
    • It is keyed by the search, not the brand. A row already there is left alone (ignoreDuplicates), so a live brand's classification is never overwritten.
    • normalizeIntentQuery moved from routes/prompts.js to lib/intent-extraction.js to be shared; same function.
  • Coverage: these tables move from PENDING to built. brand_cms_connections, content_draft_deliveries, catalog_images and catalog_item_issues are skipped, each with its reason. content_shopping_checks stays pending, for a demo follow-up.

Migration / deploy notes: no migration. Demo brands built at version 2 are rebuilt at the next visit.

Related issue

None (demo brand).

Stacked on #1735 (demo brand, part 2: workflows).

Type of change

  • feat — New feature
  • refactor — auditContextOf, normalizeIntentQuery (shared, unchanged)

How to test

  1. With parts 1–3 on a dev database, open the demo brand: it is rebuilt at version 3.
  2. Audit: the latest audit opens with its pages, scores and recommendations; Site trust and Brand facts are filled.
  3. AI Referral Traffic: 90 days of visits, crawler hits and the Google Analytics / Search Console tabs.
  4. Product Visibility: the catalog's 22 products, categories and AI shelf. Settings › Integrations › Catalog shows the feed source.
  5. Prompts › Query Fan-out: intent badges show at once.

Checklist

🤖 Generated with Claude Code

cihan-gyk and others added 30 commits October 28, 2026 14:29
… counts

Migration 00380 adds brands.is_demo, demo_version, demo_built_at and
demo_hidden_at, one demo brand per organization (partial unique index) and
policies that let members read it but never insert, change or delete one.
The plan's prompt-location quota, the usage cards' account totals and the
web's brand limit leave the demo brand out; the health report's fan-out
share leaves out its answers. The brand delete route refuses it: the demo
brand is hidden, not deleted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The daily tracking list, the job claim and recovery (activeBrandFilter /
isBrandActive), the signal catch-up, the pulse, the task writer, executor
and checks, action validation and Improve outcomes, the Insights sweep,
brand facts, Search Console and Analytics syncs, page opportunities, the
traffic digest, auto-audits, catalog feeds, Webflow status and volume
analysis all leave demo brands out: their data is sample data and nothing
may track, write or spend for it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
lib/demo/ builds an organization's demo brand in its own brands: Brewline
Coffee (brewline.example) with fictional `.example` competitors and
publishers, 12 prompts in 3 topics, 6 engines and a run every 3 days over
a month (720 short answers) with citations, product cards, searches and
volumes. Answers are raw engine responses run through tracking's own
parseScraperResponse, parseResponse and the result and shopping card rows
(now pure resultRow and shoppingCardRows in cloro-result-handler.js), and
the rollups are rebuilt by the nightly run's own functions.

ensureDemoBrand creates it, rebuilds it in place (same ids) when
DEMO_VERSION moves on or its data is three days old, and leaves it alone
otherwise; concurrent visits share one build (one-per-org index, a
compare-and-set claim, a lease). Modules are { name, tables, build }, and
a coverage test fails on any brand_id table the demo neither builds nor
lists as skipped or pending.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
POST /api/demo creates or rebuilds the organization's demo brand for any
member and returns { brandId, version, rebuilt }; PATCH /api/demo
{ hidden } hides or shows it for admins and managers ({ brandId, hidden },
404 no_demo without one). Both stay open once a plan has ended.

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

Four demo modules over core's answers: signals and a month of actions
(tasks, trail, measured outcomes, a task waiting for review, ready-made
KPIs, Getting started with its page steps opened), prompt clusters,
content opportunities, Editor drafts and Plan marks, prompt, topic and
Improve suggestions, and two saved reports. Numbers are counted from the
demo's own answers; shapes come from the engine's own functions. detect.js
exports single and promptTarget so the demo writes signals in their shape.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
DEMO_MODULES runs core, suggestions, actionCenter, content and reports;
DEMO_VERSION 2 rebuilds existing demo brands on their next visit. The
coverage lists move the workflow tables to built, skip the engine's
internal queues and logs and the org-level author default, and leave the
draft shopping check to demo-site with the catalog.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ith auditContextOf

buildAuditContext fetches the page, robots.txt and llms.txt, then hands
them to auditContextOf, which parses the HTML once and extracts its text
as before. A page that isn't fetched (the demo brand's) is read exactly as
a fetched one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Brewline's website (site-world.js) and its traffic: 90 days of Google
Analytics as GA4 reports mapped by ga-sync.js (AI sessions by source and
page, ChatGPT Shopping's feed visits, pages, channels, items), Search
Console's query and page rows mapped by gsc-sync.js, four weeks of snippet
visits (a removed guide's 404s for Broken AI links) and journeys made by
traffic-events.js's eventRow, a month of AI crawler counts with a
Cloudflare Worker connection whose secret hash matches no secret, and the
page opportunities detectPageOpportunities finds in them. The brand maps
the sample GA4 and Search Console properties and has conversions on.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… own verdicts

Brewline's pages are rendered as HTML round by round and scored by
runSignals and scoreAudit: six key pages audited three times as fixes
land, every page in the latest auto-audit. The model-judged signals,
Wikidata's brand entity and the recommendations are written in the shapes
those steps store. The page inventory goes through selectPages and
parseHead, site trust through site-trust.js's checks (4/5: no editorial
policy), and the brand facts through factText and keptFacts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A Google XML feed of 22 products read by the feed parser and kept as
catalogRecords and hashOf keep them, with stable demo ids: a removed
seasonal blend, an out-of-stock size, a sale, no images. The products the
demo's AI answers show as cards are the same page, title and price. Two
categories get their page by hand; the rest match their collection pages.

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

The demo writes the intent of each search its answers ran into
fanout_query_intents, keyed as the route keys it (normalizeIntentQuery,
moved to intent-extraction.js), adding only what the shared cache lacks,
so Query Fan-out never needs a model for the demo.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s with the demo brand (version 3)

The demo-site modules join the core in DEMO_MODULES, and DEMO_VERSION is
3, so every demo brand is rebuilt with them on its next visit. Their
tables leave the coverage test's pending list; a CMS connection, sent
drafts, product images and Merchant Center item issues are skipped, with
why.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… rows stay the same

One rebuild for another brand two days later checks both that only the
ids and dates change, with room past the default 5 s on a busy machine.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	server/src/lib/demo/coverage.js
#	server/src/lib/demo/index.js
The first module lays down what the others point at; the rest write their
own tables together, each after the module it names in `after`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A first build no longer clears 70 empty tables, and the core writes each
step's independent tables side by side through a shared queue of four
statements (write.js: insertChunks, demoWriter). Its rollups move to a
refresh step that runs alongside the other modules, Insights, Citations and
Mentions together, the month's answer terms in one call (refreshMentionsDaily
takes an optional termDays). The core alone went from about 17 s to 7 s on
the dev database.

A rebuild (new DEMO_VERSION, or data older than three days) no longer
deletes the demo first: an `inPlace` module writes over its rows by key
(ids are deterministic) and deletes only the rows it didn't write again,
then rebuilds the rollups over the old and new days, each refresh call
rewriting its days in one statement. Someone opening the demo meanwhile sees
last week's data, not empty pages. Modules not marked `inPlace` still have
their tables cleared, now just before they are built.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A brand just created isn't empty: its insert trigger starts Getting started,
so skipping every clear on a first build made the Action Center's insert hit
getting_started_pkey. An in-place module now always writes over by key (the
first build only skips reading back and pruning); a module that isn't
rebuilt in place clears its own tables just before it is built, on a first
build too, alongside the other modules rather than all up front.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…irst build

Nobody looks at a demo being built for the first time, so every module not
rebuilt in place starts clearing what the new brand's triggers made at once,
while the core writes, instead of each in turn later, when its deletes queue
behind the rollups. A rebuild still clears each module just before it is
built, so its old rows stay on show as long as they can.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A table with an identity id and no other unique columns (ai_bot_events)
can't be written over by key. write(table, rows, { generated: true })
inserts the new rows and, on a rebuild, deletes the brand's rows that were
there before right after: never empty, both there for a moment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ts in place

The four workflow modules write through the build's writer (ctx.write):
each step's independent tables side by side, and on a rebuild over their
old rows by key, deleting only what isn't written again, so their pages
never empty while the demo is rebuilt. Keys where a row has no id:
getting_started (brand_id, also what a new brand's trigger made),
getting_started_steps, action_signals, the cluster members, searches and
scopes, and the plan marks; the action and cluster children are found
through their parent (scopes).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cihan-gyk and others added 9 commits October 28, 2026 20:50
The three site modules write through the build's writer (ctx.write): their
independent tables side by side (traffic's thirteen at once, a visit before
its pageviews), and on a rebuild over their old rows by key, deleting only
what isn't written again, so their pages never empty while the demo is
rebuilt. Google Analytics and Search Console rows are keyed by their day and
what they count (their unique columns, as their syncs write them), the
audits' signals by audit and signal (found through their audit), the
single-row settings by brand. ai_bot_events has an identity id and no other
key: its rows are replaced, the old ones deleted right after the new are in.
site-common's insertRows goes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
refreshMentionsDaily takes `together`: the rollups (refresh_mentions_daily)
and the answer terms (refresh_mention_terms) take their own locks and write
their own tables, so the demo runs them side by side instead of one after
the other, a second off the longest step of its build. The nightly run
keeps them in turn.

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

# Conflicts:
#	server/src/lib/action-center/task-checks.js
#	server/src/lib/action-center/validate.js
#	server/src/routes/index.js
#	supabase/schema.sql
…ver main's new tables

sweepPromptDemand chose brands by their organization's plan only, so an
active workspace's demo brand would have had its sample prompts read and
DataForSEO's paid tasks set for them. It now leaves demo brands out, as
the other sweeps do. The demo coverage list names the two brand tables
main added: prompt_table_views (skipped: the demo starts on the default
columns) and prompt_demand (pending a demo follow-up).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cihan-gyk and others added 7 commits October 29, 2026 18:49
…core

# Conflicts:
#	server/src/lib/action-center/execution/run.js
#	server/src/lib/action-center/execution/run.test.js
#	supabase/schema.sql
…n's new tables

sweepCompetitorTimeline (learning C3, on main) chose brands by their
organization's plan only, so a demo brand's sample answers would have had
their cited pages read every night. It now leaves demo brands out, as the
other sweeps do. The demo coverage list names the brand tables main added:
cited_page_features, competitor_page_events and competitor_timeline_scans
(pending a demo follow-up) and chat_conversations (with Chat).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Chat's precedence (ansvisor#1776) left readBrandIsDemo false until the demo chain
added brands.is_demo, with a type check that stops compiling once the
column exists. It now reads the column, as the server's demo guard does,
so a tool that changes or spends on the demo brand is refused with
demo_brand; a brand that isn't found isn't one, and a failed read throws.

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

Copy link
Copy Markdown
Collaborator Author

Merged main forward through #1735's updated branch (no conflicts of its own). Typecheck and the demo tests pass; server lint clean.

…oduct cap

The catalog sync's room (productRoom) counted the live products of every
brand in the workspace, so the demo brand's sample catalog took room from
the workspace's own sources on a capped plan. It now counts the
workspace's real brands only.

Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A

@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 with 086640b1: the demo's sample catalog no longer counts against the plan's product cap. A merge of main with three follow-on changes is on top of it, at d06e94bf.

Reviewed 21f3a02 (part 3), as its own diff on top of #1735's head ebe6378. No migration.

What I changed

  • 086640b1 (on 21f3a02): productRoom (lib/catalog/sources.js) counted the live products of every brand in the workspace against maxCatalogProducts. That included the demo brand's 22 live sample products, so on Starter and Growth they took room from the workspace's own feeds. It now counts the workspace's real brands only (.eq('is_demo', false)). The cap tests now include a demo brand with a live product: 4 of them fail without the change.
  • The merge with main (3b7611c), on top of that:
    • Conflicts resolved: execution/run.js (main's retry_after read beside the demo filter), its test, and schema.sql (rebuilt with build-schema.sh).
    • 8e38ca0d. Main's competitor timeline pass (learning C3, #1746) goes over every active brand with competitors. An active workspace's demo brand would have had its sample competitors' pages read each night (spending the night's brand slots on .example hosts) and events written to it. It now leaves demo brands out, with a test that fails without the change.
    • 8e38ca0d, coverage. The demo coverage test failed on main's four newer brand-scoped tables. cited_page_features, competitor_page_events and competitor_timeline_scans are now skipped, since nothing is read for a demo brand; chat_conversations is pending with the demo Chat.
    • d06e94bf. Main's Chat precedence (#1776) has a compile-time reminder that fails tsc once brands.is_demo exists. readBrandIsDemo now reads the column, so Chat refuses a change or a cost on the demo brand. A read that fails throws. Tested both ways.

What I checked

  • No outside request. The pages are built HTML, parsed by auditContextOf and scored by the real signals, none of which fetches anything. The feed is parsed from text. GA and Search Console rows go through the sync's mappers without a sync. The bot connection's secret_hash can't match any secret, so no sender can write to it.
  • Quotas. Site Audit usage counts site_audit_usage and running audits; the demo writes neither (its audits are completed). The bot event caps count ai_bot_usage; the demo writes ai_bot_events/ai_bot_daily directly, so its 30 days of hits don't count against the month. The catalog cap is fixed above.
  • Shared rows. fanout_query_intents gets 25 coffee searches, insert-if-missing (ignoreDuplicates), so a live classification is never overwritten. citation_urls gets the .example addresses (append-only). No other row outside the demo brand is written.
  • audit/context.js and normalizeIntentQuery: behaviour unchanged, covered by the moved tests.
  • Tests:
    • On 21f3a02: demo, catalog, middleware and routes, 375 tests, pass.
    • On the merged branch, the full server suite: everything passes except the Framer and content-draft suites (no framer-api package in my local install) and one timing test that passes alone.
    • On the merged branch, web: tsc clean; src/lib/chat, the embed guard, subscription-guard-coverage and brand.test.ts (241 tests) pass.

Follow-ups

  1. The nightly card match (sweepShoppingCardMatches) goes over every brand whose catalog synced in the last day. The demo's source says it synced at build time, so it is matched again the night after a build. That costs nothing and should change nothing, but it is a nightly write to the demo. A brands!inner(is_demo) filter there (one foreign key) would keep it off.
  2. Pre-seeding fanout_query_intents makes the demo's hand-written labels the answer for any real brand whose fan-out runs the same 25 searches. They read right today; just keep them sensible if they change.

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